@claude-flow/cli 3.32.29 → 3.32.30

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 (372) hide show
  1. package/.claude/helpers/helpers.manifest.json +2 -2
  2. package/catalog-manifest.json +2 -2
  3. package/dist/src/init/claudemd-generator.js +53 -2
  4. package/dist/src/mcp-tools/capability-brain.js +22 -22
  5. package/dist/src/mcp-tools/guidance-tools.js +1 -1
  6. package/node_modules/@claude-flow/codex/.agents/skills/memory-management/SKILL.md +45 -0
  7. package/node_modules/@claude-flow/codex/.agents/skills/security-audit/SKILL.md +46 -0
  8. package/node_modules/@claude-flow/codex/.agents/skills/sparc-methodology/SKILL.md +46 -0
  9. package/node_modules/@claude-flow/codex/.agents/skills/swarm-orchestration/SKILL.md +53 -0
  10. package/node_modules/@claude-flow/codex/README.md +1044 -0
  11. package/node_modules/@claude-flow/codex/dist/cli.d.ts +9 -0
  12. package/node_modules/@claude-flow/codex/dist/cli.d.ts.map +1 -0
  13. package/node_modules/@claude-flow/codex/dist/cli.js +686 -0
  14. package/node_modules/@claude-flow/codex/dist/cli.js.map +1 -0
  15. package/node_modules/@claude-flow/codex/dist/dual-mode/cli.d.ts +17 -0
  16. package/node_modules/@claude-flow/codex/dist/dual-mode/cli.d.ts.map +1 -0
  17. package/node_modules/@claude-flow/codex/dist/dual-mode/cli.js +278 -0
  18. package/node_modules/@claude-flow/codex/dist/dual-mode/cli.js.map +1 -0
  19. package/node_modules/@claude-flow/codex/dist/dual-mode/index.d.ts +8 -0
  20. package/node_modules/@claude-flow/codex/dist/dual-mode/index.d.ts.map +1 -0
  21. package/node_modules/@claude-flow/codex/dist/dual-mode/index.js +7 -0
  22. package/node_modules/@claude-flow/codex/dist/dual-mode/index.js.map +1 -0
  23. package/node_modules/@claude-flow/codex/dist/dual-mode/orchestrator.d.ts +143 -0
  24. package/node_modules/@claude-flow/codex/dist/dual-mode/orchestrator.d.ts.map +1 -0
  25. package/node_modules/@claude-flow/codex/dist/dual-mode/orchestrator.js +621 -0
  26. package/node_modules/@claude-flow/codex/dist/dual-mode/orchestrator.js.map +1 -0
  27. package/node_modules/@claude-flow/codex/dist/generators/agents-md.d.ts +12 -0
  28. package/node_modules/@claude-flow/codex/dist/generators/agents-md.d.ts.map +1 -0
  29. package/node_modules/@claude-flow/codex/dist/generators/agents-md.js +730 -0
  30. package/node_modules/@claude-flow/codex/dist/generators/agents-md.js.map +1 -0
  31. package/node_modules/@claude-flow/codex/dist/generators/config-toml.d.ts +74 -0
  32. package/node_modules/@claude-flow/codex/dist/generators/config-toml.d.ts.map +1 -0
  33. package/node_modules/@claude-flow/codex/dist/generators/config-toml.js +922 -0
  34. package/node_modules/@claude-flow/codex/dist/generators/config-toml.js.map +1 -0
  35. package/node_modules/@claude-flow/codex/dist/generators/index.d.ts +9 -0
  36. package/node_modules/@claude-flow/codex/dist/generators/index.d.ts.map +1 -0
  37. package/node_modules/@claude-flow/codex/dist/generators/index.js +9 -0
  38. package/node_modules/@claude-flow/codex/dist/generators/index.js.map +1 -0
  39. package/node_modules/@claude-flow/codex/dist/generators/skill-md.d.ts +20 -0
  40. package/node_modules/@claude-flow/codex/dist/generators/skill-md.d.ts.map +1 -0
  41. package/node_modules/@claude-flow/codex/dist/generators/skill-md.js +951 -0
  42. package/node_modules/@claude-flow/codex/dist/generators/skill-md.js.map +1 -0
  43. package/node_modules/@claude-flow/codex/dist/harness/build-evidence.d.ts +46 -0
  44. package/node_modules/@claude-flow/codex/dist/harness/build-evidence.d.ts.map +1 -0
  45. package/node_modules/@claude-flow/codex/dist/harness/build-evidence.js +126 -0
  46. package/node_modules/@claude-flow/codex/dist/harness/build-evidence.js.map +1 -0
  47. package/node_modules/@claude-flow/codex/dist/harness/contract.d.ts +153 -0
  48. package/node_modules/@claude-flow/codex/dist/harness/contract.d.ts.map +1 -0
  49. package/node_modules/@claude-flow/codex/dist/harness/contract.js +44 -0
  50. package/node_modules/@claude-flow/codex/dist/harness/contract.js.map +1 -0
  51. package/node_modules/@claude-flow/codex/dist/harness/in-memory-fenced-lease-reference.d.ts +33 -0
  52. package/node_modules/@claude-flow/codex/dist/harness/in-memory-fenced-lease-reference.d.ts.map +1 -0
  53. package/node_modules/@claude-flow/codex/dist/harness/in-memory-fenced-lease-reference.js +175 -0
  54. package/node_modules/@claude-flow/codex/dist/harness/in-memory-fenced-lease-reference.js.map +1 -0
  55. package/node_modules/@claude-flow/codex/dist/harness/in-memory-inbox-reference.d.ts +42 -0
  56. package/node_modules/@claude-flow/codex/dist/harness/in-memory-inbox-reference.d.ts.map +1 -0
  57. package/node_modules/@claude-flow/codex/dist/harness/in-memory-inbox-reference.js +140 -0
  58. package/node_modules/@claude-flow/codex/dist/harness/in-memory-inbox-reference.js.map +1 -0
  59. package/node_modules/@claude-flow/codex/dist/harness/in-memory-run-receipt-reference.d.ts +19 -0
  60. package/node_modules/@claude-flow/codex/dist/harness/in-memory-run-receipt-reference.d.ts.map +1 -0
  61. package/node_modules/@claude-flow/codex/dist/harness/in-memory-run-receipt-reference.js +79 -0
  62. package/node_modules/@claude-flow/codex/dist/harness/in-memory-run-receipt-reference.js.map +1 -0
  63. package/node_modules/@claude-flow/codex/dist/harness/index.d.ts +9 -0
  64. package/node_modules/@claude-flow/codex/dist/harness/index.d.ts.map +1 -0
  65. package/node_modules/@claude-flow/codex/dist/harness/index.js +9 -0
  66. package/node_modules/@claude-flow/codex/dist/harness/index.js.map +1 -0
  67. package/node_modules/@claude-flow/codex/dist/harness/portable-case-fold.d.ts +8 -0
  68. package/node_modules/@claude-flow/codex/dist/harness/portable-case-fold.d.ts.map +1 -0
  69. package/node_modules/@claude-flow/codex/dist/harness/portable-case-fold.js +10 -0
  70. package/node_modules/@claude-flow/codex/dist/harness/portable-case-fold.js.map +1 -0
  71. package/node_modules/@claude-flow/codex/dist/harness/repository-state.d.ts +68 -0
  72. package/node_modules/@claude-flow/codex/dist/harness/repository-state.d.ts.map +1 -0
  73. package/node_modules/@claude-flow/codex/dist/harness/repository-state.js +403 -0
  74. package/node_modules/@claude-flow/codex/dist/harness/repository-state.js.map +1 -0
  75. package/node_modules/@claude-flow/codex/dist/harness/unsigned-integer.d.ts +3 -0
  76. package/node_modules/@claude-flow/codex/dist/harness/unsigned-integer.d.ts.map +1 -0
  77. package/node_modules/@claude-flow/codex/dist/harness/unsigned-integer.js +14 -0
  78. package/node_modules/@claude-flow/codex/dist/harness/unsigned-integer.js.map +1 -0
  79. package/node_modules/@claude-flow/codex/dist/index.d.ts +53 -0
  80. package/node_modules/@claude-flow/codex/dist/index.d.ts.map +1 -0
  81. package/node_modules/@claude-flow/codex/dist/index.js +54 -0
  82. package/node_modules/@claude-flow/codex/dist/index.js.map +1 -0
  83. package/node_modules/@claude-flow/codex/dist/initializer.d.ts +98 -0
  84. package/node_modules/@claude-flow/codex/dist/initializer.d.ts.map +1 -0
  85. package/node_modules/@claude-flow/codex/dist/initializer.js +795 -0
  86. package/node_modules/@claude-flow/codex/dist/initializer.js.map +1 -0
  87. package/node_modules/@claude-flow/codex/dist/loop/cli.d.ts +3 -0
  88. package/node_modules/@claude-flow/codex/dist/loop/cli.d.ts.map +1 -0
  89. package/node_modules/@claude-flow/codex/dist/loop/cli.js +123 -0
  90. package/node_modules/@claude-flow/codex/dist/loop/cli.js.map +1 -0
  91. package/node_modules/@claude-flow/codex/dist/loop/index.d.ts +58 -0
  92. package/node_modules/@claude-flow/codex/dist/loop/index.d.ts.map +1 -0
  93. package/node_modules/@claude-flow/codex/dist/loop/index.js +230 -0
  94. package/node_modules/@claude-flow/codex/dist/loop/index.js.map +1 -0
  95. package/node_modules/@claude-flow/codex/dist/mcp-config.d.ts +28 -0
  96. package/node_modules/@claude-flow/codex/dist/mcp-config.d.ts.map +1 -0
  97. package/node_modules/@claude-flow/codex/dist/mcp-config.js +121 -0
  98. package/node_modules/@claude-flow/codex/dist/mcp-config.js.map +1 -0
  99. package/node_modules/@claude-flow/codex/dist/migrations/index.d.ts +114 -0
  100. package/node_modules/@claude-flow/codex/dist/migrations/index.d.ts.map +1 -0
  101. package/node_modules/@claude-flow/codex/dist/migrations/index.js +880 -0
  102. package/node_modules/@claude-flow/codex/dist/migrations/index.js.map +1 -0
  103. package/node_modules/@claude-flow/codex/dist/templates/index.d.ts +92 -0
  104. package/node_modules/@claude-flow/codex/dist/templates/index.d.ts.map +1 -0
  105. package/node_modules/@claude-flow/codex/dist/templates/index.js +284 -0
  106. package/node_modules/@claude-flow/codex/dist/templates/index.js.map +1 -0
  107. package/node_modules/@claude-flow/codex/dist/types.d.ts +240 -0
  108. package/node_modules/@claude-flow/codex/dist/types.d.ts.map +1 -0
  109. package/node_modules/@claude-flow/codex/dist/types.js +8 -0
  110. package/node_modules/@claude-flow/codex/dist/types.js.map +1 -0
  111. package/node_modules/@claude-flow/codex/dist/validators/index.d.ts +42 -0
  112. package/node_modules/@claude-flow/codex/dist/validators/index.d.ts.map +1 -0
  113. package/node_modules/@claude-flow/codex/dist/validators/index.js +929 -0
  114. package/node_modules/@claude-flow/codex/dist/validators/index.js.map +1 -0
  115. package/node_modules/@claude-flow/codex/dist/worktrees/coordinator.d.ts +37 -0
  116. package/node_modules/@claude-flow/codex/dist/worktrees/coordinator.d.ts.map +1 -0
  117. package/node_modules/@claude-flow/codex/dist/worktrees/coordinator.js +137 -0
  118. package/node_modules/@claude-flow/codex/dist/worktrees/coordinator.js.map +1 -0
  119. package/node_modules/@claude-flow/codex/dist/worktrees/index.d.ts +2 -0
  120. package/node_modules/@claude-flow/codex/dist/worktrees/index.d.ts.map +1 -0
  121. package/node_modules/@claude-flow/codex/dist/worktrees/index.js +2 -0
  122. package/node_modules/@claude-flow/codex/dist/worktrees/index.js.map +1 -0
  123. package/node_modules/@claude-flow/codex/package.json +122 -0
  124. package/node_modules/@claude-flow/plugin-agent-federation/README.md +49 -0
  125. package/node_modules/@claude-flow/plugin-agent-federation/dist/a2a/agent-card.d.ts +130 -0
  126. package/node_modules/@claude-flow/plugin-agent-federation/dist/a2a/agent-card.d.ts.map +1 -0
  127. package/node_modules/@claude-flow/plugin-agent-federation/dist/a2a/agent-card.js +239 -0
  128. package/node_modules/@claude-flow/plugin-agent-federation/dist/a2a/agent-card.js.map +1 -0
  129. package/node_modules/@claude-flow/plugin-agent-federation/dist/a2a/consume.d.ts +34 -0
  130. package/node_modules/@claude-flow/plugin-agent-federation/dist/a2a/consume.d.ts.map +1 -0
  131. package/node_modules/@claude-flow/plugin-agent-federation/dist/a2a/consume.js +69 -0
  132. package/node_modules/@claude-flow/plugin-agent-federation/dist/a2a/consume.js.map +1 -0
  133. package/node_modules/@claude-flow/plugin-agent-federation/dist/a2a/well-known.d.ts +46 -0
  134. package/node_modules/@claude-flow/plugin-agent-federation/dist/a2a/well-known.d.ts.map +1 -0
  135. package/node_modules/@claude-flow/plugin-agent-federation/dist/a2a/well-known.js +84 -0
  136. package/node_modules/@claude-flow/plugin-agent-federation/dist/a2a/well-known.js.map +1 -0
  137. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/claim-checker.d.ts +27 -0
  138. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/claim-checker.d.ts.map +1 -0
  139. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/claim-checker.js +46 -0
  140. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/claim-checker.js.map +1 -0
  141. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/federation-breaker-service.d.ts +192 -0
  142. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/federation-breaker-service.d.ts.map +1 -0
  143. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/federation-breaker-service.js +253 -0
  144. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/federation-breaker-service.js.map +1 -0
  145. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/federation-coordinator.d.ts +211 -0
  146. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/federation-coordinator.d.ts.map +1 -0
  147. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/federation-coordinator.js +501 -0
  148. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/federation-coordinator.js.map +1 -0
  149. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-dispatcher.d.ts +114 -0
  150. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-dispatcher.d.ts.map +1 -0
  151. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-dispatcher.js +356 -0
  152. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/inbound-dispatcher.js.map +1 -0
  153. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/policy-engine.d.ts +41 -0
  154. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/policy-engine.d.ts.map +1 -0
  155. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/policy-engine.js +184 -0
  156. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/policy-engine.js.map +1 -0
  157. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/spend-reporter.d.ts +150 -0
  158. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/spend-reporter.d.ts.map +1 -0
  159. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/spend-reporter.js +128 -0
  160. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/spend-reporter.js.map +1 -0
  161. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/trust-evaluator.d.ts +74 -0
  162. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/trust-evaluator.d.ts.map +1 -0
  163. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/trust-evaluator.js +179 -0
  164. package/node_modules/@claude-flow/plugin-agent-federation/dist/application/trust-evaluator.js.map +1 -0
  165. package/node_modules/@claude-flow/plugin-agent-federation/dist/bin.d.ts +13 -0
  166. package/node_modules/@claude-flow/plugin-agent-federation/dist/bin.d.ts.map +1 -0
  167. package/node_modules/@claude-flow/plugin-agent-federation/dist/bin.js +189 -0
  168. package/node_modules/@claude-flow/plugin-agent-federation/dist/bin.js.map +1 -0
  169. package/node_modules/@claude-flow/plugin-agent-federation/dist/cli-commands.d.ts +7 -0
  170. package/node_modules/@claude-flow/plugin-agent-federation/dist/cli-commands.d.ts.map +1 -0
  171. package/node_modules/@claude-flow/plugin-agent-federation/dist/cli-commands.js +317 -0
  172. package/node_modules/@claude-flow/plugin-agent-federation/dist/cli-commands.js.map +1 -0
  173. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/federation-envelope.d.ts +45 -0
  174. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/federation-envelope.d.ts.map +1 -0
  175. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/federation-envelope.js +71 -0
  176. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/federation-envelope.js.map +1 -0
  177. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/federation-node.d.ts +104 -0
  178. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/federation-node.d.ts.map +1 -0
  179. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/federation-node.js +152 -0
  180. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/federation-node.js.map +1 -0
  181. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/federation-session.d.ts +55 -0
  182. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/federation-session.d.ts.map +1 -0
  183. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/federation-session.js +105 -0
  184. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/federation-session.js.map +1 -0
  185. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/trust-level.d.ts +17 -0
  186. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/trust-level.d.ts.map +1 -0
  187. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/trust-level.js +35 -0
  188. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/entities/trust-level.js.map +1 -0
  189. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/audit-service.d.ts +69 -0
  190. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/audit-service.d.ts.map +1 -0
  191. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/audit-service.js +149 -0
  192. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/audit-service.js.map +1 -0
  193. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/discovery-service.d.ts +68 -0
  194. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/discovery-service.d.ts.map +1 -0
  195. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/discovery-service.js +161 -0
  196. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/discovery-service.js.map +1 -0
  197. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/handshake-service.d.ts +58 -0
  198. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/handshake-service.d.ts.map +1 -0
  199. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/handshake-service.js +122 -0
  200. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/handshake-service.js.map +1 -0
  201. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/pii-pipeline-service.d.ts +65 -0
  202. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/pii-pipeline-service.d.ts.map +1 -0
  203. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/pii-pipeline-service.js +208 -0
  204. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/pii-pipeline-service.js.map +1 -0
  205. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/routing-service.d.ts +51 -0
  206. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/routing-service.d.ts.map +1 -0
  207. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/routing-service.js +147 -0
  208. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/routing-service.js.map +1 -0
  209. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/wg-firewall-service.d.ts +71 -0
  210. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/wg-firewall-service.d.ts.map +1 -0
  211. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/wg-firewall-service.js +194 -0
  212. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/wg-firewall-service.js.map +1 -0
  213. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/wg-mesh-service.d.ts +156 -0
  214. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/wg-mesh-service.d.ts.map +1 -0
  215. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/wg-mesh-service.js +292 -0
  216. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/wg-mesh-service.js.map +1 -0
  217. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/wg-witness-service.d.ts +98 -0
  218. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/wg-witness-service.d.ts.map +1 -0
  219. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/wg-witness-service.js +122 -0
  220. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/services/wg-witness-service.js.map +1 -0
  221. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/value-objects/federation-budget.d.ts +89 -0
  222. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/value-objects/federation-budget.d.ts.map +1 -0
  223. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/value-objects/federation-budget.js +165 -0
  224. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/value-objects/federation-budget.js.map +1 -0
  225. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/value-objects/federation-node-state.d.ts +92 -0
  226. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/value-objects/federation-node-state.d.ts.map +1 -0
  227. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/value-objects/federation-node-state.js +100 -0
  228. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/value-objects/federation-node-state.js.map +1 -0
  229. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/value-objects/wg-config.d.ts +70 -0
  230. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/value-objects/wg-config.d.ts.map +1 -0
  231. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/value-objects/wg-config.js +104 -0
  232. package/node_modules/@claude-flow/plugin-agent-federation/dist/domain/value-objects/wg-config.js.map +1 -0
  233. package/node_modules/@claude-flow/plugin-agent-federation/dist/index.d.ts +23 -0
  234. package/node_modules/@claude-flow/plugin-agent-federation/dist/index.d.ts.map +1 -0
  235. package/node_modules/@claude-flow/plugin-agent-federation/dist/index.js +24 -0
  236. package/node_modules/@claude-flow/plugin-agent-federation/dist/index.js.map +1 -0
  237. package/node_modules/@claude-flow/plugin-agent-federation/dist/mcp-tools.d.ts +10 -0
  238. package/node_modules/@claude-flow/plugin-agent-federation/dist/mcp-tools.d.ts.map +1 -0
  239. package/node_modules/@claude-flow/plugin-agent-federation/dist/mcp-tools.js +439 -0
  240. package/node_modules/@claude-flow/plugin-agent-federation/dist/mcp-tools.js.map +1 -0
  241. package/node_modules/@claude-flow/plugin-agent-federation/dist/plugin.d.ts +19 -0
  242. package/node_modules/@claude-flow/plugin-agent-federation/dist/plugin.d.ts.map +1 -0
  243. package/node_modules/@claude-flow/plugin-agent-federation/dist/plugin.js +515 -0
  244. package/node_modules/@claude-flow/plugin-agent-federation/dist/plugin.js.map +1 -0
  245. package/node_modules/@claude-flow/plugin-agent-federation/dist/transport/midstream-aware-loader.d.ts +72 -0
  246. package/node_modules/@claude-flow/plugin-agent-federation/dist/transport/midstream-aware-loader.d.ts.map +1 -0
  247. package/node_modules/@claude-flow/plugin-agent-federation/dist/transport/midstream-aware-loader.js +269 -0
  248. package/node_modules/@claude-flow/plugin-agent-federation/dist/transport/midstream-aware-loader.js.map +1 -0
  249. package/node_modules/@claude-flow/plugin-agent-federation/dist/version.d.ts +3 -0
  250. package/node_modules/@claude-flow/plugin-agent-federation/dist/version.d.ts.map +1 -0
  251. package/node_modules/@claude-flow/plugin-agent-federation/dist/version.js +3 -0
  252. package/node_modules/@claude-flow/plugin-agent-federation/dist/version.js.map +1 -0
  253. package/node_modules/@claude-flow/plugin-agent-federation/package.json +64 -0
  254. package/node_modules/@claude-flow/security/README.md +292 -0
  255. package/node_modules/@claude-flow/security/dist/CVE-REMEDIATION.d.ts +97 -0
  256. package/node_modules/@claude-flow/security/dist/CVE-REMEDIATION.d.ts.map +1 -0
  257. package/node_modules/@claude-flow/security/dist/CVE-REMEDIATION.js +537 -0
  258. package/node_modules/@claude-flow/security/dist/CVE-REMEDIATION.js.map +1 -0
  259. package/node_modules/@claude-flow/security/dist/application/index.d.ts +7 -0
  260. package/node_modules/@claude-flow/security/dist/application/index.d.ts.map +1 -0
  261. package/node_modules/@claude-flow/security/dist/application/index.js +7 -0
  262. package/node_modules/@claude-flow/security/dist/application/index.js.map +1 -0
  263. package/node_modules/@claude-flow/security/dist/application/services/security-application-service.d.ts +71 -0
  264. package/node_modules/@claude-flow/security/dist/application/services/security-application-service.d.ts.map +1 -0
  265. package/node_modules/@claude-flow/security/dist/application/services/security-application-service.js +153 -0
  266. package/node_modules/@claude-flow/security/dist/application/services/security-application-service.js.map +1 -0
  267. package/node_modules/@claude-flow/security/dist/authorization/propagator.d.ts +148 -0
  268. package/node_modules/@claude-flow/security/dist/authorization/propagator.d.ts.map +1 -0
  269. package/node_modules/@claude-flow/security/dist/authorization/propagator.js +182 -0
  270. package/node_modules/@claude-flow/security/dist/authorization/propagator.js.map +1 -0
  271. package/node_modules/@claude-flow/security/dist/credential-generator.d.ts +176 -0
  272. package/node_modules/@claude-flow/security/dist/credential-generator.d.ts.map +1 -0
  273. package/node_modules/@claude-flow/security/dist/credential-generator.js +272 -0
  274. package/node_modules/@claude-flow/security/dist/credential-generator.js.map +1 -0
  275. package/node_modules/@claude-flow/security/dist/domain/entities/security-context.d.ts +68 -0
  276. package/node_modules/@claude-flow/security/dist/domain/entities/security-context.d.ts.map +1 -0
  277. package/node_modules/@claude-flow/security/dist/domain/entities/security-context.js +132 -0
  278. package/node_modules/@claude-flow/security/dist/domain/entities/security-context.js.map +1 -0
  279. package/node_modules/@claude-flow/security/dist/domain/index.d.ts +8 -0
  280. package/node_modules/@claude-flow/security/dist/domain/index.d.ts.map +1 -0
  281. package/node_modules/@claude-flow/security/dist/domain/index.js +8 -0
  282. package/node_modules/@claude-flow/security/dist/domain/index.js.map +1 -0
  283. package/node_modules/@claude-flow/security/dist/domain/services/security-domain-service.d.ts +71 -0
  284. package/node_modules/@claude-flow/security/dist/domain/services/security-domain-service.d.ts.map +1 -0
  285. package/node_modules/@claude-flow/security/dist/domain/services/security-domain-service.js +237 -0
  286. package/node_modules/@claude-flow/security/dist/domain/services/security-domain-service.js.map +1 -0
  287. package/node_modules/@claude-flow/security/dist/index.d.ts +129 -0
  288. package/node_modules/@claude-flow/security/dist/index.d.ts.map +1 -0
  289. package/node_modules/@claude-flow/security/dist/index.js +176 -0
  290. package/node_modules/@claude-flow/security/dist/index.js.map +1 -0
  291. package/node_modules/@claude-flow/security/dist/input-validator.d.ts +306 -0
  292. package/node_modules/@claude-flow/security/dist/input-validator.d.ts.map +1 -0
  293. package/node_modules/@claude-flow/security/dist/input-validator.js +393 -0
  294. package/node_modules/@claude-flow/security/dist/input-validator.js.map +1 -0
  295. package/node_modules/@claude-flow/security/dist/keychain-adapter.d.ts +48 -0
  296. package/node_modules/@claude-flow/security/dist/keychain-adapter.d.ts.map +1 -0
  297. package/node_modules/@claude-flow/security/dist/keychain-adapter.js +0 -0
  298. package/node_modules/@claude-flow/security/dist/keychain-adapter.js.map +1 -0
  299. package/node_modules/@claude-flow/security/dist/mcp-composition-inspector.d.ts +133 -0
  300. package/node_modules/@claude-flow/security/dist/mcp-composition-inspector.d.ts.map +1 -0
  301. package/node_modules/@claude-flow/security/dist/mcp-composition-inspector.js +254 -0
  302. package/node_modules/@claude-flow/security/dist/mcp-composition-inspector.js.map +1 -0
  303. package/node_modules/@claude-flow/security/dist/oauth/browser.d.ts +31 -0
  304. package/node_modules/@claude-flow/security/dist/oauth/browser.d.ts.map +1 -0
  305. package/node_modules/@claude-flow/security/dist/oauth/browser.js +55 -0
  306. package/node_modules/@claude-flow/security/dist/oauth/browser.js.map +1 -0
  307. package/node_modules/@claude-flow/security/dist/oauth/callback-server.d.ts +37 -0
  308. package/node_modules/@claude-flow/security/dist/oauth/callback-server.d.ts.map +1 -0
  309. package/node_modules/@claude-flow/security/dist/oauth/callback-server.js +86 -0
  310. package/node_modules/@claude-flow/security/dist/oauth/callback-server.js.map +1 -0
  311. package/node_modules/@claude-flow/security/dist/oauth/client.d.ts +57 -0
  312. package/node_modules/@claude-flow/security/dist/oauth/client.d.ts.map +1 -0
  313. package/node_modules/@claude-flow/security/dist/oauth/client.js +120 -0
  314. package/node_modules/@claude-flow/security/dist/oauth/client.js.map +1 -0
  315. package/node_modules/@claude-flow/security/dist/oauth/pkce.d.ts +25 -0
  316. package/node_modules/@claude-flow/security/dist/oauth/pkce.d.ts.map +1 -0
  317. package/node_modules/@claude-flow/security/dist/oauth/pkce.js +36 -0
  318. package/node_modules/@claude-flow/security/dist/oauth/pkce.js.map +1 -0
  319. package/node_modules/@claude-flow/security/dist/password-hasher.d.ts +128 -0
  320. package/node_modules/@claude-flow/security/dist/password-hasher.d.ts.map +1 -0
  321. package/node_modules/@claude-flow/security/dist/password-hasher.js +190 -0
  322. package/node_modules/@claude-flow/security/dist/password-hasher.js.map +1 -0
  323. package/node_modules/@claude-flow/security/dist/path-validator.d.ts +148 -0
  324. package/node_modules/@claude-flow/security/dist/path-validator.d.ts.map +1 -0
  325. package/node_modules/@claude-flow/security/dist/path-validator.js +421 -0
  326. package/node_modules/@claude-flow/security/dist/path-validator.js.map +1 -0
  327. package/node_modules/@claude-flow/security/dist/plugins/integrity-verifier.d.ts +125 -0
  328. package/node_modules/@claude-flow/security/dist/plugins/integrity-verifier.d.ts.map +1 -0
  329. package/node_modules/@claude-flow/security/dist/plugins/integrity-verifier.js +186 -0
  330. package/node_modules/@claude-flow/security/dist/plugins/integrity-verifier.js.map +1 -0
  331. package/node_modules/@claude-flow/security/dist/policy/canonical.d.ts +5 -0
  332. package/node_modules/@claude-flow/security/dist/policy/canonical.d.ts.map +1 -0
  333. package/node_modules/@claude-flow/security/dist/policy/canonical.js +30 -0
  334. package/node_modules/@claude-flow/security/dist/policy/canonical.js.map +1 -0
  335. package/node_modules/@claude-flow/security/dist/policy/engine.d.ts +34 -0
  336. package/node_modules/@claude-flow/security/dist/policy/engine.d.ts.map +1 -0
  337. package/node_modules/@claude-flow/security/dist/policy/engine.js +285 -0
  338. package/node_modules/@claude-flow/security/dist/policy/engine.js.map +1 -0
  339. package/node_modules/@claude-flow/security/dist/policy/envelope.d.ts +9 -0
  340. package/node_modules/@claude-flow/security/dist/policy/envelope.d.ts.map +1 -0
  341. package/node_modules/@claude-flow/security/dist/policy/envelope.js +90 -0
  342. package/node_modules/@claude-flow/security/dist/policy/envelope.js.map +1 -0
  343. package/node_modules/@claude-flow/security/dist/policy/evaluator.d.ts +4 -0
  344. package/node_modules/@claude-flow/security/dist/policy/evaluator.d.ts.map +1 -0
  345. package/node_modules/@claude-flow/security/dist/policy/evaluator.js +119 -0
  346. package/node_modules/@claude-flow/security/dist/policy/evaluator.js.map +1 -0
  347. package/node_modules/@claude-flow/security/dist/policy/index.d.ts +7 -0
  348. package/node_modules/@claude-flow/security/dist/policy/index.d.ts.map +1 -0
  349. package/node_modules/@claude-flow/security/dist/policy/index.js +7 -0
  350. package/node_modules/@claude-flow/security/dist/policy/index.js.map +1 -0
  351. package/node_modules/@claude-flow/security/dist/policy/product-plane.d.ts +238 -0
  352. package/node_modules/@claude-flow/security/dist/policy/product-plane.d.ts.map +1 -0
  353. package/node_modules/@claude-flow/security/dist/policy/product-plane.js +1022 -0
  354. package/node_modules/@claude-flow/security/dist/policy/product-plane.js.map +1 -0
  355. package/node_modules/@claude-flow/security/dist/policy/types.d.ts +169 -0
  356. package/node_modules/@claude-flow/security/dist/policy/types.d.ts.map +1 -0
  357. package/node_modules/@claude-flow/security/dist/policy/types.js +2 -0
  358. package/node_modules/@claude-flow/security/dist/policy/types.js.map +1 -0
  359. package/node_modules/@claude-flow/security/dist/safe-executor.d.ts +180 -0
  360. package/node_modules/@claude-flow/security/dist/safe-executor.d.ts.map +1 -0
  361. package/node_modules/@claude-flow/security/dist/safe-executor.js +390 -0
  362. package/node_modules/@claude-flow/security/dist/safe-executor.js.map +1 -0
  363. package/node_modules/@claude-flow/security/dist/token-generator.d.ts +224 -0
  364. package/node_modules/@claude-flow/security/dist/token-generator.d.ts.map +1 -0
  365. package/node_modules/@claude-flow/security/dist/token-generator.js +351 -0
  366. package/node_modules/@claude-flow/security/dist/token-generator.js.map +1 -0
  367. package/node_modules/@claude-flow/security/dist/tool-output-guardrail.d.ts +126 -0
  368. package/node_modules/@claude-flow/security/dist/tool-output-guardrail.d.ts.map +1 -0
  369. package/node_modules/@claude-flow/security/dist/tool-output-guardrail.js +257 -0
  370. package/node_modules/@claude-flow/security/dist/tool-output-guardrail.js.map +1 -0
  371. package/node_modules/@claude-flow/security/package.json +44 -0
  372. package/package.json +24 -8
