@nodii/dev 0.6.209 → 0.6.211

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.
@@ -4,13 +4,32 @@ import { homedir } from "node:os";
4
4
  import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  import { configPath } from "./core.js";
7
+ import { stubEnv } from "./drill-stub.js";
7
8
  import { laneConfigName } from "./lane-env.js";
8
9
  import { recordWatchedRun } from "./watchdog.js";
9
10
  import { laneSwitchOn } from "./lane-switches.js";
10
11
  import { laneStepKeys, laneTrim } from "./plugin-trim.js";
11
12
  import { continuationInvocation, continueTaskMessage, sessionIdFromLog, subagentBudgetLine } from "./lane-supervisor.js";
12
13
 
13
- const RUNTIMES = new Set(["codex", "claude"]);
14
+ // DEV-PROCESS-1: "stub" is the drill's stub runtime shipped in this package
15
+ // (drill-stub.js). It runs no model and uses no account, so a drill lane
16
+ // resumed by anyone still starts only the stub.
17
+ const RUNTIMES = new Set(["codex", "claude", "stub"]);
18
+ export const STUB_ENTRY = fileURLToPath(new URL("drill-stub.js", import.meta.url));
19
+
20
+ /**
21
+ * A stub account: a drill folder, under ~/.nodii/drill/, and nothing else. A
22
+ * real profile, or any folder outside the drill's, is refused, so a planted
23
+ * failure can never mark a real account exhausted.
24
+ */
25
+ function stubAccount(profileHome, home) {
26
+ absolutePath(profileHome, "launch.profileHome");
27
+ const drills = join(resolve(home), ".nodii", "drill");
28
+ const inside = relative(drills, resolve(profileHome));
29
+ if (!inside || inside.startsWith("..") || isAbsolute(inside) || /(?:^|\/)\.(?:claude|codex)(?:[-_.]|\/|$)/.test(inside))
30
+ throw new TypeError("the stub runtime takes no real account: launch.profileHome must be a stub account folder under ~/.nodii/drill/");
31
+ return profileHome;
32
+ }
14
33
 
