@kanadego/dsh-heartbeat 2.3.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +70 -81
  2. package/USAGE-GUIDE.md +357 -0
  3. package/dist/{chunk-43Q42HWH.js → chunk-AJ5JAQVB.js} +13 -2
  4. package/dist/chunk-AJ5JAQVB.js.map +1 -0
  5. package/dist/chunk-CRRN6UD3.js +389 -0
  6. package/dist/chunk-CRRN6UD3.js.map +1 -0
  7. package/dist/{chunk-K47VV6IQ.js → chunk-ERRPMYKB.js} +163 -153
  8. package/dist/chunk-ERRPMYKB.js.map +1 -0
  9. package/dist/chunk-L54R23O2.js +262 -0
  10. package/dist/chunk-L54R23O2.js.map +1 -0
  11. package/dist/{chunk-HSTGRQLP.js → chunk-MHRAPKES.js} +406 -66
  12. package/dist/chunk-MHRAPKES.js.map +1 -0
  13. package/dist/{chunk-ABFO4QII.js → chunk-RPWQZYNW.js} +603 -157
  14. package/dist/chunk-RPWQZYNW.js.map +1 -0
  15. package/dist/cli/index.js +160 -23
  16. package/dist/cli/index.js.map +1 -1
  17. package/dist/index.d.ts +6 -0
  18. package/dist/index.js +98 -22
  19. package/dist/index.js.map +1 -1
  20. package/dist/{migrate-6HH2ZARV.js → migrate-25F53XIC.js} +4 -2
  21. package/dist/{orchestrator-OJJM5QSV.js → orchestrator-4PJD7QYO.js} +11 -6
  22. package/dist/snapshot-J6LKNY57.js +27 -0
  23. package/dist/store-HM6ZMFKS.js +45 -0
  24. package/package.json +6 -3
  25. package/dist/chunk-43Q42HWH.js.map +0 -1
  26. package/dist/chunk-ABFO4QII.js.map +0 -1
  27. package/dist/chunk-HSTGRQLP.js.map +0 -1
  28. package/dist/chunk-JIRQ36F7.js +0 -87
  29. package/dist/chunk-JIRQ36F7.js.map +0 -1
  30. package/dist/chunk-K47VV6IQ.js.map +0 -1
  31. package/dist/chunk-KGOC6EX4.js +0 -413
  32. package/dist/chunk-KGOC6EX4.js.map +0 -1
  33. package/dist/chunk-QOLKUYQ3.js +0 -393
  34. package/dist/chunk-QOLKUYQ3.js.map +0 -1
  35. package/dist/pool-QTY2MI56.js +0 -49
  36. package/dist/snapshot-6DFNGXTR.js +0 -16
  37. /package/dist/{migrate-6HH2ZARV.js.map → migrate-25F53XIC.js.map} +0 -0
  38. /package/dist/{orchestrator-OJJM5QSV.js.map → orchestrator-4PJD7QYO.js.map} +0 -0
  39. /package/dist/{pool-QTY2MI56.js.map → snapshot-J6LKNY57.js.map} +0 -0
  40. /package/dist/{snapshot-6DFNGXTR.js.map → store-HM6ZMFKS.js.map} +0 -0
