@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
@@ -1,6 +1,8 @@
1
1
  import { consoleNeeds, characterAttentionLine, attentionCommand } from "./attention.ts";
2
2
  import { CHARACTERS, petFrame, petSize, petFooterRows, type CharacterId, type PetSize, type PetPose } from "../pet/frame.ts";
3
3
  import { PEER_PALETTE } from "../ui/peer-palette.ts";
4
+ import { SGR_RESET, TONE_SGR, ROLE_SGR, MARKERS, MARKER_COLUMN, SECTION_MARKER, cellWidth, markerCell, resolveColor, asciiMarkers, streamEnv, MARKER_NAMES, type Role, type MarkerName, type ColorEnv } from "./output-standard.ts";
5
+ export { SGR_RESET, TONE_SGR, ROLE_SGR, MARKERS, MARKER_COLUMN, SECTION_MARKER, cellWidth, markerCell, resolveColor, asciiMarkers, streamEnv, MARKER_NAMES, type Role, type MarkerName, type ColorEnv };
4
6
  import { PERMISSION_MODES, permissionBoundary } from "../hub/permission-mode.ts";
5
7
  import { PLANNER_PEERS, definitionOf, nativeStreamTone, createProjectAdapterCatalog } from "../adapters/registry.ts";
6
8
  import { taskProgress } from "../ui/task-progress.ts";
@@ -133,17 +135,22 @@ export function terminalText(value: unknown): string {
133
135
  .replace(/\x1b[^\n]?/g, "").replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, ""));
134
136
  }
135
137
  export type Tone = "info" | "strong" | "success" | "attention" | "failure" | "muted" | "peerClaude" | "peerCodex" | "taskKeyword" | "number" | "issueRef" | "taskRef";
136
- export interface Span { text: string; tone?: Tone }
138
+ /** A report span names a semantic role (CLI output standard v1, docs/design/cli-output.md) or, for the console, a tone; a role wins. */
139
+ export interface Span { text: string; tone?: Tone; role?: Role }
137
140
  export const PALETTE: Readonly<Record<Tone, string>> = Object.freeze({
138
- info: PEER_PALETTE.hub.ansi, strong: "\x1b[1;36m", success: PEER_PALETTE.local.ansi, attention: PEER_PALETTE.pi.ansi, failure: "\x1b[31m", muted: PEER_PALETTE.other.ansi,
141
+ info: PEER_PALETTE.hub.ansi, strong: TONE_SGR.strong, success: PEER_PALETTE.local.ansi, attention: PEER_PALETTE.pi.ansi, failure: TONE_SGR.failure, muted: PEER_PALETTE.other.ansi,
139
142
  peerClaude: PEER_PALETTE.claude.ansi, peerCodex: PEER_PALETTE.codex.ansi,
140
- taskKeyword: PEER_PALETTE.kimi.ansi, number: "\x1b[1m", issueRef: "\x1b[4m", taskRef: "\x1b[4;35m",
143
+ taskKeyword: PEER_PALETTE.kimi.ansi, number: TONE_SGR.number, issueRef: TONE_SGR.issueRef, taskRef: TONE_SGR.taskRef,
144
+ });
145
+ /** The console's tones onto roles. A tone that is not here names an identity (a peer, a task keyword, a reference), never a status. */
146
+ export const TONE_ROLE: Readonly<Partial<Record<Tone, Role>>> = Object.freeze({
147
+ info: "accent", strong: "header", success: "success", attention: "warning", failure: "error", muted: "hint", number: "value",
141
148
  });
142
149
  export function paint(line: Span[], color: boolean): string {
143
150
  return line.map(span => {
144
151
  const text = terminalText(span.text);
145
- const sgr = span.tone && Object.hasOwn(PALETTE, span.tone) ? PALETTE[span.tone] : undefined;
146
- return color && sgr && text ? sgr + text + "\x1b[0m" : text;
152
+ const sgr = span.role && Object.hasOwn(ROLE_SGR, span.role) ? ROLE_SGR[span.role] : span.tone && Object.hasOwn(PALETTE, span.tone) ? PALETTE[span.tone] : undefined;
153
+ return color && sgr && text ? sgr + text + SGR_RESET : text;
147
154
  }).join("");
148
155
  }
149
156
  /** Console stream headers only. Tokenize sanitized text; bodies and command output stay plain. */
