@mastra/factory 0.8.0-alpha.8 → 0.8.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 (182) hide show
  1. package/CHANGELOG.md +660 -0
  2. package/dist/factory.d.ts.map +1 -1
  3. package/dist/factory.js +42 -4
  4. package/dist/factory.js.map +1 -1
  5. package/dist/integrations/base.d.ts +8 -0
  6. package/dist/integrations/base.d.ts.map +1 -1
  7. package/dist/integrations/github/app-identity.d.ts +43 -0
  8. package/dist/integrations/github/app-identity.d.ts.map +1 -0
  9. package/dist/integrations/github/app-identity.js +62 -0
  10. package/dist/integrations/github/app-identity.js.map +1 -0
  11. package/dist/integrations/github/integration.d.ts +9 -0
  12. package/dist/integrations/github/integration.d.ts.map +1 -1
  13. package/dist/integrations/github/integration.js +9 -1
  14. package/dist/integrations/github/integration.js.map +1 -1
  15. package/dist/integrations/github/reconcile-worker.d.ts +5 -0
  16. package/dist/integrations/github/reconcile-worker.d.ts.map +1 -1
  17. package/dist/integrations/github/reconcile-worker.js +7 -0
  18. package/dist/integrations/github/reconcile-worker.js.map +1 -1
  19. package/dist/integrations/github/routes.d.ts.map +1 -1
  20. package/dist/integrations/github/routes.js +11 -6
  21. package/dist/integrations/github/routes.js.map +1 -1
  22. package/dist/integrations/github/rules.d.ts +8 -0
  23. package/dist/integrations/github/rules.d.ts.map +1 -1
  24. package/dist/integrations/github/rules.js +30 -8
  25. package/dist/integrations/github/rules.js.map +1 -1
  26. package/dist/integrations/github/sandbox.d.ts +39 -6
  27. package/dist/integrations/github/sandbox.d.ts.map +1 -1
  28. package/dist/integrations/github/sandbox.js +48 -14
  29. package/dist/integrations/github/sandbox.js.map +1 -1
  30. package/dist/integrations/github/webhook.d.ts +39 -0
  31. package/dist/integrations/github/webhook.d.ts.map +1 -1
  32. package/dist/integrations/github/webhook.js +74 -13
  33. package/dist/integrations/github/webhook.js.map +1 -1
  34. package/dist/integrations/linear/integration.d.ts.map +1 -1
  35. package/dist/integrations/linear/integration.js +1 -0
  36. package/dist/integrations/linear/integration.js.map +1 -1
  37. package/dist/integrations/linear/routes.d.ts +10 -0
  38. package/dist/integrations/linear/routes.d.ts.map +1 -1
  39. package/dist/integrations/linear/routes.js +35 -1
  40. package/dist/integrations/linear/routes.js.map +1 -1
  41. package/dist/integrations/linear/rules.d.ts.map +1 -1
  42. package/dist/integrations/linear/rules.js +2 -1
  43. package/dist/integrations/linear/rules.js.map +1 -1
  44. package/dist/integrations/platform/github/event-worker.d.ts +11 -0
  45. package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
  46. package/dist/integrations/platform/github/event-worker.js +64 -16
  47. package/dist/integrations/platform/github/event-worker.js.map +1 -1
  48. package/dist/integrations/platform/github/integration.d.ts +12 -0
  49. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  50. package/dist/integrations/platform/github/integration.js +47 -4
  51. package/dist/integrations/platform/github/integration.js.map +1 -1
  52. package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
  53. package/dist/integrations/platform/linear/integration.js +1 -0
  54. package/dist/integrations/platform/linear/integration.js.map +1 -1
  55. package/dist/integrations/slack/slack.d.ts.map +1 -1
  56. package/dist/integrations/slack/slack.js +2 -1
  57. package/dist/integrations/slack/slack.js.map +1 -1
  58. package/dist/routes/config.d.ts +12 -6
  59. package/dist/routes/config.d.ts.map +1 -1
  60. package/dist/routes/config.js +97 -56
  61. package/dist/routes/config.js.map +1 -1
  62. package/dist/routes/fs.d.ts.map +1 -1
  63. package/dist/routes/fs.js +2 -0
  64. package/dist/routes/fs.js.map +1 -1
  65. package/dist/routes/intake.d.ts +15 -0
  66. package/dist/routes/intake.d.ts.map +1 -1
  67. package/dist/routes/intake.js +65 -2
  68. package/dist/routes/intake.js.map +1 -1
  69. package/dist/routes/knowledge.d.ts +152 -0
  70. package/dist/routes/knowledge.d.ts.map +1 -0
  71. package/dist/routes/knowledge.js +442 -0
  72. package/dist/routes/knowledge.js.map +1 -0
  73. package/dist/routes/projects.d.ts +9 -1
  74. package/dist/routes/projects.d.ts.map +1 -1
  75. package/dist/routes/projects.js +8 -0
  76. package/dist/routes/projects.js.map +1 -1
  77. package/dist/routes/surface.d.ts +6 -0
  78. package/dist/routes/surface.d.ts.map +1 -1
  79. package/dist/routes/surface.js +10 -0
  80. package/dist/routes/surface.js.map +1 -1
  81. package/dist/routes/work-items.d.ts.map +1 -1
  82. package/dist/routes/work-items.js +3 -1
  83. package/dist/routes/work-items.js.map +1 -1
  84. package/dist/rules/binding-context.d.ts.map +1 -1
  85. package/dist/rules/binding-context.js +4 -1
  86. package/dist/rules/binding-context.js.map +1 -1
  87. package/dist/rules/defaults.d.ts.map +1 -1
  88. package/dist/rules/defaults.js +87 -4
  89. package/dist/rules/defaults.js.map +1 -1
  90. package/dist/rules/dispatcher.d.ts +6 -0
  91. package/dist/rules/dispatcher.d.ts.map +1 -1
  92. package/dist/rules/dispatcher.js +118 -16
  93. package/dist/rules/dispatcher.js.map +1 -1
  94. package/dist/rules/processor.d.ts.map +1 -1
  95. package/dist/rules/processor.js +20 -7
  96. package/dist/rules/processor.js.map +1 -1
  97. package/dist/rules/resolve.d.ts +1 -0
  98. package/dist/rules/resolve.d.ts.map +1 -1
  99. package/dist/rules/resolve.js +3 -2
  100. package/dist/rules/resolve.js.map +1 -1
  101. package/dist/rules/start-coordinator.d.ts +2 -0
  102. package/dist/rules/start-coordinator.d.ts.map +1 -1
  103. package/dist/rules/start-coordinator.js +3 -1
  104. package/dist/rules/start-coordinator.js.map +1 -1
  105. package/dist/rules/terminal-cleanup.d.ts +23 -0
  106. package/dist/rules/terminal-cleanup.d.ts.map +1 -0
  107. package/dist/rules/terminal-cleanup.js +43 -0
  108. package/dist/rules/terminal-cleanup.js.map +1 -0
  109. package/dist/rules/tools.d.ts.map +1 -1
  110. package/dist/rules/tools.js +24 -2
  111. package/dist/rules/tools.js.map +1 -1
  112. package/dist/rules/transition-service.d.ts +3 -0
  113. package/dist/rules/transition-service.d.ts.map +1 -1
  114. package/dist/rules/transition-service.js +10 -6
  115. package/dist/rules/transition-service.js.map +1 -1
  116. package/dist/rules/types.d.ts +32 -3
  117. package/dist/rules/types.d.ts.map +1 -1
  118. package/dist/rules/types.js +2 -0
  119. package/dist/rules/types.js.map +1 -1
  120. package/dist/rules/validation.d.ts.map +1 -1
  121. package/dist/rules/validation.js +8 -3
  122. package/dist/rules/validation.js.map +1 -1
  123. package/dist/sandbox/base-checkpoint-triggers.d.ts +77 -0
  124. package/dist/sandbox/base-checkpoint-triggers.d.ts.map +1 -0
  125. package/dist/sandbox/base-checkpoint-triggers.js +137 -0
  126. package/dist/sandbox/base-checkpoint-triggers.js.map +1 -0
  127. package/dist/sandbox/base-checkpoint.d.ts +59 -0
  128. package/dist/sandbox/base-checkpoint.d.ts.map +1 -0
  129. package/dist/sandbox/base-checkpoint.js +145 -0
  130. package/dist/sandbox/base-checkpoint.js.map +1 -0
  131. package/dist/sandbox/fleet.d.ts +32 -0
  132. package/dist/sandbox/fleet.d.ts.map +1 -1
  133. package/dist/sandbox/fleet.js +39 -10
  134. package/dist/sandbox/fleet.js.map +1 -1
  135. package/dist/session/checkpoint-capture.d.ts +3 -2
  136. package/dist/session/checkpoint-capture.d.ts.map +1 -1
  137. package/dist/session/checkpoint-capture.js +3 -3
  138. package/dist/session/checkpoint-capture.js.map +1 -1
  139. package/dist/session/factory-session.d.ts.map +1 -1
  140. package/dist/session/factory-session.js +2 -1
  141. package/dist/session/factory-session.js.map +1 -1
  142. package/dist/session/filesystem-capture.d.ts +7 -0
  143. package/dist/session/filesystem-capture.d.ts.map +1 -1
  144. package/dist/session/filesystem-capture.js +41 -4
  145. package/dist/session/filesystem-capture.js.map +1 -1
  146. package/dist/session/model-pack-hydration.d.ts +55 -0
  147. package/dist/session/model-pack-hydration.d.ts.map +1 -0
  148. package/dist/session/model-pack-hydration.js +56 -0
  149. package/dist/session/model-pack-hydration.js.map +1 -0
  150. package/dist/skills/service.d.ts +9 -0
  151. package/dist/skills/service.d.ts.map +1 -1
  152. package/dist/skills/service.js +10 -1
  153. package/dist/skills/service.js.map +1 -1
  154. package/dist/storage/domains/intake/base.d.ts +36 -0
  155. package/dist/storage/domains/intake/base.d.ts.map +1 -1
  156. package/dist/storage/domains/intake/base.js +91 -2
  157. package/dist/storage/domains/intake/base.js.map +1 -1
  158. package/dist/storage/domains/model-packs/base.d.ts +26 -0
  159. package/dist/storage/domains/model-packs/base.d.ts.map +1 -1
  160. package/dist/storage/domains/model-packs/base.js +102 -13
  161. package/dist/storage/domains/model-packs/base.js.map +1 -1
  162. package/dist/storage/domains/source-control/base.d.ts +47 -1
  163. package/dist/storage/domains/source-control/base.d.ts.map +1 -1
  164. package/dist/storage/domains/source-control/base.js +78 -19
  165. package/dist/storage/domains/source-control/base.js.map +1 -1
  166. package/dist/storage/domains/source-control/inmemory.d.ts +11 -3
  167. package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
  168. package/dist/storage/domains/source-control/inmemory.js +10 -1
  169. package/dist/storage/domains/source-control/inmemory.js.map +1 -1
  170. package/dist/storage/domains/work-items/base.d.ts +67 -1
  171. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  172. package/dist/storage/domains/work-items/base.js +183 -12
  173. package/dist/storage/domains/work-items/base.js.map +1 -1
  174. package/dist/workspace.d.ts +31 -2
  175. package/dist/workspace.d.ts.map +1 -1
  176. package/dist/workspace.js +225 -54
  177. package/dist/workspace.js.map +1 -1
  178. package/factory-skills/factory-plan/SKILL.md +1 -1
  179. package/factory-skills/factory-rereview/SKILL.md +3 -3
  180. package/factory-skills/factory-review/SKILL.md +3 -3
  181. package/factory-skills/factory-triage/SKILL.md +2 -0
  182. package/package.json +8 -8
