@cohortapp/agent-sdk 2.3.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 (731) hide show
  1. package/.claude/commands/init-agent.md +104 -0
  2. package/.claude/commands/init-maestro.md +1187 -0
  3. package/.claude/settings.json +161 -0
  4. package/.env.example +216 -0
  5. package/README.md +632 -0
  6. package/agents/browser-operator/agent.md +52 -0
  7. package/agents/calendar-ops/agent.md +50 -0
  8. package/agents/communications/agent.md +96 -0
  9. package/agents/decision-log/agent.md +65 -0
  10. package/agents/desktop-operator/agent.md +59 -0
  11. package/agents/gmail-operator/agent.md +62 -0
  12. package/agents/inbound-dispatcher/agent.md +66 -0
  13. package/agents/inbox-processor/agent.md +39 -0
  14. package/agents/pmo-execution/agent.md +60 -0
  15. package/agents/session-spawner/agent.md +64 -0
  16. package/agents/slack-operator/agent.md +60 -0
  17. package/agents/whatsapp-operator/agent.md +60 -0
  18. package/agents/workflow-automation/agent.md +61 -0
  19. package/archetypes/altitudes/c-suite.yaml +58 -0
  20. package/archetypes/altitudes/founder.yaml +68 -0
  21. package/archetypes/altitudes/senior-manager.yaml +63 -0
  22. package/archetypes/altitudes/svp.yaml +60 -0
  23. package/archetypes/altitudes/vp.yaml +50 -0
  24. package/archetypes/archetype.schema.json +77 -0
  25. package/archetypes/base.yaml +47 -0
  26. package/archetypes/capabilities/commercial-leader.yaml +159 -0
  27. package/archetypes/capabilities/compliance-officer.yaml +159 -0
  28. package/archetypes/capabilities/executive-operator.yaml +169 -0
  29. package/archetypes/capabilities/finance-leader.yaml +162 -0
  30. package/archetypes/capabilities/operations-leader.yaml +154 -0
  31. package/archetypes/capabilities/product-leader.yaml +148 -0
  32. package/archetypes/capabilities/technical-leader.yaml +146 -0
  33. package/archetypes/functions/commercial-leader.yaml +62 -0
  34. package/archetypes/functions/compliance-officer.yaml +64 -0
  35. package/archetypes/functions/executive-operator.yaml +70 -0
  36. package/archetypes/functions/finance-leader.yaml +70 -0
  37. package/archetypes/functions/operations-leader.yaml +62 -0
  38. package/archetypes/functions/product-leader.yaml +61 -0
  39. package/archetypes/functions/technical-leader.yaml +57 -0
  40. package/bin/cohort-mcp.mjs +81 -0
  41. package/bin/maestro.mjs +3516 -0
  42. package/bin/maestro.test.mjs +1015 -0
  43. package/desktop-control/README.md +56 -0
  44. package/desktop-control/app-profiles/gmail.yaml +120 -0
  45. package/desktop-control/app-profiles/slack.yaml +315 -0
  46. package/desktop-control/app-profiles/whatsapp.yaml +107 -0
  47. package/docs/architecture/agent-topology.md +2239 -0
  48. package/docs/architecture/archetype-agent-factory.md +110 -0
  49. package/docs/architecture/collective-memory-and-org-mesh.md +115 -0
  50. package/docs/architecture/continuous-monitoring.md +221 -0
  51. package/docs/architecture/mcp-capability-map.md +585 -0
  52. package/docs/architecture/system-architecture.md +1272 -0
  53. package/docs/company-context/README.md +40 -0
  54. package/docs/guides/agent-persona-setup.md +600 -0
  55. package/docs/guides/agents-observe-setup.md +64 -0
  56. package/docs/guides/billing-console-keys.md +88 -0
  57. package/docs/guides/ccxray-diagnostics.md +65 -0
  58. package/docs/guides/channel-bus.md +127 -0
  59. package/docs/guides/claude-mem-setup.md +79 -0
  60. package/docs/guides/claude-pace-setup.md +56 -0
  61. package/docs/guides/claudraband-sessions.md +98 -0
  62. package/docs/guides/clawteam-swarm.md +116 -0
  63. package/docs/guides/code-review-graph-setup.md +86 -0
  64. package/docs/guides/email-setup.md +431 -0
  65. package/docs/guides/mac-mini.md +119 -0
  66. package/docs/guides/media-generation-setup.md +349 -0
  67. package/docs/guides/model-routing.md +162 -0
  68. package/docs/guides/observability-otel.md +265 -0
  69. package/docs/guides/org-onboarding.md +132 -0
  70. package/docs/guides/outbound-governance-setup.md +437 -0
  71. package/docs/guides/pdf-generation-setup.md +315 -0
  72. package/docs/guides/poller-daemon-setup.md +563 -0
  73. package/docs/guides/rag-context-setup.md +459 -0
  74. package/docs/guides/self-optimization-pattern.md +82 -0
  75. package/docs/guides/setup-wizard.md +178 -0
  76. package/docs/guides/slack-setup.md +350 -0
  77. package/docs/guides/telegram-setup.md +227 -0
  78. package/docs/guides/twilio-subaccounts-setup.md +223 -0
  79. package/docs/guides/verification.md +128 -0
  80. package/docs/guides/voice-mode.md +188 -0
  81. package/docs/guides/voice-sms-setup.md +698 -0
  82. package/docs/guides/webhook-relay-setup.md +349 -0
  83. package/docs/guides/whatsapp-setup.md +288 -0
  84. package/docs/prompts/board-pack-cover-template.md +36 -0
  85. package/docs/prompts/decision-recommendation-template.md +88 -0
  86. package/docs/prompts/followup-message-template.md +141 -0
  87. package/docs/prompts/investor-letter-template.md +52 -0
  88. package/docs/prompts/morning-brief-template.md +82 -0
  89. package/docs/prompts/presentation-template.md +58 -0
  90. package/docs/prompts/weekly-strategic-memo-template.md +104 -0
  91. package/docs/research/hallucinated-tool-output-investigation.md +151 -0
  92. package/docs/runbooks/backup-restore.md +205 -0
  93. package/docs/runbooks/cohort-cutover.md +129 -0
  94. package/docs/runbooks/fleet-operations.md +200 -0
  95. package/docs/runbooks/incident-response.md +226 -0
  96. package/docs/runbooks/mac-mini-bootstrap.md +431 -0
  97. package/docs/runbooks/perpetual-operations.md +509 -0
  98. package/docs/runbooks/recovery-and-failover.md +260 -0
  99. package/framework-features.json +267 -0
  100. package/ingest/README.md +87 -0
  101. package/lib/action-executor.js +689 -0
  102. package/lib/action-executor.test.mjs +871 -0
  103. package/lib/agent-root.mjs +37 -0
  104. package/lib/archetype.mjs +236 -0
  105. package/lib/archetype.test.mjs +132 -0
  106. package/lib/autonomy.mjs +114 -0
  107. package/lib/autonomy.test.mjs +66 -0
  108. package/lib/backlog.mjs +358 -0
  109. package/lib/backlog.test.mjs +266 -0
  110. package/lib/budget-guard.mjs +279 -0
  111. package/lib/budget-guard.test.mjs +291 -0
  112. package/lib/cadence-bus-schedule.test.mjs +194 -0
  113. package/lib/cadence-bus.mjs +1120 -0
  114. package/lib/cadence-bus.test.mjs +720 -0
  115. package/lib/cadences.mjs +205 -0
  116. package/lib/cadences.test.mjs +125 -0
  117. package/lib/capability.mjs +154 -0
  118. package/lib/capability.test.mjs +78 -0
  119. package/lib/channels/base-adapter.mjs +719 -0
  120. package/lib/channels/base-adapter.test.mjs +590 -0
  121. package/lib/channels/channel.mjs +128 -0
  122. package/lib/channels/channels.test.mjs +371 -0
  123. package/lib/channels/contract.mjs +215 -0
  124. package/lib/channels/contract.test.mjs +137 -0
  125. package/lib/channels/conversation-resolver.mjs +95 -0
  126. package/lib/channels/gmail/adapter.mjs +87 -0
  127. package/lib/channels/inbox-item.mjs +255 -0
  128. package/lib/channels/inbox-item.test.mjs +335 -0
  129. package/lib/channels/index.mjs +94 -0
  130. package/lib/channels/orgmail/adapter.mjs +353 -0
  131. package/lib/channels/orgmail/adapter.test.mjs +311 -0
  132. package/lib/channels/pairing.mjs +363 -0
  133. package/lib/channels/pairing.test.mjs +270 -0
  134. package/lib/channels/registry.mjs +164 -0
  135. package/lib/channels/slack/adapter.mjs +317 -0
  136. package/lib/channels/slack-adapter.test.mjs +212 -0
  137. package/lib/channels/sms/adapter.mjs +43 -0
  138. package/lib/channels/telegram/adapter.mjs +432 -0
  139. package/lib/channels/telegram-adapter.test.mjs +306 -0
  140. package/lib/channels/voice/adapter.mjs +301 -0
  141. package/lib/channels/voice/adapter.test.mjs +278 -0
  142. package/lib/channels/whatsapp/adapter-baileys.mjs +587 -0
  143. package/lib/channels/whatsapp/adapter-baileys.test.mjs +359 -0
  144. package/lib/channels/whatsapp/adapter-twilio.mjs +65 -0
  145. package/lib/channels/whatsapp/baileys-typing.test.mjs +154 -0
  146. package/lib/charter.mjs +256 -0
  147. package/lib/charter.test.mjs +89 -0
  148. package/lib/claude-bin.mjs +134 -0
  149. package/lib/claude-bin.test.mjs +75 -0
  150. package/lib/collective/capture.mjs +185 -0
  151. package/lib/collective/capture.test.mjs +121 -0
  152. package/lib/collective/cards.mjs +201 -0
  153. package/lib/collective/cards.test.mjs +114 -0
  154. package/lib/collective/config.mjs +186 -0
  155. package/lib/collective/config.test.mjs +123 -0
  156. package/lib/collective/global-config.mjs +113 -0
  157. package/lib/collective/global-config.test.mjs +75 -0
  158. package/lib/collective/presence.mjs +201 -0
  159. package/lib/collective/presence.test.mjs +95 -0
  160. package/lib/collective/recall.mjs +215 -0
  161. package/lib/collective/recall.test.mjs +116 -0
  162. package/lib/comms/send-gate.mjs +554 -0
  163. package/lib/comms/send-gate.test.mjs +577 -0
  164. package/lib/comms.mjs +67 -0
  165. package/lib/comms.test.mjs +41 -0
  166. package/lib/diagnostics/alerts.mjs +424 -0
  167. package/lib/diagnostics/alerts.test.mjs +318 -0
  168. package/lib/diagnostics/backup-freshness.mjs +188 -0
  169. package/lib/diagnostics/backup-freshness.test.mjs +185 -0
  170. package/lib/diagnostics/counters.mjs +269 -0
  171. package/lib/diagnostics/counters.test.mjs +206 -0
  172. package/lib/diagnostics/events.mjs +188 -0
  173. package/lib/diagnostics/events.test.mjs +290 -0
  174. package/lib/diagnostics/otel.mjs +237 -0
  175. package/lib/diagnostics/otel.test.mjs +196 -0
  176. package/lib/diagnostics/trace.mjs +216 -0
  177. package/lib/diagnostics/trace.test.mjs +251 -0
  178. package/lib/env-compat.mjs +74 -0
  179. package/lib/env-compat.test.mjs +104 -0
  180. package/lib/feature-init.mjs +331 -0
  181. package/lib/fs-atomic.mjs +112 -0
  182. package/lib/fs-atomic.test.mjs +72 -0
  183. package/lib/fs-ownership.mjs +111 -0
  184. package/lib/fs-ownership.test.mjs +158 -0
  185. package/lib/hooks/bus.mjs +347 -0
  186. package/lib/hooks/bus.test.mjs +387 -0
  187. package/lib/index.js +16 -0
  188. package/lib/learning/config.mjs +106 -0
  189. package/lib/learning/config.test.mjs +75 -0
  190. package/lib/learning/counters.mjs +156 -0
  191. package/lib/learning/counters.test.mjs +69 -0
  192. package/lib/learning/curator-consolidate.test.mjs +238 -0
  193. package/lib/learning/curator.mjs +453 -0
  194. package/lib/learning/curator.test.mjs +106 -0
  195. package/lib/learning/log.mjs +40 -0
  196. package/lib/learning/reflect.mjs +534 -0
  197. package/lib/learning/reflect.test.mjs +0 -0
  198. package/lib/learning/session-index.mjs +352 -0
  199. package/lib/learning/session-index.test.mjs +125 -0
  200. package/lib/learning/skill-writer.mjs +474 -0
  201. package/lib/learning/skill-writer.test.mjs +210 -0
  202. package/lib/mcp/server.mjs +328 -0
  203. package/lib/mcp/server.test.mjs +400 -0
  204. package/lib/model-router/auth-profiles.mjs +758 -0
  205. package/lib/model-router/auth-profiles.test.mjs +580 -0
  206. package/lib/model-router/catalog/anthropic.yaml +153 -0
  207. package/lib/model-router/catalog/deepseek.yaml +86 -0
  208. package/lib/model-router/catalog/moonshot.yaml +81 -0
  209. package/lib/model-router/catalog/qwen.yaml +114 -0
  210. package/lib/model-router/catalog.mjs +925 -0
  211. package/lib/model-router/catalog.test.mjs +385 -0
  212. package/lib/model-router/economics.mjs +564 -0
  213. package/lib/model-router/economics.test.mjs +344 -0
  214. package/lib/model-router/failover.mjs +298 -0
  215. package/lib/model-router/failover.test.mjs +439 -0
  216. package/lib/model-router/health.mjs +453 -0
  217. package/lib/model-router/health.test.mjs +338 -0
  218. package/lib/model-router/integration-coverage.test.mjs +829 -0
  219. package/lib/model-router/integration.test.mjs +564 -0
  220. package/lib/model-router/ledger.mjs +402 -0
  221. package/lib/model-router/ledger.test.mjs +382 -0
  222. package/lib/model-router/llm-task.mjs +515 -0
  223. package/lib/model-router/llm-task.test.mjs +392 -0
  224. package/lib/model-router/org-credentials.mjs +260 -0
  225. package/lib/model-router/org-credentials.test.mjs +265 -0
  226. package/lib/model-router/pricing-refresh.mjs +463 -0
  227. package/lib/model-router/pricing-refresh.test.mjs +286 -0
  228. package/lib/model-router/reconcile.mjs +429 -0
  229. package/lib/model-router/reconcile.test.mjs +316 -0
  230. package/lib/model-router/repair.mjs +471 -0
  231. package/lib/model-router/repair.test.mjs +180 -0
  232. package/lib/model-router/resolve.mjs +1206 -0
  233. package/lib/model-router/spawn.mjs +497 -0
  234. package/lib/model-router/spawn.test.mjs +425 -0
  235. package/lib/model-router/taxonomy.mjs +893 -0
  236. package/lib/model-router/taxonomy.test.mjs +410 -0
  237. package/lib/model-router.mjs +677 -0
  238. package/lib/model-router.test.mjs +907 -0
  239. package/lib/org/activity.mjs +211 -0
  240. package/lib/org/activity.test.mjs +134 -0
  241. package/lib/org/approvals.mjs +448 -0
  242. package/lib/org/approvals.test.mjs +216 -0
  243. package/lib/org/awareness.mjs +222 -0
  244. package/lib/org/awareness.test.mjs +159 -0
  245. package/lib/org/board.mjs +229 -0
  246. package/lib/org/board.test.mjs +177 -0
  247. package/lib/org/bootstrap-context.mjs +169 -0
  248. package/lib/org/bootstrap-context.test.mjs +153 -0
  249. package/lib/org/client.mjs +1628 -0
  250. package/lib/org/client.test.mjs +1107 -0
  251. package/lib/org/cohort-client.mjs +67 -0
  252. package/lib/org/cohort-client.test.mjs +126 -0
  253. package/lib/org/cost-sync.mjs +227 -0
  254. package/lib/org/cost-sync.test.mjs +153 -0
  255. package/lib/org/doctor.mjs +212 -0
  256. package/lib/org/doctor.test.mjs +212 -0
  257. package/lib/org/handoff.mjs +293 -0
  258. package/lib/org/handoff.test.mjs +269 -0
  259. package/lib/org/integration-tools.mjs +182 -0
  260. package/lib/org/integration-tools.test.mjs +160 -0
  261. package/lib/org/keys.mjs +131 -0
  262. package/lib/org/keys.test.mjs +92 -0
  263. package/lib/org/knowledge.mjs +463 -0
  264. package/lib/org/knowledge.test.mjs +319 -0
  265. package/lib/org/leases.mjs +335 -0
  266. package/lib/org/leases.test.mjs +235 -0
  267. package/lib/org/mesh-integration.test.mjs +127 -0
  268. package/lib/org/mesh.mjs +459 -0
  269. package/lib/org/mesh.test.mjs +345 -0
  270. package/lib/org/messaging.mjs +503 -0
  271. package/lib/org/messaging.test.mjs +238 -0
  272. package/lib/org/policy.mjs +345 -0
  273. package/lib/org/policy.test.mjs +237 -0
  274. package/lib/org/protocol.checksum +1 -0
  275. package/lib/org/protocol.checksum.test.mjs +90 -0
  276. package/lib/org/protocol.mjs +967 -0
  277. package/lib/org/protocol.test.mjs +264 -0
  278. package/lib/org/registry.mjs +194 -0
  279. package/lib/org/registry.test.mjs +100 -0
  280. package/lib/org/tool-surface-integration.test.mjs +120 -0
  281. package/lib/org/tool-surface.mjs +2535 -0
  282. package/lib/org/tool-surface.test.mjs +589 -0
  283. package/lib/org/ui-parity.mjs +3236 -0
  284. package/lib/org/ui-parity.test.mjs +348 -0
  285. package/lib/org/verify.mjs +176 -0
  286. package/lib/org/verify.test.mjs +194 -0
  287. package/lib/rag/embed.mjs +188 -0
  288. package/lib/rag/indexer.mjs +425 -0
  289. package/lib/rag/rag.test.mjs +505 -0
  290. package/lib/rag/search.mjs +475 -0
  291. package/lib/rate-guard.mjs +246 -0
  292. package/lib/rate-guard.test.mjs +201 -0
  293. package/lib/render.mjs +112 -0
  294. package/lib/render.test.mjs +68 -0
  295. package/lib/resource-governor.mjs +297 -0
  296. package/lib/resource-governor.test.mjs +262 -0
  297. package/lib/scheduling/dynamic-jobs.mjs +675 -0
  298. package/lib/scheduling/dynamic-jobs.test.mjs +344 -0
  299. package/lib/scheduling/jitter.mjs +0 -0
  300. package/lib/scheduling/jitter.test.mjs +140 -0
  301. package/lib/secrets/broker.mjs +315 -0
  302. package/lib/secrets/broker.test.mjs +280 -0
  303. package/lib/secrets/providers.mjs +461 -0
  304. package/lib/secrets/providers.test.mjs +274 -0
  305. package/lib/security/audit-engine.mjs +684 -0
  306. package/lib/security/audit-engine.test.mjs +389 -0
  307. package/lib/security/coerce-args.mjs +552 -0
  308. package/lib/security/coerce-args.test.mjs +281 -0
  309. package/lib/security/dangerous-tools.mjs +97 -0
  310. package/lib/security/dangerous-tools.test.mjs +68 -0
  311. package/lib/security/external-content.mjs +145 -0
  312. package/lib/security/external-content.test.mjs +67 -0
  313. package/lib/security/redact.mjs +592 -0
  314. package/lib/security/redact.test.mjs +441 -0
  315. package/lib/security/secret-equal.mjs +73 -0
  316. package/lib/security/secret-equal.test.mjs +55 -0
  317. package/lib/session-permissions.mjs +101 -0
  318. package/lib/session-permissions.test.mjs +100 -0
  319. package/lib/setup/claude-probe.mjs +74 -0
  320. package/lib/setup/completeness.mjs +175 -0
  321. package/lib/setup/completeness.test.mjs +110 -0
  322. package/lib/setup/context-pack.mjs +173 -0
  323. package/lib/setup/context-pack.test.mjs +89 -0
  324. package/lib/setup/enrich.mjs +277 -0
  325. package/lib/setup/enrich.test.mjs +115 -0
  326. package/lib/setup/enroll-from-cohort.mjs +441 -0
  327. package/lib/setup/enroll-from-cohort.test.mjs +233 -0
  328. package/lib/setup/integration.test.mjs +162 -0
  329. package/lib/setup/io.mjs +360 -0
  330. package/lib/setup/io.test.mjs +77 -0
  331. package/lib/setup/run-generator.mjs +81 -0
  332. package/lib/setup/runner.mjs +244 -0
  333. package/lib/setup/runner.test.mjs +132 -0
  334. package/lib/setup/sections/comms.mjs +173 -0
  335. package/lib/setup/sections/company.mjs +120 -0
  336. package/lib/setup/sections/enrich.mjs +138 -0
  337. package/lib/setup/sections/identity.mjs +182 -0
  338. package/lib/setup/sections/identity.test.mjs +140 -0
  339. package/lib/setup/sections/learning.mjs +153 -0
  340. package/lib/setup/sections/learning.test.mjs +81 -0
  341. package/lib/setup/sections/messaging.mjs +219 -0
  342. package/lib/setup/sections/messaging.test.mjs +127 -0
  343. package/lib/setup/sections/model.mjs +102 -0
  344. package/lib/setup/sections/operating-model.mjs +78 -0
  345. package/lib/setup/sections/org.mjs +475 -0
  346. package/lib/setup/sections/org.test.mjs +313 -0
  347. package/lib/setup/sections/orgmail.mjs +173 -0
  348. package/lib/setup/sections/orgmail.test.mjs +118 -0
  349. package/lib/setup/sections/recovery.mjs +159 -0
  350. package/lib/setup/sections/recovery.test.mjs +98 -0
  351. package/lib/setup/sections/tools.mjs +132 -0
  352. package/lib/setup/sections/verify.mjs +97 -0
  353. package/lib/setup/sot.mjs +205 -0
  354. package/lib/setup/sot.test.mjs +81 -0
  355. package/lib/setup/state.mjs +151 -0
  356. package/lib/setup/state.test.mjs +92 -0
  357. package/lib/singleton.js +229 -0
  358. package/lib/singleton.test.mjs +135 -0
  359. package/lib/telemetry/alerts.mjs +216 -0
  360. package/lib/telemetry/alerts.test.mjs +109 -0
  361. package/lib/telemetry/collect.mjs +512 -0
  362. package/lib/telemetry/collect.test.mjs +202 -0
  363. package/lib/tool-definitions-integration.test.mjs +83 -0
  364. package/lib/tool-definitions.js +738 -0
  365. package/lib/tool-definitions.test.mjs +437 -0
  366. package/lib/util/fetch-timeout.mjs +136 -0
  367. package/lib/util/fetch-timeout.test.mjs +202 -0
  368. package/lib/util/reconnect.mjs +343 -0
  369. package/lib/util/reconnect.test.mjs +369 -0
  370. package/lib/util/unhandled.mjs +205 -0
  371. package/lib/util/unhandled.test.mjs +216 -0
  372. package/lib/voice/context-loader.mjs +466 -0
  373. package/lib/voice/index.mjs +100 -0
  374. package/lib/voice/openai-realtime.mjs +510 -0
  375. package/lib/voice/outbound.mjs +542 -0
  376. package/lib/voice/outbound.test.mjs +69 -0
  377. package/lib/voice/post-call-brief.mjs +428 -0
  378. package/lib/voice/provider.mjs +52 -0
  379. package/lib/voice/session-rotation.mjs +257 -0
  380. package/lib/voice/stt.mjs +161 -0
  381. package/lib/voice/stt.test.mjs +226 -0
  382. package/lib/voice/tool-bridge.mjs +370 -0
  383. package/lib/voice/tts.mjs +104 -0
  384. package/lib/voice/twilio-sip-bridge.mjs +288 -0
  385. package/lib/voice/voice.test.mjs +990 -0
  386. package/mcp/README.md +80 -0
  387. package/package.json +151 -0
  388. package/plugins/maestro-skills/plugin.json +139 -0
  389. package/plugins/maestro-skills/skills/agents-observe.md +110 -0
  390. package/plugins/maestro-skills/skills/board-deck.md +68 -0
  391. package/plugins/maestro-skills/skills/books-close.md +77 -0
  392. package/plugins/maestro-skills/skills/brand-steward.md +121 -0
  393. package/plugins/maestro-skills/skills/calendar-plan.md +57 -0
  394. package/plugins/maestro-skills/skills/call-working-sessions.md +124 -0
  395. package/plugins/maestro-skills/skills/ccxray-diagnostics.md +91 -0
  396. package/plugins/maestro-skills/skills/claude-pace.md +61 -0
  397. package/plugins/maestro-skills/skills/code-review-graph.md +99 -0
  398. package/plugins/maestro-skills/skills/crm-pipeline.md +65 -0
  399. package/plugins/maestro-skills/skills/decision-brief.md +89 -0
  400. package/plugins/maestro-skills/skills/directory-hygiene.md +125 -0
  401. package/plugins/maestro-skills/skills/draft-comms.md +84 -0
  402. package/plugins/maestro-skills/skills/evening-wrap.md +53 -0
  403. package/plugins/maestro-skills/skills/files-find.md +65 -0
  404. package/plugins/maestro-skills/skills/generative-ui.md +228 -0
  405. package/plugins/maestro-skills/skills/hiring-triage.md +74 -0
  406. package/plugins/maestro-skills/skills/inbox-triage.md +61 -0
  407. package/plugins/maestro-skills/skills/mail-triage.md +86 -0
  408. package/plugins/maestro-skills/skills/morning-brief.md +54 -0
  409. package/plugins/maestro-skills/skills/native-artifacts.md +157 -0
  410. package/plugins/maestro-skills/skills/org-board.md +133 -0
  411. package/plugins/maestro-skills/skills/org-credential.md +68 -0
  412. package/plugins/maestro-skills/skills/org-recall.md +81 -0
  413. package/plugins/maestro-skills/skills/pipeline-review.md +76 -0
  414. package/plugins/maestro-skills/skills/regulatory-status.md +81 -0
  415. package/plugins/maestro-skills/skills/router-why.md +78 -0
  416. package/plugins/maestro-skills/skills/schedule-meeting.md +91 -0
  417. package/plugins/maestro-skills/skills/session-search.md +71 -0
  418. package/plugins/maestro-skills/skills/set-reminder.md +93 -0
  419. package/plugins/maestro-skills/skills/slack-followup.md +64 -0
  420. package/plugins/maestro-skills/skills/team-activity.md +86 -0
  421. package/plugins/maestro-skills/skills/weekly-memo.md +70 -0
  422. package/policies/action-classification.yaml +114 -0
  423. package/policies/ai-disclosure.yaml +294 -0
  424. package/policies/communication-style.md +139 -0
  425. package/policies/information-barriers.yaml +118 -0
  426. package/policies/prompt-injection-defence.yaml +138 -0
  427. package/public/assets/icon-dark.png +0 -0
  428. package/public/assets/icon-dark.svg +9 -0
  429. package/public/assets/icon-light.svg +9 -0
  430. package/public/assets/logo-dark.svg +15 -0
  431. package/public/assets/logo-light.svg +15 -0
  432. package/scaffold/.mcp.json +7 -0
  433. package/scaffold/CLAUDE.md +368 -0
  434. package/scaffold/config/agent.json +55 -0
  435. package/scaffold/config/agent.ts +76 -0
  436. package/scaffold/config/agent.ts.example +89 -0
  437. package/scaffold/config/alerts.yaml +23 -0
  438. package/scaffold/config/allowlist.yaml.example +25 -0
  439. package/scaffold/config/caller-id-map.yaml +46 -0
  440. package/scaffold/config/collective.yaml +49 -0
  441. package/scaffold/config/company.json +20 -0
  442. package/scaffold/config/known-agents.json +6 -0
  443. package/scaffold/config/learning.yaml +55 -0
  444. package/scaffold/config/model-routing.yaml.example +104 -0
  445. package/scaffold/config/org.yaml +25 -0
  446. package/scaffold/config/orgmail.yaml.example +19 -0
  447. package/scaffold/config/recovery.yaml +72 -0
  448. package/scaffold/config/secrets.yaml +27 -0
  449. package/scaffold/config/slack.yaml.example +35 -0
  450. package/scaffold/config/telegram.yaml.example +38 -0
  451. package/scaffold/config/voice.yaml.example +89 -0
  452. package/scaffold/config/whatsapp.yaml.example +39 -0
  453. package/schedules/README.md +49 -0
  454. package/schedules/triggers/backlog-executor.md +102 -0
  455. package/schedules/triggers/brand-steward.md +72 -0
  456. package/schedules/triggers/daily-evening-wrap.md +159 -0
  457. package/schedules/triggers/daily-midday-sweep.md +58 -0
  458. package/schedules/triggers/daily-morning-brief.md +55 -0
  459. package/schedules/triggers/directory-hygiene.md +81 -0
  460. package/schedules/triggers/dynamic-jobs.md +40 -0
  461. package/schedules/triggers/inbox-processor.md +115 -0
  462. package/schedules/triggers/meeting-action-capture.md +60 -0
  463. package/schedules/triggers/meeting-prep.md +69 -0
  464. package/schedules/triggers/messaging-inbound.md +50 -0
  465. package/schedules/triggers/org-pulse.md +24 -0
  466. package/schedules/triggers/quarterly-self-assessment.md +54 -0
  467. package/schedules/triggers/weekly-engineering-health.md +37 -0
  468. package/schedules/triggers/weekly-execution.md +65 -0
  469. package/schedules/triggers/weekly-hiring.md +53 -0
  470. package/schedules/triggers/weekly-priorities.md +38 -0
  471. package/schedules/triggers/weekly-strategic-memo.md +124 -0
  472. package/scripts/archive-email.sh +55 -0
  473. package/scripts/cadence/cadence-status.mjs +36 -0
  474. package/scripts/cadence/enqueue-cadence-tick.mjs +174 -0
  475. package/scripts/cadence/enqueue-cadence-tick.test.mjs +187 -0
  476. package/scripts/cadence/launchd-cadence-wrapper.sh +85 -0
  477. package/scripts/cadence/launchd-cloud-relay-wrapper.sh +95 -0
  478. package/scripts/cadence/launchd-socket-mode-wrapper.sh +95 -0
  479. package/scripts/ci/check-docs-accuracy.mjs +493 -0
  480. package/scripts/ci/check-docs-accuracy.test.mjs +409 -0
  481. package/scripts/ci/check-exports-exist.mjs +140 -0
  482. package/scripts/ci/check-files-exist.mjs +107 -0
  483. package/scripts/ci/check-no-build-artifacts.mjs +111 -0
  484. package/scripts/ci/check-no-build-artifacts.test.mjs +71 -0
  485. package/scripts/ci/check-no-confidential.mjs +198 -0
  486. package/scripts/ci/check-no-conflict-markers.mjs +169 -0
  487. package/scripts/ci/check-no-residual-identity.mjs +163 -0
  488. package/scripts/ci/check-no-residual-identity.test.mjs +89 -0
  489. package/scripts/ci/check-tarball-fidelity.mjs +205 -0
  490. package/scripts/ci/check-unresolved-tokens.mjs +83 -0
  491. package/scripts/ci/check.mjs +109 -0
  492. package/scripts/ci/check.test.mjs +194 -0
  493. package/scripts/ci/run-coverage.mjs +82 -0
  494. package/scripts/ci/run-tests.mjs +71 -0
  495. package/scripts/cloud-relay/README.md +59 -0
  496. package/scripts/cloud-relay/index.mjs +233 -0
  497. package/scripts/cloud-relay/package.json +15 -0
  498. package/scripts/cloud-relay/railway.json +13 -0
  499. package/scripts/cloud-relay/voice/README.md +94 -0
  500. package/scripts/cloud-relay/voice/package-lock.json +39 -0
  501. package/scripts/cloud-relay/voice/package.json +16 -0
  502. package/scripts/cloud-relay/voice/railway.json +13 -0
  503. package/scripts/cloud-relay/voice/server.mjs +532 -0
  504. package/scripts/collective/hook-runner.mjs +211 -0
  505. package/scripts/collective/hook-runner.test.mjs +90 -0
  506. package/scripts/collective/org-pulse.mjs +72 -0
  507. package/scripts/collective/org-sync.mjs +61 -0
  508. package/scripts/collective/recall.mjs +45 -0
  509. package/scripts/collective/who.mjs +30 -0
  510. package/scripts/comms-monitor.sh +288 -0
  511. package/scripts/configure-whatsapp-sandbox.sh +201 -0
  512. package/scripts/continuous-monitor.sh +91 -0
  513. package/scripts/cost/fleet-digest.mjs +407 -0
  514. package/scripts/cost/fleet-digest.test.mjs +207 -0
  515. package/scripts/cost/track-claude-usage.mjs +169 -0
  516. package/scripts/daemon/agent-daemon.mjs +989 -0
  517. package/scripts/daemon/agent-daemon.test.mjs +525 -0
  518. package/scripts/daemon/cadence-consumer-governance.test.mjs +220 -0
  519. package/scripts/daemon/cadence-consumer.mjs +1080 -0
  520. package/scripts/daemon/cadence-consumer.test.mjs +770 -0
  521. package/scripts/daemon/cadence-handlers.mjs +1121 -0
  522. package/scripts/daemon/cadence-handlers.test.mjs +617 -0
  523. package/scripts/daemon/classifier.mjs +704 -0
  524. package/scripts/daemon/classifier.test.mjs +238 -0
  525. package/scripts/daemon/classify-kind.mjs +54 -0
  526. package/scripts/daemon/classify-kind.test.mjs +40 -0
  527. package/scripts/daemon/context-compiler.mjs +605 -0
  528. package/scripts/daemon/context-compiler.test.mjs +300 -0
  529. package/scripts/daemon/dispatcher-cooldown.test.mjs +122 -0
  530. package/scripts/daemon/dispatcher-governance.test.mjs +886 -0
  531. package/scripts/daemon/dispatcher.mjs +1516 -0
  532. package/scripts/daemon/health.mjs +72 -0
  533. package/scripts/daemon/inbox-deferral.mjs +210 -0
  534. package/scripts/daemon/inbox-deferral.test.mjs +242 -0
  535. package/scripts/daemon/integration.test.mjs +149 -0
  536. package/scripts/daemon/launchd-wrapper-generic.sh +96 -0
  537. package/scripts/daemon/launchd-wrapper-slack-events.sh +37 -0
  538. package/scripts/daemon/launchd-wrapper.sh +91 -0
  539. package/scripts/daemon/lib/session-router.mjs +274 -0
  540. package/scripts/daemon/lib/session-router.test.mjs +295 -0
  541. package/scripts/daemon/maestro-daemon.mjs +275 -0
  542. package/scripts/daemon/prompt-builder.mjs +685 -0
  543. package/scripts/daemon/prompt-builder.test.mjs +213 -0
  544. package/scripts/daemon/responder.mjs +854 -0
  545. package/scripts/daemon/session-lock.mjs +721 -0
  546. package/scripts/daemon/session-lock.test.mjs +252 -0
  547. package/scripts/daemon/session-outcomes.mjs +640 -0
  548. package/scripts/daemon/session-outcomes.test.mjs +533 -0
  549. package/scripts/daemon/typing-registry.mjs +90 -0
  550. package/scripts/daemon/typing-registry.test.mjs +77 -0
  551. package/scripts/daemon/voice-webhook-server.mjs +804 -0
  552. package/scripts/decisions/capture-decision.mjs +116 -0
  553. package/scripts/disclosure_assessment.py +873 -0
  554. package/scripts/disclosure_boundaries.py +562 -0
  555. package/scripts/email-signature-principal.html +52 -0
  556. package/scripts/email-signature.html +60 -0
  557. package/scripts/email_quote_thread.py +167 -0
  558. package/scripts/email_thread_dedup.py +362 -0
  559. package/scripts/emergency-stop.sh +81 -0
  560. package/scripts/healthcheck.sh +116 -0
  561. package/scripts/hooks/block-mcp-cohort-send.sh +15 -0
  562. package/scripts/hooks/block-mcp-slack-send.sh +7 -0
  563. package/scripts/hooks/post-action-log.sh +126 -0
  564. package/scripts/hooks/pre-send-audit.sh +174 -0
  565. package/scripts/hooks/pre-send-audit.test.mjs +215 -0
  566. package/scripts/hooks/session-end-log.sh +27 -0
  567. package/scripts/hooks/session-start-banner.sh +115 -0
  568. package/scripts/huddle/audio-bridge.mjs +664 -0
  569. package/scripts/huddle/boot-slack-cdp.sh +102 -0
  570. package/scripts/huddle/huddle-controller.mjs +942 -0
  571. package/scripts/huddle/huddle-server.mjs +1229 -0
  572. package/scripts/huddle/launch-slack.sh +232 -0
  573. package/scripts/huddle/openai-realtime-bridge.mjs +462 -0
  574. package/scripts/huddle/package-lock.json +62 -0
  575. package/scripts/huddle/package.json +22 -0
  576. package/scripts/huddle/setup-audio.sh +239 -0
  577. package/scripts/huddle/start-call.mjs +318 -0
  578. package/scripts/huddle/test-pipeline.mjs +263 -0
  579. package/scripts/learning/consolidate-skills.mjs +72 -0
  580. package/scripts/learning/session-search.mjs +125 -0
  581. package/scripts/llm_email_dedup.py +442 -0
  582. package/scripts/local-triggers/generate-plists.sh +432 -0
  583. package/scripts/local-triggers/generate-plists.test.mjs +413 -0
  584. package/scripts/local-triggers/install-all.sh +49 -0
  585. package/scripts/local-triggers/plists/.gitkeep +0 -0
  586. package/scripts/local-triggers/run-trigger.sh +63 -0
  587. package/scripts/local-triggers/templates/rag-reindex.plist.template +47 -0
  588. package/scripts/local-triggers/templates/voice-relay-poller.plist.template +54 -0
  589. package/scripts/local-triggers/templates/voice-tunnel.plist.template +55 -0
  590. package/scripts/local-triggers/templates/voice-webhook.plist.template +51 -0
  591. package/scripts/maintenance/backup-to-cloud.sh +124 -0
  592. package/scripts/maintenance/health-check.sh +377 -0
  593. package/scripts/media-generation/README.md +105 -0
  594. package/scripts/media-generation/gemini-image-client.mjs +173 -0
  595. package/scripts/media-generation/generate-assets.mjs +289 -0
  596. package/scripts/media-generation/veo-video-client.mjs +219 -0
  597. package/scripts/org/send-orgmail.mjs +227 -0
  598. package/scripts/outbound-dedup-cleanup.sh +43 -0
  599. package/scripts/outbound-dedup.sh +477 -0
  600. package/scripts/outbound_dedup.py +115 -0
  601. package/scripts/parse-voice-transcript.mjs +481 -0
  602. package/scripts/pdf-generation/README.md +63 -0
  603. package/scripts/pdf-generation/build-document.mjs +247 -0
  604. package/scripts/pdf-generation/templates/board-pack.latex +136 -0
  605. package/scripts/pdf-generation/templates/corporate-letter.latex +126 -0
  606. package/scripts/pdf-generation/templates/memo.latex +114 -0
  607. package/scripts/poll-slack-events.sh +35 -0
  608. package/scripts/poller/calendar-poller.mjs +12 -0
  609. package/scripts/poller/gmail-poller.mjs +192 -0
  610. package/scripts/poller/imap-client.mjs +289 -0
  611. package/scripts/poller/inbox-scan-poller.mjs +156 -0
  612. package/scripts/poller/inbox-scan-poller.test.mjs +231 -0
  613. package/scripts/poller/index.mjs +73 -0
  614. package/scripts/poller/intra-session-check.mjs +285 -0
  615. package/scripts/poller/lib/cloud-relay-dedup.mjs +88 -0
  616. package/scripts/poller/lib/cloud-relay-dedup.test.mjs +133 -0
  617. package/scripts/poller/lib/slash-command-handlers.mjs +177 -0
  618. package/scripts/poller/secondary-gmail-poller.mjs +132 -0
  619. package/scripts/poller/slack-cloud-relay-client.mjs +368 -0
  620. package/scripts/poller/slack-poller.mjs +854 -0
  621. package/scripts/poller/slack-socket-mode.mjs +917 -0
  622. package/scripts/poller/slack-socket-mode.test.mjs +753 -0
  623. package/scripts/poller/trigger.mjs +75 -0
  624. package/scripts/poller/utils.mjs +371 -0
  625. package/scripts/poller/voice-cloud-relay-client.mjs +179 -0
  626. package/scripts/poller/voice-poller.mjs +236 -0
  627. package/scripts/poller-launchd/install.sh +66 -0
  628. package/scripts/poller-launchd/poller.plist.template +40 -0
  629. package/scripts/poller-launchd/whatsapp-handler.plist.template +39 -0
  630. package/scripts/post-interaction-indexer.py +1598 -0
  631. package/scripts/pre-draft-context.py +994 -0
  632. package/scripts/pre_draft_lookup.py +258 -0
  633. package/scripts/rag/build-index.mjs +47 -0
  634. package/scripts/rag/ingest.mjs +111 -0
  635. package/scripts/rag/search.mjs +119 -0
  636. package/scripts/rag-indexer.py +629 -0
  637. package/scripts/restore-from-backup.sh +248 -0
  638. package/scripts/restore-from-backup.test.mjs +178 -0
  639. package/scripts/resume-operations.sh +80 -0
  640. package/scripts/search-secondary-inbox.py +181 -0
  641. package/scripts/secondary-inbox-poller.py +437 -0
  642. package/scripts/self-optimization/compute-metrics.py +398 -0
  643. package/scripts/send-email-as-principal.py +369 -0
  644. package/scripts/send-email-threaded.py +392 -0
  645. package/scripts/send-email-with-attachment.py +377 -0
  646. package/scripts/send-email.sh +131 -0
  647. package/scripts/send-sms.sh +175 -0
  648. package/scripts/send-whatsapp.sh +292 -0
  649. package/scripts/session-start.sh +106 -0
  650. package/scripts/setup/boot-claude-session.sh +94 -0
  651. package/scripts/setup/configure-macos.sh +674 -0
  652. package/scripts/setup/configure-twilio-sip-trunk.mjs +207 -0
  653. package/scripts/setup/configure-voice-tunnel.mjs +182 -0
  654. package/scripts/setup/generate-agent-env.mjs +92 -0
  655. package/scripts/setup/generate-agent-package-json.mjs +222 -0
  656. package/scripts/setup/generate-agent-package-json.test.mjs +143 -0
  657. package/scripts/setup/generate-autonomy.mjs +60 -0
  658. package/scripts/setup/generate-backlog.mjs +101 -0
  659. package/scripts/setup/generate-cadences.mjs +92 -0
  660. package/scripts/setup/generate-capability.mjs +162 -0
  661. package/scripts/setup/generate-charter.mjs +76 -0
  662. package/scripts/setup/generate-comms.mjs +59 -0
  663. package/scripts/setup/generate-company.mjs +92 -0
  664. package/scripts/setup/init-agent.sh +547 -0
  665. package/scripts/setup/init-agent.test.mjs +151 -0
  666. package/scripts/setup/init-archetype.mjs +74 -0
  667. package/scripts/setup/init-backup.mjs +54 -0
  668. package/scripts/setup/init-cadence-bus.mjs +60 -0
  669. package/scripts/setup/init-channel-bus.mjs +46 -0
  670. package/scripts/setup/init-cost-tracking.mjs +45 -0
  671. package/scripts/setup/init-decision-capture.mjs +66 -0
  672. package/scripts/setup/init-known-agents.mjs +57 -0
  673. package/scripts/setup/init-learning.mjs +70 -0
  674. package/scripts/setup/init-memory-executive.mjs +45 -0
  675. package/scripts/setup/init-model-router.mjs +124 -0
  676. package/scripts/setup/init-rag.mjs +174 -0
  677. package/scripts/setup/init-session-router.mjs +38 -0
  678. package/scripts/setup/init-slack-socket-mode.mjs +260 -0
  679. package/scripts/setup/init-telegram.mjs +165 -0
  680. package/scripts/setup/init-voice-realtime.mjs +204 -0
  681. package/scripts/setup/init-whatsapp-baileys.mjs +77 -0
  682. package/scripts/setup/install-dev-tools.sh +150 -0
  683. package/scripts/setup/lib/install-plist.mjs +95 -0
  684. package/scripts/setup/migrate-agent-to-sot.mjs +192 -0
  685. package/scripts/setup/render-environment-yaml.mjs +133 -0
  686. package/scripts/slack-events-ctl.sh +177 -0
  687. package/scripts/slack-events-server.mjs +1045 -0
  688. package/scripts/slack-react.mjs +89 -0
  689. package/scripts/slack-responded.sh +232 -0
  690. package/scripts/slack-send.sh +287 -0
  691. package/scripts/slack-typing.mjs +196 -0
  692. package/scripts/slack-upload-v2.py +95 -0
  693. package/scripts/sms-handler.mjs +450 -0
  694. package/scripts/spawn-session.sh +120 -0
  695. package/scripts/sync-protocol.mjs +217 -0
  696. package/scripts/system-verify.sh +184 -0
  697. package/scripts/test-email-thread-dedup.py +239 -0
  698. package/scripts/test-information-barriers.py +484 -0
  699. package/scripts/test-llm-email-dedup.py +251 -0
  700. package/scripts/test-pre-draft-integration.py +203 -0
  701. package/scripts/test-rag-phase2.sh +442 -0
  702. package/scripts/test-rag-search.sh +251 -0
  703. package/scripts/test-voice-parser.mjs +316 -0
  704. package/scripts/user-context-search.py +659 -0
  705. package/scripts/validate_outbound.py +1504 -0
  706. package/scripts/watchdog/ai.maestro.memory-watchdog.plist +41 -0
  707. package/scripts/watchdog/force-reboot.sh +157 -0
  708. package/scripts/watchdog/memory-watchdog.sh +473 -0
  709. package/scripts/whatsapp-handler.mjs +538 -0
  710. package/teams/desktop-operations.yaml +34 -0
  711. package/teams/executive-office.yaml +27 -0
  712. package/teams/legal-and-regulatory.yaml +24 -0
  713. package/teams/platform-and-engineering.yaml +23 -0
  714. package/teams/strategy-and-growth.yaml +29 -0
  715. package/workflows/continuous/backlog-executor.yaml +141 -0
  716. package/workflows/continuous/inbound-monitor.yaml +168 -0
  717. package/workflows/daily/applicant-triage.yaml +197 -0
  718. package/workflows/daily/comms-triage.yaml +80 -0
  719. package/workflows/daily/evening-wrap.yaml +105 -0
  720. package/workflows/daily/morning-brief.yaml +164 -0
  721. package/workflows/daily/slack-followup-sweep.yaml +87 -0
  722. package/workflows/event-driven/README.md +50 -0
  723. package/workflows/event-driven/agent-failure-investigation.yaml +137 -0
  724. package/workflows/event-driven/pr-review.yaml +107 -0
  725. package/workflows/monthly/board-readiness.yaml +76 -0
  726. package/workflows/quarterly/strategic-scenario-analysis.yaml +85 -0
  727. package/workflows/session-protocol.md +171 -0
  728. package/workflows/weekly/engineering-health.yaml +154 -0
  729. package/workflows/weekly/hiring-review.yaml +169 -0
  730. package/workflows/weekly/rollup-pipeline-review.yaml +76 -0
  731. package/workflows/weekly/strategic-memo.yaml +79 -0
@@ -0,0 +1,1187 @@
1
+ # /init-maestro -- Configure a New Maestro Agent Identity
2
+
3
+ > **Deprecated (manual fallback).** The primary way to configure an agent is now
4
+ > the deterministic, resumable, self-verifying CLI wizard:
5
+ >
6
+ > ```
7
+ > maestro setup
8
+ > ```
9
+ >
10
+ > `maestro setup` validates and *verifies* itself (a shared completeness gate +
11
+ > a live capability table), survives interruption (resume from a checkpoint),
12
+ > and keeps `config/agent.json` as the single source of truth. Prefer it. This
13
+ > LLM-driven command is kept only as a manual fallback for bespoke / interactive
14
+ > setups; it is no longer advertised as the default path.
15
+
16
+ You are running the Maestro initialization wizard. This is the single most important command in the system -- it configures this repository as a fully operational autonomous AI agent.
17
+
18
+ This repo was created by `npx @cohortapp/agent-sdk create` and contains the Maestro framework. Your job is to bootstrap the system, give it an identity (a name, a role, responsibilities, and an operating style), configure external services, and bring it online. The wizard handles everything -- the user should not need to run any other setup commands.
19
+
20
+ ## Important Context
21
+
22
+ - The central config file is `config/agent.ts` -- this is the single source of truth for all identity values
23
+ - CLAUDE.md defines the agent's system prompt and operating instructions
24
+ - There are 31 agent definitions in `agents/`, 13 trigger prompts in `schedules/triggers/`, and config files throughout the repo
25
+ - The current agent identity must be fully replaced -- no references to the old agent should remain in critical files
26
+
27
+ ## Phase 0: System Bootstrap
28
+
29
+ Before gathering identity information, ensure the system is ready. Run these checks silently and only report issues:
30
+
31
+ ### Step 1: Prerequisites
32
+
33
+ Check that required tools are installed. Report any missing ones and offer to install them:
34
+
35
+ ```bash
36
+ # Check each — report OK or missing
37
+ node --version # Required: >= 20.0.0
38
+ npm --version # Required
39
+ claude --version # Required for triggers
40
+ jq --version # Required for hooks
41
+ ```
42
+
43
+ If Node.js or npm are missing, stop and tell the user to install them. If Claude CLI or jq are missing, warn but continue.
44
+
45
+ ### Step 2: Install dependencies
46
+
47
+ ```bash
48
+ npm install
49
+ ```
50
+
51
+ ### Step 3: Create directories
52
+
53
+ Ensure all operational directories exist (these should already exist from `maestro create`, but init-maestro may be re-run):
54
+
55
+ ```bash
56
+ # Create any missing state/log/memory directories
57
+ for dir in state/inbox/{slack,gmail,calendar,sms,whatsapp,internal,attachments,processed} \
58
+ state/{queues,dashboards,polling,handoffs,huddle,indexes,rag,sessions} \
59
+ state/{slack-responded,slack-thread-tracker,tmp} \
60
+ state/locks/outbound state/triggers/priority \
61
+ knowledge/{decisions,decisions/archive,entities,memory,sources,syntheses} \
62
+ memory/{interactions,indexes,templates} \
63
+ memory/profiles/{users,channels} \
64
+ memory/precedents/market-signals \
65
+ outputs/{briefs,drafts,memos,research,tasks,sessions} \
66
+ logs/{polling,workflows,sessions,audit,security,evolution,huddle,daemon} \
67
+ logs/{infra,monitor,phone,sms,whatsapp,email} \
68
+ self-optimization/scenarios tests; do
69
+ mkdir -p "$dir"
70
+ done
71
+ ```
72
+
73
+ ### Step 4: Global Claude Code settings
74
+
75
+ Install the global Claude Code settings to `~/.claude/settings.json`. Read the current content first — if it already exists and has substantive customisations, ask the user before overwriting. If it doesn't exist or is a default install, write it silently.
76
+
77
+ The template is in `scripts/setup/init-agent.sh` (the heredoc in Step 4 of that script). Extract and write it.
78
+
79
+ ### Step 5: Environment file
80
+
81
+ If `.env` doesn't exist, copy from `.env.example`:
82
+
83
+ ```bash
84
+ cp .env.example .env
85
+ ```
86
+
87
+ Tell the user: "I've created a .env file from the template. We'll fill in API keys during service configuration later."
88
+
89
+ ### Step 6: Report
90
+
91
+ Only print a summary if there were issues. If everything passed silently, just say:
92
+
93
+ ```
94
+ System bootstrap complete. Let's set up your agent.
95
+ ```
96
+
97
+ Then proceed to Phase 1.
98
+
99
+ ## Phase 1: Gather Information
100
+
101
+ Run a conversational wizard to collect the new agent's identity. Be friendly, encouraging, and clear. Ask questions in small groups (2-3 at a time), not as a wall of text. Confirm values as you go.
102
+
103
+ ### Step 1: Welcome and Name
104
+
105
+ Start with a warm welcome, then ask for the basics:
106
+
107
+ ```
108
+ Welcome to Maestro -- let's set up your new AI agent.
109
+
110
+ First, the fundamentals:
111
+ 1. What is the agent's first name? (e.g., "Jacob", "Ravi", "Isla")
112
+ 2. What is the agent's last name? (e.g., "Chen", "Patel", "Roselli")
113
+ 3. What is their job title? (e.g., "Chief AI Scientist", "Head of Engineering")
114
+ 4. What is their email address? (e.g., jordan@example.com)
115
+ ```
116
+
117
+ ### Step 2: Role Archetype — Function × Altitude
118
+
119
+ Maestro models an archetype on TWO orthogonal axes, which the archetype library
120
+ (`~/maestro/archetypes/`, resolved by `~/maestro/lib/archetype.mjs`) composes
121
+ into a full operating model. Ask the user to choose ONE of each:
122
+
123
+ - **Function** — WHAT the agent owns: control towers, tools, skills, templates,
124
+ KPI categories, backlog streams.
125
+ - **Altitude** — HOW senior / how it operates: autonomy bands, decision-rights
126
+ authority, escalation thresholds, KPI altitude, backlog granularity, tone.
127
+
128
+ ```
129
+ First, the FUNCTION — what does this agent own?
130
+
131
+ 1. executive-operator — Chief of Staff / COO / GM / founder's operator (cross-functional)
132
+ 2. technical-leader — CTO / VP-Eng / Eng Manager: architecture, delivery, reliability, R&D
133
+ 3. commercial-leader — Sales / BD / IR / partnerships / revenue
134
+ 4. compliance-officer — Legal / regulatory / risk / licensing
135
+ 5. product-leader — product roadmap, UX, product-market fit, metrics
136
+ 6. operations-leader — ops / fund-ops / HR-ops / vendors / resilience
137
+
138
+ Then, the ALTITUDE — how senior is this agent?
139
+
140
+ a. founder — owner-level; broadest autonomy; sets direction, answers to the board
141
+ b. c-suite — officer; org-wide function; board-facing
142
+ c. svp — senior leader / Head-of; high autonomy within the domain
143
+ d. vp — owns a sub-function; escalates strategic & cross-functional matters
144
+ e. senior-manager — owns a team/workstream; hands-on; escalates more
145
+
146
+ Which function (1–6) and which altitude (a–e)?
147
+ ```
148
+
149
+ The seniority roles a user may have in mind decompose cleanly into cells:
150
+ **Head of Operations** = `operations-leader × svp`; **Startup Founder** =
151
+ `executive-operator × founder`; **VP of Engineering** = `technical-leader × vp`;
152
+ a **CTO** = `technical-leader × c-suite`; a **Senior Compliance Manager** =
153
+ `compliance-officer × senior-manager`.
154
+
155
+ Record BOTH `function` and `altitude`. Do NOT hand-author towers, principles,
156
+ autonomy, KPIs, or backlog streams — the library is the single source of truth;
157
+ later phases resolve and render them. To see the available ids, run:
158
+ `node -e "import('${HOME}/maestro/lib/archetype.mjs').then(m=>console.log('functions:',m.listFunctions(),'\naltitudes:',m.listAltitudes()))"`
159
+
160
+ ### Step 3: Responsibilities and Principles
161
+
162
+ Ask for the agent's key responsibilities:
163
+
164
+ ```
165
+ What are this agent's key responsibilities? List 3-7 bullet points describing
166
+ what they do day-to-day.
167
+
168
+ (If you'd like, I can generate defaults based on the archetype you chose.)
169
+ ```
170
+
171
+ Operating principles are NO LONGER hand-entered here — they are resolved from the
172
+ archetype library (base ⊕ function ⊕ altitude `operatingPrinciples`) and rendered
173
+ into the charter by `generate-charter.mjs`. Only ask the user for principles if
174
+ they want to ADD to or override the resolved defaults; otherwise proceed.
175
+
176
+ ### Step 4: Company Context
177
+
178
+ The single most important input for role-true output — the charter, backlog,
179
+ capabilities, cadences, and comms all build on it. Ask in small groups; offer
180
+ the current `config/agent.ts` values as defaults. Populate `config/company.json`
181
+ as you go (it is the company SoT).
182
+
183
+ ```
184
+ Identity
185
+ 1. Company name (trading), and legal name if different?
186
+ 2. Website / primary domain?
187
+ 3. Industry / sector?
188
+
189
+ What the company does
190
+ 4. One-line description — what does the company do?
191
+ 5. A detailed overview — mission, what you build/sell, business model (a paragraph or more)?
192
+ 6. Main products / services?
193
+
194
+ Shape
195
+ 7. Stage and size — startup / scaleup / growth / enterprise; approx headcount; funding stage?
196
+ 8. Where do you operate — HQ plus key markets?
197
+ 9. Are you regulated? Which regimes / regulators (if any)?
198
+
199
+ Strategy & people
200
+ 10. Top 3–5 strategic priorities right now?
201
+ 11. Key people / leadership (names + roles) — especially this agent's principal and key stakeholders?
202
+ 12. Main competitors / market position? (optional)
203
+ ```
204
+
205
+ **Context sources — DO THESE; they are the difference between generic and role-true:**
206
+
207
+ 13. **GitHub repos on this machine.** Ask: "Are there repos on this machine I should analyse for
208
+ context? Give me the paths." For each, read the README, the package/manifest, the top-level
209
+ structure, and the recent commit log; extract products, stack, and themes. Record paths in
210
+ `config/company.json` → `repos`.
211
+ 14. **Company docs.** Ask the user to drop strategy/deck/overview/org-chart files into
212
+ `docs/company-context/` (see README § Company context), then read each and fold it into the
213
+ overview. Record the filenames in `config/company.json` → `contextDocs`.
214
+ 15. **Tools/systems** they use (Slack, GitHub, a CRM, Google Workspace, …) — informs the MCP/plugin
215
+ and channel configuration in Phase 2.5 / Phase 4.
216
+
217
+ Write everything gathered to `config/company.json`, then synthesise + enrich the brief:
218
+
219
+ ```bash
220
+ node scripts/setup/generate-company.mjs # renders docs/company/overview.md from config/company.json
221
+ ```
222
+
223
+ Enrich the `description` / `overview` and the generated overview doc from the repo + docs analysis.
224
+ `config/company.json` is the SoT every downstream generator (charter, backlog, comms, and the CLAUDE.md
225
+ "Company Context" section) reads, and `{{company.*}}` tokens in framework prompts resolve from it.
226
+
227
+ ### Step 5: Principal (Reporting Line)
228
+
229
+ ```
230
+ Who does this agent report to?
231
+
232
+ 1. Principal's full name (e.g., "Alex Chen")
233
+ 2. Principal's title (e.g., "CEO")
234
+ 3. Principal's email (e.g., alex@example.com)
235
+ ```
236
+
237
+ ### Step 6: Machine and Timezone
238
+
239
+ ```
240
+ A few deployment details:
241
+
242
+ 1. Mac mini hostname (e.g., "jacob-mini") -- defaults to {firstname}-mini
243
+ 2. Timezone (IANA format, e.g., "America/New_York") -- defaults to current value
244
+ ```
245
+
246
+ ### Step 7: Communication Style
247
+
248
+ ```
249
+ How should this agent communicate?
250
+
251
+ 1. Default tone: formal / warm-professional / casual (default: warm-professional)
252
+ 2. Any custom voice modes beyond the standard four (agent, principal, internal, institutional)?
253
+ ```
254
+
255
+ ### Step 8: Optional Contact Details
256
+
257
+ ```
258
+ Optional -- skip any you don't have yet:
259
+
260
+ 1. Agent phone number (E.164 format, e.g., +16282656712) -- for Twilio SMS/WhatsApp
261
+ 2. Agent Slack member ID (e.g., U097N5R0M7U) -- for mentions and DM routing
262
+ ```
263
+
264
+ ### Step 9: Confirmation
265
+
266
+ Before executing, display a full summary of all gathered values and ask for confirmation:
267
+
268
+ ```
269
+ Here is the complete configuration for the new agent:
270
+
271
+ Name: {firstName} {lastName}
272
+ Title: {title}
273
+ Email: {email}
274
+ Archetype: {function} × {altitude}
275
+ Company: {company} ({companyDomain})
276
+ Principal: {principalName}, {principalTitle}
277
+ Machine: {machineName}
278
+ Timezone: {timezone}
279
+ Tone: {defaultTone}
280
+ Phone: {phone || "not set"}
281
+ Slack ID: {slackMemberId || "not set"}
282
+
283
+ Responsibilities:
284
+ - {each responsibility}
285
+
286
+ Operating Principles:
287
+ - {each principle}
288
+
289
+ Does this look correct? (yes to proceed, or tell me what to change)
290
+ ```
291
+
292
+ ## Phase 2: Execute Changes
293
+
294
+ Once the user confirms, deploy SEVEN sub-agents in parallel using the Agent tool with `run_in_background: true` (sub-agent 8 is retired — the operating model + capability surface are generated next, in Phase 2.5). Announce what you are doing:
295
+
296
+ ```
297
+ Deploying 7 parallel agents to rewrite the repository identity. The operating model and capability surface are generated next (Phase 2.5). This will take a minute or two...
298
+ ```
299
+
300
+ ### Sub-agent 1: Update config/agent.ts
301
+
302
+ **Instruction to sub-agent:** Read `config/agent.ts` and rewrite it with all the gathered values. Preserve the file structure, TypeScript types, JSDoc comments, and derived values section exactly. Only change the literal values in the `agent` object. Update:
303
+
304
+ - firstName, lastName, fullName, title, **function** + **altitude** (the two archetype axes from Step 2; also set the derived legacy `archetype` = the function id for back-compat). Do NOT hand-author towers / principles / autonomy / KPIs / backlog — those resolve from the archetype library in Phase 2.5.
305
+ - email, phone, slackMemberId
306
+ - company, companyDomain, companyDescription
307
+ - principal object (firstName, lastName, fullName, title, email -- keep slackMemberId as empty string unless provided)
308
+ - machineName, launchdLabelPrefix (ai.maestro.{lowercase-firstname})
309
+ - timezone
310
+ - communication.defaultTone, communication.externalTone (set based on archetype -- compliance/institutional roles default to formal)
311
+ - communication.voiceModes (update labels: "Agent's voice" -> "{firstName}'s voice", "Principal's voice" -> "{principalFirstName}'s voice")
312
+ - responsibilities array
313
+ - operatingPrinciples array
314
+
315
+ ### Sub-agent 2: Rewrite CLAUDE.md
316
+
317
+ **Instruction to sub-agent:** Read `CLAUDE.md` and rewrite ONLY the identity-related sections. Keep all infrastructure sections intact (Repository Layout, Build & Test, Control Towers, Operating Modes, etc.).
318
+
319
+ Sections to rewrite:
320
+ - **## Identity** -- New agent name, title, role description. Write 2-3 sentences describing who this agent is and what they do.
321
+ - **## Operating Principles** -- Replace with the new principles. Use the same numbered-list format.
322
+ - **## Communication Rules** -- Adapt the autonomy model to the archetype. An executive-operator has broad autonomy; a compliance-officer escalates more. Rewrite the "sends autonomously" and "escalates" sections with the new agent's name and appropriate boundaries. Keep the Immediate Acknowledgement Rule, Document Sharing, and Logging subsections but replace the agent name throughout.
323
+ - **## People (Key Leadership)** -- Update the "That's you" line to the new agent. Keep other people entries unless the user indicated changes.
324
+ - **## Control Towers** -- Replace the 12 generic org-wide control towers with 8-10 towers scoped to the agent's specific role and domain. Each tower should reflect what this agent actually monitors and manages. Generate towers based on archetype:
325
+ - **executive-operator**: Keep the original 12 org-wide towers (they are appropriate for this archetype).
326
+ - **technical-leader**: Model/platform architecture, R&D strategy, engineering quality, platform delivery, infrastructure & scalability, security & compliance, performance & benchmarking, team growth, systems & automation, self-governance.
327
+ - **commercial-leader**: Pipeline management, partnership development, investor relations, market intelligence, revenue operations, competitive analysis, client success, commercial governance, systems & automation, self-governance.
328
+ - **compliance-officer**: Regulatory submissions, licence management, policy framework, audit readiness, risk register, cross-jurisdiction compliance, legal obligations, reporting & disclosure, systems & automation, self-governance.
329
+ - **product-leader**: Product roadmap, user research & insights, feature delivery, design system, product-market fit, metrics & analytics, cross-functional alignment, stakeholder communication, systems & automation, self-governance.
330
+ - **operations-leader**: Process efficiency, fund operations, vendor management, capacity planning, organisational design, SLA compliance, cost management, operational resilience, systems & automation, self-governance.
331
+ Each tower should have a brief description of what it monitors (same format as the original: `**Name** — description`).
332
+
333
+ Replace ALL instances of the old agent's first name with the new agent's first name throughout the entire CLAUDE.md file. Be thorough -- check every section header, bullet point, and inline reference.
334
+
335
+ Do NOT modify these sections (keep them exactly as they are, except for agent name substitution):
336
+ - Repository Layout, Key Config Files, Brand Assets, PDF Generation, Visual Media Generation
337
+ - Source Repositories, Hiring Management (unless archetype is not executive-operator, in which case trim or adapt)
338
+ - Operational Infrastructure
339
+ - Build & Test, Code Standards, Three Operating Modes, Parallel Execution
340
+ - Agent Development, Workflow Development
341
+
342
+ ### Sub-agent 3: Update config files
343
+
344
+ **Instruction to sub-agent:** Update these configuration files:
345
+
346
+ 1. **config/environment.yaml** -- Replace agent name, email, phone, directory paths, and scheduling references. Update timezone.
347
+
348
+ 2. **config/contacts.yaml** -- Update the principal's entry to match the new principal details. Keep other contacts unless the archetype suggests they are irrelevant. Add the new agent as a contact entry.
349
+
350
+ 3. **config/priorities.yaml** -- Generate 4-6 strategic priorities appropriate for the role archetype:
351
+ - executive-operator: operational excellence, communication cadence, strategic execution, hiring, institutional memory
352
+ - technical-leader: platform architecture, engineering quality, technical debt, R&D pipeline, delivery velocity
353
+ - commercial-leader: pipeline growth, partnership development, investor relations, market positioning, commercial operations
354
+ - compliance-officer: regulatory submissions, licence maintenance, policy framework, audit readiness, cross-jurisdiction compliance
355
+ - product-leader: product roadmap, user research, feature delivery, product-market fit, design system
356
+ - operations-leader: process automation, operational efficiency, fund operations, organisational design, vendor management
357
+
358
+ ### Sub-agent 4: Update package.json, scripts, and identity-baked content
359
+
360
+ **Instruction to sub-agent:**
361
+
362
+ 1. **package.json** -- Update the `name` field to `maestro` (or keep current if already correct). Update `description` to reflect the new agent's role (e.g., "Autonomous AI Chief Scientist for your company").
363
+
364
+ 2. **Shell scripts** -- Search all files in `scripts/` for references to the old agent name (case-insensitive) and replace with the new agent name. Specifically target:
365
+ - Variable names like `SOPHIE_AI_DIR` -> `{UPPER_FIRSTNAME}_AI_DIR`
366
+ - Path references like `/Users/sophie/sophie-ai` -> `/Users/{lowercase-firstname}/{repoSlug}`
367
+ - LaunchD labels like `ai.maestro.sophie-` -> `ai.maestro.{lowercase-firstname}-`
368
+ - Pronouns: if the new agent's gender differs from the scaffolding template, update he/she/him/her/his/hers/himself/herself across system prompts, comments, and documentation. Be surgical — do NOT change pronouns inside generic regex patterns or third-party detection logic.
369
+
370
+ 3. **LaunchD plists** in `scripts/local-triggers/plists/` -- Update labels and paths in all `.plist` files.
371
+
372
+ 4. **Identity-baked content rewrites (CRITICAL — full overwrites, not grep-replace).** These files contain the agent's outbound identity (name, title, email, phone, signature) and MUST be fully rewritten with the new agent's values. Do not rely on grep-replace alone — read each file, then OVERWRITE it with content that uses these exact values:
373
+
374
+ - `firstName + lastName` (e.g., "Lucas Ferreira")
375
+ - `title` (e.g., "VP, Regulatory & Licensing")
376
+ - `email` (from config/agent.json → email)
377
+ - `phone` (use the spaced pretty form for human-facing display, the E.164 form for code)
378
+ - `companyName` (from **config/company.json → name** — never hardcode a company)
379
+ - `companyAddress` (the company's primary office from config/company.json; ask the user if absent)
380
+
381
+ **Files to rewrite:**
382
+
383
+ a. **`scripts/email-signature.html`** — The HTML signature appended to all outbound emails by `send-email.sh` and the Python send scripts. Must contain: name (bold, 14px), title (grey, 13px), the company logo (from config/company.json / brand assets — omit the logo line if none), email, phone, company address line, full confidentiality disclaimer footer. Pattern matches the template in `~/maestro/scripts/email-signature.html` — use placeholders {{AGENT_NAME}}, {{AGENT_TITLE}}, {{AGENT_EMAIL}}, {{AGENT_PHONE}}, {{COMPANY_ADDRESS}} and substitute them.
384
+
385
+ b. **`scripts/email-signature-principal.html`** — Principal's signature block (used by `send-email-as-principal.py` or equivalent send-as-principal scripts). Update with the principal's values: `principal.fullName`, `principal.title`, `principal.email`. If the principal doesn't have a phone in config/agent.ts, omit the phone line.
386
+
387
+ c. **`scripts/send-email.sh`** — Hardcoded `From:` header and inline signature fallback. Update both. The From header should be in the form `"{fullName}" <{email}>` (from config/agent.json).
388
+
389
+ d. **`scripts/send-email-threaded.py`** — `USER`, `From` header construction, inline signature, argparse description. All must reflect the new agent.
390
+
391
+ e. **`scripts/send-email-with-attachment.py`** — Same as above.
392
+
393
+ f. **`scripts/pdf-generation/build-document.mjs`** — Default `author` value (used in PDF metadata) and the help text describing the default. Set to the new agent's full name.
394
+
395
+ g. **`scripts/pdf-generation/templates/memo.latex`** — Footer line "Prepared by ... Chief of Staff" — replace with "Prepared by {fullName}, {title}".
396
+
397
+ h. **`scripts/daemon/responder.mjs` `FALLBACK_PREAMBLE`** — System prompt that introduces the agent to Claude. Identity intro line must reference the new agent. Preserve the operational rules.
398
+
399
+ i. **`scripts/daemon/prompt-builder.mjs` `FALLBACK_PREAMBLE`** — Same treatment.
400
+
401
+ j. **`scripts/daemon/classifier.mjs` `SYSTEM_PROMPT`** — Identity intro line. Preserve everything else.
402
+
403
+ k. **`scripts/huddle/huddle-server.mjs` `HUDDLE_SYSTEM_PROMPT`** — Voice agent identity line.
404
+
405
+ l. **`scripts/spawn-session.sh`** — Sub-session bootstrap prompt that names the agent.
406
+
407
+ m. **`scripts/continuous-monitor.sh`** — Channel monitor agent prompt.
408
+
409
+ n. **`scripts/llm_email_dedup.py`, `scripts/comms-monitor.sh`, `scripts/archive-email.sh`, `scripts/poller/gmail-poller.mjs`, `scripts/poller/imap-client.mjs`** — Hardcoded `LUCAS_EMAIL`/`USER`/`gmail_user` constants. Set to the new agent's email.
410
+
411
+ o. **`scripts/{firstname}-inbox-poller.py`** — Rename file from `sophie-inbox-poller.py` (or current scaffolding name) to `{firstname}-inbox-poller.py`. Update internal `LUCAS_EMAIL` constant. Update any plist references to the new filename.
412
+
413
+ p. **`scripts/rag-indexer.py`, `scripts/user-context-search.py`** — Author docstring at the top. Set to the new agent's full name.
414
+
415
+ q. **`scripts/validate-outbound.py`** — Test/regex references to the placeholder agent name "Robin Hayes" or `lookup_entity("Robin Hayes")`. Replace with the new agent's full name. Leave the generic third-party pronoun regex (around line 1007) UNCHANGED — it's a detector, not an identity reference.
416
+
417
+ **Verification step (identity AND company):** After rewrites, run `grep -rniE "robin|alex|jordan|northwind" scripts/ config/ agents/ policies/ 2>&1` and confirm NO placeholder identity remains — neither the placeholder persona (Robin / Alex) NOR the placeholder company ("Northwind"). Everything must be the new agent + the company from `config/company.json`. Report any remaining matches you cannot safely auto-resolve so the main agent can decide.
418
+
419
+ ### Sub-agent 5: Update agent definitions
420
+
421
+ **Instruction to sub-agent:**
422
+
423
+ 1. **Rename the core agent directory**: `agents/sophie-chief-of-staff` -> `agents/{lowercase-firstname}-{role-slug}` (e.g., `agents/jacob-chief-ai-scientist`). Derive the role slug from the title by lowercasing and hyphenating.
424
+
425
+ 2. **Rewrite the core agent's agent.md**: Update the name, title, mandate, and responsibilities to match the new agent identity.
426
+
427
+ 3. **Review all 31 agent directories** in `agents/`. For each:
428
+ - If the agent is generic infrastructure (inbound-dispatcher, session-spawner, workflow-automation, browser-operator, desktop-operator, slack-operator, gmail-operator, whatsapp-operator, calendar-ops, decision-log, communications, pmo-execution): Keep it, but replace any references to the old agent name in its agent.md.
429
+ - If the agent is role-specific to the old identity and relevant to the new role: Adapt it (e.g., ceo-briefing might become cto-briefing for a technical-leader).
430
+ - If the agent is role-specific and NOT relevant: Leave a note in the file that it needs review, but do not delete it.
431
+
432
+ ### Sub-agent 6: Update triggers and workflows
433
+
434
+ **Instruction to sub-agent:**
435
+
436
+ 1. **Trigger prompts** in `schedules/triggers/` -- Read each `.md` file and replace all references to the old agent name with the new agent name. Adapt the trigger content where the old agent's role is referenced (e.g., "Robin's morning brief" -> "{firstName}'s morning brief").
437
+
438
+ 2. **Workflow configs** in `workflows/` -- Update any agent name references.
439
+
440
+ 3. Keep the cadence structure intact (morning brief, midday sweep, evening wrap, backlog executor, etc.) -- these are generic patterns that work for any agent.
441
+
442
+ ### Sub-agent 7: Update README and miscellaneous
443
+
444
+ **Instruction to sub-agent:**
445
+
446
+ 1. **README.md** -- Rewrite the repository README to reflect the new agent's identity. Keep the structure but update the agent name, role description, and any old-agent-specific language.
447
+
448
+ 2. **Any other files** that reference the old agent by name in `docs/`, `teams/`, or root-level markdown files. Do a thorough search and replace.
449
+
450
+ ### Sub-agent 8: (retired)
451
+
452
+ Capability-surface generation — tools, **Claude Code skills**, **workflows**,
453
+ the **expansive 40–60 role sub-agents**, **MCP servers / plugins**, and the
454
+ **event→capability usage map** — is no longer a shallow parallel sub-agent. It is
455
+ performed comprehensively in **Phase 2.5, Step 5** below, driven by the archetype
456
+ library's capability pack + the gathered context pack. Skip this slot.
457
+
458
+ ## Phase 2.5: Generate the Operating Model & Capability Surface
459
+
460
+ After the parallel rewrite has written `config/agent.json` with `{ function, altitude }`,
461
+ generate the agent's complete operating model and capability surface FROM THE
462
+ ARCHETYPE LIBRARY (`~/maestro/archetypes/`, resolved by `lib/archetype.mjs`) —
463
+ deterministic skeletons + LLM enrichment for company-specific substance. Run in order;
464
+ everything generated is shown to the user for review before it goes live.
465
+
466
+ ### Step 1 — Resolve & validate the archetype
467
+ ```bash
468
+ node scripts/setup/init-archetype.mjs
469
+ ```
470
+ Normalises `{ function, altitude }`, resolves + validates the profile. If it fails, stop and fix.
471
+
472
+ ### Step 2 — Gather the strategic context pack (hybrid interview + research)
473
+ Conduct a focused interview (ask only what you cannot infer): the mandate the
474
+ principal is giving this agent; company stage + top 3–5 priorities; key people /
475
+ stakeholders + relationships; any docs/repos to read. THEN research the company /
476
+ market / comparable-role norms (web + available MCP + RAG over provided docs).
477
+ Write the structured result to `state/init/context-pack.json` — every generator below consumes it.
478
+
479
+ ### Step 3 — Operating charter
480
+ ```bash
481
+ node scripts/setup/generate-charter.mjs # renders config/operating-charter.md from the profile
482
+ ```
483
+ Then ENRICH the company-specific slots (mandate, named stakeholders, KPI targets, first-90)
484
+ from the context pack, and generate a branded PDF via the pdf pipeline.
485
+
486
+ ### Step 4 — Seeded WBS backlog
487
+ ```bash
488
+ node scripts/setup/generate-backlog.mjs # state/backlog/wbs.yaml + state/queues/backlog.yaml + config/priorities.yaml
489
+ ```
490
+ Then ENRICH the WBS epics/tasks with company-specific work from the context pack and
491
+ re-run to re-materialise, so the backlog-executor has real, role-true work on the first tick.
492
+
493
+ ### Step 5 — Capability surface (COMPREHENSIVE — this is what lets the agent ACT)
494
+ ```bash
495
+ node scripts/setup/generate-capability.mjs # renders the full roster + skills + workflows + event-routing + mcp declaration
496
+ ```
497
+ This resolves the archetype's **capability pack** from the library and renders skeletons for
498
+ ALL of the below. THEN ENRICH each artifact with company-specific substance — a parallel
499
+ workflow LLM-tailors the 40–60 agent mandates, skill procedures, and workflow steps to the
500
+ context pack. The generator produces (and you enrich):
501
+
502
+ a. **Sub-agents (expansive — target 40–60 role-tailored, plus the standard defaults).**
503
+ Compose the full sub-agent roster:
504
+ - KEEP the STANDARD default sub-agents that ship from `~/maestro/agents/` (generic
505
+ infrastructure every agent needs: inbox-processor, session-spawner, dispatcher,
506
+ channel operators, decision-log, pmo-execution, …);
507
+ - PLUS generate a LARGE role-tailored set (target **40–60**) from the function's
508
+ `agentTeams` capability pack — one sub-agent per role across the function's teams,
509
+ with breadth/depth scaled by altitude (founder/C-suite field more delegated teams;
510
+ senior-manager fewer, more hands-on). Each sub-agent gets a full `agents/<id>/agent.md`
511
+ (mandate, tools, model tier, towers served, decision rights), tailored to the company.
512
+ b. **Skills.** Generate the role's Claude Code skills under `plugins/agent-skills/skills/`
513
+ (the procedures the agent runs) from the skill pack + responsibilities; write `plugin.json`.
514
+ c. **Workflows.** Generate the role's workflow definitions under `workflows/`
515
+ (daily/weekly/monthly/quarterly/continuous/event-driven) from the workflow pack.
516
+ d. **MCP servers / plugins.** Install + configure the MCP servers and Claude Code plugins
517
+ the role needs (from the `mcpServers` pack — e.g. technical-leader → GitHub/code MCP;
518
+ commercial-leader → CRM MCP; compliance-officer → filings/registry MCP). Wire into `.claude`.
519
+ e. **Usage mapping (event → capability).** Write `config/event-routing.yaml` mapping incoming
520
+ task/request/event types → the skill, workflow, or sub-agent that handles them, so the
521
+ daemon routes work to the right capability.
522
+
523
+ ### Step 6 — Acceptance gate
524
+ ```bash
525
+ npx @cohortapp/agent-sdk doctor
526
+ ```
527
+ Confirm the operating-model gate passes: archetype resolves; charter present & enriched
528
+ (no `TBD` / `{{}}`); priorities populated; backlog seeded (≥5 open items); capability
529
+ surface generated (sub-agents, skills, workflows, MCP, routing). The agent is not "done"
530
+ until it can actually work.
531
+
532
+ ## Phase 3: Machine Configuration
533
+
534
+ After identity rewriting completes, generate and install the launchd plists (these need the agent name from Phase 1).
535
+
536
+ The plists generated here use the **cadence bus architecture** (maestro 1.8+): scheduled cadence ticks no longer spawn a fresh Claude Code session per tick. Instead, launchd invokes `scripts/cadence/enqueue-cadence-tick.mjs` (≈10 ms, no Claude) which drops a JSON event onto `state/cadence-bus/inbox/`. The persistent daemon (started by the `*-daemon` plist) drains the bus and decides — per cadence — whether to handle the tick inline or escalate to a managed sub-session.
537
+
538
+ ### Step 1: Generate launchd plists
539
+
540
+ ```bash
541
+ bash scripts/local-triggers/generate-plists.sh
542
+ ```
543
+
544
+ This reads `config/agent.ts` to get the agent's first name and generates all 13 launchd plist files with correct labels and paths. Every plist carries the `maestro-plist-arch: cadence-bus v1` marker.
545
+
546
+ ### Step 2: Install launchd agents
547
+
548
+ ```bash
549
+ LAUNCH_AGENTS_DIR="$HOME/Library/LaunchAgents"
550
+ mkdir -p "$LAUNCH_AGENTS_DIR"
551
+ for plist in scripts/local-triggers/plists/*.plist; do
552
+ PLIST_NAME=$(basename "$plist")
553
+ LABEL=$(basename "$plist" .plist)
554
+ DST="$LAUNCH_AGENTS_DIR/$PLIST_NAME"
555
+ launchctl unload "$DST" 2>/dev/null || true
556
+ cp "$plist" "$DST"
557
+ launchctl load "$DST"
558
+ done
559
+ ```
560
+
561
+ Report how many triggers were installed.
562
+
563
+ ### Step 2b: Cadence bus smoke test (verifies end-to-end delivery)
564
+
565
+ ```bash
566
+ # Enqueue a heartbeat tick and confirm the daemon drained it.
567
+ node scripts/cadence/enqueue-cadence-tick.mjs cadence-bus-heartbeat --source=init-maestro
568
+ sleep 4
569
+ node scripts/cadence/cadence-status.mjs
570
+ ```
571
+
572
+ The heartbeat must show `depth.inbox: 0` and a fresh `health.ts` within the last minute. If not, check `logs/cadence-bus/<date>.jsonl` and `logs/daemon/launchd-stderr.log`.
573
+
574
+ ### Step 3: macOS headless configuration (optional)
575
+
576
+ Offer to configure the Mac mini for headless 24/7 operation:
577
+
578
+ ```
579
+ Would you like to configure the Mac mini for headless operation?
580
+
581
+ This will (requires sudo):
582
+ 1. Enable auto-login (no password on reboot)
583
+ 2. Disable sleep/standby/screen saver
584
+ 3. Configure Parsec for remote desktop access
585
+ 4. Set up Slack with CDP for huddle automation
586
+ 5. Install virtual audio (BlackHole) for voice
587
+
588
+ Run macOS configuration? (yes/no)
589
+ ```
590
+
591
+ If yes, run:
592
+ ```bash
593
+ sudo ./scripts/setup/configure-macos.sh
594
+ ```
595
+
596
+ ### Step 4: External SSD configuration (REQUIRED if /Volumes/{name}-SSD is mounted)
597
+
598
+ The maestro daemon and its launchd-spawned trigger jobs should write all runtime data — Claude Code per-cwd temp dirs, daemon logs, state, outputs, memory, knowledge — to an external SSD when one is available. This keeps the internal disk free for macOS and avoids wear on the system disk.
599
+
600
+ **Two macOS hurdles need to be cleared before the SSD redirect actually works for launchd-spawned processes:**
601
+
602
+ #### 4a. Enable file ownership on the volume
603
+
604
+ By default, external volumes have Owners disabled, which makes file permissions advisory rather than enforced. The daemon's wrapper writes per-agent log files, and that requires real owners.
605
+
606
+ Detect the SSD and enable owners:
607
+
608
+ ```bash
609
+ SSD_VOLUME=""
610
+ for v in /Volumes/*-SSD /Volumes/*SSD* /Volumes/maestro-data; do
611
+ if [ -d "$v" ] && [ "$v" != "/Volumes/Macintosh HD" ]; then SSD_VOLUME="$v"; break; fi
612
+ done
613
+
614
+ if [ -n "$SSD_VOLUME" ]; then
615
+ # Tell the user we found an SSD and need sudo to enable owners
616
+ echo "Found external SSD at $SSD_VOLUME — enabling file ownership."
617
+ echo "Please run this in your terminal (it needs sudo):"
618
+ echo " sudo diskutil enableOwnership \"$SSD_VOLUME\""
619
+ echo "Reply 'done' when complete."
620
+ fi
621
+ ```
622
+
623
+ Wait for the user to confirm. Then verify:
624
+
625
+ ```bash
626
+ diskutil info "$SSD_VOLUME" | grep "Owners" | grep -q "Enabled" && echo "OK" || echo "FAIL"
627
+ ```
628
+
629
+ #### 4b. Grant Full Disk Access to bash and node (TCC)
630
+
631
+ Even with owners enabled, **macOS TCC blocks launchd-spawned processes from writing to /Volumes/ unless the binary has Full Disk Access**. This is the single most common cause of "Operation not permitted" errors when you run a daemon under launchd that tries to write to an external volume.
632
+
633
+ You cannot grant Full Disk Access programmatically without disabling SIP (which is unsafe). The user must do this via System Settings UI:
634
+
635
+ ```
636
+ 1. Open System Settings → Privacy & Security → Full Disk Access
637
+ 2. Click the + button
638
+ 3. Press Cmd+Shift+G to "Go to Folder", then enter:
639
+ /bin/bash
640
+ Press Enter, select 'bash', click Open
641
+ 4. Click + again, then:
642
+ /usr/bin/node OR ~/.nvm/versions/node/v24.11.1/bin/node
643
+ (whichever node binary the wrapper uses)
644
+ 5. Make sure both toggles are ON
645
+
646
+ The toggles take effect immediately. No restart needed.
647
+ ```
648
+
649
+ After the user confirms, test that launchd can now write to the SSD:
650
+
651
+ ```bash
652
+ cat > /tmp/ssd-tcc-test.plist <<EOF
653
+ <?xml version="1.0" encoding="UTF-8"?>
654
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
655
+ <plist version="1.0">
656
+ <dict>
657
+ <key>Label</key><string>ai.maestro.ssd-tcc-test</string>
658
+ <key>ProgramArguments</key><array>
659
+ <string>/bin/bash</string><string>-c</string>
660
+ <string>touch "$SSD_VOLUME/.tcc-test" && echo "ok=$?" > /tmp/ssd-tcc-result.log || echo "fail=$?" > /tmp/ssd-tcc-result.log</string>
661
+ </array>
662
+ <key>RunAtLoad</key><true/>
663
+ </dict>
664
+ </plist>
665
+ EOF
666
+ launchctl load /tmp/ssd-tcc-test.plist
667
+ sleep 2
668
+ cat /tmp/ssd-tcc-result.log
669
+ launchctl unload /tmp/ssd-tcc-test.plist
670
+ rm -f "$SSD_VOLUME/.tcc-test"
671
+ ```
672
+
673
+ If you see `ok=0`, TCC is configured correctly and the daemon can use the SSD. If you see `fail=1`, TCC is still blocking — repeat the System Settings step and make sure the toggles are ON.
674
+
675
+ #### 4c. Set up SSD layout and symlinks
676
+
677
+ ```bash
678
+ AGENT_NAME="$(grep firstName config/agent.ts | head -1 | sed 's/.*[\x27\"]\([a-zA-Z]*\)[\x27\"].*/\1/' | tr A-Z a-z)"
679
+ SSD_AGENT_ROOT="$SSD_VOLUME/maestro/$AGENT_NAME"
680
+ mkdir -p "$SSD_AGENT_ROOT"/{state,outputs,memory,knowledge,claude-tmp,logs,tmp}
681
+
682
+ # Symlink runtime data dirs from the agent repo to the SSD.
683
+ # IMPORTANT: do NOT symlink logs/ — launchd's StandardErrorPath cannot follow
684
+ # symlinks to external volumes. The daemon's wrapper writes its own log file
685
+ # directly to the SSD via shell redirection (see launchd-wrapper.sh).
686
+ for d in state outputs memory knowledge; do
687
+ if [ -d "$d" ] && [ ! -L "$d" ]; then
688
+ rsync -a "$d/" "$SSD_AGENT_ROOT/$d/"
689
+ rm -rf "$d"
690
+ ln -sfn "$SSD_AGENT_ROOT/$d" "$d"
691
+ fi
692
+ done
693
+
694
+ # Create internal-disk logs/ as a real directory (NOT a symlink)
695
+ mkdir -p logs/{daemon,polling,workflows,sessions,audit,security,evolution,huddle,infra,monitor,phone,sms,whatsapp,email,launchd,cloudflared}
696
+ ```
697
+
698
+ The wrapper scripts (`scripts/daemon/launchd-wrapper.sh` and `launchd-wrapper-generic.sh`) handle the runtime side: they detect the SSD, set `CLAUDE_CODE_TMPDIR`, and redirect daemon stdout/stderr to a log file on the SSD. They gracefully fall back to internal-disk paths if the SSD isn't writable (e.g. if TCC isn't granted yet).
699
+
700
+ #### 4d. Verify
701
+
702
+ ```bash
703
+ # Daemon should now be writing to the SSD log file
704
+ launchctl unload ~/Library/LaunchAgents/ai.maestro.${AGENT_NAME}-daemon.plist
705
+ launchctl load ~/Library/LaunchAgents/ai.maestro.${AGENT_NAME}-daemon.plist
706
+ sleep 4
707
+ ls -la "$SSD_AGENT_ROOT/logs/daemon/" | tail -5
708
+ ls -la "$SSD_AGENT_ROOT/state/inbox/" | tail -5
709
+ ```
710
+
711
+ You should see the daemon log file growing and inbox directories populating. If you don't, repeat steps 4a–4b (most often it's TCC).
712
+
713
+ ## Phase 4: Autonomous Service Configuration
714
+
715
+ This phase sets up all third-party integrations **autonomously**. Use Playwright MCP for web-based setup (Slack API portal, Twilio Console, Google Account, ElevenLabs, Deepgram) and Bash for local scripts. Only ask the user for input when genuinely required (existing credentials, 2FA codes, payment authorisation).
716
+
717
+ **Tooling:**
718
+ - **Playwright MCP** (`mcp__plugin_playwright_playwright__browser_navigate`, `browser_click`, `browser_fill_form`, `browser_snapshot`, etc.) for all web UI interactions
719
+ - **Bash** for local scripts, CLI tools, file writes, service starts
720
+ - If a web UI requires authentication the agent doesn't have, ask the user to log in via `! open <url>` then resume automation once they confirm they're logged in
721
+
722
+ **Implementation guides**: Each service has a detailed guide in `docs/guides/`. Follow the guide's steps exactly during setup. Reference the guide's troubleshooting section if something fails.
723
+
724
+ ### Step 0: Ask what services this agent needs
725
+
726
+ ```
727
+ Which services does this agent need? Select all that apply:
728
+
729
+ [1] Slack (messaging, events, typing indicators)
730
+ [2] Gmail (email send/receive via IMAP/SMTP)
731
+ [3] Twilio SMS (inbound/outbound text messaging)
732
+ [4] Twilio WhatsApp (inbound/outbound WhatsApp)
733
+ [5] Voice / Huddle (Deepgram STT + ElevenLabs TTS)
734
+ [6] Cloudflare Tunnels (public webhook URLs — needed if 3/4/5 selected)
735
+ [7] Gemini / Veo (AI image + video generation)
736
+ [8] All of the above
737
+ [9] Minimal (Slack + Gmail only)
738
+
739
+ Which? (comma-separated numbers, or "all" / "minimal")
740
+ ```
741
+
742
+ Then execute each selected service. For services with existing credentials, ask the user to paste them. For new accounts, drive the web UI via Playwright.
743
+
744
+ ### Step 1: Slack — per `docs/guides/slack-setup.md`
745
+
746
+ **If user has existing tokens:** ask for xoxb- and xoxp- tokens, write to `.env`.
747
+
748
+ **If creating new app — execute via Playwright:**
749
+
750
+ 1. `browser_navigate` to `https://api.slack.com/apps`
751
+ 2. `browser_snapshot` to check auth — if not logged in, ask user: `! open https://api.slack.com/apps` and log in, then resume
752
+ 3. Click "Create New App" → "From scratch"
753
+ 4. `browser_fill_form` with app name "Maestro - {AgentFirstName}", select workspace
754
+ 5. Navigate to OAuth & Permissions
755
+ 6. Add Bot Token Scopes: `chat:write`, `chat:write.customize`, `channels:read`, `channels:history`, `groups:read`, `groups:history`, `im:read`, `im:history`, `im:write`, `users:read`, `users:read.email`, `reactions:read`, `reactions:write`, `files:read`, `files:write`
756
+ 7. Add User Token Scopes: `channels:history`, `groups:history`, `im:history`, `search:read`, `chat:write`
757
+ 8. Click "Install to Workspace" → authorize
758
+ 9. Extract Bot User OAuth Token (xoxb-...) and User OAuth Token (xoxp-...) from the page
759
+ 10. Navigate to Basic Information → extract Signing Secret
760
+ 11. Write `SLACK_BOT_TOKEN`, `SLACK_USER_TOKEN`, `SLACK_SIGNING_SECRET` to `.env`
761
+
762
+ **Verify:**
763
+ ```bash
764
+ source .env && curl -s -H "Authorization: Bearer $SLACK_USER_TOKEN" https://slack.com/api/auth.test | python3 -c "import json,sys; d=json.load(sys.stdin); print('Slack OK: ' + d.get('user','') if d.get('ok') else 'FAIL: ' + d.get('error',''))"
765
+ ```
766
+
767
+ ### Step 2: Gmail — per `docs/guides/email-setup.md`
768
+
769
+ Gmail app passwords require 2FA interaction — ask user:
770
+ ```
771
+ Gmail setup: Please generate an app password:
772
+ 1. Go to https://myaccount.google.com/apppasswords (or I can open it for you)
773
+ 2. Generate a password for "Mail" on "Mac"
774
+ 3. Paste the 16-character password here:
775
+ ```
776
+
777
+ After receiving the password:
778
+ 1. Write `GMAIL_APP_PASSWORD` to `.env`
779
+ 2. If monitoring principal's inbox, ask for secondary password → `SECONDARY_GMAIL_APP_PASSWORD`
780
+ 3. Install msmtp: `brew install msmtp 2>/dev/null || true`
781
+ 4. Write `~/.msmtprc` per guide § 1.4, set `chmod 600 ~/.msmtprc`
782
+
783
+ **Verify:**
784
+ ```bash
785
+ source .env && python3 -c "import imaplib,os; m=imaplib.IMAP4_SSL('imap.gmail.com'); m.login('${AGENT_EMAIL}', os.environ['GMAIL_APP_PASSWORD']); print('IMAP OK'); m.logout()"
786
+ ```
787
+
788
+ ### Step 3: Twilio (SMS + WhatsApp) — per `docs/guides/voice-sms-setup.md`, `docs/guides/whatsapp-setup.md`
789
+
790
+ **If user has credentials:** ask for Account SID, Auth Token, Phone Number → write to `.env`.
791
+
792
+ **If creating new account — execute via Playwright:**
793
+
794
+ 1. `browser_navigate` to `https://www.twilio.com/console`
795
+ 2. `browser_snapshot` — if not logged in, ask user to log in via `! open https://www.twilio.com/login`
796
+ 3. Once authenticated, extract Account SID and Auth Token from Console dashboard
797
+ 4. Navigate to Phone Numbers → Buy a Number → search for SMS+Voice number in preferred country
798
+ 5. **Ask user to confirm the purchase** (payment authorisation)
799
+ 6. After purchase, extract phone number (E.164) and Phone SID
800
+ 7. Write `TWILIO_ACCOUNT_SID`, `TWILIO_AUTH_TOKEN`, `TWILIO_PHONE_NUMBER`, `TWILIO_PHONE_SID` to `.env`
801
+
802
+ **If SMS selected:** Configure webhook per guide:
803
+ 1. Navigate to Twilio Console → Phone Numbers → Active Numbers → select number
804
+ 2. Under Messaging → "A message comes in" → Webhook POST → `{tunnel_url}/sms`
805
+ 3. Enable geo-permissions: navigate to Messaging → Settings → Geo Permissions → enable needed countries
806
+
807
+ **If WhatsApp selected:** Configure sandbox per guide:
808
+ 1. `browser_navigate` to `https://console.twilio.com/us1/develop/sms/try-it-out/whatsapp-learn`
809
+ 2. Under Sandbox Settings → set webhook URL to `{tunnel_url}/whatsapp` POST
810
+ 3. Set Status Callback to `{tunnel_url}/whatsapp/status` POST
811
+ 4. Note and report the sandbox join keyword to the user
812
+ 5. Write `WHATSAPP_MODE=sandbox`, `WHATSAPP_PORT=3002` to `.env`
813
+
814
+ ### Step 4: Webhook Relay (Railway) — per `docs/guides/webhook-relay-setup.md`
815
+
816
+ **This is the canonical pattern. Do NOT use Cloudflare Tunnels for new agents** — they were a transitional approach. Each agent gets its own Railway-deployed webhook relay. The local Mac mini polls the relay every 5 seconds and never needs an inbound tunnel.
817
+
818
+ The relay handles:
819
+ - `POST /slack/events` — Slack Events API (HMAC verified via SLACK_SIGNING_SECRET)
820
+ - `POST /sms` — Twilio SMS inbound (HMAC verified via TWILIO_AUTH_TOKEN)
821
+ - `POST /whatsapp` — Twilio WhatsApp inbound
822
+ - `POST /whatsapp/status` — Twilio WhatsApp delivery status
823
+ - `GET /events`, `/sms/messages`, `/whatsapp/messages` — drained by Mac mini poller
824
+ - `GET /health` — service status
825
+
826
+ **Source code** is already in the repo at `services/webhook-relay/` (copied from the maestro framework). It's a ~250-line Node 20 HTTP server, no dependencies, deployable straight to Railway.
827
+
828
+ **Prerequisites:**
829
+ - Railway CLI installed: `brew install railway 2>/dev/null || true`
830
+ - User must run `railway login` once (interactive — opens browser)
831
+ - User must have admin rights in the company's Railway workspace (e.g., "Northwind")
832
+
833
+ **Deploy steps (run from the agent's repo root):**
834
+
835
+ ```bash
836
+ # 1. Create the project in the company's Railway workspace
837
+ cd services/webhook-relay
838
+ railway init --name {firstname-lower}-webhook-relay --workspace {Company}
839
+
840
+ # 2. Add the service and deploy
841
+ railway up --service {firstname-lower}-webhook-relay --detach
842
+
843
+ # 3. Generate a public domain
844
+ railway domain --service {firstname-lower}-webhook-relay
845
+ # Captures: https://{firstname-lower}-webhook-relay-production.up.railway.app
846
+
847
+ # 4. Set env vars (must include the agent's own SLACK_SIGNING_SECRET and TWILIO_AUTH_TOKEN)
848
+ source ../../.env
849
+ railway variables --service {firstname-lower}-webhook-relay \
850
+ --set "SLACK_SIGNING_SECRET=$SLACK_SIGNING_SECRET" \
851
+ --set "TWILIO_AUTH_TOKEN=$TWILIO_AUTH_TOKEN" \
852
+ --set "PUBLIC_HOSTNAME={firstname-lower}-webhook-relay-production.up.railway.app" \
853
+ --set "BUFFER_TTL_MS=600000" \
854
+ --set "MAX_BUFFER_SIZE=1000"
855
+
856
+ # 5. Trigger redeploy so the running container picks up the new env vars
857
+ railway up --service {firstname-lower}-webhook-relay --detach
858
+
859
+ # 6. Wait until /health returns slack_signature: true and twilio_signature: true
860
+ for i in 1 2 3 4 5 6 7 8 9 10 11 12; do
861
+ RESP=$(curl -sf -m 5 https://{firstname-lower}-webhook-relay-production.up.railway.app/health)
862
+ if echo "$RESP" | grep -q '"slack_signature":true' && echo "$RESP" | grep -q '"twilio_signature":true'; then
863
+ echo "Relay live with signature verification"
864
+ break
865
+ fi
866
+ sleep 10
867
+ done
868
+ ```
869
+
870
+ **Configure external services to point at the relay:**
871
+
872
+ ```bash
873
+ # Twilio SMS webhook (uses Twilio API directly, no UI)
874
+ RELAY_URL="https://{firstname-lower}-webhook-relay-production.up.railway.app"
875
+ curl -s -u "$TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN" -X POST \
876
+ "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/IncomingPhoneNumbers/$TWILIO_PHONE_SID.json" \
877
+ --data-urlencode "SmsUrl=$RELAY_URL/sms" --data-urlencode "SmsMethod=POST"
878
+ ```
879
+
880
+ For **Slack Events Subscription**: use Playwright to update via the App Manifest editor (more reliable than the events page). Navigate to `https://app.slack.com/app-settings/{TEAM_ID}/{APP_ID}/app-manifest`, read the JSON via the CodeMirror instance, add this block to `settings`, and click Save Changes:
881
+
882
+ ```json
883
+ "event_subscriptions": {
884
+ "request_url": "https://{firstname-lower}-webhook-relay-production.up.railway.app/slack/events",
885
+ "bot_events": [
886
+ "app_mention",
887
+ "message.channels",
888
+ "message.groups",
889
+ "message.im",
890
+ "message.mpim"
891
+ ]
892
+ }
893
+ ```
894
+
895
+ After save, navigate to the Event Subscriptions page and check for the yellow "Click here to verify" button — click it. Then **reinstall the app** at `https://api.slack.com/apps/{APP_ID}/install-on-team` so the new event scopes activate.
896
+
897
+ For **Twilio WhatsApp sandbox**: this requires a per-agent Twilio sub-account (see Phase 4 Step 3.5). Cannot share with other agents because the sandbox webhook is account-wide.
898
+
899
+ **Update local poll script:**
900
+
901
+ ```bash
902
+ # Edit scripts/poll-slack-events.sh and scripts/comms-monitor.sh
903
+ # Set EVENTS_URL to https://{firstname-lower}-webhook-relay-production.up.railway.app/events
904
+ ```
905
+
906
+ **Install the launchd job that polls the relay every 5 seconds:**
907
+
908
+ ```bash
909
+ cat > scripts/local-triggers/plists/ai.maestro.{firstname-lower}-poll-relay.plist <<EOF
910
+ <?xml version="1.0" encoding="UTF-8"?>
911
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
912
+ <plist version="1.0">
913
+ <dict>
914
+ <key>Label</key><string>ai.maestro.{firstname-lower}-poll-relay</string>
915
+ <key>ProgramArguments</key><array>
916
+ <string>/bin/bash</string>
917
+ <string>{REPO_ROOT}/scripts/poll-slack-events.sh</string>
918
+ </array>
919
+ <key>WorkingDirectory</key><string>{REPO_ROOT}</string>
920
+ <key>StartInterval</key><integer>5</integer>
921
+ <key>RunAtLoad</key><true/>
922
+ <key>StandardOutPath</key><string>{REPO_ROOT}/logs/polling/poll-relay-stdout.log</string>
923
+ <key>StandardErrorPath</key><string>{REPO_ROOT}/logs/polling/poll-relay-stderr.log</string>
924
+ </dict>
925
+ </plist>
926
+ EOF
927
+ cp scripts/local-triggers/plists/ai.maestro.{firstname-lower}-poll-relay.plist ~/Library/LaunchAgents/
928
+ launchctl load ~/Library/LaunchAgents/ai.maestro.{firstname-lower}-poll-relay.plist
929
+ ```
930
+
931
+ **Add the relay URL block to `.env`:**
932
+
933
+ ```bash
934
+ cat >> .env <<EOF
935
+
936
+ # ─── RAILWAY WEBHOOK RELAY ──────────────────────────────────────────────────
937
+ WEBHOOK_RELAY_URL=https://{firstname-lower}-webhook-relay-production.up.railway.app
938
+ WEBHOOK_RELAY_SLACK_EVENTS=https://{firstname-lower}-webhook-relay-production.up.railway.app/slack/events
939
+ WEBHOOK_RELAY_SMS_INBOUND=https://{firstname-lower}-webhook-relay-production.up.railway.app/sms
940
+ WEBHOOK_RELAY_WHATSAPP_INBOUND=https://{firstname-lower}-webhook-relay-production.up.railway.app/whatsapp
941
+ WEBHOOK_RELAY_POLL_EVENTS=https://{firstname-lower}-webhook-relay-production.up.railway.app/events
942
+ WEBHOOK_RELAY_POLL_SMS=https://{firstname-lower}-webhook-relay-production.up.railway.app/sms/messages
943
+ WEBHOOK_RELAY_POLL_WHATSAPP=https://{firstname-lower}-webhook-relay-production.up.railway.app/whatsapp/messages
944
+ EOF
945
+ ```
946
+
947
+ **End-to-end test:**
948
+
949
+ 1. Have Lucas (or any user) send a Slack message to a channel where the bot is a member, OR @-mention the bot in a public channel
950
+ 2. Within ~5 seconds, the local Mac mini should fetch the buffered event and write a YAML file to `state/inbox/slack/`
951
+ 3. The inbox processor picks it up and routes it
952
+ 4. Verify `railway logs --service {firstname-lower}-webhook-relay` shows `[slack] buffered ...`
953
+
954
+ ### Step 5: Voice / Huddle — per `docs/guides/voice-sms-setup.md` § 5
955
+
956
+ **API keys** — if user has them, paste directly. Otherwise, drive signup via Playwright:
957
+
958
+ 1. **ElevenLabs**: `browser_navigate` to `https://elevenlabs.io/` → sign up or log in → navigate to Profile → API Keys → extract key
959
+ 2. **Deepgram**: `browser_navigate` to `https://console.deepgram.com/` → sign up or log in → navigate to API Keys → create and extract key
960
+ 3. Write `ELEVENLABS_API_KEY`, `DEEPGRAM_API_KEY` to `.env`
961
+
962
+ **Local setup:**
963
+ ```bash
964
+ bash scripts/huddle/setup-audio.sh # Install BlackHole, sox, verify
965
+ cd scripts/huddle && npm install && cd ../.. # Install huddle Node.js deps
966
+ bash scripts/huddle/launch-slack.sh # Launch Slack with CDP
967
+ ```
968
+
969
+ ### Step 6: Media Generation — per `docs/guides/media-generation-setup.md`
970
+
971
+ 1. If user has Gemini key, paste directly. Otherwise: `browser_navigate` to `https://aistudio.google.com/apikey` → extract or create key
972
+ 2. Write `GEMINI_API_KEY` to `.env`
973
+
974
+ ### Step 7: Additional Keys
975
+
976
+ Prompt for any remaining optional keys: `OPENAI_API_KEY`, `GREPTILE_API_KEY`. Write to `.env` or skip.
977
+
978
+ ## Phase 5: Subsystem Implementation & Verification
979
+
980
+ After credentials are configured, this phase **autonomously implements and verifies** every subsystem by following each implementation guide's setup and test steps. This ensures the agent is actually operational — not just configured with API keys.
981
+
982
+ **Execution:** Spawn parallel background agents for independent subsystems. Report results as a verification matrix. Do NOT proceed to Phase 6 until all selected subsystems pass (or user explicitly accepts failures).
983
+
984
+ Tell the user:
985
+ ```
986
+ Credentials configured. Now I'll set up and verify each subsystem end-to-end.
987
+ This runs autonomously — I'll report results when complete.
988
+ ```
989
+
990
+ ### 5.1 Outbound Governance — `docs/guides/outbound-governance-setup.md`
991
+
992
+ Verify FIRST — all send scripts depend on this.
993
+
994
+ 1. Verify hooks registered in `.claude/settings.json` (PreToolUse for block-mcp-slack-send and pre-send-audit, PostToolUse for post-action-log, Stop for session-end-log)
995
+ 2. `chmod +x scripts/hooks/*.sh`
996
+ 3. Test dedup: generate key → acquire → verify CLAIMED → cleanup
997
+ 4. Test validate-outbound.py runs without crash
998
+ 5. Test disclosure_assessment.py runs without crash
999
+
1000
+ ### 5.2 Email — `docs/guides/email-setup.md`
1001
+
1002
+ 1. Test IMAP connectivity (if GMAIL_APP_PASSWORD set)
1003
+ 2. Verify msmtp config exists: `test -f ~/.msmtprc`
1004
+ 3. Verify email signature files: `test -f scripts/email-signature.html`
1005
+ 4. `chmod +x scripts/send-email.sh`
1006
+
1007
+ ### 5.3 Slack — `docs/guides/slack-setup.md`
1008
+
1009
+ 1. Test token: `curl -s -H "Authorization: Bearer $SLACK_USER_TOKEN" https://slack.com/api/auth.test`
1010
+ 2. Verify slack-send.sh uses xoxp- token (not xoxb-)
1011
+ 3. Verify typing indicator exists: `test -f scripts/slack-typing.mjs`
1012
+ 4. Verify MCP block hook: `test -f scripts/hooks/block-mcp-slack-send.sh`
1013
+
1014
+ ### 5.4 SMS & WhatsApp — `docs/guides/voice-sms-setup.md`, `docs/guides/whatsapp-setup.md`
1015
+
1016
+ 1. Verify `config/caller-id-map.yaml` exists and has principal with `access_level: ceo`
1017
+ 2. Start SMS handler, verify health: `curl http://localhost:3001/health`
1018
+ 3. Start WhatsApp handler, verify health: `curl http://localhost:3002/health`
1019
+ 4. `chmod +x scripts/send-sms.sh scripts/send-whatsapp.sh`
1020
+
1021
+ ### 5.5 Voice / Huddle — `docs/guides/voice-sms-setup.md` § 5
1022
+
1023
+ 1. `bash scripts/huddle/setup-audio.sh --check`
1024
+ 2. Verify huddle deps: `test -d scripts/huddle/node_modules`
1025
+ 3. Verify Deepgram + ElevenLabs keys are set
1026
+
1027
+ ### 5.6 Poller & Daemon — `docs/guides/poller-daemon-setup.md`
1028
+
1029
+ 1. Run poller once: `timeout 30 node scripts/poller/index.mjs`
1030
+ 2. Verify daemon entry point: `head -5 scripts/daemon/maestro-daemon.mjs`
1031
+ 3. Verify plists generated: `ls scripts/local-triggers/plists/*.plist | wc -l`
1032
+ 4. Test emergency stop: `touch .emergency-stop` → run trigger → verify blocked → `rm .emergency-stop`
1033
+ 5. Verify watchdog: `bash scripts/watchdog/memory-watchdog.sh --check`
1034
+
1035
+ ### 5.7 RAG & Context — `docs/guides/rag-context-setup.md`
1036
+
1037
+ 1. Build search index: `python3 scripts/rag-indexer.py --full`
1038
+ 2. Verify docs indexed: `python3 scripts/rag-indexer.py --stats`
1039
+ 3. Test search: `python3 scripts/user-context-search.py --user unknown --query "adaptic" --max-results 1`
1040
+ 4. Run test suite if available: `bash scripts/test-rag-search.sh`
1041
+
1042
+ ### 5.8 PDF Generation — `docs/guides/pdf-generation-setup.md`
1043
+
1044
+ 1. `pandoc --version`
1045
+ 2. Check XeLaTeX: `xelatex --version 2>/dev/null || ~/Library/TinyTeX/bin/universal-darwin/xelatex --version 2>/dev/null`
1046
+ 3. Generate test PDF:
1047
+ ```bash
1048
+ echo "# Test\nGenerated by init-maestro." > /tmp/init-test.md
1049
+ node scripts/pdf-generation/build-document.mjs --input /tmp/init-test.md --template memo --output /tmp/init-test.pdf
1050
+ test -f /tmp/init-test.pdf && echo "PDF OK"
1051
+ rm -f /tmp/init-test.md /tmp/init-test.pdf
1052
+ ```
1053
+
1054
+ ### 5.9 Media Generation — `docs/guides/media-generation-setup.md`
1055
+
1056
+ 1. Verify Gemini key set
1057
+ 2. List specs: `node scripts/media-generation/generate-assets.mjs --list`
1058
+ 3. Verify client loads: `node -e "import('./scripts/media-generation/gemini-image-client.mjs').then(() => console.log('OK'))"`
1059
+
1060
+ ### 5.10 Verification Summary
1061
+
1062
+ Print results:
1063
+
1064
+ ```
1065
+ ╔══════════════════════════════════════════════════════════════╗
1066
+ ║ SUBSYSTEM VERIFICATION RESULTS ║
1067
+ ╠══════════════════════════════════════════════════════════════╣
1068
+ ║ ║
1069
+ ║ Outbound Governance ✅ PASS hooks, dedup, validation ║
1070
+ ║ Email (Gmail) ✅ PASS IMAP, SMTP, signatures ║
1071
+ ║ Slack ✅ PASS tokens, send, typing ║
1072
+ ║ SMS (Twilio) ✅ PASS handler, send, caller-id ║
1073
+ ║ WhatsApp ⏭️ SKIP not selected ║
1074
+ ║ Voice / Huddle ⏭️ SKIP not selected ║
1075
+ ║ Poller & Daemon ✅ PASS poller, plists, watchdog ║
1076
+ ║ RAG & Context ✅ PASS index built, search works ║
1077
+ ║ PDF Generation ✅ PASS pandoc + xelatex OK ║
1078
+ ║ Media Generation ⏭️ SKIP not selected ║
1079
+ ║ ║
1080
+ ║ Overall: 7/7 selected subsystems PASS ║
1081
+ ║ ║
1082
+ ║ Guides: docs/guides/ (for detailed testing & troubleshoot) ║
1083
+ ╚══════════════════════════════════════════════════════════════╝
1084
+ ```
1085
+
1086
+ If any subsystem FAILS: diagnose via the guide's troubleshooting section, attempt one fix, re-run check. If still failing, report failure with specific error and ask user whether to continue or abort.
1087
+
1088
+ ## Phase 6: Generate Agent README
1089
+
1090
+ Generate a comprehensive README.md for this agent's repository. This describes THIS specific agent, not the Maestro framework.
1091
+
1092
+ Include all of the following sections populated with gathered values:
1093
+
1094
+ 1. **Title and tagline**: `{fullName} — Autonomous {title} for {company}`
1095
+ 2. **Who is {firstName}?**: 3-4 sentence description of role, reporting line, autonomy level
1096
+ 3. **Capabilities**: 8-12 bullet points based on archetype and responsibilities
1097
+ 4. **Architecture**: 5-tier model with role-specific domain controllers
1098
+ 5. **Subsystem Status**: Include the Phase 5 verification matrix
1099
+ 6. **Operating Modes**: Reactive (polling), Scheduled (triggers), Proactive (backlog)
1100
+ 7. **Commands**: npm run daemon, healthcheck, emergency-stop, resume, upgrade
1101
+ 8. **Implementation Guides**: Table linking to all 10 guides in `docs/guides/`
1102
+ 9. **Communication Governance**: Based on archetype autonomy model
1103
+
1104
+ Write to repo root as `README.md`.
1105
+
1106
+ ## Phase 7: Create GitHub Repository
1107
+
1108
+ Ask the user whether they want to create a GitHub repo:
1109
+
1110
+ ```
1111
+ Would you like me to create a GitHub repository for this agent? (yes/no)
1112
+ ```
1113
+
1114
+ If yes: ask for org/username (default: adapticai), repo name (default: {repoName}), visibility (default: private). Then:
1115
+
1116
+ ```bash
1117
+ gh repo create {org}/{repoName} --private --description "{fullName} — Autonomous {title} for {company} (powered by Maestro)"
1118
+ git remote add origin https://github.com/{org}/{repoName}.git
1119
+ git add -A
1120
+ git commit -m "Initialize {fullName} as {title} — powered by @cohortapp/agent-sdk"
1121
+ git push -u origin main
1122
+ ```
1123
+
1124
+ ## Phase 8: Final Verification
1125
+
1126
+ ### Step 1: Grep for stale agent references
1127
+
1128
+ Search critical files for the old agent name AND the placeholder company "Northwind" (case-insensitive): CLAUDE.md, config/agent.ts, config/*.{yaml,json}, package.json, schedules/triggers/*.md, agents/*/agent.md, policies/*. Everything must be the new agent + the company from config/company.json. Fix any stragglers.
1129
+
1130
+ ### Step 2: Validate config/agent.ts
1131
+
1132
+ Read and verify valid TypeScript, all fields populated with new values.
1133
+
1134
+ ### Step 3: Health check
1135
+
1136
+ ```bash
1137
+ npm run healthcheck
1138
+ ```
1139
+
1140
+ ### Step 4: Completion Summary
1141
+
1142
+ ```
1143
+ ═══════════════════════════════════════════════════════════════
1144
+ MAESTRO INITIALIZATION COMPLETE
1145
+ ═══════════════════════════════════════════════════════════════
1146
+
1147
+ Agent: {fullName}, {title}
1148
+ Archetype: {archetype}
1149
+ Company: {company}
1150
+ Principal: {principalName}
1151
+ Machine: {machineName}
1152
+
1153
+ Identity (Phase 2): ✅ 8 parallel agents rewrote repo
1154
+ Infrastructure (Phase 3): ✅ {N} launchd triggers installed
1155
+ Services (Phase 4): ✅ {list configured services}
1156
+ Subsystems (Phase 5): {include verification matrix}
1157
+ README (Phase 6): ✅ Agent-specific README generated
1158
+ GitHub (Phase 7): {repo URL or "skipped"}
1159
+
1160
+ ─────────────────────────────────────────────────────────
1161
+
1162
+ Next steps:
1163
+ 1. Start the daemon: npm run daemon
1164
+ 2. Monitor logs: tail -f logs/daemon/$(date +%Y-%m-%d)-sessions.jsonl
1165
+ 3. Test a message: Send a Slack DM to {firstName}
1166
+
1167
+ Implementation guides: docs/guides/
1168
+ ═══════════════════════════════════════════════════════════════
1169
+ ```
1170
+
1171
+ ## Guidelines for the Wizard
1172
+
1173
+ - Be warm and professional. This is a setup experience, not an interrogation.
1174
+ - Offer sensible defaults wherever possible.
1175
+ - Always confirm before executing identity changes (Phase 2). Service configuration (Phase 4) and verification (Phase 5) execute autonomously after the user selects services.
1176
+ - Sub-agents MUST run in parallel (`run_in_background: true`).
1177
+ - **Autonomous execution is the default.** Only ask for input when you cannot proceed without it (credentials, 2FA, payment). Everything else — web UI navigation, script execution, file writes, verification — you do yourself.
1178
+ - **Use Playwright MCP** for web UIs: Slack API portal, Twilio Console, Google Account, ElevenLabs, Deepgram, Gemini.
1179
+ - **Use Bash** for local operations: scripts, installs, service starts, tests.
1180
+ - If Playwright fails (auth wall, CAPTCHA), fall back to asking user to do that specific step via `! open <url>`, then resume.
1181
+
1182
+ ## Error Handling
1183
+
1184
+ - If a sub-agent fails, report which one and offer to retry.
1185
+ - If a Phase 5 subsystem verification fails, diagnose using the guide's troubleshooting section, attempt one fix, re-run. If still failing, report with specific error and ask whether to continue.
1186
+ - If user aborts mid-wizard, exit cleanly.
1187
+ - If config/agent.ts unreadable, suggest `npx @cohortapp/agent-sdk create` first.