@jmtrin/kevin-core 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/dist/Archiver.d.ts +42 -0
  2. package/dist/Archiver.js +83 -0
  3. package/dist/ArtifactWriter.d.ts +93 -0
  4. package/dist/ArtifactWriter.js +291 -0
  5. package/dist/CausalChain.d.ts +22 -0
  6. package/dist/CausalChain.js +197 -0
  7. package/dist/ChatBridge.d.ts +41 -0
  8. package/dist/ChatBridge.js +103 -0
  9. package/dist/ConflictDetector.d.ts +35 -0
  10. package/dist/ConflictDetector.js +260 -0
  11. package/dist/ContextInjector.d.ts +222 -0
  12. package/dist/ContextInjector.js +533 -0
  13. package/dist/ConventionMiner.d.ts +35 -0
  14. package/dist/ConventionMiner.js +242 -0
  15. package/dist/Curator.d.ts +118 -0
  16. package/dist/Curator.js +326 -0
  17. package/dist/DashboardHtml.d.ts +5 -0
  18. package/dist/DashboardHtml.js +180 -0
  19. package/dist/Feedback.d.ts +67 -0
  20. package/dist/Feedback.js +120 -0
  21. package/dist/HookLiveness.d.ts +88 -0
  22. package/dist/HookLiveness.js +322 -0
  23. package/dist/InjectionLedger.d.ts +98 -0
  24. package/dist/InjectionLedger.js +295 -0
  25. package/dist/LessonFixer.d.ts +44 -0
  26. package/dist/LessonFixer.js +45 -0
  27. package/dist/Materializer.d.ts +84 -0
  28. package/dist/Materializer.js +181 -0
  29. package/dist/MemoryService.d.ts +360 -0
  30. package/dist/MemoryService.js +1242 -0
  31. package/dist/Migrate.d.ts +24 -0
  32. package/dist/Migrate.js +285 -0
  33. package/dist/PatternMiner.d.ts +49 -0
  34. package/dist/PatternMiner.js +132 -0
  35. package/dist/QualityGate.d.ts +124 -0
  36. package/dist/QualityGate.js +119 -0
  37. package/dist/Reflector.d.ts +91 -0
  38. package/dist/Reflector.js +307 -0
  39. package/dist/RepoIdentity.d.ts +124 -0
  40. package/dist/RepoIdentity.js +300 -0
  41. package/dist/RepoTruth.d.ts +80 -0
  42. package/dist/RepoTruth.js +599 -0
  43. package/dist/Retrospective.d.ts +18 -0
  44. package/dist/Retrospective.js +216 -0
  45. package/dist/SharedLayer.d.ts +159 -0
  46. package/dist/SharedLayer.js +462 -0
  47. package/dist/Store.d.ts +29 -0
  48. package/dist/Store.js +50 -0
  49. package/dist/ToolCallObserver.d.ts +32 -0
  50. package/dist/ToolCallObserver.js +201 -0
  51. package/dist/TuiActions.d.ts +43 -0
  52. package/dist/TuiActions.js +181 -0
  53. package/dist/TuiSnapshots.d.ts +24 -0
  54. package/dist/TuiSnapshots.js +159 -0
  55. package/dist/capabilities.d.ts +6 -0
  56. package/dist/capabilities.js +1 -0
  57. package/dist/columns.d.ts +11 -0
  58. package/dist/columns.js +54 -0
  59. package/dist/confidence.d.ts +8 -0
  60. package/dist/confidence.js +34 -0
  61. package/dist/contract.d.ts +68 -0
  62. package/dist/contract.js +430 -0
  63. package/dist/diff.d.ts +8 -0
  64. package/dist/diff.js +182 -0
  65. package/dist/env.d.ts +5 -0
  66. package/dist/env.js +12 -0
  67. package/dist/escape.d.ts +39 -0
  68. package/dist/escape.js +60 -0
  69. package/dist/fingerprint.d.ts +27 -0
  70. package/dist/fingerprint.js +73 -0
  71. package/dist/host.d.ts +18 -0
  72. package/dist/host.js +7 -0
  73. package/dist/idle-pipeline.d.ts +9 -0
  74. package/dist/idle-pipeline.js +44 -0
  75. package/dist/index.d.ts +72 -0
  76. package/dist/index.js +109 -0
  77. package/dist/inferability.d.ts +32 -0
  78. package/dist/inferability.js +88 -0
  79. package/dist/kevin_approve.d.ts +34 -0
  80. package/dist/kevin_approve.js +52 -0
  81. package/dist/kevin_audit.d.ts +230 -0
  82. package/dist/kevin_audit.js +631 -0
  83. package/dist/kevin_bench.d.ts +11 -0
  84. package/dist/kevin_bench.js +83 -0
  85. package/dist/kevin_conflicts.d.ts +9 -0
  86. package/dist/kevin_conflicts.js +50 -0
  87. package/dist/kevin_contract.d.ts +8 -0
  88. package/dist/kevin_contract.js +59 -0
  89. package/dist/kevin_doctor.d.ts +63 -0
  90. package/dist/kevin_doctor.js +197 -0
  91. package/dist/kevin_facts.d.ts +42 -0
  92. package/dist/kevin_facts.js +36 -0
  93. package/dist/kevin_forget.d.ts +33 -0
  94. package/dist/kevin_forget.js +260 -0
  95. package/dist/kevin_native.d.ts +29 -0
  96. package/dist/kevin_native.js +79 -0
  97. package/dist/kevin_propose.d.ts +23 -0
  98. package/dist/kevin_propose.js +14 -0
  99. package/dist/kevin_publish.d.ts +38 -0
  100. package/dist/kevin_publish.js +18 -0
  101. package/dist/kevin_why.d.ts +23 -0
  102. package/dist/kevin_why.js +111 -0
  103. package/dist/memory-format.d.ts +20 -0
  104. package/dist/memory-format.js +59 -0
  105. package/dist/metrics.d.ts +97 -0
  106. package/dist/metrics.js +288 -0
  107. package/dist/migrations/001_initial.sql +92 -0
  108. package/dist/migrations/002_indexes.sql +14 -0
  109. package/dist/migrations/003_v02_signal.sql +58 -0
  110. package/dist/migrations/004_v03_knowledge.sql +138 -0
  111. package/dist/migrations/005_v04_signal.sql +57 -0
  112. package/dist/migrations/006_v05_glassbox.sql +118 -0
  113. package/dist/migrations/007_v06_pull.sql +145 -0
  114. package/dist/migrations/008_v07_truth.sql +124 -0
  115. package/dist/migrations/009_v08_team.sql +100 -0
  116. package/dist/migrations/010_v09_native.sql +78 -0
  117. package/dist/migrations/011_v10_proven.sql +69 -0
  118. package/dist/migrations/012_v11_drift.sql +24 -0
  119. package/dist/native.d.ts +23 -0
  120. package/dist/native.js +1 -0
  121. package/dist/okf-export.d.ts +3 -0
  122. package/dist/okf-export.js +134 -0
  123. package/dist/okf-import.d.ts +76 -0
  124. package/dist/okf-import.js +271 -0
  125. package/dist/okf.d.ts +107 -0
  126. package/dist/okf.js +303 -0
  127. package/dist/perf.d.ts +35 -0
  128. package/dist/perf.js +174 -0
  129. package/dist/query-tokenizer.d.ts +13 -0
  130. package/dist/query-tokenizer.js +133 -0
  131. package/dist/redact.d.ts +2 -0
  132. package/dist/redact.js +18 -0
  133. package/dist/replay-types.d.ts +69 -0
  134. package/dist/replay-types.js +156 -0
  135. package/dist/replay.d.ts +44 -0
  136. package/dist/replay.js +215 -0
  137. package/dist/sqlite-adapter.d.ts +12 -0
  138. package/dist/sqlite-adapter.js +78 -0
  139. package/dist/time-ms.d.ts +1 -0
  140. package/dist/time-ms.js +16 -0
  141. package/dist/tui-types.d.ts +59 -0
  142. package/dist/tui-types.js +4 -0
  143. package/dist/uuid.d.ts +1 -0
  144. package/dist/uuid.js +50 -0
  145. package/package.json +28 -0