@@ -223,11 +230,89 @@ export function wrapStreamTokens(value: string, columns: number, tone?: Tone, ki
223
230
  return out;
224
231
  });
225
232
  }
226
- export function resolveColor(flag: string | undefined, env: { isTTY: boolean; TERM?: string; NO_COLOR?: string }): boolean | Error {
227
- if (flag === "always") return true;
228
- if (flag === "never") return false;
229
- if (flag === undefined || flag === "auto") return env.isTTY && env.TERM !== "dumb" && !env.NO_COLOR;
230
- return new Error("usage: ahub <command> [--color=auto|always|never]");
233
+ /**
234
+ * The layout grammar of standard v1 as one builder, so every report has the same header, section, key/value row, bullet row, next step
235
+ * and summary line. Blank lines follow the standard: exactly one before each section, none after it, never two in a row, none at the
236
+ * end. Lines are Span arrays; `paint(line, color)` prints them. The builder never colors by itself: it names roles.
237
+ */
238
+ export class Report {
239
+ private readonly out: Span[][] = [];
240
+ /** `columns` undefined means no wrap width: standard v1 wraps on a pipe only when COLUMNS is set, so a script reading `ahub doctor | grep` gets whole lines. */
241
+ constructor(readonly columns: number | undefined = undefined, readonly ascii = false) {}
242
+ /** The text as lines at most `room` cells wide, or as one line per source line when there is no wrap width. */
243
+ private fit(text: string, room: number): string[] {
244
+ return this.columns === undefined ? terminalText(text).split("\n").map(line => line.replace(/\t/g, " ")) : wrap(text, Math.max(10, room), 0);
245
+ }
246
+ private push(line: Span[]) { this.out.push(line); }
247
+ /** ` <tool> <Report>` in `header`, then one line of context in `hint` on the same line. At most one per report. */
248
+ header(tool: string, name: string, context?: string): this {
249
+ this.push([{ text: ` ${tool} ${name}`, role: "header" }, ...(context ? [{ text: ` ${context}`, role: "hint" as const }] : [])]);
250
+ return this;
251
+ }
252
+ /** One blank line, then `▸ <Name>` (ASCII `> <Name>`) in `section`, with an optional count in `hint`. */
253
+ section(name: string, count?: string): this {
254
+ if (this.out.length && this.out.at(-1)!.length) this.push([]);
255
+ this.push([{ text: `${this.ascii ? SECTION_MARKER.ascii : SECTION_MARKER.glyph} ${name}`, role: "section" }, ...(count ? [{ text: ` (${count})`, role: "hint" as const }] : [])]);
256
+ return this;
257
+ }
258
+ /**
259
+ * Key/value rows of one section: two-space indent, `Key:` padded to the widest key, two spaces, value. A key wider than 28 cells
260
+ * puts its value on the next line at a four-space indent. An empty value is `(unset)` in `hint`.
261
+ */
262
+ kv(rows: readonly (readonly [string, unknown])[], indent = 2): this {
263
+ const keys = rows.map(([key]) => cellWidth(`${terminalText(key)}:`));
264
+ const pad = Math.max(0, ...keys.filter(width => width <= 28));
265
+ for (const [index, [key, raw]] of rows.entries()) {
266
+ const label = `${terminalText(key)}:`, text = terminalText(raw ?? "").trim();
267
+ const value = (line: string): Span => text ? { text: line, role: "value" } : { text: "(unset)", role: "hint" };
268
+ const lead = " ".repeat(indent);
269
+ if (keys[index]! > 28) {
270
+ this.push([{ text: `${lead}${label}`, role: "key" }]);
271
+ for (const line of text ? this.fit(text, (this.columns ?? 0) - indent - 2) : [""]) this.push([{ text: `${lead} ` }, value(line)]);
272
+ continue;
273
+ }
274
+ const gap = " ".repeat(pad - keys[index]! + 2), room = (this.columns ?? 0) - indent - pad - 2;
275
+ const lines = text ? this.fit(text, room) : [""];
276
+ this.push([{ text: lead }, { text: label, role: "key" }, { text: gap }, value(lines[0]!)]);
277
+ for (const line of lines.slice(1)) this.push([{ text: " ".repeat(indent + pad + 2) }, value(line)]);
278
+ }
279
+ return this;
280
+ }
281
+ /** ` <marker> <text>`; a nested detail line uses four spaces. The text carries the state word, so meaning survives without color. */
282
+ bullet(name: MarkerName, text: string, nested = false): this {
283
+ const indent = nested ? " " : " ", lead = indent.length + MARKER_COLUMN + 1;
284
+ const lines = this.fit(text, (this.columns ?? 0) - lead);
285
+ this.push([{ text: indent }, { text: markerCell(name, this.ascii), role: MARKERS[name].role }, { text: " " }, { text: lines[0]! }]);
286
+ for (const line of lines.slice(1)) this.push([{ text: " ".repeat(lead) + line }]);
287
+ return this;
288
+ }
289
+ /** Lines another renderer built (a table), placed as they are. A section's blank line is still added by `section()`. */
290
+ append(lines: readonly Span[][]): this { for (const line of lines) this.push([...line]); return this; }
291
+ /** A free line in one role, indented two cells (a pointer to more detail, a note). */
292
+ note(text: string, role: Role = "hint"): this {
293
+ for (const line of this.fit(text, (this.columns ?? 0) - 2)) this.push([{ text: " " }, { text: line, role }]);
294
+ return this;
295
+ }
296
+ /** ` → <command>` in `accent`: complete and copyable, never shortened. */
297
+ next(command: string): this {
298
+ this.push([{ text: " " }, { text: `${markerCell("next", this.ascii)} ${terminalText(command)}`, role: "accent" }]);
299
+ return this;
300
+ }
301
+ /** The last line of a check command: `✗ 2 failed ⚠ 3 warnings ✓ 18 ok`, zero counts omitted, unknowns as `? 2 unknown`. */
302
+ summary(counts: { failed?: number; warnings?: number; unknown?: number; ok?: number }): this {
303
+ const parts: Span[] = [];
304
+ const add = (n: number | undefined, name: MarkerName, word: string) => {
305
+ if (!n) return;
306
+ if (parts.length) parts.push({ text: " " });
307
+ parts.push({ text: `${this.ascii ? MARKERS[name].ascii : MARKERS[name].glyph} ${n} ${word}`, role: MARKERS[name].role });
308
+ };
309
+ add(counts.failed, "fail", "failed"); add(counts.warnings, "warn", counts.warnings === 1 ? "warning" : "warnings"); add(counts.unknown, "unknown", "unknown"); add(counts.ok, "ok", "ok");
310
+ if (parts.length) { if (this.out.length) this.push([]); this.push(parts); }
311
+ return this;
312
+ }
313
+ lines(): Span[][] { return this.out.map(line => line.map(item => ({ ...item }))); }
314
+ /** The report as text: one painted string per line, no trailing blank line. */
315
+ render(color: boolean): string[] { return this.out.map(line => paint(line, color)); }
231
316
  }
232
317
  export function stateTone(state: string): Tone | undefined {
233
318
  if (state === "idle" || state === "approved") return "success";
@@ -1003,7 +1088,9 @@ export function cells(s: ConsoleState, row: any, selected: boolean, now: number,
1003
1088
  const paused = b?.paused ? `budget ${relative(b.paused.resetsAt, now)}` : row.paused && typeof row.paused === "object"
1004
1089
  ? `${row.paused.by ?? "paused"}${typeof row.paused.at === "number" ? ` ${duration(now - row.paused.at)}` : ""}`
1005
1090
  : row.paused === "manual" ? "user" : row.paused ? String(row.paused).split(":")[0] : "-";
1006
- return [id(row.planner ? `${row.id} (planner)` : row.id, row.state === "offline" ? undefined : "info"), span(`${row.rostered === false ? `${row.state} off roster` : row.state}${Array.isArray(row.standbySessions) && row.standbySessions.length ? ` +standby:${row.standbySessions.length}` : ""}`, stateTone(row.state)),
1091
+ // #1414: the conductor from the hub's settled flow roles, first so a narrow PEER column still shows it; an older hub without flowRoles keeps the planner-only label.
1092
+ const tags = [Array.isArray(row.flowRoles) && row.flowRoles.includes("conductor") && "conductor", row.planner && "planner"].filter(Boolean);
1093
+ return [id(tags.length ? `${row.id} (${tags.join(", ")})` : row.id, row.state === "offline" ? undefined : "info"), span(`${row.rostered === false ? `${row.state} off roster` : row.state}${Array.isArray(row.standbySessions) && row.standbySessions.length ? ` +standby:${row.standbySessions.length}` : ""}`, stateTone(row.state)),
1007
1094
  ...(showPermissionModes(s) ? [span(row.permissionMode && row.permissionMode !== "ask" ? row.permissionMode : "-", row.permissionMode === "never-ask" ? "attention" : undefined)] : []),
1008
1095
  span(row.pullOnly && definitionOf(row.id)?.attach?.pullOnlyForms?.includes("tui") ? "pull-only" : row.toolsOnly ? "tools-only" : row.attached === false ? "detached" : "attached", row.toolsOnly ? "attention" : undefined),
1009
1096
  ((hub) => span(hub.cell, hub.differs ? "attention" : hub.cell === "-" || hub.unknown ? "muted" : undefined))(peerHubVersion(row, s.versions?.daemon)),
@@ -6,7 +6,7 @@ import type { ControlClient } from "../hub/control-client.ts";
6
6
  import { contextLine } from "./status-lines.ts";
7
7
  import { renderTailEvent } from "./tail-render.ts";
8
8
  import { reviewResult } from "./console-review.ts";
9
- import { syncPermissionDefaults, permissionDefaultText, approvalFrom, initialConsoleState, keyTable, notify, paint, permissionText, plural, pruneApprovals, reduceConsole, renderConsoleLines, resolveColor, stateTone, streamTokens, wrapStreamTokens, terminalText, wrap, captureConsoleSelection, selectedPanelRow, appendEvent, FIRST_KEYS, LAST_KEYS } from "./console-state.ts";
9
+ import { syncPermissionDefaults, permissionDefaultText, approvalFrom, initialConsoleState, keyTable, notify, paint, permissionText, plural, pruneApprovals, reduceConsole, renderConsoleLines, resolveColor, streamEnv, stateTone, streamTokens, wrapStreamTokens, terminalText, wrap, captureConsoleSelection, selectedPanelRow, appendEvent, FIRST_KEYS, LAST_KEYS } from "./console-state.ts";
10
10
  import type { ConsoleEffect, ConsoleEvent, Detail, Tone } from "./console-state.ts";
11
11
  import type { BusEvent } from "../hub/bus.ts";
12
12
  import { consoleNeeds, attentionFacts, attentionResults } from "./attention.ts";
@@ -95,7 +95,7 @@ function labeled(text: string): Detail {
95
95
  /** One terminal client, no daemon ownership. All text crosses terminalText before writing. */
96
96
  export async function runConsole(options: ConsoleOptions): Promise<void> {
97
97
  const { client } = options; const terminal = options.terminal ?? nativeTerminal();
98
- const color = options.color ?? resolveColor(undefined, { isTTY: terminal.isTTY, TERM: process.env.TERM, NO_COLOR: process.env.NO_COLOR }) === true;
98
+ const color = options.color ?? resolveColor(undefined, streamEnv(terminal.isTTY)) === true;
99
99
  let state = initialConsoleState(!!options.panels); state.project = basename(options.cwd);
100
100
  let pet = loadPetConfig(options.cwd);
101
101
  let petSignature = JSON.stringify([pet.enabled, pet.character, pet.size, pet.glyphs, pet.blink, pet.bell]);
@@ -196,6 +196,7 @@ export async function runConsole(options: ConsoleOptions): Promise<void> {
196
196
  notice(`detail ${id} changed or is no longer available`);
197
197
  }
198
198
  };
199
+ let instructedAnswersSeen = new Set<string>();
199
200
  const refresh = async () => {
200
201
  if (polling || !active) { if (active) refreshPending = true; return; }
201
202
  polling = true;
@@ -232,6 +233,9 @@ export async function runConsole(options: ConsoleOptions): Promise<void> {
232
233
  }
233
234
  } catch { /* retain running console presentation while a config file is unreadable */ }
234
235
  if (questionReply?.ok === true) {
236
+ const instructed = Array.isArray(questionReply.answeredQuestions) ? questionReply.answeredQuestions.filter((row: any) => row.state === "answered" && row.instructed === true && typeof row.provenance === "string") : [];
237
+ for (const row of instructed) if (!instructedAnswersSeen.has(row.set)) stream({ text: ` ${terminalText(String(row.set))}: ${terminalText(row.provenance)}`, peer: row.peer, kind: "question", tone: "success" });
238
+ instructedAnswersSeen = new Set(instructed.map((row: any) => String(row.set)));
235
239
  const rows = questionRows(questionReply.questions);
236
240
  // A set the person has not been told about gets one stream line with no question text: A answers it, or ahub answer.
237
241
  const seen = new Set(state.questionsSeen ?? []);
@@ -0,0 +1,19 @@
1
+ import { MARKERS, terminalText } from "./console-state.ts";
2
+
3
+ // CLI output standard v1, Messages. Pure, so a test reads the exact text without starting the CLI (main.ts runs on import).
4
+ /**
5
+ * 2 for a usage error (standard v1: an unknown command or flag, a bad argument), 1 for every other failure. A usage error is one whose text starts with
6
+ * `usage:` or names an unknown command, or that carries its usage as a line of its own (`<what is wrong>\nusage: ...`, the form `ahub study` prints), or is a flag
7
+ * with no value (`--task needs a value`), or is the release command's malformed-arguments refusal, or names an argument, option or flag the command does not take (`unknown argument`, `unknown option`, `unknown flag`).
8
+ * A NEW usage error must start with `usage:` (or use one of these forms) to exit 2; any other text exits 1, so a later call site would otherwise exit 1 by accident. A refusal that changed nothing (`never-ask requires --yes`) is not a usage error and keeps exit 1.
9
+ */
10
+ export function failureExitCode(message: string): 1 | 2 {
11
+ return /^(usage:|unknown command )|\nusage:|^--[a-z][a-z-]* needs a value|^invalid release command$|^(ahub [a-z-]+: )?unknown (argument|option) |; unknown flag |^unknown flag /i.test(message) ? 2 : 1;
12
+ }
13
+
14
+ /** The error line and its optional next step, as `fail()` prints them; pure so a test reads the exact text. */
15
+ export function errorLines(message: string, next: string | undefined, terminal: boolean, ascii: boolean): string[] {
16
+ const line = `ahub: ${message}`;
17
+ const first = terminal ? `${MARKERS.fail[ascii ? "ascii" : "glyph"]} ${line}` : line;
18
+ return next ? [first, ` ${MARKERS.next[ascii ? "ascii" : "glyph"]} ${terminalText(next)}`] : [first];
19
+ }
@@ -6,3 +6,23 @@ export function freeText(words: string[], usage: string): string {
6
6
  if (flag) throw new Error(`the message would absorb the flag "${flag}"; put it after "--" to send it as text; usage: ${usage}`);
7
7
  return (end === -1 ? words : [...before, ...words.slice(end + 1)]).join(" ");
8
8
  }
9
+
10
+ /**
11
+ * #1433: the first word of a write command's free text that reads as an option the command does not know: it starts with `--`, or is `-h`. Words after a lone `--` are text, as in `freeText`.
12
+ * A command that takes its flags out first passes what is left.
13
+ */
14
+ export function unknownOption(words: readonly string[]): string | undefined {
15
+ const end = words.indexOf("--");
16
+ return (end === -1 ? words : words.slice(0, end)).find(word => word.startsWith("--") || word === "-h");
17
+ }
18
+
19
+ /** The text words with the lone `--` separator removed. */
20
+ export function withoutSeparator(words: readonly string[]): string[] {
21
+ const end = words.indexOf("--");
22
+ return end === -1 ? [...words] : [...words.slice(0, end), ...words.slice(end + 1)];
23
+ }
24
+
25
+ /** The refusal for an option-like word where a write command wanted text, said before anything is filed. */
26
+ export function unknownOptionRefusal(word: string, command: string, usage: string | undefined): string {
27
+ return `unknown option ${JSON.stringify(word)} for ${command}; nothing was filed. Put "--" before text that starts with dashes${usage ? `. Usage: ${usage}` : ""}`;
28
+ }
@@ -23,7 +23,7 @@ export function parseHandoffArgs(operands: readonly string[]): HandoffCliRequest
23
23
  const value = operands[++i];
24
24
  if (value === undefined || value.startsWith("--")) return { usage: HANDOFF_USAGE };
25
25
  if (arg === "--path") paths.push(value); else { if (Object.hasOwn(one, arg)) return { usage: HANDOFF_USAGE }; one[arg] = value; }
26
- } else if (arg.startsWith("--")) return { usage: HANDOFF_USAGE };
26
+ } else if (arg.startsWith("--") || arg === "-h") return { usage: `unknown option ${JSON.stringify(arg)}; nothing was filed\n${HANDOFF_USAGE}` };
27
27
  else rest.push(arg);
28
28
  }
29
29
  const project = one["--project"];