@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
@@ -116,7 +116,12 @@ function hasCredentialAnchors(text) {
116
116
  text.includes("_TOKEN=") || // ACCESS_TOKEN=, AUTH_TOKEN=, ...
117
117
  text.includes("_SECRET=") || // API_SECRET=, CLIENT_SECRET=, ...
118
118
  text.includes("_PASSWORD=") || // DB_PASSWORD=, ROOT_PASSWORD=, ...
119
- text.includes("mongodb://") || text.includes("mongodb+srv://") || text.includes("postgres://") || text.includes("postgresql://") || text.includes("mysql://") || text.includes("redis://");
119
+ text.includes("mongodb://") || text.includes("mongodb+srv://") || text.includes("postgres://") || text.includes("postgresql://") || text.includes("mysql://") || text.includes("redis://") || // JSON-style credential keys: tool outputs often serialise objects as
120
+ // raw JSON strings rather than parsed objects. The value may not start
121
+ // with a recognisable prefix (sk-, ghp_, etc.), so we anchor on common
122
+ // key names. The `"` prefix avoids matching prose that happens to mention
123
+ // these words — JSON serialisation always quotes string keys.
124
+ text.includes('"apiKey"') || text.includes('"api_key"') || text.includes('"token"') || text.includes('"secret"') || text.includes('"password"') || text.includes('"authorization"') || text.includes('"bearer"') || text.includes('"private_key"') || text.includes('"access_token"') || text.includes('"refresh_token"') || text.includes('"client_secret"');
120
125
  }
121
126
  var DefaultSecretScrubber = class {
122
127
  scrub(text) {
@@ -612,7 +617,7 @@ function walk(node, vault, transform) {
612
617
  }
613
618
  return out;
614
619
  }
615
- var SECRET_KEY_PATTERN = /(?:apikey|api_key|authtoken|auth_token|bearer|secret|password|passwd|pwd|refreshtoken|refresh_token|sessionkey|session_key|access[_-]?token|private[_-]?key)/i;
620
+ var SECRET_KEY_PATTERN = /(?:apikey|api_key|authtoken|auth_token|bearer|secret|password|passwd|pwd|refreshtoken|refresh_token|sessionkey|session_key|access[_-]?token|private[_-]?key|token\b)/i;
616
621
  var NON_SECRET_OVERRIDES = /* @__PURE__ */ new Set(["publickey", "public_key"]);
617
622
  function isSecretField(name) {
618
623
  const lc = name.toLowerCase();
@@ -705,31 +710,40 @@ function unwrapDataKey(buf, keyFile) {
705
710
  });
706
711
  }
707
712
  }
