pi-dev-flow 0.59.0 → 0.59.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 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.59.1] - 2026-10-23
8
+
9
+ ### Fixed
10
+
11
+ - **A session running an older dev-flow build than the checkout now says so — including in the dev-flow repo, where it never could.** `flow start` carried a behind-the-checkout warning and `flow release` carried the update-or-proceed question, but both compared the loaded build against `pluginVersion(import.meta.dirname)` — the `package.json` sitting beside the running code, which is the same file `loadedVersion()` reads — so the comparison was X against X and only the `DEV_FLOW_LOADED_VERSION` test seam ever made it unequal. A session that loaded 0.54.0 while this checkout already shipped 0.58.1 started, released and finished looking current, and the gate proofs shipped in between silently did not run. `checkoutBuild(root)` now answers what the disk says to run: this checkout's own manifest in the dev-flow repo, the installed package's everywhere else. `start`, `status`, `version`, `release` and `release-done` read it, the stamp in `state.json` records the build that actually ran rather than the one the disk claims, and `flow version` names the directory the stale code lives in. The stale release question stays a question — an operator who ships from behind is a choice, never a block.
12
+ - **Scratch outside the checkout is stage-free.** With a flow bound at `implement` or `pre-release`, the write guard refused every path that was not the worktree or `.dev-flow/` — `/tmp/split_skill.py` included — so an agent doing a mechanical multi-file rewrite had nowhere to keep a throwaway script and learned to park junk inside the checkout instead. A path whose realpath is under the OS temp dir is now allowed at every stage and with no flow bound, checked after the dev-flow-owned refusals and after per-path owner attribution, so neither a symlink out of the temp dir nor a `worktreeDir` an operator parked there reaches those rules; a repository that merely lives under the temp dir (every smoke-test repo) keeps the stage rules untouched. The refusal that remains names the temp dir as its own way out.
13
+
7
14
  ## [0.59.0] - 2026-10-23
8
15
 
9
16
  ### Added
@@ -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.
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.
10
10
  - **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.
11
11
  - **Gates can't be skipped**: flow state is untouchable by the agent (edit tool and bash) — writing `state.json`, moving it away, or deleting a feature directory or the whole `.dev-flow/` folder all block; the `project.md` playbook is operator-owned — the main-checkout copy is blocked for the agent outright, and only a **docs or patch flow's** worktree copy may be edited (normal features route playbook changes to their own flow); every sanctioned playbook overwrite keeps the previous file as `project.md.bak`; editing worktree code invalidates a passing test check until `flow test` reruns.
12
12
  - **Your project's own rules**: every `deny`/`confirm`/`protect`/`forbid` rule from the `flow-guard` block in project.md `## global` runs on every bash command and every edit/write path — in every stage and binding, ahead of dev-flow's own verdicts. A block always carries the reason you wrote.
