@staix/agent-hub 0.38.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 (195) hide show
  1. package/CHANGELOG.md +84 -0
  2. package/README.md +28 -12
  3. package/docs/adding-an-ai-tool.md +7 -5
  4. package/docs/agent-notes/README.md +23 -0
  5. package/docs/agent-notes/adapters.md +9 -5
  6. package/docs/agent-notes/benchmarks.md +2 -0
  7. package/docs/agent-notes/budget.md +9 -0
  8. package/docs/agent-notes/bus.md +1 -0
  9. package/docs/agent-notes/daemon.md +21 -9
  10. package/docs/agent-notes/local-worker.md +4 -2
  11. package/docs/agent-notes/security-review.md +56 -0
  12. package/docs/agent-notes/tasks.md +22 -6
  13. package/docs/agent-notes/tests.md +10 -9
  14. package/docs/contracts/companion-cli-v1.json +4 -0
  15. package/docs/design/adapters.md +142 -0
  16. package/docs/design/agent-hub-architecture.md +46 -1
  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 +185 -5
  23. package/docs/dogfood.md +30 -9
  24. package/docs/events.md +7 -7
  25. package/docs/memory.md +5 -5
  26. package/docs/operations.md +315 -54
  27. package/docs/profiles.md +101 -8
  28. package/docs/quickstart.md +47 -6
  29. package/docs/research.md +6 -3
  30. package/docs/roles.md +52 -0
  31. package/docs/sdlc.md +190 -2
  32. package/docs/security.md +90 -15
  33. package/docs/text-projection.md +1 -0
  34. package/docs/verification/2026-11-13-claude-implementer-2.1.323.md +59 -0
  35. package/docs/verification/2026-11-13-codex-01672-reviewer-isolation.md +69 -0
  36. package/docs/verification/2026-11-14-0.39.0.md +51 -0
  37. package/docs/verification/2026-11-14-codex-0169-reviewer-isolation.md +70 -0
  38. package/docs/verification/2026-11-14-codex-0169-reviewer-tool-call.md +48 -0
  39. package/docs/verification/2026-11-14-pi-152-compat.md +45 -0
  40. package/docs/verification/2026-11-15-0.40.0.md +39 -0
  41. package/docs/verification/2026-11-16-pi-loopback-1447.md +39 -0
  42. package/docs/verification/pi-152-model-free.ts +57 -0
  43. package/docs/verification/pi-152-native.mjs +21 -0
  44. package/docs/verified.json +48 -25
  45. package/package.json +4 -4
  46. package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
  47. package/plugins/agent-hub/kimi-hook.js +2266 -530
  48. package/plugins/agent-hub/kimi-review-policy-worker.js +16 -11
  49. package/plugins/agent-hub/server.js +2423 -645
  50. package/src/adapters/acp-model-policy.ts +1 -1
  51. package/src/adapters/acp-session-model.ts +35 -0
  52. package/src/adapters/acp.ts +14 -0
  53. package/src/adapters/agy/definition.ts +2 -2
  54. package/src/adapters/agy/hooks.ts +7 -0
  55. package/src/adapters/claude-channel.ts +1 -1
  56. package/src/adapters/claude-implementer.ts +8 -0
  57. package/src/adapters/claude-print-child.ts +26 -2
  58. package/src/adapters/claude-print.ts +4 -0
  59. package/src/adapters/codex-appserver.ts +90 -16
  60. package/src/adapters/codex-review-isolation.ts +63 -17
  61. package/src/adapters/compat.ts +10 -10
  62. package/src/adapters/conformance/fakes/acp-server.ts +11 -2
  63. package/src/adapters/conformance/fakes/app-server.ts +5 -1
  64. package/src/adapters/conformance/fakes/pi-rpc.ts +1 -1
  65. package/src/adapters/definitions/builtin-metadata.ts +12 -12
  66. package/src/adapters/definitions/native-cli-jcode-mcp.ts +18 -3
  67. package/src/adapters/definitions/native-config-defaults.ts +1 -1
  68. package/src/adapters/definitions/native-config-policy.ts +1 -1
  69. package/src/adapters/definitions/native-quota.ts +122 -0
  70. package/src/adapters/definitions/native-recovery.ts +3 -0
  71. package/src/adapters/definitions/qwen.ts +2 -2
  72. package/src/adapters/kimi-review.ts +23 -0
  73. package/src/adapters/kimi-wire-usage.ts +39 -16
  74. package/src/adapters/local-worker.ts +9 -4
  75. package/src/adapters/pi-state-model.ts +12 -0
  76. package/src/adapters/pi.ts +76 -11
  77. package/src/adapters/print-result-model.ts +24 -0
  78. package/src/adapters/registry-types.ts +12 -2
  79. package/src/adapters/registry.ts +19 -2
  80. package/src/adapters/reviewer-print.ts +132 -16
  81. package/src/adapters/role-eligibility.ts +99 -0
  82. package/src/adapters/same-directory.ts +16 -0
  83. package/src/cli/agy-mcp.ts +18 -7
  84. package/src/cli/answer-args.ts +11 -3
  85. package/src/cli/console-question.ts +1 -1
  86. package/src/cli/console-state.ts +98 -11
  87. package/src/cli/console.ts +6 -2
  88. package/src/cli/error-format.ts +19 -0
  89. package/src/cli/free-text.ts +20 -0
  90. package/src/cli/handoff-args.ts +1 -1
  91. package/src/cli/help.ts +350 -30
  92. package/src/cli/identity-audit.ts +8 -7
  93. package/src/cli/identity.ts +27 -4
  94. package/src/cli/init-prompt.ts +31 -2
  95. package/src/cli/init-roles.ts +156 -0
  96. package/src/cli/init-settings.ts +24 -2
  97. package/src/cli/init.ts +232 -17
  98. package/src/cli/main.js +2 -2
  99. package/src/cli/main.ts +250 -69
  100. package/src/cli/model.ts +1 -1
  101. package/src/cli/output-standard.ts +56 -0
  102. package/src/cli/output.ts +199 -9
  103. package/src/cli/preview.ts +1 -1
  104. package/src/cli/recovery-launch.ts +114 -0
  105. package/src/cli/recovery-package.ts +14 -7
  106. package/src/cli/recovery-version-preflight.ts +104 -0
  107. package/src/cli/roadmap.ts +215 -0
  108. package/src/cli/role-doctor.ts +39 -0
  109. package/src/cli/sdlc-output.ts +66 -1
  110. package/src/cli/smoke-pty-bridge.ts +7 -24
  111. package/src/cli/study-output.ts +54 -0
  112. package/src/cli/study.ts +14 -1
  113. package/src/cli/task-output.ts +3 -1
  114. package/src/cli/terminal-recovery.ts +14 -0
  115. package/src/cli/upgrade-presentation-flags.ts +2 -2
  116. package/src/cli/upgrade-presentation.ts +4 -0
  117. package/src/cli/upgrade-restore-state.ts +12 -3
  118. package/src/cli/upgrade-runtime.ts +40 -2
  119. package/src/cli/upgrade.ts +8 -4
  120. package/src/hub/advisor-survey.ts +139 -0
  121. package/src/hub/audit-source.ts +66 -0
  122. package/src/hub/board.ts +677 -15
  123. package/src/hub/budget.ts +54 -4
  124. package/src/hub/bus.ts +9 -0
  125. package/src/hub/check-runner.ts +3 -4
  126. package/src/hub/ci-watch.ts +19 -4
  127. package/src/hub/conductor.ts +14 -8
  128. package/src/hub/config-apply.ts +2 -1
  129. package/src/hub/config-edit-host.ts +77 -5
  130. package/src/hub/considered-findings.ts +47 -0
  131. package/src/hub/control-client.ts +1 -1
  132. package/src/hub/daemon.ts +585 -98
  133. package/src/hub/deliverable-files.ts +17 -1
  134. package/src/hub/dogfood-profile.ts +3 -2
  135. package/src/hub/events.ts +25 -4
  136. package/src/hub/execution-reference.ts +1 -1
  137. package/src/hub/folder-trigger.ts +11 -4
  138. package/src/hub/github-import.ts +81 -0
  139. package/src/hub/hub-tools.ts +117 -20
  140. package/src/hub/install-policy.ts +23 -0
  141. package/src/hub/kimi-usage.ts +34 -2
  142. package/src/hub/lifecycle-schema.ts +3 -3
  143. package/src/hub/memory-profile.ts +9 -1
  144. package/src/hub/memory-sync-state.ts +1 -0
  145. package/src/hub/model-overrides.ts +2 -1
  146. package/src/hub/no-writes.ts +5 -0
  147. package/src/hub/operational-authority.ts +8 -1
  148. package/src/hub/operational-view.ts +6 -2
  149. package/src/hub/peers.ts +2 -0
  150. package/src/hub/pi-failure.ts +7 -0
  151. package/src/hub/plan-conformance.ts +20 -2
  152. package/src/hub/question-desk.ts +26 -7
  153. package/src/hub/questions.ts +33 -5
  154. package/src/hub/quota-account.ts +34 -0
  155. package/src/hub/recovery-policy.ts +18 -4
  156. package/src/hub/research-evidence.ts +51 -3
  157. package/src/hub/research.ts +77 -13
  158. package/src/hub/restart.ts +21 -0
  159. package/src/hub/review-budget.ts +88 -0
  160. package/src/hub/review-findings.ts +93 -12
  161. package/src/hub/reviewer-pool-config.ts +6 -2
  162. package/src/hub/reviewer-pool.ts +39 -6
  163. package/src/hub/roadmap-triage.ts +86 -0
  164. package/src/hub/roadmap-unplaced.ts +169 -0
  165. package/src/hub/roadmap-view.ts +83 -0
  166. package/src/hub/roadmap.ts +127 -0
  167. package/src/hub/routing.ts +7 -3
  168. package/src/hub/sdlc-merge.ts +6 -5
  169. package/src/hub/sdlc-queue.ts +17 -7
  170. package/src/hub/sdlc-release.ts +1 -1
  171. package/src/hub/sdlc.ts +47 -8
  172. package/src/hub/security-audit.ts +178 -0
  173. package/src/hub/security-pass.ts +115 -0
  174. package/src/hub/settings.ts +11 -5
  175. package/src/hub/source-read.ts +80 -2
  176. package/src/hub/sources.ts +57 -9
  177. package/src/hub/specs-task.ts +7 -0
  178. package/src/hub/startup-event-seeds.ts +5 -3
  179. package/src/hub/startup-timing.ts +1 -0
  180. package/src/hub/synthesis-readiness.ts +279 -0
  181. package/src/hub/task-sweep.ts +29 -2
  182. package/src/hub/task-worktree.ts +37 -0
  183. package/src/hub/tasks.ts +1464 -76
  184. package/src/hub/text-projection.ts +11 -1
  185. package/src/memory/capture.ts +2 -1
  186. package/src/pi/dependency-publish.ts +50 -0
  187. package/src/pi/extension.ts +1 -1
  188. package/src/pi/launch.ts +1 -1
  189. package/src/pi/task-dependencies.ts +249 -0
  190. package/src/ui/index.html +56 -13
  191. package/src/ui/office-model.ts +11 -3
  192. package/src/ui/office-space.ts +50 -30
  193. package/src/ui/plugin-questions.ts +5 -0
  194. package/src/ui/plugin.ts +27 -12
  195. package/templates/config.json +1 -1