15
34
  const requiredText = (value, name) => {
16
35
  if (typeof value !== "string" || !value.trim())
@@ -53,7 +72,7 @@ function validateData(data) {
53
72
  const laneKey = requiredText(data?.lane?.key, "lane.key");
54
73
  const runtime = requiredText(data?.launch?.runtime, "launch.runtime");
55
74
  if (!RUNTIMES.has(runtime))
56
- throw new TypeError("launch.runtime must be codex or claude");
75
+ throw new TypeError("launch.runtime must be codex, claude or stub");
57
76
  const model = requiredText(data?.launch?.model, "launch.model");
58
77
  const cwd = absolutePath(data?.launch?.cwd, "launch.cwd");
59
78
  const addDirs = data?.launch?.addDirs ?? [];
@@ -69,7 +88,7 @@ function validateLaunch(options) {
69
88
  throw new TypeError("runId is not a safe state-directory name");
70
89
  const laneKey = requiredText(options?.laneKey, "laneKey");
71
90
  const runtime = requiredText(options?.runtime, "runtime");
72
- if (!RUNTIMES.has(runtime)) throw new TypeError("runtime must be codex or claude");
91
+ if (!RUNTIMES.has(runtime)) throw new TypeError("runtime must be codex, claude or stub");
73
92
  const model = requiredText(options?.model, "model");
74
93
  const cwd = absolutePath(options?.cwd, "cwd");
75
94
  const devConfigPath = laneConfig(options?.devConfigPath, laneKey, "devConfigPath");
@@ -77,11 +96,13 @@ function validateLaunch(options) {
77
96
  if (!Array.isArray(addDirs)) throw new TypeError("addDirs must be an array");
78
97
  for (const [index, path] of addDirs.entries()) absolutePath(path, `addDirs[${index}]`);
79
98
  const prompt = requiredText(options?.prompt, "prompt");
80
- return { runId, laneKey, runtime, model, cwd, devConfigPath, addDirs, prompt, profileHome: options.profileHome };
99
+ return { runId, laneKey, runtime, model, cwd, devConfigPath, addDirs, prompt, profileHome: options.profileHome, stubScript: options.stubScript };
81
100
  }
82
101
 
83
102
  function profileVariable(runtime, profileHome, home) {
84
103
  if (profileHome === undefined || profileHome === null) return {};
104
+ // The stub runs on no real account: its profile, if any, is a stub account (a drill folder), passed as an argument, never as a profile variable.
105
+ if (runtime === "stub") throw new TypeError("the stub runtime takes no profile variable");
85
106
  absolutePath(profileHome, "launch.profileHome");
86
107
  absolutePath(home, "home");
87
108
  const child = relative(home, profileHome);
@@ -272,7 +293,7 @@ export function buildRecoveryPrompt(data) {
272
293
  export function buildRecoveryInvocation(data, { env = process.env, home = homedir(), trim = null } = {}) {
273
294
  const { runId, laneKey, runtime, model, cwd, addDirs } = validateData(data);
274
295
  const devConfigPath = laneConfig(data?.launch?.devConfigPath, laneKey, "launch.devConfigPath");
275
- return buildInvocation({ runId, laneKey, runtime, model, cwd, addDirs, profileHome: data.launch.profileHome, devConfigPath, trim }, { env, home });
296
+ return buildInvocation({ runId, laneKey, runtime, model, cwd, addDirs, profileHome: data.launch.profileHome, devConfigPath, trim, stubScript: data.launch.stubScript }, { env, home });
276
297
  }
277
298
 
278
299
  /** NODII-DEV-CLI-191 change (8): a recovered lane's scope, from its Freeze boundaries and its steps. */
@@ -284,7 +305,7 @@ export function recoveryScope(data) {
284
305
  }
285
306
 
286
307
  function buildInvocation(options, { env = process.env, home = homedir() } = {}) {
287
- const { runId, laneKey, runtime, model, cwd, addDirs, profileHome, devConfigPath, trim = null } = options;
308
+ const { runId, laneKey, runtime, model, cwd, addDirs, profileHome, devConfigPath, trim = null, stubScript } = options;
288
309
  // NODII-DEV-CLI-191 change (8): plugins and connectors outside the lane's scope stay off.
289
310
  const trimmed = runtime === "claude" && trim ? trim : null;
290
311
  // A headless lane has nobody to approve a tool call, so it runs in the
@@ -292,6 +313,20 @@ function buildInvocation(options, { env = process.env, home = homedir() } = {})
292
313
  // lane's own profile, with the harness safety hooks as the guard (they
293
314
  // still run in this mode). Without it every Bash call, `nodii-dev lane
294
315
  // gather` included, is refused "requires approval" (AGENT-HARNESS-43).
316
+ if (runtime === "stub") return {
317
+ command: process.execPath,
318
+ args: [STUB_ENTRY, "--script", absolutePath(stubScript, "stubScript"), "--model", model, ...(profileHome ? ["--account", stubAccount(profileHome, home)] : [])],
319
+ ...(profileHome ? { stubAccount: profileHome } : {}),
320
+ runtime,
321
+ cwd,
322
+ env: {
323
+ // No account or credential reaches the stub or its steps: an inherited profile could otherwise be recorded exhausted by a drill's planted limit.
324
+ ...stubEnv(env),
325
+ NODII_DEV_RUN_ID: runId,
326
+ NODII_DEV_LANE_KEY: laneKey,
327
+ NODII_DEV_CONFIG_PATH: devConfigPath,
328
+ },
329
+ };
295
330
  const args = runtime === "codex"
296
331
  ? ["exec", "--json", "--dangerously-bypass-approvals-and-sandbox", "--cd", cwd, "--model", model, ...addDirs.flatMap((path) => ["--add-dir", path]), "-"]
297
332
  // Claude Code refuses --print with stream-json unless --verbose is set.
package/dist/safety.js CHANGED
@@ -6,7 +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, LIVE_LANE_STATUSES, configPath, devRequest, encode, hookLanePath, query, readConfig } from "./core.js";
8
8
  import { laneCapReminder } from "./watchdog.js";
9
- import { heavyViolation } from "./heavy.js";
9
+ import { ciOnlyViolation, heavyViolation } from "./heavy.js";
10
10
  import { compareHandrolled } from "./handrolled.js";
11
11
 
12
12
  const execFileAsync = promisify(execFile);
@@ -1071,7 +1071,11 @@ export async function safetyPreHook(payload, contextOrResolver = safetyContext,
1071
1071
  // hub-377 (MW2-51, K02-4): a lane's heavy work goes through the machine's slot queue. This is host load, not
1072
1072
  // ownership, so it binds every lane session, proven or not: a lane working in a repository with no lane
1073
1073
  // marker still shares the machine. A heredoc body read as text is not a command, so it is left out first.
1074
- const heavy = provenLane(context) || context.role === "lane" ? heavyViolation(withoutHeredocBodies(command), { original: command }) : null;
1074
+ // DEV-PROCESS-2 (hub-650): an every-page check runs only in CI, on the pull request; it is refused before the queue is offered.
1075
+ const inLane = provenLane(context) || context.role === "lane";
1076
+ const ciOnly = inLane ? ciOnlyViolation(withoutHeredocBodies(command)) : null;
1077
+ if (ciOnly) blocked(ciOnly);
1078
+ const heavy = inLane ? heavyViolation(withoutHeredocBodies(command), { original: command }) : null;
1075
1079
  if (heavy) blocked(heavy);
1076
1080
  if (usesNoVerify(command) && context.role === "coordinator" && context.noVerifyReason)
1077
1081
  await recordNoVerifyReason(cwd, context.noVerifyReason);
@@ -239,7 +239,7 @@ const stewardKeyOf = (resolved) => (resolved.kind === "steward" && resolved.stew
239
239
  * only, so `ruling file` can prove its words were typed in it. One file per
240
240
  * session, overwritten each turn; it is never sent.
241
241
  */
242
- export const RULING_LINE = "nodii-dev: if the person's message gives an instruction or rule about how work is done, file it verbatim this turn, their exact words on stdin: `nodii-dev ruling file --text - <<'EOF'`, the words, then `EOF` on its own line; or `--text '<their exact words>'` in single quotes (MW1-115). File nothing else.";
242
+ export const RULING_LINE = "nodii-dev: if the person's message gives an instruction or rule about how work is done, file it verbatim this turn, their exact words on stdin: `nodii-dev ruling file --text - <<'EOF'`, the words, then `EOF` on its own line; or `--text '<their exact words>'` in single quotes (MW1-115). Use your current Codex or Claude session. File nothing else.";
243
243
 
244
244
  /** A lane session (a lane run or a lane config) files no rulings, so its turns are not kept. */
245
245
  const isLaneSession = (env) => Boolean(env.NODII_DEV_RUN_ID) || isLaneConfig(env);
package/dist/starting.js CHANGED
@@ -16,6 +16,7 @@ import { clearCoordinatorMarker, coordinatorMarkerPath } from "./coordinator-ite
16
16
  import { accountFlags, listAccounts, profilePath, registerAccount, reportUsage, usageLine } from "./accounts.js";
17
17
  import { subagentBudgetLine } from "./lane-supervisor.js";
18
18
  import { laneStepKeys } from "./plugin-trim.js";
19
+ import { requireFloor } from "./machine-floor.js";
19
20
 
20
21
  const execFile = promisify(execFileCallback);
21
22
  const via = { via: "nodii-dev" };
@@ -583,8 +584,16 @@ export async function launchLaneCommand(key, flags, {
583
584
  findRun = findCoordinatorRun,
584
585
  save = saveJson,
585
586
  isAlive = async (pid, startedAt) => (await import("./watchdog.js")).isProcessAlive(pid, startedAt),
587
+ floor = requireFloor,
586
588
  } = {}) {
587
589
  if (!key) throw new CliError("USAGE", "lane launch needs <key>.", 2);
590
+ // DEV-PROCESS-2 (must-item 2): every launch reads the machine's floor first, before the coordinator, the governor,
591
+ // the cap or the account. Under it the launch is refused (MACHINE_UNDER_FLOOR, naming the reading, the figure and
592
+ // what holds memory) and nothing is created. --tighten READING=GB makes this one call stricter; --preflight-only
593
+ // stops after Dev's preflight.
594
+ const preflightOnly = Boolean(flags["preflight-only"]);
595
+ if (flags["preflight-only"] !== undefined && flags["preflight-only"] !== true) throw new CliError("USAGE", "--preflight-only takes no value.", 2);
596
+ const floorVerdict = await floor({ kind: "launch", what: key, preflight: preflightOnly, ...(flags.tighten !== undefined ? { tighten: flags.tighten } : {}) });
588
597
  const machine = requireFlag(flags, "machine");
589
598
  let coordinator = flags["coordinator-run"]
590
599
  ? { runId: flags["coordinator-run"], machineId: requireFlag(flags, "machine-id") }
@@ -664,6 +673,9 @@ export async function launchLaneCommand(key, flags, {
664
673
  if (governor) assertGovernorOpen(governor);
665
674
  try { await request("POST", "/api/v1/lanes/launch", { phase: "preflight", ...body }); }
666
675
  catch (error) { throw laneCapRefusal(error); }
676
+ // --preflight-only stops here: no worktree, no lane record, no runtime.
677
+ if (preflightOnly)
678
+ return { payload: { data: { preflight: "passed", launched: false, key, floor: floorVerdict } }, human: `Preflight for ${key} passed; nothing was created. ${floorVerdict.message}` };
667
679
  await worktrees(repositories);
668
680
  const lastPushedCommit = await head(repositories);
669
681
  let payload;
package/dist/watchdog.js CHANGED
@@ -213,20 +213,23 @@ export async function refreshMachineUsage(machineId, {
213
213
  return results;
214
214
  }
215
215
 
216
- const LANE_CAP_REMIND_MS = 10 * 60_000;
217
216
  const laneCapReminderPath = (home = homedir()) => join(watchdogHome(home), "lane-cap-reminder.txt");
218
217
 
219
- /** MW1-38.10: what the coordinator must hear, or null while the cap has time left. */
220
- export function laneCapReminderText(state, now = new Date()) {
218
+ /**
219
+ * MW1-38.10 (hub-414): what the coordinator must hear, or null while the cap
220
+ * holds. The cap holds while this machine's watchdog reports in, so there is
221
+ * nothing to re-declare: it speaks only when no cap is declared, or Dev's last
222
+ * watchdog report from this machine is 10 minutes old (or there is none).
223
+ */
224
+ export function laneCapReminderText(state) {
221
225
  if (!state) return null;
222
- if (state.cap === null || !state.lapsesAt)
226
+ if (state.cap === null || state.cap === undefined)
223
227
  return "nodii-dev watchdog: this machine has no declared lane cap, so Dev refuses new launches. Declare it with nodii-dev lane cap (MW1-38.10).";
224
- const left = new Date(state.lapsesAt).getTime() - now.getTime();
225
- if (left <= 0)
226
- return `nodii-dev watchdog: this machine's lane cap lapsed at ${state.lapsesAt}, so Dev refuses new launches. Re-declare it with nodii-dev lane cap (MW1-38.10).`;
227
- if (left <= LANE_CAP_REMIND_MS)
228
- return `nodii-dev watchdog: this machine's lane cap lapses at ${state.lapsesAt}. Re-declare it with nodii-dev lane cap (MW1-38.10).`;
229
- return null;
228
+ if (state.holds ?? !state.lapsed) return null;
229
+ const report = state.lastWatchdogReportAt;
230
+ return report
231
+ ? `nodii-dev watchdog: this machine's lane cap of ${state.cap} is lapsed: Dev's last watchdog report from it is at ${report}, 10 minutes or more ago, so Dev refuses new launches. It holds again once the watchdog reports in; check it with nodii-dev watchdog install (MW1-38.10).`
232
+ : `nodii-dev watchdog: this machine's lane cap of ${state.cap} is not in force: Dev has no watchdog report from this machine, so Dev refuses new launches. It holds once the watchdog reports in; check it with nodii-dev watchdog install (MW1-38.10).`;
230
233
  }
231
234
 
232
235
  /** Held in a file because the sweep runs under launchd or systemd, outside the coordinator's session. */
@@ -425,7 +428,7 @@ export async function sweepWatchdog({
425
428
  try {
426
429
  machine = (await request("GET", `/api/v1/machines/${encode(effectiveMachineId)}`)).data ?? null;
427
430
  laneCap = machine?.laneCapState ?? null;
428
- await saveReminder(laneCapReminderText(laneCap, now()));
431
+ await saveReminder(laneCapReminderText(laneCap));
429
432
  } catch (error) {
430
433
  facts.errors.push({ kind: "lane_cap", code: error?.code ?? "LANE_CAP_READ_FAILED" });
431
434
  }
@@ -500,10 +503,12 @@ const xml = (value) => String(value).replaceAll("&", "&amp;").replaceAll("<", "&
500
503
  * plist carries the installing shell's PATH, plus the directory of the runtime
501
504
  * that runs the CLI.
502
505
  */
503
- export function watchdogPath(envPath = process.env.PATH, runtime = process.execPath) {
504
- const dirs = [dirname(runtime), ...String(envPath ?? "").split(":"), "/usr/bin", "/bin", "/usr/sbin", "/sbin"];
506
+ export function watchdogPath(envPath = process.env.PATH, runtime = process.execPath, home = homedir()) {
507
+ const dirs = [join(home, ".bun", "bin"), dirname(runtime), ...String(envPath ?? "").split(":"), "/usr/bin", "/bin", "/usr/sbin", "/sbin"];
505
508
  // A package runner's own bins (npx's _npx cache, node_modules/.bin) are left out: they are temporary.
506
- const kept = dirs.filter((dir) => dir && dir.startsWith("/") && !dir.includes("/node_modules/") && !dir.includes("/_npx/"));
509
+ // A config path is not a directory, but older launch environments could
510
+ // accidentally append NODII_DEV_CONFIG_PATH to PATH. Never preserve it.
511
+ const kept = dirs.filter((dir) => dir && dir.startsWith("/") && !dir.endsWith("config.json") && !dir.includes("/node_modules/") && !dir.includes("/_npx/"));
507
512
  return [...new Set(kept)].join(":");
508
513
  }
509
514
 
@@ -557,7 +562,7 @@ function installSystemdWatchdog({ home, env, interval, runtime, entry, configFil
557
562
  return installSupervised({
558
563
  home, execute, activate: WATCHDOG_TIMER, errorCode: "WATCHDOG_INSTALL_FAILED",
559
564
  // PATH is the installing shell's: the sweep resumes lanes and must find their runtime (hub-251).
560
- build: ({ logs }) => watchdogUnits({ runtime, entry, config: resolve(configFile), interval, stdoutPath: join(logs, "watchdog.log"), stderrPath: join(logs, "watchdog.error.log"), path: watchdogPath(env.PATH, runtime) }),
565
+ build: ({ logs }) => watchdogUnits({ runtime, entry, config: resolve(configFile), interval, stdoutPath: join(logs, "watchdog.log"), stderrPath: join(logs, "watchdog.error.log"), path: watchdogPath(env.PATH, runtime, home) }),
561
566
  }).then((installed) => ({ ...installed, interval }));
562
567
  }
563
568
 
@@ -587,7 +592,7 @@ export async function installWatchdog({
587
592
  if (os === "linux") return installSystemdWatchdog({ home, env, interval, runtime, entry, configFile, execute });
588
593
  const logs = logsDir({ home, os });
589
594
  const plistPath = join(home, "Library", "LaunchAgents", `${WATCHDOG_LABEL}.plist`);
590
- const contents = launchdPlist({ runtime, entry, config: resolve(configFile), interval, stdoutPath: join(logs, "watchdog.log"), stderrPath: join(logs, "watchdog.error.log") });
595
+ const contents = launchdPlist({ runtime, entry, config: resolve(configFile), interval, stdoutPath: join(logs, "watchdog.log"), stderrPath: join(logs, "watchdog.error.log"), path: watchdogPath(env.PATH, runtime, home) });
591
596
  await mkdir(logs, { recursive: true, mode: 0o700 });
592
597
  const previous = await readFile(plistPath, "utf8").catch((error) => error?.code === "ENOENT" ? null : Promise.reject(error));
593
598
  const service = `gui/${uid}/${WATCHDOG_LABEL}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.209",
3
+ "version": "0.6.211",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {