@oss-autopilot/core 3.38.0 → 3.39.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/dist/cli-registry.js +7 -4
- package/dist/cli.bundle.cjs +139 -132
- package/dist/commands/daily-dismiss-filter.d.ts +37 -0
- package/dist/commands/daily-dismiss-filter.js +80 -0
- package/dist/commands/daily-merged-pr-notes.d.ts +27 -0
- package/dist/commands/daily-merged-pr-notes.js +166 -0
- package/dist/commands/daily-reviewed-prs.d.ts +41 -0
- package/dist/commands/daily-reviewed-prs.js +270 -0
- package/dist/commands/daily-warnings.d.ts +28 -0
- package/dist/commands/daily-warnings.js +37 -0
- package/dist/commands/daily.d.ts +22 -1
- package/dist/commands/daily.js +287 -107
- package/dist/commands/dashboard-cache.js +9 -2
- package/dist/commands/dashboard-data.js +40 -20
- package/dist/commands/dashboard-gist-sync.d.ts +4 -0
- package/dist/commands/dashboard-gist-sync.js +5 -1
- package/dist/commands/dismiss.d.ts +25 -5
- package/dist/commands/dismiss.js +38 -10
- package/dist/commands/overnight.js +14 -1
- package/dist/commands/scout-bridge.js +4 -1
- package/dist/commands/validation.d.ts +11 -0
- package/dist/commands/validation.js +16 -0
- package/dist/core/checklist-analysis.js +34 -0
- package/dist/core/closed-pr-status.d.ts +73 -0
- package/dist/core/closed-pr-status.js +113 -0
- package/dist/core/comment-decision.d.ts +10 -3
- package/dist/core/comment-decision.js +13 -5
- package/dist/core/comment-utils.d.ts +38 -1
- package/dist/core/comment-utils.js +124 -1
- package/dist/core/concurrency.d.ts +6 -0
- package/dist/core/concurrency.js +13 -0
- package/dist/core/daily-logic.d.ts +13 -1
- package/dist/core/daily-logic.js +59 -2
- package/dist/core/engaged-issues.d.ts +93 -0
- package/dist/core/engaged-issues.js +183 -0
- package/dist/core/errors.d.ts +4 -0
- package/dist/core/errors.js +10 -0
- package/dist/core/github-stats.d.ts +10 -0
- package/dist/core/github-stats.js +35 -0
- package/dist/core/index.d.ts +10 -5
- package/dist/core/index.js +9 -4
- package/dist/core/issue-conversation.d.ts +83 -12
- package/dist/core/issue-conversation.js +306 -118
- package/dist/core/merged-pr-notes.d.ts +192 -0
- package/dist/core/merged-pr-notes.js +340 -0
- package/dist/core/pr-assembly.js +3 -0
- package/dist/core/pr-monitor.d.ts +62 -0
- package/dist/core/pr-monitor.js +113 -3
- package/dist/core/reviewed-prs-fetch.d.ts +91 -0
- package/dist/core/reviewed-prs-fetch.js +271 -0
- package/dist/core/reviewed-prs.d.ts +244 -0
- package/dist/core/reviewed-prs.js +380 -0
- package/dist/core/state-persistence.js +4 -23
- package/dist/core/state-schema.d.ts +6 -0
- package/dist/core/state-schema.js +9 -0
- package/dist/core/state.d.ts +70 -8
- package/dist/core/state.js +101 -10
- package/dist/core/types.d.ts +47 -0
- package/dist/core/urls.d.ts +13 -0
- package/dist/core/urls.js +16 -0
- package/dist/formatters/json.d.ts +186 -1
- package/dist/formatters/json.js +78 -0
- package/package.json +1 -1
|
@@ -1,24 +1,73 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Issue Conversation Monitor — tracks issues the user has commented on
|
|
3
|
-
* and detects
|
|
2
|
+
* Issue Conversation Monitor — tracks issues the user has commented on or is
|
|
3
|
+
* working on, and detects replies that need attention.
|
|
4
4
|
*
|
|
5
5
|
* Follows the same pattern as PRMonitor: stateless fetch from GitHub,
|
|
6
6
|
* bounded concurrency via worker pool, bot/acknowledgment filtering.
|
|
7
|
+
*
|
|
8
|
+
* Two reply rules apply (#1862):
|
|
9
|
+
* - On an issue the user only commented on in passing, a reply counts when
|
|
10
|
+
* it is directed at the user: from a maintainer (OWNER / MEMBER /
|
|
11
|
+
* COLLABORATOR), @mentions the user, or quotes the user's comment (#343).
|
|
12
|
+
* - On an engaged issue (claimed, or linked from one of the user's PRs; see
|
|
13
|
+
* `collectEngagedIssues`), any substantive non-bot comment after the
|
|
14
|
+
* user's last word counts, and so does anything directed at the user even
|
|
15
|
+
* when short (a maintainer's "any update?"). Short thanks and "+1" /
|
|
16
|
+
* emoji-only reactions do not, except that a bare status request on a
|
|
17
|
+
* claimed issue is addressed to the claimant and counts. Engaged issues
|
|
18
|
+
* the comment search does not return (the user never commented, or not
|
|
19
|
+
* within the window) are fetched directly, up to
|
|
20
|
+
* {@link MAX_DIRECT_ENGAGED_FETCHES} per run.
|
|
7
21
|
*/
|
|
8
22
|
import { getOctokit } from './github.js';
|
|
9
|
-
import { isBotAuthor, isAcknowledgmentComment } from './comment-utils.js';
|
|
10
|
-
import { paginateAllDetailed } from './pagination.js';
|
|
23
|
+
import { isBotAuthor, isAcknowledgmentComment, isReactionOnlyComment, isQuoteReplyTo, isStatusNudge, } from './comment-utils.js';
|
|
24
|
+
import { paginateAll, paginateAllDetailed } from './pagination.js';
|
|
11
25
|
import { getHttpCache, cachedRequest } from './http-cache.js';
|
|
12
26
|
import { getStateManager } from './state.js';
|
|
13
27
|
import { daysBetween } from './dates.js';
|
|
14
|
-
import { splitRepo, extractOwnerRepo, isOwnRepo } from './urls.js';
|
|
28
|
+
import { splitRepo, extractOwnerRepo, isOwnRepo, parseGitHubUrl, issueRefKey } from './urls.js';
|
|
15
29
|
import { runWorkerPool, DEFAULT_CONCURRENCY } from './concurrency.js';
|
|
16
|
-
import {
|
|
30
|
+
import { toIssueEngagement } from './engaged-issues.js';
|
|
31
|
+
import { ConfigurationError, ValidationError, errorMessage, getHttpStatusCode, isRateLimitOrAuthError, } from './errors.js';
|
|
17
32
|
import { debug, warn } from './logger.js';
|
|
18
33
|
const MODULE = 'issue-conversation';
|
|
19
34
|
const MAX_CONCURRENT_REQUESTS = DEFAULT_CONCURRENCY;
|
|
35
|
+
/**
|
|
36
|
+
* Most engaged issues fetched directly per run when the comment search
|
|
37
|
+
* misses them (#1862). Each costs one issue lookup plus its comment pages,
|
|
38
|
+
* all ETag-cached, so a quiet day is mostly 304s; the cap bounds a first run
|
|
39
|
+
* for a user with many open claims. Strongest engagements come first, so
|
|
40
|
+
* the open-PR and claim issues are the ones kept.
|
|
41
|
+
*/
|
|
42
|
+
export const MAX_DIRECT_ENGAGED_FETCHES = 25;
|
|
20
43
|
/** Associations that indicate someone with repo-level permissions. */
|
|
21
44
|
const MAINTAINER_ASSOCIATIONS = new Set(['OWNER', 'MEMBER', 'COLLABORATOR']);
|
|
45
|
+
function parseMs(value) {
|
|
46
|
+
if (!value)
|
|
47
|
+
return -Infinity;
|
|
48
|
+
const ms = Date.parse(value);
|
|
49
|
+
return Number.isNaN(ms) ? -Infinity : ms;
|
|
50
|
+
}
|
|
51
|
+
function excerpt(body) {
|
|
52
|
+
return body.slice(0, 200) + (body.length > 200 ? '...' : '');
|
|
53
|
+
}
|
|
54
|
+
function describeError(error) {
|
|
55
|
+
const status = getHttpStatusCode(error);
|
|
56
|
+
return status === undefined ? errorMessage(error) : `HTTP ${status}: ${errorMessage(error)}`;
|
|
57
|
+
}
|
|
58
|
+
/** 404/410: the issue is gone (deleted, transferred, or now private). */
|
|
59
|
+
function isGoneError(error) {
|
|
60
|
+
const status = getHttpStatusCode(error);
|
|
61
|
+
return status === 404 || status === 410;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Whether a gone engaged issue is worth a warning: a claim or an open PR
|
|
65
|
+
* still points at it and the user can release the claim or fix the PR's
|
|
66
|
+
* closing link. A finished PR's link is history; nothing to act on.
|
|
67
|
+
*/
|
|
68
|
+
function isActionableEngagement(engagement) {
|
|
69
|
+
return engagement?.reason === 'claim' || engagement?.reason === 'open_pr';
|
|
70
|
+
}
|
|
22
71
|
export class IssueConversationMonitor {
|
|
23
72
|
octokit;
|
|
24
73
|
stateManager;
|
|
@@ -27,11 +76,39 @@ export class IssueConversationMonitor {
|
|
|
27
76
|
this.stateManager = getStateManager();
|
|
28
77
|
}
|
|
29
78
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
79
|
+
* Whether the configured user commented on `issueUrl` at or after `since`
|
|
80
|
+
* (#1863). Backs the closed-PR status nudge: once the user has told the
|
|
81
|
+
* linked issue what happened, the nudge drops out. GitHub's `since` filter
|
|
82
|
+
* keys on `updated_at`, so an old comment edited after the close would
|
|
83
|
+
* come back too; `created_at` is re-checked to count only new comments.
|
|
84
|
+
*
|
|
85
|
+
* @throws {ConfigurationError} If no GitHub username is configured
|
|
86
|
+
* @throws {ValidationError} If `issueUrl` is not a GitHub issue URL
|
|
33
87
|
*/
|
|
34
|
-
async
|
|
88
|
+
async hasUserCommentSince(issueUrl, since) {
|
|
89
|
+
const username = this.stateManager.getState().config.githubUsername;
|
|
90
|
+
if (!username) {
|
|
91
|
+
throw new ConfigurationError('No GitHub username configured. Run setup first.');
|
|
92
|
+
}
|
|
93
|
+
const parsed = parseGitHubUrl(issueUrl);
|
|
94
|
+
if (!parsed) {
|
|
95
|
+
throw new ValidationError(`Invalid issue URL format: ${issueUrl}`);
|
|
96
|
+
}
|
|
97
|
+
const { owner, repo, number } = parsed;
|
|
98
|
+
const comments = await paginateAll((page) => this.octokit.issues.listComments({ owner, repo, since, page, issue_number: number, per_page: 100 }));
|
|
99
|
+
const user = username.toLowerCase();
|
|
100
|
+
const sinceMs = Date.parse(since);
|
|
101
|
+
return comments.some((c) => c.user?.login?.toLowerCase() === user && Date.parse(c.created_at) >= sinceMs);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Fetch issues the user has commented on or is engaged in and determine
|
|
105
|
+
* conversation state. Filters out: user-authored issues, user-owned repos,
|
|
106
|
+
* excluded repos/orgs, AI policy blocklisted repos, and pull requests.
|
|
107
|
+
* Engaged issues (#1862) are scanned under the wider reply rule and
|
|
108
|
+
* fetched directly when the comment search misses them.
|
|
109
|
+
*/
|
|
110
|
+
async fetchCommentedIssues(options = {}) {
|
|
111
|
+
const { maxDays = 30, engaged = new Map() } = options;
|
|
35
112
|
const config = this.stateManager.getState().config;
|
|
36
113
|
if (!config.githubUsername) {
|
|
37
114
|
throw new ConfigurationError('No GitHub username configured. Run setup first.');
|
|
@@ -40,6 +117,7 @@ export class IssueConversationMonitor {
|
|
|
40
117
|
const cutoffDate = new Date();
|
|
41
118
|
cutoffDate.setDate(cutoffDate.getDate() - maxDays);
|
|
42
119
|
const since = cutoffDate.toISOString().split('T', 1)[0];
|
|
120
|
+
const warnings = [];
|
|
43
121
|
debug(MODULE, `Fetching commented issues for @${username} (last ${maxDays} days)...`);
|
|
44
122
|
// Search for open issues the user has commented on, updated within window
|
|
45
123
|
// Single page (100) is sufficient for most users; log if truncated.
|
|
@@ -52,15 +130,10 @@ export class IssueConversationMonitor {
|
|
|
52
130
|
if (data.total_count > 100) {
|
|
53
131
|
warn(MODULE, `Search returned ${data.total_count} results but only first 100 were fetched. Some commented issues may be missing.`);
|
|
54
132
|
}
|
|
55
|
-
//
|
|
56
|
-
const trackedIssues = this.stateManager.getState().activeIssues || [];
|
|
57
|
-
const trackedIssueKeys = new Set(trackedIssues
|
|
58
|
-
.filter((i) => i.status === 'claimed' || i.status === 'in_progress' || i.status === 'pr_submitted')
|
|
59
|
-
.map((i) => `${i.repo}#${i.number}`));
|
|
60
|
-
const blocklist = new Set((config.aiPolicyBlocklist || []).map((r) => r.toLowerCase()));
|
|
61
|
-
// Filter out PRs, user-authored issues, excluded repos, blocklisted repos, and already-tracked issues.
|
|
133
|
+
// Filter out PRs, user-authored issues, excluded repos, and blocklisted repos.
|
|
62
134
|
// Also parse repo info for each candidate to avoid re-parsing in analyzeIssueConversation.
|
|
63
135
|
const candidates = [];
|
|
136
|
+
const seenKeys = new Set();
|
|
64
137
|
for (const item of data.items) {
|
|
65
138
|
// Defensive: skip pull requests in case type:issue qualifier is unreliable
|
|
66
139
|
if (item.pull_request)
|
|
@@ -70,43 +143,64 @@ export class IssueConversationMonitor {
|
|
|
70
143
|
warn(MODULE, `Skipping issue with unparseable URL: ${item.html_url}`);
|
|
71
144
|
continue;
|
|
72
145
|
}
|
|
73
|
-
const {
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
if (isOwnRepo(owner, username))
|
|
77
|
-
continue;
|
|
146
|
+
const repoFullName = `${parsed.owner}/${parsed.repo}`;
|
|
147
|
+
const key = issueRefKey(item.html_url) ?? item.html_url;
|
|
148
|
+
seenKeys.add(key);
|
|
78
149
|
// Skip user-authored issues
|
|
79
150
|
if (item.user?.login?.toLowerCase() === username.toLowerCase())
|
|
80
151
|
continue;
|
|
81
|
-
|
|
82
|
-
if (config.excludeRepos.includes(repoFullName))
|
|
152
|
+
if (!this.isRepoAllowed(repoFullName, config))
|
|
83
153
|
continue;
|
|
84
|
-
|
|
154
|
+
candidates.push({ item, repoFullName, engagement: engaged.get(key), url: item.html_url, number: item.number });
|
|
155
|
+
}
|
|
156
|
+
// Live engaged issues the search did not return are looked up directly.
|
|
157
|
+
const missing = [];
|
|
158
|
+
for (const entry of engaged.values()) {
|
|
159
|
+
if (!entry.fetchWhenMissing || seenKeys.has(entry.key))
|
|
85
160
|
continue;
|
|
86
|
-
|
|
87
|
-
if (
|
|
161
|
+
const parsed = extractOwnerRepo(entry.url);
|
|
162
|
+
if (!parsed || !this.isRepoAllowed(`${parsed.owner}/${parsed.repo}`, config))
|
|
88
163
|
continue;
|
|
89
|
-
|
|
90
|
-
|
|
164
|
+
missing.push(entry);
|
|
165
|
+
}
|
|
166
|
+
// `engaged` iterates strongest reason first (open PR, claim, then closed
|
|
167
|
+
// and merged links), so the cap drops finished-PR links before claims.
|
|
168
|
+
const skipped = missing.slice(MAX_DIRECT_ENGAGED_FETCHES);
|
|
169
|
+
if (skipped.length > 0) {
|
|
170
|
+
warnings.push(`${skipped.length} engaged issue${skipped.length === 1 ? '' : 's'} missing from the comment search ${skipped.length === 1 ? 'was' : 'were'} not fetched this run (cap of ${MAX_DIRECT_ENGAGED_FETCHES} direct lookups; open-PR and claimed issues come first), so replies there may be missed: ${skipped.map((e) => e.url).join(', ')}`);
|
|
171
|
+
}
|
|
172
|
+
for (const entry of missing.slice(0, MAX_DIRECT_ENGAGED_FETCHES)) {
|
|
173
|
+
const parsed = parseGitHubUrl(entry.url);
|
|
174
|
+
if (!parsed)
|
|
91
175
|
continue;
|
|
92
|
-
candidates.push({
|
|
176
|
+
candidates.push({
|
|
177
|
+
url: entry.url,
|
|
178
|
+
repoFullName: `${parsed.owner}/${parsed.repo}`,
|
|
179
|
+
number: parsed.number,
|
|
180
|
+
engagement: entry,
|
|
181
|
+
});
|
|
93
182
|
}
|
|
94
183
|
debug(MODULE, `Found ${candidates.length} commented issues to check`);
|
|
95
184
|
// Fetch comments for each issue using worker pool.
|
|
96
185
|
const results = [];
|
|
97
186
|
const failures = [];
|
|
98
|
-
await runWorkerPool(candidates, async (
|
|
187
|
+
await runWorkerPool(candidates, async (candidate) => {
|
|
99
188
|
try {
|
|
100
|
-
const
|
|
189
|
+
const item = candidate.item ?? (await this.fetchEngagedIssue(candidate, username, cutoffDate));
|
|
190
|
+
if (!item)
|
|
191
|
+
return;
|
|
192
|
+
const issue = await this.analyzeIssueConversation(item, candidate.repoFullName, username, candidate.engagement, warnings);
|
|
101
193
|
if (issue) {
|
|
102
194
|
results.push(issue);
|
|
195
|
+
return;
|
|
103
196
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
197
|
+
// An engaged issue with nothing to report is not a failure.
|
|
198
|
+
if (candidate.engagement)
|
|
199
|
+
return;
|
|
200
|
+
failures.push({
|
|
201
|
+
issueUrl: candidate.url,
|
|
202
|
+
error: 'No user comment found despite commenter: search match (possible pagination or eventual consistency)',
|
|
203
|
+
});
|
|
110
204
|
}
|
|
111
205
|
catch (error) {
|
|
112
206
|
// Rate-limit / auth failures must propagate, not degrade to "fewer
|
|
@@ -117,9 +211,21 @@ export class IssueConversationMonitor {
|
|
|
117
211
|
// aborting the run just like PRMonitor's 429s do.
|
|
118
212
|
if (isRateLimitOrAuthError(error))
|
|
119
213
|
throw error;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
214
|
+
if (candidate.item === undefined && isGoneError(error)) {
|
|
215
|
+
// Only a direct fetch can see a 404/410: the issue was deleted,
|
|
216
|
+
// transferred, or made private since the PR or claim linked it.
|
|
217
|
+
// Worth telling the user only while something of theirs still
|
|
218
|
+
// points at it (a claim to release, an open PR's closing link).
|
|
219
|
+
const message = `${candidate.url}: issue no longer reachable (${describeError(error)}); dropped`;
|
|
220
|
+
if (isActionableEngagement(candidate.engagement))
|
|
221
|
+
warnings.push(message);
|
|
222
|
+
else
|
|
223
|
+
debug(MODULE, message);
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
const msg = describeError(error);
|
|
227
|
+
failures.push({ issueUrl: candidate.url, error: msg });
|
|
228
|
+
warn(MODULE, `Error analyzing issue ${candidate.url}: ${msg}`);
|
|
123
229
|
}
|
|
124
230
|
}, MAX_CONCURRENT_REQUESTS);
|
|
125
231
|
if (failures.length > 0) {
|
|
@@ -128,6 +234,8 @@ export class IssueConversationMonitor {
|
|
|
128
234
|
if (failures.length === candidates.length && candidates.length > 0) {
|
|
129
235
|
warn(MODULE, `All ${candidates.length} issue analysis call(s) failed. Possible systemic issue (network, GitHub availability).`);
|
|
130
236
|
}
|
|
237
|
+
for (const message of warnings)
|
|
238
|
+
warn(MODULE, message);
|
|
131
239
|
// Sort: new_response first, then waiting, then acknowledged
|
|
132
240
|
const statusOrder = {
|
|
133
241
|
new_response: 0,
|
|
@@ -136,95 +244,134 @@ export class IssueConversationMonitor {
|
|
|
136
244
|
};
|
|
137
245
|
results.sort((a, b) => statusOrder[a.status] - statusOrder[b.status]);
|
|
138
246
|
debug(MODULE, `Analyzed ${results.length} issue conversations (${results.filter((i) => i.status === 'new_response').length} with new responses)`);
|
|
139
|
-
return { issues: results, failures };
|
|
247
|
+
return { issues: results, failures, warnings };
|
|
248
|
+
}
|
|
249
|
+
/** Repo-level exclusions shared by the search results and the direct fetches. */
|
|
250
|
+
isRepoAllowed(repoFullName, config) {
|
|
251
|
+
const { owner } = splitRepo(repoFullName);
|
|
252
|
+
// Skip issues in user-owned repos (we only care about contributing to others' projects)
|
|
253
|
+
if (isOwnRepo(owner, config.githubUsername))
|
|
254
|
+
return false;
|
|
255
|
+
if (config.excludeRepos.includes(repoFullName))
|
|
256
|
+
return false;
|
|
257
|
+
if (config.excludeOrgs?.some((org) => owner.toLowerCase() === org.toLowerCase()))
|
|
258
|
+
return false;
|
|
259
|
+
const blocklist = (config.aiPolicyBlocklist || []).map((r) => r.toLowerCase());
|
|
260
|
+
return !blocklist.includes(repoFullName.toLowerCase());
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Look up an engaged issue the comment search did not return (#1862).
|
|
264
|
+
* Returns undefined, with a debug line, when the number is a pull request,
|
|
265
|
+
* the issue is closed, the user authored it, or nothing on it changed
|
|
266
|
+
* since the later of the search window's start and the engagement step.
|
|
267
|
+
* The window keeps this path consistent with the commenter search (a
|
|
268
|
+
* reply older than `maxDays` is not surfaced either way); the engagement
|
|
269
|
+
* step tightens it because only comments after that step can be replies
|
|
270
|
+
* to the user, so an issue untouched since then has nothing to report.
|
|
271
|
+
* ETag-cached like the comment pages. Errors propagate to the worker.
|
|
272
|
+
*/
|
|
273
|
+
async fetchEngagedIssue(candidate, username, cutoffDate) {
|
|
274
|
+
const { owner, repo } = splitRepo(candidate.repoFullName);
|
|
275
|
+
const url = `/repos/${owner}/${repo}/issues/${candidate.number}`;
|
|
276
|
+
const issue = await cachedRequest(getHttpCache(), url, (headers) => this.octokit.issues.get({ owner, repo, headers, issue_number: candidate.number }));
|
|
277
|
+
const skip = (reason) => {
|
|
278
|
+
debug(MODULE, `Skipping engaged issue ${candidate.url}: ${reason}`);
|
|
279
|
+
};
|
|
280
|
+
if (issue.pull_request)
|
|
281
|
+
return skip('the number is a pull request');
|
|
282
|
+
if (issue.state !== 'open')
|
|
283
|
+
return skip(`issue is ${issue.state}`);
|
|
284
|
+
if (issue.user?.login?.toLowerCase() === username.toLowerCase())
|
|
285
|
+
return skip('authored by the user');
|
|
286
|
+
const activitySinceMs = Math.max(cutoffDate.getTime(), parseMs(candidate.engagement?.since));
|
|
287
|
+
if (Date.parse(issue.updated_at) < activitySinceMs)
|
|
288
|
+
return skip(`not updated since ${issue.updated_at}`);
|
|
289
|
+
return { html_url: issue.html_url, number: issue.number, title: issue.title, labels: issue.labels };
|
|
140
290
|
}
|
|
141
291
|
/**
|
|
142
292
|
* Analyze a single issue's comment thread to determine conversation status.
|
|
293
|
+
* Returns null when there is nothing to report: the user never commented
|
|
294
|
+
* on a non-engaged issue (the search said otherwise), or an engaged issue
|
|
295
|
+
* the user never commented on has no reply yet (nothing to wait for).
|
|
143
296
|
*/
|
|
144
|
-
async analyzeIssueConversation(item, repoFullName, username) {
|
|
145
|
-
const {
|
|
146
|
-
const cache = getHttpCache();
|
|
147
|
-
// Each page gets its own cache entry (URL includes `page`) so issues with
|
|
148
|
-
// >100 comments still get conditional-request savings on every page, not
|
|
149
|
-
// just the first.
|
|
150
|
-
const { items: allComments, truncated } = await paginateAllDetailed((page) => {
|
|
151
|
-
const url = `/repos/${owner}/${repo}/issues/${item.number}/comments?per_page=100&page=${page}`;
|
|
152
|
-
return cachedRequest(cache, url, (headers) => this.octokit.issues.listComments({
|
|
153
|
-
owner,
|
|
154
|
-
repo,
|
|
155
|
-
issue_number: item.number,
|
|
156
|
-
per_page: 100,
|
|
157
|
-
page,
|
|
158
|
-
headers,
|
|
159
|
-
})).then((data) => ({ data }));
|
|
160
|
-
});
|
|
297
|
+
async analyzeIssueConversation(item, repoFullName, username, engagement, warnings) {
|
|
298
|
+
const { timeline, truncated } = await this.fetchTimeline(item, repoFullName, username);
|
|
161
299
|
if (truncated) {
|
|
162
300
|
// Comments arrive oldest-first, so hitting the pagination cap drops
|
|
163
|
-
// the NEWEST responses
|
|
164
|
-
//
|
|
165
|
-
|
|
301
|
+
// the NEWEST responses and the status below may be stale (#1456).
|
|
302
|
+
// Engaged issues are the long-lived threads most likely to hit this.
|
|
303
|
+
warnings.push(`${item.html_url}: comment thread longer than the pagination cap; the newest comments were not read and its conversation status may be stale`);
|
|
166
304
|
}
|
|
167
|
-
const timeline = [];
|
|
168
|
-
for (const comment of allComments) {
|
|
169
|
-
if (!comment.user?.login)
|
|
170
|
-
continue; // Skip comments from deleted accounts
|
|
171
|
-
const author = comment.user.login;
|
|
172
|
-
timeline.push({
|
|
173
|
-
author,
|
|
174
|
-
body: comment.body || '',
|
|
175
|
-
createdAt: comment.created_at,
|
|
176
|
-
isUser: author.toLowerCase() === username.toLowerCase(),
|
|
177
|
-
authorAssociation: typeof comment.author_association === 'string'
|
|
178
|
-
? comment.author_association
|
|
179
|
-
: '',
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
timeline.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
183
305
|
// Find the user's last comment
|
|
184
306
|
let userLastComment;
|
|
185
307
|
for (const entry of timeline) {
|
|
186
308
|
if (entry.isUser)
|
|
187
309
|
userLastComment = entry;
|
|
188
310
|
}
|
|
189
|
-
|
|
190
|
-
|
|
311
|
+
if (!userLastComment && !engagement) {
|
|
312
|
+
// Shouldn't happen with commenter: search, but be safe
|
|
191
313
|
warn(MODULE, `No user comment found for ${item.html_url} despite commenter: search match`);
|
|
192
314
|
return null;
|
|
193
315
|
}
|
|
194
|
-
|
|
195
|
-
//
|
|
316
|
+
// The user's last word on the thread: their last comment, or the later
|
|
317
|
+
// of that and the engagement step (claim, PR opened) on engaged issues.
|
|
318
|
+
const userLastWordMs = Math.max(parseMs(userLastComment?.createdAt), parseMs(engagement?.since));
|
|
319
|
+
if (userLastWordMs === -Infinity) {
|
|
320
|
+
// Engaged, no comment from the user, and nothing to anchor "after the
|
|
321
|
+
// user's last word" on. A missing `since` (ledger link without an
|
|
322
|
+
// opening time) is expected and cannot happen on a direct fetch; a
|
|
323
|
+
// stamp that does not parse is bad state worth a warning.
|
|
324
|
+
if (engagement?.since === undefined) {
|
|
325
|
+
debug(MODULE, `Skipping engaged issue ${item.html_url}: no user comment and no engagement time`);
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
warnings.push(`${item.html_url}: skipped; the user never commented and the engagement time "${engagement.since}" does not parse`);
|
|
329
|
+
}
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
const userMention = `@${username.toLowerCase()}`;
|
|
333
|
+
const userLastCommentBody = userLastComment?.body;
|
|
334
|
+
// Directed at the user (#343, extended by #1862 with quote replies):
|
|
196
335
|
// 1. From a maintainer (OWNER/MEMBER/COLLABORATOR) — inherently authoritative
|
|
197
336
|
// 2. @mentions the user — explicitly addressed
|
|
337
|
+
// 3. Quotes the user's last comment — explicitly addressed
|
|
198
338
|
// This filters out community "+1" and "me too" noise.
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
//
|
|
339
|
+
const isDirectedAtUser = (entry) => MAINTAINER_ASSOCIATIONS.has(entry.authorAssociation) ||
|
|
340
|
+
entry.body.toLowerCase().includes(userMention) ||
|
|
341
|
+
(userLastCommentBody !== undefined && isQuoteReplyTo(entry.body, userLastCommentBody));
|
|
342
|
+
// On an engaged issue (#1862) a comment is relevant when it is directed
|
|
343
|
+
// at the user (a maintainer's "any update?" is short but still a reply),
|
|
344
|
+
// when it says more than a reaction, or, on a claimed issue, when it is a
|
|
345
|
+
// bare status request: "any update?" there asks the claimant. `claimed`,
|
|
346
|
+
// not `reason`: an open PR outranks the claim as the reason, and the
|
|
347
|
+
// claimant is still the one being asked.
|
|
348
|
+
const isRelevant = (entry) => {
|
|
349
|
+
if (isDirectedAtUser(entry))
|
|
350
|
+
return true;
|
|
351
|
+
if (!engagement)
|
|
352
|
+
return false;
|
|
353
|
+
if (engagement.claimed && isStatusNudge(entry.body))
|
|
354
|
+
return true;
|
|
355
|
+
return !isReactionOnlyComment(entry.body);
|
|
356
|
+
};
|
|
357
|
+
// A reply: by someone else after the user's last word, substantive and relevant.
|
|
358
|
+
const isAfterUser = (entry) => !entry.isUser && !isBotAuthor(entry.author) && parseMs(entry.createdAt) > userLastWordMs;
|
|
359
|
+
const isReply = (entry) => isAfterUser(entry) && !isAcknowledgmentComment(entry.body) && isRelevant(entry);
|
|
204
360
|
let lastResponse;
|
|
205
361
|
for (const entry of timeline) {
|
|
206
|
-
if (entry
|
|
207
|
-
|
|
208
|
-
if (isBotAuthor(entry.author))
|
|
209
|
-
continue;
|
|
210
|
-
const entryTime = new Date(entry.createdAt);
|
|
211
|
-
if (entryTime > userLastCommentTime) {
|
|
212
|
-
if (isAcknowledgmentComment(entry.body))
|
|
213
|
-
continue;
|
|
214
|
-
if (!isDirectedAtUser(entry))
|
|
215
|
-
continue;
|
|
216
|
-
lastResponse = {
|
|
217
|
-
author: entry.author,
|
|
218
|
-
body: entry.body.slice(0, 200) + (entry.body.length > 200 ? '...' : ''),
|
|
219
|
-
createdAt: entry.createdAt,
|
|
220
|
-
authorAssociation: entry.authorAssociation,
|
|
221
|
-
};
|
|
222
|
-
}
|
|
362
|
+
if (isReply(entry))
|
|
363
|
+
lastResponse = entry;
|
|
223
364
|
}
|
|
224
|
-
|
|
365
|
+
if (!userLastComment && !lastResponse) {
|
|
366
|
+
debug(MODULE, `Engaged issue ${item.html_url} has no reply after ${engagement?.since}; nothing to report`);
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
const labels = (item.labels || []).map((l) => (typeof l === 'string' ? l : l.name || '')).filter(Boolean);
|
|
370
|
+
// One of the two is set: the -Infinity check above returned otherwise.
|
|
371
|
+
const userLastWordAt = userLastComment?.createdAt ?? engagement?.since ?? '';
|
|
225
372
|
// Body excerpts stay RAW here on purpose (#1372): these objects feed the
|
|
226
373
|
// dashboard SPA and the CLI text renderers directly, and the matching
|
|
227
|
-
// above (acknowledgment / @mention) operates on raw text. The
|
|
374
|
+
// above (acknowledgment / @mention / quote) operates on raw text. The
|
|
228
375
|
// `<github-content>` fence is applied at the agent-facing serialization
|
|
229
376
|
// boundary in `toDailyOutput()` (commands/daily.ts).
|
|
230
377
|
const base = {
|
|
@@ -232,32 +379,73 @@ export class IssueConversationMonitor {
|
|
|
232
379
|
number: item.number,
|
|
233
380
|
title: item.title,
|
|
234
381
|
url: item.html_url,
|
|
235
|
-
userLastCommentedAt:
|
|
236
|
-
userLastCommentBody:
|
|
382
|
+
userLastCommentedAt: userLastWordAt,
|
|
383
|
+
userLastCommentBody: excerpt(userLastComment?.body ?? ''),
|
|
237
384
|
labels,
|
|
238
|
-
daysSinceUserComment: daysBetween(
|
|
385
|
+
daysSinceUserComment: daysBetween(new Date(userLastWordMs), new Date()),
|
|
386
|
+
...(engagement && { engagement: toIssueEngagement(engagement) }),
|
|
239
387
|
};
|
|
240
388
|
if (lastResponse) {
|
|
241
389
|
return {
|
|
242
390
|
...base,
|
|
243
391
|
status: 'new_response',
|
|
244
392
|
lastResponseAuthor: lastResponse.author,
|
|
245
|
-
lastResponseBody: lastResponse.body,
|
|
393
|
+
lastResponseBody: excerpt(lastResponse.body),
|
|
246
394
|
lastResponseAt: lastResponse.createdAt,
|
|
247
395
|
isFromMaintainer: MAINTAINER_ASSOCIATIONS.has(lastResponse.authorAssociation),
|
|
248
396
|
};
|
|
249
397
|
}
|
|
250
|
-
// No
|
|
251
|
-
// commenter
|
|
252
|
-
//
|
|
398
|
+
// No relevant response found. Determine whether the user or a relevant
|
|
399
|
+
// commenter spoke last. Irrelevant community comments are excluded from
|
|
400
|
+
// this check too (#343). A relevant comment the engagement step already
|
|
401
|
+
// answered (posted before the claim or the PR) does not count as waiting.
|
|
253
402
|
const lastRelevantComment = [...timeline].reverse().find((e) => {
|
|
254
403
|
if (isBotAuthor(e.author))
|
|
255
404
|
return false;
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
405
|
+
return e.isUser || isRelevant(e);
|
|
406
|
+
});
|
|
407
|
+
const isWaiting = lastRelevantComment !== undefined &&
|
|
408
|
+
!lastRelevantComment.isUser &&
|
|
409
|
+
parseMs(lastRelevantComment.createdAt) > userLastWordMs;
|
|
410
|
+
return { ...base, status: isWaiting ? 'waiting' : 'acknowledged' };
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* All comments on the issue, oldest first, with deleted-account comments
|
|
414
|
+
* dropped. `truncated` is set when the pagination cap cut the thread short.
|
|
415
|
+
*/
|
|
416
|
+
async fetchTimeline(item, repoFullName, username) {
|
|
417
|
+
const { owner, repo } = splitRepo(repoFullName);
|
|
418
|
+
const cache = getHttpCache();
|
|
419
|
+
// Each page gets its own cache entry (URL includes `page`) so issues with
|
|
420
|
+
// >100 comments still get conditional-request savings on every page, not
|
|
421
|
+
// just the first.
|
|
422
|
+
const { items: allComments, truncated } = await paginateAllDetailed((page) => {
|
|
423
|
+
const url = `/repos/${owner}/${repo}/issues/${item.number}/comments?per_page=100&page=${page}`;
|
|
424
|
+
return cachedRequest(cache, url, (headers) => this.octokit.issues.listComments({
|
|
425
|
+
owner,
|
|
426
|
+
repo,
|
|
427
|
+
issue_number: item.number,
|
|
428
|
+
per_page: 100,
|
|
429
|
+
page,
|
|
430
|
+
headers,
|
|
431
|
+
})).then((data) => ({ data }));
|
|
259
432
|
});
|
|
260
|
-
const
|
|
261
|
-
|
|
433
|
+
const timeline = [];
|
|
434
|
+
for (const comment of allComments) {
|
|
435
|
+
if (!comment.user?.login)
|
|
436
|
+
continue; // Skip comments from deleted accounts
|
|
437
|
+
const author = comment.user.login;
|
|
438
|
+
timeline.push({
|
|
439
|
+
author,
|
|
440
|
+
body: comment.body || '',
|
|
441
|
+
createdAt: comment.created_at,
|
|
442
|
+
isUser: author.toLowerCase() === username.toLowerCase(),
|
|
443
|
+
authorAssociation: typeof comment.author_association === 'string'
|
|
444
|
+
? comment.author_association
|
|
445
|
+
: '',
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
timeline.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
449
|
+
return { timeline, truncated };
|
|
262
450
|
}
|
|
263
451
|
}
|