@jmtrin/opencode-kevin 1.1.0 → 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 (131) hide show
  1. package/dist/plugin/capabilities.d.ts +2 -0
  2. package/dist/plugin/capabilities.js +3 -0
  3. package/dist/plugin/index.d.ts +5 -4
  4. package/dist/plugin/index.js +401 -108
  5. package/dist/plugin/native.d.ts +2 -2
  6. package/dist/plugin/native.js +2 -2
  7. package/package.json +56 -63
  8. package/LICENSE +0 -21
  9. package/README.md +0 -576
  10. package/dist/migrations/001_initial.sql +0 -92
  11. package/dist/migrations/002_indexes.sql +0 -14
  12. package/dist/migrations/003_v02_signal.sql +0 -58
  13. package/dist/migrations/004_v03_knowledge.sql +0 -138
  14. package/dist/migrations/005_v04_signal.sql +0 -57
  15. package/dist/migrations/006_v05_glassbox.sql +0 -118
  16. package/dist/migrations/007_v06_pull.sql +0 -145
  17. package/dist/migrations/008_v07_truth.sql +0 -124
  18. package/dist/migrations/009_v08_team.sql +0 -100
  19. package/dist/migrations/010_v09_native.sql +0 -78
  20. package/dist/migrations/011_v10_proven.sql +0 -69
  21. package/dist/migrations/012_v11_drift.sql +0 -24
  22. package/dist/plugin/Archiver.d.ts +0 -42
  23. package/dist/plugin/Archiver.js +0 -83
  24. package/dist/plugin/ArtifactWriter.d.ts +0 -93
  25. package/dist/plugin/ArtifactWriter.js +0 -291
  26. package/dist/plugin/CausalChain.d.ts +0 -22
  27. package/dist/plugin/CausalChain.js +0 -197
  28. package/dist/plugin/ConflictDetector.d.ts +0 -35
  29. package/dist/plugin/ConflictDetector.js +0 -260
  30. package/dist/plugin/ContextInjector.d.ts +0 -222
  31. package/dist/plugin/ContextInjector.js +0 -533
  32. package/dist/plugin/ConventionMiner.d.ts +0 -35
  33. package/dist/plugin/ConventionMiner.js +0 -242
  34. package/dist/plugin/Curator.d.ts +0 -116
  35. package/dist/plugin/Curator.js +0 -324
  36. package/dist/plugin/Feedback.d.ts +0 -67
  37. package/dist/plugin/Feedback.js +0 -120
  38. package/dist/plugin/HookLiveness.d.ts +0 -88
  39. package/dist/plugin/HookLiveness.js +0 -322
  40. package/dist/plugin/InjectionLedger.d.ts +0 -98
  41. package/dist/plugin/InjectionLedger.js +0 -295
  42. package/dist/plugin/LessonFixer.d.ts +0 -44
  43. package/dist/plugin/LessonFixer.js +0 -45
  44. package/dist/plugin/Materializer.d.ts +0 -83
  45. package/dist/plugin/Materializer.js +0 -181
  46. package/dist/plugin/MemoryService.d.ts +0 -360
  47. package/dist/plugin/MemoryService.js +0 -1242
  48. package/dist/plugin/Migrate.d.ts +0 -17
  49. package/dist/plugin/Migrate.js +0 -271
  50. package/dist/plugin/PatternMiner.d.ts +0 -49
  51. package/dist/plugin/PatternMiner.js +0 -132
  52. package/dist/plugin/QualityGate.d.ts +0 -124
  53. package/dist/plugin/QualityGate.js +0 -119
  54. package/dist/plugin/Reflector.d.ts +0 -91
  55. package/dist/plugin/Reflector.js +0 -307
  56. package/dist/plugin/RepoIdentity.d.ts +0 -124
  57. package/dist/plugin/RepoIdentity.js +0 -300
  58. package/dist/plugin/RepoTruth.d.ts +0 -80
  59. package/dist/plugin/RepoTruth.js +0 -599
  60. package/dist/plugin/Retrospective.d.ts +0 -17
  61. package/dist/plugin/Retrospective.js +0 -213
  62. package/dist/plugin/SharedLayer.d.ts +0 -159
  63. package/dist/plugin/SharedLayer.js +0 -462
  64. package/dist/plugin/Store.d.ts +0 -29
  65. package/dist/plugin/Store.js +0 -50
  66. package/dist/plugin/ToolCallObserver.d.ts +0 -32
  67. package/dist/plugin/ToolCallObserver.js +0 -201
  68. package/dist/plugin/columns.d.ts +0 -11
  69. package/dist/plugin/columns.js +0 -54
  70. package/dist/plugin/confidence.d.ts +0 -8
  71. package/dist/plugin/confidence.js +0 -34
  72. package/dist/plugin/contract.d.ts +0 -54
  73. package/dist/plugin/contract.js +0 -383
  74. package/dist/plugin/diff.d.ts +0 -8
  75. package/dist/plugin/diff.js +0 -182
  76. package/dist/plugin/escape.d.ts +0 -39
  77. package/dist/plugin/escape.js +0 -60
  78. package/dist/plugin/fingerprint.d.ts +0 -27
  79. package/dist/plugin/fingerprint.js +0 -73
  80. package/dist/plugin/inferability.d.ts +0 -32
  81. package/dist/plugin/inferability.js +0 -88
  82. package/dist/plugin/kevin_approve.d.ts +0 -34
  83. package/dist/plugin/kevin_approve.js +0 -52
  84. package/dist/plugin/kevin_audit.d.ts +0 -213
  85. package/dist/plugin/kevin_audit.js +0 -563
  86. package/dist/plugin/kevin_bench.d.ts +0 -10
  87. package/dist/plugin/kevin_bench.js +0 -82
  88. package/dist/plugin/kevin_conflicts.d.ts +0 -9
  89. package/dist/plugin/kevin_conflicts.js +0 -50
  90. package/dist/plugin/kevin_contract.d.ts +0 -8
  91. package/dist/plugin/kevin_contract.js +0 -59
  92. package/dist/plugin/kevin_doctor.d.ts +0 -62
  93. package/dist/plugin/kevin_doctor.js +0 -196
  94. package/dist/plugin/kevin_facts.d.ts +0 -42
  95. package/dist/plugin/kevin_facts.js +0 -36
  96. package/dist/plugin/kevin_forget.d.ts +0 -33
  97. package/dist/plugin/kevin_forget.js +0 -260
  98. package/dist/plugin/kevin_native.d.ts +0 -29
  99. package/dist/plugin/kevin_native.js +0 -79
  100. package/dist/plugin/kevin_propose.d.ts +0 -23
  101. package/dist/plugin/kevin_propose.js +0 -14
  102. package/dist/plugin/kevin_publish.d.ts +0 -38
  103. package/dist/plugin/kevin_publish.js +0 -18
  104. package/dist/plugin/kevin_why.d.ts +0 -23
  105. package/dist/plugin/kevin_why.js +0 -111
  106. package/dist/plugin/memory-format.d.ts +0 -20
  107. package/dist/plugin/memory-format.js +0 -59
  108. package/dist/plugin/metrics.d.ts +0 -97
  109. package/dist/plugin/metrics.js +0 -284
  110. package/dist/plugin/okf-export.d.ts +0 -3
  111. package/dist/plugin/okf-export.js +0 -134
  112. package/dist/plugin/okf-import.d.ts +0 -76
  113. package/dist/plugin/okf-import.js +0 -271
  114. package/dist/plugin/okf.d.ts +0 -107
  115. package/dist/plugin/okf.js +0 -303
  116. package/dist/plugin/perf.d.ts +0 -35
  117. package/dist/plugin/perf.js +0 -174
  118. package/dist/plugin/query-tokenizer.d.ts +0 -13
  119. package/dist/plugin/query-tokenizer.js +0 -133
  120. package/dist/plugin/redact.d.ts +0 -2
  121. package/dist/plugin/redact.js +0 -18
  122. package/dist/plugin/replay-types.d.ts +0 -69
  123. package/dist/plugin/replay-types.js +0 -156
  124. package/dist/plugin/replay.d.ts +0 -36
  125. package/dist/plugin/replay.js +0 -202
  126. package/dist/plugin/sqlite-adapter.d.ts +0 -12
  127. package/dist/plugin/sqlite-adapter.js +0 -81
  128. package/dist/plugin/time-ms.d.ts +0 -1
  129. package/dist/plugin/time-ms.js +0 -16
  130. package/dist/plugin/uuid.d.ts +0 -1
  131. package/dist/plugin/uuid.js +0 -50
