@decionis/agentsafe 0.1.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 (436) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +4 -0
  3. package/README.md +909 -0
  4. package/dist/Cli.d.ts +3 -0
  5. package/dist/Cli.d.ts.map +1 -0
  6. package/dist/Cli.js +150 -0
  7. package/dist/Cli.js.map +1 -0
  8. package/dist/Index.d.ts +104 -0
  9. package/dist/Index.d.ts.map +1 -0
  10. package/dist/Index.js +102 -0
  11. package/dist/Index.js.map +1 -0
  12. package/dist/Serve.d.ts +26 -0
  13. package/dist/Serve.d.ts.map +1 -0
  14. package/dist/Serve.js +143 -0
  15. package/dist/Serve.js.map +1 -0
  16. package/dist/TrustedExecutor.d.ts +66 -0
  17. package/dist/TrustedExecutor.d.ts.map +1 -0
  18. package/dist/TrustedExecutor.js +170 -0
  19. package/dist/TrustedExecutor.js.map +1 -0
  20. package/dist/Version.d.ts +6 -0
  21. package/dist/Version.d.ts.map +1 -0
  22. package/dist/Version.js +21 -0
  23. package/dist/Version.js.map +1 -0
  24. package/dist/adapters/AdapterActionHandler.d.ts +48 -0
  25. package/dist/adapters/AdapterActionHandler.d.ts.map +1 -0
  26. package/dist/adapters/AdapterActionHandler.js +148 -0
  27. package/dist/adapters/AdapterActionHandler.js.map +1 -0
  28. package/dist/adapters/EffectAdapter.d.ts +96 -0
  29. package/dist/adapters/EffectAdapter.d.ts.map +1 -0
  30. package/dist/adapters/EffectAdapter.js +16 -0
  31. package/dist/adapters/EffectAdapter.js.map +1 -0
  32. package/dist/adapters/EffectAwareGrantVerifier.d.ts +30 -0
  33. package/dist/adapters/EffectAwareGrantVerifier.d.ts.map +1 -0
  34. package/dist/adapters/EffectAwareGrantVerifier.js +38 -0
  35. package/dist/adapters/EffectAwareGrantVerifier.js.map +1 -0
  36. package/dist/adapters/EffectComparison.d.ts +20 -0
  37. package/dist/adapters/EffectComparison.d.ts.map +1 -0
  38. package/dist/adapters/EffectComparison.js +48 -0
  39. package/dist/adapters/EffectComparison.js.map +1 -0
  40. package/dist/adapters/EffectEvidenceBuilder.d.ts +60 -0
  41. package/dist/adapters/EffectEvidenceBuilder.d.ts.map +1 -0
  42. package/dist/adapters/EffectEvidenceBuilder.js +127 -0
  43. package/dist/adapters/EffectEvidenceBuilder.js.map +1 -0
  44. package/dist/adapters/EffectEvidenceRegister.d.ts +31 -0
  45. package/dist/adapters/EffectEvidenceRegister.d.ts.map +1 -0
  46. package/dist/adapters/EffectEvidenceRegister.js +21 -0
  47. package/dist/adapters/EffectEvidenceRegister.js.map +1 -0
  48. package/dist/adapters/JcsDigest.d.ts +43 -0
  49. package/dist/adapters/JcsDigest.d.ts.map +1 -0
  50. package/dist/adapters/JcsDigest.js +86 -0
  51. package/dist/adapters/JcsDigest.js.map +1 -0
  52. package/dist/adapters/banking/BankingAction.d.ts +146 -0
  53. package/dist/adapters/banking/BankingAction.d.ts.map +1 -0
  54. package/dist/adapters/banking/BankingAction.js +102 -0
  55. package/dist/adapters/banking/BankingAction.js.map +1 -0
  56. package/dist/adapters/banking/BankingAdapter.d.ts +60 -0
  57. package/dist/adapters/banking/BankingAdapter.d.ts.map +1 -0
  58. package/dist/adapters/banking/BankingAdapter.js +107 -0
  59. package/dist/adapters/banking/BankingAdapter.js.map +1 -0
  60. package/dist/adapters/banking/BankingHandlers.d.ts +24 -0
  61. package/dist/adapters/banking/BankingHandlers.d.ts.map +1 -0
  62. package/dist/adapters/banking/BankingHandlers.js +47 -0
  63. package/dist/adapters/banking/BankingHandlers.js.map +1 -0
  64. package/dist/adapters/banking/BankingIntentBinder.d.ts +47 -0
  65. package/dist/adapters/banking/BankingIntentBinder.d.ts.map +1 -0
  66. package/dist/adapters/banking/BankingIntentBinder.js +64 -0
  67. package/dist/adapters/banking/BankingIntentBinder.js.map +1 -0
  68. package/dist/adapters/banking/CoreBankingHttpAdapter.d.ts +55 -0
  69. package/dist/adapters/banking/CoreBankingHttpAdapter.d.ts.map +1 -0
  70. package/dist/adapters/banking/CoreBankingHttpAdapter.js +248 -0
  71. package/dist/adapters/banking/CoreBankingHttpAdapter.js.map +1 -0
  72. package/dist/adapters/banking/Currency.d.ts +10 -0
  73. package/dist/adapters/banking/Currency.d.ts.map +1 -0
  74. package/dist/adapters/banking/Currency.js +91 -0
  75. package/dist/adapters/banking/Currency.js.map +1 -0
  76. package/dist/adapters/banking/EffectProjections.d.ts +52 -0
  77. package/dist/adapters/banking/EffectProjections.d.ts.map +1 -0
  78. package/dist/adapters/banking/EffectProjections.js +140 -0
  79. package/dist/adapters/banking/EffectProjections.js.map +1 -0
  80. package/dist/adapters/banking/Iban.d.ts +18 -0
  81. package/dist/adapters/banking/Iban.d.ts.map +1 -0
  82. package/dist/adapters/banking/Iban.js +38 -0
  83. package/dist/adapters/banking/Iban.js.map +1 -0
  84. package/dist/adapters/banking/Money.d.ts +32 -0
  85. package/dist/adapters/banking/Money.d.ts.map +1 -0
  86. package/dist/adapters/banking/Money.js +81 -0
  87. package/dist/adapters/banking/Money.js.map +1 -0
  88. package/dist/adapters/banking/ReasonCodes.d.ts +19 -0
  89. package/dist/adapters/banking/ReasonCodes.d.ts.map +1 -0
  90. package/dist/adapters/banking/ReasonCodes.js +35 -0
  91. package/dist/adapters/banking/ReasonCodes.js.map +1 -0
  92. package/dist/audit/ChainJournal.d.ts +38 -0
  93. package/dist/audit/ChainJournal.d.ts.map +1 -0
  94. package/dist/audit/ChainJournal.js +97 -0
  95. package/dist/audit/ChainJournal.js.map +1 -0
  96. package/dist/audit/HashChain.d.ts +39 -0
  97. package/dist/audit/HashChain.d.ts.map +1 -0
  98. package/dist/audit/HashChain.js +63 -0
  99. package/dist/audit/HashChain.js.map +1 -0
  100. package/dist/audit/HashChainedAuditSink.d.ts +22 -0
  101. package/dist/audit/HashChainedAuditSink.d.ts.map +1 -0
  102. package/dist/audit/HashChainedAuditSink.js +26 -0
  103. package/dist/audit/HashChainedAuditSink.js.map +1 -0
  104. package/dist/audit/LineAuditSink.d.ts +19 -0
  105. package/dist/audit/LineAuditSink.d.ts.map +1 -0
  106. package/dist/audit/LineAuditSink.js +35 -0
  107. package/dist/audit/LineAuditSink.js.map +1 -0
  108. package/dist/cli/Arguments.d.ts +26 -0
  109. package/dist/cli/Arguments.d.ts.map +1 -0
  110. package/dist/cli/Arguments.js +66 -0
  111. package/dist/cli/Arguments.js.map +1 -0
  112. package/dist/cli/CliProcess.d.ts +29 -0
  113. package/dist/cli/CliProcess.d.ts.map +1 -0
  114. package/dist/cli/CliProcess.js +78 -0
  115. package/dist/cli/CliProcess.js.map +1 -0
  116. package/dist/cli/Commands.d.ts +8 -0
  117. package/dist/cli/Commands.d.ts.map +1 -0
  118. package/dist/cli/Commands.js +67 -0
  119. package/dist/cli/Commands.js.map +1 -0
  120. package/dist/cli/ConfigCommand.d.ts +7 -0
  121. package/dist/cli/ConfigCommand.d.ts.map +1 -0
  122. package/dist/cli/ConfigCommand.js +77 -0
  123. package/dist/cli/ConfigCommand.js.map +1 -0
  124. package/dist/cli/ConfigFile.d.ts +21 -0
  125. package/dist/cli/ConfigFile.d.ts.map +1 -0
  126. package/dist/cli/ConfigFile.js +57 -0
  127. package/dist/cli/ConfigFile.js.map +1 -0
  128. package/dist/cli/Credentials.d.ts +15 -0
  129. package/dist/cli/Credentials.d.ts.map +1 -0
  130. package/dist/cli/Credentials.js +51 -0
  131. package/dist/cli/Credentials.js.map +1 -0
  132. package/dist/cli/Doctor.d.ts +25 -0
  133. package/dist/cli/Doctor.d.ts.map +1 -0
  134. package/dist/cli/Doctor.js +211 -0
  135. package/dist/cli/Doctor.js.map +1 -0
  136. package/dist/cli/Help.d.ts +3 -0
  137. package/dist/cli/Help.d.ts.map +1 -0
  138. package/dist/cli/Help.js +38 -0
  139. package/dist/cli/Help.js.map +1 -0
  140. package/dist/cli/Init.d.ts +32 -0
  141. package/dist/cli/Init.d.ts.map +1 -0
  142. package/dist/cli/Init.js +163 -0
  143. package/dist/cli/Init.js.map +1 -0
  144. package/dist/cli/Login.d.ts +16 -0
  145. package/dist/cli/Login.d.ts.map +1 -0
  146. package/dist/cli/Login.js +74 -0
  147. package/dist/cli/Login.js.map +1 -0
  148. package/dist/cli/Proxy.d.ts +41 -0
  149. package/dist/cli/Proxy.d.ts.map +1 -0
  150. package/dist/cli/Proxy.js +161 -0
  151. package/dist/cli/Proxy.js.map +1 -0
  152. package/dist/cli/Status.d.ts +7 -0
  153. package/dist/cli/Status.d.ts.map +1 -0
  154. package/dist/cli/Status.js +64 -0
  155. package/dist/cli/Status.js.map +1 -0
  156. package/dist/cli/TestCommand.d.ts +36 -0
  157. package/dist/cli/TestCommand.d.ts.map +1 -0
  158. package/dist/cli/TestCommand.js +173 -0
  159. package/dist/cli/TestCommand.js.map +1 -0
  160. package/dist/config/ConfigKeys.d.ts +10 -0
  161. package/dist/config/ConfigKeys.d.ts.map +1 -0
  162. package/dist/config/ConfigKeys.js +105 -0
  163. package/dist/config/ConfigKeys.js.map +1 -0
  164. package/dist/config/ExecutorConfig.d.ts +254 -0
  165. package/dist/config/ExecutorConfig.d.ts.map +1 -0
  166. package/dist/config/ExecutorConfig.js +637 -0
  167. package/dist/config/ExecutorConfig.js.map +1 -0
  168. package/dist/containment/ContainmentProbe.d.ts +87 -0
  169. package/dist/containment/ContainmentProbe.d.ts.map +1 -0
  170. package/dist/containment/ContainmentProbe.js +103 -0
  171. package/dist/containment/ContainmentProbe.js.map +1 -0
  172. package/dist/credential/CredentialError.d.ts +6 -0
  173. package/dist/credential/CredentialError.d.ts.map +1 -0
  174. package/dist/credential/CredentialError.js +10 -0
  175. package/dist/credential/CredentialError.js.map +1 -0
  176. package/dist/credential/DownstreamCredential.d.ts +38 -0
  177. package/dist/credential/DownstreamCredential.d.ts.map +1 -0
  178. package/dist/credential/DownstreamCredential.js +2 -0
  179. package/dist/credential/DownstreamCredential.js.map +1 -0
  180. package/dist/credential/GrantOf.d.ts +10 -0
  181. package/dist/credential/GrantOf.d.ts.map +1 -0
  182. package/dist/credential/GrantOf.js +16 -0
  183. package/dist/credential/GrantOf.js.map +1 -0
  184. package/dist/credential/PrivateKeyJwtCredential.d.ts +43 -0
  185. package/dist/credential/PrivateKeyJwtCredential.d.ts.map +1 -0
  186. package/dist/credential/PrivateKeyJwtCredential.js +126 -0
  187. package/dist/credential/PrivateKeyJwtCredential.js.map +1 -0
  188. package/dist/credential/SignedRequestCredential.d.ts +112 -0
  189. package/dist/credential/SignedRequestCredential.d.ts.map +1 -0
  190. package/dist/credential/SignedRequestCredential.js +255 -0
  191. package/dist/credential/SignedRequestCredential.js.map +1 -0
  192. package/dist/credential/StaticHeaderCredential.d.ts +16 -0
  193. package/dist/credential/StaticHeaderCredential.d.ts.map +1 -0
  194. package/dist/credential/StaticHeaderCredential.js +21 -0
  195. package/dist/credential/StaticHeaderCredential.js.map +1 -0
  196. package/dist/egress/EgressError.d.ts +13 -0
  197. package/dist/egress/EgressError.d.ts.map +1 -0
  198. package/dist/egress/EgressError.js +16 -0
  199. package/dist/egress/EgressError.js.map +1 -0
  200. package/dist/egress/EgressPolicy.d.ts +55 -0
  201. package/dist/egress/EgressPolicy.d.ts.map +1 -0
  202. package/dist/egress/EgressPolicy.js +137 -0
  203. package/dist/egress/EgressPolicy.js.map +1 -0
  204. package/dist/egress/GlobalFetchLock.d.ts +16 -0
  205. package/dist/egress/GlobalFetchLock.d.ts.map +1 -0
  206. package/dist/egress/GlobalFetchLock.js +34 -0
  207. package/dist/egress/GlobalFetchLock.js.map +1 -0
  208. package/dist/egress/GuardedFetch.d.ts +56 -0
  209. package/dist/egress/GuardedFetch.d.ts.map +1 -0
  210. package/dist/egress/GuardedFetch.js +300 -0
  211. package/dist/egress/GuardedFetch.js.map +1 -0
  212. package/dist/egress/TcpProbe.d.ts +35 -0
  213. package/dist/egress/TcpProbe.d.ts.map +1 -0
  214. package/dist/egress/TcpProbe.js +45 -0
  215. package/dist/egress/TcpProbe.js.map +1 -0
  216. package/dist/gateway/Activation.d.ts +39 -0
  217. package/dist/gateway/Activation.d.ts.map +1 -0
  218. package/dist/gateway/Activation.js +61 -0
  219. package/dist/gateway/Activation.js.map +1 -0
  220. package/dist/gateway/BoundaryTest.d.ts +92 -0
  221. package/dist/gateway/BoundaryTest.d.ts.map +1 -0
  222. package/dist/gateway/BoundaryTest.js +349 -0
  223. package/dist/gateway/BoundaryTest.js.map +1 -0
  224. package/dist/gateway/DemoAuthority.d.ts +41 -0
  225. package/dist/gateway/DemoAuthority.d.ts.map +1 -0
  226. package/dist/gateway/DemoAuthority.js +66 -0
  227. package/dist/gateway/DemoAuthority.js.map +1 -0
  228. package/dist/gateway/ForwardHandler.d.ts +56 -0
  229. package/dist/gateway/ForwardHandler.d.ts.map +1 -0
  230. package/dist/gateway/ForwardHandler.js +111 -0
  231. package/dist/gateway/ForwardHandler.js.map +1 -0
  232. package/dist/gateway/Gateway.d.ts +142 -0
  233. package/dist/gateway/Gateway.d.ts.map +1 -0
  234. package/dist/gateway/Gateway.js +819 -0
  235. package/dist/gateway/Gateway.js.map +1 -0
  236. package/dist/gateway/GatewayConfig.d.ts +237 -0
  237. package/dist/gateway/GatewayConfig.d.ts.map +1 -0
  238. package/dist/gateway/GatewayConfig.js +706 -0
  239. package/dist/gateway/GatewayConfig.js.map +1 -0
  240. package/dist/gateway/GatewayMetrics.d.ts +26 -0
  241. package/dist/gateway/GatewayMetrics.d.ts.map +1 -0
  242. package/dist/gateway/GatewayMetrics.js +28 -0
  243. package/dist/gateway/GatewayMetrics.js.map +1 -0
  244. package/dist/gateway/GatewayReport.d.ts +74 -0
  245. package/dist/gateway/GatewayReport.d.ts.map +1 -0
  246. package/dist/gateway/GatewayReport.js +109 -0
  247. package/dist/gateway/GatewayReport.js.map +1 -0
  248. package/dist/gateway/InterceptedRequest.d.ts +53 -0
  249. package/dist/gateway/InterceptedRequest.d.ts.map +1 -0
  250. package/dist/gateway/InterceptedRequest.js +80 -0
  251. package/dist/gateway/InterceptedRequest.js.map +1 -0
  252. package/dist/gateway/RouteTable.d.ts +28 -0
  253. package/dist/gateway/RouteTable.d.ts.map +1 -0
  254. package/dist/gateway/RouteTable.js +72 -0
  255. package/dist/gateway/RouteTable.js.map +1 -0
  256. package/dist/gateway/Upstream.d.ts +46 -0
  257. package/dist/gateway/Upstream.d.ts.map +1 -0
  258. package/dist/gateway/Upstream.js +158 -0
  259. package/dist/gateway/Upstream.js.map +1 -0
  260. package/dist/handlers/ForwardRequestHandler.d.ts +26 -0
  261. package/dist/handlers/ForwardRequestHandler.d.ts.map +1 -0
  262. package/dist/handlers/ForwardRequestHandler.js +98 -0
  263. package/dist/handlers/ForwardRequestHandler.js.map +1 -0
  264. package/dist/handlers/HandlerRegistration.d.ts +37 -0
  265. package/dist/handlers/HandlerRegistration.d.ts.map +1 -0
  266. package/dist/handlers/HandlerRegistration.js +2 -0
  267. package/dist/handlers/HandlerRegistration.js.map +1 -0
  268. package/dist/handlers/JournaledActionHandler.d.ts +31 -0
  269. package/dist/handlers/JournaledActionHandler.d.ts.map +1 -0
  270. package/dist/handlers/JournaledActionHandler.js +63 -0
  271. package/dist/handlers/JournaledActionHandler.js.map +1 -0
  272. package/dist/http/ExecutorHttpServer.d.ts +33 -0
  273. package/dist/http/ExecutorHttpServer.d.ts.map +1 -0
  274. package/dist/http/ExecutorHttpServer.js +176 -0
  275. package/dist/http/ExecutorHttpServer.js.map +1 -0
  276. package/dist/http/GatewayHttpServer.d.ts +42 -0
  277. package/dist/http/GatewayHttpServer.d.ts.map +1 -0
  278. package/dist/http/GatewayHttpServer.js +195 -0
  279. package/dist/http/GatewayHttpServer.js.map +1 -0
  280. package/dist/http/RecordingTarget.d.ts +18 -0
  281. package/dist/http/RecordingTarget.d.ts.map +1 -0
  282. package/dist/http/RecordingTarget.js +71 -0
  283. package/dist/http/RecordingTarget.js.map +1 -0
  284. package/dist/http/RequestContext.d.ts +17 -0
  285. package/dist/http/RequestContext.d.ts.map +1 -0
  286. package/dist/http/RequestContext.js +19 -0
  287. package/dist/http/RequestContext.js.map +1 -0
  288. package/dist/http/Routes.d.ts +93 -0
  289. package/dist/http/Routes.d.ts.map +1 -0
  290. package/dist/http/Routes.js +46 -0
  291. package/dist/http/Routes.js.map +1 -0
  292. package/dist/http/TlsListener.d.ts +38 -0
  293. package/dist/http/TlsListener.d.ts.map +1 -0
  294. package/dist/http/TlsListener.js +52 -0
  295. package/dist/http/TlsListener.js.map +1 -0
  296. package/dist/identity/Authenticator.d.ts +58 -0
  297. package/dist/identity/Authenticator.d.ts.map +1 -0
  298. package/dist/identity/Authenticator.js +170 -0
  299. package/dist/identity/Authenticator.js.map +1 -0
  300. package/dist/identity/PeerIdentity.d.ts +24 -0
  301. package/dist/identity/PeerIdentity.d.ts.map +1 -0
  302. package/dist/identity/PeerIdentity.js +29 -0
  303. package/dist/identity/PeerIdentity.js.map +1 -0
  304. package/dist/identity/PrincipalRegistry.d.ts +102 -0
  305. package/dist/identity/PrincipalRegistry.d.ts.map +1 -0
  306. package/dist/identity/PrincipalRegistry.js +191 -0
  307. package/dist/identity/PrincipalRegistry.js.map +1 -0
  308. package/dist/identity/PrincipalsFile.d.ts +152 -0
  309. package/dist/identity/PrincipalsFile.d.ts.map +1 -0
  310. package/dist/identity/PrincipalsFile.js +125 -0
  311. package/dist/identity/PrincipalsFile.js.map +1 -0
  312. package/dist/identity/RateLimiter.d.ts +43 -0
  313. package/dist/identity/RateLimiter.d.ts.map +1 -0
  314. package/dist/identity/RateLimiter.js +84 -0
  315. package/dist/identity/RateLimiter.js.map +1 -0
  316. package/dist/identity/SeparationOfDuties.d.ts +11 -0
  317. package/dist/identity/SeparationOfDuties.d.ts.map +1 -0
  318. package/dist/identity/SeparationOfDuties.js +25 -0
  319. package/dist/identity/SeparationOfDuties.js.map +1 -0
  320. package/dist/identity/WorkloadJwtVerifier.d.ts +57 -0
  321. package/dist/identity/WorkloadJwtVerifier.d.ts.map +1 -0
  322. package/dist/identity/WorkloadJwtVerifier.js +145 -0
  323. package/dist/identity/WorkloadJwtVerifier.js.map +1 -0
  324. package/dist/incident/EvidenceExport.d.ts +128 -0
  325. package/dist/incident/EvidenceExport.d.ts.map +1 -0
  326. package/dist/incident/EvidenceExport.js +187 -0
  327. package/dist/incident/EvidenceExport.js.map +1 -0
  328. package/dist/incident/FileProbe.d.ts +22 -0
  329. package/dist/incident/FileProbe.d.ts.map +1 -0
  330. package/dist/incident/FileProbe.js +31 -0
  331. package/dist/incident/FileProbe.js.map +1 -0
  332. package/dist/incident/HaltSwitch.d.ts +95 -0
  333. package/dist/incident/HaltSwitch.d.ts.map +1 -0
  334. package/dist/incident/HaltSwitch.js +171 -0
  335. package/dist/incident/HaltSwitch.js.map +1 -0
  336. package/dist/incident/Metrics.d.ts +71 -0
  337. package/dist/incident/Metrics.d.ts.map +1 -0
  338. package/dist/incident/Metrics.js +146 -0
  339. package/dist/incident/Metrics.js.map +1 -0
  340. package/dist/incident/SecurityEvents.d.ts +182 -0
  341. package/dist/incident/SecurityEvents.d.ts.map +1 -0
  342. package/dist/incident/SecurityEvents.js +167 -0
  343. package/dist/incident/SecurityEvents.js.map +1 -0
  344. package/dist/journal/ExecutionJournal.d.ts +96 -0
  345. package/dist/journal/ExecutionJournal.d.ts.map +1 -0
  346. package/dist/journal/ExecutionJournal.js +100 -0
  347. package/dist/journal/ExecutionJournal.js.map +1 -0
  348. package/dist/journal/FileExecutionJournal.d.ts +38 -0
  349. package/dist/journal/FileExecutionJournal.d.ts.map +1 -0
  350. package/dist/journal/FileExecutionJournal.js +137 -0
  351. package/dist/journal/FileExecutionJournal.js.map +1 -0
  352. package/dist/journal/InMemoryExecutionJournal.d.ts +23 -0
  353. package/dist/journal/InMemoryExecutionJournal.d.ts.map +1 -0
  354. package/dist/journal/InMemoryExecutionJournal.js +47 -0
  355. package/dist/journal/InMemoryExecutionJournal.js.map +1 -0
  356. package/dist/journal/StartupReconciler.d.ts +47 -0
  357. package/dist/journal/StartupReconciler.d.ts.map +1 -0
  358. package/dist/journal/StartupReconciler.js +89 -0
  359. package/dist/journal/StartupReconciler.js.map +1 -0
  360. package/dist/limits/HardLimits.d.ts +63 -0
  361. package/dist/limits/HardLimits.d.ts.map +1 -0
  362. package/dist/limits/HardLimits.js +120 -0
  363. package/dist/limits/HardLimits.js.map +1 -0
  364. package/dist/logging/LineEmitter.d.ts +26 -0
  365. package/dist/logging/LineEmitter.d.ts.map +1 -0
  366. package/dist/logging/LineEmitter.js +36 -0
  367. package/dist/logging/LineEmitter.js.map +1 -0
  368. package/dist/posture/HostPosture.d.ts +60 -0
  369. package/dist/posture/HostPosture.d.ts.map +1 -0
  370. package/dist/posture/HostPosture.js +104 -0
  371. package/dist/posture/HostPosture.js.map +1 -0
  372. package/dist/posture/PostureChecks.d.ts +52 -0
  373. package/dist/posture/PostureChecks.d.ts.map +1 -0
  374. package/dist/posture/PostureChecks.js +172 -0
  375. package/dist/posture/PostureChecks.js.map +1 -0
  376. package/dist/secrets/CompositeSecretStore.d.ts +37 -0
  377. package/dist/secrets/CompositeSecretStore.d.ts.map +1 -0
  378. package/dist/secrets/CompositeSecretStore.js +99 -0
  379. package/dist/secrets/CompositeSecretStore.js.map +1 -0
  380. package/dist/secrets/EnvSecretStore.d.ts +18 -0
  381. package/dist/secrets/EnvSecretStore.d.ts.map +1 -0
  382. package/dist/secrets/EnvSecretStore.js +46 -0
  383. package/dist/secrets/EnvSecretStore.js.map +1 -0
  384. package/dist/secrets/FileSecretStore.d.ts +60 -0
  385. package/dist/secrets/FileSecretStore.d.ts.map +1 -0
  386. package/dist/secrets/FileSecretStore.js +180 -0
  387. package/dist/secrets/FileSecretStore.js.map +1 -0
  388. package/dist/secrets/Redactor.d.ts +32 -0
  389. package/dist/secrets/Redactor.d.ts.map +1 -0
  390. package/dist/secrets/Redactor.js +108 -0
  391. package/dist/secrets/Redactor.js.map +1 -0
  392. package/dist/secrets/SecretHandle.d.ts +34 -0
  393. package/dist/secrets/SecretHandle.d.ts.map +1 -0
  394. package/dist/secrets/SecretHandle.js +71 -0
  395. package/dist/secrets/SecretHandle.js.map +1 -0
  396. package/dist/secrets/SecretStore.d.ts +37 -0
  397. package/dist/secrets/SecretStore.d.ts.map +1 -0
  398. package/dist/secrets/SecretStore.js +12 -0
  399. package/dist/secrets/SecretStore.js.map +1 -0
  400. package/dist/service/AuthorityClients.d.ts +50 -0
  401. package/dist/service/AuthorityClients.d.ts.map +1 -0
  402. package/dist/service/AuthorityClients.js +83 -0
  403. package/dist/service/AuthorityClients.js.map +1 -0
  404. package/dist/service/EscalationResolver.d.ts +97 -0
  405. package/dist/service/EscalationResolver.d.ts.map +1 -0
  406. package/dist/service/EscalationResolver.js +196 -0
  407. package/dist/service/EscalationResolver.js.map +1 -0
  408. package/dist/service/Requests.d.ts +99 -0
  409. package/dist/service/Requests.d.ts.map +1 -0
  410. package/dist/service/Requests.js +42 -0
  411. package/dist/service/Requests.js.map +1 -0
  412. package/dist/service/ServiceError.d.ts +20 -0
  413. package/dist/service/ServiceError.d.ts.map +1 -0
  414. package/dist/service/ServiceError.js +25 -0
  415. package/dist/service/ServiceError.js.map +1 -0
  416. package/dist/service/TrustedExecutorService.d.ts +221 -0
  417. package/dist/service/TrustedExecutorService.d.ts.map +1 -0
  418. package/dist/service/TrustedExecutorService.js +1066 -0
  419. package/dist/service/TrustedExecutorService.js.map +1 -0
  420. package/dist/time/ClockSkewGuard.d.ts +25 -0
  421. package/dist/time/ClockSkewGuard.d.ts.map +1 -0
  422. package/dist/time/ClockSkewGuard.js +35 -0
  423. package/dist/time/ClockSkewGuard.js.map +1 -0
  424. package/dist/time/MonotonicClock.d.ts +35 -0
  425. package/dist/time/MonotonicClock.d.ts.map +1 -0
  426. package/dist/time/MonotonicClock.js +52 -0
  427. package/dist/time/MonotonicClock.js.map +1 -0
  428. package/dist/verify/VerifyAuditChain.d.ts +36 -0
  429. package/dist/verify/VerifyAuditChain.d.ts.map +1 -0
  430. package/dist/verify/VerifyAuditChain.js +109 -0
  431. package/dist/verify/VerifyAuditChain.js.map +1 -0
  432. package/dist/verify/VerifyEvidenceBundle.d.ts +50 -0
  433. package/dist/verify/VerifyEvidenceBundle.d.ts.map +1 -0
  434. package/dist/verify/VerifyEvidenceBundle.js +157 -0
  435. package/dist/verify/VerifyEvidenceBundle.js.map +1 -0
  436. package/package.json +80 -0
@@ -0,0 +1,819 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { appendFileSync, mkdirSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { ActionRegistry, AuditRecorder, DecionisGate, DecionisGrantVerifier, IntentCapture, SafeExecutor, ShadowPipeline, } from "@decionis/agent-safe-pipeline";
5
+ import { ChainJournal } from "../audit/ChainJournal.js";
6
+ import { HashChain } from "../audit/HashChain.js";
7
+ import { EVIDENCE_STREAM, HashChainedAuditSink } from "../audit/HashChainedAuditSink.js";
8
+ import { EgressPolicy } from "../egress/EgressPolicy.js";
9
+ import { GuardedFetch } from "../egress/GuardedFetch.js";
10
+ import { RequestContext } from "../http/RequestContext.js";
11
+ import { SECURITY_STREAM, SecurityEvents } from "../incident/SecurityEvents.js";
12
+ import { LineEmitter } from "../logging/LineEmitter.js";
13
+ import { CompositeSecretStore } from "../secrets/CompositeSecretStore.js";
14
+ import { Redactor } from "../secrets/Redactor.js";
15
+ import { EscalationResolver } from "../service/EscalationResolver.js";
16
+ import { ActivationFunnel } from "./Activation.js";
17
+ import { startDemoAuthority } from "./DemoAuthority.js";
18
+ import { httpForwardHandler, registerHttpActions, RequestHolder, } from "./ForwardHandler.js";
19
+ import { gatewayMetrics } from "./GatewayMetrics.js";
20
+ import { renderHuman, renderJson, } from "./GatewayReport.js";
21
+ import { normalizeRequest } from "./InterceptedRequest.js";
22
+ import { RouteTable } from "./RouteTable.js";
23
+ import { Upstream } from "./Upstream.js";
24
+ /** The gateway's own evidence stream: what it did that the pipeline's audit contract has no event for. */
25
+ export const GATEWAY_STREAM = "agent-safe.gateway-events/1";
26
+ /** Every path under it belongs to the gateway and is never forwarded. */
27
+ export const GATEWAY_PREFIX = "/_agentsafe";
28
+ /** The version of the wire shape the gateway answers with on its own responses. */
29
+ export const GATEWAY_RESPONSE_VERSION = "agent-safe.gateway/1";
30
+ /** The most escalations held at once; beyond it a new hold is refused rather than an old one dropped. */
31
+ const MAX_HELD = 1_000;
32
+ const RETRY_AFTER_SECONDS = 5;
33
+ /**
34
+ * The HTTP-interception ingress over the unchanged lifecycle. A request the
35
+ * route table calls consequential becomes a captured intent; the authority
36
+ * decides; on `ALLOW` the executor claims the grant and the forwarding
37
+ * handler sends the exact bytes the intent bound; the outcome is finalized
38
+ * and every step is chained evidence. In shadow the request goes through
39
+ * unchanged while the authority is asked what it would have decided.
40
+ * Nothing here decides ALLOW, BLOCK or ESCALATE; it asks, enforces and records.
41
+ */
42
+ export class Gateway {
43
+ config;
44
+ upstream;
45
+ routes;
46
+ metrics;
47
+ emitLine;
48
+ io;
49
+ secrets;
50
+ demo;
51
+ evidence;
52
+ chain;
53
+ clock;
54
+ version;
55
+ held = new Map();
56
+ holder = new RequestHolder();
57
+ capture;
58
+ executor;
59
+ shadow;
60
+ resolver;
61
+ stopFollowing;
62
+ counts = {};
63
+ activation;
64
+ constructor(config, upstream, routes, audit, gate, verifier, metrics, emitLine, io, security, secrets, demo, journal, evidence, chain, clock, version) {
65
+ this.config = config;
66
+ this.upstream = upstream;
67
+ this.routes = routes;
68
+ this.metrics = metrics;
69
+ this.emitLine = emitLine;
70
+ this.io = io;
71
+ this.secrets = secrets;
72
+ this.demo = demo;
73
+ this.evidence = evidence;
74
+ this.chain = chain;
75
+ this.clock = clock;
76
+ this.version = version;
77
+ this.capture = new IntentCapture({ audit, ttlSeconds: config.intentTtlSeconds });
78
+ this.activation = new ActivationFunnel((milestone, at) => this.report({ event: "ACTIVATION", milestone, at }), clock);
79
+ const registry = registerHttpActions(new ActionRegistry(), routes.actions(), httpForwardHandler(upstream, this.holder));
80
+ this.executor = new SafeExecutor(registry, verifier, audit);
81
+ this.shadow =
82
+ config.authority.mode === "SHADOW"
83
+ ? new ShadowPipeline(gate, { audit, timeoutMs: config.authority.timeoutMs })
84
+ : null;
85
+ this.resolver =
86
+ config.authority.mode === "ENFORCEMENT"
87
+ ? new EscalationResolver(config.escalation, gate, audit, {})
88
+ : null;
89
+ this.stopFollowing =
90
+ journal === null
91
+ ? []
92
+ : [
93
+ journal.follow(evidence, security),
94
+ journal.follow(chain, security),
95
+ journal.follow(security.chain, security),
96
+ ];
97
+ }
98
+ /**
99
+ * Assembles the gateway: the secrets it needs opened, the demo authority
100
+ * started when chosen, the guarded egress sealed to the authority, the
101
+ * pipeline objects built over it, the evidence chains restored. Nothing
102
+ * listens; the listener is the caller's.
103
+ */
104
+ static async create(config, dependencies = {}) {
105
+ const env = dependencies.env ?? process.env;
106
+ const clock = dependencies.clock ?? (() => Date.now());
107
+ const version = dependencies.version ?? "0.0.0";
108
+ const io = dependencies.io ?? {
109
+ stdout: (line) => {
110
+ process.stdout.write(`${line}\n`);
111
+ },
112
+ stderr: (line) => {
113
+ process.stderr.write(`${line}\n`);
114
+ },
115
+ color: process.stdout.isTTY === true && env["NO_COLOR"] === undefined,
116
+ };
117
+ let store = dependencies.secrets ?? null;
118
+ const emitter = new LineEmitter({ stdout: io.stdout, stderr: io.stderr }, new Redactor(() => store === null || !(store instanceof CompositeSecretStore)
119
+ ? []
120
+ : store.names().map((name) => store?.get(name).digest() ?? "")));
121
+ let journal = null;
122
+ if (config.evidence.enabled && config.evidence.journalDir !== null) {
123
+ mkdirSync(config.evidence.journalDir, { recursive: true });
124
+ journal = new ChainJournal(config.evidence.journalDir, { checkpointLines: 100 });
125
+ }
126
+ const security = new SecurityEvents(emitter.security, {
127
+ chain: new HashChain(SECURITY_STREAM, journal?.restore(SECURITY_STREAM) ?? null),
128
+ });
129
+ emitter.reportRedactions((patterns) => security.emit({ event: "LEAK_SUSPECTED", patterns: [...patterns] }));
130
+ if (store === null && config.secrets.required.length > 0) {
131
+ store = CompositeSecretStore.fromEnvironment(env, config.secrets.required, {
132
+ events: security,
133
+ production: config.production,
134
+ enforcePermissions: config.production,
135
+ watch: false,
136
+ });
137
+ }
138
+ const secrets = store;
139
+ const demo = config.authority.kind === "LOCAL"
140
+ ? await (dependencies.demoAuthority ?? startDemoAuthority)()
141
+ : null;
142
+ const authorityUrl = demo === null ? config.authority.endpoint : demo.baseUrl;
143
+ const egress = new GuardedFetch({
144
+ policy: new EgressPolicy([
145
+ { origin: new URL(authorityUrl).origin, pathPrefixes: ["/"], ca: null, pins: [] },
146
+ ]),
147
+ events: security,
148
+ maxResponseBytes: 1024 * 1024,
149
+ ...(dependencies.authorityFetch === undefined
150
+ ? {}
151
+ : { transport: dependencies.authorityFetch }),
152
+ });
153
+ const apiKey = demo !== null
154
+ ? demo.apiKey
155
+ : () => secrets === null
156
+ ? ""
157
+ : secrets.get("DECIONIS_API_KEY").use((value) => value.toString("utf8"));
158
+ const connection = {
159
+ baseUrl: authorityUrl,
160
+ apiKey,
161
+ allowInsecureLoopback: demo !== null || config.authority.allowInsecureLoopback,
162
+ timeoutMs: config.authority.timeoutMs,
163
+ fetch: egress.fetch,
164
+ };
165
+ const gate = new DecionisGate({
166
+ ...connection,
167
+ mode: config.authority.mode,
168
+ source: { example: `agentsafe-gateway@${version}` },
169
+ });
170
+ const verifier = new DecionisGrantVerifier(connection);
171
+ const metrics = gatewayMetrics();
172
+ // Evidence lines: always in JSON mode; in human mode to the terminal only
173
+ // when asked, and to the journal directory's file whenever there is one.
174
+ const evidenceFile = config.evidence.enabled && config.evidence.journalDir !== null
175
+ ? join(config.evidence.journalDir, "evidence.jsonl")
176
+ : null;
177
+ const toTerminal = config.output.format === "JSON" || config.output.verbose;
178
+ const emitLine = (line) => {
179
+ if (evidenceFile !== null)
180
+ appendFileSync(evidenceFile, `${line}\n`);
181
+ if (toTerminal)
182
+ emitter.audit(line);
183
+ };
184
+ const upstream = new Upstream({
185
+ url: config.upstream.url,
186
+ timeoutMs: config.upstream.timeoutMs,
187
+ maxResponseBytes: config.upstream.maxResponseBytes,
188
+ fetch: dependencies.upstreamFetch ?? fetch,
189
+ });
190
+ const routes = new RouteTable(config.interception.routes, config.interception.unmatched, config.interception.http);
191
+ const evidence = new HashChain(EVIDENCE_STREAM, journal?.restore(EVIDENCE_STREAM) ?? null);
192
+ const chain = new HashChain(GATEWAY_STREAM, journal?.restore(GATEWAY_STREAM) ?? null);
193
+ const audit = new AuditRecorder({
194
+ sink: new HashChainedAuditSink(emitLine, evidence),
195
+ failurePolicy: config.evidence.enabled ? "REQUIRE_BEFORE_EXECUTION" : "BEST_EFFORT",
196
+ });
197
+ const gateway = new Gateway(config, upstream, routes, audit, gate, verifier, metrics, emitLine, io, security, secrets, demo, journal, evidence, chain, clock, version);
198
+ return gateway;
199
+ }
200
+ get authorityLabel() {
201
+ return this.demo !== null
202
+ ? "local/demo (synthetic policy on loopback; not Decionis)"
203
+ : `decionis ${this.config.authority.endpoint}`;
204
+ }
205
+ get evidenceLabel() {
206
+ if (this.config.evidence.journalDir !== null) {
207
+ return join(this.config.evidence.journalDir, "evidence.jsonl");
208
+ }
209
+ if (this.config.output.format === "JSON" || this.config.output.verbose)
210
+ return "terminal";
211
+ return "not written; use --verbose or evidence.journalDir";
212
+ }
213
+ /** The banner, once the listener is bound. */
214
+ started(gatewayUrl) {
215
+ this.report({
216
+ event: "GATEWAY_STARTED",
217
+ at: new Date(this.clock()).toISOString(),
218
+ gateway: gatewayUrl,
219
+ upstream: this.config.upstream.url,
220
+ mode: this.config.authority.mode,
221
+ authority: this.authorityLabel,
222
+ failure_policy: this.config.authority.failurePolicy,
223
+ routes: this.config.interception.routes.length,
224
+ evidence: this.evidenceLabel,
225
+ version: this.version,
226
+ });
227
+ this.link({
228
+ event: "GATEWAY_STARTED",
229
+ mode: this.config.authority.mode,
230
+ authority: this.demo === null ? "decionis" : "local/demo",
231
+ });
232
+ this.activation.started({
233
+ mode: this.config.authority.mode,
234
+ authority: this.config.authority.kind,
235
+ production: this.config.production,
236
+ });
237
+ }
238
+ stopped(signal) {
239
+ this.report({ event: "GATEWAY_STOPPED", at: new Date(this.clock()).toISOString(), signal });
240
+ }
241
+ plan(method, path) {
242
+ return this.routes.plan(method, path);
243
+ }
244
+ readiness() {
245
+ return {
246
+ ready: true,
247
+ body: {
248
+ ready: true,
249
+ mode: this.config.authority.mode,
250
+ authority: this.demo === null ? "decionis" : "local/demo",
251
+ },
252
+ };
253
+ }
254
+ status() {
255
+ return {
256
+ status: "ready",
257
+ version: this.version,
258
+ mode: this.config.authority.mode,
259
+ authority: this.demo === null ? "decionis" : "local/demo",
260
+ failure_policy: this.config.authority.failurePolicy,
261
+ upstream: this.config.upstream.url,
262
+ routes: this.config.interception.routes.length,
263
+ held: this.held.size,
264
+ counts: { ...this.counts },
265
+ evidence: this.evidence.head,
266
+ activation: this.activation.snapshot(),
267
+ };
268
+ }
269
+ metricsText() {
270
+ return this.metrics.registry.render();
271
+ }
272
+ /** A request that is not consequential: forwarded unchanged, counted, not evaluated. */
273
+ async passthrough(request) {
274
+ this.metrics.requests.inc({ kind: "passthrough" });
275
+ this.count("passthrough");
276
+ const startedAt = this.clock();
277
+ try {
278
+ const result = await this.upstream.send(request.method.toUpperCase(), request.path, request.search, this.upstream.headersFor(request), request.body, this.upstream.signal());
279
+ this.metrics.observeForwardLatency(this.clock() - startedAt);
280
+ return { status: result.status, headers: result.headers, body: result.body };
281
+ }
282
+ catch (error) {
283
+ return this.upstreamFailure(error);
284
+ }
285
+ }
286
+ /** A consequential request, through the whole lifecycle. */
287
+ async govern(request, action) {
288
+ this.metrics.requests.inc({ kind: "governed" });
289
+ this.count("governed");
290
+ const startedAt = this.clock();
291
+ let captured;
292
+ try {
293
+ captured = this.captureIntent(request, action);
294
+ }
295
+ catch (error) {
296
+ const code = error instanceof Error ? error.message : "INTENT_INVALID";
297
+ return this.own(code === "INTENT_TOO_LARGE" || code === "INTENT_TOO_COMPLEX" ? 413 : 400, {
298
+ state: "ERROR",
299
+ verdict: null,
300
+ reason_codes: [code],
301
+ execution: "NOT_FORWARDED",
302
+ });
303
+ }
304
+ this.metrics.interceptions.inc({ action });
305
+ this.count("interceptions");
306
+ this.activation.intercepted();
307
+ return await RequestContext.run({ principal: this.principalOf(captured) }, async () => {
308
+ if (this.shadow !== null)
309
+ return await this.observe(request, captured, startedAt);
310
+ return await this.enforce(request, captured, startedAt);
311
+ });
312
+ }
313
+ /** What a held escalation looks like from outside; null when nothing is held under the id. */
314
+ escalation(intentId) {
315
+ const entry = this.held.get(intentId);
316
+ if (entry === undefined)
317
+ return null;
318
+ return this.holdBody(entry);
319
+ }
320
+ /**
321
+ * Asks the authority again about a held intent. Only a fresh `ALLOW` with
322
+ * a grant executes, once; anything else is still held or refused. The
323
+ * gateway never turns the hold into permission on its own.
324
+ */
325
+ async resume(intentId) {
326
+ this.metrics.requests.inc({ kind: "control" });
327
+ const entry = this.held.get(intentId);
328
+ if (entry === undefined) {
329
+ return this.own(404, {
330
+ state: "ERROR",
331
+ verdict: null,
332
+ reason_codes: ["ESCALATION_NOT_HELD"],
333
+ execution: "NOT_FORWARDED",
334
+ });
335
+ }
336
+ if (entry.handoff === null || this.resolver === null) {
337
+ return this.own(409, {
338
+ state: "ESCALATE",
339
+ verdict: "ESCALATE",
340
+ reason_codes: ["ESCALATION_NOT_RESUMABLE", "PRESENCE_NOT_CONFIGURED"],
341
+ execution: "HELD",
342
+ intent_id: intentId,
343
+ decision_id: entry.decision.decisionId,
344
+ dossier_id: entry.decision.dossierId,
345
+ });
346
+ }
347
+ const startedAt = this.clock();
348
+ const resolution = await this.resolver.resume(entry.captured, {
349
+ ...entry.handoff,
350
+ intent: entry.captured.intent,
351
+ });
352
+ if (resolution.kind === "PENDING") {
353
+ return this.own(202, {
354
+ state: "ESCALATE",
355
+ verdict: "ESCALATE",
356
+ reason_codes: resolution.reasonCodes,
357
+ execution: "HELD",
358
+ intent_id: intentId,
359
+ decision_id: entry.decision.decisionId,
360
+ dossier_id: entry.decision.dossierId,
361
+ escalation: resolution.handoff,
362
+ });
363
+ }
364
+ this.release(intentId);
365
+ if (resolution.kind === "REFUSED") {
366
+ const state = resolution.failClosed ? "AUTHORITY_UNAVAILABLE" : "BLOCK";
367
+ this.link({
368
+ event: "ESCALATION_REFUSED",
369
+ intent_id: intentId,
370
+ reason_codes: [...resolution.reasonCodes],
371
+ fail_closed: resolution.failClosed,
372
+ });
373
+ return this.own(resolution.failClosed ? 503 : 403, {
374
+ state,
375
+ verdict: resolution.failClosed ? null : "BLOCK",
376
+ reason_codes: resolution.reasonCodes,
377
+ execution: "NOT_FORWARDED",
378
+ intent_id: intentId,
379
+ });
380
+ }
381
+ return await RequestContext.run({ principal: this.principalOf(entry.captured) }, () => this.execute(entry.request, entry.captured, resolution.decision, startedAt, null));
382
+ }
383
+ async close() {
384
+ for (const stop of this.stopFollowing)
385
+ stop();
386
+ this.held.clear();
387
+ if (this.demo !== null)
388
+ await this.demo.stop();
389
+ this.secrets?.close();
390
+ }
391
+ captureIntent(request, action) {
392
+ const normalized = normalizeRequest(request, action, {
393
+ maxEmbeddedBodyBytes: this.config.interception.maxEmbeddedBodyBytes,
394
+ principalHeader: this.config.interception.principalHeader,
395
+ });
396
+ const trusted = {
397
+ tenantId: this.config.authority.tenantId,
398
+ actor: this.config.actor,
399
+ downstreamTarget: {
400
+ system: this.config.upstream.system,
401
+ operation: action,
402
+ environment: this.config.upstream.environment,
403
+ endpoint: this.config.upstream.url,
404
+ },
405
+ context: {
406
+ ...normalized.context,
407
+ ingress: "http",
408
+ ...(normalized.principal === null ? {} : { claimed_principal: normalized.principal }),
409
+ },
410
+ idempotencyKey: normalized.idempotencyKey ?? randomUUID(),
411
+ ...(normalized.correlationId === null ? {} : { correlationId: normalized.correlationId }),
412
+ };
413
+ return this.capture.capture(normalized.proposal, trusted);
414
+ }
415
+ principalOf(captured) {
416
+ const claimed = captured.intent.context["claimed_principal"];
417
+ return typeof claimed === "string" ? claimed : this.config.actor.id;
418
+ }
419
+ async observe(request, captured, startedAt) {
420
+ const shadow = this.shadow;
421
+ if (shadow === null)
422
+ throw new Error("MODE_MISMATCH");
423
+ const forwardStarted = this.clock();
424
+ const run = await shadow.observe(captured, () => this.upstream.send(request.method.toUpperCase(), request.path, request.search, this.upstream.headersFor(request, { "x-agent-safe-intent-hash": captured.intentHash }), request.body, this.upstream.signal()));
425
+ this.metrics.observeForwardLatency(this.clock() - forwardStarted);
426
+ const production = run.production;
427
+ const upstreamStatus = production.status === "COMPLETED" ? production.result.status : null;
428
+ // The observation settles on its own bound and is reported when it does;
429
+ // the client's response never waits for the authority.
430
+ void run.observation.then((observation) => {
431
+ this.metrics.shadowDecisions.inc({ verdict: observation.verdict ?? "NONE" });
432
+ this.count("shadow");
433
+ this.report({
434
+ ...this.interception(request, captured, startedAt),
435
+ state: "SHADOW",
436
+ verdict: observation.verdict,
437
+ reason_codes: observation.status === "OBSERVED"
438
+ ? observation.reasonCodes
439
+ : [observation.status, ...observation.reasonCodes],
440
+ execution: "PASSTHROUGH",
441
+ decision_id: observation.decisionId,
442
+ dossier_id: observation.dossierId,
443
+ upstream_status: upstreamStatus,
444
+ finalization: null,
445
+ authority_ms: observation.durationMs,
446
+ });
447
+ });
448
+ if (production.status === "FAILED")
449
+ return this.upstreamFailure(production.error);
450
+ return this.relay(production.result, {
451
+ "agentsafe-mode": "SHADOW",
452
+ "agentsafe-execution": "PASSTHROUGH",
453
+ });
454
+ }
455
+ async enforce(request, captured, startedAt) {
456
+ const escalation = this.resolver;
457
+ if (escalation === null)
458
+ throw new Error("MODE_MISMATCH");
459
+ const authorityStarted = this.clock();
460
+ const decision = await escalation.evaluate(captured);
461
+ const authorityMs = this.clock() - authorityStarted;
462
+ this.metrics.observeAuthorityLatency(authorityMs);
463
+ if (decision.failClosed) {
464
+ return await this.unavailable(request, captured, decision, startedAt, authorityMs);
465
+ }
466
+ this.metrics.decisions.inc({ verdict: decision.verdict });
467
+ this.activation.governed();
468
+ if (decision.verdict === "ALLOW") {
469
+ this.metrics.allows.inc();
470
+ this.count("allows");
471
+ return await this.execute(request, captured, decision, startedAt, authorityMs);
472
+ }
473
+ // A BLOCK or an ESCALATE goes through the executor too, so the evidence
474
+ // chain carries the refusal in the same shape as an execution.
475
+ await this.executor.run(captured, decision);
476
+ if (decision.verdict === "BLOCK") {
477
+ this.metrics.blocks.inc();
478
+ this.count("blocks");
479
+ this.report({
480
+ ...this.interception(request, captured, startedAt),
481
+ state: "BLOCK",
482
+ verdict: "BLOCK",
483
+ reason_codes: decision.reasonCodes,
484
+ execution: "NOT_FORWARDED",
485
+ decision_id: decision.decisionId,
486
+ dossier_id: decision.dossierId,
487
+ upstream_status: null,
488
+ finalization: null,
489
+ authority_ms: authorityMs,
490
+ });
491
+ return this.own(403, {
492
+ state: "BLOCK",
493
+ verdict: "BLOCK",
494
+ reason_codes: decision.reasonCodes,
495
+ execution: "NOT_FORWARDED",
496
+ intent_id: captured.intent.intentId,
497
+ intent_hash: captured.intentHash,
498
+ decision_id: decision.decisionId,
499
+ dossier_id: decision.dossierId,
500
+ });
501
+ }
502
+ this.metrics.escalations.inc();
503
+ this.count("escalations");
504
+ const handoff = await escalation.handoff(captured, decision);
505
+ const reasonCodes = [
506
+ ...decision.reasonCodes,
507
+ ...(handoff === null && this.config.escalation.mode !== "NONE"
508
+ ? ["ESCALATION_HANDOFF_UNAVAILABLE"]
509
+ : []),
510
+ ];
511
+ const entry = {
512
+ captured,
513
+ request,
514
+ decision,
515
+ handoff: handoff === null ? null : { ...handoff, intent: captured.intent },
516
+ heldAt: new Date(this.clock()).toISOString(),
517
+ expiresAt: Date.parse(captured.intent.expiresAt),
518
+ };
519
+ const heldOk = this.hold(captured.intent.intentId, entry);
520
+ this.link({
521
+ event: "ESCALATION_HELD",
522
+ intent_id: captured.intent.intentId,
523
+ intent_hash: captured.intentHash,
524
+ decision_id: decision.decisionId,
525
+ dossier_id: decision.dossierId,
526
+ resumable: handoff !== null,
527
+ held: heldOk,
528
+ });
529
+ this.report({
530
+ ...this.interception(request, captured, startedAt),
531
+ state: "ESCALATE",
532
+ verdict: "ESCALATE",
533
+ reason_codes: reasonCodes,
534
+ execution: "HELD",
535
+ decision_id: decision.decisionId,
536
+ dossier_id: decision.dossierId,
537
+ upstream_status: null,
538
+ finalization: null,
539
+ authority_ms: authorityMs,
540
+ });
541
+ return this.own(202, {
542
+ state: "ESCALATE",
543
+ verdict: "ESCALATE",
544
+ reason_codes: heldOk ? reasonCodes : [...reasonCodes, "HOLD_CAPACITY_EXCEEDED"],
545
+ execution: "HELD",
546
+ intent_id: captured.intent.intentId,
547
+ intent_hash: captured.intentHash,
548
+ decision_id: decision.decisionId,
549
+ dossier_id: decision.dossierId,
550
+ escalation: entry.handoff === null ? null : this.handoffBody(entry.handoff),
551
+ resume: heldOk ? `${GATEWAY_PREFIX}/v1/escalations/${captured.intent.intentId}` : null,
552
+ expires_at: captured.intent.expiresAt,
553
+ });
554
+ }
555
+ /** The authority could not be asked: its own state, and never a policy BLOCK. */
556
+ async unavailable(request, captured, decision, startedAt, authorityMs) {
557
+ const code = decision.reasonCodes[0] ?? "AUTHORITY_UNAVAILABLE";
558
+ this.metrics.authorityErrors.inc({ code });
559
+ this.count("authority_errors");
560
+ // The refusal is evidence in the executor's own shape, fail-open or not.
561
+ await this.executor.run(captured, decision);
562
+ if (this.config.authority.failurePolicy === "FAIL_OPEN") {
563
+ this.metrics.ungoverned.inc();
564
+ this.count("ungoverned");
565
+ this.link({
566
+ event: "EXECUTION_UNGOVERNED",
567
+ intent_id: captured.intent.intentId,
568
+ intent_hash: captured.intentHash,
569
+ reason_codes: [...decision.reasonCodes],
570
+ failure_policy: "FAIL_OPEN",
571
+ });
572
+ const forwarded = await this.passthrough(request);
573
+ this.report({
574
+ ...this.interception(request, captured, startedAt),
575
+ state: "AUTHORITY_UNAVAILABLE",
576
+ verdict: null,
577
+ reason_codes: decision.reasonCodes,
578
+ execution: "FORWARDED_UNGOVERNED",
579
+ decision_id: null,
580
+ dossier_id: null,
581
+ upstream_status: forwarded.status,
582
+ finalization: null,
583
+ authority_ms: authorityMs,
584
+ });
585
+ return {
586
+ ...forwarded,
587
+ headers: [
588
+ ...forwarded.headers,
589
+ ["agentsafe-state", "AUTHORITY_UNAVAILABLE"],
590
+ ["agentsafe-execution", "FORWARDED_UNGOVERNED"],
591
+ ],
592
+ };
593
+ }
594
+ this.report({
595
+ ...this.interception(request, captured, startedAt),
596
+ state: "AUTHORITY_UNAVAILABLE",
597
+ verdict: null,
598
+ reason_codes: decision.reasonCodes,
599
+ execution: "NOT_FORWARDED",
600
+ decision_id: null,
601
+ dossier_id: null,
602
+ upstream_status: null,
603
+ finalization: null,
604
+ authority_ms: authorityMs,
605
+ });
606
+ return this.own(503, {
607
+ state: "AUTHORITY_UNAVAILABLE",
608
+ verdict: null,
609
+ reason_codes: decision.reasonCodes,
610
+ execution: "NOT_FORWARDED",
611
+ intent_id: captured.intent.intentId,
612
+ intent_hash: captured.intentHash,
613
+ }, { "retry-after": String(RETRY_AFTER_SECONDS) });
614
+ }
615
+ /** An ALLOW: the grant claimed, the exact request sent once, the outcome finalized and relayed. */
616
+ async execute(request, captured, decision, startedAt, authorityMs) {
617
+ const intentId = captured.intent.intentId;
618
+ this.holder.hold(intentId, request, {});
619
+ const forwardStarted = this.clock();
620
+ let outcome;
621
+ let forward;
622
+ try {
623
+ outcome = await this.executor.run(captured, decision);
624
+ }
625
+ finally {
626
+ forward = this.holder.release(intentId);
627
+ }
628
+ this.metrics.observeForwardLatency(this.clock() - forwardStarted);
629
+ const base = {
630
+ ...this.interception(request, captured, startedAt),
631
+ verdict: "ALLOW",
632
+ decision_id: decision.decisionId,
633
+ dossier_id: decision.dossierId,
634
+ authority_ms: authorityMs,
635
+ };
636
+ const finalization = "finalization" in outcome ? outcome.finalization : null;
637
+ const evidenceHeaders = {
638
+ "agentsafe-decision": "ALLOW",
639
+ ...(decision.dossierId === null ? {} : { "agentsafe-dossier-id": decision.dossierId }),
640
+ "agentsafe-intent-hash": captured.intentHash,
641
+ };
642
+ if (outcome.outcome === "COMPLETED") {
643
+ this.report({
644
+ ...base,
645
+ state: "ALLOW",
646
+ reason_codes: decision.reasonCodes,
647
+ execution: "FORWARDED",
648
+ upstream_status: outcome.result.status,
649
+ finalization,
650
+ });
651
+ return this.relay(outcome.result, { ...evidenceHeaders, "agentsafe-execution": "FORWARDED" });
652
+ }
653
+ if (outcome.outcome === "DEFINITELY_NOT_EXECUTED" && forward.response !== null) {
654
+ this.report({
655
+ ...base,
656
+ state: "EXECUTION_FAILED",
657
+ reason_codes: [outcome.reason],
658
+ execution: "FAILED",
659
+ upstream_status: forward.response.status,
660
+ finalization,
661
+ });
662
+ return this.relay(forward.response, { ...evidenceHeaders, "agentsafe-execution": "FAILED" });
663
+ }
664
+ if (outcome.outcome === "UNKNOWN_AFTER_DISPATCH") {
665
+ this.metrics.indeterminate.inc();
666
+ this.count("indeterminate");
667
+ const codes = [outcome.reason, ...(forward.failure === null ? [] : [forward.failure])];
668
+ this.report({
669
+ ...base,
670
+ state: "EXECUTION_INDETERMINATE",
671
+ reason_codes: codes,
672
+ execution: "INDETERMINATE",
673
+ upstream_status: forward.response?.status ?? null,
674
+ finalization,
675
+ });
676
+ if (forward.response !== null) {
677
+ return this.relay(forward.response, {
678
+ ...evidenceHeaders,
679
+ "agentsafe-execution": "INDETERMINATE",
680
+ });
681
+ }
682
+ return this.own(502, {
683
+ state: "EXECUTION_INDETERMINATE",
684
+ verdict: "ALLOW",
685
+ reason_codes: codes,
686
+ execution: "INDETERMINATE",
687
+ intent_id: intentId,
688
+ intent_hash: captured.intentHash,
689
+ decision_id: decision.decisionId,
690
+ dossier_id: decision.dossierId,
691
+ finalization,
692
+ });
693
+ }
694
+ // Blocked at the claim, or failed before anything was sent: nothing reached the upstream.
695
+ const reason = "reason" in outcome ? outcome.reason : "EXECUTION_BLOCKED";
696
+ const state = outcome.outcome === "BLOCKED" ? "ERROR" : "EXECUTION_FAILED";
697
+ this.report({
698
+ ...base,
699
+ state,
700
+ reason_codes: [reason],
701
+ execution: "NOT_FORWARDED",
702
+ upstream_status: null,
703
+ finalization,
704
+ });
705
+ return this.own(outcome.outcome === "BLOCKED" ? 503 : 502, {
706
+ state,
707
+ verdict: "ALLOW",
708
+ reason_codes: [reason],
709
+ execution: "NOT_FORWARDED",
710
+ intent_id: intentId,
711
+ intent_hash: captured.intentHash,
712
+ decision_id: decision.decisionId,
713
+ dossier_id: decision.dossierId,
714
+ finalization,
715
+ });
716
+ }
717
+ hold(intentId, entry) {
718
+ this.expireHeld();
719
+ if (this.held.size >= MAX_HELD)
720
+ return false;
721
+ this.held.set(intentId, entry);
722
+ this.metrics.held.set(this.held.size);
723
+ return true;
724
+ }
725
+ release(intentId) {
726
+ this.held.delete(intentId);
727
+ this.metrics.held.set(this.held.size);
728
+ }
729
+ expireHeld() {
730
+ const now = this.clock();
731
+ for (const [id, entry] of this.held) {
732
+ if (entry.expiresAt <= now)
733
+ this.held.delete(id);
734
+ }
735
+ this.metrics.held.set(this.held.size);
736
+ }
737
+ holdBody(entry) {
738
+ return {
739
+ version: GATEWAY_RESPONSE_VERSION,
740
+ state: "ESCALATE",
741
+ verdict: "ESCALATE",
742
+ execution: "HELD",
743
+ intent_id: entry.captured.intent.intentId,
744
+ intent_hash: entry.captured.intentHash,
745
+ decision_id: entry.decision.decisionId,
746
+ dossier_id: entry.decision.dossierId,
747
+ reason_codes: entry.decision.reasonCodes,
748
+ held_at: entry.heldAt,
749
+ expires_at: entry.captured.intent.expiresAt,
750
+ resumable: entry.handoff !== null,
751
+ escalation: entry.handoff === null ? null : this.handoffBody(entry.handoff),
752
+ };
753
+ }
754
+ /** The handoff without the intent, which the gateway holds itself. */
755
+ handoffBody(handoff) {
756
+ const { intent: _intent, ...rest } = handoff;
757
+ void _intent;
758
+ return rest;
759
+ }
760
+ interception(request, captured, startedAt) {
761
+ return {
762
+ event: "INTERCEPTED",
763
+ at: new Date(this.clock()).toISOString(),
764
+ method: request.method.toUpperCase(),
765
+ path: request.path,
766
+ action: captured.intent.action,
767
+ mode: this.config.authority.mode,
768
+ authority: this.demo === null ? "decionis" : "local/demo",
769
+ intent_id: captured.intent.intentId,
770
+ intent_hash: captured.intentHash,
771
+ latency_ms: Math.max(this.clock() - startedAt, 0),
772
+ };
773
+ }
774
+ relay(result, extra) {
775
+ return {
776
+ status: result.status,
777
+ headers: [...result.headers, ...Object.entries(extra)],
778
+ body: result.body,
779
+ };
780
+ }
781
+ upstreamFailure(error) {
782
+ const tooLarge = error instanceof Error && error.name === "UpstreamResponseTooLarge";
783
+ return this.own(502, {
784
+ state: "ERROR",
785
+ verdict: null,
786
+ reason_codes: [tooLarge ? "UPSTREAM_RESPONSE_TOO_LARGE" : "UPSTREAM_UNREACHABLE"],
787
+ execution: tooLarge ? "INDETERMINATE" : "NOT_FORWARDED",
788
+ });
789
+ }
790
+ /** A response the gateway itself makes: JSON, protective headers, the wire version. */
791
+ own(status, body, headers = {}) {
792
+ return {
793
+ status,
794
+ headers: [
795
+ ["content-type", "application/json; charset=utf-8"],
796
+ ["cache-control", "no-store"],
797
+ ["x-content-type-options", "nosniff"],
798
+ ["agentsafe-state", body.state],
799
+ ["agentsafe-execution", body.execution],
800
+ ...Object.entries(headers),
801
+ ],
802
+ body: Buffer.from(JSON.stringify({ version: GATEWAY_RESPONSE_VERSION, ...body }), "utf8"),
803
+ };
804
+ }
805
+ report(report) {
806
+ if (this.config.output.format === "JSON")
807
+ this.io.stdout(renderJson(report));
808
+ else
809
+ this.io.stdout(renderHuman(report, { color: this.io.color }));
810
+ }
811
+ /** One chained line on the gateway's own stream. */
812
+ link(fields) {
813
+ this.chain.link({ at: new Date(this.clock()).toISOString(), ...fields }, this.emitLine);
814
+ }
815
+ count(name) {
816
+ this.counts[name] = (this.counts[name] ?? 0) + 1;
817
+ }
818
+ }
819
+ //# sourceMappingURL=Gateway.js.map