open-pstack 0.9.173 → 0.9.175
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/NOTICE.md +1 -1
- package/lib/bundle.mjs +50 -4
- package/lib/cli.mjs +1 -1
- package/lib/harnesses.mjs +26 -15
- package/lib/steps.mjs +3 -3
- package/package.json +1 -1
- package/plugin/.antigravity-plugin/plugin.json +1 -1
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/.codex-plugin/plugin.json +1 -1
- package/plugin/.github/plugin/plugin.json +1 -1
- package/plugin/.grok-plugin/plugin.json +1 -1
- package/plugin/.muse-plugin/plugin.json +1 -1
- package/plugin/hooks/session-start.sh +6 -3
- package/plugin/package.json +1 -1
- package/plugin/pi/index.ts +3 -2
- package/plugin/pi/prompt.ts +8 -3
- package/plugin/skills/poteto-mode/playbooks/worktree-cleanup.md +1 -1
- package/plugin/skills/poteto-mode/scripts/.prettierignore +3 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/cloud-reader.test.ts +21 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/cloud-reader.ts +7 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/fakes.test-helper.ts +6 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/github.port.test.ts +33 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/github.ts +25 -23
- package/plugin/skills/poteto-mode/scripts/watch-pr/head-checks.ts +47 -1
- package/plugin/skills/poteto-mode/scripts/watch-pr/policy.port.test.ts +158 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay/fixtures/grafana-139602-cancelled-suites-beside-green.json +921 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay/fixtures/grafana-139606-approval-gated.json +82 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay/fixtures/grafana-139612-cancelled-check-beside-green.json +174 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay/fixtures/octocat-hello-world-34-no-checks.json +42 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay/gh.ts +144 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay/harness.ts +172 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay/heads.json +73 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay/record.ts +410 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay/watch.ts +72 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/replay.port.test.ts +264 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/types.ts +2 -0
- package/plugin/skills/poteto-mode/scripts/watch-pr/workflow-runs.ts +58 -21
- package/plugin/skills/poteto-mode/scripts/worktree-audit.mjs +75 -6
- package/plugin/skills/setup-pstack/scripts/read-sheet.sh +6 -2
- package/plugin/vibe/plugin.json +1 -1
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
// Replays GitHub's recorded answers for real pull request heads through
|
|
2
|
+
// watch-pr's own CLI and reader, with a stand-in `gh` on PATH, and checks the
|
|
3
|
+
// verdict for each head. replay/record.ts records and refreshes the corpus,
|
|
4
|
+
// and replay/heads.json holds each expected verdict with its reasoning.
|
|
5
|
+
import { afterAll, describe, expect, it } from "bun:test";
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
7
|
+
import {
|
|
8
|
+
existsSync,
|
|
9
|
+
mkdtempSync,
|
|
10
|
+
readdirSync,
|
|
11
|
+
readFileSync,
|
|
12
|
+
rmSync,
|
|
13
|
+
writeFileSync,
|
|
14
|
+
} from "node:fs";
|
|
15
|
+
import { tmpdir } from "node:os";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
import { isRead, requestName, type Fixture } from "./replay/gh.ts";
|
|
18
|
+
import {
|
|
19
|
+
fixturePath,
|
|
20
|
+
ghOnPath,
|
|
21
|
+
heads,
|
|
22
|
+
movedHead,
|
|
23
|
+
outcomeOf,
|
|
24
|
+
runWatch,
|
|
25
|
+
type Head,
|
|
26
|
+
type Outcome,
|
|
27
|
+
} from "./replay/harness.ts";
|
|
28
|
+
|
|
29
|
+
const dir = mkdtempSync(join(tmpdir(), "watch-replay-"));
|
|
30
|
+
afterAll(() => rmSync(dir, { recursive: true, force: true }));
|
|
31
|
+
|
|
32
|
+
const fixtureOf = (head: Head): Fixture =>
|
|
33
|
+
JSON.parse(readFileSync(fixturePath(head.name), "utf8")) as Fixture;
|
|
34
|
+
const replay = (head: Head, fixture = fixturePath(head.name)): Outcome =>
|
|
35
|
+
outcomeOf(
|
|
36
|
+
runWatch(head, ghOnPath(mkdtempSync(join(dir, "gh-")), { fixture }))
|
|
37
|
+
);
|
|
38
|
+
const headNamed = (name: string): Head => {
|
|
39
|
+
const head = heads().find((item) => item.name === name);
|
|
40
|
+
if (head === undefined) throw new Error(`heads.json has no ${name}`);
|
|
41
|
+
return head;
|
|
42
|
+
};
|
|
43
|
+
const SPAWNS = 60_000;
|
|
44
|
+
|
|
45
|
+
describe("the recorded heads", () => {
|
|
46
|
+
it("each have a fixture for the head they name, and a reason for the verdict", () => {
|
|
47
|
+
expect(heads().length).toBeGreaterThanOrEqual(3);
|
|
48
|
+
for (const head of heads()) {
|
|
49
|
+
expect(existsSync(fixturePath(head.name))).toBe(true);
|
|
50
|
+
const fixture = fixtureOf(head);
|
|
51
|
+
expect({ pr: fixture.pr, head: fixture.head }).toEqual({
|
|
52
|
+
pr: `${head.owner}/${head.repo}#${head.pr}`,
|
|
53
|
+
head: head.head,
|
|
54
|
+
});
|
|
55
|
+
expect(movedHead(head, fixture.calls)).toBeNull();
|
|
56
|
+
expect(head.because.length).toBeGreaterThan(200);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// record.ts refuses to write a fixture whose answers came from a newer head.
|
|
61
|
+
it("are told apart from a recording GitHub answered for another head", () => {
|
|
62
|
+
const head = headNamed("grafana-139612-cancelled-check-beside-green");
|
|
63
|
+
const { calls } = fixtureOf(head);
|
|
64
|
+
const factsKey = Object.keys(calls).find((name) =>
|
|
65
|
+
name.startsWith("graphql PullRequestFacts ")
|
|
66
|
+
);
|
|
67
|
+
if (factsKey === undefined) throw new Error("no PullRequestFacts call");
|
|
68
|
+
const newer = "0".repeat(40);
|
|
69
|
+
const moved = {
|
|
70
|
+
...calls,
|
|
71
|
+
[factsKey]: {
|
|
72
|
+
code: 0,
|
|
73
|
+
json: {
|
|
74
|
+
data: { repository: { pullRequest: { headRefOid: newer } } },
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
expect(movedHead(head, moved)).toBe(
|
|
79
|
+
`GitHub answered for head ${newer}, not ${head.head}, so the pull request has moved on. Pick another head for heads.json`
|
|
80
|
+
);
|
|
81
|
+
const { [factsKey]: _dropped, ...unanswered } = calls;
|
|
82
|
+
expect(movedHead(head, unanswered)).toBe(
|
|
83
|
+
`no PullRequestFacts answer names a head, so nothing shows the recording is of ${head.head}`
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("include a head with cancelled suites beside green checks and a head with no checks", () => {
|
|
88
|
+
expect(heads().map((head) => head.property)).toEqual(
|
|
89
|
+
expect.arrayContaining([
|
|
90
|
+
"cancelled-suite-beside-green-checks",
|
|
91
|
+
"no-checks-and-no-suites",
|
|
92
|
+
])
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
for (const head of heads())
|
|
97
|
+
it(
|
|
98
|
+
`${head.name} replays to its expected verdict`,
|
|
99
|
+
() => {
|
|
100
|
+
expect(replay(head)).toEqual(head.expected);
|
|
101
|
+
},
|
|
102
|
+
SPAWNS
|
|
103
|
+
);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// A changed fixture replays to a different verdict, so the cases above read
|
|
107
|
+
// the fixtures and not a constant. This is the grafana head as it would be
|
|
108
|
+
// had the three workflows started: the two cancelled suites still sit beside
|
|
109
|
+
// green checks, and nothing else blocks.
|
|
110
|
+
describe("a recorded head with one fact changed", () => {
|
|
111
|
+
it(
|
|
112
|
+
"is READY once the suites that failed to start are gone, cancelled suites or not",
|
|
113
|
+
() => {
|
|
114
|
+
const head = headNamed("grafana-139602-cancelled-suites-beside-green");
|
|
115
|
+
const fixture = fixtureOf(head);
|
|
116
|
+
const suitesKey = Object.keys(fixture.calls).find((name) =>
|
|
117
|
+
name.includes("/check-suites?")
|
|
118
|
+
);
|
|
119
|
+
if (suitesKey === undefined) throw new Error("no suites call recorded");
|
|
120
|
+
const pages = fixture.calls[suitesKey].json as {
|
|
121
|
+
check_suites: { conclusion: string | null }[];
|
|
122
|
+
}[];
|
|
123
|
+
const suites = pages.flatMap((page) => page.check_suites);
|
|
124
|
+
const conclusions = suites.map((suite) => suite.conclusion);
|
|
125
|
+
expect(conclusions).toContain("cancelled");
|
|
126
|
+
expect(conclusions).toContain("startup_failure");
|
|
127
|
+
const changed = join(dir, "started.json");
|
|
128
|
+
writeFileSync(
|
|
129
|
+
changed,
|
|
130
|
+
JSON.stringify({
|
|
131
|
+
...fixture,
|
|
132
|
+
calls: {
|
|
133
|
+
...fixture.calls,
|
|
134
|
+
[suitesKey]: {
|
|
135
|
+
code: 0,
|
|
136
|
+
json: [
|
|
137
|
+
{
|
|
138
|
+
check_suites: suites.filter(
|
|
139
|
+
(suite) => suite.conclusion !== "startup_failure"
|
|
140
|
+
),
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
})
|
|
146
|
+
);
|
|
147
|
+
expect(replay(head, changed)).toEqual({
|
|
148
|
+
status: { exitCode: 0, kind: "STATUS", ci: "ci-clean" },
|
|
149
|
+
watch: { exitCode: 0, kind: "READY", detail: null, failed: [] },
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
SPAWNS
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
it(
|
|
156
|
+
"fails the read when the fixture lacks an answer, and never falls through to GitHub",
|
|
157
|
+
() => {
|
|
158
|
+
const head = headNamed("octocat-hello-world-34-no-checks");
|
|
159
|
+
const fixture = fixtureOf(head);
|
|
160
|
+
const checksKey = Object.keys(fixture.calls).find((name) =>
|
|
161
|
+
name.startsWith("pr checks ")
|
|
162
|
+
);
|
|
163
|
+
const { [checksKey ?? ""]: _dropped, ...rest } = fixture.calls;
|
|
164
|
+
const changed = join(dir, "no-checks-answer.json");
|
|
165
|
+
writeFileSync(changed, JSON.stringify({ ...fixture, calls: rest }));
|
|
166
|
+
expect(replay(head, changed)).toMatchObject({
|
|
167
|
+
status: { exitCode: 7, kind: "BLOCKER" },
|
|
168
|
+
watch: { exitCode: 7, kind: "BLOCKER", detail: "status-query" },
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
SPAWNS
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe("the stand-in gh", () => {
|
|
176
|
+
const graphql = (document: string): string[] => [
|
|
177
|
+
"api",
|
|
178
|
+
"graphql",
|
|
179
|
+
"-f",
|
|
180
|
+
`query=${document}`,
|
|
181
|
+
"-f",
|
|
182
|
+
"owner=o",
|
|
183
|
+
"-F",
|
|
184
|
+
"pr=1",
|
|
185
|
+
];
|
|
186
|
+
|
|
187
|
+
it("passes on watch-pr's reads when recording", () => {
|
|
188
|
+
for (const args of [
|
|
189
|
+
graphql("query PullRequestFacts($owner: String!) { repository }"),
|
|
190
|
+
[
|
|
191
|
+
"api",
|
|
192
|
+
"--paginate",
|
|
193
|
+
"--slurp",
|
|
194
|
+
"repos/o/r/commits/abc123/check-suites?per_page=100",
|
|
195
|
+
],
|
|
196
|
+
[
|
|
197
|
+
"api",
|
|
198
|
+
"--paginate",
|
|
199
|
+
"--slurp",
|
|
200
|
+
"repos/o/r/actions/runs?head_sha=abc123&per_page=100",
|
|
201
|
+
],
|
|
202
|
+
["pr", "checks", "1", "--repo", "o/r", "--json", "name"],
|
|
203
|
+
["pr", "view", "1", "--json", "number,url"],
|
|
204
|
+
["pr", "list", "--repo", "o/r"],
|
|
205
|
+
["repo", "view", "o/r", "--json", "defaultBranchRef"],
|
|
206
|
+
])
|
|
207
|
+
expect({ args, read: isRead(args) }).toEqual({ args, read: true });
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it("refuses everything else when recording", () => {
|
|
211
|
+
for (const args of [
|
|
212
|
+
graphql(
|
|
213
|
+
"mutation Merge { mergePullRequest(input: {}) { clientMutationId } }"
|
|
214
|
+
),
|
|
215
|
+
graphql("query Q { viewer { login } } mutation M { x }"),
|
|
216
|
+
["api", "graphql", "-f", "owner=o"],
|
|
217
|
+
[
|
|
218
|
+
"api",
|
|
219
|
+
"-X",
|
|
220
|
+
"POST",
|
|
221
|
+
"repos/o/r/commits/abc123/check-suites?per_page=100",
|
|
222
|
+
],
|
|
223
|
+
["api", "--method=DELETE", "repos/o/r/actions/runs?head_sha=abc123"],
|
|
224
|
+
["api", "-f", "body=hi", "repos/o/r/actions/runs?head_sha=abc123"],
|
|
225
|
+
["api", "repos/o/r/pulls/1/merge"],
|
|
226
|
+
["api", "repos/o/r/issues/1/comments"],
|
|
227
|
+
["pr", "merge", "1"],
|
|
228
|
+
["pr", "comment", "1", "--body", "hi"],
|
|
229
|
+
["pr", "close", "1"],
|
|
230
|
+
["repo", "delete", "o/r"],
|
|
231
|
+
["issue", "create"],
|
|
232
|
+
])
|
|
233
|
+
expect({ args, read: isRead(args) }).toEqual({ args, read: false });
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("refuses a write through the gh on PATH and runs nothing", () => {
|
|
237
|
+
const cwd = mkdtempSync(join(dir, "refused-"));
|
|
238
|
+
// In place of the real gh: touch would leave files named after the
|
|
239
|
+
// arguments in the empty working directory if the stand-in ran it.
|
|
240
|
+
const bin = ghOnPath(mkdtempSync(join(dir, "gh-")), {
|
|
241
|
+
gh: "/usr/bin/touch",
|
|
242
|
+
log: join(cwd, "log"),
|
|
243
|
+
});
|
|
244
|
+
const result = spawnSync(join(bin, "gh"), ["pr", "merge", "1"], {
|
|
245
|
+
encoding: "utf8",
|
|
246
|
+
cwd,
|
|
247
|
+
env: { PATH: process.env.PATH },
|
|
248
|
+
});
|
|
249
|
+
expect(result.status).toBe(1);
|
|
250
|
+
expect(result.stderr).toContain(
|
|
251
|
+
"record: refused, not one of watch-pr's reads"
|
|
252
|
+
);
|
|
253
|
+
expect(readdirSync(cwd)).toEqual([]);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it("names a GraphQL request by its operation and variables, not its document", () => {
|
|
257
|
+
expect(
|
|
258
|
+
requestName(graphql("query PrCheckRollup($owner: String!) {\n a\n}"))
|
|
259
|
+
).toBe("graphql PrCheckRollup owner=o pr=1");
|
|
260
|
+
expect(requestName(["pr", "checks", "1", "--repo", "o/r"])).toBe(
|
|
261
|
+
"pr checks 1 --repo o/r"
|
|
262
|
+
);
|
|
263
|
+
});
|
|
264
|
+
});
|
|
@@ -490,6 +490,8 @@ export interface GitHubReader {
|
|
|
490
490
|
checksRead: CheckRead["kind"],
|
|
491
491
|
expectedApps: readonly string[]
|
|
492
492
|
): Promise<SuiteRead>;
|
|
493
|
+
/** The pages of the head's Actions workflow runs, as REST lists them. */
|
|
494
|
+
workflowRunPages(context: PrContext, head: string): Promise<unknown>;
|
|
493
495
|
}
|
|
494
496
|
export interface PollingOptions {
|
|
495
497
|
readonly interval: number;
|
|
@@ -112,6 +112,56 @@ function ownCorrelatedSuites(
|
|
|
112
112
|
if (runIdentity(run) === identity) ownedSuiteIds.add(run.checkSuiteId);
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
// Every run in the pages of an `actions/runs?head_sha=` read, which must all
|
|
116
|
+
// be on `head`.
|
|
117
|
+
function runsOnHead(pages: unknown, head: string): WorkflowRun[] {
|
|
118
|
+
if (!Array.isArray(pages) || pages.length === 0)
|
|
119
|
+
missing("workflow run pages", pages);
|
|
120
|
+
const runs: WorkflowRun[] = [];
|
|
121
|
+
for (const page of pages) {
|
|
122
|
+
if (!isRecord(page)) missing("workflow_runs", page);
|
|
123
|
+
if (!("workflow_runs" in page)) missing("workflow_runs");
|
|
124
|
+
if (!Array.isArray(page.workflow_runs))
|
|
125
|
+
missing("workflow_runs", page.workflow_runs);
|
|
126
|
+
for (const value of page.workflow_runs) {
|
|
127
|
+
if (!isRecord(value)) missing("workflow run", value);
|
|
128
|
+
const run = parseWorkflowRun(value);
|
|
129
|
+
if (run.headSha !== head)
|
|
130
|
+
missing(
|
|
131
|
+
"workflow run.head_sha must match the queried head",
|
|
132
|
+
run.headSha
|
|
133
|
+
);
|
|
134
|
+
runs.push(run);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return runs;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// The IDs of the runs on `head` that a later, finished run of the same
|
|
141
|
+
// workflow and event supersedes. resolveWorkflowRunChecks also counts a run
|
|
142
|
+
// still in progress, and hides a cancelled suite beside an earlier success;
|
|
143
|
+
// this does neither.
|
|
144
|
+
export function replacedRunIds(
|
|
145
|
+
pages: unknown,
|
|
146
|
+
head: string
|
|
147
|
+
): ReadonlySet<number> {
|
|
148
|
+
const runs = runsOnHead(pages, head).sort(compareRuns);
|
|
149
|
+
return new Set(
|
|
150
|
+
runs
|
|
151
|
+
.filter((run, index) =>
|
|
152
|
+
runs
|
|
153
|
+
.slice(index + 1)
|
|
154
|
+
.some(
|
|
155
|
+
(later) =>
|
|
156
|
+
later.status === "completed" &&
|
|
157
|
+
runIdentity(later) === runIdentity(run) &&
|
|
158
|
+
canSupersede(later)
|
|
159
|
+
)
|
|
160
|
+
)
|
|
161
|
+
.map((run) => run.id)
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
115
165
|
// Check suites with a zero-run startup_failure cannot name the workflow or
|
|
116
166
|
// event, so Actions workflow runs supply the identity while the already-parsed
|
|
117
167
|
// suite evidence proves the zero-run case. Sorting runs chronologically makes
|
|
@@ -133,28 +183,15 @@ export function resolveWorkflowRunChecks(
|
|
|
133
183
|
startupSuiteIds.push(suite.id);
|
|
134
184
|
}
|
|
135
185
|
const runs: WorkflowRun[] = [];
|
|
136
|
-
for (const
|
|
137
|
-
if (!
|
|
138
|
-
if (
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const run = parseWorkflowRun(value);
|
|
144
|
-
if (run.headSha !== head)
|
|
145
|
-
missing(
|
|
146
|
-
"workflow run.head_sha must match the queried head",
|
|
147
|
-
run.headSha
|
|
148
|
-
);
|
|
149
|
-
if (!suites.actionsSuites.has(run.checkSuiteId)) continue;
|
|
150
|
-
if (run.status === "completed") {
|
|
151
|
-
if (run.conclusion === null)
|
|
152
|
-
missing("workflow run.conclusion of a completed run", run.conclusion);
|
|
153
|
-
if (!KNOWN_COMPLETED_CONCLUSIONS.has(run.conclusion))
|
|
154
|
-
missing("workflow run.conclusion", run.conclusion);
|
|
155
|
-
}
|
|
156
|
-
runs.push(run);
|
|
186
|
+
for (const run of runsOnHead(pages, head)) {
|
|
187
|
+
if (!suites.actionsSuites.has(run.checkSuiteId)) continue;
|
|
188
|
+
if (run.status === "completed") {
|
|
189
|
+
if (run.conclusion === null)
|
|
190
|
+
missing("workflow run.conclusion of a completed run", run.conclusion);
|
|
191
|
+
if (!KNOWN_COMPLETED_CONCLUSIONS.has(run.conclusion))
|
|
192
|
+
missing("workflow run.conclusion", run.conclusion);
|
|
157
193
|
}
|
|
194
|
+
runs.push(run);
|
|
158
195
|
}
|
|
159
196
|
const matchedSuiteIds = new Set(runs.map((run) => run.checkSuiteId));
|
|
160
197
|
for (const suiteId of startupSuiteIds)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Read-only worktree prune audit. Classifies every git worktree by size, merge
|
|
3
|
-
// state, uncommitted work,
|
|
3
|
+
// state, uncommitted work, edits that `git status` is told to overlook, ignored
|
|
4
|
+
// files outside build and cache directories,
|
|
4
5
|
// commits only its HEAD reflog reaches, remote/PR state, and the most recent chat that
|
|
5
6
|
// operated in it, then prints a table sorted by size with a suggested bucket.
|
|
6
7
|
// Never deletes anything; deletion stays a human-gated step in the playbook.
|
|
@@ -19,9 +20,9 @@
|
|
|
19
20
|
// Every probe yields a Fact, { known: true, value } or { known: false }. A hold
|
|
20
21
|
// bucket needs only its own fact; `safe` needs every fact known.
|
|
21
22
|
import { execFileSync } from "node:child_process";
|
|
22
|
-
import { readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
23
|
+
import { lstatSync, readdirSync, readFileSync, readlinkSync, realpathSync, statSync } from "node:fs";
|
|
23
24
|
import { homedir } from "node:os";
|
|
24
|
-
import { basename, dirname, join } from "node:path";
|
|
25
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
25
26
|
import process from "node:process";
|
|
26
27
|
import { fileURLToPath } from "node:url";
|
|
27
28
|
import zlib from "node:zlib";
|
|
@@ -56,7 +57,7 @@ export const DISPOSABLE = new Set([
|
|
|
56
57
|
export function classify(facts) {
|
|
57
58
|
const { locked, dirty, orphans, pr, recent, ancestry, head } = facts;
|
|
58
59
|
if (locked.known && locked.value !== null) return "hold-locked";
|
|
59
|
-
if (dirty.known && dirty.value.wip > 0) return "hold-wip";
|
|
60
|
+
if (dirty.known && (dirty.value.wip > 0 || dirty.value.hidden > 0 || dirty.value.autostash > 0)) return "hold-wip";
|
|
60
61
|
if (dirty.known && dirty.value.untracked > 0) return "hold-untracked";
|
|
61
62
|
if (orphans.known && orphans.value > 0) return "hold-reflog";
|
|
62
63
|
if (dirty.known && dirty.value.ignored > 0) return "hold-ignored";
|
|
@@ -296,7 +297,73 @@ function dirtyState(path) {
|
|
|
296
297
|
"git ls-files --others --ignored --exclude-standard --directory --no-empty-directory -z");
|
|
297
298
|
ignored += nested.split("\0").filter((name) => name && keepIgnored(name)).length;
|
|
298
299
|
}
|
|
299
|
-
|
|
300
|
+
let hidden = hiddenEdits(path);
|
|
301
|
+
let autostash = autostashes(path);
|
|
302
|
+
if (statSync(join(path, ".gitmodules"), { throwIfNoEntry: false })) {
|
|
303
|
+
const nested = git(path, "submodule", "foreach", "--quiet", "--recursive", "git rev-parse --show-toplevel");
|
|
304
|
+
for (const submodule of nested.split("\n").filter(Boolean)) {
|
|
305
|
+
hidden += hiddenEdits(submodule);
|
|
306
|
+
autostash += autostashes(submodule);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return { wip: lines.length - untracked - ignoredLines.length, untracked, ignored, hidden, autostash };
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const gitInput = (cwd, input, ...args) =>
|
|
313
|
+
execFileSync("git", args, { cwd, encoding: "utf8", input, stdio: ["pipe", "pipe", "pipe"], maxBuffer: Infinity });
|
|
314
|
+
|
|
315
|
+
// One `git ls-files -v -s -z` record: tag, mode, blob, stage, then the path.
|
|
316
|
+
const INDEX_ENTRY = /^(\S) (\d+) ([0-9a-f]+) \d\t([\s\S]+)$/;
|
|
317
|
+
|
|
318
|
+
// `git status` reports nothing for an index entry flagged skip-worktree or
|
|
319
|
+
// assume-unchanged, in a sparse checkout or out of one, and `git worktree
|
|
320
|
+
// remove` then deletes the tree without asking for --force. Counts the flagged
|
|
321
|
+
// entries whose file on disk differs from the index. A flagged entry with no
|
|
322
|
+
// file on disk, as outside a sparse checkout's cone, holds nothing. Reads only:
|
|
323
|
+
// the flags stay as the user set them.
|
|
324
|
+
function hiddenEdits(path) {
|
|
325
|
+
const flagged = git(path, "ls-files", "-v", "-s", "-z").split("\0")
|
|
326
|
+
.map((entry) => INDEX_ENTRY.exec(entry))
|
|
327
|
+
// `S` is skip-worktree and a lowercase tag is assume-unchanged. A gitlink is the submodule's own tree.
|
|
328
|
+
.filter((entry) => entry && (entry[1] === "S" || entry[1] !== entry[1].toUpperCase()) && entry[2] !== "160000")
|
|
329
|
+
.map(([, , mode, sha, name]) => ({ mode, sha, name, stat: lstatSync(join(path, name), { throwIfNoEntry: false }) }))
|
|
330
|
+
.filter((entry) => entry.stat);
|
|
331
|
+
let hidden = 0;
|
|
332
|
+
const files = [];
|
|
333
|
+
for (const entry of flagged) {
|
|
334
|
+
if (entry.mode === "120000") {
|
|
335
|
+
// A checkout without symlink support holds the link's target as a file's text.
|
|
336
|
+
const full = join(path, entry.name);
|
|
337
|
+
const target = entry.stat.isSymbolicLink() ? readlinkSync(full) : entry.stat.isFile() ? readFileSync(full) : null;
|
|
338
|
+
if (target === null || gitInput(path, target, "hash-object", "--stdin", "--no-filters").trim() !== entry.sha) hidden += 1;
|
|
339
|
+
} else if (entry.stat.isFile()) files.push(entry);
|
|
340
|
+
else hidden += 1;
|
|
341
|
+
}
|
|
342
|
+
if (files.length === 0) return hidden;
|
|
343
|
+
// One path per line, so a name with a newline in it cannot be asked about.
|
|
344
|
+
if (files.some((entry) => entry.name.includes("\n"))) throw new Error("a flagged path contains a newline");
|
|
345
|
+
const hashes = gitInput(path, `${files.map((entry) => entry.name).join("\n")}\n`, "hash-object", "--stdin-paths").trim().split("\n");
|
|
346
|
+
if (hashes.length !== files.length) throw new Error("git hash-object answered for a different number of paths");
|
|
347
|
+
return hidden + files.filter((entry, index) => hashes[index] !== entry.sha).length;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// An interrupted `rebase --autostash` keeps the stashed edits as a commit named
|
|
351
|
+
// only by a file in this worktree's git directory, and an interrupted
|
|
352
|
+
// `merge --autostash` by the MERGE_AUTOSTASH ref, which the reftable backend
|
|
353
|
+
// keeps in its tables rather than as a file. Status is clean while they wait.
|
|
354
|
+
// Counts them.
|
|
355
|
+
function autostashes(path) {
|
|
356
|
+
const stashes = ["rebase-merge/autostash", "rebase-apply/autostash"];
|
|
357
|
+
const files = git(path, "rev-parse", ...stashes.flatMap((name) => ["--git-path", name])).split("\n").filter(Boolean)
|
|
358
|
+
.filter((stash) => statSync(resolve(path, stash), { throwIfNoEntry: false })).length;
|
|
359
|
+
try {
|
|
360
|
+
git(path, "rev-parse", "--verify", "MERGE_AUTOSTASH");
|
|
361
|
+
return files + 1;
|
|
362
|
+
} catch (error) {
|
|
363
|
+
// rev-parse --verify exits 128 for a name that resolves to nothing.
|
|
364
|
+
if (error.status === 128) return files;
|
|
365
|
+
throw error;
|
|
366
|
+
}
|
|
300
367
|
}
|
|
301
368
|
|
|
302
369
|
// Counts commits that only this worktree's HEAD reflog reaches, which
|
|
@@ -343,9 +410,11 @@ function sizeKey(label) {
|
|
|
343
410
|
return Number(match[1]) * 1024 ** (match[2] ? "KMGTPE".indexOf(match[2]) + 1 : 0);
|
|
344
411
|
}
|
|
345
412
|
|
|
346
|
-
function dirtyLabel({ wip, untracked, ignored }, orphans) {
|
|
413
|
+
function dirtyLabel({ wip, untracked, ignored, hidden, autostash }, orphans) {
|
|
347
414
|
return [
|
|
348
415
|
wip > 0 && `wip:${wip}`,
|
|
416
|
+
hidden > 0 && `hidden:${hidden}`,
|
|
417
|
+
autostash > 0 && `autostash:${autostash}`,
|
|
349
418
|
untracked > 0 && `untracked:${untracked}`,
|
|
350
419
|
ignored > 0 && `ignored:${ignored}`,
|
|
351
420
|
orphans.known && orphans.value > 0 && `reflog:${orphans.value}`,
|
|
@@ -16,9 +16,13 @@ if [ "$(od -An -tx1 -N2 "$sheet" | tr -d ' ')" = fffe ]; then
|
|
|
16
16
|
utf16=true
|
|
17
17
|
fi
|
|
18
18
|
bom=$(printf '\357\273\277')
|
|
19
|
-
|
|
19
|
+
stx=$(printf '\002')
|
|
20
20
|
# Command substitution in the callers drops NUL bytes, which would join the
|
|
21
21
|
# text around a NUL into a line the sheet never held. NUL travels as \001
|
|
22
22
|
# instead: neither byte can appear in a line any consumer accepts.
|
|
23
|
+
# sed drops the one CR at the end of each line. Every other CR travels as \001
|
|
24
|
+
# too: under Git for Windows' sh, sed, grep, awk and command substitution each
|
|
25
|
+
# drop a CR before an LF, so `off` with two CRs read as off. A CR is \002 until
|
|
26
|
+
# sed has run, so no CR-LF pair reaches sed, and a \002 from the sheet is \001.
|
|
23
27
|
if $utf16; then iconv -f UTF-16LE -t UTF-8 "$sheet"; else cat "$sheet"; fi |
|
|
24
|
-
tr '\000' '\001' | sed -e "1s/^$bom//" -e "s/$
|
|
28
|
+
tr '\000\002\015' '\001\001\002' | sed -e "1s/^$bom//" -e "s/$stx\$//" | tr '\002' '\001'
|
package/plugin/vibe/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
|
|
3
3
|
"name": "pstack",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.175",
|
|
5
5
|
"description": "If you want to go fast, go deep first. pstack helps you write less, but higher quality code. rigorous agent workflows you can parallelize with confidence. Ported from cursor/plugins/pstack to Vibe. Original pstack by Lauren Tan (poteto).",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Michael Denyer",
|