@staix/agent-hub 0.51.0 → 0.52.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 (299) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/README.md +1 -1
  3. package/docs/adding-an-ai-tool.md +24 -2
  4. package/docs/agent-notes/adapters.md +1 -0
  5. package/docs/agent-notes/budget.md +8 -2
  6. package/docs/agent-notes/daemon.md +13 -8
  7. package/docs/agent-notes/security-review.md +6 -5
  8. package/docs/agent-notes/tasks.md +5 -2
  9. package/docs/agent-notes/tests.md +4 -3
  10. package/docs/cooperbench.md +1 -1
  11. package/docs/design/adapters.md +4 -0
  12. package/docs/design/cli-output-inventory.md +162 -152
  13. package/docs/design/cli-output.md +4 -3
  14. package/docs/design/guidance-probes.md +1 -0
  15. package/docs/design/roadmap.md +2 -0
  16. package/docs/design/task-board.md +1 -0
  17. package/docs/dogfood.md +14 -0
  18. package/docs/events.md +4 -2
  19. package/docs/memory.md +5 -3
  20. package/docs/operations.md +210 -16
  21. package/docs/quickstart.md +12 -2
  22. package/docs/roles.md +1 -1
  23. package/docs/sdlc.md +26 -3
  24. package/docs/security.md +11 -5
  25. package/docs/specs/2026-09-19-agent-hub-design.md +43 -0
  26. package/docs/specs/2026-09-19-multi-project-design.md +4 -0
  27. package/docs/specs/2026-09-20-upgrade-recovery-design.md +17 -0
  28. package/docs/specs/mcp-endpoint.md +63 -0
  29. package/docs/verification/2026-11-30-capability-listing-shape-1808.md +45 -0
  30. package/docs/verification/2026-11-30-upgrade-keep-1807.md +174 -0
  31. package/docs/verification/2026-12-01-1811-confirmation-receipt.md +19 -0
  32. package/docs/verification/2026-12-01-1811-orca-agent-list.md +20 -0
  33. package/docs/verification/2026-12-01-1811-orca-pane-key.md +21 -0
  34. package/docs/verification/2026-12-02-1819-claude-process-after-renewal.md +54 -0
  35. package/docs/verification/2026-12-02-agy-1.5.21.md +74 -0
  36. package/docs/verification/2026-12-02-claude-implementer-2.1.334.md +44 -0
  37. package/docs/verification/2026-12-02-cli-import-graph.md +33 -0
  38. package/docs/verification/2026-12-03-0.52.0.md +150 -0
  39. package/docs/verification/2026-12-03-codex-0173-reviewer-isolation.md +53 -0
  40. package/docs/verification/2026-12-03-codex-0173-reviewer-tool-call.md +34 -0
  41. package/docs/verification/2026-12-03-jcode-1.3.0.md +25 -0
  42. package/docs/verification/agy/README.md +17 -0
  43. package/docs/verification/agy/cli-surface.ts +68 -0
  44. package/docs/verification/agy/interactive-bridge.ts +92 -0
  45. package/docs/verification/agy/interactive-session.ts +131 -0
  46. package/docs/verification/agy/launcher-nonce.ts +215 -0
  47. package/docs/verification/agy/native-hooks.ts +210 -0
  48. package/docs/verification/agy/originals/agent-hub-681/cli-surface.ts +87 -0
  49. package/docs/verification/agy/originals/agent-hub-681/native-hooks-adapted.ts +91 -0
  50. package/docs/verification/agy/originals/agent-hub-681/tui-actual.ts +200 -0
  51. package/docs/verification/agy/originals/agent-hub-684/probe.ts +107 -0
  52. package/docs/verification/agy/originals.json +25 -0
  53. package/docs/verification/agy/permission-new-functions.ts +128 -0
  54. package/docs/verification/agy/run-probe.py +108 -0
  55. package/docs/verification/agy/runtime.ts +171 -0
  56. package/docs/verification/agy/tmux-helper-control.ts +6 -0
  57. package/docs/verification/agy/tmux-session.ts +235 -0
  58. package/docs/verified.json +82 -41
  59. package/package.json +3 -3
  60. package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
  61. package/plugins/agent-hub/compat.json +157 -0
  62. package/plugins/agent-hub/kimi-hook.js +621 -865
  63. package/plugins/agent-hub/server.js +17423 -32962
  64. package/src/adapters/agy/definition.ts +7 -24
  65. package/src/adapters/channel-peer.ts +3 -1
  66. package/src/adapters/claude-channel.ts +38 -257
  67. package/src/adapters/claude-implementer.ts +3 -1
  68. package/src/adapters/codex-appserver.ts +77 -15
  69. package/src/adapters/compat.ts +74 -11
  70. package/src/adapters/configured-acp.ts +23 -163
  71. package/src/adapters/configured-adapter-policy.ts +160 -0
  72. package/src/adapters/configured-pull-entry.ts +53 -0
  73. package/src/adapters/configured-pull.ts +38 -0
  74. package/src/adapters/conformance/fakes/app-server.ts +9 -2
  75. package/src/adapters/declaration-catalog.ts +25 -0
  76. package/src/adapters/declaration-data.ts +342 -0
  77. package/src/adapters/declaration-resolution.ts +53 -0
  78. package/src/adapters/definitions/builtin-metadata.ts +61 -83
  79. package/src/adapters/definitions/jcode-launch.ts +13 -0
  80. package/src/adapters/definitions/native-adapter-policy.ts +390 -0
  81. package/src/adapters/definitions/native-cli-claude-launch.ts +3 -2
  82. package/src/adapters/definitions/native-cli-codex-launch.ts +2 -1
  83. package/src/adapters/definitions/native-cli-entry-jcode.ts +4 -2
  84. package/src/adapters/definitions/native-cli-entry-types.ts +9 -2
  85. package/src/adapters/definitions/native-cli-launch-common.ts +2 -2
  86. package/src/adapters/definitions/native-cli-retained.ts +1 -1
  87. package/src/adapters/definitions/native-configuration.ts +18 -0
  88. package/src/adapters/definitions/native-help.ts +24 -0
  89. package/src/adapters/definitions/native-launch-declarations.ts +34 -0
  90. package/src/adapters/definitions/native-launch-policy.ts +4 -0
  91. package/src/adapters/definitions/native-launch-settings.ts +72 -0
  92. package/src/adapters/definitions/native-light-cli.ts +18 -0
  93. package/src/adapters/definitions/native-light-preview.ts +10 -0
  94. package/src/adapters/definitions/native-wrapper-launch.ts +10 -0
  95. package/src/adapters/definitions/qwen.ts +6 -29
  96. package/src/adapters/definitions/reviewer-variants.ts +7 -8
  97. package/src/adapters/external-declarations.ts +31 -0
  98. package/src/adapters/external-modules.ts +4 -29
  99. package/src/adapters/jcode.ts +3 -12
  100. package/src/adapters/native-capabilities.ts +18 -8
  101. package/src/adapters/native-proof-ports.ts +1 -1
  102. package/src/adapters/presets.ts +136 -0
  103. package/src/adapters/qwen-dual.ts +2 -2
  104. package/src/adapters/registry-types.ts +3 -0
  105. package/src/adapters/registry.ts +20 -81
  106. package/src/adapters/reviewer-print.ts +26 -9
  107. package/src/adapters/role-eligibility.ts +2 -1
  108. package/src/cli/accounts-import.ts +72 -0
  109. package/src/cli/agents-latest-table.ts +88 -0
  110. package/src/cli/agents-latest.ts +22 -0
  111. package/src/cli/agents-output.ts +10 -0
  112. package/src/cli/agents-presets.ts +100 -0
  113. package/src/cli/agents.ts +1 -1
  114. package/src/cli/attention.ts +3 -2
  115. package/src/cli/autonomy-homes.ts +7 -2
  116. package/src/cli/budget-renew-guidance.ts +129 -0
  117. package/src/cli/claude-homes.ts +9 -5
  118. package/src/cli/command-context.ts +3 -0
  119. package/src/cli/command-table.ts +123 -0
  120. package/src/cli/commands/accounts.ts +8 -0
  121. package/src/cli/commands/agents.ts +18 -0
  122. package/src/cli/commands/answer.ts +28 -0
  123. package/src/cli/commands/ask.ts +17 -0
  124. package/src/cli/commands/autonomy.ts +83 -0
  125. package/src/cli/commands/backlog.ts +46 -0
  126. package/src/cli/commands/bench.ts +60 -0
  127. package/src/cli/commands/board.ts +48 -0
  128. package/src/cli/commands/broker.ts +9 -0
  129. package/src/cli/commands/budget.ts +96 -0
  130. package/src/cli/commands/capabilities.ts +12 -0
  131. package/src/cli/commands/check-path.ts +55 -0
  132. package/src/cli/commands/completion.ts +8 -0
  133. package/src/cli/commands/console.ts +12 -0
  134. package/src/cli/commands/daemon.ts +8 -0
  135. package/src/cli/commands/deliverables.ts +25 -0
  136. package/src/cli/commands/doctor.ts +249 -0
  137. package/src/cli/commands/down.ts +3 -0
  138. package/src/cli/commands/export.ts +15 -0
  139. package/src/cli/commands/facts.ts +15 -0
  140. package/src/cli/commands/goal.ts +22 -0
  141. package/src/cli/commands/guidance.ts +102 -0
  142. package/src/cli/commands/help.ts +17 -0
  143. package/src/cli/commands/host.ts +45 -0
  144. package/src/cli/commands/init.ts +121 -0
  145. package/src/cli/commands/instructed.ts +19 -0
  146. package/src/cli/commands/instruction-hook.ts +15 -0
  147. package/src/cli/commands/intake.ts +24 -0
  148. package/src/cli/commands/kill.ts +15 -0
  149. package/src/cli/commands/learn.ts +23 -0
  150. package/src/cli/commands/lineage.ts +30 -0
  151. package/src/cli/commands/logs.ts +21 -0
  152. package/src/cli/commands/manager.ts +15 -0
  153. package/src/cli/commands/memory.ts +21 -0
  154. package/src/cli/commands/model.ts +25 -0
  155. package/src/cli/commands/models.ts +40 -0
  156. package/src/cli/commands/native.ts +39 -0
  157. package/src/cli/commands/pause.ts +5 -0
  158. package/src/cli/commands/peer.ts +32 -0
  159. package/src/cli/commands/permission.ts +26 -0
  160. package/src/cli/commands/permit.ts +12 -0
  161. package/src/cli/commands/pet.ts +24 -0
  162. package/src/cli/commands/projects.ts +49 -0
  163. package/src/cli/commands/queue.ts +70 -0
  164. package/src/cli/commands/recovery-run.ts +13 -0
  165. package/src/cli/commands/recovery.ts +130 -0
  166. package/src/cli/commands/release.ts +23 -0
  167. package/src/cli/commands/releases.ts +9 -0
  168. package/src/cli/commands/remember.ts +6 -0
  169. package/src/cli/commands/report.ts +27 -0
  170. package/src/cli/commands/research.ts +53 -0
  171. package/src/cli/commands/reset.ts +89 -0
  172. package/src/cli/commands/restart.ts +5 -0
  173. package/src/cli/commands/results.ts +31 -0
  174. package/src/cli/commands/resume.ts +5 -0
  175. package/src/cli/commands/review.ts +24 -0
  176. package/src/cli/commands/roadmap.ts +21 -0
  177. package/src/cli/commands/role.ts +34 -0
  178. package/src/cli/commands/roles.ts +30 -0
  179. package/src/cli/commands/room.ts +14 -0
  180. package/src/cli/commands/roster.ts +48 -0
  181. package/src/cli/commands/route.ts +9 -0
  182. package/src/cli/commands/say.ts +21 -0
  183. package/src/cli/commands/schedule.ts +17 -0
  184. package/src/cli/commands/sdlc.ts +321 -0
  185. package/src/cli/commands/settings.ts +148 -0
  186. package/src/cli/commands/setup.ts +89 -0
  187. package/src/cli/commands/shared-refusals.ts +25 -0
  188. package/src/cli/commands/smoke.ts +44 -0
  189. package/src/cli/commands/source.ts +64 -0
  190. package/src/cli/commands/specs.ts +13 -0
  191. package/src/cli/commands/status.ts +28 -0
  192. package/src/cli/commands/stop.ts +17 -0
  193. package/src/cli/commands/structure.ts +60 -0
  194. package/src/cli/commands/study.ts +39 -0
  195. package/src/cli/commands/tail.ts +19 -0
  196. package/src/cli/commands/task.ts +114 -0
  197. package/src/cli/commands/title.ts +17 -0
  198. package/src/cli/commands/turns.ts +10 -0
  199. package/src/cli/commands/ui.ts +47 -0
  200. package/src/cli/commands/undo.ts +77 -0
  201. package/src/cli/commands/up.ts +39 -0
  202. package/src/cli/commands/upgrade.ts +5 -0
  203. package/src/cli/commands/usage.ts +33 -0
  204. package/src/cli/commands/version.ts +5 -0
  205. package/src/cli/commands/watch.ts +30 -0
  206. package/src/cli/commands/worktrees.ts +31 -0
  207. package/src/cli/console-state.ts +5 -138
  208. package/src/cli/console-versions.ts +1 -1
  209. package/src/cli/help.ts +37 -15
  210. package/src/cli/identity.ts +23 -4
  211. package/src/cli/launch-check.ts +1 -2
  212. package/src/cli/launch.ts +13 -82
  213. package/src/cli/light-dispatch.ts +29 -0
  214. package/src/cli/main.js +8 -1
  215. package/src/cli/main.ts +233 -2816
  216. package/src/cli/orca-probe.ts +119 -0
  217. package/src/cli/output.ts +31 -2
  218. package/src/cli/preview.ts +10 -5
  219. package/src/cli/recovery-version-preflight.ts +28 -9
  220. package/src/cli/replace-process.ts +22 -0
  221. package/src/cli/report-layout.ts +142 -0
  222. package/src/cli/roadmap-usage.ts +16 -0
  223. package/src/cli/roadmap.ts +3 -16
  224. package/src/cli/sdlc-doctor.ts +27 -0
  225. package/src/cli/sdlc-output.ts +55 -1
  226. package/src/cli/setup-homes.ts +1 -1
  227. package/src/cli/start-agents-run.ts +1 -1
  228. package/src/cli/statusline-tee.ts +25 -4
  229. package/src/cli/terminal-recovery.ts +53 -10
  230. package/src/cli/upgrade-interactive.ts +1 -0
  231. package/src/cli/upgrade-runtime.ts +11 -0
  232. package/src/cli/upgrade.ts +4 -15
  233. package/src/hub/accounts.ts +148 -0
  234. package/src/hub/addons.ts +20 -0
  235. package/src/hub/agent-drift.ts +2 -1
  236. package/src/hub/budget-projection.ts +39 -7
  237. package/src/hub/budget.ts +231 -16
  238. package/src/hub/channel-project.ts +3 -3
  239. package/src/hub/conductor-peer.ts +24 -0
  240. package/src/hub/conductor.ts +2 -21
  241. package/src/hub/config-apply.ts +24 -13
  242. package/src/hub/config-edit.ts +1 -1
  243. package/src/hub/config-tier.ts +2 -0
  244. package/src/hub/config.ts +31 -14
  245. package/src/hub/control-client.ts +48 -0
  246. package/src/hub/daemon.ts +421 -61
  247. package/src/hub/events.ts +3 -0
  248. package/src/hub/home-tag.ts +12 -0
  249. package/src/hub/host.ts +217 -0
  250. package/src/hub/hub-tools.ts +2 -1
  251. package/src/hub/instance-budget.ts +2 -2
  252. package/src/hub/instance-config.ts +15 -126
  253. package/src/hub/instances.ts +22 -6
  254. package/src/hub/instruction-receipt.ts +2 -2
  255. package/src/hub/kimi-usage.ts +38 -11
  256. package/src/hub/lifecycle.ts +86 -4
  257. package/src/hub/mcp-bridge-core.ts +98 -0
  258. package/src/hub/mcp-channel-push.ts +20 -0
  259. package/src/hub/mcp-endpoint-serve.ts +178 -0
  260. package/src/hub/mcp-endpoint.ts +226 -0
  261. package/src/hub/mcp-tool-call.ts +181 -0
  262. package/src/hub/operational-settings.ts +2 -0
  263. package/src/hub/orca-env.ts +6 -0
  264. package/src/hub/orca-state.ts +84 -0
  265. package/src/hub/peers.ts +5 -1
  266. package/src/hub/permission-mode.ts +2 -1
  267. package/src/hub/project.ts +20 -0
  268. package/src/hub/protocol-window.ts +58 -0
  269. package/src/hub/quota-origin.ts +20 -0
  270. package/src/hub/registry.ts +36 -2
  271. package/src/hub/report.ts +1 -1
  272. package/src/hub/research.ts +1 -1
  273. package/src/hub/review-brief.ts +47 -2
  274. package/src/hub/roster.ts +6 -3
  275. package/src/hub/routing.ts +9 -2
  276. package/src/hub/sdlc-check.ts +205 -0
  277. package/src/hub/sdlc-sync.ts +146 -0
  278. package/src/hub/sdlc.ts +33 -4
  279. package/src/hub/settings.ts +7 -4
  280. package/src/hub/start-agents.ts +1 -1
  281. package/src/hub/start-mode.ts +11 -4
  282. package/src/hub/structure-budget.ts +131 -0
  283. package/src/hub/structure-scan.ts +149 -0
  284. package/src/hub/tasks-experiment.ts +455 -0
  285. package/src/hub/tasks-guidance.ts +606 -0
  286. package/src/hub/tasks-roadmap-plan.ts +419 -0
  287. package/src/hub/tasks-roadmap.ts +491 -0
  288. package/src/hub/tasks-study.ts +661 -0
  289. package/src/hub/tasks-survey.ts +192 -0
  290. package/src/hub/tasks.ts +319 -2548
  291. package/src/hub/terminal-open.ts +5 -3
  292. package/src/hub/tooling.ts +3 -19
  293. package/src/hub/usage-rollup.ts +9 -3
  294. package/src/local/tools.ts +5 -0
  295. package/src/ui/index.html +1 -1
  296. package/src/ui/needs.ts +17 -5
  297. package/src/ui/peer-palette.ts +2 -4
  298. package/templates/presets/agents.json +60 -0
  299. package/templates/presets/confirmation-matrix.json +8 -8
