@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,309 +0,0 @@
1
- import { spawnSync } from "node:child_process";
2
- import { lstatSync, readdirSync, readFileSync, realpathSync } from "node:fs";
3
- import path from "node:path";
4
- import { DatabaseSync } from "node:sqlite";
5
- import { executionProfile } from "./execution-profile.ts";
6
- import { resolveOpenSpecInvocation } from "./openspec-cli.ts";
7
- import { resolveStateRoot } from "./state-root.ts";
8
- import { requestBounds } from "./transport-budget.ts";
9
- import { validateVerificationAdapterCapability } from "./verification-capability.ts";
10
- import { probeWindowsJob } from "./windows-job-backend.ts";
11
-
12
- export interface DoctorCheck {
13
- name: string;
14
- ok: boolean;
15
- detail: string;
16
- nextStep?: string;
17
- }
18
- const PACKAGE_LOCKS = {
19
- bun: ["bun.lock", "bun.lockb"],
20
- npm: ["package-lock.json", "npm-shrinkwrap.json"],
21
- pnpm: ["pnpm-lock.yaml"],
22
- yarn: ["yarn.lock"],
23
- } as const;
24
- type PackageManager = keyof typeof PACKAGE_LOCKS;
25
-
26
- function packageManagerSelection(root: string, declaration: unknown) {
27
- const managers = Object.keys(PACKAGE_LOCKS) as PackageManager[];
28
- const lockfiles = managers.flatMap((manager) =>
29
- PACKAGE_LOCKS[manager].filter((file) =>
30
- lstatSync(path.join(root, file), { throwIfNoEntry: false })?.isFile(),
31
- ),
32
- );
33
- const inferred = managers.filter((manager) =>
34
- PACKAGE_LOCKS[manager].some((file) => lockfiles.includes(file)),
35
- );
36
- const declared =
37
- typeof declaration === "string"
38
- ? managers.find((manager) =>
39
- new RegExp(
40
- `^${manager}@[0-9]+\\.[0-9]+\\.[0-9]+(?:[-+][a-z0-9._+-]+)?$`,
41
- "iu",
42
- ).test(declaration),
43
- )
44
- : undefined;
45
- const selectedPackageManager =
46
- declaration !== undefined
47
- ? (declared ?? null)
48
- : inferred.length === 1
49
- ? (inferred[0] ?? null)
50
- : inferred.length > 1
51
- ? null
52
- : "npm";
53
- const selectionSource =
54
- declaration !== undefined
55
- ? declared
56
- ? "package.json"
57
- : "invalid-declaration"
58
- : inferred.length === 1
59
- ? "lockfile"
60
- : inferred.length > 1
61
- ? "ambiguous"
62
- : "default";
63
- return {
64
- selectedPackageManager,
65
- selectionSource,
66
- lockfiles,
67
- ambiguousLockfiles: inferred.length > 1,
68
- };
69
- }
70
-
71
- export function inspectConsumer(root: string) {
72
- root = realpathSync(root);
73
- const checks: DoctorCheck[] = [];
74
- const check = (name: string, action: () => string, nextStep: string) => {
75
- try {
76
- checks.push({ name, ok: true, detail: action() });
77
- } catch (error) {
78
- checks.push({
79
- name,
80
- ok: false,
81
- detail: error instanceof Error ? error.message : "unavailable",
82
- nextStep,
83
- });
84
- }
85
- };
86
- check(
87
- "node",
88
- () => {
89
- if (
90
- Number(process.versions.node.split(".")[0]) < 22 ||
91
- (Number(process.versions.node.split(".")[0]) === 22 &&
92
- Number(process.versions.node.split(".")[1]) < 13)
93
- )
94
- throw new Error("Node 22.13+ required");
95
- return process.versions.node;
96
- },
97
- "Install Node >=22.13.",
98
- );
99
- check(
100
- "git",
101
- () => {
102
- const result = spawnSync("git", ["rev-parse", "--show-toplevel"], {
103
- cwd: root,
104
- encoding: "utf8",
105
- timeout: 5000,
106
- maxBuffer: 65536,
107
- });
108
- if (result.status !== 0) throw new Error("git-repository-unavailable");
109
- return result.stdout.trim();
110
- },
111
- "Install Git and initialize the consumer repository.",
112
- );
113
- check(
114
- "openspec",
115
- () => {
116
- resolveOpenSpecInvocation(root);
117
- return "resolved (protocol not executed)";
118
- },
119
- "Install @fission-ai/openspec@1.5.0, or configure ABEL_OPENSPEC_PACKAGE_ROOT / ABEL_OPENSPEC_NODE before launching the host.",
120
- );
121
- check(
122
- "execution",
123
- () => {
124
- const profile = executionProfile();
125
- if (profile.mode === "host-trusted") {
126
- if (!probeWindowsJob(profile.windowsHelperPath ?? ""))
127
- throw new Error("windows-job-backend-unavailable");
128
- return "host-trusted: Windows x64 Job probe passed; host files/network accessible";
129
- }
130
- if (process.platform !== "linux")
131
- throw new Error("linux-pid-isolation-required");
132
-
133
- const result = spawnSync(
134
- profile.bwrapPath,
135
- [
136
- "--ro-bind",
137
- "/",
138
- "/",
139
- profile.mode === "local-trusted" ? "--unshare-pid" : "--unshare-all",
140
- "--",
141
- "/bin/true",
142
- ],
143
- { timeout: 5000, encoding: "utf8", maxBuffer: 65536 },
144
- );
145
- if (result.status !== 0) throw new Error("bubblewrap-probe-failed");
146
- return `${profile.mode}: Bubblewrap PID namespace probe passed`;
147
- },
148
- "On Linux install/enable Bubblewrap; set ABEL_BWRAP_PATH for a custom install. Trusted Linux projects may explicitly set ABEL_EXECUTION_MODE=local-trusted; Windows x64 trusted projects may explicitly select ABEL_EXECUTION_MODE=host-trusted and install the matching native Job helper (ABEL_WINDOWS_JOB_HELPER).",
149
- );
150
- check(
151
- "request-budgets",
152
- () => JSON.stringify(requestBounds()),
153
- "Set ABEL_FIRST_PROGRESS_MS and ABEL_STREAM_IDLE_MS to positive milliseconds <=1200000.",
154
- );
155
- check(
156
- "state-root",
157
- () =>
158
- resolveStateRoot({
159
- consumerRoot: root,
160
- xdgStateHome: process.env.XDG_STATE_HOME,
161
- }).rootDir,
162
- "Use an absolute repository-external XDG_STATE_HOME.",
163
- );
164
- check(
165
- "workspace-dependencies",
166
- () => {
167
- const dependencies = path.join(root, "node_modules");
168
- if (!lstatSync(dependencies, { throwIfNoEntry: false }))
169
- return "no node_modules; prepare dependencies before verification";
170
- const names = readdirSync(dependencies).flatMap((name) =>
171
- name.startsWith("@") &&
172
- lstatSync(path.join(dependencies, name)).isDirectory()
173
- ? readdirSync(path.join(dependencies, name)).map(
174
- (child) => `${name}/${child}`,
175
- )
176
- : [name],
177
- );
178
- if (names.length > 20_000) throw new Error("dependency-view-too-large");
179
- let links = 0;
180
- for (const name of names) {
181
- const file = path.join(dependencies, name);
182
- if (!lstatSync(file).isSymbolicLink()) continue;
183
- const resolved = realpathSync(file);
184
- const relative = path.relative(root, resolved);
185
- if (
186
- relative === ".." ||
187
- relative.startsWith(`..${path.sep}`) ||
188
- path.isAbsolute(relative)
189
- )
190
- throw new Error("dependency-link-outside-consumer");
191
- if (!resolved.startsWith(`${dependencies}${path.sep}`)) links++;
192
- }
193
- return `${links} repository workspace link(s); their targets must be included in the candidate baseline`;
194
- },
195
- "Repair dangling/external workspace links and ensure local package sources are tracked or admitted in the candidate.",
196
- );
197
- const manifest = path.join(root, "package.json");
198
- let selection = packageManagerSelection(root, undefined);
199
- if (lstatSync(manifest, { throwIfNoEntry: false })?.isFile()) {
200
- check(
201
- "manifest",
202
- () => {
203
- const parsed = JSON.parse(readFileSync(manifest, "utf8"));
204
- if (!parsed || typeof parsed !== "object")
205
- throw new Error("manifest-invalid");
206
- return (
207
- Object.keys(parsed.scripts ?? {}).join(", ") || "no package scripts"
208
- );
209
- },
210
- "Repair package.json.",
211
- );
212
- const parsed = (() => {
213
- try {
214
- const value = JSON.parse(readFileSync(manifest, "utf8"));
215
- return value && typeof value === "object" && !Array.isArray(value)
216
- ? value
217
- : {};
218
- } catch {
219
- return {};
220
- }
221
- })();
222
- selection = packageManagerSelection(root, parsed.packageManager);
223
- check(
224
- "package-manager",
225
- () => {
226
- if (!selection.selectedPackageManager)
227
- throw new Error(`package-manager-${selection.selectionSource}`);
228
- return `${selection.selectedPackageManager} (${selection.selectionSource})`;
229
- },
230
- "Declare the intended packageManager in package.json; doctor does not read private plans, install runners or remove lockfiles.",
231
- );
232
- for (const script of ["test", "check", "build"].filter(
233
- (name) => typeof parsed.scripts?.[name] === "string",
234
- )) {
235
- check(
236
- `script:${script}`,
237
- () => {
238
- const manager = selection.selectedPackageManager;
239
- if (!manager)
240
- throw new Error(`package-manager-${selection.selectionSource}`);
241
- const result = validateVerificationAdapterCapability(root, {
242
- kind: "package-script",
243
- id: `doctor-${script}`,
244
- packageManager: manager,
245
- script,
246
- command: parsed.scripts[script],
247
- args: [],
248
- classification: "expected-green",
249
- });
250
- if (!result.ok)
251
- throw new Error(`${manager}:${result.diagnostic.code}`);
252
- return "statically admitted; tests not executed";
253
- },
254
- "Check the runner, installed dependencies and execution configuration; this probe does not execute your tests.",
255
- );
256
- }
257
- }
258
- return { root, ...selection, ok: checks.every((entry) => entry.ok), checks };
259
- }
260
-
261
- /** Bounded metadata traversal, no symlink following and no automatic deletion. */
262
- export function storageUsage(root: string, maximum = 100_000) {
263
- let entries = 0;
264
- let bytes = 0;
265
- let truncated = false;
266
- const visit = (file: string) => {
267
- if (entries >= maximum) {
268
- truncated = true;
269
- return;
270
- }
271
- const stat = lstatSync(file, { throwIfNoEntry: false });
272
- if (!stat) return;
273
- entries++;
274
- if (stat.isFile()) bytes += stat.size;
275
- else if (stat.isDirectory())
276
- for (const name of readdirSync(file)) {
277
- visit(path.join(file, name));
278
- if (truncated) break;
279
- }
280
- };
281
- visit(root);
282
- return { entries, bytes, truncated };
283
- }
284
-
285
- export function inspectRuns(root: string) {
286
- const state = resolveStateRoot({
287
- consumerRoot: root,
288
- xdgStateHome: process.env.XDG_STATE_HOME,
289
- });
290
- const usage = storageUsage(state.rootDir);
291
- if (!lstatSync(state.databasePath, { throwIfNoEntry: false }))
292
- return { stateRoot: state.rootDir, usage, runs: [], truncated: false };
293
- const db = new DatabaseSync(state.databasePath, { readOnly: true });
294
- try {
295
- const rows = db
296
- .prepare(
297
- "SELECT run_id, stage, change_name, state, sequence FROM runs ORDER BY run_id LIMIT 1001",
298
- )
299
- .all();
300
- return {
301
- stateRoot: state.rootDir,
302
- usage,
303
- runs: rows.slice(0, 1000),
304
- truncated: rows.length > 1000,
305
- };
306
- } finally {
307
- db.close();
308
- }
309
- }
@@ -1,227 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import path from "node:path";
3
- import { runChildSession } from "./child-session.ts";
4
- import type { VerificationFailureSummary } from "./contracts.ts";
5
- import { LIMITS } from "./contracts.ts";
6
- import type { DurableWorkflowEngineOptions } from "./durable-contracts.ts";
7
- import type { ParentModelSource } from "./model-source.ts";
8
- import { runtimeForWorkerRoute } from "./parent-provider.ts";
9
- import type { WorkerRoutePolicy } from "./route-policy.ts";
10
- import { isSafeRegularFile } from "./safe-path.ts";
11
- import {
12
- classifyCandidateContextRequest,
13
- permitsContextRead,
14
- } from "./submit-tool.ts";
15
- import { transportFailureError } from "./transport-budget.ts";
16
- import type { DurableCandidateProposal } from "./workflow-policy.ts";
17
-
18
- function childRequestId(
19
- operationId: string,
20
- taskId: string,
21
- phase: string,
22
- ): string {
23
- return `child-${createHash("sha256").update(`${operationId}\0${taskId}\0${phase}`).digest("hex").slice(0, 40)}`;
24
- }
25
- export async function proposePackageCandidate(
26
- input: Parameters<DurableWorkflowEngineOptions["proposeCandidate"]>[0],
27
- context: ParentModelSource | undefined,
28
- implementationAgent: { content: string },
29
- verificationDiagnostics: VerificationFailureSummary[] = [],
30
- ): Promise<DurableCandidateProposal> {
31
- if (!context) {
32
- return { kind: "paused", code: "parent-context-unavailable" };
33
- }
34
- const phaseRuntime = await runtimeForWorkerRoute(
35
- input.route as WorkerRoutePolicy,
36
- context,
37
- input.signal,
38
- process.env,
39
- );
40
- if (!phaseRuntime.ok) {
41
- if (phaseRuntime.failure.kind === "cancelled") {
42
- return { kind: "operation-cancelled", code: "cancelled" };
43
- }
44
- throw new Error(phaseRuntime.failure.code);
45
- }
46
- const phase = input.task.phases[input.phase];
47
- if (!phase) {
48
- return { kind: "paused", code: "task-phase-unavailable" };
49
- }
50
- const taskPhases = Object.values(input.task.phases);
51
- const executionBoundary = input.artifactCorrection
52
- ? {
53
- read: [
54
- ...new Set(
55
- taskPhases.flatMap((boundary) => [
56
- ...boundary.read,
57
- ...boundary.write,
58
- ...boundary.delete,
59
- ]),
60
- ),
61
- ].sort(),
62
- write: [
63
- ...new Set(taskPhases.flatMap((boundary) => boundary.write)),
64
- ].sort(),
65
- delete: [
66
- ...new Set(taskPhases.flatMap((boundary) => boundary.delete)),
67
- ].sort(),
68
- }
69
- : {
70
- read: [
71
- ...new Set(
72
- taskPhases.flatMap((boundary) => [
73
- ...boundary.read,
74
- ...boundary.write,
75
- ...boundary.delete,
76
- ]),
77
- ),
78
- ].sort(),
79
- write: [...phase.write],
80
- delete: [...phase.delete],
81
- };
82
- executionBoundary.read = [
83
- ...new Set([
84
- ...executionBoundary.read,
85
- ...(input.contextReadPaths ?? []).filter(
86
- (relative) =>
87
- permitsContextRead(relative, input.task.roots) &&
88
- isSafeRegularFile(input.workspaceRoot, relative),
89
- ),
90
- ]),
91
- ].sort();
92
- const phaseContract = {
93
- verificationDiagnostics,
94
- candidateId: input.candidateArtifact.identity.candidateId,
95
- taskId: input.taskId,
96
- phase: input.phase,
97
- readSet: executionBoundary.read,
98
- writeSet: executionBoundary.write,
99
- deleteSet: executionBoundary.delete,
100
- verification: structuredClone(phase.verification),
101
- agentsImpact: input.task.agents.impact,
102
- agentsTarget: input.task.agents.target ?? null,
103
- agentsManagedOnly: true,
104
- agentsWriteAllowed: false,
105
- impactClosure: structuredClone(input.task.impactClosure),
106
- ...(input.artifactCorrection
107
- ? { artifactCorrection: structuredClone(input.artifactCorrection) }
108
- : {}),
109
- ...(input.contextRequest
110
- ? { requestedContext: structuredClone(input.contextRequest) }
111
- : {}),
112
- ...(input.recoveryFeedback
113
- ? { recoveryFeedback: structuredClone(input.recoveryFeedback) }
114
- : {}),
115
- ...(input.repair
116
- ? {
117
- repair: {
118
- attempt: input.repair.attempt,
119
- attribution: input.repair.attribution,
120
- failureIdentities: [...input.repair.failureIdentities],
121
- verification: structuredClone(input.task.repairVerification),
122
- inBoundaryOnly: true,
123
- },
124
- }
125
- : {}),
126
- };
127
- const child = await runChildSession({
128
- cwd: input.workspaceRoot,
129
- modelRuntime: phaseRuntime.modelRuntime,
130
- model: phaseRuntime.model,
131
- systemPrompt: [
132
- implementationAgent.content,
133
- input.task.objective,
134
- input.task.context.agents,
135
- input.task.context.contract,
136
- "Use recoveryFeedback to change the failing approach. For compact-patch, prefer exact replace operations and omit unchanged bodies; submit one complete atomic patch. Never repeat an unchanged failing submission or weaken verification to obtain a pass.",
137
- `<phase-contract>${JSON.stringify(phaseContract)}</phase-contract>`,
138
- ].join("\n\n"),
139
- requestId: childRequestId(input.operationId, input.taskId, input.phase),
140
- taskId: input.taskId,
141
- role: "implementation-worker",
142
- phase: input.phase,
143
- output: "diff",
144
- roots: input.task.roots.map((root) =>
145
- path.resolve(input.workspaceRoot, root),
146
- ),
147
- allowedPaths: [
148
- ...new Set([
149
- ...executionBoundary.read,
150
- ...executionBoundary.write,
151
- ...executionBoundary.delete,
152
- ]),
153
- ],
154
- timeoutMs: LIMITS.phaseTimeoutMs,
155
- signal: input.signal,
156
- ledgerProjection: input.ledgerProjection,
157
- candidateArtifact: input.candidateArtifact,
158
- onStreamStart: input.onRequestStart,
159
- onStreamHeaders: input.onHeaders,
160
- onStreamProgress: input.onProgress,
161
- });
162
- if (!child.ok) {
163
- if (child.failure.kind === "transport") {
164
- throw transportFailureError(child.failure.code);
165
- }
166
- if (child.failure.kind === "cancelled") {
167
- return { kind: "operation-cancelled", code: "cancelled" };
168
- }
169
- if (child.failure.kind === "approval-boundary") {
170
- return { kind: "approval-needed", code: child.failure.code };
171
- }
172
- if (child.failure.kind === "execution-limit") {
173
- return { kind: "paused", code: "needs-task-split" };
174
- }
175
- if (child.failure.kind === "result-limit") {
176
- return { kind: "retryable", code: "needs-task-split" };
177
- }
178
- const attemptDiagnostic = {
179
- finalCategory: child.classification.finalCategory,
180
- submitAttempts: child.classification.attempts,
181
- schema: child.classification.schema,
182
- identityMismatch: Object.entries(child.classification.identity)
183
- .filter(([, matches]) => !matches)
184
- .map(([dimension]) => dimension),
185
- };
186
- return child.failure.kind === "environment" ||
187
- child.failure.kind === "verification-adapter"
188
- ? { kind: "paused", code: child.failure.code, attemptDiagnostic }
189
- : { kind: "retryable", code: child.failure.code, attemptDiagnostic };
190
- }
191
- const result = child.result;
192
- if (result.kind === "context-request") {
193
- return classifyCandidateContextRequest(result, {
194
- phase: input.phase,
195
- contextReadRoots: input.task.roots,
196
- readPaths: phase.read,
197
- writePaths: phase.write,
198
- deletePaths: phase.delete,
199
- taskPaths: [
200
- ...new Set(
201
- Object.values(input.task.phases).flatMap((boundary) => [
202
- ...boundary.read,
203
- ...boundary.write,
204
- ...boundary.delete,
205
- ]),
206
- ),
207
- ],
208
- redWritePaths: input.task.phases.red.write,
209
- agents: {
210
- impact: input.task.agents.impact,
211
- ...(input.task.agents.target
212
- ? { target: input.task.agents.target }
213
- : {}),
214
- },
215
- });
216
- }
217
- if (result.kind !== "sealed-candidate") {
218
- return { kind: "retryable", code: "candidate-diff-invalid" };
219
- }
220
- return {
221
- kind: "sealed-candidate",
222
- candidateId: result.candidateId,
223
- artifactHash: result.artifactHash,
224
- bytes: result.bytes,
225
- paths: [...result.paths],
226
- };
227
- }