@mastra/factory 0.29.0-alpha.2 → 0.29.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/README.md +44 -5
  2. package/dist/factory.d.ts +8 -0
  3. package/dist/factory.d.ts.map +1 -1
  4. package/dist/factory.js +26 -10
  5. package/dist/factory.js.map +1 -1
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +1 -2
  9. package/dist/integrations/dependabot/rules.d.ts.map +1 -1
  10. package/dist/integrations/dependabot/rules.js +1 -5
  11. package/dist/integrations/dependabot/rules.js.map +1 -1
  12. package/dist/integrations/github/commits.d.ts +0 -21
  13. package/dist/integrations/github/commits.d.ts.map +1 -1
  14. package/dist/integrations/github/commits.js +1 -24
  15. package/dist/integrations/github/commits.js.map +1 -1
  16. package/dist/integrations/github/integration.d.ts +1 -1
  17. package/dist/integrations/github/integration.d.ts.map +1 -1
  18. package/dist/integrations/github/integration.js +2 -6
  19. package/dist/integrations/github/integration.js.map +1 -1
  20. package/dist/integrations/github/reconcile-worker.d.ts.map +1 -1
  21. package/dist/integrations/github/reconcile-worker.js +30 -1
  22. package/dist/integrations/github/reconcile-worker.js.map +1 -1
  23. package/dist/integrations/github/routes.d.ts +1 -11
  24. package/dist/integrations/github/routes.d.ts.map +1 -1
  25. package/dist/integrations/github/routes.js +6 -515
  26. package/dist/integrations/github/routes.js.map +1 -1
  27. package/dist/integrations/github/rules.d.ts.map +1 -1
  28. package/dist/integrations/github/rules.js +76 -13
  29. package/dist/integrations/github/rules.js.map +1 -1
  30. package/dist/integrations/github/sandbox.d.ts.map +1 -1
  31. package/dist/integrations/github/sandbox.js +11 -2
  32. package/dist/integrations/github/sandbox.js.map +1 -1
  33. package/dist/integrations/gitlab/discovery.d.ts +1 -1
  34. package/dist/integrations/gitlab/discovery.js +1 -1
  35. package/dist/integrations/gitlab/discovery.js.map +1 -1
  36. package/dist/integrations/gitlab/integration.d.ts.map +1 -1
  37. package/dist/integrations/gitlab/integration.js +0 -1
  38. package/dist/integrations/gitlab/integration.js.map +1 -1
  39. package/dist/integrations/gitlab/routes.d.ts +0 -2
  40. package/dist/integrations/gitlab/routes.d.ts.map +1 -1
  41. package/dist/integrations/gitlab/routes.js +49 -165
  42. package/dist/integrations/gitlab/routes.js.map +1 -1
  43. package/dist/integrations/gitlab/rules.d.ts.map +1 -1
  44. package/dist/integrations/gitlab/rules.js +20 -7
  45. package/dist/integrations/gitlab/rules.js.map +1 -1
  46. package/dist/integrations/incidentio/routes.d.ts +5 -5
  47. package/dist/integrations/incidentio/routes.d.ts.map +1 -1
  48. package/dist/integrations/incidentio/routes.js +3 -59
  49. package/dist/integrations/incidentio/routes.js.map +1 -1
  50. package/dist/integrations/incidentio/rules.d.ts.map +1 -1
  51. package/dist/integrations/incidentio/rules.js +1 -5
  52. package/dist/integrations/incidentio/rules.js.map +1 -1
  53. package/dist/integrations/jira/issue-reconciler.d.ts +1 -1
  54. package/dist/integrations/jira/issue-reconciler.d.ts.map +1 -1
  55. package/dist/integrations/jira/issue-reconciler.js.map +1 -1
  56. package/dist/integrations/jira/routes.d.ts +2 -2
  57. package/dist/integrations/jira/routes.d.ts.map +1 -1
  58. package/dist/integrations/jira/routes.js +0 -68
  59. package/dist/integrations/jira/routes.js.map +1 -1
  60. package/dist/integrations/jira/rules.d.ts.map +1 -1
  61. package/dist/integrations/jira/rules.js +1 -5
  62. package/dist/integrations/jira/rules.js.map +1 -1
  63. package/dist/integrations/linear/routes.d.ts +2 -2
  64. package/dist/integrations/linear/routes.d.ts.map +1 -1
  65. package/dist/integrations/linear/routes.js +0 -83
  66. package/dist/integrations/linear/routes.js.map +1 -1
  67. package/dist/integrations/linear/rules.d.ts.map +1 -1
  68. package/dist/integrations/linear/rules.js +12 -5
  69. package/dist/integrations/linear/rules.js.map +1 -1
  70. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  71. package/dist/integrations/platform/github/integration.js +1 -3
  72. package/dist/integrations/platform/github/integration.js.map +1 -1
  73. package/dist/integrations/platform/jira/routes.d.ts +2 -2
  74. package/dist/integrations/platform/jira/routes.d.ts.map +1 -1
  75. package/dist/integrations/platform/jira/routes.js +0 -69
  76. package/dist/integrations/platform/jira/routes.js.map +1 -1
  77. package/dist/integrations/vanta/rules.d.ts.map +1 -1
  78. package/dist/integrations/vanta/rules.js +1 -5
  79. package/dist/integrations/vanta/rules.js.map +1 -1
  80. package/dist/metrics/collectors/postgres.d.ts +29 -0
  81. package/dist/metrics/collectors/postgres.d.ts.map +1 -0
  82. package/dist/metrics/collectors/postgres.js +121 -0
  83. package/dist/metrics/collectors/postgres.js.map +1 -0
  84. package/dist/metrics/collectors/probe.d.ts +22 -0
  85. package/dist/metrics/collectors/probe.d.ts.map +1 -0
  86. package/dist/metrics/collectors/probe.js +69 -0
  87. package/dist/metrics/collectors/probe.js.map +1 -0
  88. package/dist/metrics/collectors/process.d.ts +13 -0
  89. package/dist/metrics/collectors/process.d.ts.map +1 -0
  90. package/dist/metrics/collectors/process.js +85 -0
  91. package/dist/metrics/collectors/process.js.map +1 -0
  92. package/dist/metrics/collectors/redis.d.ts +29 -0
  93. package/dist/metrics/collectors/redis.d.ts.map +1 -0
  94. package/dist/metrics/collectors/redis.js +97 -0
  95. package/dist/metrics/collectors/redis.js.map +1 -0
  96. package/dist/metrics/config.d.ts +33 -0
  97. package/dist/metrics/config.d.ts.map +1 -0
  98. package/dist/metrics/config.js +65 -0
  99. package/dist/metrics/config.js.map +1 -0
  100. package/dist/metrics/index.d.ts +20 -0
  101. package/dist/metrics/index.d.ts.map +1 -0
  102. package/dist/metrics/index.js +65 -0
  103. package/dist/metrics/index.js.map +1 -0
  104. package/dist/metrics/intake.d.ts +28 -0
  105. package/dist/metrics/intake.d.ts.map +1 -0
  106. package/dist/metrics/intake.js +76 -0
  107. package/dist/metrics/intake.js.map +1 -0
  108. package/dist/metrics/metrics.d.ts +60 -0
  109. package/dist/metrics/metrics.d.ts.map +1 -0
  110. package/dist/metrics/metrics.js +182 -0
  111. package/dist/metrics/metrics.js.map +1 -0
  112. package/dist/metrics/sandbox.d.ts +35 -0
  113. package/dist/metrics/sandbox.d.ts.map +1 -0
  114. package/dist/metrics/sandbox.js +156 -0
  115. package/dist/metrics/sandbox.js.map +1 -0
  116. package/dist/packages/_internals/workspace/dist/index.js.map +1 -1
  117. package/dist/routes/automation-runs.d.ts +0 -2
  118. package/dist/routes/automation-runs.d.ts.map +1 -1
  119. package/dist/routes/automation-runs.js +2 -6
  120. package/dist/routes/automation-runs.js.map +1 -1
  121. package/dist/routes/contracts.d.ts +0 -5
  122. package/dist/routes/contracts.d.ts.map +1 -1
  123. package/dist/routes/contracts.js +2 -4
  124. package/dist/routes/contracts.js.map +1 -1
  125. package/dist/routes/fs.d.ts +10 -0
  126. package/dist/routes/fs.d.ts.map +1 -1
  127. package/dist/routes/fs.js +184 -11
  128. package/dist/routes/fs.js.map +1 -1
  129. package/dist/routes/projects.d.ts.map +1 -1
  130. package/dist/routes/projects.js +4 -17
  131. package/dist/routes/projects.js.map +1 -1
  132. package/dist/routes/source-control-sessions.d.ts +0 -3
  133. package/dist/routes/source-control-sessions.d.ts.map +1 -1
  134. package/dist/routes/source-control-sessions.js +0 -19
  135. package/dist/routes/source-control-sessions.js.map +1 -1
  136. package/dist/routes/surface.d.ts +0 -2
  137. package/dist/routes/surface.d.ts.map +1 -1
  138. package/dist/routes/surface.js +2 -12
  139. package/dist/routes/surface.js.map +1 -1
  140. package/dist/rules/dispatcher.d.ts +1 -0
  141. package/dist/rules/dispatcher.d.ts.map +1 -1
  142. package/dist/rules/dispatcher.js +27 -13
  143. package/dist/rules/dispatcher.js.map +1 -1
  144. package/dist/rules/processor.d.ts.map +1 -1
  145. package/dist/rules/processor.js +1 -6
  146. package/dist/rules/processor.js.map +1 -1
  147. package/dist/rules/start-coordinator.d.ts +1 -0
  148. package/dist/rules/start-coordinator.d.ts.map +1 -1
  149. package/dist/rules/start-coordinator.js +2 -1
  150. package/dist/rules/start-coordinator.js.map +1 -1
  151. package/dist/rules/transition-service.d.ts.map +1 -1
  152. package/dist/rules/transition-service.js +0 -2
  153. package/dist/rules/transition-service.js.map +1 -1
  154. package/dist/sandbox/session-retirement.d.ts.map +1 -1
  155. package/dist/sandbox/session-retirement.js +22 -14
  156. package/dist/sandbox/session-retirement.js.map +1 -1
  157. package/dist/sandbox/session-sandbox.d.ts +2 -0
  158. package/dist/sandbox/session-sandbox.d.ts.map +1 -1
  159. package/dist/sandbox/session-sandbox.js +7 -1
  160. package/dist/sandbox/session-sandbox.js.map +1 -1
  161. package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
  162. package/dist/storage/domains/boards/schemas.js +0 -4
  163. package/dist/storage/domains/boards/schemas.js.map +1 -1
  164. package/dist/storage/domains/intake/base.d.ts +11 -10
  165. package/dist/storage/domains/intake/base.d.ts.map +1 -1
  166. package/dist/storage/domains/intake/base.js +30 -65
  167. package/dist/storage/domains/intake/base.js.map +1 -1
  168. package/dist/storage/domains/integrations/base.d.ts +0 -2
  169. package/dist/storage/domains/integrations/base.d.ts.map +1 -1
  170. package/dist/storage/domains/integrations/base.js +0 -6
  171. package/dist/storage/domains/integrations/base.js.map +1 -1
  172. package/dist/storage/domains/projects/base.d.ts.map +1 -1
  173. package/dist/storage/domains/projects/base.js +0 -12
  174. package/dist/storage/domains/projects/base.js.map +1 -1
  175. package/dist/storage/domains/source-control/base.d.ts +0 -10
  176. package/dist/storage/domains/source-control/base.d.ts.map +1 -1
  177. package/dist/storage/domains/source-control/base.js +1 -19
  178. package/dist/storage/domains/source-control/base.js.map +1 -1
  179. package/dist/storage/domains/source-control/inmemory.d.ts +1 -1
  180. package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
  181. package/dist/storage/domains/source-control/inmemory.js +1 -6
  182. package/dist/storage/domains/source-control/inmemory.js.map +1 -1
  183. package/dist/storage/domains/work-items/base.d.ts +6 -36
  184. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  185. package/dist/storage/domains/work-items/base.js +42 -82
  186. package/dist/storage/domains/work-items/base.js.map +1 -1
  187. package/dist/storage/domains/work-items/work-item-schema.d.ts +12 -3
  188. package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -1
  189. package/dist/storage/domains/work-items/work-item-schema.js +12 -3
  190. package/dist/storage/domains/work-items/work-item-schema.js.map +1 -1
  191. package/dist/storage/legacy-collections.d.ts +9 -0
  192. package/dist/storage/legacy-collections.d.ts.map +1 -0
  193. package/dist/storage/legacy-collections.js +17 -0
  194. package/dist/storage/legacy-collections.js.map +1 -0
  195. package/dist/timing.d.ts +4 -1
  196. package/dist/timing.d.ts.map +1 -1
  197. package/dist/timing.js +12 -4
  198. package/dist/timing.js.map +1 -1
  199. package/dist/workspace.d.ts.map +1 -1
  200. package/dist/workspace.js +8 -4
  201. package/dist/workspace.js.map +1 -1
  202. package/factory-skills/configure-factory-rules/SKILL.md +2 -2
  203. package/package.json +10 -10
  204. package/dist/session/filesystem-capture.d.ts +0 -50
  205. package/dist/session/filesystem-capture.d.ts.map +0 -1
  206. package/dist/session/filesystem-capture.js +0 -229
  207. package/dist/session/filesystem-capture.js.map +0 -1
  208. package/dist/storage/domains/filesystem/base.d.ts +0 -30
  209. package/dist/storage/domains/filesystem/base.d.ts.map +0 -1
  210. package/dist/storage/domains/filesystem/base.js +0 -78
  211. package/dist/storage/domains/filesystem/base.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"session-sandbox.js","names":[],"sources":["../../src/sandbox/session-sandbox.ts"],"sourcesContent":["import path from 'node:path';\nimport {\n SETUP_FAILED_MARKER_PATH,\n SETUP_MARKER_PATH,\n WORKSPACE_SETUP_MARKER_PATH,\n repoSetupMarkerPath,\n setupMarkerContent,\n} from '@internal/workspace';\n\nimport type {\n FactorySandbox,\n FactorySandboxContext as CoreFactorySandboxContext,\n MastraSandbox,\n SandboxStartHook,\n WorkspaceSandbox,\n} from '@mastra/core/workspace';\nimport { timedPhase } from '../timing.js';\nimport { deriveLocalWorkdir, deriveRemoteRepoDir, repoDirUnder, repositoryDirectoryName } from './workdir.js';\n\n/**\n * Everything factory knows about a session's sandbox needs: the whole contract\n * between factory and the host's FactorySandbox. Factory owns intent; the\n * provider owns resolving `sessionId` to a runnable VM. Defined in\n * `@mastra/core/workspace` so provider packages can implement it without\n * depending on factory.\n */\nexport type FactorySandboxContext = CoreFactorySandboxContext;\n\n/**\n * The deploy's sandbox configuration: construct a session's sandbox from\n * intent. The sandbox identity is the session id; the provider must honor\n * id-keyed getOrCreate on `start()` (reconnect/resume an existing VM for the\n * id, create otherwise). Construction must be cheap and side-effect-free —\n * VMs are provisioned on `start()` only. Local sandboxes should root their\n * `workingDirectory` at a per-session directory (e.g.\n * `join(root, ctx.sessionId)`); the repo checks out as a subdirectory of it.\n *\n * Forward `ctx.sandboxId` to providers that reattach by physical id so resume\n * reattaches the original VM instead of provisioning a replacement.\n *\n * Returns a `MastraSandbox`, not the bare `WorkspaceSandbox` interface:\n * factory relies on the base class for the start lifecycle and the runtime\n * env, so providers extend it rather than reimplementing the contract.\n *\n * Factory attaches its own session setup to the returned sandbox, so the\n * callback never has to wire it up. A callback may still pass its own\n * `onStart`; it runs after factory's setup, against a prepared workspace.\n *\n * @example\n * ```typescript\n * sandbox: ({ sessionId, sandboxId }) => new E2BSandbox({ id: sessionId, sandboxId })\n * ```\n *\n * A FactorySandbox instance (for example `new E2BFactorySandbox({ apiKey })`)\n * additionally exposes settings and template builds to the environment.\n */\nexport type MastraFactorySandboxConfig = (ctx: FactorySandboxContext) => MastraSandbox;\n\n/**\n * The `sandbox` option of `MastraFactoryConfig`: a FactorySandbox instance\n * (it owns the session sandbox constructor, the repo template and the\n * environment settings schema) or a bare callback, which the factory wraps as a `provider: 'custom'` sandbox with no settings.\n */\nexport type MastraFactorySandboxOption = FactorySandbox | MastraFactorySandboxConfig;\n\n/**\n * What the start hook learned about the setup command before running the\n * session setup, and how to record its completion afterwards.\n */\nexport interface SessionSetupGate {\n /** True when the sandbox already carries a marker for the current setup command. */\n setupDone: boolean;\n /** Write the marker once the setup command succeeded. Best-effort. */\n markSetupDone: () => Promise<void>;\n}\n\n/**\n * The session's setup work, run against a started sandbox on EVERY start.\n * Materialize and checkout are idempotent and must always run (a warm boot\n * still needs its pull); only the setup command consults `gate`.\n */\nexport type SessionSetupRun = (sandbox: WorkspaceSandbox, workdir: string, gate: SessionSetupGate) => Promise<void>;\n\n/** One environment repository as the boot hook needs it: its slug and setup command. */\nexport interface SessionEnvironmentRepository {\n slug: string;\n setupCommand?: string;\n}\n\n/** What the environment hook learned about one repository before the boot runs. */\nexport interface SessionEnvironmentRepositoryGate extends SessionEnvironmentRepository {\n /** `<root>/<repoDir>`, the directory the template cloned this repository into. */\n dir: string;\n gate: SessionSetupGate;\n}\n\n/** The environment hook's view of the workspace: the root, every repository in position order, the workspace gate. */\nexport interface SessionEnvironmentGate {\n /** The workspace root, parent of every repository directory. */\n root: string;\n repos: SessionEnvironmentRepositoryGate[];\n /** Gate for `workspaceSetupCommand`; `setupDone` when there is no command or its marker matches. */\n workspace: SessionSetupGate;\n}\n\n/** The list-form session boot: run on every start, like `SessionSetupRun`. */\nexport type SessionEnvironmentSetupRun = (\n sandbox: WorkspaceSandbox,\n environment: SessionEnvironmentGate,\n) => Promise<void>;\n\n/**\n * Per-process session-id → sandbox instance memo.\n *\n * The provider contract is id-keyed getOrCreate, but provider find-then-create\n * has a real double-create race across independent instances. Memoizing the\n * instance per session makes the base class's per-instance start coalescing\n * apply process-wide per session — the same single-flight scope the fleet's\n * per-binding coalescing provided. Cross-replica races are accepted (the\n * fleet was also per-replica).\n */\ninterface SessionSandboxEntry {\n sandbox: WorkspaceSandbox;\n /**\n * The session's repo checkout root, recorded for passive readers (fs\n * routes, capture, authz). Local sandboxes derive it at construction;\n * remote sandboxes clone into the VM's own home, so it is undefined until\n * `resolveSessionWorkdir` probes the first started VM — passive readers\n * treat an unresolved workdir as \"nothing materialized\".\n */\n workdir?: string;\n /** The session's own repository, the only one `workdir` is ever recorded for. */\n ownRepo: string;\n /** Environment repositories in position order; the session's own repository is among them. */\n repos?: string[];\n}\n\nconst sessionSandboxes = new Map<string, SessionSandboxEntry>();\n\n/** One environment repository as the file readers see it. */\nexport interface SessionLayoutRepository {\n slug: string;\n /** Absolute checkout directory. */\n dir: string;\n /** Path prefix of this checkout under the layout root: empty for a single-repository session, `<dir>/` otherwise. */\n prefix: string;\n}\n\n/**\n * Where a session's files are read from. A session with one repository is\n * rooted at that checkout, as before environments existed; a session with\n * several is rooted at the workspace root with each checkout as a directory\n * beneath it.\n */\nexport interface SessionLayout {\n root: string;\n repos: SessionLayoutRepository[];\n}\n\n/** The layout of a memoized session, `undefined` until its workdir resolved. */\nexport function sessionLayout(entry: SessionSandboxEntry | undefined): SessionLayout | undefined {\n if (!entry?.workdir) return undefined;\n const slugs = entry.repos?.length ? entry.repos : [entry.ownRepo];\n if (slugs.length === 1) {\n return { root: entry.workdir, repos: [{ slug: slugs[0]!, dir: entry.workdir, prefix: '' }] };\n }\n const root = path.posix.dirname(entry.workdir);\n return {\n root,\n repos: slugs.map(slug => {\n const dir = slug.toLowerCase() === entry.ownRepo.toLowerCase() ? entry.workdir! : repoDirUnder(root, slug);\n return { slug, dir, prefix: `${path.posix.basename(dir)}/` };\n }),\n };\n}\n\n/**\n * Get the session's memoized sandbox entry, constructing (and memoizing) it on\n * first access. Construction is cheap and side-effect-free by contract; VMs\n * are provisioned on `start()` only. Local sandboxes get their workdir here;\n * remote workdirs are a runtime fact of the VM, resolved on first start.\n */\nexport function getSessionSandbox(\n sessionId: string,\n repoFullName: string,\n construct: () => WorkspaceSandbox,\n repos?: string[],\n): SessionSandboxEntry {\n const existing = sessionSandboxes.get(sessionId);\n if (existing) {\n // The environment can change between boots; the layout follows the latest.\n if (repos) existing.repos = repos;\n return existing;\n }\n const sandbox = construct();\n const local = deriveLocalWorkdir(sandbox, repoFullName);\n const entry: SessionSandboxEntry = {\n sandbox,\n ownRepo: repoFullName,\n ...(local ? { workdir: local } : {}),\n ...(repos ? { repos } : {}),\n };\n sessionSandboxes.set(sessionId, entry);\n return entry;\n}\n\n/**\n * Resolve (and memoize on the session entry) the session's repo checkout\n * root. Local sandboxes answer synchronously from their configured\n * `workingDirectory`; remote sandboxes clone into the VM's own default cwd,\n * so the first resolution probes it with one `pwd` — the VM tells us where\n * home is, we never invent a path. Calling this against a stopped sandbox\n * lazily starts it (the probe is a command), so passive readers must peek\n * `entry.workdir` instead. The memo is the session's own checkout; another\n * environment repository lives beside it under the same root, so it is\n * answered from the memo's parent without a second probe.\n */\nexport async function resolveSessionWorkdir(\n sessionId: string,\n sandbox: WorkspaceSandbox,\n repoFullName: string,\n): Promise<string> {\n const entry = sessionSandboxes.get(sessionId);\n const memo = entry && entry.sandbox === sandbox ? entry : undefined;\n if (memo && memo.ownRepo !== repoFullName) {\n // Passive readers take `workdir` as the session's own checkout, so a\n // sibling never lands in the memo: resolve the own checkout (cold memo\n // included) and answer the sibling beside it.\n const own = await resolveSessionWorkdir(sessionId, sandbox, memo.ownRepo);\n return repoDirUnder(path.posix.dirname(own), repoFullName);\n }\n if (memo?.workdir) return memo.workdir;\n const workdir =\n deriveLocalWorkdir(sandbox, repoFullName) ??\n deriveRemoteRepoDir(sandbox, repoFullName) ??\n repoDirUnder(await probeHome(sandbox), repoFullName);\n if (memo) memo.workdir = workdir;\n return workdir;\n}\n\n/** One `pwd` in the VM's default shell cwd — its home dir, by provider convention. */\nasync function probeHome(sandbox: WorkspaceSandbox): Promise<string> {\n if (!sandbox.executeCommand) {\n throw new Error(`Sandbox '${sandbox.id}' cannot resolve its workdir: no executeCommand implementation`);\n }\n const probe = await sandbox.executeCommand('pwd');\n const home = probe.stdout.trim().split('\\n').pop()?.trim() ?? '';\n if (probe.exitCode !== 0 || !home.startsWith('/')) {\n throw new Error(\n `Sandbox '${sandbox.id}' default cwd probe failed (exit ${probe.exitCode}): ${\n probe.stderr.trim() || probe.stdout.trim() || 'empty output'\n }`,\n );\n }\n return home;\n}\n\n/**\n * The session's memoized sandbox (and its workdir) when one was already\n * constructed in this process, else undefined. Never constructs — passive\n * read paths use this so browsing files cannot provision a VM.\n */\nexport function peekSessionSandbox(sessionId: string): SessionSandboxEntry | undefined {\n return sessionSandboxes.get(sessionId);\n}\n\n/** Drop the memoized instance (on stop/destroy/retirement or construction failure). */\nexport function evictSessionSandbox(sessionId: string): void {\n sessionSandboxes.delete(sessionId);\n failedSetupCommands.delete(sessionId);\n}\n\n/** Test-only: reset the process-wide memo between tests. */\nexport function __clearSessionSandboxesForTests(): void {\n sessionSandboxes.clear();\n failedSetupCommands.clear();\n}\n\n/**\n * Setup commands that already failed once for a session. The first failure\n * fails the start loudly — the agent sees the real error in the tool result\n * that triggered it. Recording it lets the next start skip the known-bad\n * command instead of wedging the session behind a permanently failing\n * onStart: clone and checkout still run, and the agent can fix or re-run\n * the setup itself. Keyed by the exact command, one entry per failed command, so an\n * edited setup command runs fresh. In-memory only — a server restart re-runs the (idempotent)\n * setup.\n */\nconst failedSetupCommands = new Map<string, Set<string>>();\n\nexport function recordFailedSetupCommand(sessionId: string, command: string): void {\n const failed = failedSetupCommands.get(sessionId) ?? new Set<string>();\n failed.add(command);\n failedSetupCommands.set(sessionId, failed);\n}\n\nexport function hasFailedSetupCommand(sessionId: string, command: string): boolean {\n return failedSetupCommands.get(sessionId)?.has(command) ?? false;\n}\n\n/** Forget a session's failed setup commands, so a replacement VM runs them again. */\nexport function clearFailedSetupCommands(sessionId: string): void {\n failedSetupCommands.delete(sessionId);\n}\n\n/**\n * The setup completion marker is a convention shared with the repo templates\n * (`@internal/workspace`): `.mastra-sandbox/setup` beside the checkout,\n * containing a digest of the setup commands. Templates write it as their last\n * build step, so a sandbox booted from a warm image already carries it; the\n * start hook writes it after a successful runtime setup. It is a skip cache,\n * not a correctness mechanism: the setup command is assumed idempotent, and a\n * missing or mismatched marker only re-runs it.\n *\n * The working directory is the parent of the repo dir, which is also the\n * template's build cwd, so this is the file the template's marker step wrote.\n */\nfunction markerShellPath(workdir: string): string {\n return `${path.posix.dirname(workdir)}/${SETUP_MARKER_PATH}`;\n}\n\nasync function markerMatches(sandbox: WorkspaceSandbox, workdir: string, content: string): Promise<boolean> {\n // The marker sits beside the checkout, not inside it, so it can outlive a\n // removed checkout (a wiped local session dir, a recovered VM). Trust it\n // only when the checkout it describes exists and it names this command.\n const marker = markerShellPath(workdir);\n const probe = await sandbox.executeCommand!(\n `test -d \"${workdir}/.git\" && test -f \"${marker}\" && [ \"$(cat \"${marker}\")\" = \"${content}\" ]`,\n );\n return probe.exitCode === 0;\n}\n\nasync function writeMarker(sandbox: WorkspaceSandbox, workdir: string, content: string): Promise<void> {\n // Best-effort: a missing marker only re-runs the idempotent setup later.\n const marker = markerShellPath(workdir);\n await sandbox.executeCommand!(`mkdir -p \"$(dirname \"${marker}\")\" && printf '%s' '${content}' > \"${marker}\"`).catch(\n () => {},\n );\n}\n\n/**\n * Build the session setup hook, which factory attaches to the constructed\n * sandbox with `setOnStart`. Runs inside the sandbox start lifecycle on\n * every start, fresh VM or reconnect: materialize and checkout always run,\n * and the setup command runs unless the sandbox already carries the marker\n * for it (a warm template image, or an earlier successful start). Throwing\n * fails `start()` loudly; core treats onStart errors as fatal.\n */\nexport function createSessionSetupHook(\n run: SessionSetupRun,\n sessionId: string,\n repoFullName: string,\n setupCommand: string | undefined,\n): SandboxStartHook {\n // No command, no marker: nothing to gate.\n const marker = setupCommand?.trim() ? setupMarkerContent(setupCommand) : undefined;\n return async ({ sandbox }) => {\n if (!sandbox.executeCommand) {\n throw new Error(`Sandbox '${sandbox.id}' cannot run the session setup: no executeCommand implementation`);\n }\n // Resolved from the live instance (the hook runs inside `start()`, so the\n // VM is up) and memoized on the session entry for passive readers.\n const workdir = await resolveSessionWorkdir(sessionId, sandbox, repoFullName);\n // Probed before materialize so a wiped checkout reads as \"not done\" even\n // though materialize is about to restore it.\n const setupDone = marker\n ? await timedPhase('workspace.setup-marker', () => markerMatches(sandbox, workdir, marker))\n : true;\n if (marker) {\n process.stderr.write(\n `[factory:setup] ${setupDone ? 'marker matches, skipping setup command' : 'no matching marker, setup command will run'} (${markerShellPath(workdir)})\\n`,\n );\n }\n await run(sandbox, workdir, {\n setupDone,\n markSetupDone: () => (marker ? writeMarker(sandbox, workdir, marker) : Promise.resolve()),\n });\n };\n}\n\n/**\n * Shell-quote one marker file's content. Marker contents are digests, but\n * the quoting keeps an edited command's digest from ever reaching the shell\n * unquoted.\n */\nfunction shellQuote(value: string): string {\n return `'${value.replace(/'/g, `'\\\\''`)}'`;\n}\n\n/**\n * The list-form marker probe: trust a repository's marker only when its\n * checkout exists, the marker names this command, and the template did not\n * record the repository in `setup-failed` (a failed per-repo setup still\n * writes the marker because every step ran; the failure list says it failed).\n */\nasync function repoMarkerMatches(\n sandbox: WorkspaceSandbox,\n root: string,\n repoDir: string,\n content: string,\n): Promise<boolean> {\n const marker = `${root}/${repoSetupMarkerPath(repoDir)}`;\n const failed = `${root}/${SETUP_FAILED_MARKER_PATH}`;\n const probe = await sandbox.executeCommand!(\n `test -d \"${root}/${repoDir}/.git\" && test -f \"${marker}\" && [ \"$(cat \"${marker}\")\" = ${shellQuote(content)} ] && ! grep -qxF -- ${shellQuote(repoDir)} \"${failed}\" 2>/dev/null`,\n );\n return probe.exitCode === 0;\n}\n\n/** Write a repository's marker and drop it from `setup-failed`. Best-effort, like `writeMarker`. */\nasync function writeRepoMarker(\n sandbox: WorkspaceSandbox,\n root: string,\n repoDir: string,\n content: string,\n): Promise<void> {\n const marker = `${root}/${repoSetupMarkerPath(repoDir)}`;\n const failed = `${root}/${SETUP_FAILED_MARKER_PATH}`;\n await sandbox.executeCommand!(\n `mkdir -p \"$(dirname \"${marker}\")\" && printf '%s' ${shellQuote(content)} > \"${marker}\" && { test -f \"${failed}\" && { grep -vxF -- ${shellQuote(repoDir)} \"${failed}\" > \"${failed}.tmp\" || true; } && mv \"${failed}.tmp\" \"${failed}\" || true; }`,\n ).catch(() => {});\n}\n\nasync function workspaceMarkerMatches(sandbox: WorkspaceSandbox, root: string, content: string): Promise<boolean> {\n const marker = `${root}/${WORKSPACE_SETUP_MARKER_PATH}`;\n const probe = await sandbox.executeCommand!(\n `test -f \"${marker}\" && [ \"$(cat \"${marker}\")\" = ${shellQuote(content)} ]`,\n );\n return probe.exitCode === 0;\n}\n\nasync function writeWorkspaceMarker(sandbox: WorkspaceSandbox, root: string, content: string): Promise<void> {\n const marker = `${root}/${WORKSPACE_SETUP_MARKER_PATH}`;\n await sandbox.executeCommand!(\n `mkdir -p \"$(dirname \"${marker}\")\" && printf '%s' ${shellQuote(content)} > \"${marker}\"`,\n ).catch(() => {});\n}\n\n/**\n * The list-form start hook for a session whose factory has an environment:\n * the same lifecycle as `createSessionSetupHook`, with one gate per\n * repository plus one for the workspace setup command. The markers are the\n * ones the multi-repo templates write (`.mastra-sandbox/repos/<repoDir>`,\n * `.mastra-sandbox/workspace-setup`, `.mastra-sandbox/setup-failed`), all\n * under the workspace root, which is the parent of the primary repository's\n * directory: `resolveSessionWorkdir` keeps answering that directory so the\n * PR tools and passive readers see the primary checkout, and the root is\n * derived from it rather than probed twice.\n *\n * `repos` is in position order and must include the primary (`repoFullName`).\n */\nexport function createEnvironmentSetupHook(\n run: SessionEnvironmentSetupRun,\n sessionId: string,\n repoFullName: string,\n environment: { repos: SessionEnvironmentRepository[]; workspaceSetupCommand?: string },\n): SandboxStartHook {\n const workspaceCommand = environment.workspaceSetupCommand?.trim() ? environment.workspaceSetupCommand : undefined;\n const workspaceMarker = workspaceCommand ? setupMarkerContent(workspaceCommand) : undefined;\n return async ({ sandbox }) => {\n if (!sandbox.executeCommand) {\n throw new Error(`Sandbox '${sandbox.id}' cannot run the session setup: no executeCommand implementation`);\n }\n const workdir = await resolveSessionWorkdir(sessionId, sandbox, repoFullName);\n const root = path.posix.dirname(workdir);\n const repos: SessionEnvironmentRepositoryGate[] = [];\n for (const repo of environment.repos) {\n const repoDir = repositoryDirectoryName(repo.slug);\n const marker = repo.setupCommand?.trim() ? setupMarkerContent(repo.setupCommand) : undefined;\n const setupDone = marker\n ? await timedPhase(`workspace.setup-marker(${repoDir})`, () =>\n repoMarkerMatches(sandbox, root, repoDir, marker),\n )\n : true;\n if (marker) {\n process.stderr.write(\n `[factory:setup] ${repo.slug}: ${setupDone ? 'marker matches, skipping setup command' : 'no matching marker, setup command will run'} (${root}/${repoSetupMarkerPath(repoDir)})\\n`,\n );\n }\n repos.push({\n ...repo,\n dir: `${root}/${repoDir}`,\n gate: {\n setupDone,\n markSetupDone: () => (marker ? writeRepoMarker(sandbox, root, repoDir, marker) : Promise.resolve()),\n },\n });\n }\n const workspaceDone = workspaceMarker\n ? await timedPhase('workspace.setup-marker(workspace)', () =>\n workspaceMarkerMatches(sandbox, root, workspaceMarker),\n )\n : true;\n await run(sandbox, {\n root,\n repos,\n workspace: {\n setupDone: workspaceDone,\n markSetupDone: () =>\n workspaceMarker ? writeWorkspaceMarker(sandbox, root, workspaceMarker) : Promise.resolve(),\n },\n });\n };\n}\n"],"mappings":";;;;;AAyIA,MAAM,mCAAmB,IAAI,IAAiC;;AAuB9D,SAAgB,cAAc,OAAmE;CAC/F,IAAI,CAAC,OAAO,SAAS,OAAO,KAAA;CAC5B,MAAM,QAAQ,MAAM,OAAO,SAAS,MAAM,QAAQ,CAAC,MAAM,OAAO;CAChE,IAAI,MAAM,WAAW,GACnB,OAAO;EAAE,MAAM,MAAM;EAAS,OAAO,CAAC;GAAE,MAAM,MAAM;GAAK,KAAK,MAAM;GAAS,QAAQ;EAAG,CAAC;CAAE;CAE7F,MAAM,OAAO,KAAK,MAAM,QAAQ,MAAM,OAAO;CAC7C,OAAO;EACL;EACA,OAAO,MAAM,KAAI,SAAQ;GACvB,MAAM,MAAM,KAAK,YAAY,MAAM,MAAM,QAAQ,YAAY,IAAI,MAAM,UAAW,aAAa,MAAM,IAAI;GACzG,OAAO;IAAE;IAAM;IAAK,QAAQ,GAAG,KAAK,MA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C,IAAI,KAAK,GAAG,oBAAoB,OAAO,EAAE,IAChL;GAEF,MAAM,KAAK;IACT,GAAG;IACH,KAAK,GAAG,KAAK,GAAG;IAChB,MAAM;KACJ;KACA,qBAAsB,SAAS,gBAAgB,SAAS,MAAM,SAAS,MAAM,IAAI,QAAQ,QAAQ;IACnG;GACF,CAAC;EACH;EAMA,MAAM,IAAI,SAAS;GACjB;GACA;GACA,WAAW;IACT,WATkB,kBAClB,MAAM,WAAW,2CACf,uBAAuB,SAAS,MAAM,eAAe,CACvD,IACA;IAMA,qBACE,kBAAkB,qBAAqB,SAAS,MAAM,eAAe,IAAI,QAAQ,QAAQ;GAC7F;EACF,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"session-sandbox.js","names":[],"sources":["../../src/sandbox/session-sandbox.ts"],"sourcesContent":["import path from 'node:path';\nimport {\n SETUP_FAILED_MARKER_PATH,\n SETUP_MARKER_PATH,\n WORKSPACE_SETUP_MARKER_PATH,\n repoSetupMarkerPath,\n setupMarkerContent,\n} from '@internal/workspace';\n\nimport type {\n FactorySandbox,\n FactorySandboxContext as CoreFactorySandboxContext,\n MastraSandbox,\n SandboxStartHook,\n WorkspaceSandbox,\n} from '@mastra/core/workspace';\nimport { timedPhase } from '../timing.js';\nimport { deriveLocalWorkdir, deriveRemoteRepoDir, repoDirUnder, repositoryDirectoryName } from './workdir.js';\n\n/**\n * Everything factory knows about a session's sandbox needs: the whole contract\n * between factory and the host's FactorySandbox. Factory owns intent; the\n * provider owns resolving `sessionId` to a runnable VM. Defined in\n * `@mastra/core/workspace` so provider packages can implement it without\n * depending on factory.\n */\nexport type FactorySandboxContext = CoreFactorySandboxContext;\n\n/**\n * The deploy's sandbox configuration: construct a session's sandbox from\n * intent. The sandbox identity is the session id; the provider must honor\n * id-keyed getOrCreate on `start()` (reconnect/resume an existing VM for the\n * id, create otherwise). Construction must be cheap and side-effect-free —\n * VMs are provisioned on `start()` only. Local sandboxes should root their\n * `workingDirectory` at a per-session directory (e.g.\n * `join(root, ctx.sessionId)`); the repo checks out as a subdirectory of it.\n *\n * Forward `ctx.sandboxId` to providers that reattach by physical id so resume\n * reattaches the original VM instead of provisioning a replacement.\n *\n * Returns a `MastraSandbox`, not the bare `WorkspaceSandbox` interface:\n * factory relies on the base class for the start lifecycle and the runtime\n * env, so providers extend it rather than reimplementing the contract.\n *\n * Factory attaches its own session setup to the returned sandbox, so the\n * callback never has to wire it up. A callback may still pass its own\n * `onStart`; it runs after factory's setup, against a prepared workspace.\n *\n * @example\n * ```typescript\n * sandbox: ({ sessionId, sandboxId }) => new E2BSandbox({ id: sessionId, sandboxId })\n * ```\n *\n * A FactorySandbox instance (for example `new E2BFactorySandbox({ apiKey })`)\n * additionally exposes settings and template builds to the environment.\n */\nexport type MastraFactorySandboxConfig = (ctx: FactorySandboxContext) => MastraSandbox;\n\n/**\n * The `sandbox` option of `MastraFactoryConfig`: a FactorySandbox instance\n * (it owns the session sandbox constructor, the repo template and the\n * environment settings schema) or a bare callback, which the factory wraps as a `provider: 'custom'` sandbox with no settings.\n */\nexport type MastraFactorySandboxOption = FactorySandbox | MastraFactorySandboxConfig;\n\n/**\n * What the start hook learned about the setup command before running the\n * session setup, and how to record its completion afterwards.\n */\nexport interface SessionSetupGate {\n /** True when the sandbox already carries a marker for the current setup command. */\n setupDone: boolean;\n /** Write the marker once the setup command succeeded. Best-effort. */\n markSetupDone: () => Promise<void>;\n}\n\n/**\n * The session's setup work, run against a started sandbox on EVERY start.\n * Materialize and checkout are idempotent and must always run (a warm boot\n * still needs its pull); only the setup command consults `gate`.\n */\nexport type SessionSetupRun = (sandbox: WorkspaceSandbox, workdir: string, gate: SessionSetupGate) => Promise<void>;\n\n/** One environment repository as the boot hook needs it: its slug and setup command. */\nexport interface SessionEnvironmentRepository {\n slug: string;\n setupCommand?: string;\n}\n\n/** What the environment hook learned about one repository before the boot runs. */\nexport interface SessionEnvironmentRepositoryGate extends SessionEnvironmentRepository {\n /** `<root>/<repoDir>`, the directory the template cloned this repository into. */\n dir: string;\n gate: SessionSetupGate;\n}\n\n/** The environment hook's view of the workspace: the root, every repository in position order, the workspace gate. */\nexport interface SessionEnvironmentGate {\n /** The workspace root, parent of every repository directory. */\n root: string;\n repos: SessionEnvironmentRepositoryGate[];\n /** Gate for `workspaceSetupCommand`; `setupDone` when there is no command or its marker matches. */\n workspace: SessionSetupGate;\n}\n\n/** The list-form session boot: run on every start, like `SessionSetupRun`. */\nexport type SessionEnvironmentSetupRun = (\n sandbox: WorkspaceSandbox,\n environment: SessionEnvironmentGate,\n) => Promise<void>;\n\n/**\n * Per-process session-id → sandbox instance memo.\n *\n * The provider contract is id-keyed getOrCreate, but provider find-then-create\n * has a real double-create race across independent instances. Memoizing the\n * instance per session makes the base class's per-instance start coalescing\n * apply process-wide per session — the same single-flight scope the fleet's\n * per-binding coalescing provided. Cross-replica races are accepted (the\n * fleet was also per-replica).\n */\ninterface SessionSandboxEntry {\n sandbox: WorkspaceSandbox;\n /**\n * The session's repo checkout root, recorded for passive readers (fs\n * routes, capture, authz). Local sandboxes derive it at construction;\n * remote sandboxes clone into the VM's own home, so it is undefined until\n * `resolveSessionWorkdir` probes the first started VM — passive readers\n * treat an unresolved workdir as \"nothing materialized\".\n */\n workdir?: string;\n /** The session's own repository, the only one `workdir` is ever recorded for. */\n ownRepo: string;\n /** Environment repositories in position order; the session's own repository is among them. */\n repos?: string[];\n}\n\nconst sessionSandboxes = new Map<string, SessionSandboxEntry>();\n\n/** One environment repository as the file readers see it. */\nexport interface SessionLayoutRepository {\n slug: string;\n /** Absolute checkout directory. */\n dir: string;\n /** Path prefix of this checkout under the layout root: empty for a single-repository session, `<dir>/` otherwise. */\n prefix: string;\n}\n\n/**\n * Where a session's files are read from. A session with one repository is\n * rooted at that checkout, as before environments existed; a session with\n * several is rooted at the workspace root with each checkout as a directory\n * beneath it.\n */\nexport interface SessionLayout {\n root: string;\n repos: SessionLayoutRepository[];\n}\n\n/** The layout of a memoized session, `undefined` until its workdir resolved. */\nexport function sessionLayout(entry: SessionSandboxEntry | undefined): SessionLayout | undefined {\n if (!entry?.workdir) return undefined;\n const slugs = entry.repos?.length ? entry.repos : [entry.ownRepo];\n if (slugs.length === 1) {\n return { root: entry.workdir, repos: [{ slug: slugs[0]!, dir: entry.workdir, prefix: '' }] };\n }\n const root = path.posix.dirname(entry.workdir);\n return {\n root,\n repos: slugs.map(slug => {\n const dir = slug.toLowerCase() === entry.ownRepo.toLowerCase() ? entry.workdir! : repoDirUnder(root, slug);\n return { slug, dir, prefix: `${path.posix.basename(dir)}/` };\n }),\n };\n}\n\n/**\n * Get the session's memoized sandbox entry, constructing (and memoizing) it on\n * first access. Construction is cheap and side-effect-free by contract; VMs\n * are provisioned on `start()` only. Local sandboxes get their workdir here;\n * remote workdirs are a runtime fact of the VM, resolved on first start.\n */\nexport function getSessionSandbox(\n sessionId: string,\n repoFullName: string,\n construct: () => WorkspaceSandbox,\n repos?: string[],\n): SessionSandboxEntry {\n const existing = sessionSandboxes.get(sessionId);\n if (existing) {\n // The environment can change between boots; the layout follows the latest.\n if (repos) existing.repos = repos;\n return existing;\n }\n const sandbox = construct();\n const local = deriveLocalWorkdir(sandbox, repoFullName);\n const entry: SessionSandboxEntry = {\n sandbox,\n ownRepo: repoFullName,\n ...(local ? { workdir: local } : {}),\n ...(repos ? { repos } : {}),\n };\n sessionSandboxes.set(sessionId, entry);\n return entry;\n}\n\n/**\n * Resolve (and memoize on the session entry) the session's repo checkout\n * root. Local sandboxes answer synchronously from their configured\n * `workingDirectory`; remote sandboxes clone into the VM's own default cwd,\n * so the first resolution probes it with one `pwd` — the VM tells us where\n * home is, we never invent a path. Calling this against a stopped sandbox\n * lazily starts it (the probe is a command), so passive readers must peek\n * `entry.workdir` instead. The memo is the session's own checkout; another\n * environment repository lives beside it under the same root, so it is\n * answered from the memo's parent without a second probe.\n */\nexport async function resolveSessionWorkdir(\n sessionId: string,\n sandbox: WorkspaceSandbox,\n repoFullName: string,\n): Promise<string> {\n const entry = sessionSandboxes.get(sessionId);\n const memo = entry && entry.sandbox === sandbox ? entry : undefined;\n if (memo && memo.ownRepo !== repoFullName) {\n // Passive readers take `workdir` as the session's own checkout, so a\n // sibling never lands in the memo: resolve the own checkout (cold memo\n // included) and answer the sibling beside it.\n const own = await resolveSessionWorkdir(sessionId, sandbox, memo.ownRepo);\n return repoDirUnder(path.posix.dirname(own), repoFullName);\n }\n if (memo?.workdir) return memo.workdir;\n const workdir =\n deriveLocalWorkdir(sandbox, repoFullName) ??\n deriveRemoteRepoDir(sandbox, repoFullName) ??\n repoDirUnder(await probeHome(sandbox), repoFullName);\n if (memo) memo.workdir = workdir;\n return workdir;\n}\n\n/** One `pwd` in the VM's default shell cwd — its home dir, by provider convention. */\nasync function probeHome(sandbox: WorkspaceSandbox): Promise<string> {\n if (!sandbox.executeCommand) {\n throw new Error(`Sandbox '${sandbox.id}' cannot resolve its workdir: no executeCommand implementation`);\n }\n const probe = await sandbox.executeCommand('pwd');\n const home = probe.stdout.trim().split('\\n').pop()?.trim() ?? '';\n if (probe.exitCode !== 0 || !home.startsWith('/')) {\n throw new Error(\n `Sandbox '${sandbox.id}' default cwd probe failed (exit ${probe.exitCode}): ${\n probe.stderr.trim() || probe.stdout.trim() || 'empty output'\n }`,\n );\n }\n return home;\n}\n\n/**\n * The session's memoized sandbox (and its workdir) when one was already\n * constructed in this process, else undefined. Never constructs — passive\n * read paths use this so browsing files cannot provision a VM.\n */\nexport function peekSessionSandbox(sessionId: string): SessionSandboxEntry | undefined {\n return sessionSandboxes.get(sessionId);\n}\n\n/** Drop the memoized instance (on stop/destroy/retirement or construction failure). */\nexport function evictSessionSandbox(sessionId: string): void {\n sessionSandboxes.delete(sessionId);\n failedSetupCommands.delete(sessionId);\n}\n\n/** How many of this process's session sandboxes are running. */\nexport function countRunningSessionSandboxes(): number {\n let running = 0;\n for (const entry of sessionSandboxes.values()) if (entry.sandbox.status === 'running') running++;\n return running;\n}\n\n/** Test-only: reset the process-wide memo between tests. */\nexport function __clearSessionSandboxesForTests(): void {\n sessionSandboxes.clear();\n failedSetupCommands.clear();\n}\n\n/**\n * Setup commands that already failed once for a session. The first failure\n * fails the start loudly — the agent sees the real error in the tool result\n * that triggered it. Recording it lets the next start skip the known-bad\n * command instead of wedging the session behind a permanently failing\n * onStart: clone and checkout still run, and the agent can fix or re-run\n * the setup itself. Keyed by the exact command, one entry per failed command, so an\n * edited setup command runs fresh. In-memory only — a server restart re-runs the (idempotent)\n * setup.\n */\nconst failedSetupCommands = new Map<string, Set<string>>();\n\nexport function recordFailedSetupCommand(sessionId: string, command: string): void {\n const failed = failedSetupCommands.get(sessionId) ?? new Set<string>();\n failed.add(command);\n failedSetupCommands.set(sessionId, failed);\n}\n\nexport function hasFailedSetupCommand(sessionId: string, command: string): boolean {\n return failedSetupCommands.get(sessionId)?.has(command) ?? false;\n}\n\n/** Forget a session's failed setup commands, so a replacement VM runs them again. */\nexport function clearFailedSetupCommands(sessionId: string): void {\n failedSetupCommands.delete(sessionId);\n}\n\n/**\n * The setup completion marker is a convention shared with the repo templates\n * (`@internal/workspace`): `.mastra-sandbox/setup` beside the checkout,\n * containing a digest of the setup commands. Templates write it as their last\n * build step, so a sandbox booted from a warm image already carries it; the\n * start hook writes it after a successful runtime setup. It is a skip cache,\n * not a correctness mechanism: the setup command is assumed idempotent, and a\n * missing or mismatched marker only re-runs it.\n *\n * The working directory is the parent of the repo dir, which is also the\n * template's build cwd, so this is the file the template's marker step wrote.\n */\nfunction markerShellPath(workdir: string): string {\n return `${path.posix.dirname(workdir)}/${SETUP_MARKER_PATH}`;\n}\n\nasync function markerMatches(sandbox: WorkspaceSandbox, workdir: string, content: string): Promise<boolean> {\n // The marker sits beside the checkout, not inside it, so it can outlive a\n // removed checkout (a wiped local session dir, a recovered VM). Trust it\n // only when the checkout it describes exists and it names this command.\n const marker = markerShellPath(workdir);\n const probe = await sandbox.executeCommand!(\n `test -d \"${workdir}/.git\" && test -f \"${marker}\" && [ \"$(cat \"${marker}\")\" = \"${content}\" ]`,\n );\n return probe.exitCode === 0;\n}\n\nasync function writeMarker(sandbox: WorkspaceSandbox, workdir: string, content: string): Promise<void> {\n // Best-effort: a missing marker only re-runs the idempotent setup later.\n const marker = markerShellPath(workdir);\n await sandbox.executeCommand!(`mkdir -p \"$(dirname \"${marker}\")\" && printf '%s' '${content}' > \"${marker}\"`).catch(\n () => {},\n );\n}\n\n/**\n * Build the session setup hook, which factory attaches to the constructed\n * sandbox with `setOnStart`. Runs inside the sandbox start lifecycle on\n * every start, fresh VM or reconnect: materialize and checkout always run,\n * and the setup command runs unless the sandbox already carries the marker\n * for it (a warm template image, or an earlier successful start). Throwing\n * fails `start()` loudly; core treats onStart errors as fatal.\n */\nexport function createSessionSetupHook(\n run: SessionSetupRun,\n sessionId: string,\n repoFullName: string,\n setupCommand: string | undefined,\n): SandboxStartHook {\n // No command, no marker: nothing to gate.\n const marker = setupCommand?.trim() ? setupMarkerContent(setupCommand) : undefined;\n return async ({ sandbox }) => {\n if (!sandbox.executeCommand) {\n throw new Error(`Sandbox '${sandbox.id}' cannot run the session setup: no executeCommand implementation`);\n }\n // Resolved from the live instance (the hook runs inside `start()`, so the\n // VM is up) and memoized on the session entry for passive readers.\n const workdir = await resolveSessionWorkdir(sessionId, sandbox, repoFullName);\n // Probed before materialize so a wiped checkout reads as \"not done\" even\n // though materialize is about to restore it.\n const setupDone = marker\n ? await timedPhase('workspace.setup-marker', () => markerMatches(sandbox, workdir, marker))\n : true;\n if (marker) {\n process.stderr.write(\n `[factory:setup] ${setupDone ? 'marker matches, skipping setup command' : 'no matching marker, setup command will run'} (${markerShellPath(workdir)})\\n`,\n );\n }\n await run(sandbox, workdir, {\n setupDone,\n markSetupDone: () => (marker ? writeMarker(sandbox, workdir, marker) : Promise.resolve()),\n });\n };\n}\n\n/**\n * Shell-quote one marker file's content. Marker contents are digests, but\n * the quoting keeps an edited command's digest from ever reaching the shell\n * unquoted.\n */\nfunction shellQuote(value: string): string {\n return `'${value.replace(/'/g, `'\\\\''`)}'`;\n}\n\n/**\n * The list-form marker probe: trust a repository's marker only when its\n * checkout exists, the marker names this command, and the template did not\n * record the repository in `setup-failed` (a failed per-repo setup still\n * writes the marker because every step ran; the failure list says it failed).\n */\nasync function repoMarkerMatches(\n sandbox: WorkspaceSandbox,\n root: string,\n repoDir: string,\n content: string,\n): Promise<boolean> {\n const marker = `${root}/${repoSetupMarkerPath(repoDir)}`;\n const failed = `${root}/${SETUP_FAILED_MARKER_PATH}`;\n const probe = await sandbox.executeCommand!(\n `test -d \"${root}/${repoDir}/.git\" && test -f \"${marker}\" && [ \"$(cat \"${marker}\")\" = ${shellQuote(content)} ] && ! grep -qxF -- ${shellQuote(repoDir)} \"${failed}\" 2>/dev/null`,\n );\n return probe.exitCode === 0;\n}\n\n/** Write a repository's marker and drop it from `setup-failed`. Best-effort, like `writeMarker`. */\nasync function writeRepoMarker(\n sandbox: WorkspaceSandbox,\n root: string,\n repoDir: string,\n content: string,\n): Promise<void> {\n const marker = `${root}/${repoSetupMarkerPath(repoDir)}`;\n const failed = `${root}/${SETUP_FAILED_MARKER_PATH}`;\n await sandbox.executeCommand!(\n `mkdir -p \"$(dirname \"${marker}\")\" && printf '%s' ${shellQuote(content)} > \"${marker}\" && { test -f \"${failed}\" && { grep -vxF -- ${shellQuote(repoDir)} \"${failed}\" > \"${failed}.tmp\" || true; } && mv \"${failed}.tmp\" \"${failed}\" || true; }`,\n ).catch(() => {});\n}\n\nasync function workspaceMarkerMatches(sandbox: WorkspaceSandbox, root: string, content: string): Promise<boolean> {\n const marker = `${root}/${WORKSPACE_SETUP_MARKER_PATH}`;\n const probe = await sandbox.executeCommand!(\n `test -f \"${marker}\" && [ \"$(cat \"${marker}\")\" = ${shellQuote(content)} ]`,\n );\n return probe.exitCode === 0;\n}\n\nasync function writeWorkspaceMarker(sandbox: WorkspaceSandbox, root: string, content: string): Promise<void> {\n const marker = `${root}/${WORKSPACE_SETUP_MARKER_PATH}`;\n await sandbox.executeCommand!(\n `mkdir -p \"$(dirname \"${marker}\")\" && printf '%s' ${shellQuote(content)} > \"${marker}\"`,\n ).catch(() => {});\n}\n\n/**\n * The list-form start hook for a session whose factory has an environment:\n * the same lifecycle as `createSessionSetupHook`, with one gate per\n * repository plus one for the workspace setup command. The markers are the\n * ones the multi-repo templates write (`.mastra-sandbox/repos/<repoDir>`,\n * `.mastra-sandbox/workspace-setup`, `.mastra-sandbox/setup-failed`), all\n * under the workspace root, which is the parent of the primary repository's\n * directory: `resolveSessionWorkdir` keeps answering that directory so the\n * PR tools and passive readers see the primary checkout, and the root is\n * derived from it rather than probed twice.\n *\n * `repos` is in position order and must include the primary (`repoFullName`).\n */\nexport function createEnvironmentSetupHook(\n run: SessionEnvironmentSetupRun,\n sessionId: string,\n repoFullName: string,\n environment: { repos: SessionEnvironmentRepository[]; workspaceSetupCommand?: string },\n): SandboxStartHook {\n const workspaceCommand = environment.workspaceSetupCommand?.trim() ? environment.workspaceSetupCommand : undefined;\n const workspaceMarker = workspaceCommand ? setupMarkerContent(workspaceCommand) : undefined;\n return async ({ sandbox }) => {\n if (!sandbox.executeCommand) {\n throw new Error(`Sandbox '${sandbox.id}' cannot run the session setup: no executeCommand implementation`);\n }\n const workdir = await resolveSessionWorkdir(sessionId, sandbox, repoFullName);\n const root = path.posix.dirname(workdir);\n const repos: SessionEnvironmentRepositoryGate[] = [];\n for (const repo of environment.repos) {\n const repoDir = repositoryDirectoryName(repo.slug);\n const marker = repo.setupCommand?.trim() ? setupMarkerContent(repo.setupCommand) : undefined;\n const setupDone = marker\n ? await timedPhase(`workspace.setup-marker(${repoDir})`, () =>\n repoMarkerMatches(sandbox, root, repoDir, marker),\n )\n : true;\n if (marker) {\n process.stderr.write(\n `[factory:setup] ${repo.slug}: ${setupDone ? 'marker matches, skipping setup command' : 'no matching marker, setup command will run'} (${root}/${repoSetupMarkerPath(repoDir)})\\n`,\n );\n }\n repos.push({\n ...repo,\n dir: `${root}/${repoDir}`,\n gate: {\n setupDone,\n markSetupDone: () => (marker ? writeRepoMarker(sandbox, root, repoDir, marker) : Promise.resolve()),\n },\n });\n }\n const workspaceDone = workspaceMarker\n ? await timedPhase('workspace.setup-marker(workspace)', () =>\n workspaceMarkerMatches(sandbox, root, workspaceMarker),\n )\n : true;\n await run(sandbox, {\n root,\n repos,\n workspace: {\n setupDone: workspaceDone,\n markSetupDone: () =>\n workspaceMarker ? writeWorkspaceMarker(sandbox, root, workspaceMarker) : Promise.resolve(),\n },\n });\n };\n}\n"],"mappings":";;;;;AAyIA,MAAM,mCAAmB,IAAI,IAAiC;;AAuB9D,SAAgB,cAAc,OAAmE;CAC/F,IAAI,CAAC,OAAO,SAAS,OAAO,KAAA;CAC5B,MAAM,QAAQ,MAAM,OAAO,SAAS,MAAM,QAAQ,CAAC,MAAM,OAAO;CAChE,IAAI,MAAM,WAAW,GACnB,OAAO;EAAE,MAAM,MAAM;EAAS,OAAO,CAAC;GAAE,MAAM,MAAM;GAAK,KAAK,MAAM;GAAS,QAAQ;EAAG,CAAC;CAAE;CAE7F,MAAM,OAAO,KAAK,MAAM,QAAQ,MAAM,OAAO;CAC7C,OAAO;EACL;EACA,OAAO,MAAM,KAAI,SAAQ;GACvB,MAAM,MAAM,KAAK,YAAY,MAAM,MAAM,QAAQ,YAAY,IAAI,MAAM,UAAW,aAAa,MAAM,IAAI;GACzG,OAAO;IAAE;IAAM;IAAK,QAAQ,GAAG,KAAK,MAAM,SAAS,GAAG,EAAE;GAAG;EAC7D,CAAC;CACH;AACF;;;;;;;AAQA,SAAgB,kBACd,WACA,cACA,WACA,OACqB;CACrB,MAAM,WAAW,iBAAiB,IAAI,SAAS;CAC/C,IAAI,UAAU;EAEZ,IAAI,OAAO,SAAS,QAAQ;EAC5B,OAAO;CACT;CACA,MAAM,UAAU,UAAU;CAC1B,MAAM,QAAQ,mBAAmB,SAAS,YAAY;CACtD,MAAM,QAA6B;EACjC;EACA,SAAS;EACT,GAAI,QAAQ,EAAE,SAAS,MAAM,IAAI,CAAC;EAClC,GAAI,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,SAAS;GACjB;GACA;GACA,WAAW;IACT,WATkB,kBAClB,MAAM,WAAW,2CACf,uBAAuB,SAAS,MAAM,eAAe,CACvD,IACA;IAMA,qBACE,kBAAkB,qBAAqB,SAAS,MAAM,eAAe,IAAI,QAAQ,QAAQ;GAC7F;EACF,CAAC;CACH;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/boards/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,sFAAsF;AACtF,eAAO,MAAM,qBAAqB,EAAE,gBAmBnC,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,2BAA2B,EAAE,gBA4BzC,CAAC;AAEF,yFAAyF;AACzF,eAAO,MAAM,4BAA4B,EAAE,gBAgC1C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,EAAE,gBAY/C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,wCAAwC,EAAE,gBAgBtD,CAAC"}
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/boards/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,sFAAsF;AACtF,eAAO,MAAM,qBAAqB,EAAE,gBAmBnC,CAAC;AAEF,0EAA0E;AAC1E,eAAO,MAAM,2BAA2B,EAAE,gBA4BzC,CAAC;AAEF,yFAAyF;AACzF,eAAO,MAAM,4BAA4B,EAAE,gBA8B1C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,EAAE,gBAY/C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,wCAAwC,EAAE,gBAgBtD,CAAC"}
@@ -113,10 +113,6 @@ const FACTORY_INTAKE_ROUTES_SCHEMA = {
113
113
  type: "json",
114
114
  nullable: true
115
115
  },
116
- allow_working_phase: {
117
- type: "boolean",
118
- nullable: true
119
- },
120
116
  join_closed_issue: {
121
117
  type: "boolean",
122
118
  nullable: true
@@ -1 +1 @@
1
- {"version":3,"file":"schemas.js","names":[],"sources":["../../../../src/storage/domains/boards/schemas.ts"],"sourcesContent":["import type { CollectionSchema } from '@mastra/core/storage';\n\n/** A project's boards. `board_key` is the id cards reference (`work_items.board`). */\nexport const FACTORY_BOARDS_SCHEMA: CollectionSchema = {\n name: 'factory_boards',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n board_key: { type: 'text' },\n name: { type: 'text' },\n description: { type: 'text', nullable: true },\n position: { type: 'integer' },\n // Rises on every write to the board or its phases; the compare-and-set token for edits.\n revision: { type: 'integer' },\n created_by: { type: 'text' },\n created_at: { type: 'timestamp' },\n updated_by: { type: 'text' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [{ name: 'factory_boards_project_key', columns: ['org_id', 'factory_project_id', 'board_key'] }],\n indexes: [{ name: 'factory_boards_project', columns: ['org_id', 'factory_project_id'] }],\n};\n\n/** A board's ordered phases. `phase_key` is the stage id cards sit in. */\nexport const FACTORY_BOARD_PHASES_SCHEMA: CollectionSchema = {\n name: 'factory_board_phases',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n board_key: { type: 'text' },\n phase_key: { type: 'text' },\n position: { type: 'integer' },\n name: { type: 'text' },\n description: { type: 'text', nullable: true },\n kind: { type: 'text' },\n // { skill?, context?, instructions? }; room for other runner types later.\n runner: { type: 'json', nullable: true },\n next_phases: { type: 'json', nullable: true },\n auto_start: { type: 'boolean', default: false },\n auto_start_when: { type: 'json', nullable: true },\n exit_tool: { type: 'json', nullable: true },\n // Factory tools the phase grants the session working the card there, e.g. [\"factory_record_review_verdict\"].\n tools: { type: 'json', nullable: true },\n },\n uniqueIndexes: [\n {\n name: 'factory_board_phases_project_board_phase',\n columns: ['org_id', 'factory_project_id', 'board_key', 'phase_key'],\n },\n ],\n indexes: [{ name: 'factory_board_phases_project', columns: ['org_id', 'factory_project_id'] }],\n};\n\n/** A project's ordered intake routes: where new cards matching `when_condition` land. */\nexport const FACTORY_INTAKE_ROUTES_SCHEMA: CollectionSchema = {\n name: 'factory_intake_routes',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n name: { type: 'text' },\n enabled: { type: 'boolean', default: true },\n position: { type: 'integer' },\n // A card RuleGroup; null matches every card. Not named `when`, which is an SQL keyword.\n when_condition: { type: 'json', nullable: true },\n board_key: { type: 'text' },\n // Null lands the card in the board's first phase.\n phase_key: { type: 'text', nullable: true },\n // The status events the route handles (`StatusEvent`s). Null on rows written before routes named\n // events: those place new cards, as `['work_item.created']`.\n on_events: { type: 'json', nullable: true },\n // No longer read or written: a route moves a card into any phase. Kept so existing tables match.\n allow_working_phase: { type: 'boolean', nullable: true },\n // True files a pull request on the card of the issue it closes instead of a new card. Null on rows written before it.\n join_closed_issue: { type: 'boolean', nullable: true },\n // Rises on every write to the route, including a move; the compare-and-set token for edits.\n revision: { type: 'integer' },\n created_by: { type: 'text' },\n created_at: { type: 'timestamp' },\n updated_by: { type: 'text' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n { name: 'factory_intake_routes_project_position', columns: ['org_id', 'factory_project_id', 'position'] },\n ],\n indexes: [{ name: 'factory_intake_routes_project', columns: ['org_id', 'factory_project_id'] }],\n};\n\n/**\n * One row per project that every write adding, deleting or moving intake routes upserts first,\n * inside its transaction. The upsert holds the row until commit, so those writes on one project\n * run one after another and positions stay 0..n-1 with no gaps.\n */\nexport const FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA: CollectionSchema = {\n name: 'factory_intake_route_locks',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n locked_at: { type: 'timestamp' },\n // Keys of the default routes Factory added to the project (`DEFAULT_INTAKE_ROUTES`), so each is\n // added once. Null on rows written before the list: those projects got `outside-authors`.\n seeded_defaults: { type: 'json', nullable: true },\n },\n uniqueIndexes: [{ name: 'factory_intake_route_locks_project', columns: ['org_id', 'factory_project_id'] }],\n};\n\n/**\n * One row per project whose `version` is replaced inside every board write, so other replicas\n * can tell their cached boards are stale with one indexed read.\n */\nexport const FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA: CollectionSchema = {\n name: 'factory_board_definition_versions',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n version: { type: 'text' },\n updated_at: { type: 'timestamp' },\n // Keys of the boards Factory stored in the project (Work, app and seed boards); each is stored\n // once, so one the project deleted stays deleted. Null on projects stored before the list.\n seeded_boards: { type: 'json', nullable: true },\n // Keys of the board migrations applied to the project, so each runs once: a field a user\n // later sets back to an old default is never rewritten again. Null before the first one.\n applied_migrations: { type: 'json', nullable: true },\n },\n uniqueIndexes: [{ name: 'factory_board_definition_versions_project', columns: ['org_id', 'factory_project_id'] }],\n};\n"],"mappings":";;AAGA,MAAa,wBAA0C;CACrD,MAAM;CACN,SAAS;EACP,IAAI,EAAE,MAAM,UAAU;EACtB,QAAQ,EAAE,MAAM,OAAO;EACvB,oBAAoB,EAAE,MAAM,OAAO;EACnC,WAAW,EAAE,MAAM,OAAO;EAC1B,MAAM,EAAE,MAAM,OAAO;EACrB,aAAa;GAAE,MAAM;GAAQ,UAAU;EAAK;EAC5C,UAAU,EAAE,MAAM,UAAU;EAE5B,UAAU,EAAE,MAAM,UAAU;EAC5B,YAAY,EAAE,MAAM,OAAO;EAC3B,YAAY,EAAE,MAAM,YAAY;EAChC,YAAY,EAAE,MAAM,OAAO;EAC3B,YAAY,EAAE,MAAM,YAAY;CAClC;CACA,eAAe,CAAC;EAAE,MAAM;EAA8B,SAAS;GAAC;GAAU;GAAsB;EAAW;CAAE,CAAC;CAC9G,SAAS,CAAC;EAAE,MAAM;EAA0B,SAAS,CAAC,UAAU,o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GAAW,UAAU;EAAK;EAEvD,mBAAmB;GAAE,MAAM;GAAW,UAAU;EAAK;EAErD,UAAU,EAAE,MAAM,UAAU;EAC5B,YAAY,EAAE,MAAM,OAAO;EAC3B,YAAY,EAAE,MAAM,YAAY;EAChC,YAAY,EAAE,MAAM,OAAO;EAC3B,YAAY,EAAE,MAAM,YAAY;CAClC;CACA,eAAe,CACb;EAAE,MAAM;EAA0C,SAAS;GAAC;GAAU;GAAsB;EAAU;CAAE,CAC1G;CACA,SAAS,CAAC;EAAE,MAAM;EAAiC,SAAS,CAAC,UAAU,oBAAoB;CAAE,CAAC;AAChG;;;;;;AAOA,MAAa,oCAAsD;CACjE,MAAM;CACN,SAAS;EACP,IAAI,EAAE,MAAM,UAAU;EACtB,QAAQ,EAAE,MAAM,OAAO;EACvB,oBAAoB,EAAE,MAAM,OAAO;EACnC,WAAW,EAAE,MAAM,YAAY;EAG/B,iBAAiB;GAAE,MAAM;GAAQ,UAAU;EAAK;CAClD;CACA,eAAe,CAAC;EAAE,MAAM;EAAsC,SAAS,CAAC,UAAU,oBAAoB;CAAE,CAAC;AAC3G;;;;;AAMA,MAAa,2CAA6D;CACxE,MAAM;CACN,SAAS;EACP,IAAI,EAAE,MAAM,UAAU;EACtB,QAAQ,EAAE,MAAM,OAAO;EACvB,oBAAoB,EAAE,MAAM,OAAO;EACnC,SAAS,EAAE,MAAM,OAAO;EACxB,YAAY,EAAE,MAAM,YAAY;EAGhC,eAAe;GAAE,MAAM;GAAQ,UAAU;EAAK;EAG9C,oBAAoB;GAAE,MAAM;GAAQ,UAAU;EAAK;CACrD;CACA,eAAe,CAAC;EAAE,MAAM;EAA6C,SAAS,CAAC,UAAU,oBAAoB;CAAE,CAAC;AAClH"}
1
+ {"version":3,"file":"schemas.js","names":[],"sources":["../../../../src/storage/domains/boards/schemas.ts"],"sourcesContent":["import type { CollectionSchema } from '@mastra/core/storage';\n\n/** A project's boards. `board_key` is the id cards reference (`work_items.board`). */\nexport const FACTORY_BOARDS_SCHEMA: CollectionSchema = {\n name: 'factory_boards',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n board_key: { type: 'text' },\n name: { type: 'text' },\n description: { type: 'text', nullable: true },\n position: { type: 'integer' },\n // Rises on every write to the board or its phases; the compare-and-set token for edits.\n revision: { type: 'integer' },\n created_by: { type: 'text' },\n created_at: { type: 'timestamp' },\n updated_by: { type: 'text' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [{ name: 'factory_boards_project_key', columns: ['org_id', 'factory_project_id', 'board_key'] }],\n indexes: [{ name: 'factory_boards_project', columns: ['org_id', 'factory_project_id'] }],\n};\n\n/** A board's ordered phases. `phase_key` is the stage id cards sit in. */\nexport const FACTORY_BOARD_PHASES_SCHEMA: CollectionSchema = {\n name: 'factory_board_phases',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n board_key: { type: 'text' },\n phase_key: { type: 'text' },\n position: { type: 'integer' },\n name: { type: 'text' },\n description: { type: 'text', nullable: true },\n kind: { type: 'text' },\n // { skill?, context?, instructions? }; room for other runner types later.\n runner: { type: 'json', nullable: true },\n next_phases: { type: 'json', nullable: true },\n auto_start: { type: 'boolean', default: false },\n auto_start_when: { type: 'json', nullable: true },\n exit_tool: { type: 'json', nullable: true },\n // Factory tools the phase grants the session working the card there, e.g. [\"factory_record_review_verdict\"].\n tools: { type: 'json', nullable: true },\n },\n uniqueIndexes: [\n {\n name: 'factory_board_phases_project_board_phase',\n columns: ['org_id', 'factory_project_id', 'board_key', 'phase_key'],\n },\n ],\n indexes: [{ name: 'factory_board_phases_project', columns: ['org_id', 'factory_project_id'] }],\n};\n\n/** A project's ordered intake routes: where new cards matching `when_condition` land. */\nexport const FACTORY_INTAKE_ROUTES_SCHEMA: CollectionSchema = {\n name: 'factory_intake_routes',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n name: { type: 'text' },\n enabled: { type: 'boolean', default: true },\n position: { type: 'integer' },\n // A card RuleGroup; null matches every card. Not named `when`, which is an SQL keyword.\n when_condition: { type: 'json', nullable: true },\n board_key: { type: 'text' },\n // Null lands the card in the board's first phase.\n phase_key: { type: 'text', nullable: true },\n // The status events the route handles (`StatusEvent`s). Null on rows written before routes named\n // events: those place new cards, as `['work_item.created']`.\n on_events: { type: 'json', nullable: true },\n // True files a pull request on the card of the issue it closes instead of a new card. Null on rows written before it.\n join_closed_issue: { type: 'boolean', nullable: true },\n // Rises on every write to the route, including a move; the compare-and-set token for edits.\n revision: { type: 'integer' },\n created_by: { type: 'text' },\n created_at: { type: 'timestamp' },\n updated_by: { type: 'text' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n { name: 'factory_intake_routes_project_position', columns: ['org_id', 'factory_project_id', 'position'] },\n ],\n indexes: [{ name: 'factory_intake_routes_project', columns: ['org_id', 'factory_project_id'] }],\n};\n\n/**\n * One row per project that every write adding, deleting or moving intake routes upserts first,\n * inside its transaction. The upsert holds the row until commit, so those writes on one project\n * run one after another and positions stay 0..n-1 with no gaps.\n */\nexport const FACTORY_INTAKE_ROUTE_LOCKS_SCHEMA: CollectionSchema = {\n name: 'factory_intake_route_locks',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n locked_at: { type: 'timestamp' },\n // Keys of the default routes Factory added to the project (`DEFAULT_INTAKE_ROUTES`), so each is\n // added once. Null on rows written before the list: those projects got `outside-authors`.\n seeded_defaults: { type: 'json', nullable: true },\n },\n uniqueIndexes: [{ name: 'factory_intake_route_locks_project', columns: ['org_id', 'factory_project_id'] }],\n};\n\n/**\n * One row per project whose `version` is replaced inside every board write, so other replicas\n * can tell their cached boards are stale with one indexed read.\n */\nexport const FACTORY_BOARD_DEFINITION_VERSIONS_SCHEMA: CollectionSchema = {\n name: 'factory_board_definition_versions',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n version: { type: 'text' },\n updated_at: { type: 'timestamp' },\n // Keys of the boards Factory stored in the project (Work, app and seed boards); each is stored\n // once, so one the project deleted stays deleted. Null on projects stored before the list.\n seeded_boards: { type: 'json', nullable: true },\n // Keys of the board migrations applied to the project, so each runs once: a field a user\n // later sets back to an old default is never rewritten again. Null before the first one.\n applied_migrations: { type: 'json', nullable: true },\n },\n uniqueIndexes: [{ name: 'factory_board_definition_versions_project', columns: ['org_id', 'factory_project_id'] }],\n};\n"],"mappings":";;AAGA,MAAa,wBAA0C;CACrD,MAAM;CACN,SAAS;EACP,IAAI,EAAE,MAAM,UAAU;EACtB,QAAQ,EAAE,MAAM,OAAO;EACvB,oBAAoB,EAAE,MAAM,OAAO;EACnC,WAAW,EAAE,MAAM,OAAO;EAC1B,MAAM,EAAE,MAAM,OAAO;EACrB,aAAa;GAAE,MAAM;GAAQ,UAAU;EAAK;EAC5C,UAAU,EAAE,MAAM,UAAU;EAE5B,UAAU,EAAE,MAAM,UAAU;EAC5B,YAAY,EAAE,MAAM,OAAO;EAC3B,YAAY,EAAE,MAAM,YAAY;EAChC,YAAY,EAAE,MAAM,OAAO;EAC3B,YAAY,EAAE,MAAM,YAAY;CAClC;CACA,eAAe,CAAC;EAAE,MAAM;EAA8B,SAAS;GAAC;GAAU;GAAsB;EAAW;CAAE,CAAC;CAC9G,SAAS,CAAC;EAAE,MAAM;EAA0B,SAAS,CAAC,UAAU,oBAAoB;CAAE,CAAC;AACzF;;AAGA,MAAa,8BAAgD;CAC3D,MAAM;CACN,SAAS;EACP,IAAI,EAAE,MAAM,UAAU;EACtB,QAAQ,EAAE,MAAM,OAAO;EACvB,oBAAoB,EAAE,MAAM,OAAO;EACnC,WAAW,EAAE,MAAM,OAAO;EAC1B,WAAW,EAAE,MAAM,OAAO;EAC1B,UAAU,EAAE,MAAM,UAAU;EAC5B,MAAM,EAAE,MAAM,OAAO;EACrB,aAAa;GAAE,MAAM;GAAQ,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;CAAE,CAAC;AAChG;;;;;;AAOA,MAAa,oCAAsD;CACjE,MAAM;CACN,SAAS;EACP,IAAI,EAAE,MAAM,UAAU;EACtB,QAAQ,EAAE,MAAM,OAAO;EACvB,oBAAoB,EAAE,MAAM,OAAO;EACnC,WAAW,EAAE,MAAM,YAAY;EAG/B,iBAAiB;GAAE,MAAM;GAAQ,UAAU;EAAK;CAClD;CACA,eAAe,CAAC;EAAE,MAAM;EAAsC,SAAS,CAAC,UAAU,oBAAoB;CAAE,CAAC;AAC3G;;;;;AAMA,MAAa,2CAA6D;CACxE,MAAM;CACN,SAAS;EACP,IAAI,EAAE,MAAM,UAAU;EACtB,QAAQ,EAAE,MAAM,OAAO;EACvB,oBAAoB,EAAE,MAAM,OAAO;EACnC,SAAS,EAAE,MAAM,OAAO;EACxB,YAAY,EAAE,MAAM,YAAY;EAGhC,eAAe;GAAE,MAAM;GAAQ,UAAU;EAAK;EAG9C,oBAAoB;GAAE,MAAM;GAAQ,UAAU;EAAK;CACrD;CACA,eAAe,CAAC;EAAE,MAAM;EAA6C,SAAS,CAAC,UAAU,oBAAoB;CAAE,CAAC;AAClH"}
@@ -20,7 +20,10 @@ export interface IntakeSelection {
20
20
  export type IntakeConfig = Record<string, IntakeSelection>;
21
21
  export declare const DEFAULT_INTAKE_CONFIG: IntakeConfig;
22
22
  export declare const INTAKE_ORG_SETTINGS_SCHEMA: CollectionSchema;
23
- /** Collection evolution is additive, so the per-member unique index cannot be narrowed: rows stay and are folded at boot. */
23
+ /**
24
+ * Collection evolution is additive, so the per-member unique index cannot be narrowed: rows stay and
25
+ * are folded at boot. Registered only on a database an earlier release already created it in.
26
+ */
24
27
  export declare const LEGACY_INTAKE_USER_SETTINGS_SCHEMA: CollectionSchema;
25
28
  /** What the org effectively saw while selections were personal: a member's sources fed the shared board only while their switch was on. */
26
29
  export declare function mergeIntakeSelections(configs: readonly IntakeConfig[]): IntakeConfig;
@@ -34,8 +37,9 @@ export declare function mergeIntakeSelections(configs: readonly IntakeConfig[]):
34
37
  *
35
38
  * Frozen: its unique index allows one binding per source, and indexes cannot be
36
39
  * narrowed, so bindings moved to {@link INTAKE_SOURCE_SUBSCRIPTIONS_SCHEMA}. Rows
37
- * are copied once at boot and never written again; the collection stays
38
- * registered so an earlier build that is rolled back to still finds them.
40
+ * are copied once at boot and never written again. Registered, with
41
+ * {@link INTAKE_DATA_MIGRATIONS_SCHEMA}, only on a database an earlier release
42
+ * already created it in, so a build rolled back to still finds the rows there.
39
43
  */
40
44
  export declare const INTAKE_SOURCE_BINDINGS_SCHEMA: CollectionSchema;
41
45
  /**
@@ -45,7 +49,10 @@ export declare const INTAKE_SOURCE_BINDINGS_SCHEMA: CollectionSchema;
45
49
  * projects share a source, each taking the issues carrying its own labels.
46
50
  */
47
51
  export declare const INTAKE_SOURCE_SUBSCRIPTIONS_SCHEMA: CollectionSchema;
48
- /** One-time data migrations that have run, so none re-runs over rows users have changed since. */
52
+ /**
53
+ * One-time data migrations that have run, so none re-runs over rows users have changed since. Its one
54
+ * migration copies {@link INTAKE_SOURCE_BINDINGS_SCHEMA}, so it exists only alongside that collection.
55
+ */
49
56
  export declare const INTAKE_DATA_MIGRATIONS_SCHEMA: CollectionSchema;
50
57
  export interface IntakeSourceBinding {
51
58
  integrationId: string;
@@ -75,12 +82,6 @@ export declare function bindingLabelSlice(binding: Pick<IntakeSourceBinding, 'fa
75
82
  export declare function bindingTakesIssue(binding: Pick<IntakeSourceBinding, 'factoryProjectId' | 'labels' | 'createdAt'>, siblings: readonly Pick<IntakeSourceBinding, 'factoryProjectId' | 'labels' | 'createdAt'>[], labels: readonly string[]): boolean;
76
83
  /** Trim and de-duplicate case-insensitively, keeping the first spelling the user typed. */
77
84
  export declare function normalizeBindingLabels(labels: readonly string[]): string[];
78
- /**
79
- * Retired: label routes sent labelled items to a board. Intake routes replaced them; the collection
80
- * stays registered so an earlier build that is rolled back to still finds it, but nothing reads or
81
- * writes it.
82
- */
83
- export declare const INTAKE_LABEL_ROUTES_SCHEMA: CollectionSchema;
84
85
  /** Labels are matched the way GitHub treats them: case-insensitively. */
85
86
  export declare function normalizeIntakeLabel(label: string): string;
86
87
  export declare class IntakeStorage extends FactoryStorageDomain {
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/intake/base.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,oBAAoB,EAAwB,MAAM,sBAAsB,CAAC;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAEhF,qBAAa,2BAA4B,SAAQ,KAAK;IACpD,cAGC;CACF;AAQD,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,mEAAmE;IACnE,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAC3B,yBAAyB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACpD;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AAE3D,eAAO,MAAM,qBAAqB,EAAE,YAAiB,CAAC;AAEtD,eAAO,MAAM,0BAA0B,EAAE,gBAUxC,CAAC;AAEF,6HAA6H;AAC7H,eAAO,MAAM,kCAAkC,EAAE,gBAWhD,CAAC;AAEF,2IAA2I;AAC3I,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,YAAY,CAcpF;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,6BAA6B,EAAE,gBAqB3C,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kCAAkC,EAAE,gBAuBhD,CAAC;AAEF,kGAAkG;AAClG,eAAO,MAAM,6BAA6B,EAAE,gBAM3C,CAAC;AAIF,MAAM,WAAW,mBAAmB;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAg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M,CAAC;QACzB,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QACxB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,GAAG,OAAO,CAAC;QAAE,SAAS,EAAE,qBAAqB,EAAE,CAAA;KAAE,CAAC,CAclD;IAED,yFAAyF;IACnF,gBAAgB,CAAC,EACrB,KAAK,EACL,aAAa,EACb,UAAU,GACX,EAAE;QACD,KAAK,EAAE,MAAM,CAAC;QACd,aAAa,EAAE,MAAM,CAAC;QACtB,UAAU,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,EAAE,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KACjD,GAAG,OAAO,CAAC;QAAE,UAAU,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,EAAE,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAAC,SAAS,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,EAAE,EAAE,MAAM,CAAA;SAAE,CAAC,CAAA;KAAE,CAAC,CAyE/G;CACF"}
@@ -1,3 +1,4 @@
1
+ import { ensureLegacyCollections } from "../../legacy-collections.js";
1
2
  import { FactoryStorageDomain, UniqueViolationError } from "@mastra/core/storage";
2
3
  // src/storage/domains/intake/base.ts
3
4
  /**
@@ -35,7 +36,10 @@ const INTAKE_ORG_SETTINGS_SCHEMA = {
35
36
  columns: ["org_id"]
36
37
  }]
37
38
  };
38
- /** Collection evolution is additive, so the per-member unique index cannot be narrowed: rows stay and are folded at boot. */
39
+ /**
40
+ * Collection evolution is additive, so the per-member unique index cannot be narrowed: rows stay and
41
+ * are folded at boot. Registered only on a database an earlier release already created it in.
42
+ */
39
43
  const LEGACY_INTAKE_USER_SETTINGS_SCHEMA = {
40
44
  name: "intake_settings",
41
45
  columns: {
@@ -78,8 +82,9 @@ function mergeIntakeSelections(configs) {
78
82
  *
79
83
  * Frozen: its unique index allows one binding per source, and indexes cannot be
80
84
  * narrowed, so bindings moved to {@link INTAKE_SOURCE_SUBSCRIPTIONS_SCHEMA}. Rows
81
- * are copied once at boot and never written again; the collection stays
82
- * registered so an earlier build that is rolled back to still finds them.
85
+ * are copied once at boot and never written again. Registered, with
86
+ * {@link INTAKE_DATA_MIGRATIONS_SCHEMA}, only on a database an earlier release
87
+ * already created it in, so a build rolled back to still finds the rows there.
83
88
  */
84
89
  const INTAKE_SOURCE_BINDINGS_SCHEMA = {
85
90
  name: "intake_source_bindings",
@@ -89,11 +94,6 @@ const INTAKE_SOURCE_BINDINGS_SCHEMA = {
89
94
  integration_id: { type: "text" },
90
95
  source_id: { type: "text" },
91
96
  factory_project_id: { type: "text" },
92
- /** Retired: intake routes decide where a source's cards land. Nothing reads or writes it. */
93
- board: {
94
- type: "text",
95
- nullable: true
96
- },
97
97
  created_by_user_id: {
98
98
  type: "text",
99
99
  nullable: true
@@ -128,11 +128,6 @@ const INTAKE_SOURCE_SUBSCRIPTIONS_SCHEMA = {
128
128
  integration_id: { type: "text" },
129
129
  source_id: { type: "text" },
130
130
  factory_project_id: { type: "text" },
131
- /** Retired: intake routes decide where a source's cards land. Nothing reads or writes it. */
132
- board: {
133
- type: "text",
134
- nullable: true
135
- },
136
131
  /** Labels whose issues this binding takes, as the user typed them; `null` takes every unclaimed issue. */
137
132
  labels: {
138
133
  type: "json",
@@ -159,7 +154,10 @@ const INTAKE_SOURCE_SUBSCRIPTIONS_SCHEMA = {
159
154
  ]
160
155
  }]
161
156
  };
162
- /** One-time data migrations that have run, so none re-runs over rows users have changed since. */
157
+ /**
158
+ * One-time data migrations that have run, so none re-runs over rows users have changed since. Its one
159
+ * migration copies {@link INTAKE_SOURCE_BINDINGS_SCHEMA}, so it exists only alongside that collection.
160
+ */
163
161
  const INTAKE_DATA_MIGRATIONS_SCHEMA = {
164
162
  name: "intake_data_migrations",
165
163
  columns: {
@@ -213,42 +211,6 @@ function normalizeBindingLabels(labels) {
213
211
  }
214
212
  return kept;
215
213
  }
216
- /**
217
- * Retired: label routes sent labelled items to a board. Intake routes replaced them; the collection
218
- * stays registered so an earlier build that is rolled back to still finds it, but nothing reads or
219
- * writes it.
220
- */
221
- const INTAKE_LABEL_ROUTES_SCHEMA = {
222
- name: "intake_label_routes",
223
- columns: {
224
- id: { type: "uuid-pk" },
225
- org_id: { type: "text" },
226
- factory_project_id: { type: "text" },
227
- integration_id: { type: "text" },
228
- /** Label as the provider reports it; matched case-insensitively. */
229
- label: { type: "text" },
230
- board: { type: "text" },
231
- created_by_user_id: {
232
- type: "text",
233
- nullable: true
234
- },
235
- created_at: { type: "timestamp" },
236
- updated_at: { type: "timestamp" }
237
- },
238
- indexes: [{
239
- name: "intake_label_routes_project_idx",
240
- columns: ["org_id", "factory_project_id"]
241
- }],
242
- uniqueIndexes: [{
243
- name: "intake_label_routes_org_project_integration_label_unique",
244
- columns: [
245
- "org_id",
246
- "factory_project_id",
247
- "integration_id",
248
- "label"
249
- ]
250
- }]
251
- };
252
214
  /** Labels are matched the way GitHub treats them: case-insensitively. */
253
215
  function normalizeIntakeLabel(label) {
254
216
  return label.trim().toLowerCase();
@@ -295,20 +257,22 @@ async function upsertBinding(ops, key, patch, userId) {
295
257
  });
296
258
  }
297
259
  var IntakeStorage = class extends FactoryStorageDomain {
260
+ /** The legacy collections this database has, so only those are read, migrated, or cleared. */
261
+ #legacy = {
262
+ userSettings: false,
263
+ bindings: false
264
+ };
298
265
  constructor() {
299
266
  super("intake");
300
267
  }
301
268
  async init() {
302
- await this.ensureCollections([
303
- INTAKE_ORG_SETTINGS_SCHEMA,
304
- LEGACY_INTAKE_USER_SETTINGS_SCHEMA,
305
- INTAKE_SOURCE_BINDINGS_SCHEMA,
306
- INTAKE_SOURCE_SUBSCRIPTIONS_SCHEMA,
307
- INTAKE_DATA_MIGRATIONS_SCHEMA,
308
- INTAKE_LABEL_ROUTES_SCHEMA
309
- ]);
310
- await this.#foldLegacyUserSelections();
311
- await this.#copyLegacyBindings();
269
+ await this.ensureCollections([INTAKE_ORG_SETTINGS_SCHEMA, INTAKE_SOURCE_SUBSCRIPTIONS_SCHEMA]);
270
+ this.#legacy = {
271
+ userSettings: await ensureLegacyCollections(this.storage, [LEGACY_INTAKE_USER_SETTINGS_SCHEMA]),
272
+ bindings: await ensureLegacyCollections(this.storage, [INTAKE_SOURCE_BINDINGS_SCHEMA, INTAKE_DATA_MIGRATIONS_SCHEMA])
273
+ };
274
+ if (this.#legacy.userSettings) await this.#foldLegacyUserSelections();
275
+ if (this.#legacy.bindings) await this.#copyLegacyBindings();
312
276
  }
313
277
  /**
314
278
  * Copy `intake_source_bindings` into `intake_source_subscriptions` as
@@ -357,11 +321,12 @@ var IntakeStorage = class extends FactoryStorageDomain {
357
321
  }
358
322
  async dangerouslyClearAll() {
359
323
  await this.ops.deleteMany("intake_org_settings", {});
360
- await this.ops.deleteMany("intake_settings", {});
361
- await this.ops.deleteMany("intake_source_bindings", {});
324
+ if (this.#legacy.userSettings) await this.ops.deleteMany("intake_settings", {});
325
+ if (this.#legacy.bindings) {
326
+ await this.ops.deleteMany("intake_source_bindings", {});
327
+ await this.ops.deleteMany("intake_data_migrations", {});
328
+ }
362
329
  await this.ops.deleteMany("intake_source_subscriptions", {});
363
- await this.ops.deleteMany("intake_data_migrations", {});
364
- await this.ops.deleteMany("intake_label_routes", {});
365
330
  }
366
331
  get #db() {
367
332
  return this.ops;
@@ -595,6 +560,6 @@ var IntakeStorage = class extends FactoryStorageDomain {
595
560
  }, { isolationLevel: "serializable" });
596
561
  }
597
562
  };
598
- export { DEFAULT_INTAKE_CONFIG, FactoryProjectNotFoundError, INTAKE_DATA_MIGRATIONS_SCHEMA, INTAKE_LABEL_ROUTES_SCHEMA, INTAKE_ORG_SETTINGS_SCHEMA, INTAKE_SOURCE_BINDINGS_SCHEMA, INTAKE_SOURCE_SUBSCRIPTIONS_SCHEMA, IntakeStorage, LEGACY_INTAKE_USER_SETTINGS_SCHEMA, bindingLabelSlice, bindingTakesIssue, mergeIntakeSelections, normalizeBindingLabels, normalizeIntakeLabel };
563
+ export { DEFAULT_INTAKE_CONFIG, FactoryProjectNotFoundError, INTAKE_DATA_MIGRATIONS_SCHEMA, INTAKE_ORG_SETTINGS_SCHEMA, INTAKE_SOURCE_BINDINGS_SCHEMA, INTAKE_SOURCE_SUBSCRIPTIONS_SCHEMA, IntakeStorage, LEGACY_INTAKE_USER_SETTINGS_SCHEMA, bindingLabelSlice, bindingTakesIssue, mergeIntakeSelections, normalizeBindingLabels, normalizeIntakeLabel };
599
564
 
600
565
  //# sourceMappingURL=base.js.map