pi-dev-flow 0.61.0 → 0.61.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,16 @@ Format: newest first. `Unreleased` collects what's merged but not yet tagged.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.61.1] - 2026-10-23
8
+
9
+ ### Changed
10
+
11
+ - **The newest dev-flow copy judges the guards alone.** When one process runs several copies (the documented two-sources situation — a checkout's own `pi.extensions` manifest beside the npm install is the common one), every copy's event hooks now run an election first: a copy with a lower registered version answers nothing — no guard vetoes, no context injection, no footer, no compaction takeover. Stale code judging alongside fresh was the real hazard the two-sources warning hinted at: on a 22-hour-old pi-web server a 0.57.0-era copy blocked tool calls beside the current one, and nobody could say which copy answered. Node cannot unload a loaded module and pi cannot unregister its hooks, so silence is the most in-package removal can be — only a host restart drops the stale code, and the warnings now say so. Equal versions both judge; a copy whose version cannot be read is never outranked; gate tool handlers stay live on every copy (the host dispatches those per session, and the stale-build warnings already cover them).
12
+
13
+ ### Fixed
14
+
15
+ - **The duplicate-copy warning names its speaker** — `this call served by <dir> (v); this copy is the newest and judges the guards` (or admits it is the older one and stays silent) — and the stale-build notes across `start`, `status` and `version` tell the truth about what fixes skew: `/reload` re-binds session state, but in a shared-process host (pi-web) only restarting the host swaps loaded code; docs/development.md and the README's two-sources section now say the same. Proven on the live server: a working-tree stamp frozen at 0.57.0 survived a day of reloads while the checkout shipped two versions.
16
+
7
17
  ## [0.61.0] - 2026-10-23
8
18
 
9
19
  ### Fixed
package/README.md CHANGED
@@ -52,8 +52,12 @@ pi install ./pi-dev-flow # or a local checkout
52
52
  Later releases arrive with `pi update --extensions` (an npm install reconciles to the newest version);
53
53
  then `/reload` — a running session keeps the code it loaded at startup. Two sources at once (a project
54
54
  `git:` pin beside the global `npm:` package) load two copies — pi dedupes extensions by path, not by
55
- package — so keep the one you actually update from: `flow version` lists every dev-flow copy
56
- registered in the process, and the on-disk session claim keeps the guard of a copy that never served
55
+ package — so keep the one you actually update from. **The newest copy judges alone:** every copy's
56
+ guard hooks check which registered version is highest, and a stale duplicate answers nothing — the
57
+ most in-package removal can be, because Node cannot unload a loaded module and pi cannot unregister
58
+ its hooks. Only a host restart drops stale code; `/reload` re-binds session state, it never swaps
59
+ code. `flow version` lists every dev-flow copy registered in the process and names the copy serving
60
+ the call, and the on-disk session claim keeps the guard of a copy that never served
57
61
  a flow call attributing your commands correctly.
58
62
 
59
63
  Until `flow init` writes the playbook (`.dev-flow/project.md`), dev-flow says nothing in a repo — no
@@ -8,14 +8,18 @@ pi -e . run /flow status # try it against any repo
8
8
  ```
9
9
 
10
10
  Sessions in this checkout load the **single global dev-flow install** (`pi update --extensions`
11
- reconciles it after a release, `/reload` brings it into a running session) — there is deliberately no
11
+ reconciles it after a release; loaded code swaps only when the process re-imports — `/reload` in a
12
+ per-session host, a host restart in a shared-process host like pi-web) — there is deliberately no
12
13
  `.pi/extensions/` pointer here: a committed shim beside the global package loads two copies of the
13
14
  extension in one process (pi dedupes by path, not by package — see the README's two-sources
14
- warning), which is what the shim used to cause. To dogfood the working tree instead of the
15
- installed copy, point pi at it explicitly for that run: `pi -e .`.
15
+ warning), which is what the shim used to cause. The package's own `pi.extensions` manifest remains a
16
+ second source for any session opened in this checkout — deliberate dogfooding, made safe by the guard
17
+ election: the newest registered copy judges, older loaded copies answer nothing. To dogfood the
18
+ working tree instead of the installed copy, point pi at it explicitly for that run: `pi -e .`.
16
19
 
17
20
  A release cannot update a session that is already running — pi keeps the code it loaded at startup.
18
- After merging and tagging, `/reload` in every session that must carry the new behavior.
21
+ After merging and tagging, `/reload` in every session that must carry the new behavior; shared-process
22
+ hosts (pi-web) keep stale code until restarted, so reload there re-binds state but does not swap code.
19
23
 
20
24
  ## The skill: an injected core, plus references a stage reads
21
25
 
@@ -167,11 +167,24 @@ function registerCopy(): void {
167
167
  function otherCopies(): CopyEntry[] {
168
168
  return COPIES.filter((r) => r.pid === process.pid && r.dir !== SELF_BUILD.dir);
169
169
  }
170
+ /** Election: when one process runs several dev-flow copies (the documented two-sources hazard, or a
171
+ * copy whose loaded code predates an update), only the highest-version copy may judge — stale code
172
+ * must not veto tool calls with a build nobody reviewed. Node cannot unload a loaded module and pi
173
+ * cannot unregister its hooks, so silence is the most removal can be from inside the package; only
174
+ * a host restart truly drops stale code. Equal versions both judge (same code, same verdicts); a
175
+ * copy whose version cannot be read is never outranked. Gate tool/command handlers stay live on
176
+ * every copy: the host dispatches a session's flow calls to whichever copy loaded that session,
177
+ * and staleness there is what the /reload warnings address. */
178
+ function guardsAreMine(): boolean {
179
+ const mine = SELF_BUILD.version;
180
+ if (!mine) return true; // an unreadable version is never outranked
181
+ return !otherCopies().some((r) => r.version && cmpVersions(r.version, mine) > 0);
182
+ }
170
183
  function copyWarning(): string | null {
171
184
  const dup = otherCopies();
172
- return dup.length
173
- ? `warning: ${dup.length} other dev-flow cop${dup.length === 1 ? "y" : "ies"} registered in this process: ${dup.map((d) => `${d.dir} (${d.version ?? "?"})`).join(", ")} — every copy evaluates the guard hooks, so keep only one source you intend (README: two sources at once)`
174
- : null;
185
+ if (!dup.length) return null;
186
+ const verdict = guardsAreMine() ? "this copy is the newest and judges the guards" : "this copy is older and stays silent \u2014 the newest copy judges";
187
+ return `warning: ${dup.length} other dev-flow cop${dup.length === 1 ? "y" : "ies"} registered in this process: ${dup.map((d) => `${d.dir} (${d.version ?? "?"})`).join(", ")} \u2014 this call served by ${SELF_BUILD.dir} (${SELF_BUILD.version ?? "?"}); ${verdict}. Keep only one source you intend; a host restart drops stale code (README: two sources at once)`;
175
188
  }
176
189
  /** Test seam: the smoke suite cannot load a second copy of this module, so it plants registry
177
190
  * entries and asserts the warnings the real duplicate would print. */
@@ -856,7 +869,7 @@ ${mdDigest(draftRefresh)}`))
856
869
  const notes: string[] = [];
