pi-gauntlet 5.9.0 → 5.9.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/CHANGELOG.md +4 -0
- package/README.md +2 -0
- package/extensions/lib/checkout.test.ts +59 -0
- package/extensions/lib/checkout.ts +57 -0
- package/extensions/lib/gauntlet-settings-loader.test.ts +32 -0
- package/extensions/lib/gauntlet-settings-loader.ts +11 -7
- package/extensions/lib/phase-tracker-helpers.test.ts +17 -0
- package/extensions/lib/phase-tracker-helpers.ts +16 -17
- package/extensions/lib/telemetry-paths.test.ts +10 -0
- package/extensions/lib/telemetry-paths.ts +9 -5
- package/extensions/phase-tracker.test.ts +75 -23
- package/extensions/phase-tracker.ts +20 -29
- package/extensions/telemetry.test.ts +51 -10
- package/extensions/telemetry.ts +57 -41
- package/extensions/verify-before-ship.test.ts +16 -0
- package/extensions/verify-before-ship.ts +4 -4
- package/package.json +1 -1
- package/skills/brainstorming/SKILL.md +7 -5
- package/skills/finishing-a-development-branch/SKILL.md +51 -88
- package/skills/gauntlet-resume/SKILL.md +1 -3
- package/skills/gauntlet-resume/reference/brief-contract.md +1 -1
- package/skills/roasting-the-spec/SKILL.md +1 -1
- package/skills/subagent-driven-development/SKILL.md +18 -15
- package/skills/using-git-worktrees/SKILL.md +46 -39
- package/skills/verification-before-completion/reference/conformance-check.md +6 -6
- package/skills/verification-before-completion/reference/settings-precedence.md +8 -6
- package/skills/writing-plans/SKILL.md +5 -3
- package/skills/writing-plans/reference/plan-contract.md +1 -1
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
* Use phase_tracker for "what stage am I in?", plan_tracker for "which task?".
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { execSync } from "node:child_process";
|
|
13
12
|
import { existsSync, globSync, readdirSync, readFileSync, readFileSync as readFileBytes } from "node:fs";
|
|
14
13
|
import { isAbsolute, join, resolve } from "node:path";
|
|
15
14
|
import { StringEnum } from "@earendil-works/pi-ai";
|
|
@@ -25,6 +24,7 @@ import {
|
|
|
25
24
|
settingsErrorWarning,
|
|
26
25
|
} from "./lib/gauntlet-settings.ts";
|
|
27
26
|
import { loadGauntletSettings } from "./lib/gauntlet-settings-loader.ts";
|
|
27
|
+
import { checkoutOf, gitSync } from "./lib/checkout.ts";
|
|
28
28
|
import { checkPlan, sha256, type FsPort, type PlanCheckFinding } from "./lib/plan-check.ts";
|
|
29
29
|
import {
|
|
30
30
|
checkSubstep,
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
implementWriteGuardApplies,
|
|
35
35
|
markerBlockReason,
|
|
36
36
|
nextGauntletEntered,
|
|
37
|
+
parseGitCommand,
|
|
37
38
|
parseGitCommit,
|
|
38
39
|
phaseLabel,
|
|
39
40
|
recoverableEdge,
|
|
@@ -159,8 +160,8 @@ const GUARD_PHASES: Phase[] = ["brainstorm", "plan", "implement"];
|
|
|
159
160
|
// Guard 2 — branch ops in place. `git switch` never targets a file path;
|
|
160
161
|
// `git checkout -b/-B` is explicit branch creation. Bare `git checkout <x>`
|
|
161
162
|
// is excluded (ambiguous with file checkout). `git worktree ...` is exempt.
|
|
162
|
-
const
|
|
163
|
-
const
|
|
163
|
+
const SWITCH_SUB = /switch(?=\s|$)/;
|
|
164
|
+
const CHECKOUT_BRANCH_SUB = /checkout\s+-[bB](?=\s|$)/;
|
|
164
165
|
const GIT_WORKTREE = /\bgit\s+worktree\b/;
|
|
165
166
|
|
|
166
167
|
// Guard 3 — bash mutation forms during brainstorm.
|
|
@@ -394,21 +395,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
394
395
|
// implementer's first write would trip a spurious advisory.
|
|
395
396
|
const isSubagentChild = Number(process.env.PI_SUBAGENT_DEPTH ?? "0") > 0;
|
|
396
397
|
|
|
397
|
-
const inPrimaryCheckout = (() => {
|
|
398
|
-
try {
|
|
399
|
-
const lines = execSync("git rev-parse --git-dir --git-common-dir", {
|
|
400
|
-
encoding: "utf8",
|
|
401
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
402
|
-
timeout: 5000,
|
|
403
|
-
})
|
|
404
|
-
.trim()
|
|
405
|
-
.split("\n");
|
|
406
|
-
return lines.length === 2 && lines[0] === lines[1];
|
|
407
|
-
} catch {
|
|
408
|
-
return false;
|
|
409
|
-
}
|
|
410
|
-
})();
|
|
411
|
-
|
|
412
398
|
// Auto-complete the implement phase from plan_tracker once every task is done,
|
|
413
399
|
// but only when a skill has explicitly started it (TDD, or the SDD
|
|
414
400
|
// execution preamble). The tracker never *fabricates* implement from task activity:
|
|
@@ -630,15 +616,16 @@ export default function (pi: ExtensionAPI) {
|
|
|
630
616
|
|
|
631
617
|
const warnings: string[] = [];
|
|
632
618
|
|
|
633
|
-
// Guard 2
|
|
619
|
+
// Guard 2 - branch op in the primary checkout (brainstorm/plan/implement). The target
|
|
620
|
+
// is the command's own -C / leading-cd dir, else the session cwd; a linked worktree
|
|
621
|
+
// target passes, an unresolvable one passes (the guard protects the primary only).
|
|
634
622
|
const gphase = activeGuardPhase();
|
|
635
|
-
if (
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
return { block: true, reason: branchBlockReason(gphase) };
|
|
623
|
+
if (gphase && !GIT_WORKTREE.test(command)) {
|
|
624
|
+
const form = parseGitCommand(command, SWITCH_SUB) ?? parseGitCommand(command, CHECKOUT_BRANCH_SUB);
|
|
625
|
+
if (form) {
|
|
626
|
+
const target = resolveRepoDir(form, ctx.cwd);
|
|
627
|
+
if ((await checkoutOf(target, gitSync))?.isPrimary === true) return { block: true, reason: branchBlockReason(gphase) };
|
|
628
|
+
}
|
|
642
629
|
}
|
|
643
630
|
|
|
644
631
|
// Marker commit guard — the context draft (brainstorming gather step) must be
|
|
@@ -805,6 +792,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
805
792
|
} catch {
|
|
806
793
|
return fail([{ check: "input", line: 0, text: "", reason: `plan file unreadable at ${planAbs}` }], planAbs);
|
|
807
794
|
}
|
|
795
|
+
const root = (await checkoutOf(planAbs, gitSync))?.toplevel;
|
|
796
|
+
if (!root) {
|
|
797
|
+
return fail([{ check: "input", line: 0, text: "", reason: "plan is not inside a git checkout" }], planAbs);
|
|
798
|
+
}
|
|
808
799
|
const planText = planBytes.toString("utf8");
|
|
809
800
|
const planLines = planText.split("\n");
|
|
810
801
|
const planSeparatorIdx = planLines.findIndex((l) => l.trim() === "---");
|
|
@@ -820,7 +811,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
820
811
|
planAbs,
|
|
821
812
|
);
|
|
822
813
|
}
|
|
823
|
-
const specAbs = isAbsolute(specPathRaw) ? specPathRaw : resolve(
|
|
814
|
+
const specAbs = isAbsolute(specPathRaw) ? specPathRaw : resolve(root, specPathRaw);
|
|
824
815
|
let specBytes: Buffer;
|
|
825
816
|
try {
|
|
826
817
|
specBytes = readFileBytes(specAbs);
|
|
@@ -829,8 +820,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
829
820
|
}
|
|
830
821
|
const specText = specBytes.toString("utf8");
|
|
831
822
|
const port: FsPort = {
|
|
832
|
-
exists: (p) => existsSync(resolve(
|
|
833
|
-
glob: (pattern) => globSync(pattern, { cwd:
|
|
823
|
+
exists: (p) => existsSync(resolve(root, p)),
|
|
824
|
+
glob: (pattern) => globSync(pattern, { cwd: root }),
|
|
834
825
|
};
|
|
835
826
|
const findings = checkPlan(planText, specText, port);
|
|
836
827
|
if (findings.length > 0) return fail(findings, planAbs);
|
|
@@ -20,13 +20,15 @@
|
|
|
20
20
|
|
|
21
21
|
type Handler = (event: any, ctx: any) => unknown;
|
|
22
22
|
|
|
23
|
-
function harness(o: { branch?: unknown[]; enabled?: boolean; gitFail?: (args: string[]) => GitResult | undefined; cwdSub?: string; sessionId?: string; model?: { provider: string; id: string }; thinkingLevel?: string; contextTokens?: number | null; telemetryWarning?: string; telemetryDir?: string } = {}) {
|
|
23
|
+
function harness(o: { branch?: unknown[]; enabled?: boolean; gitFail?: (args: string[], cwd: string) => GitResult | undefined; cwdSub?: string; sessionId?: string; model?: { provider: string; id: string }; thinkingLevel?: string; contextTokens?: number | null; telemetryWarning?: string; telemetryDir?: string } = {}) {
|
|
24
24
|
const root = mkdtempSync(join(tmpdir(), "telemetry-test-"));
|
|
25
25
|
tempDirs.push(root);
|
|
26
26
|
mkdirSync(join(root, "doc/specs"), { recursive: true });
|
|
27
27
|
mkdirSync(join(root, "doc/plans"), { recursive: true });
|
|
28
|
+
mkdirSync(join(root, ".worktrees/x/doc/specs"), { recursive: true });
|
|
28
29
|
const handlers = new Map<string, Handler[]>();
|
|
29
30
|
const gitCalls: string[][] = [];
|
|
31
|
+
const gitCwds: string[] = [];
|
|
30
32
|
const readFileCalls: string[] = [];
|
|
31
33
|
let clock = Date.parse("2026-09-17T10:00:00Z");
|
|
32
34
|
const deps: Deps = {
|
|
@@ -34,11 +36,15 @@
|
|
|
34
36
|
now: () => new Date((clock += 1000)).toISOString().replace(/\.\d{3}Z$/, "Z"),
|
|
35
37
|
git: async (args, cwd) => {
|
|
36
38
|
gitCalls.push(args);
|
|
37
|
-
|
|
39
|
+
gitCwds.push(cwd);
|
|
40
|
+
const forced = o.gitFail?.(args, cwd);
|
|
38
41
|
if (forced) return forced;
|
|
39
|
-
if (args[0] === "rev-parse" && args.includes("--
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
+
if (args[0] === "rev-parse" && args.includes("--path-format=absolute")) {
|
|
43
|
+
const wt = /^(.*\/\.worktrees\/[^/]+)(\/|$)/.exec(cwd)?.[1];
|
|
44
|
+
const primary = cwd === root || cwd.startsWith(root + "/") ? root : cwd.replace(/\/(?:doc|\.pi)(?:\/.*)?$/, "");
|
|
45
|
+
const toplevel = wt ?? primary;
|
|
46
|
+
const gitDir = wt ? `${primary}/.git/worktrees/${wt.split("/").pop()}` : `${primary}/.git`;
|
|
47
|
+
return { code: 0, stdout: `${toplevel}\n${gitDir}\n${primary}/.git\n`, stderr: "" };
|
|
42
48
|
}
|
|
43
49
|
if (args[0] === "rev-parse" && args.includes("--abbrev-ref")) return { code: 0, stdout: "gh-33\n", stderr: "" };
|
|
44
50
|
if (args[0] === "config") return { code: 0, stdout: (args[1] === "user.name" ? "Tester" : "t@example.com") + "\n", stderr: "" };
|
|
@@ -71,7 +77,7 @@
|
|
|
71
77
|
await emit("tool_call", { toolName: "write", toolCallId: "w", input: { path: rel, content: body } });
|
|
72
78
|
return emit("tool_result", { toolName: "write", toolCallId: "w", input: { path: rel, content: body }, content: [], isError: false, details: undefined });
|
|
73
79
|
};
|
|
74
|
-
return { root, handlers, emit, gitCalls, readFileCalls, commits, recordPath, readRecord, phaseResult, writeSpec, setBranch: (b: unknown[]) => (branch = b), ctx };
|
|
80
|
+
return { root, handlers, emit, gitCalls, gitCwds, readFileCalls, commits, recordPath, readRecord, phaseResult, writeSpec, setBranch: (b: unknown[]) => (branch = b), ctx };
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
const P = (over: Record<string, string> = {}) => Object.fromEntries(["brainstorm", "plan", "implement", "verify", "ship"].map((p) => [p, { status: over[p] ?? "pending" }]));
|
|
@@ -265,12 +271,47 @@
|
|
|
265
271
|
fail = false;
|
|
266
272
|
await h.phaseResult("complete", P({ brainstorm: "complete" }));
|
|
267
273
|
assert.equal(h.commits().length, 2);
|
|
268
|
-
const
|
|
274
|
+
const outside = mkdtempSync(join(tmpdir(), "telemetry-outside-"));
|
|
275
|
+
tempDirs.push(outside);
|
|
276
|
+
const outsideSpec = join(outside, "doc/specs/outside.md");
|
|
277
|
+
const nogit = harness({ gitFail: (args, cwd) => (args[0] === "rev-parse" && cwd.startsWith(outside) ? { code: 128, stdout: "", stderr: "fatal: not a git repository" } : undefined) });
|
|
269
278
|
await nogit.phaseResult("start", P({ brainstorm: "in_progress" }));
|
|
279
|
+
await nogit.emit("tool_result", { toolName: "write", toolCallId: "outside", input: { path: outsideSpec }, content: [], isError: false, details: undefined });
|
|
270
280
|
await nogit.writeSpec("doc/specs/a.md");
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
281
|
+
assert.deepEqual(nogit.readRecord().events.filter((e) => e.kind === "warning").map((e: any) => e.message), [`spec ${outsideSpec} is outside a git checkout; telemetry not recorded`]);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
test("worktree spec from a primary cwd: record keyed under the worktree, committed there (AC 8)", async () => {
|
|
285
|
+
const h = harness();
|
|
286
|
+
await h.emit("session_start", { type: "session_start", reason: "startup" });
|
|
287
|
+
await h.phaseResult("start", P({ brainstorm: "in_progress" }));
|
|
288
|
+
await h.writeSpec(".worktrees/x/doc/specs/a.md");
|
|
289
|
+
const wt = join(h.root, ".worktrees/x");
|
|
290
|
+
assert.ok(existsSync(join(wt, ".pi/gauntlet/telemetry/doc/specs/a.yaml")), "record lives under the worktree toplevel");
|
|
291
|
+
assert.equal(existsSync(join(h.root, ".pi/gauntlet")), false, "nothing written under the primary checkout");
|
|
292
|
+
assert.ok(h.gitCwds.every((c) => c === wt || c.startsWith(wt + "/")), "no git call runs in the primary");
|
|
293
|
+
const commitIdx = h.gitCalls.findIndex((a) => a[0] === "commit");
|
|
294
|
+
assert.ok(commitIdx >= 0);
|
|
295
|
+
assert.equal(h.gitCwds[commitIdx], wt);
|
|
296
|
+
assert.deepEqual(h.gitCalls[commitIdx].slice(-1), [".pi/gauntlet/telemetry/doc/specs/a.yaml"]);
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
test("a spec in another checkout is a fresh bind, never a git mv", async () => {
|
|
300
|
+
for (const tool of ["write", "edit"] as const) {
|
|
301
|
+
const h = harness();
|
|
302
|
+
await h.phaseResult("start", P({ brainstorm: "in_progress" }));
|
|
303
|
+
await h.writeSpec(".worktrees/x/doc/specs/a.md", "# CONTEXT DRAFT - NOT A SPEC - fully replaced at spec-writing\n");
|
|
304
|
+
if (tool === "write") {
|
|
305
|
+
await h.writeSpec("doc/specs/a.md");
|
|
306
|
+
} else {
|
|
307
|
+
writeFileSync(join(h.root, "doc/specs/a.md"), "# Spec\n");
|
|
308
|
+
await h.emit("tool_result", { toolName: "edit", toolCallId: "e", input: { path: "doc/specs/a.md", oldText: "# Old\n", newText: "# Spec\n" }, content: [], isError: false, details: undefined });
|
|
309
|
+
}
|
|
310
|
+
assert.ok(existsSync(h.recordPath("doc/specs/a.md")), `primary record created for ${tool}`);
|
|
311
|
+
assert.ok(existsSync(join(h.root, ".worktrees/x/.pi/gauntlet/telemetry/doc/specs/a.yaml")), `worktree record left in place for ${tool}`);
|
|
312
|
+
assert.equal(h.gitCalls.some((a) => a[0] === "mv"), false);
|
|
313
|
+
assert.equal(h.readRecord("doc/specs/a.md").events.some((e) => e.kind === "spec_renamed"), false);
|
|
314
|
+
}
|
|
274
315
|
});
|
|
275
316
|
|
|
276
317
|
test("second session rehydrates all derived accumulators with exactly total and live blocks", async () => {
|
package/extensions/telemetry.ts
CHANGED
|
@@ -9,12 +9,13 @@
|
|
|
9
9
|
import { execFile } from "node:child_process";
|
|
10
10
|
import { randomUUID } from "node:crypto";
|
|
11
11
|
import * as nodeFs from "node:fs";
|
|
12
|
-
import { dirname, join, posix } from "node:path";
|
|
12
|
+
import { dirname, isAbsolute, join, posix, resolve } from "node:path";
|
|
13
13
|
import * as piRuntime from "@earendil-works/pi-coding-agent";
|
|
14
14
|
import { SettingsManager, getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
15
15
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
16
16
|
import { DEFAULT_TEST_COMMANDS, resolveTelemetry, settingsErrorWarning, type TelemetryResolved } from "./lib/gauntlet-settings.ts";
|
|
17
17
|
import { loadGauntletSettings } from "./lib/gauntlet-settings-loader.ts";
|
|
18
|
+
import { checkoutOf } from "./lib/checkout.ts";
|
|
18
19
|
import { CONTEXT_DRAFT_MARKER } from "./lib/phase-tracker-helpers.ts";
|
|
19
20
|
import { sha256 } from "./lib/plan-check.ts";
|
|
20
21
|
import { SUPERSEDED_BY_RE, aggregateNumstat, isPlanPath, isSpecPath, isSupersededByBanner, matchDiscardStatement, matchShipStatement, matchTestStatement, parseSpecLinks, planSpecHeader, recordPathFor, repoRelativeToolPath, toPosix, truncateCommand } from "./lib/telemetry-paths.ts";
|
|
@@ -100,9 +101,9 @@
|
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
function realSettings(cwd: string): SettingsSnapshot {
|
|
103
|
-
const { gauntlet, errors } = loadGauntletSettings(cwd);
|
|
104
|
+
const { gauntlet, errors, root } = loadGauntletSettings(cwd);
|
|
104
105
|
const telemetry = resolveTelemetry(gauntlet);
|
|
105
|
-
const sm = SettingsManager.create(
|
|
106
|
+
const sm = SettingsManager.create(root, getAgentDir());
|
|
106
107
|
const layer = (s: unknown) => ((s as { subagents?: { agentOverrides?: unknown } })?.subagents?.agentOverrides ?? undefined) as Record<string, unknown> | undefined;
|
|
107
108
|
const preset = layer(sm.getGlobalSettings());
|
|
108
109
|
const repo = layer(sm.getProjectSettings());
|
|
@@ -158,8 +159,7 @@
|
|
|
158
159
|
|
|
159
160
|
export default function (pi: ExtensionAPI, deps: Deps = realDeps) {
|
|
160
161
|
let phases: PhaseMap = emptyPhases();
|
|
161
|
-
let toplevel: string | undefined;
|
|
162
|
-
let inGit = false;
|
|
162
|
+
let toplevel: string | undefined; // toplevel of the bound record's checkout; undefined until bind
|
|
163
163
|
let boundSpec: string | undefined; // repo-relative
|
|
164
164
|
let record: TelemetryRecord | undefined;
|
|
165
165
|
const predecessorLinks = new Set<string>();
|
|
@@ -180,12 +180,13 @@
|
|
|
180
180
|
return s;
|
|
181
181
|
};
|
|
182
182
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
183
|
+
// Resolves a tool path (relative to ctx.cwd or absolute) to its owning checkout and
|
|
184
|
+
// checkout-relative key. undefined outside any checkout.
|
|
185
|
+
const locate = async (ctx: ExtensionContext, p: string): Promise<{ toplevel: string; rel: string } | undefined> => {
|
|
186
|
+
const candidateAbs = isAbsolute(p) ? p : resolve(ctx.cwd, p);
|
|
187
|
+
const co = await checkoutOf(candidateAbs, deps.git);
|
|
188
|
+
const rel = co ? repoRelativeToolPath(co.toplevel, ctx.cwd, p) : undefined;
|
|
189
|
+
return co && rel ? { toplevel: co.toplevel, rel } : undefined;
|
|
189
190
|
};
|
|
190
191
|
|
|
191
192
|
const live = (): Accumulators => record
|
|
@@ -228,7 +229,7 @@
|
|
|
228
229
|
};
|
|
229
230
|
|
|
230
231
|
const commitRecord = async () => {
|
|
231
|
-
if (!record || !recordRel || frozen || !
|
|
232
|
+
if (!record || !recordRel || frozen || !toplevel) return;
|
|
232
233
|
const text = deps.fs.readFile(abs(recordRel)) ?? "";
|
|
233
234
|
if (text === lastCommitted) return;
|
|
234
235
|
const paths = [recordRel, ...(oldRecordRel ? [oldRecordRel] : [])];
|
|
@@ -273,7 +274,8 @@
|
|
|
273
274
|
return newRecord({ spec: specRel, session: sessionId, now: buffer[0]?.ts ?? deps.now(), runId: randomUUID() });
|
|
274
275
|
};
|
|
275
276
|
|
|
276
|
-
const bind = async (specRel: string, snap: SettingsSnapshot) => {
|
|
277
|
+
const bind = async (specRel: string, snap: SettingsSnapshot, specToplevel: string) => {
|
|
278
|
+
toplevel = specToplevel;
|
|
277
279
|
currentDir = snap.telemetry.dir;
|
|
278
280
|
boundSpec = specRel;
|
|
279
281
|
recordRel = recordPathFor(currentDir, specRel);
|
|
@@ -302,7 +304,6 @@
|
|
|
302
304
|
const approval = record.events.find((e) => e.kind === "phase" && e.name === "brainstorm" && (e.action === "complete" || e.action === "skip"));
|
|
303
305
|
if (approval) record.approved_at ??= approval.ts;
|
|
304
306
|
buffer = [];
|
|
305
|
-
if (!inGit) warn("not a git repository: record is written but never committed");
|
|
306
307
|
if (!settingsWarned && (snap.errors.length || snap.telemetry.warning)) {
|
|
307
308
|
settingsWarned = true;
|
|
308
309
|
if (snap.errors.length) warn(settingsErrorWarning(snap.errors));
|
|
@@ -312,6 +313,7 @@
|
|
|
312
313
|
};
|
|
313
314
|
|
|
314
315
|
const unbind = () => {
|
|
316
|
+
toplevel = undefined;
|
|
315
317
|
boundSpec = undefined;
|
|
316
318
|
record = undefined;
|
|
317
319
|
recordRel = undefined;
|
|
@@ -347,8 +349,8 @@
|
|
|
347
349
|
warn(`record move skipped: ${to} already exists`);
|
|
348
350
|
return false;
|
|
349
351
|
}
|
|
350
|
-
const trackedResult =
|
|
351
|
-
const tracked = trackedResult
|
|
352
|
+
const trackedResult = await deps.git(["ls-files", "--error-unmatch", "--", from], toplevel!);
|
|
353
|
+
const tracked = trackedResult.code === 0 && trackedResult.stdout.trim() !== "";
|
|
352
354
|
try {
|
|
353
355
|
deps.fs.mkdirp(dirname(abs(to)));
|
|
354
356
|
if (tracked) {
|
|
@@ -408,14 +410,13 @@
|
|
|
408
410
|
const snap = enabledSettings(ctx);
|
|
409
411
|
if (!snap) return;
|
|
410
412
|
sessionId = ctx.sessionManager.getSessionId();
|
|
411
|
-
await ensureToplevel(ctx);
|
|
412
413
|
currentDir = snap.telemetry.dir;
|
|
413
414
|
const replay = replayBranch(ctx.sessionManager.getBranch());
|
|
414
415
|
phases = replay.phases;
|
|
415
416
|
const candidate = replay.planCheckSpec ?? replay.lastSpecWrite;
|
|
416
|
-
const
|
|
417
|
-
if (
|
|
418
|
-
await bind(rel, snap);
|
|
417
|
+
const loc = candidate ? await locate(ctx, candidate) : undefined;
|
|
418
|
+
if (loc && isSpecPath(loc.rel)) {
|
|
419
|
+
await bind(loc.rel, snap, loc.toplevel);
|
|
419
420
|
await flush(false);
|
|
420
421
|
}
|
|
421
422
|
});
|
|
@@ -436,19 +437,20 @@
|
|
|
436
437
|
const snap = enabledSettings(ctx);
|
|
437
438
|
if (!snap) return undefined;
|
|
438
439
|
if (!sessionId) sessionId = ctx.sessionManager.getSessionId();
|
|
439
|
-
await ensureToplevel(ctx);
|
|
440
440
|
if (event.toolName === "phase_tracker" && !event.isError) {
|
|
441
441
|
await applyPhaseDetails(event.details as never, snap);
|
|
442
442
|
return undefined;
|
|
443
443
|
}
|
|
444
444
|
if (event.toolName === "plan_check" && !event.isError) {
|
|
445
445
|
const d = event.details as { status?: string; specPath?: string; planPath?: string } | undefined;
|
|
446
|
-
const
|
|
447
|
-
const
|
|
446
|
+
const specLoc = d?.specPath ? await locate(ctx, d.specPath) : undefined;
|
|
447
|
+
const planLoc = d?.planPath ? await locate(ctx, d.planPath) : undefined;
|
|
448
|
+
const spec = specLoc?.rel;
|
|
449
|
+
const plan = planLoc?.rel;
|
|
448
450
|
const pass = d?.status === "pass";
|
|
449
|
-
if (pass &&
|
|
451
|
+
if (pass && specLoc && (specLoc.rel !== boundSpec || specLoc.toplevel !== toplevel)) {
|
|
450
452
|
if (record) unbind();
|
|
451
|
-
await bind(
|
|
453
|
+
await bind(specLoc.rel, snap, specLoc.toplevel);
|
|
452
454
|
}
|
|
453
455
|
live().gates.plan_rounds += 1;
|
|
454
456
|
pushEvent({ kind: "plan_check", pass, spec, plan });
|
|
@@ -457,9 +459,12 @@
|
|
|
457
459
|
}
|
|
458
460
|
if ((event.toolName === "write" || event.toolName === "edit" || event.toolName === "read") && !event.isError) {
|
|
459
461
|
const rawPath = (event.input as { path?: unknown }).path;
|
|
460
|
-
const
|
|
461
|
-
if (!
|
|
462
|
-
|
|
462
|
+
const loc = typeof rawPath === "string" ? await locate(ctx, rawPath) : undefined;
|
|
463
|
+
if (!loc) {
|
|
464
|
+
if (typeof rawPath === "string" && isSpecPath(toPosix(rawPath))) warn(`spec ${rawPath} is outside a git checkout; telemetry not recorded`);
|
|
465
|
+
return undefined;
|
|
466
|
+
}
|
|
467
|
+
return onSpecInteraction(event.toolName, loc, event, snap);
|
|
463
468
|
}
|
|
464
469
|
if (event.toolName === "subagent" && !event.isError) {
|
|
465
470
|
await onSubagentResult(event.details, event.content);
|
|
@@ -493,23 +498,35 @@
|
|
|
493
498
|
});
|
|
494
499
|
|
|
495
500
|
// Binding + spec-write bookkeeping; the bound-spec hooks are defined in block 2.
|
|
496
|
-
const onSpecInteraction = async (tool: "write" | "edit" | "read", rel: string, event: { input: unknown; content: unknown[] }, snap: SettingsSnapshot): Promise<unknown> => {
|
|
501
|
+
const onSpecInteraction = async (tool: "write" | "edit" | "read", loc: { toplevel: string; rel: string }, event: { input: unknown; content: unknown[] }, snap: SettingsSnapshot): Promise<unknown> => {
|
|
502
|
+
const rel = loc.rel;
|
|
497
503
|
if (!boundSpec) {
|
|
498
504
|
if ((tool === "write" || tool === "edit") && isSpecPath(rel)) {
|
|
499
|
-
await bind(rel, snap);
|
|
505
|
+
await bind(rel, snap, loc.toplevel);
|
|
500
506
|
const patch = onBoundSpecWrite(tool, rel, event);
|
|
501
507
|
await flush(true);
|
|
502
508
|
return patch;
|
|
503
509
|
} else if (isPlanPath(rel)) {
|
|
504
|
-
const spec = planSpecHeader(deps.fs.readFile(
|
|
505
|
-
const specRel = spec ? repoRelativeToolPath(toplevel
|
|
506
|
-
if (specRel && deps.fs.exists(
|
|
507
|
-
await bind(specRel, snap);
|
|
510
|
+
const spec = planSpecHeader(deps.fs.readFile(join(loc.toplevel, rel)) ?? "");
|
|
511
|
+
const specRel = spec ? repoRelativeToolPath(loc.toplevel, loc.toplevel, spec) : undefined;
|
|
512
|
+
if (specRel && deps.fs.exists(join(loc.toplevel, specRel))) {
|
|
513
|
+
await bind(specRel, snap, loc.toplevel);
|
|
508
514
|
await flush(true);
|
|
509
515
|
}
|
|
510
516
|
}
|
|
511
517
|
return undefined;
|
|
512
518
|
}
|
|
519
|
+
if (loc.toplevel !== toplevel) {
|
|
520
|
+
// Another checkout: a fresh run, never a rename of this record.
|
|
521
|
+
if ((tool === "write" || tool === "edit") && isSpecPath(rel)) {
|
|
522
|
+
unbind();
|
|
523
|
+
await bind(rel, snap, loc.toplevel);
|
|
524
|
+
const patch = onBoundSpecWrite(tool, rel, event);
|
|
525
|
+
await flush(true);
|
|
526
|
+
return patch;
|
|
527
|
+
}
|
|
528
|
+
return undefined;
|
|
529
|
+
}
|
|
513
530
|
if (tool === "read") return undefined;
|
|
514
531
|
if (rel === boundSpec) {
|
|
515
532
|
const patch = onBoundSpecWrite(tool, rel, event);
|
|
@@ -603,7 +620,7 @@
|
|
|
603
620
|
let pendingShip: { id: string; option: "squash" | "pr" | "discard" } | undefined;
|
|
604
621
|
|
|
605
622
|
const computeDiff = async (snap: SettingsSnapshot) => {
|
|
606
|
-
if (!record || !
|
|
623
|
+
if (!record || !toplevel) return;
|
|
607
624
|
let baseRef: string | undefined;
|
|
608
625
|
for (const ref of BASE_REFS) {
|
|
609
626
|
if ((await deps.git(["rev-parse", "--verify", "--quiet", ref], toplevel!)).code === 0) {
|
|
@@ -665,13 +682,12 @@
|
|
|
665
682
|
if (event.toolName === "write") {
|
|
666
683
|
const rawPath = (event.input as { path?: unknown }).path;
|
|
667
684
|
if (typeof rawPath === "string" && phases.brainstorm.status === "in_progress") {
|
|
668
|
-
await
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
const
|
|
672
|
-
const existing = deps.fs.readFile(join(toplevel!, recRel));
|
|
685
|
+
const loc = await locate(ctx, rawPath);
|
|
686
|
+
if (loc && isSpecPath(loc.rel)) {
|
|
687
|
+
const recRel = recordPathFor(snap.telemetry.dir, loc.rel);
|
|
688
|
+
const existing = deps.fs.readFile(join(loc.toplevel, recRel));
|
|
673
689
|
const parsed = existing ? parseRecord(existing) : undefined;
|
|
674
|
-
if (parsed?.shipped_at) return { block: true, reason: guardReason(rel, parsed.shipped_at, recRel) };
|
|
690
|
+
if (parsed?.shipped_at) return { block: true, reason: guardReason(loc.rel, parsed.shipped_at, recRel) };
|
|
675
691
|
}
|
|
676
692
|
}
|
|
677
693
|
return undefined;
|
|
@@ -72,6 +72,22 @@ test("gh pr create warns when unverified", async () => {
|
|
|
72
72
|
assert.match(warning ?? "", /ran without verification/);
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
+
test("git -C <worktree> push and merge --squash are ship events (AC 5)", async () => {
|
|
76
|
+
for (const cmd of ["git -C /p push -u origin HEAD", "git -C /p merge --squash f"]) {
|
|
77
|
+
const h = harness();
|
|
78
|
+
await editSource(h);
|
|
79
|
+
await h.emitEvent("tool_call", bashCall("s1", cmd));
|
|
80
|
+
assert.match(warningOf(await h.emitEvent("tool_result", bashResult("s1"))) ?? "", /ran without verification/, cmd);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("a quoted mention of git push is not a ship event", async () => {
|
|
85
|
+
const h = harness();
|
|
86
|
+
await editSource(h);
|
|
87
|
+
await h.emitEvent("tool_call", bashCall("q1", 'rg "git push" skills/'));
|
|
88
|
+
assert.equal((await h.emitEvent("tool_result", bashResult("q1")))[0], undefined);
|
|
89
|
+
});
|
|
90
|
+
|
|
75
91
|
test("a passing recognised run clears the warning for push", async () => {
|
|
76
92
|
const h = harness();
|
|
77
93
|
await editSource(h);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Verify-before-ship extension
|
|
3
3
|
*
|
|
4
|
-
* Single-session verification gate for shipping commands
|
|
4
|
+
* Single-session verification gate for statement-start shipping commands: git merge
|
|
5
|
+
* --squash, git push, and gh pr create (with any git global flags).
|
|
5
6
|
* Local commits are not ship events; commit-time review-cadence advisories live in
|
|
6
7
|
* phase-tracker. Tracks whether a recognised verification command has succeeded
|
|
7
8
|
* since the last source-file write; injects an advisory warning into the tool
|
|
@@ -32,8 +33,7 @@ import {
|
|
|
32
33
|
settingsErrorWarning,
|
|
33
34
|
} from "./lib/gauntlet-settings.ts";
|
|
34
35
|
import { loadGauntletSettings } from "./lib/gauntlet-settings-loader.ts";
|
|
35
|
-
|
|
36
|
-
const SHIP_CMD = /\b(git\s+push|gh\s+pr\s+create)\b/;
|
|
36
|
+
import { matchShipStatement } from "./lib/telemetry-paths.ts";
|
|
37
37
|
|
|
38
38
|
const SOURCE_EXT = /\.(ts|tsx|js|jsx|py|rb|go|rs|java|swift|kt)$/;
|
|
39
39
|
const TEST_PATH = /(^|\/)(tests?|__tests__)\/|\.(test|spec)\.|_test\.(py|go|rb)$/;
|
|
@@ -101,7 +101,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
101
101
|
return undefined;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
if (
|
|
104
|
+
if (matchShipStatement(command) && !verified) {
|
|
105
105
|
if (settingsWarned && !settingsErrShown) {
|
|
106
106
|
addShipWarning(event.toolCallId, settingsWarned);
|
|
107
107
|
settingsErrShown = true;
|
package/package.json
CHANGED
|
@@ -92,8 +92,8 @@ If the project's `AGENTS.md` calls out additional reading for a specific area (e
|
|
|
92
92
|
The spec is the **first commit in a dedicated worktree**, not a separate commit on `main`. Before drafting any spec content:
|
|
93
93
|
|
|
94
94
|
1. Invoke `/skill:using-git-worktrees`. Worktrees live under `.worktrees/` at the repo root, or wherever a project-native worktree script places them.
|
|
95
|
-
2.
|
|
96
|
-
3.
|
|
95
|
+
2. Carry the worktree path from the `using-git-worktrees` Step 4 report (`Worktree ready at <full-path>`) as a value: the spec path is `<full-path>/doc/specs/<filename>.md`, every dispatch below sets `cwd: "<full-path>"`, and git runs as `git -C <full-path> ...`. The process cwd stays where pi was launched.
|
|
96
|
+
3. Write the spec at that path, run self-review, commit with `git -C <full-path>`, hand off.
|
|
97
97
|
|
|
98
98
|
Spec doc, plan doc, and implementation are all developed in the same worktree; the squash ships the spec and the implementation, with the ephemeral plan stripped before landing (see `/skill:finishing-a-development-branch`).
|
|
99
99
|
|
|
@@ -103,6 +103,8 @@ Spec doc, plan doc, and implementation are all developed in the same worktree; t
|
|
|
103
103
|
|
|
104
104
|
### 1. Check git state
|
|
105
105
|
|
|
106
|
+
Check git state in the primary checkout (the process cwd; no worktree exists yet):
|
|
107
|
+
|
|
106
108
|
```bash
|
|
107
109
|
git status
|
|
108
110
|
git --no-pager log --oneline -5
|
|
@@ -271,7 +273,7 @@ The first three checks — **placeholder scan**, **internal consistency**, and *
|
|
|
271
273
|
- **Otherwise** → dispatch one fresh `worker` that applies the scope + ambiguity checks and fixes them in place:
|
|
272
274
|
|
|
273
275
|
```
|
|
274
|
-
subagent({ agent: "worker", context: "fresh", async: false, cwd: "<abs worktree path, from
|
|
276
|
+
subagent({ agent: "worker", context: "fresh", async: false, cwd: "<abs worktree path, from the using-git-worktrees Step 4 report>", task:
|
|
275
277
|
"Problem statement: <the problem the spec addresses + the user's stated intent>.\n" +
|
|
276
278
|
"Read the spec at <abs path to doc/specs/...>. Edit ONLY that file. Apply two checks and\n" +
|
|
277
279
|
"fix what you find in place: (1) Scope — does every paragraph serve the goal? Cut filler;\n" +
|
|
@@ -302,7 +304,7 @@ SUMMARY_PATH=$(mktemp "${TMPDIR:-/tmp}/gauntlet-spec-summary.XXXXXX") # absolu
|
|
|
302
304
|
```
|
|
303
305
|
|
|
304
306
|
```
|
|
305
|
-
subagent({ agent: "spec-summarizer", context: "fresh", async: false, cwd: "<abs worktree path, from
|
|
307
|
+
subagent({ agent: "spec-summarizer", context: "fresh", async: false, cwd: "<abs worktree path, from the using-git-worktrees Step 4 report>",
|
|
306
308
|
output: "<SUMMARY_PATH>", outputMode: "file-only", task:
|
|
307
309
|
"Summarize the spec at <abs path to doc/specs/...> for the user review gate. Read ONLY that file." })
|
|
308
310
|
```
|
|
@@ -354,7 +356,7 @@ phase_tracker({ action: "complete", phase: "brainstorm" })
|
|
|
354
356
|
|
|
355
357
|
Execute this section in place from any later phase. Do not invoke `/skill:brainstorming` (its entry resets both trackers). Worktree, spec commits, and plan survive.
|
|
356
358
|
|
|
357
|
-
1. Edit the spec. Show `git --no-pager diff -- <spec path>` and one line of impact (affected plan tasks / waves, or "no plan yet").
|
|
359
|
+
1. Edit the spec. Show `git -C <abs worktree path> --no-pager diff -- <spec path>` and one line of impact (affected plan tasks / waves, or "no plan yet").
|
|
358
360
|
2. Wait for approval. Change request -> revise, re-show.
|
|
359
361
|
3. No plan yet -> commit the spec; continue. Plan exists -> update affected anchors and tasks: `plan_tracker` `add` for new tasks; anchor-changed completed tasks are reopened as `in_progress` and re-run the task loop (`update` never sets `pending`). A removed task is deleted from the plan; then re-`init` the tracker with `{ name, status }` elements: preserved tasks keep their order and statuses, reopened tasks are `in_progress` in place, every still-`pending` task (including newly added ones, whatever wave label they carry) trails the non-pending ones, removed tasks are the only deletions (the only permitted `init` after handoff; never `clear`). Re-run `plan_check` until it passes, commit spec + plan together; continue. A task reopened while `verify` or `ship` is in progress: `phase_tracker({ action: "skip", phase: "<current>", reason: "amendment reopened Task N" })`, then `phase_tracker({ action: "start", phase: "implement", force: true })`; later phases re-enter with `force: true` and rerun in full.
|
|
360
362
|
|