agent-recall-core 3.4.30 → 3.4.35

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 (251) hide show
  1. package/README.md +121 -441
  2. package/dist/digest/store.d.ts.map +1 -1
  3. package/dist/digest/store.js +4 -3
  4. package/dist/digest/store.js.map +1 -1
  5. package/dist/display/board-render.d.ts +61 -0
  6. package/dist/display/board-render.d.ts.map +1 -0
  7. package/dist/display/board-render.js +223 -0
  8. package/dist/display/board-render.js.map +1 -0
  9. package/dist/helpers/alignment-patterns.d.ts +10 -0
  10. package/dist/helpers/alignment-patterns.d.ts.map +1 -1
  11. package/dist/helpers/alignment-patterns.js +5 -1
  12. package/dist/helpers/alignment-patterns.js.map +1 -1
  13. package/dist/helpers/blind-spots.d.ts +86 -0
  14. package/dist/helpers/blind-spots.d.ts.map +1 -0
  15. package/dist/helpers/blind-spots.js +205 -0
  16. package/dist/helpers/blind-spots.js.map +1 -0
  17. package/dist/helpers/conflict-scan.d.ts +10 -0
  18. package/dist/helpers/conflict-scan.d.ts.map +1 -1
  19. package/dist/helpers/conflict-scan.js +3 -3
  20. package/dist/helpers/conflict-scan.js.map +1 -1
  21. package/dist/helpers/semantic-match.d.ts +82 -0
  22. package/dist/helpers/semantic-match.d.ts.map +1 -0
  23. package/dist/helpers/semantic-match.js +229 -0
  24. package/dist/helpers/semantic-match.js.map +1 -0
  25. package/dist/index.d.ts +52 -11
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +48 -9
  28. package/dist/index.js.map +1 -1
  29. package/dist/palace/awareness.d.ts +30 -0
  30. package/dist/palace/awareness.d.ts.map +1 -1
  31. package/dist/palace/awareness.js +65 -2
  32. package/dist/palace/awareness.js.map +1 -1
  33. package/dist/palace/consolidate.d.ts.map +1 -1
  34. package/dist/palace/consolidate.js +17 -0
  35. package/dist/palace/consolidate.js.map +1 -1
  36. package/dist/palace/decay-pass.d.ts +46 -0
  37. package/dist/palace/decay-pass.d.ts.map +1 -0
  38. package/dist/palace/decay-pass.js +87 -0
  39. package/dist/palace/decay-pass.js.map +1 -0
  40. package/dist/palace/insights-index.d.ts.map +1 -1
  41. package/dist/palace/insights-index.js +4 -2
  42. package/dist/palace/insights-index.js.map +1 -1
  43. package/dist/palace/skills.d.ts +41 -2
  44. package/dist/palace/skills.d.ts.map +1 -1
  45. package/dist/palace/skills.js +106 -4
  46. package/dist/palace/skills.js.map +1 -1
  47. package/dist/prompts/consolidation-prompt.d.ts +25 -0
  48. package/dist/prompts/consolidation-prompt.d.ts.map +1 -0
  49. package/dist/prompts/consolidation-prompt.js +91 -0
  50. package/dist/prompts/consolidation-prompt.js.map +1 -0
  51. package/dist/storage/archive-prune.d.ts +56 -0
  52. package/dist/storage/archive-prune.d.ts.map +1 -0
  53. package/dist/storage/archive-prune.js +118 -0
  54. package/dist/storage/archive-prune.js.map +1 -0
  55. package/dist/storage/archive-write.d.ts +38 -0
  56. package/dist/storage/archive-write.d.ts.map +1 -0
  57. package/dist/storage/archive-write.js +98 -0
  58. package/dist/storage/archive-write.js.map +1 -0
  59. package/dist/storage/blind-spots-store.d.ts +30 -0
  60. package/dist/storage/blind-spots-store.d.ts.map +1 -0
  61. package/dist/storage/blind-spots-store.js +91 -0
  62. package/dist/storage/blind-spots-store.js.map +1 -0
  63. package/dist/storage/capture-router.d.ts +60 -0
  64. package/dist/storage/capture-router.d.ts.map +1 -0
  65. package/dist/storage/capture-router.js +133 -0
  66. package/dist/storage/capture-router.js.map +1 -0
  67. package/dist/storage/classification.d.ts +32 -0
  68. package/dist/storage/classification.d.ts.map +1 -0
  69. package/dist/storage/classification.js +74 -0
  70. package/dist/storage/classification.js.map +1 -0
  71. package/dist/storage/consolidation-queue.d.ts +39 -0
  72. package/dist/storage/consolidation-queue.d.ts.map +1 -0
  73. package/dist/storage/consolidation-queue.js +120 -0
  74. package/dist/storage/consolidation-queue.js.map +1 -0
  75. package/dist/storage/content-guard.d.ts +74 -0
  76. package/dist/storage/content-guard.d.ts.map +1 -0
  77. package/dist/storage/content-guard.js +179 -0
  78. package/dist/storage/content-guard.js.map +1 -0
  79. package/dist/storage/corrections.d.ts +246 -21
  80. package/dist/storage/corrections.d.ts.map +1 -1
  81. package/dist/storage/corrections.js +605 -56
  82. package/dist/storage/corrections.js.map +1 -1
  83. package/dist/storage/durable-intent.d.ts +49 -0
  84. package/dist/storage/durable-intent.d.ts.map +1 -0
  85. package/dist/storage/durable-intent.js +124 -0
  86. package/dist/storage/durable-intent.js.map +1 -0
  87. package/dist/storage/filelock.d.ts +6 -0
  88. package/dist/storage/filelock.d.ts.map +1 -1
  89. package/dist/storage/filelock.js +6 -1
  90. package/dist/storage/filelock.js.map +1 -1
  91. package/dist/storage/memory-protocol.d.ts +19 -0
  92. package/dist/storage/memory-protocol.d.ts.map +1 -0
  93. package/dist/storage/memory-protocol.js +101 -0
  94. package/dist/storage/memory-protocol.js.map +1 -0
  95. package/dist/storage/paths.d.ts +23 -0
  96. package/dist/storage/paths.d.ts.map +1 -1
  97. package/dist/storage/paths.js +39 -0
  98. package/dist/storage/paths.js.map +1 -1
  99. package/dist/storage/retention.d.ts +23 -0
  100. package/dist/storage/retention.d.ts.map +1 -0
  101. package/dist/storage/retention.js +48 -0
  102. package/dist/storage/retention.js.map +1 -0
  103. package/dist/storage/session.d.ts +2 -2
  104. package/dist/storage/session.d.ts.map +1 -1
  105. package/dist/storage/session.js +11 -1
  106. package/dist/storage/session.js.map +1 -1
  107. package/dist/supabase/config.d.ts +8 -0
  108. package/dist/supabase/config.d.ts.map +1 -1
  109. package/dist/supabase/config.js +5 -0
  110. package/dist/supabase/config.js.map +1 -1
  111. package/dist/supabase/recall-backend.d.ts +1 -0
  112. package/dist/supabase/recall-backend.d.ts.map +1 -1
  113. package/dist/supabase/recall-backend.js +13 -13
  114. package/dist/supabase/recall-backend.js.map +1 -1
  115. package/dist/supabase/sync.d.ts.map +1 -1
  116. package/dist/supabase/sync.js +30 -3
  117. package/dist/supabase/sync.js.map +1 -1
  118. package/dist/tools-logic/bootstrap.d.ts +15 -0
  119. package/dist/tools-logic/bootstrap.d.ts.map +1 -1
  120. package/dist/tools-logic/bootstrap.js +238 -47
  121. package/dist/tools-logic/bootstrap.js.map +1 -1
  122. package/dist/tools-logic/brief.d.ts +84 -0
  123. package/dist/tools-logic/brief.d.ts.map +1 -0
  124. package/dist/tools-logic/brief.js +193 -0
  125. package/dist/tools-logic/brief.js.map +1 -0
  126. package/dist/tools-logic/check-action.d.ts +9 -0
  127. package/dist/tools-logic/check-action.d.ts.map +1 -1
  128. package/dist/tools-logic/check-action.js +31 -2
  129. package/dist/tools-logic/check-action.js.map +1 -1
  130. package/dist/tools-logic/check.d.ts +7 -0
  131. package/dist/tools-logic/check.d.ts.map +1 -1
  132. package/dist/tools-logic/check.js +24 -2
  133. package/dist/tools-logic/check.js.map +1 -1
  134. package/dist/tools-logic/confidence.d.ts +50 -0
  135. package/dist/tools-logic/confidence.d.ts.map +1 -0
  136. package/dist/tools-logic/confidence.js +70 -0
  137. package/dist/tools-logic/confidence.js.map +1 -0
  138. package/dist/tools-logic/drill-down.d.ts +37 -0
  139. package/dist/tools-logic/drill-down.d.ts.map +1 -0
  140. package/dist/tools-logic/drill-down.js +63 -0
  141. package/dist/tools-logic/drill-down.js.map +1 -0
  142. package/dist/tools-logic/export-corrections.d.ts +63 -0
  143. package/dist/tools-logic/export-corrections.d.ts.map +1 -0
  144. package/dist/tools-logic/export-corrections.js +124 -0
  145. package/dist/tools-logic/export-corrections.js.map +1 -0
  146. package/dist/tools-logic/journal-capture.d.ts.map +1 -1
  147. package/dist/tools-logic/journal-capture.js +4 -1
  148. package/dist/tools-logic/journal-capture.js.map +1 -1
  149. package/dist/tools-logic/journal-write.d.ts.map +1 -1
  150. package/dist/tools-logic/journal-write.js +3 -2
  151. package/dist/tools-logic/journal-write.js.map +1 -1
  152. package/dist/tools-logic/memory-query.d.ts +10 -3
  153. package/dist/tools-logic/memory-query.d.ts.map +1 -1
  154. package/dist/tools-logic/memory-query.js +31 -7
  155. package/dist/tools-logic/memory-query.js.map +1 -1
  156. package/dist/tools-logic/mirror-builder.d.ts +115 -0
  157. package/dist/tools-logic/mirror-builder.d.ts.map +1 -0
  158. package/dist/tools-logic/mirror-builder.js +348 -0
  159. package/dist/tools-logic/mirror-builder.js.map +1 -0
  160. package/dist/tools-logic/palace-write.d.ts.map +1 -1
  161. package/dist/tools-logic/palace-write.js +3 -2
  162. package/dist/tools-logic/palace-write.js.map +1 -1
  163. package/dist/tools-logic/pipeline-close.d.ts.map +1 -1
  164. package/dist/tools-logic/pipeline-close.js +2 -1
  165. package/dist/tools-logic/pipeline-close.js.map +1 -1
  166. package/dist/tools-logic/pipeline-open.d.ts.map +1 -1
  167. package/dist/tools-logic/pipeline-open.js +2 -1
  168. package/dist/tools-logic/pipeline-open.js.map +1 -1
  169. package/dist/tools-logic/predict-correction.d.ts +47 -0
  170. package/dist/tools-logic/predict-correction.d.ts.map +1 -0
  171. package/dist/tools-logic/predict-correction.js +137 -0
  172. package/dist/tools-logic/predict-correction.js.map +1 -0
  173. package/dist/tools-logic/prior-builder.d.ts +27 -0
  174. package/dist/tools-logic/prior-builder.d.ts.map +1 -0
  175. package/dist/tools-logic/prior-builder.js +57 -0
  176. package/dist/tools-logic/prior-builder.js.map +1 -0
  177. package/dist/tools-logic/recognition-builder.d.ts +116 -0
  178. package/dist/tools-logic/recognition-builder.d.ts.map +1 -0
  179. package/dist/tools-logic/recognition-builder.js +289 -0
  180. package/dist/tools-logic/recognition-builder.js.map +1 -0
  181. package/dist/tools-logic/safety-consolidation.d.ts +104 -0
  182. package/dist/tools-logic/safety-consolidation.d.ts.map +1 -0
  183. package/dist/tools-logic/safety-consolidation.js +256 -0
  184. package/dist/tools-logic/safety-consolidation.js.map +1 -0
  185. package/dist/tools-logic/session-end-reflect.d.ts +18 -0
  186. package/dist/tools-logic/session-end-reflect.d.ts.map +1 -1
  187. package/dist/tools-logic/session-end-reflect.js +68 -29
  188. package/dist/tools-logic/session-end-reflect.js.map +1 -1
  189. package/dist/tools-logic/session-end.d.ts +9 -0
  190. package/dist/tools-logic/session-end.d.ts.map +1 -1
  191. package/dist/tools-logic/session-end.js +111 -13
  192. package/dist/tools-logic/session-end.js.map +1 -1
  193. package/dist/tools-logic/session-start-lite.d.ts +2 -0
  194. package/dist/tools-logic/session-start-lite.d.ts.map +1 -1
  195. package/dist/tools-logic/session-start-lite.js +10 -0
  196. package/dist/tools-logic/session-start-lite.js.map +1 -1
  197. package/dist/tools-logic/session-start.d.ts +46 -0
  198. package/dist/tools-logic/session-start.d.ts.map +1 -1
  199. package/dist/tools-logic/session-start.js +96 -3
  200. package/dist/tools-logic/session-start.js.map +1 -1
  201. package/dist/tools-logic/skill-propose.d.ts +27 -0
  202. package/dist/tools-logic/skill-propose.d.ts.map +1 -0
  203. package/dist/tools-logic/skill-propose.js +66 -0
  204. package/dist/tools-logic/skill-propose.js.map +1 -0
  205. package/dist/tools-logic/skill-recall.d.ts +5 -0
  206. package/dist/tools-logic/skill-recall.d.ts.map +1 -1
  207. package/dist/tools-logic/skill-recall.js +14 -1
  208. package/dist/tools-logic/skill-recall.js.map +1 -1
  209. package/dist/tools-logic/smart-recall.d.ts +17 -0
  210. package/dist/tools-logic/smart-recall.d.ts.map +1 -1
  211. package/dist/tools-logic/smart-recall.js +51 -16
  212. package/dist/tools-logic/smart-recall.js.map +1 -1
  213. package/dist/tools-logic/store-doctor.d.ts +71 -0
  214. package/dist/tools-logic/store-doctor.d.ts.map +1 -0
  215. package/dist/tools-logic/store-doctor.js +387 -0
  216. package/dist/tools-logic/store-doctor.js.map +1 -0
  217. package/dist/tools-logic/store-repair.d.ts +64 -0
  218. package/dist/tools-logic/store-repair.d.ts.map +1 -0
  219. package/dist/tools-logic/store-repair.js +243 -0
  220. package/dist/tools-logic/store-repair.js.map +1 -0
  221. package/dist/tools-logic/supersession.d.ts +34 -0
  222. package/dist/tools-logic/supersession.d.ts.map +1 -0
  223. package/dist/tools-logic/supersession.js +103 -0
  224. package/dist/tools-logic/supersession.js.map +1 -0
  225. package/dist/types.d.ts +7 -1
  226. package/dist/types.d.ts.map +1 -1
  227. package/dist/types.js +1 -1
  228. package/dist/vector/local-vector-backend.d.ts.map +1 -1
  229. package/dist/vector/local-vector-backend.js +14 -17
  230. package/dist/vector/local-vector-backend.js.map +1 -1
  231. package/package.json +9 -1
  232. package/dist/relevance/injector.d.ts +0 -51
  233. package/dist/relevance/injector.d.ts.map +0 -1
  234. package/dist/relevance/injector.js +0 -121
  235. package/dist/relevance/injector.js.map +0 -1
  236. package/dist/relevance/precision.d.ts +0 -109
  237. package/dist/relevance/precision.d.ts.map +0 -1
  238. package/dist/relevance/precision.js +0 -279
  239. package/dist/relevance/precision.js.map +0 -1
  240. package/dist/relevance/promoter.d.ts +0 -60
  241. package/dist/relevance/promoter.d.ts.map +0 -1
  242. package/dist/relevance/promoter.js +0 -336
  243. package/dist/relevance/promoter.js.map +0 -1
  244. package/dist/relevance/stager.d.ts +0 -61
  245. package/dist/relevance/stager.d.ts.map +0 -1
  246. package/dist/relevance/stager.js +0 -251
  247. package/dist/relevance/stager.js.map +0 -1
  248. package/dist/relevance/surfacer.d.ts +0 -34
  249. package/dist/relevance/surfacer.d.ts.map +0 -1
  250. package/dist/relevance/surfacer.js +0 -333
  251. package/dist/relevance/surfacer.js.map +0 -1
