@mastra/factory 0.13.0-alpha.6 → 0.13.0-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -0
- package/dist/boards/index.d.ts +4 -3
- package/dist/boards/index.d.ts.map +1 -1
- package/dist/boards/index.js +2 -1
- package/dist/boards/index.js.map +1 -1
- package/dist/boards/registry.d.ts +16 -0
- package/dist/boards/registry.d.ts.map +1 -0
- package/dist/boards/registry.js +27 -0
- package/dist/boards/registry.js.map +1 -0
- package/dist/boards/review.js +1 -1
- package/dist/boards/work.js +2 -2
- package/dist/factory.d.ts +6 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +10 -0
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/integrations/github/default-rules.d.ts +194 -0
- package/dist/integrations/github/default-rules.d.ts.map +1 -0
- package/dist/integrations/github/default-rules.js +230 -0
- package/dist/integrations/github/default-rules.js.map +1 -0
- package/dist/integrations/github/integration.d.ts +4 -0
- package/dist/integrations/github/integration.d.ts.map +1 -1
- package/dist/integrations/github/integration.js +6 -0
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/rules.d.ts +3 -1
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +1 -2
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/linear/rules.js +1 -1
- package/dist/integrations/platform/github/integration.d.ts +4 -0
- package/dist/integrations/platform/github/integration.d.ts.map +1 -1
- package/dist/integrations/platform/github/integration.js +6 -0
- package/dist/integrations/platform/github/integration.js.map +1 -1
- package/dist/integrations/slack/slack.d.ts +3 -1
- package/dist/integrations/slack/slack.d.ts.map +1 -1
- package/dist/integrations/slack/slack.js +19 -1
- package/dist/integrations/slack/slack.js.map +1 -1
- package/dist/routes/surface.d.ts +3 -0
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +2 -1
- package/dist/routes/surface.js.map +1 -1
- package/dist/routes/work-items.d.ts +3 -0
- package/dist/routes/work-items.d.ts.map +1 -1
- package/dist/routes/work-items.js +48 -15
- package/dist/routes/work-items.js.map +1 -1
- package/dist/rules/defaults.d.ts.map +1 -1
- package/dist/rules/defaults.js +1 -229
- package/dist/rules/defaults.js.map +1 -1
- package/dist/rules/index.d.ts +2 -2
- package/dist/rules/index.d.ts.map +1 -1
- package/dist/rules/index.js +2 -2
- package/dist/rules/processor.d.ts +2 -0
- package/dist/rules/processor.d.ts.map +1 -1
- package/dist/rules/processor.js +9 -7
- package/dist/rules/processor.js.map +1 -1
- package/dist/rules/resolve.d.ts +4 -4
- package/dist/rules/resolve.d.ts.map +1 -1
- package/dist/rules/resolve.js +4 -6
- package/dist/rules/resolve.js.map +1 -1
- package/dist/rules/transition-service.d.ts +2 -0
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +16 -10
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/rules/types.d.ts +3 -8
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js +1 -1
- package/dist/rules/types.js.map +1 -1
- package/dist/rules/validation.d.ts.map +1 -1
- package/dist/rules/validation.js +1 -9
- package/dist/rules/validation.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +11 -1
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +22 -2
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/factory-skills/configure-factory-rules/SKILL.md +12 -4
- package/package.json +6 -6
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
//#region src/integrations/github/default-rules.ts
|
|
2
|
+
function trustedGithubActor(context) {
|
|
3
|
+
return context.actor.type === "github" && context.actor.trusted;
|
|
4
|
+
}
|
|
5
|
+
function githubActorLogin(context) {
|
|
6
|
+
return context.actor.type === "github" ? context.actor.login : void 0;
|
|
7
|
+
}
|
|
8
|
+
function retriageGithubIssue(context) {
|
|
9
|
+
if (!context.item || context.item.source !== "github-issue" || !context.item.url) return;
|
|
10
|
+
if (context.actor.type === "github" && context.actor.factoryAuthored) return;
|
|
11
|
+
const reason = context.event === "issueEdited" ? context.issueChange?.title && context.issueChange.body ? "issue title and body edited" : context.issueChange?.title ? "issue title edited" : "issue body edited" : context.event === "issueCommentDeleted" ? "comment deleted" : context.event === "issueCommentEdited" ? "comment edited" : "comment created";
|
|
12
|
+
return {
|
|
13
|
+
type: "invokeSkill",
|
|
14
|
+
idempotencyKey: `${context.ingress.id}:factory-triage`,
|
|
15
|
+
role: "triage",
|
|
16
|
+
skillName: "factory-triage",
|
|
17
|
+
arguments: `Re-triage GitHub issue (${context.item.url}) after ${reason}.`
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function createdAfterFactory(createdAt, factoryCreatedAt) {
|
|
21
|
+
if (!createdAt) return false;
|
|
22
|
+
const sourceCreatedAt = Date.parse(createdAt);
|
|
23
|
+
const projectCreatedAt = Date.parse(factoryCreatedAt);
|
|
24
|
+
return Number.isFinite(sourceCreatedAt) && Number.isFinite(projectCreatedAt) && sourceCreatedAt > projectCreatedAt;
|
|
25
|
+
}
|
|
26
|
+
function issueOpened(context) {
|
|
27
|
+
if (!context.issue) return;
|
|
28
|
+
return {
|
|
29
|
+
type: "upsertLinkedWorkItem",
|
|
30
|
+
idempotencyKey: `${context.ingress.id}:issue-intake`,
|
|
31
|
+
board: "work",
|
|
32
|
+
source: "github-issue",
|
|
33
|
+
sourceKey: `github-issue:${context.issue.number}`,
|
|
34
|
+
title: context.issue.title,
|
|
35
|
+
url: context.issue.url,
|
|
36
|
+
stage: "intake",
|
|
37
|
+
metadata: {
|
|
38
|
+
githubRepositoryId: context.repository.id,
|
|
39
|
+
githubIssueNumber: context.issue.number,
|
|
40
|
+
...context.issue.createdAt ? { sourceCreatedAt: context.issue.createdAt } : {},
|
|
41
|
+
...githubActorLogin(context) ? { author: githubActorLogin(context) } : {},
|
|
42
|
+
authorTrusted: trustedGithubActor(context),
|
|
43
|
+
autoStartCandidate: trustedGithubActor(context) && createdAfterFactory(context.issue.createdAt, context.factory.createdAt),
|
|
44
|
+
assignees: context.issue.assignees ?? [],
|
|
45
|
+
labels: context.issue.labels ?? []
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function issueClosed(context) {
|
|
50
|
+
if (!context.item || context.item.source !== "github-issue" || !context.issue) return;
|
|
51
|
+
if (context.board !== "work") return;
|
|
52
|
+
if (context.item.stages.some((stage) => stage === "done" || stage === "canceled")) return;
|
|
53
|
+
const canceled = context.issue.stateReason === "not_planned" || context.issue.stateReason === "duplicate";
|
|
54
|
+
return {
|
|
55
|
+
type: "transition",
|
|
56
|
+
idempotencyKey: `${context.ingress.id}:issue-closed`,
|
|
57
|
+
board: "work",
|
|
58
|
+
stage: canceled ? "canceled" : "done",
|
|
59
|
+
message: { text: `GitHub issue #${context.issue.number} was closed${context.issue.stateReason ? ` (${context.issue.stateReason})` : ""}; this Work card was moved to ${canceled ? "Canceled" : "Done"}.` }
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function materializePullRequestIntake(context, { idempotencyKey, autoStartCandidate }) {
|
|
63
|
+
if (!context.pullRequest) return;
|
|
64
|
+
return {
|
|
65
|
+
type: "upsertLinkedWorkItem",
|
|
66
|
+
idempotencyKey,
|
|
67
|
+
board: "review",
|
|
68
|
+
source: "github-pr",
|
|
69
|
+
sourceKey: `github-pr:${context.pullRequest.number}`,
|
|
70
|
+
title: context.pullRequest.title,
|
|
71
|
+
url: context.pullRequest.url,
|
|
72
|
+
stage: "intake",
|
|
73
|
+
metadata: {
|
|
74
|
+
githubRepositoryId: context.repository.id,
|
|
75
|
+
githubPullRequestNumber: context.pullRequest.number,
|
|
76
|
+
...context.pullRequest.createdAt ? { sourceCreatedAt: context.pullRequest.createdAt } : {},
|
|
77
|
+
factoryAuthored: context.pullRequest.factoryAuthored,
|
|
78
|
+
authorTrusted: trustedGithubActor(context),
|
|
79
|
+
autoStartCandidate,
|
|
80
|
+
state: context.pullRequest.state,
|
|
81
|
+
draft: context.pullRequest.draft,
|
|
82
|
+
merged: context.pullRequest.merged,
|
|
83
|
+
assignees: context.pullRequest.assignees ?? [],
|
|
84
|
+
requestedReviewers: context.pullRequest.requestedReviewers ?? [],
|
|
85
|
+
labels: context.pullRequest.labels ?? [],
|
|
86
|
+
headBranch: context.pullRequest.headBranch,
|
|
87
|
+
baseBranch: context.pullRequest.baseBranch,
|
|
88
|
+
...context.pullRequest.author ? { author: context.pullRequest.author } : {}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function pullRequestOpened(context) {
|
|
93
|
+
if (!context.pullRequest) return;
|
|
94
|
+
const autoStartCandidate = (trustedGithubActor(context) || context.pullRequest.factoryAuthored) && createdAfterFactory(context.pullRequest.createdAt, context.factory.createdAt);
|
|
95
|
+
return materializePullRequestIntake(context, {
|
|
96
|
+
idempotencyKey: `${context.ingress.id}:pull-request-intake`,
|
|
97
|
+
autoStartCandidate
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
function pullRequestMerged(context) {
|
|
101
|
+
if (!context.item || !context.pullRequest?.merged) return;
|
|
102
|
+
if (context.board === "review") return {
|
|
103
|
+
type: "transition",
|
|
104
|
+
idempotencyKey: `${context.ingress.id}:pull-request-merged`,
|
|
105
|
+
board: "review",
|
|
106
|
+
stage: "done",
|
|
107
|
+
message: { text: `Pull request #${context.pullRequest.number} merged; this Review card was moved to Done. No further review is needed unless follow-up work was requested.` }
|
|
108
|
+
};
|
|
109
|
+
return {
|
|
110
|
+
type: "sendMessage",
|
|
111
|
+
idempotencyKey: `${context.ingress.id}:assess-work-completion`,
|
|
112
|
+
role: "work",
|
|
113
|
+
message: `Pull request #${context.pullRequest.number} merged. Assess whether the linked Work item is complete. Do not mark it Done solely because this PR merged; use factory_transition_work_item only after verifying the work.`
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function addressReviewFeedback(context) {
|
|
117
|
+
if (!context.item || !context.pullRequest || !context.review) return;
|
|
118
|
+
if (context.board !== "work") return;
|
|
119
|
+
if (context.pullRequest.state !== "open" || context.pullRequest.merged) return;
|
|
120
|
+
if (context.review.state.toLowerCase() !== "changes_requested") return;
|
|
121
|
+
return {
|
|
122
|
+
type: "sendMessage",
|
|
123
|
+
idempotencyKey: `${context.ingress.id}:address-review-feedback`,
|
|
124
|
+
role: "work",
|
|
125
|
+
priority: "high",
|
|
126
|
+
message: `Changes were requested on pull request #${context.pullRequest.number} (${context.review.url}). Read the review comments on this PR, address the ones you agree with, and push the fixes to the PR branch. Reply on GitHub to anything you are deliberately not changing, explaining why.`
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Detects the `factory-review` handoff verdict in a comment body.
|
|
131
|
+
*
|
|
132
|
+
* GitHub forbids an app from reviewing a pull request it authored, so on
|
|
133
|
+
* Factory-authored PRs the review skill falls back to posting its verdict as a
|
|
134
|
+
* plain comment. That comment is the only signal the authoring agent gets, so
|
|
135
|
+
* it has to be readable back out. The skill's handoff contract puts the verdict
|
|
136
|
+
* on the first line (`Verdict: request changes`), so only that line is
|
|
137
|
+
* inspected — a verdict quoted later in the findings must not count.
|
|
138
|
+
*/
|
|
139
|
+
function requestsChangesVerdict(body) {
|
|
140
|
+
const firstLine = body?.split("\n").map((line) => line.trim()).find((line) => line.length > 0);
|
|
141
|
+
if (!firstLine) return false;
|
|
142
|
+
const normalized = firstLine.replaceAll(/[*_`#>\s]+/g, " ").trim().toLowerCase();
|
|
143
|
+
return /^verdict: ?(request changes|changes requested)$/.test(normalized);
|
|
144
|
+
}
|
|
145
|
+
function addressPullRequestComment(context) {
|
|
146
|
+
if (context.reviewCommand) return reReviewRequestedPullRequest(context);
|
|
147
|
+
if (!context.item || !context.pullRequest || !context.issueComment) return;
|
|
148
|
+
if (context.board !== "work") return;
|
|
149
|
+
if (context.pullRequest.state !== "open" || context.pullRequest.merged) return;
|
|
150
|
+
if (context.actor.type === "github" && context.actor.factoryAuthored && !requestsChangesVerdict(context.issueComment.body)) return;
|
|
151
|
+
return {
|
|
152
|
+
type: "sendMessage",
|
|
153
|
+
idempotencyKey: `${context.ingress.id}:address-pull-request-comment`,
|
|
154
|
+
role: "work",
|
|
155
|
+
priority: "high",
|
|
156
|
+
message: `${context.issueComment.author ?? "Someone"} commented on pull request #${context.pullRequest.number} (${context.issueComment.url ?? context.pullRequest.url}). Read the comment, address it if you agree, and push the fixes to the PR branch. Reply on GitHub to anything you are deliberately not changing, explaining why.`
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function pullRequestClosed(context) {
|
|
160
|
+
if (!context.item || !context.pullRequest || context.pullRequest.merged) return;
|
|
161
|
+
if (context.board !== "review") return;
|
|
162
|
+
return {
|
|
163
|
+
type: "transition",
|
|
164
|
+
idempotencyKey: `${context.ingress.id}:pull-request-closed`,
|
|
165
|
+
board: "review",
|
|
166
|
+
stage: "canceled",
|
|
167
|
+
message: { text: `Pull request #${context.pullRequest.number} was closed without merging; this Review card was moved to Canceled.` }
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function reReviewRequestedPullRequest(context) {
|
|
171
|
+
const factoryReviewEntry = context.reviewRequest?.factoryReviewer || context.reviewCommand !== void 0;
|
|
172
|
+
if (context.item && context.board !== "review" || !factoryReviewEntry) return;
|
|
173
|
+
if (!context.pullRequest || context.pullRequest.state !== "open" || context.pullRequest.merged) return;
|
|
174
|
+
if (!trustedGithubActor(context)) return;
|
|
175
|
+
if (context.actor.type === "github" && context.actor.factoryAuthored) return;
|
|
176
|
+
if (!context.item) return materializePullRequestIntake(context, {
|
|
177
|
+
idempotencyKey: `${context.ingress.id}:pull-request-review-requested-intake`,
|
|
178
|
+
autoStartCandidate: true
|
|
179
|
+
});
|
|
180
|
+
if (context.item.stages.length === 1 && context.item.stages[0] === "review") return;
|
|
181
|
+
return {
|
|
182
|
+
type: "transition",
|
|
183
|
+
idempotencyKey: `${context.ingress.id}:re-review-requested`,
|
|
184
|
+
board: "review",
|
|
185
|
+
stage: "review"
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function reReviewUpdatedPullRequest(context) {
|
|
189
|
+
if (!context.item || context.board !== "review") return;
|
|
190
|
+
if (!context.pullRequest || context.pullRequest.state !== "open" || context.pullRequest.merged) return;
|
|
191
|
+
if (context.item.stages.some((stage) => stage === "intake")) return;
|
|
192
|
+
const alreadyReviewing = context.item.stages.some((stage) => stage === "review");
|
|
193
|
+
return {
|
|
194
|
+
type: "transition",
|
|
195
|
+
idempotencyKey: `${context.ingress.id}:re-review-updated`,
|
|
196
|
+
board: "review",
|
|
197
|
+
stage: "review",
|
|
198
|
+
...alreadyReviewing ? { reenter: true } : {}
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
const defaultGithubRules = Object.freeze({
|
|
202
|
+
issueOpened,
|
|
203
|
+
issueEdited: retriageGithubIssue,
|
|
204
|
+
issueClosed,
|
|
205
|
+
issueCommentCreated: retriageGithubIssue,
|
|
206
|
+
issueCommentEdited: retriageGithubIssue,
|
|
207
|
+
issueCommentDeleted: retriageGithubIssue,
|
|
208
|
+
pullRequestOpened,
|
|
209
|
+
pullRequestUpdated: reReviewUpdatedPullRequest,
|
|
210
|
+
pullRequestCommentCreated: addressPullRequestComment,
|
|
211
|
+
pullRequestReviewRequested: reReviewRequestedPullRequest,
|
|
212
|
+
pullRequestReviewSubmitted: addressReviewFeedback,
|
|
213
|
+
pullRequestMerged,
|
|
214
|
+
pullRequestClosed
|
|
215
|
+
});
|
|
216
|
+
function resolveGithubRules(overrides) {
|
|
217
|
+
if (overrides !== void 0 && (overrides === null || typeof overrides !== "object" || Array.isArray(overrides))) throw new Error("GitHub rules must be an object.");
|
|
218
|
+
const rules = { ...defaultGithubRules };
|
|
219
|
+
for (const key of Reflect.ownKeys(overrides ?? {})) {
|
|
220
|
+
if (typeof key !== "string" || !Object.hasOwn(defaultGithubRules, key)) throw new Error(`Unknown GitHub rule event: ${String(key)}.`);
|
|
221
|
+
const handler = overrides?.[key];
|
|
222
|
+
if (handler !== void 0 && handler !== null && typeof handler !== "function") throw new Error(`GitHub rule ${key} must be a function, null, or undefined.`);
|
|
223
|
+
if (handler !== void 0) rules[key] = handler;
|
|
224
|
+
}
|
|
225
|
+
return Object.freeze(rules);
|
|
226
|
+
}
|
|
227
|
+
//#endregion
|
|
228
|
+
export { defaultGithubRules, resolveGithubRules };
|
|
229
|
+
|
|
230
|
+
//# sourceMappingURL=default-rules.js.map
|
|
@@ -0,0 +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"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ACb,aAAa;CACA;CACb,qBAAqB;CACrB,oBAAoB;CACpB,qBAAqB;CACF;CACnB,oBAAoB;CACpB,2BAA2B;CAC3B,4BAA4B;CAC5B,4BAA4B;CACT;CACA;AACrB,CAA4B;AAE5B,SAAgB,mBAAmB,WAAmD;CACpF,IAAI,cAAc,KAAA,MAAc,cAAc,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"}
|
|
@@ -29,6 +29,7 @@ import { Octokit } from '@octokit/rest';
|
|
|
29
29
|
import type { Intake } from '../../capabilities/intake.js';
|
|
30
30
|
import type { VersionControl } from '../../capabilities/version-control.js';
|
|
31
31
|
import type { FactoryIntegration, IntegrationContext, IntegrationTools } from '../base.js';
|
|
32
|
+
import type { GithubEventRules, GithubRuleOverrides } from './default-rules.js';
|
|
32
33
|
import type { ReconcileIssueState, ReconcilePullRequestState } from './rules.js';
|
|
33
34
|
import type { GithubSubscriptionStorage } from './subscriptions.js';
|
|
34
35
|
/**
|
|
@@ -88,6 +89,8 @@ export interface ListRepoOpenIssuesOptions {
|
|
|
88
89
|
label?: string;
|
|
89
90
|
}
|
|
90
91
|
export interface GithubIntegrationConfig {
|
|
92
|
+
/** Replace an event handler, or disable it with null; omitted events keep defaults. */
|
|
93
|
+
rules?: GithubRuleOverrides;
|
|
91
94
|
/** GitHub App id (the numeric id, as a string). */
|
|
92
95
|
appId: string;
|
|
93
96
|
/**
|
|
@@ -119,6 +122,7 @@ export declare class GithubIntegration implements FactoryIntegration {
|
|
|
119
122
|
#private;
|
|
120
123
|
/** Stable integration identifier (see `../factory-integration.ts`). */
|
|
121
124
|
readonly id = "github";
|
|
125
|
+
get rules(): GithubEventRules;
|
|
122
126
|
readonly intake: Intake;
|
|
123
127
|
readonly versionControl: VersionControl;
|
|
124
128
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/integration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAGxC,OAAO,KAAK,EAGV,MAAM,EAKP,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAKV,cAAc,EACf,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../../../src/integrations/github/integration.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAE,OAAO,E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EAAE,MAAM,CAAC;QACnB,MAAM,EAAE,MAAM,CAAC;KAChB,GAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC;IA6B5C;;;OAGG;IACG,0BAA0B,CAAC,KAAK,EAAE,8BAA8B,GAAG,OAAO,CAAC,+BAA+B,CAAC;IAsCjH,YAAY,CAAC,EAAE,cAAc,EAAE,EAAE;QAAE,cAAc,EAAE,cAAc,CAAA;KAAE,GAAG,gBAAgB;IAIhF,gBAAgB,CAAC,EACrB,WAAW,EACX,cAAc,GACf,EAAE,UAAU,CAAC,WAAW,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAMrF,sEAAsE;IACtE,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAMvC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createGithubSubscriptionTools, parseCreatedPullRequest, subscribeCurrentSessionToPullRequest } from "./session-subscriptions.js";
|
|
2
|
+
import { resolveGithubRules } from "./default-rules.js";
|
|
2
3
|
import { attachGithubReconciler, attachGithubRules } from "./rules.js";
|
|
3
4
|
import { attachGithubIssueReconciler } from "./issue-reconciler.js";
|
|
4
5
|
import { reconcileInterval, reconciliationEnabled } from "./reconciliation-config.js";
|
|
@@ -50,6 +51,10 @@ const REQUIRED_FIELDS = [
|
|
|
50
51
|
var GithubIntegration = class {
|
|
51
52
|
/** Stable integration identifier (see `../factory-integration.ts`). */
|
|
52
53
|
id = "github";
|
|
54
|
+
#rules;
|
|
55
|
+
get rules() {
|
|
56
|
+
return this.#rules;
|
|
57
|
+
}
|
|
53
58
|
intake = {
|
|
54
59
|
resolveIntakeDispatch: (input) => this.#resolveIntakeDispatch(input),
|
|
55
60
|
listSources: async ({ orgId }) => {
|
|
@@ -235,6 +240,7 @@ var GithubIntegration = class {
|
|
|
235
240
|
/** Same key → lookup already in flight, so overlapping callers share one request. */
|
|
236
241
|
#collaboratorPermissionInFlight = /* @__PURE__ */ new Map();
|
|
237
242
|
constructor(config) {
|
|
243
|
+
this.#rules = resolveGithubRules(config.rules);
|
|
238
244
|
const missing = REQUIRED_FIELDS.filter((field) => !config[field]);
|
|
239
245
|
if (missing.length > 0) throw new Error(`GithubIntegration: missing required config field(s): ${missing.join(", ")}. Provide the full GitHub App credentials (appId, privateKey, clientId, clientSecret, slug) or omit the integration to disable GitHub-backed repositories.`);
|
|
240
246
|
this.#appId = config.appId;
|