@nodii/dev 0.6.178 → 0.6.180

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 CHANGED
@@ -197,7 +197,7 @@ nodii-dev figma publish FILE --sets CS-1,CS-2 [--dry-run]
197
197
  ```
198
198
 
199
199
  - **Board.** "Waiting on" comes from Dev's real state: the lane's status, the change sets it holds (state, pending items, file order), Dev's wait records, the heavy-slot queue and `answered.md`. It never comes from the lane's note, which is shown as written in its own column. A question counts as the operator's only when it is an open item on the sheet. `--write` puts "What's running" on the status page `docs/open/<sheet>-status.md` and only the lanes that wait on the operator on the sheet, because MW4-31 keeps status off the sheet. It works in the worktree `nodii-infra/.claude/worktrees/<sheet>-board` and merges through a PR. First it copies every answer the operator typed in their checkout, verbatim, into `answered.md` and into the sheet. Then it fast-forwards the operator's checkout, and only when nothing else there differs from main. An empty board, or one that drops by more than half, is refused (`--force` once you have checked Dev). Priority domains are coordinator configuration in `~/.config/nodii-dev/coordinator/settings.json` (`domains`); a lane outside them is listed under "Other lanes".
200
- - **Watch.** Jobs and intervals: board 15 min, apply-watch 3, publish-watch 10, real-stuck 30, complexity 30, orphan-slots 10, keepalive 10. Everything goes to one log, `coordinator-watch.log`, under `~/Library/Logs/nodii-dev/` on macOS and `~/.local/state/nodii-dev/logs/` on Linux. On Linux the memory guard on a resume reads `MemAvailable` from `/proc/meminfo`. Alerts go to `~/.config/nodii-dev/coordinator/alerts.log` and open the coordinator's next session. A job is paused by `~/.config/nodii-dev/coordinator/hold-<job>`. A resume tries the lane's own account first. On an account refusal it tries the accounts listed in `settings.json` `keepaliveProfiles` (`[{ "profile": "/abs/path", "class": "short" }]`), because the account roster is the operator's call (MW1-38.3). The watch never stops a process it did not start (K02-15). It reports an orphaned slot instead.
200
+ - **Watch.** Jobs and intervals: board 15 min, apply-watch 3, publish-watch 10, real-stuck 30, complexity 30, orphan-slots 10, keepalive 10. Everything goes to one log, `coordinator-watch.log`, under `~/Library/Logs/nodii-dev/` on macOS and `~/.local/state/nodii-dev/logs/` on Linux. On Linux the memory guard on a resume reads `MemAvailable` from `/proc/meminfo`. Alerts go to `~/.config/nodii-dev/coordinator/alerts.log` and open the coordinator's next session. A job is paused by `~/.config/nodii-dev/coordinator/hold-<job>`. A resume tries the lane's own account first. On an account refusal it tries the accounts listed in `settings.json` `keepaliveProfiles` (`[{ "profile": "/abs/path", "class": "short" }]`), because the account roster is the operator's call (MW1-38.3). The watch never stops a process it did not start (K02-15). It reports an orphaned slot instead. Keepalive resumes a blocked lane only through `lane resume --if-changed` (MW1-102): a lane whose blockers have not changed stays down, and does not use up the run's resumes. A down lane that is not blocked (an orphan) resumes as before. At `NODII_DEV_RESUME_IF_CHANGED=0`, keepalive resumes a blocked lane at most once an hour. When the installed `@nodii/dev` is not the version the daemon started with, the daemon logs it and exits, and launchd (`KeepAlive`) or systemd (`Restart=always`) starts it again on the new code.
201
201
  - **publish-watch** stays off until the coordinator sets `"publishWatch": true` in `settings.json`. MW8-7 still names the operator as publisher until hub-429 lands. It needs a Figma token to read the new version. It reads the token from `FIGMA_PAT` (or `FIGMA_TOKEN`) in the daemon's own environment first, then from the macOS keychain (`security add-generic-password -s nodii-dev-figma-pat -a "$USER" -w`). The plist that `coordinator watch install` writes carries no token, so the keychain is the usual source; a token someone adds to the plist's environment would be used before it. It never reads a file. On Linux the job answers "macOS only", so nothing there reads a Secret Service for the token.
202
202
  - **Chrome.** `chrome start` adopts the Chrome already serving the port, or starts one on the profile, and records the endpoint on Dev's machine record (`hostFacts.sharedChrome`; coordinator or staff only). Every command opens its own background tab and closes only that tab (K02-16, K02-17). `chrome signin` refuses anything but a `tech-*` tenant and a yopmail test identity. It signs in within its own tab and opens `--open PATH` if given. Then it signs out (the app's logout, then that origin's storage and cookies cleared), so no session or token outlives it (MW3-40.2). It never prints or stores a credential, tries each tenant at most once an hour, skips a tenant another tab has open, and rests a tenant after a failed sign-in until `--clear-rest`.
203
203
  - **figma publish** refuses a set that is not `awaiting_publish`. It ticks exactly the approved components of the named sets in Figma's Publish library dialog and unticks every other row. It stops if a row won't settle or if it saw fewer rows than the dialog counts. It records a set in Dev only when all of the set's components were published.
@@ -987,7 +987,11 @@ check not recorded. Continue the Task: STEP.` BLOCKED is not an exit
987
987
  only a typed human gate lets the stop through. The gates
