@koreanhole/kandev 0.0.0-stage → 0.1.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 (51) hide show
  1. package/README.md +367 -2
  2. package/bin/codex-acp.js +16 -0
  3. package/bin/kandev-auto-sync.mjs +101 -0
  4. package/bin/kandev-config.js +53 -0
  5. package/bin/kandev.js +35 -0
  6. package/config/config.yaml +6 -0
  7. package/config/docker/projects/opencodex-cli.json +79 -0
  8. package/config/docker/projects/samsung-bus-tracker.json +91 -0
  9. package/config/gateways.json +14 -0
  10. package/config/pipeline.json +150 -0
  11. package/config/workflows/sdlc.yaml +1019 -0
  12. package/docker/Dockerfile +68 -0
  13. package/docker/Dockerfile.opencodex-cli +44 -0
  14. package/docker/Dockerfile.samsung-bus-tracker +75 -0
  15. package/package.json +61 -4
  16. package/scripts/agent-tools-docker.mjs +223 -0
  17. package/scripts/baseline.mjs +20 -0
  18. package/scripts/codex-medium +2 -0
  19. package/scripts/codex-stage +22 -0
  20. package/scripts/gate.mjs +909 -0
  21. package/scripts/gateways/docker.mjs +64 -0
  22. package/scripts/gateways/speckit.mjs +78 -0
  23. package/scripts/install-prerequisites.mjs +48 -0
  24. package/scripts/lib/artifacts.mjs +990 -0
  25. package/scripts/lib/bugfix.mjs +325 -0
  26. package/scripts/lib/checksum.mjs +166 -0
  27. package/scripts/lib/docker-workspace.mjs +1209 -0
  28. package/scripts/lib/gateways.mjs +79 -0
  29. package/scripts/lib/kandev.mjs +273 -0
  30. package/scripts/lib/mcp.mjs +111 -0
  31. package/scripts/lib/pipeline.mjs +548 -0
  32. package/scripts/lib/planning-replan.mjs +103 -0
  33. package/scripts/lib/resume.mjs +207 -0
  34. package/scripts/lib/review-history.mjs +260 -0
  35. package/scripts/lib/stage-boundary.mjs +146 -0
  36. package/scripts/lib/stage-model.mjs +23 -0
  37. package/scripts/lib/task-worktree.mjs +40 -0
  38. package/scripts/measure-tokens.mjs +121 -0
  39. package/scripts/planning-tools.mjs +166 -0
  40. package/scripts/replan-planning.mjs +82 -0
  41. package/scripts/review-digest.mjs +240 -0
  42. package/scripts/run-android-e2e.mjs +116 -0
  43. package/scripts/run-code-review.mjs +281 -0
  44. package/scripts/run-detached.mjs +163 -0
  45. package/scripts/run-doc-review.mjs +155 -0
  46. package/scripts/run-gateways.mjs +138 -0
  47. package/scripts/sync.mjs +588 -0
  48. package/scripts/verify-change.mjs +252 -0
  49. package/scripts/verify-node.mjs +288 -0
  50. package/scripts/verify.mjs +442 -0
  51. package/scripts/wait-status.mjs +88 -0