package/src/cli/help.ts CHANGED
@@ -1,9 +1,26 @@
1
1
  import { ADAPTERS, deriveAdapterLists, type AdapterDefinition } from "../adapters/registry.ts";
2
2
  import { VERSION } from "../version.ts";
3
- import { paint, wrap, type Span } from "./console-state.ts";
3
+ import { ROADMAP_FORMS } from "./roadmap.ts";
4
+ import { paint, wrap, Report as LayoutReport, type Span } from "./console-state.ts";
4
5
 
5
6
  /** One usage form of `ahub help`: the usage starts with `ahub <command>`, alternatives joined by `|`. */
6
- export interface HelpEntry { section: string; usage: string; description: string }
7
+ export interface HelpEntry { section: string; usage: string; description: string; /** #1504: the overview row of a native agent, from the third element of its definition's `cli.usage` entry; never a table in this file that names a peer. */ summary?: string }
8
+
9
+ /** #1405: one source for the probe usage, read by `ahub help` and by the refusal of a malformed probe command. */
10
+ export const GUIDANCE_PROBE_USAGE = {
11
+ register: "register --file JSON [--json]",
12
+ start: "start --id HASH --revision N [--variant G1-HASH] [--json]",
13
+ show: "show --id HASH [--json]",
14
+ receipts: "receipts --id HASH [--json]",
15
+ cancel: "cancel --id HASH --revision N [--json]",
16
+ } as const;
17
+ /** What to print when `ahub guidance probe ...` did not parse: the typed subcommand's own usage, or all five for an unknown one. */
18
+ export function guidanceProbeUsage(args: readonly string[]): string {
19
+ const typed = args[1], known = typed !== undefined && Object.hasOwn(GUIDANCE_PROBE_USAGE, typed);
20
+ const forms = known ? [GUIDANCE_PROBE_USAGE[typed as keyof typeof GUIDANCE_PROBE_USAGE]] : Object.values(GUIDANCE_PROBE_USAGE);
21
+ const id = known && typed === "register" ? "" : " HASH is the 64-character probe id that ahub guidance probe register printed; no command lists probes.";
22
+ return `${known ? `ahub guidance probe ${typed} has a missing or malformed argument` : "unknown guidance probe command"}; usage: ${forms.map(form => `ahub guidance probe ${form}`).join(" | ")}.${id}`;
23
+ }
7
24
 