@@ -1 +1 @@
1
- {"version":3,"file":"inmemory.js","names":[],"sources":["../../../../src/storage/domains/source-control/inmemory.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { UniqueViolationError } from '@mastra/core/storage';\n\nimport type {\n ConfiguredExternalRepositoryKey,\n CreateProjectSourceControlConnectionInput,\n CreateSourceControlSessionInput,\n ExternalRepositoryProjectTarget,\n LinkProjectRepositoryInput,\n PooledSandbox,\n ProjectRepository,\n ProjectRepositorySandbox,\n ProjectSourceControlConnection,\n ReleasePooledSandboxInput,\n SourceControlInstallation,\n SourceControlRepository,\n SourceControlSession,\n SourceControlStorageHandle,\n SourceControlWorktree,\n UpdateProjectRepositoryInput,\n UpsertSourceControlInstallationInput,\n UpsertSourceControlRepositoryInput,\n UpsertSourceControlWorktreeInput,\n} from './base.js';\n\n/** In-memory provider-scoped source-control handle for route tests. */\nexport class SourceControlStorageInMemory implements SourceControlStorageHandle {\n readonly integrationId: string;\n installationsRows: SourceControlInstallation[] = [];\n repositoriesRows: SourceControlRepository[] = [];\n connectionsRows: ProjectSourceControlConnection[] = [];\n projectRepositoriesRows: ProjectRepository[] = [];\n sandboxesRows: ProjectRepositorySandbox[] = [];\n sandboxPoolRows: PooledSandbox[] = [];\n worktreesRows: SourceControlWorktree[] = [];\n sessionsRows: SourceControlSession[] = [];\n\n constructor(integrationId = 'github') {\n this.integrationId = integrationId;\n }\n\n readonly installations = {\n list: async ({ orgId }: { orgId: string }): Promise<SourceControlInstallation[]> =>\n this.installationsRows.filter(row => row.orgId === orgId),\n get: async ({ orgId, id }: { orgId: string; id: string }): Promise<SourceControlInstallation | null> =>\n this.installationsRows.find(row => row.orgId === orgId && row.id === id) ?? null,\n findByExternalId: async ({\n orgId,\n externalId,\n }: {\n orgId: string;\n externalId: string;\n }): Promise<SourceControlInstallation | null> =>\n this.installationsRows.find(row => row.orgId === orgId && row.externalId === externalId) ?? null,\n upsert: async (input: UpsertSourceControlInstallationInput): Promise<SourceControlInstallation> => {\n const existing = this.installationsRows.find(\n row => row.orgId === input.orgId && row.externalId === input.externalId,\n );\n if (existing) {\n Object.assign(existing, {\n connectedByUserId: input.connectedByUserId,\n accountName: input.accountName ?? null,\n accountType: input.accountType ?? null,\n providerMetadata: input.providerMetadata ?? {},\n });\n return existing;\n }\n const created: SourceControlInstallation = {\n id: randomUUID(),\n integrationId: this.integrationId,\n orgId: input.orgId,\n connectedByUserId: input.connectedByUserId,\n externalId: input.externalId,\n accountName: input.accountName ?? null,\n accountType: input.accountType ?? null,\n providerMetadata: input.providerMetadata ?? {},\n createdAt: new Date(),\n };\n this.installationsRows.push(created);\n return created;\n },\n delete: async ({ orgId, id }: { orgId: string; id: string }): Promise<boolean> => {\n const index = this.installationsRows.findIndex(row => row.orgId === orgId && row.id === id);\n if (index < 0) return false;\n this.installationsRows.splice(index, 1);\n return true;\n },\n };\n\n readonly repositories = {\n list: async ({ orgId, installationId }: { orgId: string; installationId: string }) => {\n const installation = await this.installations.get({ orgId, id: installationId });\n return installation ? this.repositoriesRows.filter(row => row.installationId === installationId) : [];\n },\n get: async ({ orgId, id }: { orgId: string; id: string }): Promise<SourceControlRepository | null> => {\n const row = this.repositoriesRows.find(candidate => candidate.id === id);\n if (!row) return null;\n return (await this.installations.get({ orgId, id: row.installationId })) ? row : null;\n },\n findByExternalId: async ({\n orgId,\n installationId,\n externalId,\n }: {\n orgId: string;\n installationId: string;\n externalId: string;\n }) => {\n const rows = await this.repositories.list({ orgId, installationId });\n return rows.find(row => row.externalId === externalId) ?? null;\n },\n findBySlug: async ({ orgId, installationId, slug }: { orgId: string; installationId: string; slug: string }) => {\n const rows = await this.repositories.list({ orgId, installationId });\n return rows.find(row => row.slug === slug) ?? null;\n },\n upsert: async ({\n orgId,\n input,\n }: {\n orgId: string;\n input: UpsertSourceControlRepositoryInput;\n }): Promise<SourceControlRepository> => {\n if (!(await this.installations.get({ orgId, id: input.installationId }))) {\n throw new Error('Source-control installation not found');\n }\n const existing = this.repositoriesRows.find(\n row => row.installationId === input.installationId && row.externalId === input.externalId,\n );\n const now = new Date();\n if (existing) {\n Object.assign(existing, {\n slug: input.slug,\n defaultBranch: input.defaultBranch,\n providerMetadata: input.providerMetadata ?? {},\n updatedAt: now,\n });\n return existing;\n }\n const created: SourceControlRepository = {\n id: randomUUID(),\n installationId: input.installationId,\n externalId: input.externalId,\n slug: input.slug,\n defaultBranch: input.defaultBranch,\n providerMetadata: input.providerMetadata ?? {},\n createdAt: now,\n updatedAt: now,\n };\n this.repositoriesRows.push(created);\n return created;\n },\n migrateInstallation: async ({\n orgId,\n id,\n newInstallationId,\n }: {\n orgId: string;\n id: string;\n newInstallationId: string;\n }) => {\n const existing = await this.repositories.get({ orgId, id });\n if (!existing) {\n throw new Error(`Repository ${id} not found in organization ${orgId}`);\n }\n if (!(await this.installations.get({ orgId, id: newInstallationId }))) {\n throw new Error('Source-control installation not found');\n }\n // Check if a repository with the same external_id exists under the new installation\n const conflict = this.repositoriesRows.find(\n row => row.installationId === newInstallationId && row.externalId === existing.externalId,\n );\n if (conflict) {\n // Return the existing repository under the new installation\n return conflict;\n }\n // Update the repository's installation\n existing.installationId = newInstallationId;\n existing.updatedAt = new Date();\n // Migrate dependent connections to the new installation\n for (const conn of this.connectionsRows) {\n if (conn.installationId === existing.installationId) {\n conn.installationId = newInstallationId;\n }\n }\n return existing;\n },\n };\n\n readonly connections = {\n list: async ({ factoryProjectId }: { orgId: string; factoryProjectId: string }) =>\n this.connectionsRows.filter(row => row.factoryProjectId === factoryProjectId),\n get: async ({ orgId, id }: { orgId: string; id: string }): Promise<ProjectSourceControlConnection | null> => {\n const row = this.connectionsRows.find(candidate => candidate.id === id);\n if (!row) return null;\n return (await this.installations.get({ orgId, id: row.installationId })) ? row : null;\n },\n create: async (input: CreateProjectSourceControlConnectionInput): Promise<ProjectSourceControlConnection> => {\n if (!(await this.installations.get({ orgId: input.orgId, id: input.installationId }))) {\n throw new Error('Source-control installation not found');\n }\n const existing = this.connectionsRows.find(\n row =>\n row.factoryProjectId === input.factoryProjectId &&\n row.integrationId === this.integrationId &&\n row.installationId === input.installationId,\n );\n if (existing) return existing;\n const created: ProjectSourceControlConnection = {\n id: randomUUID(),\n factoryProjectId: input.factoryProjectId,\n integrationId: this.integrationId,\n installationId: input.installationId,\n createdByUserId: input.createdByUserId,\n createdAt: new Date(),\n };\n this.connectionsRows.push(created);\n return created;\n },\n delete: async ({ orgId, id }: { orgId: string; id: string }): Promise<boolean> => {\n if (!(await this.connections.get({ orgId, id }))) return false;\n this.connectionsRows.splice(0, this.connectionsRows.length, ...this.connectionsRows.filter(row => row.id !== id));\n return true;\n },\n };\n\n readonly projectRepositories = {\n list: async ({ orgId, connectionId }: { orgId: string; connectionId: string }) =>\n (await this.connections.get({ orgId, id: connectionId }))\n ? this.projectRepositoriesRows.filter(row => row.connectionId === connectionId)\n : [],\n listConfiguredExternalKeys: async (): Promise<ConfiguredExternalRepositoryKey[]> => {\n const keys = new Map<string, ConfiguredExternalRepositoryKey>();\n for (const connection of this.connectionsRows.filter(row => row.integrationId === this.integrationId)) {\n const installation = this.installationsRows.find(row => row.id === connection.installationId);\n if (!installation) continue;\n for (const link of this.projectRepositoriesRows.filter(row => row.connectionId === connection.id)) {\n const repository = this.repositoriesRows.find(row => row.id === link.repositoryId);\n if (!repository) continue;\n keys.set(`${installation.externalId}\\u0000${repository.externalId}`, {\n installationExternalId: installation.externalId,\n repositoryExternalId: repository.externalId,\n });\n }\n }\n return [...keys.values()];\n },\n listByExternalRepository: async ({\n installationExternalId,\n repositoryExternalId,\n }: {\n installationExternalId: string;\n repositoryExternalId: string;\n }): Promise<ExternalRepositoryProjectTarget[]> => {\n const targets: ExternalRepositoryProjectTarget[] = [];\n for (const installation of this.installationsRows.filter(row => row.externalId === installationExternalId)) {\n const repository = this.repositoriesRows.find(\n row => row.installationId === installation.id && row.externalId === repositoryExternalId,\n );\n if (!repository) continue;\n for (const projectRepository of this.projectRepositoriesRows.filter(\n row => row.repositoryId === repository.id,\n )) {\n const connection = this.connectionsRows.find(\n row =>\n row.id === projectRepository.connectionId &&\n row.installationId === installation.id &&\n row.integrationId === this.integrationId,\n );\n if (!connection) continue;\n targets.push({\n orgId: installation.orgId,\n factoryProjectId: connection.factoryProjectId,\n projectRepository,\n });\n }\n }\n return targets;\n },\n get: async ({ orgId, id }: { orgId: string; id: string }): Promise<ProjectRepository | null> => {\n const row = this.projectRepositoriesRows.find(candidate => candidate.id === id);\n if (!row) return null;\n return (await this.connections.get({ orgId, id: row.connectionId })) ? row : null;\n },\n link: async (input: LinkProjectRepositoryInput): Promise<ProjectRepository> => {\n const connection = await this.connections.get({ orgId: input.orgId, id: input.connectionId });\n const repository = await this.repositories.get({ orgId: input.orgId, id: input.repositoryId });\n if (!connection || !repository || repository.installationId !== connection.installationId) {\n throw new Error('Source-control connection or repository not found');\n }\n const existing = this.projectRepositoriesRows.find(\n row => row.connectionId === input.connectionId && row.repositoryId === input.repositoryId,\n );\n if (existing) return existing;\n const now = new Date();\n const created: ProjectRepository = {\n id: randomUUID(),\n connectionId: input.connectionId,\n repositoryId: input.repositoryId,\n createdByUserId: input.createdByUserId,\n branch: input.branch ?? null,\n sandboxProvider: input.sandboxProvider,\n sandboxWorkdir: input.sandboxWorkdir,\n setupCommand: input.setupCommand ?? null,\n teardownCommand: input.teardownCommand ?? null,\n createdAt: now,\n updatedAt: now,\n };\n this.projectRepositoriesRows.push(created);\n return created;\n },\n update: async ({\n orgId,\n id,\n input,\n }: {\n orgId: string;\n id: string;\n input: UpdateProjectRepositoryInput;\n }): Promise<ProjectRepository | null> => {\n const row = await this.projectRepositories.get({ orgId, id });\n if (!row) return null;\n Object.assign(row, input, { updatedAt: new Date() });\n return row;\n },\n unlink: async ({ orgId, id }: { orgId: string; id: string }): Promise<boolean> => {\n if (!(await this.projectRepositories.get({ orgId, id }))) return false;\n this.projectRepositoriesRows.splice(\n 0,\n this.projectRepositoriesRows.length,\n ...this.projectRepositoriesRows.filter(row => row.id !== id),\n );\n return true;\n },\n };\n\n readonly sandboxes = {\n getOrCreate: async ({\n projectRepository,\n userId,\n }: {\n projectRepository: ProjectRepository;\n userId: string;\n }): Promise<ProjectRepositorySandbox> => {\n const existing = this.sandboxesRows.find(\n row => row.projectRepositoryId === projectRepository.id && row.userId === userId,\n );\n if (existing) return existing;\n const created: ProjectRepositorySandbox = {\n id: randomUUID(),\n projectRepositoryId: projectRepository.id,\n userId,\n sandboxId: null,\n sandboxWorkdir: projectRepository.sandboxWorkdir,\n materializedAt: null,\n createdAt: new Date(),\n };\n this.sandboxesRows.push(created);\n return created;\n },\n getById: async ({ id }: { id: string }): Promise<ProjectRepositorySandbox | null> =>\n this.sandboxesRows.find(row => row.id === id) ?? null,\n setWorkdir: async ({ id, sandboxWorkdir }: { id: string; sandboxWorkdir: string }): Promise<void> => {\n const row = this.sandboxesRows.find(candidate => candidate.id === id);\n if (row) Object.assign(row, { sandboxWorkdir, materializedAt: null });\n },\n setSandboxId: async ({ id, sandboxId }: { id: string; sandboxId: string }): Promise<void> => {\n const row = this.sandboxesRows.find(candidate => candidate.id === id);\n if (row) row.sandboxId = sandboxId;\n },\n clearBinding: async ({ id }: { id: string }): Promise<void> => {\n const row = this.sandboxesRows.find(candidate => candidate.id === id);\n if (row) Object.assign(row, { sandboxId: null, materializedAt: null });\n },\n markMaterialized: async ({ id }: { id: string }): Promise<void> => {\n const row = this.sandboxesRows.find(candidate => candidate.id === id);\n if (row) row.materializedAt = new Date();\n },\n };\n\n readonly sandboxPool = {\n release: async (input: ReleasePooledSandboxInput): Promise<void> => {\n // Mirror the SQL implementation: a missing project-repository link\n // makes the release a silent no-op.\n if (!this.projectRepositoriesRows.some(row => row.id === input.projectRepositoryId)) return;\n if (this.sandboxPoolRows.some(row => row.sandboxId === input.sandboxId)) return;\n this.sandboxPoolRows.push({ id: randomUUID(), releasedAt: new Date(), ...input });\n },\n claim: async ({ projectRepositoryId }: { projectRepositoryId: string }): Promise<PooledSandbox | null> => {\n const candidates = this.sandboxPoolRows\n .filter(row => row.projectRepositoryId === projectRepositoryId)\n .sort((left, right) => right.releasedAt.getTime() - left.releasedAt.getTime());\n const claimed = candidates[0];\n if (!claimed) return null;\n this.sandboxPoolRows.splice(this.sandboxPoolRows.indexOf(claimed), 1);\n return claimed;\n },\n };\n\n readonly worktrees = {\n upsert: async (input: UpsertSourceControlWorktreeInput): Promise<void> => {\n const existing = this.worktreesRows.find(\n row =>\n row.projectRepositoryId === input.projectRepositoryId &&\n row.userId === input.userId &&\n row.branch === input.branch,\n );\n if (existing) {\n existing.baseBranch = input.baseBranch;\n existing.worktreePath = input.worktreePath;\n return;\n }\n this.worktreesRows.push({ id: randomUUID(), createdAt: new Date(), ...input });\n },\n list: async ({\n projectRepositoryId,\n userId,\n }: {\n projectRepositoryId: string;\n userId: string;\n }): Promise<SourceControlWorktree[]> =>\n this.worktreesRows.filter(row => row.projectRepositoryId === projectRepositoryId && row.userId === userId),\n get: async ({\n projectRepositoryId,\n userId,\n branch,\n }: {\n projectRepositoryId: string;\n userId: string;\n branch: string;\n }): Promise<SourceControlWorktree | null> =>\n this.worktreesRows.find(\n row => row.projectRepositoryId === projectRepositoryId && row.userId === userId && row.branch === branch,\n ) ?? null,\n findByPath: async ({\n projectRepositoryId,\n userId,\n worktreePath,\n }: {\n projectRepositoryId: string;\n userId: string;\n worktreePath: string;\n }): Promise<SourceControlWorktree | null> =>\n this.worktreesRows.find(\n row =>\n row.projectRepositoryId === projectRepositoryId && row.userId === userId && row.worktreePath === worktreePath,\n ) ?? null,\n delete: async ({\n projectRepositoryId,\n userId,\n branch,\n }: {\n projectRepositoryId: string;\n userId: string;\n branch: string;\n }): Promise<void> => {\n this.worktreesRows.splice(\n 0,\n this.worktreesRows.length,\n ...this.worktreesRows.filter(\n row => !(row.projectRepositoryId === projectRepositoryId && row.userId === userId && row.branch === branch),\n ),\n );\n },\n };\n\n readonly sessions = {\n list: async ({ projectRepositoryId, userId }: { projectRepositoryId: string; userId: string }) =>\n this.sessionsRows.filter(row => row.projectRepositoryId === projectRepositoryId && row.userId === userId),\n listByProjectRepository: async ({ projectRepositoryId }: { projectRepositoryId: string }) =>\n this.sessionsRows.filter(row => row.projectRepositoryId === projectRepositoryId),\n getBySessionId: async (sessionId: string): Promise<SourceControlSession | null> =>\n this.sessionsRows.find(row => row.sessionId === sessionId) ?? null,\n getForBranch: async ({\n projectRepositoryId,\n userId,\n branch,\n }: {\n projectRepositoryId: string;\n userId: string;\n branch: string;\n }): Promise<SourceControlSession | null> =>\n this.sessionsRows.find(\n row => row.projectRepositoryId === projectRepositoryId && row.userId === userId && row.branch === branch,\n ) ?? null,\n create: async (input: CreateSourceControlSessionInput): Promise<SourceControlSession> => {\n const existing = await this.sessions.getForBranch(input);\n if (existing) return existing;\n if (this.sessionsRows.some(row => row.sessionId === input.sessionId)) {\n throw new UniqueViolationError('Source-control session ID already exists');\n }\n const now = new Date();\n const session: SourceControlSession = {\n id: randomUUID(),\n ...input,\n title: input.title ?? null,\n sandboxId: null,\n sandboxWorkdir: null,\n materializedAt: null,\n firstMessageAt: null,\n firstMeaningfulExecAt: null,\n createdAt: now,\n updatedAt: now,\n };\n this.sessionsRows.push(session);\n return session;\n },\n setSandbox: async ({\n id,\n sandboxId,\n sandboxWorkdir,\n }: {\n id: string;\n sandboxId: string | null;\n sandboxWorkdir: string;\n }) => {\n const row = this.sessionsRows.find(candidate => candidate.id === id);\n if (row) Object.assign(row, { sandboxId, sandboxWorkdir, updatedAt: new Date() });\n },\n markMaterialized: async ({ id }: { id: string }) => {\n const row = this.sessionsRows.find(candidate => candidate.id === id);\n if (row && row.materializedAt === null) Object.assign(row, { materializedAt: new Date(), updatedAt: new Date() });\n },\n markFirstMessage: async ({ sessionId }: { sessionId: string }) => {\n const row = this.sessionsRows.find(candidate => candidate.sessionId === sessionId);\n if (row && row.firstMessageAt === null) Object.assign(row, { firstMessageAt: new Date(), updatedAt: new Date() });\n },\n markFirstMeaningfulExec: async ({ sessionId }: { sessionId: string }) => {\n const row = this.sessionsRows.find(candidate => candidate.sessionId === sessionId);\n if (row && row.firstMeaningfulExecAt === null) {\n Object.assign(row, { firstMeaningfulExecAt: new Date(), updatedAt: new Date() });\n }\n },\n delete: async (id: string) => {\n this.sessionsRows.splice(0, this.sessionsRows.length, ...this.sessionsRows.filter(row => row.id !== id));\n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,KAAK;IAAE,gCAAgB,IAAI,KAAK;IAAG,2BAAW,IAAI,KAAK;GAAE,CAAC;EAClH;EACA,yBAAyB,OAAO,EAAE,gBAAuC;GACvE,MAAM,MAAM,KAAK,aAAa,MAAK,cAAa,UAAU,cAAc,SAAS;GACjF,IAAI,OAAO,IAAI,0BAA0B,MACvC,OAAO,OAAO,KAAK;IAAE,uCAAuB,IAAI,KAAK;IAAG,2BAAW,IAAI,KAAK;GAAE,CAAC;EAEnF;EACA,QAAQ,OAAO,OAAe;GAC5B,KAAK,aAAa,OAAO,GAAG,KAAK,aAAa,QAAQ,GAAG,KAAK,aAAa,QAAO,QAAO,IAAI,OAAO,EAAE,CAAC;EACzG;CACF;AACF"}
1
+ {"version":3,"file":"inmemory.js","names":[],"sources":["../../../../src/storage/domains/source-control/inmemory.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { UniqueViolationError } from '@mastra/core/storage';\n\nimport type {\n ConfiguredExternalRepositoryKey,\n CreateProjectSourceControlConnectionInput,\n CreateSourceControlSessionInput,\n ExternalRepositoryProjectTarget,\n LinkProjectRepositoryInput,\n PooledSandbox,\n ProjectRepository,\n ProjectRepositoryBaseCheckpoint,\n ProjectRepositorySandbox,\n ProjectSourceControlConnection,\n ReleasePooledSandboxInput,\n SourceControlInstallation,\n SourceControlRepository,\n SourceControlSession,\n SourceControlStorageHandle,\n SourceControlWorktree,\n UpdateProjectRepositoryInput,\n UpsertSourceControlInstallationInput,\n UpsertSourceControlRepositoryInput,\n UpsertSourceControlWorktreeInput,\n} from './base.js';\n\n/** In-memory provider-scoped source-control handle for route tests. */\nexport class SourceControlStorageInMemory implements SourceControlStorageHandle {\n readonly integrationId: string;\n installationsRows: SourceControlInstallation[] = [];\n repositoriesRows: SourceControlRepository[] = [];\n connectionsRows: ProjectSourceControlConnection[] = [];\n projectRepositoriesRows: ProjectRepository[] = [];\n sandboxesRows: ProjectRepositorySandbox[] = [];\n sandboxPoolRows: PooledSandbox[] = [];\n worktreesRows: SourceControlWorktree[] = [];\n sessionsRows: SourceControlSession[] = [];\n\n constructor(integrationId = 'github') {\n this.integrationId = integrationId;\n }\n\n readonly installations = {\n list: async ({ orgId }: { orgId: string }): Promise<SourceControlInstallation[]> =>\n this.installationsRows.filter(row => row.orgId === orgId),\n get: async ({ orgId, id }: { orgId: string; id: string }): Promise<SourceControlInstallation | null> =>\n this.installationsRows.find(row => row.orgId === orgId && row.id === id) ?? null,\n findByExternalId: async ({\n orgId,\n externalId,\n }: {\n orgId: string;\n externalId: string;\n }): Promise<SourceControlInstallation | null> =>\n this.installationsRows.find(row => row.orgId === orgId && row.externalId === externalId) ?? null,\n upsert: async (input: UpsertSourceControlInstallationInput): Promise<SourceControlInstallation> => {\n const existing = this.installationsRows.find(\n row => row.orgId === input.orgId && row.externalId === input.externalId,\n );\n if (existing) {\n Object.assign(existing, {\n connectedByUserId: input.connectedByUserId,\n accountName: input.accountName ?? null,\n accountType: input.accountType ?? null,\n providerMetadata: input.providerMetadata ?? {},\n });\n return existing;\n }\n const created: SourceControlInstallation = {\n id: randomUUID(),\n integrationId: this.integrationId,\n orgId: input.orgId,\n connectedByUserId: input.connectedByUserId,\n externalId: input.externalId,\n accountName: input.accountName ?? null,\n accountType: input.accountType ?? null,\n providerMetadata: input.providerMetadata ?? {},\n createdAt: new Date(),\n };\n this.installationsRows.push(created);\n return created;\n },\n delete: async ({ orgId, id }: { orgId: string; id: string }): Promise<boolean> => {\n const index = this.installationsRows.findIndex(row => row.orgId === orgId && row.id === id);\n if (index < 0) return false;\n this.installationsRows.splice(index, 1);\n return true;\n },\n };\n\n readonly repositories = {\n list: async ({ orgId, installationId }: { orgId: string; installationId: string }) => {\n const installation = await this.installations.get({ orgId, id: installationId });\n return installation ? this.repositoriesRows.filter(row => row.installationId === installationId) : [];\n },\n get: async ({ orgId, id }: { orgId: string; id: string }): Promise<SourceControlRepository | null> => {\n const row = this.repositoriesRows.find(candidate => candidate.id === id);\n if (!row) return null;\n return (await this.installations.get({ orgId, id: row.installationId })) ? row : null;\n },\n findByExternalId: async ({\n orgId,\n installationId,\n externalId,\n }: {\n orgId: string;\n installationId: string;\n externalId: string;\n }) => {\n const rows = await this.repositories.list({ orgId, installationId });\n return rows.find(row => row.externalId === externalId) ?? null;\n },\n findBySlug: async ({ orgId, installationId, slug }: { orgId: string; installationId: string; slug: string }) => {\n const rows = await this.repositories.list({ orgId, installationId });\n return rows.find(row => row.slug === slug) ?? null;\n },\n upsert: async ({\n orgId,\n input,\n }: {\n orgId: string;\n input: UpsertSourceControlRepositoryInput;\n }): Promise<SourceControlRepository> => {\n if (!(await this.installations.get({ orgId, id: input.installationId }))) {\n throw new Error('Source-control installation not found');\n }\n const existing = this.repositoriesRows.find(\n row => row.installationId === input.installationId && row.externalId === input.externalId,\n );\n const now = new Date();\n if (existing) {\n Object.assign(existing, {\n slug: input.slug,\n defaultBranch: input.defaultBranch,\n providerMetadata: input.providerMetadata ?? {},\n updatedAt: now,\n });\n return existing;\n }\n const created: SourceControlRepository = {\n id: randomUUID(),\n installationId: input.installationId,\n externalId: input.externalId,\n slug: input.slug,\n defaultBranch: input.defaultBranch,\n providerMetadata: input.providerMetadata ?? {},\n createdAt: now,\n updatedAt: now,\n };\n this.repositoriesRows.push(created);\n return created;\n },\n migrateInstallation: async ({\n orgId,\n id,\n newInstallationId,\n }: {\n orgId: string;\n id: string;\n newInstallationId: string;\n }) => {\n const existing = await this.repositories.get({ orgId, id });\n if (!existing) {\n throw new Error(`Repository ${id} not found in organization ${orgId}`);\n }\n if (!(await this.installations.get({ orgId, id: newInstallationId }))) {\n throw new Error('Source-control installation not found');\n }\n // Check if a repository with the same external_id exists under the new installation\n const conflict = this.repositoriesRows.find(\n row => row.installationId === newInstallationId && row.externalId === existing.externalId,\n );\n if (conflict) {\n // Return the existing repository under the new installation\n return conflict;\n }\n // Update the repository's installation\n existing.installationId = newInstallationId;\n existing.updatedAt = new Date();\n // Migrate dependent connections to the new installation\n for (const conn of this.connectionsRows) {\n if (conn.installationId === existing.installationId) {\n conn.installationId = newInstallationId;\n }\n }\n return existing;\n },\n };\n\n readonly connections = {\n list: async ({ factoryProjectId }: { orgId: string; factoryProjectId: string }) =>\n this.connectionsRows.filter(row => row.factoryProjectId === factoryProjectId),\n get: async ({ orgId, id }: { orgId: string; id: string }): Promise<ProjectSourceControlConnection | null> => {\n const row = this.connectionsRows.find(candidate => candidate.id === id);\n if (!row) return null;\n return (await this.installations.get({ orgId, id: row.installationId })) ? row : null;\n },\n create: async (input: CreateProjectSourceControlConnectionInput): Promise<ProjectSourceControlConnection> => {\n if (!(await this.installations.get({ orgId: input.orgId, id: input.installationId }))) {\n throw new Error('Source-control installation not found');\n }\n const existing = this.connectionsRows.find(\n row =>\n row.factoryProjectId === input.factoryProjectId &&\n row.integrationId === this.integrationId &&\n row.installationId === input.installationId,\n );\n if (existing) return existing;\n const created: ProjectSourceControlConnection = {\n id: randomUUID(),\n factoryProjectId: input.factoryProjectId,\n integrationId: this.integrationId,\n installationId: input.installationId,\n createdByUserId: input.createdByUserId,\n createdAt: new Date(),\n };\n this.connectionsRows.push(created);\n return created;\n },\n delete: async ({ orgId, id }: { orgId: string; id: string }): Promise<boolean> => {\n if (!(await this.connections.get({ orgId, id }))) return false;\n this.connectionsRows.splice(0, this.connectionsRows.length, ...this.connectionsRows.filter(row => row.id !== id));\n return true;\n },\n };\n\n readonly projectRepositories = {\n list: async ({ orgId, connectionId }: { orgId: string; connectionId: string }) =>\n (await this.connections.get({ orgId, id: connectionId }))\n ? this.projectRepositoriesRows.filter(row => row.connectionId === connectionId)\n : [],\n listConfiguredExternalKeys: async (): Promise<ConfiguredExternalRepositoryKey[]> => {\n const keys = new Map<string, ConfiguredExternalRepositoryKey>();\n for (const connection of this.connectionsRows.filter(row => row.integrationId === this.integrationId)) {\n const installation = this.installationsRows.find(row => row.id === connection.installationId);\n if (!installation) continue;\n for (const link of this.projectRepositoriesRows.filter(row => row.connectionId === connection.id)) {\n const repository = this.repositoriesRows.find(row => row.id === link.repositoryId);\n if (!repository) continue;\n keys.set(`${installation.externalId}\\u0000${repository.externalId}`, {\n installationExternalId: installation.externalId,\n repositoryExternalId: repository.externalId,\n });\n }\n }\n return [...keys.values()];\n },\n listByExternalRepository: async ({\n installationExternalId,\n repositoryExternalId,\n }: {\n installationExternalId: string;\n repositoryExternalId: string;\n }): Promise<ExternalRepositoryProjectTarget[]> => {\n const targets: ExternalRepositoryProjectTarget[] = [];\n for (const installation of this.installationsRows.filter(row => row.externalId === installationExternalId)) {\n const repository = this.repositoriesRows.find(\n row => row.installationId === installation.id && row.externalId === repositoryExternalId,\n );\n if (!repository) continue;\n for (const projectRepository of this.projectRepositoriesRows.filter(\n row => row.repositoryId === repository.id,\n )) {\n const connection = this.connectionsRows.find(\n row =>\n row.id === projectRepository.connectionId &&\n row.installationId === installation.id &&\n row.integrationId === this.integrationId,\n );\n if (!connection) continue;\n targets.push({\n orgId: installation.orgId,\n factoryProjectId: connection.factoryProjectId,\n projectRepository,\n });\n }\n }\n return targets;\n },\n get: async ({ orgId, id }: { orgId: string; id: string }): Promise<ProjectRepository | null> => {\n const row = this.projectRepositoriesRows.find(candidate => candidate.id === id);\n if (!row) return null;\n return (await this.connections.get({ orgId, id: row.connectionId })) ? row : null;\n },\n link: async (input: LinkProjectRepositoryInput): Promise<ProjectRepository> => {\n const connection = await this.connections.get({ orgId: input.orgId, id: input.connectionId });\n const repository = await this.repositories.get({ orgId: input.orgId, id: input.repositoryId });\n if (!connection || !repository || repository.installationId !== connection.installationId) {\n throw new Error('Source-control connection or repository not found');\n }\n const existing = this.projectRepositoriesRows.find(\n row => row.connectionId === input.connectionId && row.repositoryId === input.repositoryId,\n );\n if (existing) return existing;\n const now = new Date();\n const created: ProjectRepository = {\n id: randomUUID(),\n connectionId: input.connectionId,\n repositoryId: input.repositoryId,\n createdByUserId: input.createdByUserId,\n branch: input.branch ?? null,\n sandboxProvider: input.sandboxProvider,\n sandboxWorkdir: input.sandboxWorkdir,\n setupCommand: input.setupCommand ?? null,\n baseCheckpoint: null,\n teardownCommand: input.teardownCommand ?? null,\n createdAt: now,\n updatedAt: now,\n };\n this.projectRepositoriesRows.push(created);\n return created;\n },\n update: async ({\n orgId,\n id,\n input,\n }: {\n orgId: string;\n id: string;\n input: UpdateProjectRepositoryInput;\n }): Promise<ProjectRepository | null> => {\n const row = await this.projectRepositories.get({ orgId, id });\n if (!row) return null;\n if (input.setupCommand !== undefined && input.setupCommand !== row.setupCommand) {\n row.baseCheckpoint = null;\n }\n Object.assign(row, input, { updatedAt: new Date() });\n return row;\n },\n setBaseCheckpoint: async (\n args:\n | { id: string; checkpoint: null }\n | { id: string; checkpoint: ProjectRepositoryBaseCheckpoint; expectedSetupCommand: string | null },\n ): Promise<void> => {\n const row = this.projectRepositoriesRows.find(candidate => candidate.id === args.id);\n if (!row) throw new Error('Project repository not found');\n if (args.checkpoint && row.setupCommand !== args.expectedSetupCommand) return;\n row.baseCheckpoint = args.checkpoint;\n },\n unlink: async ({ orgId, id }: { orgId: string; id: string }): Promise<boolean> => {\n if (!(await this.projectRepositories.get({ orgId, id }))) return false;\n this.projectRepositoriesRows.splice(\n 0,\n this.projectRepositoriesRows.length,\n ...this.projectRepositoriesRows.filter(row => row.id !== id),\n );\n return true;\n },\n };\n\n readonly sandboxes = {\n getOrCreate: async ({\n projectRepository,\n userId,\n }: {\n projectRepository: ProjectRepository;\n userId: string;\n }): Promise<ProjectRepositorySandbox> => {\n const existing = this.sandboxesRows.find(\n row => row.projectRepositoryId === projectRepository.id && row.userId === userId,\n );\n if (existing) return existing;\n const created: ProjectRepositorySandbox = {\n id: randomUUID(),\n projectRepositoryId: projectRepository.id,\n userId,\n sandboxId: null,\n sandboxWorkdir: projectRepository.sandboxWorkdir,\n materializedAt: null,\n createdAt: new Date(),\n };\n this.sandboxesRows.push(created);\n return created;\n },\n getById: async ({ id }: { id: string }): Promise<ProjectRepositorySandbox | null> =>\n this.sandboxesRows.find(row => row.id === id) ?? null,\n setWorkdir: async ({ id, sandboxWorkdir }: { id: string; sandboxWorkdir: string }): Promise<void> => {\n const row = this.sandboxesRows.find(candidate => candidate.id === id);\n if (row) Object.assign(row, { sandboxWorkdir, materializedAt: null });\n },\n setSandboxId: async ({ id, sandboxId }: { id: string; sandboxId: string }): Promise<void> => {\n const row = this.sandboxesRows.find(candidate => candidate.id === id);\n if (row) row.sandboxId = sandboxId;\n },\n clearBinding: async ({ id }: { id: string }): Promise<void> => {\n const row = this.sandboxesRows.find(candidate => candidate.id === id);\n if (row) Object.assign(row, { sandboxId: null, materializedAt: null });\n },\n markMaterialized: async ({ id }: { id: string }): Promise<void> => {\n const row = this.sandboxesRows.find(candidate => candidate.id === id);\n if (row) row.materializedAt = new Date();\n },\n };\n\n readonly sandboxPool = {\n release: async (input: ReleasePooledSandboxInput): Promise<void> => {\n // Mirror the SQL implementation: a missing project-repository link\n // makes the release a silent no-op.\n if (!this.projectRepositoriesRows.some(row => row.id === input.projectRepositoryId)) return;\n if (this.sandboxPoolRows.some(row => row.sandboxId === input.sandboxId)) return;\n this.sandboxPoolRows.push({ id: randomUUID(), releasedAt: new Date(), ...input });\n },\n claim: async ({ projectRepositoryId }: { projectRepositoryId: string }): Promise<PooledSandbox | null> => {\n const candidates = this.sandboxPoolRows\n .filter(row => row.projectRepositoryId === projectRepositoryId)\n .sort((left, right) => right.releasedAt.getTime() - left.releasedAt.getTime());\n const claimed = candidates[0];\n if (!claimed) return null;\n this.sandboxPoolRows.splice(this.sandboxPoolRows.indexOf(claimed), 1);\n return claimed;\n },\n };\n\n readonly worktrees = {\n upsert: async (input: UpsertSourceControlWorktreeInput): Promise<void> => {\n const existing = this.worktreesRows.find(\n row =>\n row.projectRepositoryId === input.projectRepositoryId &&\n row.userId === input.userId &&\n row.branch === input.branch,\n );\n if (existing) {\n existing.baseBranch = input.baseBranch;\n existing.worktreePath = input.worktreePath;\n return;\n }\n this.worktreesRows.push({ id: randomUUID(), createdAt: new Date(), ...input });\n },\n list: async ({\n projectRepositoryId,\n userId,\n }: {\n projectRepositoryId: string;\n userId: string;\n }): Promise<SourceControlWorktree[]> =>\n this.worktreesRows.filter(row => row.projectRepositoryId === projectRepositoryId && row.userId === userId),\n get: async ({\n projectRepositoryId,\n userId,\n branch,\n }: {\n projectRepositoryId: string;\n userId: string;\n branch: string;\n }): Promise<SourceControlWorktree | null> =>\n this.worktreesRows.find(\n row => row.projectRepositoryId === projectRepositoryId && row.userId === userId && row.branch === branch,\n ) ?? null,\n findByPath: async ({\n projectRepositoryId,\n userId,\n worktreePath,\n }: {\n projectRepositoryId: string;\n userId: string;\n worktreePath: string;\n }): Promise<SourceControlWorktree | null> =>\n this.worktreesRows.find(\n row =>\n row.projectRepositoryId === projectRepositoryId && row.userId === userId && row.worktreePath === worktreePath,\n ) ?? null,\n delete: async ({\n projectRepositoryId,\n userId,\n branch,\n }: {\n projectRepositoryId: string;\n userId: string;\n branch: string;\n }): Promise<void> => {\n this.worktreesRows.splice(\n 0,\n this.worktreesRows.length,\n ...this.worktreesRows.filter(\n row => !(row.projectRepositoryId === projectRepositoryId && row.userId === userId && row.branch === branch),\n ),\n );\n },\n };\n\n readonly sessions = {\n list: async ({ projectRepositoryId, viewerUserId }: { projectRepositoryId: string; viewerUserId: string }) =>\n this.sessionsRows.filter(\n row =>\n row.projectRepositoryId === projectRepositoryId &&\n (row.visibility !== 'private' || row.userId === viewerUserId),\n ),\n listByProjectRepository: async ({ projectRepositoryId }: { projectRepositoryId: string }) =>\n this.sessionsRows.filter(row => row.projectRepositoryId === projectRepositoryId),\n getBySessionId: async (sessionId: string): Promise<SourceControlSession | null> =>\n this.sessionsRows.find(row => row.sessionId === sessionId) ?? null,\n getForBranch: async ({\n projectRepositoryId,\n userId,\n branch,\n }: {\n projectRepositoryId: string;\n userId: string;\n branch: string;\n }): Promise<SourceControlSession | null> =>\n this.sessionsRows.find(\n row => row.projectRepositoryId === projectRepositoryId && row.userId === userId && row.branch === branch,\n ) ?? null,\n create: async (input: CreateSourceControlSessionInput): Promise<SourceControlSession> => {\n const existing = await this.sessions.getForBranch(input);\n if (existing) return existing;\n if (this.sessionsRows.some(row => row.sessionId === input.sessionId)) {\n throw new UniqueViolationError('Source-control session ID already exists');\n }\n const now = new Date();\n const session: SourceControlSession = {\n id: randomUUID(),\n ...input,\n title: input.title ?? null,\n visibility: input.visibility ?? 'org',\n sandboxId: null,\n sandboxWorkdir: null,\n materializedAt: null,\n firstMessageAt: null,\n firstMeaningfulExecAt: null,\n createdAt: now,\n updatedAt: now,\n };\n this.sessionsRows.push(session);\n return session;\n },\n setSandbox: async ({\n id,\n sandboxId,\n sandboxWorkdir,\n }: {\n id: string;\n sandboxId: string | null;\n sandboxWorkdir: string;\n }) => {\n const row = this.sessionsRows.find(candidate => candidate.id === id);\n if (row) Object.assign(row, { sandboxId, sandboxWorkdir, updatedAt: new Date() });\n },\n markMaterialized: async ({ id }: { id: string }) => {\n const row = this.sessionsRows.find(candidate => candidate.id === id);\n if (row && row.materializedAt === null) Object.assign(row, { materializedAt: new Date(), updatedAt: new Date() });\n },\n markFirstMessage: async ({ sessionId }: { sessionId: string }) => {\n const row = this.sessionsRows.find(candidate => candidate.sessionId === sessionId);\n if (row && row.firstMessageAt === null) Object.assign(row, { firstMessageAt: new Date(), updatedAt: new Date() });\n },\n markFirstMeaningfulExec: async ({ sessionId }: { sessionId: string }) => {\n const row = this.sessionsRows.find(candidate => candidate.sessionId === sessionId);\n if (row && row.firstMeaningfulExecAt === null) {\n Object.assign(row, { firstMeaningfulExecAt: new Date(), updatedAt: new Date() });\n }\n },\n delete: async (id: string) => {\n this.sessionsRows.splice(0, this.sessionsRows.length, ...this.sessionsRows.filter(row => row.id !== id));\n },\n };\n}\n"],"mappings":";;;;AA2BA,IAAa,+BAAb,MAAgF;CAC9E;CACA,oBAAiD,CAAC;CAClD,mBAA8C,CAAC;CAC/C,kBAAoD,CAAC;CACrD,0BAA+C,CAAC;CAChD,gBAA4C,CAAC;CAC7C,kBAAmC,CAAC;CACpC,gBAAyC,CA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KAAK;GAAE,CAAC;EAClH;EACA,kBAAkB,OAAO,EAAE,gBAAuC;GAChE,MAAM,MAAM,KAAK,aAAa,MAAK,cAAa,UAAU,cAAc,SAAS;GACjF,IAAI,OAAO,IAAI,mBAAmB,MAAM,OAAO,OAAO,KAAK;IAAE,gCAAgB,IAAI,KAAK;IAAG,2BAAW,IAAI,KAAK;GAAE,CAAC;EAClH;EACA,yBAAyB,OAAO,EAAE,gBAAuC;GACvE,MAAM,MAAM,KAAK,aAAa,MAAK,cAAa,UAAU,cAAc,SAAS;GACjF,IAAI,OAAO,IAAI,0BAA0B,MACvC,OAAO,OAAO,KAAK;IAAE,uCAAuB,IAAI,KAAK;IAAG,2BAAW,IAAI,KAAK;GAAE,CAAC;EAEnF;EACA,QAAQ,OAAO,OAAe;GAC5B,KAAK,aAAa,OAAO,GAAG,KAAK,aAAa,QAAQ,GAAG,KAAK,aAAa,QAAO,QAAO,IAAI,OAAO,EAAE,CAAC;EACzG;CACF;AACF"}
@@ -168,6 +168,17 @@ export interface RevokeFactoryRunBindingInput {
168
168
  bindingId: string;
169
169
  revokedAt: Date;
170
170
  }
171
+ export interface RevokeStaleFactoryRunBindingsInput {
172
+ /** Active bindings created before this instant are revoked regardless of item state. */
173
+ olderThan: Date;
174
+ now: Date;
175
+ }
176
+ export interface RevokeFactoryRunBindingsForWorkItemInput {
177
+ orgId: string;
178
+ factoryProjectId: string;
179
+ workItemId: string;
180
+ revokedAt: Date;
181
+ }
171
182
  export interface FactoryRunBindingRecord {
172
183
  id: string;
173
184
  orgId: string;
@@ -242,6 +253,8 @@ export interface CommitFactoryTransitionInput {
242
253
  code: string;
243
254
  reason: string;
244
255
  };
256
+ /** Arm autonomy in the same revision-checked update that commits the transition. */
257
+ armAutonomy?: boolean;
245
258
  }
246
259
  export type CommitFactoryTransitionResult = {
247
260
  status: 'committed';
@@ -267,6 +280,8 @@ export interface PrepareFactoryRunStartInput {
267
280
  resourceId: string;
268
281
  kickoffKey: string;
269
282
  kickoffMessage: string | null;
283
+ /** Arm the item's autonomy in the same transaction that prepares the run. */
284
+ armAutonomy?: boolean;
270
285
  }
271
286
  export interface PrepareFactoryRunStartResult {
272
287
  item: WorkItemRow;
@@ -292,6 +307,13 @@ export interface WorkItemRow {
292
307
  stageHistory: WorkItemStageEntry[];
293
308
  sessions: WorkItemSessions;
294
309
  metadata: Record<string, unknown> | null;
310
+ /**
311
+ * When a person first committed this item to the Factory, by starting a run
312
+ * on it or releasing one that was proposed. Projects that withhold auto-run
313
+ * are asking to decide what the Factory picks up, not to approve each step of
314
+ * work they already asked for, so runs on an armed item skip the gate.
315
+ */
316
+ autonomyArmedAt: Date | null;
295
317
  revision: number;
296
318
  createdBy: string;
297
319
  createdAt: Date;
@@ -362,10 +384,30 @@ export declare class WorkItemsStorage extends FactoryStorageDomain {
362
384
  failDeferredDecision(input: FactoryDispatchFailureInput): Promise<FactoryDeferredDecisionRecord | null>;
363
385
  /** Park a claimed effect for human approval; the dispatcher never claims `proposed` rows. */
364
386
  proposeDeferredDecision(identity: FactoryLeaseIdentity, now: Date): Promise<FactoryDeferredDecisionRecord | null>;
365
- /** Release an approved effect back to the dispatcher; only `proposed` rows are approvable. */
387
+ /**
388
+ * Release an approved effect back to the dispatcher; only `proposed` rows are
389
+ * approvable. Approval is a person taking the item on, so the item's autonomy
390
+ * is armed in the same transaction — a crash cannot release the run while
391
+ * leaving its follow-up work parked for re-approval.
392
+ */
366
393
  approveDeferredDecision(orgId: string, factoryProjectId: string, decisionId: string, now: Date): Promise<FactoryDeferredDecisionRecord | null>;
367
394
  /** Retire a proposal nobody wants: `dismissed` is terminal, so the run never happens. */
368
395
  dismissDeferredDecision(orgId: string, factoryProjectId: string, decisionId: string, now: Date): Promise<FactoryDeferredDecisionRecord | null>;
396
+ /**
397
+ * Retire proposals parked on a work item. A merged pull request (or an item
398
+ * closed out any other way) leaves its queued runs with nothing left to do,
399
+ * and they would otherwise sit on the card forever asking to be answered.
400
+ *
401
+ * Pass `role` to retire only the proposals a run now starting has overtaken:
402
+ * a parked "start triage" is moot the moment triage is actually running.
403
+ */
404
+ dismissProposalsForWorkItem(input: {
405
+ orgId: string;
406
+ factoryProjectId: string;
407
+ workItemId: string;
408
+ role?: string;
409
+ dismissedAt: Date;
410
+ }): Promise<FactoryDeferredDecisionRecord[]>;
369
411
  /** Requeue the same idempotent terminal effect; non-failed decisions are never rerun. */
370
412
  retryDeferredDecision(orgId: string, factoryProjectId: string, decisionId: string, now: Date): Promise<FactoryDeferredDecisionRecord | null>;
371
413
  /** Resolve exact active agent authority; partial session matches never authorize. */
@@ -385,6 +427,19 @@ export declare class WorkItemsStorage extends FactoryStorageDomain {
385
427
  findRunBindingBySession(address: FactoryRunBindingSessionAddress): Promise<FactoryRunBindingRecord | null>;
386
428
  /** Revoke one exact tenant-scoped binding. */
387
429
  revokeRunBinding(input: RevokeFactoryRunBindingInput): Promise<FactoryRunBindingRecord | null>;
430
+ /**
431
+ * Revoke every active binding for one work item (all roles). Called from
432
+ * terminal-stage cleanup so completed items stop paying the reconcile walk.
433
+ * Returns the number of bindings revoked.
434
+ */
435
+ revokeRunBindingsForWorkItem(input: RevokeFactoryRunBindingsForWorkItemInput): Promise<number>;
436
+ /**
437
+ * Revoke leaked/legacy active bindings: older than `olderThan`, or whose
438
+ * work item is gone, malformed, or already terminal. Terminal-stage cleanup
439
+ * handles bindings go-forward; this sweep drains anything that slipped past
440
+ * it. Returns the number of bindings revoked.
441
+ */
442
+ revokeStaleRunBindings(input: RevokeStaleFactoryRunBindingsInput): Promise<number>;
388
443
  /** Enumerate active bindings for the server-owned restart reconciler. */
389
444
  listActiveRunBindings(): Promise<FactoryRunBindingRecord[]>;
390
445
  /** List binding history, optionally narrowed to one work item. */
@@ -420,6 +475,17 @@ export declare class WorkItemsStorage extends FactoryStorageDomain {
420
475
  item: WorkItemRow;
421
476
  previous: WorkItemPriorState;
422
477
  } | null>;
478
+ /**
479
+ * Record that a person committed this item to the Factory. Only the first
480
+ * time counts: the timestamp marks when the item stopped needing permission,
481
+ * so later runs must not push it forward. Bumps no revision, because arming
482
+ * is not a change anyone is editing against.
483
+ */
484
+ armAutonomy({ orgId, id, now }: {
485
+ orgId: string;
486
+ id: string;
487
+ now: Date;
488
+ }): Promise<void>;
423
489
  delete({ orgId, id }: {
424
490
  orgId: string;
425
491
  id: string;
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/work-items/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EAAE,oBAAoB,EAAwB,MAAM,sBAAsB,CAAC;AAClF,OAAO,KAAK,EAAE,gBAAgB,EAAqB,MAAM,sBAAsB,CAAC;AAEhF,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAanC,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAE7E;AAED,MAAM,WAAW,sBAAsB;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,aAAa,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAG5D;AAED,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,wBAAwB;IACvC,EAAE,EAAE,MAAM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B,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC;IAS5C;;;;;;;OAOG;IACG,MAAM,CAAC,MAAM,EAAE;QACnB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;QACf,gBAAgB,EAAE,MAAM,CAAC;QACzB,KAAK,EAAE,mBAAmB,CAAC;QAC3B,SAAS,CAAC,EAAE,QAAQ,GAAG,UAAU,GAAG,WAAW,CAAC;KACjD,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAwG3B,MAAM,CAAC,EACX,KAAK,EACL,EAAE,EACF,MAAM,EACN,KAAK,GACN,EAAE;QACD,KAAK,EAAE,MAAM,CAAC;QACd,EAAE,EAAE,MAAM,CAAC;QACX,MAAM,EAAE,MAAM,CAAC;QACf,KAAK,EAAE,mBAAmB,CAAC;KAC5B,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,WAAW,CAAC;QAAC,QAAQ,EAAE,kBAAkB,CAAA;KAAE,GAAG,IAAI,CAAC;IAuBvE;;;;;OAKG;IACG,WAAW,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA0CxF,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;CAwBxF"}
@@ -32,6 +32,18 @@ function isAgentActor(by) {
32
32
  if (by === void 0) return false;
33
33
  return by.startsWith("agent:") || by === "factory-tool-result-rule";
34
34
  }
35
+ /**
36
+ * Stages in which a bound run can still act on its work item. Mirrors the
37
+ * non-terminal subset of `FACTORY_RULE_STAGES` (rules/types.ts); bindings for
38
+ * items outside these stages are dead weight in the reconcile walk.
39
+ */
40
+ const ACTIVE_RUN_BINDING_STAGES = /* @__PURE__ */ new Set([
41
+ "intake",
42
+ "triage",
43
+ "planning",
44
+ "execute",
45
+ "review"
46
+ ]);
35
47
  const WORK_ITEMS_SCHEMA = {
36
48
  name: "work_items",
37
49
  columns: {
@@ -58,6 +70,10 @@ const WORK_ITEMS_SCHEMA = {
58
70
  type: "json",
59
71
  nullable: true
60
72
  },
73
+ autonomy_armed_at: {
74
+ type: "timestamp",
75
+ nullable: true
76
+ },
61
77
  revision: {
62
78
  type: "integer",
63
79
  default: 1
@@ -101,6 +117,7 @@ function toWorkItem(row) {
101
117
  stageHistory: row.stage_history,
102
118
  sessions: row.sessions,
103
119
  metadata: row.metadata,
120
+ autonomyArmedAt: row.autonomy_armed_at ?? null,
104
121
  revision: row.revision,
105
122
  createdBy: row.created_by,
106
123
  createdAt: row.created_at,
@@ -116,6 +133,7 @@ function patchColumns(changes) {
116
133
  ...changes.stageHistory !== void 0 ? { stage_history: changes.stageHistory } : {},
117
134
  ...changes.sessions !== void 0 ? { sessions: changes.sessions } : {},
118
135
  ...changes.metadata !== void 0 ? { metadata: changes.metadata } : {},
136
+ ...changes.autonomyArmedAt !== void 0 && changes.autonomyArmedAt !== null ? { autonomy_armed_at: changes.autonomyArmedAt } : {},
119
137
  ...changes.revision !== void 0 ? { revision: changes.revision } : {},
120
138
  ...changes.updatedAt !== void 0 ? { updated_at: changes.updatedAt } : {}
121
139
  };
@@ -213,6 +231,13 @@ function withInProcessProjectLock(key, fn) {
213
231
  });
214
232
  return result;
215
233
  }
234
+ /** Source key a decision materializes, used to purge governance rows when the item is deleted. */
235
+ function decisionSourceKey(decision) {
236
+ if (typeof decision !== "object" || decision === null) return null;
237
+ const record = decision;
238
+ if (record.type !== "upsertLinkedWorkItem" || typeof record.sourceKey !== "string") return null;
239
+ return record.sourceKey;
240
+ }
216
241
  const FACTORY_GOVERNANCE_SCHEMAS = [
217
242
  {
218
243
  name: "factory_rule_ingress",
@@ -273,6 +298,10 @@ const FACTORY_GOVERNANCE_SCHEMAS = [
273
298
  type: "text",
274
299
  nullable: true
275
300
  },
301
+ source_key: {
302
+ type: "text",
303
+ nullable: true
304
+ },
276
305
  idempotency_key: { type: "text" },
277
306
  effect_ordinal: { type: "integer" },
278
307
  effect_hash: { type: "text" },
@@ -653,8 +682,10 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
653
682
  reason = input.evaluation.reason;
654
683
  return null;
655
684
  }
656
- if (existing.stages.length === 1 && existing.stages[0] === input.destinationStage) return null;
685
+ const arm = input.armAutonomy === true && !existing.autonomyArmedAt;
686
+ if (existing.stages.length === 1 && existing.stages[0] === input.destinationStage) return arm ? patchColumns({ autonomyArmedAt: now }) : null;
657
687
  return patchColumns({
688
+ ...arm ? { autonomyArmedAt: now } : {},
658
689
  stages: [input.destinationStage],
659
690
  stageHistory: applyStageTransition(existing.stageHistory, existing.stages, [input.destinationStage], input.actorId, now),
660
691
  revision: existing.revision + 1,
@@ -707,6 +738,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
707
738
  factory_project_id: input.factoryProjectId,
708
739
  evaluation_id: evaluation.id,
709
740
  work_item_id: item.id,
741
+ source_key: decisionSourceKey(decision),
710
742
  idempotency_key: String(decision.idempotencyKey),
711
743
  effect_ordinal: index,
712
744
  effect_hash: factoryDecisionHash(decision),
@@ -822,6 +854,7 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
822
854
  factory_project_id: input.factoryProjectId,
823
855
  evaluation_id: evaluation.id,
824
856
  work_item_id: item?.id ?? null,
857
+ source_key: decisionSourceKey(decision),
825
858
  idempotency_key: String(decision.idempotencyKey),
826
859
  effect_ordinal: effectOrdinal,
827
860
  effect_hash: factoryDecisionHash(decision),
@@ -933,18 +966,37 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
933
966
  });
934
967
  return proposed && row ? toDeferredDecision(row) : null;
935
968
  }
936
- /** Release an approved effect back to the dispatcher; only `proposed` rows are approvable. */
969
+ /**
970
+ * Release an approved effect back to the dispatcher; only `proposed` rows are
971
+ * approvable. Approval is a person taking the item on, so the item's autonomy
972
+ * is armed in the same transaction — a crash cannot release the run while
973
+ * leaving its follow-up work parked for re-approval.
974
+ */
937
975
  async approveDeferredDecision(orgId, factoryProjectId, decisionId, now) {
938
- return this.#settleProposedDecision({
939
- orgId,
940
- factoryProjectId,
941
- decisionId
942
- }, {
943
- status: "pending",
944
- attempts: 0,
945
- available_at: now,
946
- approved_at: now,
947
- updated_at: now
976
+ return this.storage.withTransaction(async (ops) => {
977
+ let settled = false;
978
+ const row = await ops.updateAtomic("factory_deferred_decisions", {
979
+ id: decisionId,
980
+ org_id: orgId,
981
+ factory_project_id: factoryProjectId
982
+ }, (current) => {
983
+ if (current.status !== "proposed") return null;
984
+ settled = true;
985
+ return {
986
+ status: "pending",
987
+ attempts: 0,
988
+ available_at: now,
989
+ approved_at: now,
990
+ updated_at: now
991
+ };
992
+ });
993
+ if (!settled || !row) return null;
994
+ const record = toDeferredDecision(row);
995
+ if (record.workItemId) await ops.updateAtomic("work_items", {
996
+ org_id: orgId,
997
+ id: record.workItemId
998
+ }, (current) => current.autonomy_armed_at ? null : { autonomy_armed_at: now });
999
+ return record;
948
1000
  });
949
1001
  }
950
1002
  /** Retire a proposal nobody wants: `dismissed` is terminal, so the run never happens. */
@@ -959,6 +1011,29 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
959
1011
  completed_at: now
960
1012
  });
961
1013
  }
1014
+ /**
1015
+ * Retire proposals parked on a work item. A merged pull request (or an item
1016
+ * closed out any other way) leaves its queued runs with nothing left to do,
1017
+ * and they would otherwise sit on the card forever asking to be answered.
1018
+ *
1019
+ * Pass `role` to retire only the proposals a run now starting has overtaken:
1020
+ * a parked "start triage" is moot the moment triage is actually running.
1021
+ */
1022
+ async dismissProposalsForWorkItem(input) {
1023
+ const rows = await this.#db.findMany("factory_deferred_decisions", {
1024
+ org_id: input.orgId,
1025
+ factory_project_id: input.factoryProjectId,
1026
+ work_item_id: input.workItemId,
1027
+ status: "proposed"
1028
+ });
1029
+ const dismissed = [];
1030
+ for (const row of rows) {
1031
+ if (input.role !== void 0 && toDeferredDecision(row).decision.role !== input.role) continue;
1032
+ const record = await this.dismissDeferredDecision(input.orgId, input.factoryProjectId, row.id, input.dismissedAt);
1033
+ if (record) dismissed.push(record);
1034
+ }
1035
+ return dismissed;
1036
+ }
962
1037
  async #settleProposedDecision({ orgId, factoryProjectId, decisionId }, patch) {
963
1038
  let settled = false;
964
1039
  const row = await this.#db.updateAtomic("factory_deferred_decisions", {
@@ -1057,6 +1132,56 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
1057
1132
  });
1058
1133
  return revoked && row ? toBinding(row) : null;
1059
1134
  }
1135
+ /**
1136
+ * Revoke every active binding for one work item (all roles). Called from
1137
+ * terminal-stage cleanup so completed items stop paying the reconcile walk.
1138
+ * Returns the number of bindings revoked.
1139
+ */
1140
+ async revokeRunBindingsForWorkItem(input) {
1141
+ return this.#db.updateMany("factory_run_bindings", {
1142
+ org_id: input.orgId,
1143
+ factory_project_id: input.factoryProjectId,
1144
+ work_item_id: input.workItemId,
1145
+ status: "active"
1146
+ }, {
1147
+ status: "revoked",
1148
+ revoked_at: input.revokedAt
1149
+ });
1150
+ }
1151
+ /**
1152
+ * Revoke leaked/legacy active bindings: older than `olderThan`, or whose
1153
+ * work item is gone, malformed, or already terminal. Terminal-stage cleanup
1154
+ * handles bindings go-forward; this sweep drains anything that slipped past
1155
+ * it. Returns the number of bindings revoked.
1156
+ */
1157
+ async revokeStaleRunBindings(input) {
1158
+ const bindings = await this.listActiveRunBindings();
1159
+ const itemCache = /* @__PURE__ */ new Map();
1160
+ let revoked = 0;
1161
+ for (const binding of bindings) {
1162
+ let stale = binding.createdAt.getTime() < input.olderThan.getTime();
1163
+ if (!stale) {
1164
+ const key = `${binding.orgId}:${binding.workItemId}`;
1165
+ let item = itemCache.get(key);
1166
+ if (item === void 0) {
1167
+ item = await this.get({
1168
+ orgId: binding.orgId,
1169
+ id: binding.workItemId
1170
+ });
1171
+ itemCache.set(key, item);
1172
+ }
1173
+ stale = !item || item.stages.length !== 1 || !ACTIVE_RUN_BINDING_STAGES.has(item.stages[0]) || item.factoryProjectId !== binding.factoryProjectId;
1174
+ }
1175
+ if (!stale) continue;
1176
+ if (await this.revokeRunBinding({
1177
+ orgId: binding.orgId,
1178
+ factoryProjectId: binding.factoryProjectId,
1179
+ bindingId: binding.id,
1180
+ revokedAt: input.now
1181
+ })) revoked += 1;
1182
+ }
1183
+ return revoked;
1184
+ }
1060
1185
  /** Enumerate active bindings for the server-owned restart reconciler. */
