@staix/agent-hub 0.48.3 → 0.49.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 (58) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +1 -1
  3. package/docs/agent-notes/daemon.md +2 -2
  4. package/docs/agent-notes/tasks.md +1 -1
  5. package/docs/design/adapters.md +4 -7
  6. package/docs/design/agent-hub-architecture.md +1 -1
  7. package/docs/design/agent-hub.md +1 -1
  8. package/docs/design/bus.md +2 -2
  9. package/docs/design/cli-output-inventory.md +39 -38
  10. package/docs/design/cli-output.md +7 -3
  11. package/docs/design/guidance-experiments.md +3 -1
  12. package/docs/design/guidance-probes.md +33 -31
  13. package/docs/design/model-routes.md +11 -14
  14. package/docs/design/roadmap.md +10 -9
  15. package/docs/design/supervision.md +6 -6
  16. package/docs/design/task-board.md +2 -2
  17. package/docs/dogfood.md +1 -1
  18. package/docs/operations.md +12 -7
  19. package/docs/quickstart.md +19 -1
  20. package/docs/roadmap.json +519 -1
  21. package/docs/roadmap.md +94 -0
  22. package/docs/security.md +3 -1
  23. package/docs/verification/2026-11-26-compat-pi-1.6.1.md +28 -0
  24. package/docs/verification/2026-11-27-0.48.4.md +37 -0
  25. package/docs/verification/2026-11-28-0.49.0.md +53 -0
  26. package/docs/verified.json +19 -19
  27. package/package.json +1 -1
  28. package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
  29. package/plugins/agent-hub/kimi-hook.js +29 -4
  30. package/plugins/agent-hub/server.js +34 -5
  31. package/src/adapters/channel-peer.ts +5 -2
  32. package/src/adapters/claude-channel.ts +1 -0
  33. package/src/adapters/compat.ts +4 -4
  34. package/src/adapters/definitions/native-cli-entry-claude.ts +22 -1
  35. package/src/cli/agents-output.ts +13 -0
  36. package/src/cli/agents.ts +16 -7
  37. package/src/cli/answer-output.ts +67 -0
  38. package/src/cli/broker.ts +9 -2
  39. package/src/cli/launch.ts +1 -1
  40. package/src/cli/main.ts +96 -127
  41. package/src/cli/recovery-package.ts +78 -26
  42. package/src/cli/reset-output.ts +50 -0
  43. package/src/cli/sdlc-output.ts +57 -0
  44. package/src/cli/settings-output.ts +80 -0
  45. package/src/hub/check-runner.ts +7 -3
  46. package/src/hub/claude-launch-proof.ts +12 -2
  47. package/src/hub/claude-state.ts +3 -0
  48. package/src/hub/control-client.ts +2 -0
  49. package/src/hub/daemon.ts +102 -40
  50. package/src/hub/memory-profile.ts +12 -1
  51. package/src/hub/roadmap-export.ts +12 -9
  52. package/src/hub/roadmap-issue-states.ts +35 -0
  53. package/src/hub/runtime-capture-prune.ts +21 -6
  54. package/src/hub/runtime-package-assets.ts +6 -0
  55. package/src/hub/supervision-proposals.ts +3 -3
  56. package/src/hub/supervision-rules.ts +2 -2
  57. package/src/hub/task-sweep.ts +1 -1
  58. package/src/hub/tasks.ts +37 -20
package/src/cli/main.ts CHANGED
@@ -42,6 +42,7 @@ import { renderHandoffReceipt, renderHandoffs } from "./handoff-output.ts";
42
42
  import { parseHandoffArgs } from "./handoff-args.ts";
43
43
  import { terminalText } from "./console-state.ts";
44
44
  import { parseSettingsEditArgs, runSettingsEdit, SETTINGS_EDIT_USAGE } from "./settings-edit.ts";
45
+ import { renderSdlcSetting, renderSettingsConfirmation, renderSettingsPreview, renderSettingsReceipt, renderSettingsRejected, renderSettingsRows } from "./settings-output.ts";
45
46
  import { autonomyEnvironment, runAutonomy } from "./autonomy.ts";
46
47
  import { readAutonomyDefaults, writeAutonomyDefaults } from "../hub/autonomy-defaults.ts";
47
48
  import { inheritMachineAutonomy, prepareAutonomyProject, runAllProjectAutonomy, type PreparedAutonomyProject } from "./autonomy-projects.ts";
@@ -62,7 +63,7 @@ import { verifiedJcodeCommand } from "../adapters/jcode.ts";
62
63
  import { configureJcodeMcp, jcodeExtraMcpServers, splitJcodeMcpServers } from "./jcode-mcp.ts";
63
64
  import { qwenSessionId } from "../hub/crash.ts";
64
65
  import { isPermissionMode } from "../hub/permission-mode.ts";
65
- import { parseSettingText, settingDef, settingText, undoableDef, type SettingRow } from "../hub/settings.ts";
66
+ import { parseSettingText, settingDef, undoableDef, type SettingRow } from "../hub/settings.ts";
66
67
  import { startModeOf } from "../hub/start-mode.ts";
67
68
  import { rolesRow } from "./role-doctor.ts";
68
69
  import { classListRow, currentRouting, loadRouting, OVERLAY_FILE, parseOverlay, parseRouting, routingText, type Routing, type RoutingOverlay } from "../hub/routing.ts";
