@jmtrin/opencode-kevin 0.5.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 (90) hide show
  1. package/README.md +268 -122
  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 +145 -0
  8. package/dist/migrations/008_v07_truth.sql +124 -0
  9. package/dist/plugin/Archiver.js +4 -3
  10. package/dist/plugin/Archiver.js.map +1 -1
  11. package/dist/plugin/ArtifactWriter.d.ts +50 -0
  12. package/dist/plugin/ArtifactWriter.js +240 -0
  13. package/dist/plugin/ArtifactWriter.js.map +1 -0
  14. package/dist/plugin/ConflictDetector.d.ts +35 -0
  15. package/dist/plugin/ConflictDetector.js +283 -0
  16. package/dist/plugin/ConflictDetector.js.map +1 -0
  17. package/dist/plugin/ContextInjector.d.ts +15 -0
  18. package/dist/plugin/ContextInjector.js +46 -11
  19. package/dist/plugin/ContextInjector.js.map +1 -1
  20. package/dist/plugin/ConventionMiner.d.ts +35 -0
  21. package/dist/plugin/ConventionMiner.js +243 -0
  22. package/dist/plugin/ConventionMiner.js.map +1 -0
  23. package/dist/plugin/Curator.d.ts +96 -0
  24. package/dist/plugin/Curator.js +283 -0
  25. package/dist/plugin/Curator.js.map +1 -0
  26. package/dist/plugin/Feedback.js +4 -3
  27. package/dist/plugin/Feedback.js.map +1 -1
  28. package/dist/plugin/Materializer.d.ts +59 -0
  29. package/dist/plugin/Materializer.js +237 -0
  30. package/dist/plugin/Materializer.js.map +1 -0
  31. package/dist/plugin/MemoryService.d.ts +37 -0
  32. package/dist/plugin/MemoryService.js +241 -20
  33. package/dist/plugin/MemoryService.js.map +1 -1
  34. package/dist/plugin/Migrate.js +51 -2
  35. package/dist/plugin/Migrate.js.map +1 -1
  36. package/dist/plugin/QualityGate.d.ts +15 -1
  37. package/dist/plugin/QualityGate.js +12 -0
  38. package/dist/plugin/QualityGate.js.map +1 -1
  39. package/dist/plugin/Reflector.js +13 -0
  40. package/dist/plugin/Reflector.js.map +1 -1
  41. package/dist/plugin/RepoTruth.d.ts +80 -0
  42. package/dist/plugin/RepoTruth.js +600 -0
  43. package/dist/plugin/RepoTruth.js.map +1 -0
  44. package/dist/plugin/Retrospective.d.ts +1 -0
  45. package/dist/plugin/Retrospective.js +20 -1
  46. package/dist/plugin/Retrospective.js.map +1 -1
  47. package/dist/plugin/capabilities.d.ts +15 -0
  48. package/dist/plugin/capabilities.js +42 -0
  49. package/dist/plugin/capabilities.js.map +1 -0
  50. package/dist/plugin/diff.d.ts +8 -0
  51. package/dist/plugin/diff.js +183 -0
  52. package/dist/plugin/diff.js.map +1 -0
  53. package/dist/plugin/index.d.ts +8 -1
  54. package/dist/plugin/index.js +354 -2
  55. package/dist/plugin/index.js.map +1 -1
  56. package/dist/plugin/inferability.d.ts +32 -0
  57. package/dist/plugin/inferability.js +89 -0
  58. package/dist/plugin/inferability.js.map +1 -0
  59. package/dist/plugin/kevin_approve.d.ts +34 -0
  60. package/dist/plugin/kevin_approve.js +50 -0
  61. package/dist/plugin/kevin_approve.js.map +1 -0
  62. package/dist/plugin/kevin_audit.d.ts +87 -1
  63. package/dist/plugin/kevin_audit.js +190 -3
  64. package/dist/plugin/kevin_audit.js.map +1 -1
  65. package/dist/plugin/kevin_conflicts.d.ts +9 -0
  66. package/dist/plugin/kevin_conflicts.js +51 -0
  67. package/dist/plugin/kevin_conflicts.js.map +1 -0
  68. package/dist/plugin/kevin_facts.d.ts +42 -0
  69. package/dist/plugin/kevin_facts.js +37 -0
  70. package/dist/plugin/kevin_facts.js.map +1 -0
  71. package/dist/plugin/kevin_propose.d.ts +23 -0
  72. package/dist/plugin/kevin_propose.js +15 -0
  73. package/dist/plugin/kevin_propose.js.map +1 -0
  74. package/dist/plugin/kevin_publish.d.ts +38 -0
  75. package/dist/plugin/kevin_publish.js +19 -0
  76. package/dist/plugin/kevin_publish.js.map +1 -0
  77. package/dist/plugin/metrics.d.ts +12 -1
  78. package/dist/plugin/metrics.js +49 -0
  79. package/dist/plugin/metrics.js.map +1 -1
  80. package/dist/plugin/replay-types.d.ts +8 -8
  81. package/dist/plugin/replay.js +10 -0
  82. package/dist/plugin/replay.js.map +1 -1
  83. package/migrations/001_initial.sql +91 -91
  84. package/migrations/003_v02_signal.sql +57 -57
  85. package/migrations/004_v03_knowledge.sql +138 -138
  86. package/migrations/005_v04_signal.sql +57 -57
  87. package/migrations/006_v05_glassbox.sql +118 -118
  88. package/migrations/007_v06_pull.sql +145 -0
  89. package/migrations/008_v07_truth.sql +124 -0
  90. package/package.json +3 -2
