@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
package/src/hub/board.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { specReportHistory } from "./spec-report-history.ts";
1
2
  import { instructedExecution, instructedHistory } from "./instructed-exact.ts";
2
3
  import { PreEffectToolRefusal } from "./tool-refusal.ts";
3
4
  import { GUIDANCE_VARIANT_LIMITS, GUIDANCE_PAGE_MAX_RECORDS, GUIDANCE_HASH_HEX_LENGTH, parseGuidanceVariantV1, parseGuidanceExperiment, parseGuidanceStoredRecord, validateGuidanceVariantV1, type GuidanceVariantV1, type GuidanceExperimentRecord, type GuidanceStoredRecord, type GuidanceWriteFence } from "./guidance-variants.ts";
@@ -32,7 +33,7 @@ import { parseReviewFindings, type ReviewFindingSet } from "./review-findings.ts
32
33
  import { storedSecurityPass, type SecurityPassRecord } from "./security-pass.ts";
33
34
  import { parseDeliverableRecords, type DeliverableRecord } from "./deliverables.ts";
34
35
  import type { CostPlan, ReviewCost } from "./cost-governance.ts";
35
- import type { SpecRef, SpecTaskReport } from "./specs-task.ts";
36
+ import type { SpecTaskReport } from "./specs-task.ts";
36
37
  export type { SpecAck, SpecRef, SpecTaskReport } from "./specs-task.ts";
37
38
  import { campaignHash, parseResearchCampaign, parseResearchHandoff, type ResearchCampaignContract, type ResearchCampaignStatus, type ResearchUnit, type ResearchHandoffV1, type ResearchHandoffRecord } from "./research-campaign.ts";
38
39
  import { parseSurveyFindings, parseSurveyVetDecisions, surveyArray, surveyObject, surveyPath, surveyText, surveyFindingId, surveyPass, type SurveyFinding, type SurveyVetDecision, SURVEY_FOCUS, SURVEY_LIMITS, type SurveyFocus } from "./advisor-survey.ts";
@@ -442,31 +443,6 @@ function reviewerHistory(extra: ReviewerHistory): ReviewerHistory {
442
443
  if (failure && (!id(failure.peer) || !["start_failed", "quota", "no_verdict"].includes(failure.cause) || failure.head !== undefined && (typeof failure.head !== "string" || !failure.head.trim() || failure.head.length > 300 || Buffer.byteLength(failure.head) > 1200 || /\p{Cc}/u.test(failure.head)))) throw new Error("invalid reviewer failure metadata");
443
444
  return { ...(wait ? { reviewerQuotaWait: { created: wait.created, binding: wait.binding, since: wait.since, deadline: wait.deadline, resetAt: wait.resetAt } } : {}), ...(extra.reviewerFamily ? { reviewerFamily: extra.reviewerFamily } : {}), ...(extra.reviewerReason ? { reviewerReason: extra.reviewerReason } : {}), ...(extra.reviewBlocked ? { reviewBlocked: true } : {}), ...(extra.queueReviewHeld ? { queueReviewHeld: true, ...(extra.queueReviewBinding !== undefined ? { queueReviewBinding: extra.queueReviewBinding } : {}) } : {}), ...(failure ? { reviewerFailure: { peer: failure.peer, cause: failure.cause, ...(failure.reason ? { reason: failure.reason } : {}), ...(failure.head ? { head: failure.head } : {}) } } : {}) };
444
445
  }
