attocode 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (577) hide show
  1. package/CHANGELOG.md +56 -1
  2. package/dist/src/adapters.d.ts +2 -1
  3. package/dist/src/adapters.d.ts.map +1 -1
  4. package/dist/src/adapters.js +60 -2
  5. package/dist/src/adapters.js.map +1 -1
  6. package/dist/src/agent/agent-builder.d.ts +117 -0
  7. package/dist/src/agent/agent-builder.d.ts.map +1 -0
  8. package/dist/src/agent/agent-builder.js +204 -0
  9. package/dist/src/agent/agent-builder.js.map +1 -0
  10. package/dist/src/agent/feature-initializer.d.ts +80 -0
  11. package/dist/src/agent/feature-initializer.d.ts.map +1 -0
  12. package/dist/src/agent/feature-initializer.js +677 -0
  13. package/dist/src/agent/feature-initializer.js.map +1 -0
  14. package/dist/src/agent/index.d.ts +13 -0
  15. package/dist/src/agent/index.d.ts.map +1 -0
  16. package/dist/src/agent/index.js +13 -0
  17. package/dist/src/agent/index.js.map +1 -0
  18. package/dist/src/agent/message-builder.d.ts +50 -0
  19. package/dist/src/agent/message-builder.d.ts.map +1 -0
  20. package/dist/src/agent/message-builder.js +173 -0
  21. package/dist/src/agent/message-builder.js.map +1 -0
  22. package/dist/src/agent/session-api.d.ts +94 -0
  23. package/dist/src/agent/session-api.d.ts.map +1 -0
  24. package/dist/src/agent/session-api.js +262 -0
  25. package/dist/src/agent/session-api.js.map +1 -0
  26. package/dist/src/agent-tools/lsp-file-tools.d.ts +1 -1
  27. package/dist/src/agent-tools/lsp-file-tools.d.ts.map +1 -1
  28. package/dist/src/agent.d.ts +14 -115
  29. package/dist/src/agent.d.ts.map +1 -1
  30. package/dist/src/agent.js +36 -1177
  31. package/dist/src/agent.js.map +1 -1
  32. package/dist/src/cli.js +1 -1
  33. package/dist/src/cli.js.map +1 -1
  34. package/dist/src/commands/handler.d.ts.map +1 -1
  35. package/dist/src/commands/handler.js +8 -7
  36. package/dist/src/commands/handler.js.map +1 -1
  37. package/dist/src/commands/init.js +1 -1
  38. package/dist/src/commands/init.js.map +1 -1
  39. package/dist/src/config/schema.d.ts +6 -6
  40. package/dist/src/core/execution-loop.d.ts.map +1 -1
  41. package/dist/src/core/execution-loop.js +155 -16
  42. package/dist/src/core/execution-loop.js.map +1 -1
  43. package/dist/src/core/response-handler.d.ts.map +1 -1
  44. package/dist/src/core/response-handler.js +3 -2
  45. package/dist/src/core/response-handler.js.map +1 -1
  46. package/dist/src/core/subagent-spawner.d.ts.map +1 -1
  47. package/dist/src/core/subagent-spawner.js +13 -6
  48. package/dist/src/core/subagent-spawner.js.map +1 -1
  49. package/dist/src/core/tool-executor.d.ts.map +1 -1
  50. package/dist/src/core/tool-executor.js +7 -2
  51. package/dist/src/core/tool-executor.js.map +1 -1
  52. package/dist/src/core/types.d.ts +1 -0
  53. package/dist/src/core/types.d.ts.map +1 -1
  54. package/dist/src/core/types.js.map +1 -1
  55. package/dist/src/integrations/agents/agent-registry.d.ts +262 -0
  56. package/dist/src/integrations/agents/agent-registry.d.ts.map +1 -0
  57. package/dist/src/integrations/agents/agent-registry.js +686 -0
  58. package/dist/src/integrations/agents/agent-registry.js.map +1 -0
  59. package/dist/src/integrations/agents/async-subagent.d.ts +135 -0
  60. package/dist/src/integrations/agents/async-subagent.d.ts.map +1 -0
  61. package/dist/src/integrations/agents/async-subagent.js +213 -0
  62. package/dist/src/integrations/agents/async-subagent.js.map +1 -0
  63. package/dist/src/integrations/agents/complexity-classifier.d.ts +86 -0
  64. package/dist/src/integrations/agents/complexity-classifier.d.ts.map +1 -0
  65. package/dist/src/integrations/agents/complexity-classifier.js +233 -0
  66. package/dist/src/integrations/agents/complexity-classifier.js.map +1 -0
  67. package/dist/src/integrations/agents/delegation-protocol.d.ts +86 -0
  68. package/dist/src/integrations/agents/delegation-protocol.d.ts.map +1 -0
  69. package/dist/src/integrations/agents/delegation-protocol.js +127 -0
  70. package/dist/src/integrations/agents/delegation-protocol.js.map +1 -0
  71. package/dist/src/integrations/agents/multi-agent.d.ts +150 -0
  72. package/dist/src/integrations/agents/multi-agent.d.ts.map +1 -0
  73. package/dist/src/integrations/agents/multi-agent.js +306 -0
  74. package/dist/src/integrations/agents/multi-agent.js.map +1 -0
  75. package/dist/src/integrations/agents/result-synthesizer.d.ts +389 -0
  76. package/dist/src/integrations/agents/result-synthesizer.d.ts.map +1 -0
  77. package/dist/src/integrations/agents/result-synthesizer.js +951 -0
  78. package/dist/src/integrations/agents/result-synthesizer.js.map +1 -0
  79. package/dist/src/integrations/agents/shared-blackboard.d.ts +406 -0
  80. package/dist/src/integrations/agents/shared-blackboard.d.ts.map +1 -0
  81. package/dist/src/integrations/agents/shared-blackboard.js +757 -0
  82. package/dist/src/integrations/agents/shared-blackboard.js.map +1 -0
  83. package/dist/src/integrations/agents/subagent-output-store.d.ts +91 -0
  84. package/dist/src/integrations/agents/subagent-output-store.d.ts.map +1 -0
  85. package/dist/src/integrations/agents/subagent-output-store.js +257 -0
  86. package/dist/src/integrations/agents/subagent-output-store.js.map +1 -0
  87. package/dist/src/integrations/budget/budget-pool.d.ts +115 -0
  88. package/dist/src/integrations/budget/budget-pool.d.ts.map +1 -0
  89. package/dist/src/integrations/budget/budget-pool.js +205 -0
  90. package/dist/src/integrations/budget/budget-pool.js.map +1 -0
  91. package/dist/src/integrations/budget/cancellation.d.ts +229 -0
  92. package/dist/src/integrations/budget/cancellation.d.ts.map +1 -0
  93. package/dist/src/integrations/budget/cancellation.js +520 -0
  94. package/dist/src/integrations/budget/cancellation.js.map +1 -0
  95. package/dist/src/integrations/budget/dynamic-budget.d.ts +81 -0
  96. package/dist/src/integrations/budget/dynamic-budget.d.ts.map +1 -0
  97. package/dist/src/integrations/budget/dynamic-budget.js +151 -0
  98. package/dist/src/integrations/budget/dynamic-budget.js.map +1 -0
  99. package/dist/src/integrations/budget/economics.d.ts +435 -0
  100. package/dist/src/integrations/budget/economics.d.ts.map +1 -0
  101. package/dist/src/integrations/budget/economics.js +1007 -0
  102. package/dist/src/integrations/budget/economics.js.map +1 -0
  103. package/dist/src/integrations/budget/injection-budget.d.ts +71 -0
  104. package/dist/src/integrations/budget/injection-budget.d.ts.map +1 -0
  105. package/dist/src/integrations/budget/injection-budget.js +137 -0
  106. package/dist/src/integrations/budget/injection-budget.js.map +1 -0
  107. package/dist/src/integrations/budget/loop-detector.d.ts +105 -0
  108. package/dist/src/integrations/budget/loop-detector.d.ts.map +1 -0
  109. package/dist/src/integrations/budget/loop-detector.js +287 -0
  110. package/dist/src/integrations/budget/loop-detector.js.map +1 -0
  111. package/dist/src/integrations/budget/phase-tracker.d.ts +114 -0
  112. package/dist/src/integrations/budget/phase-tracker.d.ts.map +1 -0
  113. package/dist/src/integrations/budget/phase-tracker.js +262 -0
  114. package/dist/src/integrations/budget/phase-tracker.js.map +1 -0
  115. package/dist/src/integrations/budget/resources.d.ts +182 -0
  116. package/dist/src/integrations/budget/resources.d.ts.map +1 -0
  117. package/dist/src/integrations/budget/resources.js +318 -0
  118. package/dist/src/integrations/budget/resources.js.map +1 -0
  119. package/dist/src/integrations/context/auto-compaction.d.ts +210 -0
  120. package/dist/src/integrations/context/auto-compaction.d.ts.map +1 -0
  121. package/dist/src/integrations/context/auto-compaction.js +477 -0
  122. package/dist/src/integrations/context/auto-compaction.js.map +1 -0
  123. package/dist/src/integrations/context/code-analyzer.d.ts +71 -0
  124. package/dist/src/integrations/context/code-analyzer.d.ts.map +1 -0
  125. package/dist/src/integrations/context/code-analyzer.js +448 -0
  126. package/dist/src/integrations/context/code-analyzer.js.map +1 -0
  127. package/dist/src/integrations/context/code-selector.d.ts +78 -0
  128. package/dist/src/integrations/context/code-selector.d.ts.map +1 -0
  129. package/dist/src/integrations/context/code-selector.js +649 -0
  130. package/dist/src/integrations/context/code-selector.js.map +1 -0
  131. package/dist/src/integrations/context/codebase-ast.d.ts +138 -0
  132. package/dist/src/integrations/context/codebase-ast.d.ts.map +1 -0
  133. package/dist/src/integrations/context/codebase-ast.js +818 -0
  134. package/dist/src/integrations/context/codebase-ast.js.map +1 -0
  135. package/dist/src/integrations/context/codebase-context.d.ts +473 -0
  136. package/dist/src/integrations/context/codebase-context.d.ts.map +1 -0
  137. package/dist/src/integrations/context/codebase-context.js +685 -0
  138. package/dist/src/integrations/context/codebase-context.js.map +1 -0
  139. package/dist/src/integrations/context/compaction.d.ts +191 -0
  140. package/dist/src/integrations/context/compaction.d.ts.map +1 -0
  141. package/dist/src/integrations/context/compaction.js +384 -0
  142. package/dist/src/integrations/context/compaction.js.map +1 -0
  143. package/dist/src/integrations/context/context-engineering.d.ts +274 -0
  144. package/dist/src/integrations/context/context-engineering.d.ts.map +1 -0
  145. package/dist/src/integrations/context/context-engineering.js +437 -0
  146. package/dist/src/integrations/context/context-engineering.js.map +1 -0
  147. package/dist/src/integrations/context/file-cache.d.ts +97 -0
  148. package/dist/src/integrations/context/file-cache.d.ts.map +1 -0
  149. package/dist/src/integrations/context/file-cache.js +218 -0
  150. package/dist/src/integrations/context/file-cache.js.map +1 -0
  151. package/dist/src/integrations/context/semantic-cache.d.ts +178 -0
  152. package/dist/src/integrations/context/semantic-cache.d.ts.map +1 -0
  153. package/dist/src/integrations/context/semantic-cache.js +372 -0
  154. package/dist/src/integrations/context/semantic-cache.js.map +1 -0
  155. package/dist/src/integrations/index.d.ts +72 -68
  156. package/dist/src/integrations/index.d.ts.map +1 -1
  157. package/dist/src/integrations/index.js +76 -68
  158. package/dist/src/integrations/index.js.map +1 -1
  159. package/dist/src/integrations/lsp/lsp.d.ts +196 -0
  160. package/dist/src/integrations/lsp/lsp.d.ts.map +1 -0
  161. package/dist/src/integrations/lsp/lsp.js +583 -0
  162. package/dist/src/integrations/lsp/lsp.js.map +1 -0
  163. package/dist/src/integrations/mcp/mcp-client.d.ts +279 -0
  164. package/dist/src/integrations/mcp/mcp-client.d.ts.map +1 -0
  165. package/dist/src/integrations/mcp/mcp-client.js +755 -0
  166. package/dist/src/integrations/mcp/mcp-client.js.map +1 -0
  167. package/dist/src/integrations/mcp/mcp-custom-tools.d.ts +102 -0
  168. package/dist/src/integrations/mcp/mcp-custom-tools.d.ts.map +1 -0
  169. package/dist/src/integrations/mcp/mcp-custom-tools.js +232 -0
  170. package/dist/src/integrations/mcp/mcp-custom-tools.js.map +1 -0
  171. package/dist/src/integrations/mcp/mcp-tool-search.d.ts +77 -0
  172. package/dist/src/integrations/mcp/mcp-tool-search.d.ts.map +1 -0
  173. package/dist/src/integrations/mcp/mcp-tool-search.js +220 -0
  174. package/dist/src/integrations/mcp/mcp-tool-search.js.map +1 -0
  175. package/dist/src/integrations/mcp/mcp-tool-validator.d.ts +60 -0
  176. package/dist/src/integrations/mcp/mcp-tool-validator.d.ts.map +1 -0
  177. package/dist/src/integrations/mcp/mcp-tool-validator.js +141 -0
  178. package/dist/src/integrations/mcp/mcp-tool-validator.js.map +1 -0
  179. package/dist/src/integrations/persistence/codebase-repository.d.ts +45 -0
  180. package/dist/src/integrations/persistence/codebase-repository.d.ts.map +1 -0
  181. package/dist/src/integrations/persistence/codebase-repository.js +81 -0
  182. package/dist/src/integrations/persistence/codebase-repository.js.map +1 -0
  183. package/dist/src/integrations/persistence/goal-repository.d.ts +71 -0
  184. package/dist/src/integrations/persistence/goal-repository.d.ts.map +1 -0
  185. package/dist/src/integrations/persistence/goal-repository.js +184 -0
  186. package/dist/src/integrations/persistence/goal-repository.js.map +1 -0
  187. package/dist/src/integrations/persistence/history.d.ts +72 -0
  188. package/dist/src/integrations/persistence/history.d.ts.map +1 -0
  189. package/dist/src/integrations/persistence/history.js +165 -0
  190. package/dist/src/integrations/persistence/history.js.map +1 -0
  191. package/dist/src/integrations/persistence/persistence.d.ts +49 -0
  192. package/dist/src/integrations/persistence/persistence.d.ts.map +1 -0
  193. package/dist/src/integrations/persistence/persistence.js +197 -0
  194. package/dist/src/integrations/persistence/persistence.js.map +1 -0
  195. package/dist/src/integrations/persistence/session-repository.d.ts +212 -0
  196. package/dist/src/integrations/persistence/session-repository.d.ts.map +1 -0
  197. package/dist/src/integrations/persistence/session-repository.js +770 -0
  198. package/dist/src/integrations/persistence/session-repository.js.map +1 -0
  199. package/dist/src/integrations/persistence/session-store.d.ts +184 -0
  200. package/dist/src/integrations/persistence/session-store.d.ts.map +1 -0
  201. package/dist/src/integrations/persistence/session-store.js +346 -0
  202. package/dist/src/integrations/persistence/session-store.js.map +1 -0
  203. package/dist/src/integrations/persistence/sqlite-store.d.ts +453 -0
  204. package/dist/src/integrations/persistence/sqlite-store.d.ts.map +1 -0
  205. package/dist/src/integrations/persistence/sqlite-store.js +676 -0
  206. package/dist/src/integrations/persistence/sqlite-store.js.map +1 -0
  207. package/dist/src/integrations/persistence/worker-repository.d.ts +65 -0
  208. package/dist/src/integrations/persistence/worker-repository.d.ts.map +1 -0
  209. package/dist/src/integrations/persistence/worker-repository.js +183 -0
  210. package/dist/src/integrations/persistence/worker-repository.js.map +1 -0
  211. package/dist/src/integrations/quality/auto-checkpoint.d.ts +98 -0
  212. package/dist/src/integrations/quality/auto-checkpoint.d.ts.map +1 -0
  213. package/dist/src/integrations/quality/auto-checkpoint.js +252 -0
  214. package/dist/src/integrations/quality/auto-checkpoint.js.map +1 -0
  215. package/dist/src/integrations/quality/dead-letter-queue.d.ts +233 -0
  216. package/dist/src/integrations/quality/dead-letter-queue.d.ts.map +1 -0
  217. package/dist/src/integrations/quality/dead-letter-queue.js +543 -0
  218. package/dist/src/integrations/quality/dead-letter-queue.js.map +1 -0
  219. package/dist/src/integrations/quality/health-check.d.ts +218 -0
  220. package/dist/src/integrations/quality/health-check.d.ts.map +1 -0
  221. package/dist/src/integrations/quality/health-check.js +415 -0
  222. package/dist/src/integrations/quality/health-check.js.map +1 -0
  223. package/dist/src/integrations/quality/learning-store.d.ts +291 -0
  224. package/dist/src/integrations/quality/learning-store.d.ts.map +1 -0
  225. package/dist/src/integrations/quality/learning-store.js +646 -0
  226. package/dist/src/integrations/quality/learning-store.js.map +1 -0
  227. package/dist/src/integrations/quality/self-improvement.d.ts +90 -0
  228. package/dist/src/integrations/quality/self-improvement.d.ts.map +1 -0
  229. package/dist/src/integrations/quality/self-improvement.js +229 -0
  230. package/dist/src/integrations/quality/self-improvement.js.map +1 -0
  231. package/dist/src/integrations/quality/tool-recommendation.d.ts +61 -0
  232. package/dist/src/integrations/quality/tool-recommendation.d.ts.map +1 -0
  233. package/dist/src/integrations/quality/tool-recommendation.js +268 -0
  234. package/dist/src/integrations/quality/tool-recommendation.js.map +1 -0
  235. package/dist/src/integrations/safety/bash-policy.d.ts +33 -0
  236. package/dist/src/integrations/safety/bash-policy.d.ts.map +1 -0
  237. package/dist/src/integrations/safety/bash-policy.js +144 -0
  238. package/dist/src/integrations/safety/bash-policy.js.map +1 -0
  239. package/dist/src/integrations/safety/edit-validator.d.ts +30 -0
  240. package/dist/src/integrations/safety/edit-validator.d.ts.map +1 -0
  241. package/dist/src/integrations/safety/edit-validator.js +87 -0
  242. package/dist/src/integrations/safety/edit-validator.js.map +1 -0
  243. package/dist/src/integrations/safety/execution-policy.d.ts +189 -0
  244. package/dist/src/integrations/safety/execution-policy.d.ts.map +1 -0
  245. package/dist/src/integrations/safety/execution-policy.js +352 -0
  246. package/dist/src/integrations/safety/execution-policy.js.map +1 -0
  247. package/dist/src/integrations/safety/policy-engine.d.ts +55 -0
  248. package/dist/src/integrations/safety/policy-engine.d.ts.map +1 -0
  249. package/dist/src/integrations/safety/policy-engine.js +247 -0
  250. package/dist/src/integrations/safety/policy-engine.js.map +1 -0
  251. package/dist/src/integrations/safety/safety.d.ts +174 -0
  252. package/dist/src/integrations/safety/safety.d.ts.map +1 -0
  253. package/dist/src/integrations/safety/safety.js +470 -0
  254. package/dist/src/integrations/safety/safety.js.map +1 -0
  255. package/dist/src/integrations/safety/sandbox/basic.d.ts +81 -0
  256. package/dist/src/integrations/safety/sandbox/basic.d.ts.map +1 -0
  257. package/dist/src/integrations/safety/sandbox/basic.js +335 -0
  258. package/dist/src/integrations/safety/sandbox/basic.js.map +1 -0
  259. package/dist/src/integrations/safety/sandbox/docker.d.ts +94 -0
  260. package/dist/src/integrations/safety/sandbox/docker.d.ts.map +1 -0
  261. package/dist/src/integrations/safety/sandbox/docker.js +294 -0
  262. package/dist/src/integrations/safety/sandbox/docker.js.map +1 -0
  263. package/dist/src/integrations/safety/sandbox/index.d.ts +188 -0
  264. package/dist/src/integrations/safety/sandbox/index.d.ts.map +1 -0
  265. package/dist/src/integrations/safety/sandbox/index.js +386 -0
  266. package/dist/src/integrations/safety/sandbox/index.js.map +1 -0
  267. package/dist/src/integrations/safety/sandbox/landlock.d.ts +59 -0
  268. package/dist/src/integrations/safety/sandbox/landlock.d.ts.map +1 -0
  269. package/dist/src/integrations/safety/sandbox/landlock.js +329 -0
  270. package/dist/src/integrations/safety/sandbox/landlock.js.map +1 -0
  271. package/dist/src/integrations/safety/sandbox/seatbelt.d.ts +68 -0
  272. package/dist/src/integrations/safety/sandbox/seatbelt.d.ts.map +1 -0
  273. package/dist/src/integrations/safety/sandbox/seatbelt.js +298 -0
  274. package/dist/src/integrations/safety/sandbox/seatbelt.js.map +1 -0
  275. package/dist/src/integrations/safety/type-checker.d.ts +53 -0
  276. package/dist/src/integrations/safety/type-checker.d.ts.map +1 -0
  277. package/dist/src/integrations/safety/type-checker.js +142 -0
  278. package/dist/src/integrations/safety/type-checker.js.map +1 -0
  279. package/dist/src/integrations/skills/skill-executor.d.ts +113 -0
  280. package/dist/src/integrations/skills/skill-executor.d.ts.map +1 -0
  281. package/dist/src/integrations/skills/skill-executor.js +270 -0
  282. package/dist/src/integrations/skills/skill-executor.js.map +1 -0
  283. package/dist/src/integrations/skills/skills.d.ts +262 -0
  284. package/dist/src/integrations/skills/skills.d.ts.map +1 -0
  285. package/dist/src/integrations/skills/skills.js +602 -0
  286. package/dist/src/integrations/skills/skills.js.map +1 -0
  287. package/dist/src/integrations/streaming/pty-shell.d.ts +169 -0
  288. package/dist/src/integrations/streaming/pty-shell.d.ts.map +1 -0
  289. package/dist/src/integrations/streaming/pty-shell.js +367 -0
  290. package/dist/src/integrations/streaming/pty-shell.js.map +1 -0
  291. package/dist/src/integrations/streaming/streaming.d.ts +102 -0
  292. package/dist/src/integrations/streaming/streaming.d.ts.map +1 -0
  293. package/dist/src/integrations/streaming/streaming.js +362 -0
  294. package/dist/src/integrations/streaming/streaming.js.map +1 -0
  295. package/dist/src/integrations/swarm/index.d.ts +2 -1
  296. package/dist/src/integrations/swarm/index.d.ts.map +1 -1
  297. package/dist/src/integrations/swarm/index.js +2 -0
  298. package/dist/src/integrations/swarm/index.js.map +1 -1
  299. package/dist/src/integrations/swarm/model-selector.js +1 -1
  300. package/dist/src/integrations/swarm/model-selector.js.map +1 -1
  301. package/dist/src/integrations/swarm/swarm-budget.d.ts +1 -1
  302. package/dist/src/integrations/swarm/swarm-budget.d.ts.map +1 -1
  303. package/dist/src/integrations/swarm/swarm-budget.js +1 -1
  304. package/dist/src/integrations/swarm/swarm-budget.js.map +1 -1
  305. package/dist/src/integrations/swarm/swarm-config-loader.d.ts.map +1 -1
  306. package/dist/src/integrations/swarm/swarm-config-loader.js +7 -0
  307. package/dist/src/integrations/swarm/swarm-config-loader.js.map +1 -1
  308. package/dist/src/integrations/swarm/swarm-events.d.ts +1 -1
  309. package/dist/src/integrations/swarm/swarm-events.d.ts.map +1 -1
  310. package/dist/src/integrations/swarm/swarm-execution.d.ts +27 -0
  311. package/dist/src/integrations/swarm/swarm-execution.d.ts.map +1 -0
  312. package/dist/src/integrations/swarm/swarm-execution.js +1021 -0
  313. package/dist/src/integrations/swarm/swarm-execution.js.map +1 -0
  314. package/dist/src/integrations/swarm/swarm-helpers.d.ts +26 -0
  315. package/dist/src/integrations/swarm/swarm-helpers.d.ts.map +1 -0
  316. package/dist/src/integrations/swarm/swarm-helpers.js +95 -0
  317. package/dist/src/integrations/swarm/swarm-helpers.js.map +1 -0
  318. package/dist/src/integrations/swarm/swarm-lifecycle.d.ts +100 -0
  319. package/dist/src/integrations/swarm/swarm-lifecycle.d.ts.map +1 -0
  320. package/dist/src/integrations/swarm/swarm-lifecycle.js +922 -0
  321. package/dist/src/integrations/swarm/swarm-lifecycle.js.map +1 -0
  322. package/dist/src/integrations/swarm/swarm-orchestrator.d.ts +84 -203
  323. package/dist/src/integrations/swarm/swarm-orchestrator.d.ts.map +1 -1
  324. package/dist/src/integrations/swarm/swarm-orchestrator.js +251 -2870
  325. package/dist/src/integrations/swarm/swarm-orchestrator.js.map +1 -1
  326. package/dist/src/integrations/swarm/swarm-quality-gate.js +1 -1
  327. package/dist/src/integrations/swarm/swarm-quality-gate.js.map +1 -1
  328. package/dist/src/integrations/swarm/swarm-recovery.d.ts +75 -0
  329. package/dist/src/integrations/swarm/swarm-recovery.d.ts.map +1 -0
  330. package/dist/src/integrations/swarm/swarm-recovery.js +550 -0
  331. package/dist/src/integrations/swarm/swarm-recovery.js.map +1 -0
  332. package/dist/src/integrations/swarm/swarm-state-store.d.ts.map +1 -1
  333. package/dist/src/integrations/swarm/swarm-state-store.js +6 -0
  334. package/dist/src/integrations/swarm/swarm-state-store.js.map +1 -1
  335. package/dist/src/integrations/swarm/task-queue.d.ts +1 -1
  336. package/dist/src/integrations/swarm/task-queue.d.ts.map +1 -1
  337. package/dist/src/integrations/swarm/task-queue.js +28 -1
  338. package/dist/src/integrations/swarm/task-queue.js.map +1 -1
  339. package/dist/src/integrations/swarm/types.d.ts +17 -5
  340. package/dist/src/integrations/swarm/types.d.ts.map +1 -1
  341. package/dist/src/integrations/swarm/types.js.map +1 -1
  342. package/dist/src/integrations/swarm/worker-pool.d.ts +1 -1
  343. package/dist/src/integrations/swarm/worker-pool.d.ts.map +1 -1
  344. package/dist/src/integrations/swarm/worker-pool.js +13 -9
  345. package/dist/src/integrations/swarm/worker-pool.js.map +1 -1
  346. package/dist/src/integrations/tasks/dependency-analyzer.d.ts +34 -0
  347. package/dist/src/integrations/tasks/dependency-analyzer.d.ts.map +1 -0
  348. package/dist/src/integrations/tasks/dependency-analyzer.js +232 -0
  349. package/dist/src/integrations/tasks/dependency-analyzer.js.map +1 -0
  350. package/dist/src/integrations/tasks/interactive-planning.d.ts +322 -0
  351. package/dist/src/integrations/tasks/interactive-planning.d.ts.map +1 -0
  352. package/dist/src/integrations/tasks/interactive-planning.js +655 -0
  353. package/dist/src/integrations/tasks/interactive-planning.js.map +1 -0
  354. package/dist/src/integrations/tasks/pending-plan.d.ts +196 -0
  355. package/dist/src/integrations/tasks/pending-plan.d.ts.map +1 -0
  356. package/dist/src/integrations/tasks/pending-plan.js +431 -0
  357. package/dist/src/integrations/tasks/pending-plan.js.map +1 -0
  358. package/dist/src/integrations/tasks/planning.d.ts +115 -0
  359. package/dist/src/integrations/tasks/planning.d.ts.map +1 -0
  360. package/dist/src/integrations/tasks/planning.js +413 -0
  361. package/dist/src/integrations/tasks/planning.js.map +1 -0
  362. package/dist/src/integrations/tasks/smart-decomposer.d.ts +316 -0
  363. package/dist/src/integrations/tasks/smart-decomposer.d.ts.map +1 -0
  364. package/dist/src/integrations/tasks/smart-decomposer.js +661 -0
  365. package/dist/src/integrations/tasks/smart-decomposer.js.map +1 -0
  366. package/dist/src/integrations/tasks/task-manager.d.ts +164 -0
  367. package/dist/src/integrations/tasks/task-manager.d.ts.map +1 -0
  368. package/dist/src/integrations/tasks/task-manager.js +383 -0
  369. package/dist/src/integrations/tasks/task-manager.js.map +1 -0
  370. package/dist/src/integrations/tasks/task-splitter.d.ts +56 -0
  371. package/dist/src/integrations/tasks/task-splitter.d.ts.map +1 -0
  372. package/dist/src/integrations/tasks/task-splitter.js +537 -0
  373. package/dist/src/integrations/tasks/task-splitter.js.map +1 -0
  374. package/dist/src/integrations/tasks/verification-gate.d.ts +103 -0
  375. package/dist/src/integrations/tasks/verification-gate.d.ts.map +1 -0
  376. package/dist/src/integrations/tasks/verification-gate.js +193 -0
  377. package/dist/src/integrations/tasks/verification-gate.js.map +1 -0
  378. package/dist/src/integrations/tasks/work-log.d.ts +87 -0
  379. package/dist/src/integrations/tasks/work-log.d.ts.map +1 -0
  380. package/dist/src/integrations/tasks/work-log.js +275 -0
  381. package/dist/src/integrations/tasks/work-log.js.map +1 -0
  382. package/dist/src/integrations/utilities/capabilities.d.ts +160 -0
  383. package/dist/src/integrations/utilities/capabilities.d.ts.map +1 -0
  384. package/dist/src/integrations/utilities/capabilities.js +426 -0
  385. package/dist/src/integrations/utilities/capabilities.js.map +1 -0
  386. package/dist/src/integrations/utilities/diff-utils.d.ts +105 -0
  387. package/dist/src/integrations/utilities/diff-utils.d.ts.map +1 -0
  388. package/dist/src/integrations/utilities/diff-utils.js +497 -0
  389. package/dist/src/integrations/utilities/diff-utils.js.map +1 -0
  390. package/dist/src/integrations/utilities/environment-facts.d.ts +52 -0
  391. package/dist/src/integrations/utilities/environment-facts.d.ts.map +1 -0
  392. package/dist/src/integrations/utilities/environment-facts.js +84 -0
  393. package/dist/src/integrations/utilities/environment-facts.js.map +1 -0
  394. package/dist/src/integrations/utilities/file-change-tracker.d.ts +162 -0
  395. package/dist/src/integrations/utilities/file-change-tracker.d.ts.map +1 -0
  396. package/dist/src/integrations/utilities/file-change-tracker.js +538 -0
  397. package/dist/src/integrations/utilities/file-change-tracker.js.map +1 -0
  398. package/dist/src/integrations/utilities/graph-visualization.d.ts +72 -0
  399. package/dist/src/integrations/utilities/graph-visualization.d.ts.map +1 -0
  400. package/dist/src/integrations/utilities/graph-visualization.js +383 -0
  401. package/dist/src/integrations/utilities/graph-visualization.js.map +1 -0
  402. package/dist/src/integrations/utilities/hierarchical-config.d.ts +215 -0
  403. package/dist/src/integrations/utilities/hierarchical-config.d.ts.map +1 -0
  404. package/dist/src/integrations/utilities/hierarchical-config.js +504 -0
  405. package/dist/src/integrations/utilities/hierarchical-config.js.map +1 -0
  406. package/dist/src/integrations/utilities/hooks.d.ts +116 -0
  407. package/dist/src/integrations/utilities/hooks.d.ts.map +1 -0
  408. package/dist/src/integrations/utilities/hooks.js +410 -0
  409. package/dist/src/integrations/utilities/hooks.js.map +1 -0
  410. package/dist/src/integrations/utilities/ignore.d.ts +143 -0
  411. package/dist/src/integrations/utilities/ignore.d.ts.map +1 -0
  412. package/dist/src/integrations/utilities/ignore.js +417 -0
  413. package/dist/src/integrations/utilities/ignore.js.map +1 -0
  414. package/dist/src/integrations/utilities/image-renderer.d.ts +119 -0
  415. package/dist/src/integrations/utilities/image-renderer.d.ts.map +1 -0
  416. package/dist/src/integrations/utilities/image-renderer.js +306 -0
  417. package/dist/src/integrations/utilities/image-renderer.js.map +1 -0
  418. package/dist/src/integrations/utilities/logger.d.ts +104 -0
  419. package/dist/src/integrations/utilities/logger.d.ts.map +1 -0
  420. package/dist/src/integrations/utilities/logger.js +219 -0
  421. package/dist/src/integrations/utilities/logger.js.map +1 -0
  422. package/dist/src/integrations/utilities/memory.d.ts +116 -0
  423. package/dist/src/integrations/utilities/memory.d.ts.map +1 -0
  424. package/dist/src/integrations/utilities/memory.js +311 -0
  425. package/dist/src/integrations/utilities/memory.js.map +1 -0
  426. package/dist/src/integrations/utilities/observability.d.ts +162 -0
  427. package/dist/src/integrations/utilities/observability.d.ts.map +1 -0
  428. package/dist/src/integrations/utilities/observability.js +407 -0
  429. package/dist/src/integrations/utilities/observability.js.map +1 -0
  430. package/dist/src/integrations/utilities/openrouter-pricing.d.ts +67 -0
  431. package/dist/src/integrations/utilities/openrouter-pricing.d.ts.map +1 -0
  432. package/dist/src/integrations/utilities/openrouter-pricing.js +166 -0
  433. package/dist/src/integrations/utilities/openrouter-pricing.js.map +1 -0
  434. package/dist/src/integrations/utilities/react.d.ts +139 -0
  435. package/dist/src/integrations/utilities/react.d.ts.map +1 -0
  436. package/dist/src/integrations/utilities/react.js +273 -0
  437. package/dist/src/integrations/utilities/react.js.map +1 -0
  438. package/dist/src/integrations/utilities/retry.d.ts +132 -0
  439. package/dist/src/integrations/utilities/retry.d.ts.map +1 -0
  440. package/dist/src/integrations/utilities/retry.js +233 -0
  441. package/dist/src/integrations/utilities/retry.js.map +1 -0
  442. package/dist/src/integrations/utilities/routing.d.ts +118 -0
  443. package/dist/src/integrations/utilities/routing.d.ts.map +1 -0
  444. package/dist/src/integrations/utilities/routing.js +348 -0
  445. package/dist/src/integrations/utilities/routing.js.map +1 -0
  446. package/dist/src/integrations/utilities/rules.d.ts +131 -0
  447. package/dist/src/integrations/utilities/rules.d.ts.map +1 -0
  448. package/dist/src/integrations/utilities/rules.js +284 -0
  449. package/dist/src/integrations/utilities/rules.js.map +1 -0
  450. package/dist/src/integrations/utilities/sourcegraph.d.ts +169 -0
  451. package/dist/src/integrations/utilities/sourcegraph.d.ts.map +1 -0
  452. package/dist/src/integrations/utilities/sourcegraph.js +379 -0
  453. package/dist/src/integrations/utilities/sourcegraph.js.map +1 -0
  454. package/dist/src/integrations/utilities/thinking-strategy.d.ts +52 -0
  455. package/dist/src/integrations/utilities/thinking-strategy.d.ts.map +1 -0
  456. package/dist/src/integrations/utilities/thinking-strategy.js +129 -0
  457. package/dist/src/integrations/utilities/thinking-strategy.js.map +1 -0
  458. package/dist/src/integrations/utilities/thread-manager.d.ts +199 -0
  459. package/dist/src/integrations/utilities/thread-manager.d.ts.map +1 -0
  460. package/dist/src/integrations/utilities/thread-manager.js +357 -0
  461. package/dist/src/integrations/utilities/thread-manager.js.map +1 -0
  462. package/dist/src/integrations/utilities/token-estimate.d.ts +11 -0
  463. package/dist/src/integrations/utilities/token-estimate.d.ts.map +1 -0
  464. package/dist/src/integrations/utilities/token-estimate.js +14 -0
  465. package/dist/src/integrations/utilities/token-estimate.js.map +1 -0
  466. package/dist/src/main.js +10 -4
  467. package/dist/src/main.js.map +1 -1
  468. package/dist/src/modes/repl.d.ts.map +1 -1
  469. package/dist/src/modes/repl.js +22 -5
  470. package/dist/src/modes/repl.js.map +1 -1
  471. package/dist/src/modes/tui.d.ts.map +1 -1
  472. package/dist/src/modes/tui.js +23 -6
  473. package/dist/src/modes/tui.js.map +1 -1
  474. package/dist/src/modes.js +1 -1
  475. package/dist/src/modes.js.map +1 -1
  476. package/dist/src/observability/tracer.js +1 -1
  477. package/dist/src/observability/tracer.js.map +1 -1
  478. package/dist/src/persistence/schema.d.ts +2 -0
  479. package/dist/src/persistence/schema.d.ts.map +1 -1
  480. package/dist/src/persistence/schema.js +31 -0
  481. package/dist/src/persistence/schema.js.map +1 -1
  482. package/dist/src/providers/adapters/anthropic.d.ts +6 -0
  483. package/dist/src/providers/adapters/anthropic.d.ts.map +1 -1
  484. package/dist/src/providers/adapters/anthropic.js +99 -15
  485. package/dist/src/providers/adapters/anthropic.js.map +1 -1
  486. package/dist/src/providers/adapters/azure.d.ts +74 -0
  487. package/dist/src/providers/adapters/azure.d.ts.map +1 -0
  488. package/dist/src/providers/adapters/azure.js +354 -0
  489. package/dist/src/providers/adapters/azure.js.map +1 -0
  490. package/dist/src/providers/adapters/mock.d.ts +16 -2
  491. package/dist/src/providers/adapters/mock.d.ts.map +1 -1
  492. package/dist/src/providers/adapters/mock.js +44 -3
  493. package/dist/src/providers/adapters/mock.js.map +1 -1
  494. package/dist/src/providers/adapters/openai.d.ts +6 -1
  495. package/dist/src/providers/adapters/openai.d.ts.map +1 -1
  496. package/dist/src/providers/adapters/openai.js +39 -8
  497. package/dist/src/providers/adapters/openai.js.map +1 -1
  498. package/dist/src/providers/adapters/openrouter.d.ts +6 -0
  499. package/dist/src/providers/adapters/openrouter.d.ts.map +1 -1
  500. package/dist/src/providers/adapters/openrouter.js +73 -3
  501. package/dist/src/providers/adapters/openrouter.js.map +1 -1
  502. package/dist/src/providers/provider.js +1 -1
  503. package/dist/src/providers/provider.js.map +1 -1
  504. package/dist/src/providers/resilient-provider.js +1 -1
  505. package/dist/src/providers/resilient-provider.js.map +1 -1
  506. package/dist/src/providers/types.d.ts +23 -2
  507. package/dist/src/providers/types.d.ts.map +1 -1
  508. package/dist/src/session-picker.d.ts +1 -1
  509. package/dist/src/session-picker.d.ts.map +1 -1
  510. package/dist/src/session-picker.js +1 -1
  511. package/dist/src/session-picker.js.map +1 -1
  512. package/dist/src/shared/budget-tracker.js +1 -1
  513. package/dist/src/shared/budget-tracker.js.map +1 -1
  514. package/dist/src/tools/agent.d.ts +1 -1
  515. package/dist/src/tools/agent.d.ts.map +1 -1
  516. package/dist/src/tools/bash.js +1 -1
  517. package/dist/src/tools/bash.js.map +1 -1
  518. package/dist/src/tools/file.js +1 -1
  519. package/dist/src/tools/file.js.map +1 -1
  520. package/dist/src/tools/permission.js +2 -2
  521. package/dist/src/tools/permission.js.map +1 -1
  522. package/dist/src/tools/registry.d.ts +1 -1
  523. package/dist/src/tools/registry.d.ts.map +1 -1
  524. package/dist/src/tools/registry.js +1 -1
  525. package/dist/src/tools/registry.js.map +1 -1
  526. package/dist/src/tools/tasks.d.ts +1 -1
  527. package/dist/src/tools/tasks.d.ts.map +1 -1
  528. package/dist/src/tools/undo.d.ts +1 -1
  529. package/dist/src/tools/undo.d.ts.map +1 -1
  530. package/dist/src/tracing/cache-boundary-tracker.d.ts.map +1 -1
  531. package/dist/src/tracing/cache-boundary-tracker.js +2 -2
  532. package/dist/src/tracing/cache-boundary-tracker.js.map +1 -1
  533. package/dist/src/tracing/trace-collector.d.ts +22 -0
  534. package/dist/src/tracing/trace-collector.d.ts.map +1 -1
  535. package/dist/src/tracing/trace-collector.js +27 -3
  536. package/dist/src/tracing/trace-collector.js.map +1 -1
  537. package/dist/src/tracing/types.d.ts +17 -1
  538. package/dist/src/tracing/types.d.ts.map +1 -1
  539. package/dist/src/tracing/types.js.map +1 -1
  540. package/dist/src/tricks/failure-evidence.js +1 -1
  541. package/dist/src/tricks/failure-evidence.js.map +1 -1
  542. package/dist/src/tricks/recitation.d.ts.map +1 -1
  543. package/dist/src/tricks/recitation.js +2 -1
  544. package/dist/src/tricks/recitation.js.map +1 -1
  545. package/dist/src/tricks/recursive-context.d.ts.map +1 -1
  546. package/dist/src/tricks/recursive-context.js +2 -2
  547. package/dist/src/tricks/recursive-context.js.map +1 -1
  548. package/dist/src/tricks/reversible-compaction.d.ts.map +1 -1
  549. package/dist/src/tricks/reversible-compaction.js +6 -2
  550. package/dist/src/tricks/reversible-compaction.js.map +1 -1
  551. package/dist/src/tui/app.d.ts +3 -3
  552. package/dist/src/tui/app.d.ts.map +1 -1
  553. package/dist/src/tui/app.js +86 -14
  554. package/dist/src/tui/app.js.map +1 -1
  555. package/dist/src/tui/components/CollapsibleDiffView.d.ts +1 -1
  556. package/dist/src/tui/components/CollapsibleDiffView.d.ts.map +1 -1
  557. package/dist/src/tui/components/DiagnosticsPanel.d.ts +24 -0
  558. package/dist/src/tui/components/DiagnosticsPanel.d.ts.map +1 -0
  559. package/dist/src/tui/components/DiagnosticsPanel.js +47 -0
  560. package/dist/src/tui/components/DiagnosticsPanel.js.map +1 -0
  561. package/dist/src/tui/components/DiffView.d.ts +1 -1
  562. package/dist/src/tui/components/DiffView.d.ts.map +1 -1
  563. package/dist/src/tui/components/ErrorBoundary.js +1 -1
  564. package/dist/src/tui/components/ErrorBoundary.js.map +1 -1
  565. package/dist/src/tui/components/TasksPanel.d.ts +1 -1
  566. package/dist/src/tui/components/TasksPanel.d.ts.map +1 -1
  567. package/dist/src/tui/event-display.js +1 -1
  568. package/dist/src/tui/event-display.js.map +1 -1
  569. package/dist/src/tui/index.js +1 -1
  570. package/dist/src/tui/index.js.map +1 -1
  571. package/dist/src/tui/transparency-aggregator.d.ts +13 -0
  572. package/dist/src/tui/transparency-aggregator.d.ts.map +1 -1
  573. package/dist/src/tui/transparency-aggregator.js +21 -0
  574. package/dist/src/tui/transparency-aggregator.js.map +1 -1
  575. package/dist/src/types.d.ts +27 -2
  576. package/dist/src/types.d.ts.map +1 -1
  577. package/package.json +1 -1
