@abelxiaoxing/cadence 1.8.3 → 2.0.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 +324 -111
- package/THIRD_PARTY_NOTICES.md +15 -0
- package/agents/design-explorer.md +14 -26
- package/agents/diagnosis-worker.md +14 -25
- package/agents/implementation-worker.md +16 -35
- package/config/.env.example +2 -5
- package/config/workflow-task.example.json +7 -0
- package/docs/remote-access.md +60 -0
- package/docs/reuse-and-distribution.md +44 -0
- package/docs/service-management.md +108 -0
- package/licenses/bundled-web.txt +6245 -0
- package/licenses/pi-web-ui-MIT.txt +21 -0
- package/licenses/pi-web-ui-reuse.md +22 -0
- package/package.json +94 -21
- package/src/index.ts +22 -1807
- package/src/native-build.ts +6 -0
- package/src/native-client.ts +103 -0
- package/src/native-export.ts +58 -0
- package/src/native-history.ts +359 -0
- package/src/operator-cli.mjs +453 -1937
- package/src/plan-proposal.ts +87 -0
- package/src/sdk-worker.mjs +549 -0
- package/src/service/contracts/active.ts +82 -0
- package/src/service/contracts/budget.ts +148 -0
- package/src/service/contracts/build.ts +67 -0
- package/src/service/contracts/capture.ts +48 -0
- package/src/service/contracts/core.ts +33 -0
- package/src/service/contracts/current.ts +261 -0
- package/src/service/contracts/domain.ts +68 -0
- package/src/service/contracts/history.ts +2245 -0
- package/src/service/contracts/models.ts +139 -0
- package/src/service/coordination.ts +862 -0
- package/src/service/private-files.ts +204 -0
- package/src/service-cli.mjs +5592 -0
- package/src/service-client.ts +747 -0
- package/src/service-contract.ts +245 -0
- package/src/service-host.mjs +22382 -0
- package/src/service-http-client.ts +425 -0
- package/src/service-wire.ts +372 -0
- package/src/task-shell.ts +1045 -0
- package/src/task-store.ts +479 -0
- package/src/task-types.ts +184 -0
- package/src/verification-diagnostics.ts +29 -72
- package/src/worker-capture.mjs +1197 -0
- package/src/worker-public.mjs +1753 -0
- package/src/worker-redaction.mjs +608 -0
- package/src/worker-tools.mjs +202 -0
- package/web/dist/assets/KaTeX_AMS-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_AMS-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_AMS-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Bold.ttf +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Bold.woff +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Bold.woff2 +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Caligraphic-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Bold.ttf +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Bold.woff +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Bold.woff2 +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Fraktur-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-Bold.ttf +0 -0
- package/web/dist/assets/KaTeX_Main-Bold.woff +0 -0
- package/web/dist/assets/KaTeX_Main-Bold.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-BoldItalic.ttf +0 -0
- package/web/dist/assets/KaTeX_Main-BoldItalic.woff +0 -0
- package/web/dist/assets/KaTeX_Main-BoldItalic.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-Italic.ttf +0 -0
- package/web/dist/assets/KaTeX_Main-Italic.woff +0 -0
- package/web/dist/assets/KaTeX_Main-Italic.woff2 +0 -0
- package/web/dist/assets/KaTeX_Main-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Main-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Main-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Math-BoldItalic.ttf +0 -0
- package/web/dist/assets/KaTeX_Math-BoldItalic.woff +0 -0
- package/web/dist/assets/KaTeX_Math-BoldItalic.woff2 +0 -0
- package/web/dist/assets/KaTeX_Math-Italic.ttf +0 -0
- package/web/dist/assets/KaTeX_Math-Italic.woff +0 -0
- package/web/dist/assets/KaTeX_Math-Italic.woff2 +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Bold.ttf +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Bold.woff +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Bold.woff2 +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Italic.ttf +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Italic.woff +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Italic.woff2 +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_SansSerif-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Script-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Script-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Script-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Size1-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Size1-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Size1-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Size2-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Size2-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Size2-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Size3-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Size3-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Size3-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Size4-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Size4-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Size4-Regular.woff2 +0 -0
- package/web/dist/assets/KaTeX_Typewriter-Regular.ttf +0 -0
- package/web/dist/assets/KaTeX_Typewriter-Regular.woff +0 -0
- package/web/dist/assets/KaTeX_Typewriter-Regular.woff2 +0 -0
- package/web/dist/assets/cadence.css +2 -0
- package/web/dist/assets/cadence.js +7 -0
- package/web/dist/assets/markdown.js +296 -0
- package/web/dist/assets/react.js +9 -0
- package/web/dist/assets/rolldown-runtime.js +1 -0
- package/web/dist/assets/timeline-client.js +41 -0
- package/web/dist/assets/vis-timeline.css +1274 -0
- package/web/dist/assets/vis-timeline.js +32 -0
- package/web/dist/index.html +18 -0
- package/web/dist/manifest.json +505 -0
- package/config/plan-draft.example.json +0 -125
- package/config/plan-draft.multiple-tasks.example.json +0 -375
- package/config/plan-draft.quick.example.json +0 -78
- package/config/routes.example.json +0 -39
- package/prompts/abel-design.md +0 -382
- package/prompts/abel-diagnose.md +0 -71
- package/prompts/abel-implement.md +0 -284
- package/prompts/abel-init.md +0 -52
- package/src/activation.ts +0 -44
- package/src/activity-contracts.ts +0 -82
- package/src/agent-registry.ts +0 -53
- package/src/apply-transaction.ts +0 -1437
- package/src/artifact-store.ts +0 -213
- package/src/build-windows-job.mjs +0 -95
- package/src/candidate-artifact.ts +0 -143
- package/src/candidate-patch.ts +0 -271
- package/src/candidate-workspace.ts +0 -80
- package/src/canonical.ts +0 -16
- package/src/change-contract-schema.ts +0 -191
- package/src/change-contract.ts +0 -324
- package/src/change-verification.ts +0 -1617
- package/src/child-budget.ts +0 -58
- package/src/child-model.ts +0 -142
- package/src/child-session.ts +0 -640
- package/src/contracts.ts +0 -2476
- package/src/control-contracts.ts +0 -382
- package/src/delivery-compiler.ts +0 -1805
- package/src/delivery-revision.ts +0 -42
- package/src/design-control.ts +0 -1299
- package/src/design-diagnostics.ts +0 -181
- package/src/design-journal.ts +0 -1773
- package/src/directory-sync.ts +0 -36
- package/src/durable-contracts.ts +0 -231
- package/src/durable-workflow.ts +0 -978
- package/src/evidence-draft.ts +0 -122
- package/src/execution-profile.ts +0 -64
- package/src/execution-retention.ts +0 -77
- package/src/file-snapshot.ts +0 -163
- package/src/implement-continuation.ts +0 -559
- package/src/implement-graph.ts +0 -690
- package/src/implement-plan.ts +0 -72
- package/src/install-config.d.mts +0 -6
- package/src/isolation-backend.ts +0 -353
- package/src/model-source.ts +0 -22
- package/src/openspec-cli.ts +0 -494
- package/src/operator-cli-entry.mjs +0 -24
- package/src/operator-tools.ts +0 -309
- package/src/package-candidate.ts +0 -227
- package/src/package-delivery.ts +0 -486
- package/src/package-state.ts +0 -320
- package/src/package-verification.ts +0 -635
- package/src/package-workflow.ts +0 -342
- package/src/packet-runtime.ts +0 -570
- package/src/parent-provider.ts +0 -375
- package/src/phase-execution.ts +0 -2259
- package/src/pi-adapter.ts +0 -19
- package/src/plan-draft-summary.ts +0 -527
- package/src/plan-draft.ts +0 -502
- package/src/remove-path.ts +0 -32
- package/src/route-policy.ts +0 -545
- package/src/run-state.ts +0 -420
- package/src/run-store.ts +0 -1179
- package/src/safe-path.ts +0 -77
- package/src/scoped-grep-worker.mjs +0 -23
- package/src/scoped-tools.ts +0 -775
- package/src/single-task-draft.ts +0 -142
- package/src/sqlite-schema.ts +0 -171
- package/src/state-root.ts +0 -215
- package/src/storage-schema.ts +0 -360
- package/src/subagent-activity.ts +0 -1417
- package/src/submit-tool.ts +0 -950
- package/src/task-ledger.ts +0 -1338
- package/src/transport-budget.ts +0 -52
- package/src/verification-capability.ts +0 -1191
- package/src/verification-environment-io.ts +0 -389
- package/src/verification-environment.ts +0 -162
- package/src/verification-identity.ts +0 -77
- package/src/verification-scan.ts +0 -64
- package/src/windows-job-backend.ts +0 -419
- package/src/windows-job.c +0 -149
- package/src/worker-broker.ts +0 -806
- package/src/workflow-engine.ts +0 -28
- package/src/workflow-policy.ts +0 -1679
- package/src/workflow-recovery-policy.ts +0 -97
- package/src/workflow-scheduling.ts +0 -105
- package/src/workflow-state-machine.ts +0 -4355
- package/src/workflow-status.ts +0 -576
- package/src/workspace-io-entry.mjs +0 -76
- package/src/workspace-io-worker.mjs +0 -1312
- package/src/workspace-io.ts +0 -89
- package/src/workspace-store.ts +0 -634
package/src/candidate-patch.ts
DELETED
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
import { lstatSync, readFileSync } from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { generateUnifiedPatch } from "@earendil-works/pi-coding-agent";
|
|
4
|
-
import { compareCanonicalStrings } from "./canonical.ts";
|
|
5
|
-
|
|
6
|
-
import { isValidRelativePath } from "./contracts.ts";
|
|
7
|
-
import { observeSafePath } from "./safe-path.ts";
|
|
8
|
-
|
|
9
|
-
export type CandidatePatchOperation =
|
|
10
|
-
| {
|
|
11
|
-
kind: "replace";
|
|
12
|
-
path: string;
|
|
13
|
-
oldText: string;
|
|
14
|
-
newText: string;
|
|
15
|
-
}
|
|
16
|
-
| { kind: "rewrite"; path: string; content: string }
|
|
17
|
-
| {
|
|
18
|
-
kind: "create";
|
|
19
|
-
path: string;
|
|
20
|
-
content: string;
|
|
21
|
-
mode: "regular" | "executable";
|
|
22
|
-
}
|
|
23
|
-
| { kind: "delete"; path: string };
|
|
24
|
-
|
|
25
|
-
interface CandidateFileState {
|
|
26
|
-
path: string;
|
|
27
|
-
base: string | null;
|
|
28
|
-
current: string | null;
|
|
29
|
-
mode: "100644" | "100755";
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function exactKeys(value: object, expected: readonly string[]): boolean {
|
|
33
|
-
const actual = Object.keys(value).sort();
|
|
34
|
-
return (
|
|
35
|
-
actual.length === expected.length &&
|
|
36
|
-
[...expected].sort().every((key, index) => actual[index] === key)
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function safeText(value: unknown, maxBytes: number): value is string {
|
|
41
|
-
if (typeof value !== "string" || value.includes("\0")) return false;
|
|
42
|
-
const encoded = Buffer.from(value, "utf8");
|
|
43
|
-
return encoded.byteLength <= maxBytes && encoded.toString("utf8") === value;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function renderFileDiff(state: CandidateFileState): string {
|
|
47
|
-
if (state.base === state.current) return "";
|
|
48
|
-
if (state.base === null && state.current === "") {
|
|
49
|
-
throw new Error("candidate-empty-file-create-unsupported");
|
|
50
|
-
}
|
|
51
|
-
if (state.current === null && state.base === "") {
|
|
52
|
-
throw new Error("candidate-empty-file-delete-unsupported");
|
|
53
|
-
}
|
|
54
|
-
const output: string[] = [`diff --git a/${state.path} b/${state.path}`];
|
|
55
|
-
if (state.base === null) output.push(`new file mode ${state.mode}`);
|
|
56
|
-
if (state.current === null) output.push(`deleted file mode ${state.mode}`);
|
|
57
|
-
const generated = generateUnifiedPatch(
|
|
58
|
-
state.path,
|
|
59
|
-
state.base ?? "",
|
|
60
|
-
state.current ?? "",
|
|
61
|
-
3,
|
|
62
|
-
);
|
|
63
|
-
const generatedHeaders = `--- ${state.path}\n+++ ${state.path}\n`;
|
|
64
|
-
if (!generated.startsWith(generatedHeaders)) {
|
|
65
|
-
throw new Error("candidate-patch-diff-invalid");
|
|
66
|
-
}
|
|
67
|
-
output.push(state.base === null ? "--- /dev/null" : `--- a/${state.path}`);
|
|
68
|
-
output.push(state.current === null ? "+++ /dev/null" : `+++ b/${state.path}`);
|
|
69
|
-
return `${output.join("\n")}\n${generated.slice(generatedHeaders.length)}`;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function occurrenceCount(value: string, search: string): number {
|
|
73
|
-
let count = 0;
|
|
74
|
-
let offset = 0;
|
|
75
|
-
for (;;) {
|
|
76
|
-
const found = value.indexOf(search, offset);
|
|
77
|
-
if (found < 0) return count;
|
|
78
|
-
count += 1;
|
|
79
|
-
if (count > 1) return count;
|
|
80
|
-
offset = found + 1;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export function compileCandidatePatch(input: {
|
|
85
|
-
root: string;
|
|
86
|
-
writePaths: readonly string[];
|
|
87
|
-
deletePaths: readonly string[];
|
|
88
|
-
operations: readonly CandidatePatchOperation[];
|
|
89
|
-
maxBytes: number;
|
|
90
|
-
}): string {
|
|
91
|
-
if (
|
|
92
|
-
!path.isAbsolute(input.root) ||
|
|
93
|
-
!Number.isSafeInteger(input.maxBytes) ||
|
|
94
|
-
input.maxBytes < 1 ||
|
|
95
|
-
!Array.isArray(input.operations) ||
|
|
96
|
-
input.operations.length < 1 ||
|
|
97
|
-
input.operations.length > 128
|
|
98
|
-
) {
|
|
99
|
-
throw new Error("candidate-patch-invalid");
|
|
100
|
-
}
|
|
101
|
-
const writePaths = new Set(input.writePaths);
|
|
102
|
-
const deletePaths = new Set(input.deletePaths);
|
|
103
|
-
const states = new Map<string, CandidateFileState>();
|
|
104
|
-
|
|
105
|
-
const requirePath = (relative: unknown): string => {
|
|
106
|
-
if (
|
|
107
|
-
!isValidRelativePath(relative) ||
|
|
108
|
-
relative === "." ||
|
|
109
|
-
relative.trim() !== relative ||
|
|
110
|
-
/[\r\n\t]/u.test(relative)
|
|
111
|
-
) {
|
|
112
|
-
throw new Error("candidate-patch-path-invalid");
|
|
113
|
-
}
|
|
114
|
-
return relative;
|
|
115
|
-
};
|
|
116
|
-
const load = (relative: string): CandidateFileState => {
|
|
117
|
-
const existing = states.get(relative);
|
|
118
|
-
if (existing) return existing;
|
|
119
|
-
const observation = observeSafePath(input.root, relative);
|
|
120
|
-
if (observation.kind === "directory" || observation.kind === "unsafe") {
|
|
121
|
-
throw new Error("candidate-patch-path-unsafe");
|
|
122
|
-
}
|
|
123
|
-
let base: string | null = null;
|
|
124
|
-
let mode: CandidateFileState["mode"] = "100644";
|
|
125
|
-
if (observation.kind === "file") {
|
|
126
|
-
const target = path.join(input.root, relative);
|
|
127
|
-
const stat = lstatSync(target);
|
|
128
|
-
if (stat.size > input.maxBytes) {
|
|
129
|
-
throw new Error("candidate-patch-source-too-large");
|
|
130
|
-
}
|
|
131
|
-
const bytes = readFileSync(target);
|
|
132
|
-
try {
|
|
133
|
-
base = new TextDecoder("utf-8", {
|
|
134
|
-
fatal: true,
|
|
135
|
-
ignoreBOM: true,
|
|
136
|
-
}).decode(bytes);
|
|
137
|
-
} catch {
|
|
138
|
-
throw new Error("candidate-patch-source-invalid");
|
|
139
|
-
}
|
|
140
|
-
if (base.includes("\0")) {
|
|
141
|
-
throw new Error("candidate-patch-source-invalid");
|
|
142
|
-
}
|
|
143
|
-
mode = stat.mode & 0o111 ? "100755" : "100644";
|
|
144
|
-
}
|
|
145
|
-
const state = { path: relative, base, current: base, mode };
|
|
146
|
-
states.set(relative, state);
|
|
147
|
-
return state;
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
for (const [operationIndex, operation] of input.operations.entries()) {
|
|
151
|
-
if (
|
|
152
|
-
!operation ||
|
|
153
|
-
typeof operation !== "object" ||
|
|
154
|
-
Array.isArray(operation)
|
|
155
|
-
) {
|
|
156
|
-
throw new Error("candidate-patch-operation-invalid");
|
|
157
|
-
}
|
|
158
|
-
switch (operation.kind) {
|
|
159
|
-
case "replace": {
|
|
160
|
-
if (
|
|
161
|
-
!exactKeys(operation, ["kind", "path", "oldText", "newText"]) ||
|
|
162
|
-
!safeText(operation.oldText, input.maxBytes) ||
|
|
163
|
-
operation.oldText.length === 0 ||
|
|
164
|
-
!safeText(operation.newText, input.maxBytes)
|
|
165
|
-
) {
|
|
166
|
-
throw new Error("candidate-patch-replace-invalid");
|
|
167
|
-
}
|
|
168
|
-
const relative = requirePath(operation.path);
|
|
169
|
-
const reject = (reason: string, hint: string): never => {
|
|
170
|
-
throw new Error(
|
|
171
|
-
JSON.stringify({
|
|
172
|
-
code: "candidate-patch-replace-invalid",
|
|
173
|
-
operationIndex,
|
|
174
|
-
...(relative.length <= 512 && !/[\p{Cc}\p{Cf}]/u.test(relative)
|
|
175
|
-
? { path: relative }
|
|
176
|
-
: {}),
|
|
177
|
-
reason,
|
|
178
|
-
hint,
|
|
179
|
-
}),
|
|
180
|
-
);
|
|
181
|
-
};
|
|
182
|
-
if (!writePaths.has(relative)) {
|
|
183
|
-
reject(
|
|
184
|
-
"path-not-authorized",
|
|
185
|
-
"Use only approved write paths; request context instead of widening authority.",
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
const state = load(relative);
|
|
189
|
-
const current =
|
|
190
|
-
state.current ??
|
|
191
|
-
reject(
|
|
192
|
-
"file-not-found",
|
|
193
|
-
"Use create for a new approved file, or correct the path.",
|
|
194
|
-
);
|
|
195
|
-
const occurrences = occurrenceCount(current, operation.oldText);
|
|
196
|
-
if (occurrences !== 1) {
|
|
197
|
-
reject(
|
|
198
|
-
occurrences === 0 ? "old-text-not-found" : "old-text-ambiguous",
|
|
199
|
-
"Read the approved file and supply exact unique oldText, including enough surrounding context. Operations are applied in order.",
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
state.current = current.replace(operation.oldText, operation.newText);
|
|
203
|
-
break;
|
|
204
|
-
}
|
|
205
|
-
case "rewrite": {
|
|
206
|
-
if (
|
|
207
|
-
!exactKeys(operation, ["kind", "path", "content"]) ||
|
|
208
|
-
!safeText(operation.content, input.maxBytes)
|
|
209
|
-
) {
|
|
210
|
-
throw new Error("candidate-patch-rewrite-invalid");
|
|
211
|
-
}
|
|
212
|
-
const relative = requirePath(operation.path);
|
|
213
|
-
if (!writePaths.has(relative)) {
|
|
214
|
-
throw new Error("candidate-patch-rewrite-invalid");
|
|
215
|
-
}
|
|
216
|
-
const state = load(relative);
|
|
217
|
-
if (state.current === null) {
|
|
218
|
-
throw new Error("candidate-patch-rewrite-invalid");
|
|
219
|
-
}
|
|
220
|
-
state.current = operation.content;
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
case "create": {
|
|
224
|
-
if (
|
|
225
|
-
!exactKeys(operation, ["kind", "path", "content", "mode"]) ||
|
|
226
|
-
!safeText(operation.content, input.maxBytes) ||
|
|
227
|
-
operation.content.length === 0 ||
|
|
228
|
-
(operation.mode !== "regular" && operation.mode !== "executable")
|
|
229
|
-
) {
|
|
230
|
-
throw new Error("candidate-patch-create-invalid");
|
|
231
|
-
}
|
|
232
|
-
const relative = requirePath(operation.path);
|
|
233
|
-
if (!writePaths.has(relative)) {
|
|
234
|
-
throw new Error("candidate-patch-create-invalid");
|
|
235
|
-
}
|
|
236
|
-
const state = load(relative);
|
|
237
|
-
if (state.base !== null || state.current !== null) {
|
|
238
|
-
throw new Error("candidate-patch-create-invalid");
|
|
239
|
-
}
|
|
240
|
-
state.current = operation.content;
|
|
241
|
-
state.mode = operation.mode === "executable" ? "100755" : "100644";
|
|
242
|
-
break;
|
|
243
|
-
}
|
|
244
|
-
case "delete": {
|
|
245
|
-
if (!exactKeys(operation, ["kind", "path"])) {
|
|
246
|
-
throw new Error("candidate-patch-delete-invalid");
|
|
247
|
-
}
|
|
248
|
-
const relative = requirePath(operation.path);
|
|
249
|
-
if (!deletePaths.has(relative)) {
|
|
250
|
-
throw new Error("candidate-patch-delete-invalid");
|
|
251
|
-
}
|
|
252
|
-
const state = load(relative);
|
|
253
|
-
if (state.base === null || state.current === null) {
|
|
254
|
-
throw new Error("candidate-patch-delete-invalid");
|
|
255
|
-
}
|
|
256
|
-
state.current = null;
|
|
257
|
-
break;
|
|
258
|
-
}
|
|
259
|
-
default:
|
|
260
|
-
throw new Error("candidate-patch-operation-invalid");
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
const diff = [...states.values()]
|
|
265
|
-
.filter((state) => state.base !== state.current)
|
|
266
|
-
.sort((left, right) => compareCanonicalStrings(left.path, right.path))
|
|
267
|
-
.map(renderFileDiff)
|
|
268
|
-
.join("");
|
|
269
|
-
if (diff.length === 0) throw new Error("candidate-patch-empty");
|
|
270
|
-
return diff;
|
|
271
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
|
-
import { lstatSync, readFileSync } from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { observeSafePath } from "./safe-path.ts";
|
|
5
|
-
|
|
6
|
-
export function runGitApply(
|
|
7
|
-
root: string,
|
|
8
|
-
diff: Uint8Array,
|
|
9
|
-
checkOnly: boolean,
|
|
10
|
-
signal: AbortSignal,
|
|
11
|
-
): Promise<"ok" | "failed" | "cancelled"> {
|
|
12
|
-
if (signal.aborted) return Promise.resolve("cancelled");
|
|
13
|
-
return new Promise((resolve) => {
|
|
14
|
-
let settled = false;
|
|
15
|
-
const settle = (value: "ok" | "failed" | "cancelled") => {
|
|
16
|
-
if (settled) return;
|
|
17
|
-
settled = true;
|
|
18
|
-
signal.removeEventListener("abort", abort);
|
|
19
|
-
resolve(value);
|
|
20
|
-
};
|
|
21
|
-
const child = spawn(
|
|
22
|
-
"git",
|
|
23
|
-
[
|
|
24
|
-
// Candidate patches bind exact bytes, independent of host checkout
|
|
25
|
-
// preferences. Git's Windows autocrlf default must not rewrite them.
|
|
26
|
-
"-c",
|
|
27
|
-
"core.autocrlf=false",
|
|
28
|
-
"-c",
|
|
29
|
-
"core.eol=lf",
|
|
30
|
-
"apply",
|
|
31
|
-
...(checkOnly ? ["--check"] : []),
|
|
32
|
-
"--recount",
|
|
33
|
-
"--whitespace=nowarn",
|
|
34
|
-
"-",
|
|
35
|
-
],
|
|
36
|
-
{ cwd: root, shell: false, stdio: ["pipe", "ignore", "ignore"] },
|
|
37
|
-
);
|
|
38
|
-
const abort = () => {
|
|
39
|
-
child.kill("SIGTERM");
|
|
40
|
-
settle("cancelled");
|
|
41
|
-
};
|
|
42
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
43
|
-
child.once("error", () => settle(signal.aborted ? "cancelled" : "failed"));
|
|
44
|
-
child.once("close", (code) =>
|
|
45
|
-
settle(signal.aborted ? "cancelled" : code === 0 ? "ok" : "failed"),
|
|
46
|
-
);
|
|
47
|
-
child.stdin.on("error", () => undefined);
|
|
48
|
-
child.stdin.end(Buffer.from(diff));
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
export function revisionChanges(
|
|
52
|
-
root: string,
|
|
53
|
-
paths: readonly string[],
|
|
54
|
-
): Record<
|
|
55
|
-
string,
|
|
56
|
-
{ kind: "absent" } | { kind: "file"; bytes: Uint8Array; mode: number }
|
|
57
|
-
> {
|
|
58
|
-
const changes: Record<
|
|
59
|
-
string,
|
|
60
|
-
{ kind: "absent" } | { kind: "file"; bytes: Uint8Array; mode: number }
|
|
61
|
-
> = {};
|
|
62
|
-
for (const relative of [...new Set(paths)].sort()) {
|
|
63
|
-
const observation = observeSafePath(root, relative);
|
|
64
|
-
if (observation.kind === "absent") {
|
|
65
|
-
changes[relative] = { kind: "absent" };
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
if (observation.kind !== "file") {
|
|
69
|
-
throw new Error("workflow-candidate-path-unsafe");
|
|
70
|
-
}
|
|
71
|
-
const target = path.join(root, ...relative.split("/"));
|
|
72
|
-
const stat = lstatSync(target);
|
|
73
|
-
changes[relative] = {
|
|
74
|
-
kind: "file",
|
|
75
|
-
bytes: readFileSync(target),
|
|
76
|
-
mode: stat.mode & 0o777,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
return changes;
|
|
80
|
-
}
|
package/src/canonical.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/** Canonical identity ordering is UTF-16 code-unit order, never host collation. */
|
|
2
|
-
export function compareCanonicalStrings(left: string, right: string): number {
|
|
3
|
-
return left < right ? -1 : left > right ? 1 : 0;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export function canonicalJson(value: unknown): string {
|
|
7
|
-
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
8
|
-
if (value && typeof value === "object") {
|
|
9
|
-
return `{${Object.entries(value as Record<string, unknown>)
|
|
10
|
-
.filter(([, entry]) => entry !== undefined)
|
|
11
|
-
.sort(([left], [right]) => compareCanonicalStrings(left, right))
|
|
12
|
-
.map(([key, entry]) => `${JSON.stringify(key)}:${canonicalJson(entry)}`)
|
|
13
|
-
.join(",")}}`;
|
|
14
|
-
}
|
|
15
|
-
return JSON.stringify(value) ?? "null";
|
|
16
|
-
}
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { Type } from "typebox";
|
|
2
|
-
import { Value } from "typebox/value";
|
|
3
|
-
import {
|
|
4
|
-
isValidRelativePath,
|
|
5
|
-
VERIFICATION_LIMITS,
|
|
6
|
-
validateVerificationContract,
|
|
7
|
-
} from "./contracts.ts";
|
|
8
|
-
import type { DesignPlanDiagnostic } from "./design-diagnostics.ts";
|
|
9
|
-
|
|
10
|
-
const text = Type.String({ minLength: 1, maxLength: 8192, pattern: "\\S" });
|
|
11
|
-
const id = Type.String({ pattern: "^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$" });
|
|
12
|
-
const object = <T extends Parameters<typeof Type.Object>[0]>(properties: T) =>
|
|
13
|
-
Type.Object(properties, { additionalProperties: false });
|
|
14
|
-
const managers = Type.Union([
|
|
15
|
-
Type.Literal("bun"),
|
|
16
|
-
Type.Literal("npm"),
|
|
17
|
-
Type.Literal("pnpm"),
|
|
18
|
-
Type.Literal("yarn"),
|
|
19
|
-
]);
|
|
20
|
-
const packageRunner = {
|
|
21
|
-
kind: Type.Literal("package-script"),
|
|
22
|
-
packageManager: managers,
|
|
23
|
-
script: text,
|
|
24
|
-
command: text,
|
|
25
|
-
};
|
|
26
|
-
const executable = Type.Union([
|
|
27
|
-
object(packageRunner),
|
|
28
|
-
object({ kind: Type.Literal("local-binary"), executable: text }),
|
|
29
|
-
object({
|
|
30
|
-
kind: Type.Literal("npx"),
|
|
31
|
-
executable: text,
|
|
32
|
-
noInstall: Type.Literal(true),
|
|
33
|
-
}),
|
|
34
|
-
]);
|
|
35
|
-
const classification = Type.Union([
|
|
36
|
-
Type.Literal("expected-red"),
|
|
37
|
-
Type.Literal("expected-green"),
|
|
38
|
-
Type.Literal("expected-refactor"),
|
|
39
|
-
]);
|
|
40
|
-
const base = {
|
|
41
|
-
id,
|
|
42
|
-
classification,
|
|
43
|
-
expectedFailure: Type.Optional(Type.String({ minLength: 1, maxLength: 512 })),
|
|
44
|
-
executionBindings: Type.Optional(
|
|
45
|
-
Type.Record(Type.String(), Type.Union([Type.String(), Type.Null()])),
|
|
46
|
-
),
|
|
47
|
-
};
|
|
48
|
-
const args = Type.Array(Type.String(), { maxItems: 128 });
|
|
49
|
-
export const ATOMIC_VERIFICATION_SCHEMAS = {
|
|
50
|
-
vitest: object({
|
|
51
|
-
...base,
|
|
52
|
-
kind: Type.Literal("vitest"),
|
|
53
|
-
runner: executable,
|
|
54
|
-
testFiles: Type.Array(text, {
|
|
55
|
-
minItems: VERIFICATION_LIMITS.minTestFiles,
|
|
56
|
-
maxItems: VERIFICATION_LIMITS.maxTestFiles,
|
|
57
|
-
uniqueItems: true,
|
|
58
|
-
}),
|
|
59
|
-
args,
|
|
60
|
-
minTests: Type.Integer({ minimum: 1 }),
|
|
61
|
-
}),
|
|
62
|
-
"package-script": object({ ...base, ...packageRunner, args }),
|
|
63
|
-
"static-check": object({
|
|
64
|
-
...base,
|
|
65
|
-
kind: Type.Literal("static-check"),
|
|
66
|
-
runner: Type.Union([
|
|
67
|
-
executable,
|
|
68
|
-
object({ kind: Type.Literal("node"), script: text }),
|
|
69
|
-
]),
|
|
70
|
-
args,
|
|
71
|
-
}),
|
|
72
|
-
};
|
|
73
|
-
const atomic = Type.Union(Object.values(ATOMIC_VERIFICATION_SCHEMAS));
|
|
74
|
-
const steps = object({
|
|
75
|
-
kind: Type.Literal("steps"),
|
|
76
|
-
id,
|
|
77
|
-
classification,
|
|
78
|
-
steps: Type.Array(atomic, {
|
|
79
|
-
minItems: VERIFICATION_LIMITS.minSteps,
|
|
80
|
-
maxItems: VERIFICATION_LIMITS.maxSteps,
|
|
81
|
-
}),
|
|
82
|
-
});
|
|
83
|
-
export const VERIFICATION_SCHEMA = Type.Union([atomic, steps]);
|
|
84
|
-
export const CHANGE_CONTRACT_SCHEMA = object({
|
|
85
|
-
goal: text,
|
|
86
|
-
acceptance: Type.Array(
|
|
87
|
-
object({ id, statement: text, verification: VERIFICATION_SCHEMA }),
|
|
88
|
-
{ minItems: 1, maxItems: 256 },
|
|
89
|
-
),
|
|
90
|
-
constraints: Type.Array(object({ id, statement: text }), { maxItems: 256 }),
|
|
91
|
-
policy: object({
|
|
92
|
-
writeRoots: Type.Array(text, {
|
|
93
|
-
minItems: 1,
|
|
94
|
-
maxItems: 256,
|
|
95
|
-
uniqueItems: true,
|
|
96
|
-
}),
|
|
97
|
-
dependencies: Type.Array(text, { maxItems: 256, uniqueItems: true }),
|
|
98
|
-
verificationModes: Type.Array(
|
|
99
|
-
Type.Union([
|
|
100
|
-
Type.Literal("behavior"),
|
|
101
|
-
Type.Literal("mechanical"),
|
|
102
|
-
Type.Literal("refactor"),
|
|
103
|
-
]),
|
|
104
|
-
{ minItems: 1, maxItems: 256, uniqueItems: true },
|
|
105
|
-
),
|
|
106
|
-
}),
|
|
107
|
-
});
|
|
108
|
-
function record(value: unknown): value is Record<string, unknown> {
|
|
109
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const schemaFields = new Set([
|
|
113
|
-
"goal",
|
|
114
|
-
"acceptance",
|
|
115
|
-
"id",
|
|
116
|
-
"statement",
|
|
117
|
-
"verification",
|
|
118
|
-
"constraints",
|
|
119
|
-
"policy",
|
|
120
|
-
"writeRoots",
|
|
121
|
-
"dependencies",
|
|
122
|
-
"verificationModes",
|
|
123
|
-
"classification",
|
|
124
|
-
"expectedFailure",
|
|
125
|
-
"executionBindings",
|
|
126
|
-
"kind",
|
|
127
|
-
"runner",
|
|
128
|
-
"packageManager",
|
|
129
|
-
"script",
|
|
130
|
-
"command",
|
|
131
|
-
"executable",
|
|
132
|
-
"noInstall",
|
|
133
|
-
"testFiles",
|
|
134
|
-
"args",
|
|
135
|
-
"minTests",
|
|
136
|
-
"steps",
|
|
137
|
-
]);
|
|
138
|
-
function diagnosticField(pointer: string): string {
|
|
139
|
-
const fields = ["contract"];
|
|
140
|
-
for (const part of pointer.split("/").slice(1)) {
|
|
141
|
-
if (!schemaFields.has(part) && !/^(0|[1-9][0-9]{0,5})$/u.test(part)) break;
|
|
142
|
-
fields.push(part);
|
|
143
|
-
// Binding keys are author data, even when they happen to look like schema fields.
|
|
144
|
-
if (part === "executionBindings") break;
|
|
145
|
-
}
|
|
146
|
-
return fields.join(".");
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/** Shared shape, bounded field-only diagnostics; never return submitted values or parser messages. */
|
|
150
|
-
export function changeContractDiagnostics(
|
|
151
|
-
value: unknown,
|
|
152
|
-
): DesignPlanDiagnostic[] {
|
|
153
|
-
const diagnostics: DesignPlanDiagnostic[] = Value.Errors(
|
|
154
|
-
CHANGE_CONTRACT_SCHEMA,
|
|
155
|
-
value,
|
|
156
|
-
)
|
|
157
|
-
.slice(0, 32)
|
|
158
|
-
.map((error) => ({
|
|
159
|
-
code: "change-contract-field-invalid",
|
|
160
|
-
field: diagnosticField(error.instancePath),
|
|
161
|
-
category: error.keyword,
|
|
162
|
-
}));
|
|
163
|
-
if (!record(value)) return diagnostics;
|
|
164
|
-
if (Array.isArray(value.acceptance))
|
|
165
|
-
value.acceptance.slice(0, 256).forEach((item, index) => {
|
|
166
|
-
if (!record(item)) return;
|
|
167
|
-
const verification = item.verification;
|
|
168
|
-
if (!validateVerificationContract(verification).ok) {
|
|
169
|
-
const field = `contract.acceptance.${index}.verification`;
|
|
170
|
-
if (
|
|
171
|
-
record(verification) &&
|
|
172
|
-
verification.classification === "expected-red" &&
|
|
173
|
-
typeof verification.expectedFailure !== "string"
|
|
174
|
-
)
|
|
175
|
-
diagnostics.push({
|
|
176
|
-
code: "change-contract-field-invalid",
|
|
177
|
-
field: `${field}.expectedFailure`,
|
|
178
|
-
});
|
|
179
|
-
else diagnostics.push({ code: "change-contract-field-invalid", field });
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
if (record(value.policy) && Array.isArray(value.policy.writeRoots))
|
|
183
|
-
value.policy.writeRoots.slice(0, 256).forEach((root, index) => {
|
|
184
|
-
if (root !== "." && !isValidRelativePath(root))
|
|
185
|
-
diagnostics.push({
|
|
186
|
-
code: "change-contract-field-invalid",
|
|
187
|
-
field: `contract.policy.writeRoots.${index}`,
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
return diagnostics.slice(0, 32);
|
|
191
|
-
}
|