@gamaze/hicortex 0.20.9 → 0.21.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 (48) hide show
  1. package/README.md +8 -0
  2. package/assets/dashboard.html +4174 -835
  3. package/dist/calibration.d.ts +119 -0
  4. package/dist/calibration.js +149 -1
  5. package/dist/capture-health.d.ts +87 -0
  6. package/dist/capture-health.js +106 -0
  7. package/dist/capture-pause.d.ts +86 -0
  8. package/dist/capture-pause.js +127 -0
  9. package/dist/capture.d.ts +9 -0
  10. package/dist/capture.js +2 -1
  11. package/dist/cli.js +36 -0
  12. package/dist/consolidate.d.ts +35 -0
  13. package/dist/consolidate.js +85 -9
  14. package/dist/dashboard.d.ts +322 -3
  15. package/dist/dashboard.js +592 -7
  16. package/dist/db.js +105 -0
  17. package/dist/eval/importance-eval.d.ts +85 -0
  18. package/dist/eval/importance-eval.js +286 -0
  19. package/dist/eval/planted-fixtures.d.ts +1 -1
  20. package/dist/eval/ranking-battery.d.ts +78 -0
  21. package/dist/eval/ranking-battery.js +181 -0
  22. package/dist/eval/ranking-eval.d.ts +41 -0
  23. package/dist/eval/ranking-eval.js +391 -0
  24. package/dist/eval/ranking-fixtures.d.ts +77 -0
  25. package/dist/eval/ranking-fixtures.js +226 -0
  26. package/dist/identity-store.d.ts +21 -0
  27. package/dist/identity-store.js +49 -0
  28. package/dist/init.d.ts +14 -0
  29. package/dist/init.js +32 -0
  30. package/dist/mcp-server.d.ts +12 -0
  31. package/dist/mcp-server.js +184 -3
  32. package/dist/nightly.d.ts +9 -1
  33. package/dist/nightly.js +59 -7
  34. package/dist/prompts.d.ts +10 -0
  35. package/dist/prompts.js +28 -5
  36. package/dist/reconsolidation.d.ts +59 -30
  37. package/dist/reconsolidation.js +526 -296
  38. package/dist/rescore-importance.d.ts +80 -0
  39. package/dist/rescore-importance.js +236 -0
  40. package/dist/retrieval.d.ts +12 -0
  41. package/dist/retrieval.js +30 -1
  42. package/dist/stages.d.ts +37 -0
  43. package/dist/stages.js +51 -0
  44. package/dist/state.d.ts +32 -6
  45. package/dist/storage.d.ts +34 -2
  46. package/dist/storage.js +63 -6
  47. package/dist/types.d.ts +48 -0
  48. package/package.json +3 -1
@@ -42,13 +42,32 @@
42
42
  * NOTHING else: no status change, no rewrite, no merge queue; both records
43
43
  * stay live so the consumer sees both truths. Both merge paths (the zone's
44
44
  * planDedup and the judged mergeMemoryIds) refuse to blend a conflicts-linked
45
- * pair, counted as conflict_skipped. The zone therefore runs AFTER the
46
- * rewrite phase — with the zone first, a >=0.92 conflict pair was blended
45
+ * pair, counted as conflict_skipped. The zone therefore runs AFTER the scan —
46
+ * with the zone first, a >=0.92 conflict pair was blended
47
47
  * before the judge ever saw it (the planted-eval harm: canonical=older, the
48
48
  * newer truth erased); running it last means verdicts/marks/binds land first
49
49
  * and the zone merges only what no verdict claimed — a conflicts bind set by
50
50
  * this run's scan guards the SAME run's zone.
51
51
  *
