pi-dev-flow 0.78.0 → 0.79.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,13 @@ Format: newest first. `Unreleased` collects what's merged but not yet tagged.
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.79.0] - 2026-11-03
|
|
8
|
+
|
|
9
|
+
**Scratch files live in the feature folder and go away at finish.**
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
- **Scratch files now go in the feature folder, not `/tmp`.** A bound session's bash calls, and every project command a gate runs (`flow test`, checks, build, dev, seed, health), now run with `TMPDIR` set to `.dev-flow/<slug>/tmp/`. Throwaway scripts, `mktemp` output and test fixtures created with `os.tmpdir()` (the smoke suite alone makes about 40 per run) land there instead of piling up in the OS temp dir. `flow finish` removes the folder with the feature, and `flow abort` drops it when it unbinds. The prefix goes on after the guards have judged the command, so no guard ever sees it. Unbound sessions are unchanged.
|
|
13
|
+
|
|
7
14
|
## [0.78.0] - 2026-11-03
|
|
8
15
|
|
|
9
16
|
**`flow init` asks better questions and writes your answers itself.**
|
package/docs/guardrails.md
CHANGED
|
@@ -6,7 +6,7 @@ While a feature is active, the extension intercepts every tool call:
|
|
|
6
6
|
|
|
7
7
|
- **Nothing on main, ever** (until release): `git commit` on the default branch is blocked at every stage except `release` — where release chores commit in the main checkout (prefixed `DEV_FLOW_ALLOW_MAIN=1` for the hook) — and except one chore that needs no flow: a commit whose **only** change in the checkout is `.dev-flow/project.md`, because tracking the operator's playbook is setup, not feature work (any other dirty path closes that lane). pushes are judged by the ref they write — only pushing *to* the default branch (or a bare push while on it) requires stage `release`, so tag pushes and feature-branch pushes pass from any stage; `git merge` onto the default branch also requires stage `release`. Plus the standalone pre-commit hook for commits made outside Pi.
|
|
8
8
|
- **No code before an approved plan**: at stage `plan`, edits are confined to `.dev-flow/<slug>/` — the session's **own** feature directory, so one session cannot write another feature's plan and have its gate rubber-stamp what it never wrote.
|
|
9
|
-
- **Work stays in the worktree**: at stages `implement` and `pre-release`, edits are confined to that feature's worktree — judged per-path by the owning feature, so one session can never write into another session's worktree or into the main checkout. A throwaway **outside** the checkout is not feature work and stays free at every stage (the OS temp dir, e.g. a one-off rewrite script): both sides are realpath'd, so a symlink out of the temp dir is still judged as the repo path it writes, and a repository that merely lives under the temp dir (a test repo) keeps the stage rules.
|
|
9
|
+
- **Work stays in the worktree**: at stages `implement` and `pre-release`, edits are confined to that feature's worktree — judged per-path by the owning feature, so one session can never write into another session's worktree or into the main checkout. A throwaway **outside** the checkout is not feature work and stays free at every stage (the OS temp dir, e.g. a one-off rewrite script): both sides are realpath'd, so a symlink out of the temp dir is still judged as the repo path it writes, and a repository that merely lives under the temp dir (a test repo) keeps the stage rules. For a bound feature that scratch lives in the feature itself: every bash call the guards let through, and every project command a gate runs (test, checks, build, dev, seed, health), gets `TMPDIR=.dev-flow/<slug>/tmp/`, so `mktemp`, `os.tmpdir()` and test-suite fixtures land there and `flow finish` (or `flow abort`) removes them. Unbound sessions keep the OS temp dir.
|
|
10
10
|
- **Shipping waits for `flow release`**: while a bound feature is at `plan`, `implement` or `pre-release`, cutting or pushing a tag (`git tag <name>`, `git push --tags`, `refs/tags/…`), merging its PR (`gh pr merge`, `glab mr merge`) and creating a forge release (`gh|glab release create`) are refused with "run flow release first". Shipping by hand first left `flow release` unable to record the release ("already tagged") and the flow unable to close. Reads (`git tag -l`, `gh pr view`) and opening the PR at pre-release are unaffected.
|
|
11
11
|
- **A feature worktree keeps its branch**: creating a branch inside a feature worktree (`git checkout -b`, `git switch -c`) is refused. An unrelated fix is its own flow (`flow start <slug> --patch --confirmed`), not a side branch in someone's worktree. A session whose cwd is a feature worktree is judged by the **main checkout's** `.dev-flow/` state, which is where the features live.
|
|
12
12
|
- **Flow by default**: in a repo with `.dev-flow/`, an unbound session cannot touch source files at all — every request goes through `flow start`/`flow use`; there is no bypass. `flow start` refuses when the main checkout isn't on the default branch, worktrees are always created from the default branch, and the agent cannot check feature branches out in the main checkout.
|
package/extensions/dev-flow.ts
CHANGED
|
@@ -25,7 +25,7 @@ import path from "node:path";
|
|
|
25
25
|
import { promisify } from "node:util";
|
|
26
26
|
import { Type } from "@earendil-works/pi-ai";
|
|
27
27
|
import { compact, createAgentSession, DefaultResourceLoader, defineTool, getAgentDir, isToolCallEventType, SessionManager, SettingsManager, type AgentSession, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
28
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
28
|
+
import type { ExtensionAPI, ToolCallEvent, ToolCallEventResult } from "@earendil-works/pi-coding-agent";
|
|
29
29
|
import {
|
|
30
30
|
ALLOW_REWRITE,
|
|
31
31
|
approveGate,
|
|
@@ -114,6 +114,8 @@ import {
|
|
|
114
114
|
statusJson,
|
|
115
115
|
subst,
|
|
116
116
|
sq,
|
|
117
|
+
featureTmpDir,
|
|
118
|
+
withTmpDir,
|
|
117
119
|
tagNotesCommand,
|
|
118
120
|
validSlug,
|
|
119
121
|
verifyGate,
|
|
@@ -228,9 +230,9 @@ const now = () => new Date().toISOString();
|
|
|
228
230
|
|
|
229
231
|
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
230
232
|
|
|
231
|
-
async function sh(command: string, cwd: string, timeoutMs = 15 * 60_000): Promise<{ ok: boolean; out: string }> {
|
|
233
|
+
async function sh(command: string, cwd: string, timeoutMs = 15 * 60_000, env?: Record<string, string>): Promise<{ ok: boolean; out: string }> {
|
|
232
234
|
try {
|
|
233
|
-
const { stdout, stderr } = await execAsync(command, { cwd, timeout: timeoutMs, maxBuffer: 16 * 1024 * 1024 });
|
|
235
|
+
const { stdout, stderr } = await execAsync(command, { cwd, timeout: timeoutMs, maxBuffer: 16 * 1024 * 1024, ...(env ? { env: { ...process.env, ...env } } : {}) });
|
|
234
236
|
return { ok: true, out: `${stdout}\n${stderr}`.trim() };
|
|
235
237
|
} catch (e) {
|
|
236
238
|
const err = e as { stdout?: string; stderr?: string; message?: string };
|
|
@@ -345,12 +347,12 @@ async function writePlaybookMergePolicy(root: string, style: string): Promise<{
|
|
|
345
347
|
* container start can never pass a single shot, and hand-writing a poll loop into every playbook was
|
|
346
348
|
* the workaround; the gate waits and says how long it tried. Attempts/schedule: core.healthRetry.
|
|
347
349
|
*/
|
|
348
|
-
async function runHealthProbe(cmd: string, cwd: string, waitSec: number): Promise<{ ok: boolean; out: string; attempts: number }> {
|
|
350
|
+
async function runHealthProbe(cmd: string, cwd: string, waitSec: number, env?: Record<string, string>): Promise<{ ok: boolean; out: string; attempts: number }> {
|
|
349
351
|
const { attempts, delayMs } = healthRetry(waitSec);
|
|
350
352
|
const deadline = Date.now() + waitSec * 1000; // the budget is wall time: a slow probe must not multiply it by its own duration
|
|
351
353
|
let res = { ok: false, out: "" };
|
|
352
354
|
for (let i = 1; ; i++) {
|
|
353
|
-
res = await sh(cmd, cwd);
|
|
355
|
+
res = await sh(cmd, cwd, undefined, env);
|
|
354
356
|
if (res.ok || i >= attempts || Date.now() >= deadline) return { ...res, attempts: i };
|
|
355
357
|
await sleep(delayMs);
|
|
356
358
|
}
|
|
@@ -603,6 +605,14 @@ function gateCwd(root: string, state: FlowState): string {
|
|
|
603
605
|
return wt && existsSync(wt) ? wt : root;
|
|
604
606
|
}
|
|
605
607
|
|
|
608
|
+
/** TMPDIR for the project commands a gate runs: the feature's own scratch dir, removed at finish —
|
|
609
|
+
* a test suite's mkdtemp fixtures no longer pile up in the OS temp dir. */
|
|
610
|
+
function featureEnv(root: string, state: FlowState): Record<string, string> {
|
|
611
|
+
const dir = featureTmpDir(dfDir(root), state.slug);
|
|
612
|
+
mkdirSync(dir, { recursive: true });
|
|
613
|
+
return { TMPDIR: dir };
|
|
614
|
+
}
|
|
615
|
+
|
|
606
616
|
/** Tier-1 checks the gate still has to see green. Entering a stage — and every edit of the worktree —
|
|
607
617
|
* clears the records, so "run flow check first" cost three round trips to say what one could (#84).
|
|
608
618
|
* `health` is left to the post-deploy probe when there is a deploy to prove: probing twice only waits twice. */
|
|
@@ -618,7 +628,7 @@ async function runChecks(root: string, state: FlowState, cfg: Config, checks: St
|
|
|
618
628
|
const ran: string[] = [];
|
|
619
629
|
for (const c of checks) {
|
|
620
630
|
// health is the same probe `flow health` runs: seeded first, retried within healthWait
|
|
621
|
-
const res = c.name === "health" ? await seededProbe(root, state, cfg, c.cmd) : await sh(c.cmd, gateCwd(root, state));
|
|
631
|
+
const res = c.name === "health" ? await seededProbe(root, state, cfg, c.cmd) : await sh(c.cmd, gateCwd(root, state), undefined, featureEnv(root, state));
|
|
622
632
|
if ("seedFail" in res) {
|
|
623
633
|
lines.push(res.seedFail.text);
|
|
624
634
|
failed = true;
|
|
@@ -643,7 +653,7 @@ const healthRerunsAfterDeploy = (cfg: Config) => !!cfg.commands.dev && !!healthP
|
|
|
643
653
|
* deploy probe both do this). Returns an error result on failure, null when seeded or not configured. */
|
|
644
654
|
async function seedStep(root: string, state: FlowState, cfg: Config): Promise<{ text: string; isError: true } | null> {
|
|
645
655
|
if (!cfg.commands.seedData) return null;
|
|
646
|
-
const seed = await sh(cfg.commands.seedData, gateCwd(root, state));
|
|
656
|
+
const seed = await sh(cfg.commands.seedData, gateCwd(root, state), undefined, featureEnv(root, state));
|
|
647
657
|
state.checks.seedData = { ok: seed.ok, at: now() };
|
|
648
658
|
writeState(root, state);
|
|
649
659
|
return seed.ok ? null : { text: `seedData FAILED (${cfg.commands.seedData}):\n${tail(seed.out)}`, isError: true };
|
|
@@ -654,7 +664,7 @@ type HealthRun = { ok: boolean; out: string; attempts: number } | { seedFail: Ru
|
|
|
654
664
|
/** Seed (when configured), then run the health probe within the playbook's wait budget. */
|
|
655
665
|
async function seededProbe(root: string, state: FlowState, cfg: Config, probe: string): Promise<HealthRun> {
|
|
656
666
|
const seedFail = await seedStep(root, state, cfg);
|
|
657
|
-
return seedFail ? { seedFail } : runHealthProbe(probe, gateCwd(root, state), cfg.healthWait);
|
|
667
|
+
return seedFail ? { seedFail } : runHealthProbe(probe, gateCwd(root, state), cfg.healthWait, featureEnv(root, state));
|
|
658
668
|
}
|
|
659
669
|
|
|
660
670
|
/** seededProbe, recorded and stamped as the `health` check — `flow health` and both verify probes. */
|
|
@@ -1055,7 +1065,7 @@ async function gateVerify(o: GateCtx): Promise<RunResult> {
|
|
|
1055
1065
|
did.push("docs mode: project commands skipped (build/dev/health)");
|
|
1056
1066
|
} else {
|
|
1057
1067
|
if (cfg.commands.build) {
|
|
1058
|
-
const res = await sh(cfg.commands.build, gateCwd(root, state!));
|
|
1068
|
+
const res = await sh(cfg.commands.build, gateCwd(root, state!), undefined, featureEnv(root, state!));
|
|
1059
1069
|
state!.checks.build = { ok: res.ok, at: now() };
|
|
1060
1070
|
writeState(root, state!);
|
|
1061
1071
|
if (!res.ok) return { text: `build FAILED (${cfg.commands.build}):\n${tail(res.out)}`, isError: true };
|
|
@@ -1064,7 +1074,7 @@ async function gateVerify(o: GateCtx): Promise<RunResult> {
|
|
|
1064
1074
|
// deploy to dev before asking — the operator reviews the running dev app, not a promise
|
|
1065
1075
|
const probe = healthProbe(cfg);
|
|
1066
1076
|
if (cfg.commands.dev) {
|
|
1067
|
-
const res = await sh(cfg.commands.dev, gateCwd(root, state!));
|
|
1077
|
+
const res = await sh(cfg.commands.dev, gateCwd(root, state!), undefined, featureEnv(root, state!));
|
|
1068
1078
|
state!.checks.dev = { ok: res.ok, at: now() };
|
|
1069
1079
|
writeState(root, state!);
|
|
1070
1080
|
if (!res.ok) return { text: `dev deploy FAILED (${cfg.commands.dev}):\n${tail(res.out)}`, isError: true };
|
|
@@ -1992,7 +2002,7 @@ async function gateTest(o: GateCtx): Promise<RunResult> {
|
|
|
1992
2002
|
const { state, err } = needState(root, sess, slugArg);
|
|
1993
2003
|
if (err) return err;
|
|
1994
2004
|
if (!cfg.commands.test) return { text: "no commands.test configured — add `test = <command>` under ## implement in .dev-flow/project.md", isError: true };
|
|
1995
|
-
const res = await sh(cfg.commands.test, gateCwd(root, state!));
|
|
2005
|
+
const res = await sh(cfg.commands.test, gateCwd(root, state!), undefined, featureEnv(root, state!));
|
|
1996
2006
|
state!.checks.test = { ok: res.ok, at: now() };
|
|
1997
2007
|
await stampChecks(root, state!, ["test"]);
|
|
1998
2008
|
writeState(root, state!);
|
|
@@ -2068,6 +2078,8 @@ async function gateAbort(o: GateCtx): Promise<RunResult> {
|
|
|
2068
2078
|
return { text: `aborted ${target} — feature removed (nothing approved, nothing to recover)` };
|
|
2069
2079
|
}
|
|
2070
2080
|
if (sess.slug === target) sess.bind(null);
|
|
2081
|
+
// the scratch dir is the bound session's working junk — it does not outlive the binding
|
|
2082
|
+
rmSync(featureTmpDir(dfDir(root), target), { recursive: true, force: true });
|
|
2071
2083
|
if (st?.worktree) { st.aborted = now(); writeState(root, st); } // the doctor skips the removed worktree for stamped states (gh#138)
|
|
2072
2084
|
return { text: `session unbound from ${target}; state stays at .dev-flow/${target}/` + (st?.aborted ? " (marked aborted — the doctor leaves it alone once you clean the worktree up)" : "") + (st?.worktree ? `\nto remove the worktree and branch:\n git worktree remove ${st.worktree}\n git branch -D ${st.branch}` : "") };
|
|
2073
2085
|
}
|
|
@@ -2656,7 +2668,22 @@ export default function devFlow(pi: ExtensionAPI) {
|
|
|
2656
2668
|
pi.appendEntry("dev-flow-skill", { core: true, stale: true });
|
|
2657
2669
|
});
|
|
2658
2670
|
|
|
2671
|
+
// A bash call every guard let through runs with TMPDIR in its bound feature's scratch dir
|
|
2672
|
+
// (.dev-flow/<slug>/tmp/): mktemp, os.tmpdir() and test fixtures land there and flow finish removes
|
|
2673
|
+
// them. Prefixed only after the verdict, so no guard ever judges the prefix.
|
|
2659
2674
|
pi.on("tool_call", async (event, ctx) => {
|
|
2675
|
+
const verdict = await guardToolCall(event, ctx);
|
|
2676
|
+
if (verdict || !isToolCallEventType("bash", event) || !guardsAreMine() || !initiated(ctx.cwd)) return verdict;
|
|
2677
|
+
const root = await flowRoot(ctx.cwd);
|
|
2678
|
+
const bound = boundFeature(root, sessionKey(ctx));
|
|
2679
|
+
if (!bound) return undefined;
|
|
2680
|
+
const dir = featureTmpDir(dfDir(root), bound.slug);
|
|
2681
|
+
mkdirSync(dir, { recursive: true });
|
|
2682
|
+
event.input.command = withTmpDir(String(event.input.command ?? ""), dir);
|
|
2683
|
+
return undefined;
|
|
2684
|
+
});
|
|
2685
|
+
|
|
2686
|
+
async function guardToolCall(event: ToolCallEvent, ctx: ExtensionContext): Promise<ToolCallEventResult | undefined> {
|
|
2660
2687
|
if (!guardsAreMine()) return undefined; // election: only the newest loaded copy judges
|
|
2661
2688
|
// pi kills a shell call only when a timeout was passed, and the model omits it in ~75% of
|
|
2662
2689
|
// calls (observed hangs: hours). Deterministic class defaults, clamped ceilings — runs for
|
|
@@ -2786,7 +2813,7 @@ export default function devFlow(pi: ExtensionAPI) {
|
|
|
2786
2813
|
}
|
|
2787
2814
|
}
|
|
2788
2815
|
return undefined;
|
|
2789
|
-
}
|
|
2816
|
+
}
|
|
2790
2817
|
|
|
2791
2818
|
pi.on("before_agent_start", async (_event, ctx) => {
|
|
2792
2819
|
if (!guardsAreMine()) return undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-dev-flow",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.79.0",
|
|
4
4
|
"description": "Enforced feature workflow for Pi: plan → implement → pre-release → release, gated checkpoints, self-improvement reflections, one git worktree per feature, changelog + publish as part of the release",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -43,8 +43,8 @@ unmerged. `flow finish [slug]`:
|
|
|
43
43
|
through `flow abort` instead;
|
|
44
44
|
- requires the main checkout **clean and pushed** — an uncommitted changelog or
|
|
45
45
|
a local-only release commit is exactly what it protects against;
|
|
46
|
-
- removes the worktree and branch, then deletes `.dev-flow/<slug>/`
|
|
47
|
-
unbinds the session. A feature branch still on `origin` is deleted **only on
|
|
46
|
+
- removes the worktree and branch, then deletes `.dev-flow/<slug>/` (its
|
|
47
|
+
`tmp/` scratch dir included) and unbinds the session. A feature branch still on `origin` is deleted **only on
|
|
48
48
|
proof it was merged** — ancestor of `origin/<default>`, or a merged PR via gh
|
|
49
49
|
or glab (what a squash leaves behind); otherwise kept with a note. Uncommitted worktree edits block
|
|
50
50
|
finish; commits that never reached the default branch are read against the playbook's `merge` policy —
|
|
@@ -22,6 +22,9 @@ feature).
|
|
|
22
22
|
never block verify, they are what the operator sees they are approving.
|
|
23
23
|
2. Write tests as you go (project framework: the `test` key / `flow-check`
|
|
24
24
|
blocks).
|
|
25
|
+
Throwaway scripts and scratch output go in `$TMPDIR` (or `mktemp`), not a
|
|
26
|
+
hard-coded `/tmp/...`: in a bound session, and in every command a gate runs,
|
|
27
|
+
it is `.dev-flow/<slug>/tmp/`, and finish removes it with the feature.
|
|
25
28
|
3. `flow check` runs every tier-1 check (test, health, named `flow-check`
|
|
26
29
|
blocks) and records each against a fingerprint of the worktree; any later
|
|
27
30
|
worktree change makes them stale — verify reruns stale checks itself.
|
package/src/core.ts
CHANGED
|
@@ -1325,6 +1325,18 @@ export function mainCheckoutRoot(cwd: string, commonDir: string | null): string
|
|
|
1325
1325
|
return main === path.resolve(cwd) ? null : main;
|
|
1326
1326
|
}
|
|
1327
1327
|
|
|
1328
|
+
/** A bound feature's scratch dir: every process the flow runs for it gets this as TMPDIR, so throwaways
|
|
1329
|
+
* and test fixtures land inside `.dev-flow/<slug>/` and `flow finish` removes them with the feature. */
|
|
1330
|
+
export function featureTmpDir(dfDir: string, slug: string): string {
|
|
1331
|
+
return path.join(dfDir, slug, "tmp");
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
/** The agent's shell command with TMPDIR pointed at the feature's scratch dir (newline-prefixed, the
|
|
1335
|
+
* shape pi's own commandPrefix uses — the command itself stays byte-for-byte what the guards judged). */
|
|
1336
|
+
export function withTmpDir(command: string, dir: string): string {
|
|
1337
|
+
return `export TMPDIR=${sq(dir)}\n${command}`;
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1328
1340
|
export function inScratchDir(abs: string, repoRoot?: string | null): boolean {
|
|
1329
1341
|
const real = realAbs(abs);
|
|
1330
1342
|
if (repoRoot) {
|
|
@@ -1382,7 +1394,7 @@ export function writeGuard(o: { abs: string; dfDir: string; features: FeatureRef
|
|
|
1382
1394
|
}
|
|
1383
1395
|
if (bound) {
|
|
1384
1396
|
if (bound.state.stage === "implement" || bound.state.stage === "pre-release")
|
|
1385
|
-
return `bound feature ${o.boundSlug} is at ${bound.state.stage} — edit its worktree (${bound.state.worktree}), not the main checkout; a throwaway script goes
|
|
1397
|
+
return `bound feature ${o.boundSlug} is at ${bound.state.stage} — edit its worktree (${bound.state.worktree}), not the main checkout; a throwaway script goes in $TMPDIR (.dev-flow/${o.boundSlug}/tmp/, removed at finish)`;
|
|
1386
1398
|
return null; // release: release chores may touch the main checkout
|
|
1387
1399
|
}
|
|
1388
1400
|
if (!o.features.length) return "no active flow — every request goes through flow: flow start <slug> for new work, flow use <slug> for an unfinished feature";
|