@wrongstack/core 0.287.0 → 0.291.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 (339) hide show
  1. package/dist/agent-status-tracker.d.ts +13 -0
  2. package/dist/agent-status-tracker.d.ts.map +1 -1
  3. package/dist/boot.d.ts.map +1 -1
  4. package/dist/chronicle/context.d.ts +13 -0
  5. package/dist/chronicle/context.d.ts.map +1 -0
  6. package/dist/chronicle/decision-adapter.d.ts +13 -0
  7. package/dist/chronicle/decision-adapter.d.ts.map +1 -0
  8. package/dist/chronicle/domain-adapter.d.ts +13 -0
  9. package/dist/chronicle/domain-adapter.d.ts.map +1 -0
  10. package/dist/chronicle/file-observer.d.ts +20 -0
  11. package/dist/chronicle/file-observer.d.ts.map +1 -0
  12. package/dist/chronicle/health-monitor.d.ts +11 -0
  13. package/dist/chronicle/health-monitor.d.ts.map +1 -0
  14. package/dist/chronicle/identity.d.ts +18 -0
  15. package/dist/chronicle/identity.d.ts.map +1 -0
  16. package/dist/chronicle/index.d.ts +16 -0
  17. package/dist/chronicle/index.d.ts.map +1 -0
  18. package/dist/chronicle/index.js +2555 -0
  19. package/dist/chronicle/index.js.map +7 -0
  20. package/dist/chronicle/journal.d.ts +81 -0
  21. package/dist/chronicle/journal.d.ts.map +1 -0
  22. package/dist/chronicle/process-adapter.d.ts +14 -0
  23. package/dist/chronicle/process-adapter.d.ts.map +1 -0
  24. package/dist/chronicle/prompt-manifest.d.ts +34 -0
  25. package/dist/chronicle/prompt-manifest.d.ts.map +1 -0
  26. package/dist/chronicle/provider-adapter.d.ts +13 -0
  27. package/dist/chronicle/provider-adapter.d.ts.map +1 -0
  28. package/dist/chronicle/query.d.ts +108 -0
  29. package/dist/chronicle/query.d.ts.map +1 -0
  30. package/dist/chronicle/rollup-adapter.d.ts +14 -0
  31. package/dist/chronicle/rollup-adapter.d.ts.map +1 -0
  32. package/dist/chronicle/stream-adapter.d.ts +13 -0
  33. package/dist/chronicle/stream-adapter.d.ts.map +1 -0
  34. package/dist/chronicle/tool-adapter.d.ts +15 -0
  35. package/dist/chronicle/tool-adapter.d.ts.map +1 -0
  36. package/dist/chronicle/types.d.ts +82 -0
  37. package/dist/chronicle/types.d.ts.map +1 -0
  38. package/dist/coordination/agent-monitor.d.ts +40 -0
  39. package/dist/coordination/agent-monitor.d.ts.map +1 -1
  40. package/dist/coordination/agent-subagent-runner.d.ts +7 -1
  41. package/dist/coordination/agent-subagent-runner.d.ts.map +1 -1
  42. package/dist/coordination/agents/phase6-domain.d.ts.map +1 -1
  43. package/dist/coordination/autonomous-coordinator.d.ts +2 -0
  44. package/dist/coordination/autonomous-coordinator.d.ts.map +1 -1
  45. package/dist/coordination/brain-monitor.d.ts +1 -1
  46. package/dist/coordination/brain.d.ts +3 -2
  47. package/dist/coordination/brain.d.ts.map +1 -1
  48. package/dist/coordination/collab-debug.d.ts +0 -9
  49. package/dist/coordination/collab-debug.d.ts.map +1 -1
  50. package/dist/coordination/coordinator/error-classifier.d.ts.map +1 -1
  51. package/dist/coordination/dep-watcher.d.ts +2 -1
  52. package/dist/coordination/dep-watcher.d.ts.map +1 -1
  53. package/dist/coordination/director/director-collab.d.ts +1 -1
  54. package/dist/coordination/director/director-collab.d.ts.map +1 -1
  55. package/dist/coordination/director-tools.d.ts.map +1 -1
  56. package/dist/coordination/director.d.ts +10 -1
  57. package/dist/coordination/director.d.ts.map +1 -1
  58. package/dist/coordination/file-author-tracker.d.ts.map +1 -1
  59. package/dist/coordination/fleet-bus.d.ts.map +1 -1
  60. package/dist/coordination/fleet-event-validation.d.ts +0 -7
  61. package/dist/coordination/fleet-event-validation.d.ts.map +1 -1
  62. package/dist/coordination/fleet-spawn.d.ts.map +1 -1
  63. package/dist/coordination/fleet-supervisor.d.ts +1 -1
  64. package/dist/coordination/fleet-supervisor.d.ts.map +1 -1
  65. package/dist/coordination/fleet.d.ts +0 -44
  66. package/dist/coordination/fleet.d.ts.map +1 -1
  67. package/dist/coordination/global-mailbox.d.ts +7 -1
  68. package/dist/coordination/global-mailbox.d.ts.map +1 -1
  69. package/dist/coordination/index.d.ts +5 -3
  70. package/dist/coordination/index.d.ts.map +1 -1
  71. package/dist/coordination/index.js +2426 -299
  72. package/dist/coordination/index.js.map +4 -4
  73. package/dist/coordination/knowledge-graph.d.ts +2 -1
  74. package/dist/coordination/knowledge-graph.d.ts.map +1 -1
  75. package/dist/coordination/large-answer-store.d.ts +0 -6
  76. package/dist/coordination/large-answer-store.d.ts.map +1 -1
  77. package/dist/coordination/mail-tools.d.ts +2 -2
  78. package/dist/coordination/mail-tools.d.ts.map +1 -1
  79. package/dist/coordination/mailbox-hooks.d.ts +2 -0
  80. package/dist/coordination/mailbox-hooks.d.ts.map +1 -1
  81. package/dist/coordination/mailbox-http-router.d.ts +43 -0
  82. package/dist/coordination/mailbox-http-router.d.ts.map +1 -0
  83. package/dist/coordination/mailbox-message-codec.d.ts +35 -0
  84. package/dist/coordination/mailbox-message-codec.d.ts.map +1 -1
  85. package/dist/coordination/mailbox-tool.d.ts +1 -1
  86. package/dist/coordination/mailbox-tool.d.ts.map +1 -1
  87. package/dist/coordination/mailbox-types.d.ts +170 -10
  88. package/dist/coordination/mailbox-types.d.ts.map +1 -1
  89. package/dist/coordination/mailbox.d.ts +1 -1
  90. package/dist/coordination/mailbox.d.ts.map +1 -1
  91. package/dist/coordination/package-author-tracker.d.ts.map +1 -1
  92. package/dist/coordination/provider-status-tracker.d.ts +236 -0
  93. package/dist/coordination/provider-status-tracker.d.ts.map +1 -0
  94. package/dist/coordination/subagent-budget.d.ts +2 -1
  95. package/dist/coordination/subagent-budget.d.ts.map +1 -1
  96. package/dist/core/agent-loop.d.ts +8 -3
  97. package/dist/core/agent-loop.d.ts.map +1 -1
  98. package/dist/core/agent-response.d.ts +5 -4
  99. package/dist/core/agent-response.d.ts.map +1 -1
  100. package/dist/core/agent-tools.d.ts +1 -1
  101. package/dist/core/agent-tools.d.ts.map +1 -1
  102. package/dist/core/agent.d.ts +4 -2
  103. package/dist/core/agent.d.ts.map +1 -1
  104. package/dist/core/context.d.ts +55 -1
  105. package/dist/core/context.d.ts.map +1 -1
  106. package/dist/core/fallback-model.d.ts +14 -8
  107. package/dist/core/fallback-model.d.ts.map +1 -1
  108. package/dist/core/fallback-profile-manager.d.ts +118 -0
  109. package/dist/core/fallback-profile-manager.d.ts.map +1 -0
  110. package/dist/core/fleet-pulse.d.ts +2 -1
  111. package/dist/core/fleet-pulse.d.ts.map +1 -1
  112. package/dist/core/iteration-limit.d.ts +2 -1
  113. package/dist/core/iteration-limit.d.ts.map +1 -1
  114. package/dist/core/mailbox-loop.d.ts +16 -1
  115. package/dist/core/mailbox-loop.d.ts.map +1 -1
  116. package/dist/core/model-availability-calendar.d.ts +27 -0
  117. package/dist/core/model-availability-calendar.d.ts.map +1 -0
  118. package/dist/core/provider-runner.d.ts.map +1 -1
  119. package/dist/core/system-prompt-builder.d.ts +2 -1
  120. package/dist/core/system-prompt-builder.d.ts.map +1 -1
  121. package/dist/defaults/index.js +1920 -598
  122. package/dist/defaults/index.js.map +4 -4
  123. package/dist/execution/auto-compaction-middleware.d.ts +3 -2
  124. package/dist/execution/auto-compaction-middleware.d.ts.map +1 -1
  125. package/dist/execution/compaction-core.d.ts.map +1 -1
  126. package/dist/execution/council-brain.d.ts +28 -49
  127. package/dist/execution/council-brain.d.ts.map +1 -1
  128. package/dist/execution/council-orchestrator.d.ts +30 -0
  129. package/dist/execution/council-orchestrator.d.ts.map +1 -1
  130. package/dist/execution/enhance-recovery.d.ts +8 -0
  131. package/dist/execution/enhance-recovery.d.ts.map +1 -1
  132. package/dist/execution/error-handler.d.ts +2 -2
  133. package/dist/execution/error-handler.d.ts.map +1 -1
  134. package/dist/execution/eternal-autonomy.d.ts.map +1 -1
  135. package/dist/execution/index.js +2600 -1903
  136. package/dist/execution/index.js.map +4 -4
  137. package/dist/execution/intelligent-compactor.d.ts +0 -16
  138. package/dist/execution/intelligent-compactor.d.ts.map +1 -1
  139. package/dist/execution/model-runtime.d.ts.map +1 -1
  140. package/dist/execution/one-shot-llm.d.ts +9 -1
  141. package/dist/execution/one-shot-llm.d.ts.map +1 -1
  142. package/dist/execution/prompt-enhancer.d.ts +36 -0
  143. package/dist/execution/prompt-enhancer.d.ts.map +1 -1
  144. package/dist/execution/prompt-enhancer.js +158 -10
  145. package/dist/execution/prompt-enhancer.js.map +2 -2
  146. package/dist/execution/retry-policy.d.ts +0 -13
  147. package/dist/execution/retry-policy.d.ts.map +1 -1
  148. package/dist/execution/skill-loader.d.ts.map +1 -1
  149. package/dist/execution/tool-executor.d.ts.map +1 -1
  150. package/dist/goal/checkpoint.d.ts.map +1 -0
  151. package/dist/{autophase/auto-phase-planner.d.ts → goal/goal-planner.d.ts} +8 -8
  152. package/dist/goal/goal-planner.d.ts.map +1 -0
  153. package/dist/{autophase/auto-phase-runner.d.ts → goal/goal-runner.d.ts} +10 -10
  154. package/dist/goal/goal-runner.d.ts.map +1 -0
  155. package/dist/{autophase → goal}/index.d.ts +3 -3
  156. package/dist/goal/index.d.ts.map +1 -0
  157. package/dist/goal/phase-graph-builder.d.ts.map +1 -0
  158. package/dist/{autophase → goal}/phase-orchestrator.d.ts +2 -2
  159. package/dist/goal/phase-orchestrator.d.ts.map +1 -0
  160. package/dist/goal/phase-store.d.ts.map +1 -0
  161. package/dist/{autophase → goal}/types.d.ts +2 -2
  162. package/dist/goal/types.d.ts.map +1 -0
  163. package/dist/hq/auth-store.d.ts.map +1 -1
  164. package/dist/hq/commands.d.ts +2 -1
  165. package/dist/hq/commands.d.ts.map +1 -1
  166. package/dist/hq/exposure.d.ts +66 -0
  167. package/dist/hq/exposure.d.ts.map +1 -0
  168. package/dist/hq/index.d.ts +1 -0
  169. package/dist/hq/index.d.ts.map +1 -1
  170. package/dist/hq/index.js +190 -21
  171. package/dist/hq/index.js.map +4 -4
  172. package/dist/hq/mailbox-mapper.d.ts +13 -1
  173. package/dist/hq/mailbox-mapper.d.ts.map +1 -1
  174. package/dist/hq/protocol/browser.d.ts +9 -1
  175. package/dist/hq/protocol/browser.d.ts.map +1 -1
  176. package/dist/hq/protocol/client.d.ts +2 -2
  177. package/dist/hq/protocol/client.d.ts.map +1 -1
  178. package/dist/hq/protocol/core.d.ts.map +1 -1
  179. package/dist/hq/protocol/mailbox.d.ts +6 -0
  180. package/dist/hq/protocol/mailbox.d.ts.map +1 -1
  181. package/dist/hq/protocol/session.d.ts +4 -0
  182. package/dist/hq/protocol/session.d.ts.map +1 -1
  183. package/dist/hq/publisher.d.ts.map +1 -1
  184. package/dist/index.d.ts +34 -25
  185. package/dist/index.d.ts.map +1 -1
  186. package/dist/index.js +30287 -22214
  187. package/dist/index.js.map +4 -4
  188. package/dist/infrastructure/index.js +60 -5
  189. package/dist/infrastructure/index.js.map +2 -2
  190. package/dist/kernel/events/agent-events.d.ts +33 -1
  191. package/dist/kernel/events/agent-events.d.ts.map +1 -1
  192. package/dist/kernel/events/file-events.d.ts +65 -0
  193. package/dist/kernel/events/file-events.d.ts.map +1 -0
  194. package/dist/kernel/events/memory-events.d.ts +36 -0
  195. package/dist/kernel/events/memory-events.d.ts.map +1 -1
  196. package/dist/kernel/events/network-events.d.ts +60 -0
  197. package/dist/kernel/events/network-events.d.ts.map +1 -0
  198. package/dist/kernel/events/process-events.d.ts +44 -0
  199. package/dist/kernel/events/process-events.d.ts.map +1 -0
  200. package/dist/kernel/events/provider-events.d.ts +89 -0
  201. package/dist/kernel/events/provider-events.d.ts.map +1 -1
  202. package/dist/kernel/events/tool-events.d.ts +10 -0
  203. package/dist/kernel/events/tool-events.d.ts.map +1 -1
  204. package/dist/kernel/events/worktree-events.d.ts +1 -1
  205. package/dist/kernel/events.d.ts +14 -1
  206. package/dist/kernel/events.d.ts.map +1 -1
  207. package/dist/kernel/index.js +2 -1
  208. package/dist/kernel/index.js.map +2 -2
  209. package/dist/kernel/tokens.d.ts +3 -1
  210. package/dist/kernel/tokens.d.ts.map +1 -1
  211. package/dist/mailbox-attach.d.ts.map +1 -1
  212. package/dist/models/index.js.map +2 -2
  213. package/dist/observability/index.d.ts +3 -0
  214. package/dist/observability/index.d.ts.map +1 -1
  215. package/dist/observability/index.js +278 -0
  216. package/dist/observability/index.js.map +4 -4
  217. package/dist/observability/network-telemetry.d.ts +15 -0
  218. package/dist/observability/network-telemetry.d.ts.map +1 -0
  219. package/dist/observability/process-telemetry.d.ts +18 -0
  220. package/dist/observability/process-telemetry.d.ts.map +1 -0
  221. package/dist/observability/redact-command.d.ts +20 -0
  222. package/dist/observability/redact-command.d.ts.map +1 -0
  223. package/dist/plugins/auto-review-plugin.d.ts +56 -3
  224. package/dist/plugins/auto-review-plugin.d.ts.map +1 -1
  225. package/dist/plugins/chimera-plugin.d.ts +164 -5
  226. package/dist/plugins/chimera-plugin.d.ts.map +1 -1
  227. package/dist/plugins/review-context-builder.d.ts +52 -0
  228. package/dist/plugins/review-context-builder.d.ts.map +1 -0
  229. package/dist/security/index.d.ts +1 -0
  230. package/dist/security/index.d.ts.map +1 -1
  231. package/dist/security/index.js +186 -9
  232. package/dist/security/index.js.map +4 -4
  233. package/dist/security/kanban-boundary.d.ts +10 -0
  234. package/dist/security/kanban-boundary.d.ts.map +1 -0
  235. package/dist/security/permission-policy.d.ts +1 -0
  236. package/dist/security/permission-policy.d.ts.map +1 -1
  237. package/dist/session-registry.d.ts +80 -0
  238. package/dist/session-registry.d.ts.map +1 -1
  239. package/dist/skills/index.js.map +2 -2
  240. package/dist/storage/config-loader.d.ts +7 -0
  241. package/dist/storage/config-loader.d.ts.map +1 -1
  242. package/dist/storage/file-session-writer.d.ts +20 -7
  243. package/dist/storage/file-session-writer.d.ts.map +1 -1
  244. package/dist/storage/goal-coordination.d.ts +40 -0
  245. package/dist/storage/goal-coordination.d.ts.map +1 -0
  246. package/dist/storage/goal-store.d.ts +9 -5
  247. package/dist/storage/goal-store.d.ts.map +1 -1
  248. package/dist/storage/index.d.ts +4 -2
  249. package/dist/storage/index.d.ts.map +1 -1
  250. package/dist/storage/index.js +1066 -226
  251. package/dist/storage/index.js.map +4 -4
  252. package/dist/storage/memory-consolidator.d.ts +49 -4
  253. package/dist/storage/memory-consolidator.d.ts.map +1 -1
  254. package/dist/storage/memory-graph-backend.d.ts +11 -0
  255. package/dist/storage/memory-graph-backend.d.ts.map +1 -1
  256. package/dist/storage/provider-config-watcher.d.ts +19 -0
  257. package/dist/storage/provider-config-watcher.d.ts.map +1 -1
  258. package/dist/storage/session-event-bridge.d.ts +2 -2
  259. package/dist/storage/session-event-bridge.d.ts.map +1 -1
  260. package/dist/storage/session-resume-validation.d.ts +10 -0
  261. package/dist/storage/session-resume-validation.d.ts.map +1 -1
  262. package/dist/storage/session-rewind-apply.d.ts +53 -0
  263. package/dist/storage/session-rewind-apply.d.ts.map +1 -0
  264. package/dist/storage/session-rewinder.d.ts.map +1 -1
  265. package/dist/storage/session-store.d.ts.map +1 -1
  266. package/dist/tasking/index.js.map +1 -1
  267. package/dist/tasking/task-store.d.ts +1 -1
  268. package/dist/tools/council-tool.d.ts +3 -0
  269. package/dist/tools/council-tool.d.ts.map +1 -1
  270. package/dist/tools/fallback-manage-tools.d.ts +82 -0
  271. package/dist/tools/fallback-manage-tools.d.ts.map +1 -0
  272. package/dist/tools/index.d.ts +1 -0
  273. package/dist/tools/index.d.ts.map +1 -1
  274. package/dist/tools/index.js +3423 -192
  275. package/dist/tools/index.js.map +4 -4
  276. package/dist/tools/one-shot-llm-tool.d.ts +2 -0
  277. package/dist/tools/one-shot-llm-tool.d.ts.map +1 -1
  278. package/dist/types/config.d.ts +76 -7
  279. package/dist/types/config.d.ts.map +1 -1
  280. package/dist/types/file-event-record.d.ts +68 -0
  281. package/dist/types/file-event-record.d.ts.map +1 -0
  282. package/dist/types/index.d.ts +1 -0
  283. package/dist/types/index.d.ts.map +1 -1
  284. package/dist/types/index.js +13 -8
  285. package/dist/types/index.js.map +3 -3
  286. package/dist/types/memory.d.ts +12 -0
  287. package/dist/types/memory.d.ts.map +1 -1
  288. package/dist/types/multi-agent.d.ts +12 -1
  289. package/dist/types/multi-agent.d.ts.map +1 -1
  290. package/dist/types/one-shot-llm.d.ts +16 -7
  291. package/dist/types/one-shot-llm.d.ts.map +1 -1
  292. package/dist/types/provider.d.ts +1 -1
  293. package/dist/types/provider.d.ts.map +1 -1
  294. package/dist/types/session.d.ts +68 -2
  295. package/dist/types/session.d.ts.map +1 -1
  296. package/dist/types/tool-executor.d.ts +2 -0
  297. package/dist/types/tool-executor.d.ts.map +1 -1
  298. package/dist/types/tool.d.ts +5 -0
  299. package/dist/types/tool.d.ts.map +1 -1
  300. package/dist/utils/atomic-write.d.ts.map +1 -1
  301. package/dist/utils/index.d.ts +10 -10
  302. package/dist/utils/index.d.ts.map +1 -1
  303. package/dist/utils/index.js +497 -254
  304. package/dist/utils/index.js.map +4 -4
  305. package/dist/utils/message-invariants.d.ts +9 -0
  306. package/dist/utils/message-invariants.d.ts.map +1 -1
  307. package/dist/utils/safe-json.d.ts +1 -1
  308. package/dist/utils/safe-json.d.ts.map +1 -1
  309. package/dist/utils/term.d.ts +279 -0
  310. package/dist/utils/term.d.ts.map +1 -1
  311. package/dist/utils/tool-wire-compact.d.ts +9 -0
  312. package/dist/utils/tool-wire-compact.d.ts.map +1 -1
  313. package/dist/utils/wstack-paths.d.ts +12 -2
  314. package/dist/utils/wstack-paths.d.ts.map +1 -1
  315. package/dist/worktree/worktree-manager.d.ts +1 -1
  316. package/dist/worktree/worktree-manager.d.ts.map +1 -1
  317. package/instructions/agents/ios.md +113 -0
  318. package/instructions/agents/search.md +1 -1
  319. package/instructions/llm/chimera-review.md +66 -9
  320. package/instructions/llm/memory-consolidator.md +4 -12
  321. package/instructions/llm/prompt-enhancer.md +3 -1
  322. package/instructions/sections/tool/common-patterns.md +3 -3
  323. package/instructions/system.md +40 -5
  324. package/package.json +7 -3
  325. package/skills/auto-review/SKILL.md +176 -0
  326. package/skills/mnemosyne/SKILL.md +156 -0
  327. package/skills/mnemosyne/instructions/agent-prompt.md +200 -0
  328. package/dist/autophase/auto-phase-planner.d.ts.map +0 -1
  329. package/dist/autophase/auto-phase-runner.d.ts.map +0 -1
  330. package/dist/autophase/checkpoint.d.ts.map +0 -1
  331. package/dist/autophase/index.d.ts.map +0 -1
  332. package/dist/autophase/phase-graph-builder.d.ts.map +0 -1
  333. package/dist/autophase/phase-orchestrator.d.ts.map +0 -1
  334. package/dist/autophase/phase-store.d.ts.map +0 -1
  335. package/dist/autophase/types.d.ts.map +0 -1
  336. /package/dist/{autophase → goal}/checkpoint.d.ts +0 -0
  337. /package/dist/{autophase → goal}/phase-graph-builder.d.ts +0 -0
  338. /package/dist/{autophase → goal}/phase-store.d.ts +0 -0
  339. /package/instructions/{autophase → goal}/phase-planner.md +0 -0
