@mastra/factory 0.27.0-alpha.2 → 0.27.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.
- package/README.md +94 -47
- package/dist/boards/card-facts.d.ts +4 -2
- package/dist/boards/card-facts.d.ts.map +1 -1
- package/dist/boards/card-facts.js +7 -4
- package/dist/boards/card-facts.js.map +1 -1
- package/dist/boards/define-board.d.ts +2 -0
- package/dist/boards/define-board.d.ts.map +1 -1
- package/dist/boards/define-board.js +1 -0
- package/dist/boards/define-board.js.map +1 -1
- package/dist/boards/intake-routing.d.ts +2 -2
- package/dist/boards/intake-routing.d.ts.map +1 -1
- package/dist/boards/intake-routing.js.map +1 -1
- package/dist/boards/phase-automation.d.ts +4 -4
- package/dist/boards/phase-automation.d.ts.map +1 -1
- package/dist/boards/phase-automation.js.map +1 -1
- package/dist/boards/pull-request-review.d.ts +0 -7
- package/dist/boards/pull-request-review.d.ts.map +1 -1
- package/dist/boards/pull-request-review.js +15 -14
- package/dist/boards/pull-request-review.js.map +1 -1
- package/dist/boards/relocate.d.ts +4 -4
- package/dist/boards/relocate.d.ts.map +1 -1
- package/dist/boards/relocate.js +1 -1
- package/dist/boards/relocate.js.map +1 -1
- package/dist/boards/review.d.ts.map +1 -1
- package/dist/boards/review.js +1 -2
- package/dist/boards/review.js.map +1 -1
- package/dist/boards/semantics.d.ts +8 -8
- package/dist/boards/semantics.d.ts.map +1 -1
- package/dist/boards/semantics.js.map +1 -1
- package/dist/boards/transition-policy.d.ts +7 -0
- package/dist/boards/transition-policy.d.ts.map +1 -1
- package/dist/boards/transition-policy.js.map +1 -1
- package/dist/boards/work.d.ts +6 -0
- package/dist/boards/work.d.ts.map +1 -1
- package/dist/boards/work.js +71 -25
- package/dist/boards/work.js.map +1 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +6 -15
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/integrations/github/acceptance-labels.d.ts +2 -2
- package/dist/integrations/github/acceptance-labels.d.ts.map +1 -1
- package/dist/integrations/github/acceptance-labels.js +2 -2
- package/dist/integrations/github/acceptance-labels.js.map +1 -1
- package/dist/integrations/github/default-rules.d.ts +5 -11
- package/dist/integrations/github/default-rules.d.ts.map +1 -1
- package/dist/integrations/github/default-rules.js +6 -22
- package/dist/integrations/github/default-rules.js.map +1 -1
- package/dist/integrations/github/issue-reconciler.js +6 -4
- package/dist/integrations/github/issue-reconciler.js.map +1 -1
- package/dist/integrations/github/provenance.d.ts +2 -2
- package/dist/integrations/github/provenance.d.ts.map +1 -1
- package/dist/integrations/github/provenance.js.map +1 -1
- package/dist/integrations/github/routes.d.ts.map +1 -1
- package/dist/integrations/github/routes.js +46 -1
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/rules.d.ts +3 -3
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +43 -39
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/gitlab/default-rules.d.ts +2 -9
- package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/default-rules.js +2 -19
- package/dist/integrations/gitlab/default-rules.js.map +1 -1
- package/dist/integrations/gitlab/issue-reconciler.js +2 -2
- package/dist/integrations/gitlab/issue-reconciler.js.map +1 -1
- package/dist/integrations/gitlab/merge-request-reconciler.d.ts.map +1 -1
- package/dist/integrations/gitlab/merge-request-reconciler.js +11 -11
- package/dist/integrations/gitlab/merge-request-reconciler.js.map +1 -1
- package/dist/integrations/gitlab/rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/rules.js +2 -1
- package/dist/integrations/gitlab/rules.js.map +1 -1
- package/dist/integrations/incidentio/rules.d.ts.map +1 -1
- package/dist/integrations/incidentio/rules.js +1 -0
- package/dist/integrations/incidentio/rules.js.map +1 -1
- package/dist/integrations/issue-reconciler.d.ts +7 -7
- package/dist/integrations/issue-reconciler.d.ts.map +1 -1
- package/dist/integrations/issue-reconciler.js +11 -14
- package/dist/integrations/issue-reconciler.js.map +1 -1
- package/dist/integrations/jira/rules.d.ts.map +1 -1
- package/dist/integrations/jira/rules.js +1 -0
- package/dist/integrations/jira/rules.js.map +1 -1
- package/dist/integrations/linear/issue-reconciler.js +2 -2
- package/dist/integrations/linear/issue-reconciler.js.map +1 -1
- package/dist/integrations/linear/routes.d.ts.map +1 -1
- package/dist/integrations/linear/routes.js +1 -1
- package/dist/integrations/linear/routes.js.map +1 -1
- package/dist/integrations/linear/rules.d.ts.map +1 -1
- package/dist/integrations/linear/rules.js +2 -1
- package/dist/integrations/linear/rules.js.map +1 -1
- package/dist/integrations/slack/feed-publisher.d.ts +2 -2
- package/dist/integrations/slack/feed-publisher.d.ts.map +1 -1
- package/dist/integrations/slack/feed-publisher.js.map +1 -1
- package/dist/integrations/slack/slack.d.ts.map +1 -1
- package/dist/integrations/slack/slack.js.map +1 -1
- package/dist/packages/_internals/workspace/dist/index.js +1 -1
- package/dist/routes/attention-activity.js +1 -1
- package/dist/routes/attention-activity.js.map +1 -1
- package/dist/routes/attention-parked.js.map +1 -1
- package/dist/routes/attention-providers.d.ts +4 -4
- package/dist/routes/attention-providers.d.ts.map +1 -1
- package/dist/routes/attention-providers.js +2 -2
- package/dist/routes/attention-providers.js.map +1 -1
- package/dist/routes/contracts.d.ts +33 -5
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +13 -4
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/intake.d.ts.map +1 -1
- package/dist/routes/intake.js +1 -1
- package/dist/routes/intake.js.map +1 -1
- package/dist/routes/projects.js +3 -2
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/surface.js +4 -4
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +9 -3
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/binding-context.js +1 -1
- package/dist/rules/binding-context.js.map +1 -1
- package/dist/rules/decision-applicability.d.ts +2 -2
- package/dist/rules/decision-applicability.d.ts.map +1 -1
- package/dist/rules/decision-applicability.js +1 -1
- package/dist/rules/decision-applicability.js.map +1 -1
- package/dist/rules/dispatcher.d.ts +2 -7
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +13 -17
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/processor.d.ts +2 -2
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +4 -2
- package/dist/rules/processor.js.map +1 -1
- package/dist/rules/review-source-tool.d.ts.map +1 -1
- package/dist/rules/review-source-tool.js +2 -4
- package/dist/rules/review-source-tool.js.map +1 -1
- package/dist/rules/start-coordinator.d.ts.map +1 -1
- package/dist/rules/start-coordinator.js +5 -2
- package/dist/rules/start-coordinator.js.map +1 -1
- package/dist/rules/tools.d.ts.map +1 -1
- package/dist/rules/tools.js +7 -10
- package/dist/rules/tools.js.map +1 -1
- package/dist/rules/transition-service.d.ts +8 -16
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +19 -21
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/rules/types.d.ts +9 -3
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js +2 -2
- package/dist/rules/types.js.map +1 -1
- package/dist/session/resource-migration.d.ts +3 -3
- package/dist/session/resource-migration.d.ts.map +1 -1
- package/dist/session/resource-migration.js.map +1 -1
- package/dist/session/work-item-repository.d.ts +4 -2
- package/dist/session/work-item-repository.d.ts.map +1 -1
- package/dist/session/work-item-repository.js +2 -2
- package/dist/session/work-item-repository.js.map +1 -1
- package/dist/skills/catalog.js +1 -1
- package/dist/storage/domains/comments/base.d.ts.map +1 -1
- package/dist/storage/domains/comments/base.js +15 -8
- package/dist/storage/domains/comments/base.js.map +1 -1
- package/dist/storage/domains/comments/domain.d.ts +2 -2
- package/dist/storage/domains/comments/domain.d.ts.map +1 -1
- package/dist/storage/domains/comments/domain.js +1 -1
- package/dist/storage/domains/comments/domain.js.map +1 -1
- package/dist/storage/domains/comments/feed-sync.d.ts +2 -2
- package/dist/storage/domains/comments/feed-sync.d.ts.map +1 -1
- package/dist/storage/domains/projects/base.d.ts +0 -3
- package/dist/storage/domains/projects/base.d.ts.map +1 -1
- package/dist/storage/domains/projects/base.js +0 -3
- package/dist/storage/domains/projects/base.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +99 -35
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +318 -170
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/storage/domains/work-items/board-version.d.ts +2 -2
- package/dist/storage/domains/work-items/board-version.d.ts.map +1 -1
- package/dist/storage/domains/work-items/board-version.js +16 -5
- package/dist/storage/domains/work-items/board-version.js.map +1 -1
- package/dist/storage/domains/work-items/cards.d.ts +57 -0
- package/dist/storage/domains/work-items/cards.d.ts.map +1 -0
- package/dist/storage/domains/work-items/cards.js +290 -0
- package/dist/storage/domains/work-items/cards.js.map +1 -0
- package/dist/storage/domains/work-items/metrics.d.ts +2 -2
- package/dist/storage/domains/work-items/metrics.d.ts.map +1 -1
- package/dist/storage/domains/work-items/metrics.js.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.d.ts +117 -0
- package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -0
- package/dist/storage/domains/work-items/work-item-schema.js +300 -0
- package/dist/storage/domains/work-items/work-item-schema.js.map +1 -0
- package/dist/tools/read-tools.d.ts +4 -4
- package/dist/tools/read-tools.d.ts.map +1 -1
- package/dist/tools/read-tools.js +19 -9
- package/dist/tools/read-tools.js.map +1 -1
- package/dist/tools/session-tools.d.ts.map +1 -1
- package/dist/tools/session-tools.js.map +1 -1
- package/dist/tools/side-sessions.d.ts +2 -2
- package/dist/tools/side-sessions.d.ts.map +1 -1
- package/dist/tools/side-sessions.js.map +1 -1
- package/dist/tools/work-item-tools.d.ts.map +1 -1
- package/dist/tools/work-item-tools.js +12 -17
- package/dist/tools/work-item-tools.js.map +1 -1
- package/dist/work-items/create-work-item.d.ts +4 -4
- package/dist/work-items/create-work-item.d.ts.map +1 -1
- package/dist/work-items/create-work-item.js +65 -27
- package/dist/work-items/create-work-item.js.map +1 -1
- package/dist/work-items/providers/base.d.ts +22 -0
- package/dist/work-items/providers/base.d.ts.map +1 -0
- package/dist/work-items/providers/base.js +44 -0
- package/dist/work-items/providers/base.js.map +1 -0
- package/dist/work-items/providers/factory.d.ts +4 -0
- package/dist/work-items/providers/factory.d.ts.map +1 -0
- package/dist/work-items/providers/factory.js +13 -0
- package/dist/work-items/providers/factory.js.map +1 -0
- package/dist/work-items/providers/github.d.ts +3 -0
- package/dist/work-items/providers/github.d.ts.map +1 -0
- package/dist/work-items/providers/github.js +30 -0
- package/dist/work-items/providers/github.js.map +1 -0
- package/dist/work-items/providers/gitlab.d.ts +3 -0
- package/dist/work-items/providers/gitlab.d.ts.map +1 -0
- package/dist/work-items/providers/gitlab.js +35 -0
- package/dist/work-items/providers/gitlab.js.map +1 -0
- package/dist/work-items/providers/incidentio.d.ts +3 -0
- package/dist/work-items/providers/incidentio.d.ts.map +1 -0
- package/dist/work-items/providers/incidentio.js +23 -0
- package/dist/work-items/providers/incidentio.js.map +1 -0
- package/dist/work-items/providers/index.d.ts +8 -0
- package/dist/work-items/providers/index.d.ts.map +1 -0
- package/dist/work-items/providers/index.js +34 -0
- package/dist/work-items/providers/index.js.map +1 -0
- package/dist/work-items/providers/jira.d.ts +3 -0
- package/dist/work-items/providers/jira.d.ts.map +1 -0
- package/dist/work-items/providers/jira.js +16 -0
- package/dist/work-items/providers/jira.js.map +1 -0
- package/dist/work-items/providers/linear.d.ts +3 -0
- package/dist/work-items/providers/linear.d.ts.map +1 -0
- package/dist/work-items/providers/linear.js +24 -0
- package/dist/work-items/providers/linear.js.map +1 -0
- package/dist/work-items/providers/metadata-keys.d.ts +24 -0
- package/dist/work-items/providers/metadata-keys.d.ts.map +1 -0
- package/dist/work-items/providers/metadata-keys.js +84 -0
- package/dist/work-items/providers/metadata-keys.js.map +1 -0
- package/dist/work-items/providers/slack.d.ts +6 -0
- package/dist/work-items/providers/slack.d.ts.map +1 -0
- package/dist/work-items/providers/slack.js +15 -0
- package/dist/work-items/providers/slack.js.map +1 -0
- package/dist/work-items/providers/types.d.ts +23 -0
- package/dist/work-items/providers/types.d.ts.map +1 -0
- package/dist/work-items/providers/types.js +1 -0
- package/dist/work-items/split-migration.d.ts +51 -0
- package/dist/work-items/split-migration.d.ts.map +1 -0
- package/dist/work-items/split-migration.js +293 -0
- package/dist/work-items/split-migration.js.map +1 -0
- package/factory-skills/configure-factory-rules/SKILL.md +12 -16
- package/factory-skills/factory-self-review/SKILL.md +1 -1
- package/factory-skills/factory-triage/SKILL.md +3 -3
- package/package.json +15 -15
- package/dist/boards/work-transition-policy.d.ts +0 -3
- package/dist/boards/work-transition-policy.d.ts.map +0 -1
- package/dist/boards/work-transition-policy.js +0 -78
- package/dist/boards/work-transition-policy.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binding-context.js","names":[],"sources":["../../src/rules/binding-context.ts"],"sourcesContent":["import type { AgentControllerRequestContext } from '@mastra/core/agent-controller';\nimport type { RequestContext } from '@mastra/core/request-context';\n\nimport { getFactoryAuthOrgId, getFactoryAuthUserFromContext } from '../auth.js';\nimport type {\n FactoryRunBindingAddress,\n FactoryRunBindingRecord,\n FactoryRunBindingSessionAddress,\n WorkItemsStorage,\n} from '../storage/domains/work-items/base.js';\n\ninterface FactorySessionState {\n factoryProjectId?: string;\n factoryOrgId?: string;\n projectRepositoryId?: string;\n untrustedCheckout?: boolean;\n baseRef?: string;\n}\n\ntype FactorySessionControllerContext = AgentControllerRequestContext<FactorySessionState>;\n\n/** Minimal source-control session lookup used to heal recovered session state. */\nexport interface FactorySessionSourceLookup {\n getBySessionId(\n sessionId: string,\n ): Promise<{ orgId: string; projectRepositoryId: string | null; baseBranch: string } | null>;\n}\n\nexport function getFactorySessionCoordinates(\n requestContext: RequestContext | undefined,\n): FactoryRunBindingSessionAddress | null {\n if (!requestContext || typeof requestContext.get !== 'function') return null;\n const context = requestContext.get('controller') as FactorySessionControllerContext | undefined;\n const factoryProjectId = context?.getState().factoryProjectId;\n if (!context?.threadId || !context.resourceId || !context.sessionId || !factoryProjectId) return null;\n return {\n factoryProjectId,\n threadId: context.threadId,\n resourceId: context.resourceId,\n sessionId: context.sessionId,\n };\n}\n\nexport function getFactorySessionAddress(requestContext: RequestContext | undefined): FactoryRunBindingAddress | null {\n const coordinates = getFactorySessionCoordinates(requestContext);\n if (!coordinates || !requestContext || typeof requestContext.get !== 'function') return null;\n const user = getFactoryAuthUserFromContext(requestContext);\n const orgId = getFactoryAuthOrgId(user);\n if (!orgId) return null;\n return { orgId, ...coordinates };\n}\n\n/**\n * Read the session's factory scoping off controller state: the project whose\n * shared settings row applies to its runs, plus the org rung that row is keyed\n * by (`factoryOrgId` is seeded at session start and is authoritative for\n * downstream identity reads — the owner id is a user, never an org).\n */\nexport function readFactorySessionScope(\n requestContext: RequestContext | undefined,\n): { factoryProjectId: string; factoryOrgId?: string } | null {\n if (!requestContext || typeof requestContext.get !== 'function') return null;\n const context = requestContext.get('controller') as FactorySessionControllerContext | undefined;\n const state = context?.getState();\n const factoryProjectId = state?.factoryProjectId;\n if (typeof factoryProjectId !== 'string' || factoryProjectId.length === 0) return null;\n const factoryOrgId = state?.factoryOrgId;\n return {\n factoryProjectId,\n ...(typeof factoryOrgId === 'string' && factoryOrgId.length > 0 ? { factoryOrgId } : {}),\n };\n}\n\n/**\n * Read the active run binding for this session when controller state has lost\n * `factoryProjectId` — a crash-recovered session (\"Continue\") is recreated with\n * empty state, so the binding table is the only remaining source of the project\n * whose shared settings row applies to the run. Read-only, unlike\n * `resolveFactorySessionAddress`: it neither heals state nor touches source\n * control, so input processors can call it before any tool has run.\n */\nexport async function findSessionRunBinding(\n requestContext: RequestContext | undefined,\n storage: Pick<WorkItemsStorage, 'findActiveRunBindingByThread'>,\n): Promise<FactoryRunBindingRecord | null> {\n if (!requestContext || typeof requestContext.get !== 'function') return null;\n const context = requestContext.get('controller') as FactorySessionControllerContext | undefined;\n if (!context?.threadId || !context.resourceId || !context.sessionId) return null;\n const orgId = getFactoryAuthOrgId(getFactoryAuthUserFromContext(requestContext));\n if (!orgId) return null;\n return storage.findActiveRunBindingByThread({\n orgId,\n threadId: context.threadId,\n resourceId: context.resourceId,\n sessionId: context.sessionId,\n });\n}\n\nexport interface FactorySessionAddressResolution {\n address: FactoryRunBindingAddress;\n /** Present only when the address was recovered from the binding table. */\n binding?: FactoryRunBindingRecord;\n}\n\n/**\n * Resolve the bound session address, falling back to the active binding row\n * when the in-memory session state is missing `factoryProjectId` — a server\n * crash drops controller sessions, and a resumed session (\"Continue\") is\n * recreated with empty state, which silently unregistered the transition\n * tool. On recovery the lost state is healed back onto the session (including\n * the `untrustedCheckout`/`baseRef` security posture the start coordinator\n * originally seeded) so later reads resolve directly.\n */\nexport async function resolveFactorySessionAddress(options: {\n requestContext: RequestContext | undefined;\n storage: Pick<WorkItemsStorage, 'findActiveRunBindingByThread' | 'get'>;\n sessions?: FactorySessionSourceLookup;\n /**\n * Resolve through the binding table even when state already carries\n * `factoryProjectId`, so the row heals the rest of the session state. Prompt\n * creation uses this: a partially persisted state can keep the project id\n * while the untrusted-checkout posture is gone, and the direct short-circuit\n * would take that id as proof the session is intact.\n */\n forceBindingLookup?: boolean;\n}): Promise<FactorySessionAddressResolution | null> {\n const direct = options.forceBindingLookup ? null : getFactorySessionAddress(options.requestContext);\n if (direct) return { address: direct };\n\n const requestContext = options.requestContext;\n if (!requestContext || typeof requestContext.get !== 'function') return null;\n const context = requestContext.get('controller') as FactorySessionControllerContext | undefined;\n if (!context?.threadId || !context.resourceId || !context.sessionId) return null;\n const user = getFactoryAuthUserFromContext(requestContext);\n const orgId = getFactoryAuthOrgId(user);\n if (!orgId) return null;\n\n const binding = await options.storage.findActiveRunBindingByThread({\n orgId,\n threadId: context.threadId,\n resourceId: context.resourceId,\n sessionId: context.sessionId,\n });\n if (!binding) return null;\n\n await healRecoveredSessionState({ context, binding, storage: options.storage, sessions: options.sessions });\n\n return {\n address: {\n orgId,\n factoryProjectId: binding.factoryProjectId,\n threadId: context.threadId,\n resourceId: context.resourceId,\n sessionId: context.sessionId,\n },\n binding,\n };\n}\n\nasync function healRecoveredSessionState(options: {\n context: FactorySessionControllerContext;\n binding: FactoryRunBindingRecord;\n storage: Pick<WorkItemsStorage, 'get'>;\n sessions?: FactorySessionSourceLookup;\n}): Promise<void> {\n const { binding } = options;\n // `factoryOrgId` mirrors the start coordinator's seed: the binding row holds\n // the authoritative org id, so crash-recovered sessions heal it for free.\n const updates: FactorySessionState = { factoryProjectId: binding.factoryProjectId, factoryOrgId: binding.orgId };\n // Security posture first, from the binding row alone (no I/O): review-bound\n // sessions run against attacker-writable checkouts, so `untrustedCheckout`\n // must survive even if the enrichment lookups below fail transiently.\n if (binding.role === 'review') {\n updates.untrustedCheckout = true;\n }\n // Best-effort enrichment mirroring the start coordinator's original seed:\n // PR-sourced work items are untrusted regardless of role, and `baseRef`\n // restores the trusted instruction source for untrusted checkouts.\n try {\n const item = await options.storage.get({ orgId: binding.orgId, id: binding.workItemId });\n const foundSession = (await options.sessions?.getBySessionId(binding.sessionId)) ?? null;\n const sourceSession = foundSession?.orgId === binding.orgId ? foundSession : null;\n if (sourceSession?.projectRepositoryId) {\n updates.projectRepositoryId = sourceSession.projectRepositoryId;\n }\n const untrusted = updates.untrustedCheckout === true || item?.externalSource?.type === 'pull-request';\n if (untrusted) {\n updates.untrustedCheckout = true;\n const metadataBaseBranch = item?.metadata?.baseBranch;\n const baseRef =\n sourceSession?.baseBranch ||\n (typeof metadataBaseBranch === 'string' && metadataBaseBranch ? metadataBaseBranch : undefined);\n if (baseRef) updates.baseRef = baseRef;\n } else {\n // Record the trusted verdict explicitly so a healed session carries every\n // trust field; the prompt-time recovery check treats a missing flag as\n // \"not yet verified\" and would otherwise re-run on every prompt. Left\n // unset when enrichment fails so the next prompt retries the lookup.\n updates.untrustedCheckout = false;\n }\n } catch {\n // Enrichment is best-effort; the address itself only needs the binding.\n }\n try {\n await options.context.setState(updates);\n } catch {\n // State healing must never block tool registration on the recovered address.\n }\n}\n"],"mappings":";;AA4BA,SAAgB,6BACd,gBACwC;CACxC,IAAI,CAAC,kBAAkB,OAAO,eAAe,QAAQ,YAAY,OAAO;CACxE,MAAM,UAAU,eAAe,IAAI,YAAY;CAC/C,MAAM,mBAAmB,SAAS,SAAS,CAAC,CAAC;CAC7C,IAAI,CAAC,SAAS,YAAY,CAAC,QAAQ,cAAc,CAAC,QAAQ,aAAa,CAAC,kBAAkB,OAAO;CACjG,OAAO;EACL;EACA,UAAU,QAAQ;EAClB,YAAY,QAAQ;EACpB,WAAW,QAAQ;CACrB;AACF;AAEA,SAAgB,yBAAyB,gBAA6E;CACpH,MAAM,cAAc,6BAA6B,cAAc;CAC/D,IAAI,CAAC,eAAe,CAAC,kBAAkB,OAAO,eAAe,QAAQ,YAAY,OAAO;CACxF,MAAM,OAAO,8BAA8B,cAAc;CACzD,MAAM,QAAQ,oBAAoB,IAAI;CACtC,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO;EAAE;EAAO,GAAG;CAAY;AACjC;;;;;;;AAQA,SAAgB,wBACd,gBAC4D;CAC5D,IAAI,CAAC,kBAAkB,OAAO,eAAe,QAAQ,YAAY,OAAO;CAExE,MAAM,QADU,eAAe,IAAI,YACf,CAAC,EAAE,SAAS;CAChC,MAAM,mBAAmB,OAAO;CAChC,IAAI,OAAO,qBAAqB,YAAY,iBAAiB,WAAW,GAAG,OAAO;CAClF,MAAM,eAAe,OAAO;CAC5B,OAAO;EACL;EACA,GAAI,OAAO,iBAAiB,YAAY,aAAa,SAAS,IAAI,EAAE,aAAa,IAAI,CAAC;CACxF;AACF;;;;;;;;;AAUA,eAAsB,sBACpB,gBACA,SACyC;CACz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AAE,kBAAkB,QAAQ;EAAkB,cAAc,QAAQ;CAAM;CAI/G,IAAI,QAAQ,SAAS,UACnB,QAAQ,oBAAoB;CAK9B,IAAI;EACF,MAAM,OAAO,MAAM,QAAQ,QAAQ,IAAI;GAAE,OAAO,QAAQ;GAAO,IAAI,QAAQ;EAAW,CAAC;EACvF,MAAM,eAAgB,MAAM,QAAQ,UAAU,eAAe,QAAQ,SAAS,KAAM;EACpF,MAAM,gBAAgB,cAAc,UAAU,QAAQ,QAAQ,eAAe;EAC7E,IAAI,eAAe,qBACjB,QAAQ,sBAAsB,cAAc;EAG9C,IADkB,QAAQ,sBAAsB,QAAQ,MAAM,gBAAgB,SAAS,gBACxE;GACb,QAAQ,oBAAoB;GAC5B,MAAM,qBAAqB,MAAM,UAAU;GAC3C,MAAM,UACJ,eAAe,eACd,OAAO,uBAAuB,YAAY,qBAAqB,qBAAqB,KAAA;GACvF,IAAI,SAAS,QAAQ,UAAU;EACjC,OAKE,QAAQ,oBAAoB;CAEhC,QAAQ,CAER;CACA,IAAI;EACF,MAAM,QAAQ,QAAQ,SAAS,OAAO;CACxC,QAAQ,CAER;AACF"}
|
|
1
|
+
{"version":3,"file":"binding-context.js","names":[],"sources":["../../src/rules/binding-context.ts"],"sourcesContent":["import type { AgentControllerRequestContext } from '@mastra/core/agent-controller';\nimport type { RequestContext } from '@mastra/core/request-context';\n\nimport { getFactoryAuthOrgId, getFactoryAuthUserFromContext } from '../auth.js';\nimport type {\n FactoryRunBindingAddress,\n FactoryRunBindingRecord,\n FactoryRunBindingSessionAddress,\n WorkItemsStorage,\n} from '../storage/domains/work-items/base.js';\n\ninterface FactorySessionState {\n factoryProjectId?: string;\n factoryOrgId?: string;\n projectRepositoryId?: string;\n untrustedCheckout?: boolean;\n baseRef?: string;\n}\n\ntype FactorySessionControllerContext = AgentControllerRequestContext<FactorySessionState>;\n\n/** Minimal source-control session lookup used to heal recovered session state. */\nexport interface FactorySessionSourceLookup {\n getBySessionId(\n sessionId: string,\n ): Promise<{ orgId: string; projectRepositoryId: string | null; baseBranch: string } | null>;\n}\n\nexport function getFactorySessionCoordinates(\n requestContext: RequestContext | undefined,\n): FactoryRunBindingSessionAddress | null {\n if (!requestContext || typeof requestContext.get !== 'function') return null;\n const context = requestContext.get('controller') as FactorySessionControllerContext | undefined;\n const factoryProjectId = context?.getState().factoryProjectId;\n if (!context?.threadId || !context.resourceId || !context.sessionId || !factoryProjectId) return null;\n return {\n factoryProjectId,\n threadId: context.threadId,\n resourceId: context.resourceId,\n sessionId: context.sessionId,\n };\n}\n\nexport function getFactorySessionAddress(requestContext: RequestContext | undefined): FactoryRunBindingAddress | null {\n const coordinates = getFactorySessionCoordinates(requestContext);\n if (!coordinates || !requestContext || typeof requestContext.get !== 'function') return null;\n const user = getFactoryAuthUserFromContext(requestContext);\n const orgId = getFactoryAuthOrgId(user);\n if (!orgId) return null;\n return { orgId, ...coordinates };\n}\n\n/**\n * Read the session's factory scoping off controller state: the project whose\n * shared settings row applies to its runs, plus the org rung that row is keyed\n * by (`factoryOrgId` is seeded at session start and is authoritative for\n * downstream identity reads — the owner id is a user, never an org).\n */\nexport function readFactorySessionScope(\n requestContext: RequestContext | undefined,\n): { factoryProjectId: string; factoryOrgId?: string } | null {\n if (!requestContext || typeof requestContext.get !== 'function') return null;\n const context = requestContext.get('controller') as FactorySessionControllerContext | undefined;\n const state = context?.getState();\n const factoryProjectId = state?.factoryProjectId;\n if (typeof factoryProjectId !== 'string' || factoryProjectId.length === 0) return null;\n const factoryOrgId = state?.factoryOrgId;\n return {\n factoryProjectId,\n ...(typeof factoryOrgId === 'string' && factoryOrgId.length > 0 ? { factoryOrgId } : {}),\n };\n}\n\n/**\n * Read the active run binding for this session when controller state has lost\n * `factoryProjectId` — a crash-recovered session (\"Continue\") is recreated with\n * empty state, so the binding table is the only remaining source of the project\n * whose shared settings row applies to the run. Read-only, unlike\n * `resolveFactorySessionAddress`: it neither heals state nor touches source\n * control, so input processors can call it before any tool has run.\n */\nexport async function findSessionRunBinding(\n requestContext: RequestContext | undefined,\n storage: Pick<WorkItemsStorage, 'findActiveRunBindingByThread'>,\n): Promise<FactoryRunBindingRecord | null> {\n if (!requestContext || typeof requestContext.get !== 'function') return null;\n const context = requestContext.get('controller') as FactorySessionControllerContext | undefined;\n if (!context?.threadId || !context.resourceId || !context.sessionId) return null;\n const orgId = getFactoryAuthOrgId(getFactoryAuthUserFromContext(requestContext));\n if (!orgId) return null;\n return storage.findActiveRunBindingByThread({\n orgId,\n threadId: context.threadId,\n resourceId: context.resourceId,\n sessionId: context.sessionId,\n });\n}\n\nexport interface FactorySessionAddressResolution {\n address: FactoryRunBindingAddress;\n /** Present only when the address was recovered from the binding table. */\n binding?: FactoryRunBindingRecord;\n}\n\n/**\n * Resolve the bound session address, falling back to the active binding row\n * when the in-memory session state is missing `factoryProjectId` — a server\n * crash drops controller sessions, and a resumed session (\"Continue\") is\n * recreated with empty state, which silently unregistered the transition\n * tool. On recovery the lost state is healed back onto the session (including\n * the `untrustedCheckout`/`baseRef` security posture the start coordinator\n * originally seeded) so later reads resolve directly.\n */\nexport async function resolveFactorySessionAddress(options: {\n requestContext: RequestContext | undefined;\n storage: Pick<WorkItemsStorage, 'findActiveRunBindingByThread' | 'get'>;\n sessions?: FactorySessionSourceLookup;\n /**\n * Resolve through the binding table even when state already carries\n * `factoryProjectId`, so the row heals the rest of the session state. Prompt\n * creation uses this: a partially persisted state can keep the project id\n * while the untrusted-checkout posture is gone, and the direct short-circuit\n * would take that id as proof the session is intact.\n */\n forceBindingLookup?: boolean;\n}): Promise<FactorySessionAddressResolution | null> {\n const direct = options.forceBindingLookup ? null : getFactorySessionAddress(options.requestContext);\n if (direct) return { address: direct };\n\n const requestContext = options.requestContext;\n if (!requestContext || typeof requestContext.get !== 'function') return null;\n const context = requestContext.get('controller') as FactorySessionControllerContext | undefined;\n if (!context?.threadId || !context.resourceId || !context.sessionId) return null;\n const user = getFactoryAuthUserFromContext(requestContext);\n const orgId = getFactoryAuthOrgId(user);\n if (!orgId) return null;\n\n const binding = await options.storage.findActiveRunBindingByThread({\n orgId,\n threadId: context.threadId,\n resourceId: context.resourceId,\n sessionId: context.sessionId,\n });\n if (!binding) return null;\n\n await healRecoveredSessionState({ context, binding, storage: options.storage, sessions: options.sessions });\n\n return {\n address: {\n orgId,\n factoryProjectId: binding.factoryProjectId,\n threadId: context.threadId,\n resourceId: context.resourceId,\n sessionId: context.sessionId,\n },\n binding,\n };\n}\n\nasync function healRecoveredSessionState(options: {\n context: FactorySessionControllerContext;\n binding: FactoryRunBindingRecord;\n storage: Pick<WorkItemsStorage, 'get'>;\n sessions?: FactorySessionSourceLookup;\n}): Promise<void> {\n const { binding } = options;\n // `factoryOrgId` mirrors the start coordinator's seed: the binding row holds\n // the authoritative org id, so crash-recovered sessions heal it for free.\n const updates: FactorySessionState = { factoryProjectId: binding.factoryProjectId, factoryOrgId: binding.orgId };\n // Security posture first, from the binding row alone (no I/O): review-bound\n // sessions run against attacker-writable checkouts, so `untrustedCheckout`\n // must survive even if the enrichment lookups below fail transiently.\n if (binding.role === 'review') {\n updates.untrustedCheckout = true;\n }\n // Best-effort enrichment mirroring the start coordinator's original seed:\n // PR-sourced work items are untrusted regardless of role, and `baseRef`\n // restores the trusted instruction source for untrusted checkouts.\n try {\n const item = await options.storage.get({ orgId: binding.orgId, id: binding.workItemId });\n const foundSession = (await options.sessions?.getBySessionId(binding.sessionId)) ?? null;\n const sourceSession = foundSession?.orgId === binding.orgId ? foundSession : null;\n if (sourceSession?.projectRepositoryId) {\n updates.projectRepositoryId = sourceSession.projectRepositoryId;\n }\n const untrusted = updates.untrustedCheckout === true || item?.externalSource?.type === 'pull-request';\n if (untrusted) {\n updates.untrustedCheckout = true;\n const metadataBaseBranch = item?.workItem.metadata?.baseBranch;\n const baseRef =\n sourceSession?.baseBranch ||\n (typeof metadataBaseBranch === 'string' && metadataBaseBranch ? metadataBaseBranch : undefined);\n if (baseRef) updates.baseRef = baseRef;\n } else {\n // Record the trusted verdict explicitly so a healed session carries every\n // trust field; the prompt-time recovery check treats a missing flag as\n // \"not yet verified\" and would otherwise re-run on every prompt. Left\n // unset when enrichment fails so the next prompt retries the lookup.\n updates.untrustedCheckout = false;\n }\n } catch {\n // Enrichment is best-effort; the address itself only needs the binding.\n }\n try {\n await options.context.setState(updates);\n } catch {\n // State healing must never block tool registration on the recovered address.\n }\n}\n"],"mappings":";;AA4BA,SAAgB,6BACd,gBACwC;CACxC,IAAI,CAAC,kBAAkB,OAAO,eAAe,QAAQ,YAAY,OAAO;CACxE,MAAM,UAAU,eAAe,IAAI,YAAY;CAC/C,MAAM,mBAAmB,SAAS,SAAS,CAAC,CAAC;CAC7C,IAAI,CAAC,SAAS,YAAY,CAAC,QAAQ,cAAc,CAAC,QAAQ,aAAa,CAAC,kBAAkB,OAAO;CACjG,OAAO;EACL;EACA,UAAU,QAAQ;EAClB,YAAY,QAAQ;EACpB,WAAW,QAAQ;CACrB;AACF;AAEA,SAAgB,yBAAyB,gBAA6E;CACpH,MAAM,cAAc,6BAA6B,cAAc;CAC/D,IAAI,CAAC,eAAe,CAAC,kBAAkB,OAAO,eAAe,QAAQ,YAAY,OAAO;CACxF,MAAM,OAAO,8BAA8B,cAAc;CACzD,MAAM,QAAQ,oBAAoB,IAAI;CACtC,IAAI,CAAC,OAAO,OAAO;CACnB,OAAO;EAAE;EAAO,GAAG;CAAY;AACjC;;;;;;;AAQA,SAAgB,wBACd,gBAC4D;CAC5D,IAAI,CAAC,kBAAkB,OAAO,eAAe,QAAQ,YAAY,OAAO;CAExE,MAAM,QADU,eAAe,IAAI,YACf,CAAC,EAAE,SAAS;CAChC,MAAM,mBAAmB,OAAO;CAChC,IAAI,OAAO,qBAAqB,YAAY,iBAAiB,WAAW,GAAG,OAAO;CAClF,MAAM,eAAe,OAAO;CAC5B,OAAO;EACL;EACA,GAAI,OAAO,iBAAiB,YAAY,aAAa,SAAS,IAAI,EAAE,aAAa,IAAI,CAAC;CACxF;AACF;;;;;;;;;AAUA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AE,YAAY;CAGpB,MAAM,UAA+B;EAAE,kBAAkB,QAAQ;EAAkB,cAAc,QAAQ;CAAM;CAI/G,IAAI,QAAQ,SAAS,UACnB,QAAQ,oBAAoB;CAK9B,IAAI;EACF,MAAM,OAAO,MAAM,QAAQ,QAAQ,IAAI;GAAE,OAAO,QAAQ;GAAO,IAAI,QAAQ;EAAW,CAAC;EACvF,MAAM,eAAgB,MAAM,QAAQ,UAAU,eAAe,QAAQ,SAAS,KAAM;EACpF,MAAM,gBAAgB,cAAc,UAAU,QAAQ,QAAQ,eAAe;EAC7E,IAAI,eAAe,qBACjB,QAAQ,sBAAsB,cAAc;EAG9C,IADkB,QAAQ,sBAAsB,QAAQ,MAAM,gBAAgB,SAAS,gBACxE;GACb,QAAQ,oBAAoB;GAC5B,MAAM,qBAAqB,MAAM,SAAS,UAAU;GACpD,MAAM,UACJ,eAAe,eACd,OAAO,uBAAuB,YAAY,qBAAqB,qBAAqB,KAAA;GACvF,IAAI,SAAS,QAAQ,UAAU;EACjC,OAKE,QAAQ,oBAAoB;CAEhC,QAAQ,CAER;CACA,IAAI;EACF,MAAM,QAAQ,QAAQ,SAAS,OAAO;CACxC,QAAQ,CAER;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BoardRegistry } from '../boards/index.js';
|
|
2
|
-
import type { FactoryDeferredDecisionRecord,
|
|
2
|
+
import type { FactoryDeferredDecisionRecord, Card, WorkItemsStorage } from '../storage/domains/work-items/base.js';
|
|
3
3
|
type ApplicabilityRecord = Pick<FactoryDeferredDecisionRecord, 'id' | 'evaluationId' | 'createdAt' | 'decision'>;
|
|
4
4
|
/** The seat a skill run needs; other decision types are not tied to one phase. */
|
|
5
5
|
export declare function skillDecisionRole(record: Pick<FactoryDeferredDecisionRecord, 'decision'>): string | undefined;
|
|
@@ -17,7 +17,7 @@ export declare function decisionRetryable(record: Pick<FactoryDeferredDecisionRe
|
|
|
17
17
|
*/
|
|
18
18
|
export declare function decisionOvertaken(input: {
|
|
19
19
|
boards: BoardRegistry;
|
|
20
|
-
item:
|
|
20
|
+
item: Card | null;
|
|
21
21
|
record: ApplicabilityRecord;
|
|
22
22
|
role: string;
|
|
23
23
|
/** Decisions from the same rule evaluation as `record`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decision-applicability.d.ts","sourceRoot":"","sources":["../../src/rules/decision-applicability.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"decision-applicability.d.ts","sourceRoot":"","sources":["../../src/rules/decision-applicability.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,KAAK,EAAE,6BAA6B,EAAE,IAAI,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAGnH,KAAK,mBAAmB,GAAG,IAAI,CAAC,6BAA6B,EAAE,IAAI,GAAG,cAAc,GAAG,WAAW,GAAG,UAAU,CAAC,CAAC;AAEjH,kFAAkF;AAClF,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,IAAI,CAAC,6BAA6B,EAAE,UAAU,CAAC,GAAG,MAAM,GAAG,SAAS,CAG7G;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,IAAI,CAAC,6BAA6B,EAAE,QAAQ,GAAG,aAAa,CAAC,EACrE,SAAS,EAAE,OAAO,GACjB,OAAO,CAET;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,MAAM,EAAE,aAAa,CAAC;IACtB,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,MAAM,EAAE,mBAAmB,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,2DAA2D;IAC3D,QAAQ,EAAE,mBAAmB,EAAE,CAAC;CACjC,GAAG,OAAO,CA+BV;AAED,qFAAqF;AACrF,wBAAsB,oBAAoB,CACxC,SAAS,EAAE,IAAI,CAAC,gBAAgB,EAAE,WAAW,GAAG,6BAA6B,CAAC,EAC9E,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAA;CAAE,EAClD,OAAO,EAAE,6BAA6B,EAAE,GACvC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAyBtB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { factoryDispatchFailureMetadata } from "./dispatch-errors.js";
|
|
1
2
|
import { boardForWorkItem, resolvePhaseSemantics } from "../boards/semantics.js";
|
|
2
3
|
import "../boards/index.js";
|
|
3
|
-
import { factoryDispatchFailureMetadata } from "./dispatch-errors.js";
|
|
4
4
|
import { workStageCarries } from "../boards/legacy-plan-role.js";
|
|
5
5
|
// src/rules/decision-applicability.ts
|
|
6
6
|
/** The seat a skill run needs; other decision types are not tied to one phase. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decision-applicability.js","names":[],"sources":["../../src/rules/decision-applicability.ts"],"sourcesContent":["import { boardForWorkItem, resolvePhaseSemantics } from '../boards/index.js';\nimport type { BoardRegistry } from '../boards/index.js';\nimport { workStageCarries } from '../boards/legacy-plan-role.js';\nimport type {
|
|
1
|
+
{"version":3,"file":"decision-applicability.js","names":[],"sources":["../../src/rules/decision-applicability.ts"],"sourcesContent":["import { boardForWorkItem, resolvePhaseSemantics } from '../boards/index.js';\nimport type { BoardRegistry } from '../boards/index.js';\nimport { workStageCarries } from '../boards/legacy-plan-role.js';\nimport type { FactoryDeferredDecisionRecord, Card, WorkItemsStorage } from '../storage/domains/work-items/base.js';\nimport { factoryDispatchFailureMetadata } from './dispatch-errors.js';\n\ntype ApplicabilityRecord = Pick<FactoryDeferredDecisionRecord, 'id' | 'evaluationId' | 'createdAt' | 'decision'>;\n\n/** The seat a skill run needs; other decision types are not tied to one phase. */\nexport function skillDecisionRole(record: Pick<FactoryDeferredDecisionRecord, 'decision'>): string | undefined {\n const { type, role } = record.decision;\n return type === 'invokeSkill' && typeof role === 'string' ? role : undefined;\n}\n\n/**\n * Whether a person may retry this decision: it failed, its failure is one a rerun\n * can fix, and the card has not left the phase it was decided for. Overtaken is\n * resolved by the caller (see `overtakenDecisionIds`) because it needs the card.\n */\nexport function decisionRetryable(\n record: Pick<FactoryDeferredDecisionRecord, 'status' | 'failureCode'>,\n overtaken: boolean,\n): boolean {\n return record.status === 'failed' && !overtaken && factoryDispatchFailureMetadata(record.failureCode).canRetry;\n}\n\n/**\n * Whether the card has moved on from the phase a run was decided for: any stage it\n * now sits in was entered after the decision. Anchored on the decision rather than\n * an attempt, so a retry after the move is still recognised as stale, and a card\n * that left and came back to the same role is a new phase entry.\n */\nexport function decisionOvertaken(input: {\n boards: BoardRegistry;\n item: Card | null;\n record: ApplicabilityRecord;\n role: string;\n /** Decisions from the same rule evaluation as `record`. */\n siblings: ApplicabilityRecord[];\n}): boolean {\n const { boards, item, record, role } = input;\n if (item === null) return true;\n const decidedAt = record.createdAt.getTime();\n const enteredSince = item.stageHistory.filter(\n entry => entry.exitedAt === undefined && new Date(entry.enteredAt).getTime() > decidedAt,\n );\n // A run decided while the card sat outside its seat's stages (a held\n // triage in Intake) is fulfilled, not overtaken, when the card first\n // enters a stage that seat carries — e.g. the Investigate click.\n const board = boardForWorkItem(item);\n const contextOf = (stage: string) => resolvePhaseSemantics(boards, board, stage)?.role;\n // Work's phases share a context, so its lanes also follow the decision's skill and the old `plan` role.\n const carriesRole = (stage: string) =>\n workStageCarries(boards.get(board), stage, role, record.decision.skillName) ?? contextOf(stage) === role;\n const decidedOutsideRole = !item.stageHistory.some(\n entry =>\n new Date(entry.enteredAt).getTime() <= decidedAt &&\n (entry.exitedAt === undefined || new Date(entry.exitedAt).getTime() > decidedAt) &&\n carriesRole(entry.stage),\n );\n const movedOn = decidedOutsideRole ? enteredSince.filter(entry => !carriesRole(entry.stage)) : enteredSince;\n if (movedOn.length === 0) return false;\n // A transition from the same rule evaluation lands after this decision\n // was created; entering that stage is part of this run's intent.\n const siblingStages = new Set(\n input.siblings\n .filter(sibling => sibling.evaluationId === record.evaluationId && sibling.decision.type === 'transition')\n .map(sibling => sibling.decision.stage),\n );\n return movedOn.some(entry => !siblingStages.has(entry.stage));\n}\n\n/** Ids of the given skill-run decisions whose card has moved on from their phase. */\nexport async function overtakenDecisionIds(\n workItems: Pick<WorkItemsStorage, 'listByIds' | 'listDecisionsForEvaluations'>,\n boards: BoardRegistry,\n scope: { orgId: string; factoryProjectId: string },\n records: FactoryDeferredDecisionRecord[],\n): Promise<Set<string>> {\n const candidates = records.filter(record => record.workItemId !== null && skillDecisionRole(record) !== undefined);\n if (candidates.length === 0) return new Set();\n const [items, siblings] = await Promise.all([\n workItems.listByIds({ ...scope, ids: [...new Set(candidates.map(record => record.workItemId!))] }),\n workItems.listDecisionsForEvaluations(\n scope.orgId,\n scope.factoryProjectId,\n candidates.map(record => record.evaluationId),\n ),\n ]);\n const itemsById = new Map(items.map(item => [item.id, item]));\n return new Set(\n candidates\n .filter(record =>\n decisionOvertaken({\n boards,\n item: itemsById.get(record.workItemId!) ?? null,\n record,\n role: skillDecisionRole(record)!,\n siblings,\n }),\n )\n .map(record => record.id),\n );\n}\n"],"mappings":";;;;;;AASA,SAAgB,kBAAkB,QAA6E;CAC7G,MAAM,EAAE,MAAM,SAAS,OAAO;CAC9B,OAAO,SAAS,iBAAiB,OAAO,SAAS,WAAW,OAAO,KAAA;AACrE;;;;;;AAOA,SAAgB,kBACd,QACA,WACS;CACT,OAAO,OAAO,WAAW,YAAY,CAAC,aAAa,+BAA+B,OAAO,WAAW,CAAC,CAAC;AACxG;;;;;;;AAQA,SAAgB,kBAAkB,OAOtB;CACV,MAAM,EAAE,QAAQ,MAAM,QAAQ,SAAS;CACvC,IAAI,SAAS,MAAM,OAAO;CAC1B,MAAM,YAAY,OAAO,UAAU,QAAQ;CA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UAAU,4BACR,MAAM,OACN,MAAM,kBACN,WAAW,KAAI,WAAU,OAAO,YAAY,CAC9C,CACF,CAAC;CACD,MAAM,YAAY,IAAI,IAAI,MAAM,KAAI,SAAQ,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;CAC5D,OAAO,IAAI,IACT,WACG,QAAO,WACN,kBAAkB;EAChB;EACA,MAAM,UAAU,IAAI,OAAO,UAAW,KAAK;EAC3C;EACA,MAAM,kBAAkB,MAAM;EAC9B;CACF,CAAC,CACH,CAAC,CACA,KAAI,WAAU,OAAO,EAAE,CAC5B;AACF"}
|
|
@@ -5,14 +5,14 @@ import type { IntakeRoutesReader } from '../boards/intake-routing.js';
|
|
|
5
5
|
import type { ProjectBoardSource } from '../boards/project-boards.js';
|
|
6
6
|
import type { AuditRecorder } from '../storage/domains/audit/domain.js';
|
|
7
7
|
import type { FactoryFeedReader } from '../storage/domains/comments/feed-context.js';
|
|
8
|
-
import type { FactoryDeferredDecisionRecord,
|
|
8
|
+
import type { FactoryDeferredDecisionRecord, Card, WorkItemsStorage } from '../storage/domains/work-items/base.js';
|
|
9
9
|
import type { FactoryRunEndReporter } from '../tools/reports.js';
|
|
10
10
|
import type { FactoryTransitionService } from './transition-service.js';
|
|
11
11
|
import type { FactoryCommitDecision } from './types.js';
|
|
12
12
|
type FactoryController = Pick<AgentController<MastraCodeState>, 'getSession' | 'listActiveThreadRuns'>;
|
|
13
13
|
export interface FactoryBindingPreparationInput {
|
|
14
14
|
record: FactoryDeferredDecisionRecord;
|
|
15
|
-
item:
|
|
15
|
+
item: Card;
|
|
16
16
|
role: string;
|
|
17
17
|
}
|
|
18
18
|
export interface FactoryDecisionDispatcherOptions {
|
|
@@ -30,11 +30,6 @@ export interface FactoryDecisionDispatcherOptions {
|
|
|
30
30
|
orgId: string;
|
|
31
31
|
factoryProjectId: string;
|
|
32
32
|
}) => Promise<boolean>;
|
|
33
|
-
/** `true` lets the dispatcher answer a run's plan itself, so started work carries to Done. */
|
|
34
|
-
autoApprovePlans?: (tenant: {
|
|
35
|
-
orgId: string;
|
|
36
|
-
factoryProjectId: string;
|
|
37
|
-
}) => Promise<boolean>;
|
|
38
33
|
reconcileToolResults?: () => Promise<void>;
|
|
39
34
|
prepareBinding?: (input: FactoryBindingPreparationInput) => Promise<void>;
|
|
40
35
|
primeCredentials?: (tenant: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/rules/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAyC,MAAM,+BAA+B,CAAC;AAe5G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAOxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAGtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAatE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAExE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6CAA6C,CAAC;AAErF,OAAO,KAAK,EACV,6BAA6B,EAI7B,
|
|
1
|
+
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/rules/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAyC,MAAM,+BAA+B,CAAC;AAe5G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAOxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAGtE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAatE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAExE,OAAO,KAAK,EAAE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,CAAC,GAAG,OAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7C;CA6yCF;AAED,eAAO,MAAM,0BAA0B;aACrC,OAAO;aACP,MAAM;aACN,SAAS;aACT,WAAW;aACX,cAAc;aACd,YAAY;aACZ,mCAAmC;aACnC,sBAAsB;aACtB,cAAc;aACd,WAAW;aACX,MAAM;CACE,CAAC"}
|
package/dist/rules/dispatcher.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { FACTORY_RULE_STAGES, externalSourceForWorkItem, workItemSource } from "./types.js";
|
|
2
2
|
import { assertFactoryDecisionTarget, validateFactoryRuleDecision } from "./validation.js";
|
|
3
|
+
import { FactoryDispatchError, factoryDispatchFailureCode, factoryDispatchFailureMetadata } from "./dispatch-errors.js";
|
|
4
|
+
import { FACTORY_RULE_MATERIALIZATION_KEY } from "../storage/domains/work-items/base.js";
|
|
5
|
+
import { workItemProviderAdapter } from "../work-items/providers/index.js";
|
|
3
6
|
import { cardRuleFacts } from "../boards/card-facts.js";
|
|
4
7
|
import { boardForWorkItem, isPullRequestCard, isTerminalWorkItem, pullRequestReviewPhase, resolvePhaseSemantics, reviewsPullRequest, workItemPhaseSemantics } from "../boards/semantics.js";
|
|
5
8
|
import "../boards/index.js";
|
|
6
9
|
import { toBoardSource } from "../boards/project-boards.js";
|
|
7
10
|
import { INTAKE_ROUTE_METADATA_KEY, landingPhase, placedByIntakeRoute, resolveIntakePlacement } from "../boards/intake-routing.js";
|
|
8
|
-
import { FactoryDispatchError, factoryDispatchFailureCode, factoryDispatchFailureMetadata } from "./dispatch-errors.js";
|
|
9
|
-
import { FACTORY_RULE_MATERIALIZATION_KEY } from "../storage/domains/work-items/base.js";
|
|
10
11
|
import { moveCardToBoard } from "../boards/relocate.js";
|
|
11
12
|
import { decisionOvertaken } from "./decision-applicability.js";
|
|
12
13
|
import { FACTORY_OPEN_RUN_STALE_MS, heartbeatSessionOpenRun, isOpenRunLiveElsewhere, listSessionOpenRuns, recordSessionRunStart, waitForSessionRunAudit } from "../session/run-audit.js";
|
|
@@ -297,7 +298,6 @@ var FactoryDecisionDispatcher = class {
|
|
|
297
298
|
#storage;
|
|
298
299
|
#ownerId;
|
|
299
300
|
#isAutoRunEnabled;
|
|
300
|
-
#autoApprovePlans;
|
|
301
301
|
#reconcileToolResults;
|
|
302
302
|
#prepareBinding;
|
|
303
303
|
#primeCredentials;
|
|
@@ -332,7 +332,6 @@ var FactoryDecisionDispatcher = class {
|
|
|
332
332
|
this.#storage = options.storage;
|
|
333
333
|
this.#ownerId = options.ownerId ?? `factory-dispatcher:${globalThis.crypto.randomUUID()}`;
|
|
334
334
|
this.#isAutoRunEnabled = options.isAutoRunEnabled;
|
|
335
|
-
this.#autoApprovePlans = options.autoApprovePlans;
|
|
336
335
|
this.#reconcileToolResults = options.reconcileToolResults;
|
|
337
336
|
this.#prepareBinding = options.prepareBinding;
|
|
338
337
|
this.#primeCredentials = options.primeCredentials;
|
|
@@ -849,7 +848,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
849
848
|
const cards = (await this.#storage.list({
|
|
850
849
|
orgId: record.orgId,
|
|
851
850
|
factoryProjectId: record.factoryProjectId
|
|
852
|
-
})).filter((item) => item.externalSource?.integrationId === "linear" && item.metadata?.linearIssueId === issueId);
|
|
851
|
+
})).filter((item) => item.externalSource?.integrationId === "linear" && item.workItem.metadata?.linearIssueId === issueId);
|
|
853
852
|
return cards.find((item) => !isTerminalWorkItem(boards, item)) ?? cards[0] ?? null;
|
|
854
853
|
}
|
|
855
854
|
async #upsertLinkedItem(record, requested, causalChain) {
|
|
@@ -924,13 +923,15 @@ var FactoryDecisionDispatcher = class {
|
|
|
924
923
|
};
|
|
925
924
|
}
|
|
926
925
|
if (!result.created && !skipRules) {
|
|
927
|
-
const
|
|
926
|
+
const providerKeys = workItemProviderAdapter(result.item.externalSource).providerMetadataKeys;
|
|
927
|
+
const missing = Object.fromEntries(Object.entries(decision.metadata ?? {}).filter(([key]) => key !== "factoryRuleMaterializationKey" && (providerKeys.includes(key) ? result.item.workItem.metadata?.[key] : result.item.metadata?.[key]) === void 0));
|
|
928
928
|
if (Object.keys(missing).length > 0) {
|
|
929
|
-
const filled = await this.#storage.
|
|
929
|
+
const filled = await this.#storage.syncCard({
|
|
930
930
|
orgId: record.orgId,
|
|
931
931
|
id: result.item.id,
|
|
932
932
|
userId: "factory-rule-dispatcher",
|
|
933
|
-
patch: { metadata: missing }
|
|
933
|
+
patch: { metadata: missing },
|
|
934
|
+
fillOnly: true
|
|
934
935
|
});
|
|
935
936
|
if (filled) result = {
|
|
936
937
|
...result,
|
|
@@ -1157,23 +1158,18 @@ var FactoryDecisionDispatcher = class {
|
|
|
1157
1158
|
return session;
|
|
1158
1159
|
}
|
|
1159
1160
|
/**
|
|
1160
|
-
* Whether the run answers its plan approvals itself: the
|
|
1161
|
-
*
|
|
1162
|
-
* a plan someone should see.
|
|
1161
|
+
* Whether the run answers its plan approvals itself: the card's phase ends with an auto-approved
|
|
1162
|
+
* `submit_plan`. Otherwise a plan waits for a person.
|
|
1163
1163
|
*/
|
|
1164
1164
|
async #plansAreAutoApproved({ orgId, factoryProjectId, workItemId }) {
|
|
1165
1165
|
const item = workItemId ? await this.#storage.get({
|
|
1166
1166
|
orgId,
|
|
1167
1167
|
id: workItemId
|
|
1168
1168
|
}) : null;
|
|
1169
|
-
|
|
1170
|
-
orgId,
|
|
1171
|
-
factoryProjectId
|
|
1172
|
-
}), item) === "submit_plan") return true;
|
|
1173
|
-
return this.#autoApprovePlans ? await this.#autoApprovePlans({
|
|
1169
|
+
return item !== null && autoApprovedExitTool(await this.#boards.load({
|
|
1174
1170
|
orgId,
|
|
1175
1171
|
factoryProjectId
|
|
1176
|
-
})
|
|
1172
|
+
}), item) === "submit_plan";
|
|
1177
1173
|
}
|
|
1178
1174
|
async #requireSession(binding) {
|
|
1179
1175
|
const session = await this.#findSession(binding);
|