@abelxiaoxing/cadence 1.8.4 → 2.0.1

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 (202) hide show
  1. package/README.md +324 -117
  2. package/THIRD_PARTY_NOTICES.md +15 -0
  3. package/agents/design-explorer.md +14 -18
  4. package/agents/diagnosis-worker.md +14 -14
  5. package/agents/implementation-worker.md +16 -17
  6. package/config/workflow-task.example.json +7 -0
  7. package/docs/remote-access.md +60 -0
  8. package/docs/reuse-and-distribution.md +44 -0
  9. package/docs/service-management.md +108 -0
  10. package/licenses/bundled-web.txt +6245 -0
  11. package/licenses/pi-web-ui-MIT.txt +21 -0
  12. package/licenses/pi-web-ui-reuse.md +22 -0
  13. package/package.json +92 -20
  14. package/src/index.ts +21 -1802
  15. package/src/native-build.ts +6 -0
  16. package/src/native-client.ts +103 -0
  17. package/src/native-export.ts +58 -0
  18. package/src/native-history.ts +359 -0
  19. package/src/operator-cli.mjs +453 -1937
  20. package/src/plan-proposal.ts +87 -0
  21. package/src/sdk-worker.mjs +549 -0
  22. package/src/service/contracts/active.ts +82 -0
  23. package/src/service/contracts/budget.ts +148 -0
  24. package/src/service/contracts/build.ts +67 -0
  25. package/src/service/contracts/capture.ts +48 -0
  26. package/src/service/contracts/core.ts +33 -0
  27. package/src/service/contracts/current.ts +261 -0
  28. package/src/service/contracts/domain.ts +68 -0
  29. package/src/service/contracts/history.ts +2245 -0
  30. package/src/service/contracts/models.ts +139 -0
  31. package/src/service/coordination.ts +862 -0
  32. package/src/service/private-files.ts +204 -0
  33. package/src/service-cli.mjs +5592 -0
  34. package/src/service-client.ts +747 -0
  35. package/src/service-contract.ts +245 -0
  36. package/src/service-host.mjs +22382 -0
  37. package/src/service-http-client.ts +425 -0
  38. package/src/service-wire.ts +372 -0
  39. package/src/task-shell.ts +1045 -0
  40. package/src/task-store.ts +479 -0
  41. package/src/task-types.ts +184 -0
  42. package/src/verification-diagnostics.ts +29 -72
  43. package/src/worker-capture.mjs +1197 -0
  44. package/src/worker-public.mjs +1753 -0
  45. package/src/worker-redaction.mjs +608 -0
  46. package/src/worker-tools.mjs +202 -0
  47. package/web/dist/assets/KaTeX_AMS-Regular.ttf +0 -0
  48. package/web/dist/assets/KaTeX_AMS-Regular.woff +0 -0
  49. package/web/dist/assets/KaTeX_AMS-Regular.woff2 +0 -0
  50. package/web/dist/assets/KaTeX_Caligraphic-Bold.ttf +0 -0
  51. package/web/dist/assets/KaTeX_Caligraphic-Bold.woff +0 -0
  52. package/web/dist/assets/KaTeX_Caligraphic-Bold.woff2 +0 -0
  53. package/web/dist/assets/KaTeX_Caligraphic-Regular.ttf +0 -0
  54. package/web/dist/assets/KaTeX_Caligraphic-Regular.woff +0 -0
  55. package/web/dist/assets/KaTeX_Caligraphic-Regular.woff2 +0 -0
  56. package/web/dist/assets/KaTeX_Fraktur-Bold.ttf +0 -0
  57. package/web/dist/assets/KaTeX_Fraktur-Bold.woff +0 -0
  58. package/web/dist/assets/KaTeX_Fraktur-Bold.woff2 +0 -0
  59. package/web/dist/assets/KaTeX_Fraktur-Regular.ttf +0 -0
  60. package/web/dist/assets/KaTeX_Fraktur-Regular.woff +0 -0
  61. package/web/dist/assets/KaTeX_Fraktur-Regular.woff2 +0 -0
  62. package/web/dist/assets/KaTeX_Main-Bold.ttf +0 -0
  63. package/web/dist/assets/KaTeX_Main-Bold.woff +0 -0
  64. package/web/dist/assets/KaTeX_Main-Bold.woff2 +0 -0
  65. package/web/dist/assets/KaTeX_Main-BoldItalic.ttf +0 -0
  66. package/web/dist/assets/KaTeX_Main-BoldItalic.woff +0 -0
  67. package/web/dist/assets/KaTeX_Main-BoldItalic.woff2 +0 -0
  68. package/web/dist/assets/KaTeX_Main-Italic.ttf +0 -0
  69. package/web/dist/assets/KaTeX_Main-Italic.woff +0 -0
  70. package/web/dist/assets/KaTeX_Main-Italic.woff2 +0 -0
  71. package/web/dist/assets/KaTeX_Main-Regular.ttf +0 -0
  72. package/web/dist/assets/KaTeX_Main-Regular.woff +0 -0
  73. package/web/dist/assets/KaTeX_Main-Regular.woff2 +0 -0
  74. package/web/dist/assets/KaTeX_Math-BoldItalic.ttf +0 -0
  75. package/web/dist/assets/KaTeX_Math-BoldItalic.woff +0 -0
  76. package/web/dist/assets/KaTeX_Math-BoldItalic.woff2 +0 -0
  77. package/web/dist/assets/KaTeX_Math-Italic.ttf +0 -0
  78. package/web/dist/assets/KaTeX_Math-Italic.woff +0 -0
  79. package/web/dist/assets/KaTeX_Math-Italic.woff2 +0 -0
  80. package/web/dist/assets/KaTeX_SansSerif-Bold.ttf +0 -0
  81. package/web/dist/assets/KaTeX_SansSerif-Bold.woff +0 -0
  82. package/web/dist/assets/KaTeX_SansSerif-Bold.woff2 +0 -0
  83. package/web/dist/assets/KaTeX_SansSerif-Italic.ttf +0 -0
  84. package/web/dist/assets/KaTeX_SansSerif-Italic.woff +0 -0
  85. package/web/dist/assets/KaTeX_SansSerif-Italic.woff2 +0 -0
  86. package/web/dist/assets/KaTeX_SansSerif-Regular.ttf +0 -0
  87. package/web/dist/assets/KaTeX_SansSerif-Regular.woff +0 -0
  88. package/web/dist/assets/KaTeX_SansSerif-Regular.woff2 +0 -0
  89. package/web/dist/assets/KaTeX_Script-Regular.ttf +0 -0
  90. package/web/dist/assets/KaTeX_Script-Regular.woff +0 -0
  91. package/web/dist/assets/KaTeX_Script-Regular.woff2 +0 -0
  92. package/web/dist/assets/KaTeX_Size1-Regular.ttf +0 -0
  93. package/web/dist/assets/KaTeX_Size1-Regular.woff +0 -0
  94. package/web/dist/assets/KaTeX_Size1-Regular.woff2 +0 -0
  95. package/web/dist/assets/KaTeX_Size2-Regular.ttf +0 -0
  96. package/web/dist/assets/KaTeX_Size2-Regular.woff +0 -0
  97. package/web/dist/assets/KaTeX_Size2-Regular.woff2 +0 -0
  98. package/web/dist/assets/KaTeX_Size3-Regular.ttf +0 -0
  99. package/web/dist/assets/KaTeX_Size3-Regular.woff +0 -0
  100. package/web/dist/assets/KaTeX_Size3-Regular.woff2 +0 -0
  101. package/web/dist/assets/KaTeX_Size4-Regular.ttf +0 -0
  102. package/web/dist/assets/KaTeX_Size4-Regular.woff +0 -0
  103. package/web/dist/assets/KaTeX_Size4-Regular.woff2 +0 -0
  104. package/web/dist/assets/KaTeX_Typewriter-Regular.ttf +0 -0
  105. package/web/dist/assets/KaTeX_Typewriter-Regular.woff +0 -0
  106. package/web/dist/assets/KaTeX_Typewriter-Regular.woff2 +0 -0
  107. package/web/dist/assets/cadence.css +2 -0
  108. package/web/dist/assets/cadence.js +7 -0
  109. package/web/dist/assets/markdown.js +296 -0
  110. package/web/dist/assets/react.js +9 -0
  111. package/web/dist/assets/rolldown-runtime.js +1 -0
  112. package/web/dist/assets/timeline-client.js +41 -0
  113. package/web/dist/assets/vis-timeline.css +1274 -0
  114. package/web/dist/assets/vis-timeline.js +32 -0
  115. package/web/dist/index.html +18 -0
  116. package/web/dist/manifest.json +505 -0
  117. package/config/plan-draft.example.json +0 -125
  118. package/config/plan-draft.multiple-tasks.example.json +0 -375
  119. package/config/plan-draft.quick.example.json +0 -78
  120. package/prompts/abel-design.md +0 -382
  121. package/prompts/abel-diagnose.md +0 -71
  122. package/prompts/abel-implement.md +0 -284
  123. package/prompts/abel-init.md +0 -52
  124. package/src/activation.ts +0 -44
  125. package/src/activity-contracts.ts +0 -82
  126. package/src/agent-registry.ts +0 -53
  127. package/src/apply-transaction.ts +0 -1437
  128. package/src/artifact-store.ts +0 -213
  129. package/src/build-windows-job.mjs +0 -95
  130. package/src/candidate-artifact.ts +0 -143
  131. package/src/candidate-context.ts +0 -289
  132. package/src/candidate-patch.ts +0 -271
  133. package/src/candidate-workspace.ts +0 -80
  134. package/src/canonical.ts +0 -16
  135. package/src/change-contract-schema.ts +0 -191
  136. package/src/change-contract.ts +0 -324
  137. package/src/change-verification.ts +0 -1617
  138. package/src/contracts.ts +0 -2466
  139. package/src/control-contracts.ts +0 -382
  140. package/src/delivery-compiler.ts +0 -1805
  141. package/src/delivery-revision.ts +0 -42
  142. package/src/design-control.ts +0 -1299
  143. package/src/design-diagnostics.ts +0 -181
  144. package/src/design-journal.ts +0 -1773
  145. package/src/directory-sync.ts +0 -36
  146. package/src/durable-contracts.ts +0 -227
  147. package/src/durable-workflow.ts +0 -822
  148. package/src/evidence-draft.ts +0 -122
  149. package/src/execution-profile.ts +0 -64
  150. package/src/execution-retention.ts +0 -77
  151. package/src/file-snapshot.ts +0 -163
  152. package/src/implement-continuation.ts +0 -559
  153. package/src/implement-graph.ts +0 -690
  154. package/src/implement-plan.ts +0 -72
  155. package/src/install-config.d.mts +0 -6
  156. package/src/isolation-backend.ts +0 -353
  157. package/src/model-source.ts +0 -22
  158. package/src/openspec-cli.ts +0 -494
  159. package/src/operator-cli-entry.mjs +0 -24
  160. package/src/operator-tools.ts +0 -309
  161. package/src/package-candidate-process.ts +0 -206
  162. package/src/package-candidate.ts +0 -24
  163. package/src/package-delivery.ts +0 -486
  164. package/src/package-state.ts +0 -320
  165. package/src/package-verification.ts +0 -635
  166. package/src/package-workflow.ts +0 -305
  167. package/src/packet-runtime.ts +0 -459
  168. package/src/phase-execution.ts +0 -2163
  169. package/src/pi-adapter.ts +0 -19
  170. package/src/plan-draft-summary.ts +0 -527
  171. package/src/plan-draft.ts +0 -502
  172. package/src/remove-path.ts +0 -32
  173. package/src/run-state.ts +0 -420
  174. package/src/run-store.ts +0 -1179
  175. package/src/safe-path.ts +0 -77
  176. package/src/scoped-grep-worker.mjs +0 -23
  177. package/src/scoped-tools.ts +0 -775
  178. package/src/single-task-draft.ts +0 -142
  179. package/src/sqlite-schema.ts +0 -171
  180. package/src/state-root.ts +0 -215
  181. package/src/storage-schema.ts +0 -360
  182. package/src/subagent-activity.ts +0 -1417
  183. package/src/subagent-process.ts +0 -476
  184. package/src/task-ledger.ts +0 -1338
  185. package/src/transport-budget.ts +0 -50
  186. package/src/verification-capability.ts +0 -1191
  187. package/src/verification-environment-io.ts +0 -389
  188. package/src/verification-environment.ts +0 -162
  189. package/src/verification-identity.ts +0 -77
  190. package/src/verification-scan.ts +0 -64
  191. package/src/windows-job-backend.ts +0 -419
  192. package/src/windows-job.c +0 -149
  193. package/src/workflow-engine.ts +0 -28
  194. package/src/workflow-policy.ts +0 -1670
  195. package/src/workflow-recovery-policy.ts +0 -97
  196. package/src/workflow-scheduling.ts +0 -105
  197. package/src/workflow-state-machine.ts +0 -4341
  198. package/src/workflow-status.ts +0 -576
  199. package/src/workspace-io-entry.mjs +0 -76
  200. package/src/workspace-io-worker.mjs +0 -1312
  201. package/src/workspace-io.ts +0 -89
  202. package/src/workspace-store.ts +0 -634
