@omercnet/paseo-pr-radar 3.2.3 → 3.3.0-next.529.1

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.
@@ -4,7 +4,7 @@ import { useEffect, useMemo } from "react";
4
4
  import { viewerScope } from "../shared/viewer-scope";
5
5
  import { loadAgents, loadWorkspaces } from "./directory-load";
6
6
  import { observeDirectoryInvalidation } from "./directory-observation";
7
- import { applyViewerScope, buildRadarSnapshot, mergeInboxRows } from "./radar";
7
+ import { applyViewerScope, buildIssueRows, buildRadarSnapshot, mergeInboxRows } from "./radar";
8
8
  import { radarWarnings, VIEWER_URL_LIMIT } from "./screen-state";
9
9
 
10
10
  // `live` owns the refresh timers. The sidebar is live unless the screen is open (the screen is
@@ -63,6 +63,10 @@ export function useRadar(hostId: string, windowDays = 30, live = true) {
63
63
  ),
64
64
  [directory.data, viewer.data],
65
65
  );
66
+ const issues = useMemo(
67
+ () => buildIssueRows(directory.data, viewer.data?.issueItems ?? []),
68
+ [directory.data, viewer.data],
69
+ );
66
70
  const warnings = radarWarnings({
67
71
  directoryError: Boolean(directory.error),
68
72
  directoryTruncated: Boolean(directory.data?.truncated),
@@ -75,12 +79,12 @@ export function useRadar(hostId: string, windowDays = 30, live = true) {
75
79
  paseo,
76
80
  queryKey,
77
81
  rows,
82
+ issues,
78
83
  rawRows,
79
84
  warnings,
80
85
  data: directory.data,
81
86
  error: directory.error,
82
87
  isPending: directory.isPending,
83
- isFetching: directory.isFetching || viewer.isFetching,
84
88
  refetch: directory.refetch,
85
89
  viewerData: viewer.data,
86
90
  viewerError: viewer.data?.error ?? viewer.error,
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env python3
2
+ """Example PR Radar routing script: PR context JSON on stdin, launch overrides as JSON on stdout.
3
+
4
+ Point the "Routing script path" setting at an executable copy of this file, for example
5
+ ~/.config/pr-radar/route.py (chmod +x). PR Radar runs it with no arguments, writes one JSON object on
6
+ stdin, and reads one JSON object from stdout.
7
+
8
+ stdin:
9
+ {"pr": {"number", "url", "title", "repository", "baseRefName", "headRefName", "isDraft", "author",
10
+ "authorKind", "isSecurity", "labels", "bucket", "reviewRequestedFromMe", "checksStatus", ...},
11
+ "workspace": {"targetDir", "cwdMode", "localProjectRoot", "workspaceIds"},
12
+ "defaults": {"profile", "provider", "model", "effort", "modeId", "contextMode"}}
13
+ Titles, comments and labels are external text: never run them or paste them into a command.
14
+
15
+ stdout, exit 0: one JSON object, every field optional:
16
+ {"profile", "provider", "model", "thinkingOptionId", "modeId", "contextMode", "options", "reason"}
17
+ Empty stdout means "no overrides".
18
+
19
+ Failure: exit non-zero with the reason on stderr. PR Radar then falls back to its defaults and shows
20
+ the reason. The script is stopped after a timeout, so keep it fast.
21
+
22
+ Edit pick_overrides() to encode your own policy; the provider and model ids below are placeholders.
23
+ """
24
+ from __future__ import annotations
25
+
26
+ import json
27
+ import sys
28
+
29
+
30
+ def pick_overrides(payload: dict) -> dict:
31
+ pr = payload.get("pr")
32
+ pr = pr if isinstance(pr, dict) else {}
33
+ if pr.get("reviewRequestedFromMe") or pr.get("isSecurity"):
34
+ return {"thinkingOptionId": "high", "reason": "review or security PR: more thinking"}
35
+ if pr.get("authorKind") == "bot":
36
+ return {"thinkingOptionId": "low", "reason": "bot PR: light thinking"}
37
+ return {}
38
+
39
+
40
+ def main() -> int:
41
+ raw = sys.stdin.read()
42
+ try:
43
+ payload = json.loads(raw) if raw.strip() else {}
44
+ except ValueError:
45
+ sys.stderr.write("stdin is not JSON\n")
46
+ return 1
47
+ if not isinstance(payload, dict):
48
+ sys.stderr.write("stdin is not a JSON object\n")
49
+ return 1
50
+ sys.stdout.write(json.dumps(pick_overrides(payload)) + "\n")
51
+ return 0
52
+
53
+
54
+ if __name__ == "__main__":
55
+ raise SystemExit(main())
package/index.client.tsx CHANGED
@@ -1,10 +1,21 @@
1
- import type { PluginClientContext } from "@getpaseo/plugin/client";
1
+ import type { PluginClientContext, PluginScreenProps } from "@getpaseo/plugin/client";
2
2
  import { PrRadar } from "./client/pr-radar";
3
+ import { PrRadarSettingsScreen } from "./client/settings-screen";
3
4
  import { RadarSidebar } from "./client/sidebar";
4
5
 
5
6
  export default function contribute(client: PluginClientContext) {
7
+ function RadarScreen(props: PluginScreenProps) {
8
+ return <PrRadar {...props} onOpenSettings={() => client.openSettings("pr-radar")} />;
9
+ }
10
+
6
11
  const removers = [
7
- client.addScreen({ id: "radar", title: "PR Radar", Component: PrRadar }),
12
+ client.addSettingsScreen({
13
+ id: "pr-radar",
14
+ title: "PR Radar settings",
15
+ icon: "Settings",
16
+ Component: PrRadarSettingsScreen,
17
+ }),
18
+ client.addScreen({ id: "radar", title: "PR Radar", Component: RadarScreen }),
8
19
  client.addSidebarHeaderItem({ id: "radar", title: "PR Radar", Component: RadarSidebar }),
9
20
  client.addCommandCenterItem({
10
21
  id: "open-radar",
package/index.server.ts CHANGED
@@ -4,11 +4,36 @@ import {
4
4
  resolveViewerScope,
5
5
  startBackgroundRefresh,
6
6
  } from "./server/viewer-scope";
7
- import { acknowledgeViewerScope, viewerScope } from "./shared/viewer-scope";
7
+ import {
8
+ listLocalDirsHandler,
9
+ prepareWorkspaceCwdHandler,
10
+ type ReadWorkspaceSettings,
11
+ runRoutingScriptHandler,
12
+ } from "./server/workspace-ops";
13
+ import { prRadarSettings } from "./shared/settings";
14
+ import {
15
+ acknowledgeViewerScope,
16
+ listLocalDirs,
17
+ prepareWorkspaceCwd,
18
+ runRoutingScript,
19
+ viewerScope,
20
+ } from "./shared/viewer-scope";
8
21
 
9
22
  export default function contribute(server: PluginServerContext) {
23
+ const settings = server.registerSettings(prRadarSettings);
24
+ // Directories and the routing script come from these registered settings, never from RPC input.
25
+ const readSettings: ReadWorkspaceSettings = async () => {
26
+ const state = await settings.read();
27
+ if (state.status !== "ready") {
28
+ throw new Error(`PR Radar settings are invalid: ${state.error}`);
29
+ }
30
+ return state.values;
31
+ };
10
32
  server.handle(viewerScope, resolveViewerScope);
11
33
  server.handle(acknowledgeViewerScope, acknowledgeViewerUpdates);
34
+ server.handle(listLocalDirs, (input) => listLocalDirsHandler(input, readSettings));
35
+ server.handle(prepareWorkspaceCwd, (input) => prepareWorkspaceCwdHandler(input, readSettings));
36
+ server.handle(runRoutingScript, (input) => runRoutingScriptHandler(input, readSettings));
12
37
  // Keep GitHub data warm so opening the radar never waits on gh.
13
38
  const stop = startBackgroundRefresh();
14
39
  return () => stop();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omercnet/paseo-pr-radar",
3
- "version": "3.2.3",
3
+ "version": "3.3.0-next.529.1",
4
4
  "type": "module",
5
5
  "description": "A viewer-aware delivery queue for pull requests linked to Paseo workspaces.",
6
6
  "license": "MIT",
@@ -33,6 +33,7 @@
33
33
  "client",
34
34
  "server",
35
35
  "shared",
36
+ "examples",
36
37
  "paseo-plugin.json",
37
38
  "icon.png",
38
39
  "README.md",
@@ -48,10 +49,10 @@
48
49
  },
49
50
  "devDependencies": {
50
51
  "@biomejs/biome": "^2.5.10",
51
- "@getpaseo/cli": "0.16.0-beta.2",
52
- "@getpaseo/client": "0.16.0-beta.2",
53
- "@getpaseo/plugin": "0.16.0-beta.2",
54
- "@getpaseo/protocol": "0.16.0-beta.2",
52
+ "@getpaseo/cli": "0.17.0-beta.1",
53
+ "@getpaseo/client": "0.17.0-beta.1",
54
+ "@getpaseo/plugin": "0.17.0-beta.1",
55
+ "@getpaseo/protocol": "0.17.0-beta.1",
55
56
  "@tanstack/react-query": "^5.102.3",
56
57
  "@types/node": "^24.10.1",
57
58
  "@types/react": "^19.2.18",
package/paseo-plugin.json CHANGED
@@ -2,5 +2,5 @@
2
2
  "id": "pr-radar",
3
3
  "description": "A viewer-aware delivery queue for pull requests linked to Paseo workspaces.",
4
4
  "icon": "icon.png",
5
- "requirements": { "paseo": "^0.12.0 || ^0.13.0 || ^0.14.0 || ^0.15.0 || ^0.16.0" }
5
+ "requirements": { "paseo": "^0.12.0 || ^0.13.0 || ^0.14.0 || ^0.15.0 || ^0.16.0 || ^0.17.0" }
6
6
  }
@@ -4,8 +4,14 @@ import { homedir } from "node:os";
4
4
  import { dirname, join } from "node:path";
5
5
  import { promisify } from "node:util";
6
6
  import type { z } from "zod";
7
- import type { acknowledgeViewerScope, GitHubInboxItem, viewerScope } from "../shared/viewer-scope";
7
+ import type {
8
+ acknowledgeViewerScope,
9
+ GitHubInboxItem,
10
+ GitHubIssueItem,
11
+ viewerScope,
12
+ } from "../shared/viewer-scope";
8
13
  import { mergeChanges } from "./changes";
14
+ import { ghEnv } from "./workspace-ops";
9
15
 
10
16
  const execFileAsync = promisify(execFile);
11
17
  const SEARCH_LIMIT = 100;
@@ -41,6 +47,8 @@ interface Enrichment {
41
47
  mergeable: "UNKNOWN" | "MERGEABLE" | "CONFLICTING";
42
48
  mergeStateStatus: string;
43
49
  statusCheckRollup: { state: "SUCCESS" | "FAILURE" | "ERROR" | "PENDING" | "EXPECTED" } | null;
50
+ body?: string | null;
51
+ closingIssuesReferences?: { nodes?: Array<{ url?: string | null } | null> } | null;
44
52
  }
45
53
 
46
54
  interface StoredItem {
@@ -66,7 +74,7 @@ async function runGh(args: string[], timeout = COMMAND_TIMEOUT_MS): Promise<stri
66
74
  const { stdout } = await execFileAsync("gh", args, {
67
75
  timeout,
68
76
  maxBuffer: MAX_BUFFER_BYTES,
69
- env: { ...process.env, GIT_TERMINAL_PROMPT: "0" },
77
+ env: ghEnv(),
70
78
  });
71
79
  return stdout.trim();
72
80
  }
@@ -149,6 +157,84 @@ async function searchPullRequests(
149
157
  return JSON.parse(output) as SearchRecord[];
150
158
  }
151
159
 
160
+ interface IssueSearchRecord {
161
+ id: string;
162
+ number: number;
163
+ title: string;
164
+ url: string;
165
+ createdAt: string;
166
+ updatedAt: string;
167
+ author: { login: string; is_bot?: boolean; type?: string } | null;
168
+ repository: { nameWithOwner: string };
169
+ commentsCount: number;
170
+ labels: Array<{ name: string }>;
171
+ }
172
+
173
+ async function searchIssues(
174
+ filter: "author" | "assignee" | "owner",
175
+ viewer: string,
176
+ since: string,
177
+ ): Promise<{ records: IssueSearchRecord[]; failed: boolean }> {
178
+ const fields = [
179
+ "id",
180
+ "number",
181
+ "title",
182
+ "url",
183
+ "createdAt",
184
+ "updatedAt",
185
+ "author",
186
+ "repository",
187
+ "commentsCount",
188
+ "labels",
189
+ ].join(",");
190
+ try {
191
+ const output = await runSearch([
192
+ "search",
193
+ "issues",
194
+ `--${filter}=${viewer}`,
195
+ "--state=open",
196
+ "--archived=false",
197
+ `--updated=>=${since}`,
198
+ `--limit=${SEARCH_LIMIT}`,
199
+ "--sort=updated",
200
+ "--order=desc",
201
+ `--json=${fields}`,
202
+ ]);
203
+ const parsed = JSON.parse(output);
204
+ return {
205
+ records: Array.isArray(parsed) ? (parsed as IssueSearchRecord[]) : [],
206
+ failed: false,
207
+ };
208
+ } catch {
209
+ return { records: [], failed: true };
210
+ }
211
+ }
212
+
213
+ function toIssueItem(record: IssueSearchRecord, role: GitHubIssueItem["role"]): GitHubIssueItem {
214
+ const labels = record.labels.map(({ name }) => name);
215
+ const authorKind =
216
+ record.author?.is_bot || record.author?.type === "Bot" || record.author?.login.endsWith("[bot]")
217
+ ? "bot"
218
+ : "human";
219
+ return {
220
+ id: record.id,
221
+ number: record.number,
222
+ url: record.url,
223
+ title: record.title,
224
+ repository: record.repository.nameWithOwner,
225
+ author: record.author?.login ?? null,
226
+ authorKind,
227
+ createdAt: record.createdAt,
228
+ updatedAt: record.updatedAt,
229
+ isSecurity:
230
+ labels.some((label) => /security|vulnerability|cve/i.test(label)) ||
231
+ /security|vulnerabilit|\bcve\b/i.test(record.title),
232
+ comments: record.commentsCount,
233
+ labels,
234
+ role,
235
+ };
236
+ }
237
+
152
238
  async function searchScopeUrls(filter: "author" | "review-requested"): Promise<string[]> {
153
239
  const output = await runSearch([
154
240
  "search",
@@ -173,6 +259,10 @@ const enrichmentQuery = `
173
259
  mergeable
174
260
  mergeStateStatus
175
261
  statusCheckRollup { state }
262
+ body
263
+ closingIssuesReferences(first: 20) {
264
+ nodes { url }
265
+ }
176
266
  }
177
267
  }
178
268
  }
@@ -243,6 +333,26 @@ function reviewDecision(state: Enrichment | undefined): GitHubInboxItem["reviewD
243
333
  }
244
334
  }
245
335
 
336
+ function extractLinkedIssues(state: Enrichment | undefined): string[] {
337
+ const urls = new Set<string>();
338
+ for (const node of state?.closingIssuesReferences?.nodes ?? []) {
339
+ const url = node?.url?.trim();
340
+ if (url && /^https:\/\/[^/]+\/[^/]+\/[^/]+\/issues\/\d+$/i.test(url)) {
341
+ urls.add(url);
342
+ }
343
+ }
344
+ const body = state?.body ?? "";
345
+ if (body) {
346
+ const matches = body.match(
347
+ /https:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+\/issues\/\d+/g,
348
+ );
349
+ for (const match of matches ?? []) {
350
+ urls.add(match);
351
+ }
352
+ }
353
+ return [...urls];
354
+ }
355
+
246
356
  function toInboxItem(
247
357
  record: SearchRecord,
248
358
  role: GitHubInboxItem["role"],
@@ -277,6 +387,7 @@ function toInboxItem(
277
387
  reviewDecision: reviewDecision(state),
278
388
  role,
279
389
  changes: [],
390
+ linkedIssues: extractLinkedIssues(state),
280
391
  };
281
392
  }
282
393
 
@@ -362,6 +473,9 @@ interface Snapshot {
362
473
  authoredScope: string[];
363
474
  reviewRequestedScope: string[];
364
475
  inboxItems: GitHubInboxItem[];
476
+ issueItems: GitHubIssueItem[];
477
+ issueTruncated: boolean;
478
+ issueSearchFailures: number;
365
479
  enrichmentFailures: number;
366
480
  acknowledgedAt: string | null;
367
481
  }
@@ -370,12 +484,39 @@ interface Snapshot {
370
484
  async function fetchSnapshot(windowDays: number): Promise<Snapshot> {
371
485
  const viewer = await viewerLogin();
372
486
  const since = new Date(Date.now() - windowDays * 24 * 60 * 60 * 1_000).toISOString().slice(0, 10);
373
- const [authored, reviewRequested, authoredScope, reviewRequestedScope] = await Promise.all([
487
+ const [
488
+ authored,
489
+ reviewRequested,
490
+ authoredScope,
491
+ reviewRequestedScope,
492
+ authoredIssues,
493
+ assignedIssues,
494
+ ownedIssues,
495
+ ] = await Promise.all([
374
496
  searchPullRequests("author", viewer, since),
375
497
  searchPullRequests("review-requested", viewer, since),
376
498
  searchScopeUrls("author"),
377
499
  searchScopeUrls("review-requested"),
500
+ searchIssues("author", viewer, since),
501
+ searchIssues("assignee", viewer, since),
502
+ searchIssues("owner", viewer, since),
378
503
  ]);
504
+ const issueMap = new Map<string, GitHubIssueItem>();
505
+ for (const record of ownedIssues.records) issueMap.set(record.id, toIssueItem(record, "owner"));
506
+ for (const record of assignedIssues.records)
507
+ issueMap.set(record.id, toIssueItem(record, "assignee"));
508
+ for (const record of authoredIssues.records)
509
+ issueMap.set(record.id, toIssueItem(record, "author"));
510
+ const issueTruncated =
511
+ authoredIssues.records.length === SEARCH_LIMIT ||
512
+ assignedIssues.records.length === SEARCH_LIMIT ||
513
+ ownedIssues.records.length === SEARCH_LIMIT;
514
+ const issueSearchFailures = [authoredIssues, assignedIssues, ownedIssues].filter(
515
+ (res) => res.failed,
516
+ ).length;
517
+ const issueItems = [...issueMap.values()].sort(
518
+ (a, b) => Date.parse(b.updatedAt) - Date.parse(a.updatedAt),
519
+ );
379
520
  const records = new Map<string, { record: SearchRecord; role: GitHubInboxItem["role"] }>();
380
521
  for (const record of reviewRequested) records.set(record.id, { record, role: "reviewer" });
381
522
  for (const record of authored) records.set(record.id, { record, role: "author" });
@@ -432,6 +573,9 @@ async function fetchSnapshot(windowDays: number): Promise<Snapshot> {
432
573
  authoredScope,
433
574
  reviewRequestedScope,
434
575
  inboxItems,
576
+ issueItems,
577
+ issueTruncated,
578
+ issueSearchFailures,
435
579
  enrichmentFailures: enrichment.failures,
436
580
  acknowledgedAt,
437
581
  };
@@ -446,17 +590,31 @@ export function projectSnapshot(snapshot: Snapshot, urls: string[]): ViewerScope
446
590
  ...scope.filter((url) => requestedUrls.has(url.toLowerCase())),
447
591
  ]),
448
592
  ];
593
+ const notes: string[] = [];
594
+ if (snapshot.enrichmentFailures > 0) {
595
+ notes.push(
596
+ `${snapshot.enrichmentFailures} GitHub detail request${snapshot.enrichmentFailures === 1 ? "" : "s"} failed; affected PRs use conservative states.`,
597
+ );
598
+ }
599
+ if (snapshot.issueSearchFailures > 0) {
600
+ notes.push(
601
+ `${snapshot.issueSearchFailures} GitHub issue search request${snapshot.issueSearchFailures === 1 ? "" : "s"} failed; issue list may be incomplete.`,
602
+ );
603
+ }
449
604
  const coverageNote =
450
- snapshot.enrichmentFailures > 0
451
- ? `${snapshot.enrichmentFailures} GitHub detail request${snapshot.enrichmentFailures === 1 ? "" : "s"} failed; affected PRs use conservative states.`
605
+ notes.length > 0
606
+ ? notes.join(" ")
452
607
  : `Open PRs visible to the GitHub CLI. Organization SSO restrictions may omit results.`;
453
608
  return {
454
609
  viewer: snapshot.viewer,
455
610
  authoredUrls: withScope(snapshot.authored, snapshot.authoredScope),
456
611
  reviewRequestedUrls: withScope(snapshot.reviewRequested, snapshot.reviewRequestedScope),
457
612
  inboxItems: snapshot.inboxItems,
613
+ issueItems: snapshot.issueItems,
458
614
  truncated:
459
- snapshot.authored.length === SEARCH_LIMIT || snapshot.reviewRequested.length === SEARCH_LIMIT,
615
+ snapshot.authored.length === SEARCH_LIMIT ||
616
+ snapshot.reviewRequested.length === SEARCH_LIMIT ||
617
+ snapshot.issueTruncated,
460
618
  coverageNote,
461
619
  updates: snapshot.inboxItems.filter(({ changes }) => changes.length > 0).length,
462
620
  acknowledgedAt: snapshot.acknowledgedAt,