pi-dev-flow 0.58.1 → 0.59.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +11 -0
- package/docs/development.md +21 -0
- package/docs/guardrails.md +2 -1
- package/extensions/dev-flow.ts +119 -26
- package/package.json +1 -1
- package/skills/dev-flow/SKILL.md +53 -375
- package/skills/dev-flow/references/finish.md +35 -0
- package/skills/dev-flow/references/implement.md +66 -0
- package/skills/dev-flow/references/plan.md +53 -0
- package/skills/dev-flow/references/pre-release.md +35 -0
- package/skills/dev-flow/references/reflect.md +60 -0
- package/skills/dev-flow/references/release.md +56 -0
- package/skills/dev-flow/references/start.md +68 -0
- package/src/core.ts +57 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,23 @@ Format: newest first. `Unreleased` collects what's merged but not yet tagged.
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.59.1] - 2026-10-23
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- **A session running an older dev-flow build than the checkout now says so — including in the dev-flow repo, where it never could.** `flow start` carried a behind-the-checkout warning and `flow release` carried the update-or-proceed question, but both compared the loaded build against `pluginVersion(import.meta.dirname)` — the `package.json` sitting beside the running code, which is the same file `loadedVersion()` reads — so the comparison was X against X and only the `DEV_FLOW_LOADED_VERSION` test seam ever made it unequal. A session that loaded 0.54.0 while this checkout already shipped 0.58.1 started, released and finished looking current, and the gate proofs shipped in between silently did not run. `checkoutBuild(root)` now answers what the disk says to run: this checkout's own manifest in the dev-flow repo, the installed package's everywhere else. `start`, `status`, `version`, `release` and `release-done` read it, the stamp in `state.json` records the build that actually ran rather than the one the disk claims, and `flow version` names the directory the stale code lives in. The stale release question stays a question — an operator who ships from behind is a choice, never a block.
|
|
12
|
+
- **Scratch outside the checkout is stage-free.** With a flow bound at `implement` or `pre-release`, the write guard refused every path that was not the worktree or `.dev-flow/` — `/tmp/split_skill.py` included — so an agent doing a mechanical multi-file rewrite had nowhere to keep a throwaway script and learned to park junk inside the checkout instead. A path whose realpath is under the OS temp dir is now allowed at every stage and with no flow bound, checked after the dev-flow-owned refusals and after per-path owner attribution, so neither a symlink out of the temp dir nor a `worktreeDir` an operator parked there reaches those rules; a repository that merely lives under the temp dir (every smoke-test repo) keeps the stage rules untouched. The refusal that remains names the temp dir as its own way out.
|
|
13
|
+
|
|
14
|
+
## [0.59.0] - 2026-10-23
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- **The playbook's ground rules are now handed to the session, not left waiting to be read.** Pi lists a skill's name, description and path and loads the file only if the model chooses to — so a session could open in a dev-flow repo having never seen the rules the guards enforce, guess at a checkpoint, and then argue with the refusal that followed. `skills/dev-flow/SKILL.md` now carries a marker-delimited **core**: flow-is-a-tool-not-a-shell-command, you-run-the-gates with the checkpoint verbs and yolo, binds are explicit, `state.json` and `project.md` are read-only, project `flow-guard` rules outrank flow, the bash `timeout` rule, `flow abort` for abandonment. The extension extracts that block and appends it to the hidden `[dev-flow]` line it already writes — **once per session**: a `dev-flow-skill` entry records the injection so a reload, resume or fork does not pay the ~1k tokens twice; a compaction that summarizes it away re-arms exactly one re-injection, recorded on the branch as well as in memory, so a session that survives a compaction as a reload gets the rules back instead of quietly running without them; a branch rewound or forked past the injection gets them back too. A copy shipped without its `skills/` directory, or a skill whose markers were damaged, leaves every message exactly as it was — the extractor returns nothing rather than throwing inside a guard hook — and `package.test.ts` refuses a core over 4,000 characters, because that budget is what every session in a dev-flow repo pays.
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- **The rest of the skill is one file per stage, and each stage names its own.** The stage detail moved verbatim into `skills/dev-flow/references/{start,plan,implement,pre-release,release,finish,reflect}.md` (SKILL.md: 25,817 → 5,085 chars), and a bound session's stage turn now ends with the absolute path of the one file its stage needs (`…/references/plan.md` at plan), so the model reads a 3k-char stage brief instead of either guessing what a gate wants or hauling the whole playbook into context. pi never advertises the reference files — only `SKILL.md` registers as a skill, and a directory holding one is not scanned deeper — and the tests keep both halves honest: every stage has a file, the map in `SKILL.md` names every file, and `release.md` hands over to `finish.md`, because the state machine has no finish stage that could name it.
|
|
23
|
+
|
|
7
24
|
## [0.58.1] - 2026-10-23
|
|
8
25
|
|
|
9
26
|
### Fixed
|
package/README.md
CHANGED
|
@@ -163,6 +163,17 @@ your playbook's `prose.implement` replaces it wholesale whenever you write your
|
|
|
163
163
|
rules adapt ponytail, obra/superpowers and pi-development-system — all MIT, credited in the
|
|
164
164
|
skill files.)
|
|
165
165
|
|
|
166
|
+
## The playbook the agent always has
|
|
167
|
+
|
|
168
|
+
Pi lists a skill's name and description and loads the file only if the model chooses to read it —
|
|
169
|
+
and a session that never read the playbook is the one that guesses at a gate, then argues with the
|
|
170
|
+
guard. So dev-flow injects what must never be missing: the ground rules of `skills/dev-flow/SKILL.md`
|
|
171
|
+
(the flow tool is the only invocation, checkpoints are words in chat, binds are explicit, the
|
|
172
|
+
playbook and state files are read-only) land in the session once, roughly a thousand tokens, and a
|
|
173
|
+
compaction that summarizes them away brings them back exactly once. The per-stage detail — mockup harness,
|
|
174
|
+
release sequence, reflection protocol — stays on disk, and each stage's turn names the one file to
|
|
175
|
+
read. Nothing to configure; reloads, resumed and forked sessions do not pay for it twice.
|
|
176
|
+
|
|
166
177
|
## What is enforced
|
|
167
178
|
|
|
168
179
|
While a feature is active, every tool call passes a guard:
|
package/docs/development.md
CHANGED
|
@@ -17,6 +17,27 @@ installed copy, point pi at it explicitly for that run: `pi -e .`.
|
|
|
17
17
|
A release cannot update a session that is already running — pi keeps the code it loaded at startup.
|
|
18
18
|
After merging and tagging, `/reload` in every session that must carry the new behavior.
|
|
19
19
|
|
|
20
|
+
## The skill: an injected core, plus references a stage reads
|
|
21
|
+
|
|
22
|
+
Pi advertises a skill (name, description, path) and loads `SKILL.md` only when the model decides to
|
|
23
|
+
read it — nothing makes a skill always-on. A session that never reads the playbook is a session that
|
|
24
|
+
guesses at a gate and then fights the guard, so `skills/dev-flow/SKILL.md` is split:
|
|
25
|
+
|
|
26
|
+
- The **core** — the ground rules every turn needs — sits between `<!-- dev-flow:core:start -->` and
|
|
27
|
+
`<!-- dev-flow:core:end -->`. The extension extracts that span and injects it into the hidden
|
|
28
|
+
`[dev-flow]` message **once per session**: a `dev-flow-skill` entry records the fact, so a reload,
|
|
29
|
+
resume or fork does not pay it twice, and a compaction that summarizes it away re-arms exactly one
|
|
30
|
+
re-injection. That budget is what every session in a dev-flow repo pays, so `package.test.ts`
|
|
31
|
+
refuses a core over **4,000 characters**.
|
|
32
|
+
- Everything else lives in `references/<stage>.md` — stage prose moved verbatim. The stage injection
|
|
33
|
+
names the one file the current stage needs (`…/references/plan.md` at plan), and the map under the
|
|
34
|
+
core lists them all. `references/` stays invisible to pi: only `SKILL.md` registers, and a
|
|
35
|
+
directory holding one is not scanned deeper.
|
|
36
|
+
|
|
37
|
+
When a stage grows, add to its reference file — do not grow the core. The tests guard both halves:
|
|
38
|
+
every stage has a file, the map names every file, and `release.md` hands over to `finish.md` because
|
|
39
|
+
the state machine has no finish stage that could name it.
|
|
40
|
+
|
|
20
41
|
## Publishing
|
|
21
42
|
|
|
22
43
|
`pi-dev-flow` is published to npm by `.github/workflows/release.yml`, triggered by the `v*` tag the
|
package/docs/guardrails.md
CHANGED
|
@@ -6,10 +6,11 @@ While a feature is active, the extension intercepts every tool call:
|
|
|
6
6
|
|
|
7
7
|
- **Nothing on main, ever** (until release): `git commit` on the default branch is blocked at every stage except `release` — where release chores commit in the main checkout (prefixed `DEV_FLOW_ALLOW_MAIN=1` for the hook) — and except one chore that needs no flow: a commit whose **only** change in the checkout is `.dev-flow/project.md`, because tracking the operator's playbook is setup, not feature work (any other dirty path closes that lane). pushes are judged by the ref they write — only pushing *to* the default branch (or a bare push while on it) requires stage `release`, so tag pushes and feature-branch pushes pass from any stage; `git merge` onto the default branch also requires stage `release`. Plus the standalone pre-commit hook for commits made outside Pi.
|
|
8
8
|
- **No code before an approved plan**: at stage `plan`, edits are confined to `.dev-flow/<slug>/` — the session's **own** feature directory, so one session cannot write another feature's plan and have its gate rubber-stamp what it never wrote.
|
|
9
|
-
- **Work stays in the worktree**: at stages `implement` and `pre-release`, edits are confined to that feature's worktree — judged per-path by the owning feature, so one session can never write into another session's worktree or into the main checkout.
|
|
9
|
+
- **Work stays in the worktree**: at stages `implement` and `pre-release`, edits are confined to that feature's worktree — judged per-path by the owning feature, so one session can never write into another session's worktree or into the main checkout. A throwaway **outside** the checkout is not feature work and stays free at every stage (the OS temp dir, e.g. a one-off rewrite script): both sides are realpath'd, so a symlink out of the temp dir is still judged as the repo path it writes, and a repository that merely lives under the temp dir (a test repo) keeps the stage rules.
|
|
10
10
|
- **Flow by default**: in a repo with `.dev-flow/`, an unbound session cannot touch source files at all — every request goes through `flow start`/`flow use`; there is no bypass. `flow start` refuses when the main checkout isn't on the default branch, worktrees are always created from the default branch, and the agent cannot check feature branches out in the main checkout.
|
|
11
11
|
- **Gates can't be skipped**: flow state is untouchable by the agent (edit tool and bash) — writing `state.json`, moving it away, or deleting a feature directory or the whole `.dev-flow/` folder all block; the `project.md` playbook is operator-owned — the main-checkout copy is blocked for the agent outright, and only a **docs or patch flow's** worktree copy may be edited (normal features route playbook changes to their own flow); every sanctioned playbook overwrite keeps the previous file as `project.md.bak`; editing worktree code invalidates a passing test check until `flow test` reruns.
|
|
12
12
|
- **Your project's own rules**: every `deny`/`confirm`/`protect`/`forbid` rule from the `flow-guard` block in project.md `## global` runs on every bash command and every edit/write path — in every stage and binding, ahead of dev-flow's own verdicts. A block always carries the reason you wrote.
|
|
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.
|
|
13
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.
|
|
14
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. By default the call is therefore **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. It applies to every session that loads the package, flow-bound or not (a session with no playbook has no way to opt out).
|
|
15
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`.
|
package/extensions/dev-flow.ts
CHANGED
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
* release stage; edits confined to the plan dir or the worktree; state.json
|
|
13
13
|
* is untouchable and the project.md playbook is operator-owned.
|
|
14
14
|
* 3. before_agent_start injects the active stage so the model always knows
|
|
15
|
-
* where it is and which gate comes next
|
|
15
|
+
* where it is and which gate comes next, plus the skill's always-on core once
|
|
16
|
+
* per session (pi only advertises a skill; it never loads it unasked) and the
|
|
17
|
+
* one playbook reference file the current stage needs.
|
|
16
18
|
*
|
|
17
19
|
* The stage logic lives in src/core.ts (unit-tested); this file is pi wiring.
|
|
18
20
|
* Inactive (fully pass-through) in repos without a .dev-flow/ directory.
|
|
@@ -46,6 +48,7 @@ import {
|
|
|
46
48
|
closedReflectionCount,
|
|
47
49
|
compactionReflectionLine,
|
|
48
50
|
detectForge,
|
|
51
|
+
extractSkillCore,
|
|
49
52
|
featureBranchPrefix,
|
|
50
53
|
FLOW_SHELL_HINT,
|
|
51
54
|
flowShellInvocation,
|
|
@@ -73,6 +76,7 @@ import {
|
|
|
73
76
|
reflectionRoutes,
|
|
74
77
|
reflectionsTidy,
|
|
75
78
|
reflectionsTidyHint,
|
|
79
|
+
stageReference,
|
|
76
80
|
sessionRunsOlderBuild,
|
|
77
81
|
|
|
78
82
|
listFiles,
|
|
@@ -129,6 +133,17 @@ function loadedVersion(): string | null {
|
|
|
129
133
|
/** This build's own identity, read once (the guard hot path must not re-walk the fs per call). */
|
|
130
134
|
const SELF_BUILD = pluginVersion(import.meta.dirname);
|
|
131
135
|
|
|
136
|
+
/** The dev-flow build this session *should* be running, as the disk describes it, and how to call it.
|
|
137
|
+
* In the dev-flow repo that is the checkout's own manifest: main moves ahead of the installed copy at
|
|
138
|
+
* every release, while `loadedVersion()` and the plugin's own package.json are the same file — so a
|
|
139
|
+
* session running 0.54.0 in a checkout already at 0.58.1 compared equal and nothing anywhere said so.
|
|
140
|
+
* In a normal project the only manifest is the installed package's, which a mid-session update moves. */
|
|
141
|
+
function checkoutBuild(root: string): { version: string | null; dir: string; repo: string; label: string } {
|
|
142
|
+
return isSelfRepo(root)
|
|
143
|
+
? { ...pluginVersion(root), label: "this checkout" }
|
|
144
|
+
: { ...SELF_BUILD, label: "the dev-flow install" };
|
|
145
|
+
}
|
|
146
|
+
|
|
132
147
|
/** Cross-copy registry: one process can register dev-flow more than once (the documented
|
|
133
148
|
* two-sources-at-once hazard: a project dogfood pointer plus an installed copy), and EVERY copy
|
|
134
149
|
* evaluates every guard hook. The flow-tool binding belongs to whichever copy served the call,
|
|
@@ -158,7 +173,7 @@ function copyWarning(): string | null {
|
|
|
158
173
|
}
|
|
159
174
|
/** Test seam: the smoke suite cannot load a second copy of this module, so it plants registry
|
|
160
175
|
* entries and asserts the warnings the real duplicate would print. */
|
|
161
|
-
export const testSeams = { copies: COPIES };
|
|
176
|
+
export const testSeams = { copies: COPIES, skillCore: { value: undefined as string | null | undefined } };
|
|
162
177
|
|
|
163
178
|
interface Ui {
|
|
164
179
|
hasUI: boolean;
|
|
@@ -285,7 +300,7 @@ async function releaseTags(root: string): Promise<string[] | null> {
|
|
|
285
300
|
}
|
|
286
301
|
|
|
287
302
|
const GATE_HELP =
|
|
288
|
-
"help [--json] | init [--force|--draft|--write <text>] | reflect [<note>|tidy] | roadmap [add <text>|pick <n> <slug>|done <n>|tidy] | doctor [<issue note>] | status [slug] [--json] | start <slug> [--ui] [--force] [--patch|--docs --confirmed] [--merge=squash|merge|rebase|any] [--check-upstream] | use <slug> | test | check | health | approve [--yolo] | verify [--yolo] | release [--yolo|--no-version|--no-fold-check] | release-done [--no-artifact-check|--no-release-create] | finish [--yolo] [slug] | abort [slug] | version [--check-upstream] — start preflights the playbook before creating anything: it prints playbook gaps and warns when the session runs an older dev-flow build, and it refuses until a merge policy is set (ask the operator squash / merge / rebase / any in chat, then re-run with --merge=<style> --confirmed — the answer is written into project.md and enforced from then on: gh/glab merges that contradict it are blocked, and release-done proves what actually landed); version prints the
|
|
303
|
+
"help [--json] | init [--force|--draft|--write <text>] | reflect [<note>|tidy] | roadmap [add <text>|pick <n> <slug>|done <n>|tidy] | doctor [<issue note>] | status [slug] [--json] | start <slug> [--ui] [--force] [--patch|--docs --confirmed] [--merge=squash|merge|rebase|any] [--check-upstream] | use <slug> | test | check | health | approve [--yolo] | verify [--yolo] | release [--yolo|--no-version|--no-fold-check] | release-done [--no-artifact-check|--no-release-create] | finish [--yolo] [slug] | abort [slug] | version [--check-upstream] — start preflights the playbook before creating anything: it prints playbook gaps and warns when the session runs an older dev-flow build than the disk ships (in the dev-flow repo, an older build than this checkout's own manifest), and it refuses until a merge policy is set (ask the operator squash / merge / rebase / any in chat, then re-run with --merge=<style> --confirmed — the answer is written into project.md and enforced from then on: gh/glab merges that contradict it are blocked, and release-done proves what actually landed); version prints the build the disk says to run (this checkout's own manifest in the dev-flow repo, the installed package's elsewhere) and names any other dev-flow copies registered in the same process (--check-upstream also asks the registry for the published one) — reflect <note> queues a suggestion in reflections.md (gate flags like --confirmed are ignored there); reflect tidy drops the closed (`- [x]`) items from reflections.md — every surface that queues or reviews reflections nudges when the checked-off pile grows; bare reflect prints the full session-reflection protocol (review the session log, re-check open items against shipped fixes and newer dev-flow versions, dedupe and report new findings, put the fix decision to the operator); roadmap manages .dev-flow/roadmap.md, the gitignored backlog of future features (bare lists open items; add appends one; pick <n> <slug> stamps open item <n> with the slug a later flow start uses — flow finish checks it off when that feature ships; done <n> checks off by hand; tidy drops done items); bare doctor reviews structure, git consistency and open reflections (routes each fix to a flow; it never writes); doctor <note> prints an investigation brief for a fresh observation; state gates take [slug] and --confirmed (the operator already answered in chat); --patch/--docs likewise need --confirmed (the operator granted the mode); --yolo on any state gate (approve/verify/release/finish) = the operator said \"yolo\" at that checkpoint: it answers that question and pre-confirms every later one (needs --confirmed; checks and guardrails stay); release --no-fold-check = operator-granted escape from the changelog fold proofs (the entries pending before the release are not line-checked; the entry heading and the 'this branch touched the changelog' proofs stay); release --no-version = this flow ships merge + changelog only — no bump, tag or forge release; the entry rides under Unreleased until the next versioned release folds it (default: versioned); when the session runs an older dev-flow build than the checkout, release names both builds, lists what the running code can no longer prove, and asks the operator update (/reload) or proceed with the old release — an operator decision recorded in state and repeated by release-done, never a block";
|
|
289
304
|
const featDir = (root: string, slug: string) => path.join(dfDir(root), slug);
|
|
290
305
|
const stateFile = (root: string, slug: string) => path.join(featDir(root, slug), "state.json");
|
|
291
306
|
const claimFile = (root: string, slug: string) => path.join(featDir(root, slug), "claim.json");
|
|
@@ -324,6 +339,32 @@ const sessionKey = (ctx: { cwd: string; sessionManager?: { getSessionId(): strin
|
|
|
324
339
|
ctx.sessionManager?.getSessionId() ? `sid:${ctx.sessionManager.getSessionId()}` : `cwd:${ctx.cwd}`;
|
|
325
340
|
/** Sessions with a dev-flow-initiated compaction in flight (prevents stacked compactions). */
|
|
326
341
|
const compacting = new Set<string>();
|
|
342
|
+
/** Sessions that already received the skill's always-on core this session. The `dev-flow-skill`
|
|
343
|
+
* entry records the injection in the session branch, so /reload, resume and fork restore the fact
|
|
344
|
+
* instead of paying ~1k tokens a second time. */
|
|
345
|
+
const coreInjected = new Set<string>();
|
|
346
|
+
/** Sessions whose last compaction dropped the core out of context — the next run pays it once more. */
|
|
347
|
+
const coreStale = new Set<string>();
|
|
348
|
+
/** The skill dir of THIS loaded copy. Since 0.57.1 dropped the `.pi/extensions` dogfood shim, the
|
|
349
|
+
* copy a session runs and a development checkout are different installs, so playbook paths
|
|
350
|
+
* resolve from the code actually loaded — never from cwd. */
|
|
351
|
+
const SKILL_DIR = path.join(import.meta.dirname, "..", "skills", "dev-flow");
|
|
352
|
+
let skillCoreCache: string | null | undefined;
|
|
353
|
+
/** The core block between SKILL.md's markers, read once per process (/reload reloads the module
|
|
354
|
+
* and picks up edits). Null — no file, no markers, empty core — leaves every message exactly as it
|
|
355
|
+
* was: a copy shipped without its skill must not take the guards, or the run, down. */
|
|
356
|
+
function skillCore(): string | null {
|
|
357
|
+
// Seam first: a test cannot ship a copy of the package with its skills/ directory deleted.
|
|
358
|
+
if (testSeams.skillCore.value !== undefined) return testSeams.skillCore.value;
|
|
359
|
+
if (skillCoreCache === undefined) {
|
|
360
|
+
try {
|
|
361
|
+
skillCoreCache = extractSkillCore(readFileSync(path.join(SKILL_DIR, "SKILL.md"), "utf8"));
|
|
362
|
+
} catch {
|
|
363
|
+
skillCoreCache = null;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return skillCoreCache;
|
|
367
|
+
}
|
|
327
368
|
|
|
328
369
|
/** Seam for the takeover's summarize call (pi's own compact()); tests replace `.run` — mutable object stands in for ESM mocking. */
|
|
329
370
|
export const compactionTakeover: { run: typeof compact } = { run: compact };
|
|
@@ -390,6 +431,8 @@ const writeClaim = (root: string, slug: string, key: string) =>
|
|
|
390
431
|
function releaseSession(root: string, key: string): void {
|
|
391
432
|
bindings.delete(key);
|
|
392
433
|
compacting.delete(key);
|
|
434
|
+
coreInjected.delete(key);
|
|
435
|
+
coreStale.delete(key);
|
|
393
436
|
if (!existsSync(dfDir(root))) return;
|
|
394
437
|
for (const d of readdirSync(dfDir(root), { withFileTypes: true })) {
|
|
395
438
|
if (!d.isDirectory()) continue;
|
|
@@ -777,15 +820,15 @@ ${mdDigest(draftRefresh)}`))
|
|
|
777
820
|
if (curBr !== cfg.defaultBranch && !flag("force")) return { text: `main checkout is on ${curBr}, not ${cfg.defaultBranch} — check out ${cfg.defaultBranch} first (git checkout ${cfg.defaultBranch} && git pull) or flow use an unfinished feature; --force to override`, isError: true };
|
|
778
821
|
// --- preflight: is this session running the current build, and is the playbook complete? ---
|
|
779
822
|
const notes: string[] = [];
|
|
780
|
-
const
|
|
781
|
-
const behind = sessionRunsOlderBuild(loadedVersion(),
|
|
782
|
-
if (behind) notes.push(`warning: this session runs dev-flow ${behind},
|
|
823
|
+
const disk = checkoutBuild(root);
|
|
824
|
+
const behind = sessionRunsOlderBuild(loadedVersion(), disk.version);
|
|
825
|
+
if (behind) notes.push(`warning: this session runs dev-flow ${behind}, ${disk.label} ships ${disk.version} — /reload before trusting what a gate prints`);
|
|
783
826
|
const dupStart = copyWarning();
|
|
784
827
|
if (dupStart) notes.push(dupStart);
|
|
785
828
|
if (flag("check-upstream")) {
|
|
786
829
|
const pub = await sh("npm view pi-dev-flow version", root);
|
|
787
830
|
const newest = pub.ok ? pub.out.trim().split("\n").pop() : "";
|
|
788
|
-
notes.push(newest ? `published dev-flow: ${newest} (this build: ${
|
|
831
|
+
notes.push(newest ? `published dev-flow: ${newest} (this build: ${loadedVersion() ?? "?"})${loadedVersion() && newest !== loadedVersion() ? " — an update is available" : ""}` : "could not read the published dev-flow version (offline?)");
|
|
789
832
|
}
|
|
790
833
|
// missing playbook parameters are printed at the moment they start to matter, not promised to a later doctor run
|
|
791
834
|
const gaps = doctorFindings(root, cfg, loadProject(dfDir(root)).md).filter((x) => !x.startsWith("no merge policy"));
|
|
@@ -817,12 +860,13 @@ ${mdDigest(draftRefresh)}`))
|
|
|
817
860
|
cfg.release.merge = style;
|
|
818
861
|
notes.push(written.note);
|
|
819
862
|
}
|
|
820
|
-
// stamp the dev-flow build that started this feature — a stuck flow can later be read against its tooling
|
|
821
|
-
|
|
863
|
+
// stamp the dev-flow build that started this feature — a stuck flow can later be read against its tooling.
|
|
864
|
+
// the stamp is what ran, not what the disk claims (that mismatch is the warning above).
|
|
865
|
+
const state = newState(slugArg, flag("ui"), flag("patch"), flag("docs"), loadedVersion() ?? undefined);
|
|
822
866
|
mkdirSync(path.join(featDir(root, slugArg), "plan"), { recursive: true });
|
|
823
867
|
writeState(root, state);
|
|
824
868
|
sess.bind(slugArg);
|
|
825
|
-
return { text: `feature ${slugArg} started at stage plan (ui=${state.ui}${state.patch ? ", patch" : state.docs ? ", docs" : ""}${
|
|
869
|
+
return { text: `feature ${slugArg} started at stage plan (ui=${state.ui}${state.patch ? ", patch" : state.docs ? ", docs" : ""}${state.flowVersion ? `, dev-flow ${state.flowVersion}` : ""}).${notes.length ? `\n${notes.join("\n")}` : ""}\n${nextHint(state, cfg)}` };
|
|
826
870
|
}
|
|
827
871
|
|
|
828
872
|
case "status": {
|
|
@@ -830,7 +874,11 @@ ${mdDigest(draftRefresh)}`))
|
|
|
830
874
|
const { md } = loadProject(df);
|
|
831
875
|
// cheap fs probes only (no git subprocesses) — status is a glance, `flow doctor` is the full list
|
|
832
876
|
const findings = md ? doctorFindings(root, cfg, md) : [];
|
|
833
|
-
|
|
877
|
+
// a session running an older build than the disk ships is the one thing a glance must say: every
|
|
878
|
+
// gate proof printed since the drift began belongs to the older code.
|
|
879
|
+
const disk = checkoutBuild(root);
|
|
880
|
+
const staleBuild = sessionRunsOlderBuild(loadedVersion(), disk.version);
|
|
881
|
+
const warn = [...(findings.length ? [`⚠ doctor: ${findings.length} finding(s) — run flow doctor`] : []), ...(staleBuild ? [`⚠ this session runs dev-flow ${staleBuild}, ${disk.label} ships ${disk.version} — /reload`] : []), ...(copyWarning() ? [copyWarning()!] : [])];
|
|
834
882
|
// the backlog nudge belongs to the no-features answer too — that is when a pick is most useful
|
|
835
883
|
const rmap = roadmapOpenCount(readRoadmap(root));
|
|
836
884
|
const rmapLine = rmap ? [`◇ ${rmap} roadmap item(s) open — flow roadmap`] : [];
|
|
@@ -936,9 +984,11 @@ ${mdDigest(draftRefresh)}`))
|
|
|
936
984
|
|
|
937
985
|
case "version": {
|
|
938
986
|
// the plugin's own version — separate from the project's versioning.file version the release gates use
|
|
939
|
-
const self =
|
|
987
|
+
const self = checkoutBuild(root);
|
|
940
988
|
const behind = sessionRunsOlderBuild(loadedVersion(), self.version);
|
|
941
989
|
const head = self.version ? `dev-flow ${self.version} (pi-dev-flow at ${self.dir})` : `dev-flow version unknown — no pi-dev-flow package.json above ${self.dir}`;
|
|
990
|
+
// in the dev-flow repo head names the checkout, so name where the stale code actually lives
|
|
991
|
+
const from = SELF_BUILD.dir !== self.dir ? ` (from ${SELF_BUILD.dir})` : "";
|
|
942
992
|
const dupNote = copyWarning();
|
|
943
993
|
// --check-upstream is the one that asks the registry; plain flow version stays offline and instant
|
|
944
994
|
if (flag("check-upstream")) {
|
|
@@ -946,7 +996,7 @@ ${mdDigest(draftRefresh)}`))
|
|
|
946
996
|
const newest = pub.ok ? pub.out.trim().split("\n").pop() : "";
|
|
947
997
|
return { text: newest ? `${head} — published: ${newest}${self.version && newest !== self.version ? " (update available)" : ""}` : `${head} — could not read the published version (offline?)` };
|
|
948
998
|
}
|
|
949
|
-
return { text: `${behind ? `${head} — but this session runs ${behind}; /reload to run ${self.version}` : head}${dupNote ? `\n${dupNote}` : ""}` };
|
|
999
|
+
return { text: `${behind ? `${head} — but this session runs ${behind}${from}; /reload to run ${self.version}` : head}${dupNote ? `\n${dupNote}` : ""}` };
|
|
950
1000
|
}
|
|
951
1001
|
|
|
952
1002
|
case "approve": {
|
|
@@ -1174,7 +1224,7 @@ ${mdDigest(draftRefresh)}`))
|
|
|
1174
1224
|
// legitimate choice (hotfix, offline reload), and refusing would close exactly the emergency the relaxed
|
|
1175
1225
|
// modes exist for. The gate names both builds, lists what the running code is missing, and folds the
|
|
1176
1226
|
// update-or-proceed question into the Release? checkpoint — the operator's word, recorded in state.
|
|
1177
|
-
const selfBuild =
|
|
1227
|
+
const selfBuild = checkoutBuild(root);
|
|
1178
1228
|
const behind = sessionRunsOlderBuild(loadedVersion(), selfBuild.version);
|
|
1179
1229
|
// truly behind, not merely different: a session whose loaded build is NEWER than the checkout's manifest
|
|
1180
1230
|
// has every proof the checkout would run, and asking about it would be noise.
|
|
@@ -1185,12 +1235,12 @@ ${mdDigest(draftRefresh)}`))
|
|
|
1185
1235
|
const clPath = path.join(selfBuild.dir, "CHANGELOG.md");
|
|
1186
1236
|
const missing = existsSync(clPath) && selfBuild.version ? changelogVersionsBetween(readFileSync(clPath, "utf8"), behind, selfBuild.version) : [];
|
|
1187
1237
|
staleAsk =
|
|
1188
|
-
` This session runs dev-flow ${behind},
|
|
1238
|
+
` This session runs dev-flow ${behind}, ${selfBuild.label} ships ${selfBuild.version ?? "?"} — gate proofs shipped between the two will NOT run. ` +
|
|
1189
1239
|
(missing.length
|
|
1190
1240
|
? `Shipped since ${behind}: ${missing.slice(0, 8).join(", ")}${missing.length > 8 ? ` …(${missing.length} total)` : ""} — see ${clPath}. `
|
|
1191
1241
|
: `What shipped between them is not readable from the checkout's CHANGELOG.md — read it before deciding. `) +
|
|
1192
1242
|
`Update (/reload, then re-run flow release on the current build) or proceed with the old release?`;
|
|
1193
|
-
staleNote = `released under dev-flow ${behind} (
|
|
1243
|
+
staleNote = `released under dev-flow ${behind} (${selfBuild.label} ${selfBuild.version ?? "?"}) by operator choice — proofs newer than ${behind} did not run`;
|
|
1194
1244
|
}
|
|
1195
1245
|
const audit = flag("confirmed") ? " (confirmed by operator instruction)" : state!.yolo ? " (yolo: pre-confirmed)" : "";
|
|
1196
1246
|
if (!flag("confirmed") && !state!.yolo) {
|
|
@@ -1212,7 +1262,7 @@ ${mdDigest(draftRefresh)}`))
|
|
|
1212
1262
|
// the version of record is fixed here, from the manifest this gate validated: release-done must not
|
|
1213
1263
|
// re-read a checkout that may still be behind (#52)
|
|
1214
1264
|
if (!state!.noVersion && manifestVer) state!.releaseVersion = manifestVer;
|
|
1215
|
-
if (stale) state!.staleBuild = `${behind} (
|
|
1265
|
+
if (stale) state!.staleBuild = `${behind} (${selfBuild.label} ${selfBuild.version ?? "?"})`;
|
|
1216
1266
|
writeState(root, state!);
|
|
1217
1267
|
return { text: `release approved${audit}${state!.noVersion ? " — unversioned: no bump or tag; your changelog entry rides under Unreleased until the next versioned release folds it" : ""} — entering release stage.${manifestVer ? ` Version ${manifestVer}.` : ""}${foldNote}${staleNote ? ` ${staleNote}.` : ""}\n${nextHint(state!, cfg)}` };
|
|
1218
1268
|
}
|
|
@@ -1325,7 +1375,7 @@ ${mdDigest(draftRefresh)}`))
|
|
|
1325
1375
|
ghNote = gr.ok ? `${forge} release ${tag} created. ${notesNote}`.trim() : `${forge} release skipped: ${tail(gr.out)}`;
|
|
1326
1376
|
}
|
|
1327
1377
|
}
|
|
1328
|
-
const behind = sessionRunsOlderBuild(loadedVersion(),
|
|
1378
|
+
const behind = sessionRunsOlderBuild(loadedVersion(), checkoutBuild(root).version);
|
|
1329
1379
|
const openRelease = checklistPending(cfg, state!, "release");
|
|
1330
1380
|
// release-stage items have no gate of their own: the operator's Finish? answer is what closes them, so
|
|
1331
1381
|
// name them at the last objective gate — on the way out too, or the refusal hides half the story
|
|
@@ -1362,7 +1412,7 @@ ${mdDigest(draftRefresh)}`))
|
|
|
1362
1412
|
state!.staleBuild
|
|
1363
1413
|
? `stale build acknowledged at release gate: this session ran dev-flow ${state!.staleBuild} — proofs newer than it did not run.`
|
|
1364
1414
|
: behind
|
|
1365
|
-
? `warning: this session runs dev-flow ${behind}, not the build
|
|
1415
|
+
? `warning: this session runs dev-flow ${behind}, not the build the disk ships — /reload before trusting what it printed.`
|
|
1366
1416
|
: "",
|
|
1367
1417
|
mergeNote,
|
|
1368
1418
|
openNote,
|
|
@@ -1611,19 +1661,46 @@ export default function devFlow(pi: ExtensionAPI) {
|
|
|
1611
1661
|
/** Restore this session's binding from its branch history (survives resume/fork). */
|
|
1612
1662
|
const rebuildSession = (ctx: ExtensionContext) => {
|
|
1613
1663
|
let slug: string | null = null;
|
|
1664
|
+
let sawCore = false;
|
|
1665
|
+
let coreStaleHere = false;
|
|
1614
1666
|
for (const e of ctx.sessionManager?.getBranch() ?? []) {
|
|
1615
1667
|
// SAFETY: narrow structural view of the SessionEntry union; we only read entries whose type/customType match our own appendEntry writes.
|
|
1616
|
-
const ce = e as unknown as { type: string; customType?: string; data?: { slug?: string | null } };
|
|
1668
|
+
const ce = e as unknown as { type: string; customType?: string; data?: { slug?: string | null; stale?: boolean } };
|
|
1617
1669
|
if (ce.type === "custom" && ce.customType === "dev-flow-bind") slug = ce.data?.slug ?? null;
|
|
1670
|
+
if (ce.type === "custom" && ce.customType === "dev-flow-skill") {
|
|
1671
|
+
sawCore = true;
|
|
1672
|
+
coreStaleHere = ce.data?.stale === true; // the newest skill entry decides: a stale one follows a compaction
|
|
1673
|
+
}
|
|
1618
1674
|
}
|
|
1619
1675
|
const key = sessionKey(ctx);
|
|
1620
1676
|
bindings.set(key, slug);
|
|
1677
|
+
// The branch is the truth about what the restored context holds: a marker means the core is in it
|
|
1678
|
+
// (do not pay twice), no marker means the branch was rewound or forked past the injection (give it
|
|
1679
|
+
// back), and a stale marker means a compaction summarized it away before the reload (give it back).
|
|
1680
|
+
if (sawCore) coreInjected.add(key);
|
|
1681
|
+
else coreInjected.delete(key);
|
|
1682
|
+
if (coreStaleHere) coreStale.add(key);
|
|
1683
|
+
else coreStale.delete(key);
|
|
1621
1684
|
// A reload ends the old session, which released its claim; the restored one must reclaim what its own
|
|
1622
1685
|
// branch says it holds, or the repo answers "claimed by another live session" to the session that
|
|
1623
1686
|
// holds it. A foreign live claim wins — restoring is not a takeover.
|
|
1624
1687
|
if (slug && readState(ctx.cwd, slug) && !claimBlocks(readClaim(ctx.cwd, slug), key)) writeClaim(ctx.cwd, slug, key);
|
|
1625
1688
|
};
|
|
1626
1689
|
|
|
1690
|
+
/** The run's playbook preamble: the skill's always-on core, once per session. Later runs come back
|
|
1691
|
+
* empty because the transcript already holds it. The one exception is a compaction that summarized
|
|
1692
|
+
* it away (see session_compact), which pays it once more — and every real injection records itself,
|
|
1693
|
+
* so the newest skill entry on the branch is always the truth a reload restores from. */
|
|
1694
|
+
const corePreamble = (key: string): string => {
|
|
1695
|
+
if (coreInjected.has(key) && !coreStale.has(key)) return "";
|
|
1696
|
+
const core = skillCore();
|
|
1697
|
+
if (!core) return "";
|
|
1698
|
+
coreStale.delete(key);
|
|
1699
|
+
coreInjected.add(key);
|
|
1700
|
+
pi.appendEntry("dev-flow-skill", { core: true });
|
|
1701
|
+
return `${core}\n\n`;
|
|
1702
|
+
};
|
|
1703
|
+
|
|
1627
1704
|
pi.registerCommand("flow", {
|
|
1628
1705
|
description: `dev-flow gates: ${GATE_HELP}`,
|
|
1629
1706
|
handler: async (args, ctx) => {
|
|
@@ -1703,7 +1780,15 @@ export default function devFlow(pi: ExtensionAPI) {
|
|
|
1703
1780
|
});
|
|
1704
1781
|
// pi forcing its own compaction while a flow is bound means the pacing was wrong — park a note for the operator.
|
|
1705
1782
|
pi.on("session_compact", async (event, ctx) => {
|
|
1706
|
-
if (!existsSync(dfDir(ctx.cwd))
|
|
1783
|
+
if (!existsSync(dfDir(ctx.cwd))) return;
|
|
1784
|
+
// Whatever the reason, the summary replaced the transcript — the core the first run injected is
|
|
1785
|
+
// gone from context, so the next run pays it once more (manual compactions included: our own
|
|
1786
|
+
// safe-point compaction is the common one).
|
|
1787
|
+
coreStale.add(sessionKey(ctx));
|
|
1788
|
+
// Durable too: a compaction the session survives a reload outlives the in-memory flag, and a
|
|
1789
|
+
// branch whose newest skill entry is stale tells the restored run to pay the core again.
|
|
1790
|
+
pi.appendEntry("dev-flow-skill", { core: true, stale: true });
|
|
1791
|
+
if (event.reason === "manual") return;
|
|
1707
1792
|
const st = boundFeature(ctx.cwd, sessionKey(ctx));
|
|
1708
1793
|
if (!st) return;
|
|
1709
1794
|
const f = path.join(dfDir(ctx.cwd), "reflections.md");
|
|
@@ -1746,7 +1831,7 @@ export default function devFlow(pi: ExtensionAPI) {
|
|
|
1746
1831
|
const why = await askOperator(ctx, `Editing ${path.relative(ctx.cwd, abs) || abs}`, pv.confirm);
|
|
1747
1832
|
if (why) return { block: true, reason: why };
|
|
1748
1833
|
}
|
|
1749
|
-
const reason = writeGuard({ abs, dfDir: dfDir(ctx.cwd), features: feats, boundSlug: bound?.slug ?? null });
|
|
1834
|
+
const reason = writeGuard({ abs, dfDir: dfDir(ctx.cwd), features: feats, boundSlug: bound?.slug ?? null, repoRoot: ctx.cwd });
|
|
1750
1835
|
if (reason) return { block: true, reason };
|
|
1751
1836
|
// Editing a worktree invalidates that feature's tier-1 checks and tier-2 confirmation until they rerun.
|
|
1752
1837
|
const owner = feats.find((f) => f.worktreeAbs && abs.startsWith(f.worktreeAbs + path.sep));
|
|
@@ -1852,12 +1937,15 @@ export default function devFlow(pi: ExtensionAPI) {
|
|
|
1852
1937
|
if (run[CONTEXT_EMITTED]) return undefined;
|
|
1853
1938
|
run[CONTEXT_EMITTED] = true;
|
|
1854
1939
|
if (!existsSync(dfDir(ctx.cwd))) return undefined;
|
|
1940
|
+
const key = sessionKey(ctx);
|
|
1941
|
+
// The playbook core rides along on the message this run writes anyway — once per session.
|
|
1942
|
+
const core = corePreamble(key);
|
|
1855
1943
|
const cfg = loadProject(dfDir(ctx.cwd)).cfg;
|
|
1856
|
-
const state = boundFeature(ctx.cwd,
|
|
1944
|
+
const state = boundFeature(ctx.cwd, key);
|
|
1857
1945
|
if (!state || state.stage === "done") {
|
|
1858
1946
|
// Default posture for an unbound session in a dev-flow repo (guards make it stick; this makes it understood).
|
|
1859
1947
|
let content = "[dev-flow] no flow bound. Every request goes through flow. New work: flow start <slug>; unfinished feature: flow use <slug>.";
|
|
1860
|
-
const cb = claimBlocker(ctx.cwd,
|
|
1948
|
+
const cb = claimBlocker(ctx.cwd, key);
|
|
1861
1949
|
if (cb) content += ` Also: ${cb.state.slug} is claimed by another live session (pid ${cb.claim.pid}) — flow use ${cb.state.slug} takes it over explicitly.`;
|
|
1862
1950
|
const curBr = await currentBranch(ctx.cwd);
|
|
1863
1951
|
if (curBr && curBr !== cfg.defaultBranch) content += ` Also: main checkout is on ${curBr}, not ${cfg.defaultBranch} — surface this to the operator before starting work.`;
|
|
@@ -1865,10 +1953,15 @@ export default function devFlow(pi: ExtensionAPI) {
|
|
|
1865
1953
|
if (refl0.length) content += ` Also: ${refl0.length} reflection(s) open — run flow doctor.`;
|
|
1866
1954
|
const rmap0 = roadmapOpenCount(readRoadmap(ctx.cwd));
|
|
1867
1955
|
if (rmap0) content += ` Also: ${rmap0} roadmap item(s) open — flow roadmap lists them, flow roadmap pick <n> <slug> hands one to flow start.`;
|
|
1868
|
-
|
|
1956
|
+
content += ` Also: the playbook map is ${path.join(SKILL_DIR, "SKILL.md")} — per-stage detail sits in references/ beside it (start: flow init, modes, ownership).`;
|
|
1957
|
+
return { message: { customType: "dev-flow-context", display: false, content: `${core}${content}` } };
|
|
1869
1958
|
}
|
|
1870
1959
|
const guidance: string[] = [];
|
|
1871
1960
|
if (state.yolo) guidance.push("YOLO mode: the operator pre-confirmed every gate question from here on (Verified?/Release?/Finish?) — run the remaining gates (verify → release → release-done → finish) back to back without stopping to ask; guidance the operator attached to the yolo word (e.g. patch bump, no tag) is a binding directive for the chain; checks and guardrails stay fully enforced.");
|
|
1961
|
+
// The one playbook file this stage needs, named outright: the model reads it instead of
|
|
1962
|
+
// guessing what a stage asks of it, and it pays for itself the first time a gate is refused.
|
|
1963
|
+
const ref = stageReference(state.stage);
|
|
1964
|
+
if (ref) guidance.push(`Stage playbook: read ${path.join(SKILL_DIR, ref)} before gate work in this stage.`);
|
|
1872
1965
|
const prose = stageGuidance(cfg, state.stage);
|
|
1873
1966
|
if (prose) guidance.push(`Stage guidance (${prose.source}): ${prose.text}`);
|
|
1874
1967
|
const pend = checklistPending(cfg, state, state.stage);
|
|
@@ -1881,7 +1974,7 @@ export default function devFlow(pi: ExtensionAPI) {
|
|
|
1881
1974
|
message: {
|
|
1882
1975
|
customType: "dev-flow-context",
|
|
1883
1976
|
display: false,
|
|
1884
|
-
content:
|
|
1977
|
+
content: `${core}[dev-flow] this session is bound to: ${state.slug}${state.patch ? " (patch)" : state.docs ? " (docs)" : ""} — stage: ${state.stage}${state.ui ? " (UI)" : ""}${state.worktree ? `, worktree: ${state.worktree} (branch ${state.branch})` : ""}.
|
|
1885
1978
|
Next: ${nextHint(state, cfg)}.
|
|
1886
1979
|
${guidance.length ? guidance.join("\n") + "\n" : ""}Rules: follow the dev-flow skill playbook; gates run through the flow tool only — \`flow\` is not a shell command, and the operator answers words in chat, never commands: you run the gate. \`/flow\` is the operator's manual override, not yours. Stage guards block out-of-stage edits and main-branch git ops — do not work around them.`,
|
|
1887
1980
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-dev-flow",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.59.1",
|
|
4
4
|
"description": "Enforced feature workflow for Pi: plan → implement → pre-release → release, gated checkpoints, self-improvement reflections, one git worktree per feature, changelog + publish as part of the release",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|