@staix/agent-hub 0.50.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 (350) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +1 -1
  3. package/docs/adding-an-ai-tool.md +26 -4
  4. package/docs/agent-notes/README.md +1 -0
  5. package/docs/agent-notes/adapters.md +4 -3
  6. package/docs/agent-notes/budget.md +8 -2
  7. package/docs/agent-notes/daemon.md +13 -8
  8. package/docs/agent-notes/local-worker.md +3 -3
  9. package/docs/agent-notes/security-review.md +6 -5
  10. package/docs/agent-notes/tasks.md +10 -3
  11. package/docs/agent-notes/tests.md +4 -3
  12. package/docs/cooperbench.md +1 -1
  13. package/docs/design/adapters.md +21 -0
  14. package/docs/design/cli-output-inventory.md +165 -150
  15. package/docs/design/cli-output.md +4 -3
  16. package/docs/design/guidance-probes.md +1 -0
  17. package/docs/design/roadmap.md +3 -1
  18. package/docs/design/task-board.md +35 -0
  19. package/docs/dogfood.md +21 -3
  20. package/docs/events.md +4 -2
  21. package/docs/memory.md +5 -3
  22. package/docs/operations.md +259 -19
  23. package/docs/quickstart.md +29 -2
  24. package/docs/roadmap.json +20 -20
  25. package/docs/roadmap.md +2 -2
  26. package/docs/roles.md +1 -1
  27. package/docs/sdlc.md +29 -5
  28. package/docs/security.md +11 -5
  29. package/docs/specs/2026-09-19-agent-hub-design.md +44 -0
  30. package/docs/specs/2026-09-19-multi-project-design.md +4 -0
  31. package/docs/specs/2026-09-20-upgrade-recovery-design.md +17 -0
  32. package/docs/specs/mcp-endpoint.md +63 -0
  33. package/docs/verification/2026-11-29-agy-1.5.20.md +33 -0
  34. package/docs/verification/2026-11-29-claude-profile-hook.md +12 -0
  35. package/docs/verification/2026-11-29-idle-daemon-footprint.md +75 -0
  36. package/docs/verification/2026-11-29-kimi-281-reviewer-compat.md +38 -0
  37. package/docs/verification/2026-11-29-kimi-tui-281.md +12 -0
  38. package/docs/verification/2026-11-30-0.51.0.md +91 -0
  39. package/docs/verification/2026-11-30-account-switch-1806.md +445 -0
  40. package/docs/verification/2026-11-30-capability-listing-shape-1808.md +45 -0
  41. package/docs/verification/2026-11-30-upgrade-keep-1807.md +174 -0
  42. package/docs/verification/2026-12-01-1811-confirmation-receipt.md +19 -0
  43. package/docs/verification/2026-12-01-1811-orca-agent-list.md +20 -0
  44. package/docs/verification/2026-12-01-1811-orca-pane-key.md +21 -0
  45. package/docs/verification/2026-12-02-1819-claude-process-after-renewal.md +54 -0
  46. package/docs/verification/2026-12-02-agy-1.5.21.md +74 -0
  47. package/docs/verification/2026-12-02-claude-implementer-2.1.334.md +44 -0
  48. package/docs/verification/2026-12-02-cli-import-graph.md +33 -0
  49. package/docs/verification/2026-12-03-0.52.0.md +150 -0
  50. package/docs/verification/2026-12-03-codex-0173-reviewer-isolation.md +53 -0
  51. package/docs/verification/2026-12-03-codex-0173-reviewer-tool-call.md +34 -0
  52. package/docs/verification/2026-12-03-jcode-1.3.0.md +25 -0
  53. package/docs/verification/agy/README.md +17 -0
  54. package/docs/verification/agy/cli-surface.ts +68 -0
  55. package/docs/verification/agy/interactive-bridge.ts +92 -0
  56. package/docs/verification/agy/interactive-session.ts +131 -0
  57. package/docs/verification/agy/launcher-nonce.ts +215 -0
  58. package/docs/verification/agy/native-hooks.ts +210 -0
  59. package/docs/verification/agy/originals/agent-hub-681/cli-surface.ts +87 -0
  60. package/docs/verification/agy/originals/agent-hub-681/native-hooks-adapted.ts +91 -0
  61. package/docs/verification/agy/originals/agent-hub-681/tui-actual.ts +200 -0
  62. package/docs/verification/agy/originals/agent-hub-684/probe.ts +107 -0
  63. package/docs/verification/agy/originals.json +25 -0
  64. package/docs/verification/agy/permission-new-functions.ts +128 -0
  65. package/docs/verification/agy/run-probe.py +108 -0
  66. package/docs/verification/agy/runtime.ts +171 -0
  67. package/docs/verification/agy/tmux-helper-control.ts +6 -0
  68. package/docs/verification/agy/tmux-session.ts +235 -0
  69. package/docs/verified.json +87 -42
  70. package/package.json +3 -3
  71. package/plugins/agent-hub/.claude-plugin/plugin.json +1 -1
  72. package/plugins/agent-hub/compat.json +157 -0
  73. package/plugins/agent-hub/kimi-hook.js +1416 -24985
  74. package/plugins/agent-hub/server.js +17415 -32755
  75. package/scripts/check-docs.mjs +1 -1
  76. package/src/adapters/acp.ts +13 -13
  77. package/src/adapters/agy/definition.ts +9 -26
  78. package/src/adapters/agy/entry.ts +2 -0
  79. package/src/adapters/channel-peer.ts +3 -1
  80. package/src/adapters/claude-channel-evidence.ts +7 -3
  81. package/src/adapters/claude-channel.ts +38 -257
  82. package/src/adapters/claude-implementer.ts +3 -1
  83. package/src/adapters/codex-appserver.ts +77 -15
  84. package/src/adapters/compat.ts +78 -14
  85. package/src/adapters/configured-acp.ts +23 -163
  86. package/src/adapters/configured-adapter-policy.ts +160 -0
  87. package/src/adapters/configured-pull-entry.ts +53 -0
  88. package/src/adapters/configured-pull.ts +38 -0
  89. package/src/adapters/conformance/fakes/app-server.ts +9 -2
  90. package/src/adapters/declaration-catalog.ts +25 -0
  91. package/src/adapters/declaration-data.ts +342 -0
  92. package/src/adapters/declaration-resolution.ts +53 -0
  93. package/src/adapters/definitions/builtin-metadata.ts +62 -84
  94. package/src/adapters/definitions/jcode-launch.ts +13 -0
  95. package/src/adapters/definitions/native-adapter-policy.ts +390 -0
  96. package/src/adapters/definitions/native-cli-claude-launch.ts +6 -3
  97. package/src/adapters/definitions/native-cli-codex-launch.ts +2 -1
  98. package/src/adapters/definitions/native-cli-entry-claude.ts +17 -2
  99. package/src/adapters/definitions/native-cli-entry-codex.ts +2 -0
  100. package/src/adapters/definitions/native-cli-entry-jcode.ts +6 -2
  101. package/src/adapters/definitions/native-cli-entry-kimi.ts +2 -0
  102. package/src/adapters/definitions/native-cli-entry-pi.ts +2 -0
  103. package/src/adapters/definitions/native-cli-entry-qwen.ts +2 -0
  104. package/src/adapters/definitions/native-cli-entry-types.ts +12 -3
  105. package/src/adapters/definitions/native-cli-jcode-home-init.ts +1 -1
  106. package/src/adapters/definitions/native-cli-launch-common.ts +2 -2
  107. package/src/adapters/definitions/native-cli-preview-common.ts +1 -1
  108. package/src/adapters/definitions/native-cli-retained.ts +1 -1
  109. package/src/adapters/definitions/native-config-defaults.ts +1 -1
  110. package/src/adapters/definitions/native-configuration.ts +18 -0
  111. package/src/adapters/definitions/native-help.ts +24 -0
  112. package/src/adapters/definitions/native-launch-declarations.ts +34 -0
  113. package/src/adapters/definitions/native-launch-policy.ts +4 -0
  114. package/src/adapters/definitions/native-launch-settings.ts +72 -0
  115. package/src/adapters/definitions/native-light-cli.ts +18 -0
  116. package/src/adapters/definitions/native-light-preview.ts +10 -0
  117. package/src/adapters/definitions/native-wrapper-launch.ts +10 -0
  118. package/src/adapters/definitions/qwen.ts +6 -29
  119. package/src/adapters/definitions/reviewer-variants.ts +7 -8
  120. package/src/adapters/external-declarations.ts +31 -0
  121. package/src/adapters/external-modules.ts +4 -29
  122. package/src/adapters/jcode.ts +19 -12
  123. package/src/adapters/native-capabilities.ts +18 -8
  124. package/src/adapters/native-facts-hooks.ts +12 -0
  125. package/src/adapters/native-proof-ports.ts +1 -1
  126. package/src/adapters/presets.ts +136 -0
  127. package/src/adapters/qwen-dual.ts +2 -2
  128. package/src/adapters/registry-types.ts +3 -0
  129. package/src/adapters/registry.ts +20 -81
  130. package/src/adapters/reviewer-print.ts +26 -9
  131. package/src/adapters/role-eligibility.ts +2 -1
  132. package/src/cli/accounts-import.ts +72 -0
  133. package/src/cli/agents-latest-table.ts +88 -0
  134. package/src/cli/agents-latest.ts +22 -0
  135. package/src/cli/agents-output.ts +10 -0
  136. package/src/cli/agents-presets.ts +100 -0
  137. package/src/cli/agents.ts +1 -1
  138. package/src/cli/attention.ts +3 -2
  139. package/src/cli/autonomy-homes.ts +7 -2
  140. package/src/cli/autonomy-offline.ts +1 -1
  141. package/src/cli/bench.ts +1 -1
  142. package/src/cli/budget-renew-guidance.ts +129 -0
  143. package/src/cli/claude-homes.ts +9 -5
  144. package/src/cli/claude-profile-hook.ts +31 -11
  145. package/src/cli/command-context.ts +3 -0
  146. package/src/cli/command-table.ts +123 -0
  147. package/src/cli/commands/accounts.ts +8 -0
  148. package/src/cli/commands/agents.ts +18 -0
  149. package/src/cli/commands/answer.ts +28 -0
  150. package/src/cli/commands/ask.ts +17 -0
  151. package/src/cli/commands/autonomy.ts +83 -0
  152. package/src/cli/commands/backlog.ts +46 -0
  153. package/src/cli/commands/bench.ts +60 -0
  154. package/src/cli/commands/board.ts +48 -0
  155. package/src/cli/commands/broker.ts +9 -0
  156. package/src/cli/commands/budget.ts +96 -0
  157. package/src/cli/commands/capabilities.ts +12 -0
  158. package/src/cli/commands/check-path.ts +55 -0
  159. package/src/cli/commands/completion.ts +8 -0
  160. package/src/cli/commands/console.ts +12 -0
  161. package/src/cli/commands/daemon.ts +8 -0
  162. package/src/cli/commands/deliverables.ts +25 -0
  163. package/src/cli/commands/doctor.ts +249 -0
  164. package/src/cli/commands/down.ts +3 -0
  165. package/src/cli/commands/export.ts +15 -0
  166. package/src/cli/commands/facts.ts +15 -0
  167. package/src/cli/commands/goal.ts +22 -0
  168. package/src/cli/commands/guidance.ts +102 -0
  169. package/src/cli/commands/help.ts +17 -0
  170. package/src/cli/commands/host.ts +45 -0
  171. package/src/cli/commands/init.ts +121 -0
  172. package/src/cli/commands/instructed.ts +19 -0
  173. package/src/cli/commands/instruction-hook.ts +15 -0
  174. package/src/cli/commands/intake.ts +24 -0
  175. package/src/cli/commands/kill.ts +15 -0
  176. package/src/cli/commands/learn.ts +23 -0
  177. package/src/cli/commands/lineage.ts +30 -0
  178. package/src/cli/commands/logs.ts +21 -0
  179. package/src/cli/commands/manager.ts +15 -0
  180. package/src/cli/commands/memory.ts +21 -0
  181. package/src/cli/commands/model.ts +25 -0
  182. package/src/cli/commands/models.ts +40 -0
  183. package/src/cli/commands/native.ts +39 -0
  184. package/src/cli/commands/pause.ts +5 -0
  185. package/src/cli/commands/peer.ts +32 -0
  186. package/src/cli/commands/permission.ts +26 -0
  187. package/src/cli/commands/permit.ts +12 -0
  188. package/src/cli/commands/pet.ts +24 -0
  189. package/src/cli/commands/projects.ts +49 -0
  190. package/src/cli/commands/queue.ts +70 -0
  191. package/src/cli/commands/recovery-run.ts +13 -0
  192. package/src/cli/commands/recovery.ts +130 -0
  193. package/src/cli/commands/release.ts +23 -0
  194. package/src/cli/commands/releases.ts +91 -0
  195. package/src/cli/commands/remember.ts +6 -0
  196. package/src/cli/commands/report.ts +27 -0
  197. package/src/cli/commands/research.ts +53 -0
  198. package/src/cli/commands/reset.ts +89 -0
  199. package/src/cli/commands/restart.ts +5 -0
  200. package/src/cli/commands/results.ts +31 -0
  201. package/src/cli/commands/resume.ts +5 -0
  202. package/src/cli/commands/review.ts +24 -0
  203. package/src/cli/commands/roadmap.ts +21 -0
  204. package/src/cli/commands/role.ts +34 -0
  205. package/src/cli/commands/roles.ts +30 -0
  206. package/src/cli/commands/room.ts +14 -0
  207. package/src/cli/commands/roster.ts +48 -0
  208. package/src/cli/commands/route.ts +9 -0
  209. package/src/cli/commands/say.ts +21 -0
  210. package/src/cli/commands/schedule.ts +17 -0
  211. package/src/cli/commands/sdlc.ts +321 -0
  212. package/src/cli/commands/settings.ts +148 -0
  213. package/src/cli/commands/setup.ts +89 -0
  214. package/src/cli/commands/shared-refusals.ts +25 -0
  215. package/src/cli/commands/smoke.ts +44 -0
  216. package/src/cli/commands/source.ts +64 -0
  217. package/src/cli/commands/specs.ts +13 -0
  218. package/src/cli/commands/status.ts +28 -0
  219. package/src/cli/commands/stop.ts +17 -0
  220. package/src/cli/commands/structure.ts +60 -0
  221. package/src/cli/commands/study.ts +39 -0
  222. package/src/cli/commands/tail.ts +19 -0
  223. package/src/cli/commands/task.ts +114 -0
  224. package/src/cli/commands/title.ts +17 -0
  225. package/src/cli/commands/turns.ts +10 -0
  226. package/src/cli/commands/ui.ts +47 -0
  227. package/src/cli/commands/undo.ts +77 -0
  228. package/src/cli/commands/up.ts +39 -0
  229. package/src/cli/commands/upgrade.ts +5 -0
  230. package/src/cli/commands/usage.ts +33 -0
  231. package/src/cli/commands/version.ts +5 -0
  232. package/src/cli/commands/watch.ts +30 -0
  233. package/src/cli/commands/worktrees.ts +31 -0
  234. package/src/cli/conductor-recovery.ts +1 -1
  235. package/src/cli/console-state.ts +5 -138
  236. package/src/cli/console-versions.ts +1 -1
  237. package/src/cli/facts-hook.ts +11 -4
  238. package/src/cli/help.ts +44 -20
  239. package/src/cli/identity.ts +27 -4
  240. package/src/cli/init-prompt.ts +1 -1
  241. package/src/cli/init-settings.ts +4 -35
  242. package/src/cli/init.ts +1 -1
  243. package/src/cli/json-text-spans.ts +57 -0
  244. package/src/cli/launch-check.ts +156 -0
  245. package/src/cli/launch.ts +19 -70
  246. package/src/cli/light-dispatch.ts +29 -0
  247. package/src/cli/main.js +8 -1
  248. package/src/cli/main.ts +257 -2799
  249. package/src/cli/memory.ts +1 -1
  250. package/src/cli/orca-probe.ts +119 -0
  251. package/src/cli/output.ts +45 -3
  252. package/src/cli/preview.ts +11 -6
  253. package/src/cli/recovery-launch.ts +1 -1
  254. package/src/cli/recovery-version-preflight.ts +28 -9
  255. package/src/cli/replace-process.ts +22 -0
  256. package/src/cli/report-layout.ts +142 -0
  257. package/src/cli/roadmap-usage.ts +16 -0
  258. package/src/cli/roadmap.ts +3 -16
  259. package/src/cli/sdlc-doctor.ts +27 -0
  260. package/src/cli/sdlc-output.ts +55 -1
  261. package/src/cli/setup-homes.ts +2 -2
  262. package/src/cli/start-agents-run.ts +85 -7
  263. package/src/cli/start-check.ts +28 -0
  264. package/src/cli/statusline-tee.ts +25 -4
  265. package/src/cli/terminal-recovery.ts +53 -10
  266. package/src/cli/upgrade-interactive.ts +1 -0
  267. package/src/cli/upgrade-runtime.ts +12 -1
  268. package/src/cli/upgrade.ts +4 -15
  269. package/src/cli/warn-line.ts +1 -1
  270. package/src/hub/accounts.ts +148 -0
  271. package/src/hub/addons.ts +20 -0
  272. package/src/hub/agent-drift.ts +2 -1
  273. package/src/hub/budget-projection.ts +39 -7
  274. package/src/hub/budget.ts +231 -16
  275. package/src/hub/channel-project.ts +3 -3
  276. package/src/hub/ci-watch.ts +311 -79
  277. package/src/hub/conductor-peer.ts +24 -0
  278. package/src/hub/conductor.ts +2 -21
  279. package/src/hub/config-apply.ts +25 -14
  280. package/src/hub/config-edit.ts +1 -1
  281. package/src/hub/config-tier.ts +2 -0
  282. package/src/hub/config.ts +535 -0
  283. package/src/hub/control-client.ts +49 -1
  284. package/src/hub/daemon.ts +492 -569
  285. package/src/hub/delivery-public.ts +11 -0
  286. package/src/hub/events.ts +3 -0
  287. package/src/hub/home-tag.ts +12 -0
  288. package/src/hub/host.ts +217 -0
  289. package/src/hub/hub-check.ts +125 -0
  290. package/src/hub/hub-tools.ts +2 -1
  291. package/src/hub/instance-budget.ts +2 -2
  292. package/src/hub/instance-config.ts +15 -126
  293. package/src/hub/instances.ts +22 -6
  294. package/src/hub/instruction-receipt.ts +2 -2
  295. package/src/hub/kimi-usage.ts +38 -11
  296. package/src/hub/lifecycle.ts +86 -4
  297. package/src/hub/mcp-bridge-core.ts +98 -0
  298. package/src/hub/mcp-channel-push.ts +20 -0
  299. package/src/hub/mcp-endpoint-serve.ts +178 -0
  300. package/src/hub/mcp-endpoint.ts +226 -0
  301. package/src/hub/mcp-tool-call.ts +181 -0
  302. package/src/hub/operational-settings.ts +2 -0
  303. package/src/hub/orca-env.ts +6 -0
  304. package/src/hub/orca-state.ts +84 -0
  305. package/src/hub/path-policy.ts +1 -1
  306. package/src/hub/peers.ts +5 -1
  307. package/src/hub/permission-mode.ts +5 -41
  308. package/src/hub/permission-paths.ts +41 -0
  309. package/src/hub/project.ts +20 -0
  310. package/src/hub/protocol-window.ts +58 -0
  311. package/src/hub/quota-origin.ts +20 -0
  312. package/src/hub/recovery-policy.ts +1 -1
  313. package/src/hub/registry.ts +36 -2
  314. package/src/hub/releases-inventory.ts +198 -0
  315. package/src/hub/report.ts +1 -1
  316. package/src/hub/research.ts +1 -1
  317. package/src/hub/review-brief.ts +47 -2
  318. package/src/hub/roster.ts +6 -3
  319. package/src/hub/routing.ts +9 -2
  320. package/src/hub/runtime-capture-prune.ts +25 -3
  321. package/src/hub/runtime-prune-health.ts +8 -1
  322. package/src/hub/sdlc-check.ts +205 -0
  323. package/src/hub/sdlc-release-authorization.ts +42 -21
  324. package/src/hub/sdlc-release-diagnostics.ts +5 -0
  325. package/src/hub/sdlc-release-policy.ts +21 -7
  326. package/src/hub/sdlc-release.ts +80 -20
  327. package/src/hub/sdlc-sync.ts +146 -0
  328. package/src/hub/sdlc.ts +38 -5
  329. package/src/hub/settings.ts +7 -4
  330. package/src/hub/start-agents.ts +1 -1
  331. package/src/hub/start-mode.ts +11 -4
  332. package/src/hub/structure-budget.ts +131 -0
  333. package/src/hub/structure-scan.ts +149 -0
  334. package/src/hub/tasks-experiment.ts +455 -0
  335. package/src/hub/tasks-guidance.ts +606 -0
  336. package/src/hub/tasks-roadmap-plan.ts +419 -0
  337. package/src/hub/tasks-roadmap.ts +491 -0
  338. package/src/hub/tasks-study.ts +661 -0
  339. package/src/hub/tasks-survey.ts +192 -0
  340. package/src/hub/tasks.ts +457 -2584
  341. package/src/hub/terminal-open.ts +5 -3
  342. package/src/hub/tooling.ts +3 -19
  343. package/src/hub/usage-rollup.ts +9 -3
  344. package/src/local/tools.ts +5 -0
  345. package/src/ui/index.html +1 -1
  346. package/src/ui/needs.ts +17 -5
  347. package/src/ui/peer-palette.ts +2 -4
  348. package/src/ui/plugin.ts +1 -1
  349. package/templates/presets/agents.json +60 -0
  350. package/templates/presets/confirmation-matrix.json +8 -8