@@ -0,0 +1,352 @@
1
+ /**
2
+ * Lesson 25: Execution Policy Integration
3
+ *
4
+ * Integrates execution policies and intent classification (from Lesson 23)
5
+ * into the production agent. Provides three-tier tool access control
6
+ * and intent-aware policy decisions.
7
+ */
8
+ // =============================================================================
9
+ // EXECUTION POLICY MANAGER
10
+ // =============================================================================
11
+ /**
12
+ * ExecutionPolicyManager handles tool access control and intent classification.
13
+ */
14
+ export class ExecutionPolicyManager {
15
+ config;
16
+ grants = new Map();
17
+ listeners = [];
18
+ grantIdCounter = 0;
19
+ constructor(config = {}) {
20
+ this.config = {
21
+ defaultPolicy: config.defaultPolicy ?? 'prompt',
22
+ toolPolicies: config.toolPolicies ?? {},
23
+ intentAware: config.intentAware ?? true,
24
+ intentConfidenceThreshold: config.intentConfidenceThreshold ?? 0.7,
25
+ };
26
+ }
27
+ /**
28
+ * Evaluate policy for a tool call.
29
+ */
30
+ evaluate(toolCall, context) {
31
+ // Check for active grant first
32
+ const grant = this.findGrant(toolCall);
33
+ if (grant) {
34
+ this.useGrant(grant);
35
+ return {
36
+ policy: 'allow',
37
+ reason: `Allowed by grant: ${grant.reason || 'permission granted'}`,
38
+ grantUsed: grant,
39
+ requiresApproval: false,
40
+ };
41
+ }
42
+ // Get base policy for tool
43
+ const toolPolicy = this.config.toolPolicies[toolCall.name];
44
+ let policy = toolPolicy?.policy ?? this.config.defaultPolicy;
45
+ let reason = toolPolicy?.reason ?? 'Default policy';
46
+ // Check conditions
47
+ if (toolPolicy?.conditions) {
48
+ for (const condition of toolPolicy.conditions) {
49
+ if (this.matchesCondition(toolCall, context, condition)) {
50
+ policy = condition.policy;
51
+ reason = condition.reason || `Condition matched`;
52
+ break;
53
+ }
54
+ }
55
+ }
56
+ // Classify intent if enabled
57
+ let intent;
58
+ if (this.config.intentAware && policy === 'prompt') {
59
+ intent = this.classifyIntent(toolCall, context);
60
+ this.emit({ type: 'intent.classified', tool: toolCall.name, intent });
61
+ // Adjust policy based on intent
62
+ if (intent.type === 'deliberate' && intent.confidence >= this.config.intentConfidenceThreshold) {
63
+ policy = 'allow';
64
+ reason = `Intent: deliberate (confidence: ${(intent.confidence * 100).toFixed(0)}%)`;
65
+ }
66
+ }
67
+ const result = {
68
+ policy,
69
+ reason,
70
+ intent,
71
+ requiresApproval: policy === 'prompt',
72
+ };
73
+ this.emit({ type: 'policy.evaluated', tool: toolCall.name, result });
74
+ if (policy === 'forbidden') {
75
+ this.emit({ type: 'tool.blocked', tool: toolCall.name, reason });
76
+ }
77
+ else if (policy === 'prompt') {
78
+ this.emit({ type: 'tool.prompted', tool: toolCall.name });
79
+ }
80
+ return result;
81
+ }
82
+ /**
83
+ * Create a permission grant.
84
+ */
85
+ createGrant(options) {
86
+ const grant = {
87
+ id: `grant_${++this.grantIdCounter}`,
88
+ ...options,
89
+ };
90
+ this.grants.set(grant.id, grant);
91
+ this.emit({ type: 'grant.created', grant });
92
+ return grant;
93
+ }
94
+ /**
95
+ * Revoke a grant.
96
+ */
97
+ revokeGrant(grantId) {
98
+ const existed = this.grants.delete(grantId);
99
+ if (existed) {
100
+ this.emit({ type: 'grant.expired', grantId });
101
+ }
102
+ return existed;
103
+ }
104
+ /**
105
+ * Get active grants.
106
+ */
107
+ getActiveGrants() {
108
+ this.cleanupExpiredGrants();
109
+ return Array.from(this.grants.values());
110
+ }
111
+ /**
112
+ * Subscribe to events.
113
+ */
114
+ on(listener) {
115
+ this.listeners.push(listener);
116
+ return () => {
117
+ const idx = this.listeners.indexOf(listener);
118
+ if (idx >= 0)
119
+ this.listeners.splice(idx, 1);
120
+ };
121
+ }
122
+ /**
123
+ * Update tool policy.
124
+ */
125
+ setToolPolicy(toolName, policy) {
126
+ this.config.toolPolicies[toolName] = policy;
127
+ }
128
+ /**
129
+ * Get current config.
130
+ */
131
+ getConfig() {
132
+ return { ...this.config };
133
+ }
134
+ // -------------------------------------------------------------------------
135
+ // PRIVATE METHODS
136
+ // -------------------------------------------------------------------------
137
+ emit(event) {
138
+ for (const listener of this.listeners) {
139
+ try {
140
+ listener(event);
141
+ }
142
+ catch {
143
+ // Ignore listener errors
144
+ }
145
+ }
146
+ }
147
+ findGrant(toolCall) {
148
+ this.cleanupExpiredGrants();
149
+ for (const grant of this.grants.values()) {
150
+ if (grant.toolName !== toolCall.name)
151
+ continue;
152
+ // Check arg pattern if specified
153
+ if (grant.argPattern) {
154
+ if (!this.matchesArgPattern(toolCall.arguments, grant.argPattern)) {
155
+ continue;
156
+ }
157
+ }
158
+ // Check usage limit
159
+ if (grant.maxUsages !== undefined && (grant.usageCount ?? 0) >= grant.maxUsages) {
160
+ continue;
161
+ }
162
+ return grant;
163
+ }
164
+ return undefined;
165
+ }
166
+ useGrant(grant) {
167
+ grant.usageCount = (grant.usageCount ?? 0) + 1;
168
+ this.emit({ type: 'grant.used', grant });
169
+ // Check if grant should be removed
170
+ if (grant.maxUsages !== undefined && grant.usageCount >= grant.maxUsages) {
171
+ this.grants.delete(grant.id);
172
+ this.emit({ type: 'grant.expired', grantId: grant.id });
173
+ }
174
+ }
175
+ cleanupExpiredGrants() {
176
+ const now = new Date();
177
+ for (const [id, grant] of this.grants) {
178
+ if (grant.expiresAt && grant.expiresAt < now) {
179
+ this.grants.delete(id);
180
+ this.emit({ type: 'grant.expired', grantId: id });
181
+ }
182
+ }
183
+ }
184
+ matchesCondition(toolCall, context, condition) {
185
+ // Check argument pattern
186
+ if (condition.argMatch) {
187
+ for (const [key, pattern] of Object.entries(condition.argMatch)) {
188
+ const value = toolCall.arguments[key];
189
+ if (value === undefined)
190
+ return false;
191
+ const stringValue = String(value);
192
+ if (typeof pattern === 'string') {
193
+ if (!stringValue.includes(pattern))
194
+ return false;
195
+ }
196
+ else if (pattern instanceof RegExp) {
197
+ if (!pattern.test(stringValue))
198
+ return false;
199
+ }
200
+ }
201
+ }
202
+ // Check context condition
203
+ if (condition.contextMatch) {
204
+ if (!condition.contextMatch(context))
205
+ return false;
206
+ }
207
+ return true;
208
+ }
209
+ matchesArgPattern(args, pattern) {
210
+ for (const [key, value] of Object.entries(pattern)) {
211
+ const argValue = args[key];
212
+ if (argValue !== value)
213
+ return false;
214
+ }
215
+ return true;
216
+ }
217
+ classifyIntent(toolCall, context) {
218
+ const evidence = [];
219
+ let score = 0;
220
+ // Check if tool name appears in recent user message
221
+ const recentUserMessage = context.currentMessage || this.getLastUserMessage(context);
222
+ if (recentUserMessage) {
223
+ const normalizedTool = toolCall.name.toLowerCase().replace(/_/g, ' ');
224
+ const normalizedMessage = recentUserMessage.toLowerCase();
225
+ if (normalizedMessage.includes(normalizedTool) ||
226
+ normalizedMessage.includes(toolCall.name.toLowerCase())) {
227
+ score += 0.4;
228
+ evidence.push('Tool name mentioned in user message');
229
+ }
230
+ // Check for imperative verbs suggesting intent
231
+ const imperatives = ['please', 'can you', 'could you', 'i need', 'i want', 'do', 'run', 'execute'];
232
+ if (imperatives.some(imp => normalizedMessage.includes(imp))) {
233
+ score += 0.2;
234
+ evidence.push('Imperative language detected');
235
+ }
236
+ }
237
+ // Check if this tool was used before in conversation
238
+ const previousToolCalls = context.previousToolCalls || [];
239
+ if (previousToolCalls.some(tc => tc.name === toolCall.name)) {
240
+ score += 0.2;
241
+ evidence.push('Tool used previously in session');
242
+ }
243
+ // Check conversation flow
244
+ if (context.messages.length >= 2) {
245
+ const recentMessages = context.messages.slice(-3);
246
+ const mentionsAction = recentMessages.some(m => m.content.toLowerCase().includes(toolCall.name.toLowerCase()));
247
+ if (mentionsAction) {
248
+ score += 0.2;
249
+ evidence.push('Tool discussed in recent messages');
250
+ }
251
+ }
252
+ // Determine intent type
253
+ let type;
254
+ if (score >= 0.6) {
255
+ type = 'deliberate';
256
+ }
257
+ else if (score >= 0.3) {
258
+ type = 'inferred';
259
+ }
260
+ else {
261
+ type = 'accidental';
262
+ }
263
+ return {
264
+ type,
265
+ confidence: Math.min(1, score),
266
+ evidence,
267
+ };
268
+ }
269
+ getLastUserMessage(context) {
270
+ for (let i = context.messages.length - 1; i >= 0; i--) {
271
+ if (context.messages[i].role === 'user') {
272
+ return context.messages[i].content;
273
+ }
274
+ }
275
+ return undefined;
276
+ }
277
+ }
278
+ // =============================================================================
279
+ // FACTORY
280
+ // =============================================================================
281
+ /**
282
+ * Create an execution policy manager.
283
+ */
284
+ export function createExecutionPolicyManager(config) {
285
+ return new ExecutionPolicyManager(config);
286
+ }
287
+ // =============================================================================
288
+ // PRESET POLICIES
289
+ // =============================================================================
290
+ /**
291
+ * Strict policy preset - minimal auto-allow.
292
+ */
293
+ export const STRICT_POLICY = {
294
+ defaultPolicy: 'prompt',
295
+ intentAware: true,
296
+ intentConfidenceThreshold: 0.9,
297
+ toolPolicies: {
298
+ read_file: { policy: 'allow', reason: 'Read-only operation' },
299
+ list_directory: { policy: 'allow', reason: 'Read-only operation' },
300
+ search: { policy: 'allow', reason: 'Read-only operation' },
301
+ write_file: { policy: 'prompt', reason: 'Modifies filesystem' },
302
+ delete_file: { policy: 'forbidden', reason: 'Destructive operation' },
303
+ bash: {
304
+ policy: 'prompt',
305
+ conditions: [
306
+ { argMatch: { command: /^ls\s/ }, policy: 'allow', reason: 'Safe read command' },
307
+ { argMatch: { command: /^rm\s/ }, policy: 'forbidden', reason: 'Destructive command' },
308
+ { argMatch: { command: /^sudo\s/ }, policy: 'forbidden', reason: 'Elevated privileges' },
309
+ ],
310
+ },
311
+ },
312
+ };
313
+ /**
314
+ * Balanced policy preset - reasonable defaults.
315
+ */
316
+ export const BALANCED_POLICY = {
317
+ defaultPolicy: 'prompt',
318
+ intentAware: true,
319
+ intentConfidenceThreshold: 0.7,
320
+ toolPolicies: {
321
+ read_file: { policy: 'allow' },
322
+ list_directory: { policy: 'allow' },
323
+ search: { policy: 'allow' },
324
+ write_file: { policy: 'prompt' },
325
+ delete_file: { policy: 'prompt' },
326
+ bash: {
327
+ policy: 'prompt',
328
+ conditions: [
329
+ { argMatch: { command: /^(ls|pwd|echo|cat|head|tail|grep)\s/ }, policy: 'allow' },
330
+ { argMatch: { command: /^rm\s+-rf\s+\// }, policy: 'forbidden' },
331
+ ],
332
+ },
333
+ },
334
+ };
335
+ /**
336
+ * Permissive policy preset - trust the agent.
337
+ */
338
+ export const PERMISSIVE_POLICY = {
339
+ defaultPolicy: 'allow',
340
+ intentAware: false,
341
+ toolPolicies: {
342
+ bash: {
343
+ policy: 'allow',
344
+ conditions: [
345
+ { argMatch: { command: /^rm\s+-rf\s+\// }, policy: 'forbidden' },
346
+ { argMatch: { command: /^sudo\s/ }, policy: 'prompt' },
347
+ ],
348
+ },
349
+ delete_file: { policy: 'prompt' },
350
+ },
351
+ };
352
+ //# sourceMappingURL=execution-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"execution-policy.js","sourceRoot":"","sources":["../../../../src/integrations/safety/execution-policy.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAwHH,gFAAgF;AAChF,2BAA2B;AAC3B,gFAAgF;AAEhF;;GAEG;AACH,MAAM,OAAO,sBAAsB;IACzB,MAAM,CAAwB;IAC9B,MAAM,GAAG,IAAI,GAAG,EAA2B,CAAC;IAC5C,SAAS,GAA0B,EAAE,CAAC;IACtC,cAAc,GAAG,CAAC,CAAC;IAE3B,YAAY,SAAyC,EAAE;QACrD,IAAI,CAAC,MAAM,GAAG;YACZ,aAAa,EAAE,MAAM,CAAC,aAAa,IAAI,QAAQ;YAC/C,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,EAAE;YACvC,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,IAAI;YACvC,yBAAyB,EAAE,MAAM,CAAC,yBAAyB,IAAI,GAAG;SACnE,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,QAAQ,CACN,QAAkB,EAClB,OAAsB;QAEtB,+BAA+B;QAC/B,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QACvC,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACrB,OAAO;gBACL,MAAM,EAAE,OAAO;gBACf,MAAM,EAAE,qBAAqB,KAAK,CAAC,MAAM,IAAI,oBAAoB,EAAE;gBACnE,SAAS,EAAE,KAAK;gBAChB,gBAAgB,EAAE,KAAK;aACxB,CAAC;QACJ,CAAC;QAED,2BAA2B;QAC3B,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC3D,IAAI,MAAM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AAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAA0B;IACpD,aAAa,EAAE,QAAQ;IACvB,WAAW,EAAE,IAAI;IACjB,yBAAyB,EAAE,GAAG;IAC9B,YAAY,EAAE;QACZ,SAAS,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE;QAC9B,cAAc,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE;QACnC,MAAM,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE;QAC3B,UAAU,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;QAChC,WAAW,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;QACjC,IAAI,EAAE;YACJ,MAAM,EAAE,QAAQ;YAChB,UAAU,EAAE;gBACV,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,qCAAqC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE;gBACjF,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE;aACjE;SACF;KACF;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAA0B;IACtD,aAAa,EAAE,OAAO;IACtB,WAAW,EAAE,KAAK;IAClB,YAAY,EAAE;QACZ,IAAI,EAAE;YACJ,MAAM,EAAE,OAAO;YACf,UAAU,EAAE;gBACV,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE;gBAChE,EAAE,QAAQ,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;aACvD;SACF;QACD,WAAW,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;KAClC;CACF,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Unified policy engine.
3
+ *
4
+ * Resolves effective tool/bash/approval behavior from profiles plus
5
+ * compatibility mappings from legacy config fields.
6
+ */
7
+ import type { PolicyEngineConfig, PolicyProfile, SandboxConfig } from '../../types.js';
8
+ import type { SwarmConfig, SwarmWorkerSpec } from '../swarm/types.js';
9
+ export declare const DEFAULT_POLICY_PROFILES: Record<string, PolicyProfile>;
10
+ export declare const DEFAULT_POLICY_ENGINE_CONFIG: Required<Pick<PolicyEngineConfig, 'enabled' | 'legacyFallback' | 'defaultProfile' | 'defaultSwarmProfile'>>;
11
+ export interface ResolvePolicyProfileOptions {
12
+ policyEngine?: PolicyEngineConfig | false;
13
+ requestedProfile?: string;
14
+ swarmConfig?: SwarmConfig;
15
+ worker?: SwarmWorkerSpec;
16
+ taskType?: string;
17
+ sandboxConfig?: SandboxConfig;
18
+ isSwarmWorker?: boolean;
19
+ legacyAllowedTools?: string[];
20
+ legacyDeniedTools?: string[];
21
+ globalDeniedTools?: string[];
22
+ }
23
+ export interface ResolvedPolicyProfile {
24
+ profileName: string;
25
+ profile: PolicyProfile;
26
+ metadata: {
27
+ selectionSource: 'explicit' | 'worker-capability' | 'task-type' | 'default';
28
+ usedLegacyMappings: boolean;
29
+ legacyMappingSources: string[];
30
+ warnings: string[];
31
+ };
32
+ }
33
+ export declare function resolvePolicyProfile(options: ResolvePolicyProfileOptions): ResolvedPolicyProfile;
34
+ export declare function isToolAllowedByProfile(toolName: string, profile: PolicyProfile): {
35
+ allowed: boolean;
36
+ reason?: string;
37
+ };
38
+ export declare function evaluateBashCommandByProfile(command: string, profile: PolicyProfile, taskType?: string): {
39
+ allowed: boolean;
40
+ reason?: string;
41
+ };
42
+ export declare function mergeApprovalScopeWithProfile(scope: {
43
+ autoApprove: string[];
44
+ scopedApprove: Record<string, {
45
+ paths: string[];
46
+ }>;
47
+ requireApproval: string[];
48
+ }, profile: PolicyProfile): {
49
+ autoApprove: string[];
50
+ scopedApprove: Record<string, {
51
+ paths: string[];
52
+ }>;
53
+ requireApproval: string[];
54
+ };
55
+ //# sourceMappingURL=policy-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy-engine.d.ts","sourceR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2B,GAAG,qBAAqB,CAyFhG;AAED,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,aAAa,GACrB;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAevC;AAED,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,aAAa,EACtB,QAAQ,CAAC,EAAE,MAAM,GAChB;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAevC;AAED,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE;IACL,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;IACnD,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B,EACD,OAAO,EAAE,aAAa,GACrB;IACD,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;IACnD,eAAe,EAAE,MAAM,EAAE,CAAC;CAC3B,CAMA"}
@@ -0,0 +1,247 @@
1
+ /**
2
+ * Unified policy engine.
3
+ *
4
+ * Resolves effective tool/bash/approval behavior from profiles plus
5
+ * compatibility mappings from legacy config fields.
6
+ */
7
+ import { getTaskTypeConfig } from '../swarm/types.js';
8
+ import { evaluateBashPolicy } from './bash-policy.js';
9
+ export const DEFAULT_POLICY_PROFILES = {
10
+ 'research-safe': {
11
+ toolAccessMode: 'whitelist',
12
+ allowedTools: ['read_file', 'list_files', 'glob', 'grep', 'web_search', 'write_file', 'bash', 'task_get', 'task_list'],
13
+ deniedTools: ['delete_file'],
14
+ bashMode: 'read_only',
15
+ bashWriteProtection: 'block_file_mutation',
16
+ },
17
+ 'code-strict-bash': {
18
+ toolAccessMode: 'whitelist',
19
+ allowedTools: ['read_file', 'write_file', 'edit_file', 'list_files', 'glob', 'grep', 'bash', 'web_search', 'task_create', 'task_update', 'task_get', 'task_list'],
20
+ bashMode: 'full',
21
+ bashWriteProtection: 'block_file_mutation',
22
+ },
23
+ 'code-full': {
24
+ toolAccessMode: 'all',
25
+ bashMode: 'full',
26
+ bashWriteProtection: 'off',
27
+ },
28
+ 'review-safe': {
29
+ toolAccessMode: 'whitelist',
30
+ allowedTools: ['read_file', 'list_files', 'glob', 'grep', 'web_search', 'task_get', 'task_list'],
31
+ deniedTools: ['write_file', 'edit_file', 'delete_file', 'bash'],
32
+ bashMode: 'disabled',
33
+ bashWriteProtection: 'block_file_mutation',
34
+ },
35
+ };
36
+ export const DEFAULT_POLICY_ENGINE_CONFIG = {
37
+ enabled: true,
38
+ legacyFallback: true,
39
+ defaultProfile: 'code-full',
40
+ defaultSwarmProfile: 'code-strict-bash',
41
+ };
42
+ function mergeProfiles(...profiles) {
43
+ const merged = {};
44
+ for (const p of profiles) {
45
+ if (!p)
46
+ continue;
47
+ merged.toolAccessMode = p.toolAccessMode ?? merged.toolAccessMode;
48
+ merged.allowedTools = p.allowedTools ?? merged.allowedTools;
49
+ merged.deniedTools = p.deniedTools ?? merged.deniedTools;
50
+ merged.bashMode = p.bashMode ?? merged.bashMode;
51
+ merged.bashWriteProtection = p.bashWriteProtection ?? merged.bashWriteProtection;
52
+ if (p.approval) {
53
+ merged.approval = {
54
+ autoApprove: p.approval.autoApprove ?? merged.approval?.autoApprove,
55
+ scopedApprove: p.approval.scopedApprove ?? merged.approval?.scopedApprove,
56
+ requireApproval: p.approval.requireApproval ?? merged.approval?.requireApproval,
57
+ };
58
+ }
59
+ }
60
+ return merged;
61
+ }
62
+ function inferSwarmProfileForTask(taskType, swarmConfig) {
63
+ if (!taskType)
64
+ return 'code-strict-bash';
65
+ // V7: Use configurable policyProfile from TaskTypeConfig
66
+ const typeConfig = getTaskTypeConfig(taskType, swarmConfig);
67
+ return typeConfig.policyProfile ?? 'code-strict-bash';
68
+ }
69
+ function inferSwarmProfileForWorker(worker) {
70
+ if (!worker?.capabilities || worker.capabilities.length === 0)
71
+ return undefined;
72
+ const caps = new Set(worker.capabilities);
73
+ if (caps.has('code') || caps.has('write') || caps.has('test') || caps.has('document')) {
74
+ return 'code-strict-bash';
75
+ }
76
+ if (caps.has('review')) {
77
+ return 'review-safe';
78
+ }
79
+ if (caps.has('research')) {
80
+ return 'research-safe';
81
+ }
82
+ return undefined;
83
+ }
84
+ function applyLegacyMappings(profile, options) {
85
+ const merged = { ...profile };
86
+ const metadata = {
87
+ selectionSource: 'default',
88
+ usedLegacyMappings: false,
89
+ legacyMappingSources: [],
90
+ warnings: [],
91
+ };
92
+ const legacyAllowed = options.legacyAllowedTools ?? options.worker?.allowedTools;
93
+ if (legacyAllowed && legacyAllowed.length > 0) {
94
+ merged.toolAccessMode = 'whitelist';
95
+ merged.allowedTools = [...legacyAllowed];
96
+ metadata.usedLegacyMappings = true;
97
+ metadata.legacyMappingSources.push('legacyAllowedTools');
98
+ metadata.warnings.push('Legacy tool whitelist is active. Migrate to policyProfiles + worker.policyProfile.');
99
+ }
100
+ const denied = [
101
+ ...(merged.deniedTools ?? []),
102
+ ...(options.legacyDeniedTools ?? options.worker?.deniedTools ?? []),
103
+ ...(options.globalDeniedTools ?? options.swarmConfig?.globalDeniedTools ?? []),
104
+ ];
105
+ if (denied.length > 0) {
106
+ merged.deniedTools = [...new Set(denied)];
107
+ metadata.usedLegacyMappings = true;
108
+ metadata.legacyMappingSources.push('legacyDeniedTools/globalDeniedTools');
109
+ metadata.warnings.push('Legacy denied tools are active. Migrate to policyProfiles[].deniedTools.');
110
+ }
111
+ if (options.sandboxConfig?.blockFileCreationViaBash) {
112
+ merged.bashWriteProtection = 'block_file_mutation';
113
+ metadata.usedLegacyMappings = true;
114
+ metadata.legacyMappingSources.push('sandbox.blockFileCreationViaBash');
115
+ metadata.warnings.push('sandbox.blockFileCreationViaBash is legacy compatibility behavior. Use policy profile bashWriteProtection.');
116
+ }
117
+ if (options.sandboxConfig?.bashMode) {
118
+ merged.bashMode = options.sandboxConfig.bashMode;
119
+ metadata.usedLegacyMappings = true;
120
+ metadata.legacyMappingSources.push('sandbox.bashMode');
121
+ metadata.warnings.push('sandbox.bashMode override is active. Prefer profile-level bashMode.');
122
+ }
123
+ if (options.sandboxConfig?.bashWriteProtection) {
124
+ merged.bashWriteProtection = options.sandboxConfig.bashWriteProtection;
125
+ metadata.usedLegacyMappings = true;
126
+ metadata.legacyMappingSources.push('sandbox.bashWriteProtection');
127
+ metadata.warnings.push('sandbox.bashWriteProtection override is active. Prefer profile-level bashWriteProtection.');
128
+ }
129
+ return { profile: merged, metadata };
130
+ }
131
+ export function resolvePolicyProfile(options) {
132
+ const policyEngine = options.policyEngine || undefined;
133
+ const legacyFallback = policyEngine?.legacyFallback ?? DEFAULT_POLICY_ENGINE_CONFIG.legacyFallback;
134
+ const mergedProfiles = {
135
+ ...DEFAULT_POLICY_PROFILES,
136
+ ...(policyEngine?.profiles ?? {}),
137
+ ...(options.swarmConfig?.policyProfiles ?? {}),
138
+ };
139
+ // Apply profileExtensions (additive patches from YAML)
140
+ const extensions = options.swarmConfig?.profileExtensions;
141
+ if (extensions) {
142
+ for (const [profileName, ext] of Object.entries(extensions)) {
143
+ const target = mergedProfiles[profileName];
144
+ if (!target)
145
+ continue;
146
+ if (ext.addTools?.length && target.allowedTools) {
147
+ target.allowedTools = [...new Set([...target.allowedTools, ...ext.addTools])];
148
+ // If you explicitly add a tool, remove it from deniedTools so it actually works
149
+ if (target.deniedTools) {
150
+ target.deniedTools = target.deniedTools.filter(t => !ext.addTools.includes(t));
151
+ }
152
+ }
153
+ if (ext.removeTools?.length) {
154
+ if (target.allowedTools) {
155
+ target.allowedTools = target.allowedTools.filter(t => !ext.removeTools.includes(t));
156
+ }
157
+ // Also add removed tools to deniedTools for belt-and-suspenders
158
+ target.deniedTools = [...new Set([...(target.deniedTools ?? []), ...ext.removeTools])];
159
+ }
160
+ }
161
+ }
162
+ const defaultProfileName = options.isSwarmWorker
163
+ ? (policyEngine?.defaultSwarmProfile ?? DEFAULT_POLICY_ENGINE_CONFIG.defaultSwarmProfile)
164
+ : (policyEngine?.defaultProfile ?? DEFAULT_POLICY_ENGINE_CONFIG.defaultProfile);
165
+ let selectionSource = 'default';
166
+ let requestedProfile = defaultProfileName;
167
+ if (options.requestedProfile || options.worker?.policyProfile) {
168
+ requestedProfile = options.requestedProfile ?? options.worker?.policyProfile ?? defaultProfileName;
169
+ selectionSource = 'explicit';
170
+ }
171
+ else if (options.isSwarmWorker) {
172
+ const workerInferred = inferSwarmProfileForWorker(options.worker);
173
+ if (workerInferred) {
174
+ requestedProfile = workerInferred;
175
+ selectionSource = 'worker-capability';
176
+ }
177
+ else if (options.taskType) {
178
+ requestedProfile = inferSwarmProfileForTask(options.taskType, options.swarmConfig);
179
+ selectionSource = 'task-type';
180
+ }
181
+ else {
182
+ requestedProfile = defaultProfileName;
183
+ selectionSource = 'default';
184
+ }
185
+ }
186
+ const base = mergedProfiles[defaultProfileName] ?? DEFAULT_POLICY_PROFILES['code-full'];
187
+ const requested = mergedProfiles[requestedProfile] ?? base;
188
+ const merged = mergeProfiles(base, requested);
189
+ const { profile: effective, metadata } = legacyFallback
190
+ ? applyLegacyMappings(merged, options)
191
+ : {
192
+ profile: merged,
193
+ metadata: {
194
+ selectionSource: 'default',
195
+ usedLegacyMappings: false,
196
+ legacyMappingSources: [],
197
+ warnings: [],
198
+ },
199
+ };
200
+ // Merge worker.extraTools into the profile whitelist (additive, overrides deniedTools)
201
+ if (options.worker?.extraTools?.length && effective.toolAccessMode === 'whitelist' && effective.allowedTools) {
202
+ effective.allowedTools = [...new Set([...effective.allowedTools, ...options.worker.extraTools])];
203
+ // If you explicitly add a tool via extraTools, remove it from deniedTools so it actually works
204
+ if (effective.deniedTools) {
205
+ effective.deniedTools = effective.deniedTools.filter(t => !options.worker.extraTools.includes(t));
206
+ }
207
+ }
208
+ return {
209
+ profileName: requestedProfile,
210
+ profile: effective,
211
+ metadata: {
212
+ ...metadata,
213
+ selectionSource,
214
+ },
215
+ };
216
+ }
217
+ export function isToolAllowedByProfile(toolName, profile) {
218
+ const mode = profile.toolAccessMode ?? 'all';
219
+ if (mode === 'whitelist') {
220
+ const allowed = profile.allowedTools ?? [];
221
+ if (!allowed.includes(toolName)) {
222
+ return { allowed: false, reason: `Tool '${toolName}' is not allowed by policy whitelist.` };
223
+ }
224
+ }
225
+ if ((profile.deniedTools ?? []).includes(toolName)) {
226
+ return { allowed: false, reason: `Tool '${toolName}' is denied by policy profile.` };
227
+ }
228
+ return { allowed: true };
229
+ }
230
+ export function evaluateBashCommandByProfile(command, profile, taskType) {
231
+ let mode = profile.bashMode ?? 'full';
232
+ if (mode === 'task_scoped') {
233
+ mode = ['implement', 'test', 'refactor', 'integrate', 'deploy', 'document'].includes(taskType ?? '')
234
+ ? 'read_only'
235
+ : 'disabled';
236
+ }
237
+ const decision = evaluateBashPolicy(command, mode, profile.bashWriteProtection ?? 'off');
238
+ return { allowed: decision.allowed, reason: decision.reason };
239
+ }
240
+ export function mergeApprovalScopeWithProfile(scope, profile) {
241
+ return {
242
+ autoApprove: [...new Set([...(scope.autoApprove ?? []), ...(profile.approval?.autoApprove ?? [])])],
243
+ scopedApprove: { ...(scope.scopedApprove ?? {}), ...(profile.approval?.scopedApprove ?? {}) },
244
+ requireApproval: [...new Set([...(scope.requireApproval ?? []), ...(profile.approval?.requireApproval ?? [])])],
245
+ };
246
+ }
247
+ //# sourceMappingURL=policy-engine.js.map