@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.
- package/README.md +324 -117
- package/THIRD_PARTY_NOTICES.md +15 -0
- package/agents/design-explorer.md +14 -18
- package/agents/diagnosis-worker.md +14 -14
- package/agents/implementation-worker.md +16 -17
- 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 +92 -20
- package/src/index.ts +21 -1802
- 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/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-context.ts +0 -289
- 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/contracts.ts +0 -2466
- 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 -227
- package/src/durable-workflow.ts +0 -822
- 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-process.ts +0 -206
- package/src/package-candidate.ts +0 -24
- 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 -305
- package/src/packet-runtime.ts +0 -459
- package/src/phase-execution.ts +0 -2163
- 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/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/subagent-process.ts +0 -476
- package/src/task-ledger.ts +0 -1338
- package/src/transport-budget.ts +0 -50
- 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/workflow-engine.ts +0 -28
- package/src/workflow-policy.ts +0 -1670
- package/src/workflow-recovery-policy.ts +0 -97
- package/src/workflow-scheduling.ts +0 -105
- package/src/workflow-state-machine.ts +0 -4341
- 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/operator-tools.ts
DELETED
|
@@ -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,206 +0,0 @@
|
|
|
1
|
-
import { execFileSync } from "node:child_process";
|
|
2
|
-
import { cpSync, existsSync, mkdirSync, mkdtempSync, rmSync } from "node:fs";
|
|
3
|
-
import os from "node:os";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import type { VerificationFailureSummary } from "./contracts.ts";
|
|
6
|
-
import { isValidRelativePath } from "./contracts.ts";
|
|
7
|
-
import type { DurableWorkflowEngineOptions } from "./durable-contracts.ts";
|
|
8
|
-
import type { ParentModelSource } from "./model-source.ts";
|
|
9
|
-
import { isSafeRegularFile } from "./safe-path.ts";
|
|
10
|
-
import {
|
|
11
|
-
buildSubagentPrompt,
|
|
12
|
-
runSubagentProcess,
|
|
13
|
-
SUBAGENT_LIMITS,
|
|
14
|
-
} from "./subagent-process.ts";
|
|
15
|
-
import type { DurableCandidateProposal } from "./workflow-policy.ts";
|
|
16
|
-
|
|
17
|
-
function permitsContextRead(
|
|
18
|
-
relative: string,
|
|
19
|
-
roots: readonly string[],
|
|
20
|
-
): boolean {
|
|
21
|
-
return (
|
|
22
|
-
isValidRelativePath(relative) &&
|
|
23
|
-
relative.split("/").every((part) => !part.startsWith(".")) &&
|
|
24
|
-
!/\.(?:pem|key|p12|pfx)$/iu.test(relative) &&
|
|
25
|
-
roots.some((root) => relative === root || relative.startsWith(`${root}/`))
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function restoreWorkspace(root: string, baseline: string): void {
|
|
30
|
-
rmSync(root, { recursive: true, force: true });
|
|
31
|
-
mkdirSync(root, { recursive: true });
|
|
32
|
-
cpSync(baseline, root, { recursive: true, force: true, dereference: false });
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** Produce a Git patch from two disposable trees without invoking a shell. */
|
|
36
|
-
function workspaceDiff(baseline: string, proposal: string): Uint8Array {
|
|
37
|
-
const parent = path.dirname(baseline);
|
|
38
|
-
const proposalSnapshot = mkdtempSync(
|
|
39
|
-
path.join(parent, "cadence-subagent-proposal-"),
|
|
40
|
-
);
|
|
41
|
-
cpSync(proposal, proposalSnapshot, {
|
|
42
|
-
recursive: true,
|
|
43
|
-
force: true,
|
|
44
|
-
dereference: false,
|
|
45
|
-
});
|
|
46
|
-
try {
|
|
47
|
-
const baseName = path.basename(baseline);
|
|
48
|
-
const proposalName = path.basename(proposalSnapshot);
|
|
49
|
-
try {
|
|
50
|
-
execFileSync(
|
|
51
|
-
"git",
|
|
52
|
-
[
|
|
53
|
-
"-c",
|
|
54
|
-
"core.autocrlf=false",
|
|
55
|
-
"-c",
|
|
56
|
-
"core.eol=lf",
|
|
57
|
-
"diff",
|
|
58
|
-
"--no-index",
|
|
59
|
-
"--binary",
|
|
60
|
-
"--no-color",
|
|
61
|
-
"--",
|
|
62
|
-
baseName,
|
|
63
|
-
proposalName,
|
|
64
|
-
],
|
|
65
|
-
{
|
|
66
|
-
cwd: parent,
|
|
67
|
-
encoding: "buffer",
|
|
68
|
-
maxBuffer: 8 * 1024 * 1024,
|
|
69
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
70
|
-
},
|
|
71
|
-
);
|
|
72
|
-
return Buffer.alloc(0);
|
|
73
|
-
} catch (error) {
|
|
74
|
-
if (!error || typeof error !== "object") return Buffer.alloc(0);
|
|
75
|
-
const output = (error as { stdout?: Buffer }).stdout;
|
|
76
|
-
if (!output) return Buffer.alloc(0);
|
|
77
|
-
const pathPrefixes = [
|
|
78
|
-
`a/${baseName}/`,
|
|
79
|
-
`a/${proposalName}/`,
|
|
80
|
-
`b/${baseName}/`,
|
|
81
|
-
`b/${proposalName}/`,
|
|
82
|
-
];
|
|
83
|
-
const normalizeHeader = (line: string): string => {
|
|
84
|
-
let normalized = line;
|
|
85
|
-
for (const prefix of pathPrefixes) {
|
|
86
|
-
const replacement = prefix.startsWith("a/") ? "a/" : "b/";
|
|
87
|
-
normalized = normalized.replaceAll(prefix, replacement);
|
|
88
|
-
}
|
|
89
|
-
return normalized;
|
|
90
|
-
};
|
|
91
|
-
const normalized = output
|
|
92
|
-
.toString("utf8")
|
|
93
|
-
.split("\n")
|
|
94
|
-
.map((line) =>
|
|
95
|
-
line.startsWith("diff --git ") ||
|
|
96
|
-
line.startsWith("--- ") ||
|
|
97
|
-
line.startsWith("+++ ")
|
|
98
|
-
? normalizeHeader(line)
|
|
99
|
-
: line,
|
|
100
|
-
)
|
|
101
|
-
.join("\n");
|
|
102
|
-
return Buffer.from(normalized, "utf8");
|
|
103
|
-
}
|
|
104
|
-
} finally {
|
|
105
|
-
rmSync(proposalSnapshot, { recursive: true, force: true });
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export async function proposeProcessPackageCandidate(
|
|
110
|
-
input: Parameters<DurableWorkflowEngineOptions["proposeCandidate"]>[0],
|
|
111
|
-
context: ParentModelSource | undefined,
|
|
112
|
-
implementationAgent: { content: string },
|
|
113
|
-
verificationDiagnostics: VerificationFailureSummary[] = [],
|
|
114
|
-
): Promise<DurableCandidateProposal> {
|
|
115
|
-
if (!context) return { kind: "paused", code: "parent-context-unavailable" };
|
|
116
|
-
if (input.signal.aborted)
|
|
117
|
-
return { kind: "operation-cancelled", code: "cancelled" };
|
|
118
|
-
const phase = input.task.phases[input.phase];
|
|
119
|
-
if (!phase) return { kind: "paused", code: "task-phase-unavailable" };
|
|
120
|
-
const taskPhases = Object.values(input.task.phases);
|
|
121
|
-
const read = [
|
|
122
|
-
...new Set(
|
|
123
|
-
taskPhases.flatMap((boundary) => [
|
|
124
|
-
...boundary.read,
|
|
125
|
-
...boundary.write,
|
|
126
|
-
...boundary.delete,
|
|
127
|
-
]),
|
|
128
|
-
),
|
|
129
|
-
].sort();
|
|
130
|
-
const write = input.artifactCorrection
|
|
131
|
-
? [...new Set(taskPhases.flatMap((boundary) => boundary.write))].sort()
|
|
132
|
-
: [...phase.write];
|
|
133
|
-
const deletePaths = input.artifactCorrection
|
|
134
|
-
? [...new Set(taskPhases.flatMap((boundary) => boundary.delete))].sort()
|
|
135
|
-
: [...phase.delete];
|
|
136
|
-
const allowedContext = (input.contextReadPaths ?? []).filter(
|
|
137
|
-
(relative) =>
|
|
138
|
-
permitsContextRead(relative, input.task.roots) &&
|
|
139
|
-
isSafeRegularFile(input.workspaceRoot, relative),
|
|
140
|
-
);
|
|
141
|
-
const allowedPaths = [...new Set([...read, ...allowedContext])].sort();
|
|
142
|
-
const baseline = mkdtempSync(
|
|
143
|
-
path.join(os.tmpdir(), "cadence-subagent-baseline-"),
|
|
144
|
-
);
|
|
145
|
-
try {
|
|
146
|
-
cpSync(input.workspaceRoot, baseline, {
|
|
147
|
-
recursive: true,
|
|
148
|
-
force: true,
|
|
149
|
-
dereference: false,
|
|
150
|
-
});
|
|
151
|
-
const prompt = buildSubagentPrompt({
|
|
152
|
-
role: "implementation-worker",
|
|
153
|
-
agentContent: implementationAgent.content,
|
|
154
|
-
objective: input.task.objective,
|
|
155
|
-
context: [
|
|
156
|
-
input.task.context.agents,
|
|
157
|
-
input.task.context.contract,
|
|
158
|
-
JSON.stringify({
|
|
159
|
-
taskId: input.taskId,
|
|
160
|
-
phase: input.phase,
|
|
161
|
-
readSet: allowedPaths,
|
|
162
|
-
writeSet: write,
|
|
163
|
-
deleteSet: deletePaths,
|
|
164
|
-
verificationDiagnostics,
|
|
165
|
-
recoveryFeedback: input.recoveryFeedback,
|
|
166
|
-
}),
|
|
167
|
-
].join("\n\n"),
|
|
168
|
-
finalConvention:
|
|
169
|
-
"Edit the disposable workspace directly. Finish with a plain-text summary; the parent will derive and validate the candidate diff.",
|
|
170
|
-
});
|
|
171
|
-
const child = await runSubagentProcess({
|
|
172
|
-
role: "implementation-worker",
|
|
173
|
-
cwd: input.workspaceRoot,
|
|
174
|
-
prompt,
|
|
175
|
-
model: context.model
|
|
176
|
-
? { provider: context.model.provider, id: context.model.id }
|
|
177
|
-
: undefined,
|
|
178
|
-
signal: input.signal,
|
|
179
|
-
timeoutMs: SUBAGENT_LIMITS.timeoutMs,
|
|
180
|
-
onEvent: (event) => {
|
|
181
|
-
if (event.type === "agent_start") input.onRequestStart?.();
|
|
182
|
-
if (event.type === "tool_execution_start") input.onProgress?.();
|
|
183
|
-
},
|
|
184
|
-
});
|
|
185
|
-
if (child.status === "cancelled")
|
|
186
|
-
return { kind: "operation-cancelled", code: "cancelled" };
|
|
187
|
-
if (child.status === "timed-out")
|
|
188
|
-
return { kind: "paused", code: "child-timeout" };
|
|
189
|
-
if (child.status === "output-limit")
|
|
190
|
-
return { kind: "retryable", code: "needs-task-split" };
|
|
191
|
-
if (child.status !== "completed")
|
|
192
|
-
return { kind: "retryable", code: "transport-failure" };
|
|
193
|
-
const bytes = workspaceDiff(baseline, input.workspaceRoot);
|
|
194
|
-
// Existing parent code applies the candidate patch to this root. Restore the
|
|
195
|
-
// baseline first so child edits cannot be applied twice.
|
|
196
|
-
restoreWorkspace(input.workspaceRoot, baseline);
|
|
197
|
-
if (bytes.length === 0)
|
|
198
|
-
return { kind: "retryable", code: "candidate-diff-invalid" };
|
|
199
|
-
return { kind: "candidate", bytes };
|
|
200
|
-
} finally {
|
|
201
|
-
// A child is never allowed to leave edits in the proposal root: the
|
|
202
|
-
// parent-side apply/verification path consumes the generated bytes.
|
|
203
|
-
if (existsSync(baseline)) restoreWorkspace(input.workspaceRoot, baseline);
|
|
204
|
-
rmSync(baseline, { recursive: true, force: true });
|
|
205
|
-
}
|
|
206
|
-
}
|
package/src/package-candidate.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { VerificationFailureSummary } from "./contracts.ts";
|
|
2
|
-
import type { DurableWorkflowEngineOptions } from "./durable-contracts.ts";
|
|
3
|
-
import type { ParentModelSource } from "./model-source.ts";
|
|
4
|
-
import { proposeProcessPackageCandidate } from "./package-candidate-process.ts";
|
|
5
|
-
import type { DurableCandidateProposal } from "./workflow-policy.ts";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Parent-owned candidate adapter. The child only edits the disposable proposal
|
|
9
|
-
* root; this function returns its bounded diff to the existing sealing and
|
|
10
|
-
* verification pipeline.
|
|
11
|
-
*/
|
|
12
|
-
export function proposePackageCandidate(
|
|
13
|
-
input: Parameters<DurableWorkflowEngineOptions["proposeCandidate"]>[0],
|
|
14
|
-
context: ParentModelSource | undefined,
|
|
15
|
-
implementationAgent: { content: string },
|
|
16
|
-
verificationDiagnostics: VerificationFailureSummary[] = [],
|
|
17
|
-
): Promise<DurableCandidateProposal> {
|
|
18
|
-
return proposeProcessPackageCandidate(
|
|
19
|
-
input,
|
|
20
|
-
context,
|
|
21
|
-
implementationAgent,
|
|
22
|
-
verificationDiagnostics,
|
|
23
|
-
);
|
|
24
|
-
}
|