445
- function specReportHistory(report: unknown, binding: unknown, event: string): Pick<HistoryEntry, "specReport" | "specRefBinding"> {
446
- if (!report || typeof report !== "object" || Array.isArray(report) || !["done", "done (checking)"].includes(event)
447
- || typeof binding !== "string" || !/^[a-f0-9]{64}$/.test(binding)) throw new Error("invalid task spec report metadata");
448
- const value = report as Record<string, unknown>;
449
- if (Object.keys(value).some(key => !["head", "complete", "errors", "unchanged", "changed", "truncated", "reason"].includes(key))
450
- || typeof value.head !== "string" || value.head !== "" && !/^[a-f0-9]{40}$/.test(value.head)
451
- || value.head === "" && value.complete !== false || typeof value.complete !== "boolean"
452
- || !Number.isSafeInteger(value.errors) || (value.errors as number) < 0 || (value.errors as number) > 1_000_000
453
- || value.truncated !== undefined && value.truncated !== true
454
- || value.reason !== undefined && (typeof value.reason !== "string" || value.reason.length > 500 || /[\p{Cc}\p{Cf}]/u.test(value.reason))
455
- || !Array.isArray(value.unchanged) || value.unchanged.length > 20 || !Array.isArray(value.changed) || value.changed.length > 20) throw new Error("invalid task spec report metadata");
456
- const ref = (raw: unknown): SpecRef => {
457
- if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new Error("invalid task spec report metadata");
458
- const row = raw as Record<string, unknown>;
459
- if (Object.keys(row).some(key => !["id", "path", "title", "reason"].includes(key))
460
- || typeof row.id !== "string" || !row.id.trim() || row.id.length > 160 || /[\p{Cc}\p{Cf}]/u.test(row.id)
461
- || typeof row.path !== "string" || !row.path.trim() || row.path.length > 1000 || /[\p{Cc}\p{Cf}]/u.test(row.path)
462
- || typeof row.title !== "string" || !row.title.trim() || row.title.length > 1000 || /[\p{Cc}\p{Cf}]/u.test(row.title)
463
- || row.reason !== undefined && (typeof row.reason !== "string" || row.reason.length > 1000 || /[\p{Cc}\p{Cf}]/u.test(row.reason))) throw new Error("invalid task spec report metadata");
464
- return { id: row.id, path: row.path, title: row.title, ...(typeof row.reason === "string" ? { reason: row.reason } : {}) };
465
- };
466
- const specReport: SpecTaskReport = { head: value.head, complete: value.complete, errors: value.errors as number,
467
- unchanged: value.unchanged.map(ref), changed: value.changed.map(ref), ...(value.truncated === true ? { truncated: true } : {}), ...(typeof value.reason === "string" ? { reason: value.reason } : {}) };
468
- return { specReport, specRefBinding: binding };
469
- }
470
446
  export interface PlannerBinding { planner: PeerId | null; plannerReason: PlannerReason }
