@mastra/factory 0.13.0-alpha.17 → 0.13.0-alpha.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +18 -1
  2. package/dist/boards/relocate.d.ts +17 -0
  3. package/dist/boards/relocate.d.ts.map +1 -0
  4. package/dist/boards/relocate.js +53 -0
  5. package/dist/boards/relocate.js.map +1 -0
  6. package/dist/capabilities/intake.d.ts +2 -0
  7. package/dist/capabilities/intake.d.ts.map +1 -1
  8. package/dist/factory.js +1 -1
  9. package/dist/integrations/github/default-rules.d.ts +2 -2
  10. package/dist/integrations/github/default-rules.d.ts.map +1 -1
  11. package/dist/integrations/github/default-rules.js +2 -2
  12. package/dist/integrations/github/default-rules.js.map +1 -1
  13. package/dist/integrations/github/rules.d.ts +3 -0
  14. package/dist/integrations/github/rules.d.ts.map +1 -1
  15. package/dist/integrations/github/rules.js +81 -4
  16. package/dist/integrations/github/rules.js.map +1 -1
  17. package/dist/integrations/linear/agent-tools.d.ts.map +1 -1
  18. package/dist/integrations/linear/agent-tools.js.map +1 -1
  19. package/dist/integrations/linear/default-rules.d.ts +2 -2
  20. package/dist/integrations/linear/default-rules.d.ts.map +1 -1
  21. package/dist/integrations/linear/default-rules.js +2 -2
  22. package/dist/integrations/linear/default-rules.js.map +1 -1
  23. package/dist/integrations/linear/integration.js +1 -0
  24. package/dist/integrations/linear/integration.js.map +1 -1
  25. package/dist/integrations/linear/reconciliation-config.d.ts.map +1 -1
  26. package/dist/integrations/linear/reconciliation-config.js.map +1 -1
  27. package/dist/integrations/linear/routes.d.ts.map +1 -1
  28. package/dist/integrations/linear/routes.js +19 -26
  29. package/dist/integrations/linear/routes.js.map +1 -1
  30. package/dist/integrations/linear/rules.d.ts +4 -0
  31. package/dist/integrations/linear/rules.d.ts.map +1 -1
  32. package/dist/integrations/linear/rules.js +6 -0
  33. package/dist/integrations/linear/rules.js.map +1 -1
  34. package/dist/integrations/platform/github/integration.d.ts +1 -0
  35. package/dist/integrations/platform/github/integration.d.ts.map +1 -1
  36. package/dist/integrations/platform/github/integration.js +5 -0
  37. package/dist/integrations/platform/github/integration.js.map +1 -1
  38. package/dist/integrations/platform/linear/integration.d.ts.map +1 -1
  39. package/dist/integrations/platform/linear/integration.js +4 -1
  40. package/dist/integrations/platform/linear/integration.js.map +1 -1
  41. package/dist/routes/contracts.d.ts +29 -0
  42. package/dist/routes/contracts.d.ts.map +1 -1
  43. package/dist/routes/contracts.js +25 -0
  44. package/dist/routes/contracts.js.map +1 -1
  45. package/dist/routes/intake.d.ts +18 -0
  46. package/dist/routes/intake.d.ts.map +1 -1
  47. package/dist/routes/intake.js +265 -15
  48. package/dist/routes/intake.js.map +1 -1
  49. package/dist/routes/surface.d.ts.map +1 -1
  50. package/dist/routes/surface.js +2 -0
  51. package/dist/routes/surface.js.map +1 -1
  52. package/dist/routes/work-items.d.ts.map +1 -1
  53. package/dist/routes/work-items.js +23 -0
  54. package/dist/routes/work-items.js.map +1 -1
  55. package/dist/rules/types.d.ts +15 -0
  56. package/dist/rules/types.d.ts.map +1 -1
  57. package/dist/rules/types.js.map +1 -1
  58. package/dist/storage/domains/intake/base.d.ts +54 -1
  59. package/dist/storage/domains/intake/base.d.ts.map +1 -1
  60. package/dist/storage/domains/intake/base.js +136 -4
  61. package/dist/storage/domains/intake/base.js.map +1 -1
  62. package/package.json +5 -5
