@staix/agent-hub 0.12.32 → 0.12.34

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 (110) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +6 -5
  3. package/docs/agent-notes/adapters.md +7 -3
  4. package/docs/agent-notes/budget.md +5 -3
  5. package/docs/agent-notes/bus.md +2 -0
  6. package/docs/agent-notes/daemon.md +7 -5
  7. package/docs/agent-notes/tasks.md +3 -2
  8. package/docs/agent-notes/tests.md +2 -1
  9. package/docs/operations.md +48 -14
  10. package/docs/quickstart.md +5 -3
  11. package/docs/security.md +10 -2
  12. package/docs/smoke.md +1 -1
  13. package/docs/specs/2026-09-19-agent-hub-design.md +246 -4
  14. package/docs/specs/2026-09-20-upgrade-recovery-design.md +20 -0
  15. package/docs/verification/2026-10-18-0.12.33.md +42 -0
  16. package/docs/verification/2026-10-18-0.12.34.md +48 -0
  17. package/docs/verified.json +33 -19
  18. package/package.json +1 -1
  19. package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
  20. package/plugins/agent-hub/server.js +22882 -16496
  21. package/src/adapters/codex-appserver.ts +81 -11
  22. package/src/adapters/definitions/builtin-metadata.ts +101 -7
  23. package/src/adapters/definitions/native-cli-claude-launch.ts +90 -0
  24. package/src/adapters/definitions/native-cli-claude-setup.ts +80 -0
  25. package/src/adapters/definitions/native-cli-codex-launch.ts +14 -0
  26. package/src/adapters/definitions/native-cli-doctor.ts +46 -0
  27. package/src/adapters/definitions/native-cli-entry-claude.ts +52 -0
  28. package/src/adapters/definitions/native-cli-entry-codex.ts +26 -0
  29. package/src/adapters/definitions/native-cli-entry-jcode.ts +24 -0
  30. package/src/adapters/definitions/native-cli-entry-kimi.ts +52 -0
  31. package/src/adapters/definitions/native-cli-entry-local.ts +14 -0
  32. package/src/adapters/definitions/native-cli-entry-pi.ts +51 -0
  33. package/src/adapters/definitions/native-cli-entry-qwen.ts +20 -0
  34. package/src/adapters/definitions/native-cli-entry-types.ts +40 -0
  35. package/src/adapters/definitions/native-cli-entry.ts +19 -0
  36. package/src/adapters/definitions/native-cli-jcode-mcp.ts +58 -0
  37. package/src/adapters/definitions/native-cli-launch-common.ts +17 -0
  38. package/src/adapters/definitions/native-cli-pi.ts +33 -0
  39. package/src/adapters/definitions/native-cli-preview-claude.ts +37 -0
  40. package/src/adapters/definitions/native-cli-preview-codex.ts +20 -0
  41. package/src/adapters/definitions/native-cli-preview-common.ts +57 -0
  42. package/src/adapters/definitions/native-cli-preview-jcode.ts +20 -0
  43. package/src/adapters/definitions/native-cli-preview-kimi.ts +28 -0
  44. package/src/adapters/definitions/native-cli-preview-pi.ts +36 -0
  45. package/src/adapters/definitions/native-cli-preview-qwen.ts +22 -0
  46. package/src/adapters/definitions/native-cli-preview.ts +16 -0
  47. package/src/adapters/definitions/native-config-defaults.ts +19 -0
  48. package/src/adapters/definitions/native-config-policy.ts +35 -0
  49. package/src/adapters/definitions/native-context.ts +35 -0
  50. package/src/adapters/definitions/native-daemon-kimi.ts +5 -0
  51. package/src/adapters/definitions/native-daemon-policy.ts +18 -0
  52. package/src/adapters/definitions/native-display.ts +18 -0
  53. package/src/adapters/definitions/native-factories.ts +48 -0
  54. package/src/adapters/definitions/native-policy-aux.ts +130 -0
  55. package/src/adapters/definitions/native-quota.ts +29 -0
  56. package/src/adapters/definitions/native-recovery-continuity.ts +12 -0
  57. package/src/adapters/definitions/native-recovery.ts +88 -0
  58. package/src/adapters/definitions/qwen.ts +8 -4
  59. package/src/adapters/registry-types.ts +97 -10
  60. package/src/adapters/registry.ts +103 -3
  61. package/src/cli/console-state.ts +5 -5
  62. package/src/cli/identity.ts +6 -5
  63. package/src/cli/jcode-mcp.ts +2 -58
  64. package/src/cli/launch.ts +14 -100
  65. package/src/cli/main.ts +35 -272
  66. package/src/cli/output.ts +3 -2
  67. package/src/cli/preview.ts +14 -125
  68. package/src/cli/recovery-guidance.ts +17 -13
  69. package/src/cli/reset.ts +13 -1
  70. package/src/cli/setup.ts +2 -80
  71. package/src/cli/shell-quote.ts +3 -0
  72. package/src/cli/terminal-recovery.ts +17 -10
  73. package/src/cli/upgrade-interactive.ts +4 -2
  74. package/src/cli/upgrade-presentation.ts +11 -1
  75. package/src/cli/upgrade-restore-state.ts +2 -1
  76. package/src/cli/upgrade-runtime.ts +107 -146
  77. package/src/cli/upgrade.ts +10 -7
  78. package/src/hub/budget.ts +6 -30
  79. package/src/hub/bus.ts +133 -14
  80. package/src/hub/conductor.ts +8 -4
  81. package/src/hub/config-apply.ts +9 -13
  82. package/src/hub/config-reload.ts +7 -2
  83. package/src/hub/context-window.ts +3 -27
  84. package/src/hub/control-client.ts +1 -1
  85. package/src/hub/crash.ts +2 -35
  86. package/src/hub/daemon.ts +244 -241
  87. package/src/hub/deferred-hub.ts +60 -0
  88. package/src/hub/delivery-journal.ts +6 -0
  89. package/src/hub/execution-budget.ts +2 -1
  90. package/src/hub/hub-tools.ts +3 -3
  91. package/src/hub/peer-catalog.ts +4 -13
  92. package/src/hub/permission-mode.ts +9 -12
  93. package/src/hub/recovery-continuity.ts +6 -5
  94. package/src/hub/report.ts +9 -8
  95. package/src/hub/restart.ts +12 -1
  96. package/src/hub/roster.ts +6 -7
  97. package/src/hub/routing.ts +21 -10
  98. package/src/hub/settings.ts +6 -5
  99. package/src/hub/settled-roles.ts +1 -1
  100. package/src/hub/start-mode.ts +8 -6
  101. package/src/hub/tasks.ts +14 -11
  102. package/src/hub/tooling.ts +4 -60
  103. package/src/hub/ui.ts +3 -1
  104. package/src/memory/recall.ts +4 -5
  105. package/src/models/route/signals.ts +3 -1
  106. package/src/pi/launch.ts +2 -1
  107. package/src/ui/index.html +3 -2
  108. package/src/ui/office-model.ts +3 -1
  109. package/src/ui/peer-palette.ts +16 -6
  110. package/templates/routing.toml +2 -2
@@ -0,0 +1,60 @@
1
+ import { HUB, MAX_HOP, type Envelope } from "./envelope.ts";
2
+
3
+ /** ponytail: cap recovery at 2048 unpublished hub originals; replace with a paged durable outbox if measured recovery workloads exceed it. */
4
+ export const MAX_DEFERRED_HUB = 2048;
5
+
6
+ /** Refuses admission without dropping already accepted deferred work. */
7
+ export class RecoveryDeferredHubError extends Error {
8
+ readonly code = "recovery_deferred_hub";
9
+ constructor(message = "recovery deferred hub notice limit reached; release or abort recovery before publishing more notices") {
10
+ super(message);
11
+ this.name = "RecoveryDeferredHubError";
12
+ }
13
+ }
14
+
15
+ /** Journal-less restore uses the same bounded core envelope shape as durable deferred work. */
16
+ export function validateDeferredEnvelope(value: unknown, name: string): Envelope {
17
+ if (!value || typeof value !== "object" || Array.isArray(value))
18
+ throw new RecoveryDeferredHubError(`${name} must be an envelope`);
19
+ const env = value as Record<string, unknown>;
20
+ const text = (value: unknown, max: number) => typeof value === "string" && value.length > 0 && value.length <= max;
21
+ if (!text(env.id, 256) || !text(env.trace, 256) || env.from !== HUB ||
22
+ typeof env.body !== "string" || env.body.length > 1_000_000 ||
23
+ !Number.isSafeInteger(env.hop) || (env.hop as number) < 0 || (env.hop as number) > MAX_HOP ||
24
+ !Number.isSafeInteger(env.ts) || (env.ts as number) < 0 ||
25
+ !["chat", "task", "review", "status", "budget", "presence"].includes(env.kind as string) ||
26
+ !["important", "status", "fyi"].includes(env.priority as string) ||
27
+ (!Array.isArray(env.to) || env.to.length > 256 || !env.to.every(peer => text(peer, 256))) ||
28
+ (env.private !== undefined && typeof env.private !== "boolean"))
29
+ throw new RecoveryDeferredHubError(`${name} is invalid`);
30
+ if (env.refs !== undefined) {
31
+ if (!env.refs || typeof env.refs !== "object" || Array.isArray(env.refs)) throw new RecoveryDeferredHubError(`${name}.refs is invalid`);
32
+ const refs = env.refs as Record<string, unknown>;
33
+ for (const key of ["repo", "branch", "commit", "task"])
34
+ if (refs[key] !== undefined && !text(refs[key], 4096)) throw new RecoveryDeferredHubError(`${name}.refs.${key} is invalid`);
35
+ if (refs.paths !== undefined && (!Array.isArray(refs.paths) || refs.paths.length > 256 || !refs.paths.every(path => text(path, 4096))))
36
+ throw new RecoveryDeferredHubError(`${name}.refs.paths is invalid`);
37
+ }
38
+ return value as Envelope;
39
+ }
40
+
41
+ /** Callers keep their existing envelope validation; this leaf checks deferred-only invariants. */
42
+ export function validateDeferredHub(
43
+ value: unknown,
44
+ envelope: (value: unknown, name: string) => Envelope = validateDeferredEnvelope,
45
+ occupied: ReadonlySet<string> = new Set(),
46
+ name = "bus.deferredHub",
47
+ ): Envelope[] {
48
+ if (value === undefined) return [];
49
+ if (!Array.isArray(value) || value.length > MAX_DEFERRED_HUB)
50
+ throw new RecoveryDeferredHubError(`${name} must be an array of at most ${MAX_DEFERRED_HUB} hub envelopes`);
51
+ const ids = new Set<string>();
52
+ return value.map((item, index) => {
53
+ validateDeferredEnvelope(item, `${name}[${index}]`);
54
+ const env = envelope(item, `${name}[${index}]`);
55
+ if (env.from !== HUB) throw new RecoveryDeferredHubError(`${name}[${index}] is not hub-originated`);
56
+ if (ids.has(env.id) || occupied.has(env.id)) throw new RecoveryDeferredHubError(`${name}[${index}] repeats an accepted envelope id`);
57
+ ids.add(env.id);
58
+ return env;
59
+ });
60
+ }
@@ -6,6 +6,7 @@ import { HUB, USER, type Envelope, type Kind } from "./envelope.ts";
6
6
  import { heldDeliveryHints } from "./delivery-hints.ts";
7
7
  import { processLiveness } from "../pi/process-signature.ts";
8
8
  import { HUB_DB_BUSY_TIMEOUT_MS } from "./db-timeout.ts";
9
+ import { validateDeferredHub } from "./deferred-hub.ts";
9
10
 
10
11
  export type JournalDeliveryState =
11
12
  | "queued"
@@ -167,6 +168,11 @@ function validateBus(value: unknown, name = "bus"): BusSnapshot {
167
168
  list(b.manualPaused, `${name}.manualPaused`, 4096).forEach((id) =>
168
169
  text(id, `${name}.manualPaused[]`, 256),
169
170
  );
171
+ const occupied = new Set<string>([
172
+ ...(b.seen as Envelope[]).map(env => env.id),
173
+ ...Object.values(queues).flatMap(items => (items as Envelope[]).map(env => env.id)),
174
+ ]);
175
+ validateDeferredHub(b.deferredHub, validateEnvelope, occupied, `${name}.deferredHub`);
170
176
  if (b.journal !== undefined) fail("nested journal snapshot is invalid");
171
177
  return b as unknown as BusSnapshot;
172
178
  }
@@ -1,3 +1,4 @@
1
+ import { definitionOf } from "../adapters/registry.ts";
1
2
  import { Database } from "bun:sqlite";
2
3
  import { HUB_DB_BUSY_TIMEOUT_MS } from "./db-timeout.ts";
3
4
 
@@ -56,7 +57,7 @@ export class ExecutionBudget {
56
57
  if (input.kind === "task" && (!Number.isSafeInteger(input.taskId) || input.taskId! < 1)) throw new Error("task budget requires a positive task id");
57
58
  const peers = [...new Set(input.peers.filter((p) => typeof p === "string" && p.length > 0))].sort();
58
59
  if (!peers.length) throw new Error("execution budget requires at least one peer");
59
- const unsupported = peers.filter((peer) => peer !== "pi" && peer !== "local");
60
+ const unsupported = peers.filter((peer) => !definitionOf(peer)?.budget?.instrumented);
60
61
  if (unsupported.length) throw new Error(`execution budgets require instrumented peers (pi, local); unsupported: ${unsupported.join(", ")}`);
61
62
  const limits = validLimits(input.limits ?? {});
62
63
  if (!Object.keys(limits).length) throw new Error("execution budget requires at least one supported limit");
@@ -1,7 +1,7 @@
1
1
  import { SDLC_STAGES } from "./sdlc.ts";
2
2
  import { projectProfile, profileData, PROFILE_CLASS_NAMES, type ProfileName, type ProfileSelection } from "./profiles.ts";
3
3
  import { catalogSection, type CatalogRole } from "./roles.ts";
4
- import { SUPPORTED_PEERS, defaultPeerRoles } from "./peer-catalog.ts";
4
+ import { CONDUCTOR_START_PEERS, defaultPeerRoles } from "../adapters/registry.ts";
5
5
  // The hub's task tools, defined once: the MCP server (Claude plugin, Kimi, Codex) and the local worker both read this.
6
6
  import { NOTE_KINDS } from "./envelope.ts";
7
7
 
@@ -63,7 +63,7 @@ export const TASK_TOOLS: HubTool[] = [
63
63
  tool("hub_task_done", "Mark your task finished. It goes to its reviewer with your summary and refs. When the project configures a check for its class, the hub runs it first and the result comes as a task message: a failed check keeps the task with you.", { id, summary: { type: "string", description: "what changed, why, and the check you ran with its result" }, refs }, ["id", "summary"]),
64
64
  tool("hub_sdlc_record", "Record artifact ids or claimed local checks on your task. This grants no authority or external-check evidence. Only its owner/reviewer or the person may record; only its reviewer/person may name a reviewed head or phase checklist. Phase evidence refs are content hashes, not external verification.", { id, receipt: { type: "object", properties: { stage: { type: "string", enum: ["spec", "plan", "implement", "review", "verify", "merge", "release"] }, repo: str, issue: id, pr: id, localHead: str, localResult: { type: "string", enum: ["passed", "failed", "unknown"] }, reviewedHead: str, phase: { type: "object", properties: { id: str, head: str, tasks: { type: "array", maxItems: 64, items: { type: "object", properties: { id, after: { type: "array", maxItems: 16, items: id } }, required: ["id", "after"], additionalProperties: false } }, criteria: { type: "array", maxItems: 32, items: { type: "object", properties: { id: str, required: { type: "boolean" }, result: { type: "string", enum: ["verified", "failed", "unverified"] }, refs: { type: "array", maxItems: 8, items: str } }, required: ["id", "required", "result", "refs"], additionalProperties: false } } }, required: ["id", "tasks", "criteria"], additionalProperties: false } }, additionalProperties: false } }, ["id", "receipt"]),
65
65
  tool("hub_task_list", "The task board. PII tasks show as [pii].", { state: { type: "string", enum: ["proposed", "in_progress", "in_review", "approved", "changes_requested", "cancelled"] }, ready: { type: "boolean", description: "only proposed tasks with nothing left to wait for" } }),
66
- tool("hub_review", "Give your verdict on a task you were asked to review: map the changed signatures and call sites to the task's plan or detail, read the check result (hub_task_show has it, with the done summary), and list what is unmet. Two changes_requested in a row move the task to another peer.", { id, head: { type: "string", description: "full SHA actually reviewed; enforce binds approval to the current PR head" }, verdict: { type: "string", enum: ["approved", "changes_requested"] }, note: str, unmet: { type: "array", items: str, description: "each requirement of the plan or detail that the change does not meet" } }, ["id", "verdict"]),
66
+ tool("hub_review", "Give your verdict on a task you were asked to review: map the changed signatures and call sites to the task's plan or detail, read the check result (hub_task_show has it, with the done summary), and list what is unmet. Consecutive changes_requested verdicts (three by default, `tasks.escalate_after`) move the task to another peer.", { id, head: { type: "string", description: "full SHA actually reviewed; enforce binds approval to the current PR head" }, verdict: { type: "string", enum: ["approved", "changes_requested"] }, note: str, unmet: { type: "array", items: str, description: "each requirement of the plan or detail that the change does not meet" } }, ["id", "verdict"]),
67
67
  tool("hub_checkpoint", "Answer a checkpoint request from the hub (quota or context window pressure): what you were doing, what is half done, what whoever continues must know. Write the same to .agenthub/checkpoint.md first if you can.", { summary: str, request_id: { type: "string", description: "The request id supplied by a context checkpoint request; required for context checkpoints" } }, ["summary"]),
68
68
  tool("hub_memory_search", "Search daemon-scoped visible memory, fails first. Query <=200 UTF-8 bytes; default 8, max 20 lines; whole output <=4 KB. Incomplete excerpts are marked. No project argument.", { query: { type: "string", maxLength: 200, description: "At most 200 UTF-8 bytes, enforced by the daemon" }, limit: { type: "integer", minimum: 1, maximum: 20 } }, ["query"]),
69
69
  tool("hub_memory_show", "Read up to 8 visible memory ids or unique prefixes (6..64 UTF-8 bytes each). Original ids redirect; unavailable ids share one refusal. Whole output <=8 KB.", { ids: { type: "array", minItems: 1, maxItems: 8, items: { type: "string", minLength: 6, maxLength: 64, description: "6 to 64 UTF-8 bytes" } } }, ["ids"]),
@@ -80,7 +80,7 @@ export const CONDUCTOR_TOOLS: HubTool[] = [
80
80
  tool("hub_task_show", "Read a task's public view and history, its done summary and check result included. PII tasks remain stubs. Only the conductor and the task's current owner and reviewer may use this tool.", { id }, ["id"]),
81
81
  tool("hub_task_assign", "Name an owner (default role) or reviewer. Only the conductor may name a reviewer through this tool. A proposer may redirect an unaccepted proposed task's owner; a task that still waits reserves that owner. Pull-only peers receive work when named or when they claim it. With an explicit capabilities list, the conductor needs assign capability for either role, the proposer only to give ownership to another peer.", { id, peer: str, role: { type: "string", enum: ["owner", "reviewer"] } }, ["id", "peer"]),
82
82
  tool("hub_task_escalate", "Escalate a task through the normal task flow, as the conductor. Requires assign capability when explicitly listed.", { id }, ["id"]),
83
- tool("hub_peer_start", "Start local, kimi, qwen, jcode, pi, claude or codex in the start mode a person set for it; you cannot choose the mode. A headless peer starts at once. A TUI peer (claude, and pi and codex by default) opens in a terminal with a fixed command; when the hub cannot open a terminal the call fails with the command for the person to run.", { peer: { type: "string", enum: ["local", "kimi", "pi", ...SUPPORTED_PEERS.filter(peer => !["local", "kimi", "pi"].includes(peer))] } }, ["peer"]),
83
+ tool("hub_peer_start", "Start local, kimi, qwen, jcode, pi, claude or codex in the start mode a person set for it; you cannot choose the mode. A headless peer starts at once. A TUI peer (claude, and pi and codex by default) opens in a terminal with a fixed command; when the hub cannot open a terminal the call fails with the command for the person to run.", { peer: { type: "string", enum: CONDUCTOR_START_PEERS } }, ["peer"]),
84
84
  tool("hub_peer_hold", "Hold a peer's deliveries as the conductor. This hold is separate from the person's hold and budget pauses.", { peer: str }, ["peer"]),
85
85
  tool("hub_peer_release", "Release only the conductor hold you placed. Never lifts a person's hold or a budget pause.", { peer: str }, ["peer"]),
86
86
  ];
@@ -1,4 +1,5 @@
1
- import { definitionOf } from "../adapters/registry.ts";
1
+ import { definitionOf, SUPPORTED_PEERS } from "../adapters/registry.ts";
2
+ export { SUPPORTED_PEERS } from "../adapters/registry.ts";
2
3
 
3
4
  // ponytail: older staged coordinators read these literal declarations to probe target support.
4
5
  // A2 replaces that source probe with a published capability before deleting the compatibility exports.
@@ -6,7 +7,6 @@ import { definitionOf } from "../adapters/registry.ts";
6
7
  export const KNOWN_PEERS = ["claude", "codex", "kimi", "pi", "local"] as const;
7
8
  /** Optional production peers are added explicitly; legacy defaults remain stable. */
8
9
  export const OPTIONAL_PEERS = ["qwen", "jcode"] as const;
9
- export const SUPPORTED_PEERS = [...KNOWN_PEERS, ...OPTIONAL_PEERS] as const;
10
10
  export type KnownPeer = typeof SUPPORTED_PEERS[number];
11
11
 
12
12
  export const isKnownPeer = (value: unknown): value is KnownPeer =>
@@ -15,14 +15,5 @@ export const isKnownPeer = (value: unknown): value is KnownPeer =>
15
15
  export const isSupportedPeer = (value: unknown): value is KnownPeer =>
16
16
  typeof value === "string" && !!definitionOf(value);
17
17
 
18
- // Policy metadata, not a membership list. Preserve DEFAULT_ROLES' existing key order.
19
- const ROLE_ORDER: readonly KnownPeer[] = ["claude", "codex", "kimi", "local", "pi", "qwen", "jcode"];
20
-
21
- /** Each caller owns its role arrays; changing a project's defaults cannot change another's. */
22
- export function defaultPeerRoles(includeOptional = false): Record<string, string[]> {
23
- return Object.fromEntries(ROLE_ORDER.filter(peer => includeOptional || !definitionOf(peer)!.optional)
24
- .map(peer => [peer, [...definitionOf(peer)!.roles]]));
25
- }
26
-
27
- /** #455: who may hold the planner role, in the order automatic assignment tries them; the hub-sandboxed pi and local never plan. */
28
- export const PLANNER_PEERS = ["claude", "codex", "kimi", "qwen", "jcode"] as const;
18
+ // Policy and historical projection order belong to the registry; public compatibility exports remain intact.
19
+ export { defaultPeerRoles, PLANNER_PEERS } from "../adapters/registry.ts";
@@ -1,4 +1,3 @@
1
- import { isSupportedPeer } from "./peer-catalog.ts";
2
1
  import { definitionOf } from "../adapters/registry.ts";
3
2
  import { lstatSync } from "node:fs";
4
3
  import { isAbsolute, relative, resolve, sep } from "node:path";
@@ -14,8 +13,9 @@ export function permissionDefaults(value: unknown): Record<string, PermissionMod
14
13
  if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("permission_modes must be an object with ask, ask-when-needed or never-ask values");
15
14
  const result: Record<string, PermissionMode> = {};
16
15
  for (const [peer, mode] of Object.entries(value)) {
17
- if (!isSupportedPeer(peer)) throw new Error(`permission_modes.${peer}: unsupported peer`);
18
- if (peer === "jcode") throw new Error("Jcode native policy is unmanaged; no hub permission_modes.jcode mapping exists");
16
+ const definition = typeof peer === "string" ? definitionOf(peer) : undefined;
17
+ if (!definition) throw new Error(`permission_modes.${peer}: unsupported peer`);
18
+ if (definition.permission.unmanaged) throw new Error(`${definition.displayName} native policy is unmanaged; no hub permission_modes.${peer} mapping exists`);
19
19
  if (!isPermissionMode(mode)) throw new Error(`permission_modes.${peer} must be ask, ask-when-needed or never-ask`);
20
20
  result[peer] = mode;
21
21
  }
@@ -23,25 +23,22 @@ export function permissionDefaults(value: unknown): Record<string, PermissionMod
23
23
  }
24
24
  /** Approval frequency does not create a common sandbox across native peers. */
25
25
  export function permissionBoundary(peer: string): string {
26
- if (peer === "jcode") return "jcode: native policy unmanaged; NO hub sandbox; approvals belong to its native tools";
27
- if (peer === "pi" || peer === "local") return `${peer}: inside hub sandbox, path guard and denylist`;
28
- if (peer === "claude" || peer === "codex") return `${peer}: native vendor bounds; no hub sandbox`;
26
+ const definition = definitionOf(peer);
27
+ if (definition?.permission.unmanaged) return `${peer}: native policy unmanaged; NO hub sandbox; approvals belong to its native tools`;
28
+ if (definition?.trust.hubSandboxed) return `${peer}: inside hub sandbox, path guard and denylist`;
29
+ if (definition?.transport === "claude-channel" || definition?.transport === "codex-appserver") return `${peer}: native vendor bounds; no hub sandbox`;
29
30
  return `${peer}: runs its own tools; NO hub sandbox`;
30
31
  }
31
32
  /** What a mode lets a peer do without asking, in one line a person reads before choosing it (#269). */
32
33
  export function permissionGrant(peer: string, mode: PermissionMode): string {
33
34
  const grant = definitionOf(peer)?.permission.grants?.[mode];
34
35
  if (grant !== undefined) return grant;
35
- if (peer === "jcode") return "no verified hub mode mapping; native policy only";
36
- if (mode === "ask") return peer === "codex" ? "the session's own approval policy applies again" : peer === "kimi" ? "Kimi asks as it does on its own" : peer === "claude" ? "Claude's own permission rules decide" : "every write, edit and shell command asks";
37
- if (peer === "kimi") return mode === "never-ask" ? "Kimi's auto mode: nothing asks" : "Kimi's yolo mode: it asks only where it judges it must";
38
- if (peer === "codex") return mode === "never-ask" ? "approval policy never on every turn: nothing asks" : "approval policy on-request on every turn";
39
- if (peer === "claude") return mode === "never-ask" ? "every tool runs without asking" : "file tools on project files run without asking, outside .agenthub, .git and agent configuration; other tools keep Claude's own rules";
36
+ if (mode === "ask") return "every write, edit and shell command asks";
40
37
  return mode === "never-ask" ? "every tool runs without asking, inside the hub sandbox and path guard" : "write and edit inside the project run without asking; shell and git writes still ask";
41
38
  }
42
39
  export const PI_EDIT_TOOLS = new Set(["edit", "write"]);
43
40
  /** Native agent policy files are never included in scoped automatic file grants. */
44
- export const AGENT_CONFIG_SEGMENTS: ReadonlySet<string> = new Set([".claude", ".codex", ".qwen", ".kimi", ".kimi-code", ".jcode", ".pi", ".mcp.json", ".agents", ".claude.json"]);
41
+ export const AGENT_CONFIG_SEGMENTS: ReadonlySet<string> = new Set([".claude", ".codex", ".qwen", ".kimi", ".kimi-code", ".jcode", ".pi", ".mcp.json", ".agents", ".agent", "_agents", "_agent", ".gemini", ".grok", ".claude.json"]);
45
42
  export const INSTRUCTION_FILES: ReadonlySet<string> = new Set(["agents.md", "claude.md", "qwen.md"]);
46
43
  export const isInstructionPath = (path: string): boolean => path.split(/[\\/]/).some(segment => INSTRUCTION_FILES.has(foldSegment(segment)));
47
44
  export function instructionProtection(value: unknown): boolean {
@@ -1,3 +1,4 @@
1
+ import { ADAPTERS } from "../adapters/registry.ts";
1
2
  import { Database } from "bun:sqlite";
2
3
  import { createHash, randomUUID } from "node:crypto";
3
4
  import { chmodSync, closeSync, constants, fstatSync, lstatSync, openSync, readSync, renameSync, unlinkSync } from "node:fs";
@@ -37,12 +38,12 @@ function canonicalRoot(value: unknown): string {
37
38
  return root;
38
39
  }
39
40
  function checked(value: unknown): RecoveryContinuityBookmark {
40
- if (!record(value) || !keys(value, ["schema", "operationId", "projectId", "projectRoot", "at", "pi"]) || value.schema !== 1 || typeof value.operationId !== "string" || !operationIdPattern.test(value.operationId) || !id(value.projectId) || !absolute(value.projectRoot) || !Number.isSafeInteger(value.at) || (value.at as number) < 0) return unavailable();
41
- const pi = value.pi;
42
- if (!record(pi) || !keys(pi, ["sessionId", "sessionFile", "backend", "model"]) || !id(pi.sessionId) || pi.sessionFile !== undefined && !absolute(pi.sessionFile) || pi.backend !== undefined && !["auto", "dgx", "mlx"].includes(String(pi.backend)) || pi.model !== undefined && !text(pi.model, 4096)) return unavailable();
41
+ const codecs = ADAPTERS.flatMap(adapter => adapter.session.continuity ? [adapter.session.continuity] : []);
42
+ if (!record(value) || !keys(value, ["schema", "operationId", "projectId", "projectRoot", "at", ...codecs.map(codec => codec.key)]) || value.schema !== 1 || typeof value.operationId !== "string" || !operationIdPattern.test(value.operationId) || !id(value.projectId) || !absolute(value.projectRoot) || !Number.isSafeInteger(value.at) || (value.at as number) < 0) return unavailable();
43
+ const native: Record<string, unknown> = {};
44
+ for (const codec of codecs) { const parsed = codec.parse(value[codec.key]); if (parsed === undefined) return unavailable(); native[codec.key] = parsed; }
43
45
  const projectRoot = canonicalRoot(value.projectRoot);
44
- return { schema: 1, operationId: value.operationId, projectId: value.projectId, projectRoot, at: value.at as number,
45
- pi: { sessionId: pi.sessionId, ...(pi.sessionFile === undefined ? {} : { sessionFile: pi.sessionFile as string }), ...(pi.backend === undefined ? {} : { backend: pi.backend as "auto" | "dgx" | "mlx" }), ...(pi.model === undefined ? {} : { model: pi.model as string }) } };
46
+ return { schema: 1, operationId: value.operationId, projectId: value.projectId, projectRoot, at: value.at as number, ...native } as RecoveryContinuityBookmark;
46
47
  }
47
48
  function stateDirectory(stateDir: string): void {
48
49
  if (!absolute(stateDir)) return unavailable();
package/src/hub/report.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { definitionOf } from "../adapters/registry.ts";
1
2
  import type { StampedEvent } from "./events.ts";
2
3
 
3
4
  export interface Report {
@@ -103,7 +104,7 @@ export function summarize(events: StampedEvent[]): Report {
103
104
  const r: Report = { peers: {}, conduct: {}, supervision: {}, routes: {}, usage: { peers: {}, totals: { inputTokens: 0, inputRecords: 0, outputTokens: 0, outputRecords: 0, cacheReadTokens: 0, cacheReadRecords: 0, cacheWriteTokens: 0, cacheWriteRecords: 0, totalTokens: 0, totalRecords: 0 }, unknownPeers: [], completeCoverage: true }, messages: { total: 0, dropped: {}, overflow: 0, undeliverable: 0, perTask: 0 }, overlaps: { warnings: 0, pairs: 0 }, conflicts: 0, tasks: {}, quota: { readings: 0, hard: 0 } };
104
105
  const supervisor = (id: string) => (r.supervision[id] ??= { turns: null, tokens: null, measuredTokens: null, knownTokenTurns: 0, unknownTokenTurns: 0 });
105
106
  const peer = (id: string) => (r.peers[id] ??= { turns: 0, busyMinutes: 0, tokens: 0 });
106
- const claudeNativeStops = events.some(event => event.type === "native_turn_end" && event.peer === "claude" && !!event.id);
107
+ const nativeStops = events.some(event => event.type === "native_turn_end" && definitionOf(event.peer)?.turnEnd === "native-hook" && !!event.id);
107
108
  const seenNativeStops = new Set<string>();
108
109
  const usagePeer = (id: string) => (r.usage.peers[id] ??= emptyUsage());
109
110
  const pairs = new Set<string>();
@@ -147,11 +148,11 @@ export function summarize(events: StampedEvent[]): Report {
147
148
  r.messages.dropped.stale = (r.messages.dropped.stale ?? 0) + 1;
148
149
  break;
149
150
  case "turn_end":
150
- if (e.peer !== "claude" || !claudeNativeStops) peer(e.peer).turns = (peer(e.peer).turns ?? 0) + 1;
151
+ if (definitionOf(e.peer)?.turnEnd !== "native-hook" || !nativeStops) peer(e.peer).turns = (peer(e.peer).turns ?? 0) + 1;
151
152
  peer(e.peer).busyMinutes += e.ms / 60_000;
152
153
  break;
153
154
  case "native_turn_end":
154
- if (e.peer === "claude" && e.id) {
155
+ if (definitionOf(e.peer)?.turnEnd === "native-hook" && e.id) {
155
156
  if (seenNativeStops.has(e.id)) break;
156
157
  seenNativeStops.add(e.id);
157
158
  peer(e.peer).turns = (peer(e.peer).turns ?? 0) + 1;
@@ -211,10 +212,10 @@ export function summarize(events: StampedEvent[]): Report {
211
212
  // Pricing is intentionally absent: a token count is neither an estimated price nor provider-reported spend.
212
213
  r.messages.perTask = taskMessages.size ? Number(([...taskMessages.values()].reduce((a, b) => a + b, 0) / taskMessages.size).toFixed(1)) : 0;
213
214
  for (const p of Object.values(r.peers)) p.busyMinutes = Number(p.busyMinutes.toFixed(1));
214
- if (r.peers.claude) {
215
- const logical = events.some(event => event.type === "turn_end" && event.peer === "claude");
216
- r.peers.claude.turnSource = claudeNativeStops ? "native-stop" : logical ? "logical-state" : "unknown";
217
- if (!claudeNativeStops && !logical) r.peers.claude.turns = null;
215
+ for (const [id, summary] of Object.entries(r.peers)) if (definitionOf(id)?.turnEnd === "native-hook") {
216
+ const logical = events.some(event => event.type === "turn_end" && event.peer === id);
217
+ summary.turnSource = nativeStops ? "native-stop" : logical ? "logical-state" : "unknown";
218
+ if (!nativeStops && !logical) summary.turns = null;
218
219
  }
219
220
  return r;
220
221
  }
@@ -223,7 +224,7 @@ export function formatReport(r: Report): string[] {
223
224
  const lines = [`period: ${r.from ?? "-"} .. ${r.to ?? "-"}`];
224
225
  for (const [id, p] of Object.entries(r.peers).sort(([a], [b]) => a.localeCompare(b))) {
225
226
  const turns = p.turns === null ? "turns unknown" : `${p.turns} turn${p.turns === 1 ? "" : "s"}${p.turnSource === "native-stop" ? " (native Stop)" : p.turnSource === "logical-state" ? " (logical state, native completion unobserved)" : ""}`;
226
- lines.push(`peer ${id}: ${turns}, ${p.busyMinutes} busy minutes, ${p.tokens ? `${p.tokens} tokens` : id === "pi" ? "tokens not reported" : "- tokens"}`);
227
+ lines.push(`peer ${id}: ${turns}, ${p.busyMinutes} busy minutes, ${p.tokens ? `${p.tokens} tokens` : definitionOf(id)?.reporting?.tokensNotReported ? "tokens not reported" : "- tokens"}`);
227
228
  }
228
229
  if (Object.keys(r.usage.peers).length) lines.push(...formatUsage(r.usage));
229
230
  for (const [id, s] of Object.entries(r.supervision).sort(([a], [b]) => a.localeCompare(b))) {
@@ -2,10 +2,11 @@ import { chmodSync, mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSy
2
2
  import { createHash } from "node:crypto";
3
3
  import { join } from "node:path";
4
4
  import type { BusSnapshot } from "./bus.ts";
5
- import type { PeerId, PeerState } from "./envelope.ts";
5
+ import type { Envelope, PeerId, PeerState } from "./envelope.ts";
6
6
  import { MAX_HOP } from "./envelope.ts";
7
7
  import { validateJournalSnapshot } from "./delivery-journal.ts";
8
8
  import { atomicPrivateJSON } from "./recovery-store.ts";
9
+ import { RecoveryDeferredHubError, validateDeferredHub } from "./deferred-hub.ts";
9
10
 
10
11
  export const RESTART_SCHEMA_VERSION = 1;
11
12
 
@@ -75,6 +76,16 @@ export function readRestartSnapshot(stateDir: string, expected: RestartReadExpec
75
76
  const bus = s.bus as Partial<BusSnapshot>;
76
77
  if (bus.schemaVersion !== 1 || !bus.queues || typeof bus.queues !== "object" || !bus.prefaces || typeof bus.prefaces !== "object" || !Array.isArray(bus.seen) || !bus.attempts || typeof bus.attempts !== "object" || !Array.isArray(bus.withdrawn)) return undefined;
77
78
  if (!Object.keys(bus.queues).every(peerId) || !Object.keys(bus.prefaces).every(peerId) || !Object.values(bus.queues).every((queue) => Array.isArray(queue) && queue.every((e) => isEnvelope(e))) || !Object.values(bus.prefaces).every((e) => isEnvelope(e)) || !bus.seen.every((e) => isEnvelope(e, true)) || !bus.withdrawn.every((id) => typeof id === "string" && id.length > 0) || !Object.values(bus.attempts).every((n) => Number.isSafeInteger(n) && n > 0)) return undefined;
79
+ try {
80
+ const occupied = new Set<string>([
81
+ ...bus.seen.map(env => env.id),
82
+ ...Object.values(bus.queues).flatMap(queue => queue.map(env => env.id)),
83
+ ]);
84
+ validateDeferredHub(bus.deferredHub, (value, name) => {
85
+ if (!isEnvelope(value)) throw new Error(`${name} is invalid`);
86
+ return value as Envelope;
87
+ }, occupied);
88
+ } catch (error) { if (error instanceof RecoveryDeferredHubError) throw error; return undefined; }
78
89
  if (!Array.isArray(s.manualPaused) || !s.manualPaused.every((id) => typeof id === "string") || !Array.isArray(s.peers) || !s.peers.every((peer) => peer && typeof peer === "object" && typeof peer.id === "string" && ["idle", "busy", "paused", "offline"].includes(peer.state as string) && Array.isArray(peer.queueIds) && peer.queueIds.every((id) => typeof id === "string"))) return undefined;
79
90
  if (s.integrity !== undefined && (!s.integrity || typeof s.integrity !== "object" || typeof s.integrity.boardDigest !== "string" || typeof s.integrity.budgetDigest !== "string" || !Array.isArray(s.integrity.manualPaused) || !s.integrity.manualPaused.every((id) => typeof id === "string") || !s.integrity.queues || typeof s.integrity.queues !== "object" || !Object.values(s.integrity.queues).every((ids) => Array.isArray(ids) && ids.every((id) => typeof id === "string")))) return undefined;
80
91
  if (bus.journal !== undefined) { try { validateJournalSnapshot(bus.journal); } catch { return undefined; } }
package/src/hub/roster.ts CHANGED
@@ -1,15 +1,14 @@
1
- import { isSupportedPeer, type KnownPeer } from "./peer-catalog.ts";
1
+ import { definitionOf } from "../adapters/registry.ts";
2
+ import { defaultRosterEnabled } from "../adapters/registry.ts";
2
3
 
3
- export type PeerRoster = Partial<Record<KnownPeer, boolean>>;
4
- // Default participation policy, not another catalog. New catalog members default off.
5
- const DEFAULT_ON: Partial<Record<KnownPeer, boolean>> = { claude: true, codex: true, kimi: true, local: true };
4
+ export type PeerRoster = Partial<Record<string, boolean>>;
6
5
 
7
6
  export function peerRosterConfig(value: unknown): PeerRoster {
8
7
  if (value === undefined) return {};
9
8
  if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("roster must be an object of boolean peer values");
10
9
  const roster: PeerRoster = {};
11
10
  for (const [peer, on] of Object.entries(value)) {
12
- if (!isSupportedPeer(peer)) throw new Error("roster contains an unsupported peer");
11
+ if (!definitionOf(peer)) throw new Error("roster contains an unsupported peer");
13
12
  if (typeof on !== "boolean") throw new Error(`roster.${peer} must be a boolean`);
14
13
  roster[peer] = on;
15
14
  }
@@ -18,6 +17,6 @@ export function peerRosterConfig(value: unknown): PeerRoster {
18
17
 
19
18
  /** External ids keep their existing admission rules; Pi's legacy switch is only its default. */
20
19
  export function rosterAllows(roster: PeerRoster, peer: string, piEnabled: boolean): boolean {
21
- if (!isSupportedPeer(peer)) return true;
22
- return roster[peer] ?? (peer === "pi" ? piEnabled : DEFAULT_ON[peer] ?? false);
20
+ if (!definitionOf(peer)) return true;
21
+ return roster[peer] ?? defaultRosterEnabled(peer, piEnabled);
23
22
  }
@@ -1,3 +1,4 @@
1
+ import { ADAPTERS, definitionOf } from "../adapters/registry.ts";
1
2
  import { readFileSync, statSync } from "node:fs";
2
3
  import { join, resolve } from "node:path";
3
4
  import { CLASSES, type Task, type TaskClass } from "./board.ts";
@@ -17,7 +18,7 @@ export interface ClassPolicy {
17
18
  /** Switchyard route the local worker asks for on a task of this class */
18
19
  route?: string;
19
20
  fixed_model?: string;
20
- /** on two consecutive changes_requested */
21
+ /** on `tasks.escalate_after` consecutive changes_requested (default 3) */
21
22
  escalate_to?: PeerId[];
22
23
  /** false: `local` is never owner or reviewer for this class */
23
24
  local_allowed?: boolean;
@@ -108,6 +109,16 @@ const TEMPLATE = join(import.meta.dir, "..", "..", "templates", "routing.toml");
108
109
  export const LOCAL: PeerId = "local";
109
110
  export const PI: PeerId = "pi";
110
111
 
112
+ /** The quota/roster relay keeps its native preference order, then the class's original tail. */
113
+ export function relayCandidates(classPeers: readonly PeerId[], pii: boolean): PeerId[] {
114
+ const preferred = ADAPTERS.filter(adapter => adapter.routing?.handoffPriority !== undefined)
115
+ .sort((a, b) => a.routing!.handoffPriority! - b.routing!.handoffPriority!);
116
+ return [
117
+ ...preferred.filter(adapter => !pii || adapter.trust.onPrem).map(adapter => adapter.kind),
118
+ ...classPeers.filter(peer => definitionOf(peer)?.routing?.handoffPriority === undefined),
119
+ ].filter((peer): peer is PeerId => !!peer);
120
+ }
121
+
111
122
  /**
112
123
  * `.agenthub/routing.toml`, or the shipped default when the project has none, with `.agenthub/routing.local.toml`
113
124
  * merged over it key by key (#269). Throws on a file that does not parse or lacks a fixed model.
@@ -323,15 +334,15 @@ export function assign(
323
334
  if (states[peer] === "paused" && routing.constraints.budget_paused === "skip_peer") return deny("paused", "paused");
324
335
  const failing = peerEntry(opts.failing, peer);
325
336
  if (failing) return deny("failing", `failing: ${failing}`);
326
- if (pii && peer !== LOCAL) return deny("pii", "pii: on-prem peers only");
327
- if (peer === LOCAL && policy?.local_allowed === false) return deny("policy", "local_allowed = false for this class");
328
- if (peer === PI && policy?.local_allowed === false) return deny("policy", "local_allowed = false also excludes pi for this class");
329
- if (peer === PI && task.signals.includes("long_context")) {
337
+ if (pii && definitionOf(peer)?.trust.onPrem !== true) return deny("pii", "pii: on-prem peers only");
338
+ const nativeRouting = definitionOf(peer)?.routing;
339
+ if (nativeRouting?.localAllowedRefusal && policy?.local_allowed === false) return deny("policy", nativeRouting.localAllowedRefusal);
340
+ if (nativeRouting?.longContext === "backend-limit" && task.signals.includes("long_context")) {
330
341
  const backend = policy?.pi_backend ?? "dgx";
331
342
  const limit = backend === "mlx" ? routing.pi.mlx_max_context_tokens : routing.pi.dgx_max_context_tokens;
332
- if (routing.signals.long_context_tokens > limit) return deny("policy", `pi ${backend} capability limit ${limit} tokens`);
343
+ if (routing.signals.long_context_tokens > limit) return deny("policy", `${nativeRouting.backendLabel} ${backend} capability limit ${limit} tokens`);
333
344
  }
334
- if (peer === LOCAL && role === "owner" && task.signals.includes("long_context") && routing.constraints.long_context === "skip_local") return deny("policy", "long_context: skip local");
345
+ if (nativeRouting?.longContext === "skip-owner" && role === "owner" && task.signals.includes("long_context") && routing.constraints.long_context === "skip_local") return deny("policy", "long_context: skip local");
335
346
  return undefined;
336
347
  };
337
348
  /** Quota that resets soonest gets used first: headroom per hour left in the window, at least 15 min (a task assigned that close to a reset mostly runs after it). */
@@ -381,7 +392,7 @@ export function assign(
381
392
  }
382
393
  const ranked = rank(ok, role, not);
383
394
  // Demotion applies to local and Pi too: a demoted one loses its place ahead of the cloud peers.
384
- const localTier = ranked.filter((p) => (p === LOCAL || p === PI) && !(role === "owner" && peerEntry(opts.demoted, p)));
395
+ const localTier = ranked.filter((p) => definitionOf(p)?.routing?.preferredTier === true && !(role === "owner" && peerEntry(opts.demoted, p)));
385
396
  if (localTier.length) return localTier.find((p) => states[p] === "idle") ?? localTier[0]; // local/Pi stays ahead of an idle cloud peer
386
397
  return ranked.find((p) => states[p] === "idle") ?? ranked[0];
387
398
  };
@@ -413,8 +424,8 @@ export function assign(
413
424
  const route = policy?.route ?? routing.local.route;
414
425
  const fixedModel = policy?.fixed_model ?? routing.local.fixed_model;
415
426
  const piBackend = policy?.pi_backend;
416
- if (owner === LOCAL) trace.push(`route: ${route ?? "(none)"}, fixed_model ${fixedModel}`);
417
- if (owner === PI) trace.push(`pi decision: backend ${piBackend ?? "dgx"}${task.signals.includes("long_context") ? `, context limit ${piBackend === "mlx" ? routing.pi.mlx_max_context_tokens : routing.pi.dgx_max_context_tokens}` : ""}`);
427
+ if (owner && definitionOf(owner)?.routing?.trace === "route") trace.push(`route: ${route ?? "(none)"}, fixed_model ${fixedModel}`);
428
+ if (owner && definitionOf(owner)?.routing?.trace === "backend") trace.push(`${definitionOf(owner)!.routing!.backendLabel} decision: backend ${piBackend ?? "dgx"}${task.signals.includes("long_context") ? `, context limit ${piBackend === "mlx" ? routing.pi.mlx_max_context_tokens : routing.pi.dgx_max_context_tokens}` : ""}`);
418
429
  return { ...(owner ? { owner } : {}), ...(pii ? { reviewer: "user" } : reviewer ? { reviewer } : {}), ...(route ? { route } : {}), fixedModel, ...(piBackend ? { piBackend } : {}), ...(unreserved ? { unreserved } : {}), ...(refusals.size ? { refusals: [...refusals.values()] } : {}), trace };
419
430
  }
420
431
 
@@ -1,4 +1,4 @@
1
- import { PLANNER_PEERS, SUPPORTED_PEERS } from "./peer-catalog.ts";
1
+ import { definitionOf, ADAPTERS, PLANNER_PEERS, SUPPORTED_PEERS, START_MODE_PEERS } from "../adapters/registry.ts";
2
2
  import { createHash } from "node:crypto";
3
3
  import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
4
4
  import { tmpdir } from "node:os";
@@ -6,7 +6,7 @@ import { basename, dirname, join } from "node:path";
6
6
  import { CLASSES, type TaskClass } from "./board.ts";
7
7
  import { configTracked, configRepositoryPresent } from "./config-trust.ts";
8
8
  import { PERMISSION_MODES, permissionBoundary } from "./permission-mode.ts";
9
- import { START_MODE_PEERS, START_MODES } from "./start-mode.ts";
9
+ import { START_MODES } from "./start-mode.ts";
10
10
  import { OVERLAY_FILE, overlayToml, parseOverlay, parseRouting, routingText, type Routing, type RoutingOverlay } from "./routing.ts";
11
11
 
12
12
  /**
@@ -49,14 +49,15 @@ export const SETTINGS: readonly SettingDef[] = [
49
49
  ...["enabled", "auto_reassign"].map((key): SettingDef => ({ key: `task_sweep.${key}`, group: "Switches", label: `Task sweep: ${key}`, type: "boolean", store: "config", applies: "live", risk: "raises", floor: false, path: ["task_sweep", key] })),
50
50
  ...["interval_s", "unaccepted_min", "idle_min", "review_min", "ready_min", "ladder_min"].map((key): SettingDef => ({ key: `task_sweep.${key}`, group: "Switches", label: `Task sweep: ${key}`, type: "number", min: 1, max: 2_147_483_647 / (key === "interval_s" ? 1000 : 60_000), store: "config", applies: "live", risk: "raises", path: ["task_sweep", key] })),
51
51
  ...SETTING_PEERS.map((peer): SettingDef => ({ key: `tasks.wip_limits.${peer}`, group: "Routing", label: `${peer}: planner WIP limit`, type: "integer", min: 0, max: 32, store: "config", applies: "live", risk: "raises", floor: 0, path: ["tasks", "wip_limits", peer] })),
52
+ { key: "tasks.escalate_after", group: "Routing", label: "Escalate after N consecutive changes_requested", type: "integer", min: 1, max: 10, store: "config", applies: "live", risk: "raises", path: ["tasks", "escalate_after"] },
52
53
  { key: "planner", group: "Roles", label: "Planner (the one peer that plans)", type: "enum", values: PLANNER_PEERS, store: "config", applies: "live", risk: "raises", path: ["planner"] },
53
54
  ...SETTING_PEERS.map((peer): SettingDef => ({ key: `catalog_roles.${peer}`, group: "Roles", label: `${peer}: catalog guidance`, type: "roles", store: "config", applies: "next use", risk: "safe", path: ["catalog_roles", peer] })),
54
55
  { key: "scoped_grants.protect_instructions", group: "Permissions", label: "Ask before writing instruction files", type: "boolean", store: "config", applies: "live", risk: "raises", floor: true, path: ["protect_instruction_files"] },
55
56
  ...SETTING_PEERS.map((peer): SettingDef => ({ key: `roster.${peer}`, group: "Roster", label: `${peer}: participates`, type: "boolean", store: "config", applies: "live", risk: "raises", floor: false, path: ["roster", peer] })),
56
- ...SETTING_PEERS.filter(peer => peer !== "jcode").map((peer): SettingDef => ({ key: `permission.${peer}`, group: "Permissions", label: `${peer}: mode now`, type: "enum", values: PERMISSION_MODES, store: "runtime", applies: "live", risk: "raises", floor: "ask", path: [peer] })),
57
- ...SETTING_PEERS.filter(peer => peer !== "jcode").map((peer): SettingDef => ({ key: `permission_modes.${peer}`, group: "Permissions", label: `${peer}: mode at next peer start`, type: "enum", values: PERMISSION_MODES, store: "config", applies: "next use", risk: "raises", floor: "ask", path: ["permission_modes", peer] })),
57
+ ...SETTING_PEERS.filter(peer => !definitionOf(peer)?.permission.unmanaged).map((peer): SettingDef => ({ key: `permission.${peer}`, group: "Permissions", label: `${peer}: mode now`, type: "enum", values: PERMISSION_MODES, store: "runtime", applies: "live", risk: "raises", floor: "ask", path: [peer] })),
58
+ ...SETTING_PEERS.filter(peer => !definitionOf(peer)?.permission.unmanaged).map((peer): SettingDef => ({ key: `permission_modes.${peer}`, group: "Permissions", label: `${peer}: mode at next peer start`, type: "enum", values: PERMISSION_MODES, store: "config", applies: "next use", risk: "raises", floor: "ask", path: ["permission_modes", peer] })),
58
59
  ...START_MODE_PEERS.map((peer): SettingDef => ({ key: `peers.${peer}.start_mode`, group: "Start", label: `${peer}: start mode (tui unless set)`, type: "enum", values: START_MODES, store: "config", applies: "next use", risk: "raises", floor: "tui", path: ["peers", peer, "start_mode"] })),
59
- { key: "pi.auto_start", group: "Start", label: "Start Pi with the hub", type: "boolean", store: "config", applies: "next use", risk: "raises", floor: false, path: ["pi", "auto_start"] },
60
+ ...ADAPTERS.flatMap(adapter => adapter.configuration?.settings ?? []),
60
61
  { key: "routing.stay_switch", group: "Routing", label: "Stay or switch (hub/auto and stage routes)", type: "enum", values: ["off", "shadow", "enforce"], store: "routing", applies: "live", risk: "raises", path: ["stay_switch"] },
61
62
  ...CLASSES.flatMap(perClass),
62
63
  { key: "research.enabled", group: "Switches", label: "Research records", type: "boolean", store: "config", applies: "live", risk: "safe", path: ["research", "enabled"] },
@@ -1,5 +1,5 @@
1
1
  import { conductorPeer } from "./conductor.ts";
2
- import { PLANNER_PEERS } from "./peer-catalog.ts";
2
+ import { PLANNER_PEERS } from "../adapters/registry.ts";
3
3
 
4
4
  export interface SettledRoles {
5
5
  roles: Record<string, string[]>;
@@ -1,4 +1,4 @@
1
- import { SUPPORTED_PEERS, isSupportedPeer } from "./peer-catalog.ts";
1
+ import { definitionOf, SUPPORTED_PEERS, START_MODE_PEERS as REGISTRY_START_MODE_PEERS } from "../adapters/registry.ts";
2
2
 
3
3
  /**
4
4
  * #269: how a peer comes up when the hub starts it: its own TUI in a terminal, or headless. A person who types
@@ -8,12 +8,15 @@ import { SUPPORTED_PEERS, isSupportedPeer } from "./peer-catalog.ts";
8
8
  export const PEER_START_RETRY_MS = 30_000;
9
9
  export const START_MODES = ["tui", "headless"] as const;
10
10
  export type StartMode = typeof START_MODES[number];
11
+ // ponytail: released coordinators source-probe this exact literal before restoring headless Kimi.
12
+ // Keep it until those readers negotiate the registry capability.
11
13
  /** The peers with both forms. Kimi's TUI is pull-only; Claude has only a TUI and local only headless. */
12
14
  export const START_MODE_PEERS = ["pi", "codex", "kimi"] as const;
13
15
  /** Every peer the hub can start itself. */
14
16
  export const STARTABLE_PEERS = SUPPORTED_PEERS;
15
17
  export type StartablePeer = typeof STARTABLE_PEERS[number];
16
- export const isStartablePeer = (value: unknown): value is StartablePeer => isSupportedPeer(value);
18
+ export const isStartablePeer = (value: unknown): value is StartablePeer => typeof value === "string" && !!definitionOf(value)?.start.conductorStartable;
19
+
17
20
 
18
21
  export type PeerStartConfig = Record<string, { start_mode?: StartMode }>;
19
22
  /** The checked per-peer start modes; only peers with both forms may be configured. */
@@ -22,7 +25,7 @@ export function peerStartConfig(value: unknown): PeerStartConfig {
22
25
  if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("peers must be an object of per-peer settings");
23
26
  const result: PeerStartConfig = {};
24
27
  for (const [peer, block] of Object.entries(value)) {
25
- if (!(START_MODE_PEERS as readonly string[]).includes(peer)) throw new Error(`peers.${peer}: only ${START_MODE_PEERS.join(" and ")} have a start mode`);
28
+ if (!(REGISTRY_START_MODE_PEERS as readonly string[]).includes(peer)) throw new Error(`peers.${peer}: only ${REGISTRY_START_MODE_PEERS.join(" and ")} have a start mode`);
26
29
  if (!block || typeof block !== "object" || Array.isArray(block)) throw new Error(`peers.${peer} must be an object`);
27
30
  const mode = (block as { start_mode?: unknown }).start_mode;
28
31
  if (mode !== undefined && !(START_MODES as readonly unknown[]).includes(mode)) throw new Error(`peers.${peer}.start_mode must be tui or headless`);
@@ -33,9 +36,8 @@ export function peerStartConfig(value: unknown): PeerStartConfig {
33
36
 
34
37
  /** The mode a start of `peer` takes when nothing more specific was asked: `tui` wherever the peer has one. */
35
38
  export function startModeOf(peers: PeerStartConfig | undefined, peer: string): StartMode {
36
- if (peer === "claude") return "tui";
37
- if ((START_MODE_PEERS as readonly string[]).includes(peer)) return peers?.[peer]?.start_mode ?? "tui";
38
- return "headless";
39
+ if ((REGISTRY_START_MODE_PEERS as readonly string[]).includes(peer)) return peers?.[peer]?.start_mode ?? definitionOf(peer)?.start.defaultForm ?? "tui";
40
+ return definitionOf(peer)?.start.defaultForm ?? "headless";
39
41
  }
40
42
 
41
43
  /**