feat(linkedin-studio): RE-R3a — persist relevance score on the store record + rank the morning brief on it [skip-docs]
R3 slice 1 (research-deepening). Stop discarding the relevance judgment the
trend-spotter already computes: persist a 4-field TrendScore {mode, dimensions,
composite, priority} on TrendRecord (schema v2->v3, additive lossless migrate),
computed by the existing score.ts composite()+band() (one owner, no new arithmetic),
threaded item->store; then rankForBrief sorts each bucket composite-first (sentinel
-1 for unscored) and renderBrief surfaces "· <priority> (<mode>)" per body entry
(briefSummary shows the band only). First-sight only; mode-blind ranking with the mode
shown so the operator can disambiguate instruments.
- score.ts: TrendScore + requiredDimensions(mode) (ordered) + scoreEnvelope (composes
composite+band; throws on bad dim by contract)
- types.ts: SCHEMA_VERSION 2->3; TrendRecord.score?
- store.ts: TrendInput.score?; addTrend persists first-sight (duplicate keeps it);
migrate comment v1->v2->v3 (logic unchanged, JSON.stringify preserves the field)
- item.ts: TrendItem.score?; normalizeItem validates (non-array score/dimensions + the
mode's five dims in [1,10]) -> structured error never throw, carries validated dims;
itemToInput -> scoreEnvelope (no throw on the capture path; direct call throws by contract)
- brief.ts: composite-primary comparator; band+mode render; exact ranking: descriptor
- cli.ts: capture persists score via itemToInput (doc-only); add/score paths unchanged
- agents/trend-spotter.md Step 4.5: capture batch carries the Step-2 dimensions
- gate: TRENDS_TESTS_FLOOR 104->146; new unconditional Section 16j; ASSERT floor 94->99
Tests: trends 146/146 (RED two-phase: logic-RED store/brief/cli; stub-first then
assertion-RED score/item). Gate green (Passed 114 / Failed 0; 113 checks >= 99).
Hook suite 139/139 untouched. Counts 27/19/29 unchanged. No new source file/agent/command.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VmHCQjJHUyWwxGAVVjNLgp
This commit is contained in:
parent
4d3b9f4711
commit
e169c78710
14 changed files with 829 additions and 40 deletions
|
|
@ -6,6 +6,8 @@ import { mkdtempSync, rmSync, readFileSync, existsSync, writeFileSync } from "no
|
|||
import { join } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
|
||||
import { SCHEMA_VERSION } from "../src/types.js";
|
||||
|
||||
// Resolve the package root (scripts/trends) so the subprocess `src/cli.ts` path + the
|
||||
// `tsx` loader resolve regardless of the runner's cwd.
|
||||
const trendsDir = fileURLToPath(new URL("..", import.meta.url));
|
||||
|
|
@ -97,7 +99,7 @@ describe("trends CLI — normalize/score subcommands (RE-R1 / Step 4)", () => {
|
|||
"tally must sum to the input size",
|
||||
);
|
||||
const persisted = JSON.parse(readFileSync(store, "utf8"));
|
||||
assert.equal(persisted.schemaVersion, 2);
|
||||
assert.equal(persisted.schemaVersion, SCHEMA_VERSION);
|
||||
assert.equal(persisted.trends.length, 1);
|
||||
assert.equal(persisted.trends[0].publishedAt, "2026-06-20");
|
||||
assert.match(persisted.trends[0].capturedAt, /^\d{4}-\d{2}-\d{2}$/);
|
||||
|
|
@ -157,6 +159,73 @@ describe("trends CLI — normalize/score subcommands (RE-R1 / Step 4)", () => {
|
|||
const { status } = run(["capture"], "");
|
||||
assert.equal(status, 2);
|
||||
});
|
||||
|
||||
// ── RE-R3a: capture persists the computed relevance score (SC7) ──
|
||||
test("a valid per-item score -> record carries the computed composite/priority (read back via list --json)", () => {
|
||||
const store = tmpStore();
|
||||
try {
|
||||
const batch = JSON.stringify([
|
||||
{
|
||||
source: "tavily",
|
||||
title: "Scored capture",
|
||||
url: "https://example.com/sc",
|
||||
topics: ["ai"],
|
||||
score: { mode: "kortform", dimensions: { pillar: 9, audience: 8, timing: 9, angle: 7, authority: 6 } },
|
||||
},
|
||||
]);
|
||||
const cap = run(["capture", "--store", store, "--json"], batch);
|
||||
assert.equal(cap.status, 0);
|
||||
const summary = JSON.parse(cap.stdout);
|
||||
assert.equal(summary.added, 1);
|
||||
assert.equal(summary.errors.length, 0);
|
||||
|
||||
const ls = run(["list", "--store", store, "--json"], "");
|
||||
assert.equal(ls.status, 0);
|
||||
const rows = JSON.parse(ls.stdout);
|
||||
assert.equal(rows.length, 1);
|
||||
// 9*.30 + 8*.25 + 9*.20 + 7*.15 + 6*.10 = 8.15 -> round1 8.1 (8.15*10 = 81.4999… in IEEE-754) -> Immediate
|
||||
assert.equal(rows[0].score.composite, 8.1);
|
||||
assert.equal(rows[0].score.priority, "Immediate");
|
||||
assert.equal(rows[0].score.mode, "kortform");
|
||||
assert.deepEqual(rows[0].score.dimensions, { pillar: 9, audience: 8, timing: 9, angle: 7, authority: 6 });
|
||||
} finally {
|
||||
rmSync(join(store, ".."), { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("a batch with one bad score (timing:99) -> that item in errors[], the valid one added, exit 0", () => {
|
||||
const store = tmpStore();
|
||||
try {
|
||||
const batch = JSON.stringify([
|
||||
{
|
||||
source: "tavily",
|
||||
title: "Good scored",
|
||||
url: "https://example.com/good",
|
||||
topics: ["ai"],
|
||||
score: { mode: "kortform", dimensions: { pillar: 8, audience: 7, timing: 9, angle: 6, authority: 5 } },
|
||||
},
|
||||
{
|
||||
source: "tavily",
|
||||
title: "Bad scored",
|
||||
url: "https://example.com/bad",
|
||||
topics: ["ai"],
|
||||
score: { mode: "kortform", dimensions: { pillar: 8, audience: 7, timing: 99, angle: 6, authority: 5 } },
|
||||
},
|
||||
]);
|
||||
const { status, stdout } = run(["capture", "--store", store, "--json"], batch);
|
||||
assert.equal(status, 0, "a bad score must not fail the run");
|
||||
const summary = JSON.parse(stdout);
|
||||
assert.equal(summary.added, 1, "the valid scored item is added");
|
||||
assert.equal(summary.errors.length, 1, "the bad-score item lands in errors[]");
|
||||
assert.equal(
|
||||
summary.added + summary.merged + summary.duplicates + summary.errors.length,
|
||||
2,
|
||||
"tally must sum to the input size",
|
||||
);
|
||||
} finally {
|
||||
rmSync(join(store, ".."), { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue