@cohortapp/agent-sdk 2.17.0 → 2.18.5

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 (531) hide show
  1. package/.claude/settings.json +18 -0
  2. package/.env.example +18 -5
  3. package/README.md +1 -0
  4. package/bin/maestro.mjs +62 -0
  5. package/docs/guides/billing-console-keys.md +60 -0
  6. package/docs/guides/front-door-session.md +54 -9
  7. package/docs/guides/mac-mini.md +20 -25
  8. package/docs/guides/setup-wizard.md +1 -1
  9. package/docs/runbooks/fleet-rollout.md +156 -0
  10. package/docs/runbooks/mac-mini-bootstrap.md +12 -14
  11. package/lib/action-executor.js +19 -3
  12. package/lib/budget-guard.mjs +279 -3
  13. package/lib/channels/base-adapter.mjs +3 -1
  14. package/lib/channels/contract.mjs +2 -1
  15. package/lib/channels/inbox-item.mjs +8 -0
  16. package/lib/claude-bin.mjs +5 -6
  17. package/lib/cli/doctor-checks.mjs +141 -10
  18. package/lib/cli/global-setup-extras.mjs +5 -1
  19. package/lib/cli/inbox.mjs +100 -15
  20. package/lib/cli/seat-auth.mjs +463 -0
  21. package/lib/cli/session.mjs +80 -12
  22. package/lib/collective/capture-slots.mjs +234 -0
  23. package/lib/collective/capture.mjs +8 -6
  24. package/lib/collective/config.mjs +2 -0
  25. package/lib/collective/global-config.mjs +63 -1
  26. package/lib/collective/loop-guard.mjs +155 -0
  27. package/lib/collective/presence.mjs +142 -5
  28. package/lib/comms/send-gate.mjs +559 -1
  29. package/lib/diagnostics/alerts.mjs +49 -0
  30. package/lib/diagnostics/cadence-output-freshness.mjs +288 -0
  31. package/lib/engine/agents/definitions.mjs +343 -0
  32. package/lib/engine/agents/persist.mjs +275 -0
  33. package/lib/engine/agents/runtime.mjs +748 -0
  34. package/lib/engine/agents/usage.mjs +95 -0
  35. package/lib/engine/auth-status.mjs +139 -0
  36. package/lib/engine/budget.mjs +194 -0
  37. package/lib/engine/cli.mjs +1204 -0
  38. package/lib/engine/commands/index.mjs +269 -0
  39. package/lib/engine/context/budget.mjs +219 -0
  40. package/lib/engine/context/cache.mjs +125 -0
  41. package/lib/engine/context/child-env.mjs +215 -0
  42. package/lib/engine/context/compaction.mjs +342 -0
  43. package/lib/engine/context/images.mjs +90 -0
  44. package/lib/engine/context/instructions.mjs +327 -0
  45. package/lib/engine/context/lazy-instructions.mjs +169 -0
  46. package/lib/engine/context/manager.mjs +182 -0
  47. package/lib/engine/context/real-path.mjs +91 -0
  48. package/lib/engine/context/secret-values.mjs +163 -0
  49. package/lib/engine/context/settings.mjs +274 -0
  50. package/lib/engine/context/stream-input.mjs +159 -0
  51. package/lib/engine/guard.mjs +152 -0
  52. package/lib/engine/hooks.mjs +713 -0
  53. package/lib/engine/loop.mjs +560 -0
  54. package/lib/engine/mcp/client.mjs +254 -0
  55. package/lib/engine/mcp/config.mjs +301 -0
  56. package/lib/engine/mcp/http.mjs +201 -0
  57. package/lib/engine/mcp/index.mjs +146 -0
  58. package/lib/engine/mcp/jsonrpc.mjs +147 -0
  59. package/lib/engine/mcp/naming.mjs +66 -0
  60. package/lib/engine/mcp/resources.mjs +89 -0
  61. package/lib/engine/mcp/results.mjs +133 -0
  62. package/lib/engine/mcp/stdio.mjs +137 -0
  63. package/lib/engine/mcp/supervisor.mjs +116 -0
  64. package/lib/engine/messages.mjs +104 -0
  65. package/lib/engine/output/json.mjs +164 -0
  66. package/lib/engine/output/stream-json.mjs +266 -0
  67. package/lib/engine/permissions.mjs +845 -0
  68. package/lib/engine/process-identity.mjs +164 -0
  69. package/lib/engine/process-tree.mjs +551 -0
  70. package/lib/engine/prompt.mjs +60 -0
  71. package/lib/engine/session/store.mjs +299 -0
  72. package/lib/engine/session-runtime/args.mjs +97 -0
  73. package/lib/engine/session-runtime/host.mjs +143 -0
  74. package/lib/engine/session-runtime/inbox.mjs +122 -0
  75. package/lib/engine/session-runtime/notifications.mjs +129 -0
  76. package/lib/engine/session-runtime/registry.mjs +328 -0
  77. package/lib/engine/session-runtime/runner.mjs +344 -0
  78. package/lib/engine/session-runtime/socket.mjs +212 -0
  79. package/lib/engine/session-runtime/wakeup.mjs +115 -0
  80. package/lib/engine/skills/index.mjs +321 -0
  81. package/lib/engine/tools/bash-background.mjs +533 -0
  82. package/lib/engine/tools/bash.mjs +216 -0
  83. package/lib/engine/tools/edit.mjs +97 -0
  84. package/lib/engine/tools/glob.mjs +81 -0
  85. package/lib/engine/tools/grep.mjs +224 -0
  86. package/lib/engine/tools/index.mjs +84 -0
  87. package/lib/engine/tools/list-agents.mjs +32 -0
  88. package/lib/engine/tools/ls.mjs +127 -0
  89. package/lib/engine/tools/monitor.mjs +82 -0
  90. package/lib/engine/tools/notebook-edit.mjs +218 -0
  91. package/lib/engine/tools/read.mjs +103 -0
  92. package/lib/engine/tools/schedule-wakeup.mjs +45 -0
  93. package/lib/engine/tools/schema.mjs +144 -0
  94. package/lib/engine/tools/send-message.mjs +77 -0
  95. package/lib/engine/tools/session.mjs +70 -0
  96. package/lib/engine/tools/todo.mjs +144 -0
  97. package/lib/engine/tools/toolsearch.mjs +217 -0
  98. package/lib/engine/tools/walk.mjs +193 -0
  99. package/lib/engine/tools/web-switch.mjs +31 -0
  100. package/lib/engine/tools/webfetch-html.mjs +387 -0
  101. package/lib/engine/tools/webfetch-net.mjs +340 -0
  102. package/lib/engine/tools/webfetch.mjs +198 -0
  103. package/lib/engine/tools/websearch.mjs +91 -0
  104. package/lib/engine/tools/workflow.mjs +95 -0
  105. package/lib/engine/tools/write.mjs +76 -0
  106. package/lib/engine/tui/line-editor.mjs +137 -0
  107. package/lib/engine/tui/render.mjs +86 -0
  108. package/lib/engine/tui/tui.mjs +274 -0
  109. package/lib/engine/wire/anthropic-messages.mjs +263 -0
  110. package/lib/engine/wire/effort.mjs +36 -0
  111. package/lib/engine/wire/errors.mjs +496 -0
  112. package/lib/engine/wire/http.mjs +441 -0
  113. package/lib/engine/wire/index.mjs +76 -0
  114. package/lib/engine/wire/openai-chat.mjs +332 -0
  115. package/lib/engine/wire/prompt-cache.mjs +79 -0
  116. package/lib/engine/wire/search.mjs +140 -0
  117. package/lib/engine/wire/sse.mjs +114 -0
  118. package/lib/engine/wire/stall.mjs +349 -0
  119. package/lib/engine/wire/token-provider.mjs +175 -0
  120. package/lib/engine/wire/usage.mjs +192 -0
  121. package/lib/engine/workflow/host.mjs +524 -0
  122. package/lib/engine/workflow/journal.mjs +188 -0
  123. package/lib/engine/workflow/json-schema.mjs +171 -0
  124. package/lib/engine/workflow/meta.mjs +329 -0
  125. package/lib/engine/workflow/notifications.mjs +52 -0
  126. package/lib/engine/workflow/runtime.mjs +447 -0
  127. package/lib/engine/workflow/sandbox.mjs +534 -0
  128. package/lib/engine/workflow/worker.mjs +141 -0
  129. package/lib/engine/workflow/worktree.mjs +74 -0
  130. package/lib/execution/disposition.mjs +1 -1
  131. package/lib/execution/intake.mjs +10 -0
  132. package/lib/execution/surface-policy.mjs +15 -0
  133. package/lib/learning/curator.mjs +8 -6
  134. package/lib/learning/reflect.mjs +8 -6
  135. package/lib/model-router/catalog/cohort.yaml +137 -0
  136. package/lib/model-router/catalog.mjs +118 -1
  137. package/lib/model-router/failover.mjs +67 -16
  138. package/lib/model-router/llm-task.mjs +39 -3
  139. package/lib/model-router/resolve.mjs +89 -3
  140. package/lib/model-router/spawn.mjs +46 -47
  141. package/lib/model-router/taxonomy.mjs +126 -4
  142. package/lib/org/cost-sync.mjs +141 -11
  143. package/lib/org/inbound/broadcast.mjs +289 -0
  144. package/lib/org/inbound/collective.mjs +375 -0
  145. package/lib/org/inbound/directedness.mjs +96 -8
  146. package/lib/org/inbound/facts.mjs +78 -2
  147. package/lib/org/inbound/project.mjs +22 -0
  148. package/lib/org/inbound/surfaces.mjs +14 -0
  149. package/lib/org/llm-token.mjs +879 -0
  150. package/lib/org/mesh.mjs +61 -0
  151. package/lib/org/messaging.mjs +3 -1
  152. package/lib/org/protocol.checksum +1 -1
  153. package/lib/org/protocol.mjs +15 -0
  154. package/lib/org/quota.mjs +520 -0
  155. package/lib/org/tool-surface.mjs +104 -16
  156. package/lib/org/ui-parity.mjs +16 -1
  157. package/lib/org/work-ledger.mjs +37 -6
  158. package/lib/rate-guard.mjs +114 -1
  159. package/lib/resource-governor.mjs +41 -6
  160. package/lib/runtime/adapter.mjs +833 -0
  161. package/lib/runtime/child-env.mjs +191 -0
  162. package/lib/runtime/legacy-shell-guard.mjs +97 -0
  163. package/lib/runtime/seat-engine.mjs +162 -0
  164. package/lib/session/ask-ledger.mjs +271 -0
  165. package/lib/session/current-work.mjs +676 -0
  166. package/lib/session/feed-core.mjs +40 -3
  167. package/lib/session/launch-args.mjs +56 -4
  168. package/lib/session/status-summary.mjs +26 -9
  169. package/lib/session/upgrade-notice.mjs +42 -0
  170. package/lib/setup/claude-probe.mjs +117 -13
  171. package/lib/setup/enrich.mjs +13 -10
  172. package/lib/setup/sections/model.mjs +39 -13
  173. package/lib/telemetry/collect.mjs +229 -11
  174. package/lib/upgrade/ignored-drift.mjs +105 -0
  175. package/lib/voice/post-call-brief.mjs +30 -17
  176. package/package.json +13 -3
  177. package/plugins/maestro-skills/skills/board-work.md +5 -0
  178. package/plugins/maestro-skills/skills/inbound-triage.md +56 -15
  179. package/plugins/maestro-skills/skills/main-session.md +18 -7
  180. package/scaffold/config/collective.yaml +7 -0
  181. package/scripts/ci/check-durable-write-seam.mjs +3 -1
  182. package/scripts/ci/check-tarball-fidelity.mjs +126 -2
  183. package/scripts/ci/run-tests.mjs +47 -19
  184. package/scripts/cohort-llm/api-key-helper.mjs +92 -0
  185. package/scripts/collective/hook-runner.mjs +142 -19
  186. package/scripts/continuous-monitor.sh +13 -0
  187. package/scripts/cost/track-claude-usage.mjs +15 -0
  188. package/scripts/daemon/agent-daemon.mjs +408 -20
  189. package/scripts/daemon/assurance.mjs +48 -12
  190. package/scripts/daemon/cadence-consumer.mjs +218 -68
  191. package/scripts/daemon/cadence-handlers.mjs +73 -4
  192. package/scripts/daemon/classifier.mjs +75 -26
  193. package/scripts/daemon/context-compiler.mjs +51 -37
  194. package/scripts/daemon/deliver.mjs +30 -1
  195. package/scripts/daemon/dispatcher.mjs +595 -149
  196. package/scripts/daemon/health.mjs +14 -1
  197. package/scripts/daemon/maestro-daemon.mjs +11 -0
  198. package/scripts/daemon/prompt-builder.mjs +24 -0
  199. package/scripts/daemon/responder.mjs +246 -79
  200. package/scripts/daemon/sdk-version.mjs +98 -16
  201. package/scripts/eval/probe-gateway.mjs +635 -0
  202. package/scripts/eval/replay/extract.mjs +270 -0
  203. package/scripts/eval/replay/grade.mjs +260 -0
  204. package/scripts/eval/replay/lib/config.mjs +50 -0
  205. package/scripts/eval/replay/lib/effects.mjs +65 -0
  206. package/scripts/eval/replay/lib/fixture.mjs +188 -0
  207. package/scripts/eval/replay/lib/judge.mjs +72 -0
  208. package/scripts/eval/replay/lib/redact.mjs +136 -0
  209. package/scripts/eval/replay/lib/sandbox.mjs +170 -0
  210. package/scripts/eval/replay/lib/schema-check.mjs +63 -0
  211. package/scripts/eval/replay/lib/transcript.mjs +76 -0
  212. package/scripts/eval/replay/mcp-replay-stub.mjs +101 -0
  213. package/scripts/eval/replay/report.mjs +185 -0
  214. package/scripts/eval/replay/run.mjs +404 -0
  215. package/scripts/fleet/rollout.mjs +1151 -0
  216. package/scripts/hooks/pre-send-audit.sh +36 -245
  217. package/scripts/hooks/pre-write-yaml-validate.mjs +275 -0
  218. package/scripts/hooks/validate-state-yaml.sh +190 -0
  219. package/scripts/huddle/huddle-llm.mjs +361 -0
  220. package/scripts/huddle/huddle-server.mjs +46 -121
  221. package/scripts/local-triggers/autoupdate.sh +465 -81
  222. package/scripts/local-triggers/run-trigger.sh +13 -0
  223. package/scripts/maintenance/pin-integrity.mjs +364 -0
  224. package/scripts/poll-slack-events.sh +41 -9
  225. package/scripts/poller/slack-socket-mode.mjs +28 -3
  226. package/scripts/session/supervisor.mjs +80 -13
  227. package/scripts/spawn-session.sh +13 -0
  228. package/bin/maestro.test.mjs +0 -1574
  229. package/lib/action-executor.test.mjs +0 -871
  230. package/lib/archetype.test.mjs +0 -132
  231. package/lib/assurance/plan-note.test.mjs +0 -234
  232. package/lib/assurance/room-budget.test.mjs +0 -486
  233. package/lib/assurance/tier.test.mjs +0 -174
  234. package/lib/autonomy.test.mjs +0 -66
  235. package/lib/backlog.test.mjs +0 -302
  236. package/lib/backup/policy.test.mjs +0 -305
  237. package/lib/budget-escalate.test.mjs +0 -232
  238. package/lib/budget-guard.envelope.test.mjs +0 -476
  239. package/lib/budget-guard.test.mjs +0 -427
  240. package/lib/cadence-bus-requeue.test.mjs +0 -83
  241. package/lib/cadence-bus-schedule.test.mjs +0 -194
  242. package/lib/cadence-bus.test.mjs +0 -720
  243. package/lib/cadences.test.mjs +0 -230
  244. package/lib/capability/inventory.test.mjs +0 -232
  245. package/lib/capability.test.mjs +0 -78
  246. package/lib/channels/base-adapter.test.mjs +0 -590
  247. package/lib/channels/channels.test.mjs +0 -371
  248. package/lib/channels/contract.test.mjs +0 -162
  249. package/lib/channels/inbox-item.test.mjs +0 -368
  250. package/lib/channels/orgmail/adapter.test.mjs +0 -448
  251. package/lib/channels/pairing.test.mjs +0 -270
  252. package/lib/channels/repeat-suppressor.test.mjs +0 -134
  253. package/lib/channels/slack-adapter.test.mjs +0 -212
  254. package/lib/channels/telegram-adapter.test.mjs +0 -306
  255. package/lib/channels/voice/adapter.test.mjs +0 -278
  256. package/lib/channels/whatsapp/adapter-baileys.test.mjs +0 -359
  257. package/lib/channels/whatsapp/baileys-typing.test.mjs +0 -154
  258. package/lib/charter.test.mjs +0 -89
  259. package/lib/claude-bin.test.mjs +0 -131
  260. package/lib/cli/board.test.mjs +0 -227
  261. package/lib/cli/design.test.mjs +0 -270
  262. package/lib/cli/doctor-checks.test.mjs +0 -336
  263. package/lib/cli/global-setup-extras.test.mjs +0 -462
  264. package/lib/cli/inbox.test.mjs +0 -230
  265. package/lib/cli/session-ack.test.mjs +0 -63
  266. package/lib/cli/session.test.mjs +0 -613
  267. package/lib/collective/capture.test.mjs +0 -121
  268. package/lib/collective/cards.test.mjs +0 -114
  269. package/lib/collective/config.test.mjs +0 -123
  270. package/lib/collective/global-config.test.mjs +0 -220
  271. package/lib/collective/global-skills.test.mjs +0 -126
  272. package/lib/collective/presence.test.mjs +0 -95
  273. package/lib/collective/recall.test.mjs +0 -116
  274. package/lib/collective/vendor-skills.test.mjs +0 -306
  275. package/lib/comms/send-gate.test.mjs +0 -770
  276. package/lib/comms.test.mjs +0 -41
  277. package/lib/context/budget.test.mjs +0 -252
  278. package/lib/context/history-scope.test.mjs +0 -79
  279. package/lib/cost/ledger-row.test.mjs +0 -183
  280. package/lib/design/design-md.test.mjs +0 -318
  281. package/lib/design/fixtures/DESIGN.golden.md +0 -238
  282. package/lib/design/fixtures/PRODUCT.golden.md +0 -67
  283. package/lib/design/fixtures/foundation.json +0 -133
  284. package/lib/design/refresh-gate.test.mjs +0 -144
  285. package/lib/design/write.test.mjs +0 -241
  286. package/lib/diagnostics/alerts.test.mjs +0 -318
  287. package/lib/diagnostics/backup-freshness.test.mjs +0 -185
  288. package/lib/diagnostics/counters.test.mjs +0 -206
  289. package/lib/diagnostics/events.test.mjs +0 -290
  290. package/lib/diagnostics/otel.test.mjs +0 -196
  291. package/lib/diagnostics/trace.test.mjs +0 -251
  292. package/lib/env-compat.test.mjs +0 -104
  293. package/lib/execution/disposition.test.mjs +0 -553
  294. package/lib/execution/drive.test.mjs +0 -270
  295. package/lib/execution/effects.test.mjs +0 -344
  296. package/lib/execution/intake.test.mjs +0 -389
  297. package/lib/execution/journal.test.mjs +0 -261
  298. package/lib/execution/match.test.mjs +0 -235
  299. package/lib/execution/pipeline.test.mjs +0 -392
  300. package/lib/execution/route.test.mjs +0 -186
  301. package/lib/execution/surface-policy.test.mjs +0 -162
  302. package/lib/fs-atomic.test.mjs +0 -72
  303. package/lib/fs-ownership.test.mjs +0 -158
  304. package/lib/goals/admission.test.mjs +0 -164
  305. package/lib/goals/classify.test.mjs +0 -167
  306. package/lib/goals/collaborate.test.mjs +0 -336
  307. package/lib/goals/gaps.test.mjs +0 -284
  308. package/lib/goals/loop.test.mjs +0 -845
  309. package/lib/hooks/bus.test.mjs +0 -387
  310. package/lib/identity/persona.test.mjs +0 -142
  311. package/lib/kpi-sensors.test.mjs +0 -278
  312. package/lib/kpi.test.mjs +0 -244
  313. package/lib/learning/config.test.mjs +0 -75
  314. package/lib/learning/counters.test.mjs +0 -69
  315. package/lib/learning/curator-consolidate.test.mjs +0 -238
  316. package/lib/learning/curator.test.mjs +0 -106
  317. package/lib/learning/reflect.test.mjs +0 -0
  318. package/lib/learning/session-index.test.mjs +0 -125
  319. package/lib/learning/skill-writer.test.mjs +0 -210
  320. package/lib/mandate/audit.test.mjs +0 -195
  321. package/lib/mandate/contract.test.mjs +0 -185
  322. package/lib/mandate/derive.test.mjs +0 -274
  323. package/lib/mandate/model.test.mjs +0 -164
  324. package/lib/mandate/refresh.test.mjs +0 -389
  325. package/lib/mcp/server.test.mjs +0 -426
  326. package/lib/model-router/auth-profiles.test.mjs +0 -580
  327. package/lib/model-router/catalog.test.mjs +0 -385
  328. package/lib/model-router/economics.test.mjs +0 -438
  329. package/lib/model-router/failover.test.mjs +0 -439
  330. package/lib/model-router/health.test.mjs +0 -338
  331. package/lib/model-router/integration-coverage.test.mjs +0 -831
  332. package/lib/model-router/integration.test.mjs +0 -564
  333. package/lib/model-router/ledger.test.mjs +0 -415
  334. package/lib/model-router/llm-task.test.mjs +0 -392
  335. package/lib/model-router/org-credentials.test.mjs +0 -265
  336. package/lib/model-router/pricing-refresh.test.mjs +0 -286
  337. package/lib/model-router/reconcile.test.mjs +0 -316
  338. package/lib/model-router/repair.test.mjs +0 -180
  339. package/lib/model-router/spawn.test.mjs +0 -446
  340. package/lib/model-router/taxonomy.test.mjs +0 -410
  341. package/lib/model-router.test.mjs +0 -1207
  342. package/lib/org/activity.test.mjs +0 -134
  343. package/lib/org/approvals.test.mjs +0 -216
  344. package/lib/org/awareness.test.mjs +0 -159
  345. package/lib/org/board-mine-cache.test.mjs +0 -53
  346. package/lib/org/board.test.mjs +0 -187
  347. package/lib/org/bootstrap-context.test.mjs +0 -153
  348. package/lib/org/client.test.mjs +0 -1206
  349. package/lib/org/cohort-client.test.mjs +0 -126
  350. package/lib/org/cost-sync.test.mjs +0 -153
  351. package/lib/org/doctor.test.mjs +0 -346
  352. package/lib/org/engagement-ledger.test.mjs +0 -112
  353. package/lib/org/engagement.test.mjs +0 -739
  354. package/lib/org/handoff.test.mjs +0 -269
  355. package/lib/org/inbound/directedness.test.mjs +0 -668
  356. package/lib/org/inbound/facts.test.mjs +0 -471
  357. package/lib/org/inbound/hydrate.test.mjs +0 -908
  358. package/lib/org/inbound/index.test.mjs +0 -429
  359. package/lib/org/inbound/project.test.mjs +0 -287
  360. package/lib/org/integration-tools.test.mjs +0 -160
  361. package/lib/org/keys.test.mjs +0 -92
  362. package/lib/org/knowledge.test.mjs +0 -326
  363. package/lib/org/leases.test.mjs +0 -235
  364. package/lib/org/mesh-directives.test.mjs +0 -110
  365. package/lib/org/mesh-integration.test.mjs +0 -127
  366. package/lib/org/mesh.test.mjs +0 -400
  367. package/lib/org/messaging.test.mjs +0 -471
  368. package/lib/org/param-contract.test.mjs +0 -477
  369. package/lib/org/policy.test.mjs +0 -237
  370. package/lib/org/protocol.checksum.test.mjs +0 -90
  371. package/lib/org/protocol.test.mjs +0 -323
  372. package/lib/org/push.test.mjs +0 -792
  373. package/lib/org/registry.test.mjs +0 -100
  374. package/lib/org/resource-tools.test.mjs +0 -361
  375. package/lib/org/tool-access.test.mjs +0 -144
  376. package/lib/org/tool-surface-integration.test.mjs +0 -120
  377. package/lib/org/tool-surface.test.mjs +0 -1268
  378. package/lib/org/typing.test.mjs +0 -291
  379. package/lib/org/ui-parity.test.mjs +0 -560
  380. package/lib/org/verify.test.mjs +0 -194
  381. package/lib/org/work-ledger.test.mjs +0 -273
  382. package/lib/plan/adoption-e2e.test.mjs +0 -366
  383. package/lib/plan/budget-enforcement.test.mjs +0 -400
  384. package/lib/plan/compile.test.mjs +0 -382
  385. package/lib/plan/emit.test.mjs +0 -269
  386. package/lib/plan/explain.test.mjs +0 -188
  387. package/lib/prompts/parallelism.test.mjs +0 -177
  388. package/lib/rag/rag.test.mjs +0 -505
  389. package/lib/rate-guard.test.mjs +0 -272
  390. package/lib/reactive-gate.test.mjs +0 -57
  391. package/lib/render.test.mjs +0 -68
  392. package/lib/resource-governor.test.mjs +0 -488
  393. package/lib/scheduling/dynamic-jobs.test.mjs +0 -344
  394. package/lib/scheduling/jitter.test.mjs +0 -140
  395. package/lib/secrets/broker.test.mjs +0 -280
  396. package/lib/secrets/providers.test.mjs +0 -274
  397. package/lib/security/audit-engine.test.mjs +0 -424
  398. package/lib/security/coerce-args.test.mjs +0 -281
  399. package/lib/security/dangerous-tools.test.mjs +0 -68
  400. package/lib/security/external-content.test.mjs +0 -84
  401. package/lib/security/redact.test.mjs +0 -441
  402. package/lib/security/secret-equal.test.mjs +0 -55
  403. package/lib/session/config.test.mjs +0 -92
  404. package/lib/session/feed-core.test.mjs +0 -198
  405. package/lib/session/first-run.test.mjs +0 -121
  406. package/lib/session/frontdoor.test.mjs +0 -205
  407. package/lib/session/handoffs.test.mjs +0 -183
  408. package/lib/session/identity.test.mjs +0 -180
  409. package/lib/session/inbox-claims.test.mjs +0 -286
  410. package/lib/session/launch-args.test.mjs +0 -157
  411. package/lib/session/liveness.test.mjs +0 -100
  412. package/lib/session/status-summary.test.mjs +0 -118
  413. package/lib/session-permissions.test.mjs +0 -120
  414. package/lib/setup/claude-probe.test.mjs +0 -187
  415. package/lib/setup/completeness.test.mjs +0 -110
  416. package/lib/setup/context-pack.test.mjs +0 -89
  417. package/lib/setup/enrich.test.mjs +0 -115
  418. package/lib/setup/enroll-from-cohort.test.mjs +0 -300
  419. package/lib/setup/integration.test.mjs +0 -162
  420. package/lib/setup/io.test.mjs +0 -77
  421. package/lib/setup/runner.test.mjs +0 -132
  422. package/lib/setup/sections/identity.test.mjs +0 -234
  423. package/lib/setup/sections/inventory.test.mjs +0 -198
  424. package/lib/setup/sections/learning.test.mjs +0 -81
  425. package/lib/setup/sections/mandate.test.mjs +0 -388
  426. package/lib/setup/sections/messaging.test.mjs +0 -127
  427. package/lib/setup/sections/model.test.mjs +0 -240
  428. package/lib/setup/sections/org.test.mjs +0 -346
  429. package/lib/setup/sections/orgmail.test.mjs +0 -118
  430. package/lib/setup/sections/recovery.test.mjs +0 -98
  431. package/lib/setup/sections/subagents.test.mjs +0 -429
  432. package/lib/setup/sections/verify.test.mjs +0 -175
  433. package/lib/setup/sot.test.mjs +0 -81
  434. package/lib/setup/state.test.mjs +0 -115
  435. package/lib/singleton.test.mjs +0 -151
  436. package/lib/subagents/cli.test.mjs +0 -389
  437. package/lib/subagents/client.test.mjs +0 -309
  438. package/lib/subagents/gap.test.mjs +0 -234
  439. package/lib/subagents/lock.test.mjs +0 -248
  440. package/lib/subagents/manifest.test.mjs +0 -175
  441. package/lib/subagents/refs.test.mjs +0 -204
  442. package/lib/subagents/resolve.test.mjs +0 -422
  443. package/lib/subagents/schema.test.mjs +0 -328
  444. package/lib/telemetry/alerts.test.mjs +0 -109
  445. package/lib/telemetry/collect.test.mjs +0 -1274
  446. package/lib/tool-definitions-integration.test.mjs +0 -83
  447. package/lib/tool-definitions.test.mjs +0 -437
  448. package/lib/upgrade/global-refresh.test.mjs +0 -65
  449. package/lib/upgrade/launchd-reconcile.test.mjs +0 -272
  450. package/lib/upgrade/post-steps.test.mjs +0 -200
  451. package/lib/upgrade/verify.test.mjs +0 -164
  452. package/lib/util/fetch-timeout.test.mjs +0 -202
  453. package/lib/util/reconnect.test.mjs +0 -369
  454. package/lib/util/unhandled.test.mjs +0 -216
  455. package/lib/voice/outbound.test.mjs +0 -69
  456. package/lib/voice/session-rotation.test.mjs +0 -114
  457. package/lib/voice/stt.test.mjs +0 -226
  458. package/lib/voice/voice.test.mjs +0 -990
  459. package/scripts/cadence/enqueue-cadence-tick.test.mjs +0 -187
  460. package/scripts/ci/check-docs-accuracy.test.mjs +0 -409
  461. package/scripts/ci/check-durable-write-seam.test.mjs +0 -90
  462. package/scripts/ci/check-no-build-artifacts.test.mjs +0 -71
  463. package/scripts/ci/check-no-residual-identity.test.mjs +0 -202
  464. package/scripts/ci/check-skill-packs.test.mjs +0 -495
  465. package/scripts/ci/check-subagent-frontmatter.test.mjs +0 -124
  466. package/scripts/ci/check.test.mjs +0 -194
  467. package/scripts/ci/conformance-org-api.test.mjs +0 -425
  468. package/scripts/cloud-relay/voice/relay-identity.test.mjs +0 -96
  469. package/scripts/collective/hook-runner.test.mjs +0 -173
  470. package/scripts/cost/fleet-digest.test.mjs +0 -207
  471. package/scripts/cost/track-claude-usage-pricing.test.mjs +0 -183
  472. package/scripts/cost/track-claude-usage.test.mjs +0 -148
  473. package/scripts/daemon/agent-daemon-board-mine.test.mjs +0 -96
  474. package/scripts/daemon/agent-daemon-design.test.mjs +0 -238
  475. package/scripts/daemon/agent-daemon-frontdoor.test.mjs +0 -60
  476. package/scripts/daemon/agent-daemon.test.mjs +0 -995
  477. package/scripts/daemon/assurance-e2e.test.mjs +0 -613
  478. package/scripts/daemon/assurance.test.mjs +0 -1791
  479. package/scripts/daemon/board-mirror.test.mjs +0 -165
  480. package/scripts/daemon/cadence-consumer-frontdoor.test.mjs +0 -393
  481. package/scripts/daemon/cadence-consumer-governance.test.mjs +0 -276
  482. package/scripts/daemon/cadence-consumer.test.mjs +0 -776
  483. package/scripts/daemon/cadence-handlers.test.mjs +0 -837
  484. package/scripts/daemon/classifier-identity.test.mjs +0 -137
  485. package/scripts/daemon/classifier.test.mjs +0 -266
  486. package/scripts/daemon/classify-kind.test.mjs +0 -40
  487. package/scripts/daemon/context-compiler.test.mjs +0 -406
  488. package/scripts/daemon/deliver.test.mjs +0 -564
  489. package/scripts/daemon/dispatcher-cooldown.test.mjs +0 -122
  490. package/scripts/daemon/dispatcher-governance.test.mjs +0 -1013
  491. package/scripts/daemon/dispatcher-resume.test.mjs +0 -166
  492. package/scripts/daemon/dispatcher-session-continuity.test.mjs +0 -365
  493. package/scripts/daemon/execution-ladder.test.mjs +0 -470
  494. package/scripts/daemon/goal-steward-cadence.test.mjs +0 -312
  495. package/scripts/daemon/inbox-deferral-session.test.mjs +0 -49
  496. package/scripts/daemon/inbox-deferral.test.mjs +0 -336
  497. package/scripts/daemon/inbox-wake.test.mjs +0 -199
  498. package/scripts/daemon/integration.test.mjs +0 -149
  499. package/scripts/daemon/lib/self-echo.test.mjs +0 -153
  500. package/scripts/daemon/lib/session-router.test.mjs +0 -554
  501. package/scripts/daemon/prompt-builder-preamble.test.mjs +0 -210
  502. package/scripts/daemon/prompt-builder.test.mjs +0 -556
  503. package/scripts/daemon/responder-cost.test.mjs +0 -68
  504. package/scripts/daemon/responder-history.test.mjs +0 -221
  505. package/scripts/daemon/sdk-version.test.mjs +0 -31
  506. package/scripts/daemon/session-lock.test.mjs +0 -252
  507. package/scripts/daemon/session-outcomes.test.mjs +0 -533
  508. package/scripts/daemon/typing-registry.test.mjs +0 -102
  509. package/scripts/hooks/pre-send-audit.test.mjs +0 -354
  510. package/scripts/huddle/huddle-prompt.test.mjs +0 -176
  511. package/scripts/local-triggers/autoupdate.test.mjs +0 -518
  512. package/scripts/local-triggers/generate-plists.test.mjs +0 -456
  513. package/scripts/media-generation/brand-clause.test.mjs +0 -135
  514. package/scripts/org/send-orgmail.first-contact.test.mjs +0 -102
  515. package/scripts/poller/inbox-privilege-injection.test.mjs +0 -167
  516. package/scripts/poller/inbox-scan-poller.test.mjs +0 -295
  517. package/scripts/poller/lib/cloud-relay-dedup.test.mjs +0 -133
  518. package/scripts/poller/slack-socket-mode.test.mjs +0 -805
  519. package/scripts/poller-launchd/install.test.mjs +0 -243
  520. package/scripts/restore-from-backup.test.mjs +0 -181
  521. package/scripts/session/feed.test.mjs +0 -196
  522. package/scripts/session/supervisor-sh.test.mjs +0 -218
  523. package/scripts/session/supervisor.test.mjs +0 -482
  524. package/scripts/setup/configure-macos.test.mjs +0 -306
  525. package/scripts/setup/gen-subagent-manifest.test.mjs +0 -124
  526. package/scripts/setup/generate-agent-package-json.test.mjs +0 -143
  527. package/scripts/setup/generate-capability.test.mjs +0 -134
  528. package/scripts/setup/init-agent.test.mjs +0 -370
  529. package/scripts/setup/init-skill-marketplace.test.mjs +0 -193
  530. package/scripts/vendor/sync-skill-packs.test.mjs +0 -103
  531. package/scripts/watchdog/memory-watchdog.test.mjs +0 -64
@@ -1,272 +0,0 @@
1
- /**
2
- * launchd-reconcile.test.mjs — the pure plist reconcile planner + the edge
3
- * applier with a recorded `exec` (design 2026-09-08, WP-M6 step 2).
4
- */
5
-
6
- import { test } from "node:test";
7
- import assert from "node:assert/strict";
8
- import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, statSync, rmSync } from "node:fs";
9
- import { join } from "node:path";
10
- import { tmpdir } from "node:os";
11
- import {
12
- planLaunchdReconcile, applyLaunchdReconcile, readLaunchdState, readLoadedLabels, readHoldReason,
13
- parseLaunchctlList, parseLaunchctlPrintServices, labelOf, REWRITE_ONLY_NOTE,
14
- } from "./launchd-reconcile.mjs";
15
-
16
- const G = ["ai.maestro.ivy-daemon", "ai.maestro.ivy-session", "ai.maestro.ivy-autoupdate", "ai.maestro.ivy-inbox-processor"];
17
-
18
- function byLabel(plan) {
19
- const m = {};
20
- for (const a of plan.actions) m[a.label] = a;
21
- return m;
22
- }
23
-
24
- test("first hop: the -session job is generated but not installed → install (bootstrap); the rest unchanged", () => {
25
- const plan = planLaunchdReconcile({
26
- generated: G,
27
- installed: ["ai.maestro.ivy-daemon", "ai.maestro.ivy-autoupdate", "ai.maestro.ivy-inbox-processor"],
28
- loaded: ["ai.maestro.ivy-daemon", "ai.maestro.ivy-autoupdate", "ai.maestro.ivy-inbox-processor"],
29
- sameContent: () => true,
30
- });
31
- const m = byLabel(plan);
32
- assert.equal(m["ai.maestro.ivy-session"].action, "install");
33
- assert.equal(m["ai.maestro.ivy-session"].bootstrap, true);
34
- assert.equal(m["ai.maestro.ivy-daemon"].action, "unchanged");
35
- assert.equal(m["ai.maestro.ivy-inbox-processor"].action, "unchanged");
36
- assert.deepEqual(plan.summary, { install: 1, replace: 0, load: 0, unchanged: 3, orphan: 0, held: 0 });
37
- assert.equal(plan.hold, null);
38
- });
39
-
40
- test("content differs while loaded: EVERY label is rewritten only — no kickstart, ever (launchd does not re-read a rewritten plist; -autoupdate is the job this upgrade runs inside)", () => {
41
- const plan = planLaunchdReconcile({ generated: G, installed: G, loaded: G, sameContent: () => false });
42
- const m = byLabel(plan);
43
- for (const l of G) {
44
- assert.equal(m[l].action, "replace", l);
45
- assert.equal(m[l].bootstrap, false, `${l} is loaded: no bootstrap`);
46
- assert.equal("restart" in m[l], false, "the plan has no restart concept at all");
47
- assert.match(m[l].reason, /content differs; file rewritten; launchd keeps the loaded definition until next login/);
48
- }
49
- assert.ok(!JSON.stringify(plan).includes("kickstart"), "nothing in the plan says kickstart");
50
- assert.deepEqual(plan.summary, { install: 0, replace: 4, load: 0, unchanged: 0, orphan: 0, held: 0 });
51
- assert.match(REWRITE_ONLY_NOTE, /bootout gui\/<uid>\/<label> && launchctl bootstrap/);
52
- });
53
-
54
- test("hold (emergency stop / kill-switch): files are still written but NOTHING is bootstrapped; every held row names the reason", () => {
55
- const plan = planLaunchdReconcile({
56
- generated: G, installed: ["ai.maestro.ivy-daemon", "ai.maestro.ivy-autoupdate"], loaded: [],
57
- sameContent: (l) => l === "ai.maestro.ivy-daemon", hold: "emergency stop (.emergency-stop)",
58
- });
59
- const m = byLabel(plan);
60
- assert.equal(m["ai.maestro.ivy-session"].action, "install");
61
- assert.equal(m["ai.maestro.ivy-session"].bootstrap, false);
62
- assert.equal(m["ai.maestro.ivy-session"].held, true);
63
- assert.match(m["ai.maestro.ivy-session"].reason, /held: emergency stop \(\.emergency-stop\)/);
64
- assert.equal(m["ai.maestro.ivy-autoupdate"].action, "replace");
65
- assert.equal(m["ai.maestro.ivy-autoupdate"].bootstrap, false);
66
- assert.equal(m["ai.maestro.ivy-daemon"].action, "load");
67
- assert.equal(m["ai.maestro.ivy-daemon"].bootstrap, false);
68
- assert.ok(plan.actions.every((a) => a.bootstrap === false));
69
- assert.equal(plan.summary.held, 4);
70
- assert.equal(plan.hold, "emergency stop (.emergency-stop)");
71
- });
72
-
73
- test("installed but not loaded → bootstrap (same content: load; different: replace + bootstrap)", () => {
74
- const plan = planLaunchdReconcile({
75
- generated: G, installed: G, loaded: ["ai.maestro.ivy-daemon"],
76
- sameContent: (l) => l !== "ai.maestro.ivy-session",
77
- });
78
- const m = byLabel(plan);
79
- assert.equal(m["ai.maestro.ivy-inbox-processor"].action, "load");
80
- assert.equal(m["ai.maestro.ivy-inbox-processor"].bootstrap, true);
81
- assert.equal(m["ai.maestro.ivy-session"].action, "replace");
82
- assert.equal(m["ai.maestro.ivy-session"].bootstrap, true);
83
- assert.equal(m["ai.maestro.ivy-daemon"].action, "unchanged");
84
- });
85
-
86
- test("an installed maestro label that is no longer generated is an orphan: reported, never booted out; foreign labels are ignored", () => {
87
- const plan = planLaunchdReconcile({
88
- generated: ["ai.maestro.ivy-daemon"],
89
- installed: ["ai.maestro.ivy-daemon", "ai.maestro.ivy-boot-claude-session", "ai.adaptic.ivy-old", "com.apple.something"],
90
- loaded: ["ai.maestro.ivy-daemon"], sameContent: () => true,
91
- });
92
- const orphans = plan.actions.filter((a) => a.action === "orphan").map((a) => a.label).sort();
93
- assert.deepEqual(orphans, ["ai.adaptic.ivy-old", "ai.maestro.ivy-boot-claude-session"]);
94
- assert.ok(!plan.actions.some((a) => a.label === "com.apple.something"));
95
- assert.ok(plan.actions.every((a) => a.action !== "bootout"));
96
- });
97
-
98
- test("a throwing sameContent is treated as 'different' (rewrite is the safe direction); .plist suffixes are normalised", () => {
99
- const plan = planLaunchdReconcile({ generated: ["ai.maestro.ivy-daemon.plist"], installed: ["ai.maestro.ivy-daemon.plist"], loaded: ["ai.maestro.ivy-daemon"], sameContent: () => { throw new Error("EACCES"); } });
100
- assert.equal(plan.actions[0].action, "replace");
101
- assert.equal(plan.actions[0].bootstrap, false, "loaded → rewrite only");
102
- assert.equal(labelOf("x.plist"), "x");
103
- });
104
-
105
- test("parseLaunchctlPrintServices: the labels inside `services = { … }` of `launchctl print gui/<uid>`; null without that block", () => {
106
- const out = [
107
- "gui/501 = {", "\ttype = gui", "\thandle = 501",
108
- "\tservices = {",
109
- "\t\t 46859 - \tapplication.com.microsoft.VSCode.590407.590413",
110
- "\t\t 0 0 \tai.maestro.ivy-inbox-processor",
111
- "\t\t 4242 - \tai.maestro.ivy-daemon",
112
- "\t}",
113
- "\tdisabled services = {", "\t\t\"ai.maestro.ivy-old\" => disabled", "\t}", "}", "",
114
- ].join("\n");
115
- assert.deepEqual(parseLaunchctlPrintServices(out), ["application.com.microsoft.VSCode.590407.590413", "ai.maestro.ivy-inbox-processor", "ai.maestro.ivy-daemon"]);
116
- assert.equal(parseLaunchctlPrintServices("Could not find domain for gui/501\n"), null);
117
- assert.equal(parseLaunchctlPrintServices(""), null);
118
- });
119
-
120
- test("readLoadedLabels: `launchctl print gui/<uid>` is the source of truth; `launchctl list` only when print is unavailable", () => {
121
- const print = { status: 0, stdout: "gui/501 = {\n\tservices = {\n\t\t0\t0\tai.maestro.ivy-daemon\n\t}\n}\n" };
122
- const list = { status: 0, stdout: "PID\tStatus\tLabel\n" }; // what ssh sees: no gui-domain agents
123
- const both = (cmd, args) => (args[0] === "print" ? print : list);
124
- assert.deepEqual(readLoadedLabels({ exec: both, uid: 501 }), { loaded: ["ai.maestro.ivy-daemon"], ok: true, via: "print" });
125
- const calls = [];
126
- const noPrint = (cmd, args) => { calls.push(args.join(" ")); return args[0] === "print" ? { status: 1, stdout: "", stderr: "Bad request." } : { status: 0, stdout: "PID\tStatus\tLabel\n1\t0\tai.maestro.ivy-daemon\n" }; };
127
- assert.deepEqual(readLoadedLabels({ exec: noPrint, uid: 501 }), { loaded: ["ai.maestro.ivy-daemon"], ok: true, via: "list" });
128
- assert.deepEqual(calls, ["print gui/501", "list"]);
129
- assert.deepEqual(readLoadedLabels({ exec: () => ({ status: 127, stdout: "", stderr: "not found" }), uid: 501 }), { loaded: [], ok: false, via: "none" });
130
- });
131
-
132
- test("readHoldReason: .emergency-stop, state/EMERGENCY_STOP and the two kill-switch files each hold; a clean seat does not", () => {
133
- const root = mkdtempSync(join(tmpdir(), "launchd-hold-"));
134
- try {
135
- const cwd = join(root, "agent"); const home = join(root, "home");
136
- mkdirSync(join(cwd, "state"), { recursive: true }); mkdirSync(home, { recursive: true });
137
- assert.equal(readHoldReason({ cwd, home }), null);
138
- writeFileSync(join(home, ".maestro-no-autoupdate"), ""); assert.match(readHoldReason({ cwd, home }), /kill-switch \(~\/\.maestro-no-autoupdate\)/);
139
- writeFileSync(join(cwd, "state", "EMERGENCY_STOP"), ""); assert.match(readHoldReason({ cwd, home }), /emergency stop \(state\/EMERGENCY_STOP\)/);
140
- writeFileSync(join(cwd, ".emergency-stop"), ""); assert.match(readHoldReason({ cwd, home }), /emergency stop \(\.emergency-stop\)/, "the emergency stop outranks the kill-switch in the message");
141
- rmSync(join(cwd, ".emergency-stop")); rmSync(join(cwd, "state", "EMERGENCY_STOP")); rmSync(join(home, ".maestro-no-autoupdate"));
142
- writeFileSync(join(cwd, ".no-autoupdate"), ""); assert.match(readHoldReason({ cwd, home }), /kill-switch \(\.no-autoupdate\)/);
143
- } finally { rmSync(root, { recursive: true, force: true }); }
144
- });
145
-
146
- test("parseLaunchctlList: last column is the label; the header row is dropped; PID '-' still counts as loaded", () => {
147
- const out = "PID\tStatus\tLabel\n4242\t0\tai.maestro.ivy-daemon\n-\t0\tai.maestro.ivy-inbox-processor\n";
148
- assert.deepEqual(parseLaunchctlList(out), ["ai.maestro.ivy-daemon", "ai.maestro.ivy-inbox-processor"]);
149
- assert.deepEqual(parseLaunchctlList(""), []);
150
- });
151
-
152
- // ---------------------------------------------------------------------------
153
- // applyLaunchdReconcile — the edge, with a recorded exec
154
- // ---------------------------------------------------------------------------
155
-
156
- function fx() {
157
- const root = mkdtempSync(join(tmpdir(), "launchd-reconcile-"));
158
- const generatedDir = join(root, "plists");
159
- const launchAgentsDir = join(root, "LaunchAgents");
160
- mkdirSync(generatedDir, { recursive: true });
161
- mkdirSync(launchAgentsDir, { recursive: true });
162
- return { root, generatedDir, launchAgentsDir };
163
- }
164
-
165
- /** A launchctl/launchd double: `loaded` answers `print gui/<uid>` (the services block) and `print gui/<uid>/<label>`. */
166
- function recorder(responses = {}, { loaded = [] } = {}) {
167
- const calls = [];
168
- const exec = (cmd, args) => {
169
- calls.push([cmd, ...args]);
170
- const key = `${cmd} ${args.slice(0, 2).join(" ")}`;
171
- for (const [k, v] of Object.entries(responses)) if (key.startsWith(k)) return typeof v === "function" ? v(args) : v;
172
- if (cmd === "launchctl" && args[0] === "print") {
173
- const parts = String(args[1]).split("/");
174
- if (parts.length === 2) return { status: 0, stdout: `gui/501 = {\n\tservices = {\n${loaded.map((l) => `\t\t0\t0\t${l}`).join("\n")}\n\t}\n}\n`, stderr: "" };
175
- return loaded.includes(parts[2]) ? { status: 0, stdout: `${parts[2]} = {\n\tstate = running\n}\n`, stderr: "" } : { status: 113, stdout: "", stderr: `Could not find service "${parts[2]}" in domain for user gui: 501` };
176
- }
177
- return { status: 0, stdout: "", stderr: "" };
178
- };
179
- exec.calls = calls;
180
- return exec;
181
- }
182
-
183
- test("apply: install copies the plist with mode 600 and bootstraps gui/<uid>; a changed loaded job (cadence, -autoupdate, -daemon alike) is rewritten and never kickstarted", () => {
184
- const f = fx();
185
- try {
186
- writeFileSync(join(f.generatedDir, "ai.maestro.ivy-session.plist"), "<plist>session</plist>");
187
- writeFileSync(join(f.generatedDir, "ai.maestro.ivy-inbox-processor.plist"), "<plist>new</plist>");
188
- writeFileSync(join(f.launchAgentsDir, "ai.maestro.ivy-inbox-processor.plist"), "<plist>old</plist>");
189
- writeFileSync(join(f.generatedDir, "ai.maestro.ivy-autoupdate.plist"), "<plist>au-new</plist>");
190
- writeFileSync(join(f.launchAgentsDir, "ai.maestro.ivy-autoupdate.plist"), "<plist>au-old</plist>");
191
- writeFileSync(join(f.generatedDir, "ai.maestro.ivy-daemon.plist"), "<plist>daemon-new</plist>");
192
- writeFileSync(join(f.launchAgentsDir, "ai.maestro.ivy-daemon.plist"), "<plist>daemon-old</plist>");
193
- const exec = recorder({}, { loaded: ["ai.maestro.ivy-inbox-processor", "ai.maestro.ivy-autoupdate", "ai.maestro.ivy-daemon"] });
194
- const state = readLaunchdState({ ...f, exec, uid: 501 });
195
- assert.equal(state.loadedVia, "print");
196
- assert.deepEqual(state.generated.sort(), ["ai.maestro.ivy-autoupdate", "ai.maestro.ivy-daemon", "ai.maestro.ivy-inbox-processor", "ai.maestro.ivy-session"]);
197
- const plan = planLaunchdReconcile(state);
198
- const r = applyLaunchdReconcile({ plan, ...f, uid: 501, exec });
199
- assert.equal(r.ok, true, JSON.stringify(r.results));
200
-
201
- const dst = join(f.launchAgentsDir, "ai.maestro.ivy-session.plist");
202
- assert.ok(existsSync(dst));
203
- assert.equal(statSync(dst).mode & 0o777, 0o600);
204
- assert.equal(readFileSync(join(f.launchAgentsDir, "ai.maestro.ivy-inbox-processor.plist"), "utf8"), "<plist>new</plist>");
205
- assert.equal(readFileSync(join(f.launchAgentsDir, "ai.maestro.ivy-autoupdate.plist"), "utf8"), "<plist>au-new</plist>");
206
- assert.equal(readFileSync(join(f.launchAgentsDir, "ai.maestro.ivy-daemon.plist"), "utf8"), "<plist>daemon-new</plist>");
207
-
208
- const calls = exec.calls.map((c) => c.join(" "));
209
- assert.ok(calls.includes(`launchctl bootstrap gui/501 ${dst}`), calls.join("\n"));
210
- assert.ok(!calls.some((c) => /kickstart/.test(c)), `nothing is ever kickstarted: ${calls.join("\n")}`);
211
- assert.ok(!calls.some((c) => /bootout|unload/.test(c)));
212
- assert.ok(!calls.some((c) => /^launchctl load/.test(c)), "bootstrap succeeded → no domain-less load");
213
- const rows = Object.fromEntries(r.results.map((x) => [x.label, x]));
214
- assert.match(rows["ai.maestro.ivy-autoupdate"].detail, /replaced \(file only\)/);
215
- assert.match(rows["ai.maestro.ivy-inbox-processor"].detail, /until next login/);
216
- } finally { rmSync(f.root, { recursive: true, force: true }); }
217
- });
218
-
219
- test("apply: held seat — the session plist is written (600) but no launchctl bootstrap/load happens, and the row says why", () => {
220
- const f = fx();
221
- try {
222
- writeFileSync(join(f.generatedDir, "ai.maestro.ivy-session.plist"), "<plist>session</plist>");
223
- const exec = recorder();
224
- const plan = planLaunchdReconcile({ generated: ["ai.maestro.ivy-session"], installed: [], loaded: [], hold: "emergency stop (.emergency-stop)" });
225
- const r = applyLaunchdReconcile({ plan, ...f, uid: 501, exec });
226
- assert.equal(r.ok, true);
227
- const dst = join(f.launchAgentsDir, "ai.maestro.ivy-session.plist");
228
- assert.ok(existsSync(dst));
229
- assert.equal(statSync(dst).mode & 0o777, 0o600);
230
- assert.match(r.results[0].detail, /file written; not installed; held: emergency stop/);
231
- assert.deepEqual(exec.calls, [], "no launchctl call at all on a held seat");
232
- } finally { rmSync(f.root, { recursive: true, force: true }); }
233
- });
234
-
235
- test("apply: bootstrap 5 with the label already loaded in gui/<uid> is success WITHOUT a `launchctl load`; bootstrap failing for a label launchd does not know falls back to load; both failing reports ok:false without throwing", () => {
236
- const f = fx();
237
- try {
238
- writeFileSync(join(f.generatedDir, "ai.maestro.ivy-session.plist"), "<plist/>");
239
- writeFileSync(join(f.generatedDir, "ai.maestro.ivy-autoupdate.plist"), "<plist/>");
240
- writeFileSync(join(f.generatedDir, "ai.maestro.ivy-inbox-processor.plist"), "<plist/>");
241
- const exec = recorder({
242
- "launchctl bootstrap": () => ({ status: 5, stdout: "", stderr: "Bootstrap failed: 5: Input/output error" }),
243
- "launchctl load": (args) => (args[1].includes("autoupdate") ? { status: 1, stdout: "", stderr: "nope" } : { status: 0, stdout: "", stderr: "" }),
244
- }, { loaded: ["ai.maestro.ivy-session"] }); // ssh case: `print gui/501` was consulted for the plan, but here the plan says "install" for all three
245
- const plan = planLaunchdReconcile({ generated: ["ai.maestro.ivy-session", "ai.maestro.ivy-autoupdate", "ai.maestro.ivy-inbox-processor"], installed: [], loaded: [] });
246
- const r = applyLaunchdReconcile({ plan, ...f, uid: 501, exec });
247
- assert.equal(r.ok, false);
248
- const rows = Object.fromEntries(r.results.map((x) => [x.label, x]));
249
- assert.equal(rows["ai.maestro.ivy-session"].ok, true);
250
- assert.match(rows["ai.maestro.ivy-session"].detail, /bootstrap 5 but already loaded in gui\/501/);
251
- assert.equal(rows["ai.maestro.ivy-inbox-processor"].ok, true);
252
- assert.match(rows["ai.maestro.ivy-inbox-processor"].detail, /via launchctl load/);
253
- assert.equal(rows["ai.maestro.ivy-autoupdate"].ok, false);
254
- assert.match(rows["ai.maestro.ivy-autoupdate"].detail, /file written but not loaded/);
255
- assert.ok(existsSync(join(f.launchAgentsDir, "ai.maestro.ivy-autoupdate.plist")), "the file lands even when loading fails");
256
- const calls = exec.calls.map((c) => c.join(" "));
257
- assert.ok(!calls.some((c) => /^launchctl load .*ivy-session/.test(c)), `already-loaded label must not be loaded a second time: ${calls.join("\n")}`);
258
- assert.ok(calls.includes("launchctl print gui/501/ai.maestro.ivy-session"));
259
- } finally { rmSync(f.root, { recursive: true, force: true }); }
260
- });
261
-
262
- test("apply: a missing generated file is reported as a failed row, never thrown", () => {
263
- const f = fx();
264
- try {
265
- const exec = recorder();
266
- const plan = planLaunchdReconcile({ generated: ["ai.maestro.ivy-ghost"], installed: [], loaded: [] });
267
- const r = applyLaunchdReconcile({ plan, ...f, uid: 501, exec });
268
- assert.equal(r.ok, false);
269
- assert.match(r.results[0].detail, /install failed/);
270
- assert.deepEqual(exec.calls, []);
271
- } finally { rmSync(f.root, { recursive: true, force: true }); }
272
- });
@@ -1,200 +0,0 @@
1
- /**
2
- * post-steps.test.mjs — runUpgradePostSteps over a temp agent dir + HOME with
3
- * a recorded exec. Nothing real is run: generate-plists.sh is a stub the test
4
- * writes, npm/launchctl are answered by the recorder, and
5
- * MAESTRO_SKIP_GLOBAL_INSTALL=1 is set throughout.
6
- */
7
-
8
- import { test } from "node:test";
9
- import assert from "node:assert/strict";
10
- import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, statSync, rmSync } from "node:fs";
11
- import { join } from "node:path";
12
- import { tmpdir } from "node:os";
13
- import { spawnSync } from "node:child_process";
14
- import { runUpgradePostSteps, UPGRADE_RESULT_REL, STEP_NAMES } from "./post-steps.mjs";
15
-
16
- const LABELS = ["ai.maestro.ivy-daemon", "ai.maestro.ivy-session", "ai.maestro.ivy-autoupdate"];
17
-
18
- function seat() {
19
- const root = mkdtempSync(join(tmpdir(), "post-steps-"));
20
- const cwd = join(root, "ivy-ai");
21
- const home = join(root, "home");
22
- mkdirSync(join(cwd, "scripts", "local-triggers", "plists"), { recursive: true });
23
- mkdirSync(join(home, "Library", "LaunchAgents"), { recursive: true });
24
- mkdirSync(join(cwd, "config"), { recursive: true });
25
- writeFileSync(join(cwd, "config", "agent.json"), JSON.stringify({ firstName: "Ivy" }));
26
- // The daemon + autoupdate plists are already installed (an existing seat);
27
- // the session plist is what the generator adds on the first hop.
28
- for (const l of ["ai.maestro.ivy-daemon", "ai.maestro.ivy-autoupdate"]) writeFileSync(join(home, "Library", "LaunchAgents", `${l}.plist`), `<plist>${l} OLD</plist>`);
29
- return { root, cwd, home };
30
- }
31
-
32
- /** A generator stub that renders the three labels and prints the real footer line. */
33
- function stubGenerator(cwd, { fail = false, autoupdateBody = "" } = {}) {
34
- const dir = join(cwd, "scripts", "local-triggers");
35
- writeFileSync(join(dir, "generate-plists.sh"), fail
36
- ? "#!/bin/bash\necho boom >&2\nexit 3\n"
37
- : `#!/bin/bash\nset -e\nD="$(cd "$(dirname "$0")" && pwd)/plists"\nmkdir -p "$D"\nfor l in ${LABELS.join(" ")}; do printf '<plist>%s</plist>' "$l" > "$D/$l.plist"; done\n${autoupdateBody}\necho "Generated 3 plist files in $D"\n`);
38
- }
39
-
40
- /**
41
- * launchd double. `loaded` is what the gui domain holds: `print gui/<uid>`
42
- * lists it, `print gui/<uid>/<label>` answers per label. `listShows` is what a
43
- * domain-less `launchctl list` prints — from ssh that is NOT the gui domain,
44
- * so it defaults to nothing (the case the reconcile must get right).
45
- */
46
- function recorder({ loaded = ["ai.maestro.ivy-daemon", "ai.maestro.ivy-autoupdate"], listShows = [], printOk = true } = {}) {
47
- const calls = [];
48
- const exec = (cmd, args, opts) => {
49
- calls.push([cmd, ...args]);
50
- if (cmd === "/bin/bash") {
51
- // Run the generator for real — it is the test's own stub.
52
- const r = spawnSync(cmd, args, { encoding: "utf8", cwd: opts && opts.cwd });
53
- return { status: r.status, stdout: r.stdout, stderr: r.stderr };
54
- }
55
- if (cmd === "launchctl" && args[0] === "print") {
56
- if (!printOk) return { status: 1, stdout: "", stderr: "Bad request." };
57
- const parts = String(args[1]).split("/");
58
- if (parts.length === 2) return { status: 0, stdout: `gui/501 = {\n\tservices = {\n${loaded.map((l) => `\t\t0\t0\t${l}`).join("\n")}\n\t}\n}\n`, stderr: "" };
59
- return loaded.includes(parts[2]) ? { status: 0, stdout: `${parts[2]} = {}\n`, stderr: "" } : { status: 113, stdout: "", stderr: `Could not find service "${parts[2]}" in domain for user gui: 501` };
60
- }
61
- if (cmd === "launchctl" && args[0] === "list") return { status: 0, stdout: `PID Status Label\n${listShows.map((l) => `1 0 ${l}`).join("\n")}\n`, stderr: "" };
62
- if (cmd === "launchctl" && args[0] === "bootstrap") {
63
- const label = String(args[2]).replace(/^.*\//, "").replace(/\.plist$/, "");
64
- if (loaded.includes(label)) return { status: 5, stdout: "", stderr: "Bootstrap failed: 5: Input/output error" };
65
- loaded.push(label);
66
- return { status: 0, stdout: "", stderr: "" };
67
- }
68
- if (cmd === "launchctl") return { status: 0, stdout: "", stderr: "" };
69
- return { status: 1, stdout: "", stderr: "unexpected" };
70
- };
71
- exec.calls = calls;
72
- return exec;
73
- }
74
- test("first hop on an existing seat: plists regenerated, the -session job installed (600 + bootstrap), the changed daemon AND autoupdate plists rewritten but never kickstarted, global-setup run, result file written", async () => {
75
- const s = seat();
76
- try {
77
- stubGenerator(s.cwd);
78
- const exec = recorder();
79
- let setupRuns = 0;
80
- const said = [];
81
- const r = await runUpgradePostSteps({
82
- cwd: s.cwd, home: s.home, uid: 501, env: { MAESTRO_SKIP_GLOBAL_INSTALL: "1" }, exec, sdkVersion: "2.12.0", from: "2.11.17", now: Date.parse("2026-09-08T12:00:00Z"),
83
- globalSetup: async () => { setupRuns++; },
84
- say: { log: (m) => said.push(m), ok: (m) => said.push(`ok ${m}`), warn: (m) => said.push(`warn ${m}`) },
85
- });
86
- assert.equal(r.from, "2.11.17");
87
- assert.equal(r.to, "2.12.0");
88
- assert.equal(r.at, "2026-09-08T12:00:00.000Z");
89
- assert.deepEqual(Object.keys(r.steps), STEP_NAMES);
90
- assert.equal(r.steps.plists.ok, true, r.steps.plists.detail);
91
- assert.match(r.steps.plists.detail, /regenerated 3 plist/);
92
- assert.equal(r.steps.launchd.ok, true, r.steps.launchd.detail);
93
- assert.match(r.steps.launchd.detail, /1 installed, 2 replaced/);
94
- assert.equal(r.steps.globalSetup.ok, true);
95
- assert.equal(setupRuns, 1);
96
- assert.equal(r.steps.globalInstall.ok, true);
97
- assert.match(r.steps.globalInstall.detail, /skipped .*MAESTRO_SKIP_GLOBAL_INSTALL/);
98
- assert.equal(typeof r.steps.verify.ok, "boolean");
99
-
100
- const dst = join(s.home, "Library", "LaunchAgents", "ai.maestro.ivy-session.plist");
101
- assert.ok(existsSync(dst), "session plist must be installed");
102
- assert.equal(statSync(dst).mode & 0o777, 0o600);
103
- const calls = exec.calls.map((c) => c.join(" "));
104
- assert.ok(calls.includes(`launchctl bootstrap gui/501 ${dst}`), calls.join("\n"));
105
- assert.ok(!calls.some((c) => /kickstart/.test(c)), `nothing is kickstarted — least of all the -autoupdate job this upgrade runs inside: ${calls.join("\n")}`);
106
- assert.ok(!calls.some((c) => /bootout|unload/.test(c)));
107
- assert.ok(!calls.some((c) => /^launchctl load/.test(c)), "bootstrap succeeded → no domain-less load");
108
- assert.ok(calls.includes("launchctl print gui/501"), "loaded-ness is read from the gui domain, not a domain-less `launchctl list`");
109
- assert.ok(!calls.includes("launchctl list"), calls.join("\n"));
110
- assert.ok(said.some((m) => /ai\.maestro\.ivy-autoupdate: replaced \(file only\)/.test(m)), said.join("\n"));
111
- assert.ok(!said.some((m) => /kickstart/.test(m)));
112
- assert.ok(!calls.some((c) => /^npm install/.test(c)), "no global install under the skip flag");
113
-
114
- const file = JSON.parse(readFileSync(join(s.cwd, UPGRADE_RESULT_REL), "utf8"));
115
- assert.deepEqual(file, { from: "2.11.17", to: "2.12.0", at: "2026-09-08T12:00:00.000Z", steps: r.steps });
116
- assert.ok(said.some((m) => /^ok launchd:/.test(m)), said.join("\n"));
117
- } finally { rmSync(s.root, { recursive: true, force: true }); }
118
- });
119
-
120
- test("fail-open: a failing generator, a throwing global-setup and a missing launchctl are each ONE failed step; the rest still run and the result file is still written", async () => {
121
- const s = seat();
122
- try {
123
- stubGenerator(s.cwd, { fail: true });
124
- const exec = (cmd, args, opts) => {
125
- if (cmd === "/bin/bash") { const r = spawnSync(cmd, args, { encoding: "utf8", cwd: opts && opts.cwd }); return { status: r.status, stdout: r.stdout, stderr: r.stderr }; }
126
- return { status: 127, stdout: "", stderr: "launchctl: command not found" };
127
- };
128
- const r = await runUpgradePostSteps({ cwd: s.cwd, home: s.home, uid: 501, env: { MAESTRO_SKIP_GLOBAL_INSTALL: "1" }, exec, sdkVersion: "2.12.0", globalSetup: async () => { throw new Error("no ~/.claude"); } });
129
- assert.equal(r.steps.plists.ok, false);
130
- assert.match(r.steps.plists.detail, /exited 3 \(boom\)/);
131
- assert.equal(r.steps.launchd.ok, false);
132
- assert.match(r.steps.launchd.detail, /launchctl unavailable/);
133
- assert.equal(r.steps.globalSetup.ok, false);
134
- assert.match(r.steps.globalSetup.detail, /no ~\/\.claude/);
135
- assert.equal(r.steps.globalInstall.ok, true);
136
- assert.equal(r.from, null);
137
- assert.ok(existsSync(join(s.cwd, UPGRADE_RESULT_REL)));
138
- assert.ok(!existsSync(join(s.home, "Library", "LaunchAgents", "ai.maestro.ivy-session.plist")), "nothing installed when launchd is unreachable");
139
- } finally { rmSync(s.root, { recursive: true, force: true }); }
140
- });
141
-
142
- test("no generator on disk (a stripped repo): the plists step fails, launchd sees nothing generated, no launchctl write happens", async () => {
143
- const s = seat();
144
- try {
145
- const exec = recorder();
146
- const r = await runUpgradePostSteps({ cwd: s.cwd, home: s.home, uid: 501, env: { MAESTRO_SKIP_GLOBAL_INSTALL: "1" }, exec, sdkVersion: "2.12.0", globalSetup: async () => {} });
147
- assert.equal(r.steps.plists.ok, false);
148
- assert.match(r.steps.launchd.detail, /0 installed, 0 replaced/);
149
- assert.ok(!exec.calls.some((c) => c[0] === "launchctl" && c[1] !== "print"));
150
- } finally { rmSync(s.root, { recursive: true, force: true }); }
151
- });
152
-
153
- test("held seat: under .emergency-stop the session plist is written but NOT bootstrapped; the step and the result file say why; the kill-switch holds the same way", async () => {
154
- for (const marker of [".emergency-stop", join("state", "EMERGENCY_STOP"), ".no-autoupdate"]) {
155
- const s = seat();
156
- try {
157
- stubGenerator(s.cwd);
158
- mkdirSync(join(s.cwd, "state"), { recursive: true });
159
- writeFileSync(join(s.cwd, marker), "2026-09-08T12:00:00Z\n");
160
- // emergency-stop.sh unloaded everything: nothing is loaded in gui/501.
161
- const exec = recorder({ loaded: [] });
162
- const r = await runUpgradePostSteps({ cwd: s.cwd, home: s.home, uid: 501, env: { MAESTRO_SKIP_GLOBAL_INSTALL: "1" }, exec, sdkVersion: "2.12.0", globalSetup: async () => {} });
163
- assert.equal(r.steps.launchd.ok, true, r.steps.launchd.detail);
164
- assert.match(r.steps.launchd.detail, /3 not bootstrapped — held: (emergency stop|autoupdate kill-switch)/, `${marker}: ${r.steps.launchd.detail}`);
165
- const dst = join(s.home, "Library", "LaunchAgents", "ai.maestro.ivy-session.plist");
166
- assert.ok(existsSync(dst), "the file still lands so the next login / an explicit start has it");
167
- assert.equal(statSync(dst).mode & 0o777, 0o600);
168
- const calls = exec.calls.map((c) => c.join(" "));
169
- assert.ok(!calls.some((c) => /bootstrap|^launchctl load|kickstart/.test(c)), `${marker}: no job may start under a hold: ${calls.join("\n")}`);
170
- const file = JSON.parse(readFileSync(join(s.cwd, UPGRADE_RESULT_REL), "utf8"));
171
- assert.match(file.steps.launchd.detail, /held/);
172
- } finally { rmSync(s.root, { recursive: true, force: true }); }
173
- }
174
- });
175
-
176
- test("from ssh: a domain-less `launchctl list` shows nothing, but `print gui/<uid>` shows the jobs — nothing is re-loaded and nothing is double-registered", async () => {
177
- const s = seat();
178
- try {
179
- stubGenerator(s.cwd);
180
- const exec = recorder({ loaded: ["ai.maestro.ivy-daemon", "ai.maestro.ivy-autoupdate"], listShows: [] });
181
- const r = await runUpgradePostSteps({ cwd: s.cwd, home: s.home, uid: 501, env: { MAESTRO_SKIP_GLOBAL_INSTALL: "1" }, exec, sdkVersion: "2.12.0", globalSetup: async () => {} });
182
- assert.equal(r.steps.launchd.ok, true, r.steps.launchd.detail);
183
- assert.match(r.steps.launchd.detail, /1 installed, 2 replaced, 0 loaded/);
184
- const calls = exec.calls.map((c) => c.join(" "));
185
- assert.equal(calls.filter((c) => /^launchctl bootstrap/.test(c)).length, 1, "only the session job is bootstrapped");
186
- assert.ok(!calls.some((c) => /^launchctl load/.test(c)), `no domain-less load from ssh: ${calls.join("\n")}`);
187
- assert.ok(!/launchctl list/.test(r.steps.launchd.detail));
188
- } finally { rmSync(s.root, { recursive: true, force: true }); }
189
- });
190
-
191
- test("when `launchctl print` is unavailable the reconcile falls back to `launchctl list` and says so in the step detail", async () => {
192
- const s = seat();
193
- try {
194
- stubGenerator(s.cwd);
195
- const exec = recorder({ loaded: [], listShows: ["ai.maestro.ivy-daemon", "ai.maestro.ivy-autoupdate"], printOk: false });
196
- const r = await runUpgradePostSteps({ cwd: s.cwd, home: s.home, uid: 501, env: { MAESTRO_SKIP_GLOBAL_INSTALL: "1" }, exec, sdkVersion: "2.12.0", globalSetup: async () => {} });
197
- assert.match(r.steps.launchd.detail, /loaded-ness from `launchctl list`/);
198
- assert.match(r.steps.launchd.detail, /1 installed, 2 replaced/);
199
- } finally { rmSync(s.root, { recursive: true, force: true }); }
200
- });
@@ -1,164 +0,0 @@
1
- /**
2
- * verify.test.mjs — buildVerifyReport is pure; collectVerifyInputs reads a
3
- * temp HOME + agent dir with a recorded exec (never the real npm/launchctl).
4
- */
5
-
6
- import { test } from "node:test";
7
- import assert from "node:assert/strict";
8
- import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
9
- import { join } from "node:path";
10
- import { tmpdir } from "node:os";
11
- import { buildVerifyReport, formatVerifyReport, parseDaemonHealth, collectVerifyInputs, runVerify } from "./verify.mjs";
12
- import { IDENTITY_BEGIN, IDENTITY_END, CLAUDE_MD_BEGIN, CLAUDE_MD_END, mergeSessionSettings } from "../collective/global-config.mjs";
13
-
14
- const G = ["ai.maestro.ivy-daemon", "ai.maestro.ivy-session"];
15
- const allMarkers = { identityConfigured: true, identity: true, collective: true, mcp: true, settings: true, pointer: true, skills: true };
16
-
17
- function good(over = {}) {
18
- return {
19
- expected: "2.12.0", globalVersion: "2.12.0", localVersion: "2.12.0", manifestPresent: true, manifestVersion: "2.12.0",
20
- daemon: { version: "2.12.0", updatedAt: "2026-09-08T12:00:00Z" },
21
- plists: { generated: G, installed: G, loaded: G, launchctlOk: true }, markers: allMarkers, ...over,
22
- };
23
- }
24
-
25
- const byName = (r) => Object.fromEntries(r.rows.map((x) => [x.name, x]));
26
-
27
- test("a seat wholly on the expected version is ok with no mismatches", () => {
28
- const r = buildVerifyReport(good());
29
- assert.equal(r.ok, true, JSON.stringify(r.rows));
30
- assert.deepEqual(r.mismatches, []);
31
- assert.ok(r.rows.every((x) => x.level === "ok"));
32
- assert.match(formatVerifyReport(r).pop(), /seat is on 2\.12\.0/);
33
- });
34
-
35
- test("global bin behind → fail; under MAESTRO_SKIP_GLOBAL_INSTALL it is a warn", () => {
36
- const r = buildVerifyReport(good({ globalVersion: "2.11.17" }));
37
- assert.equal(r.ok, false);
38
- assert.deepEqual(r.mismatches, ["global"]);
39
- assert.match(byName(r).global.msg, /npm i -g @cohortapp\/agent-sdk@2\.12\.0 --no-audit --no-fund/);
40
- const s = buildVerifyReport(good({ globalVersion: "", skipGlobal: true }));
41
- assert.equal(s.ok, true);
42
- assert.equal(byName(s).global.level, "warn");
43
- assert.equal(buildVerifyReport(good({ globalVersion: "" })).mismatches[0], "global");
44
- });
45
-
46
- test("local / manifest / daemon: missing is a warn, a different version is a fail; daemonRestartPending downgrades the daemon row", () => {
47
- assert.equal(byName(buildVerifyReport(good({ localVersion: "" }))).local.level, "warn");
48
- assert.deepEqual(buildVerifyReport(good({ localVersion: "2.11.17" })).mismatches, ["local"]);
49
- assert.equal(byName(buildVerifyReport(good({ manifestPresent: false }))).manifest.level, "warn");
50
- assert.equal(byName(buildVerifyReport(good({ manifestVersion: "" }))).manifest.level, "warn");
51
- assert.deepEqual(buildVerifyReport(good({ manifestVersion: "2.11.17" })).mismatches, ["manifest"]);
52
- assert.equal(byName(buildVerifyReport(good({ daemon: { version: "" } }))).daemon.level, "warn");
53
- assert.deepEqual(buildVerifyReport(good({ daemon: { version: "2.11.17" } })).mismatches, ["daemon"]);
54
- const pending = buildVerifyReport(good({ daemon: { version: "2.11.17" }, daemonRestartPending: true }));
55
- assert.equal(pending.ok, true);
56
- assert.match(byName(pending).daemon.msg, /autoupdate kickstarts/);
57
- });
58
-
59
- test("plists: a generated label that is not installed, or installed but not loaded, is a fail naming the label", () => {
60
- const notInstalled = buildVerifyReport(good({ plists: { generated: G, installed: [G[0]], loaded: [G[0]], launchctlOk: true } }));
61
- assert.deepEqual(notInstalled.mismatches, ["plists"]);
62
- assert.match(byName(notInstalled).plists.msg, /not installed: ai\.maestro\.ivy-session/);
63
- const notLoaded = buildVerifyReport(good({ plists: { generated: G, installed: G, loaded: [G[0]], launchctlOk: true } }));
64
- assert.match(byName(notLoaded).plists.msg, /not loaded: ai\.maestro\.ivy-session/);
65
- const noLaunchctl = buildVerifyReport(good({ plists: { generated: G, installed: G, loaded: [], launchctlOk: false } }));
66
- assert.equal(noLaunchctl.ok, true, "cannot prove loaded without launchctl → warn");
67
- assert.equal(byName(buildVerifyReport(good({ plists: { generated: [], installed: [], loaded: [] } }))).plists.level, "warn");
68
- });
69
-
70
- test("global-setup markers: any missing marker is a fail; an unconfigured identity is a warn", () => {
71
- const r = buildVerifyReport(good({ markers: { ...allMarkers, mcp: false, skills: false } }));
72
- assert.deepEqual(r.mismatches, ["global-setup"]);
73
- assert.match(byName(r)["global-setup"].msg, /cohort MCP server/);
74
- assert.match(byName(r)["global-setup"].msg, /maestro-main-session\/SKILL\.md/);
75
- const unconf = buildVerifyReport(good({ markers: { ...allMarkers, identityConfigured: false, identity: false } }));
76
- assert.equal(unconf.ok, true);
77
- assert.equal(unconf.rows.filter((x) => x.name === "global-setup")[0].level, "warn");
78
- const noId = buildVerifyReport(good({ markers: { ...allMarkers, identity: false } }));
79
- assert.equal(noId.ok, false);
80
- });
81
-
82
- test("parseDaemonHealth reads sdk_version / updated / pid from the flat YAML the daemon writes", () => {
83
- const y = "updated: 2026-09-08T12:00:00.000Z\nuptime_s: 40\nsdk_version: 2.12.0\npid: 4242\ndispatcher:\n {\n }\n";
84
- assert.deepEqual(parseDaemonHealth(y), { version: "2.12.0", updatedAt: "2026-09-08T12:00:00.000Z", pid: 4242 });
85
- assert.deepEqual(parseDaemonHealth(""), { version: "", updatedAt: "", pid: null });
86
- });
87
-
88
- // ---------------------------------------------------------------------------
89
- // collectVerifyInputs — the edge over a temp HOME + agent dir
90
- // ---------------------------------------------------------------------------
91
-
92
- function seat({ version = "2.12.0", withSetup = true } = {}) {
93
- const root = mkdtempSync(join(tmpdir(), "verify-"));
94
- const cwd = join(root, "ivy-ai");
95
- const home = join(root, "home");
96
- const claudeDir = join(home, ".claude");
97
- mkdirSync(join(cwd, "config"), { recursive: true });
98
- mkdirSync(join(cwd, "node_modules", "@cohortapp", "agent-sdk"), { recursive: true });
99
- mkdirSync(join(cwd, ".maestro"), { recursive: true });
100
- mkdirSync(join(cwd, "state", "dashboards"), { recursive: true });
101
- mkdirSync(join(cwd, "scripts", "local-triggers", "plists"), { recursive: true });
102
- mkdirSync(join(home, "Library", "LaunchAgents"), { recursive: true });
103
- mkdirSync(join(claudeDir, "skills", "maestro-main-session"), { recursive: true });
104
- writeFileSync(join(cwd, "config", "agent.json"), JSON.stringify({ firstName: "Ivy", fullName: "Ivy Tester" }));
105
- writeFileSync(join(cwd, "package.json"), JSON.stringify({ name: "ivy-ai" }));
106
- writeFileSync(join(cwd, "node_modules", "@cohortapp", "agent-sdk", "package.json"), JSON.stringify({ name: "@cohortapp/agent-sdk", version }));
107
- writeFileSync(join(cwd, ".maestro", "shipped-manifest.json"), JSON.stringify({ version: 1, sdkVersion: version, files: [] }));
108
- writeFileSync(join(cwd, "state", "dashboards", "daemon-health.yaml"), `updated: 2026-09-08T12:00:00Z\nsdk_version: ${version}\n`);
109
- for (const l of G) {
110
- writeFileSync(join(cwd, "scripts", "local-triggers", "plists", `${l}.plist`), `<plist>${l}</plist>`);
111
- writeFileSync(join(home, "Library", "LaunchAgents", `${l}.plist`), `<plist>${l}</plist>`);
112
- }
113
- if (withSetup) {
114
- writeFileSync(join(claudeDir, "CLAUDE.md"), `${CLAUDE_MD_BEGIN}\nx\n${CLAUDE_MD_END}\n${IDENTITY_BEGIN}\nid\n${IDENTITY_END}\n`);
115
- writeFileSync(join(home, ".claude.json"), JSON.stringify({ mcpServers: { cohort: { command: "cohort-mcp", args: [], env: { COHORT_AGENT_ROOT: cwd } } } }));
116
- writeFileSync(join(claudeDir, "settings.json"), JSON.stringify(mergeSessionSettings({}, { agentRoot: cwd }).settings));
117
- writeFileSync(join(claudeDir, "maestro-agent.json"), JSON.stringify({ agentRepo: cwd }));
118
- writeFileSync(join(claudeDir, "skills", "maestro-main-session", "SKILL.md"), "# skill");
119
- }
120
- return { root, cwd, home };
121
- }
122
-
123
- function execFor({ globalVersion = "2.12.0", loaded = G } = {}) {
124
- const calls = [];
125
- const exec = (cmd, args) => {
126
- calls.push([cmd, ...args]);
127
- if (cmd === "npm") return { status: 0, stdout: JSON.stringify({ dependencies: { "@cohortapp/agent-sdk": { version: globalVersion } } }), stderr: "" };
128
- if (cmd === "launchctl") return { status: 0, stdout: `PID\tStatus\tLabel\n${loaded.map((l) => `1\t0\t${l}`).join("\n")}\n`, stderr: "" };
129
- return { status: 1, stdout: "", stderr: "" };
130
- };
131
- exec.calls = calls;
132
- return exec;
133
- }
134
-
135
- test("collectVerifyInputs reads a fully-set-up seat as all-ok; runVerify agrees", () => {
136
- const s = seat();
137
- try {
138
- const exec = execFor();
139
- const inputs = collectVerifyInputs({ cwd: s.cwd, home: s.home, env: {}, exec, expected: "2.12.0" });
140
- assert.equal(inputs.globalVersion, "2.12.0");
141
- assert.equal(inputs.localVersion, "2.12.0");
142
- assert.equal(inputs.manifestVersion, "2.12.0");
143
- assert.equal(inputs.daemon.version, "2.12.0");
144
- assert.deepEqual(inputs.plists.generated.sort(), G);
145
- assert.deepEqual(inputs.markers, { identityConfigured: true, identity: true, collective: true, mcp: true, settings: true, pointer: true, skills: true });
146
- const r = runVerify({ cwd: s.cwd, home: s.home, env: {}, exec, expected: "2.12.0" });
147
- assert.equal(r.ok, true, JSON.stringify(r.rows));
148
- assert.ok(exec.calls.some((c) => c[0] === "npm" && c[1] === "ls" && c[2] === "-g"));
149
- } finally { rmSync(s.root, { recursive: true, force: true }); }
150
- });
151
-
152
- test("collectVerifyInputs: a seat with no global-setup and a stale global bin reports both mismatches; MAESTRO_SKIP_GLOBAL_INSTALL skips the npm read", () => {
153
- const s = seat({ withSetup: false });
154
- try {
155
- const exec = execFor({ globalVersion: "2.11.17", loaded: [G[0]] });
156
- const r = runVerify({ cwd: s.cwd, home: s.home, env: {}, exec, expected: "2.12.0" });
157
- assert.equal(r.ok, false);
158
- assert.deepEqual(r.mismatches.sort(), ["global", "global-setup", "plists"]);
159
- const skipExec = execFor();
160
- const inputs = collectVerifyInputs({ cwd: s.cwd, home: s.home, env: { MAESTRO_SKIP_GLOBAL_INSTALL: "1" }, exec: skipExec, expected: "2.12.0" });
161
- assert.equal(inputs.skipGlobal, true);
162
- assert.ok(!skipExec.calls.some((c) => c[0] === "npm"), "no npm call under the skip flag");
163
- } finally { rmSync(s.root, { recursive: true, force: true }); }
164
- });