@@ -0,0 +1,47 @@
1
+ /**
2
+ * predict-correction.ts — the north-star: anticipate a correction BEFORE the
3
+ * user makes it (Wave 5, Decision #8).
4
+ *
5
+ * Given a plan, overlap its tokens against the corrections-derived Blind-Spots
6
+ * profile. A fired risk means "this plan resembles a tendency you have been
7
+ * corrected on" — pushed as an EARLY prior at session_start / check(), not a
8
+ * RAG fact pulled late. Synchronous (Decision #3 — retrieval is a function, no
9
+ * spawned per-call agent). Reuses the exported tokenize/overlap grammar from
10
+ * check-action (Wave 4) — does NOT fork it.
11
+ */
12
+ export interface PredictCorrectionInput {
13
+ /** The plan / action / goal text to evaluate. */
14
+ plan: string;
15
+ project?: string;
16
+ }
17
+ export interface PredictedRisk {
18
+ /** The tendency this plan resembles. */
19
+ tendency: string;
20
+ /** Normalized risk score for this single tendency (0–1). */
21
+ score: number;
22
+ /** The plan tokens that matched the tendency's trigger keywords. */
23
+ matched: string[];
24
+ /** Correction id this risk is anchored to (for outcome instrumentation). */
25
+ correction_id?: string;
26
+ severity: "p0" | "p1";
27
+ }
28
+ export interface PredictCorrectionResult {
29
+ /** High-threshold-first likelihood band. */
30
+ likelihood: "high" | "medium" | "low";
31
+ /** Top fired risks (capped). */
32
+ top_risks: PredictedRisk[];
33
+ /** Blind-spot tendencies that matched (for orientation display). */
34
+ matched_blind_spots: string[];
35
+ /** A single actionable guard line the agent can act on, or null. */
36
+ suggested_guard: string | null;
37
+ }
38
+ /**
39
+ * LOCAL semantic-similarity floor for a risk to fire when the keyword path does
40
+ * NOT (Loop 5). Re-exported from blind-spots.ts (the single matching grammar) so
41
+ * production and the LOO eval share ONE threshold. Tuned on the real corpus to
42
+ * balance recall against false positives on unrelated pairs. No API key, no
43
+ * network — pure stemming + concept map + char-trigram cosine.
44
+ */
45
+ export declare const SEMANTIC_THRESHOLD = 0.2;
46
+ export declare function predictCorrection(input: PredictCorrectionInput): Promise<PredictCorrectionResult>;
47
+ //# sourceMappingURL=predict-correction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predict-correction.d.ts","sourceRoot":"","sources":["../../src/tools-logic/predict-correction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAQH,MAAM,WAAW,sBAAsB;IACrC,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,wCAAwC;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,4EAA4E;IAC5E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,uBAAuB;IACtC,4CAA4C;IAC5C,UAAU,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IACtC,gCAAgC;IAChC,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,oEAAoE;IACpE,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,oEAAoE;IACpE,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAID;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,MAAgC,CAAC;AAyBhE,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,sBAAsB,GAC5B,OAAO,CAAC,uBAAuB,CAAC,CAgGlC"}
@@ -0,0 +1,137 @@
1
+ /**
2
+ * predict-correction.ts — the north-star: anticipate a correction BEFORE the
3
+ * user makes it (Wave 5, Decision #8).
4
+ *
5
+ * Given a plan, overlap its tokens against the corrections-derived Blind-Spots
6
+ * profile. A fired risk means "this plan resembles a tendency you have been
7
+ * corrected on" — pushed as an EARLY prior at session_start / check(), not a
8
+ * RAG fact pulled late. Synchronous (Decision #3 — retrieval is a function, no
9
+ * spawned per-call agent). Reuses the exported tokenize/overlap grammar from
10
+ * check-action (Wave 4) — does NOT fork it.
11
+ */
12
+ import { resolveProject } from "../storage/project.js";
13
+ import { tokenize, overlap } from "./check-action.js";
14
+ import { readBlindSpots, recomputeBlindSpots } from "../storage/blind-spots-store.js";
15
+ import { readActiveCorrections, recordOutcome } from "../storage/corrections.js";
16
+ import { matchesBlindSpot, BLIND_SPOT_SEMANTIC_THRESHOLD } from "../helpers/blind-spots.js";
17
+ /** Minimum trigger-keyword overlap for a risk to fire (strict — mirrors prior-builder). */
18
+ const MIN_OVERLAP = 2;
19
+ /**
20
+ * LOCAL semantic-similarity floor for a risk to fire when the keyword path does
21
+ * NOT (Loop 5). Re-exported from blind-spots.ts (the single matching grammar) so
22
+ * production and the LOO eval share ONE threshold. Tuned on the real corpus to
23
+ * balance recall against false positives on unrelated pairs. No API key, no
24
+ * network — pure stemming + concept map + char-trigram cosine.
25
+ */
26
+ export const SEMANTIC_THRESHOLD = BLIND_SPOT_SEMANTIC_THRESHOLD;
27
+ /** Likelihood band thresholds — HIGH-THRESHOLD-FIRST ternary. */
28
+ const HIGH_BAND = 0.6;
29
+ const MEDIUM_BAND = 0.3;
30
+ const MAX_RISKS = 3;
31
+ /**
32
+ * Find the active correction backing a blind spot — by trigger-keyword overlap
33
+ * against its rule. Used to anchor the recurrence/predict_precision weight and
34
+ * the `predicted` outcome to a concrete record.
35
+ */
36
+ function matchingCorrection(bs, corrections) {
37
+ const triggerSet = new Set(bs.trigger_keywords.map((k) => k.toLowerCase()));
38
+ let best;
39
+ for (const c of corrections) {
40
+ const ruleTokens = tokenize(`${c.rule} ${(c.tags ?? []).join(" ")}`);
41
+ const n = overlap(ruleTokens, triggerSet).length;
42
+ if (n >= 1 && (!best || n > best.n))
43
+ best = { rec: c, n };
44
+ }
45
+ return best?.rec;
46
+ }
47
+ export async function predictCorrection(input) {
48
+ const empty = {
49
+ likelihood: "low",
50
+ top_risks: [],
51
+ matched_blind_spots: [],
52
+ suggested_guard: null,
53
+ };
54
+ const plan = (input.plan ?? "").trim();
55
+ if (!plan)
56
+ return empty;
57
+ const slug = await resolveProject(input.project);
58
+ // Load profile; lazily recompute if missing (no spawned agent — synchronous).
59
+ let profile = readBlindSpots(slug);
60
+ if (!profile) {
61
+ try {
62
+ profile = recomputeBlindSpots(slug);
63
+ }
64
+ catch {
65
+ profile = null;
66
+ }
67
+ }
68
+ if (!profile || profile.blind_spots.length === 0)
69
+ return empty;
70
+ const corrections = readActiveCorrections(slug);
71
+ const planTokens = tokenize(plan);
72
+ if (planTokens.size === 0)
73
+ return empty;
74
+ const risks = [];
75
+ for (const bs of profile.blind_spots) {
76
+ // FLOOR keyword overlap + WIDEN local semantic similarity — the SINGLE shared
77
+ // matching grammar (helpers/blind-spots.ts). Keyword path is the floor; the
78
+ // semantic path strictly ADDS recall, with NO API key and NO network.
79
+ const m = matchesBlindSpot(plan, bs, MIN_OVERLAP, SEMANTIC_THRESHOLD);
80
+ if (!m.fired)
81
+ continue;
82
+ const corr = matchingCorrection(bs, corrections);
83
+ const recurrence = corr?.recurrence_count ?? 0;
84
+ const predictPrecision = corr?.predict_precision ?? 0;
85
+ // Keyword hits score on matched-token count; a semantic-only hit scores on its
86
+ // similarity (mapped onto a comparable scale, ~MIN_OVERLAP-equivalent) so a
87
+ // strong lexical match still outranks a borderline semantic one.
88
+ const baseMatch = m.via === "keyword" ? m.matched.length : MIN_OVERLAP * m.semanticScore;
89
+ // Weighted overlap: more matched triggers + P0 severity + observed recurrence
90
+ // + a track record of accurate predictions all raise the score.
91
+ const raw = baseMatch *
92
+ (bs.severity === "p0" ? 1.5 : 1) *
93
+ (1 + 0.2 * recurrence) *
94
+ (1 + 0.5 * predictPrecision);
95
+ risks.push({
96
+ tendency: bs.tendency,
97
+ score: raw,
98
+ matched: m.via === "keyword" ? m.matched : [`~semantic:${m.semanticScore.toFixed(2)}`],
99
+ correction_id: corr?.id,
100
+ severity: bs.severity,
101
+ });
102
+ }
103
+ if (risks.length === 0)
104
+ return empty;
105
+ risks.sort((a, b) => b.score - a.score);
106
+ // Normalize the strongest risk against the plan's token count so a longer
107
+ // plan with one match doesn't inflate. Cap each risk's normalized score at 1.
108
+ const denom = Math.max(planTokens.size, 3);
109
+ const normalize = (s) => Math.min(1, s / denom);
110
+ const topScore = normalize(risks[0].score);
111
+ // HIGH-THRESHOLD-FIRST ternary (Done-Definition #3).
112
+ const likelihood = topScore >= HIGH_BAND ? "high" : topScore >= MEDIUM_BAND ? "medium" : "low";
113
+ const topRisks = risks.slice(0, MAX_RISKS).map((r) => ({ ...r, score: Math.round(normalize(r.score) * 1000) / 1000 }));
114
+ // Instrument the predict-the-correction loop: each fired risk that anchors to
115
+ // a real correction records a `predicted` outcome. Best-effort — never throw.
116
+ const at = new Date().toISOString();
117
+ for (const r of topRisks) {
118
+ if (!r.correction_id)
119
+ continue;
120
+ try {
121
+ recordOutcome({ correction_id: r.correction_id, project: slug, kind: "predicted", at });
122
+ }
123
+ catch {
124
+ // instrumentation must never break prediction
125
+ }
126
+ }
127
+ const guard = topRisks.length > 0
128
+ ? `Likely correction: ${topRisks[0].tendency}. Reconcile before proceeding (matched: ${topRisks[0].matched.join(", ")}).`
129
+ : null;
130
+ return {
131
+ likelihood,
132
+ top_risks: topRisks,
133
+ matched_blind_spots: topRisks.map((r) => r.tendency),
134
+ suggested_guard: guard,
135
+ };
136
+ }
137
+ //# sourceMappingURL=predict-correction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predict-correction.js","sourceRoot":"","sources":["../../src/tools-logic/predict-correction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtF,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAyB,MAAM,2BAA2B,CAAC;AACxG,OAAO,EAAE,gBAAgB,EAAE,6BAA6B,EAAkB,MAAM,2BAA2B,CAAC;AA+B5G,2FAA2F;AAC3F,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,6BAA6B,CAAC;AAChE,iEAAiE;AACjE,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,MAAM,SAAS,GAAG,CAAC,CAAC;AAEpB;;;;GAIG;AACH,SAAS,kBAAkB,CACzB,EAAa,EACb,WAA+B;IAE/B,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,gBAA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EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC;IAEvH,8EAA8E;IAC9E,8EAA8E;IAC9E,MAAM,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACpC,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACzB,IAAI,CAAC,CAAC,CAAC,aAAa;YAAE,SAAS;QAC/B,IAAI,CAAC;YACH,aAAa,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;QAC1F,CAAC;QAAC,MAAM,CAAC;YACP,8CAA8C;QAChD,CAAC;IACH,CAAC;IAED,MAAM,KAAK,GACT,QAAQ,CAAC,MAAM,GAAG,CAAC;QACjB,CAAC,CAAC,sBAAsB,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,2CAA2C,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;QACzH,CAAC,CAAC,IAAI,CAAC;IAEX,OAAO;QACL,UAAU;QACV,SAAS,EAAE,QAAQ;QACnB,mBAAmB,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;QACpD,eAAe,EAAE,KAAK;KACvB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * prior-builder.ts — the "push a calibrated prior EARLY" half of the Bridge (Wave 4).
3
+ *
4
+ * hook-ambient fires before the agent reasons. Instead of only surfacing a fact
5
+ * list pulled late, we push a correction-derived PRIOR above it: "this resembles
6
+ * a past correction — check before proceeding." Memory becoming understanding.
7
+ *
8
+ * Pure + exported so it is unit-testable WITHOUT spawning the CLI. The CLI passes
9
+ * in the prompt, the project's P0 corrections, and the awareness blind-spots.
10
+ *
11
+ * Overlap gate starts STRICT (>=2 content tokens) to avoid noise (Risk #8). The
12
+ * tokenizer/overlap grammar is REUSED from check-action.ts — do not fork it.
13
+ */
14
+ /** Minimal shape of a correction the prior-builder needs. */
15
+ export interface PriorCorrection {
16
+ id?: string;
17
+ rule: string;
18
+ severity?: string;
19
+ tags?: string[];
20
+ }
21
+ /**
22
+ * Build the early-prior lines for a prompt.
23
+ * Corrections fire a hard "resembles a past correction" instinct; blind-spots
24
+ * fire a softer "tends to" nudge. Corrections take precedence.
25
+ */
26
+ export declare function buildPriors(prompt: string, corrections: PriorCorrection[], blindSpots: string[]): string[];
27
+ //# sourceMappingURL=prior-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prior-builder.d.ts","sourceRoot":"","sources":["../../src/tools-logic/prior-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,6DAA6D;AAC7D,MAAM,WAAW,eAAe;IAC9B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAOD;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,eAAe,EAAE,EAC9B,UAAU,EAAE,MAAM,EAAE,GACnB,MAAM,EAAE,CAkCV"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * prior-builder.ts — the "push a calibrated prior EARLY" half of the Bridge (Wave 4).
3
+ *
4
+ * hook-ambient fires before the agent reasons. Instead of only surfacing a fact
5
+ * list pulled late, we push a correction-derived PRIOR above it: "this resembles
6
+ * a past correction — check before proceeding." Memory becoming understanding.
7
+ *
8
+ * Pure + exported so it is unit-testable WITHOUT spawning the CLI. The CLI passes
9
+ * in the prompt, the project's P0 corrections, and the awareness blind-spots.
10
+ *
11
+ * Overlap gate starts STRICT (>=2 content tokens) to avoid noise (Risk #8). The
12
+ * tokenizer/overlap grammar is REUSED from check-action.ts — do not fork it.
13
+ */
14
+ import { tokenize, overlap } from "./check-action.js";
15
+ /** Minimum content-token overlap for a correction prior to fire (strict). */
16
+ const MIN_OVERLAP = 2;
17
+ /** Max priors emitted (kept tiny — these sit above the fact list). */
18
+ const MAX_PRIORS = 2;
19
+ /**
20
+ * Build the early-prior lines for a prompt.
21
+ * Corrections fire a hard "resembles a past correction" instinct; blind-spots
22
+ * fire a softer "tends to" nudge. Corrections take precedence.
23
+ */
24
+ export function buildPriors(prompt, corrections, blindSpots) {
25
+ const out = [];
26
+ if (!prompt || !prompt.trim())
27
+ return out;
28
+ const promptTokens = tokenize(prompt);
29
+ if (promptTokens.size === 0)
30
+ return out;
31
+ // 1. Correction priors (authoritative ground truth — strongest signal).
32
+ for (const c of corrections ?? []) {
33
+ if (out.length >= MAX_PRIORS)
34
+ break;
35
+ if (!c || !c.rule)
36
+ continue;
37
+ const ruleTokens = tokenize(`${c.rule} ${(c.tags ?? []).join(" ")}`);
38
+ const matched = overlap(promptTokens, ruleTokens);
39
+ if (matched.length >= MIN_OVERLAP) {
40
+ out.push(`⚠ [AgentRecall instinct] Resembles a past correction — ${c.rule.trim()}. Check before proceeding.`);
41
+ }
42
+ }
43
+ // 2. Blind-spot priors (softer — derived tendency, not a hard rule).
44
+ for (const bs of blindSpots ?? []) {
45
+ if (out.length >= MAX_PRIORS)
46
+ break;
47
+ if (!bs || !bs.trim())
48
+ continue;
49
+ const bsTokens = tokenize(bs);
50
+ const matched = overlap(promptTokens, bsTokens);
51
+ if (matched.length >= MIN_OVERLAP) {
52
+ out.push(`⚠ [AgentRecall] Watch a known tendency — ${bs.trim()}.`);
53
+ }
54
+ }
55
+ return out.slice(0, MAX_PRIORS);
56
+ }
57
+ //# sourceMappingURL=prior-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prior-buil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AC;QAClC,IAAI,GAAG,CAAC,MAAM,IAAI,UAAU;YAAE,MAAM;QACpC,IAAI,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE;YAAE,SAAS;QAChC,MAAM,QAAQ,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC9B,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAChD,IAAI,OAAO,CAAC,MAAM,IAAI,WAAW,EAAE,CAAC;YAClC,GAAG,CAAC,IAAI,CACN,4CAA4C,EAAE,CAAC,IAAI,EAAE,GAAG,CACzD,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,116 @@
1
+ /**
2
+ * recognition.ts — Loop 4 north-star: REAL-TIME RECOGNITION at session start.
3
+ *
4
+ * When a session opens, the agent must instantly know FOUR things from LOCAL
5
+ * data only — zero network, no Supabase, no LLM on the hot path, deterministic:
6
+ *
7
+ * 1. WHO — identity / role (from palace/identity.ts + owner)
8
+ * 2. CAN_DO — capabilities (palace/skills + capability-bearing corrections)
9
+ * 3. PROJECT — project + progress (status board + journal + palace state)
10
+ * 4. PERSON — "what kind of person" = blind-spots profile rendered as
11
+ * tendencies-to-watch, WITH an explicit low-confidence caveat
12
+ * (Loop 3 measured this profile at 0/13 predictive — surface,
13
+ * never over-claim).
14
+ *
15
+ * This module ASSEMBLES existing stores — it does NOT rebuild them. Every read
16
+ * is a pure, synchronous filesystem read of already-derived artifacts. The
17
+ * payload is deterministically ordered so the same on-disk state yields a
18
+ * byte-identical JSON across repeated runs (no timestamps, no Date.now in the
19
+ * output — those would break determinism and aren't part of "recognition").
20
+ *
21
+ * Honesty law: WHO is `'unknown'` when no identity card exists. We NEVER infer
22
+ * or fabricate a persona. CAN_DO and PERSON are honestly empty when nothing is
23
+ * known.
24
+ */
25
+ /** Field 1 — WHO is in front of the agent. `name` is `'unknown'` when no identity card exists. */
26
+ export interface RecognitionWho {
27
+ /** Identity name / project label, or the literal string `'unknown'`. */
28
+ name: string;
29
+ /** One-line role / intention from the identity card, or `null`. NEVER fabricated. */
30
+ role: string | null;
31
+ /** Project owner (filesystem source path or owner marker), or `null`. */
32
+ owner: string | null;
33
+ /** True when no identity.md (or only a template stub) exists — `name` is `'unknown'`. */
34
+ unknown: boolean;
35
+ }
36
+ /** Field 2 — WHAT THEY CAN DO. Honestly empty when nothing is known. */
37
+ export interface RecognitionCapabilities {
38
+ /** Declared skills (procedural memory), deterministically ordered by slug. */
39
+ skills: Array<{
40
+ slug: string;
41
+ name: string;
42
+ topic: string;
43
+ triggers: string[];
44
+ }>;
45
+ /**
46
+ * Capability / permission signals surfaced from corrections — rules whose text
47
+ * reads as a standing tool/permission constraint (e.g. "never push without
48
+ * approval"). Deterministically ordered by severity then id.
49
+ */
50
+ permissions: Array<{
51
+ id: string;
52
+ rule: string;
53
+ severity: "p0" | "p1";
54
+ }>;
55
+ }
56
+ /** Field 3 — PROJECT + PROGRESS. A one-glance "what this is and where it stands". */
57
+ export interface RecognitionProject {
58
+ slug: string;
59
+ /** Latest journal date (YYYY-MM-DD), or `null` when no journal exists. */
60
+ last_journal_date: string | null;
61
+ /** Coarse status board bucket derived from journal freshness. */
62
+ status: "needs-you" | "backlog" | "stale" | "empty";
63
+ /** Latest `## Next` trajectory line, trimmed, or `null`. */
64
+ trajectory: string | null;
65
+ /** Active palace rooms (top by salience), deterministically ordered. */
66
+ rooms: Array<{
67
+ name: string;
68
+ salience: number;
69
+ stale: boolean;
70
+ }>;
71
+ }
72
+ /**
73
+ * Field 4 — WHAT KIND OF PERSON. The blind-spots profile rendered as tendencies
74
+ * to watch. ALWAYS carries `caveat` — the profile measured 0/13 predictive on
75
+ * real data (Loop 3), so recognition surfaces it but must NOT over-claim it.
76
+ */
77
+ export interface RecognitionPerson {
78
+ /** Tendencies to watch, deterministically ordered by severity then evidence. */
79
+ tendencies: Array<{
80
+ tendency: string;
81
+ severity: "p0" | "p1";
82
+ evidence_count: number;
83
+ }>;
84
+ /** Mandatory low-confidence caveat. Present whether or not tendencies is empty. */
85
+ caveat: string;
86
+ }
87
+ export interface RecognitionPayload {
88
+ who: RecognitionWho;
89
+ can_do: RecognitionCapabilities;
90
+ project: RecognitionProject;
91
+ person: RecognitionPerson;
92
+ }
93
+ export interface BuildRecognitionOptions {
94
+ /** Cap on skills surfaced (default 8). */
95
+ maxSkills?: number;
96
+ /** Cap on capability/permission corrections surfaced (default 5). */
97
+ maxPermissions?: number;
98
+ /** Cap on rooms surfaced (default 3). */
99
+ maxRooms?: number;
100
+ /** Cap on person tendencies surfaced (default 3). */
101
+ maxTendencies?: number;
102
+ }
103
+ /**
104
+ * The mandatory low-confidence caveat for the person profile. Loop 3's
105
+ * leave-one-out eval measured the blind-spots profile at 0/13 predictive on real
106
+ * corrections, so it is surfaced for orientation only — never as validated truth.
107
+ */
108
+ export declare const PERSON_LOW_CONFIDENCE_CAVEAT = "low-confidence: derived tendencies, measured 0/13 predictive on real data (Loop 3) \u2014 orientation only, not validated.";
109
+ /**
110
+ * Assemble the real-time recognition payload for a project from LOCAL stores
111
+ * only. Synchronous, deterministic, zero-network. Caller must have already
112
+ * resolved `project` to a concrete slug (this function does not auto-detect, so
113
+ * it never shells out to git — keeping the hot path pure and fast).
114
+ */
115
+ export declare function buildRecognition(project: string, opts?: BuildRecognitionOptions): RecognitionPayload;
116
+ //# sourceMappingURL=recognition-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recognition-builder.d.ts","sourceRoot":"","sources":["../../src/tools-logic/recognition-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAeH,kGAAkG;AAClG,MAAM,WAAW,cAAc;IAC7B,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,qFAAqF;IACrF,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,y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