@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,4007 @@
1
+ // The SQLite adapter behind the operational store seam: local and small self-host installs, on Node's built-in node:sqlite, sharing one DB file with the memory provider.
2
+ // Audit is append-only BY CONTRACT here — this module has no delete path — while Postgres enforces append-only at the DB layer.
3
+
4
+ import { mkdirSync } from "node:fs";
5
+ import { dirname, join } from "node:path";
6
+ import { DatabaseSync } from "node:sqlite";
7
+ import type { Routine } from "../routines/routine.js";
8
+ // A VALUE import, deliberately: the assertions and the retention ceiling are ONE definition shared
9
+ // by both backends, so a bound cannot drift between two hand-copied SQL statements.
10
+ // (Webhook hooks are not stored here at all: OPE-224 left ONE config-declared class, so a hook's
11
+ // identity is whatever a merged PR says and uniqueness is a boot check, not an index.)
12
+ 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, type AuditChainRow, type AuditEntry, type ChannelSessionRuntimeStamp, type AuditFilter, type CapLevel, type ClaimedIngressDelivery, type DueIngressDelivery, type LinkChallengeRow, type LinkChallengeStatus, type LinkSetRow, type LinkSetStatus, type LinkedIdRow, type LinkedIdStatus, type OperationalStore, type SlackAttachmentRow, type SpendLedgerRow, type SpendLedgerWrite, type SpendLedgerFilter, type SpendTotals, type SurfaceMode, type TurnAnchorRow, type UsageEventEntry, type ModelCallCaptureWrite, type ModelCallCaptureRow, type ModelCallCaptureSessionRow, type MemoryProposalRow, type MemoryProposalWrite, type DmAudienceRow } from "./store.js";
13
+ import { grantBorrowColumnsProblem, grantFrozenArgsDigest, grantJsonColumn, grantJsonFromColumn, grantRefundTurnOrdinal } from "./credential-grant-rows.js";
14
+ import type { CredentialGrantAskRow, CredentialGrantAskState, CredentialGrantMode, CredentialGrantRow, CredentialGrantState } from "./credential-grant-rows.js";
15
+ import type { PendingActionRow, PendingStatus } from "../approvals/types.js";
16
+ // Both prefixes are imported, never respelled, so the legacy-connector sweep's key prefix and kind prefix keep one spelling in the file that defines them.
17
+ import { CONNECTOR_OP_KIND_PREFIX, ROUTINE_PERMISSION_PREFIX } from "../approvals/session-grant.js";
18
+ import { SESSION_TAIL_MAX_ENTRIES, type SessionTailEntry } from "../channels/session-tail.js";
19
+ import type { ModelReasoning } from "../memory/domain.js";
20
+ import { AUDIT_CHAIN_EPOCH_ACTION, auditEpochDetail, auditEpochSealFor, auditRowSha, withOrgAuditLock } from "../audit/chain.js";
21
+ import { assembleAnalyticsSql } from "../analytics/compile.js";
22
+
23
+ // Shares memory's DB-file convention so both land in one file; override with
24
+ // OE_SQLITE_PATH (memory + operational then share it — table names don't clash).
25
+ /** The resolved file, and WHETHER `OE_SQLITE_PATH` named it. The flag is what {@link getDb} needs:
26
+ * the fallback branch is derived from `OE_MEMORY_DIR`, else the process's cwd, and neither may
27
+ * displace a handle the env already pinned — so the guard pins against an `OE_MEMORY_DIR` change
28
+ * mid-process too, not only against a blocked `OE_SQLITE_PATH` read. */
29
+ function dbPath(): { readonly path: string; readonly fromEnv: boolean } {
30
+ if (process.env.OE_SQLITE_PATH) return { path: process.env.OE_SQLITE_PATH, fromEnv: true };
31
+ const root = process.env.OE_MEMORY_DIR ?? join(process.cwd(), ".open-everywhere-memory");
32
+ return { path: join(root, "open-everywhere.sqlite3"), fromEnv: false };
33
+ }
34
+
35
+ let db: DatabaseSync | null = null;
36
+ let openedPath: string | null = null;
37
+
38
+ function getDb(): DatabaseSync {
39
+ const resolved = dbPath();
40
+ // 🔴 AN ABSENT `OE_SQLITE_PATH` NEVER MOVES AN OPEN HANDLE (OPE-1933). This function re-reads the
41
+ // env on EVERY call, so any scope that hides `process.env` turns the env read into `undefined` —
42
+ // and the fallback above then computes a DIFFERENT file from `process.cwd()`. The old code closed
43
+ // the open DB and reopened at that file, silently, mid-process: every row written afterwards
44
+ // landed in a store nothing would ever read again. just-bash's DefenseInDepthBox is one such
45
+ // scope (its ALS wraps `process.env` in a blocking Proxy), and a store call made inside it is all
46
+ // it takes. An absent env read is NOT an instruction to switch files, so it keeps the handle.
47
+ // A PRESENT value naming a different file still switches — that is an explicit instruction, not
48
+ // a guess — and a test that genuinely wants a different path uses `_resetOperationalDbForTest`.
49
+ if (db && !resolved.fromEnv) return db;
50
+ const path = resolved.path;
51
+ if (db && openedPath !== path) {
52
+ db.close();
53
+ db = null;
54
+ }
55
+ if (db) return db;
56
+ if (path !== ":memory:") mkdirSync(dirname(path), { recursive: true });
57
+ const handle = new DatabaseSync(path);
58
+ // busy_timeout: WAL allows one writer; a second process (the integration tier reads/tampers the
59
+ // store through its own handle) would otherwise get an immediate SQLITE_BUSY instead of a retry.
60
+ handle.exec("PRAGMA journal_mode = WAL; PRAGMA foreign_keys = ON; PRAGMA busy_timeout = 5000;");
61
+ // An old-shape spend_ledger is DROPPED and recreated, never migrated: cost_source sits in the primary key and SQLite cannot ALTER a key.
62
+ // The accepted cost is at most the current month's cap accounting; usd_micros_measured is the shape probe, because no old table can have it.
63
+ const spendCols = handle.prepare("SELECT name FROM pragma_table_info('spend_ledger')").all() as { name: string }[];
64
+ if (spendCols.length > 0 && !spendCols.some((c) => c.name === "usd_micros_measured")) handle.exec("DROP TABLE spend_ledger");
65
+ // An existing identity_linked_ids crosses to the tenant-in-key shape by rename-create-copy-drop, and ITS ROWS ARE KEPT, unlike the spend_ledger case above.
66
+ // The index must be dropped FIRST: SQLite index names are schema-global, so a renamed table keeps the name the CREATE INDEX below needs.
67
+ const linkedIdCols = handle.prepare("SELECT name FROM pragma_table_info('identity_linked_ids')").all() as { name: string }[];
68
+ const needsLinkedIdTenantRebuild = linkedIdCols.length > 0 && !linkedIdCols.some((c) => c.name === "tenant");
69
+ if (needsLinkedIdTenantRebuild) {
70
+ handle.exec("DROP INDEX IF EXISTS identity_linked_ids_org_set; ALTER TABLE identity_linked_ids RENAME TO identity_linked_ids__pre_tenant;");
71
+ }
72
+ handle.exec(`
73
+ CREATE TABLE IF NOT EXISTS spend_ledger (
74
+ org_id TEXT NOT NULL,
75
+ surface_key TEXT NOT NULL,
76
+ principal_id TEXT NOT NULL DEFAULT '', -- '' = unattributed (PK columns can't be NULL)
77
+ routine_id TEXT NOT NULL DEFAULT '', -- '' = not a routine turn
78
+ model TEXT NOT NULL DEFAULT '', -- '' = no model (unstamped call; sandbox runtime)
79
+ period TEXT NOT NULL, -- "YYYY-MM"
80
+ -- OPE-1862 (mirrored in the ALTER list below): WHICH KIND OF CONVERSATION this row's spend
81
+ -- happened in — 'dm' | 'mpim' | 'channel', or '' when nothing stamped it. The anti-doxxing
82
+ -- mask reads THIS and never the shape of a surface id, so Discord and Teams DMs mask exactly
83
+ -- as Slack's do. Deliberately OUTSIDE the primary key: a surface's mode never changes, so
84
+ -- keying on it would split a month for nothing — and would force the table drop an additive
85
+ -- column avoids.
86
+ surface_mode TEXT NOT NULL DEFAULT '',
87
+ input_tokens INTEGER NOT NULL DEFAULT 0,
88
+ output_tokens INTEGER NOT NULL DEFAULT 0,
89
+ cache_read_tokens INTEGER NOT NULL DEFAULT 0,
90
+ cache_write_tokens INTEGER NOT NULL DEFAULT 0,
91
+ -- OPE-1611 (mirrored in the ALTER list below): reasoning tokens, ATTRIBUTION only. No rate
92
+ -- table names a reasoning rate, so this never reaches usd_micros and no cap sees it.
93
+ reasoning_tokens INTEGER NOT NULL DEFAULT 0,
94
+ usd_micros INTEGER NOT NULL DEFAULT 0, -- millionths of a dollar, DERIVED at write from the rate table (what caps sum)
95
+ -- OPE-369: the GATEWAY's own billed figure for these same calls, when it published one.
96
+ -- 0 on a cost_source='derived' row. Never read by a cap — see store.ts's CostSource section.
97
+ usd_micros_measured INTEGER NOT NULL DEFAULT 0,
98
+ cost_source TEXT NOT NULL DEFAULT 'derived', -- 'measured' | 'derived'; in the PK so a row is homogeneous
99
+ calls INTEGER NOT NULL DEFAULT 0,
100
+ PRIMARY KEY (org_id, surface_key, principal_id, routine_id, model, period, cost_source)
101
+ );
102
+ -- OPE-1677: the PERIOD index the primary key cannot be. The bounded spend reads are shaped
103
+ -- "WHERE org_id = ? AND period ..." (spendLedgerConjuncts in store.ts). period is the SIXTH
104
+ -- primary-key column, and a btree bounds its scan only up to the first column the query
105
+ -- leaves unconstrained -- so the automatic primary-key index bounds on org_id, and everything
106
+ -- after it is a per-row test over every row the org ever wrote. This index puts period
107
+ -- second, which makes the range a plan-level narrowing rather than a transfer saving. It
108
+ -- matters most on the "/oe budget raise" domain scan, which answers a Discord interaction
109
+ -- inside 3 seconds. This statement is also the MIGRATION: the CREATE block runs on every
110
+ -- database open, so an existing file builds the index in place, with no drop-and-recreate.
111
+ CREATE INDEX IF NOT EXISTS spend_ledger_org_period ON spend_ledger (org_id, period);
112
+ CREATE TABLE IF NOT EXISTS routine (
113
+ org_id TEXT NOT NULL,
114
+ id TEXT NOT NULL,
115
+ surface_key TEXT NOT NULL,
116
+ data TEXT NOT NULL, -- JSON of the full Routine
117
+ PRIMARY KEY (org_id, id)
118
+ );
119
+ -- APPEND-ONLY prompt history for the mutable routine row (OPE-242). Written by
120
+ -- updateRoutine on a patch that REPLACES the prompt, never updated, never deleted, never
121
+ -- pruned — see RoutinePromptRevisionRow in store.ts for why a routine's prompt history is an
122
+ -- audit artefact (an edit revokes standing authority), why the log begins at the first EDIT
123
+ -- rather than at creation, and for the retention position. Append-only here is BY CONTRACT
124
+ -- only: sqlite has no RLS, so unlike Postgres (SELECT+INSERT policies under FORCE) nothing at
125
+ -- the engine stops a rewrite. Same caveat audit_entry carries on this deprecated backend,
126
+ -- stated rather than implied.
127
+ CREATE TABLE IF NOT EXISTS routine_prompt_revisions (
128
+ seq INTEGER PRIMARY KEY AUTOINCREMENT,
129
+ org_id TEXT NOT NULL,
130
+ surface_key TEXT NOT NULL,
131
+ routine_id TEXT NOT NULL,
132
+ prompt TEXT NOT NULL, -- the exact text the routine ran under
133
+ generation INTEGER, -- the promptGeneration it ran under (joins routinePermissionKey)
134
+ authored_by TEXT, -- createdBy on the genesis row, the edit's requestedBy after
135
+ armed_by TEXT, -- the approver whose click armed it (never on genesis)
136
+ approval_id TEXT, -- pending_actions.id of the card that armed it
137
+ recorded_at TEXT NOT NULL -- ISO-8601 (the routine's createdAt on the genesis row)
138
+ );
139
+ CREATE INDEX IF NOT EXISTS routine_prompt_revisions_org_surface_routine ON routine_prompt_revisions (org_id, surface_key, routine_id, seq);
140
+ CREATE TABLE IF NOT EXISTS audit_entry (
141
+ seq INTEGER PRIMARY KEY AUTOINCREMENT,
142
+ ts TEXT NOT NULL,
143
+ org_id TEXT NOT NULL,
144
+ platform TEXT NOT NULL,
145
+ workspace TEXT NOT NULL,
146
+ surface TEXT,
147
+ surface_mode TEXT, -- OPE-1866: the conversation the surface names; NULL = unclassified, which MASKS
148
+ principal_id TEXT,
149
+ action TEXT NOT NULL,
150
+ detail TEXT, -- JSON
151
+ prev_sha TEXT -- sha256 of the org's previous row (OPE-52 hash chain); NULL = genesis
152
+ );
153
+ CREATE INDEX IF NOT EXISTS audit_org_ts ON audit_entry (org_id, ts);
154
+ CREATE TABLE IF NOT EXISTS spend_limit (
155
+ org_id TEXT NOT NULL,
156
+ scope_key TEXT NOT NULL,
157
+ level TEXT NOT NULL, -- "surface" | "workspace" | "domain" | "user" (free-text, no CHECK — see store.ts CapLevel)
158
+ monthly_tokens INTEGER NOT NULL, -- -1 = no token component (legacy NOT NULL; see setSpendLimit)
159
+ monthly_usd REAL, -- NULL = no USD component
160
+ expires_at INTEGER, -- epoch ms; NULL = no auto-expiry
161
+ reason TEXT,
162
+ set_by TEXT,
163
+ PRIMARY KEY (org_id, scope_key, level)
164
+ );
165
+ CREATE TABLE IF NOT EXISTS halt (
166
+ org_id TEXT NOT NULL,
167
+ level TEXT NOT NULL, -- "" on an org-wide row: FILLER, never an address (store.ts haltAddressColumns)
168
+ scope_key TEXT NOT NULL, -- "" on an org-wide row, same reason
169
+ org_wide INTEGER NOT NULL, -- 1 = the org-wide MARKER; the column every match branches on first
170
+ active INTEGER NOT NULL, -- 1 = halted; a cleared row stays for the trail
171
+ set_by TEXT,
172
+ set_at TEXT NOT NULL, -- ISO-8601
173
+ set_ref TEXT, -- host wake owning a chat-set halt; NULL for operator/legacy rows
174
+ cleared_by TEXT,
175
+ cleared_at TEXT, -- ISO-8601; NULL until a resume clears it
176
+ PRIMARY KEY (org_id, level, scope_key, org_wide)
177
+ );
178
+ CREATE TABLE IF NOT EXISTS connector_override (
179
+ org_id TEXT NOT NULL,
180
+ scope_key TEXT NOT NULL,
181
+ connector TEXT NOT NULL,
182
+ granted INTEGER NOT NULL, -- 1 = grant, 0 = revoke
183
+ reason TEXT, -- no expires_at: auto-expiry would re-open access
184
+ set_by TEXT,
185
+ PRIMARY KEY (org_id, scope_key, connector)
186
+ );
187
+ CREATE TABLE IF NOT EXISTS thread_engagement (
188
+ org_id TEXT NOT NULL,
189
+ surface_key TEXT NOT NULL, -- platform/workspace/surface (the channel)
190
+ thread_ts TEXT NOT NULL,
191
+ engaged_at TEXT NOT NULL, -- ISO-8601, set once
192
+ last_turn_at TEXT NOT NULL, -- ISO-8601, refreshed each engaged turn
193
+ participating INTEGER NOT NULL DEFAULT 0, -- 1 = invited participant (replied/@mentioned); 0 = warm watcher
194
+ silent_streak INTEGER NOT NULL DEFAULT 0, -- consecutive silent woken turns since last engage/participation
195
+ stopped INTEGER NOT NULL DEFAULT 0, -- 1 = an explicit stop landed (task #100 window path); suppress non-mention wakes until re-invited
196
+ 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)
197
+ PRIMARY KEY (org_id, surface_key, thread_ts)
198
+ );
199
+ CREATE TABLE IF NOT EXISTS channel_session (
200
+ org_id TEXT NOT NULL,
201
+ surface_key TEXT NOT NULL, -- the channel (platform/workspace/surface)
202
+ token TEXT NOT NULL, -- caller-minted continuation token for the CURRENT generation
203
+ generation INTEGER NOT NULL, -- 1 on first mint, +1 on every rotation
204
+ created_at TEXT NOT NULL, -- ISO-8601, reset on rotation
205
+ last_wake_at TEXT NOT NULL, -- ISO-8601, bumped by touchChannelSession, reset on rotation
206
+ turn_count INTEGER NOT NULL DEFAULT 0, -- bumped by touchChannelSession, reset to 0 on rotation (BACKSTOP trigger)
207
+ input_tokens_total INTEGER, -- measured cumulative input+cacheRead this generation (§2 #551); NULL = unknown ⇒ rotate
208
+ first_wake_at TEXT, -- ISO-8601 of the first delivered wake (H7c); NULL = none yet ⇒ still fresh
209
+ last_input_tokens INTEGER, -- OPE-794: measured input+cacheRead of the LATEST request (SET, not summed); NULL = none yet ⇒ rung skipped
210
+ 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
211
+ 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
212
+ 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
213
+ PRIMARY KEY (org_id, surface_key)
214
+ );
215
+ -- session_tail (OPE-794): the standing-seat TAIL ring. One row per recorded conversational
216
+ -- event on ONE generation — the wake messages the deployment delivered and the posts the seat
217
+ -- made. The rotate leg reads the OUTGOING generation's rows and renders them into the fresh
218
+ -- generation's first wake. Keyed by the generation's live TOKEN, so a straggler write from a
219
+ -- retired generation files under the retired token and is simply never read again.
220
+ -- Bounded on write (channels/session-tail.ts SESSION_TAIL_MAX_ENTRIES) and dropped once carried.
221
+ CREATE TABLE IF NOT EXISTS session_tail (
222
+ org_id TEXT NOT NULL,
223
+ surface_key TEXT NOT NULL, -- the channel_session registry key this generation lives under
224
+ token TEXT NOT NULL, -- the generation's continuation token (the read + prune key)
225
+ seq INTEGER NOT NULL, -- insertion ordinal within the token; ties broken by the at column at render
226
+ at TEXT NOT NULL, -- ISO-8601 of the event (the ORDERING key the render sorts on)
227
+ entry_json TEXT NOT NULL, -- serialized SessionTailEntry (opaque to the store)
228
+ PRIMARY KEY (org_id, surface_key, token, seq)
229
+ );
230
+ CREATE TABLE IF NOT EXISTS event_dedupe (
231
+ org_id TEXT NOT NULL,
232
+ key TEXT NOT NULL, -- Slack event_id (or channel:ts fallback)
233
+ seen_at TEXT NOT NULL, -- ISO-8601 (lexicographic = chronological)
234
+ PRIMARY KEY (org_id, key)
235
+ );
236
+ -- Durable provider inbox. The verified signer id is part of the immutable delivery identity;
237
+ -- payload_json contains a versioned provider envelope but never the raw signature or secret.
238
+ -- Pending rows have retain_until NULL and survive arbitrarily long outages. Completion erases
239
+ -- payload_json and starts the bounded tombstone clock in the SAME fenced UPDATE.
240
+ CREATE TABLE IF NOT EXISTS ingress_delivery (
241
+ org_id TEXT NOT NULL,
242
+ source TEXT NOT NULL,
243
+ authority_id TEXT NOT NULL,
244
+ delivery_id TEXT NOT NULL,
245
+ payload_json TEXT,
246
+ received_at TEXT NOT NULL,
247
+ available_at TEXT NOT NULL,
248
+ claim_id TEXT,
249
+ claimed_at TEXT,
250
+ completed_at TEXT,
251
+ retain_until TEXT,
252
+ PRIMARY KEY (org_id, source, authority_id, delivery_id)
253
+ );
254
+ CREATE INDEX IF NOT EXISTS ingress_delivery_due ON ingress_delivery (org_id, source, completed_at, available_at, claimed_at);
255
+ -- webhook_capture: the BOUNDED CAPTURE WINDOW (OPE-211 + OPE-184 Half 2). The only table here
256
+ -- that holds bytes an outside party authored — see webhooks/capture-window.ts for what the
257
+ -- document column is (the jq filter document, NOT the raw body) and why that is the safety
258
+ -- property rather than a redaction step. Mutable + self-pruning, like event_dedupe: rows are
259
+ -- swept on write and a whole window is cleared on re-arm. Never UPDATEd.
260
+ -- (No backticks in this block: it is inside a template literal and one would close it.)
261
+ CREATE TABLE IF NOT EXISTS webhook_capture (
262
+ org_id TEXT NOT NULL,
263
+ source TEXT NOT NULL, -- the hook HANDLE a routine subscribes to (= the declared id)
264
+ seq INTEGER NOT NULL, -- 1-based ordinal within the current window; the number a human says
265
+ captured_at TEXT NOT NULL, -- ISO-8601 receive time (OUR clock; prune key)
266
+ document TEXT NOT NULL, -- serialized EventFilterDocument (opaque to the store)
267
+ PRIMARY KEY (org_id, source, seq)
268
+ );
269
+ CREATE TABLE IF NOT EXISTS unified_wake_target (
270
+ org_id TEXT NOT NULL,
271
+ wake_id TEXT NOT NULL, -- host-minted per-wake id (rides the wake envelope)
272
+ target_json TEXT NOT NULL, -- serialized UnifiedWakeOrigin (opaque to the store)
273
+ created_at TEXT NOT NULL, -- ISO-8601 (lexicographic = chronological; TTL prune key)
274
+ window_token TEXT, -- OPE-161: the BARE window token dispatched to; NULL = legacy row (never answerable via the pending arm)
275
+ answered_at TEXT, -- OPE-161: ISO-8601 when a reply answered this wake; NULL = still pending
276
+ answered_turn_id TEXT, -- OPE-161: the turn that answered it (the same-turn re-accept key)
277
+ inbound INTEGER, -- OPE-767: 1 = this wake carries a real message from the room; NULL/0 = a wake the deployment minted for itself
278
+ audited_at TEXT, -- OPE-836: ISO-8601 when the turn-end wake-accounting audit considered this wake; NULL = not yet audited. Read ONLY by listUnauditedUnifiedWakes.
279
+ PRIMARY KEY (org_id, wake_id)
280
+ );
281
+ CREATE TABLE IF NOT EXISTS thread_ownership (
282
+ org_id TEXT NOT NULL,
283
+ channel_key TEXT NOT NULL, -- the container (unifiedThreadRef.channelKey)
284
+ thread_key TEXT NOT NULL, -- the thread within it (unifiedThreadRef.threadKey)
285
+ task_token TEXT NOT NULL, -- the owning task window token (embeds its generation)
286
+ created_at TEXT NOT NULL, -- ISO-8601 (lexicographic = chronological; TTL prune key)
287
+ PRIMARY KEY (org_id, channel_key, thread_key)
288
+ );
289
+ CREATE TABLE IF NOT EXISTS thread_seat_state (
290
+ org_id TEXT NOT NULL,
291
+ channel_key TEXT NOT NULL, -- the container (unifiedThreadRef.channelKey)
292
+ thread_key TEXT NOT NULL, -- the thread within it (unifiedThreadRef.threadKey)
293
+ seat_token TEXT NOT NULL, -- the thread seat's own window token
294
+ parent_key TEXT NOT NULL, -- the PARENT seat's channel_session registry key
295
+ state TEXT NOT NULL, -- 'open' | 'completed'
296
+ origin_json TEXT NOT NULL, -- the thread's own wake origin (UnifiedWakeOrigin JSON)
297
+ report TEXT, -- the seat's closing report, in its own words
298
+ opened_at TEXT NOT NULL, -- ISO-8601 of the spawn
299
+ updated_at TEXT NOT NULL, -- ISO-8601 (lexicographic = chronological; TTL prune key)
300
+ PRIMARY KEY (org_id, channel_key, thread_key)
301
+ );
302
+ CREATE TABLE IF NOT EXISTS turn_anchor (
303
+ org_id TEXT NOT NULL,
304
+ window_key TEXT NOT NULL, -- the continuation token / window this turn belongs to
305
+ anchor_key TEXT, -- "<platform>:<channelId>:<messageId>" where the surface knows it
306
+ channel_key TEXT, -- "<platform>:<channelId>" — the slash-command arm (NOT unique)
307
+ session_id TEXT NOT NULL, -- → attachSession(session_id)
308
+ turn_id TEXT NOT NULL, -- → cancel({turnId})
309
+ surface_key TEXT NOT NULL,
310
+ created_at TEXT NOT NULL, -- ISO-8601 (lexicographic = chronological; TTL prune key)
311
+ PRIMARY KEY (org_id, window_key)
312
+ );
313
+ -- An org-scoped, TTL-pruned, OPAQUE key-value scratch table. The NAME is historical (see the
314
+ -- store interface's note): minted for the deleted roll-own delegation regime, now shared by the
315
+ -- native-subagent taint markers, the question bridge and the task-wake join, each under its own
316
+ -- key prefix.
317
+ CREATE TABLE IF NOT EXISTS task_result (
318
+ org_id TEXT NOT NULL,
319
+ task_id TEXT NOT NULL, -- the consumer's own namespaced key
320
+ result_json TEXT NOT NULL, -- opaque to the store; each consumer owns its shape
321
+ created_at TEXT NOT NULL, -- ISO-8601 (lexicographic = chronological; TTL prune key)
322
+ PRIMARY KEY (org_id, task_id)
323
+ );
324
+ CREATE TABLE IF NOT EXISTS slack_attachment (
325
+ org_id TEXT NOT NULL,
326
+ file_id TEXT NOT NULL, -- Slack file id (the model-named ref; trusted-provenance key)
327
+ url_private TEXT NOT NULL, -- event-supplied url_private (opaque; never a model string)
328
+ mime_type TEXT, -- IANA media type from the event, when known
329
+ name TEXT, -- original filename, when known (extension fallback for the read path)
330
+ team_id TEXT, -- Slack team id, when known
331
+ created_at TEXT NOT NULL, -- ISO-8601 (lexicographic = chronological; TTL prune key)
332
+ PRIMARY KEY (org_id, file_id)
333
+ );
334
+ -- stored_credential (task #113): ciphertext store behind the "db" credential broker. NEVER
335
+ -- plaintext — ciphertext is an AES-256-GCM envelope, opaque here. Mutable (re-store replaces).
336
+ CREATE TABLE IF NOT EXISTS stored_credential (
337
+ org_id TEXT NOT NULL,
338
+ ref TEXT NOT NULL, -- unique lookup key, e.g. "db:notion-<domain>-key"
339
+ ciphertext TEXT NOT NULL, -- AES-256-GCM envelope (iv‖tag‖ct, base64); NEVER logged
340
+ connector TEXT, -- label only (audit/admin views), never the value
341
+ domain TEXT, -- label only
342
+ created_by TEXT NOT NULL, -- storing principal (the intake requester)
343
+ created_at TEXT NOT NULL, -- ISO-8601
344
+ PRIMARY KEY (org_id, ref)
345
+ );
346
+ -- credential_intake (task #113): the single-use, TTL'd binding a "Set API key" button carries.
347
+ -- Mutable; the ONE unused→used transition is CAS-guarded (WHERE used_at IS NULL). NEVER holds
348
+ -- the secret value — only where it goes (ref), who may store it (requested_by), and labels.
349
+ CREATE TABLE IF NOT EXISTS credential_intake (
350
+ org_id TEXT NOT NULL,
351
+ id TEXT NOT NULL, -- opaque intake id (embedded in the button action_id)
352
+ ref TEXT NOT NULL, -- the stored_credential ref the value is written under
353
+ connector TEXT NOT NULL, -- label shown in the modal
354
+ domain TEXT, -- label shown in the modal
355
+ requested_by TEXT NOT NULL, -- the ONLY principal permitted to open + submit
356
+ channel_id TEXT NOT NULL, -- where the button lives (wrong-clicker notice + confirm)
357
+ thread_ts TEXT,
358
+ created_at TEXT NOT NULL, -- ISO-8601
359
+ expires_at TEXT NOT NULL, -- ISO-8601 TTL bound (~15 min)
360
+ used_at TEXT, -- ISO-8601 when consumed; NULL = still open (single-use)
361
+ PRIMARY KEY (org_id, id)
362
+ );
363
+ -- webhook_capture_window (OPE-211, re-homed by OPE-224): the ONLY mutable state a DECLARED
364
+ -- webhook has -- when its capture window closes and who opened it. Keyed by (org_id, hook_id):
365
+ -- a hook id is unique within an org's config, unlike the deleted chat-created class's ids which
366
+ -- were globally-unique URL segments and therefore keyed on the bare id. Nothing here is secret
367
+ -- and nothing here is authority -- the hook's identity, posture and read grant are re-read from
368
+ -- the config registry at arm and at delivery time. See the postgres twin.
369
+ CREATE TABLE IF NOT EXISTS webhook_capture_window (
370
+ org_id TEXT NOT NULL,
371
+ hook_id TEXT NOT NULL, -- the DECLARED hook's id (= webhook_capture.source)
372
+ capture_until TEXT NOT NULL, -- ISO-8601, already clamped by the arming path
373
+ armed_by TEXT NOT NULL,
374
+ armed_at TEXT NOT NULL,
375
+ PRIMARY KEY (org_id, hook_id)
376
+ );
377
+ -- github_installation (scm/installations.ts): owner → installation id, learned from the App's own
378
+ -- signature-verified "installation" webhook so a new org installing the App self-registers instead
379
+ -- of needing an OE_GITHUB_INSTALLATIONS env edit + redeploy. NOT a secret (an installation id is a
380
+ -- public routing number; the App private key stays in env). The env map is composed OVER these
381
+ -- rows — env stays authoritative, this only augments.
382
+ CREATE TABLE IF NOT EXISTS github_installation (
383
+ org_id TEXT NOT NULL,
384
+ owner TEXT NOT NULL, -- installation.account.login (the SCM map's key)
385
+ installation_id TEXT NOT NULL, -- installation.id, stringified
386
+ account_type TEXT, -- "Organization" | "User" (diagnostics)
387
+ repository_selection TEXT, -- "all" | "selected" (refreshed by installation_repositories)
388
+ updated_at TEXT NOT NULL, -- ISO-8601 of the delivery that last wrote this row
389
+ PRIMARY KEY (org_id, owner)
390
+ );
391
+ -- pr_session_approval (OPE-53): the "Approve for session" grant on a pr.open card. Keyed by the
392
+ -- bare session/window token (embeds the generation ⇒ the memo dies with the session). Scoped to
393
+ -- kind="pr.open" by the callers. NEVER holds PR content — only who granted the skip + when.
394
+ CREATE TABLE IF NOT EXISTS pr_session_approval (
395
+ org_id TEXT NOT NULL,
396
+ session_id TEXT NOT NULL, -- the bare session/window token of the granting turn
397
+ kind TEXT NOT NULL, -- always "pr.open" (the only session-skippable kind)
398
+ granted_by TEXT NOT NULL, -- the member who clicked "Approve for session"
399
+ created_at TEXT NOT NULL, -- ISO-8601
400
+ expires_at TEXT NOT NULL, -- ISO-8601 GC bound (prune-on-write); death is via session_id
401
+ PRIMARY KEY (org_id, session_id, kind)
402
+ );
403
+ CREATE TABLE IF NOT EXISTS pending_actions (
404
+ org_id TEXT NOT NULL,
405
+ id TEXT NOT NULL,
406
+ kind TEXT NOT NULL, -- e.g. "spend.set" (agent/approvals/actions.ts registry key)
407
+ args_json TEXT NOT NULL, -- FROZEN mutation args, JSON
408
+ scope_key TEXT NOT NULL, -- the scope the mutation targets
409
+ domain TEXT, -- memory domain resolved at propose time (NULL if none)
410
+ requested_by TEXT NOT NULL, -- proposing session's verified principal id
411
+ channel_id TEXT NOT NULL, -- where the card is posted
412
+ thread_ts TEXT,
413
+ message_ts TEXT, -- the card's ts, set after post
414
+ posted_to TEXT, -- proposing surfaceKey frozen at mint (task #105); NULL = no sweep feedback
415
+ status TEXT NOT NULL, -- pending|approved|rejected|expired
416
+ created_at TEXT NOT NULL,
417
+ expires_at TEXT NOT NULL,
418
+ decided_by TEXT,
419
+ decided_at TEXT,
420
+ PRIMARY KEY (org_id, id)
421
+ );
422
+ CREATE INDEX IF NOT EXISTS pending_actions_org_status ON pending_actions (org_id, status);
423
+ CREATE TABLE IF NOT EXISTS domain_skill (
424
+ org_id TEXT NOT NULL,
425
+ domain TEXT NOT NULL,
426
+ name TEXT NOT NULL, -- bare (no repo-style namespace)
427
+ content TEXT NOT NULL, -- model-facing markdown, verbatim
428
+ updated_by TEXT, -- authoring principalId, when known
429
+ updated_at TEXT NOT NULL, -- ISO-8601
430
+ PRIMARY KEY (org_id, domain, name)
431
+ );
432
+ -- APPEND-ONLY content history for domain_skill (OPE-237). Written by putDomainSkill on
433
+ -- every write, never updated, never deleted, never pruned — see DomainSkillRevisionRow in
434
+ -- store.ts for why a domain skill's history is an audit artefact, and for the retention
435
+ -- position. Append-only here is BY CONTRACT only: sqlite has no RLS, so unlike Postgres
436
+ -- (SELECT+INSERT policies under FORCE) nothing at the engine stops a rewrite. That is the
437
+ -- same caveat audit_entry carries on this deprecated backend, stated rather than implied.
438
+ CREATE TABLE IF NOT EXISTS domain_skill_revisions (
439
+ seq INTEGER PRIMARY KEY AUTOINCREMENT,
440
+ org_id TEXT NOT NULL,
441
+ domain TEXT NOT NULL,
442
+ name TEXT NOT NULL,
443
+ content TEXT NOT NULL, -- the exact body written to domain_skill
444
+ authored_by TEXT, -- authoring principalId, when known
445
+ armed_by TEXT, -- the approver whose click armed it, when known
446
+ approval_id TEXT, -- pending_actions.id of the card that armed it
447
+ recorded_at TEXT NOT NULL -- ISO-8601 (= the live row's updated_at)
448
+ );
449
+ CREATE INDEX IF NOT EXISTS domain_skill_revisions_org_domain_name ON domain_skill_revisions (org_id, domain, name, seq);
450
+ CREATE TABLE IF NOT EXISTS domain_model (
451
+ org_id TEXT NOT NULL,
452
+ domain TEXT NOT NULL,
453
+ model_id TEXT, -- NULL = no modelId component (reasoning-only pick)
454
+ reasoning TEXT, -- NULL = no reasoning component (modelId-only pick)
455
+ set_by TEXT,
456
+ updated_at TEXT NOT NULL, -- ISO-8601
457
+ PRIMARY KEY (org_id, domain)
458
+ );
459
+ CREATE TABLE IF NOT EXISTS usage_events (
460
+ seq INTEGER PRIMARY KEY AUTOINCREMENT,
461
+ org_id TEXT NOT NULL,
462
+ surface_key TEXT NOT NULL,
463
+ session_id TEXT NOT NULL,
464
+ principal_id TEXT,
465
+ ts TEXT NOT NULL, -- ISO-8601
466
+ kind TEXT, -- "dm" | "channel" | "routine" | "sandbox" | ...
467
+ routine_id TEXT, -- OPE-145: set iff kind = "routine"
468
+ input_tokens INTEGER NOT NULL DEFAULT 0,
469
+ output_tokens INTEGER NOT NULL DEFAULT 0,
470
+ cache_read_tokens INTEGER NOT NULL DEFAULT 0,
471
+ cache_write_tokens INTEGER NOT NULL DEFAULT 0,
472
+ model TEXT,
473
+ detail TEXT, -- JSON
474
+ -- OPE-1611 (mirrored in the ALTER list below): the cache/reasoning ATTRIBUTION pair. Both
475
+ -- NULLABLE on purpose — NULL is "the source reported nothing", a different fact from a
476
+ -- reported zero, and keeping the two apart is the whole point of the dimension.
477
+ -- OPE-1862 (mirrored in the ALTER list below): the conversation this event happened in —
478
+ -- 'dm' | 'mpim' | 'channel'; NULL = unstamped. The kind column above cannot answer this: a routine,
479
+ -- supervisor or subagent turn wins that tag before the DM test runs, so a routine fired in a
480
+ -- DM is stamped kind 'routine'. Reports mask an unstamped row rather than guess.
481
+ surface_mode TEXT,
482
+ cache_tokens_reported INTEGER, -- 1 = the call reported a cache split; 0 = it did not; NULL = never asked
483
+ reasoning_tokens INTEGER, -- NULL = unreported; a number (0 included) = reported
484
+ -- OPE-369 (mirrored in the ALTER list below, which is what an existing DB takes)
485
+ usd_micros_measured INTEGER, -- the gateway's billed figure for THIS call; NULL = nothing measured it
486
+ cost_source TEXT, -- 'measured' | 'derived'; NULL on pre-migration/non-model rows
487
+ delegation_depth INTEGER, -- 0 = root turn, 1 = direct child, 2 = two-or-more hops (a BAND — see store.ts)
488
+ root_session_id TEXT -- top of this call's delegation chain (its own session id on a root turn)
489
+ );
490
+ CREATE INDEX IF NOT EXISTS usage_events_org_session ON usage_events (org_id, session_id);
491
+ CREATE INDEX IF NOT EXISTS usage_events_org_surface_ts ON usage_events (org_id, surface_key, ts);
492
+ -- identity link-sets (P1): the three tables behind DB-backed cross-surface identity. See the
493
+ -- LinkSetRow section in store.ts for what they are, and the postgres twin for the RLS half.
494
+ -- Read-write (a person severs an account, an admin suspends a set); the immutable HISTORY is
495
+ -- audit_entry, which identity/link-store.ts appends on every mutation. The handle column is
496
+ -- DISPLAY ONLY -- no index, no uniqueness, no lookup -- because a name/handle join is exactly the
497
+ -- attacker-controllable merge the fail-closed-on-merge doctrine forbids.
498
+ CREATE TABLE IF NOT EXISTS identity_link_sets (
499
+ org_id TEXT NOT NULL,
500
+ id TEXT NOT NULL, -- opaque, host-minted; the ONLY join key for a set
501
+ handle TEXT NOT NULL, -- DISPLAY ONLY: admin lists + audit rows
502
+ status TEXT NOT NULL, -- active | suspended | revoked ("revoked" is terminal)
503
+ created_at TEXT NOT NULL,
504
+ updated_at TEXT NOT NULL,
505
+ PRIMARY KEY (org_id, id)
506
+ );
507
+ -- PRIMARY KEY (org_id, platform, tenant, native_id) IS the "an account is exactly one person"
508
+ -- invariant -- assertPrincipalsValid's rule, moved from config load to write time. tenant joined
509
+ -- the key in OPE-309 phase 2: on a tenant-scoped platform a person id is issued PER WORKSPACE, so
510
+ -- the 3-column key made two workspaces' members one row -- i.e. one person. See the postgres twin
511
+ -- and identity/link-tenant.ts. SQLite cannot ALTER a PRIMARY KEY, so an existing table crosses over
512
+ -- by the rename-and-copy rebuild either side of this exec (needsLinkedIdTenantRebuild).
513
+ CREATE TABLE IF NOT EXISTS identity_linked_ids (
514
+ org_id TEXT NOT NULL,
515
+ platform TEXT NOT NULL,
516
+ tenant TEXT NOT NULL DEFAULT '', -- OPE-309: '' = vendor-global platform, or not yet backfilled
517
+ native_id TEXT NOT NULL,
518
+ link_set_id TEXT NOT NULL,
519
+ status TEXT NOT NULL, -- suggested | confirmed | revoked ("revoked" terminal)
520
+ established_by TEXT NOT NULL, -- "challenge:<id>" | "config-import" | "directory-sync:<p>"
521
+ evidence TEXT, -- structured evidence record as JSON; opaque here
522
+ created_at TEXT NOT NULL,
523
+ updated_at TEXT NOT NULL,
524
+ PRIMARY KEY (org_id, platform, tenant, native_id)
525
+ );
526
+ CREATE INDEX IF NOT EXISTS identity_linked_ids_org_set ON identity_linked_ids (org_id, link_set_id);
527
+ -- The proof-of-control nonce ledger. nonce_hash is a sha-256 -- the RAW code is NEVER stored,
528
+ -- so a copy of this file yields no usable codes. Single-use is the pending-only claim CAS.
529
+ CREATE TABLE IF NOT EXISTS identity_link_challenges (
530
+ org_id TEXT NOT NULL,
531
+ id TEXT NOT NULL,
532
+ nonce_hash TEXT NOT NULL, -- sha-256 hex of the uppercased code; NEVER the code
533
+ initiating_platform TEXT NOT NULL,
534
+ initiating_tenant TEXT NOT NULL DEFAULT '', -- OPE-309; '' off a tenant-scoped platform
535
+ initiating_native_id TEXT NOT NULL,
536
+ initiating_surface_key TEXT NOT NULL, -- the DM the ratification must come back to
537
+ claimed_platform TEXT, -- stamped from the WAKE's own captured author
538
+ claimed_tenant TEXT, -- ...in the same CAS, so a claimed row names a whole account
539
+ claimed_native_id TEXT,
540
+ claimed_at TEXT,
541
+ transport TEXT NOT NULL DEFAULT 'code', -- OPE-617; code | directory
542
+ target_platform TEXT, -- the directory transport's NAMED target ...
543
+ target_tenant TEXT, -- ...matched inside the consent CAS, so a consent
544
+ target_native_id TEXT, -- ...from any other account matches no row
545
+ back_nonce_hash TEXT, -- sha-256 of code-2; its PRESENCE forces the code-back
546
+ status TEXT NOT NULL, -- pending | claimed | ratified | denied | expired
547
+ created_at TEXT NOT NULL,
548
+ expires_at TEXT NOT NULL,
549
+ decided_at TEXT,
550
+ PRIMARY KEY (org_id, id)
551
+ );
552
+ CREATE INDEX IF NOT EXISTS identity_link_challenges_org_nonce ON identity_link_challenges (org_id, nonce_hash);
553
+ -- credential_grant_ask (OPE-1060): one person's REQUEST for another person's credential, pending
554
+ -- the owner's answer in their own DM. The purpose is MODEL-AUTHORED and is stored as data -- every
555
+ -- reader renders it escaped and quoted. Single-answer is the pending-only approve CAS.
556
+ CREATE TABLE IF NOT EXISTS credential_grant_ask (
557
+ org_id TEXT NOT NULL,
558
+ id TEXT NOT NULL,
559
+ requester_principal_id TEXT NOT NULL,
560
+ owner_principal_id TEXT NOT NULL,
561
+ owner_slug TEXT NOT NULL, -- the eventual tool name's owner segment, PINNED here
562
+ owner_platform TEXT NOT NULL, -- where the owner's card is delivered
563
+ owner_native_id TEXT NOT NULL, -- the bare platform id the DM arm addresses
564
+ connector TEXT NOT NULL,
565
+ verb TEXT NOT NULL, -- the vendor tool SLUGIFIED, as a name segment; a label, never the wire name
566
+ resource TEXT NOT NULL, -- the host-composed DISPLAY LABEL, holding model-authored text and the frozen VALUES
567
+ mcp_tool TEXT, -- OPE-1136: the vendor MCP tool, in the vendor's exact bytes
568
+ frozen_args TEXT, -- OPE-1136: canonical JSON; '{}' is "nothing frozen", NULL is "no borrow"
569
+ tool_name TEXT, -- OPE-1136: the full mounted name, PINNED here with the ordinal
570
+ scope_key TEXT NOT NULL, -- the CHAT this would serve (the session id)
571
+ domain_scope_key TEXT, -- OPE-1950: the room's domain-shaped seat key; a STANDING grant binds here instead
572
+ purpose TEXT NOT NULL, -- model-authored; untrusted content
573
+ requester_target TEXT, -- JSON ReplyTarget: where the owner's answer is reported back
574
+ card_surface_id TEXT, -- where the owner's card landed -- the lapse sweep rewrites it
575
+ card_message_id TEXT,
576
+ requested_mode TEXT NOT NULL, -- once | session | standing
577
+ status TEXT NOT NULL, -- pending | approved | declined | expired
578
+ created_at TEXT NOT NULL,
579
+ expires_at TEXT NOT NULL, -- the ASK's own short TTL, NOT the grant's
580
+ decided_at TEXT,
581
+ grant_id TEXT, -- stamped by the approve CAS
582
+ PRIMARY KEY (org_id, id)
583
+ );
584
+ CREATE INDEX IF NOT EXISTS credential_grant_ask_org_scope ON credential_grant_ask (org_id, scope_key);
585
+ -- credential_grant (OPE-1060): the owner-approved grant a chat spends. The tier is decided ONCE at
586
+ -- mint -- from the verb definition on the registry path, from classifyConnectorOpTier on the
587
+ -- OPE-1136 borrow path -- and is never re-derived from the mounted tool name (a grant__… name
588
+ -- carries a person's handle where a classifier looks for a verb).
589
+ -- Rows are NEVER deleted: the mount projects every row for a scope and the broker refuses on
590
+ -- state, so a removed row would make a tool vanish mid-plan instead of refusing.
591
+ -- 🔴 NO UNIQUE INDEX ON (org_id, scope_key, tool_name), and the reason is stated once here
592
+ -- (OPE-1136). Uniqueness inside one chat is held by the ORDINAL: nextGrantBorrowToolName reads
593
+ -- every row in the scope, dead ones included, and picks the lowest free ordinal. The only hole
594
+ -- that leaves is two asks composing at the same instant, and the mount-side dedupe closes that
595
+ -- one. A unique index would ALSO refuse a write, and it would start doing so before any writer
596
+ -- of tool_name exists to be tested against it -- so the constraint waits for the transport
597
+ -- slice, where a real writer can be proven against it.
598
+ CREATE TABLE IF NOT EXISTS credential_grant (
599
+ org_id TEXT NOT NULL,
600
+ id TEXT NOT NULL,
601
+ ask_id TEXT NOT NULL,
602
+ requester_principal_id TEXT NOT NULL,
603
+ owner_principal_id TEXT NOT NULL,
604
+ owner_slug TEXT NOT NULL, -- the mounted name's owner segment, PINNED at mint
605
+ connector TEXT NOT NULL,
606
+ verb TEXT NOT NULL,
607
+ resource TEXT NOT NULL,
608
+ mcp_tool TEXT, -- OPE-1136: the vendor MCP tool, in the vendor's exact bytes
609
+ frozen_args TEXT, -- OPE-1136: canonical JSON; '{}' is "nothing frozen", NULL is "no borrow"
610
+ tool_name TEXT, -- OPE-1136: the full mounted name, copied from the ask
611
+ input_schema TEXT, -- OPE-1136: the post-bake schema snapshot, taken at approve
612
+ scope_key TEXT NOT NULL,
613
+ mode TEXT NOT NULL, -- once | session | standing
614
+ tier TEXT NOT NULL, -- read | write | destructive, pinned at mint
615
+ status TEXT NOT NULL, -- active | used | revoked | expired
616
+ purpose TEXT NOT NULL, -- model-authored; untrusted content
617
+ created_at TEXT NOT NULL,
618
+ expires_at TEXT NOT NULL,
619
+ used_at TEXT,
620
+ revoked_at TEXT,
621
+ refund_turn TEXT, -- OPE-1264: the turn key the refund count below belongs to
622
+ refund_turn_seq INTEGER, -- OPE-1281: that key's eve turn ordinal; only a LATER one rolls the count
623
+ refund_count INTEGER NOT NULL DEFAULT 0, -- OPE-1264: refunds already claimed on that turn
624
+ PRIMARY KEY (org_id, id)
625
+ );
626
+ CREATE INDEX IF NOT EXISTS credential_grant_org_scope ON credential_grant (org_id, scope_key);
627
+ -- notice_claim: LIFETIME at-most-once claims (store.ts claimNotice), four key families. NO TTL
628
+ -- and NO DELETE at all, on purpose: the one thing it records is "this already happened", and
629
+ -- dropping that would make an announcement periodic and a recorded reaction repeatable. Every
630
+ -- family is bounded by the thing it records (one room, one grant, one reaction), never by the
631
+ -- number of ships. Two families are traffic-derived; store.ts's own section states what bounds
632
+ -- each. The fifth family, OPE-1751's runtime-rotation claim, was the one entry that grew per
633
+ -- ship per standing seat, and OPE-1821 retired it with the sweep it needed.
634
+ CREATE TABLE IF NOT EXISTS notice_claim (
635
+ org_id TEXT NOT NULL,
636
+ key TEXT NOT NULL,
637
+ claimed_at TEXT NOT NULL, -- ISO-8601
638
+ PRIMARY KEY (org_id, key)
639
+ );
640
+ -- proactive_address (OPE-887): where this deployment may reach somebody with no live turn.
641
+ -- UPSERTED, never appended — one row per (platform, kind, ref_key), re-stamped by every inbound
642
+ -- activity, so a moved serviceUrl region corrects itself. The address column is a provider-shaped
643
+ -- JSON bag core never reads inside. No TTL: see store.ts's PROACTIVE ADDRESSES section.
644
+ CREATE TABLE IF NOT EXISTS proactive_address (
645
+ org_id TEXT NOT NULL,
646
+ platform TEXT NOT NULL,
647
+ kind TEXT NOT NULL, -- the provider's own record species
648
+ ref_key TEXT NOT NULL, -- the provider's own key inside (platform, kind)
649
+ tenant TEXT NOT NULL, -- "" when the platform has no tenant
650
+ address TEXT NOT NULL, -- provider-shaped JSON
651
+ updated_at TEXT NOT NULL, -- ISO-8601
652
+ PRIMARY KEY (org_id, platform, kind, ref_key)
653
+ );
654
+ -- model_call_capture (OPE-846): the soak lane's byte-exact model-call recorder. MUTABLE and
655
+ -- deliberately so — retention here is an explicit delete-by-session, not a TTL (store.ts's
656
+ -- MODEL-CALL CAPTURE section carries the whole posture). Written only while soak.capture is
657
+ -- armed; a deployment that never arms it never grows a row. body_gzip_b64 is gzip(body)
658
+ -- base64'd, TRANSCRIPT-GRADE: it holds the composed prompt verbatim. Never logged.
659
+ CREATE TABLE IF NOT EXISTS model_call_capture (
660
+ seq INTEGER PRIMARY KEY AUTOINCREMENT,
661
+ org_id TEXT NOT NULL,
662
+ surface_key TEXT NOT NULL, -- spend grain (domainKeyOf), joins to usage_events
663
+ session_id TEXT NOT NULL, -- eve's durable session id (wrun_…)
664
+ turn_id TEXT NOT NULL, -- eve turn id; '' when none was resolvable
665
+ step_index INTEGER NOT NULL, -- 0-based, within the turn
666
+ ts TEXT NOT NULL, -- ISO-8601
667
+ model TEXT NOT NULL, -- the id the router resolved for THIS call
668
+ provider TEXT NOT NULL,
669
+ schema_version INTEGER NOT NULL, -- serialised-shape version (replay validates on read)
670
+ sha256 TEXT NOT NULL, -- sha256 of the UNCOMPRESSED body
671
+ body_bytes INTEGER NOT NULL, -- uncompressed length
672
+ body_gzip_b64 TEXT NOT NULL, -- '' when truncated
673
+ truncated INTEGER NOT NULL DEFAULT 0
674
+ );
675
+ CREATE INDEX IF NOT EXISTS model_call_capture_org_session ON model_call_capture (org_id, session_id, seq);
676
+ -- memory_proposal (OPE-957): the dream cycle's proposal review queue, moved off the audit log
677
+ -- (store.ts's MEMORY PROPOSALS section carries the whole posture). MUTABLE, like
678
+ -- model_call_capture — a store holding member text needs a real erasure path.
679
+ CREATE TABLE IF NOT EXISTS memory_proposal (
680
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
681
+ org_id TEXT NOT NULL,
682
+ kind TEXT NOT NULL,
683
+ scope TEXT NOT NULL,
684
+ summary TEXT NOT NULL,
685
+ before_text TEXT,
686
+ after_text TEXT,
687
+ detail_json TEXT,
688
+ principal_id TEXT NOT NULL,
689
+ created_at TEXT NOT NULL
690
+ );
691
+ CREATE INDEX IF NOT EXISTS memory_proposal_org ON memory_proposal (org_id, id);
692
+ -- dm_audience (OPE-1064 tier P2): who this deployment may START a direct message with, and
693
+ -- whether they have stopped it. Two nullable timestamps and no content — store.ts's DM AUDIENCE
694
+ -- section carries the whole posture, including why the key is the grant's own ARN-like address.
695
+ CREATE TABLE IF NOT EXISTS dm_audience (
696
+ org_id TEXT NOT NULL,
697
+ address TEXT NOT NULL, -- the person address, e.g. slack:person/U0123ABC
698
+ first_dm_at TEXT, -- ISO-8601 of the FIRST proactive DM; NULL = never delivered
699
+ stopped_at TEXT, -- ISO-8601 the recipient stopped it; NULL = not stopped
700
+ PRIMARY KEY (org_id, address)
701
+ );
702
+ CREATE TABLE IF NOT EXISTS instance_meta (
703
+ key TEXT PRIMARY KEY,
704
+ value TEXT NOT NULL
705
+ );
706
+ `);
707
+ // OPE-309 phase 2, second half of the linked-ids rebuild: copy every row across with the sentinel
708
+ // tenant, then drop the old table. `''` is CORRECT-and-final for a vendor-global platform and means
709
+ // "nobody has named this yet" on a tenant-scoped one — identity/link-tenant-backfill.ts fills the
710
+ // latter at boot, or says loudly that it cannot. Column list written out in full rather than
711
+ // `SELECT *` so a future column added to one side can never silently shift the copy.
712
+ if (needsLinkedIdTenantRebuild) {
713
+ handle.exec(`
714
+ INSERT INTO identity_linked_ids (org_id, platform, tenant, native_id, link_set_id, status, established_by, evidence, created_at, updated_at)
715
+ SELECT org_id, platform, '', native_id, link_set_id, status, established_by, evidence, created_at, updated_at
716
+ FROM identity_linked_ids__pre_tenant;
717
+ DROP TABLE identity_linked_ids__pre_tenant;
718
+ `);
719
+ }
720
+ // Migrate older DBs in place: CREATE TABLE IF NOT EXISTS won't add columns to a table
721
+ // that already exists, so add the override-metadata columns if missing. ALTER ... ADD
722
+ // COLUMN throws "duplicate column name" once migrated — swallow that (idempotent).
723
+ for (const ddl of [
724
+ "ALTER TABLE spend_limit ADD COLUMN expires_at INTEGER",
725
+ "ALTER TABLE spend_limit ADD COLUMN reason TEXT",
726
+ "ALTER TABLE spend_limit ADD COLUMN set_by TEXT",
727
+ "ALTER TABLE spend_limit ADD COLUMN monthly_usd REAL", // item 16: USD caps
728
+ "ALTER TABLE halt ADD COLUMN set_ref TEXT",
729
+
730
+ "ALTER TABLE connector_override ADD COLUMN reason TEXT",
731
+ "ALTER TABLE connector_override ADD COLUMN set_by TEXT",
732
+
733
+ // Warm-on-wake engagement (participating watcher + silent-streak shedding): additive
734
+ // columns on a table that predates them. NOT NULL DEFAULT is honoured for existing
735
+ // rows too (SQLite backfills the default), so a pre-migration engaged thread reads as
736
+ // a NON-participating (warm) thread with a zero streak — the fail-safe reading.
737
+ "ALTER TABLE thread_engagement ADD COLUMN participating INTEGER NOT NULL DEFAULT 0",
738
+ "ALTER TABLE thread_engagement ADD COLUMN silent_streak INTEGER NOT NULL DEFAULT 0",
739
+
740
+ // Additive columns on a pre-existing table: owner_token stays NULL until a router sets one, and SQLite backfills the DEFAULT, so every pre-migration row reads kind = thread.
741
+ "ALTER TABLE thread_engagement ADD COLUMN owner_token TEXT",
742
+ "ALTER TABLE thread_engagement ADD COLUMN kind TEXT NOT NULL DEFAULT 'thread'",
743
+
744
+ // Durable STOPPED marker (task #100 follow-up — window-riding supervisor stop): additive
745
+ // on the same pre-existing table, same fail-safe pattern. NOT NULL DEFAULT 0 backfills every
746
+ // existing row to NOT-stopped, so a pre-migration engaged thread keeps waking (the safe
747
+ // reading — a stop only ever suppresses AFTER it has been written).
748
+ "ALTER TABLE thread_engagement ADD COLUMN stopped INTEGER NOT NULL DEFAULT 0",
749
+
750
+ // Durable engage-idempotency (OPE-1527): the ids of the events that PROMOTED this row.
751
+ // Nullable, and a NULL reads as "no recorded promoter", which never blocks a clear — a
752
+ // pre-migration stopped row keeps the pre-OPE-1527 behaviour and the guard only ever engages
753
+ // once a promoter id has been recorded.
754
+ "ALTER TABLE thread_engagement ADD COLUMN engaged_by TEXT",
755
+ // OPE-1562 REFRAME: the column went from ONE bare id to a FRAMED list. A row written by
756
+ // OPE-1527 holds a bare id, so frame it in place. Idempotent and self-guarding: a framed value
757
+ // already starts with the separator, and no platform event id does, so a second run matches
758
+ // nothing. Safe on an existing row — it rewrites the encoding, never the id, so the guard the
759
+ // row already carried survives the migration unchanged.
760
+ // 🔴 AN OPTIMISATION, NOT A PRECONDITION — `markEngaged` normalises a bare value inside its own
761
+ // statement, because the Postgres twin of this list does not run on every deployment.
762
+ "UPDATE thread_engagement SET engaged_by = char(10) || engaged_by || char(10) WHERE engaged_by IS NOT NULL AND engaged_by <> '' AND substr(engaged_by, 1, 1) <> char(10)",
763
+
764
+ // Cumulative-token rotation + H7c (§2, eve #551): additive, all nullable.
765
+ // input_tokens_total stays NULL on pre-migration rows ⇒ shouldRotate fails safe and rotates
766
+ // once (self-heals — the new row starts at 0). first_wake_at stays NULL.
767
+ "ALTER TABLE channel_session ADD COLUMN input_tokens_total INTEGER",
768
+ "ALTER TABLE channel_session ADD COLUMN first_wake_at TEXT",
769
+ // A NULL last_input_tokens SKIPS the context-size rung rather than rotating: every freshly-minted generation is NULL too, and rotating on it would retire each generation before its first turn.
770
+ // handoff_note is deliberately not dropped — nothing reads it, a fresh install never grows it, and a destructive DROP on a live table buys nothing.
771
+ "ALTER TABLE channel_session ADD COLUMN last_input_tokens INTEGER",
772
+ // OPE-820 operator mark. NULL on every pre-migration row, which reads as "unmarked" — the
773
+ // rung is skipped, so the migration changes no seat's rotation behaviour on its own.
774
+ "ALTER TABLE channel_session ADD COLUMN rotate_marked_at TEXT",
775
+
776
+ // OPE-1821 runtime-rotation comparison. Additive, both nullable. NULL reads as "never stamped",
777
+ // which stampChannelSessionRuntime ADOPTS rather than rotating: a pre-migration seat keeps its
778
+ // generation on the deploy that runs this migration and rotates on the next CODE change. The
779
+ // fail-safe direction here is NOT to rotate — rotating on absence would retire every standing
780
+ // seat's generation at migration time and again on every seat's first wake after a fresh mint.
781
+ "ALTER TABLE channel_session ADD COLUMN served_code_fingerprint TEXT",
782
+ "ALTER TABLE channel_session ADD COLUMN served_domain_fingerprint TEXT",
783
+
784
+ // Answerable-wake lifecycle (OPE-161): additive, all three nullable. Pre-migration rows (6h-TTL ephemera) keep NULL window_token ⇒ they
785
+ // never qualify for the PENDING arm of the reply fence (fail-closed — an un-window-stamped row
786
+ // can't prove it belongs to the answering session), and NULL answered_at ⇒ they read as
787
+ // unanswered, which is the safe direction (worst case a duplicate reply, never a lost answer).
788
+ "ALTER TABLE unified_wake_target ADD COLUMN window_token TEXT",
789
+ "ALTER TABLE unified_wake_target ADD COLUMN answered_at TEXT",
790
+ "ALTER TABLE unified_wake_target ADD COLUMN answered_turn_id TEXT",
791
+ // OPE-767: additive, nullable. A pre-migration row reads as NOT inbound, so it never appears in
792
+ // `listPendingUnifiedWakes` and can never make a reply look stale — a missed refusal, never a
793
+ // false one, which is the direction the whole freshness gate fails in.
794
+ "ALTER TABLE unified_wake_target ADD COLUMN inbound INTEGER",
795
+ // OPE-836: additive, nullable — the turn-end wake-accounting HORIZON. A pre-migration row reads
796
+ // NULL ⇒ "not yet audited", so the first turn after the migration considers it once and stamps
797
+ // it. Only `listUnauditedUnifiedWakes` filters on this column, so adding it cannot change the
798
+ // reply-freshness gate or the answerable-reply fence — both read `listPendingUnifiedWakes`.
799
+ "ALTER TABLE unified_wake_target ADD COLUMN audited_at TEXT",
800
+
801
+ // Frozen proposing-surface identity (task #105 — sweep-expiry decision feedback): additive,
802
+ // nullable. Pre-migration rows stay NULL ⇒ the TTL sweep expires them WITHOUT notice/wake
803
+ // feedback (the fail-safe reading — feedback only ever fires on a mint that froze its target).
804
+ "ALTER TABLE pending_actions ADD COLUMN posted_to TEXT",
805
+
806
+ // Cross-process single-flight claim (OPE-91): additive, both nullable, on the stored_credential
807
+ // table. A row's ciphertext is an OPAQUE AES envelope, so the CAS can't live inside it — the
808
+ // claim gets its OWN columns (a random, non-secret claim id + an ISO-8601 lease stamp). Pre-
809
+ // migration / never-claimed rows read NULL ⇒ the row is FREE (claimable), the fail-safe reading.
810
+ "ALTER TABLE stored_credential ADD COLUMN claim_id TEXT",
811
+ "ALTER TABLE stored_credential ADD COLUMN claimed_at TEXT",
812
+
813
+ // SQLite's RENAME COLUMN has no guard clause, so it rides the same try/catch swallow as the ADD COLUMNs above: it throws "no such column" once already renamed.
814
+ // A fresh CREATE TABLE never has a provider column, so this only fires on a pre-existing DB.
815
+ "ALTER TABLE stored_credential RENAME COLUMN provider TO connector",
816
+ "ALTER TABLE credential_intake RENAME COLUMN provider TO connector",
817
+
818
+ // Audit hash chain (OPE-52, audit-wedge WS-6c): additive, nullable. The chain STARTS at
819
+ // the first row appended after this migration — pre-migration rows keep prev_sha NULL, so
820
+ // the boundary reads as a genesis (the fail-safe, backfill-free reading: a later null-prev
821
+ // row sitting AFTER non-null rows is itself a detectable break, findChainBreak flags it).
822
+ "ALTER TABLE audit_entry ADD COLUMN prev_sha TEXT",
823
+
824
+ // OPE-1866: the conversation mode the anti-doxxing mask reads on the AUDIT dataset, the last
825
+ // table that could not classify its own surfaces. Additive and nullable, exactly as the
826
+ // spend/usage pair above, and NOTHING IS BACKFILLED for the same reason: the mode was knowable
827
+ // only from the turn's binding, which no stored row carries. A pre-migration row therefore
828
+ // reads NULL and `query_analytics` masks it as `(unclassified)` — fail closed, because the
829
+ // alternative is publishing a surface id the reader cannot classify. It is OUTSIDE the hash
830
+ // prefix too (agent/audit/chain.ts), so adding the column breaks no existing chain link.
831
+ "ALTER TABLE audit_entry ADD COLUMN surface_mode TEXT",
832
+
833
+ // Per-routine cost attribution (OPE-145): additive, nullable. Pre-migration `kind = "routine"`
834
+ // rows keep routine_id NULL — they are honestly "a routine ran, we can't say which", which is
835
+ // exactly what they were. Nothing is backfilled: the marker that would name the routine only
836
+ // ever existed in the fired session's auth, never on the stored row.
837
+ "ALTER TABLE usage_events ADD COLUMN routine_id TEXT",
838
+
839
+ // Each of these records something knowable only AT THE MOMENT OF THE CALL, so a pre-migration row honestly reads NULL and nothing is backfilled.
840
+ // None of them touches the primary key, so these are ordinary ADD COLUMNs and the rows are kept.
841
+ "ALTER TABLE usage_events ADD COLUMN usd_micros_measured INTEGER",
842
+ "ALTER TABLE usage_events ADD COLUMN cost_source TEXT",
843
+ "ALTER TABLE usage_events ADD COLUMN delegation_depth INTEGER",
844
+ "ALTER TABLE usage_events ADD COLUMN root_session_id TEXT",
845
+
846
+ // Cache/reasoning ATTRIBUTION (OPE-1611): additive, and the two usage_events columns are
847
+ // NULLABLE for the same reason the four above are — each records what the call's own source
848
+ // reported at the moment of the call, so a pre-migration row honestly reads NULL rather than
849
+ // being handed a zero it never earned. spend_ledger takes a NOT NULL DEFAULT instead: it is a
850
+ // monthly SUM, and a SUM has no way to say "unreported" anyway.
851
+ "ALTER TABLE usage_events ADD COLUMN cache_tokens_reported INTEGER",
852
+ "ALTER TABLE usage_events ADD COLUMN reasoning_tokens INTEGER",
853
+ "ALTER TABLE spend_ledger ADD COLUMN reasoning_tokens INTEGER NOT NULL DEFAULT 0",
854
+
855
+ // OPE-1862: the conversation mode the anti-doxxing mask reads. Additive on both tables and
856
+ // NOT in either primary key, so existing rows are kept. Nothing is backfilled and nothing may
857
+ // be: the mode was knowable only from the turn's binding, which no stored row carries. An
858
+ // unstamped row therefore reads '' / NULL, and every report MASKS it — fail closed, because
859
+ // the alternative is publishing a surface id the reader cannot classify.
860
+ "ALTER TABLE usage_events ADD COLUMN surface_mode TEXT",
861
+ "ALTER TABLE spend_ledger ADD COLUMN surface_mode TEXT NOT NULL DEFAULT ''",
862
+
863
+ // OPE-309 phase 2: both ends of a link challenge record their tenant. Additive and ordinary —
864
+ // unlike identity_linked_ids these are not PK columns, so no rebuild is needed. Pre-migration
865
+ // rows take `''` / NULL; challenges carry a short TTL (link-challenge.ts), so in practice every
866
+ // one of them has expired before this line ever runs, and an expired challenge writes nothing.
867
+ "ALTER TABLE identity_link_challenges ADD COLUMN initiating_tenant TEXT NOT NULL DEFAULT ''",
868
+ "ALTER TABLE identity_link_challenges ADD COLUMN claimed_tenant TEXT",
869
+
870
+ // OPE-617: the transport a challenge belongs to, the directory transport's named target, and the
871
+ // code-back digest. Additive and nullable, and `transport` defaults to 'code' — which is exactly
872
+ // what every pre-migration row IS, so no backfill can be wrong. The same TTL argument as above
873
+ // applies: a challenge that outlived this migration has expired anyway.
874
+ "ALTER TABLE identity_link_challenges ADD COLUMN transport TEXT NOT NULL DEFAULT 'code'",
875
+ "ALTER TABLE identity_link_challenges ADD COLUMN target_platform TEXT",
876
+ "ALTER TABLE identity_link_challenges ADD COLUMN target_tenant TEXT",
877
+ "ALTER TABLE identity_link_challenges ADD COLUMN target_native_id TEXT",
878
+ "ALTER TABLE identity_link_challenges ADD COLUMN back_nonce_hash TEXT",
879
+
880
+ // OPE-1060 S3: where the owner's answer is reported back — a JSON ReplyTarget, pinned when the
881
+ // ask is raised. Additive and nullable. A pre-migration ask reads NULL, which is the honest
882
+ // reading: nothing recorded the requesting room, so the resolution notice is skipped rather
883
+ // than posted somewhere guessed. Asks carry a 30-minute TTL, so in practice every pre-migration
884
+ // row has already expired before this line runs.
885
+ "ALTER TABLE credential_grant_ask ADD COLUMN requester_target TEXT",
886
+
887
+ // OPE-1112: where the owner's DM card landed, so the TTL sweep can rewrite it to `expired`.
888
+ // Additive and nullable. A pre-migration ask reads NULL, which is the honest reading: nothing
889
+ // recorded the card's address, so the sweep skips the rewrite rather than editing a guessed
890
+ // message. Asks carry a 30-minute TTL, so every pre-migration row has already lapsed.
891
+ "ALTER TABLE credential_grant_ask ADD COLUMN card_surface_id TEXT",
892
+ "ALTER TABLE credential_grant_ask ADD COLUMN card_message_id TEXT",
893
+
894
+ // A pre-migration row reads NULL on all four borrow columns: it names no vendor tool, so it is read but never spendable — the broker refuses no_lent_tool and it mounts nothing.
895
+ // NULL is NOT an empty object; see credential-grant-rows.ts for why the two must never collapse.
896
+ "ALTER TABLE credential_grant_ask ADD COLUMN mcp_tool TEXT",
897
+ "ALTER TABLE credential_grant_ask ADD COLUMN frozen_args TEXT",
898
+ "ALTER TABLE credential_grant_ask ADD COLUMN tool_name TEXT",
899
+ "ALTER TABLE credential_grant ADD COLUMN mcp_tool TEXT",
900
+ "ALTER TABLE credential_grant ADD COLUMN frozen_args TEXT",
901
+ "ALTER TABLE credential_grant ADD COLUMN tool_name TEXT",
902
+ "ALTER TABLE credential_grant ADD COLUMN input_schema TEXT",
903
+ "ALTER TABLE credential_grant ADD COLUMN refund_turn TEXT",
904
+ "ALTER TABLE credential_grant ADD COLUMN refund_count INTEGER NOT NULL DEFAULT 0",
905
+ "ALTER TABLE credential_grant ADD COLUMN refund_turn_seq INTEGER",
906
+
907
+ // OPE-1950: the room's DOMAIN-shaped seat key, recorded beside the session one so the mint can
908
+ // bind a STANDING grant to the domain and every other mode to the session. Additive and
909
+ // nullable. A pre-migration ask reads NULL, which is the honest reading — nothing recorded the
910
+ // room's domain. Since OPE-2160 such an ask is offered no 30-day arm at all; before that, a
911
+ // standing grant minted from one kept the exact-session rule. Asks carry a 30-minute TTL, so every pre-migration row has
912
+ // already lapsed by the time this line runs.
913
+ "ALTER TABLE credential_grant_ask ADD COLUMN domain_scope_key TEXT",
914
+ ]) {
915
+ try {
916
+ handle.exec(ddl);
917
+ } catch {
918
+ /* column already present — already migrated */
919
+ }
920
+ }
921
+ db = handle;
922
+ openedPath = path;
923
+ return handle;
924
+ }
925
+
926
+ /** The runtime file path the operational sqlite store opens — the SAME resolution the
927
+ * migrator uses to find the source DB (OE_SQLITE_PATH, else OE_MEMORY_DIR/open-everywhere.sqlite3).
928
+ * Exported so migrate-operational.ts reads the exact file the runtime writes, not a guess. */
929
+ export function sqliteOperationalDbPath(): string {
930
+ return dbPath().path;
931
+ }
932
+
933
+ /** Test seam: the file the cached handle is actually OPEN at, or `null` when nothing is open.
934
+ * {@link sqliteOperationalDbPath} answers what the env RESOLVES to right now, which is a different
935
+ * question and the one OPE-1933's silent switch turned on — a test that cannot tell them apart
936
+ * cannot prove the handle stayed put. */
937
+ export function _openedOperationalDbPathForTest(): string | null {
938
+ return openedPath;
939
+ }
940
+
941
+ /** WHERE THE ROWS ACTUALLY ARE — the store's `root`, and the provenance field `auditRoot()` puts on
942
+ * every audit view. It must name the OPEN handle's file, not the env's current resolution: since
943
+ * OPE-1933 `getDb()` deliberately keeps its handle when the env read returns `undefined`, so inside
944
+ * the very scope that guard exists for, the env resolves to a cwd-derived path while the rows come
945
+ * from the pinned one. Reporting the env's answer there would state a location the rows are not in.
946
+ * Falls back to the resolution only when nothing is open yet, which is what a caller asking before
947
+ * the first read wants. */
948
+ function operationalRoot(): string {
949
+ return openedPath ?? dbPath().path;
950
+ }
951
+
952
+ /** Every operational table this store actually creates (read from sqlite_master on the live
953
+ * handle) — the runtime-truth counterpart to OPERATIONAL_TABLES that migrate-operational-test.ts
954
+ * asserts against, so a new CREATE TABLE here can't drift from the migrator's canonical list.
955
+ * Excludes sqlite internal tables AND the memory tables (memory_file/memory_tier) — those share
956
+ * the file but belong to the memory provider, not the operational store, so a :memory: DB opened
957
+ * through this store alone (memory provider untouched) never creates them. */
958
+ export function sqliteOperationalTableNames(): string[] {
959
+ const rows = getDb()
960
+ .prepare("SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%' AND name NOT IN ('memory_file', 'memory_tier') ORDER BY name")
961
+ .all() as { name: string }[];
962
+ return rows.map((r) => r.name);
963
+ }
964
+
965
+ /** Test seam: drop the cached handle so the next call reopens (e.g. new path). */
966
+ export function _resetOperationalDbForTest(): void {
967
+ if (db) db.close();
968
+ db = null;
969
+ openedPath = null;
970
+ }
971
+
972
+ // Same rationale as UsageEventRow below: a `type` alias (not `interface`) so the cast off
973
+ // `.all()`'s indexed rows compiles cleanly.
974
+ type ModelCallCaptureDbRow = {
975
+ seq: number;
976
+ surface_key: string;
977
+ session_id: string;
978
+ turn_id: string;
979
+ step_index: number;
980
+ ts: string;
981
+ model: string;
982
+ provider: string;
983
+ schema_version: number;
984
+ sha256: string;
985
+ body_bytes: number;
986
+ body_gzip_b64: string;
987
+ truncated: number;
988
+ };
989
+
990
+ function modelCallCaptureFromRow(org: string, r: ModelCallCaptureDbRow): ModelCallCaptureRow {
991
+ return {
992
+ seq: Number(r.seq),
993
+ org,
994
+ surfaceKey: r.surface_key,
995
+ sessionId: r.session_id,
996
+ turnId: r.turn_id,
997
+ stepIndex: Number(r.step_index),
998
+ ts: r.ts,
999
+ model: r.model,
1000
+ provider: r.provider,
1001
+ schemaVersion: Number(r.schema_version),
1002
+ sha256: r.sha256,
1003
+ bodyBytes: Number(r.body_bytes),
1004
+ bodyGzipB64: r.body_gzip_b64,
1005
+ truncated: Number(r.truncated) === 1,
1006
+ };
1007
+ }
1008
+
1009
+ // Same rationale as UsageEventRow below: a `type` alias (not `interface`) so the cast off
1010
+ // `.all()`'s indexed rows compiles cleanly.
1011
+ type SpendLedgerDbRow = {
1012
+ org_id: string;
1013
+ surface_key: string;
1014
+ principal_id: string;
1015
+ routine_id: string;
1016
+ model: string;
1017
+ period: string;
1018
+ surface_mode: string | null;
1019
+ input_tokens: number;
1020
+ output_tokens: number;
1021
+ cache_read_tokens: number;
1022
+ cache_write_tokens: number;
1023
+ reasoning_tokens: number;
1024
+ usd_micros: number;
1025
+ usd_micros_measured: number;
1026
+ cost_source: string;
1027
+ calls: number;
1028
+ };
1029
+
1030
+ function spendRowFrom(r: SpendLedgerDbRow): SpendLedgerRow {
1031
+ return {
1032
+ org: r.org_id,
1033
+ surfaceKey: r.surface_key,
1034
+ principalId: r.principal_id,
1035
+ routineId: r.routine_id,
1036
+ model: r.model,
1037
+ period: r.period,
1038
+ costSource: r.cost_source === "measured" ? "measured" : "derived",
1039
+ // `?? ""` covers the window between the ADD COLUMN and a write: a row read through an older
1040
+ // prepared statement, or any NULL an operator's own migration left, reads as UNSTAMPED.
1041
+ surfaceMode: r.surface_mode ?? "",
1042
+ inputTokens: r.input_tokens,
1043
+ outputTokens: r.output_tokens,
1044
+ cacheReadTokens: r.cache_read_tokens,
1045
+ cacheWriteTokens: r.cache_write_tokens,
1046
+ reasoningTokens: r.reasoning_tokens,
1047
+ usdMicros: r.usd_micros,
1048
+ usdMicrosMeasured: r.usd_micros_measured,
1049
+ calls: r.calls,
1050
+ };
1051
+ }
1052
+
1053
+ // A type ALIAS, never an interface: .all() returns an indexed Record<string, SQLOutputValue>[], and casting that to a same-shaped interface trips TS2352 while the identical type alias casts cleanly.
1054
+ type UsageEventRow = {
1055
+ surface_key: string;
1056
+ session_id: string;
1057
+ principal_id: string | null;
1058
+ ts: string;
1059
+ kind: string | null;
1060
+ routine_id: string | null;
1061
+ input_tokens: number;
1062
+ output_tokens: number;
1063
+ cache_read_tokens: number;
1064
+ cache_write_tokens: number;
1065
+ model: string | null;
1066
+ detail: string | null;
1067
+ usd_micros_measured: number | null;
1068
+ cost_source: string | null;
1069
+ delegation_depth: number | null;
1070
+ root_session_id: string | null;
1071
+ cache_tokens_reported: number | null;
1072
+ reasoning_tokens: number | null;
1073
+ surface_mode: string | null;
1074
+ };
1075
+
1076
+ function usageEventFromRow(org: string, r: UsageEventRow): UsageEventEntry {
1077
+ return {
1078
+ org,
1079
+ surfaceKey: r.surface_key,
1080
+ sessionId: r.session_id,
1081
+ ...(r.principal_id ? { principalId: r.principal_id } : {}),
1082
+ ts: r.ts,
1083
+ ...(r.kind ? { kind: r.kind } : {}),
1084
+ ...(r.routine_id ? { routineId: r.routine_id } : {}),
1085
+ inputTokens: r.input_tokens,
1086
+ outputTokens: r.output_tokens,
1087
+ cacheReadTokens: r.cache_read_tokens,
1088
+ cacheWriteTokens: r.cache_write_tokens,
1089
+ ...(r.model ? { model: r.model } : {}),
1090
+ // OPE-369. `usd_micros_measured` is read back on `!= null` rather than on truthiness: a
1091
+ // genuinely-measured $0.000000 call (a cached/free response the gateway still bills as zero)
1092
+ // is EVIDENCE that the gateway answered, and dropping it would silently demote the row to
1093
+ // "nothing measured it". `delegation_depth` reads the same way — 0 IS the root turn.
1094
+ ...(r.usd_micros_measured != null ? { usdMicrosMeasured: Number(r.usd_micros_measured) } : {}),
1095
+ ...(r.cost_source ? { costSource: r.cost_source === "measured" ? ("measured" as const) : ("derived" as const) } : {}),
1096
+ ...(r.delegation_depth != null ? { delegationDepth: Number(r.delegation_depth) } : {}),
1097
+ ...(r.root_session_id ? { rootSessionId: r.root_session_id } : {}),
1098
+ // OPE-1611, read back on `!= null` for the SAME reason: `0` here means "the source reported a
1099
+ // zero", which is real evidence, while NULL means it reported nothing at all. The flag stores
1100
+ // 1/0 (node:sqlite has no boolean) and comes back as a real boolean.
1101
+ ...(r.cache_tokens_reported != null ? { cacheTokensReported: r.cache_tokens_reported === 1 } : {}),
1102
+ ...(r.reasoning_tokens != null ? { reasoningTokens: Number(r.reasoning_tokens) } : {}),
1103
+ // OPE-1862: only the three declared spellings become a mode. Every other value — '', NULL, a
1104
+ // spelling a foreign writer invented — stays ABSENT, which the report mask treats as
1105
+ // unclassified and hides.
1106
+ ...((): { surfaceMode?: SurfaceMode } => {
1107
+ const mode = asSurfaceMode(r.surface_mode);
1108
+ return mode ? { surfaceMode: mode } : {};
1109
+ })(),
1110
+ ...(r.detail ? { detail: JSON.parse(r.detail) as Record<string, unknown> } : {}),
1111
+ };
1112
+ }
1113
+
1114
+ // Same rationale as UsageEventRow above: a `type` alias (not `interface`) so the cast off
1115
+ // `.get()`/`.all()`'s indexed result shape typechecks cleanly.
1116
+ type PendingActionSqlRow = {
1117
+ id: string;
1118
+ kind: string;
1119
+ args_json: string;
1120
+ scope_key: string;
1121
+ domain: string | null;
1122
+ requested_by: string;
1123
+ channel_id: string;
1124
+ thread_ts: string | null;
1125
+ message_ts: string | null;
1126
+ posted_to: string | null;
1127
+ status: string;
1128
+ created_at: string;
1129
+ expires_at: string;
1130
+ decided_by: string | null;
1131
+ decided_at: string | null;
1132
+ };
1133
+
1134
+ function pendingActionFromRow(org: string, r: PendingActionSqlRow): PendingActionRow {
1135
+ return {
1136
+ id: r.id,
1137
+ org,
1138
+ kind: r.kind,
1139
+ argsJson: r.args_json,
1140
+ scopeKey: r.scope_key,
1141
+ domain: r.domain,
1142
+ requestedBy: r.requested_by,
1143
+ channelId: r.channel_id,
1144
+ threadTs: r.thread_ts,
1145
+ messageTs: r.message_ts,
1146
+ postedTo: r.posted_to,
1147
+ status: r.status as PendingStatus,
1148
+ createdAt: r.created_at,
1149
+ expiresAt: r.expires_at,
1150
+ decidedBy: r.decided_by,
1151
+ decidedAt: r.decided_at,
1152
+ };
1153
+ }
1154
+
1155
+ /** `?, ?, …` for an `IN (…)` over a CLOSED status vocabulary — never caller text (sqlite has no
1156
+ * array-parameter form, so a status CAS list has to be spread into placeholders). */
1157
+ function placeholders(n: number): string {
1158
+ return new Array(n).fill("?").join(", ");
1159
+ }
1160
+
1161
+ const TURN_ANCHOR_SELECT = "SELECT window_key, anchor_key, channel_key, session_id, turn_id, surface_key, created_at FROM turn_anchor";
1162
+
1163
+ type TurnAnchorSqlRow = {
1164
+ window_key: string;
1165
+ anchor_key: string | null;
1166
+ channel_key: string | null;
1167
+ session_id: string;
1168
+ turn_id: string;
1169
+ surface_key: string;
1170
+ created_at: string;
1171
+ };
1172
+
1173
+ /** Project a raw turn_anchor row (or an absent one) into {@link TurnAnchorRow}. NULL optional
1174
+ * columns are OMITTED rather than carried as null, matching getUnifiedWakeRecord's shape. */
1175
+ function readTurnAnchorRow(raw: unknown): TurnAnchorRow | null {
1176
+ const r = raw as TurnAnchorSqlRow | undefined;
1177
+ if (!r) return null;
1178
+ return {
1179
+ windowKey: r.window_key,
1180
+ ...(r.anchor_key !== null ? { anchorKey: r.anchor_key } : {}),
1181
+ ...(r.channel_key !== null ? { channelKey: r.channel_key } : {}),
1182
+ sessionId: r.session_id,
1183
+ turnId: r.turn_id,
1184
+ surfaceKey: r.surface_key,
1185
+ createdAt: r.created_at,
1186
+ };
1187
+ }
1188
+
1189
+ type LinkSetSqliteRow = { id: string; handle: string; status: string; created_at: string; updated_at: string };
1190
+
1191
+ function linkSetFromSqliteRow(org: string, r: LinkSetSqliteRow): LinkSetRow {
1192
+ return { org, id: r.id, handle: r.handle, status: r.status as LinkSetStatus, createdAt: r.created_at, updatedAt: r.updated_at };
1193
+ }
1194
+
1195
+ const LINKED_ID_SQLITE_SELECT = "SELECT platform, tenant, native_id, link_set_id, status, established_by, evidence, created_at, updated_at FROM identity_linked_ids";
1196
+
1197
+ type LinkedIdSqliteRow = {
1198
+ platform: string;
1199
+ tenant: string;
1200
+ native_id: string;
1201
+ link_set_id: string;
1202
+ status: string;
1203
+ established_by: string;
1204
+ evidence: string | null;
1205
+ created_at: string;
1206
+ updated_at: string;
1207
+ };
1208
+
1209
+ function linkedIdFromSqliteRow(org: string, r: LinkedIdSqliteRow): LinkedIdRow {
1210
+ return {
1211
+ org,
1212
+ linkSetId: r.link_set_id,
1213
+ platform: r.platform,
1214
+ tenant: r.tenant,
1215
+ nativeId: r.native_id,
1216
+ status: r.status as LinkedIdStatus,
1217
+ establishedBy: r.established_by,
1218
+ ...(r.evidence === null ? {} : { evidenceJson: r.evidence }),
1219
+ createdAt: r.created_at,
1220
+ updatedAt: r.updated_at,
1221
+ };
1222
+ }
1223
+
1224
+ const LINK_CHALLENGE_SQLITE_SELECT =
1225
+ `SELECT id, nonce_hash, initiating_platform, initiating_tenant, initiating_native_id, initiating_surface_key,
1226
+ claimed_platform, claimed_tenant, claimed_native_id, claimed_at,
1227
+ transport, target_platform, target_tenant, target_native_id, back_nonce_hash,
1228
+ status, created_at, expires_at, decided_at
1229
+ FROM identity_link_challenges`;
1230
+
1231
+ type LinkChallengeSqliteRow = {
1232
+ id: string;
1233
+ nonce_hash: string;
1234
+ initiating_platform: string;
1235
+ initiating_tenant: string;
1236
+ initiating_native_id: string;
1237
+ initiating_surface_key: string;
1238
+ claimed_platform: string | null;
1239
+ claimed_tenant: string | null;
1240
+ claimed_native_id: string | null;
1241
+ claimed_at: string | null;
1242
+ transport: string | null;
1243
+ target_platform: string | null;
1244
+ target_tenant: string | null;
1245
+ target_native_id: string | null;
1246
+ back_nonce_hash: string | null;
1247
+ status: string;
1248
+ created_at: string;
1249
+ expires_at: string;
1250
+ decided_at: string | null;
1251
+ };
1252
+
1253
+ function linkChallengeFromSqliteRow(org: string, r: LinkChallengeSqliteRow): LinkChallengeRow {
1254
+ return {
1255
+ org,
1256
+ id: r.id,
1257
+ nonceHash: r.nonce_hash,
1258
+ initiatingPlatform: r.initiating_platform,
1259
+ initiatingTenant: r.initiating_tenant,
1260
+ initiatingNativeId: r.initiating_native_id,
1261
+ initiatingSurfaceKey: r.initiating_surface_key,
1262
+ ...(r.claimed_platform === null ? {} : { claimedPlatform: r.claimed_platform }),
1263
+ ...(r.claimed_tenant === null ? {} : { claimedTenant: r.claimed_tenant }),
1264
+ ...(r.claimed_native_id === null ? {} : { claimedNativeId: r.claimed_native_id }),
1265
+ ...(r.claimed_at === null ? {} : { claimedAt: r.claimed_at }),
1266
+ // A pre-OPE-617 row (or one read through a driver that returns no such column) is a CODE-transport
1267
+ // row — that is what every row was before the column existed, so the fallback states a fact
1268
+ // rather than guessing one.
1269
+ transport: r.transport ?? "code",
1270
+ ...(r.target_platform === null || r.target_platform === undefined ? {} : { targetPlatform: r.target_platform }),
1271
+ ...(r.target_tenant === null || r.target_tenant === undefined ? {} : { targetTenant: r.target_tenant }),
1272
+ ...(r.target_native_id === null || r.target_native_id === undefined ? {} : { targetNativeId: r.target_native_id }),
1273
+ ...(r.back_nonce_hash === null || r.back_nonce_hash === undefined ? {} : { backNonceHash: r.back_nonce_hash }),
1274
+ status: r.status as LinkChallengeStatus,
1275
+ createdAt: r.created_at,
1276
+ expiresAt: r.expires_at,
1277
+ ...(r.decided_at === null ? {} : { decidedAt: r.decided_at }),
1278
+ };
1279
+ }
1280
+
1281
+ /** Refuse a half-written borrow at the INSERT, where the caller can still be fixed — see
1282
+ * {@link grantBorrowColumnsProblem} for what "half" means and why it is silent otherwise. */
1283
+ function refuseHalfBorrow(table: string, row: Parameters<typeof grantBorrowColumnsProblem>[0]): void {
1284
+ const problem = grantBorrowColumnsProblem(row);
1285
+ if (problem !== undefined) throw new Error(`${table}: ${problem}`);
1286
+ }
1287
+
1288
+ const GRANT_ASK_SQLITE_SELECT =
1289
+ `SELECT id, requester_principal_id, owner_principal_id, owner_slug, owner_platform, owner_native_id, connector, verb, resource,
1290
+ mcp_tool, frozen_args, tool_name,
1291
+ 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
1292
+ FROM credential_grant_ask`;
1293
+
1294
+ type GrantAskSqliteRow = {
1295
+ id: string;
1296
+ requester_principal_id: string;
1297
+ owner_principal_id: string;
1298
+ owner_slug: string;
1299
+ owner_platform: string;
1300
+ owner_native_id: string;
1301
+ connector: string;
1302
+ verb: string;
1303
+ resource: string;
1304
+ mcp_tool: string | null;
1305
+ frozen_args: string | null;
1306
+ tool_name: string | null;
1307
+ scope_key: string;
1308
+ domain_scope_key: string | null;
1309
+ purpose: string;
1310
+ requester_target: string | null;
1311
+ card_surface_id: string | null;
1312
+ card_message_id: string | null;
1313
+ requested_mode: string;
1314
+ status: string;
1315
+ created_at: string;
1316
+ expires_at: string;
1317
+ decided_at: string | null;
1318
+ grant_id: string | null;
1319
+ };
1320
+
1321
+ function grantAskFromSqliteRow(r: GrantAskSqliteRow): CredentialGrantAskRow {
1322
+ const frozenArgs = grantJsonFromColumn(r.frozen_args, "credential_grant_ask.frozen_args");
1323
+ return {
1324
+ id: r.id,
1325
+ requesterPrincipalId: r.requester_principal_id,
1326
+ ownerPrincipalId: r.owner_principal_id,
1327
+ ownerSlug: r.owner_slug,
1328
+ ownerPlatform: r.owner_platform,
1329
+ ownerNativeId: r.owner_native_id,
1330
+ connector: r.connector,
1331
+ verb: r.verb,
1332
+ resource: r.resource,
1333
+ ...(r.mcp_tool === null || r.mcp_tool === undefined ? {} : { mcpTool: r.mcp_tool }),
1334
+ ...(frozenArgs === undefined ? {} : { frozenArgs }),
1335
+ ...(r.tool_name === null || r.tool_name === undefined ? {} : { toolName: r.tool_name }),
1336
+ scopeKey: r.scope_key,
1337
+ ...(r.domain_scope_key === null || r.domain_scope_key === undefined ? {} : { domainScopeKey: r.domain_scope_key }),
1338
+ purpose: r.purpose,
1339
+ ...(r.requester_target === null ? {} : { requesterTarget: r.requester_target }),
1340
+ ...(r.card_surface_id === null ? {} : { cardSurfaceId: r.card_surface_id }),
1341
+ ...(r.card_message_id === null ? {} : { cardMessageId: r.card_message_id }),
1342
+ requestedMode: r.requested_mode as CredentialGrantMode,
1343
+ status: r.status as CredentialGrantAskState,
1344
+ createdAt: r.created_at,
1345
+ expiresAt: r.expires_at,
1346
+ ...(r.decided_at === null ? {} : { decidedAt: r.decided_at }),
1347
+ ...(r.grant_id === null ? {} : { grantId: r.grant_id }),
1348
+ };
1349
+ }
1350
+
1351
+ const GRANT_SQLITE_SELECT =
1352
+ `SELECT id, ask_id, requester_principal_id, owner_principal_id, owner_slug, connector, verb, resource,
1353
+ mcp_tool, frozen_args, tool_name, input_schema,
1354
+ scope_key, mode, tier, status, purpose, created_at, expires_at, used_at, revoked_at
1355
+ FROM credential_grant`;
1356
+
1357
+ type GrantSqliteRow = {
1358
+ id: string;
1359
+ ask_id: string;
1360
+ requester_principal_id: string;
1361
+ owner_principal_id: string;
1362
+ owner_slug: string;
1363
+ connector: string;
1364
+ verb: string;
1365
+ resource: string;
1366
+ mcp_tool: string | null;
1367
+ frozen_args: string | null;
1368
+ tool_name: string | null;
1369
+ input_schema: string | null;
1370
+ scope_key: string;
1371
+ mode: string;
1372
+ tier: string;
1373
+ status: string;
1374
+ purpose: string;
1375
+ created_at: string;
1376
+ expires_at: string;
1377
+ used_at: string | null;
1378
+ revoked_at: string | null;
1379
+ };
1380
+
1381
+ function grantFromSqliteRow(r: GrantSqliteRow): CredentialGrantRow {
1382
+ const frozenArgs = grantJsonFromColumn(r.frozen_args, "credential_grant.frozen_args");
1383
+ const inputSchema = grantJsonFromColumn(r.input_schema, "credential_grant.input_schema");
1384
+ return {
1385
+ id: r.id,
1386
+ askId: r.ask_id,
1387
+ requesterPrincipalId: r.requester_principal_id,
1388
+ ownerPrincipalId: r.owner_principal_id,
1389
+ ownerSlug: r.owner_slug,
1390
+ connector: r.connector,
1391
+ verb: r.verb,
1392
+ resource: r.resource,
1393
+ ...(r.mcp_tool === null || r.mcp_tool === undefined ? {} : { mcpTool: r.mcp_tool }),
1394
+ ...(frozenArgs === undefined ? {} : { frozenArgs }),
1395
+ ...(r.tool_name === null || r.tool_name === undefined ? {} : { toolName: r.tool_name }),
1396
+ ...(inputSchema === undefined ? {} : { inputSchema }),
1397
+ scopeKey: r.scope_key,
1398
+ mode: r.mode as CredentialGrantMode,
1399
+ tier: r.tier as CredentialGrantRow["tier"],
1400
+ status: r.status as CredentialGrantState,
1401
+ purpose: r.purpose,
1402
+ createdAt: r.created_at,
1403
+ expiresAt: r.expires_at,
1404
+ ...(r.used_at === null ? {} : { usedAt: r.used_at }),
1405
+ ...(r.revoked_at === null ? {} : { revokedAt: r.revoked_at }),
1406
+ };
1407
+ }
1408
+
1409
+ /** One `dm_audience` row → {@link DmAudienceRow}. A NULL timestamp is dropped rather than carried as
1410
+ * `null`, so a caller reads absence as absence and never has to test two spellings of "not set". */
1411
+ function dmAudienceRowFrom(r: { address: string; first_dm_at: string | null; stopped_at: string | null }): DmAudienceRow {
1412
+ return {
1413
+ address: r.address,
1414
+ ...(r.first_dm_at === null ? {} : { firstDmAt: r.first_dm_at }),
1415
+ ...(r.stopped_at === null ? {} : { stoppedAt: r.stopped_at }),
1416
+ };
1417
+ }
1418
+
1419
+ export const sqliteOperationalStore: OperationalStore = {
1420
+ id: "sqlite",
1421
+ root: operationalRoot,
1422
+
1423
+ async recordSpend(org, write: SpendLedgerWrite) {
1424
+ getDb()
1425
+ .prepare(
1426
+ `INSERT INTO spend_ledger
1427
+ (org_id, surface_key, principal_id, routine_id, model, period, cost_source, surface_mode,
1428
+ input_tokens, output_tokens, cache_read_tokens, cache_write_tokens, reasoning_tokens, usd_micros, usd_micros_measured, calls)
1429
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1)
1430
+ ON CONFLICT(org_id, surface_key, principal_id, routine_id, model, period, cost_source) DO UPDATE SET
1431
+ -- OPE-1862: a stamped mode HEALS a row an older build (or a writer with no binding)
1432
+ -- left unstamped, and an unstamped write never erases a mode the row already holds.
1433
+ -- A surface cannot change mode, so the two spellings can only ever be '' and the truth.
1434
+ surface_mode = COALESCE(NULLIF(excluded.surface_mode, ''), spend_ledger.surface_mode),
1435
+ input_tokens = input_tokens + excluded.input_tokens,
1436
+ output_tokens = output_tokens + excluded.output_tokens,
1437
+ cache_read_tokens = cache_read_tokens + excluded.cache_read_tokens,
1438
+ cache_write_tokens = cache_write_tokens + excluded.cache_write_tokens,
1439
+ reasoning_tokens = reasoning_tokens + excluded.reasoning_tokens,
1440
+ usd_micros = usd_micros + excluded.usd_micros,
1441
+ usd_micros_measured = usd_micros_measured + excluded.usd_micros_measured,
1442
+ calls = calls + 1`,
1443
+ )
1444
+ .run(
1445
+ org,
1446
+ write.surfaceKey,
1447
+ write.principalId ?? "",
1448
+ write.routineId ?? "",
1449
+ write.model ?? "",
1450
+ write.period,
1451
+ write.costSource ?? "derived",
1452
+ write.surfaceMode ?? "",
1453
+ write.inputTokens ?? 0,
1454
+ write.outputTokens ?? 0,
1455
+ write.cacheReadTokens ?? 0,
1456
+ write.cacheWriteTokens ?? 0,
1457
+ write.reasoningTokens ?? 0,
1458
+ write.usdMicros ?? 0,
1459
+ write.usdMicrosMeasured ?? 0,
1460
+ );
1461
+ },
1462
+
1463
+ async spendTotals(org, filter: SpendLedgerFilter = {}): Promise<SpendTotals> {
1464
+ const { conjuncts, params } = spendLedgerConjuncts(filter);
1465
+ const row = getDb()
1466
+ .prepare(
1467
+ `SELECT COALESCE(SUM(input_tokens), 0) AS input_tokens,
1468
+ COALESCE(SUM(output_tokens), 0) AS output_tokens,
1469
+ COALESCE(SUM(cache_read_tokens), 0) AS cache_read_tokens,
1470
+ COALESCE(SUM(cache_write_tokens), 0) AS cache_write_tokens,
1471
+ COALESCE(SUM(reasoning_tokens), 0) AS reasoning_tokens,
1472
+ COALESCE(SUM(usd_micros), 0) AS usd_micros,
1473
+ COALESCE(SUM(usd_micros_measured), 0) AS usd_micros_measured,
1474
+ COALESCE(SUM(calls), 0) AS calls
1475
+ FROM spend_ledger WHERE ${["org_id = ?", ...conjuncts].join(" AND ")}`,
1476
+ )
1477
+ .get(org, ...params) as { input_tokens: number; output_tokens: number; cache_read_tokens: number; cache_write_tokens: number; reasoning_tokens: number; usd_micros: number; usd_micros_measured: number; calls: number };
1478
+ return {
1479
+ inputTokens: row.input_tokens,
1480
+ outputTokens: row.output_tokens,
1481
+ cacheReadTokens: row.cache_read_tokens,
1482
+ cacheWriteTokens: row.cache_write_tokens,
1483
+ reasoningTokens: row.reasoning_tokens,
1484
+ usdMicros: row.usd_micros,
1485
+ usdMicrosMeasured: row.usd_micros_measured,
1486
+ calls: row.calls,
1487
+ };
1488
+ },
1489
+
1490
+ async listSpendLedger(org?: string, filter: SpendLedgerFilter = {}) {
1491
+ // The filter goes into the QUERY, never into a `.filter()` over the result (OPE-1653): a
1492
+ // caller that renders one period must not pay to load every period the deployment ever
1493
+ // wrote. Same `spendLedgerConjuncts` assembly the SUM read uses, so the two reads — and the
1494
+ // two backends — agree on what each conjunct means.
1495
+ const { conjuncts, params } = spendLedgerConjuncts(filter);
1496
+ const where = [...(org !== undefined ? ["org_id = ?"] : []), ...conjuncts];
1497
+ const rows = getDb()
1498
+ .prepare(`SELECT * FROM spend_ledger${where.length ? ` WHERE ${where.join(" AND ")}` : ""}`)
1499
+ .all(...(org !== undefined ? [org] : []), ...params) as SpendLedgerDbRow[];
1500
+ return rows.map(spendRowFrom);
1501
+ },
1502
+
1503
+ async listRoutines(org, surfaceKey) {
1504
+ const rows = getDb()
1505
+ .prepare("SELECT data FROM routine WHERE org_id = ? AND surface_key = ?")
1506
+ .all(org, surfaceKey) as { data: string }[];
1507
+ return rows.map((r) => JSON.parse(r.data) as Routine);
1508
+ },
1509
+
1510
+ async getRoutine(org, surfaceKey, id) {
1511
+ const row = getDb()
1512
+ .prepare("SELECT data FROM routine WHERE org_id = ? AND id = ? AND surface_key = ?")
1513
+ .get(org, id, surfaceKey) as { data: string } | undefined;
1514
+ return row ? (JSON.parse(row.data) as Routine) : null;
1515
+ },
1516
+
1517
+ async addRoutine(routine) {
1518
+ getDb()
1519
+ .prepare("INSERT INTO routine (org_id, id, surface_key, data) VALUES (?, ?, ?, ?)")
1520
+ .run(routine.org, routine.id, routine.surfaceKey, JSON.stringify(routine));
1521
+ return routine;
1522
+ },
1523
+
1524
+ async updateRoutine(org, surfaceKey, id, patch, provenance) {
1525
+ const handle = getDb();
1526
+ const row = handle.prepare("SELECT data FROM routine WHERE org_id = ? AND id = ? AND surface_key = ?").get(org, id, surfaceKey) as
1527
+ | { data: string }
1528
+ | undefined;
1529
+ if (!row) return null;
1530
+ const existing = JSON.parse(row.data) as Routine;
1531
+ const updated: Routine = { ...existing, ...patch, id: existing.id, org: existing.org, surfaceKey: existing.surfaceKey };
1532
+ // REVISIONS BEFORE the destructive UPDATE (OPE-242) — same reasoning as the Postgres adapter,
1533
+ // and the same shared decision (routinePromptRevisionWrites) so the two backends cannot drift
1534
+ // on WHAT gets recorded. Only a patch that REPLACES the prompt records anything.
1535
+ if (patch.prompt !== undefined && patch.prompt !== existing.prompt) {
1536
+ const prior = handle
1537
+ .prepare("SELECT 1 FROM routine_prompt_revisions WHERE org_id = ? AND surface_key = ? AND routine_id = ? LIMIT 1")
1538
+ .get(org, surfaceKey, id);
1539
+ const writes = routinePromptRevisionWrites({
1540
+ existing,
1541
+ updated,
1542
+ ...(provenance ? { provenance } : {}),
1543
+ hasPriorRevisions: prior !== undefined,
1544
+ nowIso: new Date().toISOString(),
1545
+ });
1546
+ const insert = handle.prepare(
1547
+ `INSERT INTO routine_prompt_revisions (org_id, surface_key, routine_id, prompt, generation, authored_by, armed_by, approval_id, recorded_at)
1548
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
1549
+ );
1550
+ for (const w of writes) {
1551
+ insert.run(org, surfaceKey, id, w.prompt, w.generation, w.authoredBy ?? null, w.armedBy ?? null, w.approvalId ?? null, w.recordedAt);
1552
+ }
1553
+ }
1554
+ handle.prepare("UPDATE routine SET data = ? WHERE org_id = ? AND id = ?").run(JSON.stringify(updated), org, id);
1555
+ return updated;
1556
+ },
1557
+
1558
+ async listRoutinePromptRevisions(org, surfaceKey, routineId) {
1559
+ const rows = getDb()
1560
+ .prepare(
1561
+ `SELECT seq, routine_id, prompt, generation, authored_by, armed_by, approval_id, recorded_at
1562
+ FROM routine_prompt_revisions
1563
+ WHERE org_id = ? AND surface_key = ? AND (? IS NULL OR routine_id = ?)
1564
+ ORDER BY seq`,
1565
+ )
1566
+ .all(org, surfaceKey, routineId ?? null, routineId ?? null) as {
1567
+ seq: number;
1568
+ routine_id: string;
1569
+ prompt: string;
1570
+ generation: number | null;
1571
+ authored_by: string | null;
1572
+ armed_by: string | null;
1573
+ approval_id: string | null;
1574
+ recorded_at: string;
1575
+ }[];
1576
+ return rows.map((r) => ({
1577
+ seq: Number(r.seq),
1578
+ org,
1579
+ surfaceKey,
1580
+ routineId: r.routine_id,
1581
+ prompt: r.prompt,
1582
+ ...(r.generation === null ? {} : { generation: Number(r.generation) }),
1583
+ ...(r.authored_by ? { authoredBy: r.authored_by } : {}),
1584
+ ...(r.armed_by ? { armedBy: r.armed_by } : {}),
1585
+ ...(r.approval_id ? { approvalId: r.approval_id } : {}),
1586
+ recordedAt: r.recorded_at,
1587
+ }));
1588
+ },
1589
+
1590
+ async removeRoutine(org, surfaceKey, id) {
1591
+ const info = getDb().prepare("DELETE FROM routine WHERE org_id = ? AND id = ? AND surface_key = ?").run(org, id, surfaceKey);
1592
+ return info.changes > 0;
1593
+ },
1594
+
1595
+ async listAllRoutines() {
1596
+ const rows = getDb().prepare("SELECT data FROM routine").all() as { data: string }[];
1597
+ return rows.map((r) => JSON.parse(r.data) as Routine);
1598
+ },
1599
+
1600
+ async appendAudit(entry: AuditEntry) {
1601
+ // Hash-chain link (OPE-52): stamp prev_sha = sha256 of the org's current LAST row. The
1602
+ // read-last-then-insert is a race window for one org, so the whole body runs under the
1603
+ // per-org in-process lock (OPE-1636 moved that lock here from audit.ts, so a caller that
1604
+ // reaches the store directly is covered too). sqlite is one process by construction — a
1605
+ // local/self-host file — so this lock is the WHOLE serialisation the engine needs; there
1606
+ // is no cross-process layer to add. See chain.ts's concurrency stance.
1607
+ return withOrgAuditLock(entry.org, async () => {
1608
+ const handle = getDb();
1609
+ const last = handle
1610
+ .prepare(
1611
+ `SELECT ts, org_id, platform, workspace, surface, surface_mode, principal_id, action, detail, prev_sha
1612
+ FROM audit_entry WHERE org_id = ? ORDER BY seq DESC LIMIT 1`,
1613
+ )
1614
+ .get(entry.org) as
1615
+ | { ts: string; org_id: string; platform: string; workspace: string; surface: string | null; surface_mode: string | null; principal_id: string | null; action: string; detail: string | null; prev_sha: string | null }
1616
+ | undefined;
1617
+ // Read the predecessor's mode back through asSurfaceMode, so a stored value outside the enum
1618
+ // hashes as ABSENT here exactly as it reads as unclassified everywhere else. The predecessor's
1619
+ // sha must be recomputed from the same reading the row itself gets, or the link breaks on a
1620
+ // row nobody touched.
1621
+ const lastMode = auditSurfaceMode(last?.surface_mode);
1622
+ const prevSha = last
1623
+ ? auditRowSha(
1624
+ {
1625
+ org: last.org_id,
1626
+ ts: last.ts,
1627
+ platform: last.platform,
1628
+ workspace: last.workspace,
1629
+ ...(last.surface ? { surface: last.surface } : {}),
1630
+ ...lastMode,
1631
+ ...(last.principal_id ? { principalId: last.principal_id } : {}),
1632
+ action: last.action,
1633
+ ...(last.detail ? { detail: JSON.parse(last.detail) as Record<string, unknown> } : {}),
1634
+ },
1635
+ last.prev_sha,
1636
+ )
1637
+ : null;
1638
+ handle
1639
+ .prepare(
1640
+ `INSERT INTO audit_entry (ts, org_id, platform, workspace, surface, surface_mode, principal_id, action, detail, prev_sha)
1641
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
1642
+ )
1643
+ .run(
1644
+ entry.ts,
1645
+ entry.org,
1646
+ entry.platform,
1647
+ entry.workspace,
1648
+ entry.surface ?? null,
1649
+ entry.surfaceMode ?? null,
1650
+ entry.principalId ?? null,
1651
+ entry.action,
1652
+ entry.detail ? JSON.stringify(entry.detail) : null,
1653
+ prevSha,
1654
+ );
1655
+ });
1656
+ },
1657
+
1658
+ async readAudit(filter: AuditFilter) {
1659
+ // Refuse before the builder runs (OPE-1812) — the Postgres twin does the same, through the same
1660
+ // helper, so the two query builders cannot drift on the one predicate that partitions the log.
1661
+ const org = auditReadOrg(filter);
1662
+ const where: string[] = [];
1663
+ const params: string[] = [];
1664
+ const eq = (col: string, val: string | undefined) => {
1665
+ if (val !== undefined) {
1666
+ where.push(`${col} = ?`);
1667
+ params.push(val);
1668
+ }
1669
+ };
1670
+ eq("org_id", org);
1671
+ eq("platform", filter.platform);
1672
+ eq("workspace", filter.workspace);
1673
+ eq("surface", filter.surface);
1674
+ eq("action", filter.action);
1675
+ eq("principal_id", filter.principalId);
1676
+ if (filter.since !== undefined) {
1677
+ where.push("ts >= ?");
1678
+ params.push(filter.since);
1679
+ }
1680
+ if (filter.until !== undefined) {
1681
+ where.push("ts <= ?");
1682
+ params.push(filter.until);
1683
+ }
1684
+ const clause = where.length ? `WHERE ${where.join(" AND ")}` : "";
1685
+ const limit = filter.limit && filter.limit > 0 ? filter.limit : -1; // SQLite: -1 = no limit
1686
+ const rows = getDb()
1687
+ .prepare(
1688
+ // `seq` rides along (OPE-1933): it is already the ORDER BY tiebreak, and it is the only
1689
+ // monotonic locator a reader can anchor on when the box's wall clock steps backward.
1690
+ // `surface_mode` is the anti-doxxing mask's input (OPE-1866).
1691
+ `SELECT seq, ts, org_id, platform, workspace, surface, surface_mode, principal_id, action, detail
1692
+ FROM audit_entry ${clause} ORDER BY ts DESC, seq DESC LIMIT ?`,
1693
+ )
1694
+ .all(...params, limit) as {
1695
+ seq: number;
1696
+ ts: string;
1697
+ org_id: string;
1698
+ platform: string;
1699
+ workspace: string;
1700
+ surface: string | null;
1701
+ surface_mode: string | null;
1702
+ principal_id: string | null;
1703
+ action: string;
1704
+ detail: string | null;
1705
+ }[];
1706
+ return rows.map((r) => ({
1707
+ seq: Number(r.seq),
1708
+ ts: r.ts,
1709
+ org: r.org_id,
1710
+ platform: r.platform,
1711
+ workspace: r.workspace,
1712
+ ...(r.surface ? { surface: r.surface } : {}),
1713
+ ...auditSurfaceMode(r.surface_mode),
1714
+ ...(r.principal_id ? { principalId: r.principal_id } : {}),
1715
+ action: r.action,
1716
+ ...(r.detail ? { detail: JSON.parse(r.detail) as Record<string, unknown> } : {}),
1717
+ }));
1718
+ },
1719
+
1720
+ async listAuditOrgs() {
1721
+ const rows = getDb().prepare("SELECT DISTINCT org_id FROM audit_entry ORDER BY org_id").all() as { org_id: string }[];
1722
+ return rows.map((r) => r.org_id);
1723
+ },
1724
+
1725
+ async readAuditChain(org, opts) {
1726
+ // Rows come back OLDEST-first, which is the order the hash-chain walk needs; a tailLimit takes the last N by seq and re-orders them ascending.
1727
+ const tail = opts?.tailLimit;
1728
+ const sql =
1729
+ tail && tail > 0
1730
+ ? `SELECT * FROM (
1731
+ SELECT seq, ts, org_id, platform, workspace, surface, surface_mode, principal_id, action, detail, prev_sha
1732
+ FROM audit_entry WHERE org_id = ? ORDER BY seq DESC LIMIT ?
1733
+ ) ORDER BY seq ASC`
1734
+ : `SELECT seq, ts, org_id, platform, workspace, surface, surface_mode, principal_id, action, detail, prev_sha
1735
+ FROM audit_entry WHERE org_id = ? ORDER BY seq ASC`;
1736
+ const rows = getDb()
1737
+ .prepare(sql)
1738
+ .all(...(tail && tail > 0 ? [org, tail] : [org])) as {
1739
+ seq: number;
1740
+ ts: string;
1741
+ org_id: string;
1742
+ platform: string;
1743
+ workspace: string;
1744
+ surface: string | null;
1745
+ surface_mode: string | null;
1746
+ principal_id: string | null;
1747
+ action: string;
1748
+ detail: string | null;
1749
+ prev_sha: string | null;
1750
+ }[];
1751
+ return rows.map(
1752
+ (r): AuditChainRow => ({
1753
+ seq: Number(r.seq),
1754
+ ts: r.ts,
1755
+ org: r.org_id,
1756
+ platform: r.platform,
1757
+ workspace: r.workspace,
1758
+ ...(r.surface ? { surface: r.surface } : {}),
1759
+ ...auditSurfaceMode(r.surface_mode),
1760
+ ...(r.principal_id ? { principalId: r.principal_id } : {}),
1761
+ action: r.action,
1762
+ ...(r.detail ? { detail: JSON.parse(r.detail) as Record<string, unknown> } : {}),
1763
+ prevSha: r.prev_sha,
1764
+ }),
1765
+ );
1766
+ },
1767
+
1768
+ async sealAuditChainEpoch(org, sealedBy) {
1769
+ // The read and the insert run under the SAME per-org lock as an append (OPE-1636): a row
1770
+ // that landed between them would sit after the era the seal claims to cover. The org's whole
1771
+ // chain is read inside that lock, so this org's appends queue behind it for the duration.
1772
+ return withOrgAuditLock(org, async () => {
1773
+ const rows = await sqliteOperationalStore.readAuditChain(org);
1774
+ const seal = auditEpochSealFor(rows);
1775
+ if (seal === null) return null;
1776
+ // The marker's seq comes from the INSERT itself (`lastInsertRowid` — `seq` is the table's
1777
+ // INTEGER PRIMARY KEY AUTOINCREMENT, i.e. the rowid). Reading the chain back for it would
1778
+ // sit outside this lock and could name a row another writer appended first.
1779
+ const written = getDb()
1780
+ .prepare(
1781
+ `INSERT INTO audit_entry (ts, org_id, platform, workspace, principal_id, action, detail, prev_sha)
1782
+ VALUES (?, ?, 'db', 'sqlite', ?, ?, ?, NULL)`,
1783
+ )
1784
+ .run(new Date().toISOString(), org, sealedBy, AUDIT_CHAIN_EPOCH_ACTION, JSON.stringify(auditEpochDetail(seal)));
1785
+ return { seal, markerSeq: Number(written.lastInsertRowid) };
1786
+ });
1787
+ },
1788
+
1789
+ async setSpendLimit(org, scopeKey, level, limit, meta, condition) {
1790
+ assertSpendLimitAmount(limit);
1791
+ // ENCODING: monthly_tokens = -1 means "no token component". The column is NOT NULL
1792
+ // in every pre-existing DB and SQLite's ALTER TABLE can't relax that, so a sentinel
1793
+ // is the only additive migration; -1 is unambiguous because assertSpendLimitAmount
1794
+ // rejects any non-positive real limit. monthly_usd (a new, nullable column) uses a
1795
+ // plain NULL. spendLimits() below decodes both back to `undefined`.
1796
+ const conflict = condition?.ifAbsent
1797
+ ? "DO NOTHING"
1798
+ : `DO UPDATE SET
1799
+ monthly_tokens = excluded.monthly_tokens,
1800
+ monthly_usd = excluded.monthly_usd,
1801
+ expires_at = excluded.expires_at,
1802
+ reason = excluded.reason,
1803
+ set_by = excluded.set_by`;
1804
+ return (
1805
+ getDb()
1806
+ .prepare(
1807
+ `INSERT INTO spend_limit (org_id, scope_key, level, monthly_tokens, monthly_usd, expires_at, reason, set_by) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
1808
+ ON CONFLICT(org_id, scope_key, level) ${conflict}`,
1809
+ )
1810
+ .run(org, scopeKey, level, limit.monthlyTokens ?? -1, limit.monthlyUsd ?? null, meta?.expiresAt ?? null, meta?.reason ?? null, meta?.setBy ?? null).changes > 0
1811
+ );
1812
+ },
1813
+
1814
+ async clearSpendLimit(org, scopeKey, level, expected) {
1815
+ const sql = expected
1816
+ ? "DELETE FROM spend_limit WHERE org_id = ? AND scope_key = ? AND level = ? AND monthly_tokens IS ? AND monthly_usd IS ? AND expires_at IS ? AND reason IS ? AND set_by IS ?"
1817
+ : "DELETE FROM spend_limit WHERE org_id = ? AND scope_key = ? AND level = ?";
1818
+ const params = expected
1819
+ ? [org, scopeKey, level, expected.monthlyTokens ?? -1, expected.monthlyUsd ?? null, expected.expiresAt ?? null, expected.reason ?? null, expected.setBy ?? null]
1820
+ : [org, scopeKey, level];
1821
+ return getDb().prepare(sql).run(...params).changes > 0;
1822
+ },
1823
+
1824
+ async spendLimits(org) {
1825
+ const rows = getDb()
1826
+ .prepare("SELECT scope_key, level, monthly_tokens, monthly_usd, expires_at, reason, set_by FROM spend_limit WHERE org_id = ?")
1827
+ .all(org) as { scope_key: string; level: string; monthly_tokens: number; monthly_usd: number | null; expires_at: number | null; reason: string | null; set_by: string | null }[];
1828
+ return rows.map((r) => ({
1829
+ org,
1830
+ scopeKey: r.scope_key,
1831
+ level: r.level as CapLevel,
1832
+ // Decode the storage encodings (see setSpendLimit): -1 tokens = no token
1833
+ // component; NULL usd = no USD component.
1834
+ ...(r.monthly_tokens >= 0 ? { monthlyTokens: r.monthly_tokens } : {}),
1835
+ ...(r.monthly_usd != null ? { monthlyUsd: r.monthly_usd } : {}),
1836
+ ...(r.expires_at != null ? { expiresAt: r.expires_at } : {}),
1837
+ ...(r.reason ? { reason: r.reason } : {}),
1838
+ ...(r.set_by ? { setBy: r.set_by } : {}),
1839
+ }));
1840
+ },
1841
+
1842
+ async setHalt(org, address, meta) {
1843
+ assertHaltAddress(address);
1844
+ const a = haltAddressColumns(address);
1845
+ // Re-halting an already-halted address restamps who/when and DROPS the previous resume stamps:
1846
+ // a cleared_at left beside an active row would read as "resumed" to anyone scanning the table.
1847
+ getDb()
1848
+ .prepare(
1849
+ `INSERT INTO halt (org_id, level, scope_key, org_wide, active, set_by, set_at, set_ref, cleared_by, cleared_at) VALUES (?, ?, ?, ?, 1, ?, ?, ?, NULL, NULL)
1850
+ ON CONFLICT(org_id, level, scope_key, org_wide) DO UPDATE SET
1851
+ active = 1,
1852
+ set_by = excluded.set_by,
1853
+ set_at = excluded.set_at,
1854
+ set_ref = excluded.set_ref,
1855
+ cleared_by = NULL,
1856
+ cleared_at = NULL`,
1857
+ )
1858
+ .run(org, a.level, a.scopeKey, a.orgWide ? 1 : 0, meta?.setBy ?? null, meta?.setAt ?? new Date().toISOString(), meta?.setRef ?? null);
1859
+ },
1860
+
1861
+ async clearHalt(org, address, meta, expected) {
1862
+ assertHaltAddress(address);
1863
+ const a = haltAddressColumns(address);
1864
+ // `AND active = 1` is what makes the boolean answer honest: a second resume on an already-clear
1865
+ // address returns false rather than restamping a clear that already happened.
1866
+ const expectedSql = expected ? " AND set_at = ? AND set_by IS ? AND set_ref IS ?" : "";
1867
+ const expectedParams = expected ? [expected.setAt, expected.setBy ?? null, expected.setRef ?? null] : [];
1868
+ return (
1869
+ getDb()
1870
+ .prepare(`UPDATE halt SET active = 0, cleared_by = ?, cleared_at = ? WHERE org_id = ? AND level = ? AND scope_key = ? AND org_wide = ? AND active = 1${expectedSql}`)
1871
+ .run(meta?.clearedBy ?? null, new Date().toISOString(), org, a.level, a.scopeKey, a.orgWide ? 1 : 0, ...expectedParams).changes > 0
1872
+ );
1873
+ },
1874
+
1875
+ async activeHalts(org) {
1876
+ const rows = getDb()
1877
+ .prepare("SELECT level, scope_key, org_wide, set_by, set_at, set_ref, cleared_by, cleared_at FROM halt WHERE org_id = ? AND active = 1")
1878
+ .all(org) as { level: string; scope_key: string; org_wide: number; set_by: string | null; set_at: string; set_ref: string | null; cleared_by: string | null; cleared_at: string | null }[];
1879
+ return rows.map((r) => ({
1880
+ org,
1881
+ address: haltAddressFromColumns(r.level, r.scope_key, r.org_wide === 1),
1882
+ active: true,
1883
+ setAt: r.set_at,
1884
+ ...(r.set_by ? { setBy: r.set_by } : {}),
1885
+ ...(r.set_ref ? { setRef: r.set_ref } : {}),
1886
+ ...(r.cleared_by ? { clearedBy: r.cleared_by } : {}),
1887
+ ...(r.cleared_at ? { clearedAt: r.cleared_at } : {}),
1888
+ }));
1889
+ },
1890
+
1891
+ async setConnectorOverride(org, scopeKey, connector, granted, meta) {
1892
+ getDb()
1893
+ .prepare(
1894
+ `INSERT INTO connector_override (org_id, scope_key, connector, granted, reason, set_by) VALUES (?, ?, ?, ?, ?, ?)
1895
+ ON CONFLICT(org_id, scope_key, connector) DO UPDATE SET
1896
+ granted = excluded.granted,
1897
+ reason = excluded.reason,
1898
+ set_by = excluded.set_by`,
1899
+ )
1900
+ .run(org, scopeKey, connector, granted ? 1 : 0, meta?.reason ?? null, meta?.setBy ?? null);
1901
+ },
1902
+
1903
+ async clearConnectorOverride(org, scopeKey, connector) {
1904
+ return getDb().prepare("DELETE FROM connector_override WHERE org_id = ? AND scope_key = ? AND connector = ?").run(org, scopeKey, connector).changes > 0;
1905
+ },
1906
+
1907
+ async connectorOverrides(org, scopeKey) {
1908
+ // Hot gate path — only the fields the connector gate needs (stays robust even if a
1909
+ // drift-view column is missing). reason/setBy are read by allConnectorOverrides.
1910
+ const rows = getDb()
1911
+ .prepare("SELECT connector, granted FROM connector_override WHERE org_id = ? AND scope_key = ?")
1912
+ .all(org, scopeKey) as { connector: string; granted: number }[];
1913
+ return rows.map((r) => ({ connector: r.connector, granted: r.granted === 1 }));
1914
+ },
1915
+
1916
+ async allConnectorOverrides(org) {
1917
+ const rows = getDb()
1918
+ .prepare("SELECT scope_key, connector, granted, reason, set_by FROM connector_override WHERE org_id = ?")
1919
+ .all(org) as { scope_key: string; connector: string; granted: number; reason: string | null; set_by: string | null }[];
1920
+ return rows.map((r) => ({ scopeKey: r.scope_key, connector: r.connector, granted: r.granted === 1, ...(r.reason ? { reason: r.reason } : {}), ...(r.set_by ? { setBy: r.set_by } : {}) }));
1921
+ },
1922
+
1923
+ async setDomainModel(org, domain, pick, setBy) {
1924
+ assertDomainModelPick(pick);
1925
+ getDb()
1926
+ .prepare(
1927
+ `INSERT INTO domain_model (org_id, domain, model_id, reasoning, set_by, updated_at) VALUES (?, ?, ?, ?, ?, ?)
1928
+ ON CONFLICT(org_id, domain) DO UPDATE SET
1929
+ model_id = excluded.model_id,
1930
+ reasoning = excluded.reasoning,
1931
+ set_by = excluded.set_by,
1932
+ updated_at = excluded.updated_at`,
1933
+ )
1934
+ .run(org, domain, pick.modelId ?? null, pick.reasoning ?? null, setBy ?? null, new Date().toISOString());
1935
+ },
1936
+
1937
+ async clearDomainModel(org, domain) {
1938
+ return getDb().prepare("DELETE FROM domain_model WHERE org_id = ? AND domain = ?").run(org, domain).changes > 0;
1939
+ },
1940
+
1941
+ async getDomainModel(org, domain) {
1942
+ const row = getDb()
1943
+ .prepare("SELECT model_id, reasoning, set_by, updated_at FROM domain_model WHERE org_id = ? AND domain = ?")
1944
+ .get(org, domain) as { model_id: string | null; reasoning: string | null; set_by: string | null; updated_at: string } | undefined;
1945
+ if (!row) return null;
1946
+ return {
1947
+ org,
1948
+ domain,
1949
+ ...(row.model_id ? { modelId: row.model_id } : {}),
1950
+ ...(row.reasoning ? { reasoning: row.reasoning as ModelReasoning } : {}),
1951
+ ...(row.set_by ? { setBy: row.set_by } : {}),
1952
+ updatedAt: row.updated_at,
1953
+ };
1954
+ },
1955
+
1956
+ async domainModels(org) {
1957
+ const rows = getDb()
1958
+ .prepare("SELECT domain, model_id, reasoning, set_by, updated_at FROM domain_model WHERE org_id = ? ORDER BY domain")
1959
+ .all(org) as { domain: string; model_id: string | null; reasoning: string | null; set_by: string | null; updated_at: string }[];
1960
+ return rows.map((r) => ({
1961
+ org,
1962
+ domain: r.domain,
1963
+ ...(r.model_id ? { modelId: r.model_id } : {}),
1964
+ ...(r.reasoning ? { reasoning: r.reasoning as ModelReasoning } : {}),
1965
+ ...(r.set_by ? { setBy: r.set_by } : {}),
1966
+ updatedAt: r.updated_at,
1967
+ }));
1968
+ },
1969
+
1970
+ async markEngaged(org, surfaceKey, threadTs, at, opts) {
1971
+ // A promotion from any id the row already records NEVER clears stopped: a platform that redelivers one event replays the invitation, and that must not lift a stand-down nobody asked to lift. The statement normalises a legacy bare id ITSELF and must — the boot migration does not run for a non-owner runtime role, and an un-normalised value fails OPEN.
1972
+ // The trim rides a SECOND statement on purpose: the stopped decision and the promoter append have to be ONE atomic statement, and the Postgres twin has no transaction seam. A crash between the two leaves the promoter list one entry over PROMOTER_LIST_MAX, where it stays — bounded, but never self-healed.
1973
+ const participating = opts?.participating ? 1 : 0;
1974
+ const ownerToken = opts?.ownerToken ?? null;
1975
+ const kind = opts?.kind ?? "thread";
1976
+ // FRAMED (`\nID\n`) on both sides of every comparison — see store.ts. `instr` of the framed id
1977
+ // against the framed list is therefore an EXACT membership test, and `replace(list, framed,
1978
+ // SEP) || <framed minus its leading SEP>` removes any existing entry and re-appends it last.
1979
+ const framed = participating === 1 && opts?.engagedBy ? framePromoterId(opts.engagedBy) : null;
1980
+ getDb()
1981
+ .prepare(
1982
+ `INSERT INTO thread_engagement (org_id, surface_key, thread_ts, engaged_at, last_turn_at, participating, silent_streak, owner_token, kind, stopped, engaged_by)
1983
+ VALUES (?, ?, ?, ?, ?, ?, 0, ?, ?, 0, ?)
1984
+ ON CONFLICT(org_id, surface_key, thread_ts) DO UPDATE SET
1985
+ last_turn_at = excluded.last_turn_at,
1986
+ participating = MAX(participating, excluded.participating),
1987
+ silent_streak = CASE WHEN excluded.participating = 1 THEN 0 ELSE silent_streak END,
1988
+ owner_token = COALESCE(excluded.owner_token, owner_token),
1989
+ stopped = CASE
1990
+ WHEN excluded.participating = 1
1991
+ AND (excluded.engaged_by IS NULL
1992
+ OR instr(CASE WHEN engaged_by IS NULL OR engaged_by = '' THEN char(10)
1993
+ WHEN substr(engaged_by, 1, 1) = char(10) THEN engaged_by
1994
+ ELSE char(10) || engaged_by || char(10) END,
1995
+ excluded.engaged_by) = 0)
1996
+ THEN 0 ELSE stopped END,
1997
+ engaged_by = CASE
1998
+ WHEN excluded.participating = 1 AND excluded.engaged_by IS NOT NULL
1999
+ THEN replace(CASE WHEN engaged_by IS NULL OR engaged_by = '' THEN char(10)
2000
+ WHEN substr(engaged_by, 1, 1) = char(10) THEN engaged_by
2001
+ ELSE char(10) || engaged_by || char(10) END,
2002
+ excluded.engaged_by, char(10)) || substr(excluded.engaged_by, 2)
2003
+ ELSE engaged_by END`,
2004
+ )
2005
+ .run(org, surfaceKey, threadTs, at, at, participating, ownerToken, kind, framed);
2006
+ if (framed === null) return;
2007
+ // THE BOUND. One promotion appends at most one entry, so dropping at most one entry per
2008
+ // promotion holds the list at PROMOTER_LIST_MAX. Entry count is (separators - 1); the drop is
2009
+ // "cut everything up to and including the SECOND separator", which is the oldest entry. Safe on
2010
+ // a legacy value because the statement above has just framed it.
2011
+ getDb()
2012
+ .prepare(
2013
+ `UPDATE thread_engagement
2014
+ SET engaged_by = substr(engaged_by, instr(substr(engaged_by, 2), char(10)) + 1)
2015
+ WHERE org_id = ? AND surface_key = ? AND thread_ts = ?
2016
+ AND engaged_by IS NOT NULL
2017
+ AND length(engaged_by) - length(replace(engaged_by, char(10), '')) - 1 > ?`,
2018
+ )
2019
+ .run(org, surfaceKey, threadTs, PROMOTER_LIST_MAX);
2020
+ },
2021
+
2022
+ async markStopped(org, surfaceKey, threadTs) {
2023
+ // Set the durable stopped marker on an EXISTING row (task #100 follow-up). No INSERT — a
2024
+ // stop only ever applies to a thread that already carries an engagement row (the caller
2025
+ // gates on that). Missing row → 0 changes → false. Idempotent (re-stop is a no-op write).
2026
+ return getDb().prepare("UPDATE thread_engagement SET stopped = 1 WHERE org_id = ? AND surface_key = ? AND thread_ts = ?").run(org, surfaceKey, threadTs).changes > 0;
2027
+ },
2028
+
2029
+ async bumpSilentStreak(org, surfaceKey, threadTs) {
2030
+ // RETURNING (SQLite ≥3.35) hands back the post-increment value in one statement; a
2031
+ // missing row matches nothing → get() is undefined → 0 (no-op, nothing to shed).
2032
+ const row = getDb()
2033
+ .prepare(
2034
+ `UPDATE thread_engagement SET silent_streak = silent_streak + 1
2035
+ WHERE org_id = ? AND surface_key = ? AND thread_ts = ? RETURNING silent_streak`,
2036
+ )
2037
+ .get(org, surfaceKey, threadTs) as { silent_streak: number } | undefined;
2038
+ return row ? row.silent_streak : 0;
2039
+ },
2040
+
2041
+ async getEngagement(org, surfaceKey, threadTs) {
2042
+ const row = getDb()
2043
+ .prepare("SELECT engaged_at, last_turn_at, participating, silent_streak, owner_token, kind, stopped, engaged_by FROM thread_engagement WHERE org_id = ? AND surface_key = ? AND thread_ts = ?")
2044
+ .get(org, surfaceKey, threadTs) as
2045
+ | { engaged_at: string; last_turn_at: string; participating: number; silent_streak: number; owner_token: string | null; kind: string | null; stopped: number; engaged_by: string | null }
2046
+ | undefined;
2047
+ return row
2048
+ ? {
2049
+ org,
2050
+ surfaceKey,
2051
+ threadTs,
2052
+ engagedAt: row.engaged_at,
2053
+ lastTurnAt: row.last_turn_at,
2054
+ participating: row.participating === 1,
2055
+ silentStreak: row.silent_streak,
2056
+ ...(row.owner_token ? { ownerToken: row.owner_token } : {}),
2057
+ kind: (row.kind as "thread" | "spawned" | null) ?? "thread",
2058
+ stopped: row.stopped === 1,
2059
+ ...promoterListField(row.engaged_by),
2060
+ }
2061
+ : null;
2062
+ },
2063
+
2064
+ async disengage(org, surfaceKey, threadTs) {
2065
+ return getDb().prepare("DELETE FROM thread_engagement WHERE org_id = ? AND surface_key = ? AND thread_ts = ?").run(org, surfaceKey, threadTs).changes > 0;
2066
+ },
2067
+
2068
+ async listEngagements(org) {
2069
+ const rows = getDb()
2070
+ .prepare("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 = ?")
2071
+ .all(org) as {
2072
+ surface_key: string;
2073
+ thread_ts: string;
2074
+ engaged_at: string;
2075
+ last_turn_at: string;
2076
+ participating: number;
2077
+ silent_streak: number;
2078
+ owner_token: string | null;
2079
+ kind: string | null;
2080
+ stopped: number;
2081
+ engaged_by: string | null;
2082
+ }[];
2083
+ return rows.map((r) => ({
2084
+ org,
2085
+ surfaceKey: r.surface_key,
2086
+ threadTs: r.thread_ts,
2087
+ engagedAt: r.engaged_at,
2088
+ lastTurnAt: r.last_turn_at,
2089
+ participating: r.participating === 1,
2090
+ silentStreak: r.silent_streak,
2091
+ ...(r.owner_token ? { ownerToken: r.owner_token } : {}),
2092
+ kind: (r.kind as "thread" | "spawned" | null) ?? "thread",
2093
+ stopped: r.stopped === 1,
2094
+ ...promoterListField(r.engaged_by),
2095
+ }));
2096
+ },
2097
+
2098
+ async getChannelSession(org, surfaceKey) {
2099
+ const row = getDb()
2100
+ .prepare("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 = ? AND surface_key = ?")
2101
+ .get(org, surfaceKey) as
2102
+ | { token: string; generation: number; created_at: string; last_wake_at: string; turn_count: number; input_tokens_total: number | null; first_wake_at: string | null; last_input_tokens: number | null; rotate_marked_at: string | null; served_code_fingerprint: string | null; served_domain_fingerprint: string | null }
2103
+ | undefined;
2104
+ return row
2105
+ ? {
2106
+ org, surfaceKey, token: row.token, generation: row.generation, createdAt: row.created_at,
2107
+ lastWakeAt: row.last_wake_at, turnCount: row.turn_count,
2108
+ inputTokensTotal: row.input_tokens_total == null ? null : Number(row.input_tokens_total),
2109
+ firstWakeAt: row.first_wake_at ?? null,
2110
+ lastInputTokens: row.last_input_tokens == null ? null : Number(row.last_input_tokens),
2111
+ rotateMarkedAt: row.rotate_marked_at ?? null,
2112
+ servedCodeFingerprint: row.served_code_fingerprint ?? null,
2113
+ servedDomainFingerprint: row.served_domain_fingerprint ?? null,
2114
+ }
2115
+ : null;
2116
+ },
2117
+
2118
+ async stampChannelSessionRuntime(org, surfaceKey, codeFingerprint, domainFingerprint) {
2119
+ // The read reports what the row HELD; the conditional UPDATE decides who ACTS on it, and only
2120
+ // the UPDATE's own `changes` is trusted for that. `IS NOT` is SQLite's null-safe comparison, so
2121
+ // a row that carries no pair at all matches the predicate.
2122
+ //
2123
+ // 🔴 WHY THIS NEEDS NO TRANSACTION. The two statements are synchronous and sit between no
2124
+ // `await`, so nothing else in this process runs between them; across processes SQLite evaluates
2125
+ // the UPDATE's WHERE under the write lock, so exactly one of two racing wakes gets changes = 1.
2126
+ // A loser whose SELECT saw the stale pair still reads changes = 0 and answers "current" — the
2127
+ // seat's generation retires ONCE. The Postgres twin gets the same guarantee from one statement.
2128
+ const handle = getDb();
2129
+ const prev = handle
2130
+ .prepare("SELECT served_code_fingerprint, served_domain_fingerprint FROM channel_session WHERE org_id = ? AND surface_key = ?")
2131
+ .get(org, surfaceKey) as { served_code_fingerprint: string | null; served_domain_fingerprint: string | null } | undefined;
2132
+ if (prev === undefined) return { outcome: "absent", previousCodeFingerprint: null, previousDomainFingerprint: null };
2133
+ const previousCodeFingerprint = prev.served_code_fingerprint ?? null;
2134
+ const previousDomainFingerprint = prev.served_domain_fingerprint ?? null;
2135
+ const info = handle
2136
+ .prepare(
2137
+ `UPDATE channel_session SET served_code_fingerprint = ?, served_domain_fingerprint = ?
2138
+ WHERE org_id = ? AND surface_key = ?
2139
+ AND (served_code_fingerprint IS NOT ? OR served_domain_fingerprint IS NOT ?)`,
2140
+ )
2141
+ .run(codeFingerprint, domainFingerprint, org, surfaceKey, codeFingerprint, domainFingerprint);
2142
+ if (Number(info.changes ?? 0) === 0) return { outcome: "current", previousCodeFingerprint, previousDomainFingerprint };
2143
+ // NULL is ADOPTED, never rotated: the row was minted by this same bundle moments ago (the
2144
+ // mint arm writes no pair) or predates the columns, and neither proves the code changed.
2145
+ const outcome: ChannelSessionRuntimeStamp["outcome"] = previousCodeFingerprint === null ? "adopted" : "rotate";
2146
+ return { outcome, previousCodeFingerprint, previousDomainFingerprint };
2147
+ },
2148
+
2149
+ async rotateChannelSession(org, surfaceKey, newToken, at) {
2150
+ const handle = getDb();
2151
+ // In a SQLite UPSERT's DO UPDATE SET an unqualified column reads the PRE-update row and excluded.x reads the proposed values, so generation = generation + 1 bumps atomically in one statement.
2152
+ // Every rotation sets rotate_marked_at = NULL, which SPENDS the operator mark; a mark that survived its own rotation would retire the seat on every wake.
2153
+ const row = handle
2154
+ .prepare(
2155
+ `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)
2156
+ VALUES (?, ?, ?, 1, ?, ?, 0, 0, NULL, NULL, NULL)
2157
+ ON CONFLICT(org_id, surface_key) DO UPDATE SET
2158
+ token = excluded.token,
2159
+ generation = generation + 1,
2160
+ created_at = excluded.created_at,
2161
+ last_wake_at = excluded.last_wake_at,
2162
+ turn_count = 0,
2163
+ input_tokens_total = 0,
2164
+ first_wake_at = NULL,
2165
+ last_input_tokens = NULL,
2166
+ rotate_marked_at = NULL
2167
+ RETURNING generation, served_code_fingerprint, served_domain_fingerprint`,
2168
+ )
2169
+ .get(org, surfaceKey, newToken, at, at) as { generation: number; served_code_fingerprint: string | null; served_domain_fingerprint: string | null };
2170
+ const generation = row.generation;
2171
+ // The fingerprint pair is NOT in the INSERT column list and NOT in the DO UPDATE SET, so a fresh
2172
+ // mint starts NULL (adopted by the next wake) and a rotation KEEPS the pair the pre-dispatch
2173
+ // stamp just wrote. Resetting it here would rotate the seat again on its very next wake.
2174
+ return {
2175
+ org, surfaceKey, token: newToken, generation, createdAt: at, lastWakeAt: at, turnCount: 0, inputTokensTotal: 0, firstWakeAt: null, lastInputTokens: null, rotateMarkedAt: null,
2176
+ servedCodeFingerprint: row.served_code_fingerprint ?? null,
2177
+ servedDomainFingerprint: row.served_domain_fingerprint ?? null,
2178
+ };
2179
+ },
2180
+
2181
+ async markChannelSessionRotation(org, surfaceKey, at) {
2182
+ // UPDATE, never an upsert: a registry key with no row has no generation to retire, and minting
2183
+ // one here would seat a channel nobody woke. COALESCE keeps the FIRST mark's stamp, so a
2184
+ // re-run of the sweep is idempotent and the stamp stays readable as "marked since when".
2185
+ const res = getDb()
2186
+ .prepare("UPDATE channel_session SET rotate_marked_at = COALESCE(rotate_marked_at, ?) WHERE org_id = ? AND surface_key = ?")
2187
+ .run(at, org, surfaceKey);
2188
+ return Number(res.changes ?? 0) > 0;
2189
+ },
2190
+
2191
+ async touchChannelSession(org, surfaceKey, at) {
2192
+ // first_wake_at set ONCE (COALESCE) — runs only after a successful wake (H7c "delivered").
2193
+ getDb()
2194
+ .prepare("UPDATE channel_session SET last_wake_at = ?, turn_count = turn_count + 1, first_wake_at = COALESCE(first_wake_at, ?) WHERE org_id = ? AND surface_key = ?")
2195
+ .run(at, at, org, surfaceKey);
2196
+ },
2197
+
2198
+ async bumpChannelSessionUsage(org, surfaceKey, token, delta) {
2199
+ // Token-guarded: only the LIVE generation's row updates, so a straggler step from a
2200
+ // retired generation is a no-op (no phantom counting across a rotation). NULL⇒0 first.
2201
+ // ONE write, TWO rungs (OPE-794): the running SUM is the cumulative backstop's input, the SET
2202
+ // value is the context-size trigger's. They share this statement so they can never disagree
2203
+ // about which step they saw, and the token guard covers both.
2204
+ const res = getDb()
2205
+ .prepare("UPDATE channel_session SET input_tokens_total = COALESCE(input_tokens_total, 0) + ?, last_input_tokens = ? WHERE org_id = ? AND surface_key = ? AND token = ?")
2206
+ .run(delta, delta, org, surfaceKey, token);
2207
+ return Number(res.changes ?? 0);
2208
+ },
2209
+
2210
+ async listChannelSessions(org, keyPrefix) {
2211
+ const rows = (
2212
+ keyPrefix === undefined
2213
+ ? getDb()
2214
+ .prepare("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 = ?")
2215
+ .all(org)
2216
+ : getDb()
2217
+ // LIKE with a literal, colon/`::`-only prefix (`oe-domain::`) — no user-controlled
2218
+ // wildcard chars ever reach this call, so a plain concatenation is safe.
2219
+ .prepare("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 = ? AND surface_key LIKE ?")
2220
+ .all(org, `${keyPrefix}%`)
2221
+ ) as {
2222
+ surface_key: string; token: string; generation: number; created_at: string; last_wake_at: string; turn_count: number;
2223
+ input_tokens_total: number | null; first_wake_at: string | null; last_input_tokens: number | null; rotate_marked_at: string | null;
2224
+ served_code_fingerprint: string | null; served_domain_fingerprint: string | null;
2225
+ }[];
2226
+ return rows.map((r) => ({
2227
+ org, surfaceKey: r.surface_key, token: r.token, generation: r.generation, createdAt: r.created_at,
2228
+ lastWakeAt: r.last_wake_at, turnCount: r.turn_count,
2229
+ inputTokensTotal: r.input_tokens_total == null ? null : Number(r.input_tokens_total),
2230
+ firstWakeAt: r.first_wake_at ?? null,
2231
+ lastInputTokens: r.last_input_tokens == null ? null : Number(r.last_input_tokens),
2232
+ rotateMarkedAt: r.rotate_marked_at ?? null,
2233
+ servedCodeFingerprint: r.served_code_fingerprint ?? null,
2234
+ servedDomainFingerprint: r.served_domain_fingerprint ?? null,
2235
+ }));
2236
+ },
2237
+
2238
+ // The tail ring is bounded ON WRITE, in the same statement batch as the insert. A ring pruned by a sweep has a window where a hot generation is unbounded, and this table takes a write on every wake and every post.
2239
+
2240
+ async appendSessionTail(org, surfaceKey, token, entry) {
2241
+ const handle = getDb();
2242
+ const next = handle
2243
+ .prepare("SELECT COALESCE(MAX(seq), 0) + 1 AS seq FROM session_tail WHERE org_id = ? AND surface_key = ? AND token = ?")
2244
+ .get(org, surfaceKey, token) as { seq: number };
2245
+ handle
2246
+ .prepare("INSERT INTO session_tail (org_id, surface_key, token, seq, at, entry_json) VALUES (?, ?, ?, ?, ?, ?)")
2247
+ .run(org, surfaceKey, token, next.seq, entry.at, JSON.stringify(entry));
2248
+ handle
2249
+ .prepare(
2250
+ `DELETE FROM session_tail
2251
+ WHERE org_id = ? AND surface_key = ? AND token = ?
2252
+ AND seq <= ?`,
2253
+ )
2254
+ .run(org, surfaceKey, token, next.seq - SESSION_TAIL_MAX_ENTRIES);
2255
+ },
2256
+
2257
+ async readSessionTail(org, surfaceKey, token) {
2258
+ const rows = getDb()
2259
+ .prepare("SELECT entry_json FROM session_tail WHERE org_id = ? AND surface_key = ? AND token = ? ORDER BY seq ASC")
2260
+ .all(org, surfaceKey, token) as { entry_json: string }[];
2261
+ // A row whose JSON no longer parses is DROPPED, not thrown on: this feeds a wake, and one bad
2262
+ // row must never cost the whole tail. There is no schema version to negotiate — the entry is
2263
+ // written and read by the same deployment within one generation's lifetime.
2264
+ const out: SessionTailEntry[] = [];
2265
+ for (const r of rows) {
2266
+ try {
2267
+ out.push(JSON.parse(r.entry_json) as SessionTailEntry);
2268
+ } catch {
2269
+ /* unreadable entry — skip it, keep the rest of the tail */
2270
+ }
2271
+ }
2272
+ return out;
2273
+ },
2274
+
2275
+ async clearSessionTail(org, surfaceKey, token) {
2276
+ getDb().prepare("DELETE FROM session_tail WHERE org_id = ? AND surface_key = ? AND token = ?").run(org, surfaceKey, token);
2277
+ },
2278
+
2279
+ // The ring's only mutation: rewrite ONE post row's text after edit_reply's platform-confirmed success.
2280
+ // The match runs in JS on the parsed rows because entry_json is opaque to this store, and the post-kind test guards a wake row carrying the same platform message id.
2281
+ async editSessionTailPost(org, surfaceKey, token, messageId, text) {
2282
+ const rows = getDb()
2283
+ .prepare("SELECT seq, entry_json FROM session_tail WHERE org_id = ? AND surface_key = ? AND token = ? ORDER BY seq DESC")
2284
+ .all(org, surfaceKey, token) as { seq: number; entry_json: string }[];
2285
+ for (const r of rows) {
2286
+ let entry: SessionTailEntry;
2287
+ try {
2288
+ entry = JSON.parse(r.entry_json) as SessionTailEntry;
2289
+ } catch {
2290
+ continue; // an unreadable row can't be the match — readSessionTail drops it too
2291
+ }
2292
+ if (entry.kind !== "post" || entry.id !== messageId) continue;
2293
+ const updated: SessionTailEntry = { ...entry, text };
2294
+ getDb()
2295
+ .prepare("UPDATE session_tail SET entry_json = ? WHERE org_id = ? AND surface_key = ? AND token = ? AND seq = ?")
2296
+ .run(JSON.stringify(updated), org, surfaceKey, token, r.seq);
2297
+ return true;
2298
+ }
2299
+ return false;
2300
+ },
2301
+
2302
+ async listDomainSkills(org, domain) {
2303
+ const rows = getDb()
2304
+ .prepare("SELECT name, content, updated_by, updated_at FROM domain_skill WHERE org_id = ? AND domain = ? ORDER BY name")
2305
+ .all(org, domain) as { name: string; content: string; updated_by: string | null; updated_at: string }[];
2306
+ return rows.map((r) => ({
2307
+ org,
2308
+ domain,
2309
+ name: r.name,
2310
+ content: r.content,
2311
+ ...(r.updated_by ? { updatedBy: r.updated_by } : {}),
2312
+ updatedAt: r.updated_at,
2313
+ }));
2314
+ },
2315
+
2316
+ async putDomainSkill(org, domain, name, content, updatedBy, updatedAt, provenance) {
2317
+ // REVISION FIRST, then the destructive upsert — same reasoning as the Postgres adapter:
2318
+ // if the two tear, over-record (an extra revision for a body that failed to arm) rather
2319
+ // than under-record (a live body with no record of what an approver agreed to).
2320
+ getDb()
2321
+ .prepare(
2322
+ `INSERT INTO domain_skill_revisions (org_id, domain, name, content, authored_by, armed_by, approval_id, recorded_at)
2323
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
2324
+ )
2325
+ .run(org, domain, name, content, updatedBy ?? null, provenance?.armedBy ?? null, provenance?.approvalId ?? null, updatedAt);
2326
+ getDb()
2327
+ .prepare(
2328
+ `INSERT INTO domain_skill (org_id, domain, name, content, updated_by, updated_at) VALUES (?, ?, ?, ?, ?, ?)
2329
+ ON CONFLICT(org_id, domain, name) DO UPDATE SET
2330
+ content = excluded.content,
2331
+ updated_by = excluded.updated_by,
2332
+ updated_at = excluded.updated_at`,
2333
+ )
2334
+ .run(org, domain, name, content, updatedBy ?? null, updatedAt);
2335
+ },
2336
+
2337
+ async deleteDomainSkill(org, domain, name) {
2338
+ return getDb().prepare("DELETE FROM domain_skill WHERE org_id = ? AND domain = ? AND name = ?").run(org, domain, name).changes > 0;
2339
+ },
2340
+
2341
+ async listDomainSkillRevisions(org, domain, name) {
2342
+ const rows = getDb()
2343
+ .prepare(
2344
+ `SELECT seq, name, content, authored_by, armed_by, approval_id, recorded_at
2345
+ FROM domain_skill_revisions
2346
+ WHERE org_id = ? AND domain = ? AND (? IS NULL OR name = ?)
2347
+ ORDER BY seq`,
2348
+ )
2349
+ .all(org, domain, name ?? null, name ?? null) as {
2350
+ seq: number;
2351
+ name: string;
2352
+ content: string;
2353
+ authored_by: string | null;
2354
+ armed_by: string | null;
2355
+ approval_id: string | null;
2356
+ recorded_at: string;
2357
+ }[];
2358
+ return rows.map((r) => ({
2359
+ seq: Number(r.seq),
2360
+ org,
2361
+ domain,
2362
+ name: r.name,
2363
+ content: r.content,
2364
+ ...(r.authored_by ? { authoredBy: r.authored_by } : {}),
2365
+ ...(r.armed_by ? { armedBy: r.armed_by } : {}),
2366
+ ...(r.approval_id ? { approvalId: r.approval_id } : {}),
2367
+ recordedAt: r.recorded_at,
2368
+ }));
2369
+ },
2370
+
2371
+ async appendUsageEvent(entry) {
2372
+ getDb()
2373
+ .prepare(
2374
+ `INSERT INTO usage_events
2375
+ (org_id, surface_key, session_id, principal_id, ts, kind, routine_id,
2376
+ input_tokens, output_tokens, cache_read_tokens, cache_write_tokens, model, detail,
2377
+ usd_micros_measured, cost_source, delegation_depth, root_session_id,
2378
+ cache_tokens_reported, reasoning_tokens, surface_mode)
2379
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
2380
+ )
2381
+ .run(
2382
+ entry.org,
2383
+ entry.surfaceKey,
2384
+ entry.sessionId,
2385
+ entry.principalId ?? null,
2386
+ entry.ts,
2387
+ entry.kind ?? null,
2388
+ entry.routineId ?? null,
2389
+ entry.inputTokens,
2390
+ entry.outputTokens,
2391
+ entry.cacheReadTokens,
2392
+ entry.cacheWriteTokens,
2393
+ entry.model ?? null,
2394
+ entry.detail ? JSON.stringify(entry.detail) : null,
2395
+ // `?? null` on all four, never `?? 0`/`?? ''`: a NULL says "this writer had nothing to
2396
+ // report", which is a different fact from a measured zero or a root turn's depth 0.
2397
+ entry.usdMicrosMeasured ?? null,
2398
+ entry.costSource ?? null,
2399
+ entry.delegationDepth ?? null,
2400
+ entry.rootSessionId ?? null,
2401
+ // OPE-1611, same `?? null` discipline: NULL is "nothing was reported". node:sqlite has no
2402
+ // boolean, so the flag stores 1/0 and reads back through the same `!= null` test.
2403
+ entry.cacheTokensReported === undefined ? null : entry.cacheTokensReported ? 1 : 0,
2404
+ entry.reasoningTokens ?? null,
2405
+ // OPE-1862, same discipline: NULL says "no binding stamped this row", and a report masks
2406
+ // such a row. It is never inferred from the surface id.
2407
+ entry.surfaceMode ?? null,
2408
+ );
2409
+ },
2410
+
2411
+ async usageForSession(org, sessionId) {
2412
+ const rows = getDb()
2413
+ .prepare(
2414
+ `SELECT surface_key, session_id, principal_id, ts, kind, routine_id,
2415
+ input_tokens, output_tokens, cache_read_tokens, cache_write_tokens, model, detail,
2416
+ usd_micros_measured, cost_source, delegation_depth, root_session_id,
2417
+ cache_tokens_reported, reasoning_tokens, surface_mode
2418
+ FROM usage_events WHERE org_id = ? AND session_id = ? ORDER BY seq ASC`,
2419
+ )
2420
+ .all(org, sessionId) as UsageEventRow[];
2421
+ return rows.map((r) => usageEventFromRow(org, r));
2422
+ },
2423
+
2424
+ async usageSummary(org, filter = {}) {
2425
+ const where: string[] = ["org_id = ?"];
2426
+ const params: string[] = [org];
2427
+ if (filter.surfaceKeyPrefix !== undefined) {
2428
+ where.push("surface_key LIKE ?");
2429
+ params.push(`${filter.surfaceKeyPrefix}%`);
2430
+ }
2431
+ if (filter.sinceTs !== undefined) {
2432
+ where.push("ts >= ?");
2433
+ params.push(filter.sinceTs);
2434
+ }
2435
+ if (filter.untilTs !== undefined) {
2436
+ where.push("ts <= ?");
2437
+ params.push(filter.untilTs);
2438
+ }
2439
+ // OPE-402: exclude rows whose session had ANY recorded usage event before the bound — the
2440
+ // session-scoped half of the leak sinceTs alone cannot close (see UsageSummaryFilter's doc).
2441
+ // Rides the existing (org_id, session_id) index (usage_events_org_session).
2442
+ if (filter.sessionStartedAfter !== undefined) {
2443
+ where.push("session_id IN (SELECT session_id FROM usage_events WHERE org_id = ? GROUP BY session_id HAVING MIN(ts) >= ?)");
2444
+ params.push(org, filter.sessionStartedAfter);
2445
+ }
2446
+ const rows = getDb()
2447
+ .prepare(
2448
+ `SELECT surface_key, principal_id, kind, routine_id, model, surface_mode,
2449
+ SUM(input_tokens) AS input_tokens, SUM(output_tokens) AS output_tokens,
2450
+ SUM(cache_read_tokens) AS cache_read_tokens, SUM(cache_write_tokens) AS cache_write_tokens,
2451
+ -- OPE-1611: the attribution dimension AND its coverage. COALESCE keeps the sum an
2452
+ -- integer when every row is NULL; the two counts say how many calls actually
2453
+ -- reported, so a reader never mistakes an all-NULL group's 0 for "no caching".
2454
+ -- (sqlite has no FILTER clause here, so the flag count is a SUM over 1/0.)
2455
+ COALESCE(SUM(reasoning_tokens), 0) AS reasoning_tokens,
2456
+ COALESCE(SUM(CASE WHEN cache_tokens_reported = 1 THEN 1 ELSE 0 END), 0) AS cache_reported_calls,
2457
+ COUNT(reasoning_tokens) AS reasoning_reported_calls,
2458
+ COUNT(*) AS events, COUNT(DISTINCT session_id) AS sessions
2459
+ FROM usage_events WHERE ${where.join(" AND ")}
2460
+ -- OPE-1862: surface_mode joins the GRAIN rather than riding along as MAX(). A group must
2461
+ -- be homogeneous in every column it reports, and one surface can hold both unstamped
2462
+ -- legacy rows and stamped new ones; those two masks differently, so they must not blend.
2463
+ GROUP BY surface_key, principal_id, kind, routine_id, model, surface_mode`,
2464
+ )
2465
+ .all(...params) as {
2466
+ surface_key: string;
2467
+ principal_id: string | null;
2468
+ kind: string | null;
2469
+ routine_id: string | null;
2470
+ model: string | null;
2471
+ surface_mode: string | null;
2472
+ input_tokens: number;
2473
+ output_tokens: number;
2474
+ cache_read_tokens: number;
2475
+ cache_write_tokens: number;
2476
+ reasoning_tokens: number;
2477
+ cache_reported_calls: number;
2478
+ reasoning_reported_calls: number;
2479
+ events: number;
2480
+ sessions: number;
2481
+ }[];
2482
+ return rows.map((r) => ({
2483
+ surfaceKey: r.surface_key,
2484
+ ...(r.principal_id ? { principalId: r.principal_id } : {}),
2485
+ ...(r.kind ? { kind: r.kind } : {}),
2486
+ ...(r.routine_id ? { routineId: r.routine_id } : {}),
2487
+ ...(r.model ? { model: r.model } : {}),
2488
+ ...((): { surfaceMode?: SurfaceMode } => {
2489
+ const mode = asSurfaceMode(r.surface_mode);
2490
+ return mode ? { surfaceMode: mode } : {};
2491
+ })(),
2492
+ inputTokens: r.input_tokens,
2493
+ outputTokens: r.output_tokens,
2494
+ cacheReadTokens: r.cache_read_tokens,
2495
+ cacheWriteTokens: r.cache_write_tokens,
2496
+ reasoningTokens: r.reasoning_tokens,
2497
+ cacheReportedCalls: r.cache_reported_calls,
2498
+ reasoningReportedCalls: r.reasoning_reported_calls,
2499
+ events: r.events,
2500
+ sessions: r.sessions,
2501
+ }));
2502
+ },
2503
+
2504
+ async pruneUsageEvents(org, olderThanTs) {
2505
+ // node:sqlite types `changes` as `number | bigint`; this DB never runs with
2506
+ // BigInt result mode, but the type needs a plain Number() to satisfy the
2507
+ // Promise<number> contract.
2508
+ return Number(getDb().prepare("DELETE FROM usage_events WHERE org_id = ? AND ts < ?").run(org, olderThanTs).changes);
2509
+ },
2510
+
2511
+ async appendModelCallCapture(write: ModelCallCaptureWrite) {
2512
+ getDb()
2513
+ .prepare(
2514
+ `INSERT INTO model_call_capture
2515
+ (org_id, surface_key, session_id, turn_id, step_index, ts, model, provider,
2516
+ schema_version, sha256, body_bytes, body_gzip_b64, truncated)
2517
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
2518
+ )
2519
+ .run(
2520
+ write.org,
2521
+ write.surfaceKey,
2522
+ write.sessionId,
2523
+ write.turnId,
2524
+ write.stepIndex,
2525
+ write.ts,
2526
+ write.model,
2527
+ write.provider,
2528
+ write.schemaVersion,
2529
+ write.sha256,
2530
+ write.bodyBytes,
2531
+ write.bodyGzipB64,
2532
+ write.truncated ? 1 : 0,
2533
+ );
2534
+ },
2535
+
2536
+ async modelCallCapturesForSession(org, sessionId, opts = {}) {
2537
+ const includeBody = opts.includeBody !== false;
2538
+ // The body column is selected only when asked for. A metadata read of a 200-row soak session
2539
+ // otherwise drags tens of MB of prompt bytes through the process for a count.
2540
+ const bodyCol = includeBody ? "body_gzip_b64" : "'' AS body_gzip_b64";
2541
+ const where = ["org_id = ?", "session_id = ?"];
2542
+ const params: (string | number)[] = [org, sessionId];
2543
+ if (opts.turnId !== undefined) {
2544
+ where.push("turn_id = ?");
2545
+ params.push(opts.turnId);
2546
+ }
2547
+ const limit = opts.limit !== undefined ? ` LIMIT ${Math.max(0, Math.floor(opts.limit))}` : "";
2548
+ const rows = getDb()
2549
+ .prepare(
2550
+ `SELECT seq, surface_key, session_id, turn_id, step_index, ts, model, provider,
2551
+ schema_version, sha256, body_bytes, ${bodyCol}, truncated
2552
+ FROM model_call_capture WHERE ${where.join(" AND ")} ORDER BY seq ASC${limit}`,
2553
+ )
2554
+ .all(...params) as ModelCallCaptureDbRow[];
2555
+ return rows.map((r) => modelCallCaptureFromRow(org, r));
2556
+ },
2557
+
2558
+ async modelCallCaptureSessions(org) {
2559
+ const rows = getDb()
2560
+ .prepare(
2561
+ `SELECT session_id, MIN(ts) AS first_ts, MAX(ts) AS last_ts, COUNT(*) AS row_count, SUM(body_bytes) AS total_bytes
2562
+ FROM model_call_capture WHERE org_id = ?
2563
+ GROUP BY session_id
2564
+ ORDER BY MAX(ts) DESC`,
2565
+ )
2566
+ .all(org) as { session_id: string; first_ts: string; last_ts: string; row_count: number; total_bytes: number | null }[];
2567
+ return rows.map(
2568
+ (r): ModelCallCaptureSessionRow => ({
2569
+ sessionId: r.session_id,
2570
+ firstTs: r.first_ts,
2571
+ lastTs: r.last_ts,
2572
+ rowCount: Number(r.row_count),
2573
+ totalBytes: Number(r.total_bytes ?? 0),
2574
+ }),
2575
+ );
2576
+ },
2577
+
2578
+ async deleteModelCallCapturesForSession(org, sessionId) {
2579
+ return Number(getDb().prepare("DELETE FROM model_call_capture WHERE org_id = ? AND session_id = ?").run(org, sessionId).changes);
2580
+ },
2581
+
2582
+ async addMemoryProposal(write: MemoryProposalWrite) {
2583
+ const result = getDb()
2584
+ .prepare(
2585
+ `INSERT INTO memory_proposal (org_id, kind, scope, summary, before_text, after_text, detail_json, principal_id, created_at)
2586
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
2587
+ )
2588
+ .run(
2589
+ write.org,
2590
+ write.kind,
2591
+ write.scope,
2592
+ write.summary,
2593
+ write.before ?? null,
2594
+ write.after ?? null,
2595
+ write.detail ? JSON.stringify(write.detail) : null,
2596
+ write.principalId,
2597
+ write.createdAt,
2598
+ );
2599
+ return { ...write, id: Number(result.lastInsertRowid) } as MemoryProposalRow;
2600
+ },
2601
+
2602
+ async listMemoryProposals(org) {
2603
+ const rows = getDb()
2604
+ .prepare(
2605
+ `SELECT id, kind, scope, summary, before_text, after_text, detail_json, principal_id, created_at
2606
+ FROM memory_proposal WHERE org_id = ? ORDER BY id DESC`,
2607
+ )
2608
+ .all(org) as {
2609
+ id: number;
2610
+ kind: string;
2611
+ scope: string;
2612
+ summary: string;
2613
+ before_text: string | null;
2614
+ after_text: string | null;
2615
+ detail_json: string | null;
2616
+ principal_id: string;
2617
+ created_at: string;
2618
+ }[];
2619
+ return rows.map(
2620
+ (r): MemoryProposalRow => ({
2621
+ id: r.id,
2622
+ org,
2623
+ kind: r.kind,
2624
+ scope: r.scope,
2625
+ summary: r.summary,
2626
+ ...(r.before_text !== null ? { before: r.before_text } : {}),
2627
+ ...(r.after_text !== null ? { after: r.after_text } : {}),
2628
+ ...(r.detail_json ? { detail: JSON.parse(r.detail_json) as Record<string, unknown> } : {}),
2629
+ principalId: r.principal_id,
2630
+ createdAt: r.created_at,
2631
+ }),
2632
+ );
2633
+ },
2634
+
2635
+ async getDmAudience(org, address) {
2636
+ const row = getDb()
2637
+ .prepare("SELECT address, first_dm_at, stopped_at FROM dm_audience WHERE org_id = ? AND address = ?")
2638
+ .get(org, address) as { address: string; first_dm_at: string | null; stopped_at: string | null } | undefined;
2639
+ return row ? dmAudienceRowFrom(row) : null;
2640
+ },
2641
+
2642
+ async markDmAudienceDelivered(org, address, at) {
2643
+ // COALESCE keeps the ORIGINAL first_dm_at — see store.ts's method doc. `stopped_at` is not in the
2644
+ // update list at all, so a delivery can never clear a stop even if a caller raced one.
2645
+ getDb()
2646
+ .prepare(
2647
+ `INSERT INTO dm_audience (org_id, address, first_dm_at, stopped_at) VALUES (?, ?, ?, NULL)
2648
+ ON CONFLICT (org_id, address) DO UPDATE SET first_dm_at = COALESCE(dm_audience.first_dm_at, excluded.first_dm_at)`,
2649
+ )
2650
+ .run(org, address, at);
2651
+ },
2652
+
2653
+ async setDmAudienceStopped(org, address, at) {
2654
+ // COALESCE for the same reason as above, in the other direction: a second stop keeps the FIRST
2655
+ // stopped_at, so the trail records when the boundary was first drawn rather than last repeated.
2656
+ getDb()
2657
+ .prepare(
2658
+ `INSERT INTO dm_audience (org_id, address, first_dm_at, stopped_at) VALUES (?, ?, NULL, ?)
2659
+ ON CONFLICT (org_id, address) DO UPDATE SET stopped_at = COALESCE(dm_audience.stopped_at, excluded.stopped_at)`,
2660
+ )
2661
+ .run(org, address, at);
2662
+ },
2663
+
2664
+ async clearDmAudienceStopped(org, address) {
2665
+ // The `stopped_at IS NOT NULL` conjunct is what makes the return value honest: `changes` counts
2666
+ // rows the UPDATE actually altered, so a row that was never stopped answers false rather than
2667
+ // reporting a resume that resumed nothing.
2668
+ return (
2669
+ getDb()
2670
+ .prepare("UPDATE dm_audience SET stopped_at = NULL WHERE org_id = ? AND address = ? AND stopped_at IS NOT NULL")
2671
+ .run(org, address).changes > 0
2672
+ );
2673
+ },
2674
+
2675
+ async listDmAudience(org) {
2676
+ const rows = getDb()
2677
+ .prepare("SELECT address, first_dm_at, stopped_at FROM dm_audience WHERE org_id = ? ORDER BY address")
2678
+ .all(org) as { address: string; first_dm_at: string | null; stopped_at: string | null }[];
2679
+ return rows.map(dmAudienceRowFrom);
2680
+ },
2681
+
2682
+ async runAnalyticsQuery(compiled) {
2683
+ // OPE-66: assemble the SELECT-only statement with `?` placeholders (the SQLite style) and run it.
2684
+ // Every non-param token is registry-derived; only `params` bind. node:sqlite returns bigints as
2685
+ // JS numbers here (no BigInt result mode), so the plain objects need no coercion at this layer.
2686
+ const { sql, params } = assembleAnalyticsSql(compiled, "qmark");
2687
+ return getDb().prepare(sql).all(...(params as (string | number | null)[])) as Record<string, unknown>[];
2688
+ },
2689
+
2690
+ async enqueueIngressDelivery(org, write) {
2691
+ const handle = getDb();
2692
+ // Completed rows contain no payload and exist only to suppress a vendor replay. Prune them on
2693
+ // the next enqueue for this org/source; pending rows carry NULL and are never clock-expired.
2694
+ handle
2695
+ .prepare("DELETE FROM ingress_delivery WHERE org_id = ? AND source = ? AND completed_at IS NOT NULL AND retain_until IS NOT NULL AND retain_until <= ?")
2696
+ .run(org, write.source, write.receivedAt);
2697
+ const info = handle
2698
+ .prepare(
2699
+ `INSERT OR IGNORE INTO ingress_delivery
2700
+ (org_id, source, authority_id, delivery_id, payload_json, received_at, available_at)
2701
+ VALUES (?, ?, ?, ?, ?, ?, ?)`,
2702
+ )
2703
+ .run(org, write.source, write.authorityId, write.deliveryId, write.payloadJson, write.receivedAt, write.receivedAt);
2704
+ return info.changes > 0;
2705
+ },
2706
+
2707
+ async listDueIngressDeliveries(org, source, nowIso, staleBeforeIso, limit) {
2708
+ const rows = getDb()
2709
+ .prepare(
2710
+ `SELECT authority_id, delivery_id, received_at, available_at
2711
+ FROM ingress_delivery
2712
+ WHERE org_id = ? AND source = ? AND completed_at IS NULL AND payload_json IS NOT NULL
2713
+ AND available_at <= ?
2714
+ AND (claim_id IS NULL OR (claimed_at IS NOT NULL AND claimed_at <= ?))
2715
+ ORDER BY received_at ASC, authority_id ASC, delivery_id ASC
2716
+ LIMIT ?`,
2717
+ )
2718
+ .all(org, source, nowIso, staleBeforeIso, Math.max(0, Math.trunc(limit))) as Array<{
2719
+ authority_id: string;
2720
+ delivery_id: string;
2721
+ received_at: string;
2722
+ available_at: string;
2723
+ }>;
2724
+ return rows.map((row): DueIngressDelivery => ({
2725
+ source,
2726
+ authorityId: row.authority_id,
2727
+ deliveryId: row.delivery_id,
2728
+ receivedAt: row.received_at,
2729
+ availableAt: row.available_at,
2730
+ }));
2731
+ },
2732
+
2733
+ async claimIngressDelivery(org, key, claimId, claimedAtIso, staleBeforeIso) {
2734
+ const row = getDb()
2735
+ .prepare(
2736
+ `UPDATE ingress_delivery SET claim_id = ?, claimed_at = ?
2737
+ WHERE org_id = ? AND source = ? AND authority_id = ? AND delivery_id = ?
2738
+ AND completed_at IS NULL AND payload_json IS NOT NULL AND available_at <= ?
2739
+ AND (claim_id IS NULL OR (claimed_at IS NOT NULL AND claimed_at <= ?))
2740
+ RETURNING payload_json, received_at, available_at`,
2741
+ )
2742
+ .get(claimId, claimedAtIso, org, key.source, key.authorityId, key.deliveryId, claimedAtIso, staleBeforeIso) as
2743
+ | { payload_json: string; received_at: string; available_at: string }
2744
+ | undefined;
2745
+ return row
2746
+ ? ({
2747
+ ...key,
2748
+ payloadJson: row.payload_json,
2749
+ receivedAt: row.received_at,
2750
+ availableAt: row.available_at,
2751
+ claimId,
2752
+ claimedAt: claimedAtIso,
2753
+ } satisfies ClaimedIngressDelivery)
2754
+ : null;
2755
+ },
2756
+
2757
+ async releaseIngressDelivery(org, key, claimId, availableAtIso) {
2758
+ const info = getDb()
2759
+ .prepare(
2760
+ `UPDATE ingress_delivery SET claim_id = NULL, claimed_at = NULL, available_at = ?
2761
+ WHERE org_id = ? AND source = ? AND authority_id = ? AND delivery_id = ?
2762
+ AND completed_at IS NULL AND claim_id = ?`,
2763
+ )
2764
+ .run(availableAtIso, org, key.source, key.authorityId, key.deliveryId, claimId);
2765
+ return info.changes > 0;
2766
+ },
2767
+
2768
+ async completeIngressDelivery(org, key, claimId, completedAtIso, retainUntilIso) {
2769
+ assertIngressDeliveryRetainUntil(completedAtIso, retainUntilIso);
2770
+ const info = getDb()
2771
+ .prepare(
2772
+ `UPDATE ingress_delivery
2773
+ SET payload_json = NULL, claim_id = NULL, claimed_at = NULL,
2774
+ completed_at = ?, retain_until = ?
2775
+ WHERE org_id = ? AND source = ? AND authority_id = ? AND delivery_id = ?
2776
+ AND completed_at IS NULL AND claim_id = ?`,
2777
+ )
2778
+ .run(completedAtIso, retainUntilIso, org, key.source, key.authorityId, key.deliveryId, claimId);
2779
+ return info.changes > 0;
2780
+ },
2781
+
2782
+ async discardIngressDelivery(org, key, claimId) {
2783
+ const info = getDb()
2784
+ .prepare(
2785
+ `DELETE FROM ingress_delivery
2786
+ WHERE org_id = ? AND source = ? AND authority_id = ? AND delivery_id = ?
2787
+ AND completed_at IS NULL AND claim_id = ?`,
2788
+ )
2789
+ .run(org, key.source, key.authorityId, key.deliveryId, claimId);
2790
+ return info.changes > 0;
2791
+ },
2792
+
2793
+ async markEventSeen(org, key, at, ttlMs) {
2794
+ const handle = getDb();
2795
+ // Opportunistic prune keeps the table bounded without a scheduled job; ISO timestamps compare
2796
+ // lexicographically so string < works. TWO clauses, both ORG-SCOPED (see store.ts):
2797
+ // • the caller's `ttlMs`, applied to THIS KEY ONLY — the table is shared by callers whose
2798
+ // windows differ by an order of magnitude (60 s postOnce vs 10 min Slack retry dedupe), so
2799
+ // a bare TTL sweep let the shortest-TTL caller expire everyone else's keys;
2800
+ // • a fixed 24 h housekeeping ceiling for everything else this org wrote.
2801
+ const atMs = Date.parse(at);
2802
+ const ttlCutoff = new Date(atMs - ttlMs).toISOString();
2803
+ const maxCutoff = new Date(atMs - EVENT_DEDUPE_MAX_RETENTION_MS).toISOString();
2804
+ handle
2805
+ .prepare("DELETE FROM event_dedupe WHERE org_id = ? AND (seen_at < ? OR (key = ? AND seen_at < ?))")
2806
+ .run(org, maxCutoff, key, ttlCutoff);
2807
+ // INSERT OR IGNORE is the atomic first-sighting check: exactly one of two
2808
+ // racing inserts lands (changes=1); the loser sees changes=0 → duplicate.
2809
+ const info = handle.prepare("INSERT OR IGNORE INTO event_dedupe (org_id, key, seen_at) VALUES (?, ?, ?)").run(org, key, at);
2810
+ return info.changes > 0;
2811
+ },
2812
+
2813
+ async claimNotice(org, key, at) {
2814
+ // INSERT OR IGNORE is the atomic claim, exactly as markEventSeen's is: one of two racing callers
2815
+ // lands the row (changes=1) and announces; the loser sees changes=0 and stays quiet.
2816
+ // NO DELETE PATH — a claim is a lifetime record, and dropping one lets the thing it records
2817
+ // happen a second time. Every key space on this table is bounded by the thing it records.
2818
+ const info = getDb().prepare("INSERT OR IGNORE INTO notice_claim (org_id, key, claimed_at) VALUES (?, ?, ?)").run(org, key, at);
2819
+ return info.changes > 0;
2820
+ },
2821
+
2822
+ async noticeClaimed(org, key) {
2823
+ const row = getDb().prepare("SELECT 1 FROM notice_claim WHERE org_id = ? AND key = ? LIMIT 1").get(org, key);
2824
+ return row !== undefined;
2825
+ },
2826
+
2827
+ async recordProactiveAddress(org, row) {
2828
+ getDb()
2829
+ .prepare(
2830
+ `INSERT INTO proactive_address (org_id, platform, kind, ref_key, tenant, address, updated_at)
2831
+ VALUES (?, ?, ?, ?, ?, ?, ?)
2832
+ ON CONFLICT(org_id, platform, kind, ref_key) DO UPDATE SET
2833
+ tenant = excluded.tenant, address = excluded.address, updated_at = excluded.updated_at`,
2834
+ )
2835
+ .run(org, row.platform, row.kind, row.refKey, row.tenant, JSON.stringify(row.address ?? {}), row.updatedAt);
2836
+ },
2837
+
2838
+ async proactiveAddress(org, platform, kind, refKey) {
2839
+ const row = getDb()
2840
+ .prepare("SELECT tenant, address, updated_at FROM proactive_address WHERE org_id = ? AND platform = ? AND kind = ? AND ref_key = ?")
2841
+ .get(org, platform, kind, refKey) as { tenant: string; address: string; updated_at: string } | undefined;
2842
+ return row ? proactiveAddressRow(platform, kind, refKey, row.tenant, row.address, row.updated_at) : undefined;
2843
+ },
2844
+
2845
+ async proactiveAddresses(org, platform, kind, limit) {
2846
+ const rows = getDb()
2847
+ .prepare(
2848
+ `SELECT ref_key, tenant, address, updated_at FROM proactive_address
2849
+ WHERE org_id = ? AND platform = ? AND kind = ? ORDER BY updated_at DESC LIMIT ?`,
2850
+ )
2851
+ .all(org, platform, kind, Math.max(0, Math.trunc(limit))) as { ref_key: string; tenant: string; address: string; updated_at: string }[];
2852
+ return rows.map((r) => proactiveAddressRow(platform, kind, r.ref_key, r.tenant, r.address, r.updated_at));
2853
+ },
2854
+
2855
+ async hasEventSeen(org, key, at, ttlMs) {
2856
+ // READ-ONLY twin of markEventSeen: same cutoff arithmetic, no write, no prune. A caller uses
2857
+ // this to check "is this already marked" before deciding whether marking is even safe.
2858
+ const cutoff = new Date(Date.parse(at) - ttlMs).toISOString();
2859
+ const row = getDb()
2860
+ .prepare("SELECT 1 FROM event_dedupe WHERE org_id = ? AND key = ? AND seen_at >= ? LIMIT 1")
2861
+ .get(org, key, cutoff);
2862
+ return row !== undefined;
2863
+ },
2864
+
2865
+ async forgetEventSeen(org, key) {
2866
+ // ONE row, org-scoped and keyed — never a sweep. See the interface note for when a claim is
2867
+ // given back (OPE-821: a DEFINITIVE post failure, so an identical retry can really post).
2868
+ getDb().prepare("DELETE FROM event_dedupe WHERE org_id = ? AND key = ?").run(org, key);
2869
+ },
2870
+
2871
+ async captureDelivery(org, source, documentJson, at, captureUntil, maxRows) {
2872
+ const handle = getDb();
2873
+ const atMs = Date.parse(at);
2874
+ // A NON-PARSEABLE `at` FAILS CLOSED. Every other TTL-pruned table in this file derives a cutoff
2875
+ // from `Date.parse(at)` and would compute `Invalid Date` on a bad stamp; here that would mean a
2876
+ // sweep that deletes nothing while the insert still lands, i.e. the one table whose bound must
2877
+ // hold silently losing it. Refusing to capture costs a sample.
2878
+ if (!Number.isFinite(atMs)) return false;
2879
+ // BOUND 1 — the absolute age sweep, ORG-SCOPED, and FIRST so it runs even on a write the window
2880
+ // is about to refuse. This is the bound that holds when the other two are wrong.
2881
+ const maxCutoff = new Date(atMs - CAPTURE_MAX_RETENTION_MS).toISOString();
2882
+ handle.prepare("DELETE FROM webhook_capture WHERE org_id = ? AND captured_at < ?").run(org, maxCutoff);
2883
+ // BOUND 2 — the window closed on TIME. Compared as instants, not as strings: `captureUntil` is
2884
+ // minted by the arming path and a lexicographic comparison would quietly do the wrong thing on
2885
+ // any stamp that is not Z-normalised.
2886
+ const untilMs = Date.parse(captureUntil);
2887
+ if (!Number.isFinite(untilMs) || atMs >= untilMs) return false;
2888
+ // BOUND 3 — the window closed on VOLUME. The row count IS the counter, so there is no separate
2889
+ // tally that can drift from the rows it claims to count.
2890
+ const row = handle
2891
+ .prepare("SELECT COUNT(*) AS n, COALESCE(MAX(seq), 0) AS maxSeq FROM webhook_capture WHERE org_id = ? AND source = ?")
2892
+ .get(org, source) as { n: number; maxSeq: number };
2893
+ if (row.n >= maxRows) return false;
2894
+ handle
2895
+ .prepare("INSERT INTO webhook_capture (org_id, source, seq, captured_at, document) VALUES (?, ?, ?, ?, ?)")
2896
+ .run(org, source, row.maxSeq + 1, at, documentJson);
2897
+ return true;
2898
+ },
2899
+
2900
+ async listCapturedDeliveries(org, source, limit) {
2901
+ const rows = getDb()
2902
+ .prepare("SELECT seq, captured_at, document FROM webhook_capture WHERE org_id = ? AND source = ? ORDER BY seq ASC LIMIT ?")
2903
+ .all(org, source, limit) as { seq: number; captured_at: string; document: string }[];
2904
+ return rows.map((r) => ({ seq: r.seq, capturedAt: r.captured_at, documentJson: r.document }));
2905
+ },
2906
+
2907
+ async clearCapturedDeliveries(org, source) {
2908
+ getDb().prepare("DELETE FROM webhook_capture WHERE org_id = ? AND source = ?").run(org, source);
2909
+ },
2910
+
2911
+ async putUnifiedWakeTarget(org, wakeId, targetJson, at, ttlMs, windowToken, inbound) {
2912
+ const handle = getDb();
2913
+ // Opportunistic TTL prune, same posture as markEventSeen (bounded table, no scheduled job).
2914
+ // ORG-SCOPED (matches the postgres backend): one org's write never touches another org's rows.
2915
+ const cutoff = new Date(Date.parse(at) - ttlMs).toISOString();
2916
+ handle.prepare("DELETE FROM unified_wake_target WHERE created_at < ? AND org_id = ?").run(cutoff, org);
2917
+ handle
2918
+ .prepare(
2919
+ // 🔴 The conflict clause updates target_json/created_at/window_token and NEVER the answered
2920
+ // columns — a redrive/webhook-retry re-register must not clear (or resurrect) a mark.
2921
+ // 🔴 `inbound` is STICKY-TRUE (MAX over the two sides), unlike every other updated column:
2922
+ // the redrive re-registers an EXISTING wake id as an INTERNAL dispatch, and a plain
2923
+ // overwrite would clear the flag on a row a human's message created.
2924
+ `INSERT INTO unified_wake_target (org_id, wake_id, target_json, created_at, window_token, inbound) VALUES (?, ?, ?, ?, ?, ?)
2925
+ ON CONFLICT (org_id, wake_id) DO UPDATE SET target_json = excluded.target_json, created_at = excluded.created_at, window_token = excluded.window_token,
2926
+ inbound = MAX(COALESCE(excluded.inbound, 0), COALESCE(unified_wake_target.inbound, 0))`,
2927
+ )
2928
+ .run(org, wakeId, targetJson, at, windowToken ?? null, inbound === true ? 1 : 0);
2929
+ },
2930
+
2931
+ async getUnifiedWakeTarget(org, wakeId) {
2932
+ const row = getDb().prepare("SELECT target_json FROM unified_wake_target WHERE org_id = ? AND wake_id = ?").get(org, wakeId) as
2933
+ | { target_json: string }
2934
+ | undefined;
2935
+ return row?.target_json ?? null;
2936
+ },
2937
+
2938
+ async getUnifiedWakeRecord(org, wakeId) {
2939
+ const row = getDb()
2940
+ .prepare("SELECT target_json, created_at, window_token, answered_at, answered_turn_id, audited_at, inbound FROM unified_wake_target WHERE org_id = ? AND wake_id = ?")
2941
+ .get(org, wakeId) as
2942
+ | { target_json: string; created_at: string; window_token: string | null; answered_at: string | null; answered_turn_id: string | null; audited_at: string | null; inbound: number | null }
2943
+ | undefined;
2944
+ if (!row) return null;
2945
+ return {
2946
+ targetJson: row.target_json,
2947
+ createdAt: row.created_at,
2948
+ ...(row.window_token !== null ? { windowToken: row.window_token } : {}),
2949
+ ...(row.answered_at !== null ? { answeredAt: row.answered_at } : {}),
2950
+ ...(row.answered_turn_id !== null ? { answeredTurnId: row.answered_turn_id } : {}),
2951
+ ...(row.audited_at !== null ? { auditedAt: row.audited_at } : {}),
2952
+ // A NULL column is a legacy row, and it stays ABSENT rather than becoming `false` — the two say
2953
+ // different things, and every reader treats absent as attended (OPE-2051).
2954
+ ...(row.inbound !== null ? { inbound: row.inbound === 1 } : {}),
2955
+ };
2956
+ },
2957
+
2958
+ async listPendingUnifiedWakes(org, windowToken, afterIso, limit) {
2959
+ // ORDER BY created_at ASC: the gate reports the OLDEST unseen messages first, which is the order
2960
+ // a reader would meet them in. `answered_at IS NULL` is the whole "pending" definition — the same
2961
+ // column the answerable-reply fence reads, so the two can never disagree about what pending means.
2962
+ const rows = getDb()
2963
+ .prepare(
2964
+ `SELECT wake_id, target_json, created_at FROM unified_wake_target
2965
+ WHERE org_id = ? AND window_token = ? AND answered_at IS NULL AND inbound = 1 AND created_at > ?
2966
+ ORDER BY created_at ASC LIMIT ?`,
2967
+ )
2968
+ .all(org, windowToken, afterIso, limit) as { wake_id: string; target_json: string; created_at: string }[];
2969
+ return rows.map((r) => ({ wakeId: r.wake_id, targetJson: r.target_json, createdAt: r.created_at }));
2970
+ },
2971
+
2972
+ async listUnauditedUnifiedWakes(org, windowToken, limit) {
2973
+ // Same pending definition as the listing above, plus the OPE-836 horizon (`audited_at IS NULL`)
2974
+ // and NO time bound below — a row an earlier turn considered is already excluded by the column.
2975
+ // The filter is in SQL so `limit` bounds the rows still to consider, never a backlog of audited
2976
+ // ones. This query is the accounting audit's alone; the freshness gate's own SQL is untouched.
2977
+ const rows = getDb()
2978
+ .prepare(
2979
+ `SELECT wake_id, target_json, created_at FROM unified_wake_target
2980
+ WHERE org_id = ? AND window_token = ? AND answered_at IS NULL AND inbound = 1 AND audited_at IS NULL
2981
+ ORDER BY created_at ASC LIMIT ?`,
2982
+ )
2983
+ .all(org, windowToken, limit) as { wake_id: string; target_json: string; created_at: string }[];
2984
+ return rows.map((r) => ({ wakeId: r.wake_id, targetJson: r.target_json, createdAt: r.created_at }));
2985
+ },
2986
+
2987
+ async markUnifiedWakesAudited(org, wakeIds, at) {
2988
+ // UPDATE-only and FIRST-STAMP-WINS (`audited_at IS NULL`), so a re-run cannot move the horizon
2989
+ // stamp and a missing row inserts nothing. One statement per id keeps the parameter count fixed
2990
+ // (node:sqlite has no array binding); the caller's own cap bounds the list.
2991
+ if (wakeIds.length === 0) return;
2992
+ const stmt = getDb().prepare("UPDATE unified_wake_target SET audited_at = ? WHERE org_id = ? AND wake_id = ? AND audited_at IS NULL");
2993
+ for (const wakeId of wakeIds) stmt.run(at, org, wakeId);
2994
+ },
2995
+
2996
+ async markUnifiedWakeAnswered(org, wakeId, at, turnId) {
2997
+ // UPDATE-only (never an upsert): an answered mark on a row with no origin is meaningless, and
2998
+ // inserting one would create a phantom the resolver would then have to reject.
2999
+ getDb()
3000
+ .prepare("UPDATE unified_wake_target SET answered_at = ?, answered_turn_id = ? WHERE org_id = ? AND wake_id = ?")
3001
+ .run(at, turnId ?? null, org, wakeId);
3002
+ },
3003
+
3004
+ async putThreadOwner(org, channelKey, threadKey, taskToken, at, ttlMs) {
3005
+ const handle = getDb();
3006
+ // Opportunistic ORG-SCOPED TTL prune (bounded table, no scheduled job), same posture as
3007
+ // putUnifiedWakeTarget — a backstop over the explicit clears (complete_thread / generation GC).
3008
+ const cutoff = new Date(Date.parse(at) - ttlMs).toISOString();
3009
+ handle.prepare("DELETE FROM thread_ownership WHERE created_at < ? AND org_id = ?").run(cutoff, org);
3010
+ handle
3011
+ .prepare(
3012
+ `INSERT INTO thread_ownership (org_id, channel_key, thread_key, task_token, created_at) VALUES (?, ?, ?, ?, ?)
3013
+ ON CONFLICT (org_id, channel_key, thread_key) DO UPDATE SET task_token = excluded.task_token, created_at = excluded.created_at`,
3014
+ )
3015
+ .run(org, channelKey, threadKey, taskToken, at);
3016
+ },
3017
+
3018
+ async getThreadOwner(org, channelKey, threadKey) {
3019
+ const row = getDb().prepare("SELECT task_token FROM thread_ownership WHERE org_id = ? AND channel_key = ? AND thread_key = ?").get(org, channelKey, threadKey) as
3020
+ | { task_token: string }
3021
+ | undefined;
3022
+ return row?.task_token ?? null;
3023
+ },
3024
+
3025
+ async clearThreadOwner(org, channelKey, threadKey) {
3026
+ return getDb().prepare("DELETE FROM thread_ownership WHERE org_id = ? AND channel_key = ? AND thread_key = ?").run(org, channelKey, threadKey).changes > 0;
3027
+ },
3028
+
3029
+ async putThreadSeatState(org, row, at, ttlMs) {
3030
+ const handle = getDb();
3031
+ // Opportunistic ORG-SCOPED TTL prune, the same posture as putThreadOwner beside it.
3032
+ const cutoff = new Date(Date.parse(at) - ttlMs).toISOString();
3033
+ handle.prepare("DELETE FROM thread_seat_state WHERE updated_at < ? AND org_id = ?").run(cutoff, org);
3034
+ handle
3035
+ .prepare(
3036
+ `INSERT INTO thread_seat_state (org_id, channel_key, thread_key, seat_token, parent_key, state, origin_json, report, opened_at, updated_at)
3037
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
3038
+ ON CONFLICT (org_id, channel_key, thread_key) DO UPDATE SET
3039
+ seat_token = excluded.seat_token,
3040
+ parent_key = excluded.parent_key,
3041
+ state = excluded.state,
3042
+ origin_json = excluded.origin_json,
3043
+ report = excluded.report,
3044
+ opened_at = excluded.opened_at,
3045
+ updated_at = excluded.updated_at`,
3046
+ )
3047
+ .run(org, row.channelKey, row.threadKey, row.seatToken, row.parentRegistryKey, row.state, row.originJson, row.report ?? null, row.openedAt, at);
3048
+ },
3049
+
3050
+ async getThreadSeatState(org, channelKey, threadKey) {
3051
+ const row = getDb()
3052
+ .prepare("SELECT seat_token, parent_key, state, origin_json, report, opened_at, updated_at FROM thread_seat_state WHERE org_id = ? AND channel_key = ? AND thread_key = ?")
3053
+ .get(org, channelKey, threadKey) as
3054
+ | { seat_token: string; parent_key: string; state: string; origin_json: string; report: string | null; opened_at: string; updated_at: string }
3055
+ | undefined;
3056
+ if (!row) return null;
3057
+ return {
3058
+ channelKey,
3059
+ threadKey,
3060
+ seatToken: row.seat_token,
3061
+ parentRegistryKey: row.parent_key,
3062
+ // Anything but the two written values reads as `completed`: an unreadable state must never
3063
+ // report a seat as LIVE, which is the direction that would send a steer into a dead session.
3064
+ state: row.state === "open" ? "open" : "completed",
3065
+ originJson: row.origin_json,
3066
+ ...(row.report !== null ? { report: row.report } : {}),
3067
+ openedAt: row.opened_at,
3068
+ updatedAt: row.updated_at,
3069
+ };
3070
+ },
3071
+
3072
+ async putTurnAnchor(org, anchor, at, ttlMs) {
3073
+ const handle = getDb();
3074
+ // Opportunistic ORG-SCOPED TTL prune (bounded table, no scheduled job) — a BACKSTOP over the
3075
+ // explicit clear the turn-end hook does, exactly like putThreadOwner's.
3076
+ const cutoff = new Date(Date.parse(at) - ttlMs).toISOString();
3077
+ handle.prepare("DELETE FROM turn_anchor WHERE created_at < ? AND org_id = ?").run(cutoff, org);
3078
+ handle
3079
+ .prepare(
3080
+ `INSERT INTO turn_anchor (org_id, window_key, anchor_key, channel_key, session_id, turn_id, surface_key, created_at)
3081
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
3082
+ ON CONFLICT (org_id, window_key) DO UPDATE SET
3083
+ anchor_key = excluded.anchor_key, channel_key = excluded.channel_key,
3084
+ session_id = excluded.session_id, turn_id = excluded.turn_id,
3085
+ surface_key = excluded.surface_key, created_at = excluded.created_at`,
3086
+ )
3087
+ .run(org, anchor.windowKey, anchor.anchorKey ?? null, anchor.channelKey ?? null, anchor.sessionId, anchor.turnId, anchor.surfaceKey, at);
3088
+ },
3089
+
3090
+ async getTurnAnchorByWindow(org, windowKey) {
3091
+ return readTurnAnchorRow(getDb().prepare(`${TURN_ANCHOR_SELECT} WHERE org_id = ? AND window_key = ?`).get(org, windowKey));
3092
+ },
3093
+
3094
+ async getTurnAnchorByAnchor(org, anchorKey) {
3095
+ return readTurnAnchorRow(getDb().prepare(`${TURN_ANCHOR_SELECT} WHERE org_id = ? AND anchor_key = ?`).get(org, anchorKey));
3096
+ },
3097
+
3098
+ async getLatestTurnAnchorForChannel(org, channelKey) {
3099
+ return readTurnAnchorRow(
3100
+ getDb().prepare(`${TURN_ANCHOR_SELECT} WHERE org_id = ? AND channel_key = ? ORDER BY created_at DESC, window_key DESC LIMIT 1`).get(org, channelKey),
3101
+ );
3102
+ },
3103
+
3104
+ async clearTurnAnchor(org, windowKey) {
3105
+ return getDb().prepare("DELETE FROM turn_anchor WHERE org_id = ? AND window_key = ?").run(org, windowKey).changes > 0;
3106
+ },
3107
+
3108
+ async putTaskResult(org, taskId, resultJson, at, ttlMs) {
3109
+ const handle = getDb();
3110
+ // Opportunistic ORG-SCOPED TTL prune (bounded table, no scheduled job), same posture as
3111
+ // putUnifiedWakeTarget — one org's write never touches another org's rows.
3112
+ const cutoff = new Date(Date.parse(at) - ttlMs).toISOString();
3113
+ handle.prepare("DELETE FROM task_result WHERE created_at < ? AND org_id = ?").run(cutoff, org);
3114
+ handle
3115
+ .prepare(
3116
+ `INSERT INTO task_result (org_id, task_id, result_json, created_at) VALUES (?, ?, ?, ?)
3117
+ ON CONFLICT (org_id, task_id) DO UPDATE SET result_json = excluded.result_json, created_at = excluded.created_at`,
3118
+ )
3119
+ .run(org, taskId, resultJson, at);
3120
+ },
3121
+
3122
+ async putTaskResultIfAbsent(org, taskId, resultJson, at, ttlMs) {
3123
+ const handle = getDb();
3124
+ const cutoff = new Date(Date.parse(at) - ttlMs).toISOString();
3125
+ handle.prepare("DELETE FROM task_result WHERE created_at < ? AND org_id = ?").run(cutoff, org);
3126
+ const info = handle
3127
+ .prepare(`INSERT INTO task_result (org_id, task_id, result_json, created_at) VALUES (?, ?, ?, ?) ON CONFLICT (org_id, task_id) DO NOTHING`)
3128
+ .run(org, taskId, resultJson, at);
3129
+ return info.changes > 0;
3130
+ },
3131
+
3132
+ async getTaskResult(org, taskId) {
3133
+ const row = getDb().prepare("SELECT result_json FROM task_result WHERE org_id = ? AND task_id = ?").get(org, taskId) as
3134
+ | { result_json?: string }
3135
+ | undefined;
3136
+ return typeof row?.result_json === "string" ? row.result_json : null;
3137
+ },
3138
+
3139
+ async deleteTaskResult(org, taskId) {
3140
+ return getDb().prepare("DELETE FROM task_result WHERE org_id = ? AND task_id = ?").run(org, taskId).changes > 0;
3141
+ },
3142
+
3143
+ async putSlackAttachment(org, fileId, rec, at, ttlMs) {
3144
+ const handle = getDb();
3145
+ // Opportunistic ORG-SCOPED TTL prune (bounded table, no scheduled job), same posture as
3146
+ // putUnifiedWakeTarget — one org's write never touches another org's rows.
3147
+ const cutoff = new Date(Date.parse(at) - ttlMs).toISOString();
3148
+ handle.prepare("DELETE FROM slack_attachment WHERE created_at < ? AND org_id = ?").run(cutoff, org);
3149
+ handle
3150
+ .prepare(
3151
+ `INSERT INTO slack_attachment (org_id, file_id, url_private, mime_type, name, team_id, created_at)
3152
+ VALUES (?, ?, ?, ?, ?, ?, ?)
3153
+ ON CONFLICT (org_id, file_id) DO UPDATE SET
3154
+ url_private = excluded.url_private, mime_type = excluded.mime_type,
3155
+ name = excluded.name, team_id = excluded.team_id, created_at = excluded.created_at`,
3156
+ )
3157
+ .run(org, fileId, rec.urlPrivate, rec.mimeType ?? null, rec.name ?? null, rec.teamId ?? null, at);
3158
+ },
3159
+
3160
+ async getSlackAttachment(org, fileId) {
3161
+ const row = getDb()
3162
+ .prepare("SELECT url_private, mime_type, name, team_id FROM slack_attachment WHERE org_id = ? AND file_id = ?")
3163
+ .get(org, fileId) as { url_private: string; mime_type: string | null; name: string | null; team_id: string | null } | undefined;
3164
+ if (!row) return null;
3165
+ const rec: SlackAttachmentRow = {
3166
+ urlPrivate: row.url_private,
3167
+ ...(row.mime_type ? { mimeType: row.mime_type } : {}),
3168
+ ...(row.name ? { name: row.name } : {}),
3169
+ ...(row.team_id ? { teamId: row.team_id } : {}),
3170
+ };
3171
+ return rec;
3172
+ },
3173
+
3174
+ async putStoredCredential(org, rec) {
3175
+ // Upsert the ciphertext envelope. `rec.ciphertext` is opaque here — never inspected, never logged.
3176
+ getDb()
3177
+ .prepare(
3178
+ `INSERT INTO stored_credential (org_id, ref, ciphertext, connector, domain, created_by, created_at)
3179
+ VALUES (?, ?, ?, ?, ?, ?, ?)
3180
+ ON CONFLICT (org_id, ref) DO UPDATE SET
3181
+ ciphertext = excluded.ciphertext, connector = excluded.connector,
3182
+ domain = excluded.domain, created_by = excluded.created_by, created_at = excluded.created_at`,
3183
+ )
3184
+ .run(org, rec.ref, rec.ciphertext, rec.connector ?? null, rec.domain ?? null, rec.createdBy, rec.createdAt);
3185
+ },
3186
+
3187
+ async getStoredCredential(org, ref) {
3188
+ const row = getDb()
3189
+ .prepare("SELECT ref, ciphertext, connector, domain, created_by, created_at FROM stored_credential WHERE org_id = ? AND ref = ?")
3190
+ .get(org, ref) as { ref: string; ciphertext: string; connector: string | null; domain: string | null; created_by: string; created_at: string } | undefined;
3191
+ if (!row) return null;
3192
+ return {
3193
+ ref: row.ref,
3194
+ ciphertext: row.ciphertext,
3195
+ ...(row.connector ? { connector: row.connector } : {}),
3196
+ ...(row.domain ? { domain: row.domain } : {}),
3197
+ createdBy: row.created_by,
3198
+ createdAt: row.created_at,
3199
+ };
3200
+ },
3201
+
3202
+ async deleteStoredCredential(org, ref) {
3203
+ // A REAL delete of the ciphertext row (OPE-287) — the self-host twin of the postgres path. See
3204
+ // the store port for why this table retires by destruction rather than by status.
3205
+ return getDb().prepare("DELETE FROM stored_credential WHERE org_id = ? AND ref = ?").run(org, ref).changes > 0;
3206
+ },
3207
+
3208
+ async listStoredCredentialRefs(org, refPrefix) {
3209
+ // REFS ONLY (OPE-349) — the ciphertext column is deliberately not in the projection; see the
3210
+ // store port for why an enumerating caller must never be handed envelopes. `refPrefix` narrows
3211
+ // IN THE PREDICATE (OPE-1025) — the self-host twin of the postgres path, same escaping.
3212
+ if (refPrefix) {
3213
+ const rows = getDb().prepare("SELECT ref FROM stored_credential WHERE org_id = ? AND ref LIKE ? ESCAPE '\\' ORDER BY ref").all(org, likePrefixPattern(refPrefix)) as { ref: string }[];
3214
+ return rows.map((r) => r.ref);
3215
+ }
3216
+ const rows = getDb().prepare("SELECT ref FROM stored_credential WHERE org_id = ? ORDER BY ref").all(org) as { ref: string }[];
3217
+ return rows.map((r) => r.ref);
3218
+ },
3219
+
3220
+ async putGitHubInstallation(org, rec) {
3221
+ getDb()
3222
+ .prepare(
3223
+ `INSERT INTO github_installation (org_id, owner, installation_id, account_type, repository_selection, updated_at)
3224
+ VALUES (?, ?, ?, ?, ?, ?)
3225
+ ON CONFLICT (org_id, owner) DO UPDATE SET installation_id = excluded.installation_id,
3226
+ account_type = excluded.account_type, repository_selection = excluded.repository_selection,
3227
+ updated_at = excluded.updated_at`,
3228
+ )
3229
+ .run(org, rec.owner, rec.installationId, rec.accountType ?? null, rec.repositorySelection ?? null, rec.updatedAt);
3230
+ },
3231
+
3232
+ async deleteGitHubInstallation(org, owner) {
3233
+ return getDb().prepare("DELETE FROM github_installation WHERE org_id = ? AND owner = ?").run(org, owner).changes > 0;
3234
+ },
3235
+
3236
+ async listGitHubInstallations(org) {
3237
+ const rows = getDb()
3238
+ .prepare("SELECT owner, installation_id, account_type, repository_selection, updated_at FROM github_installation WHERE org_id = ? ORDER BY owner ASC")
3239
+ .all(org) as { owner: string; installation_id: string; account_type: string | null; repository_selection: string | null; updated_at: string }[];
3240
+ return rows.map((r) => ({
3241
+ owner: r.owner,
3242
+ installationId: r.installation_id,
3243
+ ...(r.account_type ? { accountType: r.account_type } : {}),
3244
+ ...(r.repository_selection ? { repositorySelection: r.repository_selection } : {}),
3245
+ updatedAt: r.updated_at,
3246
+ }));
3247
+ },
3248
+
3249
+ async claimStoredCredential(org, ref, claimId, claimedAtIso, staleBeforeIso) {
3250
+ // Atomic compare-and-set on the claim columns: win iff the row is free (claim_id NULL) OR the
3251
+ // existing claim's lease is stale (claimed_at <= staleBefore). ISO-8601 compares lexicographically,
3252
+ // so `<=` is a correct time comparison. A single UPDATE ⇒ of two racing claimants exactly one
3253
+ // flips `changes` (the other loses). A missing row updates nothing ⇒ changes=0 ⇒ lost.
3254
+ const info = getDb()
3255
+ .prepare(
3256
+ `UPDATE stored_credential SET claim_id = ?, claimed_at = ?
3257
+ WHERE org_id = ? AND ref = ? AND (claim_id IS NULL OR claimed_at <= ?)`,
3258
+ )
3259
+ .run(claimId, claimedAtIso, org, ref, staleBeforeIso);
3260
+ return info.changes > 0;
3261
+ },
3262
+
3263
+ async releaseStoredCredential(org, ref, claimId) {
3264
+ // Guarded release: clear the claim only if THIS caller still holds it (claim_id matches). A caller
3265
+ // whose lease was stolen mismatches and no-ops — it never clears the new owner's claim.
3266
+ const info = getDb()
3267
+ .prepare("UPDATE stored_credential SET claim_id = NULL, claimed_at = NULL WHERE org_id = ? AND ref = ? AND claim_id = ?")
3268
+ .run(org, ref, claimId);
3269
+ return info.changes > 0;
3270
+ },
3271
+
3272
+ async addCredentialIntake(row) {
3273
+ getDb()
3274
+ .prepare(
3275
+ `INSERT INTO credential_intake (org_id, id, ref, connector, domain, requested_by, channel_id, thread_ts, created_at, expires_at, used_at)
3276
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
3277
+ )
3278
+ .run(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);
3279
+ },
3280
+
3281
+ async getCredentialIntake(org, id) {
3282
+ const row = getDb()
3283
+ .prepare(
3284
+ "SELECT id, ref, connector, domain, requested_by, channel_id, thread_ts, created_at, expires_at, used_at FROM credential_intake WHERE org_id = ? AND id = ?",
3285
+ )
3286
+ .get(org, id) as
3287
+ | { id: string; ref: string; connector: string; domain: string | null; requested_by: string; channel_id: string; thread_ts: string | null; created_at: string; expires_at: string; used_at: string | null }
3288
+ | undefined;
3289
+ if (!row) return null;
3290
+ return {
3291
+ org,
3292
+ id: row.id,
3293
+ ref: row.ref,
3294
+ connector: row.connector,
3295
+ ...(row.domain ? { domain: row.domain } : {}),
3296
+ requestedBy: row.requested_by,
3297
+ channelId: row.channel_id,
3298
+ ...(row.thread_ts ? { threadTs: row.thread_ts } : {}),
3299
+ createdAt: row.created_at,
3300
+ expiresAt: row.expires_at,
3301
+ ...(row.used_at ? { usedAt: row.used_at } : {}),
3302
+ };
3303
+ },
3304
+
3305
+ async armWebhookCaptureWindow(org, hookId, captureUntil, armedBy, at) {
3306
+ // UPSERT on the whole key — re-arming replaces, never accumulates (see the store port).
3307
+ getDb()
3308
+ .prepare(
3309
+ `INSERT INTO webhook_capture_window (org_id, hook_id, capture_until, armed_by, armed_at) VALUES (?, ?, ?, ?, ?)
3310
+ ON CONFLICT (org_id, hook_id) DO UPDATE SET capture_until = excluded.capture_until, armed_by = excluded.armed_by, armed_at = excluded.armed_at`,
3311
+ )
3312
+ .run(org, hookId, captureUntil, armedBy, at);
3313
+ },
3314
+
3315
+ async getWebhookCaptureWindow(org, hookId) {
3316
+ const row = getDb()
3317
+ .prepare("SELECT hook_id, capture_until, armed_by, armed_at FROM webhook_capture_window WHERE org_id = ? AND hook_id = ?")
3318
+ .get(org, hookId) as { hook_id: string; capture_until: string; armed_by: string; armed_at: string } | undefined;
3319
+ // Returned EXPIRED-AND-ALL: closing is the caller's comparison (`captureWindowOpen`).
3320
+ return row ? { hookId: row.hook_id, captureUntil: row.capture_until, armedBy: row.armed_by, armedAt: row.armed_at } : null;
3321
+ },
3322
+
3323
+ async consumeCredentialIntake(org, id, usedAt) {
3324
+ // Single-use CAS: a single UPDATE gated on used_at IS NULL means of two racing submits
3325
+ // exactly one flips `changes` (the other loses and is refused).
3326
+ const info = getDb()
3327
+ .prepare("UPDATE credential_intake SET used_at = ? WHERE org_id = ? AND id = ? AND used_at IS NULL")
3328
+ .run(usedAt, org, id);
3329
+ return info.changes > 0;
3330
+ },
3331
+
3332
+ async addPendingAction(row) {
3333
+ getDb()
3334
+ .prepare(
3335
+ `INSERT INTO pending_actions
3336
+ (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)
3337
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
3338
+ )
3339
+ .run(
3340
+ row.org,
3341
+ row.id,
3342
+ row.kind,
3343
+ row.argsJson,
3344
+ row.scopeKey,
3345
+ row.domain,
3346
+ row.requestedBy,
3347
+ row.channelId,
3348
+ row.threadTs,
3349
+ row.messageTs,
3350
+ row.postedTo,
3351
+ row.status,
3352
+ row.createdAt,
3353
+ row.expiresAt,
3354
+ row.decidedBy,
3355
+ row.decidedAt,
3356
+ );
3357
+ },
3358
+
3359
+ async addPendingActionIfAbsent(row) {
3360
+ // The conflict arm the derived-id wedge needs — see the store interface's note (OPE-1348).
3361
+ const info = getDb()
3362
+ .prepare(
3363
+ `INSERT INTO pending_actions
3364
+ (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)
3365
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
3366
+ ON CONFLICT (org_id, id) DO NOTHING`,
3367
+ )
3368
+ .run(
3369
+ row.org,
3370
+ row.id,
3371
+ row.kind,
3372
+ row.argsJson,
3373
+ row.scopeKey,
3374
+ row.domain,
3375
+ row.requestedBy,
3376
+ row.channelId,
3377
+ row.threadTs,
3378
+ row.messageTs,
3379
+ row.postedTo,
3380
+ row.status,
3381
+ row.createdAt,
3382
+ row.expiresAt,
3383
+ row.decidedBy,
3384
+ row.decidedAt,
3385
+ );
3386
+ return info.changes > 0;
3387
+ },
3388
+
3389
+ async getPendingAction(org, id) {
3390
+ const row = getDb()
3391
+ .prepare(
3392
+ `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
3393
+ FROM pending_actions WHERE org_id = ? AND id = ?`,
3394
+ )
3395
+ .get(org, id) as PendingActionSqlRow | undefined;
3396
+ return row ? pendingActionFromRow(org, row) : null;
3397
+ },
3398
+
3399
+ async listPendingActions(org) {
3400
+ const rows = getDb()
3401
+ .prepare(
3402
+ `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
3403
+ FROM pending_actions WHERE org_id = ? AND status = 'pending' ORDER BY created_at ASC`,
3404
+ )
3405
+ .all(org) as PendingActionSqlRow[];
3406
+ return rows.map((r) => pendingActionFromRow(org, r));
3407
+ },
3408
+
3409
+ async listExpiredPendingActions(org, nowIso) {
3410
+ const rows = getDb()
3411
+ .prepare(
3412
+ `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
3413
+ FROM pending_actions WHERE org_id = ? AND status = 'pending' AND expires_at <= ? ORDER BY created_at ASC`,
3414
+ )
3415
+ .all(org, nowIso) as PendingActionSqlRow[];
3416
+ return rows.map((r) => pendingActionFromRow(org, r));
3417
+ },
3418
+
3419
+ async listRejectedActionsSince(org, sinceIso) {
3420
+ const rows = getDb()
3421
+ .prepare(
3422
+ `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
3423
+ FROM pending_actions WHERE org_id = ? AND status = 'rejected' AND decided_at >= ? ORDER BY decided_at DESC`,
3424
+ )
3425
+ .all(org, sinceIso) as PendingActionSqlRow[];
3426
+ return rows.map((r) => pendingActionFromRow(org, r));
3427
+ },
3428
+
3429
+ async setPendingActionMessage(org, id, messageTs) {
3430
+ getDb().prepare("UPDATE pending_actions SET message_ts = ? WHERE org_id = ? AND id = ?").run(messageTs, org, id);
3431
+ },
3432
+
3433
+ async decidePendingAction(org, id, status, decidedBy, decidedAt) {
3434
+ // The CAS: a single UPDATE gated on status='pending' means of two racing decides
3435
+ // (two clicks, or a click racing a lazy-expiry sweep) exactly one flips `changes`.
3436
+ const info = getDb()
3437
+ .prepare("UPDATE pending_actions SET status = ?, decided_by = ?, decided_at = ? WHERE org_id = ? AND id = ? AND status = 'pending'")
3438
+ .run(status, decidedBy, decidedAt, org, id);
3439
+ return info.changes > 0;
3440
+ },
3441
+
3442
+ async setSessionApproval(row) {
3443
+ const db = getDb();
3444
+ // Prune-on-write: drop this org's expired memos so the table can't grow unboundedly (there is no
3445
+ // sweep — the session_id generation is the real death mechanism, this is just GC).
3446
+ db.prepare("DELETE FROM pr_session_approval WHERE org_id = ? AND expires_at <= ?").run(row.org, row.createdAt);
3447
+ db.prepare(
3448
+ `INSERT INTO pr_session_approval (org_id, session_id, kind, granted_by, created_at, expires_at)
3449
+ VALUES (?, ?, ?, ?, ?, ?)
3450
+ 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`,
3451
+ ).run(row.org, row.sessionId, row.kind, row.grantedBy, row.createdAt, row.expiresAt);
3452
+ },
3453
+
3454
+ async getSessionApproval(org, sessionId, kind, nowIso) {
3455
+ const row = getDb()
3456
+ .prepare("SELECT session_id, kind, granted_by, created_at, expires_at FROM pr_session_approval WHERE org_id = ? AND session_id = ? AND kind = ? AND expires_at > ?")
3457
+ .get(org, sessionId, kind, nowIso) as { session_id: string; kind: string; granted_by: string; created_at: string; expires_at: string } | undefined;
3458
+ if (!row) return null;
3459
+ return { org, sessionId: row.session_id, kind: row.kind, grantedBy: row.granted_by, createdAt: row.created_at, expiresAt: row.expires_at };
3460
+ },
3461
+
3462
+ async listSessionApprovals(org, sessionId, nowIso) {
3463
+ const rows = getDb()
3464
+ .prepare(
3465
+ "SELECT session_id, kind, granted_by, created_at, expires_at FROM pr_session_approval WHERE org_id = ? AND session_id = ? AND expires_at > ? ORDER BY kind ASC",
3466
+ )
3467
+ .all(org, sessionId, nowIso) as { session_id: string; kind: string; granted_by: string; created_at: string; expires_at: string }[];
3468
+ return rows.map((r) => ({ org, sessionId: r.session_id, kind: r.kind, grantedBy: r.granted_by, createdAt: r.created_at, expiresAt: r.expires_at }));
3469
+ },
3470
+
3471
+ async revokeSessionApprovals(org, sessionId) {
3472
+ // `changes` is `number | bigint` on this driver (a BigInt only past 2^53 rows) — normalise.
3473
+ return Number(getDb().prepare("DELETE FROM pr_session_approval WHERE org_id = ? AND session_id = ?").run(org, sessionId).changes);
3474
+ },
3475
+
3476
+ async sweepLegacyConnectorOpRows(org) {
3477
+ // Both prefixes, and no expiry clause — see the port's own comment for why each is required.
3478
+ // The two prefixes are code constants, never caller text, and carry no LIKE metacharacter.
3479
+ return Number(
3480
+ getDb()
3481
+ .prepare("DELETE FROM pr_session_approval WHERE org_id = ? AND session_id LIKE ? AND kind LIKE ?")
3482
+ .run(org, `${ROUTINE_PERMISSION_PREFIX}%`, `${CONNECTOR_OP_KIND_PREFIX}%`).changes,
3483
+ );
3484
+ },
3485
+
3486
+ // The Postgres twin is the reference; these are the same statements in sqlite's placeholder dialect.
3487
+ // status = ANY($n) has no sqlite equivalent, so each CAS spreads its closed status list into an IN list with one placeholder per member.
3488
+
3489
+ async putLinkSet(org, row) {
3490
+ getDb()
3491
+ .prepare(
3492
+ `INSERT INTO identity_link_sets (org_id, id, handle, status, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?)
3493
+ ON CONFLICT(org_id, id) DO UPDATE SET handle = excluded.handle, status = excluded.status, updated_at = excluded.updated_at`,
3494
+ )
3495
+ .run(org, row.id, row.handle, row.status, row.createdAt, row.updatedAt);
3496
+ },
3497
+
3498
+ async getLinkSet(org, id) {
3499
+ const row = getDb().prepare("SELECT id, handle, status, created_at, updated_at FROM identity_link_sets WHERE org_id = ? AND id = ?").get(org, id) as
3500
+ | LinkSetSqliteRow
3501
+ | undefined;
3502
+ return row ? linkSetFromSqliteRow(org, row) : null;
3503
+ },
3504
+
3505
+ async listLinkSets(org) {
3506
+ const rows = getDb().prepare("SELECT id, handle, status, created_at, updated_at FROM identity_link_sets WHERE org_id = ? ORDER BY id ASC").all(org) as LinkSetSqliteRow[];
3507
+ return rows.map((r) => linkSetFromSqliteRow(org, r));
3508
+ },
3509
+
3510
+ async updateLinkSetStatus(org, id, from, to, at) {
3511
+ const changes = getDb()
3512
+ .prepare(`UPDATE identity_link_sets SET status = ?, updated_at = ? WHERE org_id = ? AND id = ? AND status IN (${placeholders(from.length)})`)
3513
+ .run(to, at, org, id, ...from).changes;
3514
+ return Number(changes) > 0;
3515
+ },
3516
+
3517
+ async insertLinkedId(org, row) {
3518
+ // DO NOTHING, never DO UPDATE — the conflict IS the answer (the account already belongs to a
3519
+ // person). See the postgres twin.
3520
+ const changes = getDb()
3521
+ .prepare(
3522
+ `INSERT INTO identity_linked_ids (org_id, platform, tenant, native_id, link_set_id, status, established_by, evidence, created_at, updated_at)
3523
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
3524
+ ON CONFLICT(org_id, platform, tenant, native_id) DO NOTHING`,
3525
+ )
3526
+ .run(org, row.platform, row.tenant, row.nativeId, row.linkSetId, row.status, row.establishedBy, row.evidenceJson ?? null, row.createdAt, row.updatedAt).changes;
3527
+ return Number(changes) > 0;
3528
+ },
3529
+
3530
+ async getLinkedId(org, platform, tenant, nativeId) {
3531
+ const row = getDb()
3532
+ .prepare(`${LINKED_ID_SQLITE_SELECT} WHERE org_id = ? AND platform = ? AND tenant = ? AND native_id = ?`)
3533
+ .get(org, platform, tenant, nativeId) as LinkedIdSqliteRow | undefined;
3534
+ return row ? linkedIdFromSqliteRow(org, row) : null;
3535
+ },
3536
+
3537
+ async listLinkedIds(org, linkSetId) {
3538
+ const sql = `${LINKED_ID_SQLITE_SELECT} WHERE org_id = ?${linkSetId === undefined ? "" : " AND link_set_id = ?"} ORDER BY platform ASC, tenant ASC, native_id ASC`;
3539
+ const rows = (linkSetId === undefined ? getDb().prepare(sql).all(org) : getDb().prepare(sql).all(org, linkSetId)) as LinkedIdSqliteRow[];
3540
+ return rows.map((r) => linkedIdFromSqliteRow(org, r));
3541
+ },
3542
+
3543
+ async updateLinkedIdStatus(org, platform, tenant, nativeId, from, to, establishedBy, evidenceJson, at) {
3544
+ const changes = getDb()
3545
+ .prepare(
3546
+ `UPDATE identity_linked_ids SET status = ?, established_by = ?, evidence = ?, updated_at = ?
3547
+ WHERE org_id = ? AND platform = ? AND tenant = ? AND native_id = ? AND status IN (${placeholders(from.length)})`,
3548
+ )
3549
+ .run(to, establishedBy, evidenceJson ?? null, at, org, platform, tenant, nativeId, ...from).changes;
3550
+ return Number(changes) > 0;
3551
+ },
3552
+
3553
+ async deleteLinkedId(org, platform, tenant, nativeId) {
3554
+ return Number(getDb().prepare("DELETE FROM identity_linked_ids WHERE org_id = ? AND platform = ? AND tenant = ? AND native_id = ?").run(org, platform, tenant, nativeId).changes) > 0;
3555
+ },
3556
+
3557
+ async revokeLinkedIdsForSet(org, linkSetId, at) {
3558
+ return Number(
3559
+ getDb().prepare("UPDATE identity_linked_ids SET status = 'revoked', updated_at = ? WHERE org_id = ? AND link_set_id = ? AND status <> 'revoked'").run(at, org, linkSetId).changes,
3560
+ );
3561
+ },
3562
+
3563
+ async unbackfilledLinkedIdPlatforms() {
3564
+ // Deployment-wide, no org filter — the tenant a row should carry is a fact about the deployment's
3565
+ // channel config, not about an org. See the seam's doc on OperationalStore.
3566
+ const rows = getDb().prepare("SELECT DISTINCT platform FROM identity_linked_ids WHERE tenant = '' ORDER BY platform ASC").all() as { platform: string }[];
3567
+ return rows.map((r) => r.platform);
3568
+ },
3569
+
3570
+ async backfillLinkedIdTenant(platform, tenant, at) {
3571
+ // `tenant = ''` in the predicate is what makes this fill-a-blank-only: a row that already names a
3572
+ // workspace is a delivery's own statement and is never rewritten here.
3573
+ return Number(getDb().prepare("UPDATE identity_linked_ids SET tenant = ?, updated_at = ? WHERE platform = ? AND tenant = ''").run(tenant, at, platform).changes);
3574
+ },
3575
+
3576
+ async addLinkChallenge(org, row) {
3577
+ getDb()
3578
+ .prepare(
3579
+ `INSERT INTO identity_link_challenges
3580
+ (org_id, id, nonce_hash, initiating_platform, initiating_tenant, initiating_native_id, initiating_surface_key,
3581
+ claimed_platform, claimed_tenant, claimed_native_id, claimed_at,
3582
+ transport, target_platform, target_tenant, target_native_id, back_nonce_hash,
3583
+ status, created_at, expires_at, decided_at)
3584
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
3585
+ )
3586
+ .run(
3587
+ org,
3588
+ row.id,
3589
+ row.nonceHash,
3590
+ row.initiatingPlatform,
3591
+ row.initiatingTenant,
3592
+ row.initiatingNativeId,
3593
+ row.initiatingSurfaceKey,
3594
+ row.claimedPlatform ?? null,
3595
+ row.claimedTenant ?? null,
3596
+ row.claimedNativeId ?? null,
3597
+ row.claimedAt ?? null,
3598
+ row.transport,
3599
+ row.targetPlatform ?? null,
3600
+ row.targetTenant ?? null,
3601
+ row.targetNativeId ?? null,
3602
+ row.backNonceHash ?? null,
3603
+ row.status,
3604
+ row.createdAt,
3605
+ row.expiresAt,
3606
+ row.decidedAt ?? null,
3607
+ );
3608
+ },
3609
+
3610
+ async getLinkChallenge(org, id) {
3611
+ const row = getDb().prepare(`${LINK_CHALLENGE_SQLITE_SELECT} WHERE org_id = ? AND id = ?`).get(org, id) as LinkChallengeSqliteRow | undefined;
3612
+ return row ? linkChallengeFromSqliteRow(org, row) : null;
3613
+ },
3614
+
3615
+ async listLinkChallenges(org, filter) {
3616
+ const conjuncts = ["org_id = ?"];
3617
+ const params: string[] = [org];
3618
+ if (filter?.initiatingPlatform !== undefined) {
3619
+ conjuncts.push("initiating_platform = ?");
3620
+ params.push(filter.initiatingPlatform);
3621
+ }
3622
+ if (filter?.initiatingTenant !== undefined) {
3623
+ conjuncts.push("initiating_tenant = ?");
3624
+ params.push(filter.initiatingTenant);
3625
+ }
3626
+ if (filter?.initiatingNativeId !== undefined) {
3627
+ conjuncts.push("initiating_native_id = ?");
3628
+ params.push(filter.initiatingNativeId);
3629
+ }
3630
+ if (filter?.targetPlatform !== undefined) {
3631
+ conjuncts.push("target_platform = ?");
3632
+ params.push(filter.targetPlatform);
3633
+ }
3634
+ if (filter?.targetTenant !== undefined) {
3635
+ conjuncts.push("target_tenant = ?");
3636
+ params.push(filter.targetTenant);
3637
+ }
3638
+ if (filter?.targetNativeId !== undefined) {
3639
+ conjuncts.push("target_native_id = ?");
3640
+ params.push(filter.targetNativeId);
3641
+ }
3642
+ if (filter?.claimedPlatform !== undefined) {
3643
+ conjuncts.push("claimed_platform = ?");
3644
+ params.push(filter.claimedPlatform);
3645
+ }
3646
+ if (filter?.claimedTenant !== undefined) {
3647
+ conjuncts.push("claimed_tenant = ?");
3648
+ params.push(filter.claimedTenant);
3649
+ }
3650
+ if (filter?.claimedNativeId !== undefined) {
3651
+ conjuncts.push("claimed_native_id = ?");
3652
+ params.push(filter.claimedNativeId);
3653
+ }
3654
+ if (filter?.status !== undefined) {
3655
+ conjuncts.push("status = ?");
3656
+ params.push(filter.status);
3657
+ }
3658
+ const rows = getDb()
3659
+ .prepare(`${LINK_CHALLENGE_SQLITE_SELECT} WHERE ${conjuncts.join(" AND ")} ORDER BY created_at DESC`)
3660
+ .all(...params) as LinkChallengeSqliteRow[];
3661
+ return rows.map((r) => linkChallengeFromSqliteRow(org, r));
3662
+ },
3663
+
3664
+ async claimLinkChallenge(org, nonceHash, platform, tenant, nativeId, at, backNonceHash) {
3665
+ // This driver's run has no RETURNING, so the claimed row is read back by id; the UPDATE alone decides the winner, so the read cannot hand a second caller the same claim.
3666
+ // The initiator exclusion is TENANT-QUALIFIED: platform plus native_id alone would treat an id-twin in another workspace as a self-claim and refuse a legitimate one.
3667
+ const db = getDb();
3668
+ const changes = db
3669
+ .prepare(
3670
+ `UPDATE identity_link_challenges SET claimed_platform = ?, claimed_tenant = ?, claimed_native_id = ?, claimed_at = ?, back_nonce_hash = ?, status = 'claimed'
3671
+ WHERE org_id = ? AND nonce_hash = ? AND status = 'pending' AND expires_at > ?
3672
+ AND NOT (initiating_platform = ? AND initiating_tenant = ? AND initiating_native_id = ?)`,
3673
+ )
3674
+ .run(platform, tenant, nativeId, at, backNonceHash ?? null, org, nonceHash, at, platform, tenant, nativeId).changes;
3675
+ if (Number(changes) === 0) return null;
3676
+ const row = db.prepare(`${LINK_CHALLENGE_SQLITE_SELECT} WHERE org_id = ? AND nonce_hash = ? AND claimed_at = ?`).get(org, nonceHash, at) as LinkChallengeSqliteRow | undefined;
3677
+ return row ? linkChallengeFromSqliteRow(org, row) : null;
3678
+ },
3679
+
3680
+ async consentLinkChallenge(org, id, consenter, at, backNonceHash) {
3681
+ // The TARGET MATCH is a conjunct, not a caller-side check (see store.ts's contract): a consent
3682
+ // from any account but the one this challenge named matches no row and returns null. Single-use
3683
+ // rides the same `status = 'pending'` predicate the claim CAS uses, and the TTL rides
3684
+ // `expires_at > at` — all three in one statement, so none can be lost to a race.
3685
+ const db = getDb();
3686
+ const changes = db
3687
+ .prepare(
3688
+ `UPDATE identity_link_challenges SET claimed_platform = ?, claimed_tenant = ?, claimed_native_id = ?, claimed_at = ?, back_nonce_hash = ?, status = 'claimed'
3689
+ WHERE org_id = ? AND id = ? AND status = 'pending' AND expires_at > ?
3690
+ AND target_platform = ? AND target_tenant = ? AND target_native_id = ?`,
3691
+ )
3692
+ .run(consenter.platform, consenter.tenant, consenter.nativeId, at, backNonceHash ?? null, org, id, at, consenter.platform, consenter.tenant, consenter.nativeId).changes;
3693
+ if (Number(changes) === 0) return null;
3694
+ const row = db.prepare(`${LINK_CHALLENGE_SQLITE_SELECT} WHERE org_id = ? AND id = ?`).get(org, id) as LinkChallengeSqliteRow | undefined;
3695
+ return row ? linkChallengeFromSqliteRow(org, row) : null;
3696
+ },
3697
+
3698
+ async decideLinkChallenge(org, id, from, to, at) {
3699
+ // TTL CONJUNCT ON RATIFY (audit finding F7) — the postgres twin's contract on the floor backend:
3700
+ // the terminal `ratified` transition (the one that writes a link) also requires `expires_at > at`
3701
+ // so a claimed-but-expired challenge cannot be ratified without a prior sweep. Deny carries no
3702
+ // TTL conjunct (it writes nothing). TTL lives INSIDE the statement, not in a caller's clock read.
3703
+ const ttlConjunct = to === "ratified" ? " AND expires_at > ?" : "";
3704
+ const args = to === "ratified" ? [to, at, org, id, ...from, at] : [to, at, org, id, ...from];
3705
+ const changes = getDb()
3706
+ .prepare(`UPDATE identity_link_challenges SET status = ?, decided_at = ? WHERE org_id = ? AND id = ? AND status IN (${placeholders(from.length)})${ttlConjunct}`)
3707
+ .run(...args).changes;
3708
+ return Number(changes) > 0;
3709
+ },
3710
+
3711
+ async expireLinkChallenges(org, nowIso) {
3712
+ return Number(
3713
+ getDb()
3714
+ .prepare("UPDATE identity_link_challenges SET status = 'expired', decided_at = ? WHERE org_id = ? AND status IN ('pending', 'claimed') AND expires_at <= ?")
3715
+ .run(nowIso, org, nowIso).changes,
3716
+ );
3717
+ },
3718
+
3719
+ async addCredentialGrantAsk(org, row) {
3720
+ refuseHalfBorrow("credential_grant_ask", row);
3721
+ getDb()
3722
+ .prepare(
3723
+ `INSERT INTO credential_grant_ask
3724
+ (org_id, id, requester_principal_id, owner_principal_id, owner_slug, owner_platform, owner_native_id, connector, verb, resource,
3725
+ mcp_tool, frozen_args, tool_name,
3726
+ 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)
3727
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
3728
+ )
3729
+ .run(
3730
+ org,
3731
+ row.id,
3732
+ row.requesterPrincipalId,
3733
+ row.ownerPrincipalId,
3734
+ row.ownerSlug,
3735
+ row.ownerPlatform,
3736
+ row.ownerNativeId,
3737
+ row.connector,
3738
+ row.verb,
3739
+ row.resource,
3740
+ row.mcpTool ?? null,
3741
+ grantJsonColumn(row.frozenArgs),
3742
+ row.toolName ?? null,
3743
+ row.scopeKey,
3744
+ row.domainScopeKey ?? null,
3745
+ row.purpose,
3746
+ row.requesterTarget ?? null,
3747
+ row.cardSurfaceId ?? null,
3748
+ row.cardMessageId ?? null,
3749
+ row.requestedMode,
3750
+ row.status,
3751
+ row.createdAt,
3752
+ row.expiresAt,
3753
+ row.decidedAt ?? null,
3754
+ row.grantId ?? null,
3755
+ );
3756
+ },
3757
+
3758
+ async setCredentialGrantAskCard(org, id, surfaceId, messageId) {
3759
+ getDb().prepare("UPDATE credential_grant_ask SET card_surface_id = ?, card_message_id = ? WHERE org_id = ? AND id = ?").run(surfaceId, messageId, org, id);
3760
+ },
3761
+
3762
+ async getCredentialGrantAsk(org, id) {
3763
+ const row = getDb().prepare(`${GRANT_ASK_SQLITE_SELECT} WHERE org_id = ? AND id = ?`).get(org, id) as GrantAskSqliteRow | undefined;
3764
+ return row ? grantAskFromSqliteRow(row) : null;
3765
+ },
3766
+
3767
+ async liveCredentialGrantAsk(org, requesterPrincipalId, ownerPrincipalId, verb, resource, nowIso) {
3768
+ // EXPIRY IN THE PREDICATE, never a status check alone: the sweep is a tidy-up, so an unswept
3769
+ // `pending` row past its TTL must read as gone here or a lapsed ask would block a fresh one.
3770
+ const row = getDb()
3771
+ .prepare(
3772
+ `${GRANT_ASK_SQLITE_SELECT}
3773
+ WHERE org_id = ? AND requester_principal_id = ? AND owner_principal_id = ? AND verb = ? AND resource = ?
3774
+ AND status = 'pending' AND expires_at > ?
3775
+ ORDER BY created_at DESC LIMIT 1`,
3776
+ )
3777
+ .get(org, requesterPrincipalId, ownerPrincipalId, verb, resource, nowIso) as GrantAskSqliteRow | undefined;
3778
+ return row ? grantAskFromSqliteRow(row) : null;
3779
+ },
3780
+
3781
+ async approveCredentialGrantAsk(org, id, mode, grantId, at) {
3782
+ // Single-answer + TTL in ONE statement (the claimLinkChallenge discipline). `status = 'pending'`
3783
+ // admits exactly one approval, and `expires_at > at` makes a late click on a scrolled-back card
3784
+ // lose the CAS rather than be caught by a UI state.
3785
+ const db = getDb();
3786
+ const changes = db
3787
+ .prepare(
3788
+ `UPDATE credential_grant_ask SET status = 'approved', requested_mode = ?, grant_id = ?, decided_at = ?
3789
+ WHERE org_id = ? AND id = ? AND status = 'pending' AND expires_at > ?`,
3790
+ )
3791
+ .run(mode, grantId, at, org, id, at).changes;
3792
+ if (Number(changes) === 0) return null;
3793
+ const row = db.prepare(`${GRANT_ASK_SQLITE_SELECT} WHERE org_id = ? AND id = ?`).get(org, id) as GrantAskSqliteRow | undefined;
3794
+ return row ? grantAskFromSqliteRow(row) : null;
3795
+ },
3796
+
3797
+ async decideCredentialGrantAsk(org, id, from, to, at) {
3798
+ const changes = getDb()
3799
+ .prepare(`UPDATE credential_grant_ask SET status = ?, decided_at = ? WHERE org_id = ? AND id = ? AND status IN (${placeholders(from.length)})`)
3800
+ .run(to, at, org, id, ...from).changes;
3801
+ return Number(changes) > 0;
3802
+ },
3803
+
3804
+ async listExpiredCredentialGrantAsks(org, nowIso) {
3805
+ const rows = getDb()
3806
+ .prepare(`${GRANT_ASK_SQLITE_SELECT} WHERE org_id = ? AND status = 'pending' AND expires_at <= ? ORDER BY created_at ASC`)
3807
+ .all(org, nowIso) as GrantAskSqliteRow[];
3808
+ return rows.map(grantAskFromSqliteRow);
3809
+ },
3810
+
3811
+ async pendingCredentialGrantAsksForScope(org, scopeKey, nowIso) {
3812
+ // EXPIRY IN THE PREDICATE, for `liveCredentialGrantAsk`'s reason: the sweep is a tidy-up, so an
3813
+ // unswept `pending` row past its TTL must read as gone or a lapsed ask would hold its name for
3814
+ // ever. The read rides the `(org_id, scope_key)` index the table already carries.
3815
+ const rows = getDb()
3816
+ .prepare(`${GRANT_ASK_SQLITE_SELECT} WHERE org_id = ? AND scope_key = ? AND status = 'pending' AND expires_at > ? ORDER BY created_at ASC`)
3817
+ .all(org, scopeKey, nowIso) as GrantAskSqliteRow[];
3818
+ return rows.map(grantAskFromSqliteRow);
3819
+ },
3820
+
3821
+ async addCredentialGrant(org, row) {
3822
+ refuseHalfBorrow("credential_grant", row);
3823
+ getDb()
3824
+ .prepare(
3825
+ `INSERT INTO credential_grant
3826
+ (org_id, id, ask_id, requester_principal_id, owner_principal_id, owner_slug, connector, verb, resource,
3827
+ mcp_tool, frozen_args, tool_name, input_schema,
3828
+ scope_key, mode, tier, status, purpose, created_at, expires_at, used_at, revoked_at)
3829
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
3830
+ )
3831
+ .run(
3832
+ org,
3833
+ row.id,
3834
+ row.askId,
3835
+ row.requesterPrincipalId,
3836
+ row.ownerPrincipalId,
3837
+ row.ownerSlug,
3838
+ row.connector,
3839
+ row.verb,
3840
+ row.resource,
3841
+ row.mcpTool ?? null,
3842
+ grantJsonColumn(row.frozenArgs),
3843
+ row.toolName ?? null,
3844
+ grantJsonColumn(row.inputSchema),
3845
+ row.scopeKey,
3846
+ row.mode,
3847
+ row.tier,
3848
+ row.status,
3849
+ row.purpose,
3850
+ row.createdAt,
3851
+ row.expiresAt,
3852
+ row.usedAt ?? null,
3853
+ row.revokedAt ?? null,
3854
+ );
3855
+ },
3856
+
3857
+ async getCredentialGrant(org, id) {
3858
+ const row = getDb().prepare(`${GRANT_SQLITE_SELECT} WHERE org_id = ? AND id = ?`).get(org, id) as GrantSqliteRow | undefined;
3859
+ return row ? grantFromSqliteRow(row) : null;
3860
+ },
3861
+
3862
+ async credentialGrantsForScope(org, scopeKey) {
3863
+ // NO status filter, deliberately — the mount projects EXISTENCE and the broker refuses on STATE.
3864
+ // See the store.ts contract for why a status filter here breaks the cold-heal path.
3865
+ const rows = getDb()
3866
+ .prepare(`${GRANT_SQLITE_SELECT} WHERE org_id = ? AND scope_key = ? ORDER BY created_at DESC`)
3867
+ .all(org, scopeKey) as GrantSqliteRow[];
3868
+ return rows.map(grantFromSqliteRow);
3869
+ },
3870
+
3871
+ async liveStandingCredentialGrantsForScope(org, scopeKey, nowIso) {
3872
+ // STATUS, EXPIRY, REVOCATION AND MODE ALL IN THE PREDICATE — a domain-keyed row is read by
3873
+ // sessions that never saw it, so a dead one must not mount there. See the store.ts contract.
3874
+ const rows = getDb()
3875
+ .prepare(
3876
+ `${GRANT_SQLITE_SELECT} WHERE org_id = ? AND scope_key = ? AND mode = 'standing' AND status = 'active'
3877
+ AND expires_at > ? AND revoked_at IS NULL ORDER BY created_at DESC`,
3878
+ )
3879
+ .all(org, scopeKey, nowIso) as GrantSqliteRow[];
3880
+ return rows.map(grantFromSqliteRow);
3881
+ },
3882
+
3883
+ async liveCredentialGrantsForOwner(org, ownerPrincipalId, nowIso) {
3884
+ // STATUS AND EXPIRY BOTH IN THE PREDICATE — the owner may only be offered rows they can still
3885
+ // end. See the store.ts contract for why this filters where `credentialGrantsForScope` must not.
3886
+ const rows = getDb()
3887
+ .prepare(`${GRANT_SQLITE_SELECT} WHERE org_id = ? AND owner_principal_id = ? AND status = 'active' AND expires_at > ? ORDER BY created_at ASC`)
3888
+ .all(org, ownerPrincipalId, nowIso) as GrantSqliteRow[];
3889
+ return rows.map(grantFromSqliteRow);
3890
+ },
3891
+
3892
+ async liveBorrowCredentialGrant(org, ownerPrincipalId, connector, mcpTool, frozenArgsDigest, scopeKey, nowIso) {
3893
+ // THE DIGEST IS COMPARED IN TYPESCRIPT, not in SQL, because it is not a column. The predicate
3894
+ // narrows to the rows that could match — one owner, one connector, one vendor tool, one chat,
3895
+ // still live — and there are at most a handful of those, so the scan is cheap. A digest column
3896
+ // would be a second copy of `frozen_args` that a partial write could put out of step with it.
3897
+ const rows = getDb()
3898
+ .prepare(
3899
+ `${GRANT_SQLITE_SELECT} WHERE org_id = ? AND owner_principal_id = ? AND connector = ? AND mcp_tool = ? AND scope_key = ?
3900
+ AND status = 'active' AND expires_at > ? ORDER BY created_at DESC`,
3901
+ )
3902
+ .all(org, ownerPrincipalId, connector, mcpTool, scopeKey, nowIso) as GrantSqliteRow[];
3903
+ for (const r of rows) {
3904
+ const row = grantFromSqliteRow(r);
3905
+ if (row.frozenArgs !== undefined && grantFrozenArgsDigest(row.frozenArgs) === frozenArgsDigest) return row;
3906
+ }
3907
+ return null;
3908
+ },
3909
+
3910
+ async burnCredentialGrant(org, id, at) {
3911
+ // THE WHOLE OF ONCE-MODE. Both conjuncts are in the statement: `status = 'active'` makes the burn
3912
+ // single-use, `expires_at > at` makes an expired row unspendable without waiting for a sweep.
3913
+ const db = getDb();
3914
+ const changes = db
3915
+ .prepare(`UPDATE credential_grant SET status = 'used', used_at = ? WHERE org_id = ? AND id = ? AND status = 'active' AND expires_at > ?`)
3916
+ .run(at, org, id, at).changes;
3917
+ if (Number(changes) === 0) return null;
3918
+ const row = db.prepare(`${GRANT_SQLITE_SELECT} WHERE org_id = ? AND id = ?`).get(org, id) as GrantSqliteRow | undefined;
3919
+ return row ? grantFromSqliteRow(row) : null;
3920
+ },
3921
+
3922
+ async refundCredentialGrant(org, id, burnedAt) {
3923
+ // `used_at = ?` IS THE CONTROL, not a tidy extra conjunct: it binds the refund to the caller's
3924
+ // OWN burn, so a call that lost the burn race cannot un-spend the winner's. `revoked_at IS NULL`
3925
+ // is what makes an owner's revoke beat a refund racing it — see `revokeCredentialGrant`.
3926
+ const changes = getDb()
3927
+ .prepare(
3928
+ `UPDATE credential_grant SET status = 'active', used_at = NULL
3929
+ WHERE org_id = ? AND id = ? AND status = 'used' AND used_at = ? AND revoked_at IS NULL`,
3930
+ )
3931
+ .run(org, id, burnedAt).changes;
3932
+ return Number(changes) > 0;
3933
+ },
3934
+
3935
+ async claimCredentialGrantRefund(org, id, turnKey, cap) {
3936
+ // ONE STATEMENT, so two calls racing in one step cannot both read the same remaining count. The
3937
+ // right-hand `refund_turn_seq` is the row's PRE-UPDATE value in both engines, so every CASE and
3938
+ // the WHERE read the same stored ordinal.
3939
+ //
3940
+ // 🔴 ONLY A STRICTLY LATER TURN ROLLS (OPE-1281). The predicate is the ORDINAL comparison, not
3941
+ // the key inequality this statement used to carry: an inequality rolls in both directions, so
3942
+ // two turn ids alternating on one row each read the other as new and each collected a fresh
3943
+ // allowance. A NULL ordinal — no turn id, or a key eve's shape no longer mints — never rolls;
3944
+ // it counts against the stored turn and leaves the turn in place, which is the fail-closed
3945
+ // direction.
3946
+ //
3947
+ // 🔴 A ROW THAT HAS COUNTED A TURN AND CARRIES NO ORDINAL NEVER ROLLS EITHER, and that is the
3948
+ // upgrade window rather than a corner. A row written before this column existed holds a turn
3949
+ // key, a count up to `cap`, and a NULL ordinal; reading that NULL as "never counted" would let
3950
+ // ANY turn roll it — the same turn included — which is the hole this ticket closes. So the
3951
+ // first disjunct asks for BOTH columns empty, which is a row that has genuinely counted
3952
+ // nothing. A migrated row keeps the allowance it had for the rest of its life, bounded by the
3953
+ // grant's TTL.
3954
+ const key = turnKey ?? null;
3955
+ const seq = grantRefundTurnOrdinal(turnKey) ?? null;
3956
+ // The roll predicate, spelled once and bound twice per use. Binds below follow the statement's
3957
+ // own order: (seq, seq, key) (seq, seq, seq) (seq, seq) org id (seq, seq) cap.
3958
+ const rolls = "(? IS NOT NULL AND ((refund_turn IS NULL AND refund_turn_seq IS NULL) OR ? > refund_turn_seq))";
3959
+ const changes = getDb()
3960
+ .prepare(
3961
+ `UPDATE credential_grant
3962
+ SET refund_turn = CASE WHEN ${rolls} THEN ? ELSE refund_turn END,
3963
+ refund_turn_seq = CASE WHEN ${rolls} THEN ? ELSE refund_turn_seq END,
3964
+ refund_count = CASE WHEN ${rolls} THEN 1 ELSE COALESCE(refund_count, 0) + 1 END
3965
+ WHERE org_id = ? AND id = ?
3966
+ AND (${rolls} OR COALESCE(refund_count, 0) < ?)`,
3967
+ )
3968
+ .run(seq, seq, key, seq, seq, seq, seq, seq, org, id, seq, seq, cap).changes;
3969
+ return Number(changes) > 0;
3970
+ },
3971
+
3972
+ async revokeCredentialGrant(org, id, at) {
3973
+ const db = getDb();
3974
+ const changes = db
3975
+ .prepare("UPDATE credential_grant SET status = 'revoked', revoked_at = ? WHERE org_id = ? AND id = ? AND status = 'active'")
3976
+ .run(at, org, id).changes;
3977
+ if (Number(changes) > 0) return true;
3978
+ // THE ROW WAS NOT LIVE. If it is `used`, the owner may be racing a once call that is still in
3979
+ // flight: stamp the intent so a refund cannot re-open it (OPE-1198). The STATUS is left alone —
3980
+ // a spent grant is already terminal, and rewriting it would lose which arm ended it. The answer
3981
+ // stays `false`: this call revoked no live grant.
3982
+ db.prepare("UPDATE credential_grant SET revoked_at = ? WHERE org_id = ? AND id = ? AND status = 'used' AND revoked_at IS NULL").run(at, org, id);
3983
+ return false;
3984
+ },
3985
+
3986
+ async expireCredentialGrants(org, nowIso) {
3987
+ return Number(
3988
+ getDb()
3989
+ .prepare("UPDATE credential_grant SET status = 'expired' WHERE org_id = ? AND status = 'active' AND expires_at <= ?")
3990
+ .run(org, nowIso).changes,
3991
+ );
3992
+ },
3993
+
3994
+ async getMeta(key) {
3995
+ const row = getDb().prepare("SELECT value FROM instance_meta WHERE key = ?").get(key) as { value: string } | undefined;
3996
+ return row ? row.value : null;
3997
+ },
3998
+
3999
+ async setMeta(key, value) {
4000
+ getDb()
4001
+ .prepare(
4002
+ `INSERT INTO instance_meta (key, value) VALUES (?, ?)
4003
+ ON CONFLICT(key) DO UPDATE SET value = excluded.value`,
4004
+ )
4005
+ .run(key, value);
4006
+ },
4007
+ };