pr-shepherd 1.5.0 → 1.6.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.
Files changed (72) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +1 -0
  3. package/bin/api.d.mts +1 -1
  4. package/bin/commands/iterate/index.mjs +4 -0
  5. package/bin/commands/poll-events.d.mts +44 -0
  6. package/bin/commands/poll-events.mjs +123 -0
  7. package/bin/commands/poll-options.d.mts +9 -0
  8. package/bin/commands/poll-options.mjs +1 -0
  9. package/bin/commands/poll-progress.d.mts +2 -0
  10. package/bin/commands/poll-progress.mjs +6 -4
  11. package/bin/commands/poll-quota.d.mts +2 -0
  12. package/bin/commands/poll-quota.mjs +4 -0
  13. package/bin/commands/poll-summary.d.mts +1 -0
  14. package/bin/commands/poll-summary.mjs +30 -18
  15. package/bin/commands/poll-tick.d.mts +17 -0
  16. package/bin/commands/poll-tick.mjs +24 -0
  17. package/bin/commands/poll.d.mts +3 -9
  18. package/bin/commands/poll.mjs +64 -60
  19. package/bin/commands/stall-deadline.d.mts +20 -0
  20. package/bin/commands/stall-deadline.mjs +42 -0
  21. package/bin/commands/tick.mjs +1 -16
  22. package/bin/config/schema.d.mts +14 -0
  23. package/bin/config/schema.mjs +6 -0
  24. package/bin/events/config.d.mts +7 -0
  25. package/bin/events/config.mjs +66 -0
  26. package/bin/events/envelope.d.mts +4 -0
  27. package/bin/events/envelope.mjs +27 -0
  28. package/bin/events/filters.d.mts +8 -0
  29. package/bin/events/filters.mjs +27 -0
  30. package/bin/events/health.d.mts +14 -0
  31. package/bin/events/health.mjs +27 -0
  32. package/bin/events/matcher.d.mts +2 -0
  33. package/bin/events/matcher.mjs +32 -0
  34. package/bin/events/relay.d.mts +11 -0
  35. package/bin/events/relay.mjs +86 -0
  36. package/bin/events/serve.d.mts +10 -0
  37. package/bin/events/serve.mjs +137 -0
  38. package/bin/events/sse.d.mts +10 -0
  39. package/bin/events/sse.mjs +50 -0
  40. package/bin/events/types.d.mts +69 -0
  41. package/bin/events/types.mjs +1 -0
  42. package/bin/events/waiter.d.mts +47 -0
  43. package/bin/events/waiter.mjs +80 -0
  44. package/bin/github/batch-first-page.d.mts +17 -0
  45. package/bin/github/batch-first-page.mjs +48 -0
  46. package/bin/github/batch-page.d.mts +2 -0
  47. package/bin/github/batch-page.mjs +2 -2
  48. package/bin/github/batch-stack-evidence.d.mts +3 -1
  49. package/bin/github/batch-stack-evidence.mjs +4 -2
  50. package/bin/github/batch-viewer.d.mts +24 -0
  51. package/bin/github/batch-viewer.mjs +66 -0
  52. package/bin/github/batch.d.mts +1 -1
  53. package/bin/github/batch.mjs +30 -35
  54. package/bin/github/check-annotations-batch.mjs +1 -7
  55. package/bin/github/gql/batch-pr-viewer.gql +46 -0
  56. package/bin/github/gql-strip-viewer.d.mts +7 -0
  57. package/bin/github/gql-strip-viewer.mjs +14 -0
  58. package/bin/github/queries.d.mts +8 -0
  59. package/bin/github/queries.mjs +9 -0
  60. package/bin/github/thread-comments.d.mts +1 -1
  61. package/bin/github/thread-comments.mjs +7 -7
  62. package/bin/types/iterate.d.mts +9 -0
  63. package/bin/util/chunks.d.mts +2 -0
  64. package/bin/util/chunks.mjs +8 -0
  65. package/package.json +1 -1
  66. package/plugins/pr-shepherd/.claude-plugin/plugin.json +1 -1
  67. package/plugins/pr-shepherd/.codex-plugin/plugin.json +1 -1
  68. package/plugins/pr-shepherd/.codex.mcp.json +1 -1
  69. package/plugins/pr-shepherd/.mcp.json +1 -1
  70. package/plugins/pr-shepherd/package-lock.json +4 -4
  71. package/plugins/pr-shepherd/package.json +1 -1
  72. package/pr-shepherd.schema.json +21 -0
