pr-shepherd 1.4.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.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +1 -0
- package/bin/api.d.mts +1 -1
- package/bin/cli/help-command-pages.d.mts +2 -2
- package/bin/cli/help-iterate-poll-pages.d.mts +2 -2
- package/bin/cli/help-iterate-poll-pages.mjs +3 -2
- package/bin/cli/help.d.mts +2 -2
- package/bin/commands/iterate/index.mjs +4 -0
- package/bin/commands/poll-events.d.mts +44 -0
- package/bin/commands/poll-events.mjs +123 -0
- package/bin/commands/poll-options.d.mts +9 -0
- package/bin/commands/poll-options.mjs +1 -0
- package/bin/commands/poll-progress.d.mts +2 -0
- package/bin/commands/poll-progress.mjs +6 -4
- package/bin/commands/poll-quota.d.mts +2 -0
- package/bin/commands/poll-quota.mjs +4 -0
- package/bin/commands/poll-summary-explicit-instructions.mjs +1 -1
- package/bin/commands/poll-summary.d.mts +1 -0
- package/bin/commands/poll-summary.mjs +30 -18
- package/bin/commands/poll-tick.d.mts +17 -0
- package/bin/commands/poll-tick.mjs +24 -0
- package/bin/commands/poll.d.mts +3 -9
- package/bin/commands/poll.mjs +64 -60
- package/bin/commands/stall-deadline.d.mts +20 -0
- package/bin/commands/stall-deadline.mjs +42 -0
- package/bin/commands/tick.mjs +2 -16
- package/bin/config/schema.d.mts +14 -0
- package/bin/config/schema.mjs +6 -0
- package/bin/events/config.d.mts +7 -0
- package/bin/events/config.mjs +66 -0
- package/bin/events/envelope.d.mts +4 -0
- package/bin/events/envelope.mjs +27 -0
- package/bin/events/filters.d.mts +8 -0
- package/bin/events/filters.mjs +27 -0
- package/bin/events/health.d.mts +14 -0
- package/bin/events/health.mjs +27 -0
- package/bin/events/matcher.d.mts +2 -0
- package/bin/events/matcher.mjs +32 -0
- package/bin/events/relay.d.mts +11 -0
- package/bin/events/relay.mjs +86 -0
- package/bin/events/serve.d.mts +10 -0
- package/bin/events/serve.mjs +137 -0
- package/bin/events/sse.d.mts +10 -0
- package/bin/events/sse.mjs +50 -0
- package/bin/events/types.d.mts +69 -0
- package/bin/events/types.mjs +1 -0
- package/bin/events/waiter.d.mts +47 -0
- package/bin/events/waiter.mjs +80 -0
- package/bin/github/batch-first-page.d.mts +17 -0
- package/bin/github/batch-first-page.mjs +48 -0
- package/bin/github/batch-page.d.mts +2 -0
- package/bin/github/batch-page.mjs +2 -2
- package/bin/github/batch-stack-evidence.d.mts +3 -1
- package/bin/github/batch-stack-evidence.mjs +4 -2
- package/bin/github/batch-viewer.d.mts +24 -0
- package/bin/github/batch-viewer.mjs +66 -0
- package/bin/github/batch.d.mts +1 -1
- package/bin/github/batch.mjs +30 -35
- package/bin/github/check-annotations-batch.mjs +1 -7
- package/bin/github/gql/batch-pr-viewer.gql +46 -0
- package/bin/github/gql-strip-viewer.d.mts +7 -0
- package/bin/github/gql-strip-viewer.mjs +14 -0
- package/bin/github/queries.d.mts +8 -0
- package/bin/github/queries.mjs +9 -0
- package/bin/github/thread-comments.d.mts +1 -1
- package/bin/github/thread-comments.mjs +7 -7
- package/bin/types/iterate.d.mts +9 -0
- package/bin/util/chunks.d.mts +2 -0
- package/bin/util/chunks.mjs +8 -0
- package/package.json +1 -1
- package/plugins/pr-shepherd/.claude-plugin/plugin.json +1 -1
- package/plugins/pr-shepherd/.codex-plugin/plugin.json +1 -1
- package/plugins/pr-shepherd/.codex.mcp.json +1 -1
- package/plugins/pr-shepherd/.mcp.json +1 -1
- package/plugins/pr-shepherd/package-lock.json +4 -4
- package/plugins/pr-shepherd/package.json +1 -1
- package/plugins/pr-shepherd/skills/pr-shepherd/SKILL.md +2 -2
- package/plugins/pr-shepherd/skills/pr-shepherd/references/waiting.md +8 -0
- package/pr-shepherd.schema.json +21 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { graphqlWithRateLimit } from "./client.mjs";
|
|
2
|
+
import { mapPool } from "../util/pool.mjs";
|
|
3
|
+
import { chunksOf } from "../util/chunks.mjs";
|
|
4
|
+
import { BATCH_PR_VIEWER_QUERY } from "./queries.mjs";
|
|
5
|
+
const NODES_PER_REQUEST = 100; // GraphQL `nodes(ids:)` limit
|
|
6
|
+
const CONCURRENCY = 4;
|
|
7
|
+
/** A bot's GraphQL `Bot` author has no `[bot]` suffix, but its token's `viewer.login` does. */
|
|
8
|
+
const normalizeLogin = (login) => login.toLowerCase().replace(/\[bot\]$/, "");
|
|
9
|
+
/**
|
|
10
|
+
* Read the viewer-relative fields a viewer-free `BatchPr` read omitted, on the user's token, in
|
|
11
|
+
* the same tick, and write them onto the raw nodes. A node GitHub did not return keeps its
|
|
12
|
+
* fields unset, which the parser reads as "no" (fail closed). `viewerDidAuthor` on thread
|
|
13
|
+
* comments is the viewer login compared with the comment author: one login per request instead
|
|
14
|
+
* of one id per comment.
|
|
15
|
+
*/
|
|
16
|
+
export async function applyBatchViewer(repo, raw, targets) {
|
|
17
|
+
const ids = [
|
|
18
|
+
raw.id,
|
|
19
|
+
...targets.threads.map((t) => t.id),
|
|
20
|
+
...targets.comments.map((c) => c.id),
|
|
21
|
+
...targets.reviews.map((r) => r.id),
|
|
22
|
+
];
|
|
23
|
+
const nodes = new Map();
|
|
24
|
+
// Only the first chunk selects `viewer` and the repository. `allowPartialData`: an id that no
|
|
25
|
+
// longer resolves (a comment deleted since the data read) comes back null beside a NOT_FOUND
|
|
26
|
+
// error, and its fields stay unset (fail closed) instead of failing the tick.
|
|
27
|
+
const results = await mapPool(chunksOf(ids, NODES_PER_REQUEST), CONCURRENCY, (batch, index) => graphqlWithRateLimit(BATCH_PR_VIEWER_QUERY, { owner: repo.owner, repo: repo.name, ids: batch, includeViewer: index === 0 }, { allowPartialData: true }));
|
|
28
|
+
for (const res of results) {
|
|
29
|
+
for (const node of res.data.nodes)
|
|
30
|
+
if (node?.id)
|
|
31
|
+
nodes.set(node.id, node);
|
|
32
|
+
}
|
|
33
|
+
const first = results[0];
|
|
34
|
+
if (!first.data.repository) {
|
|
35
|
+
throw new Error(`GitHub viewer read did not include repository ${repo.owner}/${repo.name}`);
|
|
36
|
+
}
|
|
37
|
+
const viewer = {
|
|
38
|
+
login: first.data.viewer?.login ?? null,
|
|
39
|
+
repository: first.data.repository,
|
|
40
|
+
...(first.rateLimit && { rateLimit: first.rateLimit }),
|
|
41
|
+
};
|
|
42
|
+
const login = viewer.login === null ? undefined : normalizeLogin(viewer.login);
|
|
43
|
+
const prNode = nodes.get(raw.id);
|
|
44
|
+
raw.viewerDidAuthor = prNode?.viewerDidAuthor === true;
|
|
45
|
+
raw.viewerCanUpdate = prNode?.viewerCanUpdate === true;
|
|
46
|
+
raw.viewerCanEnableAutoMerge = prNode?.viewerCanEnableAutoMerge === true;
|
|
47
|
+
raw.viewerCanEditFiles = prNode?.viewerCanEditFiles === true;
|
|
48
|
+
if (raw.headRepository) {
|
|
49
|
+
raw.headRepository.viewerPermission = prNode?.headRepository?.viewerPermission ?? null;
|
|
50
|
+
}
|
|
51
|
+
for (const thread of targets.threads) {
|
|
52
|
+
const node = nodes.get(thread.id);
|
|
53
|
+
thread.viewerCanReply = node?.viewerCanReply === true;
|
|
54
|
+
thread.viewerCanResolve = node?.viewerCanResolve === true;
|
|
55
|
+
for (const comment of thread.comments.nodes) {
|
|
56
|
+
comment.viewerDidAuthor =
|
|
57
|
+
login !== undefined &&
|
|
58
|
+
comment.author?.login !== undefined &&
|
|
59
|
+
normalizeLogin(comment.author.login) === login;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (const item of [...targets.comments, ...targets.reviews]) {
|
|
63
|
+
item.viewerCanMinimize = nodes.get(item.id)?.viewerCanMinimize === true;
|
|
64
|
+
}
|
|
65
|
+
return viewer;
|
|
66
|
+
}
|
package/bin/github/batch.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { RateLimitInfo, RepoInfo } from "./client.mts";
|
|
2
2
|
import type { WorkflowSuiteSnapshot } from "../checks/unreported-required.mts";
|
|
3
3
|
import type { RawSummaryPr } from "./poll-summary-raw.mts";
|
|
4
4
|
import type { BatchPrData } from "../types.mts";
|
package/bin/github/batch.mjs
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { recordThreadIdentity } from "./rest-identities.mjs";
|
|
2
2
|
import { githubOperation, runWithGithubTransport } from "./transport.mjs";
|
|
3
3
|
import { fetchRestPrBatch } from "./rest-batch-read.mjs";
|
|
4
|
-
import { graphqlWithRateLimit } from "./client.mjs";
|
|
5
4
|
import { hydrateThreadCommentPages } from "./thread-comments.mjs";
|
|
6
|
-
import {
|
|
5
|
+
import { makeAuthHeaders } from "./http-auth.mjs";
|
|
6
|
+
import { readBatchFirstPage, usesViewerSplit } from "./batch-first-page.mjs";
|
|
7
|
+
import { applyBatchViewer } from "./batch-viewer.mjs";
|
|
7
8
|
import { prepareBatchReceiptEvidence } from "./batch-receipt-evidence.mjs";
|
|
8
|
-
import { GitHubRequestError, isRetryableGraphQlResourceLimit, } from "./errors.mjs";
|
|
9
|
-
import { rateLimitKind } from "./rate-limit-kind.mjs";
|
|
10
9
|
import { parseRawPr } from "./batch-parsers.mjs";
|
|
11
10
|
import { parseCheckSuitesComplete, parseHeadCheckSuitesEmpty, workflowSuites, parseSuiteStartupFailures, } from "./batch-parse-suites.mjs";
|
|
12
11
|
import { mergeStartupFailureChecks } from "../checks/startup-failures.mjs";
|
|
@@ -16,46 +15,39 @@ import { hydrateMergeQueueChecks } from "./merge-queue-checks.mjs";
|
|
|
16
15
|
import { fingerprintFromRaw } from "./fingerprint.mjs";
|
|
17
16
|
import { stackEvidenceFromRaw } from "./batch-stack-evidence.mjs";
|
|
18
17
|
import { takeStackHandoff } from "./stack-handoff.mjs";
|
|
19
|
-
function onlyReceiptSummaryErrors(errors) {
|
|
20
|
-
return (!!errors?.length &&
|
|
21
|
-
errors.every((error) => Array.isArray(error.path) &&
|
|
22
|
-
error.path[0] === "repository" &&
|
|
23
|
-
error.path[1] === "receiptSummary"));
|
|
24
|
-
}
|
|
25
|
-
async function readBatchFirstPage(pr, repo, opts) {
|
|
26
|
-
const variables = { owner: repo.owner, repo: repo.name, pr };
|
|
27
|
-
try {
|
|
28
|
-
return await graphqlWithRateLimit(opts.includeReceiptSummary ? BATCH_PR_RECEIPT_QUERY : BATCH_PR_QUERY, variables);
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
if (!opts.includeReceiptSummary ||
|
|
32
|
-
!(error instanceof GitHubRequestError) ||
|
|
33
|
-
rateLimitKind(error) !== null ||
|
|
34
|
-
!(isRetryableGraphQlResourceLimit(error.graphqlErrors) ||
|
|
35
|
-
(error.status === 200 && onlyReceiptSummaryErrors(error.graphqlErrors))))
|
|
36
|
-
throw error;
|
|
37
|
-
// Receipt evidence is optional; a resource-limited combined query or an
|
|
38
|
-
// error confined to its sibling must not prevent the ordinary snapshot.
|
|
39
|
-
return graphqlWithRateLimit(BATCH_PR_QUERY, variables);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
18
|
/**
|
|
43
19
|
* Fetch all PR data needed for a `shepherd check` in one (or a few, if paginating) GraphQL requests.
|
|
44
20
|
*/
|
|
45
21
|
async function fetchGraphqlPrBatch(pr, repo, opts = {}, reuse) {
|
|
46
22
|
const handoff = await takeStackHandoff(repo, pr); // a routed stack layer's first read
|
|
47
|
-
|
|
23
|
+
// The READY receipt sibling and a stack handoff carry viewer fields in the same document, and
|
|
24
|
+
// a READY candidate needs them anyway, so those reads stay combined on the user's token.
|
|
25
|
+
const split = !handoff && (await usesViewerSplit(repo, opts));
|
|
26
|
+
const result = handoff ? { data: handoff } : await readBatchFirstPage(pr, repo, opts, split);
|
|
48
27
|
const raw = requireRawPr(result.data, pr, repo);
|
|
49
|
-
|
|
28
|
+
// A split read carries no viewer field, so its fingerprint holds the user token's identity in
|
|
29
|
+
// place of the viewer login: another token never matches a stored one.
|
|
30
|
+
const fingerprint = fingerprintFromRaw(raw, result.data.repository?.viewerPermission ?? null, result.data.viewer?.login ?? (split ? `token:${(await makeAuthHeaders()).fingerprint}` : null));
|
|
50
31
|
// Decide reuse from the first page alone, before any supplement is paid for.
|
|
51
32
|
const reused = reuse && (await reuse(fingerprint));
|
|
52
33
|
const baseTipOid = raw.baseRef?.target?.oid;
|
|
53
|
-
|
|
34
|
+
// A split read has no viewer fields yet, so a reused tick carries only the trunk rules.
|
|
35
|
+
let stackEvidence = stackEvidenceFromRaw(raw, result.data, split);
|
|
54
36
|
if (reused)
|
|
55
37
|
return { reused, ...(baseTipOid && { baseTipOid }), ...(stackEvidence && { stackEvidence }) };
|
|
56
38
|
const queueRateLimit = await hydrateMergeQueueChecks(raw, repo, result.rateLimit);
|
|
57
|
-
const paged = await paginateBatchConnections(pr, repo, raw, opts, queueRateLimit);
|
|
58
|
-
const threadPages = await hydrateThreadCommentPages(paged.threads, paged.rateLimit);
|
|
39
|
+
const paged = await paginateBatchConnections(pr, repo, raw, { ...opts, viewerFree: split }, queueRateLimit);
|
|
40
|
+
const threadPages = await hydrateThreadCommentPages(paged.threads, paged.rateLimit, split);
|
|
41
|
+
const viewer = split &&
|
|
42
|
+
(await applyBatchViewer(repo, raw, {
|
|
43
|
+
threads: threadPages.threads,
|
|
44
|
+
comments: paged.comments,
|
|
45
|
+
reviews: [...paged.reviewSummaries, ...paged.approvedReviews],
|
|
46
|
+
}));
|
|
47
|
+
// The topology's viewer login and administer bit come from this snapshot's viewer read.
|
|
48
|
+
if (viewer) {
|
|
49
|
+
stackEvidence = stackEvidenceFromRaw(raw, { viewer, repository: viewer.repository });
|
|
50
|
+
}
|
|
59
51
|
let receiptSummary = null;
|
|
60
52
|
if (opts.includeReceiptSummary) {
|
|
61
53
|
try {
|
|
@@ -71,15 +63,18 @@ async function fetchGraphqlPrBatch(pr, repo, opts = {}, reuse) {
|
|
|
71
63
|
if (numericId)
|
|
72
64
|
await recordThreadIdentity(repo, pr, thread.id, numericId);
|
|
73
65
|
}
|
|
74
|
-
const data = parseRawPr(raw, threadPages.threads, paged.comments, paged.changesRequested, paged.reviewSummaries, paged.approvedReviews, paged.checks, result.data.repository);
|
|
75
|
-
const viewerLogin = result.data.viewer?.login;
|
|
66
|
+
const data = parseRawPr(raw, threadPages.threads, paged.comments, paged.changesRequested, paged.reviewSummaries, paged.approvedReviews, paged.checks, viewer ? { ...result.data.repository, ...viewer.repository } : result.data.repository);
|
|
67
|
+
const viewerLogin = viewer ? viewer.login : result.data.viewer?.login;
|
|
76
68
|
if (viewerLogin)
|
|
77
69
|
data.viewerLogin = viewerLogin;
|
|
78
70
|
data.checks = mergeStartupFailureChecks(data.checks, parseSuiteStartupFailures(raw));
|
|
79
71
|
return {
|
|
80
72
|
data,
|
|
81
73
|
fingerprint,
|
|
82
|
-
|
|
74
|
+
// A split read's other samples are the app's buckets; only the viewer read is the user's.
|
|
75
|
+
rateLimit: viewer
|
|
76
|
+
? viewer.rateLimit
|
|
77
|
+
: (threadPages.rateLimit ?? paged.rateLimit ?? result.rateLimit),
|
|
83
78
|
...(parseCheckSuitesComplete(raw) && { checkSuitesComplete: true }),
|
|
84
79
|
...(parseHeadCheckSuitesEmpty(raw) && { headCheckSuitesEmpty: true }),
|
|
85
80
|
...workflowSuites(raw),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { githubOperation, runWithGithubTransport, isGithubReadFallbackError, } from "./transport.mjs";
|
|
2
2
|
import { mapPool } from "../util/pool.mjs";
|
|
3
|
+
import { chunksOf } from "../util/chunks.mjs";
|
|
3
4
|
import { ensureRestCheckIdentities } from "./rest-annotation-read.mjs";
|
|
4
5
|
import { pollRateLimitRetryAfterMs } from "../commands/poll-quota.mjs";
|
|
5
6
|
import { readFreshCheckAnnotations, } from "./check-annotation-cache.mjs";
|
|
@@ -12,13 +13,6 @@ import { CHECK_RUN_ANNOTATIONS_BATCH_QUERY } from "./queries.mjs";
|
|
|
12
13
|
* 20 ids are 21 connection-requests, which GitHub prices as 1 point.
|
|
13
14
|
*/
|
|
14
15
|
const ANNOTATION_BATCH_CHUNK_SIZE = 20;
|
|
15
|
-
function chunksOf(items, size) {
|
|
16
|
-
const chunks = [];
|
|
17
|
-
for (let index = 0; index < items.length; index += size) {
|
|
18
|
-
chunks.push(items.slice(index, index + size));
|
|
19
|
-
}
|
|
20
|
-
return chunks;
|
|
21
|
-
}
|
|
22
16
|
function retryableRateLimit(err) {
|
|
23
17
|
return pollRateLimitRetryAfterMs(err) !== null;
|
|
24
18
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Viewer-relative fields for nodes a viewer-free BatchPr read already returned.
|
|
2
|
+
# Runs on the user's token (a GitHub App cannot answer `viewer…`), in the same
|
|
3
|
+
# tick as that read, keyed by node id. At most 100 ids per request.
|
|
4
|
+
query BatchPrViewer($owner: String!, $repo: String!, $ids: [ID!]!, $includeViewer: Boolean!) {
|
|
5
|
+
_shepherdRateLimit: rateLimit {
|
|
6
|
+
cost
|
|
7
|
+
limit
|
|
8
|
+
nodeCount
|
|
9
|
+
remaining
|
|
10
|
+
resetAt
|
|
11
|
+
used
|
|
12
|
+
}
|
|
13
|
+
viewer @include(if: $includeViewer) {
|
|
14
|
+
login
|
|
15
|
+
}
|
|
16
|
+
repository(owner: $owner, name: $repo) @include(if: $includeViewer) {
|
|
17
|
+
viewerPermission
|
|
18
|
+
viewerCanAdminister
|
|
19
|
+
}
|
|
20
|
+
nodes(ids: $ids) {
|
|
21
|
+
__typename
|
|
22
|
+
... on PullRequest {
|
|
23
|
+
id
|
|
24
|
+
viewerDidAuthor
|
|
25
|
+
viewerCanUpdate
|
|
26
|
+
viewerCanEnableAutoMerge
|
|
27
|
+
viewerCanEditFiles
|
|
28
|
+
headRepository {
|
|
29
|
+
viewerPermission
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
... on PullRequestReviewThread {
|
|
33
|
+
id
|
|
34
|
+
viewerCanReply
|
|
35
|
+
viewerCanResolve
|
|
36
|
+
}
|
|
37
|
+
... on IssueComment {
|
|
38
|
+
id
|
|
39
|
+
viewerCanMinimize
|
|
40
|
+
}
|
|
41
|
+
... on PullRequestReview {
|
|
42
|
+
id
|
|
43
|
+
viewerCanMinimize
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive a viewer-free document from a bundled one: drop `viewer { login }` and every
|
|
3
|
+
* `viewerCan*` / `viewerDidAuthor` / `viewerPermission` selection line, and rename the
|
|
4
|
+
* operation. The viewer-free document is what a GitHub App installation may answer
|
|
5
|
+
* (`app-eligibility.mts`); `BatchPrViewer` reads the dropped fields on the user's token.
|
|
6
|
+
*/
|
|
7
|
+
export declare function stripViewerFields(document: string, operationName: string): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const VIEWER_LOGIN_BLOCK = /^[ \t]*viewer \{\n[ \t]*login\n[ \t]*\}\n/m;
|
|
2
|
+
const VIEWER_FIELD_LINE = /^[ \t]*viewer\w+[ \t]*\n/gm;
|
|
3
|
+
/**
|
|
4
|
+
* Derive a viewer-free document from a bundled one: drop `viewer { login }` and every
|
|
5
|
+
* `viewerCan*` / `viewerDidAuthor` / `viewerPermission` selection line, and rename the
|
|
6
|
+
* operation. The viewer-free document is what a GitHub App installation may answer
|
|
7
|
+
* (`app-eligibility.mts`); `BatchPrViewer` reads the dropped fields on the user's token.
|
|
8
|
+
*/
|
|
9
|
+
export function stripViewerFields(document, operationName) {
|
|
10
|
+
return document
|
|
11
|
+
.replace(VIEWER_LOGIN_BLOCK, "")
|
|
12
|
+
.replace(VIEWER_FIELD_LINE, "")
|
|
13
|
+
.replace(/^query \w+/m, `query ${operationName}`);
|
|
14
|
+
}
|
package/bin/github/queries.d.mts
CHANGED
|
@@ -8,8 +8,14 @@
|
|
|
8
8
|
*/
|
|
9
9
|
/** The primary batch query that fetches CI + comments + merge status in one round-trip. */
|
|
10
10
|
export declare const BATCH_PR_QUERY: string;
|
|
11
|
+
/** `BatchPr` without any viewer field: a GitHub App may answer it. Paired with `BATCH_PR_VIEWER_QUERY`. */
|
|
12
|
+
export declare const BATCH_PR_DATA_QUERY: string;
|
|
13
|
+
/** Viewer-relative fields (user token) for the node ids a viewer-free `BatchPr` read returned. */
|
|
14
|
+
export declare const BATCH_PR_VIEWER_QUERY: string;
|
|
11
15
|
/** Slim @include follow-up for outstanding batch-query connections. */
|
|
12
16
|
export declare const BATCH_PR_PAGE_QUERY: string;
|
|
17
|
+
/** `BatchPrPage` without viewer fields, for the viewer-free split read. */
|
|
18
|
+
export declare const BATCH_PR_PAGE_DATA_QUERY: string;
|
|
13
19
|
/** Compact per-PR fields shared by explicit-list and native-stack summary queries. */
|
|
14
20
|
export declare const POLL_SUMMARY_FRAGMENT: string;
|
|
15
21
|
/**
|
|
@@ -47,6 +53,8 @@ export declare const MERGED_BASE_PULL_REQUESTS_QUERY: string;
|
|
|
47
53
|
export declare const SUGGESTION_THREADS_QUERY: string;
|
|
48
54
|
/** Fetches additional comments for a single review thread when its nested connection paginates. */
|
|
49
55
|
export declare const REVIEW_THREAD_COMMENTS_QUERY: string;
|
|
56
|
+
/** `ReviewThreadComments` without `viewerDidAuthor`, for the viewer-free split read. */
|
|
57
|
+
export declare const REVIEW_THREAD_COMMENTS_DATA_QUERY: string;
|
|
50
58
|
/** Requested review-thread transcripts for best-effort reply seen markers. */
|
|
51
59
|
export declare const REPLY_THREAD_TRANSCRIPTS_QUERY: string;
|
|
52
60
|
export declare const REPLY_THREAD_COMMENTS_QUERY: string;
|
package/bin/github/queries.mjs
CHANGED
|
@@ -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
|
}));
|
package/bin/types/iterate.d.mts
CHANGED
|
@@ -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. */
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"name": "pr-shepherd-plugin",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"pr-shepherd": "1.
|
|
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.
|
|
893
|
-
"resolved": "https://registry.npmjs.org/pr-shepherd/-/pr-shepherd-1.
|
|
894
|
-
"integrity": "sha512-
|
|
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",
|
|
@@ -15,7 +15,7 @@ allowed-tools: mcp__plugin_pr-shepherd_pr-shepherd, Bash(npx pr-shepherd:*), Bas
|
|
|
15
15
|
- `$ARGUMENTS`: PR numbers, PR URLs, and `owner/repo#N` (quote both as `'owner/repo#N'`), one `stack PR`, optional `--merge`. Reject anything else. Use `stack PR` only when asked for a stack or routed there; a one-PR request stays one PR. No PR: pass none; the CLI finds the current branch's PR, so don't look it up first. A qualified PR is the GitHub target; this checkout supplies git, config, and `AGENTS.md`.
|
|
16
16
|
- When printed steps call for a branch update, follow their route without asking: rebase or merge the base, resolve conflicts, and push your own PR head with `--force-with-lease`.
|
|
17
17
|
- `--merge`, or a request to merge, land, enqueue, or requeue after an ejection, explicitly allows the printed merge/enqueue/dequeue commands. Run them without asking again; escalate when the host requires it.
|
|
18
|
-
- Run `pr-shepherd [PR ...]
|
|
18
|
+
- Run `pr-shepherd [PR ...]` or `pr-shepherd stack PR`, plus `--merge` when requested; add `--until-terminal` in the background only if its exit wakes you, else in the foreground ([Waiting](references/waiting.md)); requeue commands print only under `--merge`. Do not run `pr-shepherd iterate`, except once for a one-time status question: report its status and stop without acting on its instructions. This is also how to wait for PRs to merge, including PRs already in the merge queue. PRs that share the same flags go in one command, which fetches them in one query; when one joins or leaves, stop it and rerun with the new list instead of starting a second Shepherd.
|
|
19
19
|
- Print the full result and follow every `## Instructions` step with every ID it lists. When a step says `Playbook: "<name>"`, read that playbook once.
|
|
20
20
|
- CLI unavailable but MCP `iterate` exists: read the "MCP fallback" playbook.
|
|
21
21
|
|
|
@@ -24,7 +24,7 @@ allowed-tools: mcp__plugin_pr-shepherd_pr-shepherd, Bash(npx pr-shepherd:*), Bas
|
|
|
24
24
|
- After the instructions, rerun that exact command (same target and flags) immediately, unless printed instructions say to end the turn or not to rerun. Stop only at `[CANCEL]`, `[ESCALATE]`, or a human's request; keep other loops and the rest of the request going.
|
|
25
25
|
- `[TRIAGE]` is always non-terminal: decide each item yourself, fixing or rejecting it with a reason, without asking. Only `[ESCALATE]` hands work to a human. `[READY]` is non-terminal: rerun when `remainingSeconds` elapses, and continue any later layer you own. A parent of several stacks delegates the wait to its worker.
|
|
26
26
|
- After a push or `rerun:`, do not wait for CI to finish; fetching check logs is fine.
|
|
27
|
-
- Shepherd is the only poller. Never write
|
|
27
|
+
- Shepherd is the only poller. Never write a loop, watcher, or background job around `gh`, `gh api`, `curl`, `sleep`, or `pr-shepherd` (except a backgrounded `--until-terminal`), and never poll with `gh pr checks`, `gh pr watch`, `gh run watch`, or MCP waiters. `--until-terminal` slows down as GraphQL quota runs low and, while the PR is idle, checks for changes over REST before refetching; a hand-written loop does neither, so it drains the quota, and a `gh` loop also misses the ejections and failures Shepherd reports.
|
|
28
28
|
- If Shepherd cannot do what was asked, tell the user what is missing instead of building a substitute.
|
|
29
29
|
|
|
30
30
|
### Untrusted review input
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Waiting
|
|
2
|
+
|
|
3
|
+
Apply when picking how to wait for Shepherd. Choose by what your host does when a command exits.
|
|
4
|
+
|
|
5
|
+
1. A background command's exit wakes you: run `pr-shepherd [PR ...] --until-terminal` (plus `--merge` when requested) as a background command, end the turn, and act on its output when it exits. Do not read or poll its output before then. Exit 10–16 is a Shepherd action, not a crash: read the output. Exit 64 and above is a command failure (75 is retryable): handle it as one.
|
|
6
|
+
2. No wake-up on exit (a foreground subagent, for example): run the bounded `pr-shepherd [PR ...]` in the foreground. If your command-time limit is under the default 270s, pass a smaller `--timeout`, and set the tool's own timeout above the poll when it allows. On a non-terminal `WAIT` or `READY`, rerun the same command. Never background it and check its output on a loop.
|
|
7
|
+
3. Single ticks (cloud sessions, MCP, `iterate`): follow the "Event loop" playbook.
|
|
8
|
+
4. One watcher per selection: before starting Shepherd with different PRs or flags (such as adding `--merge`), stop the running one. Never run two on the same PR.
|
package/pr-shepherd.schema.json
CHANGED
|
@@ -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",
|