@@ -1,202 +0,0 @@
1
- import { dirname, join } from "node:path";
2
- import { fileURLToPath } from "node:url";
3
- import { Archiver } from "./Archiver.js";
4
- import { CausalChain } from "./CausalChain.js";
5
- import { ContextInjector } from "./ContextInjector.js";
6
- import { InjectionLedger } from "./InjectionLedger.js";
7
- import { MemoryService } from "./MemoryService.js";
8
- import { Migrate } from "./Migrate.js";
9
- import { Reflector } from "./Reflector.js";
10
- import { Store } from "./Store.js";
11
- import { ToolCallObserver } from "./ToolCallObserver.js";
12
- import { Metrics } from "./metrics.js";
13
- const MIGRATIONS_DIR = join(dirname(fileURLToPath(import.meta.url)), "..", "migrations");
14
- export async function replay(transcript, opts) {
15
- const store = new Store({ path: opts?.dbPath ?? ":memory:" });
16
- await new Migrate(store, MIGRATIONS_DIR).run();
17
- // Freeze retrieval BEFORE any query happens (K5-008): deterministic
18
- // mode uses the DATE_NOW sentinel, ignores recency and never bumps.
19
- store
20
- .prepare("INSERT OR IGNORE INTO kevin_settings (key, value) VALUES ('deterministic_retrieval', '1')")
21
- .run();
22
- store
23
- .prepare("UPDATE kevin_settings SET value = '1' WHERE key = 'deterministic_retrieval'")
24
- .run();
25
- // v0.6.0 (K6-022) — the release floor (0.6) blocks every
26
- // single-observation memory the v0.5-era fixture exercises; the replay
27
- // harness preserves the v0.5 push semantics it was recorded under, the
28
- // same opt-out the legacy plugin harnesses apply.
29
- store
30
- .prepare("INSERT OR IGNORE INTO kevin_settings (key, value) VALUES ('injection_confidence_floor', '0')")
31
- .run();
32
- store
33
- .prepare("UPDATE kevin_settings SET value = '0' WHERE key = 'injection_confidence_floor'")
34
- .run();
35
- const metrics = new Metrics(store);
36
- const memoryService = new MemoryService(store, metrics);
37
- const observer = new ToolCallObserver(store, metrics);
38
- // v0.3.0 fix (mirrors index.ts) — the Reflector stamps
39
- // tool_calls.error_fingerprint with the stderr-based fingerprint the
40
- // error memory uses; without it the recurrence queries in settle and
41
- // the feedback loop never match (tool_calls.fingerprint is keyed on
42
- // `${tool}|${args}|${success}`, memories on a hash of stderr/stdout).
43
- const linkErrorStmt = store.prepare("UPDATE tool_calls SET error_fingerprint = ? WHERE id = ?");
44
- const reflector = new Reflector(memoryService, {
45
- throttleMs: 0,
46
- onLinkError: (callID, fp) => {
47
- linkErrorStmt.run(fp, callID);
48
- },
49
- }, metrics);
50
- const ledger = new InjectionLedger(store, metrics);
51
- const injector = new ContextInjector(memoryService, metrics, ledger);
52
- const causalChain = new CausalChain(store, memoryService, metrics);
53
- // The Archiver reads the clock through this accessor, which is updated
54
- // to the current event's `at` before each event is processed.
55
- let currentAt = new Date(transcript.events[0]?.at ?? Date.now());
56
- const archiver = new Archiver(store, memoryService, metrics, () => currentAt);
57
- const lastUserQueryBySession = new Map();
58
- const callCache = new Map();
59
- function resolveQuery(sessionId) {
60
- return lastUserQueryBySession.get(sessionId) ?? "";
61
- }
62
- for (const event of transcript.events) {
63
- currentAt = new Date(event.at);
64
- await handleEvent(event);
65
- }
66
- metrics.flush();
67
- const outcomeRows = store
68
- .prepare("SELECT outcome, COUNT(*) AS n FROM kevin_injections GROUP BY outcome")
69
- .all();
70
- const counts = {
71
- unmeasured: 0,
72
- effective: 0,
73
- ineffective: 0,
74
- inconclusive: 0,
75
- };
76
- for (const r of outcomeRows) {
77
- counts[r.outcome] = r.n;
78
- }
79
- const total = outcomeRows.reduce((acc, r) => acc + r.n, 0);
80
- const tokenValue = (key) => {
81
- const row = store
82
- .prepare("SELECT value FROM kevin_metrics WHERE key = ?")
83
- .get(key);
84
- return row?.value ?? 0;
85
- };
86
- return {
87
- transcript: transcript.name,
88
- memoriesCreated: totalMemories(store),
89
- injections: {
90
- total,
91
- effective: counts.effective,
92
- ineffective: counts.ineffective,
93
- inconclusive: counts.inconclusive,
94
- unmeasured: counts.unmeasured,
95
- },
96
- precisionRate: metrics.precisionRate(),
97
- coverageRate: metrics.coverageRate(),
98
- tokensInjected: {
99
- prePrompt: tokenValue("tokens_injected_pre_prompt"),
100
- compacting: tokenValue("tokens_injected_compacting"),
101
- },
102
- blocked: metrics.blockedSnapshot(),
103
- };
104
- async function handleEvent(event) {
105
- switch (event.kind) {
106
- case "session.created":
107
- // Mirror of the live wiring (index.ts): a fresh session must
108
- // not inherit the previous session's injection seen-set
109
- // (plan §5.1 rule 3). Without this, a multi-session
110
- // transcript would block every memory in session 2 with
111
- // `seen_this_session` while the live plugin would admit it.
112
- injector.onSessionCreated(event.sessionId);
113
- return;
114
- case "chat.message": {
115
- const derived = injector.deriveQuery([
116
- { role: "user", content: event.text },
117
- ]);
118
- if (derived.length > 0) {
119
- lastUserQueryBySession.set(event.sessionId, derived);
120
- }
121
- return;
122
- }
123
- case "tool.before": {
124
- callCache.set(event.callId, {
125
- tool: event.tool,
126
- args: event.args,
127
- });
128
- observer.onBefore({
129
- tool: event.tool,
130
- args: event.args,
131
- sessionId: event.sessionId,
132
- callID: event.callId,
133
- projectId: null,
134
- }, {});
135
- return;
136
- }
137
- case "tool.after": {
138
- const cached = callCache.get(event.callId);
139
- const tool = cached?.tool ?? "unknown";
140
- const args = cached?.args ?? {};
141
- const stderr = event.stderr ?? "";
142
- const stdout = event.stdout ?? "";
143
- observer.onAfter({
144
- tool,
145
- args,
146
- sessionId: event.sessionId,
147
- callID: event.callId,
148
- projectId: null,
149
- }, { success: event.success, stdout, stderr, exitCode: event.exitCode });
150
- if (!event.success) {
151
- await reflector.invoke({
152
- toolName: tool,
153
- argsSummary: observer.summarizeArgs(args),
154
- stderr,
155
- stdout,
156
- exitCode: event.exitCode,
157
- errorType: observer.inferErrorType(stderr, stdout, event.exitCode),
158
- sessionId: event.sessionId,
159
- callID: event.callId,
160
- projectId: null,
161
- });
162
- }
163
- else {
164
- causalChain.onSuccess(tool, args, null, event.sessionId);
165
- }
166
- return;
167
- }
168
- case "system.transform": {
169
- const query = resolveQuery(event.sessionId);
170
- if (!query)
171
- return;
172
- const output = { system: [] };
173
- injector.onSystemTransform({
174
- sessionID: event.sessionId,
175
- messages: [{ role: "user", content: query }],
176
- }, output);
177
- return;
178
- }
179
- case "compacting": {
180
- const query = resolveQuery(event.sessionId);
181
- if (!query)
182
- return;
183
- const output = { context: [] };
184
- injector.onCompacting({
185
- sessionID: event.sessionId,
186
- messages: [{ role: "user", content: query }],
187
- }, output);
188
- return;
189
- }
190
- case "session.idle": {
191
- ledger.settle(event.sessionId);
192
- archiver.run();
193
- metrics.flush();
194
- return;
195
- }
196
- }
197
- }
198
- }
199
- function totalMemories(store) {
200
- const row = store.prepare("SELECT COUNT(*) AS n FROM memories").get();
201
- return row.n ?? 0;
202
- }
@@ -1,12 +0,0 @@
1
- export interface SqliteStatement {
2
- get(...params: unknown[]): unknown;
3
- all(...params: unknown[]): unknown[];
4
- run(...params: unknown[]): void;
5
- }
6
- export interface SqliteAdapter {
7
- prepare(sql: string): SqliteStatement;
8
- transaction<T>(fn: () => T): () => T;
9
- exec(sql: string): void;
10
- close(): void;
11
- }
12
- export declare function createDatabase(path: string): SqliteAdapter;
@@ -1,81 +0,0 @@
1
- import { createRequire } from "node:module";
2
- import { fileURLToPath } from "node:url";
3
- const localRequire = createRequire(typeof import.meta.url === "string"
4
- ? import.meta.url
5
- : fileURLToPath(`file://${process.cwd()}/`));
6
- function detectRuntime() {
7
- if (typeof globalThis.Bun !== "undefined") {
8
- return "bun";
9
- }
10
- return "node";
11
- }
12
- function loadBunDatabase(path) {
13
- const mod = localRequire("bun:sqlite");
14
- return new mod.Database(path);
15
- }
16
- /**
17
- * Wrapper sobre `node:sqlite` (DatabaseSync, estable en Node 24+).
18
- * API equivalente a better-sqlite3 excepto `transaction`, que implementamos
19
- * manualmente con BEGIN/COMMIT/ROLLBACK.
20
- */
21
- class NodeSqliteAdapter {
22
- db;
23
- constructor(db) {
24
- this.db = db;
25
- }
26
- prepare(sql) {
27
- return this.db.prepare(sql);
28
- }
29
- exec(sql) {
30
- this.db.exec(sql);
31
- }
32
- close() {
33
- this.db.close();
34
- }
35
- transaction(fn) {
36
- return () => {
37
- this.db.exec("BEGIN");
38
- try {
39
- const result = fn();
40
- this.db.exec("COMMIT");
41
- return result;
42
- }
43
- catch (err) {
44
- try {
45
- this.db.exec("ROLLBACK");
46
- }
47
- catch {
48
- // ignore rollback errors
49
- }
50
- throw err;
51
- }
52
- };
53
- }
54
- }
55
- function loadNodeSqliteDatabase(path) {
56
- const mod = localRequire("node:sqlite");
57
- return new NodeSqliteAdapter(new mod.DatabaseSync(path));
58
- }
59
- function loadBetterSqliteDatabase(path) {
60
- const D = localRequire("better-sqlite3");
61
- const Ctor = "default" in D ? D.default : D;
62
- return new Ctor(path);
63
- }
64
- function loadNodeDatabase(path) {
65
- // 1) Prefer node:sqlite (built-in, sin binarios nativos que descargar).
66
- // Estable en Node 24+ sin flag; en Node 22/23 requiere --experimental-sqlite.
67
- // Si require falla (modulo ausente o flag deshabilitado), cae al fallback.
68
- try {
69
- return loadNodeSqliteDatabase(path);
70
- }
71
- catch {
72
- // 2) Fallback a better-sqlite3 (Node 20 o Node 22/23 sin flag).
73
- return loadBetterSqliteDatabase(path);
74
- }
75
- }
76
- export function createDatabase(path) {
77
- if (detectRuntime() === "bun") {
78
- return loadBunDatabase(path);
79
- }
80
- return loadNodeDatabase(path);
81
- }
@@ -1 +0,0 @@
1
- export declare function toMs(legacyValue: string | null | undefined, msValue: number | null | undefined): number | null;
@@ -1,16 +0,0 @@
1
- // v1.1.0 (K11-003/K11-004 / plan §5.2, D11-01) — millisecond helper.
2
- // Readers prefer _ms and fall back to legacy second-granularity column.
3
- // The helper is the single implementation imported by InjectionLedger and
4
- // CausalChain (moved here in K11-004 to avoid duplication).
5
- export function toMs(legacyValue, msValue) {
6
- if (typeof msValue === "number" && !Number.isNaN(msValue))
7
- return msValue;
8
- if (!legacyValue)
9
- return null;
10
- // SQLite datetime('now') is 'YYYY-MM-DD HH:MM:SS' UTC
11
- const iso = legacyValue.includes("T")
12
- ? legacyValue
13
- : `${legacyValue.replace(" ", "T")}Z`;
14
- const n = Date.parse(iso);
15
- return Number.isNaN(n) ? null : n;
16
- }
@@ -1 +0,0 @@
1
- export declare function uuidv7(): string;
@@ -1,50 +0,0 @@
1
- import { randomBytes } from "node:crypto";
2
- // UUID v7 generator — timestamp-ordered IDs.
3
- // Format: xxxxxxxx-xxxx-7xxx-yxxx-xxxxxxxxxxxx
4
- // First 48 bits: Unix timestamp (ms). Version nibble set to 7.
5
- // Variant nibble starts with binary 10.
6
- let lastTs = 0;
7
- let lastRandom = Buffer.alloc(10);
8
- function toHex(bytes) {
9
- return bytes.toString("hex");
10
- }
11
- export function uuidv7() {
12
- let ts = Date.now();
13
- if (ts < lastTs)
14
- ts = lastTs;
15
- if (ts === lastTs) {
16
- for (let i = 9; i >= 0; i--) {
17
- if (lastRandom[i] === 0xff) {
18
- lastRandom[i] = 0;
19
- }
20
- else {
21
- lastRandom[i]++;
22
- break;
23
- }
24
- }
25
- }
26
- else {
27
- lastRandom = randomBytes(10);
28
- }
29
- lastTs = ts;
30
- const rand = lastRandom;
31
- const bytes = Buffer.alloc(16);
32
- bytes[0] = Math.floor(ts / 2 ** 40) & 0xff;
33
- bytes[1] = Math.floor(ts / 2 ** 32) & 0xff;
34
- bytes[2] = (ts >>> 24) & 0xff;
35
- bytes[3] = (ts >>> 16) & 0xff;
36
- bytes[4] = (ts >>> 8) & 0xff;
37
- bytes[5] = ts & 0xff;
38
- bytes[6] = 0x70 | (rand[0] & 0x0f);
39
- bytes[7] = rand[1];
40
- bytes[8] = 0x80 | (rand[2] & 0x3f);
41
- bytes[9] = rand[3];
42
- bytes[10] = rand[4];
43
- bytes[11] = rand[5];
44
- bytes[12] = rand[6];
45
- bytes[13] = rand[7];
46
- bytes[14] = rand[8];
47
- bytes[15] = rand[9];
48
- const hex = toHex(bytes);
49
- return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`;
50
- }