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

@ -6,6 +6,7 @@
* [--source <s>] [--summary "<s>"] [--store <path>]
* node --import tsx src/cli.ts query --topics <a,b> [--store <path>] [--json]
* node --import tsx src/cli.ts list [--since <YYYY-MM-DD>] [--limit <n>] [--store <path>] [--json]
* node --import tsx src/cli.ts status [--store <path>] [--json]
*
* The capture agent (research-engine) calls `add` to fold a freshly-polled trend
* into the store, and `query`/`list` to reason over accumulated history. The
@ -19,6 +20,7 @@ import {
defaultStorePath,
history,
loadStore,
newestCaptureDate,
queryByTopic,
saveStore,
} from "./store.js";
@ -55,7 +57,8 @@ function usage(msg: string): never {
"usage:\n" +
' add --title "<t>" --url "<u>" --topics <a,b> [--source <s>] [--summary "<s>"] [--store <path>]\n' +
" query --topics <a,b> [--store <path>] [--json]\n" +
" list [--since <YYYY-MM-DD>] [--limit <n>] [--store <path>] [--json]",
" list [--since <YYYY-MM-DD>] [--limit <n>] [--store <path>] [--json]\n" +
" status [--store <path>] [--json]",
);
process.exit(2);
}
@ -64,6 +67,11 @@ function today(): string {
return new Date().toISOString().slice(0, 10);
}
/** Whole days from one ISO date to another (floor); negative if `from` is later. */
function daysBetween(fromIso: string, toIso: string): number {
return Math.floor((new Date(toIso).getTime() - new Date(fromIso).getTime()) / 86400000);
}
function main(): void {
const [command, ...rest] = process.argv.slice(2);
const flags = parseFlags(rest);
@ -140,6 +148,24 @@ function main(): void {
return;
}
if (command === "status") {
const store = loadStore(storePath);
const newest = newestCaptureDate(store);
const daysStale = newest === null ? null : daysBetween(newest, today());
if (asJson) {
console.log(JSON.stringify({ store: storePath, count: store.trends.length, newest, daysStale }));
return;
}
console.log(`Store: ${storePath}`);
console.log(` trends: ${store.trends.length}`);
if (newest === null) {
console.log(" newest: — (empty store; no captures yet)");
} else {
console.log(` newest: ${newest} (${daysStale}d ago)`);
}
return;
}
usage(command ? `unknown command: ${command}` : "no command given");
}