@cohortapp/agent-sdk 2.11.15 → 2.13.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 (280) hide show
  1. package/.env.example +37 -22
  2. package/README.md +2 -0
  3. package/bin/maestro.mjs +117 -39
  4. package/bin/maestro.test.mjs +175 -5
  5. package/docs/guides/front-door-session.md +313 -0
  6. package/docs/guides/mac-mini.md +100 -28
  7. package/docs/guides/org-onboarding.md +1 -1
  8. package/docs/guides/setup-wizard.md +9 -5
  9. package/docs/runbooks/cohort-cutover.md +11 -1
  10. package/docs/runbooks/mac-mini-bootstrap.md +38 -63
  11. package/lib/cadence-bus-requeue.test.mjs +83 -0
  12. package/lib/cadence-bus.mjs +43 -7
  13. package/lib/channels/inbox-item.mjs +59 -2
  14. package/lib/cli/board.mjs +285 -0
  15. package/lib/cli/board.test.mjs +227 -0
  16. package/lib/cli/design.mjs +185 -0
  17. package/lib/cli/design.test.mjs +270 -0
  18. package/lib/cli/doctor-checks.mjs +441 -0
  19. package/lib/cli/doctor-checks.test.mjs +336 -0
  20. package/lib/cli/global-setup-extras.mjs +454 -0
  21. package/lib/cli/global-setup-extras.test.mjs +462 -0
  22. package/lib/cli/inbox.mjs +304 -0
  23. package/lib/cli/inbox.test.mjs +230 -0
  24. package/lib/cli/session-ack.mjs +63 -0
  25. package/lib/cli/session-ack.test.mjs +63 -0
  26. package/lib/cli/session.mjs +760 -0
  27. package/lib/cli/session.test.mjs +613 -0
  28. package/lib/collective/global-config.mjs +209 -6
  29. package/lib/collective/global-config.test.mjs +145 -0
  30. package/lib/collective/global-skills.mjs +145 -0
  31. package/lib/collective/global-skills.test.mjs +126 -0
  32. package/lib/collective/presence.mjs +4 -3
  33. package/lib/collective/vendor-skills.mjs +305 -0
  34. package/lib/collective/vendor-skills.test.mjs +306 -0
  35. package/lib/comms/send-gate.mjs +115 -0
  36. package/lib/comms/send-gate.test.mjs +113 -0
  37. package/lib/design/design-md.mjs +793 -0
  38. package/lib/design/design-md.test.mjs +318 -0
  39. package/lib/design/fixtures/DESIGN.golden.md +238 -0
  40. package/lib/design/fixtures/PRODUCT.golden.md +67 -0
  41. package/lib/design/fixtures/foundation.json +133 -0
  42. package/lib/design/refresh-gate.mjs +154 -0
  43. package/lib/design/refresh-gate.test.mjs +144 -0
  44. package/lib/design/write.mjs +275 -0
  45. package/lib/design/write.test.mjs +241 -0
  46. package/lib/feature-init.mjs +2 -2
  47. package/lib/mcp/server.test.mjs +9 -4
  48. package/lib/model-router/spawn.test.mjs +21 -0
  49. package/lib/org/board-mine-cache.mjs +99 -0
  50. package/lib/org/board-mine-cache.test.mjs +53 -0
  51. package/lib/org/board.mjs +11 -0
  52. package/lib/org/board.test.mjs +11 -1
  53. package/lib/org/client.mjs +36 -0
  54. package/lib/org/client.test.mjs +46 -0
  55. package/lib/org/inbound/directedness.mjs +18 -2
  56. package/lib/org/inbound/directedness.test.mjs +58 -0
  57. package/lib/org/inbound/index.mjs +8 -1
  58. package/lib/org/inbound/index.test.mjs +22 -0
  59. package/lib/org/mesh-directives.test.mjs +110 -0
  60. package/lib/org/mesh.mjs +61 -1
  61. package/lib/org/protocol.checksum +1 -1
  62. package/lib/org/protocol.mjs +52 -0
  63. package/lib/org/protocol.test.mjs +12 -1
  64. package/lib/org/registry.mjs +3 -2
  65. package/lib/org/tool-surface.mjs +120 -0
  66. package/lib/org/tool-surface.test.mjs +118 -5
  67. package/lib/prompts/parallelism.mjs +79 -0
  68. package/lib/prompts/parallelism.test.mjs +177 -0
  69. package/lib/security/external-content.mjs +1 -1
  70. package/lib/security/external-content.test.mjs +17 -0
  71. package/lib/session/config.mjs +137 -0
  72. package/lib/session/config.test.mjs +92 -0
  73. package/lib/session/feed-core.mjs +229 -0
  74. package/lib/session/feed-core.test.mjs +198 -0
  75. package/lib/session/first-run.mjs +126 -0
  76. package/lib/session/first-run.test.mjs +121 -0
  77. package/lib/session/frontdoor.mjs +266 -0
  78. package/lib/session/frontdoor.test.mjs +205 -0
  79. package/lib/session/handoffs.mjs +295 -0
  80. package/lib/session/handoffs.test.mjs +183 -0
  81. package/lib/session/identity.mjs +220 -0
  82. package/lib/session/identity.test.mjs +180 -0
  83. package/lib/session/inbox-claims.mjs +434 -0
  84. package/lib/session/inbox-claims.test.mjs +286 -0
  85. package/lib/session/launch-args.mjs +161 -0
  86. package/lib/session/launch-args.test.mjs +157 -0
  87. package/lib/session/liveness.mjs +174 -0
  88. package/lib/session/liveness.test.mjs +100 -0
  89. package/lib/session/status-summary.mjs +172 -0
  90. package/lib/session/status-summary.test.mjs +118 -0
  91. package/lib/session-permissions.mjs +39 -3
  92. package/lib/session-permissions.test.mjs +20 -0
  93. package/lib/setup/claude-probe.mjs +161 -24
  94. package/lib/setup/claude-probe.test.mjs +187 -0
  95. package/lib/setup/sections/learning.mjs +2 -1
  96. package/lib/setup/sections/model.mjs +104 -24
  97. package/lib/setup/sections/model.test.mjs +240 -0
  98. package/lib/setup/sections/org.mjs +27 -2
  99. package/lib/setup/sections/org.test.mjs +35 -2
  100. package/lib/setup/sections/verify.mjs +5 -0
  101. package/lib/setup/state.mjs +30 -10
  102. package/lib/setup/state.test.mjs +24 -1
  103. package/lib/singleton.js +11 -3
  104. package/lib/singleton.test.mjs +16 -0
  105. package/lib/subagents/lock.mjs +1 -1
  106. package/lib/telemetry/collect.mjs +270 -6
  107. package/lib/telemetry/collect.test.mjs +196 -1
  108. package/lib/upgrade/global-refresh.mjs +108 -0
  109. package/lib/upgrade/global-refresh.test.mjs +65 -0
  110. package/lib/upgrade/launchd-reconcile.mjs +327 -0
  111. package/lib/upgrade/launchd-reconcile.test.mjs +272 -0
  112. package/lib/upgrade/post-steps.mjs +151 -0
  113. package/lib/upgrade/post-steps.test.mjs +200 -0
  114. package/lib/upgrade/verify.mjs +215 -0
  115. package/lib/upgrade/verify.test.mjs +164 -0
  116. package/lib/voice/outbound.mjs +3 -2
  117. package/lib/voice/post-call-brief.mjs +2 -1
  118. package/lib/voice/session-rotation.mjs +6 -1
  119. package/lib/voice/session-rotation.test.mjs +114 -0
  120. package/package.json +3 -3
  121. package/plugins/maestro-skills/plugin.json +25 -1
  122. package/plugins/maestro-skills/skills/board-work.md +63 -0
  123. package/plugins/maestro-skills/skills/cohort-design.md +153 -0
  124. package/plugins/maestro-skills/skills/inbound-triage.md +80 -0
  125. package/plugins/maestro-skills/skills/main-session.md +102 -0
  126. package/plugins/maestro-skills/skills/peer-sessions.md +65 -0
  127. package/plugins/maestro-skills/skills/persona-discipline.md +75 -0
  128. package/plugins/maestro-skills/vendor/emilkowalski/LICENSE +21 -0
  129. package/plugins/maestro-skills/vendor/emilkowalski/UPSTREAM.json +70 -0
  130. package/plugins/maestro-skills/vendor/emilkowalski/skills/animate/RECIPES.md +324 -0
  131. package/plugins/maestro-skills/vendor/emilkowalski/skills/animate/SKILL.md +199 -0
  132. package/plugins/maestro-skills/vendor/emilkowalski/skills/animation-vocabulary/SKILL.md +173 -0
  133. package/plugins/maestro-skills/vendor/emilkowalski/skills/apple-design/SKILL.md +282 -0
  134. package/plugins/maestro-skills/vendor/emilkowalski/skills/emil-design-eng/SKILL.md +674 -0
  135. package/plugins/maestro-skills/vendor/emilkowalski/skills/find-animation-opportunities/SKILL.md +132 -0
  136. package/plugins/maestro-skills/vendor/emilkowalski/skills/improve-animations/AUDIT.md +115 -0
  137. package/plugins/maestro-skills/vendor/emilkowalski/skills/improve-animations/PLAN-TEMPLATE.md +73 -0
  138. package/plugins/maestro-skills/vendor/emilkowalski/skills/improve-animations/SKILL.md +101 -0
  139. package/plugins/maestro-skills/vendor/emilkowalski/skills/prototype/PICKER.md +197 -0
  140. package/plugins/maestro-skills/vendor/emilkowalski/skills/prototype/SKILL.md +90 -0
  141. package/plugins/maestro-skills/vendor/emilkowalski/skills/review-animations/SKILL.md +112 -0
  142. package/plugins/maestro-skills/vendor/emilkowalski/skills/review-animations/STANDARDS.md +187 -0
  143. package/plugins/maestro-skills/vendor/impeccable/LICENSE +191 -0
  144. package/plugins/maestro-skills/vendor/impeccable/NOTICE.md +11 -0
  145. package/plugins/maestro-skills/vendor/impeccable/SKILL.md +86 -0
  146. package/plugins/maestro-skills/vendor/impeccable/UPSTREAM.json +201 -0
  147. package/plugins/maestro-skills/vendor/impeccable/agents/impeccable-asset-producer.md +42 -0
  148. package/plugins/maestro-skills/vendor/impeccable/agents/impeccable-documenter.md +29 -0
  149. package/plugins/maestro-skills/vendor/impeccable/agents/impeccable-finish-reviewer.md +43 -0
  150. package/plugins/maestro-skills/vendor/impeccable/agents/impeccable-manual-edit-applier.md +97 -0
  151. package/plugins/maestro-skills/vendor/impeccable/reference/adapt.md +312 -0
  152. package/plugins/maestro-skills/vendor/impeccable/reference/adapt.native.md +58 -0
  153. package/plugins/maestro-skills/vendor/impeccable/reference/android.md +46 -0
  154. package/plugins/maestro-skills/vendor/impeccable/reference/animate.md +89 -0
  155. package/plugins/maestro-skills/vendor/impeccable/reference/audit.md +136 -0
  156. package/plugins/maestro-skills/vendor/impeccable/reference/audit.native.md +139 -0
  157. package/plugins/maestro-skills/vendor/impeccable/reference/bolder.md +33 -0
  158. package/plugins/maestro-skills/vendor/impeccable/reference/clarify.md +94 -0
  159. package/plugins/maestro-skills/vendor/impeccable/reference/colorize.md +86 -0
  160. package/plugins/maestro-skills/vendor/impeccable/reference/craft-floor.md +44 -0
  161. package/plugins/maestro-skills/vendor/impeccable/reference/craft.md +5 -0
  162. package/plugins/maestro-skills/vendor/impeccable/reference/critique.md +806 -0
  163. package/plugins/maestro-skills/vendor/impeccable/reference/degraded/asset-producer.md +37 -0
  164. package/plugins/maestro-skills/vendor/impeccable/reference/degraded/documenter.md +24 -0
  165. package/plugins/maestro-skills/vendor/impeccable/reference/degraded/finish-reviewer.md +38 -0
  166. package/plugins/maestro-skills/vendor/impeccable/reference/degraded/manual-edit-applier.md +92 -0
  167. package/plugins/maestro-skills/vendor/impeccable/reference/delight.md +70 -0
  168. package/plugins/maestro-skills/vendor/impeccable/reference/distill.md +111 -0
  169. package/plugins/maestro-skills/vendor/impeccable/reference/doctor.md +54 -0
  170. package/plugins/maestro-skills/vendor/impeccable/reference/document.md +416 -0
  171. package/plugins/maestro-skills/vendor/impeccable/reference/extract.md +69 -0
  172. package/plugins/maestro-skills/vendor/impeccable/reference/harden.md +336 -0
  173. package/plugins/maestro-skills/vendor/impeccable/reference/hooks.md +111 -0
  174. package/plugins/maestro-skills/vendor/impeccable/reference/init.md +131 -0
  175. package/plugins/maestro-skills/vendor/impeccable/reference/ios.md +51 -0
  176. package/plugins/maestro-skills/vendor/impeccable/reference/layout.md +84 -0
  177. package/plugins/maestro-skills/vendor/impeccable/reference/live-setup.md +104 -0
  178. package/plugins/maestro-skills/vendor/impeccable/reference/live.md +325 -0
  179. package/plugins/maestro-skills/vendor/impeccable/reference/new-work.md +147 -0
  180. package/plugins/maestro-skills/vendor/impeccable/reference/onboard.md +234 -0
  181. package/plugins/maestro-skills/vendor/impeccable/reference/operate.md +61 -0
  182. package/plugins/maestro-skills/vendor/impeccable/reference/optimize.md +258 -0
  183. package/plugins/maestro-skills/vendor/impeccable/reference/overdrive.md +127 -0
  184. package/plugins/maestro-skills/vendor/impeccable/reference/polish.md +105 -0
  185. package/plugins/maestro-skills/vendor/impeccable/reference/quieter.md +99 -0
  186. package/plugins/maestro-skills/vendor/impeccable/reference/routing.md +24 -0
  187. package/plugins/maestro-skills/vendor/impeccable/reference/shape.md +59 -0
  188. package/plugins/maestro-skills/vendor/impeccable/reference/typeset.md +80 -0
  189. package/plugins/maestro-skills/vendor/impeccable/reference/visualize.md +46 -0
  190. package/plugins/maestro-skills/vendor/taste-skill/LICENSE +21 -0
  191. package/plugins/maestro-skills/vendor/taste-skill/UPSTREAM.json +37 -0
  192. package/plugins/maestro-skills/vendor/taste-skill/skills/minimalist-skill/SKILL.md +85 -0
  193. package/plugins/maestro-skills/vendor/taste-skill/skills/redesign-skill/SKILL.md +178 -0
  194. package/plugins/maestro-skills/vendor/taste-skill/skills/soft-skill/SKILL.md +98 -0
  195. package/plugins/maestro-skills/vendor/taste-skill/skills/taste-skill/SKILL.md +1206 -0
  196. package/plugins/maestro-skills/vendor/unlazy/LICENSE +21 -0
  197. package/plugins/maestro-skills/vendor/unlazy/SECURITY.md +72 -0
  198. package/plugins/maestro-skills/vendor/unlazy/SKILL.md +104 -0
  199. package/plugins/maestro-skills/vendor/unlazy/UPSTREAM.json +94 -0
  200. package/plugins/maestro-skills/vendor/unlazy/references/dispatch.md +82 -0
  201. package/plugins/maestro-skills/vendor/unlazy/references/gates.md +149 -0
  202. package/plugins/maestro-skills/vendor/unlazy/references/method.md +49 -0
  203. package/plugins/maestro-skills/vendor/unlazy/references/orchestration.md +107 -0
  204. package/plugins/maestro-skills/vendor/unlazy/references/parallel.md +133 -0
  205. package/plugins/maestro-skills/vendor/unlazy/references/token-economy.md +48 -0
  206. package/plugins/maestro-skills/vendor/unlazy/scripts/dispatch-check.mjs +139 -0
  207. package/plugins/maestro-skills/vendor/unlazy/scripts/gate-check.mjs +960 -0
  208. package/plugins/maestro-skills/vendor/unlazy/scripts/gate-lint.mjs +245 -0
  209. package/plugins/maestro-skills/vendor/unlazy/scripts/lib/check-supervisor.mjs +46 -0
  210. package/plugins/maestro-skills/vendor/unlazy/scripts/lib/dispatch.mjs +293 -0
  211. package/plugins/maestro-skills/vendor/unlazy/scripts/lib/gates.mjs +953 -0
  212. package/plugins/maestro-skills/vendor/unlazy/scripts/lib/process-tree.mjs +161 -0
  213. package/plugins/maestro-skills/vendor/unlazy/scripts/lib/regex-worker.mjs +9 -0
  214. package/plugins/maestro-skills/vendor/unlazy/templates/PLAN.md +116 -0
  215. package/plugins/maestro-skills/vendor/unlazy/templates/gates-leaf.md +51 -0
  216. package/plugins/maestro-skills/vendor/unlazy/templates/gates-node.md +51 -0
  217. package/scaffold/CLAUDE.md +24 -0
  218. package/scripts/ci/check-durable-write-seam.mjs +147 -0
  219. package/scripts/ci/check-durable-write-seam.test.mjs +90 -0
  220. package/scripts/ci/check-skill-packs.mjs +388 -0
  221. package/scripts/ci/check-skill-packs.test.mjs +495 -0
  222. package/scripts/ci/check.mjs +6 -0
  223. package/scripts/collective/hook-runner.mjs +39 -4
  224. package/scripts/collective/hook-runner.test.mjs +85 -2
  225. package/scripts/daemon/agent-daemon-board-mine.test.mjs +96 -0
  226. package/scripts/daemon/agent-daemon-design.test.mjs +238 -0
  227. package/scripts/daemon/agent-daemon-frontdoor.test.mjs +60 -0
  228. package/scripts/daemon/agent-daemon.mjs +249 -10
  229. package/scripts/daemon/agent-daemon.test.mjs +73 -0
  230. package/scripts/daemon/assurance-e2e.test.mjs +141 -6
  231. package/scripts/daemon/assurance.mjs +461 -37
  232. package/scripts/daemon/assurance.test.mjs +408 -43
  233. package/scripts/daemon/cadence-consumer-frontdoor.test.mjs +393 -0
  234. package/scripts/daemon/cadence-consumer.mjs +289 -89
  235. package/scripts/daemon/cadence-handlers.mjs +53 -0
  236. package/scripts/daemon/classifier.mjs +1 -1
  237. package/scripts/daemon/dispatcher-resume.test.mjs +166 -0
  238. package/scripts/daemon/dispatcher.mjs +127 -19
  239. package/scripts/daemon/health.mjs +12 -1
  240. package/scripts/daemon/inbox-deferral-session.test.mjs +49 -0
  241. package/scripts/daemon/inbox-deferral.mjs +6 -0
  242. package/scripts/daemon/lib/self-echo.mjs +201 -0
  243. package/scripts/daemon/lib/self-echo.test.mjs +153 -0
  244. package/scripts/daemon/maestro-daemon.mjs +3 -0
  245. package/scripts/daemon/prompt-builder.mjs +19 -3
  246. package/scripts/daemon/responder.mjs +51 -40
  247. package/scripts/daemon/sdk-version.mjs +51 -0
  248. package/scripts/daemon/sdk-version.test.mjs +31 -0
  249. package/scripts/hooks/pre-send-audit.sh +97 -4
  250. package/scripts/hooks/pre-send-audit.test.mjs +140 -1
  251. package/scripts/local-triggers/autoupdate.sh +243 -19
  252. package/scripts/local-triggers/autoupdate.test.mjs +518 -0
  253. package/scripts/local-triggers/generate-plists.sh +24 -1
  254. package/scripts/local-triggers/generate-plists.test.mjs +49 -11
  255. package/scripts/org/send-orgmail.first-contact.test.mjs +102 -0
  256. package/scripts/org/send-orgmail.mjs +27 -3
  257. package/scripts/poller/inbox-privilege-injection.test.mjs +167 -0
  258. package/scripts/poller/slack-poller.mjs +13 -1
  259. package/scripts/poller/utils.mjs +46 -1
  260. package/scripts/poller-launchd/install.sh +19 -11
  261. package/scripts/poller-launchd/install.test.mjs +243 -0
  262. package/scripts/poller-launchd/launchd-poller-wrapper.sh +92 -0
  263. package/scripts/poller-launchd/migrate.sh +66 -0
  264. package/scripts/poller-launchd/poller.plist.template +4 -2
  265. package/scripts/session/feed.mjs +237 -0
  266. package/scripts/session/feed.test.mjs +196 -0
  267. package/scripts/session/supervisor-sh.test.mjs +218 -0
  268. package/scripts/session/supervisor.mjs +328 -0
  269. package/scripts/session/supervisor.sh +141 -0
  270. package/scripts/session/supervisor.test.mjs +482 -0
  271. package/scripts/setup/configure-macos.sh +250 -55
  272. package/scripts/setup/configure-macos.test.mjs +306 -0
  273. package/scripts/setup/init-agent.sh +112 -7
  274. package/scripts/setup/init-agent.test.mjs +220 -1
  275. package/scripts/vendor/skill-packs.mjs +354 -0
  276. package/scripts/vendor/sync-skill-packs.mjs +242 -0
  277. package/scripts/vendor/sync-skill-packs.test.mjs +103 -0
  278. package/scripts/watchdog/memory-watchdog.sh +37 -1
  279. package/scripts/watchdog/memory-watchdog.test.mjs +64 -0
  280. package/scripts/setup/boot-claude-session.sh +0 -94