988
988
  are a wait on an operator question (`Q-n`), a decision (`DEC-n`), a release or
989
989
  launch day; a wait on a `steward-*` lane; or a latest heartbeat typed
990
- `WAITING: human-gate totp|steward|spend: WHAT THE PERSON MUST DO`. Any other
990
+ `WAITING: human-gate totp|steward|coordinator|spend: WHAT THE PERSON MUST DO`.
991
+ `coordinator` is for a coordinator-only step that leeway may not reach, such
992
+ as uploading an operator-approved lock-change decision (MW1 1.33, DEC-0508).
993
+ When a launched run ends on it, the supervisor reports the end to the machine's
994
+ coordinator as a lane message (MW1-12.11). Any other
991
995
  blocker, such as a blocked step, a PR, an issue, another lane, or an untyped
992
996
  BLOCKED or WAITING note, holds the stop. The answer then names the blocker and
993
997
  says to claim it with `lane leeway` (MW1-12.6), fix it with the lane's
@@ -1,5 +1,5 @@
1
1
  import { CliError, devRequest, encode, readConfig } from "./core.js";
2
- import { agentFallbackReason, coordinatorGatherPayload, gatherDeadline, gatherText, pickDocuments, pickerModelName, warmPicker, withPickLock } from "./gather.js";
2
+ import { GATHER_TIMEOUT_MS, agentFallbackReason, coordinatorGatherPayload, gatherDeadline, gatherText, pickDocuments, pickerModelName, warmPicker, withPickLock } from "./gather.js";
3
3
  import { findCoordinatorRun } from "./starting.js";
4
4
 
5
5
  const list = (value) => String(value ?? "").split(",").map((item) => item.trim()).filter(Boolean);
