feat(linkedin-studio): specifics-bank store — lived-specifics inventory (fix #2 slice 1)
Fix #2 (kilde-så-draft) slice 1: the deterministic STORE half of the lived-specifics bank — the operator's real, un-generatable raw material (measured number / named-but-real case / what broke / contrarian opinion / mind-change), so drafts start grounded instead of hollow (retning §3; dream-spec "Lived-Specifics Extraction", the single biggest missing upstream piece for the authenticity thesis). scripts/specifics-bank/ (sibling to contract-gate, same tsx convention): - src/types.ts — Specific/Bank schema (schemaVersion 1), un-generatable taxonomy - src/bank.ts — pure store: normalizeContent, content-hash id (= dedupe key), load/save, addSpecific (dedupe + topicTag union on re-capture), queryByTopic (active-only, ranked by tag overlap then recency) - src/cli.ts — query / add / list; default bank under ${LINKEDIN_STUDIO_DATA:-~/.claude/linkedin-studio}/specifics-bank/ so it survives plugin upgrades/reinstalls (M0 data-path seam) - tests/bank.test.ts — 15/15 green; tsc clean - README + .gitignore for node_modules/build Content is stored verbatim; never AI-generated. The elicitation interview (refuses vague answers; abstrakt/ekstern escape hatches) lands in slice 3 (/linkedin:newsletter Step 1.5). Forward-compatible with the profile-evolution / "second brain" architecture. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
e26d9fb659
commit
b390b87ad5
9 changed files with 1239 additions and 0 deletions
151
scripts/specifics-bank/src/cli.ts
Normal file
151
scripts/specifics-bank/src/cli.ts
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
#!/usr/bin/env node
|
||||
/**
|
||||
* CLI for the lived-specifics bank (Fix #2 — kilde-så-draft).
|
||||
*
|
||||
* node --import tsx src/cli.ts query --tags <a,b> [--bank <path>] [--json]
|
||||
* node --import tsx src/cli.ts add --type <t> --content "<text>" --tags <a,b>
|
||||
* [--source <s>] [--verification <v>] [--bank <path>]
|
||||
* node --import tsx src/cli.ts list [--bank <path>] [--json]
|
||||
*
|
||||
* The command layer (Step 1.5) calls `query` to surface inventory the operator
|
||||
* already has for an edition's topics, and `add` to fold newly-elicited material
|
||||
* back in. Deterministic store; the elicitation interview itself lives upstream.
|
||||
*
|
||||
* Exit code: 0 on success, 2 on usage error.
|
||||
*/
|
||||
|
||||
import {
|
||||
addSpecific,
|
||||
defaultBankPath,
|
||||
loadBank,
|
||||
queryByTopic,
|
||||
saveBank,
|
||||
} from "./bank.js";
|
||||
import type { SpecificType, Verification } from "./types.js";
|
||||
|
||||
const VALID_TYPES: SpecificType[] = [
|
||||
"number",
|
||||
"named-case",
|
||||
"what-broke",
|
||||
"contrarian",
|
||||
"mind-change",
|
||||
"other",
|
||||
];
|
||||
const VALID_VERIFICATION: Verification[] = ["verified", "unverified", "n/a"];
|
||||
|
||||
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 splitTags(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" +
|
||||
" query --tags <a,b> [--bank <path>] [--json]\n" +
|
||||
' add --type <t> --content "<text>" --tags <a,b> [--source <s>] [--verification <v>] [--bank <path>]\n' +
|
||||
" list [--bank <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 bankPath = flags.bank ?? defaultBankPath();
|
||||
const asJson = flags.json === "true";
|
||||
|
||||
if (command === "query") {
|
||||
const tags = splitTags(flags.tags);
|
||||
if (tags.length === 0) usage("query needs --tags <a,b>");
|
||||
const hits = queryByTopic(loadBank(bankPath), tags);
|
||||
if (asJson) {
|
||||
console.log(JSON.stringify(hits, null, 2));
|
||||
return;
|
||||
}
|
||||
if (hits.length === 0) {
|
||||
console.log(`No lived specifics found for tags: ${tags.join(", ")}`);
|
||||
console.log("→ elicit fresh material from the operator (Step 1.5), then `add` it.");
|
||||
return;
|
||||
}
|
||||
console.log(`${hits.length} lived specific(s) for: ${tags.join(", ")}`);
|
||||
for (const { specific, tagOverlap } of hits) {
|
||||
const v = specific.verification === "verified" ? "" : ` [${specific.verification}]`;
|
||||
console.log(`\n · (${specific.type}, overlap ${tagOverlap})${v} ${specific.content}`);
|
||||
console.log(` tags: ${specific.topicTags.join(", ")} — from ${specific.provenance.source}`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (command === "add") {
|
||||
const type = flags.type as SpecificType;
|
||||
if (!VALID_TYPES.includes(type)) usage(`--type must be one of: ${VALID_TYPES.join(", ")}`);
|
||||
const content = flags.content;
|
||||
if (!content || content === "true") usage("add needs --content \"<text>\"");
|
||||
const tags = splitTags(flags.tags);
|
||||
if (tags.length === 0) usage("add needs --tags <a,b>");
|
||||
const verification = (flags.verification as Verification) ?? "unverified";
|
||||
if (!VALID_VERIFICATION.includes(verification)) {
|
||||
usage(`--verification must be one of: ${VALID_VERIFICATION.join(", ")}`);
|
||||
}
|
||||
const bank = loadBank(bankPath);
|
||||
const res = addSpecific(bank, {
|
||||
type,
|
||||
content,
|
||||
topicTags: tags,
|
||||
provenance: { capturedAt: today(), source: flags.source ?? "manual" },
|
||||
verification,
|
||||
});
|
||||
saveBank(bankPath, res.bank);
|
||||
if (res.added) {
|
||||
console.log(`Added (${type}): ${content}`);
|
||||
} else {
|
||||
console.log(`Duplicate — already in bank${res.merged ? " (tags unioned)" : ""}: ${content}`);
|
||||
}
|
||||
console.log(`Bank: ${bankPath} (${res.bank.specifics.length} specifics)`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (command === "list") {
|
||||
const bank = loadBank(bankPath);
|
||||
if (asJson) {
|
||||
console.log(JSON.stringify(bank, null, 2));
|
||||
return;
|
||||
}
|
||||
console.log(`Bank: ${bankPath} — ${bank.specifics.length} specific(s)`);
|
||||
for (const s of bank.specifics) {
|
||||
const flag = s.status === "active" ? "" : ` (${s.status})`;
|
||||
console.log(` · [${s.type}]${flag} ${s.content} {${s.topicTags.join(", ")}}`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
usage(command ? `unknown command: ${command}` : "no command given");
|
||||
}
|
||||
|
||||
main();
|
||||
Loading…
Add table
Add a link
Reference in a new issue