pi-dev-flow 0.89.0 → 0.90.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.
@@ -1,72 +1,66 @@
1
- # Hacking on dev-flow
1
+ # Working on dev-flow
2
2
 
3
- This checkout dogfoods itself — the repo is developed with dev-flow.
3
+ This repo is built with dev-flow itself.
4
4
 
5
5
  ```bash
6
- npm i && npm test # unit tests + wiring smoke test (node --test)
7
- pi -e . run /flow status # try it against any repo
6
+ npm i && npm test # unit tests + wiring smoke test (node --test)
7
+ pi -e . run /flow status # try the working tree against any repo
8
8
  ```
9
9
 
10
- Sessions in this checkout load the **single global dev-flow install** (`pi update --extensions`
11
- reconciles it after a release; loaded code swaps only when the process re-imports — `/reload` in a
12
- per-session host, a host restart in a shared-process host like pi-web) — there is deliberately no
13
- `.pi/extensions/` pointer here: a committed shim beside the global package loads two copies of the
14
- extension in one process (pi dedupes by path, not by package — see the README's two-sources
15
- warning), which is what the shim used to cause. The package's own `pi.extensions` manifest remains a
16
- second source for any session opened in this checkout — deliberate dogfooding, made safe by the guard
17
- election: the newest registered copy judges, older loaded copies answer nothing. To dogfood the
18
- working tree instead of the installed copy, point pi at it explicitly for that run: `pi -e .`.
10
+ ## Loaded code and duplicate copies
19
11
 
20
- A release cannot update a session that is already running — pi keeps the code it loaded at startup.
21
- After merging and tagging, `/reload` in every session that must carry the new behavior; shared-process
22
- hosts (pi-web) keep stale code until restarted, so reload there re-binds state but does not swap code.
12
+ - **A running session keeps the code it started with.** After a release, run `/reload` in each
13
+ session that needs the new behavior. Shared-process hosts like pi-web keep the old code until
14
+ they're restarted: there, `/reload` re-binds state but doesn't swap code.
15
+ - **Two install sources load two copies.** For example, a project `git:` pin next to a global `npm:`
16
+ install. Pi dedupes extensions by path, not by package. Keep only the source you update from.
17
+ - **The newest copy decides.** Every loaded copy's guards check which registered version is highest,
18
+ and older copies stay silent. `flow version` lists every copy in the process and names the one
19
+ serving the call.
20
+ - **This checkout uses the global install.** There's deliberately no `.pi/extensions/` shim here:
21
+ one would load a second copy. The package's own `pi.extensions` manifest is a second source in
22
+ this checkout, which is safe because the newest copy decides. To run the working tree instead, use
23
+ `pi -e .`.
23
24
 
24
25
  ## Layout
25
26
 
26
- - `extensions/dev-flow.ts` — the pi wiring only: the `/flow` command, the `flow` and `flow_stage` tools,
27
- the event hooks (guards, injections, footer, compaction).
28
- - `src/runtime/` — what the wiring runs: `base` (shell, paths, state, sessions, claims), `checks` (dev
29
- deploy, health, tier-1 checks, the stage-line facts), `gates` (the runner and the non-shipping gates),
30
- `ship` (verify, release, release-done, finish), `setup` (init questions), `reflect`, `workers`.
31
- - `src/core.ts`, `src/projectmd.ts`, `src/present.ts`, … — pure logic, unit-tested without pi.
32
- `present.ts` splits every gate result into the operator's view and the agent's text.
27
+ - `extensions/dev-flow.ts`: Pi wiring only. The `/flow` command, the `flow` and `flow_stage` tools,
28
+ and the event hooks (guards, injections, footer, compaction).
29
+ - `src/runtime/`: what the wiring runs.
30
+ - `base`: shell, paths, state, sessions, claims.
31
+ - `checks`: dev deploy, health, tier-1 checks.
32
+ - `gates`: the runner and the non-shipping gates.
33
+ - `ship`: verify, release, release-done, finish.
34
+ - `setup`, `reflect`, `workers`.
35
+ - `src/core.ts`, `src/projectmd.ts`, `src/present.ts`, …: pure logic, unit-tested without Pi.
36
+ `present.ts` splits each gate result into your view and the agent's text.
33
37
 
34
- ## The skill: an injected core, plus references a stage reads
38
+ ## The skill: an injected core plus per-stage references
35
39
 
36
- Pi advertises a skill (name, description, path) and loads `SKILL.md` only when the model decides to
37
- read it — nothing makes a skill always-on. A session that never reads the playbook is a session that
38
- guesses at a gate and then fights the guard, so `skills/dev-flow/SKILL.md` is split:
40
+ Pi loads a skill's `SKILL.md` only when the model decides to read it. A session that never reads the
41
+ rules guesses at gates and fights the guards. So `skills/dev-flow/SKILL.md` is split in two:
39
42
 
40
- - The **core** — the ground rules every turn needs — sits between `<!-- dev-flow:core:start -->` and
41
- `<!-- dev-flow:core:end -->`. The extension extracts that span and injects it into the hidden
42
- `[dev-flow]` message **once per session**: a `dev-flow-skill` entry records the fact, so a reload,
43
- resume or fork does not pay it twice, and a compaction that summarizes it away re-arms exactly one
44
- re-injection. That budget is what every session in a dev-flow repo pays, so `package.test.ts`
45
- refuses a core over **4,000 characters**.
46
- - Everything else lives in `references/<stage>.md` — stage prose moved verbatim. The stage injection
47
- names the one file the current stage needs (`…/references/plan.md` at plan), and the map under the
48
- core lists them all. `references/` stays invisible to pi: only `SKILL.md` registers, and a
49
- directory holding one is not scanned deeper.
43
+ - **The core** sits between `<!-- dev-flow:core:start -->` and `<!-- dev-flow:core:end -->`. It's
44
+ injected **once per session**. A reload, resume or fork doesn't inject it again, and a compaction
45
+ that summarizes it away brings it back once. Every session pays for it, so `package.test.ts`
46
+ rejects a core over **4,000 characters**.
47
+ - **Everything else** lives in `references/<stage>.md`. Each stage's message names the one file it
48
+ needs.
50
49
 
51
- When a stage grows, add to its reference file — do not grow the core. The tests guard both halves:
52
- every stage has a file, the map names every file, and `release.md` hands over to `finish.md` because
53
- the state machine has no finish stage that could name it.
50
+ When a stage needs more guidance, add it to that stage's reference file, not the core. The tests
51
+ check that every stage has a file and that the map names every file.
54
52
 
55
53
  ## Publishing
56
54
 
57
- `pi-dev-flow` is published to npm by `.github/workflows/release.yml`, triggered by the `v*` tag the
58
- release stage pushes: it checks out that tag, runs `npm ci && npm test`, and `npm publish --provenance`
59
- from exactly that commit. Nothing publishes from a developer machine.
55
+ `.github/workflows/release.yml` publishes to npm when a `v*` tag is pushed. It checks out the tag,
56
+ runs `npm ci && npm test`, and runs `npm publish --provenance`. Nothing publishes from a laptop.
60
57
 
