@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":"metrics.js","names":[],"sources":["../../../../src/storage/domains/work-items/metrics.ts"],"sourcesContent":["/**\n * Aggregation math for the Factory Overview page.\n *\n * Pure functions over `work_items` rows — throughput, lead time, in-flight\n * count, demand mix and per-stage agent coverage, all read from the\n * server-appended `stageHistory` log. Keeping this DB-free makes the math unit\n * testable and lets the route stay a thin shell.\n *\n * Everything windowed is counted as an event that happened inside the window,\n * never as \"the state the board happens to be in now\", so re-querying a past\n * window always returns the same numbers.\n */\n\nimport { isAgentActor } from './base.js';\nimport type { WorkItemRow } from './base.js';\n\n/** Default window span (days) when the request omits or malforms the range. */\nexport const DEFAULT_METRICS_WINDOW = 30;\n/** Hard cap on the range span (days) — bounds the gap-filled throughput array. */\nexport const MAX_METRICS_WINDOW = 366;\n\nconst DAY_MS = 86_400_000;\n\n/** Terminal stage — items here count as completed, not in-flight. */\nconst DONE_STAGE = 'done';\n\n/** Terminal stage for tracked non-completions — never a completion. */\nconst CANCELED_STAGE = 'canceled';\n\n/**\n * Terminal stages — items holding only these are not in-flight. `done` is a\n * completion (feeds throughput/lead time); `canceled` is a tracked\n * non-completion outcome and feeds neither.\n */\nconst TERMINAL_STAGES = new Set([DONE_STAGE, CANCELED_STAGE]);\n\nconst INTAKE_STAGE = 'intake';\n\n/**\n * Pipeline work excludes the inbox as well as the terminal stages: an intake\n * card is queued, not in flight, and its pass through is the poller filing it.\n */\nfunction isPipelineStage(stage: string): boolean {\n return !TERMINAL_STAGES.has(stage) && stage !== INTAKE_STAGE;\n}\n\n/**\n * Cards the Factory ran: starting a run records its session on the row. The\n * integrations sync every issue and PR of a connected repo into the board and\n * those outnumber the Factory's own work by an order of magnitude, so counting\n * them reports the upstream repo's flow as the Factory's.\n */\nfunction hasFactoryRun(item: WorkItemRow): boolean {\n return Object.keys(item.sessions).length > 0;\n}\n\n/**\n * Flow metrics over the cards the Factory ran ({@link hasFactoryRun}) — synced\n * upstream issues and PRs nobody started a run on are not the Factory's work\n * and are excluded from every field below.\n */\nexport interface FactoryMetrics {\n /**\n * Days the series covers: the requested window clipped to the board's life.\n * Days before the first card could hold no completion, so counting them would\n * drag the per-day rate toward zero on a young board.\n */\n daysCovered: number;\n /** Entries into `done` per UTC day, gap-filled across the covered days. */\n throughput: { date: string; count: number }[];\n /** Card creation → `done` for every completion that landed in the window. */\n leadTime: { medianMs: number | null; p90Ms: number | null; samples: number };\n /** Distinct cards in a pipeline stage — past intake, not yet terminal. */\n wipTotal: number;\n /** Cards created in the window, by source. */\n sourceMix: { source: string; count: number }[];\n /** Per-stage agent coverage over first visits that ended in the window. */\n agentCoverage: {\n stage: string;\n /**\n * First visits to this stage that ended in the window. Repeat visits are\n * excluded from both sides: they are rework, already reported as such, and\n * counting them in the denominator alone caps a fully agent-run stage below\n * 100%.\n */\n passes: number;\n /**\n * Of those: passes an agent finished (`exitedBy` is an agent actor). The\n * entry actor is not required — the rules engine is what queues a card into\n * a stage, so demanding both ends would report 0% for stages agents run\n * end to end. Missing `exitedBy` (entries written before exit stamping)\n * does not count.\n */\n byAgent: number;\n /**\n * Outcomes of the agent-finished passes' items as of the window's end,\n * mutually exclusive, first match wins: `reworked` (a later visit to the\n * same stage — deliberately outranks `done`: a pass that needed a redo is a\n * failed pass even if the item eventually merged), then `done`, then\n * `canceled`, then `inFlight`.\n */\n outcomes: { done: number; canceled: number; reworked: number; inFlight: number };\n }[];\n}\n\nconst DATE_ONLY_RE = /^\\d{4}-\\d{2}-\\d{2}$/;\n/** Datetime carrying an explicit `Z` or `±HH:MM` offset. */\nconst ZONED_DATETIME_RE = /(?:[Zz]|[+-]\\d{2}:?\\d{2})$/;\n\nfunction parseRangeParam(value: unknown, boundary: 'from' | 'to'): number | undefined {\n if (typeof value !== 'string' || value.length === 0) return undefined;\n const dateOnly = DATE_ONLY_RE.test(value);\n // Timezone-less datetimes are parsed as server-local by Date.parse, so the\n // window would shift by deployment region — reject them as invalid.\n if (!dateOnly && !ZONED_DATETIME_RE.test(value)) return undefined;\n const time = Date.parse(value);\n if (Number.isNaN(time)) return undefined;\n return boundary === 'to' && dateOnly ? time + DAY_MS : time;\n}\n\nfunction utcDayStart(time: number): number {\n return Date.parse(`${utcDay(time)}T00:00:00Z`);\n}\n\n/**\n * Resolve untrusted `from`/`to` into a bounded half-open UTC window. A date-only\n * `to` covers the whole day; an open/future end resolves to the end of the\n * current UTC day (not `now`) so an event at this instant stays inside the\n * window instead of on its excluded edge.\n */\nexport function parseMetricsRange(\n fromParam: unknown,\n toParam: unknown,\n now: Date,\n): { windowStart: number; windowEnd: number } {\n const nowMs = now.getTime();\n const endOfToday = utcDayStart(nowMs) + DAY_MS;\n const requestedEnd = parseRangeParam(toParam, 'to') ?? endOfToday;\n const windowEnd = Math.min(requestedEnd, endOfToday);\n const lastIncludedDay = utcDayStart(windowEnd - 1);\n const defaultStart = lastIncludedDay - (DEFAULT_METRICS_WINDOW - 1) * DAY_MS;\n const parsedFrom = parseRangeParam(fromParam, 'from');\n let windowStart = parsedFrom !== undefined && parsedFrom < windowEnd ? parsedFrom : defaultStart;\n const earliestStart = lastIncludedDay - (MAX_METRICS_WINDOW - 1) * DAY_MS;\n if (windowStart < earliestStart) windowStart = earliestStart;\n return { windowStart, windowEnd };\n}\n\n/** Stage history is server-appended, so an unparsable stamp is a corrupt row. */\nfunction parseTime(iso: string): number {\n const time = Date.parse(iso);\n if (Number.isNaN(time)) throw new Error(`Unparsable stage-history timestamp: ${iso}`);\n return time;\n}\n\n/** Asserted up front so a corrupt row fails every window, not just the ones that read it. */\nfunction assertParsableHistory(items: WorkItemRow[]): void {\n for (const item of items) {\n for (const entry of item.stageHistory) {\n parseTime(entry.enteredAt);\n if (entry.exitedAt !== undefined) parseTime(entry.exitedAt);\n }\n }\n}\n\n/** Nearest-rank percentile over an unsorted sample list. */\nfunction percentile(samples: number[], fraction: number): number | null {\n if (samples.length === 0) return null;\n const sorted = [...samples].sort((a, b) => a - b);\n const rank = Math.max(1, Math.ceil(fraction * sorted.length));\n return sorted[rank - 1]!;\n}\n\n/** UTC `YYYY-MM-DD` for a timestamp. */\nfunction utcDay(time: number): string {\n return new Date(time).toISOString().slice(0, 10);\n}\n\n/** Stages the item was holding at `time`, replayed from its history. */\nfunction stagesHeldAt(item: WorkItemRow, time: number): Set<string> {\n const held = new Set<string>();\n for (const entry of item.stageHistory) {\n if (parseTime(entry.enteredAt) >= time) continue;\n if (entry.exitedAt !== undefined && parseTime(entry.exitedAt) <= time) continue;\n held.add(entry.stage);\n }\n return held;\n}\n\ntype Window = { windowStart: number; windowEnd: number };\n\n/**\n * Completions per UTC day, plus one lead-time sample each. A completion is an\n * entry *into* `done`, not the state of the card now: a card reopened today\n * must not erase the day it shipped, and a card that shipped twice shipped\n * twice. Days before the oldest card are left out rather than gap-filled with\n * zeroes that would drag the daily average down.\n */\nfunction completions(items: WorkItemRow[], { windowStart, windowEnd }: Window) {\n let earliestItem = Infinity;\n for (const item of items) earliestItem = Math.min(earliestItem, item.createdAt.getTime());\n const boardStart = Number.isFinite(earliestItem) ? utcDayStart(earliestItem) : -Infinity;\n\n const byDay = new Map<string, number>();\n for (let day = Math.max(utcDayStart(windowStart), boardStart); day < windowEnd; day += DAY_MS) {\n byDay.set(utcDay(day), 0);\n }\n\n const leadSamples: number[] = [];\n for (const item of items) {\n for (const entry of item.stageHistory) {\n if (entry.stage !== DONE_STAGE) continue;\n const doneAt = parseTime(entry.enteredAt);\n if (doneAt < windowStart || doneAt >= windowEnd) continue;\n byDay.set(utcDay(doneAt), (byDay.get(utcDay(doneAt)) ?? 0) + 1);\n leadSamples.push(Math.max(0, doneAt - item.createdAt.getTime()));\n }\n }\n return { byDay, leadSamples };\n}\n\n/** Cards holding at least one pipeline stage right now — window-independent. */\nfunction countInFlight(items: WorkItemRow[]): number {\n return items.filter(item => item.stages.some(isPipelineStage)).length;\n}\n\n/** Where the window's cards came from, most common first. */\nfunction demandMix(items: WorkItemRow[], { windowStart, windowEnd }: Window): FactoryMetrics['sourceMix'] {\n const counts = new Map<string, number>();\n for (const item of items) {\n const created = item.createdAt.getTime();\n if (created < windowStart || created >= windowEnd) continue;\n const source = item.externalSource ? `${item.externalSource.integrationId}:${item.externalSource.type}` : 'manual';\n counts.set(source, (counts.get(source) ?? 0) + 1);\n }\n return [...counts.entries()].map(([source, count]) => ({ source, count })).sort((a, b) => b.count - a.count);\n}\n\n/**\n * How much of each stage's work an agent finished, counting a card's first\n * visit to a stage once. Rows appear in insertion order of each stage's first\n * counted exit; only pipeline stages get rows, since intake and terminal\n * stages have no pass to hand over.\n */\nfunction agentCoverage(items: WorkItemRow[], { windowStart, windowEnd }: Window): FactoryMetrics['agentCoverage'] {\n const byStage = new Map<string, FactoryMetrics['agentCoverage'][number]>();\n for (const item of items) {\n const heldAtWindowEnd = stagesHeldAt(item, windowEnd);\n const visited = new Set<string>();\n for (let i = 0; i < item.stageHistory.length; i++) {\n const entry = item.stageHistory[i]!;\n if (!isPipelineStage(entry.stage) || visited.has(entry.stage)) continue;\n visited.add(entry.stage);\n if (entry.exitedAt === undefined) continue;\n const exited = parseTime(entry.exitedAt);\n if (exited < windowStart || exited >= windowEnd) continue;\n\n let row = byStage.get(entry.stage);\n if (!row) {\n row = {\n stage: entry.stage,\n passes: 0,\n byAgent: 0,\n outcomes: { done: 0, canceled: 0, reworked: 0, inFlight: 0 },\n };\n byStage.set(entry.stage, row);\n }\n row.passes += 1;\n if (!isAgentActor(entry.exitedBy)) continue;\n row.byAgent += 1;\n\n const reworked = item.stageHistory.some(\n (later, j) => j > i && later.stage === entry.stage && parseTime(later.enteredAt) < windowEnd,\n );\n if (reworked) row.outcomes.reworked += 1;\n else if (heldAtWindowEnd.has(DONE_STAGE)) row.outcomes.done += 1;\n else if (heldAtWindowEnd.has(CANCELED_STAGE)) row.outcomes.canceled += 1;\n else row.outcomes.inFlight += 1;\n }\n }\n return [...byStage.values()];\n}\n\nexport function computeFactoryMetrics(boardItems: WorkItemRow[], window: Window): FactoryMetrics {\n const items = boardItems.filter(hasFactoryRun);\n assertParsableHistory(items);\n\n const { byDay, leadSamples } = completions(items, window);\n\n return {\n daysCovered: byDay.size,\n throughput: [...byDay.entries()]\n .map(([date, count]) => ({ date, count }))\n .sort((a, b) => a.date.localeCompare(b.date)),\n leadTime: {\n medianMs: percentile(leadSamples, 0.5),\n p90Ms: percentile(leadSamples, 0.9),\n samples: leadSamples.length,\n },\n wipTotal: countInFlight(items),\n sourceMix: demandMix(items, window),\n agentCoverage: agentCoverage(items, window),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,MAAa,yBAAyB;;AAEtC,MAAa,qBAAqB;AAElC,MAAM,SAAS;;AAGf,MAAM,aAAa;;AAGnB,MAAM,iBAAiB;;;;;;AAOvB,MAAM,kCAAkB,IAAI,IAAI,CAAC,YAAY,cAAc,CAAC;AAE5D,MAAM,eAAe;;;;;AAMrB,SAAS,gBAAgB,OAAwB;CAC/C,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,EAAG;GAClC,SAAS,YAAY;EACvB;EACA,UAAU,cAAc,KAAK;EAC7B,WAAW,UAAU,OAAO,MAAM;EAClC,eAAe,cAAc,OAAO,MAAM;CAC5C;AACF"}
|
|
1
|
+
{"version":3,"file":"metrics.js","names":[],"sources":["../../../../src/storage/domains/work-items/metrics.ts"],"sourcesContent":["/**\n * Aggregation math for the Factory Overview page.\n *\n * Pure functions over `work_items` rows — throughput, lead time, in-flight\n * count, demand mix and per-stage agent coverage, all read from the\n * server-appended `stageHistory` log. Keeping this DB-free makes the math unit\n * testable and lets the route stay a thin shell.\n *\n * Everything windowed is counted as an event that happened inside the window,\n * never as \"the state the board happens to be in now\", so re-querying a past\n * window always returns the same numbers.\n */\n\nimport { isAgentActor } from './base.js';\nimport type { Card } from './base.js';\n\n/** Default window span (days) when the request omits or malforms the range. */\nexport const DEFAULT_METRICS_WINDOW = 30;\n/** Hard cap on the range span (days) — bounds the gap-filled throughput array. */\nexport const MAX_METRICS_WINDOW = 366;\n\nconst DAY_MS = 86_400_000;\n\n/** Terminal stage — items here count as completed, not in-flight. */\nconst DONE_STAGE = 'done';\n\n/** Terminal stage for tracked non-completions — never a completion. */\nconst CANCELED_STAGE = 'canceled';\n\n/**\n * Terminal stages — items holding only these are not in-flight. `done` is a\n * completion (feeds throughput/lead time); `canceled` is a tracked\n * non-completion outcome and feeds neither.\n */\nconst TERMINAL_STAGES = new Set([DONE_STAGE, CANCELED_STAGE]);\n\nconst INTAKE_STAGE = 'intake';\n\n/**\n * Pipeline work excludes the inbox as well as the terminal stages: an intake\n * card is queued, not in flight, and its pass through is the poller filing it.\n */\nfunction isPipelineStage(stage: string): boolean {\n return !TERMINAL_STAGES.has(stage) && stage !== INTAKE_STAGE;\n}\n\n/**\n * Cards the Factory ran: starting a run records its session on the row. The\n * integrations sync every issue and PR of a connected repo into the board and\n * those outnumber the Factory's own work by an order of magnitude, so counting\n * them reports the upstream repo's flow as the Factory's.\n */\nfunction hasFactoryRun(item: Card): boolean {\n return Object.keys(item.sessions).length > 0;\n}\n\n/**\n * Flow metrics over the cards the Factory ran ({@link hasFactoryRun}) — synced\n * upstream issues and PRs nobody started a run on are not the Factory's work\n * and are excluded from every field below.\n */\nexport interface FactoryMetrics {\n /**\n * Days the series covers: the requested window clipped to the board's life.\n * Days before the first card could hold no completion, so counting them would\n * drag the per-day rate toward zero on a young board.\n */\n daysCovered: number;\n /** Entries into `done` per UTC day, gap-filled across the covered days. */\n throughput: { date: string; count: number }[];\n /** Card creation → `done` for every completion that landed in the window. */\n leadTime: { medianMs: number | null; p90Ms: number | null; samples: number };\n /** Distinct cards in a pipeline stage — past intake, not yet terminal. */\n wipTotal: number;\n /** Cards created in the window, by source. */\n sourceMix: { source: string; count: number }[];\n /** Per-stage agent coverage over first visits that ended in the window. */\n agentCoverage: {\n stage: string;\n /**\n * First visits to this stage that ended in the window. Repeat visits are\n * excluded from both sides: they are rework, already reported as such, and\n * counting them in the denominator alone caps a fully agent-run stage below\n * 100%.\n */\n passes: number;\n /**\n * Of those: passes an agent finished (`exitedBy` is an agent actor). The\n * entry actor is not required — the rules engine is what queues a card into\n * a stage, so demanding both ends would report 0% for stages agents run\n * end to end. Missing `exitedBy` (entries written before exit stamping)\n * does not count.\n */\n byAgent: number;\n /**\n * Outcomes of the agent-finished passes' items as of the window's end,\n * mutually exclusive, first match wins: `reworked` (a later visit to the\n * same stage — deliberately outranks `done`: a pass that needed a redo is a\n * failed pass even if the item eventually merged), then `done`, then\n * `canceled`, then `inFlight`.\n */\n outcomes: { done: number; canceled: number; reworked: number; inFlight: number };\n }[];\n}\n\nconst DATE_ONLY_RE = /^\\d{4}-\\d{2}-\\d{2}$/;\n/** Datetime carrying an explicit `Z` or `±HH:MM` offset. */\nconst ZONED_DATETIME_RE = /(?:[Zz]|[+-]\\d{2}:?\\d{2})$/;\n\nfunction parseRangeParam(value: unknown, boundary: 'from' | 'to'): number | undefined {\n if (typeof value !== 'string' || value.length === 0) return undefined;\n const dateOnly = DATE_ONLY_RE.test(value);\n // Timezone-less datetimes are parsed as server-local by Date.parse, so the\n // window would shift by deployment region — reject them as invalid.\n if (!dateOnly && !ZONED_DATETIME_RE.test(value)) return undefined;\n const time = Date.parse(value);\n if (Number.isNaN(time)) return undefined;\n return boundary === 'to' && dateOnly ? time + DAY_MS : time;\n}\n\nfunction utcDayStart(time: number): number {\n return Date.parse(`${utcDay(time)}T00:00:00Z`);\n}\n\n/**\n * Resolve untrusted `from`/`to` into a bounded half-open UTC window. A date-only\n * `to` covers the whole day; an open/future end resolves to the end of the\n * current UTC day (not `now`) so an event at this instant stays inside the\n * window instead of on its excluded edge.\n */\nexport function parseMetricsRange(\n fromParam: unknown,\n toParam: unknown,\n now: Date,\n): { windowStart: number; windowEnd: number } {\n const nowMs = now.getTime();\n const endOfToday = utcDayStart(nowMs) + DAY_MS;\n const requestedEnd = parseRangeParam(toParam, 'to') ?? endOfToday;\n const windowEnd = Math.min(requestedEnd, endOfToday);\n const lastIncludedDay = utcDayStart(windowEnd - 1);\n const defaultStart = lastIncludedDay - (DEFAULT_METRICS_WINDOW - 1) * DAY_MS;\n const parsedFrom = parseRangeParam(fromParam, 'from');\n let windowStart = parsedFrom !== undefined && parsedFrom < windowEnd ? parsedFrom : defaultStart;\n const earliestStart = lastIncludedDay - (MAX_METRICS_WINDOW - 1) * DAY_MS;\n if (windowStart < earliestStart) windowStart = earliestStart;\n return { windowStart, windowEnd };\n}\n\n/** Stage history is server-appended, so an unparsable stamp is a corrupt row. */\nfunction parseTime(iso: string): number {\n const time = Date.parse(iso);\n if (Number.isNaN(time)) throw new Error(`Unparsable stage-history timestamp: ${iso}`);\n return time;\n}\n\n/** Asserted up front so a corrupt row fails every window, not just the ones that read it. */\nfunction assertParsableHistory(items: Card[]): void {\n for (const item of items) {\n for (const entry of item.stageHistory) {\n parseTime(entry.enteredAt);\n if (entry.exitedAt !== undefined) parseTime(entry.exitedAt);\n }\n }\n}\n\n/** Nearest-rank percentile over an unsorted sample list. */\nfunction percentile(samples: number[], fraction: number): number | null {\n if (samples.length === 0) return null;\n const sorted = [...samples].sort((a, b) => a - b);\n const rank = Math.max(1, Math.ceil(fraction * sorted.length));\n return sorted[rank - 1]!;\n}\n\n/** UTC `YYYY-MM-DD` for a timestamp. */\nfunction utcDay(time: number): string {\n return new Date(time).toISOString().slice(0, 10);\n}\n\n/** Stages the item was holding at `time`, replayed from its history. */\nfunction stagesHeldAt(item: Card, time: number): Set<string> {\n const held = new Set<string>();\n for (const entry of item.stageHistory) {\n if (parseTime(entry.enteredAt) >= time) continue;\n if (entry.exitedAt !== undefined && parseTime(entry.exitedAt) <= time) continue;\n held.add(entry.stage);\n }\n return held;\n}\n\ntype Window = { windowStart: number; windowEnd: number };\n\n/**\n * Completions per UTC day, plus one lead-time sample each. A completion is an\n * entry *into* `done`, not the state of the card now: a card reopened today\n * must not erase the day it shipped, and a card that shipped twice shipped\n * twice. Days before the oldest card are left out rather than gap-filled with\n * zeroes that would drag the daily average down.\n */\nfunction completions(items: Card[], { windowStart, windowEnd }: Window) {\n let earliestItem = Infinity;\n for (const item of items) earliestItem = Math.min(earliestItem, item.createdAt.getTime());\n const boardStart = Number.isFinite(earliestItem) ? utcDayStart(earliestItem) : -Infinity;\n\n const byDay = new Map<string, number>();\n for (let day = Math.max(utcDayStart(windowStart), boardStart); day < windowEnd; day += DAY_MS) {\n byDay.set(utcDay(day), 0);\n }\n\n const leadSamples: number[] = [];\n for (const item of items) {\n for (const entry of item.stageHistory) {\n if (entry.stage !== DONE_STAGE) continue;\n const doneAt = parseTime(entry.enteredAt);\n if (doneAt < windowStart || doneAt >= windowEnd) continue;\n byDay.set(utcDay(doneAt), (byDay.get(utcDay(doneAt)) ?? 0) + 1);\n leadSamples.push(Math.max(0, doneAt - item.createdAt.getTime()));\n }\n }\n return { byDay, leadSamples };\n}\n\n/** Cards holding at least one pipeline stage right now — window-independent. */\nfunction countInFlight(items: Card[]): number {\n return items.filter(item => item.stages.some(isPipelineStage)).length;\n}\n\n/** Where the window's cards came from, most common first. */\nfunction demandMix(items: Card[], { windowStart, windowEnd }: Window): FactoryMetrics['sourceMix'] {\n const counts = new Map<string, number>();\n for (const item of items) {\n const created = item.createdAt.getTime();\n if (created < windowStart || created >= windowEnd) continue;\n const source = item.externalSource ? `${item.externalSource.integrationId}:${item.externalSource.type}` : 'manual';\n counts.set(source, (counts.get(source) ?? 0) + 1);\n }\n return [...counts.entries()].map(([source, count]) => ({ source, count })).sort((a, b) => b.count - a.count);\n}\n\n/**\n * How much of each stage's work an agent finished, counting a card's first\n * visit to a stage once. Rows appear in insertion order of each stage's first\n * counted exit; only pipeline stages get rows, since intake and terminal\n * stages have no pass to hand over.\n */\nfunction agentCoverage(items: Card[], { windowStart, windowEnd }: Window): FactoryMetrics['agentCoverage'] {\n const byStage = new Map<string, FactoryMetrics['agentCoverage'][number]>();\n for (const item of items) {\n const heldAtWindowEnd = stagesHeldAt(item, windowEnd);\n const visited = new Set<string>();\n for (let i = 0; i < item.stageHistory.length; i++) {\n const entry = item.stageHistory[i]!;\n if (!isPipelineStage(entry.stage) || visited.has(entry.stage)) continue;\n visited.add(entry.stage);\n if (entry.exitedAt === undefined) continue;\n const exited = parseTime(entry.exitedAt);\n if (exited < windowStart || exited >= windowEnd) continue;\n\n let row = byStage.get(entry.stage);\n if (!row) {\n row = {\n stage: entry.stage,\n passes: 0,\n byAgent: 0,\n outcomes: { done: 0, canceled: 0, reworked: 0, inFlight: 0 },\n };\n byStage.set(entry.stage, row);\n }\n row.passes += 1;\n if (!isAgentActor(entry.exitedBy)) continue;\n row.byAgent += 1;\n\n const reworked = item.stageHistory.some(\n (later, j) => j > i && later.stage === entry.stage && parseTime(later.enteredAt) < windowEnd,\n );\n if (reworked) row.outcomes.reworked += 1;\n else if (heldAtWindowEnd.has(DONE_STAGE)) row.outcomes.done += 1;\n else if (heldAtWindowEnd.has(CANCELED_STAGE)) row.outcomes.canceled += 1;\n else row.outcomes.inFlight += 1;\n }\n }\n return [...byStage.values()];\n}\n\nexport function computeFactoryMetrics(boardItems: Card[], window: Window): FactoryMetrics {\n const items = boardItems.filter(hasFactoryRun);\n assertParsableHistory(items);\n\n const { byDay, leadSamples } = completions(items, window);\n\n return {\n daysCovered: byDay.size,\n throughput: [...byDay.entries()]\n .map(([date, count]) => ({ date, count }))\n .sort((a, b) => a.date.localeCompare(b.date)),\n leadTime: {\n medianMs: percentile(leadSamples, 0.5),\n p90Ms: percentile(leadSamples, 0.9),\n samples: leadSamples.length,\n },\n wipTotal: countInFlight(items),\n sourceMix: demandMix(items, window),\n agentCoverage: agentCoverage(items, window),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,MAAa,yBAAyB;;AAEtC,MAAa,qBAAqB;AAElC,MAAM,SAAS;;AAGf,MAAM,aAAa;;AAGnB,MAAM,iBAAiB;;;;;;AAOvB,MAAM,kCAAkB,IAAI,IAAI,CAAC,YAAY,cAAc,CAAC;AAE5D,MAAM,eAAe;;;;;AAMrB,SAAS,gBAAgB,OAAwB;CAC/C,OAAO,CAAC,gBAAgB,IAAI,KAAK,KAAK,UAAU;AAClD;;;;;;;AAQA,SAAS,cAAc,MAAqB;CAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,SAAS;AAC7C;AAmDA,MAAM,eAAe;;AAErB,MAAM,oBAAoB;AAE1B,SAAS,gBAAgB,OAAgB,UAA6C;CACpF,IAAI,OAAO,UAAU,YAAY,MAAM,WAAW,GAAG,OAAO,KAAA;CAC5D,MAAM,WAAW,aAAa,KAAK,KAAK;CAGxC,IAAI,CAAC,YAAY,CAAC,kBAAkB,KAAK,KAAK,GAAG,OAAO,KAAA;CACxD,MAAM,OAAO,KAAK,MAAM,KAAK;CAC7B,IAAI,OAAO,MAAM,IAAI,GAAG,OAAO,KAAA;CAC/B,OAAO,aAAa,QAAQ,WAAW,OAAO,SAAS;AACzD;AAEA,SAAS,YAAY,MAAsB;CACzC,OAAO,KAAK,MAAM,GAAG,OAAO,IAAI,EAAE,WAAW;A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AS,YAAY;QAClC,IAAI,gBAAgB,IAAI,UAAU,GAAG,IAAI,SAAS,QAAQ;QAC1D,IAAI,gBAAgB,IAAI,cAAc,GAAG,IAAI,SAAS,YAAY;QAClE,IAAI,SAAS,YAAY;EAChC;CACF;CACA,OAAO,CAAC,GAAG,QAAQ,OAAO,CAAC;AAC7B;AAEA,SAAgB,sBAAsB,YAAoB,QAAgC;CACxF,MAAM,QAAQ,WAAW,OAAO,aAAa;CAC7C,sBAAsB,KAAK;CAE3B,MAAM,EAAE,OAAO,gBAAgB,YAAY,OAAO,MAAM;CAExD,OAAO;EACL,aAAa,MAAM;EACnB,YAAY,CAAC,GAAG,MAAM,QAAQ,CAAC,CAAC,CAC7B,KAAK,CAAC,MAAM,YAAY;GAAE;GAAM;EAAM,EAAE,CAAC,CACzC,MAAM,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC;EAC9C,UAAU;GACR,UAAU,WAAW,aAAa,EAAG;GACrC,OAAO,WAAW,aAAa,EAAG;GAClC,SAAS,YAAY;EACvB;EACA,UAAU,cAAc,KAAK;EAC7B,WAAW,UAAU,OAAO,MAAM;EAClC,eAAe,cAAc,OAAO,MAAM;CAC5C;AACF"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { CollectionSchema } from '@mastra/core/storage';
|
|
2
|
+
import type { FactoryTriageType } from '../../../rules/types.js';
|
|
3
|
+
export type WorkItemProvider = 'github' | 'gitlab' | 'jira' | 'linear' | 'slack' | 'incidentio' | 'factory' | (string & {});
|
|
4
|
+
/** The work itself; external identities and facts belong to its sources. */
|
|
5
|
+
export declare const FACTORY_WORK_ITEMS_SCHEMA: CollectionSchema;
|
|
6
|
+
/** Several external records can describe one work item. Native work has no source. */
|
|
7
|
+
export declare const FACTORY_WORK_ITEM_SOURCES_SCHEMA: CollectionSchema;
|
|
8
|
+
/** Placement/process state. Its id preserves every legacy card reference. */
|
|
9
|
+
export declare const FACTORY_BOARD_ITEMS_SCHEMA: CollectionSchema;
|
|
10
|
+
export interface WorkItemDbRecord extends Record<string, unknown> {
|
|
11
|
+
id: string;
|
|
12
|
+
org_id: string;
|
|
13
|
+
factory_project_id: string;
|
|
14
|
+
title: string;
|
|
15
|
+
parent_work_item_id: string | null;
|
|
16
|
+
revision: number;
|
|
17
|
+
created_at: Date;
|
|
18
|
+
updated_at: Date;
|
|
19
|
+
}
|
|
20
|
+
export interface WorkItemSourceDbRecord extends Record<string, unknown> {
|
|
21
|
+
id: string;
|
|
22
|
+
org_id: string;
|
|
23
|
+
factory_project_id: string;
|
|
24
|
+
work_item_id: string;
|
|
25
|
+
provider: WorkItemProvider;
|
|
26
|
+
integration_id: string;
|
|
27
|
+
source_type: string;
|
|
28
|
+
workspace_id: string | null;
|
|
29
|
+
external_id: string;
|
|
30
|
+
source_key: string | null;
|
|
31
|
+
url: string | null;
|
|
32
|
+
key: string | null;
|
|
33
|
+
state: string | null;
|
|
34
|
+
labels: string[];
|
|
35
|
+
author: string | null;
|
|
36
|
+
metadata: Record<string, unknown> | null;
|
|
37
|
+
revision: number;
|
|
38
|
+
synced_at: Date | null;
|
|
39
|
+
created_at: Date;
|
|
40
|
+
updated_at: Date;
|
|
41
|
+
}
|
|
42
|
+
export interface WorkItemSourceRow {
|
|
43
|
+
id: string;
|
|
44
|
+
workItemId: string;
|
|
45
|
+
provider: WorkItemProvider;
|
|
46
|
+
integrationId: string;
|
|
47
|
+
sourceType: string;
|
|
48
|
+
workspaceId: string | null;
|
|
49
|
+
externalId: string;
|
|
50
|
+
sourceKey: string | null;
|
|
51
|
+
key: string | null;
|
|
52
|
+
url: string | null;
|
|
53
|
+
state: string | null;
|
|
54
|
+
labels: string[];
|
|
55
|
+
author: string | null;
|
|
56
|
+
metadata: Record<string, unknown> | null;
|
|
57
|
+
revision: number;
|
|
58
|
+
syncedAt: Date | null;
|
|
59
|
+
createdAt: Date;
|
|
60
|
+
updatedAt: Date;
|
|
61
|
+
}
|
|
62
|
+
export declare function primarySource(card: {
|
|
63
|
+
workItem: {
|
|
64
|
+
sources: readonly WorkItemSourceRow[];
|
|
65
|
+
};
|
|
66
|
+
}): WorkItemSourceRow | null;
|
|
67
|
+
export interface WorkItemRow {
|
|
68
|
+
sources: WorkItemSourceRow[];
|
|
69
|
+
id: string;
|
|
70
|
+
orgId: string;
|
|
71
|
+
factoryProjectId: string;
|
|
72
|
+
provider: WorkItemProvider;
|
|
73
|
+
externalId: string;
|
|
74
|
+
key: string | null;
|
|
75
|
+
url: string | null;
|
|
76
|
+
title: string;
|
|
77
|
+
state: string | null;
|
|
78
|
+
labels: string[];
|
|
79
|
+
author: string | null;
|
|
80
|
+
parentWorkItemId: string | null;
|
|
81
|
+
metadata: Record<string, unknown> | null;
|
|
82
|
+
revision: number;
|
|
83
|
+
syncedAt: Date | null;
|
|
84
|
+
createdAt: Date;
|
|
85
|
+
updatedAt: Date;
|
|
86
|
+
}
|
|
87
|
+
export interface BoardItemDbRecord extends Record<string, unknown> {
|
|
88
|
+
id: string;
|
|
89
|
+
org_id: string;
|
|
90
|
+
factory_project_id: string;
|
|
91
|
+
work_item_id: string;
|
|
92
|
+
triage_type: FactoryTriageType | null;
|
|
93
|
+
accepted_at: Date | null;
|
|
94
|
+
autonomy_armed_at: Date | null;
|
|
95
|
+
plans_preapproved_at: Date | null;
|
|
96
|
+
board: string | null;
|
|
97
|
+
parent_board_item_id: string | null;
|
|
98
|
+
stages: string[];
|
|
99
|
+
stage_history: unknown[];
|
|
100
|
+
sessions: Record<string, unknown>;
|
|
101
|
+
metadata: Record<string, unknown> | null;
|
|
102
|
+
comment_count: number;
|
|
103
|
+
feed_activity_at: Date | null;
|
|
104
|
+
revision: number;
|
|
105
|
+
created_by: string;
|
|
106
|
+
created_at: Date;
|
|
107
|
+
updated_at: Date;
|
|
108
|
+
migrated_from_updated_at: Date | null;
|
|
109
|
+
migrated_from_hash: string | null;
|
|
110
|
+
}
|
|
111
|
+
/** Serializes first-copy migration with deletion without locking an entire project's cards. */
|
|
112
|
+
export declare const FACTORY_WORK_ITEM_SPLIT_LOCKS_SCHEMA: CollectionSchema;
|
|
113
|
+
/** Deleted card ids prevent the boot migration resurrecting frozen legacy rows. */
|
|
114
|
+
export declare const FACTORY_BOARD_ITEM_TOMBSTONES_SCHEMA: CollectionSchema;
|
|
115
|
+
/** The pre-split card table. Frozen: only the split migration reads it. */
|
|
116
|
+
export declare const WORK_ITEMS_SCHEMA: CollectionSchema;
|
|
117
|
+
//# sourceMappingURL=work-item-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"work-item-schema.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/work-items/work-item-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,MAAM,MAAM,gBAAgB,GACxB,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,OAAO,GACP,YAAY,GACZ,SAAS,GACT,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAElB,4EAA4E;AAC5E,eAAO,MAAM,yBAAyB,EAAE,gBAavC,CAAC;AAEF,sFAAsF;AACtF,eAAO,MAAM,gCAAgC,EAAE,gBAkC9C,CAAC;AAEF,6EAA6E;AAC7E,eAAO,MAAM,0BAA0B,EAAE,gBAqCxC,CAAC;AAEF,MAAM,WAAW,gBAAiB,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC/D,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,EAAE,MAAM,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,mBAAmB,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;CAClB;AAED,MAAM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E,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,kBAAkB,EAAE,MAAM,CAAC;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACtC,WAAW,EAAE,IAAI,GAAG,IAAI,CAAC;IACzB,iBAAiB,EAAE,IAAI,GAAG,IAAI,CAAC;IAC/B,oBAAoB,EAAE,IAAI,GAAG,IAAI,CAAC;IAClC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,aAAa,EAAE,OAAO,EAAE,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACzC,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,IAAI,GAAG,IAAI,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,IAAI,CAAC;IACjB,UAAU,EAAE,IAAI,CAAC;IACjB,wBAAwB,EAAE,IAAI,GAAG,IAAI,CAAC;IACtC,kBAAkB,EAAE,MAAM,GAAG,IAAI,CAAC;CACnC;AAED,+FAA+F;AAC/F,eAAO,MAAM,oCAAoC,EAAE,gBAOlD,CAAC;AAEF,mFAAmF;AACnF,eAAO,MAAM,oCAAoC,EAAE,gBAOlD,CAAC;AAEF,2EAA2E;AAC3E,eAAO,MAAM,iBAAiB,EAAE,gBAyD/B,CAAC"}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
// src/storage/domains/work-items/work-item-schema.ts
|
|
2
|
+
/** The work itself; external identities and facts belong to its sources. */
|
|
3
|
+
const FACTORY_WORK_ITEMS_SCHEMA = {
|
|
4
|
+
name: "factory_work_items",
|
|
5
|
+
columns: {
|
|
6
|
+
id: { type: "uuid-pk" },
|
|
7
|
+
org_id: { type: "text" },
|
|
8
|
+
factory_project_id: { type: "text" },
|
|
9
|
+
title: { type: "text" },
|
|
10
|
+
parent_work_item_id: {
|
|
11
|
+
type: "text",
|
|
12
|
+
nullable: true
|
|
13
|
+
},
|
|
14
|
+
revision: {
|
|
15
|
+
type: "integer",
|
|
16
|
+
default: 1
|
|
17
|
+
},
|
|
18
|
+
created_at: { type: "timestamp" },
|
|
19
|
+
updated_at: { type: "timestamp" }
|
|
20
|
+
},
|
|
21
|
+
indexes: [{
|
|
22
|
+
name: "factory_work_items_org_project_idx",
|
|
23
|
+
columns: ["org_id", "factory_project_id"]
|
|
24
|
+
}]
|
|
25
|
+
};
|
|
26
|
+
/** Several external records can describe one work item. Native work has no source. */
|
|
27
|
+
const FACTORY_WORK_ITEM_SOURCES_SCHEMA = {
|
|
28
|
+
name: "factory_work_item_sources",
|
|
29
|
+
columns: {
|
|
30
|
+
id: { type: "uuid-pk" },
|
|
31
|
+
org_id: { type: "text" },
|
|
32
|
+
factory_project_id: { type: "text" },
|
|
33
|
+
work_item_id: { type: "text" },
|
|
34
|
+
provider: { type: "text" },
|
|
35
|
+
integration_id: { type: "text" },
|
|
36
|
+
source_type: { type: "text" },
|
|
37
|
+
workspace_id: {
|
|
38
|
+
type: "text",
|
|
39
|
+
nullable: true
|
|
40
|
+
},
|
|
41
|
+
external_id: { type: "text" },
|
|
42
|
+
source_key: {
|
|
43
|
+
type: "text",
|
|
44
|
+
nullable: true
|
|
45
|
+
},
|
|
46
|
+
url: {
|
|
47
|
+
type: "text",
|
|
48
|
+
nullable: true
|
|
49
|
+
},
|
|
50
|
+
key: {
|
|
51
|
+
type: "text",
|
|
52
|
+
nullable: true
|
|
53
|
+
},
|
|
54
|
+
state: {
|
|
55
|
+
type: "text",
|
|
56
|
+
nullable: true
|
|
57
|
+
},
|
|
58
|
+
labels: { type: "json" },
|
|
59
|
+
author: {
|
|
60
|
+
type: "text",
|
|
61
|
+
nullable: true
|
|
62
|
+
},
|
|
63
|
+
metadata: {
|
|
64
|
+
type: "json",
|
|
65
|
+
nullable: true
|
|
66
|
+
},
|
|
67
|
+
revision: {
|
|
68
|
+
type: "integer",
|
|
69
|
+
default: 1
|
|
70
|
+
},
|
|
71
|
+
synced_at: {
|
|
72
|
+
type: "timestamp",
|
|
73
|
+
nullable: true
|
|
74
|
+
},
|
|
75
|
+
created_at: { type: "timestamp" },
|
|
76
|
+
updated_at: { type: "timestamp" }
|
|
77
|
+
},
|
|
78
|
+
uniqueIndexes: [{
|
|
79
|
+
name: "factory_work_item_sources_project_provider_external_unique",
|
|
80
|
+
columns: [
|
|
81
|
+
"org_id",
|
|
82
|
+
"factory_project_id",
|
|
83
|
+
"provider",
|
|
84
|
+
"external_id"
|
|
85
|
+
]
|
|
86
|
+
}],
|
|
87
|
+
indexes: [{
|
|
88
|
+
name: "factory_work_item_sources_work_item_idx",
|
|
89
|
+
columns: ["work_item_id"]
|
|
90
|
+
}, {
|
|
91
|
+
name: "factory_work_item_sources_source_key_idx",
|
|
92
|
+
columns: ["source_key"]
|
|
93
|
+
}]
|
|
94
|
+
};
|
|
95
|
+
/** Placement/process state. Its id preserves every legacy card reference. */
|
|
96
|
+
const FACTORY_BOARD_ITEMS_SCHEMA = {
|
|
97
|
+
name: "factory_board_items",
|
|
98
|
+
columns: {
|
|
99
|
+
id: { type: "uuid-pk" },
|
|
100
|
+
org_id: { type: "text" },
|
|
101
|
+
factory_project_id: { type: "text" },
|
|
102
|
+
work_item_id: { type: "text" },
|
|
103
|
+
triage_type: {
|
|
104
|
+
type: "text",
|
|
105
|
+
nullable: true
|
|
106
|
+
},
|
|
107
|
+
accepted_at: {
|
|
108
|
+
type: "timestamp",
|
|
109
|
+
nullable: true
|
|
110
|
+
},
|
|
111
|
+
autonomy_armed_at: {
|
|
112
|
+
type: "timestamp",
|
|
113
|
+
nullable: true
|
|
114
|
+
},
|
|
115
|
+
plans_preapproved_at: {
|
|
116
|
+
type: "timestamp",
|
|
117
|
+
nullable: true
|
|
118
|
+
},
|
|
119
|
+
board: {
|
|
120
|
+
type: "text",
|
|
121
|
+
nullable: true
|
|
122
|
+
},
|
|
123
|
+
parent_board_item_id: {
|
|
124
|
+
type: "text",
|
|
125
|
+
nullable: true
|
|
126
|
+
},
|
|
127
|
+
stages: { type: "json" },
|
|
128
|
+
stage_history: { type: "json" },
|
|
129
|
+
sessions: { type: "json" },
|
|
130
|
+
metadata: {
|
|
131
|
+
type: "json",
|
|
132
|
+
nullable: true
|
|
133
|
+
},
|
|
134
|
+
comment_count: {
|
|
135
|
+
type: "integer",
|
|
136
|
+
default: 0
|
|
137
|
+
},
|
|
138
|
+
feed_activity_at: {
|
|
139
|
+
type: "timestamp",
|
|
140
|
+
nullable: true
|
|
141
|
+
},
|
|
142
|
+
revision: {
|
|
143
|
+
type: "integer",
|
|
144
|
+
default: 1
|
|
145
|
+
},
|
|
146
|
+
created_by: { type: "text" },
|
|
147
|
+
created_at: { type: "timestamp" },
|
|
148
|
+
updated_at: { type: "timestamp" },
|
|
149
|
+
migrated_from_updated_at: {
|
|
150
|
+
type: "timestamp",
|
|
151
|
+
nullable: true
|
|
152
|
+
},
|
|
153
|
+
migrated_from_hash: {
|
|
154
|
+
type: "text",
|
|
155
|
+
nullable: true
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
uniqueIndexes: [{
|
|
159
|
+
name: "factory_board_items_work_item_unique",
|
|
160
|
+
columns: ["work_item_id"]
|
|
161
|
+
}],
|
|
162
|
+
indexes: [{
|
|
163
|
+
name: "factory_board_items_org_project_created_at_id_idx",
|
|
164
|
+
columns: [
|
|
165
|
+
"org_id",
|
|
166
|
+
"factory_project_id",
|
|
167
|
+
"created_at",
|
|
168
|
+
"id"
|
|
169
|
+
]
|
|
170
|
+
}, {
|
|
171
|
+
name: "factory_board_items_project_parent_idx",
|
|
172
|
+
columns: [
|
|
173
|
+
"org_id",
|
|
174
|
+
"factory_project_id",
|
|
175
|
+
"parent_board_item_id"
|
|
176
|
+
]
|
|
177
|
+
}]
|
|
178
|
+
};
|
|
179
|
+
function primarySource(card) {
|
|
180
|
+
return card.workItem.sources[0] ?? null;
|
|
181
|
+
}
|
|
182
|
+
/** Serializes first-copy migration with deletion without locking an entire project's cards. */
|
|
183
|
+
const FACTORY_WORK_ITEM_SPLIT_LOCKS_SCHEMA = {
|
|
184
|
+
name: "factory_work_item_split_locks",
|
|
185
|
+
columns: {
|
|
186
|
+
id: { type: "uuid-pk" },
|
|
187
|
+
org_id: { type: "text" },
|
|
188
|
+
factory_project_id: { type: "text" }
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
/** Deleted card ids prevent the boot migration resurrecting frozen legacy rows. */
|
|
192
|
+
const FACTORY_BOARD_ITEM_TOMBSTONES_SCHEMA = {
|
|
193
|
+
name: "factory_board_item_tombstones",
|
|
194
|
+
columns: {
|
|
195
|
+
id: { type: "uuid-pk" },
|
|
196
|
+
org_id: { type: "text" },
|
|
197
|
+
factory_project_id: { type: "text" }
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
/** The pre-split card table. Frozen: only the split migration reads it. */
|
|
201
|
+
const WORK_ITEMS_SCHEMA = {
|
|
202
|
+
name: "work_items",
|
|
203
|
+
columns: {
|
|
204
|
+
id: { type: "uuid-pk" },
|
|
205
|
+
org_id: { type: "text" },
|
|
206
|
+
factory_project_id: { type: "text" },
|
|
207
|
+
board: {
|
|
208
|
+
type: "text",
|
|
209
|
+
nullable: true
|
|
210
|
+
},
|
|
211
|
+
external_source: {
|
|
212
|
+
type: "json",
|
|
213
|
+
nullable: true
|
|
214
|
+
},
|
|
215
|
+
source_key: {
|
|
216
|
+
type: "text",
|
|
217
|
+
nullable: true
|
|
218
|
+
},
|
|
219
|
+
claim_key: {
|
|
220
|
+
type: "text",
|
|
221
|
+
nullable: true
|
|
222
|
+
},
|
|
223
|
+
parent_work_item_id: {
|
|
224
|
+
type: "text",
|
|
225
|
+
nullable: true
|
|
226
|
+
},
|
|
227
|
+
title: { type: "text" },
|
|
228
|
+
stages: { type: "json" },
|
|
229
|
+
stage_history: { type: "json" },
|
|
230
|
+
sessions: { type: "json" },
|
|
231
|
+
metadata: {
|
|
232
|
+
type: "json",
|
|
233
|
+
nullable: true
|
|
234
|
+
},
|
|
235
|
+
triage_type: {
|
|
236
|
+
type: "text",
|
|
237
|
+
nullable: true
|
|
238
|
+
},
|
|
239
|
+
autonomy_armed_at: {
|
|
240
|
+
type: "timestamp",
|
|
241
|
+
nullable: true
|
|
242
|
+
},
|
|
243
|
+
plans_preapproved_at: {
|
|
244
|
+
type: "timestamp",
|
|
245
|
+
nullable: true
|
|
246
|
+
},
|
|
247
|
+
accepted_at: {
|
|
248
|
+
type: "timestamp",
|
|
249
|
+
nullable: true
|
|
250
|
+
},
|
|
251
|
+
comment_count: {
|
|
252
|
+
type: "integer",
|
|
253
|
+
default: 0
|
|
254
|
+
},
|
|
255
|
+
feed_activity_at: {
|
|
256
|
+
type: "timestamp",
|
|
257
|
+
nullable: true
|
|
258
|
+
},
|
|
259
|
+
revision: {
|
|
260
|
+
type: "integer",
|
|
261
|
+
default: 1
|
|
262
|
+
},
|
|
263
|
+
created_by: { type: "text" },
|
|
264
|
+
created_at: { type: "timestamp" },
|
|
265
|
+
updated_at: { type: "timestamp" }
|
|
266
|
+
},
|
|
267
|
+
uniqueIndexes: [{
|
|
268
|
+
name: "work_items_project_source_key_unique",
|
|
269
|
+
columns: ["factory_project_id", "source_key"]
|
|
270
|
+
}, {
|
|
271
|
+
name: "work_items_org_claim_key_unique",
|
|
272
|
+
columns: ["org_id", "claim_key"]
|
|
273
|
+
}],
|
|
274
|
+
indexes: [
|
|
275
|
+
{
|
|
276
|
+
name: "work_items_org_project_created_at_id_idx",
|
|
277
|
+
columns: [
|
|
278
|
+
"org_id",
|
|
279
|
+
"factory_project_id",
|
|
280
|
+
"created_at",
|
|
281
|
+
"id"
|
|
282
|
+
]
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
name: "work_items_project_parent_idx",
|
|
286
|
+
columns: [
|
|
287
|
+
"org_id",
|
|
288
|
+
"factory_project_id",
|
|
289
|
+
"parent_work_item_id"
|
|
290
|
+
]
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
name: "work_items_source_key_idx",
|
|
294
|
+
columns: ["source_key"]
|
|
295
|
+
}
|
|
296
|
+
]
|
|
297
|
+
};
|
|
298
|
+
export { FACTORY_BOARD_ITEMS_SCHEMA, FACTORY_BOARD_ITEM_TOMBSTONES_SCHEMA, FACTORY_WORK_ITEMS_SCHEMA, FACTORY_WORK_ITEM_SOURCES_SCHEMA, FACTORY_WORK_ITEM_SPLIT_LOCKS_SCHEMA, WORK_ITEMS_SCHEMA, primarySource };
|
|
299
|
+
|
|
300
|
+
//# sourceMappingURL=work-item-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"work-item-schema.js","names":[],"sources":["../../../../src/storage/domains/work-items/work-item-schema.ts"],"sourcesContent":["import type { CollectionSchema } from '@mastra/core/storage';\n\nimport type { FactoryTriageType } from '../../../rules/types.js';\n\nexport type WorkItemProvider =\n | 'github'\n | 'gitlab'\n | 'jira'\n | 'linear'\n | 'slack'\n | 'incidentio'\n | 'factory'\n | (string & {});\n\n/** The work itself; external identities and facts belong to its sources. */\nexport const FACTORY_WORK_ITEMS_SCHEMA: CollectionSchema = {\n name: 'factory_work_items',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n title: { type: 'text' },\n parent_work_item_id: { type: 'text', nullable: true },\n revision: { type: 'integer', default: 1 },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n indexes: [{ name: 'factory_work_items_org_project_idx', columns: ['org_id', 'factory_project_id'] }],\n};\n\n/** Several external records can describe one work item. Native work has no source. */\nexport const FACTORY_WORK_ITEM_SOURCES_SCHEMA: CollectionSchema = {\n name: 'factory_work_item_sources',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n work_item_id: { type: 'text' },\n provider: { type: 'text' },\n integration_id: { type: 'text' },\n source_type: { type: 'text' },\n workspace_id: { type: 'text', nullable: true },\n external_id: { type: 'text' },\n source_key: { type: 'text', nullable: true },\n url: { type: 'text', nullable: true },\n key: { type: 'text', nullable: true },\n state: { type: 'text', nullable: true },\n labels: { type: 'json' },\n author: { type: 'text', nullable: true },\n metadata: { type: 'json', nullable: true },\n revision: { type: 'integer', default: 1 },\n synced_at: { type: 'timestamp', nullable: true },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n {\n name: 'factory_work_item_sources_project_provider_external_unique',\n columns: ['org_id', 'factory_project_id', 'provider', 'external_id'],\n },\n ],\n indexes: [\n { name: 'factory_work_item_sources_work_item_idx', columns: ['work_item_id'] },\n { name: 'factory_work_item_sources_source_key_idx', columns: ['source_key'] },\n ],\n};\n\n/** Placement/process state. Its id preserves every legacy card reference. */\nexport const FACTORY_BOARD_ITEMS_SCHEMA: CollectionSchema = {\n name: 'factory_board_items',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n work_item_id: { type: 'text' },\n triage_type: { type: 'text', nullable: true },\n accepted_at: { type: 'timestamp', nullable: true },\n autonomy_armed_at: { type: 'timestamp', nullable: true },\n plans_preapproved_at: { type: 'timestamp', nullable: true },\n board: { type: 'text', nullable: true },\n parent_board_item_id: { type: 'text', nullable: true },\n stages: { type: 'json' },\n stage_history: { type: 'json' },\n sessions: { type: 'json' },\n metadata: { type: 'json', nullable: true },\n comment_count: { type: 'integer', default: 0 },\n feed_activity_at: { type: 'timestamp', nullable: true },\n revision: { type: 'integer', default: 1 },\n created_by: { type: 'text' },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n migrated_from_updated_at: { type: 'timestamp', nullable: true },\n migrated_from_hash: { type: 'text', nullable: true },\n },\n uniqueIndexes: [{ name: 'factory_board_items_work_item_unique', columns: ['work_item_id'] }],\n indexes: [\n {\n name: 'factory_board_items_org_project_created_at_id_idx',\n columns: ['org_id', 'factory_project_id', 'created_at', 'id'],\n },\n {\n name: 'factory_board_items_project_parent_idx',\n columns: ['org_id', 'factory_project_id', 'parent_board_item_id'],\n },\n ],\n};\n\nexport interface WorkItemDbRecord extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n title: string;\n parent_work_item_id: string | null;\n revision: number;\n created_at: Date;\n updated_at: Date;\n}\n\nexport interface WorkItemSourceDbRecord extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n work_item_id: string;\n provider: WorkItemProvider;\n integration_id: string;\n source_type: string;\n workspace_id: string | null;\n external_id: string;\n source_key: string | null;\n url: string | null;\n key: string | null;\n state: string | null;\n labels: string[];\n author: string | null;\n metadata: Record<string, unknown> | null;\n revision: number;\n synced_at: Date | null;\n created_at: Date;\n updated_at: Date;\n}\n\nexport interface WorkItemSourceRow {\n id: string;\n workItemId: string;\n provider: WorkItemProvider;\n integrationId: string;\n sourceType: string;\n workspaceId: string | null;\n externalId: string;\n sourceKey: string | null;\n key: string | null;\n url: string | null;\n state: string | null;\n labels: string[];\n author: string | null;\n metadata: Record<string, unknown> | null;\n revision: number;\n syncedAt: Date | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport function primarySource(card: { workItem: { sources: readonly WorkItemSourceRow[] } }): WorkItemSourceRow | null {\n return card.workItem.sources[0] ?? null;\n}\n\nexport interface WorkItemRow {\n sources: WorkItemSourceRow[];\n id: string;\n orgId: string;\n factoryProjectId: string;\n provider: WorkItemProvider;\n externalId: string;\n key: string | null;\n url: string | null;\n title: string;\n state: string | null;\n labels: string[];\n author: string | null;\n parentWorkItemId: string | null;\n metadata: Record<string, unknown> | null;\n revision: number;\n syncedAt: Date | null;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface BoardItemDbRecord extends Record<string, unknown> {\n id: string;\n org_id: string;\n factory_project_id: string;\n work_item_id: string;\n triage_type: FactoryTriageType | null;\n accepted_at: Date | null;\n autonomy_armed_at: Date | null;\n plans_preapproved_at: Date | null;\n board: string | null;\n parent_board_item_id: string | null;\n stages: string[];\n stage_history: unknown[];\n sessions: Record<string, unknown>;\n metadata: Record<string, unknown> | null;\n comment_count: number;\n feed_activity_at: Date | null;\n revision: number;\n created_by: string;\n created_at: Date;\n updated_at: Date;\n migrated_from_updated_at: Date | null;\n migrated_from_hash: string | null;\n}\n\n/** Serializes first-copy migration with deletion without locking an entire project's cards. */\nexport const FACTORY_WORK_ITEM_SPLIT_LOCKS_SCHEMA: CollectionSchema = {\n name: 'factory_work_item_split_locks',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n },\n};\n\n/** Deleted card ids prevent the boot migration resurrecting frozen legacy rows. */\nexport const FACTORY_BOARD_ITEM_TOMBSTONES_SCHEMA: CollectionSchema = {\n name: 'factory_board_item_tombstones',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n },\n};\n\n/** The pre-split card table. Frozen: only the split migration reads it. */\nexport const WORK_ITEMS_SCHEMA: CollectionSchema = {\n name: 'work_items',\n columns: {\n id: { type: 'uuid-pk' },\n org_id: { type: 'text' },\n factory_project_id: { type: 'text' },\n board: { type: 'text', nullable: true },\n external_source: { type: 'json', nullable: true },\n source_key: { type: 'text', nullable: true },\n // Retained for existing tables; claims no longer govern work-item identity.\n claim_key: { type: 'text', nullable: true },\n parent_work_item_id: { type: 'text', nullable: true },\n title: { type: 'text' },\n stages: { type: 'json' },\n stage_history: { type: 'json' },\n sessions: { type: 'json' },\n metadata: { type: 'json', nullable: true },\n triage_type: { type: 'text', nullable: true },\n autonomy_armed_at: { type: 'timestamp', nullable: true },\n // Retired hands-off plan grant: plans are approved per board (`exitTool`).\n plans_preapproved_at: { type: 'timestamp', nullable: true },\n accepted_at: { type: 'timestamp', nullable: true },\n comment_count: { type: 'integer', default: 0 },\n feed_activity_at: { type: 'timestamp', nullable: true },\n revision: { type: 'integer', default: 1 },\n created_by: { type: 'text' },\n created_at: { type: 'timestamp' },\n updated_at: { type: 'timestamp' },\n },\n uniqueIndexes: [\n {\n name: 'work_items_project_source_key_unique',\n columns: ['factory_project_id', 'source_key'],\n },\n {\n // One live card per claimed external record per org. NULL keys never\n // collide, so unclaimed cards are unaffected.\n name: 'work_items_org_claim_key_unique',\n columns: ['org_id', 'claim_key'],\n },\n ],\n indexes: [\n {\n name: 'work_items_org_project_created_at_id_idx',\n columns: ['org_id', 'factory_project_id', 'created_at', 'id'],\n },\n {\n name: 'work_items_project_parent_idx',\n columns: ['org_id', 'factory_project_id', 'parent_work_item_id'],\n },\n {\n // The unique index leads with `factory_project_id`, so it cannot serve a\n // lookup by the key alone — which is what a platform message has.\n name: 'work_items_source_key_idx',\n columns: ['source_key'],\n },\n ],\n};\n"],"mappings":";;AAeA,MAAa,4BAA8C;CACzD,MAAM;CACN,SAAS;EACP,IAAI,EAAE,MAAM,UAAU;EACtB,QAAQ,EAAE,MAAM,OAAO;EACvB,oBAAoB,EAAE,MAAM,OAAO;EACnC,OAAO,EAAE,MAAM,OAAO;EACtB,qBAAqB;GAAE,MAAM;GAAQ,UAAU;EAAK;EACpD,UAAU;GAAE,MAAM;GAAW,SAAS;EAAE;EACxC,YAAY,EAAE,MAAM,YAAY;EAChC,YAAY,EAAE,MAAM,YAAY;CAClC;CACA,SAAS,CAAC;EAAE,MAAM;EAAsC,SAAS,CAAC,UAAU,oBAAoB;CAAE,CAAC;AACrG;;AAGA,MAAa,mCAAqD;CAChE,MAAM;CACN,SAAS;EACP,IAAI,EAAE,MAAM,UAAU;EACtB,QAAQ,EAAE,MAAM,OAAO;EACvB,oBAAoB,EAAE,MAAM,OAAO;EACnC,cAAc,EAAE,MAAM,OAAO;EAC7B,UAAU,EAAE,MAA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AE,MAAM;GAAQ,UAAU;EAAK;EAChD,YAAY;GAAE,MAAM;GAAQ,UAAU;EAAK;EAE3C,WAAW;GAAE,MAAM;GAAQ,UAAU;EAAK;EAC1C,qBAAqB;GAAE,MAAM;GAAQ,UAAU;EAAK;EACpD,OAAO,EAAE,MAAM,OAAO;EACtB,QAAQ,EAAE,MAAM,OAAO;EACvB,eAAe,EAAE,MAAM,OAAO;EAC9B,UAAU,EAAE,MAAM,OAAO;EACzB,UAAU;GAAE,MAAM;GAAQ,UAAU;EAAK;EACzC,aAAa;GAAE,MAAM;GAAQ,UAAU;EAAK;EAC5C,mBAAmB;GAAE,MAAM;GAAa,UAAU;EAAK;EAEvD,sBAAsB;GAAE,MAAM;GAAa,UAAU;EAAK;EAC1D,aAAa;GAAE,MAAM;GAAa,UAAU;EAAK;EACjD,eAAe;GAAE,MAAM;GAAW,SAAS;EAAE;EAC7C,kBAAkB;GAAE,MAAM;GAAa,UAAU;EAAK;EACtD,UAAU;GAAE,MAAM;GAAW,SAAS;EAAE;EACxC,YAAY,EAAE,MAAM,OAAO;EAC3B,YAAY,EAAE,MAAM,YAAY;EAChC,YAAY,EAAE,MAAM,YAAY;CAClC;CACA,eAAe,CACb;EACE,MAAM;EACN,SAAS,CAAC,sBAAsB,YAAY;CAC9C,GACA;EAGE,MAAM;EACN,SAAS,CAAC,UAAU,WAAW;CACjC,CACF;CACA,SAAS;EACP;GACE,MAAM;GACN,SAAS;IAAC;IAAU;IAAsB;IAAc;GAAI;EAC9D;EACA;GACE,MAAM;GACN,SAAS;IAAC;IAAU;IAAsB;GAAqB;EACjE;EACA;GAGE,MAAM;GACN,SAAS,CAAC,YAAY;EACxB;CACF;AACF"}
|
|
@@ -4,7 +4,7 @@ import type { ProjectBoardSource } from '../boards/project-boards.js';
|
|
|
4
4
|
import type { IntegrationTools } from '../integrations/base.js';
|
|
5
5
|
import type { AuditStorage } from '../storage/domains/audit/base.js';
|
|
6
6
|
import type { WorkItemCommentsStorage } from '../storage/domains/comments/base.js';
|
|
7
|
-
import type {
|
|
7
|
+
import type { Card, WorkItemsStorage } from '../storage/domains/work-items/base.js';
|
|
8
8
|
import type { FactoryMessaging } from './messaging-tools.js';
|
|
9
9
|
import type { FactoryToolScope } from './scope.js';
|
|
10
10
|
export declare const MAX_TEXT = 600;
|
|
@@ -21,12 +21,12 @@ export interface FactoryReadToolDependencies {
|
|
|
21
21
|
}
|
|
22
22
|
export declare function truncate(text: string, max: number): string;
|
|
23
23
|
/** The number a person sees on the card: the issue or PR number the item was filed from. */
|
|
24
|
-
export declare function workItemNumber(item: Pick<
|
|
25
|
-
export declare function workItemStage(item: Pick<
|
|
24
|
+
export declare function workItemNumber(item: Pick<Card, 'workItem'>): number | null;
|
|
25
|
+
export declare function workItemStage(item: Pick<Card, 'stages'>): string;
|
|
26
26
|
/** A work item id or its card number; anything else can't name an item. */
|
|
27
27
|
export declare const workItemRefSchema: z.ZodString;
|
|
28
28
|
/** Resolve `<uuid>` or `#123` to an item in this Factory only. Pass a ref validated by `workItemRefSchema`. */
|
|
29
|
-
export declare function findWorkItem(workItems: Pick<WorkItemsStorage, 'list' | 'getForProject'>, scope: Pick<FactoryToolScope, 'orgId' | 'factoryProjectId'>, ref: string): Promise<
|
|
29
|
+
export declare function findWorkItem(workItems: Pick<WorkItemsStorage, 'list' | 'getForProject'>, scope: Pick<FactoryToolScope, 'orgId' | 'factoryProjectId'>, ref: string): Promise<Card | null>;
|
|
30
30
|
export declare function workItemNotFound(ref: string): Error;
|
|
31
31
|
export declare function createFactoryReadTools(scope: FactoryToolScope, deps: FactoryReadToolDependencies): IntegrationTools;
|
|
32
32
|
//# sourceMappingURL=read-tools.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-tools.d.ts","sourceRoot":"","sources":["../../src/tools/read-tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EAAE,aAAa,EAAE,MA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C3C,mHAAmH;IACnH,SAAS,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE,YAAY,CAAC,GAAG,IAAI,CAAC,CAAC;CACxE;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAE1D;AAQD,4FAA4F;AAC5F,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,GAAG,MAAM,GAAG,IAAI,CAM1E;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,MAAM,CAEhE;AAED,2EAA2E;AAC3E,eAAO,MAAM,iBAAiB,aAOyB,CAAC;AAExD,+GAA+G;AAC/G,wBAAsB,YAAY,CAChC,SAAS,EAAE,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,eAAe,CAAC,EAC3D,KAAK,EAAE,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,kBAAkB,CAAC,EAC3D,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAQtB;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAEnD;AAsFD,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,2BAA2B,GAAG,gBAAgB,CA2NnH"}
|
package/dist/tools/read-tools.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { needsApproval } from "../rules/types.js";
|
|
2
|
+
import { factoryDispatchFailureMetadata } from "../rules/dispatch-errors.js";
|
|
1
3
|
import { boardForWorkItem } from "../boards/semantics.js";
|
|
2
4
|
import "../boards/index.js";
|
|
3
5
|
import { toBoardSource } from "../boards/project-boards.js";
|
|
4
|
-
import { factoryDispatchFailureMetadata } from "../rules/dispatch-errors.js";
|
|
5
6
|
import { sessionActivity } from "./deliver.js";
|
|
6
7
|
import { factorySessionUrl, factoryWorkItemUrl } from "../links.js";
|
|
7
8
|
import { decisionRetryable, overtakenDecisionIds } from "../rules/decision-applicability.js";
|
|
@@ -22,7 +23,7 @@ function iso(value) {
|
|
|
22
23
|
}
|
|
23
24
|
/** The number a person sees on the card: the issue or PR number the item was filed from. */
|
|
24
25
|
function workItemNumber(item) {
|
|
25
|
-
const number = item.metadata?.number ?? item.metadata?.githubIssueNumber ?? item.metadata?.githubPullRequestNumber;
|
|
26
|
+
const number = item.workItem.metadata?.number ?? item.workItem.metadata?.githubIssueNumber ?? item.workItem.metadata?.githubPullRequestNumber;
|
|
26
27
|
return typeof number === "number" ? number : null;
|
|
27
28
|
}
|
|
28
29
|
function workItemStage(item) {
|
|
@@ -87,9 +88,20 @@ function summarizeDecision(decision, overtaken = false) {
|
|
|
87
88
|
updatedAt: iso(decision.updatedAt)
|
|
88
89
|
};
|
|
89
90
|
}
|
|
90
|
-
|
|
91
|
+
const PAST_TRIAGE = /* @__PURE__ */ new Set([
|
|
92
|
+
"planning",
|
|
93
|
+
"execute",
|
|
94
|
+
"review"
|
|
95
|
+
]);
|
|
96
|
+
/**
|
|
97
|
+
* Held: a Work card triage left in Intake (or whose source asks for approval), until a person
|
|
98
|
+
* moves it on. A card that has been past Triage since (parked by self-review, or dragged back)
|
|
99
|
+
* resumes instead, matching the board's held state.
|
|
100
|
+
*/
|
|
91
101
|
function isHeld(item) {
|
|
92
|
-
|
|
102
|
+
if (boardForWorkItem(item) !== "work" || item.stages[0] !== "intake") return false;
|
|
103
|
+
if (needsApproval(item)) return true;
|
|
104
|
+
return item.sessions.triage !== void 0 && !item.stageHistory.some((entry) => PAST_TRIAGE.has(entry.stage));
|
|
93
105
|
}
|
|
94
106
|
const listInputSchema = z.object({
|
|
95
107
|
query: z.string().trim().min(1).max(200).optional().describe("Case-insensitive text in the title, or an exact card number like \"#123\"."),
|
|
@@ -178,7 +190,7 @@ function createFactoryReadTools(scope, deps) {
|
|
|
178
190
|
]);
|
|
179
191
|
const itemDecisions = decisions.slice(-50);
|
|
180
192
|
const overtaken = await overtakenDecisionIds(deps.workItems, await toBoardSource(deps.boards).load(project), project, itemDecisions.filter((decision) => decision.status === "failed"));
|
|
181
|
-
const labels = Array.isArray(item.
|
|
193
|
+
const labels = Array.isArray(item.workItem.labels) ? item.workItem.labels.filter((label) => typeof label === "string").slice(0, 50) : [];
|
|
182
194
|
const parent = item.parentWorkItemId ? all.find((candidate) => candidate.id === item.parentWorkItemId) : void 0;
|
|
183
195
|
const children = all.filter((candidate) => candidate.parentWorkItemId === item.id);
|
|
184
196
|
const controller = (await deps.messaging?.())?.controller;
|
|
@@ -203,8 +215,7 @@ function createFactoryReadTools(scope, deps) {
|
|
|
203
215
|
item: {
|
|
204
216
|
...summarizeItem(item, bindings),
|
|
205
217
|
source: item.externalSource ? `${item.externalSource.integrationId}:${item.externalSource.type}` : "manual",
|
|
206
|
-
sourceUrl: typeof item.
|
|
207
|
-
triageType: item.triageType,
|
|
218
|
+
sourceUrl: typeof item.workItem.url === "string" ? item.workItem.url : null,
|
|
208
219
|
revision: item.revision
|
|
209
220
|
},
|
|
210
221
|
labels,
|
|
@@ -241,7 +252,7 @@ function createFactoryReadTools(scope, deps) {
|
|
|
241
252
|
}),
|
|
242
253
|
factory_list_attention: createTool({
|
|
243
254
|
id: "factory_list_attention",
|
|
244
|
-
description: "What in this Factory needs a person: failed decisions grouped by failure code and error (one incident per group), proposals waiting for approval, and
|
|
255
|
+
description: "What in this Factory needs a person: failed decisions grouped by failure code and error (one incident per group), proposals waiting for approval, and Work cards triage left in Intake for a person to move on.",
|
|
245
256
|
inputSchema: z.object({ limit: z.number().int().min(1).max(50).optional() }).strict(),
|
|
246
257
|
execute: async ({ limit = DEFAULT_LIST }) => {
|
|
247
258
|
const [decisions, items] = await Promise.all([deps.workItems.listDeferredDecisions(scope.orgId, scope.factoryProjectId, { statuses: ["failed", "proposed"] }), deps.workItems.list(project)]);
|
|
@@ -295,7 +306,6 @@ function createFactoryReadTools(scope, deps) {
|
|
|
295
306
|
})),
|
|
296
307
|
held: held.slice(0, limit).map((item) => ({
|
|
297
308
|
...ref(item.id),
|
|
298
|
-
triageType: item.triageType,
|
|
299
309
|
stage: workItemStage(item)
|
|
300
310
|
})),
|
|
301
311
|
truncated: allIncidents.length > limit || incidents.some((group) => group.shown.length < group.decisions.length) || proposals.length > limit || held.length > limit
|