@mastra/github-signals 0.0.0-agent-learning-fetch-again-20260701152039

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/dist/index.js ADDED
@@ -0,0 +1,1371 @@
1
+ import { randomUUID, createHash } from 'crypto';
2
+ import { readFile } from 'fs/promises';
3
+ import { homedir } from 'os';
4
+ import { join } from 'path';
5
+ import { promisify } from 'util';
6
+ import { SignalProvider } from '@mastra/core/signals';
7
+ import { createTool } from '@mastra/core/tools';
8
+ import z from 'zod';
9
+
10
+ // src/index.ts
11
+ var _execFileAsync;
12
+ async function execFileAsync(file, args, options) {
13
+ if (!_execFileAsync) {
14
+ const cp = await import('child_process');
15
+ _execFileAsync = promisify(cp.execFile);
16
+ }
17
+ return _execFileAsync(file, args, options);
18
+ }
19
+ var GITHUB_SUBSCRIBE_PR_TAG = "github-subscribe-pr";
20
+ var GITHUB_UNSUBSCRIBE_PR_TAG = "github-unsubscribe-pr";
21
+ var GITHUB_SYNC_STATUS_TAG = "github-sync-status";
22
+ var GITHUB_SIGNALS_METADATA_KEY = "githubSignals";
23
+ var DEFAULT_AUTHORIZED_PERMISSIONS = ["admin", "maintain", "write"];
24
+ var DEFAULT_AUTHORIZED_BOTS = ["coderabbitai[bot]", "devin-ai-integration[bot]"];
25
+ var PERMISSION_CACHE_TTL_MS = 5 * 60 * 1e3;
26
+ var AUTHOR_GATED_NOTIFICATION_KINDS = /* @__PURE__ */ new Set(["pull-request-activity", "pull-request-review-activity"]);
27
+ var createGithubTool = createTool;
28
+ function isPlainObject(value) {
29
+ return typeof value === "object" && value !== null && !Array.isArray(value);
30
+ }
31
+ function readString(value) {
32
+ return typeof value === "string" && value.length > 0 ? value : void 0;
33
+ }
34
+ function readNumber(value) {
35
+ if (typeof value === "number" && Number.isInteger(value) && value > 0) return value;
36
+ if (typeof value === "string" && /^\d+$/.test(value)) return Number(value);
37
+ return void 0;
38
+ }
39
+ function stableJson(value) {
40
+ if (Array.isArray(value)) return `[${value.map(stableJson).join(",")}]`;
41
+ if (isPlainObject(value)) {
42
+ return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableJson(value[key])}`).join(",")}}`;
43
+ }
44
+ return JSON.stringify(value);
45
+ }
46
+ function snapshotHash(value) {
47
+ return createHash("sha256").update(stableJson(value)).digest("hex");
48
+ }
49
+ function resolveHomePath(path) {
50
+ return path.startsWith("~/") ? join(homedir(), path.slice(2)) : path;
51
+ }
52
+ async function getGitcrawlDbPath() {
53
+ if (process.env.GITCRAWL_DB_PATH) return resolveHomePath(process.env.GITCRAWL_DB_PATH);
54
+ const configPath = process.env.GITCRAWL_CONFIG_PATH ?? join(homedir(), ".config", "gitcrawl", "config.toml");
55
+ try {
56
+ const config = await readFile(resolveHomePath(configPath), "utf8");
57
+ const match = /^\s*db_path\s*=\s*['\"]([^'\"]+)['\"]/m.exec(config);
58
+ if (match?.[1]) return resolveHomePath(match[1]);
59
+ } catch {
60
+ }
61
+ return join(homedir(), ".config", "gitcrawl", "gitcrawl.db");
62
+ }
63
+ async function queryGitcrawlDb(sql) {
64
+ const dbPath = await getGitcrawlDbPath();
65
+ const { stdout } = await execFileAsync("sqlite3", ["-json", dbPath, sql], { maxBuffer: 10 * 1024 * 1024 });
66
+ return JSON.parse(stdout || "[]");
67
+ }
68
+ function sqlString(value) {
69
+ return `'${value.replaceAll("'", "''")}'`;
70
+ }
71
+ function getSignalMetadata(message) {
72
+ if (message.role !== "signal") return void 0;
73
+ const signal = message.content.metadata?.signal;
74
+ return isPlainObject(signal) ? signal : void 0;
75
+ }
76
+ function getGithubMetadata(threadMetadata) {
77
+ const mastra = isPlainObject(threadMetadata?.mastra) ? threadMetadata.mastra : {};
78
+ const githubSignals = isPlainObject(mastra[GITHUB_SIGNALS_METADATA_KEY]) ? mastra[GITHUB_SIGNALS_METADATA_KEY] : {};
79
+ const rawSubscriptions = Array.isArray(githubSignals.subscriptions) ? githubSignals.subscriptions : [];
80
+ const subscriptions = [];
81
+ for (const rawSubscription of rawSubscriptions) {
82
+ if (!isPlainObject(rawSubscription)) continue;
83
+ const owner = readString(rawSubscription.owner);
84
+ const repo = readString(rawSubscription.repo);
85
+ const number = readNumber(rawSubscription.number);
86
+ const subscribedAt = readString(rawSubscription.subscribedAt);
87
+ const updatedAt = readString(rawSubscription.updatedAt);
88
+ const lastSubscribeSignalId = readString(rawSubscription.lastSubscribeSignalId);
89
+ if (!owner || !repo || !number || !subscribedAt || !updatedAt || !lastSubscribeSignalId) continue;
90
+ subscriptions.push({
91
+ owner,
92
+ repo,
93
+ number,
94
+ subscribedAt,
95
+ updatedAt,
96
+ lastSubscribeSignalId,
97
+ ...readString(rawSubscription.lastSyncAt) ? { lastSyncAt: readString(rawSubscription.lastSyncAt) } : {},
98
+ ...rawSubscription.lastSyncStatus === "success" || rawSubscription.lastSyncStatus === "error" || rawSubscription.lastSyncStatus === "skipped" ? { lastSyncStatus: rawSubscription.lastSyncStatus } : {},
99
+ ...readString(rawSubscription.lastSyncError) ? { lastSyncError: readString(rawSubscription.lastSyncError) } : {},
100
+ ...readString(rawSubscription.lastObservedGithubUpdatedAt) ? { lastObservedGithubUpdatedAt: readString(rawSubscription.lastObservedGithubUpdatedAt) } : {},
101
+ ...readString(rawSubscription.lastObservedContentHash) ? { lastObservedContentHash: readString(rawSubscription.lastObservedContentHash) } : {},
102
+ ...readString(rawSubscription.lastObservedThreadContentHash) ? { lastObservedThreadContentHash: readString(rawSubscription.lastObservedThreadContentHash) } : {},
103
+ ...readString(rawSubscription.lastObservedHeadSha) ? { lastObservedHeadSha: readString(rawSubscription.lastObservedHeadSha) } : {},
104
+ ...readString(rawSubscription.lastObservedState) ? { lastObservedState: readString(rawSubscription.lastObservedState) } : {},
105
+ ...readString(rawSubscription.lastObservedMergeableState) ? { lastObservedMergeableState: readString(rawSubscription.lastObservedMergeableState) } : {},
106
+ ...readString(rawSubscription.lastObservedCiState) ? { lastObservedCiState: readString(rawSubscription.lastObservedCiState) } : {},
107
+ ...readString(rawSubscription.lastObservedReviewStateHash) ? { lastObservedReviewStateHash: readString(rawSubscription.lastObservedReviewStateHash) } : {},
108
+ ...readString(rawSubscription.lastNotificationAt) ? { lastNotificationAt: readString(rawSubscription.lastNotificationAt) } : {},
109
+ ...readString(rawSubscription.lastNotificationKind) ? { lastNotificationKind: readString(rawSubscription.lastNotificationKind) } : {},
110
+ ...rawSubscription.lastNotificationPriority === "medium" || rawSubscription.lastNotificationPriority === "high" ? { lastNotificationPriority: rawSubscription.lastNotificationPriority } : {},
111
+ ...readString(rawSubscription.lastNotificationSummary) ? { lastNotificationSummary: readString(rawSubscription.lastNotificationSummary) } : {}
112
+ });
113
+ }
114
+ return {
115
+ subscriptions,
116
+ ...githubSignals.subscriptionHintShown === true ? { subscriptionHintShown: true } : {}
117
+ };
118
+ }
119
+ function setGithubMetadata(threadMetadata, githubSignals) {
120
+ const existing = threadMetadata ?? {};
121
+ const mastra = isPlainObject(existing.mastra) ? existing.mastra : {};
122
+ const existingGithubSignals = isPlainObject(mastra[GITHUB_SIGNALS_METADATA_KEY]) ? mastra[GITHUB_SIGNALS_METADATA_KEY] : {};
123
+ return {
124
+ ...existing,
125
+ mastra: {
126
+ ...mastra,
127
+ [GITHUB_SIGNALS_METADATA_KEY]: {
128
+ ...existingGithubSignals,
129
+ ...githubSignals
130
+ }
131
+ }
132
+ };
133
+ }
134
+ function getFailingChecks(snapshot) {
135
+ return (snapshot.checks ?? []).filter((check) => check.conclusion === "failure" || check.conclusion === "timed_out");
136
+ }
137
+ function getPendingChecks(snapshot) {
138
+ return (snapshot.checks ?? []).filter((check) => check.status && check.status !== "completed");
139
+ }
140
+ function getPrLabel(subscription, snapshot) {
141
+ const pr = `${subscription.owner}/${subscription.repo}#${subscription.number}`;
142
+ return snapshot?.title ? `${pr}: ${snapshot.title}` : pr;
143
+ }
144
+ function getMergedNotificationSummary(label) {
145
+ return `${label} was merged. This thread has been automatically unsubscribed from this PR. Resubscribe if you still need updates.`;
146
+ }
147
+ function stripBlocks(text, open, close) {
148
+ const haystack = text.toLowerCase();
149
+ const openLower = open.toLowerCase();
150
+ const closeLower = close.toLowerCase();
151
+ let result = "";
152
+ let cursor = 0;
153
+ for (; ; ) {
154
+ const start = haystack.indexOf(openLower, cursor);
155
+ if (start === -1) {
156
+ result += text.slice(cursor);
157
+ return result;
158
+ }
159
+ result += text.slice(cursor, start);
160
+ const end = haystack.indexOf(closeLower, start + openLower.length);
161
+ if (end === -1) return result;
162
+ cursor = end + closeLower.length;
163
+ }
164
+ }
165
+ var CODE_TOKEN_PREFIX = "\0CODE";
166
+ var CODE_TOKEN_SUFFIX = "\0";
167
+ function preserveMarkdownCode(text) {
168
+ const preserved = [];
169
+ const stash = (match) => {
170
+ const token = `${CODE_TOKEN_PREFIX}${preserved.length}${CODE_TOKEN_SUFFIX}`;
171
+ preserved.push(match);
172
+ return token;
173
+ };
174
+ const protectedText = text.replace(/```[\s\S]*?```/g, stash).replace(/(`{2,})(?!`)[\s\S]*?[^`]\1(?!`)/g, stash).replace(/`[^`\n]*`/g, stash);
175
+ return {
176
+ text: protectedText,
177
+ restore: (sanitized) => sanitized.replace(/\u0000CODE(\d+)\u0000/g, (_, index) => preserved[Number(index)] ?? "")
178
+ };
179
+ }
180
+ function sanitizeCommentText(body) {
181
+ const { text: protectedBody, restore } = preserveMarkdownCode(body);
182
+ let text = stripBlocks(protectedBody, "<!--", "-->");
183
+ text = stripBlocks(text, "<details", "</details>");
184
+ const stripped = text.replace(/<\/?[a-zA-Z][^<>]*>/g, "").replace(/<[!/a-zA-Z][\s\S]*$/g, "").replace(/</g, "").replace(/\n{3,}/g, "\n\n").trim();
185
+ return restore(stripped);
186
+ }
187
+ function sanitizeCommentBody(body) {
188
+ if (body === void 0) return void 0;
189
+ const sanitized = sanitizeCommentText(body);
190
+ return sanitized.length > 0 ? sanitized : void 0;
191
+ }
192
+ function getCommentExcerpt(body) {
193
+ const excerpt = sanitizeCommentText(body).replace(/\s+/g, " ").trim();
194
+ return excerpt.length > 240 ? `${excerpt.slice(0, 237)}...` : excerpt;
195
+ }
196
+ function getCommentNotificationSummary(pr, snapshot) {
197
+ if (!snapshot.latestCommentAuthor || !snapshot.latestCommentBody) return void 0;
198
+ return `${snapshot.latestCommentAuthor} commented on ${pr}: ${getCommentExcerpt(snapshot.latestCommentBody)}`;
199
+ }
200
+ var githubActivityNotificationPriority = {
201
+ high: 0,
202
+ medium: 1
203
+ };
204
+ function getGithubActivityNotificationRank(notification) {
205
+ return notification.kind === "pull-request-activity" ? 0 : 1;
206
+ }
207
+ function compareGithubActivityNotifications(a, b) {
208
+ if (!a && !b) return 0;
209
+ if (!a) return 1;
210
+ if (!b) return -1;
211
+ const priorityComparison = githubActivityNotificationPriority[a.priority] - githubActivityNotificationPriority[b.priority];
212
+ if (priorityComparison !== 0) return priorityComparison;
213
+ return getGithubActivityNotificationRank(a) - getGithubActivityNotificationRank(b);
214
+ }
215
+ function classifyGithubCommentActivityNotification(input) {
216
+ if (isBotOnlyActivity(input.snapshot)) return void 0;
217
+ const pr = `${input.subscription.owner}/${input.subscription.repo}#${input.subscription.number}`;
218
+ const summary = getCommentNotificationSummary(pr, input.snapshot);
219
+ if (!summary) return void 0;
220
+ return { kind: "pull-request-activity", priority: "high", summary };
221
+ }
222
+ function getCheckUpdatedTime(check) {
223
+ const value = check.updatedAt ? Date.parse(check.updatedAt) : Number.NaN;
224
+ return Number.isFinite(value) ? value : 0;
225
+ }
226
+ function getCheckKey(check) {
227
+ return `${check.name || "check"}:${check.detailsUrl || check.workflowName || ""}`;
228
+ }
229
+ function normalizeGithubChecksForSnapshot(input) {
230
+ const latestCheckUpdatedAt = input.checkRows.reduce(
231
+ (latest, check) => Math.max(latest, getCheckUpdatedTime(check)),
232
+ 0
233
+ );
234
+ const rows = [
235
+ ...input.checkRows,
236
+ ...input.workflowRows.filter(
237
+ (workflow) => input.checkRows.length === 0 || getCheckUpdatedTime(workflow) >= latestCheckUpdatedAt
238
+ )
239
+ ];
240
+ const byKey = /* @__PURE__ */ new Map();
241
+ for (const row of rows) {
242
+ const key = getCheckKey(row);
243
+ const existing = byKey.get(key);
244
+ if (!existing) {
245
+ byKey.set(key, row);
246
+ continue;
247
+ }
248
+ const rowTime = getCheckUpdatedTime(row);
249
+ const existingTime = getCheckUpdatedTime(existing);
250
+ if (rowTime > existingTime || rowTime === existingTime && existing.source === "workflow" && row.source === "check") {
251
+ byKey.set(key, row);
252
+ }
253
+ }
254
+ return [...byKey.values()].map(({ source: _source, ...check }) => check).sort((a, b) => `${a.name}:${a.detailsUrl ?? ""}`.localeCompare(`${b.name}:${b.detailsUrl ?? ""}`));
255
+ }
256
+ function isBotOnlyActivity(snapshot) {
257
+ return snapshot.latestCommentIsBot === true && (!snapshot.ciState || snapshot.ciState === "unknown");
258
+ }
259
+ function stringifyEvidence(value) {
260
+ if (typeof value === "string") return value;
261
+ try {
262
+ return JSON.stringify(value);
263
+ } catch {
264
+ return "";
265
+ }
266
+ }
267
+ function detectPrWorkEvidence(input) {
268
+ const evidence = [
269
+ input.text ?? "",
270
+ ...(input.toolCalls ?? []).map((toolCall) => `${toolCall.toolName} ${stringifyEvidence(toolCall.args)}`)
271
+ ].join("\n");
272
+ if (!evidence.trim()) return void 0;
273
+ const url = /github\.com\/([^\s/#]+)\/([^\s/#]+)\/pull\/(\d+)/i.exec(evidence);
274
+ if (url?.[1] && url[2] && url[3]) return { owner: url[1], repo: url[2], number: Number(url[3]) };
275
+ const repoRef = /\b([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)#(\d+)\b/.exec(evidence);
276
+ if (repoRef?.[1] && repoRef[2] && repoRef[3])
277
+ return { owner: repoRef[1], repo: repoRef[2], number: Number(repoRef[3]) };
278
+ const ghCommand = /\bgh\s+(?:pr\s+(?:view|checks|status|comment|diff|checkout)|run\s+(?:rerun|view))\b/i.test(
279
+ evidence
280
+ );
281
+ if (!ghCommand) return void 0;
282
+ const numberMatch = /(?:^|\s)#?(\d{2,})(?:\s|$)/.exec(evidence);
283
+ return numberMatch?.[1] ? { number: Number(numberMatch[1]) } : void 0;
284
+ }
285
+ function classifyGithubActivityNotification(input) {
286
+ const pr = `${input.subscription.owner}/${input.subscription.repo}#${input.subscription.number}`;
287
+ const label = getPrLabel(input.subscription, input.snapshot);
288
+ if (input.snapshot.state && input.subscription.lastObservedState !== input.snapshot.state) {
289
+ if (input.snapshot.state === "merged")
290
+ return {
291
+ kind: "pull-request-merged",
292
+ priority: "high",
293
+ summary: getMergedNotificationSummary(label)
294
+ };
295
+ if (input.snapshot.state === "closed")
296
+ return { kind: "pull-request-closed", priority: "high", summary: `${label} was closed` };
297
+ if (input.subscription.lastObservedState && input.snapshot.state === "open")
298
+ return { kind: "pull-request-reopened", priority: "medium", summary: `${label} was reopened` };
299
+ }
300
+ const failingChecks = getFailingChecks(input.snapshot);
301
+ if (input.snapshot.ciState === "failure" && input.subscription.lastObservedCiState !== "failure") {
302
+ const names = failingChecks.slice(0, 3).map((check) => check.name).join(", ");
303
+ return {
304
+ kind: "pull-request-ci-failure",
305
+ priority: "high",
306
+ summary: `${pr} has failing CI${names ? `: ${names}` : ""}`
307
+ };
308
+ }
309
+ if (input.snapshot.mergeableState === "dirty" && input.subscription.lastObservedMergeableState !== "dirty") {
310
+ return {
311
+ kind: "pull-request-conflict",
312
+ priority: "high",
313
+ summary: `${pr} has merge conflicts${input.snapshot.title ? `: ${input.snapshot.title}` : ""}`
314
+ };
315
+ }
316
+ if (input.snapshot.mergeableState && input.subscription.lastObservedMergeableState === "dirty" && input.snapshot.mergeableState !== "dirty") {
317
+ return {
318
+ kind: "pull-request-conflict-resolved",
319
+ priority: "medium",
320
+ summary: `${pr} merge conflicts were resolved`
321
+ };
322
+ }
323
+ if (input.snapshot.mergeableState === "dirty") return void 0;
324
+ if (input.snapshot.ciState === "success" && input.subscription.lastObservedCiState && input.subscription.lastObservedCiState !== "success") {
325
+ return { kind: "pull-request-ci-recovered", priority: "medium", summary: `${pr} CI recovered` };
326
+ }
327
+ if (input.snapshot.reviewStateHash && input.subscription.lastObservedReviewStateHash && input.snapshot.reviewStateHash !== input.subscription.lastObservedReviewStateHash && (input.snapshot.unresolvedReviewThreads ?? 0) > 0) {
328
+ return {
329
+ kind: "pull-request-review-activity",
330
+ priority: "medium",
331
+ summary: `${pr} has ${input.snapshot.unresolvedReviewThreads} unresolved review thread${input.snapshot.unresolvedReviewThreads === 1 ? "" : "s"}`
332
+ };
333
+ }
334
+ const pendingChecks = getPendingChecks(input.snapshot);
335
+ if (input.snapshot.ciState === "pending" && input.subscription.lastObservedCiState !== "pending" && pendingChecks.length > 0) {
336
+ const names = pendingChecks.slice(0, 3).map((check) => check.name).join(", ");
337
+ return {
338
+ kind: "pull-request-ci-pending",
339
+ priority: "medium",
340
+ summary: `${pr} has CI still running${names ? `: ${names}` : ""}`
341
+ };
342
+ }
343
+ if (input.snapshot.ciState === "pending" && input.subscription.lastObservedCiState === "pending") return void 0;
344
+ if (isBotOnlyActivity(input.snapshot)) return void 0;
345
+ const commentSummary = getCommentNotificationSummary(pr, input.snapshot);
346
+ return {
347
+ kind: "pull-request-activity",
348
+ priority: commentSummary ? "high" : "medium",
349
+ summary: commentSummary ?? `${pr} has new activity${input.snapshot.title ? `: ${input.snapshot.title}` : ""}`
350
+ };
351
+ }
352
+ function classifyGithubBaselineNotification(input) {
353
+ const pr = `${input.subscription.owner}/${input.subscription.repo}#${input.subscription.number}`;
354
+ const failingChecks = getFailingChecks(input.snapshot);
355
+ const reviewCount = input.snapshot.unresolvedReviewThreads ?? 0;
356
+ const high = input.snapshot.ciState === "failure" || input.snapshot.mergeableState === "dirty";
357
+ const details = [
358
+ input.snapshot.state ? `state: ${input.snapshot.state}` : void 0,
359
+ input.snapshot.ciState && input.snapshot.ciState !== "unknown" ? `CI: ${input.snapshot.ciState}` : void 0,
360
+ input.snapshot.mergeableState ? `mergeability: ${input.snapshot.mergeableState}` : void 0,
361
+ reviewCount > 0 ? `${reviewCount} unresolved review thread${reviewCount === 1 ? "" : "s"}` : void 0,
362
+ failingChecks.length > 0 ? `failing: ${failingChecks.slice(0, 3).map((check) => check.name).join(", ")}` : void 0
363
+ ].filter(Boolean);
364
+ return {
365
+ kind: "pull-request-baseline",
366
+ priority: high ? "high" : "medium",
367
+ summary: `${pr} subscribed${input.snapshot.title ? `: ${input.snapshot.title}` : ""}${details.length ? ` (${details.join("; ")})` : ""}`
368
+ };
369
+ }
370
+ function applySnapshotCursor(subscription, snapshot) {
371
+ if (snapshot.githubUpdatedAt) subscription.lastObservedGithubUpdatedAt = snapshot.githubUpdatedAt;
372
+ if (snapshot.contentHash) subscription.lastObservedContentHash = snapshot.contentHash;
373
+ if (snapshot.threadContentHash) subscription.lastObservedThreadContentHash = snapshot.threadContentHash;
374
+ if (snapshot.headSha) subscription.lastObservedHeadSha = snapshot.headSha;
375
+ if (snapshot.state) subscription.lastObservedState = snapshot.state;
376
+ if (snapshot.mergeableState) subscription.lastObservedMergeableState = snapshot.mergeableState;
377
+ if (snapshot.ciState) subscription.lastObservedCiState = snapshot.ciState;
378
+ if (snapshot.reviewStateHash) subscription.lastObservedReviewStateHash = snapshot.reviewStateHash;
379
+ }
380
+ function parseGitHubRemoteUrl(remoteUrl) {
381
+ const trimmed = remoteUrl.trim().replace(/\.git$/, "");
382
+ const httpsMatch = /^https:\/\/github\.com\/([^/]+)\/([^/]+)$/.exec(trimmed);
383
+ if (httpsMatch?.[1] && httpsMatch[2]) return { owner: httpsMatch[1], repo: httpsMatch[2] };
384
+ const sshMatch = /^git@github\.com:([^/]+)\/([^/]+)$/.exec(trimmed);
385
+ if (sshMatch?.[1] && sshMatch[2]) return { owner: sshMatch[1], repo: sshMatch[2] };
386
+ return void 0;
387
+ }
388
+ var GitRemoteRepositoryResolver = class {
389
+ async resolveRepository(input) {
390
+ try {
391
+ const { stdout } = await execFileAsync("git", ["remote", "get-url", "origin"], {
392
+ cwd: input.cwd,
393
+ signal: input.abortSignal
394
+ });
395
+ return parseGitHubRemoteUrl(stdout);
396
+ } catch {
397
+ return void 0;
398
+ }
399
+ }
400
+ };
401
+ var GitcrawlSyncClient = class {
402
+ #command;
403
+ constructor(options = {}) {
404
+ this.#command = options.command ?? "gitcrawl";
405
+ }
406
+ async syncPullRequest(input) {
407
+ try {
408
+ const args = [
409
+ "sync",
410
+ `${input.owner}/${input.repo}`,
411
+ "--numbers",
412
+ String(input.number),
413
+ ...input.includeComments === false ? [] : ["--include-comments"],
414
+ "--with",
415
+ "pr-details",
416
+ "--json"
417
+ ];
418
+ const { stdout, stderr } = await execFileAsync(this.#command, args, {
419
+ cwd: input.cwd,
420
+ signal: input.abortSignal,
421
+ maxBuffer: 10 * 1024 * 1024
422
+ });
423
+ return { ok: true, stdout, stderr };
424
+ } catch (error) {
425
+ return { ok: false, error: error instanceof Error ? error.message : String(error) };
426
+ }
427
+ }
428
+ async getPullRequestSnapshot(input) {
429
+ try {
430
+ const { stdout } = await execFileAsync(
431
+ this.#command,
432
+ ["threads", `${input.owner}/${input.repo}`, "--numbers", String(input.number), "--json"],
433
+ {
434
+ cwd: input.cwd,
435
+ signal: input.abortSignal,
436
+ maxBuffer: 10 * 1024 * 1024
437
+ }
438
+ );
439
+ const parsed = JSON.parse(stdout);
440
+ const thread = parsed.threads?.find((item) => readNumber(item.number) === input.number);
441
+ if (!thread) return void 0;
442
+ const owner = sqlString(input.owner);
443
+ const repo = sqlString(input.repo);
444
+ const number = input.number;
445
+ const [threadDetails] = await queryGitcrawlDb(`select t.state, t.closed_at_gh, t.merged_at_gh
446
+ from threads t
447
+ join repositories r on r.id=t.repo_id
448
+ where r.owner=${owner} and r.name=${repo} and t.number=${number}
449
+ limit 1`);
450
+ const [details] = await queryGitcrawlDb(`select d.head_sha, d.head_ref, d.mergeable_state,
451
+ json_extract(d.raw_json, '$.merged_at') as merged_at
452
+ from pull_request_details d
453
+ join threads t on t.id=d.thread_id
454
+ join repositories r on r.id=t.repo_id
455
+ where r.owner=${owner} and r.name=${repo} and t.number=${number}
456
+ limit 1`);
457
+ const headSha = readString(details?.head_sha);
458
+ const checkRows = await queryGitcrawlDb(`select c.name, c.status, c.conclusion, c.workflow_name, c.details_url,
459
+ coalesce(c.completed_at, c.started_at, c.fetched_at) as updated_at
460
+ from pull_request_checks c
461
+ join threads t on t.id=c.thread_id
462
+ join repositories r on r.id=t.repo_id
463
+ where r.owner=${owner} and r.name=${repo} and t.number=${number}${headSha ? ` and json_extract(c.raw_json, '$.head_sha')=${sqlString(headSha)}` : ""}`);
464
+ const workflowRows = details?.head_sha ? await queryGitcrawlDb(`select workflow_name, status, conclusion, html_url, updated_at_gh
465
+ from github_workflow_runs w
466
+ join repositories r on r.id=w.repo_id
467
+ where r.owner=${owner} and r.name=${repo} and w.head_sha=${sqlString(details.head_sha)}`) : [];
468
+ const [reviewState] = await queryGitcrawlDb(`select count(*) as unresolved_count,
469
+ max(coalesce(first_comment_updated_at, first_comment_created_at, fetched_at)) as latest_review_thread_at
470
+ from pull_request_review_threads rt
471
+ join threads t on t.id=rt.thread_id
472
+ join repositories r on r.id=t.repo_id
473
+ where r.owner=${owner} and r.name=${repo} and t.number=${number} and rt.is_resolved=0`);
474
+ const latestComments = await queryGitcrawlDb(`select c.author_login, c.author_type, c.is_bot, c.body, json_extract(c.raw_json, '$.html_url') as html_url,
475
+ coalesce(c.updated_at_gh, c.created_at_gh) as updated_at
476
+ from comments c
477
+ join threads t on t.id=c.thread_id
478
+ join repositories r on r.id=t.repo_id
479
+ where r.owner=${owner} and r.name=${repo} and t.number=${number}
480
+ order by coalesce(c.updated_at_gh, c.created_at_gh) desc
481
+ limit 20`);
482
+ const latestComment = latestComments[0];
483
+ const checks = normalizeGithubChecksForSnapshot({
484
+ checkRows: checkRows.map((row) => ({
485
+ source: "check",
486
+ name: readString(row.name) ?? "check",
487
+ status: readString(row.status),
488
+ conclusion: readString(row.conclusion),
489
+ workflowName: readString(row.workflow_name),
490
+ detailsUrl: readString(row.details_url),
491
+ updatedAt: readString(row.updated_at)
492
+ })),
493
+ workflowRows: workflowRows.map((row) => ({
494
+ source: "workflow",
495
+ name: readString(row.workflow_name) ?? "workflow",
496
+ status: readString(row.status),
497
+ conclusion: readString(row.conclusion),
498
+ workflowName: readString(row.workflow_name),
499
+ detailsUrl: readString(row.html_url),
500
+ updatedAt: readString(row.updated_at_gh)
501
+ }))
502
+ });
503
+ const ciState = checks.some((check) => check.conclusion === "failure" || check.conclusion === "timed_out") ? "failure" : checks.some((check) => check.status && check.status !== "completed") ? "pending" : checks.length > 0 ? "success" : "unknown";
504
+ const threadContentHash = readString(thread.content_hash);
505
+ const unresolvedReviewThreads = Number(reviewState?.unresolved_count ?? 0);
506
+ const reviewStateHash = snapshotHash({
507
+ unresolvedReviewThreads,
508
+ latestReviewThreadAt: reviewState?.latest_review_thread_at
509
+ });
510
+ const contentHash = snapshotHash({
511
+ threadContentHash,
512
+ state: thread.state,
513
+ headSha: details?.head_sha,
514
+ mergeableState: details?.mergeable_state,
515
+ ciState,
516
+ reviewStateHash,
517
+ checks: checks.map((check) => ({
518
+ name: check.name,
519
+ status: check.status,
520
+ conclusion: check.conclusion,
521
+ detailsUrl: check.detailsUrl,
522
+ updatedAt: check.updatedAt
523
+ }))
524
+ });
525
+ return {
526
+ title: readString(thread.title),
527
+ state: readString(details?.merged_at) || readString(threadDetails?.merged_at_gh) ? "merged" : readString(threadDetails?.state) ?? readString(thread.state),
528
+ htmlUrl: readString(thread.html_url),
529
+ githubUpdatedAt: readString(thread.updated_at_gh),
530
+ closedAt: readString(threadDetails?.closed_at_gh),
531
+ mergedAt: readString(details?.merged_at) ?? readString(threadDetails?.merged_at_gh),
532
+ threadContentHash,
533
+ contentHash,
534
+ headSha: readString(details?.head_sha),
535
+ headRef: readString(details?.head_ref),
536
+ mergeableState: readString(details?.mergeable_state),
537
+ checks,
538
+ ciState,
539
+ unresolvedReviewThreads,
540
+ reviewStateHash,
541
+ latestReviewThreadAt: readString(reviewState?.latest_review_thread_at),
542
+ latestCommentAuthor: readString(latestComment?.author_login),
543
+ latestCommentAuthorType: readString(latestComment?.author_type),
544
+ latestCommentIsBot: latestComment?.is_bot === 1,
545
+ latestCommentBody: sanitizeCommentBody(readString(latestComment?.body)),
546
+ latestCommentUrl: readString(latestComment?.html_url),
547
+ latestCommentUpdatedAt: readString(latestComment?.updated_at),
548
+ latestComments: latestComments.map((comment) => ({
549
+ author: readString(comment.author_login),
550
+ authorType: readString(comment.author_type),
551
+ isBot: comment.is_bot === 1,
552
+ body: sanitizeCommentBody(readString(comment.body)),
553
+ url: readString(comment.html_url),
554
+ updatedAt: readString(comment.updated_at)
555
+ }))
556
+ };
557
+ } catch {
558
+ return void 0;
559
+ }
560
+ }
561
+ };
562
+ var GithubSignals = class extends SignalProvider {
563
+ id = "github-signals";
564
+ name = "GitHub Signals";
565
+ #ghMastra;
566
+ static signals = {
567
+ subscribeToPR(input) {
568
+ const normalized = typeof input === "number" ? { number: input } : input;
569
+ return {
570
+ type: "reactive",
571
+ tagName: GITHUB_SUBSCRIBE_PR_TAG,
572
+ contents: `Subscribe to GitHub PR #${normalized.number}`,
573
+ attributes: {
574
+ ...normalized.owner ? { owner: normalized.owner } : {},
575
+ ...normalized.repo ? { repo: normalized.repo } : {},
576
+ number: normalized.number
577
+ },
578
+ metadata: {
579
+ github: {
580
+ action: "subscribeToPR",
581
+ ...normalized
582
+ }
583
+ }
584
+ };
585
+ },
586
+ unsubscribeFromPR(input) {
587
+ const normalized = typeof input === "number" ? { number: input } : input;
588
+ return {
589
+ type: "reactive",
590
+ tagName: GITHUB_UNSUBSCRIBE_PR_TAG,
591
+ contents: `Unsubscribe from GitHub PR #${normalized.number}`,
592
+ attributes: {
593
+ ...normalized.owner ? { owner: normalized.owner } : {},
594
+ ...normalized.repo ? { repo: normalized.repo } : {},
595
+ number: normalized.number
596
+ },
597
+ metadata: {
598
+ github: {
599
+ action: "unsubscribeFromPR",
600
+ ...normalized
601
+ }
602
+ }
603
+ };
604
+ }
605
+ };
606
+ #options;
607
+ #syncClient;
608
+ #repositoryResolver;
609
+ #polling = /* @__PURE__ */ new Map();
610
+ #permissionCache = /* @__PURE__ */ new Map();
611
+ #agent;
612
+ #agentOptions = {};
613
+ #subscriptionsChangedHandler;
614
+ #pollingChangedHandler;
615
+ constructor(options = {}) {
616
+ super();
617
+ this.#options = options;
618
+ this.#syncClient = options.syncClient ?? new GitcrawlSyncClient({ command: options.gitcrawlCommand });
619
+ this.#repositoryResolver = options.repositoryResolver ?? new GitRemoteRepositoryResolver();
620
+ if (options.getNotificationStreamOptions) {
621
+ this.#agentOptions = { getNotificationStreamOptions: options.getNotificationStreamOptions };
622
+ }
623
+ }
624
+ /**
625
+ * @deprecated Use `Agent({ signals: [githubSignals] })` instead.
626
+ * Kept for backward compatibility.
627
+ */
628
+ addAgent(agent, options = {}) {
629
+ this.#agent = agent;
630
+ this.#agentOptions = options;
631
+ }
632
+ /**
633
+ * Called by the Agent constructor when this provider is passed via `signals: [...]`.
634
+ * Sets the bidirectional link so the provider can send signals back to the agent.
635
+ */
636
+ connect(agent) {
637
+ super.connect(agent);
638
+ this.#agent = agent;
639
+ }
640
+ getInputProcessors() {
641
+ return [this];
642
+ }
643
+ getOutputProcessors() {
644
+ return [this];
645
+ }
646
+ onSubscriptionsChanged(handler) {
647
+ this.#subscriptionsChangedHandler = handler;
648
+ }
649
+ onPollingChanged(handler) {
650
+ this.#pollingChangedHandler = handler;
651
+ }
652
+ __registerMastra(mastra) {
653
+ super.__registerMastra(mastra);
654
+ this.#ghMastra = mastra;
655
+ }
656
+ async syncThreadNow(input) {
657
+ return this.#pollThread(input, { includeComments: true });
658
+ }
659
+ async subscribeThreadToPR(input) {
660
+ const pr = typeof input.pr === "number" ? { number: input.pr } : input.pr;
661
+ return this.#subscribe({
662
+ id: `github-command-subscribe-${randomUUID()}`,
663
+ ...pr,
664
+ threadId: input.threadId,
665
+ resourceId: input.resourceId
666
+ });
667
+ }
668
+ async unsubscribeThreadFromPR(input) {
669
+ const pr = typeof input.pr === "number" ? { number: input.pr } : input.pr;
670
+ return this.#unsubscribe({
671
+ id: `github-command-unsubscribe-${randomUUID()}`,
672
+ ...pr,
673
+ threadId: input.threadId,
674
+ resourceId: input.resourceId
675
+ });
676
+ }
677
+ async startPollingForThread(input, options = {}) {
678
+ const subscriptions = await this.#getThreadSubscriptions(input);
679
+ if (subscriptions.length === 0) {
680
+ this.stopPollingForThread(input);
681
+ return false;
682
+ }
683
+ const key = this.#pollingKey(input);
684
+ for (const [pollingKey, state] of this.#polling.entries()) {
685
+ if (pollingKey === key) continue;
686
+ clearInterval(state.timer);
687
+ this.#polling.delete(pollingKey);
688
+ }
689
+ if (this.#polling.has(key)) return true;
690
+ const runPoll = (pollOptions = {}) => {
691
+ void this.#pollThread(input, pollOptions).catch((error) => {
692
+ console.warn("GitHub PR polling failed:", error);
693
+ });
694
+ };
695
+ const timer = setInterval(() => {
696
+ runPoll({ includeComments: true });
697
+ }, this.#options.pollIntervalMs ?? 3e5);
698
+ if (options.pollImmediately) runPoll({ includeComments: true });
699
+ timer.unref?.();
700
+ this.#polling.set(key, { ...input, timer, running: false });
701
+ return true;
702
+ }
703
+ stopPollingForThread(input) {
704
+ const key = this.#pollingKey(input);
705
+ const state = this.#polling.get(key);
706
+ if (!state) return;
707
+ clearInterval(state.timer);
708
+ this.#polling.delete(key);
709
+ }
710
+ isPollingThread(input) {
711
+ return this.#polling.has(this.#pollingKey(input));
712
+ }
713
+ isPollingThreadRunning(input) {
714
+ return this.#polling.get(this.#pollingKey(input))?.running ?? false;
715
+ }
716
+ getPollIntervalMs() {
717
+ return this.#options.pollIntervalMs ?? 3e5;
718
+ }
719
+ stopAllPolling() {
720
+ for (const state of this.#polling.values()) clearInterval(state.timer);
721
+ this.#polling.clear();
722
+ }
723
+ async pollThreadNow(input) {
724
+ return this.#pollThread(input, { includeComments: true });
725
+ }
726
+ async processInputStep(args) {
727
+ const tools = this.#createTools(args);
728
+ if (args.stepNumber !== 0) return { tools };
729
+ const signal = this.#findLatestGithubSignal(args.messages);
730
+ if (!signal) return { tools };
731
+ const threadContext = this.#getThreadContext(args);
732
+ if (signal.tagName === GITHUB_UNSUBSCRIBE_PR_TAG) {
733
+ const result2 = await this.#unsubscribe({ ...signal, ...threadContext, abortSignal: args.abortSignal });
734
+ await this.#sendStatus(args, result2, {
735
+ status: result2.removed ? "unsubscribed" : "not_subscribed",
736
+ action: "unsubscribeFromPR",
737
+ message: result2.removed ? `Unsubscribed from ${result2.owner}/${result2.repo}#${result2.number}.` : `No GitHub subscription found for ${result2.owner}/${result2.repo}#${result2.number}.`
738
+ });
739
+ return { tools };
740
+ }
741
+ const result = await this.#subscribe({ ...signal, ...threadContext, abortSignal: args.abortSignal });
742
+ if (result.alreadyProcessed) return { tools };
743
+ await this.#sendStatus(args, result, {
744
+ status: result.syncResult?.ok === false ? "sync_error" : "subscribed",
745
+ action: "subscribeToPR",
746
+ 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}.`
747
+ });
748
+ return { tools };
749
+ }
750
+ async processOutputStep(args) {
751
+ const evidence = detectPrWorkEvidence({ text: args.text, toolCalls: args.toolCalls });
752
+ if (!evidence) return;
753
+ const threadContext = this.#getThreadContext(args);
754
+ if (!threadContext.threadId || !threadContext.resourceId) return;
755
+ const { threadStore, loadedThread } = await this.#loadThread(threadContext);
756
+ const githubMetadata = getGithubMetadata(loadedThread.metadata);
757
+ if (githubMetadata.subscriptionHintShown || githubMetadata.subscriptions.length > 0) return;
758
+ let repository;
759
+ try {
760
+ repository = await this.#resolveRepository({
761
+ id: "github-subscription-hint",
762
+ owner: evidence.owner,
763
+ repo: evidence.repo,
764
+ number: evidence.number
765
+ });
766
+ } catch {
767
+ return;
768
+ }
769
+ await threadStore.saveThread({
770
+ thread: {
771
+ ...loadedThread,
772
+ id: threadContext.threadId,
773
+ resourceId: threadContext.resourceId,
774
+ createdAt: loadedThread.createdAt ?? /* @__PURE__ */ new Date(),
775
+ updatedAt: /* @__PURE__ */ new Date(),
776
+ metadata: setGithubMetadata(loadedThread.metadata, { ...githubMetadata, subscriptionHintShown: true })
777
+ }
778
+ });
779
+ await args.sendSignal?.({
780
+ type: "reactive",
781
+ tagName: "system-reminder",
782
+ contents: `Looks like you're working with ${repository.owner}/${repository.repo}#${evidence.number}. Use /github subscribe ${evidence.number} or the github_subscribe_pr tool to follow updates.`,
783
+ attributes: { type: "github-subscription-hint" },
784
+ metadata: {
785
+ github: {
786
+ action: "subscriptionHint",
787
+ owner: repository.owner,
788
+ repo: repository.repo,
789
+ number: evidence.number
790
+ }
791
+ }
792
+ });
793
+ }
794
+ async #resolveThreadStore() {
795
+ if (this.#options.threadStore) return this.#options.threadStore;
796
+ const storage = this.#ghMastra?.getStorage?.();
797
+ const memoryStore = storage?.getStore ? await storage.getStore("memory") : void 0;
798
+ return memoryStore;
799
+ }
800
+ #getThreadContext(args) {
801
+ const memoryContext = args.requestContext?.get("MastraMemory");
802
+ return { threadId: memoryContext?.thread?.id, resourceId: memoryContext?.resourceId };
803
+ }
804
+ #createTools(args) {
805
+ const threadContext = this.#getThreadContext(args);
806
+ const getExecutionThreadContext = (context) => ({
807
+ threadId: context?.agent?.threadId ?? threadContext.threadId,
808
+ resourceId: context?.agent?.resourceId ?? threadContext.resourceId
809
+ });
810
+ return {
811
+ ...args.tools,
812
+ github_subscribe_pr: createGithubTool({
813
+ id: "github_subscribe_pr",
814
+ description: "Subscribe this thread to a GitHub pull request. Syncs only the requested PR with gitcrawl and stores the subscription on the thread.",
815
+ inputSchema: z.object({
816
+ number: z.number().int().positive(),
817
+ owner: z.string().optional(),
818
+ repo: z.string().optional()
819
+ }),
820
+ execute: async (input, context) => {
821
+ const executionThreadContext = getExecutionThreadContext(context);
822
+ const result = await this.#subscribe({
823
+ id: `github-tool-subscribe-${randomUUID()}`,
824
+ owner: input.owner,
825
+ repo: input.repo,
826
+ number: input.number,
827
+ threadId: executionThreadContext.threadId,
828
+ resourceId: executionThreadContext.resourceId
829
+ });
830
+ return {
831
+ subscribed: true,
832
+ owner: result.owner,
833
+ repo: result.repo,
834
+ number: result.number,
835
+ syncStatus: result.syncResult?.ok === false ? "error" : result.syncResult ? "success" : void 0,
836
+ 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}.`
837
+ };
838
+ }
839
+ }),
840
+ github_unsubscribe_pr: createGithubTool({
841
+ id: "github_unsubscribe_pr",
842
+ description: "Unsubscribe this thread from a GitHub pull request.",
843
+ inputSchema: z.object({
844
+ number: z.number().int().positive(),
845
+ owner: z.string().optional(),
846
+ repo: z.string().optional()
847
+ }),
848
+ execute: async (input, context) => {
849
+ const executionThreadContext = getExecutionThreadContext(context);
850
+ const result = await this.#unsubscribe({
851
+ id: `github-tool-unsubscribe-${randomUUID()}`,
852
+ owner: input.owner,
853
+ repo: input.repo,
854
+ number: input.number,
855
+ threadId: executionThreadContext.threadId,
856
+ resourceId: executionThreadContext.resourceId
857
+ });
858
+ return {
859
+ unsubscribed: result.removed ?? false,
860
+ owner: result.owner,
861
+ repo: result.repo,
862
+ number: result.number,
863
+ remainingSubscriptions: result.remainingSubscriptions,
864
+ message: result.removed ? `Unsubscribed from ${result.owner}/${result.repo}#${result.number}.` : `No GitHub subscription found for ${result.owner}/${result.repo}#${result.number}.`
865
+ };
866
+ }
867
+ })
868
+ };
869
+ }
870
+ async #resolveRepository(input) {
871
+ const resolvedRepository = input.owner && input.repo ? { owner: input.owner, repo: input.repo } : this.#options.owner && this.#options.repo ? { owner: this.#options.owner, repo: this.#options.repo } : await this.#repositoryResolver.resolveRepository({
872
+ cwd: this.#options.cwd,
873
+ abortSignal: input.abortSignal
874
+ });
875
+ if (!resolvedRepository?.owner || !resolvedRepository.repo) {
876
+ throw new Error(
877
+ "GitHub PR subscription requires owner and repo. Run inside a GitHub repo or pass owner and repo."
878
+ );
879
+ }
880
+ return resolvedRepository;
881
+ }
882
+ async #loadThread(input) {
883
+ const threadStore = await this.#resolveThreadStore();
884
+ if (!threadStore) throw new Error("GitHub PR subscription requires memory-backed thread storage.");
885
+ if (!input.threadId || !input.resourceId)
886
+ throw new Error("GitHub PR subscription requires threadId and resourceId.");
887
+ const loadedThread = await threadStore.getThreadById({ threadId: input.threadId, resourceId: input.resourceId }) ?? void 0;
888
+ if (!loadedThread) throw new Error(`Could not load thread ${input.threadId}.`);
889
+ return { threadStore, loadedThread };
890
+ }
891
+ #pollingKey(input) {
892
+ return `${input.resourceId}:${input.threadId}`;
893
+ }
894
+ #getNotificationAgent(_input) {
895
+ if (this.#agent) return this.#agent;
896
+ const agentId = _input?.agentId ?? this.#options.agentId;
897
+ return agentId ? this.#ghMastra?.getAgentById?.(agentId) : void 0;
898
+ }
899
+ async #getThreadSubscriptions(input) {
900
+ const { loadedThread } = await this.#loadThread(input);
901
+ return getGithubMetadata(loadedThread.metadata).subscriptions;
902
+ }
903
+ #notifySubscriptionsChanged(input) {
904
+ this.#subscriptionsChangedHandler?.(input);
905
+ }
906
+ #notifyPollingChanged(input) {
907
+ this.#pollingChangedHandler?.(input);
908
+ }
909
+ async #pollThread(input, options = {}) {
910
+ const key = this.#pollingKey(input);
911
+ const state = this.#polling.get(key);
912
+ if (state?.running) {
913
+ return 0;
914
+ }
915
+ if (state) state.running = true;
916
+ this.#notifyPollingChanged({ threadId: input.threadId, resourceId: input.resourceId, running: true });
917
+ try {
918
+ const { threadStore, loadedThread } = await this.#loadThread(input);
919
+ const githubMetadata = getGithubMetadata(loadedThread.metadata);
920
+ if (githubMetadata.subscriptions.length === 0) {
921
+ this.stopPollingForThread(input);
922
+ return 0;
923
+ }
924
+ const now = (/* @__PURE__ */ new Date()).toISOString();
925
+ const subscriptions = [];
926
+ for (const subscription of githubMetadata.subscriptions) {
927
+ const syncInput = {
928
+ owner: subscription.owner,
929
+ repo: subscription.repo,
930
+ number: subscription.number,
931
+ cwd: this.#options.cwd,
932
+ includeComments: options.includeComments
933
+ };
934
+ const syncResult = await this.#syncClient.syncPullRequest(syncInput);
935
+ let snapshot = syncResult.ok ? await this.#syncClient.getPullRequestSnapshot?.(syncInput) : void 0;
936
+ if (snapshot)
937
+ snapshot = await this.#filterUnauthorizedLatestComment(subscription.owner, subscription.repo, snapshot);
938
+ const nextSubscription = {
939
+ ...subscription,
940
+ updatedAt: now,
941
+ lastSyncAt: now,
942
+ lastSyncStatus: syncResult.ok ? "success" : "error"
943
+ };
944
+ if (syncResult.error) nextSubscription.lastSyncError = syncResult.error;
945
+ else delete nextSubscription.lastSyncError;
946
+ const previousGithubUpdatedAt = subscription.lastObservedGithubUpdatedAt;
947
+ const previousContentHash = subscription.lastObservedContentHash;
948
+ const previousThreadContentHash = subscription.lastObservedThreadContentHash;
949
+ const previousHeadSha = subscription.lastObservedHeadSha;
950
+ const latestCommentChanged = !!previousGithubUpdatedAt && !!snapshot?.latestCommentUpdatedAt && Date.parse(snapshot.latestCommentUpdatedAt) > Date.parse(previousGithubUpdatedAt);
951
+ if (snapshot) applySnapshotCursor(nextSubscription, snapshot);
952
+ const isFirstObservation = syncResult.ok && snapshot && !previousGithubUpdatedAt && !previousContentHash;
953
+ const legacyAggregateChanged = previousContentHash && snapshot?.contentHash && previousContentHash !== snapshot.contentHash && !previousThreadContentHash && !previousHeadSha;
954
+ const changed = isFirstObservation || syncResult.ok && snapshot && (legacyAggregateChanged || latestCommentChanged || previousThreadContentHash && snapshot.threadContentHash && previousThreadContentHash !== snapshot.threadContentHash || previousHeadSha && snapshot.headSha && previousHeadSha !== snapshot.headSha || subscription.lastObservedState && snapshot.state && subscription.lastObservedState !== snapshot.state || subscription.lastObservedMergeableState && snapshot.mergeableState && subscription.lastObservedMergeableState !== snapshot.mergeableState || subscription.lastObservedCiState && snapshot.ciState && subscription.lastObservedCiState !== snapshot.ciState || subscription.lastObservedReviewStateHash && snapshot.reviewStateHash && subscription.lastObservedReviewStateHash !== snapshot.reviewStateHash);
955
+ let shouldKeepSubscription = true;
956
+ if (changed && snapshot) {
957
+ const notifications = await this.#sendActivityNotifications({
958
+ polling: input,
959
+ subscription,
960
+ snapshot,
961
+ previousGithubUpdatedAt,
962
+ previousContentHash,
963
+ latestCommentChanged
964
+ });
965
+ const primaryNotification = notifications[0];
966
+ if (primaryNotification) {
967
+ nextSubscription.lastNotificationAt = now;
968
+ nextSubscription.lastNotificationKind = primaryNotification.kind;
969
+ nextSubscription.lastNotificationPriority = primaryNotification.priority;
970
+ nextSubscription.lastNotificationSummary = primaryNotification.summary;
971
+ shouldKeepSubscription = notifications.every((notification) => notification.kind !== "pull-request-merged");
972
+ }
973
+ }
974
+ if (shouldKeepSubscription) subscriptions.push(nextSubscription);
975
+ }
976
+ await threadStore.saveThread({
977
+ thread: {
978
+ ...loadedThread,
979
+ id: input.threadId,
980
+ resourceId: input.resourceId,
981
+ createdAt: loadedThread.createdAt ?? /* @__PURE__ */ new Date(),
982
+ updatedAt: /* @__PURE__ */ new Date(),
983
+ metadata: setGithubMetadata(loadedThread.metadata, { subscriptions })
984
+ }
985
+ });
986
+ this.#notifySubscriptionsChanged({ threadId: input.threadId, resourceId: input.resourceId, subscriptions });
987
+ if (subscriptions.length === 0) this.stopPollingForThread(input);
988
+ return subscriptions.length;
989
+ } catch (error) {
990
+ throw error;
991
+ } finally {
992
+ const latestState = this.#polling.get(key);
993
+ if (latestState) latestState.running = false;
994
+ this.#notifyPollingChanged({ threadId: input.threadId, resourceId: input.resourceId, running: false });
995
+ }
996
+ }
997
+ #createGithubNotificationInput(input) {
998
+ const failingChecks = getFailingChecks(input.snapshot);
999
+ const pendingChecks = getPendingChecks(input.snapshot);
1000
+ const latestCommentExcerpt = input.snapshot.latestCommentBody ? getCommentExcerpt(input.snapshot.latestCommentBody) : void 0;
1001
+ const latestCommentDedupeSuffix = input.notification.kind === "pull-request-activity" && input.snapshot.latestCommentUrl ? `comment:${input.snapshot.latestCommentUrl}:${input.snapshot.latestCommentUpdatedAt ?? ""}` : input.dedupeSuffix;
1002
+ const notificationInput = {
1003
+ source: "github",
1004
+ kind: input.notification.kind,
1005
+ priority: input.notification.priority,
1006
+ summary: input.notification.summary,
1007
+ dedupeKey: `github:${input.subscription.owner}/${input.subscription.repo}#${input.subscription.number}:${latestCommentDedupeSuffix}`,
1008
+ coalesceKey: `github:${input.subscription.owner}/${input.subscription.repo}#${input.subscription.number}:${input.notification.kind}`,
1009
+ attributes: {
1010
+ owner: input.subscription.owner,
1011
+ repo: input.subscription.repo,
1012
+ number: input.subscription.number,
1013
+ ...input.snapshot.title ? { title: input.snapshot.title } : {},
1014
+ ...input.snapshot.state ? { state: input.snapshot.state } : {},
1015
+ ...input.snapshot.htmlUrl ? { url: input.snapshot.htmlUrl } : {},
1016
+ ...input.snapshot.githubUpdatedAt ? { githubUpdatedAt: input.snapshot.githubUpdatedAt } : {},
1017
+ ...input.previousGithubUpdatedAt ? { previousGithubUpdatedAt: input.previousGithubUpdatedAt } : {},
1018
+ ...input.snapshot.mergeableState ? { mergeableState: input.snapshot.mergeableState } : {},
1019
+ ...input.snapshot.ciState ? { ciState: input.snapshot.ciState } : {},
1020
+ ...input.snapshot.unresolvedReviewThreads !== void 0 ? { unresolvedReviewThreads: input.snapshot.unresolvedReviewThreads } : {},
1021
+ ...input.snapshot.latestCommentAuthor ? { latestCommentAuthor: input.snapshot.latestCommentAuthor } : {},
1022
+ ...latestCommentExcerpt ? { latestCommentExcerpt } : {},
1023
+ ...input.snapshot.latestCommentUrl ? { latestCommentUrl: input.snapshot.latestCommentUrl } : {},
1024
+ ...input.snapshot.latestCommentUpdatedAt ? { latestCommentUpdatedAt: input.snapshot.latestCommentUpdatedAt } : {},
1025
+ ...failingChecks.length > 0 ? { failingChecks: failingChecks.map((check) => check.name).join(", ") } : {},
1026
+ ...pendingChecks.length > 0 ? { pendingChecks: pendingChecks.map((check) => check.name).join(", ") } : {}
1027
+ },
1028
+ metadata: {
1029
+ github: {
1030
+ owner: input.subscription.owner,
1031
+ repo: input.subscription.repo,
1032
+ number: input.subscription.number,
1033
+ title: input.snapshot.title,
1034
+ state: input.snapshot.state,
1035
+ htmlUrl: input.snapshot.htmlUrl,
1036
+ githubUpdatedAt: input.snapshot.githubUpdatedAt,
1037
+ previousGithubUpdatedAt: input.previousGithubUpdatedAt,
1038
+ contentHash: input.snapshot.contentHash,
1039
+ previousContentHash: input.previousContentHash,
1040
+ threadContentHash: input.snapshot.threadContentHash,
1041
+ headSha: input.snapshot.headSha,
1042
+ headRef: input.snapshot.headRef,
1043
+ mergeableState: input.snapshot.mergeableState,
1044
+ ciState: input.snapshot.ciState,
1045
+ closedAt: input.snapshot.closedAt,
1046
+ mergedAt: input.snapshot.mergedAt,
1047
+ unresolvedReviewThreads: input.snapshot.unresolvedReviewThreads,
1048
+ reviewStateHash: input.snapshot.reviewStateHash,
1049
+ latestReviewThreadAt: input.snapshot.latestReviewThreadAt,
1050
+ latestCommentAuthor: input.snapshot.latestCommentAuthor,
1051
+ latestCommentAuthorType: input.snapshot.latestCommentAuthorType,
1052
+ latestCommentIsBot: input.snapshot.latestCommentIsBot,
1053
+ // Intentionally omit the full latestCommentBody here: persisting it verbatim bloats
1054
+ // notification payloads (a single CodeRabbit comment can exceed 100KB) and can overflow
1055
+ // agent context windows when listed. The 240-char latestCommentExcerpt is stored instead.
1056
+ latestCommentExcerpt,
1057
+ latestCommentUrl: input.snapshot.latestCommentUrl,
1058
+ latestCommentUpdatedAt: input.snapshot.latestCommentUpdatedAt,
1059
+ failingChecks,
1060
+ pendingChecks
1061
+ }
1062
+ }
1063
+ };
1064
+ return notificationInput;
1065
+ }
1066
+ async #sendGithubNotification(input) {
1067
+ const notificationInput = this.#createGithubNotificationInput(input);
1068
+ const streamOptions = await this.#agentOptions.getNotificationStreamOptions?.(input.target);
1069
+ await input.agent?.sendNotificationSignal?.(
1070
+ notificationInput,
1071
+ streamOptions ? { ...input.target, ifIdle: { streamOptions } } : input.target
1072
+ );
1073
+ }
1074
+ async #sendBaselineNotification(input) {
1075
+ const agent = this.#getNotificationAgent({});
1076
+ if (!agent?.sendNotificationSignal) return;
1077
+ await this.#sendGithubNotification({
1078
+ agent,
1079
+ subscription: input.subscription,
1080
+ snapshot: input.snapshot,
1081
+ notification: classifyGithubBaselineNotification({ subscription: input.subscription, snapshot: input.snapshot }),
1082
+ target: { resourceId: input.resourceId, threadId: input.threadId },
1083
+ dedupeSuffix: `baseline:${input.subscription.lastSubscribeSignalId}`
1084
+ });
1085
+ }
1086
+ async #isAuthorizedAuthor(owner, repo, user, metadata = {}) {
1087
+ if (!user) return false;
1088
+ const normalizedUser = user.toLowerCase();
1089
+ const isBot = metadata.isBot === true || metadata.authorType?.toLowerCase() === "bot" || normalizedUser.endsWith("[bot]");
1090
+ if (isBot) {
1091
+ const ignoredBots = this.#options.ignoredBots ?? [];
1092
+ if (ignoredBots.some((bot) => bot.toLowerCase() === normalizedUser)) return false;
1093
+ const authorizedBots = this.#options.authorizedBots ?? DEFAULT_AUTHORIZED_BOTS;
1094
+ return authorizedBots.some((bot) => bot.toLowerCase() === normalizedUser);
1095
+ }
1096
+ const permission = await this.#loadAuthorPermission(owner, repo, user);
1097
+ const authorizedPermissions = this.#options.authorizedPermissions ?? DEFAULT_AUTHORIZED_PERMISSIONS;
1098
+ return !!permission && authorizedPermissions.includes(permission);
1099
+ }
1100
+ async #filterUnauthorizedLatestComment(owner, repo, snapshot) {
1101
+ const comments = snapshot.latestComments?.length ? snapshot.latestComments : [
1102
+ {
1103
+ author: snapshot.latestCommentAuthor,
1104
+ authorType: snapshot.latestCommentAuthorType,
1105
+ isBot: snapshot.latestCommentIsBot,
1106
+ body: snapshot.latestCommentBody,
1107
+ url: snapshot.latestCommentUrl,
1108
+ updatedAt: snapshot.latestCommentUpdatedAt
1109
+ }
1110
+ ];
1111
+ if (!comments.some((comment) => comment.author)) return snapshot;
1112
+ if (!comments.some((comment) => comment.body || comment.url || comment.updatedAt)) return snapshot;
1113
+ for (const comment of comments) {
1114
+ if (!await this.#isAuthorizedAuthor(owner, repo, comment.author, {
1115
+ authorType: comment.authorType,
1116
+ isBot: comment.isBot
1117
+ })) {
1118
+ continue;
1119
+ }
1120
+ return {
1121
+ ...snapshot,
1122
+ latestCommentAuthor: comment.author,
1123
+ latestCommentAuthorType: comment.authorType,
1124
+ latestCommentIsBot: comment.isBot,
1125
+ latestCommentBody: comment.body,
1126
+ latestCommentUrl: comment.url,
1127
+ latestCommentUpdatedAt: comment.updatedAt
1128
+ };
1129
+ }
1130
+ return {
1131
+ ...snapshot,
1132
+ latestCommentAuthor: void 0,
1133
+ latestCommentAuthorType: void 0,
1134
+ latestCommentIsBot: void 0,
1135
+ latestCommentBody: void 0,
1136
+ latestCommentUrl: void 0,
1137
+ latestCommentUpdatedAt: void 0
1138
+ };
1139
+ }
1140
+ async #loadAuthorPermission(owner, repo, user) {
1141
+ const cacheKey = `${owner}/${repo}:${user.toLowerCase()}`;
1142
+ const cached = this.#permissionCache.get(cacheKey);
1143
+ if (cached && cached.expiresAt > Date.now()) return cached.permission;
1144
+ if (cached) this.#permissionCache.delete(cacheKey);
1145
+ try {
1146
+ let permission;
1147
+ if (this.#options.permissionResolver) {
1148
+ permission = await this.#options.permissionResolver.getPermission(owner, repo, user);
1149
+ } else {
1150
+ const { stdout } = await execFileAsync("gh", [
1151
+ "api",
1152
+ `repos/${owner}/${repo}/collaborators/${user}/permission`,
1153
+ "--jq",
1154
+ ".permission"
1155
+ ]);
1156
+ const raw = stdout.trim();
1157
+ permission = ["admin", "maintain", "write", "triage", "read", "none"].includes(
1158
+ raw
1159
+ ) ? raw : void 0;
1160
+ }
1161
+ if (permission) {
1162
+ this.#permissionCache.set(cacheKey, { permission, expiresAt: Date.now() + PERMISSION_CACHE_TTL_MS });
1163
+ }
1164
+ return permission;
1165
+ } catch {
1166
+ this.#permissionCache.delete(cacheKey);
1167
+ return void 0;
1168
+ }
1169
+ }
1170
+ async #sendActivityNotifications(input) {
1171
+ const agent = this.#getNotificationAgent(input.polling);
1172
+ if (!agent?.sendNotificationSignal) return [];
1173
+ const notifications = [
1174
+ classifyGithubActivityNotification({
1175
+ subscription: input.subscription,
1176
+ snapshot: input.snapshot
1177
+ })
1178
+ ];
1179
+ if (input.latestCommentChanged && notifications[0]?.kind !== "pull-request-activity") {
1180
+ notifications.push(
1181
+ classifyGithubCommentActivityNotification({
1182
+ subscription: input.subscription,
1183
+ snapshot: input.snapshot
1184
+ })
1185
+ );
1186
+ }
1187
+ const sent = [];
1188
+ const notificationInputs = [];
1189
+ for (const notification of notifications.sort(compareGithubActivityNotifications)) {
1190
+ if (!notification) continue;
1191
+ if (AUTHOR_GATED_NOTIFICATION_KINDS.has(notification.kind)) {
1192
+ const authorized = await this.#isAuthorizedAuthor(
1193
+ input.subscription.owner,
1194
+ input.subscription.repo,
1195
+ input.snapshot.latestCommentAuthor,
1196
+ {
1197
+ authorType: input.snapshot.latestCommentAuthorType,
1198
+ isBot: input.snapshot.latestCommentIsBot
1199
+ }
1200
+ );
1201
+ if (!authorized) continue;
1202
+ }
1203
+ notificationInputs.push(
1204
+ this.#createGithubNotificationInput({
1205
+ subscription: input.subscription,
1206
+ snapshot: input.snapshot,
1207
+ notification,
1208
+ dedupeSuffix: input.snapshot.contentHash ?? input.snapshot.githubUpdatedAt ?? String(Date.now()),
1209
+ previousGithubUpdatedAt: input.previousGithubUpdatedAt,
1210
+ previousContentHash: input.previousContentHash
1211
+ })
1212
+ );
1213
+ sent.push(notification);
1214
+ }
1215
+ if (notificationInputs.length > 0) {
1216
+ const target = { resourceId: input.polling.resourceId, threadId: input.polling.threadId };
1217
+ const streamOptions = await this.#agentOptions.getNotificationStreamOptions?.(target);
1218
+ await agent.sendNotificationSignal(
1219
+ notificationInputs,
1220
+ streamOptions ? { ...target, ifIdle: { streamOptions } } : target
1221
+ );
1222
+ }
1223
+ return sent;
1224
+ }
1225
+ async #subscribe(input) {
1226
+ const { owner, repo } = await this.#resolveRepository(input);
1227
+ const { threadStore, loadedThread } = await this.#loadThread(input);
1228
+ const githubMetadata = getGithubMetadata(loadedThread.metadata);
1229
+ const existingIndex = githubMetadata.subscriptions.findIndex(
1230
+ (subscription2) => subscription2.owner === owner && subscription2.repo === repo && subscription2.number === input.number
1231
+ );
1232
+ const existing = existingIndex >= 0 ? githubMetadata.subscriptions[existingIndex] : void 0;
1233
+ if (existing?.lastSubscribeSignalId === input.id) {
1234
+ return { owner, repo, number: input.number, subscription: existing, alreadyProcessed: true };
1235
+ }
1236
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1237
+ const subscription = {
1238
+ owner,
1239
+ repo,
1240
+ number: input.number,
1241
+ subscribedAt: existing?.subscribedAt ?? now,
1242
+ updatedAt: now,
1243
+ lastSubscribeSignalId: input.id,
1244
+ ...existing?.lastSyncAt ? { lastSyncAt: existing.lastSyncAt } : {},
1245
+ ...existing?.lastSyncStatus ? { lastSyncStatus: existing.lastSyncStatus } : {},
1246
+ ...existing?.lastSyncError ? { lastSyncError: existing.lastSyncError } : {},
1247
+ ...existing?.lastObservedGithubUpdatedAt ? { lastObservedGithubUpdatedAt: existing.lastObservedGithubUpdatedAt } : {},
1248
+ ...existing?.lastObservedContentHash ? { lastObservedContentHash: existing.lastObservedContentHash } : {},
1249
+ ...existing?.lastObservedThreadContentHash ? { lastObservedThreadContentHash: existing.lastObservedThreadContentHash } : {},
1250
+ ...existing?.lastObservedHeadSha ? { lastObservedHeadSha: existing.lastObservedHeadSha } : {},
1251
+ ...existing?.lastObservedState ? { lastObservedState: existing.lastObservedState } : {},
1252
+ ...existing?.lastObservedMergeableState ? { lastObservedMergeableState: existing.lastObservedMergeableState } : {},
1253
+ ...existing?.lastObservedCiState ? { lastObservedCiState: existing.lastObservedCiState } : {},
1254
+ ...existing?.lastObservedReviewStateHash ? { lastObservedReviewStateHash: existing.lastObservedReviewStateHash } : {}
1255
+ };
1256
+ let syncResult;
1257
+ let baselineSnapshot;
1258
+ if (this.#options.syncOnSubscribe !== false) {
1259
+ const syncInput = {
1260
+ owner,
1261
+ repo,
1262
+ number: input.number,
1263
+ cwd: this.#options.cwd,
1264
+ abortSignal: input.abortSignal
1265
+ };
1266
+ syncResult = await this.#syncClient.syncPullRequest(syncInput);
1267
+ subscription.lastSyncAt = (/* @__PURE__ */ new Date()).toISOString();
1268
+ subscription.lastSyncStatus = syncResult.ok ? "success" : "error";
1269
+ if (syncResult.error) subscription.lastSyncError = syncResult.error;
1270
+ else delete subscription.lastSyncError;
1271
+ const snapshot = syncResult.ok ? await this.#syncClient.getPullRequestSnapshot?.(syncInput) : void 0;
1272
+ baselineSnapshot = snapshot;
1273
+ if (snapshot) applySnapshotCursor(subscription, snapshot);
1274
+ } else {
1275
+ subscription.lastSyncStatus = "skipped";
1276
+ }
1277
+ const subscriptions = [subscription];
1278
+ await threadStore.saveThread({
1279
+ thread: {
1280
+ ...loadedThread,
1281
+ id: input.threadId,
1282
+ resourceId: input.resourceId,
1283
+ createdAt: loadedThread.createdAt ?? /* @__PURE__ */ new Date(),
1284
+ updatedAt: /* @__PURE__ */ new Date(),
1285
+ metadata: setGithubMetadata(loadedThread.metadata, { subscriptions })
1286
+ }
1287
+ });
1288
+ this.#notifySubscriptionsChanged({ threadId: input.threadId, resourceId: input.resourceId, subscriptions });
1289
+ if (baselineSnapshot) {
1290
+ await this.#sendBaselineNotification({
1291
+ threadId: input.threadId,
1292
+ resourceId: input.resourceId,
1293
+ subscription,
1294
+ snapshot: baselineSnapshot
1295
+ });
1296
+ }
1297
+ await this.startPollingForThread({ threadId: input.threadId, resourceId: input.resourceId });
1298
+ return { owner, repo, number: input.number, subscription, syncResult };
1299
+ }
1300
+ async #unsubscribe(input) {
1301
+ const { owner, repo } = await this.#resolveRepository(input);
1302
+ const { threadStore, loadedThread } = await this.#loadThread(input);
1303
+ const githubMetadata = getGithubMetadata(loadedThread.metadata);
1304
+ const subscriptions = githubMetadata.subscriptions.filter(
1305
+ (subscription) => !(subscription.owner === owner && subscription.repo === repo && subscription.number === input.number)
1306
+ );
1307
+ const removed = subscriptions.length !== githubMetadata.subscriptions.length;
1308
+ if (removed) {
1309
+ await threadStore.saveThread({
1310
+ thread: {
1311
+ ...loadedThread,
1312
+ id: input.threadId,
1313
+ resourceId: input.resourceId,
1314
+ createdAt: loadedThread.createdAt ?? /* @__PURE__ */ new Date(),
1315
+ updatedAt: /* @__PURE__ */ new Date(),
1316
+ metadata: setGithubMetadata(loadedThread.metadata, { subscriptions })
1317
+ }
1318
+ });
1319
+ this.#notifySubscriptionsChanged({ threadId: input.threadId, resourceId: input.resourceId, subscriptions });
1320
+ if (subscriptions.length === 0)
1321
+ this.stopPollingForThread({ threadId: input.threadId, resourceId: input.resourceId });
1322
+ }
1323
+ return { owner, repo, number: input.number, removed, remainingSubscriptions: subscriptions.length };
1324
+ }
1325
+ #findLatestGithubSignal(messages) {
1326
+ const message = messages.at(-1);
1327
+ if (!message) return void 0;
1328
+ const signal = getSignalMetadata(message);
1329
+ if (!signal || signal.tagName !== GITHUB_SUBSCRIBE_PR_TAG && signal.tagName !== GITHUB_UNSUBSCRIBE_PR_TAG) {
1330
+ return void 0;
1331
+ }
1332
+ const attributes = isPlainObject(signal.attributes) ? signal.attributes : {};
1333
+ const metadata = isPlainObject(signal.metadata) ? signal.metadata : {};
1334
+ const github = isPlainObject(metadata.github) ? metadata.github : {};
1335
+ const number = readNumber(attributes.number) ?? readNumber(github.number);
1336
+ if (!number) return void 0;
1337
+ return {
1338
+ tagName: String(signal.tagName),
1339
+ id: readString(signal.id) ?? message.id,
1340
+ owner: readString(attributes.owner) ?? readString(github.owner),
1341
+ repo: readString(attributes.repo) ?? readString(github.repo),
1342
+ number
1343
+ };
1344
+ }
1345
+ async #sendStatus(args, signal, status) {
1346
+ await args.sendSignal?.({
1347
+ type: "reactive",
1348
+ tagName: GITHUB_SYNC_STATUS_TAG,
1349
+ contents: status.message,
1350
+ attributes: {
1351
+ status: status.status,
1352
+ owner: signal.owner,
1353
+ repo: signal.repo,
1354
+ number: signal.number
1355
+ },
1356
+ metadata: {
1357
+ github: {
1358
+ action: status.action,
1359
+ status: status.status,
1360
+ owner: signal.owner,
1361
+ repo: signal.repo,
1362
+ number: signal.number
1363
+ }
1364
+ }
1365
+ });
1366
+ }
1367
+ };
1368
+
1369
+ export { GITHUB_SIGNALS_METADATA_KEY, GITHUB_SUBSCRIBE_PR_TAG, GITHUB_SYNC_STATUS_TAG, GITHUB_UNSUBSCRIBE_PR_TAG, GitRemoteRepositoryResolver, GitcrawlSyncClient, GithubSignals, normalizeGithubChecksForSnapshot, sanitizeCommentText };
1370
+ //# sourceMappingURL=index.js.map
1371
+ //# sourceMappingURL=index.js.map