@@ -0,0 +1,121 @@
1
+ import { terminalText } from "../console-state.ts";
2
+ import { autonomyEnvironment } from "../autonomy.ts";
3
+ import { readAutonomyDefaults } from "../../hub/autonomy-defaults.ts";
4
+ import { inheritMachineAutonomy } from "../autonomy-projects.ts";
5
+ import { resolveProfile } from "../../hub/profiles.ts";
6
+ import { existsSync } from "node:fs";
7
+ import { join } from "node:path";
8
+ import { hubHome } from "../../hub/project.ts";
9
+ import { Registry } from "../../hub/registry.ts";
10
+ import { autonomyInheritanceChange, init, initNextSteps, initResearchDefault, withInitResearch, initSettingRows, planInit } from "../init.ts";
11
+ import { discoverInitChecks, withInitChecks } from "../init-required-checks.ts";
12
+ import { INIT_USAGE, parseInitSettings } from "../init-settings.ts";
13
+ import { installedPeers } from "../init-roles.ts";
14
+ import { promptGate, runInitPrompt, settingLines, shadowOffered, type InitAnswers } from "../init-prompt.ts";
15
+ import { loadPacks } from "../../hub/packs.ts";
16
+ import { applyJcodeHome, installSkillsInJcodeHome, jcodeHomeBlocked, writeJcodeHomeConfig } from "../../adapters/definitions/native-cli-jcode-home-init.ts";
17
+ import { createInterface } from "node:readline/promises";
18
+ import { assertLifecycleAvailable } from "../../hub/recovery-store.ts";
19
+ import { inheritMachineStart } from "../start-agents-run.ts";
20
+ import { repoOf } from "../../hub/snapshots.ts";
21
+ import { errorLines } from "../error-format.ts";
22
+ import { asciiMarkers } from "../console-state.ts";
23
+ import type { CommandContext } from "../command-context.ts";
24
+
25
+ export async function run(context: CommandContext) {
26
+ const { args, cliDir, cwd, delegatedPeer, identity, initJcodeHome, liveTest, projectConfig, registeredProject, takeFlags, warn } = context;
27
+ const fail: CommandContext["fail"] = context.fail;
28
+ // #1065 T1: the settings flags come out first (a value flag takes the next word), then the older flags as before.
29
+ let settings: ReturnType<typeof parseInitSettings>;
30
+ try { settings = parseInitSettings(args); } catch (error) { return fail((error as Error).message); }
31
+ const flags = takeFlags(settings.rest.filter(arg => arg !== "--dry-run" && arg !== "--json" && arg !== "--shadow" && arg !== "--release-guard" && arg !== "--yes" && arg !== "--no-jcode-home"), ["--profile"], []);
32
+ if (flags.rest.length) fail(INIT_USAGE);
33
+ // A pack is a project file in .agenthub/roles/<name>.pack.json (#513a); init resolves the name and refuses an unknown one with the profiles and packs it knows.
34
+ let requestedProfile = flags.one["--profile"];
35
+ const newProject = !existsSync(join(cwd, ".agenthub/config.json"));
36
+ const initMachine = newProject ? readAutonomyDefaults(hubHome(), [cwd]) : undefined;
37
+ let request = settings.request, asked = Object.keys(request.values).length > 0;
38
+ let shadow = args.includes("--shadow"), releaseGuard = args.includes("--release-guard");
39
+ // #1065 T2: a person at a terminal on a new project, with no flag that sets anything and no --yes, is asked each setting (init-prompt.ts). Every other run, including a delegated peer, a live test and any run
40
+ // without a terminal, is never asked and gets defaults plus its flags. The gate is checked here, before any file is read or written, and --dry-run never prompts.
41
+ const flagGiven = asked || settings.request.autonomy !== undefined || requestedProfile !== undefined || shadow || releaseGuard;
42
+ if (promptGate({ newProject, flagGiven, yes: args.includes("--yes"), dryRun: args.includes("--dry-run"), stdinIsTTY: !!process.stdin.isTTY, stdoutIsTTY: !!process.stdout.isTTY, role: identity.role, delegated: !!delegatedPeer, liveTest })) {
43
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
44
+ // Ctrl-C closes the readline interface, which settles a pending question as null: the prompt ends with nothing written.
45
+ const interrupted = new Promise<null>(done => rl.once("close", () => done(null)));
46
+ const ask = (question: string): Promise<string | null> => Promise.race([rl.question(question).catch(() => null), interrupted]);
47
+ const machine = readAutonomyDefaults(hubHome(), [cwd]);
48
+ const preview = (answers: InitAnswers): string[] => {
49
+ const planned = withInitResearch(cwd, answers.request, initMachine?.researchEnabled);
50
+ const rows = initSettingRows(cwd, answers.profile, answers.shadow, answers.releaseGuard, planned);
51
+ const plan = planInit(cwd, answers.profile, answers.shadow, answers.releaseGuard, planned);
52
+ // The same autonomy-inheritance row `--dry-run` shows, from the one helper: a new project inherits the trusted machine preset after the writes unless the answer was off.
53
+ const inherit = autonomyInheritanceChange(cwd, machine.enabled, answers.request.autonomy);
54
+ if (inherit) plan.push(inherit);
55
+ return [...plan.map(change => `${change.action} ${change.path}: ${change.reason}${change.managedBlock ? ` (managed block: ${change.managedBlock})` : ""}`), ...settingLines(rows)];
56
+ };
57
+ let result: Awaited<ReturnType<typeof runInitPrompt>>;
58
+ try {
59
+ result = await runInitPrompt({ ask, print: line => console.log(terminalText(line)) },
60
+ { ...(machine.startAgents ? { machineAgents: machine.startAgents } : {}), machineResearch: initResearchDefault(cwd, initMachine?.researchEnabled), installedPeers: installedPeers(), packs: [...loadPacks(cwd).packs.keys()], discoverChecks: async () => (await discoverInitChecks(cwd)).names, shadowAvailable: shadowOffered(repoOf(cwd)) }, preview);
61
+ } finally { rl.close(); }
62
+ if (!result.ok) { if (result.reason === "refused") console.error(errorLines(`init: ${result.message}`, undefined, !!process.stderr.isTTY, asciiMarkers(process.env, process.argv.includes("--ascii"))).join("\n")); else warn(`init: ${result.reason === "interrupted" ? `interrupted: ${result.message}` : result.message}`); process.exitCode = result.reason === "refused" ? 1 : 0; return; }
63
+ requestedProfile = result.answers.profile; request = result.answers.request; asked = Object.keys(request.values).length > 0; shadow = result.answers.shadow; releaseGuard = result.answers.releaseGuard;
64
+ }
65
+ request = withInitResearch(cwd, request, initMachine?.researchEnabled);
66
+ try { request = await withInitChecks(cwd, request); } catch (error) { return fail((error as Error).message); }
67
+ // `--autonomy off` skips the machine inheritance on a new project; `inherit` is today's behaviour. Neither changes an existing project.
68
+ const inheritAutonomy = newProject && request.autonomy !== "off";
69
+ if (!newProject && request.autonomy !== undefined) warn("--autonomy applies to a new project only: this project already exists, so its autonomy settings are unchanged");
70
+ if (args.includes("--dry-run")) {
71
+ const plan = planInit(cwd, requestedProfile, shadow, releaseGuard, request);
72
+ const rows = initSettingRows(cwd, requestedProfile, shadow, releaseGuard, request);
73
+ const defaults = readAutonomyDefaults(hubHome(), [cwd]);
74
+ const inherit = inheritAutonomy ? autonomyInheritanceChange(cwd, defaults.enabled, request.autonomy) : undefined;
75
+ if (inherit) plan.push(inherit);
76
+ if (defaults.notice) warn(defaults.notice);
77
+ // #1627 A: the hub-owned jcode home is part of the plan, never written by a dry run.
78
+ const homePlan = args.includes("--no-jcode-home") ? undefined : initJcodeHome();
79
+ if (homePlan?.applicable) for (const line of homePlan.lines) plan.push({ action: homePlan.plan?.exists ? "modify" : "create", path: homePlan.plan!.home, reason: line.trim() });
80
+ // Without a settings flag the preview is the bare list of file rows, as it always was; with one it is { changes, settings }.
81
+ if (args.includes("--json")) return console.log(JSON.stringify(asked ? { changes: plan, settings: rows } : plan, null, 2));
82
+ const settingLines = rows.map(row => ` ${row.key}: ${row.from === undefined ? "(not set)" : JSON.stringify(row.from)} -> ${JSON.stringify(row.to)} (${row.file})`);
83
+ return console.log([...plan.map(change => `${change.action} ${change.path}: ${change.reason}${change.managedBlock ? ` (managed block: ${change.managedBlock})` : ""}`), ...settingLines].join("\n") || "already up to date");
84
+ }
85
+ assertLifecycleAvailable(cwd);
86
+ if (inheritAutonomy && delegatedPeer && readAutonomyDefaults(hubHome(), [cwd]).enabled) fail("machine autonomy inheritance is person-only; delegated live tests cannot apply it (ahub init --autonomy off skips it)");
87
+ let changed: string[], nextSteps: string[];
88
+ try { nextSteps = initNextSteps(cwd, request); changed = init(cwd, requestedProfile, shadow, releaseGuard, request); } catch (error) { return fail((error as Error).message); }
89
+ const project = registeredProject();
90
+ console.log(changed.length ? changed.map((p) => `${existsSync(p) ? "wrote" : "removed"} ${p}`).join("\n") : "already up to date");
91
+ // #1627 A: the hub-owned jcode home, after the project files exist. The person's own home is never written; a rerun reports drift only.
92
+ if (!args.includes("--no-jcode-home")) {
93
+ const homeInit = initJcodeHome();
94
+ if (homeInit.applicable && homeInit.plan) {
95
+ for (const line of homeInit.lines) console.log(terminalText(line));
96
+ if (homeInit.switchHome) { try { writeJcodeHomeConfig(cwd, homeInit.plan.home); console.log(`jcode_home now points at ${homeInit.plan.home}`); } catch (error) { warn((error as Error).message); process.exitCode = 1; } }
97
+ if (!homeInit.plan.exists) {
98
+ if (jcodeHomeBlocked(homeInit.plan.home)) warn(`jcode home ${homeInit.plan.home} is not a plain directory: nothing was created there`);
99
+ else {
100
+ try {
101
+ applyJcodeHome(homeInit.plan);
102
+ const installed = installSkillsInJcodeHome(join(cliDir, "..", "..", "plugins", "agent-hub", "skills"), homeInit.plan.home);
103
+ console.log(`wrote ${homeInit.plan.home}; hub skills: ${installed.filter(entry => entry.action === "install" || entry.action === "replace").length} installed`);
104
+ } catch (error) { warn(`jcode home was not fully set up: ${(error as Error).message}`); process.exitCode = 1; }
105
+ }
106
+ }
107
+ }
108
+ }
109
+ if (newProject) {
110
+ if (inheritAutonomy) {
111
+ const registry = new Registry();
112
+ try { for (const line of await inheritMachineAutonomy(project, hubHome(), autonomyEnvironment(process.env, !!process.stdin.isTTY), registry)) console.log(terminalText(line)); }
113
+ finally { registry.close(); }
114
+ }
115
+ // #608: the machine's default agent set, copied the same way (person-only: a delegated live test never inherits it). An explicit --agents is already in config.local.json, so it wins.
116
+ if (!delegatedPeer) { const roots = (() => { const r = new Registry(); try { return r.list().map(row => row.root); } finally { r.close(); } })(); for (const line of inheritMachineStart(cwd, hubHome(), [...roots, cwd])) console.log(terminalText(line)); }
117
+ }
118
+ const config = projectConfig(), examples = resolveProfile(config.profile, config.profile_overrides).example_checks;
119
+ if (examples.length) console.log(terminalText("Example checks (advisory):\n" + examples.map(example => "- " + example).join("\n")));
120
+ console.log(nextSteps.join("\n"));
121
+ }
@@ -0,0 +1,19 @@
1
+ import { INSTRUCTION_CONTROL_TIMEOUT_MS } from "../../hub/instructed-exact.ts";
2
+ import type { CommandContext } from "../command-context.ts";
3
+
4
+ export async function run(context: CommandContext) {
5
+ const { args, caller, connect, liveTest } = context;
6
+ const fail: CommandContext["fail"] = context.fail;
7
+ if (args[0] === "run") {
8
+ const session = process.env.CLAUDE_CODE_SESSION_ID;
9
+ if (caller.role !== "tools" || !session || liveTest) return fail("instruction requires the current managed Claude session");
10
+ const hub = await connect();
11
+ try {
12
+ const result = await hub.request({ t: "instruction_execute", session, ...(args.length > 1 ? { argv: args.slice(1) } : {}) }, INSTRUCTION_CONTROL_TIMEOUT_MS);
13
+ if (typeof result.output === "string") process.stdout.write(result.output);
14
+ if (result.ok !== true) fail(String(result.error ?? "instruction was not completed"));
15
+ } finally { hub.close(); }
16
+ return;
17
+ }
18
+ return fail("usage: ahub instructed run [<operation> <args...>]");
19
+ }
@@ -0,0 +1,15 @@
1
+ import { parseInstructionHook } from "../instruction-hook.ts";
2
+ import type { CommandContext } from "../command-context.ts";
3
+
4
+ export async function run({ args, caller, connect, liveTest }: CommandContext) {
5
+ if (args.length || caller.role !== "tools" || liveTest) return;
6
+ try {
7
+ const chunks: Buffer[] = []; let size = 0;
8
+ for await (const chunk of process.stdin) { const bytes = Buffer.from(chunk); size += bytes.length; if (size > 1024 * 1024) return; chunks.push(bytes); }
9
+ const input = Buffer.concat(chunks).toString("utf8");
10
+ const message = parseInstructionHook(input, process.env);
11
+ if (!message) return;
12
+ const hub = await connect(2000);
13
+ try { await hub.request(message, 2000); } finally { hub.close(); }
14
+ } catch { /* Hook failure never alters the native prompt or reveals it. */ }
15
+ }
@@ -0,0 +1,24 @@
1
+ import { renderIntake, renderIntakeChange } from "../intake-output.ts";
2
+ import type { CommandContext } from "../command-context.ts";
3
+
4
+ export async function run(context: CommandContext) {
5
+ const { args, outputOptions, showToolText, splitPresentation, taskOp } = context;
6
+ const fail: CommandContext["fail"] = context.fail;
7
+ // #334 (#511a): natural-language intake. Person only, except approve (#933: the configured conductor too, admitted and audited by the daemon).
8
+ // The request is a draft backlog card that nothing offers until `approve`; the hub, not this process, splits it.
9
+ const split = splitPresentation(args, { valueFlags: ["--source"] });
10
+ const present = outputOptions(split.flags); // before any request: an invalid --color must refuse before a mutation is sent
11
+ const usage = "usage: ahub intake \"<text>\" [--source <id>...] | approve <id> | discard <id> [--json] [--color=auto|always|never]";
12
+ const sources: string[] = [], words: string[] = [];
13
+ for (let i = 0; i < split.operands.length; i++) {
14
+ const arg = split.operands[i]!;
15
+ if (arg === "--source") { const id = split.operands[++i]; if (!id) return fail("--source needs a source id"); sources.push(id); } else words.push(arg);
16
+ }
17
+ const [sub, id] = words;
18
+ if ((sub === "approve" || sub === "discard") && words.length === 2 && !sources.length) {
19
+ if (!/^[1-9]\d*$/.test(id!)) return fail(usage);
20
+ return showToolText((data, _c, now, ascii) => renderIntakeChange(sub, data, present.columns, now, ascii), await taskOp(sub === "approve" ? "intake_approve" : "intake_discard", { id: Number(id) }), present);
21
+ }
22
+ if (words.length !== 1 || !words[0]!.trim()) return fail(usage);
23
+ return showToolText((data, _c, now, ascii) => renderIntake(data, present.columns, now, ascii), await taskOp("intake", { text: words[0], ...(sources.length ? { sources } : {}) }, false, undefined, 90_000), present);
24
+ }
@@ -0,0 +1,15 @@
1
+ import { stopProject } from "../../hub/lifecycle.ts";
2
+ import { renderLifecycleReceipt } from "../reset-output.ts";
3
+ import type { CommandContext } from "../command-context.ts";
4
+
5
+ export async function run(context: CommandContext) {
6
+ const { hubManifest, matchingProject, printOutput } = context;
7
+ const fail: CommandContext["fail"] = context.fail;
8
+ const project = matchingProject();
9
+ if (!project) {
10
+ if (!hubManifest()) return printOutput(renderLifecycleReceipt({ lines: ["hub is not running"] }), false);
11
+ fail("hub has no matching registration; use its matching CLI to stop it before upgrading");
12
+ }
13
+ await stopProject(project);
14
+ printOutput(renderLifecycleReceipt({ lines: ["hub stopped"] }), false);
15
+ }
@@ -0,0 +1,23 @@
1
+ import { renderLearnChange, renderLearnList } from "../learn-output.ts";
2
+ import type { CommandContext } from "../command-context.ts";
3
+
4
+ export async function run(context: CommandContext) {
5
+ const { args, outputOptions, showToolText, splitPresentation, taskOp } = context;
6
+ const fail: CommandContext["fail"] = context.fail;
7
+ // #514b: the person's verdict on a recurring-criterion candidate (#514a). Person only, end to end: `learn` is a `console` command for an agent shell (classifyPeerCommand has no entry for it, so the
8
+ // identity layer refuses it before this runs), and the daemon refuses any caller but the person again. `accept` writes ONE key (profile_overrides.review_checklist) to the machine-local
9
+ // config through the settings writer; nothing in a card's text is written.
10
+ const split = splitPresentation(args);
11
+ const present = outputOptions(split.flags); // before any request: an invalid --color must refuse before a mutation is sent
12
+ const usage = "usage: ahub learn list [--all] [--accepted] | accept <id> | reject <id> [--json] [--color=auto|always|never]";
13
+ const [sub, ...rest] = split.operands;
14
+ if (sub === "list" && rest.every(arg => arg === "--all" || arg === "--accepted")) {
15
+ const all = rest.includes("--all"), accepted = rest.includes("--accepted");
16
+ // #1642 T2: `--accepted` is the outcome view of the lines already accepted, so --all (the decided candidates) has nothing to add there.
17
+ if (all && accepted) return fail("usage: ahub learn list [--all] [--accepted] (pass one of them)");
18
+ return showToolText((data, _c, _now, ascii) => renderLearnList(data, present.columns, all, accepted, ascii), await taskOp("learn_list", { ...(all ? { all: true } : {}), ...(accepted ? { accepted: true } : {}) }), present);
19
+ }
20
+ const [id, ...extra] = rest;
21
+ if ((sub !== "accept" && sub !== "reject") || !id || extra.length || !/^[1-9]\d*$/.test(id)) return fail(usage);
22
+ return showToolText((data, _c, now, ascii) => renderLearnChange(sub, data, present.columns, now, ascii), await taskOp(sub === "accept" ? "learn_accept" : "learn_reject", { id: Number(id) }), present);
23
+ }
@@ -0,0 +1,30 @@
1
+ import { terminalText } from "../console-state.ts";
2
+ import type { CommandContext } from "../command-context.ts";
3
+
4
+ export async function run(context: CommandContext) {
5
+ const { args, connect, liveTest } = context;
6
+ const fail: CommandContext["fail"] = context.fail;
7
+ const { parseLineageCommand, renderExecutionLineage, validateLineageReply, validateLineageLink } = await import("../lineage.ts");
8
+ let command;
9
+ try { command = parseLineageCommand(args); } catch (error) { return fail((error as Error).message); }
10
+ if (liveTest && command.op === "link") return fail("live-test cannot register execution links; retry without --live-test as the task's authorized actor");
11
+ const hub = await connect();
12
+ try {
13
+ if (!hub.features.includes("execution_lineage")) return fail("running hub lacks execution_lineage support; upgrade and restart the hub, then retry ahub lineage");
14
+ const { op, json, ...message } = command;
15
+ const result = await hub.request({ t: op === "show" ? "lineage_show" : "lineage_link", ...message });
16
+ if (result.ok !== true) return fail(`${terminalText(result.error ?? "lineage request refused").replace(/[\r\n]+/g, " ").slice(0, 512)}; check task scope, current flow revision and source access before retrying ahub lineage`, result.refusalAudited === true, result.authorityRefused);
17
+ const options = { json };
18
+ if (op === "show") {
19
+ let lineage;
20
+ try { lineage = validateLineageReply(result.lineage); } catch (error) { return fail((error as Error).message); }
21
+ if (options.json) console.log(JSON.stringify(lineage, null, 2));
22
+ else console.log(renderExecutionLineage(lineage).join("\n"));
23
+ } else {
24
+ let link;
25
+ try { link = validateLineageLink(result.link, command); } catch (error) { return fail((error as Error).message); }
26
+ if (options.json) console.log(JSON.stringify(link, null, 2));
27
+ else console.log(`Declared execution metadata link ${link.already ? "already registered" : "registered"} for task #${link.taskId}; this does not attest to producer execution.`);
28
+ }
29
+ } finally { hub.close(); }
30
+ }
@@ -0,0 +1,21 @@
1
+ import { join } from "node:path";
2
+ import type { CommandContext } from "../command-context.ts";
3
+
4
+ export async function run(context: CommandContext) {
5
+ const { args, connect, exec, identity, operationalIncomplete, stateDir } = context;
6
+ const fail: CommandContext["fail"] = context.fail;
7
+ if (identity.role !== "tools") return exec("tail", [args.includes("-f") ? "-f" : "-n100", join(stateDir, "hub.log")]);
8
+ const hub=await connect();const pending:string[]=[];let ready=false,incompleteShown=false;
9
+ hub.onPush=message=>{if(message.t==="operational_log" && typeof message.line==="string"){if(message.complete===false && !incompleteShown){operationalIncomplete(message,"log");incompleteShown=true;}if(ready)console.log(message.line);else if(pending.length<100)pending.push(message.line);}};
10
+ try {
11
+ const result=await hub.request({t:"conductor_operational",op:"logs",follow:args.includes("-f")});
12
+ if(result.ok!==true)fail(String(result.error??"operational logs unavailable"),result.refusalAudited===true,result.authorityRefused);
13
+ for(const line of result.lines??[])console.log(line);
14
+ ready=true;for(const line of pending)console.log(line);
15
+ if(!incompleteShown){operationalIncomplete(result,"log");if(result.complete===false)incompleteShown=true;}
16
+ if(args.includes("-f"))await new Promise<void>(resolve=>{
17
+ const finish=()=>{process.off("SIGINT",finish);resolve();};
18
+ hub.onClose=finish;process.once("SIGINT",finish);
19
+ });
20
+ } finally {hub.close();}
21
+ }
@@ -0,0 +1,15 @@
1
+ import { loadConfig } from "../../hub/config.ts";
2
+ import { hubHome } from "../../hub/project.ts";
3
+ import { startManager } from "../../hub/manager.ts";
4
+ import { effectiveStartAgents, startProjectAgents } from "../start-agents-run.ts";
5
+ import type { CommandContext } from "../command-context.ts";
6
+
7
+ export async function run({ lifecycle }: CommandContext) {
8
+ // #608: the dashboard's "start" counts as the person's `ahub up`: the manager starts the project's default agent set after the hub is ready.
9
+ const manager = await startManager({ lifecycle, afterStart: async (project) => {
10
+ const chosen = effectiveStartAgents(project.root, loadConfig(project.root).start.agents, hubHome(), [project.root]);
11
+ return startProjectAgents(project, chosen.agents);
12
+ } });
13
+ for (const signal of ["SIGINT", "SIGTERM"] as const) process.on(signal, () => void manager.stop());
14
+ await manager.stopped;
15
+ }
@@ -0,0 +1,21 @@
1
+ import { memoryCommand } from "../memory.ts";
2
+ import { selectedMemoryProfile } from "../../hub/memory-profile.ts";
3
+ import { checkMemoryProfiles, formatMemoryProfileCheck } from "../../hub/memory-profile-check.ts";
4
+ import type { CommandContext } from "../command-context.ts";
5
+
6
+ export async function run(context: CommandContext) {
7
+ const { args, caller, cwd } = context;
8
+ const fail: CommandContext["fail"] = context.fail;
9
+ // #258: the hub's own memory on this machine; reads are anyone's, changes a person's.
10
+ if (args.filter(arg => arg !== "--json")[0] === "profile-check") {
11
+ if (args.some(arg => arg !== "profile-check" && arg !== "--json")) fail("usage: ahub memory profile-check [--json]");
12
+ let selected: ReturnType<typeof selectedMemoryProfile>;
13
+ try { selected = selectedMemoryProfile(); } catch (e) { return fail((e as Error).message); } // an inactive split names the resume remedy
14
+ const result = await checkMemoryProfiles(selected);
15
+ console.log(args.includes("--json") ? JSON.stringify(result, null, 2) : formatMemoryProfileCheck(result));
16
+ if (!result.ready) process.exitCode = 1;
17
+ return;
18
+ }
19
+ // #1522: an agent shell runs this as itself; its peer id, not the person, is what amem records for a change.
20
+ try { console.log(await memoryCommand(args, cwd, { person: caller.role === "console", ...(caller.role === "tools" ? { agent: caller.peer } : {}) })); } catch (e) { fail((e as Error).message); }
21
+ }
@@ -0,0 +1,25 @@
1
+ import { renderRuntimeModels } from "../output.ts";
2
+ import type { CommandContext } from "../command-context.ts";
3
+
4
+ export async function run(context: CommandContext) {
5
+ const { args, connect, printOutput } = context;
6
+ const fail: CommandContext["fail"] = context.fail;
7
+ const { parseModelCommand, projectModelStatus } = await import("../model.ts");
8
+ let command;
9
+ try { command = parseModelCommand(args); } catch (error) { return fail((error as Error).message); }
10
+ const hub = await connect();
11
+ try {
12
+ if (!hub.features.includes("model_overrides")) return fail("running hub lacks model_overrides support; upgrade and restart the hub, then retry ahub model list");
13
+ const { json, ...message } = command;
14
+ const result = await hub.request({ t: "model", ...message });
15
+ if (result.ok !== true) return fail(String(result.error ?? "model request refused; upgrade and restart the hub before retrying"), result.refusalAudited === true, result.authorityRefused);
16
+ if (command.op !== "list" && result.appliesFrom !== "next_turn") return fail("model change is unconfirmed; inspect ahub model list before retrying");
17
+ const values = command.op === "list" ? result.models : [result.model];
18
+ if (!Array.isArray(values) || values.length > 512) return fail("model reply is not a supported bounded row list; upgrade and restart the hub, then retry ahub model list");
19
+ const models = values.map(projectModelStatus);
20
+ if (models.some(row => row === null)) return fail("model reply invalid; upgrade and restart the hub, then retry ahub model list");
21
+ const options = { json };
22
+ if (options.json) console.log(JSON.stringify({ models }, null, 2));
23
+ else printOutput(renderRuntimeModels(models.filter((row): row is NonNullable<typeof row> => row !== null)), false);
24
+ } finally { hub.close(); }
25
+ }
@@ -0,0 +1,40 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import { homedir } from "node:os";
4
+ import { join, resolve } from "node:path";
5
+ import { ensureMlx, inspectMlx, stopMlx } from "../../models/mlx.ts";
6
+ import { setupOllamaModel } from "../models-setup.ts";
7
+ import { renderModelsStatus } from "../output.ts";
8
+ import type { CommandContext } from "../command-context.ts";
9
+
10
+ export async function run(context: CommandContext) {
11
+ const { cwd, outputArguments, outputOptions, printOutput, projectConfig } = context;
12
+ const fail: CommandContext["fail"] = context.fail;
13
+ const action = outputArguments()[0] ?? "status";
14
+ const options = ["status", "start", "setup"].includes(action) ? outputOptions() : undefined;
15
+ const showStatus = (data: unknown) => options!.json ? console.log(JSON.stringify(data, null, 2)) : printOutput(renderModelsStatus(data, options!.columns, Date.now()), options!.color);
16
+ const configured = projectConfig().mlx;
17
+ if (configured.enabled === false) {
18
+ if (action === "status") return showStatus({ state: "disabled", enabled: false });
19
+ if (["setup", "start", "stop"].includes(action)) fail("MLX is disabled by mlx.enabled=false; models commands do not manage shared Ollama");
20
+ fail("usage: ahub models setup|status|start|stop");
21
+ }
22
+ const runtimeDir = configured.runtimeDir ? resolve(cwd, configured.runtimeDir) : join(homedir(), ".agenthub", "runtimes", "mlx");
23
+ const modelPath = configured.modelPath ? resolve(cwd, configured.modelPath) : join(homedir(), ".agenthub", "models", "qwen3-8b-mlx");
24
+ const mlxOptions = configured.provider === "ollama" ? configured : { ...configured, runtimeDir, modelPath };
25
+ if (action === "status") return showStatus(await inspectMlx(mlxOptions));
26
+ if (action === "start") { const handle = await ensureMlx(mlxOptions); return showStatus(handle.status()); }
27
+ if (action === "stop") { await stopMlx(mlxOptions); return console.log("MLX stopped"); }
28
+ if (action !== "setup") fail("usage: ahub models setup|status|start|stop");
29
+ if (configured.provider === "ollama") {
30
+ await setupOllamaModel(configured);
31
+ const handle = await ensureMlx(configured);
32
+ return showStatus(handle.status());
33
+ }
34
+ const python = join(runtimeDir, "bin", "python");
35
+ const run = (argv: string[]) => { const result = spawnSync(argv[0]!, argv.slice(1), { cwd, stdio: "inherit" }); if (result.status !== 0) fail(`models setup failed: ${argv.join(" ")}`); };
36
+ if (!existsSync(python)) run(["uv", "venv", "--python", "3.12", runtimeDir]);
37
+ run(["uv", "pip", "install", "--python", python, "mlx-lm==0.31.3"]);
38
+ run([python, "-c", `from huggingface_hub import snapshot_download; snapshot_download(repo_id='Qwen/Qwen3-8B-MLX-4bit', revision='383413e909f3bc5303ce195ebbdf0339c5a1a2a3', local_dir=${JSON.stringify(modelPath)}, token=False)`]);
39
+ console.log(`MLX runtime and pinned model prepared at ${runtimeDir}`);
40
+ }
@@ -0,0 +1,39 @@
1
+ import type { NativeCliDispatchEntry, NativeCliEntryContext } from "../../adapters/definitions/native-cli-entry-types.ts";
2
+ import type { CommandContext } from "../command-context.ts";
3
+
4
+ export async function runNative(commandContext: CommandContext, entry: NativeCliDispatchEntry): Promise<void> {
5
+ const { args, assertLifecycleAvailable, buildKimiTuiLaunch, buildLaunch, caller, childEnv,
6
+ claudeObservationHooks, cleanupClaudeSettings, cleanupStaleClaudeSettings, cliDir,
7
+ configureJcodeMcp, configureKimiMcp, connectLaunch, connectOnce, cwd, effectiveInstanceRoles, exec,
8
+ execWithEnv, launcherPreview, nativeLaunchEnv, nativeSelection, prepareTerminalLaunch,
9
+ processSignature, projectConfig, qwenSessionId, readControl, readInstanceRoleConfig,
10
+ recordClaudeLaunch, recordTerminalLaunch, recoveryLock, registerTerminalLaunch,
11
+ requireActiveInstance, requirePeerInstances, resolveInstanceExecutionCwd, runClaudeLaunch,
12
+ selectedInstance, startModeOf, stateDir, takeFlags, unattendedEnv } = commandContext;
13
+ const fail: CommandContext["fail"] = commandContext.fail;
14
+
15
+ // Preserve the original guard before native effects; previews remain read-only and precede this guard.
16
+ if (entry.lifecycleAdmission && !args.includes("--print-command") && !args.includes("--dry-run")) assertLifecycleAvailable(cwd);
17
+ const nativeConnect = async () => {
18
+ const hub = await connectLaunch();
19
+ try { if (selectedInstance) { requirePeerInstances(hub.features); requireActiveInstance((await hub.request({ t: "status" })).status, selectedInstance); } return hub; }
20
+ catch (error) { hub.close(); throw error; }
21
+ };
22
+ if (selectedInstance && !args.includes("--print-command") && !args.includes("--dry-run")) {
23
+ const hub = await nativeConnect(); hub.close();
24
+ }
25
+ const context: NativeCliEntryContext = { args, cwd, stateDir, cliDir, unattendedEnv, person: caller.role === "console", definition: entry.definition,
26
+ ...(selectedInstance ? { instance: selectedInstance } : {}), ...(nativeSelection.hubStarted ? { hubStarted: true as const } : {}),
27
+ projectConfig, connect: nativeConnect, connectOnce, fail,
28
+ exec: (bin, argv, tool) => exec(bin, argv, tool, context.executionCwd),
29
+ execWithEnv: (bin, argv, env, replace) => execWithEnv(bin, argv, env, selectedInstance ?? entry.command, context.executionCwd, replace === true), takeFlags,
30
+ helpers: { resolveExecutionCwd: peer => {
31
+ const current = readInstanceRoleConfig(cwd);
32
+ return resolveInstanceExecutionCwd(cwd, peer, current.instances, effectiveInstanceRoles(peer, current.instances, current.roles, current.catalog), current.catalog);
33
+ }, launcherPreview: (tool, raw, projectRoot, state, unattended) => launcherPreview(tool, raw, projectRoot, state, unattended, selectedInstance), readControl, recordTerminalLaunch, prepareTerminalLaunch, registerTerminalLaunch, recoveryLock, processSignature,
34
+ buildLaunch, claudeObservationHooks, recordClaudeLaunch, cleanupStaleClaudeSettings, cleanupClaudeSettings,
35
+ nativeLaunchEnv, runClaudeLaunch, childEnv, qwenSessionId, configureJcodeMcp, configureKimiMcp,
36
+ buildKimiTuiLaunch, startModeOf },
37
+ };
38
+ return entry.execute(context);
39
+ }
@@ -0,0 +1,5 @@
1
+ import type { CommandContext } from "../command-context.ts";
2
+
3
+ export function run({ hold }: CommandContext) {
4
+ return hold("pause");
5
+ }
@@ -0,0 +1,32 @@
1
+ import type { CommandContext } from "../command-context.ts";
2
+
3
+ export async function run(context: CommandContext) {
4
+ const { args, connect, outputOptions, splitPresentation } = context;
5
+ const fail: CommandContext["fail"] = context.fail;
6
+ const options = outputOptions();
7
+ const { operands, flags } = splitPresentation(args);
8
+ const usage = "usage: ahub peer takeover <peer> [standby-id] [--json] [--color=auto|always|never]";
9
+ const [sub, peer, standbyId, ...extra] = operands;
10
+ const uuid = (value: string | undefined): value is string => typeof value === "string" && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value);
11
+ if (sub !== "takeover" || !peer || !/^[a-z][a-z0-9-]{0,31}$/.test(peer) || extra.length || standbyId !== undefined && !uuid(standbyId)
12
+ || flags.some(flag => flag !== "--json" && !flag.startsWith("--color="))) fail(usage);
13
+ const hub = await connect();
14
+ try {
15
+ if (!hub.features.includes("peer_takeover")) fail("running hub lacks peer_takeover; upgrade and restart the running hub first");
16
+ let reply: any;
17
+ try { reply = await hub.request({ t: "peer_takeover", peer, ...(standbyId ? { standbyId } : {}) }, 5000); }
18
+ catch (error) {
19
+ const message = String((error as Error).message ?? "");
20
+ if (/unknown (?:control )?(?:message|request|command)(?:\b|:)|this hub does not know \"peer_takeover\"/i.test(message)) fail(`${message}; upgrade and restart the running hub to use ahub peer takeover`);
21
+ fail(`${message || "peer takeover result is unconfirmed"}; inspect ahub status before retrying; takeover may already have started`);
22
+ }
23
+ const transportError = String(reply.error ?? "");
24
+ if (reply.ok === false && (transportError === "hub connection closed" || transportError === "hub request could not be sent" || /^no answer from the hub within \d+ s$/.test(transportError))) {
25
+ fail(`${transportError}; inspect ahub status before retrying; takeover may already have started`);
26
+ }
27
+ if (reply.ok !== true) fail(String(reply.error ?? "peer takeover was refused"), reply.refusalAudited === true, reply.authorityRefused);
28
+ if (reply.outcome !== "requested" || !uuid(reply.standbyId) || standbyId !== undefined && reply.standbyId !== standbyId) fail("peer takeover result was not confirmed; refresh ahub status");
29
+ if (options.json) console.log(JSON.stringify(reply, null, 2));
30
+ else console.log(`${peer}: old session detached; standby attachment requested`);
31
+ } finally { hub.close(); }
32
+ }
@@ -0,0 +1,26 @@
1
+ import { isPermissionMode } from "../../hub/permission-mode.ts";
2
+ import { refuseNeverAskWithoutYes } from "../commands/shared-refusals.ts";
3
+ import { permissionBoundary } from "../console-state.ts";
4
+ import type { CommandContext } from "../command-context.ts";
5
+
6
+ export async function run(context: CommandContext) {
7
+ const { args, connect, localDeclarations, warn } = context;
8
+ const fail: CommandContext["fail"] = context.fail;
9
+ const positional = args.filter(arg => arg !== "--yes");
10
+ const [peer, mode] = positional;
11
+ if (positional.length > 2 || positional.some(arg => arg.startsWith("--")) || (mode !== undefined && !isPermissionMode(mode))) fail("usage: ahub permission [<peer> [ask|ask-when-needed|never-ask]] [--yes]");
12
+ if (mode === "never-ask" && !args.includes("--yes")) refuseNeverAskWithoutYes(fail);
13
+ const { scope: permissionScope, error: permissionScopeError } = localDeclarations();
14
+ if (mode === "never-ask" && peer) warn(`never-ask: ${permissionBoundary(peer, permissionScope.instances, permissionScope.catalog)}: approval prompts are disabled${permissionScopeError ? ` (project config unreadable: ${permissionScopeError})` : ""}`);
15
+ const hub = await connect();
16
+ try {
17
+ const reply = await hub.request({ t: "permission", ...(peer ? { peer } : {}), ...(mode ? { mode, confirmed: args.includes("--yes") } : {}) }, 35_000);
18
+ if (reply.ok === false) {
19
+ const error = String(reply.error ?? "permission request refused");
20
+ fail(/unknown (?:control )?(?:message|request|command)(?:\b|:)|this hub does not know "permission"/i.test(error) ? `${error}; upgrade the running hub to use ahub permission` : error);
21
+ }
22
+ if (reply.peers) for (const [id, value] of Object.entries(reply.peers)) console.log(`${id}: ${value}`);
23
+ else console.log(`${peer}: ${reply.permissionMode}`);
24
+ if (typeof reply.note === "string" && reply.note) console.log(reply.note);
25
+ } finally { hub.close(); }
26
+ }
@@ -0,0 +1,12 @@
1
+ import type { CommandContext } from "../command-context.ts";
2
+
3
+ export async function run(context: CommandContext) {
4
+ const { args, connect } = context;
5
+ const fail: CommandContext["fail"] = context.fail;
6
+ const [id, option] = args;
7
+ if (!id || !option) fail("usage: ahub permit <id> <option|deny>");
8
+ const hub = await connect();
9
+ hub.send({ t: "permit", id, ...(option === "deny" ? {} : { option }) });
10
+ await hub.request({ t: "status" }); // flush before closing
11
+ hub.close();
12
+ }
@@ -0,0 +1,24 @@
1
+ import { readPet, renderPet } from "../pet.ts";
2
+ import { PET_WINDOW_RETIRED_NOTICE, petPalette } from "../../pet/config.ts";
3
+ import { loadPetConfig } from "../pet-config.ts";
4
+ import type { CommandContext } from "../command-context.ts";
5
+
6
+ export async function run(context: CommandContext) {
7
+ const { args, cwd, stateDir } = context;
8
+ const fail: CommandContext["fail"] = context.fail;
9
+ if (args.includes("--window")) {
10
+ if (args.some(arg => !["--window", "--close"].includes(arg))) return fail("usage: ahub pet --window [--close]");
11
+ return console.log(PET_WINDOW_RETIRED_NOTICE);
12
+ }
13
+ if (args.includes("--palette")) {
14
+ if (args.length !== 2 || args[0] !== "--palette") return fail("usage: ahub pet [--short] | --window [--close] | --palette <blue|teal|violet|ochre>");
15
+ if (!petPalette(args[1])) return fail("Unknown pet palette; use blue, teal, violet or ochre (a/b/c/d).");
16
+ return console.log(PET_WINDOW_RETIRED_NOTICE);
17
+ }
18
+ if (args.some(arg => arg !== "--short")) return fail("usage: ahub pet [--short] | --window [--close] | --palette <blue|teal|violet|ochre>");
19
+ const short = args.includes("--short");
20
+ let character: import("../../pet/frame.ts").CharacterId | undefined;
21
+ try { character = loadPetConfig(cwd).character; } catch { /* explicit structural reads remain available with malformed presentation config */ }
22
+ const text = renderPet(readPet(stateDir), short, character);
23
+ process.stdout.write(short ? text : text + "\n");
24
+ }
@@ -0,0 +1,49 @@
1
+ import { terminalText } from "../console-state.ts";
2
+ import { basename } from "node:path";
3
+ import { Registry } from "../../hub/registry.ts";
4
+ import { applyProjectMove, previewProjectMove } from "../../hub/project-move.ts";
5
+ import type { CommandContext } from "../command-context.ts";
6
+
7
+ export async function run(context: CommandContext) {
8
+ const { args, caller, liveTest, outputArguments, outputOptions, printProjects, takeFlags } = context;
9
+ const fail: CommandContext["fail"] = context.fail;
10
+ if (args[0] === "move") {
11
+ if (caller.role !== "console" || liveTest) fail("moving a project is person-only; run ahub projects move from your terminal");
12
+ const { one, rest } = takeFlags(args.slice(1), ["--state", "--confirm"], []);
13
+ const [old, root] = rest;
14
+ if (rest.length !== 2 || !old || !root || rest.some(arg => arg.startsWith("--")) ||
15
+ Object.values(one).some(value => !value || value.startsWith("--")))
16
+ fail("usage: ahub projects move <old-id|old-root> <new-root> [--state <dir>] [--confirm <fingerprint>]");
17
+ const registry = new Registry();
18
+ try {
19
+ const confirm = one["--confirm"];
20
+ const plan = confirm === undefined
21
+ ? previewProjectMove(registry, old, root, one["--state"])
22
+ : applyProjectMove(registry, old, root, one["--state"], confirm);
23
+ const lines = [`${plan.old.id} -> ${plan.next.id}`, `${plan.old.root} -> ${plan.next.root}`,
24
+ `State: ${plan.next.stateDir}`, `Base port kept: ${plan.old.basePort}`];
25
+ for (const store of plan.stores) {
26
+ lines.push(`Database ${store.project.id}: ${store.file}`);
27
+ for (const change of store.rewrites) lines.push(` ${change.table}.${change.column}: ${change.count}`);
28
+ }
29
+ for (const marker of plan.markers) lines.push(` ${basename(marker.file)}: 1 (${marker.after === undefined ? "archived" : "rebound"})`);
30
+ lines.push("Autonomy consent is dropped. Run ahub autonomy on from the new root to grant it again.",
31
+ "Memory project keys and recovery history are left at their original identities.",
32
+ `Backup ${confirm === undefined ? "directory (on confirm)" : "saved at"}: ${plan.archive}`,
33
+ "Undo: stop the affected hubs and follow the restore.json mapping in the backup. See Multiple projects and worktrees in the operations guide.");
34
+ if (confirm === undefined) lines.push(`Confirm by repeating the command with --confirm ${plan.fingerprint}`);
35
+ console.log(terminalText(lines.join("\n")));
36
+ } finally { registry.close(); }
37
+ return;
38
+ }
39
+ if (args[0] === "remove") {
40
+ if (args.length !== 2) fail("usage: ahub projects remove <id>");
41
+ const registry = new Registry();
42
+ try { registry.remove(args[1]!); } finally { registry.close(); }
43
+ console.log("registration removed; project files were kept");
44
+ return;
45
+ }
46
+ const options = outputOptions();
47
+ if (outputArguments().length) fail("usage: ahub projects [--json] [--full] [--color=auto|always|never]");
48
+ await printProjects(options);
49
+ }