package/dist/hq/index.js CHANGED
@@ -14,13 +14,21 @@ var KNOWN_HQ_CLIENT_FRAME_TYPES = /* @__PURE__ */ new Set([
14
14
  "client.command_poll",
15
15
  "client.command_ack"
16
16
  ]);
17
- var HQ_CLIENT_KINDS = /* @__PURE__ */ new Set(["tui", "repl", "webui", "cli", "unknown"]);
17
+ var HQ_CLIENT_KINDS = /* @__PURE__ */ new Set([
18
+ "tui",
19
+ "repl",
20
+ "webui",
21
+ "cli",
22
+ "mailbox",
23
+ "unknown"
24
+ ]);
18
25
  var HQ_WORKSPACE_KINDS = /* @__PURE__ */ new Set(["git", "directory", "unknown"]);
19
26
  var HQ_CLIENT_CAPABILITIES = /* @__PURE__ */ new Set([
20
27
  "telemetry.publish",
21
28
  "session.summary",
22
29
  "fleet.summary",
23
30
  "mailbox.summary",
31
+ "mailbox.serve",
24
32
  "control.receive"
25
33
  ]);
26
34
  var HQ_COMMAND_ACK_STATUSES = /* @__PURE__ */ new Set([
@@ -832,6 +840,23 @@ function summarizeHqToolArgs(value, options = {}) {
832
840
  return summary;
833
841
  }
834
842
 
843
+ // src/coordination/mailbox-types.ts
844
+ var SESSION_RECIPIENT_PREFIX = "@session:";
845
+ function sessionRecipient(sessionId) {
846
+ const normalizedSessionId = sessionId.trim();
847
+ if (!normalizedSessionId) {
848
+ throw new TypeError('sessionId is required for the "@session" recipient');
849
+ }
850
+ return `${SESSION_RECIPIENT_PREFIX}${normalizedSessionId}`;
851
+ }
852
+ function normalizeRecipient(to, sessionId) {
853
+ const trimmed = to.trim();
854
+ const normalized = trimmed.toLowerCase();
855
+ if (normalized === "all") return "*";
856
+ if (normalized === "@session") return sessionRecipient(sessionId ?? "");
857
+ return trimmed;
858
+ }
859
+
835
860
  // src/hq/mailbox-mapper.ts
836
861
  function previewText(value, maxLength, policy) {
837
862
  if (value === void 0 || value.length === 0) return void 0;
@@ -845,6 +870,15 @@ function previewText(value, maxLength, policy) {
845
870
  function readCount(message) {
846
871
  return Object.keys(message.readBy).length;
847
872
  }
873
+ function classifyMailboxRecipient(to) {
874
+ if (to === "*" || to === "all") return { scope: "project" };
875
+ if (to.startsWith(SESSION_RECIPIENT_PREFIX)) {
876
+ const recipientSessionId = to.slice(SESSION_RECIPIENT_PREFIX.length);
877
+ if (recipientSessionId.length === 0) return { scope: "agent" };
878
+ return { scope: "session", recipientSessionId };
879
+ }
880
+ return { scope: "agent" };
881
+ }
848
882
  function taskSummary(message) {
849
883
  if (message.taskContext === void 0) return void 0;
850
884
  const task = {
@@ -860,12 +894,15 @@ function mapMailboxMessageToHqSummary(message, options = {}) {
860
894
  const bodyPreview = previewText(message.body, previewLength, options.redactionPolicy);
861
895
  const outcomePreview = previewText(message.outcome, previewLength, options.redactionPolicy);
862
896
  const task = taskSummary(message);
897
+ const recipient = classifyMailboxRecipient(message.to);
863
898
  return {
864
899
  mailId: message.id,
865
900
  // unique UUID per message record, used for deduplication
866
901
  messageId: message.id,
867
902
  from: message.from,
868
903
  to: message.to,
904
+ scope: recipient.scope,
905
+ ...recipient.recipientSessionId !== void 0 ? { recipientSessionId: recipient.recipientSessionId } : {},
869
906
  type: message.type,
870
907
  subject: previewText(message.subject, previewLength, options.redactionPolicy) ?? "",
871
908
  priority: message.priority,
@@ -951,7 +988,7 @@ var DEFAULT_RECONNECT_BASE_MS = 1e3;
951
988
  var DEFAULT_RECONNECT_MAX_MS = 3e4;
952
989
  var DEFAULT_DISCOVERY_POLL_MS = 5e3;
953
990
  var DEFAULT_MAX_QUEUED_MESSAGES = 2e3;
954
- var DEFAULT_COMMAND_POLL_INTERVAL_MS = 2e3;
991
+ var DEFAULT_COMMAND_POLL_INTERVAL_MS = 500;
955
992
  var DEFAULT_COMMAND_POLL_LIMIT = 25;
956
993
  var DEFAULT_HEARTBEAT_INTERVAL_MS = 25e3;
957
994
  function defaultSocketFactory(url) {
@@ -1477,6 +1514,11 @@ function resolveWstackPaths(opts) {
1477
1514
  homeDir,
1478
1515
  configDir: globalRoot,
1479
1516
  globalConfig: path2.join(globalRoot, "config.json"),
1517
+ profilesDir: path2.join(globalRoot, "profiles"),
1518
+ profileConfig: (name) => {
1519
+ const safe = name.replace(/[/\\:]/g, "_").replace(/\.\./g, "_");
1520
+ return path2.join(globalRoot, "profiles", safe || "default", "config.json");
1521
+ },
1480
1522
  secretsKey: path2.join(globalRoot, ".key"),
1481
1523
  globalMemory: path2.join(globalRoot, "memory.md"),
1482
1524
  globalSkills: path2.join(globalRoot, "skills"),
@@ -1671,7 +1713,7 @@ async function withFileLock(targetPath, fn, opts = {}) {
1671
1713
  const dir = path3.dirname(targetPath);
1672
1714
  await fs2.mkdir(dir, { recursive: true });
1673
1715
  const lockPath = path3.join(dir, `.${path3.basename(targetPath)}.lock`);
1674
- const timeoutMs = opts.timeoutMs ?? 5e3;
1716
+ const timeoutMs = opts.timeoutMs ?? 15e3;
1675
1717
  const staleMs = opts.staleMs ?? 3e4;
1676
1718
  const started = Date.now();
1677
1719
  let handle;
@@ -1681,6 +1723,13 @@ async function withFileLock(targetPath, fn, opts = {}) {
1681
1723
  await handle.writeFile(`${process.pid}:${Date.now()}`);
1682
1724
  break;
1683
1725
  } catch (err) {
1726
+ if (handle) {
1727
+ await handle.close().catch(() => {
1728
+ });
1729
+ await fs2.unlink(lockPath).catch(() => {
1730
+ });
1731
+ handle = void 0;
1732
+ }
1684
1733
  const code = err.code;
1685
1734
  if (code === "ENOENT") {
1686
1735
  await fs2.mkdir(dir, { recursive: true });
@@ -1964,11 +2013,6 @@ function serializeAckRecord(ack) {
1964
2013
  return JSON.stringify(ack) + "\n";
1965
2014
  }
1966
2015
 
1967
- // src/coordination/mailbox-types.ts
1968
- function normalizeRecipient(to) {
1969
- return to.trim().toLowerCase() === "all" ? "*" : to.trim();
1970
- }
1971
-
1972
2016
  // src/coordination/global-mailbox.ts
1973
2017
  var MAILBOX_FILE = "_mailbox.jsonl";
1974
2018
  var CLIENT_REGISTRY_FILE = "_mailbox.clients.json";
@@ -2097,9 +2141,9 @@ var GlobalMailbox = class {
2097
2141
  const msg = {
2098
2142
  id: randomUUID2(),
2099
2143
  from: input.from,
2100
- // "all" is an accepted spelling of the broadcast address — canonical
2101
- // form on disk is '*' so every query/checker matches it.
2102
- to: normalizeRecipient(input.to),
2144
+ // "all" maps to project broadcast; "@session" is resolved against the
2145
+ // sender's session before persistence so recipients can match it exactly.
2146
+ to: normalizeRecipient(input.to, input.senderSessionId),
2103
2147
  type: normalizeMailboxMessageType(input.type),
2104
2148
  subject: input.subject,
2105
2149
  body: input.body,
@@ -2109,6 +2153,7 @@ var GlobalMailbox = class {
2109
2153
  timestamp: now,
2110
2154
  replyTo: input.replyTo,
2111
2155
  taskContext: input.taskContext,
2156
+ senderSessionId: input.senderSessionId,
2112
2157
  expiresAt: input.ttlMs !== void 0 ? new Date(Date.now() + input.ttlMs).toISOString() : void 0
2113
2158
  };
2114
2159
  const line = JSON.stringify(msg) + LINE_SEPARATOR;
@@ -2164,6 +2209,7 @@ var GlobalMailbox = class {
2164
2209
  for (const m of candidates) {
2165
2210
  if (q.to !== void 0 && m.to !== q.to && m.to !== "*") continue;
2166
2211
  if (q.from !== void 0 && m.from !== q.from) continue;
2212
+ if (q.sessionId !== void 0 && m.senderSessionId !== q.sessionId) continue;
2167
2213
  if (q.unreadBy !== void 0 && q.unreadBy in m.readBy) continue;
2168
2214
  if (q.incompleteOnly && m.completed) continue;
2169
2215
  if (queryType !== void 0 && m.type !== queryType) continue;
@@ -2293,8 +2339,9 @@ var GlobalMailbox = class {
2293
2339
  if (updated.length > 0) this.publishHqMailboxSnapshot();
2294
2340
  return updated;
2295
2341
  }
2296
- async unreadCount(forAgentId) {
2342
+ async unreadCount(forAgentId, sessionId) {
2297
2343
  const all = await this._readMessagesCached();
2344
+ const scopedSessionRecipient = sessionId === void 0 ? void 0 : sessionRecipient(sessionId);
2298
2345
  let count = 0;
2299
2346
  if (this._recipientIndex !== null) {
2300
2347
  const indices = /* @__PURE__ */ new Set();
@@ -2302,6 +2349,10 @@ var GlobalMailbox = class {
2302
2349
  if (direct !== void 0) for (const i of direct) indices.add(i);
2303
2350
  const broadcasts = this._recipientIndex.get("*");
2304
2351
  if (broadcasts !== void 0) for (const i of broadcasts) indices.add(i);
2352
+ if (scopedSessionRecipient !== void 0) {
2353
+ const sessionBroadcasts = this._recipientIndex.get(scopedSessionRecipient);
2354
+ if (sessionBroadcasts !== void 0) for (const i of sessionBroadcasts) indices.add(i);
2355
+ }
2305
2356
  for (const i of indices) {
2306
2357
  const m = all[i];
2307
2358
  if (!(forAgentId in m.readBy) && !m.completed) count++;
@@ -2309,9 +2360,7 @@ var GlobalMailbox = class {
2309
2360
  } else {
2310
2361
  for (let i = 0; i < all.length; i++) {
2311
2362
  const m = all[i];
2312
- if ((m.to === forAgentId || m.to === "*") && !(forAgentId in m.readBy) && !m.completed) {
2313
- count++;
2314
- }
2363
+ if ((m.to === forAgentId || m.to === "*" || m.to === scopedSessionRecipient) && !(forAgentId in m.readBy) && !m.completed) count++;
2315
2364
  }
2316
2365
  }
2317
2366
  return count;
@@ -2415,7 +2464,7 @@ var GlobalMailbox = class {
2415
2464
  toolCalls: 0,
2416
2465
  registeredAt: now,
2417
2466
  lastSeenAt: now,
2418
- pid: input.pid,
2467
+ pid: input.pid ?? process.pid,
2419
2468
  source: input.source
2420
2469
  };
2421
2470
  await withFileLock(this.registryPath, async () => {
@@ -2447,7 +2496,7 @@ var GlobalMailbox = class {
2447
2496
  lastActivityAt: now,
2448
2497
  lastSeenAt: now,
2449
2498
  online: true,
2450
- pid: input.pid,
2499
+ pid: input.pid ?? process.pid,
2451
2500
  ...input.source !== void 0 ? { source: input.source } : {}
2452
2501
  }
2453
2502
  });
@@ -2574,7 +2623,7 @@ var GlobalMailbox = class {
2574
2623
  source: input.source,
2575
2624
  registeredAt: now,
2576
2625
  lastSeenAt: now,
2577
- pid: input.pid
2626
+ pid: input.pid ?? process.pid
2578
2627
  };
2579
2628
  await withFileLock(this.clientRegistryPath, async () => {
2580
2629
  const registry = await this._readClientRegistry({ fresh: true });
@@ -3084,6 +3133,48 @@ var GlobalMailbox = class {
3084
3133
  async _ensureRegistry() {
3085
3134
  await fsp.mkdir(path4.dirname(this.registryPath), { recursive: true });
3086
3135
  }
3136
+ /** Minimal shape-check for a deserialized agent registry entry.
3137
+ * Logs a warning and returns `false` for structurally invalid data
3138
+ * so a single corrupted entry doesn't break the entire registry. */
3139
+ _parseAgentEntry(value) {
3140
+ if (typeof value !== "object" || value === null) return null;
3141
+ const v = value;
3142
+ if (typeof v.agentId !== "string") return null;
3143
+ if (typeof v.sessionId !== "string") return null;
3144
+ const statuses = ["idle", "busy", "running", "streaming", "waiting_user", "error"];
3145
+ const status = typeof v.status === "string" && statuses.includes(v.status) ? v.status : "idle";
3146
+ return {
3147
+ ...v,
3148
+ agentId: v.agentId,
3149
+ sessionId: v.sessionId,
3150
+ name: typeof v.name === "string" ? v.name : v.agentId,
3151
+ registeredAt: typeof v.registeredAt === "string" ? v.registeredAt : (/* @__PURE__ */ new Date(0)).toISOString(),
3152
+ lastSeenAt: typeof v.lastSeenAt === "string" ? v.lastSeenAt : (/* @__PURE__ */ new Date(0)).toISOString(),
3153
+ iterations: typeof v.iterations === "number" && Number.isFinite(v.iterations) ? v.iterations : 0,
3154
+ toolCalls: typeof v.toolCalls === "number" && Number.isFinite(v.toolCalls) ? v.toolCalls : 0,
3155
+ pid: typeof v.pid === "number" && Number.isFinite(v.pid) ? v.pid : 0,
3156
+ status
3157
+ };
3158
+ }
3159
+ /** Minimal shape-check for a deserialized client registry entry. */
3160
+ _parseClientEntry(value) {
3161
+ if (typeof value !== "object" || value === null) return null;
3162
+ const v = value;
3163
+ if (typeof v.clientId !== "string") return null;
3164
+ if (typeof v.sessionId !== "string") return null;
3165
+ const sources = ["repl", "tui", "webui", "http"];
3166
+ const source = typeof v.source === "string" && sources.includes(v.source) ? v.source : "http";
3167
+ return {
3168
+ ...v,
3169
+ clientId: v.clientId,
3170
+ sessionId: v.sessionId,
3171
+ name: typeof v.name === "string" ? v.name : v.clientId,
3172
+ registeredAt: typeof v.registeredAt === "string" ? v.registeredAt : (/* @__PURE__ */ new Date(0)).toISOString(),
3173
+ lastSeenAt: typeof v.lastSeenAt === "string" ? v.lastSeenAt : (/* @__PURE__ */ new Date(0)).toISOString(),
3174
+ pid: typeof v.pid === "number" && Number.isFinite(v.pid) ? v.pid : 0,
3175
+ source
3176
+ };
3177
+ }
3087
3178
  async _readRegistry(opts) {
3088
3179
  if (!opts?.fresh && this._registryCache && Date.now() - this._registryCacheAt < REGISTRY_CACHE_TTL_MS) {
3089
3180
  return new Map(this._registryCache);
@@ -3093,7 +3184,12 @@ var GlobalMailbox = class {
3093
3184
  const data = JSON.parse(raw);
3094
3185
  const map = /* @__PURE__ */ new Map();
3095
3186
  for (const [id, agent] of Object.entries(data)) {
3096
- map.set(id, agent);
3187
+ const parsed = this._parseAgentEntry(agent);
3188
+ if (parsed) {
3189
+ map.set(id, parsed);
3190
+ } else {
3191
+ console.warn(JSON.stringify({ level: "warn", event: "mailbox.registry.invalid_agent", message: `Skipping malformed agent entry "${id}" in registry`, timestamp: (/* @__PURE__ */ new Date()).toISOString() }));
3192
+ }
3097
3193
  }
3098
3194
  this._registryCache = map;
3099
3195
  this._registryCacheAt = Date.now();
@@ -3139,7 +3235,12 @@ var GlobalMailbox = class {
3139
3235
  const data = JSON.parse(raw);
3140
3236
  const map = /* @__PURE__ */ new Map();
3141
3237
  for (const [id, client] of Object.entries(data)) {
3142
- map.set(id, client);
3238
+ const parsed = this._parseClientEntry(client);
3239
+ if (parsed) {
3240
+ map.set(id, parsed);
3241
+ } else {
3242
+ console.warn(JSON.stringify({ level: "warn", event: "mailbox.registry.invalid_client", message: `Skipping malformed client entry "${id}" in client registry`, timestamp: (/* @__PURE__ */ new Date()).toISOString() }));
3243
+ }
3143
3244
  }
3144
3245
  this._clientRegistryCache = map;
3145
3246
  this._clientRegistryCacheAt = Date.now();
@@ -3276,7 +3377,23 @@ async function ensureHqFirstRunAuthFile(dataDir, opts = {}) {
3276
3377
  const file = hqAuthFilePath(dataDir);
3277
3378
  try {
3278
3379
  await fs3.access(file);
3279
- return { authFile: await readHqAuthFile(dataDir, opts), created: false };
3380
+ const existing = await readHqAuthFile(dataDir, opts);
3381
+ if (opts.password) {
3382
+ const passwordUnchanged = existing.passwordHash !== void 0 && await verifyHqPassword(opts.password, existing.passwordHash);
3383
+ if (!passwordUnchanged) {
3384
+ const authFile2 = {
3385
+ ...existing,
3386
+ passwordHash: await hashHqPassword(opts.password),
3387
+ // Rotating the cookie secret invalidates sessions created with the
3388
+ // previous password. This matters when --password is used to
3389
+ // recover or deliberately change an existing HQ installation.
3390
+ cookieSecret: mintHqCookieSecret()
3391
+ };
3392
+ await writeHqAuthFile(dataDir, authFile2);
3393
+ return { authFile: await readHqAuthFile(dataDir, opts), created: false };
3394
+ }
3395
+ }
3396
+ return { authFile: existing, created: false };
3280
3397
  } catch (err) {
3281
3398
  if (err.code !== "ENOENT") {
3282
3399
  opts.warn?.(`HQ auth file access failed at ${file}: ${err.message}`);
@@ -3518,6 +3635,49 @@ function createGlobalMailbox(options) {
3518
3635
  return new GlobalMailbox(options.projectDir, options.events, options.hqPublisher);
3519
3636
  }
3520
3637
 
3638
+ // src/hq/exposure.ts
3639
+ var HQ_CLI_DEFAULT_HOST = "0.0.0.0";
3640
+ var HqInsecureExposureError = class extends Error {
3641
+ constructor(message) {
3642
+ super(message);
3643
+ this.name = "HqInsecureExposureError";
3644
+ }
3645
+ };
3646
+ function isLoopbackHost(host) {
3647
+ const normalized = host.trim().toLowerCase().replace(/^\[/, "").replace(/\]$/, "");
3648
+ if (normalized === "localhost" || normalized === "::1") return true;
3649
+ return /^127\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(normalized);
3650
+ }
3651
+ function isOpenMode(input) {
3652
+ return !input.hasBrowserTokens && !input.hasPassword;
3653
+ }
3654
+ function assessHqExposure(input) {
3655
+ if (isLoopbackHost(input.host)) return { kind: "ok" };
3656
+ if (isOpenMode(input)) {
3657
+ const detail = `HQ is configured in open mode (no browser tokens and no password), so every request \u2014 including POST /api/command, which runs commands in your live sessions \u2014 is served unauthenticated. Binding that to ${input.host} exposes it to every peer on the network.`;
3658
+ if (input.allowInsecure) {
3659
+ return {
3660
+ kind: "warn",
3661
+ message: `${detail} Continuing because --insecure-open was passed.`
3662
+ };
3663
+ }
3664
+ return {
3665
+ kind: "refuse",
3666
+ message: `${detail}
3667
+
3668
+ Fix one of these, then retry:
3669
+ \u2022 bind locally: wstack hq --host 127.0.0.1
3670
+ \u2022 mint a token: wstack hq token create
3671
+ \u2022 set a password: wstack hq --password <value>
3672
+ \u2022 accept the risk: wstack hq --insecure-open`
3673
+ };
3674
+ }
3675
+ return {
3676
+ kind: "warn",
3677
+ message: `HQ is bound to ${input.host} (all interfaces) without TLS. Access tokens travel in cleartext and appear in the URL query. Prefer --host 127.0.0.1 unless you intend HQ to be reachable from other machines.`
3678
+ };
3679
+ }
3680
+
3521
3681
  // src/hq/session-bridge.ts
3522
3682
  import * as fs5 from "node:fs";
3523
3683
  import * as fsp2 from "node:fs/promises";
@@ -4617,6 +4777,9 @@ var HqCommandAuditLog = class {
4617
4777
  this.onPersist?.(entry);
4618
4778
  }
4619
4779
  }
4780
+ get(commandId) {
4781
+ return this.entries.find((entry) => entry.commandId === commandId);
4782
+ }
4620
4783
  /** Update only when the command belongs to the authenticated client. */
4621
4784
  updateForClient(commandId, clientId, patch) {
4622
4785
  const entry = this.entries.find(
@@ -4808,17 +4971,21 @@ function toAlertMessage(alert) {
4808
4971
  export {
4809
4972
  DEFAULT_HQ_REDACTION_POLICY,
4810
4973
  HQ_AUTH_FILE_VERSION,
4974
+ HQ_CLI_DEFAULT_HOST,
4811
4975
  HQ_COMMAND_TYPES,
4812
4976
  HQ_PROTOCOL_VERSION,
4813
4977
  HQ_TRANSCRIPT_TEXT_CAP,
4814
4978
  HqAlertEngine,
4815
4979
  HqCommandAuditLog,
4816
4980
  HqEventLog,
4981
+ HqInsecureExposureError,
4817
4982
  HqPublisher,
4818
4983
  HqSimpleLog,
4819
4984
  HqSnapshotStore,
4820
4985
  HqTimeseriesStore,
4986
+ assessHqExposure,
4821
4987
  buildTranscriptFromEvents,
4988
+ classifyMailboxRecipient,
4822
4989
  createGlobalMailbox,
4823
4990
  createHqEventEnvelope,
4824
4991
  createHqPersistence,
@@ -4833,6 +5000,8 @@ export {
4833
5000
  hashHqPassword,
4834
5001
  hqAuthFilePath,
4835
5002
  hqRuntimeFilePath,
5003
+ isLoopbackHost,
5004
+ isOpenMode,
4836
5005
  mapMailboxAgentToHqSummary,
4837
5006
  mapMailboxMessageToHqSummary,
4838
5007
  mapSessionEventToEntries,