857
870
  const disk = checkoutBuild(root);
858
871
  const behind = sessionRunsOlderBuild(loadedVersion(), disk.version);
859
- if (behind) notes.push(`warning: this session runs dev-flow ${behind}, ${disk.label} ships ${disk.version} — /reload before trusting what a gate prints`);
872
+ if (behind) notes.push(`warning: this session runs dev-flow ${behind}, ${disk.label} ships ${disk.version} — /reload rebinds session state; only restarting the host swaps the code it runs`);
860
873
  const dupStart = copyWarning();
861
874
  if (dupStart) notes.push(dupStart);
862
875
  if (flag("check-upstream")) {
@@ -912,7 +925,7 @@ ${mdDigest(draftRefresh)}`))
912
925
  // gate proof printed since the drift began belongs to the older code.
913
926
  const disk = checkoutBuild(root);
914
927
  const staleBuild = sessionRunsOlderBuild(loadedVersion(), disk.version);
915
- 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()!] : [])];
928
+ 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 rebinds; restart swaps code`] : []), ...(copyWarning() ? [copyWarning()!] : [])];
916
929
  // the backlog nudge belongs to the no-features answer too — that is when a pick is most useful
917
930
  const rmap = roadmapOpenCount(readRoadmap(root));
918
931
  const rmapLine = rmap ? [`◇ ${rmap} roadmap item(s) open — flow roadmap`] : [];