@@ -8,12 +8,19 @@
8
8
  */
9
9
  import { readFileSync } from "node:fs";
10
10
  import { join } from "node:path";
11
+ import { stripViewerFields } from "./gql-strip-viewer.mjs";
11
12
  const gql = (name) => readFileSync(join(import.meta.dirname, "gql", name), "utf8");
12
13
  const withSharedFragments = (query) => `${gql("ref-rules.gql")}\n${gql("pr-merge-policy.gql")}\n${gql("commit-check-suites.gql")}\n${query}`;
13
14
  /** The primary batch query that fetches CI + comments + merge status in one round-trip. */
14
15
  export const BATCH_PR_QUERY = withSharedFragments(gql("batch-pr.gql"));
16
+ /** `BatchPr` without any viewer field: a GitHub App may answer it. Paired with `BATCH_PR_VIEWER_QUERY`. */
17
+ export const BATCH_PR_DATA_QUERY = stripViewerFields(BATCH_PR_QUERY, "BatchPrData");
18
+ /** Viewer-relative fields (user token) for the node ids a viewer-free `BatchPr` read returned. */
19
+ export const BATCH_PR_VIEWER_QUERY = gql("batch-pr-viewer.gql");
15
20
  /** Slim @include follow-up for outstanding batch-query connections. */
16
21
  export const BATCH_PR_PAGE_QUERY = gql("batch-pr-page.gql");
22
+ /** `BatchPrPage` without viewer fields, for the viewer-free split read. */
23
+ export const BATCH_PR_PAGE_DATA_QUERY = stripViewerFields(BATCH_PR_PAGE_QUERY, "BatchPrPageData");
17
24
  const POLL_SUMMARY_CHECK_CONTEXTS_FRAGMENT = gql("poll-summary-check-contexts.gql");
18
25
  /** Compact per-PR fields shared by explicit-list and native-stack summary queries. */
19
26
  export const POLL_SUMMARY_FRAGMENT = `${gql("ref-rules.gql")}\n${POLL_SUMMARY_CHECK_CONTEXTS_FRAGMENT}\n${gql("poll-summary-fragment.gql")}`;
