Lift the research engine's deterministic core out of agents/trend-spotter.md prose into pure, tested TypeScript under scripts/trends/, behind a CLI seam the agent calls. - B1 src/item.ts: TrendItem ingress envelope + normalizeItem/normalizeItems (required-field validation, topic normalize+dedupe via store's normalizeField, optional publishedAt ISO-validate). No id (store derives it); no store bridge (capturedAt injection is R2). - B2 src/score.ts: per-mode weight consts mirroring the SSOT (references/trend-scoring-modes.md), composite (weighted sum, [1,10] guard), band (5-band map + exact SSOT action strings), triage (keep>=threshold, rank desc, annotate composite+band). Owns ONLY the arithmetic; the five judgment scores stay model-side. - CLI normalize/score: JSON payload on STDIN, JSON to stdout (the existing --json output toggle is untouched); exit 2 on bad invocation, 0 otherwise. - Wire trend-spotter.md to name 'src/cli.ts score' as the deterministic-step owner (prose pointer; the agent still supplies the five scores). Domain-general. - Gate: TRENDS_TESTS_FLOOR 24->62; new unconditional Section 16g (score.ts both-mode weight-sets + trend-spotter scorer-pointer + non-vacuity self-test); ASSERT_BASELINE_FLOOR 84->87. TDD: logic-RED proven (33/34 item+score fail on assertions, not module-not-found), then GREEN (trends suite 62/62); CLI RED 2/4 -> GREEN 4/4. Full gate 102/0/0. No store-schema change (SCHEMA_VERSION stays 1). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VmHCQjJHUyWwxGAVVjNLgp |
||
|---|---|---|
| .. | ||
| src | ||
| tests | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
linkedin-trends-store
Persistent trend store — the foundation layer of the research engine (retning §5). A topic-tagged, provenance-bearing inventory of trend signals captured over time, so the engine accumulates history instead of starting amnesiac each session.
Twin of scripts/specifics-bank: same deterministic
store / dedup / query discipline, different dedupe key — a trend is identified by
its normalized title+URL, not by free-text content.
Generic by architecture
Nothing niche-specific lives here. A TrendRecord carries free-form topics
tags and a free-form source string; which topics matter and which sources
to poll are decided upstream (config/profile + the capture agent), never
hard-coded in this module. The same store serves any niche.
Data location
The store lives under the per-user data dir (M0 data-path convention), so trend history survives plugin upgrades/reinstalls:
${LINKEDIN_STUDIO_DATA:-$HOME/.claude/linkedin-studio}/trends/trends.json
LINKEDIN_STUDIO_DATA overrides the root. No path is hard-coded in prose.
Record shape (minimal generic core)
interface TrendRecord {
id: string; // sha256(normalized title+url).slice(0,12) — also the dedupe key
title: string; // headline, verbatim
url: string; // source URL, verbatim
source: string; // "tavily" | "websearch" | "manual" | <mcp-name>
capturedAt: string; // ISO-8601 date
topics: string[]; // query tags; unioned across re-captures
summary?: string; // optional, verbatim
}
Fields (relevance score, first-mover timing, status) can be added in a later slice without breaking the shape.
CLI
# Capture a freshly-polled trend (dedupes on title+url; unions topics on re-capture)
node --import tsx src/cli.ts add \
--title "Agentic workflows hit production" \
--url "https://example.com/agentic" \
--topics "agents,engineering" --source tavily \
--summary "Teams ship multi-step agents past the demo stage."
# Topic-scoped history — trends matching these topics, ranked by overlap then recency
node --import tsx src/cli.ts query --topics "agents,engineering" [--json]
# Time-scoped history — newest first, optionally windowed/capped
node --import tsx src/cli.ts list [--since 2026-06-01] [--limit 10] [--json]
Re-running add with the same title+url never appends a duplicate.
Tests
cd scripts/trends
npm install
npm test # deterministic store: normalize/id, load/save, dedup+union, query, history
npm run build