@mastra/factory 0.28.0-alpha.5 → 0.28.0-alpha.7
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 +52 -28
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +5 -5
- package/dist/auth.js.map +1 -1
- package/dist/boards/board-writes.d.ts +1 -1
- package/dist/boards/board-writes.d.ts.map +1 -1
- package/dist/boards/board-writes.js +7 -8
- package/dist/boards/board-writes.js.map +1 -1
- package/dist/boards/index.d.ts +1 -1
- package/dist/boards/index.d.ts.map +1 -1
- package/dist/boards/index.js +2 -2
- package/dist/boards/project-boards.d.ts +30 -4
- package/dist/boards/project-boards.d.ts.map +1 -1
- package/dist/boards/project-boards.js +71 -19
- package/dist/boards/project-boards.js.map +1 -1
- package/dist/boards/registry.d.ts +7 -1
- package/dist/boards/registry.d.ts.map +1 -1
- package/dist/boards/registry.js +16 -3
- package/dist/boards/registry.js.map +1 -1
- package/dist/boards/semantics.d.ts +5 -4
- package/dist/boards/semantics.d.ts.map +1 -1
- package/dist/boards/semantics.js +5 -4
- package/dist/boards/semantics.js.map +1 -1
- package/dist/boards/work-migrations.d.ts +4 -3
- package/dist/boards/work-migrations.d.ts.map +1 -1
- package/dist/boards/work-migrations.js +6 -5
- package/dist/boards/work-migrations.js.map +1 -1
- package/dist/boards/work-seeds.d.ts +9 -0
- package/dist/boards/work-seeds.d.ts.map +1 -0
- package/dist/boards/work-seeds.js +56 -0
- package/dist/boards/work-seeds.js.map +1 -0
- package/dist/boards/work.d.ts +2 -2
- package/dist/boards/work.d.ts.map +1 -1
- package/dist/boards/work.js +0 -16
- package/dist/boards/work.js.map +1 -1
- package/dist/environment/build-runner.d.ts.map +1 -1
- package/dist/environment/build-runner.js +2 -2
- package/dist/environment/build-runner.js.map +1 -1
- package/dist/environment/build-workflow.d.ts.map +1 -1
- package/dist/environment/build-workflow.js +6 -5
- package/dist/environment/build-workflow.js.map +1 -1
- package/dist/environment/build.d.ts +15 -2
- package/dist/environment/build.d.ts.map +1 -1
- package/dist/environment/build.js +32 -9
- package/dist/environment/build.js.map +1 -1
- package/dist/factory.d.ts +8 -4
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +57 -59
- package/dist/factory.js.map +1 -1
- package/dist/feed-events.d.ts +2 -3
- package/dist/feed-events.d.ts.map +1 -1
- package/dist/feed-events.js +4 -5
- package/dist/feed-events.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/integrations/base.d.ts +0 -11
- package/dist/integrations/base.d.ts.map +1 -1
- package/dist/integrations/github/integration.d.ts.map +1 -1
- package/dist/integrations/github/integration.js +7 -3
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/issue-reconciler.js +2 -2
- package/dist/integrations/github/issue-reconciler.js.map +1 -1
- package/dist/integrations/github/provenance.js +1 -1
- package/dist/integrations/github/provenance.js.map +1 -1
- package/dist/integrations/github/reconcile-worker.d.ts +5 -1
- package/dist/integrations/github/reconcile-worker.d.ts.map +1 -1
- package/dist/integrations/github/reconcile-worker.js +39 -6
- package/dist/integrations/github/reconcile-worker.js.map +1 -1
- package/dist/integrations/github/routes.d.ts +4 -3
- package/dist/integrations/github/routes.d.ts.map +1 -1
- package/dist/integrations/github/routes.js +9 -86
- package/dist/integrations/github/routes.js.map +1 -1
- package/dist/integrations/github/rules.d.ts +67 -0
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +215 -12
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts +10 -2
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +20 -4
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/gitlab/merge-request-reconciler.js +1 -1
- 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 +6 -5
- 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 +5 -2
- package/dist/integrations/incidentio/rules.js.map +1 -1
- package/dist/integrations/issue-reconciler.js +1 -1
- 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 +5 -2
- package/dist/integrations/jira/rules.js.map +1 -1
- package/dist/integrations/linear/agent-tools.d.ts.map +1 -1
- package/dist/integrations/linear/agent-tools.js +1 -1
- package/dist/integrations/linear/agent-tools.js.map +1 -1
- package/dist/integrations/linear/rules.d.ts.map +1 -1
- package/dist/integrations/linear/rules.js +2 -2
- package/dist/integrations/linear/rules.js.map +1 -1
- package/dist/integrations/platform/github/event-worker.d.ts +4 -1
- package/dist/integrations/platform/github/event-worker.d.ts.map +1 -1
- package/dist/integrations/platform/github/event-worker.js +39 -3
- package/dist/integrations/platform/github/event-worker.js.map +1 -1
- package/dist/integrations/platform/github/integration.d.ts +8 -0
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +21 -3
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/platform/linear/event-worker.d.ts +1 -1
- package/dist/integrations/platform/linear/event-worker.d.ts.map +1 -1
- package/dist/integrations/platform/linear/event-worker.js +1 -1
- package/dist/integrations/platform/linear/event-worker.js.map +1 -1
- package/dist/integrations/slack/integration.d.ts +0 -2
- package/dist/integrations/slack/integration.d.ts.map +1 -1
- package/dist/integrations/slack/integration.js +0 -5
- package/dist/integrations/slack/integration.js.map +1 -1
- package/dist/integrations/slack/slack.d.ts +3 -18
- package/dist/integrations/slack/slack.d.ts.map +1 -1
- package/dist/integrations/slack/slack.js +3 -74
- package/dist/integrations/slack/slack.js.map +1 -1
- package/dist/links.d.ts +1 -2
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +1 -2
- package/dist/links.js.map +1 -1
- package/dist/mcp/routes.js +1 -1
- package/dist/mcp/routes.js.map +1 -1
- package/dist/routes/attention-parked.js +1 -1
- package/dist/routes/attention-parked.js.map +1 -1
- package/dist/routes/attention-providers.d.ts +0 -25
- package/dist/routes/attention-providers.d.ts.map +1 -1
- package/dist/routes/attention-providers.js +2 -150
- package/dist/routes/attention-providers.js.map +1 -1
- package/dist/routes/attention.d.ts +0 -2
- package/dist/routes/attention.d.ts.map +1 -1
- package/dist/routes/attention.js +2 -13
- package/dist/routes/attention.js.map +1 -1
- package/dist/routes/boards.d.ts +1 -1
- package/dist/routes/boards.d.ts.map +1 -1
- package/dist/routes/boards.js.map +1 -1
- package/dist/routes/contracts.d.ts +121 -14
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +73 -3
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/feed-events.d.ts +15 -0
- package/dist/routes/feed-events.d.ts.map +1 -0
- package/dist/routes/feed-events.js +68 -0
- package/dist/routes/feed-events.js.map +1 -0
- package/dist/routes/knowledge.js +1 -1
- package/dist/routes/projects.d.ts +1 -1
- package/dist/routes/projects.d.ts.map +1 -1
- package/dist/routes/projects.js +13 -7
- package/dist/routes/projects.js.map +1 -1
- package/dist/routes/sandbox-envs.d.ts +26 -0
- package/dist/routes/sandbox-envs.d.ts.map +1 -0
- package/dist/routes/sandbox-envs.js +180 -0
- package/dist/routes/sandbox-envs.js.map +1 -0
- package/dist/routes/surface.d.ts +0 -7
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +1 -5
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/work-items.d.ts +0 -3
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +1 -2
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/dispatcher.d.ts +0 -3
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +8 -9
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/sandbox/sandbox-env-cache.d.ts +33 -0
- package/dist/sandbox/sandbox-env-cache.d.ts.map +1 -0
- package/dist/sandbox/sandbox-env-cache.js +140 -0
- package/dist/sandbox/sandbox-env-cache.js.map +1 -0
- package/dist/sandbox/sandbox-env.d.ts +77 -0
- package/dist/sandbox/sandbox-env.d.ts.map +1 -0
- package/dist/sandbox/sandbox-env.js +130 -0
- package/dist/sandbox/sandbox-env.js.map +1 -0
- package/dist/storage/domains/audit/actions.d.ts +2 -1
- package/dist/storage/domains/audit/actions.d.ts.map +1 -1
- package/dist/storage/domains/audit/actions.js +5 -4
- package/dist/storage/domains/audit/actions.js.map +1 -1
- package/dist/storage/domains/boards/base.d.ts +15 -1
- package/dist/storage/domains/boards/base.d.ts.map +1 -1
- package/dist/storage/domains/boards/base.js +21 -5
- package/dist/storage/domains/boards/base.js.map +1 -1
- package/dist/storage/domains/channel-identity/base.d.ts +0 -4
- package/dist/storage/domains/channel-identity/base.d.ts.map +1 -1
- package/dist/storage/domains/channel-identity/base.js +0 -7
- package/dist/storage/domains/channel-identity/base.js.map +1 -1
- package/dist/storage/domains/sandbox-envs/base.d.ts +70 -0
- package/dist/storage/domains/sandbox-envs/base.d.ts.map +1 -0
- package/dist/storage/domains/sandbox-envs/base.js +227 -0
- package/dist/storage/domains/sandbox-envs/base.js.map +1 -0
- package/dist/storage/domains/work-items/base.d.ts +8 -9
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +20 -86
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/storage/domains/work-items/cards.d.ts +3 -3
- package/dist/storage/domains/work-items/cards.d.ts.map +1 -1
- package/dist/storage/domains/work-items/cards.js +10 -10
- package/dist/storage/domains/work-items/cards.js.map +1 -1
- package/dist/storage/domains/work-items/metrics.d.ts +1 -1
- 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 +1 -2
- package/dist/storage/domains/work-items/work-item-schema.d.ts.map +1 -1
- package/dist/storage/domains/work-items/work-item-schema.js +8 -8
- package/dist/storage/domains/work-items/work-item-schema.js.map +1 -1
- package/dist/tools/read-tools.d.ts +0 -2
- package/dist/tools/read-tools.d.ts.map +1 -1
- package/dist/tools/read-tools.js +3 -14
- package/dist/tools/read-tools.js.map +1 -1
- package/dist/tools/work-item-tools.d.ts +0 -3
- package/dist/tools/work-item-tools.d.ts.map +1 -1
- package/dist/tools/work-item-tools.js +8 -18
- package/dist/tools/work-item-tools.js.map +1 -1
- package/dist/work-items/create-work-item.d.ts.map +1 -1
- package/dist/work-items/create-work-item.js +3 -2
- package/dist/work-items/create-work-item.js.map +1 -1
- package/dist/work-items/description-context.d.ts +5 -0
- package/dist/work-items/description-context.d.ts.map +1 -0
- package/dist/work-items/description-context.js +17 -0
- package/dist/work-items/description-context.js.map +1 -0
- package/dist/work-items/split-migration.d.ts.map +1 -1
- package/dist/work-items/split-migration.js +1 -6
- package/dist/work-items/split-migration.js.map +1 -1
- package/dist/workspace.d.ts +3 -0
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +21 -4
- package/dist/workspace.js.map +1 -1
- package/factory-skills/configure-factory-rules/SKILL.md +3 -3
- package/factory-skills/factory-rereview/SKILL.md +2 -2
- package/factory-skills/factory-review/SKILL.md +2 -2
- package/factory-skills/factory-triage/SKILL.md +3 -2
- package/package.json +7 -7
- package/dist/integrations/slack/emoji-shortcodes.generated.d.ts +0 -8
- package/dist/integrations/slack/emoji-shortcodes.generated.d.ts.map +0 -1
- package/dist/integrations/slack/emoji-shortcodes.generated.js +0 -1984
- package/dist/integrations/slack/emoji-shortcodes.generated.js.map +0 -1
- package/dist/integrations/slack/emoji.d.ts +0 -3
- package/dist/integrations/slack/emoji.d.ts.map +0 -1
- package/dist/integrations/slack/emoji.js +0 -11
- package/dist/integrations/slack/emoji.js.map +0 -1
- package/dist/integrations/slack/feed-publisher.d.ts +0 -26
- package/dist/integrations/slack/feed-publisher.d.ts.map +0 -1
- package/dist/integrations/slack/feed-publisher.js +0 -43
- package/dist/integrations/slack/feed-publisher.js.map +0 -1
- package/dist/routes/attention-activity.d.ts +0 -23
- package/dist/routes/attention-activity.d.ts.map +0 -1
- package/dist/routes/attention-activity.js +0 -154
- package/dist/routes/attention-activity.js.map +0 -1
- package/dist/storage/domains/comments/activity.d.ts +0 -40
- package/dist/storage/domains/comments/activity.d.ts.map +0 -1
- package/dist/storage/domains/comments/activity.js +0 -93
- package/dist/storage/domains/comments/activity.js.map +0 -1
- package/dist/storage/domains/comments/actor.d.ts +0 -51
- package/dist/storage/domains/comments/actor.d.ts.map +0 -1
- package/dist/storage/domains/comments/actor.js +0 -37
- package/dist/storage/domains/comments/actor.js.map +0 -1
- package/dist/storage/domains/comments/base.d.ts +0 -245
- package/dist/storage/domains/comments/base.d.ts.map +0 -1
- package/dist/storage/domains/comments/base.js +0 -539
- package/dist/storage/domains/comments/base.js.map +0 -1
- package/dist/storage/domains/comments/domain.d.ts +0 -135
- package/dist/storage/domains/comments/domain.d.ts.map +0 -1
- package/dist/storage/domains/comments/domain.js +0 -284
- package/dist/storage/domains/comments/domain.js.map +0 -1
- package/dist/storage/domains/comments/feed-context.d.ts +0 -22
- package/dist/storage/domains/comments/feed-context.d.ts.map +0 -1
- package/dist/storage/domains/comments/feed-context.js +0 -88
- package/dist/storage/domains/comments/feed-context.js.map +0 -1
- package/dist/storage/domains/comments/feed-sync.d.ts +0 -21
- package/dist/storage/domains/comments/feed-sync.d.ts.map +0 -1
- package/dist/storage/domains/comments/feed-sync.js +0 -1
- package/dist/storage/domains/comments/parse.d.ts +0 -23
- package/dist/storage/domains/comments/parse.d.ts.map +0 -1
- package/dist/storage/domains/comments/parse.js +0 -89
- package/dist/storage/domains/comments/parse.js.map +0 -1
- package/dist/storage/domains/comments/routes.d.ts +0 -24
- package/dist/storage/domains/comments/routes.d.ts.map +0 -1
- package/dist/storage/domains/comments/routes.js +0 -301
- package/dist/storage/domains/comments/routes.js.map +0 -1
- package/dist/storage/domains/comments/schema.d.ts +0 -5
- package/dist/storage/domains/comments/schema.d.ts.map +0 -1
- package/dist/storage/domains/comments/schema.js +0 -178
- package/dist/storage/domains/comments/schema.js.map +0 -1
- package/dist/storage/domains/comments/wire.d.ts +0 -40
- package/dist/storage/domains/comments/wire.d.ts.map +0 -1
- package/dist/storage/domains/comments/wire.js +0 -36
- package/dist/storage/domains/comments/wire.js.map +0 -1
|
@@ -6,7 +6,9 @@ import type { WorkItemDbRecord, WorkItemSourceDbRecord } from './work-item-schem
|
|
|
6
6
|
export interface LegacyCardCopier {
|
|
7
7
|
copy(rows: readonly WorkItemDbRow[]): Promise<void>;
|
|
8
8
|
}
|
|
9
|
-
export type CardInsert = Pick<WorkItemDbRow, 'org_id' | 'factory_project_id' | 'board' | 'external_source' | 'source_key' | 'parent_work_item_id' | 'title' | 'stages' | 'stage_history' | 'sessions' | 'metadata' | 'revision' | 'created_by' | 'created_at' | 'updated_at'
|
|
9
|
+
export type CardInsert = Pick<WorkItemDbRow, 'org_id' | 'factory_project_id' | 'board' | 'external_source' | 'source_key' | 'parent_work_item_id' | 'title' | 'stages' | 'stage_history' | 'sessions' | 'metadata' | 'revision' | 'created_by' | 'created_at' | 'updated_at'> & {
|
|
10
|
+
description?: string | null;
|
|
11
|
+
};
|
|
10
12
|
export declare function splitCardRows(card: WorkItemDbRow, options: {
|
|
11
13
|
workItemId: string;
|
|
12
14
|
revision?: number;
|
|
@@ -29,8 +31,6 @@ export declare function splitCardRows(card: WorkItemDbRow, options: {
|
|
|
29
31
|
stage_history: unknown[];
|
|
30
32
|
sessions: Record<string, unknown>;
|
|
31
33
|
metadata: Record<string, unknown> | null;
|
|
32
|
-
comment_count: number;
|
|
33
|
-
feed_activity_at: Date | null;
|
|
34
34
|
revision: number;
|
|
35
35
|
created_by: string;
|
|
36
36
|
created_at: Date;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cards.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/work-items/cards.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGtG,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AASvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAS3D,OAAO,KAAK,EAAqB,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"cards.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/work-items/cards.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAGtG,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AASvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAS3D,OAAO,KAAK,EAAqB,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAkBzG,0GAA0G;AAC1G,MAAM,WAAW,gBAAgB;IAC/B,IAAI,CAAC,IAAI,EAAE,SAAS,aAAa,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrD;AAED,MAAM,MAAM,UAAU,GAAG,IAAI,CAC3B,aAAa,EACX,QAAQ,GACR,oBAAoB,GACpB,OAAO,GACP,iBAAiB,GACjB,YAAY,GACZ,qBAAqB,GACrB,OAAO,GACP,QAAQ,GACR,eAAe,GACf,UAAU,GACV,UAAU,GACV,UAAU,GACV,YAAY,GACZ,YAAY,GACZ,YAAY,CACf,GAAG;IAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAEpC,wBAAgB,aAAa,CAAC,IAAI,EAAE,aAAa,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,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;QAAC,GAAG,EAAE,IAAI,CAAA;KAAE,EACxG,gBAAgB,CAAC,EAAE,MAAM,GACxB,OAAO,CAAC;QAAE,GAAG,EAAE,aAAa,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAC;QAAC,eAAe,CAAC,EAAE,MAAM,CAAC;QAAC,gBAAgB,CAAC,EAAE,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC,CAkD9G;IAEK,UAAU,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAKvF;IAEK,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAkCxD;CACF"}
|
|
@@ -13,8 +13,7 @@ const PROJECTED_COLUMNS = /* @__PURE__ */ new Set([
|
|
|
13
13
|
"external_source",
|
|
14
14
|
"source_key",
|
|
15
15
|
"title",
|
|
16
|
-
"
|
|
17
|
-
"feed_activity_at"
|
|
16
|
+
"description"
|
|
18
17
|
]);
|
|
19
18
|
const ID_BATCH = 500;
|
|
20
19
|
const LEGACY = WORK_ITEMS_SCHEMA.name;
|
|
@@ -69,6 +68,7 @@ function joinCard(board, work, sources, reviewInUse = false) {
|
|
|
69
68
|
claim_key: null,
|
|
70
69
|
parent_work_item_id: board.parent_board_item_id,
|
|
71
70
|
title: work.title,
|
|
71
|
+
description: work.description ?? null,
|
|
72
72
|
stages: board.stages,
|
|
73
73
|
stage_history: board.stage_history,
|
|
74
74
|
sessions: board.sessions,
|
|
@@ -80,8 +80,6 @@ function joinCard(board, work, sources, reviewInUse = false) {
|
|
|
80
80
|
autonomy_armed_at: board.autonomy_armed_at ?? null,
|
|
81
81
|
plans_preapproved_at: board.plans_preapproved_at ?? null,
|
|
82
82
|
accepted_at: board.accepted_at ?? null,
|
|
83
|
-
comment_count: board.comment_count ?? 0,
|
|
84
|
-
feed_activity_at: board.feed_activity_at ?? null,
|
|
85
83
|
revision: board.revision,
|
|
86
84
|
created_by: board.created_by,
|
|
87
85
|
created_at: board.created_at,
|
|
@@ -234,8 +232,7 @@ var Cards = class {
|
|
|
234
232
|
autonomy_armed_at: null,
|
|
235
233
|
plans_preapproved_at: null,
|
|
236
234
|
accepted_at: null,
|
|
237
|
-
|
|
238
|
-
feed_activity_at: null,
|
|
235
|
+
description: null,
|
|
239
236
|
...card,
|
|
240
237
|
id: randomUUID()
|
|
241
238
|
}, { workItemId: randomUUID() });
|
|
@@ -270,8 +267,11 @@ var Cards = class {
|
|
|
270
267
|
...current,
|
|
271
268
|
...patch
|
|
272
269
|
}, { workItemId: row.work_item_id }).boardItem.metadata;
|
|
273
|
-
|
|
274
|
-
|
|
270
|
+
const titleChanged = patch.title !== void 0 && patch.title !== current.title;
|
|
271
|
+
const descriptionChanged = patch.description !== void 0 && patch.description !== current.description;
|
|
272
|
+
if (titleChanged || descriptionChanged) await this.ops.updateAtomic(WORK_ITEMS, { id: row.work_item_id }, (work) => ({
|
|
273
|
+
...titleChanged ? { title: patch.title } : {},
|
|
274
|
+
...descriptionChanged ? { description: patch.description } : {},
|
|
275
275
|
revision: work.revision + 1,
|
|
276
276
|
updated_at: /* @__PURE__ */ new Date()
|
|
277
277
|
}));
|
|
@@ -308,8 +308,8 @@ var Cards = class {
|
|
|
308
308
|
} else if (next) await this.ops.insertOne(SOURCES, next);
|
|
309
309
|
else if (previous) await this.ops.deleteMany(SOURCES, { id: previous.id });
|
|
310
310
|
}
|
|
311
|
-
const nativeTitleChanged = !current.external_source &&
|
|
312
|
-
if (!(nativeTitleChanged || Object.entries(columns).some(([key, value]) => !["revision", "updated_at"].includes(key) && JSON.stringify(row[key]) !== JSON.stringify(value)))) {
|
|
311
|
+
const nativeTitleChanged = !current.external_source && titleChanged;
|
|
312
|
+
if (!(nativeTitleChanged || descriptionChanged || Object.entries(columns).some(([key, value]) => !["revision", "updated_at"].includes(key) && JSON.stringify(row[key]) !== JSON.stringify(value)))) {
|
|
313
313
|
if (!touch) return null;
|
|
314
314
|
return { updated_at: new Date(Math.max(Date.now(), new Date(row.updated_at).getTime() + 1)) };
|
|
315
315
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cards.js","names":[],"sources":["../../../../src/storage/domains/work-items/cards.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport type { CollectionListOptions, CollectionWhere, FactoryStorageOps } from '@mastra/core/storage';\n\nimport { splitLegacyWorkItem } from '../../../work-items/split-migration.js';\nimport type { ExternalWorkItemSource, WorkItemDbRow } from './base.js';\nimport {\n isLegacyReviewPlacement,\n LEGACY_REVIEW_BOARD,\n normalizeLegacyReviewColumns,\n readLegacyReviewRow,\n readReviewBoardInUse,\n widenLegacyReviewBoardFilter,\n} from './legacy-review.js';\nimport type { ReviewBoardInUse } from './legacy-review.js';\nimport {\n FACTORY_BOARD_ITEMS_SCHEMA,\n FACTORY_WORK_ITEMS_SCHEMA,\n FACTORY_WORK_ITEM_SOURCES_SCHEMA,\n FACTORY_WORK_ITEM_SPLIT_LOCKS_SCHEMA,\n FACTORY_BOARD_ITEM_TOMBSTONES_SCHEMA,\n WORK_ITEMS_SCHEMA,\n} from './work-item-schema.js';\nimport type { BoardItemDbRecord, WorkItemDbRecord, WorkItemSourceDbRecord } from './work-item-schema.js';\n\nconst BOARD_ITEMS = FACTORY_BOARD_ITEMS_SCHEMA.name;\nconst WORK_ITEMS = FACTORY_WORK_ITEMS_SCHEMA.name;\nconst SOURCES = FACTORY_WORK_ITEM_SOURCES_SCHEMA.name;\nconst BOARD_COLUMNS = new Set(Object.keys(FACTORY_BOARD_ITEMS_SCHEMA.columns));\nconst PROJECTED_COLUMNS = new Set([\n 'work_item',\n 'work_item_sources',\n 'external_source',\n 'source_key',\n 'title',\n 'comment_count',\n 'feed_activity_at',\n]);\nconst ID_BATCH = 500;\nconst LEGACY = WORK_ITEMS_SCHEMA.name;\nconst LEGACY_KEYS = ['id', 'org_id', 'factory_project_id', 'source_key'] as const;\n\n/** Copies legacy cards that have no split rows yet; only supplied while the split backfill is pending. */\nexport interface LegacyCardCopier {\n copy(rows: readonly WorkItemDbRow[]): Promise<void>;\n}\n\nexport type CardInsert = Pick<\n WorkItemDbRow,\n | 'org_id'\n | 'factory_project_id'\n | 'board'\n | 'external_source'\n | 'source_key'\n | 'parent_work_item_id'\n | 'title'\n | 'stages'\n | 'stage_history'\n | 'sessions'\n | 'metadata'\n | 'revision'\n | 'created_by'\n | 'created_at'\n | 'updated_at'\n>;\n\nexport function splitCardRows(card: WorkItemDbRow, options: { workItemId: string; revision?: number }) {\n const rows = splitLegacyWorkItem(card, options);\n return { ...rows, boardItem: { ...rows.boardItem, migrated_from_updated_at: null, migrated_from_hash: null } };\n}\n\nfunction externalSourceOf(source: WorkItemSourceDbRecord | undefined): ExternalWorkItemSource | null {\n if (!source) return null;\n const prefix = `${source.source_type}:${source.workspace_id ? `${source.workspace_id}:` : ''}`;\n return {\n integrationId: source.integration_id,\n type: source.source_type,\n ...(source.workspace_id ? { workspaceId: source.workspace_id } : {}),\n externalId: source.external_id.startsWith(prefix) ? source.external_id.slice(prefix.length) : source.external_id,\n ...(source.url ? { url: source.url } : {}),\n };\n}\n\n/** A source row written before `role` existed is its work item's only source, so it is the origin. */\nfunction isOriginSource(source: WorkItemSourceDbRecord): boolean {\n return source.role !== 'attached';\n}\n\n/** The origin source first, then attached ones, each keeping the order they were read in. */\nfunction originFirst(sources: WorkItemSourceDbRecord[]): WorkItemSourceDbRecord[] {\n return [...sources.filter(isOriginSource), ...sources.filter(source => !isOriginSource(source))];\n}\n\nfunction joinCard(\n board: BoardItemDbRecord,\n work: WorkItemDbRecord | null,\n sources: WorkItemSourceDbRecord[],\n reviewInUse = false,\n): WorkItemDbRow {\n if (!work) throw new Error(`Board item ${board.id} has no work item ${board.work_item_id}.`);\n const source = sources.find(isOriginSource) ?? sources[0];\n return readLegacyReviewRow(\n {\n work_item: work,\n work_item_sources: sources,\n id: board.id,\n org_id: board.org_id,\n factory_project_id: board.factory_project_id,\n board: board.board,\n external_source: externalSourceOf(source),\n source_key: source?.source_key ?? null,\n claim_key: null,\n parent_work_item_id: board.parent_board_item_id,\n title: work.title,\n stages: board.stages,\n stage_history: board.stage_history as WorkItemDbRow['stage_history'],\n sessions: board.sessions as WorkItemDbRow['sessions'],\n metadata: board.metadata || source?.metadata ? { ...board.metadata, ...source?.metadata } : null,\n triage_type: board.triage_type ?? null,\n autonomy_armed_at: board.autonomy_armed_at ?? null,\n plans_preapproved_at: board.plans_preapproved_at ?? null,\n accepted_at: board.accepted_at ?? null,\n comment_count: board.comment_count ?? 0,\n feed_activity_at: board.feed_activity_at ?? null,\n revision: board.revision,\n created_by: board.created_by,\n created_at: board.created_at,\n updated_at: board.updated_at,\n },\n reviewInUse,\n );\n}\n\n/** A board filter that leaves Review out: a widened query's rows a project keeping Review holds there. */\nfunction excludesReview(filter: unknown): boolean {\n if (filter === LEGACY_REVIEW_BOARD) return false;\n if (filter && typeof filter === 'object' && 'in' in filter && Array.isArray(filter.in)) {\n return !filter.in.includes(LEGACY_REVIEW_BOARD);\n }\n return true;\n}\n\nfunction boardColumns(patch: Partial<WorkItemDbRow>, { filter = false } = {}): Partial<BoardItemDbRecord> {\n const columns: Record<string, unknown> = {};\n for (const [column, value] of Object.entries(patch)) {\n if ((column === 'id' && !filter) || column === 'claim_key' || PROJECTED_COLUMNS.has(column)) continue;\n if (column === 'parent_work_item_id') columns.parent_board_item_id = value;\n else if (BOARD_COLUMNS.has(column)) columns[column] = value;\n else throw new Error(`[cards] unknown card column '${column}'.`);\n }\n return columns as Partial<BoardItemDbRecord>;\n}\n\n/** Compatibility row operations over work, source and placement tables. Writes require transaction ops. */\nexport class Cards {\n constructor(\n private readonly ops: FactoryStorageOps,\n private readonly legacyMode = false,\n private readonly copier?: LegacyCardCopier,\n private readonly reviewInUse: ReviewBoardInUse = readReviewBoardInUse,\n ) {}\n\n readonly #reviewInUse = new Map<string, Promise<boolean>>();\n\n /** The projects among `boards` that still use the Review board, asked once per project per operation. */\n async #projectsUsingReview(boards: readonly BoardItemDbRecord[]): Promise<Set<string>> {\n const using = new Set<string>();\n for (const board of boards) {\n if (board.board !== LEGACY_REVIEW_BOARD) continue;\n const key = `${board.org_id}\\0${board.factory_project_id}`;\n let inUse = this.#reviewInUse.get(key);\n if (!inUse) {\n inUse = this.reviewInUse(this.ops, { orgId: board.org_id, factoryProjectId: board.factory_project_id });\n this.#reviewInUse.set(key, inUse);\n }\n if (await inUse) using.add(key);\n }\n return using;\n }\n\n /**\n * Copies the legacy cards a lookup by id or source addresses that have no split rows and no\n * tombstone. Returns whether it tried, so the caller re-reads the split tables.\n */\n async #copyLegacy(where: CollectionWhere): Promise<boolean> {\n if (!this.copier || (where.id === undefined && where.source_key === undefined)) return false;\n const legacyWhere: CollectionWhere = {};\n for (const key of LEGACY_KEYS) if (where[key] !== undefined) legacyWhere[key] = where[key];\n const rows = await this.ops.findMany<WorkItemDbRow>(LEGACY, legacyWhere);\n if (!rows.length) return false;\n const ids = { in: rows.map(row => row.id) };\n const done = new Set(\n [\n ...(await this.ops.findMany<{ id: string }>(BOARD_ITEMS, { id: ids })),\n ...(await this.ops.findMany<{ id: string }>(FACTORY_BOARD_ITEM_TOMBSTONES_SCHEMA.name, { id: ids })),\n ].map(row => row.id),\n );\n const missing = rows.filter(row => !done.has(row.id));\n if (!missing.length) return false;\n await this.copier.copy(missing);\n return true;\n }\n\n /** Single-card writes copy first only when the split tables miss the card. */\n async #copyLegacyOnMiss(where: CollectionWhere): Promise<void> {\n if (!this.copier) return;\n const boardWhere = await this.#where(where);\n if (boardWhere && (await this.ops.findOne(BOARD_ITEMS, boardWhere))) return;\n await this.#copyLegacy(where);\n }\n\n async #where(where: CollectionWhere): Promise<CollectionWhere | null> {\n const { source_key: sourceKey, ...rest } = where;\n const boardWhere = boardColumns(rest as Partial<WorkItemDbRow>, { filter: true }) as CollectionWhere;\n if (boardWhere.board !== undefined) boardWhere.board = widenLegacyReviewBoardFilter(boardWhere.board) as never;\n if (sourceKey === undefined) return boardWhere;\n const scope: CollectionWhere = {};\n if (rest.org_id !== undefined) scope.org_id = rest.org_id;\n if (rest.factory_project_id !== undefined) scope.factory_project_id = rest.factory_project_id;\n const sources = await this.ops.findMany<WorkItemSourceDbRecord>(SOURCES, { ...scope, source_key: sourceKey });\n return sources.length ? { ...boardWhere, work_item_id: { in: sources.map(source => source.work_item_id) } } : null;\n }\n\n async #join(boards: readonly BoardItemDbRecord[]): Promise<WorkItemDbRow[]> {\n const ids = [...new Set(boards.map(board => board.work_item_id))];\n const items = new Map<string, WorkItemDbRecord>();\n const sources = new Map<string, WorkItemSourceDbRecord[]>();\n for (let index = 0; index < ids.length; index += ID_BATCH) {\n const pageIds = ids.slice(index, index + ID_BATCH);\n const page = await this.ops.findMany<WorkItemDbRecord>(WORK_ITEMS, { id: { in: pageIds } });\n for (const item of page) items.set(item.id, item);\n const sourcePage = await this.ops.findMany<WorkItemSourceDbRecord>(\n SOURCES,\n { work_item_id: { in: pageIds } },\n {\n orderBy: [\n ['created_at', 'asc'],\n ['id', 'asc'],\n ],\n },\n );\n for (const source of sourcePage) {\n const group = sources.get(source.work_item_id) ?? [];\n group.push(source);\n sources.set(source.work_item_id, group);\n }\n }\n const deletedMidRead = await this.#deletedBoardIds(boards.filter(board => !items.has(board.work_item_id)));\n const usingReview = await this.#projectsUsingReview(boards);\n return boards\n .filter(board => !deletedMidRead.has(board.id))\n .map(board =>\n joinCard(\n board,\n items.get(board.work_item_id) ?? null,\n originFirst(sources.get(board.work_item_id) ?? []),\n usingReview.has(`${board.org_id}\\0${board.factory_project_id}`),\n ),\n );\n }\n\n async #deletedBoardIds(boards: readonly BoardItemDbRecord[]): Promise<Set<string>> {\n const deleted = new Set(boards.map(board => board.id));\n const ids = [...deleted];\n for (let index = 0; index < ids.length; index += ID_BATCH) {\n const page = await this.ops.findMany<BoardItemDbRecord>(BOARD_ITEMS, {\n id: { in: ids.slice(index, index + ID_BATCH) },\n });\n for (const board of page) deleted.delete(board.id);\n }\n return deleted;\n }\n\n async findOne(where: CollectionWhere): Promise<WorkItemDbRow | null> {\n if (this.legacyMode) return this.ops.findOne(WORK_ITEMS_SCHEMA.name, where);\n const found = await this.#findOne(where);\n return found || !(await this.#copyLegacy(where)) ? found : this.#findOne(where);\n }\n\n async #findOne(where: CollectionWhere): Promise<WorkItemDbRow | null> {\n const boardWhere = await this.#where(where);\n if (!boardWhere) return null;\n if (where.board !== undefined && excludesReview(where.board)) {\n // The widened filter may match a row its project keeps on Review; only another row answers.\n return (await this.#findMany(where, boardWhere))[0] ?? null;\n }\n const board = await this.ops.findOne<BoardItemDbRecord>(BOARD_ITEMS, boardWhere);\n return board ? ((await this.#join([board]))[0] ?? null) : null;\n }\n\n async #findMany(\n where: CollectionWhere,\n boardWhere: CollectionWhere,\n options?: CollectionListOptions,\n ): Promise<WorkItemDbRow[]> {\n const rows = await this.#join(await this.ops.findMany<BoardItemDbRecord>(BOARD_ITEMS, boardWhere, options));\n // A filter that leaves Review out was widened to find redundant Review rows read as Work;\n // rows a project keeps on Review still read as Review, so they don't match it.\n return where.board !== undefined && excludesReview(where.board)\n ? rows.filter(row => row.board !== LEGACY_REVIEW_BOARD)\n : rows;\n }\n\n async findMany(where: CollectionWhere, options?: CollectionListOptions): Promise<WorkItemDbRow[]> {\n if (this.legacyMode) return this.ops.findMany(WORK_ITEMS_SCHEMA.name, where, options);\n // A split hit does not prove every match is copied (a source spans projects), so check first.\n await this.#copyLegacy(where);\n const boardWhere = await this.#where(where);\n return boardWhere ? this.#findMany(where, boardWhere, options) : [];\n }\n\n async insertOne(card: CardInsert): Promise<WorkItemDbRow> {\n if (this.legacyMode) return this.ops.insertOne<WorkItemDbRow>(WORK_ITEMS_SCHEMA.name, card);\n const rows = splitCardRows(\n {\n claim_key: null,\n triage_type: null,\n autonomy_armed_at: null,\n plans_preapproved_at: null,\n accepted_at: null,\n comment_count: 0,\n feed_activity_at: null,\n ...card,\n id: randomUUID(),\n },\n { workItemId: randomUUID() },\n );\n const work = await this.ops.insertOne<WorkItemDbRecord>(WORK_ITEMS, rows.workItem);\n if (rows.source) await this.ops.insertOne(SOURCES, rows.source);\n const board = await this.ops.insertOne<BoardItemDbRecord>(BOARD_ITEMS, rows.boardItem);\n const reviewInUse = (await this.#projectsUsingReview([board])).size > 0;\n return joinCard(board, work, rows.source ? [rows.source] : [], reviewInUse);\n }\n\n async updateAtomic(\n where: CollectionWhere,\n updater: (card: WorkItemDbRow) => Partial<WorkItemDbRow> | null | Promise<Partial<WorkItemDbRow> | null>,\n /**\n * Moves the board item's `updated_at` forward even when only work or source facts changed,\n * without bumping its revision, so a revision-and-time guarded delete sees the write.\n */\n { touch = false }: { touch?: boolean } = {},\n ): Promise<WorkItemDbRow | null> {\n if (this.legacyMode) return this.ops.updateAtomic(WORK_ITEMS_SCHEMA.name, where, updater);\n await this.#copyLegacyOnMiss(where);\n const boardWhere = await this.#where(where);\n if (!boardWhere) return null;\n const board = await this.ops.updateAtomic<BoardItemDbRecord>(BOARD_ITEMS, boardWhere, async row => {\n const joined = (await this.#join([row]))[0]!;\n const matchedSource = joined.work_item_sources?.find(source => source.source_key === where.source_key);\n const current = matchedSource\n ? {\n ...joined,\n external_source: externalSourceOf(matchedSource),\n source_key: matchedSource.source_key,\n metadata: row.metadata || matchedSource.metadata ? { ...row.metadata, ...matchedSource.metadata } : null,\n work_item_sources: [\n matchedSource,\n ...joined.work_item_sources!.filter(source => source.id !== matchedSource.id),\n ],\n }\n : joined;\n const patch = await updater(current);\n if (!patch) return null;\n const columns = boardColumns(patch);\n if (patch.metadata !== undefined) {\n const next = { ...current, ...patch };\n const split = splitCardRows(next, { workItemId: row.work_item_id });\n columns.metadata = split.boardItem.metadata;\n }\n if (patch.title !== undefined && patch.title !== current.title) {\n await this.ops.updateAtomic<WorkItemDbRecord>(WORK_ITEMS, { id: row.work_item_id }, work => ({\n title: patch.title,\n revision: work.revision + 1,\n updated_at: new Date(),\n }));\n }\n if (patch.metadata !== undefined || patch.external_source !== undefined) {\n const next = splitCardRows({ ...current, ...patch }, { workItemId: row.work_item_id }).source;\n const previous = current.work_item_sources?.[0];\n if (next && previous) {\n const before = splitCardRows(current, { workItemId: row.work_item_id }).source;\n const changed = Object.fromEntries(\n Object.entries(next).filter(\n ([key, value]) =>\n !['id', 'revision', 'created_at', 'updated_at', 'synced_at'].includes(key) &&\n JSON.stringify(before?.[key]) !== JSON.stringify(value),\n ),\n );\n if (Object.keys(changed).length)\n await this.ops.updateAtomic<WorkItemSourceDbRecord>(SOURCES, { id: previous.id }, source => {\n const metadata = { ...source.metadata };\n if ('metadata' in changed && next.metadata !== null) {\n for (const key of new Set([...Object.keys(before?.metadata ?? {}), ...Object.keys(next.metadata)])) {\n if (JSON.stringify(before?.metadata?.[key]) === JSON.stringify(next.metadata[key])) continue;\n if (Object.hasOwn(next.metadata, key)) metadata[key] = next.metadata[key];\n else delete metadata[key];\n }\n }\n return {\n ...changed,\n ...('metadata' in changed ? { metadata: next.metadata === null ? null : metadata } : {}),\n revision: source.revision + 1,\n updated_at: new Date(),\n synced_at: new Date(),\n };\n });\n } else if (next) await this.ops.insertOne(SOURCES, next);\n else if (previous) await this.ops.deleteMany(SOURCES, { id: previous.id });\n }\n const nativeTitleChanged = !current.external_source && patch.title !== undefined && patch.title !== current.title;\n const boardChanged =\n nativeTitleChanged ||\n Object.entries(columns).some(\n ([key, value]) =>\n !['revision', 'updated_at'].includes(key) && JSON.stringify(row[key]) !== JSON.stringify(value),\n );\n if (!boardChanged) {\n if (!touch) return null;\n return { updated_at: new Date(Math.max(Date.now(), new Date(row.updated_at).getTime() + 1)) };\n }\n // A legacy Review row read as Work stores its Work placement on its first real write.\n if (\n isLegacyReviewPlacement(row.board, joined.work_item_sources?.[0]?.source_type) &&\n joined.board !== LEGACY_REVIEW_BOARD\n ) {\n Object.assign(columns, normalizeLegacyReviewColumns(row, columns));\n }\n return {\n ...columns,\n ...(nativeTitleChanged\n ? { revision: patch.revision ?? row.revision + 1, updated_at: patch.updated_at ?? new Date() }\n : {}),\n };\n });\n return board ? ((await this.#join([board]))[0] ?? null) : null;\n }\n\n /**\n * Add one more source to an existing card's work item. The new source is stored\n * as `attached`, so it sorts after the card's origin source and never becomes the\n * card's primary source, whatever its timestamp. Only\n * the source's provider facts are stored; Factory-owned keys in `metadata`\n * (trust stamps, process state) belong to the card and are ignored here.\n */\n async attachSource(\n where: { org_id: string; id: string },\n source: { external_source: ExternalWorkItemSource; metadata: Record<string, unknown> | null; now: Date },\n expectedRevision?: number,\n ): Promise<{ row: WorkItemDbRow; attached: boolean; ownerWorkItemId?: string; revisionConflict?: true } | null> {\n if (this.legacyMode) throw new Error('[cards] attaching a source needs the split work item tables.');\n const board = await this.ops.findOne<BoardItemDbRecord>(BOARD_ITEMS, where);\n if (!board) return null;\n const [joined] = await this.#join([board]);\n if (!joined) return null;\n const next = splitCardRows(\n { ...joined, external_source: source.external_source, metadata: source.metadata },\n { workItemId: board.work_item_id },\n ).source;\n if (!next) throw new Error('[cards] an attached source must carry provider facts.');\n const existing = await this.ops.findOne<WorkItemSourceDbRecord>(SOURCES, {\n org_id: board.org_id,\n factory_project_id: board.factory_project_id,\n provider: next.provider,\n external_id: next.external_id,\n });\n if (existing) {\n return existing.work_item_id === board.work_item_id\n ? { row: joined, attached: false }\n : { row: joined, attached: false, ownerWorkItemId: existing.work_item_id };\n }\n // Bump the card first: the row lock makes a concurrent attach against the same revision\n // wait, then see the new revision and stop.\n let stale = false;\n const bumped = await this.ops.updateAtomic<BoardItemDbRecord>(BOARD_ITEMS, { id: board.id }, row => {\n if (expectedRevision !== undefined && row.revision !== expectedRevision) {\n stale = true;\n return null;\n }\n return {\n revision: row.revision + 1,\n updated_at: source.now,\n ...(isLegacyReviewPlacement(row.board, joined.work_item_sources?.[0]?.source_type) &&\n joined.board !== LEGACY_REVIEW_BOARD\n ? normalizeLegacyReviewColumns(row, {})\n : {}),\n };\n });\n if (!bumped || stale) return { row: joined, attached: false, revisionConflict: true };\n await this.ops.insertOne<WorkItemSourceDbRecord>(SOURCES, {\n ...next,\n id: randomUUID(),\n role: 'attached',\n created_at: source.now,\n updated_at: source.now,\n synced_at: source.now,\n });\n const [attached] = await this.#join([bumped]);\n return attached ? { row: attached, attached: true } : null;\n }\n\n async updateMany(where: CollectionWhere, patch: Partial<WorkItemDbRow>): Promise<number> {\n if (this.legacyMode) return this.ops.updateMany(WORK_ITEMS_SCHEMA.name, where, patch);\n const boards = await this.findMany(where);\n for (const board of boards) await this.updateAtomic({ id: board.id }, () => patch);\n return boards.length;\n }\n\n async deleteMany(where: CollectionWhere): Promise<number> {\n if (this.legacyMode) return this.ops.deleteMany(WORK_ITEMS_SCHEMA.name, where);\n // Copy first so the delete tombstones the card; otherwise the backfill would bring it back.\n await this.#copyLegacy(where);\n const boardWhere = await this.#where(where);\n if (!boardWhere) return 0;\n const boards = await this.ops.findMany<BoardItemDbRecord>(BOARD_ITEMS, boardWhere, { orderBy: [['id', 'asc']] });\n let deleted = 0;\n for (const board of boards) {\n const scope = { org_id: board.org_id, factory_project_id: board.factory_project_id };\n const guard = await this.ops.updateAtomic(\n FACTORY_WORK_ITEM_SPLIT_LOCKS_SCHEMA.name,\n { id: board.id },\n () => null,\n );\n if (!guard) await this.ops.insertOne(FACTORY_WORK_ITEM_SPLIT_LOCKS_SCHEMA.name, { ...scope, id: board.id });\n // Re-check the whole filter under the row lock, so a write that landed since the read\n // above (e.g. a bumped revision) keeps the row.\n const locked = await this.ops.updateAtomic(BOARD_ITEMS, { ...boardWhere, ...scope, id: board.id }, () => null);\n if (!locked) continue;\n deleted++;\n await this.ops.updateAtomic(WORK_ITEMS, { ...scope, id: board.work_item_id }, () => null);\n const sources = await this.ops.findMany<WorkItemSourceDbRecord>(\n SOURCES,\n { ...scope, work_item_id: board.work_item_id },\n { orderBy: [['id', 'asc']] },\n );\n for (const source of sources) await this.ops.updateAtomic(SOURCES, { id: source.id }, () => null);\n await this.ops.deleteMany(SOURCES, { ...scope, work_item_id: board.work_item_id });\n await this.ops.deleteMany(BOARD_ITEMS, { ...scope, id: board.id });\n await this.ops.deleteMany(WORK_ITEMS, { ...scope, id: board.work_item_id });\n await this.ops.upsertOne(FACTORY_BOARD_ITEM_TOMBSTONES_SCHEMA.name, ['id'], { ...scope, id: board.id });\n }\n return deleted;\n }\n}\n"],"mappings":";;;;;AAyBA,MAAM,cAAc,2BAA2B;AAC/C,MAAM,aAAa,0BAA0B;AAC7C,MAAM,UAAU,iCAAiC;AACjD,MAAM,gBAAgB,IAAI,IAAI,OAAO,KAAK,2BAA2B,OAAO,CAAC;AAC7E,MAAM,oCAAoB,IAAI,IAAI;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AACD,MAAM,WAAW;AACjB,MAAM,SAAS,kBAAkB;AACjC,MAAM,cAAc;CAAC;CAAM;CAAU;CAAsB;AAAY;AA0BvE,SAAgB,cAAc,MAAqB,SAAoD;CACrG,MAAM,OAAO,oBAAoB,MAAM,OAAO;CAC9C,OAAO;EAAE,GAAG;EAAM,WAAW;GAAE,GAAG,KAAK;GAAW,0BAA0B;GAAM,oBAAoB;EAAK;CAAE;AAC/G;AAEA,SAAS,iBAAiB,QAA2E;CACnG,IAAI,CAAC,QAAQ,OAAO;CACpB,MAAM,SAAS,GAAG,OAAO,YAAY,GAAG,OAAO,eAAe,GAAG,OAAO,aAAa,KAAK;CAC1F,OAAO;EACL,eAAe,OAAO;EACtB,MAAM,OAAO;EACb,GAAI,OAAO,eAAe,EAAE,aAAa,OAAO,aAAa,IAAI,CAAC;EAClE,YAAY,OAAO,YAAY,WAAW,MAAM,IAAI,OAAO,YAAY,MAAM,OAAO,MAAM,IAAI,OAAO;EACrG,GAAI,OAAO,MAAM,EAAE,KAAK,OAAO,IAAI,IAAI,CAAC;CAC1C;AACF;;AAGA,SAAS,eAAe,QAAyC;CAC/D,OAAO,OAAO,SAAS;AACzB;;AAGA,SAAS,YAAY,SAA6D;CAChF,OA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AK,MAAM,SAAS,QAAQ;GAC1B,MAAM,QAAQ;IAAE,QAAQ,MAAM;IAAQ,oBAAoB,MAAM;GAAmB;GAMnF,IAAI,CAAC,MALe,KAAK,IAAI,aAC3B,qCAAqC,MACrC,EAAE,IAAI,MAAM,GAAG,SACT,IACR,GACY,MAAM,KAAK,IAAI,UAAU,qCAAqC,MAAM;IAAE,GAAG;IAAO,IAAI,MAAM;GAAG,CAAC;GAI1G,IAAI,CAAC,MADgB,KAAK,IAAI,aAAa,aAAa;IAAE,GAAG;IAAY,GAAG;IAAO,IAAI,MAAM;GAAG,SAAS,IAAI,GAChG;GACb;GACA,MAAM,KAAK,IAAI,aAAa,YAAY;IAAE,GAAG;IAAO,IAAI,MAAM;GAAa,SAAS,IAAI;GACxF,MAAM,UAAU,MAAM,KAAK,IAAI,SAC7B,SACA;IAAE,GAAG;IAAO,cAAc,MAAM;GAAa,GAC7C,EAAE,SAAS,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAC7B;GACA,KAAK,MAAM,UAAU,SAAS,MAAM,KAAK,IAAI,aAAa,SAAS,EAAE,IAAI,OAAO,GAAG,SAAS,IAAI;GAChG,MAAM,KAAK,IAAI,WAAW,SAAS;IAAE,GAAG;IAAO,cAAc,MAAM;GAAa,CAAC;GACjF,MAAM,KAAK,IAAI,WAAW,aAAa;IAAE,GAAG;IAAO,IAAI,MAAM;GAAG,CAAC;GACjE,MAAM,KAAK,IAAI,WAAW,YAAY;IAAE,GAAG;IAAO,IAAI,MAAM;GAAa,CAAC;GAC1E,MAAM,KAAK,IAAI,UAAU,qCAAqC,MAAM,CAAC,IAAI,GAAG;IAAE,GAAG;IAAO,IAAI,MAAM;GAAG,CAAC;EACxG;EACA,OAAO;CACT;AACF"}
|
|
1
|
+
{"version":3,"file":"cards.js","names":[],"sources":["../../../../src/storage/domains/work-items/cards.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\n\nimport type { CollectionListOptions, CollectionWhere, FactoryStorageOps } from '@mastra/core/storage';\n\nimport { splitLegacyWorkItem } from '../../../work-items/split-migration.js';\nimport type { ExternalWorkItemSource, WorkItemDbRow } from './base.js';\nimport {\n isLegacyReviewPlacement,\n LEGACY_REVIEW_BOARD,\n normalizeLegacyReviewColumns,\n readLegacyReviewRow,\n readReviewBoardInUse,\n widenLegacyReviewBoardFilter,\n} from './legacy-review.js';\nimport type { ReviewBoardInUse } from './legacy-review.js';\nimport {\n FACTORY_BOARD_ITEMS_SCHEMA,\n FACTORY_WORK_ITEMS_SCHEMA,\n FACTORY_WORK_ITEM_SOURCES_SCHEMA,\n FACTORY_WORK_ITEM_SPLIT_LOCKS_SCHEMA,\n FACTORY_BOARD_ITEM_TOMBSTONES_SCHEMA,\n WORK_ITEMS_SCHEMA,\n} from './work-item-schema.js';\nimport type { BoardItemDbRecord, WorkItemDbRecord, WorkItemSourceDbRecord } from './work-item-schema.js';\n\nconst BOARD_ITEMS = FACTORY_BOARD_ITEMS_SCHEMA.name;\nconst WORK_ITEMS = FACTORY_WORK_ITEMS_SCHEMA.name;\nconst SOURCES = FACTORY_WORK_ITEM_SOURCES_SCHEMA.name;\nconst BOARD_COLUMNS = new Set(Object.keys(FACTORY_BOARD_ITEMS_SCHEMA.columns));\nconst PROJECTED_COLUMNS = new Set([\n 'work_item',\n 'work_item_sources',\n 'external_source',\n 'source_key',\n 'title',\n 'description',\n]);\nconst ID_BATCH = 500;\nconst LEGACY = WORK_ITEMS_SCHEMA.name;\nconst LEGACY_KEYS = ['id', 'org_id', 'factory_project_id', 'source_key'] as const;\n\n/** Copies legacy cards that have no split rows yet; only supplied while the split backfill is pending. */\nexport interface LegacyCardCopier {\n copy(rows: readonly WorkItemDbRow[]): Promise<void>;\n}\n\nexport type CardInsert = Pick<\n WorkItemDbRow,\n | 'org_id'\n | 'factory_project_id'\n | 'board'\n | 'external_source'\n | 'source_key'\n | 'parent_work_item_id'\n | 'title'\n | 'stages'\n | 'stage_history'\n | 'sessions'\n | 'metadata'\n | 'revision'\n | 'created_by'\n | 'created_at'\n | 'updated_at'\n> & { description?: string | null };\n\nexport function splitCardRows(card: WorkItemDbRow, options: { workItemId: string; revision?: number }) {\n const rows = splitLegacyWorkItem(card, options);\n return { ...rows, boardItem: { ...rows.boardItem, migrated_from_updated_at: null, migrated_from_hash: null } };\n}\n\nfunction externalSourceOf(source: WorkItemSourceDbRecord | undefined): ExternalWorkItemSource | null {\n if (!source) return null;\n const prefix = `${source.source_type}:${source.workspace_id ? `${source.workspace_id}:` : ''}`;\n return {\n integrationId: source.integration_id,\n type: source.source_type,\n ...(source.workspace_id ? { workspaceId: source.workspace_id } : {}),\n externalId: source.external_id.startsWith(prefix) ? source.external_id.slice(prefix.length) : source.external_id,\n ...(source.url ? { url: source.url } : {}),\n };\n}\n\n/** A source row written before `role` existed is its work item's only source, so it is the origin. */\nfunction isOriginSource(source: WorkItemSourceDbRecord): boolean {\n return source.role !== 'attached';\n}\n\n/** The origin source first, then attached ones, each keeping the order they were read in. */\nfunction originFirst(sources: WorkItemSourceDbRecord[]): WorkItemSourceDbRecord[] {\n return [...sources.filter(isOriginSource), ...sources.filter(source => !isOriginSource(source))];\n}\n\nfunction joinCard(\n board: BoardItemDbRecord,\n work: WorkItemDbRecord | null,\n sources: WorkItemSourceDbRecord[],\n reviewInUse = false,\n): WorkItemDbRow {\n if (!work) throw new Error(`Board item ${board.id} has no work item ${board.work_item_id}.`);\n const source = sources.find(isOriginSource) ?? sources[0];\n return readLegacyReviewRow(\n {\n work_item: work,\n work_item_sources: sources,\n id: board.id,\n org_id: board.org_id,\n factory_project_id: board.factory_project_id,\n board: board.board,\n external_source: externalSourceOf(source),\n source_key: source?.source_key ?? null,\n claim_key: null,\n parent_work_item_id: board.parent_board_item_id,\n title: work.title,\n description: work.description ?? null,\n stages: board.stages,\n stage_history: board.stage_history as WorkItemDbRow['stage_history'],\n sessions: board.sessions as WorkItemDbRow['sessions'],\n metadata: board.metadata || source?.metadata ? { ...board.metadata, ...source?.metadata } : null,\n triage_type: board.triage_type ?? null,\n autonomy_armed_at: board.autonomy_armed_at ?? null,\n plans_preapproved_at: board.plans_preapproved_at ?? null,\n accepted_at: board.accepted_at ?? null,\n revision: board.revision,\n created_by: board.created_by,\n created_at: board.created_at,\n updated_at: board.updated_at,\n },\n reviewInUse,\n );\n}\n\n/** A board filter that leaves Review out: a widened query's rows a project keeping Review holds there. */\nfunction excludesReview(filter: unknown): boolean {\n if (filter === LEGACY_REVIEW_BOARD) return false;\n if (filter && typeof filter === 'object' && 'in' in filter && Array.isArray(filter.in)) {\n return !filter.in.includes(LEGACY_REVIEW_BOARD);\n }\n return true;\n}\n\nfunction boardColumns(patch: Partial<WorkItemDbRow>, { filter = false } = {}): Partial<BoardItemDbRecord> {\n const columns: Record<string, unknown> = {};\n for (const [column, value] of Object.entries(patch)) {\n if ((column === 'id' && !filter) || column === 'claim_key' || PROJECTED_COLUMNS.has(column)) continue;\n if (column === 'parent_work_item_id') columns.parent_board_item_id = value;\n else if (BOARD_COLUMNS.has(column)) columns[column] = value;\n else throw new Error(`[cards] unknown card column '${column}'.`);\n }\n return columns as Partial<BoardItemDbRecord>;\n}\n\n/** Compatibility row operations over work, source and placement tables. Writes require transaction ops. */\nexport class Cards {\n constructor(\n private readonly ops: FactoryStorageOps,\n private readonly legacyMode = false,\n private readonly copier?: LegacyCardCopier,\n private readonly reviewInUse: ReviewBoardInUse = readReviewBoardInUse,\n ) {}\n\n readonly #reviewInUse = new Map<string, Promise<boolean>>();\n\n /** The projects among `boards` that still use the Review board, asked once per project per operation. */\n async #projectsUsingReview(boards: readonly BoardItemDbRecord[]): Promise<Set<string>> {\n const using = new Set<string>();\n for (const board of boards) {\n if (board.board !== LEGACY_REVIEW_BOARD) continue;\n const key = `${board.org_id}\\0${board.factory_project_id}`;\n let inUse = this.#reviewInUse.get(key);\n if (!inUse) {\n inUse = this.reviewInUse(this.ops, { orgId: board.org_id, factoryProjectId: board.factory_project_id });\n this.#reviewInUse.set(key, inUse);\n }\n if (await inUse) using.add(key);\n }\n return using;\n }\n\n /**\n * Copies the legacy cards a lookup by id or source addresses that have no split rows and no\n * tombstone. Returns whether it tried, so the caller re-reads the split tables.\n */\n async #copyLegacy(where: CollectionWhere): Promise<boolean> {\n if (!this.copier || (where.id === undefined && where.source_key === undefined)) return false;\n const legacyWhere: CollectionWhere = {};\n for (const key of LEGACY_KEYS) if (where[key] !== undefined) legacyWhere[key] = where[key];\n const rows = await this.ops.findMany<WorkItemDbRow>(LEGACY, legacyWhere);\n if (!rows.length) return false;\n const ids = { in: rows.map(row => row.id) };\n const done = new Set(\n [\n ...(await this.ops.findMany<{ id: string }>(BOARD_ITEMS, { id: ids })),\n ...(await this.ops.findMany<{ id: string }>(FACTORY_BOARD_ITEM_TOMBSTONES_SCHEMA.name, { id: ids })),\n ].map(row => row.id),\n );\n const missing = rows.filter(row => !done.has(row.id));\n if (!missing.length) return false;\n await this.copier.copy(missing);\n return true;\n }\n\n /** Single-card writes copy first only when the split tables miss the card. */\n async #copyLegacyOnMiss(where: CollectionWhere): Promise<void> {\n if (!this.copier) return;\n const boardWhere = await this.#where(where);\n if (boardWhere && (await this.ops.findOne(BOARD_ITEMS, boardWhere))) return;\n await this.#copyLegacy(where);\n }\n\n async #where(where: CollectionWhere): Promise<CollectionWhere | null> {\n const { source_key: sourceKey, ...rest } = where;\n const boardWhere = boardColumns(rest as Partial<WorkItemDbRow>, { filter: true }) as CollectionWhere;\n if (boardWhere.board !== undefined) boardWhere.board = widenLegacyReviewBoardFilter(boardWhere.board) as never;\n if (sourceKey === undefined) return boardWhere;\n const scope: CollectionWhere = {};\n if (rest.org_id !== undefined) scope.org_id = rest.org_id;\n if (rest.factory_project_id !== undefined) scope.factory_project_id = rest.factory_project_id;\n const sources = await this.ops.findMany<WorkItemSourceDbRecord>(SOURCES, { ...scope, source_key: sourceKey });\n return sources.length ? { ...boardWhere, work_item_id: { in: sources.map(source => source.work_item_id) } } : null;\n }\n\n async #join(boards: readonly BoardItemDbRecord[]): Promise<WorkItemDbRow[]> {\n const ids = [...new Set(boards.map(board => board.work_item_id))];\n const items = new Map<string, WorkItemDbRecord>();\n const sources = new Map<string, WorkItemSourceDbRecord[]>();\n for (let index = 0; index < ids.length; index += ID_BATCH) {\n const pageIds = ids.slice(index, index + ID_BATCH);\n const page = await this.ops.findMany<WorkItemDbRecord>(WORK_ITEMS, { id: { in: pageIds } });\n for (const item of page) items.set(item.id, item);\n const sourcePage = await this.ops.findMany<WorkItemSourceDbRecord>(\n SOURCES,\n { work_item_id: { in: pageIds } },\n {\n orderBy: [\n ['created_at', 'asc'],\n ['id', 'asc'],\n ],\n },\n );\n for (const source of sourcePage) {\n const group = sources.get(source.work_item_id) ?? [];\n group.push(source);\n sources.set(source.work_item_id, group);\n }\n }\n const deletedMidRead = await this.#deletedBoardIds(boards.filter(board => !items.has(board.work_item_id)));\n const usingReview = await this.#projectsUsingReview(boards);\n return boards\n .filter(board => !deletedMidRead.has(board.id))\n .map(board =>\n joinCard(\n board,\n items.get(board.work_item_id) ?? null,\n originFirst(sources.get(board.work_item_id) ?? []),\n usingReview.has(`${board.org_id}\\0${board.factory_project_id}`),\n ),\n );\n }\n\n async #deletedBoardIds(boards: readonly BoardItemDbRecord[]): Promise<Set<string>> {\n const deleted = new Set(boards.map(board => board.id));\n const ids = [...deleted];\n for (let index = 0; index < ids.length; index += ID_BATCH) {\n const page = await this.ops.findMany<BoardItemDbRecord>(BOARD_ITEMS, {\n id: { in: ids.slice(index, index + ID_BATCH) },\n });\n for (const board of page) deleted.delete(board.id);\n }\n return deleted;\n }\n\n async findOne(where: CollectionWhere): Promise<WorkItemDbRow | null> {\n if (this.legacyMode) return this.ops.findOne(WORK_ITEMS_SCHEMA.name, where);\n const found = await this.#findOne(where);\n return found || !(await this.#copyLegacy(where)) ? found : this.#findOne(where);\n }\n\n async #findOne(where: CollectionWhere): Promise<WorkItemDbRow | null> {\n const boardWhere = await this.#where(where);\n if (!boardWhere) return null;\n if (where.board !== undefined && excludesReview(where.board)) {\n // The widened filter may match a row its project keeps on Review; only another row answers.\n return (await this.#findMany(where, boardWhere))[0] ?? null;\n }\n const board = await this.ops.findOne<BoardItemDbRecord>(BOARD_ITEMS, boardWhere);\n return board ? ((await this.#join([board]))[0] ?? null) : null;\n }\n\n async #findMany(\n where: CollectionWhere,\n boardWhere: CollectionWhere,\n options?: CollectionListOptions,\n ): Promise<WorkItemDbRow[]> {\n const rows = await this.#join(await this.ops.findMany<BoardItemDbRecord>(BOARD_ITEMS, boardWhere, options));\n // A filter that leaves Review out was widened to find redundant Review rows read as Work;\n // rows a project keeps on Review still read as Review, so they don't match it.\n return where.board !== undefined && excludesReview(where.board)\n ? rows.filter(row => row.board !== LEGACY_REVIEW_BOARD)\n : rows;\n }\n\n async findMany(where: CollectionWhere, options?: CollectionListOptions): Promise<WorkItemDbRow[]> {\n if (this.legacyMode) return this.ops.findMany(WORK_ITEMS_SCHEMA.name, where, options);\n // A split hit does not prove every match is copied (a source spans projects), so check first.\n await this.#copyLegacy(where);\n const boardWhere = await this.#where(where);\n return boardWhere ? this.#findMany(where, boardWhere, options) : [];\n }\n\n async insertOne(card: CardInsert): Promise<WorkItemDbRow> {\n if (this.legacyMode) return this.ops.insertOne<WorkItemDbRow>(WORK_ITEMS_SCHEMA.name, card);\n const rows = splitCardRows(\n {\n claim_key: null,\n triage_type: null,\n autonomy_armed_at: null,\n plans_preapproved_at: null,\n accepted_at: null,\n description: null,\n ...card,\n id: randomUUID(),\n },\n { workItemId: randomUUID() },\n );\n const work = await this.ops.insertOne<WorkItemDbRecord>(WORK_ITEMS, rows.workItem);\n if (rows.source) await this.ops.insertOne(SOURCES, rows.source);\n const board = await this.ops.insertOne<BoardItemDbRecord>(BOARD_ITEMS, rows.boardItem);\n const reviewInUse = (await this.#projectsUsingReview([board])).size > 0;\n return joinCard(board, work, rows.source ? [rows.source] : [], reviewInUse);\n }\n\n async updateAtomic(\n where: CollectionWhere,\n updater: (card: WorkItemDbRow) => Partial<WorkItemDbRow> | null | Promise<Partial<WorkItemDbRow> | null>,\n /**\n * Moves the board item's `updated_at` forward even when only work or source facts changed,\n * without bumping its revision, so a revision-and-time guarded delete sees the write.\n */\n { touch = false }: { touch?: boolean } = {},\n ): Promise<WorkItemDbRow | null> {\n if (this.legacyMode) return this.ops.updateAtomic(WORK_ITEMS_SCHEMA.name, where, updater);\n await this.#copyLegacyOnMiss(where);\n const boardWhere = await this.#where(where);\n if (!boardWhere) return null;\n const board = await this.ops.updateAtomic<BoardItemDbRecord>(BOARD_ITEMS, boardWhere, async row => {\n const joined = (await this.#join([row]))[0]!;\n const matchedSource = joined.work_item_sources?.find(source => source.source_key === where.source_key);\n const current = matchedSource\n ? {\n ...joined,\n external_source: externalSourceOf(matchedSource),\n source_key: matchedSource.source_key,\n metadata: row.metadata || matchedSource.metadata ? { ...row.metadata, ...matchedSource.metadata } : null,\n work_item_sources: [\n matchedSource,\n ...joined.work_item_sources!.filter(source => source.id !== matchedSource.id),\n ],\n }\n : joined;\n const patch = await updater(current);\n if (!patch) return null;\n const columns = boardColumns(patch);\n if (patch.metadata !== undefined) {\n const next = { ...current, ...patch };\n const split = splitCardRows(next, { workItemId: row.work_item_id });\n columns.metadata = split.boardItem.metadata;\n }\n const titleChanged = patch.title !== undefined && patch.title !== current.title;\n const descriptionChanged = patch.description !== undefined && patch.description !== current.description;\n if (titleChanged || descriptionChanged) {\n await this.ops.updateAtomic<WorkItemDbRecord>(WORK_ITEMS, { id: row.work_item_id }, work => ({\n ...(titleChanged ? { title: patch.title } : {}),\n ...(descriptionChanged ? { description: patch.description } : {}),\n revision: work.revision + 1,\n updated_at: new Date(),\n }));\n }\n if (patch.metadata !== undefined || patch.external_source !== undefined) {\n const next = splitCardRows({ ...current, ...patch }, { workItemId: row.work_item_id }).source;\n const previous = current.work_item_sources?.[0];\n if (next && previous) {\n const before = splitCardRows(current, { workItemId: row.work_item_id }).source;\n const changed = Object.fromEntries(\n Object.entries(next).filter(\n ([key, value]) =>\n !['id', 'revision', 'created_at', 'updated_at', 'synced_at'].includes(key) &&\n JSON.stringify(before?.[key]) !== JSON.stringify(value),\n ),\n );\n if (Object.keys(changed).length)\n await this.ops.updateAtomic<WorkItemSourceDbRecord>(SOURCES, { id: previous.id }, source => {\n const metadata = { ...source.metadata };\n if ('metadata' in changed && next.metadata !== null) {\n for (const key of new Set([...Object.keys(before?.metadata ?? {}), ...Object.keys(next.metadata)])) {\n if (JSON.stringify(before?.metadata?.[key]) === JSON.stringify(next.metadata[key])) continue;\n if (Object.hasOwn(next.metadata, key)) metadata[key] = next.metadata[key];\n else delete metadata[key];\n }\n }\n return {\n ...changed,\n ...('metadata' in changed ? { metadata: next.metadata === null ? null : metadata } : {}),\n revision: source.revision + 1,\n updated_at: new Date(),\n synced_at: new Date(),\n };\n });\n } else if (next) await this.ops.insertOne(SOURCES, next);\n else if (previous) await this.ops.deleteMany(SOURCES, { id: previous.id });\n }\n const nativeTitleChanged = !current.external_source && titleChanged;\n const boardChanged =\n nativeTitleChanged ||\n descriptionChanged ||\n Object.entries(columns).some(\n ([key, value]) =>\n !['revision', 'updated_at'].includes(key) && JSON.stringify(row[key]) !== JSON.stringify(value),\n );\n if (!boardChanged) {\n if (!touch) return null;\n return { updated_at: new Date(Math.max(Date.now(), new Date(row.updated_at).getTime() + 1)) };\n }\n // A legacy Review row read as Work stores its Work placement on its first real write.\n if (\n isLegacyReviewPlacement(row.board, joined.work_item_sources?.[0]?.source_type) &&\n joined.board !== LEGACY_REVIEW_BOARD\n ) {\n Object.assign(columns, normalizeLegacyReviewColumns(row, columns));\n }\n return {\n ...columns,\n ...(nativeTitleChanged\n ? { revision: patch.revision ?? row.revision + 1, updated_at: patch.updated_at ?? new Date() }\n : {}),\n };\n });\n return board ? ((await this.#join([board]))[0] ?? null) : null;\n }\n\n /**\n * Add one more source to an existing card's work item. The new source is stored\n * as `attached`, so it sorts after the card's origin source and never becomes the\n * card's primary source, whatever its timestamp. Only\n * the source's provider facts are stored; Factory-owned keys in `metadata`\n * (trust stamps, process state) belong to the card and are ignored here.\n */\n async attachSource(\n where: { org_id: string; id: string },\n source: { external_source: ExternalWorkItemSource; metadata: Record<string, unknown> | null; now: Date },\n expectedRevision?: number,\n ): Promise<{ row: WorkItemDbRow; attached: boolean; ownerWorkItemId?: string; revisionConflict?: true } | null> {\n if (this.legacyMode) throw new Error('[cards] attaching a source needs the split work item tables.');\n const board = await this.ops.findOne<BoardItemDbRecord>(BOARD_ITEMS, where);\n if (!board) return null;\n const [joined] = await this.#join([board]);\n if (!joined) return null;\n const next = splitCardRows(\n { ...joined, external_source: source.external_source, metadata: source.metadata },\n { workItemId: board.work_item_id },\n ).source;\n if (!next) throw new Error('[cards] an attached source must carry provider facts.');\n const existing = await this.ops.findOne<WorkItemSourceDbRecord>(SOURCES, {\n org_id: board.org_id,\n factory_project_id: board.factory_project_id,\n provider: next.provider,\n external_id: next.external_id,\n });\n if (existing) {\n return existing.work_item_id === board.work_item_id\n ? { row: joined, attached: false }\n : { row: joined, attached: false, ownerWorkItemId: existing.work_item_id };\n }\n // Bump the card first: the row lock makes a concurrent attach against the same revision\n // wait, then see the new revision and stop.\n let stale = false;\n const bumped = await this.ops.updateAtomic<BoardItemDbRecord>(BOARD_ITEMS, { id: board.id }, row => {\n if (expectedRevision !== undefined && row.revision !== expectedRevision) {\n stale = true;\n return null;\n }\n return {\n revision: row.revision + 1,\n updated_at: source.now,\n ...(isLegacyReviewPlacement(row.board, joined.work_item_sources?.[0]?.source_type) &&\n joined.board !== LEGACY_REVIEW_BOARD\n ? normalizeLegacyReviewColumns(row, {})\n : {}),\n };\n });\n if (!bumped || stale) return { row: joined, attached: false, revisionConflict: true };\n await this.ops.insertOne<WorkItemSourceDbRecord>(SOURCES, {\n ...next,\n id: randomUUID(),\n role: 'attached',\n created_at: source.now,\n updated_at: source.now,\n synced_at: source.now,\n });\n const [attached] = await this.#join([bumped]);\n return attached ? { row: attached, attached: true } : null;\n }\n\n async updateMany(where: CollectionWhere, patch: Partial<WorkItemDbRow>): Promise<number> {\n if (this.legacyMode) return this.ops.updateMany(WORK_ITEMS_SCHEMA.name, where, patch);\n const boards = await this.findMany(where);\n for (const board of boards) await this.updateAtomic({ id: board.id }, () => patch);\n return boards.length;\n }\n\n async deleteMany(where: CollectionWhere): Promise<number> {\n if (this.legacyMode) return this.ops.deleteMany(WORK_ITEMS_SCHEMA.name, where);\n // Copy first so the delete tombstones the card; otherwise the backfill would bring it back.\n await this.#copyLegacy(where);\n const boardWhere = await this.#where(where);\n if (!boardWhere) return 0;\n const boards = await this.ops.findMany<BoardItemDbRecord>(BOARD_ITEMS, boardWhere, { orderBy: [['id', 'asc']] });\n let deleted = 0;\n for (const board of boards) {\n const scope = { org_id: board.org_id, factory_project_id: board.factory_project_id };\n const guard = await this.ops.updateAtomic(\n FACTORY_WORK_ITEM_SPLIT_LOCKS_SCHEMA.name,\n { id: board.id },\n () => null,\n );\n if (!guard) await this.ops.insertOne(FACTORY_WORK_ITEM_SPLIT_LOCKS_SCHEMA.name, { ...scope, id: board.id });\n // Re-check the whole filter under the row lock, so a write that landed since the read\n // above (e.g. a bumped revision) keeps the row.\n const locked = await this.ops.updateAtomic(BOARD_ITEMS, { ...boardWhere, ...scope, id: board.id }, () => null);\n if (!locked) continue;\n deleted++;\n await this.ops.updateAtomic(WORK_ITEMS, { ...scope, id: board.work_item_id }, () => null);\n const sources = await this.ops.findMany<WorkItemSourceDbRecord>(\n SOURCES,\n { ...scope, work_item_id: board.work_item_id },\n { orderBy: [['id', 'asc']] },\n );\n for (const source of sources) await this.ops.updateAtomic(SOURCES, { id: source.id }, () => null);\n await this.ops.deleteMany(SOURCES, { ...scope, work_item_id: board.work_item_id });\n await this.ops.deleteMany(BOARD_ITEMS, { ...scope, id: board.id });\n await this.ops.deleteMany(WORK_ITEMS, { ...scope, id: board.work_item_id });\n await this.ops.upsertOne(FACTORY_BOARD_ITEM_TOMBSTONES_SCHEMA.name, ['id'], { ...scope, id: board.id });\n }\n return deleted;\n }\n}\n"],"mappings":";;;;;AA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AAqC,MACrC,EAAE,IAAI,MAAM,GAAG,SACT,IACR,GACY,MAAM,KAAK,IAAI,UAAU,qCAAqC,MAAM;IAAE,GAAG;IAAO,IAAI,MAAM;GAAG,CAAC;GAI1G,IAAI,CAAC,MADgB,KAAK,IAAI,aAAa,aAAa;IAAE,GAAG;IAAY,GAAG;IAAO,IAAI,MAAM;GAAG,SAAS,IAAI,GAChG;GACb;GACA,MAAM,KAAK,IAAI,aAAa,YAAY;IAAE,GAAG;IAAO,IAAI,MAAM;GAAa,SAAS,IAAI;GACxF,MAAM,UAAU,MAAM,KAAK,IAAI,SAC7B,SACA;IAAE,GAAG;IAAO,cAAc,MAAM;GAAa,GAC7C,EAAE,SAAS,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAC7B;GACA,KAAK,MAAM,UAAU,SAAS,MAAM,KAAK,IAAI,aAAa,SAAS,EAAE,IAAI,OAAO,GAAG,SAAS,IAAI;GAChG,MAAM,KAAK,IAAI,WAAW,SAAS;IAAE,GAAG;IAAO,cAAc,MAAM;GAAa,CAAC;GACjF,MAAM,KAAK,IAAI,WAAW,aAAa;IAAE,GAAG;IAAO,IAAI,MAAM;GAAG,CAAC;GACjE,MAAM,KAAK,IAAI,WAAW,YAAY;IAAE,GAAG;IAAO,IAAI,MAAM;GAAa,CAAC;GAC1E,MAAM,KAAK,IAAI,UAAU,qCAAqC,MAAM,CAAC,IAAI,GAAG;IAAE,GAAG;IAAO,IAAI,MAAM;GAAG,CAAC;EACxG;EACA,OAAO;CACT;AACF"}
|
|
@@ -100,6 +100,6 @@ type Window = {
|
|
|
100
100
|
windowStart: number;
|
|
101
101
|
windowEnd: number;
|
|
102
102
|
};
|
|
103
|
-
export declare function computeFactoryMetrics(boardItems: Card[], window: Window, outcomeOf: MetricsPhaseOutcomes): FactoryMetrics;
|
|
103
|
+
export declare function computeFactoryMetrics(boardItems: readonly Card[], window: Window, outcomeOf: MetricsPhaseOutcomes): FactoryMetrics;
|
|
104
104
|
export {};
|
|
105
105
|
//# sourceMappingURL=metrics.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/work-items/metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEtC,+EAA+E;AAC/E,eAAO,MAAM,sBAAsB,KAAK,CAAC;AACzC,kFAAkF;AAClF,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAItC;;;;;GAKG;AACH,MAAM,MAAM,mBAAmB,GAAG,WAAW,GAAG,UAAU,GAAG,QAAQ,GAAG,UAAU,CAAC;AACnF,MAAM,MAAM,oBAAoB,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,mBAAmB,CAAC;AAYrG;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,uFAAuF;IACvF,UAAU,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC9C,iFAAiF;IACjF,QAAQ,EAAE;QAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7E,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,SAAS,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC/C,2EAA2E;IAC3E,aAAa,EAAE;QACb,KAAK,EAAE,MAAM,CAAC;QACd;;;;;WAKG;QACH,MAAM,EAAE,MAAM,CAAC;QACf;;;;;;WAMG;QACH,OAAO,EAAE,MAAM,CAA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E,EAAE,CAAC;IAC9C,iFAAiF;IACjF,QAAQ,EAAE;QAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7E,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,SAAS,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC/C,2EAA2E;IAC3E,aAAa,EAAE;QACb,KAAK,EAAE,MAAM,CAAC;QACd;;;;;WAKG;QACH,MAAM,EAAE,MAAM,CAAC;QACf;;;;;;WAMG;QACH,OAAO,EAAE,MAAM,CAAC;QAChB;;;;;;WAMG;QACH,QAAQ,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAC;KAClF,EAAE,CAAC;CACL;AAqBD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,OAAO,EAClB,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,IAAI,GACR;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAY5C;AA2CD,KAAK,MAAM,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAkGzD,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,SAAS,IAAI,EAAE,EAC3B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,oBAAoB,GAC9B,cAAc,CAoBhB"}
|
|
@@ -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 { 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/**\n * What a card holding `stage` means for flow metrics, read from the card's board: `completed`\n * (an entry feeds throughput and lead time), `canceled` (a tracked non-completion, feeds\n * neither), `queued` (at rest, not yet in flight) or `pipeline` (in flight). Built by\n * `boardPhaseOutcomes`.\n */\nexport type MetricsPhaseOutcome = 'completed' | 'canceled' | 'queued' | 'pipeline';\nexport type MetricsPhaseOutcomes = (item: Pick<Card, 'board'>, stage: string) => MetricsPhaseOutcome;\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 a completing phase per UTC day, gap-filled across the covered days. */\n throughput: { date: string; count: number }[];\n /** Card creation → completion 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 rest, 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* a completing phase, 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, outcomeOf: MetricsPhaseOutcomes) {\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 (outcomeOf(item, entry.stage) !== 'completed') 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[], outcomeOf: MetricsPhaseOutcomes): number {\n return items.filter(item => item.stages.some(stage => outcomeOf(item, stage) === 'pipeline')).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(\n items: Card[],\n { windowStart, windowEnd }: Window,\n outcomeOf: MetricsPhaseOutcomes,\n): FactoryMetrics['agentCoverage'] {\n const byStage = new Map<string, FactoryMetrics['agentCoverage'][number]>();\n for (const item of items) {\n const heldAtWindowEnd = [...stagesHeldAt(item, windowEnd)].map(stage => outcomeOf(item, stage));\n const visited = new Set<string>();\n for (let i = 0; i < item.stageHistory.length; i++) {\n const entry = item.stageHistory[i]!;\n if (outcomeOf(item, entry.stage) !== 'pipeline' || 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.includes('completed')) row.outcomes.done += 1;\n else if (heldAtWindowEnd.includes('canceled')) row.outcomes.canceled += 1;\n else row.outcomes.inFlight += 1;\n }\n }\n return [...byStage.values()];\n}\n\nexport function computeFactoryMetrics(\n boardItems: Card[],\n window: Window,\n outcomeOf: MetricsPhaseOutcomes,\n): FactoryMetrics {\n const items = boardItems.filter(hasFactoryRun);\n assertParsableHistory(items);\n\n const { byDay, leadSamples } = completions(items, window, outcomeOf);\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, outcomeOf),\n sourceMix: demandMix(items, window),\n agentCoverage: agentCoverage(items, window, outcomeOf),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,MAAa,yBAAyB;;AAEtC,MAAa,qBAAqB;AAElC,MAAM,SAAS;;;;;;;AAiBf,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;AAC/C;;;;;;;AAQA,SAAgB,kBACd,WACA,SACA,KAC4C;CAE5C,MAAM,aAAa,YADL,IAAI,QACiB,CAAC,IAAI;CACxC,MAAM,eAAe,gBAAgB,SAAS,IAAI,KAAK;CACvD,MAAM,YAAY,KAAK,IAAI,cAAc,UAAU;CACnD,MAAM,kBAAkB,YAAY,YAAY,CAAC;CACjD,MAAM,eAAe,kBAAmB,KAA8B;CACtE,MAAM,aAAa,gBAAgB,WAAW,MAAM;CACpD,IAAI,cAAc,eAAe,KAAA,KAAa,aAAa,YAAY,aAAa;CACpF,MAAM,gBAAgB,kBAAmB,MAA0B;CACnE,IAAI,cAAc,eAAe,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AAa;CAC7C,sBAAsB,KAAK;CAE3B,MAAM,EAAE,OAAO,gBAAgB,YAAY,OAAO,QAAQ,SAAS;CAEnE,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,OAAO,SAAS;EACxC,WAAW,UAAU,OAAO,MAAM;EAClC,eAAe,cAAc,OAAO,QAAQ,SAAS;CACvD;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/**\n * What a card holding `stage` means for flow metrics, read from the card's board: `completed`\n * (an entry feeds throughput and lead time), `canceled` (a tracked non-completion, feeds\n * neither), `queued` (at rest, not yet in flight) or `pipeline` (in flight). Built by\n * `boardPhaseOutcomes`.\n */\nexport type MetricsPhaseOutcome = 'completed' | 'canceled' | 'queued' | 'pipeline';\nexport type MetricsPhaseOutcomes = (item: Pick<Card, 'board'>, stage: string) => MetricsPhaseOutcome;\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 a completing phase per UTC day, gap-filled across the covered days. */\n throughput: { date: string; count: number }[];\n /** Card creation → completion 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 rest, 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* a completing phase, 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, outcomeOf: MetricsPhaseOutcomes) {\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 (outcomeOf(item, entry.stage) !== 'completed') 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[], outcomeOf: MetricsPhaseOutcomes): number {\n return items.filter(item => item.stages.some(stage => outcomeOf(item, stage) === 'pipeline')).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(\n items: Card[],\n { windowStart, windowEnd }: Window,\n outcomeOf: MetricsPhaseOutcomes,\n): FactoryMetrics['agentCoverage'] {\n const byStage = new Map<string, FactoryMetrics['agentCoverage'][number]>();\n for (const item of items) {\n const heldAtWindowEnd = [...stagesHeldAt(item, windowEnd)].map(stage => outcomeOf(item, stage));\n const visited = new Set<string>();\n for (let i = 0; i < item.stageHistory.length; i++) {\n const entry = item.stageHistory[i]!;\n if (outcomeOf(item, entry.stage) !== 'pipeline' || 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.includes('completed')) row.outcomes.done += 1;\n else if (heldAtWindowEnd.includes('canceled')) row.outcomes.canceled += 1;\n else row.outcomes.inFlight += 1;\n }\n }\n return [...byStage.values()];\n}\n\nexport function computeFactoryMetrics(\n boardItems: readonly Card[],\n window: Window,\n outcomeOf: MetricsPhaseOutcomes,\n): FactoryMetrics {\n const items = boardItems.filter(hasFactoryRun);\n assertParsableHistory(items);\n\n const { byDay, leadSamples } = completions(items, window, outcomeOf);\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, outcomeOf),\n sourceMix: demandMix(items, window),\n agentCoverage: agentCoverage(items, window, outcomeOf),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,MAAa,yBAAyB;;AAEtC,MAAa,qBAAqB;AAElC,MAAM,SAAS;;;;;;;AAiBf,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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AS;KACT,UAAU;MAAE,MAAM;MAAG,UAAU;MAAG,UAAU;MAAG,UAAU;KAAE;IAC7D;IACA,QAAQ,IAAI,MAAM,OAAO,GAAG;GAC9B;GACA,IAAI,UAAU;GACd,IAAI,CAAC,aAAa,MAAM,QAAQ,GAAG;GACnC,IAAI,WAAW;GAKf,IAHiB,KAAK,aAAa,MAChC,OAAO,MAAM,IAAI,KAAK,MAAM,UAAU,MAAM,SAAS,UAAU,MAAM,SAAS,IAAI,SAE1E,GAAG,IAAI,SAAS,YAAY;QAClC,IAAI,gBAAgB,SAAS,WAAW,GAAG,IAAI,SAAS,QAAQ;QAChE,IAAI,gBAAgB,SAAS,UAAU,GAAG,IAAI,SAAS,YAAY;QACnE,IAAI,SAAS,YAAY;EAChC;CACF;CACA,OAAO,CAAC,GAAG,QAAQ,OAAO,CAAC;AAC7B;AAEA,SAAgB,sBACd,YACA,QACA,WACgB;CAChB,MAAM,QAAQ,WAAW,OAAO,aAAa;CAC7C,sBAAsB,KAAK;CAE3B,MAAM,EAAE,OAAO,gBAAgB,YAAY,OAAO,QAAQ,SAAS;CAEnE,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,OAAO,SAAS;EACxC,WAAW,UAAU,OAAO,MAAM;EAClC,eAAe,cAAc,OAAO,QAAQ,SAAS;CACvD;AACF"}
|
|
@@ -12,6 +12,7 @@ export interface WorkItemDbRecord extends Record<string, unknown> {
|
|
|
12
12
|
org_id: string;
|
|
13
13
|
factory_project_id: string;
|
|
14
14
|
title: string;
|
|
15
|
+
description: string | null;
|
|
15
16
|
parent_work_item_id: string | null;
|
|
16
17
|
revision: number;
|
|
17
18
|
created_at: Date;
|
|
@@ -101,8 +102,6 @@ export interface BoardItemDbRecord extends Record<string, unknown> {
|
|
|
101
102
|
stage_history: unknown[];
|
|
102
103
|
sessions: Record<string, unknown>;
|
|
103
104
|
metadata: Record<string, unknown> | null;
|
|
104
|
-
comment_count: number;
|
|
105
|
-
feed_activity_at: Date | null;
|
|
106
105
|
revision: number;
|
|
107
106
|
created_by: string;
|
|
108
107
|
created_at: Date;
|
|
@@ -1 +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,
|
|
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,gBAcvC,CAAC;AAEF,sFAAsF;AACtF,eAAO,MAAM,gC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ACnB,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,gBAgE/B,CAAC;AAEF,6GAA6G;AAC7G,eAAO,MAAM,oCAAoC,EAAE,gBAQlD,CAAC"}
|
|
@@ -7,6 +7,10 @@ const FACTORY_WORK_ITEMS_SCHEMA = {
|
|
|
7
7
|
org_id: { type: "text" },
|
|
8
8
|
factory_project_id: { type: "text" },
|
|
9
9
|
title: { type: "text" },
|
|
10
|
+
description: {
|
|
11
|
+
type: "text",
|
|
12
|
+
nullable: true
|
|
13
|
+
},
|
|
10
14
|
parent_work_item_id: {
|
|
11
15
|
type: "text",
|
|
12
16
|
nullable: true
|
|
@@ -136,14 +140,6 @@ const FACTORY_BOARD_ITEMS_SCHEMA = {
|
|
|
136
140
|
type: "json",
|
|
137
141
|
nullable: true
|
|
138
142
|
},
|
|
139
|
-
comment_count: {
|
|
140
|
-
type: "integer",
|
|
141
|
-
default: 0
|
|
142
|
-
},
|
|
143
|
-
feed_activity_at: {
|
|
144
|
-
type: "timestamp",
|
|
145
|
-
nullable: true
|
|
146
|
-
},
|
|
147
143
|
revision: {
|
|
148
144
|
type: "integer",
|
|
149
145
|
default: 1
|
|
@@ -230,6 +226,10 @@ const WORK_ITEMS_SCHEMA = {
|
|
|
230
226
|
nullable: true
|
|
231
227
|
},
|
|
232
228
|
title: { type: "text" },
|
|
229
|
+
description: {
|
|
230
|
+
type: "text",
|
|
231
|
+
nullable: true
|
|
232
|
+
},
|
|
233
233
|
stages: { type: "json" },
|
|
234
234
|
stage_history: { type: "json" },
|
|
235
235
|
sessions: { type: "json" },
|
|
@@ -1 +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 /** `origin` for the record the work item was created from, `attached` for one added later. Null (rows written before this column) reads as `origin`. */\n role: { type: 'text', 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 role?: WorkItemSourceRole | null;\n revision: number;\n synced_at: Date | null;\n created_at: Date;\n updated_at: Date;\n}\n\nexport type WorkItemSourceRole = 'origin' | 'attached';\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 // Finds the newest legacy write without a scan, so a finished split can be confirmed at boot.\n name: 'work_items_updated_at_id_idx',\n columns: ['updated_at', 'id'],\n },\n ],\n};\n\n/** Records the newest legacy row a finished split pass covered; later boots skip unchanged legacy tables. */\nexport const FACTORY_WORK_ITEM_SPLIT_STATE_SCHEMA: CollectionSchema = {\n name: 'factory_work_item_split_state',\n columns: {\n id: { type: 'text', primaryKey: true },\n legacy_updated_at: { type: 'timestamp', nullable: true },\n legacy_id: { type: 'text', nullable: true },\n completed_at: { type: 'timestamp' },\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,MAAM,OAAO;EACzB,gBAAgB,EAAE,MAAM,OAAO;EAC/B,aAAa,EAAE,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E,MAAM;GAAQ,UAAU;EAAK;EAC1C,cAAc,EAAE,MAAM,YAAY;CACpC;AACF"}
|
|
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 description: { type: 'text', nullable: true },\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 /** `origin` for the record the work item was created from, `attached` for one added later. Null (rows written before this column) reads as `origin`. */\n role: { type: 'text', 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 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 description: string | null;\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 role?: WorkItemSourceRole | null;\n revision: number;\n synced_at: Date | null;\n created_at: Date;\n updated_at: Date;\n}\n\nexport type WorkItemSourceRole = 'origin' | 'attached';\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 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 description: { type: 'text', nullable: true },\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 // Retired comment summaries: kept so replicas still on the old release can write them.\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 // Finds the newest legacy write without a scan, so a finished split can be confirmed at boot.\n name: 'work_items_updated_at_id_idx',\n columns: ['updated_at', 'id'],\n },\n ],\n};\n\n/** Records the newest legacy row a finished split pass covered; later boots skip unchanged legacy tables. */\nexport const FACTORY_WORK_ITEM_SPLIT_STATE_SCHEMA: CollectionSchema = {\n name: 'factory_work_item_split_state',\n columns: {\n id: { type: 'text', primaryKey: true },\n legacy_updated_at: { type: 'timestamp', nullable: true },\n legacy_id: { type: 'text', nullable: true },\n completed_at: { type: 'timestamp' },\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,aAAa;GAAE,MAAM;GAAQ,UAAU;EAAK;EAC5C,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,EA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AU;EAAK;EACvD,WAAW;GAAE,MAAM;GAAQ,UAAU;EAAK;EAC1C,cAAc,EAAE,MAAM,YAAY;CACpC;AACF"}
|
|
@@ -5,7 +5,6 @@ import type { IntegrationTools } from '../integrations/base.js';
|
|
|
5
5
|
import type { SourceControlSessionLookup } from '../session/factory-session.js';
|
|
6
6
|
import type { LiveSessions } from '../session/live-sessions.js';
|
|
7
7
|
import type { AuditStorage } from '../storage/domains/audit/base.js';
|
|
8
|
-
import type { WorkItemCommentsStorage } from '../storage/domains/comments/base.js';
|
|
9
8
|
import type { Card, WorkItemsStorage } from '../storage/domains/work-items/base.js';
|
|
10
9
|
import type { FactoryMessaging } from './messaging-tools.js';
|
|
11
10
|
import type { FactoryToolScope } from './scope.js';
|
|
@@ -14,7 +13,6 @@ export declare const MAX_ERROR = 400;
|
|
|
14
13
|
export declare const MAX_LIST = 50;
|
|
15
14
|
export interface FactoryReadToolDependencies {
|
|
16
15
|
workItems: Pick<WorkItemsStorage, 'listShared' | 'getForProject' | 'listRunBindings' | 'listDeferredDecisions' | 'listByIds' | 'listDecisionsForEvaluations' | 'listWorkItemSubscribers' | 'listSessionSubscriptions'>;
|
|
17
|
-
comments: Pick<WorkItemCommentsStorage, 'listRecent'>;
|
|
18
16
|
audit: Pick<AuditStorage, 'list'>;
|
|
19
17
|
/** A fixed registry, or the per-project boards. */
|
|
20
18
|
boards: BoardRegistry | ProjectBoardSource;
|
|
@@ -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;AAUxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAMhE,OAAO,KAAK,EAAE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