@@ -52,6 +59,8 @@ export const MERGED_BASE_PULL_REQUESTS_QUERY = gql("merged-base-pull-requests.gq
52
59
  export const SUGGESTION_THREADS_QUERY = gql("suggestion-threads.gql");
53
60
  /** Fetches additional comments for a single review thread when its nested connection paginates. */
54
61
  export const REVIEW_THREAD_COMMENTS_QUERY = gql("review-thread-comments.gql");
62
+ /** `ReviewThreadComments` without `viewerDidAuthor`, for the viewer-free split read. */
63
+ export const REVIEW_THREAD_COMMENTS_DATA_QUERY = stripViewerFields(REVIEW_THREAD_COMMENTS_QUERY, "ReviewThreadCommentsData");
55
64
  /** Requested review-thread transcripts for best-effort reply seen markers. */
56
65
  export const REPLY_THREAD_TRANSCRIPTS_QUERY = gql("reply-thread-transcripts.gql");
57
66
  export const REPLY_THREAD_COMMENTS_QUERY = gql("reply-thread-comments.gql");
@@ -1,6 +1,6 @@
1
1
  import { type RateLimitInfo } from "./client.mts";
2
2
  import type { RawThread } from "./batch-raw-types.mts";
3
- export declare function hydrateThreadCommentPages(threads: RawThread[], initialRateLimit?: RateLimitInfo): Promise<{
3
+ export declare function hydrateThreadCommentPages(threads: RawThread[], initialRateLimit?: RateLimitInfo, viewerFree?: boolean): Promise<{
4
4
  threads: RawThread[];
5
5
  rateLimit?: RateLimitInfo;
6
6
  }>;
@@ -3,10 +3,10 @@ import { readRestRawThread } from "./rest-thread-read.mjs";
3
3
  import { graphqlWithRateLimit } from "./client.mjs";
4
4
  import { GitHubRequestError } from "./errors.mjs";
5
5
  import { paginateForward } from "./pagination.mjs";
6
- import { REVIEW_THREAD_COMMENTS_QUERY } from "./queries.mjs";
6
+ import { REVIEW_THREAD_COMMENTS_DATA_QUERY, REVIEW_THREAD_COMMENTS_QUERY } from "./queries.mjs";
7
7
  import { mapPool } from "../util/pool.mjs";
8
8
  const THREAD_COMMENT_PAGE_CONCURRENCY = 4;
9
- async function hydrateGraphqlThreadCommentPages(threads, initialRateLimit) {
9
+ async function hydrateGraphqlThreadCommentPages(threads, initialRateLimit, viewerFree = false) {
10
10
  const gate = {
11
11
  rateLimit: initialRateLimit,
12
12
  exhausted: initialRateLimit?.remaining === 0,
@@ -15,7 +15,7 @@ async function hydrateGraphqlThreadCommentPages(threads, initialRateLimit) {
15
15
  if (gate.error !== undefined)
16
16
  return thread;
17
17
  try {
18
- return await hydrateThreadCommentPage(thread, gate);
18
+ return await hydrateThreadCommentPage(thread, gate, viewerFree);
19
19
  }
20
20
  catch (error) {
21
21
  gate.error ??= error;
@@ -26,7 +26,7 @@ async function hydrateGraphqlThreadCommentPages(threads, initialRateLimit) {
26
26
  throw gate.error;
27
27
  return { threads: hydrated, rateLimit: gate.rateLimit };
28
28
  }
29
- async function hydrateThreadCommentPage(thread, gate) {
29
+ async function hydrateThreadCommentPage(thread, gate, viewerFree) {
30
30
  const pageInfo = thread.comments.pageInfo;
31
31
  if (!pageInfo?.hasNextPage || !pageInfo.endCursor)
32
32
  return thread;
@@ -36,7 +36,7 @@ async function hydrateThreadCommentPage(thread, gate) {
36
36
  if (gate.exhausted) {
37
37
  throw new GitHubRequestError("GitHub GraphQL rate limit remaining is 0; thread comment pagination incomplete", { status: 403, rateLimit: gate.rateLimit });
38
38
  }
39
- const res = await graphqlWithRateLimit(REVIEW_THREAD_COMMENTS_QUERY, {
39
+ const res = await graphqlWithRateLimit(viewerFree ? REVIEW_THREAD_COMMENTS_DATA_QUERY : REVIEW_THREAD_COMMENTS_QUERY, {
40
40
  threadId: thread.id,
41
41
  ...(cursor ? { commentsCursor: cursor } : {}),
42
42
  });
@@ -62,8 +62,8 @@ async function hydrateThreadCommentPage(thread, gate) {
62
62
  },
63
63
  };
64
64
  }
65
- export function hydrateThreadCommentPages(threads, initialRateLimit) {
66
- return githubOperation("ReviewThreadComments", () => hydrateGraphqlThreadCommentPages(threads, initialRateLimit), async () => ({
65
+ export function hydrateThreadCommentPages(threads, initialRateLimit, viewerFree = false) {
66
+ return githubOperation("ReviewThreadComments", () => hydrateGraphqlThreadCommentPages(threads, initialRateLimit, viewerFree), async () => ({
67
67
  threads: await mapPool(threads, THREAD_COMMENT_PAGE_CONCURRENCY, async (thread) => thread.comments.pageInfo?.hasNextPage ? readRestRawThread(thread.id) : thread),
68
68
  rateLimit: initialRateLimit,
69
69
  }));
@@ -200,6 +200,15 @@ export interface IterateCommandOptions extends GlobalOptions {
200
200
  stallDeadlineSink?: {
201
201
  ciStartDeadlineSeconds?: number;
202
202
  };
203
+ /**
204
+ * Internal. Poll receives the PR's head SHA and head branch from the tick's batch data so
205
+ * event-driven waits can match webhook events. Never serialized into a result. Excluded from
206
+ * the public `IterateInput` in api.mts.
207
+ */
208
+ eventTargetSink?: {
209
+ headSha?: string;
210
+ headRef?: string;
211
+ };
203
212
  /** Shepherd through readiness and emit the exact merge/queue command when ready. */
204
213
  merge?: boolean;
205
214
  /** Override `iterate.instructions` for this call. */
@@ -0,0 +1,2 @@
1
+ /** Split `items` into consecutive slices of at most `size`. */
2
+ export declare function chunksOf<T>(items: T[], size: number): T[][];
@@ -0,0 +1,8 @@
1
+ /** Split `items` into consecutive slices of at most `size`. */
2
+ export function chunksOf(items, size) {
3
+ const chunks = [];
4
+ for (let index = 0; index < items.length; index += size) {
5
+ chunks.push(items.slice(index, index + size));
6
+ }
7
+ return chunks;
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pr-shepherd",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Autonomous PR CI monitor and review-comment resolver for agentic coding tools",
5
5
  "keywords": [
6
6
  "automation",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pr-shepherd",
3
3
  "description": "Autonomous PR CI monitor and review-comment resolver for agentic coding tools",
4
- "version": "1.5.0",
4
+ "version": "1.6.0",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",
7
7
  "email": "jonathanrichardong@gmail.com"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pr-shepherd",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Autonomous PR CI monitor and review-comment resolver for Codex.",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",
@@ -2,7 +2,7 @@
2
2
  "mcpServers": {
3
3
  "pr-shepherd": {
4
4
  "command": "npx",
5
- "args": ["--yes", "--package", "pr-shepherd@1.5.0", "pr-shepherd-mcp"]
5
+ "args": ["--yes", "--package", "pr-shepherd@1.6.0", "pr-shepherd-mcp"]
6
6
  }
7
7
  }
8
8
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "pr-shepherd": {
3
3
  "command": "npx",
4
- "args": ["--yes", "--package", "pr-shepherd@1.5.0", "pr-shepherd-mcp"]
4
+ "args": ["--yes", "--package", "pr-shepherd@1.6.0", "pr-shepherd-mcp"]
5
5
  }
6
6
  }
@@ -7,7 +7,7 @@
7
7
  "name": "pr-shepherd-plugin",
8
8
  "license": "MIT",
9
9
  "dependencies": {
10
- "pr-shepherd": "1.4.0"
10
+ "pr-shepherd": "1.5.0"
11
11
  }
12
12
  },
13
13
  "node_modules/@hono/node-server": {
@@ -889,9 +889,9 @@
889
889
  }
890
890
  },
891
891
  "node_modules/pr-shepherd": {
892
- "version": "1.4.0",
893
- "resolved": "https://registry.npmjs.org/pr-shepherd/-/pr-shepherd-1.4.0.tgz",
894
- "integrity": "sha512-3eYsELFSn/tR1fPUFjYVm1zc5w7GfhxcDUvhALvhtdipT2T1ynyCr9lwAc2eX8G/32FMltpsC0YQTuV/gDulQw==",
892
+ "version": "1.5.0",
893
+ "resolved": "https://registry.npmjs.org/pr-shepherd/-/pr-shepherd-1.5.0.tgz",
894
+ "integrity": "sha512-flRD8kbqdaRH9STn+DO4LBRj6WMOUUYYdMd7nkXW0dut08CJnkLildPmJ8U0GZqJ9LPOW5wCwpVJu2xSGWnXig==",
895
895
  "license": "MIT",
896
896
  "dependencies": {
897
897
  "@modelcontextprotocol/sdk": "^1.30.0",
@@ -4,6 +4,6 @@
4
4
  "description": "Pins the pr-shepherd package that .mcp.json launches",
5
5
  "license": "MIT",
6
6
  "dependencies": {
7
- "pr-shepherd": "1.4.0"
7
+ "pr-shepherd": "1.5.0"
8
8
  }
9
9
  }
@@ -242,6 +242,27 @@
242
242
  },
243
243
  "additionalProperties": false
244
244
  },
245
+ "events": {
246
+ "default": {},
247
+ "type": "object",
248
+ "properties": {
249
+ "source": {
250
+ "default": "none",
251
+ "type": "string",
252
+ "enum": [
253
+ "none",
254
+ "hook-harness"
255
+ ]
256
+ },
257
+ "fallback-interval-seconds": {
258
+ "default": 300,
259
+ "type": "number",
260
+ "exclusiveMinimum": 0,
261
+ "maximum": 86400
262
+ }
263
+ },
264
+ "additionalProperties": false
265
+ },
245
266
  "apply": {
246
267
  "default": {},
247
268
  "type": "object",