feat(linkedin-studio): trends store — research-engine inventory (§5 slice 1)
[skip-docs] internal plumbing — standalone store, no command/agent/pipeline
surface change until slice 2 wiring (mirrors specifics-bank slice 2). CLAUDE.md
"Telling"/counts untouched; lint stays 84/0/0.
Research-engine §5 (foundation layer) slice 1: the deterministic STORE half of
the persistent trend store — a topic-tagged, provenance-bearing inventory of
trend signals captured over time, so the research engine accumulates HISTORY
instead of starting amnesiac each session. Trend-side twin of the lived-specifics
bank (same store/dedup/query discipline; dedupe key is normalized title+URL, not
free-text content). Generic by architecture: nothing niche-specific lives here —
topics and source are free-form, decided upstream via config/profile.
scripts/trends/ (sibling to specifics-bank, same tsx convention):
- src/types.ts — TrendRecord/TrendStore schema (schemaVersion 1), minimal
generic core: title, url, source, capturedAt, topics[], optional summary
- src/store.ts — pure store: normalizeField, title+url-hash id (= dedupe key),
load/save, addTrend (dedupe + topic union on re-capture; first-sighting
source/capturedAt kept), queryByTopic (overlap-ranked then recency), history
(time-scoped, since/limit)
- src/cli.ts — add / query / list; default store under
${LINKEDIN_STUDIO_DATA:-~/.claude/linkedin-studio}/trends/ so trend history
survives plugin upgrades/reinstalls (M0 data-path seam)
- tests/store.test.ts — 21/21 green; tsc clean
- README + .gitignore for node_modules/build
Capture/scoring agent + MCP-first routing land in slice 2; the CI binding guard
is deferred to wiring, mirroring the specifics-bank timeline.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
527391ab47
commit
be21788321
9 changed files with 1343 additions and 0 deletions
146
scripts/trends/src/cli.ts
Normal file
146
scripts/trends/src/cli.ts
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
#!/usr/bin/env node
|
||||
/**
|
||||
* CLI for the persistent trend store (research-engine §5, foundation layer).
|
||||
*
|
||||
* node --import tsx src/cli.ts add --title "<t>" --url "<u>" --topics <a,b>
|
||||
* [--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]
|
||||
*
|
||||
* 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
|
||||
* polling + relevance-scoring itself lives upstream; this is the deterministic store.
|
||||
*
|
||||
* Exit code: 0 on success, 2 on usage error.
|
||||
*/
|
||||
|
||||
import {
|
||||
addTrend,
|
||||
defaultStorePath,
|
||||
history,
|
||||
loadStore,
|
||||
queryByTopic,
|
||||
saveStore,
|
||||
} from "./store.js";
|
||||
|
||||
function parseFlags(args: string[]): Record<string, string> {
|
||||
const out: Record<string, string> = {};
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const a = args[i];
|
||||
if (a.startsWith("--")) {
|
||||
const key = a.slice(2);
|
||||
const next = args[i + 1];
|
||||
if (next === undefined || next.startsWith("--")) {
|
||||
out[key] = "true";
|
||||
} else {
|
||||
out[key] = next;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function splitTopics(raw: string | undefined): string[] {
|
||||
if (!raw) return [];
|
||||
return raw
|
||||
.split(",")
|
||||
.map((t) => t.trim())
|
||||
.filter((t) => t.length > 0);
|
||||
}
|
||||
|
||||
function usage(msg: string): never {
|
||||
console.error(`error: ${msg}`);
|
||||
console.error(
|
||||
"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]",
|
||||
);
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
function today(): string {
|
||||
return new Date().toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
function main(): void {
|
||||
const [command, ...rest] = process.argv.slice(2);
|
||||
const flags = parseFlags(rest);
|
||||
const storePath = flags.store ?? defaultStorePath();
|
||||
const asJson = flags.json === "true";
|
||||
|
||||
if (command === "add") {
|
||||
const title = flags.title;
|
||||
if (!title || title === "true") usage('add needs --title "<text>"');
|
||||
const url = flags.url;
|
||||
if (!url || url === "true") usage('add needs --url "<url>"');
|
||||
const topics = splitTopics(flags.topics);
|
||||
if (topics.length === 0) usage("add needs --topics <a,b>");
|
||||
const store = loadStore(storePath);
|
||||
const res = addTrend(store, {
|
||||
title,
|
||||
url,
|
||||
source: flags.source && flags.source !== "true" ? flags.source : "manual",
|
||||
capturedAt: today(),
|
||||
topics,
|
||||
...(flags.summary && flags.summary !== "true" ? { summary: flags.summary } : {}),
|
||||
});
|
||||
saveStore(storePath, res.store);
|
||||
if (res.added) {
|
||||
console.log(`Added: ${title}`);
|
||||
} else {
|
||||
console.log(`Duplicate — already in store${res.merged ? " (topics unioned)" : ""}: ${title}`);
|
||||
}
|
||||
console.log(`Store: ${storePath} (${res.store.trends.length} trends)`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (command === "query") {
|
||||
const topics = splitTopics(flags.topics);
|
||||
if (topics.length === 0) usage("query needs --topics <a,b>");
|
||||
const hits = queryByTopic(loadStore(storePath), topics);
|
||||
if (asJson) {
|
||||
console.log(JSON.stringify(hits, null, 2));
|
||||
return;
|
||||
}
|
||||
if (hits.length === 0) {
|
||||
console.log(`No trends found for topics: ${topics.join(", ")}`);
|
||||
console.log("→ poll fresh signals (research engine), then `add` them.");
|
||||
return;
|
||||
}
|
||||
console.log(`${hits.length} trend(s) for: ${topics.join(", ")}`);
|
||||
for (const { trend, topicOverlap } of hits) {
|
||||
console.log(`\n · (overlap ${topicOverlap}) ${trend.title}`);
|
||||
console.log(` ${trend.url}`);
|
||||
console.log(` topics: ${trend.topics.join(", ")} — ${trend.source}, ${trend.capturedAt}`);
|
||||
if (trend.summary) console.log(` ${trend.summary}`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (command === "list") {
|
||||
const opts: { since?: string; limit?: number } = {};
|
||||
if (flags.since && flags.since !== "true") opts.since = flags.since;
|
||||
if (flags.limit && flags.limit !== "true") {
|
||||
const n = Number.parseInt(flags.limit, 10);
|
||||
if (Number.isNaN(n) || n < 0) usage("--limit must be a non-negative integer");
|
||||
opts.limit = n;
|
||||
}
|
||||
const rows = history(loadStore(storePath), opts);
|
||||
if (asJson) {
|
||||
console.log(JSON.stringify(rows, null, 2));
|
||||
return;
|
||||
}
|
||||
const scope = opts.since ? ` since ${opts.since}` : "";
|
||||
console.log(`Store: ${storePath} — ${rows.length} trend(s)${scope}`);
|
||||
for (const t of rows) {
|
||||
console.log(` · ${t.capturedAt} ${t.title} {${t.topics.join(", ")}}`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
usage(command ? `unknown command: ${command}` : "no command given");
|
||||
}
|
||||
|
||||
main();
|
||||
Loading…
Add table
Add a link
Reference in a new issue