@jmtrin/opencode-kevin 1.0.0 → 1.1.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/LICENSE +21 -0
- package/README.md +24 -7
- package/dist/migrations/001_initial.sql +91 -91
- package/dist/migrations/002_indexes.sql +13 -13
- package/dist/migrations/003_v02_signal.sql +57 -57
- package/dist/migrations/004_v03_knowledge.sql +138 -138
- package/dist/migrations/005_v04_signal.sql +57 -57
- package/dist/migrations/006_v05_glassbox.sql +118 -118
- package/dist/migrations/007_v06_pull.sql +144 -144
- package/dist/migrations/012_v11_drift.sql +24 -0
- package/dist/plugin/Archiver.js +2 -17
- package/dist/plugin/CausalChain.js +32 -13
- package/dist/plugin/ConflictDetector.js +7 -29
- package/dist/plugin/Feedback.js +2 -19
- package/dist/plugin/HookLiveness.d.ts +1 -0
- package/dist/plugin/HookLiveness.js +11 -27
- package/dist/plugin/InjectionLedger.js +104 -57
- package/dist/plugin/Materializer.js +1 -88
- package/dist/plugin/MemoryService.d.ts +59 -1
- package/dist/plugin/MemoryService.js +13 -106
- package/dist/plugin/Migrate.js +5 -0
- package/dist/plugin/Retrospective.js +4 -0
- package/dist/plugin/ToolCallObserver.js +18 -5
- package/dist/plugin/columns.d.ts +11 -0
- package/dist/plugin/columns.js +54 -0
- package/dist/plugin/contract.d.ts +8 -0
- package/dist/plugin/contract.js +20 -5
- package/dist/plugin/index.d.ts +1 -1
- package/dist/plugin/index.js +24 -3
- package/dist/plugin/kevin_forget.d.ts +33 -0
- package/dist/plugin/kevin_forget.js +260 -0
- package/dist/plugin/kevin_why.js +1 -18
- package/dist/plugin/metrics.d.ts +1 -1
- package/dist/plugin/metrics.js +4 -0
- package/dist/plugin/query-tokenizer.js +56 -8
- package/dist/plugin/time-ms.d.ts +1 -0
- package/dist/plugin/time-ms.js +16 -0
- package/package.json +2 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 jmtrin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -26,15 +26,19 @@ injects exactly what matters back into the model's context, curates the best
|
|
|
26
26
|
of it into files you control, and shares it across a team through one
|
|
27
27
|
git-friendly file — deterministically, locally, with zero network calls.
|
|
28
28
|
|
|
29
|
-

|
|
30
30
|

|
|
31
|
-

|
|
32
32
|

|
|
33
33
|

|
|
34
34
|

|
|
35
35
|
|
|
36
36
|
</div>
|
|
37
37
|
|
|
38
|
+
<!-- uncomment when docs/demo.gif lands
|
|
39
|
+

