@staix/agent-hub 0.52.0 → 0.54.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 (196) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +4 -3
  3. package/docs/addons/open-code-review.md +3 -6
  4. package/docs/agent-notes/README.md +1 -1
  5. package/docs/agent-notes/adapters.md +5 -4
  6. package/docs/agent-notes/budget.md +2 -2
  7. package/docs/agent-notes/bus.md +1 -0
  8. package/docs/agent-notes/daemon.md +6 -5
  9. package/docs/agent-notes/models.md +1 -1
  10. package/docs/agent-notes/tasks.md +3 -3
  11. package/docs/agent-notes/tests.md +4 -4
  12. package/docs/contracts/companion-cli-v2.json +90 -0
  13. package/docs/contracts/companion-cli-v3.json +348 -0
  14. package/docs/design/adapters.md +1 -1
  15. package/docs/design/agent-hub-architecture.md +8 -5
  16. package/docs/design/bus.md +1 -1
  17. package/docs/design/cli-output-inventory.md +4 -2
  18. package/docs/design/execution-reference.md +1 -1
  19. package/docs/design/guidance-experiments.md +1 -0
  20. package/docs/design/guidance-probes.md +1 -0
  21. package/docs/design/model-routes.md +20 -5
  22. package/docs/design/roadmap.md +6 -4
  23. package/docs/design/task-board.md +21 -2
  24. package/docs/dogfood.md +13 -6
  25. package/docs/events.md +1 -1
  26. package/docs/memory.md +2 -2
  27. package/docs/operations.md +158 -50
  28. package/docs/quickstart.md +14 -2
  29. package/docs/security.md +17 -9
  30. package/docs/specs/2026-09-19-agent-hub-design.md +5 -3
  31. package/docs/specs/2026-09-19-multi-project-design.md +1 -1
  32. package/docs/specs/2026-09-20-upgrade-recovery-design.md +24 -0
  33. package/docs/specs/2026-12-04-arev-adoption-design.md +84 -0
  34. package/docs/specs/mcp-endpoint.md +15 -4
  35. package/docs/specs/relay-contract.md +38 -0
  36. package/docs/verification/2026-12-04-host-shared-receipts.md +43 -0
  37. package/docs/verification/2026-12-05-0.53.0.md +101 -0
  38. package/docs/verification/2026-12-05-agy-1.5.24.md +55 -0
  39. package/docs/verification/2026-12-05-claude-implementer-2.1.337.md +43 -0
  40. package/docs/verification/2026-12-06-0.54.0.md +76 -0
  41. package/docs/verification/2026-12-06-codex-0174-reviewer-isolation.md +43 -0
  42. package/docs/verification/2026-12-06-codex-0174-reviewer-tool-call.md +34 -0
  43. package/docs/verification/2026-12-06-compat-codex-capabilities-0.174.0.md +25 -0
  44. package/docs/verification/2026-12-06-compat-pi-1.8.0.md +23 -0
  45. package/docs/verified.json +38 -29
  46. package/package.json +9 -3
  47. package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
  48. package/plugins/agent-hub/.mcp.json +1 -1
  49. package/plugins/agent-hub/compat.json +9 -5
  50. package/plugins/agent-hub/kimi-hook.js +892 -874
  51. package/plugins/agent-hub/relay-launcher.js +24 -0
  52. package/plugins/agent-hub/server.js +27271 -25146
  53. package/src/adapters/acp-session-model.ts +1 -1
  54. package/src/adapters/acp.ts +5 -4
  55. package/src/adapters/agy/definition.ts +1 -1
  56. package/src/adapters/agy/hooks.ts +1 -1
  57. package/src/adapters/channel-peer.ts +3 -1
  58. package/src/adapters/claude-channel-evidence.ts +26 -1
  59. package/src/adapters/claude-channel.ts +27 -30
  60. package/src/adapters/claude-connection-policy.ts +62 -0
  61. package/src/adapters/claude-relay.ts +255 -0
  62. package/src/adapters/codex-review-isolation.ts +1 -2
  63. package/src/adapters/compat.ts +28 -18
  64. package/src/adapters/definitions/native-cli-preview-pi.ts +2 -1
  65. package/src/adapters/definitions/native-config-defaults.ts +1 -1
  66. package/src/adapters/definitions/native-context.ts +1 -2
  67. package/src/adapters/definitions/native-factories.ts +4 -1
  68. package/src/adapters/definitions/native-quota.ts +1 -1
  69. package/src/adapters/definitions/native-recovery.ts +3 -1
  70. package/src/adapters/external-modules.ts +2 -2
  71. package/src/adapters/kimi-review.ts +1 -1
  72. package/src/adapters/kimi-tui-facts.ts +1 -1
  73. package/src/adapters/local-worker.ts +3 -3
  74. package/src/adapters/native-capabilities.ts +1 -1
  75. package/src/adapters/pi.ts +26 -7
  76. package/src/adapters/registry-types.ts +2 -0
  77. package/src/adapters/relay-launcher.ts +27 -0
  78. package/src/adapters/reviewer-mcp.ts +1 -1
  79. package/src/cli/agents.ts +20 -8
  80. package/src/cli/agy-mcp.ts +1 -1
  81. package/src/cli/claude-profile-hook.ts +1 -1
  82. package/src/cli/command-table.ts +1 -0
  83. package/src/cli/commands/agents.ts +18 -1
  84. package/src/cli/commands/doctor.ts +18 -4
  85. package/src/cli/commands/launch-line.ts +32 -0
  86. package/src/cli/commands/status.ts +14 -3
  87. package/src/cli/help.ts +7 -4
  88. package/src/cli/identity.ts +1 -1
  89. package/src/cli/init-roles.ts +1 -1
  90. package/src/cli/init-settings.ts +1 -1
  91. package/src/cli/launch-line-plan.ts +82 -0
  92. package/src/cli/launch-line-project.ts +13 -0
  93. package/src/cli/main.ts +10 -9
  94. package/src/cli/pi-steps-warning.ts +14 -0
  95. package/src/cli/recovery-package.ts +60 -6
  96. package/src/cli/reset.ts +1 -1
  97. package/src/cli/shell-quote.ts +1 -3
  98. package/src/cli/upgrade-interactive.ts +7 -2
  99. package/src/cli/upgrade-keep-plan.ts +47 -0
  100. package/src/cli/upgrade-restore-state.ts +1 -1
  101. package/src/cli/upgrade-runtime.ts +119 -18
  102. package/src/cli/upgrade.ts +17 -2
  103. package/src/hub/accounts.ts +8 -4
  104. package/src/hub/action-class.ts +1 -3
  105. package/src/hub/adec-triage.ts +105 -0
  106. package/src/hub/autonomy.ts +1 -1
  107. package/src/hub/board.ts +3 -27
  108. package/src/hub/bus.ts +39 -6
  109. package/src/hub/capabilities.ts +1 -1
  110. package/src/hub/channel-project-base.ts +46 -0
  111. package/src/hub/channel-project.ts +21 -46
  112. package/src/hub/config-apply.ts +1 -1
  113. package/src/hub/config-edit.ts +1 -1
  114. package/src/hub/config-tier.ts +1 -1
  115. package/src/hub/config.ts +2 -2
  116. package/src/hub/confirmation-matrix.ts +1 -1
  117. package/src/hub/control/board-messages.ts +415 -0
  118. package/src/hub/control/dashboard-messages.ts +221 -0
  119. package/src/hub/control/delivery-messages.ts +356 -0
  120. package/src/hub/control/dispatch.ts +114 -0
  121. package/src/hub/control/hub-tool-helpers.ts +243 -0
  122. package/src/hub/control/hub-tools.ts +147 -0
  123. package/src/hub/control/native-messages.ts +665 -0
  124. package/src/hub/control/operations-messages.ts +269 -0
  125. package/src/hub/control/peer-messages.ts +126 -0
  126. package/src/hub/control/recovery-messages.ts +391 -0
  127. package/src/hub/control/recovery-operation.ts +480 -0
  128. package/src/hub/control/scope.ts +460 -0
  129. package/src/hub/control/sdlc-messages.ts +373 -0
  130. package/src/hub/control/task-ops-more.ts +245 -0
  131. package/src/hub/control/task-ops.ts +553 -0
  132. package/src/hub/control/ui-actions.ts +241 -0
  133. package/src/hub/control-write-trace.ts +1 -4
  134. package/src/hub/daemon.ts +485 -4324
  135. package/src/hub/delivery-hints.ts +2 -0
  136. package/src/hub/delivery-journal.ts +17 -6
  137. package/src/hub/events.ts +2 -1
  138. package/src/hub/execution-reference.ts +1 -1
  139. package/src/hub/host.ts +41 -9
  140. package/src/hub/hub-tools.ts +3 -4
  141. package/src/hub/invocations.ts +1 -1
  142. package/src/hub/lifecycle.ts +4 -3
  143. package/src/hub/mcp-endpoint-serve.ts +4 -3
  144. package/src/hub/mcp-endpoint.ts +15 -6
  145. package/src/hub/memory-profile-check.ts +1 -1
  146. package/src/hub/no-writes.ts +1 -1
  147. package/src/hub/peers.ts +2 -0
  148. package/src/hub/pi-exit-policy.ts +27 -0
  149. package/src/hub/progress.ts +1 -1
  150. package/src/hub/project-runtime-state.ts +17 -4
  151. package/src/hub/project-runtime.ts +3 -1
  152. package/src/hub/protocol-window.ts +1 -1
  153. package/src/hub/recovery-continuity.ts +3 -3
  154. package/src/hub/recovery-kept-roster.ts +50 -0
  155. package/src/hub/review-anchor.ts +13 -181
  156. package/src/hub/review-brief.ts +78 -28
  157. package/src/hub/review-findings.ts +15 -193
  158. package/src/hub/review-ledger.ts +162 -0
  159. package/src/hub/review-material.ts +3 -3
  160. package/src/hub/reviewer-pool.ts +4 -2
  161. package/src/hub/roadmap-issue-states.ts +65 -14
  162. package/src/hub/roadmap-sync.ts +39 -14
  163. package/src/hub/routing.ts +9 -0
  164. package/src/hub/runtime-capture-prune.ts +8 -2
  165. package/src/hub/runtime-package-assets.ts +3 -0
  166. package/src/hub/sdlc-release-policy.ts +1 -2
  167. package/src/hub/settings.ts +1 -1
  168. package/src/hub/spec-ack-tool.ts +4 -0
  169. package/src/hub/spec-report-history.ts +36 -0
  170. package/src/hub/specs.ts +1 -4
  171. package/src/hub/supervision.ts +33 -6
  172. package/src/hub/tasks-audit.ts +390 -0
  173. package/src/hub/tasks-backlog.ts +522 -0
  174. package/src/hub/tasks-handoff.ts +208 -0
  175. package/src/hub/tasks-release.ts +257 -0
  176. package/src/hub/tasks-roadmap.ts +17 -3
  177. package/src/hub/tasks-specs.ts +672 -0
  178. package/src/hub/tasks-types.ts +334 -0
  179. package/src/hub/tasks.ts +286 -1961
  180. package/src/hub/upgrade-session-contract.ts +11 -0
  181. package/src/local/probe-sandbox.ts +1 -2
  182. package/src/local/probe-workspace.ts +1 -1
  183. package/src/models/route/config.ts +4 -4
  184. package/src/models/route/decision.ts +18 -10
  185. package/src/models/route/observation-signals.ts +1 -2
  186. package/src/models/route/runtime.ts +8 -5
  187. package/src/npm-artifact.ts +76 -0
  188. package/src/omniroute/client.ts +6 -0
  189. package/src/pi/extension.ts +5 -2
  190. package/src/pi/install.ts +77 -0
  191. package/src/pi/pin.ts +49 -0
  192. package/src/primitives.ts +14 -0
  193. package/src/version.ts +2 -0
  194. package/templates/adec/README.md +10 -6
  195. package/templates/config.json +1 -1
  196. package/templates/specs.block.md +1 -0
