agent-recall-core 3.4.50 → 3.5.2

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 (152) hide show
  1. package/README.md +559 -330
  2. package/dist/embeddings/config.d.ts.map +1 -1
  3. package/dist/embeddings/config.js +17 -4
  4. package/dist/embeddings/config.js.map +1 -1
  5. package/dist/helpers/alignment-patterns.d.ts +46 -0
  6. package/dist/helpers/alignment-patterns.d.ts.map +1 -1
  7. package/dist/helpers/alignment-patterns.js +103 -2
  8. package/dist/helpers/alignment-patterns.js.map +1 -1
  9. package/dist/helpers/journal-files.d.ts +12 -6
  10. package/dist/helpers/journal-files.d.ts.map +1 -1
  11. package/dist/helpers/journal-files.js +13 -7
  12. package/dist/helpers/journal-files.js.map +1 -1
  13. package/dist/helpers/transcript-project.d.ts +69 -0
  14. package/dist/helpers/transcript-project.d.ts.map +1 -0
  15. package/dist/helpers/transcript-project.js +212 -0
  16. package/dist/helpers/transcript-project.js.map +1 -0
  17. package/dist/index.d.ts +28 -7
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +62 -6
  20. package/dist/index.js.map +1 -1
  21. package/dist/palace/awareness.d.ts +6 -0
  22. package/dist/palace/awareness.d.ts.map +1 -1
  23. package/dist/palace/awareness.js +10 -4
  24. package/dist/palace/awareness.js.map +1 -1
  25. package/dist/prompts/consolidation-prompt.js +14 -14
  26. package/dist/retrieval/activation.d.ts +202 -0
  27. package/dist/retrieval/activation.d.ts.map +1 -0
  28. package/dist/retrieval/activation.js +313 -0
  29. package/dist/retrieval/activation.js.map +1 -0
  30. package/dist/retrieval/candidates.d.ts +17 -0
  31. package/dist/retrieval/candidates.d.ts.map +1 -1
  32. package/dist/retrieval/candidates.js +4 -2
  33. package/dist/retrieval/candidates.js.map +1 -1
  34. package/dist/retrieval/contradiction.d.ts +42 -0
  35. package/dist/retrieval/contradiction.d.ts.map +1 -1
  36. package/dist/retrieval/contradiction.js +126 -7
  37. package/dist/retrieval/contradiction.js.map +1 -1
  38. package/dist/retrieval/lexical-index.d.ts +150 -0
  39. package/dist/retrieval/lexical-index.d.ts.map +1 -0
  40. package/dist/retrieval/lexical-index.js +514 -0
  41. package/dist/retrieval/lexical-index.js.map +1 -0
  42. package/dist/retrieval/query-memory.d.ts +17 -7
  43. package/dist/retrieval/query-memory.d.ts.map +1 -1
  44. package/dist/retrieval/query-memory.js +274 -68
  45. package/dist/retrieval/query-memory.js.map +1 -1
  46. package/dist/storage/classification.d.ts.map +1 -1
  47. package/dist/storage/classification.js +4 -1
  48. package/dist/storage/classification.js.map +1 -1
  49. package/dist/storage/content-guard.d.ts +26 -0
  50. package/dist/storage/content-guard.d.ts.map +1 -1
  51. package/dist/storage/content-guard.js +450 -48
  52. package/dist/storage/content-guard.js.map +1 -1
  53. package/dist/storage/corrections.d.ts +140 -2
  54. package/dist/storage/corrections.d.ts.map +1 -1
  55. package/dist/storage/corrections.js +144 -70
  56. package/dist/storage/corrections.js.map +1 -1
  57. package/dist/storage/cwd-allowlist.d.ts +28 -2
  58. package/dist/storage/cwd-allowlist.d.ts.map +1 -1
  59. package/dist/storage/cwd-allowlist.js +61 -13
  60. package/dist/storage/cwd-allowlist.js.map +1 -1
  61. package/dist/storage/filelock.d.ts +26 -8
  62. package/dist/storage/filelock.d.ts.map +1 -1
  63. package/dist/storage/filelock.js +202 -26
  64. package/dist/storage/filelock.js.map +1 -1
  65. package/dist/storage/fs-utils.d.ts +51 -0
  66. package/dist/storage/fs-utils.d.ts.map +1 -1
  67. package/dist/storage/fs-utils.js +123 -2
  68. package/dist/storage/fs-utils.js.map +1 -1
  69. package/dist/storage/heed-tiers.d.ts +206 -0
  70. package/dist/storage/heed-tiers.d.ts.map +1 -0
  71. package/dist/storage/heed-tiers.js +318 -0
  72. package/dist/storage/heed-tiers.js.map +1 -0
  73. package/dist/storage/memory-protocol.js +55 -55
  74. package/dist/storage/paths.d.ts.map +1 -1
  75. package/dist/storage/paths.js +7 -2
  76. package/dist/storage/paths.js.map +1 -1
  77. package/dist/storage/project.d.ts.map +1 -1
  78. package/dist/storage/project.js +9 -2
  79. package/dist/storage/project.js.map +1 -1
  80. package/dist/storage/store-manifest.js +57 -57
  81. package/dist/supabase/embedding.d.ts.map +1 -1
  82. package/dist/supabase/embedding.js +7 -0
  83. package/dist/supabase/embedding.js.map +1 -1
  84. package/dist/supabase/sync.d.ts +1 -1
  85. package/dist/supabase/sync.d.ts.map +1 -1
  86. package/dist/supabase/sync.js +88 -28
  87. package/dist/supabase/sync.js.map +1 -1
  88. package/dist/tools-logic/association.d.ts +260 -0
  89. package/dist/tools-logic/association.d.ts.map +1 -0
  90. package/dist/tools-logic/association.js +502 -0
  91. package/dist/tools-logic/association.js.map +1 -0
  92. package/dist/tools-logic/bootstrap.d.ts.map +1 -1
  93. package/dist/tools-logic/bootstrap.js +4 -2
  94. package/dist/tools-logic/bootstrap.js.map +1 -1
  95. package/dist/tools-logic/check-action.d.ts.map +1 -1
  96. package/dist/tools-logic/check-action.js +14 -0
  97. package/dist/tools-logic/check-action.js.map +1 -1
  98. package/dist/tools-logic/check.d.ts +7 -0
  99. package/dist/tools-logic/check.d.ts.map +1 -1
  100. package/dist/tools-logic/check.js +54 -44
  101. package/dist/tools-logic/check.js.map +1 -1
  102. package/dist/tools-logic/dream-admission.js +29 -29
  103. package/dist/tools-logic/implicit-harvest.d.ts +196 -0
  104. package/dist/tools-logic/implicit-harvest.d.ts.map +1 -0
  105. package/dist/tools-logic/implicit-harvest.js +675 -0
  106. package/dist/tools-logic/implicit-harvest.js.map +1 -0
  107. package/dist/tools-logic/insight-promotion.d.ts.map +1 -1
  108. package/dist/tools-logic/insight-promotion.js +53 -1
  109. package/dist/tools-logic/insight-promotion.js.map +1 -1
  110. package/dist/tools-logic/recall-backend.d.ts.map +1 -1
  111. package/dist/tools-logic/recall-backend.js +3 -1
  112. package/dist/tools-logic/recall-backend.js.map +1 -1
  113. package/dist/tools-logic/retier.d.ts +274 -0
  114. package/dist/tools-logic/retier.d.ts.map +1 -0
  115. package/dist/tools-logic/retier.js +511 -0
  116. package/dist/tools-logic/retier.js.map +1 -0
  117. package/dist/tools-logic/session-end.d.ts +35 -0
  118. package/dist/tools-logic/session-end.d.ts.map +1 -1
  119. package/dist/tools-logic/session-end.js +26 -7
  120. package/dist/tools-logic/session-end.js.map +1 -1
  121. package/dist/tools-logic/session-start.d.ts +11 -0
  122. package/dist/tools-logic/session-start.d.ts.map +1 -1
  123. package/dist/tools-logic/session-start.js +34 -4
  124. package/dist/tools-logic/session-start.js.map +1 -1
  125. package/dist/tools-logic/smart-recall.d.ts +63 -0
  126. package/dist/tools-logic/smart-recall.d.ts.map +1 -1
  127. package/dist/tools-logic/smart-recall.js +213 -31
  128. package/dist/tools-logic/smart-recall.js.map +1 -1
  129. package/dist/tools-logic/smart-remember-vector.d.ts +3 -1
  130. package/dist/tools-logic/smart-remember-vector.d.ts.map +1 -1
  131. package/dist/tools-logic/smart-remember-vector.js +3 -1
  132. package/dist/tools-logic/smart-remember-vector.js.map +1 -1
  133. package/dist/tools-logic/smart-remember.d.ts.map +1 -1
  134. package/dist/tools-logic/smart-remember.js +6 -2
  135. package/dist/tools-logic/smart-remember.js.map +1 -1
  136. package/dist/tools-logic/transcript-audit.d.ts +128 -0
  137. package/dist/tools-logic/transcript-audit.d.ts.map +1 -0
  138. package/dist/tools-logic/transcript-audit.js +428 -0
  139. package/dist/tools-logic/transcript-audit.js.map +1 -0
  140. package/dist/types.d.ts +17 -2
  141. package/dist/types.d.ts.map +1 -1
  142. package/dist/types.js +31 -3
  143. package/dist/types.js.map +1 -1
  144. package/dist/vector/embedding.d.ts +20 -1
  145. package/dist/vector/embedding.d.ts.map +1 -1
  146. package/dist/vector/embedding.js +27 -1
  147. package/dist/vector/embedding.js.map +1 -1
  148. package/dist/vector/local-vector-backend.d.ts +4 -1
  149. package/dist/vector/local-vector-backend.d.ts.map +1 -1
  150. package/dist/vector/local-vector-backend.js +7 -3
  151. package/dist/vector/local-vector-backend.js.map +1 -1
  152. package/package.json +59 -59
