@jmtrin/opencode-kevin 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/plugin/capabilities.d.ts +2 -0
- package/dist/plugin/capabilities.js +3 -0
- package/dist/plugin/index.d.ts +5 -4
- package/dist/plugin/index.js +401 -108
- package/dist/plugin/native.d.ts +2 -2
- package/dist/plugin/native.js +2 -2
- package/package.json +56 -63
- package/LICENSE +0 -21
- package/README.md +0 -576
- package/dist/migrations/001_initial.sql +0 -92
- package/dist/migrations/002_indexes.sql +0 -14
- package/dist/migrations/003_v02_signal.sql +0 -58
- package/dist/migrations/004_v03_knowledge.sql +0 -138
- package/dist/migrations/005_v04_signal.sql +0 -57
- package/dist/migrations/006_v05_glassbox.sql +0 -118
- package/dist/migrations/007_v06_pull.sql +0 -145
- package/dist/migrations/008_v07_truth.sql +0 -124
- package/dist/migrations/009_v08_team.sql +0 -100
- package/dist/migrations/010_v09_native.sql +0 -78
- package/dist/migrations/011_v10_proven.sql +0 -69
- package/dist/migrations/012_v11_drift.sql +0 -24
- package/dist/plugin/Archiver.d.ts +0 -42
- package/dist/plugin/Archiver.js +0 -83
- package/dist/plugin/ArtifactWriter.d.ts +0 -93
- package/dist/plugin/ArtifactWriter.js +0 -291
- package/dist/plugin/CausalChain.d.ts +0 -22
- package/dist/plugin/CausalChain.js +0 -197
- package/dist/plugin/ConflictDetector.d.ts +0 -35
- package/dist/plugin/ConflictDetector.js +0 -260
- package/dist/plugin/ContextInjector.d.ts +0 -222
- package/dist/plugin/ContextInjector.js +0 -533
- package/dist/plugin/ConventionMiner.d.ts +0 -35
- package/dist/plugin/ConventionMiner.js +0 -242
- package/dist/plugin/Curator.d.ts +0 -116
- package/dist/plugin/Curator.js +0 -324
- package/dist/plugin/Feedback.d.ts +0 -67
- package/dist/plugin/Feedback.js +0 -120
- package/dist/plugin/HookLiveness.d.ts +0 -88
- package/dist/plugin/HookLiveness.js +0 -322
- package/dist/plugin/InjectionLedger.d.ts +0 -98
- package/dist/plugin/InjectionLedger.js +0 -295
- package/dist/plugin/LessonFixer.d.ts +0 -44
- package/dist/plugin/LessonFixer.js +0 -45
- package/dist/plugin/Materializer.d.ts +0 -83
- package/dist/plugin/Materializer.js +0 -181
- package/dist/plugin/MemoryService.d.ts +0 -360
- package/dist/plugin/MemoryService.js +0 -1242
- package/dist/plugin/Migrate.d.ts +0 -17
- package/dist/plugin/Migrate.js +0 -271
- package/dist/plugin/PatternMiner.d.ts +0 -49
- package/dist/plugin/PatternMiner.js +0 -132
- package/dist/plugin/QualityGate.d.ts +0 -124
- package/dist/plugin/QualityGate.js +0 -119
- package/dist/plugin/Reflector.d.ts +0 -91
- package/dist/plugin/Reflector.js +0 -307
- package/dist/plugin/RepoIdentity.d.ts +0 -124
- package/dist/plugin/RepoIdentity.js +0 -300
- package/dist/plugin/RepoTruth.d.ts +0 -80
- package/dist/plugin/RepoTruth.js +0 -599
- package/dist/plugin/Retrospective.d.ts +0 -17
- package/dist/plugin/Retrospective.js +0 -213
- package/dist/plugin/SharedLayer.d.ts +0 -159
- package/dist/plugin/SharedLayer.js +0 -462
- package/dist/plugin/Store.d.ts +0 -29
- package/dist/plugin/Store.js +0 -50
- package/dist/plugin/ToolCallObserver.d.ts +0 -32
- package/dist/plugin/ToolCallObserver.js +0 -201
- package/dist/plugin/columns.d.ts +0 -11
- package/dist/plugin/columns.js +0 -54
- package/dist/plugin/confidence.d.ts +0 -8
- package/dist/plugin/confidence.js +0 -34
- package/dist/plugin/contract.d.ts +0 -54
- package/dist/plugin/contract.js +0 -383
- package/dist/plugin/diff.d.ts +0 -8
- package/dist/plugin/diff.js +0 -182
- package/dist/plugin/escape.d.ts +0 -39
- package/dist/plugin/escape.js +0 -60
- package/dist/plugin/fingerprint.d.ts +0 -27
- package/dist/plugin/fingerprint.js +0 -73
- package/dist/plugin/inferability.d.ts +0 -32
- package/dist/plugin/inferability.js +0 -88
- package/dist/plugin/kevin_approve.d.ts +0 -34
- package/dist/plugin/kevin_approve.js +0 -52
- package/dist/plugin/kevin_audit.d.ts +0 -213
- package/dist/plugin/kevin_audit.js +0 -563
- package/dist/plugin/kevin_bench.d.ts +0 -10
- package/dist/plugin/kevin_bench.js +0 -82
- package/dist/plugin/kevin_conflicts.d.ts +0 -9
- package/dist/plugin/kevin_conflicts.js +0 -50
- package/dist/plugin/kevin_contract.d.ts +0 -8
- package/dist/plugin/kevin_contract.js +0 -59
- package/dist/plugin/kevin_doctor.d.ts +0 -62
- package/dist/plugin/kevin_doctor.js +0 -196
- package/dist/plugin/kevin_facts.d.ts +0 -42
- package/dist/plugin/kevin_facts.js +0 -36
- package/dist/plugin/kevin_forget.d.ts +0 -33
- package/dist/plugin/kevin_forget.js +0 -260
- package/dist/plugin/kevin_native.d.ts +0 -29
- package/dist/plugin/kevin_native.js +0 -79
- package/dist/plugin/kevin_propose.d.ts +0 -23
- package/dist/plugin/kevin_propose.js +0 -14
- package/dist/plugin/kevin_publish.d.ts +0 -38
- package/dist/plugin/kevin_publish.js +0 -18
- package/dist/plugin/kevin_why.d.ts +0 -23
- package/dist/plugin/kevin_why.js +0 -111
- package/dist/plugin/memory-format.d.ts +0 -20
- package/dist/plugin/memory-format.js +0 -59
- package/dist/plugin/metrics.d.ts +0 -97
- package/dist/plugin/metrics.js +0 -284
- package/dist/plugin/okf-export.d.ts +0 -3
- package/dist/plugin/okf-export.js +0 -134
- package/dist/plugin/okf-import.d.ts +0 -76
- package/dist/plugin/okf-import.js +0 -271
- package/dist/plugin/okf.d.ts +0 -107
- package/dist/plugin/okf.js +0 -303
- package/dist/plugin/perf.d.ts +0 -35
- package/dist/plugin/perf.js +0 -174
- package/dist/plugin/query-tokenizer.d.ts +0 -13
- package/dist/plugin/query-tokenizer.js +0 -133
- package/dist/plugin/redact.d.ts +0 -2
- package/dist/plugin/redact.js +0 -18
- package/dist/plugin/replay-types.d.ts +0 -69
- package/dist/plugin/replay-types.js +0 -156
- package/dist/plugin/replay.d.ts +0 -36
- package/dist/plugin/replay.js +0 -202
- package/dist/plugin/sqlite-adapter.d.ts +0 -12
- package/dist/plugin/sqlite-adapter.js +0 -81
- package/dist/plugin/time-ms.d.ts +0 -1
- package/dist/plugin/time-ms.js +0 -16
- package/dist/plugin/uuid.d.ts +0 -1
- package/dist/plugin/uuid.js +0 -50
package/dist/plugin/contract.js
DELETED
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
// v1.0.0 (K10-006 / plan §5.1) — the surface, as data.
|
|
2
|
-
import { MARKER_BEGIN, MARKER_END } from "./ArtifactWriter.js";
|
|
3
|
-
import { METRIC_KEY_LABELS } from "./Retrospective.js";
|
|
4
|
-
import { fnv1a64 } from "./fingerprint.js";
|
|
5
|
-
import { KEVIN_CONFIG_KEYS } from "./index.js";
|
|
6
|
-
import { MAX_ENTRIES, MAX_LINE_BYTES } from "./okf.js";
|
|
7
|
-
export const CONTRACT_VERSION = 1;
|
|
8
|
-
// Tool names — the live source of truth for C-03. Any rename here must
|
|
9
|
-
// flow to the contract (K10-006 AC: renaming a tool changes C-03).
|
|
10
|
-
// Keep this array adjacent to the actual tool registrations in index.ts
|
|
11
|
-
// (checked by a test that parses both files).
|
|
12
|
-
export const CONTRACT_TOOL_NAMES = [
|
|
13
|
-
"kevin_save",
|
|
14
|
-
"kevin_query",
|
|
15
|
-
"kevin_get",
|
|
16
|
-
"kevin_recall",
|
|
17
|
-
"kevin_status",
|
|
18
|
-
"kevin_project",
|
|
19
|
-
"kevin_audit",
|
|
20
|
-
"kevin_doctor",
|
|
21
|
-
"kevin_native",
|
|
22
|
-
"kevin_retrospective",
|
|
23
|
-
"kevin_why",
|
|
24
|
-
"kevin_feedback",
|
|
25
|
-
"kevin_trace",
|
|
26
|
-
"kevin_export",
|
|
27
|
-
"kevin_import",
|
|
28
|
-
"kevin_config",
|
|
29
|
-
"kevin_facts",
|
|
30
|
-
"kevin_conflicts",
|
|
31
|
-
"kevin_propose",
|
|
32
|
-
"kevin_publish",
|
|
33
|
-
"kevin_approve",
|
|
34
|
-
"kevin_share",
|
|
35
|
-
"kevin_sync",
|
|
36
|
-
];
|
|
37
|
-
/**
|
|
38
|
-
* v1.0.0 (K10-018/K10-019 / plan §5.6) — tools added AFTER the initial
|
|
39
|
-
* freeze, each carrying the `since` the deprecation policy requires. A
|
|
40
|
-
* 1.x addition without an entry here fails the contract test as
|
|
41
|
-
* added_bare.
|
|
42
|
-
*/
|
|
43
|
-
export const CONTRACT_TOOL_ADDITIONS = [
|
|
44
|
-
{ name: "kevin_bench", since: "1.0.0" },
|
|
45
|
-
{ name: "kevin_contract", since: "1.0.0" },
|
|
46
|
-
{ name: "kevin_forget", since: "1.1.0" },
|
|
47
|
-
];
|
|
48
|
-
/**
|
|
49
|
-
* v1.1.0 (K11-007 / plan §5.1, D11-01) — metric keys added after the freeze,
|
|
50
|
-
* each carrying the `since` the deprecation policy requires (C-05).
|
|
51
|
-
*/
|
|
52
|
-
export const CONTRACT_METRIC_ADDITIONS = [
|
|
53
|
-
{ name: "bench_regression_failures", since: "1.1.0" },
|
|
54
|
-
{ name: "forget_requests_total", since: "1.1.0" },
|
|
55
|
-
{ name: "forget_tombstones_published", since: "1.1.0" },
|
|
56
|
-
];
|
|
57
|
-
/**
|
|
58
|
-
* v1.0.0 (K10-027 / plan §5.7) — the C-09 boundary addition. Stored is
|
|
59
|
-
* not trusted: anything reaching an artifact or a prompt is escaped at
|
|
60
|
-
* the single write path, according to its container.
|
|
61
|
-
*/
|
|
62
|
-
export const BOUNDARY_INVARIANT = "untrusted-input escaping at the single write path";
|
|
63
|
-
// For canonical JSON: sort keys recursively, no floats.
|
|
64
|
-
function canonicalJson(value) {
|
|
65
|
-
if (value === null)
|
|
66
|
-
return "null";
|
|
67
|
-
if (typeof value === "boolean")
|
|
68
|
-
return value ? "true" : "false";
|
|
69
|
-
if (typeof value === "number") {
|
|
70
|
-
if (!Number.isFinite(value) || !Number.isInteger(value))
|
|
71
|
-
throw new Error("contract: non-integer number in canonical JSON");
|
|
72
|
-
return String(value);
|
|
73
|
-
}
|
|
74
|
-
if (typeof value === "string")
|
|
75
|
-
return JSON.stringify(value);
|
|
76
|
-
if (Array.isArray(value))
|
|
77
|
-
return `[${value.map(canonicalJson).join(",")}]`;
|
|
78
|
-
if (typeof value === "object") {
|
|
79
|
-
const obj = value;
|
|
80
|
-
const keys = Object.keys(obj).sort();
|
|
81
|
-
return `{${keys.map((k) => `${JSON.stringify(k)}:${canonicalJson(obj[k])}`).join(",")}}`;
|
|
82
|
-
}
|
|
83
|
-
return JSON.stringify(value);
|
|
84
|
-
}
|
|
85
|
-
export function describeContract(_input) {
|
|
86
|
-
// Derive clause values from live source wherever possible (plan §5.1).
|
|
87
|
-
// C-03 members added after the freeze carry their `since` as objects;
|
|
88
|
-
// the original frozen set stays plain strings.
|
|
89
|
-
const toolAdditions = [...CONTRACT_TOOL_ADDITIONS].sort((a, b) => a.name.localeCompare(b.name));
|
|
90
|
-
const toolValue = {
|
|
91
|
-
tools: [[...CONTRACT_TOOL_NAMES].sort(), toolAdditions].flat(),
|
|
92
|
-
};
|
|
93
|
-
const settingValue = { keys: [...KEVIN_CONFIG_KEYS].sort() };
|
|
94
|
-
// v1.1.0 — metric keys added after freeze carry `since` (C-05)
|
|
95
|
-
const metricAdditions = [...CONTRACT_METRIC_ADDITIONS].sort((a, b) => a.name.localeCompare(b.name));
|
|
96
|
-
const baseMetricKeys = Object.keys(METRIC_KEY_LABELS)
|
|
97
|
-
.filter((k) => !metricAdditions.some((a) => a.name === k))
|
|
98
|
-
.sort();
|
|
99
|
-
const metricValue = { keys: [...baseMetricKeys, ...metricAdditions].flat() };
|
|
100
|
-
const clauses = [
|
|
101
|
-
{
|
|
102
|
-
id: "C-01",
|
|
103
|
-
title: "AGENTS.md marker pair",
|
|
104
|
-
stability: "frozen",
|
|
105
|
-
since: "0.6.0",
|
|
106
|
-
value: {
|
|
107
|
-
markers: [MARKER_BEGIN, MARKER_END],
|
|
108
|
-
splice_rule: "bytes outside markers preserved verbatim",
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
id: "C-02",
|
|
113
|
-
title: "OKF v2 wire format",
|
|
114
|
-
stability: "frozen",
|
|
115
|
-
since: "0.8.0",
|
|
116
|
-
value: {
|
|
117
|
-
header_lines: 3,
|
|
118
|
-
field_order: ["entry_id", "type", "content", "scope", "created_at"],
|
|
119
|
-
entry_id_derivation: "fnv1a64 over canonical field ordering",
|
|
120
|
-
eol: "LF",
|
|
121
|
-
integers_only: true,
|
|
122
|
-
sort_order: "entry_id ascending",
|
|
123
|
-
max_line_bytes: MAX_LINE_BYTES,
|
|
124
|
-
max_entries: MAX_ENTRIES,
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
id: "C-03",
|
|
129
|
-
title: "Tool names and argument shapes",
|
|
130
|
-
stability: "frozen",
|
|
131
|
-
since: "0.2.0",
|
|
132
|
-
value: toolValue,
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
id: "C-04",
|
|
136
|
-
title: "Setting keys, types and defaults",
|
|
137
|
-
stability: "frozen",
|
|
138
|
-
since: "0.2.0",
|
|
139
|
-
value: settingValue,
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
id: "C-05",
|
|
143
|
-
title: "Metric key names",
|
|
144
|
-
stability: "frozen",
|
|
145
|
-
since: "0.2.0",
|
|
146
|
-
value: metricValue,
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
id: "C-06",
|
|
150
|
-
title: "Package entry points",
|
|
151
|
-
stability: "frozen",
|
|
152
|
-
since: "0.1.0",
|
|
153
|
-
value: {
|
|
154
|
-
name: "@jmtrin/opencode-kevin",
|
|
155
|
-
main: "dist/plugin/index.js",
|
|
156
|
-
types: "dist/plugin/index.d.ts",
|
|
157
|
-
exports_order: ["types", "import"],
|
|
158
|
-
engines: ">=22.5.0",
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
id: "C-07",
|
|
163
|
-
title: "Database schema",
|
|
164
|
-
stability: "forward-only",
|
|
165
|
-
since: "0.1.0",
|
|
166
|
-
value: {
|
|
167
|
-
schema_version: "012",
|
|
168
|
-
migrations_forward_only: true,
|
|
169
|
-
},
|
|
170
|
-
},
|
|
171
|
-
{
|
|
172
|
-
id: "C-08",
|
|
173
|
-
title: "Filesystem locations",
|
|
174
|
-
stability: "frozen",
|
|
175
|
-
since: "0.2.0",
|
|
176
|
-
value: {
|
|
177
|
-
db: "~/.opencode-kevin/kevin.db",
|
|
178
|
-
refs: "refs/",
|
|
179
|
-
skills: "skills/",
|
|
180
|
-
okf: ".kevin/knowledge.okf",
|
|
181
|
-
},
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
id: "C-09",
|
|
185
|
-
title: "Behavioural invariants",
|
|
186
|
-
stability: "frozen",
|
|
187
|
-
since: "0.8.0",
|
|
188
|
-
value: {
|
|
189
|
-
invariants: [
|
|
190
|
-
"zero process spawns",
|
|
191
|
-
"zero network calls",
|
|
192
|
-
"no raw author email written",
|
|
193
|
-
"single write path: ArtifactWriter is the only artifact writer",
|
|
194
|
-
],
|
|
195
|
-
// v1.0.0 (K10-027 / plan §5.7) — the untrusted-input boundary
|
|
196
|
-
// joins the clause as an addition carrying its `since`; the
|
|
197
|
-
// frozen invariant strings above are untouched.
|
|
198
|
-
boundary: [{ name: BOUNDARY_INVARIANT, since: "1.0.0" }],
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
];
|
|
202
|
-
return { contractVersion: CONTRACT_VERSION, clauses };
|
|
203
|
-
}
|
|
204
|
-
export function contractDigest(c) {
|
|
205
|
-
const payload = canonicalJson(c.clauses);
|
|
206
|
-
return fnv1a64(payload);
|
|
207
|
-
}
|
|
208
|
-
function valueMembers(value) {
|
|
209
|
-
// Normalize clause value into a flat member map for diffing.
|
|
210
|
-
// If value is { tools: [...] } => members are tool names.
|
|
211
|
-
// If { keys: [...] } => member per key.
|
|
212
|
-
// Otherwise flatten object keys.
|
|
213
|
-
if (value !== null && typeof value === "object") {
|
|
214
|
-
const obj = value;
|
|
215
|
-
if (Array.isArray(obj.tools)) {
|
|
216
|
-
const m = new Map();
|
|
217
|
-
for (const t of obj.tools) {
|
|
218
|
-
if (typeof t === "string")
|
|
219
|
-
m.set(t, undefined);
|
|
220
|
-
else if (t !== null &&
|
|
221
|
-
typeof t === "object" &&
|
|
222
|
-
"name" in t)
|
|
223
|
-
m.set(t.name, t);
|
|
224
|
-
}
|
|
225
|
-
return m;
|
|
226
|
-
}
|
|
227
|
-
if (Array.isArray(obj.keys)) {
|
|
228
|
-
const m = new Map();
|
|
229
|
-
for (const k of obj.keys) {
|
|
230
|
-
if (typeof k === "string")
|
|
231
|
-
m.set(k, undefined);
|
|
232
|
-
else if (k !== null &&
|
|
233
|
-
typeof k === "object" &&
|
|
234
|
-
"name" in k)
|
|
235
|
-
m.set(k.name, k);
|
|
236
|
-
}
|
|
237
|
-
return m;
|
|
238
|
-
}
|
|
239
|
-
if (Array.isArray(obj.markers) || Array.isArray(obj.invariants)) {
|
|
240
|
-
const arr = (obj.markers ?? obj.invariants);
|
|
241
|
-
const m = new Map();
|
|
242
|
-
for (const v of arr)
|
|
243
|
-
m.set(v, v);
|
|
244
|
-
// v1.0.0 (K10-027) — boundary additions sit beside the frozen
|
|
245
|
-
// invariant strings and carry their `since` like tool additions.
|
|
246
|
-
if (Array.isArray(obj.boundary)) {
|
|
247
|
-
for (const b of obj.boundary) {
|
|
248
|
-
if (b !== null &&
|
|
249
|
-
typeof b === "object" &&
|
|
250
|
-
"name" in b)
|
|
251
|
-
m.set(b.name, b);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return m;
|
|
255
|
-
}
|
|
256
|
-
// Generic object: each key is a member
|
|
257
|
-
const m = new Map();
|
|
258
|
-
for (const [k, v] of Object.entries(obj))
|
|
259
|
-
m.set(k, v);
|
|
260
|
-
return m;
|
|
261
|
-
}
|
|
262
|
-
return new Map([["value", value]]);
|
|
263
|
-
}
|
|
264
|
-
export function diffContract(golden, live) {
|
|
265
|
-
const diffs = [];
|
|
266
|
-
const goldenById = new Map(golden.clauses.map((c) => [c.id, c]));
|
|
267
|
-
const liveById = new Map(live.clauses.map((c) => [c.id, c]));
|
|
268
|
-
// Removed clauses
|
|
269
|
-
for (const g of golden.clauses) {
|
|
270
|
-
if (!liveById.has(g.id)) {
|
|
271
|
-
diffs.push({
|
|
272
|
-
clauseId: g.id,
|
|
273
|
-
path: g.id,
|
|
274
|
-
kind: "removed",
|
|
275
|
-
remedy: `Clause ${g.id} was removed. Revert, or open a 2.0.0.`,
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
// Added clauses — check since
|
|
280
|
-
for (const l of live.clauses) {
|
|
281
|
-
if (!goldenById.has(l.id)) {
|
|
282
|
-
const hasSince = typeof l.since === "string" &&
|
|
283
|
-
l.since.length > 0;
|
|
284
|
-
diffs.push({
|
|
285
|
-
clauseId: l.id,
|
|
286
|
-
path: l.id,
|
|
287
|
-
kind: hasSince ? "added_ok" : "added_bare",
|
|
288
|
-
remedy: hasSince
|
|
289
|
-
? `Clause ${l.id} was added with since. Allowed in 1.x.`
|
|
290
|
-
: `Clause ${l.id} was added without since. Add since or revert, or open a 2.0.0.`,
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
// Within-clause diff
|
|
295
|
-
for (const g of golden.clauses) {
|
|
296
|
-
const l = liveById.get(g.id);
|
|
297
|
-
if (!l)
|
|
298
|
-
continue;
|
|
299
|
-
const gMembers = valueMembers(g.value);
|
|
300
|
-
const lMembers = valueMembers(l.value);
|
|
301
|
-
// Normalize members: for arrays we care about set equality
|
|
302
|
-
for (const [mem, _gv] of gMembers) {
|
|
303
|
-
if (!lMembers.has(mem)) {
|
|
304
|
-
diffs.push({
|
|
305
|
-
clauseId: g.id,
|
|
306
|
-
path: `${g.id}.${mem}`,
|
|
307
|
-
kind: "removed",
|
|
308
|
-
remedy: `Member ${mem} in ${g.id} was removed. Revert, or open a 2.0.0.`,
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
const lv = lMembers.get(mem);
|
|
313
|
-
const gv = gMembers.get(mem);
|
|
314
|
-
if (JSON.stringify(lv) !== JSON.stringify(gv)) {
|
|
315
|
-
// Member present on both sides but its value moved (e.g. an
|
|
316
|
-
// addition object whose `since` was edited). Report it here,
|
|
317
|
-
// at member granularity, instead of letting it fall through
|
|
318
|
-
// to the coarser clause-level check below.
|
|
319
|
-
diffs.push({
|
|
320
|
-
clauseId: g.id,
|
|
321
|
-
path: `${g.id}.${mem}`,
|
|
322
|
-
kind: "changed",
|
|
323
|
-
remedy: `Member ${mem} in ${g.id} changed. Revert, or open a 2.0.0.`,
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
for (const [mem, _lv] of lMembers) {
|
|
329
|
-
if (!gMembers.has(mem)) {
|
|
330
|
-
const liveVal = l.value;
|
|
331
|
-
// Check if the live member carries `since` (additions may ride
|
|
332
|
-
// in the keys, tools or boundary arrays — K10-018/K10-027).
|
|
333
|
-
const lists = [liveVal.keys, liveVal.tools, liveVal.boundary];
|
|
334
|
-
let hasSince = false;
|
|
335
|
-
for (const list of lists) {
|
|
336
|
-
if (!Array.isArray(list))
|
|
337
|
-
continue;
|
|
338
|
-
const entry = list.find((e) => {
|
|
339
|
-
if (typeof e === "string")
|
|
340
|
-
return e === mem;
|
|
341
|
-
if (e !== null &&
|
|
342
|
-
typeof e === "object" &&
|
|
343
|
-
"name" in e)
|
|
344
|
-
return e.name === mem;
|
|
345
|
-
return false;
|
|
346
|
-
});
|
|
347
|
-
if (entry !== null &&
|
|
348
|
-
typeof entry === "object" &&
|
|
349
|
-
typeof entry.since === "string") {
|
|
350
|
-
hasSince = true;
|
|
351
|
-
break;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
diffs.push({
|
|
355
|
-
clauseId: g.id,
|
|
356
|
-
path: `${g.id}.${mem}`,
|
|
357
|
-
kind: hasSince ? "added_ok" : "added_bare",
|
|
358
|
-
remedy: hasSince
|
|
359
|
-
? `Member ${mem} in ${g.id} was added with since. Allowed in 1.x.`
|
|
360
|
-
: `Member ${mem} in ${g.id} was added without since. Add since or revert, or open a 2.0.0.`,
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
// Also compare clause-level metadata that is not in valueMembers (e.g., package version in C-06)
|
|
365
|
-
// If the whole value JSON differs but members didn't capture it (e.g., name change), mark changed.
|
|
366
|
-
if (JSON.stringify(g.value) !== JSON.stringify(l.value)) {
|
|
367
|
-
// Only emit clause-level changed if no finer-grained diff already emitted for this clause
|
|
368
|
-
const hasFiner = diffs.some((d) => d.clauseId === g.id && d.path !== g.id);
|
|
369
|
-
if (!hasFiner) {
|
|
370
|
-
diffs.push({
|
|
371
|
-
clauseId: g.id,
|
|
372
|
-
path: g.id,
|
|
373
|
-
kind: "changed",
|
|
374
|
-
remedy: `Clause ${g.id} changed. Revert, or open a 2.0.0.`,
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
diffs.sort((a, b) => a.clauseId === b.clauseId
|
|
380
|
-
? a.path.localeCompare(b.path)
|
|
381
|
-
: a.clauseId.localeCompare(b.clauseId));
|
|
382
|
-
return diffs;
|
|
383
|
-
}
|
package/dist/plugin/diff.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unified diff between `before` and `after` for `path`, in git's format:
|
|
3
|
-
* `--- a/<path>` / `+++ b/<path>` headers, `@@ -l,s +l,s @@` hunk headers
|
|
4
|
-
* (count omitted when 1, `0,0` for an empty side), three lines of context and
|
|
5
|
-
* adjacent hunks merged when their context windows overlap. Identical inputs
|
|
6
|
-
* yield the empty string.
|
|
7
|
-
*/
|
|
8
|
-
export declare function unifiedDiff(path: string, before: string, after: string): string;
|
package/dist/plugin/diff.js
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
// v0.6.0 (K6-006 / plan §5.2, D6-05) — a minimal deterministic unified-diff
|
|
2
|
-
// generator. Pure, dependency-free, byte-for-byte compatible with
|
|
3
|
-
// `git diff -U3 --no-index` for the fixtures the tests compare.
|
|
4
|
-
//
|
|
5
|
-
// It exists for exactly one reason: approval prompts must show a diff, never
|
|
6
|
-
// prose (D6-05). Determinism is a hard requirement: the output is persisted
|
|
7
|
-
// into `curation_proposals.diff` and compared across runs. No timestamps, no
|
|
8
|
-
// `Object.keys` iteration, no `Set` iteration — arrays only.
|
|
9
|
-
const CONTEXT = 3;
|
|
10
|
-
/**
|
|
11
|
-
* Split text into logical lines. A trailing newline is not part of the line
|
|
12
|
-
* model, so a file that merely gains or loses its final newline produces no
|
|
13
|
-
* spurious final-line hunk.
|
|
14
|
-
*/
|
|
15
|
-
function linesOf(text) {
|
|
16
|
-
if (text === "")
|
|
17
|
-
return [];
|
|
18
|
-
const parts = text.split("\n");
|
|
19
|
-
if (parts[parts.length - 1] === "")
|
|
20
|
-
parts.pop();
|
|
21
|
-
return parts;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* LCS over lines via dynamic programming, then a deterministic walk emitting
|
|
25
|
-
* context / deletion / addition ops. Within each change region deletions are
|
|
26
|
-
* emitted before additions, matching git's block ordering exactly.
|
|
27
|
-
*/
|
|
28
|
-
function computeOps(a, b) {
|
|
29
|
-
const m = a.length;
|
|
30
|
-
const n = b.length;
|
|
31
|
-
const w = n + 1;
|
|
32
|
-
const dp = new Int32Array((m + 1) * w);
|
|
33
|
-
for (let i = m - 1; i >= 0; i--) {
|
|
34
|
-
for (let j = n - 1; j >= 0; j--) {
|
|
35
|
-
dp[i * w + j] =
|
|
36
|
-
a[i] === b[j]
|
|
37
|
-
? dp[(i + 1) * w + j + 1] + 1
|
|
38
|
-
: Math.max(dp[(i + 1) * w + j], dp[i * w + j + 1]);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
const ops = [];
|
|
42
|
-
const pendingDel = [];
|
|
43
|
-
const pendingAdd = [];
|
|
44
|
-
const flush = () => {
|
|
45
|
-
for (const line of pendingDel)
|
|
46
|
-
ops.push({ type: "del", line });
|
|
47
|
-
for (const line of pendingAdd)
|
|
48
|
-
ops.push({ type: "add", line });
|
|
49
|
-
pendingDel.length = 0;
|
|
50
|
-
pendingAdd.length = 0;
|
|
51
|
-
};
|
|
52
|
-
let i = 0;
|
|
53
|
-
let j = 0;
|
|
54
|
-
while (i < m && j < n) {
|
|
55
|
-
if (a[i] === b[j]) {
|
|
56
|
-
flush();
|
|
57
|
-
ops.push({ type: "ctx", line: a[i] });
|
|
58
|
-
i++;
|
|
59
|
-
j++;
|
|
60
|
-
}
|
|
61
|
-
else if (dp[(i + 1) * w + j] >= dp[i * w + j + 1]) {
|
|
62
|
-
pendingDel.push(a[i]);
|
|
63
|
-
i++;
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
pendingAdd.push(b[j]);
|
|
67
|
-
j++;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
flush();
|
|
71
|
-
while (i < m) {
|
|
72
|
-
pendingDel.push(a[i]);
|
|
73
|
-
i++;
|
|
74
|
-
}
|
|
75
|
-
flush();
|
|
76
|
-
while (j < n) {
|
|
77
|
-
pendingAdd.push(b[j]);
|
|
78
|
-
j++;
|
|
79
|
-
}
|
|
80
|
-
flush();
|
|
81
|
-
return ops;
|
|
82
|
-
}
|
|
83
|
-
function buildHunks(ops) {
|
|
84
|
-
// Maximal change regions: runs of ops containing at least one del/add.
|
|
85
|
-
const regions = [];
|
|
86
|
-
let regionStart = -1;
|
|
87
|
-
for (let k = 0; k < ops.length; k++) {
|
|
88
|
-
if (ops[k].type !== "ctx") {
|
|
89
|
-
if (regionStart === -1)
|
|
90
|
-
regionStart = k;
|
|
91
|
-
}
|
|
92
|
-
else if (regionStart !== -1) {
|
|
93
|
-
regions.push([regionStart, k]);
|
|
94
|
-
regionStart = -1;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (regionStart !== -1)
|
|
98
|
-
regions.push([regionStart, ops.length]);
|
|
99
|
-
// Extend each region by CONTEXT lines and merge overlapping windows.
|
|
100
|
-
const windows = [];
|
|
101
|
-
for (const [rs, re] of regions) {
|
|
102
|
-
const start = Math.max(0, rs - CONTEXT);
|
|
103
|
-
const end = Math.min(ops.length, re + CONTEXT);
|
|
104
|
-
const prev = windows[windows.length - 1];
|
|
105
|
-
if (prev !== undefined && start <= prev.end) {
|
|
106
|
-
prev.end = end;
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
windows.push({ start, end });
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const hunks = [];
|
|
113
|
-
for (const win of windows) {
|
|
114
|
-
let beforeStart = 0;
|
|
115
|
-
let afterStart = 0;
|
|
116
|
-
let countA = 0;
|
|
117
|
-
let countB = 0;
|
|
118
|
-
for (let k = 0; k < win.end; k++) {
|
|
119
|
-
const op = ops[k];
|
|
120
|
-
const inside = k >= win.start;
|
|
121
|
-
if (op.type === "del") {
|
|
122
|
-
if (!inside)
|
|
123
|
-
beforeStart++;
|
|
124
|
-
if (inside)
|
|
125
|
-
countA++;
|
|
126
|
-
}
|
|
127
|
-
else if (op.type === "add") {
|
|
128
|
-
if (!inside)
|
|
129
|
-
afterStart++;
|
|
130
|
-
if (inside)
|
|
131
|
-
countB++;
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
if (!inside) {
|
|
135
|
-
beforeStart++;
|
|
136
|
-
afterStart++;
|
|
137
|
-
}
|
|
138
|
-
if (inside) {
|
|
139
|
-
countA++;
|
|
140
|
-
countB++;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
// 1-based start lines; a side with zero lines starts at 0.
|
|
145
|
-
const startA = countA > 0 ? beforeStart + 1 : 0;
|
|
146
|
-
const startB = countB > 0 ? afterStart + 1 : 0;
|
|
147
|
-
const rangeA = countA === 1 ? `-${startA}` : `-${startA},${countA}`;
|
|
148
|
-
const rangeB = countB === 1 ? `+${startB}` : `+${startB},${countB}`;
|
|
149
|
-
const lines = [];
|
|
150
|
-
for (let k = win.start; k < win.end; k++) {
|
|
151
|
-
const op = ops[k];
|
|
152
|
-
if (op.type === "del")
|
|
153
|
-
lines.push(`-${op.line}`);
|
|
154
|
-
else if (op.type === "add")
|
|
155
|
-
lines.push(`+${op.line}`);
|
|
156
|
-
else
|
|
157
|
-
lines.push(` ${op.line}`);
|
|
158
|
-
}
|
|
159
|
-
hunks.push({ header: `@@ ${rangeA} ${rangeB} @@`, lines });
|
|
160
|
-
}
|
|
161
|
-
return hunks;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Unified diff between `before` and `after` for `path`, in git's format:
|
|
165
|
-
* `--- a/<path>` / `+++ b/<path>` headers, `@@ -l,s +l,s @@` hunk headers
|
|
166
|
-
* (count omitted when 1, `0,0` for an empty side), three lines of context and
|
|
167
|
-
* adjacent hunks merged when their context windows overlap. Identical inputs
|
|
168
|
-
* yield the empty string.
|
|
169
|
-
*/
|
|
170
|
-
export function unifiedDiff(path, before, after) {
|
|
171
|
-
const ops = computeOps(linesOf(before), linesOf(after));
|
|
172
|
-
const hunks = buildHunks(ops);
|
|
173
|
-
if (hunks.length === 0)
|
|
174
|
-
return "";
|
|
175
|
-
const parts = [];
|
|
176
|
-
for (const hunk of hunks) {
|
|
177
|
-
parts.push(hunk.header);
|
|
178
|
-
parts.push(...hunk.lines);
|
|
179
|
-
}
|
|
180
|
-
const header = `--- a/${path}\n+++ b/${path}\n`;
|
|
181
|
-
return `${header}${parts.join("\n")}\n`;
|
|
182
|
-
}
|
package/dist/plugin/escape.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* v1.0.0 (K10-027 / plan §5.7) — the untrusted-input boundary.
|
|
3
|
-
*
|
|
4
|
-
* One pure, total, idempotent escaping function per container Kevin
|
|
5
|
-
* writes stored text into. Every function here is a fixed point after
|
|
6
|
-
* one application — applying it twice equals applying it once — because
|
|
7
|
-
* a re-curated memory passes through the boundary on every regeneration
|
|
8
|
-
* and must not accumulate escaping.
|
|
9
|
-
*
|
|
10
|
-
* This module imports nothing and touches no filesystem. It is the
|
|
11
|
-
* boundary; the single enforcement point is ArtifactWriter (D6-01).
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Neutralise text destined for the AGENTS.md marker block: HTML-escape
|
|
15
|
-
* (the memory-format discipline, made idempotent) so the literal
|
|
16
|
-
* `<!-- kevin:end -->` marker sequence and every comment terminator
|
|
17
|
-
* lose their meaning inside the block. The line-level strip of anything
|
|
18
|
-
* containing `kevin:begin`/`kevin:end` stays in
|
|
19
|
-
* ArtifactWriter.sanitizeArtifactBody — it is a filter, not an escape.
|
|
20
|
-
*/
|
|
21
|
-
export declare function escapeForMarkerBlock(text: string): string;
|
|
22
|
-
/**
|
|
23
|
-
* Neutralise fenced-code delimiters: any run of three or more backticks
|
|
24
|
-
* or tildes would close (or open) a markdown fence around the rendered
|
|
25
|
-
* block and let stored text masquerade as un-fenced document content.
|
|
26
|
-
* Each byte of the run becomes its numeric HTML entity, which renders
|
|
27
|
-
* identically but can never form a delimiter again.
|
|
28
|
-
*/
|
|
29
|
-
export declare function escapeForFence(text: string): string;
|
|
30
|
-
/**
|
|
31
|
-
* Neutralise bytes that would terminate an OKF v2 line: newline,
|
|
32
|
-
* carriage return and every other C0 control character become their
|
|
33
|
-
* JSON-style escapes, so a statement can never split into a second
|
|
34
|
-
* line even if a future writer forgets JSON.stringify. Quotation marks
|
|
35
|
-
* and backslashes are deliberately NOT touched here — the OKF line is
|
|
36
|
-
* canonical JSON and re-escaping them would corrupt parsing; JSON
|
|
37
|
-
* already guarantees they stay inside the string.
|
|
38
|
-
*/
|
|
39
|
-
export declare function escapeForOkfLine(text: string): string;
|
package/dist/plugin/escape.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* v1.0.0 (K10-027 / plan §5.7) — the untrusted-input boundary.
|
|
3
|
-
*
|
|
4
|
-
* One pure, total, idempotent escaping function per container Kevin
|
|
5
|
-
* writes stored text into. Every function here is a fixed point after
|
|
6
|
-
* one application — applying it twice equals applying it once — because
|
|
7
|
-
* a re-curated memory passes through the boundary on every regeneration
|
|
8
|
-
* and must not accumulate escaping.
|
|
9
|
-
*
|
|
10
|
-
* This module imports nothing and touches no filesystem. It is the
|
|
11
|
-
* boundary; the single enforcement point is ArtifactWriter (D6-01).
|
|
12
|
-
*/
|
|
13
|
-
const ENTITY_HEADS = /&(?!(amp|lt|gt|#\d+);)/g;
|
|
14
|
-
/**
|
|
15
|
-
* Neutralise text destined for the AGENTS.md marker block: HTML-escape
|
|
16
|
-
* (the memory-format discipline, made idempotent) so the literal
|
|
17
|
-
* `<!-- kevin:end -->` marker sequence and every comment terminator
|
|
18
|
-
* lose their meaning inside the block. The line-level strip of anything
|
|
19
|
-
* containing `kevin:begin`/`kevin:end` stays in
|
|
20
|
-
* ArtifactWriter.sanitizeArtifactBody — it is a filter, not an escape.
|
|
21
|
-
*/
|
|
22
|
-
export function escapeForMarkerBlock(text) {
|
|
23
|
-
return text
|
|
24
|
-
.replace(ENTITY_HEADS, "&")
|
|
25
|
-
.replace(/</g, "<")
|
|
26
|
-
.replace(/>/g, ">");
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Neutralise fenced-code delimiters: any run of three or more backticks
|
|
30
|
-
* or tildes would close (or open) a markdown fence around the rendered
|
|
31
|
-
* block and let stored text masquerade as un-fenced document content.
|
|
32
|
-
* Each byte of the run becomes its numeric HTML entity, which renders
|
|
33
|
-
* identically but can never form a delimiter again.
|
|
34
|
-
*/
|
|
35
|
-
export function escapeForFence(text) {
|
|
36
|
-
return text
|
|
37
|
-
.replace(/`{3,}/g, (run) => "`".repeat(run.length))
|
|
38
|
-
.replace(/~{3,}/g, (run) => "~".repeat(run.length));
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Neutralise bytes that would terminate an OKF v2 line: newline,
|
|
42
|
-
* carriage return and every other C0 control character become their
|
|
43
|
-
* JSON-style escapes, so a statement can never split into a second
|
|
44
|
-
* line even if a future writer forgets JSON.stringify. Quotation marks
|
|
45
|
-
* and backslashes are deliberately NOT touched here — the OKF line is
|
|
46
|
-
* canonical JSON and re-escaping them would corrupt parsing; JSON
|
|
47
|
-
* already guarantees they stay inside the string.
|
|
48
|
-
*/
|
|
49
|
-
export function escapeForOkfLine(text) {
|
|
50
|
-
// biome-ignore lint/suspicious/noControlCharactersInRegex: neutralising control bytes is this function's entire job
|
|
51
|
-
return text.replace(/[\u0000-\u001f]/g, (c) => {
|
|
52
|
-
if (c === "\n")
|
|
53
|
-
return "\\n";
|
|
54
|
-
if (c === "\r")
|
|
55
|
-
return "\\r";
|
|
56
|
-
if (c === "\t")
|
|
57
|
-
return "\\t";
|
|
58
|
-
return `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`;
|
|
59
|
-
});
|
|
60
|
-
}
|