1061
1186
  async listActiveRunBindings() {
1062
1187
  return (await this.#db.findMany("factory_run_bindings", { status: "active" })).map(toBinding);
@@ -1161,6 +1286,10 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
1161
1286
  });
1162
1287
  item = toRow(row);
1163
1288
  }
1289
+ if (input.armAutonomy && !item.autonomyArmedAt) {
1290
+ const armedRow = await ops.updateAtomic("work_items", { id: item.id }, (current) => current.autonomy_armed_at ? null : { autonomy_armed_at: now });
1291
+ if (armedRow) item = toRow(armedRow);
1292
+ }
1164
1293
  await ops.updateMany("factory_run_bindings", {
1165
1294
  org_id: input.orgId,
1166
1295
  factory_project_id: input.factoryProjectId,
@@ -1358,6 +1487,43 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
1358
1487
  if (!candidate) return null;
1359
1488
  return this.#withProjectRelationTransaction(orgId, candidate.factory_project_id, run);
1360
1489
  }
1490
+ /**
1491
+ * Record that a person committed this item to the Factory. Only the first
1492
+ * time counts: the timestamp marks when the item stopped needing permission,
1493
+ * so later runs must not push it forward. Bumps no revision, because arming
1494
+ * is not a change anyone is editing against.
1495
+ */
1496
+ async armAutonomy({ orgId, id, now }) {
1497
+ await this.#db.updateAtomic("work_items", {
1498
+ org_id: orgId,
1499
+ id
1500
+ }, (current) => current.autonomy_armed_at ? null : { autonomy_armed_at: now });
1501
+ }
1502
+ /**
1503
+ * Drop the governance rows that materialized a source key so a deleted work item
1504
+ * is not resurrected by the prior-ingress replay path on the next intake poll.
1505
+ */
1506
+ async #purgeRuleState(ops, { orgId, factoryProjectId, sourceKey }) {
1507
+ const decisions = await ops.findMany("factory_deferred_decisions", {
1508
+ org_id: orgId,
1509
+ factory_project_id: factoryProjectId,
1510
+ source_key: sourceKey
1511
+ });
1512
+ if (decisions.length === 0) return;
1513
+ const evaluationIds = [...new Set(decisions.map((decision) => String(decision.evaluation_id)))];
1514
+ const ingressIds = /* @__PURE__ */ new Set();
1515
+ for (const evaluationId of evaluationIds) {
1516
+ const evaluation = await ops.findOne("factory_rule_evaluations", { id: evaluationId });
1517
+ if (evaluation) ingressIds.add(String(evaluation.ingress_id));
1518
+ }
1519
+ await ops.deleteMany("factory_deferred_decisions", {
1520
+ org_id: orgId,
1521
+ factory_project_id: factoryProjectId,
1522
+ source_key: sourceKey
1523
+ });
1524
+ for (const evaluationId of evaluationIds) await ops.deleteMany("factory_rule_evaluations", { id: evaluationId });
1525
+ for (const ingressId of ingressIds) if ((await ops.findMany("factory_rule_evaluations", { ingress_id: ingressId })).length === 0) await ops.deleteMany("factory_rule_ingress", { id: ingressId });
1526
+ }
1361
1527
  async delete({ orgId, id }) {
1362
1528
  const candidate = await this.#db.findOne("work_items", {
1363
1529
  org_id: orgId,
@@ -1374,6 +1540,11 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
1374
1540
  org_id: orgId,
1375
1541
  id
1376
1542
  }) === 0) return null;
1543
+ if (existing.source_key) await this.#purgeRuleState(ops, {
1544
+ orgId,
1545
+ factoryProjectId: existing.factory_project_id,
1546
+ sourceKey: existing.source_key
1547
+ });
1377
1548
  await ops.updateMany("work_items", {
1378
1549
  org_id: orgId,
1379
1550
  parent_work_item_id: id