@@ -0,0 +1,206 @@
1
+ /**
2
+ * heed-tiers.ts — symmetric evidence-tier classification for correction
3
+ * outcome events (the S0 heed-rate split: ADJUDICATED vs LOOSE, correction-
4
+ * level and event-level).
5
+ *
6
+ * PROVENANCE / SINGLE SOURCE OF TRUTH (fix12 hygiene, 2026-09-12): this logic
7
+ * was authored in `scripts/eval/heed-rate/lib.mjs` (fix11, review-hardened —
8
+ * symmetric tiering after the asymmetric-tiers HIGH finding) and MOVED here
9
+ * verbatim so the shipped KPI surfaces (`ar stats`) can present the tiered
10
+ * split without forking the eval's classification. `lib.mjs` now re-exports
11
+ * these functions from the built core — change the tiers HERE, never in a
12
+ * copy. The eval's mechanics tests (scripts/eval/heed-rate/heed-rate.test.mjs)
13
+ * exercise this implementation through the re-export.
14
+ *
15
+ * WHY TIERS (fix11 retrospective, 2026-09-12): the shipped KPI formula
16
+ * heed_rate = heeded/(heeded+recurred) is bookkeeping, not evidence — in the
17
+ * live store 75.8% of its numerator was pre-C3 default-heeded absence-of-
18
+ * evidence credit, and its denominator carried session_end self-report marker
19
+ * fan-out (3 of 4 correction-level "violated" verdicts traced to unrelated
20
+ * sessions). Presenting the single number invites 2×-style over-trust in
21
+ * either direction, so every KPI surface renders BOTH tiers as a range.
22
+ */
23
+ /** Minimal structural shape of one `_outcomes.jsonl` event for tiering. */
24
+ export interface HeedTierEvent {
25
+ kind?: string;
26
+ evidence?: string;
27
+ at?: string;
28
+ }
29
+ export type HeedEventTier = "heeded_verified" | "heeded_checkaction" | "heeded_default" | "recurred_verified" | "recurred_selfreport" | "not_violated" | "surfaced" | "no_signal" | "prediction" | "other";
30
+ /**
31
+ * Evidence tiers for outcome-ledger events (_outcomes.jsonl lines).
32
+ *
33
+ * Tiering rationale (verified against the live store 2026-09-12 and against
34
+ * the producer code paths):
35
+ *
36
+ * heeded_verified kind=heeded, evidence starts "dream-audit:" — the C3b
37
+ * nightly audit cites verbatim transcript/journal
38
+ * compliance evidence. Strongest heed signal the ledger
39
+ * carries.
40
+ * heeded_checkaction kind=heeded, evidence mentions "check-action" — the C3
41
+ * authoritative session-end path (trigger evidence + no
42
+ * recurrence marker). Designed but NEVER observed in the
43
+ * live store (0 "triggered" events exist store-wide).
44
+ * heeded_default kind=heeded, anything else — the pre-C3 default-heeded
45
+ * bias ("no recurrence evidence in session summary",
46
+ * with or without the explicit "(default-heeded …)"
47
+ * marker). Credits heed on ABSENCE of evidence — loose
48
+ * tier only.
49
+ * recurred_verified kind=recurred, dream-audit prefix — audited violation.
50
+ * recurred_selfreport kind=recurred, otherwise — session-summary recurrence
51
+ * markers. Loose tier only: primary-evidence review
52
+ * (2026-09-12) showed session_end FANS one summary's
53
+ * marker out onto every correction with ≥2-3 topical
54
+ * content words, so these over-count violations from
55
+ * unrelated sessions (3 of 4 originally-"violated"
56
+ * verdicts were such fan-out artifacts).
57
+ * not_violated weak non-violation (topical overlap, no marker) — own
58
+ * counter by design, NEVER blended into heed_rate.
59
+ * surfaced kind=retrieved — the correction was injected.
60
+ * no_signal unknown / not_triggered — no compliance information.
61
+ * prediction predicted / predict_hit — prediction loop, not heed.
62
+ * other unrecognized kind (forward-compat).
63
+ *
64
+ * NOTE (class-not-instance): the tiers key off producer evidence-string
65
+ * conventions ("dream-audit:" prefix, "check-action" mention). If a producer
66
+ * changes wording, add a row HERE — every consumer (eval + `ar stats` +
67
+ * rmr-report) picks it up.
68
+ */
69
+ export declare function classifyEvent(evt: HeedTierEvent | null | undefined): HeedEventTier;
70
+ /**
71
+ * Symmetric evidence tiers (fix11 fix round 2026-09-12, review HIGH):
72
+ *
73
+ * The original design excluded default-heeded (absence-of-evidence POSITIVES)
74
+ * from the strict rate but trusted self-report recurrence markers
75
+ * (keyword-heuristic NEGATIVES) at full weight — asymmetric. Primary-evidence
76
+ * review proved the self-report channel over-counts: session_end fans one
77
+ * summary's recurrence marker out onto every correction with ≥2-3 topical
78
+ * content words, producing violation verdicts from unrelated sessions.
79
+ *
80
+ * So both rates are tiered SYMMETRICALLY and reported as a range:
81
+ *
82
+ * ADJUDICATED — evidence-cited verdicts only, both directions:
83
+ * heed: heeded_verified (dream-audit verbatim) + heeded_checkaction
84
+ * (C3 authoritative trigger; zero instances to date)
85
+ * violation: recurred_verified (dream-audit verbatim)
86
+ *
87
+ * LOOSE — heuristic channels included, both directions:
88
+ * heed: adjudicated heeds + heeded_default (pre-C3 absence-of-
89
+ * evidence credit)
90
+ * violation: adjudicated violations + recurred_selfreport (summary
91
+ * marker fan-out)
92
+ *
93
+ * At event level the LOOSE rate is by construction the shipped KPI formula
94
+ * heeded/(heeded+recurred). `not_violated` stays outside BOTH tiers (its own
95
+ * design contract — never blended into heed_rate).
96
+ */
97
+ export declare const ADJUDICATED_HEED: ReadonlySet<HeedEventTier>;
98
+ export declare const ADJUDICATED_VIOLATION: ReadonlySet<HeedEventTier>;
99
+ export declare const LOOSE_HEED: ReadonlySet<HeedEventTier>;
100
+ export declare const LOOSE_VIOLATION: ReadonlySet<HeedEventTier>;
101
+ /** Local-calendar-day string for an ISO timestamp ("sv" locale = YYYY-MM-DD). */
102
+ export declare function dayOf(iso: string | undefined): string | null;
103
+ export type HeedTierVerdict = "heeded" | "violated" | "mixed" | "no-evidence";
104
+ export interface HeedTierCounts {
105
+ heeds: number;
106
+ violations: number;
107
+ verdict: HeedTierVerdict;
108
+ }
109
+ export interface HeedCorrectionResult {
110
+ status: "surfaced" | "not-surfaced";
111
+ label: string;
112
+ surfaced_count: number;
113
+ first_surfaced: string | null;
114
+ adjudicated: HeedTierCounts;
115
+ loose: HeedTierCounts;
116
+ weak_not_violated: number;
117
+ tiers: Partial<Record<HeedEventTier, number>>;
118
+ pre_surfacing: Array<{
119
+ tier: HeedEventTier;
120
+ at: string | undefined;
121
+ evidence: string;
122
+ }>;
123
+ evidence: Array<{
124
+ tier: HeedEventTier;
125
+ at: string | undefined;
126
+ evidence: string;
127
+ }>;
128
+ }
129
+ /**
130
+ * Classify one correction's full event list into per-correction verdicts,
131
+ * one per evidence tier (symmetric tiering — see the tier doc above).
132
+ *
133
+ * Only events on/after the first surfacing day count toward compliance —
134
+ * "did SUBSEQUENT behavior comply" (same-day counts as subsequent: retrieval
135
+ * fires at session_start, verdicts at session_end / overnight audit, and the
136
+ * C3b audit backdates `at` to the audited day).
137
+ *
138
+ * Result:
139
+ * status "surfaced" | "not-surfaced"
140
+ * adjudicated {heeds, violations, verdict} evidence-cited, both directions
141
+ * loose {heeds, violations, verdict} heuristic channels included, both directions
142
+ * weak_not_violated count of not_violated signals (outside both tiers)
143
+ * label one display bucket for summary tables:
144
+ * adjudicated-heeded/violated/mixed → loose-heeded/violated/mixed
145
+ * → weak-not-violated → silent
146
+ */
147
+ export declare function classifyCorrection(events: HeedTierEvent[]): HeedCorrectionResult;
148
+ export interface HeedTierAggregate {
149
+ corrections: {
150
+ heeded: number;
151
+ violated: number;
152
+ mixed: number;
153
+ no_evidence: number;
154
+ denominator: number;
155
+ rate: number | null;
156
+ };
157
+ events: {
158
+ heeded: number;
159
+ recurred: number;
160
+ rate: number | null;
161
+ };
162
+ coverage_of_surfaced: number | null;
163
+ }
164
+ export interface HeedAggregateRow {
165
+ id: string;
166
+ project?: string;
167
+ retracted?: boolean;
168
+ result: HeedCorrectionResult;
169
+ }
170
+ export interface HeedAggregate {
171
+ corrections_total: number;
172
+ corrections_retracted: number;
173
+ corrections_live: number;
174
+ surfaced: number;
175
+ by_label: Record<string, number>;
176
+ adjudicated: HeedTierAggregate;
177
+ loose: HeedTierAggregate;
178
+ kpi_formula: {
179
+ rate: number | null;
180
+ heeded_all: number;
181
+ heeded_default_share: number;
182
+ heeded_default_fraction: number | null;
183
+ recurred: number;
184
+ };
185
+ no_evidence: {
186
+ no_adjudicated_evidence: number;
187
+ no_loose_evidence: number;
188
+ weak_not_violated_only: number;
189
+ silent: number;
190
+ share_without_adjudicated: number | null;
191
+ };
192
+ }
193
+ /**
194
+ * Aggregate per-correction results into the retrospective's headline numbers,
195
+ * SYMMETRICALLY tiered (adjudicated / loose — see the tier doc above) and
196
+ * presented as a range. `rows` = [{id, project, retracted, result}] where
197
+ * result = classifyCorrection().
198
+ *
199
+ * Retracted corrections are aggregated SEPARATELY: in this store every
200
+ * retraction is a "capture noise" triage (the record was never a real rule),
201
+ * so a retraction is an exclusion, NOT a violation — despite the fix11 task
202
+ * brief's suggestion, the data does not support counting retractions as
203
+ * violations.
204
+ */
205
+ export declare function aggregate(rows: HeedAggregateRow[]): HeedAggregate;
206
+ //# sourceMappingURL=heed-tiers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"heed-tiers.d.ts","sourceRoot":"","sources":["../../src/storage/heed-tiers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAMH,2EAA2E;AAC3E,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,MAAM,aAAa,GACrB,iBAAiB,GACjB,oBAAoB,GACpB,gBAAgB,GAChB,mBAAmB,GACnB,qBAAqB,GACrB,cAAc,GACd,UAAU,GACV,WAAW,GACX,YAAY,GACZ,OAAO,CAAC;AAEZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI,GAAG,SAAS,GAAG,aAAa,CAwBlF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,aAAa,CAGtD,CAAC;AACH,eAAO,MAAM,qBAAqB,EAAE,WAAW,CAAC,aAAa,CAE3D,CAAC;AACH,eAAO,MAAM,UAAU,EAAE,WAAW,CAAC,aAAa,CAGhD,CAAC;AACH,eAAO,MAAM,eAAe,EAAE,WAAW,CAAC,aAAa,CAGrD,CAAC;AAOH,iFAAiF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
+ /**
2
+ * heed-tiers.ts — symmetric evidence-tier classification for correction
3
+ * outcome events (the S0 heed-rate split: ADJUDICATED vs LOOSE, correction-
4
+ * level and event-level).
5
+ *
6
+ * PROVENANCE / SINGLE SOURCE OF TRUTH (fix12 hygiene, 2026-09-12): this logic
7
+ * was authored in `scripts/eval/heed-rate/lib.mjs` (fix11, review-hardened —
8
+ * symmetric tiering after the asymmetric-tiers HIGH finding) and MOVED here
9
+ * verbatim so the shipped KPI surfaces (`ar stats`) can present the tiered
10
+ * split without forking the eval's classification. `lib.mjs` now re-exports
11
+ * these functions from the built core — change the tiers HERE, never in a
12
+ * copy. The eval's mechanics tests (scripts/eval/heed-rate/heed-rate.test.mjs)
13
+ * exercise this implementation through the re-export.
14
+ *
15
+ * WHY TIERS (fix11 retrospective, 2026-09-12): the shipped KPI formula
16
+ * heed_rate = heeded/(heeded+recurred) is bookkeeping, not evidence — in the
17
+ * live store 75.8% of its numerator was pre-C3 default-heeded absence-of-
18
+ * evidence credit, and its denominator carried session_end self-report marker
19
+ * fan-out (3 of 4 correction-level "violated" verdicts traced to unrelated
20
+ * sessions). Presenting the single number invites 2×-style over-trust in
21
+ * either direction, so every KPI surface renders BOTH tiers as a range.
22
+ */
23
+ /**
24
+ * Evidence tiers for outcome-ledger events (_outcomes.jsonl lines).
25
+ *
26
+ * Tiering rationale (verified against the live store 2026-09-12 and against
27
+ * the producer code paths):
28
+ *
29
+ * heeded_verified kind=heeded, evidence starts "dream-audit:" — the C3b
30
+ * nightly audit cites verbatim transcript/journal
31
+ * compliance evidence. Strongest heed signal the ledger
32
+ * carries.
33
+ * heeded_checkaction kind=heeded, evidence mentions "check-action" — the C3
34
+ * authoritative session-end path (trigger evidence + no
35
+ * recurrence marker). Designed but NEVER observed in the
36
+ * live store (0 "triggered" events exist store-wide).
37
+ * heeded_default kind=heeded, anything else — the pre-C3 default-heeded
38
+ * bias ("no recurrence evidence in session summary",
39
+ * with or without the explicit "(default-heeded …)"
40
+ * marker). Credits heed on ABSENCE of evidence — loose
41
+ * tier only.
42
+ * recurred_verified kind=recurred, dream-audit prefix — audited violation.
43
+ * recurred_selfreport kind=recurred, otherwise — session-summary recurrence
44
+ * markers. Loose tier only: primary-evidence review
45
+ * (2026-09-12) showed session_end FANS one summary's
46
+ * marker out onto every correction with ≥2-3 topical
47
+ * content words, so these over-count violations from
48
+ * unrelated sessions (3 of 4 originally-"violated"
49
+ * verdicts were such fan-out artifacts).
50
+ * not_violated weak non-violation (topical overlap, no marker) — own
51
+ * counter by design, NEVER blended into heed_rate.
52
+ * surfaced kind=retrieved — the correction was injected.
53
+ * no_signal unknown / not_triggered — no compliance information.
54
+ * prediction predicted / predict_hit — prediction loop, not heed.
55
+ * other unrecognized kind (forward-compat).
56
+ *
57
+ * NOTE (class-not-instance): the tiers key off producer evidence-string
58
+ * conventions ("dream-audit:" prefix, "check-action" mention). If a producer
59
+ * changes wording, add a row HERE — every consumer (eval + `ar stats` +
60
+ * rmr-report) picks it up.
61
+ */
62
+ export function classifyEvent(evt) {
63
+ const kind = evt?.kind;
64
+ const evidence = (evt?.evidence ?? "").toLowerCase();
65
+ const isDream = evidence.startsWith("dream-audit:");
66
+ switch (kind) {
67
+ case "heeded":
68
+ if (isDream)
69
+ return "heeded_verified";
70
+ if (evidence.includes("check-action"))
71
+ return "heeded_checkaction";
72
+ return "heeded_default";
73
+ case "recurred":
74
+ return isDream ? "recurred_verified" : "recurred_selfreport";
75
+ case "not_violated":
76
+ return "not_violated";
77
+ case "retrieved":
78
+ return "surfaced";
79
+ case "unknown":
80
+ case "not_triggered":
81
+ return "no_signal";
82
+ case "predicted":
83
+ case "predict_hit":
84
+ return "prediction";
85
+ default:
86
+ return "other";
87
+ }
88
+ }
89
+ /**
90
+ * Symmetric evidence tiers (fix11 fix round 2026-09-12, review HIGH):
91
+ *
92
+ * The original design excluded default-heeded (absence-of-evidence POSITIVES)
93
+ * from the strict rate but trusted self-report recurrence markers
94
+ * (keyword-heuristic NEGATIVES) at full weight — asymmetric. Primary-evidence
95
+ * review proved the self-report channel over-counts: session_end fans one
96
+ * summary's recurrence marker out onto every correction with ≥2-3 topical
97
+ * content words, producing violation verdicts from unrelated sessions.
98
+ *
99
+ * So both rates are tiered SYMMETRICALLY and reported as a range:
100
+ *
101
+ * ADJUDICATED — evidence-cited verdicts only, both directions:
102
+ * heed: heeded_verified (dream-audit verbatim) + heeded_checkaction
103
+ * (C3 authoritative trigger; zero instances to date)
104
+ * violation: recurred_verified (dream-audit verbatim)
105
+ *
106
+ * LOOSE — heuristic channels included, both directions:
107
+ * heed: adjudicated heeds + heeded_default (pre-C3 absence-of-
108
+ * evidence credit)
109
+ * violation: adjudicated violations + recurred_selfreport (summary
110
+ * marker fan-out)
111
+ *
112
+ * At event level the LOOSE rate is by construction the shipped KPI formula
113
+ * heeded/(heeded+recurred). `not_violated` stays outside BOTH tiers (its own
114
+ * design contract — never blended into heed_rate).
115
+ */
116
+ export const ADJUDICATED_HEED = new Set([
117
+ "heeded_verified",
118
+ "heeded_checkaction",
119
+ ]);
120
+ export const ADJUDICATED_VIOLATION = new Set([
121
+ "recurred_verified",
122
+ ]);
123
+ export const LOOSE_HEED = new Set([
124
+ ...ADJUDICATED_HEED,
125
+ "heeded_default",
126
+ ]);
127
+ export const LOOSE_VIOLATION = new Set([
128
+ ...ADJUDICATED_VIOLATION,
129
+ "recurred_selfreport",
130
+ ]);
131
+ const COMPLIANCE_BEARING = new Set([
132
+ ...LOOSE_HEED,
133
+ ...LOOSE_VIOLATION,
134
+ "not_violated",
135
+ ]);
136
+ /** Local-calendar-day string for an ISO timestamp ("sv" locale = YYYY-MM-DD). */
137
+ export function dayOf(iso) {
138
+ const d = new Date(iso ?? "");
139
+ return Number.isNaN(d.getTime()) ? null : d.toLocaleDateString("sv");
140
+ }
141
+ /** Verdict within one evidence tier from heed/violation counts. */
142
+ function tierVerdict(heeds, violations) {
143
+ if (heeds > 0 && violations > 0)
144
+ return "mixed";
145
+ if (heeds > 0)
146
+ return "heeded";
147
+ if (violations > 0)
148
+ return "violated";
149
+ return "no-evidence";
150
+ }
151
+ /**
152
+ * Classify one correction's full event list into per-correction verdicts,
153
+ * one per evidence tier (symmetric tiering — see the tier doc above).
154
+ *
155
+ * Only events on/after the first surfacing day count toward compliance —
156
+ * "did SUBSEQUENT behavior comply" (same-day counts as subsequent: retrieval
157
+ * fires at session_start, verdicts at session_end / overnight audit, and the
158
+ * C3b audit backdates `at` to the audited day).
159
+ *
160
+ * Result:
161
+ * status "surfaced" | "not-surfaced"
162
+ * adjudicated {heeds, violations, verdict} evidence-cited, both directions
163
+ * loose {heeds, violations, verdict} heuristic channels included, both directions
164
+ * weak_not_violated count of not_violated signals (outside both tiers)
165
+ * label one display bucket for summary tables:
166
+ * adjudicated-heeded/violated/mixed → loose-heeded/violated/mixed
167
+ * → weak-not-violated → silent
168
+ */
169
+ export function classifyCorrection(events) {
170
+ const empty = { heeds: 0, violations: 0, verdict: "no-evidence" };
171
+ const surfacings = events.filter((e) => e.kind === "retrieved" && dayOf(e.at));
172
+ if (surfacings.length === 0) {
173
+ return {
174
+ status: "not-surfaced", label: "not-surfaced", surfaced_count: 0, first_surfaced: null,
175
+ adjudicated: { ...empty }, loose: { ...empty }, weak_not_violated: 0,
176
+ tiers: {}, pre_surfacing: [], evidence: [],
177
+ };
178
+ }
179
+ const firstDay = surfacings.map((e) => dayOf(e.at)).sort()[0];
180
+ const tiers = {};
181
+ const evidence = [];
182
+ const preSurfacing = [];
183
+ for (const e of events) {
184
+ const tier = classifyEvent(e);
185
+ const day = dayOf(e.at);
186
+ // Compliance-bearing events strictly BEFORE first surfacing cannot answer
187
+ // "did behavior comply after the rule was surfaced" — flagged, not counted.
188
+ if (COMPLIANCE_BEARING.has(tier) && day !== null && firstDay !== null && day < firstDay) {
189
+ preSurfacing.push({ tier, at: e.at, evidence: e.evidence ?? "" });
190
+ continue;
191
+ }
192
+ tiers[tier] = (tiers[tier] ?? 0) + 1;
193
+ if (COMPLIANCE_BEARING.has(tier) || tier === "no_signal") {
194
+ evidence.push({ tier, at: e.at, evidence: e.evidence ?? "" });
195
+ }
196
+ }
197
+ const count = (set) => [...set].reduce((n, t) => n + (tiers[t] ?? 0), 0);
198
+ const adjHeeds = count(ADJUDICATED_HEED);
199
+ const adjViolations = count(ADJUDICATED_VIOLATION);
200
+ const adjudicated = {
201
+ heeds: adjHeeds,
202
+ violations: adjViolations,
203
+ verdict: tierVerdict(adjHeeds, adjViolations),
204
+ };
205
+ const looseHeeds = count(LOOSE_HEED);
206
+ const looseViolations = count(LOOSE_VIOLATION);
207
+ const loose = {
208
+ heeds: looseHeeds,
209
+ violations: looseViolations,
210
+ verdict: tierVerdict(looseHeeds, looseViolations),
211
+ };
212
+ const weakNotViolated = tiers.not_violated ?? 0;
213
+ let label;
214
+ if (adjudicated.verdict !== "no-evidence")
215
+ label = `adjudicated-${adjudicated.verdict}`;
216
+ else if (loose.verdict !== "no-evidence")
217
+ label = `loose-${loose.verdict}`;
218
+ else if (weakNotViolated > 0)
219
+ label = "weak-not-violated";
220
+ else
221
+ label = "silent";
222
+ return {
223
+ status: "surfaced",
224
+ label,
225
+ surfaced_count: surfacings.length,
226
+ first_surfaced: firstDay,
227
+ adjudicated,
228
+ loose,
229
+ weak_not_violated: weakNotViolated,
230
+ tiers,
231
+ pre_surfacing: preSurfacing,
232
+ evidence,
233
+ };
234
+ }
235
+ /** Correction-level + event-level rates for ONE evidence tier. */
236
+ function tierAggregate(surfaced, tierKey) {
237
+ const byVerdict = {
238
+ heeded: 0, violated: 0, mixed: 0, "no-evidence": 0,
239
+ };
240
+ let evHeeds = 0, evViolations = 0;
241
+ for (const r of surfaced) {
242
+ const t = r.result[tierKey];
243
+ byVerdict[t.verdict] = (byVerdict[t.verdict] ?? 0) + 1;
244
+ evHeeds += t.heeds;
245
+ evViolations += t.violations;
246
+ }
247
+ const denom = byVerdict.heeded + byVerdict.violated + byVerdict.mixed;
248
+ return {
249
+ corrections: {
250
+ heeded: byVerdict.heeded,
251
+ violated: byVerdict.violated,
252
+ mixed: byVerdict.mixed, // counts AGAINST the numerator: a violation after surfacing is a heed failure even if a separate day complied
253
+ no_evidence: byVerdict["no-evidence"],
254
+ denominator: denom,
255
+ rate: denom > 0 ? byVerdict.heeded / denom : null,
256
+ },
257
+ events: {
258
+ heeded: evHeeds,
259
+ recurred: evViolations,
260
+ rate: evHeeds + evViolations > 0 ? evHeeds / (evHeeds + evViolations) : null,
261
+ },
262
+ coverage_of_surfaced: surfaced.length > 0 ? denom / surfaced.length : null,
263
+ };
264
+ }
265
+ /**
266
+ * Aggregate per-correction results into the retrospective's headline numbers,
267
+ * SYMMETRICALLY tiered (adjudicated / loose — see the tier doc above) and
268
+ * presented as a range. `rows` = [{id, project, retracted, result}] where
269
+ * result = classifyCorrection().
270
+ *
271
+ * Retracted corrections are aggregated SEPARATELY: in this store every
272
+ * retraction is a "capture noise" triage (the record was never a real rule),
273
+ * so a retraction is an exclusion, NOT a violation — despite the fix11 task
274
+ * brief's suggestion, the data does not support counting retractions as
275
+ * violations.
276
+ */
277
+ export function aggregate(rows) {
278
+ const live = rows.filter((r) => !r.retracted);
279
+ const surfaced = live.filter((r) => r.result.status === "surfaced");
280
+ const byLabel = {};
281
+ for (const r of surfaced)
282
+ byLabel[r.result.label] = (byLabel[r.result.label] ?? 0) + 1;
283
+ const adjudicated = tierAggregate(surfaced, "adjudicated");
284
+ const loose = tierAggregate(surfaced, "loose");
285
+ // The shipped KPI formula heeded/(heeded+recurred) equals the LOOSE
286
+ // event-level rate by construction; annotate its numerator composition.
287
+ let evHeedDefault = 0;
288
+ for (const r of surfaced)
289
+ evHeedDefault += r.result.tiers?.heeded_default ?? 0;
290
+ const kpi_formula = {
291
+ rate: loose.events.rate,
292
+ heeded_all: loose.events.heeded,
293
+ heeded_default_share: evHeedDefault, // absence-of-evidence credit inside the numerator
294
+ heeded_default_fraction: loose.events.heeded > 0 ? evHeedDefault / loose.events.heeded : null,
295
+ recurred: loose.events.recurred,
296
+ };
297
+ return {
298
+ corrections_total: rows.length,
299
+ corrections_retracted: rows.length - live.length,
300
+ corrections_live: live.length,
301
+ surfaced: surfaced.length,
302
+ by_label: byLabel,
303
+ adjudicated,
304
+ loose,
305
+ kpi_formula,
306
+ // Absence-of-evidence classes (the honest denominator problem):
307
+ no_evidence: {
308
+ no_adjudicated_evidence: surfaced.length - adjudicated.corrections.denominator,
309
+ no_loose_evidence: surfaced.length - loose.corrections.denominator,
310
+ weak_not_violated_only: byLabel["weak-not-violated"] ?? 0,
311
+ silent: byLabel.silent ?? 0,
312
+ share_without_adjudicated: surfaced.length > 0
313
+ ? (surfaced.length - adjudicated.corrections.denominator) / surfaced.length
314
+ : null,
315
+ },
316
+ };
317
+ }
318
+ //# sourceMappingURL=heed-tiers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"heed-tiers.js","sourceRoot":"","sources":["../../src/storage/heed-tiers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAyBH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,UAAU,aAAa,CAAC,GAAqC;IACjE,MAAM,IAAI,GAAG,GAAG,EAAE,IAAI,CAAC;IACvB,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,QAAQ,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IACrD,MAAM,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;IACpD,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,QAAQ;YACX,IAAI,OAAO;gBAAE,OAAO,iBAAiB,CAAC;YACtC,IAAI,QAAQ,CAAC,QAAQ,CAAC,cAAc,CAAC;gBAAE,OAAO,oBAAoB,CAAC;YACnE,OAAO,gBAAgB,CAAC;QAC1B,KAAK,UAAU;YACb,OAAO,OAAO,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,qBAAqB,CAAC;QAC/D,KAAK,cAAc;YACjB,OAAO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W;QACX,KAAK;QACL,WAAW;QACX,gEAAgE;QAChE,WAAW,EAAE;YACX,uBAAuB,EAAE,QAAQ,CAAC,MAAM,GAAG,WAAW,CAAC,WAAW,CAAC,WAAW;YAC9E,iBAAiB,EAAE,QAAQ,CAAC,MAAM,GAAG,KAAK,CAAC,WAAW,CAAC,WAAW;YAClE,sBAAsB,EAAE,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC;YACzD,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,CAAC;YAC3B,yBAAyB,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC;gBAC5C,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,GAAG,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,MAAM;gBAC3E,CAAC,CAAC,IAAI;SACT;KACF,CAAC;AACJ,CAAC"}
@@ -22,61 +22,61 @@ const PROTOCOL_FILENAME = "MEMORY-PROTOCOL.md";
22
22
  function projectRoot(project) {
23
23
  return projectSubPath(project);
24
24
  }