@@ -0,0 +1,252 @@
1
+ #!/usr/bin/env node
2
+ /** Run the one deterministic build/compile/test verification for Stage 3. */
3
+ import { spawnSync } from "node:child_process";
4
+ import fs from "node:fs";
5
+ import path from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ import { maybeReexecInTaskContainer } from "./lib/docker-workspace.mjs";
8
+ import {
9
+ buildImplementation,
10
+ buildNodePlan,
11
+ implementationExitCode,
12
+ parseGitStatus,
13
+ runPlan,
14
+ } from "./verify-node.mjs";
15
+ import {
16
+ contractProblems,
17
+ readContract,
18
+ readRun,
19
+ runProblems,
20
+ sha256File,
21
+ } from "./lib/bugfix.mjs";
22
+
23
+ const LOG_PATH = ".agentic/verify.log";
24
+ const PLATFORMS = new Set(["node", "web", "android"]);
25
+
26
+ class UsageError extends Error {}
27
+
28
+ function readJson(file) {
29
+ try {
30
+ return JSON.parse(fs.readFileSync(file, "utf8"));
31
+ } catch {
32
+ return null;
33
+ }
34
+ }
35
+
36
+ function readScripts(cwd) {
37
+ const packageJson = readJson(path.join(cwd, "package.json"));
38
+ return packageJson?.scripts && typeof packageJson.scripts === "object" ? packageJson.scripts : {};
39
+ }
40
+
41
+ function changedFiles(cwd) {
42
+ const result = spawnSync("git", ["-C", cwd, "status", "--porcelain", "--untracked-files=all"], {
43
+ encoding: "utf8",
44
+ timeout: 30_000,
45
+ });
46
+ if (result.status !== 0) throw new Error(result.stderr || "git status failed");
47
+ return parseGitStatus(result.stdout);
48
+ }
49
+
50
+ function configured(key, command, argv) {
51
+ return { key, command, argv, stdout: "", stderr: "" };
52
+ }
53
+
54
+ function missing(key) {
55
+ return { key, command: "not-configured", argv: null, exit_code: 127, stdout: "", stderr: "" };
56
+ }
57
+
58
+ function attachBugfixEvidence(root, spec, artifact, files) {
59
+ if (spec.change_type !== "bugfix") return artifact;
60
+ const contractResult = readContract(root);
61
+ if (contractResult.problems.length) throw new Error(contractResult.problems.join("; "));
62
+ const contract = contractResult.data;
63
+ const contractErrors = contractProblems(root, spec, contract);
64
+ if (contractErrors.length) throw new Error(`bugfix contract invalid: ${contractErrors.join("; ")}`);
65
+ const scenarioId = contract.reproduction.scenario_id;
66
+
67
+ const before = readRun(root, "implementation-before");
68
+ if (before.problems.length) throw new Error(before.problems.join("; "));
69
+ const beforeErrors = runProblems(root, before.data, {
70
+ phase: "implementation-before",
71
+ status: "failed",
72
+ scenarioId,
73
+ });
74
+ if (beforeErrors.length) throw new Error(beforeErrors.join("; "));
75
+
76
+ const after = readRun(root, "implementation-after");
77
+ if (after.problems.length) throw new Error(after.problems.join("; "));
78
+ const afterErrors = runProblems(root, after.data, {
79
+ phase: "implementation-after",
80
+ status: "passed",
81
+ scenarioId,
82
+ requireRegression: true,
83
+ });
84
+ if (afterErrors.length) throw new Error(afterErrors.join("; "));
85
+
86
+ const regressionPath = contract.regression_test.path;
87
+ if (!files.includes(regressionPath)) {
88
+ throw new Error(`regression test is not in files_changed: ${regressionPath}`);
89
+ }
90
+ const regressionFile = path.resolve(root, regressionPath);
91
+ if (!fs.existsSync(regressionFile) || !fs.statSync(regressionFile).isFile()) {
92
+ throw new Error(`regression test is missing: ${regressionPath}`);
93
+ }
94
+ const regressionHash = sha256File(regressionFile);
95
+ if (after.data.regression_test.sha256 !== regressionHash) {
96
+ throw new Error("regression test hash changed after the implementation run");
97
+ }
98
+
99
+ return {
100
+ ...artifact,
101
+ bugfix: {
102
+ before: {
103
+ phase: "implementation-before",
104
+ result: ".agentic/bugfix-runs/implementation-before.json",
105
+ },
106
+ after: {
107
+ phase: "implementation-after",
108
+ result: ".agentic/bugfix-runs/implementation-after.json",
109
+ },
110
+ regression_test: {
111
+ path: regressionPath,
112
+ command: contract.regression_test.command,
113
+ exit_code: after.data.regression_test.exit_code,
114
+ sha256: regressionHash,
115
+ },
116
+ },
117
+ };
118
+ }
119
+
120
+ /** Android verification uses the wrapper and the debug unit-test task. */
121
+ export function buildGradlePlan({ wrapper = true } = {}) {
122
+ const build = wrapper
123
+ ? configured("build", "./gradlew assembleDebug", ["./gradlew", "assembleDebug"])
124
+ : { key: "build", command: "./gradlew assembleDebug", argv: null, stdout: "", stderr: "" };
125
+ const test = wrapper
126
+ ? configured("test", "./gradlew testDebugUnitTest", ["./gradlew", "testDebugUnitTest"])
127
+ : { key: "test", command: "./gradlew testDebugUnitTest", argv: null, stdout: "", stderr: "" };
128
+ return [build, missing("lint"), test];
129
+ }
130
+
131
+ export function planFor({ platform, scripts = {}, wrapper = true } = {}) {
132
+ if (platform === "android") return buildGradlePlan({ wrapper });
133
+ if (platform === "node" || platform === "web") return buildNodePlan({ scripts, mode: "change" });
134
+ throw new UsageError(`unsupported platform: ${platform}`);
135
+ }
136
+
137
+ export function formatLog(results, cwd) {
138
+ return results.map((entry) => [
139
+ "## " + entry.command,
140
+ "cwd: " + cwd,
141
+ "exit_code: " + entry.exit_code,
142
+ "stdout:",
143
+ entry.stdout || "",
144
+ "stderr:",
145
+ entry.stderr || "",
146
+ "",
147
+ ].join("\n")).join("\n");
148
+ }
149
+
150
+ export function verifyChange({ cwd, platform = null, runner } = {}) {
151
+ const root = path.resolve(cwd || process.cwd());
152
+ const specFile = path.join(root, ".agentic", "spec.json");
153
+ const spec = readJson(specFile);
154
+ if (!spec || typeof spec.task !== "string" || !spec.task.trim()) {
155
+ throw new UsageError("spec.json is missing or lacks task");
156
+ }
157
+ const resolved = platform || spec.platform;
158
+ if (!PLATFORMS.has(resolved)) throw new UsageError(`unsupported platform: ${resolved ?? "missing"}`);
159
+
160
+ const scripts = readScripts(root);
161
+ const wrapper = fs.existsSync(path.join(root, "gradlew"));
162
+ const plan = planFor({ platform: resolved, scripts, wrapper });
163
+ const results = runPlan({ cwd: root, plan, runner });
164
+ const files = changedFiles(root);
165
+ if (!files.length) throw new Error("no application changes to verify");
166
+
167
+ let artifact = buildImplementation({
168
+ task: spec.task,
169
+ filesChanged: files,
170
+ results: results.map(({ key, command, exit_code }) => ({ key, command, exit_code })),
171
+ notes: `verify-change.mjs platform=${resolved} log=${LOG_PATH}`,
172
+ });
173
+ artifact = attachBugfixEvidence(root, spec, artifact, files);
174
+ return {
175
+ artifact,
176
+ results,
177
+ exitCode: implementationExitCode({ results, filesChanged: files }),
178
+ platform: resolved,
179
+ log: formatLog(results, root),
180
+ };
181
+ }
182
+
183
+ function parse(argv) {
184
+ const options = { cwd: process.cwd(), platform: null };
185
+ for (let index = 0; index < argv.length; index += 1) {
186
+ const key = argv[index];
187
+ if (key === "--help") return { help: true };
188
+ if (!["--cwd", "--platform"].includes(key)) throw new UsageError("unknown option " + key);
189
+ const value = argv[index + 1];
190
+ if (value === undefined) throw new UsageError("missing value for " + key);
191
+ if (key === "--cwd") options.cwd = value;
192
+ if (key === "--platform") options.platform = value;
193
+ index += 1;
194
+ }
195
+ return options;
196
+ }
197
+
198
+ function summary(result) {
199
+ const entry = (key) => result.results.find((item) => item.key === key);
200
+ const build = entry("build");
201
+ const lint = entry("lint");
202
+ const test = entry("test");
203
+ return [
204
+ result.exitCode === 0 ? "PASS" : "FAIL",
205
+ `platform=${result.platform}`,
206
+ `build=${build?.exit_code ?? "missing"}`,
207
+ `lint=${lint?.exit_code ?? "missing"}`,
208
+ `test=${test?.exit_code ?? "missing"}`,
209
+ `log=${LOG_PATH}`,
210
+ ].join(" ");
211
+ }
212
+
213
+ async function main() {
214
+ let options;
215
+ try {
216
+ options = parse(process.argv.slice(2));
217
+ } catch (error) {
218
+ process.stderr.write(error.message + "\n");
219
+ process.exitCode = 2;
220
+ return;
221
+ }
222
+ if (options.help) {
223
+ process.stdout.write("Usage: node scripts/verify-change.mjs --cwd <dir> [--platform node|web|android]\n");
224
+ return;
225
+ }
226
+ try {
227
+ const selfPath = fileURLToPath(import.meta.url);
228
+ const reexec = await maybeReexecInTaskContainer({
229
+ cwd: options.cwd,
230
+ scriptPath: selfPath,
231
+ root: path.resolve(path.dirname(selfPath), ".."),
232
+ });
233
+ if (reexec) {
234
+ process.exitCode = reexec.status;
235
+ return;
236
+ }
237
+ const result = verifyChange(options);
238
+ const agentic = path.join(path.resolve(options.cwd), ".agentic");
239
+ fs.mkdirSync(agentic, { recursive: true });
240
+ fs.writeFileSync(path.join(agentic, "implementation.json"), JSON.stringify(result.artifact, null, 2) + "\n");
241
+ fs.writeFileSync(path.join(agentic, "verify.log"), result.log + "\n");
242
+ process.stdout.write(summary(result) + "\n");
243
+ process.exitCode = result.exitCode;
244
+ } catch (error) {
245
+ process.stderr.write(error.message + "\n");
246
+ process.exitCode = error instanceof UsageError ? 2 : 1;
247
+ }
248
+ }
249
+
250
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
251
+ main();
252
+ }
@@ -0,0 +1,288 @@
1
+ #!/usr/bin/env node
2
+ /** Run Node build/lint/test verification once and write stage artifacts. */
3
+ import { spawnSync } from "node:child_process";
4
+ import fs from "node:fs";
5
+ import path from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ import { maybeReexecInTaskContainer } from "./lib/docker-workspace.mjs";
8
+
9
+ const SELF = fileURLToPath(import.meta.url);
10
+ const ROOT = path.resolve(path.dirname(SELF), "..");
11
+
12
+ const MAX_CAPTURE = 8000;
13
+ const TEST_PATH_RE = /(^|\/)(tests?|__tests__|spec)\/|\.(test|spec)\.[A-Za-z0-9]+$/;
14
+
15
+ function bounded(value) {
16
+ const text = String(value || "");
17
+ return text.length > MAX_CAPTURE ? text.slice(0, MAX_CAPTURE) + "\n[output truncated]\n" : text;
18
+ }
19
+
20
+ function defaultRunner(argv, cwd) {
21
+ return spawnSync(argv[0], argv.slice(1), {
22
+ cwd,
23
+ encoding: "utf8",
24
+ timeout: 1_800_000,
25
+ maxBuffer: 16 * 1024 * 1024,
26
+ });
27
+ }
28
+
29
+ function configured(key, command, argv) {
30
+ return { key, command, argv, stdout: "", stderr: "" };
31
+ }
32
+
33
+ function missing(key) {
34
+ return { key, command: "not-configured", argv: null, exit_code: 127, stdout: "", stderr: "" };
35
+ }
36
+
37
+ export function buildNodePlan({ scripts = {}, mode } = {}) {
38
+ if (!["change", "e2e"].includes(mode)) throw new Error("mode must be change or e2e");
39
+ const build = scripts.build ? configured("build", "npm run build", ["npm", "run", "build"]) : missing("build");
40
+ const lint = scripts.lint ? configured("lint", "npm run lint", ["npm", "run", "lint"]) : missing("lint");
41
+ const test = scripts.test ? configured("test", "npm test", ["npm", "test"]) : missing("test");
42
+ const sync = scripts["sync:dry"]
43
+ ? configured("sync", "npm run sync:dry", ["npm", "run", "sync:dry"])
44
+ : missing("sync");
45
+ return mode === "change" ? [build, lint, test] : [test, sync];
46
+ }
47
+
48
+ export function runPlan({ cwd, plan, runner = defaultRunner } = {}) {
49
+ if (!Array.isArray(plan)) throw new Error("plan must be an array");
50
+ const results = [];
51
+ for (const entry of plan) {
52
+ if (!entry || typeof entry !== "object") throw new Error("plan entry must be an object");
53
+ if (!entry.argv) {
54
+ results.push({ ...entry, exit_code: 127, stdout: "", stderr: "" });
55
+ continue;
56
+ }
57
+ const result = runner(entry.argv, cwd);
58
+ const exitCode = Number.isInteger(result?.status) ? result.status : 1;
59
+ results.push({
60
+ key: entry.key,
61
+ command: entry.command,
62
+ exit_code: exitCode,
63
+ stdout: bounded(result?.stdout),
64
+ stderr: bounded(result?.stderr || result?.error?.message),
65
+ });
66
+ }
67
+ return results;
68
+ }
69
+
70
+ export function parseGitStatus(output) {
71
+ const files = [];
72
+ for (const line of String(output || "").split("\n")) {
73
+ if (!line.trim()) continue;
74
+ let file = line.slice(3).trim();
75
+ if (file.includes(" -> ")) file = file.split(" -> ").pop().trim();
76
+ if (!file || file.startsWith(".agentic/") || file.startsWith('"')) continue;
77
+ files.push(file);
78
+ }
79
+ return files;
80
+ }
81
+
82
+ export function buildImplementation({ task, filesChanged, results, notes = "" } = {}) {
83
+ const entry = (key) => {
84
+ const found = (results || []).find((item) => item.key === key);
85
+ return {
86
+ command: found?.command || "not-configured",
87
+ exit_code: Number.isInteger(found?.exit_code) ? found.exit_code : 127,
88
+ ...(found?.stdout ? { stdout: found.stdout } : {}),
89
+ ...(found?.stderr ? { stderr: found.stderr } : {}),
90
+ };
91
+ };
92
+ return {
93
+ stage: "implementation",
94
+ task,
95
+ timestamp: new Date().toISOString(),
96
+ files_changed: filesChanged || [],
97
+ build: entry("build"),
98
+ lint: entry("lint"),
99
+ test: entry("test"),
100
+ notes,
101
+ };
102
+ }
103
+
104
+ export function buildE2eSummary({ task, results, logPath } = {}) {
105
+ return {
106
+ stage: "node-e2e",
107
+ task,
108
+ timestamp: new Date().toISOString(),
109
+ commands: (results || []).map((entry) => ({
110
+ command: entry.command,
111
+ exit_code: Number.isInteger(entry.exit_code) ? entry.exit_code : 127,
112
+ })),
113
+ log: logPath,
114
+ };
115
+ }
116
+
117
+ /** Deterministically turn the Node test result into the Stage 5 gate artifact. */
118
+ export function buildNodeE2eArtifact({ spec, results, logPath = ".agentic/node-test.log", timestamp = new Date().toISOString() } = {}) {
119
+ const test = (results || []).find((entry) => entry.key === "test");
120
+ const sync = (results || []).find((entry) => entry.key === "sync");
121
+ const testOkay = test?.exit_code === 0;
122
+ const syncOkay = sync?.exit_code === 0 || (sync?.exit_code === 127 && sync?.command === "not-configured");
123
+ const passed = testOkay && syncOkay;
124
+ const scenarios = (spec?.acceptance_criteria || []).map((ac) => ({
125
+ name: `${ac.id} ${String(ac.then || "").trim()}`.trim(),
126
+ status: passed ? "passed" : "failed",
127
+ evidence: `${logPath}#${ac.id}`,
128
+ }));
129
+ return {
130
+ stage: "e2e",
131
+ task: spec?.task,
132
+ timestamp,
133
+ verdict: passed ? "PASS" : "FAIL",
134
+ platform: "node",
135
+ commands: (results || []).map(({ command, exit_code }) => ({ command, exit_code })),
136
+ scenarios,
137
+ report_path: logPath,
138
+ app: { command: "npm test", url: "", device: "" },
139
+ };
140
+ }
141
+
142
+ function readJson(file) {
143
+ try {
144
+ return JSON.parse(fs.readFileSync(file, "utf8"));
145
+ } catch {
146
+ return null;
147
+ }
148
+ }
149
+
150
+ function readScripts(cwd) {
151
+ const packageJson = readJson(path.join(cwd, "package.json"));
152
+ return packageJson?.scripts && typeof packageJson.scripts === "object" ? packageJson.scripts : {};
153
+ }
154
+
155
+ function readTask(cwd, fallback) {
156
+ if (fallback) return fallback;
157
+ return readJson(path.join(cwd, ".agentic", "spec.json"))?.task || null;
158
+ }
159
+
160
+ function changedFiles(cwd) {
161
+ const result = spawnSync("git", ["-C", cwd, "status", "--porcelain", "--untracked-files=all"], {
162
+ encoding: "utf8",
163
+ timeout: 30_000,
164
+ });
165
+ if (result.status !== 0) return [];
166
+ return parseGitStatus(result.stdout);
167
+ }
168
+
169
+ function formatLog(results, cwd) {
170
+ return results.map((entry) => [
171
+ "## " + entry.command,
172
+ "cwd: " + cwd,
173
+ "exit_code: " + entry.exit_code,
174
+ "stdout:",
175
+ entry.stdout || "",
176
+ "stderr:",
177
+ entry.stderr || "",
178
+ "",
179
+ ].join("\n")).join("\n");
180
+ }
181
+
182
+ export function implementationExitCode({ results = [], filesChanged = [] } = {}) {
183
+ const entry = (key) => (results || []).find((item) => item.key === key);
184
+ const allowed = (value) =>
185
+ value && (value.exit_code === 0 || (value.exit_code === 127 && value.command === "not-configured"));
186
+ const testChanged = (filesChanged || []).some((file) => TEST_PATH_RE.test(file));
187
+ const build = entry("build");
188
+ const lint = entry("lint");
189
+ const test = entry("test");
190
+ const testOkay =
191
+ test && (test.exit_code === 0 || (!testChanged && test.exit_code === 127 && test.command === "not-configured"));
192
+ return allowed(build) && allowed(lint) && testOkay ? 0 : 1;
193
+ }
194
+
195
+ export function runVerification({ cwd, mode, task, runner = defaultRunner } = {}) {
196
+ const scripts = readScripts(cwd);
197
+ const plan = buildNodePlan({ scripts, mode });
198
+ const results = runPlan({ cwd, plan, runner });
199
+ const resolvedTask = readTask(cwd, task);
200
+ if (!resolvedTask) throw new Error("task is required (pass --task or write .agentic/spec.json)");
201
+ if (mode === "change") {
202
+ const files = changedFiles(cwd);
203
+ if (!files.length) throw new Error("no application changes to verify");
204
+ const artifact = buildImplementation({
205
+ task: resolvedTask,
206
+ filesChanged: files,
207
+ results,
208
+ notes: "verify-node.mjs change mode",
209
+ });
210
+ const exitCode = implementationExitCode({ results, filesChanged: files });
211
+ return { artifact, results, exitCode, mode };
212
+ }
213
+ const test = results.find((entry) => entry.key === "test");
214
+ const sync = results.find((entry) => entry.key === "sync");
215
+ const logPath = ".agentic/node-test.log";
216
+ const spec = readJson(path.join(cwd, ".agentic", "spec.json"));
217
+ if (!spec || !Array.isArray(spec.acceptance_criteria) || spec.acceptance_criteria.length === 0) {
218
+ throw new Error("spec.json with acceptance_criteria is required for e2e");
219
+ }
220
+ const artifact = buildE2eSummary({ task: resolvedTask, results, logPath });
221
+ const e2eArtifact = buildNodeE2eArtifact({ spec, results, logPath });
222
+ const syncOkay = sync?.exit_code === 0 || (sync?.exit_code === 127 && sync?.command === "not-configured");
223
+ const exitCode = test?.exit_code === 0 && syncOkay ? 0 : 1;
224
+ return { artifact, e2eArtifact, results, exitCode, mode, log: formatLog(results, cwd) };
225
+ }
226
+
227
+ function parse(argv) {
228
+ const options = { cwd: process.cwd(), mode: null, task: null };
229
+ for (let index = 0; index < argv.length; index += 1) {
230
+ const key = argv[index];
231
+ if (key === "--help") return { help: true };
232
+ if (!["--cwd", "--mode", "--task"].includes(key)) throw new Error("unknown option " + key);
233
+ const value = argv[index + 1];
234
+ if (value === undefined) throw new Error("missing value for " + key);
235
+ if (key === "--cwd") options.cwd = value;
236
+ if (key === "--mode") options.mode = value;
237
+ if (key === "--task") options.task = value;
238
+ index += 1;
239
+ }
240
+ if (!options.mode) throw new Error("missing --mode change|e2e");
241
+ return options;
242
+ }
243
+
244
+ async function main() {
245
+ let options;
246
+ try {
247
+ options = parse(process.argv.slice(2));
248
+ } catch (error) {
249
+ process.stderr.write(error.message + "\n");
250
+ process.exitCode = 2;
251
+ return;
252
+ }
253
+ if (options.help) {
254
+ process.stdout.write("Usage: node scripts/verify-node.mjs --cwd <dir> --mode change|e2e [--task <text>]\n");
255
+ return;
256
+ }
257
+ try {
258
+ const reexec = await maybeReexecInTaskContainer({
259
+ cwd: options.cwd,
260
+ scriptPath: SELF,
261
+ root: ROOT,
262
+ });
263
+ if (reexec) {
264
+ process.exitCode = reexec.status;
265
+ return;
266
+ }
267
+ const result = runVerification(options);
268
+ const agentic = path.join(path.resolve(options.cwd), ".agentic");
269
+ fs.mkdirSync(agentic, { recursive: true });
270
+ if (result.mode === "change") {
271
+ fs.writeFileSync(path.join(agentic, "implementation.json"), JSON.stringify(result.artifact, null, 2) + "\n");
272
+ } else {
273
+ fs.writeFileSync(path.join(agentic, "node-result.json"), JSON.stringify(result.artifact, null, 2) + "\n");
274
+ fs.writeFileSync(path.join(agentic, "node-test.log"), result.log + "\n");
275
+ fs.writeFileSync(path.join(agentic, "e2e.json"), JSON.stringify(result.e2eArtifact, null, 2) + "\n");
276
+ }
277
+ process.stdout.write(JSON.stringify({ mode: result.mode, exitCode: result.exitCode, artifact: result.artifact }) + "\n");
278
+ process.exitCode = result.exitCode;
279
+ } catch (error) {
280
+ process.stderr.write(error.message + "\n");
281
+ process.exitCode = 1;
282
+ }
283
+ }
284
+
285
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
286
+ main();
287
+ }
288
+