@nodii/dev 0.6.124 → 0.6.126

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/dist/heavy.js ADDED
@@ -0,0 +1,302 @@
1
+ // hub-377 (MW2-51, K02-4, K02-6, K02-7): every heavy command a lane
2
+ // runs goes through one machine-wide slot queue. The queue itself is
3
+ // heavy-slot.sh, beside this file; `nodii-dev heavy run -- CMD` reaches it
4
+ // (bin/nodii-dev execs it straight into bash). This module is the Node side:
5
+ // which shell commands are heavy, the rewrite that queues them, the argv the
6
+ // gate runner spawns, and a fallback for `heavy` when the CLI starts on Node.
7
+ // [TOOL GAP hub-86] MW5-19 places heavy-slot as a util; until the util
8
+ // pipeline exists it ships here.
9
+ import { spawn } from "node:child_process";
10
+ import { basename } from "node:path";
11
+ import { fileURLToPath } from "node:url";
12
+ import { CliError } from "./core.js";
13
+
14
+ export const HEAVY_SLOT_SCRIPT = fileURLToPath(new URL("./heavy-slot.sh", import.meta.url));
15
+ export const HEAVY_PREFIX = "nodii-dev heavy run -- ";
16
+ export const HEAVY_USAGE = "nodii-dev heavy run -- <command...> | nodii-dev heavy status";
17
+
18
+ /** The process that runs ARGV under a heavy slot: `[file, args]` for spawn. A nested call runs at once (K02-6). */
19
+ export const heavySlotArgv = (argv) => ["/bin/bash", [HEAVY_SLOT_SCRIPT, ...argv]];
20
+
21
+ /** `nodii-dev heavy run|status` when the CLI was started on Node or Bun rather than through bin/nodii-dev. */
22
+ export async function heavyCommand(args, { spawnImpl = spawn, env = process.env, signals = process } = {}) {
23
+ const [action, ...rest] = args;
24
+ let argv;
25
+ if (action === "status") argv = ["--status"];
26
+ else if (action === "run") {
27
+ argv = rest[0] === "--" ? rest.slice(1) : rest;
28
+ if (!argv.length) throw new CliError("USAGE", HEAVY_USAGE, 2);
29
+ } else throw new CliError("USAGE", HEAVY_USAGE, 2);
30
+ const [file, fileArgs] = heavySlotArgv(argv);
31
+ return new Promise((resolve) => {
32
+ const child = spawnImpl(file, fileArgs, { stdio: "inherit", env });
33
+ // The slot holder is the bash child; pass a stop on to it so it frees the slot and stops the job.
34
+ const forward = (signal) => () => child.kill(signal);
35
+ const handlers = ["SIGINT", "SIGTERM", "SIGHUP"].map((signal) => [signal, forward(signal)]);
36
+ for (const [signal, handler] of handlers) signals.on?.(signal, handler);
37
+ const done = (code) => {
38
+ for (const [signal, handler] of handlers) signals.off?.(signal, handler);
39
+ resolve(code);
40
+ };
41
+ child.on("error", () => done(127));
42
+ child.on("close", (code, signal) => done(code ?? (signal ? 128 : 1)));
43
+ });
44
+ }
45
+
46
+ // --- which shell commands are heavy -------------------------------------------
47
+
48
+ /**
49
+ * Shell words with their source offsets, split into simple commands on control
50
+ * operators (`&&`, `||`, `;`, `|`, `&`, newline). Quotes are kept out of a word's
51
+ * text; a word's `start` is where it begins in COMMAND, so a prefix can be
52
+ * inserted in front of it.
53
+ */
54
+ export function shellCommands(command) {
55
+ const text = String(command ?? "");
56
+ const out = [[]];
57
+ let word = null;
58
+ const finish = (end) => {
59
+ if (word) out.at(-1).push({ ...word, end });
60
+ word = null;
61
+ };
62
+ for (let i = 0; i < text.length; i += 1) {
63
+ const c = text[i];
64
+ if (c === "\\" && i + 1 < text.length) {
65
+ word ??= { text: "", start: i, quoted: false };
66
+ if (text[i + 1] !== "\n") word.text += text[i + 1];
67
+ i += 1;
68
+ continue;
69
+ }
70
+ if (c === "'" || c === '"') {
71
+ word ??= { text: "", start: i, quoted: false };
72
+ word.quoted = true;
73
+ let j = i + 1;
74
+ while (j < text.length && text[j] !== c) {
75
+ if (c === '"' && text[j] === "\\" && j + 1 < text.length) { word.text += text[j + 1]; j += 2; continue; }
76
+ word.text += text[j];
77
+ j += 1;
78
+ }
79
+ i = j;
80
+ continue;
81
+ }
82
+ if (c === " " || c === "\t") { finish(i); continue; }
83
+ const two = text.slice(i, i + 2);
84
+ // `2>&1`, `>&2` and `&>file` are redirections, not the background operator.
85
+ const redirect = c === "&" && ((word && /[<>]$/.test(word.text)) || text[i + 1] === ">");
86
+ if (!redirect && (two === "&&" || two === "||" || two === "|&" || two === ";;")) { finish(i); out.push([]); i += 1; continue; }
87
+ if (!redirect && (c === ";" || c === "|" || c === "&" || c === "\n")) { finish(i); out.push([]); continue; }
88
+ word ??= { text: "", start: i, quoted: false };
89
+ word.text += c;
90
+ }
91
+ finish(text.length);
92
+ return out.filter((segment) => segment.length);
93
+ }
94
+
95
+ // Words that start a command without being it. After these the queue prefix goes after them...
96
+ const KEYWORDS = new Set(["if", "then", "else", "elif", "do", "while", "until", "!", "exec", "command", "{", "("]);
97
+ // ...and these wrap the job, so the prefix goes in front of them (the slot is held for all of it).
98
+ const WRAPPERS = new Set(["time", "nohup", "env", "timeout", "gtimeout", "nice", "caffeinate"]);
99
+ const ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/;
100
+ const HELP = new Set(["--version", "-v", "-V", "--help", "-h"]);
101
+
102
+ // A package script is heavy when any `:`-part of its name is one of these (`test:unit`, `typecheck`,
103
+ // `build:all`, `gate`), or when it starts a stack. A lone `validate:<name>` is a cheap scan (heavy-slot v23).
104
+ const HEAVY_SCRIPT_PARTS = new Set(["test", "tests", "typecheck", "type-check", "types", "tsc", "check", "build", "gate", "gates", "lint", "e2e", "ci", "verify", "coverage", "prepush", "pre-push", "integration", "regression"]);
105
+ export function heavyScript(name) {
106
+ const script = String(name ?? "");
107
+ if (!script || script.startsWith("validate:")) return false;
108
+ if (/stack:up|stack-up/.test(script)) return true;
109
+ return script.split(/[:\s]/).some((part) => HEAVY_SCRIPT_PARTS.has(part));
110
+ }
111
+
112
+ const plainName = (word) => basename(String(word ?? "").replace(/^[({]+/, "").replace(/[)}]+$/, ""));
113
+ const firstOperand = (args, valueFlags = new Set()) => {
114
+ for (let i = 0; i < args.length; i += 1) {
115
+ if (args[i] === "--") return args[i + 1] ? { word: args[i + 1], at: i + 1 } : null;
116
+ if (args[i].startsWith("-")) { if (valueFlags.has(args[i])) i += 1; continue; }
117
+ return { word: args[i], at: i };
118
+ }
119
+ return null;
120
+ };
121
+
122
+ const PM_VALUE_FLAGS = {
123
+ npm: new Set(["-w", "--workspace", "--prefix", "-C"]),
124
+ pnpm: new Set(["-C", "--dir", "--filter", "-F", "--filter-prod", "--workspace-concurrency", "--reporter", "--test-pattern", "--changed-files-ignore-pattern"]),
125
+ yarn: new Set(["--cwd"]),
126
+ bun: new Set(["--cwd", "-F", "--filter", "--config", "-c"]),
127
+ };
128
+
129
+ /** What a package manager command runs: a script name, an inner command, or nothing heavy. */
130
+ function packageManager(name, args) {
131
+ const values = PM_VALUE_FLAGS[name];
132
+ let found = firstOperand(args, values);
133
+ if (!found) return false;
134
+ let sub = found.word;
135
+ let rest = args.slice(found.at + 1);
136
+ if (["recursive", "multi", "m"].includes(sub) && name === "pnpm") {
137
+ found = firstOperand(rest, values);
138
+ if (!found) return false;
139
+ sub = found.word; rest = rest.slice(found.at + 1);
140
+ }
141
+ if (name === "yarn" && sub === "workspace") return packageManager(name, rest.slice(1));
142
+ if (name === "yarn" && sub === "workspaces") {
143
+ const run = rest.indexOf("run");
144
+ return run !== -1 && heavyScript(firstOperand(rest.slice(run + 1))?.word);
145
+ }
146
+ if (["run", "run-script", "rum", "urn"].includes(sub)) return heavyScript(firstOperand(rest, values)?.word);
147
+ if (["exec", "dlx", "x"].includes(sub)) return heavyArgv(rest.filter((word, i) => !(i === 0 && word === "--")));
148
+ if (["test", "t", "tst"].includes(sub)) return true;
149
+ if (name === "npm") return false;
150
+ if (name === "bun" && sub === "build") return true;
151
+ if (HELP.has(sub)) return false;
152
+ return heavyScript(sub);
153
+ }
154
+
155
+ /**
156
+ * Whether ARGV (a simple command, its name first) is heavy work: a gate, a
157
+ * full or affected test suite, a typecheck, a build, an image build, a detached
158
+ * stack start, or a push whose hooks run the gates.
159
+ */
160
+ export function heavyArgv(argv) {
161
+ const [first, ...args] = argv;
162
+ const name = plainName(first);
163
+ if (!name) return false;
164
+ // `tsc --version`, `vitest -h`: a question, not a run.
165
+ if (args.length === 1 && HELP.has(args[0])) return false;
166
+ const sub = firstOperand(args)?.word;
167
+ switch (name) {
168
+ case "npm": case "pnpm": case "yarn": case "bun":
169
+ return packageManager(name, args);
170
+ case "npx": case "pnpx": case "bunx": {
171
+ const inner = args.filter((word) => !["-y", "--yes", "--no-install", "--"].includes(word));
172
+ return heavyArgv(inner);
173
+ }
174
+ case "vitest": case "jest": case "mocha": case "ava": case "tsc": case "vue-tsc": case "tsgo": case "turbo": case "nx": case "pytest": case "tox":
175
+ return !args.some((word) => ["--init", "--showConfig"].includes(word));
176
+ case "playwright": return sub === "test";
177
+ case "cypress": return sub === "run";
178
+ case "node": return args.some((word) => word === "--test" || word.startsWith("--test="));
179
+ case "python": case "python3": return args[0] === "-m" && ["pytest", "unittest"].includes(args[1]);
180
+ case "go": return ["test", "build", "vet"].includes(sub);
181
+ case "cargo": return ["test", "build", "check", "clippy", "bench", "nextest"].includes(sub);
182
+ case "gradle": case "gradlew": return args.some((word) => ["build", "test", "check", "assemble"].includes(word));
183
+ case "mvn": case "mvnw": return args.some((word) => ["test", "verify", "package", "install"].includes(word));
184
+ case "make": case "gmake": return args.some((word) => !word.startsWith("-") && !ASSIGNMENT.test(word) && heavyScript(word));
185
+ case "docker": {
186
+ if (sub === "build") return true;
187
+ if (sub === "buildx" || sub === "image") return args.includes("build");
188
+ if (sub === "compose") return composeHeavy(args.slice(args.indexOf("compose") + 1));
189
+ return false;
190
+ }
191
+ case "docker-compose": return composeHeavy(args);
192
+ case "git": return gitPush(args);
193
+ default: return false;
194
+ }
195
+ }
196
+
197
+ // `compose build`, and an `up` that starts a stack and exits (-d, --detach, --wait). A foreground `up` never
198
+ // exits, so like a dev server it never holds a slot (K02-7); a `down` frees memory and never waits.
199
+ function composeHeavy(args) {
200
+ const values = new Set(["-f", "--file", "-p", "--project-name", "--profile", "--env-file", "--project-directory", "--ansi", "--progress", "--parallel"]);
201
+ const found = firstOperand(args, values);
202
+ if (!found) return false;
203
+ if (found.word === "build") return true;
204
+ if (found.word !== "up") return false;
205
+ return args.slice(found.at + 1).some((word) => word === "--detach" || word === "--wait" || word.startsWith("--wait=") || /^-[a-zA-Z]*d[a-zA-Z]*$/.test(word));
206
+ }
207
+
208
+ function gitPush(args) {
209
+ for (let i = 0; i < args.length; i += 1) {
210
+ if (["-C", "-c", "--git-dir", "--work-tree", "--namespace", "--exec-path", "--config-env"].includes(args[i])) { i += 1; continue; }
211
+ if (args[i].startsWith("-")) continue;
212
+ return args[i] === "push";
213
+ }
214
+ return false;
215
+ }
216
+
217
+ /** The words of one simple command up to its name, and where the queue prefix goes. */
218
+ function commandStart(segment) {
219
+ let at = 0;
220
+ let insertAt = null;
221
+ while (at < segment.length) {
222
+ const word = segment[at];
223
+ const text = word.text.replace(/^[({]+/, "");
224
+ if (!word.quoted && (ASSIGNMENT.test(text) || KEYWORDS.has(word.text))) { at += 1; continue; }
225
+ if (!word.quoted && WRAPPERS.has(text)) {
226
+ insertAt ??= word.start + (word.text.length - text.length);
227
+ at += 1;
228
+ // A wrapper's own options and operands: env's assignments, timeout's duration, nice's -n value.
229
+ while (at < segment.length && (segment[at].text.startsWith("-") || ASSIGNMENT.test(segment[at].text) || /^\d+(?:\.\d+)?[smhd]?$/.test(segment[at].text))) {
230
+ if (["-n", "-s", "-k", "--signal", "--kill-after", "-u"].includes(segment[at].text)) at += 1;
231
+ at += 1;
232
+ }
233
+ continue;
234
+ }
235
+ const lead = word.text.length - text.length;
236
+ return { at, insertAt: insertAt ?? word.start + lead };
237
+ }
238
+ return null;
239
+ }
240
+
241
+ /** Already queued: `nodii-dev heavy run …`, a heavy-slot.sh copy, or a shell running one. */
242
+ function queued(argv) {
243
+ const name = plainName(argv[0]);
244
+ if (/^nodii-dev(?:\.js)?$/.test(name) || (["node", "bun"].includes(name) && /nodii-dev(?:\.js)?$/.test(argv[1] ?? ""))) {
245
+ const rest = /^nodii-dev(?:\.js)?$/.test(name) ? argv.slice(1) : argv.slice(2);
246
+ return rest.find((word) => !word.startsWith("-")) === "heavy";
247
+ }
248
+ if (name === "heavy-slot.sh") return true;
249
+ return ["bash", "sh", "zsh"].includes(name) && /(?:^|\/)heavy-slot\.sh$/.test(argv.find((word, i) => i > 0 && !word.startsWith("-")) ?? "");
250
+ }
251
+
252
+ // `nodii-dev lane check --gate …` and `nodii-dev receipt write --run …` queue each gate themselves.
253
+ function selfQueued(argv) {
254
+ const name = plainName(argv[0]);
255
+ if (!/^nodii-dev(?:\.js)?$/.test(name)) return false;
256
+ const [command, action] = argv.slice(1).filter((word) => !word.startsWith("-"));
257
+ return (command === "lane" && action === "check") || (command === "receipt" && action === "write");
258
+ }
259
+
260
+ /**
261
+ * The heavy jobs in a shell COMMAND that are not in the queue, and COMMAND
262
+ * rewritten so that each runs under `nodii-dev heavy run --`. Nothing heavy
263
+ * and unqueued: `jobs` is empty.
264
+ */
265
+ export function unqueuedHeavy(command) {
266
+ const text = String(command ?? "");
267
+ const jobs = [];
268
+ for (const segment of shellCommands(text)) {
269
+ const start = commandStart(segment);
270
+ if (!start) continue;
271
+ // A subshell's closing `)` stays on its last word: `(cd x && pnpm test)`.
272
+ const argv = segment.slice(start.at).map((word) => (word.quoted ? word.text : word.text.replace(/\)+$/, "")));
273
+ if (queued(argv) || selfQueued(argv)) continue;
274
+ const name = plainName(argv[0]);
275
+ // A shell running a string runs every command in it.
276
+ const inner = ["bash", "sh", "zsh"].includes(name) ? argv.findIndex((word) => /^-[a-z]*c[a-z]*$/.test(word)) : -1;
277
+ const heavy = inner !== -1 ? unqueuedHeavy(argv[inner + 1] ?? "").jobs.length > 0 : heavyArgv(argv);
278
+ if (!heavy) continue;
279
+ const words = segment.slice(start.at);
280
+ jobs.push({ insertAt: start.insertAt, text: text.slice(start.insertAt, words.at(-1).end).trim() });
281
+ }
282
+ let rewritten = text;
283
+ for (const job of [...jobs].sort((a, b) => b.insertAt - a.insertAt))
284
+ rewritten = `${rewritten.slice(0, job.insertAt)}${HEAVY_PREFIX}${rewritten.slice(job.insertAt)}`;
285
+ return { jobs: jobs.map((job) => job.text), command: rewritten };
286
+ }
287
+
288
+ /** The safety hook's refusal for an unqueued heavy command (null when there is none). */
289
+ export function heavyViolation(command, { original = command } = {}) {
290
+ const found = unqueuedHeavy(command);
291
+ if (!found.jobs.length) return null;
292
+ // When heredoc bodies were left out to judge the command, the rewrite can't be the whole command.
293
+ const instead = command === original ? `Run instead:\n ${found.command}` : `Put \`${HEAVY_PREFIX.trim()}\` in front of each:\n${found.jobs.map((job) => ` ${HEAVY_PREFIX}${job}`).join("\n")}`;
294
+ return {
295
+ code: "SAFETY_HEAVY_UNQUEUED",
296
+ message: [
297
+ `Heavy work runs only through the machine's heavy-slot queue (MW2-51, K02-4; hub-377). Not queued: ${found.jobs.map((job) => `\`${job}\``).join(", ")}.`,
298
+ instead,
299
+ "It waits for a slot (printing its queue place and wait), runs the command, and frees the slot when the command exits; `git push` uses the landing reserve, and a nested call never takes a second slot. A long wait can outlast the tool's timeout: when `nodii-dev heavy status` shows the slots busy, run it in the background.",
300
+ ].join("\n"),
301
+ };
302
+ }
package/dist/nodii-dev.js CHANGED
@@ -13,6 +13,12 @@ routeStdout();
13
13
  const argv = process.argv.slice(2);
14
14
 
15
15
  async function run() {
16
+ // hub-377: bin/nodii-dev execs the heavy-slot queue itself; this is for a CLI started on Node or Bun.
17
+ if (argv[0] === "heavy") {
18
+ const { heavyCommand } = await import("./heavy.js");
19
+ process.exitCode = await heavyCommand(argv.slice(1));
20
+ return;
21
+ }
16
22
  // AGENT-HARNESS-19: this is the executable boundary, so every ordinary CLI
17
23
  // invocation re-grounds without adding hidden requests to library callers.
18
24
  if (shouldReground(argv)) await regroundCurrentLane();
package/dist/review.js CHANGED
@@ -14,6 +14,7 @@ import { pickerPrompt } from "./gather.js";
14
14
  import { componentSetsIn, designCatalogSets } from "./figma-scope.js";
15
15
  import { gitPrivatePath } from "./safety.js";
16
16
  import { GENERATED_PAGE_GLOB, GENERATED_SUFFIX, hasGeneratedPageStamp } from "./surface.js";
17
+ import { heavySlotArgv } from "./heavy.js";
17
18
 
18
19
  const execFileAsync = promisify(execFile);
19
20
  export const CHECKS = ["rules", "figma", "code"];
@@ -64,11 +65,16 @@ export const privateStore = (cwd) => ({
64
65
  },
65
66
  });
66
67
 
67
- /** One gate through the shell in the worktree; its output goes to stderr, its tail is kept. */
68
- export function runGate(command, cwd) {
68
+ /**
69
+ * One gate through the shell in the worktree; its output goes to stderr, its tail is kept.
70
+ * Every gate waits for a machine-wide heavy slot first and holds it while it runs (hub-377,
71
+ * MW2-51); inside a command that already holds one it runs at once (K02-6). The queue never times out.
72
+ */
73
+ export function runGate(command, cwd, { argv = heavySlotArgv } = {}) {
69
74
  return new Promise((resolve) => {
70
75
  let tail = "";
71
- const child = spawn("/bin/sh", ["-c", command], { cwd, stdio: ["ignore", "pipe", "pipe"] });
76
+ const [file, args] = argv(["/bin/sh", "-c", command]);
77
+ const child = spawn(file, args, { cwd, stdio: ["ignore", "pipe", "pipe"] });
72
78
  const keep = (chunk) => {
73
79
  process.stderr.write(chunk);
74
80
  tail = (tail + chunk).slice(-4000);
@@ -313,19 +319,40 @@ export function reviewerInvocation({ runtime, model, profile, schema, workdir, s
313
319
  };
314
320
  }
315
321
 
316
- /** Spawn with stdin; never throws for the process's own failures, the caller maps them. */
317
- export function spawnReviewer({ command, args, env, cwd, input, timeoutMs }) {
322
+ /**
323
+ * Spawn with stdin; never throws for the process's own failures, the caller maps them.
324
+ * A review loop is heavy work (MW2-51), so the reviewer runs under a machine-wide heavy slot (hub-377).
325
+ * Its timeout starts when the slot is granted, never while it waits in the queue; on timeout the slot
326
+ * holder gets SIGTERM, which stops the reviewer's whole process tree and frees the slot.
327
+ */
328
+ export function spawnReviewer({ command, args, env, cwd, input, timeoutMs }, { argv = heavySlotArgv } = {}) {
318
329
  return new Promise((resolve) => {
319
330
  let stdout = "";
320
331
  let stderr = "";
321
332
  let timedOut = false;
322
- const child = spawn(command, args, { cwd, env: { ...process.env, ...env }, stdio: ["pipe", "pipe", "pipe"] });
323
- const timer = setTimeout(() => { timedOut = true; child.kill("SIGKILL"); }, timeoutMs);
333
+ let timer = null;
334
+ const runEnv = { ...process.env, ...env };
335
+ const [file, fileArgs] = argv([command, ...args]);
336
+ const child = spawn(file, fileArgs, { cwd, env: runEnv, stdio: ["pipe", "pipe", "pipe"] });
337
+ const start = () => {
338
+ timer ??= setTimeout(() => {
339
+ timedOut = true;
340
+ child.kill("SIGTERM");
341
+ setTimeout(() => child.kill("SIGKILL"), 10_000).unref();
342
+ }, timeoutMs);
343
+ };
344
+ // Inside a held slot, or when not queued at all, the reviewer starts at once.
345
+ if (runEnv.NODII_HEAVY_SLOT_HELD === "1" || file === command) start();
324
346
  child.stdout.on("data", (chunk) => { stdout += chunk; });
325
- child.stderr.on("data", (chunk) => { stderr = (stderr + chunk).slice(-4000); });
347
+ child.stderr.on("data", (chunk) => {
348
+ stderr = (stderr + chunk).slice(-4000);
349
+ if (/\[heavy-slot\] got /.test(String(chunk))) start();
350
+ });
326
351
  child.stdin.on("error", () => {});
327
- child.on("error", (error) => { clearTimeout(timer); resolve({ code: null, stdout, stderr, timedOut, missing: error.code === "ENOENT", error: error.message }); });
328
- child.on("close", (code) => { clearTimeout(timer); resolve({ code, stdout, stderr, timedOut, missing: false }); });
352
+ const done = (result) => { if (timer) clearTimeout(timer); resolve(result); };
353
+ child.on("error", (error) => done({ code: null, stdout, stderr, timedOut, missing: error.code === "ENOENT", error: error.message }));
354
+ // Under the queue a missing reviewer is bash's "command not found" (exit 127), not a spawn error.
355
+ child.on("close", (code) => done({ code, stdout, stderr, timedOut, missing: code === 127 && /command not found|No such file or directory/.test(stderr) }));
329
356
  child.stdin.end(input);
330
357
  });
331
358
  }
@@ -904,10 +931,17 @@ export async function runLaneCheck(ref, flags, { request, lane, freeze, current,
904
931
  // Figma (DEV-REV-9): only a lane with a frontend side.
905
932
  let figma;
906
933
  if (!["frontend", "both"].includes(lane.side)) figma = { check: "figma", outcome: "NOT_APPLICABLE", iterationCount: 0, reviewerErrors: [], inputs: { side: lane.side ?? null }, findings: [] };
907
- else if (!Array.isArray(freeze?.boundaries?.figma) || !freeze.boundaries.figma.length) {
908
- // Nothing to compare, so the leg is skipped, not crashed. Dev requires a
909
- // frontend lane's figma check to run (NOT_APPLICABLE is refused there), so
910
- // the skip records as unavailable and the run stays NOT CLEAN until it is set.
934
+ else if (Array.isArray(freeze?.boundaries?.figma) && !freeze.boundaries.figma.length) {
935
+ // hub-364: a Freeze that sets its Figma boundary to [] says the change
936
+ // touches no Figma unit, so nothing counts (as with zero touched units of
937
+ // a DS file). Dev refuses NOT_REQUIRED and NOT_APPLICABLE on a frontend
938
+ // lane's figma check, so this is a CLEAN round over zero frames.
939
+ figma = round("figma", [], { side: lane.side, frames: [], frameComparison: "not_built", boundary: [], notChecked: `${ref}'s Freeze sets its Figma boundary to none (boundaries.figma = []), so the change touches no Figma unit and nothing is counted (hub-364)` });
940
+ } else if (!Array.isArray(freeze?.boundaries?.figma)) {
941
+ // No boundary set at all: nothing to compare, so the leg is skipped, not
942
+ // crashed. Dev requires a frontend lane's figma check to run
943
+ // (NOT_APPLICABLE is refused there), so the skip records as unavailable
944
+ // and the run stays NOT CLEAN until it is set.
911
945
  figma = errorCheck("figma", new ReviewerError(UNAVAILABLE, `skipped: ${ref} is a ${lane.side} lane, but its Freeze names no Figma boundary (boundaries.figma), so there is no frame to check and no design check ran. Dev requires a ${lane.side} lane's figma check to run, so this run is NOT CLEAN until the boundary is set: nodii-dev lane freeze swap ${ref} --section boundaries.`), firstRound("figma"), { side: lane.side, frames: [], frameComparison: "not_built", boundary: null });
912
946
  } else {
913
947
  const boundary = freeze.boundaries.figma;
package/dist/safety.js CHANGED
@@ -6,6 +6,7 @@ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "nod
6
6
  import { promisify } from "node:util";
7
7
  import { CliError, LANE_CAP_RAISE_PROMPT, configPath, devRequest, encode, readConfig } from "./core.js";
8
8
  import { laneCapReminder } from "./watchdog.js";
9
+ import { heavyViolation } from "./heavy.js";
9
10
 
10
11
  const execFileAsync = promisify(execFile);
11
12
  const ACTIVE = new Set(["queued", "building", "built", "review", "on_main"]);
@@ -844,6 +845,10 @@ export async function safetyPreHook(payload, contextOrResolver = safetyContext,
844
845
  context.devBoundaries = provenLane(context) && createsAnyBranch(command) ? await devBoundaries(context.lane?.key, request) : null;
845
846
  const violation = commandViolations(command, context)[0];
846
847
  if (violation && provenLane(context)) blocked(violation);
848
+ // hub-377 (MW2-51, K02-4): a lane's heavy work goes through the machine's slot queue. A heredoc body
849
+ // read as text is not a command, so it is left out before the command is judged.
850
+ const heavy = provenLane(context) ? heavyViolation(withoutHeredocBodies(command), { original: command }) : null;
851
+ if (heavy) blocked(heavy);
847
852
  if (usesNoVerify(command) && context.role === "coordinator" && context.noVerifyReason)
848
853
  await recordNoVerifyReason(cwd, context.noVerifyReason);
849
854
  const reminder = context.role === "coordinator" ? await laneCapReminder() : null;