@wrongstack/core 0.285.0 → 0.287.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 (340) hide show
  1. package/dist/autophase/phase-orchestrator.d.ts.map +1 -1
  2. package/dist/boot.d.ts.map +1 -1
  3. package/dist/coordination/agent-monitor.d.ts +29 -0
  4. package/dist/coordination/agent-monitor.d.ts.map +1 -1
  5. package/dist/coordination/autonomous-brain.d.ts +0 -2
  6. package/dist/coordination/autonomous-brain.d.ts.map +1 -1
  7. package/dist/coordination/autonomous-coordinator.d.ts +4 -0
  8. package/dist/coordination/autonomous-coordinator.d.ts.map +1 -1
  9. package/dist/coordination/brain-ledger.d.ts +142 -0
  10. package/dist/coordination/brain-ledger.d.ts.map +1 -0
  11. package/dist/coordination/brain-monitor.d.ts +46 -2
  12. package/dist/coordination/brain-monitor.d.ts.map +1 -1
  13. package/dist/coordination/brain.d.ts +43 -0
  14. package/dist/coordination/brain.d.ts.map +1 -1
  15. package/dist/coordination/delegate-tool.d.ts +8 -14
  16. package/dist/coordination/delegate-tool.d.ts.map +1 -1
  17. package/dist/coordination/director/director-btw-notes.d.ts +20 -0
  18. package/dist/coordination/director/director-btw-notes.d.ts.map +1 -0
  19. package/dist/coordination/director/director-collab.d.ts +40 -0
  20. package/dist/coordination/director/director-collab.d.ts.map +1 -0
  21. package/dist/coordination/director.d.ts +28 -9
  22. package/dist/coordination/director.d.ts.map +1 -1
  23. package/dist/coordination/fleet-manager.d.ts +21 -0
  24. package/dist/coordination/fleet-manager.d.ts.map +1 -1
  25. package/dist/coordination/fleet.d.ts +6 -7
  26. package/dist/coordination/fleet.d.ts.map +1 -1
  27. package/dist/coordination/global-mailbox.d.ts +96 -21
  28. package/dist/coordination/global-mailbox.d.ts.map +1 -1
  29. package/dist/coordination/icoordinator.d.ts +1 -3
  30. package/dist/coordination/icoordinator.d.ts.map +1 -1
  31. package/dist/coordination/index.d.ts +2 -1
  32. package/dist/coordination/index.d.ts.map +1 -1
  33. package/dist/coordination/index.js +2176 -806
  34. package/dist/coordination/index.js.map +4 -4
  35. package/dist/coordination/knowledge-graph.d.ts +13 -1
  36. package/dist/coordination/knowledge-graph.d.ts.map +1 -1
  37. package/dist/coordination/mail-tools.d.ts.map +1 -1
  38. package/dist/coordination/mailbox-actions.d.ts +12 -13
  39. package/dist/coordination/mailbox-actions.d.ts.map +1 -1
  40. package/dist/coordination/mailbox-constants.d.ts +64 -0
  41. package/dist/coordination/mailbox-constants.d.ts.map +1 -0
  42. package/dist/coordination/mailbox-events.d.ts +32 -0
  43. package/dist/coordination/mailbox-events.d.ts.map +1 -0
  44. package/dist/coordination/mailbox-message-codec.d.ts +28 -0
  45. package/dist/coordination/mailbox-message-codec.d.ts.map +1 -0
  46. package/dist/coordination/mailbox-types.d.ts +130 -5
  47. package/dist/coordination/mailbox-types.d.ts.map +1 -1
  48. package/dist/coordination/mailbox.d.ts +21 -2
  49. package/dist/coordination/mailbox.d.ts.map +1 -1
  50. package/dist/coordination/package-author-tracker.d.ts.map +1 -1
  51. package/dist/coordination/subagent-result-tool.d.ts.map +1 -1
  52. package/dist/core/agent-loop.d.ts.map +1 -1
  53. package/dist/core/agent-response.d.ts +10 -1
  54. package/dist/core/agent-response.d.ts.map +1 -1
  55. package/dist/core/agent-tools.d.ts.map +1 -1
  56. package/dist/core/agent.d.ts +8 -0
  57. package/dist/core/agent.d.ts.map +1 -1
  58. package/dist/core/context.d.ts +25 -0
  59. package/dist/core/context.d.ts.map +1 -1
  60. package/dist/core/conversation-state.d.ts +6 -0
  61. package/dist/core/conversation-state.d.ts.map +1 -1
  62. package/dist/core/fallback-model.d.ts.map +1 -1
  63. package/dist/core/mailbox-loop.d.ts +12 -5
  64. package/dist/core/mailbox-loop.d.ts.map +1 -1
  65. package/dist/core/system-prompt-builder.d.ts +14 -6
  66. package/dist/core/system-prompt-builder.d.ts.map +1 -1
  67. package/dist/defaults/index.d.ts +0 -1
  68. package/dist/defaults/index.d.ts.map +1 -1
  69. package/dist/defaults/index.js +1690 -1998
  70. package/dist/defaults/index.js.map +4 -4
  71. package/dist/execution/auto-compaction-middleware.d.ts +8 -1
  72. package/dist/execution/auto-compaction-middleware.d.ts.map +1 -1
  73. package/dist/execution/autonomous-runner.d.ts +7 -1
  74. package/dist/execution/autonomous-runner.d.ts.map +1 -1
  75. package/dist/execution/autonomy-brain.d.ts +72 -11
  76. package/dist/execution/autonomy-brain.d.ts.map +1 -1
  77. package/dist/execution/brain-chain.d.ts +53 -0
  78. package/dist/execution/brain-chain.d.ts.map +1 -0
  79. package/dist/execution/brain-evaluation.d.ts +66 -0
  80. package/dist/execution/brain-evaluation.d.ts.map +1 -0
  81. package/dist/execution/brain-runtime.d.ts +171 -0
  82. package/dist/execution/brain-runtime.d.ts.map +1 -0
  83. package/dist/execution/compaction-core.d.ts.map +1 -1
  84. package/dist/execution/council-brain.d.ts +79 -0
  85. package/dist/execution/council-brain.d.ts.map +1 -0
  86. package/dist/execution/council-orchestrator.d.ts +32 -0
  87. package/dist/execution/council-orchestrator.d.ts.map +1 -0
  88. package/dist/execution/council-personas.d.ts +19 -0
  89. package/dist/execution/council-personas.d.ts.map +1 -0
  90. package/dist/execution/council-profiles.d.ts +34 -0
  91. package/dist/execution/council-profiles.d.ts.map +1 -0
  92. package/dist/execution/council-prompts.d.ts +21 -0
  93. package/dist/execution/council-prompts.d.ts.map +1 -0
  94. package/dist/execution/council-resolution.d.ts +57 -0
  95. package/dist/execution/council-resolution.d.ts.map +1 -0
  96. package/dist/execution/design-kit-loader.d.ts.map +1 -1
  97. package/dist/execution/enhance-recovery.d.ts +35 -0
  98. package/dist/execution/enhance-recovery.d.ts.map +1 -0
  99. package/dist/execution/error-handler.d.ts.map +1 -1
  100. package/dist/execution/eternal-autonomy.d.ts +12 -0
  101. package/dist/execution/eternal-autonomy.d.ts.map +1 -1
  102. package/dist/execution/index.d.ts +11 -1
  103. package/dist/execution/index.d.ts.map +1 -1
  104. package/dist/execution/index.js +3076 -526
  105. package/dist/execution/index.js.map +4 -4
  106. package/dist/execution/intelligent-compactor.d.ts +18 -7
  107. package/dist/execution/intelligent-compactor.d.ts.map +1 -1
  108. package/dist/execution/one-shot-llm.d.ts +52 -0
  109. package/dist/execution/one-shot-llm.d.ts.map +1 -0
  110. package/dist/execution/parallel-eternal-engine.d.ts +12 -0
  111. package/dist/execution/parallel-eternal-engine.d.ts.map +1 -1
  112. package/dist/execution/prompt-enhancer.d.ts +23 -4
  113. package/dist/execution/prompt-enhancer.d.ts.map +1 -1
  114. package/dist/execution/prompt-enhancer.js +24 -6
  115. package/dist/execution/prompt-enhancer.js.map +2 -2
  116. package/dist/execution/selective-compactor.d.ts +4 -4
  117. package/dist/execution/strategy-compactor.d.ts +7 -0
  118. package/dist/execution/strategy-compactor.d.ts.map +1 -1
  119. package/dist/execution/tool-executor.d.ts +19 -5
  120. package/dist/execution/tool-executor.d.ts.map +1 -1
  121. package/dist/hooks/registry.d.ts.map +1 -1
  122. package/dist/hooks/runner.d.ts.map +1 -1
  123. package/dist/hooks/shell-executor.d.ts.map +1 -1
  124. package/dist/hq/alerts.d.ts +5 -0
  125. package/dist/hq/alerts.d.ts.map +1 -1
  126. package/dist/hq/auth-store.d.ts +38 -10
  127. package/dist/hq/auth-store.d.ts.map +1 -1
  128. package/dist/hq/commands.d.ts +8 -4
  129. package/dist/hq/commands.d.ts.map +1 -1
  130. package/dist/hq/cost-bridge.d.ts +5 -3
  131. package/dist/hq/cost-bridge.d.ts.map +1 -1
  132. package/dist/hq/factory.d.ts +3 -0
  133. package/dist/hq/factory.d.ts.map +1 -1
  134. package/dist/hq/fleet-bridge.d.ts.map +1 -1
  135. package/dist/hq/index.d.ts +0 -1
  136. package/dist/hq/index.d.ts.map +1 -1
  137. package/dist/hq/index.js +1016 -283
  138. package/dist/hq/index.js.map +4 -4
  139. package/dist/hq/persistence.d.ts +42 -0
  140. package/dist/hq/persistence.d.ts.map +1 -1
  141. package/dist/hq/protocol/brain.d.ts +24 -0
  142. package/dist/hq/protocol/brain.d.ts.map +1 -0
  143. package/dist/hq/protocol/browser.d.ts +12 -0
  144. package/dist/hq/protocol/browser.d.ts.map +1 -0
  145. package/dist/hq/protocol/client.d.ts +69 -0
  146. package/dist/hq/protocol/client.d.ts.map +1 -0
  147. package/dist/hq/protocol/core.d.ts +130 -0
  148. package/dist/hq/protocol/core.d.ts.map +1 -0
  149. package/dist/hq/protocol/fleet.d.ts +73 -0
  150. package/dist/hq/protocol/fleet.d.ts.map +1 -0
  151. package/dist/hq/protocol/mailbox.d.ts +76 -0
  152. package/dist/hq/protocol/mailbox.d.ts.map +1 -0
  153. package/dist/hq/protocol/mcp.d.ts +51 -0
  154. package/dist/hq/protocol/mcp.d.ts.map +1 -0
  155. package/dist/hq/protocol/project.d.ts +26 -0
  156. package/dist/hq/protocol/project.d.ts.map +1 -0
  157. package/dist/hq/protocol/session.d.ts +153 -0
  158. package/dist/hq/protocol/session.d.ts.map +1 -0
  159. package/dist/hq/protocol/tool.d.ts +31 -0
  160. package/dist/hq/protocol/tool.d.ts.map +1 -0
  161. package/dist/hq/protocol.d.ts +10 -559
  162. package/dist/hq/protocol.d.ts.map +1 -1
  163. package/dist/hq/publisher.d.ts +4 -0
  164. package/dist/hq/publisher.d.ts.map +1 -1
  165. package/dist/index.d.ts +24 -8
  166. package/dist/index.d.ts.map +1 -1
  167. package/dist/index.js +7676 -3432
  168. package/dist/index.js.map +4 -4
  169. package/dist/infrastructure/index.js +13 -11
  170. package/dist/infrastructure/index.js.map +2 -2
  171. package/dist/infrastructure/token-counter.d.ts.map +1 -1
  172. package/dist/kernel/events/agent-events.d.ts +283 -0
  173. package/dist/kernel/events/agent-events.d.ts.map +1 -0
  174. package/dist/kernel/events/brain-events.d.ts +176 -0
  175. package/dist/kernel/events/brain-events.d.ts.map +1 -0
  176. package/dist/kernel/events/fleet-events.d.ts +39 -0
  177. package/dist/kernel/events/fleet-events.d.ts.map +1 -0
  178. package/dist/kernel/events/memory-events.d.ts +165 -0
  179. package/dist/kernel/events/memory-events.d.ts.map +1 -0
  180. package/dist/kernel/events/provider-events.d.ts +98 -0
  181. package/dist/kernel/events/provider-events.d.ts.map +1 -0
  182. package/dist/kernel/events/sdd-events.d.ts +118 -0
  183. package/dist/kernel/events/sdd-events.d.ts.map +1 -0
  184. package/dist/kernel/events/session-events.d.ts +227 -0
  185. package/dist/kernel/events/session-events.d.ts.map +1 -0
  186. package/dist/kernel/events/tool-events.d.ts +185 -0
  187. package/dist/kernel/events/tool-events.d.ts.map +1 -0
  188. package/dist/kernel/events/worktree-events.d.ts +58 -0
  189. package/dist/kernel/events/worktree-events.d.ts.map +1 -0
  190. package/dist/kernel/events.d.ts +12 -1282
  191. package/dist/kernel/events.d.ts.map +1 -1
  192. package/dist/kernel/index.js +22 -2
  193. package/dist/kernel/index.js.map +2 -2
  194. package/dist/kernel/run-controller.d.ts +15 -0
  195. package/dist/kernel/run-controller.d.ts.map +1 -1
  196. package/dist/mailbox-attach.d.ts.map +1 -1
  197. package/dist/models/index.js +19 -6
  198. package/dist/models/index.js.map +2 -2
  199. package/dist/models/llm-selector.d.ts +7 -0
  200. package/dist/models/llm-selector.d.ts.map +1 -1
  201. package/dist/observability/index.js +16 -15
  202. package/dist/observability/index.js.map +2 -2
  203. package/dist/plugins/auto-review-plugin.d.ts +36 -0
  204. package/dist/plugins/auto-review-plugin.d.ts.map +1 -0
  205. package/dist/plugins/chimera-plugin.d.ts +8 -0
  206. package/dist/plugins/chimera-plugin.d.ts.map +1 -1
  207. package/dist/security/index.d.ts +1 -0
  208. package/dist/security/index.d.ts.map +1 -1
  209. package/dist/security/index.js +260 -23
  210. package/dist/security/index.js.map +4 -4
  211. package/dist/security/permission-policy-schema.d.ts +77 -0
  212. package/dist/security/permission-policy-schema.d.ts.map +1 -0
  213. package/dist/security/permission-policy.d.ts +5 -0
  214. package/dist/security/permission-policy.d.ts.map +1 -1
  215. package/dist/security/secret-scrubber.d.ts.map +1 -1
  216. package/dist/security/secret-vault.d.ts +9 -0
  217. package/dist/security/secret-vault.d.ts.map +1 -1
  218. package/dist/session-registry.d.ts.map +1 -1
  219. package/dist/skills/index.js.map +2 -2
  220. package/dist/storage/config-loader.d.ts +10 -0
  221. package/dist/storage/config-loader.d.ts.map +1 -1
  222. package/dist/storage/goal-kanban.d.ts +69 -0
  223. package/dist/storage/goal-kanban.d.ts.map +1 -0
  224. package/dist/storage/goal-store.d.ts +1 -1
  225. package/dist/storage/goal-store.d.ts.map +1 -1
  226. package/dist/storage/index.d.ts +1 -1
  227. package/dist/storage/index.d.ts.map +1 -1
  228. package/dist/storage/index.js +572 -879
  229. package/dist/storage/index.js.map +4 -4
  230. package/dist/storage/memory-consolidator.d.ts +9 -1
  231. package/dist/storage/memory-consolidator.d.ts.map +1 -1
  232. package/dist/storage/plan-store.d.ts +1 -1
  233. package/dist/storage/plan-store.d.ts.map +1 -1
  234. package/dist/storage/queue-store.d.ts +4 -0
  235. package/dist/storage/queue-store.d.ts.map +1 -1
  236. package/dist/storage/session-store.d.ts +9 -0
  237. package/dist/storage/session-store.d.ts.map +1 -1
  238. package/dist/storage/task-store.d.ts +1 -1
  239. package/dist/storage/task-store.d.ts.map +1 -1
  240. package/dist/storage/todos-checkpoint.d.ts +2 -2
  241. package/dist/storage/todos-checkpoint.d.ts.map +1 -1
  242. package/dist/tools/council-tool.d.ts +25 -0
  243. package/dist/tools/council-tool.d.ts.map +1 -0
  244. package/dist/tools/index.d.ts +2 -0
  245. package/dist/tools/index.d.ts.map +1 -1
  246. package/dist/tools/index.js +1884 -12
  247. package/dist/tools/index.js.map +4 -4
  248. package/dist/tools/one-shot-llm-tool.d.ts +51 -0
  249. package/dist/tools/one-shot-llm-tool.d.ts.map +1 -0
  250. package/dist/types/config.d.ts +236 -4
  251. package/dist/types/config.d.ts.map +1 -1
  252. package/dist/types/context-window.d.ts.map +1 -1
  253. package/dist/types/council.d.ts +134 -0
  254. package/dist/types/council.d.ts.map +1 -0
  255. package/dist/types/default-config.d.ts +3 -3
  256. package/dist/types/hooks.d.ts +14 -0
  257. package/dist/types/hooks.d.ts.map +1 -1
  258. package/dist/types/index.d.ts +2 -0
  259. package/dist/types/index.d.ts.map +1 -1
  260. package/dist/types/index.js +40 -8
  261. package/dist/types/index.js.map +3 -3
  262. package/dist/types/multi-agent.d.ts +8 -0
  263. package/dist/types/multi-agent.d.ts.map +1 -1
  264. package/dist/types/observability.d.ts +5 -0
  265. package/dist/types/observability.d.ts.map +1 -1
  266. package/dist/types/one-shot-llm.d.ts +128 -0
  267. package/dist/types/one-shot-llm.d.ts.map +1 -0
  268. package/dist/types/plugin.d.ts +6 -0
  269. package/dist/types/plugin.d.ts.map +1 -1
  270. package/dist/types/provider.d.ts +17 -0
  271. package/dist/types/provider.d.ts.map +1 -1
  272. package/dist/types/system-prompt.d.ts +2 -1
  273. package/dist/types/system-prompt.d.ts.map +1 -1
  274. package/dist/types/tool-executor.d.ts +10 -0
  275. package/dist/types/tool-executor.d.ts.map +1 -1
  276. package/dist/types/tool.d.ts +7 -0
  277. package/dist/types/tool.d.ts.map +1 -1
  278. package/dist/utils/atomic-write.d.ts.map +1 -1
  279. package/dist/utils/glob-expand.d.ts.map +1 -1
  280. package/dist/utils/incoming-images.d.ts +39 -0
  281. package/dist/utils/incoming-images.d.ts.map +1 -0
  282. package/dist/utils/index.d.ts +1 -0
  283. package/dist/utils/index.d.ts.map +1 -1
  284. package/dist/utils/index.js +156 -11
  285. package/dist/utils/index.js.map +4 -4
  286. package/dist/utils/tool-wire-compact.d.ts +1 -0
  287. package/dist/utils/tool-wire-compact.d.ts.map +1 -1
  288. package/dist/utils/wstack-paths.d.ts +20 -4
  289. package/dist/utils/wstack-paths.d.ts.map +1 -1
  290. package/dist/worktree/worktree-manager.d.ts +13 -4
  291. package/dist/worktree/worktree-manager.d.ts.map +1 -1
  292. package/instructions/agents/browser.md +25 -16
  293. package/instructions/cli/next-task-predictor.md +5 -3
  294. package/instructions/coordination/subagent-baseline.md +17 -2
  295. package/instructions/leader-after-task.md +19 -8
  296. package/instructions/llm/council-judge.md +19 -0
  297. package/instructions/llm/council-voter.md +22 -0
  298. package/instructions/modes/architect.md +14 -9
  299. package/instructions/modes/audit-lite.md +9 -7
  300. package/instructions/modes/brief-system.md +12 -12
  301. package/instructions/modes/brief.md +7 -5
  302. package/instructions/modes/code-auditor.md +13 -8
  303. package/instructions/modes/code-reviewer.md +13 -8
  304. package/instructions/modes/debug-lite.md +7 -6
  305. package/instructions/modes/debugger.md +13 -9
  306. package/instructions/modes/devops.md +13 -9
  307. package/instructions/modes/plan-lite.md +7 -6
  308. package/instructions/modes/refactor-lite.md +7 -6
  309. package/instructions/modes/refactorer.md +14 -9
  310. package/instructions/modes/research-lite.md +8 -6
  311. package/instructions/modes/research-web.md +18 -55
  312. package/instructions/modes/review-lite.md +7 -6
  313. package/instructions/modes/teach-system.md +15 -15
  314. package/instructions/modes/teach.md +13 -12
  315. package/instructions/modes/test-lite.md +6 -5
  316. package/instructions/modes/tester.md +13 -9
  317. package/instructions/modes/ui-design.md +14 -8
  318. package/instructions/sections/tool/commit-hygiene.md +1 -7
  319. package/instructions/sections/tool/common-patterns.md +7 -1
  320. package/instructions/sections/tool/delegation-full.md +3 -31
  321. package/instructions/sections/tool/mailbox-compact.md +1 -1
  322. package/instructions/sections/tool/mailbox-full.md +6 -22
  323. package/instructions/system.md +294 -8
  324. package/package.json +2 -2
  325. package/skills/docker-deploy/SKILL.md +1 -1
  326. package/skills/mailbox-bridge/SKILL.md +16 -7
  327. package/skills/output-standards/SKILL.md +16 -16
  328. package/skills/wrongstack-mailbox/SKILL.md +57 -12
  329. package/dist/coordination/director-construction.d.ts +0 -90
  330. package/dist/coordination/director-construction.d.ts.map +0 -1
  331. package/dist/hq/agent-bridge.d.ts +0 -27
  332. package/dist/hq/agent-bridge.d.ts.map +0 -1
  333. package/dist/plugins/git-plugin.d.ts +0 -15
  334. package/dist/plugins/git-plugin.d.ts.map +0 -1
  335. package/dist/plugins/observability-plugin.d.ts +0 -19
  336. package/dist/plugins/observability-plugin.d.ts.map +0 -1
  337. package/dist/plugins/plan-plugin.d.ts +0 -16
  338. package/dist/plugins/plan-plugin.d.ts.map +0 -1
  339. package/dist/storage/memory-store.d.ts +0 -119
  340. package/dist/storage/memory-store.d.ts.map +0 -1