package/README.md CHANGED
@@ -311,12 +311,29 @@ export function createFactory(config: Omit<MastraFactoryConfig, 'boards' | 'incl
311
311
 
312
312
  Use the host's normal `prepare()`, `new Mastra(...)`, and `finalize()` sequence. Change the hardcoded `includeDefaultBoards: true` in `createFactory` to `false` to run without Work or Review. Working roles name bindings on the shared Code Agent; they do not register separate agents. Factory has no per-role agent configuration option. The board's kickoff prompts supply the role-specific instructions.
313
313
 
314
- Create a card with `POST /web/factory/projects/:id/work-items`, passing `board: 'release'`, a title, and the GitHub issue's `externalSource`. The card starts in `queued`. Then use `POST /web/factory/projects/:id/work-items/:workItemId/transition` with `board: 'release'`, `stage: 'preparing'`, the returned `expectedRevision`, a unique `requestId`, and a `cause`. Send these requests as an authorized user using the host's authentication. The human transition satisfies this board's policy and starts the preparer. Its bound tool advances to `shipping`; the publisher's completed check produces a deferred transition to `shipped`. Terminal entry revokes the binding and releases the sandbox. Check the persisted card's board, phase, and deferred decision status rather than relying on the built-in UI pipeline.
314
+ Create a card with `POST /web/factory/projects/:id/work-items`, passing `board: 'release'`, a title, and the GitHub issue's `externalSource`. The card starts in `queued`. Then use `POST /web/factory/projects/:id/work-items/:workItemId/transition` with `board: 'release'`, `stage: 'preparing'`, the returned `expectedRevision`, a unique `requestId`, and a `cause`. Send these requests as an authorized user using the host's authentication. The human transition satisfies this board's policy and starts the preparer. Its bound tool advances to `shipping`; the publisher's completed check produces a deferred transition to `shipped`. Terminal entry revokes the binding and releases the sandbox. The Factory UI performs the same operations against installed boards (see below); verify the persisted card's board, phase, and deferred decision status either way.
315
315
 
316
316
  Lifecycle, tool-result, and integration handlers may return `upsertLinkedWorkItem` targeting a different installed board. Linked cards enter that board's declared initial phase before moving to the requested phase. Existing cards cannot be reassigned to another board through either decision type. Targets are validated against their own installed board before acceptance and again before uncommitted deferred effects execute; a phase declared only on another board is not valid. Committed replay retains its recorded result and original `configVersion`.
317
317
 
318
318
  Custom phase signals and persisted tool-result ingestion use the item's installed board. Bound tools re-resolve the live binding, retain revision and topology checks, and reject session reassignment. A custom role named `triage` does not inherit Work's classification requirements. Existing authorization, external-author safeguards, and board-owned policies still apply.
319
319
 
320
+ ### Custom boards in the Factory UI
321
+
322
+ `GET /web/factory/projects/:id/boards` returns the installed board catalog for an authorized project: each board's `id`, `title`, `initialPhase`, declaration-ordered `phases` (with `kind` and working `role`), and transition topology. Handlers, policies, and prompts are never serialized. The Factory UI reads this catalog instead of assuming Work and Review:
323
+
324
+ - Installed boards appear in the sidebar — built-ins first, then custom boards in registry order. Work and Review keep `/factories/:id/work` and `/factories/:id/review`; custom boards open at `/factories/:id/boards/:boardId`. An unknown board ID or a failed catalog request shows an explicit unavailable state rather than falling back to Work.
325
+ - Columns, phase labels, and working/terminal presentation come from the phase definitions. Card creation sends the selected `board`, so the server picks the initial phase. Card menus offer only moves the topology declares; the server still enforces policy, authorization, and revisions.
326
+ - A card's persisted `board` decides which board it belongs to. UI actions cannot move a card to a different board.
327
+ - Settings › Skills groups built-in skills under Work and Review and lists each custom board's declared roles. Custom-board kickoff instructions live in code; there is no skill or per-role agent configuration for them.
328
+ - Not yet board-aware: the Overview funnel and stage-hold metrics (Work-only), search scopes (Work/Review sessions), and the automation toggles that are specific to Work triage and Review. Custom-board cards still count toward in-flight totals and appear in activity and audit logs.
329
+
330
+ ### Route intake to custom boards
331
+
332
+ Intake bindings are explicit. A Linear project (Settings › Intake › Linear routing) or GitHub repository is only offered as a candidate feed once it is bound to a board; nothing is materialized just by opening a board. Review only accepts pull requests and is not offered for issue routing.
333
+
334
+ - **Linear:** each project binding selects one installed board. Changing the board moves that source's existing cards to the new board's initial phase, skipping terminal cards and cards with an active session.
335
+ - **GitHub:** Settings › Intake › GitHub routing maps a label to a board per Factory project (`GET`/`PUT /web/intake/label-routes`). Labels match case-insensitively; unrouted issues go to Work. Saving a route relocates matching cards the same way, and `issues.labeled` / `issues.unlabeled` webhooks move a card between its routed board and Work while refreshing its label metadata. Routes apply to every repository linked to the project; label input is free text (no repository label autocomplete yet).
336
+
320
337
  ### GitHub event rules
321
338
 
322
339
  Both `GithubIntegration` and `PlatformGithubIntegration` own their GitHub event handlers. Existing installations retain the defaults without additional configuration.
@@ -0,0 +1,17 @@
1
+ import type { WorkItemRow, WorkItemsStorage } from '../storage/domains/work-items/base.js';
2
+ import type { BoardRegistry } from './registry.js';
3
+ /** Rows that predate persisted boards used source-type routing. */
4
+ export declare function effectiveBoard(item: WorkItemRow): string;
5
+ /**
6
+ * Put one card on `targetBoard`'s initial phase. Terminal cards and cards with a session attached to a
7
+ * current stage stay put; so does a card that changed under us (a run started or someone moved it).
8
+ */
9
+ export declare function moveCardToBoard({ workItems, boardRegistry, userId, item, targetBoard, }: {
10
+ workItems: Pick<WorkItemsStorage, 'update' | 'supersedeDecisionsForWorkItem'>;
11
+ boardRegistry: BoardRegistry;
12
+ userId: string;
13
+ item: WorkItemRow;
14
+ targetBoard: string;
15
+ }): Promise<'moved' | 'skipped' | 'unchanged'>;
16
+ export declare function cardLabels(item: WorkItemRow): string[];
17
+ //# sourceMappingURL=relocate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relocate.d.ts","sourceRoot":"","sources":["../../src/boards/relocate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAC3F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,mEAAmE;AACnE,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAExD;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,EACpC,SAAS,EACT,aAAa,EACb,MAAM,EACN,IAAI,EACJ,WAAW,GACZ,EAAE;IACD,SAAS,EAAE,IAAI,CAAC,gBAAgB,EAAE,QAAQ,GAAG,+BAA+B,CAAC,CAAC;IAC9E,aAAa,EAAE,aAAa,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,WAAW,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,GAAG,WAAW,CAAC,CAmC7C;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,EAAE,CAGtD"}
@@ -0,0 +1,53 @@
1
+ import { WorkItemUpdateConflictError } from "../storage/domains/work-items/base.js";
2
+ //#region src/boards/relocate.ts
3
+ /** Rows that predate persisted boards used source-type routing. */
4
+ function effectiveBoard(item) {
5
+ return item.board ?? (item.externalSource?.type === "pull-request" ? "review" : "work");
6
+ }
7
+ /**
8
+ * Put one card on `targetBoard`'s initial phase. Terminal cards and cards with a session attached to a
9
+ * current stage stay put; so does a card that changed under us (a run started or someone moved it).
10
+ */
11
+ async function moveCardToBoard({ workItems, boardRegistry, userId, item, targetBoard }) {
12
+ const target = boardRegistry.get(targetBoard);
13
+ if (!target) return "unchanged";
14
+ const currentBoard = effectiveBoard(item);
15
+ if (currentBoard === targetBoard) return "unchanged";
16
+ const current = boardRegistry.get(currentBoard);
17
+ if (!item.stages.every((stage) => {
18
+ if (current?.phases[stage]?.kind === "terminal") return false;
19
+ const role = current?.roleForPhase(stage);
20
+ return role === void 0 || item.sessions[role] === void 0;
21
+ })) return "skipped";
22
+ try {
23
+ if (!await workItems.update({
24
+ orgId: item.orgId,
25
+ id: item.id,
26
+ userId,
27
+ patch: {
28
+ board: targetBoard,
29
+ stages: [target.initialPhase]
30
+ },
31
+ expectedRevision: item.revision,
32
+ expectedBoard: item.board
33
+ })) return "skipped";
34
+ await workItems.supersedeDecisionsForWorkItem({
35
+ orgId: item.orgId,
36
+ factoryProjectId: item.factoryProjectId,
37
+ workItemId: item.id,
38
+ supersededAt: /* @__PURE__ */ new Date()
39
+ });
40
+ return "moved";
41
+ } catch (error) {
42
+ if (!(error instanceof WorkItemUpdateConflictError)) throw error;
43
+ return "skipped";
44
+ }
45
+ }
46
+ function cardLabels(item) {
47
+ const labels = item.metadata?.labels;
48
+ return Array.isArray(labels) ? labels.filter((label) => typeof label === "string") : [];
49
+ }
50
+ //#endregion
51
+ export { cardLabels, effectiveBoard, moveCardToBoard };
52
+
53
+ //# sourceMappingURL=relocate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relocate.js","names":[],"sources":["../../src/boards/relocate.ts"],"sourcesContent":["import { WorkItemUpdateConflictError } from '../storage/domains/work-items/base.js';\nimport type { WorkItemRow, WorkItemsStorage } from '../storage/domains/work-items/base.js';\nimport type { BoardRegistry } from './registry.js';\n\n/** Rows that predate persisted boards used source-type routing. */\nexport function effectiveBoard(item: WorkItemRow): string {\n return item.board ?? (item.externalSource?.type === 'pull-request' ? 'review' : 'work');\n}\n\n/**\n * Put one card on `targetBoard`'s initial phase. Terminal cards and cards with a session attached to a\n * current stage stay put; so does a card that changed under us (a run started or someone moved it).\n */\nexport async function moveCardToBoard({\n workItems,\n boardRegistry,\n userId,\n item,\n targetBoard,\n}: {\n workItems: Pick<WorkItemsStorage, 'update' | 'supersedeDecisionsForWorkItem'>;\n boardRegistry: BoardRegistry;\n userId: string;\n item: WorkItemRow;\n targetBoard: string;\n}): Promise<'moved' | 'skipped' | 'unchanged'> {\n const target = boardRegistry.get(targetBoard);\n if (!target) return 'unchanged';\n const currentBoard = effectiveBoard(item);\n if (currentBoard === targetBoard) return 'unchanged';\n const current = boardRegistry.get(currentBoard);\n // Sessions are keyed by the phase's role, not the phase id.\n const movable = item.stages.every(stage => {\n if (current?.phases[stage]?.kind === 'terminal') return false;\n const role = current?.roleForPhase(stage);\n return role === undefined || item.sessions[role] === undefined;\n });\n if (!movable) return 'skipped';\n try {\n const updated = await workItems.update({\n orgId: item.orgId,\n id: item.id,\n userId,\n patch: { board: targetBoard, stages: [target.initialPhase] },\n expectedRevision: item.revision,\n expectedBoard: item.board,\n });\n if (!updated) return 'skipped';\n // Runs proposed by the old board's phases (e.g. Work's triage) mean nothing on the new board.\n await workItems.supersedeDecisionsForWorkItem({\n orgId: item.orgId,\n factoryProjectId: item.factoryProjectId,\n workItemId: item.id,\n supersededAt: new Date(),\n });\n return 'moved';\n } catch (error) {\n if (!(error instanceof WorkItemUpdateConflictError)) throw error;\n return 'skipped';\n }\n}\n\nexport function cardLabels(item: WorkItemRow): string[] {\n const labels = item.metadata?.labels;\n return Array.isArray(labels) ? labels.filter((label): label is string => typeof label === 'string') : [];\n}\n"],"mappings":";;;AAKA,SAAgB,eAAe,MAA2B;CACxD,OAAO,KAAK,UAAU,KAAK,gBAAgB,SAAS,iBAAiB,WAAW;AAClF;;;;;AAMA,eAAsB,gBAAgB,EACpC,WACA,eACA,QACA,MACA,eAO6C;CAC7C,MAAM,SAAS,cAAc,IAAI,WAAW;CAC5C,IAAI,CAAC,QAAQ,OAAO;CACpB,MAAM,eAAe,eAAe,IAAI;CACxC,IAAI,iBAAiB,aAAa,OAAO;CACzC,MAAM,UAAU,cAAc,IAAI,YAAY;CAO9C,IAAI,CALY,KAAK,OAAO,OAAM,UAAS;EACzC,IAAI,SAAS,OAAO,MAAM,EAAE,SAAS,YAAY,OAAO;EACxD,MAAM,OAAO,SAAS,aAAa,KAAK;EACxC,OAAO,SAAS,KAAA,KAAa,KAAK,SAAS,UAAU,KAAA;CACvD,CACW,GAAG,OAAO;CACrB,IAAI;EASF,IAAI,CAAC,MARiB,UAAU,OAAO;GACrC,OAAO,KAAK;GACZ,IAAI,KAAK;GACT;GACA,OAAO;IAAE,OAAO;IAAa,QAAQ,CAAC,OAAO,YAAY;GAAE;GAC3D,kBAAkB,KAAK;GACvB,eAAe,KAAK;EACtB,CAAC,GACa,OAAO;EAErB,MAAM,UAAU,8BAA8B;GAC5C,OAAO,KAAK;GACZ,kBAAkB,KAAK;GACvB,YAAY,KAAK;GACjB,8BAAc,IAAI,KAAK;EACzB,CAAC;EACD,OAAO;CACT,SAAS,OAAO;EACd,IAAI,EAAE,iBAAiB,8BAA8B,MAAM;EAC3D,OAAO;CACT;AACF;AAEA,SAAgB,WAAW,MAA6B;CACtD,MAAM,SAAS,KAAK,UAAU;CAC9B,OAAO,MAAM,QAAQ,MAAM,IAAI,OAAO,QAAQ,UAA2B,OAAO,UAAU,QAAQ,IAAI,CAAC;AACzG"}
@@ -45,6 +45,8 @@ export interface IntakeIssue {
45
45
  assignee: string | null;
46
46
  assignees?: string[];
47
47
  source: string | null;
48
+ /** Provider source id the issue was read from (Linear project id); lets callers map issues back to intake bindings. */
49
+ sourceId?: string | null;
48
50
  labels: string[];
49
51
  commentCount: number | null;
50
52
  createdAt: string;
@@ -1 +1 @@
1
- {"version":3,"file":"intake.d.ts","sourceRoot":"","sources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sB,GAAG,IAAI,CAAC,CAAC;IAClG,WAAW,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IACpE,SAAS,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAChE,UAAU,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IACnE,QAAQ,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC;IACxE,aAAa,CAAC,KAAK,EAAE,wBAAwB,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAAC;IACrF;;;;;;OAMG;IACH,WAAW,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;CACzE"}
package/dist/factory.js CHANGED
@@ -9,6 +9,7 @@ import { reconcileGithubAcceptanceLabels } from "./integrations/github/acceptanc
9
9
  import { recordFactoryPullRequestProvenance, resolveFactoryPullRequestParentWorkItemId } from "./integrations/github/provenance.js";
10
10
  import { isValidGitRef } from "./integrations/github/sandbox.js";
11
11
  import { WorkItemsStorage } from "./storage/domains/work-items/base.js";
12
+ import { IntakeStorage } from "./storage/domains/intake/base.js";
12
13
  import { PlatformGithubIntegration } from "./integrations/platform/github/integration.js";
13
14
  import { PlatformLinearIntegration } from "./integrations/platform/linear/integration.js";
14
15
  import { createCustomProvidersPrimer, registerCustomProvidersSource } from "./routes/custom-provider-source.js";
@@ -48,7 +49,6 @@ import { WorkItemCommentsStorage } from "./storage/domains/comments/base.js";
48
49
  import { CommentsDomain } from "./storage/domains/comments/domain.js";
49
50
  import { CustomProvidersStorage } from "./storage/domains/custom-providers/base.js";
50
51
  import { FilesystemStorage } from "./storage/domains/filesystem/base.js";
51
- import { IntakeStorage } from "./storage/domains/intake/base.js";
52
52
  import { IntegrationStorage } from "./storage/domains/integrations/base.js";
53
53
  import { ModelPacksStorage } from "./storage/domains/model-packs/base.js";
54
54
  import { FactoryProjectsStorage } from "./storage/domains/projects/base.js";
@@ -11,12 +11,12 @@ declare function retriageGithubIssue(context: FactoryGithubRuleContext): {
11
11
  declare function issueOpened(context: FactoryGithubRuleContext): {
12
12
  readonly type: "upsertLinkedWorkItem";
13
13
  readonly idempotencyKey: `${string}:issue-intake`;
14
- readonly board: "work";
14
+ readonly board: string;
15
15
  readonly source: "github-issue";
16
16
  readonly sourceKey: `github-issue:${number}`;
17
17
  readonly title: string;
18
18
  readonly url: string;
19
- readonly stage: "intake";
19
+ readonly stage: string;
20
20
  readonly metadata: {
21
21
  readonly authorTrusted: boolean;
22
22
  readonly autoStartCandidate: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"default-rules.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/default-rules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAEjH,MAAM,MAAM,mBAAmB,GAAG,OAAO,CACvC,MAAM,CAAC,sBAAsB,EAAE,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,CAChG,CAAC;AACF,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CACrC,MAAM,CAAC,sBAAsB,EAAE,kBAAkB,CAAC,wBAAwB,CAAC,GAAG,IAAI,CAAC,CACpF,CAAC;AAUF,iBAAS,mBAAmB,CAAC,OAAO,EAAE,wBAAwB;;;;;;cAuB7D;AASD,iBAAS,WAAW,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;;;;;;;;;;;;cAyBrD;AAED,iBAAS,WAAW,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;cAqBrD;AAoCD,iBAAS,iBAAiB,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;cAW3D;AAED,iBAAS,iBAAiB,CAAC,OAAO,EAAE,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BAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;cAW3D;AAED,iBAAS,iBAAiB,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;;;;;;;;;cA6B3D;AAED,iBAAS,qBAAqB,CAAC,OAAO,EAAE,wBAAwB;;;;;;cA0B/D;AA4BD,iBAAS,yBAAyB,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkCnE;AAED,iBAAS,iBAAiB,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;cAgB3D;AAED,iBAAS,4BAA4B,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA6BtE;AAED,iBAAS,0BAA0B,CAAC,OAAO,EAAE,wBAAwB;;;;;;cAoBpE;AAED,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;EAcF,CAAC;AAE9B,wBAAgB,kBAAkB,CAAC,SAAS,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,CAgBpF"}
@@ -28,12 +28,12 @@ function issueOpened(context) {
28
28
  return {
29
29
  type: "upsertLinkedWorkItem",
30
30
  idempotencyKey: `${context.ingress.id}:issue-intake`,
31
- board: "work",
31
+ board: context.intake?.board ?? "work",
32
32
  source: "github-issue",
33
33
  sourceKey: `github-issue:${context.issue.number}`,
34
34
  title: context.issue.title,
35
35
  url: context.issue.url,
36
- stage: "intake",
36
+ stage: context.intake?.initialPhase ?? "intake",
37
37
  metadata: {
38
38
  githubRepositoryId: context.repository.id,
39
39
  githubIssueNumber: context.issue.number,
@@ -1 +1 @@
1
- {"version":3,"file":"default-rules.js","names":[],"sources":["../../../src/integrations/github/default-rules.ts"],"sourcesContent":["import type { FactoryGithubEventName, FactoryGithubRuleContext, FactoryRuleHandler } from '../../rules/types.js';\n\nexport type GithubRuleOverrides = Partial<\n Record<FactoryGithubEventName, FactoryRuleHandler<FactoryGithubRuleContext> | null | undefined>\n>;\nexport type GithubEventRules = Readonly<\n Record<FactoryGithubEventName, FactoryRuleHandler<FactoryGithubRuleContext> | null>\n>;\n\nfunction trustedGithubActor(context: Pick<FactoryGithubRuleContext, 'actor'>): boolean {\n return context.actor.type === 'github' && context.actor.trusted;\n}\n\nfunction githubActorLogin(context: Pick<FactoryGithubRuleContext, 'actor'>): string | undefined {\n return context.actor.type === 'github' ? context.actor.login : undefined;\n}\n\nfunction retriageGithubIssue(context: FactoryGithubRuleContext) {\n if (!context.item || context.item.source !== 'github-issue' || !context.item.url) return;\n if (context.actor.type === 'github' && context.actor.factoryAuthored) return;\n\n const reason =\n context.event === 'issueEdited'\n ? context.issueChange?.title && context.issueChange.body\n ? 'issue title and body edited'\n : context.issueChange?.title\n ? 'issue title edited'\n : 'issue body edited'\n : context.event === 'issueCommentDeleted'\n ? 'comment deleted'\n : context.event === 'issueCommentEdited'\n ? 'comment edited'\n : 'comment created';\n return {\n type: 'invokeSkill',\n idempotencyKey: `${context.ingress.id}:factory-triage`,\n role: 'triage',\n skillName: 'factory-triage',\n arguments: `Re-triage GitHub issue (${context.item.url}) after ${reason}.`,\n } as const;\n}\n\nfunction createdAfterFactory(createdAt: string | undefined, factoryCreatedAt: string): boolean {\n if (!createdAt) return false;\n const sourceCreatedAt = Date.parse(createdAt);\n const projectCreatedAt = Date.parse(factoryCreatedAt);\n return Number.isFinite(sourceCreatedAt) && Number.isFinite(projectCreatedAt) && sourceCreatedAt > projectCreatedAt;\n}\n\nfunction issueOpened(context: FactoryGithubRuleContext) {\n if (!context.issue) return;\n // Everything arrives in Intake; arrival only stamps whether `onArrival` may\n // suggest this card's run without a person.\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey: `${context.ingress.id}:issue-intake`,\n board: 'work',\n source: 'github-issue',\n sourceKey: `github-issue:${context.issue.number}`,\n title: context.issue.title,\n url: context.issue.url,\n stage: 'intake',\n metadata: {\n githubRepositoryId: context.repository.id,\n githubIssueNumber: context.issue.number,\n ...(context.issue.createdAt ? { sourceCreatedAt: context.issue.createdAt } : {}),\n ...(githubActorLogin(context) ? { author: githubActorLogin(context) } : {}),\n authorTrusted: trustedGithubActor(context),\n autoStartCandidate:\n trustedGithubActor(context) && createdAfterFactory(context.issue.createdAt, context.factory.createdAt),\n assignees: context.issue.assignees ?? [],\n labels: context.issue.labels ?? [],\n },\n } as const;\n}\n\nfunction issueClosed(context: FactoryGithubRuleContext) {\n if (!context.item || context.item.source !== 'github-issue' || !context.issue) return;\n if (context.board !== 'work') return;\n // Already off the board: nothing to reconcile.\n if (context.item.stages.some(stage => stage === 'done' || stage === 'canceled')) return;\n // Issue closure is a repository fact, not third-party input — no actor trust\n // gate. `not_planned` (and `duplicate`) means abandoned, everything else is\n // completed work.\n const canceled = context.issue.stateReason === 'not_planned' || context.issue.stateReason === 'duplicate';\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:issue-closed`,\n board: 'work',\n stage: canceled ? 'canceled' : 'done',\n message: {\n text:\n `GitHub issue #${context.issue.number} was closed` +\n `${context.issue.stateReason ? ` (${context.issue.stateReason})` : ''}; ` +\n `this Work card was moved to ${canceled ? 'Canceled' : 'Done'}.`,\n },\n } as const;\n}\n\nfunction materializePullRequestIntake(\n context: FactoryGithubRuleContext,\n { idempotencyKey, autoStartCandidate }: { idempotencyKey: string; autoStartCandidate: boolean },\n) {\n if (!context.pullRequest) return;\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey,\n board: 'review',\n source: 'github-pr',\n sourceKey: `github-pr:${context.pullRequest.number}`,\n title: context.pullRequest.title,\n url: context.pullRequest.url,\n stage: 'intake',\n metadata: {\n githubRepositoryId: context.repository.id,\n githubPullRequestNumber: context.pullRequest.number,\n ...(context.pullRequest.createdAt ? { sourceCreatedAt: context.pullRequest.createdAt } : {}),\n factoryAuthored: context.pullRequest.factoryAuthored,\n authorTrusted: trustedGithubActor(context),\n autoStartCandidate,\n state: context.pullRequest.state,\n draft: context.pullRequest.draft,\n merged: context.pullRequest.merged,\n assignees: context.pullRequest.assignees ?? [],\n requestedReviewers: context.pullRequest.requestedReviewers ?? [],\n labels: context.pullRequest.labels ?? [],\n headBranch: context.pullRequest.headBranch,\n baseBranch: context.pullRequest.baseBranch,\n ...(context.pullRequest.author ? { author: context.pullRequest.author } : {}),\n },\n } as const;\n}\n\nfunction pullRequestOpened(context: FactoryGithubRuleContext) {\n if (!context.pullRequest) return;\n // A GitHub App bot is never a collaborator, so Factory's own PRs score\n // untrusted; their authorship is the trust signal.\n const autoStartCandidate =\n (trustedGithubActor(context) || context.pullRequest.factoryAuthored) &&\n createdAfterFactory(context.pullRequest.createdAt, context.factory.createdAt);\n return materializePullRequestIntake(context, {\n idempotencyKey: `${context.ingress.id}:pull-request-intake`,\n autoStartCandidate,\n });\n}\n\nfunction pullRequestMerged(context: FactoryGithubRuleContext) {\n if (!context.item || !context.pullRequest?.merged) return;\n if (context.board === 'review') {\n // The event is bound to the PR's own Review card: a merged PR is finished\n // review work, so always move the card to Done. The message only reaches\n // an active session (if any) — cards without one just move, instead of\n // failing retries against a binding that never existed.\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:pull-request-merged`,\n board: 'review',\n stage: 'done',\n message: {\n text:\n `Pull request #${context.pullRequest.number} merged; this Review card was moved to Done. ` +\n 'No further review is needed unless follow-up work was requested.',\n },\n } as const;\n }\n // Provenance bound the event to the originating Work item instead: remind\n // its agent to assess completion — never auto-complete the Work item.\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:assess-work-completion`,\n role: 'work',\n message:\n `Pull request #${context.pullRequest.number} merged. Assess whether the linked Work item is complete. ` +\n 'Do not mark it Done solely because this PR merged; use factory_transition_work_item only after verifying the work.',\n } as const;\n}\n\nfunction addressReviewFeedback(context: FactoryGithubRuleContext) {\n if (!context.item || !context.pullRequest || !context.review) return;\n // Only the Work item that authored the PR can act on the feedback. Provenance\n // binds the event there; a Review card seeing its own posted review must not\n // react to it (that would loop the reviewer against itself).\n if (context.board !== 'work') return;\n // A closed or merged pull request has no branch left to push fixes to.\n if (context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // `approved` needs no work, and `commented` (a review body with no verdict)\n // is how a reviewer leaves notes without blocking — only a verdict that asks\n // for changes should pull the author back in.\n if (context.review.state.toLowerCase() !== 'changes_requested') return;\n // The authoring thread is already subscribed to this PR (`gh pr create`\n // subscribes automatically), so it can read the individual line comments\n // from its own notification inbox — the message only has to wake it and\n // point at the review.\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:address-review-feedback`,\n role: 'work',\n priority: 'high',\n message:\n `Changes were requested on pull request #${context.pullRequest.number} (${context.review.url}). ` +\n 'Read the review comments on this PR, address the ones you agree with, and push the fixes to the PR branch. ' +\n 'Reply on GitHub to anything you are deliberately not changing, explaining why.',\n } as const;\n}\n\n/**\n * Detects the `factory-review` handoff verdict in a comment body.\n *\n * GitHub forbids an app from reviewing a pull request it authored, so on\n * Factory-authored PRs the review skill falls back to posting its verdict as a\n * plain comment. That comment is the only signal the authoring agent gets, so\n * it has to be readable back out. The skill's handoff contract puts the verdict\n * on the first line (`Verdict: request changes`), so only that line is\n * inspected — a verdict quoted later in the findings must not count.\n */\nfunction requestsChangesVerdict(body: string | undefined): boolean {\n const firstLine = body\n ?.split('\\n')\n .map(line => line.trim())\n .find(line => line.length > 0);\n if (!firstLine) return false;\n // Tolerate the markdown the skill wraps the line in (`**Verdict: ...**`).\n const normalized = firstLine\n .replaceAll(/[*_`#>\\s]+/g, ' ')\n .trim()\n .toLowerCase();\n // Match the verdict exactly so negated phrasings (\"Verdict: do not request\n // changes\") cannot wake the author.\n return /^verdict: ?(request changes|changes requested)$/.test(normalized);\n}\n\nfunction addressPullRequestComment(context: FactoryGithubRuleContext) {\n // A validated Factory mention is a review-entry request, not feedback for the\n // authoring Work session. Invalid or unrecognized comments retain the normal\n // feedback route below.\n if (context.reviewCommand) return reReviewRequestedPullRequest(context);\n if (!context.item || !context.pullRequest || !context.issueComment) return;\n // Provenance binds the comment to the Work item that authored the PR — the\n // only session that can act on it. A Review card must not react to comments\n // on the PR it is reviewing.\n if (context.board !== 'work') return;\n if (context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // `factoryAuthored` is one bit for the whole Factory, so Factory's own\n // comments are indistinguishable between roles — waking on all of them would\n // let the Work agent's own progress comments wake itself in a loop. The one\n // exception is the review verdict the Review run had to post as a comment\n // because GitHub refused a self-review: that is the handoff, and it only ever\n // asks for changes once per review, so it cannot sustain a loop.\n if (\n context.actor.type === 'github' &&\n context.actor.factoryAuthored &&\n !requestsChangesVerdict(context.issueComment.body)\n ) {\n return;\n }\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:address-pull-request-comment`,\n role: 'work',\n priority: 'high',\n message:\n `${context.issueComment.author ?? 'Someone'} commented on pull request #${context.pullRequest.number} ` +\n `(${context.issueComment.url ?? context.pullRequest.url}). Read the comment, address it if you agree, and push ` +\n 'the fixes to the PR branch. Reply on GitHub to anything you are deliberately not changing, explaining why.',\n } as const;\n}\n\nfunction pullRequestClosed(context: FactoryGithubRuleContext) {\n if (!context.item || !context.pullRequest || context.pullRequest.merged) return;\n if (context.board !== 'review') return;\n // A PR closed without merging is abandoned review work: clear the card off\n // the board instead of leaving it in Reviewing forever.\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:pull-request-closed`,\n board: 'review',\n stage: 'canceled',\n message: {\n text:\n `Pull request #${context.pullRequest.number} was closed without merging; ` +\n 'this Review card was moved to Canceled.',\n },\n } as const;\n}\n\nfunction reReviewRequestedPullRequest(context: FactoryGithubRuleContext) {\n // GitHub reviewer requests and Factory's exact mention command are both\n // explicit requests to enter the same Review lifecycle.\n const factoryReviewEntry = context.reviewRequest?.factoryReviewer || context.reviewCommand !== undefined;\n if ((context.item && context.board !== 'review') || !factoryReviewEntry) return;\n if (!context.pullRequest || context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // Trusted (write/admin) requesters only: creating or re-entering review checks\n // out and executes PR code, the same bar pullRequestOpened applies to auto-review.\n if (!trustedGithubActor(context)) return;\n if (context.actor.type === 'github' && context.actor.factoryAuthored) return;\n if (!context.item) {\n // On this path the actor is the *requester*, so the materialized\n // `authorTrusted` stamp records their trust (always true past the gate\n // above), not the PR author's: a trusted maintainer requesting a Factory\n // review vouches for the PR.\n return materializePullRequestIntake(context, {\n idempotencyKey: `${context.ingress.id}:pull-request-review-requested-intake`,\n autoStartCandidate: true,\n });\n }\n // Already in Reviewing: a review pass is pending or running; re-entering\n // would be a same-stage no-op anyway (stage rules only fire on change).\n if (context.item.stages.length === 1 && context.item.stages[0] === 'review') return;\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:re-review-requested`,\n board: 'review',\n stage: 'review',\n } as const;\n}\n\nfunction reReviewUpdatedPullRequest(context: FactoryGithubRuleContext) {\n if (!context.item || context.board !== 'review') return;\n if (!context.pullRequest || context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // Intake has not started a review pass yet, so a push there is just more of\n // the code the first pass will read. A push to a card sitting in Reviewing is\n // different: it invalidates whatever that pass is reading, so re-enter the\n // stage to supersede it. `reviewPullRequest` cancels the stale run and picks\n // the right skill for the entry it sees.\n if (context.item.stages.some(stage => stage === 'intake')) return;\n const alreadyReviewing = context.item.stages.some(stage => stage === 'review');\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:re-review-updated`,\n board: 'review',\n stage: 'review',\n // Re-entry is the point when the card is already Reviewing: the stage's\n // entry rule is what cancels the superseded pass and starts one on the code\n // that just landed.\n ...(alreadyReviewing ? { reenter: true } : {}),\n } as const;\n}\n\nexport const defaultGithubRules = Object.freeze({\n issueOpened: issueOpened,\n issueEdited: retriageGithubIssue,\n issueClosed: issueClosed,\n issueCommentCreated: retriageGithubIssue,\n issueCommentEdited: retriageGithubIssue,\n issueCommentDeleted: retriageGithubIssue,\n pullRequestOpened: pullRequestOpened,\n pullRequestUpdated: reReviewUpdatedPullRequest,\n pullRequestCommentCreated: addressPullRequestComment,\n pullRequestReviewRequested: reReviewRequestedPullRequest,\n pullRequestReviewSubmitted: addressReviewFeedback,\n pullRequestMerged: pullRequestMerged,\n pullRequestClosed: pullRequestClosed,\n} satisfies GithubEventRules);\n\nexport function resolveGithubRules(overrides?: GithubRuleOverrides): GithubEventRules {\n if (overrides !== undefined && (overrides === null || typeof overrides !== 'object' || Array.isArray(overrides))) {\n throw new Error('GitHub rules must be an object.');\n }\n const rules: Record<string, FactoryRuleHandler<FactoryGithubRuleContext> | null> = { ...defaultGithubRules };\n for (const key of Reflect.ownKeys(overrides ?? {})) {\n if (typeof key !== 'string' || !Object.hasOwn(defaultGithubRules, key)) {\n throw new Error(`Unknown GitHub rule event: ${String(key)}.`);\n }\n const handler = overrides?.[key as FactoryGithubEventName];\n if (handler !== undefined && handler !== null && typeof handler !== 'function') {\n throw new Error(`GitHub rule ${key} must be a function, null, or undefined.`);\n }\n if (handler !== undefined) rules[key] = handler;\n }\n return Object.freeze(rules) as GithubEventRules;\n}\n"],"mappings":";AASA,SAAS,mBAAmB,SAA2D;CACrF,OAAO,QAAQ,MAAM,SAAS,YAAY,QAAQ,MAAM;AAC1D;AAEA,SAAS,iBAAiB,SAAsE;CAC9F,OAAO,QAAQ,MAAM,SAAS,WAAW,QAAQ,MAAM,QAAQ,KAAA;AACjE;AAEA,SAAS,oBAAoB,SAAmC;CAC9D,IAAI,CAAC,QAAQ,QAAQ,QAAQ,KAAK,WAAW,kBAAkB,CAAC,QAAQ,KAAK,KAAK;CAClF,IAAI,QAAQ,MAAM,SAAS,YAAY,QAAQ,MAAM,iBAAiB;CAEtE,MAAM,SACJ,QAAQ,UAAU,gBACd,QAAQ,aAAa,SAAS,QAAQ,YAAY,OAChD,gCACA,QAAQ,aAAa,QACnB,uBACA,sBACJ,QAAQ,UAAU,wBAChB,oBACA,QAAQ,UAAU,uBAChB,mBACA;CACV,OAAO;EACL,MAAM;EACN,gBAAgB,GAAG,QAAQ,QAAQ,GAAG;EACtC,MAAM;EACN,WAAW;EACX,WAAW,2BAA2B,QAAQ,K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E,IAAI,YAAY,KAAA,GAAW,MAAM,OAAO;CAC1C;CACA,OAAO,OAAO,OAAO,KAAK;AAC5B"}
1
+ {"version":3,"file":"default-rules.js","names":[],"sources":["../../../src/integrations/github/default-rules.ts"],"sourcesContent":["import type { FactoryGithubEventName, FactoryGithubRuleContext, FactoryRuleHandler } from '../../rules/types.js';\n\nexport type GithubRuleOverrides = Partial<\n Record<FactoryGithubEventName, FactoryRuleHandler<FactoryGithubRuleContext> | null | undefined>\n>;\nexport type GithubEventRules = Readonly<\n Record<FactoryGithubEventName, FactoryRuleHandler<FactoryGithubRuleContext> | null>\n>;\n\nfunction trustedGithubActor(context: Pick<FactoryGithubRuleContext, 'actor'>): boolean {\n return context.actor.type === 'github' && context.actor.trusted;\n}\n\nfunction githubActorLogin(context: Pick<FactoryGithubRuleContext, 'actor'>): string | undefined {\n return context.actor.type === 'github' ? context.actor.login : undefined;\n}\n\nfunction retriageGithubIssue(context: FactoryGithubRuleContext) {\n if (!context.item || context.item.source !== 'github-issue' || !context.item.url) return;\n if (context.actor.type === 'github' && context.actor.factoryAuthored) return;\n\n const reason =\n context.event === 'issueEdited'\n ? context.issueChange?.title && context.issueChange.body\n ? 'issue title and body edited'\n : context.issueChange?.title\n ? 'issue title edited'\n : 'issue body edited'\n : context.event === 'issueCommentDeleted'\n ? 'comment deleted'\n : context.event === 'issueCommentEdited'\n ? 'comment edited'\n : 'comment created';\n return {\n type: 'invokeSkill',\n idempotencyKey: `${context.ingress.id}:factory-triage`,\n role: 'triage',\n skillName: 'factory-triage',\n arguments: `Re-triage GitHub issue (${context.item.url}) after ${reason}.`,\n } as const;\n}\n\nfunction createdAfterFactory(createdAt: string | undefined, factoryCreatedAt: string): boolean {\n if (!createdAt) return false;\n const sourceCreatedAt = Date.parse(createdAt);\n const projectCreatedAt = Date.parse(factoryCreatedAt);\n return Number.isFinite(sourceCreatedAt) && Number.isFinite(projectCreatedAt) && sourceCreatedAt > projectCreatedAt;\n}\n\nfunction issueOpened(context: FactoryGithubRuleContext) {\n if (!context.issue) return;\n // Everything arrives on the routed board's initial phase (Work › Intake when\n // no label route selects another board); arrival only stamps whether\n // `onArrival` may suggest this card's run without a person.\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey: `${context.ingress.id}:issue-intake`,\n board: context.intake?.board ?? 'work',\n source: 'github-issue',\n sourceKey: `github-issue:${context.issue.number}`,\n title: context.issue.title,\n url: context.issue.url,\n stage: context.intake?.initialPhase ?? 'intake',\n metadata: {\n githubRepositoryId: context.repository.id,\n githubIssueNumber: context.issue.number,\n ...(context.issue.createdAt ? { sourceCreatedAt: context.issue.createdAt } : {}),\n ...(githubActorLogin(context) ? { author: githubActorLogin(context) } : {}),\n authorTrusted: trustedGithubActor(context),\n autoStartCandidate:\n trustedGithubActor(context) && createdAfterFactory(context.issue.createdAt, context.factory.createdAt),\n assignees: context.issue.assignees ?? [],\n labels: context.issue.labels ?? [],\n },\n } as const;\n}\n\nfunction issueClosed(context: FactoryGithubRuleContext) {\n if (!context.item || context.item.source !== 'github-issue' || !context.issue) return;\n if (context.board !== 'work') return;\n // Already off the board: nothing to reconcile.\n if (context.item.stages.some(stage => stage === 'done' || stage === 'canceled')) return;\n // Issue closure is a repository fact, not third-party input — no actor trust\n // gate. `not_planned` (and `duplicate`) means abandoned, everything else is\n // completed work.\n const canceled = context.issue.stateReason === 'not_planned' || context.issue.stateReason === 'duplicate';\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:issue-closed`,\n board: 'work',\n stage: canceled ? 'canceled' : 'done',\n message: {\n text:\n `GitHub issue #${context.issue.number} was closed` +\n `${context.issue.stateReason ? ` (${context.issue.stateReason})` : ''}; ` +\n `this Work card was moved to ${canceled ? 'Canceled' : 'Done'}.`,\n },\n } as const;\n}\n\nfunction materializePullRequestIntake(\n context: FactoryGithubRuleContext,\n { idempotencyKey, autoStartCandidate }: { idempotencyKey: string; autoStartCandidate: boolean },\n) {\n if (!context.pullRequest) return;\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey,\n board: 'review',\n source: 'github-pr',\n sourceKey: `github-pr:${context.pullRequest.number}`,\n title: context.pullRequest.title,\n url: context.pullRequest.url,\n stage: 'intake',\n metadata: {\n githubRepositoryId: context.repository.id,\n githubPullRequestNumber: context.pullRequest.number,\n ...(context.pullRequest.createdAt ? { sourceCreatedAt: context.pullRequest.createdAt } : {}),\n factoryAuthored: context.pullRequest.factoryAuthored,\n authorTrusted: trustedGithubActor(context),\n autoStartCandidate,\n state: context.pullRequest.state,\n draft: context.pullRequest.draft,\n merged: context.pullRequest.merged,\n assignees: context.pullRequest.assignees ?? [],\n requestedReviewers: context.pullRequest.requestedReviewers ?? [],\n labels: context.pullRequest.labels ?? [],\n headBranch: context.pullRequest.headBranch,\n baseBranch: context.pullRequest.baseBranch,\n ...(context.pullRequest.author ? { author: context.pullRequest.author } : {}),\n },\n } as const;\n}\n\nfunction pullRequestOpened(context: FactoryGithubRuleContext) {\n if (!context.pullRequest) return;\n // A GitHub App bot is never a collaborator, so Factory's own PRs score\n // untrusted; their authorship is the trust signal.\n const autoStartCandidate =\n (trustedGithubActor(context) || context.pullRequest.factoryAuthored) &&\n createdAfterFactory(context.pullRequest.createdAt, context.factory.createdAt);\n return materializePullRequestIntake(context, {\n idempotencyKey: `${context.ingress.id}:pull-request-intake`,\n autoStartCandidate,\n });\n}\n\nfunction pullRequestMerged(context: FactoryGithubRuleContext) {\n if (!context.item || !context.pullRequest?.merged) return;\n if (context.board === 'review') {\n // The event is bound to the PR's own Review card: a merged PR is finished\n // review work, so always move the card to Done. The message only reaches\n // an active session (if any) — cards without one just move, instead of\n // failing retries against a binding that never existed.\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:pull-request-merged`,\n board: 'review',\n stage: 'done',\n message: {\n text:\n `Pull request #${context.pullRequest.number} merged; this Review card was moved to Done. ` +\n 'No further review is needed unless follow-up work was requested.',\n },\n } as const;\n }\n // Provenance bound the event to the originating Work item instead: remind\n // its agent to assess completion — never auto-complete the Work item.\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:assess-work-completion`,\n role: 'work',\n message:\n `Pull request #${context.pullRequest.number} merged. Assess whether the linked Work item is complete. ` +\n 'Do not mark it Done solely because this PR merged; use factory_transition_work_item only after verifying the work.',\n } as const;\n}\n\nfunction addressReviewFeedback(context: FactoryGithubRuleContext) {\n if (!context.item || !context.pullRequest || !context.review) return;\n // Only the Work item that authored the PR can act on the feedback. Provenance\n // binds the event there; a Review card seeing its own posted review must not\n // react to it (that would loop the reviewer against itself).\n if (context.board !== 'work') return;\n // A closed or merged pull request has no branch left to push fixes to.\n if (context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // `approved` needs no work, and `commented` (a review body with no verdict)\n // is how a reviewer leaves notes without blocking — only a verdict that asks\n // for changes should pull the author back in.\n if (context.review.state.toLowerCase() !== 'changes_requested') return;\n // The authoring thread is already subscribed to this PR (`gh pr create`\n // subscribes automatically), so it can read the individual line comments\n // from its own notification inbox — the message only has to wake it and\n // point at the review.\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:address-review-feedback`,\n role: 'work',\n priority: 'high',\n message:\n `Changes were requested on pull request #${context.pullRequest.number} (${context.review.url}). ` +\n 'Read the review comments on this PR, address the ones you agree with, and push the fixes to the PR branch. ' +\n 'Reply on GitHub to anything you are deliberately not changing, explaining why.',\n } as const;\n}\n\n/**\n * Detects the `factory-review` handoff verdict in a comment body.\n *\n * GitHub forbids an app from reviewing a pull request it authored, so on\n * Factory-authored PRs the review skill falls back to posting its verdict as a\n * plain comment. That comment is the only signal the authoring agent gets, so\n * it has to be readable back out. The skill's handoff contract puts the verdict\n * on the first line (`Verdict: request changes`), so only that line is\n * inspected — a verdict quoted later in the findings must not count.\n */\nfunction requestsChangesVerdict(body: string | undefined): boolean {\n const firstLine = body\n ?.split('\\n')\n .map(line => line.trim())\n .find(line => line.length > 0);\n if (!firstLine) return false;\n // Tolerate the markdown the skill wraps the line in (`**Verdict: ...**`).\n const normalized = firstLine\n .replaceAll(/[*_`#>\\s]+/g, ' ')\n .trim()\n .toLowerCase();\n // Match the verdict exactly so negated phrasings (\"Verdict: do not request\n // changes\") cannot wake the author.\n return /^verdict: ?(request changes|changes requested)$/.test(normalized);\n}\n\nfunction addressPullRequestComment(context: FactoryGithubRuleContext) {\n // A validated Factory mention is a review-entry request, not feedback for the\n // authoring Work session. Invalid or unrecognized comments retain the normal\n // feedback route below.\n if (context.reviewCommand) return reReviewRequestedPullRequest(context);\n if (!context.item || !context.pullRequest || !context.issueComment) return;\n // Provenance binds the comment to the Work item that authored the PR — the\n // only session that can act on it. A Review card must not react to comments\n // on the PR it is reviewing.\n if (context.board !== 'work') return;\n if (context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // `factoryAuthored` is one bit for the whole Factory, so Factory's own\n // comments are indistinguishable between roles — waking on all of them would\n // let the Work agent's own progress comments wake itself in a loop. The one\n // exception is the review verdict the Review run had to post as a comment\n // because GitHub refused a self-review: that is the handoff, and it only ever\n // asks for changes once per review, so it cannot sustain a loop.\n if (\n context.actor.type === 'github' &&\n context.actor.factoryAuthored &&\n !requestsChangesVerdict(context.issueComment.body)\n ) {\n return;\n }\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:address-pull-request-comment`,\n role: 'work',\n priority: 'high',\n message:\n `${context.issueComment.author ?? 'Someone'} commented on pull request #${context.pullRequest.number} ` +\n `(${context.issueComment.url ?? context.pullRequest.url}). Read the comment, address it if you agree, and push ` +\n 'the fixes to the PR branch. Reply on GitHub to anything you are deliberately not changing, explaining why.',\n } as const;\n}\n\nfunction pullRequestClosed(context: FactoryGithubRuleContext) {\n if (!context.item || !context.pullRequest || context.pullRequest.merged) return;\n if (context.board !== 'review') return;\n // A PR closed without merging is abandoned review work: clear the card off\n // the board instead of leaving it in Reviewing forever.\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:pull-request-closed`,\n board: 'review',\n stage: 'canceled',\n message: {\n text:\n `Pull request #${context.pullRequest.number} was closed without merging; ` +\n 'this Review card was moved to Canceled.',\n },\n } as const;\n}\n\nfunction reReviewRequestedPullRequest(context: FactoryGithubRuleContext) {\n // GitHub reviewer requests and Factory's exact mention command are both\n // explicit requests to enter the same Review lifecycle.\n const factoryReviewEntry = context.reviewRequest?.factoryReviewer || context.reviewCommand !== undefined;\n if ((context.item && context.board !== 'review') || !factoryReviewEntry) return;\n if (!context.pullRequest || context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // Trusted (write/admin) requesters only: creating or re-entering review checks\n // out and executes PR code, the same bar pullRequestOpened applies to auto-review.\n if (!trustedGithubActor(context)) return;\n if (context.actor.type === 'github' && context.actor.factoryAuthored) return;\n if (!context.item) {\n // On this path the actor is the *requester*, so the materialized\n // `authorTrusted` stamp records their trust (always true past the gate\n // above), not the PR author's: a trusted maintainer requesting a Factory\n // review vouches for the PR.\n return materializePullRequestIntake(context, {\n idempotencyKey: `${context.ingress.id}:pull-request-review-requested-intake`,\n autoStartCandidate: true,\n });\n }\n // Already in Reviewing: a review pass is pending or running; re-entering\n // would be a same-stage no-op anyway (stage rules only fire on change).\n if (context.item.stages.length === 1 && context.item.stages[0] === 'review') return;\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:re-review-requested`,\n board: 'review',\n stage: 'review',\n } as const;\n}\n\nfunction reReviewUpdatedPullRequest(context: FactoryGithubRuleContext) {\n if (!context.item || context.board !== 'review') return;\n if (!context.pullRequest || context.pullRequest.state !== 'open' || context.pullRequest.merged) return;\n // Intake has not started a review pass yet, so a push there is just more of\n // the code the first pass will read. A push to a card sitting in Reviewing is\n // different: it invalidates whatever that pass is reading, so re-enter the\n // stage to supersede it. `reviewPullRequest` cancels the stale run and picks\n // the right skill for the entry it sees.\n if (context.item.stages.some(stage => stage === 'intake')) return;\n const alreadyReviewing = context.item.stages.some(stage => stage === 'review');\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:re-review-updated`,\n board: 'review',\n stage: 'review',\n // Re-entry is the point when the card is already Reviewing: the stage's\n // entry rule is what cancels the superseded pass and starts one on the code\n // that just landed.\n ...(alreadyReviewing ? { reenter: true } : {}),\n } as const;\n}\n\nexport const defaultGithubRules = Object.freeze({\n issueOpened: issueOpened,\n issueEdited: retriageGithubIssue,\n issueClosed: issueClosed,\n issueCommentCreated: retriageGithubIssue,\n issueCommentEdited: retriageGithubIssue,\n issueCommentDeleted: retriageGithubIssue,\n pullRequestOpened: pullRequestOpened,\n pullRequestUpdated: reReviewUpdatedPullRequest,\n pullRequestCommentCreated: addressPullRequestComment,\n pullRequestReviewRequested: reReviewRequestedPullRequest,\n pullRequestReviewSubmitted: addressReviewFeedback,\n pullRequestMerged: pullRequestMerged,\n pullRequestClosed: pullRequestClosed,\n} satisfies GithubEventRules);\n\nexport function resolveGithubRules(overrides?: GithubRuleOverrides): GithubEventRules {\n if (overrides !== undefined && (overrides === null || typeof overrides !== 'object' || Array.isArray(overrides))) {\n throw new Error('GitHub rules must be an object.');\n }\n const rules: Record<string, FactoryRuleHandler<FactoryGithubRuleContext> | null> = { ...defaultGithubRules };\n for (const key of Reflect.ownKeys(overrides ?? {})) {\n if (typeof key !== 'string' || !Object.hasOwn(defaultGithubRules, key)) {\n throw new Error(`Unknown GitHub rule event: ${String(key)}.`);\n }\n const handler = overrides?.[key as FactoryGithubEventName];\n if (handler !== undefined && handler !== null && typeof handler !== 'function') {\n throw new Error(`GitHub rule ${key} must be a function, null, or undefined.`);\n }\n if (handler !== undefined) rules[key] = handler;\n }\n return Object.freeze(rules) as GithubEventRules;\n}\n"],"mappings":";AASA,SAAS,mBAAmB,SAA2D;CACrF,OAAO,QAAQ,MAAM,SAAS,YAAY,QAAQ,MAAM;AAC1D;AAEA,SAAS,iBAAiB,SAAsE;CAC9F,OAAO,QAAQ,MAAM,SAAS,WAAW,QAAQ,MAAM,QAAQ,KAAA;AACjE;AAEA,SAAS,oBAAoB,SAAmC;CAC9D,IAAI,CAAC,QAAQ,QAAQ,QA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,QAAQ,OAAO,cAAc,YAAY,MAAM,QAAQ,SAAS,IAC5G,MAAM,IAAI,MAAM,iCAAiC;CAEnD,MAAM,QAA6E,EAAE,GAAG,mBAAmB;CAC3G,KAAK,MAAM,OAAO,QAAQ,QAAQ,aAAa,CAAC,CAAC,GAAG;EAClD,IAAI,OAAO,QAAQ,YAAY,CAAC,OAAO,OAAO,oBAAoB,GAAG,GACnE,MAAM,IAAI,MAAM,8BAA8B,OAAO,GAAG,EAAE,EAAE;EAE9D,MAAM,UAAU,YAAY;EAC5B,IAAI,YAAY,KAAA,KAAa,YAAY,QAAQ,OAAO,YAAY,YAClE,MAAM,IAAI,MAAM,eAAe,IAAI,yCAAyC;EAE9E,IAAI,YAAY,KAAA,GAAW,MAAM,OAAO;CAC1C;CACA,OAAO,OAAO,OAAO,KAAK;AAC5B"}
@@ -1,4 +1,5 @@
1
1
  import type { BoardRegistry } from '../../boards/index.js';
2
+ import type { IntakeStorage } from '../../storage/domains/intake/base.js';
2
3
  import type { IntegrationStorageHandle } from '../../storage/domains/integrations/base.js';
3
4
  import type { FactoryProjectsStorage } from '../../storage/domains/projects/base.js';
4
5
  import type { SourceControlStorageHandle } from '../../storage/domains/source-control/base.js';
@@ -35,6 +36,8 @@ export interface GithubRulesOptions {
35
36
  storage: WorkItemsStorage;
36
37
  configVersion: string;
37
38
  boards: BoardRegistry;
39
+ /** Label routes decide which installed board a labelled issue lands on. Absent means Work. */
40
+ intake?: Pick<IntakeStorage, 'listLabelRoutes'>;
38
41
  }
39
42
  export declare class GithubRules {
40
43
  #private;
@@ -1 +1 @@
1
- {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/rules.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAQ3D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AAC3F,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CA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,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,OAAO,CAM/E;AAyBD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,mBAAmB,GAAG,MAAM,GAAG,SAAS,CAoB9G;AAED,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,mBAAmB,EAC/B,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,mBAAmB,GACzB,mBAAmB,CAuBrB;AAED,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,mBAAmB,EAC/B,iBAAiB,EAAE,MAAM,EACzB,KAAK,EAAE,yBAAyB,GAC/B,mBAAmB,CA2BrB;AAkDD;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAC/C,OAAO,EAAE,kBAAkB,EAC3B,gBAAgB,EAAE,wBAAwB,GACzC,2BAA2B,CAiL7B;AAED,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,kBAAkB,GAC1B,kBAAkB,GAAG,SAAS,CAYhC;AAED,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,kBAAkB,GAC1B,CAAC,CAAC,KAAK,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,SAAS,CAKhE;AAED,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,sBAAsB,EAC9B,OAAO,EAAE,kBAAkB,EAC3B,gBAAgB,EAAE,wBAAwB,GACzC,2BAA2B,GAAG,SAAS,CAIzC"}
@@ -2,7 +2,9 @@ import { assertFactoryDecisionTarget, validateFactoryRuleDecisions } from "../..
2
2
  import { boardForWorkItem, workItemPhaseSemantics } from "../../boards/semantics.js";
3
3
  import "../../boards/index.js";
4
4
  import { changeRequestTargetKey } from "./subscriptions.js";
5
- import { FACTORY_PULL_REQUEST_RECONCILIATION_KEY } from "../../storage/domains/work-items/base.js";
5
+ import { FACTORY_PULL_REQUEST_RECONCILIATION_KEY, WorkItemUpdateConflictError } from "../../storage/domains/work-items/base.js";
6
+ import { cardLabels, moveCardToBoard } from "../../boards/relocate.js";
7
+ import { resolveIntakeLabelRoute } from "../../storage/domains/intake/base.js";
6
8
  //#region src/integrations/github/rules.ts
7
9
  const TRUSTED_PERMISSIONS = /* @__PURE__ */ new Set(["write", "admin"]);
8
10
  const RULE_TIMEOUT_MS = 5e3;
@@ -36,6 +38,9 @@ function actorLogins(value) {
36
38
  return login ? [login] : [];
37
39
  });
38
40
  }
41
+ function sameLabels(a, b) {
42
+ return a.length === b.length && a.every((label, index) => label === b[index]);
43
+ }
39
44
  function labelNames(value) {
40
45
  if (!Array.isArray(value)) return [];
41
46
  return value.flatMap((label) => {
@@ -151,6 +156,12 @@ function pullRequestProvenance(data, factoryProjectId) {
151
156
  workItemId: data.workItemId
152
157
  };
153
158
  }
159
+ /** Identity under which label-driven relocations are recorded. */
160
+ const LABEL_ROUTE_USER_ID = "factory-rule-dispatcher";
161
+ function issueLabelChange(parsed) {
162
+ const action = string(parsed.payload.action);
163
+ return parsed.event === "issues" && (action === "labeled" || action === "unlabeled");
164
+ }
154
165
  var GithubRules = class {
155
166
  options;
156
167
  constructor(options) {
@@ -175,21 +186,84 @@ var GithubRules = class {
175
186
  const slug = this.options.github.slug?.trim();
176
187
  return slug ? `${slug.toLowerCase()}[bot]` : void 0;
177
188
  }
189
+ /**
190
+ * Board an issue's labels select under the project's label routes, when that board is installed.
191
+ * Undefined leaves built-in routing (Work) in charge.
192
+ */
193
+ async #labelRouteTarget(orgId, factoryProjectId, labels) {
194
+ if (!this.options.intake || labels.length === 0) return void 0;
195
+ const route = resolveIntakeLabelRoute(await this.options.intake.listLabelRoutes({
196
+ orgId,
197
+ factoryProjectId,
198
+ integrationId: "github"
199
+ }), labels);
200
+ const board = route ? this.options.boards.get(route.board) : void 0;
201
+ return board ? {
202
+ board: board.id,
203
+ initialPhase: board.initialPhase
204
+ } : void 0;
205
+ }
206
+ /**
207
+ * `labeled` / `unlabeled` are not rule events: the labels only decide which board the card belongs
208
+ * on, so the card is re-routed here and its label metadata refreshed. Cards a run owns, and
209
+ * finished cards, stay where they are.
210
+ */
211
+ async #relocateLabeledIssue(parsed, repositoryId, repositoryName, project) {
212
+ const issue = object(parsed.payload.issue);
213
+ const issueNumber = issue?.pull_request === void 0 ? number(issue?.number) : void 0;
214
+ if (!issueNumber) return { status: "ignored" };
215
+ const found = await this.#relatedItem(project.orgId, project.factoryProjectId, repositoryId, repositoryName, issueNumber, void 0, void 0, null);
216
+ if (!found || found.externalSource?.type !== "issue") return { status: "ignored" };
217
+ const labels = labelNames(issue?.labels);
218
+ let item = found;
219
+ let changed = false;
220
+ if (!sameLabels(cardLabels(item), labels)) {
221
+ let updated;
222
+ try {
223
+ updated = await this.options.storage.update({
224
+ orgId: item.orgId,
225
+ id: item.id,
226
+ userId: LABEL_ROUTE_USER_ID,
227
+ patch: { metadata: {
228
+ ...item.metadata ?? {},
229
+ labels
230
+ } },
231
+ expectedRevision: item.revision
232
+ });
233
+ } catch (error) {
234
+ if (!(error instanceof WorkItemUpdateConflictError)) throw error;
235
+ return { status: "ignored" };
236
+ }
237
+ if (!updated) return { status: "ignored" };
238
+ item = updated.item;
239
+ changed = true;
240
+ }
241
+ const target = await this.#labelRouteTarget(project.orgId, project.factoryProjectId, labels);
242
+ const outcome = await moveCardToBoard({
243
+ workItems: this.options.storage,
244
+ boardRegistry: this.options.boards,
245
+ userId: LABEL_ROUTE_USER_ID,
246
+ item,
247
+ targetBoard: target?.board ?? "work"
248
+ });
249
+ return { status: changed || outcome === "moved" ? "committed" : "ignored" };
250
+ }
178
251
  async ingest(parsed) {
179
252
  const event = eventName(parsed);
253
+ const labelChange = issueLabelChange(parsed);
180
254
  const repository = object(parsed.payload.repository);
181
255
  const installationId = number(object(parsed.payload.installation)?.id);
182
256
  const repositoryId = number(repository?.id);
183
257
  const repositoryName = string(repository?.full_name);
184
258
  const login = string(object(parsed.payload.sender)?.login);
185
- if (!event || !installationId || !repositoryId || !repositoryName || !login) return { status: "ignored" };
259
+ if (!event && !labelChange || !installationId || !repositoryId || !repositoryName || !login) return { status: "ignored" };
186
260
  const projects = await this.options.sourceControl.projectRepositories.listByExternalRepository({
187
261
  installationExternalId: String(installationId),
188
262
  repositoryExternalId: String(repositoryId)
189
263
  });
190
264
  if (projects.length === 0) return { status: "ignored" };
191
265
  const results = [];
192
- for (const project of projects) results.push(await this.#ingestProject(parsed, event, installationId, repositoryId, repositoryName, login, project));
266
+ for (const project of projects) results.push(event ? await this.#ingestProject(parsed, event, installationId, repositoryId, repositoryName, login, project) : await this.#relocateLabeledIssue(parsed, repositoryId, repositoryName, project));
193
267
  if (results.some((result) => result.status === "committed")) return { status: "committed" };
194
268
  if (results.some((result) => result.status === "replayed")) return { status: "replayed" };
195
269
  return results[0] ?? { status: "ignored" };
@@ -218,6 +292,7 @@ var GithubRules = class {
218
292
  const pullRequestFactoryAuthored = provenance !== null || this.#isFactoryLogin(pullRequestAuthor);
219
293
  const resolvedItem = await this.#relatedItem(project.orgId, project.factoryProjectId, repositoryId, repositoryName, issueNumber, pullRequestNumber, string(object(pullRequest?.head)?.ref), reReviewEvent ? null : provenance, senderIsResponder && !reviewEntryRequested);
220
294
  const relatedItem = reviewEntryRequested && resolvedItem?.externalSource?.type !== "pull-request" ? void 0 : resolvedItem;
295
+ const intake = issueNumber ? await this.#labelRouteTarget(project.orgId, project.factoryProjectId, labelNames(issue?.labels)) : void 0;
221
296
  const actor = await githubActor(this.options.github, {
222
297
  installationId,
223
298
  repository: repositoryName,
@@ -254,6 +329,7 @@ var GithubRules = class {
254
329
  board: boardForWorkItem(item),
255
330
  itemRevision: item.revision
256
331
  } : {},
332
+ ...intake ? { intake } : {},
257
333
  event,
258
334
  deliveryId: parsed.deliveryId,
259
335
  factory: { createdAt: factoryProject.createdAt.toISOString() },
@@ -690,7 +766,8 @@ function githubRulesOptions(github, context) {
690
766
  projects: context.storage.projects,
691
767
  storage: context.runtime.workItems,
692
768
  configVersion: context.runtime.configVersion,
693
- boards: context.runtime.boards
769
+ boards: context.runtime.boards,
770
+ intake: context.storage.intake
694
771
  };
695
772
  }
696
773
  function attachGithubRules(github, context) {