@@ -0,0 +1,186 @@
1
+ /**
2
+ * PluginIntegrityVerifier — install-layer security for plugin supply chain.
3
+ *
4
+ * Implements P1 of ADR-145 (ruvnet/ruflo#2254): Stage-1 Ed25519 signature
5
+ * verification at `plugins install`. Stage-2 (semantic-intent scan against
6
+ * SCH attacks) lands in P2; per-namespace write ACLs land in P3-P4.
7
+ *
8
+ * Threat model
9
+ * ------------
10
+ * Ruflo's plugin install path fetches manifests from IPFS via Pinata with
11
+ * NO signature verification and NO intent analysis. Two attacks land today:
12
+ *
13
+ * - DDIPE (arXiv:2604.03081): malicious logic embedded in plugin docs and
14
+ * config templates. 11.6-33.5% bypass rate across 4 frameworks/5 models;
15
+ * 2.5% evade both detection and alignment. Stage-1 signing blocks the
16
+ * static-payload variants.
17
+ *
18
+ * - SCH (arXiv:2605.14460): malicious intent wrapped as natural-language
19
+ * "compliance rules" in plugin descriptions. The agent generates the
20
+ * harmful code at runtime — no static payload exists. 77.67% breach
21
+ * success, 0.00% scanner detection. Stage-2 (P2) catches this; Stage-1
22
+ * does not.
23
+ *
24
+ * Scope (P1)
25
+ * ----------
26
+ * - Ed25519 signature verification of a detached signature over the manifest.
27
+ * - Trust-anchor allowlist: the publisher's signing key fingerprint must be
28
+ * in `trust-anchors.json`, gated on CODEOWNERS review.
29
+ * - Backwards compatible: default mode is warn-only. `CLAUDE_FLOW_STRICT_PLUGINS=true`
30
+ * makes verification a hard gate.
31
+ *
32
+ * Non-goals (P1)
33
+ * --------------
34
+ * - Semantic intent scan (SCH defence). Lands in P2 with a pattern-rule
35
+ * fallback for environments without LLM credentials.
36
+ * - Sandboxing the plugin runtime. Orthogonal blast-radius concern.
37
+ *
38
+ * Reference: ADR-145, arXiv:2605.14460 (SCH), arXiv:2604.03081 (DDIPE),
39
+ * arXiv:2604.16548 (Mnemonic Sovereignty survey).
40
+ */
41
+ import { createHash } from 'node:crypto';
42
+ import * as nodeCrypto from 'node:crypto';
43
+ /**
44
+ * Canonical JSON serialisation for hashing. Deterministic key ordering at
45
+ * every nesting level. Pure; identical input → identical output bytes.
46
+ */
47
+ export function canonicalize(value) {
48
+ if (value === null || typeof value !== 'object')
49
+ return JSON.stringify(value);
50
+ if (Array.isArray(value))
51
+ return '[' + value.map(canonicalize).join(',') + ']';
52
+ const obj = value;
53
+ const keys = Object.keys(obj).sort();
54
+ return '{' + keys.map(k => JSON.stringify(k) + ':' + canonicalize(obj[k])).join(',') + '}';
55
+ }
56
+ /** Hex-encoded SHA-256 of the canonical-JSON manifest. */
57
+ export function hashManifest(manifest) {
58
+ return createHash('sha256').update(canonicalize(manifest)).digest('hex');
59
+ }
60
+ /** Short fingerprint for telemetry — first 16 hex chars of the key. */
61
+ export function fingerprint(publicKey) {
62
+ return publicKey.slice(0, 16);
63
+ }
64
+ /**
65
+ * Find the trust anchor that vouches for a manifest. Returns the matched
66
+ * anchor (with anchor.publicKey === signer.publicKey) or null.
67
+ *
68
+ * Scope-matching uses a minimal glob: `*` at the end of the scope string
69
+ * matches any suffix. Empty/missing scope matches every plugin id.
70
+ */
71
+ export function findAnchor(anchors, pluginId, signerPublicKey, now) {
72
+ for (const a of anchors) {
73
+ if (a.publicKey !== signerPublicKey)
74
+ continue;
75
+ if (a.expiresAt && new Date(a.expiresAt).getTime() <= now)
76
+ continue;
77
+ if (!a.scope || a.scope === '*' || a.scope === pluginId)
78
+ return a;
79
+ if (a.scope.endsWith('*') && pluginId.startsWith(a.scope.slice(0, -1)))
80
+ return a;
81
+ }
82
+ return null;
83
+ }
84
+ /**
85
+ * `PluginIntegrityVerifier` — Stage-1 verifier (signature + trust anchor).
86
+ *
87
+ * Pure-ish: holds the trust-anchor list and clock, no other state. Safe to
88
+ * construct per-invocation or share.
89
+ */
90
+ export class PluginIntegrityVerifier {
91
+ config;
92
+ constructor(config) {
93
+ this.config = config;
94
+ }
95
+ /**
96
+ * Verify a signed manifest. Returns the verification status; the caller
97
+ * decides what to do with `signature-missing` / `manifest-hash-mismatch`
98
+ * etc. based on its strict-mode policy.
99
+ */
100
+ async verify(signed) {
101
+ const now = (this.config.now ?? Date.now)();
102
+ const pluginId = signed.manifest?.id ?? '<unknown>';
103
+ if (!signed.signature || !signed.publicKey) {
104
+ return { status: 'signature-missing', pluginId, ts: now };
105
+ }
106
+ // Re-hash the manifest and compare to the signed hash.
107
+ const recomputed = hashManifest(signed.manifest);
108
+ if (recomputed !== signed.manifestHash) {
109
+ return {
110
+ status: 'manifest-hash-mismatch',
111
+ pluginId,
112
+ signerFingerprint: fingerprint(signed.publicKey),
113
+ ts: now,
114
+ detail: `expected ${signed.manifestHash}, got ${recomputed}`,
115
+ };
116
+ }
117
+ // Find a trust anchor that vouches for this signer + plugin.
118
+ const anchor = findAnchor(this.config.trustAnchors.anchors, pluginId, signed.publicKey, now);
119
+ if (!anchor) {
120
+ return {
121
+ status: 'unknown-signer',
122
+ pluginId,
123
+ signerFingerprint: fingerprint(signed.publicKey),
124
+ ts: now,
125
+ };
126
+ }
127
+ // Ed25519 verify. Probe @noble/ed25519 (already a workspace dep); fall
128
+ // back to the failure status if it isn't resolvable in this environment
129
+ // (mirrors verify.mjs's #1880 precondition pattern).
130
+ const ed = await loadEd25519();
131
+ if (!ed) {
132
+ return {
133
+ status: 'signature-invalid',
134
+ pluginId,
135
+ signerFingerprint: fingerprint(signed.publicKey),
136
+ ts: now,
137
+ detail: '@noble/ed25519 not available — cannot verify',
138
+ };
139
+ }
140
+ // Required by @noble/ed25519 v2 for sync sha512.
141
+ if (!ed.etc.sha512Sync) {
142
+ ed.etc.sha512Sync = (...m) => {
143
+ const h = nodeCrypto.createHash('sha512');
144
+ for (const x of m)
145
+ h.update(x);
146
+ return h.digest();
147
+ };
148
+ }
149
+ let ok = false;
150
+ try {
151
+ const sigBytes = hexToBytes(signed.signature);
152
+ const msgBytes = hexToBytes(signed.manifestHash);
153
+ const pubBytes = hexToBytes(signed.publicKey);
154
+ ok = await ed.verify(sigBytes, msgBytes, pubBytes);
155
+ }
156
+ catch {
157
+ ok = false;
158
+ }
159
+ if (!ok) {
160
+ return {
161
+ status: 'signature-invalid',
162
+ pluginId,
163
+ signerFingerprint: fingerprint(signed.publicKey),
164
+ ts: now,
165
+ };
166
+ }
167
+ return { status: 'pass', pluginId, signerFingerprint: fingerprint(signed.publicKey), ts: now };
168
+ }
169
+ }
170
+ // ─── helpers ────────────────────────────────────────────────────────────
171
+ function hexToBytes(hex) {
172
+ const out = new Uint8Array(hex.length >>> 1);
173
+ for (let i = 0; i < out.length; i++)
174
+ out[i] = parseInt(hex.substr(i * 2, 2), 16);
175
+ return out;
176
+ }
177
+ async function loadEd25519() {
178
+ try {
179
+ const mod = await import('@noble/ed25519');
180
+ return mod;
181
+ }
182
+ catch {
183
+ return null;
184
+ }
185
+ }
186
+ //# sourceMappingURL=integrity-verifier.js.map
@@ -0,0 +1 @@
1
+ {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EAAE,EAAE,CAAC,CAAC;IACjF,OAAO,GAAG,CAAC;AACb,CAAC;AAOD,KAAK,UAAU,WAAW;IACxB,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAC3C,OAAO,GAA8B,CAAC;IACxC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare function canonicalizePolicy(value: unknown): string;
2
+ export declare function policyHash(value: unknown): string;
3
+ export declare function signPolicyHash(hash: string, key: string | Buffer): string;
4
+ export declare function verifyPolicySignature(hash: string, signature: string, key: string | Buffer): boolean;
5
+ //# sourceMappingURL=canonical.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../../src/policy/canonical.ts"],"names":[],"mappings":"AAkBA,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEzD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEjD;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAEzE;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAIpG"}
@@ -0,0 +1,30 @@
1
+ import { createHash, createHmac, timingSafeEqual } from 'node:crypto';
2
+ function normalize(value) {
3
+ if (Array.isArray(value))
4
+ return value.map(normalize);
5
+ if (value && typeof value === 'object') {
6
+ return Object.fromEntries(Object.entries(value)
7
+ .filter(([, item]) => item !== undefined)
8
+ .sort(([a], [b]) => a.localeCompare(b))
9
+ .map(([key, item]) => [key, normalize(item)]));
10
+ }
11
+ if (typeof value === 'number' && !Number.isFinite(value)) {
12
+ throw new TypeError('Policy canonicalization rejects non-finite numbers');
13
+ }
14
+ return value;
15
+ }
16
+ export function canonicalizePolicy(value) {
17
+ return JSON.stringify(normalize(value));
18
+ }
19
+ export function policyHash(value) {
20
+ return `sha256:${createHash('sha256').update(canonicalizePolicy(value)).digest('hex')}`;
21
+ }
22
+ export function signPolicyHash(hash, key) {
23
+ return createHmac('sha256', key).update(hash).digest('base64url');
24
+ }
25
+ export function verifyPolicySignature(hash, signature, key) {
26
+ const expected = Buffer.from(signPolicyHash(hash, key));
27
+ const actual = Buffer.from(signature);
28
+ return expected.length === actual.length && timingSafeEqual(expected, actual);
29
+ }
30
+ //# sourceMappingURL=canonical.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.js","sourceRoot":"","sources":["../../src/policy/canonical.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEtE,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACtD,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvC,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC;aAC7C,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC;aACxC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;aACtC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAChD,CAAC;IACJ,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACzD,MAAM,IAAI,SAAS,CAAC,oDAAoD,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,OAAO,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,UAAU,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AAC1F,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,GAAoB;IAC/D,OAAO,UAAU,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IAAY,EAAE,SAAiB,EAAE,GAAoB;IACzF,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;IACxD,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACtC,OAAO,QAAQ,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,IAAI,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAChF,CAAC"}
@@ -0,0 +1,34 @@
1
+ import type { BudgetLimit, PolicyApproval, PolicyDecision, PolicyEngineOptions, PolicyRequest, PolicyRule, PolicyState } from './types.js';
2
+ export declare class AgenticPolicyEngine {
3
+ private readonly now;
4
+ private readonly signingKey?;
5
+ private readonly keyId?;
6
+ private readonly evidenceVerifier?;
7
+ private readonly approvalIssuerVerifier?;
8
+ private state;
9
+ constructor(options?: PolicyEngineOptions);
10
+ static fromState(state: PolicyState, options?: Omit<PolicyEngineOptions, 'mode' | 'rules' | 'budgets' | 'usage' | 'approvals' | 'receipts'>): AgenticPolicyEngine;
11
+ exportState(): PolicyState;
12
+ setMode(mode: PolicyState['mode']): void;
13
+ setConfiguredMode(mode: PolicyState['mode']): void;
14
+ upsertRule(rule: PolicyRule): void;
15
+ setBudget(limit: BudgetLimit): void;
16
+ issueApproval(approval: Omit<PolicyApproval, 'uses' | 'issuedAt'> & {
17
+ uses?: number;
18
+ issuedAt?: number;
19
+ }): PolicyApproval;
20
+ revokeApproval(id: string): boolean;
21
+ evaluate(request: PolicyRequest): PolicyDecision;
22
+ verifyLedger(): {
23
+ valid: boolean;
24
+ length: number;
25
+ error?: string;
26
+ };
27
+ private applyBudget;
28
+ private applyApproval;
29
+ private consumeBudget;
30
+ private appendReceipt;
31
+ private validateRequest;
32
+ }
33
+ export declare function createLegacyCompatibleState(source?: string): PolicyState;
34
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/policy/engine.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,WAAW,EAEX,cAAc,EACd,cAAc,EAEd,mBAAmB,EAEnB,aAAa,EACb,UAAU,EACV,WAAW,EACZ,MAAM,YAAY,CAAC;AASpB,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAkB;IAC9C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAgE;IAClG,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAC,CAA8B;IACtE,OAAO,CAAC,KAAK,CAAc;gBAEf,OAAO,GAAE,mBAAwB;IAiB7C,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,WAAW,EAAE,OAAO,GAAE,IAAI,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,GAAG,WAAW,GAAG,UAAU,CAAM,GAAG,mBAAmB;IAgBrK,WAAW,IAAI,WAAW;IAI1B,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI;IAIxC,iBAAiB,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI;IAMlD,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI;IAgBlC,SAAS,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAWnC,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,UAAU,CAAC,GAAG;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,cAAc;IAmBzH,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAOnC,QAAQ,CAAC,OAAO,EAAE,aAAa,GAAG,cAAc;IAoBhD,YAAY,IAAI;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE;IA0BlE,OAAO,CAAC,WAAW;IA2BnB,OAAO,CAAC,aAAa;IAyBrB,OAAO,CAAC,aAAa;IAkBrB,OAAO,CAAC,aAAa;IAwBrB,OAAO,CAAC,eAAe;CAcxB;AAED,wBAAgB,2BAA2B,CAAC,MAAM,SAAgB,GAAG,WAAW,CAY/E"}
@@ -0,0 +1,285 @@
1
+ import { policyHash, signPolicyHash, verifyPolicySignature } from './canonical.js';
2
+ import { evaluatePolicy } from './evaluator.js';
3
+ import { POLICY_STATE_VERSION } from './types.js';
4
+ function wildcard(pattern, value) {
5
+ if (!pattern)
6
+ return true;
7
+ if (!value)
8
+ return false;
9
+ return pattern === '*' || pattern === value || (pattern.endsWith('*') && value.startsWith(pattern.slice(0, -1)));
10
+ }
11
+ export class AgenticPolicyEngine {
12
+ now;
13
+ signingKey;
14
+ keyId;
15
+ evidenceVerifier;
16
+ approvalIssuerVerifier;
17
+ state;
18
+ constructor(options = {}) {
19
+ this.now = options.now ?? Date.now;
20
+ this.signingKey = options.signingKey;
21
+ this.keyId = options.keyId;
22
+ this.evidenceVerifier = options.evidenceVerifier;
23
+ this.approvalIssuerVerifier = options.approvalIssuerVerifier;
24
+ this.state = {
25
+ version: POLICY_STATE_VERSION,
26
+ mode: options.mode ?? 'legacy',
27
+ rules: [...(options.rules ?? [])],
28
+ budgets: [...(options.budgets ?? [])],
29
+ usage: [...(options.usage ?? [])],
30
+ approvals: [...(options.approvals ?? [])],
31
+ receipts: [...(options.receipts ?? [])],
32
+ };
33
+ }
34
+ static fromState(state, options = {}) {
35
+ const engine = new AgenticPolicyEngine({
36
+ ...options,
37
+ mode: state.mode,
38
+ rules: state.rules,
39
+ budgets: state.budgets,
40
+ usage: state.usage,
41
+ approvals: state.approvals,
42
+ receipts: state.receipts,
43
+ });
44
+ engine.state.migratedAt = state.migratedAt;
45
+ engine.state.migratedFrom = state.migratedFrom;
46
+ engine.state.configuredMode = state.configuredMode;
47
+ return engine;
48
+ }
49
+ exportState() {
50
+ return structuredClone(this.state);
51
+ }
52
+ setMode(mode) {
53
+ this.state.mode = mode;
54
+ }
55
+ setConfiguredMode(mode) {
56
+ this.state.configuredMode = mode;
57
+ const rank = { legacy: 0, observe: 1, enforce: 2 };
58
+ if (rank[mode] > rank[this.state.mode])
59
+ this.state.mode = mode;
60
+ }
61
+ upsertRule(rule) {
62
+ if (!rule.id || !rule.actions.length)
63
+ throw new Error('invalid-policy-rule');
64
+ for (const value of [
65
+ rule.constraints?.maxCostUsd,
66
+ rule.constraints?.maxTokens,
67
+ rule.constraints?.maxConcurrency,
68
+ ]) {
69
+ if (value !== undefined && (!Number.isFinite(value) || value < 0)) {
70
+ throw new Error('invalid-policy-rule-limit');
71
+ }
72
+ }
73
+ const index = this.state.rules.findIndex((item) => item.id === rule.id);
74
+ if (index >= 0)
75
+ this.state.rules[index] = structuredClone(rule);
76
+ else
77
+ this.state.rules.push(structuredClone(rule));
78
+ }
79
+ setBudget(limit) {
80
+ if (limit.periodMs <= 0)
81
+ throw new Error('invalid-budget-period');
82
+ if (!Number.isFinite(limit.periodMs)
83
+ || [limit.maxCostUsd, limit.maxTokens].some((value) => (value !== undefined && (!Number.isFinite(value) || value < 0))))
84
+ throw new Error('invalid-budget-limit');
85
+ const index = this.state.budgets.findIndex((item) => item.id === limit.id);
86
+ if (index >= 0)
87
+ this.state.budgets[index] = structuredClone(limit);
88
+ else
89
+ this.state.budgets.push(structuredClone(limit));
90
+ }
91
+ issueApproval(approval) {
92
+ if (approval.issuedBy === approval.principal)
93
+ throw new Error('self-approval-forbidden');
94
+ if (this.approvalIssuerVerifier?.(approval.issuedBy) !== true) {
95
+ throw new Error('untrusted-approval-issuer');
96
+ }
97
+ const issuedAt = approval.issuedAt ?? this.now();
98
+ const record = { ...approval, issuedAt, uses: approval.uses ?? 0 };
99
+ if (this.state.approvals.some((item) => item.id === record.id))
100
+ throw new Error('duplicate-approval-id');
101
+ if (!record.id
102
+ || record.expiresAt <= issuedAt
103
+ || !Number.isInteger(record.maxUses)
104
+ || record.maxUses <= 0
105
+ || !Number.isInteger(record.uses)
106
+ || record.uses < 0
107
+ || record.uses > record.maxUses)
108
+ throw new Error('invalid-approval');
109
+ this.state.approvals.push(record);
110
+ return structuredClone(record);
111
+ }
112
+ revokeApproval(id) {
113
+ const approval = this.state.approvals.find((item) => item.id === id);
114
+ if (!approval || approval.revokedAt)
115
+ return false;
116
+ approval.revokedAt = this.now();
117
+ return true;
118
+ }
119
+ evaluate(request) {
120
+ const normalized = {
121
+ ...request,
122
+ requestId: request.requestId ?? crypto.randomUUID(),
123
+ // Caller time is evidence only; expiry, budgets, and receipts always use
124
+ // the authority's clock.
125
+ context: { ...request.context, now: this.now() },
126
+ };
127
+ this.validateRequest(normalized);
128
+ const verifiedEvidenceIds = (normalized.context?.evidence ?? [])
129
+ .filter((evidence) => evidence.id && this.evidenceVerifier?.(evidence, normalized) === true)
130
+ .map((evidence) => evidence.id);
131
+ let decision = evaluatePolicy(normalized, this.state.rules, this.state.mode, verifiedEvidenceIds);
132
+ decision = this.applyBudget(normalized, decision);
133
+ decision = this.applyApproval(normalized, decision);
134
+ const receipt = this.appendReceipt(normalized, decision);
135
+ this.consumeBudget(normalized, decision);
136
+ return { ...decision, receiptId: receipt.payload.receiptId };
137
+ }
138
+ verifyLedger() {
139
+ let previous = null;
140
+ for (let i = 0; i < this.state.receipts.length; i++) {
141
+ const receipt = this.state.receipts[i];
142
+ if (receipt.payload.sequence !== i || receipt.payload.previousReceiptHash !== previous) {
143
+ return { valid: false, length: i, error: 'receipt-chain-mismatch' };
144
+ }
145
+ const hash = policyHash(receipt.payload);
146
+ const { receiptId, ...unsignedIdPayload } = receipt.payload;
147
+ if (hash !== receipt.hash || receiptId !== policyHash(unsignedIdPayload)) {
148
+ return { valid: false, length: i, error: 'receipt-hash-mismatch' };
149
+ }
150
+ if (this.signingKey && !receipt.signature) {
151
+ return { valid: false, length: i, error: 'receipt-signature-missing' };
152
+ }
153
+ if (receipt.signature && !this.signingKey) {
154
+ return { valid: false, length: i, error: 'receipt-signing-key-required' };
155
+ }
156
+ if (receipt.signature && this.signingKey && !verifyPolicySignature(hash, receipt.signature, this.signingKey)) {
157
+ return { valid: false, length: i, error: 'receipt-signature-invalid' };
158
+ }
159
+ previous = receipt.hash;
160
+ }
161
+ return { valid: true, length: this.state.receipts.length };
162
+ }
163
+ applyBudget(request, decision) {
164
+ if (decision.outcome === 'denied')
165
+ return decision;
166
+ const now = request.context?.now ?? this.now();
167
+ for (const limit of this.state.budgets) {
168
+ if (!wildcard(limit.principal, request.identity.id)
169
+ || !wildcard(limit.action, request.action.type)
170
+ || !wildcard(limit.resource, request.action.resource))
171
+ continue;
172
+ let usage = this.state.usage.find((item) => item.limitId === limit.id);
173
+ if (!usage || now - usage.windowStartedAt >= limit.periodMs) {
174
+ usage = { limitId: limit.id, windowStartedAt: now, costUsd: 0, tokens: 0 };
175
+ }
176
+ if (limit.maxCostUsd !== undefined && usage.costUsd + (request.action.costUsd ?? 0) > limit.maxCostUsd) {
177
+ return { ...decision, outcome: 'denied', enforcedOutcome: this.state.mode === 'enforce' ? 'denied' : 'allowed', reason: `budget-exceeded:${limit.id}` };
178
+ }
179
+ if (limit.maxCostUsd !== undefined && request.action.costUsd === undefined) {
180
+ return { ...decision, outcome: 'denied', enforcedOutcome: this.state.mode === 'enforce' ? 'denied' : 'allowed', reason: `budget-metering-required:${limit.id}:costUsd` };
181
+ }
182
+ if (limit.maxTokens !== undefined && request.action.tokens === undefined) {
183
+ return { ...decision, outcome: 'denied', enforcedOutcome: this.state.mode === 'enforce' ? 'denied' : 'allowed', reason: `budget-metering-required:${limit.id}:tokens` };
184
+ }
185
+ if (limit.maxTokens !== undefined && usage.tokens + (request.action.tokens ?? 0) > limit.maxTokens) {
186
+ return { ...decision, outcome: 'denied', enforcedOutcome: this.state.mode === 'enforce' ? 'denied' : 'allowed', reason: `budget-exceeded:${limit.id}` };
187
+ }
188
+ }
189
+ return decision;
190
+ }
191
+ applyApproval(request, decision) {
192
+ if (decision.outcome !== 'approval_required')
193
+ return decision;
194
+ const now = request.context?.now ?? this.now();
195
+ const ids = new Set(request.context?.approvalIds ?? []);
196
+ const approval = this.state.approvals.find((item) => (ids.has(item.id)
197
+ && !item.revokedAt
198
+ && item.expiresAt > now
199
+ && item.uses < item.maxUses
200
+ && wildcard(item.principal, request.identity.id)
201
+ && item.actions.some((action) => wildcard(action, request.action.type))
202
+ && (!item.resources?.length || item.resources.some((resource) => wildcard(resource, request.action.resource)))));
203
+ if (!approval)
204
+ return decision;
205
+ approval.uses += 1;
206
+ return {
207
+ ...decision,
208
+ outcome: 'allowed',
209
+ enforcedOutcome: 'allowed',
210
+ reason: `approved-by:${approval.id}`,
211
+ approvalId: approval.id,
212
+ obligations: [],
213
+ };
214
+ }
215
+ consumeBudget(request, decision) {
216
+ if (decision.enforcedOutcome !== 'allowed')
217
+ return;
218
+ const now = request.context?.now ?? this.now();
219
+ for (const limit of this.state.budgets) {
220
+ if (!wildcard(limit.principal, request.identity.id)
221
+ || !wildcard(limit.action, request.action.type)
222
+ || !wildcard(limit.resource, request.action.resource))
223
+ continue;
224
+ let usage = this.state.usage.find((item) => item.limitId === limit.id);
225
+ if (!usage || now - usage.windowStartedAt >= limit.periodMs) {
226
+ usage = { limitId: limit.id, windowStartedAt: now, costUsd: 0, tokens: 0 };
227
+ this.state.usage = this.state.usage.filter((item) => item.limitId !== limit.id);
228
+ this.state.usage.push(usage);
229
+ }
230
+ usage.costUsd += request.action.costUsd ?? 0;
231
+ usage.tokens += request.action.tokens ?? 0;
232
+ }
233
+ }
234
+ appendReceipt(request, decision) {
235
+ const previous = this.state.receipts.at(-1)?.hash ?? null;
236
+ const sequence = this.state.receipts.length;
237
+ const payloadWithoutId = {
238
+ previousReceiptHash: previous,
239
+ sequence,
240
+ issuedAt: request.context?.now ?? this.now(),
241
+ request,
242
+ decision,
243
+ policyHash: policyHash({ mode: this.state.mode, rules: this.state.rules, budgets: this.state.budgets }),
244
+ };
245
+ const receiptId = policyHash(payloadWithoutId);
246
+ const payload = { receiptId, ...payloadWithoutId };
247
+ const hash = policyHash(payload);
248
+ const receipt = {
249
+ payload,
250
+ hash,
251
+ signature: this.signingKey ? signPolicyHash(hash, this.signingKey) : undefined,
252
+ keyId: this.signingKey ? (this.keyId ?? 'local') : undefined,
253
+ };
254
+ this.state.receipts.push(receipt);
255
+ return receipt;
256
+ }
257
+ validateRequest(request) {
258
+ if (!request.identity?.id || !request.identity.type || !request.action?.type) {
259
+ throw new Error('invalid-policy-request');
260
+ }
261
+ for (const [name, value] of [
262
+ ['costUsd', request.action.costUsd],
263
+ ['tokens', request.action.tokens],
264
+ ['concurrency', request.action.concurrency],
265
+ ]) {
266
+ if (value !== undefined && (!Number.isFinite(value) || value < 0)) {
267
+ throw new Error(`invalid-policy-action-${name}`);
268
+ }
269
+ }
270
+ }
271
+ }
272
+ export function createLegacyCompatibleState(source = 'pre-ADR-324') {
273
+ return {
274
+ version: POLICY_STATE_VERSION,
275
+ mode: 'legacy',
276
+ migratedFrom: source,
277
+ migratedAt: Date.now(),
278
+ rules: [],
279
+ budgets: [],
280
+ usage: [],
281
+ approvals: [],
282
+ receipts: [],
283
+ };
284
+ }
285
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/policy/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAahD,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,SAAS,QAAQ,CAAC,OAA2B,EAAE,KAAyB;IACtE,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAC1B,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IACzB,OAAO,OAAO,KAAK,GAAG,IAAI,OAAO,KAAK,KAAK,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnH,CAAC;AAED,MAAM,OAAO,mBAAmB;IACb,GAAG,CAAe;IAClB,UAAU,CAAmB;IAC7B,KAAK,CAAU;IACf,gBAAgB,CAAiE;IACjF,sBAAsB,CAA+B;IAC9D,KAAK,CAAc;IAE3B,YAAY,UAA+B,EAAE;QAC3C,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,OAAO,C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AC;SACnC,EAAE,CAAC;YACX,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;gBAClE,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC;YACnD,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED,MAAM,UAAU,2BAA2B,CAAC,MAAM,GAAG,aAAa;IAChE,OAAO;QACL,OAAO,EAAE,oBAAoB;QAC7B,IAAI,EAAE,QAAQ;QACd,YAAY,EAAE,MAAM;QACpB,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE;QACtB,KAAK,EAAE,EAAE;QACT,OAAO,EAAE,EAAE;QACX,KAAK,EAAE,EAAE;QACT,SAAS,EAAE,EAAE;QACb,QAAQ,EAAE,EAAE;KACb,CAAC;AACJ,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { CapabilityEnvelope, PolicyAction } from './types.js';
2
+ export interface EnvelopeCheck {
3
+ allowed: boolean;
4
+ reason?: string;
5
+ }
6
+ export declare function checkCapabilityEnvelope(action: PolicyAction, envelope: CapabilityEnvelope | undefined, now?: number): EnvelopeCheck;
7
+ export declare function isEnvelopeReduction(parent: CapabilityEnvelope, child: CapabilityEnvelope): boolean;
8
+ export declare function delegateEnvelope(parent: CapabilityEnvelope, child: CapabilityEnvelope): CapabilityEnvelope;
9
+ //# sourceMappingURL=envelope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/policy/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEnE,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAkBD,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,YAAY,EACpB,QAAQ,EAAE,kBAAkB,GAAG,SAAS,EACxC,GAAG,SAAa,GACf,aAAa,CA+Bf;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAyBlG;AAED,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,kBAAkB,EAC1B,KAAK,EAAE,kBAAkB,GACxB,kBAAkB,CAkBpB"}