feat(linkedin-studio): trend-store staleness nudge — SessionStart B-S3 [skip-docs]

SessionStart now warns (>=7d, warn-only) when the persistent trend store's
newest capture is stale, firing ONLY when the store already holds captures
(a never-scanned user is never nagged). Neutral wording — "scan for trends"
hits trend-spotter's own trigger; no hardcoded beat (de-niche invariant).

- store.ts: newestCaptureDate() — pure max-capturedAt staleness signal (SSOT)
- cli.ts: status [--json] subcommand (count + newest + daysStale)
- session-start.mjs: trendsNewestCapture() reads trends.json as raw JSON
  (no tsx spawn at session start) + the reminder line, beside import-staleness
- tests: +3 store tests (newestCaptureDate) + hook subprocess test (3 cases:
  >=7d fires, <7d silent, absent/empty silent + no crash)
- test-runner.sh: trends floor 21->24

Verified: trends 24/24 · all hook tests 131/131 · gate 89/0/0 · real render
confirms "Trend signals are N days old. Scan for trends…".

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RigJBiRFNtFZKCz21qNbQ4
This commit is contained in:
Kjell Tore Guttormsen 2026-06-23 12:23:53 +02:00
commit 0907b2b92d
6 changed files with 186 additions and 2 deletions

View file

@ -13,6 +13,7 @@ import {
addTrend,
queryByTopic,
history,
newestCaptureDate,
} from "../src/store.js";
import { SCHEMA_VERSION } from "../src/types.js";
import type { TrendStore } from "../src/types.js";
@ -294,4 +295,39 @@ describe("trends store", () => {
assert.deepEqual(h.map((t) => t.title), ["Newest"]);
});
});
describe("newestCaptureDate (B-S3 staleness signal)", () => {
test("empty store → null (no captures yet → no nudge)", () => {
assert.equal(newestCaptureDate(emptyStore()), null);
});
test("single trend → its capturedAt", () => {
const store = addTrend(emptyStore(), {
title: "Solo",
url: "https://example.com/solo",
source: "tavily",
capturedAt: "2026-06-05",
topics: ["x"],
}).store;
assert.equal(newestCaptureDate(store), "2026-06-05");
});
test("multiple trends → the max (newest) capturedAt, regardless of insertion order", () => {
let store = emptyStore();
for (const [title, capturedAt] of [
["Middle", "2026-05-01"],
["Newest", "2026-06-01"],
["Oldest", "2026-04-01"],
] as const) {
store = addTrend(store, {
title,
url: `https://example.com/${title}`,
source: "tavily",
capturedAt,
topics: ["x"],
}).store;
}
assert.equal(newestCaptureDate(store), "2026-06-01");
});
});
});