52
+ * #439 apply-on-confirm — confirmed merges and rewrite groups apply at the
53
+ * candidate BOUNDARY (the end of the scan iteration that confirmed them), not
54
+ * in post-scan phases. The old end-of-run batch was a completion assumption
55
+ * written when nightlies finished in an hour; under #405 budget pressure it
56
+ * became a days-long queue where confirmed work never landed and every night
57
+ * re-paid the judgment cost (cursor held below un-applied groups, pairs
58
+ * re-detected, re-judged). Now each judged-merge pair applies via
59
+ * mergeMemoryIds in its OWN transaction at confirmation time, each rewrite
60
+ * group via its own rewrite call + applyRewriteGroup transaction; the cursor
61
+ * advances per APPLIED candidate, so a deferral holds it below exactly ONE
62
+ * candidate's pairs. One pre-merge backup per run (lazy, before the first
63
+ * application); the capture lock is taken per boundary batch with a same-run
64
+ * retry list + a final drain. A shared trigger IS the current candidate, so
65
+ * the multi-target keep rule resolves across the boundary's groups (any keep
66
+ * keeps). A target corrected by two different candidates takes two sequential
67
+ * rewrites — the second composes the already-corrected story — instead of one
68
+ * grouped call (the ONE-call grouping was a cost optimization, not a
69
+ * correctness invariant; accepted semantics change).
70
+ *
52
71
  * Status vocabulary (code-defined, extensible — deliberately NOT config):
53
72
  * NULL/'active' default | 'superseded' + 'retracted' demote in ranking |
