@mastra/factory 0.19.2-alpha.7 → 0.20.0-alpha.10

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 (57) hide show
  1. package/dist/factory.js +7 -7
  2. package/dist/factory.js.map +1 -1
  3. package/dist/integrations/base.d.ts +5 -5
  4. package/dist/integrations/base.d.ts.map +1 -1
  5. package/dist/integrations/github/default-rules.d.ts +4 -4
  6. package/dist/integrations/github/default-rules.d.ts.map +1 -1
  7. package/dist/integrations/github/default-rules.js +13 -2
  8. package/dist/integrations/github/default-rules.js.map +1 -1
  9. package/dist/integrations/github/integration.js +1 -1
  10. package/dist/integrations/github/provenance.d.ts.map +1 -1
  11. package/dist/integrations/github/provenance.js +2 -1
  12. package/dist/integrations/github/provenance.js.map +1 -1
  13. package/dist/integrations/github/routes.d.ts.map +1 -1
  14. package/dist/integrations/github/routes.js +3 -1
  15. package/dist/integrations/github/routes.js.map +1 -1
  16. package/dist/integrations/github/rules.d.ts +8 -0
  17. package/dist/integrations/github/rules.d.ts.map +1 -1
  18. package/dist/integrations/github/rules.js +2 -2
  19. package/dist/integrations/github/rules.js.map +1 -1
  20. package/dist/integrations/github/session-subscriptions.js +1 -1
  21. package/dist/integrations/platform/github/integration.js +1 -1
  22. package/dist/integrations/slack/integration.js +1 -1
  23. package/dist/integrations/slack/integration.js.map +1 -1
  24. package/dist/integrations/slack/slack.d.ts +10 -11
  25. package/dist/integrations/slack/slack.d.ts.map +1 -1
  26. package/dist/integrations/slack/slack.js +36 -37
  27. package/dist/integrations/slack/slack.js.map +1 -1
  28. package/dist/routes/config.d.ts +15 -61
  29. package/dist/routes/config.d.ts.map +1 -1
  30. package/dist/routes/config.js +40 -217
  31. package/dist/routes/config.js.map +1 -1
  32. package/dist/routes/projects.d.ts.map +1 -1
  33. package/dist/routes/projects.js +2 -17
  34. package/dist/routes/projects.js.map +1 -1
  35. package/dist/routes/surface.d.ts +4 -4
  36. package/dist/routes/surface.d.ts.map +1 -1
  37. package/dist/routes/surface.js +3 -3
  38. package/dist/routes/surface.js.map +1 -1
  39. package/dist/session/default-model-hydration.d.ts +40 -0
  40. package/dist/session/default-model-hydration.d.ts.map +1 -0
  41. package/dist/session/default-model-hydration.js +45 -0
  42. package/dist/session/default-model-hydration.js.map +1 -0
  43. package/dist/session/factory-session.js +1 -1
  44. package/dist/session/factory-session.js.map +1 -1
  45. package/dist/storage/domains/model-defaults/base.d.ts +29 -0
  46. package/dist/storage/domains/model-defaults/base.d.ts.map +1 -0
  47. package/dist/storage/domains/model-defaults/base.js +79 -0
  48. package/dist/storage/domains/model-defaults/base.js.map +1 -0
  49. package/package.json +8 -8
  50. package/dist/session/model-pack-hydration.d.ts +0 -55
  51. package/dist/session/model-pack-hydration.d.ts.map +0 -1
  52. package/dist/session/model-pack-hydration.js +0 -56
  53. package/dist/session/model-pack-hydration.js.map +0 -1
  54. package/dist/storage/domains/model-packs/base.d.ts +0 -75
  55. package/dist/storage/domains/model-packs/base.d.ts.map +0 -1
  56. package/dist/storage/domains/model-packs/base.js +0 -185
  57. package/dist/storage/domains/model-packs/base.js.map +0 -1
