@mastra/github-signals 0.2.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/dist/index.cjs +153 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +153 -27
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @mastra/github-signals
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added intent-aware GitHub pull request subscription modes. Review mode follows code revisions, authorized comments, review-thread state, and terminal PR state without CI or mergeability noise, while omitted modes retain working behavior. ([#21542](https://github.com/mastra-ai/mastra/pull/21542))
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
await githubSignals.subscribeThreadToPR({ threadId, resourceId, pr, mode: 'review' });
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [[`79f04a7`](https://github.com/mastra-ai/mastra/commit/79f04a7f6c6829da541139f638f2f1d267916e08), [`65edab1`](https://github.com/mastra-ai/mastra/commit/65edab1c233d17b8f163bad12fca410d0e6f16b1), [`1e47b75`](https://github.com/mastra-ai/mastra/commit/1e47b7520cab4cfaa8daed52f17e2e6d14ff7539), [`ab20a38`](https://github.com/mastra-ai/mastra/commit/ab20a38d0275f8d85e0f3833bd87ef487bcc609f), [`fd4d5fe`](https://github.com/mastra-ai/mastra/commit/fd4d5fe4f943699b85db5e74404f190d5a6b8c2a), [`ae8790c`](https://github.com/mastra-ai/mastra/commit/ae8790c4bfaa088d2ab279d1dcc06f326b9fd109), [`2c85f42`](https://github.com/mastra-ai/mastra/commit/2c85f428e04ccd63ea31a7ec80b5b327afdad555), [`11bbeb9`](https://github.com/mastra-ai/mastra/commit/11bbeb9b108ef2264e05acefc6dafb9cbb342921), [`48ef1f1`](https://github.com/mastra-ai/mastra/commit/48ef1f1d24eedafbb07f64e659a81b52b67b8bf6), [`aa3a85d`](https://github.com/mastra-ai/mastra/commit/aa3a85daf094c683bb97efdf4b6a696d2e474af5), [`d29d06f`](https://github.com/mastra-ai/mastra/commit/d29d06fe00bbd35b4571150ea04c59d2ed783c71), [`e6516df`](https://github.com/mastra-ai/mastra/commit/e6516dfcdae4f4ac0e7971d84359a81385ee602f), [`1a485f3`](https://github.com/mastra-ai/mastra/commit/1a485f3538f5ec64d58bd8b5e1e99de0c695c87b), [`0d37487`](https://github.com/mastra-ai/mastra/commit/0d37487d9f349388a3f1cef6a536cf9dcc4b6273), [`8661d7d`](https://github.com/mastra-ai/mastra/commit/8661d7d7179f0a024456aabdd8679bcecd09ac28), [`dbbfeb8`](https://github.com/mastra-ai/mastra/commit/dbbfeb85ec949dc9ebc0755e1ad262e4f5eba8db), [`575e343`](https://github.com/mastra-ai/mastra/commit/575e343900451021d96110916497d334af7bc252), [`0b2a3d1`](https://github.com/mastra-ai/mastra/commit/0b2a3d1783875c5b97b7b36ab3d03d7360e0dde7), [`6bb5d71`](https://github.com/mastra-ai/mastra/commit/6bb5d7193fe9166b219f0fccae17db7a5ae86e65), [`3cc9d00`](https://github.com/mastra-ai/mastra/commit/3cc9d00b2b4333e0377a5e9df5eff92c17ce7630), [`cacb839`](https://github.com/mastra-ai/mastra/commit/cacb8392d9e74189b56d857290b0615f98a2683d), [`57de7d6`](https://github.com/mastra-ai/mastra/commit/57de7d644ba7146edb4e9e6111ec4fa98c3a59e9), [`c8e4cea`](https://github.com/mastra-ai/mastra/commit/c8e4ceac9a390d78c8327dff3cdb2861dd71957f), [`ed01e9a`](https://github.com/mastra-ai/mastra/commit/ed01e9a807514a904374bf687a7b8f18750f6f78), [`b47b26e`](https://github.com/mastra-ai/mastra/commit/b47b26e6fe95cb8a3482be2c5e52de157fe59d0b), [`0d37487`](https://github.com/mastra-ai/mastra/commit/0d37487d9f349388a3f1cef6a536cf9dcc4b6273), [`733a537`](https://github.com/mastra-ai/mastra/commit/733a537489a858b5880b2e98809334fba895a221), [`e8e299c`](https://github.com/mastra-ai/mastra/commit/e8e299cc6abdfc39947e2fec25803493015d3882), [`edfc548`](https://github.com/mastra-ai/mastra/commit/edfc548886bc7bae17b681f8b6b41a47eb32bcd2), [`b05f486`](https://github.com/mastra-ai/mastra/commit/b05f48612984d5fe2447ea2d6cdd5c604d285b97), [`a8a4871`](https://github.com/mastra-ai/mastra/commit/a8a4871215f51da95c47129602157ce5372f634a), [`eb9ecaa`](https://github.com/mastra-ai/mastra/commit/eb9ecaa89c36e889749e3b825cfc507ce7f7980b), [`4ff3ee2`](https://github.com/mastra-ai/mastra/commit/4ff3ee2bff7ed07528b4817f8f49639031c72a4d), [`9207dfa`](https://github.com/mastra-ai/mastra/commit/9207dfab8062e5fc68b751684797ff86fe0b4e70), [`5165cdc`](https://github.com/mastra-ai/mastra/commit/5165cdcdcf50e144bb8113278535196cc9b07065), [`e737014`](https://github.com/mastra-ai/mastra/commit/e737014e0fc7035759762bb5b48baef1d6c0f6a7), [`6bb5d71`](https://github.com/mastra-ai/mastra/commit/6bb5d7193fe9166b219f0fccae17db7a5ae86e65), [`f591643`](https://github.com/mastra-ai/mastra/commit/f591643becdf0be9bddce6ba1748e64bc30d77f1), [`63796ba`](https://github.com/mastra-ai/mastra/commit/63796ba0fda60253be17535e68f6bbbf1e6ffa09), [`b1ad324`](https://github.com/mastra-ai/mastra/commit/b1ad324d657f3544b0701332aef7eb10e9a36258), [`61c566d`](https://github.com/mastra-ai/mastra/commit/61c566dd2f2cde2b23ed8f139924e530d4202214), [`c24754c`](https://github.com/mastra-ai/mastra/commit/c24754c1fb6fe144e5051e536e98c8a18b0214ac), [`12c61d2`](https://github.com/mastra-ai/mastra/commit/12c61d280c8cb208bc3c8dbcbe5dcc60cf9d1cd0), [`c46eb09`](https://github.com/mastra-ai/mastra/commit/c46eb09ce4987509af57a0ac582c61241a6dd2f1), [`9ee8120`](https://github.com/mastra-ai/mastra/commit/9ee8120ce17f76b9f617489e05a283353742690a), [`d975e92`](https://github.com/mastra-ai/mastra/commit/d975e924d4936f46c386bd3dee39c671720289f6), [`45dd6ee`](https://github.com/mastra-ai/mastra/commit/45dd6ee089bd7df0d0c98a10098e483fd388e04a), [`4e9a228`](https://github.com/mastra-ai/mastra/commit/4e9a2283d5fd6ed1b70a2751eb3dc2cbf82ada20), [`d6ce34a`](https://github.com/mastra-ai/mastra/commit/d6ce34aeceb06ddf3d595a1eed5cc74f481a46a1), [`f95f468`](https://github.com/mastra-ai/mastra/commit/f95f468cf1e7c2b924a13826494f98b8f2ccd581), [`30ed33e`](https://github.com/mastra-ai/mastra/commit/30ed33ee14084a26019aba15fceadda6d6ddefaf), [`04a815f`](https://github.com/mastra-ai/mastra/commit/04a815fc8971d29e97fcdcc5008a1eb472fc00ff), [`1cfa878`](https://github.com/mastra-ai/mastra/commit/1cfa8784d8da0dfaa0317e5048bc48b6084a5ea5), [`9a12ef3`](https://github.com/mastra-ai/mastra/commit/9a12ef3fccf3f4186db0f294f4ee1f02cf4d8db2), [`32d3583`](https://github.com/mastra-ai/mastra/commit/32d358332cb8ac2306b83b73cf3536e74dbd435e), [`7960688`](https://github.com/mastra-ai/mastra/commit/7960688828e04eaf3106e34f7758fa580257eef6), [`91ad69d`](https://github.com/mastra-ai/mastra/commit/91ad69d64994c89199b0c55399e64ed91c61df2f), [`8dc408d`](https://github.com/mastra-ai/mastra/commit/8dc408d34438f9e13297f792c11a5cfd6cf952e1), [`c92def1`](https://github.com/mastra-ai/mastra/commit/c92def10a13c822972c96f0a4ca6ffc1f4258aed), [`63041eb`](https://github.com/mastra-ai/mastra/commit/63041eb4c50b520a0a80e03d4cd6ea99f67715a0), [`c118318`](https://github.com/mastra-ai/mastra/commit/c1183181c9804303db4b511c2e2648f8b714712b), [`c5eaec5`](https://github.com/mastra-ai/mastra/commit/c5eaec5a860d80d0e3805e67db0414b87ac8cbed), [`fc07c64`](https://github.com/mastra-ai/mastra/commit/fc07c6465043e08e99193a6751a01c56ffc2e7a1), [`cced745`](https://github.com/mastra-ai/mastra/commit/cced745a056ec2225c5bc702e32d848847aa8b65), [`542dee2`](https://github.com/mastra-ai/mastra/commit/542dee254167f974ff8cbbbfc0ce10f9a2616a7b), [`3c19dce`](https://github.com/mastra-ai/mastra/commit/3c19dcef8e73062a80627a4927eae3ec11145afd), [`aca2869`](https://github.com/mastra-ai/mastra/commit/aca2869b2031982f3c4a2f52525c9be7cf123ef8), [`a58483c`](https://github.com/mastra-ai/mastra/commit/a58483cff1a9d41fce7c931843f48cb0ac450f64), [`a58483c`](https://github.com/mastra-ai/mastra/commit/a58483cff1a9d41fce7c931843f48cb0ac450f64), [`e6f8450`](https://github.com/mastra-ai/mastra/commit/e6f845074d478527026b18d85031b23353e1d0a4), [`895e9df`](https://github.com/mastra-ai/mastra/commit/895e9dfc17d6f34299eca64e317ded9e5f5e5ef8), [`e66b2ba`](https://github.com/mastra-ai/mastra/commit/e66b2ba100db63eaeab6e21e1ea34b113f2ec781), [`3e8727e`](https://github.com/mastra-ai/mastra/commit/3e8727e11ec1a5d733acedb5c872896394be18c1)]:
|
|
16
|
+
- @mastra/core@1.62.0
|
|
17
|
+
|
|
18
|
+
## 0.3.0-alpha.0
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- Added intent-aware GitHub pull request subscription modes. Review mode follows code revisions, authorized comments, review-thread state, and terminal PR state without CI or mergeability noise, while omitted modes retain working behavior. ([#21542](https://github.com/mastra-ai/mastra/pull/21542))
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
await githubSignals.subscribeThreadToPR({ threadId, resourceId, pr, mode: 'review' });
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Patch Changes
|
|
29
|
+
|
|
30
|
+
- Updated dependencies [[`4ff3ee2`](https://github.com/mastra-ai/mastra/commit/4ff3ee2bff7ed07528b4817f8f49639031c72a4d), [`c24754c`](https://github.com/mastra-ai/mastra/commit/c24754c1fb6fe144e5051e536e98c8a18b0214ac), [`45dd6ee`](https://github.com/mastra-ai/mastra/commit/45dd6ee089bd7df0d0c98a10098e483fd388e04a), [`32d3583`](https://github.com/mastra-ai/mastra/commit/32d358332cb8ac2306b83b73cf3536e74dbd435e), [`aca2869`](https://github.com/mastra-ai/mastra/commit/aca2869b2031982f3c4a2f52525c9be7cf123ef8)]:
|
|
31
|
+
- @mastra/core@1.62.0-alpha.11
|
|
32
|
+
|
|
3
33
|
## 0.2.5
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -47,8 +47,8 @@ const DEFAULT_AUTHORIZED_PERMISSIONS = [
|
|
|
47
47
|
];
|
|
48
48
|
const DEFAULT_AUTHORIZED_BOTS = ["coderabbitai[bot]", "devin-ai-integration[bot]"];
|
|
49
49
|
const PERMISSION_CACHE_TTL_MS = 300 * 1e3;
|
|
50
|
-
/** Notification kinds
|
|
51
|
-
const AUTHOR_GATED_NOTIFICATION_KINDS = /* @__PURE__ */ new Set(["pull-request-activity"
|
|
50
|
+
/** Notification kinds that include comment content and should be gated by author permission. */
|
|
51
|
+
const AUTHOR_GATED_NOTIFICATION_KINDS = /* @__PURE__ */ new Set(["pull-request-activity"]);
|
|
52
52
|
const createGithubTool = _mastra_core_tools.createTool;
|
|
53
53
|
function isPlainObject(value) {
|
|
54
54
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -60,6 +60,12 @@ function readNumber(value) {
|
|
|
60
60
|
if (typeof value === "number" && Number.isInteger(value) && value > 0) return value;
|
|
61
61
|
if (typeof value === "string" && /^\d+$/.test(value)) return Number(value);
|
|
62
62
|
}
|
|
63
|
+
function normalizeGithubSubscriptionMode(value) {
|
|
64
|
+
return value === "review" ? "review" : "working";
|
|
65
|
+
}
|
|
66
|
+
function getGithubTerminalState(snapshot) {
|
|
67
|
+
return snapshot?.state === "closed" || snapshot?.state === "merged" ? snapshot.state : void 0;
|
|
68
|
+
}
|
|
63
69
|
function stableJson(value) {
|
|
64
70
|
if (Array.isArray(value)) return `[${value.map(stableJson).join(",")}]`;
|
|
65
71
|
if (isPlainObject(value)) return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableJson(value[key])}`).join(",")}}`;
|
|
@@ -120,6 +126,7 @@ function getGithubMetadata(threadMetadata) {
|
|
|
120
126
|
owner,
|
|
121
127
|
repo,
|
|
122
128
|
number,
|
|
129
|
+
mode: normalizeGithubSubscriptionMode(rawSubscription.mode),
|
|
123
130
|
subscribedAt,
|
|
124
131
|
updatedAt,
|
|
125
132
|
lastSubscribeSignalId,
|
|
@@ -174,8 +181,11 @@ function getPrLabel(subscription, snapshot) {
|
|
|
174
181
|
const pr = `${subscription.owner}/${subscription.repo}#${subscription.number}`;
|
|
175
182
|
return snapshot?.title ? `${pr}: ${snapshot.title}` : pr;
|
|
176
183
|
}
|
|
184
|
+
function getTerminalNotificationSummary(label, terminalState) {
|
|
185
|
+
return `${label} was ${terminalState}. This thread has been automatically unsubscribed from this PR. Resubscribe if you still need updates.`;
|
|
186
|
+
}
|
|
177
187
|
function getMergedNotificationSummary(label) {
|
|
178
|
-
return
|
|
188
|
+
return getTerminalNotificationSummary(label, "merged");
|
|
179
189
|
}
|
|
180
190
|
/**
|
|
181
191
|
* Removes a hidden block (its delimiters *and* its content) starting at every `open` marker.
|
|
@@ -273,7 +283,10 @@ const githubActivityNotificationPriority = {
|
|
|
273
283
|
medium: 1
|
|
274
284
|
};
|
|
275
285
|
function getGithubActivityNotificationRank(notification) {
|
|
276
|
-
|
|
286
|
+
if (notification.kind === "pull-request-activity") return 0;
|
|
287
|
+
if (notification.kind === "pull-request-code-activity") return 1;
|
|
288
|
+
if (notification.kind === "pull-request-review-activity") return 2;
|
|
289
|
+
return 3;
|
|
277
290
|
}
|
|
278
291
|
function compareGithubActivityNotifications(a, b) {
|
|
279
292
|
if (!a && !b) return 0;
|
|
@@ -293,6 +306,28 @@ function classifyGithubCommentActivityNotification(input) {
|
|
|
293
306
|
summary
|
|
294
307
|
};
|
|
295
308
|
}
|
|
309
|
+
function classifyGithubTerminalActivityNotification(input) {
|
|
310
|
+
return {
|
|
311
|
+
kind: input.terminalState === "merged" ? "pull-request-merged" : "pull-request-closed",
|
|
312
|
+
priority: "high",
|
|
313
|
+
summary: getTerminalNotificationSummary(getPrLabel(input.subscription, input.snapshot), input.terminalState)
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
function classifyGithubHeadActivityNotification(input) {
|
|
317
|
+
return {
|
|
318
|
+
kind: "pull-request-code-activity",
|
|
319
|
+
priority: "medium",
|
|
320
|
+
summary: `New head revision for ${getPrLabel(input.subscription, input.snapshot)}.`
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
function classifyGithubReviewStateActivityNotification(input) {
|
|
324
|
+
const count = input.snapshot.unresolvedReviewThreads ?? 0;
|
|
325
|
+
return {
|
|
326
|
+
kind: "pull-request-review-activity",
|
|
327
|
+
priority: "medium",
|
|
328
|
+
summary: count === 0 ? `All review threads are resolved for ${getPrLabel(input.subscription, input.snapshot)}.` : `${getPrLabel(input.subscription, input.snapshot)} has ${count} unresolved review ${count === 1 ? "thread" : "threads"}.`
|
|
329
|
+
};
|
|
330
|
+
}
|
|
296
331
|
function getCheckUpdatedTime(check) {
|
|
297
332
|
const value = check.updatedAt ? Date.parse(check.updatedAt) : NaN;
|
|
298
333
|
return Number.isFinite(value) ? value : 0;
|
|
@@ -703,6 +738,7 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
703
738
|
static signals = {
|
|
704
739
|
subscribeToPR(input) {
|
|
705
740
|
const normalized = typeof input === "number" ? { number: input } : input;
|
|
741
|
+
const mode = normalizeGithubSubscriptionMode(normalized.mode);
|
|
706
742
|
return {
|
|
707
743
|
type: "reactive",
|
|
708
744
|
tagName: GITHUB_SUBSCRIBE_PR_TAG,
|
|
@@ -710,11 +746,13 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
710
746
|
attributes: {
|
|
711
747
|
...normalized.owner ? { owner: normalized.owner } : {},
|
|
712
748
|
...normalized.repo ? { repo: normalized.repo } : {},
|
|
713
|
-
number: normalized.number
|
|
749
|
+
number: normalized.number,
|
|
750
|
+
mode
|
|
714
751
|
},
|
|
715
752
|
metadata: { github: {
|
|
716
753
|
action: "subscribeToPR",
|
|
717
|
-
...normalized
|
|
754
|
+
...normalized,
|
|
755
|
+
mode
|
|
718
756
|
} }
|
|
719
757
|
};
|
|
720
758
|
},
|
|
@@ -794,6 +832,7 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
794
832
|
return this.#subscribe({
|
|
795
833
|
id: `github-command-subscribe-${(0, crypto.randomUUID)()}`,
|
|
796
834
|
...pr,
|
|
835
|
+
mode: normalizeGithubSubscriptionMode(input.mode),
|
|
797
836
|
threadId: input.threadId,
|
|
798
837
|
resourceId: input.resourceId
|
|
799
838
|
});
|
|
@@ -898,10 +937,11 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
898
937
|
abortSignal: args.abortSignal
|
|
899
938
|
});
|
|
900
939
|
if (result.alreadyProcessed) return { tools };
|
|
940
|
+
const terminalMessage = result.terminalState ? `Not subscribed to ${result.owner}/${result.repo}#${result.number} in review mode because it is already ${result.terminalState}.` : void 0;
|
|
901
941
|
await this.#sendStatus(args, result, {
|
|
902
|
-
status: result.syncResult?.ok === false ? "sync_error" : "subscribed",
|
|
942
|
+
status: result.terminalState ? "not_subscribed_terminal" : result.syncResult?.ok === false ? "sync_error" : "subscribed",
|
|
903
943
|
action: "subscribeToPR",
|
|
904
|
-
message: result.syncResult?.ok === false ? `Subscribed to ${result.owner}/${result.repo}#${result.number}, but gitcrawl sync failed: ${result.syncResult.error}` : `Subscribed to ${result.owner}/${result.repo}#${result.number}.`
|
|
944
|
+
message: terminalMessage ?? (result.syncResult?.ok === false ? `Subscribed to ${result.owner}/${result.repo}#${result.number} in ${result.mode} mode, but gitcrawl sync failed: ${result.syncResult.error}` : `Subscribed to ${result.owner}/${result.repo}#${result.number} in ${result.mode} mode.`)
|
|
905
945
|
});
|
|
906
946
|
return { tools };
|
|
907
947
|
}
|
|
@@ -941,8 +981,12 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
941
981
|
await args.sendSignal?.({
|
|
942
982
|
type: "reactive",
|
|
943
983
|
tagName: "system-reminder",
|
|
944
|
-
contents: `
|
|
945
|
-
attributes: {
|
|
984
|
+
contents: `Choose whether to follow ${repository.owner}/${repository.repo}#${evidence.number}: use /github subscribe ${evidence.number} --mode review for new commits, authorized latest PR comments, review-thread-state changes including all threads resolved, and PR close or merge updates; use --mode working for all actionable PR activity. Do not subscribe for a one-off inspection.`,
|
|
985
|
+
attributes: {
|
|
986
|
+
type: "github-subscription-hint",
|
|
987
|
+
availableModes: "review,working",
|
|
988
|
+
defaultMode: null
|
|
989
|
+
},
|
|
946
990
|
metadata: { github: {
|
|
947
991
|
action: "subscriptionHint",
|
|
948
992
|
owner: repository.owner,
|
|
@@ -973,11 +1017,12 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
973
1017
|
...args.tools,
|
|
974
1018
|
github_subscribe_pr: createGithubTool({
|
|
975
1019
|
id: "github_subscribe_pr",
|
|
976
|
-
description: "Subscribe this thread to a GitHub pull request.
|
|
1020
|
+
description: "Subscribe this thread to a GitHub pull request. Use review mode for new commits, authorized latest PR comments, review-thread-state changes including all threads resolved, and PR close or merge updates. Use working mode for all actionable PR activity. Omitted mode defaults to working. Do not subscribe for a one-off inspection.",
|
|
977
1021
|
inputSchema: zod.default.object({
|
|
978
1022
|
number: zod.default.number().int().positive(),
|
|
979
1023
|
owner: zod.default.string().optional(),
|
|
980
|
-
repo: zod.default.string().optional()
|
|
1024
|
+
repo: zod.default.string().optional(),
|
|
1025
|
+
mode: zod.default.enum(["working", "review"]).optional()
|
|
981
1026
|
}),
|
|
982
1027
|
execute: async (input, context) => {
|
|
983
1028
|
const executionThreadContext = getExecutionThreadContext(context);
|
|
@@ -986,16 +1031,28 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
986
1031
|
owner: input.owner,
|
|
987
1032
|
repo: input.repo,
|
|
988
1033
|
number: input.number,
|
|
1034
|
+
mode: normalizeGithubSubscriptionMode(input.mode),
|
|
989
1035
|
threadId: executionThreadContext.threadId,
|
|
990
1036
|
resourceId: executionThreadContext.resourceId
|
|
991
1037
|
});
|
|
1038
|
+
if (result.terminalState) return {
|
|
1039
|
+
subscribed: false,
|
|
1040
|
+
mode: result.mode,
|
|
1041
|
+
terminalState: result.terminalState,
|
|
1042
|
+
reason: "terminal",
|
|
1043
|
+
owner: result.owner,
|
|
1044
|
+
repo: result.repo,
|
|
1045
|
+
number: result.number,
|
|
1046
|
+
message: `Not subscribed to ${result.owner}/${result.repo}#${result.number} in review mode because it is already ${result.terminalState}.`
|
|
1047
|
+
};
|
|
992
1048
|
return {
|
|
993
1049
|
subscribed: true,
|
|
1050
|
+
mode: result.mode,
|
|
994
1051
|
owner: result.owner,
|
|
995
1052
|
repo: result.repo,
|
|
996
1053
|
number: result.number,
|
|
997
1054
|
syncStatus: result.syncResult?.ok === false ? "error" : result.syncResult ? "success" : void 0,
|
|
998
|
-
message: result.syncResult?.ok === false ? `Subscribed to ${result.owner}/${result.repo}#${result.number}, but gitcrawl sync failed: ${result.syncResult.error}` : `Subscribed to ${result.owner}/${result.repo}#${result.number}.`
|
|
1055
|
+
message: result.syncResult?.ok === false ? `Subscribed to ${result.owner}/${result.repo}#${result.number} in ${result.mode} mode, but gitcrawl sync failed: ${result.syncResult.error}` : `Subscribed to ${result.owner}/${result.repo}#${result.number} in ${result.mode} mode.`
|
|
999
1056
|
};
|
|
1000
1057
|
}
|
|
1001
1058
|
}),
|
|
@@ -1135,15 +1192,19 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1135
1192
|
const previousContentHash = subscription.lastObservedContentHash;
|
|
1136
1193
|
const previousThreadContentHash = subscription.lastObservedThreadContentHash;
|
|
1137
1194
|
const previousHeadSha = subscription.lastObservedHeadSha;
|
|
1195
|
+
const previousReviewStateHash = subscription.lastObservedReviewStateHash;
|
|
1138
1196
|
const latestCommentTimestampChanged = !!previousGithubUpdatedAt && !!snapshot?.latestCommentUpdatedAt && Date.parse(snapshot.latestCommentUpdatedAt) > Date.parse(previousGithubUpdatedAt);
|
|
1139
1197
|
const existingBotCommentEdited = latestCommentTimestampChanged && !!snapshot && isExistingBotCommentEdit(subscription, snapshot);
|
|
1140
1198
|
const latestCommentChanged = latestCommentTimestampChanged && !existingBotCommentEdited;
|
|
1199
|
+
const headChanged = !!previousHeadSha && !!snapshot?.headSha && previousHeadSha !== snapshot.headSha;
|
|
1200
|
+
const reviewStateChanged = !!previousReviewStateHash && !!snapshot?.reviewStateHash && previousReviewStateHash !== snapshot.reviewStateHash;
|
|
1141
1201
|
if (snapshot) applySnapshotCursor(nextSubscription, snapshot);
|
|
1142
1202
|
const isFirstObservation = syncResult.ok && snapshot && !previousGithubUpdatedAt && !previousContentHash;
|
|
1143
1203
|
const legacyAggregateChanged = previousContentHash && snapshot?.contentHash && previousContentHash !== snapshot.contentHash && !previousThreadContentHash && !previousHeadSha;
|
|
1144
|
-
const changed = isFirstObservation || syncResult.ok && snapshot && (legacyAggregateChanged || latestCommentChanged || previousThreadContentHash && snapshot.threadContentHash && previousThreadContentHash !== snapshot.threadContentHash && !existingBotCommentEdited ||
|
|
1145
|
-
|
|
1146
|
-
|
|
1204
|
+
const changed = isFirstObservation || syncResult.ok && snapshot && (legacyAggregateChanged || latestCommentChanged || previousThreadContentHash && snapshot.threadContentHash && previousThreadContentHash !== snapshot.threadContentHash && !existingBotCommentEdited || headChanged || subscription.lastObservedState && snapshot.state && subscription.lastObservedState !== snapshot.state || hasMeaningfulMergeableStateChange(subscription.lastObservedMergeableState, snapshot.mergeableState) || subscription.lastObservedCiState && snapshot.ciState && subscription.lastObservedCiState !== snapshot.ciState || reviewStateChanged);
|
|
1205
|
+
const terminalState = subscription.mode === "review" ? getGithubTerminalState(snapshot) : void 0;
|
|
1206
|
+
let shouldKeepSubscription = !terminalState;
|
|
1207
|
+
if ((changed || terminalState) && snapshot && !(subscription.mode === "review" && isFirstObservation && !terminalState) && isCurrentGeneration()) {
|
|
1147
1208
|
const notifications = await this.#sendActivityNotifications({
|
|
1148
1209
|
polling: input,
|
|
1149
1210
|
subscription,
|
|
@@ -1151,6 +1212,9 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1151
1212
|
previousGithubUpdatedAt,
|
|
1152
1213
|
previousContentHash,
|
|
1153
1214
|
latestCommentChanged,
|
|
1215
|
+
headChanged,
|
|
1216
|
+
reviewStateChanged,
|
|
1217
|
+
terminalState,
|
|
1154
1218
|
isCurrentGeneration
|
|
1155
1219
|
});
|
|
1156
1220
|
if (!isCurrentGeneration()) return 0;
|
|
@@ -1160,7 +1224,7 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1160
1224
|
nextSubscription.lastNotificationKind = primaryNotification.kind;
|
|
1161
1225
|
nextSubscription.lastNotificationPriority = primaryNotification.priority;
|
|
1162
1226
|
nextSubscription.lastNotificationSummary = primaryNotification.summary;
|
|
1163
|
-
shouldKeepSubscription = notifications.every((notification) => notification.kind !== "pull-request-merged");
|
|
1227
|
+
if (!terminalState) shouldKeepSubscription = notifications.every((notification) => notification.kind !== "pull-request-merged");
|
|
1164
1228
|
}
|
|
1165
1229
|
}
|
|
1166
1230
|
if (shouldKeepSubscription) subscriptions.push(nextSubscription);
|
|
@@ -1210,6 +1274,7 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1210
1274
|
owner: input.subscription.owner,
|
|
1211
1275
|
repo: input.subscription.repo,
|
|
1212
1276
|
number: input.subscription.number,
|
|
1277
|
+
mode: input.subscription.mode,
|
|
1213
1278
|
...input.snapshot.title ? { title: input.snapshot.title } : {},
|
|
1214
1279
|
...input.snapshot.state ? { state: input.snapshot.state } : {},
|
|
1215
1280
|
...input.snapshot.htmlUrl ? { url: input.snapshot.htmlUrl } : {},
|
|
@@ -1229,6 +1294,7 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1229
1294
|
owner: input.subscription.owner,
|
|
1230
1295
|
repo: input.subscription.repo,
|
|
1231
1296
|
number: input.subscription.number,
|
|
1297
|
+
mode: input.subscription.mode,
|
|
1232
1298
|
title: input.snapshot.title,
|
|
1233
1299
|
state: input.snapshot.state,
|
|
1234
1300
|
htmlUrl: input.snapshot.htmlUrl,
|
|
@@ -1371,14 +1437,36 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1371
1437
|
async #sendActivityNotifications(input) {
|
|
1372
1438
|
const agent = this.#getNotificationAgent(input.polling);
|
|
1373
1439
|
if (!agent?.sendNotificationSignal) return [];
|
|
1374
|
-
const notifications = [
|
|
1375
|
-
|
|
1376
|
-
snapshot: input.snapshot
|
|
1377
|
-
})];
|
|
1378
|
-
if (input.latestCommentChanged && notifications[0]?.kind !== "pull-request-activity") notifications.push(classifyGithubCommentActivityNotification({
|
|
1440
|
+
const notifications = [];
|
|
1441
|
+
if (input.subscription.mode === "review") if (input.terminalState) notifications.push(classifyGithubTerminalActivityNotification({
|
|
1379
1442
|
subscription: input.subscription,
|
|
1380
|
-
snapshot: input.snapshot
|
|
1443
|
+
snapshot: input.snapshot,
|
|
1444
|
+
terminalState: input.terminalState
|
|
1381
1445
|
}));
|
|
1446
|
+
else {
|
|
1447
|
+
if (input.latestCommentChanged) notifications.push(classifyGithubCommentActivityNotification({
|
|
1448
|
+
subscription: input.subscription,
|
|
1449
|
+
snapshot: input.snapshot
|
|
1450
|
+
}));
|
|
1451
|
+
if (input.headChanged) notifications.push(classifyGithubHeadActivityNotification({
|
|
1452
|
+
subscription: input.subscription,
|
|
1453
|
+
snapshot: input.snapshot
|
|
1454
|
+
}));
|
|
1455
|
+
if (input.reviewStateChanged) notifications.push(classifyGithubReviewStateActivityNotification({
|
|
1456
|
+
subscription: input.subscription,
|
|
1457
|
+
snapshot: input.snapshot
|
|
1458
|
+
}));
|
|
1459
|
+
}
|
|
1460
|
+
else {
|
|
1461
|
+
notifications.push(classifyGithubActivityNotification({
|
|
1462
|
+
subscription: input.subscription,
|
|
1463
|
+
snapshot: input.snapshot
|
|
1464
|
+
}));
|
|
1465
|
+
if (input.latestCommentChanged && notifications[0]?.kind !== "pull-request-activity") notifications.push(classifyGithubCommentActivityNotification({
|
|
1466
|
+
subscription: input.subscription,
|
|
1467
|
+
snapshot: input.snapshot
|
|
1468
|
+
}));
|
|
1469
|
+
}
|
|
1382
1470
|
const sent = [];
|
|
1383
1471
|
const notificationInputs = [];
|
|
1384
1472
|
for (const notification of notifications.sort(compareGithubActivityNotifications)) {
|
|
@@ -1418,6 +1506,7 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1418
1506
|
return sent;
|
|
1419
1507
|
}
|
|
1420
1508
|
async #subscribe(input) {
|
|
1509
|
+
const mode = normalizeGithubSubscriptionMode(input.mode);
|
|
1421
1510
|
const { owner, repo } = await this.#resolveRepository(input);
|
|
1422
1511
|
const { threadStore, loadedThread } = await this.#loadThread(input);
|
|
1423
1512
|
const githubMetadata = getGithubMetadata(loadedThread.metadata);
|
|
@@ -1427,6 +1516,7 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1427
1516
|
owner,
|
|
1428
1517
|
repo,
|
|
1429
1518
|
number: input.number,
|
|
1519
|
+
mode: existing.mode,
|
|
1430
1520
|
subscription: existing,
|
|
1431
1521
|
alreadyProcessed: true
|
|
1432
1522
|
};
|
|
@@ -1435,6 +1525,7 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1435
1525
|
owner,
|
|
1436
1526
|
repo,
|
|
1437
1527
|
number: input.number,
|
|
1528
|
+
mode,
|
|
1438
1529
|
subscribedAt: existing?.subscribedAt ?? now,
|
|
1439
1530
|
updatedAt: now,
|
|
1440
1531
|
lastSubscribeSignalId: input.id,
|
|
@@ -1478,6 +1569,35 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1478
1569
|
baselineSnapshot = snapshot;
|
|
1479
1570
|
if (snapshot) applySnapshotCursor(subscription, snapshot);
|
|
1480
1571
|
} else subscription.lastSyncStatus = "skipped";
|
|
1572
|
+
const terminalState = mode === "review" ? getGithubTerminalState(baselineSnapshot) : void 0;
|
|
1573
|
+
if (terminalState) {
|
|
1574
|
+
const subscriptions = githubMetadata.subscriptions.filter((candidate) => !(candidate.owner === owner && candidate.repo === repo && candidate.number === input.number));
|
|
1575
|
+
await threadStore.saveThread({ thread: {
|
|
1576
|
+
...loadedThread,
|
|
1577
|
+
id: input.threadId,
|
|
1578
|
+
resourceId: input.resourceId,
|
|
1579
|
+
createdAt: loadedThread.createdAt ?? /* @__PURE__ */ new Date(),
|
|
1580
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
1581
|
+
metadata: setGithubMetadata(loadedThread.metadata, { subscriptions })
|
|
1582
|
+
} });
|
|
1583
|
+
this.#notifySubscriptionsChanged({
|
|
1584
|
+
threadId: input.threadId,
|
|
1585
|
+
resourceId: input.resourceId,
|
|
1586
|
+
subscriptions
|
|
1587
|
+
});
|
|
1588
|
+
if (subscriptions.length === 0) this.stopPollingForThread({
|
|
1589
|
+
threadId: input.threadId,
|
|
1590
|
+
resourceId: input.resourceId
|
|
1591
|
+
});
|
|
1592
|
+
return {
|
|
1593
|
+
owner,
|
|
1594
|
+
repo,
|
|
1595
|
+
number: input.number,
|
|
1596
|
+
mode,
|
|
1597
|
+
terminalState,
|
|
1598
|
+
syncResult
|
|
1599
|
+
};
|
|
1600
|
+
}
|
|
1481
1601
|
const subscriptions = [subscription];
|
|
1482
1602
|
await threadStore.saveThread({ thread: {
|
|
1483
1603
|
...loadedThread,
|
|
@@ -1492,7 +1612,7 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1492
1612
|
resourceId: input.resourceId,
|
|
1493
1613
|
subscriptions
|
|
1494
1614
|
});
|
|
1495
|
-
if (baselineSnapshot) await this.#sendBaselineNotification({
|
|
1615
|
+
if (baselineSnapshot && mode === "working") await this.#sendBaselineNotification({
|
|
1496
1616
|
threadId: input.threadId,
|
|
1497
1617
|
resourceId: input.resourceId,
|
|
1498
1618
|
subscription,
|
|
@@ -1506,6 +1626,7 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1506
1626
|
owner,
|
|
1507
1627
|
repo,
|
|
1508
1628
|
number: input.number,
|
|
1629
|
+
mode,
|
|
1509
1630
|
subscription,
|
|
1510
1631
|
syncResult
|
|
1511
1632
|
};
|
|
@@ -1558,7 +1679,8 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1558
1679
|
id: readString(signal.id) ?? message.id,
|
|
1559
1680
|
owner: readString(attributes.owner) ?? readString(github.owner),
|
|
1560
1681
|
repo: readString(attributes.repo) ?? readString(github.repo),
|
|
1561
|
-
number
|
|
1682
|
+
number,
|
|
1683
|
+
...signal.tagName === "github-subscribe-pr" ? { mode: normalizeGithubSubscriptionMode(attributes.mode ?? github.mode) } : {}
|
|
1562
1684
|
};
|
|
1563
1685
|
}
|
|
1564
1686
|
async #sendStatus(args, signal, status) {
|
|
@@ -1570,14 +1692,18 @@ var GithubSignals = class extends _mastra_core_signals.SignalProvider {
|
|
|
1570
1692
|
status: status.status,
|
|
1571
1693
|
owner: signal.owner,
|
|
1572
1694
|
repo: signal.repo,
|
|
1573
|
-
number: signal.number
|
|
1695
|
+
number: signal.number,
|
|
1696
|
+
...signal.mode ? { mode: signal.mode } : {},
|
|
1697
|
+
...signal.terminalState ? { terminalState: signal.terminalState } : {}
|
|
1574
1698
|
},
|
|
1575
1699
|
metadata: { github: {
|
|
1576
1700
|
action: status.action,
|
|
1577
1701
|
status: status.status,
|
|
1578
1702
|
owner: signal.owner,
|
|
1579
1703
|
repo: signal.repo,
|
|
1580
|
-
number: signal.number
|
|
1704
|
+
number: signal.number,
|
|
1705
|
+
...signal.mode ? { mode: signal.mode } : {},
|
|
1706
|
+
...signal.terminalState ? { terminalState: signal.terminalState } : {}
|
|
1581
1707
|
} }
|
|
1582
1708
|
});
|
|
1583
1709
|
}
|