@@ -1 +1 @@
1
- {"version":3,"file":"Archiver.js","sourceRoot":"","sources":["../../plugin/Archiver.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,QAAQ;IAKF;IACA;IALD,OAAO,CAAiB;IACxB,GAAG,CAAa;IAEjC,YACkB,KAAY,EACZ,aAA4B,EAC7C,OAAwB,EACxB,MAAkB,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE;QAHjB,UAAK,GAAL,KAAK,CAAO;QACZ,kBAAa,GAAb,aAAa,CAAe;QAI7C,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,IAAI,CAAC;QAC/B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACH,GAAG;QACF,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE;YAAE,OAAO,CAAC,CAAC;QACxC,MAAM,IAAI,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACrC,IAAI,IAAI,IAAI,CAAC;YAAE,OAAO,CAAC,CAAC;QAExB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC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AAC,KAAK,CAAC,CAAC;IAC5C,CAAC;CACD;AAED,0EAA0E;AAC1E,2EAA2E;AAC3E,MAAM,mBAAmB,GAAG,IAAI,OAAO,EAAkB,CAAC;AAC1D,SAAS,uBAAuB,CAAC,KAAY;IAC5C,MAAM,MAAM,GAAG,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC9C,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACjC,IAAI,CAAC;QACJ,KAAK,CAAC,OAAO,CAAC,0CAA0C,CAAC,CAAC,GAAG,EAAE,CAAC;QAChE,mBAAmB,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC;IACb,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,KAAK,CAAC;IACd,CAAC;AACF,CAAC;AAED;kEACkE;AAClE,SAAS,eAAe,CAAC,CAAO;IAC/B,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACtD,OAAO,GAAG,CAAC,CAAC,cAAc,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,IAAI,GAAG,CAC9D,CAAC,CAAC,UAAU,EAAE,CACd,IAAI,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC,EAAE,CAAC;AACjF,CAAC"}
@@ -0,0 +1,50 @@
1
+ import type { Store } from "./Store.js";
2
+ import type { Metrics } from "./metrics.js";
3
+ export declare const MARKER_BEGIN = "<!-- kevin:begin \u2014 curated by opencode-kevin, safe to edit -->";
4
+ export declare const MARKER_END = "<!-- kevin:end -->";
5
+ export type WriteOutcome = "written" | "noop" | "refused";
6
+ export interface WritePlan {
7
+ readonly path: string;
8
+ readonly before: string;
9
+ readonly after: string;
10
+ readonly diff: string;
11
+ readonly outcome: WriteOutcome;
12
+ readonly reason?: string;
13
+ readonly hashBefore: string;
14
+ readonly hashAfter: string;
15
+ }
16
+ /**
17
+ * Rule 9 (K6-009 / plan §5.1, D6-02) — three layers applied to the body
18
+ * before splicing:
19
+ * (a) the escaping discipline of `plugin/memory-format.ts`;
20
+ * (b) strip any line containing `kevin:begin` or `kevin:end`, in any
21
+ * casing, anywhere in the line;
22
+ * (c) strip HTML comment terminators (`-->`).
23
+ * Without this, a memory containing a literal `<!-- kevin:end -->` line would
24
+ * close the marker comment early and let subsequent content escape the
25
+ * curated region on the next regeneration — a marker-injection variant of the
26
+ * v0.1.5 prompt-injection defect (plan §3.5).
27
+ */
28
+ export declare function sanitizeArtifactBody(body: string): string;
29
+ /**
30
+ * v0.6.0 (K6-005 / plan §5.1) — the single write path to disk (D6-01).
31
+ *
32
+ * `plan()` is pure: it reads the target file, locates the marker pair, splices
33
+ * the body between the markers and returns a {@link WritePlan}. It performs no
34
+ * writes — rule 1. `apply()` is implemented by K6-007; until then it is a stub
35
+ * that throws, so no caller can accidentally write before the audit trail
36
+ * exists.
37
+ *
38
+ * `projectId` is a constructor argument rather than a per-call argument so that
39
+ * every audit row is attributed without the call site having to remember.
40
+ */
41
+ export declare class ArtifactWriter {
42
+ private readonly store;
43
+ private readonly projectId;
44
+ private readonly metrics;
45
+ constructor(store: Store, projectId: string, metrics?: Metrics | null);
46
+ plan(path: string, body: string): WritePlan;
47
+ apply(plan: WritePlan, proposalId?: string): WriteOutcome;
48
+ private renameTemp;
49
+ private audit;
50
+ }
@@ -0,0 +1,240 @@
1
+ import { createHash } from "node:crypto";
2
+ import { closeSync, fsyncSync, openSync, readFileSync, renameSync, unlinkSync, writeSync, } from "node:fs";
3
+ import { unifiedDiff } from "./diff.js";
4
+ import { uuidv7 } from "./uuid.js";
5
+ // v0.6.0 (K6-005 / plan §5.1, D6-02) — the frozen marker contract. The exact
6
+ // byte sequences are load-bearing: README, v1.0.0 plan C-01 and the round-trip
7
+ // test all depend on them.
8
+ export const MARKER_BEGIN = "<!-- kevin:begin — curated by opencode-kevin, safe to edit -->";
9
+ export const MARKER_END = "<!-- kevin:end -->";
10
+ function sha256(text) {
11
+ return createHash("sha256").update(text, "utf8").digest("hex");
12
+ }
13
+ /**
14
+ * Rule 5 (K6-008 / plan §5.1, D6-02) — the line-ending style comes from the
15
+ * FIRST line ending in the existing file: CRLF if it is CRLF, otherwise LF.
16
+ * A CRLF file whose last line lacks a terminator, and a mixed-ending file,
17
+ * are both resolved by the same first-ending rule, deterministically.
18
+ */
19
+ function detectEol(text) {
20
+ const nl = text.indexOf("\n");
21
+ if (nl === -1)
22
+ return "\n";
23
+ return nl > 0 && text[nl - 1] === "\r" ? "\r\n" : "\n";
24
+ }
25
+ /**
26
+ * Rule 5 (K6-008) — normalize the generated body into the file's line-ending
27
+ * style so a CRLF file stays CRLF everywhere, including inside the block.
28
+ */
29
+ function normalizeEol(body, eol) {
30
+ return body.replace(/\r\n/g, "\n").replace(/\n/g, eol);
31
+ }
32
+ /**
33
+ * Rule 9, layer (a) — the escaping discipline of `plugin/memory-format.ts`
34
+ * (`&`, `<`, `>`) made idempotent: an ampersand that already heads a known
35
+ * entity (`&amp;`, `&lt;`, `&gt;`, `&#NNN;`) is left alone, so sanitizing
36
+ * sanitized output is a fixed point. The round-trip property of the marker
37
+ * block depends on this: a non-idempotent escape would grow `&amp;lt;` on
38
+ * every regeneration (K6-009 / plan §5.1 rule 9).
39
+ */
40
+ function escapeIdempotent(text) {
41
+ return text
42
+ .replace(/&(?!(amp|lt|gt|#\d+);)/g, "&amp;")
43
+ .replace(/</g, "&lt;")
44
+ .replace(/>/g, "&gt;");
45
+ }
46
+ /**
47
+ * Rule 9 (K6-009 / plan §5.1, D6-02) — three layers applied to the body
48
+ * before splicing:
49
+ * (a) the escaping discipline of `plugin/memory-format.ts`;
50
+ * (b) strip any line containing `kevin:begin` or `kevin:end`, in any
51
+ * casing, anywhere in the line;
52
+ * (c) strip HTML comment terminators (`-->`).
53
+ * Without this, a memory containing a literal `<!-- kevin:end -->` line would
54
+ * close the marker comment early and let subsequent content escape the
55
+ * curated region on the next regeneration — a marker-injection variant of the
56
+ * v0.1.5 prompt-injection defect (plan §3.5).
57
+ */
58
+ export function sanitizeArtifactBody(body) {
59
+ const escaped = escapeIdempotent(body);
60
+ const kept = escaped
61
+ .split("\n")
62
+ .filter((line) => !/kevin:begin|kevin:end/i.test(line))
63
+ .join("\n");
64
+ return kept.replace(/-->/g, "");
65
+ }
66
+ /**
67
+ * v0.6.0 (K6-005 / plan §5.1) — the single write path to disk (D6-01).
68
+ *
69
+ * `plan()` is pure: it reads the target file, locates the marker pair, splices
70
+ * the body between the markers and returns a {@link WritePlan}. It performs no
71
+ * writes — rule 1. `apply()` is implemented by K6-007; until then it is a stub
72
+ * that throws, so no caller can accidentally write before the audit trail
73
+ * exists.
74
+ *
75
+ * `projectId` is a constructor argument rather than a per-call argument so that
76
+ * every audit row is attributed without the call site having to remember.
77
+ */
78
+ export class ArtifactWriter {
79
+ store;
80
+ projectId;
81
+ metrics;
82
+ constructor(store, projectId, metrics) {
83
+ this.store = store;
84
+ this.projectId = projectId;
85
+ this.metrics = metrics ?? null;
86
+ }
87
+ plan(path, body) {
88
+ let before;
89
+ try {
90
+ // Read as Buffer, not as utf8 text: readFileSync's text decoding
91
+ // strips a leading BOM, which would silently drop it on the next
92
+ // write. Buffer.toString keeps \uFEFF as a character of `before`.
93
+ before = readFileSync(path).toString("utf8");
94
+ }
95
+ catch (err) {
96
+ if (err instanceof Error && "code" in err && err.code === "ENOENT") {
97
+ before = "";
98
+ }
99
+ else {
100
+ throw err;
101
+ }
102
+ }
103
+ const eol = detectEol(before);
104
+ // Rule 9 — sanitation happens in plan(), before hashing, so the hashes
105
+ // describe what was actually written.
106
+ const bodyEol = normalizeEol(sanitizeArtifactBody(body), eol);
107
+ const firstBegin = before.indexOf(MARKER_BEGIN);
108
+ const firstEnd = before.indexOf(MARKER_END);
109
+ let after;
110
+ let outcome = "written";
111
+ let reason;
112
+ if (firstBegin === -1 && firstEnd === -1) {
113
+ // Rule 2 — create: the block is appended at the end of the content,
114
+ // preceded by a blank line. For an empty file (missing file treated
115
+ // as "") the result is exactly: blank line, MARKER_BEGIN, body,
116
+ // MARKER_END, trailing newline.
117
+ const separator = before === "" ? eol : before.endsWith(eol) ? eol : eol + eol;
118
+ after =
119
+ before +
120
+ separator +
121
+ MARKER_BEGIN +
122
+ eol +
123
+ bodyEol +
124
+ eol +
125
+ MARKER_END +
126
+ eol;
127
+ }
128
+ else if (firstBegin === -1 || firstEnd === -1) {
129
+ // Rule 3 — exactly one marker present.
130
+ after = before;
131
+ outcome = "refused";
132
+ reason =
133
+ firstBegin === -1
134
+ ? "kevin:end marker present without kevin:begin"
135
+ : "kevin:begin marker present without kevin:end";
136
+ }
137
+ else if (firstEnd < firstBegin) {
138
+ // Rule 3 — MARKER_END precedes MARKER_BEGIN.
139
+ after = before;
140
+ outcome = "refused";
141
+ reason = "kevin:end appears before kevin:begin";
142
+ }
143
+ else if (before.indexOf(MARKER_BEGIN, firstBegin + MARKER_BEGIN.length) !== -1 ||
144
+ before.indexOf(MARKER_END, firstEnd + MARKER_END.length) !== -1) {
145
+ // Rule 3 — more than one pair (any additional marker occurrence).
146
+ after = before;
147
+ outcome = "refused";
148
+ reason = "more than one marker pair present";
149
+ }
150
+ else {
151
+ // Rule 4 — bytes outside the marker pair are byte-identical. The
152
+ // block between the markers (begin marker, old block, end marker)
153
+ // is replaced by the regenerated block.
154
+ const blockEnd = firstEnd + MARKER_END.length;
155
+ after =
156
+ before.slice(0, firstBegin) +
157
+ MARKER_BEGIN +
158
+ eol +
159
+ bodyEol +
160
+ eol +
161
+ MARKER_END +
162
+ before.slice(blockEnd);
163
+ // Rule 6 — unchanged content is a noop, never a write.
164
+ outcome = after === before ? "noop" : "written";
165
+ }
166
+ return {
167
+ path,
168
+ before,
169
+ after,
170
+ // v0.6.0 (K6-006 / plan §5.2, D6-05) — approval prompts show bytes,
171
+ // never prose. Identical inputs yield "".
172
+ diff: unifiedDiff(path, before, after),
173
+ outcome,
174
+ ...(reason !== undefined ? { reason } : {}),
175
+ hashBefore: sha256(before),
176
+ hashAfter: sha256(after),
177
+ };
178
+ }
179
+ // v0.6.0 (K6-007 / plan §5.1, rules 7–8) — atomic write + audit row.
180
+ apply(plan, proposalId) {
181
+ // Rule 8 — refusals and noops still leave an audit trail; a refusal
182
+ // that leaves no trace is indistinguishable from a write that never
183
+ // happened. Rule 6 — a noop creates no temp file and writes nothing.
184
+ if (plan.outcome === "noop" || plan.outcome === "refused") {
185
+ if (plan.outcome === "noop") {
186
+ this.metrics?.incr("artifact_writes_noop", 1);
187
+ }
188
+ this.audit(plan, proposalId);
189
+ return plan.outcome;
190
+ }
191
+ // Rule 7 — write to `<path>.kevin.tmp` in the same directory (same
192
+ // filesystem, so rename is atomic), fsync, close, then rename over the
193
+ // target. Never write the target path directly, never truncate-then-write.
194
+ const tmpPath = `${plan.path}.kevin.tmp`;
195
+ let fd;
196
+ try {
197
+ fd = openSync(tmpPath, "w");
198
+ writeSync(fd, plan.after, null, "utf8");
199
+ fsyncSync(fd);
200
+ closeSync(fd);
201
+ fd = undefined;
202
+ this.renameTemp(tmpPath, plan.path);
203
+ }
204
+ catch (err) {
205
+ // Never leave .kevin.tmp litter next to the user's file.
206
+ if (fd !== undefined) {
207
+ try {
208
+ closeSync(fd);
209
+ }
210
+ catch {
211
+ // already closed or unusable; unlink below is the cleanup
212
+ }
213
+ }
214
+ try {
215
+ unlinkSync(tmpPath);
216
+ }
217
+ catch {
218
+ // nothing to clean up
219
+ }
220
+ throw err;
221
+ }
222
+ this.metrics?.incr("artifact_writes_total", 1);
223
+ this.audit(plan, proposalId);
224
+ return "written";
225
+ }
226
+ // Fault-injection seam for the atomicity test: the rename is the point
227
+ // where a failure must leave the target untouched and the temp file gone.
228
+ renameTemp(tmpPath, target) {
229
+ renameSync(tmpPath, target);
230
+ }
231
+ audit(plan, proposalId) {
232
+ this.store
233
+ .prepare(`INSERT INTO artifact_writes
234
+ (id, proposal_id, project_id, path, bytes_before, bytes_after,
235
+ hash_before, hash_after, outcome, reason)
236
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`)
237
+ .run(uuidv7(), proposalId ?? null, this.projectId, plan.path, Buffer.byteLength(plan.before, "utf8"), Buffer.byteLength(plan.after, "utf8"), plan.hashBefore, plan.hashAfter, plan.outcome, plan.reason ?? null);
238
+ }
239
+ }
240
+ //# sourceMappingURL=ArtifactWriter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArtifactWriter.js","sourceRoot":"","sources":["../../plugin/ArtifactWriter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACN,SAAS,EACT,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,UAAU,EACV,SAAS,GACT,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,6EAA6E;AAC7E,+EAA+E;AAC/E,2BAA2B;AAC3B,MAAM,CAAC,MAAM,YAAY,GACxB,gEAAgE,CAAC;AAClE,MAAM,CAAC,MAAM,UAAU,GAAG,oBAAoB,CAAC;AAe/C,SAAS,MAAM,CAAC,IAAY;IAC3B,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC;AAED;;;;;GAKG;AACH,SAAS,SAAS,CAAC,IAAY;IAC9B,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,EAAE,KAAK,CAAC,CAAC;QAAE,OAAO,IAAI,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} from "./RepoTruth.js";
3
+ import type { Store } from "./Store.js";
4
+ import type { Metrics } from "./metrics.js";
5
+ export type ConflictKind = "repo_truth" | "decision_pair" | "temporal";
6
+ export interface Conflict {
7
+ readonly id: string;
8
+ readonly kind: ConflictKind;
9
+ readonly memoryA: string;
10
+ readonly memoryB?: string;
11
+ readonly factId?: string;
12
+ readonly detail: string;
13
+ }
14
+ export interface RepoTruthConflictInput {
15
+ readonly memoryId: string;
16
+ readonly factId?: string | null;
17
+ readonly reasons: readonly string[];
18
+ }
19
+ export declare class ConflictDetector {
20
+ private readonly store;
21
+ private readonly projectId;
22
+ private readonly repoTruth?;
23
+ private readonly memoryService?;
24
+ private readonly metrics;
25
+ constructor(store: Store, projectId: string, metrics?: Metrics | null, repoTruth?: RepoTruth | undefined, memoryService?: MemoryService | undefined);
26
+ detect(repoTruthInput?: readonly RepoTruthConflictInput[]): Conflict[];
27
+ acknowledge(id: string): void;
28
+ /** Human-only operation. It resolves the conflict row, never a memory. */
29
+ resolve(id: string, keepMemoryId: string): void;
30
+ private detectRepoTruth;
31
+ private repoTruthInputs;
32
+ private detectDecisionPairs;
33
+ private detectTemporal;
34
+ private insertIfNew;
35
+ }
@@ -0,0 +1,283 @@
1
+ import { normalize } from "./fingerprint.js";
2
+ import { uuidv7 } from "./uuid.js";
3
+ const POLARITY_RULES = [
4
+ {
5
+ positive: ["use"],
6
+ negative: [
7
+ ["do", "not", "use"],
8
+ ["don't", "use"],
9
+ ["never", "use"],
10
+ ],
11
+ },
12
+ { positive: ["always"], negative: [["never"]] },
13
+ { positive: ["required"], negative: [["forbidden"], ["not", "required"]] },
14
+ { positive: ["enable"], negative: [["disable"]] },
15
+ { positive: ["prefer"], negative: [["avoid"]] },
16
+ ];
17
+ const STOP_WORDS = new Set([
18
+ "a",
19
+ "an",
20
+ "and",
21
+ "are",
22
+ "as",
23
+ "at",
24
+ "be",
25
+ "by",
26
+ "for",
27
+ "from",
28
+ "in",
29
+ "is",
30
+ "it",
31
+ "of",
32
+ "on",
33
+ "or",
34
+ "that",
35
+ "the",
36
+ "this",
37
+ "to",
38
+ "with",
39
+ "we",
40
+ "when",
41
+ "where",
42
+ "you",
43
+ ]);
44
+ const POLARITY_WORDS = new Set([
45
+ "use",
46
+ "do",
47
+ "not",
48
+ // "don't" tokenizes to ["don", "t"] (see tokens()); the lexicon phrase
49
+ // ["don't","use"] is matched by tokenizing the phrase the same way, so
50
+ // both fragments must be excluded from subjects() too (K7-014).
51
+ "don",
52
+ "t",
53
+ "never",
54
+ "always",
55
+ "required",
56
+ "forbidden",
57
+ "enable",
58
+ "disable",
59
+ "prefer",
60
+ "avoid",
61
+ ]);
62
+ export class ConflictDetector {
63
+ store;
64
+ projectId;
65
+ repoTruth;
66
+ memoryService;
67
+ metrics;
68
+ constructor(store, projectId, metrics, repoTruth, memoryService) {
69
+ this.store = store;
70
+ this.projectId = projectId;
71
+ this.repoTruth = repoTruth;
72
+ this.memoryService = memoryService;
73
+ this.metrics = metrics ?? null;
74
+ }
75
+ detect(repoTruthInput) {
76
+ const detected = [];
77
+ detected.push(...this.detectRepoTruth(repoTruthInput));
78
+ detected.push(...this.detectDecisionPairs());
79
+ detected.push(...this.detectTemporal());
80
+ return detected;
81
+ }
82
+ acknowledge(id) {
83
+ this.store
84
+ .prepare("UPDATE memory_conflicts SET status = 'acknowledged' WHERE id = ? AND project_id = ? AND status = 'open'")
85
+ .run(id, this.projectId);
86
+ }
87
+ /** Human-only operation. It resolves the conflict row, never a memory. */
88
+ resolve(id, keepMemoryId) {
89
+ const row = this.store
90
+ .prepare(`SELECT memory_a, memory_b FROM memory_conflicts
91
+ WHERE id = ? AND project_id = ? AND status <> 'resolved'`)
92
+ .get(id, this.projectId);
93
+ if (!row)
94
+ throw new Error(`conflict not found: ${id}`);
95
+ if (keepMemoryId !== row.memory_a && keepMemoryId !== row.memory_b) {
96
+ throw new Error("keep must identify one of the conflict memories");
97
+ }
98
+ this.store
99
+ .prepare("UPDATE memory_conflicts SET status = 'resolved', resolved_at = datetime('now') WHERE id = ? AND project_id = ?")
100
+ .run(id, this.projectId);
101
+ }
102
+ detectRepoTruth(input) {
103
+ const items = input ?? this.repoTruthInputs();
104
+ const out = [];
105
+ for (const item of items) {
106
+ for (const reason of item.reasons) {
107
+ this.memoryService?.applyTruthPenalty(item.memoryId, 0.5, reason);
108
+ const id = this.insertIfNew({
109
+ kind: "repo_truth",
110
+ memoryA: item.memoryId,
111
+ memoryB: null,
112
+ factId: item.factId ?? null,
113
+ detail: reason,
114
+ });
115
+ if (id)
116
+ out.push({
117
+ id,
118
+ kind: "repo_truth",
119
+ memoryA: item.memoryId,
120
+ factId: item.factId ?? undefined,
121
+ detail: reason,
122
+ });
123
+ }
124
+ }
125
+ // v0.7.0 (D7-03) — "recoverable by re-scanning": a memory whose
126
+ // contradiction has lapsed (the repo no longer contradicts it) is
127
+ // de-ranked no longer. The conflict row stays open — resolution is
128
+ // human-initiated only (D7-06) — but the score penalty lifts, so
129
+ // fixing the repo genuinely recovers the memory. Runs only on the
130
+ // production path (no explicit input): explicit-input callers control
131
+ // every write themselves.
132
+ if (!input && this.repoTruth && this.memoryService) {
133
+ const penalized = this.store
134
+ .prepare("SELECT id FROM memories WHERE project_id = ? AND truth_penalty > 0 AND status = 'active'")
135
+ .all(this.projectId);
136
+ for (const row of penalized) {
137
+ const memory = this.memoryService.getById(row.id);
138
+ if (!memory)
139
+ continue;
140
+ if ((this.repoTruth.contradictions(memory) ?? []).length === 0) {
141
+ this.memoryService.applyTruthPenalty(row.id, 0, "");
142
+ }
143
+ }
144
+ }
145
+ return out;
146
+ }
147
+ repoTruthInputs() {
148
+ if (!this.repoTruth)
149
+ return [];
150
+ const rows = this.store
151
+ .prepare(`SELECT id, type, content, scope, relevance_score, source_tool,
152
+ source_session, metadata, created_at, updated_at, expires_at,
153
+ project_id, fingerprint, origin, evidence_count, last_verified_at,
154
+ status, fix_args, ignored, superseded_by, feedback_positive,
155
+ feedback_negative, curated, curated_at, inferable,
156
+ truth_penalty, contradicted_at
157
+ FROM memories WHERE project_id = ? AND status = 'active'`)
158
+ .all(this.projectId);
159
+ return rows.flatMap((row) => {
160
+ const memory = row;
161
+ const reasons = this.repoTruth?.contradictions(memory) ?? [];
162
+ return reasons.length > 0 ? [{ memoryId: row.id, reasons }] : [];
163
+ });
164
+ }
165
+ detectDecisionPairs() {
166
+ const rows = this.store
167
+ .prepare(`SELECT id, type, content, fingerprint FROM memories
168
+ WHERE project_id = ? AND status = 'active'
169
+ AND type IN ('decision', 'rule') ORDER BY id`)
170
+ .all(this.projectId);
171
+ const out = [];
172
+ for (let i = 0; i < rows.length; i++) {
173
+ for (let j = i + 1; j < rows.length; j++) {
174
+ const a = rows[i];
175
+ const b = rows[j];
176
+ if (!a || !b || a.fingerprint === b.fingerprint)
177
+ continue;
178
+ const pair = oppositePair(a.content, b.content);
179
+ if (!pair)
180
+ continue;
181
+ const id = this.insertIfNew({
182
+ kind: "decision_pair",
183
+ memoryA: a.id,
184
+ memoryB: b.id,
185
+ factId: null,
186
+ detail: pair,
187
+ });
188
+ if (id)
189
+ out.push({
190
+ id,
191
+ kind: "decision_pair",
192
+ memoryA: a.id,
193
+ memoryB: b.id,
194
+ detail: pair,
195
+ });
196
+ }
197
+ }
198
+ return out;
199
+ }
200
+ detectTemporal() {
201
+ const rows = this.store
202
+ .prepare(`SELECT m.id,
203
+ MAX(CASE WHEN i.outcome = 'effective' THEN i.injected_at END) AS effective_at,
204
+ MAX(CASE WHEN i.outcome = 'ineffective' THEN i.injected_at END) AS ineffective_at
205
+ FROM memories m JOIN kevin_injections i ON i.memory_id = m.id
206
+ WHERE m.project_id = ? AND m.status = 'active'
207
+ GROUP BY m.id
208
+ HAVING effective_at IS NOT NULL AND ineffective_at IS NOT NULL
209
+ AND ineffective_at > effective_at`)
210
+ .all(this.projectId);
211
+ const out = [];
212
+ for (const row of rows) {
213
+ const detail = `memory was effective at ${row.effective_at} and became ineffective at ${row.ineffective_at}`;
214
+ const id = this.insertIfNew({
215
+ kind: "temporal",
216
+ memoryA: row.id,
217
+ memoryB: null,
218
+ factId: null,
219
+ detail,
220
+ });
221
+ if (id)
222
+ out.push({ id, kind: "temporal", memoryA: row.id, detail });
223
+ }
224
+ return out;
225
+ }
226
+ insertIfNew(input) {
227
+ const existing = this.store
228
+ .prepare(`SELECT id FROM memory_conflicts
229
+ WHERE project_id = ? AND kind = ? AND memory_a = ?
230
+ AND (memory_b IS ? OR (memory_b IS NULL AND ? IS NULL))
231
+ AND (fact_id IS ? OR (fact_id IS NULL AND ? IS NULL))
232
+ AND status = 'open' LIMIT 1`)
233
+ .get(this.projectId, input.kind, input.memoryA, input.memoryB, input.memoryB, input.factId, input.factId);
234
+ if (existing)
235
+ return null;
236
+ const id = uuidv7();
237
+ this.store
238
+ .prepare(`INSERT INTO memory_conflicts
239
+ (id, project_id, memory_a, memory_b, fact_id, kind, detail)
240
+ VALUES (?, ?, ?, ?, ?, ?, ?)`)
241
+ .run(id, this.projectId, input.memoryA, input.memoryB, input.factId, input.kind, input.detail);
242
+ this.metrics?.incr("conflicts_detected", 1);
243
+ return id;
244
+ }
245
+ }
246
+ function tokens(text) {
247
+ return normalize(text).match(/[a-z0-9@._/-]+/g) ?? [];
248
+ }
249
+ function hasPhrase(words, phrase) {
250
+ if (phrase.length === 1)
251
+ return words.includes(phrase[0] ?? "");
252
+ for (let i = 0; i <= words.length - phrase.length; i++) {
253
+ if (phrase.every((word, offset) => words[i + offset] === word))
254
+ return true;
255
+ }
256
+ return false;
257
+ }
258
+ function polarity(text, rule) {
259
+ const words = tokens(text);
260
+ // Lexicon phrases are run through the same tokenizer as the text: "don't
261
+ // use" → ["don","t","use"], which is exactly how the text's own apostrophe
262
+ // is split, so a phrase never becomes unreachable (K7-014).
263
+ const match = (phrase) => hasPhrase(words, tokens(phrase.join(" ")));
264
+ const negative = rule.negative.some(match);
265
+ return { positive: !negative && match(rule.positive), negative };
266
+ }
267
+ function subjects(text) {
268
+ return new Set(tokens(text).filter((token) => !STOP_WORDS.has(token) && !POLARITY_WORDS.has(token)));
269
+ }
270
+ function oppositePair(a, b) {
271
+ const shared = [...subjects(a)].some((token) => subjects(b).has(token));
272
+ if (!shared)
273
+ return null;
274
+ for (const rule of POLARITY_RULES) {
275
+ const pa = polarity(a, rule);
276
+ const pb = polarity(b, rule);
277
+ if ((pa.positive && pb.negative) || (pa.negative && pb.positive)) {
278
+ return `statements carry opposite ${rule.positive.join(" ")} polarity for shared subject ${shared}`;
279
+ }
280
+ }
281
+ return null;
282
+ }
283
+ //# sourceMappingURL=ConflictDetector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConflictDetector.js","sourceRoot":"","sources":["../../plugin/ConflictDetector.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAyCnC,MAAM,cAAc,GAA4B;IAC/C;QACC,QAAQ,EAAE,CAAC,KAAK,CAAC;QACjB,QAAQ,EAAE;YACT,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC;YACpB,CAAC,OAAO,EAAE,KAAK,CAAC;YAChB,CAAC,OAAO,EAAE,KAAK,CAAC;SAChB;KACD;IACD,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE;IAC/C,EAAE,QAAQ,EAAE,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE;IAC1E,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE;IACjD,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE;CAC/C,CAAC;AAEF,MAAM,UAAU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