pr-shepherd 2.3.0 → 2.4.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.
- package/.claude-plugin/plugin.json +1 -1
- package/bin/api.d.mts +10 -0
- package/bin/api.mjs +21 -1
- package/bin/cli/iterate-formatter.mjs +3 -1
- package/bin/commands/iterate/base.mjs +1 -0
- package/bin/commands/iterate/helpers.mjs +1 -0
- package/bin/commands/iterate/index.mjs +11 -3
- package/bin/commands/poll-summary-instructions.d.mts +1 -1
- package/bin/commands/poll-summary-instructions.mjs +2 -2
- package/bin/commands/poll-summary.mjs +1 -1
- package/bin/commands/ready-delay.mjs +24 -1
- package/bin/commands/stack-merge-escalations.d.mts +6 -0
- package/bin/commands/stack-merge-escalations.mjs +17 -0
- package/bin/commands/stack-merge-plan.mjs +10 -6
- package/bin/comments/rest-reply.mjs +2 -1
- package/bin/comments/uncertain-replies.mjs +2 -1
- package/bin/comments/uncertain-reply-guards.mjs +2 -1
- package/bin/execution-context.d.mts +7 -0
- package/bin/execution-context.mjs +13 -1
- package/bin/github/graphql-http.mjs +2 -0
- package/bin/github/graphql-internal-retry.mjs +2 -1
- package/bin/github/read-only-guard.d.mts +4 -0
- package/bin/github/read-only-guard.mjs +25 -0
- package/bin/github/rest-http.mjs +2 -0
- package/bin/github/rest-identities.mjs +16 -2
- package/bin/log/log-file.mjs +1 -1
- package/bin/state/base.mjs +30 -12
- package/bin/state/check-blockers.mjs +2 -1
- package/bin/state/check-follow-up.mjs +2 -1
- package/bin/state/ci-retrigger.mjs +2 -1
- package/bin/state/conflicting-head-seen.mjs +2 -1
- package/bin/state/fix-attempts.mjs +2 -1
- package/bin/state/graphql-quota-claims.mjs +6 -1
- package/bin/state/graphql-quota-warnings.mjs +2 -1
- package/bin/state/guarded-fs.d.mts +16 -0
- package/bin/state/guarded-fs.mjs +49 -0
- package/bin/state/merge-request.mjs +2 -1
- package/bin/state/pr-fingerprint.mjs +2 -1
- package/bin/state/queue-removal-ack.mjs +2 -1
- package/bin/state/ready-receipts.mjs +2 -1
- package/bin/state/rest-cache.mjs +2 -1
- package/bin/state/rest-snapshot-report.mjs +2 -1
- package/bin/state/seen-comments.mjs +2 -1
- package/bin/state/signature-marker.mjs +2 -1
- package/bin/state/stack-merge-approval.mjs +2 -1
- package/bin/state/stall-repair.mjs +2 -1
- package/bin/state/stall-state-store.mjs +2 -1
- package/bin/types/iterate.d.mts +2 -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/bin/api.d.mts
CHANGED
|
@@ -38,6 +38,11 @@ export type MultiIterateInput = IterateOptions & {
|
|
|
38
38
|
pr?: never;
|
|
39
39
|
};
|
|
40
40
|
export type IterateInput = SingleIterateInput | MultiIterateInput;
|
|
41
|
+
/**
|
|
42
|
+
* The per-tick options of a single-PR `iterate` that a read-only `status` check honors. There is
|
|
43
|
+
* no `prs`: `status` answers for exactly one PR.
|
|
44
|
+
*/
|
|
45
|
+
export type StatusInput = Pick<SingleIterateInput, "pr" | "merge" | "readyDelaySeconds" | "stallTimeoutSeconds" | "transport" | "instructions">;
|
|
41
46
|
/**
|
|
42
47
|
* One aggregate tick over one native stack. `refs` is one stack number (or `owner/repo#N` naming
|
|
43
48
|
* one), which the caller owns entirely; or one or more PRs of one stack, which select it and own only
|
|
@@ -142,6 +147,11 @@ export interface PrShepherd {
|
|
|
142
147
|
iterate(input?: SingleIterateInput): Promise<IterateResult>;
|
|
143
148
|
iterate(input: MultiIterateInput): Promise<PollSummaryResult>;
|
|
144
149
|
iterate(input: IterateInput): Promise<IterateResult | PollSummaryResult>;
|
|
150
|
+
/**
|
|
151
|
+
* One single-PR `iterate` tick through the same code path as `iterate`, with no GitHub mutation
|
|
152
|
+
* and no local state write. Library only: there is no CLI command or MCP tool for it.
|
|
153
|
+
*/
|
|
154
|
+
status(input?: StatusInput): Promise<IterateResult>;
|
|
145
155
|
stack(input: StackInput): Promise<PollSummaryResult>;
|
|
146
156
|
apply(input: ApplyInput): Promise<ApplyResult>;
|
|
147
157
|
suggest(input: SuggestInput): Promise<SuggestResult>;
|
package/bin/api.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import { validateJournalItem } from "./commands/journal/transform.mjs";
|
|
|
12
12
|
import { runMarkFilesAsViewed, } from "./commands/mark-files-as-viewed.mjs";
|
|
13
13
|
import { runResolveMutate } from "./commands/resolve-mutate.mjs";
|
|
14
14
|
import { applyQueueRemovalAck, } from "./commands/apply-queue-removal.mjs";
|
|
15
|
-
import { runWithExecutionCwd } from "./execution-context.mjs";
|
|
15
|
+
import { runReadOnly, runWithExecutionCwd } from "./execution-context.mjs";
|
|
16
16
|
import { loadConfig } from "./config/load.mjs";
|
|
17
17
|
import { parsePrReference, normalizeRepositoryIdentity, resolveParsedPrTarget, } from "./pr-reference.mjs";
|
|
18
18
|
import { runWithAuthScope } from "./github/auth-target.mjs";
|
|
@@ -69,8 +69,28 @@ export function createPrShepherd(options = {}) {
|
|
|
69
69
|
return runIterateTick({ ...iterateOptions, ...target, format: "json" });
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
|
+
function status(input = {}) {
|
|
73
|
+
// The read-only scope wraps the whole client run, so transport fallback probes and quota
|
|
74
|
+
// bookkeeping inside the runner are covered too.
|
|
75
|
+
return runReadOnly(() => runInClient(input, async () => {
|
|
76
|
+
if (input === null || typeof input !== "object" || "prs" in input) {
|
|
77
|
+
throw new PrShepherdValidationError("status takes one PR: pass pr, not prs");
|
|
78
|
+
}
|
|
79
|
+
const { pr, merge, readyDelaySeconds, stallTimeoutSeconds, instructions } = input;
|
|
80
|
+
const target = resolvePrReference(pr);
|
|
81
|
+
return runIterateTick({
|
|
82
|
+
...(merge !== undefined && { merge }),
|
|
83
|
+
...(readyDelaySeconds !== undefined && { readyDelaySeconds }),
|
|
84
|
+
...(stallTimeoutSeconds !== undefined && { stallTimeoutSeconds }),
|
|
85
|
+
...(instructions !== undefined && { instructions }),
|
|
86
|
+
...target,
|
|
87
|
+
format: "json",
|
|
88
|
+
});
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
72
91
|
return Object.freeze({
|
|
73
92
|
iterate,
|
|
93
|
+
status,
|
|
74
94
|
stack(input) {
|
|
75
95
|
return runInClient(input ?? {}, async () => {
|
|
76
96
|
if (!input || !Array.isArray(input.refs) || input.refs.length === 0) {
|
|
@@ -55,7 +55,9 @@ export function formatIterateResult(result, opts) {
|
|
|
55
55
|
? ` · **merge** \`${result.mergeStateStatus}\``
|
|
56
56
|
: "";
|
|
57
57
|
const stateSeg = verbose || result.state !== "OPEN" ? ` · **state** \`${result.state}\`` : "";
|
|
58
|
-
|
|
58
|
+
// Verbose only, like baseBranch: the raw result and verbose JSON always carry `headSha`.
|
|
59
|
+
const headSeg = verbose && result.headSha ? ` · **head** \`${result.headSha}\`` : "";
|
|
60
|
+
const baseLine = `**status** \`${result.status}\`${mergeSeg}${reviewDecisionSeg}${stateSeg}${repoSeg}${headSeg}${baseBranchSeg}`;
|
|
59
61
|
const branchSeg = branchStateSegment(result);
|
|
60
62
|
let summaryLine;
|
|
61
63
|
if (verbose) {
|
|
@@ -5,6 +5,7 @@ export function buildIterateBase(report, readyState) {
|
|
|
5
5
|
return {
|
|
6
6
|
pr: report.pr,
|
|
7
7
|
repo: report.repo,
|
|
8
|
+
...(report.headSha && { headSha: report.headSha }),
|
|
8
9
|
...(report.transport && { transport: report.transport }),
|
|
9
10
|
...(report.transportReason && { transportReason: report.transportReason }),
|
|
10
11
|
...(report.transportUnavailable?.length && {
|
|
@@ -28,6 +28,7 @@ export function buildTerminalCancelResult(report) {
|
|
|
28
28
|
return {
|
|
29
29
|
pr: report.pr,
|
|
30
30
|
repo: report.repo,
|
|
31
|
+
...(report.headSha && { headSha: report.headSha }),
|
|
31
32
|
...(report.transport && { transport: report.transport }),
|
|
32
33
|
...(report.transportReason && { transportReason: report.transportReason }),
|
|
33
34
|
...(report.transportUnavailable?.length && {
|
|
@@ -3,6 +3,7 @@ import { runCheck } from "../check.mjs";
|
|
|
3
3
|
import { clearReadyDelay, updateReadyDelay } from "../ready-delay.mjs";
|
|
4
4
|
import { getCurrentPrNumber } from "../../github/client.mjs";
|
|
5
5
|
import { loadConfig } from "../../config/load.mjs";
|
|
6
|
+
import { isReadOnly } from "../../execution-context.mjs";
|
|
6
7
|
import { EXIT, ShepherdError } from "../../exit-codes.mjs";
|
|
7
8
|
import { buildWaitLog, buildTerminalCancelResult, blockedCancelNote } from "./helpers.mjs";
|
|
8
9
|
import { classifyReviewSummaries } from "./classify.mjs";
|
|
@@ -71,12 +72,15 @@ async function runIterateCore(opts, tick) {
|
|
|
71
72
|
throw new ShepherdError("No open PR found for current branch. Pass a PR number explicitly.", EXIT.UNAVAILABLE);
|
|
72
73
|
}
|
|
73
74
|
const checkContext = createCheckExecutionContext(readyDelaySeconds);
|
|
75
|
+
// A read-only status check sends no GitHub mutation: nothing is auto-resolved or auto-minimized,
|
|
76
|
+
// so those IDs stay in the agent-facing set exactly as when a mutation is not confirmed.
|
|
77
|
+
const readOnly = isReadOnly();
|
|
74
78
|
const report = await runCheck({
|
|
75
79
|
...opts,
|
|
76
80
|
prNumber,
|
|
77
81
|
// Outdated Shepherd-visible threads are always resolved by iterate.
|
|
78
82
|
autoResolve: true,
|
|
79
|
-
autoMinimizeSuppressed: config.actions["auto-minimize-suppressed"],
|
|
83
|
+
autoMinimizeSuppressed: !readOnly && config.actions["auto-minimize-suppressed"],
|
|
80
84
|
reviewOutputMaxChars: config.iterate["review-output-max-chars"],
|
|
81
85
|
}, checkContext);
|
|
82
86
|
tick.report = report;
|
|
@@ -122,7 +126,10 @@ async function runIterateCore(opts, tick) {
|
|
|
122
126
|
// any ID it did not confirm minimized falls back into the agent-facing set so
|
|
123
127
|
// the apply command remains a working fallback instead of silently dropping it.
|
|
124
128
|
let reviewSummaryIds = minimizeIds;
|
|
125
|
-
if (selfMinimizeIds.length > 0) {
|
|
129
|
+
if (selfMinimizeIds.length > 0 && readOnly) {
|
|
130
|
+
reviewSummaryIds = [...reviewSummaryIds, ...selfMinimizeIds];
|
|
131
|
+
}
|
|
132
|
+
else if (selfMinimizeIds.length > 0) {
|
|
126
133
|
checkContext.invalidateReceiptSummary();
|
|
127
134
|
const { minimized } = await autoMinimizeComments(selfMinimizeIds);
|
|
128
135
|
const minimizedIds = new Set(minimized);
|
|
@@ -301,7 +308,8 @@ async function runIterateCore(opts, tick) {
|
|
|
301
308
|
escalate: { ...escalation, humanMessage: buildEscalateHumanMessage(escalation, report.pr) },
|
|
302
309
|
};
|
|
303
310
|
}
|
|
304
|
-
|
|
311
|
+
// Marking a draft ready is a GitHub mutation, so a read-only check treats it as disabled.
|
|
312
|
+
const autoMarkReady = !opts.noAutoMarkReady && !readOnly && config["mark-ready"].auto;
|
|
305
313
|
if (canMarkReady && !autoMarkReady) {
|
|
306
314
|
await clearReadyDelay(report.pr, repoOwner, repoName);
|
|
307
315
|
await clearStallState(stallKey);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PollSummaryItem, PollSummaryResult, StackMergeScope } from "../types.mts";
|
|
2
2
|
import { type ApproveCommands } from "./stack-merge-plan.mts";
|
|
3
3
|
/** Keep aggregate JSON, Markdown, and MCP instructions on one projection. */
|
|
4
|
-
export declare function withPollSummaryInstructions(result: PollSummaryResult, mergeRequested: boolean, rerunCommand?: string, scope?: StackMergeScope): PollSummaryResult;
|
|
4
|
+
export declare function withPollSummaryInstructions(result: PollSummaryResult, mergeRequested: boolean, rerunCommand?: string, scope?: StackMergeScope, approve?: ApproveCommands): PollSummaryResult;
|
|
5
5
|
/** The projected summary, plus the idle layers when the stack plan can only wait on them. */
|
|
6
6
|
export declare function planPollSummary(result: PollSummaryResult, mergeRequested: boolean, rerunCommand?: string, scope?: StackMergeScope | undefined, approve?: ApproveCommands): {
|
|
7
7
|
result: PollSummaryResult;
|
|
@@ -8,8 +8,8 @@ import { aboveThroughTarget } from "./stack-merge-scope.mjs";
|
|
|
8
8
|
import { ownershipBoundaryStep } from "./stack-ownership.mjs";
|
|
9
9
|
import { appendStackRerunInstruction, onlyDraftReadinessVerification, splitStackWork, stackRerunTarget, } from "./stack-work.mjs";
|
|
10
10
|
/** Keep aggregate JSON, Markdown, and MCP instructions on one projection. */
|
|
11
|
-
export function withPollSummaryInstructions(result, mergeRequested, rerunCommand, scope) {
|
|
12
|
-
return planPollSummary(result, mergeRequested, rerunCommand, scope).result;
|
|
11
|
+
export function withPollSummaryInstructions(result, mergeRequested, rerunCommand, scope, approve) {
|
|
12
|
+
return planPollSummary(result, mergeRequested, rerunCommand, scope, approve).result;
|
|
13
13
|
}
|
|
14
14
|
/** The projected summary, plus the idle layers when the stack plan can only wait on them. */
|
|
15
15
|
export function planPollSummary(result, mergeRequested, rerunCommand, scope = mergeRequested ? { kind: "all" } : undefined, approve) {
|
|
@@ -259,7 +259,7 @@ function attachUsage(result, opts) {
|
|
|
259
259
|
return withoutImpliedOwnership(enriched);
|
|
260
260
|
}
|
|
261
261
|
const scope = requestedMergeScope(opts);
|
|
262
|
-
return withoutImpliedOwnership(withPollSummaryInstructions(enriched, scope !== undefined, aggregateRerunCommand(enriched.repo, enriched.selection, opts), scope));
|
|
262
|
+
return withoutImpliedOwnership(withPollSummaryInstructions(enriched, scope !== undefined, aggregateRerunCommand(enriched.repo, enriched.selection, opts), scope, (extra) => stackApprovalCommands(enriched.repo, enriched.selection, opts, extra)));
|
|
263
263
|
}
|
|
264
264
|
/** Whole-stack ownership is the default, so rows say `owned` only when the caller listed PRs. */
|
|
265
265
|
function withoutImpliedOwnership(result) {
|
|
@@ -7,9 +7,11 @@
|
|
|
7
7
|
* result, or a different head, resets the timer. An elapsed marker stays until
|
|
8
8
|
* the caller consumes it with `clearReadyDelay`.
|
|
9
9
|
*/
|
|
10
|
-
import { readFile
|
|
10
|
+
import { readFile } from "node:fs/promises";
|
|
11
|
+
import { writeFile, mkdir, unlink } from "../state/guarded-fs.mjs";
|
|
11
12
|
import { dirname } from "node:path";
|
|
12
13
|
import { resolvePrStatePath } from "../state/base.mjs";
|
|
14
|
+
import { isReadOnly } from "../execution-context.mjs";
|
|
13
15
|
/**
|
|
14
16
|
* Update the ready-delay state machine and return the current decision.
|
|
15
17
|
*
|
|
@@ -22,6 +24,8 @@ import { resolvePrStatePath } from "../state/base.mjs";
|
|
|
22
24
|
*/
|
|
23
25
|
export async function updateReadyDelay(prNumber, isReady, readyDelaySeconds, owner, repo, options) {
|
|
24
26
|
const markerPath = readySincePath(prNumber, owner, repo, options.summary);
|
|
27
|
+
if (isReadOnly())
|
|
28
|
+
return readOnlyReadyDelay(markerPath, isReady, readyDelaySeconds, options);
|
|
25
29
|
if (!isReady) {
|
|
26
30
|
// Reset the timer.
|
|
27
31
|
await safeUnlink(markerPath);
|
|
@@ -50,6 +54,25 @@ export async function updateReadyDelay(prNumber, isReady, readyDelaySeconds, own
|
|
|
50
54
|
}
|
|
51
55
|
return { isReady: true, shouldCancel: false, remainingSeconds: remaining };
|
|
52
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* What the existing marker implies, without creating, refreshing or deleting it: no usable marker
|
|
59
|
+
* means the countdown has not started, so the full delay remains; a delay of 0 has elapsed at once.
|
|
60
|
+
*/
|
|
61
|
+
async function readOnlyReadyDelay(markerPath, isReady, readyDelaySeconds, options) {
|
|
62
|
+
if (!isReady)
|
|
63
|
+
return { isReady: false, shouldCancel: false, remainingSeconds: readyDelaySeconds };
|
|
64
|
+
if (options.alreadyElapsed || readyDelaySeconds <= 0) {
|
|
65
|
+
return { isReady: true, shouldCancel: true, remainingSeconds: 0 };
|
|
66
|
+
}
|
|
67
|
+
const now = Math.floor(Date.now() / 1000);
|
|
68
|
+
const readySince = await readReadySince(markerPath, options.headSha);
|
|
69
|
+
const remaining = readySince === null || readySince > now
|
|
70
|
+
? readyDelaySeconds
|
|
71
|
+
: readyDelaySeconds - (now - readySince);
|
|
72
|
+
return remaining <= 0
|
|
73
|
+
? { isReady: true, shouldCancel: true, remainingSeconds: 0 }
|
|
74
|
+
: { isReady: true, shouldCancel: false, remainingSeconds: remaining };
|
|
75
|
+
}
|
|
53
76
|
/** Delete the ready-delay marker once an elapsed delay has been consumed. */
|
|
54
77
|
export async function clearReadyDelay(prNumber, owner, repo) {
|
|
55
78
|
await safeUnlink(readySincePath(prNumber, owner, repo));
|
|
@@ -10,6 +10,12 @@ export type ApproveCommands = (extra: number[]) => {
|
|
|
10
10
|
* with its author and title, says what merging would do, and prints the commands that approve.
|
|
11
11
|
*/
|
|
12
12
|
export declare function unlistedEscalation(target: PollSummaryItem, unlisted: PollSummaryItem[], rerunCommand: string | undefined, approve: ApproveCommands | undefined): StackPlan;
|
|
13
|
+
/**
|
|
14
|
+
* `--merge` with listed PRs leaves unlisted layers above the merge open. The
|
|
15
|
+
* caller may have listed only the bottom PR of a stack it was asked to merge whole, so the step
|
|
16
|
+
* names those layers and prints the command that lands them in the same merge.
|
|
17
|
+
*/
|
|
18
|
+
export declare function unlistedAboveStep(above: PollSummaryItem[], rerunCommand: string | undefined, approve: ApproveCommands | undefined): string | undefined;
|
|
13
19
|
export declare const list: (items: PollSummaryItem[]) => string;
|
|
14
20
|
/** Layers that joined the stack after the merge was requested: the request never covered them. */
|
|
15
21
|
export declare function addedLayersEscalation(result: PollSummaryResult, open: PollSummaryItem[], scope: StackMergeScope, rerunCommand?: string): StackPlan | undefined;
|
|
@@ -22,6 +22,23 @@ export function unlistedEscalation(target, unlisted, rerunCommand, approve) {
|
|
|
22
22
|
: `They either approve it, and you ${listAll}, or wait for ${owner}.`;
|
|
23
23
|
return escalation(`\`unowned-stack-layers\`: merging PR #${target.pr} also merges ${describeLayers(unlisted)}, which you did not list as yours. Nothing was merged, and never merge only #${target.pr} while leaving ${them} open. If the user's request already covers ${them} (they asked for the whole stack, or for every layer up to #${target.pr}), ${listAll} now. Otherwise stop and tell the user that merging #${target.pr} also merges ${list(unlisted)}. ${approval}`);
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* `--merge` with listed PRs leaves unlisted layers above the merge open. The
|
|
27
|
+
* caller may have listed only the bottom PR of a stack it was asked to merge whole, so the step
|
|
28
|
+
* names those layers and prints the command that lands them in the same merge.
|
|
29
|
+
*/
|
|
30
|
+
export function unlistedAboveStep(above, rerunCommand, approve) {
|
|
31
|
+
const unlisted = above.filter((item) => !item.owned);
|
|
32
|
+
if (unlisted.length === 0)
|
|
33
|
+
return undefined;
|
|
34
|
+
const one = unlisted.length === 1;
|
|
35
|
+
const names = list(unlisted);
|
|
36
|
+
const commands = approve?.(unlisted.map((item) => item.pr));
|
|
37
|
+
const instead = commands
|
|
38
|
+
? `run \`${commands.listed}\` instead (or \`${commands.whole}\`; the stack number owns every layer)`
|
|
39
|
+
: `rerun ${stackRerunTarget(rerunCommand)} with ${one ? "it" : "them"} listed after \`stack\` instead`;
|
|
40
|
+
return `${names} ${one ? "sits" : "sit"} above this merge and ${one ? "is" : "are"} not listed after \`stack\`, so the merge below leaves ${one ? "it" : "them"} open and GitHub retargets ${one ? "it" : "them"} onto the trunk, which needs another rebase and CI run. "Not listed" is about this command line, not authorship. If the user asked to merge the whole stack or ${names} too, do not run the merge below: ${instead}, which lands every layer in one command. Otherwise continue with the merge.`;
|
|
41
|
+
}
|
|
25
42
|
export const list = (items) => items.map((i) => `#${i.pr}`).join(", ");
|
|
26
43
|
/** Layers that joined the stack after the merge was requested: the request never covered them. */
|
|
27
44
|
export function addedLayersEscalation(result, open, scope, rerunCommand) {
|
|
@@ -4,7 +4,7 @@ import { appendAutonomousInstructions, idleWaitPlan, appendHumanHandoffInstructi
|
|
|
4
4
|
import { isStackLayerReady, aboveThroughTarget, closedInScope, mergeScopeLayers, openLayers, readyPrefix, stackPosition, } from "./stack-merge-scope.mjs";
|
|
5
5
|
import { stackMergeFlag } from "./stack-merge-flag.mjs";
|
|
6
6
|
import { MERGE_CONFLICT_NOTE, trunkPreCheck } from "./stack-merge-trunk-check.mjs";
|
|
7
|
-
import { addedLayersEscalation, escalation, list, scopeDone, unlistedEscalation, } from "./stack-merge-escalations.mjs";
|
|
7
|
+
import { addedLayersEscalation, escalation, list, scopeDone, unlistedAboveStep, unlistedEscalation, } from "./stack-merge-escalations.mjs";
|
|
8
8
|
import { splitStackWork, stackRerunTarget } from "./stack-work.mjs";
|
|
9
9
|
const NO_PER_LAYER = "One command lands every listed layer. Do not merge the layers one at a time with `gh pr merge`, and do not rebase or push between layers; GitHub retargets the remaining layers itself.";
|
|
10
10
|
/**
|
|
@@ -23,7 +23,7 @@ export function planStackMerge(result, scope, rerunCommand, approve) {
|
|
|
23
23
|
const prefix = readyPrefix(result, true);
|
|
24
24
|
const top = prefix.at(-1);
|
|
25
25
|
if (top)
|
|
26
|
-
return mergePlan(result, top, scope, rerunCommand);
|
|
26
|
+
return mergePlan(result, top, scope, rerunCommand, approve);
|
|
27
27
|
const bottom = open.reduce((low, item) => stackPosition(item) < stackPosition(low) ? item : low);
|
|
28
28
|
if (!bottom.owned && isStackLayerReady(bottom) && open.some((item) => item.owned)) {
|
|
29
29
|
const above = open.filter((item) => item.owned).at(-1);
|
|
@@ -48,11 +48,11 @@ export function planStackMerge(result, scope, rerunCommand, approve) {
|
|
|
48
48
|
if (unowned.length > 0)
|
|
49
49
|
return unlistedEscalation(target, unowned, rerunCommand, approve);
|
|
50
50
|
return readyPrefix(result, false).some((item) => item.pr === target.pr)
|
|
51
|
-
? mergePlan(result, target, scope, rerunCommand)
|
|
51
|
+
? mergePlan(result, target, scope, rerunCommand, approve)
|
|
52
52
|
: undefined;
|
|
53
53
|
}
|
|
54
54
|
/** The one merge for `top`, which lands it and every unmerged layer below it. */
|
|
55
|
-
function mergePlan(result, top, scope, rerunCommand) {
|
|
55
|
+
function mergePlan(result, top, scope, rerunCommand, approve) {
|
|
56
56
|
const stack = top.stack;
|
|
57
57
|
const outside = aboveThroughTarget(result, scope);
|
|
58
58
|
const open = openLayers(result);
|
|
@@ -78,8 +78,12 @@ function mergePlan(result, top, scope, rerunCommand) {
|
|
|
78
78
|
const waiting = idleWaitPlan(lands);
|
|
79
79
|
return { ...waiting, instructions: [`1. ${first.unavailable}`] };
|
|
80
80
|
}
|
|
81
|
-
const
|
|
82
|
-
|
|
81
|
+
const steps = [
|
|
82
|
+
partial && scope.kind === "all" ? unlistedAboveStep(above, rerunCommand, approve) : undefined,
|
|
83
|
+
trunkPreCheck(result, top),
|
|
84
|
+
first.text,
|
|
85
|
+
].filter((step) => step !== undefined);
|
|
86
|
+
const instructions = steps.map((step, index) => `${index + 1}. ${step}`);
|
|
83
87
|
appendAutonomousInstructions(instructions, work.sessions, hasListedOwnership(result));
|
|
84
88
|
const handoffs = findHumanHandoffs(result);
|
|
85
89
|
if (handoffs)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { readFile
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { writeFile, mkdir, unlink } from "../state/guarded-fs.mjs";
|
|
3
4
|
import { dirname } from "node:path";
|
|
4
5
|
import { resolvePrStatePath } from "../state/base.mjs";
|
|
5
6
|
import { rest, restWithRateLimit } from "../github/http.mjs";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { readFile
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { mkdir, writeFile } from "../state/guarded-fs.mjs";
|
|
3
4
|
import { dirname } from "node:path";
|
|
4
5
|
import { resolvePrStatePath } from "../state/base.mjs";
|
|
5
6
|
import { resolveRestThreadRoot } from "../github/rest-identities.mjs";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import {
|
|
2
|
+
import { readFile, readdir } from "node:fs/promises";
|
|
3
|
+
import { mkdir, unlink, writeFile } from "../state/guarded-fs.mjs";
|
|
3
4
|
import { join } from "node:path";
|
|
4
5
|
import { resolvePrStatePath } from "../state/base.mjs";
|
|
5
6
|
import { resolveRestThreadRoot } from "../github/rest-identities.mjs";
|
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
* process state. This keeps independent API/MCP requests safe to run together.
|
|
4
4
|
*/
|
|
5
5
|
export declare function runWithExecutionCwd<T>(cwd: string | undefined, work: () => T): T;
|
|
6
|
+
/**
|
|
7
|
+
* Runs work in a read-only scope: state writes, deletes and directory creation become no-ops,
|
|
8
|
+
* and the HTTP layer refuses GitHub mutations. Composes with `runWithExecutionCwd` in either order.
|
|
9
|
+
*/
|
|
10
|
+
export declare function runReadOnly<T>(work: () => T): T;
|
|
11
|
+
/** True inside `runReadOnly`. */
|
|
12
|
+
export declare function isReadOnly(): boolean;
|
|
6
13
|
/** The caller-scoped working directory, when one was supplied. */
|
|
7
14
|
export declare function getExecutionCwd(): string | undefined;
|
|
8
15
|
/** The caller-scoped working directory, falling back to the CLI process cwd. */
|
|
@@ -7,7 +7,19 @@ const executionContext = new AsyncLocalStorage();
|
|
|
7
7
|
export function runWithExecutionCwd(cwd, work) {
|
|
8
8
|
if (cwd === undefined)
|
|
9
9
|
return work();
|
|
10
|
-
|
|
10
|
+
// Keep any enclosing scope's other fields (read-only) when only the cwd changes.
|
|
11
|
+
return executionContext.run({ ...executionContext.getStore(), cwd }, work);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Runs work in a read-only scope: state writes, deletes and directory creation become no-ops,
|
|
15
|
+
* and the HTTP layer refuses GitHub mutations. Composes with `runWithExecutionCwd` in either order.
|
|
16
|
+
*/
|
|
17
|
+
export function runReadOnly(work) {
|
|
18
|
+
return executionContext.run({ ...executionContext.getStore(), readOnly: true }, work);
|
|
19
|
+
}
|
|
20
|
+
/** True inside `runReadOnly`. */
|
|
21
|
+
export function isReadOnly() {
|
|
22
|
+
return executionContext.getStore()?.readOnly === true;
|
|
11
23
|
}
|
|
12
24
|
/** The caller-scoped working directory, when one was supplied. */
|
|
13
25
|
export function getExecutionCwd() {
|
|
@@ -4,6 +4,7 @@ import { formatRequestEntry, formatResponseEntry } from "../log/session.mjs";
|
|
|
4
4
|
import { GitHubRequestError } from "./errors.mjs";
|
|
5
5
|
import { isGraphQlMutationDocument, withGraphQlInternalRetry } from "./graphql-internal-retry.mjs";
|
|
6
6
|
import { githubFetch } from "./github-fetch.mjs";
|
|
7
|
+
import { assertGraphQlReadable } from "./read-only-guard.mjs";
|
|
7
8
|
import { formatGraphQlErrors, parseGraphQlPayload } from "./graphql-response.mjs";
|
|
8
9
|
import { withoutToleratedErrors } from "./graphql-tolerated-errors.mjs";
|
|
9
10
|
import { CCR_GRAPHQL_REFUSAL_MESSAGE, isCcrGraphqlRefusal } from "./graphql-session-refusal.mjs";
|
|
@@ -20,6 +21,7 @@ function graphqlInner(query, vars, opts) {
|
|
|
20
21
|
return withAppQuotaFallback("graphql", () => graphqlAttempt(query, vars, opts));
|
|
21
22
|
}
|
|
22
23
|
async function graphqlAttempt(query, vars, opts) {
|
|
24
|
+
assertGraphQlReadable(query);
|
|
23
25
|
const url = `${BASE_URL}/graphql`;
|
|
24
26
|
const n = nextEntry();
|
|
25
27
|
appendEntry(formatRequestEntry({
|
|
@@ -5,7 +5,8 @@ const GRAPHQL_INTERNAL_RETRY_DELAYS = [500, 1500];
|
|
|
5
5
|
export function isGraphQlMutationDocument(document) {
|
|
6
6
|
let rest = document;
|
|
7
7
|
for (;;) {
|
|
8
|
-
|
|
8
|
+
// Commas are ignored tokens in GraphQL, like whitespace.
|
|
9
|
+
rest = rest.replace(/^[\s,]+/, "");
|
|
9
10
|
if (rest.startsWith("#")) {
|
|
10
11
|
const nl = rest.indexOf("\n");
|
|
11
12
|
rest = nl === -1 ? "" : rest.slice(nl + 1);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Refuse a GraphQL document whose root operation is a mutation. */
|
|
2
|
+
export declare function assertGraphQlReadable(document: string): void;
|
|
3
|
+
/** Refuse any REST method other than GET or HEAD. */
|
|
4
|
+
export declare function assertRestReadable(method: string, path: string): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isReadOnly } from "../execution-context.mjs";
|
|
2
|
+
import { isGraphQlMutationDocument } from "./graphql-internal-retry.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Raised when a read-only scope (the library `status` method) reaches a GitHub mutation. A normal
|
|
5
|
+
* status tick never gets here: the call sites that mutate are skipped first, so this is only the
|
|
6
|
+
* backstop that keeps a missed site from changing GitHub.
|
|
7
|
+
*/
|
|
8
|
+
class ReadOnlyViolationError extends Error {
|
|
9
|
+
constructor(operation) {
|
|
10
|
+
super(`read-only status check refused a GitHub mutation: ${operation}`);
|
|
11
|
+
this.name = "ReadOnlyViolationError";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** Refuse a GraphQL document whose root operation is a mutation. */
|
|
15
|
+
export function assertGraphQlReadable(document) {
|
|
16
|
+
if (isReadOnly() && isGraphQlMutationDocument(document)) {
|
|
17
|
+
throw new ReadOnlyViolationError("GraphQL mutation");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** Refuse any REST method other than GET or HEAD. */
|
|
21
|
+
export function assertRestReadable(method, path) {
|
|
22
|
+
if (isReadOnly() && method.toUpperCase() !== "GET" && method.toUpperCase() !== "HEAD") {
|
|
23
|
+
throw new ReadOnlyViolationError(`REST ${method.toUpperCase()} ${path}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
package/bin/github/rest-http.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* eslint-disable max-lines */
|
|
2
|
+
import { assertRestReadable } from "./read-only-guard.mjs";
|
|
2
3
|
import { appendEntry, nextEntry } from "../log/log-file.mjs";
|
|
3
4
|
import { formatRequestEntry, formatResponseEntry } from "../log/session.mjs";
|
|
4
5
|
import { loadEtagEntry, storeEtagEntry } from "../state/rest-cache.mjs";
|
|
@@ -37,6 +38,7 @@ export function restWithRateLimit(method, path, body, opts) {
|
|
|
37
38
|
return withAppQuotaFallback("core", () => restAttempt(method, path, body, opts));
|
|
38
39
|
}
|
|
39
40
|
async function restAttempt(method, path, body, opts) {
|
|
41
|
+
assertRestReadable(method, path);
|
|
40
42
|
const url = githubApiUrl(path);
|
|
41
43
|
const n = nextEntry();
|
|
42
44
|
appendEntry(formatRequestEntry({ n, kind: "REST", method, url, body }));
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import {
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { mkdir, writeFile } from "../state/guarded-fs.mjs";
|
|
3
4
|
import { join } from "node:path";
|
|
4
5
|
import { resolveStateBase } from "../state/base.mjs";
|
|
6
|
+
import { isReadOnly } from "../execution-context.mjs";
|
|
5
7
|
function identityPath(id) {
|
|
6
8
|
const hash = createHash("sha256").update(id).digest("hex");
|
|
7
9
|
return join(resolveStateBase(), "github-identities", `${hash}.json`);
|
|
@@ -15,7 +17,17 @@ function numeric(value) {
|
|
|
15
17
|
export function restThreadId(rootCommentId) {
|
|
16
18
|
return `rest-thread-${numeric(rootCommentId)}`;
|
|
17
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Identities recorded inside a read-only scope, keyed by their would-be file path. The scope writes
|
|
22
|
+
* nothing to disk, but later reads in the same tick (check annotations, thread aliases) still need
|
|
23
|
+
* the identities that tick fetched.
|
|
24
|
+
*/
|
|
25
|
+
const readOnlyIdentities = new Map();
|
|
18
26
|
async function storeIdentity(id, entry) {
|
|
27
|
+
if (isReadOnly()) {
|
|
28
|
+
readOnlyIdentities.set(identityPath(id), JSON.stringify({ id, ...entry }));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
19
31
|
await mkdir(join(resolveStateBase(), "github-identities"), { recursive: true });
|
|
20
32
|
await writeFile(identityPath(id), JSON.stringify({ id, ...entry }));
|
|
21
33
|
}
|
|
@@ -27,7 +39,9 @@ export async function recordRestIdentity(repo, pr, nodeId, numericId, kind) {
|
|
|
27
39
|
export async function resolveRestIdentity(id, kind) {
|
|
28
40
|
let entry;
|
|
29
41
|
try {
|
|
30
|
-
|
|
42
|
+
const path = identityPath(id);
|
|
43
|
+
const recorded = isReadOnly() ? readOnlyIdentities.get(path) : undefined;
|
|
44
|
+
entry = JSON.parse(recorded ?? (await readFile(path, "utf8")));
|
|
31
45
|
}
|
|
32
46
|
catch {
|
|
33
47
|
throw new Error(`No recorded REST identity for ${id}; refresh this PR with REST transport first`);
|
package/bin/log/log-file.mjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Write failures flip an internal disabled flag so the CLI never crashes because
|
|
8
8
|
* logging failed.
|
|
9
9
|
*/
|
|
10
|
-
import { appendFileSync, mkdirSync } from "
|
|
10
|
+
import { appendFileSyncGuarded as appendFileSync, mkdirSyncGuarded as mkdirSync, } from "../state/guarded-fs.mjs";
|
|
11
11
|
import { dirname, join } from "node:path";
|
|
12
12
|
import { resolveRepoStateDir } from "../state/base.mjs";
|
|
13
13
|
import { getWorktreeKey } from "../util/worktree.mjs";
|
package/bin/state/base.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { join } from "node:path";
|
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { SAFE_PR_NUMBER, SAFE_SEGMENT } from "../util/path-segment.mjs";
|
|
5
5
|
import { resolveDurableStateBase } from "./durable-state.mjs";
|
|
6
|
+
import { isReadOnly } from "../execution-context.mjs";
|
|
6
7
|
/** Read once per process; null when the platform is not Linux or the shared base is unusable. */
|
|
7
8
|
let linuxUserStateBase;
|
|
8
9
|
/**
|
|
@@ -12,17 +13,23 @@ let linuxUserStateBase;
|
|
|
12
13
|
* directory must be a real directory (not a symlink) owned by this user and not writable by
|
|
13
14
|
* anyone else; it must also be readable, writable, and searchable from this process. Otherwise fall back to `TMPDIR`.
|
|
14
15
|
*/
|
|
15
|
-
function
|
|
16
|
+
function sharedLinuxStateDir() {
|
|
17
|
+
return join("/tmp", `pr-shepherd-state-${process.getuid()}`);
|
|
18
|
+
}
|
|
19
|
+
/** `"missing"` only when `create` is false and the directory does not exist yet. */
|
|
20
|
+
function readLinuxUserStateBase(create) {
|
|
16
21
|
if (process.platform !== "linux" || typeof process.getuid !== "function")
|
|
17
22
|
return null;
|
|
18
23
|
const uid = process.getuid();
|
|
19
|
-
const dir =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const dir = sharedLinuxStateDir();
|
|
25
|
+
if (create) {
|
|
26
|
+
try {
|
|
27
|
+
mkdirSync(dir, { mode: 0o700 });
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
if (err.code !== "EEXIST")
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
26
33
|
}
|
|
27
34
|
try {
|
|
28
35
|
const stat = lstatSync(dir);
|
|
@@ -31,8 +38,8 @@ function readLinuxUserStateBase() {
|
|
|
31
38
|
accessSync(dir, constants.R_OK | constants.W_OK | constants.X_OK);
|
|
32
39
|
return dir;
|
|
33
40
|
}
|
|
34
|
-
catch {
|
|
35
|
-
return null;
|
|
41
|
+
catch (err) {
|
|
42
|
+
return !create && err.code === "ENOENT" ? "missing" : null;
|
|
36
43
|
}
|
|
37
44
|
}
|
|
38
45
|
export function resolveStateBase() {
|
|
@@ -42,8 +49,19 @@ export function resolveStateBase() {
|
|
|
42
49
|
const durable = resolveDurableStateBase();
|
|
43
50
|
if (durable)
|
|
44
51
|
return durable;
|
|
45
|
-
if (linuxUserStateBase === undefined)
|
|
46
|
-
|
|
52
|
+
if (linuxUserStateBase === undefined) {
|
|
53
|
+
// A read-only scope never creates the shared base. A missing base holds no state to read, so
|
|
54
|
+
// name it without caching the answer: the next writing call must still create it.
|
|
55
|
+
if (isReadOnly()) {
|
|
56
|
+
const base = readLinuxUserStateBase(false);
|
|
57
|
+
if (base === "missing")
|
|
58
|
+
return sharedLinuxStateDir();
|
|
59
|
+
linuxUserStateBase = base;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
linuxUserStateBase = readLinuxUserStateBase(true);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
47
65
|
if (linuxUserStateBase)
|
|
48
66
|
return linuxUserStateBase;
|
|
49
67
|
return join(tmpdir(), "pr-shepherd-state");
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* `$PR_SHEPHERD_STATE_DIR/<owner>/<repo>/<pr>/check-blockers.json`
|
|
5
5
|
*/
|
|
6
|
-
import { readFile
|
|
6
|
+
import { readFile } from "node:fs/promises";
|
|
7
|
+
import { writeFile, rename, unlink, mkdir } from "./guarded-fs.mjs";
|
|
7
8
|
import { randomUUID } from "node:crypto";
|
|
8
9
|
import { dirname } from "node:path";
|
|
9
10
|
import { resolvePrStatePath } from "./base.mjs";
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* not that the caller ran it. The next presented tick with the same head and checks escalates.
|
|
7
7
|
* Internal debounce preview ticks do not write this marker.
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
9
|
+
import { readFile } from "node:fs/promises";
|
|
10
|
+
import { mkdir, writeFile } from "./guarded-fs.mjs";
|
|
10
11
|
import { dirname } from "node:path";
|
|
11
12
|
import { resolvePrStatePath } from "./base.mjs";
|
|
12
13
|
/**
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
* Reopening does not change the head SHA, so the next presented tick must not offer it again.
|
|
7
7
|
* Internal debounce preview ticks do not write this marker.
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
9
|
+
import { readFile } from "node:fs/promises";
|
|
10
|
+
import { mkdir, writeFile } from "./guarded-fs.mjs";
|
|
10
11
|
import { dirname } from "node:path";
|
|
11
12
|
import { resolvePrStatePath } from "./base.mjs";
|
|
12
13
|
/** The stored head and context set, or undefined when no usable marker exists. */
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* GitHub's Commit object has no push timestamp, so the missing-CI grace
|
|
6
6
|
* starts at this observation instead of `committedDate`.
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { readFile } from "node:fs/promises";
|
|
9
|
+
import { mkdir, writeFile } from "./guarded-fs.mjs";
|
|
9
10
|
import { dirname } from "node:path";
|
|
10
11
|
import { resolvePrStatePath } from "./base.mjs";
|
|
11
12
|
/** Unix seconds of the first observation of `headSha`, or undefined when state cannot be used. */
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
*
|
|
7
7
|
* State lives in `$PR_SHEPHERD_STATE_DIR/<owner>/<repo>/<pr>/fix-attempts.json`.
|
|
8
8
|
*/
|
|
9
|
-
import { readFile
|
|
9
|
+
import { readFile } from "node:fs/promises";
|
|
10
|
+
import { writeFile, rename, unlink, mkdir } from "./guarded-fs.mjs";
|
|
10
11
|
import { randomUUID } from "node:crypto";
|
|
11
12
|
import { dirname } from "node:path";
|
|
12
13
|
import { resolvePrStatePath } from "./base.mjs";
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { open, readdir } from "node:fs/promises";
|
|
2
|
+
import { mkdir, unlink } from "./guarded-fs.mjs";
|
|
2
3
|
import { join } from "node:path";
|
|
4
|
+
import { isReadOnly } from "../execution-context.mjs";
|
|
3
5
|
export async function claimWarning(path, warning, now, rearmEpoch) {
|
|
6
|
+
// A read-only check surfaces the warning without taking the claim another session would need.
|
|
7
|
+
if (isReadOnly())
|
|
8
|
+
return true;
|
|
4
9
|
const claimsDir = `${path}.claims`;
|
|
5
10
|
const claimPath = join(claimsDir, `${warning.resetAt}-${warning.limit}-${warning.thresholdPercent}-${rearmEpoch}.json`);
|
|
6
11
|
let handle;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import {
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { mkdir, rename, unlink, writeFile } from "./guarded-fs.mjs";
|
|
3
4
|
import { dirname, join } from "node:path";
|
|
4
5
|
import { resolveRepoStateDir } from "./base.mjs";
|
|
5
6
|
import { getWorktreeKey } from "../util/worktree.mjs";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one door for local state writes. Inside a read-only scope (`runReadOnly`, used by the library
|
|
3
|
+
* `status` method) every write, delete, rename, link and directory creation is a silent no-op, so a
|
|
4
|
+
* check can never create, refresh or clear state that a concurrent session owns. Reads stay on
|
|
5
|
+
* `node:fs/promises` directly.
|
|
6
|
+
*/
|
|
7
|
+
import * as fsp from "node:fs/promises";
|
|
8
|
+
import { appendFileSync, mkdirSync } from "node:fs";
|
|
9
|
+
export declare function writeFile(...args: Parameters<typeof fsp.writeFile>): Promise<void>;
|
|
10
|
+
export declare function mkdir(...args: Parameters<typeof fsp.mkdir>): Promise<void>;
|
|
11
|
+
export declare function rename(...args: Parameters<typeof fsp.rename>): Promise<void>;
|
|
12
|
+
export declare function unlink(...args: Parameters<typeof fsp.unlink>): Promise<void>;
|
|
13
|
+
export declare function rm(...args: Parameters<typeof fsp.rm>): Promise<void>;
|
|
14
|
+
export declare function link(...args: Parameters<typeof fsp.link>): Promise<void>;
|
|
15
|
+
export declare function appendFileSyncGuarded(...args: Parameters<typeof appendFileSync>): void;
|
|
16
|
+
export declare function mkdirSyncGuarded(...args: Parameters<typeof mkdirSync>): void;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one door for local state writes. Inside a read-only scope (`runReadOnly`, used by the library
|
|
3
|
+
* `status` method) every write, delete, rename, link and directory creation is a silent no-op, so a
|
|
4
|
+
* check can never create, refresh or clear state that a concurrent session owns. Reads stay on
|
|
5
|
+
* `node:fs/promises` directly.
|
|
6
|
+
*/
|
|
7
|
+
import * as fsp from "node:fs/promises";
|
|
8
|
+
import { appendFileSync, mkdirSync } from "node:fs";
|
|
9
|
+
import { isReadOnly } from "../execution-context.mjs";
|
|
10
|
+
export async function writeFile(...args) {
|
|
11
|
+
if (isReadOnly())
|
|
12
|
+
return;
|
|
13
|
+
await fsp.writeFile(...args);
|
|
14
|
+
}
|
|
15
|
+
export async function mkdir(...args) {
|
|
16
|
+
if (isReadOnly())
|
|
17
|
+
return;
|
|
18
|
+
await fsp.mkdir(...args);
|
|
19
|
+
}
|
|
20
|
+
export async function rename(...args) {
|
|
21
|
+
if (isReadOnly())
|
|
22
|
+
return;
|
|
23
|
+
await fsp.rename(...args);
|
|
24
|
+
}
|
|
25
|
+
export async function unlink(...args) {
|
|
26
|
+
if (isReadOnly())
|
|
27
|
+
return;
|
|
28
|
+
await fsp.unlink(...args);
|
|
29
|
+
}
|
|
30
|
+
export async function rm(...args) {
|
|
31
|
+
if (isReadOnly())
|
|
32
|
+
return;
|
|
33
|
+
await fsp.rm(...args);
|
|
34
|
+
}
|
|
35
|
+
export async function link(...args) {
|
|
36
|
+
if (isReadOnly())
|
|
37
|
+
return;
|
|
38
|
+
await fsp.link(...args);
|
|
39
|
+
}
|
|
40
|
+
export function appendFileSyncGuarded(...args) {
|
|
41
|
+
if (isReadOnly())
|
|
42
|
+
return;
|
|
43
|
+
appendFileSync(...args);
|
|
44
|
+
}
|
|
45
|
+
export function mkdirSyncGuarded(...args) {
|
|
46
|
+
if (isReadOnly())
|
|
47
|
+
return;
|
|
48
|
+
mkdirSync(...args);
|
|
49
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
-
import {
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { link, mkdir, rename, rm, unlink, writeFile } from "./guarded-fs.mjs";
|
|
3
4
|
import { dirname } from "node:path";
|
|
4
5
|
import { resolvePrStatePath } from "./base.mjs";
|
|
5
6
|
import { restMergeStackGuardKey, validateRestMergeStackGuard, } from "../github/rest-merge-stack-guard.mjs";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
|
-
import {
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { mkdir, rename, unlink, writeFile } from "./guarded-fs.mjs";
|
|
4
5
|
import { dirname } from "node:path";
|
|
5
6
|
import { resolvePrStatePath } from "./base.mjs";
|
|
6
7
|
import { discoverRuleFiles } from "../classify/loader.mjs";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** A caller's acknowledgment of one observed CI-driven native-stack queue removal. */
|
|
2
|
-
import {
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { mkdir, rename, unlink, writeFile } from "./guarded-fs.mjs";
|
|
3
4
|
import { randomUUID } from "node:crypto";
|
|
4
5
|
import { dirname } from "node:path";
|
|
5
6
|
import { resolvePrStatePath } from "./base.mjs";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { mkdir, unlink, writeFile } from "./guarded-fs.mjs";
|
|
2
3
|
import { dirname } from "node:path";
|
|
3
4
|
import { resolvePrStatePath } from "./base.mjs";
|
|
4
5
|
/** Read a persisted one-PR readiness receipt. Invalid/stale-shaped files are ignored. */
|
package/bin/state/rest-cache.mjs
CHANGED
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
* and are removed for free when `pr-shepherd clean` deletes the PR's state
|
|
19
19
|
* directory — there is no separate pruning routine.
|
|
20
20
|
*/
|
|
21
|
-
import { readFile
|
|
21
|
+
import { readFile } from "node:fs/promises";
|
|
22
|
+
import { writeFile, rename, unlink, mkdir } from "./guarded-fs.mjs";
|
|
22
23
|
import { dirname } from "node:path";
|
|
23
24
|
import { createHash, randomUUID } from "node:crypto";
|
|
24
25
|
import { resolvePrStatePath } from "./base.mjs";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import {
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { mkdir, rename, unlink, writeFile } from "./guarded-fs.mjs";
|
|
3
4
|
import { dirname } from "node:path";
|
|
4
5
|
import { resolvePrStatePath } from "./base.mjs";
|
|
5
6
|
import { fingerprintInputDigest } from "./pr-fingerprint.mjs";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable max-lines */
|
|
2
|
-
import { readFile,
|
|
2
|
+
import { readFile, access, readdir } from "node:fs/promises";
|
|
3
|
+
import { writeFile, rename, unlink, mkdir } from "./guarded-fs.mjs";
|
|
3
4
|
import { join, dirname } from "node:path";
|
|
4
5
|
import { createHash, randomUUID } from "node:crypto";
|
|
5
6
|
import { SAFE_SEGMENT } from "../util/path-segment.mjs";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** A one-field marker file in the PR state directory: "this exact situation was already presented". */
|
|
2
|
-
import {
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { mkdir, writeFile } from "./guarded-fs.mjs";
|
|
3
4
|
import { dirname } from "node:path";
|
|
4
5
|
import { resolvePrStatePath } from "./base.mjs";
|
|
5
6
|
/** True when the marker file holds exactly this signature. */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { mkdir, unlink, writeFile } from "./guarded-fs.mjs";
|
|
2
3
|
import { dirname } from "node:path";
|
|
3
4
|
import { resolveStackStatePath } from "./base.mjs";
|
|
4
5
|
/** How long one request's approval lasts; a request outliving it is approved afresh. */
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* When even the temp directory is unusable the marker cannot bound the repair tick, so the failure escalates at once.
|
|
10
10
|
*/
|
|
11
11
|
import { createHash } from "node:crypto";
|
|
12
|
-
import { readFile
|
|
12
|
+
import { readFile } from "node:fs/promises";
|
|
13
|
+
import { writeFile } from "./guarded-fs.mjs";
|
|
13
14
|
import { tmpdir } from "node:os";
|
|
14
15
|
import { join } from "node:path";
|
|
15
16
|
import { resolveStateBase } from "./base.mjs";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { readFile
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { writeFile, rename, unlink, mkdir } from "./guarded-fs.mjs";
|
|
2
3
|
import { randomUUID } from "node:crypto";
|
|
3
4
|
import { dirname } from "node:path";
|
|
4
5
|
/**
|
package/bin/types/iterate.d.mts
CHANGED
|
@@ -27,6 +27,8 @@ export interface IterateResultBase {
|
|
|
27
27
|
}>;
|
|
28
28
|
pr: number;
|
|
29
29
|
repo: string;
|
|
30
|
+
/** The PR head commit this tick evaluated. Omitted when GitHub did not report it. */
|
|
31
|
+
headSha?: string;
|
|
30
32
|
status: ShepherdStatus;
|
|
31
33
|
state: "OPEN" | "CLOSED" | "MERGED" | "UNKNOWN";
|
|
32
34
|
mergeStateStatus: MergeStateStatus;
|
package/package.json
CHANGED