@@ -13,7 +13,7 @@ declare function issueOpened(context: FactoryGithubRuleContext): {
13
13
  readonly idempotencyKey: `${string}:issue-intake`;
14
14
  readonly board: string;
15
15
  readonly source: "github-issue";
16
- readonly sourceKey: `github-issue:${number}`;
16
+ readonly sourceKey: string;
17
17
  readonly title: string;
18
18
  readonly url: string;
19
19
  readonly stage: string;
@@ -42,7 +42,7 @@ declare function pullRequestOpened(context: FactoryGithubRuleContext): {
42
42
  readonly idempotencyKey: string;
43
43
  readonly board: "review";
44
44
  readonly source: "github-pr";
45
- readonly sourceKey: `github-pr:${number}`;
45
+ readonly sourceKey: string;
46
46
  readonly title: string;
47
47
  readonly url: string;
48
48
  readonly stage: "review" | "intake";
@@ -115,7 +115,7 @@ declare function addressPullRequestComment(context: FactoryGithubRuleContext): {
115
115
  readonly idempotencyKey: string;
116
116
  readonly board: "review";
117
117
  readonly source: "github-pr";
118
- readonly sourceKey: `github-pr:${number}`;
118
+ readonly sourceKey: string;
119
119
  readonly title: string;
120
120
  readonly url: string;
121
121
  readonly stage: "review" | "intake";
@@ -163,7 +163,7 @@ declare function reReviewRequestedPullRequest(context: FactoryGithubRuleContext)
163
163
  readonly idempotencyKey: string;
164
164
  readonly board: "review";
165
165
  readonly source: "github-pr";
166
- readonly sourceKey: `github-pr:${number}`;
166
+ readonly sourceKey: string;
167
167
  readonly title: string;
168
168
  readonly url: string;
169
169
  readonly stage: "review" | "intake";
@@ -1 +1 @@
1
- {"version":3,"file":"default-rules.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/default-rules.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAGjH,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;;;;;;cA4B7D;AASD,iBAAS,WAAW,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;;;;;;;;;;;;cA0BrD;AAED,iBAAS,WAAW,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;cAqBrD;AAwCD,iBAAS,iBAAiB,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8B3D;AAED,iBAAS,iBAAiB,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;cAwC3D;AAmDD,iBAAS,0BAA0B,CAAC,OAAO,EAAE,wBAAwB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AiB,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;cAwC3D;AAmDD,iBAAS,0BAA0B,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;;;;;;;cAEpE;AAqBD,iBAAS,yBAAyB,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAkCnE;AAED,iBAAS,iBAAiB,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;cAgB3D;AAED,iBAAS,4BAA4B,CAAC,OAAO,EAAE,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAiCtE;AAED,iBAAS,0BAA0B,CAAC,OAAO,EAAE,wBAAwB;;;;;;cAuBpE;AAED,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;EAcF,CAAC;AAE9B,wBAAgB,kBAAkB,CAAC,SAAS,CAAC,EAAE,mBAAmB,GAAG,gBAAgB,CAgBpF"}
@@ -30,6 +30,17 @@ function createdAfterFactory(createdAt, factoryCreatedAt) {
30
30
  const projectCreatedAt = Date.parse(factoryCreatedAt);
31
31
  return Number.isFinite(sourceCreatedAt) && Number.isFinite(projectCreatedAt) && sourceCreatedAt > projectCreatedAt;
32
32
  }
33
+ /**
34
+ * Issue and pull request numbers repeat across repositories, so new cards are
35
+ * keyed by repository. A card this repository already owns keeps its key —
36
+ * including canonical `github-issue:N` / `github-pr:N` keys from before
37
+ * scoping — but only when it is the same kind of source: pull request intake
38
+ * runs with the authoring issue as `context.item`.
39
+ */
40
+ function githubSourceKey(context, source, itemNumber) {
41
+ if (context.item?.source === source && context.item.sourceKey) return context.item.sourceKey;
42
+ return `github:${context.repository.id}:${source === "github-issue" ? "issue" : "pull-request"}:${itemNumber}`;
43
+ }
33
44
  function issueOpened(context) {
34
45
  if (!context.issue) return;
35
46
  return {
@@ -37,7 +48,7 @@ function issueOpened(context) {
37
48
  idempotencyKey: `${context.ingress.id}:issue-intake`,
38
49
  board: context.intake?.board ?? "work",
39
50
  source: "github-issue",
40
- sourceKey: `github-issue:${context.issue.number}`,
51
+ sourceKey: githubSourceKey(context, "github-issue", context.issue.number),
41
52
  title: context.issue.title,
42
53
  url: context.issue.url,
43
54
  stage: context.intake?.initialPhase ?? "intake",
@@ -73,7 +84,7 @@ function materializePullRequestIntake(context, { idempotencyKey, autoStartCandid
73
84
  idempotencyKey,
74
85
  board: "review",
75
86
  source: "github-pr",
76
- sourceKey: `github-pr:${context.pullRequest.number}`,
87
+ sourceKey: githubSourceKey(context, "github-pr", context.pullRequest.number),
77
88
  title: context.pullRequest.title,
78
89
  url: context.pullRequest.url,
79
90
  stage,
@@ -1 +1 @@
1
- {"version":3,"file":"default-rules.js","names":[],"sources":["../../../src/integrations/github/default-rules.ts"],"sourcesContent":["import { hasRecordedVerdict } from '../../boards/review.js';\nimport { normalizedVerdictLine } from '../../review-verdict.js';\nimport { isTerminalFactoryRuleStage } from '../../rules/types.js';\nimport type { FactoryGithubEventName, FactoryGithubRuleContext, FactoryRuleHandler } from '../../rules/types.js';\nimport { isFactoryApproveVerdict } from './stale-reviews.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 // Re-triage would take over a card that is being built or reviewed.\n const stage = context.item.stages?.length === 1 ? context.item.stages[0] : undefined;\n if (stage === 'execute' || stage === 'review') return;\n // A finished card has nothing left to triage; talk on a closed issue must not park a run on it.\n if (isTerminalFactoryRuleStage(context.item.stages)) 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). Trust/timing stamps remain available\n // to custom board rules.\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 {\n idempotencyKey,\n autoStartCandidate,\n stage = 'intake',\n }: { idempotencyKey: string; autoStartCandidate: boolean; stage?: 'intake' | 'review' },\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,\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 // Opening a pull request is evaluated once per card it concerns. This rule\n // files the pull request's own Review card, which is the arrival — the\n // evaluation carrying `pullRequestIntake` — so the authoring Work item's own\n // evaluation only moves it out for review: Building means \"no pull request\n // yet\", Review means one is open. The card rests there through every round of\n // feedback — the builder is woken in place — until the merge closes it.\n if (context.item && context.pullRequestIntake !== true) {\n if (context.board !== 'work' || context.pullRequest.state !== 'open') return;\n if (!context.item.stages.includes('execute')) return;\n // Resolution can match a Work item by branch alone, so a fork's pull\n // request must not be able to move it: same bar as auto-starting a review.\n if (!trustedGithubActor(context) && !context.pullRequest.factoryAuthored) return;\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:out-for-review`,\n board: 'work',\n stage: 'review',\n } as const;\n }\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: the merge\n // is what finishes the work, so it closes the Work card alongside its Review card —\n // unless the card has since opened another pull request, which is still out.\n const openPullRequestNumber = context.item.metadata?.openPullRequestNumber;\n if (typeof openPullRequestNumber === 'number' && openPullRequestNumber !== context.pullRequest.number) {\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:work-merged`,\n role: 'work',\n message:\n `Pull request #${context.pullRequest.number} merged. Pull request #${openPullRequestNumber} is still open, ` +\n 'so this Work card stays in Review until it merges.',\n } as const;\n }\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:work-merged`,\n board: 'work',\n stage: 'done',\n message: { text: `Pull request #${context.pullRequest.number} merged; this Work card was moved to Done.` },\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 * A Factory approval does not clear a change request left by a different\n * Factory identity (an earlier reviewer token, say), so GitHub would keep the\n * pull request blocked. Ask the dispatcher to dismiss those superseded reviews.\n */\nfunction dismissStaleFactoryReviews(context: FactoryGithubRuleContext) {\n const { pullRequest, review, repository } = context;\n if (!pullRequest || !review || !review.author || !repository.installationId) return;\n if (review.state.toLowerCase() !== 'approved' || !isFactoryApproveVerdict(review.body)) return;\n if (!pullRequest.factoryAuthored || pullRequest.state !== 'open' || pullRequest.merged) return;\n return {\n type: 'dismissStaleReviews',\n idempotencyKey: `${context.ingress.id}:dismiss-stale-reviews`,\n installationId: repository.installationId,\n repository: repository.fullName,\n pullRequestNumber: pullRequest.number,\n approvingReviewId: String(review.id),\n approvingAuthor: review.author,\n } as const;\n}\n\nfunction pullRequestReviewSubmitted(context: FactoryGithubRuleContext) {\n return addressReviewFeedback(context) ?? dismissStaleFactoryReviews(context);\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 // Tolerate the markdown the skill wraps the line in (`**Verdict: ...**`).\n const normalized = normalizedVerdictLine(body);\n if (!normalized) return false;\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 stage: 'review',\n });\n }\n // Already in Reviewing with no verdict yet: a pass is pending or running.\n // Once a verdict is recorded the card rests in Reviewing, so a fresh request\n // re-enters the stage to start another pass.\n const reviewing = context.item.stages.length === 1 && context.item.stages[0] === 'review';\n if (reviewing && !hasRecordedVerdict(context.item)) return;\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:re-review-requested`,\n board: 'review',\n stage: 'review',\n ...(reviewing ? { reenter: true } : {}),\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 // A fork's author controls its head branch, so an untrusted push must not be\n // able to start review passes on demand; a maintainer can still request one.\n if (!trustedGithubActor(context) && !context.pullRequest.factoryAuthored) 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: pullRequestReviewSubmitted,\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":";;;;;AAaA,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,QAAQ,QAAQ,KAAK,QAAQ,WAAW,IAAI,QAAQ,KAAK,OAAO,KAAK,KAAA;CAC3E,IAAI,UAAU,aAAa,UAAU,UAAU;CAE/C,IAAI,2BAA2B,QAAQ,KAAK,MAAM,GAAG;CAErD,MAAM,SACJ,QAAQ,UAAU,gBACd,QAAQ,aAAa,SAAS,QAAQ,YAAY,OAChD,gCACA,QAAQ,aAAa,QACnB,uBACA,sBACJ,QAAQ,UAAU,wBAChB,oBACA,QAAQ,UAAU,uBAChB,mB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a,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
+ {"version":3,"file":"default-rules.js","names":[],"sources":["../../../src/integrations/github/default-rules.ts"],"sourcesContent":["import { hasRecordedVerdict } from '../../boards/review.js';\nimport { normalizedVerdictLine } from '../../review-verdict.js';\nimport { isTerminalFactoryRuleStage } from '../../rules/types.js';\nimport type { FactoryGithubEventName, FactoryGithubRuleContext, FactoryRuleHandler } from '../../rules/types.js';\nimport { isFactoryApproveVerdict } from './stale-reviews.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 // Re-triage would take over a card that is being built or reviewed.\n const stage = context.item.stages?.length === 1 ? context.item.stages[0] : undefined;\n if (stage === 'execute' || stage === 'review') return;\n // A finished card has nothing left to triage; talk on a closed issue must not park a run on it.\n if (isTerminalFactoryRuleStage(context.item.stages)) 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\n/**\n * Issue and pull request numbers repeat across repositories, so new cards are\n * keyed by repository. A card this repository already owns keeps its key —\n * including canonical `github-issue:N` / `github-pr:N` keys from before\n * scoping — but only when it is the same kind of source: pull request intake\n * runs with the authoring issue as `context.item`.\n */\nfunction githubSourceKey(\n context: FactoryGithubRuleContext,\n source: 'github-issue' | 'github-pr',\n itemNumber: number,\n): string {\n if (context.item?.source === source && context.item.sourceKey) return context.item.sourceKey;\n return `github:${context.repository.id}:${source === 'github-issue' ? 'issue' : 'pull-request'}:${itemNumber}`;\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). Trust/timing stamps remain available\n // to custom board rules.\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey: `${context.ingress.id}:issue-intake`,\n board: context.intake?.board ?? 'work',\n source: 'github-issue',\n sourceKey: githubSourceKey(context, '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 {\n idempotencyKey,\n autoStartCandidate,\n stage = 'intake',\n }: { idempotencyKey: string; autoStartCandidate: boolean; stage?: 'intake' | 'review' },\n) {\n if (!context.pullRequest) return;\n return {\n type: 'upsertLinkedWorkItem',\n idempotencyKey,\n board: 'review',\n source: 'github-pr',\n sourceKey: githubSourceKey(context, 'github-pr', context.pullRequest.number),\n title: context.pullRequest.title,\n url: context.pullRequest.url,\n stage,\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 // Opening a pull request is evaluated once per card it concerns. This rule\n // files the pull request's own Review card, which is the arrival — the\n // evaluation carrying `pullRequestIntake` — so the authoring Work item's own\n // evaluation only moves it out for review: Building means \"no pull request\n // yet\", Review means one is open. The card rests there through every round of\n // feedback — the builder is woken in place — until the merge closes it.\n if (context.item && context.pullRequestIntake !== true) {\n if (context.board !== 'work' || context.pullRequest.state !== 'open') return;\n if (!context.item.stages.includes('execute')) return;\n // Resolution can match a Work item by branch alone, so a fork's pull\n // request must not be able to move it: same bar as auto-starting a review.\n if (!trustedGithubActor(context) && !context.pullRequest.factoryAuthored) return;\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:out-for-review`,\n board: 'work',\n stage: 'review',\n } as const;\n }\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: the merge\n // is what finishes the work, so it closes the Work card alongside its Review card —\n // unless the card has since opened another pull request, which is still out.\n const openPullRequestNumber = context.item.metadata?.openPullRequestNumber;\n if (typeof openPullRequestNumber === 'number' && openPullRequestNumber !== context.pullRequest.number) {\n return {\n type: 'sendMessage',\n idempotencyKey: `${context.ingress.id}:work-merged`,\n role: 'work',\n message:\n `Pull request #${context.pullRequest.number} merged. Pull request #${openPullRequestNumber} is still open, ` +\n 'so this Work card stays in Review until it merges.',\n } as const;\n }\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:work-merged`,\n board: 'work',\n stage: 'done',\n message: { text: `Pull request #${context.pullRequest.number} merged; this Work card was moved to Done.` },\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 * A Factory approval does not clear a change request left by a different\n * Factory identity (an earlier reviewer token, say), so GitHub would keep the\n * pull request blocked. Ask the dispatcher to dismiss those superseded reviews.\n */\nfunction dismissStaleFactoryReviews(context: FactoryGithubRuleContext) {\n const { pullRequest, review, repository } = context;\n if (!pullRequest || !review || !review.author || !repository.installationId) return;\n if (review.state.toLowerCase() !== 'approved' || !isFactoryApproveVerdict(review.body)) return;\n if (!pullRequest.factoryAuthored || pullRequest.state !== 'open' || pullRequest.merged) return;\n return {\n type: 'dismissStaleReviews',\n idempotencyKey: `${context.ingress.id}:dismiss-stale-reviews`,\n installationId: repository.installationId,\n repository: repository.fullName,\n pullRequestNumber: pullRequest.number,\n approvingReviewId: String(review.id),\n approvingAuthor: review.author,\n } as const;\n}\n\nfunction pullRequestReviewSubmitted(context: FactoryGithubRuleContext) {\n return addressReviewFeedback(context) ?? dismissStaleFactoryReviews(context);\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 // Tolerate the markdown the skill wraps the line in (`**Verdict: ...**`).\n const normalized = normalizedVerdictLine(body);\n if (!normalized) return false;\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 stage: 'review',\n });\n }\n // Already in Reviewing with no verdict yet: a pass is pending or running.\n // Once a verdict is recorded the card rests in Reviewing, so a fresh request\n // re-enters the stage to start another pass.\n const reviewing = context.item.stages.length === 1 && context.item.stages[0] === 'review';\n if (reviewing && !hasRecordedVerdict(context.item)) return;\n return {\n type: 'transition',\n idempotencyKey: `${context.ingress.id}:re-review-requested`,\n board: 'review',\n stage: 'review',\n ...(reviewing ? { reenter: true } : {}),\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 // A fork's author controls its head branch, so an untrusted push must not be\n // able to start review passes on demand; a maintainer can still request one.\n if (!trustedGithubActor(context) && !context.pullRequest.factoryAuthored) 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: pullRequestReviewSubmitted,\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":";;;;;AAaA,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,QAAQ,QAAQ,KAAK,QAAQ,WAAW,IAAI,QAAQ,KAAK,OAAO,KAAK,KAAA;CAC3E,IAAI,UAAU,aAAa,UAAU,UAAU;CAE/C,IAAI,2BAA2B,QAAQ,KAAK,MAAM,GAAG;CAErD,MAAM,SACJ,QAAQ,UAAU,gBACd,QAAQ,aAAa,SAAS,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,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,5 +1,5 @@
1
- import { createGithubSubscriptionTools, parseCreatedPullRequest, subscribeCurrentSessionToPullRequest } from "./session-subscriptions.js";
2
1
  import { attachGithubReconciler, attachGithubRules } from "./rules.js";
2
+ import { createGithubSubscriptionTools, parseCreatedPullRequest, subscribeCurrentSessionToPullRequest } from "./session-subscriptions.js";
3
3
  import { resolveGithubRules } from "./default-rules.js";
4
4
  import { attachGithubIssueReconciler } from "./issue-reconciler.js";
5
5
  import { reconcileInterval, reconciliationEnabled } from "./reconciliation-config.js";
@@ -1 +1 @@
1
- {"version":3,"file":"provenance.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/provenance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AAC3F,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,8CAA8C,CAAC;AAC/F,OAAO,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAC;AACvH,OAAO,KAAK,EAAE,iBAAiB,EAAE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gC,CACjC,EACD,KAAK,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,gBAAgB,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,GAClG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAYxB;AAED,wBAAsB,kCAAkC,CACtD,MAAM,EAAE,iBAAiB,EACzB,aAAa,EAAE,0BAA0B,EACzC,kBAAkB,EAAE,wBAAwB,CAC1C,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvB,gCAAgC,CACjC,EACD,SAAS,EAAE,gBAAgB,EAC3B,KAAK,EAAE,uCAAuC,GAC7C,OAAO,CAAC,IAAI,CAAC,CA2Gf"}
@@ -1,3 +1,4 @@
1
+ import { cardBelongsToRepository } from "./rules.js";
1
2
  import { parseCreatedPullRequest } from "./session-subscriptions.js";
2
3
  //#region src/integrations/github/provenance.ts
3
4
  async function resolveFactoryPullRequestParentWorkItemId(integrationStorage, input) {
@@ -73,7 +74,7 @@ async function recordFactoryPullRequestProvenance(github, sourceControl, integra
73
74
  const reviewItem = (await workItems.list({
74
75
  orgId: input.binding.orgId,
75
76
  factoryProjectId: input.binding.factoryProjectId
76
- })).find((item) => item.externalSource?.integrationId === "github" && item.externalSource.type === "pull-request" && (item.externalSource.externalId === `github-pr:${pullRequestNumber}` || item.externalSource.externalId === `github:${repositoryId}:pull-request:${pullRequestNumber}`));
77
+ })).find((item) => item.externalSource?.integrationId === "github" && item.externalSource.type === "pull-request" && (item.externalSource.externalId === `github:${repositoryId}:pull-request:${pullRequestNumber}` || item.externalSource.externalId === `github-pr:${pullRequestNumber}` && cardBelongsToRepository(item, repositoryId, repositorySlug)));
77
78
  if (reviewItem) await workItems.setParentWorkItemIfMissing({
78
79
  orgId: input.binding.orgId,
79
80
  id: reviewItem.id,
@@ -1 +1 @@
1
- {"version":3,"file":"provenance.js","names":[],"sources":["../../../src/integrations/github/provenance.ts"],"sourcesContent":["import type { FactoryRuleJsonValue } from '../../rules/types.js';\nimport type { IntegrationStorageHandle } from '../../storage/domains/integrations/base.js';\nimport type { SourceControlStorageHandle } from '../../storage/domains/source-control/base.js';\nimport type { FactoryRunBindingRecord, WorkItemRow, WorkItemsStorage } from '../../storage/domains/work-items/base.js';\nimport type { GithubIntegration } from './integration.js';\nimport { parseCreatedPullRequest } from './session-subscriptions.js';\n\nexport interface RecordFactoryPullRequestProvenanceInput {\n binding: FactoryRunBindingRecord;\n item: WorkItemRow;\n assistantMessageId: string;\n toolCallId: string;\n toolName: string;\n toolInput: FactoryRuleJsonValue;\n toolResult: FactoryRuleJsonValue;\n status: 'success' | 'error';\n}\n\nexport interface FactoryPullRequestProvenanceData {\n kind: 'factory-pr-provenance';\n bindingId: string;\n workItemId: string;\n factoryProjectId: string;\n repositoryId: number;\n pullRequestNumber: number;\n pullRequestUrl: string;\n assistantMessageId: string;\n toolCallId: string;\n}\n\nexport async function resolveFactoryPullRequestParentWorkItemId(\n integrationStorage: IntegrationStorageHandle<\n Record<string, unknown>,\n Record<string, unknown>,\n FactoryPullRequestProvenanceData\n >,\n input: { orgId: string; factoryProjectId: string; repositoryId: number; pullRequestNumber: number },\n): Promise<string | null> {\n const targetKey = `factory-pr-provenance:${input.repositoryId}:${input.pullRequestNumber}`;\n // Provenance is scoped to the Factory project whose run authored the PR.\n // Rows from a sibling project in the same org — or legacy rows without the\n // project stamp — fail closed rather than linking another project's card.\n const provenance = (await integrationStorage.subscriptions.listByTarget(targetKey, { status: 'active' })).find(\n row =>\n row.orgId === input.orgId &&\n row.data?.kind === 'factory-pr-provenance' &&\n row.data.factoryProjectId === input.factoryProjectId,\n );\n return provenance?.data?.workItemId ?? null;\n}\n\nexport async function recordFactoryPullRequestProvenance(\n github: GithubIntegration,\n sourceControl: SourceControlStorageHandle,\n integrationStorage: IntegrationStorageHandle<\n Record<string, unknown>,\n Record<string, unknown>,\n FactoryPullRequestProvenanceData\n >,\n workItems: WorkItemsStorage,\n input: RecordFactoryPullRequestProvenanceInput,\n): Promise<void> {\n if (input.status !== 'success' || input.item.externalSource?.type === 'pull-request') return;\n const url = parseCreatedPullRequest({\n toolName: input.toolName,\n input: input.toolInput,\n output: input.toolResult,\n });\n if (!url) return;\n\n try {\n const match = url.match(/^https:\\/\\/github\\.com\\/([^/]+\\/[^/]+)\\/pull\\/(\\d+)\\/?$/i);\n if (!match) return;\n const repositorySlug = match[1]!;\n let repositoryId: number | undefined;\n let installationId: number | undefined;\n for (const connection of await sourceControl.connections.list({\n orgId: input.binding.orgId,\n factoryProjectId: input.binding.factoryProjectId,\n })) {\n const installation = await sourceControl.installations.get({\n orgId: input.binding.orgId,\n id: connection.installationId,\n });\n if (!installation) continue;\n for (const link of await sourceControl.projectRepositories.list({\n orgId: input.binding.orgId,\n connectionId: connection.id,\n })) {\n const repository = await sourceControl.repositories.get({ orgId: input.binding.orgId, id: link.repositoryId });\n if (!repository || repository.slug.toLowerCase() !== repositorySlug.toLowerCase()) continue;\n repositoryId = Number(repository.externalId);\n installationId = Number(installation.externalId);\n break;\n }\n if (repositoryId !== undefined) break;\n }\n const pullRequestNumber = Number(match[2]);\n const [owner, repo] = repositorySlug.split('/');\n if (\n !owner ||\n !repo ||\n repositoryId === undefined ||\n installationId === undefined ||\n !Number.isInteger(repositoryId) ||\n !Number.isInteger(installationId) ||\n !Number.isInteger(pullRequestNumber) ||\n pullRequestNumber < 1\n )\n return;\n const targetKey = `factory-pr-provenance:${repositoryId}:${pullRequestNumber}`;\n // Dedupe within the authoring project only: a sibling project's row must\n // not block this project from recording its own provenance.\n if (\n (await integrationStorage.subscriptions.listByTarget(targetKey)).some(\n row => row.orgId === input.binding.orgId && row.data?.factoryProjectId === input.binding.factoryProjectId,\n )\n ) {\n return;\n }\n\n const { data } = await github\n .getInstallationOctokit(installationId)\n .pulls.get({ owner, repo, pull_number: pullRequestNumber });\n if (data.base.repo.id !== repositoryId || data.number !== pullRequestNumber || data.html_url !== url) return;\n\n await integrationStorage.subscriptions.create({\n orgId: input.binding.orgId,\n targetKey,\n threadId: input.binding.threadId,\n status: 'active',\n data: {\n kind: 'factory-pr-provenance',\n bindingId: input.binding.id,\n workItemId: input.item.id,\n factoryProjectId: input.binding.factoryProjectId,\n repositoryId,\n pullRequestNumber,\n pullRequestUrl: url,\n assistantMessageId: input.assistantMessageId,\n toolCallId: input.toolCallId,\n },\n });\n\n const reviewItem = (\n await workItems.list({\n orgId: input.binding.orgId,\n factoryProjectId: input.binding.factoryProjectId,\n })\n ).find(\n item =>\n item.externalSource?.integrationId === 'github' &&\n item.externalSource.type === 'pull-request' &&\n (item.externalSource.externalId === `github-pr:${pullRequestNumber}` ||\n item.externalSource.externalId === `github:${repositoryId}:pull-request:${pullRequestNumber}`),\n );\n if (reviewItem) {\n await workItems.setParentWorkItemIfMissing({\n orgId: input.binding.orgId,\n id: reviewItem.id,\n userId: 'factory-pr-provenance',\n parentWorkItemId: input.item.id,\n });\n }\n } catch {\n return;\n }\n}\n"],"mappings":";;AA8BA,eAAsB,0CACpB,oBAKA,OACwB;CACxB,MAAM,YAAY,yBAAyB,MAAM,aAAa,GAAG,MAAM;CAUvE,QANoB,MAAM,mBAAmB,cAAc,aAAa,WAAW,EAAE,QAAQ,SAAS,CAAC,EAAA,CAAG,MACxG,QACE,IAAI,UAAU,MAAM,SACpB,IAAI,MAAM,SAAS,2BACnB,IAAI,KAAK,qBAAqB,MAAM,gBAExB,CAAC,EAAE,MAAM,cAAc;AACzC;AAEA,eAAsB,mCACpB,QACA,eACA,oBAKA,WACA,OACe;CACf,IAAI,MAAM,WAAW,aAAa,MAAM,KAAK,gBAAgB,SAAS,gBAAgB;CACtF,MAAM,MAAM,wBAAwB;EAClC,UAAU,MAAM;EAChB,OAAO,MAAM;EACb,QAAQ,MAAM;CAChB,CAAC;CACD,IAAI,CAAC,KAAK;CAEV,IAAI;EACF,MAAM,QAAQ,IAAI,MAAM,0DAA0D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M,IAAI;GAAE;GAAO;GAAM,aAAa;EAAkB,CAAC;EAC5D,IAAI,KAAK,KAAK,KAAK,OAAO,gBAAgB,KAAK,WAAW,qBAAqB,KAAK,aAAa,KAAK;EAEtG,MAAM,mBAAmB,cAAc,OAAO;GAC5C,OAAO,MAAM,QAAQ;GACrB;GACA,UAAU,MAAM,QAAQ;GACxB,QAAQ;GACR,MAAM;IACJ,MAAM;IACN,WAAW,MAAM,QAAQ;IACzB,YAAY,MAAM,KAAK;IACvB,kBAAkB,MAAM,QAAQ;IAChC;IACA;IACA,gBAAgB;IAChB,oBAAoB,MAAM;IAC1B,YAAY,MAAM;GACpB;EACF,CAAC;EAED,MAAM,cACJ,MAAM,UAAU,KAAK;GACnB,OAAO,MAAM,QAAQ;GACrB,kBAAkB,MAAM,QAAQ;EAClC,CAAC,EAAA,CACD,MACA,SACE,KAAK,gBAAgB,kBAAkB,YACvC,KAAK,eAAe,SAAS,mBAC5B,KAAK,eAAe,eAAe,aAAa,uBAC/C,KAAK,eAAe,eAAe,UAAU,aAAa,gBAAgB,oBAChF;EACA,IAAI,YACF,MAAM,UAAU,2BAA2B;GACzC,OAAO,MAAM,QAAQ;GACrB,IAAI,WAAW;GACf,QAAQ;GACR,kBAAkB,MAAM,KAAK;EAC/B,CAAC;CAEL,QAAQ;EACN;CACF;AACF"}
1
+ {"version":3,"file":"provenance.js","names":[],"sources":["../../../src/integrations/github/provenance.ts"],"sourcesContent":["import type { FactoryRuleJsonValue } from '../../rules/types.js';\nimport type { IntegrationStorageHandle } from '../../storage/domains/integrations/base.js';\nimport type { SourceControlStorageHandle } from '../../storage/domains/source-control/base.js';\nimport type { FactoryRunBindingRecord, WorkItemRow, WorkItemsStorage } from '../../storage/domains/work-items/base.js';\nimport type { GithubIntegration } from './integration.js';\nimport { cardBelongsToRepository } from './rules.js';\nimport { parseCreatedPullRequest } from './session-subscriptions.js';\n\nexport interface RecordFactoryPullRequestProvenanceInput {\n binding: FactoryRunBindingRecord;\n item: WorkItemRow;\n assistantMessageId: string;\n toolCallId: string;\n toolName: string;\n toolInput: FactoryRuleJsonValue;\n toolResult: FactoryRuleJsonValue;\n status: 'success' | 'error';\n}\n\nexport interface FactoryPullRequestProvenanceData {\n kind: 'factory-pr-provenance';\n bindingId: string;\n workItemId: string;\n factoryProjectId: string;\n repositoryId: number;\n pullRequestNumber: number;\n pullRequestUrl: string;\n assistantMessageId: string;\n toolCallId: string;\n}\n\nexport async function resolveFactoryPullRequestParentWorkItemId(\n integrationStorage: IntegrationStorageHandle<\n Record<string, unknown>,\n Record<string, unknown>,\n FactoryPullRequestProvenanceData\n >,\n input: { orgId: string; factoryProjectId: string; repositoryId: number; pullRequestNumber: number },\n): Promise<string | null> {\n const targetKey = `factory-pr-provenance:${input.repositoryId}:${input.pullRequestNumber}`;\n // Provenance is scoped to the Factory project whose run authored the PR.\n // Rows from a sibling project in the same org — or legacy rows without the\n // project stamp — fail closed rather than linking another project's card.\n const provenance = (await integrationStorage.subscriptions.listByTarget(targetKey, { status: 'active' })).find(\n row =>\n row.orgId === input.orgId &&\n row.data?.kind === 'factory-pr-provenance' &&\n row.data.factoryProjectId === input.factoryProjectId,\n );\n return provenance?.data?.workItemId ?? null;\n}\n\nexport async function recordFactoryPullRequestProvenance(\n github: GithubIntegration,\n sourceControl: SourceControlStorageHandle,\n integrationStorage: IntegrationStorageHandle<\n Record<string, unknown>,\n Record<string, unknown>,\n FactoryPullRequestProvenanceData\n >,\n workItems: WorkItemsStorage,\n input: RecordFactoryPullRequestProvenanceInput,\n): Promise<void> {\n if (input.status !== 'success' || input.item.externalSource?.type === 'pull-request') return;\n const url = parseCreatedPullRequest({\n toolName: input.toolName,\n input: input.toolInput,\n output: input.toolResult,\n });\n if (!url) return;\n\n try {\n const match = url.match(/^https:\\/\\/github\\.com\\/([^/]+\\/[^/]+)\\/pull\\/(\\d+)\\/?$/i);\n if (!match) return;\n const repositorySlug = match[1]!;\n let repositoryId: number | undefined;\n let installationId: number | undefined;\n for (const connection of await sourceControl.connections.list({\n orgId: input.binding.orgId,\n factoryProjectId: input.binding.factoryProjectId,\n })) {\n const installation = await sourceControl.installations.get({\n orgId: input.binding.orgId,\n id: connection.installationId,\n });\n if (!installation) continue;\n for (const link of await sourceControl.projectRepositories.list({\n orgId: input.binding.orgId,\n connectionId: connection.id,\n })) {\n const repository = await sourceControl.repositories.get({ orgId: input.binding.orgId, id: link.repositoryId });\n if (!repository || repository.slug.toLowerCase() !== repositorySlug.toLowerCase()) continue;\n repositoryId = Number(repository.externalId);\n installationId = Number(installation.externalId);\n break;\n }\n if (repositoryId !== undefined) break;\n }\n const pullRequestNumber = Number(match[2]);\n const [owner, repo] = repositorySlug.split('/');\n if (\n !owner ||\n !repo ||\n repositoryId === undefined ||\n installationId === undefined ||\n !Number.isInteger(repositoryId) ||\n !Number.isInteger(installationId) ||\n !Number.isInteger(pullRequestNumber) ||\n pullRequestNumber < 1\n )\n return;\n const targetKey = `factory-pr-provenance:${repositoryId}:${pullRequestNumber}`;\n // Dedupe within the authoring project only: a sibling project's row must\n // not block this project from recording its own provenance.\n if (\n (await integrationStorage.subscriptions.listByTarget(targetKey)).some(\n row => row.orgId === input.binding.orgId && row.data?.factoryProjectId === input.binding.factoryProjectId,\n )\n ) {\n return;\n }\n\n const { data } = await github\n .getInstallationOctokit(installationId)\n .pulls.get({ owner, repo, pull_number: pullRequestNumber });\n if (data.base.repo.id !== repositoryId || data.number !== pullRequestNumber || data.html_url !== url) return;\n\n await integrationStorage.subscriptions.create({\n orgId: input.binding.orgId,\n targetKey,\n threadId: input.binding.threadId,\n status: 'active',\n data: {\n kind: 'factory-pr-provenance',\n bindingId: input.binding.id,\n workItemId: input.item.id,\n factoryProjectId: input.binding.factoryProjectId,\n repositoryId,\n pullRequestNumber,\n pullRequestUrl: url,\n assistantMessageId: input.assistantMessageId,\n toolCallId: input.toolCallId,\n },\n });\n\n const reviewItem = (\n await workItems.list({\n orgId: input.binding.orgId,\n factoryProjectId: input.binding.factoryProjectId,\n })\n ).find(\n item =>\n item.externalSource?.integrationId === 'github' &&\n item.externalSource.type === 'pull-request' &&\n (item.externalSource.externalId === `github:${repositoryId}:pull-request:${pullRequestNumber}` ||\n (item.externalSource.externalId === `github-pr:${pullRequestNumber}` &&\n cardBelongsToRepository(item, repositoryId, repositorySlug))),\n );\n if (reviewItem) {\n await workItems.setParentWorkItemIfMissing({\n orgId: input.binding.orgId,\n id: reviewItem.id,\n userId: 'factory-pr-provenance',\n parentWorkItemId: input.item.id,\n });\n }\n } catch {\n return;\n }\n}\n"],"mappings":";;;AA+BA,eAAsB,0CACpB,oBAKA,OACwB;CACxB,MAAM,YAAY,yBAAyB,MAAM,aAAa,GAAG,MAAM;CAUvE,QANoB,MAAM,mBAAmB,cAAc,aAAa,WAAW,EAAE,QAAQ,SAAS,CAAC,EAAA,CAAG,MACxG,QACE,IAAI,UAAU,MAAM,SACpB,IAAI,MAAM,SAAS,2BACnB,IAAI,KAAK,qBAAqB,MAAM,gBAExB,CAAC,EAAE,MAAM,cAAc;AACzC;AAEA,eAAsB,mCACpB,QACA,eACA,oBAKA,WACA,OACe;CACf,IAAI,MAAM,WAAW,aAAa,MAAM,KAAK,gBAAgB,SAAS,gBAAgB;CACtF,MAAM,MAAM,wBAAwB;EAClC,UAAU,MAAM;EAChB,OAAO,MAAM;EACb,QAAQ,MAAM;CAChB,CAAC;CACD,IAAI,CAAC,KAAK;CAEV,IAAI;EACF,MAAM,QAAQ,IAAI,MAAM,0DAA0D;EAClF,IAAI,CAAC,OAAO;EACZ,MAAM,iBAAiB,MAAM;EAC7B,IAAI;EACJ,IAAI;EACJ,KAAK,MAAM,cAAc,MAAM,cAAc,YAAY,KAAK;GAC5D,OAAO,MAAM,QAAQ;GACrB,kBAAkB,MAAM,QAAQ;EAClC,CAAC,GAAG;GACF,MAAM,eAAe,MAAM,cAAc,cAAc,IAAI;IACzD,OAAO,MAAM,QAAQ;IACrB,IAAI,WAAW;GACjB,CAAC;GACD,IAAI,CAAC,cAAc;G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IACjF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4FAA4F;IAC5F,UAAU,CAAC,EAAE,iBAAiB,CAAC,YAAY,CAAC,CAAC;IAC7C,gGAAgG;IAChG,cAAc,EAAE,IAAI,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;IACnD,6EAA6E;IAC7E,SAAS,CAAC,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC;IACjC,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,sBAAsB,CAAC;IAClC,iBAAiB,CAAC,EAAE,OAAO,qCAAqC,EAAE,4BAA4B,CAAC;IAC/F,kFAAkF;IAClF,SAAS,CAAC,EAAE,IAAI,CAAC,OAAO,0CAA0C,EAAE,gBAAgB,EAAE,wBAAwB,CAAC,CAAC;IAChH,+FAA+F;IAC/F,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CACvE;AAyOD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,QAAQ,EAAE,CAsoB/E;AA+GD,KAAK,wBAAwB,GAAG,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import { AUTO_TRIAGED_LABEL, NEEDS_APPROVAL_LABEL } from "../../rules/types.js";
2
- import { clearGithubPat, getGithubPatStatus, setGithubPat } from "./pat.js";
3
2
  import { listPullRequestSubscriptionsForThread, subscribeToPullRequest } from "./subscriptions.js";
4
3
  import { polledPullRequestEvent } from "./rules.js";
4
+ import { clearGithubPat, getGithubPatStatus, setGithubPat } from "./pat.js";
5
5
  import { requireExec } from "../../sandbox/materialization.js";
6
6
  import { sanitizeSegment } from "../../sandbox/workdir.js";
7
7
  import { peekSessionSandbox } from "../../sandbox/session-sandbox.js";
@@ -418,6 +418,7 @@ function buildGithubRoutes(options) {
418
418
  cursor: String(page)
419
419
  });
420
420
  const responseIssues = issues.map((issue) => ({
421
+ repositoryId: Number(loaded.project.repository.externalId),
421
422
  number: Number(issue.id),
422
423
  title: issue.title,
423
424
  url: issue.url,
@@ -507,6 +508,7 @@ function buildGithubRoutes(options) {
507
508
  cursor: String(page)
508
509
  });
509
510
  const responsePullRequests = pullRequests.map((pr) => ({
511
+ repositoryId: Number(loaded.project.repository.externalId),
510
512
  number: Number(pr.id),
511
513
  title: pr.title,
512
514
  url: pr.url,