@@ -0,0 +1,241 @@
1
+ import type { DaemonScope } from "./scope.ts";
2
+ import { newEnvelope, parseMarker, sanitize, USER } from "../envelope.ts";
3
+ import type { MilestoneLinkKind, MilestoneState } from "../roadmap.ts";
4
+ import type { SettingAuthority } from "../settings.ts";
5
+ import { PreEffectToolRefusal } from "../tool-refusal.ts";
6
+ import type { DashboardSession } from "../ui.ts";
7
+
8
+ /** A dashboard roadmap refusal is the only text the page may echo: a `PreEffectToolRefusal` sentence is canned and
9
+ * carries refs or an id, never task text. Anything else is reported without its message (the terminal has it). */
10
+ function roadmapRefusal(error: unknown): string {
11
+ return error instanceof PreEffectToolRefusal ? error.message : "roadmap action failed; see ahub ui in the terminal";
12
+ }
13
+
14
+ /** The revision the page rendered, checked before any write: a stale page is refused with its cause named. */
15
+ function roadmapFresh(scope: DaemonScope, rawId: unknown, rawRevision: unknown): number {
16
+ if (typeof rawId !== "number" || !Number.isSafeInteger(rawId) || rawId < 1) throw new PreEffectToolRefusal("roadmap milestone id is missing; reload the dashboard");
17
+ if (typeof rawRevision !== "number" || !Number.isSafeInteger(rawRevision) || rawRevision < 0) throw new PreEffectToolRefusal("roadmap revision is missing; reload the dashboard");
18
+ let current: number;
19
+ try { current = scope.tasks.milestoneShow(USER, rawId).revision; } catch { throw new PreEffectToolRefusal("roadmap milestone is gone; reload the dashboard"); }
20
+ if (current !== rawRevision) throw new PreEffectToolRefusal("roadmap changed since this page loaded; reload the dashboard before editing");
21
+ return rawId;
22
+ }
23
+
24
+ /** One move renumbers its lane, so a card's `order` is its position and a drag and a Move button agree. */
25
+ async function roadmapMove(scope: DaemonScope, id: number, horizon: string | undefined, order: number) {
26
+ const view = scope.tasks.milestoneShow(USER, id), fields: Record<string, unknown> = { order };
27
+ if (horizon === "now" || horizon === "next" || horizon === "later") if (horizon !== view.horizon) fields.horizon = horizon;
28
+ if (Object.keys(fields).length) await scope.tasks.milestoneEdit(USER, id, view.revision, fields);
29
+ const lane = (fields.horizon === undefined ? view.horizon : fields.horizon) as string;
30
+ const others = scope.tasks.milestoneList(USER).filter(row => row.id !== id && row.horizon === lane).sort((left, right) => left.order - right.order || left.id - right.id).map(row => row.id);
31
+ const at = Math.min(Math.max(order, 0), others.length);
32
+ // ponytail: one write per card, so a failure partway leaves gaps in this lane's `order`; the next move renumbers it
33
+ // from scratch, and a board transaction is the upgrade if a gap ever has to survive without one.
34
+ for (const [index, cardId] of [...others.slice(0, at), id, ...others.slice(at)].entries())
35
+ if (scope.tasks.milestoneShow(USER, cardId).order !== index) scope.tasks.milestoneOrder(USER, cardId, index);
36
+ }
37
+
38
+ function watchSentence(watch: unknown): string {
39
+ const w = watch as { command?: string; opened?: string } | undefined;
40
+ return w?.command ? (w.opened ? ` A watch pane is open (${w.command}).` : ` Watch it with ${w.command}.`) : "";
41
+ }
42
+
43
+ export async function uiAction(scope: DaemonScope, a: Record<string, unknown>, session?: DashboardSession): Promise<unknown> {
44
+ const bad = { ok: false, error: "invalid or unavailable dashboard action" };
45
+ // #269: a session opened by `ahub ui --settings` may raise authority while its window lasts; any other may not.
46
+ const authority: SettingAuthority = session?.settings ? "settings" : "ordinary";
47
+ const text = (key: string, max: number) => typeof a[key] === "string" && (a[key] as string).length <= max;
48
+ const peer = () => text("peer", 32) && scope.peerIdPattern.test(a.peer as string);
49
+ const taskId = () => typeof a.id === "number" && Number.isSafeInteger(a.id) && a.id > 0;
50
+ if (a.action === "sdlc_queue" || a.action === "sdlc_release") {
51
+ const liveIssues = a.liveIssues ?? [];
52
+ if (typeof a.repo !== "string" || !Array.isArray(liveIssues) || liveIssues.length > 32) return bad;
53
+ const report = a.action === "sdlc_queue" ? await scope.tasks.deliveryQueue(a.repo) : scope.releaseAuthorizations.report(await scope.tasks.releaseReadiness(a.repo, liveIssues));
54
+ return { ok: true, report };
55
+ }
56
+ switch (a.action) {
57
+ // #1483 R5: the dashboard's roadmap writes. Each one carries the revision the page rendered (checked by
58
+ // `roadmapFresh`), so a stale page is refused with its cause named instead of overwriting a newer edit.
59
+ case "roadmap_new":
60
+ case "roadmap_edit":
61
+ case "roadmap_link":
62
+ case "roadmap_unlink":
63
+ case "roadmap_move":
64
+ case "roadmap_state":
65
+ case "roadmap_accept":
66
+ case "roadmap_reject":
67
+ case "roadmap_check":
68
+ case "roadmap_unplaced":
69
+ case "roadmap_triage":
70
+ try {
71
+ switch (a.action) {
72
+ case "roadmap_new":
73
+ if (scope.stopping || scope.recoveryActive()) return { ok: false, error: "recovery or shutdown is holding roadmap changes" };
74
+ return { ok: true, milestone: await scope.tasks.milestoneNew(USER, { title: a.title, outcome: a.outcome, ...(a.horizon === undefined ? {} : { horizon: a.horizon }), ...(a.target === undefined ? {} : { target: a.target }) }) };
75
+ case "roadmap_edit": {
76
+ if (scope.stopping || scope.recoveryActive()) return { ok: false, error: "recovery or shutdown is holding roadmap changes" };
77
+ const id = roadmapFresh(scope, a.id, a.revision);
78
+ if (!a.fields || typeof a.fields !== "object" || Array.isArray(a.fields)) return bad;
79
+ return { ok: true, milestone: await scope.tasks.milestoneEdit(USER, id, scope.tasks.milestoneShow(USER, id).revision, a.fields) };
80
+ }
81
+ case "roadmap_link":
82
+ case "roadmap_unlink": {
83
+ if (scope.stopping || scope.recoveryActive()) return { ok: false, error: "recovery or shutdown is holding roadmap changes" };
84
+ const id = roadmapFresh(scope, a.id, a.revision);
85
+ if (typeof a.kind !== "string" || typeof a.ref !== "string") return bad;
86
+ const kind = a.kind as MilestoneLinkKind;
87
+ return { ok: true, milestone: a.action === "roadmap_link" ? scope.tasks.milestoneLink(USER, id, kind, a.ref) : scope.tasks.milestoneUnlink(USER, id, kind, a.ref) };
88
+ }
89
+ case "roadmap_move": {
90
+ if (scope.stopping || scope.recoveryActive()) return { ok: false, error: "recovery or shutdown is holding roadmap changes" };
91
+ const id = roadmapFresh(scope, a.id, a.revision);
92
+ if (typeof a.order !== "number" || !Number.isSafeInteger(a.order) || a.order < 0) return bad;
93
+ await roadmapMove(scope, id, typeof a.horizon === "string" ? a.horizon : undefined, a.order);
94
+ return { ok: true, milestones: scope.tasks.milestoneList(USER) };
95
+ }
96
+ case "roadmap_state": {
97
+ if (scope.stopping || scope.recoveryActive()) return { ok: false, error: "recovery or shutdown is holding roadmap changes" };
98
+ const id = roadmapFresh(scope, a.id, a.revision);
99
+ if (typeof a.state !== "string") return bad;
100
+ return { ok: true, milestone: scope.tasks.milestoneState(USER, id, a.state as MilestoneState) };
101
+ }
102
+ case "roadmap_accept":
103
+ case "roadmap_reject": {
104
+ if (scope.stopping || scope.recoveryActive()) return { ok: false, error: "recovery or shutdown is holding roadmap changes" };
105
+ if (a.suggestion === undefined) return bad;
106
+ return a.action === "roadmap_accept" ? { ok: true, milestone: await scope.tasks.roadmapAccept(USER, a.suggestion) } : { ok: true, rejected: await scope.tasks.roadmapReject(USER, a.suggestion) };
107
+ }
108
+ case "roadmap_check":
109
+ scope.roadmapDrift = { at: Date.now(), ...(await scope.tasks.roadmapCheck(USER)) };
110
+ return { ok: true, drift: scope.roadmapDrift };
111
+ case "roadmap_triage":
112
+ return { ok: true, suggestions: (await scope.tasks.roadmapTriage(USER)).suggestions };
113
+ default:
114
+ return { ok: true, unplaced: await scope.tasks.roadmapUnplaced(USER) };
115
+ }
116
+ } catch (error) { return { ok: false, error: roadmapRefusal(error) }; }
117
+ case "intake": {
118
+ if (session?.liveTest) return { ok: false, error: "live-test dashboard cannot write person-attributed content; use peer tools" };
119
+ if (scope.stopping || scope.recoveryActive()) return { ok: false, error: "recovery or shutdown is holding mutations" };
120
+ // Reuse the CLI task dispatch, including in-flight recovery accounting and publicView projections.
121
+ return { ok: true, ...JSON.parse(await scope.taskOp(USER, "intake", { text: a.text, sources: a.sources })) };
122
+ }
123
+ case "pause":
124
+ case "resume":
125
+ return peer() ? scope.holdPeer(a.action, a.peer as string) : bad;
126
+ case "permit": {
127
+ if (!text("id", 64) || !text("option", 128)) return bad;
128
+ const pending = scope.permissions.get(a.id as string);
129
+ if (!pending) return { ok: false, error: "permission expired or already answered" };
130
+ const req = JSON.parse(pending.push);
131
+ const option = req.options.find((o: { optionId: string }) => o.optionId === a.option);
132
+ if (!option || (scope.definitionOf(req.peer)?.trust.hubSandboxed === true && option.kind !== "reject_once")) return bad;
133
+ return pending.done(option.optionId, "dashboard") ? { ok: true } : { ok: false, error: "permission expired or already answered" };
134
+ }
135
+ case "supervision": {
136
+ // #1221 T2 AC5: an advisory inbox row decides one proposal as the person, through the same fence the hub tool
137
+ // uses (`decide`); the console supplies the verb and the id, never an actor, a task or an action.
138
+ if (typeof a.id !== "string" || (a.verb !== "accept" && a.verb !== "dismiss")) return bad;
139
+ if (scope.stopping || scope.recoveryActive()) return { ok: false, error: "recovery or shutdown is holding supervision decisions" };
140
+ const decision = await scope.supervisionProposals.decide(USER, a.id, a.verb);
141
+ return decision.ok
142
+ ? { ok: true, proposal: scope.proposalView(decision.proposal), ...(decision.receipt ? { receipt: decision.receipt } : {}) }
143
+ : { ok: false, error: decision.error };
144
+ }
145
+ case "send": {
146
+ if (!text("body", 8000)) return bad;
147
+ if (a.to !== undefined && (!Array.isArray(a.to) || a.to.length > 32 || a.to.some((id) => typeof id !== "string" || !scope.peerIdPattern.test(id) || !scope.bus.knownPeers().includes(id) && scope.membershipAllowed(id)))) return bad;
148
+ const { body, priority } = parseMarker(a.body as string, "important");
149
+ if (!body) return bad;
150
+ const targets = Array.isArray(a.to) ? a.to as string[] : [];
151
+ const off = targets.filter(id => !scope.membershipAllowed(id));
152
+ if (off.length && off.length === targets.length) return { ok: false, error: `off roster: ${off.join(", ")}` };
153
+ scope.bus.publish(newEnvelope(USER, body, { priority, ...(targets.length ? { to: targets } : {}) }));
154
+ return { ok: true, ...(off.length ? { text: `retained off roster for ${off.join(", ")}` } : {}) };
155
+ }
156
+ case "propose": {
157
+ if (!text("title", 300) || (a.detail !== undefined && !text("detail", 8000)) || (a.class !== undefined && !text("class", 32)) || (a.owner !== undefined && !(typeof a.owner === "string" && scope.peerIdPattern.test(a.owner))) || (a.backlog !== undefined && typeof a.backlog !== "boolean")) return bad;
158
+ const result = await scope.taskOp(USER, "hub_task_propose", { title: a.title, detail: a.detail, class: a.class, owner: a.owner, ...(a.backlog === true ? { backlog: true } : {}) });
159
+ return { ok: true, text: result };
160
+ }
161
+ case "backlog_split":
162
+ if (!taskId()) return bad;
163
+ await scope.taskOp(USER, "hub_backlog_split", { id: a.id, revision: a.revision, parts: a.parts, reason: a.reason });
164
+ return { ok: true, text: "Parts staged; the original task retains integration and acceptance." };
165
+ case "planner_pull":
166
+ if (!taskId()) return bad;
167
+ await scope.taskOp(USER, "hub_backlog_pull", { id: a.id, revision: a.revision, reason: a.reason });
168
+ return { ok: true, text: "WIP slot reserved; task pulled into To Do." };
169
+ case "planning":
170
+ case "planning_undo": {
171
+ if (!taskId()) return bad;
172
+ await scope.taskOp(USER, a.action === "planning" ? "hub_backlog_plan" : "hub_backlog_undo", { id: a.id, revision: a.revision, fields: a.fields, reason: a.reason });
173
+ return { ok: true, text: "Task planning updated." };
174
+ }
175
+ case "release_new":
176
+ await scope.taskOp(USER, "release_new", { name: a.name, goal: a.goal, order: a.order });
177
+ return { ok: true, text: "Release created." };
178
+ case "release_change":
179
+ await scope.taskOp(USER, "release_change", { id: a.id, name: a.name, revision: a.revision, fields: a.fields });
180
+ return { ok: true, text: "Release updated." };
181
+ case "backlog_pull":
182
+ case "backlog_return":
183
+ return taskId() ? { ok: true, text: await scope.taskOp(USER, a.action, { id: a.id }) } : bad;
184
+ case "assign":
185
+ return taskId() && peer() && (a.role === undefined || a.role === "owner" || a.role === "reviewer") ? { ok: true, text: await scope.taskOp(USER, "task_assign", { id: a.id, peer: a.peer, role: a.role }) } : bad;
186
+ case "start_peer": {
187
+ // #269: the hub's own start of a peer from the closed list, in the mode a person set. No argument reaches a command.
188
+ if (!peer()) return bad;
189
+ const result = await scope.hubStart(a.peer, "the dashboard", session?.liveTest !== true);
190
+ if (result.ok === true) return { ok: true, text: result.already ? `${a.peer} is already attached.` : result.opened ? `Opened a terminal running ${result.command}; ${a.peer} attaches when its TUI is ready.` : `${a.peer} started (headless).${watchSentence(result.watch)}` };
191
+ // A refusal the hub worded itself carries the command to run by hand; an adapter's own failure text stays in the log.
192
+ if (typeof result.command === "string" || typeof a.peer === "string" && !scope.membershipAllowed(a.peer)) return { ok: false, error: sanitize(String(result.error)) };
193
+ scope.log(`dashboard start ${a.peer} failed: ${String(result.error)}`);
194
+ return { ok: false, error: `${a.peer} did not start; inspect ahub status and hub.log` };
195
+ }
196
+ case "setting":
197
+ return scope.settingsSet(a.key, a.value, authority, a.confirm, a.now, a.reason);
198
+ case "model_preview":
199
+ case "model_confirm": {
200
+ const current = () => session?.settings === true && session.liveTest !== true && typeof session.authorityId === "string"
201
+ && typeof session.settingsUntil === "number" && session.settingsUntil > Date.now();
202
+ if (!current()) return scope.modelFailure("model changes require a current person settings session; reopen ahub ui --settings and preview again");
203
+ return scope.modelCommandSafe(a.action === "model_preview" ? { op: "preview", action: a.modelAction, peer: a.peer, model: a.model } : { op: "confirm", token: a.token },
204
+ { source: "dashboard", scope: session!.authorityId!, expiresAt: session!.settingsUntil, current });
205
+ }
206
+ case "setting_undo":
207
+ return scope.settingsUndo(authority, a.confirm, a.now, a.reason, a.key, a.undoDigest);
208
+ case "setting_preview":
209
+ return a.undo === true ? scope.settingsUndoPreview() : scope.settingsPreview(a.key, a.value);
210
+ case "setting_reload":
211
+ return scope.reloadConfig(authority);
212
+ case "worktree_override_set":
213
+ case "worktree_override_clear":
214
+ case "worktrees_refresh_prs": {
215
+ // The person's console and the dashboard session the manager forwards for it; a live-test dashboard never reaches this (ui.ts allowlist), and is refused here too.
216
+ if (session?.liveTest) return { ok: false, error: "live-test dashboard cannot change the worktree shelf" };
217
+ const out = await scope.worktreeShelf({ t: a.action, path: a.path, value: a.value });
218
+ if (out.ok !== true) return { ok: false, error: String(out.error ?? "the worktree shelf could not be read") };
219
+ const r = out.refreshed as { read: number; failed: number; skipped: number } | undefined;
220
+ return { ok: true, text: r ? `Read ${r.read} PR state${r.read === 1 ? "" : "s"}${r.failed ? `, ${r.failed} unreadable` : ""}${r.skipped ? `, ${r.skipped} left for the next refresh` : ""}.` : a.action === "worktree_override_set" ? "Worktree moved." : "Worktree override cleared." };
221
+ }
222
+ // #1054 T6: a person's receipt from the dashboard session. The manager forwards these only from the server-side acon provider's `receipt` port (after it checked the console's
223
+ // person meta) or from the page of `ahub ui` itself, which is the person's own browser session; a live-test dashboard is refused here as in `ui.ts`. The writes are the same three
224
+ // the console control messages make, so a receipt means the same on every surface; the surface is `dashboard`, and `acon` only through the control message the port sends.
225
+ case "result_seen":
226
+ case "results_read_all":
227
+ case "results_unread_last": {
228
+ if (session?.liveTest) return { ok: false, error: "live-test dashboard cannot write a receipt for the person" };
229
+ const done = a.action === "result_seen" ? scope.markResultSeen(a.id, "dashboard") : a.action === "results_read_all" ? scope.markAllResultsSeen("dashboard") : scope.unmarkLastResult();
230
+ if (!done.ok) return { ok: false, error: done.error };
231
+ return { ok: true, text: a.action === "result_seen" ? "Marked read." : a.action === "results_read_all" ? `Marked ${(done as { marked: number }).marked} read.` : "Marked unread again." };
232
+ }
233
+ case "config_edit_preview":
234
+ return scope.configEditor!.preview(a.edit, authority);
235
+ case "config_edit_apply":
236
+ // A dashboard session is never given the typed confirmation of an executable key: that is the console's, and refused here by the editor.
237
+ return scope.configEditor!.apply(a.edit, authority, undefined, a.reason);
238
+ default:
239
+ return bad;
240
+ }
241
+ }
@@ -1,4 +1,5 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { isRecord as isObject } from "../primitives.ts";
2
3
 
3
4
  export const CONTROL_WRITE_KINDS = [
4
5
  "hub_task_propose", "hub_review", "hub_task_accept", "hub_task_done", "hub_task_decline", "hub_task_cancel",
@@ -78,10 +79,6 @@ interface SpanInterval {
78
79
 
79
80
  const currentTrace = new AsyncLocalStorage<RequestTrace>();
80
81
 
81
- function isObject(value: unknown): value is Record<string, unknown> {
82
- return !!value && typeof value === "object" && !Array.isArray(value);
83
- }
84
-
85
82
  function validTaskId(value: unknown): value is number {
86
83
  return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
87
84
  }