package/src/plan-draft.ts DELETED
@@ -1,502 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { canonicalJson, compareCanonicalStrings } from "./canonical.ts";
3
- import type { ChangeContract } from "./change-contract.ts";
4
- import {
5
- type AtomicVerificationContract,
6
- type ImplementGraphOutput,
7
- isValidRelativePath,
8
- type PhaseBoundary,
9
- type StructuredVerificationContract,
10
- validateVerificationContract,
11
- verificationInputPaths,
12
- } from "./contracts.ts";
13
- import {
14
- type DesignPlanDiagnostic,
15
- DesignPlanValidationError,
16
- } from "./design-diagnostics.ts";
17
- import type {
18
- PlanTaskDraft,
19
- PlanTracking,
20
- PlanVerification,
21
- } from "./implement-plan.ts";
22
-
23
- type DraftCommand<T> = T extends { kind: "package-script" }
24
- ? Omit<T, "command"> & { command?: string }
25
- : T;
26
- type DraftRunner<T> = T extends { runner: infer R }
27
- ? Omit<T, "runner"> & { runner: DraftCommand<R> }
28
- : DraftCommand<T>;
29
- type Template<T> = T extends AtomicVerificationContract
30
- ? DraftRunner<
31
- Omit<T, "id" | "classification" | "expectedFailure" | "executionBindings">
32
- >
33
- : never;
34
- export type VerificationDefinition = Template<AtomicVerificationContract>;
35
- export type DraftVerification =
36
- | StructuredVerificationContract
37
- | (VerificationDefinition & {
38
- id?: string;
39
- classification?: StructuredVerificationContract["classification"];
40
- expectedFailure?: string;
41
- })
42
- | { use: string; expectedFailure?: string };
43
- export type PlanPhaseDraft = Omit<
44
- PhaseBoundary,
45
- "verificationInputs" | "read" | "verification"
46
- > & {
47
- read?: string[];
48
- verification: DraftVerification;
49
- verificationInputs?: PhaseBoundary["verificationInputs"];
50
- };
51
- export interface PlanTaskInput
52
- extends Omit<
53
- PlanTaskDraft,
54
- | "phases"
55
- | "impactClosure"
56
- | "baselineVerification"
57
- | "affectedVerification"
58
- | "repairVerification"
59
- | "agents"
60
- > {
61
- read?: string[];
62
- phases: {
63
- red?: PlanPhaseDraft;
64
- green: PlanPhaseDraft;
65
- refactor?: PlanPhaseDraft;
66
- };
67
- affectedVerification: DraftVerification;
68
- baselineVerification?: DraftVerification;
69
- repairVerification: DraftVerification;
70
- agents: Omit<PlanTaskDraft["agents"], "managedOnly"> & { managedOnly?: true };
71
- impactClosure: Omit<PlanTaskDraft["impactClosure"], "relatedTests"> & {
72
- relatedTests: Array<
73
- Omit<
74
- PlanTaskDraft["impactClosure"]["relatedTests"][number],
75
- "disposition"
76
- > & {
77
- disposition?: PlanTaskDraft["impactClosure"]["relatedTests"][number]["disposition"];
78
- }
79
- >;
80
- };
81
- }
82
- export interface PlanVerificationInput {
83
- baseline: Partial<Omit<PlanVerification["baseline"], "fullSuite">> & {
84
- fullSuite: DraftVerification;
85
- };
86
- change: Partial<Pick<PlanVerification["change"], "affected">> & {
87
- fullSuite: DraftVerification;
88
- postApply: DraftVerification;
89
- };
90
- artifactCorrection: PlanVerification["artifactCorrection"];
91
- repair: Pick<PlanVerification["repair"], "maxAttempts"> &
92
- Partial<Omit<PlanVerification["repair"], "maxAttempts">>;
93
- agentsCheckpoint?: Omit<
94
- PlanVerification["agentsCheckpoint"],
95
- "verification"
96
- > & { verification: DraftVerification | null };
97
- }
98
- /** Authoring only. The sealed plan does not inherit this interface. */
99
- export interface PlanDraft {
100
- changeContract?: ChangeContract;
101
- changeId: string;
102
- tasks: PlanTaskInput[];
103
- outputs: ImplementGraphOutput[];
104
- verification: PlanVerificationInput;
105
- tracking?: PlanTracking;
106
- verificationDefinitions?: Record<string, VerificationDefinition>;
107
- }
108
- function isRecord(value: unknown): value is Record<string, unknown> {
109
- return value !== null && typeof value === "object" && !Array.isArray(value);
110
- }
111
- const ID = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/u;
112
-
113
- /** Expand finite, local syntax only. All authority and executable validation stays strict. */
114
- export function expandPlanDraft(value: unknown): unknown {
115
- if (
116
- !isRecord(value) ||
117
- !Array.isArray(value.tasks) ||
118
- value.tasks.length > 128
119
- )
120
- return value;
121
- const draft = structuredClone(value);
122
- const diagnostics: DesignPlanDiagnostic[] = [];
123
- const definitions = new Map<string, Record<string, unknown>>();
124
- const source = draft.verificationDefinitions;
125
- if (source !== undefined) {
126
- if (!isRecord(source) || Object.keys(source).length > 512) {
127
- throw new DesignPlanValidationError("verification-definition-invalid", [
128
- {
129
- code: "verification-definition-invalid",
130
- field: "verificationDefinitions",
131
- },
132
- ]);
133
- }
134
- for (const [name, definition] of Object.entries(source)) {
135
- const validated =
136
- isRecord(definition) &&
137
- ID.test(name) &&
138
- ![
139
- "id",
140
- "classification",
141
- "expectedFailure",
142
- "executionBindings",
143
- "use",
144
- "steps",
145
- ].some((key) => Object.hasOwn(definition, key)) &&
146
- validateVerificationContract({
147
- ...definition,
148
- id: "definition",
149
- classification: "expected-green",
150
- }).ok;
151
- if (!validated)
152
- diagnostics.push({
153
- code: "verification-definition-invalid",
154
- field: "verificationDefinitions",
155
- });
156
- else definitions.set(name, definition as Record<string, unknown>);
157
- }
158
- delete draft.verificationDefinitions;
159
- }
160
- const generated = new Set<string>();
161
- const authored = new Set<string>();
162
- const collect = (node: unknown): void => {
163
- if (Array.isArray(node)) node.forEach(collect);
164
- else if (isRecord(node)) {
165
- if (
166
- ["vitest", "static-check", "package-script", "steps"].includes(
167
- String(node.kind),
168
- ) &&
169
- typeof node.id === "string"
170
- )
171
- authored.add(node.id);
172
- Object.entries(node)
173
- .filter(([key]) => key !== "changeContract")
174
- .forEach(([, item]) => {
175
- collect(item);
176
- });
177
- }
178
- };
179
- collect(draft);
180
- const expand = (
181
- node: unknown,
182
- field: string,
183
- classification: "expected-red" | "expected-green" | "expected-refactor",
184
- taskId?: string,
185
- ): unknown => {
186
- if (!isRecord(node)) return node;
187
- if (!Object.hasOwn(node, "use")) {
188
- if (
189
- !["vitest", "package-script", "static-check"].includes(
190
- String(node.kind),
191
- )
192
- )
193
- return node;
194
- if (Object.hasOwn(node, "id") && Object.hasOwn(node, "classification"))
195
- return node;
196
- const command = structuredClone(node);
197
- delete command.id;
198
- delete command.classification;
199
- delete command.executionBindings;
200
- if (command.kind === "vitest" && Array.isArray(command.testFiles))
201
- command.testFiles = [...command.testFiles].sort(
202
- compareCanonicalStrings,
203
- );
204
- const id = `verify-${createHash("sha256")
205
- .update(
206
- canonicalJson([
207
- "cadence-verifier-v1",
208
- draft.changeId,
209
- taskId ?? null,
210
- field,
211
- command,
212
- classification,
213
- ]),
214
- )
215
- .digest("hex")}`;
216
- if (!Object.hasOwn(node, "id")) {
217
- if (generated.has(id) || authored.has(id))
218
- diagnostics.push({
219
- code: "verification-identity-collision",
220
- field,
221
- taskId,
222
- });
223
- generated.add(id);
224
- }
225
- return { id, classification, ...node };
226
- }
227
- if (
228
- Object.keys(node).some(
229
- (key) => !["use", "expectedFailure"].includes(key),
230
- ) ||
231
- typeof node.use !== "string" ||
232
- !ID.test(node.use)
233
- ) {
234
- diagnostics.push({
235
- code: "verification-reference-invalid",
236
- field,
237
- taskId,
238
- });
239
- return node;
240
- }
241
- const definition = definitions.get(node.use);
242
- if (!definition) {
243
- diagnostics.push({
244
- code: "verification-reference-unavailable",
245
- field,
246
- taskId,
247
- });
248
- return node;
249
- }
250
- const command = structuredClone(definition);
251
- if (command.kind === "vitest" && Array.isArray(command.testFiles))
252
- command.testFiles = [...command.testFiles].sort(compareCanonicalStrings);
253
- if (Object.hasOwn(node, "expectedFailure"))
254
- command.expectedFailure = node.expectedFailure;
255
- const id = `verify-${createHash("sha256")
256
- .update(
257
- canonicalJson([
258
- "cadence-verifier-v1",
259
- draft.changeId,
260
- taskId ?? null,
261
- field,
262
- command,
263
- classification,
264
- ]),
265
- )
266
- .digest("hex")}`;
267
- if (generated.has(id) || authored.has(id))
268
- diagnostics.push({
269
- code: "verification-identity-collision",
270
- field,
271
- taskId,
272
- });
273
- generated.add(id);
274
- return {
275
- ...command,
276
- id,
277
- classification,
278
- ...(Object.hasOwn(node, "expectedFailure")
279
- ? { expectedFailure: node.expectedFailure }
280
- : {}),
281
- };
282
- };
283
- const defaults = (node: unknown, fields: Record<string, unknown>) => {
284
- if (isRecord(node))
285
- for (const [key, value] of Object.entries(fields))
286
- if (!Object.hasOwn(node, key)) node[key] = value;
287
- };
288
- const tasks = draft.tasks as unknown[];
289
- for (const task of tasks) {
290
- if (!isRecord(task)) continue;
291
- const taskId = typeof task.taskId === "string" ? task.taskId : undefined;
292
- const common = task.read;
293
- if (Object.hasOwn(task, "read")) {
294
- if (!Array.isArray(common) || !common.every(isValidRelativePath))
295
- diagnostics.push({
296
- code: "draft-common-read-invalid",
297
- field: "read",
298
- taskId,
299
- });
300
- delete task.read;
301
- }
302
- defaults(task.agents, { managedOnly: true });
303
- if (isRecord(task.phases))
304
- for (const [name, phase] of Object.entries(task.phases)) {
305
- if (!isRecord(phase)) continue;
306
- if (Array.isArray(common) && common.every(isValidRelativePath)) {
307
- if (phase.read === undefined) phase.read = [...common];
308
- else if (Array.isArray(phase.read))
309
- phase.read = [...new Set([...common, ...phase.read])];
310
- }
311
- const classification =
312
- name === "refactor"
313
- ? "expected-refactor"
314
- : name === "red" &&
315
- !["mechanical", "refactor"].includes(
316
- String(task.verificationMode),
317
- )
318
- ? "expected-red"
319
- : "expected-green";
320
- phase.verification = expand(
321
- phase.verification,
322
- `phases.${name}.verification`,
323
- classification,
324
- taskId,
325
- );
326
- }
327
- for (const field of ["affectedVerification", "repairVerification"])
328
- task[field] = expand(task[field], field, "expected-green", taskId);
329
- if (task.baselineVerification !== undefined)
330
- task.baselineVerification = expand(
331
- task.baselineVerification,
332
- "baselineVerification",
333
- "expected-green",
334
- taskId,
335
- );
336
- }
337
- if (isRecord(draft.verification)) {
338
- const verification = draft.verification;
339
- defaults(verification.baseline, {
340
- target: "task-red-contracts",
341
- affected: "task-affected-contracts",
342
- failureIdentity: "normalized",
343
- });
344
- defaults(verification.change, { affected: "task-affected-contracts" });
345
- defaults(verification.repair, {
346
- inBoundaryOnly: true,
347
- approvalOnBoundaryExpansion: true,
348
- attribution: ["pre-existing", "introduced", "unresolved", "environment"],
349
- });
350
- if (
351
- !Object.hasOwn(verification, "agentsCheckpoint") &&
352
- tasks.every(
353
- (task) =>
354
- isRecord(task) &&
355
- isRecord(task.agents) &&
356
- task.agents.impact === "none",
357
- )
358
- ) {
359
- verification.agentsCheckpoint = {
360
- required: false,
361
- verification: null,
362
- operations: [],
363
- };
364
- }
365
- for (const [group, fields] of [
366
- ["baseline", ["fullSuite"]],
367
- ["change", ["fullSuite", "postApply"]],
368
- ["agentsCheckpoint", ["verification"]],
369
- ] as const) {
370
- const block = verification[group];
371
- if (isRecord(block))
372
- for (const field of fields)
373
- block[field] = expand(
374
- block[field],
375
- `verification.${group}.${field}`,
376
- "expected-green",
377
- );
378
- }
379
- }
380
- if (diagnostics.length)
381
- throw new DesignPlanValidationError(
382
- "design-plan-expansion-invalid",
383
- diagnostics,
384
- );
385
- return JSON.stringify(draft) === JSON.stringify(value) ? value : draft;
386
- }
387
- /** Derive only omitted fields; the strict normalizer and graph still own admission. */
388
- export function preparePlanDraft(value: unknown): unknown {
389
- if (
390
- !isRecord(value) ||
391
- !Array.isArray(value.tasks) ||
392
- value.tasks.length > 128 ||
393
- !Array.isArray(value.outputs) ||
394
- value.outputs.length > 512
395
- )
396
- return value;
397
- const draft = structuredClone(value);
398
- let changed = false;
399
- const tasks = (draft.tasks as unknown[]).filter(isRecord);
400
- const outputs = (draft.outputs as unknown[]).filter(isRecord);
401
- const diagnostics: DesignPlanDiagnostic[] = [];
402
- const writes = (task: Record<string, unknown>): Set<string> => {
403
- const paths = new Set<string>();
404
- if (!isRecord(task.phases)) return paths;
405
- for (const [phase, boundary] of Object.entries(task.phases)) {
406
- if (!isRecord(boundary)) continue;
407
- if (
408
- phase === "red" &&
409
- ["mechanical", "refactor"].includes(String(task.verificationMode))
410
- )
411
- continue;
412
- for (const candidates of [boundary.write, boundary.delete]) {
413
- if (!Array.isArray(candidates)) continue;
414
- for (const file of candidates)
415
- if (isValidRelativePath(file)) paths.add(file);
416
- }
417
- }
418
- return paths;
419
- };
420
- const owners = new Map<string, Record<string, unknown>[]>();
421
- for (const task of tasks)
422
- for (const file of writes(task))
423
- owners.set(file, [...(owners.get(file) ?? []), task]);
424
- if (!Object.hasOwn(draft, "tracking")) {
425
- changed = true;
426
- draft.tracking = {
427
- path: "tasks.md",
428
- format: "markdown-checkbox",
429
- taskIds: (draft.tasks as unknown[]).map((task) =>
430
- isRecord(task) ? task.taskId : undefined,
431
- ),
432
- completionOwner: "parent",
433
- };
434
- }
435
- for (const task of tasks) {
436
- const taskId = typeof task.taskId === "string" ? task.taskId : undefined;
437
- if (isRecord(task.phases))
438
- for (const [phase, boundary] of Object.entries(task.phases)) {
439
- if (
440
- !isRecord(boundary) ||
441
- Object.hasOwn(boundary, "verificationInputs")
442
- )
443
- continue;
444
- const verification = validateVerificationContract(
445
- boundary.verification,
446
- );
447
- // Invalid commands get their normal structural diagnostic; never infer from invalid paths.
448
- if (!verification.ok) continue;
449
- changed = true;
450
- boundary.verificationInputs = verificationInputPaths(
451
- verification.value,
452
- ).map((file) => {
453
- const producers = outputs.filter((output) => output.path === file);
454
- if (producers.length > 1)
455
- diagnostics.push({
456
- code: "multiple-output-producers",
457
- taskId,
458
- phase,
459
- field: "outputs",
460
- path: file,
461
- });
462
- return producers.length === 1
463
- ? { kind: "output", outputId: producers[0]?.id }
464
- : { kind: "workspace", path: file };
465
- });
466
- }
467
- if (
468
- !isRecord(task.impactClosure) ||
469
- !Array.isArray(task.impactClosure.relatedTests)
470
- )
471
- continue;
472
- for (const test of task.impactClosure.relatedTests) {
473
- if (
474
- !isRecord(test) ||
475
- Object.hasOwn(test, "disposition") ||
476
- !isValidRelativePath(test.path)
477
- )
478
- continue;
479
- changed = true;
480
- const writers = owners.get(test.path) ?? [];
481
- if (writers.includes(task)) test.disposition = "current-task";
482
- else if (writers.length === 0) test.disposition = "unaffected";
483
- else if (writers.length === 1) {
484
- test.disposition = "regression-task";
485
- if (!Object.hasOwn(test, "regressionTaskId"))
486
- test.regressionTaskId = writers[0]?.taskId;
487
- } else
488
- diagnostics.push({
489
- code: "related-test-owner-ambiguous",
490
- taskId,
491
- field: "impactClosure.relatedTests",
492
- path: test.path,
493
- });
494
- }
495
- }
496
- if (diagnostics.length)
497
- throw new DesignPlanValidationError(
498
- "delivery-plan-inference-ambiguous",
499
- diagnostics,
500
- );
501
- return changed ? draft : value;
502
- }
@@ -1,32 +0,0 @@
1
- import { lstatSync, readdirSync, rmdirSync, rmSync, unlinkSync } from "node:fs";
2
- import path from "node:path";
3
-
4
- /** Remove owned paths without following directory links. Node 24.13's Windows
5
- * rmSync uses narrow std::filesystem paths and can silently miss Unicode names.
6
- * The libuv-backed unlink/rmdir APIs preserve the original UTF-16 path. */
7
- export function removePathSync(
8
- target: string,
9
- options: { recursive?: boolean; force?: boolean } = {},
10
- ): void {
11
- if (process.platform !== "win32") {
12
- rmSync(target, options);
13
- return;
14
- }
15
- let stat: import("node:fs").Stats;
16
- try {
17
- stat = lstatSync(target);
18
- } catch (error) {
19
- if (options.force && (error as NodeJS.ErrnoException).code === "ENOENT")
20
- return;
21
- throw error;
22
- }
23
- if (stat.isDirectory() && !stat.isSymbolicLink()) {
24
- if (!options.recursive)
25
- throw Object.assign(new Error("Path is a directory"), {
26
- code: "ERR_FS_EISDIR",
27
- });
28
- for (const name of readdirSync(target))
29
- removePathSync(path.join(target, name), options);
30
- rmdirSync(target);
31
- } else unlinkSync(target);
32
- }