@@ -0,0 +1,222 @@
1
+ import type { InjectionLedger } from "./InjectionLedger.js";
2
+ import type { MemoryService } from "./MemoryService.js";
3
+ import { type GateReason } from "./QualityGate.js";
4
+ import { type Metrics } from "./metrics.js";
5
+ export declare const QUALITY_GATE_SETTING = "quality_gate_enabled";
6
+ export declare const SNIPPET_INJECTION_SETTING = "lesson_snippet_injection";
7
+ /**
8
+ * v0.6.0 (K6-023 / plan §5.8) — the effective pre-prompt budget shared by
9
+ * `ContextInjector.prePromptCap()` and `kevin_audit`'s channels block
10
+ * (budget_tokens). Single source of truth for the K6-021 clamp:
11
+ * default 400 when the raw value is missing/non-numeric, clamped to
12
+ * [0, 4000]; 0 means "push off".
13
+ */
14
+ export declare function effectivePrePromptCap(raw: string | undefined): number;
15
+ export interface ChatMessage {
16
+ role: string;
17
+ content: string;
18
+ }
19
+ export interface SystemTransformInput {
20
+ sessionID?: string;
21
+ messages: ChatMessage[];
22
+ }
23
+ export interface SystemTransformOutput {
24
+ system: string[];
25
+ }
26
+ export interface CompactingInput {
27
+ sessionID: string;
28
+ messages: ChatMessage[];
29
+ }
30
+ export interface CompactingOutput {
31
+ context: string[];
32
+ }
33
+ export interface InjectionPlanItem {
34
+ id: string;
35
+ type: string;
36
+ decision: "admitted" | "blocked";
37
+ /** Gate reason when blocked; null for admitted items. */
38
+ reason?: GateReason;
39
+ /** Estimated tokens this memory would contribute to the block. */
40
+ tokens: number;
41
+ }
42
+ export interface InjectionPlan {
43
+ query: string;
44
+ tag: "context" | "memory";
45
+ cap: number;
46
+ would_inject: boolean;
47
+ /** Estimated tokens of the block that WOULD be produced (0 when
48
+ * nothing would be injected). */
49
+ total_tokens: number;
50
+ admitted: InjectionPlanItem[];
51
+ blocked: InjectionPlanItem[];
52
+ }
53
+ export declare class ContextInjector {
54
+ private memoryService;
55
+ private metrics;
56
+ private ledger;
57
+ private lastRecurrenceCount;
58
+ /** v0.4.0 (K4-016) — session that produced the last recurrence set. */
59
+ private lastRecurredSession;
60
+ /** v0.4.0 (K4-017) — per-session seen-set (plan §5.1 rule 3). */
61
+ private readonly seenBySession;
62
+ constructor(memoryService: MemoryService, metrics?: Metrics | null, ledger?: InjectionLedger | null);
63
+ /**
64
+ * v0.4.0 (K4-017) — reset the per-session seen-set when a session is
65
+ * created (plan §5.1 rule 3). Wired from the `session.created` event.
66
+ */
67
+ onSessionCreated(sessionId: string): void;
68
+ /**
69
+ * v0.3.0 (K3-020) — notify the injector that the negative feedback half
70
+ * fired N times in the last session.idle. The next system.transform or
71
+ * compacting hook will prepend a HITL suggestion block.
72
+ * v0.4.0 (K4-016) — the session id enables the concrete suggestion:
73
+ * the most-recurred fingerprint's pattern + its fix_args.
74
+ */
75
+ setRecurrences(count: number, sessionId?: string): void;
76
+ /**
77
+ * v0.4.0 (K4-016) — generate a CONCRETE HITL suggestion block when
78
+ * recurrences occurred (plan §5.5): names the most-recurred pattern,
79
+ * its exact recurrence count, observed fix_args and confidence. The
80
+ * AGENTS.md draft line derives from the lesson's `Suggestion:` text —
81
+ * never a canned string, and never the anonymous "the same error
82
+ * pattern" without naming the pattern and count.
83
+ *
84
+ * BUG-012 — emits AT MOST ONCE per session: calling it resets the
85
+ * pending recurrence signal, so whichever hook (system.transform or
86
+ * compacting) runs first in a session consumes the block. Documented
87
+ * behavior; wire index.ts to match.
88
+ */
89
+ generateSuggestion(): string;
90
+ /**
91
+ * v0.4.0 (K4-016) — the AGENTS.md draft line derives from the lesson's
92
+ * `Suggestion:` text (kept verbatim in the pattern's `Original:` block).
93
+ */
94
+ private agentsDraftLine;
95
+ /**
96
+ * v0.2.0 (K2-024): origin-aware ranking at injection time is delegated
97
+ * to `MemoryService.getRelevant()` (K2-023, D2-13). The injector does
98
+ * NOT re-rank on its own — it consumes the already-ranked slice and
99
+ * applies the conditional-budget guard for opt-out (`protect: false`)
100
+ * callers. Plan §B6.5: "apply the same multiplier as
101
+ * MemoryService.recall so reflector lessons outrank agent-saved notes
102
+ * at injection time" — satisfied transitively via the getRelevant call.
103
+ *
104
+ * v0.4.0 (K4-017): after retrieval, every memory is filtered through
105
+ * `QualityGate.canInject` (session seen-set + recurrence + strength),
106
+ * and each admitted memory is recorded in the `InjectionLedger`
107
+ * (plan §5.2 — one row per injected memory).
108
+ *
109
+ * v0.5.0 (K5-014 / plan §8.10) — the pipeline is decomposed into
110
+ * `fetchSlice` (ranked retrieval + budget overflow) + `evaluate`
111
+ * (pure gate verdicts) + this orchestrator, so the read-only `plan()`
112
+ * can mirror it without any side effect (D5-08).
113
+ */
114
+ private inject;
115
+ /**
116
+ * v0.5.0 (K5-014 / plan §8.10) — the ranked-retrieval stage shared by
117
+ * `inject` and `plan`. With `dry = true` it is a strict read:
118
+ *
119
+ * - the probe fetch never bumps (BUG-016), like the live path;
120
+ * - the overflow retry ALSO fetches with `bump: false` (the live path
121
+ * lets the retry fetch bump once — that is the only difference);
122
+ * - the no-retry bump is skipped.
123
+ *
124
+ * This is what lets `plan()` predict the EXACT slice the live path
125
+ * would inject without mutating a single relevance score.
126
+ */
127
+ private fetchSlice;
128
+ /**
129
+ * v0.5.0 (K5-014 / plan §8.10, D5-08) — PUBLIC read-only prediction of
130
+ * what `inject` WOULD do for a query: same retrieval, same gate, zero
131
+ * side effects. Never moves a counter, never writes the seen-set, never
132
+ * bumps relevance, never records ledger rows. `kevin_trace` (K5-015)
133
+ * surfaces this to the agent; tests freeze the clock + settings around
134
+ * it.
135
+ */
136
+ plan(query: string, options?: {
137
+ tag?: "context" | "memory";
138
+ cap?: number;
139
+ sessionId?: string;
140
+ }): InjectionPlan;
141
+ /**
142
+ * v0.5.0 (K5-014 / plan §8.10) — PURE gate evaluation shared by `admit`
143
+ * (live path) and `plan` (read-only path): returns the verdict for every
144
+ * candidate plus the seen-set as it WOULD look afterwards. Never writes
145
+ * state — the caller decides whether to persist.
146
+ */
147
+ private evaluate;
148
+ /**
149
+ * v0.5.0 (K5-017 / plan §8.11, D5-11) — the effective pre-prompt cap,
150
+ * read at call time from `pre_prompt_budget_tokens` (seeded "900" by
151
+ * migration 006). Clamped to [100, 4000]; a non-numeric value falls
152
+ * back to 900. `kevin_trace` reports the value used via `plan().cap`.
153
+ *
154
+ * v0.6.0 (K6-021 / plan §5.8) — default becomes "400" and the lower
155
+ * clamp bound drops to **0**: the roadmap's kill criterion K1 prescribes
156
+ * cutting the push budget to zero when coverage is poor, and v0.5's
157
+ * [100, 4000] clamp made that response unimplementable. A non-numeric
158
+ * value falls back to 400. `onSystemTransform` treats 0 as off and
159
+ * returns before any retrieval (see K6-021 acceptance).
160
+ */
161
+ private prePromptCap;
162
+ /**
163
+ * v0.4.0 (K4-017) — QualityGate admission: filters the ranked slice to
164
+ * memories that may be injected this session, updating the session
165
+ * seen-set.
166
+ *
167
+ * v0.5.0 (K5-007 / plan §5.2, D5-04) — uses `canInjectVerdict` and
168
+ * increments the matching `injections_blocked_*` counter for every
169
+ * rejection, so gate policy becomes measurable. When `dryRun === true`
170
+ * the counters stay untouched (D5-08) — and so does the seen-set
171
+ * (a dry run is a strict read, K5-014).
172
+ *
173
+ * BUG-005 — strength/actionability now go through the REAL
174
+ * `QualityGate.evaluate` semantics (plan §5.1 rules 1-2), which this
175
+ * class had only re-derived from `metadata.dispatch`:
176
+ * - dispatched code → strong + actionable (rescued errorType);
177
+ * - generic fallback suggestion + no code → weak, NOT actionable
178
+ * (the generic-suggestion ban is now enforced even for legacy
179
+ * lessons without dispatch metadata, as long as the `Suggestion:`
180
+ * text is available);
181
+ * - specific suggestion without code → strong + actionable;
182
+ * - no `Suggestion:` text at all (agent-saved note) → strong +
183
+ * actionable — the agent explicitly asked to remember it;
184
+ * - causal patterns (type='pattern') → always strong + actionable:
185
+ * they are the FIXED form of a fingerprint (K4-025).
186
+ */
187
+ private admit;
188
+ /**
189
+ * BUG-005 — the single source of truth for a memory's lesson quality,
190
+ * shared by `admit` (the gate) and `format` (the K4-023 `(low
191
+ * confidence)` marker). Routes lessons through `QualityGate.evaluate`
192
+ * — the production call site that was previously missing.
193
+ */
194
+ private lessonQuality;
195
+ /**
196
+ * v0.4.0 (K4-017) — one ledger row per admitted memory (plan §5.2).
197
+ * Token attribution uses the memory's share of the final block.
198
+ *
199
+ * v0.8.0 (K8-024 / plan §5.7) — shared projections are recorded even
200
+ * though they carry NO fingerprint by design (K8-017 — it is a
201
+ * different identity dimension): the memory id is their identity in
202
+ * the ledger, and recording them is what makes `injections_from_shared`
203
+ * observable at all. No tool call can ever match a memory id, so
204
+ * settle() marks the row inconclusive — excluded from the precision
205
+ * denominator (K5-005) — and the BUG-015 skip is unchanged for local
206
+ * notes without a fingerprint.
207
+ */
208
+ private recordInjections;
209
+ /**
210
+ * v0.4.0 (K4-012) — snippet injection payload (plan §5.1 rule 5,
211
+ * D4-05): rows show `id:` + first 2 non-empty lines + `<protect>`
212
+ * instead of the full body. Gated by the `lesson_snippet_injection`
213
+ * setting (default `'1'`); when `'0'`, full content is restored.
214
+ * `escapeInjectedText` is applied to snippet content by the formatter.
215
+ * v0.4.0 (K4-023) — weak lessons admitted in debug mode are flagged so
216
+ * the formatter renders the `(low confidence)` marker.
217
+ */
218
+ private format;
219
+ deriveQuery(messages: ChatMessage[]): string;
220
+ onSystemTransform(input: SystemTransformInput, output: SystemTransformOutput): void;
221
+ onCompacting(input: CompactingInput, output: CompactingOutput): void;
222
+ }