@@ -14,7 +14,7 @@ export async function coordinatorGather(flags, {
14
14
  const documents = list(flags.documents);
15
15
  if (Boolean(flags.shortlist) !== Boolean(documents.length) || (flags.shortlist && flags.picker !== "agent"))
16
16
  throw new CliError("USAGE", "Record an agent pick with --picker agent --shortlist ID --documents CODE[,CODE].", 2);
17
- const deadline = gatherDeadline();
17
+ const deadline = gatherDeadline(GATHER_TIMEOUT_MS);
18
18
  const timed = (method, path, body) => request(method, path, body, { signal: deadline.signal });
19
19
  try {
20
20
  const current = await config();
@@ -22,7 +22,8 @@ import { appendFile, mkdir, readFile, rename, rm, writeFile } from "node:fs/prom
22
22
  import { homedir, loadavg, platform } from "node:os";
23
23
  import { dirname, join, resolve } from "node:path";
24
24
  import { promisify } from "node:util";
25
- import { CliError, configPath, devRequest, encode, readConfig } from "./core.js";
25
+ import { CliError, VERSION, configPath, devRequest, encode, readConfig } from "./core.js";
26
+ import { laneSwitchOn } from "./lane-switches.js";
26
27
  import {
27
28
  DEFAULT_DOMAINS, boardCommand, coordinatorHome, heavyQueue, laneDomain, laneProcesses, liveChangeSets, machineLanes, readCoordinatorSettings,
28
29
  } from "./coordinator-board.js";
@@ -274,18 +275,22 @@ async function keepaliveJob(ctx) {
274
275
  const alive = await ctx.processes();
275
276
  const state = ctx.jobState;
276
277
  state.blockedResumedAt ??= {};
278
+ const gated = laneSwitchOn("resumeIfChanged", ctx.env ?? process.env);
277
279
  const down = lanes.filter((lane) => alive.get(lane.key) === false || (!alive.has(lane.key) && ["orphan", "dead"].includes(lane.liveness)))
278
280
  .sort((a, b) => Number(!laneDomain(a.key, domains)) - Number(!laneDomain(b.key, domains)) || a.key.localeCompare(b.key));
279
281
  const resumed = [];
280
282
  const skipped = [];
281
283
  for (const lane of down) {
282
284
  if (resumed.length >= (settings.keepaliveMaxPerRun ?? 3)) { skipped.push(`${lane.key} (next run)`); continue; }
283
- // A blocked lane is resumed at most once an hour, so it rechecks its blocker.
284
- if (lane.liveness === "blocked") {
285
+ // MW1-102 (NODII-DEV-CLI-191): a blocked lane resumes only when what
286
+ // blocks it changed (`lane resume --if-changed`), never on a timer. At
287
+ // NODII_DEV_RESUME_IF_CHANGED=0 it is resumed at most once an hour, as before.
288
+ const ifChanged = lane.liveness === "blocked" && gated;
289
+ if (lane.liveness === "blocked" && !gated) {
285
290
  const last = state.blockedResumedAt[lane.key] ?? 0;
286
291
  if (ctx.now() - last < 60 * MIN) { skipped.push(`${lane.key} (blocked, resumed within the hour)`); continue; }
287
292
  }
288
- const why = await ctx.tryResume(lane.key, { priority: Boolean(laneDomain(lane.key, domains)) });
293
+ const why = await ctx.tryResume(lane.key, { priority: Boolean(laneDomain(lane.key, domains)), ifChanged });
289
294
  if (why === "resumed") {
290
295
  resumed.push(lane.key);
291
296
  if (lane.liveness === "blocked") state.blockedResumedAt[lane.key] = ctx.now();
@@ -320,7 +325,7 @@ export async function figmaPatFromKeychain(execute) {
320
325
  catch { return null; }
321
326
  }
322
327
 
323
- export function watchContext({ home = homedir(), request = devRequest, config = readConfig, execute = execFile, now = Date.now, sleep = delay, log, jobState = {}, os = platform() } = {}) {
328
+ export function watchContext({ home = homedir(), request = devRequest, config = readConfig, execute = execFile, now = Date.now, sleep = delay, log, jobState = {}, os = platform(), resume = async (key, flags) => (await import("./lanes.js")).laneCommand("resume", [key], flags), guardsFor = () => machineGuards({ execute, os }) } = {}) {
324
329
  let machine = null;
325
330
  let processesCache = null;
326
331
  let guardsCache = null;
@@ -330,26 +335,32 @@ export function watchContext({ home = homedir(), request = devRequest, config =
330
335
  machineId: async () => (machine ??= await governorMachineId({}, { request, config })),
331
336
  processes: async () => (processesCache ??= await laneProcesses()),
332
337
  heavy: () => heavyQueue({ execute, os }),
333
- guards: async () => (guardsCache ??= await machineGuards({ execute, os })),
338
+ guards: async () => (guardsCache ??= await guardsFor()),
334
339
  amend: async (key, rules, reason) => {
335
340
  const { amendLaneCommand } = await import("./starting.js");
336
341
  await amendLaneCommand(key, { rules, reason });
337
342
  await log?.(`amend ${key}: ${reason}`);
338
343
  },
339
- tryResume: async (key, { priority }) => {
344
+ tryResume: async (key, { priority, ifChanged = false }) => {
340
345
  const hold = await exists(holdPath(home, "keepalive"));
341
346
  const verdict = resumeAllowed(await ctx.guards(), { priority, hold });
342
347
  if (!verdict.ok) return `not resumed: ${verdict.reason}`;
343
- const { laneCommand } = await import("./lanes.js");
344
348
  // The lane's own account first; on an account refusal, the coordinator's
345
349
  // allowed lane accounts in order (settings.keepaliveProfiles: the account
346
350
  // roster is the operator's call, MW1-38.3, so it is configuration).
347
351
  const settings = await readCoordinatorSettings(home);
348
- const attempts = [{}, ...(settings.keepaliveProfiles ?? []).map((p) => ({ profile: p.profile, class: p.class ?? "short" }))];
352
+ const gate = ifChanged ? { "if-changed": true } : {};
353
+ const attempts = [{ ...gate }, ...(settings.keepaliveProfiles ?? []).map((p) => ({ ...gate, profile: p.profile, class: p.class ?? "short" }))];
349
354
  let last = "LANE_RESUME_FAILED";
350
355
  for (const flags of attempts) {
351
356
  try {
352
- await laneCommand("resume", [key], flags);
357
+ const out = await resume(key, flags);
358
+ // MW1-102: the gate left the lane down (BLOCKERS_UNCHANGED, LANE_DEAD,
359
+ // LANDED_NOT_DONE). That is an answer, not an account refusal.
360
+ if (out?.payload?.data?.resumed === false) {
361
+ await log?.(`not resumed ${key}: ${out.payload.data.code}`);
362
+ return `not resumed (${out.payload.data.code})`;
363
+ }
353
364
  guardsCache = null;
354
365
  await log?.(`resumed ${key}${flags.profile ? ` on ${flags.profile}` : ""}`);
355
366
  return "resumed";
@@ -437,7 +448,12 @@ async function pidAlive(pid) {
437
448
  }
438
449
 
439
450
  /** The daemon loop. One instance per machine; jobs run one at a time, each on its interval. */
440
- export async function watchRun({ home = homedir(), tickMs = 30_000, sleep = delay, now = Date.now, run = runJob, forever = true } = {}) {
451
+ /** The @nodii/dev version installed on disk now, which a long-running daemon may not be running. */
452
+ export async function installedPackageVersion(read = readFile) {
453
+ try { return JSON.parse(await read(new URL("../package.json", import.meta.url), "utf8")).version ?? null; } catch { return null; }
454
+ }
455
+
456
+ export async function watchRun({ home = homedir(), tickMs = 30_000, sleep = delay, now = Date.now, run = runJob, forever = true, installed = installedPackageVersion } = {}) {
441
457
  const prior = Number((await readFile(pidPath(home), "utf8").catch(() => "")).trim());
442
458
  if (prior && prior !== process.pid && (await pidAlive(prior)))
443
459
  throw new CliError("WATCH_ALREADY_RUNNING", `coordinator watch is already running (pid ${prior}).`, 1);
@@ -448,6 +464,14 @@ export async function watchRun({ home = homedir(), tickMs = 30_000, sleep = dela
448
464
  process.once("SIGTERM", stop);
449
465
  try {
450
466
  do {
467
+ // NODII-DEV-CLI-191: a daemon keeps the code it started with. When a new
468
+ // @nodii/dev is installed it exits, and its supervisor (launchd KeepAlive,
469
+ // systemd Restart) starts it again on the new code.
470
+ const onDisk = await installed().catch(() => null);
471
+ if (onDisk && onDisk !== VERSION) {
472
+ await watchLog(`watch: @nodii/dev ${onDisk} is installed and this daemon runs ${VERSION}; exiting so it restarts on the new code`, { home });
473
+ break;
474
+ }
451
475
  const state = await readJson(statePath(home), { jobs: {} });
452
476
  for (const job of Object.keys(JOBS)) {
453
477
  const next = Date.parse(state.jobs?.[job]?.nextAt ?? 0);
package/dist/core.js CHANGED
@@ -4,7 +4,7 @@ import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
4
4
  import { homedir, platform } from "node:os";
5
5
  import { dirname, join } from "node:path";
6
6
 
7
- export const VERSION = "0.6.178";
7
+ export const VERSION = "0.6.180";
8
8
  export const configPath = () =>
9
9
  process.env.NODII_DEV_CONFIG_PATH ??
10
10
  join(homedir(), ".config/nodii-dev/config.json");
package/dist/gather.js CHANGED
@@ -210,7 +210,8 @@ export async function warmPicker(options = {}) {
210
210
  * pick, which has its own budgets (warm-up, then the first pick), so a cold
211
211
  * model never spends the requests' time.
212
212
  */
213
- export function gatherDeadline(ms) {
213
+ // NODII-DEV-CLI-159: a deadline built with no length fired at once; the default is the Gather timeout.
214
+ export function gatherDeadline(ms = GATHER_TIMEOUT_MS) {
214
215
  const controller = new AbortController();
215
216
  let remaining = ms;
216
217
  let since = Date.now();
@@ -6,7 +6,7 @@ import { dirname, join } from "node:path";
6
6
  import { promisify } from "node:util";
7
7
  import { profilePath, recordExhaustedAccount } from "./accounts.js";
8
8
  import { CliError, devRequest, encode } from "./core.js";
9
- import { inboxForContinuation } from "./lane-messages.js";
9
+ import { inboxForContinuation, laneMessageCommand } from "./lane-messages.js";
10
10
  import { laneSwitchOn } from "./lane-switches.js";
11
11
  import { redactRunText } from "./runs.js";
12
12
  import { processStartedAt, saveWatchedRun, watchdogRunDir } from "./watchdog.js";
@@ -277,12 +277,13 @@ export function laneBlockedReason(lane) {
277
277
  // NODII-DEV-CLI-191: only a typed human gate ends a lane's run. A wait on
278
278
  // an operator question, a decision, a release (the steward judges it) or launch
279
279
  // day, a wait on a steward lane, or a latest heartbeat typed
280
- // `WAITING: human-gate totp|steward|spend: ...`. Every other blocker (a blocked
280
+ // `WAITING: human-gate totp|steward|coordinator|spend: ...` (coordinator:
281
+ // MW1 1.33, DEC-0508, a coordinator-only step leeway may not reach). Every other blocker (a blocked
281
282
  // step, a PR, an issue, another lane, an untyped BLOCKED or WAITING note) is
282
283
  // the lane's to claim and fix.
283
284
  const HUMAN_GATE_WAITS = new Set(["question", "decision", "release", "launch_day"]);
284
- const HUMAN_GATE_NOTE = /^\s*(?:BLOCKED|WAITING)\s*:?\s*human[- ]gate\s*\(?\s*(totp|steward|spend)\b/i;
285
- export const HUMAN_GATE_COMMAND = (laneKey) => `nodii-dev lane heartbeat ${laneKey} --note "WAITING: human-gate totp|steward|spend: <what the person must do>"`;
285
+ const HUMAN_GATE_NOTE = /^\s*(?:BLOCKED|WAITING)\s*:?\s*human[- ]gate\s*\(?\s*(totp|steward|coordinator|spend)\b/i;
286
+ export const HUMAN_GATE_COMMAND = (laneKey) => `nodii-dev lane heartbeat ${laneKey} --note "WAITING: human-gate totp|steward|coordinator|spend: <what the person must do>"`;
286
287
 
287
288
  const latestNote = (lane) => String((lane?.events ?? [])
288
289
  .filter((event) => event.type === "heartbeat" && event.metadata?.source !== "hook" && String(event.metadata?.note ?? "").trim())
@@ -303,6 +304,12 @@ export function subagentBudgetLine(quota, env = process.env) {
303
304
  return `You have ${n} subagent slot${n === 1 ? "" : "s"} (the Agent tool; MW1-38.15). Fan independent work out to them as MW1-11 says.`;
304
305
  }
305
306
 
307
+ /** The latest heartbeat note when it types the coordinator gate (MW1-12.10, DEC-0508), or null. */
308
+ export function coordinatorGateNote(lane) {
309
+ const note = latestNote(lane);
310
+ return HUMAN_GATE_NOTE.exec(note)?.[1]?.toLowerCase() === "coordinator" ? note.slice(0, 500) : null;
311
+ }
312
+
306
313
  /** The typed human gate that ends a lane's run, or null (NODII-DEV-CLI-191). */
307
314
  export function laneHumanGate(lane) {
308
315
  for (const wait of lane?.waits ?? []) {
@@ -343,6 +350,10 @@ export function continueTaskMessage(laneKey, lane, env = process.env) {
343
350
  return `Lane ${laneKey}: done check not recorded. Continue the Task: ${step}.`;
344
351
  }
345
352
 
353
+ /** A lane message to this machine's coordinator, recorded on the ended run's own lane issue (MW1-12.11). */
354
+ const messageCoordinator = (laneKey, body, { env = process.env } = {}) =>
355
+ laneMessageCommand(["coordinator"], { body }, { env: { ...env, NODII_DEV_LANE_KEY: laneKey } });
356
+
346
357
  /**
347
358
  * The lane's Dev status and whether its done check is recorded. Unreadable
348
359
  * reads as unfinished.
@@ -350,9 +361,9 @@ export function continueTaskMessage(laneKey, lane, env = process.env) {
350
361
  async function laneProgress(request, laneKey) {
351
362
  try {
352
363
  const lane = (await request("GET", `/api/v1/lanes/${encode(laneKey)}`)).data;
353
- return { status: lane?.status ?? null, finished: doneCheckRecorded(lane), blocked: laneBlockedReason(lane), finishEvidence: laneFinishEvidence(lane) };
364
+ return { status: lane?.status ?? null, finished: doneCheckRecorded(lane), blocked: laneBlockedReason(lane), finishEvidence: laneFinishEvidence(lane), coordinatorGate: coordinatorGateNote(lane) };
354
365
  } catch {
355
- return { status: null, finished: false, blocked: null, finishEvidence: null };
366
+ return { status: null, finished: false, blocked: null, finishEvidence: null, coordinatorGate: null };
356
367
  }
357
368
  }
358
369
 
@@ -396,9 +407,10 @@ export async function reportLaneExit({ runId, laneKey, exitCode, signal, worktre
396
407
  markTerminal = markWatchedTerminal,
397
408
  now = () => new Date(),
398
409
  markExhausted = recordExhaustedAccount,
410
+ tellCoordinator = messageCoordinator,
399
411
  } = {}) {
400
412
  const worktree = await inspect(worktrees);
401
- const { status, finished, blocked, finishEvidence } = await laneProgress(request, laneKey);
413
+ const { status, finished, blocked, finishEvidence, coordinatorGate } = await laneProgress(request, laneKey);
402
414
  const clean = exitCode === 0 && !signal;
403
415
  const exitRef = signal ? `signal ${signal}` : String(exitCode ?? -1);
404
416
  const exited = signal ? `was ended by ${signal}` : `exited with code ${exitCode ?? -1}`;
@@ -469,6 +481,10 @@ export async function reportLaneExit({ runId, laneKey, exitCode, signal, worktre
469
481
  const laneFinish = finished && clean && !blocked && worktree.state === "clean" && finishEvidence
470
482
  ? await finishLane(request, laneKey, `The lane's done check was recorded and its process exited 0 with its worktree ${worktree.state}; recorded by the lane supervisor on exit.`, finishEvidence)
471
483
  : null;
484
+ // MW1-12.10 (DEC-0508): a run that ends on a coordinator-only step is
485
+ // reported to the coordinator. A report that fails changes nothing else.
486
+ if (outcome === "blocked" && coordinatorGate)
487
+ await tellCoordinator(laneKey, `Lane ${laneKey}'s run ended on a coordinator-only step (MW1-12.10, DEC-0508): ${coordinatorGate}. The lane resumes when that step is done.`).catch(() => {});
472
488
  await markTerminal(runId).catch(() => {});
473
489
  return { outcome, exitCode: exitCode ?? null, signal: signal ?? null, worktree: worktree.state, laneStatus: status, ...(laneFinish ? { laneFinish } : {}), ...(accountFailure ? { accountFailure } : {}) };
474
490
  }
package/dist/nudges.js CHANGED
@@ -684,8 +684,8 @@ export async function transcriptToolUses(path) {
684
684
  * NODII-DEV-CLI-8 (hub-58, gate for AGENT-HARNESS-13): a lane session may not
685
685
  * stop before its done check is recorded. NODII-DEV-CLI-191: BLOCKED is not an
686
686
  * exit. A blocker the lane can claim and fix holds the stop; only a typed
687
- * human gate (`laneHumanGate`: operator TOTP, a steward-only step, spend, an
688
- * operator question or decision) lets it through. The lane is read fresh: the
687
+ * human gate (`laneHumanGate`: operator TOTP, a steward-only step, a
688
+ * coordinator-only step, spend, an operator question or decision) lets it through. The lane is read fresh: the
689
689
  * lane this hook call just read from Dev by key (`context.laneDetail`), else
690
690
  * one slim read here (hub-528). An unreadable lane lets the stop through.
691
691
  * The no-progress guard: a stop held NODII_DEV_STOP_STALL_LIMIT (2) times in a
package/dist/receipt.js CHANGED
@@ -146,12 +146,18 @@ const SECRET_FLAG = new RegExp(String.raw`(^|\s)(--?[\w-]*(?:token|secret|pass|p
146
146
  const URL_USER_INFO = /(\b[a-z][a-z0-9+.-]*:\/\/)[^/\s:@]*(?::[^/\s@]*)?@/gi;
147
147
  const AUTH_SCHEME = /\b(bearer|basic|token)\s+[A-Za-z0-9._~+/=-]{8,}/gi;
148
148
  const TOKEN_SHAPED = /\b(?:gh[pousr]_[A-Za-z0-9]{10,}|github_pat_\w{10,}|sk-[\w-]{10,}|xox[abprs]-[\w-]{10,}|AKIA[0-9A-Z]{12,}|eyJ[\w-]{8,}\.[\w-]{8,}\.[\w-]*|[A-Fa-f0-9]{32,}|[A-Za-z0-9+/_-]{40,}={0,2})\b/g;
149
+ // NODII-DEV-CLI-213: a long repository path (`packages/dev/test/some-long-name`)
150
+ // fills the 40-character class too. A match is a path, not a token, when it has
151
+ // a slash and every segment between slashes is a lowercase word (letters, digits,
152
+ // `.`, `_` or `-`, with a letter). Random base64 is mixed case, so it still redacts.
153
+ const PATH_SEGMENT = /^[a-z0-9._-]*[a-z][a-z0-9._-]*$/;
154
+ const pathShaped = (match) => match.includes("/") && match.split("/").every((segment) => PATH_SEGMENT.test(segment));
149
155
  export const redactCommand = (command) => String(command)
150
156
  .replace(URL_USER_INFO, "$1<redacted>@")
151
157
  .replace(SECRET_FLAG, "$1$2 <redacted>")
152
158
  .replace(ANY_ASSIGNMENT, "$1$2=<redacted>")
153
159
  .replace(AUTH_SCHEME, "$1 <redacted>")
154
- .replace(TOKEN_SHAPED, "<redacted>");
160
+ .replace(TOKEN_SHAPED, (match) => (pathShaped(match) ? match : "<redacted>"));
155
161
 
156
162
  const many = (value) => (value === undefined ? [] : [value].flat().map(String));
157
163
  const ranAt = () => new Date().toISOString();
package/dist/surface.js CHANGED
@@ -34,7 +34,7 @@ import { MIN_FIGMA_INTERVAL_MS, figmaRest } from "./figma-rest.js";
34
34
  import { createRenderer } from "./vendor/render-templates.mjs";
35
35
 
36
36
  /** Bumped whenever the emitted code changes shape for the same inputs. */
37
- export const GENERATOR_FORMAT = 39;
37
+ export const GENERATOR_FORMAT = 40;
38
38
  export const TREE_DIR = "docs/figma-ux-ds/figma/surface-trees";
39
39
  export const GENERATED_SUFFIX = ".surface.generated.tsx";
40
40
  /** Where every generated product page lives, as a git glob (NODII-DEV-CLI-77). */
@@ -616,7 +616,7 @@ export function emitSurface(tree, row, ds) {
616
616
  const shapes = new Map();
617
617
  // The marked identifiers a template lists as optional, and the ones it doesn't (DESIGN-SYSTEM-507).
618
618
  const optionals = { optional: new Set(), required: new Set() };
619
- const views = tree.variants.map((variant) => {
619
+ const views = graftAbsentSlots(tree.variants).map((variant) => {
620
620
  let state = variant.state;
621
621
  while (used.has(state)) state += "-x";
622
622
  used.add(state);
@@ -779,9 +779,23 @@ function scopeName(node, code = "", ctx = null) {
779
779
  const own = [props.label, props.title].find(named);
780
780
  const at = own ? placeInView(node, ctx) : null;
781
781
  if (at) return camelName(`${node.instance.set} ${at}`);
782
+ // A layer named after its own sample (`PiiText · Asha Rao`) names the record, not the part:
783
+ // in a slot it takes its owner's label (`Created by`), else its set's name.
784
+ if (!own && sampleNamed(node)) {
785
+ const ownerProps = ctx?.slotOwner?.instance?.props ?? ctx?.slotOwner?.props ?? {};
786
+ const label = [ownerProps.label, ownerProps.title].find(named);
787
+ return nameOf(label ?? node.instance?.set ?? "", node.instance?.set ?? "");
788
+ }
782
789
  return nameOf(own ?? node.name ?? "", node.instance?.set ?? node.name ?? "");
783
790
  }
784
791
 
792
+ /** A layer whose name after `·` repeats one of its own text values: the designer's sample, not a name. */
793
+ function sampleNamed(node) {
794
+ const suffix = /·\s*(.+)$/.exec(node.name ?? "")?.[1]?.trim();
795
+ if (!suffix) return false;
796
+ return Object.values(node.instance?.props ?? {}).some((v) => typeof v === "string" && v.trim() === suffix);
797
+ }
798
+
785
799
  /** Where an instance stands among the instances of its set in its view (1, 2, …), when the view holds two or more; else null. */
786
800
  function placeInView(node, ctx) {
787
801
  const root = ctx?.chain?.[0];
@@ -923,6 +937,53 @@ function optionalMark(ctx, scope, name, layer = ctx.layer) {
923
937
  * numbered (`Frame`, `Frame#1`). The view's own name is left out, so the same
924
938
  * layer in another state view is the same layer, one prop (hub-468).
925
939
  */
940
+ /**
941
+ * Figma leaves a slot out of an instance whose variant does not show it (a
942
+ * `pane=hidden` Detail Page has no `right pane` SLOT), but the template still
943
+ * reads it, so that view drew the slot empty and named its controls apart from
944
+ * the open view's (NODII-DEV-CLI-188). Fill such a slot from the same
945
+ * instance in another view, the default view's first, matched by layer path
946
+ * and component set. Only the slots listed in GRAFTED_SLOTS: other parts leave
947
+ * a slot out on purpose (a Loading view's Data Table Toolbar has no `table`).
948
+ * A slot drawn empty stays empty. The saved tree is never changed: this works
949
+ * on a copy.
950
+ */
951
+ const GRAFTED_SLOTS = new Map([["Detail Page", new Set(["right pane"])]]);
952
+ function graftAbsentSlots(variants) {
953
+ const walk = (node, path, visit) => {
954
+ visit(node, path);
955
+ const seen = new Map();
956
+ for (const child of node.children ?? []) {
957
+ const at = seen.get(child.name) ?? 0;
958
+ seen.set(child.name, at + 1);
959
+ walk(child, `${path} › ${child.name}${at ? `#${at}` : ""}`, visit);
960
+ }
961
+ };
962
+ const keyOf = (node, path) => (node.type === "INSTANCE" && node.instance?.remote && GRAFTED_SLOTS.has(node.instance.set) ? `${node.instance.set}@${path}` : null);
963
+ const ordered = [...variants].sort((a, b) => (b.state === "default") - (a.state === "default"));
964
+ const drawn = new Map();
965
+ for (const variant of ordered) {
966
+ walk(variant.root, "", (node, path) => {
967
+ const key = keyOf(node, path);
968
+ if (!key) return;
969
+ const slots = drawn.get(key) ?? new Map();
970
+ for (const child of node.children ?? []) if (child.type === "SLOT" && GRAFTED_SLOTS.get(node.instance.set).has(child.slot) && !slots.has(child.slot)) slots.set(child.slot, child);
971
+ drawn.set(key, slots);
972
+ });
973
+ }
974
+ if (![...drawn.values()].some((slots) => slots.size)) return variants;
975
+ return variants.map((variant) => {
976
+ const copy = structuredClone(variant);
977
+ walk(copy.root, "", (node, path) => {
978
+ const slots = drawn.get(keyOf(node, path));
979
+ if (!slots?.size) return;
980
+ const own = new Set((node.children ?? []).filter((c) => c.type === "SLOT").map((c) => c.slot));
981
+ for (const [name, slot] of slots) if (!own.has(name)) node.children = [...(node.children ?? []), structuredClone(slot)];
982
+ });
983
+ return copy;
984
+ });
985
+ }
986
+
926
987
  function layerOf(node, ctx) {
927
988
  if (ctx.root) return "";
928
989
  const same = (ctx.parent?.children ?? []).filter((c) => c.name === node.name);
@@ -1316,7 +1377,8 @@ function showCondition(code, node, ctx, path) {
1316
1377
  * are (tabStrip).
1317
1378
  */
1318
1379
  function hideable(code) {
1319
- let out = code.replace(/<AlertAction>([\s\S]*?)<\/AlertAction>/g, (block, inner) => {
1380
+ // A parent template may include a child Alert that was already processed (NODII-DEV-CLI-209).
1381
+ let out = code.replace(/(?<!!== false && \()<AlertAction>([\s\S]*?)<\/AlertAction>/g, (block, inner) => {
1320
1382
  const flagOf = (part) => {
1321
1383
  const own = /\bonClick=\{(__s\d+)_on([A-Z]\w*)Click\}/.exec(part);
1322
1384
  return own ? `${own[1]}_show${own[2]}` : null;
@@ -1330,7 +1392,7 @@ function hideable(code) {
1330
1392
  let held = inner;
1331
1393
  for (const b of buttons.reverse()) {
1332
1394
  const flag = flagOf(b.code);
1333
- if (flag) held = `${held.slice(0, b.at)}{${flag} !== false && (${b.code})}${held.slice(b.at + b.code.length)}`;
1395
+ if (flag && !held.slice(0, b.at).endsWith(" !== false && (")) held = `${held.slice(0, b.at)}{${flag} !== false && (${b.code})}${held.slice(b.at + b.code.length)}`;
1334
1396
  }
1335
1397
  return `<AlertAction>${held}</AlertAction>`;
1336
1398
  });
@@ -2384,7 +2446,7 @@ function emitNode(node, ctx) {
2384
2446
  return comment(`unmapped: slot ${JSON.stringify(prop)} has no auto layout`);
2385
2447
  }
2386
2448
  const textOwner = TEXT_PROPERTY_PARTS.has(node.instance.set) ? node.instance.set : ctx.textOwner;
2387
- const slotCtx = { ...ctx, depth: 0, parent: slotNode, grand: null, path: `${path} › ${prop}`, root: false, textOwner, inTable: false, inSlot: true, chain: slotNode ? [...chain, slotNode] : chain, layer: `${ctx.layer}${nestedPath.map(part => ` › ${part}`).join("")} › ${prop}` };
2449
+ const slotCtx = { ...ctx, depth: 0, parent: slotNode, grand: null, path: `${path} › ${prop}`, root: false, textOwner, slotOwner: owner, inTable: false, inSlot: true, chain: slotNode ? [...chain, slotNode] : chain, layer: `${ctx.layer}${nestedPath.map(part => ` › ${part}`).join("")} › ${prop}` };
2388
2450
  const inner = emitChildren(slotNode?.children ?? [], (c) => emitNode(c, slotCtx), slotCtx);
2389
2451
  return inner.length === 0 ? "<></>" : inner.length === 1 ? inner[0] : `<>\n${inner.map((x) => indent(x, 1)).join("\n")}\n</>`;
2390
2452
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.178",
3
+ "version": "0.6.180",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {