@jmtrin/opencode-kevin 0.1.5 → 0.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.
- package/README.md +108 -33
- package/dist/migrations/003_v02_signal.sql +58 -0
- package/dist/migrations/004_v03_knowledge.sql +138 -0
- package/dist/plugin/CausalChain.d.ts +11 -0
- package/dist/plugin/CausalChain.js +109 -0
- package/dist/plugin/CausalChain.js.map +1 -0
- package/dist/plugin/ContextInjector.d.ts +25 -1
- package/dist/plugin/ContextInjector.js +72 -15
- package/dist/plugin/ContextInjector.js.map +1 -1
- package/dist/plugin/MemoryService.d.ts +110 -3
- package/dist/plugin/MemoryService.js +432 -20
- package/dist/plugin/MemoryService.js.map +1 -1
- package/dist/plugin/Migrate.d.ts +4 -1
- package/dist/plugin/Migrate.js +40 -1
- package/dist/plugin/Migrate.js.map +1 -1
- package/dist/plugin/PatternMiner.d.ts +49 -0
- package/dist/plugin/PatternMiner.js +133 -0
- package/dist/plugin/PatternMiner.js.map +1 -0
- package/dist/plugin/Reflector.d.ts +45 -2
- package/dist/plugin/Reflector.js +134 -12
- package/dist/plugin/Reflector.js.map +1 -1
- package/dist/plugin/Retrospective.d.ts +4 -1
- package/dist/plugin/Retrospective.js +72 -5
- package/dist/plugin/Retrospective.js.map +1 -1
- package/dist/plugin/Store.d.ts +15 -0
- package/dist/plugin/Store.js +15 -0
- package/dist/plugin/Store.js.map +1 -1
- package/dist/plugin/ToolCallObserver.d.ts +4 -1
- package/dist/plugin/ToolCallObserver.js +39 -7
- package/dist/plugin/ToolCallObserver.js.map +1 -1
- package/dist/plugin/fingerprint.d.ts +27 -0
- package/dist/plugin/fingerprint.js +74 -0
- package/dist/plugin/fingerprint.js.map +1 -0
- package/dist/plugin/index.js +213 -15
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/kevin_why.d.ts +19 -0
- package/dist/plugin/kevin_why.js +92 -0
- package/dist/plugin/kevin_why.js.map +1 -0
- package/dist/plugin/memory-format.d.ts +2 -0
- package/dist/plugin/memory-format.js +6 -3
- package/dist/plugin/memory-format.js.map +1 -1
- package/dist/plugin/metrics.d.ts +60 -0
- package/dist/plugin/metrics.js +162 -0
- package/dist/plugin/metrics.js.map +1 -0
- package/dist/plugin/okf-export.d.ts +3 -0
- package/dist/plugin/okf-export.js +86 -0
- package/dist/plugin/okf-export.js.map +1 -0
- package/dist/plugin/okf-import.d.ts +73 -0
- package/dist/plugin/okf-import.js +239 -0
- package/dist/plugin/okf-import.js.map +1 -0
- package/dist/plugin/redact.d.ts +1 -0
- package/dist/plugin/redact.js +7 -0
- package/dist/plugin/redact.js.map +1 -1
- package/migrations/003_v02_signal.sql +58 -0
- package/migrations/004_v03_knowledge.sql +138 -0
- package/package.json +48 -48
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { formatMemories } from "./memory-format.js";
|
|
2
|
+
import { estimateTokens } from "./metrics.js";
|
|
2
3
|
const SYSTEM_TRANSFORM_TOKENS = 1500;
|
|
3
4
|
const COMPACTING_TOKENS = 2000;
|
|
4
5
|
const STOP_WORDS = new Set([
|
|
@@ -69,8 +70,72 @@ function isWordChar(ch) {
|
|
|
69
70
|
}
|
|
70
71
|
export class ContextInjector {
|
|
71
72
|
memoryService;
|
|
72
|
-
|
|
73
|
+
metrics;
|
|
74
|
+
lastRecurrenceCount = 0;
|
|
75
|
+
constructor(memoryService, metrics = null) {
|
|
73
76
|
this.memoryService = memoryService;
|
|
77
|
+
this.metrics = metrics;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* v0.3.0 (K3-020) — notify the injector that the negative feedback half
|
|
81
|
+
* fired N times in the last session.idle. The next system.transform or
|
|
82
|
+
* compacting hook will prepend a HITL suggestion block.
|
|
83
|
+
*/
|
|
84
|
+
setRecurrences(count) {
|
|
85
|
+
this.lastRecurrenceCount = count;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* v0.3.0 (K3-020) — generate a HITL suggestion block when recurrences
|
|
89
|
+
* occurred. Returns the block or empty string. Resets the counter.
|
|
90
|
+
*/
|
|
91
|
+
generateSuggestion() {
|
|
92
|
+
if (this.lastRecurrenceCount === 0)
|
|
93
|
+
return "";
|
|
94
|
+
const block = `<kevin-suggestion>
|
|
95
|
+
The same error pattern recurred ${this.lastRecurrenceCount} time(s) this session.
|
|
96
|
+
Consider adding a skill or convention to AGENTS.md to prevent this.
|
|
97
|
+
|
|
98
|
+
Draft:
|
|
99
|
+
\`\`\`markdown
|
|
100
|
+
## Recurring pattern
|
|
101
|
+
- ${this.lastRecurrenceCount} recurrence(s) this session
|
|
102
|
+
- Kevin's confidence in this pattern is low
|
|
103
|
+
- Consider documenting the fix in AGENTS.md
|
|
104
|
+
\`\`\`
|
|
105
|
+
</kevin-suggestion>`;
|
|
106
|
+
this.lastRecurrenceCount = 0;
|
|
107
|
+
return block;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* v0.2.0 (K2-024): origin-aware ranking at injection time is delegated
|
|
111
|
+
* to `MemoryService.getRelevant()` (K2-023, D2-13). The injector does
|
|
112
|
+
* NOT re-rank on its own — it consumes the already-ranked slice and
|
|
113
|
+
* applies the conditional-budget guard for opt-out (`protect: false`)
|
|
114
|
+
* callers. Plan §B6.5: "apply the same multiplier as
|
|
115
|
+
* MemoryService.recall so reflector lessons outrank agent-saved notes
|
|
116
|
+
* at injection time" — satisfied transitively via the getRelevant call.
|
|
117
|
+
*/
|
|
118
|
+
inject(query, tag, cap, metricKey) {
|
|
119
|
+
let memories = this.memoryService.getRelevant({ query, maxTokens: cap });
|
|
120
|
+
if (memories.length === 0)
|
|
121
|
+
return "";
|
|
122
|
+
const firstBlock = formatMemories(memories, tag);
|
|
123
|
+
const aggregateTokens = estimateTokens(firstBlock);
|
|
124
|
+
const firstRowProtect = memories[0]
|
|
125
|
+
?.protect;
|
|
126
|
+
const noProtectAboveTheFold = firstRowProtect === false;
|
|
127
|
+
if (aggregateTokens > 0.8 * cap && noProtectAboveTheFold) {
|
|
128
|
+
const lowerCap = Math.max(1, Math.round(0.8 * cap));
|
|
129
|
+
memories = this.memoryService.getRelevant({
|
|
130
|
+
query,
|
|
131
|
+
maxTokens: lowerCap,
|
|
132
|
+
});
|
|
133
|
+
if (memories.length === 0)
|
|
134
|
+
return "";
|
|
135
|
+
}
|
|
136
|
+
const block = formatMemories(memories, tag);
|
|
137
|
+
this.metrics?.incr(metricKey, estimateTokens(block));
|
|
138
|
+
return block;
|
|
74
139
|
}
|
|
75
140
|
deriveQuery(messages) {
|
|
76
141
|
let lastUserContent = "";
|
|
@@ -100,25 +165,17 @@ export class ContextInjector {
|
|
|
100
165
|
const query = this.deriveQuery(input.messages);
|
|
101
166
|
if (!query)
|
|
102
167
|
return;
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
});
|
|
107
|
-
if (memories.length === 0)
|
|
108
|
-
return;
|
|
109
|
-
output.system.push(formatMemories(memories, "context"));
|
|
168
|
+
const block = this.inject(query, "context", SYSTEM_TRANSFORM_TOKENS, "tokens_injected_pre_prompt");
|
|
169
|
+
if (block)
|
|
170
|
+
output.system.push(block);
|
|
110
171
|
}
|
|
111
172
|
onCompacting(input, output) {
|
|
112
173
|
const query = this.deriveQuery(input.messages);
|
|
113
174
|
if (!query)
|
|
114
175
|
return;
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
119
|
-
if (memories.length === 0)
|
|
120
|
-
return;
|
|
121
|
-
output.context.push(formatMemories(memories, "memory"));
|
|
176
|
+
const block = this.inject(query, "memory", COMPACTING_TOKENS, "tokens_injected_compacting");
|
|
177
|
+
if (block)
|
|
178
|
+
output.context.push(block);
|
|
122
179
|
}
|
|
123
180
|
}
|
|
124
181
|
//# sourceMappingURL=ContextInjector.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextInjector.js","sourceRoot":"","sources":["../../plugin/ContextInjector.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ContextInjector.js","sourceRoot":"","sources":["../../plugin/ContextInjector.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAgB,cAAc,EAAE,MAAM,cAAc,CAAC;AAyB5D,MAAM,uBAAuB,GAAG,IAAI,CAAC;AACrC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B,MAAM,UAAU,GAAG,IAAI,GAAG,CAAS;IAClC,GAAG;IACH,IAAI;IACJ,KAAK;IACL,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,MAAM;IACN,KAAK;IACL,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,MAAM;IACN,IAAI;IACJ,KAAK;IACL,KAAK;IACL,KAAK;IACL,GAAG;IACH,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,GAAG;IACH,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,MAAM;IACN,KAAK;IACL,KAAK;IACL,KAAK;IACL,IAAI;IACJ,MAAM;IACN,KAAK;IACL,MAAM;IACN,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,KAAK;IACL,KAAK;IACL,MAAM;IACN,GAAG;IACH,KAAK;IACL,MAAM;IACN,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,IAAI;IACJ,MAAM;IACN,KAAK;IACL,KAAK;CACL,CAAC,CAAC;AAEH,SAAS,UAAU,CAAC,EAAU;IAC7B,OAAO,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,OAAO,eAAe;IAIlB;IACA;IAJD,mBAAmB,GAAG,CAAC,CAAC;IAEhC,YACS,aAA4B,EAC5B,UAA0B,IAAI;QAD9B,kBAAa,GAA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2B,EAC3B,MAA6B;QAE7B,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC/C,IAAI,CAAC,KAAK;YAAE,OAAO;QACnB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CACxB,KAAK,EACL,SAAS,EACT,uBAAuB,EACvB,4BAA4B,CAC5B,CAAC;QACF,IAAI,KAAK;YAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;IAED,YAAY,CAAC,KAAsB,EAAE,MAAwB;QAC5D,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC/C,IAAI,CAAC,KAAK;YAAE,OAAO;QACnB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CACxB,KAAK,EACL,QAAQ,EACR,iBAAiB,EACjB,4BAA4B,CAC5B,CAAC;QACF,IAAI,KAAK;YAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC;CACD"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Store } from "./Store.js";
|
|
2
|
-
|
|
2
|
+
import type { Metrics } from "./metrics.js";
|
|
3
|
+
export type MemoryType = "error" | "pattern" | "decision" | "context" | "rule" | "solution";
|
|
3
4
|
export type MemoryScope = "project" | "session";
|
|
5
|
+
export type MemoryOrigin = "reflector" | "agent" | "pattern" | "retrospective" | "causal" | "imported";
|
|
4
6
|
export interface Memory {
|
|
5
7
|
id: string;
|
|
6
8
|
type: MemoryType;
|
|
@@ -13,6 +15,20 @@ export interface Memory {
|
|
|
13
15
|
createdAt: string;
|
|
14
16
|
updatedAt: string;
|
|
15
17
|
expiresAt?: string | null;
|
|
18
|
+
/** v0.2.0 — project the memory belongs to (nullable for legacy rows). */
|
|
19
|
+
projectId?: string | null;
|
|
20
|
+
/** v0.2.0 — content fingerprint for dedup (only set for `type='error'`). */
|
|
21
|
+
fingerprint?: string | null;
|
|
22
|
+
/** v0.2.0 — origin of the memory. */
|
|
23
|
+
origin?: MemoryOrigin | null;
|
|
24
|
+
/** v0.3.0 — confidence derived from causal evidence (0..1). Only set by CausalChain. */
|
|
25
|
+
confidence?: number | null;
|
|
26
|
+
/** v0.3.0 — number of confirmed causal fix confirmations. */
|
|
27
|
+
evidenceCount?: number | null;
|
|
28
|
+
/** v0.3.0 — last time causal evidence was observed. */
|
|
29
|
+
lastVerifiedAt?: string | null;
|
|
30
|
+
/** v0.3.0 — lifecycle status. Default 'active'. */
|
|
31
|
+
status?: string | null;
|
|
16
32
|
}
|
|
17
33
|
export interface SaveInput {
|
|
18
34
|
type: MemoryType;
|
|
@@ -23,27 +39,118 @@ export interface SaveInput {
|
|
|
23
39
|
sourceSession?: string;
|
|
24
40
|
metadata?: Record<string, unknown>;
|
|
25
41
|
expiresAt?: string;
|
|
42
|
+
/** v0.2.0 — project id. When absent, the memory is cross-project (NULL project_id). */
|
|
43
|
+
projectId?: string;
|
|
44
|
+
/** v0.2.0 — origin. Defaults to `'agent'` when omitted. */
|
|
45
|
+
origin?: MemoryOrigin;
|
|
46
|
+
/** v0.2.0 — explicit fingerprint. Auto-derived for `type='error'` if absent. */
|
|
47
|
+
fingerprint?: string;
|
|
48
|
+
/** v0.3.0 — number of confirmed causal fix confirmations. */
|
|
49
|
+
evidenceCount?: number;
|
|
50
|
+
/** v0.3.0 — last time causal evidence was observed. */
|
|
51
|
+
lastVerifiedAt?: string;
|
|
52
|
+
/** v0.3.0 — lifecycle status. Default 'active'. */
|
|
53
|
+
status?: string;
|
|
26
54
|
}
|
|
27
55
|
export interface QueryInput {
|
|
28
56
|
text: string;
|
|
29
57
|
type?: string;
|
|
30
58
|
scope?: MemoryScope | "all";
|
|
31
59
|
limit?: number;
|
|
60
|
+
/** v0.2.0 — when true, returns full `Memory` rows (v0.1.x behavior).
|
|
61
|
+
* When `false` or absent, returns `SlimMemory` rows (default v0.2.0
|
|
62
|
+
* behavior, per plan §B6.3 / K2-010).
|
|
63
|
+
*/
|
|
64
|
+
full?: boolean;
|
|
65
|
+
/** v0.3.0 — when true, includes rows where status = 'superseded'.
|
|
66
|
+
* Default false (only active rows). */
|
|
67
|
+
includeSuperseded?: boolean;
|
|
68
|
+
}
|
|
69
|
+
/** v0.2.0 — slim query payload (K2-010). Snippet is a short content prefix;
|
|
70
|
+
* `score` is the FTS5 BM25 score when available, falling back to
|
|
71
|
+
* `relevanceScore` for non-FTS callers. */
|
|
72
|
+
export interface SlimMemory {
|
|
73
|
+
id: string;
|
|
74
|
+
type: MemoryType;
|
|
75
|
+
scope: MemoryScope;
|
|
76
|
+
score: number;
|
|
77
|
+
snippet: string;
|
|
32
78
|
}
|
|
33
79
|
export interface GetRelevantInput {
|
|
34
80
|
query?: string;
|
|
35
81
|
maxTokens?: number;
|
|
36
82
|
scope?: MemoryScope | "all";
|
|
83
|
+
/** v0.3.0 — when true, includes rows where status = 'superseded'.
|
|
84
|
+
* Default false (only active rows). */
|
|
85
|
+
includeSuperseded?: boolean;
|
|
37
86
|
}
|
|
38
87
|
export declare class MemoryService {
|
|
88
|
+
private readonly metrics;
|
|
89
|
+
constructor(store: Store, metrics?: Metrics | null);
|
|
39
90
|
private store;
|
|
40
|
-
constructor(store: Store);
|
|
41
91
|
save(input: SaveInput): string;
|
|
42
92
|
getById(id: string): Memory | null;
|
|
43
93
|
update(id: string, fields: Partial<Memory>): void;
|
|
44
94
|
delete(id: string): void;
|
|
45
|
-
|
|
95
|
+
/** v0.1.x behavior — returns full `Memory` rows. */
|
|
96
|
+
query(input: QueryInput & {
|
|
97
|
+
full: true;
|
|
98
|
+
}): Memory[];
|
|
99
|
+
/** v0.2.0 default — returns `SlimMemory` rows. */
|
|
100
|
+
query(input: QueryInput): SlimMemory[];
|
|
101
|
+
private isCrossProjectEnabled;
|
|
46
102
|
private loadAll;
|
|
47
103
|
private queryRelevant;
|
|
48
104
|
getRelevant(input: GetRelevantInput): Memory[];
|
|
105
|
+
/**
|
|
106
|
+
* v0.3.0 (K3-004) — Promote an error memory to a causal pattern.
|
|
107
|
+
*
|
|
108
|
+
* Creates a new `pattern` memory with `origin = 'causal'`, derived
|
|
109
|
+
* confidence, and evidence count. The original error memory is NOT
|
|
110
|
+
* deleted — the audit trail is preserved. Returns the new memory id,
|
|
111
|
+
* or null when the source error is not eligible (missing fingerprint,
|
|
112
|
+
* wrong type, or already promoted).
|
|
113
|
+
*/
|
|
114
|
+
promoteToPattern(errorId: string, evidenceCount: number): string | null;
|
|
115
|
+
/**
|
|
116
|
+
* v0.2.0 (K2-026) — Feedback loop positive half (plan §B6.10 / D2-10).
|
|
117
|
+
*
|
|
118
|
+
* For each reflector-sourced error memory emitted during the given session
|
|
119
|
+
* whose fingerprint did NOT recur as a failing `tool_call` within the same
|
|
120
|
+
* project, bump `relevance_score` by `RELEVANCE_BUMP` (capped at
|
|
121
|
+
* `RELEVANCE_MAX`). Agent-saved memories are NEVER auto-boosted by this
|
|
122
|
+
* loop (anti-gaming guarantee, D2-06).
|
|
123
|
+
*
|
|
124
|
+
* Returns the number of memories that received a positive boost.
|
|
125
|
+
*/
|
|
126
|
+
boostPositiveReflectors(sessionId: string): number;
|
|
127
|
+
/**
|
|
128
|
+
* v0.3.0 (K3-013) — Feedback loop negative half.
|
|
129
|
+
*
|
|
130
|
+
* For each reflector-sourced error memory from this session whose
|
|
131
|
+
* fingerprint DID recur as a failing tool_call (the lesson didn't
|
|
132
|
+
* prevent the error), decrement `relevance_score` by `RELEVANCE_PENALTY`
|
|
133
|
+
* (down to zero) and increment `evidence_count` as a negative signal.
|
|
134
|
+
* Agent-saved memories are NEVER penalized.
|
|
135
|
+
*
|
|
136
|
+
* Returns the number of memories penalized.
|
|
137
|
+
*/
|
|
138
|
+
/**
|
|
139
|
+
* v0.3.0 fix — Mirror of the free function `countSupersedeCandidates`
|
|
140
|
+
* exposed as an instance method so `okf-import` (which holds a
|
|
141
|
+
* `MemoryService` reference but not the underlying `Store`) can count
|
|
142
|
+
* rows that `save()` will mark as superseded.
|
|
143
|
+
*/
|
|
144
|
+
countSupersedeCandidates(type: MemoryType, fingerprint: string | null | undefined, projectId: string | null): number;
|
|
145
|
+
penalizeRecurringReflectors(sessionId: string): number;
|
|
49
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* v0.3.0 fix — Count active memories that would be superseded by a new
|
|
149
|
+
* row with the given (type, fingerprint, projectId) tuple. Used by
|
|
150
|
+
* `okf-import` to populate `ImportResult.superseded` accurately.
|
|
151
|
+
*
|
|
152
|
+
* Matches the supersede logic in `save()`: only `decision` and `rule`
|
|
153
|
+
* types supersede prior rows with the same fingerprint. Returns 0 for
|
|
154
|
+
* any other type.
|
|
155
|
+
*/
|
|
156
|
+
export declare function countSupersedeCandidates(store: Store, type: MemoryType, fingerprint: string | null | undefined, projectId: string | null): number;
|