@treeseed/sdk 0.10.28 → 0.12.4

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 (509) hide show
  1. package/README.md +213 -7
  2. package/dist/agent-capacity.d.ts +916 -0
  3. package/dist/agent-capacity.js +1600 -0
  4. package/dist/agent-tools.d.ts +37 -0
  5. package/dist/agent-tools.js +301 -0
  6. package/dist/api/app.d.ts +1 -1
  7. package/dist/api/auth/d1-database.d.ts +2 -2
  8. package/dist/api/auth/d1-provider.d.ts +4 -4
  9. package/dist/api/auth/d1-store.d.ts +2 -2
  10. package/dist/api/auth/memory-provider.d.ts +1 -1
  11. package/dist/api/auth/tokens.d.ts +1 -1
  12. package/dist/api/config.d.ts +3 -1
  13. package/dist/api/config.js +34 -10
  14. package/dist/api/http.d.ts +2 -2
  15. package/dist/api/index.d.ts +10 -10
  16. package/dist/api/index.js +4 -2
  17. package/dist/api/operations-routes.d.ts +3 -3
  18. package/dist/api/operations.d.ts +1 -1
  19. package/dist/api/providers.d.ts +1 -1
  20. package/dist/api/providers.js +21 -4
  21. package/dist/api/railway.d.ts +3 -2
  22. package/dist/api/sdk-dispatch.d.ts +4 -4
  23. package/dist/api/sdk-routes.d.ts +2 -2
  24. package/dist/api/templates.d.ts +2 -2
  25. package/dist/api/types.d.ts +3 -2
  26. package/dist/capacity-provider.d.ts +118 -59
  27. package/dist/capacity-provider.js +235 -43
  28. package/dist/capacity.d.ts +2 -2
  29. package/dist/cli-tools.d.ts +1 -1
  30. package/dist/content-operations.d.ts +97 -0
  31. package/dist/content-operations.js +250 -0
  32. package/dist/content-store.d.ts +4 -4
  33. package/dist/control-plane-client.d.ts +13 -18
  34. package/dist/control-plane-client.js +8 -86
  35. package/dist/control-plane.d.ts +3 -2
  36. package/dist/control-plane.js +38 -13
  37. package/dist/copilot.d.ts +3 -0
  38. package/dist/copilot.js +16 -1
  39. package/dist/d1-http.d.ts +1 -1
  40. package/dist/d1-store.d.ts +32 -57
  41. package/dist/d1-store.js +115 -318
  42. package/dist/db/d1.d.ts +1 -232
  43. package/dist/db/index.d.ts +3 -3
  44. package/dist/db/market-schema.d.ts +50900 -11018
  45. package/dist/db/market-schema.js +2313 -467
  46. package/dist/db/node-sqlite.d.ts +1 -232
  47. package/dist/db/node-sqlite.js +7 -2
  48. package/dist/db/schema.d.ts +0 -462
  49. package/dist/db/schema.js +2 -22
  50. package/dist/dispatch.d.ts +1 -1
  51. package/dist/dispatch.js +0 -11
  52. package/dist/fixture-support.js +52 -4
  53. package/dist/governance.d.ts +133 -0
  54. package/dist/governance.js +285 -0
  55. package/dist/graph/build.d.ts +2 -2
  56. package/dist/graph/context-query-contracts.d.ts +1 -1
  57. package/dist/graph/dsl.d.ts +1 -1
  58. package/dist/graph/query.d.ts +4 -4
  59. package/dist/graph/ranking.d.ts +1 -1
  60. package/dist/graph/schema.d.ts +1 -1
  61. package/dist/graph.d.ts +11 -11
  62. package/dist/guarantees/index.d.ts +425 -0
  63. package/dist/guarantees/index.js +1146 -0
  64. package/dist/hosting/apps.d.ts +12 -0
  65. package/dist/hosting/apps.js +107 -0
  66. package/dist/hosting/builtins.d.ts +25 -0
  67. package/dist/hosting/builtins.js +602 -0
  68. package/dist/hosting/contracts.d.ts +208 -0
  69. package/dist/hosting/contracts.js +0 -0
  70. package/dist/hosting/graph.d.ts +195 -0
  71. package/dist/hosting/graph.js +1092 -0
  72. package/dist/hosting/index.d.ts +4 -0
  73. package/dist/hosting/index.js +4 -0
  74. package/dist/index.d.ts +88 -67
  75. package/dist/index.js +142 -14
  76. package/dist/local-dev/managed-dev.d.ts +85 -0
  77. package/dist/local-dev/managed-dev.js +368 -0
  78. package/dist/managed-dependencies.d.ts +9 -0
  79. package/dist/managed-dependencies.js +10 -9
  80. package/dist/market-client.d.ts +327 -9
  81. package/dist/market-client.js +464 -20
  82. package/dist/model-registry.d.ts +1 -1
  83. package/dist/model-registry.js +19 -19
  84. package/dist/operations/agent-tools.d.ts +2 -11
  85. package/dist/operations/agent-tools.js +2 -14
  86. package/dist/operations/providers/default.d.ts +1 -1
  87. package/dist/operations/providers/default.js +20 -37
  88. package/dist/operations/repository-operations.d.ts +26 -2
  89. package/dist/operations/repository-operations.js +159 -1
  90. package/dist/operations/runtime.d.ts +3 -3
  91. package/dist/operations/services/bootstrap-runner.d.ts +4 -2
  92. package/dist/operations/services/bootstrap-runner.js +22 -2
  93. package/dist/operations/services/build-warning-policy.d.ts +34 -0
  94. package/dist/operations/services/build-warning-policy.js +81 -82
  95. package/dist/operations/services/commit-message-provider.js +4 -4
  96. package/dist/operations/services/config-runtime.d.ts +83 -24
  97. package/dist/operations/services/config-runtime.js +449 -130
  98. package/dist/operations/services/deploy.d.ts +106 -624
  99. package/dist/operations/services/deploy.js +746 -263
  100. package/dist/operations/services/deployment-readiness.d.ts +30 -0
  101. package/dist/operations/services/deployment-readiness.js +206 -0
  102. package/dist/operations/services/git-remote-policy.js +12 -4
  103. package/dist/operations/services/git-runner.d.ts +66 -0
  104. package/dist/operations/services/git-runner.js +479 -0
  105. package/dist/operations/services/git-workflow.d.ts +45 -6
  106. package/dist/operations/services/git-workflow.js +251 -23
  107. package/dist/operations/services/github-actions-verification.d.ts +4 -1
  108. package/dist/operations/services/github-actions-verification.js +12 -3
  109. package/dist/operations/services/github-api.js +22 -6
  110. package/dist/operations/services/github-automation.d.ts +4 -4
  111. package/dist/operations/services/github-automation.js +19 -21
  112. package/dist/operations/services/github-credentials.d.ts +13 -0
  113. package/dist/operations/services/github-credentials.js +59 -0
  114. package/dist/operations/services/hosted-service-checks.d.ts +81 -0
  115. package/dist/operations/services/hosted-service-checks.js +478 -0
  116. package/dist/operations/services/hosting-audit.d.ts +2 -2
  117. package/dist/operations/services/hosting-audit.js +7 -7
  118. package/dist/operations/services/hub-launch.d.ts +1 -1
  119. package/dist/operations/services/hub-provider-launch.d.ts +5 -5
  120. package/dist/operations/services/hub-provider-launch.js +22 -17
  121. package/dist/operations/services/live-hosted-service-checks.d.ts +26 -0
  122. package/dist/operations/services/live-hosted-service-checks.js +463 -0
  123. package/dist/operations/services/local-dev.js +0 -1
  124. package/dist/operations/services/managed-host-security.d.ts +1 -1
  125. package/dist/operations/services/managed-host-security.js +1 -1
  126. package/dist/operations/services/managed-repositories.d.ts +37 -0
  127. package/dist/operations/services/managed-repositories.js +177 -0
  128. package/dist/operations/services/operations-runner-smoke.d.ts +31 -0
  129. package/dist/operations/services/operations-runner-smoke.js +198 -0
  130. package/dist/operations/services/package-adapters.d.ts +170 -0
  131. package/dist/operations/services/package-adapters.js +859 -0
  132. package/dist/operations/services/package-reference-policy.d.ts +13 -88
  133. package/dist/operations/services/package-reference-policy.js +96 -215
  134. package/dist/operations/services/project-host-operations.d.ts +4 -4
  135. package/dist/operations/services/project-platform.d.ts +57 -173
  136. package/dist/operations/services/project-platform.js +80 -111
  137. package/dist/operations/services/project-web-monitor.d.ts +2 -2
  138. package/dist/operations/services/project-web-monitor.js +122 -5
  139. package/dist/operations/services/railway-api.d.ts +117 -5
  140. package/dist/operations/services/railway-api.js +915 -93
  141. package/dist/operations/services/railway-deploy.d.ts +30 -112
  142. package/dist/operations/services/railway-deploy.js +521 -961
  143. package/dist/operations/services/release-history.js +3 -4
  144. package/dist/operations/services/release-proof-ledger.d.ts +13 -0
  145. package/dist/operations/services/release-proof-ledger.js +81 -0
  146. package/dist/operations/services/release-proof-planner.d.ts +48 -0
  147. package/dist/operations/services/release-proof-planner.js +195 -0
  148. package/dist/operations/services/release-proof-runner.d.ts +16 -0
  149. package/dist/operations/services/release-proof-runner.js +169 -0
  150. package/dist/operations/services/release-proof.d.ts +81 -0
  151. package/dist/operations/services/release-proof.js +79 -0
  152. package/dist/operations/services/repository-save-orchestrator.d.ts +8 -7
  153. package/dist/operations/services/repository-save-orchestrator.js +604 -212
  154. package/dist/operations/services/runtime-paths.d.ts +1 -3
  155. package/dist/operations/services/runtime-paths.js +0 -4
  156. package/dist/operations/services/runtime-tools.d.ts +1 -191
  157. package/dist/operations/services/runtime-tools.js +4 -443
  158. package/dist/operations/services/save-deploy-preflight.js +9 -1
  159. package/dist/operations/services/template-host-bindings.d.ts +2 -2
  160. package/dist/operations/services/template-host-bindings.js +3 -2
  161. package/dist/operations/services/template-registry.d.ts +6 -6
  162. package/dist/operations/services/template-registry.js +33 -14
  163. package/dist/operations/services/template-secret-sync.d.ts +3 -3
  164. package/dist/operations/services/verification-cache.d.ts +25 -0
  165. package/dist/operations/services/verification-cache.js +71 -0
  166. package/dist/operations/services/workflow-timing.d.ts +25 -0
  167. package/dist/operations/services/workflow-timing.js +79 -0
  168. package/dist/operations/services/workspace-dependency-mode.js +50 -5
  169. package/dist/operations/services/workspace-preflight.js +8 -8
  170. package/dist/operations/services/workspace-save-script.d.ts +4 -4
  171. package/dist/operations/services/workspace-save.d.ts +1 -0
  172. package/dist/operations/services/workspace-save.js +42 -19
  173. package/dist/operations/services/workspace-tools.js +42 -7
  174. package/dist/operations-registry.d.ts +1 -1
  175. package/dist/operations-registry.js +5 -6
  176. package/dist/operations-types.d.ts +1 -1
  177. package/dist/operations.d.ts +17 -11
  178. package/dist/operations.js +57 -3
  179. package/dist/platform/book-export.js +2 -0
  180. package/dist/platform/books-data.d.ts +1 -1
  181. package/dist/platform/config.d.ts +27 -0
  182. package/dist/platform/config.js +100 -0
  183. package/dist/platform/content-runtime-source.d.ts +54 -0
  184. package/dist/platform/content-runtime-source.js +169 -0
  185. package/dist/platform/contracts.d.ts +38 -2
  186. package/dist/platform/deploy-config.d.ts +1 -1
  187. package/dist/platform/deploy-config.js +80 -9
  188. package/dist/platform/deploy-runtime.d.ts +1 -1
  189. package/dist/platform/desired-state.d.ts +63 -0
  190. package/dist/platform/desired-state.js +1021 -0
  191. package/dist/platform/env.yaml +568 -45
  192. package/dist/platform/environment.d.ts +3 -2
  193. package/dist/platform/environment.js +122 -21
  194. package/dist/platform/local-content-materialization.d.ts +9 -0
  195. package/dist/platform/local-content-materialization.js +212 -0
  196. package/dist/platform/plugin.d.ts +13 -4
  197. package/dist/platform/plugins/runtime.d.ts +3 -3
  198. package/dist/platform/plugins/runtime.js +62 -1
  199. package/dist/platform/plugins.d.ts +6 -6
  200. package/dist/platform/published-content-pipeline.d.ts +3 -3
  201. package/dist/platform/published-content-pipeline.js +5 -1
  202. package/dist/platform/published-content.d.ts +4 -3
  203. package/dist/platform/site-config-schema.d.ts +1 -0
  204. package/dist/platform/site-config-schema.js +4 -1
  205. package/dist/platform/tenant/runtime-config.d.ts +152 -2
  206. package/dist/platform/tenant-config.d.ts +1 -1
  207. package/dist/platform/utils/site-config-schema.d.ts +154 -0
  208. package/dist/platform/utils/site-config-schema.js +400 -461
  209. package/dist/platform-operation-store.d.ts +1 -1
  210. package/dist/platform-operation-store.js +2 -2
  211. package/dist/platform-operations.js +1 -1
  212. package/dist/plugin-default.d.ts +1 -1
  213. package/dist/plugin-default.js +27 -12
  214. package/dist/project-import.d.ts +91 -0
  215. package/dist/project-import.js +257 -0
  216. package/dist/project-workflow.d.ts +1 -1
  217. package/dist/reconcile/bootstrap-systems.d.ts +2 -2
  218. package/dist/reconcile/bootstrap-systems.js +5 -5
  219. package/dist/reconcile/builtin-adapters.d.ts +7 -1
  220. package/dist/reconcile/builtin-adapters.js +3190 -429
  221. package/dist/reconcile/contracts.d.ts +23 -6
  222. package/dist/reconcile/desired-state.d.ts +2 -192
  223. package/dist/reconcile/desired-state.js +29 -38
  224. package/dist/reconcile/engine.d.ts +61 -395
  225. package/dist/reconcile/engine.js +229 -44
  226. package/dist/reconcile/index.d.ts +10 -8
  227. package/dist/reconcile/index.js +2 -0
  228. package/dist/reconcile/live-acceptance.d.ts +100 -0
  229. package/dist/reconcile/live-acceptance.js +2027 -0
  230. package/dist/reconcile/platform.d.ts +104 -0
  231. package/dist/reconcile/platform.js +100 -0
  232. package/dist/reconcile/providers/docker-private.d.ts +54 -0
  233. package/dist/reconcile/providers/docker-private.js +101 -0
  234. package/dist/reconcile/providers/github-private.d.ts +65 -0
  235. package/dist/reconcile/providers/github-private.js +119 -0
  236. package/dist/reconcile/providers/local-private.d.ts +28 -0
  237. package/dist/reconcile/providers/local-private.js +75 -0
  238. package/dist/reconcile/providers/railway-iac.d.ts +66 -0
  239. package/dist/reconcile/providers/railway-iac.js +275 -0
  240. package/dist/reconcile/providers/release-private.d.ts +92 -0
  241. package/dist/reconcile/providers/release-private.js +152 -0
  242. package/dist/reconcile/registry.d.ts +2 -2
  243. package/dist/reconcile/registry.js +16 -1
  244. package/dist/reconcile/state.d.ts +1 -1
  245. package/dist/reconcile/state.js +7 -44
  246. package/dist/reconcile/units.d.ts +1 -1
  247. package/dist/reconcile/units.js +9 -3
  248. package/dist/remote.d.ts +6 -6
  249. package/dist/scenes/artifacts.d.ts +16 -0
  250. package/dist/scenes/artifacts.js +61 -0
  251. package/dist/scenes/auth.d.ts +2 -0
  252. package/dist/scenes/auth.js +28 -0
  253. package/dist/scenes/base-url.d.ts +12 -0
  254. package/dist/scenes/base-url.js +123 -0
  255. package/dist/scenes/builtin-plugins.d.ts +2 -0
  256. package/dist/scenes/builtin-plugins.js +447 -0
  257. package/dist/scenes/checkpoints.d.ts +14 -0
  258. package/dist/scenes/checkpoints.js +33 -0
  259. package/dist/scenes/device-matrix.d.ts +2 -0
  260. package/dist/scenes/device-matrix.js +97 -0
  261. package/dist/scenes/devices.d.ts +11 -0
  262. package/dist/scenes/devices.js +22 -0
  263. package/dist/scenes/diagnostics.d.ts +5 -0
  264. package/dist/scenes/diagnostics.js +22 -0
  265. package/dist/scenes/diagram-providers.d.ts +2 -0
  266. package/dist/scenes/diagram-providers.js +181 -0
  267. package/dist/scenes/diagram-validation.d.ts +22 -0
  268. package/dist/scenes/diagram-validation.js +74 -0
  269. package/dist/scenes/environment.d.ts +2 -0
  270. package/dist/scenes/environment.js +65 -0
  271. package/dist/scenes/evidence-bundle.d.ts +5 -0
  272. package/dist/scenes/evidence-bundle.js +42 -0
  273. package/dist/scenes/evidence-report.d.ts +10 -0
  274. package/dist/scenes/evidence-report.js +73 -0
  275. package/dist/scenes/evidence.d.ts +16 -0
  276. package/dist/scenes/evidence.js +277 -0
  277. package/dist/scenes/index.d.ts +48 -0
  278. package/dist/scenes/index.js +312 -0
  279. package/dist/scenes/inspect.d.ts +9 -0
  280. package/dist/scenes/inspect.js +64 -0
  281. package/dist/scenes/loader.d.ts +3 -0
  282. package/dist/scenes/loader.js +38 -0
  283. package/dist/scenes/logs.d.ts +2 -0
  284. package/dist/scenes/logs.js +47 -0
  285. package/dist/scenes/operations.d.ts +3 -0
  286. package/dist/scenes/operations.js +128 -0
  287. package/dist/scenes/phase0.d.ts +9 -0
  288. package/dist/scenes/phase0.js +637 -0
  289. package/dist/scenes/planner.d.ts +12 -0
  290. package/dist/scenes/planner.js +166 -0
  291. package/dist/scenes/playwright-adapter.d.ts +2 -0
  292. package/dist/scenes/playwright-adapter.js +63 -0
  293. package/dist/scenes/plugins.d.ts +5 -0
  294. package/dist/scenes/plugins.js +115 -0
  295. package/dist/scenes/progress.d.ts +17 -0
  296. package/dist/scenes/progress.js +24 -0
  297. package/dist/scenes/publish-destinations.d.ts +12 -0
  298. package/dist/scenes/publish-destinations.js +99 -0
  299. package/dist/scenes/publish-plan-report.d.ts +10 -0
  300. package/dist/scenes/publish-plan-report.js +70 -0
  301. package/dist/scenes/publish-plan.d.ts +15 -0
  302. package/dist/scenes/publish-plan.js +248 -0
  303. package/dist/scenes/publish-redaction.d.ts +16 -0
  304. package/dist/scenes/publish-redaction.js +148 -0
  305. package/dist/scenes/publish-release-record.d.ts +13 -0
  306. package/dist/scenes/publish-release-record.js +34 -0
  307. package/dist/scenes/publish-report.d.ts +10 -0
  308. package/dist/scenes/publish-report.js +67 -0
  309. package/dist/scenes/publish.d.ts +16 -0
  310. package/dist/scenes/publish.js +298 -0
  311. package/dist/scenes/registry.d.ts +12 -0
  312. package/dist/scenes/registry.js +65 -0
  313. package/dist/scenes/remotion-adapter.d.ts +3 -0
  314. package/dist/scenes/remotion-adapter.js +94 -0
  315. package/dist/scenes/remotion-composition-registry.d.ts +2 -0
  316. package/dist/scenes/remotion-composition-registry.js +12 -0
  317. package/dist/scenes/remotion-compositions.d.ts +15 -0
  318. package/dist/scenes/remotion-compositions.js +464 -0
  319. package/dist/scenes/remotion-diagrams.d.ts +9 -0
  320. package/dist/scenes/remotion-diagrams.js +188 -0
  321. package/dist/scenes/remotion-input.d.ts +13 -0
  322. package/dist/scenes/remotion-input.js +291 -0
  323. package/dist/scenes/remotion-visuals.d.ts +29 -0
  324. package/dist/scenes/remotion-visuals.js +198 -0
  325. package/dist/scenes/render-media-assets.d.ts +9 -0
  326. package/dist/scenes/render-media-assets.js +117 -0
  327. package/dist/scenes/render-report.d.ts +10 -0
  328. package/dist/scenes/render-report.js +27 -0
  329. package/dist/scenes/render.d.ts +2 -0
  330. package/dist/scenes/render.js +218 -0
  331. package/dist/scenes/reporter.d.ts +3 -0
  332. package/dist/scenes/reporter.js +101 -0
  333. package/dist/scenes/resume.d.ts +2 -0
  334. package/dist/scenes/resume.js +79 -0
  335. package/dist/scenes/runner.d.ts +2 -0
  336. package/dist/scenes/runner.js +674 -0
  337. package/dist/scenes/schema.d.ts +6 -0
  338. package/dist/scenes/schema.js +994 -0
  339. package/dist/scenes/seed.d.ts +2 -0
  340. package/dist/scenes/seed.js +83 -0
  341. package/dist/scenes/segments.d.ts +15 -0
  342. package/dist/scenes/segments.js +79 -0
  343. package/dist/scenes/selectors.d.ts +3 -0
  344. package/dist/scenes/selectors.js +21 -0
  345. package/dist/scenes/timeline.d.ts +11 -0
  346. package/dist/scenes/timeline.js +26 -0
  347. package/dist/scenes/timeouts.d.ts +6 -0
  348. package/dist/scenes/timeouts.js +17 -0
  349. package/dist/scenes/training-captions.d.ts +14 -0
  350. package/dist/scenes/training-captions.js +98 -0
  351. package/dist/scenes/training-report.d.ts +10 -0
  352. package/dist/scenes/training-report.js +78 -0
  353. package/dist/scenes/training-transcript.d.ts +24 -0
  354. package/dist/scenes/training-transcript.js +204 -0
  355. package/dist/scenes/training.d.ts +10 -0
  356. package/dist/scenes/training.js +134 -0
  357. package/dist/scenes/types.d.ts +1872 -0
  358. package/dist/scenes/types.js +8 -0
  359. package/dist/scenes/visual-audit-contact-sheets.d.ts +6 -0
  360. package/dist/scenes/visual-audit-contact-sheets.js +119 -0
  361. package/dist/scenes/visual-audit-fixtures.d.ts +25 -0
  362. package/dist/scenes/visual-audit-fixtures.js +210 -0
  363. package/dist/scenes/visual-audit-report.d.ts +11 -0
  364. package/dist/scenes/visual-audit-report.js +85 -0
  365. package/dist/scenes/visual-audit-review.d.ts +23 -0
  366. package/dist/scenes/visual-audit-review.js +829 -0
  367. package/dist/scenes/visual-audit-routes.d.ts +13 -0
  368. package/dist/scenes/visual-audit-routes.js +308 -0
  369. package/dist/scenes/visual-audit.d.ts +3 -0
  370. package/dist/scenes/visual-audit.js +596 -0
  371. package/dist/scripts/build-dist.js +154 -40
  372. package/dist/scripts/check-build-warnings.js +42 -53
  373. package/dist/scripts/cleanup-markdown.js +1 -1
  374. package/dist/scripts/cli-test-fixtures.js +24 -28
  375. package/dist/scripts/deployment-readiness.js +20 -0
  376. package/dist/scripts/generate-treedx-openapi-types.js +186 -0
  377. package/dist/scripts/migrate-journey-csv-to-guarantees.js +140 -0
  378. package/dist/scripts/operations-runner-smoke.js +16 -0
  379. package/dist/scripts/package-tools.js +12 -1
  380. package/dist/scripts/prepare.js +3 -7
  381. package/dist/scripts/release-verify.js +6 -6
  382. package/dist/scripts/run-fixture-astro-command.js +1 -1
  383. package/dist/scripts/template-catalog.test.js +68 -82
  384. package/dist/scripts/tenant-dev.js +0 -10
  385. package/dist/scripts/tenant-workflow-action.js +10 -1
  386. package/dist/scripts/test-cloudflare-local.js +1 -1
  387. package/dist/scripts/test-scaffold.js +0 -1
  388. package/dist/scripts/test-smoke.js +3 -3
  389. package/dist/scripts/treeseed-build-dist.js +4 -7
  390. package/dist/scripts/treeseed-release-verify.js +1 -1
  391. package/dist/scripts/verify-driver.js +30 -21
  392. package/dist/scripts/workflow-commands.test.js +18 -27
  393. package/dist/scripts/workspace-command-e2e.js +1 -1
  394. package/dist/scripts/workspace-lint.js +6 -0
  395. package/dist/scripts/workspace-release-test.js +90 -1
  396. package/dist/scripts/workspace-test.js +6 -0
  397. package/dist/sdk-dispatch.d.ts +1 -1
  398. package/dist/sdk-dispatch.js +0 -16
  399. package/dist/sdk-fields.d.ts +1 -1
  400. package/dist/sdk-filters.d.ts +1 -1
  401. package/dist/sdk-types.d.ts +1352 -116
  402. package/dist/sdk-types.js +413 -2
  403. package/dist/sdk.d.ts +106 -100
  404. package/dist/sdk.js +211 -51
  405. package/dist/secrets-capability.d.ts +421 -0
  406. package/dist/secrets-capability.js +530 -0
  407. package/dist/seeds/normalize.js +1 -0
  408. package/dist/seeds/planner.js +38 -0
  409. package/dist/seeds/schema.js +293 -4
  410. package/dist/seeds/types.d.ts +60 -0
  411. package/dist/seeds/types.js +9 -1
  412. package/dist/service-credentials.d.ts +54 -0
  413. package/dist/service-credentials.js +112 -0
  414. package/dist/stores/cursor-store.d.ts +2 -2
  415. package/dist/stores/envelopes.d.ts +1 -1
  416. package/dist/stores/helpers.d.ts +1 -1
  417. package/dist/stores/lease-store.d.ts +2 -2
  418. package/dist/stores/message-store.d.ts +2 -2
  419. package/dist/stores/operational-store.d.ts +3 -26
  420. package/dist/stores/operational-store.js +0 -225
  421. package/dist/stores/project-workflow-store.d.ts +2 -2
  422. package/dist/stores/run-store.d.ts +2 -3
  423. package/dist/stores/run-store.js +0 -98
  424. package/dist/stores/subscription-store.d.ts +2 -3
  425. package/dist/stores/subscription-store.js +0 -100
  426. package/dist/template-catalog.d.ts +1 -1
  427. package/dist/template-launch-requirements.d.ts +2 -2
  428. package/dist/template-launch-requirements.js +9 -0
  429. package/dist/template-launch-ui.d.ts +2 -2
  430. package/dist/treedx/adapters.d.ts +6 -0
  431. package/dist/treedx/adapters.js +36 -0
  432. package/dist/treedx/client.d.ts +222 -0
  433. package/dist/treedx/client.js +871 -0
  434. package/dist/treedx/errors.d.ts +13 -0
  435. package/dist/treedx/errors.js +17 -0
  436. package/dist/treedx/federated-client.d.ts +27 -0
  437. package/dist/treedx/federated-client.js +158 -0
  438. package/dist/treedx/generated/openapi-types.d.ts +3558 -0
  439. package/dist/treedx/generated/openapi-types.js +0 -0
  440. package/dist/treedx/graph-adapter.d.ts +33 -0
  441. package/dist/treedx/graph-adapter.js +156 -0
  442. package/dist/treedx/index.d.ts +14 -0
  443. package/dist/treedx/index.js +48 -0
  444. package/dist/treedx/market-integration.d.ts +27 -0
  445. package/dist/treedx/market-integration.js +131 -0
  446. package/dist/treedx/ports.d.ts +166 -0
  447. package/dist/treedx/ports.js +231 -0
  448. package/dist/treedx/query-adapter.d.ts +19 -0
  449. package/dist/treedx/query-adapter.js +62 -0
  450. package/dist/treedx/registry-client.d.ts +11 -0
  451. package/dist/treedx/registry-client.js +19 -0
  452. package/dist/treedx/repository-adapter.d.ts +45 -0
  453. package/dist/treedx/repository-adapter.js +319 -0
  454. package/dist/treedx/sdk-integration.d.ts +27 -0
  455. package/dist/treedx/sdk-integration.js +63 -0
  456. package/dist/treedx/types.d.ts +1084 -0
  457. package/dist/treedx/types.js +8 -0
  458. package/dist/treedx/workspace-adapter.d.ts +27 -0
  459. package/dist/treedx/workspace-adapter.js +65 -0
  460. package/dist/treedx-backends.d.ts +220 -0
  461. package/dist/treedx-backends.js +634 -0
  462. package/dist/treedx-client.d.ts +89 -0
  463. package/dist/treedx-client.js +184 -0
  464. package/dist/treeseed/services/compose.yml +2 -3
  465. package/dist/treeseed/template-catalog/catalog.fixture.json +27 -27
  466. package/dist/types/agents.d.ts +256 -0
  467. package/dist/types/agents.js +42 -1
  468. package/dist/verification.d.ts +1 -0
  469. package/dist/verification.js +143 -14
  470. package/dist/workflow/operations.d.ts +580 -523
  471. package/dist/workflow/operations.js +2084 -1279
  472. package/dist/workflow/policy.js +19 -7
  473. package/dist/workflow/runs.d.ts +9 -3
  474. package/dist/workflow/runs.js +66 -26
  475. package/dist/workflow/session.d.ts +4 -1
  476. package/dist/workflow/session.js +50 -10
  477. package/dist/workflow/worktrees.d.ts +6 -2
  478. package/dist/workflow/worktrees.js +98 -15
  479. package/dist/workflow-state.d.ts +17 -4
  480. package/dist/workflow-state.js +68 -41
  481. package/dist/workflow-support.d.ts +26 -17
  482. package/dist/workflow-support.js +84 -24
  483. package/dist/workflow.d.ts +51 -16
  484. package/dist/workflow.js +19 -7
  485. package/drizzle/d1/0000_treeseed_d1.sql +0 -18
  486. package/drizzle/market/0000_market_control_plane.sql +1793 -1499
  487. package/drizzle/market/0004_treedx_market_integration.sql +99 -0
  488. package/drizzle/market/0005_agent_capacity_coordination.sql +145 -0
  489. package/drizzle/market/0006_provider_assignment_lifecycle.sql +9 -0
  490. package/drizzle/market/0007_agent_architecture_gap_closure.sql +157 -0
  491. package/drizzle/market/0008_agent_capacity_operational_closure.sql +27 -0
  492. package/drizzle/market/0009_agent_capacity_runtime_hardening.sql +29 -0
  493. package/drizzle/market/0010_secrets_capability_persistence.sql +130 -0
  494. package/drizzle/market/0011_github_app_adapter.sql +47 -0
  495. package/drizzle/market/0012_workday_test_runs.sql +44 -0
  496. package/drizzle/market/0013_runtime_task_lifecycle.sql +39 -0
  497. package/drizzle/market/0014_governance_pipeline.sql +189 -0
  498. package/package.json +106 -18
  499. package/scripts/{verify-driver.mjs → verify-driver.ts} +19 -4
  500. package/templates/github/deploy-web.workflow.yml +49 -12
  501. package/dist/operations/services/mailpit-runtime.d.ts +0 -20
  502. package/dist/operations/services/mailpit-runtime.js +0 -67
  503. package/dist/operations/services/release-candidate.d.ts +0 -41
  504. package/dist/operations/services/release-candidate.js +0 -616
  505. package/dist/scripts/ensure-mailpit.js +0 -48
  506. package/dist/scripts/logs-mailpit.js +0 -2
  507. package/dist/scripts/run-ts.js +0 -45
  508. package/dist/scripts/stop-mailpit.js +0 -5
  509. package/dist/scripts/treeseed-run-ts.js +0 -45
@@ -40,50 +40,46 @@ const workDays = pgTable("work_days", {
40
40
  createdAt: text("created_at").notNull(),
41
41
  updatedAt: text("updated_at").notNull()
42
42
  });
43
- const tasks = pgTable("tasks", {
43
+ const runtimeTasks = pgTable("runtime_tasks", {
44
44
  id: text("id").primaryKey(),
45
+ projectId: text("project_id").notNull(),
45
46
  workDayId: text("work_day_id").notNull(),
46
47
  agentId: text("agent_id").notNull(),
47
- typeColumn: text("type").notNull(),
48
- state: text("state").notNull(),
49
- priority: integer("priority").notNull().default(0),
48
+ type: text("type").notNull(),
50
49
  idempotencyKey: text("idempotency_key").notNull().unique(),
51
50
  payloadJson: text("payload_json").notNull(),
52
- payloadHash: text("payload_hash"),
53
- attemptCount: integer("attempt_count").notNull().default(0),
54
- maxAttempts: integer("max_attempts").notNull().default(3),
51
+ state: text("state").notNull(),
55
52
  claimedBy: text("claimed_by"),
53
+ claimedAt: text("claimed_at"),
56
54
  leaseExpiresAt: text("lease_expires_at"),
57
- availableAt: text("available_at").notNull(),
58
- lastErrorCode: text("last_error_code"),
59
- lastErrorMessage: text("last_error_message"),
60
- graphVersion: text("graph_version"),
61
- parentTaskId: text("parent_task_id"),
55
+ attempts: integer("attempts").notNull().default(0),
62
56
  createdAt: text("created_at").notNull(),
63
- startedAt: text("started_at"),
64
- completedAt: text("completed_at"),
65
57
  updatedAt: text("updated_at").notNull()
66
58
  }, (table) => [
67
- index("idx_tasks_runnable").on(table.state, table.priority, table.availableAt),
68
- index("idx_tasks_work_day_agent").on(table.workDayId, table.agentId, table.createdAt)
59
+ index("idx_runtime_tasks_project_workday_state").on(table.projectId, table.workDayId, table.state, table.createdAt)
69
60
  ]);
70
- const taskEvents = pgTable("task_events", {
61
+ const runtimeTaskEvents = pgTable("runtime_task_events", {
71
62
  id: text("id").primaryKey(),
72
63
  taskId: text("task_id").notNull(),
73
- seq: integer("seq").notNull(),
74
64
  kind: text("kind").notNull(),
75
65
  dataJson: text("data_json").notNull(),
66
+ actor: text("actor"),
76
67
  createdAt: text("created_at").notNull()
77
68
  }, (table) => [
78
- uniqueIndex("idx_task_events_seq").on(table.taskId, table.seq)
69
+ index("idx_runtime_task_events_task_created").on(table.taskId, table.createdAt)
79
70
  ]);
80
- const taskOutputs = pgTable("task_outputs", {
71
+ const runtimeTaskOutputs = pgTable("runtime_task_outputs", {
81
72
  id: text("id").primaryKey(),
82
73
  taskId: text("task_id").notNull(),
83
74
  outputJson: text("output_json").notNull(),
84
75
  outputRef: text("output_ref"),
85
- createdAt: text("created_at").notNull()
86
- });
76
+ summaryJson: text("summary_json"),
77
+ actor: text("actor"),
78
+ createdAt: text("created_at").notNull(),
79
+ updatedAt: text("updated_at").notNull()
80
+ }, (table) => [
81
+ index("idx_runtime_task_outputs_task_created").on(table.taskId, table.createdAt)
82
+ ]);
87
83
  const graphRuns = pgTable("graph_runs", {
88
84
  id: text("id").primaryKey(),
89
85
  workDayId: text("work_day_id").notNull(),
@@ -294,6 +290,360 @@ const webSessions = pgTable("web_sessions", {
294
290
  }, (table) => [
295
291
  index("idx_web_sessions_user_id").on(table.userId)
296
292
  ]);
293
+ const commonsParticipants = pgTable("commons_participants", {
294
+ id: text("id").primaryKey(),
295
+ userId: text("user_id").notNull(),
296
+ teamId: text("team_id").notNull(),
297
+ status: text("status").notNull().default("active"),
298
+ displayName: text("display_name"),
299
+ verifiedEmail: integer("verified_email").notNull().default(0),
300
+ baseWeight: real("base_weight").notNull().default(1),
301
+ trustWeight: real("trust_weight").notNull().default(0),
302
+ contributionWeight: real("contribution_weight").notNull().default(0),
303
+ stakeholderWeight: real("stakeholder_weight").notNull().default(0),
304
+ delegatedWeight: real("delegated_weight").notNull().default(0),
305
+ totalWeight: real("total_weight").notNull().default(1),
306
+ metadataJson: text("metadata_json").notNull().default("{}"),
307
+ createdAt: text("created_at").notNull(),
308
+ updatedAt: text("updated_at").notNull()
309
+ }, (table) => [
310
+ uniqueIndex("idx_commons_participants_user").on(table.userId),
311
+ index("idx_commons_participants_team_status").on(table.teamId, table.status, table.updatedAt)
312
+ ]);
313
+ const commonsQuestions = pgTable("commons_questions", {
314
+ id: text("id").primaryKey(),
315
+ participantId: text("participant_id").notNull(),
316
+ userId: text("user_id").notNull(),
317
+ teamId: text("team_id").notNull(),
318
+ status: text("status").notNull().default("open"),
319
+ title: text("title").notNull(),
320
+ body: text("body").notNull(),
321
+ answer: text("answer"),
322
+ convertedProposalId: text("converted_proposal_id"),
323
+ metadataJson: text("metadata_json").notNull().default("{}"),
324
+ createdAt: text("created_at").notNull(),
325
+ updatedAt: text("updated_at").notNull()
326
+ }, (table) => [
327
+ index("idx_commons_questions_status").on(table.status, table.updatedAt),
328
+ index("idx_commons_questions_participant").on(table.participantId, table.status, table.updatedAt)
329
+ ]);
330
+ const commonsProposals = pgTable("commons_proposals", {
331
+ id: text("id").primaryKey(),
332
+ participantId: text("participant_id").notNull(),
333
+ userId: text("user_id").notNull(),
334
+ teamId: text("team_id").notNull(),
335
+ status: text("status").notNull().default("draft"),
336
+ title: text("title").notNull(),
337
+ summary: text("summary").notNull(),
338
+ body: text("body").notNull(),
339
+ scope: text("scope").notNull().default("treeseed_commons"),
340
+ decisionType: text("decision_type").notNull().default("advisory"),
341
+ contentProposalSlug: text("content_proposal_slug"),
342
+ contentDecisionSlug: text("content_decision_slug"),
343
+ backingCount: integer("backing_count").notNull().default(0),
344
+ voteSupportWeight: real("vote_support_weight").notNull().default(0),
345
+ voteObjectWeight: real("vote_object_weight").notNull().default(0),
346
+ voteAbstainWeight: real("vote_abstain_weight").notNull().default(0),
347
+ qualifiedAt: text("qualified_at"),
348
+ votingStartsAt: text("voting_starts_at"),
349
+ votingEndsAt: text("voting_ends_at"),
350
+ stewardDecisionAt: text("steward_decision_at"),
351
+ stewardDecisionBy: text("steward_decision_by"),
352
+ metadataJson: text("metadata_json").notNull().default("{}"),
353
+ createdAt: text("created_at").notNull(),
354
+ updatedAt: text("updated_at").notNull()
355
+ }, (table) => [
356
+ index("idx_commons_proposals_status").on(table.status, table.updatedAt),
357
+ index("idx_commons_proposals_participant").on(table.participantId, table.status, table.updatedAt),
358
+ index("idx_commons_proposals_scope").on(table.scope, table.status, table.updatedAt)
359
+ ]);
360
+ const commonsWeightSnapshots = pgTable("commons_weight_snapshots", {
361
+ id: text("id").primaryKey(),
362
+ participantId: text("participant_id").notNull(),
363
+ policyVersion: text("policy_version").notNull(),
364
+ baseWeight: real("base_weight").notNull().default(1),
365
+ verifiedEmailWeight: real("verified_email_weight").notNull().default(0),
366
+ accountAgeWeight: real("account_age_weight").notNull().default(0),
367
+ contributionWeight: real("contribution_weight").notNull().default(0),
368
+ stakeholderWeight: real("stakeholder_weight").notNull().default(0),
369
+ trustRoleWeight: real("trust_role_weight").notNull().default(0),
370
+ delegatedWeight: real("delegated_weight").notNull().default(0),
371
+ totalWeight: real("total_weight").notNull().default(1),
372
+ evidenceJson: text("evidence_json").notNull().default("{}"),
373
+ createdAt: text("created_at").notNull()
374
+ }, (table) => [
375
+ index("idx_commons_weight_snapshots_participant").on(table.participantId, table.createdAt)
376
+ ]);
377
+ const commonsProposalBackings = pgTable("commons_proposal_backings", {
378
+ id: text("id").primaryKey(),
379
+ proposalId: text("proposal_id").notNull(),
380
+ participantId: text("participant_id").notNull(),
381
+ userId: text("user_id").notNull(),
382
+ weightSnapshotId: text("weight_snapshot_id").notNull(),
383
+ weight: real("weight").notNull(),
384
+ reason: text("reason"),
385
+ createdAt: text("created_at").notNull()
386
+ }, (table) => [
387
+ uniqueIndex("idx_commons_proposal_backings_once").on(table.proposalId, table.participantId),
388
+ index("idx_commons_proposal_backings_proposal").on(table.proposalId, table.createdAt)
389
+ ]);
390
+ const commonsProposalVotes = pgTable("commons_proposal_votes", {
391
+ id: text("id").primaryKey(),
392
+ proposalId: text("proposal_id").notNull(),
393
+ participantId: text("participant_id").notNull(),
394
+ userId: text("user_id").notNull(),
395
+ vote: text("vote").notNull(),
396
+ weightSnapshotId: text("weight_snapshot_id").notNull(),
397
+ weight: real("weight").notNull(),
398
+ reason: text("reason"),
399
+ createdAt: text("created_at").notNull(),
400
+ updatedAt: text("updated_at").notNull()
401
+ }, (table) => [
402
+ uniqueIndex("idx_commons_proposal_votes_once").on(table.proposalId, table.participantId),
403
+ index("idx_commons_proposal_votes_proposal").on(table.proposalId, table.vote, table.updatedAt)
404
+ ]);
405
+ const commonsDelegations = pgTable("commons_delegations", {
406
+ id: text("id").primaryKey(),
407
+ fromParticipantId: text("from_participant_id").notNull(),
408
+ toParticipantId: text("to_participant_id").notNull(),
409
+ scope: text("scope").notNull().default("treeseed_commons"),
410
+ status: text("status").notNull().default("active"),
411
+ weightLimit: real("weight_limit"),
412
+ reason: text("reason"),
413
+ createdAt: text("created_at").notNull(),
414
+ revokedAt: text("revoked_at")
415
+ }, (table) => [
416
+ uniqueIndex("idx_commons_delegations_active").on(table.fromParticipantId, table.toParticipantId, table.scope, table.status),
417
+ index("idx_commons_delegations_to").on(table.toParticipantId, table.status)
418
+ ]);
419
+ const commonsDecisions = pgTable("commons_decisions", {
420
+ id: text("id").primaryKey(),
421
+ proposalId: text("proposal_id").notNull(),
422
+ status: text("status").notNull().default("proposed"),
423
+ decisionRecordId: text("decision_record_id"),
424
+ decisionRecordSlug: text("decision_record_slug"),
425
+ title: text("title").notNull(),
426
+ summary: text("summary").notNull(),
427
+ stewardReason: text("steward_reason"),
428
+ capacityBudget: text("capacity_budget"),
429
+ scheduledFor: text("scheduled_for"),
430
+ implementedAt: text("implemented_at"),
431
+ metadataJson: text("metadata_json").notNull().default("{}"),
432
+ createdAt: text("created_at").notNull(),
433
+ updatedAt: text("updated_at").notNull()
434
+ }, (table) => [
435
+ uniqueIndex("idx_commons_decisions_proposal").on(table.proposalId),
436
+ index("idx_commons_decisions_status").on(table.status, table.updatedAt)
437
+ ]);
438
+ const commonsGovernanceEvents = pgTable("commons_governance_events", {
439
+ id: text("id").primaryKey(),
440
+ eventType: text("event_type").notNull(),
441
+ actorType: text("actor_type").notNull().default("system"),
442
+ actorId: text("actor_id"),
443
+ participantId: text("participant_id"),
444
+ proposalId: text("proposal_id"),
445
+ questionId: text("question_id"),
446
+ decisionId: text("decision_id"),
447
+ priorState: text("prior_state"),
448
+ nextState: text("next_state"),
449
+ message: text("message"),
450
+ evidenceJson: text("evidence_json").notNull().default("{}"),
451
+ createdAt: text("created_at").notNull()
452
+ }, (table) => [
453
+ index("idx_commons_governance_events_proposal").on(table.proposalId, table.createdAt),
454
+ index("idx_commons_governance_events_participant").on(table.participantId, table.createdAt),
455
+ index("idx_commons_governance_events_type").on(table.eventType, table.createdAt)
456
+ ]);
457
+ const teamGovernancePolicies = pgTable("team_governance_policies", {
458
+ id: text("id").primaryKey(),
459
+ teamId: text("team_id").notNull(),
460
+ scope: text("scope").notNull().default("team"),
461
+ providerId: text("provider_id").notNull(),
462
+ providerVersion: text("provider_version").notNull().default("1"),
463
+ configJson: text("config_json").notNull().default("{}"),
464
+ active: integer("active").notNull().default(1),
465
+ createdBy: text("created_by"),
466
+ createdAt: text("created_at").notNull(),
467
+ updatedAt: text("updated_at").notNull(),
468
+ supersededAt: text("superseded_at")
469
+ }, (table) => [
470
+ index("idx_team_governance_policies_team_scope").on(table.teamId, table.scope, table.active)
471
+ ]);
472
+ const projectGovernancePolicies = pgTable("project_governance_policies", {
473
+ id: text("id").primaryKey(),
474
+ teamId: text("team_id").notNull(),
475
+ projectId: text("project_id").notNull(),
476
+ providerId: text("provider_id").notNull(),
477
+ providerVersion: text("provider_version").notNull().default("1"),
478
+ configJson: text("config_json").notNull().default("{}"),
479
+ active: integer("active").notNull().default(1),
480
+ createdBy: text("created_by"),
481
+ createdAt: text("created_at").notNull(),
482
+ updatedAt: text("updated_at").notNull(),
483
+ supersededAt: text("superseded_at")
484
+ }, (table) => [
485
+ index("idx_project_governance_policies_project").on(table.projectId, table.active)
486
+ ]);
487
+ const governanceProposals = pgTable("governance_proposals", {
488
+ id: text("id").primaryKey(),
489
+ teamId: text("team_id").notNull(),
490
+ projectId: text("project_id"),
491
+ scope: text("scope").notNull().default("project"),
492
+ status: text("status").notNull().default("draft"),
493
+ title: text("title").notNull(),
494
+ summary: text("summary").notNull(),
495
+ body: text("body").notNull(),
496
+ proposalType: text("proposal_type").notNull().default("implementation"),
497
+ contentProposalSlug: text("content_proposal_slug"),
498
+ contentDecisionSlug: text("content_decision_slug"),
499
+ activeVersion: integer("active_version").notNull().default(1),
500
+ activeContentHash: text("active_content_hash").notNull(),
501
+ governanceProviderId: text("governance_provider_id").notNull(),
502
+ governanceProviderVersion: text("governance_provider_version").notNull().default("1"),
503
+ governancePolicyId: text("governance_policy_id"),
504
+ decisionId: text("decision_id"),
505
+ votingStartsAt: text("voting_starts_at"),
506
+ votingEndsAt: text("voting_ends_at"),
507
+ closedAt: text("closed_at"),
508
+ closedReason: text("closed_reason"),
509
+ createdByType: text("created_by_type").notNull().default("user"),
510
+ createdById: text("created_by_id"),
511
+ metadataJson: text("metadata_json").notNull().default("{}"),
512
+ createdAt: text("created_at").notNull(),
513
+ updatedAt: text("updated_at").notNull()
514
+ }, (table) => [
515
+ index("idx_governance_proposals_team_status").on(table.teamId, table.status, table.updatedAt),
516
+ index("idx_governance_proposals_project_status").on(table.projectId, table.status, table.updatedAt),
517
+ index("idx_governance_proposals_scope_status").on(table.scope, table.status, table.updatedAt),
518
+ index("idx_governance_proposals_content_slug").on(table.contentProposalSlug)
519
+ ]);
520
+ const governanceProposalVersions = pgTable("governance_proposal_versions", {
521
+ id: text("id").primaryKey(),
522
+ proposalId: text("proposal_id").notNull(),
523
+ version: integer("version").notNull(),
524
+ title: text("title").notNull(),
525
+ summary: text("summary").notNull(),
526
+ body: text("body").notNull(),
527
+ contentHash: text("content_hash").notNull(),
528
+ changeReason: text("change_reason"),
529
+ createdByType: text("created_by_type").notNull().default("user"),
530
+ createdById: text("created_by_id"),
531
+ createdAt: text("created_at").notNull()
532
+ }, (table) => [
533
+ uniqueIndex("idx_governance_proposal_versions_unique").on(table.proposalId, table.version),
534
+ index("idx_governance_proposal_versions_proposal").on(table.proposalId, table.createdAt)
535
+ ]);
536
+ const governanceElectorateSnapshots = pgTable("governance_electorate_snapshots", {
537
+ id: text("id").primaryKey(),
538
+ proposalId: text("proposal_id").notNull(),
539
+ proposalVersion: integer("proposal_version").notNull(),
540
+ providerId: text("provider_id").notNull(),
541
+ providerVersion: text("provider_version").notNull().default("1"),
542
+ ruleSnapshotJson: text("rule_snapshot_json").notNull().default("{}"),
543
+ chambersJson: text("chambers_json").notNull().default("[]"),
544
+ eligibleVotersJson: text("eligible_voters_json").notNull().default("[]"),
545
+ delegationsJson: text("delegations_json").notNull().default("[]"),
546
+ eligibleWeightTotal: real("eligible_weight_total").notNull().default(0),
547
+ activeWeightTotal: real("active_weight_total").notNull().default(0),
548
+ createdAt: text("created_at").notNull()
549
+ }, (table) => [
550
+ index("idx_governance_electorate_snapshots_proposal").on(table.proposalId, table.proposalVersion)
551
+ ]);
552
+ const governanceProposalVotes = pgTable("governance_proposal_votes", {
553
+ id: text("id").primaryKey(),
554
+ proposalId: text("proposal_id").notNull(),
555
+ proposalVersion: integer("proposal_version").notNull(),
556
+ userId: text("user_id").notNull(),
557
+ vote: text("vote").notNull(),
558
+ reason: text("reason"),
559
+ chamberVotesJson: text("chamber_votes_json").notNull().default("{}"),
560
+ effectiveWeightsJson: text("effective_weights_json").notNull().default("{}"),
561
+ delegatedFromJson: text("delegated_from_json").notNull().default("[]"),
562
+ createdAt: text("created_at").notNull(),
563
+ updatedAt: text("updated_at").notNull()
564
+ }, (table) => [
565
+ uniqueIndex("idx_governance_proposal_votes_once").on(table.proposalId, table.proposalVersion, table.userId),
566
+ index("idx_governance_proposal_votes_proposal").on(table.proposalId, table.proposalVersion, table.vote)
567
+ ]);
568
+ const governanceVoteEvents = pgTable("governance_vote_events", {
569
+ id: text("id").primaryKey(),
570
+ proposalId: text("proposal_id").notNull(),
571
+ proposalVersion: integer("proposal_version").notNull(),
572
+ userId: text("user_id").notNull(),
573
+ priorVote: text("prior_vote"),
574
+ nextVote: text("next_vote").notNull(),
575
+ reason: text("reason"),
576
+ effectiveWeightsJson: text("effective_weights_json").notNull().default("{}"),
577
+ createdAt: text("created_at").notNull()
578
+ }, (table) => [
579
+ index("idx_governance_vote_events_proposal").on(table.proposalId, table.proposalVersion, table.createdAt)
580
+ ]);
581
+ const governanceDelegations = pgTable("governance_delegations", {
582
+ id: text("id").primaryKey(),
583
+ teamId: text("team_id").notNull(),
584
+ scope: text("scope").notNull().default("team"),
585
+ fromUserId: text("from_user_id").notNull(),
586
+ toUserId: text("to_user_id").notNull(),
587
+ chambersJson: text("chambers_json").notNull().default("[]"),
588
+ status: text("status").notNull().default("active"),
589
+ reason: text("reason"),
590
+ createdAt: text("created_at").notNull(),
591
+ revokedAt: text("revoked_at"),
592
+ expiresAt: text("expires_at"),
593
+ metadataJson: text("metadata_json").notNull().default("{}")
594
+ }, (table) => [
595
+ index("idx_governance_delegations_team_status").on(table.teamId, table.status),
596
+ index("idx_governance_delegations_from").on(table.fromUserId, table.status),
597
+ index("idx_governance_delegations_to").on(table.toUserId, table.status)
598
+ ]);
599
+ const governanceDecisions = pgTable("governance_decisions", {
600
+ id: text("id").primaryKey(),
601
+ teamId: text("team_id").notNull(),
602
+ projectId: text("project_id"),
603
+ proposalId: text("proposal_id").notNull(),
604
+ proposalVersion: integer("proposal_version").notNull(),
605
+ proposalContentHash: text("proposal_content_hash").notNull(),
606
+ status: text("status").notNull().default("creating"),
607
+ title: text("title").notNull(),
608
+ summary: text("summary").notNull(),
609
+ contentDecisionSlug: text("content_decision_slug"),
610
+ governanceProviderId: text("governance_provider_id").notNull(),
611
+ governanceRuleJson: text("governance_rule_json").notNull().default("{}"),
612
+ electorateSnapshotId: text("electorate_snapshot_id"),
613
+ voteResultJson: text("vote_result_json").notNull().default("{}"),
614
+ voterReasonsJson: text("voter_reasons_json").notNull().default("[]"),
615
+ proposalSnapshotJson: text("proposal_snapshot_json").notNull().default("{}"),
616
+ decisionRecordJson: text("decision_record_json").notNull().default("{}"),
617
+ createdByType: text("created_by_type").notNull().default("system"),
618
+ createdById: text("created_by_id"),
619
+ createdAt: text("created_at").notNull(),
620
+ updatedAt: text("updated_at").notNull(),
621
+ supersededAt: text("superseded_at")
622
+ }, (table) => [
623
+ uniqueIndex("idx_governance_decisions_proposal").on(table.proposalId),
624
+ index("idx_governance_decisions_project_status").on(table.projectId, table.status, table.updatedAt)
625
+ ]);
626
+ const governanceEvents = pgTable("governance_events", {
627
+ id: text("id").primaryKey(),
628
+ eventType: text("event_type").notNull(),
629
+ actorType: text("actor_type").notNull().default("system"),
630
+ actorId: text("actor_id"),
631
+ teamId: text("team_id").notNull(),
632
+ projectId: text("project_id"),
633
+ proposalId: text("proposal_id"),
634
+ decisionId: text("decision_id"),
635
+ proposalVersion: integer("proposal_version"),
636
+ priorState: text("prior_state"),
637
+ nextState: text("next_state"),
638
+ message: text("message"),
639
+ evidenceJson: text("evidence_json").notNull().default("{}"),
640
+ createdAt: text("created_at").notNull()
641
+ }, (table) => [
642
+ index("idx_governance_events_proposal").on(table.proposalId, table.createdAt),
643
+ index("idx_governance_events_decision").on(table.decisionId, table.createdAt),
644
+ index("idx_governance_events_team").on(table.teamId, table.createdAt),
645
+ index("idx_governance_events_project").on(table.projectId, table.createdAt)
646
+ ]);
297
647
  const projects = pgTable("projects", {
298
648
  id: text("id").primaryKey(),
299
649
  teamId: text("team_id").notNull(),
@@ -478,588 +828,1850 @@ const catalogItemCollaborators = pgTable("catalog_item_collaborators", {
478
828
  }, (table) => [
479
829
  uniqueIndex("idx_catalog_item_collaborators_subject_role").on(table.itemId, table.subjectType, table.subjectId, table.role)
480
830
  ]);
481
- const projectHosting = pgTable("project_hosting", {
831
+ const commerceVendors = pgTable("commerce_vendors", {
482
832
  id: text("id").primaryKey(),
483
- projectId: text("project_id").notNull().unique(),
484
- hostingKind: text("hosting_kind").notNull(),
485
- registration: text("registration").notNull().default("none"),
486
- marketBaseUrl: text("market_base_url"),
487
- sourceRepoOwner: text("source_repo_owner"),
488
- sourceRepoName: text("source_repo_name"),
489
- sourceRepoUrl: text("source_repo_url"),
490
- sourceRepoWorkflowPath: text("source_repo_workflow_path"),
491
- metadataJson: text("metadata_json"),
833
+ teamId: text("team_id").notNull(),
834
+ displayName: text("display_name").notNull(),
835
+ slug: text("slug").notNull(),
836
+ status: text("status").notNull().default("submitted"),
837
+ trustLevel: text("trust_level").notNull().default("public_publisher"),
838
+ professionalEntitlementId: text("professional_entitlement_id"),
839
+ stripeAccountId: text("stripe_account_id"),
840
+ salesEnabled: integer("sales_enabled").notNull().default(0),
841
+ serviceSalesEnabled: integer("service_sales_enabled").notNull().default(0),
842
+ capacityListingsEnabled: integer("capacity_listings_enabled").notNull().default(0),
843
+ metadataJson: text("metadata_json").notNull().default("{}"),
492
844
  createdAt: text("created_at").notNull(),
493
845
  updatedAt: text("updated_at").notNull()
494
- });
495
- const projectEnvironments = pgTable("project_environments", {
846
+ }, (table) => [
847
+ uniqueIndex("idx_commerce_vendors_team_id").on(table.teamId),
848
+ uniqueIndex("idx_commerce_vendors_slug").on(table.slug),
849
+ index("idx_commerce_vendors_status").on(table.status, table.updatedAt),
850
+ index("idx_commerce_vendors_trust_level").on(table.trustLevel, table.updatedAt)
851
+ ]);
852
+ const commerceVendorStripeAccounts = pgTable("commerce_vendor_stripe_accounts", {
496
853
  id: text("id").primaryKey(),
497
- projectId: text("project_id").notNull(),
498
- environment: text("environment").notNull(),
499
- deploymentProfile: text("deployment_profile").notNull(),
500
- baseUrl: text("base_url"),
501
- cloudflareAccountId: text("cloudflare_account_id"),
502
- pagesProjectName: text("pages_project_name"),
503
- workerName: text("worker_name"),
504
- r2BucketName: text("r2_bucket_name"),
505
- d1DatabaseName: text("d1_database_name"),
506
- queueName: text("queue_name"),
507
- railwayProjectName: text("railway_project_name"),
508
- metadataJson: text("metadata_json"),
854
+ vendorId: text("vendor_id").notNull(),
855
+ teamId: text("team_id").notNull(),
856
+ environment: text("environment").notNull().default("test"),
857
+ stripeAccountId: text("stripe_account_id").notNull(),
858
+ accountStatus: text("account_status").notNull().default("pending"),
859
+ onboardingStatus: text("onboarding_status").notNull().default("not_started"),
860
+ chargesEnabled: integer("charges_enabled").notNull().default(0),
861
+ payoutsEnabled: integer("payouts_enabled").notNull().default(0),
862
+ detailsSubmitted: integer("details_submitted").notNull().default(0),
863
+ requirementsCurrentlyDueJson: text("requirements_currently_due_json").notNull().default("[]"),
864
+ requirementsEventuallyDueJson: text("requirements_eventually_due_json").notNull().default("[]"),
865
+ requirementsPastDueJson: text("requirements_past_due_json").notNull().default("[]"),
866
+ requirementsDisabledReason: text("requirements_disabled_reason"),
867
+ capabilitiesJson: text("capabilities_json").notNull().default("{}"),
868
+ onboardingStartedAt: text("onboarding_started_at"),
869
+ onboardingCompletedAt: text("onboarding_completed_at"),
870
+ lastSyncedAt: text("last_synced_at"),
871
+ metadataJson: text("metadata_json").notNull().default("{}"),
509
872
  createdAt: text("created_at").notNull(),
510
873
  updatedAt: text("updated_at").notNull()
511
874
  }, (table) => [
512
- uniqueIndex("idx_project_environments_project_environment").on(table.projectId, table.environment)
875
+ uniqueIndex("idx_commerce_vendor_stripe_accounts_vendor_env").on(table.vendorId, table.environment),
876
+ uniqueIndex("idx_commerce_vendor_stripe_accounts_stripe_env").on(table.stripeAccountId, table.environment),
877
+ index("idx_commerce_vendor_stripe_accounts_team_env").on(table.teamId, table.environment),
878
+ index("idx_commerce_vendor_stripe_accounts_status").on(table.accountStatus, table.updatedAt)
513
879
  ]);
514
- const projectInfrastructureResources = pgTable("project_infrastructure_resources", {
880
+ const commerceProducts = pgTable("commerce_products", {
515
881
  id: text("id").primaryKey(),
516
- projectId: text("project_id").notNull(),
517
- environment: text("environment").notNull(),
518
- provider: text("provider").notNull(),
519
- resourceKind: text("resource_kind").notNull(),
520
- logicalName: text("logical_name").notNull(),
521
- locator: text("locator"),
522
- metadataJson: text("metadata_json"),
882
+ vendorId: text("vendor_id").notNull(),
883
+ sellerTeamId: text("seller_team_id").notNull(),
884
+ kind: text("kind").notNull(),
885
+ slug: text("slug").notNull(),
886
+ title: text("title").notNull(),
887
+ summary: text("summary"),
888
+ description: text("description"),
889
+ status: text("status").notNull().default("draft"),
890
+ visibility: text("visibility").notNull().default("private"),
891
+ catalogItemId: text("catalog_item_id"),
892
+ currentVersionId: text("current_version_id"),
893
+ ownershipModel: text("ownership_model").notNull().default("team_owned"),
894
+ ownershipRecordId: text("ownership_record_id"),
895
+ supportPolicy: text("support_policy"),
896
+ license: text("license"),
897
+ metadataJson: text("metadata_json").notNull().default("{}"),
523
898
  createdAt: text("created_at").notNull(),
524
899
  updatedAt: text("updated_at").notNull()
525
900
  }, (table) => [
526
- uniqueIndex("idx_project_infrastructure_resource_unique").on(table.projectId, table.environment, table.provider, table.resourceKind, table.logicalName)
901
+ uniqueIndex("idx_commerce_products_team_kind_slug").on(table.sellerTeamId, table.kind, table.slug),
902
+ index("idx_commerce_products_vendor_status").on(table.vendorId, table.status, table.updatedAt),
903
+ index("idx_commerce_products_catalog_item").on(table.catalogItemId),
904
+ index("idx_commerce_products_ownership_model").on(table.ownershipModel, table.updatedAt)
527
905
  ]);
528
- const projectDeployments = pgTable("project_deployments", {
906
+ const commerceOwnershipRecords = pgTable("commerce_ownership_records", {
529
907
  id: text("id").primaryKey(),
530
- teamId: text("team_id").notNull(),
531
- projectId: text("project_id").notNull(),
532
- environment: text("environment").notNull(),
533
- deploymentKind: text("deployment_kind").notNull(),
534
- action: text("action").notNull().default("deploy_web"),
535
- status: text("status").notNull(),
536
- platformOperationId: text("platform_operation_id"),
537
- retryOfDeploymentId: text("retry_of_deployment_id"),
538
- resumedFromDeploymentId: text("resumed_from_deployment_id"),
539
- idempotencyKey: text("idempotency_key"),
540
- requestedByUserId: text("requested_by_user_id"),
541
- sourceRef: text("source_ref"),
542
- releaseTag: text("release_tag"),
543
- commitSha: text("commit_sha"),
544
- triggeredByType: text("triggered_by_type"),
545
- triggeredById: text("triggered_by_id"),
546
- repositoryJson: text("repository_json").notNull().default("{}"),
547
- externalWorkflowJson: text("external_workflow_json").notNull().default("{}"),
548
- targetJson: text("target_json").notNull().default("{}"),
549
- monitorJson: text("monitor_json").notNull().default("{}"),
550
- summary: text("summary"),
551
- errorJson: text("error_json").notNull().default("{}"),
552
- metadataJson: text("metadata_json"),
553
- startedAt: text("started_at"),
554
- finishedAt: text("finished_at"),
908
+ productId: text("product_id").notNull(),
909
+ model: text("model").notNull(),
910
+ canonicalOwnerType: text("canonical_owner_type").notNull(),
911
+ canonicalOwnerId: text("canonical_owner_id"),
912
+ sellerTeamId: text("seller_team_id").notNull(),
913
+ stewardTeamId: text("steward_team_id"),
914
+ governancePolicyId: text("governance_policy_id"),
915
+ publicSummary: text("public_summary"),
916
+ buyerVisible: integer("buyer_visible").notNull().default(1),
917
+ effectiveAt: text("effective_at").notNull(),
918
+ supersededAt: text("superseded_at"),
919
+ metadataJson: text("metadata_json").notNull().default("{}"),
555
920
  createdAt: text("created_at").notNull(),
556
- updatedAt: text("updated_at").notNull(),
557
- completedAt: text("completed_at")
921
+ updatedAt: text("updated_at").notNull()
558
922
  }, (table) => [
559
- index("idx_project_deployments_project_created").on(table.projectId, table.createdAt),
560
- index("idx_project_deployments_project_environment").on(table.projectId, table.environment, table.createdAt),
561
- index("idx_project_deployments_project_status").on(table.projectId, table.status, table.updatedAt),
562
- index("idx_project_deployments_operation").on(table.platformOperationId),
563
- index("idx_project_deployments_team_created").on(table.teamId, table.createdAt),
564
- uniqueIndex("idx_project_deployments_idempotency").on(table.projectId, table.idempotencyKey)
923
+ index("idx_commerce_ownership_product_effective").on(table.productId, table.effectiveAt),
924
+ index("idx_commerce_ownership_seller_effective").on(table.sellerTeamId, table.effectiveAt),
925
+ index("idx_commerce_ownership_model_effective").on(table.model, table.effectiveAt)
565
926
  ]);
566
- const projectDeploymentEvents = pgTable("project_deployment_events", {
927
+ const commerceStewardshipAssignments = pgTable("commerce_stewardship_assignments", {
567
928
  id: text("id").primaryKey(),
568
- deploymentId: text("deployment_id").notNull(),
569
- projectId: text("project_id").notNull(),
570
- teamId: text("team_id").notNull(),
571
- operationId: text("operation_id"),
572
- kind: text("kind").notNull(),
573
- message: text("message").notNull(),
574
- status: text("status"),
575
- severity: text("severity").notNull().default("info"),
576
- sequence: integer("sequence").notNull(),
577
- payloadJson: text("payload_json").notNull().default("{}"),
929
+ ownershipRecordId: text("ownership_record_id").notNull(),
930
+ productId: text("product_id").notNull(),
931
+ role: text("role").notNull(),
932
+ assigneeType: text("assignee_type").notNull(),
933
+ assigneeId: text("assignee_id"),
934
+ displayName: text("display_name"),
935
+ responsibilitiesJson: text("responsibilities_json").notNull().default("[]"),
936
+ visibleToBuyers: integer("visible_to_buyers").notNull().default(1),
937
+ startsAt: text("starts_at").notNull(),
938
+ endsAt: text("ends_at"),
939
+ metadataJson: text("metadata_json").notNull().default("{}"),
940
+ createdAt: text("created_at").notNull(),
941
+ updatedAt: text("updated_at").notNull()
942
+ }, (table) => [
943
+ index("idx_commerce_stewards_product_role").on(table.productId, table.role),
944
+ index("idx_commerce_stewards_ownership_role").on(table.ownershipRecordId, table.role),
945
+ index("idx_commerce_stewards_assignee").on(table.assigneeType, table.assigneeId)
946
+ ]);
947
+ const commerceContributions = pgTable("commerce_contributions", {
948
+ id: text("id").primaryKey(),
949
+ productId: text("product_id").notNull(),
950
+ productVersionId: text("product_version_id"),
951
+ contributorType: text("contributor_type").notNull(),
952
+ contributorId: text("contributor_id"),
953
+ displayName: text("display_name"),
954
+ role: text("role").notNull(),
955
+ summary: text("summary"),
956
+ attributionVisibility: text("attribution_visibility").notNull().default("public"),
957
+ agreementRef: text("agreement_ref"),
958
+ benefitWeight: real("benefit_weight"),
959
+ effectiveAt: text("effective_at").notNull(),
960
+ metadataJson: text("metadata_json").notNull().default("{}"),
961
+ createdAt: text("created_at").notNull(),
962
+ updatedAt: text("updated_at").notNull()
963
+ }, (table) => [
964
+ index("idx_commerce_contributions_product_effective").on(table.productId, table.effectiveAt),
965
+ index("idx_commerce_contributions_version_effective").on(table.productVersionId, table.effectiveAt),
966
+ index("idx_commerce_contributions_contributor").on(table.contributorType, table.contributorId)
967
+ ]);
968
+ const commerceGovernancePolicies = pgTable("commerce_governance_policies", {
969
+ id: text("id").primaryKey(),
970
+ productId: text("product_id"),
971
+ teamId: text("team_id"),
972
+ policyKind: text("policy_kind").notNull(),
973
+ title: text("title").notNull(),
974
+ approvalRulesJson: text("approval_rules_json").notNull().default("{}"),
975
+ quorumRulesJson: text("quorum_rules_json").notNull().default("{}"),
976
+ buyerVisibleSummary: text("buyer_visible_summary"),
977
+ status: text("status").notNull().default("draft"),
978
+ createdAt: text("created_at").notNull(),
979
+ updatedAt: text("updated_at").notNull()
980
+ }, (table) => [
981
+ index("idx_commerce_governance_policies_product").on(table.productId, table.status),
982
+ index("idx_commerce_governance_policies_team").on(table.teamId, table.policyKind, table.status)
983
+ ]);
984
+ const commerceOwnershipTransfers = pgTable("commerce_ownership_transfers", {
985
+ id: text("id").primaryKey(),
986
+ productId: text("product_id").notNull(),
987
+ fromOwnershipRecordId: text("from_ownership_record_id").notNull(),
988
+ toOwnershipRecordId: text("to_ownership_record_id").notNull(),
989
+ status: text("status").notNull().default("draft"),
990
+ reason: text("reason").notNull(),
991
+ approvalEvidenceJson: text("approval_evidence_json").notNull().default("{}"),
992
+ buyerVisibleImpact: text("buyer_visible_impact"),
993
+ effectiveAt: text("effective_at").notNull(),
994
+ requestedByType: text("requested_by_type").notNull().default("user"),
995
+ requestedById: text("requested_by_id").notNull().default("system"),
996
+ approvedByType: text("approved_by_type"),
997
+ approvedById: text("approved_by_id"),
998
+ approvedAt: text("approved_at"),
999
+ rejectedAt: text("rejected_at"),
1000
+ supersededAt: text("superseded_at"),
1001
+ metadataJson: text("metadata_json").notNull().default("{}"),
578
1002
  createdAt: text("created_at").notNull()
579
1003
  }, (table) => [
580
- index("idx_project_deployment_events_deployment_sequence").on(table.deploymentId, table.sequence),
581
- index("idx_project_deployment_events_project_created").on(table.projectId, table.createdAt),
582
- index("idx_project_deployment_events_operation").on(table.operationId)
1004
+ index("idx_commerce_ownership_transfers_product").on(table.productId, table.effectiveAt),
1005
+ index("idx_commerce_ownership_transfers_product_status").on(table.productId, table.status, table.effectiveAt),
1006
+ index("idx_commerce_ownership_transfers_from_status").on(table.fromOwnershipRecordId, table.status),
1007
+ index("idx_commerce_ownership_transfers_to_status").on(table.toOwnershipRecordId, table.status)
583
1008
  ]);
584
- const agentPools = pgTable("agent_pools", {
1009
+ const commerceSuccessionEvents = pgTable("commerce_succession_events", {
1010
+ id: text("id").primaryKey(),
1011
+ productId: text("product_id").notNull(),
1012
+ ownershipRecordId: text("ownership_record_id"),
1013
+ stewardshipAssignmentId: text("stewardship_assignment_id"),
1014
+ successorType: text("successor_type").notNull(),
1015
+ successorId: text("successor_id").notNull(),
1016
+ eventType: text("event_type").notNull(),
1017
+ status: text("status").notNull().default("submitted"),
1018
+ reason: text("reason"),
1019
+ evidenceJson: text("evidence_json").notNull().default("{}"),
1020
+ effectiveAt: text("effective_at"),
1021
+ createdByType: text("created_by_type").notNull(),
1022
+ createdById: text("created_by_id").notNull(),
1023
+ metadataJson: text("metadata_json").notNull().default("{}"),
1024
+ createdAt: text("created_at").notNull()
1025
+ }, (table) => [
1026
+ index("idx_commerce_succession_events_product").on(table.productId, table.eventType, table.createdAt),
1027
+ index("idx_commerce_succession_events_ownership").on(table.ownershipRecordId, table.eventType),
1028
+ index("idx_commerce_succession_events_successor").on(table.successorType, table.successorId)
1029
+ ]);
1030
+ const commerceProductVersions = pgTable("commerce_product_versions", {
1031
+ id: text("id").primaryKey(),
1032
+ productId: text("product_id").notNull(),
1033
+ version: text("version").notNull(),
1034
+ status: text("status").notNull().default("draft"),
1035
+ catalogArtifactVersionId: text("catalog_artifact_version_id"),
1036
+ manifestKey: text("manifest_key"),
1037
+ artifactKey: text("artifact_key"),
1038
+ integrity: text("integrity"),
1039
+ releaseNotes: text("release_notes"),
1040
+ compatibilityJson: text("compatibility_json").notNull().default("{}"),
1041
+ metadataJson: text("metadata_json").notNull().default("{}"),
1042
+ publishedAt: text("published_at"),
1043
+ createdAt: text("created_at").notNull(),
1044
+ updatedAt: text("updated_at").notNull()
1045
+ }, (table) => [
1046
+ uniqueIndex("idx_commerce_product_versions_product_version").on(table.productId, table.version),
1047
+ index("idx_commerce_product_versions_product_status").on(table.productId, table.status, table.createdAt),
1048
+ index("idx_commerce_product_versions_catalog_artifact").on(table.catalogArtifactVersionId)
1049
+ ]);
1050
+ const commerceOffers = pgTable("commerce_offers", {
1051
+ id: text("id").primaryKey(),
1052
+ productId: text("product_id").notNull(),
1053
+ productVersionId: text("product_version_id"),
1054
+ vendorId: text("vendor_id").notNull(),
1055
+ sellerTeamId: text("seller_team_id").notNull(),
1056
+ mode: text("mode").notNull(),
1057
+ status: text("status").notNull().default("draft"),
1058
+ title: text("title").notNull(),
1059
+ termsSummary: text("terms_summary"),
1060
+ accessScopeJson: text("access_scope_json").notNull().default("{}"),
1061
+ supportScopeJson: text("support_scope_json").notNull().default("{}"),
1062
+ fulfillmentMode: text("fulfillment_mode").notNull().default("automatic"),
1063
+ activePriceId: text("active_price_id"),
1064
+ stripeProductId: text("stripe_product_id"),
1065
+ stripeProductStatus: text("stripe_product_status").notNull().default("not_synced"),
1066
+ stripeProductSyncedAt: text("stripe_product_synced_at"),
1067
+ stripeProductSyncError: text("stripe_product_sync_error"),
1068
+ stripeProductMetadataJson: text("stripe_product_metadata_json").notNull().default("{}"),
1069
+ startsAt: text("starts_at"),
1070
+ endsAt: text("ends_at"),
1071
+ metadataJson: text("metadata_json").notNull().default("{}"),
1072
+ createdAt: text("created_at").notNull(),
1073
+ updatedAt: text("updated_at").notNull()
1074
+ }, (table) => [
1075
+ index("idx_commerce_offers_product_status").on(table.productId, table.status, table.updatedAt),
1076
+ index("idx_commerce_offers_vendor_status").on(table.vendorId, table.status, table.updatedAt),
1077
+ index("idx_commerce_offers_seller_status").on(table.sellerTeamId, table.status, table.updatedAt),
1078
+ index("idx_commerce_offers_active_price").on(table.activePriceId),
1079
+ index("idx_commerce_offers_stripe_product").on(table.stripeProductId),
1080
+ index("idx_commerce_offers_stripe_status").on(table.stripeProductStatus, table.updatedAt)
1081
+ ]);
1082
+ const commercePrices = pgTable("commerce_prices", {
1083
+ id: text("id").primaryKey(),
1084
+ offerId: text("offer_id").notNull(),
1085
+ amount: integer("amount").notNull(),
1086
+ currency: text("currency").notNull(),
1087
+ billingInterval: text("billing_interval").notNull(),
1088
+ status: text("status").notNull().default("draft"),
1089
+ stripeProductId: text("stripe_product_id"),
1090
+ stripePriceId: text("stripe_price_id"),
1091
+ stripeLookupKey: text("stripe_lookup_key"),
1092
+ stripeSyncStatus: text("stripe_sync_status").notNull().default("not_synced"),
1093
+ stripeSyncedAt: text("stripe_synced_at"),
1094
+ stripeSyncError: text("stripe_sync_error"),
1095
+ stripeMetadataJson: text("stripe_metadata_json").notNull().default("{}"),
1096
+ priceVersion: integer("price_version").notNull().default(1),
1097
+ taxBehavior: text("tax_behavior").notNull().default("unspecified"),
1098
+ metadataJson: text("metadata_json").notNull().default("{}"),
1099
+ createdAt: text("created_at").notNull(),
1100
+ updatedAt: text("updated_at").notNull()
1101
+ }, (table) => [
1102
+ uniqueIndex("idx_commerce_prices_offer_version").on(table.offerId, table.priceVersion),
1103
+ index("idx_commerce_prices_offer_status").on(table.offerId, table.status),
1104
+ index("idx_commerce_prices_stripe_price").on(table.stripePriceId),
1105
+ index("idx_commerce_prices_stripe_sync_status").on(table.stripeSyncStatus, table.updatedAt)
1106
+ ]);
1107
+ const commerceGovernanceEvents = pgTable("commerce_governance_events", {
1108
+ id: text("id").primaryKey(),
1109
+ actorType: text("actor_type").notNull(),
1110
+ actorId: text("actor_id"),
1111
+ action: text("action").notNull(),
1112
+ objectType: text("object_type").notNull(),
1113
+ objectId: text("object_id").notNull(),
1114
+ priorState: text("prior_state"),
1115
+ nextState: text("next_state"),
1116
+ reason: text("reason"),
1117
+ evidenceJson: text("evidence_json").notNull().default("{}"),
1118
+ relatedOrderId: text("related_order_id"),
1119
+ relatedOfferId: text("related_offer_id"),
1120
+ relatedProductId: text("related_product_id"),
1121
+ relatedTeamId: text("related_team_id"),
1122
+ createdAt: text("created_at").notNull()
1123
+ }, (table) => [
1124
+ index("idx_commerce_governance_events_object").on(table.objectType, table.objectId, table.createdAt),
1125
+ index("idx_commerce_governance_events_product").on(table.relatedProductId, table.createdAt),
1126
+ index("idx_commerce_governance_events_offer").on(table.relatedOfferId, table.createdAt),
1127
+ index("idx_commerce_governance_events_team").on(table.relatedTeamId, table.createdAt)
1128
+ ]);
1129
+ const commerceCarts = pgTable("commerce_carts", {
1130
+ id: text("id").primaryKey(),
1131
+ buyerTeamId: text("buyer_team_id"),
1132
+ buyerUserId: text("buyer_user_id"),
1133
+ status: text("status").notNull().default("active"),
1134
+ currency: text("currency"),
1135
+ metadataJson: text("metadata_json").notNull().default("{}"),
1136
+ createdAt: text("created_at").notNull(),
1137
+ updatedAt: text("updated_at").notNull()
1138
+ }, (table) => [
1139
+ index("idx_commerce_carts_buyer_team_status").on(table.buyerTeamId, table.status, table.updatedAt),
1140
+ index("idx_commerce_carts_buyer_user_status").on(table.buyerUserId, table.status, table.updatedAt)
1141
+ ]);
1142
+ const commerceCartItems = pgTable("commerce_cart_items", {
1143
+ id: text("id").primaryKey(),
1144
+ cartId: text("cart_id").notNull(),
1145
+ vendorId: text("vendor_id").notNull(),
1146
+ sellerTeamId: text("seller_team_id").notNull(),
1147
+ productId: text("product_id").notNull(),
1148
+ productVersionId: text("product_version_id"),
1149
+ offerId: text("offer_id").notNull(),
1150
+ priceId: text("price_id"),
1151
+ quantity: integer("quantity").notNull().default(1),
1152
+ unitAmount: integer("unit_amount").notNull().default(0),
1153
+ currency: text("currency").notNull(),
1154
+ mode: text("mode").notNull(),
1155
+ status: text("status").notNull().default("active"),
1156
+ metadataJson: text("metadata_json").notNull().default("{}"),
1157
+ createdAt: text("created_at").notNull(),
1158
+ updatedAt: text("updated_at").notNull()
1159
+ }, (table) => [
1160
+ index("idx_commerce_cart_items_cart_status").on(table.cartId, table.status),
1161
+ index("idx_commerce_cart_items_vendor_status").on(table.vendorId, table.status, table.updatedAt),
1162
+ index("idx_commerce_cart_items_offer").on(table.offerId),
1163
+ index("idx_commerce_cart_items_price").on(table.priceId)
1164
+ ]);
1165
+ const commerceCheckouts = pgTable("commerce_checkouts", {
1166
+ id: text("id").primaryKey(),
1167
+ cartId: text("cart_id").notNull(),
1168
+ buyerTeamId: text("buyer_team_id"),
1169
+ buyerUserId: text("buyer_user_id"),
1170
+ status: text("status").notNull().default("draft"),
1171
+ checkoutMode: text("checkout_mode").notNull().default("stripe_elements_grouped_vendor"),
1172
+ groupCount: integer("group_count").notNull().default(0),
1173
+ completedGroupCount: integer("completed_group_count").notNull().default(0),
1174
+ metadataJson: text("metadata_json").notNull().default("{}"),
1175
+ createdAt: text("created_at").notNull(),
1176
+ updatedAt: text("updated_at").notNull()
1177
+ }, (table) => [
1178
+ index("idx_commerce_checkouts_cart").on(table.cartId),
1179
+ index("idx_commerce_checkouts_buyer_team_status").on(table.buyerTeamId, table.status, table.updatedAt),
1180
+ index("idx_commerce_checkouts_buyer_user_status").on(table.buyerUserId, table.status, table.updatedAt)
1181
+ ]);
1182
+ const commerceOrders = pgTable("commerce_orders", {
1183
+ id: text("id").primaryKey(),
1184
+ checkoutId: text("checkout_id"),
1185
+ cartId: text("cart_id"),
1186
+ buyerTeamId: text("buyer_team_id"),
1187
+ buyerUserId: text("buyer_user_id"),
1188
+ vendorId: text("vendor_id"),
1189
+ sellerTeamId: text("seller_team_id"),
1190
+ status: text("status").notNull().default("draft"),
1191
+ currency: text("currency").notNull(),
1192
+ subtotalAmount: integer("subtotal_amount").notNull().default(0),
1193
+ totalAmount: integer("total_amount").notNull().default(0),
1194
+ refundedAmount: integer("refunded_amount").notNull().default(0),
1195
+ refundStatus: text("refund_status").notNull().default("none"),
1196
+ stripeCheckoutSessionId: text("stripe_checkout_session_id"),
1197
+ stripePaymentIntentId: text("stripe_payment_intent_id"),
1198
+ stripeSubscriptionId: text("stripe_subscription_id"),
1199
+ stripeCustomerId: text("stripe_customer_id"),
1200
+ stripeConnectedAccountId: text("stripe_connected_account_id"),
1201
+ ownershipSnapshotJson: text("ownership_snapshot_json").notNull().default("{}"),
1202
+ metadataJson: text("metadata_json").notNull().default("{}"),
1203
+ createdAt: text("created_at").notNull(),
1204
+ updatedAt: text("updated_at").notNull()
1205
+ }, (table) => [
1206
+ index("idx_commerce_orders_checkout").on(table.checkoutId),
1207
+ index("idx_commerce_orders_buyer_team_status").on(table.buyerTeamId, table.status, table.updatedAt),
1208
+ index("idx_commerce_orders_buyer_user_status").on(table.buyerUserId, table.status, table.updatedAt),
1209
+ index("idx_commerce_orders_vendor_status").on(table.vendorId, table.status, table.updatedAt),
1210
+ index("idx_commerce_orders_stripe_payment_intent").on(table.stripePaymentIntentId),
1211
+ index("idx_commerce_orders_stripe_subscription").on(table.stripeSubscriptionId)
1212
+ ]);
1213
+ const commerceOrderItems = pgTable("commerce_order_items", {
1214
+ id: text("id").primaryKey(),
1215
+ orderId: text("order_id").notNull(),
1216
+ vendorId: text("vendor_id").notNull(),
1217
+ sellerTeamId: text("seller_team_id").notNull(),
1218
+ productId: text("product_id").notNull(),
1219
+ productVersionId: text("product_version_id"),
1220
+ offerId: text("offer_id").notNull(),
1221
+ priceId: text("price_id"),
1222
+ mode: text("mode").notNull(),
1223
+ quantity: integer("quantity").notNull().default(1),
1224
+ unitAmount: integer("unit_amount").notNull().default(0),
1225
+ totalAmount: integer("total_amount").notNull().default(0),
1226
+ refundedAmount: integer("refunded_amount").notNull().default(0),
1227
+ refundStatus: text("refund_status").notNull().default("none"),
1228
+ currency: text("currency").notNull(),
1229
+ status: text("status").notNull().default("pending"),
1230
+ entitlementId: text("entitlement_id"),
1231
+ ownershipSnapshotJson: text("ownership_snapshot_json").notNull().default("{}"),
1232
+ accessScopeJson: text("access_scope_json").notNull().default("{}"),
1233
+ supportScopeJson: text("support_scope_json").notNull().default("{}"),
1234
+ metadataJson: text("metadata_json").notNull().default("{}"),
1235
+ createdAt: text("created_at").notNull(),
1236
+ updatedAt: text("updated_at").notNull()
1237
+ }, (table) => [
1238
+ index("idx_commerce_order_items_order").on(table.orderId),
1239
+ index("idx_commerce_order_items_product_status").on(table.productId, table.status),
1240
+ index("idx_commerce_order_items_offer_status").on(table.offerId, table.status),
1241
+ index("idx_commerce_order_items_entitlement").on(table.entitlementId)
1242
+ ]);
1243
+ const commercePaymentGroups = pgTable("commerce_payment_groups", {
1244
+ id: text("id").primaryKey(),
1245
+ checkoutId: text("checkout_id").notNull(),
1246
+ orderId: text("order_id").notNull(),
1247
+ vendorId: text("vendor_id").notNull(),
1248
+ sellerTeamId: text("seller_team_id").notNull(),
1249
+ connectedAccountId: text("connected_account_id"),
1250
+ groupKind: text("group_kind").notNull(),
1251
+ billingInterval: text("billing_interval"),
1252
+ status: text("status").notNull().default("pending"),
1253
+ currency: text("currency").notNull(),
1254
+ subtotalAmount: integer("subtotal_amount").notNull().default(0),
1255
+ totalAmount: integer("total_amount").notNull().default(0),
1256
+ stripePaymentIntentId: text("stripe_payment_intent_id"),
1257
+ stripeSubscriptionId: text("stripe_subscription_id"),
1258
+ stripeCustomerId: text("stripe_customer_id"),
1259
+ clientSecretLast4: text("client_secret_last4"),
1260
+ metadataJson: text("metadata_json").notNull().default("{}"),
1261
+ createdAt: text("created_at").notNull(),
1262
+ updatedAt: text("updated_at").notNull()
1263
+ }, (table) => [
1264
+ index("idx_commerce_payment_groups_checkout").on(table.checkoutId),
1265
+ index("idx_commerce_payment_groups_order").on(table.orderId),
1266
+ index("idx_commerce_payment_groups_vendor_status").on(table.vendorId, table.status, table.updatedAt),
1267
+ index("idx_commerce_payment_groups_payment_intent").on(table.stripePaymentIntentId),
1268
+ index("idx_commerce_payment_groups_subscription").on(table.stripeSubscriptionId)
1269
+ ]);
1270
+ const commerceSubscriptions = pgTable("commerce_subscriptions", {
1271
+ id: text("id").primaryKey(),
1272
+ orderId: text("order_id").notNull(),
1273
+ vendorId: text("vendor_id").notNull(),
1274
+ sellerTeamId: text("seller_team_id").notNull(),
1275
+ buyerTeamId: text("buyer_team_id"),
1276
+ buyerUserId: text("buyer_user_id"),
1277
+ offerId: text("offer_id").notNull(),
1278
+ priceId: text("price_id").notNull(),
1279
+ status: text("status").notNull(),
1280
+ renewalState: text("renewal_state").notNull().default("active"),
1281
+ stripeSubscriptionId: text("stripe_subscription_id").notNull(),
1282
+ stripeCustomerId: text("stripe_customer_id"),
1283
+ stripeConnectedAccountId: text("stripe_connected_account_id").notNull(),
1284
+ currentPeriodStart: text("current_period_start"),
1285
+ currentPeriodEnd: text("current_period_end"),
1286
+ cancelAtPeriodEnd: integer("cancel_at_period_end").notNull().default(0),
1287
+ canceledAt: text("canceled_at"),
1288
+ metadataJson: text("metadata_json").notNull().default("{}"),
1289
+ createdAt: text("created_at").notNull(),
1290
+ updatedAt: text("updated_at").notNull()
1291
+ }, (table) => [
1292
+ uniqueIndex("idx_commerce_subscriptions_stripe").on(table.stripeSubscriptionId, table.stripeConnectedAccountId),
1293
+ index("idx_commerce_subscriptions_buyer_team_status").on(table.buyerTeamId, table.status, table.updatedAt),
1294
+ index("idx_commerce_subscriptions_vendor_status").on(table.vendorId, table.status, table.updatedAt),
1295
+ index("idx_commerce_subscriptions_offer_status").on(table.offerId, table.status)
1296
+ ]);
1297
+ const commerceEntitlements = pgTable("commerce_entitlements", {
1298
+ id: text("id").primaryKey(),
1299
+ buyerTeamId: text("buyer_team_id"),
1300
+ buyerUserId: text("buyer_user_id"),
1301
+ sellerTeamId: text("seller_team_id").notNull(),
1302
+ productId: text("product_id").notNull(),
1303
+ productVersionId: text("product_version_id"),
1304
+ offerId: text("offer_id").notNull(),
1305
+ orderId: text("order_id"),
1306
+ orderItemId: text("order_item_id"),
1307
+ subscriptionId: text("subscription_id"),
1308
+ status: text("status").notNull().default("pending"),
1309
+ accessScopeJson: text("access_scope_json").notNull().default("{}"),
1310
+ startsAt: text("starts_at"),
1311
+ endsAt: text("ends_at"),
1312
+ renewalState: text("renewal_state").notNull().default("none"),
1313
+ fulfillmentArtifactRefsJson: text("fulfillment_artifact_refs_json").notNull().default("[]"),
1314
+ projectId: text("project_id"),
1315
+ catalogItemId: text("catalog_item_id"),
1316
+ ownershipSnapshotJson: text("ownership_snapshot_json").notNull().default("{}"),
1317
+ metadataJson: text("metadata_json").notNull().default("{}"),
1318
+ createdAt: text("created_at").notNull(),
1319
+ updatedAt: text("updated_at").notNull()
1320
+ }, (table) => [
1321
+ index("idx_commerce_entitlements_buyer_team_status").on(table.buyerTeamId, table.status, table.updatedAt),
1322
+ index("idx_commerce_entitlements_buyer_user_status").on(table.buyerUserId, table.status, table.updatedAt),
1323
+ index("idx_commerce_entitlements_product_status").on(table.productId, table.status),
1324
+ index("idx_commerce_entitlements_offer_status").on(table.offerId, table.status),
1325
+ index("idx_commerce_entitlements_order").on(table.orderId),
1326
+ index("idx_commerce_entitlements_subscription").on(table.subscriptionId),
1327
+ index("idx_commerce_entitlements_catalog_item").on(table.catalogItemId)
1328
+ ]);
1329
+ const commerceBuyerStripeCustomers = pgTable("commerce_buyer_stripe_customers", {
1330
+ id: text("id").primaryKey(),
1331
+ buyerTeamId: text("buyer_team_id"),
1332
+ buyerUserId: text("buyer_user_id"),
1333
+ vendorId: text("vendor_id").notNull(),
1334
+ connectedAccountId: text("connected_account_id").notNull(),
1335
+ environment: text("environment").notNull().default("test"),
1336
+ stripeCustomerId: text("stripe_customer_id").notNull(),
1337
+ metadataJson: text("metadata_json").notNull().default("{}"),
1338
+ createdAt: text("created_at").notNull(),
1339
+ updatedAt: text("updated_at").notNull()
1340
+ }, (table) => [
1341
+ uniqueIndex("idx_commerce_buyer_stripe_customers_team").on(table.vendorId, table.environment, table.buyerTeamId),
1342
+ uniqueIndex("idx_commerce_buyer_stripe_customers_user").on(table.vendorId, table.environment, table.buyerUserId),
1343
+ uniqueIndex("idx_commerce_buyer_stripe_customers_stripe").on(table.connectedAccountId, table.stripeCustomerId)
1344
+ ]);
1345
+ const commerceRefunds = pgTable("commerce_refunds", {
1346
+ id: text("id").primaryKey(),
1347
+ orderId: text("order_id").notNull(),
1348
+ orderItemId: text("order_item_id"),
1349
+ paymentGroupId: text("payment_group_id"),
1350
+ vendorId: text("vendor_id").notNull(),
1351
+ sellerTeamId: text("seller_team_id").notNull(),
1352
+ buyerTeamId: text("buyer_team_id"),
1353
+ buyerUserId: text("buyer_user_id"),
1354
+ amount: integer("amount").notNull(),
1355
+ currency: text("currency").notNull(),
1356
+ status: text("status").notNull().default("processing"),
1357
+ reason: text("reason"),
1358
+ stripeRefundId: text("stripe_refund_id"),
1359
+ stripePaymentIntentId: text("stripe_payment_intent_id"),
1360
+ stripeConnectedAccountId: text("stripe_connected_account_id"),
1361
+ idempotencyKey: text("idempotency_key").notNull(),
1362
+ requestedByType: text("requested_by_type").notNull(),
1363
+ requestedById: text("requested_by_id").notNull(),
1364
+ failureReason: text("failure_reason"),
1365
+ metadataJson: text("metadata_json").notNull().default("{}"),
1366
+ createdAt: text("created_at").notNull(),
1367
+ updatedAt: text("updated_at").notNull()
1368
+ }, (table) => [
1369
+ uniqueIndex("idx_commerce_refunds_stripe").on(table.stripeRefundId, table.stripeConnectedAccountId),
1370
+ uniqueIndex("idx_commerce_refunds_idempotency").on(table.idempotencyKey),
1371
+ index("idx_commerce_refunds_order").on(table.orderId, table.createdAt),
1372
+ index("idx_commerce_refunds_vendor_status").on(table.vendorId, table.status, table.updatedAt),
1373
+ index("idx_commerce_refunds_seller_status").on(table.sellerTeamId, table.status, table.updatedAt)
1374
+ ]);
1375
+ const commerceFulfillmentEvents = pgTable("commerce_fulfillment_events", {
1376
+ id: text("id").primaryKey(),
1377
+ orderId: text("order_id").notNull(),
1378
+ orderItemId: text("order_item_id"),
1379
+ entitlementId: text("entitlement_id"),
1380
+ vendorId: text("vendor_id").notNull(),
1381
+ sellerTeamId: text("seller_team_id").notNull(),
1382
+ productId: text("product_id").notNull(),
1383
+ productVersionId: text("product_version_id"),
1384
+ catalogItemId: text("catalog_item_id"),
1385
+ catalogArtifactVersionId: text("catalog_artifact_version_id"),
1386
+ eventType: text("event_type").notNull(),
1387
+ status: text("status").notNull().default("pending"),
1388
+ artifactRefsJson: text("artifact_refs_json").notNull().default("[]"),
1389
+ deliveryRefsJson: text("delivery_refs_json").notNull().default("[]"),
1390
+ message: text("message"),
1391
+ actorType: text("actor_type").notNull(),
1392
+ actorId: text("actor_id").notNull(),
1393
+ metadataJson: text("metadata_json").notNull().default("{}"),
1394
+ createdAt: text("created_at").notNull()
1395
+ }, (table) => [
1396
+ index("idx_commerce_fulfillment_events_order").on(table.orderId, table.createdAt),
1397
+ index("idx_commerce_fulfillment_events_entitlement").on(table.entitlementId, table.createdAt),
1398
+ index("idx_commerce_fulfillment_events_vendor_status").on(table.vendorId, table.status, table.createdAt),
1399
+ index("idx_commerce_fulfillment_events_product").on(table.productId, table.createdAt)
1400
+ ]);
1401
+ const commerceServiceRequests = pgTable("commerce_service_requests", {
1402
+ id: text("id").primaryKey(),
1403
+ buyerTeamId: text("buyer_team_id"),
1404
+ buyerUserId: text("buyer_user_id"),
1405
+ vendorId: text("vendor_id").notNull(),
1406
+ sellerTeamId: text("seller_team_id").notNull(),
1407
+ productId: text("product_id").notNull(),
1408
+ offerId: text("offer_id").notNull(),
1409
+ status: text("status").notNull().default("requested"),
1410
+ requestedScope: text("requested_scope").notNull(),
1411
+ approvedScope: text("approved_scope"),
1412
+ accessNeedsJson: text("access_needs_json").notNull().default("{}"),
1413
+ buyerVisibleSummary: text("buyer_visible_summary"),
1414
+ vendorPrivateNotes: text("vendor_private_notes"),
1415
+ activeQuoteId: text("active_quote_id"),
1416
+ approvedQuoteId: text("approved_quote_id"),
1417
+ contractId: text("contract_id"),
1418
+ relatedProjectId: text("related_project_id"),
1419
+ relatedWorkdayId: text("related_workday_id"),
1420
+ orderId: text("order_id"),
1421
+ entitlementId: text("entitlement_id"),
1422
+ ownershipSnapshotJson: text("ownership_snapshot_json").notNull().default("{}"),
1423
+ metadataJson: text("metadata_json").notNull().default("{}"),
1424
+ createdAt: text("created_at").notNull(),
1425
+ updatedAt: text("updated_at").notNull()
1426
+ }, (table) => [
1427
+ index("idx_commerce_service_requests_buyer_team").on(table.buyerTeamId, table.status, table.updatedAt),
1428
+ index("idx_commerce_service_requests_buyer_user").on(table.buyerUserId, table.status, table.updatedAt),
1429
+ index("idx_commerce_service_requests_vendor").on(table.vendorId, table.status, table.updatedAt),
1430
+ index("idx_commerce_service_requests_seller").on(table.sellerTeamId, table.status, table.updatedAt),
1431
+ index("idx_commerce_service_requests_offer").on(table.offerId, table.status),
1432
+ index("idx_commerce_service_requests_project").on(table.relatedProjectId, table.status),
1433
+ index("idx_commerce_service_requests_workday").on(table.relatedWorkdayId, table.status)
1434
+ ]);
1435
+ const commerceServiceQuotes = pgTable("commerce_service_quotes", {
1436
+ id: text("id").primaryKey(),
1437
+ requestId: text("request_id").notNull(),
1438
+ vendorId: text("vendor_id").notNull(),
1439
+ sellerTeamId: text("seller_team_id").notNull(),
1440
+ buyerTeamId: text("buyer_team_id"),
1441
+ buyerUserId: text("buyer_user_id"),
1442
+ quoteVersion: integer("quote_version").notNull().default(1),
1443
+ status: text("status").notNull().default("draft"),
1444
+ title: text("title").notNull(),
1445
+ scopeSummary: text("scope_summary").notNull(),
1446
+ deliverablesJson: text("deliverables_json").notNull().default("[]"),
1447
+ assumptionsJson: text("assumptions_json").notNull().default("[]"),
1448
+ accessRequirementsJson: text("access_requirements_json").notNull().default("{}"),
1449
+ governanceRequirementsJson: text("governance_requirements_json").notNull().default("{}"),
1450
+ amount: integer("amount").notNull(),
1451
+ currency: text("currency").notNull(),
1452
+ expiresAt: text("expires_at"),
1453
+ buyerApprovedAt: text("buyer_approved_at"),
1454
+ vendorApprovedAt: text("vendor_approved_at"),
1455
+ acceptedAt: text("accepted_at"),
1456
+ rejectedAt: text("rejected_at"),
1457
+ metadataJson: text("metadata_json").notNull().default("{}"),
1458
+ createdAt: text("created_at").notNull(),
1459
+ updatedAt: text("updated_at").notNull()
1460
+ }, (table) => [
1461
+ uniqueIndex("idx_commerce_service_quotes_request_version").on(table.requestId, table.quoteVersion),
1462
+ index("idx_commerce_service_quotes_request").on(table.requestId, table.status, table.updatedAt),
1463
+ index("idx_commerce_service_quotes_vendor").on(table.vendorId, table.status, table.updatedAt),
1464
+ index("idx_commerce_service_quotes_seller").on(table.sellerTeamId, table.status, table.updatedAt)
1465
+ ]);
1466
+ const commerceServiceContracts = pgTable("commerce_service_contracts", {
1467
+ id: text("id").primaryKey(),
1468
+ requestId: text("request_id").notNull(),
1469
+ quoteId: text("quote_id").notNull(),
1470
+ vendorId: text("vendor_id").notNull(),
1471
+ sellerTeamId: text("seller_team_id").notNull(),
1472
+ buyerTeamId: text("buyer_team_id"),
1473
+ buyerUserId: text("buyer_user_id"),
1474
+ productId: text("product_id").notNull(),
1475
+ offerId: text("offer_id").notNull(),
1476
+ status: text("status").notNull().default("pending_checkout"),
1477
+ amount: integer("amount").notNull(),
1478
+ currency: text("currency").notNull(),
1479
+ orderId: text("order_id"),
1480
+ orderItemId: text("order_item_id"),
1481
+ paymentGroupId: text("payment_group_id"),
1482
+ entitlementId: text("entitlement_id"),
1483
+ relatedProjectId: text("related_project_id"),
1484
+ relatedWorkdayId: text("related_workday_id"),
1485
+ ownershipSnapshotJson: text("ownership_snapshot_json").notNull().default("{}"),
1486
+ accessApprovalSnapshotJson: text("access_approval_snapshot_json").notNull().default("{}"),
1487
+ fulfillmentSummary: text("fulfillment_summary"),
1488
+ metadataJson: text("metadata_json").notNull().default("{}"),
1489
+ createdAt: text("created_at").notNull(),
1490
+ updatedAt: text("updated_at").notNull()
1491
+ }, (table) => [
1492
+ uniqueIndex("idx_commerce_service_contracts_request_quote").on(table.requestId, table.quoteId),
1493
+ index("idx_commerce_service_contracts_vendor").on(table.vendorId, table.status, table.updatedAt),
1494
+ index("idx_commerce_service_contracts_seller").on(table.sellerTeamId, table.status, table.updatedAt),
1495
+ index("idx_commerce_service_contracts_buyer_team").on(table.buyerTeamId, table.status, table.updatedAt),
1496
+ index("idx_commerce_service_contracts_buyer_user").on(table.buyerUserId, table.status, table.updatedAt),
1497
+ index("idx_commerce_service_contracts_order").on(table.orderId),
1498
+ index("idx_commerce_service_contracts_entitlement").on(table.entitlementId),
1499
+ index("idx_commerce_service_contracts_project").on(table.relatedProjectId),
1500
+ index("idx_commerce_service_contracts_workday").on(table.relatedWorkdayId)
1501
+ ]);
1502
+ const commerceServiceEvents = pgTable("commerce_service_events", {
1503
+ id: text("id").primaryKey(),
1504
+ requestId: text("request_id").notNull(),
1505
+ quoteId: text("quote_id"),
1506
+ contractId: text("contract_id"),
1507
+ eventType: text("event_type").notNull(),
1508
+ actorType: text("actor_type").notNull(),
1509
+ actorId: text("actor_id"),
1510
+ priorState: text("prior_state"),
1511
+ nextState: text("next_state"),
1512
+ message: text("message"),
1513
+ evidenceJson: text("evidence_json").notNull().default("{}"),
1514
+ createdAt: text("created_at").notNull()
1515
+ }, (table) => [
1516
+ index("idx_commerce_service_events_request").on(table.requestId, table.createdAt),
1517
+ index("idx_commerce_service_events_quote").on(table.quoteId, table.createdAt),
1518
+ index("idx_commerce_service_events_contract").on(table.contractId, table.createdAt),
1519
+ index("idx_commerce_service_events_type").on(table.eventType, table.createdAt)
1520
+ ]);
1521
+ const commerceCapacityListings = pgTable("commerce_capacity_listings", {
1522
+ id: text("id").primaryKey(),
1523
+ productId: text("product_id").notNull(),
1524
+ vendorId: text("vendor_id").notNull(),
1525
+ sellerTeamId: text("seller_team_id").notNull(),
1526
+ capacityProviderId: text("capacity_provider_id"),
1527
+ capacityProviderLaneId: text("capacity_provider_lane_id"),
1528
+ status: text("status").notNull().default("draft"),
1529
+ accessLevel: text("access_level").notNull().default("public_summary"),
1530
+ runtimeIsolationLevel: text("runtime_isolation_level").notNull().default("none"),
1531
+ humanInvolvementLevel: text("human_involvement_level").notNull().default("none"),
1532
+ aiInvolvementLevel: text("ai_involvement_level").notNull().default("none"),
1533
+ dataAccessLevel: text("data_access_level").notNull().default("none"),
1534
+ secretAccessLevel: text("secret_access_level").notNull().default("none"),
1535
+ supportedServiceTypesJson: text("supported_service_types_json").notNull().default("[]"),
1536
+ supportedRegionsJson: text("supported_regions_json").notNull().default("[]"),
1537
+ runtimeRequirementsJson: text("runtime_requirements_json").notNull().default("{}"),
1538
+ dataHandlingSummary: text("data_handling_summary"),
1539
+ buyerVisibleRiskSummary: text("buyer_visible_risk_summary"),
1540
+ governanceRequirementsJson: text("governance_requirements_json").notNull().default("{}"),
1541
+ supportPolicy: text("support_policy"),
1542
+ availabilitySummary: text("availability_summary"),
1543
+ ownershipSnapshotJson: text("ownership_snapshot_json").notNull().default("{}"),
1544
+ metadataJson: text("metadata_json").notNull().default("{}"),
1545
+ createdAt: text("created_at").notNull(),
1546
+ updatedAt: text("updated_at").notNull()
1547
+ }, (table) => [
1548
+ uniqueIndex("idx_commerce_capacity_listings_product").on(table.productId),
1549
+ index("idx_commerce_capacity_listings_vendor_status").on(table.vendorId, table.status, table.updatedAt),
1550
+ index("idx_commerce_capacity_listings_seller_status").on(table.sellerTeamId, table.status, table.updatedAt),
1551
+ index("idx_commerce_capacity_listings_provider_status").on(table.capacityProviderId, table.status),
1552
+ index("idx_commerce_capacity_listings_lane_status").on(table.capacityProviderLaneId, table.status),
1553
+ index("idx_commerce_capacity_listings_access_status").on(table.accessLevel, table.status, table.updatedAt)
1554
+ ]);
1555
+ const commerceCapacityListingInquiries = pgTable("commerce_capacity_listing_inquiries", {
1556
+ id: text("id").primaryKey(),
1557
+ listingId: text("listing_id").notNull(),
1558
+ productId: text("product_id").notNull(),
1559
+ vendorId: text("vendor_id").notNull(),
1560
+ sellerTeamId: text("seller_team_id").notNull(),
1561
+ buyerTeamId: text("buyer_team_id"),
1562
+ buyerUserId: text("buyer_user_id"),
1563
+ status: text("status").notNull().default("requested"),
1564
+ requestedServiceType: text("requested_service_type"),
1565
+ requestedScope: text("requested_scope").notNull(),
1566
+ dataAccessRequestedJson: text("data_access_requested_json").notNull().default("{}"),
1567
+ secretAccessRequestedJson: text("secret_access_requested_json").notNull().default("{}"),
1568
+ relatedProjectId: text("related_project_id"),
1569
+ relatedWorkdayId: text("related_workday_id"),
1570
+ governanceEvidenceJson: text("governance_evidence_json").notNull().default("{}"),
1571
+ metadataJson: text("metadata_json").notNull().default("{}"),
1572
+ createdAt: text("created_at").notNull(),
1573
+ updatedAt: text("updated_at").notNull()
1574
+ }, (table) => [
1575
+ index("idx_commerce_capacity_inquiries_listing_status").on(table.listingId, table.status, table.updatedAt),
1576
+ index("idx_commerce_capacity_inquiries_buyer_team").on(table.buyerTeamId, table.status, table.updatedAt),
1577
+ index("idx_commerce_capacity_inquiries_buyer_user").on(table.buyerUserId, table.status, table.updatedAt),
1578
+ index("idx_commerce_capacity_inquiries_vendor_status").on(table.vendorId, table.status, table.updatedAt),
1579
+ index("idx_commerce_capacity_inquiries_seller_status").on(table.sellerTeamId, table.status, table.updatedAt),
1580
+ index("idx_commerce_capacity_inquiries_project").on(table.relatedProjectId, table.status),
1581
+ index("idx_commerce_capacity_inquiries_workday").on(table.relatedWorkdayId, table.status)
1582
+ ]);
1583
+ const commerceWebhookEvents = pgTable("commerce_webhook_events", {
1584
+ id: text("id").primaryKey(),
1585
+ provider: text("provider").notNull().default("stripe"),
1586
+ environment: text("environment").notNull().default("test"),
1587
+ eventId: text("event_id").notNull(),
1588
+ eventType: text("event_type").notNull(),
1589
+ connectedAccountId: text("connected_account_id"),
1590
+ status: text("status").notNull().default("received"),
1591
+ objectType: text("object_type"),
1592
+ objectId: text("object_id"),
1593
+ relatedOrderId: text("related_order_id"),
1594
+ relatedSubscriptionId: text("related_subscription_id"),
1595
+ payloadHash: text("payload_hash").notNull(),
1596
+ processingError: text("processing_error"),
1597
+ receivedAt: text("received_at").notNull(),
1598
+ processedAt: text("processed_at"),
1599
+ createdAt: text("created_at").notNull(),
1600
+ updatedAt: text("updated_at").notNull()
1601
+ }, (table) => [
1602
+ uniqueIndex("idx_commerce_webhook_events_provider_event").on(table.provider, table.environment, table.eventId),
1603
+ index("idx_commerce_webhook_events_status_received").on(table.status, table.receivedAt),
1604
+ index("idx_commerce_webhook_events_connected_type").on(table.connectedAccountId, table.eventType, table.receivedAt),
1605
+ index("idx_commerce_webhook_events_order").on(table.relatedOrderId),
1606
+ index("idx_commerce_webhook_events_subscription").on(table.relatedSubscriptionId)
1607
+ ]);
1608
+ const projectHosting = pgTable("project_hosting", {
1609
+ id: text("id").primaryKey(),
1610
+ projectId: text("project_id").notNull().unique(),
1611
+ hostingKind: text("hosting_kind").notNull(),
1612
+ registration: text("registration").notNull().default("none"),
1613
+ marketBaseUrl: text("market_base_url"),
1614
+ sourceRepoOwner: text("source_repo_owner"),
1615
+ sourceRepoName: text("source_repo_name"),
1616
+ sourceRepoUrl: text("source_repo_url"),
1617
+ sourceRepoWorkflowPath: text("source_repo_workflow_path"),
1618
+ metadataJson: text("metadata_json"),
1619
+ createdAt: text("created_at").notNull(),
1620
+ updatedAt: text("updated_at").notNull()
1621
+ });
1622
+ const projectEnvironments = pgTable("project_environments", {
585
1623
  id: text("id").primaryKey(),
586
1624
  projectId: text("project_id").notNull(),
587
- teamId: text("team_id").notNull(),
588
1625
  environment: text("environment").notNull(),
589
- name: text("name").notNull(),
590
- registrationIdentity: text("registration_identity"),
591
- serviceBaseUrl: text("service_base_url"),
592
- status: text("status").notNull().default("pending"),
593
- minWorkers: integer("min_workers").notNull().default(0),
594
- maxWorkers: integer("max_workers").notNull().default(1),
595
- targetQueueDepth: integer("target_queue_depth").notNull().default(1),
596
- cooldownSeconds: integer("cooldown_seconds").notNull().default(60),
1626
+ deploymentProfile: text("deployment_profile").notNull(),
1627
+ baseUrl: text("base_url"),
1628
+ cloudflareAccountId: text("cloudflare_account_id"),
1629
+ pagesProjectName: text("pages_project_name"),
1630
+ workerName: text("worker_name"),
1631
+ r2BucketName: text("r2_bucket_name"),
1632
+ d1DatabaseName: text("d1_database_name"),
1633
+ queueName: text("queue_name"),
1634
+ railwayProjectName: text("railway_project_name"),
597
1635
  metadataJson: text("metadata_json"),
598
1636
  createdAt: text("created_at").notNull(),
599
1637
  updatedAt: text("updated_at").notNull()
600
1638
  }, (table) => [
601
- uniqueIndex("idx_agent_pools_project_environment_name").on(table.projectId, table.environment, table.name)
1639
+ uniqueIndex("idx_project_environments_project_environment").on(table.projectId, table.environment)
602
1640
  ]);
603
- const agentPoolRegistrations = pgTable("agent_pool_registrations", {
1641
+ const projectInfrastructureResources = pgTable("project_infrastructure_resources", {
604
1642
  id: text("id").primaryKey(),
605
- poolId: text("pool_id").notNull(),
606
1643
  projectId: text("project_id").notNull(),
607
- runnerId: text("runner_id"),
608
- managerId: text("manager_id"),
609
- serviceName: text("service_name"),
610
- heartbeatAt: text("heartbeat_at").notNull(),
611
- desiredWorkers: integer("desired_workers"),
612
- observedQueueDepth: integer("observed_queue_depth"),
613
- observedActiveLeases: integer("observed_active_leases"),
1644
+ environment: text("environment").notNull(),
1645
+ provider: text("provider").notNull(),
1646
+ resourceKind: text("resource_kind").notNull(),
1647
+ logicalName: text("logical_name").notNull(),
1648
+ locator: text("locator"),
614
1649
  metadataJson: text("metadata_json"),
615
1650
  createdAt: text("created_at").notNull(),
616
1651
  updatedAt: text("updated_at").notNull()
617
1652
  }, (table) => [
618
- index("idx_agent_pool_registrations_pool_heartbeat").on(table.poolId, table.heartbeatAt)
1653
+ uniqueIndex("idx_project_infrastructure_resource_unique").on(table.projectId, table.environment, table.provider, table.resourceKind, table.logicalName)
1654
+ ]);
1655
+ const projectDeployments = pgTable("project_deployments", {
1656
+ id: text("id").primaryKey(),
1657
+ teamId: text("team_id").notNull(),
1658
+ projectId: text("project_id").notNull(),
1659
+ environment: text("environment").notNull(),
1660
+ deploymentKind: text("deployment_kind").notNull(),
1661
+ action: text("action").notNull().default("deploy_web"),
1662
+ status: text("status").notNull(),
1663
+ platformOperationId: text("platform_operation_id"),
1664
+ retryOfDeploymentId: text("retry_of_deployment_id"),
1665
+ resumedFromDeploymentId: text("resumed_from_deployment_id"),
1666
+ idempotencyKey: text("idempotency_key"),
1667
+ requestedByUserId: text("requested_by_user_id"),
1668
+ sourceRef: text("source_ref"),
1669
+ releaseTag: text("release_tag"),
1670
+ commitSha: text("commit_sha"),
1671
+ triggeredByType: text("triggered_by_type"),
1672
+ triggeredById: text("triggered_by_id"),
1673
+ repositoryJson: text("repository_json").notNull().default("{}"),
1674
+ externalWorkflowJson: text("external_workflow_json").notNull().default("{}"),
1675
+ targetJson: text("target_json").notNull().default("{}"),
1676
+ monitorJson: text("monitor_json").notNull().default("{}"),
1677
+ summary: text("summary"),
1678
+ errorJson: text("error_json").notNull().default("{}"),
1679
+ metadataJson: text("metadata_json"),
1680
+ startedAt: text("started_at"),
1681
+ finishedAt: text("finished_at"),
1682
+ createdAt: text("created_at").notNull(),
1683
+ updatedAt: text("updated_at").notNull(),
1684
+ completedAt: text("completed_at")
1685
+ }, (table) => [
1686
+ index("idx_project_deployments_project_created").on(table.projectId, table.createdAt),
1687
+ index("idx_project_deployments_project_environment").on(table.projectId, table.environment, table.createdAt),
1688
+ index("idx_project_deployments_project_status").on(table.projectId, table.status, table.updatedAt),
1689
+ index("idx_project_deployments_operation").on(table.platformOperationId),
1690
+ index("idx_project_deployments_team_created").on(table.teamId, table.createdAt),
1691
+ uniqueIndex("idx_project_deployments_idempotency").on(table.projectId, table.idempotencyKey)
1692
+ ]);
1693
+ const projectDeploymentEvents = pgTable("project_deployment_events", {
1694
+ id: text("id").primaryKey(),
1695
+ deploymentId: text("deployment_id").notNull(),
1696
+ projectId: text("project_id").notNull(),
1697
+ teamId: text("team_id").notNull(),
1698
+ operationId: text("operation_id"),
1699
+ kind: text("kind").notNull(),
1700
+ message: text("message").notNull(),
1701
+ status: text("status"),
1702
+ severity: text("severity").notNull().default("info"),
1703
+ sequence: integer("sequence").notNull(),
1704
+ payloadJson: text("payload_json").notNull().default("{}"),
1705
+ createdAt: text("created_at").notNull()
1706
+ }, (table) => [
1707
+ index("idx_project_deployment_events_deployment_sequence").on(table.deploymentId, table.sequence),
1708
+ index("idx_project_deployment_events_project_created").on(table.projectId, table.createdAt),
1709
+ index("idx_project_deployment_events_operation").on(table.operationId)
1710
+ ]);
1711
+ const agentPools = pgTable("agent_pools", {
1712
+ id: text("id").primaryKey(),
1713
+ projectId: text("project_id").notNull(),
1714
+ teamId: text("team_id").notNull(),
1715
+ environment: text("environment").notNull(),
1716
+ name: text("name").notNull(),
1717
+ registrationIdentity: text("registration_identity"),
1718
+ serviceBaseUrl: text("service_base_url"),
1719
+ status: text("status").notNull().default("pending"),
1720
+ minWorkers: integer("min_workers").notNull().default(0),
1721
+ maxWorkers: integer("max_workers").notNull().default(1),
1722
+ targetQueueDepth: integer("target_queue_depth").notNull().default(1),
1723
+ cooldownSeconds: integer("cooldown_seconds").notNull().default(60),
1724
+ metadataJson: text("metadata_json"),
1725
+ createdAt: text("created_at").notNull(),
1726
+ updatedAt: text("updated_at").notNull()
1727
+ }, (table) => [
1728
+ uniqueIndex("idx_agent_pools_project_environment_name").on(table.projectId, table.environment, table.name)
1729
+ ]);
1730
+ const agentPoolRegistrations = pgTable("agent_pool_registrations", {
1731
+ id: text("id").primaryKey(),
1732
+ poolId: text("pool_id").notNull(),
1733
+ projectId: text("project_id").notNull(),
1734
+ runnerId: text("runner_id"),
1735
+ managerId: text("manager_id"),
1736
+ serviceName: text("service_name"),
1737
+ heartbeatAt: text("heartbeat_at").notNull(),
1738
+ desiredWorkers: integer("desired_workers"),
1739
+ observedQueueDepth: integer("observed_queue_depth"),
1740
+ observedActiveLeases: integer("observed_active_leases"),
1741
+ metadataJson: text("metadata_json"),
1742
+ createdAt: text("created_at").notNull(),
1743
+ updatedAt: text("updated_at").notNull()
1744
+ }, (table) => [
1745
+ index("idx_agent_pool_registrations_pool_heartbeat").on(table.poolId, table.heartbeatAt)
1746
+ ]);
1747
+ const agentPoolScaleDecisions = pgTable("agent_pool_scale_decisions", {
1748
+ id: text("id").primaryKey(),
1749
+ poolId: text("pool_id").notNull(),
1750
+ projectId: text("project_id").notNull(),
1751
+ environment: text("environment").notNull(),
1752
+ desiredWorkers: integer("desired_workers").notNull(),
1753
+ observedQueueDepth: integer("observed_queue_depth").notNull().default(0),
1754
+ observedActiveLeases: integer("observed_active_leases").notNull().default(0),
1755
+ workDayId: text("work_day_id"),
1756
+ reason: text("reason").notNull(),
1757
+ metadataJson: text("metadata_json").notNull(),
1758
+ createdAt: text("created_at").notNull(),
1759
+ updatedAt: text("updated_at").notNull()
1760
+ }, (table) => [
1761
+ index("idx_agent_pool_scale_decisions_pool_created").on(table.poolId, table.createdAt)
1762
+ ]);
1763
+ const projectWorkdaySummaries = pgTable("project_workday_summaries", {
1764
+ id: text("id").primaryKey(),
1765
+ projectId: text("project_id").notNull(),
1766
+ environment: text("environment").notNull(),
1767
+ workDayId: text("work_day_id").notNull(),
1768
+ kind: text("kind").notNull(),
1769
+ state: text("state"),
1770
+ startedAt: text("started_at"),
1771
+ endedAt: text("ended_at"),
1772
+ summaryJson: text("summary_json").notNull(),
1773
+ metadataJson: text("metadata_json").notNull(),
1774
+ createdAt: text("created_at").notNull(),
1775
+ updatedAt: text("updated_at").notNull()
1776
+ }, (table) => [
1777
+ index("idx_project_workday_summaries_project_environment_created").on(table.projectId, table.environment, table.createdAt)
1778
+ ]);
1779
+ const workPolicies = pgTable("work_policies", {
1780
+ projectId: text("project_id"),
1781
+ environment: text("environment"),
1782
+ scheduleJson: text("schedule_json").notNull(),
1783
+ dailyTaskCreditBudget: integer("daily_task_credit_budget").notNull().default(0),
1784
+ maxQueuedTasks: integer("max_queued_tasks").notNull().default(0),
1785
+ maxQueuedCredits: integer("max_queued_credits").notNull().default(0),
1786
+ autoscaleJson: text("autoscale_json").notNull(),
1787
+ creditWeightsJson: text("credit_weights_json").notNull(),
1788
+ metadataJson: text("metadata_json").notNull(),
1789
+ createdAt: text("created_at").notNull(),
1790
+ updatedAt: text("updated_at").notNull(),
1791
+ enabled: integer("enabled").notNull().default(1),
1792
+ startCron: text("start_cron").notNull().default("0 9 * * 1-5"),
1793
+ durationMinutes: integer("duration_minutes").notNull().default(480),
1794
+ maxRunners: integer("max_runners").notNull().default(1),
1795
+ maxWorkersPerRunner: integer("max_workers_per_runner").notNull().default(4),
1796
+ dailyCreditBudget: integer("daily_credit_budget").notNull().default(0),
1797
+ closeoutGraceMinutes: integer("closeout_grace_minutes").notNull().default(15)
1798
+ }, (table) => [
1799
+ primaryKey({ columns: [table.projectId, table.environment] })
1800
+ ]);
1801
+ const priorityOverrides = pgTable("priority_overrides", {
1802
+ id: text("id").primaryKey(),
1803
+ projectId: text("project_id").notNull(),
1804
+ model: text("model").notNull(),
1805
+ subjectId: text("subject_id").notNull(),
1806
+ priority: real("priority").notNull().default(0),
1807
+ estimatedCredits: real("estimated_credits"),
1808
+ metadataJson: text("metadata_json").notNull(),
1809
+ createdAt: text("created_at").notNull(),
1810
+ updatedAt: text("updated_at").notNull()
1811
+ }, (table) => [
1812
+ index("idx_priority_overrides_project_priority").on(table.projectId, table.priority, table.updatedAt)
1813
+ ]);
1814
+ const prioritySnapshots = pgTable("priority_snapshots", {
1815
+ id: text("id").primaryKey(),
1816
+ projectId: text("project_id").notNull(),
1817
+ workDayId: text("work_day_id"),
1818
+ snapshotJson: text("snapshot_json").notNull(),
1819
+ metadataJson: text("metadata_json").notNull(),
1820
+ generatedAt: text("generated_at").notNull(),
1821
+ createdAt: text("created_at").notNull(),
1822
+ updatedAt: text("updated_at").notNull()
1823
+ }, (table) => [
1824
+ index("idx_priority_snapshots_project_generated").on(table.projectId, table.generatedAt)
1825
+ ]);
1826
+ const taskCreditLedger = pgTable("task_credit_ledger", {
1827
+ id: text("id").primaryKey(),
1828
+ projectId: text("project_id").notNull(),
1829
+ workDayId: text("work_day_id").notNull(),
1830
+ taskId: text("task_id"),
1831
+ phase: text("phase").notNull(),
1832
+ credits: real("credits").notNull(),
1833
+ metadataJson: text("metadata_json").notNull(),
1834
+ createdAt: text("created_at").notNull()
1835
+ }, (table) => [
1836
+ index("idx_task_credit_ledger_work_day_created").on(table.workDayId, table.createdAt)
1837
+ ]);
1838
+ const scaleDecisions = pgTable("scale_decisions", {
1839
+ id: text("id").primaryKey(),
1840
+ projectId: text("project_id").notNull(),
1841
+ environment: text("environment").notNull(),
1842
+ poolName: text("pool_name").notNull(),
1843
+ workDayId: text("work_day_id"),
1844
+ desiredWorkers: integer("desired_workers").notNull(),
1845
+ observedQueueDepth: integer("observed_queue_depth").notNull().default(0),
1846
+ observedActiveLeases: integer("observed_active_leases").notNull().default(0),
1847
+ reason: text("reason").notNull(),
1848
+ metadataJson: text("metadata_json").notNull(),
1849
+ createdAt: text("created_at").notNull()
1850
+ }, (table) => [
1851
+ index("idx_scale_decisions_project_environment_pool_created").on(table.projectId, table.environment, table.poolName, table.createdAt)
1852
+ ]);
1853
+ const projectSummarySnapshots = pgTable("project_summary_snapshots", {
1854
+ projectId: text("project_id").primaryKey(),
1855
+ teamId: text("team_id").notNull(),
1856
+ summaryJson: text("summary_json").notNull(),
1857
+ generatedAt: text("generated_at").notNull(),
1858
+ createdAt: text("created_at").notNull(),
1859
+ updatedAt: text("updated_at").notNull()
1860
+ }, (table) => [
1861
+ index("idx_project_summary_snapshots_team_generated").on(table.teamId, table.generatedAt)
1862
+ ]);
1863
+ const teamInboxItems = pgTable("team_inbox_items", {
1864
+ id: text("id").primaryKey(),
1865
+ teamId: text("team_id").notNull(),
1866
+ projectId: text("project_id"),
1867
+ kind: text("kind").notNull(),
1868
+ state: text("state").notNull(),
1869
+ title: text("title").notNull(),
1870
+ summary: text("summary"),
1871
+ href: text("href"),
1872
+ itemKey: text("item_key"),
1873
+ metadataJson: text("metadata_json").notNull().default("{}"),
1874
+ createdAt: text("created_at").notNull(),
1875
+ updatedAt: text("updated_at").notNull()
1876
+ }, (table) => [
1877
+ index("idx_team_inbox_items_team_created").on(table.teamId, table.createdAt)
1878
+ ]);
1879
+ const betterAuthUser = pgTable("better_auth_user", {
1880
+ id: text("id").primaryKey(),
1881
+ name: text("name").notNull(),
1882
+ email: text("email").notNull().unique(),
1883
+ emailVerified: integer("emailVerified").notNull().default(0),
1884
+ image: text("image"),
1885
+ createdAt: bigint("createdAt", { mode: "number" }).notNull(),
1886
+ updatedAt: bigint("updatedAt", { mode: "number" }).notNull(),
1887
+ username: text("username"),
1888
+ firstName: text("firstName"),
1889
+ lastName: text("lastName")
1890
+ }, (table) => [
1891
+ uniqueIndex("idx_better_auth_user_username").on(table.username)
1892
+ ]);
1893
+ const betterAuthSession = pgTable("better_auth_session", {
1894
+ id: text("id").primaryKey(),
1895
+ expiresAt: bigint("expiresAt", { mode: "number" }).notNull(),
1896
+ token: text("token").notNull().unique(),
1897
+ createdAt: bigint("createdAt", { mode: "number" }).notNull(),
1898
+ updatedAt: bigint("updatedAt", { mode: "number" }).notNull(),
1899
+ ipAddress: text("ipAddress"),
1900
+ userAgent: text("userAgent"),
1901
+ userId: text("userId").notNull()
1902
+ }, (table) => [
1903
+ index("idx_better_auth_session_token").on(table.token),
1904
+ index("idx_better_auth_session_userId").on(table.userId)
1905
+ ]);
1906
+ const betterAuthAccount = pgTable("better_auth_account", {
1907
+ id: text("id").primaryKey(),
1908
+ accountId: text("accountId").notNull(),
1909
+ providerId: text("providerId").notNull(),
1910
+ userId: text("userId").notNull(),
1911
+ accessToken: text("accessToken"),
1912
+ refreshToken: text("refreshToken"),
1913
+ idToken: text("idToken"),
1914
+ accessTokenExpiresAt: bigint("accessTokenExpiresAt", { mode: "number" }),
1915
+ refreshTokenExpiresAt: bigint("refreshTokenExpiresAt", { mode: "number" }),
1916
+ scope: text("scope"),
1917
+ password: text("password"),
1918
+ createdAt: bigint("createdAt", { mode: "number" }).notNull(),
1919
+ updatedAt: bigint("updatedAt", { mode: "number" }).notNull()
1920
+ }, (table) => [
1921
+ index("idx_better_auth_account_userId").on(table.userId),
1922
+ uniqueIndex("idx_better_auth_account_provider_account").on(table.providerId, table.accountId)
1923
+ ]);
1924
+ const betterAuthVerification = pgTable("better_auth_verification", {
1925
+ id: text("id").primaryKey(),
1926
+ identifier: text("identifier").notNull(),
1927
+ value: text("value").notNull(),
1928
+ expiresAt: bigint("expiresAt", { mode: "number" }).notNull(),
1929
+ createdAt: bigint("createdAt", { mode: "number" }).notNull(),
1930
+ updatedAt: bigint("updatedAt", { mode: "number" }).notNull()
1931
+ }, (table) => [
1932
+ index("idx_better_auth_verification_identifier").on(table.identifier)
1933
+ ]);
1934
+ const teamWebHosts = pgTable("team_web_hosts", {
1935
+ id: text("id").primaryKey(),
1936
+ teamId: text("team_id").notNull(),
1937
+ provider: text("provider").notNull(),
1938
+ ownership: text("ownership").notNull(),
1939
+ name: text("name").notNull(),
1940
+ accountLabel: text("account_label"),
1941
+ allowedEnvironmentsJson: text("allowed_environments_json").notNull().default("[]"),
1942
+ status: text("status").notNull().default("active"),
1943
+ encryptedPayloadJson: text("encrypted_payload_json"),
1944
+ metadataJson: text("metadata_json"),
1945
+ createdById: text("created_by_id"),
1946
+ updatedById: text("updated_by_id"),
1947
+ createdAt: text("created_at").notNull(),
1948
+ updatedAt: text("updated_at").notNull()
1949
+ }, (table) => [
1950
+ index("idx_team_web_hosts_team_provider").on(table.teamId, table.provider, table.status),
1951
+ uniqueIndex("idx_team_web_hosts_team_provider_name").on(table.teamId, table.provider, table.name)
1952
+ ]);
1953
+ const teamInvites = pgTable("team_invites", {
1954
+ id: text("id").primaryKey(),
1955
+ teamId: text("team_id").notNull(),
1956
+ email: text("email").notNull(),
1957
+ roleKey: text("role_key").notNull(),
1958
+ tokenPrefix: text("token_prefix").notNull(),
1959
+ tokenHash: text("token_hash").notNull(),
1960
+ status: text("status").notNull().default("pending"),
1961
+ invitedByUserId: text("invited_by_user_id"),
1962
+ acceptedByUserId: text("accepted_by_user_id"),
1963
+ acceptedAt: text("accepted_at"),
1964
+ expiresAt: text("expires_at").notNull(),
1965
+ createdAt: text("created_at").notNull(),
1966
+ updatedAt: text("updated_at").notNull()
1967
+ }, (table) => [
1968
+ index("idx_team_invites_team_status").on(table.teamId, table.status, table.createdAt),
1969
+ index("idx_team_invites_token_prefix").on(table.tokenPrefix)
1970
+ ]);
1971
+ const capacityProviders = pgTable("capacity_providers", {
1972
+ id: text("id").primaryKey(),
1973
+ teamId: text("team_id"),
1974
+ ownerTeamId: text("owner_team_id"),
1975
+ name: text("name").notNull(),
1976
+ kind: text("kind").notNull(),
1977
+ status: text("status").notNull().default("pending"),
1978
+ provider: text("provider").notNull(),
1979
+ billingScope: text("billing_scope").notNull().default("team"),
1980
+ monthlyCreditBudget: real("monthly_credit_budget").notNull().default(0),
1981
+ dailyCreditBudget: real("daily_credit_budget").notNull().default(0),
1982
+ creditBudgetMode: text("credit_budget_mode").notNull().default("derived"),
1983
+ maxConcurrentWorkdays: integer("max_concurrent_workdays").notNull().default(1),
1984
+ maxConcurrentWorkers: integer("max_concurrent_workers").notNull().default(1),
1985
+ capacityModelJson: text("capacity_model_json").notNull().default("{}"),
1986
+ metadataJson: text("metadata_json").notNull().default("{}"),
1987
+ createdAt: text("created_at").notNull(),
1988
+ updatedAt: text("updated_at").notNull()
1989
+ }, (table) => [
1990
+ index("idx_capacity_providers_team_status").on(table.teamId, table.status, table.provider)
1991
+ ]);
1992
+ const capacityProviderHosts = pgTable("capacity_provider_hosts", {
1993
+ id: text("id").primaryKey(),
1994
+ capacityProviderId: text("capacity_provider_id").notNull(),
1995
+ hostId: text("host_id").notNull(),
1996
+ role: text("role").notNull(),
1997
+ required: integer("required").notNull().default(1),
1998
+ metadataJson: text("metadata_json").notNull().default("{}"),
1999
+ createdAt: text("created_at").notNull(),
2000
+ updatedAt: text("updated_at").notNull()
2001
+ }, (table) => [
2002
+ uniqueIndex("idx_capacity_provider_hosts_unique").on(table.capacityProviderId, table.hostId, table.role)
2003
+ ]);
2004
+ const capacityProviderLanes = pgTable("capacity_provider_lanes", {
2005
+ id: text("id").primaryKey(),
2006
+ capacityProviderId: text("capacity_provider_id").notNull(),
2007
+ name: text("name").notNull(),
2008
+ businessModel: text("business_model").notNull().default("custom"),
2009
+ modelFamily: text("model_family"),
2010
+ modelClass: text("model_class"),
2011
+ regionPolicy: text("region_policy"),
2012
+ unit: text("unit").notNull().default("treeseed_credit"),
2013
+ scarcityLevel: text("scarcity_level").notNull().default("medium"),
2014
+ hardLimitsJson: text("hard_limits_json").notNull().default("{}"),
2015
+ routingPolicyJson: text("routing_policy_json").notNull().default("{}"),
2016
+ metadataJson: text("metadata_json").notNull().default("{}"),
2017
+ createdAt: text("created_at").notNull(),
2018
+ updatedAt: text("updated_at").notNull()
2019
+ }, (table) => [
2020
+ index("idx_capacity_provider_lanes_provider").on(table.capacityProviderId, table.businessModel, table.scarcityLevel)
2021
+ ]);
2022
+ const capacityGrants = pgTable("capacity_grants", {
2023
+ id: text("id").primaryKey(),
2024
+ capacityProviderId: text("capacity_provider_id").notNull(),
2025
+ laneId: text("lane_id"),
2026
+ grantScope: text("grant_scope").notNull().default("team"),
2027
+ teamId: text("team_id").notNull(),
2028
+ projectId: text("project_id"),
2029
+ environment: text("environment"),
2030
+ state: text("state").notNull().default("active"),
2031
+ dailyCreditLimit: real("daily_credit_limit"),
2032
+ weeklyCreditLimit: real("weekly_credit_limit"),
2033
+ monthlyCreditLimit: real("monthly_credit_limit"),
2034
+ dailyUsdLimit: real("daily_usd_limit"),
2035
+ weeklyQuotaMinutes: real("weekly_quota_minutes"),
2036
+ monthlyProviderUnits: real("monthly_provider_units"),
2037
+ priorityWeight: real("priority_weight").notNull().default(1),
2038
+ overflowPolicy: text("overflow_policy").notNull().default("soft_grant"),
2039
+ metadataJson: text("metadata_json").notNull().default("{}"),
2040
+ createdAt: text("created_at").notNull(),
2041
+ updatedAt: text("updated_at").notNull()
2042
+ }, (table) => [
2043
+ index("idx_capacity_grants_team_project").on(table.teamId, table.projectId, table.state),
2044
+ index("idx_capacity_grants_provider_lane").on(table.capacityProviderId, table.laneId, table.state)
2045
+ ]);
2046
+ const capacityReservations = pgTable("capacity_reservations", {
2047
+ id: text("id").primaryKey(),
2048
+ capacityProviderId: text("capacity_provider_id").notNull(),
2049
+ executionProviderId: text("execution_provider_id"),
2050
+ laneId: text("lane_id").notNull(),
2051
+ allocationSetId: text("allocation_set_id"),
2052
+ projectAgentClassId: text("project_agent_class_id"),
2053
+ assignmentId: text("assignment_id"),
2054
+ mode: text("mode"),
2055
+ teamId: text("team_id").notNull(),
2056
+ projectId: text("project_id").notNull(),
2057
+ workDayId: text("work_day_id"),
2058
+ taskId: text("task_id"),
2059
+ state: text("state").notNull().default("reserved"),
2060
+ reservedCredits: real("reserved_credits").notNull(),
2061
+ consumedCredits: real("consumed_credits").notNull().default(0),
2062
+ nativeUnit: text("native_unit"),
2063
+ reservedNativeAmount: real("reserved_native_amount"),
2064
+ consumedNativeAmount: real("consumed_native_amount"),
2065
+ reservedProviderUnits: real("reserved_provider_units"),
2066
+ consumedProviderUnits: real("consumed_provider_units"),
2067
+ reservedUsd: real("reserved_usd"),
2068
+ consumedUsd: real("consumed_usd"),
2069
+ expiresAt: text("expires_at"),
2070
+ metadataJson: text("metadata_json").notNull().default("{}"),
2071
+ createdAt: text("created_at").notNull(),
2072
+ updatedAt: text("updated_at").notNull()
2073
+ }, (table) => [
2074
+ index("idx_capacity_reservations_project_workday_state").on(table.projectId, table.workDayId, table.state, table.createdAt),
2075
+ index("idx_capacity_reservations_provider_state").on(table.capacityProviderId, table.laneId, table.state),
2076
+ index("idx_capacity_reservations_execution_provider_state").on(table.executionProviderId, table.state, table.createdAt)
2077
+ ]);
2078
+ const capacityLedgerEntries = pgTable("capacity_ledger_entries", {
2079
+ id: text("id").primaryKey(),
2080
+ capacityProviderId: text("capacity_provider_id").notNull(),
2081
+ laneId: text("lane_id"),
2082
+ reservationId: text("reservation_id"),
2083
+ assignmentId: text("assignment_id"),
2084
+ modeRunId: text("mode_run_id"),
2085
+ mode: text("mode"),
2086
+ teamId: text("team_id").notNull(),
2087
+ projectId: text("project_id"),
2088
+ workDayId: text("work_day_id"),
2089
+ taskId: text("task_id"),
2090
+ phase: text("phase").notNull(),
2091
+ credits: real("credits").notNull(),
2092
+ providerUnits: real("provider_units"),
2093
+ usd: real("usd"),
2094
+ source: text("source").notNull(),
2095
+ metadataJson: text("metadata_json").notNull().default("{}"),
2096
+ createdAt: text("created_at").notNull()
2097
+ }, (table) => [
2098
+ index("idx_capacity_ledger_project_workday_created").on(table.projectId, table.workDayId, table.createdAt)
2099
+ ]);
2100
+ const capacityRoutingDecisions = pgTable("capacity_routing_decisions", {
2101
+ id: text("id").primaryKey(),
2102
+ taskId: text("task_id"),
2103
+ workDayId: text("work_day_id"),
2104
+ projectId: text("project_id").notNull(),
2105
+ selectedProviderId: text("selected_provider_id").notNull(),
2106
+ selectedLaneId: text("selected_lane_id").notNull(),
2107
+ selectedModel: text("selected_model"),
2108
+ decision: text("decision").notNull().default("selected"),
2109
+ reason: text("reason").notNull(),
2110
+ candidateJson: text("candidate_json").notNull().default("[]"),
2111
+ scoreJson: text("score_json").notNull().default("{}"),
2112
+ metadataJson: text("metadata_json").notNull().default("{}"),
2113
+ createdAt: text("created_at").notNull()
2114
+ }, (table) => [
2115
+ index("idx_capacity_routing_decisions_project_workday").on(table.projectId, table.workDayId, table.createdAt)
2116
+ ]);
2117
+ const taskEstimates = pgTable("task_estimates", {
2118
+ id: text("id").primaryKey(),
2119
+ taskId: text("task_id"),
2120
+ workDayId: text("work_day_id"),
2121
+ projectId: text("project_id").notNull(),
2122
+ estimatePhase: text("estimate_phase").notNull(),
2123
+ taskSignature: text("task_signature").notNull(),
2124
+ confidence: text("confidence").notNull(),
2125
+ estimatedCreditsP50: real("estimated_credits_p50").notNull(),
2126
+ estimatedCreditsP90: real("estimated_credits_p90").notNull(),
2127
+ reservedCredits: real("reserved_credits").notNull(),
2128
+ estimatedInputTokensP50: integer("estimated_input_tokens_p50"),
2129
+ estimatedInputTokensP90: integer("estimated_input_tokens_p90"),
2130
+ estimatedOutputTokensP50: integer("estimated_output_tokens_p50"),
2131
+ estimatedOutputTokensP90: integer("estimated_output_tokens_p90"),
2132
+ estimatedQuotaMinutesP50: real("estimated_quota_minutes_p50"),
2133
+ estimatedQuotaMinutesP90: real("estimated_quota_minutes_p90"),
2134
+ featuresJson: text("features_json").notNull().default("{}"),
2135
+ createdAt: text("created_at").notNull(),
2136
+ executionProfileId: text("execution_profile_id").notNull().default("standard-code-model")
2137
+ }, (table) => [
2138
+ index("idx_task_estimates_project_signature").on(table.projectId, table.taskSignature, table.createdAt),
2139
+ index("idx_task_estimates_project_signature_profile").on(table.projectId, table.taskSignature, table.executionProfileId, table.createdAt)
2140
+ ]);
2141
+ const taskUsageActuals = pgTable("task_usage_actuals", {
2142
+ id: text("id").primaryKey(),
2143
+ taskId: text("task_id"),
2144
+ workDayId: text("work_day_id"),
2145
+ projectId: text("project_id").notNull(),
2146
+ taskSignature: text("task_signature").notNull(),
2147
+ assignmentId: text("assignment_id"),
2148
+ modeRunId: text("mode_run_id"),
2149
+ mode: text("mode"),
2150
+ capacityProviderId: text("capacity_provider_id"),
2151
+ executionProviderId: text("execution_provider_id"),
2152
+ laneId: text("lane_id"),
2153
+ businessModel: text("business_model").notNull(),
2154
+ modelName: text("model_name"),
2155
+ inputTokens: integer("input_tokens"),
2156
+ outputTokens: integer("output_tokens"),
2157
+ cachedInputTokens: integer("cached_input_tokens"),
2158
+ quotaMinutes: real("quota_minutes"),
2159
+ wallMinutes: real("wall_minutes"),
2160
+ filesOpened: integer("files_opened"),
2161
+ filesChanged: integer("files_changed"),
2162
+ diffLinesAdded: integer("diff_lines_added"),
2163
+ diffLinesRemoved: integer("diff_lines_removed"),
2164
+ testRuns: integer("test_runs"),
2165
+ retryCount: integer("retry_count"),
2166
+ actualCredits: real("actual_credits").notNull(),
2167
+ actualUsd: real("actual_usd"),
2168
+ creditFormulaVersion: text("credit_formula_version").notNull().default("treeseed.actual-credits.v1"),
2169
+ actualCreditSource: text("actual_credit_source").notNull().default("central_calculator"),
2170
+ nativeUsageJson: text("native_usage_json").notNull().default("{}"),
2171
+ metadataJson: text("metadata_json").notNull().default("{}"),
2172
+ createdAt: text("created_at").notNull(),
2173
+ executionProfileId: text("execution_profile_id").notNull().default("standard-code-model")
2174
+ }, (table) => [
2175
+ index("idx_task_usage_actuals_project_signature").on(table.projectId, table.taskSignature, table.createdAt),
2176
+ index("idx_task_usage_actuals_project_signature_profile").on(table.projectId, table.taskSignature, table.executionProfileId, table.createdAt),
2177
+ index("idx_task_usage_actuals_execution_provider").on(table.executionProviderId, table.createdAt)
2178
+ ]);
2179
+ const nativeUsageObservations = pgTable("native_usage_observations", {
2180
+ id: text("id").primaryKey(),
2181
+ taskUsageActualId: text("task_usage_actual_id"),
2182
+ taskId: text("task_id"),
2183
+ workDayId: text("work_day_id"),
2184
+ projectId: text("project_id").notNull(),
2185
+ taskSignature: text("task_signature").notNull(),
2186
+ executionProfileId: text("execution_profile_id").notNull().default("standard-code-model"),
2187
+ capacityProviderId: text("capacity_provider_id"),
2188
+ executionProviderId: text("execution_provider_id"),
2189
+ nativeUnit: text("native_unit"),
2190
+ nativeUsageJson: text("native_usage_json").notNull().default("{}"),
2191
+ observedAt: text("observed_at").notNull(),
2192
+ source: text("source").notNull().default("provider_report"),
2193
+ formulaVersion: text("formula_version").notNull().default("treeseed.actual-credits.v1"),
2194
+ actualCredits: real("actual_credits").notNull(),
2195
+ metadataJson: text("metadata_json").notNull().default("{}"),
2196
+ createdAt: text("created_at").notNull()
2197
+ }, (table) => [
2198
+ index("idx_native_usage_observations_profile").on(table.projectId, table.taskSignature, table.executionProfileId, table.createdAt),
2199
+ index("idx_native_usage_observations_provider").on(table.executionProviderId, table.createdAt)
619
2200
  ]);
620
- const agentPoolScaleDecisions = pgTable("agent_pool_scale_decisions", {
2201
+ const capacityAllocationSets = pgTable("capacity_allocation_sets", {
621
2202
  id: text("id").primaryKey(),
622
- poolId: text("pool_id").notNull(),
623
- projectId: text("project_id").notNull(),
624
- environment: text("environment").notNull(),
625
- desiredWorkers: integer("desired_workers").notNull(),
626
- observedQueueDepth: integer("observed_queue_depth").notNull().default(0),
627
- observedActiveLeases: integer("observed_active_leases").notNull().default(0),
628
- workDayId: text("work_day_id"),
629
- reason: text("reason").notNull(),
630
- metadataJson: text("metadata_json").notNull(),
2203
+ teamId: text("team_id").notNull(),
2204
+ version: text("version").notNull(),
2205
+ status: text("status").notNull().default("draft"),
2206
+ effectiveFrom: text("effective_from"),
2207
+ effectiveUntil: text("effective_until"),
2208
+ policyJson: text("policy_json").notNull().default("{}"),
2209
+ slicesJson: text("slices_json").notNull().default("[]"),
2210
+ metadataJson: text("metadata_json").notNull().default("{}"),
2211
+ createdById: text("created_by_id"),
2212
+ activatedAt: text("activated_at"),
2213
+ supersededById: text("superseded_by_id"),
631
2214
  createdAt: text("created_at").notNull(),
632
2215
  updatedAt: text("updated_at").notNull()
633
2216
  }, (table) => [
634
- index("idx_agent_pool_scale_decisions_pool_created").on(table.poolId, table.createdAt)
2217
+ index("idx_capacity_allocation_sets_team_status").on(table.teamId, table.status, table.version),
2218
+ index("idx_capacity_allocation_sets_team_created").on(table.teamId, table.createdAt)
635
2219
  ]);
636
- const projectWorkdaySummaries = pgTable("project_workday_summaries", {
2220
+ const projectAgentClasses = pgTable("project_agent_classes", {
637
2221
  id: text("id").primaryKey(),
2222
+ teamId: text("team_id").notNull(),
638
2223
  projectId: text("project_id").notNull(),
639
- environment: text("environment").notNull(),
640
- workDayId: text("work_day_id").notNull(),
641
- kind: text("kind").notNull(),
642
- state: text("state"),
643
- startedAt: text("started_at"),
644
- endedAt: text("ended_at"),
645
- summaryJson: text("summary_json").notNull(),
646
- metadataJson: text("metadata_json").notNull(),
2224
+ slug: text("slug").notNull(),
2225
+ name: text("name").notNull(),
2226
+ status: text("status").notNull().default("active"),
2227
+ allowedModesJson: text("allowed_modes_json").notNull().default("[]"),
2228
+ requiredCapabilitiesJson: text("required_capabilities_json").notNull().default("[]"),
2229
+ kernelProfileJson: text("kernel_profile_json").notNull().default("{}"),
2230
+ kernelPolicyJson: text("kernel_policy_json").notNull().default("{}"),
2231
+ handlerRefsJson: text("handler_refs_json").notNull().default("{}"),
2232
+ outputContractsJson: text("output_contracts_json").notNull().default("{}"),
2233
+ metadataJson: text("metadata_json").notNull().default("{}"),
647
2234
  createdAt: text("created_at").notNull(),
648
2235
  updatedAt: text("updated_at").notNull()
649
2236
  }, (table) => [
650
- index("idx_project_workday_summaries_project_environment_created").on(table.projectId, table.environment, table.createdAt)
2237
+ uniqueIndex("idx_project_agent_classes_project_slug").on(table.projectId, table.slug),
2238
+ index("idx_project_agent_classes_team_project").on(table.teamId, table.projectId, table.status)
651
2239
  ]);
652
- const workPolicies = pgTable("work_policies", {
653
- projectId: text("project_id"),
2240
+ const providerAvailabilitySessions = pgTable("provider_availability_sessions", {
2241
+ id: text("id").primaryKey(),
2242
+ teamId: text("team_id").notNull(),
2243
+ capacityProviderId: text("capacity_provider_id").notNull(),
2244
+ registrationId: text("registration_id"),
654
2245
  environment: text("environment"),
655
- scheduleJson: text("schedule_json").notNull(),
656
- dailyTaskCreditBudget: integer("daily_task_credit_budget").notNull().default(0),
657
- maxQueuedTasks: integer("max_queued_tasks").notNull().default(0),
658
- maxQueuedCredits: integer("max_queued_credits").notNull().default(0),
659
- autoscaleJson: text("autoscale_json").notNull(),
660
- creditWeightsJson: text("credit_weights_json").notNull(),
661
- metadataJson: text("metadata_json").notNull(),
2246
+ status: text("status").notNull().default("open"),
2247
+ checkedInAt: text("checked_in_at").notNull(),
2248
+ availableFrom: text("available_from"),
2249
+ availableUntil: text("available_until"),
2250
+ executionProvidersJson: text("execution_providers_json").notNull().default("[]"),
2251
+ capabilitiesJson: text("capabilities_json").notNull().default("[]"),
2252
+ grantsJson: text("grants_json").notNull().default("[]"),
2253
+ nativeLimitsJson: text("native_limits_json").notNull().default("{}"),
2254
+ runnerPressureJson: text("runner_pressure_json").notNull().default("{}"),
2255
+ constraintsJson: text("constraints_json").notNull().default("{}"),
2256
+ metadataJson: text("metadata_json").notNull().default("{}"),
662
2257
  createdAt: text("created_at").notNull(),
663
2258
  updatedAt: text("updated_at").notNull(),
664
- enabled: integer("enabled").notNull().default(1),
665
- startCron: text("start_cron").notNull().default("0 9 * * 1-5"),
666
- durationMinutes: integer("duration_minutes").notNull().default(480),
667
- maxRunners: integer("max_runners").notNull().default(1),
668
- maxWorkersPerRunner: integer("max_workers_per_runner").notNull().default(4),
669
- dailyCreditBudget: integer("daily_credit_budget").notNull().default(0),
670
- closeoutGraceMinutes: integer("closeout_grace_minutes").notNull().default(15)
2259
+ closedAt: text("closed_at")
671
2260
  }, (table) => [
672
- primaryKey({ columns: [table.projectId, table.environment] })
2261
+ index("idx_provider_availability_sessions_provider_status").on(table.capacityProviderId, table.status, table.checkedInAt),
2262
+ index("idx_provider_availability_sessions_team_status").on(table.teamId, table.status, table.checkedInAt)
673
2263
  ]);
674
- const priorityOverrides = pgTable("priority_overrides", {
2264
+ const providerAssignments = pgTable("provider_assignments", {
675
2265
  id: text("id").primaryKey(),
2266
+ teamId: text("team_id").notNull(),
676
2267
  projectId: text("project_id").notNull(),
677
- model: text("model").notNull(),
678
- subjectId: text("subject_id").notNull(),
679
- priority: real("priority").notNull().default(0),
680
- estimatedCredits: real("estimated_credits"),
681
- metadataJson: text("metadata_json").notNull(),
2268
+ capacityProviderId: text("capacity_provider_id").notNull(),
2269
+ providerSessionId: text("provider_session_id"),
2270
+ executionProviderId: text("execution_provider_id"),
2271
+ allocationSetId: text("allocation_set_id"),
2272
+ projectAgentClassId: text("project_agent_class_id").notNull(),
2273
+ reservationId: text("reservation_id"),
2274
+ workDayId: text("work_day_id"),
2275
+ taskId: text("task_id"),
2276
+ mode: text("mode").notNull(),
2277
+ status: text("status").notNull().default("pending"),
2278
+ leaseState: text("lease_state").notNull().default("unleased"),
2279
+ leaseExpiresAt: text("lease_expires_at"),
2280
+ leaseToken: text("lease_token"),
2281
+ leaseRenewedAt: text("lease_renewed_at"),
2282
+ runnerId: text("runner_id"),
2283
+ agentId: text("agent_id"),
2284
+ handlerId: text("handler_id"),
2285
+ capacityEnvelopeJson: text("capacity_envelope_json").notNull().default("{}"),
2286
+ decisionInputJson: text("decision_input_json").notNull().default("{}"),
2287
+ workspaceContextJson: text("workspace_context_json").notNull().default("{}"),
2288
+ allowedOutputsJson: text("allowed_outputs_json").notNull().default("{}"),
2289
+ explanationJson: text("explanation_json").notNull().default("{}"),
2290
+ attemptCount: integer("attempt_count").notNull().default(0),
2291
+ assignedAt: text("assigned_at"),
2292
+ claimedAt: text("claimed_at"),
2293
+ completedAt: text("completed_at"),
2294
+ returnedAt: text("returned_at"),
2295
+ failedAt: text("failed_at"),
2296
+ lifecycleReason: text("lifecycle_reason"),
2297
+ lifecycleCode: text("lifecycle_code"),
2298
+ lifecycleOutputJson: text("lifecycle_output_json").notNull().default("{}"),
2299
+ synthesizedFrom: text("synthesized_from"),
2300
+ synthesisKey: text("synthesis_key"),
2301
+ decisionId: text("decision_id"),
2302
+ proposalId: text("proposal_id"),
2303
+ fallbackOutputId: text("fallback_output_id"),
2304
+ treedxProxyHandleJson: text("treedx_proxy_handle_json").notNull().default("{}"),
2305
+ metadataJson: text("metadata_json").notNull().default("{}"),
682
2306
  createdAt: text("created_at").notNull(),
683
2307
  updatedAt: text("updated_at").notNull()
684
2308
  }, (table) => [
685
- index("idx_priority_overrides_project_priority").on(table.projectId, table.priority, table.updatedAt)
2309
+ index("idx_provider_assignments_provider_status").on(table.capacityProviderId, table.status, table.leaseExpiresAt),
2310
+ index("idx_provider_assignments_project_mode").on(table.projectId, table.mode, table.status),
2311
+ index("idx_provider_assignments_lease").on(table.capacityProviderId, table.leaseState, table.leaseExpiresAt),
2312
+ index("idx_provider_assignments_runner").on(table.runnerId, table.leaseState),
2313
+ uniqueIndex("idx_provider_assignments_synthesis_key").on(table.teamId, table.synthesisKey),
2314
+ index("idx_provider_assignments_decision").on(table.decisionId, table.status),
2315
+ index("idx_provider_assignments_team_created").on(table.teamId, table.createdAt)
686
2316
  ]);
687
- const prioritySnapshots = pgTable("priority_snapshots", {
2317
+ const agentModeRuns = pgTable("agent_mode_runs", {
688
2318
  id: text("id").primaryKey(),
2319
+ teamId: text("team_id").notNull(),
689
2320
  projectId: text("project_id").notNull(),
690
- workDayId: text("work_day_id"),
691
- snapshotJson: text("snapshot_json").notNull(),
692
- metadataJson: text("metadata_json").notNull(),
693
- generatedAt: text("generated_at").notNull(),
2321
+ providerAssignmentId: text("provider_assignment_id").notNull(),
2322
+ capacityProviderId: text("capacity_provider_id").notNull(),
2323
+ executionProviderId: text("execution_provider_id"),
2324
+ projectAgentClassId: text("project_agent_class_id").notNull(),
2325
+ agentId: text("agent_id"),
2326
+ handlerId: text("handler_id"),
2327
+ mode: text("mode").notNull(),
2328
+ status: text("status").notNull().default("queued"),
2329
+ selectedInputJson: text("selected_input_json").notNull().default("{}"),
2330
+ capacityEnvelopeJson: text("capacity_envelope_json").notNull().default("{}"),
2331
+ outputsJson: text("outputs_json").notNull().default("{}"),
2332
+ traceRefsJson: text("trace_refs_json").notNull().default("{}"),
2333
+ usageActualJson: text("usage_actual_json").notNull().default("{}"),
2334
+ validationJson: text("validation_json").notNull().default("{}"),
2335
+ fallbackReason: text("fallback_reason"),
2336
+ startedAt: text("started_at"),
2337
+ completedAt: text("completed_at"),
2338
+ failedAt: text("failed_at"),
2339
+ metadataJson: text("metadata_json").notNull().default("{}"),
694
2340
  createdAt: text("created_at").notNull(),
695
2341
  updatedAt: text("updated_at").notNull()
696
2342
  }, (table) => [
697
- index("idx_priority_snapshots_project_generated").on(table.projectId, table.generatedAt)
2343
+ index("idx_agent_mode_runs_assignment").on(table.providerAssignmentId, table.status),
2344
+ index("idx_agent_mode_runs_project_mode").on(table.projectId, table.mode, table.createdAt),
2345
+ index("idx_agent_mode_runs_provider").on(table.capacityProviderId, table.createdAt)
698
2346
  ]);
699
- const taskCreditLedger = pgTable("task_credit_ledger", {
2347
+ const decisionPlanningStatuses = pgTable("decision_planning_statuses", {
700
2348
  id: text("id").primaryKey(),
2349
+ teamId: text("team_id").notNull(),
701
2350
  projectId: text("project_id").notNull(),
702
- workDayId: text("work_day_id").notNull(),
703
- taskId: text("task_id"),
704
- phase: text("phase").notNull(),
705
- credits: real("credits").notNull(),
706
- metadataJson: text("metadata_json").notNull(),
707
- createdAt: text("created_at").notNull()
2351
+ decisionId: text("decision_id").notNull(),
2352
+ humanApprovalState: text("human_approval_state"),
2353
+ executionReadiness: text("execution_readiness").notNull().default("draft"),
2354
+ planningInputsStatus: text("planning_inputs_status").notNull().default("requested"),
2355
+ scopeHash: text("scope_hash").notNull(),
2356
+ staleReason: text("stale_reason"),
2357
+ readyAt: text("ready_at"),
2358
+ staleAt: text("stale_at"),
2359
+ metadataJson: text("metadata_json").notNull().default("{}"),
2360
+ createdAt: text("created_at").notNull(),
2361
+ updatedAt: text("updated_at").notNull()
708
2362
  }, (table) => [
709
- index("idx_task_credit_ledger_work_day_created").on(table.workDayId, table.createdAt)
2363
+ uniqueIndex("idx_decision_planning_statuses_decision").on(table.decisionId),
2364
+ index("idx_decision_planning_statuses_project").on(table.projectId, table.executionReadiness, table.updatedAt)
710
2365
  ]);
711
- const scaleDecisions = pgTable("scale_decisions", {
2366
+ const planningInputRequests = pgTable("planning_input_requests", {
712
2367
  id: text("id").primaryKey(),
713
- projectId: text("project_id").notNull(),
714
- environment: text("environment").notNull(),
715
- poolName: text("pool_name").notNull(),
716
- workDayId: text("work_day_id"),
717
- desiredWorkers: integer("desired_workers").notNull(),
718
- observedQueueDepth: integer("observed_queue_depth").notNull().default(0),
719
- observedActiveLeases: integer("observed_active_leases").notNull().default(0),
720
- reason: text("reason").notNull(),
721
- metadataJson: text("metadata_json").notNull(),
722
- createdAt: text("created_at").notNull()
723
- }, (table) => [
724
- index("idx_scale_decisions_project_environment_pool_created").on(table.projectId, table.environment, table.poolName, table.createdAt)
725
- ]);
726
- const projectSummarySnapshots = pgTable("project_summary_snapshots", {
727
- projectId: text("project_id").primaryKey(),
728
2368
  teamId: text("team_id").notNull(),
729
- summaryJson: text("summary_json").notNull(),
730
- generatedAt: text("generated_at").notNull(),
731
- createdAt: text("created_at").notNull(),
732
- updatedAt: text("updated_at").notNull()
2369
+ projectId: text("project_id").notNull(),
2370
+ decisionId: text("decision_id").notNull(),
2371
+ projectAgentClassId: text("project_agent_class_id"),
2372
+ mode: text("mode").notNull().default("planning"),
2373
+ status: text("status").notNull().default("requested"),
2374
+ scopeHash: text("scope_hash").notNull(),
2375
+ prompt: text("prompt"),
2376
+ responseJson: text("response_json").notNull().default("{}"),
2377
+ metadataJson: text("metadata_json").notNull().default("{}"),
2378
+ requestedAt: text("requested_at").notNull(),
2379
+ completedAt: text("completed_at"),
2380
+ staleAt: text("stale_at")
733
2381
  }, (table) => [
734
- index("idx_project_summary_snapshots_team_generated").on(table.teamId, table.generatedAt)
2382
+ index("idx_planning_input_requests_decision").on(table.decisionId, table.status, table.requestedAt),
2383
+ index("idx_planning_input_requests_project").on(table.projectId, table.status, table.requestedAt)
735
2384
  ]);
736
- const teamInboxItems = pgTable("team_inbox_items", {
2385
+ const decisionExecutionInputs = pgTable("decision_execution_inputs", {
737
2386
  id: text("id").primaryKey(),
738
2387
  teamId: text("team_id").notNull(),
739
- projectId: text("project_id"),
740
- kind: text("kind").notNull(),
741
- state: text("state").notNull(),
742
- title: text("title").notNull(),
743
- summary: text("summary"),
744
- href: text("href"),
745
- itemKey: text("item_key"),
2388
+ projectId: text("project_id").notNull(),
2389
+ decisionId: text("decision_id").notNull(),
2390
+ projectAgentClassId: text("project_agent_class_id").notNull(),
2391
+ mode: text("mode").notNull().default("acting"),
2392
+ status: text("status").notNull().default("proposed"),
2393
+ scopeHash: text("scope_hash").notNull(),
2394
+ inputJson: text("input_json").notNull().default("{}"),
746
2395
  metadataJson: text("metadata_json").notNull().default("{}"),
2396
+ acceptedAt: text("accepted_at"),
2397
+ revisionRequestedAt: text("revision_requested_at"),
2398
+ staleAt: text("stale_at"),
747
2399
  createdAt: text("created_at").notNull(),
748
2400
  updatedAt: text("updated_at").notNull()
749
2401
  }, (table) => [
750
- index("idx_team_inbox_items_team_created").on(table.teamId, table.createdAt)
751
- ]);
752
- const betterAuthUser = pgTable("better_auth_user", {
753
- id: text("id").primaryKey(),
754
- name: text("name").notNull(),
755
- email: text("email").notNull().unique(),
756
- emailVerified: integer("emailVerified").notNull().default(0),
757
- image: text("image"),
758
- createdAt: bigint("createdAt", { mode: "number" }).notNull(),
759
- updatedAt: bigint("updatedAt", { mode: "number" }).notNull(),
760
- username: text("username"),
761
- firstName: text("firstName"),
762
- lastName: text("lastName")
763
- }, (table) => [
764
- uniqueIndex("idx_better_auth_user_username").on(table.username)
765
- ]);
766
- const betterAuthSession = pgTable("better_auth_session", {
767
- id: text("id").primaryKey(),
768
- expiresAt: bigint("expiresAt", { mode: "number" }).notNull(),
769
- token: text("token").notNull().unique(),
770
- createdAt: bigint("createdAt", { mode: "number" }).notNull(),
771
- updatedAt: bigint("updatedAt", { mode: "number" }).notNull(),
772
- ipAddress: text("ipAddress"),
773
- userAgent: text("userAgent"),
774
- userId: text("userId").notNull()
775
- }, (table) => [
776
- index("idx_better_auth_session_token").on(table.token),
777
- index("idx_better_auth_session_userId").on(table.userId)
778
- ]);
779
- const betterAuthAccount = pgTable("better_auth_account", {
780
- id: text("id").primaryKey(),
781
- accountId: text("accountId").notNull(),
782
- providerId: text("providerId").notNull(),
783
- userId: text("userId").notNull(),
784
- accessToken: text("accessToken"),
785
- refreshToken: text("refreshToken"),
786
- idToken: text("idToken"),
787
- accessTokenExpiresAt: bigint("accessTokenExpiresAt", { mode: "number" }),
788
- refreshTokenExpiresAt: bigint("refreshTokenExpiresAt", { mode: "number" }),
789
- scope: text("scope"),
790
- password: text("password"),
791
- createdAt: bigint("createdAt", { mode: "number" }).notNull(),
792
- updatedAt: bigint("updatedAt", { mode: "number" }).notNull()
793
- }, (table) => [
794
- index("idx_better_auth_account_userId").on(table.userId),
795
- uniqueIndex("idx_better_auth_account_provider_account").on(table.providerId, table.accountId)
796
- ]);
797
- const betterAuthVerification = pgTable("better_auth_verification", {
798
- id: text("id").primaryKey(),
799
- identifier: text("identifier").notNull(),
800
- value: text("value").notNull(),
801
- expiresAt: bigint("expiresAt", { mode: "number" }).notNull(),
802
- createdAt: bigint("createdAt", { mode: "number" }).notNull(),
803
- updatedAt: bigint("updatedAt", { mode: "number" }).notNull()
804
- }, (table) => [
805
- index("idx_better_auth_verification_identifier").on(table.identifier)
2402
+ index("idx_decision_execution_inputs_decision").on(table.decisionId, table.status, table.createdAt),
2403
+ index("idx_decision_execution_inputs_project").on(table.projectId, table.status, table.mode, table.createdAt)
806
2404
  ]);
807
- const teamWebHosts = pgTable("team_web_hosts", {
2405
+ const workdayCapacityEnvelopes = pgTable("workday_capacity_envelopes", {
808
2406
  id: text("id").primaryKey(),
809
2407
  teamId: text("team_id").notNull(),
810
- provider: text("provider").notNull(),
811
- ownership: text("ownership").notNull(),
812
- name: text("name").notNull(),
813
- accountLabel: text("account_label"),
814
- allowedEnvironmentsJson: text("allowed_environments_json").notNull().default("[]"),
815
- status: text("status").notNull().default("active"),
816
- encryptedPayloadJson: text("encrypted_payload_json"),
817
- metadataJson: text("metadata_json"),
818
- createdById: text("created_by_id"),
819
- updatedById: text("updated_by_id"),
2408
+ projectId: text("project_id").notNull(),
2409
+ allocationSetId: text("allocation_set_id"),
2410
+ status: text("status").notNull().default("draft"),
2411
+ startedAt: text("started_at"),
2412
+ pausedAt: text("paused_at"),
2413
+ completedAt: text("completed_at"),
2414
+ envelopeJson: text("envelope_json").notNull().default("{}"),
2415
+ modeSplitsJson: text("mode_splits_json").notNull().default("{}"),
2416
+ capsJson: text("caps_json").notNull().default("{}"),
2417
+ reservesJson: text("reserves_json").notNull().default("{}"),
2418
+ borrowingRulesJson: text("borrowing_rules_json").notNull().default("{}"),
2419
+ metadataJson: text("metadata_json").notNull().default("{}"),
820
2420
  createdAt: text("created_at").notNull(),
821
2421
  updatedAt: text("updated_at").notNull()
822
2422
  }, (table) => [
823
- index("idx_team_web_hosts_team_provider").on(table.teamId, table.provider, table.status),
824
- uniqueIndex("idx_team_web_hosts_team_provider_name").on(table.teamId, table.provider, table.name)
2423
+ index("idx_workday_capacity_envelopes_project_status").on(table.projectId, table.status, table.createdAt),
2424
+ index("idx_workday_capacity_envelopes_team_status").on(table.teamId, table.status, table.createdAt)
825
2425
  ]);
826
- const teamInvites = pgTable("team_invites", {
2426
+ const agentCapacityPlans = pgTable("agent_capacity_plans", {
827
2427
  id: text("id").primaryKey(),
828
2428
  teamId: text("team_id").notNull(),
829
- email: text("email").notNull(),
830
- roleKey: text("role_key").notNull(),
831
- tokenPrefix: text("token_prefix").notNull(),
832
- tokenHash: text("token_hash").notNull(),
833
- status: text("status").notNull().default("pending"),
834
- invitedByUserId: text("invited_by_user_id"),
835
- acceptedByUserId: text("accepted_by_user_id"),
2429
+ projectId: text("project_id").notNull(),
2430
+ decisionId: text("decision_id").notNull(),
2431
+ status: text("status").notNull().default("draft"),
2432
+ scopeHash: text("scope_hash").notNull(),
2433
+ allocationSetId: text("allocation_set_id"),
2434
+ workDayId: text("work_day_id"),
2435
+ expectedCredits: real("expected_credits").notNull().default(0),
2436
+ highCredits: real("high_credits").notNull().default(0),
2437
+ workUnitsJson: text("work_units_json").notNull().default("[]"),
2438
+ capabilityNeedsJson: text("capability_needs_json").notNull().default("[]"),
2439
+ environmentNeedsJson: text("environment_needs_json").notNull().default("[]"),
2440
+ reservesJson: text("reserves_json").notNull().default("{}"),
2441
+ blockersJson: text("blockers_json").notNull().default("[]"),
2442
+ priorityRationale: text("priority_rationale"),
2443
+ reviewJson: text("review_json").notNull().default("{}"),
2444
+ metadataJson: text("metadata_json").notNull().default("{}"),
836
2445
  acceptedAt: text("accepted_at"),
837
- expiresAt: text("expires_at").notNull(),
2446
+ scheduledAt: text("scheduled_at"),
2447
+ supersededAt: text("superseded_at"),
838
2448
  createdAt: text("created_at").notNull(),
839
2449
  updatedAt: text("updated_at").notNull()
840
2450
  }, (table) => [
841
- index("idx_team_invites_team_status").on(table.teamId, table.status, table.createdAt),
842
- index("idx_team_invites_token_prefix").on(table.tokenPrefix)
2451
+ index("idx_agent_capacity_plans_decision").on(table.decisionId, table.status, table.createdAt),
2452
+ index("idx_agent_capacity_plans_project").on(table.projectId, table.status, table.createdAt),
2453
+ index("idx_agent_capacity_plans_workday").on(table.workDayId, table.status, table.createdAt)
843
2454
  ]);
844
- const capacityProviders = pgTable("capacity_providers", {
2455
+ const treeDxProxyHandles = pgTable("treedx_proxy_handles", {
845
2456
  id: text("id").primaryKey(),
846
- teamId: text("team_id"),
847
- ownerTeamId: text("owner_team_id"),
848
- name: text("name").notNull(),
849
- kind: text("kind").notNull(),
850
- status: text("status").notNull().default("pending"),
851
- provider: text("provider").notNull(),
852
- billingScope: text("billing_scope").notNull().default("team"),
853
- monthlyCreditBudget: real("monthly_credit_budget").notNull().default(0),
854
- dailyCreditBudget: real("daily_credit_budget").notNull().default(0),
855
- creditBudgetMode: text("credit_budget_mode").notNull().default("derived"),
856
- maxConcurrentWorkdays: integer("max_concurrent_workdays").notNull().default(1),
857
- maxConcurrentWorkers: integer("max_concurrent_workers").notNull().default(1),
858
- capacityModelJson: text("capacity_model_json").notNull().default("{}"),
2457
+ teamId: text("team_id").notNull(),
2458
+ projectId: text("project_id").notNull(),
2459
+ assignmentId: text("assignment_id"),
2460
+ repositoryId: text("repository_id"),
2461
+ workspaceId: text("workspace_id"),
2462
+ status: text("status").notNull().default("issued"),
2463
+ scopesJson: text("scopes_json").notNull().default("[]"),
2464
+ allowedOperationsJson: text("allowed_operations_json").notNull().default("[]"),
2465
+ allowedPathsJson: text("allowed_paths_json").notNull().default("[]"),
2466
+ tokenHash: text("token_hash"),
2467
+ expiresAt: text("expires_at"),
2468
+ issuedAt: text("issued_at").notNull(),
2469
+ revokedAt: text("revoked_at"),
859
2470
  metadataJson: text("metadata_json").notNull().default("{}"),
860
2471
  createdAt: text("created_at").notNull(),
861
2472
  updatedAt: text("updated_at").notNull()
862
2473
  }, (table) => [
863
- index("idx_capacity_providers_team_status").on(table.teamId, table.status, table.provider)
2474
+ index("idx_treedx_proxy_handles_assignment").on(table.assignmentId, table.status, table.expiresAt),
2475
+ index("idx_treedx_proxy_handles_project").on(table.projectId, table.status, table.updatedAt)
864
2476
  ]);
865
- const capacityProviderHosts = pgTable("capacity_provider_hosts", {
2477
+ const treeDxProjectProxyAudit = pgTable("treedx_project_proxy_audit", {
866
2478
  id: text("id").primaryKey(),
867
- capacityProviderId: text("capacity_provider_id").notNull(),
868
- hostId: text("host_id").notNull(),
869
- role: text("role").notNull(),
870
- required: integer("required").notNull().default(1),
2479
+ teamId: text("team_id").notNull(),
2480
+ projectId: text("project_id").notNull(),
2481
+ assignmentId: text("assignment_id"),
2482
+ actorType: text("actor_type").notNull(),
2483
+ actorId: text("actor_id"),
2484
+ method: text("method").notNull(),
2485
+ path: text("path").notNull(),
2486
+ handleJson: text("handle_json").notNull().default("{}"),
2487
+ resultStatus: text("result_status").notNull().default("observed"),
2488
+ reasonCode: text("reason_code"),
2489
+ reason: text("reason"),
871
2490
  metadataJson: text("metadata_json").notNull().default("{}"),
872
- createdAt: text("created_at").notNull(),
873
- updatedAt: text("updated_at").notNull()
2491
+ createdAt: text("created_at").notNull()
874
2492
  }, (table) => [
875
- uniqueIndex("idx_capacity_provider_hosts_unique").on(table.capacityProviderId, table.hostId, table.role)
2493
+ index("idx_treedx_project_proxy_audit_project").on(table.projectId, table.createdAt),
2494
+ index("idx_treedx_project_proxy_audit_assignment").on(table.assignmentId, table.createdAt),
2495
+ index("idx_treedx_project_proxy_audit_result").on(table.projectId, table.resultStatus, table.createdAt)
876
2496
  ]);
877
- const capacityProviderLanes = pgTable("capacity_provider_lanes", {
2497
+ const secretMetadataRecords = pgTable("secret_metadata_records", {
878
2498
  id: text("id").primaryKey(),
879
- capacityProviderId: text("capacity_provider_id").notNull(),
2499
+ teamId: text("team_id").notNull(),
2500
+ projectId: text("project_id"),
880
2501
  name: text("name").notNull(),
881
- businessModel: text("business_model").notNull().default("custom"),
882
- modelFamily: text("model_family"),
883
- modelClass: text("model_class"),
884
- regionPolicy: text("region_policy"),
885
- unit: text("unit").notNull().default("treeseed_credit"),
886
- scarcityLevel: text("scarcity_level").notNull().default("medium"),
887
- hardLimitsJson: text("hard_limits_json").notNull().default("{}"),
888
- routingPolicyJson: text("routing_policy_json").notNull().default("{}"),
2502
+ secretClass: text("secret_class").notNull(),
2503
+ custodyMode: text("custody_mode").notNull(),
2504
+ ownerKind: text("owner_kind").notNull(),
2505
+ status: text("status").notNull().default("active"),
2506
+ githubSecretTargetJson: text("github_secret_target_json").notNull().default("{}"),
2507
+ escrowRecordId: text("escrow_record_id"),
2508
+ apiDecryptable: integer("api_decryptable").notNull().default(0),
2509
+ plaintextAllowed: integer("plaintext_allowed").notNull().default(0),
2510
+ failClosedCode: text("fail_closed_code"),
889
2511
  metadataJson: text("metadata_json").notNull().default("{}"),
890
2512
  createdAt: text("created_at").notNull(),
891
- updatedAt: text("updated_at").notNull()
2513
+ updatedAt: text("updated_at").notNull(),
2514
+ tombstonedAt: text("tombstoned_at")
892
2515
  }, (table) => [
893
- index("idx_capacity_provider_lanes_provider").on(table.capacityProviderId, table.businessModel, table.scarcityLevel)
2516
+ index("idx_secret_metadata_team_project").on(table.teamId, table.projectId, table.status),
2517
+ index("idx_secret_metadata_custody").on(table.custodyMode, table.status),
2518
+ uniqueIndex("idx_secret_metadata_team_name").on(table.teamId, table.projectId, table.name)
894
2519
  ]);
895
- const capacityGrants = pgTable("capacity_grants", {
2520
+ const clientEncryptedEscrowRecords = pgTable("client_encrypted_escrow_records", {
896
2521
  id: text("id").primaryKey(),
897
- capacityProviderId: text("capacity_provider_id").notNull(),
898
- laneId: text("lane_id"),
899
- grantScope: text("grant_scope").notNull().default("team"),
900
2522
  teamId: text("team_id").notNull(),
901
2523
  projectId: text("project_id"),
902
- environment: text("environment"),
903
- state: text("state").notNull().default("active"),
904
- dailyCreditLimit: real("daily_credit_limit"),
905
- weeklyCreditLimit: real("weekly_credit_limit"),
906
- monthlyCreditLimit: real("monthly_credit_limit"),
907
- dailyUsdLimit: real("daily_usd_limit"),
908
- weeklyQuotaMinutes: real("weekly_quota_minutes"),
909
- monthlyProviderUnits: real("monthly_provider_units"),
910
- priorityWeight: real("priority_weight").notNull().default(1),
911
- overflowPolicy: text("overflow_policy").notNull().default("soft_grant"),
2524
+ secretId: text("secret_id").notNull(),
2525
+ status: text("status").notNull().default("active"),
2526
+ ciphertextRef: text("ciphertext_ref").notNull(),
2527
+ algorithm: text("algorithm").notNull(),
2528
+ wrappingKeyId: text("wrapping_key_id").notNull(),
2529
+ createdByClientId: text("created_by_client_id"),
2530
+ expiresAt: text("expires_at"),
2531
+ migratedTo: text("migrated_to"),
912
2532
  metadataJson: text("metadata_json").notNull().default("{}"),
913
2533
  createdAt: text("created_at").notNull(),
914
- updatedAt: text("updated_at").notNull()
2534
+ updatedAt: text("updated_at").notNull(),
2535
+ tombstonedAt: text("tombstoned_at")
915
2536
  }, (table) => [
916
- index("idx_capacity_grants_team_project").on(table.teamId, table.projectId, table.state),
917
- index("idx_capacity_grants_provider_lane").on(table.capacityProviderId, table.laneId, table.state)
2537
+ index("idx_client_encrypted_escrow_secret").on(table.secretId, table.status),
2538
+ index("idx_client_encrypted_escrow_project").on(table.teamId, table.projectId, table.status)
918
2539
  ]);
919
- const capacityReservations = pgTable("capacity_reservations", {
2540
+ const githubRepositoryGrants = pgTable("github_repository_grants", {
920
2541
  id: text("id").primaryKey(),
921
- capacityProviderId: text("capacity_provider_id").notNull(),
922
- executionProviderId: text("execution_provider_id"),
923
- laneId: text("lane_id").notNull(),
924
2542
  teamId: text("team_id").notNull(),
925
- projectId: text("project_id").notNull(),
926
- workDayId: text("work_day_id"),
927
- taskId: text("task_id"),
928
- state: text("state").notNull().default("reserved"),
929
- reservedCredits: real("reserved_credits").notNull(),
930
- consumedCredits: real("consumed_credits").notNull().default(0),
931
- nativeUnit: text("native_unit"),
932
- reservedNativeAmount: real("reserved_native_amount"),
933
- consumedNativeAmount: real("consumed_native_amount"),
934
- reservedProviderUnits: real("reserved_provider_units"),
935
- consumedProviderUnits: real("consumed_provider_units"),
936
- reservedUsd: real("reserved_usd"),
937
- consumedUsd: real("consumed_usd"),
938
- expiresAt: text("expires_at"),
2543
+ projectId: text("project_id"),
2544
+ repository: text("repository").notNull(),
2545
+ installationId: text("installation_id"),
2546
+ accountLogin: text("account_login"),
2547
+ accountId: text("account_id"),
2548
+ status: text("status").notNull().default("active"),
2549
+ permissionsJson: text("permissions_json").notNull().default("{}"),
2550
+ environmentsJson: text("environments_json").notNull().default("[]"),
2551
+ driftCode: text("drift_code"),
2552
+ observedAt: text("observed_at"),
2553
+ revokedAt: text("revoked_at"),
939
2554
  metadataJson: text("metadata_json").notNull().default("{}"),
940
2555
  createdAt: text("created_at").notNull(),
941
2556
  updatedAt: text("updated_at").notNull()
942
2557
  }, (table) => [
943
- index("idx_capacity_reservations_project_workday_state").on(table.projectId, table.workDayId, table.state, table.createdAt),
944
- index("idx_capacity_reservations_provider_state").on(table.capacityProviderId, table.laneId, table.state),
945
- index("idx_capacity_reservations_execution_provider_state").on(table.executionProviderId, table.state, table.createdAt)
2558
+ index("idx_github_repository_grants_project").on(table.teamId, table.projectId, table.status),
2559
+ uniqueIndex("idx_github_repository_grants_repository").on(table.teamId, table.repository)
946
2560
  ]);
947
- const capacityLedgerEntries = pgTable("capacity_ledger_entries", {
2561
+ const githubAppInstallationRecords = pgTable("github_app_installation_records", {
948
2562
  id: text("id").primaryKey(),
949
- capacityProviderId: text("capacity_provider_id").notNull(),
950
- laneId: text("lane_id"),
951
- reservationId: text("reservation_id"),
952
2563
  teamId: text("team_id").notNull(),
953
- projectId: text("project_id"),
954
- workDayId: text("work_day_id"),
955
- taskId: text("task_id"),
956
- phase: text("phase").notNull(),
957
- credits: real("credits").notNull(),
958
- providerUnits: real("provider_units"),
959
- usd: real("usd"),
960
- source: text("source").notNull(),
2564
+ installationId: text("installation_id").notNull(),
2565
+ accountLogin: text("account_login"),
2566
+ accountId: text("account_id"),
2567
+ accountType: text("account_type"),
2568
+ status: text("status").notNull().default("active"),
2569
+ permissionsJson: text("permissions_json").notNull().default("{}"),
2570
+ repositorySelection: text("repository_selection"),
2571
+ driftCode: text("drift_code"),
2572
+ observedAt: text("observed_at"),
2573
+ revokedAt: text("revoked_at"),
2574
+ suspendedAt: text("suspended_at"),
961
2575
  metadataJson: text("metadata_json").notNull().default("{}"),
962
- createdAt: text("created_at").notNull()
2576
+ createdAt: text("created_at").notNull(),
2577
+ updatedAt: text("updated_at").notNull()
963
2578
  }, (table) => [
964
- index("idx_capacity_ledger_project_workday_created").on(table.projectId, table.workDayId, table.createdAt)
2579
+ index("idx_github_app_installations_team_status").on(table.teamId, table.status, table.updatedAt),
2580
+ uniqueIndex("idx_github_app_installations_team_installation").on(table.teamId, table.installationId)
965
2581
  ]);
966
- const capacityRoutingDecisions = pgTable("capacity_routing_decisions", {
2582
+ const githubAppTokenIssuanceRecords = pgTable("github_app_token_issuance_records", {
967
2583
  id: text("id").primaryKey(),
968
- taskId: text("task_id"),
969
- workDayId: text("work_day_id"),
970
- projectId: text("project_id").notNull(),
971
- selectedProviderId: text("selected_provider_id").notNull(),
972
- selectedLaneId: text("selected_lane_id").notNull(),
973
- selectedModel: text("selected_model"),
974
- decision: text("decision").notNull().default("selected"),
975
- reason: text("reason").notNull(),
976
- candidateJson: text("candidate_json").notNull().default("[]"),
977
- scoreJson: text("score_json").notNull().default("{}"),
2584
+ teamId: text("team_id").notNull(),
2585
+ projectId: text("project_id"),
2586
+ assignmentId: text("assignment_id"),
2587
+ providerId: text("provider_id"),
2588
+ workdayId: text("workday_id"),
2589
+ operationId: text("operation_id"),
2590
+ repository: text("repository").notNull(),
2591
+ installationId: text("installation_id").notNull(),
2592
+ status: text("status").notNull().default("issued"),
2593
+ tokenPrefix: text("token_prefix"),
2594
+ tokenHash: text("token_hash"),
2595
+ permissionsJson: text("permissions_json").notNull().default("{}"),
2596
+ allowedOperationsJson: text("allowed_operations_json").notNull().default("[]"),
2597
+ expiresAt: text("expires_at"),
2598
+ issuedAt: text("issued_at"),
2599
+ revokedAt: text("revoked_at"),
2600
+ failClosedCode: text("fail_closed_code"),
978
2601
  metadataJson: text("metadata_json").notNull().default("{}"),
979
- createdAt: text("created_at").notNull()
2602
+ createdAt: text("created_at").notNull(),
2603
+ updatedAt: text("updated_at").notNull()
980
2604
  }, (table) => [
981
- index("idx_capacity_routing_decisions_project_workday").on(table.projectId, table.workDayId, table.createdAt)
2605
+ index("idx_github_app_token_issuance_project").on(table.teamId, table.projectId, table.status, table.updatedAt),
2606
+ index("idx_github_app_token_issuance_operation").on(table.operationId, table.status, table.expiresAt),
2607
+ index("idx_github_app_token_issuance_assignment").on(table.assignmentId, table.status, table.expiresAt)
982
2608
  ]);
983
- const taskEstimates = pgTable("task_estimates", {
2609
+ const workflowOperationRecords = pgTable("workflow_operation_records", {
984
2610
  id: text("id").primaryKey(),
985
- taskId: text("task_id"),
986
- workDayId: text("work_day_id"),
987
- projectId: text("project_id").notNull(),
988
- estimatePhase: text("estimate_phase").notNull(),
989
- taskSignature: text("task_signature").notNull(),
990
- confidence: text("confidence").notNull(),
991
- estimatedCreditsP50: real("estimated_credits_p50").notNull(),
992
- estimatedCreditsP90: real("estimated_credits_p90").notNull(),
993
- reservedCredits: real("reserved_credits").notNull(),
994
- estimatedInputTokensP50: integer("estimated_input_tokens_p50"),
995
- estimatedInputTokensP90: integer("estimated_input_tokens_p90"),
996
- estimatedOutputTokensP50: integer("estimated_output_tokens_p50"),
997
- estimatedOutputTokensP90: integer("estimated_output_tokens_p90"),
998
- estimatedQuotaMinutesP50: real("estimated_quota_minutes_p50"),
999
- estimatedQuotaMinutesP90: real("estimated_quota_minutes_p90"),
1000
- featuresJson: text("features_json").notNull().default("{}"),
2611
+ teamId: text("team_id").notNull(),
2612
+ projectId: text("project_id"),
2613
+ name: text("name").notNull(),
2614
+ repository: text("repository").notNull(),
2615
+ workflowFile: text("workflow_file").notNull(),
2616
+ secretBearing: integer("secret_bearing").notNull().default(0),
2617
+ trustedExecutionSetId: text("trusted_execution_set_id").notNull(),
2618
+ dispatchJson: text("dispatch_json").notNull().default("{}"),
2619
+ inputsJson: text("inputs_json").notNull().default("[]"),
2620
+ secretClassesJson: text("secret_classes_json").notNull().default("[]"),
2621
+ status: text("status").notNull().default("active"),
2622
+ failClosedCode: text("fail_closed_code"),
2623
+ metadataJson: text("metadata_json").notNull().default("{}"),
1001
2624
  createdAt: text("created_at").notNull(),
1002
- executionProfileId: text("execution_profile_id").notNull().default("standard-code-model")
2625
+ updatedAt: text("updated_at").notNull(),
2626
+ blockedAt: text("blocked_at")
1003
2627
  }, (table) => [
1004
- index("idx_task_estimates_project_signature").on(table.projectId, table.taskSignature, table.createdAt),
1005
- index("idx_task_estimates_project_signature_profile").on(table.projectId, table.taskSignature, table.executionProfileId, table.createdAt)
2628
+ index("idx_workflow_operation_records_project").on(table.teamId, table.projectId, table.status),
2629
+ uniqueIndex("idx_workflow_operation_records_operation").on(table.teamId, table.id)
1006
2630
  ]);
1007
- const taskUsageActuals = pgTable("task_usage_actuals", {
2631
+ const workflowDispatchRecords = pgTable("workflow_dispatch_records", {
1008
2632
  id: text("id").primaryKey(),
1009
- taskId: text("task_id"),
1010
- workDayId: text("work_day_id"),
1011
- projectId: text("project_id").notNull(),
1012
- taskSignature: text("task_signature").notNull(),
1013
- capacityProviderId: text("capacity_provider_id"),
1014
- executionProviderId: text("execution_provider_id"),
1015
- laneId: text("lane_id"),
1016
- businessModel: text("business_model").notNull(),
1017
- modelName: text("model_name"),
1018
- inputTokens: integer("input_tokens"),
1019
- outputTokens: integer("output_tokens"),
1020
- cachedInputTokens: integer("cached_input_tokens"),
1021
- quotaMinutes: real("quota_minutes"),
1022
- wallMinutes: real("wall_minutes"),
1023
- filesOpened: integer("files_opened"),
1024
- filesChanged: integer("files_changed"),
1025
- diffLinesAdded: integer("diff_lines_added"),
1026
- diffLinesRemoved: integer("diff_lines_removed"),
1027
- testRuns: integer("test_runs"),
1028
- retryCount: integer("retry_count"),
1029
- actualCredits: real("actual_credits").notNull(),
1030
- actualUsd: real("actual_usd"),
1031
- creditFormulaVersion: text("credit_formula_version").notNull().default("treeseed.actual-credits.v1"),
1032
- actualCreditSource: text("actual_credit_source").notNull().default("central_calculator"),
1033
- nativeUsageJson: text("native_usage_json").notNull().default("{}"),
2633
+ teamId: text("team_id").notNull(),
2634
+ projectId: text("project_id"),
2635
+ workflowOperationId: text("workflow_operation_id").notNull(),
2636
+ platformOperationId: text("platform_operation_id"),
2637
+ repository: text("repository").notNull(),
2638
+ workflowFile: text("workflow_file").notNull(),
2639
+ ref: text("ref"),
2640
+ status: text("status").notNull().default("queued"),
2641
+ inputsJson: text("inputs_json").notNull().default("{}"),
2642
+ resultJson: text("result_json").notNull().default("{}"),
2643
+ failClosedCode: text("fail_closed_code"),
1034
2644
  metadataJson: text("metadata_json").notNull().default("{}"),
1035
2645
  createdAt: text("created_at").notNull(),
1036
- executionProfileId: text("execution_profile_id").notNull().default("standard-code-model")
2646
+ updatedAt: text("updated_at").notNull(),
2647
+ dispatchedAt: text("dispatched_at"),
2648
+ completedAt: text("completed_at")
1037
2649
  }, (table) => [
1038
- index("idx_task_usage_actuals_project_signature").on(table.projectId, table.taskSignature, table.createdAt),
1039
- index("idx_task_usage_actuals_project_signature_profile").on(table.projectId, table.taskSignature, table.executionProfileId, table.createdAt),
1040
- index("idx_task_usage_actuals_execution_provider").on(table.executionProviderId, table.createdAt)
2650
+ index("idx_workflow_dispatch_records_operation").on(table.workflowOperationId, table.status, table.createdAt),
2651
+ index("idx_workflow_dispatch_records_platform").on(table.platformOperationId)
1041
2652
  ]);
1042
- const nativeUsageObservations = pgTable("native_usage_observations", {
2653
+ const treeDxCredentialIssuanceRecords = pgTable("treedx_credential_issuance_records", {
1043
2654
  id: text("id").primaryKey(),
1044
- taskUsageActualId: text("task_usage_actual_id"),
1045
- taskId: text("task_id"),
1046
- workDayId: text("work_day_id"),
2655
+ teamId: text("team_id").notNull(),
1047
2656
  projectId: text("project_id").notNull(),
1048
- taskSignature: text("task_signature").notNull(),
1049
- executionProfileId: text("execution_profile_id").notNull().default("standard-code-model"),
1050
- capacityProviderId: text("capacity_provider_id"),
1051
- executionProviderId: text("execution_provider_id"),
1052
- nativeUnit: text("native_unit"),
1053
- nativeUsageJson: text("native_usage_json").notNull().default("{}"),
1054
- observedAt: text("observed_at").notNull(),
1055
- source: text("source").notNull().default("provider_report"),
1056
- formulaVersion: text("formula_version").notNull().default("treeseed.actual-credits.v1"),
1057
- actualCredits: real("actual_credits").notNull(),
2657
+ assignmentId: text("assignment_id"),
2658
+ repository: text("repository"),
2659
+ credentialProvider: text("credential_provider").notNull(),
2660
+ status: text("status").notNull().default("issued"),
2661
+ tokenPrefix: text("token_prefix"),
2662
+ tokenHash: text("token_hash"),
2663
+ scopesJson: text("scopes_json").notNull().default("[]"),
2664
+ allowedOperationsJson: text("allowed_operations_json").notNull().default("[]"),
2665
+ expiresAt: text("expires_at"),
2666
+ issuedAt: text("issued_at"),
2667
+ revokedAt: text("revoked_at"),
2668
+ failClosedCode: text("fail_closed_code"),
1058
2669
  metadataJson: text("metadata_json").notNull().default("{}"),
1059
- createdAt: text("created_at").notNull()
2670
+ createdAt: text("created_at").notNull(),
2671
+ updatedAt: text("updated_at").notNull()
1060
2672
  }, (table) => [
1061
- index("idx_native_usage_observations_profile").on(table.projectId, table.taskSignature, table.executionProfileId, table.createdAt),
1062
- index("idx_native_usage_observations_provider").on(table.executionProviderId, table.createdAt)
2673
+ index("idx_treedx_credential_issuance_assignment").on(table.assignmentId, table.status, table.expiresAt),
2674
+ index("idx_treedx_credential_issuance_project").on(table.projectId, table.status, table.updatedAt)
1063
2675
  ]);
1064
2676
  const approvalRequests = pgTable("approval_requests", {
1065
2677
  id: text("id").primaryKey(),
@@ -1236,6 +2848,104 @@ const hubContentSources = pgTable("hub_content_sources", {
1236
2848
  createdAt: text("created_at").notNull(),
1237
2849
  updatedAt: text("updated_at").notNull()
1238
2850
  });
2851
+ const treeDxInstances = pgTable("treedx_instances", {
2852
+ id: text("id").primaryKey(),
2853
+ teamId: text("team_id").notNull(),
2854
+ kind: text("kind").notNull(),
2855
+ provider: text("provider").notNull(),
2856
+ name: text("name").notNull(),
2857
+ baseUrl: text("base_url"),
2858
+ registryUrl: text("registry_url"),
2859
+ publicRead: integer("public_read").notNull().default(0),
2860
+ primary: integer("primary").notNull().default(1),
2861
+ status: text("status").notNull().default("pending"),
2862
+ imageRef: text("image_ref"),
2863
+ railwayProjectId: text("railway_project_id"),
2864
+ railwayServiceId: text("railway_service_id"),
2865
+ railwayEnvironmentId: text("railway_environment_id"),
2866
+ volumeMountPath: text("volume_mount_path"),
2867
+ metadataJson: text("metadata_json").notNull().default("{}"),
2868
+ createdAt: text("created_at").notNull(),
2869
+ updatedAt: text("updated_at").notNull()
2870
+ }, (table) => [
2871
+ index("idx_treedx_instances_team_status").on(table.teamId, table.status)
2872
+ ]);
2873
+ const treeDxProjectLibraries = pgTable("treedx_project_libraries", {
2874
+ id: text("id").primaryKey(),
2875
+ teamId: text("team_id").notNull(),
2876
+ projectId: text("project_id").notNull(),
2877
+ instanceId: text("instance_id").notNull(),
2878
+ libraryId: text("library_id").notNull(),
2879
+ repositoryId: text("repository_id"),
2880
+ contentPath: text("content_path").notNull().default("src/content"),
2881
+ contentRepositoryUrl: text("content_repository_url"),
2882
+ contentRepositoryDefaultBranch: text("content_repository_default_branch"),
2883
+ contentRepositoryRef: text("content_repository_ref"),
2884
+ r2BucketName: text("r2_bucket_name"),
2885
+ r2ManifestKey: text("r2_manifest_key"),
2886
+ topologyJson: text("topology_json").notNull().default("{}"),
2887
+ metadataJson: text("metadata_json").notNull().default("{}"),
2888
+ createdAt: text("created_at").notNull(),
2889
+ updatedAt: text("updated_at").notNull()
2890
+ }, (table) => [
2891
+ uniqueIndex("idx_treedx_project_libraries_project").on(table.projectId),
2892
+ index("idx_treedx_project_libraries_instance").on(table.instanceId)
2893
+ ]);
2894
+ const treeDxMirrors = pgTable("treedx_mirrors", {
2895
+ id: text("id").primaryKey(),
2896
+ teamId: text("team_id").notNull(),
2897
+ instanceId: text("instance_id").notNull(),
2898
+ name: text("name").notNull(),
2899
+ direction: text("direction").notNull().default("bidirectional"),
2900
+ targetKind: text("target_kind").notNull(),
2901
+ targetUrl: text("target_url"),
2902
+ status: text("status").notNull().default("pending"),
2903
+ instructions: text("instructions"),
2904
+ lastSyncAt: text("last_sync_at"),
2905
+ lastSyncStatus: text("last_sync_status"),
2906
+ lastSyncMetadataJson: text("last_sync_metadata_json").notNull().default("{}"),
2907
+ metadataJson: text("metadata_json").notNull().default("{}"),
2908
+ createdAt: text("created_at").notNull(),
2909
+ updatedAt: text("updated_at").notNull()
2910
+ }, (table) => [
2911
+ index("idx_treedx_mirrors_team_instance").on(table.teamId, table.instanceId)
2912
+ ]);
2913
+ const treeDxShares = pgTable("treedx_shares", {
2914
+ id: text("id").primaryKey(),
2915
+ teamId: text("team_id").notNull(),
2916
+ instanceId: text("instance_id"),
2917
+ projectId: text("project_id"),
2918
+ libraryId: text("library_id"),
2919
+ scope: text("scope").notNull(),
2920
+ targetTeamId: text("target_team_id"),
2921
+ trustGrantJson: text("trust_grant_json").notNull().default("{}"),
2922
+ publicRead: integer("public_read").notNull().default(0),
2923
+ status: text("status").notNull().default("active"),
2924
+ expiresAt: text("expires_at"),
2925
+ metadataJson: text("metadata_json").notNull().default("{}"),
2926
+ createdAt: text("created_at").notNull(),
2927
+ updatedAt: text("updated_at").notNull(),
2928
+ revokedAt: text("revoked_at")
2929
+ }, (table) => [
2930
+ index("idx_treedx_shares_team_scope").on(table.teamId, table.scope, table.status)
2931
+ ]);
2932
+ const treeDxDeployments = pgTable("treedx_deployments", {
2933
+ id: text("id").primaryKey(),
2934
+ teamId: text("team_id").notNull(),
2935
+ instanceId: text("instance_id"),
2936
+ provider: text("provider").notNull(),
2937
+ status: text("status").notNull().default("queued"),
2938
+ imageRef: text("image_ref"),
2939
+ volumeMountPath: text("volume_mount_path"),
2940
+ serviceRefsJson: text("service_refs_json").notNull().default("{}"),
2941
+ resultJson: text("result_json").notNull().default("{}"),
2942
+ errorJson: text("error_json"),
2943
+ createdAt: text("created_at").notNull(),
2944
+ updatedAt: text("updated_at").notNull(),
2945
+ completedAt: text("completed_at")
2946
+ }, (table) => [
2947
+ index("idx_treedx_deployments_team_instance").on(table.teamId, table.instanceId, table.createdAt)
2948
+ ]);
1239
2949
  const hubLaunches = pgTable("hub_launches", {
1240
2950
  id: text("id").primaryKey(),
1241
2951
  hubId: text("hub_id").notNull(),
@@ -1669,9 +3379,6 @@ const treeseedMarketSchema = {
1669
3379
  contactSubmissions,
1670
3380
  runtimeEnvelopes,
1671
3381
  workDays,
1672
- tasks,
1673
- taskEvents,
1674
- taskOutputs,
1675
3382
  graphRuns,
1676
3383
  reports,
1677
3384
  users,
@@ -1690,6 +3397,25 @@ const treeseedMarketSchema = {
1690
3397
  teamMemberships,
1691
3398
  teamRoleBindings,
1692
3399
  webSessions,
3400
+ commonsParticipants,
3401
+ commonsQuestions,
3402
+ commonsProposals,
3403
+ commonsWeightSnapshots,
3404
+ commonsProposalBackings,
3405
+ commonsProposalVotes,
3406
+ commonsDelegations,
3407
+ commonsDecisions,
3408
+ commonsGovernanceEvents,
3409
+ teamGovernancePolicies,
3410
+ projectGovernancePolicies,
3411
+ governanceProposals,
3412
+ governanceProposalVersions,
3413
+ governanceElectorateSnapshots,
3414
+ governanceProposalVotes,
3415
+ governanceVoteEvents,
3416
+ governanceDelegations,
3417
+ governanceDecisions,
3418
+ governanceEvents,
1693
3419
  projects,
1694
3420
  projectConnections,
1695
3421
  projectCapabilityGrants,
@@ -1702,6 +3428,35 @@ const treeseedMarketSchema = {
1702
3428
  catalogItems,
1703
3429
  catalogArtifactVersions,
1704
3430
  catalogItemCollaborators,
3431
+ commerceVendors,
3432
+ commerceProducts,
3433
+ commerceOwnershipRecords,
3434
+ commerceStewardshipAssignments,
3435
+ commerceContributions,
3436
+ commerceGovernancePolicies,
3437
+ commerceOwnershipTransfers,
3438
+ commerceProductVersions,
3439
+ commerceOffers,
3440
+ commercePrices,
3441
+ commerceGovernanceEvents,
3442
+ commerceCarts,
3443
+ commerceCartItems,
3444
+ commerceCheckouts,
3445
+ commerceOrders,
3446
+ commerceOrderItems,
3447
+ commercePaymentGroups,
3448
+ commerceSubscriptions,
3449
+ commerceEntitlements,
3450
+ commerceBuyerStripeCustomers,
3451
+ commerceRefunds,
3452
+ commerceFulfillmentEvents,
3453
+ commerceServiceRequests,
3454
+ commerceServiceQuotes,
3455
+ commerceServiceContracts,
3456
+ commerceServiceEvents,
3457
+ commerceCapacityListings,
3458
+ commerceCapacityListingInquiries,
3459
+ commerceWebhookEvents,
1705
3460
  projectHosting,
1706
3461
  projectEnvironments,
1707
3462
  projectInfrastructureResources,
@@ -1743,6 +3498,17 @@ const treeseedMarketSchema = {
1743
3498
  repositoryHosts,
1744
3499
  hubRepositories,
1745
3500
  hubContentSources,
3501
+ treeDxInstances,
3502
+ treeDxProjectLibraries,
3503
+ treeDxMirrors,
3504
+ treeDxShares,
3505
+ treeDxDeployments,
3506
+ secretMetadataRecords,
3507
+ clientEncryptedEscrowRecords,
3508
+ githubRepositoryGrants,
3509
+ workflowOperationRecords,
3510
+ workflowDispatchRecords,
3511
+ treeDxCredentialIssuanceRecords,
1746
3512
  hubLaunches,
1747
3513
  hubLaunchEvents,
1748
3514
  hubWorkspaceLinks,
@@ -1759,6 +3525,11 @@ const treeseedMarketSchema = {
1759
3525
  messageQueue,
1760
3526
  capacityProviderRegistrations,
1761
3527
  capacityProviderDeployments,
3528
+ capacityAllocationSets,
3529
+ projectAgentClasses,
3530
+ providerAvailabilitySessions,
3531
+ providerAssignments,
3532
+ agentModeRuns,
1762
3533
  platformOperations,
1763
3534
  platformOperationEvents,
1764
3535
  marketOperationRunners,
@@ -1770,7 +3541,9 @@ const treeseedMarketSchema = {
1770
3541
  marketAuthPasswordResets
1771
3542
  };
1772
3543
  export {
3544
+ agentCapacityPlans,
1773
3545
  agentMessages,
3546
+ agentModeRuns,
1774
3547
  agentPoolRegistrations,
1775
3548
  agentPoolScaleDecisions,
1776
3549
  agentPools,
@@ -1783,6 +3556,7 @@ export {
1783
3556
  betterAuthSession,
1784
3557
  betterAuthUser,
1785
3558
  betterAuthVerification,
3559
+ capacityAllocationSets,
1786
3560
  capacityGrants,
1787
3561
  capacityLedgerEntries,
1788
3562
  capacityProviderApiKeys,
@@ -1796,14 +3570,68 @@ export {
1796
3570
  catalogArtifactVersions,
1797
3571
  catalogItemCollaborators,
1798
3572
  catalogItems,
3573
+ clientEncryptedEscrowRecords,
3574
+ commerceBuyerStripeCustomers,
3575
+ commerceCapacityListingInquiries,
3576
+ commerceCapacityListings,
3577
+ commerceCartItems,
3578
+ commerceCarts,
3579
+ commerceCheckouts,
3580
+ commerceContributions,
3581
+ commerceEntitlements,
3582
+ commerceFulfillmentEvents,
3583
+ commerceGovernanceEvents,
3584
+ commerceGovernancePolicies,
3585
+ commerceOffers,
3586
+ commerceOrderItems,
3587
+ commerceOrders,
3588
+ commerceOwnershipRecords,
3589
+ commerceOwnershipTransfers,
3590
+ commercePaymentGroups,
3591
+ commercePrices,
3592
+ commerceProductVersions,
3593
+ commerceProducts,
3594
+ commerceRefunds,
3595
+ commerceServiceContracts,
3596
+ commerceServiceEvents,
3597
+ commerceServiceQuotes,
3598
+ commerceServiceRequests,
3599
+ commerceStewardshipAssignments,
3600
+ commerceSubscriptions,
3601
+ commerceSuccessionEvents,
3602
+ commerceVendorStripeAccounts,
3603
+ commerceVendors,
3604
+ commerceWebhookEvents,
3605
+ commonsDecisions,
3606
+ commonsDelegations,
3607
+ commonsGovernanceEvents,
3608
+ commonsParticipants,
3609
+ commonsProposalBackings,
3610
+ commonsProposalVotes,
3611
+ commonsProposals,
3612
+ commonsQuestions,
3613
+ commonsWeightSnapshots,
1799
3614
  contactSubmissions,
1800
3615
  creditConversionProfiles,
1801
3616
  cursorState,
3617
+ decisionExecutionInputs,
3618
+ decisionPlanningStatuses,
1802
3619
  deviceCodes,
1803
3620
  entitlements,
1804
3621
  executionProviderNativeLimits,
1805
3622
  executionProviderObservations,
1806
3623
  executionProviders,
3624
+ githubAppInstallationRecords,
3625
+ githubAppTokenIssuanceRecords,
3626
+ githubRepositoryGrants,
3627
+ governanceDecisions,
3628
+ governanceDelegations,
3629
+ governanceElectorateSnapshots,
3630
+ governanceEvents,
3631
+ governanceProposalVersions,
3632
+ governanceProposalVotes,
3633
+ governanceProposals,
3634
+ governanceVoteEvents,
1807
3635
  graphRuns,
1808
3636
  hubContentSources,
1809
3637
  hubLaunchEvents,
@@ -1818,22 +3646,27 @@ export {
1818
3646
  messageQueue,
1819
3647
  nativeUsageObservations,
1820
3648
  permissions,
3649
+ planningInputRequests,
1821
3650
  platformOperationEvents,
1822
3651
  platformOperations,
1823
3652
  platformRepositoryClaims,
1824
3653
  priorityOverrides,
1825
3654
  prioritySnapshots,
3655
+ projectAgentClasses,
1826
3656
  projectCapabilityGrants,
1827
3657
  projectConnections,
1828
3658
  projectDeploymentEvents,
1829
3659
  projectDeployments,
1830
3660
  projectEnvironments,
3661
+ projectGovernancePolicies,
1831
3662
  projectHosting,
1832
3663
  projectInfrastructureResources,
1833
3664
  projectSummarySnapshots,
1834
3665
  projectUpdatePlans,
1835
3666
  projectWorkdaySummaries,
1836
3667
  projects,
3668
+ providerAssignments,
3669
+ providerAvailabilitySessions,
1837
3670
  providerCredentialSessions,
1838
3671
  remoteJobEvents,
1839
3672
  remoteJobs,
@@ -1845,18 +3678,20 @@ export {
1845
3678
  runnerScaleDecisions,
1846
3679
  runtimeEnvelopes,
1847
3680
  runtimeRecords,
3681
+ runtimeTaskEvents,
3682
+ runtimeTaskOutputs,
3683
+ runtimeTasks,
1848
3684
  scaleDecisions,
3685
+ secretMetadataRecords,
1849
3686
  seedRuns,
1850
3687
  serviceCredentials,
1851
3688
  subscribers,
1852
3689
  taskCreditLedger,
1853
3690
  taskEstimateProfiles,
1854
3691
  taskEstimates,
1855
- taskEvents,
1856
- taskOutputs,
1857
3692
  taskUsageActuals,
1858
- tasks,
1859
3693
  teamApiKeys,
3694
+ teamGovernancePolicies,
1860
3695
  teamInboxItems,
1861
3696
  teamInvites,
1862
3697
  teamMemberships,
@@ -1864,6 +3699,14 @@ export {
1864
3699
  teamStorageLocators,
1865
3700
  teamWebHosts,
1866
3701
  teams,
3702
+ treeDxCredentialIssuanceRecords,
3703
+ treeDxDeployments,
3704
+ treeDxInstances,
3705
+ treeDxMirrors,
3706
+ treeDxProjectLibraries,
3707
+ treeDxProjectProxyAudit,
3708
+ treeDxProxyHandles,
3709
+ treeDxShares,
1867
3710
  treeseedMarketSchema,
1868
3711
  userEmailAddresses,
1869
3712
  userIdentities,
@@ -1873,7 +3716,10 @@ export {
1873
3716
  webSessions,
1874
3717
  workDays,
1875
3718
  workPolicies,
3719
+ workdayCapacityEnvelopes,
1876
3720
  workdayManagerLeases,
1877
3721
  workdayRequests,
1878
- workerRunners
3722
+ workerRunners,
3723
+ workflowDispatchRecords,
3724
+ workflowOperationRecords
1879
3725
  };