@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.
Files changed (208) hide show
  1. package/README.md +324 -111
  2. package/THIRD_PARTY_NOTICES.md +15 -0
  3. package/agents/design-explorer.md +14 -26
  4. package/agents/diagnosis-worker.md +14 -25
  5. package/agents/implementation-worker.md +16 -35
  6. package/config/.env.example +2 -5
  7. package/config/workflow-task.example.json +7 -0
  8. package/docs/remote-access.md +60 -0
  9. package/docs/reuse-and-distribution.md +44 -0
  10. package/docs/service-management.md +108 -0
  11. package/licenses/bundled-web.txt +6245 -0
  12. package/licenses/pi-web-ui-MIT.txt +21 -0
  13. package/licenses/pi-web-ui-reuse.md +22 -0
  14. package/package.json +94 -21
  15. package/src/index.ts +22 -1807
  16. package/src/native-build.ts +6 -0
  17. package/src/native-client.ts +103 -0
  18. package/src/native-export.ts +58 -0
  19. package/src/native-history.ts +359 -0
  20. package/src/operator-cli.mjs +453 -1937
  21. package/src/plan-proposal.ts +87 -0
  22. package/src/sdk-worker.mjs +549 -0
  23. package/src/service/contracts/active.ts +82 -0
  24. package/src/service/contracts/budget.ts +148 -0
  25. package/src/service/contracts/build.ts +67 -0
  26. package/src/service/contracts/capture.ts +48 -0
  27. package/src/service/contracts/core.ts +33 -0
  28. package/src/service/contracts/current.ts +261 -0
  29. package/src/service/contracts/domain.ts +68 -0
  30. package/src/service/contracts/history.ts +2245 -0
  31. package/src/service/contracts/models.ts +139 -0
  32. package/src/service/coordination.ts +862 -0
  33. package/src/service/private-files.ts +204 -0
  34. package/src/service-cli.mjs +5592 -0
  35. package/src/service-client.ts +747 -0
  36. package/src/service-contract.ts +245 -0
  37. package/src/service-host.mjs +22382 -0
  38. package/src/service-http-client.ts +425 -0
  39. package/src/service-wire.ts +372 -0
  40. package/src/task-shell.ts +1045 -0
  41. package/src/task-store.ts +479 -0
  42. package/src/task-types.ts +184 -0
  43. package/src/verification-diagnostics.ts +29 -72
  44. package/src/worker-capture.mjs +1197 -0
  45. package/src/worker-public.mjs +1753 -0
  46. package/src/worker-redaction.mjs +608 -0
  47. package/src/worker-tools.mjs +202 -0
  48. package/web/dist/assets/KaTeX_AMS-Regular.ttf +0 -0
  49. package/web/dist/assets/KaTeX_AMS-Regular.woff +0 -0
  50. package/web/dist/assets/KaTeX_AMS-Regular.woff2 +0 -0
  51. package/web/dist/assets/KaTeX_Caligraphic-Bold.ttf +0 -0
  52. package/web/dist/assets/KaTeX_Caligraphic-Bold.woff +0 -0
  53. package/web/dist/assets/KaTeX_Caligraphic-Bold.woff2 +0 -0
  54. package/web/dist/assets/KaTeX_Caligraphic-Regular.ttf +0 -0
  55. package/web/dist/assets/KaTeX_Caligraphic-Regular.woff +0 -0
  56. package/web/dist/assets/KaTeX_Caligraphic-Regular.woff2 +0 -0
  57. package/web/dist/assets/KaTeX_Fraktur-Bold.ttf +0 -0
  58. package/web/dist/assets/KaTeX_Fraktur-Bold.woff +0 -0
  59. package/web/dist/assets/KaTeX_Fraktur-Bold.woff2 +0 -0
  60. package/web/dist/assets/KaTeX_Fraktur-Regular.ttf +0 -0
  61. package/web/dist/assets/KaTeX_Fraktur-Regular.woff +0 -0
  62. package/web/dist/assets/KaTeX_Fraktur-Regular.woff2 +0 -0
  63. package/web/dist/assets/KaTeX_Main-Bold.ttf +0 -0
  64. package/web/dist/assets/KaTeX_Main-Bold.woff +0 -0
  65. package/web/dist/assets/KaTeX_Main-Bold.woff2 +0 -0
  66. package/web/dist/assets/KaTeX_Main-BoldItalic.ttf +0 -0
  67. package/web/dist/assets/KaTeX_Main-BoldItalic.woff +0 -0
  68. package/web/dist/assets/KaTeX_Main-BoldItalic.woff2 +0 -0
  69. package/web/dist/assets/KaTeX_Main-Italic.ttf +0 -0
  70. package/web/dist/assets/KaTeX_Main-Italic.woff +0 -0
  71. package/web/dist/assets/KaTeX_Main-Italic.woff2 +0 -0
  72. package/web/dist/assets/KaTeX_Main-Regular.ttf +0 -0
  73. package/web/dist/assets/KaTeX_Main-Regular.woff +0 -0
  74. package/web/dist/assets/KaTeX_Main-Regular.woff2 +0 -0
  75. package/web/dist/assets/KaTeX_Math-BoldItalic.ttf +0 -0
  76. package/web/dist/assets/KaTeX_Math-BoldItalic.woff +0 -0
  77. package/web/dist/assets/KaTeX_Math-BoldItalic.woff2 +0 -0
  78. package/web/dist/assets/KaTeX_Math-Italic.ttf +0 -0
  79. package/web/dist/assets/KaTeX_Math-Italic.woff +0 -0
  80. package/web/dist/assets/KaTeX_Math-Italic.woff2 +0 -0
  81. package/web/dist/assets/KaTeX_SansSerif-Bold.ttf +0 -0
  82. package/web/dist/assets/KaTeX_SansSerif-Bold.woff +0 -0
  83. package/web/dist/assets/KaTeX_SansSerif-Bold.woff2 +0 -0
  84. package/web/dist/assets/KaTeX_SansSerif-Italic.ttf +0 -0
  85. package/web/dist/assets/KaTeX_SansSerif-Italic.woff +0 -0
  86. package/web/dist/assets/KaTeX_SansSerif-Italic.woff2 +0 -0
  87. package/web/dist/assets/KaTeX_SansSerif-Regular.ttf +0 -0
  88. package/web/dist/assets/KaTeX_SansSerif-Regular.woff +0 -0
  89. package/web/dist/assets/KaTeX_SansSerif-Regular.woff2 +0 -0
  90. package/web/dist/assets/KaTeX_Script-Regular.ttf +0 -0
  91. package/web/dist/assets/KaTeX_Script-Regular.woff +0 -0
  92. package/web/dist/assets/KaTeX_Script-Regular.woff2 +0 -0
  93. package/web/dist/assets/KaTeX_Size1-Regular.ttf +0 -0
  94. package/web/dist/assets/KaTeX_Size1-Regular.woff +0 -0
  95. package/web/dist/assets/KaTeX_Size1-Regular.woff2 +0 -0
  96. package/web/dist/assets/KaTeX_Size2-Regular.ttf +0 -0
  97. package/web/dist/assets/KaTeX_Size2-Regular.woff +0 -0
  98. package/web/dist/assets/KaTeX_Size2-Regular.woff2 +0 -0
  99. package/web/dist/assets/KaTeX_Size3-Regular.ttf +0 -0
  100. package/web/dist/assets/KaTeX_Size3-Regular.woff +0 -0
  101. package/web/dist/assets/KaTeX_Size3-Regular.woff2 +0 -0
  102. package/web/dist/assets/KaTeX_Size4-Regular.ttf +0 -0
  103. package/web/dist/assets/KaTeX_Size4-Regular.woff +0 -0
  104. package/web/dist/assets/KaTeX_Size4-Regular.woff2 +0 -0
  105. package/web/dist/assets/KaTeX_Typewriter-Regular.ttf +0 -0
  106. package/web/dist/assets/KaTeX_Typewriter-Regular.woff +0 -0
  107. package/web/dist/assets/KaTeX_Typewriter-Regular.woff2 +0 -0
  108. package/web/dist/assets/cadence.css +2 -0
  109. package/web/dist/assets/cadence.js +7 -0
  110. package/web/dist/assets/markdown.js +296 -0
  111. package/web/dist/assets/react.js +9 -0
  112. package/web/dist/assets/rolldown-runtime.js +1 -0
  113. package/web/dist/assets/timeline-client.js +41 -0
  114. package/web/dist/assets/vis-timeline.css +1274 -0
  115. package/web/dist/assets/vis-timeline.js +32 -0
  116. package/web/dist/index.html +18 -0
  117. package/web/dist/manifest.json +505 -0
  118. package/config/plan-draft.example.json +0 -125
  119. package/config/plan-draft.multiple-tasks.example.json +0 -375
  120. package/config/plan-draft.quick.example.json +0 -78
  121. package/config/routes.example.json +0 -39
  122. package/prompts/abel-design.md +0 -382
  123. package/prompts/abel-diagnose.md +0 -71
  124. package/prompts/abel-implement.md +0 -284
  125. package/prompts/abel-init.md +0 -52
  126. package/src/activation.ts +0 -44
  127. package/src/activity-contracts.ts +0 -82
  128. package/src/agent-registry.ts +0 -53
  129. package/src/apply-transaction.ts +0 -1437
  130. package/src/artifact-store.ts +0 -213
  131. package/src/build-windows-job.mjs +0 -95
  132. package/src/candidate-artifact.ts +0 -143
  133. package/src/candidate-patch.ts +0 -271
  134. package/src/candidate-workspace.ts +0 -80
  135. package/src/canonical.ts +0 -16
  136. package/src/change-contract-schema.ts +0 -191
  137. package/src/change-contract.ts +0 -324
  138. package/src/change-verification.ts +0 -1617
  139. package/src/child-budget.ts +0 -58
  140. package/src/child-model.ts +0 -142
  141. package/src/child-session.ts +0 -640
  142. package/src/contracts.ts +0 -2476
  143. package/src/control-contracts.ts +0 -382
  144. package/src/delivery-compiler.ts +0 -1805
  145. package/src/delivery-revision.ts +0 -42
  146. package/src/design-control.ts +0 -1299
  147. package/src/design-diagnostics.ts +0 -181
  148. package/src/design-journal.ts +0 -1773
  149. package/src/directory-sync.ts +0 -36
  150. package/src/durable-contracts.ts +0 -231
  151. package/src/durable-workflow.ts +0 -978
  152. package/src/evidence-draft.ts +0 -122
  153. package/src/execution-profile.ts +0 -64
  154. package/src/execution-retention.ts +0 -77
  155. package/src/file-snapshot.ts +0 -163
  156. package/src/implement-continuation.ts +0 -559
  157. package/src/implement-graph.ts +0 -690
  158. package/src/implement-plan.ts +0 -72
  159. package/src/install-config.d.mts +0 -6
  160. package/src/isolation-backend.ts +0 -353
  161. package/src/model-source.ts +0 -22
  162. package/src/openspec-cli.ts +0 -494
  163. package/src/operator-cli-entry.mjs +0 -24
  164. package/src/operator-tools.ts +0 -309
  165. package/src/package-candidate.ts +0 -227
  166. package/src/package-delivery.ts +0 -486
  167. package/src/package-state.ts +0 -320
  168. package/src/package-verification.ts +0 -635
  169. package/src/package-workflow.ts +0 -342
  170. package/src/packet-runtime.ts +0 -570
  171. package/src/parent-provider.ts +0 -375
  172. package/src/phase-execution.ts +0 -2259
  173. package/src/pi-adapter.ts +0 -19
  174. package/src/plan-draft-summary.ts +0 -527
  175. package/src/plan-draft.ts +0 -502
  176. package/src/remove-path.ts +0 -32
  177. package/src/route-policy.ts +0 -545
  178. package/src/run-state.ts +0 -420
  179. package/src/run-store.ts +0 -1179
  180. package/src/safe-path.ts +0 -77
  181. package/src/scoped-grep-worker.mjs +0 -23
  182. package/src/scoped-tools.ts +0 -775
  183. package/src/single-task-draft.ts +0 -142
  184. package/src/sqlite-schema.ts +0 -171
  185. package/src/state-root.ts +0 -215
  186. package/src/storage-schema.ts +0 -360
  187. package/src/subagent-activity.ts +0 -1417
  188. package/src/submit-tool.ts +0 -950
  189. package/src/task-ledger.ts +0 -1338
  190. package/src/transport-budget.ts +0 -52
  191. package/src/verification-capability.ts +0 -1191
  192. package/src/verification-environment-io.ts +0 -389
  193. package/src/verification-environment.ts +0 -162
  194. package/src/verification-identity.ts +0 -77
  195. package/src/verification-scan.ts +0 -64
  196. package/src/windows-job-backend.ts +0 -419
  197. package/src/windows-job.c +0 -149
  198. package/src/worker-broker.ts +0 -806
  199. package/src/workflow-engine.ts +0 -28
  200. package/src/workflow-policy.ts +0 -1679
  201. package/src/workflow-recovery-policy.ts +0 -97
  202. package/src/workflow-scheduling.ts +0 -105
  203. package/src/workflow-state-machine.ts +0 -4355
  204. package/src/workflow-status.ts +0 -576
  205. package/src/workspace-io-entry.mjs +0 -76
  206. package/src/workspace-io-worker.mjs +0 -1312
  207. package/src/workspace-io.ts +0 -89
  208. package/src/workspace-store.ts +0 -634
@@ -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
- }