@jmtrin/opencode-kevin 0.3.0 → 0.5.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 (72) hide show
  1. package/README.md +117 -9
  2. package/dist/migrations/005_v04_signal.sql +57 -0
  3. package/dist/migrations/006_v05_glassbox.sql +118 -0
  4. package/dist/plugin/Archiver.d.ts +42 -0
  5. package/dist/plugin/Archiver.js +98 -0
  6. package/dist/plugin/Archiver.js.map +1 -0
  7. package/dist/plugin/CausalChain.d.ts +13 -2
  8. package/dist/plugin/CausalChain.js +83 -13
  9. package/dist/plugin/CausalChain.js.map +1 -1
  10. package/dist/plugin/ContextInjector.d.ts +152 -4
  11. package/dist/plugin/ContextInjector.js +400 -93
  12. package/dist/plugin/ContextInjector.js.map +1 -1
  13. package/dist/plugin/Feedback.d.ts +67 -0
  14. package/dist/plugin/Feedback.js +137 -0
  15. package/dist/plugin/Feedback.js.map +1 -0
  16. package/dist/plugin/InjectionLedger.d.ts +92 -0
  17. package/dist/plugin/InjectionLedger.js +243 -0
  18. package/dist/plugin/InjectionLedger.js.map +1 -0
  19. package/dist/plugin/LessonFixer.d.ts +44 -0
  20. package/dist/plugin/LessonFixer.js +46 -0
  21. package/dist/plugin/LessonFixer.js.map +1 -0
  22. package/dist/plugin/MemoryService.d.ts +81 -1
  23. package/dist/plugin/MemoryService.js +321 -54
  24. package/dist/plugin/MemoryService.js.map +1 -1
  25. package/dist/plugin/Migrate.js +31 -0
  26. package/dist/plugin/Migrate.js.map +1 -1
  27. package/dist/plugin/QualityGate.d.ts +110 -0
  28. package/dist/plugin/QualityGate.js +108 -0
  29. package/dist/plugin/QualityGate.js.map +1 -0
  30. package/dist/plugin/Reflector.d.ts +17 -0
  31. package/dist/plugin/Reflector.js +81 -26
  32. package/dist/plugin/Reflector.js.map +1 -1
  33. package/dist/plugin/Retrospective.js +22 -1
  34. package/dist/plugin/Retrospective.js.map +1 -1
  35. package/dist/plugin/ToolCallObserver.d.ts +1 -0
  36. package/dist/plugin/ToolCallObserver.js +15 -8
  37. package/dist/plugin/ToolCallObserver.js.map +1 -1
  38. package/dist/plugin/confidence.d.ts +8 -0
  39. package/dist/plugin/confidence.js +35 -0
  40. package/dist/plugin/confidence.js.map +1 -0
  41. package/dist/plugin/index.d.ts +5 -0
  42. package/dist/plugin/index.js +368 -44
  43. package/dist/plugin/index.js.map +1 -1
  44. package/dist/plugin/kevin_audit.d.ts +49 -0
  45. package/dist/plugin/kevin_audit.js +141 -0
  46. package/dist/plugin/kevin_audit.js.map +1 -0
  47. package/dist/plugin/kevin_why.d.ts +4 -0
  48. package/dist/plugin/kevin_why.js +72 -35
  49. package/dist/plugin/kevin_why.js.map +1 -1
  50. package/dist/plugin/memory-format.d.ts +12 -0
  51. package/dist/plugin/memory-format.js +45 -5
  52. package/dist/plugin/memory-format.js.map +1 -1
  53. package/dist/plugin/metrics.d.ts +27 -1
  54. package/dist/plugin/metrics.js +61 -0
  55. package/dist/plugin/metrics.js.map +1 -1
  56. package/dist/plugin/okf-export.js +63 -22
  57. package/dist/plugin/okf-export.js.map +1 -1
  58. package/dist/plugin/okf-import.d.ts +4 -1
  59. package/dist/plugin/okf-import.js +45 -12
  60. package/dist/plugin/okf-import.js.map +1 -1
  61. package/dist/plugin/query-tokenizer.d.ts +13 -0
  62. package/dist/plugin/query-tokenizer.js +86 -0
  63. package/dist/plugin/query-tokenizer.js.map +1 -0
  64. package/dist/plugin/replay-types.d.ts +327 -0
  65. package/dist/plugin/replay-types.js +65 -0
  66. package/dist/plugin/replay-types.js.map +1 -0
  67. package/dist/plugin/replay.d.ts +36 -0
  68. package/dist/plugin/replay.js +193 -0
  69. package/dist/plugin/replay.js.map +1 -0
  70. package/migrations/005_v04_signal.sql +57 -0
  71. package/migrations/006_v05_glassbox.sql +118 -0
  72. package/package.json +3 -2
@@ -0,0 +1,57 @@
1
+ -- ============================================================
2
+ -- Kevin 0.4.0 — Migration 005: Signal over Noise (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.
7
+ -- ============================================================
8
+
9
+ -- 1. memories: positive/negative evidence split (D4-03).
10
+ -- recurrence_count — how many times this fingerprint recurred AFTER
11
+ -- injection (negative evidence; lowers confidence).
12
+ -- fix_args — deterministic capture of the linked success call's
13
+ -- args_summary ("Fixed by:" raw material, D4-07).
14
+ -- last_injected_at — timestamp of the most recent injection of this memory.
15
+ ALTER TABLE memories ADD COLUMN recurrence_count INTEGER NOT NULL DEFAULT 0;
16
+ ALTER TABLE memories ADD COLUMN fix_args TEXT;
17
+ ALTER TABLE memories ADD COLUMN last_injected_at TEXT;
18
+
19
+ -- 2. kevin_injections: the injection ledger (D4-04). One row per injected
20
+ -- memory per prompt/compaction, settled at session.idle.
21
+ CREATE TABLE IF NOT EXISTS kevin_injections (
22
+ id TEXT PRIMARY KEY,
23
+ memory_id TEXT NOT NULL,
24
+ fingerprint TEXT NOT NULL,
25
+ session_id TEXT NOT NULL,
26
+ hook TEXT NOT NULL CHECK (hook IN ('pre_prompt', 'compacting')),
27
+ tokens INTEGER NOT NULL,
28
+ injected_at TEXT NOT NULL DEFAULT (datetime('now')),
29
+ outcome TEXT CHECK (outcome IN ('unmeasured', 'effective', 'ineffective'))
30
+ NOT NULL DEFAULT 'unmeasured'
31
+ );
32
+
33
+ -- 2b. Indexes: settlement by session, recurrence lookups by fingerprint,
34
+ -- and outcome rollups for precision_rate.
35
+ CREATE INDEX IF NOT EXISTS idx_injections_fp
36
+ ON kevin_injections(fingerprint);
37
+ CREATE INDEX IF NOT EXISTS idx_injections_session
38
+ ON kevin_injections(session_id);
39
+ CREATE INDEX IF NOT EXISTS idx_injections_outcome
40
+ ON kevin_injections(outcome);
41
+
42
+ -- 3. kevin_metrics: seed new v0.4 counters.
43
+ -- patterns_promoted_new replaces patterns_causal (which was inflated by
44
+ -- idempotent refreshes); the latter stays for compat but is frozen.
45
+ INSERT OR IGNORE INTO kevin_metrics (key, value) VALUES
46
+ ('injections_total', 0),
47
+ ('injections_effective', 0),
48
+ ('injections_ineffective', 0),
49
+ ('patterns_promoted_new', 0);
50
+
51
+ -- 4. kevin_settings: seed new v0.4 flags.
52
+ INSERT OR IGNORE INTO kevin_settings (key, value) VALUES
53
+ ('quality_gate_enabled', '1'),
54
+ ('lesson_snippet_injection','1');
55
+
56
+ -- 5. Seed version 005.
57
+ INSERT OR IGNORE INTO schema_version (version) VALUES ('005');
@@ -0,0 +1,118 @@
1
+ -- ============================================================================
2
+ -- 006_v05_glassbox.sql — v0.5.0 "Glass Box"
3
+ --
4
+ -- Honest measurement, human feedback, lifecycle completion.
5
+ --
6
+ -- Section 1: rebuild kevin_injections to admit a fourth outcome.
7
+ -- Section 2: human feedback storage.
8
+ -- Section 3: memory lifecycle columns.
9
+ -- Section 4: metric seeds.
10
+ -- Section 5: setting seeds.
11
+ -- Section 6: schema_version.
12
+ -- ============================================================================
13
+
14
+ -- ---------------------------------------------------------------------------
15
+ -- 1. kevin_injections: add 'inconclusive'.
16
+ --
17
+ -- SQLite cannot ALTER a CHECK constraint, so the table must be rebuilt.
18
+ -- Migration 004 set this precedent. kevin_injections has no FTS5 triggers,
19
+ -- so unlike 004 this is a straight four-step rebuild.
20
+ --
21
+ -- Existing rows with outcome='effective' are remapped to 'inconclusive'.
22
+ -- This is not data loss: v0.4's 'effective' meant "the error did not recur",
23
+ -- which is the exact definition of the new 'inconclusive' bucket. Rows that
24
+ -- genuinely earned the new 'effective' will be re-settled naturally, and the
25
+ -- post-apply hook re-derives the counters from the table.
26
+ -- ---------------------------------------------------------------------------
27
+ CREATE TABLE IF NOT EXISTS kevin_injections_new (
28
+ id TEXT PRIMARY KEY,
29
+ memory_id TEXT NOT NULL,
30
+ fingerprint TEXT NOT NULL,
31
+ session_id TEXT NOT NULL,
32
+ hook TEXT NOT NULL CHECK (hook IN ('pre_prompt','compacting')),
33
+ tokens INTEGER NOT NULL,
34
+ injected_at TEXT NOT NULL DEFAULT (datetime('now')),
35
+ outcome TEXT NOT NULL DEFAULT 'unmeasured'
36
+ CHECK (outcome IN ('unmeasured','effective','ineffective','inconclusive'))
37
+ );
38
+
39
+ INSERT INTO kevin_injections_new
40
+ (id, memory_id, fingerprint, session_id, hook, tokens, injected_at, outcome)
41
+ SELECT
42
+ id, memory_id, fingerprint, session_id, hook, tokens, injected_at,
43
+ CASE WHEN outcome = 'effective' THEN 'inconclusive' ELSE outcome END
44
+ FROM kevin_injections;
45
+
46
+ DROP TABLE kevin_injections;
47
+ ALTER TABLE kevin_injections_new RENAME TO kevin_injections;
48
+
49
+ CREATE INDEX IF NOT EXISTS idx_injections_fp ON kevin_injections(fingerprint);
50
+ CREATE INDEX IF NOT EXISTS idx_injections_session ON kevin_injections(session_id);
51
+ CREATE INDEX IF NOT EXISTS idx_injections_outcome ON kevin_injections(outcome);
52
+
53
+ -- ---------------------------------------------------------------------------
54
+ -- 2. Human feedback. Append-only audit trail; the hot path reads the
55
+ -- denormalized counters on `memories` (section 3), never this table.
56
+ -- ---------------------------------------------------------------------------
57
+ CREATE TABLE IF NOT EXISTS memory_feedback (
58
+ id TEXT PRIMARY KEY,
59
+ memory_id TEXT NOT NULL,
60
+ verdict TEXT NOT NULL CHECK (verdict IN ('useful','wrong','outdated','ignore')),
61
+ session_id TEXT,
62
+ note TEXT,
63
+ created_at TEXT NOT NULL DEFAULT (datetime('now'))
64
+ );
65
+
66
+ CREATE INDEX IF NOT EXISTS idx_feedback_memory ON memory_feedback(memory_id);
67
+ CREATE INDEX IF NOT EXISTS idx_feedback_created ON memory_feedback(created_at);
68
+
69
+ -- ---------------------------------------------------------------------------
70
+ -- 3. Memory lifecycle and feedback columns.
71
+ --
72
+ -- feedback_positive / feedback_negative are SEPARATE from evidence_count
73
+ -- and recurrence_count by design: human judgement is evidence about the
74
+ -- memory, causal counters are evidence about the world. Mixing them was
75
+ -- the confidence-poisoning defect closed in v0.4.0.
76
+ --
77
+ -- superseded_by has no REFERENCES clause on purpose. Store enables
78
+ -- PRAGMA foreign_keys=ON, and a hard FK would block deletion of a memory
79
+ -- that superseded another.
80
+ -- ---------------------------------------------------------------------------
81
+ ALTER TABLE memories ADD COLUMN feedback_positive INTEGER NOT NULL DEFAULT 0;
82
+ ALTER TABLE memories ADD COLUMN feedback_negative INTEGER NOT NULL DEFAULT 0;
83
+ ALTER TABLE memories ADD COLUMN ignored INTEGER NOT NULL DEFAULT 0;
84
+ ALTER TABLE memories ADD COLUMN superseded_by TEXT;
85
+ ALTER TABLE memories ADD COLUMN archived_at TEXT;
86
+
87
+ CREATE INDEX IF NOT EXISTS idx_memories_ignored ON memories(ignored);
88
+ CREATE INDEX IF NOT EXISTS idx_memories_archived ON memories(archived_at);
89
+
90
+ -- ---------------------------------------------------------------------------
91
+ -- 4. Metric seeds. Order matches the additions to METRIC_KEYS in metrics.ts.
92
+ -- ---------------------------------------------------------------------------
93
+ INSERT OR IGNORE INTO kevin_metrics (key, value) VALUES
94
+ ('injections_inconclusive', 0),
95
+ ('injections_blocked_seen', 0),
96
+ ('injections_blocked_weak', 0),
97
+ ('injections_blocked_recurrence',0),
98
+ ('injections_blocked_stale', 0),
99
+ ('injections_blocked_ignored', 0),
100
+ ('feedback_positive_total', 0),
101
+ ('feedback_negative_total', 0),
102
+ ('memories_archived', 0);
103
+
104
+ -- ---------------------------------------------------------------------------
105
+ -- 5. Setting seeds. Values are TEXT, always. Read them with an explicit
106
+ -- string comparison or an explicit Number() parse — never `=== 1`.
107
+ -- (That exact mistake kept cross_project_enabled unreachable for the
108
+ -- whole of v0.3.0.)
109
+ -- ---------------------------------------------------------------------------
110
+ INSERT OR IGNORE INTO kevin_settings (key, value) VALUES
111
+ ('deterministic_retrieval', '0'),
112
+ ('pre_prompt_budget_tokens', '900'),
113
+ ('archive_after_days', '30');
114
+
115
+ -- ---------------------------------------------------------------------------
116
+ -- 6. Version marker.
117
+ -- ---------------------------------------------------------------------------
118
+ INSERT OR IGNORE INTO schema_version (version) VALUES ('006');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jmtrin/opencode-kevin",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "Kevin — Observa y aprende: capa de aprendizaje para OpenCode",
5
5
  "type": "module",
6
6
  "main": "dist/plugin/index.js",
@@ -21,7 +21,8 @@
21
21
  "typecheck": "tsc --noEmit",
22
22
  "lint": "biome check .",
23
23
  "format": "biome format --write .",
24
- "verify": "node --import tsx scripts/verify-install.ts"
24
+ "verify": "node --import tsx scripts/verify-install.ts",
25
+ "replay": "node --import tsx scripts/replay.ts"
25
26
  },
26
27
  "dependencies": {
27
28
  "@opencode-ai/plugin": "^1.17.6",