@staix/agent-hub 0.39.0 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +12 -6
  3. package/docs/adding-an-ai-tool.md +1 -1
  4. package/docs/agent-notes/README.md +7 -0
  5. package/docs/agent-notes/adapters.md +5 -3
  6. package/docs/agent-notes/benchmarks.md +2 -0
  7. package/docs/agent-notes/budget.md +1 -0
  8. package/docs/agent-notes/bus.md +1 -0
  9. package/docs/agent-notes/daemon.md +8 -3
  10. package/docs/agent-notes/local-worker.md +3 -1
  11. package/docs/agent-notes/security-review.md +1 -0
  12. package/docs/agent-notes/tasks.md +7 -2
  13. package/docs/agent-notes/tests.md +7 -7
  14. package/docs/contracts/companion-cli-v1.json +4 -0
  15. package/docs/design/adapters.md +91 -0
  16. package/docs/design/agent-hub-architecture.md +17 -0
  17. package/docs/design/agent-hub.md +10 -0
  18. package/docs/design/bus.md +7 -0
  19. package/docs/design/cli-output.md +183 -0
  20. package/docs/design/execution-reference.md +6 -1
  21. package/docs/design/roadmap.md +191 -0
  22. package/docs/design/task-board.md +34 -0
  23. package/docs/dogfood.md +11 -4
  24. package/docs/events.md +4 -4
  25. package/docs/memory.md +3 -3
  26. package/docs/operations.md +153 -41
  27. package/docs/profiles.md +1 -0
  28. package/docs/quickstart.md +17 -4
  29. package/docs/sdlc.md +3 -1
  30. package/docs/security.md +40 -4
  31. package/docs/verification/2026-11-14-codex-0169-reviewer-isolation.md +70 -0
  32. package/docs/verification/2026-11-14-codex-0169-reviewer-tool-call.md +48 -0
  33. package/docs/verification/2026-11-14-pi-152-compat.md +45 -0
  34. package/docs/verification/2026-11-15-0.40.0.md +39 -0
  35. package/docs/verification/2026-11-16-pi-loopback-1447.md +39 -0
  36. package/docs/verification/pi-152-model-free.ts +57 -0
  37. package/docs/verification/pi-152-native.mjs +21 -0
  38. package/docs/verified.json +22 -22
  39. package/package.json +3 -3
  40. package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
  41. package/plugins/agent-hub/kimi-hook.js +332 -89
  42. package/plugins/agent-hub/kimi-review-policy-worker.js +16 -11
  43. package/plugins/agent-hub/server.js +417 -160
  44. package/src/adapters/agy/definition.ts +1 -1
  45. package/src/adapters/claude-channel.ts +1 -1
  46. package/src/adapters/codex-review-isolation.ts +61 -17
  47. package/src/adapters/compat.ts +7 -7
  48. package/src/adapters/definitions/builtin-metadata.ts +6 -6
  49. package/src/adapters/definitions/native-config-defaults.ts +1 -1
  50. package/src/adapters/definitions/native-config-policy.ts +1 -1
  51. package/src/adapters/definitions/qwen.ts +1 -1
  52. package/src/adapters/local-worker.ts +5 -3
  53. package/src/adapters/pi.ts +54 -11
  54. package/src/adapters/registry-types.ts +2 -1
  55. package/src/adapters/reviewer-print.ts +2 -1
  56. package/src/cli/answer-args.ts +11 -3
  57. package/src/cli/console-question.ts +1 -1
  58. package/src/cli/console-state.ts +95 -10
  59. package/src/cli/console.ts +6 -2
  60. package/src/cli/error-format.ts +19 -0
  61. package/src/cli/help.ts +290 -25
  62. package/src/cli/identity-audit.ts +8 -7
  63. package/src/cli/identity.ts +17 -0
  64. package/src/cli/init.ts +102 -9
  65. package/src/cli/main.js +2 -2
  66. package/src/cli/main.ts +57 -21
  67. package/src/cli/output-standard.ts +56 -0
  68. package/src/cli/output.ts +143 -8
  69. package/src/cli/roadmap.ts +215 -0
  70. package/src/cli/smoke-pty-bridge.ts +7 -24
  71. package/src/cli/task-output.ts +3 -1
  72. package/src/cli/upgrade-presentation-flags.ts +2 -2
  73. package/src/hub/board.ts +200 -3
  74. package/src/hub/bus.ts +9 -0
  75. package/src/hub/check-runner.ts +3 -4
  76. package/src/hub/ci-watch.ts +19 -4
  77. package/src/hub/control-client.ts +1 -1
  78. package/src/hub/daemon.ts +245 -43
  79. package/src/hub/events.ts +2 -2
  80. package/src/hub/execution-reference.ts +1 -1
  81. package/src/hub/github-import.ts +81 -0
  82. package/src/hub/hub-tools.ts +34 -9
  83. package/src/hub/install-policy.ts +23 -0
  84. package/src/hub/lifecycle-schema.ts +2 -2
  85. package/src/hub/no-writes.ts +3 -0
  86. package/src/hub/operational-authority.ts +3 -1
  87. package/src/hub/operational-view.ts +1 -1
  88. package/src/hub/pi-failure.ts +7 -0
  89. package/src/hub/question-desk.ts +26 -7
  90. package/src/hub/questions.ts +33 -5
  91. package/src/hub/restart.ts +7 -0
  92. package/src/hub/roadmap-triage.ts +86 -0
  93. package/src/hub/roadmap-unplaced.ts +169 -0
  94. package/src/hub/roadmap-view.ts +83 -0
  95. package/src/hub/roadmap.ts +127 -0
  96. package/src/hub/sdlc-merge.ts +5 -4
  97. package/src/hub/sdlc-queue.ts +3 -3
  98. package/src/hub/sdlc.ts +37 -2
  99. package/src/hub/specs-task.ts +7 -0
  100. package/src/hub/task-sweep.ts +29 -2
  101. package/src/hub/task-worktree.ts +37 -0
  102. package/src/hub/tasks.ts +381 -7
  103. package/src/pi/dependency-publish.ts +50 -0
  104. package/src/pi/extension.ts +1 -1
  105. package/src/pi/launch.ts +1 -1
  106. package/src/pi/task-dependencies.ts +249 -0
  107. package/src/ui/index.html +53 -13
  108. package/src/ui/plugin-questions.ts +5 -0
  109. package/src/ui/plugin.ts +6 -1
  110. package/templates/config.json +1 -1
package/src/cli/output.ts CHANGED
@@ -7,7 +7,7 @@ import { definitionOf } from "../adapters/registry.ts";
7
7
  import { windowKind } from "../hub/window-kind.ts";
8
8
  import { boardColumns, type BoardPeerInput } from "../ui/task-board.ts";
9
9
  import { peerStyle } from "../ui/peer-palette.ts";
