pierre-review 0.1.86 → 0.1.87

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.
@@ -42,6 +42,7 @@ export async function activityRoutes(app) {
42
42
  allowBotIds: parseIntList(q.allowBotIds),
43
43
  botsOnly: q.botsOnly === 'true',
44
44
  botWindowDays,
45
+ includeAllCommits: q.includeAllCommits === 'true',
45
46
  });
46
47
  });
47
48
  // Mark the Activity Feed as seen (bumps the account's server-side "seen" marker to
@@ -1,4 +1,4 @@
1
- import { addBotMuteRule, deleteBotMuteRule, getBotAnalytics, getBotOnlyPrs, getBotVendorPrs, getBotDedupClusters, getResolvableBotThreadPrs, getResolvableBotThreadsForScope, listBotMuteRules, listDetectedReviewers, resolveScopeRepoIds, setReviewerOverride, SCOPE_RESOLVE_THREAD_CAP, } from '../../db/queries.js';
1
+ import { addBotMuteRule, deleteBotMuteRule, getBotAnalytics, getBotBehaviourAnalytics, getBotOnlyPrs, getBotVendorPrs, getBotDedupClusters, getResolvableBotThreadPrs, getResolvableBotThreadsForScope, listBotMuteRules, listDetectedReviewers, resolveScopeRepoIds, setReviewerOverride, SCOPE_RESOLVE_THREAD_CAP, } from '../../db/queries.js';
2
2
  import { resolveThreadsOnGitHub } from '../../bot-triage/resolve.js';
3
3
  import { accountIdOf } from '../plugins/auth.js';
4
4
  // Parse a comma-separated id list into a positive-int array, or null when empty/absent (so
@@ -173,6 +173,18 @@ export async function botTriageRoutes(app) {
173
173
  const resp = await getBotAnalytics(accountId, window, scopeRepoIds);
174
174
  return resp;
175
175
  });
176
+ // EXPERIMENTAL bot BEHAVIOUR analytics (CORE, deterministic — no AI). Per bot, over the same
177
+ // window/scope resolution as /api/bot-analytics: time-to-first-review, LoC-to-comments ratio,
178
+ // the week×hour activity heatmap (coverage / rate-limit inference), and post-first-review
179
+ // follow-up behaviour. Powers the Bots "Behaviour" sub-tab, kept separate from the ROI panel.
180
+ app.get('/api/bot-behaviour', { schema: analyticsSchema }, async (req) => {
181
+ const { window, scope, repoIds } = req.query;
182
+ const accountId = accountIdOf(req);
183
+ const explicit = parseIntList(repoIds);
184
+ const scopeRepoIds = explicit ?? (scope ? await resolveScopeRepoIds(accountId, scope) : null);
185
+ const resp = await getBotBehaviourAnalytics(accountId, window, scopeRepoIds);
186
+ return resp;
187
+ });
176
188
  // The exact PR list behind the analytics totals.botOnlyPrs count — "only a bot reviewed these".
177
189
  // Same window/scope resolution as /api/bot-analytics (a specific `repoIds` wins over `scope`) so
178
190
  // the amber caption's number and this expandable list are computed identically and can't drift.
@@ -0,0 +1,17 @@
1
+ import { getScopeMentionCandidates, resolveScopeRepoIds } from '../../db/queries.js';
2
+ import { accountIdOf } from '../plugins/auth.js';
3
+ // Scope-wide @mention candidates (CORE) — the team/repo-scoped sibling of
4
+ // GET /api/prs/:id/mention-candidates. Powers the ad-hoc Insights "Ask about the sprint" box,
5
+ // whose questions span the whole selected scope rather than one PR. `scope` mirrors the Insights
6
+ // scope string ('all' | 'none' | 'teams' | '<teamId>'); it's resolved to the account's repo set
7
+ // server-side (resolveScopeRepoIds), so a caller can't widen it. Self + bots excluded. Returns a
8
+ // bare User[] exactly like the PR route so MentionTextarea can consume it directly.
9
+ export async function mentionsRoutes(app) {
10
+ app.get('/api/mention-candidates', async (req) => {
11
+ const q = req.query;
12
+ const accountId = accountIdOf(req);
13
+ const repoIds = await resolveScopeRepoIds(accountId, q.scope ?? 'all');
14
+ return getScopeMentionCandidates(accountId, repoIds);
15
+ });
16
+ }
17
+ //# sourceMappingURL=mentions.js.map
@@ -2,9 +2,8 @@ import { createHash } from 'node:crypto';
2
2
  import { config } from '../../config.js';
3
3
  import { getAccessToken, getAccountUserId } from '../../auth/account.js';
4
4
  import { fetchActionsJobLog } from '../../github/actions-logs.js';
5
- import { getMentionCandidates, getPrDetail, getPrFilesContext, getPrWriteContext, getReviewerLogins, getResolvableBotThreads, getSuggestedReviewersBasis, getUsersByLogins, markAllViewed, markPrMergedLocally, markPrViewed, stampReviewRequests, upsertLocalPrComment, upsertLocalReview, } from '../../db/queries.js';
6
- import { getCodeownersMatch } from '../../github/codeowners.js';
7
- import { suggestTeamsFromHistory } from '../../github/team-reviewers.js';
5
+ import { getMentionCandidates, getPrDetail, getPrBotBehaviour, getPrFilesContext, getPrWriteContext, getReviewerLogins, getResolvableBotThreads, getSuggestedReviewersBasis, getUsersByLogins, markAllViewed, markPrMergedLocally, markPrViewed, stampReviewRequests, upsertLocalPrComment, upsertLocalReview, } from '../../db/queries.js';
6
+ import { enrichReviewerSuggestions } from '../../github/reviewer-suggest.js';
8
7
  import { buildFileAnchors, fallbackAnchor, isFindingAnchored, } from '../../github/diff-anchor.js';
9
8
  import { addIssueComment, fetchHeadShaFor, fetchMergeability, fetchPrFilesWithPatch, fetchPrHeadInfo, fetchRepoMergeConfig, mergePullRequest, postInlineComment, requestReviewers, rerunWorkflowRun, submitPrReview, updatePullRequestBranch, } from '../../github/mutations.js';
10
9
  import { hydratePrDetail } from '../../sync/hydrate-detail.js';
@@ -170,77 +169,17 @@ async function buildSuggestedReviewers(basis, accountId) {
170
169
  if (!basis.wants)
171
170
  return { suggestedReviewers: [], users: [] };
172
171
  const { owner, name, authorLogin, paths, suggestions, users } = basis;
173
- const extraUsers = [];
174
- let merged = suggestions;
175
- try {
176
- const token = await getAccessToken(accountId);
177
- const emptyMatch = { logins: [], teams: [] };
178
- const [match, historyTeams] = await Promise.all([
179
- paths.length > 0
180
- ? getCodeownersMatch(token, owner, name, accountId, paths)
181
- : Promise.resolve(emptyMatch),
182
- suggestTeamsFromHistory(token, owner, name, accountId),
183
- ]);
184
- // Resolve @user owners to synced users (avatar/link); unsynced owners show login-only.
185
- // Exclude the PR author (GitHub rejects self-review requests).
186
- const uniqueLogins = [...new Set(match.logins)].filter((l) => l !== authorLogin);
187
- const resolved = await getUsersByLogins(uniqueLogins);
188
- const byLogin = new Map(resolved.map((u) => [u.githubLogin, u]));
189
- const codeownerUsers = uniqueLogins.map((login) => ({
190
- kind: 'user',
191
- login,
192
- userId: byLogin.get(login)?.id ?? null,
193
- teamSlug: null,
194
- teamName: null,
195
- reason: 'owns this path (CODEOWNERS)',
196
- source: 'codeowners',
197
- }));
198
- const codeownerTeams = match.teams.map((t) => ({
199
- kind: 'team',
200
- login: null,
201
- userId: null,
202
- teamSlug: t.slug,
203
- teamName: t.name,
204
- reason: 'owns this path (CODEOWNERS)',
205
- source: 'codeowners',
206
- }));
207
- const historyTeamSuggestions = historyTeams.map((t) => ({
208
- kind: 'team',
209
- login: null,
210
- userId: null,
211
- teamSlug: t.slug,
212
- teamName: t.name,
213
- reason: `usually requested here (${t.count} recent PR${t.count === 1 ? '' : 's'})`,
214
- source: 'history',
215
- }));
216
- // Merge = precedence: CODEOWNERS users, CODEOWNERS teams (declared), inferred teams, then
217
- // the history-user suggestions. Dedup users by login and teams by slug (so a team that's
218
- // both a CODEOWNER and historically requested shows once, as the CODEOWNER).
219
- const seenLogins = new Set();
220
- const seenTeams = new Set();
221
- merged = [];
222
- for (const s of [...codeownerUsers, ...codeownerTeams, ...historyTeamSuggestions, ...suggestions]) {
223
- if (s.kind === 'team') {
224
- if (s.teamSlug && !seenTeams.has(s.teamSlug)) {
225
- seenTeams.add(s.teamSlug);
226
- merged.push(s);
227
- }
228
- }
229
- else if (s.login && !seenLogins.has(s.login)) {
230
- seenLogins.add(s.login);
231
- merged.push(s);
232
- }
233
- }
234
- // The newly-resolved codeowner users the basis didn't already carry.
235
- const known = new Set(users.map((u) => u.id));
236
- for (const u of resolved)
237
- if (!known.has(u.id))
238
- extraUsers.push(u);
239
- }
240
- catch {
241
- /* best-effort: fall back to the history-user suggestions */
242
- }
243
- return { suggestedReviewers: merged.slice(0, 5), users: [...users, ...extraUsers] };
172
+ const { suggestions: merged, extraUsers } = await enrichReviewerSuggestions({
173
+ accountId,
174
+ owner,
175
+ name,
176
+ authorLogin,
177
+ paths,
178
+ userSuggestions: suggestions,
179
+ knownUserIds: new Set(users.map((u) => u.id)),
180
+ resolveUsers: getUsersByLogins,
181
+ });
182
+ return { suggestedReviewers: merged, users: [...users, ...extraUsers] };
244
183
  }