708
- function checkKeyFilePermissions(keyFile) {
713
+ function checkKeyFilePermissions(keyFile, opts) {
709
714
  if (process.platform === "win32") return;
715
+ const warn = opts?.warn ?? ((msg) => console.warn(msg));
710
716
  try {
711
717
  const stat2 = fs2.statSync(keyFile);
712
718
  const actualMode = stat2.mode & 511;
713
719
  if (actualMode !== KEY_FILE_MODE) {
714
- console.warn(JSON.stringify({
715
- level: "warn",
716
- event: "vault.key_file_wrong_permissions",
717
- message: `Key file ${keyFile} has mode ${actualMode.toString(8)} \u2014 expected ${KEY_FILE_MODE.toString(8)}. Run: chmod ${KEY_FILE_MODE.toString(8)} ${keyFile}`,
718
- keyFile,
719
- expectedMode: KEY_FILE_MODE,
720
- actualMode,
721
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
722
- }));
720
+ warn(
721
+ `Key file ${keyFile} has mode ${actualMode.toString(8)} \u2014 expected ${KEY_FILE_MODE.toString(8)}. Run: chmod ${KEY_FILE_MODE.toString(8)} ${keyFile}`
722
+ );
723
723
  }
724
724
  } catch {
725
725
  }
726
726
  }
727
727
  var DefaultSecretVault = class {
728
728
  keyFile;
729
+ logger;
729
730
  key;
730
731
  _keyVersion = 1;
731
732
  constructor(opts) {
732
733
  this.keyFile = opts.keyFile;
734
+ this.logger = opts.logger;
735
+ }
736
+ /**
737
+ * Emit a structured warning. Uses the configured Logger when available;
738
+ * falls back to console.warn(JSON) so warnings are never silently dropped
739
+ * during early boot.
740
+ */
741
+ logWarn(msg, ctx) {
742
+ if (this.logger) {
743
+ this.logger.warn(msg, ctx);
744
+ } else {
745
+ console.warn(JSON.stringify({ ...ctx, message: msg, timestamp: (/* @__PURE__ */ new Date()).toISOString() }));
746
+ }
733
747
  }
734
748
  /** Current key version. Starts at 1; incremented by rotateKey(). */
735
749
  get keyVersion() {
@@ -808,7 +822,7 @@ var DefaultSecretVault = class {
808
822
  newKey.copy(keyFileBuf, KEY_FILE_MAGIC.length + 1);
809
823
  fs2.writeFileSync(this.keyFile, keyFileBuf, { mode: 384 });
810
824
  }
811
- checkKeyFilePermissions(this.keyFile);
825
+ checkKeyFilePermissions(this.keyFile, { warn: (msg) => this.logWarn(msg) });
812
826
  this.key = newKey;
813
827
  this._keyVersion = newVersion;
814
828
  return { oldVersion, newVersion };
@@ -827,7 +841,7 @@ var DefaultSecretVault = class {
827
841
  fs2.writeFileSync(this.keyFile, wrapDataKey(this.key, this._keyVersion, passphrase), {
828
842
  mode: 384
829
843
  });
830
- checkKeyFilePermissions(this.keyFile);
844
+ checkKeyFilePermissions(this.keyFile, { warn: (msg) => this.logWarn(msg) });
831
845
  } catch {
832
846
  }
833
847
  }
@@ -839,13 +853,13 @@ var DefaultSecretVault = class {
839
853
  const { key: key2, version } = unwrapDataKey(buf, this.keyFile);
840
854
  this.key = key2;
841
855
  this._keyVersion = version;
842
- checkKeyFilePermissions(this.keyFile);
856
+ checkKeyFilePermissions(this.keyFile, { warn: (msg) => this.logWarn(msg) });
843
857
  return this.key;
844
858
  }
845
859
  if (buf.length === KEY_BYTES) {
846
860
  this.key = buf;
847
861
  this._keyVersion = 1;
848
- checkKeyFilePermissions(this.keyFile);
862
+ checkKeyFilePermissions(this.keyFile, { warn: (msg) => this.logWarn(msg) });
849
863
  this.migrateToWrappedIfPassphrase();
850
864
  return this.key;
851
865
  }
@@ -869,7 +883,7 @@ var DefaultSecretVault = class {
869
883
  }
870
884
  this.key = Buffer.from(key2);
871
885
  this._keyVersion = version;
872
- checkKeyFilePermissions(this.keyFile);
886
+ checkKeyFilePermissions(this.keyFile, { warn: (msg) => this.logWarn(msg) });
873
887
  this.migrateToWrappedIfPassphrase();
874
888
  return this.key;
875
889
  }
@@ -894,13 +908,13 @@ var DefaultSecretVault = class {
894
908
  const { key: winnerKey, version } = unwrapDataKey(buf, this.keyFile);
895
909
  this.key = winnerKey;
896
910
  this._keyVersion = version;
897
- checkKeyFilePermissions(this.keyFile);
911
+ checkKeyFilePermissions(this.keyFile, { warn: (msg) => this.logWarn(msg) });
898
912
  return this.key;
899
913
  }
900
914
  if (buf.length === KEY_BYTES) {
901
915
  this.key = buf;
902
916
  this._keyVersion = 1;
903
- checkKeyFilePermissions(this.keyFile);
917
+ checkKeyFilePermissions(this.keyFile, { warn: (msg) => this.logWarn(msg) });
904
918
  return this.key;
905
919
  }
906
920
  if (buf.length === VERSIONED_KEY_FILE_SIZE) {
@@ -916,7 +930,7 @@ var DefaultSecretVault = class {
916
930
  const winnerKey = buf.subarray(KEY_FILE_MAGIC.length + 1);
917
931
  this.key = Buffer.from(winnerKey);
918
932
  this._keyVersion = version;
919
- checkKeyFilePermissions(this.keyFile);
933
+ checkKeyFilePermissions(this.keyFile, { warn: (msg) => this.logWarn(msg) });
920
934
  return this.key;
921
935
  }
922
936
  throw new ConfigError({
@@ -1207,6 +1221,173 @@ function getDangerousCapabilities(toolOrCaps) {
1207
1221
  );
1208
1222
  }
1209
1223
 
1224
+ // src/security/permission-policy-schema.ts
1225
+ var TRUST_POLICY_SCHEMA_VERSION = 1;
1226
+ var TRUST_POLICY_LIMITS = Object.freeze({
1227
+ maxTools: 1e3,
1228
+ maxPatternsPerRule: 1e3,
1229
+ maxToolNameChars: 256,
1230
+ maxPatternChars: 4096
1231
+ });
1232
+ var TRUST_POLICY_JSON_SCHEMA = Object.freeze({
1233
+ $schema: "https://json-schema.org/draft/2020-12/schema",
1234
+ $id: "https://wrongstack.dev/schemas/trust-policy-v1.json",
1235
+ title: "WrongStack Trust Policy",
1236
+ type: "object",
1237
+ maxProperties: TRUST_POLICY_LIMITS.maxTools,
1238
+ propertyNames: {
1239
+ minLength: 1,
1240
+ maxLength: TRUST_POLICY_LIMITS.maxToolNameChars,
1241
+ not: { enum: ["__proto__", "prototype", "constructor"] }
1242
+ },
1243
+ additionalProperties: {
1244
+ type: "object",
1245
+ additionalProperties: false,
1246
+ properties: {
1247
+ allow: {
1248
+ type: "array",
1249
+ maxItems: TRUST_POLICY_LIMITS.maxPatternsPerRule,
1250
+ items: { type: "string", minLength: 1, maxLength: TRUST_POLICY_LIMITS.maxPatternChars }
1251
+ },
1252
+ deny: {
1253
+ type: "array",
1254
+ maxItems: TRUST_POLICY_LIMITS.maxPatternsPerRule,
1255
+ items: { type: "string", minLength: 1, maxLength: TRUST_POLICY_LIMITS.maxPatternChars }
1256
+ },
1257
+ auto: { type: "boolean" },
1258
+ trustWorkdir: { type: "boolean" },
1259
+ denyPrivate: { type: "boolean" }
1260
+ }
1261
+ }
1262
+ });
1263
+ var RULE_FIELDS = /* @__PURE__ */ new Set(["allow", "deny", "auto", "trustWorkdir", "denyPrivate"]);
1264
+ var UNSAFE_PROPERTY_NAMES = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
1265
+ function isRecord(value) {
1266
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1267
+ }
1268
+ function error(diagnostics, code, path3, message) {
1269
+ diagnostics.push({ severity: "error", code, path: path3, message });
1270
+ }
1271
+ function validatePatterns(value, path3, diagnostics) {
1272
+ if (!Array.isArray(value)) {
1273
+ error(diagnostics, "invalid_pattern_list", path3, "must be an array of strings");
1274
+ return void 0;
1275
+ }
1276
+ if (value.length > TRUST_POLICY_LIMITS.maxPatternsPerRule) {
1277
+ error(
1278
+ diagnostics,
1279
+ "too_many_patterns",
1280
+ path3,
1281
+ `must contain at most ${TRUST_POLICY_LIMITS.maxPatternsPerRule} patterns`
1282
+ );
1283
+ return void 0;
1284
+ }
1285
+ const patterns = [];
1286
+ const seen = /* @__PURE__ */ new Set();
1287
+ for (const [index, pattern] of value.entries()) {
1288
+ const itemPath = `${path3}[${index}]`;
1289
+ if (typeof pattern !== "string" || pattern.length === 0 || pattern.length > TRUST_POLICY_LIMITS.maxPatternChars) {
1290
+ error(
1291
+ diagnostics,
1292
+ "invalid_pattern",
1293
+ itemPath,
1294
+ `must be a non-empty string up to ${TRUST_POLICY_LIMITS.maxPatternChars} characters`
1295
+ );
1296
+ continue;
1297
+ }
1298
+ if (seen.has(pattern)) {
1299
+ diagnostics.push({
1300
+ severity: "warning",
1301
+ code: "duplicate_pattern",
1302
+ path: itemPath,
1303
+ message: "duplicates an earlier pattern and was normalized away"
1304
+ });
1305
+ continue;
1306
+ }
1307
+ seen.add(pattern);
1308
+ patterns.push(pattern);
1309
+ }
1310
+ return patterns;
1311
+ }
1312
+ function validateTrustPolicy(value) {
1313
+ const diagnostics = [];
1314
+ if (!isRecord(value)) {
1315
+ return {
1316
+ ok: false,
1317
+ diagnostics: [
1318
+ {
1319
+ severity: "error",
1320
+ code: "invalid_root",
1321
+ path: "$",
1322
+ message: "trust policy must be an object"
1323
+ }
1324
+ ]
1325
+ };
1326
+ }
1327
+ const entries = Object.entries(value);
1328
+ if (entries.length > TRUST_POLICY_LIMITS.maxTools) {
1329
+ error(
1330
+ diagnostics,
1331
+ "too_many_tools",
1332
+ "$",
1333
+ `must contain at most ${TRUST_POLICY_LIMITS.maxTools} tool rules`
1334
+ );
1335
+ }
1336
+ const policy = {};
1337
+ for (const [toolName, rawRule] of entries.slice(0, TRUST_POLICY_LIMITS.maxTools)) {
1338
+ const toolPath = `$[${JSON.stringify(toolName)}]`;
1339
+ if (toolName.length === 0 || toolName.length > TRUST_POLICY_LIMITS.maxToolNameChars) {
1340
+ error(
1341
+ diagnostics,
1342
+ "invalid_tool_name",
1343
+ toolPath,
1344
+ `tool name must be 1-${TRUST_POLICY_LIMITS.maxToolNameChars} characters`
1345
+ );
1346
+ continue;
1347
+ }
1348
+ if (UNSAFE_PROPERTY_NAMES.has(toolName)) {
1349
+ error(
1350
+ diagnostics,
1351
+ "unsafe_tool_name",
1352
+ toolPath,
1353
+ "reserved object property names are not valid tool rules"
1354
+ );
1355
+ continue;
1356
+ }
1357
+ if (!isRecord(rawRule)) {
1358
+ error(diagnostics, "invalid_rule", toolPath, "tool rule must be an object");
1359
+ continue;
1360
+ }
1361
+ for (const field of Object.keys(rawRule)) {
1362
+ if (!RULE_FIELDS.has(field)) {
1363
+ error(
1364
+ diagnostics,
1365
+ "unknown_field",
1366
+ `${toolPath}.${field}`,
1367
+ `unknown policy field "${field}"`
1368
+ );
1369
+ }
1370
+ }
1371
+ const rule = {};
1372
+ for (const field of ["allow", "deny"]) {
1373
+ if (rawRule[field] === void 0) continue;
1374
+ const patterns = validatePatterns(rawRule[field], `${toolPath}.${field}`, diagnostics);
1375
+ if (patterns) rule[field] = patterns;
1376
+ }
1377
+ for (const field of ["auto", "trustWorkdir", "denyPrivate"]) {
1378
+ const setting = rawRule[field];
1379
+ if (setting === void 0) continue;
1380
+ if (typeof setting !== "boolean") {
1381
+ error(diagnostics, "invalid_boolean", `${toolPath}.${field}`, "must be a boolean");
1382
+ } else {
1383
+ rule[field] = setting;
1384
+ }
1385
+ }
1386
+ policy[toolName] = rule;
1387
+ }
1388
+ return diagnostics.some((diagnostic) => diagnostic.severity === "error") ? { ok: false, diagnostics } : { ok: true, policy, diagnostics };
1389
+ }
1390
+
1210
1391
  // src/utils/lru-cache.ts
1211
1392
  var LruCache = class {
1212
1393
  store = /* @__PURE__ */ new Map();
@@ -1375,6 +1556,8 @@ var DefaultPermissionPolicy = class {
1375
1556
  * the LRU evicts the least-recently-used entries first.
1376
1557
  */
1377
1558
  _evalCache = new LruCache(500);
1559
+ policyDiagnostics = [];
1560
+ policyInvalid = false;
1378
1561
  constructor(opts) {
1379
1562
  this.trustFile = opts.trustFile;
1380
1563
  this.yolo = opts.yolo ?? false;
@@ -1418,13 +1601,50 @@ var DefaultPermissionPolicy = class {
1418
1601
  getConfirmDestructive() {
1419
1602
  return this.confirmDestructive;
1420
1603
  }
1604
+ /** Read-only diagnostics for policy inspector/editor surfaces. */
1605
+ getPolicyDiagnostics() {
1606
+ return this.policyDiagnostics.map((diagnostic) => ({ ...diagnostic }));
1607
+ }
1421
1608
  async reload() {
1609
+ this.policyDiagnostics = [];
1610
+ this.policyInvalid = false;
1422
1611
  try {
1423
1612
  const raw = await fs3.readFile(this.trustFile, "utf8");
1424
1613
  const parsed = safeParse(raw);
1425
- if (parsed.ok && parsed.value) this.policy = parsed.value;
1426
- } catch {
1614
+ if (!parsed.ok) {
1615
+ this.policy = {};
1616
+ this.policyInvalid = true;
1617
+ this.policyDiagnostics = [
1618
+ {
1619
+ severity: "error",
1620
+ code: "invalid_json",
1621
+ path: "$",
1622
+ message: parsed.error ?? "trust policy is not valid JSON"
1623
+ }
1624
+ ];
1625
+ } else {
1626
+ const validation = validateTrustPolicy(parsed.value);
1627
+ this.policyDiagnostics = validation.diagnostics;
1628
+ if (validation.ok) {
1629
+ this.policy = validation.policy;
1630
+ } else {
1631
+ this.policy = {};
1632
+ this.policyInvalid = true;
1633
+ }
1634
+ }
1635
+ } catch (err) {
1427
1636
  this.policy = {};
1637
+ if (err.code !== "ENOENT") {
1638
+ this.policyInvalid = true;
1639
+ this.policyDiagnostics = [
1640
+ {
1641
+ severity: "error",
1642
+ code: "read_error",
1643
+ path: "$",
1644
+ message: err instanceof Error ? err.message : String(err)
1645
+ }
1646
+ ];
1647
+ }
1428
1648
  }
1429
1649
  this.wildcardEntries = [];
1430
1650
  for (const [key, val] of Object.entries(this.policy)) {
@@ -1437,6 +1657,13 @@ var DefaultPermissionPolicy = class {
1437
1657
  }
1438
1658
  async evaluate(tool, input, ctx) {
1439
1659
  if (!this.loaded) await this.reload();
1660
+ if (this.policyInvalid) {
1661
+ return {
1662
+ permission: "deny",
1663
+ source: "deny",
1664
+ reason: "trust policy is invalid; refusing tool execution until it is repaired"
1665
+ };
1666
+ }
1440
1667
  const namespaceEntry = this.findNamespaceEntry(tool.name);
1441
1668
  const entry = this.policy[tool.name] ?? namespaceEntry;
1442
1669
  const subject = subjectForToolInput(tool.name, input, tool.subjectKey);
@@ -1566,6 +1793,9 @@ var DefaultPermissionPolicy = class {
1566
1793
  }
1567
1794
  async trust(rule) {
1568
1795
  if (!this.loaded) await this.reload();
1796
+ if (this.policyInvalid) {
1797
+ throw new Error("Cannot update trust rules while trust.json is invalid; repair it first.");
1798
+ }
1569
1799
  const entry = this.policy[rule.tool] ?? {};
1570
1800
  entry.allow = Array.from(/* @__PURE__ */ new Set([...entry.allow ?? [], rule.pattern]));
1571
1801
  this.policy[rule.tool] = entry;
@@ -1584,6 +1814,9 @@ var DefaultPermissionPolicy = class {
1584
1814
  /** Persist a deny rule — this tool+pattern pair is permanently blocked. */
1585
1815
  async deny(rule) {
1586
1816
  if (!this.loaded) await this.reload();
1817
+ if (this.policyInvalid) {
1818
+ throw new Error("Cannot update deny rules while trust.json is invalid; repair it first.");
1819
+ }
1587
1820
  const entry = this.policy[rule.tool] ?? {};
1588
1821
  entry.deny = Array.from(/* @__PURE__ */ new Set([...entry.deny ?? [], rule.pattern]));
1589
1822
  this.policy[rule.tool] = entry;
@@ -1663,6 +1896,9 @@ export {
1663
1896
  DefaultPermissionPolicy,
1664
1897
  DefaultSecretScrubber,
1665
1898
  DefaultSecretVault,
1899
+ TRUST_POLICY_JSON_SCHEMA,
1900
+ TRUST_POLICY_LIMITS,
1901
+ TRUST_POLICY_SCHEMA_VERSION,
1666
1902
  ToolCapabilities,
1667
1903
  decryptConfigSecrets,
1668
1904
  encryptConfigSecrets,
@@ -1672,6 +1908,7 @@ export {
1672
1908
  isSecretField,
1673
1909
  migratePlaintextSecrets,
1674
1910
  rewriteConfigEncrypted,
1675
- rotateConfigKeys
1911
+ rotateConfigKeys,
1912
+ validateTrustPolicy
1676
1913
  };
1677
1914
  //# sourceMappingURL=index.js.map