@@ -10,6 +10,7 @@ function assertNever(x, message) {
10
10
  // src/utils/atomic-write.ts
11
11
  import { randomBytes } from "node:crypto";
12
12
  import * as fs from "node:fs/promises";
13
+ import { watch as watchDir } from "node:fs";
13
14
  import * as path from "node:path";
14
15
 
15
16
  // src/types/errors.ts
@@ -181,7 +182,7 @@ async function withFileLock(targetPath, fn, opts = {}) {
181
182
  await fs.mkdir(dir, { recursive: true });
182
183
  continue;
183
184
  }
184
- if (code !== "EEXIST") throw err;
185
+ if (code !== "EEXIST" && code !== "EPERM") throw err;
185
186
  try {
186
187
  const stat3 = await fs.stat(lockPath);
187
188
  if (Date.now() - stat3.mtimeMs > staleMs) {
@@ -191,7 +192,8 @@ async function withFileLock(targetPath, fn, opts = {}) {
191
192
  } catch {
192
193
  continue;
193
194
  }
194
- if (Date.now() - started >= timeoutMs) {
195
+ const elapsed = Date.now() - started;
196
+ if (elapsed >= timeoutMs) {
195
197
  throw new FsError({
196
198
  message: `Timed out waiting for file lock: ${targetPath}`,
197
199
  code: "FS_ATOMIC_WRITE_FAILED",
@@ -199,7 +201,7 @@ async function withFileLock(targetPath, fn, opts = {}) {
199
201
  context: { timeoutMs }
200
202
  });
201
203
  }
202
- await new Promise((resolve5) => setTimeout(resolve5, 25));
204
+ await waitForLockRelease(lockPath, timeoutMs - elapsed);
203
205
  }
204
206
  }
205
207
  try {
@@ -215,6 +217,50 @@ async function withFileLock(targetPath, fn, opts = {}) {
215
217
  }
216
218
  }
217
219
  }
220
+ async function waitForLockRelease(lockPath, remainingMs) {
221
+ const parentDir = path.dirname(lockPath);
222
+ const lockName = path.basename(lockPath);
223
+ const intervalMs = Math.min(remainingMs, 100);
224
+ return new Promise((resolve5) => {
225
+ let settled = false;
226
+ let watcher = null;
227
+ const timer = setTimeout(() => {
228
+ settled = true;
229
+ watcher?.close();
230
+ resolve5();
231
+ }, intervalMs);
232
+ try {
233
+ watcher = watchDir(parentDir, (eventType, filename) => {
234
+ if (settled) return;
235
+ if (filename === lockName && (eventType === "rename" || eventType === "change")) {
236
+ settled = true;
237
+ clearTimeout(timer);
238
+ watcher?.close();
239
+ resolve5();
240
+ }
241
+ });
242
+ } catch {
243
+ clearTimeout(timer);
244
+ if (!settled) {
245
+ settled = true;
246
+ setTimeout(resolve5, Math.min(remainingMs, 25));
247
+ }
248
+ return;
249
+ }
250
+ fs.access(lockPath).then(
251
+ () => {
252
+ },
253
+ () => {
254
+ if (!settled) {
255
+ settled = true;
256
+ clearTimeout(timer);
257
+ watcher?.close();
258
+ resolve5();
259
+ }
260
+ }
261
+ );
262
+ });
263
+ }
218
264
  var TRANSIENT_RENAME_CODES = /* @__PURE__ */ new Set(["EPERM", "EBUSY", "EACCES", "ENOTEMPTY"]);
219
265
  async function renameWithRetry(from, to) {
220
266
  if (process.platform !== "win32") {
@@ -1237,9 +1283,17 @@ function globToRegex(pat) {
1237
1283
  return new RegExp(re + "$");
1238
1284
  }
1239
1285
  function baseDir(pat) {
1240
- let i = pat.length - 1;
1241
- while (i >= 0 && !GLOB_CHARS.has(expectDefined(pat[i])) && pat[i] !== SEP && pat[i] !== "/") i--;
1242
- const cut = i >= 0 ? pat.lastIndexOf(SEP, i) : pat.lastIndexOf("/", i);
1286
+ let firstGlob = pat.length;
1287
+ for (let i = 0; i < pat.length; i++) {
1288
+ if (GLOB_CHARS.has(expectDefined(pat[i]))) {
1289
+ firstGlob = i;
1290
+ break;
1291
+ }
1292
+ }
1293
+ const cut = Math.max(
1294
+ pat.lastIndexOf(SEP, firstGlob - 1),
1295
+ pat.lastIndexOf("/", firstGlob - 1)
1296
+ );
1243
1297
  return cut < 0 ? "." : pat.slice(0, cut);
1244
1298
  }
1245
1299
  async function expandGlob(pattern) {
@@ -1384,6 +1438,71 @@ function matchAny(patterns, input) {
1384
1438
  return patterns.some((p) => matchGlob(p, input));
1385
1439
  }
1386
1440
 
1441
+ // src/utils/incoming-images.ts
1442
+ var MAX_INCOMING_IMAGES = 8;
1443
+ var MAX_INCOMING_IMAGE_BYTES = 8 * 1024 * 1024;
1444
+ var ALLOWED_IMAGE_MEDIA_TYPES = /* @__PURE__ */ new Set([
1445
+ "image/png",
1446
+ "image/jpeg",
1447
+ "image/webp",
1448
+ "image/gif"
1449
+ ]);
1450
+ var IncomingImageError = class extends Error {
1451
+ constructor(message) {
1452
+ super(message);
1453
+ this.name = "IncomingImageError";
1454
+ }
1455
+ };
1456
+ var DATA_URL_RE = /^data:([a-z0-9.+-]+\/[a-z0-9.+-]+)?(?:;[a-z0-9-]+=[^;,]*)*(;base64)?,/i;
1457
+ function splitDataUrl(data) {
1458
+ const match = DATA_URL_RE.exec(data);
1459
+ if (!match) return { base64: data.trim() };
1460
+ return {
1461
+ base64: data.slice(match[0].length).trim(),
1462
+ mediaType: match[1]?.toLowerCase()
1463
+ };
1464
+ }
1465
+ function parseIncomingImages(images, legacyImageBase64) {
1466
+ const raw = [...images ?? []];
1467
+ if (legacyImageBase64) raw.push({ data: legacyImageBase64 });
1468
+ if (raw.length === 0) return [];
1469
+ if (raw.length > MAX_INCOMING_IMAGES) {
1470
+ throw new IncomingImageError(
1471
+ `Too many images: ${raw.length} (max ${MAX_INCOMING_IMAGES} per message).`
1472
+ );
1473
+ }
1474
+ return raw.map((img, i) => {
1475
+ const { base64, mediaType: fromUrl } = splitDataUrl(img.data ?? "");
1476
+ const mediaType = (img.mediaType ?? fromUrl ?? "image/png").toLowerCase();
1477
+ if (!ALLOWED_IMAGE_MEDIA_TYPES.has(mediaType)) {
1478
+ throw new IncomingImageError(
1479
+ `Image ${i + 1}: unsupported media type "${mediaType}" (allowed: ${[...ALLOWED_IMAGE_MEDIA_TYPES].join(", ")}).`
1480
+ );
1481
+ }
1482
+ if (!base64) {
1483
+ throw new IncomingImageError(`Image ${i + 1}: empty image data.`);
1484
+ }
1485
+ if (!/^[A-Za-z0-9+/]+={0,2}$/.test(base64)) {
1486
+ throw new IncomingImageError(`Image ${i + 1}: data is not valid base64.`);
1487
+ }
1488
+ const bytes = Math.floor(base64.length * 3 / 4);
1489
+ if (bytes > MAX_INCOMING_IMAGE_BYTES) {
1490
+ throw new IncomingImageError(
1491
+ `Image ${i + 1}: ${(bytes / (1024 * 1024)).toFixed(1)} MB exceeds the ${MAX_INCOMING_IMAGE_BYTES / (1024 * 1024)} MB limit.`
1492
+ );
1493
+ }
1494
+ return {
1495
+ type: "image",
1496
+ source: { type: "base64", media_type: mediaType, data: base64 }
1497
+ };
1498
+ });
1499
+ }
1500
+ function buildUserContentBlocks(text, images) {
1501
+ const blocks = [...images];
1502
+ if (text) blocks.push({ type: "text", text });
1503
+ return blocks;
1504
+ }
1505
+
1387
1506
  // src/utils/ip-guard.ts
1388
1507
  import * as dns from "node:dns/promises";
1389
1508
  import * as net from "node:net";
@@ -2343,8 +2462,8 @@ function subjectForToolInput(toolName, input, subjectKey) {
2343
2462
  }
2344
2463
 
2345
2464
  // src/utils/tool-wire-compact.ts
2346
- var TOOL_DESCRIPTION_MAX_CHARS = 640;
2347
- var SCHEMA_DESCRIPTION_MAX_CHARS = 180;
2465
+ var TOOL_DESCRIPTION_MAX_CHARS = 400;
2466
+ var SCHEMA_DESCRIPTION_MAX_CHARS = 120;
2348
2467
  var compactCache = /* @__PURE__ */ new WeakMap();
2349
2468
  function compactToolDefinitionForWire(tool, opts = {}) {
2350
2469
  const useDefaultOptions = opts.descriptionMaxChars === void 0 && opts.schemaDescriptionMaxChars === void 0;
@@ -3418,14 +3537,34 @@ function applyToolResultRenderModes(registry, modes) {
3418
3537
 
3419
3538
  // src/utils/wstack-paths.ts
3420
3539
  import { createHash } from "node:crypto";
3540
+ import * as fs3 from "node:fs";
3421
3541
  import * as os from "node:os";
3422
3542
  import * as path4 from "node:path";
3543
+ function canonicalProjectRoot(absRoot) {
3544
+ const checkoutRoot = path4.resolve(absRoot);
3545
+ const dotGit = path4.join(checkoutRoot, ".git");
3546
+ try {
3547
+ if (!fs3.statSync(dotGit).isFile()) return checkoutRoot;
3548
+ const gitDirLine = fs3.readFileSync(dotGit, "utf8").trim();
3549
+ const match = /^gitdir:\s*(.+)$/i.exec(gitDirLine);
3550
+ if (!match?.[1]) return checkoutRoot;
3551
+ const gitDir = path4.resolve(checkoutRoot, match[1].trim());
3552
+ const commonDirFile = path4.join(gitDir, "commondir");
3553
+ if (!fs3.statSync(commonDirFile).isFile()) return checkoutRoot;
3554
+ const commonDir = path4.resolve(gitDir, fs3.readFileSync(commonDirFile, "utf8").trim());
3555
+ if (path4.basename(commonDir).toLowerCase() !== ".git") return checkoutRoot;
3556
+ return path4.dirname(commonDir);
3557
+ } catch {
3558
+ return checkoutRoot;
3559
+ }
3560
+ }
3423
3561
  function projectHash(absRoot) {
3424
- return createHash("sha256").update(path4.resolve(absRoot)).digest("hex").slice(0, 12);
3562
+ return createHash("sha256").update(canonicalProjectRoot(absRoot)).digest("hex").slice(0, 12);
3425
3563
  }
3426
3564
  function projectSlug(absRoot) {
3427
- const base = slugify2(path4.basename(absRoot));
3428
- const hash = createHash("sha256").update(path4.resolve(absRoot)).digest("hex").slice(0, 6);
3565
+ const identityRoot = canonicalProjectRoot(absRoot);
3566
+ const base = slugify2(path4.basename(identityRoot));
3567
+ const hash = createHash("sha256").update(identityRoot).digest("hex").slice(0, 6);
3429
3568
  return `${base}-${hash}`;
3430
3569
  }
3431
3570
  function slugify2(name) {
@@ -3495,6 +3634,9 @@ export {
3495
3634
  DEFAULT_TOOL_DESCRIPTION_MODE,
3496
3635
  DEFAULT_TOOL_RESULT_RENDER_MODE,
3497
3636
  FORBIDDEN_PROTO_KEYS,
3637
+ IncomingImageError,
3638
+ MAX_INCOMING_IMAGES,
3639
+ MAX_INCOMING_IMAGE_BYTES,
3498
3640
  applyToolDescriptionModeToTool,
3499
3641
  applyToolDescriptionModes,
3500
3642
  applyToolResultRenderModes,
@@ -3504,6 +3646,8 @@ export {
3504
3646
  buildChildEnv,
3505
3647
  buildCompletedWorkLedgerBlock,
3506
3648
  buildContextEvidenceDigest,
3649
+ buildUserContentBlocks,
3650
+ canonicalProjectRoot,
3507
3651
  coerceAgainstSchema,
3508
3652
  color,
3509
3653
  compactSchemaDescriptions,
@@ -3561,6 +3705,7 @@ export {
3561
3705
  normalizeToolDescriptionMode,
3562
3706
  normalizeToolResultRenderMode,
3563
3707
  onResize,
3708
+ parseIncomingImages,
3564
3709
  projectHash,
3565
3710
  projectSlug,
3566
3711
  readJsonObjectFile,