@@ -150,9 +151,11 @@ import { outputWidth, renderRuntimeModels, renderRoster, renderRoles, rolesView,
150
151
  import { renderHelp, configuredAcpHelp, guidanceProbeUsage, listsSubcommand, subcommandUsage } from "./help.ts";
151
152
  import { renderBacklogResult, renderGroom, renderReleaseChange, renderReleaseList, renderReleaseNew, renderReleaseShow, renderTaskCancel, renderTaskShow } from "./task-output.ts";
152
153
  import { SURVEY_FOCUS } from "../hub/advisor-survey.ts";
153
- import { renderAuthorization, renderSdlcCosts, renderSdlcExplain, renderSdlcMerge, renderSdlcMetrics, renderSdlcQueue, renderSdlcRelease, renderSdlcStatus, renderSdlcAudit, renderSdlcConfiguration, renderSdlcSurvey } from "./sdlc-output.ts";
154
+ import { renderAuthorization, renderSdlcCosts, renderSdlcExplain, renderSdlcMerge, renderSdlcMetrics, renderSdlcQueue, renderSdlcRelease, renderSdlcStatus, renderSdlcAudit, renderSdlcConfiguration, renderSdlcSurvey, renderSdlcReceipt, renderSdlcReadback, renderSdlcTrain } from "./sdlc-output.ts";
154
155
  import { renderTailEvent } from "./tail-render.ts";
155
156
  import { archiveProblem, archiveState, damagedState, failureText, MANIFEST, planReset, resetLines, resetRuntime, startState, type ResetPlan } from "./reset.ts";
157
+ import { RESET_KEPT, RESET_MEMORY, renderLifecycleReceipt, renderResetPlan, renderUndoPlan } from "./reset-output.ts";
158
+ import { renderAnswerReceipt, renderAskAnswer, renderQuestions, renderResults } from "./answer-output.ts";
156
159
 
157
160
  /** `--since 7d|24h|<iso>` for export and report; everything when absent. */
158
161
  const since = (): number => {
@@ -414,7 +417,8 @@ const lifecycle = { inspectProject, startProject, stopProject };
414
417
  const connect = async (timeoutMs = 3000) => {
415
418
  assertDelegatedAuditConsumer();
416
419
  if (delegatedAuditHub && !delegatedConnectionTaken) { delegatedConnectionTaken = true; return delegatedAuditHub; }
417
- return ControlClient.connect(stateDir, identity.role === "tools" ? { role: "tools", peer: identity.peer, projectRoot: cwd }
420
+ return ControlClient.connect(stateDir, identity.role === "tools" ? { role: "tools", peer: identity.peer, projectRoot: cwd,
421
+ ...(process.env.CLAUDECODE === "1" && process.env.CLAUDE_CODE_SESSION_ID ? { claudeSessionId: process.env.CLAUDE_CODE_SESSION_ID } : {}) }
418
422
  : { role: "console", projectRoot: cwd, ...(delegatedAuditHub ? { instanceId: delegatedAuditHub.instanceId } : {}) }, timeoutMs);
419
423
  };
420
424
 
@@ -989,7 +993,13 @@ const consoleInstalled = () => installedVersions(join(import.meta.dir, "..", "..
989
993
  const GOAL_NEW_VALUE_FLAGS = ["--milestone", "--depends"], GOAL_NEW_FLAGS = [...GOAL_NEW_VALUE_FLAGS, "--shared", "--json"];
990
994
  /** `ahub doctor` exits 1 on a failed row; `ahub setup` runs the same function and keeps its own exit behavior. */
991
995
  let doctorSetsExit = true;
992
- const commands: Record<string, () => Promise<void> | void> = {
996
+ type SdlcReceiptOutput = (title: string, ...lines: string[]) => void;
997
+ function printSdlcReceipt(title: string, ...lines: string[]): void {
998
+ const display = outputOptions([]);
999
+ printOutput(renderSdlcReceipt({ title, lines }, display.columns, Date.now(), asciiMarkers(process.env, process.argv.includes("--ascii"))), display.color);
1000
+ }
1001
+
1002
+ const commands: Record<string, (receiptOutput?: SdlcReceiptOutput) => Promise<void> | void> = {
993
1003
  upgrade: () => upgrade("upgrade"),
994
1004
  restart: () => upgrade("restart"),
995
1005
  recovery: async () => {
@@ -2096,10 +2106,13 @@ const commands: Record<string, () => Promise<void> | void> = {
2096
2106
  } finally { boardHub.close(); }
2097
2107
  },
2098
2108
 
2099
- sdlc: async () => {
2109
+ sdlc: async (receiptOutput) => {
2100
2110
  const args = sdlcOperands(), present = SDLC_READ.includes(args[0] ?? "") ? outputOptions() : undefined;
2101
2111
  /** The human form (#814). Each site keeps its own `if (present.json) console.log(JSON.stringify(...))`, so the JSON branch stays visible to the guard test. */
2102
- const human = (render: (data: any, columns?: number, now?: number, ascii?: boolean) => Span[][], data: unknown) => printOutput(render(data, present!.columns, Date.now(), asciiMarkers(process.env, process.argv.includes("--ascii"))), present!.color);
2112
+ const human = (render: Parameters<typeof showToolText>[0], data: unknown, display = present ?? outputOptions([])) =>
2113
+ printOutput(render(data, display.columns, Date.now(), asciiMarkers(process.env, process.argv.includes("--ascii"))), display.color);
2114
+ const receipt = (title: string, ...lines: string[]) => human(renderSdlcReceipt, { title, lines });
2115
+ const toolReport = async (render: Parameters<typeof showToolText>[0], result: Promise<string>) => showToolText(render, await result, outputOptions([]));
2103
2116
  const sub = args[0], id = args[1] === undefined ? undefined : Number(args[1]);
2104
2117
  if (sub === "configure") {
2105
2118
  const parsed = takeFlags(args.slice(1), ["--mode", "--required-checks"], []);
@@ -2156,7 +2169,7 @@ const commands: Record<string, () => Promise<void> | void> = {
2156
2169
  hub = await connect();
2157
2170
  const reply = await hub.request(request, 30_000);
2158
2171
  if (!reply.ok) fail(reply.error ?? "release authorization refused");
2159
- if (original) process.stdout.write(original); else console.log("release authorization matched");
2172
+ if (original) process.stdout.write(original); else receipt("Release guard", "release authorization matched");
2160
2173
  } catch { fail("release authorization unavailable; the daemon must be reachable with a matching person approval"); }
2161
2174
  finally { hub?.close(); }
2162
2175
  return;
@@ -2197,7 +2210,7 @@ const commands: Record<string, () => Promise<void> | void> = {
2197
2210
  const reply = await hub.request({ t: "sdlc", op: "audit-start", ...(flags.one["--profile"] !== undefined ? { profile: flags.one["--profile"] } : {}), ...(flags.one["--since"] !== undefined ? { since: flags.one["--since"] } : {}) }, 60_000);
2198
2211
  if (!reply.ok) fail(/unknown SDLC operation|does not know/.test(String(reply.error)) ? `${reply.error}; the running hub does not support security audits; upgrade agent-hub and run ahub restart before retrying` : reply.error);
2199
2212
  if (present!.json) console.log(JSON.stringify({ task: reply.task, audit: reply.audit, units: reply.units, planned: reply.planned, carried: reply.carried, partial: reply.partial, ref: reply.ref }, null, 2));
2200
- else console.log(`task #${reply.task}: security audit ${reply.audit} started at ${String(reply.ref).slice(0, 12)}, ${reply.units} units (${reply.planned} planned, ${reply.carried} carried over)${reply.partial ? ", partial" : ""}`);
2213
+ else receipt("Audit start", `task #${reply.task}: security audit ${reply.audit} started at ${String(reply.ref).slice(0, 12)}, ${reply.units} units (${reply.planned} planned, ${reply.carried} carried over)${reply.partial ? ", partial" : ""}`);
2201
2214
  } finally { hub.close(); }
2202
2215
  return;
2203
2216
  }
@@ -2225,21 +2238,21 @@ const commands: Record<string, () => Promise<void> | void> = {
2225
2238
  if (sub === "train") {
2226
2239
  const operation = args[1], releaseId = Number(args[2]), revision = Number(args[3]);
2227
2240
  if (!Number.isSafeInteger(releaseId) || releaseId <= 0) fail("usage: ahub sdlc train report|configure|cut <release-id> [revision] [configuration-json]");
2228
- if (operation === "report" && args.length === 3) return console.log(await taskOp("hub_release_report", { id: releaseId }));
2241
+ if (operation === "report" && args.length === 3) return toolReport(renderSdlcTrain, taskOp("hub_release_report", { id: releaseId }));
2229
2242
  if (!Number.isSafeInteger(revision) || revision < 0) fail("train mutation requires its current revision");
2230
- if (operation === "cut" && args.length === 4) return console.log(await taskOp("hub_release_cut", { id: releaseId, revision }));
2243
+ if (operation === "cut" && args.length === 4) return toolReport(renderSdlcTrain, taskOp("hub_release_cut", { id: releaseId, revision }));
2231
2244
  if (operation === "configure" && args.length === 5) {
2232
2245
  let fields;
2233
2246
  try { fields = JSON.parse(args[4]!); } catch { return fail("release train configuration must be JSON"); }
2234
2247
  if (!fields || typeof fields !== "object" || Array.isArray(fields) || Object.keys(fields).some(key => !["state", "cut", "hotfix"].includes(key))) fail("invalid release train configuration fields");
2235
- return console.log(await taskOp("hub_release_configure", { ...fields, id: releaseId, revision }));
2248
+ return toolReport(renderSdlcTrain, taskOp("hub_release_configure", { ...fields, id: releaseId, revision }));
2236
2249
  }
2237
2250
  fail("usage: ahub sdlc train report|configure|cut <release-id> [revision] [configuration-json]");
2238
2251
  }
2239
2252
  if (sub === "release-assign") {
2240
2253
  const revision = Number(args[2]), release = args[3] === "none" ? null : Number(args[3]);
2241
2254
  if (!Number.isSafeInteger(id) || id! <= 0 || !Number.isSafeInteger(revision) || revision < 0 || release !== null && (!Number.isSafeInteger(release) || release <= 0) || args.length < 5) fail("usage: ahub sdlc release-assign <task> <planning-revision> <release-id|none> <reason...>");
2242
- return console.log(await taskOp("hub_release_assign", { id, revision, release, reason: args.slice(4).join(" ") }));
2255
+ return toolReport(renderTaskShow, taskOp("hub_release_assign", { id, revision, release, reason: args.slice(4).join(" ") }));
2243
2256
  }
2244
2257
  if (sub === "costs") {
2245
2258
  if (args.length > 2) fail("usage: ahub sdlc costs [owner/repository]");
@@ -2258,7 +2271,7 @@ const commands: Record<string, () => Promise<void> | void> = {
2258
2271
  const flags = takeFlags(args.slice(3), ["--review", "--reviewers", "--ci"], []);
2259
2272
  const scope = flags.one["--review"], reviewers = flags.one["--reviewers"];
2260
2273
  if (!flags.rest.length || (scope === undefined) !== (reviewers === undefined)) fail("plan-review needs a reason and both --review and --reviewers when supplying review scope");
2261
- return console.log(await taskOp("hub_plan_review", { id, revision, reason: flags.rest.join(" "), ...(scope !== undefined ? { review: { scope, reviewers: Number(reviewers) } } : {}), ...(flags.one["--ci"] !== undefined ? { ci: flags.one["--ci"] } : {}) }));
2274
+ return toolReport(renderTaskShow, taskOp("hub_plan_review", { id, revision, reason: flags.rest.join(" "), ...(scope !== undefined ? { review: { scope, reviewers: Number(reviewers) } } : {}), ...(flags.one["--ci"] !== undefined ? { ci: flags.one["--ci"] } : {}) }));
2262
2275
  }
2263
2276
  if (sub === "accept-departure") {
2264
2277
  const head = args[2], rawReason = args.slice(3).join(" "), reason = rawReason.trim();
@@ -2267,7 +2280,7 @@ const commands: Record<string, () => Promise<void> | void> = {
2267
2280
  try {
2268
2281
  const reply = await hub.request({ t: "sdlc", op: "accept-departure", id, head, reason }, 30_000);
2269
2282
  if (!reply.ok) fail(reply.error);
2270
- console.log(`task #${id}: plan departure accepted for the reviewed head`);
2283
+ receiptOutput?.("Accept departure", `task #${id}: plan departure accepted for the reviewed head`);
2271
2284
  } finally { hub.close(); }
2272
2285
  return;
2273
2286
  }
@@ -2282,7 +2295,7 @@ const commands: Record<string, () => Promise<void> | void> = {
2282
2295
  if (/unknown SDLC operation|does not know|SDLC readback is console only/.test(reason)) fail(`${reason}; the running hub does not support adopt-merge; upgrade agent-hub and run ahub restart before retrying ahub sdlc adopt-merge`);
2283
2296
  fail(reason);
2284
2297
  }
2285
- console.log(`task #${id}: merged outside the hub; approved`);
2298
+ receipt("Adopt merge", `task #${id}: merged outside the hub; approved`);
2286
2299
  } finally { hub.close(); }
2287
2300
  return;
2288
2301
  }
@@ -2317,23 +2330,7 @@ const commands: Record<string, () => Promise<void> | void> = {
2317
2330
  if (!reply.ok) fail(reply.error, false, undefined, `check ahub sdlc status ${task} for the task's lifecycle receipt, then retry`);
2318
2331
  const view = reply.readback;
2319
2332
  if (options.json) return console.log(JSON.stringify(op === "start" ? reply : view ?? null, null, 2));
2320
- if (op === "start") {
2321
- const state = String(reply.state ?? "");
2322
- console.log(state === "requested" || state === "reported"
2323
- ? `task #${task}: spec read-back ${reply.readback} ${state === "reported" ? "already reported" : "requested"}${state === "requested" ? ` from ${reply.reader}` : ""} (${reply.repo}#${reply.issue})`
2324
- : `task #${task}: spec read-back unavailable: ${reply.reason ?? "no eligible reader"}`);
2325
- return;
2326
- }
2327
- if (!view || view.status === "none") return console.log(`task #${task}: no spec read-back; start one with ahub sdlc readback start ${task}`);
2328
- if (view.status === "private") return console.log(`task #${task}: read-back ${view.readback} belongs to a private task; its report is not printed here`);
2329
- if (view.status === "requested") return console.log(`task #${task}: read-back ${view.readback} requested from ${view.reader}; the reader has not reported yet`);
2330
- console.log(`task #${task}: read-back ${view.readback} of ${view.repo}#${view.issue} by ${view.reader}`);
2331
- if (view.report.cannot_paraphrase) console.log(`cannot paraphrase: ${view.report.cannot_paraphrase}`);
2332
- else { console.log(`proposes: ${view.report.proposes}`); console.log(`existing: ${view.report.existing}`); }
2333
- for (const item of view.report.undefined ?? []) console.log(`undefined: ${item.term} (${item.where})`);
2334
- for (const item of view.report.open_decisions ?? []) console.log(`open decision: ${item.decision} (${item.where})`);
2335
- for (const path of view.report.refs ?? []) console.log(`ref: ${path}`);
2336
- for (const path of view.missing_refs ?? []) console.log(`missing ref: ${path}`);
2333
+ human(renderSdlcReadback, { task, op, reply }, options);
2337
2334
  } finally { hub.close(); }
2338
2335
  return;
2339
2336
  }
@@ -2347,8 +2344,8 @@ const commands: Record<string, () => Promise<void> | void> = {
2347
2344
  const reply = await hub.request({ t: "sdlc", op: "accept", id, issue, ...(repo ? { repo } : {}) }, 30_000);
2348
2345
  if (!reply.ok) fail(reply.error);
2349
2346
  // #1658 AC6: the line names the read-back state read before the acceptance; the acceptance proceeds in every state.
2350
- if (reply.readback) console.log(reply.readback);
2351
- console.log(`task #${id}: spec issue #${issue} accepted at body edit ${reply.acceptance?.lastEditedAt ?? "never"}`);
2347
+ receipt("Accept spec", ...(reply.readback ? [reply.readback] : []),
2348
+ `task #${id}: spec issue #${issue} accepted at body edit ${reply.acceptance?.lastEditedAt ?? "never"}`);
2352
2349
  } finally { hub.close(); }
2353
2350
  return;
2354
2351
  }
@@ -2498,14 +2495,8 @@ const commands: Record<string, () => Promise<void> | void> = {
2498
2495
  const res = await hub.request({ t: "ask", question, remember }, 75_000); // above the hub's own budget (probe + 45 s model call)
2499
2496
  hub.close();
2500
2497
  if (!res.ok) fail(res.error);
2501
- console.log(res.answer ?? `(${res.note})`);
2502
- // "Nothing found" means the list did not answer the question: printing it anyway would only look like an answer.
2503
- if (res.evidence.length && (res.found || res.note)) {
2504
- console.log("\nEvidence:");
2505
- for (const e of res.evidence as { id: string; text: string }[]) console.log(` ${e.id.padEnd(12)} ${e.text.slice(0, 150)}`);
2506
- }
2507
- if (res.pii) console.log("\n(PII is involved: shown here only, not saved anywhere)");
2508
- if (res.saved) console.log(`\n${res.saved}`);
2498
+ const options = outputOptions([]);
2499
+ printOutput(renderAskAnswer(res, options.columns, undefined, asciiMarkers(process.env)), options.color);
2509
2500
  },
2510
2501
 
2511
2502
  route: async () => {
@@ -2698,6 +2689,11 @@ const commands: Record<string, () => Promise<void> | void> = {
2698
2689
  } finally { prepared?.close(); rl?.close(); hub?.close(); registry.close(); }
2699
2690
  },
2700
2691
  settings: async () => {
2692
+ const display = outputOptions([]);
2693
+ const ascii = asciiMarkers(process.env, process.argv.includes("--ascii"));
2694
+ const show = <T>(render: (data: T, columns?: number, now?: number, ascii?: boolean) => Span[][], data: T) =>
2695
+ printOutput(render(data, display.columns, Date.now(), ascii), display.color);
2696
+ const receipt = (title: string, ...lines: string[]) => show(renderSettingsReceipt, { title, lines });
2701
2697
  // #689: structural config edits (instances, review, snapshots, approvals, context.gate, sdlc.toml) and their backups. The hub validates and writes.
2702
2698
  if (args[0] === "edit" || args[0] === "backups") {
2703
2699
  // A command line the parser refuses never reaches the hub, not even as a connection.
@@ -2706,8 +2702,14 @@ const commands: Record<string, () => Promise<void> | void> = {
2706
2702
  const hub = await connect();
2707
2703
  try {
2708
2704
  const rl = process.stdin.isTTY ? createInterface({ input: process.stdin, output: process.stdout }) : undefined;
2705
+ const lines: string[] = [];
2706
+ const jsonBackups = args[0] === "backups" && args[1] === "--json";
2707
+ const flush = () => {
2708
+ if (lines.length) show(renderSettingsReceipt, { title: args[0] === "backups" ? "Settings backups" : "Settings edit", lines: lines.splice(0) });
2709
+ };
2709
2710
  const usage = await runSettingsEdit(args, {
2710
2711
  request: async message => {
2712
+ flush();
2711
2713
  const reply = await hub.request(message, 35_000);
2712
2714
  if (reply.ok !== true) {
2713
2715
  const error = String(reply.error ?? "config edit refused");
@@ -2715,9 +2717,12 @@ const commands: Record<string, () => Promise<void> | void> = {
2715
2717
  }
2716
2718
  return reply;
2717
2719
  },
2718
- ask: async prompt => { if (!rl) return null; try { return await rl.question(prompt); } catch { return null; } },
2719
- print: line => console.log(terminalText(line)),
2720
- }).finally(() => rl?.close());
2720
+ ask: async prompt => { flush(); if (!rl) return null; try { return await rl.question(prompt); } catch { return null; } },
2721
+ print: line => {
2722
+ if (jsonBackups) process.stdout.write(terminalText(line) + "\n");
2723
+ else lines.push(terminalText(line));
2724
+ },
2725
+ }).finally(() => { flush(); rl?.close(); });
2721
2726
  if (usage) fail(usage);
2722
2727
  } finally { hub.close(); }
2723
2728
  return;
@@ -2753,12 +2758,12 @@ const commands: Record<string, () => Promise<void> | void> = {
2753
2758
  const view = await request({ t: "settings_get" }), entry = view.sdlc?.[key!];
2754
2759
  if (!entry || !Object.hasOwn(entry, "value") || !Object.hasOwn(entry, "fileValue")) fail("running hub lacks SDLC settings reads; upgrade and restart it first");
2755
2760
  if (flags.includes("--json")) return console.log(JSON.stringify({ key, ...entry }, null, 2));
2756
- return console.log(terminalText(`${key}: running ${JSON.stringify(entry.value)}; file ${JSON.stringify(entry.fileValue)}${entry.problem ? "; file unavailable" : ""}`));
2761
+ return show(renderSdlcSetting, { key: key!, value: entry.value, fileValue: entry.fileValue, problem: entry.problem });
2757
2762
  }
2758
2763
  if (sub === "reload") {
2759
2764
  let result = await request({ t: "settings_reload" });
2760
2765
  const confirmation = result.confirmation;
2761
- if (Array.isArray(result.rejected)) for (const row of result.rejected.slice(0, 100)) console.log(terminalText(`${String(row.key).slice(0, 160)}: ${String(row.reason).slice(0, 1000)}`));
2766
+ if (Array.isArray(result.rejected) && result.rejected.length) show(renderSettingsRejected, result.rejected);
2762
2767
  if (confirmation !== undefined) {
2763
2768
  if (!confirmation || typeof confirmation.token !== "string" || !confirmation.token || confirmation.token.length > 256 || !Array.isArray(confirmation.keys) || !confirmation.keys.length || confirmation.keys.length > 200 || confirmation.keys.some((key: unknown) => typeof key !== "string" || key.length > 160)) fail("invalid reload confirmation; guarded settings were not applied");
2764
2769
  const fullValue = (value: unknown): boolean => {
@@ -2772,11 +2777,7 @@ const commands: Record<string, () => Promise<void> | void> = {
2772
2777
  return row.key !== confirmation.keys[index] || !fullValue(row.before) || !fullValue(row.after) || (row.effect !== undefined && (typeof row.effect !== "string" || Buffer.byteLength(row.effect, "utf8") > 2048));
2773
2778
  })) fail("reload preview is incomplete or unavailable; upgrade the running hub and run ahub settings reload again to review every full value; guarded settings were not applied");
2774
2779
  const token = confirmation.token;
2775
- console.log("Guarded settings awaiting confirmation:");
2776
- for (const change of confirmation.changes) {
2777
- console.log(` ${terminalText(change.key)}: ${terminalText(change.before)} -> ${terminalText(change.after)}`);
2778
- if (change.effect !== undefined) console.log(` ${terminalText(change.effect)}`);
2779
- }
2780
+ show(renderSettingsConfirmation, confirmation.changes);
2780
2781
  if (!process.stdin.isTTY || !process.stdout.isTTY) fail("guarded settings need an interactive person's terminal; run ahub settings reload there; guarded settings were not applied");
2781
2782
  const rl = createInterface({ input: process.stdin, output: process.stdout, terminal: false });
2782
2783
  const ended = new AbortController();
@@ -2785,12 +2786,12 @@ const commands: Record<string, () => Promise<void> | void> = {
2785
2786
  try { accepted = (await rl.question("Apply guarded settings? [y/N] ", { signal: AbortSignal.any([AbortSignal.timeout(30_000), ended.signal]) })).trim().toLowerCase() === "y"; }
2786
2787
  catch { /* EOF, cancellation and a missed confirmation deadline grant nothing. */ }
2787
2788
  finally { rl.close(); }
2788
- if (!accepted) return console.log("guarded settings were not applied");
2789
+ if (!accepted) return receipt("Settings reload", "guarded settings were not applied");
2789
2790
  result = await request({ t: "settings_reload", confirm: token });
2790
2791
  if (result.confirmation !== undefined) fail("reload candidate changed; run ahub settings reload again to review it; guarded settings were not applied");
2791
- if (Array.isArray(result.rejected)) for (const row of result.rejected.slice(0, 100)) console.log(terminalText(`${String(row.key).slice(0, 160)}: ${String(row.reason).slice(0, 1000)}`));
2792
+ if (Array.isArray(result.rejected) && result.rejected.length) show(renderSettingsRejected, result.rejected);
2792
2793
  }
2793
- return console.log(paint([{ text: result.text }], false));
2794
+ return receipt("Settings reload", result.text ?? "configuration reloaded");
2794
2795
  }
2795
2796
  if (sub === "undo") {
2796
2797
  const view = await request({ t: "settings_get" }), undoDef = undoableDef(view.undo, settingScope.instances, settingScope.catalog);
@@ -2808,35 +2809,20 @@ const commands: Record<string, () => Promise<void> | void> = {
2808
2809
  const rl = createInterface({ input: process.stdin, output: process.stdout });
2809
2810
  try { confirm = (await rl.question(`Type ${rosterPeer} to confirm this roster undo: `)).trim(); } finally { rl.close(); }
2810
2811
  }
2811
- return console.log(paint([{ text: (await request({ t: "settings_undo", ...(confirm ? { confirm } : {}) })).text }], false));
2812
+ return receipt("Settings undo", (await request({ t: "settings_undo", ...(confirm ? { confirm } : {}) })).text ?? "setting restored");
2812
2813
  }
2813
2814
  if (sub === "set" && flags.includes("--preview")) {
2814
2815
  const preview = await request({ t: "settings_preview", key, value });
2815
- for (const line of preview.lines ?? []) console.log(paint([{ text: line }], false));
2816
- // Each side is `route explain`: the task line, "if it were assigned now:", then the trace.
2817
- for (const task of preview.tasks ?? []) console.log([task.before[0], " before:", ...task.before.slice(2).map((line: string) => ` ${line}`), " after:", ...task.after.slice(2).map((line: string) => ` ${line}`)].join("\n"));
2818
- if (preview.hidden) console.log(`${preview.hidden} more open tasks are not shown`);
2819
- return console.log("preview only; nothing was changed");
2816
+ return show(renderSettingsPreview, preview);
2820
2817
  }
2821
2818
  if (sub === "set") {
2822
2819
  const reply = await request({ t: "settings_set", key, value, now: flags.includes("--now"), ...(flags.includes("--yes") && peer ? { confirm: peer } : {}) });
2823
- console.log(paint([{ text: reply.text }], false));
2824
- if (typeof reply.note === "string" && reply.note) console.log(paint([{ text: reply.note }], false));
2825
- return;
2820
+ return receipt("Settings set", reply.text ?? "setting saved", ...(typeof reply.note === "string" && reply.note ? [reply.note] : []));
2826
2821
  }
2827
2822
  const view = await request({ t: "settings_get" });
2828
2823
  const rows = (view.rows as SettingRow[]).filter((row) => sub === "list" || row.key === key);
2829
2824
  if (flags.includes("--json")) return console.log(JSON.stringify(sub === "get" ? rows[0] : { rows, pendingRestart: view.pendingRestart ?? [], ...(view.undo ? { undo: view.undo } : {}) }, null, 2));
2830
- const width = Math.max(...rows.map((row) => row.key.length)), valueWidth = Math.max(...rows.map((row) => settingText(row.value).length));
2831
- let group = "";
2832
- for (const row of rows) {
2833
- if (sub === "list" && row.group !== group) console.log(`${group ? "\n" : ""}${group = row.group}`);
2834
- const facts = [`from ${row.source}`, `file: ${settingText(row.fileValue === undefined ? row.pending ?? row.value : row.fileValue)}`, row.applies === "live" ? "applies at once" : row.applies === "next use" ? "applies at next use" : "pending restart", ...(row.restartReason ? [row.restartReason] : []), ...(row.note ? [row.note] : [])];
2835
- console.log(` ${row.key.padEnd(width)} ${settingText(row.value).padEnd(valueWidth)} ${facts.join("; ")}`);
2836
- if (sub === "get") console.log(` ${row.label}; written to ${row.file}; takes ${row.type === "boolean" ? "true, false" : row.type === "number-or-off" ? `off or a number from ${row.min ?? 0} to ${row.max ?? "the configured bound"}` : row.type === "integer" || row.type === "number" ? `a number from ${row.min ?? 0} to ${row.max ?? "the configured bound"}` : row.type === "peers" ? "a comma list of peer ids" : row.type === "roles" ? "up to two comma-separated catalog ids" : (row.values ?? []).join(", ")}${row.file === "this hub run" || row.key === "instructed.mode" ? "" : ", or inherit to remove the machine-local value"}${row.risk === "raises" ? "; a dashboard needs a settings session (ahub ui --settings) to raise it" : ""}`);
2837
- }
2838
- if (sub === "list" && view.pendingRestart?.length) console.log(`\npending restart: ${view.pendingRestart.map((entry: { key: string }) => entry.key).join(", ")}`);
2839
- if (sub === "list" && view.undo) console.log(`\nahub settings undo puts back the last write (${view.undo})`);
2825
+ show(renderSettingsRows, { rows, detail: sub === "get", ...(sub === "list" ? { pendingRestart: view.pendingRestart, undo: view.undo } : {}) });
2840
2826
  } finally { hub.close(); }
2841
2827
  },
2842
2828
 
@@ -2861,23 +2847,15 @@ const commands: Record<string, () => Promise<void> | void> = {
2861
2847
  if (reply.ok === false) return fail(String(reply.error ?? "questions are unavailable"));
2862
2848
  const rows = Array.isArray(reply.questions) ? reply.questions : [];
2863
2849
  if (options.json) return console.log(JSON.stringify(rows, null, 2));
2864
- if (!rows.length) return console.log("no open questions");
2865
- for (const row of rows) {
2866
- console.log(`${row.set} ${row.peer} asks${row.private ? " (private)" : ""}`);
2867
- for (const question of row.questions) {
2868
- console.log(` ${question.id}: ${terminalText(String(question.prompt))}${question.multi ? " (choose any)" : ""}${question.allowOther ? " (or --other <text>)" : ""}`);
2869
- for (const option of question.options) console.log(` ${option.id} ${terminalText(String(option.label))}${option.description ? ` - ${terminalText(String(option.description))}` : ""}`);
2870
- }
2871
- console.log(` answer with: ahub answer ${row.set} ${row.questions.map((question: { id: string; options: { id: string }[] }) => `${question.id}=${question.options[0]?.id ?? "<option>"}`).join(" ")}`);
2872
- }
2873
- return;
2850
+ return printOutput(renderQuestions(rows, options.columns, undefined, asciiMarkers(process.env)), options.color);
2874
2851
  }
2875
2852
  const parsed = parseAnswerArgs(operands);
2876
2853
  if (!parsed.ok) return fail(parsed.error);
2877
2854
  const reply = await hub.request({ t: "answer", surface: "terminal", questionSet: parsed.value.set, answers: parsed.value.answers, ...(parsed.value.instruction === undefined ? {} : { instructed: parsed.value.instruction }) });
2878
2855
  if (reply.ok === false) return fail(String(reply.error ?? "the answer was refused"));
2879
2856
  if (options.json) return console.log(JSON.stringify({ ok: true, questionSet: reply.questionSet, state: reply.state, ...(reply.instructed ? { actor: reply.actor, instructed: true } : {}) }));
2880
- console.log(`answered ${reply.questionSet ?? parsed.value.set}${reply.instructed && typeof reply.actor === "string" ? `; answered by ${terminalText(reply.actor)} on the person's instruction` : ""}`);
2857
+ printOutput(renderAnswerReceipt({ kind: "answer", set: reply.questionSet ?? parsed.value.set,
2858
+ actor: reply.instructed && typeof reply.actor === "string" ? reply.actor : undefined }), options.color);
2881
2859
  } finally { hub.close(); }
2882
2860
  },
2883
2861
 
@@ -2892,22 +2870,19 @@ const commands: Record<string, () => Promise<void> | void> = {
2892
2870
  if (request.action === "read") {
2893
2871
  const reply = await hub.request({ t: "result_seen", id: request.id, surface: "terminal" });
2894
2872
  if (reply.ok === false) return fail(String(reply.error ?? "the result could not be marked read"));
2895
- return options.json ? console.log(JSON.stringify({ ok: true, id: request.id, read: true })) : console.log(`marked ${request.id} read`);
2873
+ return options.json ? console.log(JSON.stringify({ ok: true, id: request.id, read: true })) : printOutput(renderAnswerReceipt({ kind: "read", id: request.id }), options.color);
2896
2874
  }
2897
2875
  if (request.action === "read-all" || request.action === "unread-last") {
2898
2876
  const reply = await hub.request({ t: "results", action: request.action, surface: "terminal" });
2899
2877
  if (reply.ok === false) return fail(String(reply.error ?? "the receipt could not be written"));
2900
2878
  if (options.json) return console.log(JSON.stringify(request.action === "read-all" ? { ok: true, marked: reply.marked } : { ok: true, unread: reply.unread }));
2901
- return console.log(request.action === "read-all" ? `marked ${reply.marked} ${reply.marked === 1 ? "result" : "results"} read` : `marked ${reply.unread} unread again`);
2879
+ return printOutput(renderAnswerReceipt(request.action === "read-all" ? { kind: "read-all", marked: reply.marked } : { kind: "unread-last", unread: reply.unread }), options.color);
2902
2880
  }
2903
2881
  const reply = await hub.request({ t: "results", unread: request.unread });
2904
2882
  if (reply.ok === false) return fail(String(reply.error ?? "results are unavailable"));
2905
2883
  const rows = Array.isArray(reply.results) ? reply.results : [];
2906
2884
  if (options.json) return console.log(JSON.stringify(rows, null, 2));
2907
- if (!rows.length) return console.log(request.unread ? "no unread results" : "no results");
2908
- for (const row of rows) console.log(`${row.read ? " " : "*"} ${row.id} ${terminalText(String(row.title))} ${new Date(Number(row.settledAt)).toISOString().replace("T", " ").slice(0, 16)} ${Math.round(Number(row.ms) / 1000)}s${row.read ? "" : ` ahub results --read ${row.id}`}`);
2909
- // The listing holds the newest 100. Unread results are never pruned, so when more exist than shown, say how many and how to reach them (status still counts every one).
2910
- if (Number(reply.more) > 0) console.log(`... and ${Number(reply.more)} older unread; ahub results --read-all marks them all, or read the newest ones first`);
2885
+ printOutput(renderResults({ rows, unread: request.unread, more: Number(reply.more) }), options.color);
2911
2886
  } finally { hub.close(); }
2912
2887
  },
2913
2888
 
@@ -3316,21 +3291,17 @@ const commands: Record<string, () => Promise<void> | void> = {
3316
3291
  };
3317
3292
  // #798 D3: the hub saw these submodules dirty when the turn ended and cannot see inside them: they are never restored, and never counted as "no change".
3318
3293
  const unobserved = turn.unobserved ?? [];
3319
- const unobservedNote = unobserved.length ? `\nthese submodules were changed during the turn and their contents cannot be restored (the hub does not observe inside a submodule); undo them in the submodule itself:\n ${unobserved.join("\n ")}` : "";
3320
3294
  const first = plan();
3321
- if (first.undone && !unobserved.length) return console.log(`turn ${id} is already undone: its files are as they were before it started`);
3322
- if (first.undone) return console.log(`turn ${id}: its files are as they were before it started${unobservedNote}`);
3323
- // "changed no files" is true of the files the hub observes and false of the turn: with a submodule dirty it says what it can and cannot see instead.
3324
- console.log((first.restore.length ? `turn ${id} changed:\n ${first.restore.join("\n ")}` : unobserved.length ? `turn ${id} changed no files the hub can restore` : `turn ${id} changed no files`) + unobservedNote);
3325
- console.log("(every change made in the project during the turn counts as its own, including any by Claude or by you)");
3295
+ printOutput(renderUndoPlan({ id, restore: first.restore, unobserved, undone: first.undone }, undefined, undefined, asciiMarkers(process.env)), false);
3296
+ if (first.undone) return;
3326
3297
  const projections = new TextProjections({ cwd: undoCwd, stateDir, config: undoConfig.text_projection ?? {}, deny: undoConfig.local.deny, readAllow: undoConfig.local.read_allow, log: line => warn(line) });
3327
3298
  const preview = projectedDiff({ repo, from: endTree, to: startTree, paths: first.restore, projections, deny: undoConfig.local.deny, privatePath: path => matchesPolicy(undoCwd, join(repo.top, path), undoConfig.pii?.paths ?? []) });
3328
- if (preview) console.log(terminalText("Undo preview (end snapshot to start snapshot):\n" + preview));
3299
+ if (preview) printOutput(renderLifecycleReceipt({ lines: [terminalText("Undo preview (end snapshot to start snapshot):\n" + preview)] }), false);
3329
3300
 
3330
- if (!args.includes("--yes")) return console.log("nothing was changed; add --yes to restore these files");
3301
+ if (!args.includes("--yes")) return printOutput(renderLifecycleReceipt({ lines: ["nothing was changed; add --yes to restore these files"] }), false);
3331
3302
  requireUndoWorkspace();
3332
3303
  if (args.includes("--context")) {
3333
- console.log(await taskOp("turn_revert", { turn: id }));
3304
+ printOutput(renderLifecycleReceipt({ lines: [await taskOp("turn_revert", { turn: id })] }), false);
3334
3305
  reverted = true;
3335
3306
  }
3336
3307
  // A peer may have written meanwhile (the revert alone can take seconds): plan again right before restoring.
@@ -3338,17 +3309,17 @@ const commands: Record<string, () => Promise<void> | void> = {
3338
3309
  if (second.restore.join("\0") !== first.restore.join("\0")) fail(`the project changed while undoing; nothing was restored, run ahub undo again${reverted ? " without --context (Codex's conversation was already reverted)" : ""}`);
3339
3310
  requireUndoWorkspace();
3340
3311
  restore(repo, startTree, second.restore);
3341
- if (second.restore.length) console.log(`restored to their state before ${id}`);
3312
+ if (second.restore.length) printOutput(renderLifecycleReceipt({ lines: [`restored to their state before ${id}`] }), false);
3342
3313
  },
3343
3314
 
3344
3315
  kill: async () => {
3345
3316
  const project = matchingProject();
3346
3317
  if (!project) {
3347
- if (!hubManifest()) return console.log("hub is not running");
3318
+ if (!hubManifest()) return printOutput(renderLifecycleReceipt({ lines: ["hub is not running"] }), false);
3348
3319
  fail("hub has no matching registration; use its matching CLI to stop it before upgrading");
3349
3320
  }
3350
3321
  await stopProject(project);
3351
- console.log("hub stopped");
3322
+ printOutput(renderLifecycleReceipt({ lines: ["hub stopped"] }), false);
3352
3323
  },
3353
3324
  // The counterpart of `ahub up`: the same verified graceful stop as `ahub kill`, never a second shutdown path.
3354
3325
  down: async () => { await commands.kill!(); },
@@ -3362,7 +3333,7 @@ const commands: Record<string, () => Promise<void> | void> = {
3362
3333
  const project = matchingProject() ?? fail(hubManifest() ? "hub has no matching registration; use its matching CLI to stop it; nothing was changed"
3363
3334
  : elsewhere ? `this project is registered with the state directory ${elsewhere.stateDir}; run ahub --project ${elsewhere.id} reset; nothing was changed`
3364
3335
  : "no registration matches this project and state directory; nothing was changed (ahub up registers it)");
3365
- if (!existsSync(stateDir)) return console.log("no state directory; nothing to reset");
3336
+ if (!existsSync(stateDir)) return printOutput(renderLifecycleReceipt({ lines: ["no state directory; nothing to reset"] }), false);
3366
3337
  // A state directory elsewhere (AGENTHUB_STATE_DIR, or a symlink) would cross file systems or pull outside state
3367
3338
  // into the project tree.
3368
3339
  if (all && stateDir !== join(cwd, ".agenthub", "state")) fail(`--all moves only ${join(cwd, ".agenthub", "state")}; this project's state is in ${stateDir}: stop the hub and archive it by hand; nothing was changed`);
@@ -3372,8 +3343,7 @@ const commands: Record<string, () => Promise<void> | void> = {
3372
3343
  if (!["stopped", "running", "stopping"].includes(live.state)) fail(`${live.error ?? `hub is ${live.state}`}; nothing was changed`);
3373
3344
  const recovery = live.status?.recovery as { operationId?: string; phase?: string } | undefined;
3374
3345
  if (recovery?.operationId && recovery.phase !== "released") fail(`recovery operation ${recovery.operationId} is open in this hub; nothing was changed`);
3375
- const kept = "kept: the board, logs and audit, recovery records, execution budgets, configuration and pi-sessions/";
3376
- const memory = "claude-mem is not touched: notes saved with hub_remember stay in shared memory";
3346
+ const ascii = asciiMarkers(process.env);
3377
3347
  if (!args.includes("--yes")) {
3378
3348
  // Planned only for the dry run: `--all --yes` archives a state directory it cannot read as it is.
3379
3349
  let plan: ResetPlan | undefined, unread: string | undefined;
@@ -3382,20 +3352,17 @@ const commands: Record<string, () => Promise<void> | void> = {
3382
3352
  if (!all) fail(`cannot read the state (${failureText(error)}); nothing was changed${damagedState(error) ? "; ahub reset --all --yes archives it as it is" : ""}`);
3383
3353
  unread = failureText(error);
3384
3354
  }
3385
- console.log(`ahub reset${all ? " --all" : ""}, dry run: the hub is ${live.state}${live.state === "stopped" ? "" : "; --yes stops it first, as ahub kill does"}`);
3386
- if (all) {
3387
- console.log(` move ${stateDir}${plan ? ` (${plan.entries} entries)` : ""} to ${join(cwd, ".agenthub", "archive")}/state-<UTC time>/ (0700), then start an empty state directory holding only project.json; project ${project.id} keeps its id and registration`);
3388
- console.log(unread ? ` could not read the state (${unread}); it is archived as it is` : " archived as they are:");
3389
- } else console.log(' settle as discard with reason "reset", clear and drop:');
3390
- for (const line of plan ? resetLines(plan) : []) console.log(` ${line}`);
3391
3355
  const stale = live.state === "stopped" && !all ? MANIFEST.filter((name) => existsSync(join(stateDir, name))) : [];
3392
- if (stale.length) console.log(` remove the manifest a hub left when it did not stop cleanly: ${stale.join(", ")}`);
3393
- console.log(` ${all ? ".agenthub/config.json, config.local.json and routing.toml are outside the state directory and stay" : kept}`);
3394
- console.log(` ${memory}`);
3395
- return console.log("nothing was changed; add --yes to apply");
3356
+ return printOutput(renderResetPlan({ all, state: live.state, stateDir, archive: join(cwd, ".agenthub", "archive"),
3357
+ projectId: project.id, plan, unread, stale }, undefined, undefined, ascii), false);
3396
3358
  }
3397
3359
  await stopProject(project);
3398
- if (live.state !== "stopped") console.log("hub stopped");
3360
+ let receiptStarted = false;
3361
+ const receipt = (...lines: string[]) => {
3362
+ printOutput(renderLifecycleReceipt({ ...(receiptStarted ? {} : { title: all ? "Reset --all" : "Reset" }), lines }, undefined, undefined, ascii), false);
3363
+ receiptStarted = true;
3364
+ };
3365
+ if (live.state !== "stopped") receipt("hub stopped");
3399
3366
  // Hold the claim a daemon takes to run: a hub started after the stop holds it (refused here), and none can start
3400
3367
  // while the reset acts. A reset that dies leaves a claim with a dead pid, which the next start takes over.
3401
3368
  const registry = new Registry();
@@ -3413,24 +3380,24 @@ const commands: Record<string, () => Promise<void> | void> = {
3413
3380
  let archived: string;
3414
3381
  try { archived = archiveState(cwd, stateDir); }
3415
3382
  catch (error) { throw new Error(`the hub is stopped; nothing was moved: ${failureText(error)}`); }
3416
- console.log(`moved the state directory to ${archived}`);
3383
+ receipt(`moved the state directory to ${archived}`);
3417
3384
  try { startState(stateDir, archived); }
3418
3385
  catch (error) { throw new Error(`${(error as Error).message}; the state directory is archived at ${archived}: create ${stateDir} (0700) and copy project.json from the archive`); }
3419
- console.log(`the new state directory holds only project.json (to restore: ahub kill, move ${stateDir} into ${join(cwd, ".agenthub", "archive")}/, then move the archive back to ${stateDir})`);
3386
+ receipt(`the new state directory holds only project.json (to restore: ahub kill, move ${stateDir} into ${join(cwd, ".agenthub", "archive")}/, then move the archive back to ${stateDir})`);
3420
3387
  } else {
3421
3388
  let result: ReturnType<typeof resetRuntime>;
3422
3389
  try { result = resetRuntime(stateDir, project); }
3423
3390
  catch (error) {
3424
3391
  throw new Error(`${failureText(error)}; the hub is stopped and the reset is incomplete: ${damagedState(error) ? "the state cannot be read, so a rerun fails the same way; ahub reset --all --yes archives it as it is" : "run ahub reset --yes again to finish it"}`);
3425
3392
  }
3426
- console.log(`settled ${result.settled.length} deliveries as discard with reason "reset"`);
3427
- for (const line of resetLines(result.plan).slice(1)) console.log(`cleared ${line}`);
3428
- if (result.stale.length) console.log(`removed the manifest a hub left when it did not stop cleanly: ${result.stale.join(", ")}`);
3429
- console.log(kept);
3393
+ receipt(`settled ${result.settled.length} deliveries as discard with reason "reset"`);
3394
+ for (const line of resetLines(result.plan).slice(1)) receipt(`cleared ${line}`);
3395
+ if (result.stale.length) receipt(`removed the manifest a hub left when it did not stop cleanly: ${result.stale.join(", ")}`);
3396
+ receipt(RESET_KEPT);
3430
3397
  }
3431
3398
  } finally { registry.release(project.id, claim); registry.close(); }
3432
- console.log(memory);
3433
- console.log("Claude Code sessions attached to this hub lost their hub session: relaunch them with ahub claude");
3399
+ receipt(RESET_MEMORY);
3400
+ receipt("Claude Code sessions attached to this hub lost their hub session: relaunch them with ahub claude");
3434
3401
  },
3435
3402
 
3436
3403
  role: async () => {
@@ -3721,6 +3688,8 @@ function inspectDoctorRouting(cwd: string): { routing?: Routing; errors: string[
3721
3688
  }
3722
3689
  }
3723
3690
 
3691
+ const runSdlcCommand = () => commands.sdlc!(printSdlcReceipt);
3692
+
3724
3693
  async function runConductorCommand(): Promise<void> {
3725
3694
  if (recoveryRunnerContinuation) return commands[cmd]!();
3726
3695
  const operation=conductorOperation(cmd,args);
@@ -3749,7 +3718,7 @@ async function runConductorCommand(): Promise<void> {
3749
3718
  let op: string;
3750
3719
  let input: Record<string, unknown>;
3751
3720
  if (cmd === "answer") return commands.answer!(); // The daemon checks instructed answer authority.
3752
- if (cmd === "sdlc") return commands.sdlc!(); // SDLC operational subcommands are role-checked by the daemon.
3721
+ if (cmd === "sdlc") return runSdlcCommand(); // SDLC operational subcommands are role-checked by the daemon.
3753
3722
  if (cmd === "task") {
3754
3723
  op = args[0] === "assign" ? "hub_task_assign" : "hub_task_escalate";
3755
3724
  const { one, rest: positional } = takeFlags(args.slice(1), args[0] === "assign" ? ["--role"] : [], []);
@@ -3792,7 +3761,7 @@ const runConfigured = configuredCommand ? async () => {
3792
3761
  if (!selection.preview) assertLifecycleAvailable(cwd);
3793
3762
  await runConfiguredAcpEntry({ kind: cmd, raw: args, catalog: projectCatalog, instances: declaredInstances, declaredExternalInstances: peerConfig.declaredExternalInstances, projectRoot: cwd, connect: connectLaunch, print: text => console.log(text), operationId: process.env.AGENTHUB_RECOVERY_OPERATION });
3794
3763
  } : undefined;
3795
- const run = identity.role === "tools" && commandAccess === "conductor" ? runConductorCommand : (Object.hasOwn(commands, cmd) ? commands[cmd] : undefined) ?? runConfigured ?? (() => fail(`unknown command "${cmd}"; run ahub help`));
3764
+ const run = identity.role === "tools" && commandAccess === "conductor" ? runConductorCommand : (cmd === "sdlc" ? runSdlcCommand : Object.hasOwn(commands, cmd) ? commands[cmd] : undefined) ?? runConfigured ?? (() => fail(`unknown command "${cmd}"; run ahub help`));
3796
3765
  try {
3797
3766
  assertDelegatedAuditConsumer(); // Local command paths must not begin after the authenticated consumer was replaced either.
3798
3767
  await run();