54
73
  * 'corrected' = rewritten, never demotes (demoting it would bury the
@@ -129,9 +148,9 @@ export interface ReconsolidationOptions {
129
148
  */
130
149
  deadline?: RunDeadline;
131
150
  /**
132
- * Capture-lock acquirer override (tests) — the deterministic zone and the
133
- * judged-merge phase each hold a short lock window. Defaults to the real
134
- * capture.ts lock. DedupOptions.acquireLock pattern.
151
+ * Capture-lock acquirer override (tests) — the deterministic zone and each
152
+ * #439 boundary's judged-merge batch hold a short lock window. Defaults to
153
+ * the real capture.ts lock. DedupOptions.acquireLock pattern.
135
154
  */
136
155
  acquireLock?: typeof acquireCaptureLock;
137
156
  }
@@ -329,16 +348,18 @@ export declare function buildResolutionBands(floor: number, ceiling: number): Re
329
348
  */
330
349
  export declare function bandForCosine(bands: ResolutionBand[], cosine: number): ResolutionBand | null;
331
350
  /**
332
- * Nightly reconsolidation stage (#384, #392 — THE unified resolution stage).
351
+ * Nightly reconsolidation stage (#384, #392 — THE unified resolution stage;
352
+ * #439 apply-on-confirm).
333
353
  *
334
354
  * Phase order (#393 guard-C): the deterministic merge zone (pairs >= the
335
- * ceiling) runs LAST — after the scan, the judged-merge phase, and the
336
- * rewrite phase. Judgment outranks the deterministic sweep: verdicts, marks,
337
- * and binds land first and the zone merges only what no verdict claimed. With
338
- * the zone first, a >=0.92 genuine-conflict pair was blended before the judge
339
- * ever saw it (the planted-eval harm); running it last means a `conflicts`
340
- * bind set by this run's scan guards the SAME run's zone. Zone internals
341
- * (lock, backup, deadline, persistBand, fail-soft) are unchanged.
355
+ * ceiling) runs LAST — after the scan (which now includes every judged-merge
356
+ * application and rewrite, #439). Judgment outranks the deterministic sweep:
357
+ * verdicts, marks, and binds land first and the zone merges only what no
358
+ * verdict claimed. With the zone first, a >=0.92 genuine-conflict pair was
359
+ * blended before the judge ever saw it (the planted-eval harm); running it
360
+ * last means a `conflicts` bind set by this run's scan guards the SAME run's
361
+ * zone. Zone internals (lock, backup, deadline, persistBand, fail-soft) are
362
+ * unchanged.
342
363
  *
343
364
  * Scan: every memory with rowid > reconsolidationCursor (no shape filter;
344
365
  * absorbed candidates are skipped — invisible memories are not re-judged).
@@ -349,25 +370,33 @@ export declare function bandForCosine(bands: ResolutionBand[], cosine: number):
349
370
  * judged) plus the scout's FTS hits for correction-shaped memories (same
350
371
  * verdict loop, NO similarity gate; guard-C: a scout hit whose KNN twin sits
351
372
  * at/above the ceiling is re-tagged scout so the pair IS judged instead of
352
- * being left for the zone to blend). Confirmed
353
- * `corrects` pairs above the confidence gate on fact-shaped targets group by
354
- * target into ONE rewrite call each (AC3); confirmed `merge` pairs queue for
355
- * the merge phase; a `conflicts` verdict writes the conflicts link and
356
- * nothing else (both live); everything else is mark-only.
373
+ * being left for the zone to blend). Confirmed `corrects` pairs above the
374
+ * confidence gate on fact-shaped targets group by target; a `conflicts`
375
+ * verdict writes the conflicts link and nothing else (both live); everything
376
+ * else is mark-only.
357
377
  *
358
- * Merge phase (#392): queued pairs merge through the dedup core under one
359
- * lock/backup window. A pair that cannot apply keeps both memories and holds
360
- * the cursor; a conflicts-linked or metadata-mismatched refusal keeps both
361
- * and advances (the verdict was rendered).
378
+ * #439 BOUNDARY apply: at the END of each candidate iteration everything it
379
+ * confirmed applies IMMEDIATELY — merges first (each judged-merge pair via
380
+ * mergeMemoryIds in its own transaction, under the boundary's short lock
381
+ * window; ONE lazy pre-merge backup per run), then the iteration's rewrite
382
+ * groups (one rewrite LLM call + one applyRewriteGroup transaction each;
383
+ * dispositions resolved ACROSS the boundary's groups — the multi-target keep
384
+ * rule: a trigger absorbed only if every group's contract says absorb). A
385
+ * busy capture lock pushes the boundary's merges onto a same-run retry list
386
+ * (retried at the next boundary and once in a final drain after the scan);
387
+ * a deadline, a backup failure, or a rewrite-call refusal/infra error defers
388
+ * the remaining work and holds the cursor.
362
389
  *
363
- * Cursor discipline mirrors stageSupersession: the cursor advances past a
364
- * candidate once its neighbor set has been considered, regardless of infra
365
- * skips — EXCEPT when rewrite groups or confirmed merges could not be applied
366
- * (budget exhausted / rewrite-call infra error / merge cap or lock): the
367
- * cursor then holds BELOW the earliest candidate contributing to the
368
- * un-applied work, so those pairs are re-detected next run (dup-over-loss —
369
- * an un-marked, un-rewritten, un-merged confirmed resolution must never be
370
- * silently dropped by the cursor passing it).
390
+ * Cursor discipline: the cursor advances past a candidate only when its
391
+ * iteration's confirmed work has LANDED (or was refused-with-verdict-rendered:
392
+ * metadata mismatch, conflict-linked, mark-only fallback). A deferral holds
393
+ * the cursor BELOW the current candidate — bounded to ONE candidate's pairs,
394
+ * re-detected and re-judged next run (dup-over-loss — a confirmed resolution
395
+ * must never be silently dropped by the cursor passing it). The separate
396
+ * scan high-water (state.reconsolidationScannedRowid) records the max
397
+ * candidate rowid ENTERED and is never held back, so the report can split
398
+ * verdict calls into pairs_reevaluated (at/below the prior high-water) vs
399
+ * pairs_new — the convergence measurement.
371
400
  *
372
401
  * Dry-run: the zone's discovery + the free idempotency check only — zero LLM
373
402
  * calls, zero writes, no cursor or band-stats persistence. Gate discovery is