10
- import { cells, TABLES, table, fitLine, wrap, duration, relative, plural, terminalText, initialConsoleState, stateTone, type Span, type Tone } from "./console-state.ts";
10
+ import { cells, TABLES, table, fitLine, wrap, duration, relative, plural, terminalText, initialConsoleState, stateTone, Report as LayoutReport, type MarkerName, type Span, type Tone } from "./console-state.ts";
11
11
  import { taskProgress } from "../ui/task-progress.ts";
12
12
  import { backendLabel, memorySyncLine, reviewInputHealthLine, roomsUnavailableLine } from "./status-lines.ts";
13
13
  import { ownerIsolationText } from "./role-holders.ts";
@@ -408,6 +408,119 @@ export function renderStatus(data: StatusOutput, columns?: number, now = Date.no
408
408
  if (data.personRun?.length) out.push(...lines(`WAITING ON YOU ${data.personRun.map(id => `#${id}`).join(", ")} (person-run: no agent is offered it; ahub backlog list)`, columns, "attention"));
409
409
  return out;
410
410
  }
411
+ /** One thing on `ahub status` that needs action: a marker, the finding, and the exact next command when the fix is known. */
412
+ export interface AttentionItem { marker: "fail" | "warn"; text: string; next?: string }
413
+ /**
414
+ * CLI output standard v1: every item of the status data that needs a person or an agent to act, in one list. Facts stay out; a row that is only information
415
+ * is not here. A next step is given only where the command is complete and copyable (no placeholder), never invented.
416
+ */
417
+ export function statusAttention(data: StatusOutput, now = Date.now()): AttentionItem[] {
418
+ const items: AttentionItem[] = [];
419
+ const add = (marker: AttentionItem["marker"], text: string, next?: string) => { items.push({ marker, text: flat(text), ...(next ? { next } : {}) }); };
420
+ if (data.runtimeModelsUnavailable === true) add("warn", "runtime models unavailable: could not read a bounded model catalog", "ahub model list");
421
+ const specs = data.specs;
422
+ if (specs && [specs.errors, specs.stale].every(value => Number.isSafeInteger(value) && value >= 0) && (specs.errors || specs.stale)) add("warn", `specs: ${specs.errors} errors, ${specs.stale} stale`, "ahub specs check");
423
+ if (specs?.truncated) add("warn", "specs: report truncated; narrow specs.roots", "ahub specs check");
424
+ if (specs?.missingBlockHint) add("warn", "specs: AGENTS.md has no specs instruction block");
425
+ for (const pending of data.pendingRestart ?? []) add("warn", `restart pending: ${pending.key}: ${pending.reason}`, "ahub restart --dry-run");
426
+ if (data.mainCheckout) add("warn", `main checkout: ${data.mainCheckout}`);
427
+ // Only a refused version needs action. A trusted one is already accepted (the command would repeat what was done) and an in-line one is within policy: both are facts, shown as a count on the Hub row.
428
+ for (const drift of data.agentDrift ?? []) if (drift.state === "refused") add("warn", `agent CLI ${drift.id} ${drift.version} is refused`, `ahub agents trust ${drift.id} ${drift.version}`);
429
+ if (data.retainedConfig?.length) add("warn", `config retained: ${data.retainedConfig.map(row => row.key).join(", ")}`, "ahub settings reload");
430
+ for (const row of data.schedules ?? []) if (row.error) add("warn", `schedule ${row.id}: ${row.error}`, "ahub schedule list");
431
+ for (const [peer, row] of Object.entries(data.queueBackpressure?.peers ?? {})) if (row.blocked) add("warn", `${peer} queue pressure: automatic offers held: ${row.reason ?? row.code ?? "unknown"}`, `ahub queue list --peer ${peer}`);
432
+ for (const stall of data.taskStalls ?? []) add("warn", `task #${stall.task} stalled: ${stall.cause.kind}${stall.cause.peer ? ` ${stall.cause.peer}` : ""}${stall.cause.dependency ? ` #${stall.cause.dependency}` : ""}: ${stall.cause.code}`, `ahub task show ${stall.task}`);
433
+ for (const offer of data.pendingTaskOffers ?? []) add("warn", `task #${offer.task} is waiting for ${offer.peer}`, `ahub task show ${offer.task}`);
434
+ if (data.memoryProfile?.state === "unavailable") add("warn", `memory unavailable${data.memoryProfile.error ? `: ${data.memoryProfile.error}` : ""}`, "ahub doctor");
435
+ if (data.memoryProfile?.sync?.state === "failed") add("warn", `memory sync failed: ${memorySyncLine(data.memoryProfile.sync)}`, "ahub doctor");
436
+ if (data.memoryRead?.truncated) add("warn", `memory view truncated: newest ${data.memoryRead.limit} project candidates considered`);
437
+ if (data.planner?.source === "none") add("warn", "no planner is configured", "ahub roles");
438
+ for (const [id, isolated] of Object.entries(data.ownerIsolation ?? {})) { const text = ownerIsolationText(isolated, data.ownerIsolationNotes?.[id]); if (text && !isolated) add("warn", `${id} owner isolation: ${text}`); }
439
+ if (data.roomsUnavailable !== undefined) add("fail", roomsUnavailableLine(data.roomsUnavailable));
440
+ if (data.deliveryError) add("fail", `delivery storage: ${data.deliveryError}; dispatch is stopped`, "ahub doctor");
441
+ for (const [peer, count] of Object.entries(data.deliveryFailures ?? {})) if (Number.isSafeInteger(count) && count > 0) add("warn", `${peer} has ${count} failed deliver${count === 1 ? "y" : "ies"}`, `ahub queue discard --peer ${peer} --state failed`);
442
+ if (data.reviewInputHealth) { const health = reviewInputHealthLine(data.reviewInputHealth); if (health) add(data.reviewInputHealth.state === "corrupt" ? "fail" : "warn", `review input provenance: ${health}`); }
443
+ for (const pending of data.permissionDefaults ?? []) add("warn", `permission default: ${pending.peer} never-ask from ${pending.source} stays ask until a person confirms`, "ahub console");
444
+ for (const crash of data.crash ?? []) add("warn", `crash recovery: ${crash}`);
445
+ for (const warning of data.isolatedChecks?.orphans ?? []) add("warn", `isolated check: ${warning}`);
446
+ for (const id of data.isolatedChecks?.unknownReceipts ?? []) add("warn", `check receipt ${id}: unknown; receipt storage unavailable`);
447
+ if (data.isolatedChecks?.maintenanceUnavailable) add("warn", "check maintenance unavailable; saved run outcomes are unchanged");
448
+ for (const [id, p] of Object.entries(data.peers)) {
449
+ for (const session of Array.isArray(p.standbySessions) ? p.standbySessions : []) {
450
+ if (!session || typeof session.id !== "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(session.id)) continue;
451
+ add("warn", `${id} has a standby session waiting${Number.isFinite(session.since) ? ` ${relative(session.since, now)}` : ""}`, `ahub peer takeover ${id} ${session.id}`);
452
+ }
453
+ if (typeof p.reviewObserverHoldNote === "string" && p.reviewObserverHoldNote) add("warn", `${id} review input: ${p.reviewObserverHoldNote}`);
454
+ if (p.heldRows?.length) for (const row of p.heldRows) add("fail", `${id}: a delivery is held for review (from ${row.senders.join(",")}; ${duration(Math.max(0, now - row.createdAt))} old)`, `ahub queue show ${row.id}`);
455
+ else if (p.heldBy) add("fail", `${id}: a delivery is held for review${p.holdNote ? `: ${flat(p.holdNote)}` : ""}`, `${queueResolveCommand({ id: p.heldBy, peer: id, state: "needs_review" })}`);
456
+ if (p.paused) {
457
+ const budgetPause = data.budget?.[id]?.paused;
458
+ const text = budgetPause ? `budget: ${budgetPause.reason ?? "threshold"}${typeof budgetPause.resetsAt === "number" ? `; resets ${relative(budgetPause.resetsAt, now)}` : "; reset unknown"}`
459
+ : typeof p.paused === "object" ? `${p.paused.by ?? "paused"}${p.paused.reason ? `: ${p.paused.reason}` : ""}` : flat(p.paused);
460
+ add("warn", `${id} is paused (${text})`, budgetPause ? "ahub budget" : `ahub resume ${id}`);
461
+ }
462
+ if (typeof p.reviewerUnavailable === "string" && p.reviewerUnavailable) add("fail", `${id} reviewer unavailable: ${flat(p.reviewerUnavailable)}`);
463
+ if (p.ownerIsolationNote) add("warn", `${id} owner isolation: ${p.ownerIsolationNote}`);
464
+ if (typeof p.statusNotice?.message === "string" && p.statusNotice.message) add("warn", `${id}: ${p.statusNotice.message}`);
465
+ if (typeof p.importantWaitingSince === "number" && p.importantWaitingNote) add("warn", `${id}: ${String(p.importantWaitingNote)}`, `ahub queue list --peer ${id}`);
466
+ const actionPolicy = data.actionPolicyInfo?.[id];
467
+ if (actionPolicy?.note && !actionPolicy.enforceable) add("warn", `${id} action policy: ${actionPolicy.note}`);
468
+ }
469
+ for (const b of data.models?.backends ?? []) for (const [key, label] of [["coolingUntil", "cooling"], ["failingUntil", "dispatch held"]] as const) {
470
+ if (!b[key]) continue; const at = Date.parse(b[key]);
471
+ add("warn", `${backendLabel(b)} ${label}${Number.isFinite(at) ? ` until ${relative(at, now)}` : ""}`);
472
+ }
473
+ // The documented line (docs/operations.md, person-run legs): its words are kept so a person searching status for it still finds it.
474
+ if (data.personRun?.length) add("warn", `WAITING ON YOU ${data.personRun.map(id => `#${id}`).join(", ")} (person-run: no agent is offered it)`, "ahub backlog list");
475
+ return items;
476
+ }
477
+ /**
478
+ * `ahub status` as CLI output standard v1 reads it: a header, an Attention section (every item that needs action, marked, with its next command), then the hub,
479
+ * the peers and the tasks. Everything else the older view printed stays in `renderStatus`, behind `--verbose` and `--full`. `columns` undefined is a pipe: no wrap.
480
+ */
481
+ export function renderStatusDefault(data: StatusOutput, columns?: number, now = Date.now(), ascii = false): Span[][] {
482
+ if (data.roleInfo) data = { ...data, peers: Object.fromEntries(Object.entries(data.peers).map(([peer, value]) => [peer, { ...value, ...data.roleInfo?.[peer] }])) };
483
+ const report = new LayoutReport(columns, ascii).header("ahub", "Status", [data.version, data.pid !== undefined ? `pid ${data.pid}` : undefined, data.controlPort !== undefined ? `127.0.0.1:${data.controlPort}` : undefined].filter(Boolean).join(" "));
484
+ const attention = statusAttention(data, now);
485
+ report.section("Attention", attention.length ? plural(attention.length, "item") : undefined);
486
+ if (!attention.length) report.bullet("ok", "nothing needs attention");
487
+ for (const item of attention) { report.bullet(item.marker, item.text); if (item.next) report.next(item.next); }
488
+ const hub: [string, unknown][] = [["version", data.version ?? "unknown"], ["pid", data.pid ?? "unknown"], ["control", `127.0.0.1:${data.controlPort ?? "unknown"}`], ["project", data.cwd ?? ""]];
489
+ if (data.planner) hub.push(["planner", `${data.planner.peers?.join(", ") || "nobody"} (${data.planner.source ?? "unknown"})`]);
490
+ if (data.memoryProfile) hub.push(["memory", `${data.memoryProfile.profile === "generation" ? `generation ${data.memoryProfile.generation?.slice(0, 8) ?? "unknown"}` : data.memoryProfile.profile ?? "unbound"}; ${data.memoryProfile.state ?? "unknown"}`]);
491
+ const specs = data.specs;
492
+ if (specs && [specs.specCount, specs.documents, specs.errors, specs.stale].every(value => Number.isSafeInteger(value) && value >= 0) && (specs.specCount > 0 || specs.documents > 0 || specs.errors > 0)) hub.push(["specs", `${specs.specCount} (errors ${specs.errors}, stale ${specs.stale})`]);
493
+ const outside = (data.agentDrift ?? []).filter(row => row.state !== "refused");
494
+ if (outside.length) hub.push(["agent CLIs", `${outside.length} outside the verified version, already accepted (ahub agents)`]);
495
+ if (data.schedules?.length) hub.push(["schedules", plural(data.schedules.length, "schedule")]);
496
+ report.section("Hub").kv(hub);
497
+ const peers = Object.entries(data.peers);
498
+ const s = initialConsoleState(); s.panel = 1; s.peers = data.peers; s.budget = data.budget ?? {};
499
+ const head = peers.some(([, p]) => p.permissionMode && p.permissionMode !== "ask") ? ["PEER", "STATE", "MODE", ...TABLES[1]!.slice(2)] : [...TABLES[1]!];
500
+ head.push("CONTEXT");
501
+ const peerRows = peers.map(([id, p]) => { const result = cells(s, { id, ...p }, false, now); result[0] = span(id, peerTone(id)); result.push(span(contextText(p, now))); return result; });
502
+ report.section("Peers", peers.length ? `${peers.length}` : undefined);
503
+ if (peerRows.length) report.append(rows(head, peerRows, columns));
504
+ else report.note("no peers attached yet (ahub claude | ahub codex | ahub kimi)");
505
+ // Plain keys under each peer: the peer is the heading, so a key never repeats its name (`form`, not `claude form`).
506
+ for (const [id, p] of peers) {
507
+ const facts: [string, unknown][] = [];
508
+ if (typeof p.form === "string") facts.push(["form", p.form]);
509
+ if (p.flowRoles) facts.push(["flow roles", p.flowRoles.join(", ") || "none"]);
510
+ if (Array.isArray(p.capableRoles)) facts.push(["capable roles", p.capableRoles.join(", ") || "none"]);
511
+ if (p.catalogRoles && Array.isArray(p.catalogRoles.value) && p.catalogRoles.value.length) facts.push(["catalog roles", p.catalogRoles.value.join(", ")]);
512
+ if (typeof p.oldestQueuedAt === "number") facts.push(["oldest queued", relative(p.oldestQueuedAt, now)]);
513
+ if (!facts.length) continue;
514
+ report.append([[{ text: ` ${id}`, tone: peerTone(id) }]]).kv(facts, 4);
515
+ }
516
+ const counts = Object.entries(data.tasks ?? {});
517
+ report.section("Tasks", counts.length ? `${counts.reduce((sum, [, n]) => sum + n, 0)}` : undefined);
518
+ if (counts.length) report.kv(counts.map(([state, n]) => [state, n] as const));
519
+ else report.note("no tasks");
520
+ if (data.taskWip && Object.keys(data.taskWip).length) report.kv([["planner WIP", Object.entries(data.taskWip).map(([peer, value]) => `${peer} ${value.wip}/${value.wipLimit}${wipSplit(value)}`).join("; ")]]);
521
+ report.note("ahub board lists them; ahub status --verbose shows every detail", "hint");
522
+ return report.lines();
523
+ }
411
524
  // #724: short next-step codes for the compact board, keyed on the blocker texts of src/hub/sdlc.ts; the full advice stays in --full and ahub task show.
412
525
  const STAGE_CODES: [string, string][] = [["issue identity missing", "issue?"], ["PR identity missing", "PR?"], ["PR is not open", "PR closed"], ["current PR evidence unknown", "PR state?"],
413
526
  ["required check", "CI?"], ["local gate", "gate?"], ["current head has not been reviewed", "review?"], ["GitHub review approval", "approval?"], ["review requests", "requests?"],
@@ -556,17 +669,39 @@ export function renderBoardColumns(tasks: any[], peers: Record<string, BoardPeer
556
669
  return out;
557
670
  }
558
671
 
559
- export function renderDoctor(checks: DoctorCheck[], columns?: number, _now = Date.now(), _full = false): Span[][] {
560
- const out: Span[][] = [];
561
- const tone = { ok: "success", warn: "attention", fail: "failure", unknown: "muted" } as const;
672
+ /** The standard's cap for every non-flexible text column (docs/design/cli-output.md, Layout grammar: Table). */
673
+ const COLUMN_CAP = 32;
674
+ /** A text longer than `cells` keeps its start and its end and drops the middle: `~/Library/.../home`. Never cuts inside a grapheme. */
675
+ export function shortenMiddle(text: string, cells: number): string {
676
+ const value = flat(text);
677
+ if (width(value) <= cells || cells < 5) return value;
678
+ const units = [...graphemes.segment(value)].map(part => part.segment), room = cells - 3;
679
+ let head = "", tail = "", front = 0, back = units.length;
680
+ const headRoom = Math.ceil(room / 2), tailRoom = room - headRoom;
681
+ for (; front < units.length && width(head + units[front]!) <= headRoom; front++) head += units[front]!;
682
+ for (; back > front && width(units[back - 1]! + tail) <= tailRoom; back--) tail = units[back - 1]! + tail;
683
+ return `${head}...${tail}`;
684
+ }
685
+ const DOCTOR_ORDER: Record<DoctorCheck["level"], number> = { fail: 0, warn: 1, unknown: 2, ok: 3 };
686
+ const DOCTOR_MARKER: Record<DoctorCheck["level"], MarkerName> = { fail: "fail", warn: "warn", unknown: "unknown", ok: "ok" };
687
+ /**
688
+ * `ahub doctor` as standard v1 reads: per section a marker, the check (capped at 32 cells, a long path shortened in the middle) and its finding;
689
+ * failures first, then warnings, unknowns and oks; one summary line last. The word of each state stays in the row, so it reads without color.
690
+ */
691
+ export function renderDoctor(checks: DoctorCheck[], columns?: number, _now = Date.now(), _full = false, ascii = false): Span[][] {
692
+ const report = new LayoutReport(columns, ascii);
562
693
  for (const section of ["Tools", "Hub", "Config", "Models", "Memory"] as const) {
563
694
  const group = checks.filter(check => check.section === section); if (!group.length) continue;
564
- if (out.length) out.push([]); out.push([span(section, "strong")]);
565
- out.push(...rows(["LEVEL", "CHECK", "FINDING"], group.map(check => [span(check.level, tone[check.level]), span(check.name), span(check.detail || "finding unknown")]), columns));
695
+ const worst = group.filter(check => check.level !== "ok").length;
696
+ report.section(section, worst ? `${worst} of ${group.length} need a look` : `${group.length} ok`);
697
+ for (const check of [...group].sort((x, y) => DOCTOR_ORDER[x.level] - DOCTOR_ORDER[y.level])) {
698
+ const name = shortenMiddle(check.name, COLUMN_CAP), finding = flat(check.detail) || "finding unknown";
699
+ report.bullet(DOCTOR_MARKER[check.level], `${check.level === "ok" ? "" : `${check.level} `}${name}: ${finding}`);
700
+ }
566
701
  }
567
702
  const count = (level: DoctorCheck["level"]) => checks.filter(c => c.level === level).length;
568
- out.push([], ...lines(`${count("fail")} failure${count("fail") === 1 ? "" : "s"}, ${count("warn")} warning${count("warn") === 1 ? "" : "s"}, ${count("ok")} ok, ${count("unknown")} unknown`, columns));
569
- return out;
703
+ report.summary({ failed: count("fail"), warnings: count("warn"), unknown: count("unknown"), ok: count("ok") });
704
+ return report.lines();
570
705
  }
571
706
 
572
707
  export function renderProjects(projects: any[], columns?: number, _now = Date.now()): Span[][] {
@@ -0,0 +1,215 @@
1
+ import { milestoneId, milestoneRevision, milestoneLinkRef, parseMilestoneInput, parseMilestonePatch, githubRepo, type MilestoneLinkKind } from "../hub/roadmap.ts";
2
+ import { terminalText, wrap } from "./console-state.ts";
3
+
4
+ const optionalFields = "[--horizon now|next|later] [--order <n>] [--target YYYY-MM-DD|none] [--parent <id>|none]";
5
+ export const ROADMAP_FORMS = {
6
+ list: "[list] [--json]", show: "show <id> [--json]",
7
+ new: `new --title <text> --outcome <text> ${optionalFields}`,
8
+ edit: `edit <id> --revision <n> [--title <text>] [--outcome <text>] ${optionalFields}`,
9
+ link: "link <id> <spec|issue|task|release> <ref>", unlink: "unlink <id> <kind> <ref>",
10
+ order: "order <id> <n>", state: "state <id> <proposed|planned|active|done|dropped>",
11
+ unplaced: "unplaced [--repo <owner/name>] [--json]",
12
+ triage: "triage [--repo <owner/name>] [--list] [--json]",
13
+ accept: "accept <suggestion>", reject: "reject <suggestion>",
14
+ importGithub: "import-github [--repo <owner/name>] [--apply] [--json]",
15
+ } as const;
16
+ export const ROADMAP_USAGE = `usage: ${Object.values(ROADMAP_FORMS).map(form => `ahub roadmap ${form}`).join(" | ")}`;
17
+ export interface RoadmapArgs {
18
+ op: "hub_roadmap_list" | "hub_roadmap_show" | "hub_roadmap_edit" | "hub_roadmap_unplaced" | "hub_roadmap_triage" | "roadmap_import_github";
19
+ args: Record<string, unknown>;
20
+ json: boolean;
21
+ }
22
+ /** R3 commands: their flags are not milestone fields, so they are parsed apart from new/edit. */
23
+ const R3_COMMANDS = ["unplaced", "triage", "accept", "reject", "import-github"];
24
+ const R3_JSON = ["unplaced", "triage", "import-github"];
25
+ const fieldFlags = ["title", "outcome", "horizon", "order", "target", "parent"];
26
+ const usage = (message: string): never => { throw new Error(`${message}; ${ROADMAP_USAGE}`); };
27
+ function integer(value: string | undefined, zero = false): number {
28
+ if (value === undefined || !/^(0|[1-9][0-9]*)$/.test(value)) return usage("roadmap needs a whole-number operand");
29
+ return zero ? milestoneRevision(Number(value)) : milestoneId(Number(value));
30
+ }
31
+
32
+ function parseR3(command: string, rest: readonly string[], jsonSeen: boolean): RoadmapArgs {
33
+ let json = jsonSeen, list = false, apply = false, repo: string | undefined;
34
+ const operands: string[] = [];
35
+ for (let at = 0; at < rest.length; at++) {
36
+ const word = rest[at]!;
37
+ if (word === "--json") { if (json) return usage("duplicate roadmap --json flag"); json = true; continue; }
38
+ if (word === "--list" && command === "triage") { if (list) return usage("duplicate roadmap --list flag"); list = true; continue; }
39
+ if (word === "--apply" && command === "import-github") { if (apply) return usage("duplicate roadmap --apply flag"); apply = true; continue; }
40
+ if ((word === "--repo" || word.startsWith("--repo=")) && ["unplaced", "triage", "import-github"].includes(command)) {
41
+ if (repo !== undefined) return usage("duplicate roadmap --repo option");
42
+ const value = word === "--repo" ? rest[++at] : word.slice("--repo=".length);
43
+ if (value === undefined) return usage("roadmap --repo needs owner/name");
44
+ try { repo = githubRepo(value); } catch { return usage("roadmap --repo needs owner/name"); }
45
+ continue;
46
+ }
47
+ if (word.startsWith("-")) return usage("unknown roadmap option");
48
+ operands.push(word);
49
+ }
50
+ if (json && !R3_JSON.includes(command)) return usage(`roadmap ${command} has no --json form`);
51
+ if (command === "accept" || command === "reject") {
52
+ if (operands.length !== 1) return usage(`roadmap ${command} needs one suggestion id`);
53
+ return { op: "hub_roadmap_edit", args: { op: command, suggestion: integer(operands[0]) }, json };
54
+ }
55
+ if (operands.length) return usage(`roadmap ${command} takes no operands`);
56
+ const base = repo === undefined ? {} : { repo };
57
+ if (command === "unplaced") return { op: "hub_roadmap_unplaced", args: base, json };
58
+ if (command === "triage") return { op: "hub_roadmap_triage", args: { ...base, ...(list ? { list: true } : {}) }, json };
59
+ return { op: "roadmap_import_github", args: { ...base, ...(apply ? { apply: true } : {}) }, json };
60
+ }
61
+
62
+ /** Closed argv only. Values consumed by a text flag remain literal text, including '--json'. */
63
+ export function parseRoadmapArgs(argv: readonly string[]): RoadmapArgs {
64
+ let index = 0, json = false;
65
+ if (argv[index] === "--json") { json = true; index++; }
66
+ const command = argv[index] ?? "list";
67
+ if (argv[index] !== undefined) index++;
68
+ if (!["list", "show", "new", "edit", "link", "unlink", "order", "state", ...R3_COMMANDS].includes(command)) return usage("unknown roadmap command");
69
+ if (R3_COMMANDS.includes(command)) return parseR3(command, argv.slice(index), json);
70
+ const operands: string[] = [], flags = new Map<string, string>();
71
+ for (; index < argv.length; index++) {
72
+ const word = argv[index]!;
73
+ if (word === "--json") {
74
+ if (json) return usage("duplicate roadmap --json flag");
75
+ json = true; continue;
76
+ }
77
+ if (word.startsWith("--")) {
78
+ const equal = word.indexOf("="), name = word.slice(2, equal < 0 ? undefined : equal);
79
+ if (command !== "new" && command !== "edit" || ![...fieldFlags, ...(command === "edit" ? ["revision"] : [])].includes(name)) return usage("unknown roadmap option");
80
+ if (flags.has(name)) return usage("duplicate roadmap field option");
81
+ const value = equal < 0 ? argv[++index] : word.slice(equal + 1);
82
+ if (value === undefined) return usage("roadmap field option needs a value");
83
+ flags.set(name, value); continue;
84
+ }
85
+ if (word.startsWith("-")) return usage("unknown roadmap option");
86
+ operands.push(word);
87
+ }
88
+ if (json && command !== "list" && command !== "show") return usage("roadmap --json is available on list and show only");
89
+ if (command === "list") {
90
+ if (operands.length) return usage("roadmap list takes no operands");
91
+ return { op: "hub_roadmap_list", args: {}, json };
92
+ }
93
+ if (command === "show") {
94
+ if (operands.length !== 1) return usage("roadmap show needs one id");
95
+ return { op: "hub_roadmap_show", args: { id: integer(operands[0]) }, json };
96
+ }
97
+ if (command === "new" || command === "edit") {
98
+ if (operands.length !== (command === "new" ? 0 : 1)) return usage("roadmap new takes flags; edit needs one id");
99
+ const fields: Record<string, unknown> = {};
100
+ for (const name of fieldFlags) if (flags.has(name)) {
101
+ const value = flags.get(name)!;
102
+ fields[name] = name === "order" ? integer(value, true) : name === "parent" ? value === "none" ? null : integer(value) : name === "target" && value === "none" ? null : value;
103
+ }
104
+ // Validate without substituting normalized values: free text is passed exactly as supplied.
105
+ if (command === "new") parseMilestoneInput(fields); else parseMilestonePatch(fields);
106
+ const args: Record<string, unknown> = { op: command, fields };
107
+ if (command === "edit") {
108
+ if (!flags.has("revision")) return usage("roadmap edit requires --revision from roadmap show");
109
+ args.id = integer(operands[0]); args.revision = integer(flags.get("revision"), true);
110
+ }
111
+ return { op: "hub_roadmap_edit", args, json };
112
+ }
113
+ const required = command === "link" || command === "unlink" ? 3 : 2;
114
+ if (operands.length !== required) return usage("roadmap operation has missing or unused operands");
115
+ const id = integer(operands[0]);
116
+ if (command === "link" || command === "unlink") {
117
+ const kind = operands[1] as MilestoneLinkKind;
118
+ return { op: "hub_roadmap_edit", args: { op: command, id, kind, ref: milestoneLinkRef(kind, operands[2]) }, json };
119
+ }
120
+ if (command === "order") return { op: "hub_roadmap_edit", args: { op: command, id, order: integer(operands[1], true) }, json };
121
+ const fields = parseMilestonePatch({ state: operands[1] });
122
+ return { op: "hub_roadmap_edit", args: { op: command, id, state: fields.state }, json };
123
+ }
124
+
125
+ type Row = Record<string, unknown>;
126
+ const row = (value: unknown): Row => value !== null && typeof value === "object" && !Array.isArray(value) ? value as Row : {};
127
+ const list = (value: unknown): unknown[] => Array.isArray(value) ? value : [];
128
+ const text = (value: unknown): string => typeof value === "string" || typeof value === "number" ? terminalText(value) : "unknown";
129
+ const count = (value: unknown): string => typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? String(value) : "unknown";
130
+ const ratio = (value: unknown, field: string): string => { const r = row(value); return `${count(r[field])}/${count(r.total)}`; };
131
+
132
+ /** Person-first plain text; rendering never reads the terminal, environment, files or network. */
133
+ export function renderRoadmap(input: unknown, width = 80): string {
134
+ if (typeof input === "string") {
135
+ try { input = JSON.parse(input); }
136
+ catch { return terminalText(input); }
137
+ }
138
+ const columns = Number.isFinite(width) && width >= 1 ? Math.floor(width) : 80;
139
+ const view = row(input), lines: string[] = [];
140
+ const add = (value: string) => { lines.push(...wrap(value, columns)); };
141
+ const milestone = (value: unknown) => {
142
+ const m = row(value), progress = row(m.rollup), specs = row(progress.specs), issues = row(progress.issues), releases = row(progress.releases);
143
+ add(`Milestone ${count(m.id)}: ${text(m.title)}`);
144
+ add(` ${text(m.state)} | ${text(m.horizon)} | order ${count(m.order)} | revision ${count(m.revision)}`);
145
+ add(` Outcome: ${text(m.outcome)}`);
146
+ if (m.target !== null && m.target !== undefined) add(` Target: ${text(m.target)}`);
147
+ if (m.parent !== null && m.parent !== undefined) add(` Parent: ${count(m.parent)}`);
148
+ add(` Tasks approved: ${ratio(progress.tasks, "approved")}; issues closed: ${ratio(issues, "closed")} (unknown ${count(issues.unknown)})`);
149
+ add(` Specs: fresh ${count(specs.fresh)}, stale ${count(specs.stale)}, unverified ${count(specs.unverified)}, unknown ${count(specs.unknown)}; total ${count(specs.total)}`);
150
+ add(` Releases shipped: ${ratio(releases, "shipped")} (unknown ${count(releases.unknown)})`);
151
+ if (m.withheld !== undefined) add(` Private tasks withheld: ${count(m.withheld)}`);
152
+ const tree = row(m.tree);
153
+ if (m.tree !== undefined && Number(tree.children) > 0) add(` With children (${count(tree.children)}): tasks ${ratio(tree.tasks, "approved")}, issues ${ratio(tree.issues, "closed")}, releases ${ratio(tree.releases, "shipped")}`);
154
+ const ready = row(m.readyToClose);
155
+ if (ready.ready === true) add(" Ready to close: every linked item is closed or approved. Only the person records done: ahub roadmap state " + count(m.id) + " done");
156
+ else if (m.readyToClose !== undefined && list(ready.reasons).length) add(` Not ready to close: ${list(ready.reasons).map(text).join("; ")}`);
157
+ for (const value of list(m.links)) {
158
+ const link = row(value); add(` Link ${text(link.kind)}: ${text(link.ref)}`);
159
+ }
160
+ for (const value of list(m.tasks)) {
161
+ const task = row(value), placement = row(task.placement);
162
+ const issue = /^(.+)#([1-9][0-9]*)$/.exec(text(placement.issue));
163
+ const basis = placement.rule === "source-issue" || placement.rule === "inherited" ? issue ? `inherited from #${issue[2]} (${issue[1]})` : `inherited from ${text(placement.issue)}` : placement.rule === "explicit" ? "explicit link" : "placement unknown";
164
+ add(` Task ${count(task.id)}: ${text(task.title)} (${text(task.state)}; ${basis})`);
165
+ }
166
+ };
167
+ const names = (rows: unknown[], one: (value: Row) => string) => { for (const value of rows) add(one(row(value))); };
168
+ if (Array.isArray(view.issues) && Array.isArray(view.tasks) && Array.isArray(view.specs) && view.privateTasks !== undefined) {
169
+ add(`Unplaced work${view.repo ? ` (${text(view.repo)})` : ""}`);
170
+ if (view.partial === true) add("Partial: the GitHub read stopped early or a list was cut, so these lists are a lower bound.");
171
+ for (const name of list(view.unavailable)) add(`Unavailable: ${text(name)} could not be read, so none are listed.`);
172
+ add(`Issues (${view.issues.length}${Number(row(view.more).issues) > 0 ? `, ${count(row(view.more).issues)} more` : ""})`);
173
+ names(view.issues, issue => ` ${text(issue.ref)}: ${text(issue.title)}\n why: ${text(issue.reason)}`);
174
+ add(`Tasks (${view.tasks.length}${Number(row(view.more).tasks) > 0 ? `, ${count(row(view.more).tasks)} more` : ""})`);
175
+ names(view.tasks, task => ` #${count(task.id)} ${text(task.title)} (${text(task.state)})\n why: ${text(task.reason)}`);
176
+ add(`Specs (${view.specs.length}${Number(row(view.more).specs) > 0 ? `, ${count(row(view.more).specs)} more` : ""})`);
177
+ names(view.specs, spec => ` ${text(spec.id)}: ${text(spec.title)} (${text(spec.status)})\n why: ${text(spec.reason)}`);
178
+ add(`Private tasks counted, not listed: ${count(view.privateTasks)}`);
179
+ return lines.join("\n");
180
+ }
181
+ if (Array.isArray(view.suggestions)) {
182
+ add(`Triage suggestions (${view.suggestions.length})`);
183
+ if (view.unavailable) add(`Triage unavailable: ${text(view.unavailable)}`);
184
+ if (view.partial === true) add("Partial: more unplaced work remains; run triage again after deciding these.");
185
+ if (view.asked !== undefined) add(`Asked about ${count(view.asked)} item${view.asked === 1 ? "" : "s"}; ${count(view.dropped)} model answer${view.dropped === 1 ? "" : "s"} dropped as unsupported.`);
186
+ names(view.suggestions, s => {
187
+ const proposal = row(s.proposal), target = s.milestone === null || s.milestone === undefined ? `new milestone: ${text(proposal.title)}` : `milestone ${count(s.milestone)}`;
188
+ return ` #${count(s.id)} ${text(s.kind)} ${text(s.ref)} -> ${target}\n item words: "${text(s.citeItem)}"${s.citeMilestone ? `\n milestone words: "${text(s.citeMilestone)}"` : ""}\n apply: ahub roadmap accept ${count(s.id)} drop: ahub roadmap reject ${count(s.id)}`;
189
+ });
190
+ if (!view.suggestions.length) add("Nothing pending. Nothing is linked until you run ahub roadmap accept <id>.");
191
+ return lines.join("\n");
192
+ }
193
+ if (view.suggestion !== undefined && typeof view.suggestion === "object") {
194
+ const s = row(view.suggestion);
195
+ add(`Suggestion ${count(s.id)} ${text(s.state)}: ${text(s.kind)} ${text(s.ref)}`);
196
+ if (view.milestone !== undefined) milestone(view.milestone);
197
+ return lines.join("\n");
198
+ }
199
+ if (Array.isArray(view.milestones) && view.apply !== undefined) {
200
+ add(`GitHub milestones (${text(view.repo)}): ${view.apply === true ? "applied" : "dry run, nothing written; add --apply to create them"}`);
201
+ if (view.partial === true) add("Partial: the GitHub read stopped early, so this list is a lower bound.");
202
+ names(view.milestones, m => ` GitHub #${count(m.number)} ${text(m.title)}: ${m.action === "create" ? "would create" : "already imported as"}${m.milestone ? ` milestone ${count(m.milestone)}` : ""}; ${list(m.issues).length} issue${list(m.issues).length === 1 ? "" : "s"}, ${count(m.newLinks)} new link${m.newLinks === 1 ? "" : "s"}`);
203
+ if (view.apply === true) add(`Created ${count(view.created)} milestone${view.created === 1 ? "" : "s"}, linked ${count(view.linked)} issue${view.linked === 1 ? "" : "s"}.`);
204
+ if (Number(view.withheld) > 0) add(`Withheld ${count(view.withheld)} milestone${view.withheld === 1 ? "" : "s"} whose text was not cleared for public planning.`);
205
+ return lines.join("\n");
206
+ }
207
+ if (Array.isArray(view.milestones)) {
208
+ add(`Roadmap (${view.milestones.length} milestones)`);
209
+ if (!view.milestones.length) add("No milestones recorded.");
210
+ for (const item of view.milestones) { lines.push(""); milestone(item); }
211
+ } else if (view.id !== undefined) milestone(view);
212
+ else if (view.milestone !== undefined) milestone(view.milestone);
213
+ else add("Roadmap unavailable: the hub returned no readable milestone view.");
214
+ return lines.join("\n");
215
+ }
@@ -1,27 +1,17 @@
1
1
  // macOS script(1) requires a terminal on its own stdin, including when its child gets a PTY.
2
2
  // Keep a real PTY in this owned bridge instead; the outer Node child remains tracked by stopOwnedProcess.
3
- import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
4
- import { tmpdir } from "node:os";
5
- import { join } from "node:path";
6
3
 
7
4
  /**
8
- * #560: Bun up to 1.4.3 can hang for good inside `Bun.spawn({ terminal })` on macOS when the child writes and starts exiting before the call returns (oven-sh/bun#45300, fixed in 1.4.4): the
9
- * event loop thread blocks in wait4 while the exiting session leader waits for that same thread to drain its pty. Measured here with a bare Bun script and no agent-hub code: 26 of 96 runs hung
10
- * at 12 in parallel on 1.4.3 and 0 of 180 on 1.4.4. The child therefore starts behind a gate: a shell that waits for a file the bridge writes right after `Bun.spawn` has returned, then `exec`s the
11
- * real command (same pid, same session, same terminal). The wait has no bound of its own: a bridge that dies before it opens the gate closes the pty, which hangs the shell up (the trap below), and a bridge
12
- * that is alive but never opens it is a hung bridge, which `runPty` stops with its group.
13
- * ponytail: ceiling and upgrade path. The gate exists only because of oven-sh/bun#45300 on Bun up to 1.4.3 (this repo pins 1.4.2 in `.bun-version`); the upgrade path is to delete GATE_SCRIPT, `gate` and `gateDir` once the pinned Bun is 1.4.4 or newer, which is its own task because it
14
- * touches CI and every OS leg. The parent-death stop below stays whatever the Bun version: an orphaned bridge is this repository's bug, not Bun's. The gate costs about one shell start (a few ms).
5
+ * #560: the bridge used to hold its child behind a shell until `Bun.spawn` had returned, because Bun up to 1.4.3 could hang for good inside `Bun.spawn({ terminal })` on macOS when the child wrote and
6
+ * started exiting before the call returned (oven-sh/bun#45300, fixed in 1.4.4; 26 of 96 runs hung at 12 in parallel on 1.4.3 and 0 of 180 on 1.4.4). The repository pins Bun 1.4.4 now (`.bun-version`),
7
+ * so the child starts directly. The parent-death stop below stays whatever the Bun version: an orphaned bridge is this repository's bug, not Bun's.
15
8
  */
16
- // The shell removes its own gate (file, then directory) once released and when it is hung up or terminated (a bridge killed with SIGKILL runs no cleanup, and the pty closing
17
- // sends the shell SIGHUP), so no path leaves a directory behind. `exec` resets the traps for the real command.
18
- const GATE_SCRIPT = 'd=${0%/*}; trap "rm -f \\"$0\\"; rmdir \\"$d\\" 2>/dev/null; exit 125" HUP TERM INT; while [ ! -e "$0" ]; do sleep 0.01; done; rm -f "$0"; rmdir "$d" 2>/dev/null; exec "$@"';
19
9
  /** A bridge whose caller died is stopped instead of running on: its child holds a terminal nobody reads and, under launchd, nothing else would ever stop it. */
20
10
  const PARENT_POLL_MS = 250;
21
11
  const PARENT_TERM_GRACE_MS = 1_000;
22
12
  const PARENT_HARD_EXIT_MS = 3_000;
23
13
 
24
- // The caller is whoever started this bridge, read before anything that can take time: a caller that dies while `Bun.spawn` runs (the window #45300 widens) has already reparented this process by the
14
+ // The caller is whoever started this bridge, read before anything that can take time: a caller that dies while `Bun.spawn` runs has already reparented this process by the
25
15
  // time the call returns, and a parent read after it would be launchd and never change.
26
16
  const parent = process.ppid;
27
17
  const callerGone = (): boolean => process.ppid !== parent;
@@ -31,11 +21,9 @@ if (!argv.length) {
31
21
  } else {
32
22
  let streamClosed!: () => void;
33
23
  const eof = new Promise<void>(resolve => { streamClosed = resolve; });
34
- const gateDir = process.platform === "darwin" ? mkdtempSync(join(tmpdir(), "ahub-pty-gate-")) : undefined;
35
- const gate = gateDir ? join(gateDir, "open") : undefined;
36
24
  let watch: ReturnType<typeof setInterval> | undefined;
37
25
  try {
38
- const child = Bun.spawn(gate ? ["/bin/sh", "-c", GATE_SCRIPT, gate, ...argv] : argv, {
26
+ const child = Bun.spawn(argv, {
39
27
  cwd: process.cwd(), env: process.env,
40
28
  terminal: {
41
29
  cols: 120, rows: 40, name: "xterm-256color",
@@ -52,13 +40,9 @@ if (!argv.length) {
52
40
  setTimeout(() => { try { child.kill("SIGKILL"); } catch { /* already gone */ } }, PARENT_TERM_GRACE_MS).unref();
53
41
  setTimeout(() => process.exit(129), PARENT_HARD_EXIT_MS).unref();
54
42
  };
55
- // A caller that died while Bun.spawn ran never gets its command run: the gate stays shut and the gate shell takes the SIGTERM (its trap removes the gate and exits).
56
- // Abandoning once is enough: the interval below exists only while the caller is still there, and clears itself the first time it is not.
43
+ // A caller that died while Bun.spawn ran has its child stopped at once. Abandoning once is enough: the interval below exists only while the caller is still there, and clears itself the first time it is not.
57
44
  if (callerGone()) abandon();
58
- else {
59
- if (gate) writeFileSync(gate, "");
60
- watch = setInterval(() => { if (callerGone()) abandon(); }, PARENT_POLL_MS);
61
- }
45
+ else watch = setInterval(() => { if (callerGone()) abandon(); }, PARENT_POLL_MS);
62
46
  try {
63
47
  const code = await child.exited;
64
48
  // Drain the PTY before closing it; a descendant holding a slave cannot make the bridge wait forever.
@@ -76,7 +60,6 @@ if (!argv.length) {
76
60
  process.exitCode = 125;
77
61
  } finally {
78
62
  if (watch) clearInterval(watch);
79
- if (gateDir) rmSync(gateDir, { recursive: true, force: true });
80
63
  }
81
64
  }
82
65
  export {};
@@ -104,6 +104,8 @@ function taskBlock(task: any, columns: number | undefined, now: number, detail:
104
104
  ...pair("class", dash(task?.class), columns, w, undefined, " "), ...pair("owner", taskHolderText(task, "owner"), columns, w, undefined, " "), ...pair("reviewer", taskHolderText(task, "reviewer"), columns, w, undefined, " "));
105
105
  if (task?.planner !== undefined) out.push(...pair("planner", taskHolderText(task, "planner"), columns, w, undefined, " "));
106
106
  if (task?.reserved) out.push(...pair("reserved", task.reserved, columns, w, undefined, " "));
107
+ // #1454: a recorded wait, with whether it has passed: a passed one means the idle ladder restarts, so it reads as attention.
108
+ if (task?.wait && typeof task.wait.until === "number") out.push(...pair("waiting", `${task.wait.passed ? "passed " : "until "}${new Date(task.wait.until).toISOString()}${task.wait.by ? `, set by ${task.wait.by}` : ""}${task.wait.reason ? `: ${task.wait.reason}` : ""}`, columns, w, task.wait.passed ? "attention" : undefined, " "));
107
109
  if (task?.handoffOrigin) out.push(...pair("from", `project ${task.handoffOrigin.projectId}, handed off by ${task.handoffOrigin.peer}${typeof task.handoffOrigin.task === "number" ? ` (their task #${task.handoffOrigin.task})` : ""}`, columns, w, "attention", " "));
108
110
  out.push(...pair("after", ids(task?.deps), columns, w, undefined, " "));
109
111
  if (typeof task?.release === "number") out.push(...pair("release", `#${task.release}`, columns, w, undefined, " "));
@@ -177,7 +179,7 @@ export function renderBacklogResult(op: keyof typeof BACKLOG_HEAD, result: unkno
177
179
  return out;
178
180
  }
179
181
 
180
- const GROOM_TEXT: Record<string, string> = { "text-dependency": "text names a dependency the card does not declare", overlap: "overlaps other open work", duplicate: "may duplicate another card", "over-wip": "its owner is over the WIP limit", stale: "has not moved for a long time", superseded: "was superseded", blocked: "cannot be routed", "closed-issue": "its issue is closed" };
182
+ const GROOM_TEXT: Record<string, string> = { "text-dependency": "text names a dependency the card does not declare", overlap: "overlaps other open work", duplicate: "may duplicate another card", "over-wip": "its owner is over the WIP limit", stale: "has not moved for a long time", superseded: "was superseded", blocked: "cannot be routed", "closed-issue": "its issue is closed", "wait-passed": "its recorded wait has passed, so the idle sweep runs again: record a new wait or check the owner" };
181
183
  /** `ahub backlog groom`: what the planner would look at, one line per finding. */
182
184
  export function renderGroom(digest: unknown, columns?: number, _now = Date.now()): Span[][] {
183
185
  const d = digest as any;
@@ -1,11 +1,11 @@
1
1
  import { recoveryPresentationFlag } from "./recovery-presentation-options.ts";
2
- import { resolveColor } from "./console-state.ts";
2
+ import { resolveColor, type ColorEnv } from "./console-state.ts";
3
3
  import type { RecoveryPresentationOptions } from "./upgrade-presentation.ts";
4
4
 
5
5
  /** Presentation flags never consume another option's audit, version or peer value. */
6
6
  export function readRecoveryPresentationFlags(
7
7
  argv: readonly string[],
8
- terminal: { isTTY: boolean; columns?: number; TERM?: string; NO_COLOR?: string },
8
+ terminal: ColorEnv & { columns?: number },
9
9
  now: () => number = Date.now,
10
10
  ): { args: string[]; flags: string[]; json: boolean; options: RecoveryPresentationOptions } {
11
11
  const args: string[] = [], flags: string[] = [];