@@ -0,0 +1,342 @@
1
+ import { configuredPullDefinition } from "./configured-pull.ts";
2
+ import type { ConfiguredPrintAdapterConfig } from "./configured-print.ts";
3
+ import { shellQuote } from "../cli/shell-quote.ts";
4
+ import { readConfiguredAdapters, configuredHeadlessFactory, MODES, freeze } from "./configured-adapter-policy.ts";
5
+ import { presetStatusById } from "./presets.ts";
6
+ import { defaultPeerRoles } from "./definitions/native-adapter-policy.ts";
7
+ import { readFileSync } from "node:fs";
8
+ import { join } from "node:path";
9
+ import { readAdapterModuleDeclarations, type AdapterModuleDeclaration } from "./external-declarations.ts";
10
+ import { externalMetadataDefinitions, moduleArray, moduleDataObject, moduleText } from "./external-metadata.ts";
11
+ import { readControl, stateDirFor } from "../hub/control-client.ts";
12
+ import { conductorPeer } from "../hub/conductor-peer.ts";
13
+ import { configRefusal } from "../hub/config-trust.ts";
14
+ import { isPermissionMode, type PermissionMode } from "../hub/permission-paths.ts";
15
+ import { validateInstances, type InstancesConfig } from "../hub/instances.ts";
16
+ import { checkInstanceAccounts, readAccounts, type Accounts } from "../hub/accounts.ts";
17
+
18
+ import { catalogFromDefinitions } from "./declaration-resolution.ts";
19
+ import { freshReviewerPolicy, NATIVE_ADAPTER_POLICY as policy, NATIVE_FRESH_REVIEWER_FACTORY, NATIVE_ROUTING_POLICY, NATIVE_WATCH_CAPABILITIES } from "./definitions/native-adapter-policy.ts";
20
+ import { CLAUDE_LAUNCH_POLICY, CODEX_LAUNCH_POLICY } from "./definitions/native-launch-policy.ts";
21
+ import { compareNativeRank, isBuiltinAdapterKind } from "./definitions/native-help.ts";
22
+ import type { AdapterDefinition, ProjectAdapterCatalog } from "./registry-types.ts";
23
+
24
+ const builtinFactories = new WeakMap<AdapterDefinition, boolean>();
25
+
26
+ function declaration(
27
+ row: { metadata: Pick<AdapterDefinition, "api" | "kind" | "family" | "displayName" | "transport" | "roles" | "trust" | "identity" | "permission" | "instances" | "projection" | "optional" | "defaultOnRoster" | "enabledSwitchStartOnly">;
28
+ cli: AdapterDefinition["cli"]; headlessFactory: boolean },
29
+ start: AdapterDefinition["start"],
30
+ extras: Partial<AdapterDefinition> = {},
31
+ ): AdapterDefinition {
32
+ const definition = freeze<AdapterDefinition>({
33
+ ...row.metadata, start, cli: row.cli, session: { idField: "sessionId", currentId: () => undefined },
34
+ turnEnd: "adapter", display: { palette: { fg: "white", bg: "black" } }, ...extras,
35
+ });
36
+ builtinFactories.set(definition, row.headlessFactory);
37
+ return definition;
38
+ }
39
+
40
+ const member = {
41
+ claudeReviewer: declaration(policy.claudeReviewer, policy.claudeReviewer.start, {
42
+ budget: { account: "claude" }, reviewer: { declaration: "automatic", defaultPool: true }, routing: { reviewOnly: true },
43
+ }),
44
+ claudeImplementer: declaration(policy.claudeImplementer, policy.claudeImplementer.start, { budget: { account: "claude" } }),
45
+ };
46
+
47
+ function isolatedReviewer(kind: "codex" | "kimi" | "agy", displayName: string): AdapterDefinition {
48
+ const headlessFactory = NATIVE_FRESH_REVIEWER_FACTORY[kind];
49
+ const { start, cli, ...metadata } = freshReviewerPolicy(kind, displayName, headlessFactory);
50
+ return declaration({ metadata, cli, headlessFactory }, start, {
51
+ ...(kind === "agy" ? { optional: true } : {}),
52
+ budget: { account: kind }, routing: { reviewOnly: true },
53
+ reviewer: { declaration: kind === "agy" ? "automatic" : "explicit", defaultPool: headlessFactory,
54
+ ...(kind === "agy" ? { unavailable: "agy is an implementer peer (#485)" } : { scope: "code" as const }) },
55
+ });
56
+ }
57
+
58
+ const agyReviewer = isolatedReviewer("agy", "agy reviewer");
59
+ const declarations = Object.freeze([
60
+ declaration(policy.claude, { ...policy.claude.start, ...CLAUDE_LAUNCH_POLICY }, { budget: { account: "claude", checkpoint: true },
61
+ turnEnd: "native-hook", reviewerVariant: member.claudeReviewer, headlessVariant: member.claudeImplementer,
62
+ session: { idField: "sessionId", currentId: () => undefined, configDirEnv: "CLAUDE_CONFIG_DIR", launchRecord: true },
63
+ }),
64
+ declaration(policy.codex, { ...policy.codex.start, ...CODEX_LAUNCH_POLICY }, { budget: { account: "codex", checkpoint: true },
65
+ reviewerVariant: isolatedReviewer("codex", "Codex reviewer"),
66
+ session: { idField: "threadId", currentId: () => undefined, configDirEnv: "CODEX_HOME", launchRecord: true },
67
+ }),
68
+ declaration(policy.kimi, policy.kimi.start, { budget: { account: "kimi", resetSoftTokensOnResume: true }, capabilities: NATIVE_WATCH_CAPABILITIES,
69
+ reviewerVariant: isolatedReviewer("kimi", "Kimi reviewer"), attach: { pullOnlyForms: ["tui"] },
70
+ }),
71
+ declaration(policy.pi, policy.pi.start, { budget: { account: "pi", instrumented: true, noQuotaReason: "on-prem backends have no provider quota" }, routing: NATIVE_ROUTING_POLICY.pi, title: "hub", reporting: { tokensNotReported: true }, session: { idField: "sessionId", currentId: () => undefined, launchRecord: true } }),
72
+ declaration(policy.local, policy.local.start, { budget: { account: "local", quotaExempt: true, instrumented: true, noQuotaReason: "on-prem gateway has no provider quota" }, routing: NATIVE_ROUTING_POLICY.local, title: "hub" }),
73
+ declaration(policy.qwen, policy.qwen.start, { budget: { account: "qwen" }, capabilities: NATIVE_WATCH_CAPABILITIES, defaultOnRoster: false }),
74
+ declaration(policy.jcode, policy.jcode.start, { budget: { account: "jcode" } }),
75
+ declaration(policy.agy, policy.agy.start, { routing: NATIVE_ROUTING_POLICY.agy, turnEnd: "native-hook", reviewer: agyReviewer.reviewer, reviewerVariant: agyReviewer, attach: { pullOnlyForms: ["tui"] } }),
76
+ ]);
77
+
78
+ /** Startup metadata does not establish runtime admission, native ownership or external factory provenance. */
79
+ export function createPolicyCatalog(
80
+ raw?: unknown, external: readonly AdapterDefinition[] = [],
81
+ bindEntry?: (kind: string) => AdapterDefinition["cli"]["entry"],
82
+ ): ProjectAdapterCatalog {
83
+ const configured = compileConfiguredDefinitions(raw, declarations.map(row => row.kind));
84
+ const seen = new Set(configured.map(row => row.kind));
85
+ for (const row of external) {
86
+ if (row.api !== 1 || isBuiltinAdapterKind(row.kind) || seen.has(row.kind)) throw new Error("external adapter kind or API collision");
87
+ seen.add(row.kind);
88
+ }
89
+ const builtins = bindEntry ? declarations.map(row => {
90
+ const entry = bindEntry(row.kind);
91
+ if (!entry) return row;
92
+ const bound = freeze({ ...row, cli: { ...row.cli, entry } });
93
+ builtinFactories.set(bound, builtinFactories.get(row)!);
94
+ return bound;
95
+ }) : declarations;
96
+ const entries = Object.freeze([...builtins, ...configured, ...external]);
97
+ return catalogFromDefinitions(entries, external, row => builtinFactories.get(row) ?? declaredConfiguredFactory(row));
98
+ }
99
+
100
+ const builtinCatalog = createPolicyCatalog();
101
+ export const builtinPolicyOf = builtinCatalog.definitionOf;
102
+
103
+ export const DECLARATION_SUPPORTED_PEERS = Object.freeze([
104
+ ...declarations.filter(row => !row.optional),
105
+ ...declarations.filter(row => row.optional),
106
+ ].map(row => row.kind));
107
+ export const DECLARATION_PLANNER_PEERS = Object.freeze(declarations.filter(row => row.projection?.plannerEligible).map(row => row.kind));
108
+ export const DECLARATION_REVIEW_POOL_KINDS = Object.freeze(declarations.filter(row => (row.reviewerVariant ?? row).reviewer).map(row => row.kind));
109
+ export const DECLARATION_DEFAULT_REVIEW_POOL = Object.freeze(declarations.filter(row => (row.reviewerVariant ?? row).reviewer?.defaultPool).map(row => row.kind));
110
+
111
+ export const DECLARATION_START_MODE_PEERS = Object.freeze(declarations
112
+ .filter(row => row.start.forms.includes("tui") && row.start.forms.includes("headless"))
113
+ .sort((left, right) => compareNativeRank(left.projection?.startRank, right.projection?.startRank))
114
+ .map(row => row.kind));
115
+
116
+ /** Preserve the tool schema's legacy preferred order without spreading native names into tools. */
117
+ const CONDUCTOR_START_PRIORITY = ["local", "kimi", "pi"] as const;
118
+ export const CONDUCTOR_START_PEERS = [
119
+ ...CONDUCTOR_START_PRIORITY,
120
+ ...declarations.filter(adapter => !(CONDUCTOR_START_PRIORITY as readonly string[]).includes(adapter.kind)).map(adapter => adapter.kind),
121
+ ];
122
+
123
+ /**
124
+ * The words a person reads about which kinds a conductor may start, derived from the definitions in registry order so a new kind is named without a text edit (#1408 R5).
125
+ * `refusal` keeps the sentence the conductor always got, with the kinds read from `conductorStartable` and `optional`.
126
+ */
127
+ export function conductorStartText(): { peers: string; refusal: string; tuiPeers: string } {
128
+ const startable = DECLARATION_SUPPORTED_PEERS.filter(peer => builtinPolicyOf(peer)?.start.conductorStartable === true);
129
+ const list = (names: readonly string[], joiner: string) => names.length < 2 ? names.join("") : `${names.slice(0, names.length - 1).join(", ")} ${joiner} ${names[names.length - 1]}`;
130
+ const optional = (peer: string) => builtinPolicyOf(peer)?.optional === true;
131
+ // A kind opens in a terminal when its person-set start mode is tui, and a kind whose own default form is a terminal one starts that way.
132
+ const tui = startable.filter(peer => builtinPolicyOf(peer)!.start.defaultForm === "tui" && builtinPolicyOf(peer)!.start.forms.includes("tui"));
133
+ return {
134
+ peers: list(startable, "or"),
135
+ refusal: `only ${list(startable.filter(peer => !optional(peer)), "and")}, plus the opt-in ${list(startable.filter(optional), "and")}, may be started by the conductor`,
136
+ tuiPeers: list(tui, "and"),
137
+ };
138
+ }
139
+
140
+ type ConfiguredAcpPolicy = Extract<ReturnType<typeof readConfiguredAdapters>[number], { type: "acp" }>;
141
+ type Create = NonNullable<AdapterDefinition["start"]["create"]>;
142
+ export interface ConfiguredRuntimeFactories {
143
+ print(declaration: ConfiguredPrintAdapterConfig): Create;
144
+ acp(policy: ConfiguredAcpPolicy): Create;
145
+ }
146
+
147
+ function configuredPrintDefinition(kind: string, declaration: ConfiguredPrintAdapterConfig, factories?: ConfiguredRuntimeFactories): AdapterDefinition {
148
+ const { displayName, roles: advisory } = declaration;
149
+ return freeze<AdapterDefinition>({
150
+ api: 1, kind, family: kind, displayName, roles: advisory, transport: "hub-native", optional: true, defaultOnRoster: false,
151
+ trust: { onPrem: false, hubSandboxed: true }, identity: { mcp: "none" },
152
+ start: {
153
+ daemonPort: "configured-print", forms: ["headless"], defaultForm: "headless", conductorStartable: false, hubSwitches: [], ownedFlags: [],
154
+ preflight: request => request.form && request.form !== "headless" ? "configured print supports headless only" : undefined,
155
+ ...(factories ? { create: factories.print(declaration) } : {}),
156
+ },
157
+ permission: { unmanaged: "configured print has no native approval channel; read-only sandbox applies" },
158
+ session: { idField: "sessionId", currentId: () => undefined, recoveryRefusal: () => "configured print has no retained session; stop it before recovery and start it again afterwards" },
159
+ turnEnd: "adapter", cli: { command: kind, launchConfigKeys: [`adapters.${kind}.command`, `adapters.${kind}.args`], startWords: () => [kind] },
160
+ display: { palette: { fg: "white", bg: "black" } },
161
+ });
162
+ }
163
+
164
+ const configuredFactories = new WeakMap<AdapterDefinition, boolean>();
165
+
166
+ export function declaredConfiguredFactory(definition: AdapterDefinition): boolean | undefined {
167
+ return configuredFactories.get(definition);
168
+ }
169
+
170
+ /** Bind the checked declarations to drivers only in the executable registry. */
171
+ export function compileConfiguredDefinitions(raw: unknown, builtinKinds: readonly string[], factories?: ConfiguredRuntimeFactories): readonly AdapterDefinition[] {
172
+ return Object.freeze(readConfiguredAdapters(raw, builtinKinds).map(policy => {
173
+ const definition = configuredDefinition(policy, factories);
174
+ configuredFactories.set(definition, configuredHeadlessFactory(policy));
175
+ return definition;
176
+ }));
177
+ }
178
+
179
+ function configuredDefinition(policy: ReturnType<typeof readConfiguredAdapters>[number], factories?: ConfiguredRuntimeFactories): AdapterDefinition {
180
+ if (policy.type === "print") return configuredPrintDefinition(policy.kind, policy.declaration, factories);
181
+ if (policy.type === "pull") return configuredPullDefinition(policy.kind, policy.declaration);
182
+ const { kind, command, args, argv, roles, identity, preset, modes, nativePolicy } = policy;
183
+ // #1809: a kind written from a preset carries its status word wherever its name is shown; a preset the file does not know is untested.
184
+ const displayName = preset === undefined ? policy.displayName : `${policy.displayName} (${presetStatusById(preset)})`;
185
+ const definition: AdapterDefinition = {
186
+ api: 1, kind, family: kind, displayName, transport: "acp", roles, optional: true, defaultOnRoster: false,
187
+ trust: { onPrem: false, hubSandboxed: false }, identity: { mcp: "acp-session" }, instances: { mode: "headless" },
188
+ start: {
189
+ daemonPort: "acp", forms: ["headless"], defaultForm: "headless", conductorStartable: true, hubSwitches: [], ownedFlags: [],
190
+ exclusiveStartRefusal: "configured ACP start already in progress; retry after it settles",
191
+ preflight: request => request.form !== undefined && request.form !== "headless" ? `${kind}: configured ACP supports headless only`
192
+ : !identity ? `${kind}: native identity is unverified; configure the observed name/version pin before starting` : undefined,
193
+ launch: context => {
194
+ if (context.form !== "headless") throw new Error(`${kind}: configured ACP supports headless only`);
195
+ return { cmd: command, args: [...args], metadata: { packageEntrypoint: context.entrypoint, argv: [...argv], command: argv.map(shellQuote).join(" "), env: {} } };
196
+ },
197
+ ...(factories && policy.type === "acp" ? { create: factories.acp(policy) } : {}),
198
+ conductorStartArgs: args => args.length ? new Error("configured ACP starts accept no launch overrides") : {},
199
+ },
200
+ permission: { genericAcp: nativePolicy, grants: Object.fromEntries(MODES.map(mode => [mode, modes?.[mode as PermissionMode] ? `${kind}: asks native ACP to select configured ${mode} mode; native tool policy applies; NO hub sandbox` : `${kind}: no configured native mapping for ${mode}; NO hub sandbox`])), ...(!modes || !Object.keys(modes).length ? { unmanaged: `${kind}: native policy unmanaged; no configured permission map; NO hub sandbox` } : {}) },
201
+ // ponytail: configured ACP has no verified controlled-recovery driver. Add catalog-bound restoration
202
+ // with native session/group receipts before enabling controlled recovery; explicit/crash load stays fenced.
203
+ session: { idField: "sessionId", currentId: peer => { const id = peer.recoveryMetadata?.().sessionId; return typeof id === "string" ? id : undefined; }, launchKind: "acp", resumeById: true, recoveryRefusal: () => "configured ACP has no verified controlled-recovery driver; stop it explicitly and restart with its recorded native session id" },
204
+ turnEnd: "adapter", cli: { command: kind, launchConfigKeys: [`adapters.${kind}.command`, `adapters.${kind}.args`], startWords: () => [kind] },
205
+ display: { palette: { fg: "white", bg: "black" } },
206
+ };
207
+ return freeze(definition);
208
+ }
209
+
210
+ export const INSTANCE_CONFIG_FILES = ["config.json", "config.local.json"] as const;
211
+ export interface InstanceConfigLayer { name: typeof INSTANCE_CONFIG_FILES[number]; raw: Record<string, unknown> }
212
+
213
+ /** One source capture can feed declaration validation and the ordinary config loader. */
214
+ export function readInstanceConfigLayers(cwd: string): InstanceConfigLayer[] {
215
+ return INSTANCE_CONFIG_FILES.flatMap(name => {
216
+ try { return [{ name, raw: JSON.parse(readFileSync(join(cwd, ".agenthub", name), "utf8")) as Record<string, unknown> }]; }
217
+ catch (error) { if ((error as NodeJS.ErrnoException).code === "ENOENT") return []; throw error; }
218
+ });
219
+ }
220
+
221
+ /** Declaration authority is file provenance, never a suffix or a claim made by a native child. */
222
+ export interface DeclaredExternalInstance {
223
+ readonly id: string;
224
+ readonly kind: string;
225
+ readonly availability: "declared-unknown" | "refused";
226
+ readonly refusalCode: "catalog-unavailable" | "module-refused" | "kind-unavailable";
227
+ }
228
+ export interface InstanceRoleConfig {
229
+ adapter_modules?: readonly AdapterModuleDeclaration[];
230
+ adapters?: Readonly<Record<string, import("./configured-adapter-policy.ts").ConfiguredAdapterConfig>>;
231
+ /** #1810: declared accounts (label to kind and home path), machine-local like `adapters`. */
232
+ accounts?: Accounts;
233
+ instances?: InstancesConfig;
234
+ /** Unresolved or refused module declarations, excluded from executable policy. */
235
+ declaredExternalInstances?: readonly DeclaredExternalInstance[];
236
+ catalog: ProjectAdapterCatalog;
237
+ ignored: string[];
238
+ }
239
+ /** Keep valid dormant policy on disk, but never admit it through an unavailable module's identity. */
240
+ export function withoutInertInstancePolicy(raw: Record<string, unknown>, rows: readonly DeclaredExternalInstance[] = []): Record<string, unknown> {
241
+ if (!rows.length) return raw;
242
+ const ids = new Set(rows.flatMap(row => [row.id, row.kind]));
243
+ const result = { ...raw };
244
+ for (const key of ["permission_modes", "peers"] as const) {
245
+ if (raw[key] === undefined) continue;
246
+ const block = moduleDataObject(raw[key]);
247
+ result[key] = Object.fromEntries(Object.entries(block).filter(([id, value]) => {
248
+ if (!ids.has(id)) return true;
249
+ if (key === "permission_modes") {
250
+ if (!isPermissionMode(value)) throw new Error(`permission_modes.${id}: invalid dormant mode`);
251
+ } else {
252
+ const settings = moduleDataObject(value);
253
+ if (Object.keys(settings).some(field => field !== "start_mode") || settings.start_mode !== undefined && settings.start_mode !== "headless") throw new Error(`peers.${id}: invalid dormant headless setting`);
254
+ }
255
+ return false;
256
+ }));
257
+ }
258
+ return result;
259
+ }
260
+
261
+ export function readInstanceConfigWithCatalog(
262
+ cwd: string, layers: readonly InstanceConfigLayer[], externalDefinitions: readonly AdapterDefinition[] | undefined,
263
+ createCatalog: typeof createPolicyCatalog,
264
+ ): InstanceRoleConfig {
265
+ const moduleConfig = readAdapterModuleDeclarations(cwd, layers);
266
+ const ignored: string[] = [...moduleConfig.ignored];
267
+ let adapters: Readonly<Record<string, import("./configured-adapter-policy.ts").ConfiguredAdapterConfig>> | undefined, rawInstances: unknown, rawAccounts: unknown;
268
+ for (const { name, raw } of layers) {
269
+ const keys = ["adapters", "instances", "accounts"].filter(key => raw[key] !== undefined);
270
+ if (!keys.length) continue;
271
+ const refusal = name !== "config.local.json" ? "declarations are machine-local config.local.json values" : configRefusal(cwd, name);
272
+ if (refusal) { ignored.push(`${keys.join(", ")} in .agenthub/${name} ignored: ${refusal}`); continue; }
273
+ if (raw.adapters !== undefined) adapters = raw.adapters as Readonly<Record<string, import("./configured-adapter-policy.ts").ConfiguredAdapterConfig>>;
274
+ if (raw.instances !== undefined) rawInstances = raw.instances;
275
+ if (raw.accounts !== undefined) rawAccounts = raw.accounts;
276
+ }
277
+ const accounts = readAccounts(rawAccounts);
278
+ let external = externalDefinitions;
279
+ if (external === undefined) {
280
+ // Metadata discovery is optional: retained recovery receipts may name a project that no longer exists.
281
+ let metadata;
282
+ try { metadata = readControl(stateDirFor(cwd))?.externalAdapters; } catch { /* no running catalog available */ }
283
+ external = externalMetadataDefinitions(metadata);
284
+ }
285
+ const catalog = createCatalog(adapters, external);
286
+ // A descriptor on disk is display evidence only. It cannot turn module kinds into executable
287
+ // definitions or establish live policy. Only the daemon's explicit captured definitions can.
288
+ const runtimeDefinitions = new Set(externalDefinitions?.filter(definition => typeof definition.start.create === "function"));
289
+ const declaredExternalInstances: DeclaredExternalInstance[] = [];
290
+ let executableInstances = rawInstances;
291
+ if (moduleConfig.modules.length && rawInstances !== undefined) {
292
+ const entries = moduleDataObject(rawInstances);
293
+ if (Object.keys(entries).length > 64) throw new Error("instances: at most 64 extra instances are supported");
294
+ const executable: Record<string, unknown> = Object.create(null);
295
+ for (const [id, value] of Object.entries(entries)) {
296
+ const row = moduleDataObject(value), kind = row.kind;
297
+ const definition = typeof kind === "string" ? catalog.definitionOf(kind) : undefined;
298
+ const inert = !definition || catalog.externalDefinitions.includes(definition) && !runtimeDefinitions.has(definition);
299
+ if (!inert) { executable[id] = value; continue; }
300
+ if (!/^[a-z][a-z0-9-]{0,31}$/.test(id) || typeof kind !== "string" || !/^[a-z][a-z0-9-]{0,31}$/.test(kind)
301
+ || !id.startsWith(`${kind}-`) || !/^[a-z0-9][a-z0-9-]*$/.test(id.slice(kind.length + 1))) throw new Error("instances: invalid unresolved module instance declaration");
302
+ if (Object.keys(row).some(key => !["kind", "roles", "start_mode", "permission_mode", "worktree", "readOnly"].includes(key))) throw new Error("instances: unsupported external instance field");
303
+ if (Object.hasOwn(row, "roles")) {
304
+ const roles = moduleArray(row.roles, 3);
305
+ if (roles.some(role => typeof role !== "string" || !["implementer", "verifier", "reviewer"].includes(role)) || new Set(roles).size !== roles.length) throw new Error("instances: unsupported external instance role");
306
+ }
307
+ if (Object.hasOwn(row, "start_mode") && row.start_mode !== "headless") throw new Error("instances: external instances require headless mode");
308
+ if (Object.hasOwn(row, "readOnly") && typeof row.readOnly !== "boolean") throw new Error("instances: readOnly must be a boolean");
309
+ if (Object.hasOwn(row, "permission_mode") && (typeof row.permission_mode !== "string" || !["ask", "ask-when-needed", "never-ask"].includes(row.permission_mode))) throw new Error("instances: unknown permission mode");
310
+ if (row.readOnly === true && Object.hasOwn(row, "permission_mode")) throw new Error("instances: read-only instances cannot select a permission mode");
311
+ if (Object.hasOwn(row, "worktree")) moduleText(row.worktree, 4096);
312
+ declaredExternalInstances.push(Object.freeze(externalDefinitions === undefined
313
+ ? { id, kind, availability: "declared-unknown", refusalCode: "catalog-unavailable" }
314
+ : { id, kind, availability: "refused", refusalCode: "kind-unavailable" }));
315
+ }
316
+ executableInstances = executable;
317
+ }
318
+ const instances = validateInstances(executableInstances, catalog);
319
+ checkInstanceAccounts(instances, accounts);
320
+ return { ...(moduleConfig.modules.length ? { adapter_modules: moduleConfig.modules } : {}), ...(adapters !== undefined ? { adapters } : {}), ...(Object.keys(accounts).length ? { accounts } : {}), ...(Object.keys(instances).length ? { instances } : {}), ...(declaredExternalInstances.length ? { declaredExternalInstances: Object.freeze(declaredExternalInstances) } : {}), catalog, ignored };
321
+ }
322
+
323
+ export function readInstanceRoles(declarationConfig: InstanceRoleConfig, layers: readonly InstanceConfigLayer[]): InstanceRoleConfig & { roles: Record<string, string[]> } {
324
+ const roles = defaultPeerRoles(false);
325
+ for (const definition of declarationConfig.catalog.definitions) if (!isBuiltinAdapterKind(definition.kind)) roles[definition.kind] = [...definition.roles];
326
+ for (const name of INSTANCE_CONFIG_FILES) {
327
+ const raw = layers.find(layer => layer.name === name)?.raw;
328
+ if (raw?.roles !== undefined) {
329
+ conductorPeer(raw.roles); // Preserve the ordinary loader's ids, role-list and conductor validation exactly.
330
+ for (const [id, list] of Object.entries(raw.roles as Record<string, string[]>)) roles[id] = [...list];
331
+ }
332
+ }
333
+ // Unresolved rows and display-only module definitions grant no roles through id or kind aliases.
334
+ for (const row of declarationConfig.declaredExternalInstances ?? []) { delete roles[row.id]; delete roles[row.kind]; }
335
+ for (const definition of declarationConfig.catalog.externalDefinitions) delete roles[definition.kind];
336
+ conductorPeer(roles);
337
+ return { ...declarationConfig, roles };
338
+ }
339
+
340
+ export function readChannelInstanceConfig(cwd: string): InstanceRoleConfig {
341
+ return readInstanceConfigWithCatalog(cwd, readInstanceConfigLayers(cwd), undefined, createPolicyCatalog);
342
+ }
@@ -0,0 +1,53 @@
1
+ import { types } from "node:util";
2
+ import type { AdapterDefinition, KindMap, ProjectAdapterCatalog } from "./registry-types.ts";
3
+
4
+ /** Own enumerable data field of a plain object, never a caller accessor or an inherited value. */
5
+ function ownField(value: unknown, key: string): unknown {
6
+ if (!value || typeof value !== "object" || types.isProxy(value) || Array.isArray(value)
7
+ || ![Object.prototype, null].includes(Object.getPrototypeOf(value))) return undefined;
8
+ const field = Object.getOwnPropertyDescriptor(value, key);
9
+ return field && Object.hasOwn(field, "value") && field.enumerable ? field.value : undefined;
10
+ }
11
+ /** Declaration reads never execute caller accessors or inherit another project's mapping. */
12
+ export function declaredKind(id: string, instances: KindMap | undefined, catalog: Pick<ReadonlySet<string>, "has">): string | undefined {
13
+ if (!instances || typeof instances !== "object" || types.isProxy(instances) || Array.isArray(instances)
14
+ || ![Object.prototype, null].includes(Object.getPrototypeOf(instances))) return undefined;
15
+ const field = Object.getOwnPropertyDescriptor(instances, id);
16
+ if (!field || !Object.hasOwn(field, "value") || !field.enumerable) return undefined;
17
+ const entry: unknown = field.value;
18
+ if (!entry || typeof entry !== "object" || types.isProxy(entry) || Array.isArray(entry)
19
+ || ![Object.prototype, null].includes(Object.getPrototypeOf(entry))) return undefined;
20
+ const kind = Object.getOwnPropertyDescriptor(entry, "kind");
21
+ if (!kind || !Object.hasOwn(kind, "value") || !kind.enumerable || typeof kind.value !== "string" || !catalog.has(kind.value)) return undefined;
22
+ const prefix = `${kind.value}-`;
23
+ return /^[a-z][a-z0-9-]{0,31}$/.test(id) && id.startsWith(prefix) && /^[a-z0-9][a-z0-9-]*$/.test(id.slice(prefix.length)) ? kind.value : undefined;
24
+ }
25
+ type AdapterVariant<T> = { reviewerVariant?: T; headlessVariant?: T; reviewer?: { declaration: "automatic" | "explicit" } };
26
+
27
+ export function resolvedDefinition<T extends AdapterVariant<T>>(id: string, kind: string | undefined, instances: KindMap | undefined, catalog: ReadonlyMap<string, T>): T | undefined {
28
+ const definition = kind === undefined ? undefined : catalog.get(kind);
29
+ // #223: only a declared extra (never the builtin id) with start_mode "headless" runs as the kind's reviewer variant.
30
+ const declaration = ownField(instances, id), roles = ownField(declaration, "roles");
31
+ const reviewerOnly = Array.isArray(roles) && !types.isProxy(roles) && roles.length === 1 && Object.getOwnPropertyDescriptor(roles, "0")?.value === "reviewer";
32
+ const variant = definition?.reviewerVariant;
33
+ const fresh = variant?.reviewer?.declaration === "automatic" || ownField(declaration, "review_mode") === "fresh";
34
+ const headless = kind !== id && ownField(declaration, "start_mode") === "headless";
35
+ if (variant && headless && reviewerOnly && fresh) return variant;
36
+ const roleValues = Array.isArray(roles) && !types.isProxy(roles) && roles.length <= 4 ? Array.from({ length: roles.length }, (_, index) => Object.getOwnPropertyDescriptor(roles, String(index))?.value) : [];
37
+ const writerRoles = roleValues.includes("implementer") && roleValues.every(role => role === "implementer" || role === "verifier");
38
+ return headless && writerRoles && definition?.headlessVariant ? definition.headlessVariant : definition;
39
+ }
40
+
41
+ export function catalogFromDefinitions(entries: readonly AdapterDefinition[], external: readonly AdapterDefinition[], declaredHeadlessFactory?: ProjectAdapterCatalog["declaredHeadlessFactory"]): ProjectAdapterCatalog {
42
+ const catalog = new Map(entries.map(definition => [definition.kind, definition] as const));
43
+ const kindOf = (id: string, instances?: KindMap): string | undefined => catalog.has(id) ? id : typeof id === "string" ? declaredKind(id, instances, catalog) : undefined;
44
+ const definitionOf = (id: string, instances?: KindMap): AdapterDefinition | undefined => resolvedDefinition(id, kindOf(id, instances), instances, catalog);
45
+ return Object.freeze({ definitions: entries, externalDefinitions: external, kindOf, definitionOf, ...(declaredHeadlessFactory ? { declaredHeadlessFactory } : {}),
46
+ familyOf: (id: string, instances?: KindMap) => definitionOf(id, instances)?.family,
47
+ isSupportedPeer: (id: unknown, instances?: KindMap): id is string => {
48
+ if (typeof id !== "string") return false;
49
+ const kind = kindOf(id, instances), runtime = kind === undefined ? undefined : catalog.get(kind), resolved = definitionOf(id, instances);
50
+ return runtime !== undefined && resolved !== undefined && (kind === id || resolved === runtime || resolved.reviewer?.unavailable === undefined);
51
+ },
52
+ });
53
+ }