25
- const PROTOCOL_BODY = `# AgentRecall — Memory Protocol
26
-
27
- > Self-describing, substrate-independent memory layout. A cold agent (no MCP)
28
- > can read and write this folder by convention alone. Local-first; an optional
29
- > local git commit substrate may sit on top, but **no remote push** is wired
30
- > until the privacy split is proven.
31
-
32
- ## Two-tier memory with a bridge
33
-
34
- \`\`\`
35
- journal/archive/raw/ ← MECHANICAL ARCHIVE (lossless, verbatim, never lost)
36
- appended on EVERY session end, zero judgment.
37
- awareness / palace skills ← QUALITY COMPRESSION (lossy, reasoned)
38
- distilled by the async dreaming loop, NOT in the Stop turn.
39
- \`\`\`
40
-
41
- When the compressed tier is **not confident**, retrieval drills DOWN into the
42
- lossless archive instead of answering thinly (the bridge).
43
-
44
- ## Folder layout
45
-
46
- - \`journal/\` — curated session stream (capped excerpts; the working narrative).
47
- - \`journal/archive/raw/<date>--<sessionId>.md\` — verbatim session dumps. Each
48
- file has small frontmatter (\`project, sessionId, savedAt, source\`) then the
49
- raw transcript head+tail. **Never** synced to any remote.
50
- - \`journal/archive/raw/.consumed.json\` — \`{ lastConsumedOffset, lastConsumedAt }\`.
51
- The dreaming loop advances this marker as it distills raw segments upward.
52
- - \`journal/archive/index.md\` — one append-only line per dump.
53
- - \`palace/\` — rooms (project knowledge), skills (procedural memory), pipeline,
54
- awareness (behavioral layer — PERSONAL, sync-excluded by default).
55
- - \`corrections/\` — human corrections (PERSONAL, never synced).
56
-
57
- ## Consume seam (async dreaming)
58
-
59
- Raw dumps are queued for compression, never compressed inside the Stop turn:
60
-
61
- \`\`\`
62
- ../../.consolidation-queue/<date>.jsonl ← one JSON job per line, relative
63
- to this file (../.. = the store
64
- root, two levels up from
65
- projects/<slug>/)
66
- \`\`\`
67
-
68
- A job looks like \`{ "project", "sessionId", "reason", "at", "done"? }\`.
69
- Drain the queue out-of-band (e.g. \`ar consolidate-async\`): run consolidation
70
- per job, mark each line \`done:true\`. One bad job must never block the rest.
71
-
72
- ## Cold-agent read/write rules
73
-
74
- 1. To **read**: prefer the curated \`journal/\` + \`palace/\`. If a hit is
75
- low-confidence, open the matching \`journal/archive/raw/\` file verbatim.
76
- 2. To **write a session**: append a verbatim file under \`journal/archive/raw/\`
77
- keyed on the session UUID (idempotent), then enqueue a consolidation job.
78
- 3. **Never** sync \`awareness\`, \`corrections\`, \`personal/\`, or \`_global\` palace
79
- to any remote without an explicit \`sync_personal=true\` opt-in.
25
+ const PROTOCOL_BODY = `# AgentRecall — Memory Protocol
26
+
27
+ > Self-describing, substrate-independent memory layout. A cold agent (no MCP)
28
+ > can read and write this folder by convention alone. Local-first; an optional
29
+ > local git commit substrate may sit on top, but **no remote push** is wired
30
+ > until the privacy split is proven.
31
+
32
+ ## Two-tier memory with a bridge
33
+
34
+ \`\`\`
35
+ journal/archive/raw/ ← MECHANICAL ARCHIVE (lossless, verbatim, never lost)
36
+ appended on EVERY session end, zero judgment.
37
+ awareness / palace skills ← QUALITY COMPRESSION (lossy, reasoned)
38
+ distilled by the async dreaming loop, NOT in the Stop turn.
39
+ \`\`\`
40
+
41
+ When the compressed tier is **not confident**, retrieval drills DOWN into the
42
+ lossless archive instead of answering thinly (the bridge).
43
+
44
+ ## Folder layout
45
+
46
+ - \`journal/\` — curated session stream (capped excerpts; the working narrative).
47
+ - \`journal/archive/raw/<date>--<sessionId>.md\` — verbatim session dumps. Each
48
+ file has small frontmatter (\`project, sessionId, savedAt, source\`) then the
49
+ raw transcript head+tail. **Never** synced to any remote.
50
+ - \`journal/archive/raw/.consumed.json\` — \`{ lastConsumedOffset, lastConsumedAt }\`.
51
+ The dreaming loop advances this marker as it distills raw segments upward.
52
+ - \`journal/archive/index.md\` — one append-only line per dump.
53
+ - \`palace/\` — rooms (project knowledge), skills (procedural memory), pipeline,
54
+ awareness (behavioral layer — PERSONAL, sync-excluded by default).
55
+ - \`corrections/\` — human corrections (PERSONAL, never synced).
56
+
57
+ ## Consume seam (async dreaming)
58
+
59
+ Raw dumps are queued for compression, never compressed inside the Stop turn:
60
+
61
+ \`\`\`
62
+ ../../.consolidation-queue/<date>.jsonl ← one JSON job per line, relative
63
+ to this file (../.. = the store
64
+ root, two levels up from
65
+ projects/<slug>/)
66
+ \`\`\`
67
+
68
+ A job looks like \`{ "project", "sessionId", "reason", "at", "done"? }\`.
69
+ Drain the queue out-of-band (e.g. \`ar consolidate-async\`): run consolidation
70
+ per job, mark each line \`done:true\`. One bad job must never block the rest.
71
+
72
+ ## Cold-agent read/write rules
73
+
74
+ 1. To **read**: prefer the curated \`journal/\` + \`palace/\`. If a hit is
75
+ low-confidence, open the matching \`journal/archive/raw/\` file verbatim.
76
+ 2. To **write a session**: append a verbatim file under \`journal/archive/raw/\`
77
+ keyed on the session UUID (idempotent), then enqueue a consolidation job.
78
+ 3. **Never** sync \`awareness\`, \`corrections\`, \`personal/\`, or \`_global\` palace
79
+ to any remote without an explicit \`sync_personal=true\` opt-in.
80
80
  `;
81
81
  /**
82
82
  * Write the project's MEMORY-PROTOCOL.md if it is absent (write-once).