61
- Auth is npm **trusted publishing** — the workflow's OIDC identity, no token in the repo. The publisher
62
- registered on npmjs.com names this repo **and the workflow file name**, so after renaming either one,
63
- re-register it there or the next publish is rejected. And the publisher must be registered on a package
64
- that already exists: npm has no place to put the credential before the first publish.
58
+ - **Auth is npm trusted publishing** (OIDC, no token). The registration on npmjs.com names this repo
59
+ and the workflow file name, so re-register after renaming either one.
60
+ - **`--provenance` needs a public repo.** If the repo ever goes private, drop the flag.
61
+ - **If the job fails,** fix the cause and re-run the same job. The tag already points at the right
62
+ commit. `flow release-done` refuses to close the flow until `npm view pi-dev-flow@<version>`
63
+ succeeds.
65
64
 
66
- `--provenance` requires a **public** source repository — npm refuses the attestation from a private one
67
- (`422 … Unsupported GitHub Actions source repository visibility: "private"`), which is why this repo is
68
- public. If it ever goes private, drop the flag rather than the release.
69
-
70
- If the job fails, fix the cause and **Re-run jobs** on the same failed run: the tag already points at what
71
- should ship, so no re-tag. `flow release-done` then runs `npm view pi-dev-flow@<version> version` and
72
- refuses to close the flow while the version is missing — which also catches a tag that never published.
65
+ The README is also the package page on npm and [pi.dev](https://pi.dev/packages/pi-dev-flow). Its doc
66
+ links use absolute GitHub URLs, because pi.dev rewrites relative links to raw files on jsDelivr.
package/docs/gates.md CHANGED
@@ -1,31 +1,193 @@
1
1
  # Gate reference
2
2
 
3
- Every gate, what it advances, and what makes it refuse.
3
+ Every gate: what it advances and what makes it refuse.
4
4
 
5
- You normally type none of this: the agent runs the gates and you answer words in chat. `/flow <sub>` is
6
- your **manual surface** — read state when the agent is confused, or advance a gate yourself when it is
7
- stuck or claims a result it never ran. Same gates either way; a `/flow` command you type asks you in a dialog,
8
- so it needs no `--confirmed`. The agent's own `flow` call never opens a dialog (#181): it returns
9
- `NEEDS-OPERATOR <Question?>` and the agent asks you in chat. A dialog answer is labelled
10
- `(confirmed in dialog)`, a chat answer `(confirmed by operator instruction)`.
5
+ You normally type none of this. The agent runs the gates, and you answer in chat. `/flow <sub>` is
6
+ your **manual override**: use it to read state when the agent is confused, or to advance a gate
7
+ yourself when the agent is stuck.
8
+
9
+ **How checkpoints work.** The agent's `flow` call never opens a dialog. A checkpoint gate refuses
10
+ with `NEEDS-OPERATOR <Question?>`, the agent asks you in chat, and it re-runs the gate with
11
+ `--confirmed` once you answer. A `/flow` command you type yourself asks you in a dialog instead.
12
+ `--confirmed` means "the operator literally answered this question". The agent must never add it on
13
+ its own.
14
+
15
+ ## Overview
11
16
 
12
17
  | Gate | Advances | Refuses unless |
13
18
  |---|---|---|
14
- | `start <slug> [--ui|--patch|--docs --confirmed] [--merge=squash\|merge\|rebase\|any] [--check-upstream]` | → plan | slug is new (binds the session); a `.dev-flow/<slug>/` left without `state.json` is a **ghost** it names with its contents and adopts on `--confirmed`, keeping the files (a `plan/` becomes the draft) — except a leftover `worktree/`, which it refuses with the cleanup to run first (gh#178); `use <slug>` on a ghost says the same instead of "no unfinished feature"; `--ui` and the relaxed modes are operator-granted in chat, anchored by `--confirmed` (`--ui` = the plan gate demands rendered mockups; on an existing feature still at plan, `start <slug> --ui --confirmed` from its bound session switches the flag on instead of refusing); `--patch` = chore release, no plan document, every gate unchanged; `--docs` = docs-only, no plan document and no tier-1 checks (worktree and release intact). Start prints the dev-flow build and stamps it into the feature state (`flow status` shows `flow=<ver>`), warns when **this session runs an older build than the checkout** (`--check-upstream` also asks npm for the published one), prints the playbook gaps `flow doctor` would report — and **refuses while the playbook has no `merge` policy**: it names the question (squash / merge / rebase / any), the style its own history suggests, and the re-run `--merge=<style> --confirmed`, which writes the answer into `## release` (single-line insert, validated, `.bak` kept, committed as a playbook chore only when the playbook is the only dirty path) and never asks again |
15
- | `use <slug>` | — (binds this session to a feature) | slug unfinished — the binding is persisted to disk as a claim (`flow version` lists every dev-flow copy registered in the process, and a copy whose in-memory bindings never saw the bind attributes commands from the claim, so a two-sources setup does not misjudge your git) |
16
- | `approve [--yolo]` | plan → implement (creates worktree + branch) | `plan/plan.md` exists **by name** (a separate pre-plan/direction file does not open the gate — a preliminary direction belongs inside plan.md); if `--ui`, rendered mockup screenshots (per `mockupGlobs`, default `*.png`) exist under `plan/` — headless chromium renders embedded in plan.md, and the gate opens plan.md to prove it: every image file under `plan/` must appear in an embed (`![...](…)`, case-insensitive) and every `mockups/<screen>.html` must carry an embedded `<screen>-<width>.` shot, and no mockup may link (href/src/@import) into another feature's `.dev-flow/<other>/worktree/`; **one question** — or `--confirmed` after you answered in chat; **yolo** (your chat answer at **any** checkpoint question) → run that gate with `--yolo --confirmed` (`approve`/`verify`/`release`/`finish`): that question is answered and every later one (Verified?/Release?/Finish?) is pre-confirmed — the agent then runs the remaining gates back to back, honoring guidance attached to the yolo word (e.g. "yolo, create a patch version release") — checks and guardrails stay fully enforced. `commands.setup` runs in the worktree and is retried until it succeeds once (a worktree left behind by a failed setup is set up on the next `approve`, never silently reused); a `--docs` feature runs no project command at all and says `setup skipped (docs mode)` |
17
- | `test` | records a check | — (runs the `test` command/check, records pass/fail) |
18
- | `check` | records all tier-1 checks | — (runs every `flow-check`/test/health from project.md `## implement`); a `--docs` feature runs none of them and says `docs mode: project commands skipped` — a docs flow builds nothing, so a fresh checkout must not read as a failed deploy (#96) |
19
- | `health` | records a check | — (runs `seedData` + the health command, retrying up to `healthWait` seconds; app must be up locally with real data) |
20
- | `verify [--yolo] [--port=<n>\|--replace] [--version=<v>\|--no-version]` | implement → pre-release | **the release call rides on Verified?** (gh#198): on a versioned project (`versionFile`) whose playbook leaves `version = ask`, the NEEDS-OPERATOR Verified? also asks *a patch, minor or major release (each with the number it makes from the manifest's current version), or merge unreleased?*, and `--confirmed --version=patch|minor|major` (or an exact `--version=<v>`) / `--confirmed --no-version` records the answer (`release call: …` in the output, the version on the stage line) so pre-release prepares the right thing; a playbook `version = versioned \| unversioned` makes the call for every flow, and a re-verify keeps the recorded call unless it is given again; **at pre-release it is the re-verify** (gh#187): after review fixes it runs the same build, deploy and probes over the current tree (no rebase), re-asks Verified? — a standing yolo never answers it — and on the answer moves the verdict (`verifiedHead`) to that tree, staying in pre-release; **without `--confirmed` it is the review deploy**: it fetches and, when the branch is behind `origin/<default>` (or local `<default>` with no remote), **rebases** it — untracked files never block, uncommitted tracked edits and conflicts refuse (the rebase is aborted, the branch untouched); when the dev port (playbook `port`, or the whole stack when none is set) was last deployed by **another live flow** it refuses with `NEEDS-OPERATOR Dev port?`, the measured RAM/disk against `instanceMem`/`instanceDisk`, and the options: run alongside on the next free port (offered only when `parallelDev` is not `no`, `dev`/`health` read `$DEV_FLOW_PORT`, and the resources fit), `--replace`, or wait — nothing is built first; then it deploys and returns `deployed for review` with the chat question. **With `--confirmed`** it never rewrites history: a default branch that moved since refuses (re-run `flow verify`). With `servedBuild` set the served commit must be the worktree's HEAD. Otherwise: all tier-1 checks green — a check with no passing record is **run by the gate itself** (`checks ran at the gate (test)`) rather than refused and pointed at `flow check`, since entering the stage or editing the worktree is what cleared it — and so is a record whose worktree fingerprint differs from the tree now (`stale record(s) rerun after a worktree change: …`): a change made through bash fires no edit-tool hook, the fingerprint is what notices the tree moved — and a failure there prints the run output, **the feature branch holds at least one commit** (verify refuses a branch with nothing committed — the checks describe the working tree, so an uncommitted state has never been recorded — except a **release-only flow** (#161): on a versioned project an empty branch over unreleased commits on the default branch (since the newest local version tag, or all of them before the first release) passes, the line says `release-only flow: N unreleased commit(s)`, and the version bump is the pre-release commit; with nothing unreleased the refusal says there is nothing to release; and prints `commits: N ahead of <default>, M uncommitted path(s)` with what it ran; uncommitted paths are reported, never gated), build (if configured) green, `dev` deploy (if configured) runs first so you can review the running app **and the health probe (if configured) re-runs against what it just deployed, retrying every 2s up to `healthWait` seconds** (a failing probe refuses the gate and reports how many attempts it took: the `flow check` PASS predates the deploy, and a service that needs seconds after its container starts is not a broken deploy; with no probe the output says `health: none configured`); with **no `dev` command but a `health` probe configured the gate live-re-probes the app before asking** (`health: live re-probe PASS` — a killed server refuses with `live probe FAILED`, because process death dirties no worktree fingerprint and a green record alone cannot prove liveness: start the app and rerun), tier-2 checklist (ui-only items excluded for non-UI features) confirmed as a set; a `--docs` feature runs none of it (`docs mode: project commands skipped`) and only asks you; **one question** — or `--confirmed`; `--yolo --confirmed` = you answered 'yolo' at Verified? — answers it and pre-confirms the rest |
21
- | `release [--yolo|--version=<v>|--no-version|--no-fold-check|--no-marker-check]` | pre-release → release | **the branch carries the release call** (gh#198), checked before the generic version proofs: a patch/minor/major call is **counted from the newest tag at release time**, so when a parallel flow released the number first the refusal names the new one (`bump VERSION to 1.2.0 (minor past 1.1.0) — v1.1.0 was released since Verified?`) and the call still stands; an exact version another flow already tagged is refused as **taken**, for the operator to re-make; a manifest that does not say the version the operator chose, or a bump on a flow whose call is *merge unreleased* (the manifest differs from the merge base's), is refused — re-make the call with `--version=<v>` / `--no-version` and `--confirmed` on the operator's word; **`release.ask = on-change`** (the default; `ask = always` asks every time) answers Release? itself (`auto-answered: release.ask = on-change — …` in the approved line) when the call is on record, a Verified? tree is on record, nothing but release prep landed after it, the session build is current, the playbook does not set `yolo = until-release`, and a playbook-made versioned call is not a major bump — otherwise Release? is asked as before, naming why (`asked: …`) — a call re-made on the release command without `--confirmed` is one of those reasons, since the call is the operator's, and with no call on record it asks that too; checks re-greened after the prep edits; `release.preflight` (when set) passes in the worktree — the build the tag will trigger, proven before anything ships; **the branch adds no merge-conflict marker lines** vs its merge base (#164: a hand-resolved merge that kept a `<<<<<<<`/`>>>>>>>` line is refused with `file:line`; `--no-marker-check` on the operator's word when the lines are meant); **commits after Verified?** are named in the Release? question and the approved line (#162: the operator's word covers the HEAD verify stamped — a warning, never a refusal); a **standing yolo** (given at an earlier checkpoint) does not answer Release? when such commits exist, nor ever under `yolo = until-release` in `## release` — the gate returns NEEDS-OPERATOR Release? (gh#176), while `--confirmed` (the operator's answer, a yolo said at Release? included) still passes; **the worktree holds no uncommitted paths** (gh#131: a merge ships the branch, not the working tree — an uncommitted fix at this gate is a fix that never ships; the refusal lists the paths, and the approved line prints `commits: N ahead of <default>, M uncommitted path(s)` like verify's); with `versioning.file`: the manifest version parses and is **not tagged yet** (the bump must be ahead of the last release); with `release.changelog` the gate **proves the entry mechanically** (#97): a **heading names the version** (prose that mentions it, or a `1.2.0-beta` section when releasing `1.2.0`, is not an entry), **this branch touched the file** (an inherited changelog is not release prep), **every entry that was pending before the release survives inside the new section** — compared on normalized lines, so re-indenting a fold is free while rewording or deleting one is refused by naming the line — and **nothing is left under `Unreleased`**. The proofs guard the **baseline's** pending lines — they do not freeze the wording of the entry this flow writes, so a branch that landed as several iteration commits is free to state its result as one entry (see the changelog-writer rule in the pre-release reference). The pending baseline is the newest tag's changelog (what actually shipped), else the branch's merge base; when neither resolves, the two git-dependent proofs are skipped **with a printed advisory** rather than refusing a legal release for a topology reason, and the content proofs (the heading, its body) always run; tier-2 `## pre-release` checklist confirmed; the manifest version it validates is **stamped as the release's version of record** (`release-done` publishes that, whatever the checkouts say later); **one question** (Release?) — or `--confirmed`; `--no-version` (your call at Release?) ships this flow as **merge + changelog** — the bump/tag requirements and the tag checks at `release-done` are skipped for it, but the branch must still add its **own line under `Unreleased`** (a `--docs` flow is exempt — #163: a playbook/docs change owes no user-facing entry; one it writes is welcome, not proven) (editing an older section releases nothing) and it rides there until the next versioned release folds it (default: versioned); `--no-fold-check` is the operator-granted escape from the line-level fold proofs — one flow, stamped in the gate output, the heading and touched proofs stay; **stale session build** (loaded build behind the checkout): the gate prints both builds, lists what shipped between them (those proofs will not run this release) and folds *update (/reload, then re-run) or proceed with the old release?* into the Release? question — the operator's word, recorded in the release output, **never a block**: publishing under an older gate is a legitimate choice (hotfix, offline reload) |
22
- | `release-done` | records the release (the stage stays `release`) | **no question — the Release? answer covered the publication**; verify approval; the version published is the one `release` **stamped** from the manifest it validated (a main checkout still behind cannot republish the previous version), and it must not be older than the newest matching tag **on origin** (tag lists come from `git ls-remote`, so an unfetched clone does not decide what exists; when an origin exists but cannot be asked (offline, no ssh agent) **both release gates refuse** rather than answering with local tags); with `versioning.file`: that tag exists, is reachable from the default branch **and is on origin** (a local-only tag is not a release); with `release.artifact`: the published-artifact check runs (`{version}`/`{tag}` placeholders — the line it prints names the version it verified; skip once with `--no-artifact-check`, operator-instructed only; on GitHub a miss right after the tag push **waits for the CI runs that tag started** — up to 15 min, plus a minute's grace for a registry that lags the green run — then probes again, and a refusal names a failed or still-running run with its URL, gh#179) · creates the forge release from the tag, its body **the `release.changelog` entry for that version** — the changelog is the source of truth, and the tag's annotation stands in only when the changelog has no entry for the version, else nothing (and it says why — a body that is really a shell error is dropped, never shipped) — `gh` for GitHub, `glab` for GitLab) and then **proves the release exists**: it asks the forge (`gh release view <tag>` / `glab release view <tag>`) and refuses when nothing is there, because #51, #60 and #63 were three ways of ending `release recorded as complete` with nothing published — and when the changelog was the body it **reads the stored body back** and refuses a mismatch, so the release page and the changelog cannot drift (#97; normalized before comparing, skipped with a printed note on another forge). Skipping is deliberate and loud — `--no-release-create`, `release.releases = false` or `forge = self` each print that no forge release was created, and the view check is skipped for them; **with a `merge` policy** it also proves the merge that shipped matches it — branch ancestry plus what the forge says (`gh pr view` / `glab api`), so a squash under `merge = merge` (or a merge commit under `merge = squash`) refuses the release record, while a shape it cannot see prints an advisory instead (#97's split: an invisible topology never blocks a legal release); when the release went out on a stale build the operator acknowledged at the release gate, it prints that acknowledgement in place of the after-the-fact version-skew warning, and that warning prints the session vs disk version pair plus the duplicate-copy note when a second copy is registered (#117) |
23
- | `finish [--yolo] [--no-reflect] [--note=<text>] [slug]` | release → done — **records an unrecorded release first** (published but `release-done` never ran: finish runs its proofs itself — that gate asks nothing, so it is not a separate step; its refusal is finish's) — **then the closing reflection**: while no reflection is recorded for the flow, finish starts the reflect worker before it touches anything and stops for the operator's fold/drop (or Finish? when nothing was found); a flow with **no friction** (no gate refusal, no guard block, no `--note`) skips the worker unless the playbook sets `reflect = always`; the re-run with `--confirmed` does the cleanup. `--no-reflect --confirmed` skips it on the operator's explicit word (yolo never does); `--note=` hands the worker the operator's friction notes. Cleanup (removes worktree + branch, deletes `.dev-flow/<slug>/`, and deletes `origin/<branch>` **only** when its merged state is verified — ancestor of the default branch or a merged PR/MR via `gh`/`glab`; unverifiable branches stay with a note) | a release is recorded (`release-done` ran), the main checkout is clean **and** pushed to `origin/<default>`, and the worktree has no uncommitted changes (the refusal lists the paths, not just the count — gh#131); when the clean checkout trails `origin/<default>` the gate **fast-forwards local main** as it closes out (never a merge — anything that cannot fast-forward prints the operator's exact `git pull --ff-only` command); **one question** (Finish? — mentions unmerged-looking commits with the playbook's `merge` policy in mind, and warns when the forge release create failed at `release-done` and no retry succeeded) — or `--confirmed`; under `merge = merge`, commits that never reached the default branch are a **policy violation**: `yolo` does not answer it, only your explicit answer does; to abandon an unreleased feature use `abort` |
24
- | `reflect ["<note>"|list|tidy|move <n> --playbook|--code|done <n> ["<what>"]]` | — | `reflect "<note>"` queues a suggestion in **this project's** `reflections.md` (never gates; gate flags such as `--confirmed` are ignored, they never become part of the note). `--playbook` (alias `--docs`) files it under `## playbook` — the fix lives only in `project.md`, a docs flow implements it; `--code` files it under `## code` — the fix touches project code, a patch flow implements it. `--plugin` **never writes**: dev-flow feedback is filed upstream, so it prints the recipe — `gh issue list --repo <dev-flow repo> --state all --search …` first, then `gh issue create` with a body ending `— reflection from <slug> <date>` (in the dev-flow repo itself plugin is code → `## code`). With no flag the wording guesses (plugin-shaped → the recipe; otherwise `## playbook`) and the echo prints why. `reflect list` numbers the open items with their section; `reflect move <n> --playbook|--code` re-files one; `reflect done <n> ["<what>"]` checks a fixed one off (`— fixed: <date> <slug> — <what>`) so doctor stops re-reporting it; a legacy `## plugin` row is flagged by list and doctor (file it upstream, check it off `— filed: gh#NNN`). `reflect tidy` drops the closed (`- [x]`) items — the preamble and open items stay verbatim and a `## section` heading left empty goes with its items. **Nudges are timed, not constant**: `⚑ fix the open reflections now?` prints when an item recurred this session, is ≥ 14 days old, ≥ 3 playbook items wait, or a code item waits while between flows — at finish, in an unbound session and in doctor, never mid-feature; `↻ N closed reflection(s)` prints at ≥ 5 closed, closed ≥ open (≥ 3), or a closed item ≥ 30 days old. Bare `reflect` prints the **session-reflection protocol** (from the `/flow reflect` bar it additionally wakes the model): bound to a flow, delegate the review to `flow_stage` op `reflect`; unbound, review inline; re-check every open item against the playbook and **newer dev-flow versions** (`npm view pi-dev-flow version`; the operator performs updates); show the operator a numbered list with a fold/drop recommendation per finding and stop; fold docs/code → `reflect --playbook|--code`, fold plugin → the upstream issue, drop → nothing recorded |
25
- | `roadmap [add "<feature>" [--slug=<slug>] [--brief=<notes>\|--brief-file=<path>] \| pick <n> <slug> \| done <n> \| drop <n> \| tidy]` | — | manages `.dev-flow/roadmap.md`, the gitignored backlog of future features (`- [ ]` checklist): bare prints the numbered open items, `add` appends one (`--slug=` stamps it like pick, `--brief=`/`--brief-file=` keeps notes under it as ` > ` lines, and a bound session records `— split from <slug>` — the spin-off route for a new feature surfaced mid-flow), `pick <n> <slug>` stamps open item n with `(slug)` so `flow start <slug>` can take it (start seeds `plan/plan.md` with the item and its brief) — **`finish` checks the stamped item off when that feature ships**; `done <n>` checks off by hand (items shipped outside a flow), `drop <n>` (alias `remove`) deletes an open item and its brief that nobody wants any more — `done` would record it as shipped — `tidy` drops the checked lines. Never gates; the open count is surfaced in `status` and session context |
26
- | `doctor ["<issue note>"]` | — | read-only findings: playbook drift, dead commands/scripts, untracked playbook, ghost feature dirs, orphan worktrees/branches — the state of an **aborted** feature is never a finding (its worktree cleanup is by design — gh#138) — **plus a review of every open reflection, each routed to the flow that should fix it** (playbook item → docs flow; plugin item → upstream issue, or a patch/normal flow inside the dev-flow repo) — every item is labelled from the `## section` it is filed under (the file is the record, so the table cannot disagree with it) and items sitting outside both sections are named rather than silently bucketed. It writes nothing and asks nothing, safe for agents and CI at any stage; the agent investigates, you confirm, the routed flow implements. `doctor "<note>"` prints an investigation brief and a fix route for a fresh observation, including the section it would be filed under and why |
27
- | `status [slug]` / `abort [slug]` | — | — |
28
- | `help` (`--help`, `-h`) | — | — (prints the gate help — answerable in any repo, at any stage, with no `.dev-flow/`) |
29
- | `version [--check-upstream]` | — | — (prints dev-flow's **own** version and the directory it was loaded from — which copy this session runs, this checkout vs an installed `pi-dev-flow`; when the checkout has moved past the build this session loaded it says so and names both, because the gates execute the loaded code — `/reload` to run the newer one; `--check-upstream` adds the published npm version; answerable in any repo, at any stage, with no `.dev-flow/`) |
30
-
31
- `--confirmed` is the operator-presence flag: pass it only after the operator literally answered the stage question in chat — one checkpoint per stage, no second dialog.
19
+ | `start <slug>` | → plan | the slug is new and the playbook has a `merge` policy |
20
+ | `use <slug>` | binds this session | the feature is unfinished |
21
+ | `approve` | plan → implement | `plan/plan.md` exists (plus embedded mockups for `--ui`) and you said yes |
22
+ | `verify` | implement → pre-release | the branch has commits, checks are green, the deploy is healthy, and you said yes |
23
+ | `release` | pre-release → release | the version and changelog are right, nothing is uncommitted, and you said yes (or it answered itself) |
24
+ | `release-done` | records the release | the tag is on origin, the artifact is published, and the forge release exists |
25
+ | `finish` | release → done | the release is recorded, main is clean and pushed, and you said yes |
26
+
27
+ Tools that never gate: `test`, `check`, `health`, `status`, `abort`, `doctor`, `reflect`, `roadmap`,
28
+ `help`, `version`.
29
+
30
+ ## start
31
+
32
+ `flow start <slug> [--ui | --patch | --docs] [--merge=<style>] [--check-upstream]`
33
+
34
+ Creates the feature, binds this session to it, and renames the session after the slug.
35
+
36
+ - `--ui` means the plan gate requires rendered mockups. `--patch` (a small fix, no written plan) and
37
+ `--docs` (docs only, no build checks) are lighter modes. All three need your OK in chat, and the
38
+ agent then adds `--confirmed`.
39
+ - **The playbook needs a `merge` policy.** If it has none, start asks which style to use (squash,
40
+ merge, rebase or any), suggests one from your git history, and writes your answer into
41
+ `## release`.
42
+ - It prints the dev-flow version, warns if this session runs an older build than the checkout
43
+ (`--check-upstream` also asks npm), and lists playbook gaps.
44
+ - A leftover `.dev-flow/<slug>/` without `state.json` (a "ghost") is shown to you and adopted on
45
+ `--confirmed`, unless it still holds a `worktree/`.
46
+ - If the roadmap has an item picked for this slug, the plan starts from it.
47
+
48
+ ## use
49
+
50
+ `flow use <slug>` binds this session to an unfinished feature, records a claim on disk, and renames
51
+ the session. It also takes over a feature another session holds. Nothing binds automatically.
52
+
53
+ ## approve: Approve?
54
+
55
+ `flow approve [--yolo]`
56
+
57
+ - `plan/plan.md` must exist with exactly that name.
58
+ - For a `--ui` feature, every screenshot under `plan/` must be embedded in plan.md, every
59
+ `mockups/<screen>.html` needs a `<screen>-<width>.png` render, and no mockup may link into another
60
+ feature's worktree.
61
+ - On yes, it creates the worktree and the `feat/<slug>` branch, then runs `setup` there. If setup
62
+ fails, the next `approve` retries it.
63
+
64
+ ## test, check, health
65
+
66
+ - `flow test` runs the `test` command and records the result.
67
+ - `flow check` runs every tier-1 check from `## implement`.
68
+ - `flow health` runs `seedData` and then the health probe, retrying for up to `healthWait` seconds.
69
+
70
+ Each record carries a fingerprint of the worktree. When the tree changes, the record goes stale and
71
+ the next gate re-runs it. A `--docs` flow runs none of these.
72
+
73
+ ## verify: Verified?
74
+
75
+ `flow verify [--yolo] [--version=patch|minor|major|<v> | --no-version] [--port=<n> | --replace]`
76
+
77
+ Run without `--confirmed`, it deploys for your review:
78
+
79
+ 1. Fetches, and rebases the branch if main moved ahead. Conflicts or uncommitted tracked edits
80
+ refuse, and the branch is left untouched.
81
+ 2. Checks the dev port. If another live flow holds it, it asks **Dev port?**: run alongside on
82
+ another port, replace that deploy, or wait. See [concurrency](concurrency.md).
83
+ 3. Runs the checks (re-running any that are stale or missing), the build, the `dev` deploy, and then
84
+ the health probe against what it just deployed.
85
+ 4. Asks **Verified?**
86
+
87
+ It refuses if:
88
+ - the branch has no commits (except a release-only flow on a versioned project with unreleased
89
+ commits on main);
90
+ - a check, the build or the post-deploy health probe fails;
91
+ - `servedBuild` is set and the running app isn't serving this commit.
92
+
93
+ **The release call rides on Verified?** On a versioned project with `version = ask` (the default),
94
+ the question also asks: *patch, minor or major release, or merge unreleased?* Your answer is recorded
95
+ with `--version=…` or `--no-version`.
96
+
97
+ With `--confirmed`, it never rewrites history. If main moved since the review deploy, re-run
98
+ `flow verify`.
99
+
100
+ **At pre-release, `verify` is the re-verify:** after review fixes, it re-runs the build, deploy and
101
+ probes on the current tree and asks Verified? again. A standing yolo never answers this.
102
+
103
+ ## release: Release?
104
+
105
+ `flow release [--yolo] [--version=<v> | --no-version] [--no-fold-check] [--no-marker-check]`
106
+
107
+ Proves the branch is ready to ship:
108
+
109
+ - **The version** matches your release call. Patch, minor or major is counted from the newest tag
110
+ at release time, so if a parallel flow shipped first, yours moves to the next number.
111
+ - **The version is new**: the manifest's version isn't tagged yet.
112
+ - **The changelog** has a heading for this version, this branch edited it, every entry that was
113
+ pending under `Unreleased` is kept in the new section, and `Unreleased` is now empty.
114
+ - **Merge unreleased** (`--no-version`): no bump, but the branch adds its own line under
115
+ `Unreleased`. Docs flows are exempt.
116
+ - The checks are green again after the prep edits, and `release.preflight` passes if set.
117
+ - There are no leftover conflict markers (`<<<<<<<`) and no uncommitted files in the worktree.
118
+
119
+ **Release? often answers itself** (`ask = on-change`, the default). That happens when your call is
120
+ on record and only release prep (bump, changelog) changed since Verified?. It still asks when:
121
+ - code changed after Verified?;
122
+ - the session runs an old build (proceeding is allowed, and it says what you'd miss);
123
+ - the playbook sets `yolo = until-release`;
124
+ - it's a major bump the playbook made rather than you.
125
+
126
+ Set `ask = always` in `## release` to be asked every time.
127
+
128
+ Escape hatches, used only on your word: `--no-fold-check` skips the line-level changelog check, and
129
+ `--no-marker-check` allows intentional conflict-marker lines.
130
+
131
+ ## release-done
132
+
133
+ Records the release. It asks no question, because your Release? answer covered it. `finish` runs it
134
+ for you if the agent didn't.
135
+
136
+ - The tag exists, is reachable from main, and is **on origin**. If origin can't be reached, it
137
+ refuses rather than trust local tags.
138
+ - `release.artifact` (for example `npm view <pkg>@{version} version`) passes. On GitHub, it waits
139
+ for the CI runs the tag started.
140
+ - It creates the forge release (`gh` / `glab`), using the changelog entry as the body, then reads it
141
+ back to confirm it exists and matches.
142
+ - It checks that the merge matched the `merge` policy. If that can't be seen (self-hosted forge, no
143
+ CLI), it prints a note instead of refusing.
144
+
145
+ Skip flags (on your word): `--no-artifact-check`, `--no-release-create`. You can also set
146
+ `release.releases = false` or `forge = self` to skip creating the forge release.
147
+
148
+ ## finish: Finish?
149
+
150
+ `flow finish [--yolo] [--no-reflect] [--note=<text>] [slug]`
151
+
152
+ 1. Records the release if `release-done` never ran. If the `## release` checklist still has open
153
+ items, it stops and lists them.
154
+ 2. Runs the **closing reflection** (see [reflections](reflections.md)) and waits for your fold/drop.
155
+ 3. On `--confirmed`, cleans up: removes the worktree, the branch and `.dev-flow/<slug>/`. It deletes
156
+ the remote branch only once it's proven merged. If local main is just behind origin, it
157
+ fast-forwards it.
158
+
159
+ It refuses until the release is recorded, the main checkout is clean and pushed, and the worktree has
160
+ no uncommitted changes. Under `merge = merge`, commits missing from main are a policy violation that
161
+ yolo can't answer.
162
+
163
+ To drop an unreleased feature, use `flow abort` instead.
164
+
165
+ ## reflect, roadmap, doctor
166
+
167
+ - `flow reflect …` manages the notes queue. See [reflections](reflections.md).
168
+ - `flow roadmap [add "<feature>" [--slug=] [--brief=] | pick <n> <slug> | done <n> | drop <n> | tidy]`
169
+ manages `.dev-flow/roadmap.md`. `pick` stamps an item for `flow start <slug>`, and `finish` checks
170
+ it off when the feature ships.
171
+ - `flow doctor ["<note>"]` is a read-only health report: playbook drift, dead commands, ghost
172
+ folders, orphan worktrees and branches, and a review of every open reflection. It writes nothing,
173
+ so it's safe at any stage and in CI.
174
+
175
+ ## status, abort, help, version
176
+
177
+ - `flow status [slug]` shows where every feature stands. `--json` gives machine output.
178
+ - `flow abort [slug]` drops a feature.
179
+ - `flow help` (`--json`) prints the gate contract.
180
+ - `flow version [--check-upstream]` prints which dev-flow copy this session runs and whether the
181
+ checkout is newer.
182
+
183
+ These work in any repo, even without `.dev-flow/`.
184
+
185
+ ## yolo
186
+
187
+ Answering **yolo** at any checkpoint runs that gate with `--yolo --confirmed`. That answers the
188
+ question and pre-confirms the rest, so the agent runs the remaining gates back to back, following
189
+ any wishes you added ("yolo, patch bump"). Every check and guard still applies. Yolo never answers:
190
+ - the re-verify at pre-release;
191
+ - Release? when code changed after Verified?, or when the playbook sets `yolo = until-release`;
192
+ - a `merge = merge` policy violation at finish;
193
+ - skipping the closing reflection.
@@ -1,30 +1,112 @@
1
- # Guardrails (the teeth)
2
-
3
- Everything dev-flow enforces while a feature is in flight, and what it deliberately does not do. Short version: [README → What is enforced](../README.md#what-is-enforced).
4
-
5
- While a feature is active, the extension intercepts every tool call:
6
-
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
- - **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. 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
- - **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
- - **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
- - **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. A path git ignores (`git check-ignore`, e.g. a per-machine secrets file listed in `.git/info/exclude`) is not source and stays writable unbound. Tracked and untracked-unignored paths are refused, and the refusal names that route (gh#175). `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.
13
- - **Gates can't be skipped**: flow state is untouchable by the agent (edit tool and bash) — writing `state.json` or `claim.json`, moving either away, or deleting a feature directory or the whole `.dev-flow/` folder all block, at a relative **or an absolute** path (an absolute path names the same folder); 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`; every recorded check carries a fingerprint of the worktree it ran against (paths, uncommitted diff, HEAD) — an edit-tool change clears the records at once, and any other write (`sed -i`, a formatter, codegen through bash) is caught at the gate itself, which reruns what went stale and says so; edit/write paths are judged by realpath, so a symlink out of the worktree cannot launder a confined write.
14
- - **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.
15
- - **The rules reach the agent, they are not left in a file it may never read**: pi advertises a skill and loads it only if the model chooses to, so the ground rules of the dev-flow skill are injected into every session once (and again after a compaction that summarized them away), and each stage's turn names the one playbook file that stage needs. The guards enforce the same discipline either way — this is what makes the agent follow it without being stuck.
16
- - **A forced push asks the operator**: `git push` carrying `--force`, `--force-with-lease…` or `-f` is confirmed before it runs — a rewritten branch is history CI and other sessions already have. The one spelling that answers for it is the prefix the refusal prints (`DEV_FLOW_ALLOW_REWRITE=1 git push -f …`), the same "the operator said so" contract as `DEV_FLOW_ALLOW_MAIN`. Local history rewrites (`git filter-branch --force`) are not pushes and stay free, so a project never needs a blunt flag-only deny of its own.
17
- - **Shell calls can't hang forever**: pi kills a shell command only when the model passed a `timeout` — it omits one in ~75% of calls, so a `gh` waiting on a prompt or a dead `curl` froze sessions for hours. In an initiated repo (`.dev-flow/project.md` exists) every shell call without one therefore gets the class default armed silently (30s quick inspection · 120s local git and unknown · 180s network · 300s containers/services · 900s builds/tests/installs · 1,200s watchers like `gh run watch`), and absurd explicit values clamp to 1,800s. A command that carries its own `timeout N` (coreutils, any option form, `s`/`m`/`h` suffixes) gets N + 15s, so its own timer fires first; an unreadable N falls back to the wrapped command's class. The armed value is **invisible in the call's arguments**: the transcript and pi-web's tool card show what the model wrote, and dev-flow sets the timeout after that. So when it is dev-flow's default that kills a command, the result gets a line saying so (`[dev-flow] stopped at 30s: dev-flow's default for quick commands, armed because the call stated no timeout…`), and the session's injected ground rules tell the agent the default exists. `test/e2e-timeout.test.ts` proves the kill end to end through a real pi session, so a host release that stopped honouring the hook would fail the suite. A project that wants the timeout visible on every call line sets `bashTimeout = require` in `## global` — then a call without one is refused, naming the value it would have armed (each refusal costs a turn, which is why it is no longer the default). Uninitiated folders hear nothing at all: without the playbook dev-flow enforces no rules.
18
- - **Compact-aware**: dev-flow paces compaction the way pi counts it: the self-compaction trigger uses the *effective* `reserveTokens` (settings and per-model overrides, not the built-in default) and is checked at every turn end, not only when a run settles. When pi force-compacts on its threshold anyway — the chat-only states (open tier-2 dialog, plan discussion not yet in `plan/`) refuse to self-compact by design — dev-flow takes the compaction over and redoes it with flow-aware summary instructions (overflow recovery keeps pi's compact-and-retry and is left alone). Auto-compaction turned off in settings is honored.
19
- - The active stage is injected into the model's context — in full when it changed (or after a compaction), as one line when it did not; the bundled `dev-flow` skill is the agent's playbook, including the recommended sequences: pre-release — review (`/flow-review`) → fixes → docs → changelog/version bump; release — PR → merge → tag → `finish` (which records the release first when `release-done` was not run). The package also bundles the review skills themselves — `/flow-review` (a change, read against its `plan/plan.md`), `/flow-audit` (the whole repo) and `/flow-simplify` (the operative cut: deletes dead and duplicated code, one verified commit at a time) — and injects a built-in senior-discipline guidance at implement stage unless the playbook sets its own `prose.implement`.
20
- - **Status bar**: an initiated repo (`.dev-flow/project.md` exists) always carries the dev-flow footer; while the session **is bound** to a feature it shows `<stage glyph> <slug>` plus mode markers — stages 📝 plan, 🔨 implement, 🔍 pre-release, 🚀 release; markers ⚡ patch, 📚 docs, 🎱 yolo, `💬` while a checkpoint (Approve?/Verified?/Release?/Finish?) still waits on the operator's word — the legend's "operator, your turn" glyph, the same one stage lines open with — and `⚠️` while a check of the bound feature fails (emoji render in their own color, so the footer carries no theme coloring). An **unbound** session never sees a slug — it shows `💬 N flow(s) open` (unfinished-feature count only, no warning marker) or `💬 no flows` when nothing is in flight: the pre-flow glyph, because an unbound session is parked on the operator by definition; a session binds only via `flow start`/`flow use`, never by opening. In **pi-web** status text is not clickable, so there the footer is a widget chip instead: the chip carries the footer's content packed to fit pi-web's fixed-width chip — bound: every glyph up front with no spaces, then the slug (`🔨⚡⚠️my-feature`, so only the slug's tail can clip); unbound: `💬 2 open` (hover shows a clipped label whole) and expands (click again to collapse) to one lean line per *other* unfinished flow — the bound flow is already the chip's label, so it is not repeated (alone in the repo, the panel says `no other flows open`); the stage word is spelled out, markers and `⚠️` follow the footer vocabulary; with nothing open (`💬 no flows`) it is a plain chip with nothing to expand. The TUI never shows it: a widget there is an always-present block, and in a terminal the footer stays the legend. The footer repaints at session start, at the start of every agent run (the earliest a late-attaching web client is listening) and after every gate; an uninitiated folder gets no footer at all. `flow status` is the spelled-out surface: `stage=implement`, the per-feature mode tags (`[ui]`, `[yolo]`, `[no-version]`), the `💬 <word>` marker of a checkpoint the operator has not answered, and the `flow=<ver>` stamp of the build that started the feature.
21
-
22
- ## Limitations (deliberate, v1)
23
-
24
- - Production deployment stays manual by design (phase 2 automation); `flow finish` only closes the flow.
25
- - Bash git-guard parses shell segments to find real `git` invocations (honoring `cd … &&`, `git -C`, full paths) and judges them by the branch of the directory the command runs in — the feature worktree when you work there. A `~` / `$HOME` in that directory is expanded the way the shell would (any other `$VAR` stays literal); when the directory cannot be answered for, no branch is invented — the guard stays quiet and git itself fails. A commit refusal names the directory it judged, so a wrong verdict is readable as one. Splitting respects quotes, so text inside `"…"` / `'…'` is an argument's prose, never a command: `gh pr create --body "…git commit…"` is not a commit. A wrapper that execs its argument (`sh`, `bash`, `node`, `python`, `env`, `xargs`, …) is judged on its payload — `sh -c "git push origin main"` is a push. An exotic wrapper (subshell, variable) could still slip past; the `.git` hook covers plain commits outside Pi too, but neither is a security sandbox.
26
- - `flow-guard` and the git guard are guardrails for what an agent types, **not a parser and not a sandbox**. Doing-verbs an agent types in the clear are caught; quoted prose is deliberately read as data, so a wrapper deciding to run something at runtime is out of reach. Write rules for the common mistakes, keep validation you actually depend on in scripts and CI.
27
- - `protect`/`forbid` judge edit/write tools against the repo root the session runs in — a copy of a protected file inside a feature worktree is a different path, and a bash redirect (`echo k > docker/secrets/k`) is a `deny` rule's job. A glob in the **last** segment matches the siblings of that directory (`protect docker/.env*` covers `.env` and `.env.bak-20261021`); a glob anywhere else names one literal path, so `flow init` warns that the rule guards nothing.
28
- - The read-only heads that get skipped (`find`, `awk`, `jq`, …) can write in their own dialects — `find . -delete`, `awk … > file`. A deny rule on `rm` does not cover them; write a rule for the effect you actually need to prevent.
29
- - Gate commands (`test`, `check`, `verify` build, `health`) run inside the feature worktree once it exists — the code under test lives there; before the worktree exists they run in the main checkout.
30
- - A bash segment whose first word is `flow` is always refused, with no per-project opt-out: dev-flow assumes the name is free because there is no `flow` CLI. A project that really ships a binary called `flow` calls it by path (`/usr/bin/flow`, `./node_modules/.bin/flow`) or through `npx` — the rule matches the head token only, so those pass.
1
+ # Guardrails
2
+
3
+ What dev-flow enforces while a feature is in flight, and what it deliberately doesn't do.
4
+
5
+ All of this applies only in an initialized repo, one where `.dev-flow/project.md` exists. Without the
6
+ playbook, dev-flow stays silent.
7
+
8
+ ## What is enforced
9
+
10
+ **Nothing lands on main until release.**
11
+ - `git commit`, `git merge` and pushes *to* the default branch are blocked at every stage except
12
+ `release`. Tag pushes and feature-branch pushes are fine from any stage.
13
+ - One exception: a commit whose only change is `.dev-flow/project.md`, since tracking your playbook
14
+ is setup, not feature work.
15
+ - A `pre-commit` hook covers commits made outside Pi.
16
+
17
+ **Shipping waits for `flow release`.** Before the release stage, tagging, merging the PR
18
+ (`gh pr merge`, `glab mr merge`) and creating a forge release are refused. Reads like `git tag -l`
19
+ and opening the PR are fine.
20
+
21
+ **No code before an approved plan.** During plan, the agent can only write in its own
22
+ `.dev-flow/<slug>/` folder.
23
+
24
+ **Work stays in the worktree.**
25
+ - During implement and pre-release, the agent can only write in its own feature's worktree. Each
26
+ write is judged by the feature that owns the path, so sessions can't write into each other's
27
+ worktrees.
28
+ - Paths are checked after resolving symlinks.
29
+ - Scratch files outside the repo (the OS temp dir) are always fine. A bound feature's `TMPDIR`
30
+ points to `.dev-flow/<slug>/tmp/`, which is cleaned up at finish.
31
+ - Creating a new branch inside a feature worktree is refused. An unrelated fix gets its own flow.
32
+
33
+ **No work outside a flow.**
34
+ - In a repo with `.dev-flow/`, an unbound session can't edit source files. Everything starts with
35
+ `flow start` or `flow use`.
36
+ - Files git ignores (like a local secrets file) stay writable.
37
+ - `flow start` requires the main checkout to be on the default branch.
38
+
39
+ **Gates can't be faked.**
40
+ - The agent can't write, move or delete `state.json`, `claim.json`, a feature folder or `.dev-flow/`
41
+ itself, through either edit tools or bash.
42
+ - The playbook is yours. The agent can only edit it inside a docs or patch flow's worktree, and every
43
+ sanctioned overwrite keeps a `project.md.bak`.
44
+ - Every check result is tied to a fingerprint of the worktree. Any change, even through `sed -i` or a
45
+ formatter, makes it stale, and the next gate re-runs it.
46
+
47
+ **Your own rules.** The `deny` / `confirm` / `protect` / `forbid` rules in your playbook's
48
+ `flow-guard` block run on every bash command and every edit, at every stage, before dev-flow's own
49
+ checks. A block always shows the reason you wrote. See the [playbook](playbook.md).
50
+
51
+ **Force pushes ask you.** `git push --force` / `-f` / `--force-with-lease` needs your OK. The
52
+ refusal prints the prefix that marks it as approved: `DEV_FLOW_ALLOW_REWRITE=1`.
53
+
54
+ **Shell calls can't hang.** The model often omits a timeout, so a `gh` waiting on a prompt could
55
+ freeze a session for hours. A shell call without a timeout gets a default for its kind:
56
+
57
+ | Kind | Timeout |
58
+ |---|---|
59
+ | quick inspection | 30s |
60
+ | local git, unknown commands | 120s |
61
+ | network | 180s |
62
+ | containers and services | 300s |
63
+ | builds, tests, installs | 900s |
64
+ | watchers (`gh run watch`) | 1,200s |
65
+
66
+ Explicit timeouts are capped at 1,800s. A command wrapped in its own `timeout N` gets N + 15s. When
67
+ dev-flow's default kills a command, the result says so. Set `bashTimeout = require` in `## global` to
68
+ refuse calls without a timeout instead.
69
+
70
+ **There is no `flow` CLI.** A bash command named `flow` is refused. Gates live inside the Pi session.
71
+ If your project ships its own `flow` binary, call it by path or through `npx`.
72
+
73
+ **The rules reach the agent.** Pi loads a skill only when the model decides to read it. So dev-flow
74
+ injects the ground rules (about a thousand tokens) into each session once, and again after a
75
+ compaction removes them. Each stage then names the one reference file it needs.
76
+
77
+ **Compaction is flow-aware.** dev-flow uses your effective `reserveTokens`. When Pi compacts anyway,
78
+ dev-flow redoes the compaction with flow-aware summary instructions. If auto-compaction is off in
79
+ your settings, dev-flow leaves it off.
80
+
81
+ ## Status bar
82
+
83
+ In an initialized repo, the footer shows the bound feature:
84
+
85
+ | Glyph | Means |
86
+ |---|---|
87
+ | 📝 🔨 🔍 🚀 | plan · implement · pre-release · release |
88
+ | ⚡ 📚 🎱 | patch · docs · yolo mode |
89
+ | 💬 | a checkpoint is waiting for your answer |
90
+ | ⚠️ | a check is failing |
91
+
92
+ An unbound session shows `💬 N flow(s) open` or `💬 no flows`. In pi-web, the footer is a chip you
93
+ can click to see the other open flows. `flow status` spells all of it out.
94
+
95
+ ## Limitations
96
+
97
+ These guards stop the common mistakes an agent makes. They are **not a security sandbox**.
98
+
99
+ - **Production deploys stay manual.** `flow finish` only closes the flow.
100
+ - **The git guard reads shell commands.** It splits commands into segments and understands
101
+ `cd … &&`, `git -C`, quotes, and wrappers like `sh -c`, `env` and `xargs`. An exotic wrapper
102
+ (a subshell, or a command held in a variable) can still slip past.
103
+ - **Quoted text is data.** `gh pr create --body "…git commit…"` isn't a commit. That means a command
104
+ built at runtime isn't caught either.
105
+ - **`protect` / `forbid` cover edit tools only, judged from the repo root.** A copy inside a
106
+ worktree is a different path. Use a `deny` rule to stop a bash redirect.
107
+ - **Read-only commands can still write.** `find -delete` and `awk … > file` can write, so a `deny`
108
+ on `rm` doesn't cover them. Write the rule for the effect you want to prevent.
109
+ - **Where gate commands run.** Before the worktree exists, gate commands run in the main checkout.
110
+ After that, they run in the worktree.
111
+ - **Keep real validation in CI.** Write rules for common mistakes, and keep checks you truly depend
112
+ on in scripts and CI.