@@ -1,393 +0,0 @@
1
- import {
2
- loadEncryptedText,
3
- saveEncryptedText,
4
- withFileLock
5
- } from "./chunk-GOLMRQRW.js";
6
-
7
- // src/seeds/pool.ts
8
- import path from "path";
9
-
10
- // src/seeds/types.ts
11
- function emptySeedDb() {
12
- return { seq: 0, seeds: [] };
13
- }
14
- var SEED_SOURCE_DEFAULT_CONFIDENCE = {
15
- hand: 1,
16
- profile: 0.7,
17
- chat: 0.6,
18
- screen: 0.4,
19
- browse: 0.4,
20
- bilibili: 0.4
21
- };
22
-
23
- // src/seeds/pool.ts
24
- var DAY_MS = 864e5;
25
- var NO_AUDIT = () => {
26
- };
27
- function emit(audit, entry) {
28
- try {
29
- audit(entry);
30
- } catch {
31
- }
32
- }
33
- var SEED_CATEGORY_CAPS = { topic: 16, chat: 14 };
34
- var SEED_SOURCE_CAPS = { bilibili: 6 };
35
- var CATEGORY_VALUES = ["topic", "chat"];
36
- function normalizeCategory(v) {
37
- return typeof v === "string" && CATEGORY_VALUES.includes(v) ? v : "topic";
38
- }
39
- var SEED_SIMILARITY_THRESHOLD = 0.85;
40
- var DEDUP_ARCHIVE_WINDOW_MS = 30 * DAY_MS;
41
- var DEDUP_ARCHIVE_MAX = 50;
42
- var DEDUP_SIMILAR_MIN_CHARS = 12;
43
- function normalizeSeedText(s) {
44
- return s.normalize("NFKC").toLowerCase().replace(/[\s\p{P}\p{S}]+/gu, "");
45
- }
46
- function seedSimilarity(a, b) {
47
- const na = normalizeSeedText(a);
48
- const nb = normalizeSeedText(b);
49
- if (na === nb) return 1;
50
- if (na.length < 2 || nb.length < 2) return 0;
51
- const gramCount = (t) => {
52
- const m = /* @__PURE__ */ new Map();
53
- for (let i = 0; i < t.length - 1; i++) {
54
- const g = t.slice(i, i + 2);
55
- m.set(g, (m.get(g) ?? 0) + 1);
56
- }
57
- return m;
58
- };
59
- const A = gramCount(na);
60
- const B = gramCount(nb);
61
- let inter = 0;
62
- let sizeA = 0;
63
- let sizeB = 0;
64
- for (const c of A.values()) sizeA += c;
65
- for (const c of B.values()) sizeB += c;
66
- for (const [g, c] of A) inter += Math.min(c, B.get(g) ?? 0);
67
- return 2 * inter / (sizeA + sizeB);
68
- }
69
- function recentArchived(db, now) {
70
- return archivedSeeds(db).filter((s) => now - parseIso(s.retiredAt ?? "") <= DEDUP_ARCHIVE_WINDOW_MS).sort((a, b) => parseIso(b.retiredAt ?? "") - parseIso(a.retiredAt ?? "")).slice(0, DEDUP_ARCHIVE_MAX);
71
- }
72
- var TTL_KEYS = ["news", "fandom", "scene", "promise"];
73
- function normalizeTag(tag) {
74
- if (tag && TTL_KEYS.includes(tag)) return tag;
75
- return "scene";
76
- }
77
- function parseIso(v) {
78
- const t = Date.parse(v);
79
- return Number.isFinite(t) ? t : 0;
80
- }
81
- function seedsFilePath(dataDir) {
82
- return path.join(dataDir, "seeds.jsonl");
83
- }
84
- function loadPool(guard, file) {
85
- const raw = loadEncryptedText(guard, file);
86
- if (raw === null) return emptySeedDb();
87
- const db = emptySeedDb();
88
- for (const line of raw.split("\n")) {
89
- const trimmed = line.trim();
90
- if (!trimmed) continue;
91
- try {
92
- const obj = JSON.parse(trimmed);
93
- if (typeof obj.id === "string" && obj.id.startsWith("s")) {
94
- obj.category = normalizeCategory(obj.category);
95
- db.seeds.push(obj);
96
- const n = Number(obj.id.slice(1));
97
- if (Number.isFinite(n) && n > db.seq) db.seq = n;
98
- }
99
- } catch {
100
- }
101
- }
102
- return db;
103
- }
104
- function savePool(guard, file, db) {
105
- const body = db.seeds.map((s) => JSON.stringify(s)).join("\n");
106
- saveEncryptedText(guard, file, body ? body + "\n" : "");
107
- }
108
- function update(guard, file, fn) {
109
- return withFileLock(file, () => fn(loadPool(guard, file)));
110
- }
111
- var activeSeeds = (db) => db.seeds.filter((s) => s.status === "active");
112
- var archivedSeeds = (db) => db.seeds.filter((s) => s.status === "archived");
113
- function evictionScore(seed, policy, now) {
114
- const ttlDays = policy.seeds.ttlDays[seed.tag] || 14;
115
- const daysStale = Math.max(0, (now - parseIso(seed.lastEvidenceAt)) / DAY_MS);
116
- const freshness = Math.max(0, 1 - daysStale / ttlDays);
117
- const unused = seed.used === 0 ? 1 : 1 / seed.used;
118
- const w = policy.seeds.scoreWeights;
119
- return freshness * w.freshness + unused * w.unused + seed.confidence * w.confidence;
120
- }
121
- function pickEvictionVictim(db, policy, now, category, source) {
122
- const actives = activeSeeds(db).filter(
123
- (s) => (category === void 0 || normalizeCategory(s.category) === category) && (source === void 0 || s.source === source)
124
- );
125
- if (actives.length === 0) return null;
126
- const unprotected = actives.filter((s) => !s.protected);
127
- const candidates = unprotected.length > 0 ? unprotected : actives;
128
- let worst = null;
129
- let worstScore = Number.POSITIVE_INFINITY;
130
- for (const s of candidates) {
131
- const score = evictionScore(s, policy, now);
132
- if (score < worstScore) {
133
- worstScore = score;
134
- worst = s;
135
- }
136
- }
137
- return worst;
138
- }
139
- function archiveSeed(seed, reason, now) {
140
- seed.status = "archived";
141
- seed.retireReason = reason;
142
- seed.retiredAt = new Date(now).toISOString();
143
- }
144
- function retireLimit(s, policy) {
145
- return normalizeCategory(s.category) === "chat" ? 1 : policy.seeds.retireAfterUsed;
146
- }
147
- function isConsumed(s, policy, prevUsedAt, sinceEvidence) {
148
- if (s.used < retireLimit(s, policy)) return false;
149
- return !(prevUsedAt > 0 && sinceEvidence > prevUsedAt);
150
- }
151
- function addSeed(guard, file, policy, input, now = Date.now(), audit = NO_AUDIT) {
152
- return withFileLock(file, () => addSeedLocked(guard, file, policy, input, now, audit));
153
- }
154
- function addSeedLocked(guard, file, policy, input, now, audit) {
155
- const db = loadPool(guard, file);
156
- const text = input.text.trim();
157
- if (!text) throw new Error("seed text must not be empty");
158
- const tag = normalizeTag(input.tag);
159
- const source = input.source ?? "chat";
160
- const category = normalizeCategory(input.category ?? (source === "chat" ? "chat" : "topic"));
161
- const confidence = input.confidence ?? SEED_SOURCE_DEFAULT_CONFIDENCE[source];
162
- const textNorm = normalizeSeedText(text);
163
- for (const cand of [...activeSeeds(db), ...recentArchived(db, now)]) {
164
- if (cand.text === text) {
165
- emit(audit, { event: "seed_duplicate", id: cand.id, reason: "exact" });
166
- return { kind: "duplicate", seed: cand, reason: "exact" };
167
- }
168
- const candNorm = normalizeSeedText(cand.text);
169
- if (candNorm === textNorm) {
170
- emit(audit, { event: "seed_duplicate", id: cand.id, reason: "normalized", similarity: 1 });
171
- return { kind: "duplicate", seed: cand, reason: "normalized" };
172
- }
173
- if (textNorm.length < DEDUP_SIMILAR_MIN_CHARS || candNorm.length < DEDUP_SIMILAR_MIN_CHARS) continue;
174
- const sim = seedSimilarity(cand.text, text);
175
- if (sim <= SEED_SIMILARITY_THRESHOLD) continue;
176
- emit(audit, { event: "seed_duplicate", id: cand.id, reason: "similar", similarity: Number(sim.toFixed(3)) });
177
- return { kind: "duplicate", seed: cand, reason: "similar" };
178
- }
179
- const nowIso = new Date(now).toISOString();
180
- const ttlDays = input.ttlDaysOverride ?? (policy.seeds.ttlDays[tag] || 14);
181
- const ttlMs = ttlDays * DAY_MS;
182
- const sameTopic = activeSeeds(db).filter((s) => s.topic === (input.topic ?? text.slice(0, 24)));
183
- let seed;
184
- if (sameTopic.length > 0 && !input.noMerge) {
185
- const kept = sameTopic[0];
186
- kept.text = text;
187
- kept.tag = tag;
188
- kept.source = source;
189
- kept.category = normalizeCategory(input.category ?? kept.category ?? category);
190
- kept.confidence = Math.max(kept.confidence, confidence);
191
- kept.used = sameTopic.reduce((acc, s) => acc + s.used, 0);
192
- kept.lastEvidenceAt = [kept.lastEvidenceAt, nowIso, ...sameTopic.map((s) => s.lastEvidenceAt)].reduce((a, b) => parseIso(b) > parseIso(a) ? b : a);
193
- kept.expiresAt = new Date(Math.max(parseIso(kept.expiresAt), now + ttlMs)).toISOString();
194
- kept.protected = kept.protected || source === "hand" || source === "profile" && confidence >= 0.7;
195
- for (const extra of sameTopic.slice(1)) {
196
- extra.status = "archived";
197
- extra.retireReason = "completed";
198
- extra.retiredAt = nowIso;
199
- emit(audit, { event: "seed_retired", id: extra.id, reason: "completed", via: "merge", into: kept.id });
200
- }
201
- seed = kept;
202
- if (activeSeeds(db).length > policy.seeds.maxActive) {
203
- const victim = pickEvictionVictim(db, policy, now, normalizeCategory(kept.category));
204
- if (victim && victim.id !== kept.id) {
205
- archiveSeed(victim, "pool_cap", now);
206
- emit(audit, { event: "seed_added", id: kept.id, kind: "merged", tag: kept.tag, source: kept.source, category: kept.category, confidence: kept.confidence, mergedFrom: sameTopic.length - 1 });
207
- emit(audit, { event: "seed_retired", id: victim.id, reason: "pool_cap", via: "merge", into: kept.id });
208
- savePool(guard, file, db);
209
- return { kind: "merged", seed: kept, evicted: victim };
210
- }
211
- }
212
- emit(audit, { event: "seed_added", id: kept.id, kind: "merged", tag: kept.tag, source: kept.source, category: kept.category, confidence: kept.confidence, mergedFrom: sameTopic.length - 1 });
213
- savePool(guard, file, db);
214
- return { kind: "merged", seed: kept };
215
- }
216
- const sourceVictims = [];
217
- const sourceCap = SEED_SOURCE_CAPS[source];
218
- if (sourceCap !== void 0) {
219
- while (activeSeeds(db).filter((s) => s.source === source).length >= sourceCap) {
220
- const victim = pickEvictionVictim(db, policy, now, void 0, source);
221
- if (!victim) break;
222
- archiveSeed(victim, "source_cap", now);
223
- sourceVictims.push(victim);
224
- }
225
- }
226
- let evicted;
227
- if (sourceVictims.length > 0) {
228
- evicted = sourceVictims[sourceVictims.length - 1];
229
- } else {
230
- const catCount = activeSeeds(db).filter((s) => normalizeCategory(s.category) === category).length;
231
- if (catCount >= SEED_CATEGORY_CAPS[category]) {
232
- const victim = pickEvictionVictim(db, policy, now, category);
233
- if (victim) {
234
- archiveSeed(victim, "pool_cap", now);
235
- evicted = victim;
236
- }
237
- }
238
- if (!evicted && activeSeeds(db).length >= policy.seeds.maxActive) {
239
- const victim = pickEvictionVictim(db, policy, now, category);
240
- if (victim) {
241
- archiveSeed(victim, "pool_cap", now);
242
- evicted = victim;
243
- }
244
- }
245
- }
246
- db.seq += 1;
247
- seed = {
248
- id: `s${db.seq}`,
249
- text,
250
- topic: input.topic ?? text.slice(0, 24),
251
- tag,
252
- source,
253
- category,
254
- confidence,
255
- protected: source === "hand" || source === "profile" && confidence >= 0.7,
256
- used: 0,
257
- bornAt: nowIso,
258
- expiresAt: new Date(now + ttlMs).toISOString(),
259
- ...input.ttlDaysOverride !== void 0 ? { ttlDaysOverride: input.ttlDaysOverride } : {},
260
- lastUsedAt: null,
261
- lastEvidenceAt: nowIso,
262
- status: "active"
263
- };
264
- db.seeds.push(seed);
265
- emit(audit, { event: "seed_added", id: seed.id, kind: "added", tag: seed.tag, source: seed.source, category: seed.category, confidence: seed.confidence });
266
- for (const victim of sourceVictims) {
267
- emit(audit, { event: "seed_retired", id: victim.id, reason: "source_cap", via: "add", into: seed.id });
268
- }
269
- if (evicted && sourceVictims.length === 0) {
270
- emit(audit, { event: "seed_retired", id: evicted.id, reason: "pool_cap", via: "add", into: seed.id });
271
- }
272
- savePool(guard, file, db);
273
- return { kind: "added", seed, evicted };
274
- }
275
- function gcPool(guard, file, policy, now = Date.now(), audit = NO_AUDIT) {
276
- return update(guard, file, (db) => {
277
- const report = { consumed: 0, expired: 0, coldBench: 0, activeAfter: 0, archiveTrimmed: 0 };
278
- for (const s of activeSeeds(db)) {
279
- const ageMs = now - parseIso(s.bornAt);
280
- const sinceEvidence = parseIso(s.lastEvidenceAt);
281
- const sinceUsed = s.lastUsedAt ? parseIso(s.lastUsedAt) : 0;
282
- if (isConsumed(s, policy, sinceUsed, sinceEvidence)) {
283
- archiveSeed(s, "consumed", now);
284
- report.consumed += 1;
285
- emit(audit, { event: "seed_retired", id: s.id, reason: "consumed", via: "gc", used: s.used });
286
- } else if (now > parseIso(s.expiresAt)) {
287
- archiveSeed(s, "expired", now);
288
- report.expired += 1;
289
- emit(audit, { event: "seed_retired", id: s.id, reason: "expired", via: "gc", used: s.used });
290
- } else if (s.used === 0 && ageMs >= policy.seeds.coldBenchDays * DAY_MS) {
291
- archiveSeed(s, "cold_bench", now);
292
- report.coldBench += 1;
293
- emit(audit, { event: "seed_retired", id: s.id, reason: "cold_bench", via: "gc", used: s.used });
294
- }
295
- }
296
- const archived = db.seeds.filter((s) => s.status === "archived");
297
- if (archived.length > policy.seeds.archiveCap) {
298
- const drop = [...archived].sort((a, b) => parseIso(a.retiredAt ?? "") - parseIso(b.retiredAt ?? "")).slice(0, archived.length - policy.seeds.archiveCap);
299
- const dropped = new Set(drop.map((s) => s.id));
300
- db.seeds = db.seeds.filter((s) => !dropped.has(s.id));
301
- report.archiveTrimmed = drop.length;
302
- emit(audit, { event: "seed_archive_trimmed", count: drop.length, ids: drop.slice(0, 50).map((s) => s.id) });
303
- }
304
- report.activeAfter = activeSeeds(db).length;
305
- savePool(guard, file, db);
306
- return report;
307
- });
308
- }
309
- function surfaceSeed(guard, file, policy, id, now = Date.now(), audit = NO_AUDIT) {
310
- return update(guard, file, (db) => {
311
- const s = db.seeds.find((x) => x.id === id && x.status === "active");
312
- if (!s) return null;
313
- const prevUsedAt = s.lastUsedAt ? parseIso(s.lastUsedAt) : 0;
314
- s.used += 1;
315
- s.lastUsedAt = new Date(now).toISOString();
316
- if (isConsumed(s, policy, prevUsedAt, parseIso(s.lastEvidenceAt))) {
317
- archiveSeed(s, "consumed", now);
318
- emit(audit, { event: "seed_retired", id: s.id, reason: "consumed", via: "surface", used: s.used });
319
- }
320
- savePool(guard, file, db);
321
- return s;
322
- });
323
- }
324
- function archiveSeedById(guard, file, id, reason = "completed", now = Date.now(), audit = NO_AUDIT) {
325
- return update(guard, file, (db) => {
326
- const s = db.seeds.find((x) => x.id === id && x.status === "active");
327
- if (!s) return null;
328
- archiveSeed(s, reason, now);
329
- emit(audit, { event: "seed_retired", id: s.id, reason, via: "manual" });
330
- savePool(guard, file, db);
331
- return s;
332
- });
333
- }
334
- function restoreSeed(guard, file, policy, id, now = Date.now(), audit = NO_AUDIT) {
335
- return update(guard, file, (db) => {
336
- const s = db.seeds.find((x) => x.id === id && x.status === "archived");
337
- if (!s) return { ok: false, reason: "archived seed not found" };
338
- const category = normalizeCategory(s.category);
339
- const catCap = SEED_CATEGORY_CAPS[category];
340
- const inCategory = activeSeeds(db).filter((x) => normalizeCategory(x.category) === category).length;
341
- if (inCategory >= catCap) {
342
- return { ok: false, reason: `category full (${category}: ${catCap}); archive something in it first` };
343
- }
344
- if (activeSeeds(db).length >= policy.seeds.maxActive) {
345
- return { ok: false, reason: `pool full (${policy.seeds.maxActive}); archive something first` };
346
- }
347
- s.status = "active";
348
- s.retireReason = void 0;
349
- s.retiredAt = void 0;
350
- s.bornAt = new Date(now).toISOString();
351
- const restoreTtlDays = s.ttlDaysOverride ?? (policy.seeds.ttlDays[s.tag] || 14);
352
- s.expiresAt = new Date(now + restoreTtlDays * DAY_MS).toISOString();
353
- s.lastEvidenceAt = new Date(now).toISOString();
354
- emit(audit, { event: "seed_restored", id: s.id });
355
- savePool(guard, file, db);
356
- return { ok: true, seed: s };
357
- });
358
- }
359
- function deleteSeed(guard, file, id, audit = NO_AUDIT) {
360
- return update(guard, file, (db) => {
361
- const before = db.seeds.length;
362
- db.seeds = db.seeds.filter((x) => x.id !== id);
363
- if (db.seeds.length === before) return false;
364
- emit(audit, { event: "seed_deleted", id });
365
- savePool(guard, file, db);
366
- return true;
367
- });
368
- }
369
-
370
- export {
371
- SEED_CATEGORY_CAPS,
372
- SEED_SOURCE_CAPS,
373
- normalizeCategory,
374
- SEED_SIMILARITY_THRESHOLD,
375
- normalizeSeedText,
376
- seedSimilarity,
377
- TTL_KEYS,
378
- normalizeTag,
379
- seedsFilePath,
380
- loadPool,
381
- savePool,
382
- activeSeeds,
383
- archivedSeeds,
384
- evictionScore,
385
- pickEvictionVictim,
386
- addSeed,
387
- gcPool,
388
- surfaceSeed,
389
- archiveSeedById,
390
- restoreSeed,
391
- deleteSeed
392
- };
393
- //# sourceMappingURL=chunk-QOLKUYQ3.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/seeds/pool.ts","../src/seeds/types.ts"],"sourcesContent":["// Material pool engine (design doc §4). All four eviction rules are\n// deterministic code - no LLM involvement (§4.2). Storage: data/seeds.jsonl,\n// one seed per JSON line, DPAPI-encrypted at rest (D14).\n\nimport path from 'node:path';\nimport type { PathGuard } from '../core/path-guard.js';\nimport { loadEncryptedText, saveEncryptedText } from '../vault/vault.js';\nimport { withFileLock } from '../core/file-lock.js';\nimport type { Policy } from '../config/schema.js';\nimport {\n SEED_SOURCE_DEFAULT_CONFIDENCE,\n emptySeedDb,\n type Seed,\n type SeedCategory,\n type SeedDb,\n type SeedRetireReason,\n type SeedSource,\n type SeedTag,\n} from './types.js';\n\nconst DAY_MS = 86_400_000;\n\n// ── lifecycle audit (2026-10-06 / v1.9.0) ───────────────────────────────\n// The pool used to mutate in silence: a seed could appear, be evicted for\n// capacity, or be dropped from the archive with nothing in the log. Every\n// mutator now takes an optional sink and reports what it did. IDs and\n// metadata ONLY — heartbeat.jsonl is plaintext by charter and must never\n// carry conversation text; the seed text itself stays in the DPAPI pool.\nexport type SeedAuditFn = (entry: Record<string, unknown>) => void;\n\nconst NO_AUDIT: SeedAuditFn = () => {};\n\n/** Audit must never break the pool (or the beat that called it). */\nfunction emit(audit: SeedAuditFn, entry: Record<string, unknown>): void {\n try {\n audit(entry);\n } catch {\n /* audit is diagnostic; a failed append is not a pool failure */\n }\n}\n\n// Per-category pool caps (2026-09-18 spec ⑤): topic stock vs conversation-grown\n// chat material, decoupled from `source`; sum == the global maxActive default.\nexport const SEED_CATEGORY_CAPS: Record<SeedCategory, number> = { topic: 16, chat: 14 };\n\n// Per-source pool caps (2026-11-09): one origin must not own the pool — the\n// bilibili watch history gets its own lane (source 'bilibili', see types.ts)\n// and is capped at 6 so it cannot crowd every other source out. Third quota\n// dimension, checked BEFORE the category and global caps; absent key =\n// uncapped source.\nexport const SEED_SOURCE_CAPS: Partial<Record<SeedSource, number>> = { bilibili: 6 };\n\nconst CATEGORY_VALUES: readonly string[] = ['topic', 'chat'];\n\n/** Lenient category coercion for on-disk rows: anything missing/unknown (all\n * pre-v1.5 seeds) counts as topic stock. */\nexport function normalizeCategory(v: unknown): SeedCategory {\n return typeof v === 'string' && (CATEGORY_VALUES as readonly string[]).includes(v)\n ? (v as SeedCategory)\n : 'topic';\n}\n\nexport interface AddSeedInput {\n text: string;\n topic?: string;\n tag?: SeedTag;\n source?: SeedSource;\n /** Loop role (spec ⑤); defaults from source: chat->chat, everything else->topic. */\n category?: SeedCategory;\n confidence?: number;\n /** Skip the §4.3 same-topic merge: callers registering several items under\n * one focus in a single pass (wander) set this so each item survives as\n * its own seed instead of collapsing into the first. */\n noMerge?: boolean;\n /** Per-seed TTL override in days (v2.2): wins over policy.seeds.ttlDays[tag]\n * for THIS seed only; absent = the tag default, unchanged for everyone else. */\n ttlDaysOverride?: number;\n}\n\nexport type DuplicateReason = 'exact' | 'normalized' | 'similar';\n\nexport interface AddSeedResult {\n kind: 'added' | 'merged' | 'duplicate';\n seed: Seed;\n evicted?: Seed;\n /** Why a 'duplicate' was judged; absent on other kinds. */\n reason?: DuplicateReason;\n}\n\n// ── dedup (2026-10-29): wander keeps re-seeding the same material, so the add\n// path compares against actives AND recently archived seeds on three levels —\n// raw text, NFKC-normalized text, and character-bigram Dice similarity.\nexport const SEED_SIMILARITY_THRESHOLD = 0.85;\nconst DEDUP_ARCHIVE_WINDOW_MS = 30 * DAY_MS;\nconst DEDUP_ARCHIVE_MAX = 50;\n/** Short strings are all shared bigrams: \"话题素材 1\" vs \"话题素材 11\" scores\n * 0.889 and \"没有新证据的话题\" vs \"有新证据的话题\" 0.923, i.e. the similarity\n * layer would kill genuinely distinct short headlines. Below this normalized\n * length only the exact and normalized layers run (2026-10-30 review; the\n * old seeds.test.ts cap cases caught it as a real regression). */\nconst DEDUP_SIMILAR_MIN_CHARS = 12;\n\n/** Full-width -> half-width (NFKC), lowercase, strip all whitespace and\n * punctuation: only the surviving characters may make two seeds collide. */\nexport function normalizeSeedText(s: string): string {\n return s\n .normalize('NFKC')\n .toLowerCase()\n .replace(/[\\s\\p{P}\\p{S}]+/gu, '');\n}\n\n/** Dice coefficient over character bigrams of the NORMALIZED texts:\n * 2*|A∩B| / (|A|+|B|). Identical normalizations are 1; either side short\n * enough to have no bigrams only matches when they are identical. */\nexport function seedSimilarity(a: string, b: string): number {\n const na = normalizeSeedText(a);\n const nb = normalizeSeedText(b);\n if (na === nb) return 1;\n if (na.length < 2 || nb.length < 2) return 0;\n const gramCount = (t: string): Map<string, number> => {\n const m = new Map<string, number>();\n for (let i = 0; i < t.length - 1; i++) {\n const g = t.slice(i, i + 2);\n m.set(g, (m.get(g) ?? 0) + 1);\n }\n return m;\n };\n const A = gramCount(na);\n const B = gramCount(nb);\n let inter = 0;\n let sizeA = 0;\n let sizeB = 0;\n for (const c of A.values()) sizeA += c;\n for (const c of B.values()) sizeB += c;\n for (const [g, c] of A) inter += Math.min(c, B.get(g) ?? 0);\n return (2 * inter) / (sizeA + sizeB);\n}\n\n/** Archive side of the dedup scope: recently retired only (within 30 days,\n * newest first, at most 50) — the archive is a forensic trail, not a corpus\n * to scan on every add. */\nfunction recentArchived(db: SeedDb, now: number): Seed[] {\n return archivedSeeds(db)\n .filter((s) => now - parseIso(s.retiredAt ?? '') <= DEDUP_ARCHIVE_WINDOW_MS)\n .sort((a, b) => parseIso(b.retiredAt ?? '') - parseIso(a.retiredAt ?? ''))\n .slice(0, DEDUP_ARCHIVE_MAX);\n}\n\nexport interface GcReport {\n consumed: number;\n expired: number;\n coldBench: number;\n activeAfter: number;\n /** v1.9.0: archived rows dropped to honor seeds.archiveCap (oldest first). */\n archiveTrimmed: number;\n}\n\nexport const TTL_KEYS: readonly SeedTag[] = ['news', 'fandom', 'scene', 'promise'];\n\nexport function normalizeTag(tag: string | undefined): SeedTag {\n if (tag && (TTL_KEYS as readonly string[]).includes(tag)) return tag as SeedTag;\n return 'scene';\n}\n\nfunction parseIso(v: string): number {\n const t = Date.parse(v);\n return Number.isFinite(t) ? t : 0;\n}\n\n// ── storage ─────────────────────────────────────────────────────────────\n\nexport function seedsFilePath(dataDir: string): string {\n return path.join(dataDir, 'seeds.jsonl');\n}\n\nexport function loadPool(guard: PathGuard, file: string): SeedDb {\n const raw = loadEncryptedText(guard, file);\n if (raw === null) return emptySeedDb();\n const db = emptySeedDb();\n for (const line of raw.split('\\n')) {\n const trimmed = line.trim();\n if (!trimmed) continue;\n try {\n const obj = JSON.parse(trimmed) as Seed;\n if (typeof obj.id === 'string' && obj.id.startsWith('s')) {\n // spec ⑤ loadPool tolerance: only the id is load-bearing; a missing or\n // unknown category (every pre-v1.5 row) falls back to topic stock.\n obj.category = normalizeCategory(obj.category);\n db.seeds.push(obj);\n const n = Number(obj.id.slice(1));\n if (Number.isFinite(n) && n > db.seq) db.seq = n;\n }\n } catch {\n // corrupt line: skip (pool is a cache; journal-level audit lives elsewhere)\n }\n }\n return db;\n}\n\nexport function savePool(guard: PathGuard, file: string, db: SeedDb): void {\n const body = db.seeds.map((s) => JSON.stringify(s)).join('\\n');\n saveEncryptedText(guard, file, body ? body + '\\n' : '');\n}\n\n/**\n * H-20 (minimal tier): every pool writer goes through here, so the load happens\n * INSIDE the cross-process lock and cannot be based on a read that went stale\n * while it was being mutated — the CLI is a second process sharing this file,\n * and an interleaved write used to be silently overwritten. The ciphertext is a\n * whole-file rewrite, so append/merge does not apply here; the append-only pool\n * with compaction is v2.0 work (ledger #8649f9).\n */\nfunction update<T>(guard: PathGuard, file: string, fn: (db: SeedDb) => T): T {\n return withFileLock(file, () => fn(loadPool(guard, file)));\n}\n\n// ── queries ─────────────────────────────────────────────────────────────\n\nexport const activeSeeds = (db: SeedDb): Seed[] => db.seeds.filter((s) => s.status === 'active');\nexport const archivedSeeds = (db: SeedDb): Seed[] => db.seeds.filter((s) => s.status === 'archived');\n\n// ── eviction scoring (rule 4) ───────────────────────────────────────────\n\n/**\n * Comprehensive score (§4.2): freshness x0.4 + unused x0.3 + confidence x0.3.\n * Higher = keep. Lowest-scoring active is evicted when the pool is full.\n */\nexport function evictionScore(seed: Seed, policy: Policy, now: number): number {\n const ttlDays = policy.seeds.ttlDays[seed.tag] || 14;\n const daysStale = Math.max(0, (now - parseIso(seed.lastEvidenceAt)) / DAY_MS);\n const freshness = Math.max(0, 1 - daysStale / ttlDays);\n const unused = seed.used === 0 ? 1 : 1 / seed.used;\n const w = policy.seeds.scoreWeights;\n return freshness * w.freshness + unused * w.unused + seed.confidence * w.confidence;\n}\n\n/** Pick the eviction victim: unprotected actives first (§4.2 加权保护); with\n * `category`, only that category's actives compete (spec ⑤ per-category caps);\n * with `source`, only that source's actives compete (2026-11-09 per-source\n * caps). Both filters compose when given; existing callers pass neither or\n * one and are unaffected. */\nexport function pickEvictionVictim(db: SeedDb, policy: Policy, now: number, category?: SeedCategory, source?: SeedSource): Seed | null {\n const actives = activeSeeds(db).filter(\n (s) =>\n (category === undefined || normalizeCategory(s.category) === category) &&\n (source === undefined || s.source === source),\n );\n if (actives.length === 0) return null;\n const unprotected = actives.filter((s) => !s.protected);\n const candidates = unprotected.length > 0 ? unprotected : actives;\n let worst: Seed | null = null;\n let worstScore = Number.POSITIVE_INFINITY;\n for (const s of candidates) {\n const score = evictionScore(s, policy, now);\n if (score < worstScore) {\n worstScore = score;\n worst = s;\n }\n }\n return worst;\n}\n\nfunction archiveSeed(seed: Seed, reason: SeedRetireReason, now: number): void {\n seed.status = 'archived';\n seed.retireReason = reason;\n seed.retiredAt = new Date(now).toISOString();\n}\n\n/** Spec ④: chat-grown material is consumed ONCE (conversation freshness);\n * every other category follows the policy-wide retireAfterUsed. */\nfunction retireLimit(s: Seed, policy: Policy): number {\n return normalizeCategory(s.category) === 'chat' ? 1 : policy.seeds.retireAfterUsed;\n}\n\n/**\n * Rule 1 (§4.2): used up to its limit AND no evidence newer than the PREVIOUS\n * use. `prevUsedAt` MUST be read before bumping `lastUsedAt` — comparing the\n * just-written value against `lastEvidenceAt` is vacuously true (H-22), which\n * retired seeds that had received fresh evidence in the same beat. Both\n * callers (gc and surface) share this, so the rule cannot drift again.\n *\n * `prevUsedAt === 0` means \"never used before\": there is no earlier use for\n * the evidence to be newer THAN, so the exemption cannot apply — a one-shot\n * (chat) seed still retires on its first surfacing (spec ④), which is the\n * contract, not a regression.\n */\nfunction isConsumed(s: Seed, policy: Policy, prevUsedAt: number, sinceEvidence: number): boolean {\n if (s.used < retireLimit(s, policy)) return false;\n return !(prevUsedAt > 0 && sinceEvidence > prevUsedAt);\n}\n\n// ── operations ──────────────────────────────────────────────────────────\n\nexport function addSeed(\n guard: PathGuard,\n file: string,\n policy: Policy,\n input: AddSeedInput,\n now = Date.now(),\n audit: SeedAuditFn = NO_AUDIT,\n): AddSeedResult {\n // H-20: the read-modify-write below runs under the cross-process pool lock\n // (same guard as `update`, kept as a named body to avoid re-indenting it).\n return withFileLock(file, () => addSeedLocked(guard, file, policy, input, now, audit));\n}\n\nfunction addSeedLocked(\n guard: PathGuard,\n file: string,\n policy: Policy,\n input: AddSeedInput,\n now: number,\n audit: SeedAuditFn,\n): AddSeedResult {\n const db = loadPool(guard, file);\n const text = input.text.trim();\n if (!text) throw new Error('seed text must not be empty');\n const tag = normalizeTag(input.tag);\n const source: SeedSource = input.source ?? 'chat';\n const category = normalizeCategory(input.category ?? (source === 'chat' ? 'chat' : 'topic'));\n const confidence = input.confidence ?? SEED_SOURCE_DEFAULT_CONFIDENCE[source];\n\n // Three-layer dedup against actives + recently archived. Exact hits audit\n // without a score; normalized hits score 1 by definition. The similarity\n // layer is skipped for short texts (see DEDUP_SIMILAR_MIN_CHARS): distinct\n // short headlines share too many bigrams to be told apart by Dice alone.\n const textNorm = normalizeSeedText(text);\n for (const cand of [...activeSeeds(db), ...recentArchived(db, now)]) {\n if (cand.text === text) {\n emit(audit, { event: 'seed_duplicate', id: cand.id, reason: 'exact' });\n return { kind: 'duplicate', seed: cand, reason: 'exact' };\n }\n const candNorm = normalizeSeedText(cand.text);\n if (candNorm === textNorm) {\n emit(audit, { event: 'seed_duplicate', id: cand.id, reason: 'normalized', similarity: 1 });\n return { kind: 'duplicate', seed: cand, reason: 'normalized' };\n }\n if (textNorm.length < DEDUP_SIMILAR_MIN_CHARS || candNorm.length < DEDUP_SIMILAR_MIN_CHARS) continue;\n const sim = seedSimilarity(cand.text, text);\n if (sim <= SEED_SIMILARITY_THRESHOLD) continue;\n emit(audit, { event: 'seed_duplicate', id: cand.id, reason: 'similar', similarity: Number(sim.toFixed(3)) });\n return { kind: 'duplicate', seed: cand, reason: 'similar' };\n }\n\n const nowIso = new Date(now).toISOString();\n // v2.2: a per-seed override wins for this seed only; every other seed keeps\n // the tag default (untouched behaviour).\n const ttlDays = input.ttlDaysOverride ?? (policy.seeds.ttlDays[tag] || 14);\n const ttlMs = ttlDays * DAY_MS;\n\n // Same-topic merge (§4.3): collapse all same-topic actives + the new item.\n // `noMerge` opts out — wander registers several items under one focus per\n // pass and each must land as its own seed.\n const sameTopic = activeSeeds(db).filter((s) => s.topic === (input.topic ?? text.slice(0, 24)));\n let seed: Seed;\n if (sameTopic.length > 0 && !input.noMerge) {\n const kept = sameTopic[0]!;\n kept.text = text; // brief takes the latest\n kept.tag = tag;\n kept.source = source;\n kept.category = normalizeCategory(input.category ?? kept.category ?? category);\n kept.confidence = Math.max(kept.confidence, confidence);\n kept.used = sameTopic.reduce((acc, s) => acc + s.used, 0); // used accumulates\n kept.lastEvidenceAt = [kept.lastEvidenceAt, nowIso, ...sameTopic.map((s) => s.lastEvidenceAt)]\n .reduce((a, b) => (parseIso(b) > parseIso(a) ? b : a));\n kept.expiresAt = new Date(Math.max(parseIso(kept.expiresAt), now + ttlMs)).toISOString();\n kept.protected = kept.protected || source === 'hand' || (source === 'profile' && confidence >= 0.7);\n // remove the other same-topic actives (merged into kept)\n for (const extra of sameTopic.slice(1)) {\n extra.status = 'archived';\n extra.retireReason = 'completed';\n extra.retiredAt = nowIso;\n emit(audit, { event: 'seed_retired', id: extra.id, reason: 'completed', via: 'merge', into: kept.id });\n }\n seed = kept;\n // capacity still applies after growth check below if kept is somehow over cap\n if (activeSeeds(db).length > policy.seeds.maxActive) {\n const victim = pickEvictionVictim(db, policy, now, normalizeCategory(kept.category));\n if (victim && victim.id !== kept.id) {\n archiveSeed(victim, 'pool_cap', now);\n emit(audit, { event: 'seed_added', id: kept.id, kind: 'merged', tag: kept.tag, source: kept.source, category: kept.category, confidence: kept.confidence, mergedFrom: sameTopic.length - 1 });\n emit(audit, { event: 'seed_retired', id: victim.id, reason: 'pool_cap', via: 'merge', into: kept.id });\n savePool(guard, file, db);\n return { kind: 'merged', seed: kept, evicted: victim };\n }\n }\n emit(audit, { event: 'seed_added', id: kept.id, kind: 'merged', tag: kept.tag, source: kept.source, category: kept.category, confidence: kept.confidence, mergedFrom: sameTopic.length - 1 });\n savePool(guard, file, db);\n return { kind: 'merged', seed: kept };\n }\n\n // Capacity first (rules 4 + spec ⑤ + 2026-11-09 source caps): three quota\n // dimensions checked in order source -> category -> global, each evicting\n // within its own scope. The source cap LOOP-evicts inside the incoming\n // source until the lane sits below its cap — a stock already over the cap\n // must converge, so ONE add may retire several rows (each audited; the\n // result's `evicted` carries the LAST victim — the CLI only surfaces it as\n // a hint). Once the source cap fired, the later caps cannot newly overflow\n // (one in, net <= 0 out) and are skipped.\n const sourceVictims: Seed[] = [];\n const sourceCap = SEED_SOURCE_CAPS[source];\n if (sourceCap !== undefined) {\n while (activeSeeds(db).filter((s) => s.source === source).length >= sourceCap) {\n const victim = pickEvictionVictim(db, policy, now, undefined, source);\n if (!victim) break; // lane empty (defensive): nothing left to evict\n archiveSeed(victim, 'source_cap', now);\n sourceVictims.push(victim);\n }\n }\n let evicted: Seed | undefined;\n if (sourceVictims.length > 0) {\n evicted = sourceVictims[sourceVictims.length - 1];\n } else {\n const catCount = activeSeeds(db).filter((s) => normalizeCategory(s.category) === category).length;\n if (catCount >= SEED_CATEGORY_CAPS[category]) {\n const victim = pickEvictionVictim(db, policy, now, category);\n if (victim) {\n archiveSeed(victim, 'pool_cap', now);\n evicted = victim;\n }\n }\n if (!evicted && activeSeeds(db).length >= policy.seeds.maxActive) {\n const victim = pickEvictionVictim(db, policy, now, category);\n if (victim) {\n archiveSeed(victim, 'pool_cap', now);\n evicted = victim;\n }\n }\n }\n\n db.seq += 1;\n seed = {\n id: `s${db.seq}`,\n text,\n topic: input.topic ?? text.slice(0, 24),\n tag,\n source,\n category,\n confidence,\n protected: source === 'hand' || (source === 'profile' && confidence >= 0.7),\n used: 0,\n bornAt: nowIso,\n expiresAt: new Date(now + ttlMs).toISOString(),\n ...(input.ttlDaysOverride !== undefined ? { ttlDaysOverride: input.ttlDaysOverride } : {}),\n lastUsedAt: null,\n lastEvidenceAt: nowIso,\n status: 'active',\n };\n db.seeds.push(seed);\n emit(audit, { event: 'seed_added', id: seed.id, kind: 'added', tag: seed.tag, source: seed.source, category: seed.category, confidence: seed.confidence });\n for (const victim of sourceVictims) {\n emit(audit, { event: 'seed_retired', id: victim.id, reason: 'source_cap', via: 'add', into: seed.id });\n }\n if (evicted && sourceVictims.length === 0) {\n emit(audit, { event: 'seed_retired', id: evicted.id, reason: 'pool_cap', via: 'add', into: seed.id });\n }\n savePool(guard, file, db);\n return { kind: 'added', seed, evicted };\n}\n\n/**\n * Deterministic gc (rules 1-3 of §4.2). Rule 4 (pool cap) fires on add only.\n * v1.9.0: the archive area is ALSO capped (seeds.archiveCap) — the archive is\n * a forensic trail, not a hoard; trim oldest-retired first.\n */\nexport function gcPool(guard: PathGuard, file: string, policy: Policy, now = Date.now(), audit: SeedAuditFn = NO_AUDIT): GcReport {\n return update(guard, file, (db) => {\n const report: GcReport = { consumed: 0, expired: 0, coldBench: 0, activeAfter: 0, archiveTrimmed: 0 };\n for (const s of activeSeeds(db)) {\n const ageMs = now - parseIso(s.bornAt);\n const sinceEvidence = parseIso(s.lastEvidenceAt);\n const sinceUsed = s.lastUsedAt ? parseIso(s.lastUsedAt) : 0;\n if (isConsumed(s, policy, sinceUsed, sinceEvidence)) {\n archiveSeed(s, 'consumed', now);\n report.consumed += 1;\n emit(audit, { event: 'seed_retired', id: s.id, reason: 'consumed', via: 'gc', used: s.used });\n } else if (now > parseIso(s.expiresAt)) {\n archiveSeed(s, 'expired', now);\n report.expired += 1;\n emit(audit, { event: 'seed_retired', id: s.id, reason: 'expired', via: 'gc', used: s.used });\n } else if (s.used === 0 && ageMs >= policy.seeds.coldBenchDays * DAY_MS) {\n archiveSeed(s, 'cold_bench', now);\n report.coldBench += 1;\n emit(audit, { event: 'seed_retired', id: s.id, reason: 'cold_bench', via: 'gc', used: s.used });\n }\n }\n // archive cap: drop the oldest-retired rows beyond the cap (retiredAt may be\n // missing on pre-v1.5 rows — parseIso('') = 0 sorts them oldest).\n const archived = db.seeds.filter((s) => s.status === 'archived');\n if (archived.length > policy.seeds.archiveCap) {\n const drop = [...archived]\n .sort((a, b) => parseIso(a.retiredAt ?? '') - parseIso(b.retiredAt ?? ''))\n .slice(0, archived.length - policy.seeds.archiveCap);\n const dropped = new Set(drop.map((s) => s.id));\n db.seeds = db.seeds.filter((s) => !dropped.has(s.id));\n report.archiveTrimmed = drop.length;\n // These rows are GONE (not archived — deleted): the log is the only trace\n // left, so name them. IDs only, and cap the list in case a first GC trims\n // a legacy archive wholesale.\n emit(audit, { event: 'seed_archive_trimmed', count: drop.length, ids: drop.slice(0, 50).map((s) => s.id) });\n }\n report.activeAfter = activeSeeds(db).length;\n savePool(guard, file, db);\n return report;\n });\n}\n\n/** The seed surfaced in a real expression: count + maybe retire (rule 1). */\nexport function surfaceSeed(\n guard: PathGuard,\n file: string,\n policy: Policy,\n id: string,\n now = Date.now(),\n audit: SeedAuditFn = NO_AUDIT,\n): Seed | null {\n return update(guard, file, (db) => {\n const s = db.seeds.find((x) => x.id === id && x.status === 'active');\n if (!s) return null;\n // H-22: snapshot the PREVIOUS use time before bumping it — the retirement\n // check must compare against the last use, not against this one.\n const prevUsedAt = s.lastUsedAt ? parseIso(s.lastUsedAt) : 0;\n s.used += 1;\n s.lastUsedAt = new Date(now).toISOString();\n if (isConsumed(s, policy, prevUsedAt, parseIso(s.lastEvidenceAt))) {\n archiveSeed(s, 'consumed', now);\n emit(audit, { event: 'seed_retired', id: s.id, reason: 'consumed', via: 'surface', used: s.used });\n }\n savePool(guard, file, db);\n return s;\n });\n}\n\n/** Deliberate retirement (item completed / no longer relevant). */\nexport function archiveSeedById(\n guard: PathGuard,\n file: string,\n id: string,\n reason: SeedRetireReason = 'completed',\n now = Date.now(),\n audit: SeedAuditFn = NO_AUDIT,\n): Seed | null {\n return update(guard, file, (db) => {\n const s = db.seeds.find((x) => x.id === id && x.status === 'active');\n if (!s) return null;\n archiveSeed(s, reason, now);\n emit(audit, { event: 'seed_retired', id: s.id, reason, via: 'manual' });\n savePool(guard, file, db);\n return s;\n });\n}\n\n/** Restore an archived seed to the active pool (UI operation; resets TTL). */\nexport function restoreSeed(\n guard: PathGuard,\n file: string,\n policy: Policy,\n id: string,\n now = Date.now(),\n audit: SeedAuditFn = NO_AUDIT,\n): { ok: true; seed: Seed } | { ok: false; reason: string } {\n return update<{ ok: true; seed: Seed } | { ok: false; reason: string }>(guard, file, (db) => {\n const s = db.seeds.find((x) => x.id === id && x.status === 'archived');\n if (!s) return { ok: false, reason: 'archived seed not found' };\n // H-23: a restore must satisfy the same two caps an add does — the global\n // one AND the per-category one. The add path evicts a neighbour instead, but\n // restoring a memory is a user action: refuse it rather than silently\n // pushing someone else's material out.\n const category = normalizeCategory(s.category);\n const catCap = SEED_CATEGORY_CAPS[category];\n const inCategory = activeSeeds(db).filter((x) => normalizeCategory(x.category) === category).length;\n if (inCategory >= catCap) {\n return { ok: false, reason: `category full (${category}: ${catCap}); archive something in it first` };\n }\n if (activeSeeds(db).length >= policy.seeds.maxActive) {\n return { ok: false, reason: `pool full (${policy.seeds.maxActive}); archive something first` };\n }\n s.status = 'active';\n s.retireReason = undefined;\n s.retiredAt = undefined;\n // H-23: reset bornAt as well — cold-bench eviction (used === 0 && age >=\n // coldBenchDays) keys off bornAt, so a restored seed used to be re-archived\n // by the very next maintenance beat (\"restored, then gone one beat later\").\n s.bornAt = new Date(now).toISOString();\n // v2.2: a restored seed keeps its own TTL override if it carries one (a\n // bilibili seed must not outlive its 2-day hard expiry by being restored).\n const restoreTtlDays = s.ttlDaysOverride ?? (policy.seeds.ttlDays[s.tag] || 14);\n s.expiresAt = new Date(now + restoreTtlDays * DAY_MS).toISOString();\n s.lastEvidenceAt = new Date(now).toISOString();\n emit(audit, { event: 'seed_restored', id: s.id });\n savePool(guard, file, db);\n return { ok: true, seed: s };\n });\n}\n\n/** Hard delete (UI explicit action with confirm; the caller audits it). */\nexport function deleteSeed(guard: PathGuard, file: string, id: string, audit: SeedAuditFn = NO_AUDIT): boolean {\n return update(guard, file, (db) => {\n const before = db.seeds.length;\n db.seeds = db.seeds.filter((x) => x.id !== id);\n if (db.seeds.length === before) return false;\n emit(audit, { event: 'seed_deleted', id });\n savePool(guard, file, db);\n return true;\n });\n}\n","// Material pool (\"素材池\") types. Charter (axiom 3): this pool is a CACHE,\n// not memory - volatile, evictable, burnable; long-term memory only absorbs\n// conversation-validated content. Everything here may be destroyed.\n\nexport type SeedTag = 'news' | 'fandom' | 'scene' | 'promise';\n// 'bilibili' (2026-11-09): the watch-history ingest carries its own source\n// value — it must not share the wander 'browse' lane, or the source cap would\n// let news push bilibili material out of the shared quota.\nexport type SeedSource = 'chat' | 'screen' | 'browse' | 'bilibili' | 'hand' | 'profile';\nexport type SeedCategory = 'topic' | 'chat';\nexport type SeedRetireReason = 'consumed' | 'expired' | 'cold_bench' | 'pool_cap' | 'source_cap' | 'completed';\n\nexport interface Seed {\n id: string;\n /** Short brief shown to the reflection prompt. */\n text: string;\n /** Merge key (§4.3): same-topic actives collapse into one. */\n topic: string;\n tag: SeedTag;\n source: SeedSource;\n /** Loop role, decoupled from source (2026-09-18 spec ⑤): 'topic' = wander/\n * hand/profile stock (random pick), 'chat' = conversation-grown, consumed\n * once. Absent on pre-v1.5 rows; loadPool defaults them to 'topic'. */\n category?: SeedCategory;\n /** 0..1 trust level; handwriting and high-confidence profile sources gain eviction protection. */\n confidence: number;\n /** Eviction protection (§4.2 pool-cap rule): handwritten / high-confidence profile sources. */\n protected: boolean;\n /** Times this seed surfaced in an actual expression. */\n used: number;\n bornAt: string;\n /** bornAt + ttlDays[tag] (or ttlDaysOverride when set); archived when passed (rule 2). */\n expiresAt: string;\n /** Optional per-seed TTL override in days (e.g. bilibili browse material\n * hard-expires in 2 days regardless of the scene tag). Absent = the tag's\n * policy TTL, which is the behaviour every pre-v2.2 row keeps. */\n ttlDaysOverride?: number;\n lastUsedAt: string | null;\n /** Fresh-evidence watermark: rule 1 spares seeds with evidence newer than last use. */\n lastEvidenceAt: string;\n status: 'active' | 'archived';\n retireReason?: SeedRetireReason;\n retiredAt?: string;\n}\n\nexport interface SeedDb {\n seq: number;\n seeds: Seed[];\n}\n\nexport function emptySeedDb(): SeedDb {\n return { seq: 0, seeds: [] };\n}\n\nexport const SEED_SOURCE_DEFAULT_CONFIDENCE: Record<SeedSource, number> = {\n hand: 1.0,\n profile: 0.7,\n chat: 0.6,\n screen: 0.4,\n browse: 0.4,\n bilibili: 0.4,\n};\n"],"mappings":";;;;;;;AAIA,OAAO,UAAU;;;AC8CV,SAAS,cAAsB;AACpC,SAAO,EAAE,KAAK,GAAG,OAAO,CAAC,EAAE;AAC7B;AAEO,IAAM,iCAA6D;AAAA,EACxE,MA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A,EAC3B,CAAC;AACH;AAGO,SAAS,WAAW,OAAkB,MAAc,IAAY,QAAqB,UAAmB;AAC7G,SAAO,OAAO,OAAO,MAAM,CAAC,OAAO;AACjC,UAAM,SAAS,GAAG,MAAM;AACxB,OAAG,QAAQ,GAAG,MAAM,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE;AAC7C,QAAI,GAAG,MAAM,WAAW,OAAQ,QAAO;AACvC,SAAK,OAAO,EAAE,OAAO,gBAAgB,GAAG,CAAC;AACzC,aAAS,OAAO,MAAM,EAAE;AACxB,WAAO;AAAA,EACT,CAAC;AACH;","names":[]}
@@ -1,49 +0,0 @@
1
- import {
2
- SEED_CATEGORY_CAPS,
3
- SEED_SIMILARITY_THRESHOLD,
4
- SEED_SOURCE_CAPS,
5
- TTL_KEYS,
6
- activeSeeds,
7
- addSeed,
8
- archiveSeedById,
9
- archivedSeeds,
10
- deleteSeed,
11
- evictionScore,
12
- gcPool,
13
- loadPool,
14
- normalizeCategory,
15
- normalizeSeedText,
16
- normalizeTag,
17
- pickEvictionVictim,
18
- restoreSeed,
19
- savePool,
20
- seedSimilarity,
21
- seedsFilePath,
22
- surfaceSeed
23
- } from "./chunk-QOLKUYQ3.js";
24
- import "./chunk-GOLMRQRW.js";
25
- import "./chunk-66IUDHCY.js";
26
- export {
27
- SEED_CATEGORY_CAPS,
28
- SEED_SIMILARITY_THRESHOLD,
29
- SEED_SOURCE_CAPS,
30
- TTL_KEYS,
31
- activeSeeds,
32
- addSeed,
33
- archiveSeedById,
34
- archivedSeeds,
35
- deleteSeed,
36
- evictionScore,
37
- gcPool,
38
- loadPool,
39
- normalizeCategory,
40
- normalizeSeedText,
41
- normalizeTag,
42
- pickEvictionVictim,
43
- restoreSeed,
44
- savePool,
45
- seedSimilarity,
46
- seedsFilePath,
47
- surfaceSeed
48
- };
49
- //# sourceMappingURL=pool-QTY2MI56.js.map
@@ -1,16 +0,0 @@
1
- import {
2
- SNAPSHOT_THRESHOLD,
3
- snapshotDue,
4
- snapshotIfDue,
5
- snapshotProfile
6
- } from "./chunk-JIRQ36F7.js";
7
- import "./chunk-K47VV6IQ.js";
8
- import "./chunk-GOLMRQRW.js";
9
- import "./chunk-66IUDHCY.js";
10
- export {
11
- SNAPSHOT_THRESHOLD,
12
- snapshotDue,
13
- snapshotIfDue,
14
- snapshotProfile
15
- };
16
- //# sourceMappingURL=snapshot-6DFNGXTR.js.map