@@ -24,11 +24,14 @@ function tmpRoot() {
24
24
  mkdirSync(join(root, "config"), { recursive: true });
25
25
  return root;
26
26
  }
27
- function run(event, input, root) {
27
+ function run(event, input, root, extraEnv = {}) {
28
+ const env = { ...process.env, MAESTRO_COLLECTIVE_ROOT: root };
29
+ delete env.MAESTRO_DAEMON; // never inherit a daemon marker from the runner's own environment
30
+ Object.assign(env, extraEnv);
28
31
  return spawnSync(process.execPath, [RUNNER, event], {
29
32
  input: JSON.stringify(input),
30
33
  encoding: "utf8",
31
- env: { ...process.env, MAESTRO_COLLECTIVE_ROOT: root },
34
+ env,
32
35
  });
33
36
  }
34
37
 
@@ -88,3 +91,83 @@ test("disabled config → fully silent no-op", () => {
88
91
  assert.equal(r.stdout.trim(), "");
89
92
  } finally { rmSync(root, { recursive: true, force: true }); }
90
93
  });
94
+
95
+ // ── WP-M4: the front-door primer (identity block + session status) ─────────
96
+
97
+ test("prime: injects the identity block + one-line session status + handoff/board counts when the repo has an identity", () => {
98
+ const root = tmpRoot();
99
+ try {
100
+ writeFileSync(join(root, "config", "agent.json"), JSON.stringify({
101
+ firstName: "Alex", fullName: "Alex Rivera", title: "Chief of Staff", company: "Acme",
102
+ principal: { fullName: "Jordan Lee", title: "CEO" }, repoSlug: "alex-ai",
103
+ }));
104
+ mkdirSync(join(root, "state", "session", "handoffs"), { recursive: true });
105
+ mkdirSync(join(root, "state", "org"), { recursive: true });
106
+ writeFileSync(join(root, "state", "session", "heartbeat.json"), JSON.stringify({ pid: 1, name: "alex-main", ts: Date.now() }));
107
+ writeFileSync(join(root, "state", "session", "handoffs", "t1.json"), "{}");
108
+ writeFileSync(join(root, "state", "session", "handoffs", "t2.json"), "{}");
109
+ writeFileSync(join(root, "state", "org", "board-mine.json"), JSON.stringify({ items: [{ itemId: "i1" }], fetchedAt: new Date().toISOString() }));
110
+ const r = run("prime", { session_id: "me", cwd: "/x/maestro" }, root);
111
+ assert.equal(r.status, 0);
112
+ const payload = JSON.parse(r.stdout);
113
+ const ctx = payload.hookSpecificOutput.additionalContext;
114
+ assert.match(ctx, /maestro:identity/);
115
+ assert.match(ctx, /Alex Rivera/);
116
+ assert.match(ctx, /Chief of Staff/);
117
+ assert.match(ctx, /`alex-main`/);
118
+ assert.match(ctx, /Session status: main session alex-main live/);
119
+ assert.match(ctx, /2 open handoffs/);
120
+ assert.match(ctx, /1 board item/);
121
+ } finally { rmSync(root, { recursive: true, force: true }); }
122
+ });
123
+
124
+ test("prime: identity primer and memory digest are emitted together in ONE hook frame", () => {
125
+ const root = tmpRoot();
126
+ try {
127
+ writeFileSync(join(root, "config", "agent.json"), JSON.stringify({ firstName: "Alex", fullName: "Alex Rivera" }));
128
+ register(root, { sessionId: "other", cwd: "/x/openclaw", intent: "research" });
129
+ appendCards(root, [{ kind: "decision", title: "Shipped billing", salience: 0.9, ts: new Date().toISOString() }], { sessionId: "prev" });
130
+ const r = run("prime", { session_id: "me", cwd: "/x/maestro" }, root);
131
+ assert.equal(r.status, 0);
132
+ const frames = r.stdout.trim().split("\n").filter(Boolean);
133
+ assert.equal(frames.length, 1, "exactly one JSON frame on stdout");
134
+ const ctx = JSON.parse(frames[0]).hookSpecificOutput.additionalContext;
135
+ assert.match(ctx, /maestro:collective-digest/);
136
+ assert.match(ctx, /Shipped billing/);
137
+ assert.match(ctx, /maestro:identity/);
138
+ assert.match(ctx, /Session status: main session not running/);
139
+ } finally { rmSync(root, { recursive: true, force: true }); }
140
+ });
141
+
142
+ test("prime: a denylisted cwd gets neither memory nor identity", () => {
143
+ const root = tmpRoot();
144
+ try {
145
+ writeFileSync(join(root, "config", "collective.yaml"), "repoDenylist: [client-secret]\n");
146
+ writeFileSync(join(root, "config", "agent.json"), JSON.stringify({ firstName: "Alex", fullName: "Alex Rivera" }));
147
+ const r = run("prime", { session_id: "me", cwd: "/work/client-secret" }, root);
148
+ assert.equal(r.status, 0);
149
+ assert.equal(r.stdout.trim(), "");
150
+ } finally { rmSync(root, { recursive: true, force: true }); }
151
+ });
152
+
153
+ test("prime: the daemon's own `claude --print` children (MAESTRO_DAEMON=1) get the memory digest but NOT the identity primer", () => {
154
+ const root = tmpRoot();
155
+ try {
156
+ writeFileSync(join(root, "config", "agent.json"), JSON.stringify({ firstName: "Alex", fullName: "Alex Rivera" }));
157
+ // No digest material → a daemon child is fully silent.
158
+ const quiet = run("prime", { session_id: "d1", cwd: "/x/maestro" }, root, { MAESTRO_DAEMON: "1" });
159
+ assert.equal(quiet.status, 0);
160
+ assert.equal(quiet.stdout.trim(), "", "no identity block for a daemon child");
161
+ // With digest material → the digest still flows, the identity block still does not.
162
+ register(root, { sessionId: "other", cwd: "/x/openclaw", intent: "research" });
163
+ appendCards(root, [{ kind: "decision", title: "Shipped billing", salience: 0.9, ts: new Date().toISOString() }], { sessionId: "prev" });
164
+ const r = run("prime", { session_id: "d2", cwd: "/x/maestro" }, root, { MAESTRO_DAEMON: "1" });
165
+ assert.equal(r.status, 0);
166
+ const ctx = JSON.parse(r.stdout).hookSpecificOutput.additionalContext;
167
+ assert.match(ctx, /Shipped billing/);
168
+ assert.ok(!/maestro:identity/.test(ctx), "identity primer is skipped for daemon children");
169
+ // An interactive session on the same repo still gets it.
170
+ const i = run("prime", { session_id: "i1", cwd: "/x/maestro" }, root);
171
+ assert.match(JSON.parse(i.stdout).hookSpecificOutput.additionalContext, /maestro:identity/);
172
+ } finally { rmSync(root, { recursive: true, force: true }); }
173
+ });
@@ -0,0 +1,96 @@
1
+ /**
2
+ * agent-daemon-board-mine.test.mjs — the daemon caches hq `board.mine` to
3
+ * state/org/board-mine.json every 5 minutes (design §3.5, WP-M6).
4
+ *
5
+ * Drives the REAL refreshBoardMineCache with an injected listMine and a fixed
6
+ * clock under a tmp AGENT_DIR. Same `imapflow` loader stub as the other
7
+ * daemon tests.
8
+ */
9
+
10
+ import { test, before } from "node:test";
11
+ import assert from "node:assert/strict";
12
+ import { register } from "node:module";
13
+ import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, rmSync } from "node:fs";
14
+ import { join } from "node:path";
15
+ import { tmpdir } from "node:os";
16
+
17
+ const loaderSrc = `
18
+ export async function resolve(specifier, context, next) {
19
+ if (specifier === "imapflow") return { url: "imapflow-stub:main", shortCircuit: true };
20
+ return next(specifier, context);
21
+ }
22
+ export async function load(url, context, next) {
23
+ if (url === "imapflow-stub:main") return { format: "module", shortCircuit: true, source: "export class ImapFlow {}" };
24
+ return next(url, context);
25
+ }
26
+ `;
27
+ register(`data:text/javascript,${encodeURIComponent(loaderSrc)}`);
28
+
29
+ const AGENT_DIR = mkdtempSync(join(tmpdir(), "maestro-daemon-board-mine-"));
30
+ process.env.AGENT_DIR = AGENT_DIR;
31
+ process.env.MAESTRO_DAEMON_NO_AUTOSTART = "1";
32
+
33
+ const NOW = Date.parse("2026-09-08T12:00:00Z");
34
+ const CACHE = join(AGENT_DIR, "state", "org", "board-mine.json");
35
+
36
+ let daemon;
37
+ before(async () => {
38
+ mkdirSync(join(AGENT_DIR, "config"), { recursive: true });
39
+ mkdirSync(join(AGENT_DIR, "state", "sessions", "locks"), { recursive: true });
40
+ writeFileSync(join(AGENT_DIR, "config", "org.yaml"), "org:\n cohort:\n enabled: true\n base: https://os.example.test\n token: nlk_test_token\n orgId: org_test\n");
41
+ writeFileSync(join(AGENT_DIR, "config", "agent.json"), JSON.stringify({ firstName: "Nova", lastName: "Reyes" }));
42
+ const url = new URL("./agent-daemon.mjs", import.meta.url);
43
+ daemon = await import(`${url.href}?boardmine=${Math.random()}`);
44
+ });
45
+
46
+ test("first call writes state/org/board-mine.json as {ts, items} from listMine; a call inside 5 min is a no-op; one at 5 min refreshes", async () => {
47
+ const calls = [];
48
+ const listMineImpl = async (o) => { calls.push(o); return [{ itemId: "i1", title: "Do X", col: "todo" }, null, "junk"]; };
49
+ const first = await daemon.refreshBoardMineCache({ now: NOW, listMineImpl });
50
+ assert.deepEqual(first, { refreshed: true, reason: "written", count: 1 });
51
+ assert.ok(existsSync(CACHE));
52
+ const doc = JSON.parse(readFileSync(CACHE, "utf8"));
53
+ assert.deepEqual(doc, { ts: "2026-09-08T12:00:00.000Z", items: [{ itemId: "i1", title: "Do X", col: "todo" }] });
54
+ assert.equal(calls.length, 1);
55
+ assert.equal(calls[0].base, "https://os.example.test", "the daemon's org.yaml connection is what listMine gets");
56
+ assert.equal(calls[0].orgId, "org_test");
57
+
58
+ const soon = await daemon.refreshBoardMineCache({ now: NOW + 4 * 60_000, listMineImpl });
59
+ assert.deepEqual(soon, { refreshed: false, reason: "fresh" });
60
+ assert.equal(calls.length, 1, "no hq call inside the interval");
61
+
62
+ const later = await daemon.refreshBoardMineCache({ now: NOW + 5 * 60_000, listMineImpl: async () => ({ ok: true, items: [] }) });
63
+ assert.deepEqual(later, { refreshed: true, reason: "written", count: 0 });
64
+ assert.deepEqual(JSON.parse(readFileSync(CACHE, "utf8")), { ts: "2026-09-08T12:05:00.000Z", items: [] }, "an empty board is a real answer");
65
+ });
66
+
67
+ test("hq unreachable for one tick: the last known good items are KEPT and the document is marked stale with itemsAt; the next good read clears it", async () => {
68
+ await daemon.refreshBoardMineCache({ now: NOW + 10 * 60_000, listMineImpl: async () => [{ itemId: "keep-me" }] });
69
+ const failed = await daemon.refreshBoardMineCache({ now: NOW + 15 * 60_000, listMineImpl: async () => ({ ok: false, items: [], error: "http 503" }) });
70
+ assert.deepEqual(failed, { refreshed: true, reason: "kept-previous", count: 1 });
71
+ const doc = JSON.parse(readFileSync(CACHE, "utf8"));
72
+ assert.deepEqual(doc, { ts: "2026-09-08T12:15:00.000Z", items: [{ itemId: "keep-me" }], stale: true, itemsAt: "2026-09-08T12:10:00.000Z", error: "http 503" });
73
+ const ok = await daemon.refreshBoardMineCache({ now: NOW + 20 * 60_000, listMineImpl: async () => ({ ok: true, items: [{ itemId: "fresh" }] }) });
74
+ assert.deepEqual(ok, { refreshed: true, reason: "written", count: 1 });
75
+ assert.deepEqual(JSON.parse(readFileSync(CACHE, "utf8")), { ts: "2026-09-08T12:20:00.000Z", items: [{ itemId: "fresh" }] });
76
+ });
77
+
78
+ test("a corrupt cache is refreshed; force bypasses the interval; the tick-loop call never throws when listMine rejects", async () => {
79
+ writeFileSync(CACHE, "{not json");
80
+ const r = await daemon.refreshBoardMineCache({ now: NOW + 30 * 60_000, listMineImpl: async () => [{ itemId: "z" }] });
81
+ assert.equal(r.refreshed, true);
82
+ const forced = await daemon.refreshBoardMineCache({ now: NOW + 30 * 60_000 + 1, force: true, listMineImpl: async () => [{ itemId: "y" }] });
83
+ assert.equal(forced.refreshed, true);
84
+ assert.deepEqual(JSON.parse(readFileSync(CACHE, "utf8")).items, [{ itemId: "y" }]);
85
+ await assert.rejects(daemon.refreshBoardMineCache({ now: NOW + 40 * 60_000, listMineImpl: async () => { throw new Error("boom"); } }), /boom/);
86
+ assert.deepEqual(JSON.parse(readFileSync(CACHE, "utf8")).items, [{ itemId: "y" }], "a failed refresh leaves the previous cache in place");
87
+ });
88
+
89
+ test("an un-enrolled seat (org disabled) writes nothing", async () => {
90
+ writeFileSync(join(AGENT_DIR, "config", "org.yaml"), "org:\n cohort:\n enabled: false\n");
91
+ daemon._resetDaemonOrgCfgCache();
92
+ rmSync(CACHE, { force: true });
93
+ const r = await daemon.refreshBoardMineCache({ now: NOW + 60 * 60_000, listMineImpl: async () => [{ itemId: "no" }] });
94
+ assert.deepEqual(r, { refreshed: false, reason: "org-disabled" });
95
+ assert.ok(!existsSync(CACHE));
96
+ });
@@ -0,0 +1,238 @@
1
+ /**
2
+ * agent-daemon-design.test.mjs — the daemon re-syncs the brand foundation into
3
+ * DESIGN.md + PRODUCT.md, polled every 15 minutes and rewritten when the
4
+ * foundation's version moves (WP-M7 mechanic 4).
5
+ *
6
+ * Drives the REAL `refreshDesignFoundation` with an injected
7
+ * `branding.getFoundation` and a fixed clock under a tmp AGENT_DIR — the same
8
+ * shape as `agent-daemon-board-mine.test.mjs`, including its `imapflow` loader
9
+ * stub, because importing the daemon module pulls the whole seat in.
10
+ *
11
+ * The four claims: the 15-minute gate bounds the reads; a moved version is
12
+ * detected and named on the poll that sees it; an un-enrolled seat writes
13
+ * nothing; and no failure of hq's can blank a DESIGN.md already on disk.
14
+ */
15
+
16
+ import { test, before } from "node:test";
17
+ import assert from "node:assert/strict";
18
+ import { register } from "node:module";
19
+ import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, statSync, utimesSync, rmSync } from "node:fs";
20
+ import { join } from "node:path";
21
+ import { tmpdir } from "node:os";
22
+
23
+ const loaderSrc = `
24
+ export async function resolve(specifier, context, next) {
25
+ if (specifier === "imapflow") return { url: "imapflow-stub:main", shortCircuit: true };
26
+ return next(specifier, context);
27
+ }
28
+ export async function load(url, context, next) {
29
+ if (url === "imapflow-stub:main") return { format: "module", shortCircuit: true, source: "export class ImapFlow {}" };
30
+ return next(url, context);
31
+ }
32
+ `;
33
+ register(`data:text/javascript,${encodeURIComponent(loaderSrc)}`);
34
+
35
+ const AGENT_DIR = mkdtempSync(join(tmpdir(), "maestro-daemon-design-"));
36
+ process.env.AGENT_DIR = AGENT_DIR;
37
+ process.env.MAESTRO_DAEMON_NO_AUTOSTART = "1";
38
+
39
+ const NOW = Date.parse("2026-09-08T12:00:00Z");
40
+ const FIFTEEN_MIN = 15 * 60_000;
41
+ const DESIGN = join(AGENT_DIR, "DESIGN.md");
42
+ const PRODUCT = join(AGENT_DIR, "PRODUCT.md");
43
+ const STATE = join(AGENT_DIR, "state", "design", "foundation.json");
44
+
45
+ const FIXTURE = JSON.parse(readFileSync(new URL("../../lib/design/fixtures/foundation.json", import.meta.url), "utf8"));
46
+
47
+ const frame = (over = {}) => ({
48
+ ok: true,
49
+ result: {
50
+ foundation: FIXTURE,
51
+ version: { id: "bv_01HQZ", seq: 7, label: "V2.7" },
52
+ headVersionId: "bv_01HQZ",
53
+ isHead: true,
54
+ unversioned: false,
55
+ history: [],
56
+ ...over,
57
+ },
58
+ });
59
+
60
+ let daemon;
61
+ before(async () => {
62
+ mkdirSync(join(AGENT_DIR, "config"), { recursive: true });
63
+ mkdirSync(join(AGENT_DIR, "state", "sessions", "locks"), { recursive: true });
64
+ writeFileSync(
65
+ join(AGENT_DIR, "config", "org.yaml"),
66
+ "org:\n cohort:\n enabled: true\n base: https://os.example.test\n token: nlk_test_token\n orgId: org_test\n orgName: Northwind\n",
67
+ );
68
+ writeFileSync(join(AGENT_DIR, "config", "agent.json"), JSON.stringify({ firstName: "Nova", lastName: "Reyes" }));
69
+ const url = new URL("./agent-daemon.mjs", import.meta.url);
70
+ daemon = await import(`${url.href}?design=${Math.random()}`);
71
+ });
72
+
73
+ test("the first tick writes DESIGN.md + PRODUCT.md from the seat's own connection", async () => {
74
+ const calls = [];
75
+ const getFoundationImpl = async (params, o) => { calls.push({ params, o }); return frame(); };
76
+
77
+ const first = await daemon.refreshDesignFoundation({ now: NOW, getFoundationImpl });
78
+ assert.equal(first.refreshed, true);
79
+ assert.equal(first.reason, "never", "the gate's own words for a seat that had never synced");
80
+ assert.deepEqual(first.written, ["DESIGN.md", "PRODUCT.md"]);
81
+ assert.equal(first.version, "bv_01HQZ");
82
+
83
+ assert.equal(calls.length, 1);
84
+ assert.deepEqual(calls[0].params, { historyLimit: 0 });
85
+ assert.equal(calls[0].o.base, "https://os.example.test", "the daemon's org.yaml connection is what the read gets");
86
+ assert.equal(calls[0].o.orgId, "org_test");
87
+
88
+ assert.match(readFileSync(DESIGN, "utf8"), /^---\nname: "Northwind"\n/);
89
+ assert.match(readFileSync(PRODUCT, "utf8"), /# Northwind — product voice/);
90
+ assert.equal(statSync(DESIGN).mode & 0o777, 0o644);
91
+ assert.equal(JSON.parse(readFileSync(STATE, "utf8")).version, "bv_01HQZ");
92
+ });
93
+
94
+ test("a tick inside 15 minutes spends no hq call at all", async () => {
95
+ let calls = 0;
96
+ const getFoundationImpl = async () => { calls += 1; return frame(); };
97
+ const soon = await daemon.refreshDesignFoundation({ now: NOW + 14 * 60_000, getFoundationImpl });
98
+ assert.deepEqual(soon, { refreshed: false, reason: "fresh" });
99
+ assert.equal(calls, 0, "the gate is asked BEFORE the read, which is the point of it");
100
+ });
101
+
102
+ test("a tick at 15 minutes reads, finds nothing changed, and touches no file", async () => {
103
+ const old = new Date(NOW - 86_400_000);
104
+ utimesSync(DESIGN, old, old);
105
+ utimesSync(PRODUCT, old, old);
106
+ const before = [statSync(DESIGN).mtimeMs, statSync(PRODUCT).mtimeMs];
107
+
108
+ let calls = 0;
109
+ const at = await daemon.refreshDesignFoundation({ now: NOW + FIFTEEN_MIN, getFoundationImpl: async () => { calls += 1; return frame(); } });
110
+ assert.equal(calls, 1, "the interval is what bounds the reads — hq has no cheap etag for this");
111
+ assert.equal(at.refreshed, false, "an unchanged foundation is not a refresh");
112
+ assert.equal(at.reason, "interval");
113
+ assert.deepEqual([statSync(DESIGN).mtimeMs, statSync(PRODUCT).mtimeMs], before, "not one mtime moved");
114
+ });
115
+
116
+ test("a moved foundation is picked up on the next poll, and named 'version-changed' not 'interval'", async () => {
117
+ // The honest bound: hq exposes no cheap "has the foundation changed?" etag
118
+ // the way `integration.toolsetVersion` does, so a version change can only be
119
+ // SEEN by a read, and the 15-minute gate is what bounds the reads. What the
120
+ // gate's second call buys is a truthful reason — the daemon logs why this
121
+ // tick rewrote the file, and "the palette moved" is not "the timer fired".
122
+ const moved = JSON.parse(JSON.stringify(FIXTURE));
123
+ moved.colors[2].value = "#0f172a";
124
+ const r = await daemon.refreshDesignFoundation({
125
+ now: NOW + 2 * FIFTEEN_MIN,
126
+ getFoundationImpl: async () => frame({ foundation: moved, headVersionId: "bv_02", version: { id: "bv_02", seq: 8, label: "V2.8" } }),
127
+ });
128
+
129
+ assert.equal(r.refreshed, true);
130
+ assert.equal(r.reason, "version-changed", "not 'interval' — the gate's second call names the real cause");
131
+ assert.ok(r.written.includes("DESIGN.md"));
132
+ assert.match(readFileSync(DESIGN, "utf8"), /primary-moss: "#0f172a"/);
133
+ assert.match(readFileSync(DESIGN, "utf8"), /\*\*Version:\*\* V2\.8/);
134
+ assert.equal(JSON.parse(readFileSync(STATE, "utf8")).version, "bv_02");
135
+ });
136
+
137
+ test("a forced tick inside the interval still sees a version change for what it is", async () => {
138
+ const moved = JSON.parse(JSON.stringify(FIXTURE));
139
+ moved.colors[2].value = "#334155";
140
+ const r = await daemon.refreshDesignFoundation({
141
+ now: NOW + 2 * FIFTEEN_MIN + 60_000, // one minute later: the gate would say "fresh"
142
+ force: true,
143
+ getFoundationImpl: async () => frame({ foundation: moved, headVersionId: "bv_03", version: { id: "bv_03", seq: 9, label: "V2.9" } }),
144
+ });
145
+ assert.equal(r.reason, "version-changed");
146
+ assert.ok(r.written.includes("DESIGN.md"));
147
+ });
148
+
149
+ test("a fetch failure keeps the DESIGN.md already on disk — fail-open, never blanked", async () => {
150
+ const good = readFileSync(DESIGN, "utf8");
151
+ const old = new Date(NOW - 86_400_000);
152
+ utimesSync(DESIGN, old, old);
153
+ const mtime = statSync(DESIGN).mtimeMs;
154
+ const now = NOW + 4 * FIFTEEN_MIN;
155
+
156
+ const thrown = await daemon.refreshDesignFoundation({ now, getFoundationImpl: async () => { throw new Error("ECONNREFUSED"); } });
157
+ assert.deepEqual(thrown, { refreshed: false, reason: "fetch-failed" });
158
+
159
+ const errored = await daemon.refreshDesignFoundation({ now, getFoundationImpl: async () => ({ ok: false, error: { code: "UNAUTHORIZED", message: "bad token" } }) });
160
+ assert.deepEqual(errored, { refreshed: false, reason: "error:UNAUTHORIZED" });
161
+
162
+ const empty = await daemon.refreshDesignFoundation({ now, getFoundationImpl: async () => ({ ok: true, result: { foundation: null, headVersionId: null } }) });
163
+ assert.deepEqual(empty, { refreshed: false, reason: "no-foundation" });
164
+
165
+ assert.equal(readFileSync(DESIGN, "utf8"), good, "three failures, and the last-good file is byte-identical");
166
+ assert.equal(statSync(DESIGN).mtimeMs, mtime);
167
+ });
168
+
169
+ test("an org-disabled seat writes nothing and spends no call", async () => {
170
+ const dir = mkdtempSync(join(tmpdir(), "maestro-daemon-design-off-"));
171
+ try {
172
+ mkdirSync(join(dir, "config"), { recursive: true });
173
+ mkdirSync(join(dir, "state", "sessions", "locks"), { recursive: true });
174
+ writeFileSync(join(dir, "config", "org.yaml"), "org:\n cohort:\n enabled: false\n");
175
+ writeFileSync(join(dir, "config", "agent.json"), JSON.stringify({ firstName: "Nova" }));
176
+
177
+ const prev = process.env.AGENT_DIR;
178
+ process.env.AGENT_DIR = dir;
179
+ let off;
180
+ try {
181
+ const url = new URL("./agent-daemon.mjs", import.meta.url);
182
+ off = await import(`${url.href}?designoff=${Math.random()}`);
183
+ } finally {
184
+ process.env.AGENT_DIR = prev;
185
+ }
186
+
187
+ let calls = 0;
188
+ const r = await off.refreshDesignFoundation({ now: NOW, getFoundationImpl: async () => { calls += 1; return frame(); } });
189
+ assert.deepEqual(r, { refreshed: false, reason: "org-disabled" });
190
+ assert.equal(calls, 0);
191
+ assert.ok(!existsSync(join(dir, "DESIGN.md")));
192
+ assert.ok(!existsSync(join(dir, "state", "design", "foundation.json")));
193
+ } finally {
194
+ rmSync(dir, { recursive: true, force: true });
195
+ }
196
+ });
197
+
198
+ test("force skips the gate but nothing else — an unchanged foundation still writes nothing", async () => {
199
+ // Re-establish the on-disk files from the CURRENT head, then force a second
200
+ // read one second later: the gate would have said "fresh", the read happens
201
+ // anyway, and the byte comparison still refuses to touch the files.
202
+ const now = NOW + 5 * FIFTEEN_MIN;
203
+ await daemon.refreshDesignFoundation({ now, force: true, getFoundationImpl: async () => frame() });
204
+ let calls = 0;
205
+ const r = await daemon.refreshDesignFoundation({ now: now + 1_000, force: true, getFoundationImpl: async () => { calls += 1; return frame(); } });
206
+ assert.equal(calls, 1, "a forced tick reads even though the gate would have said 'fresh'");
207
+ assert.deepEqual(r.written, [], "and still writes nothing when the bytes already match");
208
+ assert.equal(r.refreshed, false);
209
+ });
210
+
211
+ test("a workspace that never saved a foundation gets nothing written — not hq's stock defaults", async () => {
212
+ // hq NEVER returns a null foundation: an org with no saved one reads back
213
+ // `dsDefaults()` (a complete, plausible palette that is nobody's brand) with
214
+ // `unversioned: true`. Writing it would ground the seat's design skills in
215
+ // another product's palette, with a generated file's authority behind it.
216
+ const dir = mkdtempSync(join(tmpdir(), "maestro-daemon-design-unver-"));
217
+ const prevAgent = process.env.AGENT_DIR;
218
+ try {
219
+ mkdirSync(join(dir, "config"), { recursive: true });
220
+ writeFileSync(
221
+ join(dir, "config", "org.yaml"),
222
+ "org:\n cohort:\n enabled: true\n base: https://os.example.test\n token: nlk_test_token\n orgId: org_test\n orgName: Northwind\n",
223
+ );
224
+ process.env.AGENT_DIR = dir;
225
+ const mod = await import(`${new URL("./agent-daemon.mjs", import.meta.url).href}?unver=${Math.random()}`);
226
+ const r = await mod.refreshDesignFoundation({
227
+ now: NOW,
228
+ getFoundationImpl: async () => frame({ headVersionId: null, version: null, unversioned: true }),
229
+ });
230
+ assert.deepEqual(r, { refreshed: false, reason: "unversioned" });
231
+ assert.ok(!existsSync(join(dir, "DESIGN.md")), "no DESIGN.md invented from stock defaults");
232
+ assert.ok(!existsSync(join(dir, "PRODUCT.md")));
233
+ assert.ok(!existsSync(join(dir, "state", "design", "foundation.json")));
234
+ } finally {
235
+ process.env.AGENT_DIR = prevAgent;
236
+ rmSync(dir, { recursive: true, force: true });
237
+ }
238
+ });
@@ -0,0 +1,60 @@
1
+ /**
2
+ * agent-daemon-frontdoor.test.mjs — the daemon steps back from the Cohort
3
+ * inbox while the main session is live (design §3.1).
4
+ *
5
+ * Drives the REAL fast cohort scan (pollCohortFast → pollService) with a live
6
+ * heartbeat planted under the tmp AGENT_DIR and a fresh inbox item: the item
7
+ * must be left exactly as it arrived (no lock, no rename, no classification).
8
+ * The not-live branch is the pre-existing dispatch path, which would reach the
9
+ * Haiku classifier — it is covered by the pure gate tests instead.
10
+ *
11
+ * Same `imapflow` loader stub as agent-daemon.test.mjs.
12
+ */
13
+
14
+ import { test, before } from "node:test";
15
+ import assert from "node:assert/strict";
16
+ import { register } from "node:module";
17
+ import { mkdtempSync, mkdirSync, writeFileSync, readdirSync } from "node:fs";
18
+ import { join } from "node:path";
19
+ import { tmpdir } from "node:os";
20
+
21
+ const loaderSrc = `
22
+ export async function resolve(specifier, context, next) {
23
+ if (specifier === "imapflow") return { url: "imapflow-stub:main", shortCircuit: true };
24
+ return next(specifier, context);
25
+ }
26
+ export async function load(url, context, next) {
27
+ if (url === "imapflow-stub:main") return { format: "module", shortCircuit: true, source: "export class ImapFlow {}" };
28
+ return next(url, context);
29
+ }
30
+ `;
31
+ register(`data:text/javascript,${encodeURIComponent(loaderSrc)}`);
32
+
33
+ const AGENT_DIR = mkdtempSync(join(tmpdir(), "maestro-daemon-frontdoor-"));
34
+ process.env.AGENT_DIR = AGENT_DIR;
35
+ process.env.MAESTRO_DAEMON_NO_AUTOSTART = "1";
36
+
37
+ let daemon;
38
+ before(async () => {
39
+ mkdirSync(join(AGENT_DIR, "config"), { recursive: true });
40
+ mkdirSync(join(AGENT_DIR, "state", "inbox", "cohort"), { recursive: true });
41
+ mkdirSync(join(AGENT_DIR, "state", "session"), { recursive: true });
42
+ mkdirSync(join(AGENT_DIR, "state", "sessions", "locks"), { recursive: true });
43
+ writeFileSync(join(AGENT_DIR, "config", "org.yaml"), "org:\n cohort:\n enabled: true\n");
44
+ writeFileSync(join(AGENT_DIR, "config", "agent.json"), JSON.stringify({ firstName: "Nova", lastName: "Reyes" }));
45
+ const url = new URL("./agent-daemon.mjs", import.meta.url);
46
+ daemon = await import(`${url.href}?frontdoor=${Math.random()}`);
47
+ });
48
+
49
+ test("live main session: pollCohortFast leaves a fresh cohort item untouched for the session", async () => {
50
+ writeFileSync(join(AGENT_DIR, "state", "session", "heartbeat.json"), JSON.stringify({ pid: process.pid, ts: new Date().toISOString() }));
51
+ const name = "2026-09-08T10-00-00-000Z-cohort-fd1.yaml";
52
+ writeFileSync(join(AGENT_DIR, "state", "inbox", "cohort", name), [
53
+ 'id: "cohort-fd1"', 'service: "cohort"', 'channel: "dm/olivia"', 'channel_id: "ch1"', 'channel_kind: "DM"',
54
+ 'sender: "Olivia Chen"', 'timestamp: "2026-09-08T10:00:00.000Z"', 'subject: ""', "content: |", " hello", 'raw_ref: "cohort-fd1"', "",
55
+ ].join("\n"));
56
+ const n = await daemon.pollCohortFast();
57
+ assert.equal(n, 0, "nothing dispatched by the daemon");
58
+ assert.deepEqual(readdirSync(join(AGENT_DIR, "state", "inbox", "cohort")), [name], "the item is still a fresh .yaml");
59
+ assert.deepEqual(readdirSync(join(AGENT_DIR, "state", "sessions", "locks")), [], "no per-item lock taken");
60
+ });