245
184
  export async function prRoutes(app) {
246
185
  // Bulk "mark all seen": stamp every open PR (optionally scoped to repoIds) viewed
@@ -265,6 +204,19 @@ export async function prRoutes(app) {
265
204
  // cached detail never freezes a stale suggestion.)
266
205
  return hydratePrDetail(pr, accountId);
267
206
  });
207
+ // PR-scoped bot behaviour (EXPERIMENTAL, CORE, deterministic — no AI): each automated reviewer's
208
+ // touch timeline ON THIS PR + how it compares to that bot's OWN typical (an 84-day account-wide
209
+ // robust baseline). Powers the PrDetail "Bot activity" tab + the Overview chip warn badge.
210
+ // Account-scoped: 404 when the PR isn't the caller's; empty `bots` when no bot touched it.
211
+ app.get('/api/prs/:id/bot-behaviour', { schema: idParamSchema }, async (req, reply) => {
212
+ const { id } = req.params;
213
+ const resp = await getPrBotBehaviour(id, accountIdOf(req));
214
+ if (!resp) {
215
+ reply.status(404);
216
+ return { error: 'NotFound', message: `PR ${id} not found` };
217
+ }
218
+ return resp;
219
+ });
268
220
  // Suggested reviewers — its OWN live query (not embedded in the cached PR detail) so it
269
221
  // always reflects current state: it empties the instant a reviewer is requested (the assign
270
222
  // route stamps review_requests locally), rather than staying frozen until the PR's updatedAt
package/dist/app.js CHANGED
@@ -20,6 +20,7 @@ import { feedRoutes } from './api/routes/feed.js';
20
20
  import { mergersRoutes } from './api/routes/mergers.js';
21
21
  import { insightsRoutes } from './api/routes/insights.js';
22
22
  import { activityRoutes } from './api/routes/activity.js';
23
+ import { mentionsRoutes } from './api/routes/mentions.js';
23
24
  import { billingRoutes } from './api/routes/billing.js';
24
25
  import { botTriageRoutes } from './api/routes/bot-triage.js';
25
26
  import { webhookRoutes } from './api/routes/webhooks.js';
@@ -137,6 +138,7 @@ export async function buildApp() {
137
138
  await app.register(mergersRoutes);
138
139
  await app.register(insightsRoutes);
139
140
  await app.register(activityRoutes);
141
+ await app.register(mentionsRoutes);
140
142
  // Bot-triage platform (CORE, always registered): detection/override, ROI analytics,
141
143
  // cross-bot dedup, mute / auto-triage rules. Account-scoped; no AI.
142
144
  await app.register(botTriageRoutes);