@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.
- package/README.md +367 -2
- package/bin/codex-acp.js +16 -0
- package/bin/kandev-auto-sync.mjs +101 -0
- package/bin/kandev-config.js +53 -0
- package/bin/kandev.js +35 -0
- package/config/config.yaml +6 -0
- package/config/docker/projects/opencodex-cli.json +79 -0
- package/config/docker/projects/samsung-bus-tracker.json +91 -0
- package/config/gateways.json +14 -0
- package/config/pipeline.json +150 -0
- package/config/workflows/sdlc.yaml +1019 -0
- package/docker/Dockerfile +68 -0
- package/docker/Dockerfile.opencodex-cli +44 -0
- package/docker/Dockerfile.samsung-bus-tracker +75 -0
- package/package.json +61 -4
- package/scripts/agent-tools-docker.mjs +223 -0
- package/scripts/baseline.mjs +20 -0
- package/scripts/codex-medium +2 -0
- package/scripts/codex-stage +22 -0
- package/scripts/gate.mjs +909 -0
- package/scripts/gateways/docker.mjs +64 -0
- package/scripts/gateways/speckit.mjs +78 -0
- package/scripts/install-prerequisites.mjs +48 -0
- package/scripts/lib/artifacts.mjs +990 -0
- package/scripts/lib/bugfix.mjs +325 -0
- package/scripts/lib/checksum.mjs +166 -0
- package/scripts/lib/docker-workspace.mjs +1209 -0
- package/scripts/lib/gateways.mjs +79 -0
- package/scripts/lib/kandev.mjs +273 -0
- package/scripts/lib/mcp.mjs +111 -0
- package/scripts/lib/pipeline.mjs +548 -0
- package/scripts/lib/planning-replan.mjs +103 -0
- package/scripts/lib/resume.mjs +207 -0
- package/scripts/lib/review-history.mjs +260 -0
- package/scripts/lib/stage-boundary.mjs +146 -0
- package/scripts/lib/stage-model.mjs +23 -0
- package/scripts/lib/task-worktree.mjs +40 -0
- package/scripts/measure-tokens.mjs +121 -0
- package/scripts/planning-tools.mjs +166 -0
- package/scripts/replan-planning.mjs +82 -0
- package/scripts/review-digest.mjs +240 -0
- package/scripts/run-android-e2e.mjs +116 -0
- package/scripts/run-code-review.mjs +281 -0
- package/scripts/run-detached.mjs +163 -0
- package/scripts/run-doc-review.mjs +155 -0
- package/scripts/run-gateways.mjs +138 -0
- package/scripts/sync.mjs +588 -0
- package/scripts/verify-change.mjs +252 -0
- package/scripts/verify-node.mjs +288 -0
- package/scripts/verify.mjs +442 -0
- package/scripts/wait-status.mjs +88 -0
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** Live verification for the Agentic SDLC pipeline. Exits 0 only when every check passes. */
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { connect } from "./lib/mcp.mjs";
|
|
8
|
+
import {
|
|
9
|
+
advertisedModels,
|
|
10
|
+
exportWorkflow,
|
|
11
|
+
findAgent,
|
|
12
|
+
findWorkspace,
|
|
13
|
+
getMcpConfig,
|
|
14
|
+
getWorkspaceDefaultProfiles,
|
|
15
|
+
health,
|
|
16
|
+
listProfiles,
|
|
17
|
+
listSteps,
|
|
18
|
+
listWorkflows,
|
|
19
|
+
} from "./lib/kandev.mjs";
|
|
20
|
+
import { compareFingerprint, fingerprint, gateCodeHash, readBaseline } from "./lib/checksum.mjs";
|
|
21
|
+
import { loadEnv, loadPipeline, normalizePrompt } from "./lib/pipeline.mjs";
|
|
22
|
+
import { normalizeMcpConfig, runSync } from "./sync.mjs";
|
|
23
|
+
|
|
24
|
+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
25
|
+
const SECRET_PATTERNS = [
|
|
26
|
+
[/ghp_[A-Za-z0-9]{20,}/, "GitHub PAT (ghp_)"],
|
|
27
|
+
[/github_pat_[A-Za-z0-9_]{20,}/, "GitHub fine-grained PAT"],
|
|
28
|
+
[/sk-[A-Za-z0-9]{20,}/, "sk- API key"],
|
|
29
|
+
[/AKIA[0-9A-Z]{16}/, "AWS access key"],
|
|
30
|
+
[/-----BEGIN [A-Z ]*PRIVATE KEY-----/, "private key block"],
|
|
31
|
+
[/xox[baprs]-[A-Za-z0-9-]{10,}/, "Slack token"],
|
|
32
|
+
[/AIza[0-9A-Za-z_-]{30,}/, "Google API key"],
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
function pick(obj, snake, camel) {
|
|
36
|
+
return obj?.[snake] !== undefined ? obj[snake] : obj?.[camel];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function eventsProjection(events) {
|
|
40
|
+
const out = {};
|
|
41
|
+
for (const [trigger, actions] of Object.entries(events || {})) {
|
|
42
|
+
if (!Array.isArray(actions) || actions.length === 0) continue;
|
|
43
|
+
out[trigger] = actions.map((action) => ({
|
|
44
|
+
type: action?.type,
|
|
45
|
+
config: Object.fromEntries(
|
|
46
|
+
Object.entries(action?.config || {}).sort(([a], [b]) => a.localeCompare(b)),
|
|
47
|
+
),
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
return JSON.stringify(out);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function validateStep(step, index, stageCount, terminalName = null, human = false) {
|
|
54
|
+
const problems = [];
|
|
55
|
+
const isTerminal = index === stageCount;
|
|
56
|
+
const name = step.name;
|
|
57
|
+
if (human) {
|
|
58
|
+
if (Boolean(pick(step, "auto_advance_requires_signal", "autoAdvanceRequiresSignal")) !== false) {
|
|
59
|
+
problems.push(`${name}: auto_advance_requires_signal must be false`);
|
|
60
|
+
}
|
|
61
|
+
if (Boolean(pick(step, "allow_manual_move", "allowManualMove")) !== true) {
|
|
62
|
+
problems.push(`${name}: allow_manual_move must be true`);
|
|
63
|
+
}
|
|
64
|
+
if (Boolean(pick(step, "complete_task_on_enter", "completeTaskOnEnter"))) {
|
|
65
|
+
problems.push(`${name}: complete_task_on_enter must be false`);
|
|
66
|
+
}
|
|
67
|
+
if (Boolean(pick(step, "is_start_step", "isStartStep"))) {
|
|
68
|
+
problems.push(`${name}: must not be start`);
|
|
69
|
+
}
|
|
70
|
+
if ((step.events?.on_enter || []).length || (step.events?.on_turn_complete || []).length) {
|
|
71
|
+
problems.push(`${name}: must not run or transition an agent`);
|
|
72
|
+
}
|
|
73
|
+
return problems;
|
|
74
|
+
}
|
|
75
|
+
if (isTerminal) {
|
|
76
|
+
if (terminalName && name !== terminalName) problems.push(`terminal step is ${name}, expected ${terminalName}`);
|
|
77
|
+
if (Boolean(pick(step, "complete_task_on_enter", "completeTaskOnEnter")) !== true) {
|
|
78
|
+
problems.push(`${name}: complete_task_on_enter must be true`);
|
|
79
|
+
}
|
|
80
|
+
if (Boolean(pick(step, "is_start_step", "isStartStep"))) problems.push(`${name}: must not be start`);
|
|
81
|
+
if (Boolean(pick(step, "allow_manual_move", "allowManualMove"))) {
|
|
82
|
+
problems.push(`${name}: allow_manual_move must be false`);
|
|
83
|
+
}
|
|
84
|
+
if ((step.events?.on_turn_complete || []).length) problems.push(`${name}: must not transition`);
|
|
85
|
+
return problems;
|
|
86
|
+
}
|
|
87
|
+
if (Boolean(pick(step, "auto_advance_requires_signal", "autoAdvanceRequiresSignal")) !== true) {
|
|
88
|
+
problems.push(`${name}: auto_advance_requires_signal must be true`);
|
|
89
|
+
}
|
|
90
|
+
if (Boolean(pick(step, "is_start_step", "isStartStep")) !== (index === 0)) {
|
|
91
|
+
problems.push(`${name}: is_start_step must be ${index === 0}`);
|
|
92
|
+
}
|
|
93
|
+
if (Boolean(pick(step, "allow_manual_move", "allowManualMove"))) {
|
|
94
|
+
problems.push(`${name}: allow_manual_move must be false`);
|
|
95
|
+
}
|
|
96
|
+
if (Boolean(pick(step, "complete_task_on_enter", "completeTaskOnEnter"))) {
|
|
97
|
+
problems.push(`${name}: complete_task_on_enter must be false`);
|
|
98
|
+
}
|
|
99
|
+
if ((step.events?.on_turn_complete || []).length) {
|
|
100
|
+
problems.push(`${name}: must not transition; the gate owns transitions`);
|
|
101
|
+
}
|
|
102
|
+
return problems;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function scanSecrets() {
|
|
106
|
+
const files = execFileSync("git", ["ls-files", "-z"], { cwd: ROOT, encoding: "utf8" })
|
|
107
|
+
.split("\0")
|
|
108
|
+
.filter(Boolean);
|
|
109
|
+
const hits = [];
|
|
110
|
+
for (const file of files) {
|
|
111
|
+
const abs = path.join(ROOT, file);
|
|
112
|
+
if (!fs.existsSync(abs)) continue;
|
|
113
|
+
const stat = fs.statSync(abs);
|
|
114
|
+
if (!stat.isFile()) continue;
|
|
115
|
+
if (stat.size > 2_000_000) continue;
|
|
116
|
+
const text = fs.readFileSync(abs, "utf8");
|
|
117
|
+
for (const [pattern, label] of SECRET_PATTERNS) {
|
|
118
|
+
if (pattern.test(text)) hits.push(`${file}: ${label}`);
|
|
119
|
+
}
|
|
120
|
+
if (file === ".env.example") {
|
|
121
|
+
for (const line of text.split("\n")) {
|
|
122
|
+
const m = line.match(/^([A-Z0-9_]+)=(.*)$/);
|
|
123
|
+
if (m && m[2].trim() !== "") hits.push(`.env.example: ${m[1]} has a value`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return hits;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function gateHeartbeat() {
|
|
131
|
+
const file = path.join(ROOT, ".cache", "gate-heartbeat.json");
|
|
132
|
+
if (!fs.existsSync(file)) throw new Error("gate is not running; start npm run gate");
|
|
133
|
+
const data = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
134
|
+
if (data.healthy !== true || data.error) throw new Error(`gate unhealthy: ${data.error || "unknown"}`);
|
|
135
|
+
if (!data.workflow || data.tasks === undefined) throw new Error("gate heartbeat is incomplete");
|
|
136
|
+
const expectedCode = gateCodeHash(ROOT);
|
|
137
|
+
if (data.code_hash !== expectedCode) {
|
|
138
|
+
throw new Error(`gate is running stale code (${data.code_hash ?? "missing"} != ${expectedCode}); restart npm run gate`);
|
|
139
|
+
}
|
|
140
|
+
const age = Date.now() - new Date(data.at).getTime();
|
|
141
|
+
if (!Number.isFinite(age) || age > 30_000) throw new Error(`gate heartbeat is ${Math.round(age / 1000)}s old`);
|
|
142
|
+
try {
|
|
143
|
+
process.kill(data.pid, 0);
|
|
144
|
+
} catch (err) {
|
|
145
|
+
if (err.code === "EPERM") return `pid ${data.pid}, ${data.workflow}, blocked ${data.blocked ?? 0}`;
|
|
146
|
+
throw new Error(`gate process ${data.pid} is not alive`);
|
|
147
|
+
}
|
|
148
|
+
return `pid ${data.pid}, ${data.workflow}, blocked ${data.blocked ?? 0}`;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export async function runVerify({ skipInstallCheck = false } = {}) {
|
|
152
|
+
loadEnv(ROOT);
|
|
153
|
+
const checks = [];
|
|
154
|
+
const check = (name, fn) => {
|
|
155
|
+
try {
|
|
156
|
+
const detail = fn();
|
|
157
|
+
checks.push({ name, ok: true, detail: detail || "" });
|
|
158
|
+
} catch (err) {
|
|
159
|
+
checks.push({ name, ok: false, detail: err.message });
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const asyncCheck = async (name, fn) => {
|
|
163
|
+
try {
|
|
164
|
+
const detail = await fn();
|
|
165
|
+
checks.push({ name, ok: true, detail: detail || "" });
|
|
166
|
+
} catch (err) {
|
|
167
|
+
checks.push({ name, ok: false, detail: err.message });
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const { pipeline, workflow, stages } = loadPipeline(ROOT);
|
|
172
|
+
const terminalName = workflow.steps.at(-1).name;
|
|
173
|
+
const before = skipInstallCheck ? null : fingerprint();
|
|
174
|
+
|
|
175
|
+
await asyncCheck("health", async () => {
|
|
176
|
+
await health();
|
|
177
|
+
return process.env.KANDEV_URL || "http://127.0.0.1:38429";
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
let mcp;
|
|
181
|
+
let workspace;
|
|
182
|
+
let agent;
|
|
183
|
+
await asyncCheck("connection", async () => {
|
|
184
|
+
mcp = await connect();
|
|
185
|
+
workspace = await findWorkspace(mcp, process.env.KANDEV_WORKSPACE || pipeline.workspace);
|
|
186
|
+
agent = await findAgent(mcp, process.env.KANDEV_AGENT || pipeline.agent);
|
|
187
|
+
return `${workspace.name} / ${agent.name}`;
|
|
188
|
+
});
|
|
189
|
+
if (!mcp || !workspace || !agent) {
|
|
190
|
+
return { checks, ok: false };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
await asyncCheck("agent", async () => {
|
|
194
|
+
if (agent.capability_status !== "ok") throw new Error(`${agent.name}: ${agent.capability_status}`);
|
|
195
|
+
return agent.name;
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
const models = await advertisedModels(agent.name);
|
|
199
|
+
const profiles = await listProfiles(mcp, agent.id);
|
|
200
|
+
const profileByName = new Map(profiles.map((p) => [p.name, p]));
|
|
201
|
+
await asyncCheck("profiles", async () => {
|
|
202
|
+
const problems = [];
|
|
203
|
+
const checkProfile = (name, model, reasoningEffort) => {
|
|
204
|
+
const profile = profileByName.get(name);
|
|
205
|
+
if (!profile) {
|
|
206
|
+
problems.push(`${name}: missing`);
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
if (profile.enabled === false) problems.push(`${name}: disabled`);
|
|
210
|
+
if (profile.model !== model) problems.push(`${name}: model ${profile.model} != ${model}`);
|
|
211
|
+
if (reasoningEffort && profile.config_options?.reasoning_effort !== reasoningEffort) {
|
|
212
|
+
problems.push(
|
|
213
|
+
`${name}: reasoning_effort ${profile.config_options?.reasoning_effort ?? "unset"} != ${reasoningEffort}`,
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
return profile;
|
|
217
|
+
};
|
|
218
|
+
const runnable = stages.filter((stage) => stage.human_approval !== true);
|
|
219
|
+
for (const stage of runnable) {
|
|
220
|
+
checkProfile(stage.profile_name, stage.model, stage.reasoning_effort);
|
|
221
|
+
}
|
|
222
|
+
if (pipeline.default_profile) {
|
|
223
|
+
const dp = pipeline.default_profile;
|
|
224
|
+
const defaultProfile = checkProfile(dp.name, dp.model, dp.reasoning_effort);
|
|
225
|
+
if (defaultProfile) {
|
|
226
|
+
const wsDefaults = await getWorkspaceDefaultProfiles(mcp, workspace.id);
|
|
227
|
+
if (wsDefaults.default_agent_profile_id !== defaultProfile.id) {
|
|
228
|
+
problems.push(
|
|
229
|
+
`workspace default_agent_profile_id ${wsDefaults.default_agent_profile_id || "unset"} != ${defaultProfile.id}`,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
if (wsDefaults.default_config_agent_profile_id !== defaultProfile.id) {
|
|
233
|
+
problems.push(
|
|
234
|
+
`workspace default_config_agent_profile_id ${wsDefaults.default_config_agent_profile_id || "unset"} != ${defaultProfile.id}`,
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (problems.length) throw new Error(problems.join("; "));
|
|
240
|
+
return `${runnable.length} profiles`;
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
await asyncCheck("models", async () => {
|
|
244
|
+
const runnable = stages.filter((stage) => stage.human_approval !== true);
|
|
245
|
+
const required = runnable.map((s) => s.model);
|
|
246
|
+
if (pipeline.default_profile) required.push(pipeline.default_profile.model);
|
|
247
|
+
const missing = required.filter((m) => !models.includes(m));
|
|
248
|
+
if (missing.length) throw new Error(`not advertised: ${missing.join(", ")}`);
|
|
249
|
+
return `${runnable.length} models advertised`;
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
await asyncCheck("profile-mcp", async () => {
|
|
253
|
+
const problems = [];
|
|
254
|
+
const runnable = stages.filter((stage) => stage.human_approval !== true);
|
|
255
|
+
for (const stage of runnable) {
|
|
256
|
+
const profile = profileByName.get(stage.profile_name);
|
|
257
|
+
if (!profile) continue;
|
|
258
|
+
const wanted = normalizeMcpConfig({ servers: stage.mcp_servers || {} }, { desired: true });
|
|
259
|
+
const config = await getMcpConfig(mcp, profile.id);
|
|
260
|
+
const live = normalizeMcpConfig(config);
|
|
261
|
+
if (JSON.stringify(live) !== JSON.stringify(wanted)) {
|
|
262
|
+
problems.push(`${stage.profile_name}: MCP config drift`);
|
|
263
|
+
}
|
|
264
|
+
if (Object.keys(wanted.servers).length > 0 && live.enabled !== true) {
|
|
265
|
+
problems.push(`${stage.profile_name}: MCP disabled`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (problems.length) throw new Error(problems.join("; "));
|
|
269
|
+
return `${runnable.length} profiles compared`;
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
const workflows = await listWorkflows(mcp, workspace.id);
|
|
273
|
+
const liveWorkflow = workflows.find((w) => w.name === workflow.name);
|
|
274
|
+
let liveSteps = [];
|
|
275
|
+
await asyncCheck("workflow", async () => {
|
|
276
|
+
if (!liveWorkflow) throw new Error(`workflow "${workflow.name}" missing`);
|
|
277
|
+
liveSteps = await listSteps(mcp, liveWorkflow.id);
|
|
278
|
+
if (liveSteps.length !== stages.length + 1) {
|
|
279
|
+
throw new Error(`expected ${stages.length + 1} steps (${stages.length} stages + Done), found ${liveSteps.length}`);
|
|
280
|
+
}
|
|
281
|
+
const ordered = liveSteps
|
|
282
|
+
.slice()
|
|
283
|
+
.sort((a, b) => Number(pick(a, "position", "position")) - Number(pick(b, "position", "position")));
|
|
284
|
+
const problems = [];
|
|
285
|
+
for (const [index, stage] of stages.entries()) {
|
|
286
|
+
const human = stage.human_approval === true;
|
|
287
|
+
const live = ordered[index];
|
|
288
|
+
if (!live) {
|
|
289
|
+
problems.push(`position ${index} missing`);
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
if (live.name !== stage.stepDefinition.name) {
|
|
293
|
+
problems.push(`position ${index}: ${live.name} != ${stage.stepDefinition.name}`);
|
|
294
|
+
}
|
|
295
|
+
if (normalizePrompt(live.prompt) !== normalizePrompt(stage.stepDefinition.prompt)) {
|
|
296
|
+
problems.push(`${live.name}: prompt drift`);
|
|
297
|
+
}
|
|
298
|
+
problems.push(...validateStep(live, index, stages.length, terminalName, human));
|
|
299
|
+
if (!human) {
|
|
300
|
+
const profileId = pick(live, "agent_profile_id", "agentProfileId");
|
|
301
|
+
const expectedId = profileByName.get(stage.profile_name)?.id;
|
|
302
|
+
if (profileId !== expectedId) problems.push(`${live.name}: profile binding mismatch`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
const terminal = ordered[stages.length];
|
|
306
|
+
if (!terminal) problems.push("terminal Done step missing");
|
|
307
|
+
else problems.push(...validateStep(terminal, stages.length, stages.length, terminalName));
|
|
308
|
+
if (problems.length) throw new Error(problems.join("; "));
|
|
309
|
+
return `${ordered.length} steps bound`;
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
await asyncCheck("export-roundtrip", async () => {
|
|
313
|
+
if (!liveWorkflow) throw new Error("workflow missing");
|
|
314
|
+
const exported = await exportWorkflow(mcp, liveWorkflow.id);
|
|
315
|
+
let doc = exported;
|
|
316
|
+
if (exported?.document) doc = exported.document;
|
|
317
|
+
if (typeof doc === "string") {
|
|
318
|
+
const yaml = await import("js-yaml");
|
|
319
|
+
doc = yaml.load(doc);
|
|
320
|
+
}
|
|
321
|
+
const wf = Array.isArray(doc?.workflows) ? doc.workflows[0] : doc?.workflow || doc;
|
|
322
|
+
const steps = wf?.steps || [];
|
|
323
|
+
if (steps.length !== stages.length + 1) throw new Error(`exported ${steps.length} steps`);
|
|
324
|
+
const ordered = steps.slice().sort((a, b) => a.position - b.position);
|
|
325
|
+
const problems = [];
|
|
326
|
+
for (const [index, stage] of stages.entries()) {
|
|
327
|
+
const human = stage.human_approval === true;
|
|
328
|
+
const step = ordered[index];
|
|
329
|
+
if (!step) {
|
|
330
|
+
problems.push(`exported position ${index} missing`);
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
if (step.name !== stage.stepDefinition.name) problems.push(`exported ${index} name ${step.name}`);
|
|
334
|
+
if (normalizePrompt(step.prompt) !== normalizePrompt(stage.stepDefinition.prompt)) {
|
|
335
|
+
problems.push(`exported ${step.name}: prompt lost`);
|
|
336
|
+
}
|
|
337
|
+
if (eventsProjection(step.events) !== eventsProjection(stage.stepDefinition.events)) {
|
|
338
|
+
problems.push(`exported ${step.name}: events drift`);
|
|
339
|
+
}
|
|
340
|
+
if (!human) {
|
|
341
|
+
const exportedProfile = pick(step, "agent_profile_id", "agentProfileId");
|
|
342
|
+
if (exportedProfile !== undefined && exportedProfile !== profileByName.get(stage.profile_name)?.id) {
|
|
343
|
+
problems.push(`exported ${step.name}: profile binding drift`);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
problems.push(...validateStep(step, index, stages.length, terminalName, human).map((p) => `exported ${p}`));
|
|
347
|
+
}
|
|
348
|
+
const terminal = ordered[stages.length];
|
|
349
|
+
if (!terminal) problems.push("exported Done missing");
|
|
350
|
+
else problems.push(...validateStep(terminal, stages.length, stages.length, terminalName).map((p) => `exported ${p}`));
|
|
351
|
+
if (problems.length) throw new Error(problems.join("; "));
|
|
352
|
+
return `${steps.length} steps round-tripped (full projection)`;
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
check("no-secrets", () => {
|
|
356
|
+
const hits = scanSecrets();
|
|
357
|
+
if (hits.length) throw new Error(hits.slice(0, 5).join("; "));
|
|
358
|
+
return "tracked files clean";
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
check("docker-projects", () => {
|
|
362
|
+
const projects = pipeline.docker?.projects || {};
|
|
363
|
+
const names = Object.keys(projects);
|
|
364
|
+
if (names.length === 0) return "none declared";
|
|
365
|
+
const problems = [];
|
|
366
|
+
const skipDocker = !pipeline.docker?.enabled || process.env.KANDEV_DOCKER_SKIP_DAEMON === "1" || process.env.KANDEV_DOCKER_SKIP_BUILD === "1";
|
|
367
|
+
for (const [name, cfg] of Object.entries(projects)) {
|
|
368
|
+
const dockerfilePath = cfg.resolved_dockerfile || (cfg.dockerfile ? path.resolve(ROOT, cfg.dockerfile) : null);
|
|
369
|
+
if (!dockerfilePath || !fs.existsSync(dockerfilePath)) {
|
|
370
|
+
problems.push(`${name}: missing dockerfile ${cfg.dockerfile || "(unset)"}`);
|
|
371
|
+
}
|
|
372
|
+
if (!skipDocker) {
|
|
373
|
+
try {
|
|
374
|
+
execFileSync("docker", ["image", "inspect", cfg.image], { stdio: "ignore", timeout: 10_000 });
|
|
375
|
+
} catch {
|
|
376
|
+
problems.push(`${name}: docker image ${cfg.image} not built`);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (problems.length) throw new Error(problems.join("; "));
|
|
381
|
+
return `${names.length} project docker configs (${names.join(", ")})`;
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
await asyncCheck("idempotent", async () => {
|
|
385
|
+
const out = await runSync({ root: ROOT, dryRun: true });
|
|
386
|
+
const writes = out.results.filter((r) =>
|
|
387
|
+
["created", "updated", "deleted", "planned-create", "planned-update", "planned-delete", "planned-reorder"].includes(r.action),
|
|
388
|
+
);
|
|
389
|
+
if (writes.length) {
|
|
390
|
+
throw new Error(`plan is not clean: ${writes.map((w) => `${w.action} ${w.name}`).join(", ")}`);
|
|
391
|
+
}
|
|
392
|
+
return `${out.results.length} resources unchanged (dry-run)`;
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
check("gate", () => gateHeartbeat());
|
|
396
|
+
|
|
397
|
+
if (!skipInstallCheck) {
|
|
398
|
+
check("install-immutable", () => {
|
|
399
|
+
const after = fingerprint();
|
|
400
|
+
const inRun = compareFingerprint(before, after);
|
|
401
|
+
if (inRun.length) throw new Error(`changed during verify: ${inRun.slice(0, 5).join("; ")}`);
|
|
402
|
+
const baseline = readBaseline(ROOT);
|
|
403
|
+
if (!baseline) throw new Error("baseline missing; run npm run baseline once after installing Kandev");
|
|
404
|
+
if (baseline.stale) {
|
|
405
|
+
throw new Error(`baseline schema ${baseline.version} is stale; rerun npm run baseline`);
|
|
406
|
+
}
|
|
407
|
+
const changes = compareFingerprint(baseline, after);
|
|
408
|
+
if (changes.length) throw new Error(changes.slice(0, 5).join("; "));
|
|
409
|
+
return `${after.count} files unchanged`;
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return { checks, ok: checks.every((c) => c.ok) };
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
async function main() {
|
|
417
|
+
const argv = process.argv.slice(2);
|
|
418
|
+
if (argv.includes("--help")) {
|
|
419
|
+
console.log("Usage: node scripts/verify.mjs [--json] [--skip-install-check]");
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
const json = argv.includes("--json");
|
|
423
|
+
let result;
|
|
424
|
+
try {
|
|
425
|
+
result = await runVerify({ skipInstallCheck: argv.includes("--skip-install-check") });
|
|
426
|
+
} catch (err) {
|
|
427
|
+
result = { checks: [{ name: "verify", ok: false, detail: err.message }], ok: false };
|
|
428
|
+
}
|
|
429
|
+
if (json) {
|
|
430
|
+
console.log(JSON.stringify(result, null, 2));
|
|
431
|
+
} else {
|
|
432
|
+
for (const c of result.checks) {
|
|
433
|
+
console.log(`${c.ok ? "OK " : "FAIL"} ${c.name}${c.detail ? `: ${c.detail}` : ""}`);
|
|
434
|
+
}
|
|
435
|
+
console.log(result.ok ? "\nall checks passed" : "\nverification failed");
|
|
436
|
+
}
|
|
437
|
+
process.exit(result.ok ? 0 : 1);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
441
|
+
main();
|
|
442
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** Wait for a stage status file without spending a model turn per poll. */
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
|
|
7
|
+
const TERMINAL = new Set(["completed", "failed"]);
|
|
8
|
+
|
|
9
|
+
function delay(ms) {
|
|
10
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function readStatus(file) {
|
|
14
|
+
try {
|
|
15
|
+
return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
16
|
+
} catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function waitForStatus({
|
|
22
|
+
file,
|
|
23
|
+
timeoutMs = 280_000,
|
|
24
|
+
intervalMs = 500,
|
|
25
|
+
sleep = delay,
|
|
26
|
+
} = {}) {
|
|
27
|
+
if (!file) throw new Error("status file is required");
|
|
28
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs < 0) throw new Error("timeoutMs must be >= 0");
|
|
29
|
+
if (!Number.isFinite(intervalMs) || intervalMs <= 0) throw new Error("intervalMs must be > 0");
|
|
30
|
+
const deadline = Date.now() + timeoutMs;
|
|
31
|
+
let last = null;
|
|
32
|
+
while (true) {
|
|
33
|
+
last = readStatus(file);
|
|
34
|
+
if (last && TERMINAL.has(last.status)) return last;
|
|
35
|
+
const remaining = deadline - Date.now();
|
|
36
|
+
if (remaining <= 0) return { ...(last || { status: "missing" }), timeout: true };
|
|
37
|
+
await sleep(Math.min(intervalMs, remaining));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function parse(argv) {
|
|
42
|
+
const options = {};
|
|
43
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
44
|
+
const key = argv[index];
|
|
45
|
+
if (key === "--help") return { help: true };
|
|
46
|
+
if (!["--status", "--timeout-ms", "--interval-ms"].includes(key)) {
|
|
47
|
+
throw new Error("unknown option " + key);
|
|
48
|
+
}
|
|
49
|
+
const value = argv[index + 1];
|
|
50
|
+
if (value === undefined) throw new Error("missing value for " + key);
|
|
51
|
+
if (key === "--status") options.status = value;
|
|
52
|
+
if (key === "--timeout-ms") options.timeoutMs = Number(value);
|
|
53
|
+
if (key === "--interval-ms") options.intervalMs = Number(value);
|
|
54
|
+
index += 1;
|
|
55
|
+
}
|
|
56
|
+
if (!options.status) throw new Error("missing --status");
|
|
57
|
+
options.status = path.resolve(options.status);
|
|
58
|
+
return options;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function main() {
|
|
62
|
+
let options;
|
|
63
|
+
try {
|
|
64
|
+
options = parse(process.argv.slice(2));
|
|
65
|
+
} catch (error) {
|
|
66
|
+
process.stderr.write(error.message + "\n");
|
|
67
|
+
process.exitCode = 2;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (options.help) {
|
|
71
|
+
process.stdout.write("Usage: node scripts/wait-status.mjs --status <file> [--timeout-ms 280000] [--interval-ms 500]\n");
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const result = await waitForStatus({ ...options, file: options.status });
|
|
76
|
+
process.stdout.write(JSON.stringify(result) + "\n");
|
|
77
|
+
if (result.status === "failed") process.exitCode = 1;
|
|
78
|
+
else if (result.timeout) process.exitCode = 2;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
process.stderr.write(error.message + "\n");
|
|
81
|
+
process.exitCode = 2;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
86
|
+
main();
|
|
87
|
+
}
|
|
88
|
+
|