471
447
  function plannerValue(value: unknown): PeerId | null {
472
448
  if (value == null) return null;
@@ -2893,7 +2869,7 @@ export class Board {
2893
2869
  const authorHistory = Object.hasOwn(extra, "planAuthor") ? { planAuthor: plannerValue(extra.planAuthor) } : {};
2894
2870
  if (extra.selfReview !== undefined && extra.selfReview !== true) throw new Error("invalid self-review metadata");
2895
2871
  const specMetadata = extra.specReport !== undefined || extra.specRefBinding !== undefined
2896
- ? specReportHistory(extra.specReport, extra.specRefBinding, event) : {};
2872
+ ? specReportHistory(extra.specReport, extra.specRefBinding, event, task) : {};
2897
2873
  if (extra.conductorManual !== undefined && (extra.conductorManual !== true || by === "user" || by === "hub" || extra.reason !== "manual"
2898
2874
  || !["assigned", "reassigned", "reserved", "unassigned", "reviewer changed"].includes(event))) throw new Error("invalid conductor manual metadata");
2899
2875
  if (extra.invocation && (by !== HUB || event !== "invocation")) throw new Error("invocation audit is host-only");
package/src/hub/bus.ts CHANGED
@@ -11,6 +11,7 @@ import { MAX_DEFERRED_HUB, RecoveryDeferredHubError, validateDeferredHub } from
11
11
  import { parseRemotePeerId } from "../rooms/application.ts";
12
12
  import { PreEffectToolRefusal } from "./tool-refusal.ts";
13
13
  import { stripRecordLines } from "../memory/records.ts";
14
+ import { renderHeldHint } from "./delivery-hints.ts";
14
15
 
15
16
  export type { DeliveryReceipt } from "./peers.ts";
16
17
 
@@ -166,6 +167,15 @@ export const NOTES_KEPT = 10;
166
167
  export const ROOM_PROOF_UNAVAILABLE_REASON = "room delivery proof unavailable; inspect ahub queue show";
167
168
  export const ROOM_EPOCH_ROTATED_REASON = "room epoch rotated; inspect ahub queue show";
168
169
 
170
+ const HELD_HINT_HEADER = /^(?:Held|Unconfirmed) hub deliveries: \d+/;
171
+ /**
172
+ * #1946: a needs_review row holds the peer wide, as before, except a local row the ACP adapter's own unrequested stop marked `holdsSelf`, which holds only itself.
173
+ * The signal is a host-owned, persisted mark, never the reason text: a channel receipt, an ACP prompt error or a failed turn can all write any reason, but only `AcpPeer.stop()` sets the mark and the
174
+ * control receipt path builds its receipt without one. Invocation rows, an accepted-settle timeout, an aborted turn, an adapter failure, a requested stop and an unconfirmed reviewer fallback (#804)
175
+ * keep the peer-wide hold. A remote row never held the peer.
176
+ */
177
+ const holdsPeerWide = (peer: PeerId, originals: readonly Envelope[], holdsSelf: boolean | undefined): boolean => originals.some(isInvocationKind) || !remoteId(peer) && holdsSelf !== true;
178
+
169
179
  export class Bus {
170
180
  readonly peers = new Map<PeerId, PeerAdapter>();
171
181
  private readonly opts: BusOptions;
@@ -175,6 +185,8 @@ export class Bus {
175
185
  private queueTimeEntries = 0;
176
186
  private queuePressureWasTracked = false;
177
187
  private readonly prefaces = new Map<PeerId, Envelope>();
188
+ /** #1946: peers restored from the journal with a plain needs_review row; their held hint is prefaced once when the peer is first attached. */
189
+ private readonly restoredPlainHolds = new Set<PeerId>();
178
190
  private readonly remoteQueueMembers = new Map<PeerId, string>();
179
191
  private readonly remoteQueueRooms = new Map<PeerId, string>();
180
192
  private readonly remoteQueueExpires = new Map<PeerId, Map<string, number>>();
@@ -290,7 +302,8 @@ export class Bus {
290
302
  for (const id of state.manualPaused) { this.manualPaused.add(id); this.paused.add(id); }
291
303
  for (const row of this.journal.list()) {
292
304
  for (const env of row.originals) if (env.kind === "invocation") this.invocationDeliveries.set(env.id, row.id);
293
- if (row.state === "dispatching" || row.state === "accepted" || row.state === "needs_review" && (!remoteId(row.peer) || row.originals.some(isInvocationKind))) this.recoveryHeldPeers.add(row.peer);
305
+ if (row.state === "dispatching" || row.state === "accepted" || row.state === "needs_review" && holdsPeerWide(row.peer, row.originals, row.holdsSelf)) this.recoveryHeldPeers.add(row.peer); // #1946: a plain uncertainty row holds only itself, for a local peer as for a room peer
306
+ if (row.state === "needs_review" && !remoteId(row.peer) && !holdsPeerWide(row.peer, row.originals, row.holdsSelf)) this.restoredPlainHolds.add(row.peer);
294
307
  }
295
308
  }
296
309
  }
@@ -321,6 +334,7 @@ export class Bus {
321
334
  if (peer.remoteRoom !== undefined && !pendingRemote) { this.remoteQueueRooms.delete(peer.id); this.remoteQueueMembers.delete(peer.id); }
322
335
  this.clearReviewProvenance(peer.id);
323
336
  this.peers.set(peer.id, peer);
337
+ if (this.restoredPlainHolds.delete(peer.id)) this.prefaceHeld(peer.id);
324
338
  if (!this.queues.has(peer.id)) this.queues.set(peer.id, []);
325
339
  peer.onDelivery = (receipt) => { if (this.peers.get(peer.id) === peer) this.deliveryReceipt(peer.id, receipt); };
326
340
  peer.onActivity = kind => {
@@ -647,6 +661,7 @@ export class Bus {
647
661
  }
648
662
  this.loadSnapshot(snapshot);
649
663
  if (this.journal) for (const row of this.journal.list()) for (const env of row.originals) if (env.kind === "invocation") this.invocationDeliveries.set(env.id, row.id);
664
+ if (this.journal) for (const row of this.journal.list()) if (row.state === "needs_review" && !remoteId(row.peer) && !holdsPeerWide(row.peer, row.originals, row.holdsSelf)) this.restoredPlainHolds.add(row.peer); // #1946: a controlled recovery names a self-held row too
650
665
  this.persist();
651
666
  }
652
667
 
@@ -926,7 +941,7 @@ export class Bus {
926
941
  const queued = this.queues.get(peer) ?? [];
927
942
  const review = rows.filter((r) => r.state === "needs_review");
928
943
  const needsReview = review.length;
929
- const blocked = rows.find((r) => (r.state === "needs_review" && (!remoteId(peer) || r.originals.some(isInvocationKind))) || (["dispatching", "accepted"].includes(r.state) && !this.activeDeliveries.has(r.id)));
944
+ const blocked = rows.find((r) => (r.state === "needs_review" && holdsPeerWide(peer, r.originals, r.holdsSelf)) || (["dispatching", "accepted"].includes(r.state) && !this.activeDeliveries.has(r.id)));
930
945
  const liveAccepted = rows.filter((r) => r.state === "accepted" && this.activeDeliveries.get(r.id) === peer).map((r) => r.id);
931
946
  const hold = { ...(blocked ? { heldBy: blocked.id } : {}), ...(liveAccepted.length ? { liveAccepted } : {}) };
932
947
  const oldest = queued.reduce<number | undefined>((a, r) => a === undefined ? r.ts : Math.min(a, r.ts), undefined);
@@ -977,7 +992,7 @@ export class Bus {
977
992
  if (!cause && state === "failed") cause = this.stateOf(peer) === "offline" ? "peer offline" : "adapter refused";
978
993
  if (!cause) cause = "turn aborted";
979
994
  }
980
- this.journal.transition(id, state, receipt.reason, undefined, cause);
995
+ this.journal.transition(id, state, receipt.reason, undefined, cause, state === "needs_review" ? receipt.holdsSelf === true : false);
981
996
  }
982
997
  if (!remoteId(peer) && before?.state === "dispatching" && (state === "accepted" || state === "completed")) {
983
998
  this.memoryDelivery(peer, id, before.out, "delivered", before.originals);
@@ -994,20 +1009,38 @@ export class Bus {
994
1009
  for (const env of before?.originals ?? []) if (isInvocationKind(env) && (receipt.state === "completed" || receipt.state === "needs_review")) {
995
1010
  try { this.onInvocationReceipt?.(env.id, receipt.state); } catch { /* a ledger observer cannot undo a durable transport receipt */ }
996
1011
  }
997
- if (state === "needs_review" && (!remoteId(peer) || before?.originals.some(isInvocationKind))) {
1012
+ if (state === "needs_review" && holdsPeerWide(peer, before?.originals ?? [], receipt.holdsSelf)) {
998
1013
  this.recoveryHeldPeers.add(peer);
999
1014
  for (const env of before?.originals ?? []) if (env.kind === "invocation") {
1000
1015
  try { this.onInvocationUncertain?.(env.id); } catch { /* uncertainty hold remains durable */ }
1001
1016
  }
1002
1017
  }
1003
- if (state === "completed" || state === "failed" || state === "needs_review" && remoteId(peer)) { this.refreshRecoveryHold(peer); void this.drain(peer); }
1018
+ if (state === "needs_review" && !remoteId(peer) && !holdsPeerWide(peer, before?.originals ?? [], receipt.holdsSelf)) this.prefaceHeld(peer);
1019
+ if (state === "completed" || state === "failed" || state === "needs_review" && (remoteId(peer) || !holdsPeerWide(peer, before?.originals ?? [], receipt.holdsSelf))) { this.refreshRecoveryHold(peer); void this.drain(peer); }
1004
1020
  this.onQueues?.();
1005
1021
  }
1006
1022
 
1023
+ /** #1946: a plain local needs_review row no longer stops later work, so the next delivery names it once through the bounded, body-free held hint. */
1024
+ private prefaceHeld(peer: PeerId): void {
1025
+ try {
1026
+ const adapter = this.peers.get(peer) as { deliveryOnly?: boolean } | undefined;
1027
+ const hint = renderHeldHint(this.heldDeliveryHints(peer), Date.now(), !adapter || !("deliveryOnly" in adapter) || adapter.deliveryOnly === false);
1028
+ if (hint) {
1029
+ // A reattach before the next delivery replaces the pending hint instead of merging a second one (its age text differs each time).
1030
+ const pending = this.prefaces.get(peer);
1031
+ if (pending) {
1032
+ const kept = pending.body.split("\n\n").filter(block => !HELD_HINT_HEADER.test(block)).join("\n\n");
1033
+ if (kept !== pending.body) { if (kept) this.prefaces.set(peer, { ...pending, body: kept }); else this.prefaces.delete(peer); }
1034
+ }
1035
+ this.preface(peer, hint);
1036
+ }
1037
+ } catch { /* a missing hint is not a delivery failure */ }
1038
+ }
1039
+
1007
1040
  private refreshRecoveryHold(peer: PeerId): void {
1008
1041
  if (!this.journal) return;
1009
1042
  // Live accepted notifications are awaiting explicit correlation, not crash recovery.
1010
- const blocked = this.journal.list(peer).some((r) => (r.state === "needs_review" && (!remoteId(peer) || r.originals.some(isInvocationKind))) || (["dispatching", "accepted"].includes(r.state) && this.activeDeliveries.get(r.id) !== peer));
1043
+ const blocked = this.journal.list(peer).some((r) => (r.state === "needs_review" && holdsPeerWide(peer, r.originals, r.holdsSelf)) || (["dispatching", "accepted"].includes(r.state) && this.activeDeliveries.get(r.id) !== peer));
1011
1044
  if (blocked) this.recoveryHeldPeers.add(peer); else this.recoveryHeldPeers.delete(peer);
1012
1045
  }
1013
1046
 
@@ -1,5 +1,6 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { sanitize } from "./envelope.ts";
3
+ import { isRecord as object } from "../primitives.ts";
3
4
 
4
5
  /**
5
6
  * #445 C1: what an agent can offer another, and what a person has agreed to share. Pure: no I/O, no clock, no process. The hub never calls any of these capabilities itself (C2 sends a request to the
@@ -44,7 +45,6 @@ export interface Capability {
44
45
  }
45
46
  export interface CapabilityManifest { capabilities: Capability[]; observedAt: number }
46
47
 
47
- const object = (value: unknown): value is Record<string, unknown> => !!value && typeof value === "object" && !Array.isArray(value);
48
48
  const CONTROL_CHARS = "[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f\\u2028\\u2029\\u202a-\\u202e\\u2066-\\u2069]";
49
49
  /** Two regexes on purpose: the global one replaces, the plain one tests (a global regex keeps lastIndex between test calls and would miss the second of two strings). */
50
50
  const CONTROL = new RegExp(CONTROL_CHARS, "g"), HAS_CONTROL = new RegExp(CONTROL_CHARS);
@@ -0,0 +1,46 @@
1
+ import { existsSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { canonicalPath, inheritedStateDir, projectContext } from "./project.ts";
4
+
5
+ export interface ChannelProject {
6
+ root: string; stateDir: string;
7
+ /** True when the state directory came from the inherited environment, proven. */
8
+ inherited: boolean;
9
+ /**
10
+ * Set when this process has no project of its own and an inherited state directory that records another project (agent-hub#1036): it joins that hub as a distinct session, never as the
11
+ * peer id it names. `label` is the origin part of the id the hub mints (`<peer>~<label>`), or empty to let the hub choose a short one.
12
+ */
13
+ session?: { label: string };
14
+ }
15
+
16
+ /**
17
+ * `cwd` is the plugin process's working directory, `env` its environment, `proveExtra` resolves a declared managed instance when the caller needs that path.
18
+ * Returns `undefined` only when there is nothing to join at all: no project of its own and no inherited state directory. Everything else joins something (agent-hub#1036: nothing that
19
+ * works today is refused): the proven project, the cwd's own project, or, when the process cannot prove it belongs to the hub its environment names, that hub as a distinct session.
20
+ */
21
+ export function channelProjectBase(cwd: string, env: NodeJS.ProcessEnv,
22
+ proveExtra?: (cwd: string, peer: string, declared: string, env: NodeJS.ProcessEnv) => ChannelProject | null | undefined): ChannelProject | undefined {
23
+ const override = env.AGENTHUB_STATE_DIR?.trim(), declared = env.AGENTHUB_PROJECT_DIR?.trim();
24
+ // A tools-mode helper (`AGENTHUB_MODE=tools`) is started by the hub or by an agent the hub started, with the state dir and project dir set for exactly that purpose: the Claude implementer child and
25
+ // an external-module instance run in their own managed worktree and must reach the owning hub, as they always did. The daemon checks their launch id itself at the hello. The root check below is
26
+ // for a channel session, a person's `claude` that may merely have inherited a pair (review thread on #1037; agent-hub#1036 AC4).
27
+ if (env.AGENTHUB_MODE === "tools" && override && declared) return { root: canonicalPath(declared), stateDir: canonicalPath(override), inherited: true };
28
+ // The origin label is left empty on purpose: the hub mints a short id, so no directory name reaches a header another agent reads.
29
+ const asSession = (): ChannelProject | undefined => override
30
+ ? { root: declared ? canonicalPath(declared) : "", stateDir: canonicalPath(override), inherited: false, session: { label: "" } } : undefined;
31
+ let own: ReturnType<typeof projectContext>;
32
+ try { own = projectContext(cwd, {}); } catch { return asSession(); }
33
+ const peer = env.AGENTHUB_PEER_ID;
34
+ if (peer && declared && proveExtra) {
35
+ try {
36
+ const extra = proveExtra(cwd, peer, declared, env);
37
+ if (extra !== undefined) return extra ?? asSession();
38
+ } catch { return asSession(); }
39
+ }
40
+ const inherited = inheritedStateDir(own.root, env);
41
+ if (inherited) return { root: own.root, stateDir: inherited, inherited: true };
42
+ // No project of its own (no .agenthub/config.json up to the git boundary) and an inherited state directory that is not proven to belong here: it joins that hub as a distinct session.
43
+ // With a project of its own (a linked worktree, say) it keeps that project's own hub, as before.
44
+ if (override && !existsSync(join(own.root, ".agenthub", "config.json"))) return asSession();
45
+ return { root: own.root, stateDir: own.stateDir, inherited: false };
46
+ }
@@ -8,54 +8,29 @@ import { builtinPolicyOf as definitionOf } from "../adapters/declaration-data.ts
8
8
  import { readChannelInstanceConfig } from "../adapters/declaration-data.ts";
9
9
  import { effectiveInstanceRoles } from "./instances.ts";
10
10
  import { resolveInstanceExecutionCwd } from "./instance-execution.ts";
11
- import { existsSync } from "node:fs";
11
+ import { readFileSync } from "node:fs";
12
+ import { DEFAULT_ROLES } from "../adapters/definitions/native-adapter-policy.ts";
12
13
  import { join } from "node:path";
13
- import { canonicalPath, inheritedStateDir, projectContext, projectRoot, realPath } from "./project.ts";
14
+ import { channelProjectBase, type ChannelProject } from "./channel-project-base.ts";
15
+ import { inheritedStateDir, projectRoot, realPath } from "./project.ts";
14
16
 
15
- export interface ChannelProject {
16
- root: string; stateDir: string;
17
- /** True when the state directory came from the inherited environment, proven. */
18
- inherited: boolean;
19
- /**
20
- * Set when this process has no project of its own and an inherited state directory that records another project (agent-hub#1036): it joins that hub as a distinct session, never as the
21
- * peer id it names. `label` is the origin part of the id the hub mints (`<peer>~<label>`), or empty to let the hub choose a short one.
22
- */
23
- session?: { label: string };
24
- }
17
+ export type { ChannelProject } from "./channel-project-base.ts";
25
18
 
26
- /**
27
- * `cwd` is the plugin process's working directory, `env` its environment, `policyRoles(root)` the configured roles of a project (the same merge the plugin and the CLI use).
28
- * Returns `undefined` only when there is nothing to join at all: no project of its own and no inherited state directory. Everything else joins something (agent-hub#1036: nothing that
29
- * works today is refused): the proven project, the cwd's own project, or, when the process cannot prove it belongs to the hub its environment names, that hub as a distinct session.
30
- */
31
19
  export function channelProject(cwd: string, env: NodeJS.ProcessEnv, policyRoles: (root: string) => Record<string, string[]>): ChannelProject | undefined {
32
- const override = env.AGENTHUB_STATE_DIR?.trim(), declared = env.AGENTHUB_PROJECT_DIR?.trim();
33
- // A tools-mode helper (`AGENTHUB_MODE=tools`) is started by the hub or by an agent the hub started, with the state dir and project dir set for exactly that purpose: the Claude implementer child and
34
- // an external-module instance run in their own managed worktree and must reach the owning hub, as they always did. The daemon checks their launch id itself at the hello. The root check below is
35
- // for a channel session, a person's `claude` that may merely have inherited a pair (review thread on #1037; agent-hub#1036 AC4).
36
- if (env.AGENTHUB_MODE === "tools" && override && declared) return { root: canonicalPath(declared), stateDir: canonicalPath(override), inherited: true };
37
- // The origin label is left empty on purpose: the hub mints a short id, so no directory name reaches a header another agent reads.
38
- const asSession = (): ChannelProject | undefined => override
39
- ? { root: declared ? canonicalPath(declared) : "", stateDir: canonicalPath(override), inherited: false, session: { label: "" } } : undefined;
40
- let own: ReturnType<typeof projectContext>;
41
- try { own = projectContext(cwd, {}); } catch { return asSession(); }
42
- const peer = env.AGENTHUB_PEER_ID;
43
- if (peer && declared && !definitionOf(peer)) {
44
- // A declared extra instance: its workspace is the exact managed worktree the project declares for it, and its hub is the project that declares it.
45
- try {
46
- const root = realPath(declared), config = readChannelInstanceConfig(root);
47
- if (config.instances && Object.hasOwn(config.instances, peer)) {
48
- const workspace = resolveInstanceExecutionCwd(root, peer, config.instances, effectiveInstanceRoles(peer, config.instances, policyRoles(root), config.catalog), config.catalog);
49
- if (realPath(projectRoot(cwd)) !== realPath(workspace)) return asSession();
50
- const stateDir = inheritedStateDir(root, env);
51
- return stateDir ? { root, stateDir, inherited: true } : asSession();
52
- }
53
- } catch { return asSession(); }
54
- }
55
- const inherited = inheritedStateDir(own.root, env);
56
- if (inherited) return { root: own.root, stateDir: inherited, inherited: true };
57
- // No project of its own (no .agenthub/config.json up to the git boundary) and an inherited state directory that is not proven to belong here: it joins that hub as a distinct session.
58
- // With a project of its own (a linked worktree, say) it keeps that project's own hub, as before.
59
- if (override && !existsSync(join(own.root, ".agenthub", "config.json"))) return asSession();
60
- return { root: own.root, stateDir: own.stateDir, inherited: false };
20
+ return channelProjectBase(cwd, env, (cwd, peer, declared, env) => {
21
+ if (definitionOf(peer)) return undefined;
22
+ // A declared extra instance must be in its exact managed worktree.
23
+ const root = realPath(declared), config = readChannelInstanceConfig(root);
24
+ if (!config.instances || !Object.hasOwn(config.instances, peer)) return undefined;
25
+ const workspace = resolveInstanceExecutionCwd(root, peer, config.instances, effectiveInstanceRoles(peer, config.instances, policyRoles(root), config.catalog), config.catalog);
26
+ if (realPath(projectRoot(cwd)) !== realPath(workspace)) return null;
27
+ const stateDir = inheritedStateDir(root, env);
28
+ return stateDir ? { root, stateDir, inherited: true } : null;
29
+ });
30
+ }
31
+
32
+ /** Project resolution applies the same shared and machine-local role overrides on both startup paths. */
33
+ export function channelProjectRoles(root: string): Record<string, string[]> {
34
+ const read = (name: string) => { try { return JSON.parse(readFileSync(join(root, ".agenthub", name), "utf8")).roles ?? {}; } catch { return {}; } };
35
+ return { ...DEFAULT_ROLES, ...read("config.json"), ...read("config.local.json") };
61
36
  }
@@ -227,7 +227,7 @@ const schema: Record<string, Check> = {
227
227
  supervision: block({ mode: words(["off", "shadow", "advisory"]) }),
228
228
  edit_governance: block({ arm: words(["baseline", "route_guard", "occ_guard", "combined_guard"]) }),
229
229
  roadmap: block({ github_mirror: bool, github_write: words(["off", "conductor"]) }),
230
- bus: block({ max_attempts: operationalNumberCheck("bus.max_attempts"), digest_max: operationalNumberCheck("bus.digest_max"), pull_budget_bytes: operationalNumberCheck("bus.pull_budget_bytes"), notes_kept: operationalNumberCheck("bus.notes_kept"), terminal_history_limit: operationalNumberCheck("bus.terminal_history_limit"), accepted_settle_ms: operationalNumberCheck("bus.accepted_settle_ms") }),
230
+ bus: block({ max_attempts: operationalNumberCheck("bus.max_attempts"), digest_max: operationalNumberCheck("bus.digest_max"), pull_budget_bytes: operationalNumberCheck("bus.pull_budget_bytes"), notes_kept: operationalNumberCheck("bus.notes_kept"), terminal_history_limit: operationalNumberCheck("bus.terminal_history_limit"), accepted_settle_ms: operationalNumberCheck("bus.accepted_settle_ms"), hold_notice_ms: number(0, 86_400_000, true) }),
231
231
  adapter_timing: block({ acp_tool_ceiling_min: operationalNumberCheck("adapter_timing.acp_tool_ceiling_min"), acp_activity_batch_ms: operationalNumberCheck("adapter_timing.acp_activity_batch_ms"), jcode_steer_timeout_s: operationalNumberCheck("adapter_timing.jcode_steer_timeout_s") }),
232
232
  model_relay: block({ cooldown_failures: operationalNumberCheck("model_relay.cooldown_failures"), cooldown_s: operationalNumberCheck("model_relay.cooldown_s"), cooldown_cap_s: operationalNumberCheck("model_relay.cooldown_cap_s"), terminal_history_limit: operationalNumberCheck("model_relay.terminal_history_limit") }),
233
233
  console: block({ poll_ms: operationalNumberCheck("console.poll_ms"), notice_ms: operationalNumberCheck("console.notice_ms"), history_limit: operationalNumberCheck("console.history_limit"), pending_stream_limit: operationalNumberCheck("console.pending_stream_limit"), attention_limit: operationalNumberCheck("console.attention_limit") }),
@@ -5,6 +5,7 @@ import { configRepositoryPresent, configTracked } from "./config-trust.ts";
5
5
  import { configTier, CONFIG_EDIT_FILES, TIER3_INSTANCE_FIELDS, type ConfigEditFile } from "./config-tier.ts";
6
6
  import { sdlcConfig } from "./sdlc.ts";
7
7
  import { VERSION } from "../version.ts";
8
+ import { isRecord as isObject } from "../primitives.ts";
8
9
 
9
10
  /**
10
11
  * #689: structural config edits. This module is pure file work plus the loaders' verdict: it never publishes, never
@@ -23,7 +24,6 @@ export const MAX_EDIT_SETS = 16;
23
24
  export const MAX_VALUE_BYTES = 16 * 1024;
24
25
  const MAX_FILE_BYTES: Record<ConfigEditFile, number> = { "config.local.json": 1024 * 1024, "sdlc.toml": 64 * 1024 };
25
26
  export const BACKUPS_KEPT = 5;
26
- const isObject = (value: unknown): value is Record<string, unknown> => !!value && typeof value === "object" && !Array.isArray(value);
27
27
  const sha = (text: string): string => createHash("sha256").update(text).digest("hex");
28
28
  export const fileRevision = (text: string | null): string => text === null ? "absent" : sha(text);
29
29
  /** A short, stable hash of a value for the audit event: the value itself never enters it. */
@@ -1,5 +1,6 @@
1
1
  import { NEVER_EDITABLE, SETTINGS } from "./settings.ts";
2
2
  import { DEFAULT_BRIDGE_WINDOW } from "./protocol-window.ts";
3
+ import { isRecord as isObject } from "../primitives.ts";
3
4
 
4
5
  /**
5
6
  * #689: which structural keys a person may edit, and from where.
@@ -32,7 +33,6 @@ const REGISTRY_PREFIXES = ["roster", "tasks.wip_limits", "permission_modes", "ca
32
33
  const registryKey = (key: string): boolean => SETTINGS.some(def => def.key === key || def.path.join(".") === key) || REGISTRY_PREFIXES.some(prefix => key === prefix || key.startsWith(`${prefix}.`));
33
34
 
34
35
  const refuse = (reason: string): { refused: string } => ({ refused: `${reason}; nothing was written` });
35
- const isObject = (value: unknown): value is Record<string, unknown> => !!value && typeof value === "object" && !Array.isArray(value);
36
36
 
37
37
  /**
38
38
  * The tier of one edit. `value` is only read for a whole `instances.<id>` object, whose fields are classified one by one
package/src/hub/config.ts CHANGED
@@ -80,7 +80,7 @@ export interface HubConfig {
80
80
  batch_ms: number;
81
81
  queue_cap: number;
82
82
  /** #489 H3: accepted delivery policy, read at the next delivery operation without rewriting queued work. */
83
- bus?: { max_attempts?: number; digest_max?: number; pull_budget_bytes?: number; notes_kept?: number; terminal_history_limit?: number; accepted_settle_ms?: number };
83
+ bus?: { max_attempts?: number; digest_max?: number; pull_budget_bytes?: number; notes_kept?: number; terminal_history_limit?: number; accepted_settle_ms?: number; hold_notice_ms?: number };
84
84
  /** #489 H5: accepted timing captured only when a new native adapter is constructed. */
85
85
  adapter_timing?: AdapterTimingConfig["adapter_timing"];
86
86
  /** #489 H6: relay policy is captured from restart-bound accepted configuration. */
@@ -111,7 +111,7 @@ export interface HubConfig {
111
111
  context: ContextConfig;
112
112
  inference: InferenceConfig;
113
113
  omniroute: OmniRouteConfig;
114
- pi: { enabled: boolean; auto_start: boolean; cmd: string[]; backend: "auto" | "dgx" | "mlx"; dgx_coding: string; dgx_fast: string; max_steps: number; max_continuations: number };
114
+ pi: { enabled: boolean; auto_start: boolean; cmd?: string[]; backend: "auto" | "dgx" | "mlx"; dgx_coding: string; dgx_fast: string; max_steps: number; max_continuations: number };
115
115
  mlx: { enabled: boolean } & Pick<MlxOptions, "provider" | "host" | "runtimeDir" | "modelPath" | "port" | "model" | "sourceModel" | "contextWindow" | "maxInputTokens" | "maxTokens" | "maxConcurrency">;
116
116
  /** `bash_network`: true is network through the egress proxy to `network_allow` (#65); "direct" is everything, until 0.13.0 (#83). */
117
117
  local: { deny: string[]; bash_network: boolean | "direct"; network_allow: string[]; max_steps: number; read_allow: string[]; /** #515: offer the local worker `doc_read` (PDF, DOCX, HWPX through `text_projection`); off by default, machine-local. */ doc_read: boolean; /** #515b: the hosts the local worker's `web_fetch` may read; empty (the default) means the tool does not exist. Machine-local. */ web_fetch: { allow: string[] } };
@@ -1,5 +1,6 @@
1
1
  import matrixJson from "../../templates/presets/confirmation-matrix.json";
2
2
  import { ADAPTERS } from "../adapters/registry.ts";
3
+ import { isRecord as isObject } from "../primitives.ts";
3
4
 
4
5
  /**
5
6
  * #999 T0: the model-free inventory of every place a person is asked to confirm during a standard task, per agent kind and
@@ -84,7 +85,6 @@ export function catalogKinds(): CatalogKind[] {
84
85
  }
85
86
 
86
87
  const same = (left: readonly string[], right: readonly string[]): boolean => left.length === right.length && [...left].sort().join("\0") === [...right].sort().join("\0");
87
- const isObject = (value: unknown): value is Record<string, unknown> => !!value && typeof value === "object" && !Array.isArray(value);
88
88
  const oneOf = <T extends string>(list: readonly T[], value: unknown): value is T => typeof value === "string" && (list as readonly string[]).includes(value);
89
89
 
90
90
  /** Every kind and environment the rows cover, or name: a pair with neither the two required points nor an `unavailable` entry is a gap. */