@@ -1030,7 +1043,7 @@ ${mdDigest(draftRefresh)}`))
1030
1043
  const newest = pub.ok ? pub.out.trim().split("\n").pop() : "";
1031
1044
  return { text: newest ? `${head} — published: ${newest}${self.version && newest !== self.version ? " (update available)" : ""}` : `${head} — could not read the published version (offline?)` };
1032
1045
  }
1033
- return { text: `${behind ? `${head} — but this session runs ${behind}${from}; /reload to run ${self.version}` : head}${dupNote ? `\n${dupNote}` : ""}` };
1046
+ return { text: `${behind ? `${head} — but this session runs ${behind}${from}; /reload to run ${self.version} \u2014 in a shared-process host (pi-web) reload cannot swap loaded code: only a host restart does` : head}${dupNote ? `\n${dupNote}` : ""}` };
1034
1047
  }
1035
1048
 
1036
1049
  case "approve": {
@@ -1784,23 +1797,32 @@ export default function devFlow(pi: ExtensionAPI) {
1784
1797
 
1785
1798
  // Agent-run gates refresh at turn_end (tool ctx lacks setStatus; turn_end catches them).
1786
1799
  pi.on("session_start", async (_event, ctx) => {
1800
+ if (!guardsAreMine()) return;
1787
1801
  rebuildSession(ctx);
1788
1802
  refreshStatus(ctx);
1789
1803
  });
1790
- pi.on("session_tree", async (_event, ctx) => rebuildSession(ctx));
1804
+ pi.on("session_tree", async (_event, ctx) => {
1805
+ if (!guardsAreMine()) return;
1806
+ rebuildSession(ctx);
1807
+ });
1791
1808
  // The session, not the process, owns the binding and the claim: pi-web keeps serving other sessions
1792
1809
  // after one ends, and a stale claim there is a permanent lock (its pid is the server's, always alive).
1793
1810
  pi.on("session_shutdown", async (_event, ctx) => {
1811
+ if (!guardsAreMine()) return;
1794
1812
  if (!existsSync(dfDir(ctx.cwd))) return;
1795
1813
  releaseSession(ctx.cwd, sessionKey(ctx));
1796
1814
  });
1797
1815
  pi.on("turn_end", async (_event, ctx) => {
1816
+ if (!guardsAreMine()) return;
1798
1817
  refreshStatus(ctx);
1799
1818
  // pi checks its compaction threshold between every turn; our safe points must be as frequent.
1800
1819
  maybeCompactNow(ctx);
1801
1820
  });
1802
1821
  // Idle backstop: long between-gate runs compact here instead of letting pi hit the threshold mid-work.
1803
- pi.on("agent_settled", async (_event, ctx) => maybeCompactNow(ctx));
1822
+ pi.on("agent_settled", async (_event, ctx) => {
1823
+ if (!guardsAreMine()) return;
1824
+ maybeCompactNow(ctx);
1825
+ });
1804
1826
  // pi forcing a threshold compaction while a flow is bound means our safe-point pacing missed — rebuild the
1805
1827
  // summary here with flow-aware instructions and hand it back through the event's custom-compaction channel.
1806
1828
  // Never ctx.compact() from this hook: AgentSession.compact() opens with abort() + waitForIdle(), and the run
@@ -1808,6 +1830,7 @@ export default function devFlow(pi: ExtensionAPI) {
1808
1830
  // reaches the provider). If our summary fails we return undefined and pi's own compaction proceeds.
1809
1831
  // overflow is never taken over (cancelling it would drop pi's compact-and-retry); manual is the operator's or ours.
1810
1832
  pi.on("session_before_compact", async (event, ctx) => {
1833
+ if (!guardsAreMine()) return undefined;
1811
1834
  if (!initiated(ctx.cwd)) return undefined;
1812
1835
  const key = sessionKey(ctx);
1813
1836
  const st = boundFeature(ctx.cwd, key);
@@ -1831,6 +1854,7 @@ export default function devFlow(pi: ExtensionAPI) {
1831
1854
  });
1832
1855
  // pi forcing its own compaction while a flow is bound means the pacing was wrong — park a note for the operator.
1833
1856
  pi.on("session_compact", async (event, ctx) => {
1857
+ if (!guardsAreMine()) return;
1834
1858
  if (!initiated(ctx.cwd)) return;
1835
1859
  // Whatever the reason, the summary replaced the transcript — the core the first run injected is
1836
1860
  // gone from context, so the next run pays it once more (manual compactions included: our own
@@ -1849,6 +1873,7 @@ export default function devFlow(pi: ExtensionAPI) {
1849
1873
  });
1850
1874
 
1851
1875
  pi.on("tool_call", async (event, ctx) => {
1876
+ if (!guardsAreMine()) return undefined; // election: only the newest loaded copy judges
1852
1877
  // pi kills a shell call only when a timeout was passed, and the model omits it in ~75% of
1853
1878
  // calls (observed hangs: hours). Deterministic class defaults, clamped ceilings — runs for
1854
1879
  // every session that loads this package, flow-bound or not.
@@ -1977,6 +2002,7 @@ export default function devFlow(pi: ExtensionAPI) {
1977
2002
  });
1978
2003
 
1979
2004
  pi.on("before_agent_start", async (_event, ctx) => {
2005
+ if (!guardsAreMine()) return undefined;
1980
2006
  // One [dev-flow] line per run, whatever number of copies of this package are installed.
1981
2007
  // The same package reaches one runtime twice all the time (a project pin beside the npm install,
1982
2008
  // or this checkout's .pi/extensions pointer beside it) and pi dedupes extensions by file path
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-dev-flow",
3
- "version": "0.61.0",
3
+ "version": "0.61.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": [