@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,155 @@
1
+ #!/usr/bin/env node
2
+ /** Start the pinned planning-document review through run-detached. */
3
+ import { spawn } from "node:child_process";
4
+ import fs from "node:fs";
5
+ import path from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ import { requireStageModel, resolveStageAgent } from "./lib/stage-model.mjs";
8
+ import { readReviewRuns, reviewHistoryProblems, reviewScopeProblems } from "./lib/review-history.mjs";
9
+ import { maybeReexecInTaskContainer } from "./lib/docker-workspace.mjs";
10
+
11
+ const SELF = fileURLToPath(import.meta.url);
12
+
13
+ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
14
+ const DETACHED = path.join(ROOT, "scripts", "run-detached.mjs");
15
+ const PACKAGE = "@koreanhole/requirement-agent@0.1.7";
16
+ const NPX = path.join(path.dirname(process.execPath), process.platform === "win32" ? "npx.cmd" : "npx");
17
+ const ROLES = "ambiguity,testability,consistency";
18
+ const KILL_TIMEOUT_MS = "1860000";
19
+
20
+ function fail(message) {
21
+ process.stderr.write(`${message}\n`);
22
+ process.exit(2);
23
+ }
24
+
25
+ export function buildDocReviewCommand(input, env = process.env) {
26
+ const options = typeof input === "string" ? { cwd: input } : input || {};
27
+ if (!options.cwd) throw new Error("cwd is required");
28
+ if (!options.input) throw new Error("input is required");
29
+ const model = requireStageModel(env);
30
+ const agent = resolveStageAgent(env);
31
+ const cwd = path.resolve(options.cwd);
32
+ const inputPath = path.resolve(cwd, options.input);
33
+ return [
34
+ process.execPath,
35
+ DETACHED,
36
+ "--cwd", cwd,
37
+ "--log", options.log || ".agentic/doc-review.log",
38
+ "--status", options.status || ".agentic/doc-review.status.json",
39
+ "--kill-timeout-ms", options.killTimeoutMs || process.env.REVIEW_KILL_TIMEOUT_MS || KILL_TIMEOUT_MS,
40
+ "--",
41
+ NPX, "-y", PACKAGE, "review", inputPath,
42
+ "--roles", ROLES,
43
+ "--exclude", "plan.md",
44
+ "--exclude", "tasks.md",
45
+ "--exclude", "research.md",
46
+ "--exclude", "data-model.md",
47
+ "--exclude", "quickstart.md",
48
+ "--exclude", "analysis.md",
49
+ "--exclude", "contracts/**",
50
+ "--exclude", "checklists/**",
51
+ "--concurrency", "1",
52
+ "--max-doc-chars", "30000",
53
+ "--max-total-chars", "60000",
54
+ "--timeout", "600",
55
+ "--run-timeout", "1800",
56
+ "--agent", agent,
57
+ "--model", model,
58
+ "--out", path.join(cwd, ".agentic", "doc-review-runs"),
59
+ "--yes",
60
+ "--json",
61
+ ];
62
+ }
63
+
64
+ export function buildDocReviewEnvironment(env = process.env) {
65
+ const next = { ...env, npm_config_prefer_offline: "false" };
66
+ if (resolveStageAgent(env) === "gemini") {
67
+ next.GEMINI_CLI_TRUST_WORKSPACE = env.GEMINI_CLI_TRUST_WORKSPACE || "true";
68
+ }
69
+ return next;
70
+ }
71
+
72
+ /** Leave a durable, human-readable record when the convergence guard refuses a round. */
73
+ export function writePlanningBlock(cwd, problems) {
74
+ const root = path.resolve(cwd);
75
+ const agentic = path.join(root, ".agentic");
76
+ fs.mkdirSync(agentic, { recursive: true });
77
+ let spec = null;
78
+ try {
79
+ spec = JSON.parse(fs.readFileSync(path.join(agentic, "spec.json"), "utf8"));
80
+ } catch {
81
+ // A blocked planning run may not have written spec.json yet.
82
+ }
83
+ const payload = {
84
+ stage: "planning-blocked",
85
+ task: spec?.task ?? null,
86
+ timestamp: new Date().toISOString(),
87
+ verdict: "FAIL",
88
+ reason: problems.join("; "),
89
+ runs: readReviewRuns(root).map(({ id, major, startedAt }) => ({ id, major, startedAt })),
90
+ };
91
+ fs.writeFileSync(path.join(agentic, "planning-blocked.json"), `${JSON.stringify(payload, null, 2)}\n`);
92
+ return payload;
93
+ }
94
+
95
+ function parse(argv) {
96
+ const options = {};
97
+ for (let i = 0; i < argv.length; i += 1) {
98
+ const key = argv[i];
99
+ if (key === "--help") return { help: true };
100
+ if (!["--cwd", "--input", "--log", "--status"].includes(key)) fail(`unknown option ${key}`);
101
+ const value = argv[i + 1];
102
+ if (value === undefined) fail(`missing value for ${key}`);
103
+ options[key.slice(2)] = value;
104
+ i += 1;
105
+ }
106
+ if (!options.cwd) fail("missing --cwd");
107
+ if (!options.input) fail("missing --input");
108
+ return options;
109
+ }
110
+
111
+ function run(command, env) {
112
+ return new Promise((resolve, reject) => {
113
+ const child = spawn(command[0], command.slice(1), { stdio: "inherit", env });
114
+ child.on("error", reject);
115
+ child.on("exit", (code) => resolve(code ?? 1));
116
+ });
117
+ }
118
+
119
+ async function main() {
120
+ const options = parse(process.argv.slice(2));
121
+ if (options.help) {
122
+ console.log("Usage: node scripts/run-doc-review.mjs --cwd <abs> --input <feature-dir> [--log <rel>] [--status <rel>]");
123
+ return;
124
+ }
125
+ if (!fs.existsSync(path.resolve(options.cwd))) fail(`cwd does not exist: ${options.cwd}`);
126
+ if (!fs.existsSync(path.resolve(options.cwd, options.input))) fail(`input does not exist: ${options.input}`);
127
+ const reexec = await maybeReexecInTaskContainer({
128
+ cwd: options.cwd,
129
+ scriptPath: SELF,
130
+ root: ROOT,
131
+ });
132
+ if (reexec) {
133
+ process.exitCode = reexec.status;
134
+ return;
135
+ }
136
+ const history = reviewHistoryProblems(options.cwd);
137
+ if (history.length) {
138
+ writePlanningBlock(options.cwd, history);
139
+ fail(`non-converging review: ${history.join("; ")}`);
140
+ }
141
+ const scope = reviewScopeProblems(options.cwd, path.resolve(options.cwd, options.input));
142
+ if (scope.length) fail(`review scope expanded: ${scope.join("; ")}`);
143
+ try {
144
+ process.exitCode = await run(
145
+ buildDocReviewCommand(options),
146
+ buildDocReviewEnvironment(),
147
+ );
148
+ } catch (err) {
149
+ fail(err.message);
150
+ }
151
+ }
152
+
153
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
154
+ main();
155
+ }
@@ -0,0 +1,138 @@
1
+ #!/usr/bin/env node
2
+ /** Run every enabled gateway adapter and write .agentic/gateway.json. */
3
+ import { spawnSync } from "node:child_process";
4
+ import fs from "node:fs";
5
+ import path from "node:path";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
7
+ import { loadGateways } from "./lib/gateways.mjs";
8
+
9
+ const MODULE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
10
+ const ROOT = path.resolve(process.env.KANDEV_WORKFLOW_ROOT || MODULE_ROOT);
11
+ const IGNORED_PREFIXES = [".agentic/", ".specify/", ".agents/"];
12
+
13
+ function bounded(value, limit = 2000) {
14
+ const text = String(value || "");
15
+ return text.length > limit ? `${text.slice(0, limit)}\n[output truncated]\n` : text;
16
+ }
17
+
18
+ function gitChanges(cwd) {
19
+ const result = spawnSync("git", ["-C", cwd, "status", "--porcelain", "--untracked-files=all"], {
20
+ encoding: "utf8",
21
+ timeout: 30_000,
22
+ });
23
+ if (result.status !== 0) return [];
24
+ const files = [];
25
+ for (const line of String(result.stdout || "").split("\n")) {
26
+ if (!line.trim()) continue;
27
+ let file = line.slice(3).trim();
28
+ if (file.includes(" -> ")) file = file.split(" -> ").pop().trim();
29
+ if (file) files.push(file.replace(/^"|"$/g, ""));
30
+ }
31
+ return files;
32
+ }
33
+
34
+ function ignored(file) {
35
+ return IGNORED_PREFIXES.some((prefix) => file.startsWith(prefix));
36
+ }
37
+
38
+ function parse(argv) {
39
+ const options = { cwd: process.cwd(), task: "agent gateway", json: false };
40
+ for (let index = 0; index < argv.length; index += 1) {
41
+ const key = argv[index];
42
+ if (key === "--help") return { ...options, help: true };
43
+ if (key === "--json") { options.json = true; continue; }
44
+ if (key === "--once") { continue; }
45
+ if (key === "--docker") { options.docker = true; continue; }
46
+ if (key === "--no-docker") { options.docker = false; continue; }
47
+ if (!["--cwd", "--task"].includes(key)) throw new Error(`unknown option ${key}`);
48
+ const value = argv[index + 1];
49
+ if (value === undefined) throw new Error(`missing value for ${key}`);
50
+ if (key === "--cwd") options.cwd = value;
51
+ if (key === "--task") options.task = value;
52
+ index += 1;
53
+ }
54
+ return options;
55
+ }
56
+
57
+ function writeArtifact(cwd, artifact) {
58
+ const dir = path.join(cwd, ".agentic");
59
+ fs.mkdirSync(dir, { recursive: true });
60
+ fs.writeFileSync(path.join(dir, "gateway.json"), `${JSON.stringify(artifact, null, 2)}\n`);
61
+ }
62
+
63
+ export async function runGateways({ cwd, task = "agent gateway", root = ROOT, gateways = null, docker = undefined } = {}) {
64
+ const worktree = path.resolve(cwd || process.cwd());
65
+ if (!fs.existsSync(worktree)) throw new Error(`cwd does not exist: ${worktree}`);
66
+ if (docker !== undefined) {
67
+ process.env.KANDEV_DOCKER_ENABLED = String(docker);
68
+ }
69
+ const entries = (gateways || loadGateways(root)).filter((entry) => entry.enabled);
70
+ const before = gitChanges(worktree);
71
+ const results = [];
72
+ for (const entry of entries) {
73
+ const started = Date.now();
74
+ let result;
75
+ try {
76
+ const resolved = path.resolve(root, entry.module);
77
+ if (!resolved.startsWith(`${path.resolve(root)}${path.sep}`)) {
78
+ throw new Error(`gateway ${entry.id} module escapes the workflow root`);
79
+ }
80
+ if (!fs.existsSync(resolved)) throw new Error(`gateway ${entry.id} module missing: ${entry.module}`);
81
+ const mod = await import(pathToFileURL(resolved).href);
82
+ if (typeof mod.run !== "function") throw new Error(`gateway ${entry.id} does not export run()`);
83
+ result = await mod.run({ cwd: worktree, log: (message) => process.stderr.write(`${message}\n`), root, docker });
84
+ } catch (err) {
85
+ result = { id: entry.id, status: "FAIL", version: "", actions: [], evidence: [], error: err.message };
86
+ }
87
+ if (!result || typeof result !== "object") {
88
+ result = { id: entry.id, status: "FAIL", version: "", actions: [], evidence: [], error: "empty gateway result" };
89
+ }
90
+ results.push({ id: entry.id, ...result, duration_ms: Date.now() - started });
91
+ }
92
+ const after = gitChanges(worktree);
93
+ const preexisting = before.filter((file) => !ignored(file));
94
+ const changed = after.filter((file) => !before.includes(file) && !ignored(file));
95
+ const verdict = results.length > 0
96
+ && results.every((result) => result.status === "PASS")
97
+ && changed.length === 0
98
+ && preexisting.length === 0
99
+ ? "PASS"
100
+ : "FAIL";
101
+ const artifact = {
102
+ stage: "gateway",
103
+ task,
104
+ timestamp: new Date().toISOString(),
105
+ verdict,
106
+ gateways: results,
107
+ preexisting_changes: preexisting,
108
+ application_files_changed: changed,
109
+ };
110
+ writeArtifact(worktree, artifact);
111
+ return artifact;
112
+ }
113
+
114
+ async function main() {
115
+ const options = parse(process.argv.slice(2));
116
+ if (options.help) {
117
+ console.log("Usage: node scripts/run-gateways.mjs --cwd <abs> [--task <title>] [--json]");
118
+ return;
119
+ }
120
+ try {
121
+ const artifact = await runGateways({ cwd: options.cwd, task: options.task, root: ROOT, docker: options.docker });
122
+ if (options.json) console.log(JSON.stringify(artifact, null, 2));
123
+ else {
124
+ console.log(`gateway ${artifact.verdict}`);
125
+ for (const gateway of artifact.gateways) {
126
+ console.log(`${gateway.status.padEnd(4)} ${gateway.id} ${gateway.version || ""} ${bounded(gateway.error || "", 200)}`);
127
+ }
128
+ }
129
+ process.exitCode = artifact.verdict === "PASS" ? 0 : 1;
130
+ } catch (err) {
131
+ process.stderr.write(`FAIL gateways: ${err.message}\n`);
132
+ process.exitCode = 2;
133
+ }
134
+ }
135
+
136
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
137
+ main();
138
+ }