pi-dev-flow 0.59.1 → 0.61.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +4 -0
- package/docs/concurrency.md +3 -1
- package/docs/gates.md +1 -1
- package/docs/guardrails.md +3 -3
- package/docs/headless.md +6 -2
- package/extensions/dev-flow.ts +72 -20
- package/package.json +1 -1
- package/skills/dev-flow/SKILL.md +1 -1
- package/src/core.ts +69 -78
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,26 @@ Format: newest first. `Unreleased` collects what's merged but not yet tagged.
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.61.0] - 2026-10-23
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- **A green now belongs to the tree it ran against.** Every recorded check carries a fingerprint of its worktree — `status --porcelain`, a hash of the uncommitted diff, and HEAD — and `verify`/`release` drop records the tree has outgrown before deciding what is pending, then rerun them at the gate and say so (`stale record(s) rerun after a worktree change: …`). Edits through the edit tools already cleared records at once, but a write through bash — `sed -i`, a formatter, codegen — fires no hook, and the whole #84 sequence (check green, a bash-side fix, `verify`) rode a PASS measured against code that no longer existed. A commit after the check now re-proves at the gate too, so a green standing at a gate means the committed state. A record with no fingerprint (older build, or git could not answer) is never proven stale — the same measurement-failure stance as `commitsAhead`.
|
|
12
|
+
- **The delete guard reads absolute paths.** `rm -rf /abs/repo/.dev-flow/<slug>` deleted a feature — plan included — while the relative form was refused: `DF_FOLDER` demanded whitespace or a quote before `.dev-flow`, and absolute paths are the shape harnesses hand the agent. The boundary now accepts `/` too; quoted prose stays prose (the masked-payload exemption, #53, survives).
|
|
13
|
+
- **`flow abort` honors a live claim, and `claim.json` is now guarded.** Every gate refused another session's in-flight feature — except the one verb that deletes the whole feature: an unbound or other-session abort could erase a plan-stage directory while its owner was still writing it. The claim now locks `abort` exactly as it locks the gates (`flow use` remains the only takeover), and `claim.json` joins `state.json` as flow-owned in both guards — a lock is not unlocked by whoever it locks out.
|
|
14
|
+
- **`writeGuard` judges where the bytes land, not where the path points.** A symlink inside the worktree laundered a write anywhere: the stage rules compared lexical strings, so a worktree symlink into the main checkout passed a main-checkout write as confined — while `guardPath` had resolved the same symlink through realpath all along. The target, the feature worktrees and `.dev-flow` are now compared as realpaths (`realAbs`), and a symlinked escape gets the refusal its real target deserves.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- **The UI plan hint names its file instead of eating it.** With `--ui`, the hint's mockup clause replaced the sentence's tail, leaving "write the plan into .dev-flow/<slug>/plan/" pointing at a directory; it now reads `plan/plan.md` and appends the mockup clause. Approval always demanded a real file — the hint just stopped saying so.
|
|
19
|
+
- **`buildConfig` leaves production code.** Nothing at runtime has built a `Config` from a raw object since `project.md` became the only config source — the tests keep the shorthand as a test helper. `getPath` (dead once the `project.json` loader was gone) and `gitInvocation`'s unused top-level last-cd-wins `dir` (the guard judges each segment's own dir) were deleted with it.
|
|
20
|
+
|
|
21
|
+
## [0.60.0] - 2026-10-23
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- **dev-flow is fully dormant until the playbook exists — and fully present after.** *Initiated* now means exactly one thing: `.dev-flow/project.md` (written by `flow init`) exists. Until then a folder hears nothing at all: no context injection, no footer, and no guards — the stage discipline, main-branch git rules and the bash-timeout refusal and its silent arming included (`flow init` is the opt-in; a stray `.dev-flow/` without the playbook keeps the folder asleep), and every gate verb but `flow init`/`flow version` says so plainly instead of half-running. Once initiated, the footer never goes silent: bound sessions see the stage glyph + slug as before, unbound ones the `⧖ N flow(s) open` count, and a repo with nothing in flight now shows `⧖ no flows` instead of nothing — you can see dev-flow is watching. The footer also repaints at the **start** of every agent run, not just at session start and turn end: `setStatus` is a fire-and-forget push in pi-web, and run start is the earliest moment a late-attaching web client is certainly listening (a push the browser missed before attaching could leave the bar blank until the next gate).
|
|
26
|
+
|
|
7
27
|
## [0.59.1] - 2026-10-23
|
|
8
28
|
|
|
9
29
|
### Fixed
|
package/README.md
CHANGED
|
@@ -56,6 +56,10 @@ package — so keep the one you actually update from: `flow version` lists every
|
|
|
56
56
|
registered in the process, and the on-disk session claim keeps the guard of a copy that never served
|
|
57
57
|
a flow call attributing your commands correctly.
|
|
58
58
|
|
|
59
|
+
Until `flow init` writes the playbook (`.dev-flow/project.md`), dev-flow says nothing in a repo — no
|
|
60
|
+
injections, no guards, no footer: the playbook is the opt-in. A stray `.dev-flow/` without it keeps
|
|
61
|
+
the folder dormant.
|
|
62
|
+
|
|
59
63
|
Then, once per project repo, `/flow init`. It reads the repo (default branch and forge from git,
|
|
60
64
|
package manager, test/build/run conventions, version manifest) and writes **`.dev-flow/project.md`
|
|
61
65
|
— your playbook**: the commands that count as checks, the manual checklist, the version and tag
|
package/docs/concurrency.md
CHANGED
|
@@ -8,7 +8,9 @@ case. The binding lives with the session (persisted via session entries, restore
|
|
|
8
8
|
resume/fork), so nothing is repo-global. A session binds **explicitly, never automatically**:
|
|
9
9
|
`flow start` binds its own feature, `flow use <slug>` takes one over — even the lone unfinished
|
|
10
10
|
feature waits to be claimed. Every bind leaves a claim (`claim.json`, session + pid),
|
|
11
|
-
and the gates honor the claim too
|
|
11
|
+
and the gates honor the claim too — `flow abort` included, so the verb that erases a feature cannot
|
|
12
|
+
erase one a live session is working. The claim file is as guarded as `state.json`: neither the write
|
|
13
|
+
tools nor bash may change or delete it — a lock is not unlocked by whoever it locks out.
|
|
12
14
|
passing another session's slug to `flow approve`/`verify`/`finish` is refused until you take over,
|
|
13
15
|
or two sessions quietly overwrite one state file. `flow use <slug>` switches, and ambiguous sessions must
|
|
14
16
|
bind or pass explicit slugs. With nothing unfinished and no binding, the session must start a
|
package/docs/gates.md
CHANGED
|
@@ -15,7 +15,7 @@ so it needs no `--confirmed`.
|
|
|
15
15
|
| `test` | records a check | — (runs the `test` command/check, records pass/fail) |
|
|
16
16
|
| `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) |
|
|
17
17
|
| `health` | records a check | — (runs `seedData` + the health command, retrying up to `healthWait` seconds; app must be up locally with real data) |
|
|
18
|
-
| `verify [--yolo]` | implement → pre-release | 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 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 — 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`), 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 |
|
|
18
|
+
| `verify [--yolo]` | implement → pre-release | 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 — 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`), 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 |
|
|
19
19
|
| `release [--yolo|--no-version|--no-fold-check]` | pre-release → release | checks re-greened after the prep edits; 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 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`** (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) |
|
|
20
20
|
| `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) · 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 |
|
|
21
21
|
| `finish [--yolo] [slug]` | release → done (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; 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` |
|
package/docs/guardrails.md
CHANGED
|
@@ -8,14 +8,14 @@ While a feature is active, the extension intercepts every tool call:
|
|
|
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
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
|
-
- **Gates can't be skipped**: flow state is untouchable by the agent (edit tool and bash) — writing `state.json`, moving
|
|
11
|
+
- **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.
|
|
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.
|
|
13
13
|
- **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.
|
|
14
14
|
- **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.
|
|
15
|
-
- **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.
|
|
15
|
+
- **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) the call is therefore by default **refused** until the model states one (`bashTimeout = require`): the refusal names the exact value the class table would have armed, so the retry is a one-token fix and the call line in the transcript shows the timeout that is actually running. The injected class default (30s quick inspection · 120s local git and unknown · 180s network · 300s containers/services · 900s builds/tests/installs · 1,200s watchers like `gh run watch`) stays armed underneath either way, and absurd explicit values clamp to 1,800s. A project that would rather not nag sets `bashTimeout = inject` in `## global` — then the default is armed silently and the call passes. Uninitiated folders hear nothing at all: without the playbook dev-flow enforces no rules.
|
|
16
16
|
- **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; a note about any compaction dev-flow could not shape still lands in `reflections.md`.
|
|
17
17
|
- The active stage is injected into the model's context every turn; 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 → `release-done`. The package also bundles the review skills themselves — `/flow-review` (a change, read against its `plan/plan.md`) and `/flow-audit` (the whole repo) — and injects a built-in senior-discipline guidance at implement stage unless the playbook sets its own `prose.implement`.
|
|
18
|
-
- **Status bar**: while the session **is bound** to a feature
|
|
18
|
+
- **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, 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; a session binds only via `flow start`/`flow use`, never by opening. 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]`) and the `flow=<ver>` stamp of the build that started the feature.
|
|
19
19
|
|
|
20
20
|
## Limitations (deliberate, v1)
|
|
21
21
|
|
package/docs/headless.md
CHANGED
|
@@ -35,8 +35,12 @@ The contract a headless driver (a session with no UI) relies on:
|
|
|
35
35
|
`dev` deploy (runs are killed past 15 min) and re-probes health with `healthWait` retries.
|
|
36
36
|
A remote timeout must be minutes, not seconds — the gate prints progress lines while it
|
|
37
37
|
runs.
|
|
38
|
-
- **Edits invalidate checks.**
|
|
39
|
-
confirmation
|
|
38
|
+
- **Edits invalidate checks.** An edit-tool write clears recorded checks and the tier-2
|
|
39
|
+
confirmation at once; any other worktree write (bash: `sed -i`, a formatter, codegen) is caught
|
|
40
|
+
at the gate — every check carries a fingerprint of the tree it ran against, and verify/release
|
|
41
|
+
rerun records the tree has outgrown (`stale record(s) rerun after a worktree change: …`).
|
|
42
|
+
Re-running `flow check` before `verify` after the last edit is still the tidy order; the gate no
|
|
43
|
+
longer trusts a stale PASS if you skip it.
|
|
40
44
|
- **Version skew.** Gates execute the dev-flow build the session loaded at start; `flow version`
|
|
41
45
|
reports when the checkout has moved ahead of it. `flow release` turns the skew into a question —
|
|
42
46
|
update (`/reload`, then re-run) or proceed with the old release — never a block: publishing under
|
package/extensions/dev-flow.ts
CHANGED
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
appendReflection,
|
|
34
34
|
appendRoadmapItem,
|
|
35
35
|
bashFlowGuard,
|
|
36
|
+
checkFingerprint,
|
|
36
37
|
changelogEntry,
|
|
37
38
|
changelogVersionsBetween,
|
|
38
39
|
normalizeReleaseBody,
|
|
@@ -53,6 +54,7 @@ import {
|
|
|
53
54
|
FLOW_SHELL_HINT,
|
|
54
55
|
flowShellInvocation,
|
|
55
56
|
forcePushInvocation,
|
|
57
|
+
freshenChecks,
|
|
56
58
|
gateHelpJson,
|
|
57
59
|
gitInvocation,
|
|
58
60
|
githubSlug,
|
|
@@ -197,6 +199,10 @@ async function sh(command: string, cwd: string): Promise<{ ok: boolean; out: str
|
|
|
197
199
|
}
|
|
198
200
|
|
|
199
201
|
const dfDir = (root: string) => path.join(root, ".dev-flow");
|
|
202
|
+
/** dev-flow is initiated once the operator playbook exists: before flow init writes project.md the
|
|
203
|
+
* extension is silent in that folder — no injections, no guards (not even the no-playbook bash-timeout
|
|
204
|
+
* default), no footer. The flow tool itself stays registered so flow init remains callable. */
|
|
205
|
+
const initiated = (root: string): boolean => existsSync(path.join(dfDir(root), "project.md"));
|
|
200
206
|
|
|
201
207
|
/** A `--merge=squash` style flag, or null when absent. Returned as the raw string: the caller validates it
|
|
202
208
|
* with parseMergeStyle so a typo is reported instead of ignored. */
|
|
@@ -459,7 +465,7 @@ const flowCompactInstructions = (st: FlowState) =>
|
|
|
459
465
|
* never while chat-only state is pending (open dialog, undigested plan) — see shouldSelfCompact.
|
|
460
466
|
*/
|
|
461
467
|
function maybeCompactNow(ctx: ExtensionContext): void {
|
|
462
|
-
if (!
|
|
468
|
+
if (!initiated(ctx.cwd)) return;
|
|
463
469
|
const u = ctx.getContextUsage?.(); // minimal/fake contexts may lack usage info — treat as unknown
|
|
464
470
|
if (!u || u.tokens === null) return;
|
|
465
471
|
const key = sessionKey(ctx);
|
|
@@ -550,13 +556,14 @@ function gateCwd(root: string, state: FlowState): string {
|
|
|
550
556
|
* `health` is left to the post-deploy probe when there is a deploy to prove: probing twice only waits twice. */
|
|
551
557
|
function pendingChecks(state: FlowState, cfg: Config): StageCheck[] {
|
|
552
558
|
if (state.docs) return [];
|
|
553
|
-
return cfg.checkList.filter((c) => !state.checks[c.name]?.ok && !(c.name === "health" &&
|
|
559
|
+
return cfg.checkList.filter((c) => !state.checks[c.name]?.ok && !(c.name === "health" && healthRerunsAfterDeploy(cfg)));
|
|
554
560
|
}
|
|
555
561
|
|
|
556
562
|
/** Run tier-1 checks in the feature cwd and record each result (health seeds first, as `flow health` does). */
|
|
557
563
|
async function runChecks(root: string, state: FlowState, cfg: Config, checks: StageCheck[]): Promise<{ lines: string[]; failed: boolean }> {
|
|
558
564
|
const lines: string[] = [];
|
|
559
565
|
let failed = false;
|
|
566
|
+
const ran: string[] = [];
|
|
560
567
|
for (const c of checks) {
|
|
561
568
|
if (c.name === "health" && cfg.commands.seedData) {
|
|
562
569
|
const seed = await sh(cfg.commands.seedData, gateCwd(root, state));
|
|
@@ -568,13 +575,39 @@ async function runChecks(root: string, state: FlowState, cfg: Config, checks: St
|
|
|
568
575
|
}
|
|
569
576
|
const res = await sh(c.cmd, gateCwd(root, state));
|
|
570
577
|
state.checks[c.name] = { ok: res.ok, at: now() };
|
|
578
|
+
ran.push(c.name);
|
|
571
579
|
lines.push(`${c.name}: ${res.ok ? "PASS" : "FAIL"} (${c.cmd})${res.ok ? "" : `\n${tail(res.out)}`}`);
|
|
572
580
|
if (!res.ok) failed = true;
|
|
573
581
|
}
|
|
582
|
+
await stampChecks(root, state, ran);
|
|
574
583
|
writeState(root, state);
|
|
575
584
|
return { lines, failed };
|
|
576
585
|
}
|
|
577
586
|
|
|
587
|
+
/** Which health record a verify may leave stale on purpose: the post-deploy probe re-runs it, so
|
|
588
|
+
* the pre-deploy record must survive the gate that schedules the deploy. */
|
|
589
|
+
const healthRerunsAfterDeploy = (cfg: Config) => !!cfg.commands.dev && !!healthProbe(cfg);
|
|
590
|
+
|
|
591
|
+
/** Fingerprint of the working-tree state the checks ran against: paths (`status --porcelain`),
|
|
592
|
+
* tracked content (a hash of the uncommitted diff) and HEAD. Null when git cannot answer — a
|
|
593
|
+
* measurement failure must never mark a green record stale (see freshenChecks). */
|
|
594
|
+
async function worktreeFingerprint(cwd: string): Promise<string | null> {
|
|
595
|
+
const st = await sh("git status --porcelain", cwd);
|
|
596
|
+
if (!st.ok) return null;
|
|
597
|
+
const diff = await sh("git diff HEAD --no-color | git hash-object --stdin", cwd);
|
|
598
|
+
const head = await sh("git rev-parse HEAD", cwd);
|
|
599
|
+
if (!diff.ok || !head.ok) return null;
|
|
600
|
+
return checkFingerprint(`${st.out}\n${diff.out}`, head.out);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/** Stamp freshly recorded checks with the tree they ran against — taken AFTER the run, so a check
|
|
604
|
+
* that rewrites tracked files (a formatter, codegen) does not mark itself stale the moment it passes. */
|
|
605
|
+
async function stampChecks(root: string, state: FlowState, names: string[]): Promise<void> {
|
|
606
|
+
const fp = await worktreeFingerprint(gateCwd(root, state));
|
|
607
|
+
if (!fp) return;
|
|
608
|
+
for (const n of names) if (state.checks[n]) state.checks[n].wt = fp;
|
|
609
|
+
}
|
|
610
|
+
|
|
578
611
|
/** Commits the feature branch holds over its merge base with the default branch, plus how many
|
|
579
612
|
* paths sit uncommitted: verify's proof that there is a committed state behind the operator's
|
|
580
613
|
* question. Local refs only — same offline-safe stance as the changelog proof — and an
|
|
@@ -668,7 +701,8 @@ async function runFlow(args: string[], root: string, ui: Ui, sess: Session): Pro
|
|
|
668
701
|
const [sub = "status", ...rest] = args;
|
|
669
702
|
// help and version are questions about the plugin, not the repo: answerable with no .dev-flow/ at all
|
|
670
703
|
if (sub === "help" || sub === "--help" || sub === "-h") return { text: rest.includes("--json") ? gateHelpJson(GATE_HELP, loadedVersion()) : `usage: flow <sub> — ${GATE_HELP}` };
|
|
671
|
-
|
|
704
|
+
// an uninitiated folder is dormant: every gate verb but init and version needs the operator playbook (project.md)
|
|
705
|
+
if (!initiated(root) && sub !== "init" && sub !== "version") return { text: "dev-flow is not initiated here — no .dev-flow/project.md — run flow init first", isError: true };
|
|
672
706
|
const cfg = loadProject(dfDir(root)).cfg;
|
|
673
707
|
const flag = (name: string) => rest.includes(`--${name}`);
|
|
674
708
|
const slugArg = rest.find((a) => !a.startsWith("--"));
|
|
@@ -1049,6 +1083,7 @@ ${mdDigest(draftRefresh)}`))
|
|
|
1049
1083
|
if (!cfg.commands.test) return { text: "no commands.test configured — add `test = <command>` under ## implement in .dev-flow/project.md", isError: true };
|
|
1050
1084
|
const res = await sh(cfg.commands.test, gateCwd(root, state!));
|
|
1051
1085
|
state!.checks.test = { ok: res.ok, at: now() };
|
|
1086
|
+
await stampChecks(root, state!, ["test"]);
|
|
1052
1087
|
writeState(root, state!);
|
|
1053
1088
|
return { text: `test: ${res.ok ? "PASS" : "FAIL"} (${cfg.commands.test})\n${tail(res.out)}` };
|
|
1054
1089
|
}
|
|
@@ -1059,8 +1094,11 @@ ${mdDigest(draftRefresh)}`))
|
|
|
1059
1094
|
const items = applicableItems(cfg, state!, "implement");
|
|
1060
1095
|
const branch = await branchState(gateCwd(root, state!), cfg.defaultBranch);
|
|
1061
1096
|
const branchLine = describeBranchState(branch, cfg.defaultBranch);
|
|
1062
|
-
//
|
|
1063
|
-
//
|
|
1097
|
+
// A green record belongs to the tree it ran against. A worktree change made through bash (sed,
|
|
1098
|
+
// a formatter, codegen) fires no edit-tool invalidation — the fingerprint is what notices the
|
|
1099
|
+
// tree moved, and the dropped records become pending so the gate itself reruns them (#84 path).
|
|
1100
|
+
const staleAtGate = freshenChecks(state!, await worktreeFingerprint(gateCwd(root, state!)), (n) => n === "health" && healthRerunsAfterDeploy(cfg));
|
|
1101
|
+
if (staleAtGate.length) writeState(root, state!);
|
|
1064
1102
|
const pending = pendingChecks(state!, cfg);
|
|
1065
1103
|
const gateRun = pending.length ? await runChecks(root, state!, cfg, pending) : null;
|
|
1066
1104
|
if (gateRun?.failed) return { text: `verify gate FAILED — a check run at the gate failed:\n${gateRun.lines.join("\n")}\n${branchLine}`, isError: true };
|
|
@@ -1071,6 +1109,7 @@ ${mdDigest(draftRefresh)}`))
|
|
|
1071
1109
|
// agent tell the operator the dev deploy had never run, right after it recreated a container.
|
|
1072
1110
|
const did: string[] = [];
|
|
1073
1111
|
if (gateRun) did.push(`checks ran at the gate (${pending.map((c) => c.name).join(", ")})`);
|
|
1112
|
+
if (staleAtGate.length) did.push(`stale record(s) rerun after a worktree change: ${staleAtGate.join(", ")}`);
|
|
1074
1113
|
if (state!.docs) {
|
|
1075
1114
|
// docs mode's contract: no tier-1 work happens, so a docs flow neither builds, deploys nor probes (#43 #49)
|
|
1076
1115
|
did.push("docs mode: project commands skipped (build/dev/health)");
|
|
@@ -1104,6 +1143,7 @@ ${mdDigest(draftRefresh)}`))
|
|
|
1104
1143
|
}
|
|
1105
1144
|
const probed = await runHealthProbe(probe, gateCwd(root, state!), cfg.healthWait);
|
|
1106
1145
|
state!.checks.health = { ok: probed.ok, at: now() };
|
|
1146
|
+
await stampChecks(root, state!, ["health"]);
|
|
1107
1147
|
writeState(root, state!);
|
|
1108
1148
|
// a probe that needed the wait budget says so — "it passed on the 9th try" is the operator's business (#42)
|
|
1109
1149
|
const tried = probed.attempts > 1 ? `, ${probed.attempts} attempts` : "";
|
|
@@ -1160,6 +1200,7 @@ ${mdDigest(draftRefresh)}`))
|
|
|
1160
1200
|
}
|
|
1161
1201
|
const res = await runHealthProbe(cfg.commands.health, gateCwd(root, state!), cfg.healthWait);
|
|
1162
1202
|
state!.checks.health = { ok: res.ok, at: now() };
|
|
1203
|
+
await stampChecks(root, state!, ["health"]);
|
|
1163
1204
|
writeState(root, state!);
|
|
1164
1205
|
const tried = res.attempts > 1 ? `, ${res.attempts} attempts` : "";
|
|
1165
1206
|
return { text: `health: ${res.ok ? "PASS" : "FAIL"} (${cfg.commands.health}${tried})\n${tail(res.out)}` };
|
|
@@ -1217,6 +1258,8 @@ ${mdDigest(draftRefresh)}`))
|
|
|
1217
1258
|
}
|
|
1218
1259
|
}
|
|
1219
1260
|
const prep = { manifestVersion: manifestVer, remoteTags, changelog, changelogChanged, changelogBase, noFoldCheck: flag("no-fold-check") };
|
|
1261
|
+
// same freshness rule as verify: a green predating a worktree write may not stand for the tree this gate blesses
|
|
1262
|
+
if (freshenChecks(state!, await worktreeFingerprint(wtCwd)).length) writeState(root, state!);
|
|
1220
1263
|
// tier-2 pre-release confirmation is recorded by this very command, so it is excluded here
|
|
1221
1264
|
const preGate = preReleaseGate({ ...state!, confirmations: { ...state!.confirmations, "pre-release": { hash: checklistHash(items), at: now() } } }, cfg, prep);
|
|
1222
1265
|
if (preGate.length) return { text: `release gate FAILED:\n- ${preGate.join("\n- ")}`, isError: true };
|
|
@@ -1560,6 +1603,10 @@ ${mdDigest(draftRefresh)}`))
|
|
|
1560
1603
|
const target = slugArg ?? sess.slug;
|
|
1561
1604
|
if (!target) return { text: "nothing bound — pass a slug", isError: true };
|
|
1562
1605
|
const st = readState(root, target);
|
|
1606
|
+
// a live claim locks the whole feature, not only its gates: aborting it out from under the session
|
|
1607
|
+
// that works it erases the plan that session is still writing (same rule needState applies)
|
|
1608
|
+
const claim = readClaim(root, target);
|
|
1609
|
+
if (claimBlocks(claim, sess.key)) return { text: `${target} is claimed by another live session (pid ${claim!.pid}) — flow use ${target} takes it over explicitly`, isError: true };
|
|
1563
1610
|
if (sess.slug === target) sess.bind(null);
|
|
1564
1611
|
if (st && !st.worktree) {
|
|
1565
1612
|
// plan-stage abort = drop: no worktree/branch exists, so the state dir would linger
|
|
@@ -1612,12 +1659,16 @@ function tail(out: string, n = 15): string {
|
|
|
1612
1659
|
// ------------------------------------------------------------------ extension
|
|
1613
1660
|
|
|
1614
1661
|
/** Compact footer: bound flow = stage glyph, slug, mode markers, ⚠️ on its failing checks; unbound = the
|
|
1615
|
-
*
|
|
1662
|
+
* unfinished-flow count, or `⧖ no flows` — an initiated repo always carries the footer. An uninitiated
|
|
1663
|
+
* folder gets nothing: the status is cleared. Pure read — rendering never binds or claims anything. */
|
|
1616
1664
|
function refreshStatus(ctx: ExtensionContext): void {
|
|
1617
1665
|
if (!ctx.hasUI) return;
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1666
|
+
if (!initiated(ctx.cwd)) {
|
|
1667
|
+
ctx.ui.setStatus("dev-flow", undefined);
|
|
1668
|
+
return;
|
|
1669
|
+
}
|
|
1670
|
+
const s = statusFor(boundFeature(ctx.cwd, sessionKey(ctx)), unfinishedStates(ctx.cwd).length);
|
|
1671
|
+
ctx.ui.setStatus("dev-flow", s.text);
|
|
1621
1672
|
}
|
|
1622
1673
|
|
|
1623
1674
|
|
|
@@ -1757,7 +1808,7 @@ export default function devFlow(pi: ExtensionAPI) {
|
|
|
1757
1808
|
// reaches the provider). If our summary fails we return undefined and pi's own compaction proceeds.
|
|
1758
1809
|
// overflow is never taken over (cancelling it would drop pi's compact-and-retry); manual is the operator's or ours.
|
|
1759
1810
|
pi.on("session_before_compact", async (event, ctx) => {
|
|
1760
|
-
if (!
|
|
1811
|
+
if (!initiated(ctx.cwd)) return undefined;
|
|
1761
1812
|
const key = sessionKey(ctx);
|
|
1762
1813
|
const st = boundFeature(ctx.cwd, key);
|
|
1763
1814
|
if (!shouldTakeOverCompaction({ reason: event.reason, bound: !!st, inFlight: compacting.has(key) })) return undefined;
|
|
@@ -1780,7 +1831,7 @@ export default function devFlow(pi: ExtensionAPI) {
|
|
|
1780
1831
|
});
|
|
1781
1832
|
// pi forcing its own compaction while a flow is bound means the pacing was wrong — park a note for the operator.
|
|
1782
1833
|
pi.on("session_compact", async (event, ctx) => {
|
|
1783
|
-
if (!
|
|
1834
|
+
if (!initiated(ctx.cwd)) return;
|
|
1784
1835
|
// Whatever the reason, the summary replaced the transcript — the core the first run injected is
|
|
1785
1836
|
// gone from context, so the next run pays it once more (manual compactions included: our own
|
|
1786
1837
|
// safe-point compaction is the common one).
|
|
@@ -1804,14 +1855,12 @@ export default function devFlow(pi: ExtensionAPI) {
|
|
|
1804
1855
|
const shellInput = isToolCallEventType("bash", event) || isToolCallEventType("powershell", event) ? (event.input as { command?: unknown; timeout?: unknown }) : undefined;
|
|
1805
1856
|
const shellCmd = shellInput ? String(shellInput.command ?? "") : "";
|
|
1806
1857
|
const explicitTimeout = typeof shellInput?.timeout === "number" ? shellInput.timeout : undefined;
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
if (why) return { block: true, reason: why };
|
|
1814
|
-
}
|
|
1858
|
+
const noDf = !initiated(ctx.cwd);
|
|
1859
|
+
// in an initiated repo the silent default stays armed either way: it is the safety net for an
|
|
1860
|
+
// `inject` project and the number the refusal quotes; an uninitiated folder is not touched at all
|
|
1861
|
+
if (shellCmd && shellInput && !noDf) shellInput.timeout = bashTimeout(shellCmd, explicitTimeout);
|
|
1862
|
+
// an uninitiated folder hears nothing from dev-flow at all — flow init is the opt-in that arms
|
|
1863
|
+
// the guards, the no-playbook bash-timeout default included
|
|
1815
1864
|
if (noDf) return undefined;
|
|
1816
1865
|
const cfg = loadProject(dfDir(ctx.cwd)).cfg;
|
|
1817
1866
|
const mustStateTimeout = shellCmd !== "" && explicitTimeout === undefined && cfg.bashTimeout === "require";
|
|
@@ -1936,7 +1985,10 @@ export default function devFlow(pi: ExtensionAPI) {
|
|
|
1936
1985
|
const run = ctx as unknown as Record<symbol, boolean | undefined>;
|
|
1937
1986
|
if (run[CONTEXT_EMITTED]) return undefined;
|
|
1938
1987
|
run[CONTEXT_EMITTED] = true;
|
|
1939
|
-
|
|
1988
|
+
// repaint the footer at the start of every run: the session_start push can land before a web
|
|
1989
|
+
// client attaches, and this is the earliest point the client is certainly listening
|
|
1990
|
+
refreshStatus(ctx);
|
|
1991
|
+
if (!initiated(ctx.cwd)) return undefined;
|
|
1940
1992
|
const key = sessionKey(ctx);
|
|
1941
1993
|
// The playbook core rides along on the message this run writes anyway — once per session.
|
|
1942
1994
|
const core = corePreamble(key);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-dev-flow",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.61.0",
|
|
4
4
|
"description": "Enforced feature workflow for Pi: plan → implement → pre-release → release, gated checkpoints, self-improvement reflections, one git worktree per feature, changelog + publish as part of the release",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
package/skills/dev-flow/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: dev-flow
|
|
|
3
3
|
description: >
|
|
4
4
|
The repo's enforced feature workflow: plan → implement → pre-release →
|
|
5
5
|
release → done, one feature at a time, driven through the flow tool. Read before
|
|
6
|
-
starting ANY feature work in a repo
|
|
6
|
+
starting ANY feature work in a repo whose .dev-flow/project.md playbook exists — the
|
|
7
7
|
stage guards block out-of-stage edits and main-branch git ops, so working
|
|
8
8
|
outside this flow fails at the guard.
|
|
9
9
|
---
|
package/src/core.ts
CHANGED
|
@@ -16,6 +16,11 @@ export interface Check {
|
|
|
16
16
|
ok: boolean;
|
|
17
17
|
at: string;
|
|
18
18
|
note?: string;
|
|
19
|
+
/** The worktree state this check actually ran against (see checkFingerprint). A record whose
|
|
20
|
+
* fingerprint differs from the current tree at gate time was measured against code that no
|
|
21
|
+
* longer exists — green is not enough when the tree moved under it. Absent = recorded by an
|
|
22
|
+
* older build, or git could not be asked: never proven stale, never dropped. */
|
|
23
|
+
wt?: string;
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
export interface StageCheck {
|
|
@@ -175,38 +180,6 @@ export function stageReference(stage: Stage): string | null {
|
|
|
175
180
|
return STAGE_REFERENCE[stage] ?? null;
|
|
176
181
|
}
|
|
177
182
|
|
|
178
|
-
/** Build a Config from DEFAULTS + a partial overrides object (tests, drafts — the persisted
|
|
179
|
-
* source is project.md alone; the legacy project.json loader is gone). */
|
|
180
|
-
export function buildConfig(raw: unknown): Config {
|
|
181
|
-
const c: Config = structuredClone(DEFAULTS);
|
|
182
|
-
if (!raw || typeof raw !== "object") return c;
|
|
183
|
-
const r = raw as Record<string, unknown>;
|
|
184
|
-
for (const key of ["defaultBranch", "branchPattern", "worktreeDir", "mainHook", "forge"] as const) {
|
|
185
|
-
if (typeof r[key] === "string" || typeof r[key] === "boolean") (c[key] as never) = r[key] as never;
|
|
186
|
-
}
|
|
187
|
-
if (Array.isArray(r.mockupGlobs)) c.mockupGlobs = r.mockupGlobs.map(String);
|
|
188
|
-
if (r.commands && typeof r.commands === "object")
|
|
189
|
-
for (const [k, v] of Object.entries(r.commands as Record<string, unknown>)) if (typeof v === "string") (c.commands as Record<string, string>)[k] = v;
|
|
190
|
-
if (r.release && typeof r.release === "object") Object.assign(c.release, r.release);
|
|
191
|
-
if (r.healthWait !== undefined) c.healthWait = toSeconds(r.healthWait) ?? c.healthWait;
|
|
192
|
-
if (r.versioning && typeof r.versioning === "object") {
|
|
193
|
-
const v = r.versioning as Record<string, unknown>;
|
|
194
|
-
if (typeof v.file === "string") c.versioning.file = v.file;
|
|
195
|
-
if (typeof v.pattern === "string") c.versioning.pattern = v.pattern;
|
|
196
|
-
}
|
|
197
|
-
if (r.guard && typeof r.guard === "object") {
|
|
198
|
-
const g = r.guard as Record<string, unknown>;
|
|
199
|
-
for (const verb of ["deny", "confirm", "protect", "forbid"] as const)
|
|
200
|
-
if (Array.isArray(g[verb])) c.guard[verb] = normalizeGuardRules(g[verb]);
|
|
201
|
-
}
|
|
202
|
-
// tier-1 checks from plain commands so legacy project.json keeps the same teeth as project.md
|
|
203
|
-
c.checkList = [
|
|
204
|
-
...(c.commands.test ? [{ name: "test", cmd: c.commands.test }] : []),
|
|
205
|
-
...(c.commands.health ? [{ name: "health", cmd: c.commands.health }] : []),
|
|
206
|
-
];
|
|
207
|
-
return c;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
183
|
/** The project's own "running and healthy" probe — `commands.health` or a flow-check block named
|
|
211
184
|
* health. The plugin runs it, the project says what healthy means (readiness, served build stamp). */
|
|
212
185
|
export function healthProbe(c: Config): string | undefined {
|
|
@@ -457,6 +430,36 @@ export function checklistHash(items: ChecklistItem[]): string {
|
|
|
457
430
|
.slice(0, 12);
|
|
458
431
|
}
|
|
459
432
|
|
|
433
|
+
/** Fingerprint of the worktree state a tier-1 check ran against: the caller composes the working
|
|
434
|
+
* tree's `git status --porcelain`, the hash of its uncommitted `git diff HEAD` (path presence and
|
|
435
|
+
* tracked content move it), and `git rev-parse HEAD`. Deterministic and cheap; the sha is only
|
|
436
|
+
* ever compared against itself, never decoded.
|
|
437
|
+
* shortcut: a content-only change to an UNTRACKED file stays invisible — git does not look at
|
|
438
|
+
* those contents, and untracked worktree content is normally build output, not code under test. */
|
|
439
|
+
export function checkFingerprint(treeState: string, head: string): string {
|
|
440
|
+
return createHash("sha1").update(`${treeState}\n${head}`).digest("hex").slice(0, 12);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Drop every check record that carries a fingerprint differing from the tree as it is now — those
|
|
445
|
+
* greens describe code that no longer exists, and a gate must not advance on them. The caller
|
|
446
|
+
* re-runs what is missing (verify re-runs at the gate; the release gate asks for `flow check`).
|
|
447
|
+
* `fp === null` means git could not be asked: a gate must not refuse on its own measurement
|
|
448
|
+
* failure — same rule as BranchState.commitsAhead. Records without a fingerprint (older builds)
|
|
449
|
+
* are never proven stale.
|
|
450
|
+
*/
|
|
451
|
+
export function freshenChecks(state: FlowState, fp: string | null, keep: (name: string) => boolean = () => false): string[] {
|
|
452
|
+
if (!fp) return [];
|
|
453
|
+
const stale: string[] = [];
|
|
454
|
+
for (const [name, rec] of Object.entries(state.checks)) {
|
|
455
|
+
if (rec.wt && rec.wt !== fp && !keep(name)) {
|
|
456
|
+
delete state.checks[name];
|
|
457
|
+
stale.push(name);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return stale;
|
|
461
|
+
}
|
|
462
|
+
|
|
460
463
|
/** Items that apply to this feature — "(ui)" items only when the UI flag is set. */
|
|
461
464
|
export function applicableItems(cfg: Config, state: FlowState, stage: string): ChecklistItem[] {
|
|
462
465
|
return (cfg.checklist[stage] ?? []).filter((i) => !i.uiOnly || state.ui);
|
|
@@ -762,11 +765,12 @@ export function expandHome(p: string): string {
|
|
|
762
765
|
|
|
763
766
|
/** git usage in a bash command, parsed per shell segment (split on ; | & newline):
|
|
764
767
|
* the git subcommands invoked — empty when git is not a command, so paths like
|
|
765
|
-
* .git/hooks or words like pre-commit never trigger the guard — and the
|
|
766
|
-
*
|
|
768
|
+
* .git/hooks or words like pre-commit never trigger the guard — and the per-segment
|
|
769
|
+
* entries the guard judges, each carrying the directory that segment runs in
|
|
770
|
+
* (last preceding `cd` target or `git -C` target; null = session cwd).
|
|
767
771
|
* shortcut: naive segment split, subshells/backticks not tracked; the pre-commit
|
|
768
772
|
* hook still covers what slips past this advisory guard. */
|
|
769
|
-
export function gitInvocation(command: string): { subs: string[];
|
|
773
|
+
export function gitInvocation(command: string): { subs: string[]; pushes: string[][]; gitSegs: { seg: string; dir: string | null }[] } {
|
|
770
774
|
const subs: string[] = [];
|
|
771
775
|
const pushes: string[][] = [];
|
|
772
776
|
const gitSegs: { seg: string; dir: string | null }[] = [];
|
|
@@ -811,7 +815,7 @@ export function gitInvocation(command: string): { subs: string[]; dir: string |
|
|
|
811
815
|
}
|
|
812
816
|
gitSegs.push({ seg: seg.trim(), dir }); // after -C parsing so the entry carries its own effective dir
|
|
813
817
|
}
|
|
814
|
-
return { subs,
|
|
818
|
+
return { subs, pushes, gitSegs };
|
|
815
819
|
}
|
|
816
820
|
|
|
817
821
|
export type PushRef = { kind: "tag" | "branch" | "current"; name: string };
|
|
@@ -850,16 +854,18 @@ export function parsePushRefs(pushes: string[][]): PushRef[] {
|
|
|
850
854
|
return out;
|
|
851
855
|
}
|
|
852
856
|
|
|
853
|
-
/** Flow
|
|
854
|
-
* (that is how `cd .dev-flow/<slug> && mv state.json …` reaches it).
|
|
855
|
-
|
|
856
|
-
const
|
|
857
|
+
/** Flow control files by full path — state.json and claim.json — or a bare name when the command
|
|
858
|
+
* also touches `.dev-flow` (that is how `cd .dev-flow/<slug> && mv state.json …` reaches it).
|
|
859
|
+
* The claim is the live-session lock: deleting it is as much theft as forging a stage. */
|
|
860
|
+
const STATE_PATH = /(^|[\s'"\/])(?:state|claim)\.json$/;
|
|
861
|
+
const STATE_PATH_ABS = /\.dev-flow\/[\w./-]*(?:state|claim)\.json$/;
|
|
857
862
|
const PLAYBOOK_PATH = /\.dev-flow\/[\w./-]*project\.md/;
|
|
858
863
|
const DF_ANYWHERE = /\.dev-flow\b/;
|
|
859
864
|
/** The `.dev-flow/` folder itself or one feature directory under it — deleting either destroys the flow
|
|
860
865
|
* state and its plan for good. The advisory files the agent owns, and anything deeper (a worktree, a
|
|
861
|
-
* plan/mockups path), are not "the folder".
|
|
862
|
-
|
|
866
|
+
* plan/mockups path), are not "the folder". The leading boundary takes `/` too: an absolute path names
|
|
867
|
+
* the same folder, and absolute paths are the shape the harness hands the agent. */
|
|
868
|
+
const DF_FOLDER = /(?:^|[\s'"/])\.dev-flow(?:\/(?!project\.md$|roadmap\.md$|reflections\.md$|\.gitignore$)[\w.-]+)?(?=$|[\s'"])/;
|
|
863
869
|
// write tools that can overwrite a file. A bare `>` is deliberately absent: the redirect target is
|
|
864
870
|
// checked on its own, and testing for any `>` here refused every segment that merely mentioned an
|
|
865
871
|
// owned path while redirecting elsewhere (`gh pr create … 2>&1`).
|
|
@@ -1015,19 +1021,6 @@ export interface GuardRules {
|
|
|
1015
1021
|
forbid: GuardRule[];
|
|
1016
1022
|
}
|
|
1017
1023
|
|
|
1018
|
-
/** project.json may spell a rule as a bare pattern string. */
|
|
1019
|
-
function normalizeGuardRules(raw: unknown[]): GuardRule[] {
|
|
1020
|
-
const out: GuardRule[] = [];
|
|
1021
|
-
for (const e of raw) {
|
|
1022
|
-
if (typeof e === "string" && e.trim()) out.push({ pattern: e, why: "" });
|
|
1023
|
-
else if (e && typeof e === "object") {
|
|
1024
|
-
const o = e as Record<string, unknown>;
|
|
1025
|
-
if (typeof o.pattern === "string" && o.pattern.trim()) out.push({ pattern: o.pattern, why: typeof o.why === "string" ? o.why : "" });
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
return out;
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
1024
|
/** Heads that execute their argument: inside these, quoted text is code, not prose. */
|
|
1032
1025
|
export const REEXEC_HEADS = new Set(["sh", "bash", "zsh", "dash", "ksh", "node", "nodejs", "python", "python2", "python3", "perl", "ruby", "php", "env", "xargs", "sudo", "time", "nice", "nohup", "watch"]);
|
|
1033
1026
|
|
|
@@ -1203,30 +1196,36 @@ export function inScratchDir(abs: string, repoRoot?: string | null): boolean {
|
|
|
1203
1196
|
* Returns a reason or null (allowed).
|
|
1204
1197
|
*/
|
|
1205
1198
|
export function writeGuard(o: { abs: string; dfDir: string; features: FeatureRef[]; boundSlug: string | null; repoRoot?: string | null }): string | null {
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1199
|
+
// Judge where the bytes land, not where the path pretends: a symlink inside the worktree pointing
|
|
1200
|
+
// out of it is the same write as the target path (realAbs walks the deepest existing ancestor, so
|
|
1201
|
+
// a brand-new file under a real directory resolves right, and a never-existing one is stable).
|
|
1202
|
+
const abs = realAbs(o.abs);
|
|
1203
|
+
const dfDir = realAbs(o.dfDir);
|
|
1204
|
+
if (abs === path.join(dfDir, "project.json")) return ".dev-flow/project.json is legacy — it is no longer read; fold its values into project.md and delete it";
|
|
1205
|
+
if (abs === path.join(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";
|
|
1206
|
+
if (abs.endsWith("state.json") && abs.includes(dfDir + path.sep)) return "state.json is dev-flow-owned — advance stages with the flow tool only";
|
|
1207
|
+
if (abs.endsWith("claim.json") && abs.includes(dfDir + path.sep)) return "claim.json is dev-flow-owned — the live-session lock is not an edit target; take a feature over with flow use <slug>";
|
|
1209
1208
|
// Owner attribution BEFORE the .dev-flow allow: with the default worktreeDir inside .dev-flow,
|
|
1210
1209
|
// a worktree must still be judged by its owning feature's stage, not treated as free plan space.
|
|
1211
|
-
const owner = o.features.find((f) => within(
|
|
1210
|
+
const owner = o.features.find((f) => within(abs, f.worktreeAbs ? realAbs(f.worktreeAbs) : null));
|
|
1212
1211
|
if (owner) {
|
|
1213
1212
|
if (owner.state.stage === "plan") return `feature ${owner.state.slug} is in plan — code is read-only until its plan is approved`;
|
|
1214
1213
|
if (owner.state.stage === "done") return `feature ${owner.state.slug} is done`;
|
|
1215
1214
|
// the playbook copy inside a worktree: only operator-granted lightweight modes may change it
|
|
1216
|
-
if (path.basename(
|
|
1215
|
+
if (path.basename(abs) === "project.md" && abs.includes(path.join(".dev-flow", "project.md")) && !owner.state.docs && !owner.state.patch)
|
|
1217
1216
|
return `project.md changes belong to a docs or patch flow — ${owner.state.slug} is a normal feature (flow start <slug> --docs --confirmed)`;
|
|
1218
1217
|
return null; // implement/pre-release/release: own worktree is the working area
|
|
1219
1218
|
}
|
|
1220
1219
|
// Scratch outside the checkout is not a repo write: every stage (and an unbound session) may use it. It
|
|
1221
1220
|
// sits after the dev-flow-owned refusals and after owner attribution, so no path shape — a symlink, or a
|
|
1222
1221
|
// worktreeDir an operator parked in the temp dir — reaches those rules through the temp dir.
|
|
1223
|
-
if (inScratchDir(
|
|
1222
|
+
if (inScratchDir(abs, o.repoRoot)) return null;
|
|
1224
1223
|
const bound = o.boundSlug ? o.features.find((f) => f.state.slug === o.boundSlug) : undefined;
|
|
1225
1224
|
// A plan-stage session may only write its own feature directory: otherwise one session edits another
|
|
1226
1225
|
// feature's plan and that feature's approval gate then rubber-stamps text it never wrote.
|
|
1227
|
-
if (bound?.state.stage === "plan" && !within(
|
|
1226
|
+
if (bound?.state.stage === "plan" && !within(abs, path.join(dfDir, bound.state.slug)))
|
|
1228
1227
|
return `bound feature ${bound.state.slug} is in plan — write only inside its own .dev-flow/${bound.state.slug}/`;
|
|
1229
|
-
if (within(
|
|
1228
|
+
if (within(abs, dfDir)) return null;
|
|
1230
1229
|
if (bound) {
|
|
1231
1230
|
if (bound.state.stage === "implement" || bound.state.stage === "pre-release")
|
|
1232
1231
|
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)`;
|
|
@@ -1277,15 +1276,16 @@ export function statusCompact(state: FlowState): { text: string; failed: boolean
|
|
|
1277
1276
|
return { text: `${STAGE_EMOJI[state.stage]} ${state.slug}${state.patch ? " ⚡" : state.docs ? " 📚" : ""}${state.yolo ? " 🎱" : ""}`, failed };
|
|
1278
1277
|
}
|
|
1279
1278
|
|
|
1280
|
-
/** Footer decision for any session: a bound feature renders as statusCompact, its ⚠️
|
|
1281
|
-
* checks only; an unbound session shows the count of unfinished features — never a
|
|
1282
|
-
* session is never shown (or made to feel bound to) a feature it did not take with flow
|
|
1283
|
-
|
|
1279
|
+
/** Footer decision for any session in an initiated repo: a bound feature renders as statusCompact, its ⚠️
|
|
1280
|
+
* from its own failing checks only; an unbound session shows the count of unfinished features — never a
|
|
1281
|
+
* slug, so a fresh session is never shown (or made to feel bound to) a feature it did not take with flow
|
|
1282
|
+
* use — and `⧖ no flows` when nothing is in flight: dev-flow initiated means a footer always present. */
|
|
1283
|
+
export function statusFor(bound: FlowState | null, openCount: number): { text: string } {
|
|
1284
1284
|
if (bound && bound.stage !== "done") {
|
|
1285
1285
|
const { text, failed } = statusCompact(bound);
|
|
1286
1286
|
return { text: failed ? `${text} ⚠️` : text };
|
|
1287
1287
|
}
|
|
1288
|
-
if (openCount < 1) return
|
|
1288
|
+
if (openCount < 1) return { text: "⧖ no flows" };
|
|
1289
1289
|
return { text: `⧖ ${openCount} flow${openCount === 1 ? "" : "s"} open` };
|
|
1290
1290
|
}
|
|
1291
1291
|
|
|
@@ -1581,7 +1581,7 @@ export function nextHint(state: FlowState, cfg: Config): string {
|
|
|
1581
1581
|
case "plan":
|
|
1582
1582
|
if (state.patch) return `patch: describe the change to the operator in one line, then ask them Approve? in chat and run flow approve --confirmed when they answer — no plan file needed (all gates still apply)`;
|
|
1583
1583
|
if (state.docs) return `docs: describe the change to the operator in one line, then ask them Approve? in chat and run flow approve --confirmed when they answer — no plan file and no tier-1 checks (worktree and release stay intact)`;
|
|
1584
|
-
return `investigate, present your direction and proposed mode to the operator and clarify in chat, then write the plan into .dev-flow/${state.slug}/plan
|
|
1584
|
+
return `investigate, present your direction and proposed mode to the operator and clarify in chat, then write the plan into .dev-flow/${state.slug}/plan/plan.md${state.ui ? ` and render mockups to plan/mockups/ (${cfg.mockupGlobs.join(", ")}) with headless chromium, embedded in plan.md` : ""}, then ask the operator Approve? in chat and run flow approve --confirmed when they answer`;
|
|
1585
1585
|
case "implement":
|
|
1586
1586
|
if (state.docs) return `implement in the worktree ${state.worktree} — docs mode runs no project command (no build, no dev deploy, no health probe); tick the tier-2 checklist with the operator, then ask them Verified? in chat and run flow verify --confirmed when they answer`;
|
|
1587
1587
|
return `implement in the worktree ${state.worktree}, add tests, run flow check (tier-1 checks, incl. health with seeded data); tick the tier-2 checklist with the operator, then ask them Verified? in chat and run flow verify --confirmed when they answer`;
|
|
@@ -1655,15 +1655,6 @@ export function gateHelpJson(gateHelp: string, version: string | null): string {
|
|
|
1655
1655
|
);
|
|
1656
1656
|
}
|
|
1657
1657
|
|
|
1658
|
-
export function getPath(obj: Record<string, unknown>, key: string): unknown {
|
|
1659
|
-
let cur: unknown = obj;
|
|
1660
|
-
for (const seg of key.split(".")) {
|
|
1661
|
-
if (typeof cur !== "object" || cur === null) return undefined;
|
|
1662
|
-
cur = (cur as Record<string, unknown>)[seg];
|
|
1663
|
-
}
|
|
1664
|
-
return cur;
|
|
1665
|
-
}
|
|
1666
|
-
|
|
1667
1658
|
/** Write (or delete, on null) a dot-path value in a partial project.json object. */
|
|
1668
1659
|
export function applyAnswer(partial: Record<string, unknown>, key: string, value: string | boolean | null): void {
|
|
1669
1660
|
const segs = key.split(".");
|