8
25
  const SECTIONS: [string, [usage: string, description: string][]][] = [
9
26
  ["Projects", [
@@ -13,9 +30,9 @@ const SECTIONS: [string, [usage: string, description: string][]][] = [
13
30
  ["ahub projects [--json] [--full] [--color=auto|always|never]", "list registered projects and live status"],
14
31
  ["ahub projects remove <id>", "forget a stopped registration (keeps project files)"],
15
32
  ["ahub setup [--yes] [--agents <a,b>] [--research|--no-research]", "install or update the channel plugin and project-neutral hook in Claude configuration homes in use, preserving unrelated profile settings, ask once which agents ahub up starts (--agents answers it, --yes keeps the current choice or claude,codex, no terminal keeps the default), save the research default only with explicit --research/--no-research (ordinary setup leaves it unchanged), register the acon console plugin (console/plugins/ahub.json in the hub home, read at acon's next start), then run doctor"],
16
- ["ahub init [--profile dev|research|writing|general|<pack>] [--agents <a,b,...|none>] [--sdlc off|advise|enforce] [--required-checks <a,b,...>] [--coordination advisory|turn-free] [--memory|--no-memory] [--research|--no-research] [--snapshots|--no-snapshots] [--pi|--no-pi] [--specs|--no-specs] [--spec-review off|report|require] [--autonomy inherit|off] [--shadow] [--release-guard] [--yes] [--dry-run --json]", "preview or write .agenthub/config.json and the AGENTS.md marker block (drops a legacy CLAUDE.md block); a pack is a shipped one (writing-pack, analysis, ops) or a project file .agenthub/roles/<name>.pack.json; a new project inherits a trusted machine autonomy default and the agent set chosen at ahub setup (start.agents) into config.local.json. Settings flags (#1065): --agents sets start.agents (none starts no agent), --research/--no-research sets research.enabled (new project default: the trusted setup choice, else off) and --autonomy off skips the autonomy inheritance, all in config.local.json; --sdlc sets sdlc.toml mode (off writes no file on a new project); advise/enforce discovers required checks from CI or literal workflow job names; --required-checks overrides discovery, and enforce without names refuses before writes; --coordination, --memory, --snapshots and --pi set their keys in config.json. On an existing project only a flag you give changes anything, and --dry-run shows each change as old -> new (--dry-run --json adds a settings array); a value equal to the current one is a no-op, an invalid value is refused with the allowed ones and nothing is written. --specs/--no-specs and --spec-review set the design-specs keys (and the AGENTS.md specs block). A person at a terminal who runs ahub init on a new project with no flag that sets anything and no --yes is asked each setting in turn with its default in brackets (Enter keeps it, a wrong answer asks again, and a third wrong answer ends init with nothing written), sees the plan and answers y/N; N, Ctrl-C and Ctrl-D write nothing. A peer, a live test, a pipe and --dry-run are never asked, and --yes takes the defaults. Success prints next steps to commit shared init changes, start with ahub up or ahub claude and, for advise/enforce, accept specs/departures and use guarded merge. Executables, secrets, models and permissions stay file edits"],
33
+ ["ahub init [--profile dev|research|writing|general|<pack>] [--agents <a,b,...|none>] [--sdlc off|advise|enforce] [--required-checks <a,b,...>] [--coordination advisory|turn-free] [--memory|--no-memory] [--research|--no-research] [--snapshots|--no-snapshots] [--pi|--no-pi] [--specs|--no-specs] [--spec-review off|report|require] [--conductor <peer>|none] [--planner <a,b,...>] [--reviewer <a,b,...>|person] [--track-config|--no-track-config] [--autonomy inherit|off] [--shadow] [--release-guard] [--yes] [--dry-run --json]", "preview or write .agenthub/config.json and the AGENTS.md marker block (drops a legacy CLAUDE.md block); a pack is a shipped one (writing-pack, analysis, ops) or a project file .agenthub/roles/<name>.pack.json; a new project inherits a trusted machine autonomy default and the agent set chosen at ahub setup (start.agents) into config.local.json. Settings flags (#1065): --agents sets start.agents (none starts no agent), --research/--no-research sets research.enabled (new project default: the trusted setup choice, else off) and --autonomy off skips the autonomy inheritance, all in config.local.json; --sdlc sets sdlc.toml mode (off writes no file on a new project); advise/enforce discovers required checks from CI or literal workflow job names; --required-checks overrides discovery, and enforce without names refuses before writes; --coordination, --memory, --snapshots and --pi set their keys in config.json. On an existing project only a flag you give changes anything, and --dry-run shows each change as old -> new (--dry-run --json adds a settings array); a value equal to the current one is a no-op, an invalid value is refused with the allowed ones and nothing is written. --specs/--no-specs and --spec-review set the design-specs keys (and the AGENTS.md specs block). --track-config keeps .agenthub/config.json, routing.toml and sdlc.toml visible to git (a rule that ignores one is named and nothing is written; a routing.toml that names a machine endpoint stays ignored) and lists them to commit; --no-track-config ignores them; either sets the AGENTS.md role sentence, and neither keeps what git and the block say today. A person at a terminal who runs ahub init on a new project with no flag that sets anything and no --yes is asked each setting in turn with its default in brackets (Enter keeps it, a wrong answer asks again, and a third wrong answer ends init with nothing written), sees the plan and answers y/N; N, Ctrl-C and Ctrl-D write nothing. A peer, a live test, a pipe and --dry-run are never asked, and --yes takes the defaults. Success prints next steps to commit shared init changes, start with ahub up or ahub claude and, for advise/enforce, accept specs/departures and use guarded merge. --conductor, --planner and --reviewer (#1408) choose who conducts, plans and reviews, each on its own: the shared config.json roles are written as an explicit list for every peer whose roles change (the one that loses a role too), implementer and verifier are untouched, a peer that cannot hold the role (a headless conductor, a kind that cannot plan) is refused before any write with the reason and the eligible peers, --conductor none leaves the person conducting from ahub console and --reviewer person sends reviews to the person; Executables, secrets, models and permissions stay file edits"],
17
34
  ["ahub --live-test [--project <path|id>] <command> [args...]", "user-authorized operational console delegation; ordinary calls retain peer identity; person-authored content refuses"],
18
- ["ahub help [command]", "this help, or one command's entries; also --help and -h"],
35
+ ["ahub help [command [--ascii]]", "this help, or one command's entries; also --help and -h"],
19
36
  ["ahub version | --version", "print the installed version"],
20
37
  ["ahub completion zsh|bash|fish", "print a shell completion script; its candidates come from these help entries"],
21
38
  ]],
@@ -24,12 +41,18 @@ const SECTIONS: [string, [usage: string, description: string][]][] = [
24
41
  ["ahub console [--panels] [--color=auto|always|never]", "enter the human console; P cycles built-in pet characters/off; exiting leaves the daemon running"],
25
42
  ["ahub console --no-pet", "turn off attention for this session; combines with --panels and --color"],
26
43
  ["ahub pet [--short]", "read attention without connecting; --short prints ahub!N only when action is needed"],
44
+ ["ahub pet --window [--close]", "retired floating-window options: run acon ui and open Mini"],
27
45
  ["ahub pet --palette <blue|teal|violet|ochre>", "retired floating-window option: run acon ui and open Mini"],
28
46
  ["ahub sdlc status [task] | explain <task> [--json] [--color=auto|always|never] | export <task> | record <task> <receipt-json>", "read head-bound lifecycle gates and the next actor/action; status and explain are open to any agent as a public view (private tasks stay stubs), export and record are person only; export stays JSON"],
29
47
  ["ahub sdlc queue <owner/repo> | release <owner/repo> [live-issue...] [--json] [--color=auto|always|never]", "read-only merge and release evidence; open to any agent as public readback of the checkout's repositories, never an authorization"],
48
+ ["ahub sdlc survey start [--focus bugs|tests|debt|deps|dx|docs] [--json] [--color=auto|always|never]", "person or current conductor: file one read-only planner survey at a pinned source ref; only explicitly vetted findings produce backlog cards"],
49
+ ["ahub sdlc survey show <task> [--json] [--color=auto|always|never]", "read findings and their vet decisions; unchanged or unknown prior rejections remain rejected before, and reconsideration needs an explicit vetted reason"],
50
+ ["ahub sdlc audit start [--profile quick|standard] [--since <ref>] [--json] [--color=auto|always|never]", "file one read-only security audit task and seed its coverage ledger from [security] in sdlc.toml (person or current conductor); quick and scoped runs read as partial"],
51
+ ["ahub sdlc audit show [<audit>] [--json] [--color=auto|always|never]", "the newest (or named) audit: source, coverage counts by unit state, each unit and finding; open important finding details are shown to the person only"],
30
52
  ["ahub sdlc adopt-merge <task> --pr <n>", "record an already merged PR at the task's recorded head with green required checks and no open Important finding; approve and release dependents (person or current conductor)"],
31
53
  ["ahub sdlc merge <task> [--dry-run] [--json] [--color=auto|always|never]", "guarded squash merge of an approved task at its approved head after every gate is re-read; follows sdlc.toml auto_merge (off, dry-run, on); --dry-run only reports (person or conductor)"],
32
54
  ["ahub sdlc authorize-release <version> [--json] [--color=auto|always|never]", "approve this daemon checkout commit, configured version source and docs policy (person or unique configured conductor on the person's explicit release instruction naming the release in its own session; hub/task/review/file/peer relays never qualify; restart revokes)"],
55
+ ["ahub sdlc configure [--mode off|advise] [--required-checks names] [--json] [--color=auto|always|never]", "save only lifecycle mode/check names through loader validation and backup, pending restart (person or current unique conductor on the person's explicit instruction in its own session; enforce and other fields remain person-only; no release consent)"],
33
56
  ["ahub sdlc release-guard -- <literal git push|gh release create|npm publish argv>", "read-only authorization preflight; init --release-guard installs the tag pre-push hook"],
34
57
  ["ahub sdlc release-guard-hook <remote-name> <remote-url>", "internal pre-push readback; validates version tags and forwards exact stdin on success"],
35
58
  ["ahub sdlc accept <task> --issue <n> [--repo owner/repo]", "accept the task's spec issue at its current body; build entry needs it in enforce (person only)"],
@@ -40,10 +63,10 @@ const SECTIONS: [string, [usage: string, description: string][]][] = [
40
63
  ["ahub sdlc costs [owner/repo] [--json] [--color=auto|always|never]", "read bounded planner cost metrics for linked merged PRs"],
41
64
  ["ahub sdlc metrics [--since <YYYY-MM-DD|ISO time>] [--json] [--color=auto|always|never]", "read SDLC metrics and control band tiers from board history (planner or person; read-only)"],
42
65
  ["ahub backlog groom | return <task> <revision> <reason...> [--reserved <peer> | --unreserve] [--json] [--color=auto|always|never]", "read grooming findings or return accepted untouched work to backlog (planner/person); --reserved names the peer the card is reserved for as it goes back, --unreserve clears the reservation (a person's reservation needs the person)"],
43
- ["ahub status [--json] [--full] [--color=auto|always|never]", "the hub, its peers, model backends and task counts, plus a specs line (errors and stale documents) when the project has design specs"],
66
+ ["ahub status [--json] [--full] [--verbose] [--ascii] [--color=auto|always|never]", "is the hub OK, and what to do next: an Attention list (each item with its next command), then the hub, peers and tasks; --verbose or --full prints every detail (model backends, specs, queue pressure, schedules, per-peer notes)"],
44
67
  ["ahub status --all [--json] [--color=auto|always|never]", "show every registered project"],
45
68
  ["ahub logs [-f]", "person: last 100 hub.log lines (-f starts at 10); conductor: bounded public lines and follow while authority remains"],
46
- ["ahub doctor [--json] [--full] [--color=auto|always|never]", "check the tools, daemon, plugin, gateway, models, memory library and memory capture setup (read from `amem setup <tool> --json`, a preview) this project uses, and the runtime capture pruning ledger; warn when the CLI or plugin is older than its running daemon"],
69
+ ["ahub doctor [--json] [--full] [--ascii] [--color=auto|always|never]", "check the tools, daemon, plugin, gateway, models, memory library and memory capture setup (read from `amem setup <tool> --json`, a preview) this project uses, the runtime capture pruning ledger, whether the shared config.json tracking matches the AGENTS.md roles sentence, and who holds conductor, planner and reviewer as the loader settled them (a warning, never a failure); warn when the CLI or plugin is older than its running daemon"],
47
70
  ["ahub doctor --stale-anchors [--json]", "read-only bounded report of public memory symbol anchors at current HEAD; private or unavailable evidence stays unknown"],
48
71
  ["ahub doctor --orphans [--kill] [--json] [--color=auto|always|never]", "person: inspect missing-root registrations; conductor --kill: selected project only; signed hub ownership is required before any stop"],
49
72
  ["ahub agents [--json]", "show each gated agent CLI's installed version and verdict (verified, in-line, trusted, refused or unknown)"],
@@ -75,9 +98,10 @@ const SECTIONS: [string, [usage: string, description: string][]][] = [
75
98
  ["ahub tail", "live stream of messages, states and permission requests"],
76
99
  ["ahub permission [<peer> [ask|ask-when-needed|never-ask]] [--yes]", "human only: inspect or set a running peer mode; never-ask requires --yes; config never-ask waits for console y"],
77
100
  ["ahub permit <id> <option>", "answer a permission request shown by tail (\"deny\" cancels)"],
78
- ["ahub answer [<set> <question>=<option>[,<option>]... [--other [<question>=]<text>]] [--json] [--color=auto|always|never]", "person only: without operands list the questions agents asked with hub_ask; with them answer one set (every question once, known options only, other text only where offered)"],
101
+ ["ahub answer [<set> <question>=<option>[,<option>]... [--other [<question>=]<text>] [--instructed <quote>]] [--json] [--color=auto|always|never]", "without operands list open hub_ask questions; with them the person answers one set. Only the configured conductor may use --instructed on the person's explicit instruction in its own session (#1328); never its own set or a relayed instruction"],
79
102
  ["ahub results [--unread] [--read <id> | --read-all | --unread-last] [--json] [--color=auto|always|never]", "person only: list what the runs you started left behind (unread ones marked *); --read marks one read, --read-all every one, --unread-last lights the most recent read one again; listing never marks anything"],
80
- ["ahub roster [--json] [--color=auto|always|never]", "every known peer, participation, start mode and retained work"],
103
+ ["ahub roster [list] [--json] [--color=auto|always|never]", "every known peer, participation, start mode and retained work"],
104
+ ["ahub roles [--json] [--color=auto|always|never]", "each rostered peer's flow roles as the running hub settled them, the planner and who reviews when no reviewer can run; works from a task worktree"],
81
105
  ["ahub roster add <peer> | remove <peer> [--yes] [--now]", "person or configured conductor: change live participation through settings; removal previews retained messages and task handoff; remove also deletes the roster key of an instance no longer declared"],
82
106
  ["ahub autonomy on [--all-projects] [--yes] | off [--all-projects] | status [--json]", "person only: apply the autonomy preset and machine default with one confirmation, optionally to every registered project; off removes fixed preset keys (manual edits included); status reports modes, floor enforcement and Claude homes; settings undo restores a live-hub project write"],
83
107
  ["ahub model set <peer> <model> | clear <peer> | list [--json]", "person only: select a runtime model at the next turn, clear its override, or inspect effective models and pending changes; unsupported peers need a restart"],
@@ -97,6 +121,13 @@ const SECTIONS: [string, [usage: string, description: string][]][] = [
97
121
  ["ahub task propose [--class <c> | <class>] <title...> [--owner <peer>] [--path <p>]... [--after <id>]... [--urgent] [--needs-network] [--needs-worktree] [--backlog] [--detail <text>]", "put a task on the board; --needs-network keeps it away from a peer whose shell has none; --needs-worktree keeps it away from a sandboxed peer unless the hub can make the task worktree for it (it makes it, commits and pushes at done); a first word that names a class is taken as the class; while a task named by --after is not approved yet, --owner reserves the task for that peer, offered to it first once it is ready; otherwise --owner assigns it now"],
98
122
  ["ahub task handoff --list | --sync | --project <root|id> [<class>] <title...> [--path <p>]... [--issue <n>] [--task <n>] [--detail <text>] [--duplicate-ok <reason>] [--key <uuid>] [--json] [--color=auto|always|never]", "person only: register work that belongs to ANOTHER project that runs agent-hub on that project's board (an ownerless proposal its own roles take from there); the target must be registered and running, nothing is queued; a feature or behavior change first needs a spec issue there (--issue), and an issue that already has an open task there is refused with those ids unless --duplicate-ok <reason>; a handoff the target did not confirm is reported as outcome_unknown with a key, and --key <uuid> files the same request once; --list shows each handoff with its age and whether its target is reachable (reachable, unreachable with the cause, or moved), and --sync asks every target now instead of at the next 5-minute pass; its state changes show in ahub board --handoffs (an agent that hands off gets them as task messages)"],
99
123
  ["ahub backlog list [--json] [--full] [--color=auto|always|never] | add <class> <title...> | plan <id> <revision> <fields-json> <reason...> | pin <id> <revision> true|false <reason...> | person <id> <revision> true|false <reason...> | undo <id> <revision> [--json] [--color=auto|always|never]", "person only: plan work with a reason; {} records a note-only revision, fields.sdlc sets backlog repo/issue identity and clears old spec acceptance; preserve pins/frozen scope and refuse stale edits; person marks a leg only the person can run (live receipts, their accounts or approvals): no agent is offered it, auto pull and the idle sweep skip it, and it counts toward no planner WIP; list is by rank and shows it as waiting on the person (--json: raw listing)"],
124
+ [`ahub roadmap ${ROADMAP_FORMS.list} | ${ROADMAP_FORMS.show}`, "read public milestone membership and computed progress; private work is a count, unavailable evidence stays unknown"],
125
+ [`ahub roadmap ${ROADMAP_FORMS.new}`, "planner or conductor: create a milestone without GitHub writes or roadmap model calls"],
126
+ [`ahub roadmap ${ROADMAP_FORMS.edit}`, "edit at the current revision; reload roadmap show after a stale-revision refusal"],
127
+ [`ahub roadmap ${ROADMAP_FORMS.link} | ${ROADMAP_FORMS.unlink} | ${ROADMAP_FORMS.order} | ${ROADMAP_FORMS.state}`, "planner or conductor: link and order; done and dropped require the person"],
128
+ [`ahub roadmap ${ROADMAP_FORMS.unplaced}`, "read open issues, tasks and active or draft specs no milestone places, each with why; private tasks are a count; partial means a lower bound"],
129
+ [`ahub roadmap ${ROADMAP_FORMS.triage} | ${ROADMAP_FORMS.accept} | ${ROADMAP_FORMS.reject}`, "planner or conductor: the hub model suggests a milestone for unplaced work, citing ids and words; nothing is linked until accept"],
130
+ [`ahub roadmap ${ROADMAP_FORMS.importGithub}`, "person only: create proposed milestones from open GitHub milestones and link their issues; a dry run unless --apply, idempotent, never writes GitHub"],
100
131
  ["ahub release new <name> <goal> <order> | list | show <name> | plan <name> <revision> <dates-json> | activate|freeze|ship|drop <name> <revision> [--json] [--color=auto|always|never]", "person only, except show (any agent, public metadata): planned UTC millisecond dates and phased scope; ship records a time after approval, never tags or publishes"],
101
132
  ["ahub backlog split <id> <revision> <parts-json> <reason...> [--json] [--color=auto|always|never]", "person only: stage2..8 child prerequisites; original task retains integration, undo refuses used or changed children"],
102
133
  ["ahub backlog pull-ready <id> <revision> <reason...> [--json] [--color=auto|always|never]", "person only: reserve an eligible WIP slot before routing; pending unowned work can be undone"],
@@ -114,6 +145,7 @@ const SECTIONS: [string, [usage: string, description: string][]][] = [
114
145
  ["ahub capabilities [--json] [--color=auto|always|never]", "person only, never a conductor or an agent shell: list the skills and commands each attached peer offers (Kimi 2.3.2 and Qwen 0.26.1 sessions, Codex 0.166.0 skills; other versions list nothing), whether you share each one, its digest and the class a call would count as; sharing is invocation.share in .agenthub/config.local.json, this machine only; it only lists and never calls anything"],
115
146
  ["ahub learn list [--all] | accept <id> | reject <id> [--json] [--color=auto|always|never]", "person only, never a conductor or an agent shell: review a recurring-unmet-criterion candidate the hub filed (#514a); accept writes its one review checklist line, added to your current checklist, to .agenthub/config.local.json through the settings writer (this machine only, never a tracked file, ahub settings undo puts it back, applies after a restart) and closes the card; reject only closes it"],
116
147
  ["ahub study draft <parent> <contract.json> | revise <id> <revision> <contract.json> | approve <id> <revision> | close <id> <revision> --reason <text> | approve-protocol <hash> [--json] [--color=auto|always|never]", "person only: store a research campaign contract as a draft, revise it, approve it (the only step that creates the unit tasks and lets work start) or close it; approve-protocol binds approval to the exact protocol and evaluator hashes; a planner drafts through hub_study_draft and hub_study_revise and can never approve"],
148
+ ["ahub study evidence <ev-id> [--revision <n>] | evidence --task <task> | check <task> <manifest.json> [--json] [--color=auto|always|never]", "explicit evidence provenance and offline synthesis readiness: single-link reads reuse research scope/privacy; task inventory and check are person-only. Complete claim/link inventories and registered deliverable hashes bind the manifest. Separate citation, locator, person judgment, contradiction and artifact statuses never certify truth; a non-ready check exits nonzero"],
117
149
  ["ahub study show [<id> | --after <id>] [--json] [--color=auto|always|never]", "read-only for anyone: list this project's research campaigns, 50 per page (the page names the --after cursor that continues it), or one campaign's coverage per unit, handoff state, budget support and why dispatch is held; a private campaign, task or source shows ids, counts and states only"],
118
150
  ["ahub study experiments (--campaign <id> [--after <n>] | --attempt <ra-id> [--events-after <n>] | --plan <hash> --baseline <ra-id> --variant <ra-id>) [--json] [--color=auto|always|never]", "read-only for anyone, the same read as hub_experiment_show: a campaign's recorded attempts (50 a page, --after continues), one attempt with its events, or one comparison under a recorded plan; each value names its provenance and a declared value is never shown as observed"],
119
151
  ["ahub deliverables [--task <id>] [--approved] [--check] [--json] [--color=auto|always|never]", "what each task delivered and a reviewer approved, by id, hash and size (a path only where the PII screen allows); --check measures the files now and marks one changed since review; an agent sees only the tasks hub_task_show shows it"],
@@ -121,10 +153,10 @@ const SECTIONS: [string, [usage: string, description: string][]][] = [
121
153
  ["ahub task role <id> <role|none>", "the person, or an agent on a task it owns: change bounded catalog guidance on an open task; routing and authority are unchanged"],
122
154
  ["ahub task assign <id> <peer> [--role owner|reviewer|planner] [--revision N]", "name the owner (default), reviewer or person-only planner; a task that still waits reserves its owner; a peer that cannot take it is refused with the reason; --revision refuses stale console actions"],
123
155
  ["ahub task unassign <id> [--role owner|reviewer] [--revision N]", "person or configured conductor: remove the owner/reservation or reviewer without routing a replacement or stopping native work; preserves the actual actor"],
124
- ["ahub task claim <id> <slot> <supported|unsupported|unclear> [--model <label>] [--model-said <supported|unsupported|unclear>]", "person only: record your verdict on one declared plan claim (by its 1-based slot, never its text), with the model label and what the model said, so the research scorecard can show agreement; a later verdict for the slot replaces the earlier one"],
156
+ ["ahub task claim <id> <slot> <supported|unsupported|unclear> [--model <label>] [--model-said <supported|unsupported|unclear>] [--manifest <manifest.json> --disposition <resolved|qualified>]", "person only: record your verdict on one declared plan claim (by its 1-based slot, never its text), with optional model agreement metadata; paired manifest/disposition fields bind an adjudicated or explicitly qualified research conclusion to the exact synthesis manifest; a later verdict for the slot replaces the earlier one"],
125
157
  ["ahub task cancel <id> --reason <text> [--superseded-by <ref>] [--revision N] [--json] [--color=auto|always|never]", "the person, or an agent on its own task as hub_task_cancel allows: close obsolete work with a reason; retain its history without stopping native work or releasing dependents; eligibility follows the task-board policy"],
126
158
  ["ahub task label <id> ok|regressed|reverted|incomplete|wrong|abandoned [--created <time>]", "your later verdict on an approved task, kept in the research records (research must be on); an agent labels only a task it owns, and its record names it; --created is the person's"],
127
- ["ahub review <id> approved|changes_requested [note...] [--unmet <item>]... [--head <sha>] [--findings <json>]", "give a review verdict on a task; the person can do the same in ahub console: Tasks, select the task, r, then a (approve) or c (request changes, with a note)"],
159
+ ["ahub review <id> approved|changes_requested [note...] [--unmet <item>]... [--head <sha>] [--findings <json>] [--security-pass <json>]", "give a review verdict on a task; the person can do the same in ahub console: Tasks, select the task, r, then a (approve) or c (request changes, with a note)"],
128
160
  ["ahub review brief <id>", "print the review brief of a task's commit: reviewable and excluded files, rules, coverage to account for"],
129
161
  ["ahub route explain <id>", "why a task went where it went, its reserved owner and the planner walk included"],
130
162
  ["ahub route explain --class <c> <title...>", "what would happen to such a task now"],
@@ -132,14 +164,14 @@ const SECTIONS: [string, [usage: string, description: string][]][] = [
132
164
  ["ahub remember <text...>", "save a note to the memory all agents share"],
133
165
  ]],
134
166
  ["Budget", [
135
- ["ahub budget [--json] [--full] [--color=auto|always|never]", "quota windows per peer with each number's kind (native, count, manual) and source, why a peer shows no number, and who is paused until when"],
167
+ ["ahub budget [--json] [--full] [--color=auto|always|never]", "quota windows per peer with each number's kind (native, count, manual) and source, why a peer shows no number, who is paused until when, and the reviewer quota admission rule"],
136
168
  ["ahub budget set <peer> <0..1> [--resets-in 30m] [--window 5h|week]", "feed a reading by hand (also: test the relay)"],
137
169
  ["ahub budget resume <peer>", "override a budget pause; readings are ignored for that peer until the window resets"],
138
170
  ["ahub budget execution status [id] [--json] [--color=auto|always|never]", "read execution counters and limits"],
139
171
  ["ahub budget execution configure <config.json> | disable <id> [--json] [--color=auto|always|never]", "opt-in limits on model calls, tool calls, time and tokens for pi and local"],
140
172
  ]],
141
173
  ["History and reports", [
142
- ["ahub guidance probe register --file JSON [--json] | start --id HASH --revision N [--variant G1-HASH] [--json] | show --id HASH [--json] | receipts --id HASH [--json] | cancel --id HASH --revision N [--json]", "person or configured conductor only: bounded T1 declaration and fake-only probe lifecycle; receipts reads the sealed receipts, the outcome denominator and the comparability reasons, read-only; production execution is unavailable"],
174
+ [`ahub guidance probe ${Object.values(GUIDANCE_PROBE_USAGE).join(" | ")}`, "person or configured conductor only: bounded T1 declaration and fake-only probe lifecycle; receipts reads the sealed receipts, the outcome denominator and the comparability reasons, read-only; production execution is unavailable"],
143
175
  ["ahub guidance create --file JSON [--json]", "record a bounded immutable advisory proposal through current task authority; no activation or probe"],
144
176
  ["ahub guidance list --task N --task-created MS [--cursor TOKEN] [--json]", "bounded guidance metadata pages; withdrawn history and withheld fields remain explicit"],
145
177
  ["ahub guidance show --task N --task-created MS --id HASH [--json]", "screened editable-section diff selected by existing variant id, never a displayed experiment label"],
@@ -190,12 +222,12 @@ const SECTIONS: [string, [usage: string, description: string][]][] = [
190
222
  export function helpEntries(definitions: readonly AdapterDefinition[] = ADAPTERS): readonly HelpEntry[] {
191
223
  const byKind = new Map(definitions.map(definition => [definition.kind, definition]));
192
224
  const order = deriveAdapterLists(definitions).HELP_ORDER;
193
- const native = order.flatMap(kind => byKind.get(kind)?.cli.usage ?? []);
225
+ const native: readonly (readonly [string, string, string?])[] = order.flatMap(kind => byKind.get(kind)?.cli.usage ?? []);
194
226
  const instanceKinds = order.filter(kind => byKind.get(kind)?.instances !== undefined);
195
227
  const instances: readonly [string, string] = [`ahub ${instanceKinds.join("|")} --as <instance> [options...]`, "start an extra instance of that kind declared under instances in .agenthub/config.local.json"];
196
228
  return SECTIONS.flatMap(([section, rows]) => {
197
- const entries: readonly (readonly [string, string])[] = section === "Agents" ? [rows[0]!, ...native, ...(instanceKinds.length ? [instances] : []), ...rows.slice(1)] : rows;
198
- return entries.map(([usage, description]) => ({ section, usage, description }));
229
+ const entries: readonly (readonly [string, string, string?])[] = section === "Agents" ? [rows[0]!, ...native, ...(instanceKinds.length ? [instances] : []), ...rows.slice(1)] : rows;
230
+ return entries.map(([usage, description, summary]) => ({ section, usage, description, ...(summary ? { summary } : {}) }));
199
231
  });
200
232
  }
201
233
  export const HELP = helpEntries();
@@ -206,32 +238,320 @@ export function helpCommands(entry: HelpEntry): string[] {
206
238
  return COMMAND.exec(entry.usage)?.[1]!.split(/ ?\| ?/) ?? [];
207
239
  }
208
240
 
241
+
242
+ /**
243
+ * CLI output standard v1, Help: the overview lists each command once per group as ` <name> <one-line summary>` in two aligned columns; the long text, every usage form
244
+ * and every flag are in `ahub help <command>`. A summary is at most SUMMARY_MAX cells. A command not named here (the native agents, whose text comes from their
245
+ * adapter definitions, never from a table that names a peer) takes the first clause of its description. `<group>/<command>` wins over `<command>` where one name
246
+ * means two things (`backlog`, `check-path`).
247
+ */
248
+ const SUMMARY_MAX = 56;
249
+ const SUMMARIES: Readonly<Record<string, string>> = {
250
+ specs: "read design specs and check their freshness", worktrees: "list worktrees, preview and confirm cleanup", "--project": "run a command against another project",
251
+ projects: "list registered projects and live status", setup: "install the plugin and hooks, choose default agents", init: "write .agenthub/config.json and the AGENTS.md block",
252
+ "--live-test": "user-authorized console delegation (person only)", help: "this overview, or one command's usage", version: "print the installed version", completion: "print a shell completion script",
253
+ up: "start the daemon and this project's default agents", console: "open the human console", pet: "read attention without connecting", sdlc: "read lifecycle gates and the next action",
254
+ "Daemon and runtime/backlog": "return accepted untouched work to the backlog", status: "is the hub OK, and what to do next", logs: "show the hub log", doctor: "check tools, daemon, plugin, models and memory",
255
+ agents: "show each agent CLI's version and verdict", kill: "stop this project's hub", down: "stop this project's hub (same as kill)", reset: "discard queued deliveries and clear holds",
256
+ restart: "recover this project's runtime", upgrade: "review and upgrade this project", recovery: "inspect, resume or abort a held operation",
257
+ daemon: "internal: the detached hub process", "recovery-run": "internal: a detached recovery runner",
258
+ role: "read catalog guidance for a role", stop: "stop a hub-owned headless peer", peer: "hand the attached session to a standby", models: "inspect local model state",
259
+ say: "send a message as the console user", watch: "watch a headless ACP peer's activity", tail: "live stream of messages and states", permission: "inspect or set a peer's permission mode",
260
+ permit: "answer a permission request", answer: "list and answer open hub_ask questions", results: "list what your runs left behind", roster: "every known peer and its participation",
261
+ roles: "each peer's flow roles, planner and reviewers", autonomy: "apply the autonomy preset", model: "select or inspect runtime models", settings: "list, read and change settings",
262
+ pause: "hold or release a peer's deliveries", title: "rename a Pi or local-worker session", queue: "inspect and resolve durable deliveries",
263
+ board: "show the task board, import open issues", task: "put tasks on the board and move them along", "Tasks and review/backlog": "plan, pull and return backlog cards", roadmap: "milestones and their computed progress",
264
+ release: "plan and ship releases", smoke: "live smoke test in a temporary project", broker: "run the ciphertext relay for rooms", room: "encrypted rooms between hubs (person only)",
265
+ source: "register inputs as content-hashed sources", schedule: "list and run machine-local schedules", intake: "turn a plain request into a draft backlog card",
266
+ capabilities: "list the skills each attached peer offers", learn: "review recurring-criterion candidates", study: "research campaign contracts",
267
+ deliverables: "what each task delivered and a reviewer approved", review: "give a review verdict on a task", route: "why a task went where it did",
268
+ ask: "answer from the board, memory and the log", remember: "save a note to shared memory", budget: "quota windows per peer and why one is paused",
269
+ guidance: "guidance declarations and the probe lifecycle", lineage: "execution metadata and evidence strengths", turns: "recent turns and the files each changed",
270
+ undo: "put back the files a turn changed", report: "turns, tokens, messages and task events", usage: "tokens per group from the roll-up", export: "events as JSON lines",
271
+ research: "success and rework rates per approved task", bench: "run a benchmark suite against attached peers", "History and reports/check-path": "other owners' open tasks that claim a file",
272
+ memory: "the hub's own project memory", goal: "long-term tasks and who holds them", "Hooks/check-path": "Claude PreToolUse hook for file claims", facts: "Claude hook for turn-free facts",
273
+ ui: "open the local dashboard", manager: "internal: the dashboard manager process",
274
+ };
275
+ /** The first clause of a description, cut at a word and ended with `...` when it is longer than the column: the whole text is `ahub help <command>`. */
276
+ function firstClause(description: string, max: number): string {
277
+ const clause = description.replace(/\s*\([^)]*\)/g, "").split(/;(?= )|\. /)[0]!.trim();
278
+ if (Bun.stringWidth(clause) <= max) return clause;
279
+ // A clause that is too long ends where its sentence first pauses (`:` or `, `) when that leaves a readable summary; otherwise it is cut at a word and ended with `...`.
280
+ const pause = clause.search(/: |, /);
281
+ if (pause >= 8 && Bun.stringWidth(clause.slice(0, pause)) <= max) return clause.slice(0, pause);
282
+ let out = "";
283
+ for (const word of clause.split(" ")) { if (Bun.stringWidth(`${out} ${word}`.trim()) > max - 3) break; out = `${out} ${word}`.trim(); }
284
+ return `${out.replace(/[,:;\s]+$/, "")}...`;
285
+ }
286
+ /** One overview row: the command words an entry documents (`pause|resume`), and its one-line summary. */
287
+ export interface OverviewRow { section: string; name: string; summary: string }
288
+ export function helpOverviewRows(entries: readonly HelpEntry[] = HELP): OverviewRow[] {
289
+ const shown = new Map<string, Set<string>>(), rows: OverviewRow[] = [];
290
+ for (const entry of entries) {
291
+ const seen = shown.get(entry.section) ?? shown.set(entry.section, new Set()).get(entry.section)!;
292
+ const fresh = helpCommands(entry).filter(word => !seen.has(word));
293
+ if (!fresh.length) continue;
294
+ fresh.forEach(word => seen.add(word));
295
+ const own = (word: string) => SUMMARIES[`${entry.section}/${word}`] ?? SUMMARIES[word];
296
+ const summary = own(fresh[0]!) ?? entry.summary ?? firstClause(entry.description, SUMMARY_MAX);
297
+ rows.push({ section: entry.section, name: fresh.join("|").replace(/^version\|--version$/, "version|--version"), summary: Bun.stringWidth(summary) > SUMMARY_MAX ? firstClause(summary, SUMMARY_MAX) : summary });
298
+ }
299
+ return rows;
300
+ }
301
+
302
+ /**
303
+ * #1504 T2, one example or more per command that takes arguments: complete, copyable, and only ever a form, subcommand and flag the command's own usage lists
304
+ * (`test/help.test.ts` runs each against the dispatch table and the usage). A native agent's example is derived from its definition's usage, never named here.
305
+ * Internal commands (`daemon`, `recovery-run`, `manager`, `facts`) have none: nobody types them.
306
+ */
307
+ export const EXAMPLES: Readonly<Record<string, readonly string[]>> = {
308
+ specs: ["ahub specs check --require-fresh", "ahub specs covers src/cli/help.ts"], worktrees: ["ahub worktrees tidy"], "--project": ["ahub --project ../other-repo status"],
309
+ projects: ["ahub projects --json"], "--live-test": ["ahub --live-test status"], setup: ["ahub setup --agents claude,codex"], init: ["ahub init --profile dev --sdlc advise --dry-run --json"],
310
+ help: ["ahub help task"], completion: ["ahub completion zsh"],
311
+ up: ["ahub up --no-console"], console: ["ahub console --panels"], pet: ["ahub pet --short"],
312
+ sdlc: ["ahub sdlc status 12", "ahub sdlc explain 12 --json"], backlog: ["ahub backlog list --full", "ahub backlog return 12 3 waiting on a spec"],
313
+ status: ["ahub status --verbose"], logs: ["ahub logs -f"], doctor: ["ahub doctor --json"], agents: ["ahub agents --json"],
314
+ reset: ["ahub reset"], restart: ["ahub restart --dry-run"], upgrade: ["ahub upgrade --dry-run"], recovery: ["ahub recovery status"],
315
+ role: ["ahub role list"], stop: ["ahub stop pi"], peer: ["ahub peer takeover codex"], models: ["ahub models status"],
316
+ say: ["ahub say @codex please rebase on main"], watch: ["ahub watch kimi"], permission: ["ahub permission codex ask-when-needed"],
317
+ permit: ["ahub permit 7 deny"], answer: ["ahub answer"], results: ["ahub results --unread"], roster: ["ahub roster --json"], roles: ["ahub roles --json"],
318
+ autonomy: ["ahub autonomy status"], model: ["ahub model list"], settings: ["ahub settings list"], pause: ["ahub pause codex"], resume: ["ahub resume codex"],
319
+ title: ["ahub title pi release review"], queue: ["ahub queue list --peer codex"], board: ["ahub board --ready"],
320
+ task: ["ahub task show 12", "ahub task propose implement Fix the flaky test --path test/a.test.ts"], roadmap: ["ahub roadmap show 3"], release: ["ahub release list"],
321
+ smoke: ["ahub smoke run qwen-dual-output --project-id 1f3a --receipt receipt.json"], broker: ["ahub broker serve --port 8787"], room: ["ahub room list"],
322
+ source: ["ahub source list"], schedule: ["ahub schedule list"], intake: ["ahub intake \"Add a dark mode toggle\""], capabilities: ["ahub capabilities --json"], learn: ["ahub learn list"],
323
+ study: ["ahub study show --json"], deliverables: ["ahub deliverables --task 12 --check"], review: ["ahub review 12 approved looks good", "ahub review brief 12"],
324
+ route: ["ahub route explain 12"], ask: ["ahub ask what blocks task 12"], remember: ["ahub remember Pi 1.5.2 is verified"], budget: ["ahub budget --full"],
325
+ guidance: ["ahub guidance list --task 12 --task-created 1760000000000"], lineage: ["ahub lineage show --task 12"], turns: ["ahub turns codex --limit 5"],
326
+ undo: ["ahub undo 42"], report: ["ahub report --since 7d"], usage: ["ahub usage --by peer --since 7d"], export: ["ahub export --since 7d"], research: ["ahub research --since 30d"],
327
+ bench: ["ahub bench list"], "check-path": ["ahub check-path src/cli/help.ts"], memory: ["ahub memory search sweep"], goal: ["ahub goal list"], ui: ["ahub ui --no-open"],
328
+ };
329
+ /** Commands nobody types: a process the hub starts, or a hook a tool calls. They have no example. */
330
+ export const INTERNAL_COMMANDS: readonly string[] = ["daemon", "recovery-run", "manager", "facts"];
331
+
332
+ /** One example per native agent, from its own definition: `ahub <kind> --print-command` when its usage has that flag (it prints the launch and starts nothing), else the bare command. */
333
+ function nativeExample(command: string, entries: readonly HelpEntry[]): string[] {
334
+ const own = entries.find(entry => entry.section === "Agents" && helpCommands(entry).includes(command) && entry.summary !== undefined);
335
+ return own ? [own.usage.includes("--print-command") ? `ahub ${command} --print-command` : `ahub ${command}`] : [];
336
+ }
337
+
338
+ /** A flag of a command's usages: its value shape as the usage writes it, and the subcommand forms it appears in (empty for the command's base form). */
339
+ export interface HelpFlag { flag: string; shape: string; /** `=` or a space: how the usage joins the flag and its value, kept so the Flags line reads as the usage does. */ joiner: "=" | " "; forms: string[] }
340
+ const FLAG = /(?<![\w-])(-{1,2}[A-Za-z][A-Za-z0-9-]*)(?:=([^\s\]()]+)| (<[^>]+>|[A-Z][A-Za-z]*\b|N\b|[a-z0-9_,.-]+(?:\|[a-z0-9_,.<>-]+)+))?/g;
341
+ /** Every flag the usages of `command` name, in the order they first appear, once each. */
342
+ export function helpFlags(command: string, entries: readonly HelpEntry[] = HELP): HelpFlag[] {
343
+ const found = new Map<string, HelpFlag>();
344
+ for (const entry of entries.filter(entry => helpCommands(entry).includes(command))) {
345
+ const prefix = COMMAND.exec(entry.usage)?.[0] ?? "";
346
+ let lead = "";
347
+ topLevelPieces(entry.usage).forEach((piece, index) => {
348
+ const body = index === 0 ? piece.slice(prefix.length).trim() : piece;
349
+ const token = body.split(/\s/)[0]!.replace(/[\[\]]/g, "");
350
+ const named = token.split("|").filter(word => /^[a-z][a-z0-9-]*$/.test(word)).join("|");
351
+ // #1504: a piece after ` | ` that starts with a flag or an argument (`task handoff --list | --sync | --project <root|id> ...`) is another way into the form the first piece named
352
+ if (index === 0) lead = named;
353
+ const form = named || lead;
354
+ for (const match of body.matchAll(FLAG)) {
355
+ const flag = match[1]!, shape = match[2] ?? match[3] ?? "", joiner = match[2] !== undefined ? "=" as const : " " as const;
356
+ const seen = found.get(flag) ?? found.set(flag, { flag, shape, joiner, forms: [] }).get(flag)!;
357
+ if (!seen.shape && shape) { seen.shape = shape; seen.joiner = joiner; }
358
+ if (form && !seen.forms.includes(form)) seen.forms.push(form);
359
+ }
360
+ });
361
+ }
362
+ return [...found.values()];
363
+ }
364
+ /**
365
+ * #1504 AC3: what each flag is for, one short line, kept beside the usage text it describes (never a second table keyed by peer). The two flags the standard itself defines
366
+ * (`--json`, `--color`, `docs/design/cli-output.md`) keep their longer text; every other line is at most `FLAG_LINE` cells, so it fits beside the longest label at 80 columns.
367
+ * A key is a flag, or `<command> <flag>` where one command's flag is for something other than the flag's own entry. A flag with no entry (one a definition outside this
368
+ * file adds) falls back to the forms that take it, and `test/help.test.ts` fails a flag of any command in this file that has no line.
369
+ */
370
+ export const FLAG_DESCRIPTIONS: Readonly<Record<string, string>> = {
371
+ "--json": "one JSON document on stdout, never colored",
372
+ "--color": "auto, always or never; auto follows NO_COLOR, FORCE_COLOR and the terminal",
373
+ // in many commands
374
+ "--yes": "confirm without asking", "--full": "whole titles and every detail", "--verbose": "print every detail", "--ascii": "use ASCII markers", "--dry-run": "report what would happen, change nothing",
375
+ "--preview": "show the change, save nothing", "--now": "apply now, not at the next start", "--apply": "write it; without this only a preview",
376
+ "--reason": "why, recorded with the change", "--revision": "revision acted on; a stale one is refused", "--limit": "at most this many rows", "--since": "start of the period: 7d or an ISO time",
377
+ "--task": "task number it concerns", "--issue": "GitHub issue number", "--pr": "pull request number", "--repo": "repository as owner/name", "--peer": "this peer only", "--project": "project path or id",
378
+ "--label": "label to use", "--model": "model alias or id to run with", "--class": "task class, such as implement", "--format": "jsonl or csv", "--list": "list instead of acting", "--confirm": "fingerprint that confirms this action",
379
+ "--action": "the resolution to apply", "--by": "how to group the rows", "--file": "JSON file to read", "--id": "id hash of the item", "--cursor": "continue from this page token", "--variant": "variant id",
380
+ "--attempt": "attempt id (ra-...)", "--task-created": "creation time of the task, in milliseconds", "--owner": "peer that owns the task", "--after": "wait for this task id (repeatable)", "--milestone": "milestone to use",
381
+ // setup, init and sdlc
382
+ "--require-fresh": "also fail on stale documents", "--base": "compare against this git ref", "--agents": "agents ahub up starts", "--research": "turn research records on", "--no-research": "turn research records off",
383
+ "--profile": "role profile or pack", "--sdlc": "SDLC mode: off, advise or enforce", "--required-checks": "CI check names that must pass", "--coordination": "advisory or turn-free", "--memory": "turn shared memory on",
384
+ "--no-memory": "turn shared memory off", "--snapshots": "turn per-turn snapshots on", "--no-snapshots": "turn per-turn snapshots off", "--pi": "turn the Pi peer on", "--no-pi": "turn the Pi peer off",
385
+ "--specs": "turn design specs on", "--no-specs": "turn design specs off", "--spec-review": "how covering specs are reviewed", "--conductor": "the peer that conducts, or none", "--planner": "peers that plan",
386
+ "--reviewer": "peers that review, or person", "--track-config": "share config.json through git", "--no-track-config": "keep config.json out of git", "--autonomy": "inherit the machine preset, or not",
387
+ "--shadow": "hub-owned snapshots for a non-git folder", "--release-guard": "install the tag pre-push hook", "--focus": "area the survey looks at", "--review": "review scope: full, delta or none",
388
+ "--reviewers": "number of reviewers", "--ci": "CI scope: full, focused or reuse", "--reserved": "reserve the card for this peer", "--unreserve": "clear the card's reservation", "--to": "version to upgrade to",
389
+ "--version": "print the installed version",
390
+ // daemon, agents and recovery
391
+ "--unattended": "no permission prompts; the agent acts alone", "--no-console": "do not enter the console", "--no-agents": "do not start the default agents", "--panels": "start in panels mode",
392
+ "--no-pet": "turn the attention pet off", "--short": "print ahub!N only when action is needed", "--palette": "retired: run acon ui and open Mini", "pet --window": "retired: run acon ui and open Mini", "--close": "retired: no window is opened", "-f": "follow new lines",
393
+ "--stale-anchors": "report stale memory symbol anchors", "--orphans": "inspect registrations whose root is gone", "--kill": "stop the selected orphan's hub", "--revoke": "withdraw a trusted version",
394
+ "--fresh-session": "restart the peer as a new session", "--stop-and-archive": "stop its targets and archive the snapshot", "--print-command": "print the launch command, start nothing", "--as": "name of the extra instance",
395
+ "--mode": "tui or headless", "--session-id": "session id to resume or pin", "--provider-profile": "Jcode provider profile to use", "--headless": "run without a terminal", "--backend": "Pi backend: auto, dgx or mlx",
396
+ "--session-file": "Pi session file to open", "--replace-session": "replace the saved session", "--route": "routing.toml route to use", "--group": "only this catalog group", "--no-thoughts": "hide the peer's reasoning lines",
397
+ // messages, approvals and settings
398
+ "--other": "answer in free text, not an option", "--instructed": "the person's quote the conductor acts on", "--unread": "only unread results", "--read": "mark one result read", "--read-all": "mark every result read",
399
+ "--unread-last": "mark the latest read one unread", "--all-projects": "apply to every registered project", "--state": "only deliveries in this state",
400
+ // tasks, roadmap, rooms and broker
401
+ "--ready": "only tasks with nothing left to wait for", "--columns": "show the tasks as board columns", "--release": "only this release, by name", "--release-id": "only this release, by id", "--handoffs": "show work handed to other projects",
402
+ "--path": "file the task touches (repeatable)", "--urgent": "mark the task urgent", "--needs-network": "keep it from a peer with no network", "--needs-worktree": "keep it from a sandboxed peer", "--backlog": "stage it in Backlog, unoffered",
403
+ "--detail": "longer text of the task", "--sync": "sync handoff states from the targets", "--duplicate-ok": "file despite an open task, with a reason", "--key": "idempotency key (a UUID) for the handoff",
404
+ "--role": "owner, reviewer or planner", "--model-said": "what the model said about the claim", "--manifest": "synthesis manifest the verdict binds to", "--disposition": "resolved or qualified",
405
+ "--superseded-by": "work that replaces this task", "--created": "when the label applies (person only)", "--title": "milestone title", "--outcome": "the outcome the milestone delivers", "--horizon": "now, next or later",
406
+ "--order": "position among its siblings", "--target": "target date (YYYY-MM-DD) or none", "--parent": "parent milestone id, or none", "--project-id": "id of the disposable project", "--receipt": "file to write the receipt to",
407
+ "--timeout-ms": "time limit, 100 to 120000 ms", "--hostname": "interface to listen on", "--port": "port to listen on", "--public-url": "public ws or wss URL", "--state-dir": "directory for the relay's state",
408
+ "--broker": "relay URL", "--accept": "request to accept", "--name": "name to join the room under", "--roster": "signed roster to join with", "--frame": "digest of the incoming frame", "--source": "registered src: id (repeatable)",
409
+ "--campaign": "campaign id", "--events-after": "continue its events after this number", "--plan": "plan hash to compare under", "--baseline": "baseline attempt id", "--approved": "only approved tasks",
410
+ "--check": "measure the files now, mark changed ones", "--unmet": "criterion not met (repeatable)", "--head": "head commit SHA the verdict is for", "--findings": "findings as JSON", "--security-pass": "security pass result as JSON",
411
+ // history, reports and memory
412
+ "--remember": "also save the answer to memory", "--resets-in": "when the window resets, such as 30m", "--window": "5h or week", "--root": "execution root reference as JSON", "--task-scope": "task the root is scoped to",
413
+ "--nodes": "at most this many nodes", "--edges": "at most this many edges", "--bytes": "at most this many bytes", "--ref": "execution reference as JSON", "--from": "reference the link comes from, as JSON",
414
+ "--context": "also drop a Codex turn from its conversation", "--dogfood": "print the dogfood scorecard", "--dataset": "directory for the per-project datasets", "--arm": "label of the arm being run", "--repeat": "attempts per task",
415
+ "--tasks": "run only these tasks (a,b)", "--addon": "declare an add-on: name=on or name=off", "--suite": "suite to compare", "--mixed": "compare across suites", "--tier": "short or long term", "--kind": "decision, contract, fail or finding",
416
+ "--machine": "only entries from this machine", "--hops": "graph depth: 1 or 2", "--history": "include superseded and expired entries", "--as-of": "memory as it stood at this time", "--remote": "private git remote to sync with",
417
+ "--db": "claude-mem database to read", "--restart": "revisit rows skipped under an earlier policy", "--days": "older than this many days (default 90)", "--depends": "goal it depends on (repeatable)", "--shared": "share the goal across machines",
418
+ "--force": "void other machines' claims", "--no-open": "print the link, do not open it", "--settings": "open with a settings session", "--stop": "stop the dashboard manager", "--hook": "run as a Claude Code hook; never blocks",
419
+ // a flag one command uses for something other than its own entry
420
+ "--all": "include everything, not the default subset", "status --all": "every registered project", "ui --all": "the unified project dashboard", "reset --all": "archive the state directory instead", "queue --all": "include rows already settled",
421
+ "learn --all": "include decided candidates", "research --all": "every registered project", "goal --all": "include completed goals", "sdlc --mode": "off or advise", "sdlc --profile": "audit depth: quick or standard",
422
+ "sdlc --since": "git ref, or a date for metrics", "memory --since": "only entries since this ISO time", "memory --label": "name for this machine", "bench --memory": "memory state: off, claude-mem, native or both",
423
+ "task --model": "model label the verdict was given under", "room --action": "accept or discard the application", "room --label": "label for your member", "room --confirm": "member fingerprint prefix",
424
+ "worktrees --confirm": "fingerprint of the preview to run", "board --label": "only issues with this label", "board --milestone": "only issues of this milestone", "board --repo": "repository to import from", "goal --milestone": "milestone of the goal (repeatable)",
425
+ "broker --owner": "owner fingerprint allowed (repeatable)", "study --after": "continue after this id", "--live-test --project": "project to run the command in", "task --project": "project to hand the work to",
426
+ "task --revision": "refuse if the task has moved on", "study --revision": "revision of the evidence to read", "usage --by": "peer, task, issue, pr, release, day or model", "report --by": "group by task", "check-path --peer": "the peer asking (default: this one)",
427
+ };
428
+ /** The widest a flag's line may be, except the standard's two flags: it sits beside the longest label (30 cells and a gap) within 80 columns. */
429
+ export const FLAG_LINE = 46;
430
+ /** What `command` says its `flag` is for: its own entry first, then the flag's. */
431
+ export function flagDescription(command: string, flag: string): string | undefined {
432
+ return FLAG_DESCRIPTIONS[`${command} ${flag}`] ?? FLAG_DESCRIPTIONS[flag];
433
+ }
434
+
209
435
  const DESCRIPTION = 34;
210
436
  /**
211
- * Usage at 2 spaces, description at one fixed column, wrapped at word boundaries to the terminal width
212
- * (80 to 100 columns). A usage too long for that column puts its description on the next line.
213
- * With a command, only its entries; an unknown command renders nothing.
437
+ * `ahub help <command>` in the standard's shape (#1504): the usage forms, a short description, each flag on one line, examples, then the long text unchanged
438
+ * (every usage form with its whole description) so nothing a form or flag says is lost. Lines are wrapped within `width`.
214
439
  */
215
- export function renderHelp(columns: number, color: boolean, command?: string, definitions?: readonly AdapterDefinition[]): string {
216
- const width = Math.min(100, Math.max(80, columns || 80));
217
- const model = definitions === undefined ? HELP : helpEntries(definitions);
218
- const entries = command === undefined ? model : model.filter(entry => helpCommands(entry).includes(command));
219
- const lines: Span[][] = command === undefined ? wrap(`agent-hub ${VERSION}: Claude Code, Codex and Kimi as peers in one project directory`, width, 0).map(text => [{ text }]) : [];
440
+ function renderCommandHelp(width: number, ascii: boolean, command: string, model: readonly HelpEntry[]): Span[][] {
441
+ const entries = model.filter(entry => helpCommands(entry).includes(command));
442
+ if (!entries.length) return [];
443
+ const report = new LayoutReport(width, ascii);
444
+ report.section("Usage");
445
+ for (const entry of entries) {
446
+ const prefix = COMMAND.exec(entry.usage)?.[0] ?? "";
447
+ const text = wrap(entry.usage, width - 2, 4);
448
+ report.append(text.map((line, index): Span[] => index === 0 ? [{ text: " " }, { text: prefix, role: "accent" }, { text: line.slice(prefix.length) }] : [{ text: " " + line }]));
449
+ }
450
+ const row = helpOverviewRows(model).find(item => item.name.split("|").includes(command));
451
+ if (row) report.section("Description").note(row.summary, "value");
452
+ const flags = helpFlags(command, model);
453
+ if (flags.length) {
454
+ report.section("Flags", String(flags.length));
455
+ const labels = flags.map(item => item.shape ? `${item.flag}${item.joiner}${item.shape}` : item.flag);
456
+ const column = Math.min(30, Math.max(...labels.map(label => Bun.stringWidth(label)))) + 2;
457
+ flags.forEach((item, index) => {
458
+ const label = labels[index]!, base = item.flag;
459
+ const meaning = flagDescription(command, base) ?? (item.forms.length ? `in ${item.forms.length > 3 ? `${item.forms.slice(0, 3).join(", ")} and ${item.forms.length - 3} more` : item.forms.join(", ")}` : "");
460
+ const room = width - 2 - column;
461
+ if (Bun.stringWidth(label) + 2 > column || !meaning) {
462
+ report.append([[{ text: " " }, { text: label, role: "accent" }]]);
463
+ if (meaning) for (const line of wrap(meaning, width - 2 - column, 0)) report.append([[{ text: " ".repeat(2 + column) + line }]]);
464
+ return;
465
+ }
466
+ const lines = wrap(meaning, room, 0);
467
+ report.append([[{ text: " " }, { text: label, role: "accent" }, { text: " ".repeat(column - Bun.stringWidth(label)) + lines[0]! }]]);
468
+ for (const line of lines.slice(1)) report.append([[{ text: " ".repeat(2 + column) + line }]]);
469
+ });
470
+ }
471
+ const examples = [...(EXAMPLES[command] ?? []), ...nativeExample(command, model)];
472
+ if (examples.length) {
473
+ report.section("Examples");
474
+ for (const example of examples) report.append(wrap(example, width - 2, 4).map((line, index): Span[] => [{ text: index === 0 ? " " : " " }, { text: line, role: index === 0 ? "accent" : "value" }]));
475
+ }
476
+ report.section("Details");
220
477
  let section = "";
221
478
  for (const entry of entries) {
222
- if (entry.section !== section) {
223
- if (lines.length) lines.push([]);
224
- lines.push([{ text: entry.section, tone: "strong" }]);
225
- section = entry.section;
226
- }
479
+ if (entry.section !== section) { section = entry.section; report.append([[{ text: ` ${entry.section}`, tone: "strong" }]]); }
227
480
  const prefix = COMMAND.exec(entry.usage)?.[0] ?? "";
228
481
  const usage = wrap(entry.usage, width - 4, 0);
229
482
  const description = wrap(entry.description, width - DESCRIPTION, 0);
230
483
  const first: Span[] = [{ text: " " }, { text: prefix, tone: "info" }, { text: usage[0]!.slice(prefix.length) }];
231
484
  if (usage.length === 1 && 2 + Bun.stringWidth(usage[0]!) + 2 <= DESCRIPTION) first.push({ text: " ".repeat(DESCRIPTION - 2 - Bun.stringWidth(usage[0]!)) + description.shift() });
232
- lines.push(first, ...usage.slice(1).map(text => [{ text: ` ${text}` }]), ...description.map(text => [{ text: " ".repeat(DESCRIPTION) + text }]));
485
+ report.append([first, ...usage.slice(1).map((text): Span[] => [{ text: ` ${text}` }]), ...description.map((text): Span[] => [{ text: " ".repeat(DESCRIPTION) + text }])]);
233
486
  }
234
- return lines.map(line => paint(line, color)).join("\n");
487
+ return report.lines();
488
+ }
489
+
490
+ /**
491
+ * Without a command, the overview. With one, `ahub help <command>` (renderCommandHelp), wrapped at word boundaries to the terminal width (80 to 100 columns);
492
+ * an unknown command renders nothing.
493
+ */
494
+ export function renderHelp(columns: number, color: boolean, command?: string, definitions?: readonly AdapterDefinition[], ascii = false): string {
495
+ const width = Math.min(100, Math.max(80, columns || 80));
496
+ const model = definitions === undefined ? HELP : helpEntries(definitions);
497
+ // The overview is a fixed 80 columns (standard v1, Help): its rows are short, so a wider terminal gains nothing and every terminal reads the same text.
498
+ if (command === undefined) return renderOverview(80, color, ascii, model);
499
+ // #1504: one command is the standard's shape (usage, description, flags, examples) with the long text below it; an unknown command renders nothing.
500
+ return renderCommandHelp(width, ascii, command, model).map(line => paint(line, color)).join("\n");
501
+ }
502
+
503
+ /**
504
+ * `ahub help`: the standard's overview. One intro line, then each group (`▸ Group`) with ` <name> <summary>` rows in two aligned columns, never wider than the
505
+ * terminal (80 to 100 cells), then where the long text lives. Every command still appears; every usage form and flag is in `ahub help <command>`.
506
+ */
507
+ function renderOverview(width: number, color: boolean, ascii: boolean, entries: readonly HelpEntry[]): string {
508
+ const rows = helpOverviewRows(entries), column = Math.max(...rows.map(row => Bun.stringWidth(row.name))) + 2;
509
+ const report = new LayoutReport(width, ascii);
510
+ const out: Span[][] = wrap(`agent-hub ${VERSION}: Claude Code, Codex and Kimi as peers in one project directory`, width, 0).map(text => [{ text }]);
511
+ out.push([{ text: "Usage: ahub <command> [args] Details: ahub help <command>", role: "hint" }]);
512
+ let section = "";
513
+ for (const row of rows) {
514
+ if (row.section !== section) { section = row.section; report.section(section); }
515
+ const pad = " ".repeat(column - Bun.stringWidth(row.name));
516
+ const summary = wrap(row.summary, width - 2 - column, 0);
517
+ report.append([[{ text: " " }, { text: row.name, role: "accent" }, { text: `${pad}${summary[0]!}` }]]);
518
+ for (const more of summary.slice(1)) report.append([[{ text: " ".repeat(2 + column) + more }]]);
519
+ }
520
+ report.section("More").note("ahub help <command> shows every usage form and flag of one command; ahub --help and ahub -h print this overview", "value");
521
+ // #1504 AC1: every section title, the first included, follows one blank line. The report only blanks between its own sections, so the gap after the intro lines is added here.
522
+ return [...out, [], ...report.lines()].map(line => paint(line, color)).join("\n");
523
+ }
524
+
525
+ /** Split a usage at its top-level " | " only: a pipe inside [...] or <...> belongs to one alternative (`[--class <c> | <class>]`). */
526
+ function topLevelPieces(usage: string): string[] {
527
+ // Blank out each bracketed or angled group (same length), split the blanked text at " | ", and cut the real usage at the same widths.
528
+ const blanked = usage.replace(/\[[^\]]*\]|<[^>]*>|\([^)]*\)/g, group => " ".repeat(group.length));
529
+ const pieces: string[] = [];
530
+ let rest = usage;
531
+ for (const part of blanked.split(" | ")) { pieces.push(rest.slice(0, part.length).trim()); rest = rest.slice(part.length + " | ".length); }
532
+ return pieces;
533
+ }
534
+
535
+ /** The subcommand pieces a command documents, each with the words that name it: `ahub task show <id> | escalate <id>` has show and escalate. */
536
+ function subcommandPieces(command: string): { subs: string[]; usage: string }[] {
537
+ return HELP.filter(entry => helpCommands(entry).includes(command)).flatMap(entry => {
538
+ const prefix = COMMAND.exec(entry.usage)?.[0] ?? "";
539
+ return topLevelPieces(entry.usage).map((piece, index) => {
540
+ const body = index === 0 ? piece.slice(prefix.length).trim() : piece;
541
+ const token = body.split(/\s/)[0]!.replace(/[\[\]]/g, "");
542
+ return { subs: token.split("|").filter(word => /^[a-z][a-z0-9-]*$/.test(word)), usage: `ahub ${command} ${body}` };
543
+ });
544
+ });
545
+ }
546
+
547
+ /** #1433: whether the help lists `ahub <command> <sub>`, so `ahub <command> <sub> --help` asks for help instead of running it. Free text is never a listed subcommand: `ahub say try ls -h` stays a message. */
548
+ export function listsSubcommand(command: string, sub: string): boolean {
549
+ return subcommandPieces(command).some(piece => piece.subs.includes(sub));
550
+ }
551
+
552
+ /** The documented usage line of one subcommand, for a refusal that names it. */
553
+ export function subcommandUsage(command: string, sub: string): string | undefined {
554
+ return subcommandPieces(command).find(piece => piece.subs.includes(sub))?.usage;
235
555
  }
236
556
 
237
557
  /** Body-free configured command guidance; no native argv or environment values enter help. */