@nodii/dev 0.6.207 → 0.6.209

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/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 = 62;
37
+ export const GENERATOR_FORMAT = 64;
38
38
  /**
39
39
  * DS parts that are an item of their parent's own list or grid, so they take no sizing
40
40
  * wrapper: a Detail Section / Row's facts are the section grid's cells, a Right Pane / Row
@@ -1843,7 +1843,12 @@ function textNextTo(node, ctx) {
1843
1843
  }
1844
1844
  return null;
1845
1845
  };
1846
- return beside(ctx.parent, node) ?? (ctx.grand ? beside(ctx.grand, ctx.parent) : null) ?? fieldGroupLabel(ctx.slotOwner);
1846
+ // A DS Label beside the toggle (or beside its size frame) names it through htmlFor
1847
+ // (pairLabelledControls), so the group's label is never borrowed over it (hub-629).
1848
+ const dsLabelBeside = (parent, target) =>
1849
+ (parent?.children ?? []).some((c) => c !== target && c.visible !== false && c.instance?.remote && c.instance.set === "Label");
1850
+ const labelled = dsLabelBeside(ctx.parent, node) || (ctx.grand ? dsLabelBeside(ctx.grand, ctx.parent) : false);
1851
+ return beside(ctx.parent, node) ?? (ctx.grand ? beside(ctx.grand, ctx.parent) : null) ?? (labelled ? null : fieldGroupLabel(ctx.slotOwner));
1847
1852
  }
1848
1853
 
1849
1854
  /**
@@ -3373,7 +3378,9 @@ const LABELLED_CONTROL = /<(?:Checkbox|Switch|RadioGroupItem|Textarea|Input|Sele
3373
3378
  */
