@jmtrin/opencode-kevin 0.6.0 → 0.7.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 (52) hide show
  1. package/README.md +582 -580
  2. package/dist/migrations/001_initial.sql +91 -91
  3. package/dist/migrations/003_v02_signal.sql +57 -57
  4. package/dist/migrations/004_v03_knowledge.sql +138 -138
  5. package/dist/migrations/005_v04_signal.sql +57 -57
  6. package/dist/migrations/006_v05_glassbox.sql +118 -118
  7. package/dist/migrations/007_v06_pull.sql +144 -144
  8. package/dist/migrations/008_v07_truth.sql +124 -0
  9. package/dist/plugin/ConflictDetector.d.ts +35 -0
  10. package/dist/plugin/ConflictDetector.js +283 -0
  11. package/dist/plugin/ConflictDetector.js.map +1 -0
  12. package/dist/plugin/ConventionMiner.d.ts +35 -0
  13. package/dist/plugin/ConventionMiner.js +243 -0
  14. package/dist/plugin/ConventionMiner.js.map +1 -0
  15. package/dist/plugin/Curator.js +45 -14
  16. package/dist/plugin/Curator.js.map +1 -1
  17. package/dist/plugin/MemoryService.d.ts +18 -0
  18. package/dist/plugin/MemoryService.js +92 -2
  19. package/dist/plugin/MemoryService.js.map +1 -1
  20. package/dist/plugin/Migrate.js +31 -2
  21. package/dist/plugin/Migrate.js.map +1 -1
  22. package/dist/plugin/Reflector.js +13 -0
  23. package/dist/plugin/Reflector.js.map +1 -1
  24. package/dist/plugin/RepoTruth.d.ts +80 -0
  25. package/dist/plugin/RepoTruth.js +600 -0
  26. package/dist/plugin/RepoTruth.js.map +1 -0
  27. package/dist/plugin/Retrospective.js +8 -0
  28. package/dist/plugin/Retrospective.js.map +1 -1
  29. package/dist/plugin/index.d.ts +7 -2
  30. package/dist/plugin/index.js +135 -2
  31. package/dist/plugin/index.js.map +1 -1
  32. package/dist/plugin/kevin_audit.d.ts +41 -1
  33. package/dist/plugin/kevin_audit.js +98 -3
  34. package/dist/plugin/kevin_audit.js.map +1 -1
  35. package/dist/plugin/kevin_conflicts.d.ts +9 -0
  36. package/dist/plugin/kevin_conflicts.js +51 -0
  37. package/dist/plugin/kevin_conflicts.js.map +1 -0
  38. package/dist/plugin/kevin_facts.d.ts +42 -0
  39. package/dist/plugin/kevin_facts.js +37 -0
  40. package/dist/plugin/kevin_facts.js.map +1 -0
  41. package/dist/plugin/metrics.d.ts +3 -3
  42. package/dist/plugin/metrics.js +12 -2
  43. package/dist/plugin/metrics.js.map +1 -1
  44. package/dist/plugin/replay-types.d.ts +2 -2
  45. package/migrations/001_initial.sql +91 -91
  46. package/migrations/003_v02_signal.sql +57 -57
  47. package/migrations/004_v03_knowledge.sql +138 -138
  48. package/migrations/005_v04_signal.sql +57 -57
  49. package/migrations/006_v05_glassbox.sql +118 -118
  50. package/migrations/007_v06_pull.sql +144 -144
  51. package/migrations/008_v07_truth.sql +124 -0
  52. package/package.json +3 -2
@@ -1,57 +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');
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');
@@ -1,118 +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');
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');
@@ -1,145 +1,145 @@
1
- -- ============================================================================
2
- -- 007_v06_pull.sql — v0.6.0 "Pull"
3
- --
4
- -- Distribution: curated artifacts instead of a per-prompt token tax.
5
- --
6
- -- Section 1: curation_proposals — the persisted human decision record.
7
- -- Section 2: artifact_writes — the disk audit trail, including refusals.
8
- -- Section 3: memories curation + inferability columns.
9
- -- Section 4: metric seeds.
10
- -- Section 5: setting seeds.
11
- -- Section 6: conditional push-budget demotion.
12
- -- Section 7: schema_version.
13
- --
14
- -- Additive only. Every CHECK constraint introduced here is on a NEW table;
15
- -- no existing constraint is widened, so unlike migration 006 there is no
16
- -- table rebuild in this file.
17
- -- ============================================================================
18
-
19
- -- ---------------------------------------------------------------------------
20
- -- 1. curation_proposals — one row per proposed artifact change.
21
- --
22
- -- This table is the "explicit human decision between generation and
23
- -- application" of Principle 22. `kevin_propose` writes 'pending' rows and
24
- -- nothing else; `kevin_approve` moves them to 'approved' → 'applied' or to
25
- -- 'rejected'. Rows are never deleted: rejection history is the evidence
26
- -- base for roadmap kill criterion K4 ("proposals rejected more often than
27
- -- approved"), which is uncheckable if rejections are discarded.
28
- --
29
- -- memory_id has no REFERENCES clause. Store sets PRAGMA foreign_keys = ON,
30
- -- and a hard FK would block deleting a memory that a historical proposal
31
- -- once mentioned — the same reasoning as superseded_by in migration 006.
32
- -- ---------------------------------------------------------------------------
33
- CREATE TABLE IF NOT EXISTS curation_proposals (
34
- id TEXT PRIMARY KEY,
35
- project_id TEXT NOT NULL,
36
- memory_id TEXT NOT NULL,
37
- kind TEXT NOT NULL CHECK (kind IN ('agents_md','skill','reference')),
38
- target_path TEXT NOT NULL,
39
- proposed_text TEXT NOT NULL,
40
- diff TEXT NOT NULL,
41
- status TEXT NOT NULL DEFAULT 'pending'
42
- CHECK (status IN ('pending','approved','rejected','applied','superseded')),
43
- created_at TEXT NOT NULL DEFAULT (datetime('now')),
44
- decided_at TEXT,
45
- applied_at TEXT
46
- );
47
- CREATE INDEX IF NOT EXISTS idx_proposals_status ON curation_proposals(status);
48
- CREATE INDEX IF NOT EXISTS idx_proposals_memory ON curation_proposals(memory_id);
49
- CREATE INDEX IF NOT EXISTS idx_proposals_project ON curation_proposals(project_id);
50
-
51
- -- ---------------------------------------------------------------------------
52
- -- 2. artifact_writes — the append-only audit trail for every disk operation.
53
- --
54
- -- A row is written for EVERY ArtifactWriter.apply() call, including
55
- -- outcome='noop' and outcome='refused'. A refusal that leaves no trace is
56
- -- indistinguishable from a write that never happened, and the whole point
57
- -- of §5.1 rule 3 is that a refusal is a reportable event.
58
- --
59
- -- hash_before / hash_after are SHA-256 of the full file contents, not of
60
- -- the marker block. That is what makes rule 4 (bytes outside the markers
61
- -- are byte-identical) auditable after the fact rather than only at test
62
- -- time.
63
- -- ---------------------------------------------------------------------------
64
- CREATE TABLE IF NOT EXISTS artifact_writes (
65
- id TEXT PRIMARY KEY,
66
- proposal_id TEXT,
67
- project_id TEXT NOT NULL,
68
- path TEXT NOT NULL,
69
- bytes_before INTEGER,
70
- bytes_after INTEGER,
71
- hash_before TEXT,
72
- hash_after TEXT,
73
- outcome TEXT NOT NULL CHECK (outcome IN ('written','noop','refused')),
74
- reason TEXT,
75
- wrote_at TEXT NOT NULL DEFAULT (datetime('now'))
76
- );
77
- CREATE INDEX IF NOT EXISTS idx_artifact_writes_path ON artifact_writes(path);
78
-
79
- -- ---------------------------------------------------------------------------
80
- -- 3. memories: curation state and inferability.
81
- --
82
- -- curated / curated_at record that a memory has already been published,
83
- -- so the Curator does not re-propose it on every session idle.
84
- --
85
- -- inferable is deliberately NULLABLE with no default. Three states are
86
- -- needed, not two: 1 = inferable (a self-describing diagnostic the model
87
- -- resolves for free), 0 = non-inferable (project truth), NULL = unknown
88
- -- (not yet classified, or classified as 'unknown'). The Curator predicate
89
- -- is `inferable != 1`, so NULL rows stay eligible — an unclassified memory
90
- -- must not be silently withheld from curation.
91
- -- ---------------------------------------------------------------------------
92
- ALTER TABLE memories ADD COLUMN curated INTEGER NOT NULL DEFAULT 0;
93
- ALTER TABLE memories ADD COLUMN curated_at TEXT;
94
- ALTER TABLE memories ADD COLUMN inferable INTEGER;
95
-
96
- CREATE INDEX IF NOT EXISTS idx_memories_curated ON memories(curated);
97
- CREATE INDEX IF NOT EXISTS idx_memories_inferable ON memories(inferable);
98
-
99
- -- ---------------------------------------------------------------------------
100
- -- 4. Metric seeds. Order matches the additions to METRIC_KEYS in metrics.ts.
101
- -- injections_blocked_confidence is the sixth member of the v0.5 blocked
102
- -- family and MUST be counted like the other five (Principle 16).
103
- -- ---------------------------------------------------------------------------
104
- INSERT OR IGNORE INTO kevin_metrics (key, value) VALUES
105
- ('proposals_created', 0),
106
- ('proposals_approved', 0),
107
- ('proposals_rejected', 0),
108
- ('artifact_writes_total', 0),
109
- ('artifact_writes_noop', 0),
110
- ('injections_blocked_confidence', 0);
111
-
112
- -- ---------------------------------------------------------------------------
113
- -- 5. Setting seeds. Values are TEXT, always. Read them with an explicit
114
- -- string comparison or an explicit Number() parse — never `=== 1`.
115
- -- (That exact mistake kept cross_project_enabled unreachable for the
116
- -- whole of v0.3.0.)
117
- --
118
- -- skill_emission_enabled and reference_emission_enabled default to '0':
119
- -- the pull channels ship OFF and are opted into, because they depend on a
120
- -- v2 domain Kevin does not pin.
121
- -- ---------------------------------------------------------------------------
122
- INSERT OR IGNORE INTO kevin_settings (key, value) VALUES
123
- ('curation_enabled', '1'),
124
- ('agents_md_path', 'AGENTS.md'),
125
- ('skill_emission_enabled', '0'),
126
- ('reference_emission_enabled', '0'),
127
- ('injection_confidence_floor', '0.6');
128
-
129
- -- ---------------------------------------------------------------------------
130
- -- 6. Push-budget demotion.
131
- --
132
- -- Lower the default push budget only where the user has not overridden it.
133
- -- A user who deliberately set 1200 (or 1500, or 200) keeps their value;
134
- -- only an installation still sitting on the v0.5 default of '900' is
135
- -- moved to '400'. An unconditional UPDATE here would silently discard a
136
- -- deliberate configuration choice, which is a worse defect than the token
137
- -- cost it would save.
138
- -- ---------------------------------------------------------------------------
139
- UPDATE kevin_settings SET value = '400'
140
- WHERE key = 'pre_prompt_budget_tokens' AND value = '900';
141
-
142
- -- ---------------------------------------------------------------------------
143
- -- 7. Version marker.
144
- -- ---------------------------------------------------------------------------
1
+ -- ============================================================================
2
+ -- 007_v06_pull.sql — v0.6.0 "Pull"
3
+ --
4
+ -- Distribution: curated artifacts instead of a per-prompt token tax.
5
+ --
6
+ -- Section 1: curation_proposals — the persisted human decision record.
7
+ -- Section 2: artifact_writes — the disk audit trail, including refusals.
8
+ -- Section 3: memories curation + inferability columns.
9
+ -- Section 4: metric seeds.
10
+ -- Section 5: setting seeds.
11
+ -- Section 6: conditional push-budget demotion.
12
+ -- Section 7: schema_version.
13
+ --
14
+ -- Additive only. Every CHECK constraint introduced here is on a NEW table;
15
+ -- no existing constraint is widened, so unlike migration 006 there is no
16
+ -- table rebuild in this file.
17
+ -- ============================================================================
18
+
19
+ -- ---------------------------------------------------------------------------
20
+ -- 1. curation_proposals — one row per proposed artifact change.
21
+ --
22
+ -- This table is the "explicit human decision between generation and
23
+ -- application" of Principle 22. `kevin_propose` writes 'pending' rows and
24
+ -- nothing else; `kevin_approve` moves them to 'approved' → 'applied' or to
25
+ -- 'rejected'. Rows are never deleted: rejection history is the evidence
26
+ -- base for roadmap kill criterion K4 ("proposals rejected more often than
27
+ -- approved"), which is uncheckable if rejections are discarded.
28
+ --
29
+ -- memory_id has no REFERENCES clause. Store sets PRAGMA foreign_keys = ON,
30
+ -- and a hard FK would block deleting a memory that a historical proposal
31
+ -- once mentioned — the same reasoning as superseded_by in migration 006.
32
+ -- ---------------------------------------------------------------------------
33
+ CREATE TABLE IF NOT EXISTS curation_proposals (
34
+ id TEXT PRIMARY KEY,
35
+ project_id TEXT NOT NULL,
36
+ memory_id TEXT NOT NULL,
37
+ kind TEXT NOT NULL CHECK (kind IN ('agents_md','skill','reference')),
38
+ target_path TEXT NOT NULL,
39
+ proposed_text TEXT NOT NULL,
40
+ diff TEXT NOT NULL,
41
+ status TEXT NOT NULL DEFAULT 'pending'
42
+ CHECK (status IN ('pending','approved','rejected','applied','superseded')),
43
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
44
+ decided_at TEXT,
45
+ applied_at TEXT
46
+ );
47
+ CREATE INDEX IF NOT EXISTS idx_proposals_status ON curation_proposals(status);
48
+ CREATE INDEX IF NOT EXISTS idx_proposals_memory ON curation_proposals(memory_id);
49
+ CREATE INDEX IF NOT EXISTS idx_proposals_project ON curation_proposals(project_id);
50
+
51
+ -- ---------------------------------------------------------------------------
52
+ -- 2. artifact_writes — the append-only audit trail for every disk operation.
53
+ --
54
+ -- A row is written for EVERY ArtifactWriter.apply() call, including
55
+ -- outcome='noop' and outcome='refused'. A refusal that leaves no trace is
56
+ -- indistinguishable from a write that never happened, and the whole point
57
+ -- of §5.1 rule 3 is that a refusal is a reportable event.
58
+ --
59
+ -- hash_before / hash_after are SHA-256 of the full file contents, not of
60
+ -- the marker block. That is what makes rule 4 (bytes outside the markers
61
+ -- are byte-identical) auditable after the fact rather than only at test
62
+ -- time.
63
+ -- ---------------------------------------------------------------------------
64
+ CREATE TABLE IF NOT EXISTS artifact_writes (
65
+ id TEXT PRIMARY KEY,
66
+ proposal_id TEXT,
67
+ project_id TEXT NOT NULL,
68
+ path TEXT NOT NULL,
69
+ bytes_before INTEGER,
70
+ bytes_after INTEGER,
71
+ hash_before TEXT,
72
+ hash_after TEXT,
73
+ outcome TEXT NOT NULL CHECK (outcome IN ('written','noop','refused')),
74
+ reason TEXT,
75
+ wrote_at TEXT NOT NULL DEFAULT (datetime('now'))
76
+ );
77
+ CREATE INDEX IF NOT EXISTS idx_artifact_writes_path ON artifact_writes(path);
78
+
79
+ -- ---------------------------------------------------------------------------
80
+ -- 3. memories: curation state and inferability.
81
+ --
82
+ -- curated / curated_at record that a memory has already been published,
83
+ -- so the Curator does not re-propose it on every session idle.
84
+ --
85
+ -- inferable is deliberately NULLABLE with no default. Three states are
86
+ -- needed, not two: 1 = inferable (a self-describing diagnostic the model
87
+ -- resolves for free), 0 = non-inferable (project truth), NULL = unknown
88
+ -- (not yet classified, or classified as 'unknown'). The Curator predicate
89
+ -- is `inferable != 1`, so NULL rows stay eligible — an unclassified memory
90
+ -- must not be silently withheld from curation.
91
+ -- ---------------------------------------------------------------------------
92
+ ALTER TABLE memories ADD COLUMN curated INTEGER NOT NULL DEFAULT 0;
93
+ ALTER TABLE memories ADD COLUMN curated_at TEXT;
94
+ ALTER TABLE memories ADD COLUMN inferable INTEGER;
95
+
96
+ CREATE INDEX IF NOT EXISTS idx_memories_curated ON memories(curated);
97
+ CREATE INDEX IF NOT EXISTS idx_memories_inferable ON memories(inferable);
98
+
99
+ -- ---------------------------------------------------------------------------
100
+ -- 4. Metric seeds. Order matches the additions to METRIC_KEYS in metrics.ts.
101
+ -- injections_blocked_confidence is the sixth member of the v0.5 blocked
102
+ -- family and MUST be counted like the other five (Principle 16).
103
+ -- ---------------------------------------------------------------------------
104
+ INSERT OR IGNORE INTO kevin_metrics (key, value) VALUES
105
+ ('proposals_created', 0),
106
+ ('proposals_approved', 0),
107
+ ('proposals_rejected', 0),
108
+ ('artifact_writes_total', 0),
109
+ ('artifact_writes_noop', 0),
110
+ ('injections_blocked_confidence', 0);
111
+
112
+ -- ---------------------------------------------------------------------------
113
+ -- 5. Setting seeds. Values are TEXT, always. Read them with an explicit
114
+ -- string comparison or an explicit Number() parse — never `=== 1`.
115
+ -- (That exact mistake kept cross_project_enabled unreachable for the
116
+ -- whole of v0.3.0.)
117
+ --
118
+ -- skill_emission_enabled and reference_emission_enabled default to '0':
119
+ -- the pull channels ship OFF and are opted into, because they depend on a
120
+ -- v2 domain Kevin does not pin.
121
+ -- ---------------------------------------------------------------------------
122
+ INSERT OR IGNORE INTO kevin_settings (key, value) VALUES
123
+ ('curation_enabled', '1'),
124
+ ('agents_md_path', 'AGENTS.md'),
125
+ ('skill_emission_enabled', '0'),
126
+ ('reference_emission_enabled', '0'),
127
+ ('injection_confidence_floor', '0.6');
128
+
129
+ -- ---------------------------------------------------------------------------
130
+ -- 6. Push-budget demotion.
131
+ --
132
+ -- Lower the default push budget only where the user has not overridden it.
133
+ -- A user who deliberately set 1200 (or 1500, or 200) keeps their value;
134
+ -- only an installation still sitting on the v0.5 default of '900' is
135
+ -- moved to '400'. An unconditional UPDATE here would silently discard a
136
+ -- deliberate configuration choice, which is a worse defect than the token
137
+ -- cost it would save.
138
+ -- ---------------------------------------------------------------------------
139
+ UPDATE kevin_settings SET value = '400'
140
+ WHERE key = 'pre_prompt_budget_tokens' AND value = '900';
141
+
142
+ -- ---------------------------------------------------------------------------
143
+ -- 7. Version marker.
144
+ -- ---------------------------------------------------------------------------
145
145
  INSERT OR IGNORE INTO schema_version (version) VALUES ('007');