agent-recall-core 3.4.31 → 3.4.36
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.
- package/README.md +121 -441
- package/dist/digest/store.d.ts.map +1 -1
- package/dist/digest/store.js +4 -3
- package/dist/digest/store.js.map +1 -1
- package/dist/display/board-render.d.ts +61 -0
- package/dist/display/board-render.d.ts.map +1 -0
- package/dist/display/board-render.js +223 -0
- package/dist/display/board-render.js.map +1 -0
- package/dist/helpers/alignment-patterns.d.ts +10 -0
- package/dist/helpers/alignment-patterns.d.ts.map +1 -1
- package/dist/helpers/alignment-patterns.js +5 -1
- package/dist/helpers/alignment-patterns.js.map +1 -1
- package/dist/helpers/blind-spots.d.ts +86 -0
- package/dist/helpers/blind-spots.d.ts.map +1 -0
- package/dist/helpers/blind-spots.js +205 -0
- package/dist/helpers/blind-spots.js.map +1 -0
- package/dist/helpers/conflict-scan.d.ts +10 -0
- package/dist/helpers/conflict-scan.d.ts.map +1 -1
- package/dist/helpers/conflict-scan.js +3 -3
- package/dist/helpers/conflict-scan.js.map +1 -1
- package/dist/helpers/semantic-match.d.ts +82 -0
- package/dist/helpers/semantic-match.d.ts.map +1 -0
- package/dist/helpers/semantic-match.js +229 -0
- package/dist/helpers/semantic-match.js.map +1 -0
- package/dist/index.d.ts +57 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +60 -14
- package/dist/index.js.map +1 -1
- package/dist/palace/awareness.d.ts +30 -0
- package/dist/palace/awareness.d.ts.map +1 -1
- package/dist/palace/awareness.js +65 -2
- package/dist/palace/awareness.js.map +1 -1
- package/dist/palace/consolidate.d.ts.map +1 -1
- package/dist/palace/consolidate.js +17 -0
- package/dist/palace/consolidate.js.map +1 -1
- package/dist/palace/decay-pass.d.ts +46 -0
- package/dist/palace/decay-pass.d.ts.map +1 -0
- package/dist/palace/decay-pass.js +87 -0
- package/dist/palace/decay-pass.js.map +1 -0
- package/dist/palace/insights-index.d.ts.map +1 -1
- package/dist/palace/insights-index.js +4 -2
- package/dist/palace/insights-index.js.map +1 -1
- package/dist/palace/skills.d.ts +41 -2
- package/dist/palace/skills.d.ts.map +1 -1
- package/dist/palace/skills.js +106 -4
- package/dist/palace/skills.js.map +1 -1
- package/dist/prompts/consolidation-prompt.d.ts +25 -0
- package/dist/prompts/consolidation-prompt.d.ts.map +1 -0
- package/dist/prompts/consolidation-prompt.js +91 -0
- package/dist/prompts/consolidation-prompt.js.map +1 -0
- package/dist/storage/ab-experiment.d.ts +184 -0
- package/dist/storage/ab-experiment.d.ts.map +1 -0
- package/dist/storage/ab-experiment.js +294 -0
- package/dist/storage/ab-experiment.js.map +1 -0
- package/dist/storage/archive-prune.d.ts +56 -0
- package/dist/storage/archive-prune.d.ts.map +1 -0
- package/dist/storage/archive-prune.js +118 -0
- package/dist/storage/archive-prune.js.map +1 -0
- package/dist/storage/archive-write.d.ts +38 -0
- package/dist/storage/archive-write.d.ts.map +1 -0
- package/dist/storage/archive-write.js +98 -0
- package/dist/storage/archive-write.js.map +1 -0
- package/dist/storage/blind-spots-store.d.ts +30 -0
- package/dist/storage/blind-spots-store.d.ts.map +1 -0
- package/dist/storage/blind-spots-store.js +91 -0
- package/dist/storage/blind-spots-store.js.map +1 -0
- package/dist/storage/capture-router.d.ts +60 -0
- package/dist/storage/capture-router.d.ts.map +1 -0
- package/dist/storage/capture-router.js +133 -0
- package/dist/storage/capture-router.js.map +1 -0
- package/dist/storage/classification.d.ts +36 -0
- package/dist/storage/classification.d.ts.map +1 -0
- package/dist/storage/classification.js +78 -0
- package/dist/storage/classification.js.map +1 -0
- package/dist/storage/consolidation-queue.d.ts +39 -0
- package/dist/storage/consolidation-queue.d.ts.map +1 -0
- package/dist/storage/consolidation-queue.js +120 -0
- package/dist/storage/consolidation-queue.js.map +1 -0
- package/dist/storage/content-guard.d.ts +74 -0
- package/dist/storage/content-guard.d.ts.map +1 -0
- package/dist/storage/content-guard.js +179 -0
- package/dist/storage/content-guard.js.map +1 -0
- package/dist/storage/corrections.d.ts +329 -22
- package/dist/storage/corrections.d.ts.map +1 -1
- package/dist/storage/corrections.js +788 -58
- package/dist/storage/corrections.js.map +1 -1
- package/dist/storage/durable-intent.d.ts +49 -0
- package/dist/storage/durable-intent.d.ts.map +1 -0
- package/dist/storage/durable-intent.js +124 -0
- package/dist/storage/durable-intent.js.map +1 -0
- package/dist/storage/filelock.d.ts +6 -0
- package/dist/storage/filelock.d.ts.map +1 -1
- package/dist/storage/filelock.js +6 -1
- package/dist/storage/filelock.js.map +1 -1
- package/dist/storage/memory-protocol.d.ts +19 -0
- package/dist/storage/memory-protocol.d.ts.map +1 -0
- package/dist/storage/memory-protocol.js +101 -0
- package/dist/storage/memory-protocol.js.map +1 -0
- package/dist/storage/paths.d.ts +23 -0
- package/dist/storage/paths.d.ts.map +1 -1
- package/dist/storage/paths.js +39 -0
- package/dist/storage/paths.js.map +1 -1
- package/dist/storage/retention.d.ts +23 -0
- package/dist/storage/retention.d.ts.map +1 -0
- package/dist/storage/retention.js +48 -0
- package/dist/storage/retention.js.map +1 -0
- package/dist/storage/session.d.ts +2 -2
- package/dist/storage/session.d.ts.map +1 -1
- package/dist/storage/session.js +11 -1
- package/dist/storage/session.js.map +1 -1
- package/dist/supabase/config.d.ts +26 -0
- package/dist/supabase/config.d.ts.map +1 -1
- package/dist/supabase/config.js +11 -0
- package/dist/supabase/config.js.map +1 -1
- package/dist/supabase/recall-backend.d.ts +1 -0
- package/dist/supabase/recall-backend.d.ts.map +1 -1
- package/dist/supabase/recall-backend.js +13 -13
- package/dist/supabase/recall-backend.js.map +1 -1
- package/dist/supabase/sync.d.ts +1 -1
- package/dist/supabase/sync.d.ts.map +1 -1
- package/dist/supabase/sync.js +85 -3
- package/dist/supabase/sync.js.map +1 -1
- package/dist/tools-logic/bootstrap.d.ts +15 -0
- package/dist/tools-logic/bootstrap.d.ts.map +1 -1
- package/dist/tools-logic/bootstrap.js +238 -47
- package/dist/tools-logic/bootstrap.js.map +1 -1
- package/dist/tools-logic/brief.d.ts +84 -0
- package/dist/tools-logic/brief.d.ts.map +1 -0
- package/dist/tools-logic/brief.js +193 -0
- package/dist/tools-logic/brief.js.map +1 -0
- package/dist/tools-logic/check-action.d.ts +9 -0
- package/dist/tools-logic/check-action.d.ts.map +1 -1
- package/dist/tools-logic/check-action.js +61 -3
- package/dist/tools-logic/check-action.js.map +1 -1
- package/dist/tools-logic/check.d.ts +7 -0
- package/dist/tools-logic/check.d.ts.map +1 -1
- package/dist/tools-logic/check.js +24 -2
- package/dist/tools-logic/check.js.map +1 -1
- package/dist/tools-logic/confidence.d.ts +50 -0
- package/dist/tools-logic/confidence.d.ts.map +1 -0
- package/dist/tools-logic/confidence.js +70 -0
- package/dist/tools-logic/confidence.js.map +1 -0
- package/dist/tools-logic/drill-down.d.ts +37 -0
- package/dist/tools-logic/drill-down.d.ts.map +1 -0
- package/dist/tools-logic/drill-down.js +63 -0
- package/dist/tools-logic/drill-down.js.map +1 -0
- package/dist/tools-logic/export-corrections.d.ts +63 -0
- package/dist/tools-logic/export-corrections.d.ts.map +1 -0
- package/dist/tools-logic/export-corrections.js +124 -0
- package/dist/tools-logic/export-corrections.js.map +1 -0
- package/dist/tools-logic/journal-capture.d.ts.map +1 -1
- package/dist/tools-logic/journal-capture.js +4 -1
- package/dist/tools-logic/journal-capture.js.map +1 -1
- package/dist/tools-logic/journal-write.d.ts.map +1 -1
- package/dist/tools-logic/journal-write.js +3 -2
- package/dist/tools-logic/journal-write.js.map +1 -1
- package/dist/tools-logic/local-archive-backend.d.ts +33 -0
- package/dist/tools-logic/local-archive-backend.d.ts.map +1 -0
- package/dist/tools-logic/local-archive-backend.js +124 -0
- package/dist/tools-logic/local-archive-backend.js.map +1 -0
- package/dist/tools-logic/memory-backend.d.ts +74 -0
- package/dist/tools-logic/memory-backend.d.ts.map +1 -0
- package/dist/tools-logic/memory-backend.js +172 -0
- package/dist/tools-logic/memory-backend.js.map +1 -0
- package/dist/tools-logic/memory-query.d.ts +10 -3
- package/dist/tools-logic/memory-query.d.ts.map +1 -1
- package/dist/tools-logic/memory-query.js +31 -7
- package/dist/tools-logic/memory-query.js.map +1 -1
- package/dist/tools-logic/mirror-builder.d.ts +115 -0
- package/dist/tools-logic/mirror-builder.d.ts.map +1 -0
- package/dist/tools-logic/mirror-builder.js +348 -0
- package/dist/tools-logic/mirror-builder.js.map +1 -0
- package/dist/tools-logic/palace-write.d.ts.map +1 -1
- package/dist/tools-logic/palace-write.js +3 -2
- package/dist/tools-logic/palace-write.js.map +1 -1
- package/dist/tools-logic/pipeline-close.d.ts.map +1 -1
- package/dist/tools-logic/pipeline-close.js +2 -1
- package/dist/tools-logic/pipeline-close.js.map +1 -1
- package/dist/tools-logic/pipeline-open.d.ts.map +1 -1
- package/dist/tools-logic/pipeline-open.js +2 -1
- package/dist/tools-logic/pipeline-open.js.map +1 -1
- package/dist/tools-logic/predict-correction.d.ts +47 -0
- package/dist/tools-logic/predict-correction.d.ts.map +1 -0
- package/dist/tools-logic/predict-correction.js +137 -0
- package/dist/tools-logic/predict-correction.js.map +1 -0
- package/dist/tools-logic/prior-builder.d.ts +27 -0
- package/dist/tools-logic/prior-builder.d.ts.map +1 -0
- package/dist/tools-logic/prior-builder.js +90 -0
- package/dist/tools-logic/prior-builder.js.map +1 -0
- package/dist/tools-logic/recognition-builder.d.ts +122 -0
- package/dist/tools-logic/recognition-builder.d.ts.map +1 -0
- package/dist/tools-logic/recognition-builder.js +289 -0
- package/dist/tools-logic/recognition-builder.js.map +1 -0
- package/dist/tools-logic/safety-consolidation.d.ts +104 -0
- package/dist/tools-logic/safety-consolidation.d.ts.map +1 -0
- package/dist/tools-logic/safety-consolidation.js +256 -0
- package/dist/tools-logic/safety-consolidation.js.map +1 -0
- package/dist/tools-logic/session-end-reflect.d.ts +18 -0
- package/dist/tools-logic/session-end-reflect.d.ts.map +1 -1
- package/dist/tools-logic/session-end-reflect.js +69 -30
- package/dist/tools-logic/session-end-reflect.js.map +1 -1
- package/dist/tools-logic/session-end.d.ts +18 -0
- package/dist/tools-logic/session-end.d.ts.map +1 -1
- package/dist/tools-logic/session-end.js +189 -34
- package/dist/tools-logic/session-end.js.map +1 -1
- package/dist/tools-logic/session-start-lite.d.ts +2 -0
- package/dist/tools-logic/session-start-lite.d.ts.map +1 -1
- package/dist/tools-logic/session-start-lite.js +11 -2
- package/dist/tools-logic/session-start-lite.js.map +1 -1
- package/dist/tools-logic/session-start.d.ts +81 -2
- package/dist/tools-logic/session-start.d.ts.map +1 -1
- package/dist/tools-logic/session-start.js +357 -40
- package/dist/tools-logic/session-start.js.map +1 -1
- package/dist/tools-logic/skill-propose.d.ts +27 -0
- package/dist/tools-logic/skill-propose.d.ts.map +1 -0
- package/dist/tools-logic/skill-propose.js +66 -0
- package/dist/tools-logic/skill-propose.js.map +1 -0
- package/dist/tools-logic/skill-recall.d.ts +5 -0
- package/dist/tools-logic/skill-recall.d.ts.map +1 -1
- package/dist/tools-logic/skill-recall.js +14 -1
- package/dist/tools-logic/skill-recall.js.map +1 -1
- package/dist/tools-logic/smart-recall.d.ts +17 -0
- package/dist/tools-logic/smart-recall.d.ts.map +1 -1
- package/dist/tools-logic/smart-recall.js +51 -16
- package/dist/tools-logic/smart-recall.js.map +1 -1
- package/dist/tools-logic/smart-remember.js +8 -9
- package/dist/tools-logic/smart-remember.js.map +1 -1
- package/dist/tools-logic/store-doctor.d.ts +71 -0
- package/dist/tools-logic/store-doctor.d.ts.map +1 -0
- package/dist/tools-logic/store-doctor.js +387 -0
- package/dist/tools-logic/store-doctor.js.map +1 -0
- package/dist/tools-logic/store-repair.d.ts +64 -0
- package/dist/tools-logic/store-repair.d.ts.map +1 -0
- package/dist/tools-logic/store-repair.js +243 -0
- package/dist/tools-logic/store-repair.js.map +1 -0
- package/dist/tools-logic/supersession.d.ts +34 -0
- package/dist/tools-logic/supersession.d.ts.map +1 -0
- package/dist/tools-logic/supersession.js +103 -0
- package/dist/tools-logic/supersession.js.map +1 -0
- package/dist/types.d.ts +7 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -1
- package/dist/vector/embedding.d.ts +8 -0
- package/dist/vector/embedding.d.ts.map +1 -1
- package/dist/vector/embedding.js +9 -1
- package/dist/vector/embedding.js.map +1 -1
- package/dist/vector/local-vector-backend.d.ts.map +1 -1
- package/dist/vector/local-vector-backend.js +14 -17
- package/dist/vector/local-vector-backend.js.map +1 -1
- package/package.json +2 -2
- package/dist/relevance/injector.d.ts +0 -51
- package/dist/relevance/injector.d.ts.map +0 -1
- package/dist/relevance/injector.js +0 -121
- package/dist/relevance/injector.js.map +0 -1
- package/dist/relevance/precision.d.ts +0 -109
- package/dist/relevance/precision.d.ts.map +0 -1
- package/dist/relevance/precision.js +0 -279
- package/dist/relevance/precision.js.map +0 -1
- package/dist/relevance/promoter.d.ts +0 -60
- package/dist/relevance/promoter.d.ts.map +0 -1
- package/dist/relevance/promoter.js +0 -336
- package/dist/relevance/promoter.js.map +0 -1
- package/dist/relevance/stager.d.ts +0 -61
- package/dist/relevance/stager.d.ts.map +0 -1
- package/dist/relevance/stager.js +0 -251
- package/dist/relevance/stager.js.map +0 -1
- package/dist/relevance/surfacer.d.ts +0 -34
- package/dist/relevance/surfacer.d.ts.map +0 -1
- package/dist/relevance/surfacer.js +0 -333
- package/dist/relevance/surfacer.js.map +0 -1
|
@@ -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,kBA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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;AAiCD;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,eAAe,EAAE,EAC9B,UAAU,EAAE,MAAM,EAAE,GACnB,MAAM,EAAE,CA0CV"}
|
|
@@ -0,0 +1,90 @@
|
|
|
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
|
+
* Domain-noise tokens for blind-spot matching (FIX 2).
|
|
21
|
+
*
|
|
22
|
+
* These are high-frequency dev-context words that survive the generic English
|
|
23
|
+
* stop-word filter but are not discriminating enough to count as signal for a
|
|
24
|
+
* blind-spot prior. A blind spot like "… blocked on competitor API keys" should
|
|
25
|
+
* NOT fire just because a prompt asks "check the API keys configuration" — the
|
|
26
|
+
* co-occurrence of `api`+`keys` is too common in any engineering session.
|
|
27
|
+
*
|
|
28
|
+
* CORRECTION priors are NOT filtered through this set — corrections are ground-
|
|
29
|
+
* truth rules with specific rule text (longer, more distinctive). Only blind
|
|
30
|
+
* spots (derived tendency summaries) use the extended filter.
|
|
31
|
+
*
|
|
32
|
+
* Rationale for each token:
|
|
33
|
+
* api, keys, key — appear in nearly every auth/integration prompt
|
|
34
|
+
* product, projects, project — appear whenever discussing roadmap or work items
|
|
35
|
+
* build, test, run, code, file, use, check — ubiquitous dev verbs/nouns
|
|
36
|
+
* data, info, user, users — too generic to discriminate any tendency
|
|
37
|
+
*/
|
|
38
|
+
const BLIND_SPOT_DOMAIN_NOISE = new Set([
|
|
39
|
+
"api", "key", "keys",
|
|
40
|
+
"product", "project", "projects",
|
|
41
|
+
"build", "test", "run", "code", "file", "files", "use", "check",
|
|
42
|
+
"data", "info", "user", "users",
|
|
43
|
+
]);
|
|
44
|
+
/**
|
|
45
|
+
* Build the early-prior lines for a prompt.
|
|
46
|
+
* Corrections fire a hard "resembles a past correction" instinct; blind-spots
|
|
47
|
+
* fire a softer "tends to" nudge. Corrections take precedence.
|
|
48
|
+
*/
|
|
49
|
+
export function buildPriors(prompt, corrections, blindSpots) {
|
|
50
|
+
const out = [];
|
|
51
|
+
if (!prompt || !prompt.trim())
|
|
52
|
+
return out;
|
|
53
|
+
const promptTokens = tokenize(prompt);
|
|
54
|
+
if (promptTokens.size === 0)
|
|
55
|
+
return out;
|
|
56
|
+
// 1. Correction priors (authoritative ground truth — strongest signal).
|
|
57
|
+
for (const c of corrections ?? []) {
|
|
58
|
+
if (out.length >= MAX_PRIORS)
|
|
59
|
+
break;
|
|
60
|
+
if (!c || !c.rule)
|
|
61
|
+
continue;
|
|
62
|
+
const ruleTokens = tokenize(`${c.rule} ${(c.tags ?? []).join(" ")}`);
|
|
63
|
+
const matched = overlap(promptTokens, ruleTokens);
|
|
64
|
+
if (matched.length >= MIN_OVERLAP) {
|
|
65
|
+
out.push(`⚠ [AgentRecall instinct] Resembles a past correction — ${c.rule.trim()}. Check before proceeding.`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// 2. Blind-spot priors (softer — derived tendency, not a hard rule).
|
|
69
|
+
// Domain-noise filter: blind spots are broad tendency summaries, so their
|
|
70
|
+
// token set often includes generic dev terms (api, keys, projects...) that
|
|
71
|
+
// co-occur in unrelated prompts. Strip BLIND_SPOT_DOMAIN_NOISE from both
|
|
72
|
+
// sides before counting overlap — the MIN_OVERLAP=2 gate must be met by
|
|
73
|
+
// genuinely discriminating content tokens only.
|
|
74
|
+
for (const bs of blindSpots ?? []) {
|
|
75
|
+
if (out.length >= MAX_PRIORS)
|
|
76
|
+
break;
|
|
77
|
+
if (!bs || !bs.trim())
|
|
78
|
+
continue;
|
|
79
|
+
const bsTokens = tokenize(bs);
|
|
80
|
+
// Build noise-filtered token sets for the overlap test
|
|
81
|
+
const filteredBsTokens = new Set([...bsTokens].filter((t) => !BLIND_SPOT_DOMAIN_NOISE.has(t)));
|
|
82
|
+
const filteredPromptTokens = new Set([...promptTokens].filter((t) => !BLIND_SPOT_DOMAIN_NOISE.has(t)));
|
|
83
|
+
const matched = overlap(filteredPromptTokens, filteredBsTokens);
|
|
84
|
+
if (matched.length >= MIN_OVERLAP) {
|
|
85
|
+
out.push(`⚠ [AgentRecall] Watch a known tendency — ${bs.trim()}.`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return out.slice(0, MAX_PRIORS);
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=prior-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prior-builder.js","sourceRoot":"","sources":["../../src/tools-logic/prior-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAUtD,6EAA6E;AAC7E,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,sEAAsE;AACtE,MAAM,UAAU,GAAG,CAAC,CAAC;AAErB;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,uBAAuB,GAAG,IAAI,GAAG,CAAC;IACtC,KAAK,EAAE,KAAK,EAAE,MAAM;IACpB,SAAS,EAAE,SAAS,EAAE,UAAU;IAChC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,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AI,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE;YAAE,SAAS;QAChC,MAAM,QAAQ,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC9B,uDAAuD;QACvD,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/F,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACvG,MAAM,OAAO,GAAG,OAAO,CAAC,oBAAoB,EAAE,gBAAgB,CAAC,CAAC;QAChE,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,122 @@
|
|
|
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
|
+
/**
|
|
92
|
+
* ABSENT-WHEN-EMPTY: buildRecognition always populates this, but
|
|
93
|
+
* session_start DROPS the field when `tendencies` is empty — the caveat
|
|
94
|
+
* string alone carries no actionable content and wastes payload bytes.
|
|
95
|
+
* Consumers must treat a missing `person` as "no tendencies known".
|
|
96
|
+
*/
|
|
97
|
+
person?: RecognitionPerson;
|
|
98
|
+
}
|
|
99
|
+
export interface BuildRecognitionOptions {
|
|
100
|
+
/** Cap on skills surfaced (default 8). */
|
|
101
|
+
maxSkills?: number;
|
|
102
|
+
/** Cap on capability/permission corrections surfaced (default 5). */
|
|
103
|
+
maxPermissions?: number;
|
|
104
|
+
/** Cap on rooms surfaced (default 3). */
|
|
105
|
+
maxRooms?: number;
|
|
106
|
+
/** Cap on person tendencies surfaced (default 3). */
|
|
107
|
+
maxTendencies?: number;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* The mandatory low-confidence caveat for the person profile. Loop 3's
|
|
111
|
+
* leave-one-out eval measured the blind-spots profile at 0/13 predictive on real
|
|
112
|
+
* corrections, so it is surfaced for orientation only — never as validated truth.
|
|
113
|
+
*/
|
|
114
|
+
export declare const PERSON_LOW_CONFIDENCE_CAVEAT = "low-confidence: 0/13 predictive (Loop 3) \u2014 not validated, orientation only.";
|
|
115
|
+
/**
|
|
116
|
+
* Assemble the real-time recognition payload for a project from LOCAL stores
|
|
117
|
+
* only. Synchronous, deterministic, zero-network. Caller must have already
|
|
118
|
+
* resolved `project` to a concrete slug (this function does not auto-detect, so
|
|
119
|
+
* it never shells out to git — keeping the hot path pure and fast).
|
|
120
|
+
*/
|
|
121
|
+
export declare function buildRecognition(project: string, opts?: BuildRecognitionOptions): RecognitionPayload;
|
|
122
|
+
//# 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,kGAA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