@open-everywhere/core 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 (3606) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +21 -0
  3. package/README.md +67 -0
  4. package/agent/access/access-referenced-link-sets.ts +23 -0
  5. package/agent/access/admin-read-venue.ts +159 -0
  6. package/agent/access/admin-standing.ts +98 -0
  7. package/agent/access/analytics-scope.ts +84 -0
  8. package/agent/access/approval-dedupe.ts +144 -0
  9. package/agent/access/approval-judge.ts +639 -0
  10. package/agent/access/approval-preview.ts +118 -0
  11. package/agent/access/approval-scenarios.ts +48 -0
  12. package/agent/access/approver-chain.ts +779 -0
  13. package/agent/access/audience-floor.ts +270 -0
  14. package/agent/access/aws-output.ts +132 -0
  15. package/agent/access/aws-screen.ts +198 -0
  16. package/agent/access/background-tasks.ts +364 -0
  17. package/agent/access/browser-hosts.ts +151 -0
  18. package/agent/access/browser-toolkit.ts +271 -0
  19. package/agent/access/bundle.ts +716 -0
  20. package/agent/access/capabilities.ts +11 -0
  21. package/agent/access/chat-dm-grant.ts +241 -0
  22. package/agent/access/chat-write-grant.ts +194 -0
  23. package/agent/access/config.ts +132 -0
  24. package/agent/access/connector-content-origin-state.ts +72 -0
  25. package/agent/access/connector-credentials.ts +449 -0
  26. package/agent/access/connector-disclosure.ts +253 -0
  27. package/agent/access/connector-op-gating.ts +224 -0
  28. package/agent/access/connector-scope.ts +302 -0
  29. package/agent/access/consequence.ts +1208 -0
  30. package/agent/access/credential-bindings-codemod.ts +242 -0
  31. package/agent/access/credential-endpoints.ts +279 -0
  32. package/agent/access/credential-grant-ask.ts +115 -0
  33. package/agent/access/credential-grant-broker.ts +359 -0
  34. package/agent/access/credential-grant-card.ts +521 -0
  35. package/agent/access/credential-grant-click.ts +246 -0
  36. package/agent/access/credential-grant-copy.ts +338 -0
  37. package/agent/access/credential-grant-flow.ts +735 -0
  38. package/agent/access/credential-grant-key-shape.ts +59 -0
  39. package/agent/access/credential-grant-notice.ts +219 -0
  40. package/agent/access/credential-grant-owner.ts +23 -0
  41. package/agent/access/credential-grant-reach.ts +81 -0
  42. package/agent/access/credential-grant-resolution.ts +119 -0
  43. package/agent/access/credential-grant-revoke.ts +95 -0
  44. package/agent/access/credential-grant-scope.ts +306 -0
  45. package/agent/access/credential-grant.ts +284 -0
  46. package/agent/access/credentials.ts +159 -0
  47. package/agent/access/dated-read.ts +18 -0
  48. package/agent/access/delegation-flag.ts +12 -0
  49. package/agent/access/delegation-mount.ts +28 -0
  50. package/agent/access/delta.ts +386 -0
  51. package/agent/access/dispatch-origin-signal.ts +133 -0
  52. package/agent/access/domain-credentials.ts +115 -0
  53. package/agent/access/egress-denial-log.ts +111 -0
  54. package/agent/access/egress-denial-poller.ts +239 -0
  55. package/agent/access/egress-status.ts +195 -0
  56. package/agent/access/egress.ts +321 -0
  57. package/agent/access/enforcement.ts +25 -0
  58. package/agent/access/eve-patch-probe-boot.ts +91 -0
  59. package/agent/access/eve-patch-probe.ts +276 -0
  60. package/agent/access/external-policy.ts +209 -0
  61. package/agent/access/extra-hosts.ts +31 -0
  62. package/agent/access/grant-borrow-transport-registry.internal.ts +81 -0
  63. package/agent/access/grant-room-notice-registry.internal.ts +77 -0
  64. package/agent/access/grant-schema-pin.ts +38 -0
  65. package/agent/access/grants-codemod.ts +352 -0
  66. package/agent/access/group-request.ts +76 -0
  67. package/agent/access/halt-state.ts +24 -0
  68. package/agent/access/halt.ts +276 -0
  69. package/agent/access/host-egress.ts +432 -0
  70. package/agent/access/human-only-invariants-manifest.ts +172 -0
  71. package/agent/access/ingestion-binding-manifest.ts +263 -0
  72. package/agent/access/ingestion-route-inventory.generated.ts +58 -0
  73. package/agent/access/instructions.ts +89 -0
  74. package/agent/access/invoker-posture-state.ts +25 -0
  75. package/agent/access/invoker-posture.ts +96 -0
  76. package/agent/access/job-posture.ts +83 -0
  77. package/agent/access/job-session-state.ts +58 -0
  78. package/agent/access/lean-seat-state.ts +45 -0
  79. package/agent/access/lean-seat.ts +83 -0
  80. package/agent/access/lint.ts +638 -0
  81. package/agent/access/live-delegated-tasks.ts +95 -0
  82. package/agent/access/loop-breaker.ts +88 -0
  83. package/agent/access/mcp-call-fence.ts +179 -0
  84. package/agent/access/member-grant.ts +45 -0
  85. package/agent/access/member-plane.ts +212 -0
  86. package/agent/access/native-admin.ts +35 -0
  87. package/agent/access/native-delegation-state.ts +40 -0
  88. package/agent/access/network-access.ts +132 -0
  89. package/agent/access/nullable-optional-fields.ts +184 -0
  90. package/agent/access/overlay-module.ts +70 -0
  91. package/agent/access/own-account-gate-manifest.ts +134 -0
  92. package/agent/access/pane-venue.ts +238 -0
  93. package/agent/access/pending-delegation-signal.ts +282 -0
  94. package/agent/access/permission-evidence.ts +627 -0
  95. package/agent/access/permission-proposal.ts +362 -0
  96. package/agent/access/platform.ts +14 -0
  97. package/agent/access/pre-approval-rules.ts +135 -0
  98. package/agent/access/principal-gate-manifest.ts +830 -0
  99. package/agent/access/provider-selection-check.ts +130 -0
  100. package/agent/access/provider-selection.ts +96 -0
  101. package/agent/access/read-grant.ts +104 -0
  102. package/agent/access/repo-capabilities.ts +74 -0
  103. package/agent/access/request.ts +126 -0
  104. package/agent/access/requester-identity.ts +305 -0
  105. package/agent/access/requester-messages.ts +52 -0
  106. package/agent/access/reserved-hosts.ts +11 -0
  107. package/agent/access/resolver.ts +604 -0
  108. package/agent/access/resource-capabilities.ts +103 -0
  109. package/agent/access/resource-grant-manifest.ts +136 -0
  110. package/agent/access/resource-grant.ts +163 -0
  111. package/agent/access/result-cap.ts +34 -0
  112. package/agent/access/result-reduce-model-arm.ts +94 -0
  113. package/agent/access/result-reduce.ts +104 -0
  114. package/agent/access/roles.ts +106 -0
  115. package/agent/access/scope-key.ts +50 -0
  116. package/agent/access/seat-read-budget.ts +57 -0
  117. package/agent/access/self-host-egress.ts +103 -0
  118. package/agent/access/settlement-dispatch-signal.ts +96 -0
  119. package/agent/access/skill-taint-envelope.ts +94 -0
  120. package/agent/access/source-gate-manifest.ts +148 -0
  121. package/agent/access/source-scoped-mount.ts +27 -0
  122. package/agent/access/subagent-taint.ts +225 -0
  123. package/agent/access/surface-work-grant.ts +91 -0
  124. package/agent/access/taint-enforcement.ts +183 -0
  125. package/agent/access/taint-signal.ts +297 -0
  126. package/agent/access/taint-tiers.ts +168 -0
  127. package/agent/access/task-wake-signal.ts +94 -0
  128. package/agent/access/tenant-admission.ts +191 -0
  129. package/agent/access/untrusted-projection.ts +273 -0
  130. package/agent/access/untrusted.ts +132 -0
  131. package/agent/access/wake-mapping.ts +38 -0
  132. package/agent/access/web-fetch-fence.ts +81 -0
  133. package/agent/access/window-gate-manifest.ts +543 -0
  134. package/agent/access/window-gated.ts +668 -0
  135. package/agent/access/window-routing.ts +23 -0
  136. package/agent/access/work-grant.ts +119 -0
  137. package/agent/access/work-mount-manifest.ts +203 -0
  138. package/agent/access/worker-capabilities.ts +379 -0
  139. package/agent/access/worker-capability-index.generated.ts +189 -0
  140. package/agent/access/worker-continuation.ts +200 -0
  141. package/agent/access/worker-seat-state.ts +25 -0
  142. package/agent/access/worker-seat.ts +54 -0
  143. package/agent/access/worker-toolset-state.ts +65 -0
  144. package/agent/adapter-api.ts +1795 -0
  145. package/agent/analytics/compile.ts +461 -0
  146. package/agent/analytics/execute.ts +166 -0
  147. package/agent/analytics/registry.ts +302 -0
  148. package/agent/approvals/access-request.ts +255 -0
  149. package/agent/approvals/actions.ts +398 -0
  150. package/agent/approvals/agent-create.ts +272 -0
  151. package/agent/approvals/arming-context.ts +26 -0
  152. package/agent/approvals/card-disclosure.ts +53 -0
  153. package/agent/approvals/card-signal.ts +151 -0
  154. package/agent/approvals/card-venue.ts +152 -0
  155. package/agent/approvals/card.ts +121 -0
  156. package/agent/approvals/chat-dm.ts +63 -0
  157. package/agent/approvals/chat-post.ts +60 -0
  158. package/agent/approvals/clicker-floor.ts +106 -0
  159. package/agent/approvals/decision-authority.internal.ts +114 -0
  160. package/agent/approvals/decision-wake.ts +122 -0
  161. package/agent/approvals/domain-exposure.ts +182 -0
  162. package/agent/approvals/eve-response-policy.ts +48 -0
  163. package/agent/approvals/flow.ts +2185 -0
  164. package/agent/approvals/input-response-floor.ts +104 -0
  165. package/agent/approvals/judge-contradiction.ts +156 -0
  166. package/agent/approvals/memory-purge.ts +149 -0
  167. package/agent/approvals/pr-open.ts +172 -0
  168. package/agent/approvals/review-surface.ts +7 -0
  169. package/agent/approvals/routine-cancel.ts +57 -0
  170. package/agent/approvals/routine-create.ts +213 -0
  171. package/agent/approvals/routine-lifecycle.ts +206 -0
  172. package/agent/approvals/routine-permission-offer.ts +131 -0
  173. package/agent/approvals/routine-permission.ts +214 -0
  174. package/agent/approvals/routine-policy.ts +174 -0
  175. package/agent/approvals/scope-label.ts +48 -0
  176. package/agent/approvals/session-checkpoint.ts +80 -0
  177. package/agent/approvals/session-grant.ts +173 -0
  178. package/agent/approvals/skill-create.ts +60 -0
  179. package/agent/approvals/skill-delete.ts +50 -0
  180. package/agent/approvals/taint-disclosure.ts +42 -0
  181. package/agent/approvals/ticket-actions.ts +86 -0
  182. package/agent/approvals/ticket-create.ts +67 -0
  183. package/agent/approvals/types.ts +48 -0
  184. package/agent/approvals/webhook-declare.ts +297 -0
  185. package/agent/approvals/webhook.ts +205 -0
  186. package/agent/audit/action-registry.ts +1094 -0
  187. package/agent/audit/audit.ts +105 -0
  188. package/agent/audit/chain.ts +568 -0
  189. package/agent/audit/tool-action.ts +286 -0
  190. package/agent/audit/window-tool-gate.ts +54 -0
  191. package/agent/audit/worker-toolset.ts +117 -0
  192. package/agent/blob/hosting.ts +180 -0
  193. package/agent/channels/access-request-ledger.ts +139 -0
  194. package/agent/channels/ambient-skip.ts +102 -0
  195. package/agent/channels/answered-container-ledger.ts +76 -0
  196. package/agent/channels/approval-card.ts +454 -0
  197. package/agent/channels/approval-claim-guard.ts +384 -0
  198. package/agent/channels/attachments.ts +243 -0
  199. package/agent/channels/aws-sso-callback.ts +9 -0
  200. package/agent/channels/backscroll-window.ts +145 -0
  201. package/agent/channels/cancel-note.ts +127 -0
  202. package/agent/channels/channel-key.ts +56 -0
  203. package/agent/channels/channel-read.ts +501 -0
  204. package/agent/channels/chat-turn-audit.ts +23 -0
  205. package/agent/channels/closing-prose-drop.ts +53 -0
  206. package/agent/channels/command-registration.ts +165 -0
  207. package/agent/channels/context-render.ts +206 -0
  208. package/agent/channels/control-mcp.ts +44 -0
  209. package/agent/channels/control-read.ts +37 -0
  210. package/agent/channels/credential-intake-page.ts +12 -0
  211. package/agent/channels/delegated-provenance.ts +506 -0
  212. package/agent/channels/dm-audience.ts +346 -0
  213. package/agent/channels/dm-seat.ts +138 -0
  214. package/agent/channels/domain-fingerprint.ts +90 -0
  215. package/agent/channels/egress-spoof.ts +35 -0
  216. package/agent/channels/engaged-wake.ts +158 -0
  217. package/agent/channels/engagement.ts +254 -0
  218. package/agent/channels/entity-actions.ts +186 -0
  219. package/agent/channels/front-queue.ts +78 -0
  220. package/agent/channels/generation-retirement.ts +557 -0
  221. package/agent/channels/halt-per-wake.ts +166 -0
  222. package/agent/channels/memory-claim-guard.ts +425 -0
  223. package/agent/channels/name-drop-wake-audit.ts +162 -0
  224. package/agent/channels/native-wake-retry.ts +62 -0
  225. package/agent/channels/no-reply-signal.ts +49 -0
  226. package/agent/channels/normalized-wake.ts +285 -0
  227. package/agent/channels/oe-oauth-callback.ts +13 -0
  228. package/agent/channels/own-post-ledger.ts +76 -0
  229. package/agent/channels/platform-failure.ts +45 -0
  230. package/agent/channels/policy-pages.ts +15 -0
  231. package/agent/channels/post-arms.ts +321 -0
  232. package/agent/channels/proactive-dm-manifest.ts +113 -0
  233. package/agent/channels/propose-scope.ts +90 -0
  234. package/agent/channels/question-bridge.ts +594 -0
  235. package/agent/channels/rate-limit-retry.ts +355 -0
  236. package/agent/channels/react-signal.ts +26 -0
  237. package/agent/channels/reaction-ingest.ts +221 -0
  238. package/agent/channels/read-author-trust.ts +71 -0
  239. package/agent/channels/read-reach.ts +339 -0
  240. package/agent/channels/read-scope-audit.ts +127 -0
  241. package/agent/channels/read-scope-error.ts +5 -0
  242. package/agent/channels/read-spool.ts +131 -0
  243. package/agent/channels/reply-edit.ts +208 -0
  244. package/agent/channels/reply-fold.ts +517 -0
  245. package/agent/channels/reply-freshness.ts +253 -0
  246. package/agent/channels/reply-post.ts +502 -0
  247. package/agent/channels/reply-provenance.ts +804 -0
  248. package/agent/channels/reply-signal.ts +723 -0
  249. package/agent/channels/request-claim-guard.ts +532 -0
  250. package/agent/channels/runtime-code-fingerprint.generated.ts +10 -0
  251. package/agent/channels/runtime-rotation.ts +224 -0
  252. package/agent/channels/seat-admission.ts +103 -0
  253. package/agent/channels/seat-catch-up.ts +482 -0
  254. package/agent/channels/self-dispatch.ts +349 -0
  255. package/agent/channels/session-park.ts +252 -0
  256. package/agent/channels/session-resume.ts +36 -0
  257. package/agent/channels/session-tail-record.ts +172 -0
  258. package/agent/channels/session-tail.ts +140 -0
  259. package/agent/channels/slack-bridge.ts +125 -0
  260. package/agent/channels/stand-down-silence.ts +110 -0
  261. package/agent/channels/standing-authority.ts +237 -0
  262. package/agent/channels/stranded-seat.ts +155 -0
  263. package/agent/channels/supervisor-complete.ts +141 -0
  264. package/agent/channels/surface-message-ops.ts +217 -0
  265. package/agent/channels/task-wake.ts +528 -0
  266. package/agent/channels/teams-bridge.ts +85 -0
  267. package/agent/channels/test-wake.ts +12 -0
  268. package/agent/channels/thread-ownership.ts +70 -0
  269. package/agent/channels/thread-seat-state.ts +90 -0
  270. package/agent/channels/ticket-create.ts +171 -0
  271. package/agent/channels/transcript-relay.ts +9 -0
  272. package/agent/channels/turn-cancel.ts +431 -0
  273. package/agent/channels/turn-delivery.ts +484 -0
  274. package/agent/channels/turn-registry.ts +117 -0
  275. package/agent/channels/turn-terminal-actions.ts +134 -0
  276. package/agent/channels/unified-redrive.ts +215 -0
  277. package/agent/channels/unified-reply.ts +300 -0
  278. package/agent/channels/unified-supervisor.ts +193 -0
  279. package/agent/channels/unified-window.ts +1075 -0
  280. package/agent/channels/unified.ts +1575 -0
  281. package/agent/channels/wake-accounting.ts +121 -0
  282. package/agent/channels/wake-arm.ts +244 -0
  283. package/agent/channels/wake-container.ts +50 -0
  284. package/agent/channels/wake-envelope.ts +632 -0
  285. package/agent/channels/wake-origin-codec.ts +96 -0
  286. package/agent/channels/wake-origin-codecs.ts +4 -0
  287. package/agent/channels/wake-timing.ts +401 -0
  288. package/agent/channels/webhook-reveal-page.ts +12 -0
  289. package/agent/channels/webhooks.ts +216 -0
  290. package/agent/channels/window-key.ts +439 -0
  291. package/agent/channels/window-sources.ts +88 -0
  292. package/agent/channels/work-destinations.ts +48 -0
  293. package/agent/channels/work-registry.ts +26 -0
  294. package/agent/channels/work-search.ts +92 -0
  295. package/agent/commands/core.ts +737 -0
  296. package/agent/commands/rate.ts +173 -0
  297. package/agent/connections/auth-retry-memo.ts +115 -0
  298. package/agent/connections/aws-exec.ts +52 -0
  299. package/agent/connections/aws-identity.ts +297 -0
  300. package/agent/connections/aws-sso-callback.ts +103 -0
  301. package/agent/connections/aws-sso-identity-binding.ts +115 -0
  302. package/agent/connections/aws-sso-link.ts +40 -0
  303. package/agent/connections/connector-auth.ts +984 -0
  304. package/agent/connections/connector-card.ts +447 -0
  305. package/agent/connections/connector-flags.ts +44 -0
  306. package/agent/connections/connector-offer.ts +241 -0
  307. package/agent/connections/connector-transport.ts +131 -0
  308. package/agent/connections/consent-resume.ts +205 -0
  309. package/agent/connections/grant-mcp-borrow.ts +334 -0
  310. package/agent/connections/grant-mcp-transport.ts +64 -0
  311. package/agent/connections/notion.ts +42 -0
  312. package/agent/connections/oe-oauth-callback.ts +207 -0
  313. package/agent/connections/own-account-ask.ts +302 -0
  314. package/agent/connections/own-account-carriage.ts +99 -0
  315. package/agent/connections/own-account-gate.ts +361 -0
  316. package/agent/connections/own-account-vendors.ts +117 -0
  317. package/agent/connections/user-auth-flow.ts +102 -0
  318. package/agent/contributions.ts +197 -0
  319. package/agent/control/auth.ts +663 -0
  320. package/agent/control/capture-window-read.ts +382 -0
  321. package/agent/control/delivery-history.ts +558 -0
  322. package/agent/control/http.ts +169 -0
  323. package/agent/control/mcp-route.ts +105 -0
  324. package/agent/control/oauth-clients.ts +278 -0
  325. package/agent/control/oauth-resource.ts +200 -0
  326. package/agent/control/oauth-route.ts +397 -0
  327. package/agent/control/oauth-tokens.ts +222 -0
  328. package/agent/control/read-route.ts +841 -0
  329. package/agent/control/server.ts +540 -0
  330. package/agent/control/test-route.ts +527 -0
  331. package/agent/control/transcript-export.ts +197 -0
  332. package/agent/control/transcript-relay.ts +381 -0
  333. package/agent/control/transcript-render.ts +164 -0
  334. package/agent/control/views.ts +1289 -0
  335. package/agent/control/writes.ts +1431 -0
  336. package/agent/credentials/binding-pr.ts +247 -0
  337. package/agent/credentials/config-pr-github.ts +197 -0
  338. package/agent/credentials/config-pr.ts +180 -0
  339. package/agent/credentials/db-broker.ts +270 -0
  340. package/agent/credentials/home.ts +83 -0
  341. package/agent/credentials/intake-page.ts +302 -0
  342. package/agent/credentials/intake.ts +550 -0
  343. package/agent/credentials/kv-vault.ts +180 -0
  344. package/agent/credentials/operator-secrets.ts +396 -0
  345. package/agent/credentials/page-chrome.ts +59 -0
  346. package/agent/credentials/page-token.ts +219 -0
  347. package/agent/credentials/purge.ts +113 -0
  348. package/agent/credentials/ref.ts +151 -0
  349. package/agent/credentials/reserved-refs.ts +76 -0
  350. package/agent/credentials/self-secrets.ts +165 -0
  351. package/agent/credentials/warm.ts +209 -0
  352. package/agent/docs/approver-policy.ts +234 -0
  353. package/agent/docs/capability-map.ts +180 -0
  354. package/agent/docs/counted-claims.ts +433 -0
  355. package/agent/docs/registry.ts +184 -0
  356. package/agent/docs/source-map.ts +174 -0
  357. package/agent/hooks/approval-raised.ts +37 -0
  358. package/agent/hooks/approval-settlement.ts +109 -0
  359. package/agent/hooks/binding-bridge.ts +77 -0
  360. package/agent/hooks/connector-audit.ts +111 -0
  361. package/agent/hooks/egress.ts +694 -0
  362. package/agent/hooks/eve-patch-gate.ts +52 -0
  363. package/agent/hooks/fire-carriage.ts +44 -0
  364. package/agent/hooks/fire-toolset.ts +306 -0
  365. package/agent/hooks/job-posture.ts +82 -0
  366. package/agent/hooks/lean-seat.ts +233 -0
  367. package/agent/hooks/learn.ts +199 -0
  368. package/agent/hooks/link-claim.ts +269 -0
  369. package/agent/hooks/log-flush.ts +32 -0
  370. package/agent/hooks/loop-breaker.ts +17 -0
  371. package/agent/hooks/memory.ts +1250 -0
  372. package/agent/hooks/native-input-audit.ts +41 -0
  373. package/agent/hooks/own-account-ask.ts +172 -0
  374. package/agent/hooks/requester-identity.ts +30 -0
  375. package/agent/hooks/requester-messages.ts +55 -0
  376. package/agent/hooks/routine-outcome.ts +252 -0
  377. package/agent/hooks/routine-silence.ts +38 -0
  378. package/agent/hooks/session-park.ts +48 -0
  379. package/agent/hooks/settlement-flush.ts +173 -0
  380. package/agent/hooks/spawn-taint.ts +1312 -0
  381. package/agent/hooks/spend.ts +368 -0
  382. package/agent/hooks/stall-guard.ts +22 -0
  383. package/agent/hooks/telemetry.ts +90 -0
  384. package/agent/hooks/turn-anchor.ts +682 -0
  385. package/agent/hooks/turn-tally.ts +98 -0
  386. package/agent/hooks/wake-accounting-turn.ts +96 -0
  387. package/agent/hooks/wake-turn-start.ts +44 -0
  388. package/agent/hooks/window-routing.ts +51 -0
  389. package/agent/identity/account-directory.ts +138 -0
  390. package/agent/identity/account-display-name.ts +178 -0
  391. package/agent/identity/author-trust.ts +297 -0
  392. package/agent/identity/binding-bridge.ts +88 -0
  393. package/agent/identity/binding.ts +1308 -0
  394. package/agent/identity/bot-display-name.ts +50 -0
  395. package/agent/identity/bot-name.ts +79 -0
  396. package/agent/identity/capabilities.ts +79 -0
  397. package/agent/identity/delegated-binding.ts +130 -0
  398. package/agent/identity/deployment-identity.ts +105 -0
  399. package/agent/identity/directory-sync.ts +777 -0
  400. package/agent/identity/directory.ts +89 -0
  401. package/agent/identity/display-title.ts +19 -0
  402. package/agent/identity/frozen-surface-binding.internal.ts +83 -0
  403. package/agent/identity/group-sync.ts +169 -0
  404. package/agent/identity/groups-codemod.ts +142 -0
  405. package/agent/identity/groups-delivery.ts +156 -0
  406. package/agent/identity/groups.ts +174 -0
  407. package/agent/identity/link-challenge.ts +147 -0
  408. package/agent/identity/link-consent.ts +216 -0
  409. package/agent/identity/link-flow.ts +380 -0
  410. package/agent/identity/link-initiator.ts +27 -0
  411. package/agent/identity/link-resolve.ts +227 -0
  412. package/agent/identity/link-set-ref.ts +33 -0
  413. package/agent/identity/link-store.ts +889 -0
  414. package/agent/identity/link-tenant-backfill.ts +79 -0
  415. package/agent/identity/link-tenant.ts +54 -0
  416. package/agent/identity/oauth-vault-share.ts +40 -0
  417. package/agent/identity/platform.ts +48 -0
  418. package/agent/identity/principal-key-rules.ts +113 -0
  419. package/agent/identity/principal-key.ts +210 -0
  420. package/agent/identity/principals.ts +354 -0
  421. package/agent/identity/surface-key-grammar.ts +142 -0
  422. package/agent/identity/surface-parity.ts +427 -0
  423. package/agent/identity/trust-preflight.ts +271 -0
  424. package/agent/identity/trust.ts +433 -0
  425. package/agent/identity/wake-trust.ts +217 -0
  426. package/agent/instructions/access.ts +1239 -0
  427. package/agent/instructions/seat-prompt.ts +1286 -0
  428. package/agent/lib/process-registry.ts +52 -0
  429. package/agent/memory/agents-codemod.ts +443 -0
  430. package/agent/memory/connector-memory.ts +137 -0
  431. package/agent/memory/domain.ts +1276 -0
  432. package/agent/memory/dream/candidates.ts +187 -0
  433. package/agent/memory/dream/correction.ts +133 -0
  434. package/agent/memory/dream/judge.ts +174 -0
  435. package/agent/memory/dream/learn.ts +299 -0
  436. package/agent/memory/dream/mode3-cluster.ts +151 -0
  437. package/agent/memory/dream/mode3-last-mile.ts +365 -0
  438. package/agent/memory/dream/mode3.ts +311 -0
  439. package/agent/memory/dream/ops.ts +321 -0
  440. package/agent/memory/dream/proposal.ts +83 -0
  441. package/agent/memory/dream/recurrence.ts +132 -0
  442. package/agent/memory/dream/salience.ts +24 -0
  443. package/agent/memory/dream/skill-proposal-pr.ts +323 -0
  444. package/agent/memory/dream/supersede-apply.ts +94 -0
  445. package/agent/memory/dream/tidy.ts +162 -0
  446. package/agent/memory/graph.ts +178 -0
  447. package/agent/memory/host-owned-files.ts +3 -0
  448. package/agent/memory/layout.ts +85 -0
  449. package/agent/memory/listing.ts +199 -0
  450. package/agent/memory/markdown.ts +211 -0
  451. package/agent/memory/partition.ts +66 -0
  452. package/agent/memory/postgres.ts +497 -0
  453. package/agent/memory/provenance-mark.ts +318 -0
  454. package/agent/memory/provenance.ts +28 -0
  455. package/agent/memory/provider.ts +186 -0
  456. package/agent/memory/purge-redaction.ts +68 -0
  457. package/agent/memory/readonly.ts +57 -0
  458. package/agent/memory/resolve.ts +181 -0
  459. package/agent/memory/root-fence.ts +54 -0
  460. package/agent/memory/sandbox-sync.ts +84 -0
  461. package/agent/memory/selection.ts +120 -0
  462. package/agent/memory/silo.ts +71 -0
  463. package/agent/memory/sqlite.ts +206 -0
  464. package/agent/memory/store.ts +162 -0
  465. package/agent/memory/sync-timing.ts +223 -0
  466. package/agent/memory/wake-delta.ts +239 -0
  467. package/agent/memory/write-evidence.ts +150 -0
  468. package/agent/memory/write-fence.ts +145 -0
  469. package/agent/memory/write-intent.ts +205 -0
  470. package/agent/memory/write-road.ts +159 -0
  471. package/agent/model/ab-test.ts +374 -0
  472. package/agent/model/call-capture.ts +414 -0
  473. package/agent/model/default-model.ts +63 -0
  474. package/agent/model/model-stamp.ts +162 -0
  475. package/agent/model/policy.ts +378 -0
  476. package/agent/model/routing.ts +834 -0
  477. package/agent/model/step-boundary.ts +560 -0
  478. package/agent/model/stream-drop-retry.ts +334 -0
  479. package/agent/model/turn-closeout.ts +299 -0
  480. package/agent/model/turn-state.ts +461 -0
  481. package/agent/model/vision.ts +112 -0
  482. package/agent/observability/ship.ts +394 -0
  483. package/agent/observability/telemetry.ts +819 -0
  484. package/agent/observability/turn-clock.ts +96 -0
  485. package/agent/onboarding/onboarding.ts +98 -0
  486. package/agent/operational/credential-grant-rows.ts +944 -0
  487. package/agent/operational/pglite-client.ts +282 -0
  488. package/agent/operational/post-once.ts +146 -0
  489. package/agent/operational/postgres.ts +5030 -0
  490. package/agent/operational/provider.ts +190 -0
  491. package/agent/operational/sqlite.ts +4007 -0
  492. package/agent/operational/store.ts +2346 -0
  493. package/agent/ops/census.ts +1076 -0
  494. package/agent/ops/probes.ts +69 -0
  495. package/agent/ops/quickstart.ts +296 -0
  496. package/agent/ops/server.ts +485 -0
  497. package/agent/ops/surface-manifest.ts +111 -0
  498. package/agent/ops/two-role.ts +75 -0
  499. package/agent/pages/policy-pages.ts +79 -0
  500. package/agent/plugins/extract.ts +381 -0
  501. package/agent/plugins/parse.ts +122 -0
  502. package/agent/plugins/types.ts +147 -0
  503. package/agent/publish/eve-patch-pack.ts +461 -0
  504. package/agent/review/blast-radius.ts +282 -0
  505. package/agent/review/config-facts.ts +200 -0
  506. package/agent/review/facts-artifact.ts +377 -0
  507. package/agent/review/facts-cloud-status.ts +288 -0
  508. package/agent/review/pr-walkthrough.ts +772 -0
  509. package/agent/review/zip.ts +154 -0
  510. package/agent/roles/role.ts +228 -0
  511. package/agent/routines/bound.ts +262 -0
  512. package/agent/routines/check-in.ts +54 -0
  513. package/agent/routines/collector.ts +497 -0
  514. package/agent/routines/declared-permissions.ts +578 -0
  515. package/agent/routines/disable-notice.ts +181 -0
  516. package/agent/routines/entity-read.ts +305 -0
  517. package/agent/routines/event-authz.ts +268 -0
  518. package/agent/routines/event-match.ts +200 -0
  519. package/agent/routines/event-model.ts +744 -0
  520. package/agent/routines/events.ts +201 -0
  521. package/agent/routines/fire-audit.ts +823 -0
  522. package/agent/routines/fire-auth.ts +280 -0
  523. package/agent/routines/fire-carriage.ts +126 -0
  524. package/agent/routines/fire-creator.ts +86 -0
  525. package/agent/routines/fire-disclosure.ts +233 -0
  526. package/agent/routines/fire-eligibility.ts +280 -0
  527. package/agent/routines/fire-halt.ts +57 -0
  528. package/agent/routines/fire-message.ts +76 -0
  529. package/agent/routines/fire-toolset.ts +179 -0
  530. package/agent/routines/fire-window.ts +604 -0
  531. package/agent/routines/follow-ups.ts +173 -0
  532. package/agent/routines/gate.ts +251 -0
  533. package/agent/routines/github-entity-read.ts +120 -0
  534. package/agent/routines/github-fanout.ts +88 -0
  535. package/agent/routines/github-normalizer.ts +248 -0
  536. package/agent/routines/ingress.ts +855 -0
  537. package/agent/routines/job.ts +140 -0
  538. package/agent/routines/jq-filter.ts +387 -0
  539. package/agent/routines/lifecycle.ts +248 -0
  540. package/agent/routines/match-stamp.ts +131 -0
  541. package/agent/routines/outcome-fold.ts +302 -0
  542. package/agent/routines/partition.ts +27 -0
  543. package/agent/routines/permission-card-wait.ts +281 -0
  544. package/agent/routines/permission-card.ts +496 -0
  545. package/agent/routines/permission-key.ts +54 -0
  546. package/agent/routines/permission-review.ts +318 -0
  547. package/agent/routines/policy.ts +304 -0
  548. package/agent/routines/pre-fire.ts +133 -0
  549. package/agent/routines/provider-events.ts +430 -0
  550. package/agent/routines/report.ts +148 -0
  551. package/agent/routines/routine.ts +949 -0
  552. package/agent/routines/schedule.ts +209 -0
  553. package/agent/routines/scheme-name.ts +96 -0
  554. package/agent/routines/stall.ts +153 -0
  555. package/agent/routines/store.ts +100 -0
  556. package/agent/routines/watch.ts +328 -0
  557. package/agent/sandbox/backend-select.ts +58 -0
  558. package/agent/sandbox/vercel-create.ts +211 -0
  559. package/agent/scaffold/app-root.ts +104 -0
  560. package/agent/scaffold/roster-config.ts +187 -0
  561. package/agent/scaffold/roster-fs.ts +202 -0
  562. package/agent/scaffold/roster-plan.ts +880 -0
  563. package/agent/scaffold/templates.ts +85 -0
  564. package/agent/scaffold/tool-roster-read.ts +79 -0
  565. package/agent/scaffold/tool-roster.ts +214 -0
  566. package/agent/schedules/directory-sync.ts +37 -0
  567. package/agent/schedules/dispatch.ts +798 -0
  568. package/agent/schedules/dream-mode3.ts +311 -0
  569. package/agent/schedules/routine-dispatch.ts +213 -0
  570. package/agent/schedules/tidy.ts +321 -0
  571. package/agent/scm/app.ts +150 -0
  572. package/agent/scm/broker-audit.ts +107 -0
  573. package/agent/scm/broker.ts +130 -0
  574. package/agent/scm/capability-fit.ts +164 -0
  575. package/agent/scm/config-repo-token.ts +44 -0
  576. package/agent/scm/config.ts +37 -0
  577. package/agent/scm/contents.ts +162 -0
  578. package/agent/scm/git.ts +383 -0
  579. package/agent/scm/github-acting-identity.ts +127 -0
  580. package/agent/scm/github-search.ts +144 -0
  581. package/agent/scm/github-work.ts +44 -0
  582. package/agent/scm/installations.ts +155 -0
  583. package/agent/scm/issue-actions.ts +234 -0
  584. package/agent/scm/mint.ts +299 -0
  585. package/agent/scm/pr-activity.ts +130 -0
  586. package/agent/scm/pr-diff.ts +143 -0
  587. package/agent/scm/pr-feedback.ts +335 -0
  588. package/agent/scm/pr-status.ts +299 -0
  589. package/agent/scm/pr-watch.ts +162 -0
  590. package/agent/scm/pr.ts +114 -0
  591. package/agent/scm/provider.ts +46 -0
  592. package/agent/scm/refs.ts +142 -0
  593. package/agent/scm/repo-skills.ts +212 -0
  594. package/agent/scm/types.ts +50 -0
  595. package/agent/scm/write-token.ts +41 -0
  596. package/agent/settings/settings.ts +1525 -0
  597. package/agent/skills/domain-skills.ts +206 -0
  598. package/agent/skills/scoped.ts +172 -0
  599. package/agent/spend/bypass.ts +133 -0
  600. package/agent/spend/caps.ts +361 -0
  601. package/agent/spend/check.ts +164 -0
  602. package/agent/spend/checkpoint.ts +673 -0
  603. package/agent/spend/dm-mask.ts +134 -0
  604. package/agent/spend/ingress-gate.ts +349 -0
  605. package/agent/spend/pricing.ts +584 -0
  606. package/agent/spend/reporting.ts +900 -0
  607. package/agent/spend/sandbox-pricing.ts +53 -0
  608. package/agent/spend/spend.ts +480 -0
  609. package/agent/spend/stack-pricing.ts +205 -0
  610. package/agent/spend/store.ts +263 -0
  611. package/agent/spend/subagent-runs.ts +166 -0
  612. package/agent/spend/usage-events.ts +144 -0
  613. package/agent/stall/bash-hang-guard.ts +326 -0
  614. package/agent/stall/guard.ts +285 -0
  615. package/agent/status/status.ts +128 -0
  616. package/agent/subagents/contracts.ts +147 -0
  617. package/agent/subagents/declared.ts +201 -0
  618. package/agent/testing/driver-allowlist.ts +239 -0
  619. package/agent/tools/add_label.ts +68 -0
  620. package/agent/tools/add_routine_rule.ts +215 -0
  621. package/agent/tools/agent_version.ts +46 -0
  622. package/agent/tools/assign.ts +182 -0
  623. package/agent/tools/aws.ts +175 -0
  624. package/agent/tools/browser_tools.ts +22 -0
  625. package/agent/tools/cancel_routine.ts +133 -0
  626. package/agent/tools/capture_events.ts +54 -0
  627. package/agent/tools/check_pr_status.ts +72 -0
  628. package/agent/tools/checkout_repo.ts +172 -0
  629. package/agent/tools/clear_connector_override.ts +159 -0
  630. package/agent/tools/clear_spend_limit.ts +199 -0
  631. package/agent/tools/complete_job.ts +64 -0
  632. package/agent/tools/complete_thread.ts +134 -0
  633. package/agent/tools/confirm_link.ts +503 -0
  634. package/agent/tools/connector.ts +230 -0
  635. package/agent/tools/create_agent.ts +305 -0
  636. package/agent/tools/create_routine.ts +487 -0
  637. package/agent/tools/create_skill.ts +178 -0
  638. package/agent/tools/create_ticket.ts +187 -0
  639. package/agent/tools/declare_webhook.ts +362 -0
  640. package/agent/tools/delete_skill.ts +135 -0
  641. package/agent/tools/describe_image.ts +302 -0
  642. package/agent/tools/dm_person.ts +203 -0
  643. package/agent/tools/edit_reply.ts +195 -0
  644. package/agent/tools/edit_routine.ts +159 -0
  645. package/agent/tools/enable_routine.ts +162 -0
  646. package/agent/tools/explain_permission.ts +59 -0
  647. package/agent/tools/get_pr_feedback.ts +84 -0
  648. package/agent/tools/grant_tools.ts +443 -0
  649. package/agent/tools/halt.ts +172 -0
  650. package/agent/tools/link_identity.ts +308 -0
  651. package/agent/tools/list_recent_events.ts +58 -0
  652. package/agent/tools/list_repos.ts +24 -0
  653. package/agent/tools/list_routines.ts +152 -0
  654. package/agent/tools/list_skills.ts +38 -0
  655. package/agent/tools/list_webhooks.ts +72 -0
  656. package/agent/tools/memory_admin_list.ts +79 -0
  657. package/agent/tools/memory_admin_read.ts +95 -0
  658. package/agent/tools/message_thread_seat.ts +145 -0
  659. package/agent/tools/no_reply.ts +272 -0
  660. package/agent/tools/open_pull_request.ts +348 -0
  661. package/agent/tools/permission_fit_report.ts +190 -0
  662. package/agent/tools/post_file.ts +416 -0
  663. package/agent/tools/post_message.ts +169 -0
  664. package/agent/tools/post_pr_walkthrough.ts +220 -0
  665. package/agent/tools/purge_memory.ts +361 -0
  666. package/agent/tools/query_analytics.ts +83 -0
  667. package/agent/tools/react.ts +201 -0
  668. package/agent/tools/read_channel.ts +121 -0
  669. package/agent/tools/read_docs.ts +50 -0
  670. package/agent/tools/read_file_upload.ts +190 -0
  671. package/agent/tools/read_routine_transcript.ts +88 -0
  672. package/agent/tools/read_thread.ts +103 -0
  673. package/agent/tools/read_thread_seat.ts +91 -0
  674. package/agent/tools/read_webhook_history.ts +46 -0
  675. package/agent/tools/read_work_channel.ts +109 -0
  676. package/agent/tools/read_work_thread.ts +90 -0
  677. package/agent/tools/record_follow_up.ts +84 -0
  678. package/agent/tools/record_job_state.ts +49 -0
  679. package/agent/tools/record_watch_state.ts +47 -0
  680. package/agent/tools/remove_routine_rule.ts +158 -0
  681. package/agent/tools/reply.ts +757 -0
  682. package/agent/tools/report_run_failed.ts +79 -0
  683. package/agent/tools/request_access.ts +518 -0
  684. package/agent/tools/request_credential_grant.ts +550 -0
  685. package/agent/tools/resume.ts +148 -0
  686. package/agent/tools/revoke_connector.ts +155 -0
  687. package/agent/tools/revoke_credential_grant.ts +108 -0
  688. package/agent/tools/revoke_routine_permissions.ts +81 -0
  689. package/agent/tools/rotate_webhook.ts +185 -0
  690. package/agent/tools/run_routine_now.ts +120 -0
  691. package/agent/tools/sandbox_tools.ts +94 -0
  692. package/agent/tools/search.ts +121 -0
  693. package/agent/tools/session_cost.ts +135 -0
  694. package/agent/tools/set_dm_delivery.ts +115 -0
  695. package/agent/tools/set_spend_limit.ts +529 -0
  696. package/agent/tools/set_state.ts +179 -0
  697. package/agent/tools/spawn_thread_session.ts +223 -0
  698. package/agent/tools/spend_report.ts +440 -0
  699. package/agent/tools/stand_down.ts +260 -0
  700. package/agent/tools/subscribe_pr.ts +253 -0
  701. package/agent/tools/unlink_identity.ts +100 -0
  702. package/agent/tools/update_status.ts +65 -0
  703. package/agent/tools/usage_report.ts +103 -0
  704. package/agent/tools/walk_pr.ts +150 -0
  705. package/agent/webhooks/achievability.ts +235 -0
  706. package/agent/webhooks/capture-window.ts +220 -0
  707. package/agent/webhooks/config.ts +556 -0
  708. package/agent/webhooks/dispatch.ts +418 -0
  709. package/agent/webhooks/gate.ts +392 -0
  710. package/agent/webhooks/handshake-capture.ts +189 -0
  711. package/agent/webhooks/hooks-codemod.ts +266 -0
  712. package/agent/webhooks/oe-standard-webhook.ts +563 -0
  713. package/agent/webhooks/reject-audit.ts +134 -0
  714. package/agent/webhooks/replay-dedupe.ts +183 -0
  715. package/agent/webhooks/reveal-page.ts +507 -0
  716. package/agent/webhooks/secrets.ts +81 -0
  717. package/agent/webhooks/source-vocabulary.ts +333 -0
  718. package/agent/webhooks/verifier.ts +324 -0
  719. package/bin/oe-eve-patch.js +205 -0
  720. package/bin/oe.js +19 -0
  721. package/dist/agent/access/access-referenced-link-sets.d.ts +8 -0
  722. package/dist/agent/access/access-referenced-link-sets.d.ts.map +1 -0
  723. package/dist/agent/access/access-referenced-link-sets.js +20 -0
  724. package/dist/agent/access/access-referenced-link-sets.js.map +1 -0
  725. package/dist/agent/access/admin-read-venue.d.ts +48 -0
  726. package/dist/agent/access/admin-read-venue.d.ts.map +1 -0
  727. package/dist/agent/access/admin-read-venue.js +109 -0
  728. package/dist/agent/access/admin-read-venue.js.map +1 -0
  729. package/dist/agent/access/admin-standing.d.ts +16 -0
  730. package/dist/agent/access/admin-standing.d.ts.map +1 -0
  731. package/dist/agent/access/admin-standing.js +89 -0
  732. package/dist/agent/access/admin-standing.js.map +1 -0
  733. package/dist/agent/access/analytics-scope.d.ts +24 -0
  734. package/dist/agent/access/analytics-scope.d.ts.map +1 -0
  735. package/dist/agent/access/analytics-scope.js +62 -0
  736. package/dist/agent/access/analytics-scope.js.map +1 -0
  737. package/dist/agent/access/approval-dedupe.d.ts +29 -0
  738. package/dist/agent/access/approval-dedupe.d.ts.map +1 -0
  739. package/dist/agent/access/approval-dedupe.js +99 -0
  740. package/dist/agent/access/approval-dedupe.js.map +1 -0
  741. package/dist/agent/access/approval-judge.d.ts +186 -0
  742. package/dist/agent/access/approval-judge.d.ts.map +1 -0
  743. package/dist/agent/access/approval-judge.js +482 -0
  744. package/dist/agent/access/approval-judge.js.map +1 -0
  745. package/dist/agent/access/approval-preview.d.ts +27 -0
  746. package/dist/agent/access/approval-preview.d.ts.map +1 -0
  747. package/dist/agent/access/approval-preview.js +90 -0
  748. package/dist/agent/access/approval-preview.js.map +1 -0
  749. package/dist/agent/access/approval-scenarios.d.ts +18 -0
  750. package/dist/agent/access/approval-scenarios.d.ts.map +1 -0
  751. package/dist/agent/access/approval-scenarios.js +27 -0
  752. package/dist/agent/access/approval-scenarios.js.map +1 -0
  753. package/dist/agent/access/approver-chain.d.ts +210 -0
  754. package/dist/agent/access/approver-chain.d.ts.map +1 -0
  755. package/dist/agent/access/approver-chain.js +585 -0
  756. package/dist/agent/access/approver-chain.js.map +1 -0
  757. package/dist/agent/access/audience-floor.d.ts +69 -0
  758. package/dist/agent/access/audience-floor.d.ts.map +1 -0
  759. package/dist/agent/access/audience-floor.js +189 -0
  760. package/dist/agent/access/audience-floor.js.map +1 -0
  761. package/dist/agent/access/aws-output.d.ts +39 -0
  762. package/dist/agent/access/aws-output.d.ts.map +1 -0
  763. package/dist/agent/access/aws-output.js +94 -0
  764. package/dist/agent/access/aws-output.js.map +1 -0
  765. package/dist/agent/access/aws-screen.d.ts +24 -0
  766. package/dist/agent/access/aws-screen.d.ts.map +1 -0
  767. package/dist/agent/access/aws-screen.js +177 -0
  768. package/dist/agent/access/aws-screen.js.map +1 -0
  769. package/dist/agent/access/background-tasks.d.ts +100 -0
  770. package/dist/agent/access/background-tasks.d.ts.map +1 -0
  771. package/dist/agent/access/background-tasks.js +288 -0
  772. package/dist/agent/access/background-tasks.js.map +1 -0
  773. package/dist/agent/access/browser-hosts.d.ts +37 -0
  774. package/dist/agent/access/browser-hosts.d.ts.map +1 -0
  775. package/dist/agent/access/browser-hosts.js +127 -0
  776. package/dist/agent/access/browser-hosts.js.map +1 -0
  777. package/dist/agent/access/browser-toolkit.d.ts +48 -0
  778. package/dist/agent/access/browser-toolkit.d.ts.map +1 -0
  779. package/dist/agent/access/browser-toolkit.js +240 -0
  780. package/dist/agent/access/browser-toolkit.js.map +1 -0
  781. package/dist/agent/access/bundle.d.ts +239 -0
  782. package/dist/agent/access/bundle.d.ts.map +1 -0
  783. package/dist/agent/access/bundle.js +454 -0
  784. package/dist/agent/access/bundle.js.map +1 -0
  785. package/dist/agent/access/capabilities.d.ts +5 -0
  786. package/dist/agent/access/capabilities.d.ts.map +1 -0
  787. package/dist/agent/access/capabilities.js +9 -0
  788. package/dist/agent/access/capabilities.js.map +1 -0
  789. package/dist/agent/access/chat-dm-grant.d.ts +47 -0
  790. package/dist/agent/access/chat-dm-grant.d.ts.map +1 -0
  791. package/dist/agent/access/chat-dm-grant.js +185 -0
  792. package/dist/agent/access/chat-dm-grant.js.map +1 -0
  793. package/dist/agent/access/chat-write-grant.d.ts +35 -0
  794. package/dist/agent/access/chat-write-grant.d.ts.map +1 -0
  795. package/dist/agent/access/chat-write-grant.js +153 -0
  796. package/dist/agent/access/chat-write-grant.js.map +1 -0
  797. package/dist/agent/access/config.d.ts +117 -0
  798. package/dist/agent/access/config.d.ts.map +1 -0
  799. package/dist/agent/access/config.js +16 -0
  800. package/dist/agent/access/config.js.map +1 -0
  801. package/dist/agent/access/connector-content-origin-state.d.ts +17 -0
  802. package/dist/agent/access/connector-content-origin-state.d.ts.map +1 -0
  803. package/dist/agent/access/connector-content-origin-state.js +73 -0
  804. package/dist/agent/access/connector-content-origin-state.js.map +1 -0
  805. package/dist/agent/access/connector-credentials.d.ts +186 -0
  806. package/dist/agent/access/connector-credentials.d.ts.map +1 -0
  807. package/dist/agent/access/connector-credentials.js +258 -0
  808. package/dist/agent/access/connector-credentials.js.map +1 -0
  809. package/dist/agent/access/connector-disclosure.d.ts +66 -0
  810. package/dist/agent/access/connector-disclosure.d.ts.map +1 -0
  811. package/dist/agent/access/connector-disclosure.js +194 -0
  812. package/dist/agent/access/connector-disclosure.js.map +1 -0
  813. package/dist/agent/access/connector-op-gating.d.ts +32 -0
  814. package/dist/agent/access/connector-op-gating.d.ts.map +1 -0
  815. package/dist/agent/access/connector-op-gating.js +178 -0
  816. package/dist/agent/access/connector-op-gating.js.map +1 -0
  817. package/dist/agent/access/connector-scope.d.ts +42 -0
  818. package/dist/agent/access/connector-scope.d.ts.map +1 -0
  819. package/dist/agent/access/connector-scope.js +258 -0
  820. package/dist/agent/access/connector-scope.js.map +1 -0
  821. package/dist/agent/access/consequence.d.ts +205 -0
  822. package/dist/agent/access/consequence.d.ts.map +1 -0
  823. package/dist/agent/access/consequence.js +816 -0
  824. package/dist/agent/access/consequence.js.map +1 -0
  825. package/dist/agent/access/credential-bindings-codemod.d.ts +63 -0
  826. package/dist/agent/access/credential-bindings-codemod.d.ts.map +1 -0
  827. package/dist/agent/access/credential-bindings-codemod.js +179 -0
  828. package/dist/agent/access/credential-bindings-codemod.js.map +1 -0
  829. package/dist/agent/access/credential-endpoints.d.ts +47 -0
  830. package/dist/agent/access/credential-endpoints.d.ts.map +1 -0
  831. package/dist/agent/access/credential-endpoints.js +211 -0
  832. package/dist/agent/access/credential-endpoints.js.map +1 -0
  833. package/dist/agent/access/credential-grant-ask.d.ts +22 -0
  834. package/dist/agent/access/credential-grant-ask.d.ts.map +1 -0
  835. package/dist/agent/access/credential-grant-ask.js +82 -0
  836. package/dist/agent/access/credential-grant-ask.js.map +1 -0
  837. package/dist/agent/access/credential-grant-broker.d.ts +85 -0
  838. package/dist/agent/access/credential-grant-broker.d.ts.map +1 -0
  839. package/dist/agent/access/credential-grant-broker.js +252 -0
  840. package/dist/agent/access/credential-grant-broker.js.map +1 -0
  841. package/dist/agent/access/credential-grant-card.d.ts +98 -0
  842. package/dist/agent/access/credential-grant-card.d.ts.map +1 -0
  843. package/dist/agent/access/credential-grant-card.js +447 -0
  844. package/dist/agent/access/credential-grant-card.js.map +1 -0
  845. package/dist/agent/access/credential-grant-click.d.ts +43 -0
  846. package/dist/agent/access/credential-grant-click.d.ts.map +1 -0
  847. package/dist/agent/access/credential-grant-click.js +190 -0
  848. package/dist/agent/access/credential-grant-click.js.map +1 -0
  849. package/dist/agent/access/credential-grant-copy.d.ts +135 -0
  850. package/dist/agent/access/credential-grant-copy.d.ts.map +1 -0
  851. package/dist/agent/access/credential-grant-copy.js +276 -0
  852. package/dist/agent/access/credential-grant-copy.js.map +1 -0
  853. package/dist/agent/access/credential-grant-flow.d.ts +174 -0
  854. package/dist/agent/access/credential-grant-flow.d.ts.map +1 -0
  855. package/dist/agent/access/credential-grant-flow.js +503 -0
  856. package/dist/agent/access/credential-grant-flow.js.map +1 -0
  857. package/dist/agent/access/credential-grant-key-shape.d.ts +37 -0
  858. package/dist/agent/access/credential-grant-key-shape.d.ts.map +1 -0
  859. package/dist/agent/access/credential-grant-key-shape.js +51 -0
  860. package/dist/agent/access/credential-grant-key-shape.js.map +1 -0
  861. package/dist/agent/access/credential-grant-notice.d.ts +29 -0
  862. package/dist/agent/access/credential-grant-notice.d.ts.map +1 -0
  863. package/dist/agent/access/credential-grant-notice.js +187 -0
  864. package/dist/agent/access/credential-grant-notice.js.map +1 -0
  865. package/dist/agent/access/credential-grant-owner.d.ts +10 -0
  866. package/dist/agent/access/credential-grant-owner.d.ts.map +1 -0
  867. package/dist/agent/access/credential-grant-owner.js +16 -0
  868. package/dist/agent/access/credential-grant-owner.js.map +1 -0
  869. package/dist/agent/access/credential-grant-reach.d.ts +46 -0
  870. package/dist/agent/access/credential-grant-reach.d.ts.map +1 -0
  871. package/dist/agent/access/credential-grant-reach.js +77 -0
  872. package/dist/agent/access/credential-grant-reach.js.map +1 -0
  873. package/dist/agent/access/credential-grant-resolution.d.ts +30 -0
  874. package/dist/agent/access/credential-grant-resolution.d.ts.map +1 -0
  875. package/dist/agent/access/credential-grant-resolution.js +107 -0
  876. package/dist/agent/access/credential-grant-resolution.js.map +1 -0
  877. package/dist/agent/access/credential-grant-revoke.d.ts +33 -0
  878. package/dist/agent/access/credential-grant-revoke.d.ts.map +1 -0
  879. package/dist/agent/access/credential-grant-revoke.js +62 -0
  880. package/dist/agent/access/credential-grant-revoke.js.map +1 -0
  881. package/dist/agent/access/credential-grant-scope.d.ts +206 -0
  882. package/dist/agent/access/credential-grant-scope.d.ts.map +1 -0
  883. package/dist/agent/access/credential-grant-scope.js +282 -0
  884. package/dist/agent/access/credential-grant-scope.js.map +1 -0
  885. package/dist/agent/access/credential-grant.d.ts +94 -0
  886. package/dist/agent/access/credential-grant.d.ts.map +1 -0
  887. package/dist/agent/access/credential-grant.js +198 -0
  888. package/dist/agent/access/credential-grant.js.map +1 -0
  889. package/dist/agent/access/credentials.d.ts +41 -0
  890. package/dist/agent/access/credentials.d.ts.map +1 -0
  891. package/dist/agent/access/credentials.js +112 -0
  892. package/dist/agent/access/credentials.js.map +1 -0
  893. package/dist/agent/access/dated-read.d.ts +3 -0
  894. package/dist/agent/access/dated-read.d.ts.map +1 -0
  895. package/dist/agent/access/dated-read.js +24 -0
  896. package/dist/agent/access/dated-read.js.map +1 -0
  897. package/dist/agent/access/delegation-flag.d.ts +5 -0
  898. package/dist/agent/access/delegation-flag.d.ts.map +1 -0
  899. package/dist/agent/access/delegation-flag.js +10 -0
  900. package/dist/agent/access/delegation-flag.js.map +1 -0
  901. package/dist/agent/access/delegation-mount.d.ts +6 -0
  902. package/dist/agent/access/delegation-mount.d.ts.map +1 -0
  903. package/dist/agent/access/delegation-mount.js +30 -0
  904. package/dist/agent/access/delegation-mount.js.map +1 -0
  905. package/dist/agent/access/delta.d.ts +103 -0
  906. package/dist/agent/access/delta.d.ts.map +1 -0
  907. package/dist/agent/access/delta.js +267 -0
  908. package/dist/agent/access/delta.js.map +1 -0
  909. package/dist/agent/access/dispatch-origin-signal.d.ts +19 -0
  910. package/dist/agent/access/dispatch-origin-signal.d.ts.map +1 -0
  911. package/dist/agent/access/dispatch-origin-signal.js +130 -0
  912. package/dist/agent/access/dispatch-origin-signal.js.map +1 -0
  913. package/dist/agent/access/domain-credentials.d.ts +32 -0
  914. package/dist/agent/access/domain-credentials.d.ts.map +1 -0
  915. package/dist/agent/access/domain-credentials.js +78 -0
  916. package/dist/agent/access/domain-credentials.js.map +1 -0
  917. package/dist/agent/access/egress-denial-log.d.ts +28 -0
  918. package/dist/agent/access/egress-denial-log.d.ts.map +1 -0
  919. package/dist/agent/access/egress-denial-log.js +96 -0
  920. package/dist/agent/access/egress-denial-log.js.map +1 -0
  921. package/dist/agent/access/egress-denial-poller.d.ts +56 -0
  922. package/dist/agent/access/egress-denial-poller.d.ts.map +1 -0
  923. package/dist/agent/access/egress-denial-poller.js +184 -0
  924. package/dist/agent/access/egress-denial-poller.js.map +1 -0
  925. package/dist/agent/access/egress-status.d.ts +61 -0
  926. package/dist/agent/access/egress-status.d.ts.map +1 -0
  927. package/dist/agent/access/egress-status.js +130 -0
  928. package/dist/agent/access/egress-status.js.map +1 -0
  929. package/dist/agent/access/egress.d.ts +86 -0
  930. package/dist/agent/access/egress.d.ts.map +1 -0
  931. package/dist/agent/access/egress.js +236 -0
  932. package/dist/agent/access/egress.js.map +1 -0
  933. package/dist/agent/access/enforcement.d.ts +8 -0
  934. package/dist/agent/access/enforcement.d.ts.map +1 -0
  935. package/dist/agent/access/enforcement.js +24 -0
  936. package/dist/agent/access/enforcement.js.map +1 -0
  937. package/dist/agent/access/eve-patch-probe-boot.d.ts +2 -0
  938. package/dist/agent/access/eve-patch-probe-boot.d.ts.map +1 -0
  939. package/dist/agent/access/eve-patch-probe-boot.js +91 -0
  940. package/dist/agent/access/eve-patch-probe-boot.js.map +1 -0
  941. package/dist/agent/access/eve-patch-probe.d.ts +57 -0
  942. package/dist/agent/access/eve-patch-probe.d.ts.map +1 -0
  943. package/dist/agent/access/eve-patch-probe.js +225 -0
  944. package/dist/agent/access/eve-patch-probe.js.map +1 -0
  945. package/dist/agent/access/external-policy.d.ts +95 -0
  946. package/dist/agent/access/external-policy.d.ts.map +1 -0
  947. package/dist/agent/access/external-policy.js +154 -0
  948. package/dist/agent/access/external-policy.js.map +1 -0
  949. package/dist/agent/access/extra-hosts.d.ts +10 -0
  950. package/dist/agent/access/extra-hosts.d.ts.map +1 -0
  951. package/dist/agent/access/extra-hosts.js +28 -0
  952. package/dist/agent/access/extra-hosts.js.map +1 -0
  953. package/dist/agent/access/grant-borrow-transport-registry.internal.d.ts +21 -0
  954. package/dist/agent/access/grant-borrow-transport-registry.internal.d.ts.map +1 -0
  955. package/dist/agent/access/grant-borrow-transport-registry.internal.js +63 -0
  956. package/dist/agent/access/grant-borrow-transport-registry.internal.js.map +1 -0
  957. package/dist/agent/access/grant-room-notice-registry.internal.d.ts +20 -0
  958. package/dist/agent/access/grant-room-notice-registry.internal.d.ts.map +1 -0
  959. package/dist/agent/access/grant-room-notice-registry.internal.js +59 -0
  960. package/dist/agent/access/grant-room-notice-registry.internal.js.map +1 -0
  961. package/dist/agent/access/grant-schema-pin.d.ts +15 -0
  962. package/dist/agent/access/grant-schema-pin.d.ts.map +1 -0
  963. package/dist/agent/access/grant-schema-pin.js +29 -0
  964. package/dist/agent/access/grant-schema-pin.js.map +1 -0
  965. package/dist/agent/access/grants-codemod.d.ts +32 -0
  966. package/dist/agent/access/grants-codemod.d.ts.map +1 -0
  967. package/dist/agent/access/grants-codemod.js +306 -0
  968. package/dist/agent/access/grants-codemod.js.map +1 -0
  969. package/dist/agent/access/group-request.d.ts +13 -0
  970. package/dist/agent/access/group-request.d.ts.map +1 -0
  971. package/dist/agent/access/group-request.js +67 -0
  972. package/dist/agent/access/group-request.js.map +1 -0
  973. package/dist/agent/access/halt-state.d.ts +7 -0
  974. package/dist/agent/access/halt-state.d.ts.map +1 -0
  975. package/dist/agent/access/halt-state.js +23 -0
  976. package/dist/agent/access/halt-state.js.map +1 -0
  977. package/dist/agent/access/halt.d.ts +90 -0
  978. package/dist/agent/access/halt.d.ts.map +1 -0
  979. package/dist/agent/access/halt.js +239 -0
  980. package/dist/agent/access/halt.js.map +1 -0
  981. package/dist/agent/access/host-egress.d.ts +71 -0
  982. package/dist/agent/access/host-egress.d.ts.map +1 -0
  983. package/dist/agent/access/host-egress.js +384 -0
  984. package/dist/agent/access/host-egress.js.map +1 -0
  985. package/dist/agent/access/human-only-invariants-manifest.d.ts +20 -0
  986. package/dist/agent/access/human-only-invariants-manifest.d.ts.map +1 -0
  987. package/dist/agent/access/human-only-invariants-manifest.js +144 -0
  988. package/dist/agent/access/human-only-invariants-manifest.js.map +1 -0
  989. package/dist/agent/access/ingestion-binding-manifest.d.ts +41 -0
  990. package/dist/agent/access/ingestion-binding-manifest.d.ts.map +1 -0
  991. package/dist/agent/access/ingestion-binding-manifest.js +214 -0
  992. package/dist/agent/access/ingestion-binding-manifest.js.map +1 -0
  993. package/dist/agent/access/ingestion-route-inventory.generated.d.ts +13 -0
  994. package/dist/agent/access/ingestion-route-inventory.generated.d.ts.map +1 -0
  995. package/dist/agent/access/ingestion-route-inventory.generated.js +46 -0
  996. package/dist/agent/access/ingestion-route-inventory.generated.js.map +1 -0
  997. package/dist/agent/access/instructions.d.ts +5 -0
  998. package/dist/agent/access/instructions.d.ts.map +1 -0
  999. package/dist/agent/access/instructions.js +72 -0
  1000. package/dist/agent/access/instructions.js.map +1 -0
  1001. package/dist/agent/access/invoker-posture-state.d.ts +8 -0
  1002. package/dist/agent/access/invoker-posture-state.d.ts.map +1 -0
  1003. package/dist/agent/access/invoker-posture-state.js +23 -0
  1004. package/dist/agent/access/invoker-posture-state.js.map +1 -0
  1005. package/dist/agent/access/invoker-posture.d.ts +29 -0
  1006. package/dist/agent/access/invoker-posture.d.ts.map +1 -0
  1007. package/dist/agent/access/invoker-posture.js +70 -0
  1008. package/dist/agent/access/invoker-posture.js.map +1 -0
  1009. package/dist/agent/access/job-posture.d.ts +37 -0
  1010. package/dist/agent/access/job-posture.d.ts.map +1 -0
  1011. package/dist/agent/access/job-posture.js +65 -0
  1012. package/dist/agent/access/job-posture.js.map +1 -0
  1013. package/dist/agent/access/job-session-state.d.ts +13 -0
  1014. package/dist/agent/access/job-session-state.d.ts.map +1 -0
  1015. package/dist/agent/access/job-session-state.js +57 -0
  1016. package/dist/agent/access/job-session-state.js.map +1 -0
  1017. package/dist/agent/access/lean-seat-state.d.ts +12 -0
  1018. package/dist/agent/access/lean-seat-state.d.ts.map +1 -0
  1019. package/dist/agent/access/lean-seat-state.js +35 -0
  1020. package/dist/agent/access/lean-seat-state.js.map +1 -0
  1021. package/dist/agent/access/lean-seat.d.ts +25 -0
  1022. package/dist/agent/access/lean-seat.d.ts.map +1 -0
  1023. package/dist/agent/access/lean-seat.js +66 -0
  1024. package/dist/agent/access/lean-seat.js.map +1 -0
  1025. package/dist/agent/access/lint.d.ts +39 -0
  1026. package/dist/agent/access/lint.d.ts.map +1 -0
  1027. package/dist/agent/access/lint.js +556 -0
  1028. package/dist/agent/access/lint.js.map +1 -0
  1029. package/dist/agent/access/live-delegated-tasks.d.ts +20 -0
  1030. package/dist/agent/access/live-delegated-tasks.d.ts.map +1 -0
  1031. package/dist/agent/access/live-delegated-tasks.js +96 -0
  1032. package/dist/agent/access/live-delegated-tasks.js.map +1 -0
  1033. package/dist/agent/access/loop-breaker.d.ts +26 -0
  1034. package/dist/agent/access/loop-breaker.d.ts.map +1 -0
  1035. package/dist/agent/access/loop-breaker.js +77 -0
  1036. package/dist/agent/access/loop-breaker.js.map +1 -0
  1037. package/dist/agent/access/mcp-call-fence.d.ts +19 -0
  1038. package/dist/agent/access/mcp-call-fence.d.ts.map +1 -0
  1039. package/dist/agent/access/mcp-call-fence.js +180 -0
  1040. package/dist/agent/access/mcp-call-fence.js.map +1 -0
  1041. package/dist/agent/access/member-grant.d.ts +16 -0
  1042. package/dist/agent/access/member-grant.d.ts.map +1 -0
  1043. package/dist/agent/access/member-grant.js +34 -0
  1044. package/dist/agent/access/member-grant.js.map +1 -0
  1045. package/dist/agent/access/member-plane.d.ts +91 -0
  1046. package/dist/agent/access/member-plane.d.ts.map +1 -0
  1047. package/dist/agent/access/member-plane.js +114 -0
  1048. package/dist/agent/access/member-plane.js.map +1 -0
  1049. package/dist/agent/access/native-admin.d.ts +13 -0
  1050. package/dist/agent/access/native-admin.d.ts.map +1 -0
  1051. package/dist/agent/access/native-admin.js +23 -0
  1052. package/dist/agent/access/native-admin.js.map +1 -0
  1053. package/dist/agent/access/native-delegation-state.d.ts +16 -0
  1054. package/dist/agent/access/native-delegation-state.d.ts.map +1 -0
  1055. package/dist/agent/access/native-delegation-state.js +26 -0
  1056. package/dist/agent/access/native-delegation-state.js.map +1 -0
  1057. package/dist/agent/access/network-access.d.ts +23 -0
  1058. package/dist/agent/access/network-access.d.ts.map +1 -0
  1059. package/dist/agent/access/network-access.js +108 -0
  1060. package/dist/agent/access/network-access.js.map +1 -0
  1061. package/dist/agent/access/nullable-optional-fields.d.ts +13 -0
  1062. package/dist/agent/access/nullable-optional-fields.d.ts.map +1 -0
  1063. package/dist/agent/access/nullable-optional-fields.js +190 -0
  1064. package/dist/agent/access/nullable-optional-fields.js.map +1 -0
  1065. package/dist/agent/access/overlay-module.d.ts +20 -0
  1066. package/dist/agent/access/overlay-module.d.ts.map +1 -0
  1067. package/dist/agent/access/overlay-module.js +47 -0
  1068. package/dist/agent/access/overlay-module.js.map +1 -0
  1069. package/dist/agent/access/own-account-gate-manifest.d.ts +23 -0
  1070. package/dist/agent/access/own-account-gate-manifest.d.ts.map +1 -0
  1071. package/dist/agent/access/own-account-gate-manifest.js +109 -0
  1072. package/dist/agent/access/own-account-gate-manifest.js.map +1 -0
  1073. package/dist/agent/access/pane-venue.d.ts +58 -0
  1074. package/dist/agent/access/pane-venue.d.ts.map +1 -0
  1075. package/dist/agent/access/pane-venue.js +177 -0
  1076. package/dist/agent/access/pane-venue.js.map +1 -0
  1077. package/dist/agent/access/pending-delegation-signal.d.ts +38 -0
  1078. package/dist/agent/access/pending-delegation-signal.d.ts.map +1 -0
  1079. package/dist/agent/access/pending-delegation-signal.js +268 -0
  1080. package/dist/agent/access/pending-delegation-signal.js.map +1 -0
  1081. package/dist/agent/access/permission-evidence.d.ts +184 -0
  1082. package/dist/agent/access/permission-evidence.d.ts.map +1 -0
  1083. package/dist/agent/access/permission-evidence.js +412 -0
  1084. package/dist/agent/access/permission-evidence.js.map +1 -0
  1085. package/dist/agent/access/permission-proposal.d.ts +33 -0
  1086. package/dist/agent/access/permission-proposal.d.ts.map +1 -0
  1087. package/dist/agent/access/permission-proposal.js +319 -0
  1088. package/dist/agent/access/permission-proposal.js.map +1 -0
  1089. package/dist/agent/access/platform.d.ts +5 -0
  1090. package/dist/agent/access/platform.d.ts.map +1 -0
  1091. package/dist/agent/access/platform.js +15 -0
  1092. package/dist/agent/access/platform.js.map +1 -0
  1093. package/dist/agent/access/pre-approval-rules.d.ts +44 -0
  1094. package/dist/agent/access/pre-approval-rules.d.ts.map +1 -0
  1095. package/dist/agent/access/pre-approval-rules.js +86 -0
  1096. package/dist/agent/access/pre-approval-rules.js.map +1 -0
  1097. package/dist/agent/access/principal-gate-manifest.d.ts +111 -0
  1098. package/dist/agent/access/principal-gate-manifest.d.ts.map +1 -0
  1099. package/dist/agent/access/principal-gate-manifest.js +718 -0
  1100. package/dist/agent/access/principal-gate-manifest.js.map +1 -0
  1101. package/dist/agent/access/provider-selection-check.d.ts +24 -0
  1102. package/dist/agent/access/provider-selection-check.d.ts.map +1 -0
  1103. package/dist/agent/access/provider-selection-check.js +97 -0
  1104. package/dist/agent/access/provider-selection-check.js.map +1 -0
  1105. package/dist/agent/access/provider-selection.d.ts +21 -0
  1106. package/dist/agent/access/provider-selection.d.ts.map +1 -0
  1107. package/dist/agent/access/provider-selection.js +76 -0
  1108. package/dist/agent/access/provider-selection.js.map +1 -0
  1109. package/dist/agent/access/read-grant.d.ts +13 -0
  1110. package/dist/agent/access/read-grant.d.ts.map +1 -0
  1111. package/dist/agent/access/read-grant.js +96 -0
  1112. package/dist/agent/access/read-grant.js.map +1 -0
  1113. package/dist/agent/access/repo-capabilities.d.ts +30 -0
  1114. package/dist/agent/access/repo-capabilities.d.ts.map +1 -0
  1115. package/dist/agent/access/repo-capabilities.js +60 -0
  1116. package/dist/agent/access/repo-capabilities.js.map +1 -0
  1117. package/dist/agent/access/request.d.ts +17 -0
  1118. package/dist/agent/access/request.d.ts.map +1 -0
  1119. package/dist/agent/access/request.js +110 -0
  1120. package/dist/agent/access/request.js.map +1 -0
  1121. package/dist/agent/access/requester-identity.d.ts +82 -0
  1122. package/dist/agent/access/requester-identity.d.ts.map +1 -0
  1123. package/dist/agent/access/requester-identity.js +275 -0
  1124. package/dist/agent/access/requester-identity.js.map +1 -0
  1125. package/dist/agent/access/requester-messages.d.ts +7 -0
  1126. package/dist/agent/access/requester-messages.d.ts.map +1 -0
  1127. package/dist/agent/access/requester-messages.js +45 -0
  1128. package/dist/agent/access/requester-messages.js.map +1 -0
  1129. package/dist/agent/access/reserved-hosts.d.ts +5 -0
  1130. package/dist/agent/access/reserved-hosts.d.ts.map +1 -0
  1131. package/dist/agent/access/reserved-hosts.js +9 -0
  1132. package/dist/agent/access/reserved-hosts.js.map +1 -0
  1133. package/dist/agent/access/resolver.d.ts +120 -0
  1134. package/dist/agent/access/resolver.d.ts.map +1 -0
  1135. package/dist/agent/access/resolver.js +447 -0
  1136. package/dist/agent/access/resolver.js.map +1 -0
  1137. package/dist/agent/access/resource-capabilities.d.ts +37 -0
  1138. package/dist/agent/access/resource-capabilities.d.ts.map +1 -0
  1139. package/dist/agent/access/resource-capabilities.js +77 -0
  1140. package/dist/agent/access/resource-capabilities.js.map +1 -0
  1141. package/dist/agent/access/resource-grant-manifest.d.ts +21 -0
  1142. package/dist/agent/access/resource-grant-manifest.d.ts.map +1 -0
  1143. package/dist/agent/access/resource-grant-manifest.js +93 -0
  1144. package/dist/agent/access/resource-grant-manifest.js.map +1 -0
  1145. package/dist/agent/access/resource-grant.d.ts +33 -0
  1146. package/dist/agent/access/resource-grant.d.ts.map +1 -0
  1147. package/dist/agent/access/resource-grant.js +131 -0
  1148. package/dist/agent/access/resource-grant.js.map +1 -0
  1149. package/dist/agent/access/result-cap.d.ts +11 -0
  1150. package/dist/agent/access/result-cap.d.ts.map +1 -0
  1151. package/dist/agent/access/result-cap.js +31 -0
  1152. package/dist/agent/access/result-cap.js.map +1 -0
  1153. package/dist/agent/access/result-reduce-model-arm.d.ts +25 -0
  1154. package/dist/agent/access/result-reduce-model-arm.d.ts.map +1 -0
  1155. package/dist/agent/access/result-reduce-model-arm.js +73 -0
  1156. package/dist/agent/access/result-reduce-model-arm.js.map +1 -0
  1157. package/dist/agent/access/result-reduce.d.ts +13 -0
  1158. package/dist/agent/access/result-reduce.d.ts.map +1 -0
  1159. package/dist/agent/access/result-reduce.js +86 -0
  1160. package/dist/agent/access/result-reduce.js.map +1 -0
  1161. package/dist/agent/access/roles.d.ts +26 -0
  1162. package/dist/agent/access/roles.d.ts.map +1 -0
  1163. package/dist/agent/access/roles.js +78 -0
  1164. package/dist/agent/access/roles.js.map +1 -0
  1165. package/dist/agent/access/scope-key.d.ts +43 -0
  1166. package/dist/agent/access/scope-key.d.ts.map +1 -0
  1167. package/dist/agent/access/scope-key.js +36 -0
  1168. package/dist/agent/access/scope-key.js.map +1 -0
  1169. package/dist/agent/access/seat-read-budget.d.ts +17 -0
  1170. package/dist/agent/access/seat-read-budget.d.ts.map +1 -0
  1171. package/dist/agent/access/seat-read-budget.js +53 -0
  1172. package/dist/agent/access/seat-read-budget.js.map +1 -0
  1173. package/dist/agent/access/self-host-egress.d.ts +37 -0
  1174. package/dist/agent/access/self-host-egress.d.ts.map +1 -0
  1175. package/dist/agent/access/self-host-egress.js +63 -0
  1176. package/dist/agent/access/self-host-egress.js.map +1 -0
  1177. package/dist/agent/access/settlement-dispatch-signal.d.ts +22 -0
  1178. package/dist/agent/access/settlement-dispatch-signal.d.ts.map +1 -0
  1179. package/dist/agent/access/settlement-dispatch-signal.js +76 -0
  1180. package/dist/agent/access/settlement-dispatch-signal.js.map +1 -0
  1181. package/dist/agent/access/skill-taint-envelope.d.ts +31 -0
  1182. package/dist/agent/access/skill-taint-envelope.d.ts.map +1 -0
  1183. package/dist/agent/access/skill-taint-envelope.js +80 -0
  1184. package/dist/agent/access/skill-taint-envelope.js.map +1 -0
  1185. package/dist/agent/access/source-gate-manifest.d.ts +14 -0
  1186. package/dist/agent/access/source-gate-manifest.d.ts.map +1 -0
  1187. package/dist/agent/access/source-gate-manifest.js +111 -0
  1188. package/dist/agent/access/source-gate-manifest.js.map +1 -0
  1189. package/dist/agent/access/source-scoped-mount.d.ts +7 -0
  1190. package/dist/agent/access/source-scoped-mount.d.ts.map +1 -0
  1191. package/dist/agent/access/source-scoped-mount.js +26 -0
  1192. package/dist/agent/access/source-scoped-mount.js.map +1 -0
  1193. package/dist/agent/access/subagent-taint.d.ts +44 -0
  1194. package/dist/agent/access/subagent-taint.d.ts.map +1 -0
  1195. package/dist/agent/access/subagent-taint.js +175 -0
  1196. package/dist/agent/access/subagent-taint.js.map +1 -0
  1197. package/dist/agent/access/surface-work-grant.d.ts +20 -0
  1198. package/dist/agent/access/surface-work-grant.d.ts.map +1 -0
  1199. package/dist/agent/access/surface-work-grant.js +84 -0
  1200. package/dist/agent/access/surface-work-grant.js.map +1 -0
  1201. package/dist/agent/access/taint-enforcement.d.ts +46 -0
  1202. package/dist/agent/access/taint-enforcement.d.ts.map +1 -0
  1203. package/dist/agent/access/taint-enforcement.js +141 -0
  1204. package/dist/agent/access/taint-enforcement.js.map +1 -0
  1205. package/dist/agent/access/taint-signal.d.ts +100 -0
  1206. package/dist/agent/access/taint-signal.d.ts.map +1 -0
  1207. package/dist/agent/access/taint-signal.js +236 -0
  1208. package/dist/agent/access/taint-signal.js.map +1 -0
  1209. package/dist/agent/access/taint-tiers.d.ts +64 -0
  1210. package/dist/agent/access/taint-tiers.d.ts.map +1 -0
  1211. package/dist/agent/access/taint-tiers.js +93 -0
  1212. package/dist/agent/access/taint-tiers.js.map +1 -0
  1213. package/dist/agent/access/task-wake-signal.d.ts +9 -0
  1214. package/dist/agent/access/task-wake-signal.d.ts.map +1 -0
  1215. package/dist/agent/access/task-wake-signal.js +86 -0
  1216. package/dist/agent/access/task-wake-signal.js.map +1 -0
  1217. package/dist/agent/access/tenant-admission.d.ts +52 -0
  1218. package/dist/agent/access/tenant-admission.d.ts.map +1 -0
  1219. package/dist/agent/access/tenant-admission.js +154 -0
  1220. package/dist/agent/access/tenant-admission.js.map +1 -0
  1221. package/dist/agent/access/untrusted-projection.d.ts +23 -0
  1222. package/dist/agent/access/untrusted-projection.d.ts.map +1 -0
  1223. package/dist/agent/access/untrusted-projection.js +258 -0
  1224. package/dist/agent/access/untrusted-projection.js.map +1 -0
  1225. package/dist/agent/access/untrusted.d.ts +34 -0
  1226. package/dist/agent/access/untrusted.d.ts.map +1 -0
  1227. package/dist/agent/access/untrusted.js +100 -0
  1228. package/dist/agent/access/untrusted.js.map +1 -0
  1229. package/dist/agent/access/wake-mapping.d.ts +22 -0
  1230. package/dist/agent/access/wake-mapping.d.ts.map +1 -0
  1231. package/dist/agent/access/wake-mapping.js +19 -0
  1232. package/dist/agent/access/wake-mapping.js.map +1 -0
  1233. package/dist/agent/access/web-fetch-fence.d.ts +8 -0
  1234. package/dist/agent/access/web-fetch-fence.d.ts.map +1 -0
  1235. package/dist/agent/access/web-fetch-fence.js +55 -0
  1236. package/dist/agent/access/web-fetch-fence.js.map +1 -0
  1237. package/dist/agent/access/window-gate-manifest.d.ts +75 -0
  1238. package/dist/agent/access/window-gate-manifest.d.ts.map +1 -0
  1239. package/dist/agent/access/window-gate-manifest.js +474 -0
  1240. package/dist/agent/access/window-gate-manifest.js.map +1 -0
  1241. package/dist/agent/access/window-gated.d.ts +111 -0
  1242. package/dist/agent/access/window-gated.d.ts.map +1 -0
  1243. package/dist/agent/access/window-gated.js +611 -0
  1244. package/dist/agent/access/window-gated.js.map +1 -0
  1245. package/dist/agent/access/window-routing.d.ts +16 -0
  1246. package/dist/agent/access/window-routing.d.ts.map +1 -0
  1247. package/dist/agent/access/window-routing.js +11 -0
  1248. package/dist/agent/access/window-routing.js.map +1 -0
  1249. package/dist/agent/access/work-grant.d.ts +39 -0
  1250. package/dist/agent/access/work-grant.d.ts.map +1 -0
  1251. package/dist/agent/access/work-grant.js +76 -0
  1252. package/dist/agent/access/work-grant.js.map +1 -0
  1253. package/dist/agent/access/work-mount-manifest.d.ts +21 -0
  1254. package/dist/agent/access/work-mount-manifest.d.ts.map +1 -0
  1255. package/dist/agent/access/work-mount-manifest.js +149 -0
  1256. package/dist/agent/access/work-mount-manifest.js.map +1 -0
  1257. package/dist/agent/access/worker-capabilities.d.ts +60 -0
  1258. package/dist/agent/access/worker-capabilities.d.ts.map +1 -0
  1259. package/dist/agent/access/worker-capabilities.js +318 -0
  1260. package/dist/agent/access/worker-capabilities.js.map +1 -0
  1261. package/dist/agent/access/worker-capability-index.generated.d.ts +7 -0
  1262. package/dist/agent/access/worker-capability-index.generated.d.ts.map +1 -0
  1263. package/dist/agent/access/worker-capability-index.generated.js +188 -0
  1264. package/dist/agent/access/worker-capability-index.generated.js.map +1 -0
  1265. package/dist/agent/access/worker-continuation.d.ts +7 -0
  1266. package/dist/agent/access/worker-continuation.d.ts.map +1 -0
  1267. package/dist/agent/access/worker-continuation.js +180 -0
  1268. package/dist/agent/access/worker-continuation.js.map +1 -0
  1269. package/dist/agent/access/worker-seat-state.d.ts +8 -0
  1270. package/dist/agent/access/worker-seat-state.d.ts.map +1 -0
  1271. package/dist/agent/access/worker-seat-state.js +24 -0
  1272. package/dist/agent/access/worker-seat-state.js.map +1 -0
  1273. package/dist/agent/access/worker-seat.d.ts +23 -0
  1274. package/dist/agent/access/worker-seat.d.ts.map +1 -0
  1275. package/dist/agent/access/worker-seat.js +47 -0
  1276. package/dist/agent/access/worker-seat.js.map +1 -0
  1277. package/dist/agent/access/worker-toolset-state.d.ts +32 -0
  1278. package/dist/agent/access/worker-toolset-state.d.ts.map +1 -0
  1279. package/dist/agent/access/worker-toolset-state.js +40 -0
  1280. package/dist/agent/access/worker-toolset-state.js.map +1 -0
  1281. package/dist/agent/adapter-api.d.ts +416 -0
  1282. package/dist/agent/adapter-api.d.ts.map +1 -0
  1283. package/dist/agent/adapter-api.js +1147 -0
  1284. package/dist/agent/adapter-api.js.map +1 -0
  1285. package/dist/agent/analytics/compile.d.ts +127 -0
  1286. package/dist/agent/analytics/compile.d.ts.map +1 -0
  1287. package/dist/agent/analytics/compile.js +406 -0
  1288. package/dist/agent/analytics/compile.js.map +1 -0
  1289. package/dist/agent/analytics/execute.d.ts +20 -0
  1290. package/dist/agent/analytics/execute.d.ts.map +1 -0
  1291. package/dist/agent/analytics/execute.js +146 -0
  1292. package/dist/agent/analytics/execute.js.map +1 -0
  1293. package/dist/agent/analytics/registry.d.ts +89 -0
  1294. package/dist/agent/analytics/registry.d.ts.map +1 -0
  1295. package/dist/agent/analytics/registry.js +216 -0
  1296. package/dist/agent/analytics/registry.js.map +1 -0
  1297. package/dist/agent/approvals/access-request.d.ts +53 -0
  1298. package/dist/agent/approvals/access-request.d.ts.map +1 -0
  1299. package/dist/agent/approvals/access-request.js +186 -0
  1300. package/dist/agent/approvals/access-request.js.map +1 -0
  1301. package/dist/agent/approvals/actions.d.ts +95 -0
  1302. package/dist/agent/approvals/actions.d.ts.map +1 -0
  1303. package/dist/agent/approvals/actions.js +293 -0
  1304. package/dist/agent/approvals/actions.js.map +1 -0
  1305. package/dist/agent/approvals/agent-create.d.ts +44 -0
  1306. package/dist/agent/approvals/agent-create.d.ts.map +1 -0
  1307. package/dist/agent/approvals/agent-create.js +205 -0
  1308. package/dist/agent/approvals/agent-create.js.map +1 -0
  1309. package/dist/agent/approvals/arming-context.d.ts +13 -0
  1310. package/dist/agent/approvals/arming-context.d.ts.map +1 -0
  1311. package/dist/agent/approvals/arming-context.js +17 -0
  1312. package/dist/agent/approvals/arming-context.js.map +1 -0
  1313. package/dist/agent/approvals/card-disclosure.d.ts +28 -0
  1314. package/dist/agent/approvals/card-disclosure.d.ts.map +1 -0
  1315. package/dist/agent/approvals/card-disclosure.js +31 -0
  1316. package/dist/agent/approvals/card-disclosure.js.map +1 -0
  1317. package/dist/agent/approvals/card-signal.d.ts +41 -0
  1318. package/dist/agent/approvals/card-signal.d.ts.map +1 -0
  1319. package/dist/agent/approvals/card-signal.js +115 -0
  1320. package/dist/agent/approvals/card-signal.js.map +1 -0
  1321. package/dist/agent/approvals/card-venue.d.ts +55 -0
  1322. package/dist/agent/approvals/card-venue.d.ts.map +1 -0
  1323. package/dist/agent/approvals/card-venue.js +106 -0
  1324. package/dist/agent/approvals/card-venue.js.map +1 -0
  1325. package/dist/agent/approvals/card.d.ts +23 -0
  1326. package/dist/agent/approvals/card.d.ts.map +1 -0
  1327. package/dist/agent/approvals/card.js +99 -0
  1328. package/dist/agent/approvals/card.js.map +1 -0
  1329. package/dist/agent/approvals/chat-dm.d.ts +19 -0
  1330. package/dist/agent/approvals/chat-dm.d.ts.map +1 -0
  1331. package/dist/agent/approvals/chat-dm.js +41 -0
  1332. package/dist/agent/approvals/chat-dm.js.map +1 -0
  1333. package/dist/agent/approvals/chat-post.d.ts +15 -0
  1334. package/dist/agent/approvals/chat-post.d.ts.map +1 -0
  1335. package/dist/agent/approvals/chat-post.js +43 -0
  1336. package/dist/agent/approvals/chat-post.js.map +1 -0
  1337. package/dist/agent/approvals/clicker-floor.d.ts +48 -0
  1338. package/dist/agent/approvals/clicker-floor.d.ts.map +1 -0
  1339. package/dist/agent/approvals/clicker-floor.js +58 -0
  1340. package/dist/agent/approvals/clicker-floor.js.map +1 -0
  1341. package/dist/agent/approvals/decision-authority.internal.d.ts +19 -0
  1342. package/dist/agent/approvals/decision-authority.internal.d.ts.map +1 -0
  1343. package/dist/agent/approvals/decision-authority.internal.js +107 -0
  1344. package/dist/agent/approvals/decision-authority.internal.js.map +1 -0
  1345. package/dist/agent/approvals/decision-wake.d.ts +28 -0
  1346. package/dist/agent/approvals/decision-wake.d.ts.map +1 -0
  1347. package/dist/agent/approvals/decision-wake.js +84 -0
  1348. package/dist/agent/approvals/decision-wake.js.map +1 -0
  1349. package/dist/agent/approvals/domain-exposure.d.ts +27 -0
  1350. package/dist/agent/approvals/domain-exposure.d.ts.map +1 -0
  1351. package/dist/agent/approvals/domain-exposure.js +145 -0
  1352. package/dist/agent/approvals/domain-exposure.js.map +1 -0
  1353. package/dist/agent/approvals/eve-response-policy.d.ts +22 -0
  1354. package/dist/agent/approvals/eve-response-policy.d.ts.map +1 -0
  1355. package/dist/agent/approvals/eve-response-policy.js +27 -0
  1356. package/dist/agent/approvals/eve-response-policy.js.map +1 -0
  1357. package/dist/agent/approvals/flow.d.ts +398 -0
  1358. package/dist/agent/approvals/flow.d.ts.map +1 -0
  1359. package/dist/agent/approvals/flow.js +1722 -0
  1360. package/dist/agent/approvals/flow.js.map +1 -0
  1361. package/dist/agent/approvals/input-response-floor.d.ts +47 -0
  1362. package/dist/agent/approvals/input-response-floor.d.ts.map +1 -0
  1363. package/dist/agent/approvals/input-response-floor.js +56 -0
  1364. package/dist/agent/approvals/input-response-floor.js.map +1 -0
  1365. package/dist/agent/approvals/judge-contradiction.d.ts +56 -0
  1366. package/dist/agent/approvals/judge-contradiction.d.ts.map +1 -0
  1367. package/dist/agent/approvals/judge-contradiction.js +90 -0
  1368. package/dist/agent/approvals/judge-contradiction.js.map +1 -0
  1369. package/dist/agent/approvals/memory-purge.d.ts +2 -0
  1370. package/dist/agent/approvals/memory-purge.d.ts.map +1 -0
  1371. package/dist/agent/approvals/memory-purge.js +128 -0
  1372. package/dist/agent/approvals/memory-purge.js.map +1 -0
  1373. package/dist/agent/approvals/pr-open.d.ts +36 -0
  1374. package/dist/agent/approvals/pr-open.d.ts.map +1 -0
  1375. package/dist/agent/approvals/pr-open.js +134 -0
  1376. package/dist/agent/approvals/pr-open.js.map +1 -0
  1377. package/dist/agent/approvals/review-surface.d.ts +3 -0
  1378. package/dist/agent/approvals/review-surface.d.ts.map +1 -0
  1379. package/dist/agent/approvals/review-surface.js +7 -0
  1380. package/dist/agent/approvals/review-surface.js.map +1 -0
  1381. package/dist/agent/approvals/routine-cancel.d.ts +2 -0
  1382. package/dist/agent/approvals/routine-cancel.d.ts.map +1 -0
  1383. package/dist/agent/approvals/routine-cancel.js +39 -0
  1384. package/dist/agent/approvals/routine-cancel.js.map +1 -0
  1385. package/dist/agent/approvals/routine-create.d.ts +38 -0
  1386. package/dist/agent/approvals/routine-create.d.ts.map +1 -0
  1387. package/dist/agent/approvals/routine-create.js +171 -0
  1388. package/dist/agent/approvals/routine-create.js.map +1 -0
  1389. package/dist/agent/approvals/routine-lifecycle.d.ts +2 -0
  1390. package/dist/agent/approvals/routine-lifecycle.d.ts.map +1 -0
  1391. package/dist/agent/approvals/routine-lifecycle.js +135 -0
  1392. package/dist/agent/approvals/routine-lifecycle.js.map +1 -0
  1393. package/dist/agent/approvals/routine-permission-offer.d.ts +35 -0
  1394. package/dist/agent/approvals/routine-permission-offer.d.ts.map +1 -0
  1395. package/dist/agent/approvals/routine-permission-offer.js +90 -0
  1396. package/dist/agent/approvals/routine-permission-offer.js.map +1 -0
  1397. package/dist/agent/approvals/routine-permission.d.ts +51 -0
  1398. package/dist/agent/approvals/routine-permission.d.ts.map +1 -0
  1399. package/dist/agent/approvals/routine-permission.js +173 -0
  1400. package/dist/agent/approvals/routine-permission.js.map +1 -0
  1401. package/dist/agent/approvals/routine-policy.d.ts +2 -0
  1402. package/dist/agent/approvals/routine-policy.d.ts.map +1 -0
  1403. package/dist/agent/approvals/routine-policy.js +133 -0
  1404. package/dist/agent/approvals/routine-policy.js.map +1 -0
  1405. package/dist/agent/approvals/scope-label.d.ts +11 -0
  1406. package/dist/agent/approvals/scope-label.d.ts.map +1 -0
  1407. package/dist/agent/approvals/scope-label.js +43 -0
  1408. package/dist/agent/approvals/scope-label.js.map +1 -0
  1409. package/dist/agent/approvals/session-checkpoint.d.ts +11 -0
  1410. package/dist/agent/approvals/session-checkpoint.d.ts.map +1 -0
  1411. package/dist/agent/approvals/session-checkpoint.js +60 -0
  1412. package/dist/agent/approvals/session-checkpoint.js.map +1 -0
  1413. package/dist/agent/approvals/session-grant.d.ts +46 -0
  1414. package/dist/agent/approvals/session-grant.d.ts.map +1 -0
  1415. package/dist/agent/approvals/session-grant.js +153 -0
  1416. package/dist/agent/approvals/session-grant.js.map +1 -0
  1417. package/dist/agent/approvals/skill-create.d.ts +2 -0
  1418. package/dist/agent/approvals/skill-create.d.ts.map +1 -0
  1419. package/dist/agent/approvals/skill-create.js +42 -0
  1420. package/dist/agent/approvals/skill-create.js.map +1 -0
  1421. package/dist/agent/approvals/skill-delete.d.ts +2 -0
  1422. package/dist/agent/approvals/skill-delete.d.ts.map +1 -0
  1423. package/dist/agent/approvals/skill-delete.js +38 -0
  1424. package/dist/agent/approvals/skill-delete.js.map +1 -0
  1425. package/dist/agent/approvals/taint-disclosure.d.ts +10 -0
  1426. package/dist/agent/approvals/taint-disclosure.d.ts.map +1 -0
  1427. package/dist/agent/approvals/taint-disclosure.js +36 -0
  1428. package/dist/agent/approvals/taint-disclosure.js.map +1 -0
  1429. package/dist/agent/approvals/ticket-actions.d.ts +27 -0
  1430. package/dist/agent/approvals/ticket-actions.d.ts.map +1 -0
  1431. package/dist/agent/approvals/ticket-actions.js +47 -0
  1432. package/dist/agent/approvals/ticket-actions.js.map +1 -0
  1433. package/dist/agent/approvals/ticket-create.d.ts +19 -0
  1434. package/dist/agent/approvals/ticket-create.d.ts.map +1 -0
  1435. package/dist/agent/approvals/ticket-create.js +46 -0
  1436. package/dist/agent/approvals/ticket-create.js.map +1 -0
  1437. package/dist/agent/approvals/types.d.ts +42 -0
  1438. package/dist/agent/approvals/types.d.ts.map +1 -0
  1439. package/dist/agent/approvals/types.js +3 -0
  1440. package/dist/agent/approvals/types.js.map +1 -0
  1441. package/dist/agent/approvals/webhook-declare.d.ts +55 -0
  1442. package/dist/agent/approvals/webhook-declare.d.ts.map +1 -0
  1443. package/dist/agent/approvals/webhook-declare.js +239 -0
  1444. package/dist/agent/approvals/webhook-declare.js.map +1 -0
  1445. package/dist/agent/approvals/webhook.d.ts +25 -0
  1446. package/dist/agent/approvals/webhook.d.ts.map +1 -0
  1447. package/dist/agent/approvals/webhook.js +156 -0
  1448. package/dist/agent/approvals/webhook.js.map +1 -0
  1449. package/dist/agent/audit/action-registry.d.ts +78 -0
  1450. package/dist/agent/audit/action-registry.d.ts.map +1 -0
  1451. package/dist/agent/audit/action-registry.js +996 -0
  1452. package/dist/agent/audit/action-registry.js.map +1 -0
  1453. package/dist/agent/audit/audit.d.ts +32 -0
  1454. package/dist/agent/audit/audit.d.ts.map +1 -0
  1455. package/dist/agent/audit/audit.js +100 -0
  1456. package/dist/agent/audit/audit.js.map +1 -0
  1457. package/dist/agent/audit/chain.d.ts +196 -0
  1458. package/dist/agent/audit/chain.d.ts.map +1 -0
  1459. package/dist/agent/audit/chain.js +462 -0
  1460. package/dist/agent/audit/chain.js.map +1 -0
  1461. package/dist/agent/audit/tool-action.d.ts +26 -0
  1462. package/dist/agent/audit/tool-action.d.ts.map +1 -0
  1463. package/dist/agent/audit/tool-action.js +271 -0
  1464. package/dist/agent/audit/tool-action.js.map +1 -0
  1465. package/dist/agent/audit/window-tool-gate.d.ts +21 -0
  1466. package/dist/agent/audit/window-tool-gate.d.ts.map +1 -0
  1467. package/dist/agent/audit/window-tool-gate.js +40 -0
  1468. package/dist/agent/audit/window-tool-gate.js.map +1 -0
  1469. package/dist/agent/audit/worker-toolset.d.ts +25 -0
  1470. package/dist/agent/audit/worker-toolset.d.ts.map +1 -0
  1471. package/dist/agent/audit/worker-toolset.js +108 -0
  1472. package/dist/agent/audit/worker-toolset.js.map +1 -0
  1473. package/dist/agent/blob/hosting.d.ts +61 -0
  1474. package/dist/agent/blob/hosting.d.ts.map +1 -0
  1475. package/dist/agent/blob/hosting.js +142 -0
  1476. package/dist/agent/blob/hosting.js.map +1 -0
  1477. package/dist/agent/channels/access-request-ledger.d.ts +36 -0
  1478. package/dist/agent/channels/access-request-ledger.d.ts.map +1 -0
  1479. package/dist/agent/channels/access-request-ledger.js +123 -0
  1480. package/dist/agent/channels/access-request-ledger.js.map +1 -0
  1481. package/dist/agent/channels/ambient-skip.d.ts +19 -0
  1482. package/dist/agent/channels/ambient-skip.d.ts.map +1 -0
  1483. package/dist/agent/channels/ambient-skip.js +88 -0
  1484. package/dist/agent/channels/ambient-skip.js.map +1 -0
  1485. package/dist/agent/channels/answered-container-ledger.d.ts +32 -0
  1486. package/dist/agent/channels/answered-container-ledger.d.ts.map +1 -0
  1487. package/dist/agent/channels/answered-container-ledger.js +70 -0
  1488. package/dist/agent/channels/answered-container-ledger.js.map +1 -0
  1489. package/dist/agent/channels/approval-card.d.ts +266 -0
  1490. package/dist/agent/channels/approval-card.d.ts.map +1 -0
  1491. package/dist/agent/channels/approval-card.js +328 -0
  1492. package/dist/agent/channels/approval-card.js.map +1 -0
  1493. package/dist/agent/channels/approval-claim-guard.d.ts +112 -0
  1494. package/dist/agent/channels/approval-claim-guard.d.ts.map +1 -0
  1495. package/dist/agent/channels/approval-claim-guard.js +324 -0
  1496. package/dist/agent/channels/approval-claim-guard.js.map +1 -0
  1497. package/dist/agent/channels/attachments.d.ts +113 -0
  1498. package/dist/agent/channels/attachments.d.ts.map +1 -0
  1499. package/dist/agent/channels/attachments.js +157 -0
  1500. package/dist/agent/channels/attachments.js.map +1 -0
  1501. package/dist/agent/channels/aws-sso-callback.d.ts +3 -0
  1502. package/dist/agent/channels/aws-sso-callback.d.ts.map +1 -0
  1503. package/dist/agent/channels/aws-sso-callback.js +8 -0
  1504. package/dist/agent/channels/aws-sso-callback.js.map +1 -0
  1505. package/dist/agent/channels/backscroll-window.d.ts +76 -0
  1506. package/dist/agent/channels/backscroll-window.d.ts.map +1 -0
  1507. package/dist/agent/channels/backscroll-window.js +106 -0
  1508. package/dist/agent/channels/backscroll-window.js.map +1 -0
  1509. package/dist/agent/channels/cancel-note.d.ts +45 -0
  1510. package/dist/agent/channels/cancel-note.d.ts.map +1 -0
  1511. package/dist/agent/channels/cancel-note.js +99 -0
  1512. package/dist/agent/channels/cancel-note.js.map +1 -0
  1513. package/dist/agent/channels/channel-key.d.ts +19 -0
  1514. package/dist/agent/channels/channel-key.d.ts.map +1 -0
  1515. package/dist/agent/channels/channel-key.js +53 -0
  1516. package/dist/agent/channels/channel-key.js.map +1 -0
  1517. package/dist/agent/channels/channel-read.d.ts +203 -0
  1518. package/dist/agent/channels/channel-read.d.ts.map +1 -0
  1519. package/dist/agent/channels/channel-read.js +294 -0
  1520. package/dist/agent/channels/channel-read.js.map +1 -0
  1521. package/dist/agent/channels/chat-turn-audit.d.ts +9 -0
  1522. package/dist/agent/channels/chat-turn-audit.d.ts.map +1 -0
  1523. package/dist/agent/channels/chat-turn-audit.js +18 -0
  1524. package/dist/agent/channels/chat-turn-audit.js.map +1 -0
  1525. package/dist/agent/channels/closing-prose-drop.d.ts +34 -0
  1526. package/dist/agent/channels/closing-prose-drop.d.ts.map +1 -0
  1527. package/dist/agent/channels/closing-prose-drop.js +29 -0
  1528. package/dist/agent/channels/closing-prose-drop.js.map +1 -0
  1529. package/dist/agent/channels/command-registration.d.ts +62 -0
  1530. package/dist/agent/channels/command-registration.d.ts.map +1 -0
  1531. package/dist/agent/channels/command-registration.js +128 -0
  1532. package/dist/agent/channels/command-registration.js.map +1 -0
  1533. package/dist/agent/channels/context-render.d.ts +111 -0
  1534. package/dist/agent/channels/context-render.d.ts.map +1 -0
  1535. package/dist/agent/channels/context-render.js +148 -0
  1536. package/dist/agent/channels/context-render.js.map +1 -0
  1537. package/dist/agent/channels/control-mcp.d.ts +3 -0
  1538. package/dist/agent/channels/control-mcp.d.ts.map +1 -0
  1539. package/dist/agent/channels/control-mcp.js +35 -0
  1540. package/dist/agent/channels/control-mcp.js.map +1 -0
  1541. package/dist/agent/channels/control-read.d.ts +3 -0
  1542. package/dist/agent/channels/control-read.d.ts.map +1 -0
  1543. package/dist/agent/channels/control-read.js +21 -0
  1544. package/dist/agent/channels/control-read.js.map +1 -0
  1545. package/dist/agent/channels/credential-intake-page.d.ts +3 -0
  1546. package/dist/agent/channels/credential-intake-page.d.ts.map +1 -0
  1547. package/dist/agent/channels/credential-intake-page.js +11 -0
  1548. package/dist/agent/channels/credential-intake-page.js.map +1 -0
  1549. package/dist/agent/channels/delegated-provenance.d.ts +129 -0
  1550. package/dist/agent/channels/delegated-provenance.d.ts.map +1 -0
  1551. package/dist/agent/channels/delegated-provenance.js +418 -0
  1552. package/dist/agent/channels/delegated-provenance.js.map +1 -0
  1553. package/dist/agent/channels/dm-audience.d.ts +157 -0
  1554. package/dist/agent/channels/dm-audience.d.ts.map +1 -0
  1555. package/dist/agent/channels/dm-audience.js +234 -0
  1556. package/dist/agent/channels/dm-audience.js.map +1 -0
  1557. package/dist/agent/channels/dm-seat.d.ts +68 -0
  1558. package/dist/agent/channels/dm-seat.d.ts.map +1 -0
  1559. package/dist/agent/channels/dm-seat.js +87 -0
  1560. package/dist/agent/channels/dm-seat.js.map +1 -0
  1561. package/dist/agent/channels/domain-fingerprint.d.ts +40 -0
  1562. package/dist/agent/channels/domain-fingerprint.d.ts.map +1 -0
  1563. package/dist/agent/channels/domain-fingerprint.js +94 -0
  1564. package/dist/agent/channels/domain-fingerprint.js.map +1 -0
  1565. package/dist/agent/channels/egress-spoof.d.ts +11 -0
  1566. package/dist/agent/channels/egress-spoof.d.ts.map +1 -0
  1567. package/dist/agent/channels/egress-spoof.js +36 -0
  1568. package/dist/agent/channels/egress-spoof.js.map +1 -0
  1569. package/dist/agent/channels/engaged-wake.d.ts +86 -0
  1570. package/dist/agent/channels/engaged-wake.d.ts.map +1 -0
  1571. package/dist/agent/channels/engaged-wake.js +146 -0
  1572. package/dist/agent/channels/engaged-wake.js.map +1 -0
  1573. package/dist/agent/channels/engagement.d.ts +132 -0
  1574. package/dist/agent/channels/engagement.d.ts.map +1 -0
  1575. package/dist/agent/channels/engagement.js +182 -0
  1576. package/dist/agent/channels/engagement.js.map +1 -0
  1577. package/dist/agent/channels/entity-actions.d.ts +80 -0
  1578. package/dist/agent/channels/entity-actions.d.ts.map +1 -0
  1579. package/dist/agent/channels/entity-actions.js +94 -0
  1580. package/dist/agent/channels/entity-actions.js.map +1 -0
  1581. package/dist/agent/channels/front-queue.d.ts +31 -0
  1582. package/dist/agent/channels/front-queue.d.ts.map +1 -0
  1583. package/dist/agent/channels/front-queue.js +86 -0
  1584. package/dist/agent/channels/front-queue.js.map +1 -0
  1585. package/dist/agent/channels/generation-retirement.d.ts +189 -0
  1586. package/dist/agent/channels/generation-retirement.d.ts.map +1 -0
  1587. package/dist/agent/channels/generation-retirement.js +473 -0
  1588. package/dist/agent/channels/generation-retirement.js.map +1 -0
  1589. package/dist/agent/channels/halt-per-wake.d.ts +53 -0
  1590. package/dist/agent/channels/halt-per-wake.d.ts.map +1 -0
  1591. package/dist/agent/channels/halt-per-wake.js +148 -0
  1592. package/dist/agent/channels/halt-per-wake.js.map +1 -0
  1593. package/dist/agent/channels/memory-claim-guard.d.ts +77 -0
  1594. package/dist/agent/channels/memory-claim-guard.d.ts.map +1 -0
  1595. package/dist/agent/channels/memory-claim-guard.js +389 -0
  1596. package/dist/agent/channels/memory-claim-guard.js.map +1 -0
  1597. package/dist/agent/channels/name-drop-wake-audit.d.ts +93 -0
  1598. package/dist/agent/channels/name-drop-wake-audit.d.ts.map +1 -0
  1599. package/dist/agent/channels/name-drop-wake-audit.js +92 -0
  1600. package/dist/agent/channels/name-drop-wake-audit.js.map +1 -0
  1601. package/dist/agent/channels/native-wake-retry.d.ts +16 -0
  1602. package/dist/agent/channels/native-wake-retry.d.ts.map +1 -0
  1603. package/dist/agent/channels/native-wake-retry.js +44 -0
  1604. package/dist/agent/channels/native-wake-retry.js.map +1 -0
  1605. package/dist/agent/channels/no-reply-signal.d.ts +12 -0
  1606. package/dist/agent/channels/no-reply-signal.d.ts.map +1 -0
  1607. package/dist/agent/channels/no-reply-signal.js +37 -0
  1608. package/dist/agent/channels/no-reply-signal.js.map +1 -0
  1609. package/dist/agent/channels/normalized-wake.d.ts +129 -0
  1610. package/dist/agent/channels/normalized-wake.d.ts.map +1 -0
  1611. package/dist/agent/channels/normalized-wake.js +153 -0
  1612. package/dist/agent/channels/normalized-wake.js.map +1 -0
  1613. package/dist/agent/channels/oe-oauth-callback.d.ts +3 -0
  1614. package/dist/agent/channels/oe-oauth-callback.d.ts.map +1 -0
  1615. package/dist/agent/channels/oe-oauth-callback.js +8 -0
  1616. package/dist/agent/channels/oe-oauth-callback.js.map +1 -0
  1617. package/dist/agent/channels/own-post-ledger.d.ts +35 -0
  1618. package/dist/agent/channels/own-post-ledger.d.ts.map +1 -0
  1619. package/dist/agent/channels/own-post-ledger.js +57 -0
  1620. package/dist/agent/channels/own-post-ledger.js.map +1 -0
  1621. package/dist/agent/channels/platform-failure.d.ts +20 -0
  1622. package/dist/agent/channels/platform-failure.d.ts.map +1 -0
  1623. package/dist/agent/channels/platform-failure.js +42 -0
  1624. package/dist/agent/channels/platform-failure.js.map +1 -0
  1625. package/dist/agent/channels/policy-pages.d.ts +3 -0
  1626. package/dist/agent/channels/policy-pages.d.ts.map +1 -0
  1627. package/dist/agent/channels/policy-pages.js +14 -0
  1628. package/dist/agent/channels/policy-pages.js.map +1 -0
  1629. package/dist/agent/channels/post-arms.d.ts +202 -0
  1630. package/dist/agent/channels/post-arms.d.ts.map +1 -0
  1631. package/dist/agent/channels/post-arms.js +146 -0
  1632. package/dist/agent/channels/post-arms.js.map +1 -0
  1633. package/dist/agent/channels/proactive-dm-manifest.d.ts +28 -0
  1634. package/dist/agent/channels/proactive-dm-manifest.d.ts.map +1 -0
  1635. package/dist/agent/channels/proactive-dm-manifest.js +80 -0
  1636. package/dist/agent/channels/proactive-dm-manifest.js.map +1 -0
  1637. package/dist/agent/channels/propose-scope.d.ts +18 -0
  1638. package/dist/agent/channels/propose-scope.d.ts.map +1 -0
  1639. package/dist/agent/channels/propose-scope.js +91 -0
  1640. package/dist/agent/channels/propose-scope.js.map +1 -0
  1641. package/dist/agent/channels/question-bridge.d.ts +291 -0
  1642. package/dist/agent/channels/question-bridge.d.ts.map +1 -0
  1643. package/dist/agent/channels/question-bridge.js +412 -0
  1644. package/dist/agent/channels/question-bridge.js.map +1 -0
  1645. package/dist/agent/channels/rate-limit-retry.d.ts +157 -0
  1646. package/dist/agent/channels/rate-limit-retry.d.ts.map +1 -0
  1647. package/dist/agent/channels/rate-limit-retry.js +256 -0
  1648. package/dist/agent/channels/rate-limit-retry.js.map +1 -0
  1649. package/dist/agent/channels/react-signal.d.ts +5 -0
  1650. package/dist/agent/channels/react-signal.d.ts.map +1 -0
  1651. package/dist/agent/channels/react-signal.js +25 -0
  1652. package/dist/agent/channels/react-signal.js.map +1 -0
  1653. package/dist/agent/channels/reaction-ingest.d.ts +87 -0
  1654. package/dist/agent/channels/reaction-ingest.d.ts.map +1 -0
  1655. package/dist/agent/channels/reaction-ingest.js +138 -0
  1656. package/dist/agent/channels/reaction-ingest.js.map +1 -0
  1657. package/dist/agent/channels/read-author-trust.d.ts +26 -0
  1658. package/dist/agent/channels/read-author-trust.d.ts.map +1 -0
  1659. package/dist/agent/channels/read-author-trust.js +56 -0
  1660. package/dist/agent/channels/read-author-trust.js.map +1 -0
  1661. package/dist/agent/channels/read-reach.d.ts +156 -0
  1662. package/dist/agent/channels/read-reach.d.ts.map +1 -0
  1663. package/dist/agent/channels/read-reach.js +293 -0
  1664. package/dist/agent/channels/read-reach.js.map +1 -0
  1665. package/dist/agent/channels/read-scope-audit.d.ts +39 -0
  1666. package/dist/agent/channels/read-scope-audit.d.ts.map +1 -0
  1667. package/dist/agent/channels/read-scope-audit.js +88 -0
  1668. package/dist/agent/channels/read-scope-audit.js.map +1 -0
  1669. package/dist/agent/channels/read-scope-error.d.ts +4 -0
  1670. package/dist/agent/channels/read-scope-error.d.ts.map +1 -0
  1671. package/dist/agent/channels/read-scope-error.js +6 -0
  1672. package/dist/agent/channels/read-scope-error.js.map +1 -0
  1673. package/dist/agent/channels/read-spool.d.ts +38 -0
  1674. package/dist/agent/channels/read-spool.d.ts.map +1 -0
  1675. package/dist/agent/channels/read-spool.js +97 -0
  1676. package/dist/agent/channels/read-spool.js.map +1 -0
  1677. package/dist/agent/channels/reply-edit.d.ts +47 -0
  1678. package/dist/agent/channels/reply-edit.d.ts.map +1 -0
  1679. package/dist/agent/channels/reply-edit.js +173 -0
  1680. package/dist/agent/channels/reply-edit.js.map +1 -0
  1681. package/dist/agent/channels/reply-fold.d.ts +186 -0
  1682. package/dist/agent/channels/reply-fold.d.ts.map +1 -0
  1683. package/dist/agent/channels/reply-fold.js +427 -0
  1684. package/dist/agent/channels/reply-fold.js.map +1 -0
  1685. package/dist/agent/channels/reply-freshness.d.ts +69 -0
  1686. package/dist/agent/channels/reply-freshness.d.ts.map +1 -0
  1687. package/dist/agent/channels/reply-freshness.js +208 -0
  1688. package/dist/agent/channels/reply-freshness.js.map +1 -0
  1689. package/dist/agent/channels/reply-post.d.ts +176 -0
  1690. package/dist/agent/channels/reply-post.d.ts.map +1 -0
  1691. package/dist/agent/channels/reply-post.js +407 -0
  1692. package/dist/agent/channels/reply-post.js.map +1 -0
  1693. package/dist/agent/channels/reply-provenance.d.ts +172 -0
  1694. package/dist/agent/channels/reply-provenance.d.ts.map +1 -0
  1695. package/dist/agent/channels/reply-provenance.js +662 -0
  1696. package/dist/agent/channels/reply-provenance.js.map +1 -0
  1697. package/dist/agent/channels/reply-signal.d.ts +141 -0
  1698. package/dist/agent/channels/reply-signal.d.ts.map +1 -0
  1699. package/dist/agent/channels/reply-signal.js +554 -0
  1700. package/dist/agent/channels/reply-signal.js.map +1 -0
  1701. package/dist/agent/channels/request-claim-guard.d.ts +91 -0
  1702. package/dist/agent/channels/request-claim-guard.d.ts.map +1 -0
  1703. package/dist/agent/channels/request-claim-guard.js +457 -0
  1704. package/dist/agent/channels/request-claim-guard.js.map +1 -0
  1705. package/dist/agent/channels/runtime-code-fingerprint.generated.d.ts +2 -0
  1706. package/dist/agent/channels/runtime-code-fingerprint.generated.d.ts.map +1 -0
  1707. package/dist/agent/channels/runtime-code-fingerprint.generated.js +9 -0
  1708. package/dist/agent/channels/runtime-code-fingerprint.generated.js.map +1 -0
  1709. package/dist/agent/channels/runtime-rotation.d.ts +98 -0
  1710. package/dist/agent/channels/runtime-rotation.d.ts.map +1 -0
  1711. package/dist/agent/channels/runtime-rotation.js +178 -0
  1712. package/dist/agent/channels/runtime-rotation.js.map +1 -0
  1713. package/dist/agent/channels/seat-admission.d.ts +61 -0
  1714. package/dist/agent/channels/seat-admission.d.ts.map +1 -0
  1715. package/dist/agent/channels/seat-admission.js +64 -0
  1716. package/dist/agent/channels/seat-admission.js.map +1 -0
  1717. package/dist/agent/channels/seat-catch-up.d.ts +240 -0
  1718. package/dist/agent/channels/seat-catch-up.d.ts.map +1 -0
  1719. package/dist/agent/channels/seat-catch-up.js +353 -0
  1720. package/dist/agent/channels/seat-catch-up.js.map +1 -0
  1721. package/dist/agent/channels/self-dispatch.d.ts +89 -0
  1722. package/dist/agent/channels/self-dispatch.d.ts.map +1 -0
  1723. package/dist/agent/channels/self-dispatch.js +310 -0
  1724. package/dist/agent/channels/self-dispatch.js.map +1 -0
  1725. package/dist/agent/channels/session-park.d.ts +120 -0
  1726. package/dist/agent/channels/session-park.d.ts.map +1 -0
  1727. package/dist/agent/channels/session-park.js +170 -0
  1728. package/dist/agent/channels/session-park.js.map +1 -0
  1729. package/dist/agent/channels/session-resume.d.ts +26 -0
  1730. package/dist/agent/channels/session-resume.d.ts.map +1 -0
  1731. package/dist/agent/channels/session-resume.js +34 -0
  1732. package/dist/agent/channels/session-resume.js.map +1 -0
  1733. package/dist/agent/channels/session-tail-record.d.ts +65 -0
  1734. package/dist/agent/channels/session-tail-record.d.ts.map +1 -0
  1735. package/dist/agent/channels/session-tail-record.js +129 -0
  1736. package/dist/agent/channels/session-tail-record.js.map +1 -0
  1737. package/dist/agent/channels/session-tail.d.ts +90 -0
  1738. package/dist/agent/channels/session-tail.d.ts.map +1 -0
  1739. package/dist/agent/channels/session-tail.js +79 -0
  1740. package/dist/agent/channels/session-tail.js.map +1 -0
  1741. package/dist/agent/channels/slack-bridge.d.ts +56 -0
  1742. package/dist/agent/channels/slack-bridge.d.ts.map +1 -0
  1743. package/dist/agent/channels/slack-bridge.js +80 -0
  1744. package/dist/agent/channels/slack-bridge.js.map +1 -0
  1745. package/dist/agent/channels/stand-down-silence.d.ts +49 -0
  1746. package/dist/agent/channels/stand-down-silence.d.ts.map +1 -0
  1747. package/dist/agent/channels/stand-down-silence.js +101 -0
  1748. package/dist/agent/channels/stand-down-silence.js.map +1 -0
  1749. package/dist/agent/channels/standing-authority.d.ts +69 -0
  1750. package/dist/agent/channels/standing-authority.d.ts.map +1 -0
  1751. package/dist/agent/channels/standing-authority.js +205 -0
  1752. package/dist/agent/channels/standing-authority.js.map +1 -0
  1753. package/dist/agent/channels/stranded-seat.d.ts +73 -0
  1754. package/dist/agent/channels/stranded-seat.d.ts.map +1 -0
  1755. package/dist/agent/channels/stranded-seat.js +107 -0
  1756. package/dist/agent/channels/stranded-seat.js.map +1 -0
  1757. package/dist/agent/channels/supervisor-complete.d.ts +61 -0
  1758. package/dist/agent/channels/supervisor-complete.d.ts.map +1 -0
  1759. package/dist/agent/channels/supervisor-complete.js +86 -0
  1760. package/dist/agent/channels/supervisor-complete.js.map +1 -0
  1761. package/dist/agent/channels/surface-message-ops.d.ts +100 -0
  1762. package/dist/agent/channels/surface-message-ops.d.ts.map +1 -0
  1763. package/dist/agent/channels/surface-message-ops.js +156 -0
  1764. package/dist/agent/channels/surface-message-ops.js.map +1 -0
  1765. package/dist/agent/channels/task-wake.d.ts +116 -0
  1766. package/dist/agent/channels/task-wake.d.ts.map +1 -0
  1767. package/dist/agent/channels/task-wake.js +390 -0
  1768. package/dist/agent/channels/task-wake.js.map +1 -0
  1769. package/dist/agent/channels/teams-bridge.d.ts +55 -0
  1770. package/dist/agent/channels/teams-bridge.d.ts.map +1 -0
  1771. package/dist/agent/channels/teams-bridge.js +25 -0
  1772. package/dist/agent/channels/teams-bridge.js.map +1 -0
  1773. package/dist/agent/channels/test-wake.d.ts +3 -0
  1774. package/dist/agent/channels/test-wake.d.ts.map +1 -0
  1775. package/dist/agent/channels/test-wake.js +11 -0
  1776. package/dist/agent/channels/test-wake.js.map +1 -0
  1777. package/dist/agent/channels/thread-ownership.d.ts +38 -0
  1778. package/dist/agent/channels/thread-ownership.d.ts.map +1 -0
  1779. package/dist/agent/channels/thread-ownership.js +53 -0
  1780. package/dist/agent/channels/thread-ownership.js.map +1 -0
  1781. package/dist/agent/channels/thread-seat-state.d.ts +35 -0
  1782. package/dist/agent/channels/thread-seat-state.d.ts.map +1 -0
  1783. package/dist/agent/channels/thread-seat-state.js +64 -0
  1784. package/dist/agent/channels/thread-seat-state.js.map +1 -0
  1785. package/dist/agent/channels/ticket-create.d.ts +77 -0
  1786. package/dist/agent/channels/ticket-create.d.ts.map +1 -0
  1787. package/dist/agent/channels/ticket-create.js +83 -0
  1788. package/dist/agent/channels/ticket-create.js.map +1 -0
  1789. package/dist/agent/channels/transcript-relay.d.ts +3 -0
  1790. package/dist/agent/channels/transcript-relay.d.ts.map +1 -0
  1791. package/dist/agent/channels/transcript-relay.js +8 -0
  1792. package/dist/agent/channels/transcript-relay.js.map +1 -0
  1793. package/dist/agent/channels/turn-cancel.d.ts +188 -0
  1794. package/dist/agent/channels/turn-cancel.d.ts.map +1 -0
  1795. package/dist/agent/channels/turn-cancel.js +310 -0
  1796. package/dist/agent/channels/turn-cancel.js.map +1 -0
  1797. package/dist/agent/channels/turn-delivery.d.ts +213 -0
  1798. package/dist/agent/channels/turn-delivery.d.ts.map +1 -0
  1799. package/dist/agent/channels/turn-delivery.js +384 -0
  1800. package/dist/agent/channels/turn-delivery.js.map +1 -0
  1801. package/dist/agent/channels/turn-registry.d.ts +47 -0
  1802. package/dist/agent/channels/turn-registry.d.ts.map +1 -0
  1803. package/dist/agent/channels/turn-registry.js +93 -0
  1804. package/dist/agent/channels/turn-registry.js.map +1 -0
  1805. package/dist/agent/channels/turn-terminal-actions.d.ts +22 -0
  1806. package/dist/agent/channels/turn-terminal-actions.d.ts.map +1 -0
  1807. package/dist/agent/channels/turn-terminal-actions.js +128 -0
  1808. package/dist/agent/channels/turn-terminal-actions.js.map +1 -0
  1809. package/dist/agent/channels/unified-redrive.d.ts +74 -0
  1810. package/dist/agent/channels/unified-redrive.d.ts.map +1 -0
  1811. package/dist/agent/channels/unified-redrive.js +141 -0
  1812. package/dist/agent/channels/unified-redrive.js.map +1 -0
  1813. package/dist/agent/channels/unified-reply.d.ts +102 -0
  1814. package/dist/agent/channels/unified-reply.d.ts.map +1 -0
  1815. package/dist/agent/channels/unified-reply.js +247 -0
  1816. package/dist/agent/channels/unified-reply.js.map +1 -0
  1817. package/dist/agent/channels/unified-supervisor.d.ts +100 -0
  1818. package/dist/agent/channels/unified-supervisor.d.ts.map +1 -0
  1819. package/dist/agent/channels/unified-supervisor.js +143 -0
  1820. package/dist/agent/channels/unified-supervisor.js.map +1 -0
  1821. package/dist/agent/channels/unified-window.d.ts +550 -0
  1822. package/dist/agent/channels/unified-window.d.ts.map +1 -0
  1823. package/dist/agent/channels/unified-window.js +731 -0
  1824. package/dist/agent/channels/unified-window.js.map +1 -0
  1825. package/dist/agent/channels/unified.d.ts +251 -0
  1826. package/dist/agent/channels/unified.d.ts.map +1 -0
  1827. package/dist/agent/channels/unified.js +1333 -0
  1828. package/dist/agent/channels/unified.js.map +1 -0
  1829. package/dist/agent/channels/wake-accounting.d.ts +57 -0
  1830. package/dist/agent/channels/wake-accounting.d.ts.map +1 -0
  1831. package/dist/agent/channels/wake-accounting.js +87 -0
  1832. package/dist/agent/channels/wake-accounting.js.map +1 -0
  1833. package/dist/agent/channels/wake-arm.d.ts +80 -0
  1834. package/dist/agent/channels/wake-arm.d.ts.map +1 -0
  1835. package/dist/agent/channels/wake-arm.js +173 -0
  1836. package/dist/agent/channels/wake-arm.js.map +1 -0
  1837. package/dist/agent/channels/wake-container.d.ts +27 -0
  1838. package/dist/agent/channels/wake-container.d.ts.map +1 -0
  1839. package/dist/agent/channels/wake-container.js +33 -0
  1840. package/dist/agent/channels/wake-container.js.map +1 -0
  1841. package/dist/agent/channels/wake-envelope.d.ts +252 -0
  1842. package/dist/agent/channels/wake-envelope.d.ts.map +1 -0
  1843. package/dist/agent/channels/wake-envelope.js +364 -0
  1844. package/dist/agent/channels/wake-envelope.js.map +1 -0
  1845. package/dist/agent/channels/wake-origin-codec.d.ts +77 -0
  1846. package/dist/agent/channels/wake-origin-codec.d.ts.map +1 -0
  1847. package/dist/agent/channels/wake-origin-codec.js +21 -0
  1848. package/dist/agent/channels/wake-origin-codec.js.map +1 -0
  1849. package/dist/agent/channels/wake-origin-codecs.d.ts +2 -0
  1850. package/dist/agent/channels/wake-origin-codecs.d.ts.map +1 -0
  1851. package/dist/agent/channels/wake-origin-codecs.js +4 -0
  1852. package/dist/agent/channels/wake-origin-codecs.js.map +1 -0
  1853. package/dist/agent/channels/wake-timing.d.ts +230 -0
  1854. package/dist/agent/channels/wake-timing.d.ts.map +1 -0
  1855. package/dist/agent/channels/wake-timing.js +256 -0
  1856. package/dist/agent/channels/wake-timing.js.map +1 -0
  1857. package/dist/agent/channels/webhook-reveal-page.d.ts +3 -0
  1858. package/dist/agent/channels/webhook-reveal-page.d.ts.map +1 -0
  1859. package/dist/agent/channels/webhook-reveal-page.js +11 -0
  1860. package/dist/agent/channels/webhook-reveal-page.js.map +1 -0
  1861. package/dist/agent/channels/webhooks.d.ts +5 -0
  1862. package/dist/agent/channels/webhooks.d.ts.map +1 -0
  1863. package/dist/agent/channels/webhooks.js +197 -0
  1864. package/dist/agent/channels/webhooks.js.map +1 -0
  1865. package/dist/agent/channels/window-key.d.ts +187 -0
  1866. package/dist/agent/channels/window-key.d.ts.map +1 -0
  1867. package/dist/agent/channels/window-key.js +379 -0
  1868. package/dist/agent/channels/window-key.js.map +1 -0
  1869. package/dist/agent/channels/window-sources.d.ts +17 -0
  1870. package/dist/agent/channels/window-sources.d.ts.map +1 -0
  1871. package/dist/agent/channels/window-sources.js +86 -0
  1872. package/dist/agent/channels/window-sources.js.map +1 -0
  1873. package/dist/agent/channels/work-destinations.d.ts +8 -0
  1874. package/dist/agent/channels/work-destinations.d.ts.map +1 -0
  1875. package/dist/agent/channels/work-destinations.js +45 -0
  1876. package/dist/agent/channels/work-destinations.js.map +1 -0
  1877. package/dist/agent/channels/work-registry.d.ts +13 -0
  1878. package/dist/agent/channels/work-registry.d.ts.map +1 -0
  1879. package/dist/agent/channels/work-registry.js +23 -0
  1880. package/dist/agent/channels/work-registry.js.map +1 -0
  1881. package/dist/agent/channels/work-search.d.ts +52 -0
  1882. package/dist/agent/channels/work-search.d.ts.map +1 -0
  1883. package/dist/agent/channels/work-search.js +54 -0
  1884. package/dist/agent/channels/work-search.js.map +1 -0
  1885. package/dist/agent/commands/core.d.ts +184 -0
  1886. package/dist/agent/commands/core.d.ts.map +1 -0
  1887. package/dist/agent/commands/core.js +541 -0
  1888. package/dist/agent/commands/core.js.map +1 -0
  1889. package/dist/agent/commands/rate.d.ts +55 -0
  1890. package/dist/agent/commands/rate.d.ts.map +1 -0
  1891. package/dist/agent/commands/rate.js +146 -0
  1892. package/dist/agent/commands/rate.js.map +1 -0
  1893. package/dist/agent/connections/auth-retry-memo.d.ts +28 -0
  1894. package/dist/agent/connections/auth-retry-memo.d.ts.map +1 -0
  1895. package/dist/agent/connections/auth-retry-memo.js +109 -0
  1896. package/dist/agent/connections/auth-retry-memo.js.map +1 -0
  1897. package/dist/agent/connections/aws-exec.d.ts +27 -0
  1898. package/dist/agent/connections/aws-exec.d.ts.map +1 -0
  1899. package/dist/agent/connections/aws-exec.js +22 -0
  1900. package/dist/agent/connections/aws-exec.js.map +1 -0
  1901. package/dist/agent/connections/aws-identity.d.ts +138 -0
  1902. package/dist/agent/connections/aws-identity.d.ts.map +1 -0
  1903. package/dist/agent/connections/aws-identity.js +163 -0
  1904. package/dist/agent/connections/aws-identity.js.map +1 -0
  1905. package/dist/agent/connections/aws-sso-callback.d.ts +33 -0
  1906. package/dist/agent/connections/aws-sso-callback.d.ts.map +1 -0
  1907. package/dist/agent/connections/aws-sso-callback.js +68 -0
  1908. package/dist/agent/connections/aws-sso-callback.js.map +1 -0
  1909. package/dist/agent/connections/aws-sso-identity-binding.d.ts +30 -0
  1910. package/dist/agent/connections/aws-sso-identity-binding.d.ts.map +1 -0
  1911. package/dist/agent/connections/aws-sso-identity-binding.js +95 -0
  1912. package/dist/agent/connections/aws-sso-identity-binding.js.map +1 -0
  1913. package/dist/agent/connections/aws-sso-link.d.ts +18 -0
  1914. package/dist/agent/connections/aws-sso-link.d.ts.map +1 -0
  1915. package/dist/agent/connections/aws-sso-link.js +22 -0
  1916. package/dist/agent/connections/aws-sso-link.js.map +1 -0
  1917. package/dist/agent/connections/connector-auth.d.ts +216 -0
  1918. package/dist/agent/connections/connector-auth.d.ts.map +1 -0
  1919. package/dist/agent/connections/connector-auth.js +745 -0
  1920. package/dist/agent/connections/connector-auth.js.map +1 -0
  1921. package/dist/agent/connections/connector-card.d.ts +61 -0
  1922. package/dist/agent/connections/connector-card.d.ts.map +1 -0
  1923. package/dist/agent/connections/connector-card.js +361 -0
  1924. package/dist/agent/connections/connector-card.js.map +1 -0
  1925. package/dist/agent/connections/connector-flags.d.ts +22 -0
  1926. package/dist/agent/connections/connector-flags.d.ts.map +1 -0
  1927. package/dist/agent/connections/connector-flags.js +40 -0
  1928. package/dist/agent/connections/connector-flags.js.map +1 -0
  1929. package/dist/agent/connections/connector-offer.d.ts +122 -0
  1930. package/dist/agent/connections/connector-offer.d.ts.map +1 -0
  1931. package/dist/agent/connections/connector-offer.js +145 -0
  1932. package/dist/agent/connections/connector-offer.js.map +1 -0
  1933. package/dist/agent/connections/connector-transport.d.ts +55 -0
  1934. package/dist/agent/connections/connector-transport.d.ts.map +1 -0
  1935. package/dist/agent/connections/connector-transport.js +80 -0
  1936. package/dist/agent/connections/connector-transport.js.map +1 -0
  1937. package/dist/agent/connections/consent-resume.d.ts +81 -0
  1938. package/dist/agent/connections/consent-resume.d.ts.map +1 -0
  1939. package/dist/agent/connections/consent-resume.js +142 -0
  1940. package/dist/agent/connections/consent-resume.js.map +1 -0
  1941. package/dist/agent/connections/grant-mcp-borrow.d.ts +116 -0
  1942. package/dist/agent/connections/grant-mcp-borrow.d.ts.map +1 -0
  1943. package/dist/agent/connections/grant-mcp-borrow.js +256 -0
  1944. package/dist/agent/connections/grant-mcp-borrow.js.map +1 -0
  1945. package/dist/agent/connections/grant-mcp-transport.d.ts +13 -0
  1946. package/dist/agent/connections/grant-mcp-transport.d.ts.map +1 -0
  1947. package/dist/agent/connections/grant-mcp-transport.js +50 -0
  1948. package/dist/agent/connections/grant-mcp-transport.js.map +1 -0
  1949. package/dist/agent/connections/notion.d.ts +3 -0
  1950. package/dist/agent/connections/notion.d.ts.map +1 -0
  1951. package/dist/agent/connections/notion.js +35 -0
  1952. package/dist/agent/connections/notion.js.map +1 -0
  1953. package/dist/agent/connections/oe-oauth-callback.d.ts +61 -0
  1954. package/dist/agent/connections/oe-oauth-callback.d.ts.map +1 -0
  1955. package/dist/agent/connections/oe-oauth-callback.js +142 -0
  1956. package/dist/agent/connections/oe-oauth-callback.js.map +1 -0
  1957. package/dist/agent/connections/own-account-ask.d.ts +120 -0
  1958. package/dist/agent/connections/own-account-ask.d.ts.map +1 -0
  1959. package/dist/agent/connections/own-account-ask.js +204 -0
  1960. package/dist/agent/connections/own-account-ask.js.map +1 -0
  1961. package/dist/agent/connections/own-account-carriage.d.ts +33 -0
  1962. package/dist/agent/connections/own-account-carriage.d.ts.map +1 -0
  1963. package/dist/agent/connections/own-account-carriage.js +102 -0
  1964. package/dist/agent/connections/own-account-carriage.js.map +1 -0
  1965. package/dist/agent/connections/own-account-gate.d.ts +105 -0
  1966. package/dist/agent/connections/own-account-gate.d.ts.map +1 -0
  1967. package/dist/agent/connections/own-account-gate.js +305 -0
  1968. package/dist/agent/connections/own-account-gate.js.map +1 -0
  1969. package/dist/agent/connections/own-account-vendors.d.ts +40 -0
  1970. package/dist/agent/connections/own-account-vendors.d.ts.map +1 -0
  1971. package/dist/agent/connections/own-account-vendors.js +106 -0
  1972. package/dist/agent/connections/own-account-vendors.js.map +1 -0
  1973. package/dist/agent/connections/user-auth-flow.d.ts +78 -0
  1974. package/dist/agent/connections/user-auth-flow.d.ts.map +1 -0
  1975. package/dist/agent/connections/user-auth-flow.js +41 -0
  1976. package/dist/agent/connections/user-auth-flow.js.map +1 -0
  1977. package/dist/agent/contributions.d.ts +671 -0
  1978. package/dist/agent/contributions.d.ts.map +1 -0
  1979. package/dist/agent/contributions.js +192 -0
  1980. package/dist/agent/contributions.js.map +1 -0
  1981. package/dist/agent/control/auth.d.ts +291 -0
  1982. package/dist/agent/control/auth.d.ts.map +1 -0
  1983. package/dist/agent/control/auth.js +533 -0
  1984. package/dist/agent/control/auth.js.map +1 -0
  1985. package/dist/agent/control/capture-window-read.d.ts +115 -0
  1986. package/dist/agent/control/capture-window-read.d.ts.map +1 -0
  1987. package/dist/agent/control/capture-window-read.js +302 -0
  1988. package/dist/agent/control/capture-window-read.js.map +1 -0
  1989. package/dist/agent/control/delivery-history.d.ts +163 -0
  1990. package/dist/agent/control/delivery-history.d.ts.map +1 -0
  1991. package/dist/agent/control/delivery-history.js +397 -0
  1992. package/dist/agent/control/delivery-history.js.map +1 -0
  1993. package/dist/agent/control/http.d.ts +13 -0
  1994. package/dist/agent/control/http.d.ts.map +1 -0
  1995. package/dist/agent/control/http.js +131 -0
  1996. package/dist/agent/control/http.js.map +1 -0
  1997. package/dist/agent/control/mcp-route.d.ts +13 -0
  1998. package/dist/agent/control/mcp-route.d.ts.map +1 -0
  1999. package/dist/agent/control/mcp-route.js +100 -0
  2000. package/dist/agent/control/mcp-route.js.map +1 -0
  2001. package/dist/agent/control/oauth-clients.d.ts +145 -0
  2002. package/dist/agent/control/oauth-clients.d.ts.map +1 -0
  2003. package/dist/agent/control/oauth-clients.js +229 -0
  2004. package/dist/agent/control/oauth-clients.js.map +1 -0
  2005. package/dist/agent/control/oauth-resource.d.ts +59 -0
  2006. package/dist/agent/control/oauth-resource.d.ts.map +1 -0
  2007. package/dist/agent/control/oauth-resource.js +168 -0
  2008. package/dist/agent/control/oauth-resource.js.map +1 -0
  2009. package/dist/agent/control/oauth-route.d.ts +50 -0
  2010. package/dist/agent/control/oauth-route.d.ts.map +1 -0
  2011. package/dist/agent/control/oauth-route.js +343 -0
  2012. package/dist/agent/control/oauth-route.js.map +1 -0
  2013. package/dist/agent/control/oauth-tokens.d.ts +88 -0
  2014. package/dist/agent/control/oauth-tokens.d.ts.map +1 -0
  2015. package/dist/agent/control/oauth-tokens.js +171 -0
  2016. package/dist/agent/control/oauth-tokens.js.map +1 -0
  2017. package/dist/agent/control/read-route.d.ts +278 -0
  2018. package/dist/agent/control/read-route.d.ts.map +1 -0
  2019. package/dist/agent/control/read-route.js +761 -0
  2020. package/dist/agent/control/read-route.js.map +1 -0
  2021. package/dist/agent/control/server.d.ts +49 -0
  2022. package/dist/agent/control/server.d.ts.map +1 -0
  2023. package/dist/agent/control/server.js +405 -0
  2024. package/dist/agent/control/server.js.map +1 -0
  2025. package/dist/agent/control/test-route.d.ts +85 -0
  2026. package/dist/agent/control/test-route.d.ts.map +1 -0
  2027. package/dist/agent/control/test-route.js +426 -0
  2028. package/dist/agent/control/test-route.js.map +1 -0
  2029. package/dist/agent/control/transcript-export.d.ts +68 -0
  2030. package/dist/agent/control/transcript-export.d.ts.map +1 -0
  2031. package/dist/agent/control/transcript-export.js +145 -0
  2032. package/dist/agent/control/transcript-export.js.map +1 -0
  2033. package/dist/agent/control/transcript-relay.d.ts +104 -0
  2034. package/dist/agent/control/transcript-relay.d.ts.map +1 -0
  2035. package/dist/agent/control/transcript-relay.js +314 -0
  2036. package/dist/agent/control/transcript-relay.js.map +1 -0
  2037. package/dist/agent/control/transcript-render.d.ts +43 -0
  2038. package/dist/agent/control/transcript-render.d.ts.map +1 -0
  2039. package/dist/agent/control/transcript-render.js +142 -0
  2040. package/dist/agent/control/transcript-render.js.map +1 -0
  2041. package/dist/agent/control/views.d.ts +511 -0
  2042. package/dist/agent/control/views.d.ts.map +1 -0
  2043. package/dist/agent/control/views.js +743 -0
  2044. package/dist/agent/control/views.js.map +1 -0
  2045. package/dist/agent/control/writes.d.ts +15 -0
  2046. package/dist/agent/control/writes.d.ts.map +1 -0
  2047. package/dist/agent/control/writes.js +1309 -0
  2048. package/dist/agent/control/writes.js.map +1 -0
  2049. package/dist/agent/credentials/binding-pr.d.ts +51 -0
  2050. package/dist/agent/credentials/binding-pr.d.ts.map +1 -0
  2051. package/dist/agent/credentials/binding-pr.js +178 -0
  2052. package/dist/agent/credentials/binding-pr.js.map +1 -0
  2053. package/dist/agent/credentials/config-pr-github.d.ts +24 -0
  2054. package/dist/agent/credentials/config-pr-github.d.ts.map +1 -0
  2055. package/dist/agent/credentials/config-pr-github.js +160 -0
  2056. package/dist/agent/credentials/config-pr-github.js.map +1 -0
  2057. package/dist/agent/credentials/config-pr.d.ts +148 -0
  2058. package/dist/agent/credentials/config-pr.d.ts.map +1 -0
  2059. package/dist/agent/credentials/config-pr.js +45 -0
  2060. package/dist/agent/credentials/config-pr.js.map +1 -0
  2061. package/dist/agent/credentials/db-broker.d.ts +82 -0
  2062. package/dist/agent/credentials/db-broker.d.ts.map +1 -0
  2063. package/dist/agent/credentials/db-broker.js +231 -0
  2064. package/dist/agent/credentials/db-broker.js.map +1 -0
  2065. package/dist/agent/credentials/home.d.ts +51 -0
  2066. package/dist/agent/credentials/home.d.ts.map +1 -0
  2067. package/dist/agent/credentials/home.js +43 -0
  2068. package/dist/agent/credentials/home.js.map +1 -0
  2069. package/dist/agent/credentials/intake-page.d.ts +54 -0
  2070. package/dist/agent/credentials/intake-page.d.ts.map +1 -0
  2071. package/dist/agent/credentials/intake-page.js +238 -0
  2072. package/dist/agent/credentials/intake-page.js.map +1 -0
  2073. package/dist/agent/credentials/intake.d.ts +147 -0
  2074. package/dist/agent/credentials/intake.d.ts.map +1 -0
  2075. package/dist/agent/credentials/intake.js +404 -0
  2076. package/dist/agent/credentials/intake.js.map +1 -0
  2077. package/dist/agent/credentials/kv-vault.d.ts +69 -0
  2078. package/dist/agent/credentials/kv-vault.d.ts.map +1 -0
  2079. package/dist/agent/credentials/kv-vault.js +121 -0
  2080. package/dist/agent/credentials/kv-vault.js.map +1 -0
  2081. package/dist/agent/credentials/operator-secrets.d.ts +169 -0
  2082. package/dist/agent/credentials/operator-secrets.d.ts.map +1 -0
  2083. package/dist/agent/credentials/operator-secrets.js +316 -0
  2084. package/dist/agent/credentials/operator-secrets.js.map +1 -0
  2085. package/dist/agent/credentials/page-chrome.d.ts +11 -0
  2086. package/dist/agent/credentials/page-chrome.d.ts.map +1 -0
  2087. package/dist/agent/credentials/page-chrome.js +52 -0
  2088. package/dist/agent/credentials/page-chrome.js.map +1 -0
  2089. package/dist/agent/credentials/page-token.d.ts +73 -0
  2090. package/dist/agent/credentials/page-token.d.ts.map +1 -0
  2091. package/dist/agent/credentials/page-token.js +197 -0
  2092. package/dist/agent/credentials/page-token.js.map +1 -0
  2093. package/dist/agent/credentials/purge.d.ts +54 -0
  2094. package/dist/agent/credentials/purge.d.ts.map +1 -0
  2095. package/dist/agent/credentials/purge.js +82 -0
  2096. package/dist/agent/credentials/purge.js.map +1 -0
  2097. package/dist/agent/credentials/ref.d.ts +72 -0
  2098. package/dist/agent/credentials/ref.d.ts.map +1 -0
  2099. package/dist/agent/credentials/ref.js +110 -0
  2100. package/dist/agent/credentials/ref.js.map +1 -0
  2101. package/dist/agent/credentials/reserved-refs.d.ts +31 -0
  2102. package/dist/agent/credentials/reserved-refs.d.ts.map +1 -0
  2103. package/dist/agent/credentials/reserved-refs.js +70 -0
  2104. package/dist/agent/credentials/reserved-refs.js.map +1 -0
  2105. package/dist/agent/credentials/self-secrets.d.ts +24 -0
  2106. package/dist/agent/credentials/self-secrets.d.ts.map +1 -0
  2107. package/dist/agent/credentials/self-secrets.js +138 -0
  2108. package/dist/agent/credentials/self-secrets.js.map +1 -0
  2109. package/dist/agent/credentials/warm.d.ts +77 -0
  2110. package/dist/agent/credentials/warm.d.ts.map +1 -0
  2111. package/dist/agent/credentials/warm.js +136 -0
  2112. package/dist/agent/credentials/warm.js.map +1 -0
  2113. package/dist/agent/docs/approver-policy.d.ts +70 -0
  2114. package/dist/agent/docs/approver-policy.d.ts.map +1 -0
  2115. package/dist/agent/docs/approver-policy.js +193 -0
  2116. package/dist/agent/docs/approver-policy.js.map +1 -0
  2117. package/dist/agent/docs/capability-map.d.ts +69 -0
  2118. package/dist/agent/docs/capability-map.d.ts.map +1 -0
  2119. package/dist/agent/docs/capability-map.js +142 -0
  2120. package/dist/agent/docs/capability-map.js.map +1 -0
  2121. package/dist/agent/docs/counted-claims.d.ts +61 -0
  2122. package/dist/agent/docs/counted-claims.d.ts.map +1 -0
  2123. package/dist/agent/docs/counted-claims.js +363 -0
  2124. package/dist/agent/docs/counted-claims.js.map +1 -0
  2125. package/dist/agent/docs/registry.d.ts +73 -0
  2126. package/dist/agent/docs/registry.d.ts.map +1 -0
  2127. package/dist/agent/docs/registry.js +157 -0
  2128. package/dist/agent/docs/registry.js.map +1 -0
  2129. package/dist/agent/docs/source-map.d.ts +69 -0
  2130. package/dist/agent/docs/source-map.d.ts.map +1 -0
  2131. package/dist/agent/docs/source-map.js +156 -0
  2132. package/dist/agent/docs/source-map.js.map +1 -0
  2133. package/dist/agent/hooks/approval-raised.d.ts +3 -0
  2134. package/dist/agent/hooks/approval-raised.d.ts.map +1 -0
  2135. package/dist/agent/hooks/approval-raised.js +31 -0
  2136. package/dist/agent/hooks/approval-raised.js.map +1 -0
  2137. package/dist/agent/hooks/approval-settlement.d.ts +5 -0
  2138. package/dist/agent/hooks/approval-settlement.d.ts.map +1 -0
  2139. package/dist/agent/hooks/approval-settlement.js +90 -0
  2140. package/dist/agent/hooks/approval-settlement.js.map +1 -0
  2141. package/dist/agent/hooks/binding-bridge.d.ts +3 -0
  2142. package/dist/agent/hooks/binding-bridge.d.ts.map +1 -0
  2143. package/dist/agent/hooks/binding-bridge.js +63 -0
  2144. package/dist/agent/hooks/binding-bridge.js.map +1 -0
  2145. package/dist/agent/hooks/connector-audit.d.ts +3 -0
  2146. package/dist/agent/hooks/connector-audit.d.ts.map +1 -0
  2147. package/dist/agent/hooks/connector-audit.js +103 -0
  2148. package/dist/agent/hooks/connector-audit.js.map +1 -0
  2149. package/dist/agent/hooks/egress.d.ts +150 -0
  2150. package/dist/agent/hooks/egress.d.ts.map +1 -0
  2151. package/dist/agent/hooks/egress.js +546 -0
  2152. package/dist/agent/hooks/egress.js.map +1 -0
  2153. package/dist/agent/hooks/eve-patch-gate.d.ts +3 -0
  2154. package/dist/agent/hooks/eve-patch-gate.d.ts.map +1 -0
  2155. package/dist/agent/hooks/eve-patch-gate.js +51 -0
  2156. package/dist/agent/hooks/eve-patch-gate.js.map +1 -0
  2157. package/dist/agent/hooks/fire-carriage.d.ts +3 -0
  2158. package/dist/agent/hooks/fire-carriage.d.ts.map +1 -0
  2159. package/dist/agent/hooks/fire-carriage.js +32 -0
  2160. package/dist/agent/hooks/fire-carriage.js.map +1 -0
  2161. package/dist/agent/hooks/fire-toolset.d.ts +48 -0
  2162. package/dist/agent/hooks/fire-toolset.d.ts.map +1 -0
  2163. package/dist/agent/hooks/fire-toolset.js +275 -0
  2164. package/dist/agent/hooks/fire-toolset.js.map +1 -0
  2165. package/dist/agent/hooks/job-posture.d.ts +3 -0
  2166. package/dist/agent/hooks/job-posture.d.ts.map +1 -0
  2167. package/dist/agent/hooks/job-posture.js +82 -0
  2168. package/dist/agent/hooks/job-posture.js.map +1 -0
  2169. package/dist/agent/hooks/lean-seat.d.ts +3 -0
  2170. package/dist/agent/hooks/lean-seat.d.ts.map +1 -0
  2171. package/dist/agent/hooks/lean-seat.js +229 -0
  2172. package/dist/agent/hooks/lean-seat.js.map +1 -0
  2173. package/dist/agent/hooks/learn.d.ts +3 -0
  2174. package/dist/agent/hooks/learn.d.ts.map +1 -0
  2175. package/dist/agent/hooks/learn.js +193 -0
  2176. package/dist/agent/hooks/learn.js.map +1 -0
  2177. package/dist/agent/hooks/link-claim.d.ts +63 -0
  2178. package/dist/agent/hooks/link-claim.d.ts.map +1 -0
  2179. package/dist/agent/hooks/link-claim.js +215 -0
  2180. package/dist/agent/hooks/link-claim.js.map +1 -0
  2181. package/dist/agent/hooks/log-flush.d.ts +3 -0
  2182. package/dist/agent/hooks/log-flush.d.ts.map +1 -0
  2183. package/dist/agent/hooks/log-flush.js +28 -0
  2184. package/dist/agent/hooks/log-flush.js.map +1 -0
  2185. package/dist/agent/hooks/loop-breaker.d.ts +3 -0
  2186. package/dist/agent/hooks/loop-breaker.d.ts.map +1 -0
  2187. package/dist/agent/hooks/loop-breaker.js +16 -0
  2188. package/dist/agent/hooks/loop-breaker.js.map +1 -0
  2189. package/dist/agent/hooks/memory.d.ts +112 -0
  2190. package/dist/agent/hooks/memory.d.ts.map +1 -0
  2191. package/dist/agent/hooks/memory.js +1191 -0
  2192. package/dist/agent/hooks/memory.js.map +1 -0
  2193. package/dist/agent/hooks/native-input-audit.d.ts +7 -0
  2194. package/dist/agent/hooks/native-input-audit.d.ts.map +1 -0
  2195. package/dist/agent/hooks/native-input-audit.js +44 -0
  2196. package/dist/agent/hooks/native-input-audit.js.map +1 -0
  2197. package/dist/agent/hooks/own-account-ask.d.ts +52 -0
  2198. package/dist/agent/hooks/own-account-ask.d.ts.map +1 -0
  2199. package/dist/agent/hooks/own-account-ask.js +162 -0
  2200. package/dist/agent/hooks/own-account-ask.js.map +1 -0
  2201. package/dist/agent/hooks/requester-identity.d.ts +3 -0
  2202. package/dist/agent/hooks/requester-identity.d.ts.map +1 -0
  2203. package/dist/agent/hooks/requester-identity.js +24 -0
  2204. package/dist/agent/hooks/requester-identity.js.map +1 -0
  2205. package/dist/agent/hooks/requester-messages.d.ts +9 -0
  2206. package/dist/agent/hooks/requester-messages.d.ts.map +1 -0
  2207. package/dist/agent/hooks/requester-messages.js +57 -0
  2208. package/dist/agent/hooks/requester-messages.js.map +1 -0
  2209. package/dist/agent/hooks/routine-outcome.d.ts +29 -0
  2210. package/dist/agent/hooks/routine-outcome.d.ts.map +1 -0
  2211. package/dist/agent/hooks/routine-outcome.js +211 -0
  2212. package/dist/agent/hooks/routine-outcome.js.map +1 -0
  2213. package/dist/agent/hooks/routine-silence.d.ts +3 -0
  2214. package/dist/agent/hooks/routine-silence.d.ts.map +1 -0
  2215. package/dist/agent/hooks/routine-silence.js +30 -0
  2216. package/dist/agent/hooks/routine-silence.js.map +1 -0
  2217. package/dist/agent/hooks/session-park.d.ts +3 -0
  2218. package/dist/agent/hooks/session-park.d.ts.map +1 -0
  2219. package/dist/agent/hooks/session-park.js +43 -0
  2220. package/dist/agent/hooks/session-park.js.map +1 -0
  2221. package/dist/agent/hooks/settlement-flush.d.ts +45 -0
  2222. package/dist/agent/hooks/settlement-flush.d.ts.map +1 -0
  2223. package/dist/agent/hooks/settlement-flush.js +146 -0
  2224. package/dist/agent/hooks/settlement-flush.js.map +1 -0
  2225. package/dist/agent/hooks/spawn-taint.d.ts +154 -0
  2226. package/dist/agent/hooks/spawn-taint.d.ts.map +1 -0
  2227. package/dist/agent/hooks/spawn-taint.js +1200 -0
  2228. package/dist/agent/hooks/spawn-taint.js.map +1 -0
  2229. package/dist/agent/hooks/spend.d.ts +92 -0
  2230. package/dist/agent/hooks/spend.d.ts.map +1 -0
  2231. package/dist/agent/hooks/spend.js +343 -0
  2232. package/dist/agent/hooks/spend.js.map +1 -0
  2233. package/dist/agent/hooks/stall-guard.d.ts +3 -0
  2234. package/dist/agent/hooks/stall-guard.d.ts.map +1 -0
  2235. package/dist/agent/hooks/stall-guard.js +22 -0
  2236. package/dist/agent/hooks/stall-guard.js.map +1 -0
  2237. package/dist/agent/hooks/telemetry.d.ts +3 -0
  2238. package/dist/agent/hooks/telemetry.d.ts.map +1 -0
  2239. package/dist/agent/hooks/telemetry.js +93 -0
  2240. package/dist/agent/hooks/telemetry.js.map +1 -0
  2241. package/dist/agent/hooks/turn-anchor.d.ts +35 -0
  2242. package/dist/agent/hooks/turn-anchor.d.ts.map +1 -0
  2243. package/dist/agent/hooks/turn-anchor.js +647 -0
  2244. package/dist/agent/hooks/turn-anchor.js.map +1 -0
  2245. package/dist/agent/hooks/turn-tally.d.ts +32 -0
  2246. package/dist/agent/hooks/turn-tally.d.ts.map +1 -0
  2247. package/dist/agent/hooks/turn-tally.js +69 -0
  2248. package/dist/agent/hooks/turn-tally.js.map +1 -0
  2249. package/dist/agent/hooks/wake-accounting-turn.d.ts +8 -0
  2250. package/dist/agent/hooks/wake-accounting-turn.d.ts.map +1 -0
  2251. package/dist/agent/hooks/wake-accounting-turn.js +88 -0
  2252. package/dist/agent/hooks/wake-accounting-turn.js.map +1 -0
  2253. package/dist/agent/hooks/wake-turn-start.d.ts +3 -0
  2254. package/dist/agent/hooks/wake-turn-start.d.ts.map +1 -0
  2255. package/dist/agent/hooks/wake-turn-start.js +44 -0
  2256. package/dist/agent/hooks/wake-turn-start.js.map +1 -0
  2257. package/dist/agent/hooks/window-routing.d.ts +3 -0
  2258. package/dist/agent/hooks/window-routing.d.ts.map +1 -0
  2259. package/dist/agent/hooks/window-routing.js +52 -0
  2260. package/dist/agent/hooks/window-routing.js.map +1 -0
  2261. package/dist/agent/identity/account-directory.d.ts +52 -0
  2262. package/dist/agent/identity/account-directory.d.ts.map +1 -0
  2263. package/dist/agent/identity/account-directory.js +110 -0
  2264. package/dist/agent/identity/account-directory.js.map +1 -0
  2265. package/dist/agent/identity/account-display-name.d.ts +65 -0
  2266. package/dist/agent/identity/account-display-name.d.ts.map +1 -0
  2267. package/dist/agent/identity/account-display-name.js +156 -0
  2268. package/dist/agent/identity/account-display-name.js.map +1 -0
  2269. package/dist/agent/identity/author-trust.d.ts +106 -0
  2270. package/dist/agent/identity/author-trust.d.ts.map +1 -0
  2271. package/dist/agent/identity/author-trust.js +209 -0
  2272. package/dist/agent/identity/author-trust.js.map +1 -0
  2273. package/dist/agent/identity/binding-bridge.d.ts +26 -0
  2274. package/dist/agent/identity/binding-bridge.d.ts.map +1 -0
  2275. package/dist/agent/identity/binding-bridge.js +75 -0
  2276. package/dist/agent/identity/binding-bridge.js.map +1 -0
  2277. package/dist/agent/identity/binding.d.ts +567 -0
  2278. package/dist/agent/identity/binding.d.ts.map +1 -0
  2279. package/dist/agent/identity/binding.js +1050 -0
  2280. package/dist/agent/identity/binding.js.map +1 -0
  2281. package/dist/agent/identity/bot-display-name.d.ts +19 -0
  2282. package/dist/agent/identity/bot-display-name.d.ts.map +1 -0
  2283. package/dist/agent/identity/bot-display-name.js +47 -0
  2284. package/dist/agent/identity/bot-display-name.js.map +1 -0
  2285. package/dist/agent/identity/bot-name.d.ts +39 -0
  2286. package/dist/agent/identity/bot-name.d.ts.map +1 -0
  2287. package/dist/agent/identity/bot-name.js +77 -0
  2288. package/dist/agent/identity/bot-name.js.map +1 -0
  2289. package/dist/agent/identity/capabilities.d.ts +52 -0
  2290. package/dist/agent/identity/capabilities.d.ts.map +1 -0
  2291. package/dist/agent/identity/capabilities.js +39 -0
  2292. package/dist/agent/identity/capabilities.js.map +1 -0
  2293. package/dist/agent/identity/delegated-binding.d.ts +59 -0
  2294. package/dist/agent/identity/delegated-binding.d.ts.map +1 -0
  2295. package/dist/agent/identity/delegated-binding.js +116 -0
  2296. package/dist/agent/identity/delegated-binding.js.map +1 -0
  2297. package/dist/agent/identity/deployment-identity.d.ts +61 -0
  2298. package/dist/agent/identity/deployment-identity.d.ts.map +1 -0
  2299. package/dist/agent/identity/deployment-identity.js +75 -0
  2300. package/dist/agent/identity/deployment-identity.js.map +1 -0
  2301. package/dist/agent/identity/directory-sync.d.ts +195 -0
  2302. package/dist/agent/identity/directory-sync.d.ts.map +1 -0
  2303. package/dist/agent/identity/directory-sync.js +623 -0
  2304. package/dist/agent/identity/directory-sync.js.map +1 -0
  2305. package/dist/agent/identity/directory.d.ts +73 -0
  2306. package/dist/agent/identity/directory.d.ts.map +1 -0
  2307. package/dist/agent/identity/directory.js +19 -0
  2308. package/dist/agent/identity/directory.js.map +1 -0
  2309. package/dist/agent/identity/display-title.d.ts +12 -0
  2310. package/dist/agent/identity/display-title.d.ts.map +1 -0
  2311. package/dist/agent/identity/display-title.js +14 -0
  2312. package/dist/agent/identity/display-title.js.map +1 -0
  2313. package/dist/agent/identity/frozen-surface-binding.internal.d.ts +8 -0
  2314. package/dist/agent/identity/frozen-surface-binding.internal.d.ts.map +1 -0
  2315. package/dist/agent/identity/frozen-surface-binding.internal.js +90 -0
  2316. package/dist/agent/identity/frozen-surface-binding.internal.js.map +1 -0
  2317. package/dist/agent/identity/group-sync.d.ts +77 -0
  2318. package/dist/agent/identity/group-sync.d.ts.map +1 -0
  2319. package/dist/agent/identity/group-sync.js +128 -0
  2320. package/dist/agent/identity/group-sync.js.map +1 -0
  2321. package/dist/agent/identity/groups-codemod.d.ts +52 -0
  2322. package/dist/agent/identity/groups-codemod.d.ts.map +1 -0
  2323. package/dist/agent/identity/groups-codemod.js +129 -0
  2324. package/dist/agent/identity/groups-codemod.js.map +1 -0
  2325. package/dist/agent/identity/groups-delivery.d.ts +56 -0
  2326. package/dist/agent/identity/groups-delivery.d.ts.map +1 -0
  2327. package/dist/agent/identity/groups-delivery.js +116 -0
  2328. package/dist/agent/identity/groups-delivery.js.map +1 -0
  2329. package/dist/agent/identity/groups.d.ts +74 -0
  2330. package/dist/agent/identity/groups.d.ts.map +1 -0
  2331. package/dist/agent/identity/groups.js +124 -0
  2332. package/dist/agent/identity/groups.js.map +1 -0
  2333. package/dist/agent/identity/link-challenge.d.ts +58 -0
  2334. package/dist/agent/identity/link-challenge.d.ts.map +1 -0
  2335. package/dist/agent/identity/link-challenge.js +136 -0
  2336. package/dist/agent/identity/link-challenge.js.map +1 -0
  2337. package/dist/agent/identity/link-consent.d.ts +79 -0
  2338. package/dist/agent/identity/link-consent.d.ts.map +1 -0
  2339. package/dist/agent/identity/link-consent.js +179 -0
  2340. package/dist/agent/identity/link-consent.js.map +1 -0
  2341. package/dist/agent/identity/link-flow.d.ts +260 -0
  2342. package/dist/agent/identity/link-flow.d.ts.map +1 -0
  2343. package/dist/agent/identity/link-flow.js +327 -0
  2344. package/dist/agent/identity/link-flow.js.map +1 -0
  2345. package/dist/agent/identity/link-initiator.d.ts +16 -0
  2346. package/dist/agent/identity/link-initiator.d.ts.map +1 -0
  2347. package/dist/agent/identity/link-initiator.js +25 -0
  2348. package/dist/agent/identity/link-initiator.js.map +1 -0
  2349. package/dist/agent/identity/link-resolve.d.ts +40 -0
  2350. package/dist/agent/identity/link-resolve.d.ts.map +1 -0
  2351. package/dist/agent/identity/link-resolve.js +195 -0
  2352. package/dist/agent/identity/link-resolve.js.map +1 -0
  2353. package/dist/agent/identity/link-set-ref.d.ts +16 -0
  2354. package/dist/agent/identity/link-set-ref.d.ts.map +1 -0
  2355. package/dist/agent/identity/link-set-ref.js +32 -0
  2356. package/dist/agent/identity/link-set-ref.js.map +1 -0
  2357. package/dist/agent/identity/link-store.d.ts +400 -0
  2358. package/dist/agent/identity/link-store.d.ts.map +1 -0
  2359. package/dist/agent/identity/link-store.js +725 -0
  2360. package/dist/agent/identity/link-store.js.map +1 -0
  2361. package/dist/agent/identity/link-tenant-backfill.d.ts +39 -0
  2362. package/dist/agent/identity/link-tenant-backfill.d.ts.map +1 -0
  2363. package/dist/agent/identity/link-tenant-backfill.js +67 -0
  2364. package/dist/agent/identity/link-tenant-backfill.js.map +1 -0
  2365. package/dist/agent/identity/link-tenant.d.ts +28 -0
  2366. package/dist/agent/identity/link-tenant.d.ts.map +1 -0
  2367. package/dist/agent/identity/link-tenant.js +51 -0
  2368. package/dist/agent/identity/link-tenant.js.map +1 -0
  2369. package/dist/agent/identity/oauth-vault-share.d.ts +29 -0
  2370. package/dist/agent/identity/oauth-vault-share.d.ts.map +1 -0
  2371. package/dist/agent/identity/oauth-vault-share.js +36 -0
  2372. package/dist/agent/identity/oauth-vault-share.js.map +1 -0
  2373. package/dist/agent/identity/platform.d.ts +9 -0
  2374. package/dist/agent/identity/platform.d.ts.map +1 -0
  2375. package/dist/agent/identity/platform.js +48 -0
  2376. package/dist/agent/identity/platform.js.map +1 -0
  2377. package/dist/agent/identity/principal-key-rules.d.ts +23 -0
  2378. package/dist/agent/identity/principal-key-rules.d.ts.map +1 -0
  2379. package/dist/agent/identity/principal-key-rules.js +91 -0
  2380. package/dist/agent/identity/principal-key-rules.js.map +1 -0
  2381. package/dist/agent/identity/principal-key.d.ts +92 -0
  2382. package/dist/agent/identity/principal-key.d.ts.map +1 -0
  2383. package/dist/agent/identity/principal-key.js +197 -0
  2384. package/dist/agent/identity/principal-key.js.map +1 -0
  2385. package/dist/agent/identity/principals.d.ts +145 -0
  2386. package/dist/agent/identity/principals.d.ts.map +1 -0
  2387. package/dist/agent/identity/principals.js +303 -0
  2388. package/dist/agent/identity/principals.js.map +1 -0
  2389. package/dist/agent/identity/surface-key-grammar.d.ts +83 -0
  2390. package/dist/agent/identity/surface-key-grammar.d.ts.map +1 -0
  2391. package/dist/agent/identity/surface-key-grammar.js +138 -0
  2392. package/dist/agent/identity/surface-key-grammar.js.map +1 -0
  2393. package/dist/agent/identity/surface-parity.d.ts +274 -0
  2394. package/dist/agent/identity/surface-parity.d.ts.map +1 -0
  2395. package/dist/agent/identity/surface-parity.js +357 -0
  2396. package/dist/agent/identity/surface-parity.js.map +1 -0
  2397. package/dist/agent/identity/trust-preflight.d.ts +83 -0
  2398. package/dist/agent/identity/trust-preflight.d.ts.map +1 -0
  2399. package/dist/agent/identity/trust-preflight.js +196 -0
  2400. package/dist/agent/identity/trust-preflight.js.map +1 -0
  2401. package/dist/agent/identity/trust.d.ts +217 -0
  2402. package/dist/agent/identity/trust.d.ts.map +1 -0
  2403. package/dist/agent/identity/trust.js +300 -0
  2404. package/dist/agent/identity/trust.js.map +1 -0
  2405. package/dist/agent/identity/wake-trust.d.ts +129 -0
  2406. package/dist/agent/identity/wake-trust.d.ts.map +1 -0
  2407. package/dist/agent/identity/wake-trust.js +159 -0
  2408. package/dist/agent/identity/wake-trust.js.map +1 -0
  2409. package/dist/agent/instructions/access.d.ts +252 -0
  2410. package/dist/agent/instructions/access.d.ts.map +1 -0
  2411. package/dist/agent/instructions/access.js +1200 -0
  2412. package/dist/agent/instructions/access.js.map +1 -0
  2413. package/dist/agent/instructions/seat-prompt.d.ts +354 -0
  2414. package/dist/agent/instructions/seat-prompt.d.ts.map +1 -0
  2415. package/dist/agent/instructions/seat-prompt.js +1143 -0
  2416. package/dist/agent/instructions/seat-prompt.js.map +1 -0
  2417. package/dist/agent/lib/process-registry.d.ts +8 -0
  2418. package/dist/agent/lib/process-registry.d.ts.map +1 -0
  2419. package/dist/agent/lib/process-registry.js +53 -0
  2420. package/dist/agent/lib/process-registry.js.map +1 -0
  2421. package/dist/agent/memory/agents-codemod.d.ts +92 -0
  2422. package/dist/agent/memory/agents-codemod.d.ts.map +1 -0
  2423. package/dist/agent/memory/agents-codemod.js +366 -0
  2424. package/dist/agent/memory/agents-codemod.js.map +1 -0
  2425. package/dist/agent/memory/connector-memory.d.ts +54 -0
  2426. package/dist/agent/memory/connector-memory.d.ts.map +1 -0
  2427. package/dist/agent/memory/connector-memory.js +80 -0
  2428. package/dist/agent/memory/connector-memory.js.map +1 -0
  2429. package/dist/agent/memory/domain.d.ts +384 -0
  2430. package/dist/agent/memory/domain.d.ts.map +1 -0
  2431. package/dist/agent/memory/domain.js +911 -0
  2432. package/dist/agent/memory/domain.js.map +1 -0
  2433. package/dist/agent/memory/dream/candidates.d.ts +35 -0
  2434. package/dist/agent/memory/dream/candidates.d.ts.map +1 -0
  2435. package/dist/agent/memory/dream/candidates.js +149 -0
  2436. package/dist/agent/memory/dream/candidates.js.map +1 -0
  2437. package/dist/agent/memory/dream/correction.d.ts +56 -0
  2438. package/dist/agent/memory/dream/correction.d.ts.map +1 -0
  2439. package/dist/agent/memory/dream/correction.js +109 -0
  2440. package/dist/agent/memory/dream/correction.js.map +1 -0
  2441. package/dist/agent/memory/dream/judge.d.ts +47 -0
  2442. package/dist/agent/memory/dream/judge.d.ts.map +1 -0
  2443. package/dist/agent/memory/dream/judge.js +135 -0
  2444. package/dist/agent/memory/dream/judge.js.map +1 -0
  2445. package/dist/agent/memory/dream/learn.d.ts +79 -0
  2446. package/dist/agent/memory/dream/learn.d.ts.map +1 -0
  2447. package/dist/agent/memory/dream/learn.js +243 -0
  2448. package/dist/agent/memory/dream/learn.js.map +1 -0
  2449. package/dist/agent/memory/dream/mode3-cluster.d.ts +37 -0
  2450. package/dist/agent/memory/dream/mode3-cluster.d.ts.map +1 -0
  2451. package/dist/agent/memory/dream/mode3-cluster.js +123 -0
  2452. package/dist/agent/memory/dream/mode3-cluster.js.map +1 -0
  2453. package/dist/agent/memory/dream/mode3-last-mile.d.ts +134 -0
  2454. package/dist/agent/memory/dream/mode3-last-mile.d.ts.map +1 -0
  2455. package/dist/agent/memory/dream/mode3-last-mile.js +262 -0
  2456. package/dist/agent/memory/dream/mode3-last-mile.js.map +1 -0
  2457. package/dist/agent/memory/dream/mode3.d.ts +82 -0
  2458. package/dist/agent/memory/dream/mode3.d.ts.map +1 -0
  2459. package/dist/agent/memory/dream/mode3.js +236 -0
  2460. package/dist/agent/memory/dream/mode3.js.map +1 -0
  2461. package/dist/agent/memory/dream/ops.d.ts +75 -0
  2462. package/dist/agent/memory/dream/ops.d.ts.map +1 -0
  2463. package/dist/agent/memory/dream/ops.js +302 -0
  2464. package/dist/agent/memory/dream/ops.js.map +1 -0
  2465. package/dist/agent/memory/dream/proposal.d.ts +22 -0
  2466. package/dist/agent/memory/dream/proposal.d.ts.map +1 -0
  2467. package/dist/agent/memory/dream/proposal.js +66 -0
  2468. package/dist/agent/memory/dream/proposal.js.map +1 -0
  2469. package/dist/agent/memory/dream/recurrence.d.ts +38 -0
  2470. package/dist/agent/memory/dream/recurrence.d.ts.map +1 -0
  2471. package/dist/agent/memory/dream/recurrence.js +106 -0
  2472. package/dist/agent/memory/dream/recurrence.js.map +1 -0
  2473. package/dist/agent/memory/dream/salience.d.ts +10 -0
  2474. package/dist/agent/memory/dream/salience.d.ts.map +1 -0
  2475. package/dist/agent/memory/dream/salience.js +16 -0
  2476. package/dist/agent/memory/dream/salience.js.map +1 -0
  2477. package/dist/agent/memory/dream/skill-proposal-pr.d.ts +63 -0
  2478. package/dist/agent/memory/dream/skill-proposal-pr.d.ts.map +1 -0
  2479. package/dist/agent/memory/dream/skill-proposal-pr.js +245 -0
  2480. package/dist/agent/memory/dream/skill-proposal-pr.js.map +1 -0
  2481. package/dist/agent/memory/dream/supersede-apply.d.ts +40 -0
  2482. package/dist/agent/memory/dream/supersede-apply.d.ts.map +1 -0
  2483. package/dist/agent/memory/dream/supersede-apply.js +78 -0
  2484. package/dist/agent/memory/dream/supersede-apply.js.map +1 -0
  2485. package/dist/agent/memory/dream/tidy.d.ts +60 -0
  2486. package/dist/agent/memory/dream/tidy.d.ts.map +1 -0
  2487. package/dist/agent/memory/dream/tidy.js +96 -0
  2488. package/dist/agent/memory/dream/tidy.js.map +1 -0
  2489. package/dist/agent/memory/graph.d.ts +46 -0
  2490. package/dist/agent/memory/graph.d.ts.map +1 -0
  2491. package/dist/agent/memory/graph.js +130 -0
  2492. package/dist/agent/memory/graph.js.map +1 -0
  2493. package/dist/agent/memory/host-owned-files.d.ts +2 -0
  2494. package/dist/agent/memory/host-owned-files.d.ts.map +1 -0
  2495. package/dist/agent/memory/host-owned-files.js +4 -0
  2496. package/dist/agent/memory/host-owned-files.js.map +1 -0
  2497. package/dist/agent/memory/layout.d.ts +8 -0
  2498. package/dist/agent/memory/layout.d.ts.map +1 -0
  2499. package/dist/agent/memory/layout.js +77 -0
  2500. package/dist/agent/memory/layout.js.map +1 -0
  2501. package/dist/agent/memory/listing.d.ts +11 -0
  2502. package/dist/agent/memory/listing.d.ts.map +1 -0
  2503. package/dist/agent/memory/listing.js +169 -0
  2504. package/dist/agent/memory/listing.js.map +1 -0
  2505. package/dist/agent/memory/markdown.d.ts +73 -0
  2506. package/dist/agent/memory/markdown.d.ts.map +1 -0
  2507. package/dist/agent/memory/markdown.js +190 -0
  2508. package/dist/agent/memory/markdown.js.map +1 -0
  2509. package/dist/agent/memory/partition.d.ts +34 -0
  2510. package/dist/agent/memory/partition.d.ts.map +1 -0
  2511. package/dist/agent/memory/partition.js +41 -0
  2512. package/dist/agent/memory/partition.js.map +1 -0
  2513. package/dist/agent/memory/postgres.d.ts +73 -0
  2514. package/dist/agent/memory/postgres.d.ts.map +1 -0
  2515. package/dist/agent/memory/postgres.js +411 -0
  2516. package/dist/agent/memory/postgres.js.map +1 -0
  2517. package/dist/agent/memory/provenance-mark.d.ts +77 -0
  2518. package/dist/agent/memory/provenance-mark.d.ts.map +1 -0
  2519. package/dist/agent/memory/provenance-mark.js +276 -0
  2520. package/dist/agent/memory/provenance-mark.js.map +1 -0
  2521. package/dist/agent/memory/provenance.d.ts +8 -0
  2522. package/dist/agent/memory/provenance.d.ts.map +1 -0
  2523. package/dist/agent/memory/provenance.js +25 -0
  2524. package/dist/agent/memory/provenance.js.map +1 -0
  2525. package/dist/agent/memory/provider.d.ts +76 -0
  2526. package/dist/agent/memory/provider.d.ts.map +1 -0
  2527. package/dist/agent/memory/provider.js +96 -0
  2528. package/dist/agent/memory/provider.js.map +1 -0
  2529. package/dist/agent/memory/purge-redaction.d.ts +29 -0
  2530. package/dist/agent/memory/purge-redaction.d.ts.map +1 -0
  2531. package/dist/agent/memory/purge-redaction.js +65 -0
  2532. package/dist/agent/memory/purge-redaction.js.map +1 -0
  2533. package/dist/agent/memory/readonly.d.ts +25 -0
  2534. package/dist/agent/memory/readonly.d.ts.map +1 -0
  2535. package/dist/agent/memory/readonly.js +46 -0
  2536. package/dist/agent/memory/readonly.js.map +1 -0
  2537. package/dist/agent/memory/resolve.d.ts +49 -0
  2538. package/dist/agent/memory/resolve.d.ts.map +1 -0
  2539. package/dist/agent/memory/resolve.js +136 -0
  2540. package/dist/agent/memory/resolve.js.map +1 -0
  2541. package/dist/agent/memory/root-fence.d.ts +24 -0
  2542. package/dist/agent/memory/root-fence.d.ts.map +1 -0
  2543. package/dist/agent/memory/root-fence.js +46 -0
  2544. package/dist/agent/memory/root-fence.js.map +1 -0
  2545. package/dist/agent/memory/sandbox-sync.d.ts +17 -0
  2546. package/dist/agent/memory/sandbox-sync.d.ts.map +1 -0
  2547. package/dist/agent/memory/sandbox-sync.js +61 -0
  2548. package/dist/agent/memory/sandbox-sync.js.map +1 -0
  2549. package/dist/agent/memory/selection.d.ts +29 -0
  2550. package/dist/agent/memory/selection.d.ts.map +1 -0
  2551. package/dist/agent/memory/selection.js +82 -0
  2552. package/dist/agent/memory/selection.js.map +1 -0
  2553. package/dist/agent/memory/silo.d.ts +39 -0
  2554. package/dist/agent/memory/silo.d.ts.map +1 -0
  2555. package/dist/agent/memory/silo.js +36 -0
  2556. package/dist/agent/memory/silo.js.map +1 -0
  2557. package/dist/agent/memory/sqlite.d.ts +4 -0
  2558. package/dist/agent/memory/sqlite.d.ts.map +1 -0
  2559. package/dist/agent/memory/sqlite.js +196 -0
  2560. package/dist/agent/memory/sqlite.js.map +1 -0
  2561. package/dist/agent/memory/store.d.ts +36 -0
  2562. package/dist/agent/memory/store.d.ts.map +1 -0
  2563. package/dist/agent/memory/store.js +144 -0
  2564. package/dist/agent/memory/store.js.map +1 -0
  2565. package/dist/agent/memory/sync-timing.d.ts +83 -0
  2566. package/dist/agent/memory/sync-timing.d.ts.map +1 -0
  2567. package/dist/agent/memory/sync-timing.js +166 -0
  2568. package/dist/agent/memory/sync-timing.js.map +1 -0
  2569. package/dist/agent/memory/wake-delta.d.ts +96 -0
  2570. package/dist/agent/memory/wake-delta.d.ts.map +1 -0
  2571. package/dist/agent/memory/wake-delta.js +176 -0
  2572. package/dist/agent/memory/wake-delta.js.map +1 -0
  2573. package/dist/agent/memory/write-evidence.d.ts +30 -0
  2574. package/dist/agent/memory/write-evidence.d.ts.map +1 -0
  2575. package/dist/agent/memory/write-evidence.js +137 -0
  2576. package/dist/agent/memory/write-evidence.js.map +1 -0
  2577. package/dist/agent/memory/write-fence.d.ts +30 -0
  2578. package/dist/agent/memory/write-fence.d.ts.map +1 -0
  2579. package/dist/agent/memory/write-fence.js +123 -0
  2580. package/dist/agent/memory/write-fence.js.map +1 -0
  2581. package/dist/agent/memory/write-intent.d.ts +72 -0
  2582. package/dist/agent/memory/write-intent.d.ts.map +1 -0
  2583. package/dist/agent/memory/write-intent.js +197 -0
  2584. package/dist/agent/memory/write-intent.js.map +1 -0
  2585. package/dist/agent/memory/write-road.d.ts +60 -0
  2586. package/dist/agent/memory/write-road.d.ts.map +1 -0
  2587. package/dist/agent/memory/write-road.js +96 -0
  2588. package/dist/agent/memory/write-road.js.map +1 -0
  2589. package/dist/agent/model/ab-test.d.ts +132 -0
  2590. package/dist/agent/model/ab-test.d.ts.map +1 -0
  2591. package/dist/agent/model/ab-test.js +321 -0
  2592. package/dist/agent/model/ab-test.js.map +1 -0
  2593. package/dist/agent/model/call-capture.d.ts +140 -0
  2594. package/dist/agent/model/call-capture.d.ts.map +1 -0
  2595. package/dist/agent/model/call-capture.js +374 -0
  2596. package/dist/agent/model/call-capture.js.map +1 -0
  2597. package/dist/agent/model/default-model.d.ts +13 -0
  2598. package/dist/agent/model/default-model.d.ts.map +1 -0
  2599. package/dist/agent/model/default-model.js +58 -0
  2600. package/dist/agent/model/default-model.js.map +1 -0
  2601. package/dist/agent/model/model-stamp.d.ts +41 -0
  2602. package/dist/agent/model/model-stamp.d.ts.map +1 -0
  2603. package/dist/agent/model/model-stamp.js +160 -0
  2604. package/dist/agent/model/model-stamp.js.map +1 -0
  2605. package/dist/agent/model/policy.d.ts +150 -0
  2606. package/dist/agent/model/policy.d.ts.map +1 -0
  2607. package/dist/agent/model/policy.js +309 -0
  2608. package/dist/agent/model/policy.js.map +1 -0
  2609. package/dist/agent/model/routing.d.ts +210 -0
  2610. package/dist/agent/model/routing.d.ts.map +1 -0
  2611. package/dist/agent/model/routing.js +694 -0
  2612. package/dist/agent/model/routing.js.map +1 -0
  2613. package/dist/agent/model/step-boundary.d.ts +163 -0
  2614. package/dist/agent/model/step-boundary.d.ts.map +1 -0
  2615. package/dist/agent/model/step-boundary.js +491 -0
  2616. package/dist/agent/model/step-boundary.js.map +1 -0
  2617. package/dist/agent/model/stream-drop-retry.d.ts +24 -0
  2618. package/dist/agent/model/stream-drop-retry.d.ts.map +1 -0
  2619. package/dist/agent/model/stream-drop-retry.js +316 -0
  2620. package/dist/agent/model/stream-drop-retry.js.map +1 -0
  2621. package/dist/agent/model/turn-closeout.d.ts +61 -0
  2622. package/dist/agent/model/turn-closeout.d.ts.map +1 -0
  2623. package/dist/agent/model/turn-closeout.js +289 -0
  2624. package/dist/agent/model/turn-closeout.js.map +1 -0
  2625. package/dist/agent/model/turn-state.d.ts +119 -0
  2626. package/dist/agent/model/turn-state.d.ts.map +1 -0
  2627. package/dist/agent/model/turn-state.js +423 -0
  2628. package/dist/agent/model/turn-state.js.map +1 -0
  2629. package/dist/agent/model/vision.d.ts +75 -0
  2630. package/dist/agent/model/vision.d.ts.map +1 -0
  2631. package/dist/agent/model/vision.js +39 -0
  2632. package/dist/agent/model/vision.js.map +1 -0
  2633. package/dist/agent/observability/ship.d.ts +87 -0
  2634. package/dist/agent/observability/ship.d.ts.map +1 -0
  2635. package/dist/agent/observability/ship.js +354 -0
  2636. package/dist/agent/observability/ship.js.map +1 -0
  2637. package/dist/agent/observability/telemetry.d.ts +154 -0
  2638. package/dist/agent/observability/telemetry.d.ts.map +1 -0
  2639. package/dist/agent/observability/telemetry.js +764 -0
  2640. package/dist/agent/observability/telemetry.js.map +1 -0
  2641. package/dist/agent/observability/turn-clock.d.ts +41 -0
  2642. package/dist/agent/observability/turn-clock.d.ts.map +1 -0
  2643. package/dist/agent/observability/turn-clock.js +75 -0
  2644. package/dist/agent/observability/turn-clock.js.map +1 -0
  2645. package/dist/agent/onboarding/onboarding.d.ts +30 -0
  2646. package/dist/agent/onboarding/onboarding.d.ts.map +1 -0
  2647. package/dist/agent/onboarding/onboarding.js +94 -0
  2648. package/dist/agent/onboarding/onboarding.js.map +1 -0
  2649. package/dist/agent/operational/credential-grant-rows.d.ts +626 -0
  2650. package/dist/agent/operational/credential-grant-rows.d.ts.map +1 -0
  2651. package/dist/agent/operational/credential-grant-rows.js +634 -0
  2652. package/dist/agent/operational/credential-grant-rows.js.map +1 -0
  2653. package/dist/agent/operational/pglite-client.d.ts +81 -0
  2654. package/dist/agent/operational/pglite-client.d.ts.map +1 -0
  2655. package/dist/agent/operational/pglite-client.js +255 -0
  2656. package/dist/agent/operational/pglite-client.js.map +1 -0
  2657. package/dist/agent/operational/post-once.d.ts +74 -0
  2658. package/dist/agent/operational/post-once.d.ts.map +1 -0
  2659. package/dist/agent/operational/post-once.js +92 -0
  2660. package/dist/agent/operational/post-once.js.map +1 -0
  2661. package/dist/agent/operational/postgres.d.ts +55 -0
  2662. package/dist/agent/operational/postgres.d.ts.map +1 -0
  2663. package/dist/agent/operational/postgres.js +4052 -0
  2664. package/dist/agent/operational/postgres.js.map +1 -0
  2665. package/dist/agent/operational/provider.d.ts +52 -0
  2666. package/dist/agent/operational/provider.d.ts.map +1 -0
  2667. package/dist/agent/operational/provider.js +166 -0
  2668. package/dist/agent/operational/provider.js.map +1 -0
  2669. package/dist/agent/operational/sqlite.d.ts +21 -0
  2670. package/dist/agent/operational/sqlite.d.ts.map +1 -0
  2671. package/dist/agent/operational/sqlite.js +3170 -0
  2672. package/dist/agent/operational/sqlite.js.map +1 -0
  2673. package/dist/agent/operational/store.d.ts +1953 -0
  2674. package/dist/agent/operational/store.d.ts.map +1 -0
  2675. package/dist/agent/operational/store.js +302 -0
  2676. package/dist/agent/operational/store.js.map +1 -0
  2677. package/dist/agent/ops/census.d.ts +411 -0
  2678. package/dist/agent/ops/census.d.ts.map +1 -0
  2679. package/dist/agent/ops/census.js +701 -0
  2680. package/dist/agent/ops/census.js.map +1 -0
  2681. package/dist/agent/ops/probes.d.ts +20 -0
  2682. package/dist/agent/ops/probes.d.ts.map +1 -0
  2683. package/dist/agent/ops/probes.js +59 -0
  2684. package/dist/agent/ops/probes.js.map +1 -0
  2685. package/dist/agent/ops/quickstart.d.ts +53 -0
  2686. package/dist/agent/ops/quickstart.d.ts.map +1 -0
  2687. package/dist/agent/ops/quickstart.js +247 -0
  2688. package/dist/agent/ops/quickstart.js.map +1 -0
  2689. package/dist/agent/ops/server.d.ts +16 -0
  2690. package/dist/agent/ops/server.d.ts.map +1 -0
  2691. package/dist/agent/ops/server.js +414 -0
  2692. package/dist/agent/ops/server.js.map +1 -0
  2693. package/dist/agent/ops/surface-manifest.d.ts +60 -0
  2694. package/dist/agent/ops/surface-manifest.d.ts.map +1 -0
  2695. package/dist/agent/ops/surface-manifest.js +79 -0
  2696. package/dist/agent/ops/surface-manifest.js.map +1 -0
  2697. package/dist/agent/ops/two-role.d.ts +26 -0
  2698. package/dist/agent/ops/two-role.d.ts.map +1 -0
  2699. package/dist/agent/ops/two-role.js +71 -0
  2700. package/dist/agent/ops/two-role.js.map +1 -0
  2701. package/dist/agent/pages/policy-pages.d.ts +14 -0
  2702. package/dist/agent/pages/policy-pages.d.ts.map +1 -0
  2703. package/dist/agent/pages/policy-pages.js +69 -0
  2704. package/dist/agent/pages/policy-pages.js.map +1 -0
  2705. package/dist/agent/plugins/extract.d.ts +31 -0
  2706. package/dist/agent/plugins/extract.d.ts.map +1 -0
  2707. package/dist/agent/plugins/extract.js +328 -0
  2708. package/dist/agent/plugins/extract.js.map +1 -0
  2709. package/dist/agent/plugins/parse.d.ts +3 -0
  2710. package/dist/agent/plugins/parse.d.ts.map +1 -0
  2711. package/dist/agent/plugins/parse.js +112 -0
  2712. package/dist/agent/plugins/parse.js.map +1 -0
  2713. package/dist/agent/plugins/types.d.ts +105 -0
  2714. package/dist/agent/plugins/types.d.ts.map +1 -0
  2715. package/dist/agent/plugins/types.js +30 -0
  2716. package/dist/agent/plugins/types.js.map +1 -0
  2717. package/dist/agent/publish/eve-patch-pack.d.ts +210 -0
  2718. package/dist/agent/publish/eve-patch-pack.d.ts.map +1 -0
  2719. package/dist/agent/publish/eve-patch-pack.js +377 -0
  2720. package/dist/agent/publish/eve-patch-pack.js.map +1 -0
  2721. package/dist/agent/review/blast-radius.d.ts +83 -0
  2722. package/dist/agent/review/blast-radius.d.ts.map +1 -0
  2723. package/dist/agent/review/blast-radius.js +224 -0
  2724. package/dist/agent/review/blast-radius.js.map +1 -0
  2725. package/dist/agent/review/config-facts.d.ts +69 -0
  2726. package/dist/agent/review/config-facts.d.ts.map +1 -0
  2727. package/dist/agent/review/config-facts.js +155 -0
  2728. package/dist/agent/review/config-facts.js.map +1 -0
  2729. package/dist/agent/review/facts-artifact.d.ts +108 -0
  2730. package/dist/agent/review/facts-artifact.d.ts.map +1 -0
  2731. package/dist/agent/review/facts-artifact.js +288 -0
  2732. package/dist/agent/review/facts-artifact.js.map +1 -0
  2733. package/dist/agent/review/facts-cloud-status.d.ts +90 -0
  2734. package/dist/agent/review/facts-cloud-status.d.ts.map +1 -0
  2735. package/dist/agent/review/facts-cloud-status.js +226 -0
  2736. package/dist/agent/review/facts-cloud-status.js.map +1 -0
  2737. package/dist/agent/review/pr-walkthrough.d.ts +134 -0
  2738. package/dist/agent/review/pr-walkthrough.d.ts.map +1 -0
  2739. package/dist/agent/review/pr-walkthrough.js +641 -0
  2740. package/dist/agent/review/pr-walkthrough.js.map +1 -0
  2741. package/dist/agent/review/zip.d.ts +26 -0
  2742. package/dist/agent/review/zip.d.ts.map +1 -0
  2743. package/dist/agent/review/zip.js +147 -0
  2744. package/dist/agent/review/zip.js.map +1 -0
  2745. package/dist/agent/roles/role.d.ts +95 -0
  2746. package/dist/agent/roles/role.d.ts.map +1 -0
  2747. package/dist/agent/roles/role.js +188 -0
  2748. package/dist/agent/roles/role.js.map +1 -0
  2749. package/dist/agent/routines/bound.d.ts +90 -0
  2750. package/dist/agent/routines/bound.d.ts.map +1 -0
  2751. package/dist/agent/routines/bound.js +233 -0
  2752. package/dist/agent/routines/bound.js.map +1 -0
  2753. package/dist/agent/routines/check-in.d.ts +10 -0
  2754. package/dist/agent/routines/check-in.d.ts.map +1 -0
  2755. package/dist/agent/routines/check-in.js +50 -0
  2756. package/dist/agent/routines/check-in.js.map +1 -0
  2757. package/dist/agent/routines/collector.d.ts +214 -0
  2758. package/dist/agent/routines/collector.d.ts.map +1 -0
  2759. package/dist/agent/routines/collector.js +389 -0
  2760. package/dist/agent/routines/collector.js.map +1 -0
  2761. package/dist/agent/routines/declared-permissions.d.ts +302 -0
  2762. package/dist/agent/routines/declared-permissions.d.ts.map +1 -0
  2763. package/dist/agent/routines/declared-permissions.js +548 -0
  2764. package/dist/agent/routines/declared-permissions.js.map +1 -0
  2765. package/dist/agent/routines/disable-notice.d.ts +75 -0
  2766. package/dist/agent/routines/disable-notice.d.ts.map +1 -0
  2767. package/dist/agent/routines/disable-notice.js +152 -0
  2768. package/dist/agent/routines/disable-notice.js.map +1 -0
  2769. package/dist/agent/routines/entity-read.d.ts +177 -0
  2770. package/dist/agent/routines/entity-read.d.ts.map +1 -0
  2771. package/dist/agent/routines/entity-read.js +178 -0
  2772. package/dist/agent/routines/entity-read.js.map +1 -0
  2773. package/dist/agent/routines/event-authz.d.ts +76 -0
  2774. package/dist/agent/routines/event-authz.d.ts.map +1 -0
  2775. package/dist/agent/routines/event-authz.js +229 -0
  2776. package/dist/agent/routines/event-authz.js.map +1 -0
  2777. package/dist/agent/routines/event-match.d.ts +50 -0
  2778. package/dist/agent/routines/event-match.d.ts.map +1 -0
  2779. package/dist/agent/routines/event-match.js +190 -0
  2780. package/dist/agent/routines/event-match.js.map +1 -0
  2781. package/dist/agent/routines/event-model.d.ts +463 -0
  2782. package/dist/agent/routines/event-model.d.ts.map +1 -0
  2783. package/dist/agent/routines/event-model.js +367 -0
  2784. package/dist/agent/routines/event-model.js.map +1 -0
  2785. package/dist/agent/routines/events.d.ts +85 -0
  2786. package/dist/agent/routines/events.d.ts.map +1 -0
  2787. package/dist/agent/routines/events.js +167 -0
  2788. package/dist/agent/routines/events.js.map +1 -0
  2789. package/dist/agent/routines/fire-audit.d.ts +409 -0
  2790. package/dist/agent/routines/fire-audit.d.ts.map +1 -0
  2791. package/dist/agent/routines/fire-audit.js +571 -0
  2792. package/dist/agent/routines/fire-audit.js.map +1 -0
  2793. package/dist/agent/routines/fire-auth.d.ts +114 -0
  2794. package/dist/agent/routines/fire-auth.d.ts.map +1 -0
  2795. package/dist/agent/routines/fire-auth.js +254 -0
  2796. package/dist/agent/routines/fire-auth.js.map +1 -0
  2797. package/dist/agent/routines/fire-carriage.d.ts +37 -0
  2798. package/dist/agent/routines/fire-carriage.d.ts.map +1 -0
  2799. package/dist/agent/routines/fire-carriage.js +115 -0
  2800. package/dist/agent/routines/fire-carriage.js.map +1 -0
  2801. package/dist/agent/routines/fire-creator.d.ts +26 -0
  2802. package/dist/agent/routines/fire-creator.d.ts.map +1 -0
  2803. package/dist/agent/routines/fire-creator.js +78 -0
  2804. package/dist/agent/routines/fire-creator.js.map +1 -0
  2805. package/dist/agent/routines/fire-disclosure.d.ts +70 -0
  2806. package/dist/agent/routines/fire-disclosure.d.ts.map +1 -0
  2807. package/dist/agent/routines/fire-disclosure.js +193 -0
  2808. package/dist/agent/routines/fire-disclosure.js.map +1 -0
  2809. package/dist/agent/routines/fire-eligibility.d.ts +87 -0
  2810. package/dist/agent/routines/fire-eligibility.d.ts.map +1 -0
  2811. package/dist/agent/routines/fire-eligibility.js +220 -0
  2812. package/dist/agent/routines/fire-eligibility.js.map +1 -0
  2813. package/dist/agent/routines/fire-halt.d.ts +16 -0
  2814. package/dist/agent/routines/fire-halt.d.ts.map +1 -0
  2815. package/dist/agent/routines/fire-halt.js +49 -0
  2816. package/dist/agent/routines/fire-halt.js.map +1 -0
  2817. package/dist/agent/routines/fire-message.d.ts +31 -0
  2818. package/dist/agent/routines/fire-message.d.ts.map +1 -0
  2819. package/dist/agent/routines/fire-message.js +51 -0
  2820. package/dist/agent/routines/fire-message.js.map +1 -0
  2821. package/dist/agent/routines/fire-toolset.d.ts +94 -0
  2822. package/dist/agent/routines/fire-toolset.d.ts.map +1 -0
  2823. package/dist/agent/routines/fire-toolset.js +128 -0
  2824. package/dist/agent/routines/fire-toolset.js.map +1 -0
  2825. package/dist/agent/routines/fire-window.d.ts +230 -0
  2826. package/dist/agent/routines/fire-window.d.ts.map +1 -0
  2827. package/dist/agent/routines/fire-window.js +517 -0
  2828. package/dist/agent/routines/fire-window.js.map +1 -0
  2829. package/dist/agent/routines/follow-ups.d.ts +77 -0
  2830. package/dist/agent/routines/follow-ups.d.ts.map +1 -0
  2831. package/dist/agent/routines/follow-ups.js +134 -0
  2832. package/dist/agent/routines/follow-ups.js.map +1 -0
  2833. package/dist/agent/routines/gate.d.ts +133 -0
  2834. package/dist/agent/routines/gate.d.ts.map +1 -0
  2835. package/dist/agent/routines/gate.js +196 -0
  2836. package/dist/agent/routines/gate.js.map +1 -0
  2837. package/dist/agent/routines/github-entity-read.d.ts +26 -0
  2838. package/dist/agent/routines/github-entity-read.d.ts.map +1 -0
  2839. package/dist/agent/routines/github-entity-read.js +107 -0
  2840. package/dist/agent/routines/github-entity-read.js.map +1 -0
  2841. package/dist/agent/routines/github-fanout.d.ts +23 -0
  2842. package/dist/agent/routines/github-fanout.d.ts.map +1 -0
  2843. package/dist/agent/routines/github-fanout.js +67 -0
  2844. package/dist/agent/routines/github-fanout.js.map +1 -0
  2845. package/dist/agent/routines/github-normalizer.d.ts +20 -0
  2846. package/dist/agent/routines/github-normalizer.d.ts.map +1 -0
  2847. package/dist/agent/routines/github-normalizer.js +253 -0
  2848. package/dist/agent/routines/github-normalizer.js.map +1 -0
  2849. package/dist/agent/routines/ingress.d.ts +128 -0
  2850. package/dist/agent/routines/ingress.d.ts.map +1 -0
  2851. package/dist/agent/routines/ingress.js +703 -0
  2852. package/dist/agent/routines/ingress.js.map +1 -0
  2853. package/dist/agent/routines/job.d.ts +49 -0
  2854. package/dist/agent/routines/job.d.ts.map +1 -0
  2855. package/dist/agent/routines/job.js +122 -0
  2856. package/dist/agent/routines/job.js.map +1 -0
  2857. package/dist/agent/routines/jq-filter.d.ts +94 -0
  2858. package/dist/agent/routines/jq-filter.d.ts.map +1 -0
  2859. package/dist/agent/routines/jq-filter.js +322 -0
  2860. package/dist/agent/routines/jq-filter.js.map +1 -0
  2861. package/dist/agent/routines/lifecycle.d.ts +101 -0
  2862. package/dist/agent/routines/lifecycle.d.ts.map +1 -0
  2863. package/dist/agent/routines/lifecycle.js +231 -0
  2864. package/dist/agent/routines/lifecycle.js.map +1 -0
  2865. package/dist/agent/routines/match-stamp.d.ts +26 -0
  2866. package/dist/agent/routines/match-stamp.d.ts.map +1 -0
  2867. package/dist/agent/routines/match-stamp.js +121 -0
  2868. package/dist/agent/routines/match-stamp.js.map +1 -0
  2869. package/dist/agent/routines/outcome-fold.d.ts +115 -0
  2870. package/dist/agent/routines/outcome-fold.d.ts.map +1 -0
  2871. package/dist/agent/routines/outcome-fold.js +244 -0
  2872. package/dist/agent/routines/outcome-fold.js.map +1 -0
  2873. package/dist/agent/routines/partition.d.ts +5 -0
  2874. package/dist/agent/routines/partition.d.ts.map +1 -0
  2875. package/dist/agent/routines/partition.js +24 -0
  2876. package/dist/agent/routines/partition.js.map +1 -0
  2877. package/dist/agent/routines/permission-card-wait.d.ts +150 -0
  2878. package/dist/agent/routines/permission-card-wait.d.ts.map +1 -0
  2879. package/dist/agent/routines/permission-card-wait.js +213 -0
  2880. package/dist/agent/routines/permission-card-wait.js.map +1 -0
  2881. package/dist/agent/routines/permission-card.d.ts +196 -0
  2882. package/dist/agent/routines/permission-card.d.ts.map +1 -0
  2883. package/dist/agent/routines/permission-card.js +397 -0
  2884. package/dist/agent/routines/permission-card.js.map +1 -0
  2885. package/dist/agent/routines/permission-key.d.ts +25 -0
  2886. package/dist/agent/routines/permission-key.d.ts.map +1 -0
  2887. package/dist/agent/routines/permission-key.js +53 -0
  2888. package/dist/agent/routines/permission-key.js.map +1 -0
  2889. package/dist/agent/routines/permission-review.d.ts +108 -0
  2890. package/dist/agent/routines/permission-review.d.ts.map +1 -0
  2891. package/dist/agent/routines/permission-review.js +215 -0
  2892. package/dist/agent/routines/permission-review.js.map +1 -0
  2893. package/dist/agent/routines/policy.d.ts +146 -0
  2894. package/dist/agent/routines/policy.d.ts.map +1 -0
  2895. package/dist/agent/routines/policy.js +241 -0
  2896. package/dist/agent/routines/policy.js.map +1 -0
  2897. package/dist/agent/routines/pre-fire.d.ts +46 -0
  2898. package/dist/agent/routines/pre-fire.d.ts.map +1 -0
  2899. package/dist/agent/routines/pre-fire.js +111 -0
  2900. package/dist/agent/routines/pre-fire.js.map +1 -0
  2901. package/dist/agent/routines/provider-events.d.ts +115 -0
  2902. package/dist/agent/routines/provider-events.d.ts.map +1 -0
  2903. package/dist/agent/routines/provider-events.js +307 -0
  2904. package/dist/agent/routines/provider-events.js.map +1 -0
  2905. package/dist/agent/routines/report.d.ts +33 -0
  2906. package/dist/agent/routines/report.d.ts.map +1 -0
  2907. package/dist/agent/routines/report.js +122 -0
  2908. package/dist/agent/routines/report.js.map +1 -0
  2909. package/dist/agent/routines/routine.d.ts +774 -0
  2910. package/dist/agent/routines/routine.d.ts.map +1 -0
  2911. package/dist/agent/routines/routine.js +385 -0
  2912. package/dist/agent/routines/routine.js.map +1 -0
  2913. package/dist/agent/routines/schedule.d.ts +70 -0
  2914. package/dist/agent/routines/schedule.d.ts.map +1 -0
  2915. package/dist/agent/routines/schedule.js +187 -0
  2916. package/dist/agent/routines/schedule.js.map +1 -0
  2917. package/dist/agent/routines/scheme-name.d.ts +43 -0
  2918. package/dist/agent/routines/scheme-name.d.ts.map +1 -0
  2919. package/dist/agent/routines/scheme-name.js +73 -0
  2920. package/dist/agent/routines/scheme-name.js.map +1 -0
  2921. package/dist/agent/routines/stall.d.ts +46 -0
  2922. package/dist/agent/routines/stall.d.ts.map +1 -0
  2923. package/dist/agent/routines/stall.js +143 -0
  2924. package/dist/agent/routines/stall.js.map +1 -0
  2925. package/dist/agent/routines/store.d.ts +47 -0
  2926. package/dist/agent/routines/store.d.ts.map +1 -0
  2927. package/dist/agent/routines/store.js +82 -0
  2928. package/dist/agent/routines/store.js.map +1 -0
  2929. package/dist/agent/routines/watch.d.ts +134 -0
  2930. package/dist/agent/routines/watch.d.ts.map +1 -0
  2931. package/dist/agent/routines/watch.js +266 -0
  2932. package/dist/agent/routines/watch.js.map +1 -0
  2933. package/dist/agent/sandbox/backend-select.d.ts +19 -0
  2934. package/dist/agent/sandbox/backend-select.d.ts.map +1 -0
  2935. package/dist/agent/sandbox/backend-select.js +46 -0
  2936. package/dist/agent/sandbox/backend-select.js.map +1 -0
  2937. package/dist/agent/sandbox/vercel-create.d.ts +99 -0
  2938. package/dist/agent/sandbox/vercel-create.d.ts.map +1 -0
  2939. package/dist/agent/sandbox/vercel-create.js +151 -0
  2940. package/dist/agent/sandbox/vercel-create.js.map +1 -0
  2941. package/dist/agent/scaffold/app-root.d.ts +18 -0
  2942. package/dist/agent/scaffold/app-root.d.ts.map +1 -0
  2943. package/dist/agent/scaffold/app-root.js +97 -0
  2944. package/dist/agent/scaffold/app-root.js.map +1 -0
  2945. package/dist/agent/scaffold/roster-config.d.ts +130 -0
  2946. package/dist/agent/scaffold/roster-config.d.ts.map +1 -0
  2947. package/dist/agent/scaffold/roster-config.js +46 -0
  2948. package/dist/agent/scaffold/roster-config.js.map +1 -0
  2949. package/dist/agent/scaffold/roster-fs.d.ts +45 -0
  2950. package/dist/agent/scaffold/roster-fs.d.ts.map +1 -0
  2951. package/dist/agent/scaffold/roster-fs.js +195 -0
  2952. package/dist/agent/scaffold/roster-fs.js.map +1 -0
  2953. package/dist/agent/scaffold/roster-plan.d.ts +167 -0
  2954. package/dist/agent/scaffold/roster-plan.d.ts.map +1 -0
  2955. package/dist/agent/scaffold/roster-plan.js +668 -0
  2956. package/dist/agent/scaffold/roster-plan.js.map +1 -0
  2957. package/dist/agent/scaffold/templates.d.ts +13 -0
  2958. package/dist/agent/scaffold/templates.d.ts.map +1 -0
  2959. package/dist/agent/scaffold/templates.js +73 -0
  2960. package/dist/agent/scaffold/templates.js.map +1 -0
  2961. package/dist/agent/scaffold/tool-roster-read.d.ts +24 -0
  2962. package/dist/agent/scaffold/tool-roster-read.d.ts.map +1 -0
  2963. package/dist/agent/scaffold/tool-roster-read.js +68 -0
  2964. package/dist/agent/scaffold/tool-roster-read.js.map +1 -0
  2965. package/dist/agent/scaffold/tool-roster.d.ts +90 -0
  2966. package/dist/agent/scaffold/tool-roster.d.ts.map +1 -0
  2967. package/dist/agent/scaffold/tool-roster.js +128 -0
  2968. package/dist/agent/scaffold/tool-roster.js.map +1 -0
  2969. package/dist/agent/schedules/directory-sync.d.ts +6 -0
  2970. package/dist/agent/schedules/directory-sync.d.ts.map +1 -0
  2971. package/dist/agent/schedules/directory-sync.js +36 -0
  2972. package/dist/agent/schedules/directory-sync.js.map +1 -0
  2973. package/dist/agent/schedules/dispatch.d.ts +34 -0
  2974. package/dist/agent/schedules/dispatch.d.ts.map +1 -0
  2975. package/dist/agent/schedules/dispatch.js +749 -0
  2976. package/dist/agent/schedules/dispatch.js.map +1 -0
  2977. package/dist/agent/schedules/dream-mode3.d.ts +28 -0
  2978. package/dist/agent/schedules/dream-mode3.d.ts.map +1 -0
  2979. package/dist/agent/schedules/dream-mode3.js +261 -0
  2980. package/dist/agent/schedules/dream-mode3.js.map +1 -0
  2981. package/dist/agent/schedules/routine-dispatch.d.ts +125 -0
  2982. package/dist/agent/schedules/routine-dispatch.d.ts.map +1 -0
  2983. package/dist/agent/schedules/routine-dispatch.js +139 -0
  2984. package/dist/agent/schedules/routine-dispatch.js.map +1 -0
  2985. package/dist/agent/schedules/tidy.d.ts +39 -0
  2986. package/dist/agent/schedules/tidy.d.ts.map +1 -0
  2987. package/dist/agent/schedules/tidy.js +292 -0
  2988. package/dist/agent/schedules/tidy.js.map +1 -0
  2989. package/dist/agent/scm/app.d.ts +55 -0
  2990. package/dist/agent/scm/app.d.ts.map +1 -0
  2991. package/dist/agent/scm/app.js +120 -0
  2992. package/dist/agent/scm/app.js.map +1 -0
  2993. package/dist/agent/scm/broker-audit.d.ts +35 -0
  2994. package/dist/agent/scm/broker-audit.d.ts.map +1 -0
  2995. package/dist/agent/scm/broker-audit.js +94 -0
  2996. package/dist/agent/scm/broker-audit.js.map +1 -0
  2997. package/dist/agent/scm/broker.d.ts +56 -0
  2998. package/dist/agent/scm/broker.d.ts.map +1 -0
  2999. package/dist/agent/scm/broker.js +113 -0
  3000. package/dist/agent/scm/broker.js.map +1 -0
  3001. package/dist/agent/scm/capability-fit.d.ts +59 -0
  3002. package/dist/agent/scm/capability-fit.d.ts.map +1 -0
  3003. package/dist/agent/scm/capability-fit.js +122 -0
  3004. package/dist/agent/scm/capability-fit.js.map +1 -0
  3005. package/dist/agent/scm/config-repo-token.d.ts +3 -0
  3006. package/dist/agent/scm/config-repo-token.d.ts.map +1 -0
  3007. package/dist/agent/scm/config-repo-token.js +43 -0
  3008. package/dist/agent/scm/config-repo-token.js.map +1 -0
  3009. package/dist/agent/scm/config.d.ts +3 -0
  3010. package/dist/agent/scm/config.d.ts.map +1 -0
  3011. package/dist/agent/scm/config.js +36 -0
  3012. package/dist/agent/scm/config.js.map +1 -0
  3013. package/dist/agent/scm/contents.d.ts +54 -0
  3014. package/dist/agent/scm/contents.d.ts.map +1 -0
  3015. package/dist/agent/scm/contents.js +117 -0
  3016. package/dist/agent/scm/contents.js.map +1 -0
  3017. package/dist/agent/scm/git.d.ts +157 -0
  3018. package/dist/agent/scm/git.d.ts.map +1 -0
  3019. package/dist/agent/scm/git.js +318 -0
  3020. package/dist/agent/scm/git.js.map +1 -0
  3021. package/dist/agent/scm/github-acting-identity.d.ts +38 -0
  3022. package/dist/agent/scm/github-acting-identity.d.ts.map +1 -0
  3023. package/dist/agent/scm/github-acting-identity.js +121 -0
  3024. package/dist/agent/scm/github-acting-identity.js.map +1 -0
  3025. package/dist/agent/scm/github-search.d.ts +23 -0
  3026. package/dist/agent/scm/github-search.d.ts.map +1 -0
  3027. package/dist/agent/scm/github-search.js +122 -0
  3028. package/dist/agent/scm/github-search.js.map +1 -0
  3029. package/dist/agent/scm/github-work.d.ts +17 -0
  3030. package/dist/agent/scm/github-work.d.ts.map +1 -0
  3031. package/dist/agent/scm/github-work.js +43 -0
  3032. package/dist/agent/scm/github-work.js.map +1 -0
  3033. package/dist/agent/scm/installations.d.ts +46 -0
  3034. package/dist/agent/scm/installations.d.ts.map +1 -0
  3035. package/dist/agent/scm/installations.js +144 -0
  3036. package/dist/agent/scm/installations.js.map +1 -0
  3037. package/dist/agent/scm/issue-actions.d.ts +41 -0
  3038. package/dist/agent/scm/issue-actions.d.ts.map +1 -0
  3039. package/dist/agent/scm/issue-actions.js +173 -0
  3040. package/dist/agent/scm/issue-actions.js.map +1 -0
  3041. package/dist/agent/scm/mint.d.ts +76 -0
  3042. package/dist/agent/scm/mint.d.ts.map +1 -0
  3043. package/dist/agent/scm/mint.js +253 -0
  3044. package/dist/agent/scm/mint.js.map +1 -0
  3045. package/dist/agent/scm/pr-activity.d.ts +50 -0
  3046. package/dist/agent/scm/pr-activity.d.ts.map +1 -0
  3047. package/dist/agent/scm/pr-activity.js +102 -0
  3048. package/dist/agent/scm/pr-activity.js.map +1 -0
  3049. package/dist/agent/scm/pr-diff.d.ts +61 -0
  3050. package/dist/agent/scm/pr-diff.d.ts.map +1 -0
  3051. package/dist/agent/scm/pr-diff.js +104 -0
  3052. package/dist/agent/scm/pr-diff.js.map +1 -0
  3053. package/dist/agent/scm/pr-feedback.d.ts +87 -0
  3054. package/dist/agent/scm/pr-feedback.d.ts.map +1 -0
  3055. package/dist/agent/scm/pr-feedback.js +230 -0
  3056. package/dist/agent/scm/pr-feedback.js.map +1 -0
  3057. package/dist/agent/scm/pr-status.d.ts +120 -0
  3058. package/dist/agent/scm/pr-status.d.ts.map +1 -0
  3059. package/dist/agent/scm/pr-status.js +199 -0
  3060. package/dist/agent/scm/pr-status.js.map +1 -0
  3061. package/dist/agent/scm/pr-watch.d.ts +26 -0
  3062. package/dist/agent/scm/pr-watch.d.ts.map +1 -0
  3063. package/dist/agent/scm/pr-watch.js +165 -0
  3064. package/dist/agent/scm/pr-watch.js.map +1 -0
  3065. package/dist/agent/scm/pr.d.ts +42 -0
  3066. package/dist/agent/scm/pr.d.ts.map +1 -0
  3067. package/dist/agent/scm/pr.js +73 -0
  3068. package/dist/agent/scm/pr.js.map +1 -0
  3069. package/dist/agent/scm/provider.d.ts +13 -0
  3070. package/dist/agent/scm/provider.d.ts.map +1 -0
  3071. package/dist/agent/scm/provider.js +39 -0
  3072. package/dist/agent/scm/provider.js.map +1 -0
  3073. package/dist/agent/scm/refs.d.ts +65 -0
  3074. package/dist/agent/scm/refs.d.ts.map +1 -0
  3075. package/dist/agent/scm/refs.js +89 -0
  3076. package/dist/agent/scm/refs.js.map +1 -0
  3077. package/dist/agent/scm/repo-skills.d.ts +69 -0
  3078. package/dist/agent/scm/repo-skills.d.ts.map +1 -0
  3079. package/dist/agent/scm/repo-skills.js +170 -0
  3080. package/dist/agent/scm/repo-skills.js.map +1 -0
  3081. package/dist/agent/scm/types.d.ts +40 -0
  3082. package/dist/agent/scm/types.d.ts.map +1 -0
  3083. package/dist/agent/scm/types.js +9 -0
  3084. package/dist/agent/scm/types.js.map +1 -0
  3085. package/dist/agent/scm/write-token.d.ts +10 -0
  3086. package/dist/agent/scm/write-token.d.ts.map +1 -0
  3087. package/dist/agent/scm/write-token.js +40 -0
  3088. package/dist/agent/scm/write-token.js.map +1 -0
  3089. package/dist/agent/settings/settings.d.ts +935 -0
  3090. package/dist/agent/settings/settings.d.ts.map +1 -0
  3091. package/dist/agent/settings/settings.js +1104 -0
  3092. package/dist/agent/settings/settings.js.map +1 -0
  3093. package/dist/agent/skills/domain-skills.d.ts +61 -0
  3094. package/dist/agent/skills/domain-skills.d.ts.map +1 -0
  3095. package/dist/agent/skills/domain-skills.js +174 -0
  3096. package/dist/agent/skills/domain-skills.js.map +1 -0
  3097. package/dist/agent/skills/scoped.d.ts +21 -0
  3098. package/dist/agent/skills/scoped.d.ts.map +1 -0
  3099. package/dist/agent/skills/scoped.js +152 -0
  3100. package/dist/agent/skills/scoped.js.map +1 -0
  3101. package/dist/agent/spend/bypass.d.ts +30 -0
  3102. package/dist/agent/spend/bypass.d.ts.map +1 -0
  3103. package/dist/agent/spend/bypass.js +117 -0
  3104. package/dist/agent/spend/bypass.js.map +1 -0
  3105. package/dist/agent/spend/caps.d.ts +173 -0
  3106. package/dist/agent/spend/caps.d.ts.map +1 -0
  3107. package/dist/agent/spend/caps.js +323 -0
  3108. package/dist/agent/spend/caps.js.map +1 -0
  3109. package/dist/agent/spend/check.d.ts +54 -0
  3110. package/dist/agent/spend/check.d.ts.map +1 -0
  3111. package/dist/agent/spend/check.js +157 -0
  3112. package/dist/agent/spend/check.js.map +1 -0
  3113. package/dist/agent/spend/checkpoint.d.ts +158 -0
  3114. package/dist/agent/spend/checkpoint.d.ts.map +1 -0
  3115. package/dist/agent/spend/checkpoint.js +559 -0
  3116. package/dist/agent/spend/checkpoint.js.map +1 -0
  3117. package/dist/agent/spend/dm-mask.d.ts +61 -0
  3118. package/dist/agent/spend/dm-mask.d.ts.map +1 -0
  3119. package/dist/agent/spend/dm-mask.js +113 -0
  3120. package/dist/agent/spend/dm-mask.js.map +1 -0
  3121. package/dist/agent/spend/ingress-gate.d.ts +143 -0
  3122. package/dist/agent/spend/ingress-gate.d.ts.map +1 -0
  3123. package/dist/agent/spend/ingress-gate.js +217 -0
  3124. package/dist/agent/spend/ingress-gate.js.map +1 -0
  3125. package/dist/agent/spend/pricing.d.ts +251 -0
  3126. package/dist/agent/spend/pricing.d.ts.map +1 -0
  3127. package/dist/agent/spend/pricing.js +454 -0
  3128. package/dist/agent/spend/pricing.js.map +1 -0
  3129. package/dist/agent/spend/reporting.d.ts +313 -0
  3130. package/dist/agent/spend/reporting.d.ts.map +1 -0
  3131. package/dist/agent/spend/reporting.js +674 -0
  3132. package/dist/agent/spend/reporting.js.map +1 -0
  3133. package/dist/agent/spend/sandbox-pricing.d.ts +19 -0
  3134. package/dist/agent/spend/sandbox-pricing.d.ts.map +1 -0
  3135. package/dist/agent/spend/sandbox-pricing.js +50 -0
  3136. package/dist/agent/spend/sandbox-pricing.js.map +1 -0
  3137. package/dist/agent/spend/spend.d.ts +283 -0
  3138. package/dist/agent/spend/spend.d.ts.map +1 -0
  3139. package/dist/agent/spend/spend.js +255 -0
  3140. package/dist/agent/spend/spend.js.map +1 -0
  3141. package/dist/agent/spend/stack-pricing.d.ts +94 -0
  3142. package/dist/agent/spend/stack-pricing.d.ts.map +1 -0
  3143. package/dist/agent/spend/stack-pricing.js +123 -0
  3144. package/dist/agent/spend/stack-pricing.js.map +1 -0
  3145. package/dist/agent/spend/store.d.ts +139 -0
  3146. package/dist/agent/spend/store.d.ts.map +1 -0
  3147. package/dist/agent/spend/store.js +180 -0
  3148. package/dist/agent/spend/store.js.map +1 -0
  3149. package/dist/agent/spend/subagent-runs.d.ts +79 -0
  3150. package/dist/agent/spend/subagent-runs.d.ts.map +1 -0
  3151. package/dist/agent/spend/subagent-runs.js +124 -0
  3152. package/dist/agent/spend/subagent-runs.js.map +1 -0
  3153. package/dist/agent/spend/usage-events.d.ts +79 -0
  3154. package/dist/agent/spend/usage-events.d.ts.map +1 -0
  3155. package/dist/agent/spend/usage-events.js +132 -0
  3156. package/dist/agent/spend/usage-events.js.map +1 -0
  3157. package/dist/agent/stall/bash-hang-guard.d.ts +133 -0
  3158. package/dist/agent/stall/bash-hang-guard.d.ts.map +1 -0
  3159. package/dist/agent/stall/bash-hang-guard.js +303 -0
  3160. package/dist/agent/stall/bash-hang-guard.js.map +1 -0
  3161. package/dist/agent/stall/guard.d.ts +68 -0
  3162. package/dist/agent/stall/guard.d.ts.map +1 -0
  3163. package/dist/agent/stall/guard.js +248 -0
  3164. package/dist/agent/stall/guard.js.map +1 -0
  3165. package/dist/agent/status/status.d.ts +32 -0
  3166. package/dist/agent/status/status.d.ts.map +1 -0
  3167. package/dist/agent/status/status.js +116 -0
  3168. package/dist/agent/status/status.js.map +1 -0
  3169. package/dist/agent/subagents/contracts.d.ts +82 -0
  3170. package/dist/agent/subagents/contracts.d.ts.map +1 -0
  3171. package/dist/agent/subagents/contracts.js +114 -0
  3172. package/dist/agent/subagents/contracts.js.map +1 -0
  3173. package/dist/agent/subagents/declared.d.ts +44 -0
  3174. package/dist/agent/subagents/declared.d.ts.map +1 -0
  3175. package/dist/agent/subagents/declared.js +152 -0
  3176. package/dist/agent/subagents/declared.js.map +1 -0
  3177. package/dist/agent/testing/driver-allowlist.d.ts +103 -0
  3178. package/dist/agent/testing/driver-allowlist.d.ts.map +1 -0
  3179. package/dist/agent/testing/driver-allowlist.js +193 -0
  3180. package/dist/agent/testing/driver-allowlist.js.map +1 -0
  3181. package/dist/agent/tools/add_label.d.ts +52 -0
  3182. package/dist/agent/tools/add_label.d.ts.map +1 -0
  3183. package/dist/agent/tools/add_label.js +63 -0
  3184. package/dist/agent/tools/add_label.js.map +1 -0
  3185. package/dist/agent/tools/add_routine_rule.d.ts +38 -0
  3186. package/dist/agent/tools/add_routine_rule.d.ts.map +1 -0
  3187. package/dist/agent/tools/add_routine_rule.js +182 -0
  3188. package/dist/agent/tools/add_routine_rule.js.map +1 -0
  3189. package/dist/agent/tools/agent_version.d.ts +17 -0
  3190. package/dist/agent/tools/agent_version.d.ts.map +1 -0
  3191. package/dist/agent/tools/agent_version.js +38 -0
  3192. package/dist/agent/tools/agent_version.js.map +1 -0
  3193. package/dist/agent/tools/assign.d.ts +74 -0
  3194. package/dist/agent/tools/assign.d.ts.map +1 -0
  3195. package/dist/agent/tools/assign.js +167 -0
  3196. package/dist/agent/tools/assign.js.map +1 -0
  3197. package/dist/agent/tools/aws.d.ts +33 -0
  3198. package/dist/agent/tools/aws.d.ts.map +1 -0
  3199. package/dist/agent/tools/aws.js +164 -0
  3200. package/dist/agent/tools/aws.js.map +1 -0
  3201. package/dist/agent/tools/browser_tools.d.ts +3 -0
  3202. package/dist/agent/tools/browser_tools.d.ts.map +1 -0
  3203. package/dist/agent/tools/browser_tools.js +21 -0
  3204. package/dist/agent/tools/browser_tools.js.map +1 -0
  3205. package/dist/agent/tools/cancel_routine.d.ts +27 -0
  3206. package/dist/agent/tools/cancel_routine.d.ts.map +1 -0
  3207. package/dist/agent/tools/cancel_routine.js +123 -0
  3208. package/dist/agent/tools/cancel_routine.js.map +1 -0
  3209. package/dist/agent/tools/capture_events.d.ts +17 -0
  3210. package/dist/agent/tools/capture_events.d.ts.map +1 -0
  3211. package/dist/agent/tools/capture_events.js +51 -0
  3212. package/dist/agent/tools/capture_events.js.map +1 -0
  3213. package/dist/agent/tools/check_pr_status.d.ts +52 -0
  3214. package/dist/agent/tools/check_pr_status.d.ts.map +1 -0
  3215. package/dist/agent/tools/check_pr_status.js +66 -0
  3216. package/dist/agent/tools/check_pr_status.js.map +1 -0
  3217. package/dist/agent/tools/checkout_repo.d.ts +3 -0
  3218. package/dist/agent/tools/checkout_repo.d.ts.map +1 -0
  3219. package/dist/agent/tools/checkout_repo.js +158 -0
  3220. package/dist/agent/tools/checkout_repo.js.map +1 -0
  3221. package/dist/agent/tools/clear_connector_override.d.ts +48 -0
  3222. package/dist/agent/tools/clear_connector_override.d.ts.map +1 -0
  3223. package/dist/agent/tools/clear_connector_override.js +134 -0
  3224. package/dist/agent/tools/clear_connector_override.js.map +1 -0
  3225. package/dist/agent/tools/clear_spend_limit.d.ts +51 -0
  3226. package/dist/agent/tools/clear_spend_limit.d.ts.map +1 -0
  3227. package/dist/agent/tools/clear_spend_limit.js +162 -0
  3228. package/dist/agent/tools/clear_spend_limit.js.map +1 -0
  3229. package/dist/agent/tools/complete_job.d.ts +15 -0
  3230. package/dist/agent/tools/complete_job.d.ts.map +1 -0
  3231. package/dist/agent/tools/complete_job.js +59 -0
  3232. package/dist/agent/tools/complete_job.js.map +1 -0
  3233. package/dist/agent/tools/complete_thread.d.ts +8 -0
  3234. package/dist/agent/tools/complete_thread.d.ts.map +1 -0
  3235. package/dist/agent/tools/complete_thread.js +125 -0
  3236. package/dist/agent/tools/complete_thread.js.map +1 -0
  3237. package/dist/agent/tools/confirm_link.d.ts +84 -0
  3238. package/dist/agent/tools/confirm_link.d.ts.map +1 -0
  3239. package/dist/agent/tools/confirm_link.js +437 -0
  3240. package/dist/agent/tools/confirm_link.js.map +1 -0
  3241. package/dist/agent/tools/connector.d.ts +34 -0
  3242. package/dist/agent/tools/connector.d.ts.map +1 -0
  3243. package/dist/agent/tools/connector.js +212 -0
  3244. package/dist/agent/tools/connector.js.map +1 -0
  3245. package/dist/agent/tools/create_agent.d.ts +77 -0
  3246. package/dist/agent/tools/create_agent.d.ts.map +1 -0
  3247. package/dist/agent/tools/create_agent.js +261 -0
  3248. package/dist/agent/tools/create_agent.js.map +1 -0
  3249. package/dist/agent/tools/create_routine.d.ts +95 -0
  3250. package/dist/agent/tools/create_routine.d.ts.map +1 -0
  3251. package/dist/agent/tools/create_routine.js +437 -0
  3252. package/dist/agent/tools/create_routine.js.map +1 -0
  3253. package/dist/agent/tools/create_skill.d.ts +3 -0
  3254. package/dist/agent/tools/create_skill.d.ts.map +1 -0
  3255. package/dist/agent/tools/create_skill.js +157 -0
  3256. package/dist/agent/tools/create_skill.js.map +1 -0
  3257. package/dist/agent/tools/create_ticket.d.ts +70 -0
  3258. package/dist/agent/tools/create_ticket.d.ts.map +1 -0
  3259. package/dist/agent/tools/create_ticket.js +171 -0
  3260. package/dist/agent/tools/create_ticket.js.map +1 -0
  3261. package/dist/agent/tools/declare_webhook.d.ts +70 -0
  3262. package/dist/agent/tools/declare_webhook.d.ts.map +1 -0
  3263. package/dist/agent/tools/declare_webhook.js +321 -0
  3264. package/dist/agent/tools/declare_webhook.js.map +1 -0
  3265. package/dist/agent/tools/delete_skill.d.ts +3 -0
  3266. package/dist/agent/tools/delete_skill.d.ts.map +1 -0
  3267. package/dist/agent/tools/delete_skill.js +125 -0
  3268. package/dist/agent/tools/delete_skill.js.map +1 -0
  3269. package/dist/agent/tools/describe_image.d.ts +72 -0
  3270. package/dist/agent/tools/describe_image.d.ts.map +1 -0
  3271. package/dist/agent/tools/describe_image.js +269 -0
  3272. package/dist/agent/tools/describe_image.js.map +1 -0
  3273. package/dist/agent/tools/dm_person.d.ts +43 -0
  3274. package/dist/agent/tools/dm_person.d.ts.map +1 -0
  3275. package/dist/agent/tools/dm_person.js +190 -0
  3276. package/dist/agent/tools/dm_person.js.map +1 -0
  3277. package/dist/agent/tools/edit_reply.d.ts +56 -0
  3278. package/dist/agent/tools/edit_reply.d.ts.map +1 -0
  3279. package/dist/agent/tools/edit_reply.js +169 -0
  3280. package/dist/agent/tools/edit_reply.js.map +1 -0
  3281. package/dist/agent/tools/edit_routine.d.ts +32 -0
  3282. package/dist/agent/tools/edit_routine.d.ts.map +1 -0
  3283. package/dist/agent/tools/edit_routine.js +143 -0
  3284. package/dist/agent/tools/edit_routine.js.map +1 -0
  3285. package/dist/agent/tools/enable_routine.d.ts +30 -0
  3286. package/dist/agent/tools/enable_routine.d.ts.map +1 -0
  3287. package/dist/agent/tools/enable_routine.js +148 -0
  3288. package/dist/agent/tools/enable_routine.js.map +1 -0
  3289. package/dist/agent/tools/explain_permission.d.ts +27 -0
  3290. package/dist/agent/tools/explain_permission.d.ts.map +1 -0
  3291. package/dist/agent/tools/explain_permission.js +51 -0
  3292. package/dist/agent/tools/explain_permission.js.map +1 -0
  3293. package/dist/agent/tools/get_pr_feedback.d.ts +184 -0
  3294. package/dist/agent/tools/get_pr_feedback.d.ts.map +1 -0
  3295. package/dist/agent/tools/get_pr_feedback.js +77 -0
  3296. package/dist/agent/tools/get_pr_feedback.js.map +1 -0
  3297. package/dist/agent/tools/grant_tools.d.ts +27 -0
  3298. package/dist/agent/tools/grant_tools.d.ts.map +1 -0
  3299. package/dist/agent/tools/grant_tools.js +417 -0
  3300. package/dist/agent/tools/grant_tools.js.map +1 -0
  3301. package/dist/agent/tools/halt.d.ts +71 -0
  3302. package/dist/agent/tools/halt.d.ts.map +1 -0
  3303. package/dist/agent/tools/halt.js +157 -0
  3304. package/dist/agent/tools/halt.js.map +1 -0
  3305. package/dist/agent/tools/link_identity.d.ts +48 -0
  3306. package/dist/agent/tools/link_identity.d.ts.map +1 -0
  3307. package/dist/agent/tools/link_identity.js +283 -0
  3308. package/dist/agent/tools/link_identity.js.map +1 -0
  3309. package/dist/agent/tools/list_recent_events.d.ts +19 -0
  3310. package/dist/agent/tools/list_recent_events.d.ts.map +1 -0
  3311. package/dist/agent/tools/list_recent_events.js +55 -0
  3312. package/dist/agent/tools/list_recent_events.js.map +1 -0
  3313. package/dist/agent/tools/list_repos.d.ts +11 -0
  3314. package/dist/agent/tools/list_repos.d.ts.map +1 -0
  3315. package/dist/agent/tools/list_repos.js +22 -0
  3316. package/dist/agent/tools/list_repos.js.map +1 -0
  3317. package/dist/agent/tools/list_routines.d.ts +88 -0
  3318. package/dist/agent/tools/list_routines.d.ts.map +1 -0
  3319. package/dist/agent/tools/list_routines.js +143 -0
  3320. package/dist/agent/tools/list_routines.js.map +1 -0
  3321. package/dist/agent/tools/list_skills.d.ts +21 -0
  3322. package/dist/agent/tools/list_skills.d.ts.map +1 -0
  3323. package/dist/agent/tools/list_skills.js +34 -0
  3324. package/dist/agent/tools/list_skills.js.map +1 -0
  3325. package/dist/agent/tools/list_webhooks.d.ts +27 -0
  3326. package/dist/agent/tools/list_webhooks.d.ts.map +1 -0
  3327. package/dist/agent/tools/list_webhooks.js +66 -0
  3328. package/dist/agent/tools/list_webhooks.js.map +1 -0
  3329. package/dist/agent/tools/memory_admin_list.d.ts +10 -0
  3330. package/dist/agent/tools/memory_admin_list.d.ts.map +1 -0
  3331. package/dist/agent/tools/memory_admin_list.js +72 -0
  3332. package/dist/agent/tools/memory_admin_list.js.map +1 -0
  3333. package/dist/agent/tools/memory_admin_read.d.ts +17 -0
  3334. package/dist/agent/tools/memory_admin_read.d.ts.map +1 -0
  3335. package/dist/agent/tools/memory_admin_read.js +85 -0
  3336. package/dist/agent/tools/memory_admin_read.js.map +1 -0
  3337. package/dist/agent/tools/message_thread_seat.d.ts +7 -0
  3338. package/dist/agent/tools/message_thread_seat.d.ts.map +1 -0
  3339. package/dist/agent/tools/message_thread_seat.js +133 -0
  3340. package/dist/agent/tools/message_thread_seat.js.map +1 -0
  3341. package/dist/agent/tools/no_reply.d.ts +31 -0
  3342. package/dist/agent/tools/no_reply.d.ts.map +1 -0
  3343. package/dist/agent/tools/no_reply.js +251 -0
  3344. package/dist/agent/tools/no_reply.js.map +1 -0
  3345. package/dist/agent/tools/open_pull_request.d.ts +23 -0
  3346. package/dist/agent/tools/open_pull_request.d.ts.map +1 -0
  3347. package/dist/agent/tools/open_pull_request.js +323 -0
  3348. package/dist/agent/tools/open_pull_request.js.map +1 -0
  3349. package/dist/agent/tools/permission_fit_report.d.ts +63 -0
  3350. package/dist/agent/tools/permission_fit_report.d.ts.map +1 -0
  3351. package/dist/agent/tools/permission_fit_report.js +173 -0
  3352. package/dist/agent/tools/permission_fit_report.js.map +1 -0
  3353. package/dist/agent/tools/post_file.d.ts +7 -0
  3354. package/dist/agent/tools/post_file.d.ts.map +1 -0
  3355. package/dist/agent/tools/post_file.js +372 -0
  3356. package/dist/agent/tools/post_file.js.map +1 -0
  3357. package/dist/agent/tools/post_message.d.ts +32 -0
  3358. package/dist/agent/tools/post_message.d.ts.map +1 -0
  3359. package/dist/agent/tools/post_message.js +158 -0
  3360. package/dist/agent/tools/post_message.js.map +1 -0
  3361. package/dist/agent/tools/post_pr_walkthrough.d.ts +126 -0
  3362. package/dist/agent/tools/post_pr_walkthrough.d.ts.map +1 -0
  3363. package/dist/agent/tools/post_pr_walkthrough.js +200 -0
  3364. package/dist/agent/tools/post_pr_walkthrough.js.map +1 -0
  3365. package/dist/agent/tools/purge_memory.d.ts +105 -0
  3366. package/dist/agent/tools/purge_memory.d.ts.map +1 -0
  3367. package/dist/agent/tools/purge_memory.js +271 -0
  3368. package/dist/agent/tools/purge_memory.js.map +1 -0
  3369. package/dist/agent/tools/query_analytics.d.ts +59 -0
  3370. package/dist/agent/tools/query_analytics.d.ts.map +1 -0
  3371. package/dist/agent/tools/query_analytics.js +80 -0
  3372. package/dist/agent/tools/query_analytics.js.map +1 -0
  3373. package/dist/agent/tools/react.d.ts +23 -0
  3374. package/dist/agent/tools/react.d.ts.map +1 -0
  3375. package/dist/agent/tools/react.js +185 -0
  3376. package/dist/agent/tools/react.js.map +1 -0
  3377. package/dist/agent/tools/read_channel.d.ts +28 -0
  3378. package/dist/agent/tools/read_channel.d.ts.map +1 -0
  3379. package/dist/agent/tools/read_channel.js +118 -0
  3380. package/dist/agent/tools/read_channel.js.map +1 -0
  3381. package/dist/agent/tools/read_docs.d.ts +27 -0
  3382. package/dist/agent/tools/read_docs.d.ts.map +1 -0
  3383. package/dist/agent/tools/read_docs.js +43 -0
  3384. package/dist/agent/tools/read_docs.js.map +1 -0
  3385. package/dist/agent/tools/read_file_upload.d.ts +32 -0
  3386. package/dist/agent/tools/read_file_upload.d.ts.map +1 -0
  3387. package/dist/agent/tools/read_file_upload.js +175 -0
  3388. package/dist/agent/tools/read_file_upload.js.map +1 -0
  3389. package/dist/agent/tools/read_routine_transcript.d.ts +31 -0
  3390. package/dist/agent/tools/read_routine_transcript.d.ts.map +1 -0
  3391. package/dist/agent/tools/read_routine_transcript.js +79 -0
  3392. package/dist/agent/tools/read_routine_transcript.js.map +1 -0
  3393. package/dist/agent/tools/read_thread.d.ts +29 -0
  3394. package/dist/agent/tools/read_thread.d.ts.map +1 -0
  3395. package/dist/agent/tools/read_thread.js +100 -0
  3396. package/dist/agent/tools/read_thread.js.map +1 -0
  3397. package/dist/agent/tools/read_thread_seat.d.ts +7 -0
  3398. package/dist/agent/tools/read_thread_seat.d.ts.map +1 -0
  3399. package/dist/agent/tools/read_thread_seat.js +84 -0
  3400. package/dist/agent/tools/read_thread_seat.js.map +1 -0
  3401. package/dist/agent/tools/read_webhook_history.d.ts +17 -0
  3402. package/dist/agent/tools/read_webhook_history.d.ts.map +1 -0
  3403. package/dist/agent/tools/read_webhook_history.js +45 -0
  3404. package/dist/agent/tools/read_webhook_history.js.map +1 -0
  3405. package/dist/agent/tools/read_work_channel.d.ts +26 -0
  3406. package/dist/agent/tools/read_work_channel.d.ts.map +1 -0
  3407. package/dist/agent/tools/read_work_channel.js +108 -0
  3408. package/dist/agent/tools/read_work_channel.js.map +1 -0
  3409. package/dist/agent/tools/read_work_thread.d.ts +27 -0
  3410. package/dist/agent/tools/read_work_thread.d.ts.map +1 -0
  3411. package/dist/agent/tools/read_work_thread.js +89 -0
  3412. package/dist/agent/tools/read_work_thread.js.map +1 -0
  3413. package/dist/agent/tools/record_follow_up.d.ts +19 -0
  3414. package/dist/agent/tools/record_follow_up.d.ts.map +1 -0
  3415. package/dist/agent/tools/record_follow_up.js +74 -0
  3416. package/dist/agent/tools/record_follow_up.js.map +1 -0
  3417. package/dist/agent/tools/record_job_state.d.ts +15 -0
  3418. package/dist/agent/tools/record_job_state.d.ts.map +1 -0
  3419. package/dist/agent/tools/record_job_state.js +47 -0
  3420. package/dist/agent/tools/record_job_state.js.map +1 -0
  3421. package/dist/agent/tools/record_watch_state.d.ts +15 -0
  3422. package/dist/agent/tools/record_watch_state.d.ts.map +1 -0
  3423. package/dist/agent/tools/record_watch_state.js +45 -0
  3424. package/dist/agent/tools/record_watch_state.js.map +1 -0
  3425. package/dist/agent/tools/remove_routine_rule.d.ts +32 -0
  3426. package/dist/agent/tools/remove_routine_rule.d.ts.map +1 -0
  3427. package/dist/agent/tools/remove_routine_rule.js +142 -0
  3428. package/dist/agent/tools/remove_routine_rule.js.map +1 -0
  3429. package/dist/agent/tools/reply.d.ts +73 -0
  3430. package/dist/agent/tools/reply.d.ts.map +1 -0
  3431. package/dist/agent/tools/reply.js +664 -0
  3432. package/dist/agent/tools/reply.js.map +1 -0
  3433. package/dist/agent/tools/report_run_failed.d.ts +17 -0
  3434. package/dist/agent/tools/report_run_failed.d.ts.map +1 -0
  3435. package/dist/agent/tools/report_run_failed.js +71 -0
  3436. package/dist/agent/tools/report_run_failed.js.map +1 -0
  3437. package/dist/agent/tools/request_access.d.ts +118 -0
  3438. package/dist/agent/tools/request_access.d.ts.map +1 -0
  3439. package/dist/agent/tools/request_access.js +408 -0
  3440. package/dist/agent/tools/request_access.js.map +1 -0
  3441. package/dist/agent/tools/request_credential_grant.d.ts +101 -0
  3442. package/dist/agent/tools/request_credential_grant.d.ts.map +1 -0
  3443. package/dist/agent/tools/request_credential_grant.js +525 -0
  3444. package/dist/agent/tools/request_credential_grant.js.map +1 -0
  3445. package/dist/agent/tools/resume.d.ts +27 -0
  3446. package/dist/agent/tools/resume.d.ts.map +1 -0
  3447. package/dist/agent/tools/resume.js +137 -0
  3448. package/dist/agent/tools/resume.js.map +1 -0
  3449. package/dist/agent/tools/revoke_connector.d.ts +52 -0
  3450. package/dist/agent/tools/revoke_connector.d.ts.map +1 -0
  3451. package/dist/agent/tools/revoke_connector.js +129 -0
  3452. package/dist/agent/tools/revoke_connector.js.map +1 -0
  3453. package/dist/agent/tools/revoke_credential_grant.d.ts +12 -0
  3454. package/dist/agent/tools/revoke_credential_grant.d.ts.map +1 -0
  3455. package/dist/agent/tools/revoke_credential_grant.js +97 -0
  3456. package/dist/agent/tools/revoke_credential_grant.js.map +1 -0
  3457. package/dist/agent/tools/revoke_routine_permissions.d.ts +21 -0
  3458. package/dist/agent/tools/revoke_routine_permissions.d.ts.map +1 -0
  3459. package/dist/agent/tools/revoke_routine_permissions.js +72 -0
  3460. package/dist/agent/tools/revoke_routine_permissions.js.map +1 -0
  3461. package/dist/agent/tools/rotate_webhook.d.ts +37 -0
  3462. package/dist/agent/tools/rotate_webhook.d.ts.map +1 -0
  3463. package/dist/agent/tools/rotate_webhook.js +170 -0
  3464. package/dist/agent/tools/rotate_webhook.js.map +1 -0
  3465. package/dist/agent/tools/run_routine_now.d.ts +23 -0
  3466. package/dist/agent/tools/run_routine_now.d.ts.map +1 -0
  3467. package/dist/agent/tools/run_routine_now.js +106 -0
  3468. package/dist/agent/tools/run_routine_now.js.map +1 -0
  3469. package/dist/agent/tools/sandbox_tools.d.ts +11 -0
  3470. package/dist/agent/tools/sandbox_tools.d.ts.map +1 -0
  3471. package/dist/agent/tools/sandbox_tools.js +75 -0
  3472. package/dist/agent/tools/sandbox_tools.js.map +1 -0
  3473. package/dist/agent/tools/search.d.ts +65 -0
  3474. package/dist/agent/tools/search.d.ts.map +1 -0
  3475. package/dist/agent/tools/search.js +114 -0
  3476. package/dist/agent/tools/search.js.map +1 -0
  3477. package/dist/agent/tools/session_cost.d.ts +39 -0
  3478. package/dist/agent/tools/session_cost.d.ts.map +1 -0
  3479. package/dist/agent/tools/session_cost.js +124 -0
  3480. package/dist/agent/tools/session_cost.js.map +1 -0
  3481. package/dist/agent/tools/set_dm_delivery.d.ts +23 -0
  3482. package/dist/agent/tools/set_dm_delivery.d.ts.map +1 -0
  3483. package/dist/agent/tools/set_dm_delivery.js +106 -0
  3484. package/dist/agent/tools/set_dm_delivery.js.map +1 -0
  3485. package/dist/agent/tools/set_spend_limit.d.ts +156 -0
  3486. package/dist/agent/tools/set_spend_limit.d.ts.map +1 -0
  3487. package/dist/agent/tools/set_spend_limit.js +437 -0
  3488. package/dist/agent/tools/set_spend_limit.js.map +1 -0
  3489. package/dist/agent/tools/set_state.d.ts +74 -0
  3490. package/dist/agent/tools/set_state.d.ts.map +1 -0
  3491. package/dist/agent/tools/set_state.js +166 -0
  3492. package/dist/agent/tools/set_state.js.map +1 -0
  3493. package/dist/agent/tools/spawn_thread_session.d.ts +9 -0
  3494. package/dist/agent/tools/spawn_thread_session.d.ts.map +1 -0
  3495. package/dist/agent/tools/spawn_thread_session.js +204 -0
  3496. package/dist/agent/tools/spawn_thread_session.js.map +1 -0
  3497. package/dist/agent/tools/spend_report.d.ts +180 -0
  3498. package/dist/agent/tools/spend_report.d.ts.map +1 -0
  3499. package/dist/agent/tools/spend_report.js +372 -0
  3500. package/dist/agent/tools/spend_report.js.map +1 -0
  3501. package/dist/agent/tools/stand_down.d.ts +91 -0
  3502. package/dist/agent/tools/stand_down.d.ts.map +1 -0
  3503. package/dist/agent/tools/stand_down.js +245 -0
  3504. package/dist/agent/tools/stand_down.js.map +1 -0
  3505. package/dist/agent/tools/subscribe_pr.d.ts +104 -0
  3506. package/dist/agent/tools/subscribe_pr.d.ts.map +1 -0
  3507. package/dist/agent/tools/subscribe_pr.js +213 -0
  3508. package/dist/agent/tools/subscribe_pr.js.map +1 -0
  3509. package/dist/agent/tools/unlink_identity.d.ts +19 -0
  3510. package/dist/agent/tools/unlink_identity.d.ts.map +1 -0
  3511. package/dist/agent/tools/unlink_identity.js +97 -0
  3512. package/dist/agent/tools/unlink_identity.js.map +1 -0
  3513. package/dist/agent/tools/update_status.d.ts +17 -0
  3514. package/dist/agent/tools/update_status.d.ts.map +1 -0
  3515. package/dist/agent/tools/update_status.js +59 -0
  3516. package/dist/agent/tools/update_status.js.map +1 -0
  3517. package/dist/agent/tools/usage_report.d.ts +59 -0
  3518. package/dist/agent/tools/usage_report.d.ts.map +1 -0
  3519. package/dist/agent/tools/usage_report.js +91 -0
  3520. package/dist/agent/tools/usage_report.js.map +1 -0
  3521. package/dist/agent/tools/walk_pr.d.ts +79 -0
  3522. package/dist/agent/tools/walk_pr.d.ts.map +1 -0
  3523. package/dist/agent/tools/walk_pr.js +133 -0
  3524. package/dist/agent/tools/walk_pr.js.map +1 -0
  3525. package/dist/agent/webhooks/achievability.d.ts +80 -0
  3526. package/dist/agent/webhooks/achievability.d.ts.map +1 -0
  3527. package/dist/agent/webhooks/achievability.js +216 -0
  3528. package/dist/agent/webhooks/achievability.js.map +1 -0
  3529. package/dist/agent/webhooks/capture-window.d.ts +86 -0
  3530. package/dist/agent/webhooks/capture-window.d.ts.map +1 -0
  3531. package/dist/agent/webhooks/capture-window.js +194 -0
  3532. package/dist/agent/webhooks/capture-window.js.map +1 -0
  3533. package/dist/agent/webhooks/config.d.ts +326 -0
  3534. package/dist/agent/webhooks/config.d.ts.map +1 -0
  3535. package/dist/agent/webhooks/config.js +280 -0
  3536. package/dist/agent/webhooks/config.js.map +1 -0
  3537. package/dist/agent/webhooks/dispatch.d.ts +103 -0
  3538. package/dist/agent/webhooks/dispatch.d.ts.map +1 -0
  3539. package/dist/agent/webhooks/dispatch.js +358 -0
  3540. package/dist/agent/webhooks/dispatch.js.map +1 -0
  3541. package/dist/agent/webhooks/gate.d.ts +128 -0
  3542. package/dist/agent/webhooks/gate.d.ts.map +1 -0
  3543. package/dist/agent/webhooks/gate.js +296 -0
  3544. package/dist/agent/webhooks/gate.js.map +1 -0
  3545. package/dist/agent/webhooks/handshake-capture.d.ts +66 -0
  3546. package/dist/agent/webhooks/handshake-capture.d.ts.map +1 -0
  3547. package/dist/agent/webhooks/handshake-capture.js +126 -0
  3548. package/dist/agent/webhooks/handshake-capture.js.map +1 -0
  3549. package/dist/agent/webhooks/hooks-codemod.d.ts +73 -0
  3550. package/dist/agent/webhooks/hooks-codemod.d.ts.map +1 -0
  3551. package/dist/agent/webhooks/hooks-codemod.js +231 -0
  3552. package/dist/agent/webhooks/hooks-codemod.js.map +1 -0
  3553. package/dist/agent/webhooks/oe-standard-webhook.d.ts +153 -0
  3554. package/dist/agent/webhooks/oe-standard-webhook.d.ts.map +1 -0
  3555. package/dist/agent/webhooks/oe-standard-webhook.js +498 -0
  3556. package/dist/agent/webhooks/oe-standard-webhook.js.map +1 -0
  3557. package/dist/agent/webhooks/reject-audit.d.ts +40 -0
  3558. package/dist/agent/webhooks/reject-audit.d.ts.map +1 -0
  3559. package/dist/agent/webhooks/reject-audit.js +99 -0
  3560. package/dist/agent/webhooks/reject-audit.js.map +1 -0
  3561. package/dist/agent/webhooks/replay-dedupe.d.ts +58 -0
  3562. package/dist/agent/webhooks/replay-dedupe.d.ts.map +1 -0
  3563. package/dist/agent/webhooks/replay-dedupe.js +159 -0
  3564. package/dist/agent/webhooks/replay-dedupe.js.map +1 -0
  3565. package/dist/agent/webhooks/reveal-page.d.ts +116 -0
  3566. package/dist/agent/webhooks/reveal-page.d.ts.map +1 -0
  3567. package/dist/agent/webhooks/reveal-page.js +443 -0
  3568. package/dist/agent/webhooks/reveal-page.js.map +1 -0
  3569. package/dist/agent/webhooks/secrets.d.ts +17 -0
  3570. package/dist/agent/webhooks/secrets.d.ts.map +1 -0
  3571. package/dist/agent/webhooks/secrets.js +73 -0
  3572. package/dist/agent/webhooks/secrets.js.map +1 -0
  3573. package/dist/agent/webhooks/source-vocabulary.d.ts +131 -0
  3574. package/dist/agent/webhooks/source-vocabulary.d.ts.map +1 -0
  3575. package/dist/agent/webhooks/source-vocabulary.js +315 -0
  3576. package/dist/agent/webhooks/source-vocabulary.js.map +1 -0
  3577. package/dist/agent/webhooks/verifier.d.ts +251 -0
  3578. package/dist/agent/webhooks/verifier.d.ts.map +1 -0
  3579. package/dist/agent/webhooks/verifier.js +109 -0
  3580. package/dist/agent/webhooks/verifier.js.map +1 -0
  3581. package/dist/scripts/operator-store-connect.d.ts +86 -0
  3582. package/dist/scripts/operator-store-connect.d.ts.map +1 -0
  3583. package/dist/scripts/operator-store-connect.js +218 -0
  3584. package/dist/scripts/operator-store-connect.js.map +1 -0
  3585. package/package.json +3397 -0
  3586. package/patches/eve+0.54.3.patch +129 -0
  3587. package/scripts/eve-framework-tools.ts +367 -0
  3588. package/scripts/oe-cli.ts +293 -0
  3589. package/scripts/oe-secret.ts +278 -0
  3590. package/scripts/oe-wrap-untrusted.ts +63 -0
  3591. package/scripts/operator-store-connect.ts +246 -0
  3592. package/templates/subagents/fresh_eyes_review/agent.ts +37 -0
  3593. package/templates/subagents/fresh_eyes_review/hooks/spend.ts +16 -0
  3594. package/templates/subagents/fresh_eyes_review/instructions.md +52 -0
  3595. package/templates/subagents/fresh_eyes_review/tools/ask_question.ts +13 -0
  3596. package/templates/subagents/fresh_eyes_review/tools/bash.ts +13 -0
  3597. package/templates/subagents/fresh_eyes_review/tools/connection_search.ts +52 -0
  3598. package/templates/subagents/fresh_eyes_review/tools/load_skill.ts +13 -0
  3599. package/templates/subagents/fresh_eyes_review/tools/read_file.ts +13 -0
  3600. package/templates/subagents/fresh_eyes_review/tools/task_cancel.ts +20 -0
  3601. package/templates/subagents/fresh_eyes_review/tools/todo.ts +13 -0
  3602. package/templates/subagents/fresh_eyes_review/tools/web_fetch.ts +13 -0
  3603. package/templates/subagents/fresh_eyes_review/tools/web_search.ts +13 -0
  3604. package/templates/subagents/fresh_eyes_review/tools/write_file.ts +13 -0
  3605. package/tsconfig.build.json +24 -0
  3606. package/tsconfig.json +15 -0
@@ -0,0 +1,4052 @@
1
+ // The Postgres half of the OperationalStore seam, over the same small PgClient port the memory store uses; sqlite.ts is the twin and the schema is ported from it verbatim. Every query filters by org_id.
2
+ // The append-only tables (audit_entry, usage_events, domain_skill_revisions, routine_prompt_revisions) carry FORCE ROW LEVEL SECURITY, which denies UPDATE and DELETE to the table owner too — AS DML ONLY. The owner can still DROP POLICY, and on the default single-role deploy the app IS the owner, so the two-role split is what closes that escape (docs/extending/database.md). A mutable table keys its policy on the `app.current_org` GUC and PERMITS when that is unset, because a non-owner runtime role must serve before per-request GUC wiring exists; the load-bearing isolation is the org_id filter on every query either way.
3
+ // audit_entry carries that same GUC predicate (OPE-1812), so it is append-only AND org-keyed; the other three append-only tables stay GUC-free (`USING (true)`). The load-bearing isolation for the audit log is the REQUIRED org at the store boundary — readAudit refuses a read that names none (store.ts auditReadOrg) — because nothing in the shipped runtime sets the GUC.
4
+ // A value import, not a type-only one: the assertions and the retention ceilings are ONE definition shared with the sqlite twin, so a bound cannot drift between two hand-copied SQL statements.
5
+ import { asSurfaceMode, auditSurfaceMode, auditReadOrg, likePrefixPattern, assertIngressDeliveryRetainUntil, assertSpendLimitAmount, assertDomainModelPick, assertHaltAddress, haltAddressColumns, haltAddressFromColumns, framePromoterId, promoterListField, proactiveAddressRow, routinePromptRevisionWrites, spendLedgerConjuncts, CAPTURE_MAX_RETENTION_MS, EVENT_DEDUPE_MAX_RETENTION_MS, PROMOTER_LIST_MAX } from "./store.js";
6
+ import { grantBorrowColumnsProblem, grantFrozenArgsDigest, grantJsonColumn, grantJsonFromColumn, grantRefundTurnOrdinal } from "./credential-grant-rows.js";
7
+ import { CONNECTOR_OP_KIND_PREFIX, ROUTINE_PERMISSION_PREFIX } from "../approvals/session-grant.js";
8
+ import { SESSION_TAIL_MAX_ENTRIES } from "../channels/session-tail.js";
9
+ import { AsyncLocalStorage } from "node:async_hooks";
10
+ import { createHash } from "node:crypto";
11
+ import { AUDIT_CHAIN_EPOCH_ACTION, auditEpochDetail, auditEpochSealFor, auditRowSha, withOrgAuditLock } from "../audit/chain.js";
12
+ import { deploymentOrg } from "../identity/deployment-identity.js";
13
+ import { assembleAnalyticsSql } from "../analytics/compile.js";
14
+ export { setOrgContext } from "../memory/postgres.js";
15
+ // The GUC-keyed org predicate for MUTABLE tables' RLS: enforce when app.current_org is
16
+ // set, permit when unset/empty (see the header — a non-owner runtime role must be able
17
+ // to serve before per-request GUC wiring exists; the load-bearing isolation is the
18
+ // org_id filter on every query either way). NULLIF folds an empty-string GUC (a RESET
19
+ // artefact) into "unset".
20
+ const ORG_GUC = `(org_id = current_setting('app.current_org', true)
21
+ OR NULLIF(current_setting('app.current_org', true), '') IS NULL)`;
22
+ /**
23
+ * Does a deparsed policy expression carry the ORG_GUC predicate? {@link EXPECTED_POLICIES} tests the
24
+ * audit policies with this instead of an exact string, so an audit policy that drifts off the GUC
25
+ * predicate is a verifyAppendOnlyAudit violation rather than a silent widening.
26
+ *
27
+ * 🔴 A SHAPE TEST, NOT THE DEPARSED TEXT, AND THE REASON IS FAIL-CLOSED BOOT. `pg_get_expr` returns
28
+ * the server's own rendering, which on PGlite 18.3 is
29
+ * `((org_id = current_setting('app.current_org'::text, true)) OR (NULLIF(current_setting(
30
+ * 'app.current_org'::text, true), ''::text) IS NULL))` — measured, not guessed. Pinning that string
31
+ * would make a one-byte deparse difference on another server version (production runs Neon, a
32
+ * different major) throw "posture STILL failing after apply" on EVERY boot. The parts this tests —
33
+ * the column, the GUC read, and the NULLIF arm that makes it permit-when-unset — are names, not
34
+ * formatting, so they survive a reformat. `true` carries none of them, which is the case that must
35
+ * stay a violation: it is the widening this predicate replaced.
36
+ */
37
+ function isOrgGucExpr(expr) {
38
+ return (expr !== null &&
39
+ /\borg_id\b/.test(expr) &&
40
+ /current_setting\(\s*'app\.current_org'(::text)?\s*,\s*true\s*\)/i.test(expr) &&
41
+ /\bNULLIF\s*\(/i.test(expr));
42
+ }
43
+ const SCHEMA_STATEMENTS = [
44
+ // The drop guard exists because CREATE TABLE IF NOT EXISTS would silently keep an old-shape spend_ledger and every insert would then fail. The probe is usd_micros_measured, the column no pre-OPE-369 table can have, and the statement runs only in owner mode - initOperationalSchema skips all DDL as a non-owner.
45
+ `DO $$ BEGIN
46
+ IF to_regclass('public.spend_ledger') IS NOT NULL AND NOT EXISTS (
47
+ SELECT 1 FROM information_schema.columns
48
+ WHERE table_schema = 'public' AND table_name = 'spend_ledger' AND column_name = 'usd_micros_measured'
49
+ ) THEN
50
+ EXECUTE 'DROP TABLE spend_ledger';
51
+ END IF;
52
+ END $$`,
53
+ `CREATE TABLE IF NOT EXISTS spend_ledger (
54
+ org_id text NOT NULL,
55
+ surface_key text NOT NULL,
56
+ principal_id text NOT NULL DEFAULT '', -- '' = unattributed (PK columns can't be NULL)
57
+ routine_id text NOT NULL DEFAULT '', -- '' = not a routine turn
58
+ model text NOT NULL DEFAULT '', -- '' = no model (sandbox runtime); '(unknown)' = an unattributed model call
59
+ period text NOT NULL,
60
+ -- OPE-1862 (mirrored in the ALTER list below): WHICH KIND OF CONVERSATION this row's spend
61
+ -- happened in — 'dm' | 'mpim' | 'channel', or '' when nothing stamped it. The anti-doxxing
62
+ -- mask reads THIS and never the shape of a surface id, so Discord and Teams DMs mask exactly
63
+ -- as Slack's do. OUTSIDE the primary key: a surface's mode never changes, so keying on it
64
+ -- would split a month for nothing.
65
+ surface_mode text NOT NULL DEFAULT '',
66
+ input_tokens bigint NOT NULL DEFAULT 0,
67
+ output_tokens bigint NOT NULL DEFAULT 0,
68
+ cache_read_tokens bigint NOT NULL DEFAULT 0,
69
+ cache_write_tokens bigint NOT NULL DEFAULT 0,
70
+ -- OPE-1611 (mirrored in the ALTER list below): reasoning tokens, ATTRIBUTION only. No rate
71
+ -- table names a reasoning rate, so this never reaches usd_micros and no cap sees it.
72
+ reasoning_tokens bigint NOT NULL DEFAULT 0,
73
+ usd_micros bigint NOT NULL DEFAULT 0, -- millionths of a dollar, DERIVED at write from the rate table (what caps sum)
74
+ -- OPE-369: the GATEWAY's own billed figure for these same calls, when it published one.
75
+ -- 0 on a cost_source='derived' row. Never read by a cap — see store.ts's CostSource section.
76
+ usd_micros_measured bigint NOT NULL DEFAULT 0,
77
+ cost_source text NOT NULL DEFAULT 'derived', -- 'measured' | 'derived'; in the PK so a row is homogeneous
78
+ calls bigint NOT NULL DEFAULT 0,
79
+ PRIMARY KEY (org_id, surface_key, principal_id, routine_id, model, period, cost_source)
80
+ )`,
81
+ // period is the SIXTH primary-key column and a btree bounds a scan only up to the first unconstrained column, so the primary key bounds a period-ranged read on org_id alone; measured, the planner takes a Seq Scan that touches every org's rows instead. Like every statement in this list this is also the migration: it builds in place on an owner-mode boot, and a two-role deployment gets it when the owner role runs the schema step.
82
+ `CREATE INDEX IF NOT EXISTS spend_ledger_org_period ON spend_ledger (org_id, period)`,
83
+ `CREATE TABLE IF NOT EXISTS routine (
84
+ org_id text NOT NULL,
85
+ id text NOT NULL,
86
+ surface_key text NOT NULL,
87
+ data text NOT NULL,
88
+ PRIMARY KEY (org_id, id)
89
+ )`,
90
+ // routine_prompt_revisions is the append-only prompt history behind the mutable routine row above, with the same DB-enforced posture as audit_entry. See the RoutinePromptRevisionRow doc comment in store.ts for why a prompt history is an audit artefact, why the log begins at the first edit, and for the retention position.
91
+ `CREATE TABLE IF NOT EXISTS routine_prompt_revisions (
92
+ seq bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
93
+ org_id text NOT NULL,
94
+ surface_key text NOT NULL,
95
+ routine_id text NOT NULL,
96
+ prompt text NOT NULL,
97
+ generation integer,
98
+ authored_by text,
99
+ armed_by text,
100
+ approval_id text,
101
+ recorded_at text NOT NULL
102
+ )`,
103
+ `CREATE INDEX IF NOT EXISTS routine_prompt_revisions_org_surface_routine ON routine_prompt_revisions (org_id, surface_key, routine_id, seq)`,
104
+ `CREATE TABLE IF NOT EXISTS audit_entry (
105
+ seq bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
106
+ ts text NOT NULL,
107
+ org_id text NOT NULL,
108
+ platform text NOT NULL,
109
+ workspace text NOT NULL,
110
+ surface text,
111
+ surface_mode text, -- OPE-1866: the conversation the surface names; NULL = unclassified, which MASKS
112
+ principal_id text,
113
+ action text NOT NULL,
114
+ detail text,
115
+ prev_sha text -- sha256 of the org's previous row (OPE-52 hash chain); NULL = genesis
116
+ )`,
117
+ `CREATE INDEX IF NOT EXISTS audit_org_ts ON audit_entry (org_id, ts)`,
118
+ `CREATE TABLE IF NOT EXISTS spend_limit (
119
+ org_id text NOT NULL,
120
+ scope_key text NOT NULL,
121
+ level text NOT NULL, -- "surface" | "workspace" | "domain" | "user" (free-text, no CHECK — see store.ts CapLevel)
122
+ monthly_tokens bigint NOT NULL, -- -1 = no token component (matches the SQLite encoding)
123
+ monthly_usd double precision, -- NULL = no USD component
124
+ expires_at bigint, -- epoch ms; NULL = no auto-expiry
125
+ reason text,
126
+ set_by text,
127
+ PRIMARY KEY (org_id, scope_key, level)
128
+ )`,
129
+ // THE BREAK-GLASS HALT (OPE-1602). Same columns and same encodings as the SQLite adapter — the
130
+ // filler/marker rule is documented once, at store.ts `haltAddressColumns`.
131
+ `CREATE TABLE IF NOT EXISTS halt (
132
+ org_id text NOT NULL,
133
+ level text NOT NULL, -- "" on an org-wide row: FILLER, never an address
134
+ scope_key text NOT NULL, -- "" on an org-wide row, same reason
135
+ org_wide boolean NOT NULL, -- true = the org-wide MARKER; the column every match branches on first
136
+ active boolean NOT NULL, -- true = halted; a cleared row stays for the trail
137
+ set_by text,
138
+ set_at text NOT NULL, -- ISO-8601
139
+ set_ref text, -- host wake owning a chat-set halt; NULL for operator/legacy rows
140
+ cleared_by text,
141
+ cleared_at text, -- ISO-8601; NULL until a resume clears it
142
+ PRIMARY KEY (org_id, level, scope_key, org_wide)
143
+ )`,
144
+ `CREATE TABLE IF NOT EXISTS connector_override (
145
+ org_id text NOT NULL,
146
+ scope_key text NOT NULL,
147
+ connector text NOT NULL,
148
+ granted boolean NOT NULL,
149
+ reason text, -- no expires_at: auto-expiry would re-open access
150
+ set_by text,
151
+ PRIMARY KEY (org_id, scope_key, connector)
152
+ )`,
153
+ `CREATE TABLE IF NOT EXISTS thread_engagement (
154
+ org_id text NOT NULL,
155
+ surface_key text NOT NULL,
156
+ thread_ts text NOT NULL,
157
+ engaged_at text NOT NULL,
158
+ last_turn_at text NOT NULL,
159
+ participating boolean NOT NULL DEFAULT false, -- true = invited participant; false = warm watcher
160
+ silent_streak integer NOT NULL DEFAULT 0, -- consecutive silent woken turns since last engage/participation
161
+ stopped boolean NOT NULL DEFAULT false, -- true = an explicit stop landed (task #100 window path); suppress non-mention wakes until re-invited
162
+ engaged_by text, -- SEPARATOR-FRAMED list of the ids of events that PROMOTED this row, most recent last, bounded; a re-promotion from ANY id the list holds never clears stopped (store.ts PROMOTER_SEP)
163
+ PRIMARY KEY (org_id, surface_key, thread_ts)
164
+ )`,
165
+ // channel_session: the live channel-supervisor session pointer per (org, surface_key) —
166
+ // Slack Claude-Tag-parity T1.1. ONE row per surface (rotation replaces it wholesale, see
167
+ // the ChannelSessionRow doc comment in store.ts) — read-write like thread_engagement,
168
+ // NOT append-only.
169
+ `CREATE TABLE IF NOT EXISTS channel_session (
170
+ org_id text NOT NULL,
171
+ surface_key text NOT NULL,
172
+ token text NOT NULL,
173
+ generation integer NOT NULL,
174
+ created_at text NOT NULL,
175
+ last_wake_at text NOT NULL,
176
+ turn_count integer NOT NULL DEFAULT 0,
177
+ input_tokens_total bigint, -- measured cumulative input+cacheRead for this generation (§2 #551); NULL = unknown ⇒ rotate
178
+ first_wake_at text, -- ISO-8601 of the first delivered wake (H7c); NULL = none yet ⇒ still fresh
179
+ last_input_tokens bigint, -- OPE-794: measured input+cacheRead of the LATEST request (SET, not summed); NULL = none yet ⇒ rung skipped
180
+ rotate_marked_at text, -- OPE-820: ISO-8601 an operator marked this generation for retirement; NULL = unmarked. Set ONLY by the ops sweep; cleared by every rotation
181
+ served_code_fingerprint text, -- OPE-1821: the runtime CODE hash this seat was last served with; NULL = never stamped. Written ONLY by stampChannelSessionRuntime, and deliberately NOT reset by a rotation
182
+ served_domain_fingerprint text, -- OPE-1821: the DOMAIN declaration hash this seat was last served with. Same writer, same NULL meaning — the pair moves together
183
+ PRIMARY KEY (org_id, surface_key)
184
+ )`,
185
+ // session_tail (OPE-794): the standing-seat TAIL ring — one row per recorded conversational
186
+ // event on ONE generation (a delivered wake message, or a post the seat made). The rotate leg
187
+ // reads the OUTGOING generation's rows and renders them into the fresh generation's first wake.
188
+ // Keyed by the generation's live TOKEN, so a straggler write from a retired generation files
189
+ // under the retired token and is never read again. Read-write and self-pruning like
190
+ // event_dedupe; bounded on write, and dropped once its tail has been carried forward.
191
+ `CREATE TABLE IF NOT EXISTS session_tail (
192
+ org_id text NOT NULL,
193
+ surface_key text NOT NULL,
194
+ token text NOT NULL,
195
+ seq bigint NOT NULL,
196
+ at text NOT NULL,
197
+ entry_json text NOT NULL,
198
+ PRIMARY KEY (org_id, surface_key, token, seq)
199
+ )`,
200
+ `CREATE TABLE IF NOT EXISTS event_dedupe (
201
+ org_id text NOT NULL,
202
+ key text NOT NULL,
203
+ seen_at text NOT NULL,
204
+ PRIMARY KEY (org_id, key)
205
+ )`,
206
+ // Durable provider inbox. The verified signer id is part of the immutable delivery identity;
207
+ // payload_json is versioned by its provider but never contains a raw signature or secret.
208
+ // Pending rows have retain_until NULL and survive arbitrary outages. Completion erases the
209
+ // payload and starts the bounded tombstone clock in the same fenced UPDATE.
210
+ `CREATE TABLE IF NOT EXISTS ingress_delivery (
211
+ org_id text NOT NULL,
212
+ source text NOT NULL,
213
+ authority_id text NOT NULL,
214
+ delivery_id text NOT NULL,
215
+ payload_json text,
216
+ received_at text NOT NULL,
217
+ available_at text NOT NULL,
218
+ claim_id text,
219
+ claimed_at text,
220
+ completed_at text,
221
+ retain_until text,
222
+ PRIMARY KEY (org_id, source, authority_id, delivery_id)
223
+ )`,
224
+ `CREATE INDEX IF NOT EXISTS ingress_delivery_due ON ingress_delivery (org_id, source, completed_at, available_at, claimed_at)`,
225
+ // webhook_capture: the BOUNDED CAPTURE WINDOW (OPE-211 + OPE-184 Half 2). The only table in this
226
+ // schema holding bytes an outside party authored — `document` is the jq FILTER DOCUMENT, not the
227
+ // raw body (webhooks/capture-window.ts explains why that distinction is the safety property and
228
+ // not a convenience). Read-write and self-pruning like event_dedupe; never UPDATEd, which is why
229
+ // its grant is a narrow SELECT/INSERT/DELETE of its own rather than a place in the blanket list.
230
+ `CREATE TABLE IF NOT EXISTS webhook_capture (
231
+ org_id text NOT NULL,
232
+ source text NOT NULL,
233
+ seq integer NOT NULL,
234
+ captured_at text NOT NULL,
235
+ document text NOT NULL,
236
+ PRIMARY KEY (org_id, source, seq)
237
+ )`,
238
+ // unified_wake_target: the single-window wakeId → replyTarget map (channels/unified-window.ts).
239
+ // Read-write like event_dedupe (a routing map with TTL prune, not an append-only record).
240
+ `CREATE TABLE IF NOT EXISTS unified_wake_target (
241
+ org_id text NOT NULL,
242
+ wake_id text NOT NULL,
243
+ target_json text NOT NULL,
244
+ created_at text NOT NULL,
245
+ window_token text,
246
+ answered_at text,
247
+ answered_turn_id text,
248
+ inbound boolean,
249
+ audited_at text,
250
+ PRIMARY KEY (org_id, wake_id)
251
+ )`,
252
+ // thread_ownership: the async-spawn (org, channelKey, threadKey) → taskToken index the ingress
253
+ // router consults (channels/thread-ownership.ts, §S2). Read-write like unified_wake_target (a
254
+ // TTL-pruned routing map) but WITH a real clear — complete_thread + generation/idle GC delete rows.
255
+ `CREATE TABLE IF NOT EXISTS thread_ownership (
256
+ org_id text NOT NULL,
257
+ channel_key text NOT NULL,
258
+ thread_key text NOT NULL,
259
+ task_token text NOT NULL,
260
+ created_at text NOT NULL,
261
+ PRIMARY KEY (org_id, channel_key, thread_key)
262
+ )`,
263
+ // thread_seat_state: one THREAD SEAT's durable record (OPE-1696) — the seat token, the parent seat
264
+ // it reports to, open/completed, and its closing report. Read by `read_thread_seat`, never by the
265
+ // ingress router: ROUTING stays on thread_ownership, which is cleared at hand-back while this row
266
+ // survives so a coordinator can still read what came back.
267
+ `CREATE TABLE IF NOT EXISTS thread_seat_state (
268
+ org_id text NOT NULL,
269
+ channel_key text NOT NULL,
270
+ thread_key text NOT NULL,
271
+ seat_token text NOT NULL,
272
+ parent_key text NOT NULL,
273
+ state text NOT NULL,
274
+ origin_json text NOT NULL,
275
+ report text,
276
+ opened_at text NOT NULL,
277
+ updated_at text NOT NULL,
278
+ PRIMARY KEY (org_id, channel_key, thread_key)
279
+ )`,
280
+ // turn_anchor: the (org, windowKey) → {sessionId, turnId} index an INGRESS route consults to
281
+ // cancel an in-flight turn pre-dispatch (OPE-418; hooks/turn-anchor.ts writes it, the ingress
282
+ // stop path reads it). Read-write with a real clear, like thread_ownership; SHORT TTL.
283
+ `CREATE TABLE IF NOT EXISTS turn_anchor (
284
+ org_id text NOT NULL,
285
+ window_key text NOT NULL,
286
+ anchor_key text,
287
+ channel_key text,
288
+ session_id text NOT NULL,
289
+ turn_id text NOT NULL,
290
+ surface_key text NOT NULL,
291
+ created_at text NOT NULL,
292
+ PRIMARY KEY (org_id, window_key)
293
+ )`,
294
+ // task_result: an org-scoped, TTL-pruned, OPAQUE key-value scratch table. The name is historical —
295
+ // see the store interface's own note: it was minted for the deleted roll-own delegation regime and
296
+ // is now shared by the native-subagent taint markers, the question bridge and the task-wake join,
297
+ // each under its own key prefix. Read-write like unified_wake_target, no explicit clear.
298
+ `CREATE TABLE IF NOT EXISTS task_result (
299
+ org_id text NOT NULL,
300
+ task_id text NOT NULL,
301
+ result_json text NOT NULL,
302
+ created_at text NOT NULL,
303
+ PRIMARY KEY (org_id, task_id)
304
+ )`,
305
+ // slack_attachment: the DURABLE, cross-process file-id → url_private index the delegated-worker
306
+ // upload-read path turns on (channels/slack-attachments.ts; describe_image + read_file_upload).
307
+ // Read-write like unified_wake_target (a TTL-pruned routing map), no explicit clear. Written only
308
+ // from the trusted Slack event parse; the bytes are never stored, only the short-lived url + meta.
309
+ `CREATE TABLE IF NOT EXISTS slack_attachment (
310
+ org_id text NOT NULL,
311
+ file_id text NOT NULL,
312
+ url_private text NOT NULL,
313
+ mime_type text,
314
+ name text,
315
+ team_id text,
316
+ created_at text NOT NULL,
317
+ PRIMARY KEY (org_id, file_id)
318
+ )`,
319
+ // stored_credential (task #113): the ciphertext store behind the `db` credential broker
320
+ // (agent/credentials/db-broker.ts). `ciphertext` is an AES-256-GCM envelope, opaque here — this
321
+ // table NEVER holds plaintext. Read-write (a re-store under the same ref replaces the envelope),
322
+ // org-isolated by RLS. The bytes are the secret; connector/domain are labels only. Mirrors the
323
+ // slack_attachment shape (org-scoped mutable routing/lookup table).
324
+ `CREATE TABLE IF NOT EXISTS stored_credential (
325
+ org_id text NOT NULL,
326
+ ref text NOT NULL,
327
+ ciphertext text NOT NULL,
328
+ connector text,
329
+ domain text,
330
+ created_by text NOT NULL,
331
+ created_at text NOT NULL,
332
+ PRIMARY KEY (org_id, ref)
333
+ )`,
334
+ // credential_intake (task #113): the durable, single-use, TTL'd binding a "Set API key" button
335
+ // carries (agent/credentials/intake.ts). Read-write; the ONE unused→used transition is CAS-guarded
336
+ // at the query layer (consumeCredentialIntake's `WHERE used_at IS NULL`), like pending_actions.
337
+ // NEVER carries the secret value — only the ref/connector/domain labels + the requester who may
338
+ // complete it.
339
+ `CREATE TABLE IF NOT EXISTS credential_intake (
340
+ org_id text NOT NULL,
341
+ id text NOT NULL,
342
+ ref text NOT NULL,
343
+ connector text NOT NULL,
344
+ domain text,
345
+ requested_by text NOT NULL,
346
+ channel_id text NOT NULL,
347
+ thread_ts text,
348
+ created_at text NOT NULL,
349
+ expires_at text NOT NULL,
350
+ used_at text,
351
+ PRIMARY KEY (org_id, id)
352
+ )`,
353
+ // webhook_capture_window (OPE-211, re-homed by OPE-224): the ONLY mutable state a declared webhook
354
+ // has — when its capture window closes, and who opened it. Keyed by (org_id, hook_id) because a
355
+ // hook id is unique WITHIN an org's config, unlike the deleted chat-created class's ids which were
356
+ // globally-unique URL segments. Nothing here is secret, nothing here is authority: the hook's
357
+ // identity, posture and read grant are all re-read from the config registry at arm and delivery
358
+ // time, so this row can never become a second place a hook is defined.
359
+ `CREATE TABLE IF NOT EXISTS webhook_capture_window (
360
+ org_id text NOT NULL,
361
+ hook_id text NOT NULL,
362
+ capture_until text NOT NULL,
363
+ armed_by text NOT NULL,
364
+ armed_at text NOT NULL,
365
+ PRIMARY KEY (org_id, hook_id)
366
+ )`,
367
+ // github_installation (scm/installations.ts): owner → installation id, learned from the App's own
368
+ // signature-verified `installation` webhook so a new org installing the App self-registers instead
369
+ // of needing an OE_GITHUB_INSTALLATIONS env edit + redeploy. NOT a secret (an installation id is a
370
+ // public routing number; the App private key stays in env). Read-write with a real clear (an
371
+ // uninstall/suspend delivery revokes); NOT TTL-pruned — an installation is durable until GitHub says
372
+ // otherwise. The env map composes OVER these rows, so env stays authoritative.
373
+ `CREATE TABLE IF NOT EXISTS github_installation (
374
+ org_id text NOT NULL,
375
+ owner text NOT NULL,
376
+ installation_id text NOT NULL,
377
+ account_type text,
378
+ repository_selection text,
379
+ updated_at text NOT NULL,
380
+ PRIMARY KEY (org_id, owner)
381
+ )`,
382
+ // pr_session_approval (OPE-53): the "Approve for session" grant on a pr.open card. Read-write,
383
+ // keyed by the bare session/window token (its generation makes the memo die with the session).
384
+ // Written in the webhook process (the click), read in the eve workflow process (the next
385
+ // pr.open propose). Scoped to kind="pr.open" by the callers; NEVER carries PR content.
386
+ `CREATE TABLE IF NOT EXISTS pr_session_approval (
387
+ org_id text NOT NULL,
388
+ session_id text NOT NULL,
389
+ kind text NOT NULL,
390
+ granted_by text NOT NULL,
391
+ created_at text NOT NULL,
392
+ expires_at text NOT NULL,
393
+ PRIMARY KEY (org_id, session_id, kind)
394
+ )`,
395
+ // pending_actions: the in-Slack admin-approvals durable state (agent/approvals/*).
396
+ // Read-write like spend_limit/connector_override (NOT append-only like audit_entry) —
397
+ // but its one pending→decided transition is CAS-guarded at the query layer
398
+ // (decidePendingAction's `WHERE status = 'pending'`), not by RLS.
399
+ `CREATE TABLE IF NOT EXISTS pending_actions (
400
+ org_id text NOT NULL,
401
+ id text NOT NULL,
402
+ kind text NOT NULL,
403
+ args_json text NOT NULL,
404
+ scope_key text NOT NULL,
405
+ domain text,
406
+ requested_by text NOT NULL,
407
+ channel_id text NOT NULL,
408
+ thread_ts text,
409
+ message_ts text,
410
+ posted_to text,
411
+ status text NOT NULL,
412
+ created_at text NOT NULL,
413
+ expires_at text NOT NULL,
414
+ decided_by text,
415
+ decided_at text,
416
+ PRIMARY KEY (org_id, id)
417
+ )`,
418
+ `CREATE INDEX IF NOT EXISTS pending_actions_org_status ON pending_actions (org_id, status)`,
419
+ `CREATE TABLE IF NOT EXISTS domain_skill (
420
+ org_id text NOT NULL,
421
+ domain text NOT NULL,
422
+ name text NOT NULL,
423
+ content text NOT NULL,
424
+ updated_by text,
425
+ updated_at text NOT NULL,
426
+ PRIMARY KEY (org_id, domain, name)
427
+ )`,
428
+ // domain_skill_revisions (OPE-237): the APPEND-ONLY content history behind the mutable
429
+ // domain_skill row above. Same DB-enforced posture as audit_entry/usage_events — see the
430
+ // DomainSkillRevisionRow doc comment in store.ts for why a domain skill's history is an
431
+ // audit artefact rather than ordinary versioning, and for the retention position (never
432
+ // pruned; bounded by human approval clicks, not by traffic).
433
+ `CREATE TABLE IF NOT EXISTS domain_skill_revisions (
434
+ seq bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
435
+ org_id text NOT NULL,
436
+ domain text NOT NULL,
437
+ name text NOT NULL,
438
+ content text NOT NULL,
439
+ authored_by text,
440
+ armed_by text,
441
+ approval_id text,
442
+ recorded_at text NOT NULL
443
+ )`,
444
+ `CREATE INDEX IF NOT EXISTS domain_skill_revisions_org_domain_name ON domain_skill_revisions (org_id, domain, name, seq)`,
445
+ // domain_model: a domain's runtime model/reasoning pick (the DB-overlay half of the
446
+ // model-policy envelope, model/policy.ts) — read-write like domain_skill (a domain
447
+ // OWNS its pick, no expiresAt/auto-revert), NOT append-only.
448
+ `CREATE TABLE IF NOT EXISTS domain_model (
449
+ org_id text NOT NULL,
450
+ domain text NOT NULL,
451
+ model_id text,
452
+ reasoning text,
453
+ set_by text,
454
+ updated_at text NOT NULL,
455
+ PRIMARY KEY (org_id, domain)
456
+ )`,
457
+ // usage_events: append-only per-model-call ledger (session/user cost + analytics).
458
+ // Deliberately NO "IF NOT EXISTS" migration for pruning here — see the RLS note
459
+ // below: this table gets SELECT+INSERT-only policies, same as audit_entry, so
460
+ // pruneUsageEvents is a documented no-op under Postgres (sqlite prunes for real).
461
+ `CREATE TABLE IF NOT EXISTS usage_events (
462
+ seq bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
463
+ org_id text NOT NULL,
464
+ surface_key text NOT NULL,
465
+ session_id text NOT NULL,
466
+ principal_id text,
467
+ ts text NOT NULL,
468
+ kind text,
469
+ routine_id text,
470
+ input_tokens bigint NOT NULL DEFAULT 0,
471
+ output_tokens bigint NOT NULL DEFAULT 0,
472
+ cache_read_tokens bigint NOT NULL DEFAULT 0,
473
+ cache_write_tokens bigint NOT NULL DEFAULT 0,
474
+ model text,
475
+ detail text,
476
+ -- OPE-1611 (mirrored in the ALTER list below): the two attribution dimensions the cache/
477
+ -- reasoning question needs. Both NULLABLE on purpose — NULL is "the source reported nothing",
478
+ -- which is a different fact from a reported zero, and that difference is the whole ticket.
479
+ -- OPE-1862 (mirrored in the ALTER list below): the conversation this event happened in —
480
+ -- 'dm' | 'mpim' | 'channel'; NULL = unstamped. The kind column above cannot answer this: a routine,
481
+ -- supervisor or subagent turn wins that tag before the DM test runs, so a routine fired in a
482
+ -- DM reads kind 'routine'. Reports mask an unstamped row rather than guess.
483
+ surface_mode text,
484
+ cache_tokens_reported boolean, -- true = the call reported a cache split; false = it did not; NULL = never asked
485
+ reasoning_tokens bigint, -- NULL = unreported; a number (0 included) = reported
486
+ -- OPE-369 (mirrored in the ALTER list below, which is what an existing DB takes)
487
+ usd_micros_measured bigint, -- the gateway's billed figure for THIS call; NULL = nothing measured it
488
+ cost_source text, -- 'measured' | 'derived'; NULL on pre-migration/non-model rows
489
+ delegation_depth integer, -- 0 = root turn, 1 = direct child, 2 = two-or-more hops (a BAND — see store.ts)
490
+ root_session_id text -- top of this call's delegation chain (its own session id on a root turn)
491
+ )`,
492
+ `CREATE INDEX IF NOT EXISTS usage_events_org_session ON usage_events (org_id, session_id)`,
493
+ `CREATE INDEX IF NOT EXISTS usage_events_org_surface_ts ON usage_events (org_id, surface_key, ts)`,
494
+ // The three identity link tables are read-write like domain_skill, with the history in audit_entry that identity/link-store.ts appends on every mutation; nothing else writes here. handle is DISPLAY ONLY and carries no index and no uniqueness: a name/handle/email join is the attacker-controllable merge the fail-closed-on-merge doctrine forbids, so sets join on id and accounts join on (platform, native_id).
495
+ `CREATE TABLE IF NOT EXISTS identity_link_sets (
496
+ org_id text NOT NULL,
497
+ id text NOT NULL,
498
+ handle text NOT NULL, -- DISPLAY ONLY: admin lists + audit rows, never a lookup key
499
+ status text NOT NULL, -- "active" | "suspended" | "revoked" ("revoked" is terminal)
500
+ created_at text NOT NULL,
501
+ updated_at text NOT NULL,
502
+ PRIMARY KEY (org_id, id)
503
+ )`,
504
+ // The primary key IS the 'an account is exactly one person' invariant - the write API checks it too, but this is the half a racing second writer cannot lose. tenant is in the key because a tenant-scoped platform (slack) issues a person id PER WORKSPACE, so the older 3-column key made two workspaces' members one row; it is '' for every vendor-global platform, and identity/link-tenant.ts owns the value space.
505
+ `CREATE TABLE IF NOT EXISTS identity_linked_ids (
506
+ org_id text NOT NULL,
507
+ platform text NOT NULL,
508
+ tenant text NOT NULL DEFAULT '', -- '' = vendor-global platform, or not yet backfilled
509
+ native_id text NOT NULL,
510
+ link_set_id text NOT NULL,
511
+ status text NOT NULL, -- "suggested" | "confirmed" | "revoked" ("revoked" is terminal)
512
+ established_by text NOT NULL, -- "challenge:<id>" | "config-import" | "directory-sync:<provider>"
513
+ evidence text, -- the structured evidence record as JSON; opaque here
514
+ created_at text NOT NULL,
515
+ updated_at text NOT NULL,
516
+ PRIMARY KEY (org_id, platform, tenant, native_id)
517
+ )`,
518
+ `CREATE INDEX IF NOT EXISTS identity_linked_ids_org_set ON identity_linked_ids (org_id, link_set_id)`,
519
+ // identity_link_challenges: the proof-of-control nonce ledger. `nonce_hash` is a sha-256 — the
520
+ // RAW code is never stored, so a database copy yields no usable codes. Single-use is the
521
+ // pending-only claim CAS (claimLinkChallenge), not a boolean anyone has to remember to flip.
522
+ `CREATE TABLE IF NOT EXISTS identity_link_challenges (
523
+ org_id text NOT NULL,
524
+ id text NOT NULL,
525
+ nonce_hash text NOT NULL, -- sha-256 hex of the uppercased code; NEVER the code
526
+ initiating_platform text NOT NULL,
527
+ initiating_tenant text NOT NULL DEFAULT '', -- OPE-309 phase 2; '' off a tenant-scoped platform
528
+ initiating_native_id text NOT NULL,
529
+ initiating_surface_key text NOT NULL, -- the DM the ratification must come back to
530
+ claimed_platform text, -- stamped from the WAKE's own captured author
531
+ claimed_tenant text, -- …in the same CAS, so a claimed row names a whole account
532
+ claimed_native_id text,
533
+ claimed_at text,
534
+ transport text NOT NULL DEFAULT 'code', -- OPE-617; code | directory
535
+ target_platform text, -- the directory transport's NAMED target …
536
+ target_tenant text, -- …matched inside the consent CAS, so a consent
537
+ target_native_id text, -- …from any other account matches no row
538
+ back_nonce_hash text, -- sha-256 of code-2; its PRESENCE forces the code-back
539
+ status text NOT NULL, -- pending | claimed | ratified | denied | expired
540
+ created_at text NOT NULL,
541
+ expires_at text NOT NULL,
542
+ decided_at text,
543
+ PRIMARY KEY (org_id, id)
544
+ )`,
545
+ `CREATE INDEX IF NOT EXISTS identity_link_challenges_org_nonce ON identity_link_challenges (org_id, nonce_hash)`,
546
+ // credential_grant_ask (OPE-1060): one person's REQUEST for another person's credential, pending
547
+ // the owner's answer in their own DM. `purpose` is MODEL-AUTHORED and stored as data — every reader
548
+ // renders it escaped and quoted. Single-answer is the pending-only approve CAS, not a flag.
549
+ `CREATE TABLE IF NOT EXISTS credential_grant_ask (
550
+ org_id text NOT NULL,
551
+ id text NOT NULL,
552
+ requester_principal_id text NOT NULL,
553
+ owner_principal_id text NOT NULL,
554
+ owner_slug text NOT NULL, -- the eventual tool name's owner segment, PINNED here
555
+ owner_platform text NOT NULL, -- where the owner's card is delivered
556
+ owner_native_id text NOT NULL, -- the bare platform id the DM arm addresses
557
+ connector text NOT NULL,
558
+ verb text NOT NULL, -- the vendor tool SLUGIFIED, as a name segment; a label, never the wire name
559
+ resource text NOT NULL, -- the host-composed DISPLAY LABEL, holding model-authored text and the frozen VALUES
560
+ mcp_tool text, -- OPE-1136: the vendor MCP tool, in the vendor's exact bytes
561
+ frozen_args text, -- OPE-1136: canonical JSON; '{}' is "nothing frozen", NULL is "no borrow"
562
+ tool_name text, -- OPE-1136: the full mounted name, PINNED here with the ordinal
563
+ scope_key text NOT NULL, -- the CHAT this would serve (the session id)
564
+ domain_scope_key text, -- OPE-1950: the room's domain-shaped seat key; a STANDING grant binds here instead
565
+ purpose text NOT NULL, -- model-authored; untrusted content
566
+ requester_target text, -- JSON ReplyTarget: where the owner's answer is reported back
567
+ card_surface_id text, -- where the owner's card landed -- the lapse sweep rewrites it
568
+ card_message_id text,
569
+ requested_mode text NOT NULL, -- once | session | standing
570
+ status text NOT NULL, -- pending | approved | declined | expired
571
+ created_at text NOT NULL,
572
+ expires_at text NOT NULL, -- the ASK's own short TTL, NOT the grant's
573
+ decided_at text,
574
+ grant_id text, -- stamped by the approve CAS
575
+ PRIMARY KEY (org_id, id)
576
+ )`,
577
+ `CREATE INDEX IF NOT EXISTS credential_grant_ask_org_scope ON credential_grant_ask (org_id, scope_key)`,
578
+ // credential_grant (OPE-1060): the owner-approved grant a chat spends. `tier` is decided ONCE at
579
+ // mint — from the verb definition on the registry path, from `classifyConnectorOpTier` on the
580
+ // OPE-1136 borrow path — and is never re-derived from the mounted tool name (a `grant__…` name
581
+ // carries a person's handle where a classifier looks for a verb).
582
+ // Rows are NEVER deleted: the mount projects every row for a scope and the broker refuses on state,
583
+ // so a removed row would make a tool vanish mid-plan instead of refusing.
584
+ // 🔴 NO UNIQUE INDEX ON (org_id, scope_key, tool_name), deliberately — the same call the sqlite
585
+ // schema states: the ordinal holds uniqueness inside a chat, the mount-side dedupe closes the
586
+ // compose race, and a write-refusing constraint waits for a writer it can be proven against.
587
+ `CREATE TABLE IF NOT EXISTS credential_grant (
588
+ org_id text NOT NULL,
589
+ id text NOT NULL,
590
+ ask_id text NOT NULL,
591
+ requester_principal_id text NOT NULL,
592
+ owner_principal_id text NOT NULL,
593
+ owner_slug text NOT NULL, -- the mounted name's owner segment, PINNED at mint
594
+ connector text NOT NULL,
595
+ verb text NOT NULL,
596
+ resource text NOT NULL,
597
+ mcp_tool text, -- OPE-1136: the vendor MCP tool, in the vendor's exact bytes
598
+ frozen_args text, -- OPE-1136: canonical JSON; '{}' is "nothing frozen", NULL is "no borrow"
599
+ tool_name text, -- OPE-1136: the full mounted name, copied from the ask
600
+ input_schema text, -- OPE-1136: the post-bake schema snapshot, taken at approve
601
+ scope_key text NOT NULL,
602
+ mode text NOT NULL, -- once | session | standing
603
+ tier text NOT NULL, -- read | write | destructive, pinned at mint
604
+ status text NOT NULL, -- active | used | revoked | expired
605
+ purpose text NOT NULL, -- model-authored; untrusted content
606
+ created_at text NOT NULL,
607
+ expires_at text NOT NULL,
608
+ used_at text,
609
+ revoked_at text,
610
+ refund_turn text, -- OPE-1264: the turn key the refund count below belongs to
611
+ refund_turn_seq bigint, -- OPE-1281: that key's eve turn ordinal; only a LATER one rolls the count
612
+ refund_count integer NOT NULL DEFAULT 0, -- OPE-1264: refunds already claimed on that turn
613
+ PRIMARY KEY (org_id, id)
614
+ )`,
615
+ `CREATE INDEX IF NOT EXISTS credential_grant_org_scope ON credential_grant (org_id, scope_key)`,
616
+ // notice_claim: LIFETIME at-most-once claims (store.ts claimNotice) — four key families, from the
617
+ // external-room `silent` announcement pair to the GitHub reaction-feedback dedupe. NO TTL and NO
618
+ // DELETE, deliberately: the row records "this already happened", and dropping it would turn a
619
+ // once-ever announcement into a periodic one and a recorded reaction into a repeated one. Every
620
+ // family is bounded by the thing it records, never by the number of ships. Two are traffic-derived
621
+ // and grow as a constant factor of the append-only audit log the deployment already keeps —
622
+ // store.ts's own section states what bounds each. The fifth family, OPE-1751's runtime-rotation
623
+ // claim, was the one entry keyed by the (eve build, deployment) pair, so it grew by a row per ship
624
+ // per standing seat and needed the only sweep this table ever had; OPE-1821 retired both.
625
+ `CREATE TABLE IF NOT EXISTS notice_claim (
626
+ org_id text NOT NULL,
627
+ key text NOT NULL,
628
+ claimed_at text NOT NULL,
629
+ PRIMARY KEY (org_id, key)
630
+ )`,
631
+ // proactive_address (OPE-887): where this deployment may reach somebody with no live turn. UPSERTED,
632
+ // never appended — one row per (platform, kind, ref_key), re-stamped by every inbound activity, so a
633
+ // moved serviceUrl region corrects itself instead of pinning a dead address. `address` is a
634
+ // provider-shaped JSON bag core never reads inside. No TTL and no prune: an address is corrected by
635
+ // the next activity, and expiring one would trade a stale address for no address at all. See
636
+ // store.ts's PROACTIVE ADDRESSES section for the whole posture.
637
+ `CREATE TABLE IF NOT EXISTS proactive_address (
638
+ org_id text NOT NULL,
639
+ platform text NOT NULL,
640
+ kind text NOT NULL,
641
+ ref_key text NOT NULL,
642
+ tenant text NOT NULL,
643
+ address text NOT NULL,
644
+ updated_at text NOT NULL,
645
+ PRIMARY KEY (org_id, platform, kind, ref_key)
646
+ )`,
647
+ // model_call_capture (OPE-846): the soak lane's byte-exact model-call recorder. MUTABLE and
648
+ // deliberately so — the retention verb is an explicit delete-by-session, so this table takes plain
649
+ // org-isolation RLS rather than the append-only SELECT+INSERT pair `usage_events` carries. A DELETE
650
+ // that cannot delete would make the store permanent, which is the one thing store.ts's MODEL-CALL
651
+ // CAPTURE posture forbids. Written only while `soak.capture` is armed; a deployment that never arms
652
+ // it never grows a row. `body_gzip_b64` holds the composed prompt verbatim — transcript-grade at
653
+ // rest, served only over a service token, never logged.
654
+ `CREATE TABLE IF NOT EXISTS model_call_capture (
655
+ seq bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
656
+ org_id text NOT NULL,
657
+ surface_key text NOT NULL,
658
+ session_id text NOT NULL,
659
+ turn_id text NOT NULL,
660
+ step_index integer NOT NULL,
661
+ ts text NOT NULL,
662
+ model text NOT NULL,
663
+ provider text NOT NULL,
664
+ schema_version integer NOT NULL,
665
+ sha256 text NOT NULL,
666
+ body_bytes bigint NOT NULL,
667
+ body_gzip_b64 text NOT NULL,
668
+ truncated boolean NOT NULL DEFAULT false
669
+ )`,
670
+ `CREATE INDEX IF NOT EXISTS model_call_capture_org_session ON model_call_capture (org_id, session_id, seq)`,
671
+ // memory_proposal (OPE-957): the dream cycle's proposal review queue, moved off the audit log
672
+ // (store.ts's MEMORY PROPOSALS section carries the whole posture). MUTABLE, like
673
+ // model_call_capture — a store holding member text needs a real erasure path.
674
+ `CREATE TABLE IF NOT EXISTS memory_proposal (
675
+ id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
676
+ org_id text NOT NULL,
677
+ kind text NOT NULL,
678
+ scope text NOT NULL,
679
+ summary text NOT NULL,
680
+ before_text text,
681
+ after_text text,
682
+ detail_json text,
683
+ principal_id text NOT NULL,
684
+ created_at text NOT NULL
685
+ )`,
686
+ `CREATE INDEX IF NOT EXISTS memory_proposal_org ON memory_proposal (org_id, id)`,
687
+ // dm_audience (OPE-1064 tier P2): who this deployment may START a direct message with, and whether
688
+ // they have stopped it. Two nullable timestamps and no content — store.ts's DM AUDIENCE section
689
+ // carries the whole posture, including why the key is the grant's own ARN-like address.
690
+ `CREATE TABLE IF NOT EXISTS dm_audience (
691
+ org_id text NOT NULL,
692
+ address text NOT NULL,
693
+ first_dm_at text,
694
+ stopped_at text,
695
+ PRIMARY KEY (org_id, address)
696
+ )`,
697
+ // instance_meta: deployment-level KV (today just the anonymous telemetry instance
698
+ // id — observability/telemetry.ts). DELIBERATELY NOT org-partitioned — no org_id
699
+ // column, no RLS policy — because this holds facts about the DEPLOYMENT itself,
700
+ // never tenant data. One deployment can serve many orgs; the instance id must stay
701
+ // ONE value across all of them. This is the one intentional exception to every
702
+ // other table's org_id + RLS contract in this file.
703
+ `CREATE TABLE IF NOT EXISTS instance_meta (
704
+ key text PRIMARY KEY,
705
+ value text NOT NULL
706
+ )`,
707
+ // These ALTER statements migrate an older DB in place: CREATE TABLE IF NOT EXISTS leaves an existing table's columns alone. The OPE-1611 attribution columns are additive and never backfilled - spend_ledger's takes NOT NULL DEFAULT 0 so its SUM stays a plain integer, and the usage_events pair stays nullable so a row can say 'unreported' instead of claiming a zero.
708
+ `ALTER TABLE spend_ledger ADD COLUMN IF NOT EXISTS reasoning_tokens bigint NOT NULL DEFAULT 0`,
709
+ `ALTER TABLE usage_events ADD COLUMN IF NOT EXISTS cache_tokens_reported boolean`,
710
+ `ALTER TABLE usage_events ADD COLUMN IF NOT EXISTS reasoning_tokens bigint`,
711
+ // OPE-1862: the conversation mode the anti-doxxing mask reads. Additive on both tables and in
712
+ // neither primary key, so every existing row is kept. Nothing is backfilled and nothing may be:
713
+ // the mode was knowable only from the turn's binding, which no stored row carries. An unstamped
714
+ // row reads '' / NULL and every report MASKS it — fail closed.
715
+ `ALTER TABLE usage_events ADD COLUMN IF NOT EXISTS surface_mode text`,
716
+ `ALTER TABLE spend_ledger ADD COLUMN IF NOT EXISTS surface_mode text NOT NULL DEFAULT ''`,
717
+ `ALTER TABLE spend_limit ADD COLUMN IF NOT EXISTS expires_at bigint`,
718
+ `ALTER TABLE spend_limit ADD COLUMN IF NOT EXISTS reason text`,
719
+ `ALTER TABLE spend_limit ADD COLUMN IF NOT EXISTS set_by text`,
720
+ `ALTER TABLE spend_limit ADD COLUMN IF NOT EXISTS monthly_usd double precision`, // item 16: USD caps
721
+ `ALTER TABLE halt ADD COLUMN IF NOT EXISTS set_ref text`,
722
+ `ALTER TABLE connector_override ADD COLUMN IF NOT EXISTS reason text`,
723
+ `ALTER TABLE connector_override ADD COLUMN IF NOT EXISTS set_by text`,
724
+ // Warm-on-wake engagement (participating watcher + silent-streak shedding): additive
725
+ // columns on a table that predates them — mirrors the SQLite migration. The NOT NULL
726
+ // DEFAULT backfills existing rows, so a pre-migration engaged thread reads as a
727
+ // non-participating (warm) thread with a zero streak (the fail-safe reading).
728
+ `ALTER TABLE thread_engagement ADD COLUMN IF NOT EXISTS participating boolean NOT NULL DEFAULT false`,
729
+ `ALTER TABLE thread_engagement ADD COLUMN IF NOT EXISTS silent_streak integer NOT NULL DEFAULT 0`,
730
+ // Ownership routing (Slack Claude-Tag-parity T1.1): additive columns, same table,
731
+ // mirrors the SQLite migration. owner_token stays NULL until a router sets one
732
+ // (decoded to `undefined` on read); kind backfills every pre-migration row to
733
+ // "thread" via the DEFAULT (Postgres applies it to existing rows on ADD COLUMN).
734
+ `ALTER TABLE thread_engagement ADD COLUMN IF NOT EXISTS owner_token text`,
735
+ `ALTER TABLE thread_engagement ADD COLUMN IF NOT EXISTS kind text NOT NULL DEFAULT 'thread'`,
736
+ // Durable STOPPED marker (task #100 follow-up — window-riding supervisor stop): additive,
737
+ // NOT NULL DEFAULT false backfills every existing row to NOT-stopped (the safe reading — a
738
+ // stop only ever suppresses AFTER it has been written). Mirrors the SQLite migration.
739
+ `ALTER TABLE thread_engagement ADD COLUMN IF NOT EXISTS stopped boolean NOT NULL DEFAULT false`,
740
+ // Durable engage-idempotency (OPE-1527) — see the sqlite.ts migration note. Nullable, and a NULL
741
+ // reads as "no recorded promoter", which clears exactly as before.
742
+ `ALTER TABLE thread_engagement ADD COLUMN IF NOT EXISTS engaged_by text`,
743
+ // This UPDATE reframes a legacy bare engaged_by id into the one-entry list the membership test reads. The list runs with no try/catch, so the WHERE clause is what makes a second run a no-op; and it is an OPTIMISATION, never a precondition - initOperationalSchema returns early for a non-owner runtime role, so on a two-role deployment nothing here runs and markEngaged must frame the value inside its own statement.
744
+ `UPDATE thread_engagement SET engaged_by = chr(10) || engaged_by || chr(10) WHERE engaged_by IS NOT NULL AND engaged_by <> '' AND substr(engaged_by, 1, 1) <> chr(10)`,
745
+ // Cumulative-token rotation + H7c (§2, eve #551): additive, all nullable, on a table that
746
+ // predates them. input_tokens_total stays NULL on pre-migration rows ⇒ shouldRotate fails safe
747
+ // and rotates once (self-heals — the new row starts at 0). first_wake_at stays NULL.
748
+ `ALTER TABLE channel_session ADD COLUMN IF NOT EXISTS input_tokens_total bigint`,
749
+ `ALTER TABLE channel_session ADD COLUMN IF NOT EXISTS first_wake_at text`,
750
+ // OPE-794 context-size rung. NULL on pre-migration rows, and that is NOT a fail-safe rotate: the
751
+ // rung is SKIPPED on NULL (rotationTrigger), because every freshly-minted generation is NULL too
752
+ // and rotating on it would retire each new generation before its first turn.
753
+ //
754
+ // `handoff_note` is deliberately NOT dropped. OPE-794 deleted the rotation handoff note, so
755
+ // nothing reads or writes that column any more; an existing install keeps a vestigial column and
756
+ // a fresh one never grows it. A destructive DROP on a live table buys nothing.
757
+ `ALTER TABLE channel_session ADD COLUMN IF NOT EXISTS last_input_tokens bigint`,
758
+ // OPE-820 operator mark. NULL on every pre-migration row, which reads as "unmarked" — the rung
759
+ // is skipped, so the migration changes no seat's rotation behaviour on its own.
760
+ `ALTER TABLE channel_session ADD COLUMN IF NOT EXISTS rotate_marked_at text`,
761
+ // OPE-1821 runtime-rotation comparison. Additive, both nullable. NULL reads as "never stamped",
762
+ // which stampChannelSessionRuntime ADOPTS rather than rotating: a pre-migration seat keeps its
763
+ // generation on the deploy that runs this migration and rotates on the next CODE change. Rotating
764
+ // on absence would retire every standing seat at migration time, and again after every fresh mint.
765
+ `ALTER TABLE channel_session ADD COLUMN IF NOT EXISTS served_code_fingerprint text`,
766
+ `ALTER TABLE channel_session ADD COLUMN IF NOT EXISTS served_domain_fingerprint text`,
767
+ // Answerable-wake lifecycle (OPE-161): additive, all three nullable, mirrors the SQLite
768
+ // migration. Pre-migration rows keep NULL window_token ⇒ they never qualify for the PENDING arm
769
+ // of the reply fence (fail-closed), and NULL answered_at ⇒ they read as unanswered (the safe
770
+ // direction). RLS policy unchanged (unified_wake_target_org_isolation is row-scoped, FOR ALL, so
771
+ // the answered UPDATE is already permitted) and the runtime role already holds UPDATE on it.
772
+ `ALTER TABLE unified_wake_target ADD COLUMN IF NOT EXISTS window_token text`,
773
+ `ALTER TABLE unified_wake_target ADD COLUMN IF NOT EXISTS answered_at text`,
774
+ `ALTER TABLE unified_wake_target ADD COLUMN IF NOT EXISTS answered_turn_id text`,
775
+ // OPE-767: additive, nullable. A pre-migration row reads as NOT inbound, so it never appears in
776
+ // `listPendingUnifiedWakes` and can never make a reply look stale — a missed refusal, never a
777
+ // false one, which is the direction the whole freshness gate fails in.
778
+ `ALTER TABLE unified_wake_target ADD COLUMN IF NOT EXISTS inbound boolean`,
779
+ // OPE-836: additive, nullable — the turn-end wake-accounting HORIZON, mirroring the SQLite
780
+ // migration. A pre-migration row reads NULL ⇒ "not yet audited", so the first turn after the
781
+ // migration considers it once and stamps it. Only `listUnauditedUnifiedWakes` filters on this
782
+ // column, so it cannot change the reply-freshness gate or the answerable-reply fence. RLS unchanged
783
+ // (unified_wake_target_org_isolation is row-scoped, FOR ALL, so the UPDATE is already permitted)
784
+ // and the runtime role already holds UPDATE on the table.
785
+ `ALTER TABLE unified_wake_target ADD COLUMN IF NOT EXISTS audited_at text`,
786
+ // Frozen proposing-surface identity (task #105 — sweep-expiry decision feedback): additive,
787
+ // nullable, mirrors the SQLite migration. Pre-migration rows stay NULL ⇒ the TTL sweep expires
788
+ // them WITHOUT notice/wake feedback (the fail-safe reading).
789
+ `ALTER TABLE pending_actions ADD COLUMN IF NOT EXISTS posted_to text`,
790
+ // Cross-process single-flight claim (OPE-91): additive, both nullable, on stored_credential —
791
+ // mirrors the SQLite migration. The ciphertext envelope is opaque, so the CAS can't live inside it;
792
+ // the claim gets its OWN columns (a random, non-secret claim id + an ISO-8601 lease stamp). Never-
793
+ // claimed / pre-migration rows read NULL ⇒ the row is FREE (claimable), the fail-safe reading. RLS
794
+ // is unchanged (stored_credential_org_isolation is FOR ALL, so the claim UPDATE is already allowed).
795
+ `ALTER TABLE stored_credential ADD COLUMN IF NOT EXISTS claim_id text`,
796
+ `ALTER TABLE stored_credential ADD COLUMN IF NOT EXISTS claimed_at text`,
797
+ // OPE-598: `provider` → `connector` (vocabulary fix — the value was always a connector name, only
798
+ // the field name said otherwise; docs/glossary.md §6). Postgres has no `RENAME COLUMN IF EXISTS`
799
+ // (the `IF EXISTS` clause binds the TABLE, not the column), so this is guarded the same way the
800
+ // identity_linked_ids PK swap below is: inspect the columns, rename only when the OLD name is
801
+ // present and the NEW one is not — idempotent, and a no-op forever after the first run. A fresh
802
+ // CREATE TABLE above never has a `provider` column, so this only ever fires on a pre-existing DB.
803
+ `DO $$
804
+ BEGIN
805
+ IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'stored_credential' AND column_name = 'provider')
806
+ AND NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'stored_credential' AND column_name = 'connector')
807
+ THEN
808
+ ALTER TABLE stored_credential RENAME COLUMN provider TO connector;
809
+ END IF;
810
+ END
811
+ $$`,
812
+ `DO $$
813
+ BEGIN
814
+ IF EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'credential_intake' AND column_name = 'provider')
815
+ AND NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'credential_intake' AND column_name = 'connector')
816
+ THEN
817
+ ALTER TABLE credential_intake RENAME COLUMN provider TO connector;
818
+ END IF;
819
+ END
820
+ $$`,
821
+ // Audit hash chain (OPE-52, audit-wedge WS-6c): additive, nullable, mirrors the SQLite
822
+ // migration. The chain STARTS at the first row appended after this migration — pre-migration
823
+ // rows keep prev_sha NULL, so the boundary reads as a genesis (backfill-free; a later null-prev
824
+ // row after non-null rows is itself a detectable break, findChainBreak flags it). DDL runs
825
+ // owner-mode only (initOperationalSchema); the runtime role only INSERTs the column, which the
826
+ // existing SELECT+INSERT grant on audit_entry already permits — no policy/grant change needed.
827
+ `ALTER TABLE audit_entry ADD COLUMN IF NOT EXISTS prev_sha text`,
828
+ // OPE-1866: the conversation mode the anti-doxxing mask reads on the AUDIT dataset. Additive and
829
+ // nullable, on the same terms as the spend/usage pair, and the existing SELECT+INSERT grant on
830
+ // audit_entry already permits it — no policy or grant change. Nothing is backfilled: the mode was
831
+ // knowable only from the turn's binding, which no stored row carries, so a pre-migration row reads
832
+ // NULL and masks as `(unclassified)`. It sits OUTSIDE the hash prefix (agent/audit/chain.ts), so
833
+ // adding it breaks no existing chain link.
834
+ `ALTER TABLE audit_entry ADD COLUMN IF NOT EXISTS surface_mode text`,
835
+ // Per-routine cost attribution (OPE-145): additive, nullable, mirrors the SQLite migration.
836
+ // Nothing is backfilled — pre-migration `kind = 'routine'` rows honestly stay "a routine ran, we
837
+ // can't say which" (the marker that names it only ever lived in the fired session's auth). Same
838
+ // grant story as prev_sha above: DDL is owner-mode, the runtime role only INSERTs the column,
839
+ // which the existing SELECT+INSERT grant on usage_events already permits.
840
+ `ALTER TABLE usage_events ADD COLUMN IF NOT EXISTS routine_id text`,
841
+ // Measured cost + delegation lineage (OPE-369): additive, nullable, not backfilled — each
842
+ // records something only knowable AT CALL TIME (the gateway's billed figure, which cost path it
843
+ // took, the lineage eve seeded into that run), so a pre-migration row honestly reads NULL. Same
844
+ // grant story as prev_sha/routine_id above: DDL is owner-mode, and the runtime role only INSERTs
845
+ // these columns, which the existing SELECT+INSERT grant on usage_events already permits.
846
+ `ALTER TABLE usage_events ADD COLUMN IF NOT EXISTS usd_micros_measured bigint`,
847
+ `ALTER TABLE usage_events ADD COLUMN IF NOT EXISTS cost_source text`,
848
+ `ALTER TABLE usage_events ADD COLUMN IF NOT EXISTS delegation_depth integer`,
849
+ `ALTER TABLE usage_events ADD COLUMN IF NOT EXISTS root_session_id text`,
850
+ // NOT NULL DEFAULT '' backfills every existing row to the sentinel, which is correct-and-final for a vendor-global platform and 'nobody has named this yet' for a tenant-scoped one. identity/link-tenant-backfill.ts fills the latter at boot from the deployment's sole admitted tenant, or says loudly that it cannot.
851
+ `ALTER TABLE identity_linked_ids ADD COLUMN IF NOT EXISTS tenant text NOT NULL DEFAULT ''`,
852
+ `ALTER TABLE identity_link_challenges ADD COLUMN IF NOT EXISTS initiating_tenant text NOT NULL DEFAULT ''`,
853
+ `ALTER TABLE identity_link_challenges ADD COLUMN IF NOT EXISTS claimed_tenant text`,
854
+ // transport defaults to 'code', which is exactly what every pre-migration row IS - the bearer-code flow was the only one - so no backfill can be wrong.
855
+ `ALTER TABLE identity_link_challenges ADD COLUMN IF NOT EXISTS transport text NOT NULL DEFAULT 'code'`,
856
+ `ALTER TABLE identity_link_challenges ADD COLUMN IF NOT EXISTS target_platform text`,
857
+ `ALTER TABLE identity_link_challenges ADD COLUMN IF NOT EXISTS target_tenant text`,
858
+ `ALTER TABLE identity_link_challenges ADD COLUMN IF NOT EXISTS target_native_id text`,
859
+ `ALTER TABLE identity_link_challenges ADD COLUMN IF NOT EXISTS back_nonce_hash text`,
860
+ // OPE-1060 S3: where the owner's answer is reported back — a JSON ReplyTarget, pinned when the ask
861
+ // is raised. Additive and nullable; a pre-migration ask reads NULL, so its resolution notice is
862
+ // skipped rather than posted somewhere guessed.
863
+ `ALTER TABLE credential_grant_ask ADD COLUMN IF NOT EXISTS requester_target text`,
864
+ // OPE-1112: where the owner's DM card landed, so the TTL sweep can rewrite it to `expired`.
865
+ // Additive and nullable; a pre-migration ask reads NULL, so the sweep skips the rewrite rather
866
+ // than editing a guessed message.
867
+ `ALTER TABLE credential_grant_ask ADD COLUMN IF NOT EXISTS card_surface_id text`,
868
+ `ALTER TABLE credential_grant_ask ADD COLUMN IF NOT EXISTS card_message_id text`,
869
+ // OPE-1136: the borrow columns. A grant lends ONE vendor MCP tool with its arguments optionally
870
+ // frozen, so both rows carry the vendor tool name, the frozen arguments and the full mounted name;
871
+ // the grant row also carries the schema snapshot taken at approve. Additive and nullable. A
872
+ // pre-migration row reads NULL on all four, which is the honest reading: it was written by the
873
+ // verb-registry path OPE-1334 deleted, which named no vendor tool at all. Such a row is READ but
874
+ // never spendable — it refuses `no_lent_tool` at the broker and mounts nothing. NULL is NOT `{}` —
875
+ // see credential-grant-rows.ts for why the two must never collapse.
876
+ `ALTER TABLE credential_grant_ask ADD COLUMN IF NOT EXISTS mcp_tool text`,
877
+ `ALTER TABLE credential_grant_ask ADD COLUMN IF NOT EXISTS frozen_args text`,
878
+ `ALTER TABLE credential_grant_ask ADD COLUMN IF NOT EXISTS tool_name text`,
879
+ // OPE-1950: the room's DOMAIN-shaped seat key, recorded beside the session one so the mint binds a
880
+ // STANDING grant to the domain and every other mode to the session. Additive and nullable; a
881
+ // pre-migration ask reads NULL, and since OPE-2160 such an ask is offered no 30-day arm at all.
882
+ `ALTER TABLE credential_grant_ask ADD COLUMN IF NOT EXISTS domain_scope_key text`,
883
+ `ALTER TABLE credential_grant ADD COLUMN IF NOT EXISTS mcp_tool text`,
884
+ `ALTER TABLE credential_grant ADD COLUMN IF NOT EXISTS frozen_args text`,
885
+ `ALTER TABLE credential_grant ADD COLUMN IF NOT EXISTS tool_name text`,
886
+ `ALTER TABLE credential_grant ADD COLUMN IF NOT EXISTS input_schema text`,
887
+ `ALTER TABLE credential_grant ADD COLUMN IF NOT EXISTS refund_turn text`,
888
+ `ALTER TABLE credential_grant ADD COLUMN IF NOT EXISTS refund_count integer NOT NULL DEFAULT 0`,
889
+ `ALTER TABLE credential_grant ADD COLUMN IF NOT EXISTS refund_turn_seq bigint`,
890
+ // The primary-key swap has no IF NOT EXISTS form, so it inspects the existing key first: a blind DROP+ADD would rebuild the index on every cold start, and a bare ADD PRIMARY KEY errors when one is already there. It is a WIDENING, so it cannot fail on data, and it is safe to run BEFORE the tenant backfill because every row still carries tenant = '' at this point.
891
+ `DO $$
892
+ BEGIN
893
+ IF EXISTS (SELECT 1 FROM pg_class WHERE relname = 'identity_linked_ids' AND relkind = 'r')
894
+ AND NOT EXISTS (
895
+ SELECT 1
896
+ FROM pg_index i
897
+ JOIN pg_class c ON c.oid = i.indrelid
898
+ JOIN pg_attribute a ON a.attrelid = c.oid AND a.attnum = ANY(i.indkey)
899
+ WHERE c.relname = 'identity_linked_ids' AND i.indisprimary AND a.attname = 'tenant'
900
+ )
901
+ THEN
902
+ ALTER TABLE identity_linked_ids DROP CONSTRAINT IF EXISTS identity_linked_ids_pkey;
903
+ ALTER TABLE identity_linked_ids ADD CONSTRAINT identity_linked_ids_pkey PRIMARY KEY (org_id, platform, tenant, native_id);
904
+ END IF;
905
+ END
906
+ $$`,
907
+ // RLS. Spend + routine + overrides: FOR ALL (mutable). Audit + usage_events +
908
+ // domain_skill_revisions + routine_prompt_revisions: SELECT + INSERT only (append-only) AND
909
+ // FORCE — see the header
910
+ // comment for why FORCE is the load-bearing statement (it binds the table owner, which is
911
+ // what the app connects as).
912
+ `ALTER TABLE spend_ledger ENABLE ROW LEVEL SECURITY`,
913
+ `ALTER TABLE routine ENABLE ROW LEVEL SECURITY`,
914
+ `ALTER TABLE audit_entry ENABLE ROW LEVEL SECURITY`,
915
+ `ALTER TABLE spend_limit ENABLE ROW LEVEL SECURITY`,
916
+ `ALTER TABLE halt ENABLE ROW LEVEL SECURITY`,
917
+ `ALTER TABLE connector_override ENABLE ROW LEVEL SECURITY`,
918
+ `ALTER TABLE thread_engagement ENABLE ROW LEVEL SECURITY`,
919
+ `ALTER TABLE channel_session ENABLE ROW LEVEL SECURITY`,
920
+ `ALTER TABLE event_dedupe ENABLE ROW LEVEL SECURITY`,
921
+ `ALTER TABLE ingress_delivery ENABLE ROW LEVEL SECURITY`,
922
+ `ALTER TABLE session_tail ENABLE ROW LEVEL SECURITY`,
923
+ `ALTER TABLE webhook_capture ENABLE ROW LEVEL SECURITY`,
924
+ `ALTER TABLE unified_wake_target ENABLE ROW LEVEL SECURITY`,
925
+ `ALTER TABLE thread_ownership ENABLE ROW LEVEL SECURITY`,
926
+ `ALTER TABLE thread_seat_state ENABLE ROW LEVEL SECURITY`,
927
+ `ALTER TABLE turn_anchor ENABLE ROW LEVEL SECURITY`,
928
+ `ALTER TABLE task_result ENABLE ROW LEVEL SECURITY`,
929
+ `ALTER TABLE slack_attachment ENABLE ROW LEVEL SECURITY`,
930
+ `ALTER TABLE stored_credential ENABLE ROW LEVEL SECURITY`,
931
+ `ALTER TABLE credential_intake ENABLE ROW LEVEL SECURITY`,
932
+ `ALTER TABLE webhook_capture_window ENABLE ROW LEVEL SECURITY`,
933
+ `ALTER TABLE github_installation ENABLE ROW LEVEL SECURITY`,
934
+ `ALTER TABLE domain_skill ENABLE ROW LEVEL SECURITY`,
935
+ `ALTER TABLE domain_skill_revisions ENABLE ROW LEVEL SECURITY`,
936
+ `ALTER TABLE routine_prompt_revisions ENABLE ROW LEVEL SECURITY`,
937
+ `ALTER TABLE domain_model ENABLE ROW LEVEL SECURITY`,
938
+ `ALTER TABLE usage_events ENABLE ROW LEVEL SECURITY`,
939
+ `ALTER TABLE pending_actions ENABLE ROW LEVEL SECURITY`,
940
+ `ALTER TABLE pr_session_approval ENABLE ROW LEVEL SECURITY`,
941
+ `ALTER TABLE identity_link_sets ENABLE ROW LEVEL SECURITY`,
942
+ `ALTER TABLE identity_linked_ids ENABLE ROW LEVEL SECURITY`,
943
+ `ALTER TABLE identity_link_challenges ENABLE ROW LEVEL SECURITY`,
944
+ `ALTER TABLE notice_claim ENABLE ROW LEVEL SECURITY`,
945
+ `ALTER TABLE model_call_capture ENABLE ROW LEVEL SECURITY`,
946
+ `ALTER TABLE proactive_address ENABLE ROW LEVEL SECURITY`,
947
+ `ALTER TABLE memory_proposal ENABLE ROW LEVEL SECURITY`,
948
+ `ALTER TABLE credential_grant_ask ENABLE ROW LEVEL SECURITY`,
949
+ `ALTER TABLE credential_grant ENABLE ROW LEVEL SECURITY`,
950
+ `ALTER TABLE dm_audience ENABLE ROW LEVEL SECURITY`,
951
+ // FORCE the append-only tables so RLS binds the OWNER too (the default deploy connects
952
+ // as the table owner; plain ENABLE lets the owner bypass all policies). This is what makes
953
+ // "UPDATE/DELETE denied" real on the shipped single-role deploy, not just under a separate
954
+ // non-owner runtime role. Idempotent: re-running FORCE on an already-forced table is a no-op.
955
+ `ALTER TABLE audit_entry FORCE ROW LEVEL SECURITY`,
956
+ `ALTER TABLE usage_events FORCE ROW LEVEL SECURITY`,
957
+ `ALTER TABLE domain_skill_revisions FORCE ROW LEVEL SECURITY`,
958
+ `ALTER TABLE routine_prompt_revisions FORCE ROW LEVEL SECURITY`,
959
+ ];
960
+ /**
961
+ * The RLS policy span — DROP-then-CREATE for every policy, and NOTHING else. It is a list of its
962
+ * own because {@link applyPolicyStatements} must run it as ONE transaction, which the statements
963
+ * above must never join.
964
+ *
965
+ * 🔴 WHY IT IS SEPARATE. Postgres has no `CREATE POLICY IF NOT EXISTS`, so re-applying a policy
966
+ * means dropping it first. In autocommit each DROP commits on its own, and every table between the
967
+ * first DROP and its own CREATE carries RLS with NO policy. Postgres then denies SELECT and INSERT
968
+ * to every role, the owner included, because the four append-only tables also carry FORCE. A pass
969
+ * that ABORTS inside the span — a killed process, a connection error, a concurrent pass's
970
+ * `duplicate_object` — leaves the store deny-all until the next owner-mode init. Audit appends fail
971
+ * for that whole time, and agent/audit/audit.ts retries once and then DROPS the row. That is how
972
+ * `audit_entry` lost both policies on the live store on 2026-09-20 (OPE-1994). One transaction
973
+ * fixes it: a DROP and a CREATE inside one transaction are atomic, no other session ever sees the
974
+ * table policy-less, and an abort rolls the drops back.
975
+ *
976
+ * 🔴 WHY ONLY THIS SPAN. One transaction over the WHOLE array would hold ACCESS EXCLUSIVE on every
977
+ * table for the length of the apply (about 28 s measured on the live store, OPE-1993) and block the
978
+ * live app. Every statement above is `IF NOT EXISTS` or an idempotent `ALTER`, so autocommit is
979
+ * safe there.
980
+ *
981
+ * 🔴 THE INVARIANT: every `CREATE POLICY` here has its `DROP POLICY IF EXISTS` in THIS list. That
982
+ * is what makes the span self-contained, so a second pass that waits for the lock recreates from a
983
+ * clean slate instead of raising `duplicate_object` on a policy the first pass just created.
984
+ * `scripts/schema-policy-atomicity-test.ts` pins it.
985
+ */
986
+ const POLICY_STATEMENTS = [
987
+ `DROP POLICY IF EXISTS spend_org_isolation ON spend_ledger`,
988
+ `DROP POLICY IF EXISTS routine_org_isolation ON routine`,
989
+ `DROP POLICY IF EXISTS audit_select ON audit_entry`,
990
+ `DROP POLICY IF EXISTS audit_insert ON audit_entry`,
991
+ `DROP POLICY IF EXISTS spend_limit_org_isolation ON spend_limit`,
992
+ `DROP POLICY IF EXISTS halt_org_isolation ON halt`,
993
+ `DROP POLICY IF EXISTS connector_override_org_isolation ON connector_override`,
994
+ `DROP POLICY IF EXISTS thread_engagement_org_isolation ON thread_engagement`,
995
+ `DROP POLICY IF EXISTS channel_session_org_isolation ON channel_session`,
996
+ `DROP POLICY IF EXISTS event_dedupe_org_isolation ON event_dedupe`,
997
+ `DROP POLICY IF EXISTS ingress_delivery_org_isolation ON ingress_delivery`,
998
+ `DROP POLICY IF EXISTS session_tail_org_isolation ON session_tail`,
999
+ `DROP POLICY IF EXISTS webhook_capture_org_isolation ON webhook_capture`,
1000
+ `DROP POLICY IF EXISTS unified_wake_target_org_isolation ON unified_wake_target`,
1001
+ `DROP POLICY IF EXISTS thread_ownership_org_isolation ON thread_ownership`,
1002
+ `DROP POLICY IF EXISTS thread_seat_state_org_isolation ON thread_seat_state`,
1003
+ `DROP POLICY IF EXISTS turn_anchor_org_isolation ON turn_anchor`,
1004
+ `DROP POLICY IF EXISTS task_result_org_isolation ON task_result`,
1005
+ `DROP POLICY IF EXISTS slack_attachment_org_isolation ON slack_attachment`,
1006
+ `DROP POLICY IF EXISTS stored_credential_org_isolation ON stored_credential`,
1007
+ `DROP POLICY IF EXISTS credential_intake_org_isolation ON credential_intake`,
1008
+ `DROP POLICY IF EXISTS webhook_capture_window_org_isolation ON webhook_capture_window`,
1009
+ `DROP POLICY IF EXISTS github_installation_org_isolation ON github_installation`,
1010
+ `DROP POLICY IF EXISTS domain_skill_org_isolation ON domain_skill`,
1011
+ `DROP POLICY IF EXISTS domain_skill_revisions_select ON domain_skill_revisions`,
1012
+ `DROP POLICY IF EXISTS domain_skill_revisions_insert ON domain_skill_revisions`,
1013
+ `DROP POLICY IF EXISTS routine_prompt_revisions_select ON routine_prompt_revisions`,
1014
+ `DROP POLICY IF EXISTS routine_prompt_revisions_insert ON routine_prompt_revisions`,
1015
+ `DROP POLICY IF EXISTS domain_model_org_isolation ON domain_model`,
1016
+ `DROP POLICY IF EXISTS usage_events_select ON usage_events`,
1017
+ `DROP POLICY IF EXISTS usage_events_insert ON usage_events`,
1018
+ `DROP POLICY IF EXISTS pending_actions_org_isolation ON pending_actions`,
1019
+ `DROP POLICY IF EXISTS pr_session_approval_org_isolation ON pr_session_approval`,
1020
+ `DROP POLICY IF EXISTS identity_link_sets_org_isolation ON identity_link_sets`,
1021
+ `DROP POLICY IF EXISTS identity_linked_ids_org_isolation ON identity_linked_ids`,
1022
+ `DROP POLICY IF EXISTS identity_link_challenges_org_isolation ON identity_link_challenges`,
1023
+ `DROP POLICY IF EXISTS notice_claim_org_isolation ON notice_claim`,
1024
+ `DROP POLICY IF EXISTS model_call_capture_org_isolation ON model_call_capture`,
1025
+ `DROP POLICY IF EXISTS proactive_address_org_isolation ON proactive_address`,
1026
+ `DROP POLICY IF EXISTS memory_proposal_org_isolation ON memory_proposal`,
1027
+ `DROP POLICY IF EXISTS credential_grant_ask_org_isolation ON credential_grant_ask`,
1028
+ `DROP POLICY IF EXISTS credential_grant_org_isolation ON credential_grant`,
1029
+ `DROP POLICY IF EXISTS dm_audience_org_isolation ON dm_audience`,
1030
+ `CREATE POLICY spend_org_isolation ON spend_ledger
1031
+ USING ${ORG_GUC}
1032
+ WITH CHECK ${ORG_GUC}`,
1033
+ `CREATE POLICY routine_org_isolation ON routine
1034
+ USING ${ORG_GUC}
1035
+ WITH CHECK ${ORG_GUC}`,
1036
+ // audit_entry: append-only AND org-keyed (OPE-1812). Append-only is the SHAPE of this pair —
1037
+ // SELECT and INSERT policies only, no UPDATE/DELETE policy, so those two verbs are denied under
1038
+ // FORCE for every non-superuser role, the owner included. That part is unchanged and does not
1039
+ // depend on the GUC.
1040
+ //
1041
+ // The org predicate is the same ORG_GUC the mutable tables carry, for the same reason and with
1042
+ // the same bound: it ENFORCES where a deployment sets app.current_org and PERMITS where the GUC
1043
+ // is unset. These policies read `USING (true)`, which said the database would hand any session
1044
+ // every tenant's audit rows; the permit-when-unset predicate says it plainly instead, and it
1045
+ // narrows for free on any deployment that wires the GUC. 🔴 NOTHING IN THE SHIPPED RUNTIME SETS
1046
+ // THAT GUC (setOrgContext has no non-test caller), so this is a latent second layer and NOT the
1047
+ // control today: the control is the REQUIRED org at the store boundary — readAudit refuses a
1048
+ // read without one (store.ts auditReadOrg) and appendAudit writes the row's own org. Do not cite
1049
+ // this policy as the log's tenancy on a deployment that sets no GUC.
1050
+ //
1051
+ // 🔴 A DEPLOYMENT THAT SETS THE GUC NARROWS THE CROSS-ORG READS TOO: listAuditOrgs() and the
1052
+ // chain verifier (scripts/verify-audit-chain.ts) walk every org, and under a set GUC they see
1053
+ // one. Set it per request, never once per process, or run those on a session that leaves it unset.
1054
+ //
1055
+ // 🔴 THE UPGRADE WRITES ONE audit.integrity ROW, AND IT IS THE MIGRATION, NOT TAMPERING. An
1056
+ // existing store carries the old `USING (true)` pair, which no longer matches EXPECTED_POLICIES.
1057
+ // The first OWNER-mode boot therefore counts it as a violation, healUnexpectedArtifacts DROPs
1058
+ // both policies as unexpected, the re-apply recreates them, and the boot logs the repair and
1059
+ // records ONE audit.integrity row naming audit_entry.audit_select and audit_entry.audit_insert.
1060
+ // That row is this repository's evidence-of-tampering signal, so an incident responder reading
1061
+ // the chain must be able to tell this one apart: it is the upgrade to OPE-1812, it names exactly
1062
+ // those two policies, and it sits at the first boot on the new code.
1063
+ // 🔴 ON A TWO-ROLE DEPLOYMENT, RUN THE OWNER BOOT FIRST. The runtime role cannot heal: it records
1064
+ // the same row and THROWS (see initOperationalSchema's `owner === false` branch), so an app tier
1065
+ // that reaches the new code before the owner boot refuses to start.
1066
+ `CREATE POLICY audit_select ON audit_entry FOR SELECT USING ${ORG_GUC}`,
1067
+ `CREATE POLICY audit_insert ON audit_entry FOR INSERT WITH CHECK ${ORG_GUC}`,
1068
+ `CREATE POLICY spend_limit_org_isolation ON spend_limit
1069
+ USING ${ORG_GUC}
1070
+ WITH CHECK ${ORG_GUC}`,
1071
+ `CREATE POLICY halt_org_isolation ON halt
1072
+ USING ${ORG_GUC}
1073
+ WITH CHECK ${ORG_GUC}`,
1074
+ `CREATE POLICY connector_override_org_isolation ON connector_override
1075
+ USING ${ORG_GUC}
1076
+ WITH CHECK ${ORG_GUC}`,
1077
+ `CREATE POLICY thread_engagement_org_isolation ON thread_engagement
1078
+ USING ${ORG_GUC}
1079
+ WITH CHECK ${ORG_GUC}`,
1080
+ `CREATE POLICY channel_session_org_isolation ON channel_session
1081
+ USING ${ORG_GUC}
1082
+ WITH CHECK ${ORG_GUC}`,
1083
+ `CREATE POLICY event_dedupe_org_isolation ON event_dedupe
1084
+ USING ${ORG_GUC}
1085
+ WITH CHECK ${ORG_GUC}`,
1086
+ `CREATE POLICY ingress_delivery_org_isolation ON ingress_delivery
1087
+ USING ${ORG_GUC}
1088
+ WITH CHECK ${ORG_GUC}`,
1089
+ `CREATE POLICY session_tail_org_isolation ON session_tail
1090
+ USING ${ORG_GUC}
1091
+ WITH CHECK ${ORG_GUC}`,
1092
+ // webhook_capture holds third-party payload projections and takes the same enforce-when-set / permit-when-unset arm as every other mutable table. Under the single-role deploy the GUC is unwired and this policy permits, so the load-bearing isolation is the org_id filter on all four of its statements - stated here because on THIS table over-reading what RLS buys would be the expensive kind of wrong.
1093
+ `CREATE POLICY webhook_capture_org_isolation ON webhook_capture
1094
+ USING ${ORG_GUC}
1095
+ WITH CHECK ${ORG_GUC}`,
1096
+ `CREATE POLICY unified_wake_target_org_isolation ON unified_wake_target
1097
+ USING ${ORG_GUC}
1098
+ WITH CHECK ${ORG_GUC}`,
1099
+ `CREATE POLICY thread_ownership_org_isolation ON thread_ownership
1100
+ USING ${ORG_GUC}
1101
+ WITH CHECK ${ORG_GUC}`,
1102
+ // thread_seat_state is read-write like thread_ownership (a TTL-pruned per-thread row with an
1103
+ // explicit rewrite at hand-back) — same ENFORCE-WHEN-SET / PERMIT-WHEN-UNSET GUC arm. It holds a
1104
+ // thread seat's own REPORT TEXT, so the policy is the fence between one tenant's report and
1105
+ // another tenant's reader.
1106
+ `CREATE POLICY thread_seat_state_org_isolation ON thread_seat_state
1107
+ USING ${ORG_GUC}
1108
+ WITH CHECK ${ORG_GUC}`,
1109
+ // turn_anchor is read-write like thread_ownership (a short-TTL routing map with a real clear) —
1110
+ // same ENFORCE-WHEN-SET / PERMIT-WHEN-UNSET GUC arm as the other mutable tables. 🔴 THE POLICY IS
1111
+ // THE ONLY THING BETWEEN A CANCEL AND ANOTHER TENANT'S TURN: the ingress stop path resolves an
1112
+ // anchor by a channel/message key an outside party controls the shape of, so a missing policy
1113
+ // here would fail SILENTLY as a cross-org cancel, not as an error.
1114
+ `CREATE POLICY turn_anchor_org_isolation ON turn_anchor
1115
+ USING ${ORG_GUC}
1116
+ WITH CHECK ${ORG_GUC}`,
1117
+ `CREATE POLICY task_result_org_isolation ON task_result
1118
+ USING ${ORG_GUC}
1119
+ WITH CHECK ${ORG_GUC}`,
1120
+ `CREATE POLICY slack_attachment_org_isolation ON slack_attachment
1121
+ USING ${ORG_GUC}
1122
+ WITH CHECK ${ORG_GUC}`,
1123
+ `CREATE POLICY stored_credential_org_isolation ON stored_credential
1124
+ USING ${ORG_GUC}
1125
+ WITH CHECK ${ORG_GUC}`,
1126
+ `CREATE POLICY credential_intake_org_isolation ON credential_intake
1127
+ USING ${ORG_GUC}
1128
+ WITH CHECK ${ORG_GUC}`,
1129
+ // Every lookup of a capture window already knows its org, because a window is only ever reached through a hook this deployment's config declares rather than through a bare URL segment. So unlike a URL-addressed table this one needs no cross-org caveat.
1130
+ `CREATE POLICY webhook_capture_window_org_isolation ON webhook_capture_window
1131
+ USING ${ORG_GUC}
1132
+ WITH CHECK ${ORG_GUC}`,
1133
+ `CREATE POLICY github_installation_org_isolation ON github_installation
1134
+ USING ${ORG_GUC}
1135
+ WITH CHECK ${ORG_GUC}`,
1136
+ `CREATE POLICY domain_skill_org_isolation ON domain_skill
1137
+ USING ${ORG_GUC}
1138
+ WITH CHECK ${ORG_GUC}`,
1139
+ // domain_skill_revisions is append-only on the same GUC-free terms as audit_entry: SELECT and INSERT policies only under FORCE, so UPDATE and DELETE are denied to every non-superuser role, the owner included. No retention path is given up here, because nothing was ever going to prune it.
1140
+ `CREATE POLICY domain_skill_revisions_select ON domain_skill_revisions FOR SELECT USING (true)`,
1141
+ `CREATE POLICY domain_skill_revisions_insert ON domain_skill_revisions FOR INSERT WITH CHECK (true)`,
1142
+ // routine_prompt_revisions is append-only on the same GUC-free terms. The denial does more work here than on any other table: the runtime role holds full CRUD on routine itself, so whoever holds the app's credential can already rewrite what fires unattended - what they must not be able to rewrite is the record of the text a human armed.
1143
+ `CREATE POLICY routine_prompt_revisions_select ON routine_prompt_revisions FOR SELECT USING (true)`,
1144
+ `CREATE POLICY routine_prompt_revisions_insert ON routine_prompt_revisions FOR INSERT WITH CHECK (true)`,
1145
+ `CREATE POLICY domain_model_org_isolation ON domain_model
1146
+ USING ${ORG_GUC}
1147
+ WITH CHECK ${ORG_GUC}`,
1148
+ // usage_events is append-only at the DB layer: SELECT and INSERT policies only under FORCE, so UPDATE and DELETE are denied to every non-superuser role including the owner. That is the cost of the trade - pruneUsageEvents is a documented no-op under Postgres, and real retention needs a maintenance path outside the app role.
1149
+ `CREATE POLICY usage_events_select ON usage_events FOR SELECT USING (true)`,
1150
+ `CREATE POLICY usage_events_insert ON usage_events FOR INSERT WITH CHECK (true)`,
1151
+ // pending_actions is read-write (mutable, FOR ALL) like spend_limit/connector_override —
1152
+ // the CAS guarantee lives in the query (WHERE status='pending'), not in RLS.
1153
+ `CREATE POLICY pending_actions_org_isolation ON pending_actions
1154
+ USING ${ORG_GUC}
1155
+ WITH CHECK ${ORG_GUC}`,
1156
+ `CREATE POLICY pr_session_approval_org_isolation ON pr_session_approval
1157
+ USING ${ORG_GUC}
1158
+ WITH CHECK ${ORG_GUC}`,
1159
+ // The three identity link tables are read-write like domain_skill — same ENFORCE-WHEN-SET /
1160
+ // PERMIT-WHEN-UNSET GUC arm as every other mutable table. NOT append-only: a link-set is state
1161
+ // a person severs and an admin suspends, so it needs real UPDATE/DELETE. What must not be
1162
+ // rewritable is the RECORD of who linked what and on whose evidence, and that lives in
1163
+ // `audit_entry` (DB-enforced append-only), which identity/link-store.ts writes on every
1164
+ // mutation — the same split domain_skill ⇄ domain_skill_revisions makes.
1165
+ `CREATE POLICY identity_link_sets_org_isolation ON identity_link_sets
1166
+ USING ${ORG_GUC}
1167
+ WITH CHECK ${ORG_GUC}`,
1168
+ `CREATE POLICY identity_linked_ids_org_isolation ON identity_linked_ids
1169
+ USING ${ORG_GUC}
1170
+ WITH CHECK ${ORG_GUC}`,
1171
+ `CREATE POLICY identity_link_challenges_org_isolation ON identity_link_challenges
1172
+ USING ${ORG_GUC}
1173
+ WITH CHECK ${ORG_GUC}`,
1174
+ `CREATE POLICY notice_claim_org_isolation ON notice_claim
1175
+ USING ${ORG_GUC}
1176
+ WITH CHECK ${ORG_GUC}`,
1177
+ `CREATE POLICY model_call_capture_org_isolation ON model_call_capture
1178
+ USING ${ORG_GUC}
1179
+ WITH CHECK ${ORG_GUC}`,
1180
+ `CREATE POLICY proactive_address_org_isolation ON proactive_address
1181
+ USING ${ORG_GUC}
1182
+ WITH CHECK ${ORG_GUC}`,
1183
+ `CREATE POLICY memory_proposal_org_isolation ON memory_proposal
1184
+ USING ${ORG_GUC}
1185
+ WITH CHECK ${ORG_GUC}`,
1186
+ `CREATE POLICY credential_grant_ask_org_isolation ON credential_grant_ask
1187
+ USING ${ORG_GUC}
1188
+ WITH CHECK ${ORG_GUC}`,
1189
+ `CREATE POLICY credential_grant_org_isolation ON credential_grant
1190
+ USING ${ORG_GUC}
1191
+ WITH CHECK ${ORG_GUC}`,
1192
+ `CREATE POLICY dm_audience_org_isolation ON dm_audience
1193
+ USING ${ORG_GUC}
1194
+ WITH CHECK ${ORG_GUC}`,
1195
+ ];
1196
+ /** The DB-enforced append-only tables (see the header). */
1197
+ const APPEND_ONLY_TABLES = ["audit_entry", "usage_events", "domain_skill_revisions", "routine_prompt_revisions"];
1198
+ /** One `dm_audience` row → {@link DmAudienceRow}. A NULL timestamp is dropped rather than carried as
1199
+ * `null`, so a caller reads absence as absence and never has to test two spellings of "not set". */
1200
+ function dmAudienceRowFrom(r) {
1201
+ return {
1202
+ address: r.address,
1203
+ ...(r.first_dm_at === null ? {} : { firstDmAt: r.first_dm_at }),
1204
+ ...(r.stopped_at === null ? {} : { stoppedAt: r.stopped_at }),
1205
+ };
1206
+ }
1207
+ const EXPECTED_POLICIES = {
1208
+ audit_entry: [
1209
+ { name: "audit_select", permissive: true, cmd: "r", qual: isOrgGucExpr, withCheck: null },
1210
+ { name: "audit_insert", permissive: true, cmd: "a", qual: null, withCheck: isOrgGucExpr },
1211
+ ],
1212
+ usage_events: [
1213
+ { name: "usage_events_select", permissive: true, cmd: "r", qual: "true", withCheck: null },
1214
+ { name: "usage_events_insert", permissive: true, cmd: "a", qual: null, withCheck: "true" },
1215
+ ],
1216
+ domain_skill_revisions: [
1217
+ { name: "domain_skill_revisions_select", permissive: true, cmd: "r", qual: "true", withCheck: null },
1218
+ { name: "domain_skill_revisions_insert", permissive: true, cmd: "a", qual: null, withCheck: "true" },
1219
+ ],
1220
+ routine_prompt_revisions: [
1221
+ { name: "routine_prompt_revisions_select", permissive: true, cmd: "r", qual: "true", withCheck: null },
1222
+ { name: "routine_prompt_revisions_insert", permissive: true, cmd: "a", qual: null, withCheck: "true" },
1223
+ ],
1224
+ };
1225
+ function expressionMatches(found, expected) {
1226
+ return typeof expected === "function" ? expected(found) : found === expected;
1227
+ }
1228
+ function policyMatchesExpected(p, e) {
1229
+ return p.name === e.name && p.permissive === e.permissive && p.cmd === e.cmd && expressionMatches(p.qual, e.qual) && expressionMatches(p.withcheck, e.withCheck);
1230
+ }
1231
+ async function policiesOn(client, table) {
1232
+ const { rows } = await client.query(`SELECT p.polname AS name, p.polpermissive AS permissive, p.polcmd AS cmd,
1233
+ pg_get_expr(p.polqual, p.polrelid) AS qual,
1234
+ pg_get_expr(p.polwithcheck, p.polrelid) AS withcheck
1235
+ FROM pg_policy p WHERE p.polrelid = to_regclass($1)`, [table]);
1236
+ return rows.map((r) => ({
1237
+ name: r.name,
1238
+ permissive: r.permissive,
1239
+ cmd: r.cmd,
1240
+ qual: r.qual,
1241
+ withcheck: r.withcheck,
1242
+ }));
1243
+ }
1244
+ function triggerEvents(tgtype) {
1245
+ const ev = [];
1246
+ if (tgtype & 4)
1247
+ ev.push("INSERT");
1248
+ if (tgtype & 8)
1249
+ ev.push("DELETE");
1250
+ if (tgtype & 16)
1251
+ ev.push("UPDATE");
1252
+ if (tgtype & 32)
1253
+ ev.push("TRUNCATE");
1254
+ return ev;
1255
+ }
1256
+ /** Every NON-internal trigger on `table` (constraint/FK triggers are internal → excluded). */
1257
+ async function nonInternalTriggers(client, table) {
1258
+ const { rows } = await client.query(`SELECT t.tgname AS name, t.tgtype AS tgtype
1259
+ FROM pg_trigger t WHERE t.tgrelid = to_regclass($1) AND NOT t.tgisinternal`, [table]);
1260
+ return rows.map((r) => ({ name: r.name, tgtype: Number(r.tgtype) }));
1261
+ }
1262
+ /** Every UPDATE/DELETE/TRUNCATE grant on table held by a role OTHER than the owner - an owner GRANT slip that would let the runtime role, or PUBLIC, mutate the append-only log despite RLS. aclexplode over pg_class.relacl means no runtime-role name is needed, so a bad grant to ANY grantee is caught, and token comes back REVOKE-ready (a quoted role name, or the literal PUBLIC). */
1263
+ async function badMutationGrants(client, table) {
1264
+ const { rows } = await client.query(`SELECT DISTINCT
1265
+ CASE WHEN g.grantee = 0 THEN 'PUBLIC' ELSE quote_ident(r.rolname) END AS token,
1266
+ CASE WHEN g.grantee = 0 THEN 'PUBLIC' ELSE r.rolname END AS label,
1267
+ g.privilege_type AS privilege
1268
+ FROM (
1269
+ SELECT ae.grantee AS grantee, ae.privilege_type AS privilege_type, c.relowner AS relowner
1270
+ FROM pg_class c CROSS JOIN LATERAL aclexplode(c.relacl) ae
1271
+ WHERE c.oid = to_regclass($1)
1272
+ ) g
1273
+ LEFT JOIN pg_roles r ON r.oid = g.grantee
1274
+ WHERE g.privilege_type IN ('UPDATE', 'DELETE', 'TRUNCATE') AND g.grantee <> g.relowner`, [table]);
1275
+ return rows;
1276
+ }
1277
+ /**
1278
+ * Does the CURRENT role own (or inherit ownership of, via role membership — the same
1279
+ * test Postgres itself applies to DDL) the audit table? `null` when the table doesn't
1280
+ * exist yet (fresh database). Drives initOperationalSchema's owner-vs-runtime split.
1281
+ */
1282
+ async function ownsAuditTable(client) {
1283
+ const { rows } = await client.query(`SELECT pg_has_role(current_user, c.relowner, 'USAGE') AS is_owner
1284
+ FROM pg_class c WHERE c.oid = to_regclass('audit_entry')`);
1285
+ const r = rows[0];
1286
+ return r ? r.is_owner === true : null;
1287
+ }
1288
+ /**
1289
+ * The tail of every violation sentence {@link auditIntegrityCause} reads. The producers below build
1290
+ * their messages from these constants, and the classifier matches on them, so a reworded violation
1291
+ * cannot silently stop naming a cause. The sentences stay human-readable: they are what a responder
1292
+ * sees in the `audit.integrity` row and on the console.
1293
+ */
1294
+ const VIOLATION_SUFFIX = {
1295
+ noInsertPolicy: ": no INSERT policy — appends would be denied under FORCE",
1296
+ noSelectPolicy: ": no SELECT policy — reads would be denied under FORCE",
1297
+ foreignPolicy: " — not in the append-only allowlist",
1298
+ mutatingPolicy: " — append-only defeated",
1299
+ hostileTrigger: " — could suppress or alter audit writes",
1300
+ badGrant: " — a non-owner could mutate the append-only log",
1301
+ };
1302
+ /** The violations that name an artifact SOMEBODY ADDED. Each one is a thing the store never creates
1303
+ * for itself, so its presence is the tampering signature. */
1304
+ const TAMPER_SUFFIXES = [VIOLATION_SUFFIX.foreignPolicy, VIOLATION_SUFFIX.mutatingPolicy, VIOLATION_SUFFIX.hostileTrigger, VIOLATION_SUFFIX.badGrant];
1305
+ /** Verify the append-only posture of every APPEND_ONLY_TABLES entry as it ACTUALLY stands in the catalog: RLS enabled and FORCED, the full policy set matching the EXPECTED_POLICIES allowlist, no non-internal INSERT/UPDATE/DELETE trigger, and no non-owner UPDATE/DELETE/TRUNCATE grant. Returns human-readable violations, empty when sound; it is read-only and safe under any role, so the non-owner runtime boot can call it. */
1306
+ export async function verifyAppendOnlyAudit(client) {
1307
+ const violations = [];
1308
+ for (const table of APPEND_ONLY_TABLES) {
1309
+ const { rows } = await client.query(`SELECT c.relrowsecurity AS rls, c.relforcerowsecurity AS force
1310
+ FROM pg_class c WHERE c.oid = to_regclass($1)`, [table]);
1311
+ const t = rows[0];
1312
+ if (!t) {
1313
+ violations.push(`${table}: table missing`);
1314
+ continue;
1315
+ }
1316
+ if (t.rls !== true)
1317
+ violations.push(`${table}: ROW LEVEL SECURITY is disabled`);
1318
+ if (t.force !== true)
1319
+ violations.push(`${table}: FORCE ROW LEVEL SECURITY is off (owner would bypass policies)`);
1320
+ const pols = await policiesOn(client, table);
1321
+ const expected = EXPECTED_POLICIES[table] ?? [];
1322
+ // polcmd: r=SELECT a=INSERT w=UPDATE d=DELETE *=ALL
1323
+ for (const p of pols) {
1324
+ if (p.cmd === "w" || p.cmd === "d" || p.cmd === "*") {
1325
+ violations.push(`${table}: policy "${p.name}" permits ${p.cmd === "w" ? "UPDATE" : p.cmd === "d" ? "DELETE" : "ALL"}${VIOLATION_SUFFIX.mutatingPolicy}`);
1326
+ }
1327
+ if (!expected.some((e) => policyMatchesExpected(p, e))) {
1328
+ violations.push(`${table}: unexpected ${p.permissive ? "permissive" : "RESTRICTIVE"} policy "${p.name}" (cmd ${p.cmd})${VIOLATION_SUFFIX.foreignPolicy}`);
1329
+ }
1330
+ }
1331
+ if (!pols.some((p) => p.cmd === "a"))
1332
+ violations.push(`${table}${VIOLATION_SUFFIX.noInsertPolicy}`);
1333
+ if (!pols.some((p) => p.cmd === "r"))
1334
+ violations.push(`${table}${VIOLATION_SUFFIX.noSelectPolicy}`);
1335
+ for (const tr of await nonInternalTriggers(client, table)) {
1336
+ const ev = triggerEvents(tr.tgtype);
1337
+ if (ev.some((e) => e === "INSERT" || e === "UPDATE" || e === "DELETE")) {
1338
+ violations.push(`${table}: hostile trigger "${tr.name}" (${ev.join("/")})${VIOLATION_SUFFIX.hostileTrigger}`);
1339
+ }
1340
+ }
1341
+ for (const g of await badMutationGrants(client, table)) {
1342
+ violations.push(`${table}: role "${g.label}" holds a ${g.privilege} grant${VIOLATION_SUFFIX.badGrant}`);
1343
+ }
1344
+ }
1345
+ return violations;
1346
+ }
1347
+ /** Owner-only surgical repair of the suppression vectors SCHEMA_STATEMENTS cannot fix by re-CREATE alone: a foreign or RESTRICTIVE policy, a hostile trigger, a stray grant. Strictly scoped to APPEND_ONLY_TABLES and to artifacts outside the known-good set; a no-op on a sound posture. A hostile trigger and a stray grant are repaired HERE, in autocommit: neither leaves a table policy-less, and both must precede the `audit.integrity` INSERT, which a trigger could otherwise swallow. A foreign policy is only collected — see {@link HealPlan.policyDrops}. */
1348
+ async function healUnexpectedArtifacts(client) {
1349
+ const droppedPolicies = [];
1350
+ const droppedTriggers = [];
1351
+ const revokedGrants = [];
1352
+ const policyDrops = [];
1353
+ for (const table of APPEND_ONLY_TABLES) {
1354
+ // A missing table has no policies/triggers/grants to enumerate (the queries return
1355
+ // empty) and is repaired by the schema re-apply — nothing to heal here.
1356
+ const expected = EXPECTED_POLICIES[table] ?? [];
1357
+ for (const p of await policiesOn(client, table)) {
1358
+ if (!expected.some((e) => policyMatchesExpected(p, e))) {
1359
+ policyDrops.push(`DROP POLICY IF EXISTS ${quoteIdent(p.name)} ON ${table}`);
1360
+ droppedPolicies.push(`${table}.${p.name}`);
1361
+ }
1362
+ }
1363
+ for (const tr of await nonInternalTriggers(client, table)) {
1364
+ await client.query(`DROP TRIGGER IF EXISTS ${quoteIdent(tr.name)} ON ${table}`);
1365
+ droppedTriggers.push(`${table}.${tr.name}`);
1366
+ }
1367
+ for (const g of await badMutationGrants(client, table)) {
1368
+ // g.token is a REVOKE-ready identifier (quoted role name or the literal PUBLIC),
1369
+ // derived by quote_ident in the query — never raw user input.
1370
+ await client.query(`REVOKE UPDATE, DELETE, TRUNCATE ON ${table} FROM ${g.token}`);
1371
+ revokedGrants.push(`${table}:${g.label}:${g.privilege}`);
1372
+ }
1373
+ }
1374
+ return { heal: { droppedPolicies, droppedTriggers, revokedGrants }, policyDrops };
1375
+ }
1376
+ function quoteIdent(name) {
1377
+ return `"${name.replace(/"/g, '""')}"`;
1378
+ }
1379
+ /** Did the heal pass remove anything? The audit row and the console line both need that fact, and
1380
+ * an EMPTY heal is half of the aborted-init signature, so the two readers share one definition. */
1381
+ function healedAnything(heal) {
1382
+ return heal !== undefined && (heal.droppedPolicies.length > 0 || heal.droppedTriggers.length > 0 || heal.revokedGrants.length > 0);
1383
+ }
1384
+ /**
1385
+ * Name the CAUSE of a posture violation, so the heal reports what happened instead of hiding it
1386
+ * (OPE-1994). Each answer names a CATALOG STATE. It does not name a history, because the catalog
1387
+ * carries none — read each one as "what is true", then look for who did it:
1388
+ *
1389
+ * - **aborted-init** — a table stands with RLS forced and NO policy, and the heal found nothing to
1390
+ * remove. An init that aborted inside the policy span leaves exactly this state. 🔴 So does an
1391
+ * owner-credential `DROP POLICY`, which is the attack FORCE cannot stop, so this answer does NOT
1392
+ * rule a tamper out — check who held owner DDL in the window. Either way every audit append was
1393
+ * denied until this boot, and agent/audit/audit.ts dropped each row it could not append. That
1394
+ * loss is NOT recoverable — this row is the only record of it.
1395
+ * - **tampering** — an artifact outside the current allowlist is present: a policy, a trigger or a
1396
+ * mutation grant this schema never creates. An older release's own shape reads the same way (the
1397
+ * pre-OPE-1812 `USING (true)` audit policies, for one), so check the release history before
1398
+ * treating it as an intrusion.
1399
+ *
1400
+ * Tampering WINS when both hold. An aborted span can only ever remove, so an added artifact is the
1401
+ * stronger evidence and the one a responder must see first. Anything else — RLS off, FORCE off, a
1402
+ * missing table — is `unknown`: real, and outside both signatures.
1403
+ */
1404
+ export function auditIntegrityCause(violations, healedArtifacts) {
1405
+ if (healedArtifacts || violations.some((v) => TAMPER_SUFFIXES.some((suffix) => v.endsWith(suffix))))
1406
+ return "tampering";
1407
+ if (violations.some((v) => v.endsWith(VIOLATION_SUFFIX.noInsertPolicy) || v.endsWith(VIOLATION_SUFFIX.noSelectPolicy)))
1408
+ return "aborted-init";
1409
+ return "unknown";
1410
+ }
1411
+ /** One sentence per cause, for the console line a responder reads before anything else. */
1412
+ const CAUSE_NOTE = {
1413
+ "aborted-init": "a table stood with row-level security forced and NO policy, and the heal removed nothing — an init aborted inside the policy span leaves this, and so does an owner-credential DROP POLICY; every audit append since was denied and its row dropped",
1414
+ tampering: "an artifact outside the current allowlist was present — a policy, trigger or grant this schema never creates, or one an older release created; check the release history before treating it as an intrusion",
1415
+ unknown: "neither the aborted-init nor the tampering signature explains this state — read the violations",
1416
+ };
1417
+ /** Record a detected posture violation IN the audit log itself - a direct INSERT, because this runs at boot before the store singleton exists, and best-effort: if the log cannot take the row, the caller's throw is the signal. The org MUST come from deploymentOrg() and never from a second normaliser, or the row lands in a partition readAudit never queries and links onto the wrong chain. */
1418
+ async function recordAuditIntegrity(client, violations, healed, heal) {
1419
+ const healedArtifacts = healedAnything(heal);
1420
+ // `cause` is what separates an aborted init from tampering for whoever reads this row months
1421
+ // later; the violations alone read the same either way.
1422
+ const detail = { violations, healed, cause: auditIntegrityCause(violations, healedArtifacts) };
1423
+ if (healedArtifacts) {
1424
+ detail.healed_artifacts = heal;
1425
+ }
1426
+ const org = deploymentOrg();
1427
+ const ts = new Date().toISOString();
1428
+ try {
1429
+ // Chain-link this row like a normal append: a bare NULL prev_sha here would look like a genesis planted mid-chain and read as a false break. It takes the SAME serialised append as every other row, so a boot that repairs the append-only posture cannot fork the chain it is recording.
1430
+ const insert = async (conn, prevSha) => {
1431
+ await conn.query(`INSERT INTO audit_entry (ts, org_id, platform, workspace, action, detail, prev_sha)
1432
+ VALUES ($1, $2, 'db', 'postgres', 'audit.integrity', $3, $4)`, [ts, org, JSON.stringify(detail), prevSha]);
1433
+ };
1434
+ try {
1435
+ await withAuditChainLock(client, org, async (conn) => insert(conn, await nextAuditPrevSha(conn, org)));
1436
+ }
1437
+ catch (chainErr) {
1438
+ // RECORDING THE VIOLATION BEATS A PERFECT LINK. If the chained append cannot run at all
1439
+ // (the posture repair may have left the table half-usable, which is the whole reason this
1440
+ // row exists), write the row UNCHAINED rather than lose it — and say so, because a null
1441
+ // prev_sha mid-chain is exactly what the verifier reports as a break.
1442
+ console.error(`[open-everywhere:operational] the audit.integrity row could not be chain-linked (${String(chainErr)}); ` +
1443
+ "writing it UNCHAINED — the chain verifier will report a break at this row.");
1444
+ await insert(client, null);
1445
+ }
1446
+ }
1447
+ catch (err) {
1448
+ console.error(`[open-everywhere:operational] could not record audit.integrity row: ${String(err)}`);
1449
+ }
1450
+ }
1451
+ // The chain link is a read-tail-then-insert, so two writers that read the same tail stamp the same prev_sha and FORK the chain - measured at 6,966 broken links across 53,218 rows on the live store. The critical section is therefore a transaction on a pinned connection behind pg_advisory_xact_lock, whose xact form releases at COMMIT so no lock survives the connection's return to the pool; with no withConnection seam the append falls back to a plain read-then-insert, correct only for a single-process engine.
1452
+ /** Advisory-lock class for the audit chain — the first 4 bytes of sha256("open-everywhere:
1453
+ * audit-chain"), read as a signed int32. A class of its own keeps the org keys below from
1454
+ * colliding with any other advisory-lock user in the same database. */
1455
+ const AUDIT_CHAIN_LOCK_CLASS = createHash("sha256").update("open-everywhere:audit-chain").digest().readInt32BE(0);
1456
+ /** The per-org advisory-lock key: the first 4 bytes of sha256(org) as a signed int32. Derived
1457
+ * in Node rather than with Postgres's `hashtext` so the value does not depend on an internal
1458
+ * server function, and so a test can name the exact key the append must take. */
1459
+ export function auditChainLockKey(org) {
1460
+ return createHash("sha256").update(org).digest().readInt32BE(0);
1461
+ }
1462
+ /** Advisory-lock class for the schema's policy span — the first 4 bytes of
1463
+ * sha256("open-everywhere:schema-policy"), read as a signed int32. A class of its own keeps the
1464
+ * span apart from the audit-chain keys above, so a boot that re-applies the policies never waits
1465
+ * on an append and never makes one wait. A TRACKED literal, never an env var. */
1466
+ const SCHEMA_POLICY_LOCK_CLASS = createHash("sha256").update("open-everywhere:schema-policy").digest().readInt32BE(0);
1467
+ /** The one key in that class. The span is a single critical section per database — it re-applies
1468
+ * EVERY org's policies at once — so unlike the audit chain it needs no per-org key. */
1469
+ const SCHEMA_POLICY_LOCK_KEY = createHash("sha256").update("open-everywhere:operational-policy-span").digest().readInt32BE(0);
1470
+ /** How long the policy span waits for a lock. It bounds two waits: the advisory lock another init
1471
+ * pass holds, and the ACCESS EXCLUSIVE lock each DROP/CREATE POLICY takes on its table. A timeout
1472
+ * ABORTS the transaction, which rolls the span back and leaves every policy in place, so the cost
1473
+ * of the bound is a failed boot and never a deny-all store. The value is generous because the span
1474
+ * is a boot path, not a hot path: it must outlast another pass's span (about 5 s, derived from the
1475
+ * 28 s apply, never measured on its own) rather than give up beside it. A TRACKED literal, never
1476
+ * an env var. */
1477
+ const SCHEMA_POLICY_LOCK_TIMEOUT_MS = 60_000;
1478
+ /** How long an append waits for the per-org advisory lock. pg_advisory_xact_lock waits FOREVER by default and appendAudit is awaited on the hot path, so without a bound one wedged holder stalls every other instance's appends for that org; on timeout agent/audit/audit.ts retries once and then drops the row with its counter and warn. It is a TRACKED literal, never an env var. */
1479
+ const AUDIT_CHAIN_LOCK_TIMEOUT_MS = 10_000;
1480
+ /** One org's audit rows OLDEST-first with their seq + prev_sha — the hash-chain walk's input.
1481
+ * Takes the client explicitly so the epoch seal can read the chain on the SAME pinned
1482
+ * connection its INSERT runs on (OPE-1636), not through the pool. tailLimit>0 → the last N by
1483
+ * seq, then reversed to oldest-first (an inner DESC+LIMIT subquery, the outer re-orders ASC). */
1484
+ async function readAuditChainRows(client, org, tail) {
1485
+ const cols = "seq, ts, org_id, platform, workspace, surface, surface_mode, principal_id, action, detail, prev_sha";
1486
+ const sql = tail && tail > 0
1487
+ ? `SELECT ${cols} FROM (
1488
+ SELECT ${cols} FROM audit_entry WHERE org_id = $1 ORDER BY seq DESC LIMIT $2
1489
+ ) sub ORDER BY seq ASC`
1490
+ : `SELECT ${cols} FROM audit_entry WHERE org_id = $1 ORDER BY seq ASC`;
1491
+ const { rows } = await client.query(sql, tail && tail > 0 ? [org, tail] : [org]);
1492
+ return rows.map((r) => ({
1493
+ seq: Number(r.seq),
1494
+ ts: r.ts,
1495
+ org: r.org_id,
1496
+ platform: r.platform,
1497
+ workspace: r.workspace,
1498
+ ...(r.surface ? { surface: r.surface } : {}),
1499
+ ...auditSurfaceMode(r.surface_mode),
1500
+ ...(r.principal_id ? { principalId: r.principal_id } : {}),
1501
+ action: r.action,
1502
+ ...(r.detail ? { detail: JSON.parse(r.detail) } : {}),
1503
+ prevSha: r.prev_sha,
1504
+ }));
1505
+ }
1506
+ /** The orgs whose audit-chain critical section the CURRENT async context already holds, each
1507
+ * mapped to the connection that section runs on. Both locks below are NON-REENTRANT on their
1508
+ * own, so a re-entry would wait on itself forever; this is what tells one apart from a genuine
1509
+ * second writer. */
1510
+ const heldAuditChainLocks = new AsyncLocalStorage();
1511
+ /** Run body inside the per-org audit-chain critical section: body gets the connection to read the tail from and to insert on - the same connection, inside one transaction, whenever the client can pin one. The in-process lock wraps the transaction because an embedded engine has ONE connection and would otherwise nest a BEGIN, and the whole thing MUST stay reentrant: a deferred schema init can write an audit.integrity row from inside an append's own section, and without the re-entry check the lock waits on itself for the life of the process. */
1512
+ async function withAuditChainLock(client, org, body) {
1513
+ const held = heldAuditChainLocks.getStore();
1514
+ const outer = held?.get(org);
1515
+ if (outer !== undefined)
1516
+ return await body(outer);
1517
+ return withOrgAuditLock(org, async () => {
1518
+ const next = new Map(held ?? []);
1519
+ if (!client.withConnection) {
1520
+ next.set(org, client);
1521
+ return await heldAuditChainLocks.run(next, () => body(client));
1522
+ }
1523
+ return await client.withConnection(async (conn) => {
1524
+ next.set(org, conn);
1525
+ await conn.query("BEGIN");
1526
+ try {
1527
+ // SET LOCAL, so the bound dies with the transaction and never leaks onto a pooled
1528
+ // connection — the same reason the advisory lock is the xact form. The value is a module
1529
+ // constant interpolated as a literal because a utility statement takes no bind parameter.
1530
+ await conn.query(`SET LOCAL lock_timeout = ${AUDIT_CHAIN_LOCK_TIMEOUT_MS}`);
1531
+ await conn.query("SELECT pg_advisory_xact_lock($1::int, $2::int)", [AUDIT_CHAIN_LOCK_CLASS, auditChainLockKey(org)]);
1532
+ const result = await heldAuditChainLocks.run(next, () => body(conn));
1533
+ await conn.query("COMMIT");
1534
+ return result;
1535
+ }
1536
+ catch (err) {
1537
+ // ROLLBACK is what releases the advisory lock on a failed append. Its own failure is
1538
+ // swallowed — the original error is the one the caller must see — and `withConnection`
1539
+ // is told about the failure so the driver can DESTROY the connection instead of
1540
+ // returning a still-in-transaction one, holding this org's lock, to the pool.
1541
+ await conn.query("ROLLBACK").catch(() => undefined);
1542
+ throw err;
1543
+ }
1544
+ });
1545
+ });
1546
+ }
1547
+ /** Boot note (OPE-1636): a Postgres client with no `withConnection` cannot open the transaction
1548
+ * the chain append needs, so its appends serialise only inside this process. Warn ONCE per
1549
+ * process. The embedded PGlite floor is the expected, correct case — it holds a single-writer
1550
+ * file lock, so one process is all there is — and the message says so rather than crying wolf. */
1551
+ let auditChainSerialisationWarned = false;
1552
+ function warnIfAuditChainCannotSerialise(client) {
1553
+ if (client.withConnection || auditChainSerialisationWarned)
1554
+ return;
1555
+ auditChainSerialisationWarned = true;
1556
+ console.warn("[open-everywhere:operational] this Postgres client offers no withConnection seam, so audit-chain appends are serialised " +
1557
+ "IN-PROCESS ONLY. That is correct for the embedded PGlite floor (one writer by construction). On a POOLED hosted client it " +
1558
+ "means concurrent instances can fork the chain — give the client a withConnection implementation " +
1559
+ "(packages/adapters/agent/postgres/neon.ts is the reference).");
1560
+ }
1561
+ export function _resetAuditChainSerialisationWarnForTest() {
1562
+ auditChainSerialisationWarned = false;
1563
+ }
1564
+ /** Compute the OPE-52 hash-chain prev_sha for the NEXT audit row of `org`: sha256 of the org's
1565
+ * current last row (by seq), or null when the org has no rows yet (genesis). Shared by the
1566
+ * store's appendAudit and recordAuditIntegrity. */
1567
+ async function nextAuditPrevSha(client, org) {
1568
+ const { rows } = await client.query(`SELECT ts, org_id, platform, workspace, surface, surface_mode, principal_id, action, detail, prev_sha
1569
+ FROM audit_entry WHERE org_id = $1 ORDER BY seq DESC LIMIT 1`, [org]);
1570
+ const last = rows[0];
1571
+ if (!last)
1572
+ return null;
1573
+ return auditRowSha({
1574
+ org: last.org_id,
1575
+ ts: last.ts,
1576
+ platform: last.platform,
1577
+ workspace: last.workspace,
1578
+ ...(last.surface ? { surface: last.surface } : {}),
1579
+ // Through the same reading the report gets (auditSurfaceMode): a stored value outside the
1580
+ // enum hashes as ABSENT, or the link would break on a row nobody touched.
1581
+ ...auditSurfaceMode(last.surface_mode),
1582
+ ...(last.principal_id ? { principalId: last.principal_id } : {}),
1583
+ action: last.action,
1584
+ ...(last.detail ? { detail: JSON.parse(last.detail) } : {}),
1585
+ }, last.prev_sha);
1586
+ }
1587
+ /** A client with no `withConnection` seam cannot open the policy span's transaction, so the
1588
+ * deny-all window {@link POLICY_STATEMENTS} describes stays open on it. Warn ONCE per process.
1589
+ * The embedded PGlite floor is the expected, correct case — one connection, one writer, and a
1590
+ * killed process takes the whole store with it — and the message says so. */
1591
+ let policySpanAtomicityWarned = false;
1592
+ function warnIfPolicySpanCannotBeAtomic(client) {
1593
+ if (client.withConnection || policySpanAtomicityWarned)
1594
+ return;
1595
+ policySpanAtomicityWarned = true;
1596
+ console.warn("[open-everywhere:operational] this Postgres client offers no withConnection seam, so the RLS policy span re-applies in " +
1597
+ "AUTOCOMMIT. That is correct for the embedded PGlite floor. On a POOLED hosted client it means a pass that aborts inside " +
1598
+ "the span leaves the append-only tables with NO policy — deny-all — until the next owner-mode init. A one-connection " +
1599
+ "engine can run BEGIN and COMMIT; what this seam buys is the proof that every statement lands on ONE connection. Give the client a " +
1600
+ "withConnection implementation (packages/adapters/agent/postgres/neon.ts is the reference).");
1601
+ }
1602
+ /** Let a test drive the once-per-process warning above more than once. Without it the only signal a
1603
+ * pooled hosted deployment gets that its policy span is NOT atomic is one line nothing asserts. */
1604
+ export function _resetPolicySpanAtomicityWarnForTest() {
1605
+ policySpanAtomicityWarned = false;
1606
+ }
1607
+ /**
1608
+ * Apply {@link POLICY_STATEMENTS} as ONE atomic, serialised unit: a transaction on a pinned
1609
+ * connection, behind `pg_advisory_xact_lock`. The lock makes two concurrent inits take the span in
1610
+ * turn, so neither can create a policy the other just dropped (`duplicate_object`, SQLSTATE 42710);
1611
+ * the transaction makes an abort inside the span roll the drops back instead of leaving the store
1612
+ * deny-all. The xact form releases the lock at COMMIT or ROLLBACK, so no lock survives the
1613
+ * connection's return to the pool.
1614
+ *
1615
+ * `healDrops` are the heal pass's `DROP POLICY` statements for the policies outside the allowlist
1616
+ * ({@link HealPlan.policyDrops}). They run at the HEAD of the same transaction, so a foreign policy
1617
+ * is removed and the known-good set recreated as one atomic step.
1618
+ *
1619
+ * The fallback, when the client cannot pin a connection, is the plain autocommit loop — the
1620
+ * behaviour before OPE-1994, which is all this code can do without a pinning seam.
1621
+ */
1622
+ async function applyPolicyStatements(client, healDrops = []) {
1623
+ warnIfPolicySpanCannotBeAtomic(client);
1624
+ const statements = [...healDrops, ...POLICY_STATEMENTS];
1625
+ if (!client.withConnection) {
1626
+ for (const stmt of statements)
1627
+ await client.query(stmt);
1628
+ return;
1629
+ }
1630
+ await client.withConnection(async (conn) => {
1631
+ await conn.query("BEGIN");
1632
+ try {
1633
+ // SET LOCAL, so the bound dies with the transaction and never leaks onto a pooled
1634
+ // connection — the same reason the advisory lock is the xact form. The value is a module
1635
+ // constant interpolated as a literal because a utility statement takes no bind parameter.
1636
+ await conn.query(`SET LOCAL lock_timeout = ${SCHEMA_POLICY_LOCK_TIMEOUT_MS}`);
1637
+ await conn.query("SELECT pg_advisory_xact_lock($1::int, $2::int)", [SCHEMA_POLICY_LOCK_CLASS, SCHEMA_POLICY_LOCK_KEY]);
1638
+ for (const stmt of statements)
1639
+ await conn.query(stmt);
1640
+ await conn.query("COMMIT");
1641
+ }
1642
+ catch (err) {
1643
+ // ROLLBACK is what puts the dropped policies back and releases the advisory lock. Its own
1644
+ // failure is swallowed — the original error is the one the caller must see — and the throw
1645
+ // reaches `withConnection` so the driver can DESTROY a still-in-transaction connection
1646
+ // instead of returning it to the pool.
1647
+ await conn.query("ROLLBACK").catch(() => undefined);
1648
+ throw err;
1649
+ }
1650
+ });
1651
+ }
1652
+ /** Create the tables and RLS policies. Idempotent and safe on every boot, and ROLE-AWARE: as the owner (or on a fresh database) it applies the DDL and records any pre-existing posture violation as an audit.integrity row, while a non-owner runtime role runs no DDL, verifies the append-only posture instead, and refuses to boot when it does not hold - nobody with the runtime credential could have broken it and nothing running can repair it. */
1653
+ export async function initOperationalSchema(client) {
1654
+ warnIfAuditChainCannotSerialise(client);
1655
+ const owner = await ownsAuditTable(client);
1656
+ if (owner === false) {
1657
+ const violations = await verifyAppendOnlyAudit(client);
1658
+ if (violations.length > 0) {
1659
+ await recordAuditIntegrity(client, violations, false);
1660
+ const cause = auditIntegrityCause(violations, false);
1661
+ throw new Error(`operational schema: append-only audit posture FAILED verification under the non-owner runtime role — cause: ${cause} ` +
1662
+ `(${CAUSE_NOTE[cause]}) — ${violations.join("; ")}. ` +
1663
+ "Re-run the schema init as the owner/migration role to repair it, then reboot (docs/extending/database.md, two-role split).");
1664
+ }
1665
+ return; // runtime role, posture sound — no DDL to run
1666
+ }
1667
+ const preViolations = owner === true ? await verifyAppendOnlyAudit(client) : [];
1668
+ // Heal the suppression vectors SCHEMA_STATEMENTS can't fix by re-CREATE alone (a
1669
+ // foreign/RESTRICTIVE policy, a hostile trigger, a stray UPDATE/DELETE/TRUNCATE grant)
1670
+ // BEFORE recording — an insert-swallowing trigger would otherwise eat the integrity INSERT.
1671
+ // The trigger drops and grant revokes commit here; the POLICY drops are only planned, and run
1672
+ // inside the span's transaction below, so the heal never leaves a table policy-less either.
1673
+ // Only meaningful on an existing table (owner === true); a fresh DB has nothing to heal.
1674
+ const plan = owner === true ? await healUnexpectedArtifacts(client) : { heal: { droppedPolicies: [], droppedTriggers: [], revokedGrants: [] }, policyDrops: [] };
1675
+ const heal = plan.heal;
1676
+ try {
1677
+ for (const stmt of SCHEMA_STATEMENTS)
1678
+ await client.query(stmt);
1679
+ // The policy span runs apart from the loop above, and ATOMICALLY — see POLICY_STATEMENTS. The
1680
+ // heal's own policy drops ride INSIDE it, or they would open the same deny-all window here.
1681
+ await applyPolicyStatements(client, plan.policyDrops);
1682
+ }
1683
+ catch (err) {
1684
+ if (owner === null) {
1685
+ throw new Error(`operational schema: could not create the schema (fresh database, and this role may lack CREATE) — ${String(err)}. ` +
1686
+ "Run the first boot / migration as the owner role, then point the app at the runtime role (docs/extending/database.md).");
1687
+ }
1688
+ throw err;
1689
+ }
1690
+ if (preViolations.length > 0) {
1691
+ const cause = auditIntegrityCause(preViolations, healedAnything(heal));
1692
+ console.error(`[open-everywhere:operational] append-only audit posture was broken and has been re-applied — cause: ${cause} ` +
1693
+ `(${CAUSE_NOTE[cause]}): ${preViolations.join("; ")}`);
1694
+ await recordAuditIntegrity(client, preViolations, true, heal);
1695
+ }
1696
+ const post = await verifyAppendOnlyAudit(client);
1697
+ if (post.length > 0) {
1698
+ throw new Error(`operational schema: append-only audit posture STILL failing after apply — ${post.join("; ")}`);
1699
+ }
1700
+ }
1701
+ /**
1702
+ * The provisioning statements for the NON-OWNER runtime role — the exact grants the
1703
+ * two-role split needs (docs/extending/database.md walks through running them; the
1704
+ * operational test executes this same list against a real engine so docs and reality
1705
+ * can't drift). Run them AS THE OWNER, after both schema inits, each time a migration
1706
+ * adds a table (no ALTER DEFAULT PRIVILEGES on purpose: a future append-only table must
1707
+ * not silently inherit UPDATE/DELETE).
1708
+ *
1709
+ * The role itself is created separately (`CREATE ROLE <name> LOGIN PASSWORD '…'` — via
1710
+ * SQL, NOT the Neon console, so it picks up no elevated platform role memberships) —
1711
+ * see the docs. `role` is interpolated, not parameterised (DDL can't take parameters):
1712
+ * callers pass a literal role name from config, never untrusted input.
1713
+ */
1714
+ export function runtimeRoleGrantsSql(role) {
1715
+ if (!/^[a-z_][a-z0-9_]*$/.test(role)) {
1716
+ throw new Error(`runtimeRoleGrantsSql: "${role}" is not a plain lowercase identifier`);
1717
+ }
1718
+ return [
1719
+ `GRANT USAGE ON SCHEMA public TO ${role}`,
1720
+ // No DDL, ever: not owner + no CREATE = Postgres refuses DROP POLICY / ALTER TABLE outright.
1721
+ `REVOKE CREATE ON SCHEMA public FROM ${role}`,
1722
+ // Append-only tables: SELECT + INSERT and nothing else — belt (privileges) and
1723
+ // braces (the FORCE RLS policies) both deny UPDATE/DELETE.
1724
+ `GRANT SELECT, INSERT ON audit_entry, usage_events, domain_skill_revisions, routine_prompt_revisions TO ${role}`,
1725
+ `REVOKE UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER ON audit_entry, usage_events, domain_skill_revisions, routine_prompt_revisions FROM ${role}`,
1726
+ // Identity columns draw from sequences; INSERT needs USAGE on them.
1727
+ `GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO ${role}`,
1728
+ ...mutableTableGrantsSql(role),
1729
+ // webhook_capture sits OUTSIDE MUTABLE_TABLE_VERBS deliberately: it is the one table holding an outside party's bytes, and its code uses exactly SELECT (list a window), INSERT (capture one delivery) and DELETE (the sweeps and the re-arm clear). It never UPDATEs - a captured row is evidence of what arrived, and a window is replaced wholesale rather than edited - which is a property of what evidence IS, not of what its current callers happen to issue.
1730
+ `GRANT SELECT, INSERT, DELETE ON webhook_capture TO ${role}`,
1731
+ // Belt to the braces: the grant above already withholds UPDATE, and this makes the intent
1732
+ // survive someone later folding webhook_capture into MUTABLE_TABLE_VERBS by reflex.
1733
+ `REVOKE UPDATE, TRUNCATE, REFERENCES, TRIGGER ON webhook_capture FROM ${role}`,
1734
+ // The memory tables come from memory/postgres.ts's schema, so on a deployment with a Postgres operational store and a non-Postgres memory provider they do not exist and this statement fails. It is kept out of MUTABLE_TABLE_VERBS to confine that failure to the memory grant instead of taking the operational grants down with it.
1735
+ `GRANT SELECT, INSERT, UPDATE, DELETE ON memory_file, memory_tier TO ${role}`,
1736
+ `REVOKE TRUNCATE, REFERENCES, TRIGGER ON memory_file, memory_tier FROM ${role}`,
1737
+ ];
1738
+ }
1739
+ /** The four table-level DML verbs, in the canonical order every emitted statement uses. */
1740
+ const DML_VERBS = ["SELECT", "INSERT", "UPDATE", "DELETE"];
1741
+ /** The mutable operational tables, each keyed to THE VERBS THE CODE ACTUALLY ISSUES against it; add an entry with the verbs your statements use and nothing else. An INSERT ... ON CONFLICT DO UPDATE needs UPDATE as well as INSERT while DO NOTHING does not, and TRUNCATE stays revoked everywhere even where DELETE is granted because RLS does not filter TRUNCATE - one would wipe EVERY org's rows. The explicit REVOKEs are also what strip the over-wide verbs from a role upgraded from the old blanket grant. */
1742
+ const MUTABLE_TABLE_VERBS = {
1743
+ // Upsert-only cost ledger (UPSERT_SPEND: ON CONFLICT DO UPDATE) plus reads. NO DELETE: nothing
1744
+ // prunes it — the per-period rows ARE the spend history a limit is checked against, so deleting
1745
+ // one silently lowers a surface's spend. Grant DELETE only alongside a real retention path.
1746
+ spend_ledger: ["SELECT", "INSERT", "UPDATE"],
1747
+ // Full CRUD: addRoutine / updateRoutine / removeRoutine are all real user-facing operations.
1748
+ routine: ["SELECT", "INSERT", "UPDATE", "DELETE"],
1749
+ // Upsert (ON CONFLICT DO UPDATE) + a real clear when a limit is removed.
1750
+ spend_limit: ["SELECT", "INSERT", "UPDATE", "DELETE"],
1751
+ // NO DELETE, and the omission is the property: a halt row is never removed. A resume UPDATEs
1752
+ // `active` to false and stamps who cleared it, so who halted and who resumed both stay readable.
1753
+ // (scripts/operational-test.ts asserts every table's grant EQUALS the verbs its code issues, so
1754
+ // this cannot drift into a privilege nothing uses.)
1755
+ halt: ["SELECT", "INSERT", "UPDATE"],
1756
+ connector_override: ["SELECT", "INSERT", "UPDATE", "DELETE"],
1757
+ // Upsert on engage, UPDATE on the stop/turn bumps, DELETE on disengage.
1758
+ thread_engagement: ["SELECT", "INSERT", "UPDATE", "DELETE"],
1759
+ // Atomic generation bump (ON CONFLICT DO UPDATE) + UPDATE. NO DELETE: a session is retired by
1760
+ // bumping its generation, never by removing the row — the row is what makes the retirement
1761
+ // durable across a restart. A delete path here would resurrect the retired session's identity.
1762
+ channel_session: ["SELECT", "INSERT", "UPDATE"],
1763
+ // The one table whose INSERT is `ON CONFLICT DO NOTHING` (the atomic first-sighting check), so it
1764
+ // needs NO UPDATE — a dedupe row is written once and never edited; changing `seen_at` after the
1765
+ // fact would defeat the check. DELETE is the org-scoped TTL prune-on-write. Revoking UPDATE here
1766
+ // would only be wrong if the DO NOTHING became a DO UPDATE, which would itself be a bug.
1767
+ event_dedupe: ["SELECT", "INSERT", "DELETE"],
1768
+ // Verified delivery inbox: insert-if-absent freezes identity/payload; claim/release/completion are
1769
+ // fenced UPDATEs; DELETE prunes completed tombstones and gives back only a definitively refused,
1770
+ // still-claimed delivery. Pending rows are never clock-pruned.
1771
+ ingress_delivery: ["SELECT", "INSERT", "UPDATE", "DELETE"],
1772
+ // The tail ring: INSERT per recorded event, DELETE for the bound-on-write prune and the carried-forward clear, and ONE narrow UPDATE - editSessionTailPost rewrites a single post row's text, called only from edit_reply's platform-CONFIRMED success path, never a refusal or an ambiguous outcome. The room's own copy of the message changed, so the ring must change with it or it is the one lying about what the room shows.
1773
+ session_tail: ["SELECT", "INSERT", "UPDATE", "DELETE"],
1774
+ // INSERT on request, UPDATE on approve/deny (the CAS lives in `WHERE status = 'pending'`). NO
1775
+ // DELETE: a decided action is RETAINED — the row is the approval record the audit story leans on,
1776
+ // and expiry flips a status rather than removing evidence.
1777
+ pending_actions: ["SELECT", "INSERT", "UPDATE"],
1778
+ // Upsert + a real delete (deleteDomainSkill on the store port).
1779
+ domain_skill: ["SELECT", "INSERT", "UPDATE", "DELETE"],
1780
+ domain_model: ["SELECT", "INSERT", "UPDATE", "DELETE"],
1781
+ // Single-row-per-key instance settings, upserted (ON CONFLICT DO UPDATE). NO DELETE: a key is
1782
+ // overwritten, never removed; there is no "unset" operation on this seam.
1783
+ instance_meta: ["SELECT", "INSERT", "UPDATE"],
1784
+ // The lifetime at-most-once claim: INSERT ... ON CONFLICT DO NOTHING is the whole write path, so it needs no UPDATE. NO DELETE: dropping a claim lets the thing it records happen a second time, and every key space on this table is bounded by the thing it records (one room, one grant, one reaction) rather than by the number of ships.
1785
+ notice_claim: ["SELECT", "INSERT"],
1786
+ // The soak lane's model-call capture (OPE-846). INSERT per captured model call, SELECT for the
1787
+ // harvest read, DELETE because retention here IS a delete-by-session — the harvest takes the
1788
+ // prefixes and then drops them. NO UPDATE: a capture is a record of one call as it was sent, and
1789
+ // a rewritable one would be worthless as a replay source (the sha256 would stop meaning anything).
1790
+ model_call_capture: ["SELECT", "INSERT", "DELETE"],
1791
+ // The proactive-address map (OPE-887). UPSERT is the whole write path (INSERT ... ON CONFLICT DO
1792
+ // UPDATE), so it needs UPDATE alongside INSERT. NO DELETE: an address is corrected by the next
1793
+ // inbound activity, never removed — and a store that could drop one would silently turn a working
1794
+ // proactive delivery into an impossible one.
1795
+ proactive_address: ["SELECT", "INSERT", "UPDATE"],
1796
+ // The dream cycle's proposal review queue (OPE-957). INSERT per recorded proposal, SELECT for
1797
+ // the review list. NO UPDATE/DELETE: nothing calls one today — a real erasure path is future
1798
+ // work the schema does not block, but the runtime role gets no verb without a caller for it.
1799
+ memory_proposal: ["SELECT", "INSERT"],
1800
+ // Upsert on delivery/stop, UPDATE to lift a stop. NO DELETE: a stop is the recipient's boundary,
1801
+ // and a row that can be deleted is a boundary an operator can erase. Lifting one is an UPDATE the
1802
+ // recipient asks for, which keeps the row (and therefore the carded-first-delivery fact) intact.
1803
+ dm_audience: ["SELECT", "INSERT", "UPDATE"],
1804
+ // TTL-pruned routing maps the runtime role must DML or the async-spawn / delegation / upload-read
1805
+ // paths break dead-closed under two-role RLS. All three upsert (ON CONFLICT DO UPDATE ⇒ UPDATE)
1806
+ // and all three delete for real (explicit clears + the opportunistic prune-on-write).
1807
+ thread_ownership: ["SELECT", "INSERT", "UPDATE", "DELETE"],
1808
+ // The thread-seat record (OPE-1696). UPSERT is the whole write path (INSERT ... ON CONFLICT DO
1809
+ // UPDATE), so it needs UPDATE beside INSERT, and DELETE because the writer prunes its own
1810
+ // expired rows on write, exactly as thread_ownership does.
1811
+ thread_seat_state: ["SELECT", "INSERT", "UPDATE", "DELETE"],
1812
+ turn_anchor: ["SELECT", "INSERT", "UPDATE", "DELETE"],
1813
+ task_result: ["SELECT", "INSERT", "UPDATE", "DELETE"],
1814
+ slack_attachment: ["SELECT", "INSERT", "UPDATE", "DELETE"],
1815
+ // The credential broker's ciphertext store: upsert, the OPE-91 claim/release CAS, and a real DELETE. This is the one entry where 'retire by status, keep the row' is the WRONG default - there is no status column and never was, the row IS the secret, so a retained-but-retired credential is a live decryptable token; the evidence of the act survives in the append-only audit ledger, which no runtime DELETE can reach.
1816
+ stored_credential: ["SELECT", "INSERT", "UPDATE", "DELETE"],
1817
+ // The intake single-use CAS: INSERT on offer, UPDATE to stamp `used_at`. NO DELETE — burning an
1818
+ // intake marks it used; removing the row would make a single-use token replayable.
1819
+ credential_intake: ["SELECT", "INSERT", "UPDATE"],
1820
+ // The capture-window arm state: the webhook process reads it on every delivery to decide whether the window is open, and the arming path UPSERTs, so UPDATE is needed alongside INSERT to re-arm in place rather than accumulate a second window over one hook. NO DELETE - a window closes because its deadline elapses, and a delete path would be a second way to close one.
1821
+ webhook_capture_window: ["SELECT", "INSERT", "UPDATE"],
1822
+ // Single-window wakeId→origin routing map: upsert on register, UPDATE to mark answered, DELETE as
1823
+ // the org-scoped TTL prune.
1824
+ unified_wake_target: ["SELECT", "INSERT", "UPDATE", "DELETE"],
1825
+ // The GitHub App's discovered owner→installation map (OPE-226). Upsert on an `installation`
1826
+ // delivery (ON CONFLICT DO UPDATE ⇒ INSERT + UPDATE), DELETE on an uninstall/suspend — the store
1827
+ // port calls it "read-write with a real clear", so unlike the retained-evidence tables above the
1828
+ // delete is the point: an uninstalled App must stop being routable, and a status flag would leave
1829
+ // a stale installation id readable.
1830
+ github_installation: ["SELECT", "INSERT", "UPDATE", "DELETE"],
1831
+ // The approval memos (OPE-53 session grants, OPE-152 routine declared permissions). Upsert on
1832
+ // write (ON CONFLICT DO UPDATE), and DELETE twice over: the prune-on-write that drops this org's
1833
+ // expired memos, and `revokeSessionApprovals` withdrawing a routine's declared permissions. DELETE
1834
+ // rather than a status flip because a memo is live authority, not evidence — the audit row is what
1835
+ // is retained, and a withdrawn row that lingered would keep answering the "is this approved" read.
1836
+ pr_session_approval: ["SELECT", "INSERT", "UPDATE", "DELETE"],
1837
+ // Sets are retired by status and never deleted: the set id is the join key every audit row about that person cites. Linked ids take DELETE for the person's OWN sever, because a severed account must become joinable again while an ADMIN revocation tombstones instead; challenges take no DELETE, because the spent nonce row is what keeps a used code from being claimable again.
1838
+ identity_link_sets: ["SELECT", "INSERT", "UPDATE"],
1839
+ identity_linked_ids: ["SELECT", "INSERT", "UPDATE", "DELETE"],
1840
+ identity_link_challenges: ["SELECT", "INSERT", "UPDATE"],
1841
+ // Credential grants (OPE-1060): INSERT on ask/mint, UPDATE for the approve/decide/burn/revoke/
1842
+ // expire CAS chain. NO DELETE on either — a spent grant row is what makes once-mode single-use,
1843
+ // and the mount projects EVERY row for a scope so it can refuse on state rather than vanish.
1844
+ credential_grant_ask: ["SELECT", "INSERT", "UPDATE"],
1845
+ credential_grant: ["SELECT", "INSERT", "UPDATE"],
1846
+ };
1847
+ /**
1848
+ * Emit the mutable-table grants: one GRANT + one matching REVOKE per DISTINCT verb set, tables
1849
+ * grouped in map order. Grouping is a formatting choice — the statement a table lands in follows
1850
+ * only from its verbs, so appending an entry above never rewrites another table's grant.
1851
+ */
1852
+ function mutableTableGrantsSql(role) {
1853
+ const groups = new Map();
1854
+ for (const [table, verbs] of Object.entries(MUTABLE_TABLE_VERBS)) {
1855
+ // These names are interpolated into DDL (which can't take parameters). They are compile-time
1856
+ // literals today; validate anyway so that stays true if the map is ever built from config.
1857
+ if (!/^[a-z_][a-z0-9_]*$/.test(table)) {
1858
+ throw new Error(`runtimeRoleGrantsSql: "${table}" is not a plain lowercase identifier`);
1859
+ }
1860
+ if (!verbs.includes("SELECT")) {
1861
+ throw new Error(`runtimeRoleGrantsSql: ${table} must grant SELECT (every read, and every WHERE/RETURNING, needs it)`);
1862
+ }
1863
+ const canonical = DML_VERBS.filter((v) => verbs.includes(v));
1864
+ const key = canonical.join(", ");
1865
+ const group = groups.get(key);
1866
+ if (group)
1867
+ group.tables.push(table);
1868
+ else
1869
+ groups.set(key, { verbs: canonical, tables: [table] });
1870
+ }
1871
+ const out = [];
1872
+ for (const [key, { verbs, tables }] of groups) {
1873
+ const list = tables.join(", ");
1874
+ out.push(`GRANT ${key} ON ${list} TO ${role}`);
1875
+ // The complement, plus the three verbs no runtime path ever needs. TRUNCATE is the load-bearing
1876
+ // one (RLS does not filter it — see MUTABLE_TABLE_VERBS); the rest are belt-and-braces.
1877
+ const revoked = [...DML_VERBS.filter((v) => !verbs.includes(v)), "TRUNCATE", "REFERENCES", "TRIGGER"];
1878
+ out.push(`REVOKE ${revoked.join(", ")} ON ${list} FROM ${role}`);
1879
+ }
1880
+ return out;
1881
+ }
1882
+ const UPSERT_SPEND = `INSERT INTO spend_ledger
1883
+ (org_id, surface_key, principal_id, routine_id, model, period, cost_source, surface_mode,
1884
+ input_tokens, output_tokens, cache_read_tokens, cache_write_tokens, reasoning_tokens, usd_micros, usd_micros_measured, calls)
1885
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, 1)
1886
+ ON CONFLICT (org_id, surface_key, principal_id, routine_id, model, period, cost_source) DO UPDATE SET
1887
+ -- OPE-1862: a stamped mode HEALS a row an older build (or a writer with no binding) left
1888
+ -- unstamped, and an unstamped write never erases a mode the row already holds.
1889
+ surface_mode = COALESCE(NULLIF(excluded.surface_mode, ''), spend_ledger.surface_mode),
1890
+ input_tokens = spend_ledger.input_tokens + excluded.input_tokens,
1891
+ output_tokens = spend_ledger.output_tokens + excluded.output_tokens,
1892
+ cache_read_tokens = spend_ledger.cache_read_tokens + excluded.cache_read_tokens,
1893
+ cache_write_tokens = spend_ledger.cache_write_tokens + excluded.cache_write_tokens,
1894
+ reasoning_tokens = spend_ledger.reasoning_tokens + excluded.reasoning_tokens,
1895
+ usd_micros = spend_ledger.usd_micros + excluded.usd_micros,
1896
+ usd_micros_measured = spend_ledger.usd_micros_measured + excluded.usd_micros_measured,
1897
+ calls = spend_ledger.calls + 1`;
1898
+ /** Render the shared `?`-placeholder conjuncts (store.ts spendLedgerConjuncts) to $n,
1899
+ * starting after `offset` already-used params. */
1900
+ function renderSpendConjuncts(conjuncts, offset) {
1901
+ let n = offset;
1902
+ return conjuncts.map((c) => c.replace("?", () => `$${++n}`));
1903
+ }
1904
+ function pendingActionFromPgRow(org, r) {
1905
+ return {
1906
+ id: r.id,
1907
+ org,
1908
+ kind: r.kind,
1909
+ argsJson: r.args_json,
1910
+ scopeKey: r.scope_key,
1911
+ domain: r.domain,
1912
+ requestedBy: r.requested_by,
1913
+ channelId: r.channel_id,
1914
+ threadTs: r.thread_ts,
1915
+ messageTs: r.message_ts,
1916
+ postedTo: r.posted_to,
1917
+ status: r.status,
1918
+ createdAt: r.created_at,
1919
+ expiresAt: r.expires_at,
1920
+ decidedBy: r.decided_by,
1921
+ decidedAt: r.decided_at,
1922
+ };
1923
+ }
1924
+ const TURN_ANCHOR_SELECT = "SELECT window_key, anchor_key, channel_key, session_id, turn_id, surface_key, created_at FROM turn_anchor";
1925
+ /** Project a raw turn_anchor row (or an absent one) into {@link TurnAnchorRow} — the exact shape
1926
+ * sqlite.ts's readTurnAnchorRow produces, so the two backends are indistinguishable to callers. */
1927
+ function turnAnchorFromPgRow(raw) {
1928
+ const r = raw;
1929
+ if (!r)
1930
+ return null;
1931
+ return {
1932
+ windowKey: r.window_key,
1933
+ ...(r.anchor_key !== null ? { anchorKey: r.anchor_key } : {}),
1934
+ ...(r.channel_key !== null ? { channelKey: r.channel_key } : {}),
1935
+ sessionId: r.session_id,
1936
+ turnId: r.turn_id,
1937
+ surfaceKey: r.surface_key,
1938
+ createdAt: r.created_at,
1939
+ };
1940
+ }
1941
+ function linkSetFromPgRow(org, r) {
1942
+ return { org, id: r.id, handle: r.handle, status: r.status, createdAt: r.created_at, updatedAt: r.updated_at };
1943
+ }
1944
+ function linkedIdFromPgRow(org, r) {
1945
+ return {
1946
+ org,
1947
+ linkSetId: r.link_set_id,
1948
+ platform: r.platform,
1949
+ tenant: r.tenant,
1950
+ nativeId: r.native_id,
1951
+ status: r.status,
1952
+ establishedBy: r.established_by,
1953
+ ...(r.evidence === null ? {} : { evidenceJson: r.evidence }),
1954
+ createdAt: r.created_at,
1955
+ updatedAt: r.updated_at,
1956
+ };
1957
+ }
1958
+ /** The column list every challenge read uses — ONE spelling, so a filtered list and a by-id get
1959
+ * can never disagree about which columns come back. */
1960
+ const LINK_CHALLENGE_SELECT = `SELECT org_id, id, nonce_hash, initiating_platform, initiating_tenant, initiating_native_id, initiating_surface_key,
1961
+ claimed_platform, claimed_tenant, claimed_native_id, claimed_at,
1962
+ transport, target_platform, target_tenant, target_native_id, back_nonce_hash,
1963
+ status, created_at, expires_at, decided_at
1964
+ FROM identity_link_challenges`;
1965
+ /** The same column list the CAS statements RETURN — one spelling, so a claim/consent's returned row
1966
+ * can never carry fewer columns than a subsequent read of the same row. */
1967
+ const LINK_CHALLENGE_RETURNING = `org_id, id, nonce_hash, initiating_platform, initiating_tenant, initiating_native_id, initiating_surface_key,
1968
+ claimed_platform, claimed_tenant, claimed_native_id, claimed_at,
1969
+ transport, target_platform, target_tenant, target_native_id, back_nonce_hash,
1970
+ status, created_at, expires_at, decided_at`;
1971
+ function linkChallengeFromPgRow(org, r) {
1972
+ return {
1973
+ org,
1974
+ id: r.id,
1975
+ nonceHash: r.nonce_hash,
1976
+ initiatingPlatform: r.initiating_platform,
1977
+ initiatingTenant: r.initiating_tenant,
1978
+ initiatingNativeId: r.initiating_native_id,
1979
+ initiatingSurfaceKey: r.initiating_surface_key,
1980
+ ...(r.claimed_platform === null ? {} : { claimedPlatform: r.claimed_platform }),
1981
+ ...(r.claimed_tenant === null ? {} : { claimedTenant: r.claimed_tenant }),
1982
+ ...(r.claimed_native_id === null ? {} : { claimedNativeId: r.claimed_native_id }),
1983
+ ...(r.claimed_at === null ? {} : { claimedAt: r.claimed_at }),
1984
+ // A pre-OPE-617 row is a CODE-transport row — what every row was before the column existed, so
1985
+ // the fallback states a fact rather than guessing one.
1986
+ transport: r.transport ?? "code",
1987
+ ...(r.target_platform === null || r.target_platform === undefined ? {} : { targetPlatform: r.target_platform }),
1988
+ ...(r.target_tenant === null || r.target_tenant === undefined ? {} : { targetTenant: r.target_tenant }),
1989
+ ...(r.target_native_id === null || r.target_native_id === undefined ? {} : { targetNativeId: r.target_native_id }),
1990
+ ...(r.back_nonce_hash === null || r.back_nonce_hash === undefined ? {} : { backNonceHash: r.back_nonce_hash }),
1991
+ status: r.status,
1992
+ createdAt: r.created_at,
1993
+ expiresAt: r.expires_at,
1994
+ ...(r.decided_at === null ? {} : { decidedAt: r.decided_at }),
1995
+ };
1996
+ }
1997
+ // One spelling of each column list, shared by the reads and by every CAS statement's RETURNING, so a returned row can never carry fewer columns than a later read of the same row.
1998
+ /** Refuse a half-written borrow at the INSERT, where the caller can still be fixed — see
1999
+ * {@link grantBorrowColumnsProblem} for what "half" means and why it is silent otherwise. */
2000
+ function refuseHalfBorrow(table, row) {
2001
+ const problem = grantBorrowColumnsProblem(row);
2002
+ if (problem !== undefined)
2003
+ throw new Error(`${table}: ${problem}`);
2004
+ }
2005
+ const GRANT_ASK_COLUMNS = `id, requester_principal_id, owner_principal_id, owner_slug, owner_platform, owner_native_id, connector, verb, resource,
2006
+ mcp_tool, frozen_args, tool_name,
2007
+ scope_key, domain_scope_key, purpose, requester_target, card_surface_id, card_message_id, requested_mode, status, created_at, expires_at, decided_at, grant_id`;
2008
+ const GRANT_ASK_SELECT = `SELECT ${GRANT_ASK_COLUMNS} FROM credential_grant_ask`;
2009
+ function grantAskFromPgRow(r) {
2010
+ const frozenArgs = grantJsonFromColumn(r.frozen_args, "credential_grant_ask.frozen_args");
2011
+ return {
2012
+ id: r.id,
2013
+ requesterPrincipalId: r.requester_principal_id,
2014
+ ownerPrincipalId: r.owner_principal_id,
2015
+ ownerSlug: r.owner_slug,
2016
+ ownerPlatform: r.owner_platform,
2017
+ ownerNativeId: r.owner_native_id,
2018
+ connector: r.connector,
2019
+ verb: r.verb,
2020
+ resource: r.resource,
2021
+ // `undefined` as well as `null`, for the reason the card columns below carry: these are
2022
+ // migration-added columns, so a mid-rollout read can answer from a row the ALTER has not reached.
2023
+ ...(r.mcp_tool === null || r.mcp_tool === undefined ? {} : { mcpTool: r.mcp_tool }),
2024
+ ...(frozenArgs === undefined ? {} : { frozenArgs }),
2025
+ ...(r.tool_name === null || r.tool_name === undefined ? {} : { toolName: r.tool_name }),
2026
+ scopeKey: r.scope_key,
2027
+ ...(r.domain_scope_key === null || r.domain_scope_key === undefined ? {} : { domainScopeKey: r.domain_scope_key }),
2028
+ purpose: r.purpose,
2029
+ ...(r.requester_target === null ? {} : { requesterTarget: r.requester_target }),
2030
+ ...(r.card_surface_id === null || r.card_surface_id === undefined ? {} : { cardSurfaceId: r.card_surface_id }),
2031
+ ...(r.card_message_id === null || r.card_message_id === undefined ? {} : { cardMessageId: r.card_message_id }),
2032
+ requestedMode: r.requested_mode,
2033
+ status: r.status,
2034
+ createdAt: r.created_at,
2035
+ expiresAt: r.expires_at,
2036
+ ...(r.decided_at === null ? {} : { decidedAt: r.decided_at }),
2037
+ ...(r.grant_id === null ? {} : { grantId: r.grant_id }),
2038
+ };
2039
+ }
2040
+ const GRANT_COLUMNS = `id, ask_id, requester_principal_id, owner_principal_id, owner_slug, connector, verb, resource,
2041
+ mcp_tool, frozen_args, tool_name, input_schema,
2042
+ scope_key, mode, tier, status, purpose, created_at, expires_at, used_at, revoked_at`;
2043
+ const GRANT_SELECT = `SELECT ${GRANT_COLUMNS} FROM credential_grant`;
2044
+ function grantFromPgRow(r) {
2045
+ const frozenArgs = grantJsonFromColumn(r.frozen_args, "credential_grant.frozen_args");
2046
+ const inputSchema = grantJsonFromColumn(r.input_schema, "credential_grant.input_schema");
2047
+ return {
2048
+ id: r.id,
2049
+ askId: r.ask_id,
2050
+ requesterPrincipalId: r.requester_principal_id,
2051
+ ownerPrincipalId: r.owner_principal_id,
2052
+ ownerSlug: r.owner_slug,
2053
+ connector: r.connector,
2054
+ verb: r.verb,
2055
+ resource: r.resource,
2056
+ // `undefined` as well as `null`: migration-added columns, so a mid-rollout read can answer from
2057
+ // a row the ALTER has not reached yet.
2058
+ ...(r.mcp_tool === null || r.mcp_tool === undefined ? {} : { mcpTool: r.mcp_tool }),
2059
+ ...(frozenArgs === undefined ? {} : { frozenArgs }),
2060
+ ...(r.tool_name === null || r.tool_name === undefined ? {} : { toolName: r.tool_name }),
2061
+ ...(inputSchema === undefined ? {} : { inputSchema }),
2062
+ scopeKey: r.scope_key,
2063
+ mode: r.mode,
2064
+ tier: r.tier,
2065
+ status: r.status,
2066
+ purpose: r.purpose,
2067
+ createdAt: r.created_at,
2068
+ expiresAt: r.expires_at,
2069
+ ...(r.used_at === null ? {} : { usedAt: r.used_at }),
2070
+ ...(r.revoked_at === null ? {} : { revokedAt: r.revoked_at }),
2071
+ };
2072
+ }
2073
+ function spendRowFromPg(r) {
2074
+ return {
2075
+ org: r.org_id,
2076
+ surfaceKey: r.surface_key,
2077
+ principalId: r.principal_id,
2078
+ routineId: r.routine_id,
2079
+ model: r.model,
2080
+ period: r.period,
2081
+ costSource: r.cost_source === "measured" ? "measured" : "derived",
2082
+ // `?? ""` covers any NULL an operator's own migration left: an unreadable mode is UNSTAMPED,
2083
+ // which every report masks.
2084
+ surfaceMode: r.surface_mode ?? "",
2085
+ inputTokens: Number(r.input_tokens),
2086
+ outputTokens: Number(r.output_tokens),
2087
+ cacheReadTokens: Number(r.cache_read_tokens),
2088
+ cacheWriteTokens: Number(r.cache_write_tokens),
2089
+ reasoningTokens: Number(r.reasoning_tokens ?? 0),
2090
+ usdMicros: Number(r.usd_micros),
2091
+ usdMicrosMeasured: Number(r.usd_micros_measured),
2092
+ calls: Number(r.calls),
2093
+ };
2094
+ }
2095
+ export function makeOperationalPostgresStore(client) {
2096
+ return {
2097
+ id: "postgres",
2098
+ root: () => "postgres",
2099
+ async recordSpend(org, write) {
2100
+ await client.query(UPSERT_SPEND, [
2101
+ org,
2102
+ write.surfaceKey,
2103
+ write.principalId ?? "",
2104
+ write.routineId ?? "",
2105
+ write.model ?? "",
2106
+ write.period,
2107
+ write.costSource ?? "derived",
2108
+ write.surfaceMode ?? "",
2109
+ write.inputTokens ?? 0,
2110
+ write.outputTokens ?? 0,
2111
+ write.cacheReadTokens ?? 0,
2112
+ write.cacheWriteTokens ?? 0,
2113
+ write.reasoningTokens ?? 0,
2114
+ write.usdMicros ?? 0,
2115
+ write.usdMicrosMeasured ?? 0,
2116
+ ]);
2117
+ },
2118
+ async spendTotals(org, filter = {}) {
2119
+ const { conjuncts, params } = spendLedgerConjuncts(filter);
2120
+ const { rows } = await client.query(`SELECT COALESCE(SUM(input_tokens), 0) AS input_tokens,
2121
+ COALESCE(SUM(output_tokens), 0) AS output_tokens,
2122
+ COALESCE(SUM(cache_read_tokens), 0) AS cache_read_tokens,
2123
+ COALESCE(SUM(cache_write_tokens), 0) AS cache_write_tokens,
2124
+ COALESCE(SUM(reasoning_tokens), 0) AS reasoning_tokens,
2125
+ COALESCE(SUM(usd_micros), 0) AS usd_micros,
2126
+ COALESCE(SUM(usd_micros_measured), 0) AS usd_micros_measured,
2127
+ COALESCE(SUM(calls), 0) AS calls
2128
+ FROM spend_ledger WHERE ${["org_id = $1", ...renderSpendConjuncts(conjuncts, 1)].join(" AND ")}`, [org, ...params]);
2129
+ const r = rows[0];
2130
+ return {
2131
+ inputTokens: Number(r.input_tokens),
2132
+ outputTokens: Number(r.output_tokens),
2133
+ cacheReadTokens: Number(r.cache_read_tokens),
2134
+ cacheWriteTokens: Number(r.cache_write_tokens),
2135
+ reasoningTokens: Number(r.reasoning_tokens),
2136
+ usdMicros: Number(r.usd_micros),
2137
+ usdMicrosMeasured: Number(r.usd_micros_measured),
2138
+ calls: Number(r.calls),
2139
+ };
2140
+ },
2141
+ async listSpendLedger(org, filter = {}) {
2142
+ // Filtered in the QUERY, exactly as the sqlite adapter filters it (OPE-1653) — one
2143
+ // `spendLedgerConjuncts` assembly, rendered to $n here. `org` takes $1 when it is named, so
2144
+ // the conjunct offset is the count of params already placed, never a constant.
2145
+ const { conjuncts, params } = spendLedgerConjuncts(filter);
2146
+ const orgParams = org !== undefined ? [org] : [];
2147
+ const where = [...(org !== undefined ? ["org_id = $1"] : []), ...renderSpendConjuncts(conjuncts, orgParams.length)];
2148
+ const { rows } = await client.query(`SELECT * FROM spend_ledger${where.length ? ` WHERE ${where.join(" AND ")}` : ""}`, [...orgParams, ...params]);
2149
+ return rows.map(spendRowFromPg);
2150
+ },
2151
+ async listRoutines(org, surfaceKey) {
2152
+ const { rows } = await client.query("SELECT data FROM routine WHERE org_id = $1 AND surface_key = $2", [org, surfaceKey]);
2153
+ return rows.map((r) => JSON.parse(r.data));
2154
+ },
2155
+ async getRoutine(org, surfaceKey, id) {
2156
+ const { rows } = await client.query("SELECT data FROM routine WHERE org_id = $1 AND id = $2 AND surface_key = $3", [org, id, surfaceKey]);
2157
+ const row = rows[0];
2158
+ return row ? JSON.parse(row.data) : null;
2159
+ },
2160
+ async addRoutine(routine) {
2161
+ await client.query("INSERT INTO routine (org_id, id, surface_key, data) VALUES ($1, $2, $3, $4)", [
2162
+ routine.org,
2163
+ routine.id,
2164
+ routine.surfaceKey,
2165
+ JSON.stringify(routine),
2166
+ ]);
2167
+ return routine;
2168
+ },
2169
+ async updateRoutine(org, surfaceKey, id, patch, provenance) {
2170
+ const { rows } = await client.query("SELECT data FROM routine WHERE org_id = $1 AND id = $2 AND surface_key = $3", [org, id, surfaceKey]);
2171
+ const row = rows[0];
2172
+ if (!row)
2173
+ return null;
2174
+ const existing = JSON.parse(row.data);
2175
+ const updated = { ...existing, ...patch, id: existing.id, org: existing.org, surfaceKey: existing.surfaceKey };
2176
+ // Record the revision BEFORE the destructive UPDATE, and only when the patch actually replaces the prompt. The PgClient port is query-only with no transaction seam, so the two writes can tear: recording first makes the reachable tear an EXTRA revision for a prompt that failed to land, instead of a live prompt whose predecessor was destroyed unrecorded.
2177
+ if (patch.prompt !== undefined && patch.prompt !== existing.prompt) {
2178
+ const prior = await client.query("SELECT 1 FROM routine_prompt_revisions WHERE org_id = $1 AND surface_key = $2 AND routine_id = $3 LIMIT 1", [org, surfaceKey, id]);
2179
+ const writes = routinePromptRevisionWrites({
2180
+ existing,
2181
+ updated,
2182
+ ...(provenance ? { provenance } : {}),
2183
+ hasPriorRevisions: prior.rows.length > 0,
2184
+ nowIso: new Date().toISOString(),
2185
+ });
2186
+ for (const w of writes) {
2187
+ await client.query(`INSERT INTO routine_prompt_revisions (org_id, surface_key, routine_id, prompt, generation, authored_by, armed_by, approval_id, recorded_at)
2188
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`, [org, surfaceKey, id, w.prompt, w.generation, w.authoredBy ?? null, w.armedBy ?? null, w.approvalId ?? null, w.recordedAt]);
2189
+ }
2190
+ }
2191
+ await client.query("UPDATE routine SET data = $1 WHERE org_id = $2 AND id = $3", [JSON.stringify(updated), org, id]);
2192
+ return updated;
2193
+ },
2194
+ async listRoutinePromptRevisions(org, surfaceKey, routineId) {
2195
+ const { rows } = await client.query(`SELECT seq, routine_id, prompt, generation, authored_by, armed_by, approval_id, recorded_at
2196
+ FROM routine_prompt_revisions
2197
+ WHERE org_id = $1 AND surface_key = $2 AND ($3::text IS NULL OR routine_id = $3)
2198
+ ORDER BY seq`, [org, surfaceKey, routineId ?? null]);
2199
+ return rows.map((r) => ({
2200
+ seq: Number(r.seq), // bigint arrives as a string on some drivers
2201
+ org,
2202
+ surfaceKey,
2203
+ routineId: r.routine_id,
2204
+ prompt: r.prompt,
2205
+ ...(r.generation === null ? {} : { generation: Number(r.generation) }),
2206
+ ...(r.authored_by ? { authoredBy: r.authored_by } : {}),
2207
+ ...(r.armed_by ? { armedBy: r.armed_by } : {}),
2208
+ ...(r.approval_id ? { approvalId: r.approval_id } : {}),
2209
+ recordedAt: r.recorded_at,
2210
+ }));
2211
+ },
2212
+ async removeRoutine(org, surfaceKey, id) {
2213
+ const { rows } = await client.query("DELETE FROM routine WHERE org_id = $1 AND id = $2 AND surface_key = $3 RETURNING id", [org, id, surfaceKey]);
2214
+ return rows.length > 0;
2215
+ },
2216
+ async listAllRoutines() {
2217
+ const { rows } = await client.query("SELECT data FROM routine");
2218
+ return rows.map((r) => JSON.parse(r.data));
2219
+ },
2220
+ async appendAudit(entry) {
2221
+ // Hash-chain link: stamp prev_sha with the sha256 of the org's current LAST row. The read and the insert are two round trips, so both run inside one transaction behind the per-org advisory lock (withAuditChainLock) - two writers that read the same tail would otherwise fork the chain.
2222
+ await withAuditChainLock(client, entry.org, async (conn) => {
2223
+ const prevSha = await nextAuditPrevSha(conn, entry.org);
2224
+ await conn.query(`INSERT INTO audit_entry (ts, org_id, platform, workspace, surface, surface_mode, principal_id, action, detail, prev_sha)
2225
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)`, [
2226
+ entry.ts,
2227
+ entry.org,
2228
+ entry.platform,
2229
+ entry.workspace,
2230
+ entry.surface ?? null,
2231
+ entry.surfaceMode ?? null,
2232
+ entry.principalId ?? null,
2233
+ entry.action,
2234
+ entry.detail ? JSON.stringify(entry.detail) : null,
2235
+ prevSha,
2236
+ ]);
2237
+ });
2238
+ },
2239
+ async readAudit(filter) {
2240
+ // Refuse before the builder runs (OPE-1812): every other predicate is optional, so an absent
2241
+ // org would simply leave `WHERE` empty and read every org's rows.
2242
+ const org = auditReadOrg(filter);
2243
+ const where = [];
2244
+ const params = [];
2245
+ const eq = (col, val) => {
2246
+ if (val !== undefined) {
2247
+ params.push(val);
2248
+ where.push(`${col} = $${params.length}`);
2249
+ }
2250
+ };
2251
+ eq("org_id", org);
2252
+ eq("platform", filter.platform);
2253
+ eq("workspace", filter.workspace);
2254
+ eq("surface", filter.surface);
2255
+ eq("action", filter.action);
2256
+ eq("principal_id", filter.principalId);
2257
+ if (filter.since !== undefined) {
2258
+ params.push(filter.since);
2259
+ where.push(`ts >= $${params.length}`);
2260
+ }
2261
+ if (filter.until !== undefined) {
2262
+ params.push(filter.until);
2263
+ where.push(`ts <= $${params.length}`);
2264
+ }
2265
+ const clause = where.length ? `WHERE ${where.join(" AND ")}` : "";
2266
+ let limitClause = "";
2267
+ if (filter.limit && filter.limit > 0) {
2268
+ params.push(filter.limit);
2269
+ limitClause = `LIMIT $${params.length}`;
2270
+ }
2271
+ const { rows } = await client.query(
2272
+ // `seq` rides along (OPE-1933): it is already the ORDER BY tiebreak, and it is the only
2273
+ // monotonic locator a reader can anchor on when the box's wall clock steps backward.
2274
+ // `surface_mode` is the anti-doxxing mask's input (OPE-1866).
2275
+ `SELECT seq, ts, org_id, platform, workspace, surface, surface_mode, principal_id, action, detail
2276
+ FROM audit_entry ${clause} ORDER BY ts DESC, seq DESC ${limitClause}`, params);
2277
+ return rows.map((r) => ({
2278
+ seq: Number(r.seq),
2279
+ ts: r.ts,
2280
+ org: r.org_id,
2281
+ platform: r.platform,
2282
+ workspace: r.workspace,
2283
+ ...(r.surface ? { surface: r.surface } : {}),
2284
+ ...auditSurfaceMode(r.surface_mode),
2285
+ ...(r.principal_id ? { principalId: r.principal_id } : {}),
2286
+ action: r.action,
2287
+ ...(r.detail ? { detail: JSON.parse(r.detail) } : {}),
2288
+ }));
2289
+ },
2290
+ async listAuditOrgs() {
2291
+ const { rows } = await client.query("SELECT DISTINCT org_id FROM audit_entry ORDER BY org_id");
2292
+ return rows.map((r) => r.org_id);
2293
+ },
2294
+ async readAuditChain(org, opts) {
2295
+ return readAuditChainRows(client, org, opts?.tailLimit);
2296
+ },
2297
+ async sealAuditChainEpoch(org, sealedBy) {
2298
+ // The read and the INSERT MUST be one critical section: a row appended between them would land after the era the seal claims to cover, and the seal would be born wrong. The cost is this org's appends - the section holds the org's ENTIRE chain read, seconds on a 53k-row log over a hosted endpoint, and every concurrent append waits up to AUDIT_CHAIN_LOCK_TIMEOUT_MS and then drops best-effort, so do not seal a busy org unaware.
2299
+ return withAuditChainLock(client, org, async (conn) => {
2300
+ const rows = await readAuditChainRows(conn, org);
2301
+ const seal = auditEpochSealFor(rows);
2302
+ if (seal === null)
2303
+ return null;
2304
+ const { rows: written } = await conn.query(`INSERT INTO audit_entry (ts, org_id, platform, workspace, principal_id, action, detail, prev_sha)
2305
+ VALUES ($1, $2, 'db', 'postgres', $3, $4, $5, NULL) RETURNING seq`, [new Date().toISOString(), org, sealedBy, AUDIT_CHAIN_EPOCH_ACTION, JSON.stringify(auditEpochDetail(seal))]);
2306
+ return { seal, markerSeq: Number(written[0].seq) };
2307
+ });
2308
+ },
2309
+ async setSpendLimit(org, scopeKey, level, limit, meta, condition) {
2310
+ assertSpendLimitAmount(limit);
2311
+ // Same encodings as the SQLite adapter (kept identical so one documented rule
2312
+ // covers both backings): monthly_tokens = -1 means "no token component" (the
2313
+ // column predates USD caps and is NOT NULL in every existing DB); monthly_usd
2314
+ // NULL means "no USD component". spendLimits() decodes both to `undefined`.
2315
+ const params = [org, scopeKey, level, limit.monthlyTokens ?? -1, limit.monthlyUsd ?? null, meta?.expiresAt ?? null, meta?.reason ?? null, meta?.setBy ?? null];
2316
+ const { rows } = condition?.ifAbsent
2317
+ ? await client.query(`INSERT INTO spend_limit (org_id, scope_key, level, monthly_tokens, monthly_usd, expires_at, reason, set_by) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
2318
+ ON CONFLICT (org_id, scope_key, level) DO NOTHING
2319
+ RETURNING scope_key`, params)
2320
+ : await client.query(`INSERT INTO spend_limit (org_id, scope_key, level, monthly_tokens, monthly_usd, expires_at, reason, set_by) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
2321
+ ON CONFLICT (org_id, scope_key, level) DO UPDATE SET
2322
+ monthly_tokens = excluded.monthly_tokens,
2323
+ monthly_usd = excluded.monthly_usd,
2324
+ expires_at = excluded.expires_at,
2325
+ reason = excluded.reason,
2326
+ set_by = excluded.set_by
2327
+ RETURNING scope_key`, params);
2328
+ return rows.length > 0;
2329
+ },
2330
+ async clearSpendLimit(org, scopeKey, level, expected) {
2331
+ const expectedSql = expected
2332
+ ? " AND monthly_tokens IS NOT DISTINCT FROM $4 AND monthly_usd IS NOT DISTINCT FROM $5 AND expires_at IS NOT DISTINCT FROM $6 AND reason IS NOT DISTINCT FROM $7 AND set_by IS NOT DISTINCT FROM $8"
2333
+ : "";
2334
+ const params = expected
2335
+ ? [org, scopeKey, level, expected.monthlyTokens ?? -1, expected.monthlyUsd ?? null, expected.expiresAt ?? null, expected.reason ?? null, expected.setBy ?? null]
2336
+ : [org, scopeKey, level];
2337
+ const { rows } = await client.query(`DELETE FROM spend_limit WHERE org_id = $1 AND scope_key = $2 AND level = $3${expectedSql} RETURNING scope_key`, params);
2338
+ return rows.length > 0;
2339
+ },
2340
+ async spendLimits(org) {
2341
+ const { rows } = await client.query("SELECT scope_key, level, monthly_tokens, monthly_usd, expires_at, reason, set_by FROM spend_limit WHERE org_id = $1", [org]);
2342
+ return rows.map((r) => ({
2343
+ org,
2344
+ scopeKey: r.scope_key,
2345
+ level: r.level,
2346
+ // Decode the storage encodings (see setSpendLimit): -1 tokens / NULL usd =
2347
+ // component absent.
2348
+ ...(Number(r.monthly_tokens) >= 0 ? { monthlyTokens: Number(r.monthly_tokens) } : {}),
2349
+ ...(r.monthly_usd != null ? { monthlyUsd: Number(r.monthly_usd) } : {}),
2350
+ ...(r.expires_at != null ? { expiresAt: Number(r.expires_at) } : {}),
2351
+ ...(r.reason ? { reason: r.reason } : {}),
2352
+ ...(r.set_by ? { setBy: r.set_by } : {}),
2353
+ }));
2354
+ },
2355
+ async setHalt(org, address, meta) {
2356
+ assertHaltAddress(address);
2357
+ const a = haltAddressColumns(address);
2358
+ // Same upsert semantics as the SQLite adapter: restamp who/when, drop the previous resume
2359
+ // stamps so a cleared_at never sits beside an active row.
2360
+ await client.query(`INSERT INTO halt (org_id, level, scope_key, org_wide, active, set_by, set_at, set_ref, cleared_by, cleared_at) VALUES ($1, $2, $3, $4, true, $5, $6, $7, NULL, NULL)
2361
+ ON CONFLICT (org_id, level, scope_key, org_wide) DO UPDATE SET
2362
+ active = true,
2363
+ set_by = excluded.set_by,
2364
+ set_at = excluded.set_at,
2365
+ set_ref = excluded.set_ref,
2366
+ cleared_by = NULL,
2367
+ cleared_at = NULL`, [org, a.level, a.scopeKey, a.orgWide, meta?.setBy ?? null, meta?.setAt ?? new Date().toISOString(), meta?.setRef ?? null]);
2368
+ },
2369
+ async clearHalt(org, address, meta, expected) {
2370
+ assertHaltAddress(address);
2371
+ const a = haltAddressColumns(address);
2372
+ const expectedSql = expected ? " AND set_at = $7 AND set_by IS NOT DISTINCT FROM $8 AND set_ref IS NOT DISTINCT FROM $9" : "";
2373
+ const params = [meta?.clearedBy ?? null, new Date().toISOString(), org, a.level, a.scopeKey, a.orgWide, ...(expected ? [expected.setAt, expected.setBy ?? null, expected.setRef ?? null] : [])];
2374
+ const { rows } = await client.query(`UPDATE halt SET active = false, cleared_by = $1, cleared_at = $2 WHERE org_id = $3 AND level = $4 AND scope_key = $5 AND org_wide = $6 AND active = true${expectedSql} RETURNING org_id`, params);
2375
+ return rows.length > 0;
2376
+ },
2377
+ async activeHalts(org) {
2378
+ const { rows } = await client.query("SELECT level, scope_key, org_wide, set_by, set_at, set_ref, cleared_by, cleared_at FROM halt WHERE org_id = $1 AND active = true", [org]);
2379
+ return rows.map((r) => ({
2380
+ org,
2381
+ address: haltAddressFromColumns(r.level, r.scope_key, r.org_wide === true),
2382
+ active: true,
2383
+ setAt: r.set_at,
2384
+ ...(r.set_by ? { setBy: r.set_by } : {}),
2385
+ ...(r.set_ref ? { setRef: r.set_ref } : {}),
2386
+ ...(r.cleared_by ? { clearedBy: r.cleared_by } : {}),
2387
+ ...(r.cleared_at ? { clearedAt: r.cleared_at } : {}),
2388
+ }));
2389
+ },
2390
+ async setConnectorOverride(org, scopeKey, connector, granted, meta) {
2391
+ await client.query(`INSERT INTO connector_override (org_id, scope_key, connector, granted, reason, set_by) VALUES ($1, $2, $3, $4, $5, $6)
2392
+ ON CONFLICT (org_id, scope_key, connector) DO UPDATE SET
2393
+ granted = excluded.granted,
2394
+ reason = excluded.reason,
2395
+ set_by = excluded.set_by`, [org, scopeKey, connector, granted, meta?.reason ?? null, meta?.setBy ?? null]);
2396
+ },
2397
+ async clearConnectorOverride(org, scopeKey, connector) {
2398
+ const { rows } = await client.query("DELETE FROM connector_override WHERE org_id = $1 AND scope_key = $2 AND connector = $3 RETURNING connector", [org, scopeKey, connector]);
2399
+ return rows.length > 0;
2400
+ },
2401
+ async connectorOverrides(org, scopeKey) {
2402
+ // Hot gate path — only the fields the connector gate needs. reason/setBy are read by allConnectorOverrides.
2403
+ const { rows } = await client.query("SELECT connector, granted FROM connector_override WHERE org_id = $1 AND scope_key = $2", [org, scopeKey]);
2404
+ return rows.map((r) => ({ connector: r.connector, granted: r.granted }));
2405
+ },
2406
+ async allConnectorOverrides(org) {
2407
+ const { rows } = await client.query("SELECT scope_key, connector, granted, reason, set_by FROM connector_override WHERE org_id = $1", [org]);
2408
+ return rows.map((r) => ({ scopeKey: r.scope_key, connector: r.connector, granted: r.granted, ...(r.reason ? { reason: r.reason } : {}), ...(r.set_by ? { setBy: r.set_by } : {}) }));
2409
+ },
2410
+ async setDomainModel(org, domain, pick, setBy) {
2411
+ assertDomainModelPick(pick);
2412
+ await client.query(`INSERT INTO domain_model (org_id, domain, model_id, reasoning, set_by, updated_at) VALUES ($1, $2, $3, $4, $5, $6)
2413
+ ON CONFLICT (org_id, domain) DO UPDATE SET
2414
+ model_id = excluded.model_id,
2415
+ reasoning = excluded.reasoning,
2416
+ set_by = excluded.set_by,
2417
+ updated_at = excluded.updated_at`, [org, domain, pick.modelId ?? null, pick.reasoning ?? null, setBy ?? null, new Date().toISOString()]);
2418
+ },
2419
+ async clearDomainModel(org, domain) {
2420
+ const { rows } = await client.query("DELETE FROM domain_model WHERE org_id = $1 AND domain = $2 RETURNING domain", [org, domain]);
2421
+ return rows.length > 0;
2422
+ },
2423
+ async getDomainModel(org, domain) {
2424
+ const { rows } = await client.query("SELECT model_id, reasoning, set_by, updated_at FROM domain_model WHERE org_id = $1 AND domain = $2", [org, domain]);
2425
+ const r = rows[0];
2426
+ if (!r)
2427
+ return null;
2428
+ return {
2429
+ org,
2430
+ domain,
2431
+ ...(r.model_id ? { modelId: r.model_id } : {}),
2432
+ ...(r.reasoning ? { reasoning: r.reasoning } : {}),
2433
+ ...(r.set_by ? { setBy: r.set_by } : {}),
2434
+ updatedAt: r.updated_at,
2435
+ };
2436
+ },
2437
+ async domainModels(org) {
2438
+ const { rows } = await client.query("SELECT domain, model_id, reasoning, set_by, updated_at FROM domain_model WHERE org_id = $1 ORDER BY domain", [org]);
2439
+ return rows.map((r) => ({
2440
+ org,
2441
+ domain: r.domain,
2442
+ ...(r.model_id ? { modelId: r.model_id } : {}),
2443
+ ...(r.reasoning ? { reasoning: r.reasoning } : {}),
2444
+ ...(r.set_by ? { setBy: r.set_by } : {}),
2445
+ updatedAt: r.updated_at,
2446
+ }));
2447
+ },
2448
+ async markEngaged(org, surfaceKey, threadTs, at, opts) {
2449
+ // kind is set ONLY at first touch and is deliberately absent from the ON CONFLICT SET clause; participating is an OR so a refresh never downgrades a promotion, and only a promotion clears silent_streak. engaged_by carries the durable engage-idempotency rule - a promotion from ANY id the row's framed list already holds never clears stopped - and this statement frames a legacy bare id itself, because initOperationalSchema runs no migration for a non-owner runtime role.
2450
+ const framed = opts?.participating && opts?.engagedBy ? framePromoterId(opts.engagedBy) : null;
2451
+ await client.query(`INSERT INTO thread_engagement (org_id, surface_key, thread_ts, engaged_at, last_turn_at, participating, silent_streak, owner_token, kind, stopped, engaged_by)
2452
+ VALUES ($1, $2, $3, $4, $5, $6, 0, $7, $8, false, $9)
2453
+ ON CONFLICT (org_id, surface_key, thread_ts) DO UPDATE SET
2454
+ last_turn_at = excluded.last_turn_at,
2455
+ participating = thread_engagement.participating OR excluded.participating,
2456
+ silent_streak = CASE WHEN excluded.participating THEN 0 ELSE thread_engagement.silent_streak END,
2457
+ owner_token = COALESCE(excluded.owner_token, thread_engagement.owner_token),
2458
+ stopped = CASE
2459
+ WHEN excluded.participating
2460
+ AND (excluded.engaged_by IS NULL
2461
+ OR strpos(CASE WHEN thread_engagement.engaged_by IS NULL OR thread_engagement.engaged_by = '' THEN chr(10)
2462
+ WHEN substr(thread_engagement.engaged_by, 1, 1) = chr(10) THEN thread_engagement.engaged_by
2463
+ ELSE chr(10) || thread_engagement.engaged_by || chr(10) END,
2464
+ excluded.engaged_by) = 0)
2465
+ THEN false ELSE thread_engagement.stopped END,
2466
+ engaged_by = CASE
2467
+ WHEN excluded.participating AND excluded.engaged_by IS NOT NULL
2468
+ THEN replace(CASE WHEN thread_engagement.engaged_by IS NULL OR thread_engagement.engaged_by = '' THEN chr(10)
2469
+ WHEN substr(thread_engagement.engaged_by, 1, 1) = chr(10) THEN thread_engagement.engaged_by
2470
+ ELSE chr(10) || thread_engagement.engaged_by || chr(10) END,
2471
+ excluded.engaged_by, chr(10)) || substr(excluded.engaged_by, 2)
2472
+ ELSE thread_engagement.engaged_by END`, [
2473
+ org,
2474
+ surfaceKey,
2475
+ threadTs,
2476
+ at,
2477
+ at,
2478
+ opts?.participating ?? false,
2479
+ opts?.ownerToken ?? null,
2480
+ opts?.kind ?? "thread",
2481
+ framed,
2482
+ ]);
2483
+ if (framed === null)
2484
+ return;
2485
+ // THE BOUND — the SQLite twin's second statement, same reasoning: the clear decision and the
2486
+ // append ride the one atomic statement above, and the trim is bookkeeping that drops at most
2487
+ // one entry per promotion, which is all a one-entry append can ever need. A crash between the
2488
+ // two leaves the list one entry OVER the bound, where it stays — see the SQLite twin.
2489
+ await client.query(`UPDATE thread_engagement
2490
+ SET engaged_by = substr(engaged_by, strpos(substr(engaged_by, 2), chr(10)) + 1)
2491
+ WHERE org_id = $1 AND surface_key = $2 AND thread_ts = $3
2492
+ AND engaged_by IS NOT NULL
2493
+ AND length(engaged_by) - length(replace(engaged_by, chr(10), '')) - 1 > $4`, [org, surfaceKey, threadTs, PROMOTER_LIST_MAX]);
2494
+ },
2495
+ async markStopped(org, surfaceKey, threadTs) {
2496
+ // Set the durable stopped marker on an EXISTING row (task #100 follow-up); no INSERT —
2497
+ // a stop only applies to a thread that already carries a row. Missing row → 0 rows
2498
+ // returned → false. Idempotent. Kept semantically identical to the SQLite adapter.
2499
+ const { rows } = await client.query("UPDATE thread_engagement SET stopped = true WHERE org_id = $1 AND surface_key = $2 AND thread_ts = $3 RETURNING thread_ts", [org, surfaceKey, threadTs]);
2500
+ return rows.length > 0;
2501
+ },
2502
+ async bumpSilentStreak(org, surfaceKey, threadTs) {
2503
+ // RETURNING hands back the post-increment value; a missing row updates nothing →
2504
+ // no rows returned → 0 (no-op, nothing to shed).
2505
+ const { rows } = await client.query(`UPDATE thread_engagement SET silent_streak = silent_streak + 1
2506
+ WHERE org_id = $1 AND surface_key = $2 AND thread_ts = $3 RETURNING silent_streak`, [org, surfaceKey, threadTs]);
2507
+ const r = rows[0];
2508
+ return r ? Number(r.silent_streak) : 0;
2509
+ },
2510
+ async getEngagement(org, surfaceKey, threadTs) {
2511
+ const { rows } = await client.query("SELECT engaged_at, last_turn_at, participating, silent_streak, owner_token, kind, stopped, engaged_by FROM thread_engagement WHERE org_id = $1 AND surface_key = $2 AND thread_ts = $3", [org, surfaceKey, threadTs]);
2512
+ const r = rows[0];
2513
+ return r
2514
+ ? {
2515
+ org,
2516
+ surfaceKey,
2517
+ threadTs,
2518
+ engagedAt: r.engaged_at,
2519
+ lastTurnAt: r.last_turn_at,
2520
+ participating: r.participating,
2521
+ silentStreak: Number(r.silent_streak),
2522
+ ...(r.owner_token ? { ownerToken: r.owner_token } : {}),
2523
+ kind: r.kind ?? "thread",
2524
+ stopped: r.stopped,
2525
+ ...promoterListField(r.engaged_by),
2526
+ }
2527
+ : null;
2528
+ },
2529
+ async disengage(org, surfaceKey, threadTs) {
2530
+ const { rows } = await client.query("DELETE FROM thread_engagement WHERE org_id = $1 AND surface_key = $2 AND thread_ts = $3 RETURNING thread_ts", [org, surfaceKey, threadTs]);
2531
+ return rows.length > 0;
2532
+ },
2533
+ async listEngagements(org) {
2534
+ const { rows } = await client.query("SELECT surface_key, thread_ts, engaged_at, last_turn_at, participating, silent_streak, owner_token, kind, stopped, engaged_by FROM thread_engagement WHERE org_id = $1", [org]);
2535
+ return rows.map((r) => ({
2536
+ org,
2537
+ surfaceKey: r.surface_key,
2538
+ threadTs: r.thread_ts,
2539
+ engagedAt: r.engaged_at,
2540
+ lastTurnAt: r.last_turn_at,
2541
+ participating: r.participating,
2542
+ silentStreak: Number(r.silent_streak),
2543
+ ...(r.owner_token ? { ownerToken: r.owner_token } : {}),
2544
+ kind: r.kind ?? "thread",
2545
+ stopped: r.stopped,
2546
+ ...promoterListField(r.engaged_by),
2547
+ }));
2548
+ },
2549
+ async getChannelSession(org, surfaceKey) {
2550
+ const { rows } = await client.query("SELECT token, generation, created_at, last_wake_at, turn_count, input_tokens_total, first_wake_at, last_input_tokens, rotate_marked_at, served_code_fingerprint, served_domain_fingerprint FROM channel_session WHERE org_id = $1 AND surface_key = $2", [org, surfaceKey]);
2551
+ const r = rows[0];
2552
+ return r
2553
+ ? {
2554
+ org, surfaceKey, token: r.token, generation: Number(r.generation), createdAt: r.created_at,
2555
+ lastWakeAt: r.last_wake_at, turnCount: Number(r.turn_count),
2556
+ inputTokensTotal: r.input_tokens_total == null ? null : Number(r.input_tokens_total),
2557
+ firstWakeAt: r.first_wake_at ?? null,
2558
+ lastInputTokens: r.last_input_tokens == null ? null : Number(r.last_input_tokens),
2559
+ rotateMarkedAt: r.rotate_marked_at ?? null,
2560
+ servedCodeFingerprint: r.served_code_fingerprint ?? null,
2561
+ servedDomainFingerprint: r.served_domain_fingerprint ?? null,
2562
+ }
2563
+ : null;
2564
+ },
2565
+ async rotateChannelSession(org, surfaceKey, newToken, at) {
2566
+ // One INSERT ... ON CONFLICT DO UPDATE computes the next generation FROM THE ROW BEING UPDATED, inside the same statement and row lock (an unqualified column reference in a DO UPDATE SET reads the PRE-update row; excluded.x reads the proposed values), so two concurrent rotations cannot both mint the same value. A fresh generation starts at input_tokens_total = 0 rather than NULL so the NULL-means-rotate fail-safe fires only on pre-migration rows, and rotate_marked_at = NULL SPENDS the operator mark - a mark that survived its own rotation would retire the seat on every wake for ever.
2567
+ const { rows } = await client.query(`INSERT INTO channel_session (org_id, surface_key, token, generation, created_at, last_wake_at, turn_count, input_tokens_total, first_wake_at, last_input_tokens, rotate_marked_at)
2568
+ VALUES ($1, $2, $3, 1, $4, $5, 0, 0, NULL, NULL, NULL)
2569
+ ON CONFLICT (org_id, surface_key) DO UPDATE SET
2570
+ token = excluded.token,
2571
+ generation = channel_session.generation + 1,
2572
+ created_at = excluded.created_at,
2573
+ last_wake_at = excluded.last_wake_at,
2574
+ turn_count = 0,
2575
+ input_tokens_total = 0,
2576
+ first_wake_at = NULL,
2577
+ last_input_tokens = NULL,
2578
+ rotate_marked_at = NULL
2579
+ RETURNING generation, served_code_fingerprint, served_domain_fingerprint`, [org, surfaceKey, newToken, at, at]);
2580
+ // The fingerprint pair is in NEITHER the INSERT column list NOR the DO UPDATE SET, so a fresh
2581
+ // mint starts NULL (adopted by the next wake) and a rotation KEEPS the pair the pre-dispatch
2582
+ // stamp just wrote. Resetting it here would rotate the seat again on its very next wake.
2583
+ const r = rows[0];
2584
+ const generation = Number(r.generation);
2585
+ return {
2586
+ org, surfaceKey, token: newToken, generation, createdAt: at, lastWakeAt: at, turnCount: 0, inputTokensTotal: 0, firstWakeAt: null, lastInputTokens: null, rotateMarkedAt: null,
2587
+ servedCodeFingerprint: r.served_code_fingerprint ?? null,
2588
+ servedDomainFingerprint: r.served_domain_fingerprint ?? null,
2589
+ };
2590
+ },
2591
+ async stampChannelSessionRuntime(org, surfaceKey, codeFingerprint, domainFingerprint) {
2592
+ // ONE statement, so the read and the conditional write cannot interleave with another wake.
2593
+ // Every CTE here shares one snapshot and a data-modifying CTE's effects are invisible to the
2594
+ // others, so `prev` always reports the PRE-update pair. Under a concurrent wake the second
2595
+ // statement blocks on the UPDATE's row lock, re-checks its own WHERE against the updated row
2596
+ // and matches nothing — it answers "current" and the seat's generation retires exactly once.
2597
+ const { rows } = await client.query(`WITH prev AS (
2598
+ SELECT served_code_fingerprint AS c, served_domain_fingerprint AS d
2599
+ FROM channel_session WHERE org_id = $1 AND surface_key = $2
2600
+ ), upd AS (
2601
+ UPDATE channel_session SET served_code_fingerprint = $3, served_domain_fingerprint = $4
2602
+ WHERE org_id = $1 AND surface_key = $2
2603
+ AND (served_code_fingerprint IS DISTINCT FROM $3 OR served_domain_fingerprint IS DISTINCT FROM $4)
2604
+ RETURNING 1
2605
+ )
2606
+ SELECT (SELECT c FROM prev) AS prev_code,
2607
+ (SELECT d FROM prev) AS prev_domain,
2608
+ EXISTS (SELECT 1 FROM prev) AS present,
2609
+ EXISTS (SELECT 1 FROM upd) AS changed`, [org, surfaceKey, codeFingerprint, domainFingerprint]);
2610
+ const r = rows[0];
2611
+ if (!r || !r.present)
2612
+ return { outcome: "absent", previousCodeFingerprint: null, previousDomainFingerprint: null };
2613
+ const previousCodeFingerprint = r.prev_code ?? null;
2614
+ const previousDomainFingerprint = r.prev_domain ?? null;
2615
+ if (!r.changed)
2616
+ return { outcome: "current", previousCodeFingerprint, previousDomainFingerprint };
2617
+ // NULL is ADOPTED, never rotated: the row was minted by this same bundle moments ago (the
2618
+ // mint arm writes no pair) or predates the columns, and neither proves the code changed.
2619
+ return { outcome: previousCodeFingerprint === null ? "adopted" : "rotate", previousCodeFingerprint, previousDomainFingerprint };
2620
+ },
2621
+ async markChannelSessionRotation(org, surfaceKey, at) {
2622
+ // UPDATE, never an upsert: a registry key with no row has no generation to retire, and
2623
+ // minting one here would seat a channel nobody woke. COALESCE keeps the FIRST mark's stamp,
2624
+ // so a re-run of the sweep is idempotent and the stamp stays readable as "marked since when".
2625
+ const { rows } = await client.query("UPDATE channel_session SET rotate_marked_at = COALESCE(rotate_marked_at, $3) WHERE org_id = $1 AND surface_key = $2 RETURNING surface_key", [org, surfaceKey, at]);
2626
+ return rows.length > 0;
2627
+ },
2628
+ async touchChannelSession(org, surfaceKey, at) {
2629
+ // first_wake_at is set ONCE (COALESCE) — this runs only after a successful wake, so it
2630
+ // stamps "first wake delivered" (H7c). A later touch leaves it at its first value.
2631
+ await client.query("UPDATE channel_session SET last_wake_at = $1, turn_count = turn_count + 1, first_wake_at = COALESCE(first_wake_at, $1) WHERE org_id = $2 AND surface_key = $3", [at, org, surfaceKey]);
2632
+ },
2633
+ async bumpChannelSessionUsage(org, surfaceKey, token, delta) {
2634
+ // Token-guarded: the UPDATE only lands on the LIVE generation's row, so a straggler
2635
+ // step from a retired generation (a rotation-boundary race) is a no-op — no phantom
2636
+ // counting across a rotation. NULL counter ⇒ COALESCE'd to 0 first (backfill posture).
2637
+ // ONE write, TWO rungs (OPE-794): the running SUM feeds the cumulative backstop, the SET
2638
+ // value feeds the context-size trigger. They share this statement so they can never disagree
2639
+ // about which step they saw, and the token guard covers both.
2640
+ const { rows } = await client.query("UPDATE channel_session SET input_tokens_total = COALESCE(input_tokens_total, 0) + $4, last_input_tokens = $4 WHERE org_id = $1 AND surface_key = $2 AND token = $3 RETURNING surface_key", [org, surfaceKey, token, delta]);
2641
+ return rows.length;
2642
+ },
2643
+ async listChannelSessions(org, keyPrefix) {
2644
+ const { rows } = keyPrefix === undefined
2645
+ ? await client.query("SELECT surface_key, token, generation, created_at, last_wake_at, turn_count, input_tokens_total, first_wake_at, last_input_tokens, rotate_marked_at, served_code_fingerprint, served_domain_fingerprint FROM channel_session WHERE org_id = $1", [org])
2646
+ : await client.query(
2647
+ // LIKE with a literal, colon/`::`-only prefix (`oe-domain::`) — no user-controlled
2648
+ // wildcard chars ever reach this call, so a plain concatenation is safe.
2649
+ "SELECT surface_key, token, generation, created_at, last_wake_at, turn_count, input_tokens_total, first_wake_at, last_input_tokens, rotate_marked_at, served_code_fingerprint, served_domain_fingerprint FROM channel_session WHERE org_id = $1 AND surface_key LIKE $2", [org, `${keyPrefix}%`]);
2650
+ return rows.map((r) => ({
2651
+ org, surfaceKey: r.surface_key, token: r.token, generation: Number(r.generation), createdAt: r.created_at,
2652
+ lastWakeAt: r.last_wake_at, turnCount: Number(r.turn_count),
2653
+ inputTokensTotal: r.input_tokens_total == null ? null : Number(r.input_tokens_total),
2654
+ firstWakeAt: r.first_wake_at ?? null,
2655
+ lastInputTokens: r.last_input_tokens == null ? null : Number(r.last_input_tokens),
2656
+ rotateMarkedAt: r.rotate_marked_at ?? null,
2657
+ servedCodeFingerprint: r.served_code_fingerprint ?? null,
2658
+ servedDomainFingerprint: r.served_domain_fingerprint ?? null,
2659
+ }));
2660
+ },
2661
+ async appendSessionTail(org, surfaceKey, token, entry) {
2662
+ // Bounded ON WRITE, in the same round-trip pair as the insert. A ring pruned by a sweep
2663
+ // instead has a window where a hot generation is unbounded, and this table takes a write on
2664
+ // every wake and every post.
2665
+ const { rows } = await client.query(`INSERT INTO session_tail (org_id, surface_key, token, seq, at, entry_json)
2666
+ SELECT $1, $2, $3, COALESCE(MAX(seq), 0) + 1, $4, $5 FROM session_tail WHERE org_id = $1 AND surface_key = $2 AND token = $3
2667
+ RETURNING seq`, [org, surfaceKey, token, entry.at, JSON.stringify(entry)]);
2668
+ const seq = Number(rows[0].seq);
2669
+ await client.query("DELETE FROM session_tail WHERE org_id = $1 AND surface_key = $2 AND token = $3 AND seq <= $4", [
2670
+ org,
2671
+ surfaceKey,
2672
+ token,
2673
+ seq - SESSION_TAIL_MAX_ENTRIES,
2674
+ ]);
2675
+ },
2676
+ async readSessionTail(org, surfaceKey, token) {
2677
+ const { rows } = await client.query("SELECT entry_json FROM session_tail WHERE org_id = $1 AND surface_key = $2 AND token = $3 ORDER BY seq ASC", [org, surfaceKey, token]);
2678
+ // A row whose JSON no longer parses is DROPPED, not thrown on: this feeds a wake, and one bad
2679
+ // row must never cost the whole tail.
2680
+ const out = [];
2681
+ for (const r of rows) {
2682
+ try {
2683
+ out.push(JSON.parse(r.entry_json));
2684
+ }
2685
+ catch {
2686
+ }
2687
+ }
2688
+ return out;
2689
+ },
2690
+ async clearSessionTail(org, surfaceKey, token) {
2691
+ await client.query("DELETE FROM session_tail WHERE org_id = $1 AND surface_key = $2 AND token = $3", [org, surfaceKey, token]);
2692
+ },
2693
+ // The ring's only mutation: rewrite ONE post row's text, matched by its platform message id, after edit_reply's platform-CONFIRMED success - never on a refusal or an ambiguous outcome. entry_json is opaque to this store, so the match happens in JS on the parsed rows rather than in a JSON-in-SQL query, and the kind check skips a wake row that happens to carry the same platform id.
2694
+ async editSessionTailPost(org, surfaceKey, token, messageId, text) {
2695
+ const { rows } = await client.query("SELECT seq, entry_json FROM session_tail WHERE org_id = $1 AND surface_key = $2 AND token = $3 ORDER BY seq DESC", [org, surfaceKey, token]);
2696
+ for (const r of rows) {
2697
+ let entry;
2698
+ try {
2699
+ entry = JSON.parse(r.entry_json);
2700
+ }
2701
+ catch {
2702
+ continue; // an unreadable row can't be the match — readSessionTail drops it too
2703
+ }
2704
+ if (entry.kind !== "post" || entry.id !== messageId)
2705
+ continue;
2706
+ const updated = { ...entry, text };
2707
+ await client.query("UPDATE session_tail SET entry_json = $1 WHERE org_id = $2 AND surface_key = $3 AND token = $4 AND seq = $5", [
2708
+ JSON.stringify(updated),
2709
+ org,
2710
+ surfaceKey,
2711
+ token,
2712
+ r.seq,
2713
+ ]);
2714
+ return true;
2715
+ }
2716
+ return false;
2717
+ },
2718
+ async listDomainSkills(org, domain) {
2719
+ const { rows } = await client.query("SELECT name, content, updated_by, updated_at FROM domain_skill WHERE org_id = $1 AND domain = $2 ORDER BY name", [org, domain]);
2720
+ return rows.map((r) => ({
2721
+ org,
2722
+ domain,
2723
+ name: r.name,
2724
+ content: r.content,
2725
+ ...(r.updated_by ? { updatedBy: r.updated_by } : {}),
2726
+ updatedAt: r.updated_at,
2727
+ }));
2728
+ },
2729
+ async putDomainSkill(org, domain, name, content, updatedBy, updatedAt, provenance) {
2730
+ // Record the REVISION FIRST, then the destructive upsert. The PgClient port is query-only - the Neon HTTP driver has no transaction across calls - so the two writes can tear, and the reachable tear must be an extra revision for a body that failed to arm rather than an armed body with no record of what was approved. Over-record rather than under-record.
2731
+ await client.query(`INSERT INTO domain_skill_revisions (org_id, domain, name, content, authored_by, armed_by, approval_id, recorded_at)
2732
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8)`, [org, domain, name, content, updatedBy ?? null, provenance?.armedBy ?? null, provenance?.approvalId ?? null, updatedAt]);
2733
+ await client.query(`INSERT INTO domain_skill (org_id, domain, name, content, updated_by, updated_at) VALUES ($1, $2, $3, $4, $5, $6)
2734
+ ON CONFLICT (org_id, domain, name) DO UPDATE SET
2735
+ content = excluded.content,
2736
+ updated_by = excluded.updated_by,
2737
+ updated_at = excluded.updated_at`, [org, domain, name, content, updatedBy ?? null, updatedAt]);
2738
+ },
2739
+ async deleteDomainSkill(org, domain, name) {
2740
+ const { rows } = await client.query("DELETE FROM domain_skill WHERE org_id = $1 AND domain = $2 AND name = $3 RETURNING name", [org, domain, name]);
2741
+ return rows.length > 0;
2742
+ },
2743
+ async listDomainSkillRevisions(org, domain, name) {
2744
+ const { rows } = await client.query(`SELECT seq, name, content, authored_by, armed_by, approval_id, recorded_at
2745
+ FROM domain_skill_revisions
2746
+ WHERE org_id = $1 AND domain = $2 AND ($3::text IS NULL OR name = $3)
2747
+ ORDER BY seq`, [org, domain, name ?? null]);
2748
+ return rows.map((r) => ({
2749
+ seq: Number(r.seq), // bigint arrives as a string on some drivers
2750
+ org,
2751
+ domain,
2752
+ name: r.name,
2753
+ content: r.content,
2754
+ ...(r.authored_by ? { authoredBy: r.authored_by } : {}),
2755
+ ...(r.armed_by ? { armedBy: r.armed_by } : {}),
2756
+ ...(r.approval_id ? { approvalId: r.approval_id } : {}),
2757
+ recordedAt: r.recorded_at,
2758
+ }));
2759
+ },
2760
+ async appendUsageEvent(entry) {
2761
+ await client.query(`INSERT INTO usage_events
2762
+ (org_id, surface_key, session_id, principal_id, ts, kind, routine_id,
2763
+ input_tokens, output_tokens, cache_read_tokens, cache_write_tokens, model, detail,
2764
+ usd_micros_measured, cost_source, delegation_depth, root_session_id,
2765
+ cache_tokens_reported, reasoning_tokens, surface_mode)
2766
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20)`, [
2767
+ entry.org,
2768
+ entry.surfaceKey,
2769
+ entry.sessionId,
2770
+ entry.principalId ?? null,
2771
+ entry.ts,
2772
+ entry.kind ?? null,
2773
+ entry.routineId ?? null,
2774
+ entry.inputTokens,
2775
+ entry.outputTokens,
2776
+ entry.cacheReadTokens,
2777
+ entry.cacheWriteTokens,
2778
+ entry.model ?? null,
2779
+ entry.detail ? JSON.stringify(entry.detail) : null,
2780
+ // `?? null` on all four, never `?? 0`/`?? ''` — a NULL says "this writer had nothing to
2781
+ // report", which is a different fact from a measured zero or a root turn's depth 0.
2782
+ entry.usdMicrosMeasured ?? null,
2783
+ entry.costSource ?? null,
2784
+ entry.delegationDepth ?? null,
2785
+ entry.rootSessionId ?? null,
2786
+ entry.cacheTokensReported ?? null,
2787
+ entry.reasoningTokens ?? null,
2788
+ // OPE-1862, same discipline: NULL says "no binding stamped this row", and a report masks
2789
+ // such a row. It is never inferred from the surface id.
2790
+ entry.surfaceMode ?? null,
2791
+ ]);
2792
+ },
2793
+ async usageForSession(org, sessionId) {
2794
+ const { rows } = await client.query(`SELECT surface_key, session_id, principal_id, ts, kind, routine_id,
2795
+ input_tokens, output_tokens, cache_read_tokens, cache_write_tokens, model, detail,
2796
+ usd_micros_measured, cost_source, delegation_depth, root_session_id,
2797
+ cache_tokens_reported, reasoning_tokens, surface_mode
2798
+ FROM usage_events WHERE org_id = $1 AND session_id = $2 ORDER BY seq ASC`, [org, sessionId]);
2799
+ return rows.map((r) => ({
2800
+ org,
2801
+ surfaceKey: r.surface_key,
2802
+ sessionId: r.session_id,
2803
+ ...(r.principal_id ? { principalId: r.principal_id } : {}),
2804
+ ts: r.ts,
2805
+ ...(r.kind ? { kind: r.kind } : {}),
2806
+ ...(r.routine_id ? { routineId: r.routine_id } : {}),
2807
+ inputTokens: Number(r.input_tokens),
2808
+ outputTokens: Number(r.output_tokens),
2809
+ cacheReadTokens: Number(r.cache_read_tokens),
2810
+ cacheWriteTokens: Number(r.cache_write_tokens),
2811
+ ...(r.model ? { model: r.model } : {}),
2812
+ // OPE-369, read back on `!= null` (not truthiness): a measured $0 and a root turn's
2813
+ // depth 0 are both real evidence and must not degrade to "absent". Mirrors sqlite.ts.
2814
+ ...(r.usd_micros_measured != null ? { usdMicrosMeasured: Number(r.usd_micros_measured) } : {}),
2815
+ ...(r.cost_source ? { costSource: r.cost_source === "measured" ? "measured" : "derived" } : {}),
2816
+ ...(r.delegation_depth != null ? { delegationDepth: Number(r.delegation_depth) } : {}),
2817
+ ...(r.root_session_id ? { rootSessionId: r.root_session_id } : {}),
2818
+ ...(r.cache_tokens_reported != null ? { cacheTokensReported: r.cache_tokens_reported } : {}),
2819
+ ...(r.reasoning_tokens != null ? { reasoningTokens: Number(r.reasoning_tokens) } : {}),
2820
+ // OPE-1862: only the three declared spellings become a mode; every other value stays
2821
+ // ABSENT, which the report mask treats as unclassified and hides. Mirrors sqlite.ts.
2822
+ ...(() => {
2823
+ const mode = asSurfaceMode(r.surface_mode);
2824
+ return mode ? { surfaceMode: mode } : {};
2825
+ })(),
2826
+ ...(r.detail ? { detail: JSON.parse(r.detail) } : {}),
2827
+ }));
2828
+ },
2829
+ async usageSummary(org, filter = {}) {
2830
+ const where = ["org_id = $1"];
2831
+ const params = [org];
2832
+ if (filter.surfaceKeyPrefix !== undefined) {
2833
+ params.push(`${filter.surfaceKeyPrefix}%`);
2834
+ where.push(`surface_key LIKE $${params.length}`);
2835
+ }
2836
+ if (filter.sinceTs !== undefined) {
2837
+ params.push(filter.sinceTs);
2838
+ where.push(`ts >= $${params.length}`);
2839
+ }
2840
+ if (filter.untilTs !== undefined) {
2841
+ params.push(filter.untilTs);
2842
+ where.push(`ts <= $${params.length}`);
2843
+ }
2844
+ // OPE-402: exclude rows whose session had ANY recorded usage event before the bound — the
2845
+ // session-scoped half of the leak sinceTs alone cannot close (see UsageSummaryFilter's doc).
2846
+ // Reuses org_id = $1 from the outer WHERE inside the subquery (same query, same param list),
2847
+ // and rides the existing (org_id, session_id) index (usage_events_org_session).
2848
+ if (filter.sessionStartedAfter !== undefined) {
2849
+ params.push(filter.sessionStartedAfter);
2850
+ where.push(`session_id IN (SELECT session_id FROM usage_events WHERE org_id = $1 GROUP BY session_id HAVING MIN(ts) >= $${params.length})`);
2851
+ }
2852
+ const { rows } = await client.query(`SELECT surface_key, principal_id, kind, routine_id, model, surface_mode,
2853
+ SUM(input_tokens) AS input_tokens, SUM(output_tokens) AS output_tokens,
2854
+ SUM(cache_read_tokens) AS cache_read_tokens, SUM(cache_write_tokens) AS cache_write_tokens,
2855
+ -- OPE-1611: the attribution dimension AND its coverage. COALESCE keeps the sum an
2856
+ -- integer when every row is NULL; the two counts say how many calls actually
2857
+ -- reported, so a reader never mistakes an all-NULL group's 0 for "no caching".
2858
+ COALESCE(SUM(reasoning_tokens), 0) AS reasoning_tokens,
2859
+ COUNT(*) FILTER (WHERE cache_tokens_reported) AS cache_reported_calls,
2860
+ COUNT(reasoning_tokens) AS reasoning_reported_calls,
2861
+ COUNT(*) AS events, COUNT(DISTINCT session_id) AS sessions
2862
+ FROM usage_events WHERE ${where.join(" AND ")}
2863
+ -- OPE-1862: surface_mode joins the GRAIN rather than riding along as MAX(). A group must
2864
+ -- be homogeneous in every column it reports, and one surface can hold both unstamped
2865
+ -- legacy rows and stamped new ones; those two masks differently, so they must not blend.
2866
+ GROUP BY surface_key, principal_id, kind, routine_id, model, surface_mode`, params);
2867
+ return rows.map((r) => ({
2868
+ surfaceKey: r.surface_key,
2869
+ ...(r.principal_id ? { principalId: r.principal_id } : {}),
2870
+ ...(r.kind ? { kind: r.kind } : {}),
2871
+ ...(r.routine_id ? { routineId: r.routine_id } : {}),
2872
+ ...(r.model ? { model: r.model } : {}),
2873
+ ...(() => {
2874
+ const mode = asSurfaceMode(r.surface_mode);
2875
+ return mode ? { surfaceMode: mode } : {};
2876
+ })(),
2877
+ inputTokens: Number(r.input_tokens),
2878
+ outputTokens: Number(r.output_tokens),
2879
+ cacheReadTokens: Number(r.cache_read_tokens),
2880
+ cacheWriteTokens: Number(r.cache_write_tokens),
2881
+ reasoningTokens: Number(r.reasoning_tokens),
2882
+ cacheReportedCalls: Number(r.cache_reported_calls),
2883
+ reasoningReportedCalls: Number(r.reasoning_reported_calls),
2884
+ events: Number(r.events),
2885
+ sessions: Number(r.sessions),
2886
+ }));
2887
+ },
2888
+ async pruneUsageEvents() {
2889
+ // NO-OP under Postgres by design: usage_events is append-only at the DB layer
2890
+ // (SELECT+INSERT-only RLS under FORCE — see the schema comment above), so no role
2891
+ // short of a superuser (owner included) can DELETE from it. Real retention here needs
2892
+ // a maintenance path outside this seam (a migration-role-owned SECURITY DEFINER prune);
2893
+ // sqlite.ts prunes for real (local/dev is single-tenant-trusted, no such gate).
2894
+ return 0;
2895
+ },
2896
+ async appendModelCallCapture(write) {
2897
+ await client.query(`INSERT INTO model_call_capture
2898
+ (org_id, surface_key, session_id, turn_id, step_index, ts, model, provider,
2899
+ schema_version, sha256, body_bytes, body_gzip_b64, truncated)
2900
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)`, [
2901
+ write.org,
2902
+ write.surfaceKey,
2903
+ write.sessionId,
2904
+ write.turnId,
2905
+ write.stepIndex,
2906
+ write.ts,
2907
+ write.model,
2908
+ write.provider,
2909
+ write.schemaVersion,
2910
+ write.sha256,
2911
+ write.bodyBytes,
2912
+ write.bodyGzipB64,
2913
+ write.truncated,
2914
+ ]);
2915
+ },
2916
+ async modelCallCapturesForSession(org, sessionId, opts = {}) {
2917
+ const includeBody = opts.includeBody !== false;
2918
+ // The body column is selected only when asked for — a metadata read must not drag tens of MB
2919
+ // of prompt bytes across the wire for a count.
2920
+ const bodyCol = includeBody ? "body_gzip_b64" : "'' AS body_gzip_b64";
2921
+ const where = ["org_id = $1", "session_id = $2"];
2922
+ const params = [org, sessionId];
2923
+ if (opts.turnId !== undefined) {
2924
+ params.push(opts.turnId);
2925
+ where.push(`turn_id = $${params.length}`);
2926
+ }
2927
+ let limit = "";
2928
+ if (opts.limit !== undefined) {
2929
+ params.push(Math.max(0, Math.floor(opts.limit)));
2930
+ limit = ` LIMIT $${params.length}`;
2931
+ }
2932
+ const { rows } = await client.query(`SELECT seq, surface_key, session_id, turn_id, step_index, ts, model, provider,
2933
+ schema_version, sha256, body_bytes, ${bodyCol}, truncated
2934
+ FROM model_call_capture WHERE ${where.join(" AND ")} ORDER BY seq ASC${limit}`, params);
2935
+ return rows.map((r) => ({
2936
+ seq: Number(r.seq),
2937
+ org,
2938
+ surfaceKey: r.surface_key,
2939
+ sessionId: r.session_id,
2940
+ turnId: r.turn_id,
2941
+ stepIndex: Number(r.step_index),
2942
+ ts: r.ts,
2943
+ model: r.model,
2944
+ provider: r.provider,
2945
+ schemaVersion: Number(r.schema_version),
2946
+ sha256: r.sha256,
2947
+ bodyBytes: Number(r.body_bytes),
2948
+ bodyGzipB64: r.body_gzip_b64,
2949
+ truncated: r.truncated === true,
2950
+ }));
2951
+ },
2952
+ async modelCallCaptureSessions(org) {
2953
+ const { rows } = await client.query(`SELECT session_id, MIN(ts) AS first_ts, MAX(ts) AS last_ts, COUNT(*) AS row_count, SUM(body_bytes) AS total_bytes
2954
+ FROM model_call_capture WHERE org_id = $1
2955
+ GROUP BY session_id
2956
+ ORDER BY MAX(ts) DESC`, [org]);
2957
+ return rows.map((r) => ({
2958
+ sessionId: r.session_id,
2959
+ firstTs: r.first_ts,
2960
+ lastTs: r.last_ts,
2961
+ rowCount: Number(r.row_count),
2962
+ totalBytes: Number(r.total_bytes ?? 0),
2963
+ }));
2964
+ },
2965
+ async deleteModelCallCapturesForSession(org, sessionId) {
2966
+ // A REAL delete here, unlike pruneUsageEvents above: this table is not append-only, precisely
2967
+ // so that the harvest-then-drop retention story holds on the deployed Postgres too.
2968
+ // `RETURNING seq` and count the rows — the one-method PgClient port exposes no rowCount, the
2969
+ // same reason every other delete in this file returns its keys.
2970
+ const { rows } = await client.query(`DELETE FROM model_call_capture WHERE org_id = $1 AND session_id = $2 RETURNING seq`, [org, sessionId]);
2971
+ return rows.length;
2972
+ },
2973
+ async addMemoryProposal(write) {
2974
+ const { rows } = await client.query(`INSERT INTO memory_proposal (org_id, kind, scope, summary, before_text, after_text, detail_json, principal_id, created_at)
2975
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
2976
+ RETURNING id`, [
2977
+ write.org,
2978
+ write.kind,
2979
+ write.scope,
2980
+ write.summary,
2981
+ write.before ?? null,
2982
+ write.after ?? null,
2983
+ write.detail ? JSON.stringify(write.detail) : null,
2984
+ write.principalId,
2985
+ write.createdAt,
2986
+ ]);
2987
+ return { ...write, id: Number(rows[0].id) };
2988
+ },
2989
+ async listMemoryProposals(org) {
2990
+ const { rows } = await client.query(`SELECT id, kind, scope, summary, before_text, after_text, detail_json, principal_id, created_at
2991
+ FROM memory_proposal WHERE org_id = $1 ORDER BY id DESC`, [org]);
2992
+ return rows.map((r) => ({
2993
+ id: Number(r.id),
2994
+ org,
2995
+ kind: r.kind,
2996
+ scope: r.scope,
2997
+ summary: r.summary,
2998
+ ...(r.before_text !== null ? { before: r.before_text } : {}),
2999
+ ...(r.after_text !== null ? { after: r.after_text } : {}),
3000
+ ...(r.detail_json ? { detail: JSON.parse(r.detail_json) } : {}),
3001
+ principalId: r.principal_id,
3002
+ createdAt: r.created_at,
3003
+ }));
3004
+ },
3005
+ async getDmAudience(org, address) {
3006
+ const { rows } = await client.query("SELECT address, first_dm_at, stopped_at FROM dm_audience WHERE org_id = $1 AND address = $2", [org, address]);
3007
+ const row = rows[0];
3008
+ return row ? dmAudienceRowFrom(row) : null;
3009
+ },
3010
+ async markDmAudienceDelivered(org, address, at) {
3011
+ // COALESCE keeps the ORIGINAL first_dm_at — see store.ts's method doc. `stopped_at` is not in
3012
+ // the update list at all, so a delivery can never clear a stop even if a caller raced one.
3013
+ await client.query(`INSERT INTO dm_audience (org_id, address, first_dm_at, stopped_at) VALUES ($1, $2, $3, NULL)
3014
+ ON CONFLICT (org_id, address) DO UPDATE SET first_dm_at = COALESCE(dm_audience.first_dm_at, excluded.first_dm_at)`, [org, address, at]);
3015
+ },
3016
+ async setDmAudienceStopped(org, address, at) {
3017
+ // COALESCE for the same reason as above, in the other direction: a second stop keeps the FIRST
3018
+ // stopped_at, so the trail records when the boundary was first drawn rather than last repeated.
3019
+ await client.query(`INSERT INTO dm_audience (org_id, address, first_dm_at, stopped_at) VALUES ($1, $2, NULL, $3)
3020
+ ON CONFLICT (org_id, address) DO UPDATE SET stopped_at = COALESCE(dm_audience.stopped_at, excluded.stopped_at)`, [org, address, at]);
3021
+ },
3022
+ async clearDmAudienceStopped(org, address) {
3023
+ // The `stopped_at IS NOT NULL` conjunct is what makes the return value honest: RETURNING yields
3024
+ // a row only when the UPDATE actually altered one, so a row that was never stopped answers
3025
+ // false rather than reporting a resume that resumed nothing.
3026
+ const { rows } = await client.query("UPDATE dm_audience SET stopped_at = NULL WHERE org_id = $1 AND address = $2 AND stopped_at IS NOT NULL RETURNING address", [org, address]);
3027
+ return rows.length > 0;
3028
+ },
3029
+ async listDmAudience(org) {
3030
+ const { rows } = await client.query("SELECT address, first_dm_at, stopped_at FROM dm_audience WHERE org_id = $1 ORDER BY address", [org]);
3031
+ return rows.map(dmAudienceRowFrom);
3032
+ },
3033
+ async runAnalyticsQuery(compiled) {
3034
+ // OPE-66: assemble the SELECT-only statement with `$n` placeholders (the Postgres style) and
3035
+ // run it read-only. Every non-param token is registry-derived; only `params` bind. Numeric
3036
+ // SUM/COUNT come back as bigint STRINGS — analytics/execute.ts coerces. Org RLS backstops the
3037
+ // org_id scope conjunct (defence in depth, same as every other read here).
3038
+ const { sql, params } = assembleAnalyticsSql(compiled, "dollar");
3039
+ const { rows } = await client.query(sql, params);
3040
+ return rows;
3041
+ },
3042
+ async enqueueIngressDelivery(org, write) {
3043
+ // Only payload-free completed tombstones are clock-pruned. Pending work has NULL retention
3044
+ // and survives an arbitrarily long provider/store outage.
3045
+ await client.query(`DELETE FROM ingress_delivery
3046
+ WHERE org_id = $1 AND source = $2 AND completed_at IS NOT NULL
3047
+ AND retain_until IS NOT NULL AND retain_until <= $3`, [org, write.source, write.receivedAt]);
3048
+ const { rows } = await client.query(`INSERT INTO ingress_delivery
3049
+ (org_id, source, authority_id, delivery_id, payload_json, received_at, available_at)
3050
+ VALUES ($1, $2, $3, $4, $5, $6, $6)
3051
+ ON CONFLICT (org_id, source, authority_id, delivery_id) DO NOTHING
3052
+ RETURNING delivery_id`, [org, write.source, write.authorityId, write.deliveryId, write.payloadJson, write.receivedAt]);
3053
+ return rows.length > 0;
3054
+ },
3055
+ async listDueIngressDeliveries(org, source, nowIso, staleBeforeIso, limit) {
3056
+ const { rows } = await client.query(`SELECT authority_id, delivery_id, received_at, available_at
3057
+ FROM ingress_delivery
3058
+ WHERE org_id = $1 AND source = $2 AND completed_at IS NULL AND payload_json IS NOT NULL
3059
+ AND available_at <= $3
3060
+ AND (claim_id IS NULL OR (claimed_at IS NOT NULL AND claimed_at <= $4))
3061
+ ORDER BY received_at ASC, authority_id ASC, delivery_id ASC
3062
+ LIMIT $5`, [org, source, nowIso, staleBeforeIso, Math.max(0, Math.trunc(limit))]);
3063
+ return rows.map((row) => ({
3064
+ source,
3065
+ authorityId: row.authority_id,
3066
+ deliveryId: row.delivery_id,
3067
+ receivedAt: row.received_at,
3068
+ availableAt: row.available_at,
3069
+ }));
3070
+ },
3071
+ async claimIngressDelivery(org, key, claimId, claimedAtIso, staleBeforeIso) {
3072
+ const { rows } = await client.query(`UPDATE ingress_delivery SET claim_id = $1, claimed_at = $2
3073
+ WHERE org_id = $3 AND source = $4 AND authority_id = $5 AND delivery_id = $6
3074
+ AND completed_at IS NULL AND payload_json IS NOT NULL AND available_at <= $2
3075
+ AND (claim_id IS NULL OR (claimed_at IS NOT NULL AND claimed_at <= $7))
3076
+ RETURNING payload_json, received_at, available_at`, [claimId, claimedAtIso, org, key.source, key.authorityId, key.deliveryId, staleBeforeIso]);
3077
+ const row = rows[0];
3078
+ return row
3079
+ ? {
3080
+ ...key,
3081
+ payloadJson: row.payload_json,
3082
+ receivedAt: row.received_at,
3083
+ availableAt: row.available_at,
3084
+ claimId,
3085
+ claimedAt: claimedAtIso,
3086
+ }
3087
+ : null;
3088
+ },
3089
+ async releaseIngressDelivery(org, key, claimId, availableAtIso) {
3090
+ const { rows } = await client.query(`UPDATE ingress_delivery SET claim_id = NULL, claimed_at = NULL, available_at = $1
3091
+ WHERE org_id = $2 AND source = $3 AND authority_id = $4 AND delivery_id = $5
3092
+ AND completed_at IS NULL AND claim_id = $6
3093
+ RETURNING delivery_id`, [availableAtIso, org, key.source, key.authorityId, key.deliveryId, claimId]);
3094
+ return rows.length > 0;
3095
+ },
3096
+ async completeIngressDelivery(org, key, claimId, completedAtIso, retainUntilIso) {
3097
+ assertIngressDeliveryRetainUntil(completedAtIso, retainUntilIso);
3098
+ const { rows } = await client.query(`UPDATE ingress_delivery
3099
+ SET payload_json = NULL, claim_id = NULL, claimed_at = NULL,
3100
+ completed_at = $1, retain_until = $2
3101
+ WHERE org_id = $3 AND source = $4 AND authority_id = $5 AND delivery_id = $6
3102
+ AND completed_at IS NULL AND claim_id = $7
3103
+ RETURNING delivery_id`, [completedAtIso, retainUntilIso, org, key.source, key.authorityId, key.deliveryId, claimId]);
3104
+ return rows.length > 0;
3105
+ },
3106
+ async discardIngressDelivery(org, key, claimId) {
3107
+ const { rows } = await client.query(`DELETE FROM ingress_delivery
3108
+ WHERE org_id = $1 AND source = $2 AND authority_id = $3 AND delivery_id = $4
3109
+ AND completed_at IS NULL AND claim_id = $5
3110
+ RETURNING delivery_id`, [org, key.source, key.authorityId, key.deliveryId, claimId]);
3111
+ return rows.length > 0;
3112
+ },
3113
+ async markEventSeen(org, key, at, ttlMs) {
3114
+ // Opportunistic prune keeps the table bounded; ISO timestamps compare lexicographically.
3115
+ // TWO clauses, both ORG-SCOPED (see store.ts): the caller's `ttlMs` applied to THIS KEY ONLY
3116
+ // — the table is shared by callers whose windows differ by an order of magnitude, so a bare
3117
+ // TTL sweep let the shortest-TTL caller expire everyone else's keys AND crossed the tenant
3118
+ // boundary — plus a fixed 24 h housekeeping ceiling for the rest of this org's rows.
3119
+ const atMs = Date.parse(at);
3120
+ const ttlCutoff = new Date(atMs - ttlMs).toISOString();
3121
+ const maxCutoff = new Date(atMs - EVENT_DEDUPE_MAX_RETENTION_MS).toISOString();
3122
+ await client.query("DELETE FROM event_dedupe WHERE org_id = $1 AND (seen_at < $2 OR (key = $3 AND seen_at < $4))", [
3123
+ org,
3124
+ maxCutoff,
3125
+ key,
3126
+ ttlCutoff,
3127
+ ]);
3128
+ // ON CONFLICT DO NOTHING + RETURNING is the atomic first-sighting check: exactly
3129
+ // one of two racing inserts returns a row; the loser returns none → duplicate.
3130
+ const { rows } = await client.query("INSERT INTO event_dedupe (org_id, key, seen_at) VALUES ($1, $2, $3) ON CONFLICT (org_id, key) DO NOTHING RETURNING key", [org, key, at]);
3131
+ return rows.length > 0;
3132
+ },
3133
+ async hasEventSeen(org, key, at, ttlMs) {
3134
+ // READ-ONLY twin of markEventSeen: same cutoff arithmetic, no write, no prune.
3135
+ const cutoff = new Date(Date.parse(at) - ttlMs).toISOString();
3136
+ const { rows } = await client.query("SELECT 1 FROM event_dedupe WHERE org_id = $1 AND key = $2 AND seen_at >= $3 LIMIT 1", [
3137
+ org,
3138
+ key,
3139
+ cutoff,
3140
+ ]);
3141
+ return rows.length > 0;
3142
+ },
3143
+ async forgetEventSeen(org, key) {
3144
+ // ONE row, org-scoped and keyed — never a sweep. See the interface note for when a claim is
3145
+ // given back (OPE-821: a DEFINITIVE post failure, so an identical retry can really post).
3146
+ await client.query("DELETE FROM event_dedupe WHERE org_id = $1 AND key = $2", [org, key]);
3147
+ },
3148
+ async claimNotice(org, key, at) {
3149
+ // ON CONFLICT DO NOTHING + RETURNING is the atomic claim, exactly as markEventSeen's is: one of
3150
+ // two racing callers gets a row back and announces; the loser gets none and stays quiet.
3151
+ // NO DELETE PATH — a claim is a lifetime record, and dropping one lets the thing it records
3152
+ // happen a second time. Every key space on this table is bounded by the thing it records.
3153
+ const { rows } = await client.query("INSERT INTO notice_claim (org_id, key, claimed_at) VALUES ($1, $2, $3) ON CONFLICT (org_id, key) DO NOTHING RETURNING key", [org, key, at]);
3154
+ return rows.length > 0;
3155
+ },
3156
+ async noticeClaimed(org, key) {
3157
+ const { rows } = await client.query("SELECT 1 FROM notice_claim WHERE org_id = $1 AND key = $2 LIMIT 1", [org, key]);
3158
+ return rows.length > 0;
3159
+ },
3160
+ async recordProactiveAddress(org, row) {
3161
+ await client.query(`INSERT INTO proactive_address (org_id, platform, kind, ref_key, tenant, address, updated_at)
3162
+ VALUES ($1, $2, $3, $4, $5, $6, $7)
3163
+ ON CONFLICT (org_id, platform, kind, ref_key) DO UPDATE SET
3164
+ tenant = EXCLUDED.tenant, address = EXCLUDED.address, updated_at = EXCLUDED.updated_at`, [org, row.platform, row.kind, row.refKey, row.tenant, JSON.stringify(row.address ?? {}), row.updatedAt]);
3165
+ },
3166
+ async proactiveAddress(org, platform, kind, refKey) {
3167
+ const { rows } = await client.query("SELECT tenant, address, updated_at FROM proactive_address WHERE org_id = $1 AND platform = $2 AND kind = $3 AND ref_key = $4", [org, platform, kind, refKey]);
3168
+ const r = rows[0];
3169
+ return r ? proactiveAddressRow(platform, kind, refKey, r.tenant, r.address, r.updated_at) : undefined;
3170
+ },
3171
+ async proactiveAddresses(org, platform, kind, limit) {
3172
+ const { rows } = await client.query(`SELECT ref_key, tenant, address, updated_at FROM proactive_address
3173
+ WHERE org_id = $1 AND platform = $2 AND kind = $3 ORDER BY updated_at DESC LIMIT $4`, [org, platform, kind, Math.max(0, Math.trunc(limit))]);
3174
+ return rows.map((r) => proactiveAddressRow(platform, kind, r.ref_key, r.tenant, r.address, r.updated_at));
3175
+ },
3176
+ async captureDelivery(org, source, documentJson, at, captureUntil, maxRows) {
3177
+ // The three bounds, in the same order and for the same reasons as the sqlite twin — read that
3178
+ // one's comments; they are the canonical statement and this is the port of it.
3179
+ const atMs = Date.parse(at);
3180
+ if (!Number.isFinite(atMs))
3181
+ return false;
3182
+ const maxCutoff = new Date(atMs - CAPTURE_MAX_RETENTION_MS).toISOString();
3183
+ await client.query("DELETE FROM webhook_capture WHERE org_id = $1 AND captured_at < $2", [org, maxCutoff]);
3184
+ const untilMs = Date.parse(captureUntil);
3185
+ if (!Number.isFinite(untilMs) || atMs >= untilMs)
3186
+ return false;
3187
+ const { rows } = await client.query("SELECT COUNT(*) AS n, COALESCE(MAX(seq), 0) AS max_seq FROM webhook_capture WHERE org_id = $1 AND source = $2", [org, source]);
3188
+ // COUNT comes back as a bigint STRING on this driver and MAX(seq) as a number-or-string —
3189
+ // coerce both rather than comparing a string to `maxRows`, which would compare lexicographically
3190
+ // and let the volume bound fail open somewhere past nine rows.
3191
+ const agg = (rows[0] ?? {});
3192
+ const n = Number(agg.n ?? 0);
3193
+ const maxSeq = Number(agg.max_seq ?? 0);
3194
+ if (!Number.isFinite(n) || n >= maxRows)
3195
+ return false;
3196
+ await client.query("INSERT INTO webhook_capture (org_id, source, seq, captured_at, document) VALUES ($1, $2, $3, $4, $5)", [
3197
+ org,
3198
+ source,
3199
+ maxSeq + 1,
3200
+ at,
3201
+ documentJson,
3202
+ ]);
3203
+ return true;
3204
+ },
3205
+ async listCapturedDeliveries(org, source, limit) {
3206
+ const { rows } = await client.query("SELECT seq, captured_at, document FROM webhook_capture WHERE org_id = $1 AND source = $2 ORDER BY seq ASC LIMIT $3", [org, source, limit]);
3207
+ return rows.map((r) => ({
3208
+ seq: Number(r.seq),
3209
+ capturedAt: r.captured_at,
3210
+ documentJson: r.document,
3211
+ }));
3212
+ },
3213
+ async clearCapturedDeliveries(org, source) {
3214
+ await client.query("DELETE FROM webhook_capture WHERE org_id = $1 AND source = $2", [org, source]);
3215
+ },
3216
+ async putUnifiedWakeTarget(org, wakeId, targetJson, at, ttlMs, windowToken, inbound) {
3217
+ // Opportunistic TTL prune, same posture as markEventSeen (bounded table, no scheduled job).
3218
+ // ORG-SCOPED: one org's write must never prune another org's rows — the every-query-filters-
3219
+ // by-org invariant (a bare `created_at < cutoff` DELETE would cross the tenant boundary).
3220
+ const cutoff = new Date(Date.parse(at) - ttlMs).toISOString();
3221
+ await client.query("DELETE FROM unified_wake_target WHERE created_at < $1 AND org_id = $2", [cutoff, org]);
3222
+ await client.query(
3223
+ // 🔴 The conflict clause updates target_json/created_at/window_token and NEVER the answered
3224
+ // columns — a redrive/webhook-retry re-register must not clear (or resurrect) a mark.
3225
+ // 🔴 `inbound` is STICKY-TRUE (an OR over the two sides), unlike every other updated column:
3226
+ // the redrive re-registers an EXISTING wake id as an INTERNAL dispatch, and a plain overwrite
3227
+ // would clear the flag on a row a human's message created.
3228
+ `INSERT INTO unified_wake_target (org_id, wake_id, target_json, created_at, window_token, inbound) VALUES ($1, $2, $3, $4, $5, $6)
3229
+ ON CONFLICT (org_id, wake_id) DO UPDATE SET target_json = EXCLUDED.target_json, created_at = EXCLUDED.created_at, window_token = EXCLUDED.window_token,
3230
+ inbound = COALESCE(unified_wake_target.inbound, false) OR COALESCE(EXCLUDED.inbound, false)`, [org, wakeId, targetJson, at, windowToken ?? null, inbound === true]);
3231
+ },
3232
+ async getUnifiedWakeTarget(org, wakeId) {
3233
+ const { rows } = await client.query("SELECT target_json FROM unified_wake_target WHERE org_id = $1 AND wake_id = $2", [org, wakeId]);
3234
+ const r = rows[0];
3235
+ return r ? r.target_json : null;
3236
+ },
3237
+ async getUnifiedWakeRecord(org, wakeId) {
3238
+ const { rows } = await client.query("SELECT target_json, created_at, window_token, answered_at, answered_turn_id, audited_at, inbound FROM unified_wake_target WHERE org_id = $1 AND wake_id = $2", [org, wakeId]);
3239
+ const r = rows[0];
3240
+ if (!r)
3241
+ return null;
3242
+ return {
3243
+ targetJson: r.target_json,
3244
+ createdAt: r.created_at,
3245
+ ...(r.window_token !== null ? { windowToken: r.window_token } : {}),
3246
+ ...(r.answered_at !== null ? { answeredAt: r.answered_at } : {}),
3247
+ ...(r.answered_turn_id !== null ? { answeredTurnId: r.answered_turn_id } : {}),
3248
+ ...(r.audited_at !== null ? { auditedAt: r.audited_at } : {}),
3249
+ // A NULL column is a legacy row, and it stays ABSENT rather than becoming `false` — the two
3250
+ // say different things, and every reader treats absent as attended (OPE-2051).
3251
+ ...(r.inbound !== null ? { inbound: r.inbound } : {}),
3252
+ };
3253
+ },
3254
+ async listPendingUnifiedWakes(org, windowToken, afterIso, limit) {
3255
+ // ORDER BY created_at ASC: the gate reports the OLDEST unseen messages first, which is the order
3256
+ // a reader would meet them in. `answered_at IS NULL` is the whole "pending" definition — the same
3257
+ // column the answerable-reply fence reads, so the two can never disagree about what pending means.
3258
+ const { rows } = await client.query(`SELECT wake_id, target_json, created_at FROM unified_wake_target
3259
+ WHERE org_id = $1 AND window_token = $2 AND answered_at IS NULL AND inbound IS TRUE AND created_at > $3
3260
+ ORDER BY created_at ASC LIMIT $4`, [org, windowToken, afterIso, limit]);
3261
+ return rows.map((r) => ({
3262
+ wakeId: r.wake_id,
3263
+ targetJson: r.target_json,
3264
+ createdAt: r.created_at,
3265
+ }));
3266
+ },
3267
+ async listUnauditedUnifiedWakes(org, windowToken, limit) {
3268
+ // Same pending definition as the listing above, plus the OPE-836 horizon (`audited_at IS NULL`)
3269
+ // and NO time bound below — a row an earlier turn considered is already excluded by the column.
3270
+ // The filter is in SQL so `limit` bounds the rows still to consider, never a backlog of audited
3271
+ // ones. This query is the accounting audit's alone; the freshness gate's own SQL is untouched.
3272
+ const { rows } = await client.query(`SELECT wake_id, target_json, created_at FROM unified_wake_target
3273
+ WHERE org_id = $1 AND window_token = $2 AND answered_at IS NULL AND inbound IS TRUE AND audited_at IS NULL
3274
+ ORDER BY created_at ASC LIMIT $3`, [org, windowToken, limit]);
3275
+ return rows.map((r) => ({
3276
+ wakeId: r.wake_id,
3277
+ targetJson: r.target_json,
3278
+ createdAt: r.created_at,
3279
+ }));
3280
+ },
3281
+ async markUnifiedWakesAudited(org, wakeIds, at) {
3282
+ // UPDATE-only and FIRST-STAMP-WINS (`audited_at IS NULL`), so a re-run cannot move the horizon
3283
+ // stamp and a missing row inserts nothing. ONE statement for the whole batch via `= ANY`.
3284
+ if (wakeIds.length === 0)
3285
+ return;
3286
+ await client.query("UPDATE unified_wake_target SET audited_at = $1 WHERE org_id = $2 AND wake_id = ANY($3::text[]) AND audited_at IS NULL", [
3287
+ at,
3288
+ org,
3289
+ [...wakeIds],
3290
+ ]);
3291
+ },
3292
+ async markUnifiedWakeAnswered(org, wakeId, at, turnId) {
3293
+ // UPDATE-only (never an upsert): an answered mark on a row with no origin is meaningless, and
3294
+ // inserting one would create a phantom the resolver would then have to reject.
3295
+ await client.query("UPDATE unified_wake_target SET answered_at = $1, answered_turn_id = $2 WHERE org_id = $3 AND wake_id = $4", [
3296
+ at,
3297
+ turnId ?? null,
3298
+ org,
3299
+ wakeId,
3300
+ ]);
3301
+ },
3302
+ async putThreadOwner(org, channelKey, threadKey, taskToken, at, ttlMs) {
3303
+ // Opportunistic TTL prune, a backstop over complete_thread and generation GC. It is org-scoped, so it never crosses the tenant boundary.
3304
+ const cutoff = new Date(Date.parse(at) - ttlMs).toISOString();
3305
+ await client.query("DELETE FROM thread_ownership WHERE created_at < $1 AND org_id = $2", [cutoff, org]);
3306
+ await client.query(`INSERT INTO thread_ownership (org_id, channel_key, thread_key, task_token, created_at) VALUES ($1, $2, $3, $4, $5)
3307
+ ON CONFLICT (org_id, channel_key, thread_key) DO UPDATE SET task_token = EXCLUDED.task_token, created_at = EXCLUDED.created_at`, [org, channelKey, threadKey, taskToken, at]);
3308
+ },
3309
+ async getThreadOwner(org, channelKey, threadKey) {
3310
+ const { rows } = await client.query("SELECT task_token FROM thread_ownership WHERE org_id = $1 AND channel_key = $2 AND thread_key = $3", [org, channelKey, threadKey]);
3311
+ const r = rows[0];
3312
+ return r ? r.task_token : null;
3313
+ },
3314
+ async clearThreadOwner(org, channelKey, threadKey) {
3315
+ const { rows } = await client.query("DELETE FROM thread_ownership WHERE org_id = $1 AND channel_key = $2 AND thread_key = $3 RETURNING task_token", [org, channelKey, threadKey]);
3316
+ return rows.length > 0;
3317
+ },
3318
+ async putThreadSeatState(org, row, at, ttlMs) {
3319
+ // Opportunistic ORG-SCOPED TTL prune, the same posture as putThreadOwner above.
3320
+ const cutoff = new Date(Date.parse(at) - ttlMs).toISOString();
3321
+ await client.query("DELETE FROM thread_seat_state WHERE updated_at < $1 AND org_id = $2", [cutoff, org]);
3322
+ await client.query(`INSERT INTO thread_seat_state (org_id, channel_key, thread_key, seat_token, parent_key, state, origin_json, report, opened_at, updated_at)
3323
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
3324
+ ON CONFLICT (org_id, channel_key, thread_key) DO UPDATE SET
3325
+ seat_token = EXCLUDED.seat_token,
3326
+ parent_key = EXCLUDED.parent_key,
3327
+ state = EXCLUDED.state,
3328
+ origin_json = EXCLUDED.origin_json,
3329
+ report = EXCLUDED.report,
3330
+ opened_at = EXCLUDED.opened_at,
3331
+ updated_at = EXCLUDED.updated_at`, [org, row.channelKey, row.threadKey, row.seatToken, row.parentRegistryKey, row.state, row.originJson, row.report ?? null, row.openedAt, at]);
3332
+ },
3333
+ async getThreadSeatState(org, channelKey, threadKey) {
3334
+ const { rows } = await client.query("SELECT seat_token, parent_key, state, origin_json, report, opened_at, updated_at FROM thread_seat_state WHERE org_id = $1 AND channel_key = $2 AND thread_key = $3", [org, channelKey, threadKey]);
3335
+ const r = rows[0];
3336
+ if (!r)
3337
+ return null;
3338
+ return {
3339
+ channelKey,
3340
+ threadKey,
3341
+ seatToken: r.seat_token,
3342
+ parentRegistryKey: r.parent_key,
3343
+ // Anything but the two written values reads as `completed` — see the sqlite twin for why the
3344
+ // unreadable case must never report a seat as LIVE.
3345
+ state: r.state === "open" ? "open" : "completed",
3346
+ originJson: r.origin_json,
3347
+ ...(r.report !== null ? { report: r.report } : {}),
3348
+ openedAt: r.opened_at,
3349
+ updatedAt: r.updated_at,
3350
+ };
3351
+ },
3352
+ async putTurnAnchor(org, anchor, at, ttlMs) {
3353
+ // Opportunistic TTL prune, a backstop over the turn-end clear. It is org-scoped, so it never crosses the tenant boundary.
3354
+ const cutoff = new Date(Date.parse(at) - ttlMs).toISOString();
3355
+ await client.query("DELETE FROM turn_anchor WHERE created_at < $1 AND org_id = $2", [cutoff, org]);
3356
+ await client.query(`INSERT INTO turn_anchor (org_id, window_key, anchor_key, channel_key, session_id, turn_id, surface_key, created_at)
3357
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
3358
+ ON CONFLICT (org_id, window_key) DO UPDATE SET
3359
+ anchor_key = EXCLUDED.anchor_key, channel_key = EXCLUDED.channel_key,
3360
+ session_id = EXCLUDED.session_id, turn_id = EXCLUDED.turn_id,
3361
+ surface_key = EXCLUDED.surface_key, created_at = EXCLUDED.created_at`, [org, anchor.windowKey, anchor.anchorKey ?? null, anchor.channelKey ?? null, anchor.sessionId, anchor.turnId, anchor.surfaceKey, at]);
3362
+ },
3363
+ async getTurnAnchorByWindow(org, windowKey) {
3364
+ const { rows } = await client.query(`${TURN_ANCHOR_SELECT} WHERE org_id = $1 AND window_key = $2`, [org, windowKey]);
3365
+ return turnAnchorFromPgRow(rows[0]);
3366
+ },
3367
+ async getTurnAnchorByAnchor(org, anchorKey) {
3368
+ const { rows } = await client.query(`${TURN_ANCHOR_SELECT} WHERE org_id = $1 AND anchor_key = $2`, [org, anchorKey]);
3369
+ return turnAnchorFromPgRow(rows[0]);
3370
+ },
3371
+ async getLatestTurnAnchorForChannel(org, channelKey) {
3372
+ const { rows } = await client.query(`${TURN_ANCHOR_SELECT} WHERE org_id = $1 AND channel_key = $2 ORDER BY created_at DESC, window_key DESC LIMIT 1`, [org, channelKey]);
3373
+ return turnAnchorFromPgRow(rows[0]);
3374
+ },
3375
+ async clearTurnAnchor(org, windowKey) {
3376
+ const { rows } = await client.query("DELETE FROM turn_anchor WHERE org_id = $1 AND window_key = $2 RETURNING window_key", [org, windowKey]);
3377
+ return rows.length > 0;
3378
+ },
3379
+ async putTaskResult(org, taskId, resultJson, at, ttlMs) {
3380
+ // Opportunistic TTL prune for a bounded table with no scheduled job. It is org-scoped, so one org's write never touches another org's rows.
3381
+ const cutoff = new Date(Date.parse(at) - ttlMs).toISOString();
3382
+ await client.query("DELETE FROM task_result WHERE created_at < $1 AND org_id = $2", [cutoff, org]);
3383
+ await client.query(`INSERT INTO task_result (org_id, task_id, result_json, created_at) VALUES ($1, $2, $3, $4)
3384
+ ON CONFLICT (org_id, task_id) DO UPDATE SET result_json = EXCLUDED.result_json, created_at = EXCLUDED.created_at`, [org, taskId, resultJson, at]);
3385
+ },
3386
+ async putTaskResultIfAbsent(org, taskId, resultJson, at, ttlMs) {
3387
+ const cutoff = new Date(Date.parse(at) - ttlMs).toISOString();
3388
+ await client.query("DELETE FROM task_result WHERE created_at < $1 AND org_id = $2", [cutoff, org]);
3389
+ const { rows } = await client.query(`INSERT INTO task_result (org_id, task_id, result_json, created_at) VALUES ($1, $2, $3, $4)
3390
+ ON CONFLICT (org_id, task_id) DO NOTHING RETURNING task_id`, [org, taskId, resultJson, at]);
3391
+ return rows.length > 0;
3392
+ },
3393
+ async getTaskResult(org, taskId) {
3394
+ const { rows } = await client.query("SELECT result_json FROM task_result WHERE org_id = $1 AND task_id = $2", [org, taskId]);
3395
+ const r = rows[0];
3396
+ return r ? r.result_json : null;
3397
+ },
3398
+ async deleteTaskResult(org, taskId) {
3399
+ const { rows } = await client.query("DELETE FROM task_result WHERE org_id = $1 AND task_id = $2 RETURNING task_id", [org, taskId]);
3400
+ return rows.length > 0;
3401
+ },
3402
+ async putSlackAttachment(org, fileId, rec, at, ttlMs) {
3403
+ // Opportunistic TTL prune for a bounded routing map with no scheduled job. It is org-scoped, so it never crosses the tenant boundary.
3404
+ const cutoff = new Date(Date.parse(at) - ttlMs).toISOString();
3405
+ await client.query("DELETE FROM slack_attachment WHERE created_at < $1 AND org_id = $2", [cutoff, org]);
3406
+ await client.query(`INSERT INTO slack_attachment (org_id, file_id, url_private, mime_type, name, team_id, created_at)
3407
+ VALUES ($1, $2, $3, $4, $5, $6, $7)
3408
+ ON CONFLICT (org_id, file_id) DO UPDATE SET
3409
+ url_private = EXCLUDED.url_private, mime_type = EXCLUDED.mime_type,
3410
+ name = EXCLUDED.name, team_id = EXCLUDED.team_id, created_at = EXCLUDED.created_at`, [org, fileId, rec.urlPrivate, rec.mimeType ?? null, rec.name ?? null, rec.teamId ?? null, at]);
3411
+ },
3412
+ async getSlackAttachment(org, fileId) {
3413
+ const { rows } = await client.query("SELECT url_private, mime_type, name, team_id FROM slack_attachment WHERE org_id = $1 AND file_id = $2", [org, fileId]);
3414
+ const r = rows[0];
3415
+ if (!r)
3416
+ return null;
3417
+ const rec = {
3418
+ urlPrivate: r.url_private,
3419
+ ...(r.mime_type ? { mimeType: r.mime_type } : {}),
3420
+ ...(r.name ? { name: r.name } : {}),
3421
+ ...(r.team_id ? { teamId: r.team_id } : {}),
3422
+ };
3423
+ return rec;
3424
+ },
3425
+ async putStoredCredential(org, rec) {
3426
+ // Upsert the ciphertext envelope. `rec.ciphertext` is opaque here — never inspected, never logged.
3427
+ await client.query(`INSERT INTO stored_credential (org_id, ref, ciphertext, connector, domain, created_by, created_at)
3428
+ VALUES ($1, $2, $3, $4, $5, $6, $7)
3429
+ ON CONFLICT (org_id, ref) DO UPDATE SET
3430
+ ciphertext = EXCLUDED.ciphertext, connector = EXCLUDED.connector,
3431
+ domain = EXCLUDED.domain, created_by = EXCLUDED.created_by, created_at = EXCLUDED.created_at`, [org, rec.ref, rec.ciphertext, rec.connector ?? null, rec.domain ?? null, rec.createdBy, rec.createdAt]);
3432
+ },
3433
+ async getStoredCredential(org, ref) {
3434
+ const { rows } = await client.query("SELECT ref, ciphertext, connector, domain, created_by, created_at FROM stored_credential WHERE org_id = $1 AND ref = $2", [org, ref]);
3435
+ const r = rows[0];
3436
+ if (!r)
3437
+ return null;
3438
+ return {
3439
+ ref: r.ref,
3440
+ ciphertext: r.ciphertext,
3441
+ ...(r.connector ? { connector: r.connector } : {}),
3442
+ ...(r.domain ? { domain: r.domain } : {}),
3443
+ createdBy: r.created_by,
3444
+ createdAt: r.created_at,
3445
+ };
3446
+ },
3447
+ async deleteStoredCredential(org, ref) {
3448
+ // A REAL delete of the ciphertext row - see the store port for why this table retires by destruction rather than by status. The stored_credential_org_isolation policy is declared with no FOR clause, so it is FOR ALL and its USING expression applies to DELETE exactly as it does to SELECT and UPDATE.
3449
+ const { rows } = await client.query("DELETE FROM stored_credential WHERE org_id = $1 AND ref = $2 RETURNING ref", [org, ref]);
3450
+ return rows.length > 0;
3451
+ },
3452
+ async listStoredCredentialRefs(org, refPrefix) {
3453
+ // REFS ONLY: the ciphertext column is deliberately out of the projection, because an enumerating caller must never be handed envelopes. refPrefix narrows IN THE PREDICATE and never by a filter after the fact, so an in-product sweep cannot receive the names of credentials outside its own namespace; likePrefixPattern escapes the LIKE metacharacters that the ESCAPE clause declares.
3454
+ if (refPrefix) {
3455
+ const { rows } = await client.query("SELECT ref FROM stored_credential WHERE org_id = $1 AND ref LIKE $2 ESCAPE '\\' ORDER BY ref", [org, likePrefixPattern(refPrefix)]);
3456
+ return rows.map((r) => r.ref);
3457
+ }
3458
+ const { rows } = await client.query("SELECT ref FROM stored_credential WHERE org_id = $1 ORDER BY ref", [org]);
3459
+ return rows.map((r) => r.ref);
3460
+ },
3461
+ async putGitHubInstallation(org, rec) {
3462
+ await client.query(`INSERT INTO github_installation (org_id, owner, installation_id, account_type, repository_selection, updated_at)
3463
+ VALUES ($1, $2, $3, $4, $5, $6)
3464
+ ON CONFLICT (org_id, owner) DO UPDATE SET installation_id = EXCLUDED.installation_id,
3465
+ account_type = EXCLUDED.account_type, repository_selection = EXCLUDED.repository_selection,
3466
+ updated_at = EXCLUDED.updated_at`, [org, rec.owner, rec.installationId, rec.accountType ?? null, rec.repositorySelection ?? null, rec.updatedAt]);
3467
+ },
3468
+ async deleteGitHubInstallation(org, owner) {
3469
+ const { rows } = await client.query("DELETE FROM github_installation WHERE org_id = $1 AND owner = $2 RETURNING owner", [org, owner]);
3470
+ return rows.length > 0;
3471
+ },
3472
+ async listGitHubInstallations(org) {
3473
+ const { rows } = await client.query("SELECT owner, installation_id, account_type, repository_selection, updated_at FROM github_installation WHERE org_id = $1 ORDER BY owner ASC", [org]);
3474
+ return rows.map((r) => ({
3475
+ owner: r.owner,
3476
+ installationId: r.installation_id,
3477
+ ...(r.account_type ? { accountType: r.account_type } : {}),
3478
+ ...(r.repository_selection ? { repositorySelection: r.repository_selection } : {}),
3479
+ updatedAt: r.updated_at,
3480
+ }));
3481
+ },
3482
+ async claimStoredCredential(org, ref, claimId, claimedAtIso, staleBeforeIso) {
3483
+ // Atomic compare-and-set on the claim columns: win iff the row is free (claim_id NULL) OR the
3484
+ // existing claim's lease is stale (claimed_at <= staleBefore; ISO-8601 compares lexicographically).
3485
+ // A single UPDATE ... RETURNING ⇒ of two racing claimants exactly one gets a row back (the winner);
3486
+ // a missing row updates nothing ⇒ empty ⇒ lost.
3487
+ const { rows } = await client.query(`UPDATE stored_credential SET claim_id = $1, claimed_at = $2
3488
+ WHERE org_id = $3 AND ref = $4 AND (claim_id IS NULL OR claimed_at <= $5) RETURNING ref`, [claimId, claimedAtIso, org, ref, staleBeforeIso]);
3489
+ return rows.length > 0;
3490
+ },
3491
+ async releaseStoredCredential(org, ref, claimId) {
3492
+ // Guarded release: clear the claim only if THIS caller still holds it. A stolen-lease caller
3493
+ // mismatches and no-ops — it never clears the new owner's claim.
3494
+ const { rows } = await client.query("UPDATE stored_credential SET claim_id = NULL, claimed_at = NULL WHERE org_id = $1 AND ref = $2 AND claim_id = $3 RETURNING ref", [org, ref, claimId]);
3495
+ return rows.length > 0;
3496
+ },
3497
+ async addCredentialIntake(row) {
3498
+ await client.query(`INSERT INTO credential_intake (org_id, id, ref, connector, domain, requested_by, channel_id, thread_ts, created_at, expires_at, used_at)
3499
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)`, [row.org, row.id, row.ref, row.connector, row.domain ?? null, row.requestedBy, row.channelId, row.threadTs ?? null, row.createdAt, row.expiresAt, row.usedAt ?? null]);
3500
+ },
3501
+ async getCredentialIntake(org, id) {
3502
+ const { rows } = await client.query("SELECT id, ref, connector, domain, requested_by, channel_id, thread_ts, created_at, expires_at, used_at FROM credential_intake WHERE org_id = $1 AND id = $2", [org, id]);
3503
+ const r = rows[0];
3504
+ if (!r)
3505
+ return null;
3506
+ return {
3507
+ org,
3508
+ id: r.id,
3509
+ ref: r.ref,
3510
+ connector: r.connector,
3511
+ ...(r.domain ? { domain: r.domain } : {}),
3512
+ requestedBy: r.requested_by,
3513
+ channelId: r.channel_id,
3514
+ ...(r.thread_ts ? { threadTs: r.thread_ts } : {}),
3515
+ createdAt: r.created_at,
3516
+ expiresAt: r.expires_at,
3517
+ ...(r.used_at ? { usedAt: r.used_at } : {}),
3518
+ };
3519
+ },
3520
+ async consumeCredentialIntake(org, id, usedAt) {
3521
+ // Single-use CAS: exactly one of two racing submits matches `used_at IS NULL` and stamps it.
3522
+ const { rows } = await client.query("UPDATE credential_intake SET used_at = $1 WHERE org_id = $2 AND id = $3 AND used_at IS NULL RETURNING id", [usedAt, org, id]);
3523
+ return rows.length > 0;
3524
+ },
3525
+ async armWebhookCaptureWindow(org, hookId, captureUntil, armedBy, at) {
3526
+ // UPSERT on the whole key: re-arming replaces, because two overlapping windows would make the
3527
+ // numbering the human reads ambiguous across a boundary they cannot see.
3528
+ await client.query(`INSERT INTO webhook_capture_window (org_id, hook_id, capture_until, armed_by, armed_at) VALUES ($1, $2, $3, $4, $5)
3529
+ ON CONFLICT (org_id, hook_id) DO UPDATE SET capture_until = EXCLUDED.capture_until, armed_by = EXCLUDED.armed_by, armed_at = EXCLUDED.armed_at`, [org, hookId, captureUntil, armedBy, at]);
3530
+ },
3531
+ async getWebhookCaptureWindow(org, hookId) {
3532
+ const { rows } = await client.query("SELECT hook_id, capture_until, armed_by, armed_at FROM webhook_capture_window WHERE org_id = $1 AND hook_id = $2", [org, hookId]);
3533
+ const row = rows[0];
3534
+ // Returned EXPIRED-AND-ALL: closing is a comparison the caller makes (`captureWindowOpen`).
3535
+ return row ? { hookId: row.hook_id, captureUntil: row.capture_until, armedBy: row.armed_by, armedAt: row.armed_at } : null;
3536
+ },
3537
+ async addPendingAction(row) {
3538
+ await client.query(`INSERT INTO pending_actions
3539
+ (org_id, id, kind, args_json, scope_key, domain, requested_by, channel_id, thread_ts, message_ts, posted_to, status, created_at, expires_at, decided_by, decided_at)
3540
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)`, [
3541
+ row.org,
3542
+ row.id,
3543
+ row.kind,
3544
+ row.argsJson,
3545
+ row.scopeKey,
3546
+ row.domain,
3547
+ row.requestedBy,
3548
+ row.channelId,
3549
+ row.threadTs,
3550
+ row.messageTs,
3551
+ row.postedTo,
3552
+ row.status,
3553
+ row.createdAt,
3554
+ row.expiresAt,
3555
+ row.decidedBy,
3556
+ row.decidedAt,
3557
+ ]);
3558
+ },
3559
+ async addPendingActionIfAbsent(row) {
3560
+ // The conflict arm the derived-id wedge needs — see the store interface's note (OPE-1348).
3561
+ const { rows } = await client.query(`INSERT INTO pending_actions
3562
+ (org_id, id, kind, args_json, scope_key, domain, requested_by, channel_id, thread_ts, message_ts, posted_to, status, created_at, expires_at, decided_by, decided_at)
3563
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)
3564
+ ON CONFLICT (org_id, id) DO NOTHING RETURNING id`, [
3565
+ row.org,
3566
+ row.id,
3567
+ row.kind,
3568
+ row.argsJson,
3569
+ row.scopeKey,
3570
+ row.domain,
3571
+ row.requestedBy,
3572
+ row.channelId,
3573
+ row.threadTs,
3574
+ row.messageTs,
3575
+ row.postedTo,
3576
+ row.status,
3577
+ row.createdAt,
3578
+ row.expiresAt,
3579
+ row.decidedBy,
3580
+ row.decidedAt,
3581
+ ]);
3582
+ return rows.length > 0;
3583
+ },
3584
+ async getPendingAction(org, id) {
3585
+ const { rows } = await client.query(`SELECT id, kind, args_json, scope_key, domain, requested_by, channel_id, thread_ts, message_ts, posted_to, status, created_at, expires_at, decided_by, decided_at
3586
+ FROM pending_actions WHERE org_id = $1 AND id = $2`, [org, id]);
3587
+ const r = rows[0];
3588
+ return r ? pendingActionFromPgRow(org, r) : null;
3589
+ },
3590
+ async listPendingActions(org) {
3591
+ const { rows } = await client.query(`SELECT id, kind, args_json, scope_key, domain, requested_by, channel_id, thread_ts, message_ts, posted_to, status, created_at, expires_at, decided_by, decided_at
3592
+ FROM pending_actions WHERE org_id = $1 AND status = 'pending' ORDER BY created_at ASC`, [org]);
3593
+ return rows.map((r) => pendingActionFromPgRow(org, r));
3594
+ },
3595
+ async listExpiredPendingActions(org, nowIso) {
3596
+ const { rows } = await client.query(`SELECT id, kind, args_json, scope_key, domain, requested_by, channel_id, thread_ts, message_ts, posted_to, status, created_at, expires_at, decided_by, decided_at
3597
+ FROM pending_actions WHERE org_id = $1 AND status = 'pending' AND expires_at <= $2 ORDER BY created_at ASC`, [org, nowIso]);
3598
+ return rows.map((r) => pendingActionFromPgRow(org, r));
3599
+ },
3600
+ async listRejectedActionsSince(org, sinceIso) {
3601
+ const { rows } = await client.query(`SELECT id, kind, args_json, scope_key, domain, requested_by, channel_id, thread_ts, message_ts, posted_to, status, created_at, expires_at, decided_by, decided_at
3602
+ FROM pending_actions WHERE org_id = $1 AND status = 'rejected' AND decided_at >= $2 ORDER BY decided_at DESC`, [org, sinceIso]);
3603
+ return rows.map((r) => pendingActionFromPgRow(org, r));
3604
+ },
3605
+ async setPendingActionMessage(org, id, messageTs) {
3606
+ await client.query("UPDATE pending_actions SET message_ts = $1 WHERE org_id = $2 AND id = $3", [messageTs, org, id]);
3607
+ },
3608
+ async decidePendingAction(org, id, status, decidedBy, decidedAt) {
3609
+ // The CAS: exactly one of two racing decides (two clicks, or a click racing a
3610
+ // lazy-expiry sweep) matches `status = 'pending'` and returns a row.
3611
+ const { rows } = await client.query(`UPDATE pending_actions SET status = $1, decided_by = $2, decided_at = $3
3612
+ WHERE org_id = $4 AND id = $5 AND status = 'pending' RETURNING id`, [status, decidedBy, decidedAt, org, id]);
3613
+ return rows.length > 0;
3614
+ },
3615
+ async setSessionApproval(row) {
3616
+ // Prune-on-write: drop this org's expired memos (no sweep — the session_id generation is the
3617
+ // real death mechanism, this is just GC), then upsert.
3618
+ await client.query("DELETE FROM pr_session_approval WHERE org_id = $1 AND expires_at <= $2", [row.org, row.createdAt]);
3619
+ await client.query(`INSERT INTO pr_session_approval (org_id, session_id, kind, granted_by, created_at, expires_at)
3620
+ VALUES ($1, $2, $3, $4, $5, $6)
3621
+ ON CONFLICT (org_id, session_id, kind) DO UPDATE SET granted_by = excluded.granted_by, created_at = excluded.created_at, expires_at = excluded.expires_at`, [row.org, row.sessionId, row.kind, row.grantedBy, row.createdAt, row.expiresAt]);
3622
+ },
3623
+ async getSessionApproval(org, sessionId, kind, nowIso) {
3624
+ const { rows } = await client.query("SELECT session_id, kind, granted_by, created_at, expires_at FROM pr_session_approval WHERE org_id = $1 AND session_id = $2 AND kind = $3 AND expires_at > $4", [org, sessionId, kind, nowIso]);
3625
+ const r = rows[0];
3626
+ return r ? { org, sessionId: r.session_id, kind: r.kind, grantedBy: r.granted_by, createdAt: r.created_at, expiresAt: r.expires_at } : null;
3627
+ },
3628
+ async listSessionApprovals(org, sessionId, nowIso) {
3629
+ const { rows } = await client.query("SELECT session_id, kind, granted_by, created_at, expires_at FROM pr_session_approval WHERE org_id = $1 AND session_id = $2 AND expires_at > $3 ORDER BY kind ASC", [org, sessionId, nowIso]);
3630
+ return rows.map((r) => ({
3631
+ org,
3632
+ sessionId: r.session_id,
3633
+ kind: r.kind,
3634
+ grantedBy: r.granted_by,
3635
+ createdAt: r.created_at,
3636
+ expiresAt: r.expires_at,
3637
+ }));
3638
+ },
3639
+ async revokeSessionApprovals(org, sessionId) {
3640
+ const { rows } = await client.query("DELETE FROM pr_session_approval WHERE org_id = $1 AND session_id = $2 RETURNING kind", [org, sessionId]);
3641
+ return rows.length;
3642
+ },
3643
+ async sweepLegacyConnectorOpRows(org) {
3644
+ // Both prefixes, and no expiry clause — see the port's own comment for why each is required.
3645
+ const { rows } = await client.query("DELETE FROM pr_session_approval WHERE org_id = $1 AND session_id LIKE $2 AND kind LIKE $3 RETURNING kind", [org, `${ROUTINE_PERMISSION_PREFIX}%`, `${CONNECTOR_OP_KIND_PREFIX}%`]);
3646
+ return rows.length;
3647
+ },
3648
+ // Every statement here filters by org_id - the load-bearing isolation - on top of the RLS policy. Each mutating method is an upsert or a COMPARE-AND-SET over the row's current status: the from list in the WHERE is what makes revoked terminal and a nonce single-use at the engine, not only in identity/link-store.ts's checks above it.
3649
+ async putLinkSet(org, row) {
3650
+ await client.query(`INSERT INTO identity_link_sets (org_id, id, handle, status, created_at, updated_at) VALUES ($1, $2, $3, $4, $5, $6)
3651
+ ON CONFLICT (org_id, id) DO UPDATE SET handle = EXCLUDED.handle, status = EXCLUDED.status, updated_at = EXCLUDED.updated_at`, [org, row.id, row.handle, row.status, row.createdAt, row.updatedAt]);
3652
+ },
3653
+ async getLinkSet(org, id) {
3654
+ const { rows } = await client.query("SELECT id, handle, status, created_at, updated_at FROM identity_link_sets WHERE org_id = $1 AND id = $2", [org, id]);
3655
+ const r = rows[0];
3656
+ return r ? linkSetFromPgRow(org, r) : null;
3657
+ },
3658
+ async listLinkSets(org) {
3659
+ const { rows } = await client.query("SELECT id, handle, status, created_at, updated_at FROM identity_link_sets WHERE org_id = $1 ORDER BY id ASC", [org]);
3660
+ return rows.map((r) => linkSetFromPgRow(org, r));
3661
+ },
3662
+ async updateLinkSetStatus(org, id, from, to, at) {
3663
+ const { rows } = await client.query(`UPDATE identity_link_sets SET status = $1, updated_at = $2
3664
+ WHERE org_id = $3 AND id = $4 AND status = ANY($5) RETURNING id`, [to, at, org, id, [...from]]);
3665
+ return rows.length > 0;
3666
+ },
3667
+ async insertLinkedId(org, row) {
3668
+ // DO NOTHING (not DO UPDATE): the conflict IS the answer — the account already belongs to a
3669
+ // person, and quietly re-pointing it at a second one is the merge this table exists to refuse.
3670
+ const { rows } = await client.query(`INSERT INTO identity_linked_ids (org_id, platform, tenant, native_id, link_set_id, status, established_by, evidence, created_at, updated_at)
3671
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
3672
+ ON CONFLICT (org_id, platform, tenant, native_id) DO NOTHING RETURNING native_id`, [org, row.platform, row.tenant, row.nativeId, row.linkSetId, row.status, row.establishedBy, row.evidenceJson ?? null, row.createdAt, row.updatedAt]);
3673
+ return rows.length > 0;
3674
+ },
3675
+ async getLinkedId(org, platform, tenant, nativeId) {
3676
+ const { rows } = await client.query(`SELECT platform, tenant, native_id, link_set_id, status, established_by, evidence, created_at, updated_at
3677
+ FROM identity_linked_ids WHERE org_id = $1 AND platform = $2 AND tenant = $3 AND native_id = $4`, [org, platform, tenant, nativeId]);
3678
+ const r = rows[0];
3679
+ return r ? linkedIdFromPgRow(org, r) : null;
3680
+ },
3681
+ async listLinkedIds(org, linkSetId) {
3682
+ const { rows } = await client.query(`SELECT platform, tenant, native_id, link_set_id, status, established_by, evidence, created_at, updated_at
3683
+ FROM identity_linked_ids WHERE org_id = $1${linkSetId === undefined ? "" : " AND link_set_id = $2"}
3684
+ ORDER BY platform ASC, tenant ASC, native_id ASC`, linkSetId === undefined ? [org] : [org, linkSetId]);
3685
+ return rows.map((r) => linkedIdFromPgRow(org, r));
3686
+ },
3687
+ async updateLinkedIdStatus(org, platform, tenant, nativeId, from, to, establishedBy, evidenceJson, at) {
3688
+ const { rows } = await client.query(`UPDATE identity_linked_ids SET status = $1, established_by = $2, evidence = $3, updated_at = $4
3689
+ WHERE org_id = $5 AND platform = $6 AND tenant = $7 AND native_id = $8 AND status = ANY($9) RETURNING native_id`, [to, establishedBy, evidenceJson ?? null, at, org, platform, tenant, nativeId, [...from]]);
3690
+ return rows.length > 0;
3691
+ },
3692
+ async deleteLinkedId(org, platform, tenant, nativeId) {
3693
+ const { rows } = await client.query("DELETE FROM identity_linked_ids WHERE org_id = $1 AND platform = $2 AND tenant = $3 AND native_id = $4 RETURNING native_id", [org, platform, tenant, nativeId]);
3694
+ return rows.length > 0;
3695
+ },
3696
+ async revokeLinkedIdsForSet(org, linkSetId, at) {
3697
+ const { rows } = await client.query(`UPDATE identity_linked_ids SET status = 'revoked', updated_at = $1
3698
+ WHERE org_id = $2 AND link_set_id = $3 AND status <> 'revoked' RETURNING native_id`, [at, org, linkSetId]);
3699
+ return rows.length;
3700
+ },
3701
+ async unbackfilledLinkedIdPlatforms() {
3702
+ // Deployment-wide by design (see the seam's doc): no org filter, because the tenant a row
3703
+ // should carry comes from the deployment's own channel config. RLS permits this — the org
3704
+ // policies are ENFORCE-WHEN-SET and the GUC is unset here as everywhere else in this store.
3705
+ const { rows } = await client.query("SELECT DISTINCT platform FROM identity_linked_ids WHERE tenant = '' ORDER BY platform ASC");
3706
+ return rows.map((r) => r.platform);
3707
+ },
3708
+ async backfillLinkedIdTenant(platform, tenant, at) {
3709
+ // `tenant = ''` in the predicate is what makes this fill-a-blank-only: a row that already
3710
+ // names a workspace is a delivery's own statement and is never rewritten here.
3711
+ const { rows } = await client.query("UPDATE identity_linked_ids SET tenant = $1, updated_at = $2 WHERE platform = $3 AND tenant = '' RETURNING native_id", [tenant, at, platform]);
3712
+ return rows.length;
3713
+ },
3714
+ async addLinkChallenge(org, row) {
3715
+ await client.query(`INSERT INTO identity_link_challenges
3716
+ (org_id, id, nonce_hash, initiating_platform, initiating_tenant, initiating_native_id, initiating_surface_key,
3717
+ claimed_platform, claimed_tenant, claimed_native_id, claimed_at,
3718
+ transport, target_platform, target_tenant, target_native_id, back_nonce_hash,
3719
+ status, created_at, expires_at, decided_at)
3720
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20)`, [
3721
+ org,
3722
+ row.id,
3723
+ row.nonceHash,
3724
+ row.initiatingPlatform,
3725
+ row.initiatingTenant,
3726
+ row.initiatingNativeId,
3727
+ row.initiatingSurfaceKey,
3728
+ row.claimedPlatform ?? null,
3729
+ row.claimedTenant ?? null,
3730
+ row.claimedNativeId ?? null,
3731
+ row.claimedAt ?? null,
3732
+ row.transport,
3733
+ row.targetPlatform ?? null,
3734
+ row.targetTenant ?? null,
3735
+ row.targetNativeId ?? null,
3736
+ row.backNonceHash ?? null,
3737
+ row.status,
3738
+ row.createdAt,
3739
+ row.expiresAt,
3740
+ row.decidedAt ?? null,
3741
+ ]);
3742
+ },
3743
+ async getLinkChallenge(org, id) {
3744
+ const { rows } = await client.query(`${LINK_CHALLENGE_SELECT} WHERE org_id = $1 AND id = $2`, [org, id]);
3745
+ const r = rows[0];
3746
+ return r ? linkChallengeFromPgRow(org, r) : null;
3747
+ },
3748
+ async listLinkChallenges(org, filter) {
3749
+ const conjuncts = ["org_id = $1"];
3750
+ const params = [org];
3751
+ if (filter?.initiatingPlatform !== undefined) {
3752
+ params.push(filter.initiatingPlatform);
3753
+ conjuncts.push(`initiating_platform = $${params.length}`);
3754
+ }
3755
+ if (filter?.initiatingTenant !== undefined) {
3756
+ params.push(filter.initiatingTenant);
3757
+ conjuncts.push(`initiating_tenant = $${params.length}`);
3758
+ }
3759
+ if (filter?.initiatingNativeId !== undefined) {
3760
+ params.push(filter.initiatingNativeId);
3761
+ conjuncts.push(`initiating_native_id = $${params.length}`);
3762
+ }
3763
+ if (filter?.targetPlatform !== undefined) {
3764
+ params.push(filter.targetPlatform);
3765
+ conjuncts.push(`target_platform = $${params.length}`);
3766
+ }
3767
+ if (filter?.targetTenant !== undefined) {
3768
+ params.push(filter.targetTenant);
3769
+ conjuncts.push(`target_tenant = $${params.length}`);
3770
+ }
3771
+ if (filter?.targetNativeId !== undefined) {
3772
+ params.push(filter.targetNativeId);
3773
+ conjuncts.push(`target_native_id = $${params.length}`);
3774
+ }
3775
+ if (filter?.claimedPlatform !== undefined) {
3776
+ params.push(filter.claimedPlatform);
3777
+ conjuncts.push(`claimed_platform = $${params.length}`);
3778
+ }
3779
+ if (filter?.claimedTenant !== undefined) {
3780
+ params.push(filter.claimedTenant);
3781
+ conjuncts.push(`claimed_tenant = $${params.length}`);
3782
+ }
3783
+ if (filter?.claimedNativeId !== undefined) {
3784
+ params.push(filter.claimedNativeId);
3785
+ conjuncts.push(`claimed_native_id = $${params.length}`);
3786
+ }
3787
+ if (filter?.status !== undefined) {
3788
+ params.push(filter.status);
3789
+ conjuncts.push(`status = $${params.length}`);
3790
+ }
3791
+ const { rows } = await client.query(`${LINK_CHALLENGE_SELECT} WHERE ${conjuncts.join(" AND ")} ORDER BY created_at DESC`, params);
3792
+ return rows.map((r) => linkChallengeFromPgRow(org, r));
3793
+ },
3794
+ async claimLinkChallenge(org, nonceHash, platform, tenant, nativeId, at, backNonceHash) {
3795
+ // The SINGLE-USE gate as one statement: status = 'pending' admits exactly one claimer, expires_at > at closes the TTL in the same breath, and the initiator exclusion stops the issuing DM's own echo of the code from burning it - none of the three can be lost to a race between a read and a write. That exclusion is TENANT-QUALIFIED: comparing platform and native_id alone would treat an id-twin in another workspace as the initiator and refuse a legitimate claim as a self-claim.
3796
+ const { rows } = await client.query(`UPDATE identity_link_challenges
3797
+ SET claimed_platform = $1, claimed_tenant = $2, claimed_native_id = $3, claimed_at = $4, back_nonce_hash = $8, status = 'claimed'
3798
+ WHERE org_id = $5 AND nonce_hash = $6 AND status = 'pending' AND expires_at > $7
3799
+ AND NOT (initiating_platform = $1 AND initiating_tenant = $2 AND initiating_native_id = $3)
3800
+ RETURNING ${LINK_CHALLENGE_RETURNING}`, [platform, tenant, nativeId, at, org, nonceHash, at, backNonceHash ?? null]);
3801
+ const r = rows[0];
3802
+ return r ? linkChallengeFromPgRow(org, r) : null;
3803
+ },
3804
+ async consentLinkChallenge(org, id, consenter, at, backNonceHash) {
3805
+ // The TARGET MATCH is a conjunct, not a caller-side check (see store.ts's contract): a consent
3806
+ // from any account but the one this challenge named matches no row and returns null. Single-use
3807
+ // rides `status = 'pending'` and the TTL rides `expires_at > at`, both in the same statement.
3808
+ const { rows } = await client.query(`UPDATE identity_link_challenges
3809
+ SET claimed_platform = $1, claimed_tenant = $2, claimed_native_id = $3, claimed_at = $4, back_nonce_hash = $7, status = 'claimed'
3810
+ WHERE org_id = $5 AND id = $6 AND status = 'pending' AND expires_at > $4
3811
+ AND target_platform = $1 AND target_tenant = $2 AND target_native_id = $3
3812
+ RETURNING ${LINK_CHALLENGE_RETURNING}`, [consenter.platform, consenter.tenant, consenter.nativeId, at, org, id, backNonceHash ?? null]);
3813
+ const r = rows[0];
3814
+ return r ? linkChallengeFromPgRow(org, r) : null;
3815
+ },
3816
+ async decideLinkChallenge(org, id, from, to, at) {
3817
+ // TTL CONJUNCT ON RATIFY (audit finding F7): the terminal `ratified` transition — the ONE that
3818
+ // writes a link — additionally requires `expires_at > at`, so a claimed-but-expired challenge
3819
+ // cannot be ratified even without a prior sweep. Other transitions (deny) don't carry it: a
3820
+ // deny writes nothing, so bounding it buys no safety and would only turn an honest late deny
3821
+ // into a silent no-op. Enforced INSIDE the statement, never by the caller comparing clocks.
3822
+ const ttlConjunct = to === "ratified" ? " AND expires_at > $6" : "";
3823
+ const params = to === "ratified" ? [to, at, org, id, [...from], at] : [to, at, org, id, [...from]];
3824
+ const { rows } = await client.query(`UPDATE identity_link_challenges SET status = $1, decided_at = $2
3825
+ WHERE org_id = $3 AND id = $4 AND status = ANY($5)${ttlConjunct} RETURNING id`, params);
3826
+ return rows.length > 0;
3827
+ },
3828
+ async expireLinkChallenges(org, nowIso) {
3829
+ const { rows } = await client.query(`UPDATE identity_link_challenges SET status = 'expired', decided_at = $1
3830
+ WHERE org_id = $2 AND status IN ('pending', 'claimed') AND expires_at <= $1 RETURNING id`, [nowIso, org]);
3831
+ return rows.length;
3832
+ },
3833
+ async addCredentialGrantAsk(org, row) {
3834
+ refuseHalfBorrow("credential_grant_ask", row);
3835
+ await client.query(`INSERT INTO credential_grant_ask
3836
+ (org_id, id, requester_principal_id, owner_principal_id, owner_slug, owner_platform, owner_native_id, connector, verb, resource,
3837
+ mcp_tool, frozen_args, tool_name,
3838
+ scope_key, domain_scope_key, purpose, requester_target, card_surface_id, card_message_id, requested_mode, status, created_at, expires_at, decided_at, grant_id)
3839
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25)`, [
3840
+ org,
3841
+ row.id,
3842
+ row.requesterPrincipalId,
3843
+ row.ownerPrincipalId,
3844
+ row.ownerSlug,
3845
+ row.ownerPlatform,
3846
+ row.ownerNativeId,
3847
+ row.connector,
3848
+ row.verb,
3849
+ row.resource,
3850
+ row.mcpTool ?? null,
3851
+ grantJsonColumn(row.frozenArgs),
3852
+ row.toolName ?? null,
3853
+ row.scopeKey,
3854
+ row.domainScopeKey ?? null,
3855
+ row.purpose,
3856
+ row.requesterTarget ?? null,
3857
+ row.cardSurfaceId ?? null,
3858
+ row.cardMessageId ?? null,
3859
+ row.requestedMode,
3860
+ row.status,
3861
+ row.createdAt,
3862
+ row.expiresAt,
3863
+ row.decidedAt ?? null,
3864
+ row.grantId ?? null,
3865
+ ]);
3866
+ },
3867
+ async setCredentialGrantAskCard(org, id, surfaceId, messageId) {
3868
+ await client.query("UPDATE credential_grant_ask SET card_surface_id = $1, card_message_id = $2 WHERE org_id = $3 AND id = $4", [surfaceId, messageId, org, id]);
3869
+ },
3870
+ async getCredentialGrantAsk(org, id) {
3871
+ const { rows } = await client.query(`${GRANT_ASK_SELECT} WHERE org_id = $1 AND id = $2`, [org, id]);
3872
+ const r = rows[0];
3873
+ return r ? grantAskFromPgRow(r) : null;
3874
+ },
3875
+ async liveCredentialGrantAsk(org, requesterPrincipalId, ownerPrincipalId, verb, resource, nowIso) {
3876
+ // EXPIRY IN THE PREDICATE, never a status check alone: the sweep is a tidy-up, so an unswept
3877
+ // `pending` row past its TTL must read as gone here or a lapsed ask would block a fresh one.
3878
+ const { rows } = await client.query(`${GRANT_ASK_SELECT}
3879
+ WHERE org_id = $1 AND requester_principal_id = $2 AND owner_principal_id = $3 AND verb = $4 AND resource = $5
3880
+ AND status = 'pending' AND expires_at > $6
3881
+ ORDER BY created_at DESC LIMIT 1`, [org, requesterPrincipalId, ownerPrincipalId, verb, resource, nowIso]);
3882
+ const r = rows[0];
3883
+ return r ? grantAskFromPgRow(r) : null;
3884
+ },
3885
+ async approveCredentialGrantAsk(org, id, mode, grantId, at) {
3886
+ // Single-answer + TTL in ONE statement. `status = 'pending'` admits exactly one approval, and
3887
+ // `expires_at > at` makes a late click on a scrolled-back DM card lose the CAS — the row is
3888
+ // the only thing that can refuse it, because the card never goes away on its own.
3889
+ const { rows } = await client.query(`UPDATE credential_grant_ask SET status = 'approved', requested_mode = $1, grant_id = $2, decided_at = $3
3890
+ WHERE org_id = $4 AND id = $5 AND status = 'pending' AND expires_at > $3
3891
+ RETURNING ${GRANT_ASK_COLUMNS}`, [mode, grantId, at, org, id]);
3892
+ const r = rows[0];
3893
+ return r ? grantAskFromPgRow(r) : null;
3894
+ },
3895
+ async decideCredentialGrantAsk(org, id, from, to, at) {
3896
+ const { rows } = await client.query(`UPDATE credential_grant_ask SET status = $1, decided_at = $2 WHERE org_id = $3 AND id = $4 AND status = ANY($5) RETURNING id`, [to, at, org, id, [...from]]);
3897
+ return rows.length > 0;
3898
+ },
3899
+ async listExpiredCredentialGrantAsks(org, nowIso) {
3900
+ const { rows } = await client.query(`${GRANT_ASK_SELECT} WHERE org_id = $1 AND status = 'pending' AND expires_at <= $2 ORDER BY created_at ASC`, [org, nowIso]);
3901
+ return rows.map(grantAskFromPgRow);
3902
+ },
3903
+ async pendingCredentialGrantAsksForScope(org, scopeKey, nowIso) {
3904
+ // EXPIRY IN THE PREDICATE, for `liveCredentialGrantAsk`'s reason: the sweep is a tidy-up, so an
3905
+ // unswept `pending` row past its TTL must read as gone or a lapsed ask would hold its name for
3906
+ // ever. The read rides the `(org_id, scope_key)` index the table already carries.
3907
+ const { rows } = await client.query(`${GRANT_ASK_SELECT} WHERE org_id = $1 AND scope_key = $2 AND status = 'pending' AND expires_at > $3 ORDER BY created_at ASC`, [org, scopeKey, nowIso]);
3908
+ return rows.map(grantAskFromPgRow);
3909
+ },
3910
+ async addCredentialGrant(org, row) {
3911
+ refuseHalfBorrow("credential_grant", row);
3912
+ await client.query(`INSERT INTO credential_grant
3913
+ (org_id, id, ask_id, requester_principal_id, owner_principal_id, owner_slug, connector, verb, resource,
3914
+ mcp_tool, frozen_args, tool_name, input_schema,
3915
+ scope_key, mode, tier, status, purpose, created_at, expires_at, used_at, revoked_at)
3916
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22)`, [
3917
+ org,
3918
+ row.id,
3919
+ row.askId,
3920
+ row.requesterPrincipalId,
3921
+ row.ownerPrincipalId,
3922
+ row.ownerSlug,
3923
+ row.connector,
3924
+ row.verb,
3925
+ row.resource,
3926
+ row.mcpTool ?? null,
3927
+ grantJsonColumn(row.frozenArgs),
3928
+ row.toolName ?? null,
3929
+ grantJsonColumn(row.inputSchema),
3930
+ row.scopeKey,
3931
+ row.mode,
3932
+ row.tier,
3933
+ row.status,
3934
+ row.purpose,
3935
+ row.createdAt,
3936
+ row.expiresAt,
3937
+ row.usedAt ?? null,
3938
+ row.revokedAt ?? null,
3939
+ ]);
3940
+ },
3941
+ async getCredentialGrant(org, id) {
3942
+ const { rows } = await client.query(`${GRANT_SELECT} WHERE org_id = $1 AND id = $2`, [org, id]);
3943
+ const r = rows[0];
3944
+ return r ? grantFromPgRow(r) : null;
3945
+ },
3946
+ async credentialGrantsForScope(org, scopeKey) {
3947
+ // NO status filter, deliberately — the mount projects EXISTENCE and the broker refuses on
3948
+ // STATE. See the store.ts contract for why a status filter here breaks the cold-heal path.
3949
+ const { rows } = await client.query(`${GRANT_SELECT} WHERE org_id = $1 AND scope_key = $2 ORDER BY created_at DESC`, [org, scopeKey]);
3950
+ return rows.map(grantFromPgRow);
3951
+ },
3952
+ async liveStandingCredentialGrantsForScope(org, scopeKey, nowIso) {
3953
+ // STATUS, EXPIRY, REVOCATION AND MODE ALL IN THE PREDICATE — a domain-keyed row is read by
3954
+ // sessions that never saw it, so a dead one must not mount there. See the store.ts contract.
3955
+ const { rows } = await client.query(`${GRANT_SELECT} WHERE org_id = $1 AND scope_key = $2 AND mode = 'standing' AND status = 'active'
3956
+ AND expires_at > $3 AND revoked_at IS NULL ORDER BY created_at DESC`, [org, scopeKey, nowIso]);
3957
+ return rows.map(grantFromPgRow);
3958
+ },
3959
+ async liveCredentialGrantsForOwner(org, ownerPrincipalId, nowIso) {
3960
+ // STATUS AND EXPIRY BOTH IN THE PREDICATE — the owner may only be offered rows they can still
3961
+ // end. See the store.ts contract for why this filters where `credentialGrantsForScope` must not.
3962
+ const { rows } = await client.query(`${GRANT_SELECT} WHERE org_id = $1 AND owner_principal_id = $2 AND status = 'active' AND expires_at > $3 ORDER BY created_at ASC`, [org, ownerPrincipalId, nowIso]);
3963
+ return rows.map(grantFromPgRow);
3964
+ },
3965
+ async liveBorrowCredentialGrant(org, ownerPrincipalId, connector, mcpTool, frozenArgsDigest, scopeKey, nowIso) {
3966
+ // THE DIGEST IS COMPARED IN TYPESCRIPT, not in SQL, because it is not a column. The predicate
3967
+ // narrows to the rows that could match — one owner, one connector, one vendor tool, one chat,
3968
+ // still live — and there are at most a handful of those. A digest column would be a second
3969
+ // copy of `frozen_args` that a partial write could put out of step with it.
3970
+ const { rows } = await client.query(`${GRANT_SELECT} WHERE org_id = $1 AND owner_principal_id = $2 AND connector = $3 AND mcp_tool = $4 AND scope_key = $5
3971
+ AND status = 'active' AND expires_at > $6 ORDER BY created_at DESC`, [org, ownerPrincipalId, connector, mcpTool, scopeKey, nowIso]);
3972
+ for (const r of rows) {
3973
+ const row = grantFromPgRow(r);
3974
+ if (row.frozenArgs !== undefined && grantFrozenArgsDigest(row.frozenArgs) === frozenArgsDigest)
3975
+ return row;
3976
+ }
3977
+ return null;
3978
+ },
3979
+ async burnCredentialGrant(org, id, at) {
3980
+ // THE WHOLE OF ONCE-MODE. Both conjuncts sit in the statement: `status = 'active'` makes the
3981
+ // burn single-use, `expires_at > at` makes an expired row unspendable without waiting for a
3982
+ // sweep. A retried turn, a replayed step and two parallel calls in one step all race here.
3983
+ const { rows } = await client.query(`UPDATE credential_grant SET status = 'used', used_at = $1
3984
+ WHERE org_id = $2 AND id = $3 AND status = 'active' AND expires_at > $1 RETURNING ${GRANT_COLUMNS}`, [at, org, id]);
3985
+ const r = rows[0];
3986
+ return r ? grantFromPgRow(r) : null;
3987
+ },
3988
+ async refundCredentialGrant(org, id, burnedAt) {
3989
+ // `used_at = $3` IS THE CONTROL, not a tidy extra conjunct: it binds the refund to the caller's
3990
+ // OWN burn, so a call that lost the burn race cannot un-spend the winner's. `revoked_at IS
3991
+ // NULL` is what makes an owner's revoke beat a refund racing it — see `revokeCredentialGrant`.
3992
+ const { rows } = await client.query(`UPDATE credential_grant SET status = 'active', used_at = NULL
3993
+ WHERE org_id = $1 AND id = $2 AND status = 'used' AND used_at = $3 AND revoked_at IS NULL RETURNING id`, [org, id, burnedAt]);
3994
+ return rows.length > 0;
3995
+ },
3996
+ async claimCredentialGrantRefund(org, id, turnKey, cap) {
3997
+ // ONE STATEMENT, so two calls racing in one step cannot both read the same remaining count.
3998
+ // The right-hand `refund_turn_seq` is the row's PRE-UPDATE value in both engines, so every
3999
+ // CASE and the WHERE read the same stored ordinal. `COALESCE` covers a row written before the
4000
+ // count column existed; the casts are what let Postgres type a parameter that one arm only
4001
+ // compares to NULL.
4002
+ //
4003
+ // 🔴 ONLY A STRICTLY LATER TURN ROLLS (OPE-1281). The predicate is the ORDINAL comparison,
4004
+ // not the `IS DISTINCT FROM` on the key this statement used to carry: a distinctness test
4005
+ // rolls in both directions, so two turn ids alternating on one row each read the other as new
4006
+ // and each collected a fresh allowance. A NULL ordinal — no turn id, or a key eve's shape no
4007
+ // longer mints — never rolls; it counts against the stored turn and leaves the turn in place,
4008
+ // which is the fail-closed direction.
4009
+ //
4010
+ // 🔴 A ROW THAT HAS COUNTED A TURN AND CARRIES NO ORDINAL NEVER ROLLS EITHER, and that is the
4011
+ // upgrade window rather than a corner. A row written before this column existed holds a turn
4012
+ // key, a count up to `cap`, and a NULL ordinal; reading that NULL as "never counted" would let
4013
+ // ANY turn roll it — the same turn included — which is the hole this ticket closes. So the
4014
+ // first disjunct asks for BOTH columns empty, which is a row that has genuinely counted
4015
+ // nothing. A migrated row keeps the allowance it had for the rest of its life, bounded by the
4016
+ // grant's TTL.
4017
+ const rolls = "($5::bigint IS NOT NULL AND ((refund_turn IS NULL AND refund_turn_seq IS NULL) OR $5::bigint > refund_turn_seq))";
4018
+ const { rows } = await client.query(`UPDATE credential_grant
4019
+ SET refund_turn = CASE WHEN ${rolls} THEN $3::text ELSE refund_turn END,
4020
+ refund_turn_seq = CASE WHEN ${rolls} THEN $5::bigint ELSE refund_turn_seq END,
4021
+ refund_count = CASE WHEN ${rolls} THEN 1 ELSE COALESCE(refund_count, 0) + 1 END
4022
+ WHERE org_id = $1 AND id = $2
4023
+ AND (${rolls} OR COALESCE(refund_count, 0) < $4) RETURNING id`, [org, id, turnKey ?? null, cap, grantRefundTurnOrdinal(turnKey) ?? null]);
4024
+ return rows.length > 0;
4025
+ },
4026
+ async revokeCredentialGrant(org, id, at) {
4027
+ const { rows } = await client.query(`UPDATE credential_grant SET status = 'revoked', revoked_at = $1 WHERE org_id = $2 AND id = $3 AND status = 'active' RETURNING id`, [at, org, id]);
4028
+ if (rows.length > 0)
4029
+ return true;
4030
+ // THE ROW WAS NOT LIVE. If it is `used`, the owner may be racing a once call that is still in
4031
+ // flight: stamp the intent so a refund cannot re-open it (OPE-1198). The STATUS is left alone —
4032
+ // a spent grant is already terminal, and rewriting it would lose which arm ended it. The answer
4033
+ // stays `false`: this call revoked no live grant.
4034
+ await client.query(`UPDATE credential_grant SET revoked_at = $1 WHERE org_id = $2 AND id = $3 AND status = 'used' AND revoked_at IS NULL`, [at, org, id]);
4035
+ return false;
4036
+ },
4037
+ async expireCredentialGrants(org, nowIso) {
4038
+ const { rows } = await client.query(`UPDATE credential_grant SET status = 'expired' WHERE org_id = $1 AND status = 'active' AND expires_at <= $2 RETURNING id`, [org, nowIso]);
4039
+ return rows.length;
4040
+ },
4041
+ async getMeta(key) {
4042
+ const { rows } = await client.query("SELECT value FROM instance_meta WHERE key = $1", [key]);
4043
+ const r = rows[0];
4044
+ return r ? r.value : null;
4045
+ },
4046
+ async setMeta(key, value) {
4047
+ await client.query(`INSERT INTO instance_meta (key, value) VALUES ($1, $2)
4048
+ ON CONFLICT (key) DO UPDATE SET value = excluded.value`, [key, value]);
4049
+ },
4050
+ };
4051
+ }
4052
+ //# sourceMappingURL=postgres.js.map