@@ -133,6 +133,17 @@ function loadedVersion(): string | null {
133
133
  /** This build's own identity, read once (the guard hot path must not re-walk the fs per call). */
134
134
  const SELF_BUILD = pluginVersion(import.meta.dirname);
135
135
 
136
+ /** The dev-flow build this session *should* be running, as the disk describes it, and how to call it.
137
+ * In the dev-flow repo that is the checkout's own manifest: main moves ahead of the installed copy at
138
+ * every release, while `loadedVersion()` and the plugin's own package.json are the same file — so a
139
+ * session running 0.54.0 in a checkout already at 0.58.1 compared equal and nothing anywhere said so.
140
+ * In a normal project the only manifest is the installed package's, which a mid-session update moves. */
141
+ function checkoutBuild(root: string): { version: string | null; dir: string; repo: string; label: string } {
142
+ return isSelfRepo(root)
143
+ ? { ...pluginVersion(root), label: "this checkout" }
144
+ : { ...SELF_BUILD, label: "the dev-flow install" };
145
+ }
146
+
136
147
  /** Cross-copy registry: one process can register dev-flow more than once (the documented
137
148
  * two-sources-at-once hazard: a project dogfood pointer plus an installed copy), and EVERY copy
138
149
  * evaluates every guard hook. The flow-tool binding belongs to whichever copy served the call,
@@ -289,7 +300,7 @@ async function releaseTags(root: string): Promise<string[] | null> {
289
300
  }
290
301
 
291
302
  const GATE_HELP =
292
- "help [--json] | init [--force|--draft|--write <text>] | reflect [<note>|tidy] | roadmap [add <text>|pick <n> <slug>|done <n>|tidy] | doctor [<issue note>] | status [slug] [--json] | start <slug> [--ui] [--force] [--patch|--docs --confirmed] [--merge=squash|merge|rebase|any] [--check-upstream] | use <slug> | test | check | health | approve [--yolo] | verify [--yolo] | release [--yolo|--no-version|--no-fold-check] | release-done [--no-artifact-check|--no-release-create] | finish [--yolo] [slug] | abort [slug] | version [--check-upstream] — start preflights the playbook before creating anything: it prints playbook gaps and warns when the session runs an older dev-flow build, and it refuses until a merge policy is set (ask the operator squash / merge / rebase / any in chat, then re-run with --merge=<style> --confirmed — the answer is written into project.md and enforced from then on: gh/glab merges that contradict it are blocked, and release-done proves what actually landed); version prints the loaded build and names any other dev-flow copies registered in the same process (--check-upstream also asks the registry for the published one) — reflect <note> queues a suggestion in reflections.md (gate flags like --confirmed are ignored there); reflect tidy drops the closed (`- [x]`) items from reflections.md — every surface that queues or reviews reflections nudges when the checked-off pile grows; bare reflect prints the full session-reflection protocol (review the session log, re-check open items against shipped fixes and newer dev-flow versions, dedupe and report new findings, put the fix decision to the operator); roadmap manages .dev-flow/roadmap.md, the gitignored backlog of future features (bare lists open items; add appends one; pick <n> <slug> stamps open item <n> with the slug a later flow start uses — flow finish checks it off when that feature ships; done <n> checks off by hand; tidy drops done items); bare doctor reviews structure, git consistency and open reflections (routes each fix to a flow; it never writes); doctor <note> prints an investigation brief for a fresh observation; state gates take [slug] and --confirmed (the operator already answered in chat); --patch/--docs likewise need --confirmed (the operator granted the mode); --yolo on any state gate (approve/verify/release/finish) = the operator said \"yolo\" at that checkpoint: it answers that question and pre-confirms every later one (needs --confirmed; checks and guardrails stay); release --no-fold-check = operator-granted escape from the changelog fold proofs (the entries pending before the release are not line-checked; the entry heading and the 'this branch touched the changelog' proofs stay); release --no-version = this flow ships merge + changelog only — no bump, tag or forge release; the entry rides under Unreleased until the next versioned release folds it (default: versioned); when the session runs an older dev-flow build than the checkout, release names both builds, lists what the running code can no longer prove, and asks the operator update (/reload) or proceed with the old release — an operator decision recorded in state and repeated by release-done, never a block";
303
+ "help [--json] | init [--force|--draft|--write <text>] | reflect [<note>|tidy] | roadmap [add <text>|pick <n> <slug>|done <n>|tidy] | doctor [<issue note>] | status [slug] [--json] | start <slug> [--ui] [--force] [--patch|--docs --confirmed] [--merge=squash|merge|rebase|any] [--check-upstream] | use <slug> | test | check | health | approve [--yolo] | verify [--yolo] | release [--yolo|--no-version|--no-fold-check] | release-done [--no-artifact-check|--no-release-create] | finish [--yolo] [slug] | abort [slug] | version [--check-upstream] — start preflights the playbook before creating anything: it prints playbook gaps and warns when the session runs an older dev-flow build than the disk ships (in the dev-flow repo, an older build than this checkout's own manifest), and it refuses until a merge policy is set (ask the operator squash / merge / rebase / any in chat, then re-run with --merge=<style> --confirmed — the answer is written into project.md and enforced from then on: gh/glab merges that contradict it are blocked, and release-done proves what actually landed); version prints the build the disk says to run (this checkout's own manifest in the dev-flow repo, the installed package's elsewhere) and names any other dev-flow copies registered in the same process (--check-upstream also asks the registry for the published one) — reflect <note> queues a suggestion in reflections.md (gate flags like --confirmed are ignored there); reflect tidy drops the closed (`- [x]`) items from reflections.md — every surface that queues or reviews reflections nudges when the checked-off pile grows; bare reflect prints the full session-reflection protocol (review the session log, re-check open items against shipped fixes and newer dev-flow versions, dedupe and report new findings, put the fix decision to the operator); roadmap manages .dev-flow/roadmap.md, the gitignored backlog of future features (bare lists open items; add appends one; pick <n> <slug> stamps open item <n> with the slug a later flow start uses — flow finish checks it off when that feature ships; done <n> checks off by hand; tidy drops done items); bare doctor reviews structure, git consistency and open reflections (routes each fix to a flow; it never writes); doctor <note> prints an investigation brief for a fresh observation; state gates take [slug] and --confirmed (the operator already answered in chat); --patch/--docs likewise need --confirmed (the operator granted the mode); --yolo on any state gate (approve/verify/release/finish) = the operator said \"yolo\" at that checkpoint: it answers that question and pre-confirms every later one (needs --confirmed; checks and guardrails stay); release --no-fold-check = operator-granted escape from the changelog fold proofs (the entries pending before the release are not line-checked; the entry heading and the 'this branch touched the changelog' proofs stay); release --no-version = this flow ships merge + changelog only — no bump, tag or forge release; the entry rides under Unreleased until the next versioned release folds it (default: versioned); when the session runs an older dev-flow build than the checkout, release names both builds, lists what the running code can no longer prove, and asks the operator update (/reload) or proceed with the old release — an operator decision recorded in state and repeated by release-done, never a block";
293
304
  const featDir = (root: string, slug: string) => path.join(dfDir(root), slug);
294
305
  const stateFile = (root: string, slug: string) => path.join(featDir(root, slug), "state.json");
295
306
  const claimFile = (root: string, slug: string) => path.join(featDir(root, slug), "claim.json");
@@ -809,15 +820,15 @@ ${mdDigest(draftRefresh)}`))
809
820
  if (curBr !== cfg.defaultBranch && !flag("force")) return { text: `main checkout is on ${curBr}, not ${cfg.defaultBranch} — check out ${cfg.defaultBranch} first (git checkout ${cfg.defaultBranch} && git pull) or flow use an unfinished feature; --force to override`, isError: true };
810
821
  // --- preflight: is this session running the current build, and is the playbook complete? ---
811
822
  const notes: string[] = [];
812
- const self = pluginVersion(import.meta.dirname);
813
- const behind = sessionRunsOlderBuild(loadedVersion(), self.version);
814
- if (behind) notes.push(`warning: this session runs dev-flow ${behind}, the checkout has ${self.version} — /reload before trusting what a gate prints`);
823
+ const disk = checkoutBuild(root);
824
+ const behind = sessionRunsOlderBuild(loadedVersion(), disk.version);
825
+ if (behind) notes.push(`warning: this session runs dev-flow ${behind}, ${disk.label} ships ${disk.version} — /reload before trusting what a gate prints`);
815
826
  const dupStart = copyWarning();
816
827
  if (dupStart) notes.push(dupStart);
817
828
  if (flag("check-upstream")) {
818
829
  const pub = await sh("npm view pi-dev-flow version", root);
819
830
  const newest = pub.ok ? pub.out.trim().split("\n").pop() : "";
820
- notes.push(newest ? `published dev-flow: ${newest} (this build: ${self.version ?? "?"})${self.version && newest !== self.version ? " — an update is available" : ""}` : "could not read the published dev-flow version (offline?)");
831
+ notes.push(newest ? `published dev-flow: ${newest} (this build: ${loadedVersion() ?? "?"})${loadedVersion() && newest !== loadedVersion() ? " — an update is available" : ""}` : "could not read the published dev-flow version (offline?)");
821
832
  }
822
833
  // missing playbook parameters are printed at the moment they start to matter, not promised to a later doctor run
823
834
  const gaps = doctorFindings(root, cfg, loadProject(dfDir(root)).md).filter((x) => !x.startsWith("no merge policy"));
@@ -849,12 +860,13 @@ ${mdDigest(draftRefresh)}`))
849
860
  cfg.release.merge = style;
850
861
  notes.push(written.note);
851
862
  }
852
- // stamp the dev-flow build that started this feature — a stuck flow can later be read against its tooling
853
- const state = newState(slugArg, flag("ui"), flag("patch"), flag("docs"), self.version ?? undefined);
863
+ // stamp the dev-flow build that started this feature — a stuck flow can later be read against its tooling.
864
+ // the stamp is what ran, not what the disk claims (that mismatch is the warning above).
865
+ const state = newState(slugArg, flag("ui"), flag("patch"), flag("docs"), loadedVersion() ?? undefined);
854
866
  mkdirSync(path.join(featDir(root, slugArg), "plan"), { recursive: true });
855
867
  writeState(root, state);
856
868
  sess.bind(slugArg);
857
- return { text: `feature ${slugArg} started at stage plan (ui=${state.ui}${state.patch ? ", patch" : state.docs ? ", docs" : ""}${self.version ? `, dev-flow ${self.version}` : ""}).${notes.length ? `\n${notes.join("\n")}` : ""}\n${nextHint(state, cfg)}` };
869
+ return { text: `feature ${slugArg} started at stage plan (ui=${state.ui}${state.patch ? ", patch" : state.docs ? ", docs" : ""}${state.flowVersion ? `, dev-flow ${state.flowVersion}` : ""}).${notes.length ? `\n${notes.join("\n")}` : ""}\n${nextHint(state, cfg)}` };
858
870
  }
859
871
 
860
872
  case "status": {
@@ -862,7 +874,11 @@ ${mdDigest(draftRefresh)}`))
862
874
  const { md } = loadProject(df);
863
875
  // cheap fs probes only (no git subprocesses) — status is a glance, `flow doctor` is the full list
864
876
  const findings = md ? doctorFindings(root, cfg, md) : [];
865
- const warn = [...(findings.length ? [`⚠ doctor: ${findings.length} finding(s) — run flow doctor`] : []), ...(copyWarning() ? [copyWarning()!] : [])];
877
+ // a session running an older build than the disk ships is the one thing a glance must say: every
878
+ // gate proof printed since the drift began belongs to the older code.
879
+ const disk = checkoutBuild(root);
880
+ const staleBuild = sessionRunsOlderBuild(loadedVersion(), disk.version);
881
+ const warn = [...(findings.length ? [`⚠ doctor: ${findings.length} finding(s) — run flow doctor`] : []), ...(staleBuild ? [`⚠ this session runs dev-flow ${staleBuild}, ${disk.label} ships ${disk.version} — /reload`] : []), ...(copyWarning() ? [copyWarning()!] : [])];
866
882
  // the backlog nudge belongs to the no-features answer too — that is when a pick is most useful
867
883
  const rmap = roadmapOpenCount(readRoadmap(root));
868
884
  const rmapLine = rmap ? [`◇ ${rmap} roadmap item(s) open — flow roadmap`] : [];
@@ -968,9 +984,11 @@ ${mdDigest(draftRefresh)}`))
968
984
 
969
985
  case "version": {
970
986
  // the plugin's own version — separate from the project's versioning.file version the release gates use
971
- const self = pluginVersion(import.meta.dirname);
987
+ const self = checkoutBuild(root);
972
988
  const behind = sessionRunsOlderBuild(loadedVersion(), self.version);
973
989
  const head = self.version ? `dev-flow ${self.version} (pi-dev-flow at ${self.dir})` : `dev-flow version unknown — no pi-dev-flow package.json above ${self.dir}`;
990
+ // in the dev-flow repo head names the checkout, so name where the stale code actually lives
991
+ const from = SELF_BUILD.dir !== self.dir ? ` (from ${SELF_BUILD.dir})` : "";
974
992
  const dupNote = copyWarning();
975
993
  // --check-upstream is the one that asks the registry; plain flow version stays offline and instant
976
994
  if (flag("check-upstream")) {
@@ -978,7 +996,7 @@ ${mdDigest(draftRefresh)}`))
978
996
  const newest = pub.ok ? pub.out.trim().split("\n").pop() : "";
979
997
  return { text: newest ? `${head} — published: ${newest}${self.version && newest !== self.version ? " (update available)" : ""}` : `${head} — could not read the published version (offline?)` };
980
998
  }
981
- return { text: `${behind ? `${head} — but this session runs ${behind}; /reload to run ${self.version}` : head}${dupNote ? `\n${dupNote}` : ""}` };
999
+ return { text: `${behind ? `${head} — but this session runs ${behind}${from}; /reload to run ${self.version}` : head}${dupNote ? `\n${dupNote}` : ""}` };
982
1000
  }
983
1001
 
984
1002
  case "approve": {
@@ -1206,7 +1224,7 @@ ${mdDigest(draftRefresh)}`))
1206
1224
  // legitimate choice (hotfix, offline reload), and refusing would close exactly the emergency the relaxed
1207
1225
  // modes exist for. The gate names both builds, lists what the running code is missing, and folds the
1208
1226
  // update-or-proceed question into the Release? checkpoint — the operator's word, recorded in state.
1209
- const selfBuild = pluginVersion(import.meta.dirname);
1227
+ const selfBuild = checkoutBuild(root);
1210
1228
  const behind = sessionRunsOlderBuild(loadedVersion(), selfBuild.version);
1211
1229
  // truly behind, not merely different: a session whose loaded build is NEWER than the checkout's manifest
1212
1230
  // has every proof the checkout would run, and asking about it would be noise.
@@ -1217,12 +1235,12 @@ ${mdDigest(draftRefresh)}`))
1217
1235
  const clPath = path.join(selfBuild.dir, "CHANGELOG.md");
1218
1236
  const missing = existsSync(clPath) && selfBuild.version ? changelogVersionsBetween(readFileSync(clPath, "utf8"), behind, selfBuild.version) : [];
1219
1237
  staleAsk =
1220
- ` This session runs dev-flow ${behind}, the checkout ships ${selfBuild.version ?? "?"} — gate proofs shipped between the two will NOT run. ` +
1238
+ ` This session runs dev-flow ${behind}, ${selfBuild.label} ships ${selfBuild.version ?? "?"} — gate proofs shipped between the two will NOT run. ` +
1221
1239
  (missing.length
1222
1240
  ? `Shipped since ${behind}: ${missing.slice(0, 8).join(", ")}${missing.length > 8 ? ` …(${missing.length} total)` : ""} — see ${clPath}. `
1223
1241
  : `What shipped between them is not readable from the checkout's CHANGELOG.md — read it before deciding. `) +
1224
1242
  `Update (/reload, then re-run flow release on the current build) or proceed with the old release?`;
1225
- staleNote = `released under dev-flow ${behind} (checkout ${selfBuild.version ?? "?"}) by operator choice — proofs newer than ${behind} did not run`;
1243
+ staleNote = `released under dev-flow ${behind} (${selfBuild.label} ${selfBuild.version ?? "?"}) by operator choice — proofs newer than ${behind} did not run`;
1226
1244
  }
1227
1245
  const audit = flag("confirmed") ? " (confirmed by operator instruction)" : state!.yolo ? " (yolo: pre-confirmed)" : "";
1228
1246
  if (!flag("confirmed") && !state!.yolo) {
@@ -1244,7 +1262,7 @@ ${mdDigest(draftRefresh)}`))
1244
1262
  // the version of record is fixed here, from the manifest this gate validated: release-done must not
1245
1263
  // re-read a checkout that may still be behind (#52)
1246
1264
  if (!state!.noVersion && manifestVer) state!.releaseVersion = manifestVer;
1247
- if (stale) state!.staleBuild = `${behind} (checkout ${selfBuild.version ?? "?"})`;
1265
+ if (stale) state!.staleBuild = `${behind} (${selfBuild.label} ${selfBuild.version ?? "?"})`;
1248
1266
  writeState(root, state!);
1249
1267
  return { text: `release approved${audit}${state!.noVersion ? " — unversioned: no bump or tag; your changelog entry rides under Unreleased until the next versioned release folds it" : ""} — entering release stage.${manifestVer ? ` Version ${manifestVer}.` : ""}${foldNote}${staleNote ? ` ${staleNote}.` : ""}\n${nextHint(state!, cfg)}` };
1250
1268
  }
@@ -1357,7 +1375,7 @@ ${mdDigest(draftRefresh)}`))
1357
1375
  ghNote = gr.ok ? `${forge} release ${tag} created. ${notesNote}`.trim() : `${forge} release skipped: ${tail(gr.out)}`;
1358
1376
  }
1359
1377
  }
1360
- const behind = sessionRunsOlderBuild(loadedVersion(), pluginVersion(import.meta.dirname).version);
1378
+ const behind = sessionRunsOlderBuild(loadedVersion(), checkoutBuild(root).version);
1361
1379
  const openRelease = checklistPending(cfg, state!, "release");
1362
1380
  // release-stage items have no gate of their own: the operator's Finish? answer is what closes them, so
1363
1381
  // name them at the last objective gate — on the way out too, or the refusal hides half the story
@@ -1394,7 +1412,7 @@ ${mdDigest(draftRefresh)}`))
1394
1412
  state!.staleBuild
1395
1413
  ? `stale build acknowledged at release gate: this session ran dev-flow ${state!.staleBuild} — proofs newer than it did not run.`
1396
1414
  : behind
1397
- ? `warning: this session runs dev-flow ${behind}, not the build in the checkout — /reload before trusting what it printed.`
1415
+ ? `warning: this session runs dev-flow ${behind}, not the build the disk ships — /reload before trusting what it printed.`
1398
1416
  : "",
1399
1417
  mergeNote,
1400
1418
  openNote,
@@ -1813,7 +1831,7 @@ export default function devFlow(pi: ExtensionAPI) {
1813
1831
  const why = await askOperator(ctx, `Editing ${path.relative(ctx.cwd, abs) || abs}`, pv.confirm);
1814
1832
  if (why) return { block: true, reason: why };
1815
1833
  }
1816
- const reason = writeGuard({ abs, dfDir: dfDir(ctx.cwd), features: feats, boundSlug: bound?.slug ?? null });
1834
+ const reason = writeGuard({ abs, dfDir: dfDir(ctx.cwd), features: feats, boundSlug: bound?.slug ?? null, repoRoot: ctx.cwd });
1817
1835
  if (reason) return { block: true, reason };
1818
1836
  // Editing a worktree invalidates that feature's tier-1 checks and tier-2 confirmation until they rerun.
1819
1837
  const owner = feats.find((f) => f.worktreeAbs && abs.startsWith(f.worktreeAbs + path.sep));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-dev-flow",
3
- "version": "0.59.0",
3
+ "version": "0.59.1",
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": [
package/src/core.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import { existsSync, readdirSync, readFileSync, realpathSync } from "node:fs";
8
8
  import { createHash } from "node:crypto";
9
+ import os from "node:os";
9
10
  import path from "node:path";
10
11
 
11
12
  export type Stage = "plan" | "implement" | "pre-release" | "release" | "done";
@@ -1176,6 +1177,23 @@ export interface FeatureRef {
1176
1177
 
1177
1178
  const within = (abs: string, dir: string | null) => !!dir && (abs === dir || abs.startsWith(dir + path.sep));
1178
1179
 
1180
+ /**
1181
+ * A throwaway outside the repository, which is not a repo write at all: a mechanical multi-file rewrite
1182
+ * needs somewhere to keep a scratch script, and refusing `/tmp/split_skill.py` only taught agents to park
1183
+ * junk inside the checkout. Both sides are realpath'd, so a symlink in the temp dir cannot reach back into
1184
+ * the guarded checkout, and `repoRoot` keeps a repository that merely lives under the temp dir (every
1185
+ * smoke-test repo) under the normal stage rules.
1186
+ */
1187
+ export function inScratchDir(abs: string, repoRoot?: string | null): boolean {
1188
+ const real = realAbs(abs);
1189
+ if (repoRoot) {
1190
+ const root = realAbs(path.resolve(repoRoot));
1191
+ if (real === root || real.startsWith(root + path.sep)) return false;
1192
+ }
1193
+ const tmp = realAbs(path.resolve(os.tmpdir()));
1194
+ return real === tmp || real.startsWith(tmp + path.sep);
1195
+ }
1196
+
1179
1197
  /**
1180
1198
  * Write guard with per-path attribution: writes inside a worktree are judged by that
1181
1199
  * worktree's own feature; main-checkout writes are judged by the session's bound feature
@@ -1184,7 +1202,7 @@ const within = (abs: string, dir: string | null) => !!dir && (abs === dir || abs
1184
1202
  * touch the checkout at all — a bound feature is the only way in.
1185
1203
  * Returns a reason or null (allowed).
1186
1204
  */
1187
- export function writeGuard(o: { abs: string; dfDir: string; features: FeatureRef[]; boundSlug: string | null }): string | null {
1205
+ export function writeGuard(o: { abs: string; dfDir: string; features: FeatureRef[]; boundSlug: string | null; repoRoot?: string | null }): string | null {
1188
1206
  if (o.abs === path.join(o.dfDir, "project.json")) return ".dev-flow/project.json is legacy — it is no longer read; fold its values into project.md and delete it";
1189
1207
  if (o.abs === path.join(o.dfDir, "project.md")) return "project.md is the operator playbook — change it with flow init --write (setup) or inside a docs/patch flow's worktree";
1190
1208
  if (o.abs.endsWith("state.json") && o.abs.includes(o.dfDir + path.sep)) return "state.json is dev-flow-owned — advance stages with the flow tool only";
@@ -1199,6 +1217,10 @@ export function writeGuard(o: { abs: string; dfDir: string; features: FeatureRef
1199
1217
  return `project.md changes belong to a docs or patch flow — ${owner.state.slug} is a normal feature (flow start <slug> --docs --confirmed)`;
1200
1218
  return null; // implement/pre-release/release: own worktree is the working area
1201
1219
  }
1220
+ // Scratch outside the checkout is not a repo write: every stage (and an unbound session) may use it. It
1221
+ // sits after the dev-flow-owned refusals and after owner attribution, so no path shape — a symlink, or a
1222
+ // worktreeDir an operator parked in the temp dir — reaches those rules through the temp dir.
1223
+ if (inScratchDir(o.abs, o.repoRoot)) return null;
1202
1224
  const bound = o.boundSlug ? o.features.find((f) => f.state.slug === o.boundSlug) : undefined;
1203
1225
  // A plan-stage session may only write its own feature directory: otherwise one session edits another
1204
1226
  // feature's plan and that feature's approval gate then rubber-stamps text it never wrote.
@@ -1207,7 +1229,7 @@ export function writeGuard(o: { abs: string; dfDir: string; features: FeatureRef
1207
1229
  if (within(o.abs, o.dfDir)) return null;
1208
1230
  if (bound) {
1209
1231
  if (bound.state.stage === "implement" || bound.state.stage === "pre-release")
1210
- return `bound feature ${o.boundSlug} is at ${bound.state.stage} — edit its worktree (${bound.state.worktree}), not the main checkout`;
1232
+ return `bound feature ${o.boundSlug} is at ${bound.state.stage} — edit its worktree (${bound.state.worktree}), not the main checkout; a throwaway script goes outside the repo (under $TMPDIR)`;
1211
1233
  return null; // release: release chores may touch the main checkout
1212
1234
  }
1213
1235
  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";