|
|
40
|
+
-->
|
|
41
|
+
|
|
38
42
|
> **AI agents are good at solving problems. Kevin makes sure they don't have to solve the same problem twice.**
|
|
39
43
|
|
|
40
44
|
---
|
|
@@ -44,9 +48,10 @@ git-friendly file — deterministically, locally, with zero network calls.
|
|
|
44
48
|
- [Why Kevin](#-why-kevin)
|
|
45
49
|
- [The Kevin loop](#-the-kevin-loop)
|
|
46
50
|
- [Quick start](#-quick-start)
|
|
51
|
+
- [What's new in 1.1.0](#-whats-new-in-110)
|
|
47
52
|
- [What's new in 1.0.0](#-whats-new-in-100)
|
|
48
53
|
- [How it works](#-how-it-works)
|
|
49
|
-
- [The
|
|
54
|
+
- [The 26 tools](#-the-26-tools)
|
|
50
55
|
- [The benchmark: proven, not promised](#-the-benchmark-proven-not-promised)
|
|
51
56
|
- [Curation: from session noise to AGENTS.md](#-curation-from-session-noise-to-agentsmd)
|
|
52
57
|
- [Team sharing: one file, zero servers](#-team-sharing-one-file-zero-servers)
|
|
@@ -136,7 +141,7 @@ npm install @jmtrin/opencode-kevin
|
|
|
136
141
|
|
|
137
142
|
### 2. Restart OpenCode
|
|
138
143
|
|
|
139
|
-
On first boot Kevin migrates its database to schema version `
|
|
144
|
+
On first boot Kevin migrates its database to schema version `012` and starts
|
|
140
145
|
observing. Nothing else is required.
|
|
141
146
|
|
|
142
147
|
### 3. Talk to it
|
|
@@ -163,6 +168,18 @@ kevin_doctor → health report: hooks, deps, perf, verdict
|
|
|
163
168
|
|
|
164
169
|
---
|
|
165
170
|
|
|
171
|
+
## 🆕 What's new in 1.1.0 — "Drift"
|
|
172
|
+
|
|
173
|
+
> 1.1.0 protects what 1.0.0 proved: a published number without a regression gate is marketing.
|
|
174
|
+
|
|
175
|
+
- 🛡️ **Continuous benchmark gate** — `npm run bench:regress` compares the last two `bench/results` against per-metric thresholds (`precision@k` >0.02, `recall` >0.05, `mrr` >0.05 on the `kevin` arm); CI fails when truth drifts.
|
|
176
|
+
- 🗑️ **Lifecycle closure — `kevin_forget`** — dry-run default, `confirm:true` archives locally and publishes a tombstone through the single write path; second identical run is a `noop`.
|
|
177
|
+
- ⏱️ **Millisecond timestamps** — new `_ms` columns with conservative backfill; `settle()` and `CausalChain` now decide sub-second causality.
|
|
178
|
+
- 🧹 **Debt paid** — one `STOP_WORDS` source, one `readOriginCallId`, `ConflictDetector` via `mapRow`, one column-probe registry; every setting has an on-path test.
|
|
179
|
+
- 📜 **Public hygiene** — `LICENSE` (MIT), `homepage` filled, `docs/DISTRIBUTION.md` checklist, `scripts/release-notes.mjs` for `gh release create`, and `<!-- demo -->` slot.
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
166
183
|
## 🆕 What's new in 1.0.0
|
|
167
184
|
|
|
168
185
|
> 1.0.0 is the **proven release**: the surface is frozen as data, the cost is
|
|
@@ -231,7 +248,7 @@ Kevin is an intentionally deterministic pipeline — no LLM in the core loop:
|
|
|
231
248
|
|
|
232
249
|
---
|
|
233
250
|
|
|
234
|
-
## 🧰 The
|
|
251
|
+
## 🧰 The 26 tools
|
|
235
252
|
|
|
236
253
|
<details open>
|
|
237
254
|
<summary><b>🧠 Core memory</b></summary>
|
|
@@ -537,8 +554,8 @@ npm run replay # replay recorded sessions deterministically
|
|
|
537
554
|
Project layout:
|
|
538
555
|
|
|
539
556
|
```
|
|
540
|
-
plugin/
|
|
541
|
-
migrations/ 001 →
|
|
557
|
+
plugin/ 53 modules — Store, MemoryService, Reflector, Perf, Contract, columns, kevin_forget …
|
|
558
|
+
migrations/ 001 → 012 — additive, idempotent, forward-only forever
|
|
542
559
|
scripts/ bench · gen-corpus · verify-pack · verify-install · …
|
|
543
560
|
tests/ unit · integration · e2e · replay fixtures
|
|
544
561
|
bench/ committed corpus + committed results
|
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
-- ============================================================
|
|
2
|
-
-- Kevin 0.1.0 — Schema inicial
|
|
3
|
-
-- ============================================================
|
|
4
|
-
|
|
5
|
-
-- Tabla de versiones para migraciones
|
|
6
|
-
CREATE TABLE IF NOT EXISTS schema_version (
|
|
7
|
-
version TEXT PRIMARY KEY,
|
|
8
|
-
applied_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
-- ============================================================
|
|
12
|
-
-- memories: lecciones aprendidas
|
|
13
|
-
-- ============================================================
|
|
14
|
-
CREATE TABLE IF NOT EXISTS memories (
|
|
15
|
-
id TEXT PRIMARY KEY,
|
|
16
|
-
type TEXT NOT NULL CHECK(type IN ('error', 'pattern', 'decision', 'context')),
|
|
17
|
-
content TEXT NOT NULL,
|
|
18
|
-
scope TEXT NOT NULL DEFAULT 'project' CHECK(scope IN ('project', 'session')),
|
|
19
|
-
relevance_score REAL DEFAULT 0.5,
|
|
20
|
-
source_tool TEXT,
|
|
21
|
-
source_session TEXT,
|
|
22
|
-
metadata TEXT,
|
|
23
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
24
|
-
updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
25
|
-
expires_at TEXT
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
CREATE INDEX IF NOT EXISTS idx_memories_type ON memories(type);
|
|
29
|
-
CREATE INDEX IF NOT EXISTS idx_memories_scope ON memories(scope);
|
|
30
|
-
CREATE INDEX IF NOT EXISTS idx_memories_relevance ON memories(relevance_score DESC);
|
|
31
|
-
CREATE INDEX IF NOT EXISTS idx_memories_created ON memories(created_at);
|
|
32
|
-
|
|
33
|
-
-- FTS5: búsqueda full-text con remoción de diacríticos (mejor para español)
|
|
34
|
-
CREATE VIRTUAL TABLE IF NOT EXISTS memories_fts USING fts5(
|
|
35
|
-
content,
|
|
36
|
-
content='memories',
|
|
37
|
-
tokenize='unicode61 remove_diacritics 1'
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
-- Triggers para mantener FTS5 sincronizado (FTS5 external-content se indexa por rowid)
|
|
41
|
-
CREATE TRIGGER IF NOT EXISTS memories_ai AFTER INSERT ON memories BEGIN
|
|
42
|
-
INSERT INTO memories_fts(rowid, content) VALUES (new.rowid, new.content);
|
|
43
|
-
END;
|
|
44
|
-
|
|
45
|
-
CREATE TRIGGER IF NOT EXISTS memories_ad AFTER DELETE ON memories BEGIN
|
|
46
|
-
INSERT INTO memories_fts(memories_fts, rowid, content) VALUES ('delete', old.rowid, old.content);
|
|
47
|
-
END;
|
|
48
|
-
|
|
49
|
-
CREATE TRIGGER IF NOT EXISTS memories_au AFTER UPDATE ON memories BEGIN
|
|
50
|
-
INSERT INTO memories_fts(memories_fts, rowid, content) VALUES ('delete', old.rowid, old.content);
|
|
51
|
-
INSERT INTO memories_fts(rowid, content) VALUES (new.rowid, new.content);
|
|
52
|
-
END;
|
|
53
|
-
|
|
54
|
-
-- ============================================================
|
|
55
|
-
-- tool_calls: observación de tool calls del agente
|
|
56
|
-
-- ============================================================
|
|
57
|
-
CREATE TABLE IF NOT EXISTS tool_calls (
|
|
58
|
-
id TEXT PRIMARY KEY,
|
|
59
|
-
session_id TEXT NOT NULL,
|
|
60
|
-
ts TEXT NOT NULL DEFAULT (datetime('now')),
|
|
61
|
-
tool TEXT NOT NULL,
|
|
62
|
-
args_summary TEXT,
|
|
63
|
-
success INTEGER NOT NULL CHECK(success IN (0,1)),
|
|
64
|
-
duration_ms INTEGER,
|
|
65
|
-
agent TEXT,
|
|
66
|
-
error_type TEXT,
|
|
67
|
-
metadata TEXT
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
CREATE INDEX IF NOT EXISTS idx_tool_calls_session ON tool_calls(session_id);
|
|
71
|
-
CREATE INDEX IF NOT EXISTS idx_tool_calls_tool ON tool_calls(tool);
|
|
72
|
-
CREATE INDEX IF NOT EXISTS idx_tool_calls_ts ON tool_calls(ts);
|
|
73
|
-
CREATE INDEX IF NOT EXISTS idx_tool_calls_success ON tool_calls(success);
|
|
74
|
-
|
|
75
|
-
-- ============================================================
|
|
76
|
-
-- retrospectives: resúmenes de sesión
|
|
77
|
-
-- ============================================================
|
|
78
|
-
CREATE TABLE IF NOT EXISTS retrospectives (
|
|
79
|
-
id TEXT PRIMARY KEY,
|
|
80
|
-
session_id TEXT NOT NULL,
|
|
81
|
-
ts TEXT NOT NULL DEFAULT (datetime('now')),
|
|
82
|
-
failure_count INTEGER DEFAULT 0,
|
|
83
|
-
success_count INTEGER DEFAULT 0,
|
|
84
|
-
lessons_count INTEGER DEFAULT 0,
|
|
85
|
-
file_path TEXT,
|
|
86
|
-
metadata TEXT
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
-- ============================================================
|
|
90
|
-
-- Seed: versión inicial
|
|
91
|
-
-- ============================================================
|
|
1
|
+
-- ============================================================
|
|
2
|
+
-- Kevin 0.1.0 — Schema inicial
|
|
3
|
+
-- ============================================================
|
|
4
|
+
|
|
5
|
+
-- Tabla de versiones para migraciones
|
|
6
|
+
CREATE TABLE IF NOT EXISTS schema_version (
|
|
7
|
+
version TEXT PRIMARY KEY,
|
|
8
|
+
applied_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
-- ============================================================
|
|
12
|
+
-- memories: lecciones aprendidas
|
|
13
|
+
-- ============================================================
|
|
14
|
+
CREATE TABLE IF NOT EXISTS memories (
|
|
15
|
+
id TEXT PRIMARY KEY,
|
|
16
|
+
type TEXT NOT NULL CHECK(type IN ('error', 'pattern', 'decision', 'context')),
|
|
17
|
+
content TEXT NOT NULL,
|
|
18
|
+
scope TEXT NOT NULL DEFAULT 'project' CHECK(scope IN ('project', 'session')),
|
|
19
|
+
relevance_score REAL DEFAULT 0.5,
|
|
20
|
+
source_tool TEXT,
|
|
21
|
+
source_session TEXT,
|
|
22
|
+
metadata TEXT,
|
|
23
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
24
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
25
|
+
expires_at TEXT
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
CREATE INDEX IF NOT EXISTS idx_memories_type ON memories(type);
|
|
29
|
+
CREATE INDEX IF NOT EXISTS idx_memories_scope ON memories(scope);
|
|
30
|
+
CREATE INDEX IF NOT EXISTS idx_memories_relevance ON memories(relevance_score DESC);
|
|
31
|
+
CREATE INDEX IF NOT EXISTS idx_memories_created ON memories(created_at);
|
|
32
|
+
|
|
33
|
+
-- FTS5: búsqueda full-text con remoción de diacríticos (mejor para español)
|
|
34
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS memories_fts USING fts5(
|
|
35
|
+
content,
|
|
36
|
+
content='memories',
|
|
37
|
+
tokenize='unicode61 remove_diacritics 1'
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
-- Triggers para mantener FTS5 sincronizado (FTS5 external-content se indexa por rowid)
|
|
41
|
+
CREATE TRIGGER IF NOT EXISTS memories_ai AFTER INSERT ON memories BEGIN
|
|
42
|
+
INSERT INTO memories_fts(rowid, content) VALUES (new.rowid, new.content);
|
|
43
|
+
END;
|
|
44
|
+
|
|
45
|
+
CREATE TRIGGER IF NOT EXISTS memories_ad AFTER DELETE ON memories BEGIN
|
|
46
|
+
INSERT INTO memories_fts(memories_fts, rowid, content) VALUES ('delete', old.rowid, old.content);
|
|
47
|
+
END;
|
|
48
|
+
|
|
49
|
+
CREATE TRIGGER IF NOT EXISTS memories_au AFTER UPDATE ON memories BEGIN
|
|
50
|
+
INSERT INTO memories_fts(memories_fts, rowid, content) VALUES ('delete', old.rowid, old.content);
|
|
51
|
+
INSERT INTO memories_fts(rowid, content) VALUES (new.rowid, new.content);
|
|
52
|
+
END;
|
|
53
|
+
|
|
54
|
+
-- ============================================================
|
|
55
|
+
-- tool_calls: observación de tool calls del agente
|
|
56
|
+
-- ============================================================
|
|
57
|
+
CREATE TABLE IF NOT EXISTS tool_calls (
|
|
58
|
+
id TEXT PRIMARY KEY,
|
|
59
|
+
session_id TEXT NOT NULL,
|
|
60
|
+
ts TEXT NOT NULL DEFAULT (datetime('now')),
|
|
61
|
+
tool TEXT NOT NULL,
|
|
62
|
+
args_summary TEXT,
|
|
63
|
+
success INTEGER NOT NULL CHECK(success IN (0,1)),
|
|
64
|
+
duration_ms INTEGER,
|
|
65
|
+
agent TEXT,
|
|
66
|
+
error_type TEXT,
|
|
67
|
+
metadata TEXT
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
CREATE INDEX IF NOT EXISTS idx_tool_calls_session ON tool_calls(session_id);
|
|
71
|
+
CREATE INDEX IF NOT EXISTS idx_tool_calls_tool ON tool_calls(tool);
|
|
72
|
+
CREATE INDEX IF NOT EXISTS idx_tool_calls_ts ON tool_calls(ts);
|
|
73
|
+
CREATE INDEX IF NOT EXISTS idx_tool_calls_success ON tool_calls(success);
|
|
74
|
+
|
|
75
|
+
-- ============================================================
|
|
76
|
+
-- retrospectives: resúmenes de sesión
|
|
77
|
+
-- ============================================================
|
|
78
|
+
CREATE TABLE IF NOT EXISTS retrospectives (
|
|
79
|
+
id TEXT PRIMARY KEY,
|
|
80
|
+
session_id TEXT NOT NULL,
|
|
81
|
+
ts TEXT NOT NULL DEFAULT (datetime('now')),
|
|
82
|
+
failure_count INTEGER DEFAULT 0,
|
|
83
|
+
success_count INTEGER DEFAULT 0,
|
|
84
|
+
lessons_count INTEGER DEFAULT 0,
|
|
85
|
+
file_path TEXT,
|
|
86
|
+
metadata TEXT
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
-- ============================================================
|
|
90
|
+
-- Seed: versión inicial
|
|
91
|
+
-- ============================================================
|
|
92
92
|
INSERT OR IGNORE INTO schema_version (version) VALUES ('001');
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
-- ============================================================
|
|
2
|
-
-- Kevin 0.1.1 — Migration 002: indexes adicionales
|
|
3
|
-
-- ============================================================
|
|
4
|
-
|
|
5
|
-
-- F#29: uniqueness on retrospectives.session_id
|
|
6
|
-
-- Prevents duplicate retrospective rows under concurrent session.idle events.
|
|
7
|
-
CREATE UNIQUE INDEX IF NOT EXISTS idx_retrospectives_session
|
|
8
|
-
ON retrospectives(session_id);
|
|
9
|
-
|
|
10
|
-
-- F#31: index on memories.expires_at
|
|
11
|
-
-- Every query/queryRelevant/loadAll filters WHERE (expires_at IS NULL OR expires_at > datetime('now')).
|
|
12
|
-
-- Without this index the filter is a linear scan on large tables.
|
|
13
|
-
CREATE INDEX IF NOT EXISTS idx_memories_expires
|
|
1
|
+
-- ============================================================
|
|
2
|
+
-- Kevin 0.1.1 — Migration 002: indexes adicionales
|
|
3
|
+
-- ============================================================
|
|
4
|
+
|
|
5
|
+
-- F#29: uniqueness on retrospectives.session_id
|
|
6
|
+
-- Prevents duplicate retrospective rows under concurrent session.idle events.
|
|
7
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_retrospectives_session
|
|
8
|
+
ON retrospectives(session_id);
|
|
9
|
+
|
|
10
|
+
-- F#31: index on memories.expires_at
|
|
11
|
+
-- Every query/queryRelevant/loadAll filters WHERE (expires_at IS NULL OR expires_at > datetime('now')).
|
|
12
|
+
-- Without this index the filter is a linear scan on large tables.
|
|
13
|
+
CREATE INDEX IF NOT EXISTS idx_memories_expires
|
|
14
14
|
ON memories(expires_at);
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
-- ============================================================
|
|
2
|
-
-- Kevin 0.2.0 — Migration 003: Signal Quality (additive)
|
|
3
|
-
-- ============================================================
|
|
4
|
-
-- Backward-compatible, additive only. All new columns are
|
|
5
|
-
-- nullable or carry a NOT NULL DEFAULT so legacy rows keep
|
|
6
|
-
-- working without a destructive rebuild. The partial UNIQUE
|
|
7
|
-
-- index excludes NULL fingerprints so legacy error memories
|
|
8
|
-
-- do not collide. The schema_version table (created by 001)
|
|
9
|
-
-- guarantees this file runs at most once per DB.
|
|
10
|
-
-- ============================================================
|
|
11
|
-
|
|
12
|
-
-- 1. memories: Signal Quality columns.
|
|
13
|
-
-- project_id — first-class scoping dimension (D2-11).
|
|
14
|
-
-- fingerprint — stable hash of normalized error content, salted by project_id (D2-14).
|
|
15
|
-
-- origin — distinguishes reflector-sourced vs agent-sourced memories (D2-06),
|
|
16
|
-
-- with a CHECK enum and DEFAULT 'agent' so legacy rows backfill cleanly.
|
|
17
|
-
ALTER TABLE memories ADD COLUMN project_id TEXT;
|
|
18
|
-
ALTER TABLE memories ADD COLUMN fingerprint TEXT;
|
|
19
|
-
ALTER TABLE memories ADD COLUMN origin TEXT NOT NULL DEFAULT 'agent'
|
|
20
|
-
CHECK(origin IN ('reflector', 'agent', 'pattern', 'retrospective'));
|
|
21
|
-
|
|
22
|
-
-- 2. tool_calls: same scoping/fingerprint columns for dedup and PatternMiner.
|
|
23
|
-
ALTER TABLE tool_calls ADD COLUMN project_id TEXT;
|
|
24
|
-
ALTER TABLE tool_calls ADD COLUMN fingerprint TEXT;
|
|
25
|
-
|
|
26
|
-
-- 3. Partial UNIQUE: one reflector-sourced error memory per (project_id, fingerprint).
|
|
27
|
-
-- NULL fingerprints are excluded (no dedup for non-error memories or legacy rows).
|
|
28
|
-
CREATE UNIQUE INDEX IF NOT EXISTS uq_memories_error_fp
|
|
29
|
-
ON memories (project_id, fingerprint)
|
|
30
|
-
WHERE type = 'error' AND fingerprint IS NOT NULL AND origin = 'reflector';
|
|
31
|
-
|
|
32
|
-
-- 4. kevin_metrics: seeded counters surfaced by kevin_status (D2-07 / K2-004).
|
|
33
|
-
CREATE TABLE IF NOT EXISTS kevin_metrics (
|
|
34
|
-
key TEXT PRIMARY KEY,
|
|
35
|
-
value INTEGER NOT NULL DEFAULT 0,
|
|
36
|
-
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
INSERT OR IGNORE INTO kevin_metrics (key, value) VALUES
|
|
40
|
-
('tokens_injected_pre_prompt', 0),
|
|
41
|
-
('tokens_injected_compacting', 0),
|
|
42
|
-
('reflections_throttled', 0),
|
|
43
|
-
('duplicate_suppressions', 0),
|
|
44
|
-
('tool_calls_deduped', 0),
|
|
45
|
-
('patterns_mined', 0);
|
|
46
|
-
|
|
47
|
-
-- 5. kevin_settings: opt-in feature flags (PatternMiner off, tool_calls dedup off).
|
|
48
|
-
CREATE TABLE IF NOT EXISTS kevin_settings (
|
|
49
|
-
key TEXT PRIMARY KEY,
|
|
50
|
-
value TEXT NOT NULL
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
INSERT OR IGNORE INTO kevin_settings (key, value) VALUES
|
|
54
|
-
('patternminer_enabled', '0'),
|
|
55
|
-
('tool_calls_dedup_enabled', '0');
|
|
56
|
-
|
|
57
|
-
-- 6. Seed version 003.
|
|
1
|
+
-- ============================================================
|
|
2
|
+
-- Kevin 0.2.0 — Migration 003: Signal Quality (additive)
|
|
3
|
+
-- ============================================================
|
|
4
|
+
-- Backward-compatible, additive only. All new columns are
|
|
5
|
+
-- nullable or carry a NOT NULL DEFAULT so legacy rows keep
|
|
6
|
+
-- working without a destructive rebuild. The partial UNIQUE
|
|
7
|
+
-- index excludes NULL fingerprints so legacy error memories
|
|
8
|
+
-- do not collide. The schema_version table (created by 001)
|
|
9
|
+
-- guarantees this file runs at most once per DB.
|
|
10
|
+
-- ============================================================
|
|
11
|
+
|
|
12
|
+
-- 1. memories: Signal Quality columns.
|
|
13
|
+
-- project_id — first-class scoping dimension (D2-11).
|
|
14
|
+
-- fingerprint — stable hash of normalized error content, salted by project_id (D2-14).
|
|
15
|
+
-- origin — distinguishes reflector-sourced vs agent-sourced memories (D2-06),
|
|
16
|
+
-- with a CHECK enum and DEFAULT 'agent' so legacy rows backfill cleanly.
|
|
17
|
+
ALTER TABLE memories ADD COLUMN project_id TEXT;
|
|
18
|
+
ALTER TABLE memories ADD COLUMN fingerprint TEXT;
|
|
19
|
+
ALTER TABLE memories ADD COLUMN origin TEXT NOT NULL DEFAULT 'agent'
|
|
20
|
+
CHECK(origin IN ('reflector', 'agent', 'pattern', 'retrospective'));
|
|
21
|
+
|
|
22
|
+
-- 2. tool_calls: same scoping/fingerprint columns for dedup and PatternMiner.
|
|
23
|
+
ALTER TABLE tool_calls ADD COLUMN project_id TEXT;
|
|
24
|
+
ALTER TABLE tool_calls ADD COLUMN fingerprint TEXT;
|
|
25
|
+
|
|
26
|
+
-- 3. Partial UNIQUE: one reflector-sourced error memory per (project_id, fingerprint).
|
|
27
|
+
-- NULL fingerprints are excluded (no dedup for non-error memories or legacy rows).
|
|
28
|
+
CREATE UNIQUE INDEX IF NOT EXISTS uq_memories_error_fp
|
|
29
|
+
ON memories (project_id, fingerprint)
|
|
30
|
+
WHERE type = 'error' AND fingerprint IS NOT NULL AND origin = 'reflector';
|
|
31
|
+
|
|
32
|
+
-- 4. kevin_metrics: seeded counters surfaced by kevin_status (D2-07 / K2-004).
|
|
33
|
+
CREATE TABLE IF NOT EXISTS kevin_metrics (
|
|
34
|
+
key TEXT PRIMARY KEY,
|
|
35
|
+
value INTEGER NOT NULL DEFAULT 0,
|
|
36
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
INSERT OR IGNORE INTO kevin_metrics (key, value) VALUES
|
|
40
|
+
('tokens_injected_pre_prompt', 0),
|
|
41
|
+
('tokens_injected_compacting', 0),
|
|
42
|
+
('reflections_throttled', 0),
|
|
43
|
+
('duplicate_suppressions', 0),
|
|
44
|
+
('tool_calls_deduped', 0),
|
|
45
|
+
('patterns_mined', 0);
|
|
46
|
+
|
|
47
|
+
-- 5. kevin_settings: opt-in feature flags (PatternMiner off, tool_calls dedup off).
|
|
48
|
+
CREATE TABLE IF NOT EXISTS kevin_settings (
|
|
49
|
+
key TEXT PRIMARY KEY,
|
|
50
|
+
value TEXT NOT NULL
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
INSERT OR IGNORE INTO kevin_settings (key, value) VALUES
|
|
54
|
+
('patternminer_enabled', '0'),
|
|
55
|
+
('tool_calls_dedup_enabled', '0');
|
|
56
|
+
|
|
57
|
+
-- 6. Seed version 003.
|
|
58
58
|
INSERT OR IGNORE INTO schema_version (version) VALUES ('003');
|