3374
3379
  function pairLabelledControls(codes) {
3375
3380
  const out = [...codes];
3376
- const labelOf = codes.map((c) => LABEL_FOR.exec(c ?? "")?.[1] ?? null);
3381
+ // Only a sibling that IS a Label names a control. A container that holds Labels deeper
3382
+ // down (a FieldGroup's rows) pairs its own rows at its own level (hub-629).
3383
+ const labelOf = codes.map((c) => (/^\s*<Label\b/.test(c ?? "") ? LABEL_FOR.exec(c)?.[1] ?? null : null));
3377
3384
  const used = new Set();
3378
3385
  codes.forEach((code, i) => {
3379
3386
  const control = code ? LABELLED_CONTROL.exec(code) : null;
@@ -4175,14 +4182,17 @@ function tableOf(node, ctx) {
4175
4182
  const w = columnWidth(c.cell);
4176
4183
  let open = withAlign(`<TableCell${wrapperAttrs(w, first.row)}>`, i);
4177
4184
  let close = "</TableCell>";
4178
- if (c.code && !c.held) {
4179
- const emitted = emitNode(c.cell, { ...ctx, depth: 0, parent: null, path: `${ctx.path} › ${first.row.name}`, root: false, bare: true, inTable: true, scopes: null, note: () => {} });
4180
- const own = withWidth(c.selected ? selectedCell(emitted) : emitted, w).trim();
4185
+ // A union column's cell is the person cell's own, whichever row the frame draws first:
4186
+ // a plain first row would drop the rich cell's density (NODII-DEV-CLI-299).
4187
+ const sample = piiColumn[i] ? (mixedPii.get(i)?.sample ?? nullablePii.get(i)?.sample ?? personSamples.get(i) ?? c) : c;
4188
+ if (sample.code && !sample.held) {
4189
+ const emitted = emitNode(sample.cell, { ...ctx, depth: 0, parent: null, path: `${ctx.path} › ${first.row.name}`, root: false, bare: true, inTable: true, scopes: null, note: () => {} });
4190
+ const own = withWidth(sample.selected ? selectedCell(emitted) : emitted, w).trim();
4181
4191
  const end = openTagEnd(own);
4182
4192
  const tag = /^<([A-Za-z]+)/.exec(own)[1];
4183
4193
  open = withAlign(own.slice(0, end + 1).replace(/\s*\/>$/, ">"), i);
4184
4194
  close = `</${tag}>`;
4185
- if (oneLine(open, c.cell, own.slice(end + 1, own.lastIndexOf(close)), piiColumn[i])) open = withTruncate(open);
4195
+ if (oneLine(open, sample.cell, own.slice(end + 1, own.lastIndexOf(close)), piiColumn[i])) open = withTruncate(open);
4186
4196
  }
4187
4197
  // Selection is record data even when the drawing shows every row unchecked.
4188
4198
  if (/^<TableSelectionCell\b/.test(open)) {
package/dist/watchdog.js CHANGED
@@ -3,9 +3,12 @@ import { mkdir, readFile, readdir, rename, rm, writeFile, chmod } from "node:fs/
3
3
  import { homedir, platform } from "node:os";
4
4
  import { dirname, isAbsolute, join, resolve } from "node:path";
5
5
  import { promisify } from "node:util";
6
- import { CliError, configPath, devRequest, encode, readConfig } from "./core.js";
6
+ import { CliError, VERSION, configPath, devRequest, encode, readCallCost, readConfig } from "./core.js";
7
7
  import { USAGE_REFRESH_MS, listAccounts, reportUsage } from "./accounts.js";
8
8
  import { laneCloseout, laneCommand } from "./lanes.js";
9
+ import { appendInbox, inboxDir, roleWaitDeliveries, stewardRole } from "./lane-messages.js";
10
+ import { laneSwitchOn } from "./lane-switches.js";
11
+ import { managedEntry, readNeedsRoot } from "./managed-version.js";
9
12
  import { envAssignment, execLine, installNote, installSupervised, lingerLine, logsDir, supervisedDirs, unitActive, unitPath, unitState, unitText } from "./systemd.js";
10
13
 
11
14
  const execFile = promisify(execFileCallback);
@@ -255,8 +258,15 @@ export async function sweepWatchdog({
255
258
  refreshUsage = refreshMachineUsage,
256
259
  closeout = laneCloseout,
257
260
  saveReminder = saveLaneCapReminder,
261
+ // Only a record read from disk is removed: one passed in has no file here.
262
+ forget = (record) => (record.registryPath ? rm(record.registryPath, { force: true }) : undefined),
258
263
  // Dev marked it resume-due (its wait cleared), so the blocker gate is not asked again.
259
264
  resumeLane = (key, deps) => laneCommand("resume", [key], { ungated: true }, deps),
265
+ appendToInbox = appendInbox,
266
+ env = process.env,
267
+ callCost = () => readCallCost(),
268
+ needsRoot = () => readNeedsRoot(),
269
+ reportState = machineReportState(),
260
270
  } = {}) {
261
271
  const loaded = records ? { records, errors: [] } : await loadRecords();
262
272
  const facts = await collect(loaded.records, { errors: [...loaded.errors] });
@@ -264,6 +274,7 @@ export async function sweepWatchdog({
264
274
  const effectiveMachineId = machineId ?? (await coordinatorMachine({ request })).machineId;
265
275
  const orphanedRuns = [];
266
276
  const finalOrphanCloseouts = [];
277
+ const forgottenRuns = [];
267
278
  // Dev's live runs are the authority, not the local flags (NODII-DEV-CLI-42):
268
279
  // a run Dev still holds as running gets its dead process reported again, and
269
280
  // a run with no local record is one this sweep cannot see. Without Dev's list
@@ -324,10 +335,50 @@ export async function sweepWatchdog({
324
335
  facts.errors.push({ kind: "run", runId: record.runId, observation: "process_alive", code: error?.code ?? "RUN_WATCHDOG_REPORT_FAILED" });
325
336
  }
326
337
  }
338
+ // O3 item 8 (DEC-0569, MW1-36.5): a steward session's role waits and
339
+ // READYs reach it through its local inbox file, which its prompt hook reads
340
+ // at its next turn. Dev's lane message needs the steward lane's issue, and a
341
+ // scratch steward has none. Each is written once: the record keeps what it
342
+ // delivered.
343
+ const stewardDeliveries = [];
344
+ if (laneSwitchOn("laneMessages", env)) for (const live of facts.liveRuns ?? []) {
345
+ const record = byId.get(live.runId);
346
+ if (!record?.steward || !live.runtimeAlive || record.orphanReportedAt || record.terminalSeenAt) continue;
347
+ const before = Array.isArray(record.stewardDelivered) ? record.stewardDelivered : [];
348
+ try {
349
+ const role = stewardRole(record.steward);
350
+ if (!role) continue;
351
+ const board = (await request("GET", `/api/v1/lanes/waits?person=${encode(role)}`))?.data;
352
+ // A Dev without role waits has no `persons`: nothing is delivered or forgotten.
353
+ if (!Array.isArray(board?.persons)) continue;
354
+ const next = roleWaitDeliveries(record.steward, board, before, { now });
355
+ if (next.entries.length) await appendToInbox(record.steward, next.entries, { dir: inboxDir(record.configPath) });
356
+ if (next.entries.length || next.delivered.length !== before.length) {
357
+ record.stewardDelivered = next.delivered;
358
+ await saveRecord(record);
359
+ }
360
+ if (next.entries.length) stewardDeliveries.push({ runId: record.runId, steward: record.steward, delivered: next.entries.length });
361
+ } catch (error) {
362
+ facts.errors.push({ kind: "steward_waits", runId: record.runId, code: error?.code ?? "LANE_WAITS_READ_FAILED" });
363
+ }
364
+ }
327
365
  for (const dead of facts.deadRuns) {
328
366
  const record = byId.get(dead.runId);
329
367
  if (!record) continue;
330
- if ((record.orphanReportedAt || record.terminalSeenAt) && !devLiveIds.has(record.runId)) continue;
368
+ if ((record.orphanReportedAt || record.terminalSeenAt) && !devLiveIds.has(record.runId)) {
369
+ // O3 item 6: its process is dead and Dev holds it orphaned or ended, so
370
+ // nothing is left to report. Forget it, so later sweeps neither probe
371
+ // its pid nor inspect its worktree. Only on Dev's word: when the live
372
+ // list could not be read the record is kept.
373
+ if (devLiveRuns === null) continue;
374
+ try {
375
+ await forget(record);
376
+ forgottenRuns.push(record.runId);
377
+ } catch (error) {
378
+ facts.errors.push({ kind: "registry", runId: record.runId, code: error?.code ?? "WATCHDOG_RECORD_FORGET_FAILED" });
379
+ }
380
+ continue;
381
+ }
331
382
  try {
332
383
  const observedAt = now().toISOString();
333
384
  const response = await request("POST", `/api/v1/runs/${encode(record.runId)}/watchdog`, observationBody({
@@ -370,12 +421,51 @@ export async function sweepWatchdog({
370
421
  facts.errors.push({ kind: "usage", code: error?.code ?? "ACCOUNT_USAGE_REPORT_FAILED" });
371
422
  }
372
423
  let laneCap = null;
424
+ let machine = null;
373
425
  try {
374
- laneCap = (await request("GET", `/api/v1/machines/${encode(effectiveMachineId)}`)).data?.laneCapState ?? null;
426
+ machine = (await request("GET", `/api/v1/machines/${encode(effectiveMachineId)}`)).data ?? null;
427
+ laneCap = machine?.laneCapState ?? null;
375
428
  await saveReminder(laneCapReminderText(laneCap, now()));
376
429
  } catch (error) {
377
430
  facts.errors.push({ kind: "lane_cap", code: error?.code ?? "LANE_CAP_READ_FAILED" });
378
431
  }
432
+ // O3 item 6 (DEC-0569, MW1-36.5): the machine reads live from its sweeps.
433
+ // Its report carries the last sweep, the CLI version and the lane cap state
434
+ // beside the facts it already holds (a report replaces them all).
435
+ // O3 item 4 (MW5-8.1): and the local call counters and whether a harness
436
+ // update needs root, read from files here: no Dev call of their own.
437
+ // Review of #505: a report goes only when its kept facts changed or the last
438
+ // one is MACHINE_REPORT_EVERY_MS old, so Dev's lastSweepAt (live within 5
439
+ // minutes) never lapses on a one-minute sweep.
440
+ let machineReported = false;
441
+ if (machine && !(Number.isInteger(machine.heavySlotTotal) && machine.heavySlotTotal > 0))
442
+ facts.errors.push({ kind: "machine_report", code: "MACHINE_REPORT_FAILED", reason: "Dev's machine record has no heavySlotTotal, so no report was sent" });
443
+ else if (machine) {
444
+ const cost = await Promise.resolve().then(callCost).catch(() => null);
445
+ const root = await Promise.resolve().then(needsRoot).catch(() => null);
446
+ const kept = {
447
+ hostFacts: { ...(machine.hostFacts ?? {}), cliVersion: VERSION, capState: laneCap, ...(cost ? { callCost: cost } : {}), ...(typeof root === "boolean" ? { needsRoot: root } : {}) },
448
+ memoryFacts: machine.memoryFacts ?? {},
449
+ heavySlotTotal: machine.heavySlotTotal,
450
+ };
451
+ delete kept.hostFacts.lastSweepAt;
452
+ // Call cost moves on every Dev request, so it rides along but never makes
453
+ // a report due by itself (hub-ee, review of #505).
454
+ const { callCost: _moving, ...steady } = kept.hostFacts;
455
+ const digest = JSON.stringify({ ...kept, hostFacts: steady });
456
+ const last = await Promise.resolve().then(() => reportState.read()).catch(() => null);
457
+ const due = !last || last.digest !== digest || !(now() - Date.parse(last.at) < MACHINE_REPORT_EVERY_MS);
458
+ if (due) {
459
+ try {
460
+ const at = now().toISOString();
461
+ await request("POST", `/api/v1/machines/${encode(effectiveMachineId)}/report`, { ...kept, hostFacts: { ...kept.hostFacts, lastSweepAt: at } });
462
+ machineReported = true;
463
+ await Promise.resolve().then(() => reportState.write({ digest, at })).catch(() => {});
464
+ } catch (error) {
465
+ facts.errors.push({ kind: "machine_report", code: error?.code ?? "MACHINE_REPORT_FAILED" });
466
+ }
467
+ }
468
+ }
379
469
  // hub-251: a lane whose wait cleared (the lane it waited on merged, reached
380
470
  // dev or ended) and that no process works is resume due. Dev decides which;
381
471
  // this Mac resumes them, a few per sweep, and lane resume keeps the machine's
@@ -397,7 +487,7 @@ export async function sweepWatchdog({
397
487
  } catch (error) {
398
488
  facts.errors.push({ kind: "resume_due", code: error?.code ?? "RESUME_DUE_READ_FAILED" });
399
489
  }
400
- const report = { ...facts, orphanedRuns, finalOrphanCloseouts, unwatchedRuns, accounts, laneCap, resumed };
490
+ const report = { ...facts, orphanedRuns, finalOrphanCloseouts, forgottenRuns, unwatchedRuns, stewardDeliveries, accounts, laneCap, machineReported, resumed };
401
491
  return report;
402
492
  }
403
493
 
@@ -478,7 +568,7 @@ export async function installWatchdog({
478
568
  env = process.env,
479
569
  interval = 60,
480
570
  runtime = process.execPath,
481
- entry = resolve(process.argv[1]),
571
+ entry = null,
482
572
  configFile = configPath(),
483
573
  config = readConfig,
484
574
  request = devRequest,
@@ -491,6 +581,9 @@ export async function installWatchdog({
491
581
  if (os === "darwin" && (!Number.isInteger(uid) || uid < 0)) throw new CliError("WATCHDOG_INSTALL_FAILED", "Cannot determine the macOS user id for launchd.", 1);
492
582
  const current = typeof config === "function" ? await config() : config;
493
583
  await assertCoordinator(current, request);
584
+ // The job runs the managed copy, which `harness update` upgrades in place,
585
+ // never the npx cache or checkout that happened to install it (CLI-15).
586
+ entry ??= (await managedEntry()) ?? resolve(process.argv[1]);
494
587
  if (os === "linux") return installSystemdWatchdog({ home, env, interval, runtime, entry, configFile, execute });
495
588
  const logs = logsDir({ home, os });
496
589
  const plistPath = join(home, "Library", "LaunchAgents", `${WATCHDOG_LABEL}.plist`);
@@ -557,6 +650,16 @@ export async function watchdogStatus({
557
650
  * The sweep errors that leave Dev without a run's state: a failed run report,
558
651
  * Dev's live runs unread, or a local run record unreadable.
559
652
  */
653
+ /** A machine report is sent at least this often; with one-minute sweeps, reports land at most 5 minutes apart. */
654
+ export const MACHINE_REPORT_EVERY_MS = 4 * 60_000;
655
+ /** What the last machine report sent and when, beside the CLI config (the sweep's own NODII_DEV_CONFIG_PATH). */
656
+ export function machineReportState(path = join(dirname(configPath()), "watchdog-machine-report.json")) {
657
+ return {
658
+ read: async () => JSON.parse(await readFile(path, "utf8")),
659
+ write: (value) => atomicWrite(path, `${JSON.stringify(value)}\n`),
660
+ };
661
+ }
662
+
560
663
  export const SWEEP_FATAL_KINDS = new Set(["run", "live_runs", "registry"]);
561
664
 
562
665
  export async function watchdogCommand(action, flags, dependencies = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.207",
3
+ "version": "0.6.209",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {