@flowdular/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (883) hide show
  1. package/.ai/agents/README.md +27 -0
  2. package/.ai/agents/module-executor.md +36 -0
  3. package/.ai/agents/reviewer.md +23 -0
  4. package/.ai/agents/sandbox/agentic-engineer.md +31 -0
  5. package/.ai/agents/sandbox/backend-engineer.md +36 -0
  6. package/.ai/agents/sandbox/business-manager.md +23 -0
  7. package/.ai/agents/sandbox/frontend-engineer.md +27 -0
  8. package/.ai/agents/sandbox/ux-designer.md +23 -0
  9. package/.ai/agents/spec-author.md +29 -0
  10. package/.ai/blueprints/add-migration/README.md +5 -0
  11. package/.ai/blueprints/add-migration/allowed-paths.yaml +23 -0
  12. package/.ai/blueprints/add-migration/blueprint.json +14 -0
  13. package/.ai/blueprints/add-migration/examples/invalid/input-destructive.json +6 -0
  14. package/.ai/blueprints/add-migration/examples/invalid/plan-unnumbered-file.json +9 -0
  15. package/.ai/blueprints/add-migration/examples/valid/input.json +6 -0
  16. package/.ai/blueprints/add-migration/examples/valid/plan.json +9 -0
  17. package/.ai/blueprints/add-migration/gates.yaml +30 -0
  18. package/.ai/blueprints/add-migration/input.schema.json +23 -0
  19. package/.ai/blueprints/add-migration/plan.schema.json +54 -0
  20. package/.ai/blueprints/add-migration/required-files.yaml +18 -0
  21. package/.ai/blueprints/add-migration/spec-requirements.yaml +13 -0
  22. package/.ai/blueprints/add-migration/steps.yaml +62 -0
  23. package/.ai/blueprints/author-spec/README.md +5 -0
  24. package/.ai/blueprints/author-spec/allowed-paths.yaml +7 -0
  25. package/.ai/blueprints/author-spec/blueprint.json +14 -0
  26. package/.ai/blueprints/author-spec/examples/invalid/input-missing-outcome.json +5 -0
  27. package/.ai/blueprints/author-spec/examples/valid/input.json +6 -0
  28. package/.ai/blueprints/author-spec/gates.yaml +13 -0
  29. package/.ai/blueprints/author-spec/input.schema.json +20 -0
  30. package/.ai/blueprints/author-spec/plan.schema.json +14 -0
  31. package/.ai/blueprints/author-spec/required-files.yaml +6 -0
  32. package/.ai/blueprints/author-spec/spec-requirements.yaml +35 -0
  33. package/.ai/blueprints/author-spec/steps.yaml +28 -0
  34. package/.ai/blueprints/author-spec/templates/module.yaml +45 -0
  35. package/.ai/blueprints/bug-fix/README.md +5 -0
  36. package/.ai/blueprints/bug-fix/allowed-paths.yaml +29 -0
  37. package/.ai/blueprints/bug-fix/blueprint.json +14 -0
  38. package/.ai/blueprints/bug-fix/examples/invalid/input-no-symptom.json +4 -0
  39. package/.ai/blueprints/bug-fix/examples/invalid/plan-no-test.json +8 -0
  40. package/.ai/blueprints/bug-fix/examples/valid/input.json +6 -0
  41. package/.ai/blueprints/bug-fix/examples/valid/plan.json +8 -0
  42. package/.ai/blueprints/bug-fix/gates.yaml +30 -0
  43. package/.ai/blueprints/bug-fix/input.schema.json +25 -0
  44. package/.ai/blueprints/bug-fix/plan.schema.json +53 -0
  45. package/.ai/blueprints/bug-fix/required-files.yaml +7 -0
  46. package/.ai/blueprints/bug-fix/spec-requirements.yaml +7 -0
  47. package/.ai/blueprints/bug-fix/steps.yaml +51 -0
  48. package/.ai/blueprints/core-extend/README.md +5 -0
  49. package/.ai/blueprints/core-extend/allowed-paths.yaml +49 -0
  50. package/.ai/blueprints/core-extend/blueprint.json +14 -0
  51. package/.ai/blueprints/core-extend/examples/invalid/input-unknown-package.json +5 -0
  52. package/.ai/blueprints/core-extend/examples/invalid/plan-missing-gates.json +7 -0
  53. package/.ai/blueprints/core-extend/examples/valid/input.json +6 -0
  54. package/.ai/blueprints/core-extend/examples/valid/plan.json +10 -0
  55. package/.ai/blueprints/core-extend/gates.yaml +16 -0
  56. package/.ai/blueprints/core-extend/input.schema.json +54 -0
  57. package/.ai/blueprints/core-extend/plan.schema.json +39 -0
  58. package/.ai/blueprints/core-extend/required-files.yaml +36 -0
  59. package/.ai/blueprints/core-extend/spec-requirements.yaml +17 -0
  60. package/.ai/blueprints/core-extend/steps.yaml +54 -0
  61. package/.ai/blueprints/edit-module/README.md +9 -0
  62. package/.ai/blueprints/edit-module/allowed-paths.yaml +27 -0
  63. package/.ai/blueprints/edit-module/blueprint.json +20 -0
  64. package/.ai/blueprints/edit-module/examples/invalid/input-unknown-change.json +5 -0
  65. package/.ai/blueprints/edit-module/examples/invalid/plan-touches-platform.json +15 -0
  66. package/.ai/blueprints/edit-module/examples/valid/input.json +5 -0
  67. package/.ai/blueprints/edit-module/examples/valid/plan.json +25 -0
  68. package/.ai/blueprints/edit-module/gates.yaml +30 -0
  69. package/.ai/blueprints/edit-module/input.schema.json +31 -0
  70. package/.ai/blueprints/edit-module/plan.schema.json +65 -0
  71. package/.ai/blueprints/edit-module/required-files.yaml +80 -0
  72. package/.ai/blueprints/edit-module/spec-requirements.yaml +15 -0
  73. package/.ai/blueprints/edit-module/steps.yaml +115 -0
  74. package/.ai/blueprints/new-module/README.md +7 -0
  75. package/.ai/blueprints/new-module/allowed-paths.yaml +27 -0
  76. package/.ai/blueprints/new-module/blueprint.json +20 -0
  77. package/.ai/blueprints/new-module/examples/invalid/input-spec-outside-modules.json +4 -0
  78. package/.ai/blueprints/new-module/examples/invalid/plan-unknown-gate.json +8 -0
  79. package/.ai/blueprints/new-module/examples/valid/input.json +5 -0
  80. package/.ai/blueprints/new-module/examples/valid/plan.json +22 -0
  81. package/.ai/blueprints/new-module/gates.yaml +30 -0
  82. package/.ai/blueprints/new-module/input.schema.json +21 -0
  83. package/.ai/blueprints/new-module/plan.schema.json +58 -0
  84. package/.ai/blueprints/new-module/required-files.yaml +73 -0
  85. package/.ai/blueprints/new-module/spec-requirements.yaml +30 -0
  86. package/.ai/blueprints/new-module/steps.yaml +138 -0
  87. package/.ai/blueprints/release/README.md +5 -0
  88. package/.ai/blueprints/release/allowed-paths.yaml +19 -0
  89. package/.ai/blueprints/release/blueprint.json +14 -0
  90. package/.ai/blueprints/release/examples/invalid/input-bad-version.json +4 -0
  91. package/.ai/blueprints/release/examples/invalid/plan-bad-branch.json +7 -0
  92. package/.ai/blueprints/release/examples/valid/input.json +5 -0
  93. package/.ai/blueprints/release/examples/valid/plan.json +20 -0
  94. package/.ai/blueprints/release/gates.yaml +20 -0
  95. package/.ai/blueprints/release/input.schema.json +24 -0
  96. package/.ai/blueprints/release/plan.schema.json +46 -0
  97. package/.ai/blueprints/release/required-files.yaml +19 -0
  98. package/.ai/blueprints/release/spec-requirements.yaml +8 -0
  99. package/.ai/blueprints/release/steps.yaml +47 -0
  100. package/.ai/blueprints/security-review/README.md +5 -0
  101. package/.ai/blueprints/security-review/allowed-paths.yaml +6 -0
  102. package/.ai/blueprints/security-review/blueprint.json +14 -0
  103. package/.ai/blueprints/security-review/examples/invalid/input-unknown-kind.json +4 -0
  104. package/.ai/blueprints/security-review/examples/invalid/plan-finding-without-scenario.json +14 -0
  105. package/.ai/blueprints/security-review/examples/valid/input.json +4 -0
  106. package/.ai/blueprints/security-review/examples/valid/plan.json +19 -0
  107. package/.ai/blueprints/security-review/gates.yaml +22 -0
  108. package/.ai/blueprints/security-review/input.schema.json +20 -0
  109. package/.ai/blueprints/security-review/plan.schema.json +65 -0
  110. package/.ai/blueprints/security-review/required-files.yaml +6 -0
  111. package/.ai/blueprints/security-review/spec-requirements.yaml +9 -0
  112. package/.ai/blueprints/security-review/steps.yaml +38 -0
  113. package/.ai/policies/capabilities.yaml +164 -0
  114. package/.ai/policies/model-routing.yaml +72 -0
  115. package/.ai/policies/path-ownership.yaml +65 -0
  116. package/.ai/policies/task-budgets.yaml +37 -0
  117. package/.ai/references/catalog/LICENSE +21 -0
  118. package/.ai/references/catalog/migrations/0001_catalog_core.down.sql +2 -0
  119. package/.ai/references/catalog/migrations/0001_catalog_core.up.sql +21 -0
  120. package/.ai/references/catalog/migrations/0002_catalog_history.down.sql +3 -0
  121. package/.ai/references/catalog/migrations/0002_catalog_history.up.sql +20 -0
  122. package/.ai/references/catalog/migrations/0003_catalog_history_service_actors.down.sql +3 -0
  123. package/.ai/references/catalog/migrations/0003_catalog_history_service_actors.up.sql +36 -0
  124. package/.ai/references/catalog/migrations/0004_catalog_idempotency_ledger.down.sql +3 -0
  125. package/.ai/references/catalog/migrations/0004_catalog_idempotency_ledger.up.sql +19 -0
  126. package/.ai/references/catalog/migrations/README.md +3 -0
  127. package/.ai/references/catalog/module.json +27 -0
  128. package/.ai/references/catalog/package.json +49 -0
  129. package/.ai/references/catalog/spec/module.yaml +86 -0
  130. package/.ai/references/catalog/src/acl/permissions.ts +6 -0
  131. package/.ai/references/catalog/src/agent/tools.ts +164 -0
  132. package/.ai/references/catalog/src/api/endpoints.ts +243 -0
  133. package/.ai/references/catalog/src/client/CatalogHistoryDrawer.tsrx +123 -0
  134. package/.ai/references/catalog/src/client/CatalogItemForm.tsrx +190 -0
  135. package/.ai/references/catalog/src/client/CatalogView.tsrx +473 -0
  136. package/.ai/references/catalog/src/client/api.ts +111 -0
  137. package/.ai/references/catalog/src/client/contribution.tsrx +61 -0
  138. package/.ai/references/catalog/src/client/index.ts +18 -0
  139. package/.ai/references/catalog/src/client/navigation-copy.ts +9 -0
  140. package/.ai/references/catalog/src/client/state.ts +24 -0
  141. package/.ai/references/catalog/src/domain/types.ts +32 -0
  142. package/.ai/references/catalog/src/domain/variables.ts +111 -0
  143. package/.ai/references/catalog/src/index.ts +31 -0
  144. package/.ai/references/catalog/src/platform.ts +35 -0
  145. package/.ai/references/catalog/src/server/index.ts +4 -0
  146. package/.ai/references/catalog/src/server/runtime.ts +86 -0
  147. package/.ai/references/catalog/src/services/catalog-service.ts +306 -0
  148. package/.ai/references/catalog/src/services/database-repository.ts +440 -0
  149. package/.ai/references/catalog/src/services/index.ts +4 -0
  150. package/.ai/references/catalog/src/services/migration.ts +171 -0
  151. package/.ai/references/catalog/src/services/repository.ts +36 -0
  152. package/.ai/references/catalog/src/services/target-idempotency.ts +59 -0
  153. package/.ai/references/catalog/tests/agent-tools.test.ts +277 -0
  154. package/.ai/references/catalog/tests/endpoints.test.ts +320 -0
  155. package/.ai/references/catalog/tests/idempotency.test.ts +297 -0
  156. package/.ai/references/catalog/tests/migrations.test.ts +149 -0
  157. package/.ai/references/catalog/tests/module.test.ts +271 -0
  158. package/.ai/references/catalog/tests/support/database.ts +76 -0
  159. package/.ai/references/catalog/translations/en.json +101 -0
  160. package/.ai/references/catalog/translations/pl.json +101 -0
  161. package/.ai/references/catalog/tsconfig.json +15 -0
  162. package/.ai/references/catalog/vitest.config.ts +16 -0
  163. package/.ai/references/catalog.provenance.json +55 -0
  164. package/.ai/skills/README.md +36 -0
  165. package/.ai/skills/agent-tool-design/SKILL.md +209 -0
  166. package/.ai/skills/auth-security-review/SKILL.md +96 -0
  167. package/.ai/skills/auto-review/SKILL.md +112 -0
  168. package/.ai/skills/bug-hunt/SKILL.md +110 -0
  169. package/.ai/skills/business-agent-design/SKILL.md +188 -0
  170. package/.ai/skills/cli-extension/SKILL.md +114 -0
  171. package/.ai/skills/core-extend/SKILL.md +104 -0
  172. package/.ai/skills/database-adapter/SKILL.md +204 -0
  173. package/.ai/skills/database-adapter/references/first-run-and-matrix.md +105 -0
  174. package/.ai/skills/migration-authoring/SKILL.md +167 -0
  175. package/.ai/skills/module-new/SKILL.md +180 -0
  176. package/.ai/skills/module-update/SKILL.md +100 -0
  177. package/.ai/skills/perf-audit/SKILL.md +105 -0
  178. package/.ai/skills/release-eject-pr/SKILL.md +113 -0
  179. package/.ai/skills/spec-approval/SKILL.md +112 -0
  180. package/.ai/skills/test-hardening/SKILL.md +86 -0
  181. package/.ai/skills/translations-i18n/SKILL.md +85 -0
  182. package/.ai/skills/ux-design/SKILL.md +97 -0
  183. package/.ai/skills/variables/SKILL.md +164 -0
  184. package/.ai/skills/workflow-development/SKILL.md +199 -0
  185. package/AGENTS.md +59 -0
  186. package/LICENSE +21 -0
  187. package/README.md +24 -0
  188. package/docs/agent-contract.md +45 -0
  189. package/docs/design-system.md +217 -0
  190. package/modules/agents/migrations/0001_agents_core.down.sql +4 -0
  191. package/modules/agents/migrations/0001_agents_core.up.sql +106 -0
  192. package/modules/agents/migrations/0002_provider_connections.down.sql +1 -0
  193. package/modules/agents/migrations/0002_provider_connections.up.sql +34 -0
  194. package/modules/agents/migrations/0003_resource_audit.down.sql +1 -0
  195. package/modules/agents/migrations/0003_resource_audit.up.sql +25 -0
  196. package/modules/agents/migrations/0004_run_grants.down.sql +1 -0
  197. package/modules/agents/migrations/0004_run_grants.up.sql +19 -0
  198. package/modules/agents/migrations/0005_long_running_limits.down.sql +2 -0
  199. package/modules/agents/migrations/0005_long_running_limits.up.sql +14 -0
  200. package/modules/agents/migrations/0006_agent_skills.down.sql +3 -0
  201. package/modules/agents/migrations/0006_agent_skills.up.sql +44 -0
  202. package/modules/agents/migrations/0007_model_readiness.down.sql +1 -0
  203. package/modules/agents/migrations/0007_model_readiness.up.sql +18 -0
  204. package/modules/agents/migrations/0008_output_limits.down.sql +2 -0
  205. package/modules/agents/migrations/0008_output_limits.up.sql +8 -0
  206. package/modules/agents/migrations/0009_agent_audit_v3.down.sql +1 -0
  207. package/modules/agents/migrations/0009_agent_audit_v3.up.sql +25 -0
  208. package/modules/agents/migrations/0012_agent_run_costs.down.sql +3 -0
  209. package/modules/agents/migrations/0012_agent_run_costs.up.sql +32 -0
  210. package/modules/agents/migrations/0013_workflow_prerequisites.down.sql +3 -0
  211. package/modules/agents/migrations/0013_workflow_prerequisites.up.sql +97 -0
  212. package/modules/agents/migrations/0014_agent_action_audit.down.sql +1 -0
  213. package/modules/agents/migrations/0014_agent_action_audit.up.sql +25 -0
  214. package/modules/agents/migrations/0015_agent_run_actors.down.sql +1 -0
  215. package/modules/agents/migrations/0015_agent_run_actors.up.sql +17 -0
  216. package/modules/agents/migrations/0016_module_owned_agents.down.sql +6 -0
  217. package/modules/agents/migrations/0016_module_owned_agents.up.sql +68 -0
  218. package/modules/agents/migrations/0017_agent_authorization_subjects.down.sql +2 -0
  219. package/modules/agents/migrations/0017_agent_authorization_subjects.up.sql +18 -0
  220. package/modules/agents/migrations/0018_agent_child_tenant_isolation.down.sql +12 -0
  221. package/modules/agents/migrations/0018_agent_child_tenant_isolation.up.sql +88 -0
  222. package/modules/agents/migrations/0019_background_recovery_grants.down.sql +6 -0
  223. package/modules/agents/migrations/0019_background_recovery_grants.up.sql +17 -0
  224. package/modules/agents/migrations/0020_provider_summary_role.down.sql +2 -0
  225. package/modules/agents/migrations/0020_provider_summary_role.up.sql +17 -0
  226. package/modules/agents/migrations/0021_agents_agent_reconciliation_role.down.sql +4 -0
  227. package/modules/agents/migrations/0021_agents_agent_reconciliation_role.up.sql +7 -0
  228. package/modules/agents/migrations/README.md +39 -0
  229. package/modules/agents/module.json +38 -0
  230. package/modules/agents/package.json +56 -0
  231. package/modules/agents/spec/module.yaml +271 -0
  232. package/modules/agents/spec/procedures-compatibility.md +63 -0
  233. package/modules/agents/src/acl/permissions.ts +13 -0
  234. package/modules/agents/src/api/endpoints.ts +1122 -0
  235. package/modules/agents/src/cli/commands.json +29 -0
  236. package/modules/agents/src/cli/index.ts +162 -0
  237. package/modules/agents/src/client/AgentDashboardWidget.tsrx +32 -0
  238. package/modules/agents/src/client/AgentDefinitionForm.tsrx +362 -0
  239. package/modules/agents/src/client/AgentDefinitionList.tsrx +127 -0
  240. package/modules/agents/src/client/AgentPlaygroundView.tsrx +246 -0
  241. package/modules/agents/src/client/AgentProcedureForm.tsrx +182 -0
  242. package/modules/agents/src/client/AgentProcedureList.tsrx +118 -0
  243. package/modules/agents/src/client/AgentProceduresView.tsrx +253 -0
  244. package/modules/agents/src/client/AgentProvidersView.tsrx +248 -0
  245. package/modules/agents/src/client/AgentRunsView.tsrx +304 -0
  246. package/modules/agents/src/client/AgentUsageView.tsrx +233 -0
  247. package/modules/agents/src/client/AgentsView.tsrx +339 -0
  248. package/modules/agents/src/client/ModuleAgentBindingForm.tsrx +239 -0
  249. package/modules/agents/src/client/ModuleAgentList.tsrx +122 -0
  250. package/modules/agents/src/client/ProviderConnectionForm.tsrx +273 -0
  251. package/modules/agents/src/client/ProviderConnectionList.tsrx +229 -0
  252. package/modules/agents/src/client/ProviderModelEditor.tsrx +313 -0
  253. package/modules/agents/src/client/RunTimeline.tsrx +212 -0
  254. package/modules/agents/src/client/agents.css +349 -0
  255. package/modules/agents/src/client/api.ts +373 -0
  256. package/modules/agents/src/client/contribution.tsrx +181 -0
  257. package/modules/agents/src/client/index.ts +21 -0
  258. package/modules/agents/src/client/presentation.ts +162 -0
  259. package/modules/agents/src/client/state.ts +100 -0
  260. package/modules/agents/src/domain/context-variables.ts +58 -0
  261. package/modules/agents/src/domain/run-timeline.ts +145 -0
  262. package/modules/agents/src/domain/types.ts +481 -0
  263. package/modules/agents/src/index.ts +88 -0
  264. package/modules/agents/src/platform.ts +82 -0
  265. package/modules/agents/src/server/action-execution.ts +811 -0
  266. package/modules/agents/src/server/define-agent.ts +170 -0
  267. package/modules/agents/src/server/index.ts +67 -0
  268. package/modules/agents/src/server/run-execution.ts +231 -0
  269. package/modules/agents/src/server/run-queue.ts +96 -0
  270. package/modules/agents/src/server/runtime.ts +448 -0
  271. package/modules/agents/src/server/tools.ts +18 -0
  272. package/modules/agents/src/services/agent-service.ts +2167 -0
  273. package/modules/agents/src/services/credential-vault.ts +133 -0
  274. package/modules/agents/src/services/database-repository.ts +2786 -0
  275. package/modules/agents/src/services/index.ts +33 -0
  276. package/modules/agents/src/services/migration.ts +1152 -0
  277. package/modules/agents/src/services/module-agent-preflight.ts +76 -0
  278. package/modules/agents/src/services/outbound-policy.ts +136 -0
  279. package/modules/agents/src/services/provider-broker.ts +80 -0
  280. package/modules/agents/src/services/provider-repository.ts +589 -0
  281. package/modules/agents/src/services/provider-service.ts +968 -0
  282. package/modules/agents/src/services/repository.ts +294 -0
  283. package/modules/agents/src/services/run-grant.ts +305 -0
  284. package/modules/agents/src/services/usage-service.ts +119 -0
  285. package/modules/agents/src/services/worker.ts +442 -0
  286. package/modules/agents/src/settings.ts +244 -0
  287. package/modules/agents/translations/en.json +403 -0
  288. package/modules/agents/translations/pl.json +403 -0
  289. package/modules/auth/README.md +215 -0
  290. package/modules/auth/migrations/0001_auth_core.up.sql +108 -0
  291. package/modules/auth/migrations/0002_bundled_module_scopes.up.sql +26 -0
  292. package/modules/auth/migrations/0003_agent_core_scopes.up.sql +12 -0
  293. package/modules/auth/migrations/0004_owner_only_development_scopes.up.sql +8 -0
  294. package/modules/auth/migrations/0005_agent_provider_scopes.up.sql +13 -0
  295. package/modules/auth/migrations/0006_tenant_slug.up.sql +6 -0
  296. package/modules/auth/migrations/0007_sandbox_scopes.up.sql +13 -0
  297. package/modules/auth/migrations/0008_api_tokens.up.sql +43 -0
  298. package/modules/auth/migrations/0009_module_settings.up.sql +24 -0
  299. package/modules/auth/migrations/0010_sign_in_lockout.up.sql +11 -0
  300. package/modules/auth/migrations/0011_session_ids_and_password_reset.up.sql +7 -0
  301. package/modules/auth/migrations/0012_roles.up.sql +31 -0
  302. package/modules/auth/migrations/0013_audit.up.sql +27 -0
  303. package/modules/auth/migrations/0014_audit_actor.up.sql +4 -0
  304. package/modules/auth/migrations/0015_account_security.up.sql +81 -0
  305. package/modules/auth/module.json +26 -0
  306. package/modules/auth/package.json +61 -0
  307. package/modules/auth/spec/module.yaml +190 -0
  308. package/modules/auth/src/acl/scopes.ts +86 -0
  309. package/modules/auth/src/api/attempt-limiter.ts +42 -0
  310. package/modules/auth/src/api/client-address.ts +14 -0
  311. package/modules/auth/src/api/cookies.ts +52 -0
  312. package/modules/auth/src/api/origin.ts +40 -0
  313. package/modules/auth/src/cli/commands.json +74 -0
  314. package/modules/auth/src/cli/database.ts +51 -0
  315. package/modules/auth/src/cli/greenfield.ts +173 -0
  316. package/modules/auth/src/cli/index.ts +184 -0
  317. package/modules/auth/src/cli/provisioning.ts +211 -0
  318. package/modules/auth/src/client/AuthBackdrop.tsrx +137 -0
  319. package/modules/auth/src/client/AuthenticationCore.tsrx +630 -0
  320. package/modules/auth/src/client/PasswordChangeRequired.tsrx +145 -0
  321. package/modules/auth/src/client/PublicAuthFlows.tsrx +379 -0
  322. package/modules/auth/src/client/api.ts +464 -0
  323. package/modules/auth/src/client/audit/AuditView.tsrx +357 -0
  324. package/modules/auth/src/client/audit/api.ts +164 -0
  325. package/modules/auth/src/client/audit/audit-columns.tsrx +47 -0
  326. package/modules/auth/src/client/audit/audit-row.ts +38 -0
  327. package/modules/auth/src/client/auth.css +483 -0
  328. package/modules/auth/src/client/contribution.tsrx +100 -0
  329. package/modules/auth/src/client/index.ts +32 -0
  330. package/modules/auth/src/client/security/SecurityView.tsrx +253 -0
  331. package/modules/auth/src/client/settings/PreferencesCard.tsrx +65 -0
  332. package/modules/auth/src/client/settings/SettingsView.tsrx +212 -0
  333. package/modules/auth/src/client/settings/WorkspaceCard.tsrx +59 -0
  334. package/modules/auth/src/client/settings/api.ts +115 -0
  335. package/modules/auth/src/client/slug.ts +26 -0
  336. package/modules/auth/src/client/state.ts +115 -0
  337. package/modules/auth/src/client/tokens/ApiTokenForm.tsrx +153 -0
  338. package/modules/auth/src/client/tokens/ApiTokenSecret.tsrx +35 -0
  339. package/modules/auth/src/client/tokens/ApiTokensView.tsrx +216 -0
  340. package/modules/auth/src/client/tokens/api.ts +59 -0
  341. package/modules/auth/src/client/tokens/state.ts +26 -0
  342. package/modules/auth/src/client/tokens/token-columns.tsrx +64 -0
  343. package/modules/auth/src/client/translations.ts +23 -0
  344. package/modules/auth/src/domain/types.ts +152 -0
  345. package/modules/auth/src/index.ts +42 -0
  346. package/modules/auth/src/middleware/authentication.ts +97 -0
  347. package/modules/auth/src/platform.ts +0 -0
  348. package/modules/auth/src/server/actor.ts +12 -0
  349. package/modules/auth/src/server/audit-endpoints.ts +51 -0
  350. package/modules/auth/src/server/composition.ts +9 -0
  351. package/modules/auth/src/server/endpoints.ts +893 -0
  352. package/modules/auth/src/server/http.ts +153 -0
  353. package/modules/auth/src/server/index.ts +37 -0
  354. package/modules/auth/src/server/roles-endpoints.ts +120 -0
  355. package/modules/auth/src/server/runtime.ts +705 -0
  356. package/modules/auth/src/server/session-endpoints.ts +86 -0
  357. package/modules/auth/src/server/session-security.ts +62 -0
  358. package/modules/auth/src/server/token-endpoints.ts +106 -0
  359. package/modules/auth/src/services/auth-service-error.ts +11 -0
  360. package/modules/auth/src/services/auth-service.ts +2309 -0
  361. package/modules/auth/src/services/database-repository.ts +1825 -0
  362. package/modules/auth/src/services/mail-delivery.ts +27 -0
  363. package/modules/auth/src/services/migration.ts +591 -0
  364. package/modules/auth/src/services/password.ts +115 -0
  365. package/modules/auth/src/services/repository.ts +395 -0
  366. package/modules/auth/src/services/settings-store.ts +92 -0
  367. package/modules/auth/src/services/totp.ts +135 -0
  368. package/modules/auth/src/services/validation.ts +186 -0
  369. package/modules/auth/src/settings.ts +150 -0
  370. package/modules/auth/translations/en.json +263 -0
  371. package/modules/auth/translations/pl.json +263 -0
  372. package/modules/automations/migrations/0001_automations_core.down.sql +10 -0
  373. package/modules/automations/migrations/0001_automations_core.up.sql +76 -0
  374. package/modules/automations/migrations/0002_automations_targets.down.sql +9 -0
  375. package/modules/automations/migrations/0002_automations_targets.up.sql +37 -0
  376. package/modules/automations/migrations/0003_automations_scheduler_role.down.sql +3 -0
  377. package/modules/automations/migrations/0003_automations_scheduler_role.up.sql +19 -0
  378. package/modules/automations/migrations/0004_automations_trigger_routing_role.down.sql +3 -0
  379. package/modules/automations/migrations/0004_automations_trigger_routing_role.up.sql +18 -0
  380. package/modules/automations/migrations/README.md +3 -0
  381. package/modules/automations/module.json +31 -0
  382. package/modules/automations/package.json +55 -0
  383. package/modules/automations/spec/module.yaml +93 -0
  384. package/modules/automations/src/acl/permissions.ts +10 -0
  385. package/modules/automations/src/api/endpoints.ts +480 -0
  386. package/modules/automations/src/client/AutomationScheduleForm.tsrx +218 -0
  387. package/modules/automations/src/client/AutomationSchedulesView.tsrx +339 -0
  388. package/modules/automations/src/client/AutomationTriggerForm.tsrx +190 -0
  389. package/modules/automations/src/client/AutomationTriggersView.tsrx +329 -0
  390. package/modules/automations/src/client/api.ts +148 -0
  391. package/modules/automations/src/client/contribution.tsrx +70 -0
  392. package/modules/automations/src/client/index.ts +20 -0
  393. package/modules/automations/src/client/presentation.ts +38 -0
  394. package/modules/automations/src/client/state.ts +40 -0
  395. package/modules/automations/src/client/target-selection.ts +44 -0
  396. package/modules/automations/src/domain/cadence.ts +44 -0
  397. package/modules/automations/src/domain/types.ts +110 -0
  398. package/modules/automations/src/domain/variables.ts +178 -0
  399. package/modules/automations/src/index.ts +39 -0
  400. package/modules/automations/src/platform.ts +73 -0
  401. package/modules/automations/src/server/execution.ts +77 -0
  402. package/modules/automations/src/server/index.ts +39 -0
  403. package/modules/automations/src/server/runtime.ts +218 -0
  404. package/modules/automations/src/server/targets.ts +116 -0
  405. package/modules/automations/src/services/automations-service.ts +10 -0
  406. package/modules/automations/src/services/database-repository.ts +763 -0
  407. package/modules/automations/src/services/index.ts +5 -0
  408. package/modules/automations/src/services/migration.ts +223 -0
  409. package/modules/automations/src/services/repository.ts +119 -0
  410. package/modules/automations/src/services/schedule-service.ts +837 -0
  411. package/modules/automations/src/services/secret-vault.ts +124 -0
  412. package/modules/automations/src/services/trigger-service.ts +648 -0
  413. package/modules/automations/src/settings.ts +69 -0
  414. package/modules/automations/translations/en.json +126 -0
  415. package/modules/automations/translations/pl.json +126 -0
  416. package/modules/automations-workflows-integration/module.json +27 -0
  417. package/modules/automations-workflows-integration/package.json +48 -0
  418. package/modules/automations-workflows-integration/spec/module.yaml +93 -0
  419. package/modules/automations-workflows-integration/src/index.ts +14 -0
  420. package/modules/automations-workflows-integration/src/platform.ts +24 -0
  421. package/modules/automations-workflows-integration/src/server/adapter.ts +272 -0
  422. package/modules/automations-workflows-integration/src/server/index.ts +11 -0
  423. package/modules/automations-workflows-integration/src/server/tools.ts +0 -0
  424. package/modules/automations-workflows-integration/translations/en.json +21 -0
  425. package/modules/automations-workflows-integration/translations/pl.json +21 -0
  426. package/modules/profile/migrations/0001_profile_core.down.sql +1 -0
  427. package/modules/profile/migrations/0001_profile_core.up.sql +13 -0
  428. package/modules/profile/migrations/0002_profile_language.down.sql +1 -0
  429. package/modules/profile/migrations/0002_profile_language.up.sql +12 -0
  430. package/modules/profile/migrations/README.md +3 -0
  431. package/modules/profile/module.json +23 -0
  432. package/modules/profile/package.json +55 -0
  433. package/modules/profile/spec/module.yaml +136 -0
  434. package/modules/profile/src/acl/permissions.ts +5 -0
  435. package/modules/profile/src/api/endpoints.ts +184 -0
  436. package/modules/profile/src/client/DisplayNameCard.tsrx +59 -0
  437. package/modules/profile/src/client/LanguageCard.tsrx +89 -0
  438. package/modules/profile/src/client/PasswordCard.tsrx +79 -0
  439. package/modules/profile/src/client/ProfileView.tsrx +192 -0
  440. package/modules/profile/src/client/SessionsCard.tsrx +158 -0
  441. package/modules/profile/src/client/api.ts +134 -0
  442. package/modules/profile/src/client/contribution.tsrx +61 -0
  443. package/modules/profile/src/client/index.ts +15 -0
  444. package/modules/profile/src/client/password.ts +41 -0
  445. package/modules/profile/src/client/sessions-api.ts +52 -0
  446. package/modules/profile/src/client/state.ts +23 -0
  447. package/modules/profile/src/domain/types.ts +21 -0
  448. package/modules/profile/src/index.ts +21 -0
  449. package/modules/profile/src/platform.ts +23 -0
  450. package/modules/profile/src/server/index.ts +7 -0
  451. package/modules/profile/src/server/runtime.ts +84 -0
  452. package/modules/profile/src/services/database-repository.ts +154 -0
  453. package/modules/profile/src/services/index.ts +6 -0
  454. package/modules/profile/src/services/migration.ts +58 -0
  455. package/modules/profile/src/services/profile-service.ts +114 -0
  456. package/modules/profile/src/services/repository.ts +13 -0
  457. package/modules/profile/translations/en.json +58 -0
  458. package/modules/profile/translations/pl.json +58 -0
  459. package/modules/sandbox/migrations/0001_sandbox_core.down.sql +6 -0
  460. package/modules/sandbox/migrations/0001_sandbox_core.up.sql +70 -0
  461. package/modules/sandbox/migrations/0002_sandbox_session_lifecycle.down.sql +36 -0
  462. package/modules/sandbox/migrations/0002_sandbox_session_lifecycle.up.sql +37 -0
  463. package/modules/sandbox/migrations/README.md +7 -0
  464. package/modules/sandbox/module.json +31 -0
  465. package/modules/sandbox/package.json +56 -0
  466. package/modules/sandbox/spec/module.yaml +111 -0
  467. package/modules/sandbox/src/acl/permissions.ts +18 -0
  468. package/modules/sandbox/src/api/endpoints.ts +439 -0
  469. package/modules/sandbox/src/cli/commands.json +84 -0
  470. package/modules/sandbox/src/cli/index.ts +450 -0
  471. package/modules/sandbox/src/client/SandboxAccessView.tsrx +191 -0
  472. package/modules/sandbox/src/client/SandboxGrantForm.tsrx +134 -0
  473. package/modules/sandbox/src/client/SandboxGrantList.tsrx +83 -0
  474. package/modules/sandbox/src/client/SandboxSessionList.tsrx +56 -0
  475. package/modules/sandbox/src/client/api.ts +87 -0
  476. package/modules/sandbox/src/client/contribution.tsrx +47 -0
  477. package/modules/sandbox/src/client/index.ts +18 -0
  478. package/modules/sandbox/src/client/presentation.ts +47 -0
  479. package/modules/sandbox/src/client/state.ts +20 -0
  480. package/modules/sandbox/src/domain/types.ts +125 -0
  481. package/modules/sandbox/src/index.ts +33 -0
  482. package/modules/sandbox/src/platform.ts +28 -0
  483. package/modules/sandbox/src/server/index.ts +20 -0
  484. package/modules/sandbox/src/server/runtime.ts +119 -0
  485. package/modules/sandbox/src/services/database-repository.ts +567 -0
  486. package/modules/sandbox/src/services/directory.ts +33 -0
  487. package/modules/sandbox/src/services/index.ts +19 -0
  488. package/modules/sandbox/src/services/migration.ts +145 -0
  489. package/modules/sandbox/src/services/repository.ts +55 -0
  490. package/modules/sandbox/src/services/sandbox-service-error.ts +10 -0
  491. package/modules/sandbox/src/services/sandbox-service.ts +533 -0
  492. package/modules/sandbox/translations/en.json +77 -0
  493. package/modules/sandbox/translations/pl.json +77 -0
  494. package/modules/system/module.json +18 -0
  495. package/modules/system/package.json +56 -0
  496. package/modules/system/spec/module.yaml +104 -0
  497. package/modules/system/src/acl/permissions.ts +10 -0
  498. package/modules/system/src/client/ModuleSettingRow.tsrx +191 -0
  499. package/modules/system/src/client/ModuleSettingsSection.tsrx +155 -0
  500. package/modules/system/src/client/ModulesView.tsrx +241 -0
  501. package/modules/system/src/client/api.ts +36 -0
  502. package/modules/system/src/client/contribution.tsrx +48 -0
  503. package/modules/system/src/client/index.ts +26 -0
  504. package/modules/system/src/client/module-columns.tsrx +66 -0
  505. package/modules/system/src/client/overview-api.ts +30 -0
  506. package/modules/system/src/client/setting-copy.ts +30 -0
  507. package/modules/system/src/client/settings-api.ts +57 -0
  508. package/modules/system/src/client/state.ts +16 -0
  509. package/modules/system/src/index.ts +11 -0
  510. package/modules/system/src/platform.ts +11 -0
  511. package/modules/system/src/server/endpoints.ts +372 -0
  512. package/modules/system/src/server/index.ts +11 -0
  513. package/modules/system/src/server/module-catalog.ts +117 -0
  514. package/modules/system/translations/en.json +64 -0
  515. package/modules/system/translations/pl.json +64 -0
  516. package/modules/users/migrations/README.md +3 -0
  517. package/modules/users/module.json +27 -0
  518. package/modules/users/package.json +54 -0
  519. package/modules/users/spec/module.yaml +79 -0
  520. package/modules/users/src/acl/permissions.ts +6 -0
  521. package/modules/users/src/api/endpoints.ts +222 -0
  522. package/modules/users/src/client/InviteMemberForm.tsrx +62 -0
  523. package/modules/users/src/client/MemberDrawer.tsrx +298 -0
  524. package/modules/users/src/client/RoleForm.tsrx +140 -0
  525. package/modules/users/src/client/RolesView.tsrx +288 -0
  526. package/modules/users/src/client/UserAccountForm.tsrx +86 -0
  527. package/modules/users/src/client/UsersView.tsrx +486 -0
  528. package/modules/users/src/client/api.ts +172 -0
  529. package/modules/users/src/client/contribution.tsrx +92 -0
  530. package/modules/users/src/client/index.ts +19 -0
  531. package/modules/users/src/client/member-columns.tsrx +52 -0
  532. package/modules/users/src/client/roles-api.ts +90 -0
  533. package/modules/users/src/client/state.ts +42 -0
  534. package/modules/users/src/index.ts +27 -0
  535. package/modules/users/src/platform.ts +11 -0
  536. package/modules/users/src/services/index.ts +2 -0
  537. package/modules/users/src/services/users-service.ts +142 -0
  538. package/modules/users/translations/en.json +133 -0
  539. package/modules/users/translations/pl.json +133 -0
  540. package/modules/workflows/migrations/0001_workflows_core.down.sql +19 -0
  541. package/modules/workflows/migrations/0001_workflows_core.up.sql +228 -0
  542. package/modules/workflows/migrations/0002_workflows_authorization_subject.down.sql +1 -0
  543. package/modules/workflows/migrations/0002_workflows_authorization_subject.up.sql +9 -0
  544. package/modules/workflows/migrations/0003_workflows_worker_role.up.sql +34 -0
  545. package/modules/workflows/migrations/README.md +7 -0
  546. package/modules/workflows/module.json +31 -0
  547. package/modules/workflows/package.json +55 -0
  548. package/modules/workflows/spec/module.yaml +227 -0
  549. package/modules/workflows/src/acl/permissions.ts +10 -0
  550. package/modules/workflows/src/api/endpoints.ts +852 -0
  551. package/modules/workflows/src/client/WorkflowCanvas.tsrx +819 -0
  552. package/modules/workflows/src/client/WorkflowCreateForm.tsrx +111 -0
  553. package/modules/workflows/src/client/WorkflowEditor.tsrx +443 -0
  554. package/modules/workflows/src/client/WorkflowExecutionHistory.tsrx +169 -0
  555. package/modules/workflows/src/client/WorkflowFixtureDrawer.tsrx +206 -0
  556. package/modules/workflows/src/client/WorkflowInputForm.tsrx +125 -0
  557. package/modules/workflows/src/client/WorkflowInputSchemaEditor.tsrx +185 -0
  558. package/modules/workflows/src/client/WorkflowInspector.tsrx +471 -0
  559. package/modules/workflows/src/client/WorkflowLiveConfirmation.tsrx +67 -0
  560. package/modules/workflows/src/client/WorkflowMappingEditor.tsrx +283 -0
  561. package/modules/workflows/src/client/WorkflowNodePalette.tsrx +50 -0
  562. package/modules/workflows/src/client/WorkflowPointerField.tsrx +178 -0
  563. package/modules/workflows/src/client/WorkflowRevisionReview.tsrx +49 -0
  564. package/modules/workflows/src/client/WorkflowRunInspector.tsrx +143 -0
  565. package/modules/workflows/src/client/WorkflowTestPanel.tsrx +109 -0
  566. package/modules/workflows/src/client/WorkflowValidationPanel.tsrx +139 -0
  567. package/modules/workflows/src/client/WorkflowsView.tsrx +1060 -0
  568. package/modules/workflows/src/client/api.ts +312 -0
  569. package/modules/workflows/src/client/canvas-model.ts +472 -0
  570. package/modules/workflows/src/client/connected-node.ts +71 -0
  571. package/modules/workflows/src/client/contribution.tsrx +57 -0
  572. package/modules/workflows/src/client/create-model.ts +15 -0
  573. package/modules/workflows/src/client/draft-repair.ts +86 -0
  574. package/modules/workflows/src/client/index.ts +19 -0
  575. package/modules/workflows/src/client/input-model.ts +124 -0
  576. package/modules/workflows/src/client/mapping-model.ts +110 -0
  577. package/modules/workflows/src/client/pointer-model.ts +123 -0
  578. package/modules/workflows/src/client/presentation.ts +62 -0
  579. package/modules/workflows/src/client/run-actions.ts +19 -0
  580. package/modules/workflows/src/client/state.ts +57 -0
  581. package/modules/workflows/src/client/viewport.ts +107 -0
  582. package/modules/workflows/src/client/workflows.css +899 -0
  583. package/modules/workflows/src/domain/events.ts +399 -0
  584. package/modules/workflows/src/domain/graph.ts +1136 -0
  585. package/modules/workflows/src/domain/types.ts +563 -0
  586. package/modules/workflows/src/index.ts +27 -0
  587. package/modules/workflows/src/platform.ts +49 -0
  588. package/modules/workflows/src/server/index.ts +13 -0
  589. package/modules/workflows/src/server/runtime.ts +266 -0
  590. package/modules/workflows/src/services/cursor-codec.ts +62 -0
  591. package/modules/workflows/src/services/database-repository.ts +2407 -0
  592. package/modules/workflows/src/services/index.ts +6 -0
  593. package/modules/workflows/src/services/migration.ts +375 -0
  594. package/modules/workflows/src/services/payload-codec.ts +264 -0
  595. package/modules/workflows/src/services/repository.ts +285 -0
  596. package/modules/workflows/src/services/simulation.ts +359 -0
  597. package/modules/workflows/src/services/worker.ts +1196 -0
  598. package/modules/workflows/src/services/workflows-service.ts +1395 -0
  599. package/modules/workflows/translations/en.json +348 -0
  600. package/modules/workflows/translations/pl.json +348 -0
  601. package/modules.json +41 -0
  602. package/package.json +125 -0
  603. package/packages/ai-provider/package.json +46 -0
  604. package/packages/ai-provider/src/catalog.ts +102 -0
  605. package/packages/ai-provider/src/errors.ts +110 -0
  606. package/packages/ai-provider/src/index.ts +33 -0
  607. package/packages/ai-provider/src/model.ts +198 -0
  608. package/packages/ai-provider/src/pricing.ts +73 -0
  609. package/packages/cli-protocol/package.json +40 -0
  610. package/packages/cli-protocol/src/index.ts +113 -0
  611. package/packages/client/package.json +46 -0
  612. package/packages/client/src/ApplicationShell.tsrx +374 -0
  613. package/packages/client/src/contributions.ts +172 -0
  614. package/packages/client/src/i18n/index.ts +30 -0
  615. package/packages/client/src/i18n/locale.ts +25 -0
  616. package/packages/client/src/i18n/locales/en.json +66 -0
  617. package/packages/client/src/i18n/locales/pl.json +66 -0
  618. package/packages/client/src/i18n/runtime.ts +201 -0
  619. package/packages/client/src/i18n/translations.ts +88 -0
  620. package/packages/client/src/index.ts +55 -0
  621. package/packages/client/src/routing.ts +9 -0
  622. package/packages/client/src/shell/BrandMark.tsrx +10 -0
  623. package/packages/client/src/shell/CommandPalette.tsrx +79 -0
  624. package/packages/client/src/shell/ContributionOutlets.tsrx +31 -0
  625. package/packages/client/src/shell/DashboardView.tsrx +60 -0
  626. package/packages/client/src/shell/MobileHeader.tsrx +24 -0
  627. package/packages/client/src/shell/OrganizationSwitcher.tsrx +100 -0
  628. package/packages/client/src/shell/OverviewCharts.tsrx +167 -0
  629. package/packages/client/src/shell/PrimaryNavigation.tsrx +75 -0
  630. package/packages/client/src/shell/Sidebar.tsrx +76 -0
  631. package/packages/client/src/shell/Topbar.tsrx +44 -0
  632. package/packages/client/src/shell/UserMenu.tsrx +103 -0
  633. package/packages/client/src/shell/WorkspaceContent.tsrx +30 -0
  634. package/packages/client/src/shell/identity.ts +12 -0
  635. package/packages/client/src/shell/navigation.ts +68 -0
  636. package/packages/client/src/shell/shell.css +734 -0
  637. package/packages/client/src/shell/types.ts +29 -0
  638. package/packages/client/src/state.ts +63 -0
  639. package/packages/client/src/web.ts +39 -0
  640. package/packages/coding-agent/package.json +44 -0
  641. package/packages/coding-agent/src/drivers/byok.ts +322 -0
  642. package/packages/coding-agent/src/drivers/claude-code.ts +290 -0
  643. package/packages/coding-agent/src/drivers/codex.ts +281 -0
  644. package/packages/coding-agent/src/index.ts +56 -0
  645. package/packages/coding-agent/src/registry.ts +119 -0
  646. package/packages/coding-agent/src/roles/contract.ts +60 -0
  647. package/packages/coding-agent/src/roles/defaults.ts +134 -0
  648. package/packages/coding-agent/src/roles/handoff.ts +41 -0
  649. package/packages/coding-agent/src/roles/registry.ts +156 -0
  650. package/packages/coding-agent/src/roles/skills.ts +72 -0
  651. package/packages/coding-agent/src/roles/sync.ts +88 -0
  652. package/packages/coding-agent/src/types.ts +102 -0
  653. package/packages/coding-agent/src/workspace.ts +275 -0
  654. package/packages/contracts/package.json +38 -0
  655. package/packages/contracts/schemas/blueprint.schema.json +48 -0
  656. package/packages/contracts/schemas/cli-extension.schema.json +90 -0
  657. package/packages/contracts/schemas/module-artifact.schema.json +82 -0
  658. package/packages/contracts/schemas/module-catalog.schema.json +48 -0
  659. package/packages/contracts/schemas/module-spec.schema.json +111 -0
  660. package/packages/contracts/schemas/module.schema.json +156 -0
  661. package/packages/contracts/schemas/platform-spec.schema.json +17 -0
  662. package/packages/contracts/schemas/project.schema.json +270 -0
  663. package/packages/contracts/src/index.ts +191 -0
  664. package/packages/contracts/src/module-distribution.ts +47 -0
  665. package/packages/contracts/src/schemas.ts +18 -0
  666. package/packages/contracts/src/variables.ts +156 -0
  667. package/packages/contracts/src/web.ts +60 -0
  668. package/packages/database/package.json +43 -0
  669. package/packages/database/src/contracts.ts +399 -0
  670. package/packages/database/src/index.ts +112 -0
  671. package/packages/database/src/migrations.ts +444 -0
  672. package/packages/database/src/postgresql.ts +517 -0
  673. package/packages/database/src/provider.ts +639 -0
  674. package/packages/database/src/record-history.ts +201 -0
  675. package/packages/database/src/registry.ts +265 -0
  676. package/packages/database/src/reset.ts +87 -0
  677. package/packages/database-pglite/package.json +42 -0
  678. package/packages/database-pglite/src/driver.ts +168 -0
  679. package/packages/database-pglite/src/index.ts +2 -0
  680. package/packages/database-testing/package.json +44 -0
  681. package/packages/database-testing/src/index.ts +8 -0
  682. package/packages/database-testing/src/pglite.ts +124 -0
  683. package/packages/database-testing/src/postgres.ts +184 -0
  684. package/packages/database-testing/src/provider.ts +43 -0
  685. package/packages/database-testing/src/vitest-preset.ts +23 -0
  686. package/packages/dev-console/README.md +6 -0
  687. package/packages/dev-console/package.json +38 -0
  688. package/packages/dev-console/src/index.mjs +220 -0
  689. package/packages/harness/package.json +47 -0
  690. package/packages/harness/schemas/task-packet.schema.json +48 -0
  691. package/packages/harness/src/catalog.ts +24 -0
  692. package/packages/harness/src/errors.ts +9 -0
  693. package/packages/harness/src/index.ts +53 -0
  694. package/packages/harness/src/preamble.ts +31 -0
  695. package/packages/harness/src/runtime.ts +833 -0
  696. package/packages/harness/src/task-packet.ts +86 -0
  697. package/packages/harness/src/tool-adapters.ts +106 -0
  698. package/packages/harness/src/tool-contract.ts +242 -0
  699. package/packages/harness/src/vercel-ai-provider.ts +198 -0
  700. package/packages/kernel/package.json +44 -0
  701. package/packages/kernel/src/acl.ts +20 -0
  702. package/packages/kernel/src/actor.ts +139 -0
  703. package/packages/kernel/src/agent-registry.ts +81 -0
  704. package/packages/kernel/src/capability-registry.ts +28 -0
  705. package/packages/kernel/src/errors.ts +9 -0
  706. package/packages/kernel/src/index.ts +90 -0
  707. package/packages/kernel/src/legacy-local-state.ts +103 -0
  708. package/packages/kernel/src/module-compatibility.ts +70 -0
  709. package/packages/kernel/src/module-registry.ts +124 -0
  710. package/packages/kernel/src/module-settings.ts +403 -0
  711. package/packages/kernel/src/record-history.ts +146 -0
  712. package/packages/kernel/src/runtime-config.ts +51 -0
  713. package/packages/kernel/src/tool-registry.ts +25 -0
  714. package/packages/kernel/src/variable-registry.ts +339 -0
  715. package/packages/sandbox/README.md +691 -0
  716. package/packages/sandbox/bin/flowdular-sandbox.mjs +393 -0
  717. package/packages/sandbox/dist/client/assets/App-ClMOrpyg.js +11 -0
  718. package/packages/sandbox/dist/client/assets/PreviewHost-BHiHrfbQ.js +1 -0
  719. package/packages/sandbox/dist/client/assets/auto-buGEq6de.js +3 -0
  720. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
  721. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
  722. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
  723. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
  724. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
  725. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
  726. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
  727. package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
  728. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
  729. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
  730. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
  731. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
  732. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
  733. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
  734. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
  735. package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
  736. package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
  737. package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
  738. package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
  739. package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
  740. package/packages/sandbox/dist/client/assets/ibm-plex-sans-cyrillic-ext-wght-normal-d45eAU9y.woff2 +0 -0
  741. package/packages/sandbox/dist/client/assets/ibm-plex-sans-cyrillic-wght-normal-BAAhND-U.woff2 +0 -0
  742. package/packages/sandbox/dist/client/assets/ibm-plex-sans-greek-wght-normal-CmyJS8uq.woff2 +0 -0
  743. package/packages/sandbox/dist/client/assets/ibm-plex-sans-latin-ext-wght-normal-CIII54If.woff2 +0 -0
  744. package/packages/sandbox/dist/client/assets/ibm-plex-sans-latin-wght-normal-IvpUvPa2.woff2 +0 -0
  745. package/packages/sandbox/dist/client/assets/ibm-plex-sans-vietnamese-wght-normal-Dg1JeJN0.woff2 +0 -0
  746. package/packages/sandbox/dist/client/assets/index-CvwhlQ87.js +4 -0
  747. package/packages/sandbox/dist/client/assets/styles-BPWaGf55.js +3 -0
  748. package/packages/sandbox/dist/client/assets/styles-Dx1_KOag.css +1 -0
  749. package/packages/sandbox/dist/client/favicon.svg +1 -0
  750. package/packages/sandbox/dist/server/assets/auto-CVGNYyb3.js +12785 -0
  751. package/packages/sandbox/dist/server/assets/chunk-DDJLRBDX-3OUNo51g.js +4125 -0
  752. package/packages/sandbox/dist/server/assets/nodefs-DVSI7kG0.js +24 -0
  753. package/packages/sandbox/dist/server/assets/opfs-ahp-D56iokt1.js +388 -0
  754. package/packages/sandbox/dist/server/assets/token-Bvaq7Anz.js +55 -0
  755. package/packages/sandbox/dist/server/assets/token-util-BqSvdIPQ.js +3 -0
  756. package/packages/sandbox/dist/server/assets/token-util-CktFFT4z.js +494 -0
  757. package/packages/sandbox/dist/server/entry.js +91671 -0
  758. package/packages/sandbox/dist/server/favicon.svg +1 -0
  759. package/packages/sandbox/dist/server/index.html +161 -0
  760. package/packages/sandbox/index.html +159 -0
  761. package/packages/sandbox/octane.config.ts +36 -0
  762. package/packages/sandbox/package.json +83 -0
  763. package/packages/sandbox/public/favicon.svg +1 -0
  764. package/packages/sandbox/public/og.png +0 -0
  765. package/packages/sandbox/src/App.tsrx +924 -0
  766. package/packages/sandbox/src/client/ApprovalHandoff.tsrx +39 -0
  767. package/packages/sandbox/src/client/ChatPane.tsrx +694 -0
  768. package/packages/sandbox/src/client/ConnectView.tsrx +86 -0
  769. package/packages/sandbox/src/client/DiffPane.tsrx +150 -0
  770. package/packages/sandbox/src/client/EjectModal.tsrx +571 -0
  771. package/packages/sandbox/src/client/GateResults.tsrx +60 -0
  772. package/packages/sandbox/src/client/GitHubSettingsModal.tsrx +219 -0
  773. package/packages/sandbox/src/client/NewSessionForm.tsrx +214 -0
  774. package/packages/sandbox/src/client/SessionBar.tsrx +151 -0
  775. package/packages/sandbox/src/client/SessionPicker.tsrx +472 -0
  776. package/packages/sandbox/src/client/SpecEditor.tsrx +109 -0
  777. package/packages/sandbox/src/client/SpecReviewCard.tsrx +321 -0
  778. package/packages/sandbox/src/client/WorkCard.tsrx +128 -0
  779. package/packages/sandbox/src/client/WorkbenchModal.tsrx +161 -0
  780. package/packages/sandbox/src/client/WorkspaceMenu.tsrx +100 -0
  781. package/packages/sandbox/src/client/api.ts +797 -0
  782. package/packages/sandbox/src/client/attachments.ts +73 -0
  783. package/packages/sandbox/src/client/dashboard.ts +46 -0
  784. package/packages/sandbox/src/client/github-settings.ts +48 -0
  785. package/packages/sandbox/src/client/highlight.ts +105 -0
  786. package/packages/sandbox/src/client/i18n.ts +32 -0
  787. package/packages/sandbox/src/client/locales/en.json +466 -0
  788. package/packages/sandbox/src/client/locales/pl.json +466 -0
  789. package/packages/sandbox/src/client/session-labels.ts +77 -0
  790. package/packages/sandbox/src/client/state.ts +108 -0
  791. package/packages/sandbox/src/index.ts +10 -0
  792. package/packages/sandbox/src/preview/PreviewHost.tsrx +373 -0
  793. package/packages/sandbox/src/preview/load-module.ts +16 -0
  794. package/packages/sandbox/src/server/attachments.ts +308 -0
  795. package/packages/sandbox/src/server/auto-review.ts +181 -0
  796. package/packages/sandbox/src/server/checkpoints.ts +90 -0
  797. package/packages/sandbox/src/server/config.ts +460 -0
  798. package/packages/sandbox/src/server/dashboard.ts +245 -0
  799. package/packages/sandbox/src/server/delivery/configuration.ts +193 -0
  800. package/packages/sandbox/src/server/delivery/git-pr.ts +1473 -0
  801. package/packages/sandbox/src/server/delivery/index.ts +83 -0
  802. package/packages/sandbox/src/server/delivery/local.ts +151 -0
  803. package/packages/sandbox/src/server/delivery/official-modules.ts +516 -0
  804. package/packages/sandbox/src/server/delivery/plan.ts +218 -0
  805. package/packages/sandbox/src/server/delivery/policies.ts +239 -0
  806. package/packages/sandbox/src/server/delivery/record.ts +41 -0
  807. package/packages/sandbox/src/server/delivery/steps.ts +464 -0
  808. package/packages/sandbox/src/server/delivery/types.ts +158 -0
  809. package/packages/sandbox/src/server/dependencies.ts +88 -0
  810. package/packages/sandbox/src/server/diff.ts +230 -0
  811. package/packages/sandbox/src/server/gates.ts +388 -0
  812. package/packages/sandbox/src/server/index.ts +139 -0
  813. package/packages/sandbox/src/server/path-guard.ts +282 -0
  814. package/packages/sandbox/src/server/planning.ts +749 -0
  815. package/packages/sandbox/src/server/platform-client.ts +189 -0
  816. package/packages/sandbox/src/server/preview-database-host.ts +340 -0
  817. package/packages/sandbox/src/server/preview-database-protocol.ts +163 -0
  818. package/packages/sandbox/src/server/preview-database-proxy.ts +356 -0
  819. package/packages/sandbox/src/server/preview-database.ts +109 -0
  820. package/packages/sandbox/src/server/preview-ipc.ts +15 -0
  821. package/packages/sandbox/src/server/preview-modules.ts +83 -0
  822. package/packages/sandbox/src/server/preview-revision.ts +44 -0
  823. package/packages/sandbox/src/server/preview-runtime.ts +467 -0
  824. package/packages/sandbox/src/server/preview-worker-manager.ts +436 -0
  825. package/packages/sandbox/src/server/preview-worker.ts +168 -0
  826. package/packages/sandbox/src/server/reference.ts +251 -0
  827. package/packages/sandbox/src/server/routes.ts +2258 -0
  828. package/packages/sandbox/src/server/runtime.ts +188 -0
  829. package/packages/sandbox/src/server/session-owner.ts +23 -0
  830. package/packages/sandbox/src/server/sessions.ts +849 -0
  831. package/packages/sandbox/src/server/spec.ts +471 -0
  832. package/packages/sandbox/src/server/turn-lifecycle.ts +56 -0
  833. package/packages/sandbox/src/server/turns.ts +993 -0
  834. package/packages/sandbox/src/server/workspace-install.ts +266 -0
  835. package/packages/sandbox/src/server/workspace-root.ts +73 -0
  836. package/packages/sandbox/src/styles.css +1573 -0
  837. package/packages/sandbox/vite.config.ts +133 -0
  838. package/packages/server/package.json +43 -0
  839. package/packages/server/src/application-routes.ts +21 -0
  840. package/packages/server/src/composition.ts +48 -0
  841. package/packages/server/src/endpoint.ts +142 -0
  842. package/packages/server/src/http.ts +128 -0
  843. package/packages/server/src/index.ts +46 -0
  844. package/packages/server/src/response-lifetime.ts +56 -0
  845. package/packages/server/src/security-headers.ts +130 -0
  846. package/packages/server/src/web-html.ts +55 -0
  847. package/packages/server/src/web.ts +361 -0
  848. package/packages/ui/package.json +46 -0
  849. package/packages/ui/src/brand/BrandMark.tsrx +66 -0
  850. package/packages/ui/src/brand/mark.ts +44 -0
  851. package/packages/ui/src/components/Alert.tsrx +17 -0
  852. package/packages/ui/src/components/Avatar.tsrx +18 -0
  853. package/packages/ui/src/components/Button.tsrx +29 -0
  854. package/packages/ui/src/components/Chart.tsrx +274 -0
  855. package/packages/ui/src/components/CheckGrid.tsrx +93 -0
  856. package/packages/ui/src/components/ConfirmDialog.tsrx +63 -0
  857. package/packages/ui/src/components/Drawer.tsrx +71 -0
  858. package/packages/ui/src/components/EmptyState.tsrx +26 -0
  859. package/packages/ui/src/components/Filters.tsrx +39 -0
  860. package/packages/ui/src/components/FormField.tsrx +27 -0
  861. package/packages/ui/src/components/Kpi.tsrx +36 -0
  862. package/packages/ui/src/components/PageHeader.tsrx +26 -0
  863. package/packages/ui/src/components/ScopeSummary.tsrx +76 -0
  864. package/packages/ui/src/components/SearchField.tsrx +24 -0
  865. package/packages/ui/src/components/SettingRow.tsrx +50 -0
  866. package/packages/ui/src/components/Switch.tsrx +21 -0
  867. package/packages/ui/src/components/Table.tsrx +267 -0
  868. package/packages/ui/src/components/TableCard.tsrx +52 -0
  869. package/packages/ui/src/components/Tag.tsrx +28 -0
  870. package/packages/ui/src/components/VariableField.tsrx +284 -0
  871. package/packages/ui/src/components/VariableInput.tsrx +7 -0
  872. package/packages/ui/src/components/VariableSelect.tsrx +72 -0
  873. package/packages/ui/src/components/VariableTextarea.tsrx +9 -0
  874. package/packages/ui/src/components/variable-field.ts +61 -0
  875. package/packages/ui/src/components/variable-select.ts +69 -0
  876. package/packages/ui/src/icons/Icon.tsrx +56 -0
  877. package/packages/ui/src/index.ts +81 -0
  878. package/packages/ui/src/initials.ts +10 -0
  879. package/packages/ui/src/styles/base.css +71 -0
  880. package/packages/ui/src/styles/components.css +1859 -0
  881. package/packages/ui/src/styles/index.css +3 -0
  882. package/packages/ui/src/styles/tokens.css +124 -0
  883. package/tsconfig.base.json +18 -0
@@ -0,0 +1,1136 @@
1
+ import { createHash } from 'node:crypto';
2
+ import type {
3
+ JsonSchemaV1,
4
+ JsonValue,
5
+ WorkflowDryRunResponseV1,
6
+ WorkflowGateExpressionV1,
7
+ WorkflowGraphV1,
8
+ WorkflowNodeV1,
9
+ WorkflowPayloadEvidenceV1,
10
+ WorkflowReferenceSummaryV1,
11
+ WorkflowTargetMappingV1,
12
+ WorkflowValidationIssueV1,
13
+ } from './types.ts';
14
+ import { WORKFLOW_LIMITS } from './types.ts';
15
+
16
+ const IDENTIFIER = /^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)+$/;
17
+ const PORT = /^[a-z][a-z0-9-]*$/;
18
+ const FORBIDDEN_CONFIGURATION_KEYS = new Set([
19
+ 'eval',
20
+ 'javascript',
21
+ 'script',
22
+ 'sourceCode',
23
+ 'shell',
24
+ 'dynamicImport',
25
+ ]);
26
+
27
+ export interface WorkflowReferenceCatalog {
28
+ agent(
29
+ agentId: string,
30
+ revision: number,
31
+ ):
32
+ | boolean
33
+ | {
34
+ readonly available: boolean;
35
+ readonly allowedTools: readonly string[];
36
+ };
37
+ action(
38
+ actionId: string,
39
+ contractVersion: number,
40
+ ): {
41
+ readonly available: boolean;
42
+ readonly requiredPermissions: readonly string[];
43
+ readonly risk?: 'read' | 'workspace-write' | 'external' | 'destructive';
44
+ readonly idempotency?: 'required' | 'none';
45
+ };
46
+ }
47
+
48
+ export const EMPTY_WORKFLOW_GRAPH: WorkflowGraphV1 = Object.freeze({
49
+ schemaVersion: 1,
50
+ nodes: Object.freeze([]),
51
+ edges: Object.freeze([]),
52
+ schemas: Object.freeze({}),
53
+ layout: Object.freeze({}),
54
+ });
55
+
56
+ function canonical(value: unknown): string {
57
+ if (value === null || typeof value !== 'object') return JSON.stringify(value);
58
+ if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`;
59
+ return `{${Object.entries(value as Record<string, unknown>)
60
+ .sort(([left], [right]) => left.localeCompare(right))
61
+ .filter(([, entry]) => entry !== undefined)
62
+ .map(([key, entry]) => `${JSON.stringify(key)}:${canonical(entry)}`)
63
+ .join(',')}}`;
64
+ }
65
+
66
+ export function workflowGraphChecksum(graph: WorkflowGraphV1): string {
67
+ const semantic = {
68
+ schemaVersion: graph.schemaVersion,
69
+ nodes: graph.nodes,
70
+ edges: graph.edges,
71
+ schemas: graph.schemas,
72
+ };
73
+ return `sha256:${createHash('sha256').update(canonical(semantic)).digest('hex')}`;
74
+ }
75
+
76
+ export function jsonHash(value: JsonValue): string {
77
+ return `sha256:${createHash('sha256').update(canonical(value)).digest('hex')}`;
78
+ }
79
+
80
+ export function jsonByteSize(value: JsonValue): number {
81
+ return Buffer.byteLength(canonical(value));
82
+ }
83
+
84
+ function issue(
85
+ code: string,
86
+ message: string,
87
+ location: WorkflowValidationIssueV1['location'] = { kind: 'graph' },
88
+ ): WorkflowValidationIssueV1 {
89
+ return { code, severity: 'error', message, location };
90
+ }
91
+
92
+ function isRecord(value: unknown): value is Record<string, unknown> {
93
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
94
+ }
95
+
96
+ function isJson(value: unknown, depth = 0): value is JsonValue {
97
+ if (depth > 24) return false;
98
+ if (
99
+ value === null ||
100
+ typeof value === 'string' ||
101
+ typeof value === 'boolean'
102
+ ) {
103
+ return true;
104
+ }
105
+ if (typeof value === 'number') return Number.isFinite(value);
106
+ if (Array.isArray(value))
107
+ return value.every((entry) => isJson(entry, depth + 1));
108
+ if (!isRecord(value)) return false;
109
+ return Object.values(value).every((entry) => isJson(entry, depth + 1));
110
+ }
111
+
112
+ export function parseWorkflowGraph(value: unknown): WorkflowGraphV1 {
113
+ if (!isRecord(value) || value.schemaVersion !== 1 || !isJson(value)) {
114
+ throw new Error('WORKFLOW_GRAPH_INVALID');
115
+ }
116
+ if (
117
+ !Array.isArray(value.nodes) ||
118
+ !Array.isArray(value.edges) ||
119
+ !isRecord(value.schemas) ||
120
+ !isRecord(value.layout)
121
+ ) {
122
+ throw new Error('WORKFLOW_GRAPH_INVALID');
123
+ }
124
+ return structuredClone(value) as unknown as WorkflowGraphV1;
125
+ }
126
+
127
+ const EXPECTED_PORTS: Record<
128
+ WorkflowNodeV1['type'],
129
+ { readonly inputs: readonly string[]; readonly outputs: readonly string[] }
130
+ > = {
131
+ input: { inputs: [], outputs: ['data'] },
132
+ agent: { inputs: ['input'], outputs: ['success', 'failure'] },
133
+ 'agent-decision': {
134
+ inputs: ['input'],
135
+ outputs: ['pass', 'fail', 'failure'],
136
+ },
137
+ gate: { inputs: ['input'], outputs: ['pass', 'fail'] },
138
+ validator: { inputs: ['input'], outputs: ['pass', 'fail'] },
139
+ action: { inputs: ['input'], outputs: ['success', 'failure'] },
140
+ merge: { inputs: ['items'], outputs: ['data'] },
141
+ output: { inputs: ['input'], outputs: [] },
142
+ };
143
+
144
+ function configurationIssues(
145
+ node: WorkflowNodeV1,
146
+ ): readonly WorkflowValidationIssueV1[] {
147
+ const issues: WorkflowValidationIssueV1[] = [];
148
+ const inspect = (value: unknown, path: string, depth: number): void => {
149
+ if (depth > 24) {
150
+ issues.push(
151
+ issue(
152
+ 'WORKFLOW_LIMIT_EXCEEDED',
153
+ 'Node configuration exceeds the depth limit.',
154
+ {
155
+ kind: 'node',
156
+ nodeId: node.id,
157
+ path,
158
+ },
159
+ ),
160
+ );
161
+ return;
162
+ }
163
+ if (Array.isArray(value)) {
164
+ value.forEach((entry, index) =>
165
+ inspect(entry, `${path}/${index}`, depth + 1),
166
+ );
167
+ return;
168
+ }
169
+ if (!isRecord(value)) return;
170
+ for (const [key, entry] of Object.entries(value)) {
171
+ if (FORBIDDEN_CONFIGURATION_KEYS.has(key)) {
172
+ issues.push(
173
+ issue(
174
+ 'WORKFLOW_EXECUTABLE_CONFIGURATION_FORBIDDEN',
175
+ `Executable configuration field "${key}" is forbidden.`,
176
+ { kind: 'node', nodeId: node.id, path: `${path}/${key}` },
177
+ ),
178
+ );
179
+ }
180
+ inspect(entry, `${path}/${key}`, depth + 1);
181
+ }
182
+ };
183
+ inspect(node, '', 0);
184
+ return issues;
185
+ }
186
+
187
+ function schemaIssues(
188
+ id: string,
189
+ schema: JsonSchemaV1,
190
+ ): readonly WorkflowValidationIssueV1[] {
191
+ const issues: WorkflowValidationIssueV1[] = [];
192
+ if (!IDENTIFIER.test(id)) {
193
+ issues.push(
194
+ issue('WORKFLOW_SCHEMA_ID_INVALID', `Schema "${id}" has an invalid id.`),
195
+ );
196
+ }
197
+ if (jsonByteSize(schema) > 16 * 1024) {
198
+ issues.push(
199
+ issue('WORKFLOW_LIMIT_EXCEEDED', `Schema "${id}" exceeds 16 KB.`),
200
+ );
201
+ }
202
+ const allowed = new Set([
203
+ '$id',
204
+ 'title',
205
+ 'description',
206
+ 'type',
207
+ 'properties',
208
+ 'required',
209
+ 'additionalProperties',
210
+ 'items',
211
+ 'enum',
212
+ 'const',
213
+ 'minLength',
214
+ 'maxLength',
215
+ 'minimum',
216
+ 'maximum',
217
+ ]);
218
+ const walk = (value: JsonValue, depth: number): void => {
219
+ if (depth > 12) {
220
+ issues.push(
221
+ issue('WORKFLOW_LIMIT_EXCEEDED', `Schema "${id}" is too deep.`),
222
+ );
223
+ return;
224
+ }
225
+ if (value === null || typeof value !== 'object') return;
226
+ if (Array.isArray(value)) {
227
+ value.forEach((entry) => walk(entry, depth + 1));
228
+ return;
229
+ }
230
+ for (const [key, entry] of Object.entries(value)) {
231
+ if (depth === 0 && !allowed.has(key)) {
232
+ issues.push(
233
+ issue(
234
+ 'WORKFLOW_SCHEMA_KEY_UNSUPPORTED',
235
+ `Schema "${id}" uses unsupported keyword "${key}".`,
236
+ ),
237
+ );
238
+ }
239
+ walk(entry, depth + 1);
240
+ }
241
+ };
242
+ walk(schema, 0);
243
+ return issues;
244
+ }
245
+
246
+ function validateGateExpression(
247
+ expression: WorkflowGateExpressionV1,
248
+ nodeId: string,
249
+ depth = 0,
250
+ ): readonly WorkflowValidationIssueV1[] {
251
+ if (
252
+ depth > 16 ||
253
+ !isRecord(expression) ||
254
+ typeof expression.op !== 'string'
255
+ ) {
256
+ return [
257
+ issue(
258
+ 'WORKFLOW_GATE_INVALID',
259
+ 'Gate expression is invalid or too deep.',
260
+ {
261
+ kind: 'node',
262
+ nodeId,
263
+ path: '/expression',
264
+ },
265
+ ),
266
+ ];
267
+ }
268
+ if (expression.op === 'literal') {
269
+ return isJson(expression.value)
270
+ ? []
271
+ : [
272
+ issue('WORKFLOW_GATE_INVALID', 'Gate literal is not JSON.', {
273
+ kind: 'node',
274
+ nodeId,
275
+ }),
276
+ ];
277
+ }
278
+ if (expression.op === 'path') {
279
+ return typeof expression.pointer === 'string' &&
280
+ validPointer(expression.pointer)
281
+ ? []
282
+ : [
283
+ issue(
284
+ 'WORKFLOW_GATE_INVALID',
285
+ 'Gate path is not an RFC 6901 pointer.',
286
+ { kind: 'node', nodeId },
287
+ ),
288
+ ];
289
+ }
290
+ if (expression.op === 'not' || expression.op === 'exists') {
291
+ return validateGateExpression(expression.value, nodeId, depth + 1);
292
+ }
293
+ if (expression.op === 'and' || expression.op === 'or') {
294
+ return Array.isArray(expression.values) && expression.values.length > 0
295
+ ? expression.values.flatMap((entry) =>
296
+ validateGateExpression(entry, nodeId, depth + 1),
297
+ )
298
+ : [
299
+ issue(
300
+ 'WORKFLOW_GATE_INVALID',
301
+ 'Logical gates require at least one operand.',
302
+ { kind: 'node', nodeId },
303
+ ),
304
+ ];
305
+ }
306
+ if (
307
+ expression.op === 'eq' ||
308
+ expression.op === 'gt' ||
309
+ expression.op === 'gte' ||
310
+ expression.op === 'lt' ||
311
+ expression.op === 'lte' ||
312
+ expression.op === 'in'
313
+ ) {
314
+ return [
315
+ ...validateGateExpression(expression.left, nodeId, depth + 1),
316
+ ...validateGateExpression(expression.right, nodeId, depth + 1),
317
+ ];
318
+ }
319
+ return [
320
+ issue('WORKFLOW_GATE_INVALID', 'Gate operator is not supported.', {
321
+ kind: 'node',
322
+ nodeId,
323
+ }),
324
+ ];
325
+ }
326
+
327
+ function validPointer(pointer: string): boolean {
328
+ return (
329
+ typeof pointer === 'string' &&
330
+ (pointer === '' ||
331
+ (pointer.startsWith('/') && !/~(?:[^01]|$)/.test(pointer)))
332
+ );
333
+ }
334
+
335
+ function mappingIssues(
336
+ mapping: WorkflowTargetMappingV1,
337
+ node: WorkflowNodeV1,
338
+ nodeIndex: ReadonlyMap<string, number>,
339
+ graph: WorkflowGraphV1,
340
+ ): readonly WorkflowValidationIssueV1[] {
341
+ const issues: WorkflowValidationIssueV1[] = [];
342
+ if (!validPointer(mapping.targetPointer)) {
343
+ issues.push(
344
+ issue('WORKFLOW_MAPPING_POINTER_INVALID', 'Target pointer is invalid.', {
345
+ kind: 'node',
346
+ nodeId: node.id,
347
+ }),
348
+ );
349
+ }
350
+ const binding = mapping.binding;
351
+ if (binding.kind === 'literal') return issues;
352
+ const sources = binding.kind === 'path' ? [binding] : binding.variables;
353
+ if (
354
+ binding.kind === 'template' &&
355
+ Buffer.byteLength(binding.template) > 8 * 1024
356
+ ) {
357
+ issues.push(
358
+ issue('WORKFLOW_LIMIT_EXCEEDED', 'Template exceeds 8 KB.', {
359
+ kind: 'node',
360
+ nodeId: node.id,
361
+ }),
362
+ );
363
+ }
364
+ for (const source of sources) {
365
+ if (!validPointer(source.pointer)) {
366
+ issues.push(
367
+ issue(
368
+ 'WORKFLOW_MAPPING_POINTER_INVALID',
369
+ 'Source pointer is invalid.',
370
+ { kind: 'node', nodeId: node.id },
371
+ ),
372
+ );
373
+ }
374
+ const sourceIndex = nodeIndex.get(source.sourceNodeId);
375
+ const targetIndex = nodeIndex.get(node.id);
376
+ if (
377
+ sourceIndex === undefined ||
378
+ targetIndex === undefined ||
379
+ sourceIndex >= targetIndex ||
380
+ !graph.nodes
381
+ .find((entry) => entry.id === source.sourceNodeId)
382
+ ?.outputPorts.some((port) => port.name === source.sourcePort) ||
383
+ !isUpstream(graph, source.sourceNodeId, node.id)
384
+ ) {
385
+ issues.push(
386
+ issue(
387
+ 'WORKFLOW_MAPPING_SOURCE_INVALID',
388
+ `Mapping source "${source.sourceNodeId}" is not upstream.`,
389
+ { kind: 'node', nodeId: node.id },
390
+ ),
391
+ );
392
+ }
393
+ }
394
+ return issues;
395
+ }
396
+
397
+ function isUpstream(
398
+ graph: WorkflowGraphV1,
399
+ source: string,
400
+ target: string,
401
+ ): boolean {
402
+ const pending = [target];
403
+ const visited = new Set<string>();
404
+ while (pending.length) {
405
+ const id = pending.pop()!;
406
+ if (visited.has(id)) continue;
407
+ visited.add(id);
408
+ for (const edge of graph.edges) {
409
+ if (edge.target.nodeId !== id) continue;
410
+ if (edge.source.nodeId === source) return true;
411
+ pending.push(edge.source.nodeId);
412
+ }
413
+ }
414
+ return false;
415
+ }
416
+
417
+ function stableTopologicalOrder(
418
+ nodes: readonly WorkflowNodeV1[],
419
+ edges: WorkflowGraphV1['edges'],
420
+ ): { readonly order: readonly string[]; readonly cyclic: boolean } {
421
+ const incoming = new Map(nodes.map((node) => [node.id, 0]));
422
+ const outgoing = new Map(nodes.map((node) => [node.id, [] as string[]]));
423
+ for (const edge of edges) {
424
+ if (!incoming.has(edge.target.nodeId) || !outgoing.has(edge.source.nodeId))
425
+ continue;
426
+ incoming.set(
427
+ edge.target.nodeId,
428
+ (incoming.get(edge.target.nodeId) ?? 0) + 1,
429
+ );
430
+ outgoing.get(edge.source.nodeId)!.push(edge.target.nodeId);
431
+ }
432
+ const ready = [...incoming.entries()]
433
+ .filter(([, count]) => count === 0)
434
+ .map(([id]) => id)
435
+ .sort();
436
+ const order: string[] = [];
437
+ while (ready.length > 0) {
438
+ const id = ready.shift()!;
439
+ order.push(id);
440
+ for (const target of [...(outgoing.get(id) ?? [])].sort()) {
441
+ const count = (incoming.get(target) ?? 1) - 1;
442
+ incoming.set(target, count);
443
+ if (count === 0) {
444
+ ready.push(target);
445
+ ready.sort();
446
+ }
447
+ }
448
+ }
449
+ return { order, cyclic: order.length !== nodes.length };
450
+ }
451
+
452
+ export function compileWorkflowGraph(
453
+ graph: WorkflowGraphV1,
454
+ catalog?: WorkflowReferenceCatalog,
455
+ ): WorkflowDryRunResponseV1 {
456
+ const issues: WorkflowValidationIssueV1[] = [];
457
+ let checksum = 'sha256:invalid';
458
+ try {
459
+ checksum = workflowGraphChecksum(graph);
460
+ } catch {
461
+ issues.push(
462
+ issue('WORKFLOW_GRAPH_INVALID', 'Graph must contain JSON data only.'),
463
+ );
464
+ }
465
+ if (graph.schemaVersion !== 1)
466
+ issues.push(
467
+ issue(
468
+ 'WORKFLOW_GRAPH_VERSION_UNSUPPORTED',
469
+ 'Only graph schema version 1 is supported.',
470
+ ),
471
+ );
472
+ if (
473
+ jsonByteSize(graph as unknown as JsonValue) > WORKFLOW_LIMITS.maxGraphBytes
474
+ )
475
+ issues.push(issue('WORKFLOW_LIMIT_EXCEEDED', 'Graph exceeds 64 KB.'));
476
+ if (graph.nodes.length > WORKFLOW_LIMITS.maxNodes)
477
+ issues.push(issue('WORKFLOW_LIMIT_EXCEEDED', 'Graph exceeds 100 nodes.'));
478
+ if (graph.edges.length > WORKFLOW_LIMITS.maxEdges)
479
+ issues.push(issue('WORKFLOW_LIMIT_EXCEEDED', 'Graph exceeds 200 edges.'));
480
+ if (Object.keys(graph.schemas).length > WORKFLOW_LIMITS.maxSchemas)
481
+ issues.push(issue('WORKFLOW_LIMIT_EXCEEDED', 'Graph exceeds 32 schemas.'));
482
+
483
+ const nodeById = new Map<string, WorkflowNodeV1>();
484
+ const references: WorkflowReferenceSummaryV1[] = [];
485
+ const requiredPermissions = new Set<string>();
486
+ for (const [schemaId, schema] of Object.entries(graph.schemas)) {
487
+ issues.push(...schemaIssues(schemaId, schema));
488
+ references.push({
489
+ kind: 'schema',
490
+ id: schemaId,
491
+ version: '1',
492
+ available: true,
493
+ });
494
+ }
495
+ for (const node of graph.nodes) {
496
+ if (!IDENTIFIER.test(node.id))
497
+ issues.push(
498
+ issue(
499
+ 'WORKFLOW_NODE_ID_INVALID',
500
+ `Node "${node.id}" has an invalid id.`,
501
+ { kind: 'node', nodeId: node.id },
502
+ ),
503
+ );
504
+ if (nodeById.has(node.id))
505
+ issues.push(
506
+ issue('WORKFLOW_NODE_DUPLICATE', `Node "${node.id}" is duplicated.`, {
507
+ kind: 'node',
508
+ nodeId: node.id,
509
+ }),
510
+ );
511
+ nodeById.set(node.id, node);
512
+ issues.push(...configurationIssues(node));
513
+ const expected = EXPECTED_PORTS[node.type];
514
+ if (!expected) {
515
+ issues.push(
516
+ issue(
517
+ 'WORKFLOW_NODE_TYPE_INVALID',
518
+ `Node "${node.id}" has an unsupported type.`,
519
+ { kind: 'node', nodeId: node.id },
520
+ ),
521
+ );
522
+ continue;
523
+ }
524
+ for (const [kind, ports] of [
525
+ ['input', node.inputPorts],
526
+ ['output', node.outputPorts],
527
+ ] as const) {
528
+ const names = ports.map((port) => port.name);
529
+ if (
530
+ new Set(names).size !== names.length ||
531
+ names.some((name) => !PORT.test(name))
532
+ )
533
+ issues.push(
534
+ issue(
535
+ 'WORKFLOW_PORT_INVALID',
536
+ `${kind} ports on "${node.id}" are invalid.`,
537
+ { kind: 'node', nodeId: node.id },
538
+ ),
539
+ );
540
+ for (const port of ports)
541
+ if (!graph.schemas[port.schemaId])
542
+ issues.push(
543
+ issue(
544
+ 'WORKFLOW_SCHEMA_MISSING',
545
+ `Port "${port.name}" refers to missing schema "${port.schemaId}".`,
546
+ { kind: 'node', nodeId: node.id },
547
+ ),
548
+ );
549
+ }
550
+ if (
551
+ [...expected.inputs].sort().join('|') !==
552
+ node.inputPorts
553
+ .map((port) => port.name)
554
+ .sort()
555
+ .join('|') ||
556
+ [...expected.outputs].sort().join('|') !==
557
+ node.outputPorts
558
+ .map((port) => port.name)
559
+ .sort()
560
+ .join('|')
561
+ )
562
+ issues.push(
563
+ issue(
564
+ 'WORKFLOW_PORT_CONTRACT_INVALID',
565
+ `Node "${node.id}" does not declare the fixed ${node.type} ports.`,
566
+ { kind: 'node', nodeId: node.id },
567
+ ),
568
+ );
569
+ const policy = node.failurePolicy;
570
+ if (
571
+ policy &&
572
+ (policy.maxAttempts < 1 ||
573
+ policy.maxAttempts > WORKFLOW_LIMITS.maxAttemptsPerNode ||
574
+ policy.backoff.initialMs < 0 ||
575
+ policy.backoff.maximumMs < policy.backoff.initialMs ||
576
+ policy.backoff.maximumMs > 3_600_000)
577
+ )
578
+ issues.push(
579
+ issue(
580
+ 'WORKFLOW_RETRY_POLICY_INVALID',
581
+ `Node "${node.id}" has an invalid retry policy.`,
582
+ { kind: 'node', nodeId: node.id },
583
+ ),
584
+ );
585
+ if (node.type === 'agent' || node.type === 'agent-decision') {
586
+ const reference =
587
+ catalog?.agent(node.agent.agentId, node.agent.revision) ?? false;
588
+ const available =
589
+ typeof reference === 'boolean' ? reference : reference.available;
590
+ if (
591
+ !Array.isArray(node.toolGrants) ||
592
+ node.toolGrants.length > 32 ||
593
+ new Set(node.toolGrants).size !== node.toolGrants.length ||
594
+ node.toolGrants.some(
595
+ (tool) => typeof tool !== 'string' || !IDENTIFIER.test(tool),
596
+ )
597
+ ) {
598
+ issues.push(
599
+ issue(
600
+ 'WORKFLOW_AGENT_TOOL_GRANTS_INVALID',
601
+ `Agent node "${node.id}" must declare at most 32 unique tool grants.`,
602
+ { kind: 'node', nodeId: node.id, path: '/toolGrants' },
603
+ ),
604
+ );
605
+ } else if (typeof reference !== 'boolean') {
606
+ const invalidGrant = node.toolGrants.find(
607
+ (tool) => !reference.allowedTools.includes(tool),
608
+ );
609
+ if (invalidGrant) {
610
+ issues.push(
611
+ issue(
612
+ 'WORKFLOW_AGENT_TOOL_GRANT_NOT_ALLOWED',
613
+ `Tool "${invalidGrant}" is not allowed by pinned agent revision ${node.agent.revision}.`,
614
+ { kind: 'node', nodeId: node.id, path: '/toolGrants' },
615
+ ),
616
+ );
617
+ }
618
+ }
619
+ references.push({
620
+ kind: 'agent',
621
+ id: node.agent.agentId,
622
+ version: String(node.agent.revision),
623
+ available,
624
+ });
625
+ }
626
+ if (node.type === 'action') {
627
+ const action = catalog?.action(
628
+ node.action.actionId,
629
+ node.action.contractVersion,
630
+ ) ?? { available: false, requiredPermissions: [] };
631
+ const available =
632
+ action.available &&
633
+ (action.risk === undefined ||
634
+ action.risk === 'read' ||
635
+ action.risk === 'workspace-write') &&
636
+ (action.idempotency === undefined || action.idempotency === 'required');
637
+ references.push({
638
+ kind: 'action',
639
+ id: node.action.actionId,
640
+ version: String(node.action.contractVersion),
641
+ available,
642
+ });
643
+ action.requiredPermissions.forEach((permission) =>
644
+ requiredPermissions.add(permission),
645
+ );
646
+ if (action.risk === 'external' || action.risk === 'destructive')
647
+ issues.push(
648
+ issue(
649
+ 'WORKFLOW_ACTION_RISK_DENIED',
650
+ `Action "${node.action.actionId}" has an unsupported risk.`,
651
+ { kind: 'node', nodeId: node.id },
652
+ ),
653
+ );
654
+ }
655
+ }
656
+
657
+ const edgeIds = new Set<string>();
658
+ const incoming = new Map<string, number>();
659
+ const outgoing = new Map<string, number>();
660
+ for (const edge of graph.edges) {
661
+ if (!IDENTIFIER.test(edge.id))
662
+ issues.push(
663
+ issue(
664
+ 'WORKFLOW_EDGE_ID_INVALID',
665
+ `Edge "${edge.id}" has an invalid id.`,
666
+ { kind: 'edge', edgeId: edge.id },
667
+ ),
668
+ );
669
+ if (edgeIds.has(edge.id))
670
+ issues.push(
671
+ issue('WORKFLOW_EDGE_DUPLICATE', `Edge "${edge.id}" is duplicated.`, {
672
+ kind: 'edge',
673
+ edgeId: edge.id,
674
+ }),
675
+ );
676
+ edgeIds.add(edge.id);
677
+ const source = nodeById.get(edge.source.nodeId);
678
+ const target = nodeById.get(edge.target.nodeId);
679
+ if (!source || !target) {
680
+ issues.push(
681
+ issue(
682
+ 'WORKFLOW_EDGE_DANGLING',
683
+ `Edge "${edge.id}" refers to a missing node.`,
684
+ { kind: 'edge', edgeId: edge.id },
685
+ ),
686
+ );
687
+ continue;
688
+ }
689
+ const sourcePort = source.outputPorts.find(
690
+ (port) => port.name === edge.source.port,
691
+ );
692
+ const targetPort = target.inputPorts.find(
693
+ (port) => port.name === edge.target.port,
694
+ );
695
+ if (!sourcePort || !targetPort)
696
+ issues.push(
697
+ issue(
698
+ 'WORKFLOW_EDGE_PORT_MISSING',
699
+ `Edge "${edge.id}" refers to a missing port.`,
700
+ { kind: 'edge', edgeId: edge.id },
701
+ ),
702
+ );
703
+ else if (sourcePort.schemaId !== targetPort.schemaId)
704
+ issues.push(
705
+ issue(
706
+ 'WORKFLOW_EDGE_SCHEMA_INCOMPATIBLE',
707
+ `Edge "${edge.id}" connects incompatible schemas.`,
708
+ { kind: 'edge', edgeId: edge.id },
709
+ ),
710
+ );
711
+ const targetKey = `${edge.target.nodeId}:${edge.target.port}`;
712
+ incoming.set(targetKey, (incoming.get(targetKey) ?? 0) + 1);
713
+ outgoing.set(
714
+ edge.source.nodeId,
715
+ (outgoing.get(edge.source.nodeId) ?? 0) + 1,
716
+ );
717
+ }
718
+ for (const node of graph.nodes) {
719
+ for (const port of node.inputPorts) {
720
+ const count = incoming.get(`${node.id}:${port.name}`) ?? 0;
721
+ if (count === 0)
722
+ issues.push(
723
+ issue(
724
+ 'WORKFLOW_INPUT_UNCONNECTED',
725
+ `Input "${node.id}.${port.name}" is not connected.`,
726
+ { kind: 'node', nodeId: node.id },
727
+ ),
728
+ );
729
+ if (count > 1 && !(node.type === 'merge' && port.name === 'items'))
730
+ issues.push(
731
+ issue(
732
+ 'WORKFLOW_INPUT_CARDINALITY',
733
+ `Input "${node.id}.${port.name}" has more than one edge.`,
734
+ { kind: 'node', nodeId: node.id },
735
+ ),
736
+ );
737
+ }
738
+ if (node.type !== 'output' && (outgoing.get(node.id) ?? 0) === 0)
739
+ issues.push(
740
+ issue(
741
+ 'WORKFLOW_TERMINAL_OUTPUT_MISSING',
742
+ `Node "${node.id}" has no path to an output.`,
743
+ { kind: 'node', nodeId: node.id },
744
+ ),
745
+ );
746
+ }
747
+ const inputs = graph.nodes.filter((node) => node.type === 'input');
748
+ const outputs = graph.nodes.filter((node) => node.type === 'output');
749
+ if (inputs.length !== 1)
750
+ issues.push(
751
+ issue(
752
+ 'WORKFLOW_INPUT_COUNT_INVALID',
753
+ 'A graph requires exactly one input node.',
754
+ ),
755
+ );
756
+ if (outputs.length === 0)
757
+ issues.push(
758
+ issue(
759
+ 'WORKFLOW_OUTPUT_MISSING',
760
+ 'A graph requires at least one output node.',
761
+ ),
762
+ );
763
+
764
+ const topological = stableTopologicalOrder(graph.nodes, graph.edges);
765
+ if (topological.cyclic)
766
+ issues.push(issue('WORKFLOW_GRAPH_CYCLE', 'The graph contains a cycle.'));
767
+ const reachable = new Set<string>();
768
+ if (inputs[0]) {
769
+ const queue = [inputs[0].id];
770
+ while (queue.length > 0) {
771
+ const current = queue.shift()!;
772
+ if (reachable.has(current)) continue;
773
+ reachable.add(current);
774
+ for (const edge of graph.edges)
775
+ if (edge.source.nodeId === current) queue.push(edge.target.nodeId);
776
+ }
777
+ }
778
+ for (const node of graph.nodes)
779
+ if (!reachable.has(node.id))
780
+ issues.push(
781
+ issue(
782
+ 'WORKFLOW_NODE_UNREACHABLE',
783
+ `Node "${node.id}" is unreachable.`,
784
+ { kind: 'node', nodeId: node.id },
785
+ ),
786
+ );
787
+ const index = new Map(
788
+ topological.order.map((id, position) => [id, position]),
789
+ );
790
+ for (const node of graph.nodes) {
791
+ if (node.type === 'gate')
792
+ issues.push(...validateGateExpression(node.expression, node.id));
793
+ for (const mapping of node.mappings ?? [])
794
+ issues.push(...mappingIssues(mapping, node, index, graph));
795
+ }
796
+ for (const reference of references) {
797
+ if (reference.kind !== 'schema' && !reference.available)
798
+ issues.push(
799
+ issue(
800
+ reference.kind === 'agent'
801
+ ? 'WORKFLOW_AGENT_REVISION_MISSING'
802
+ : 'WORKFLOW_ACTION_VERSION_MISSING',
803
+ `${reference.kind} "${reference.id}" version ${reference.version} is unavailable.`,
804
+ ),
805
+ );
806
+ }
807
+ return {
808
+ reportVersion: 1,
809
+ graphChecksum: checksum,
810
+ valid: issues.every((entry) => entry.severity !== 'error'),
811
+ issues,
812
+ compiledOrder: topological.cyclic ? [] : topological.order,
813
+ references,
814
+ requiredPermissions: [...requiredPermissions].sort(),
815
+ limits: WORKFLOW_LIMITS,
816
+ };
817
+ }
818
+
819
+ export interface JsonValidationError {
820
+ readonly path: string;
821
+ readonly code: string;
822
+ }
823
+
824
+ export function validateJsonSchema(
825
+ value: JsonValue,
826
+ schema: JsonSchemaV1,
827
+ path = '',
828
+ ): readonly JsonValidationError[] {
829
+ const errors: JsonValidationError[] = [];
830
+ const type = schema.type;
831
+ const matches =
832
+ type === undefined ||
833
+ (type === 'null' && value === null) ||
834
+ (type === 'string' && typeof value === 'string') ||
835
+ (type === 'number' && typeof value === 'number') ||
836
+ (type === 'integer' &&
837
+ typeof value === 'number' &&
838
+ Number.isSafeInteger(value)) ||
839
+ (type === 'boolean' && typeof value === 'boolean') ||
840
+ (type === 'array' && Array.isArray(value)) ||
841
+ (type === 'object' && isRecord(value));
842
+ if (!matches) return [{ path, code: 'type' }];
843
+ if (
844
+ Array.isArray(schema.enum) &&
845
+ !schema.enum.some((entry) => canonical(entry) === canonical(value))
846
+ )
847
+ errors.push({ path, code: 'enum' });
848
+ if (
849
+ schema.const !== undefined &&
850
+ canonical(schema.const) !== canonical(value)
851
+ )
852
+ errors.push({ path, code: 'const' });
853
+ if (typeof value === 'string') {
854
+ if (typeof schema.minLength === 'number' && value.length < schema.minLength)
855
+ errors.push({ path, code: 'minLength' });
856
+ if (typeof schema.maxLength === 'number' && value.length > schema.maxLength)
857
+ errors.push({ path, code: 'maxLength' });
858
+ }
859
+ if (typeof value === 'number') {
860
+ if (typeof schema.minimum === 'number' && value < schema.minimum)
861
+ errors.push({ path, code: 'minimum' });
862
+ if (typeof schema.maximum === 'number' && value > schema.maximum)
863
+ errors.push({ path, code: 'maximum' });
864
+ }
865
+ if (Array.isArray(value) && isRecord(schema.items))
866
+ value.forEach((entry, index) =>
867
+ errors.push(
868
+ ...validateJsonSchema(
869
+ entry,
870
+ schema.items as JsonSchemaV1,
871
+ `${path}/${index}`,
872
+ ),
873
+ ),
874
+ );
875
+ if (isRecord(value)) {
876
+ const properties = isRecord(schema.properties) ? schema.properties : {};
877
+ const required = Array.isArray(schema.required)
878
+ ? new Set(
879
+ schema.required.filter(
880
+ (entry): entry is string => typeof entry === 'string',
881
+ ),
882
+ )
883
+ : new Set<string>();
884
+ for (const name of required)
885
+ if (!Object.hasOwn(value, name))
886
+ errors.push({ path: `${path}/${name}`, code: 'required' });
887
+ for (const [name, entry] of Object.entries(value)) {
888
+ const child = Object.hasOwn(properties, name)
889
+ ? properties[name]
890
+ : undefined;
891
+ if (isRecord(child))
892
+ errors.push(
893
+ ...validateJsonSchema(
894
+ entry as JsonValue,
895
+ child as JsonSchemaV1,
896
+ `${path}/${name}`,
897
+ ),
898
+ );
899
+ else if (schema.additionalProperties === false)
900
+ errors.push({ path: `${path}/${name}`, code: 'additionalProperties' });
901
+ }
902
+ }
903
+ return errors.slice(0, 100);
904
+ }
905
+
906
+ export function readJsonPointer(
907
+ value: JsonValue,
908
+ pointer: string,
909
+ ): JsonValue | undefined {
910
+ if (pointer === '') return value;
911
+ if (!validPointer(pointer)) return undefined;
912
+ let current: JsonValue | undefined = value;
913
+ for (const raw of pointer.slice(1).split('/')) {
914
+ const key = raw.replaceAll('~1', '/').replaceAll('~0', '~');
915
+ if (Array.isArray(current)) {
916
+ if (!/^(0|[1-9][0-9]*)$/.test(key)) return undefined;
917
+ const index = Number(key);
918
+ current =
919
+ Number.isSafeInteger(index) && index >= 0 ? current[index] : undefined;
920
+ } else if (isRecord(current))
921
+ current = Object.hasOwn(current, key)
922
+ ? (current[key] as JsonValue)
923
+ : undefined;
924
+ else return undefined;
925
+ }
926
+ return current;
927
+ }
928
+
929
+ function writeJsonPointer(
930
+ target: Record<string, JsonValue>,
931
+ pointer: string,
932
+ value: JsonValue,
933
+ ): void {
934
+ if (
935
+ !validPointer(pointer) ||
936
+ pointer
937
+ .split('/')
938
+ .some((part) =>
939
+ ['__proto__', 'constructor', 'prototype'].includes(
940
+ part.replaceAll('~1', '/').replaceAll('~0', '~'),
941
+ ),
942
+ )
943
+ )
944
+ throw new Error('WORKFLOW_MAPPING_TARGET_INVALID');
945
+ if (pointer === '') {
946
+ if (value === null || typeof value !== 'object' || Array.isArray(value)) {
947
+ throw new Error('WORKFLOW_MAPPING_TARGET_INVALID');
948
+ }
949
+ for (const key of Object.keys(target)) delete target[key];
950
+ for (const [key, entry] of Object.entries(value))
951
+ Object.defineProperty(target, key, {
952
+ value: structuredClone(entry),
953
+ enumerable: true,
954
+ configurable: true,
955
+ writable: true,
956
+ });
957
+ return;
958
+ }
959
+ const parts = pointer
960
+ .slice(1)
961
+ .split('/')
962
+ .map((entry) => entry.replaceAll('~1', '/').replaceAll('~0', '~'));
963
+ let current = target;
964
+ for (const part of parts.slice(0, -1)) {
965
+ const existing = Object.hasOwn(current, part) ? current[part] : undefined;
966
+ if (
967
+ existing === null ||
968
+ typeof existing !== 'object' ||
969
+ Array.isArray(existing)
970
+ ) {
971
+ current[part] = {};
972
+ }
973
+ current = current[part] as Record<string, JsonValue>;
974
+ }
975
+ const last = parts.at(-1);
976
+ if (last === undefined) throw new Error('WORKFLOW_MAPPING_TARGET_INVALID');
977
+ current[last] = structuredClone(value);
978
+ }
979
+
980
+ export function applyWorkflowMappings(
981
+ input: JsonValue,
982
+ mappings: readonly WorkflowTargetMappingV1[],
983
+ outputs: ReadonlyMap<string, JsonValue>,
984
+ ): JsonValue {
985
+ if (mappings.length === 0) return structuredClone(input);
986
+ const target: Record<string, JsonValue> = {};
987
+ for (const mapping of mappings) {
988
+ let value: JsonValue | undefined;
989
+ if (mapping.binding.kind === 'literal') value = mapping.binding.value;
990
+ if (mapping.binding.kind === 'path') {
991
+ if (
992
+ !outputs.has(
993
+ `${mapping.binding.sourceNodeId}:${mapping.binding.sourcePort}`,
994
+ )
995
+ )
996
+ throw new Error('WORKFLOW_MAPPING_SOURCE_INVALID');
997
+ value = readJsonPointer(
998
+ outputs.get(
999
+ `${mapping.binding.sourceNodeId}:${mapping.binding.sourcePort}`,
1000
+ ) ?? null,
1001
+ mapping.binding.pointer,
1002
+ );
1003
+ }
1004
+ if (mapping.binding.kind === 'template') {
1005
+ const values = new Map<string, string>();
1006
+ for (const variable of mapping.binding.variables) {
1007
+ if (!outputs.has(`${variable.sourceNodeId}:${variable.sourcePort}`))
1008
+ throw new Error('WORKFLOW_MAPPING_SOURCE_INVALID');
1009
+ const resolved = readJsonPointer(
1010
+ outputs.get(`${variable.sourceNodeId}:${variable.sourcePort}`) ??
1011
+ null,
1012
+ variable.pointer,
1013
+ );
1014
+ if (
1015
+ resolved === undefined ||
1016
+ (resolved !== null && typeof resolved === 'object')
1017
+ ) {
1018
+ throw new Error('WORKFLOW_MAPPING_SOURCE_INVALID');
1019
+ }
1020
+ values.set(variable.name, resolved === null ? '' : String(resolved));
1021
+ }
1022
+ value = mapping.binding.template.replace(
1023
+ /{{\s*([a-z][a-z0-9.-]*)\s*}}/g,
1024
+ (_match, name: string) => {
1025
+ const resolved = values.get(name);
1026
+ if (resolved === undefined)
1027
+ throw new Error('WORKFLOW_TEMPLATE_VARIABLE_MISSING');
1028
+ return resolved;
1029
+ },
1030
+ );
1031
+ }
1032
+ if (value === undefined) throw new Error('WORKFLOW_MAPPING_SOURCE_INVALID');
1033
+ writeJsonPointer(target, mapping.targetPointer, value);
1034
+ }
1035
+ return target;
1036
+ }
1037
+
1038
+ export function evaluateGate(
1039
+ expression: WorkflowGateExpressionV1,
1040
+ input: JsonValue,
1041
+ ): boolean {
1042
+ const required = (value: JsonValue | undefined): JsonValue => {
1043
+ if (value === undefined) throw new Error('WORKFLOW_GATE_PATH_MISSING');
1044
+ return value;
1045
+ };
1046
+ const boolean = (value: JsonValue | undefined): boolean => {
1047
+ if (typeof required(value) !== 'boolean')
1048
+ throw new Error('WORKFLOW_GATE_TYPE_MISMATCH');
1049
+ return value as boolean;
1050
+ };
1051
+ const evaluate = (entry: WorkflowGateExpressionV1): JsonValue | undefined => {
1052
+ switch (entry.op) {
1053
+ case 'literal':
1054
+ return entry.value;
1055
+ case 'path':
1056
+ return readJsonPointer(input, entry.pointer);
1057
+ case 'exists':
1058
+ return evaluate(entry.value) !== undefined;
1059
+ case 'not':
1060
+ return !boolean(evaluate(entry.value));
1061
+ case 'and':
1062
+ return entry.values.every((value) => boolean(evaluate(value)));
1063
+ case 'or':
1064
+ return entry.values.some((value) => boolean(evaluate(value)));
1065
+ case 'eq':
1066
+ return (
1067
+ canonical(required(evaluate(entry.left))) ===
1068
+ canonical(required(evaluate(entry.right)))
1069
+ );
1070
+ case 'gt':
1071
+ case 'gte':
1072
+ case 'lt':
1073
+ case 'lte': {
1074
+ const left = evaluate(entry.left);
1075
+ const right = evaluate(entry.right);
1076
+ if (typeof left !== 'number' || typeof right !== 'number')
1077
+ throw new Error('WORKFLOW_GATE_TYPE_MISMATCH');
1078
+ return entry.op === 'gt'
1079
+ ? left > right
1080
+ : entry.op === 'gte'
1081
+ ? left >= right
1082
+ : entry.op === 'lt'
1083
+ ? left < right
1084
+ : left <= right;
1085
+ }
1086
+ case 'in': {
1087
+ const right = required(evaluate(entry.right));
1088
+ const left = required(evaluate(entry.left));
1089
+ if (!Array.isArray(right))
1090
+ throw new Error('WORKFLOW_GATE_TYPE_MISMATCH');
1091
+ return (
1092
+ Array.isArray(right) &&
1093
+ right.some((value) => canonical(value) === canonical(left))
1094
+ );
1095
+ }
1096
+ }
1097
+ };
1098
+ const result = evaluate(expression);
1099
+ if (typeof result !== 'boolean')
1100
+ throw new Error('WORKFLOW_GATE_RESULT_INVALID');
1101
+ return result;
1102
+ }
1103
+
1104
+ export function evidenceOf(
1105
+ value: JsonValue | undefined,
1106
+ schemaId: string,
1107
+ ): WorkflowPayloadEvidenceV1 {
1108
+ if (value === undefined)
1109
+ return {
1110
+ version: 1,
1111
+ state: 'absent',
1112
+ schemaId,
1113
+ hash: jsonHash(null),
1114
+ originalByteSize: 0,
1115
+ reason: 'not-emitted',
1116
+ };
1117
+ const originalByteSize = jsonByteSize(value);
1118
+ const hash = jsonHash(value);
1119
+ if (originalByteSize > WORKFLOW_LIMITS.maxEnvelopeBytes)
1120
+ return {
1121
+ version: 1,
1122
+ state: 'truncated',
1123
+ schemaId,
1124
+ hash,
1125
+ originalByteSize,
1126
+ reason: 'size-limit',
1127
+ };
1128
+ return {
1129
+ version: 1,
1130
+ state: 'available',
1131
+ schemaId,
1132
+ hash,
1133
+ originalByteSize,
1134
+ preview: structuredClone(value),
1135
+ };
1136
+ }