@jmtrin/opencode-kevin 1.2.0 → 1.4.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/README.md +84 -22
- package/dist/plugin/index.d.ts +5 -4
- package/dist/plugin/index.js +127 -113
- package/dist/plugin/native.d.ts +2 -2
- package/dist/plugin/native.js +2 -2
- package/package.json +56 -68
- 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/ChatBridge.d.ts +0 -41
- package/dist/plugin/ChatBridge.js +0 -103
- 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/DashboardHtml.d.ts +0 -5
- package/dist/plugin/DashboardHtml.js +0 -180
- 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 -216
- 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/TuiActions.d.ts +0 -43
- package/dist/plugin/TuiActions.js +0 -181
- package/dist/plugin/TuiSnapshots.d.ts +0 -24
- package/dist/plugin/TuiSnapshots.js +0 -158
- 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 -386
- 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 -229
- package/dist/plugin/kevin_audit.js +0 -631
- 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 -288
- 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/tui-types.d.ts +0 -59
- package/dist/plugin/tui-types.js +0 -4
- package/dist/plugin/tui.d.ts +0 -18
- package/dist/plugin/tui.js +0 -198
- package/dist/plugin/uuid.d.ts +0 -1
- package/dist/plugin/uuid.js +0 -50
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// v0.4.0 (K4-010) — shared two-sided confidence formula.
|
|
2
|
-
//
|
|
3
|
-
// Confidence is derived from both positive evidence (confirmed fixes) and
|
|
4
|
-
// negative evidence (recurrences): recurrence of the same fingerprint
|
|
5
|
-
// DEMOTES a pattern's confidence, so that a "causal pattern" with a
|
|
6
|
-
// history of recurring failures stops being presented as reliable.
|
|
7
|
-
//
|
|
8
|
-
// confidence = clamp(0.5 + 0.1 * evidenceCount - 0.15 * recurrenceCount, 0.05, 0.95)
|
|
9
|
-
//
|
|
10
|
-
// Used by `MemoryService.promoteToPattern`, `MemoryService.mapRow` and
|
|
11
|
-
// `kevin_why` — keep the formula here, never inline it again.
|
|
12
|
-
//
|
|
13
|
-
// v0.5.0 (K5-010 / plan §5.3, D5-02) — human feedback joins the formula as
|
|
14
|
-
// a second, independent evidence axis. Steps are deliberately SMALLER than
|
|
15
|
-
// the causal steps: feedback is sparse, one-sided, and judgemental, while
|
|
16
|
-
// evidence_count counts confirmed, reproducible fixes. A single negative
|
|
17
|
-
// verdict (0.1) can offset one confirmed fix (0.1), but cannot alone sink
|
|
18
|
-
// a well-evidenced pattern — the causal evidence must agree (plan §5.3,
|
|
19
|
-
// "feedback cannot override causal evidence, only nudge it").
|
|
20
|
-
export const CONFIDENCE_MIN = 0.05;
|
|
21
|
-
export const CONFIDENCE_MAX = 0.95;
|
|
22
|
-
export const CONFIDENCE_BASE = 0.5;
|
|
23
|
-
export const EVIDENCE_STEP = 0.1;
|
|
24
|
-
export const RECURRENCE_PENALTY = 0.15;
|
|
25
|
-
export const FEEDBACK_POSITIVE_STEP = 0.05;
|
|
26
|
-
export const FEEDBACK_NEGATIVE_STEP = 0.1;
|
|
27
|
-
export function computeConfidence(evidenceCount, recurrenceCount, positiveFeedback = 0, negativeFeedback = 0) {
|
|
28
|
-
const raw = CONFIDENCE_BASE +
|
|
29
|
-
EVIDENCE_STEP * evidenceCount -
|
|
30
|
-
RECURRENCE_PENALTY * recurrenceCount +
|
|
31
|
-
FEEDBACK_POSITIVE_STEP * positiveFeedback -
|
|
32
|
-
FEEDBACK_NEGATIVE_STEP * negativeFeedback;
|
|
33
|
-
return Math.min(CONFIDENCE_MAX, Math.max(CONFIDENCE_MIN, raw));
|
|
34
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
export declare const CONTRACT_VERSION = 1;
|
|
2
|
-
export type Stability = "frozen" | "forward-only";
|
|
3
|
-
export interface ContractClause {
|
|
4
|
-
readonly id: string;
|
|
5
|
-
readonly title: string;
|
|
6
|
-
readonly stability: Stability;
|
|
7
|
-
readonly since: string;
|
|
8
|
-
readonly deprecated?: string;
|
|
9
|
-
readonly replacement?: string;
|
|
10
|
-
readonly value: unknown;
|
|
11
|
-
}
|
|
12
|
-
export interface PublicContract {
|
|
13
|
-
readonly contractVersion: number;
|
|
14
|
-
readonly clauses: readonly ContractClause[];
|
|
15
|
-
}
|
|
16
|
-
export interface ContractInput {
|
|
17
|
-
readonly packageName?: string;
|
|
18
|
-
readonly packageVersion?: string;
|
|
19
|
-
}
|
|
20
|
-
export declare const CONTRACT_TOOL_NAMES: readonly string[];
|
|
21
|
-
/**
|
|
22
|
-
* v1.0.0 (K10-018/K10-019 / plan §5.6) — tools added AFTER the initial
|
|
23
|
-
* freeze, each carrying the `since` the deprecation policy requires. A
|
|
24
|
-
* 1.x addition without an entry here fails the contract test as
|
|
25
|
-
* added_bare.
|
|
26
|
-
*/
|
|
27
|
-
export declare const CONTRACT_TOOL_ADDITIONS: readonly {
|
|
28
|
-
name: string;
|
|
29
|
-
since: string;
|
|
30
|
-
}[];
|
|
31
|
-
/**
|
|
32
|
-
* v1.1.0 (K11-007 / plan §5.1, D11-01) — metric keys added after the freeze,
|
|
33
|
-
* each carrying the `since` the deprecation policy requires (C-05).
|
|
34
|
-
*/
|
|
35
|
-
export declare const CONTRACT_METRIC_ADDITIONS: readonly {
|
|
36
|
-
name: string;
|
|
37
|
-
since: string;
|
|
38
|
-
}[];
|
|
39
|
-
/**
|
|
40
|
-
* v1.0.0 (K10-027 / plan §5.7) — the C-09 boundary addition. Stored is
|
|
41
|
-
* not trusted: anything reaching an artifact or a prompt is escaped at
|
|
42
|
-
* the single write path, according to its container.
|
|
43
|
-
*/
|
|
44
|
-
export declare const BOUNDARY_INVARIANT = "untrusted-input escaping at the single write path";
|
|
45
|
-
export declare function describeContract(_input?: ContractInput): PublicContract;
|
|
46
|
-
export declare function contractDigest(c: PublicContract): string;
|
|
47
|
-
export type ContractDiffKind = "removed" | "changed" | "added_ok" | "added_bare";
|
|
48
|
-
export interface ContractDiff {
|
|
49
|
-
readonly clauseId: string;
|
|
50
|
-
readonly path: string;
|
|
51
|
-
readonly kind: ContractDiffKind;
|
|
52
|
-
readonly remedy: string;
|
|
53
|
-
}
|
|
54
|
-
export declare function diffContract(golden: PublicContract, live: PublicContract): readonly ContractDiff[];
|
package/dist/plugin/contract.js
DELETED
|
@@ -1,386 +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
|
-
// v1.2.0 (K12-001 / plan §4, D12-??) — surface metrics (no migration this release)
|
|
57
|
-
{ name: "tui_snapshots_flushed", since: "1.2.0" },
|
|
58
|
-
{ name: "tui_actions_invoked", since: "1.2.0" },
|
|
59
|
-
];
|
|
60
|
-
/**
|
|
61
|
-
* v1.0.0 (K10-027 / plan §5.7) — the C-09 boundary addition. Stored is
|
|
62
|
-
* not trusted: anything reaching an artifact or a prompt is escaped at
|
|
63
|
-
* the single write path, according to its container.
|
|
64
|
-
*/
|
|
65
|
-
export const BOUNDARY_INVARIANT = "untrusted-input escaping at the single write path";
|
|
66
|
-
// For canonical JSON: sort keys recursively, no floats.
|
|
67
|
-
function canonicalJson(value) {
|
|
68
|
-
if (value === null)
|
|
69
|
-
return "null";
|
|
70
|
-
if (typeof value === "boolean")
|
|
71
|
-
return value ? "true" : "false";
|
|
72
|
-
if (typeof value === "number") {
|
|
73
|
-
if (!Number.isFinite(value) || !Number.isInteger(value))
|
|
74
|
-
throw new Error("contract: non-integer number in canonical JSON");
|
|
75
|
-
return String(value);
|
|
76
|
-
}
|
|
77
|
-
if (typeof value === "string")
|
|
78
|
-
return JSON.stringify(value);
|
|
79
|
-
if (Array.isArray(value))
|
|
80
|
-
return `[${value.map(canonicalJson).join(",")}]`;
|
|
81
|
-
if (typeof value === "object") {
|
|
82
|
-
const obj = value;
|
|
83
|
-
const keys = Object.keys(obj).sort();
|
|
84
|
-
return `{${keys.map((k) => `${JSON.stringify(k)}:${canonicalJson(obj[k])}`).join(",")}}`;
|
|
85
|
-
}
|
|
86
|
-
return JSON.stringify(value);
|
|
87
|
-
}
|
|
88
|
-
export function describeContract(_input) {
|
|
89
|
-
// Derive clause values from live source wherever possible (plan §5.1).
|
|
90
|
-
// C-03 members added after the freeze carry their `since` as objects;
|
|
91
|
-
// the original frozen set stays plain strings.
|
|
92
|
-
const toolAdditions = [...CONTRACT_TOOL_ADDITIONS].sort((a, b) => a.name.localeCompare(b.name));
|
|
93
|
-
const toolValue = {
|
|
94
|
-
tools: [[...CONTRACT_TOOL_NAMES].sort(), toolAdditions].flat(),
|
|
95
|
-
};
|
|
96
|
-
const settingValue = { keys: [...KEVIN_CONFIG_KEYS].sort() };
|
|
97
|
-
// v1.1.0 — metric keys added after freeze carry `since` (C-05)
|
|
98
|
-
const metricAdditions = [...CONTRACT_METRIC_ADDITIONS].sort((a, b) => a.name.localeCompare(b.name));
|
|
99
|
-
const baseMetricKeys = Object.keys(METRIC_KEY_LABELS)
|
|
100
|
-
.filter((k) => !metricAdditions.some((a) => a.name === k))
|
|
101
|
-
.sort();
|
|
102
|
-
const metricValue = { keys: [...baseMetricKeys, ...metricAdditions].flat() };
|
|
103
|
-
const clauses = [
|
|
104
|
-
{
|
|
105
|
-
id: "C-01",
|
|
106
|
-
title: "AGENTS.md marker pair",
|
|
107
|
-
stability: "frozen",
|
|
108
|
-
since: "0.6.0",
|
|
109
|
-
value: {
|
|
110
|
-
markers: [MARKER_BEGIN, MARKER_END],
|
|
111
|
-
splice_rule: "bytes outside markers preserved verbatim",
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
id: "C-02",
|
|
116
|
-
title: "OKF v2 wire format",
|
|
117
|
-
stability: "frozen",
|
|
118
|
-
since: "0.8.0",
|
|
119
|
-
value: {
|
|
120
|
-
header_lines: 3,
|
|
121
|
-
field_order: ["entry_id", "type", "content", "scope", "created_at"],
|
|
122
|
-
entry_id_derivation: "fnv1a64 over canonical field ordering",
|
|
123
|
-
eol: "LF",
|
|
124
|
-
integers_only: true,
|
|
125
|
-
sort_order: "entry_id ascending",
|
|
126
|
-
max_line_bytes: MAX_LINE_BYTES,
|
|
127
|
-
max_entries: MAX_ENTRIES,
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
id: "C-03",
|
|
132
|
-
title: "Tool names and argument shapes",
|
|
133
|
-
stability: "frozen",
|
|
134
|
-
since: "0.2.0",
|
|
135
|
-
value: toolValue,
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
id: "C-04",
|
|
139
|
-
title: "Setting keys, types and defaults",
|
|
140
|
-
stability: "frozen",
|
|
141
|
-
since: "0.2.0",
|
|
142
|
-
value: settingValue,
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
id: "C-05",
|
|
146
|
-
title: "Metric key names",
|
|
147
|
-
stability: "frozen",
|
|
148
|
-
since: "0.2.0",
|
|
149
|
-
value: metricValue,
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
id: "C-06",
|
|
153
|
-
title: "Package entry points",
|
|
154
|
-
stability: "frozen",
|
|
155
|
-
since: "0.1.0",
|
|
156
|
-
value: {
|
|
157
|
-
name: "@jmtrin/opencode-kevin",
|
|
158
|
-
main: "dist/plugin/index.js",
|
|
159
|
-
types: "dist/plugin/index.d.ts",
|
|
160
|
-
exports_order: ["types", "import"],
|
|
161
|
-
engines: ">=22.5.0",
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
id: "C-07",
|
|
166
|
-
title: "Database schema",
|
|
167
|
-
stability: "forward-only",
|
|
168
|
-
since: "0.1.0",
|
|
169
|
-
value: {
|
|
170
|
-
schema_version: "012",
|
|
171
|
-
migrations_forward_only: true,
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
id: "C-08",
|
|
176
|
-
title: "Filesystem locations",
|
|
177
|
-
stability: "frozen",
|
|
178
|
-
since: "0.2.0",
|
|
179
|
-
value: {
|
|
180
|
-
db: "~/.opencode-kevin/kevin.db",
|
|
181
|
-
refs: "refs/",
|
|
182
|
-
skills: "skills/",
|
|
183
|
-
okf: ".kevin/knowledge.okf",
|
|
184
|
-
},
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
id: "C-09",
|
|
188
|
-
title: "Behavioural invariants",
|
|
189
|
-
stability: "frozen",
|
|
190
|
-
since: "0.8.0",
|
|
191
|
-
value: {
|
|
192
|
-
invariants: [
|
|
193
|
-
"zero process spawns",
|
|
194
|
-
"zero network calls",
|
|
195
|
-
"no raw author email written",
|
|
196
|
-
"single write path: ArtifactWriter is the only artifact writer",
|
|
197
|
-
],
|
|
198
|
-
// v1.0.0 (K10-027 / plan §5.7) — the untrusted-input boundary
|
|
199
|
-
// joins the clause as an addition carrying its `since`; the
|
|
200
|
-
// frozen invariant strings above are untouched.
|
|
201
|
-
boundary: [{ name: BOUNDARY_INVARIANT, since: "1.0.0" }],
|
|
202
|
-
},
|
|
203
|
-
},
|
|
204
|
-
];
|
|
205
|
-
return { contractVersion: CONTRACT_VERSION, clauses };
|
|
206
|
-
}
|
|
207
|
-
export function contractDigest(c) {
|
|
208
|
-
const payload = canonicalJson(c.clauses);
|
|
209
|
-
return fnv1a64(payload);
|
|
210
|
-
}
|
|
211
|
-
function valueMembers(value) {
|
|
212
|
-
// Normalize clause value into a flat member map for diffing.
|
|
213
|
-
// If value is { tools: [...] } => members are tool names.
|
|
214
|
-
// If { keys: [...] } => member per key.
|
|
215
|
-
// Otherwise flatten object keys.
|
|
216
|
-
if (value !== null && typeof value === "object") {
|
|
217
|
-
const obj = value;
|
|
218
|
-
if (Array.isArray(obj.tools)) {
|
|
219
|
-
const m = new Map();
|
|
220
|
-
for (const t of obj.tools) {
|
|
221
|
-
if (typeof t === "string")
|
|
222
|
-
m.set(t, undefined);
|
|
223
|
-
else if (t !== null &&
|
|
224
|
-
typeof t === "object" &&
|
|
225
|
-
"name" in t)
|
|
226
|
-
m.set(t.name, t);
|
|
227
|
-
}
|
|
228
|
-
return m;
|
|
229
|
-
}
|
|
230
|
-
if (Array.isArray(obj.keys)) {
|
|
231
|
-
const m = new Map();
|
|
232
|
-
for (const k of obj.keys) {
|
|
233
|
-
if (typeof k === "string")
|
|
234
|
-
m.set(k, undefined);
|
|
235
|
-
else if (k !== null &&
|
|
236
|
-
typeof k === "object" &&
|
|
237
|
-
"name" in k)
|
|
238
|
-
m.set(k.name, k);
|
|
239
|
-
}
|
|
240
|
-
return m;
|
|
241
|
-
}
|
|
242
|
-
if (Array.isArray(obj.markers) || Array.isArray(obj.invariants)) {
|
|
243
|
-
const arr = (obj.markers ?? obj.invariants);
|
|
244
|
-
const m = new Map();
|
|
245
|
-
for (const v of arr)
|
|
246
|
-
m.set(v, v);
|
|
247
|
-
// v1.0.0 (K10-027) — boundary additions sit beside the frozen
|
|
248
|
-
// invariant strings and carry their `since` like tool additions.
|
|
249
|
-
if (Array.isArray(obj.boundary)) {
|
|
250
|
-
for (const b of obj.boundary) {
|
|
251
|
-
if (b !== null &&
|
|
252
|
-
typeof b === "object" &&
|
|
253
|
-
"name" in b)
|
|
254
|
-
m.set(b.name, b);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
return m;
|
|
258
|
-
}
|
|
259
|
-
// Generic object: each key is a member
|
|
260
|
-
const m = new Map();
|
|
261
|
-
for (const [k, v] of Object.entries(obj))
|
|
262
|
-
m.set(k, v);
|
|
263
|
-
return m;
|
|
264
|
-
}
|
|
265
|
-
return new Map([["value", value]]);
|
|
266
|
-
}
|
|
267
|
-
export function diffContract(golden, live) {
|
|
268
|
-
const diffs = [];
|
|
269
|
-
const goldenById = new Map(golden.clauses.map((c) => [c.id, c]));
|
|
270
|
-
const liveById = new Map(live.clauses.map((c) => [c.id, c]));
|
|
271
|
-
// Removed clauses
|
|
272
|
-
for (const g of golden.clauses) {
|
|
273
|
-
if (!liveById.has(g.id)) {
|
|
274
|
-
diffs.push({
|
|
275
|
-
clauseId: g.id,
|
|
276
|
-
path: g.id,
|
|
277
|
-
kind: "removed",
|
|
278
|
-
remedy: `Clause ${g.id} was removed. Revert, or open a 2.0.0.`,
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
// Added clauses — check since
|
|
283
|
-
for (const l of live.clauses) {
|
|
284
|
-
if (!goldenById.has(l.id)) {
|
|
285
|
-
const hasSince = typeof l.since === "string" &&
|
|
286
|
-
l.since.length > 0;
|
|
287
|
-
diffs.push({
|
|
288
|
-
clauseId: l.id,
|
|
289
|
-
path: l.id,
|
|
290
|
-
kind: hasSince ? "added_ok" : "added_bare",
|
|
291
|
-
remedy: hasSince
|
|
292
|
-
? `Clause ${l.id} was added with since. Allowed in 1.x.`
|
|
293
|
-
: `Clause ${l.id} was added without since. Add since or revert, or open a 2.0.0.`,
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
// Within-clause diff
|
|
298
|
-
for (const g of golden.clauses) {
|
|
299
|
-
const l = liveById.get(g.id);
|
|
300
|
-
if (!l)
|
|
301
|
-
continue;
|
|
302
|
-
const gMembers = valueMembers(g.value);
|
|
303
|
-
const lMembers = valueMembers(l.value);
|
|
304
|
-
// Normalize members: for arrays we care about set equality
|
|
305
|
-
for (const [mem, _gv] of gMembers) {
|
|
306
|
-
if (!lMembers.has(mem)) {
|
|
307
|
-
diffs.push({
|
|
308
|
-
clauseId: g.id,
|
|
309
|
-
path: `${g.id}.${mem}`,
|
|
310
|
-
kind: "removed",
|
|
311
|
-
remedy: `Member ${mem} in ${g.id} was removed. Revert, or open a 2.0.0.`,
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
else {
|
|
315
|
-
const lv = lMembers.get(mem);
|
|
316
|
-
const gv = gMembers.get(mem);
|
|
317
|
-
if (JSON.stringify(lv) !== JSON.stringify(gv)) {
|
|
318
|
-
// Member present on both sides but its value moved (e.g. an
|
|
319
|
-
// addition object whose `since` was edited). Report it here,
|
|
320
|
-
// at member granularity, instead of letting it fall through
|
|
321
|
-
// to the coarser clause-level check below.
|
|
322
|
-
diffs.push({
|
|
323
|
-
clauseId: g.id,
|
|
324
|
-
path: `${g.id}.${mem}`,
|
|
325
|
-
kind: "changed",
|
|
326
|
-
remedy: `Member ${mem} in ${g.id} changed. Revert, or open a 2.0.0.`,
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
for (const [mem, _lv] of lMembers) {
|
|
332
|
-
if (!gMembers.has(mem)) {
|
|
333
|
-
const liveVal = l.value;
|
|
334
|
-
// Check if the live member carries `since` (additions may ride
|
|
335
|
-
// in the keys, tools or boundary arrays — K10-018/K10-027).
|
|
336
|
-
const lists = [liveVal.keys, liveVal.tools, liveVal.boundary];
|
|
337
|
-
let hasSince = false;
|
|
338
|
-
for (const list of lists) {
|
|
339
|
-
if (!Array.isArray(list))
|
|
340
|
-
continue;
|
|
341
|
-
const entry = list.find((e) => {
|
|
342
|
-
if (typeof e === "string")
|
|
343
|
-
return e === mem;
|
|
344
|
-
if (e !== null &&
|
|
345
|
-
typeof e === "object" &&
|
|
346
|
-
"name" in e)
|
|
347
|
-
return e.name === mem;
|
|
348
|
-
return false;
|
|
349
|
-
});
|
|
350
|
-
if (entry !== null &&
|
|
351
|
-
typeof entry === "object" &&
|
|
352
|
-
typeof entry.since === "string") {
|
|
353
|
-
hasSince = true;
|
|
354
|
-
break;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
diffs.push({
|
|
358
|
-
clauseId: g.id,
|
|
359
|
-
path: `${g.id}.${mem}`,
|
|
360
|
-
kind: hasSince ? "added_ok" : "added_bare",
|
|
361
|
-
remedy: hasSince
|
|
362
|
-
? `Member ${mem} in ${g.id} was added with since. Allowed in 1.x.`
|
|
363
|
-
: `Member ${mem} in ${g.id} was added without since. Add since or revert, or open a 2.0.0.`,
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
// Also compare clause-level metadata that is not in valueMembers (e.g., package version in C-06)
|
|
368
|
-
// If the whole value JSON differs but members didn't capture it (e.g., name change), mark changed.
|
|
369
|
-
if (JSON.stringify(g.value) !== JSON.stringify(l.value)) {
|
|
370
|
-
// Only emit clause-level changed if no finer-grained diff already emitted for this clause
|
|
371
|
-
const hasFiner = diffs.some((d) => d.clauseId === g.id && d.path !== g.id);
|
|
372
|
-
if (!hasFiner) {
|
|
373
|
-
diffs.push({
|
|
374
|
-
clauseId: g.id,
|
|
375
|
-
path: g.id,
|
|
376
|
-
kind: "changed",
|
|
377
|
-
remedy: `Clause ${g.id} changed. Revert, or open a 2.0.0.`,
|
|
378
|
-
});
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
diffs.sort((a, b) => a.clauseId === b.clauseId
|
|
383
|
-
? a.path.localeCompare(b.path)
|
|
384
|
-
: a.clauseId.localeCompare(b.clauseId));
|
|
385
|
-
return diffs;
|
|
386
|
-
}
|
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
|
-
}
|