pi-dev-flow 0.64.5 → 0.65.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 CHANGED
@@ -4,6 +4,18 @@ Format: newest first. `Unreleased` collects what's merged but not yet tagged.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.65.0] - 2026-10-27
8
+
9
+ ### Added
10
+
11
+ - **Open GitHub issues fold into the reflection review.** `.dev-flow/reflections.md` is gitignored and per-machine, while external reports arrive on GitHub — the two drifted unseen: the same problem could sit in both lists in different words, and nothing stopped it being fixed twice (the dogfood checkout: 4 local reflections, 7 open issues, the one overlap visible only to someone diffing both lists by hand). The fold is a read-time view, never an import — each item keeps exactly one home and is resolved where it lives. With a GitHub remote, `flow doctor` and `flow reflect list` fetch `gh issue list --state open` (10 s timeout, a 5-minute cache per repo, gates and per-turn status lines stay local and offline): a local row an open issue already covers carries `⟷ gh#120` — matched by an explicit `#N` reference, a normalized title, or the `— reflection from …` body tail (backticks and dash kinds can't defeat a match); unmatched issues list below as `gh#N` rows with a route; a near-miss gets `~ gh#121 may duplicate local item 3` and is never auto-merged — the operator decides. The bare `flow reflect` protocol gained the matching rule: open issues count as already filed, an issue filed from a local item ends its body with `— reflection from <slug> <date>` (the fold's match key) and the item checks off `— filed: gh#NNN`. No GitHub remote stays silent; missing or failing `gh` prints one skip line with the reason instead of guessing; `DEV_FLOW_NO_ISSUES=1` is the operator kill switch — and what keeps the tests hermetic (smoke stub a `gh` on PATH, never the network).
12
+
13
+ ## [0.64.6] - 2026-10-26
14
+
15
+ ### Changed
16
+
17
+ - **The changelog writer reviews the branch, not its commit list.** Changelog prose was the one part of the release the agent wrote from nothing but a clause — *update the changelog* — while every real rule was a gate proof (the heading names the version, this branch prepared the entry, folded lines survive verbatim, nothing left under `Unreleased`). Proofs check structure and never granularity, so the entry kept the shape its branch was built from: a change that landed as the fix, its follow-up and the test chasing it read as three near-identical lines — and that entry is also the forge release body, so the noise published verbatim. The pre-release reference now tells the writer to read `git log` *and* `git diff <default>…HEAD` and write the net change in the reader's terms (what was broken, what works now): **one entry per net change, never one per commit**, two lines sharing a subject being the tell to merge them, and work that never reached the reader (reverted mid-branch, dropped on the way, pure moves) getting no line at all. The rule is stated as fold-safe on purpose — the fold proofs guard lines that were already pending under `Unreleased` (another flow's, moved verbatim), never the wording of the entry this flow is writing — and `docs/gates.md` says so where the proofs are documented, so their verbatim discipline is not read as *one line per commit, forever*. `docs/playbook.md` adds the human counterpart: what an entry *is* stays the project's own prose, the gate asks only for the heading and the branch's hand in it. A consistency test locks the clause, the diff step, the one-per-change rule and the fold-safe note into the stage reference.
18
+
7
19
  ## [0.64.5] - 2026-10-25
8
20
 
9
21
  ### Fixed
package/README.md CHANGED
@@ -153,6 +153,14 @@ guess the printed line explains (`flow reflect list` numbers the queue, `flow re
153
153
  --plugin` re-files one). The open count surfaces in
154
154
  `flow status` and in the agent's stage context (`↻ 2 reflection(s) open`).
155
155
 
156
+ With a GitHub remote, `flow doctor` and `flow reflect list` also **fold in the open GitHub issues**
157
+ — external submissions land on GitHub while the queue lives in `reflections.md`, so both surfaces
158
+ show one deduplicated view: a local item an open issue already covers carries `⟷ gh#120`, the rest
159
+ list below as upstream rows, and a near-duplicate is flagged (`~ gh#NNN may duplicate`) but never
160
+ auto-merged. The fold is display-only — upstream items close on GitHub, local items check off in
161
+ the file, never both. No GitHub remote shows nothing; missing or failing `gh` is one skip line, and
162
+ `DEV_FLOW_NO_ISSUES=1` turns the fold off.
163
+
156
164
  They never gate anything, and the fix is never the agent's call alone. You ask it to go through them
157
165
  — usually with `flow doctor`, which reviews each open item and routes it: a playbook item becomes a
158
166
  small docs flow that edits `project.md` through the flow (so the change is committed and reviewed like
package/docs/gates.md CHANGED
@@ -16,7 +16,7 @@ so it needs no `--confirmed`.
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
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
- | `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) |
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 proofs guard the **baseline's** pending lines — they do not freeze the wording of the entry this flow writes, so a branch that landed as several iteration commits is free to state its result as one entry (see the changelog-writer rule in the pre-release reference). The pending baseline is the newest tag's changelog (what actually shipped), else the branch's merge base; when neither resolves, the two git-dependent proofs are skipped **with a printed advisory** rather than refusing a legal release for a topology reason, and the content proofs (the heading, its body) always run; tier-2 `## pre-release` checklist confirmed; the manifest version it validates is **stamped as the release's version of record** (`release-done` publishes that, whatever the checkouts say later); **one question** (Release?) — or `--confirmed`; `--no-version` (your call at Release?) ships this flow as **merge + changelog** — the bump/tag requirements and the tag checks at `release-done` are skipped for it, but the branch must still add its **own line under `Unreleased`** (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, and that warning prints the session vs disk version pair plus the duplicate-copy note when a second copy is registered (#117) |
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` |
22
22
  | `reflect ["<note>"|list|tidy|move <n> --plugin|--playbook]` | — | `reflect "<note>"` queues a suggestion in `reflections.md` (never gates; gate flags such as `--confirmed` are ignored, they never become part of the note). `--playbook` / `--plugin` files it in that section — the agent knows what its own note is about, so the wording guess is the fallback, and the echoed line prints the reason it landed where it did (`"gate" names dev-flow itself`, `playbook or project wording`, `nothing plugin-shaped in the note …`); a note is filed under **one** section, never both. `reflect list` numbers the open items with their section; `reflect move <n> --plugin|--playbook` re-files one of them. `reflect tidy` drops the closed (`- [x]`) items — the preamble and open items stay verbatim and a `## section` heading left empty goes with its items; every surface that queues or reviews reflections (`reflect "<note>"`, bare `reflect`, `doctor`) nudges with the closed count when the checked-off pile grows. Bare `reflect` prints the full **session-reflection protocol** for the agent (from the `/flow reflect` bar it additionally wakes the model, so the protocol executes immediately): review the whole session log, re-check every open item against the current playbook and **newer dev-flow versions** (`npm view pi-dev-flow version` vs the running version — dev-flow ships from npm; recommend `pi install npm:pi-dev-flow` + `/reload`, the operator performs updates), dedupe new findings against the open ones, then report playbook vs plugin items to the operator and ask whether to fix now — plugin items: search upstream issues first (`gh issue list --repo <upstream> --state all --search …`; an author-addressed match is reported back, no match → `gh issue create` with a detailed description and a suggested fix), playbook items: `flow doctor` routes each to the docs flow that implements it |
package/docs/playbook.md CHANGED
@@ -92,7 +92,15 @@ otherwise; confirm the number before tagging” live — the agent sees them at
92
92
  `flow release` / `flow release-done` hard-check the manifest side (bumped past the last tag, then
93
93
  manifest↔tag agreement) and the changelog side (a heading for the version, an entry this branch
94
94
  prepared, and every entry that was pending before the release folded into it — see
95
- [gates.md](gates.md)). `## global` holds
95
+ [gates.md](gates.md)).
96
+ What an entry **is** stays the agent's stage convention, not a gate matter: the changelog records the
97
+ net change of a branch, not its commit history — a feature that landed through several iteration
98
+ commits is one entry telling the final state, and the fold proofs (which guard only lines already
99
+ pending under `Unreleased`) never stand in the way of merging your own lines. Say it differently
100
+ here if your project wants that (per-sprint grouping, issue numbers, a strict Keep-a-Changelog
101
+ vocabulary).
102
+
103
+ `## global` holds
96
104
  `defaultBranch`, `branchPattern`, `worktreeDir`, `mainHook`, `mockupGlobs`, `bashTimeout = require`
97
105
  (default: every shell call must state its own timeout) `| inject`, `release.review`,
98
106
  `release.changelog` (default `CHANGELOG.md`; set it empty to opt out), `release.releases` and `release.artifact = <cmd>` (verify the published artifact — image registry probe etc. — before release-done completes); the implement stage takes `setup`/`test`/`build`/`run`/`seedData`/`health`/
@@ -123,6 +123,7 @@ import {
123
123
  type SessionClaim,
124
124
  } from "../src/core.ts";
125
125
  import { buildDraft, doctorFindings, ghostFeatureDirs, loadProject, mdDigest, parseProjectMd, setPlaybookKey } from "../src/projectmd.ts";
126
+ import { dedupeReflections, linkedTag, parseGhIssues, similarNote, type FoldResult, type GhIssue } from "../src/fold.ts";
126
127
  import { bashTimeout, requireTimeout } from "../src/timeouts.ts";
127
128
  import { detectProject } from "../src/detect.ts";
128
129
 
@@ -205,9 +206,9 @@ const now = () => new Date().toISOString();
205
206
 
206
207
  const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
207
208
 
208
- async function sh(command: string, cwd: string): Promise<{ ok: boolean; out: string }> {
209
+ async function sh(command: string, cwd: string, timeoutMs = 15 * 60_000): Promise<{ ok: boolean; out: string }> {
209
210
  try {
210
- const { stdout, stderr } = await execAsync(command, { cwd, timeout: 15 * 60_000, maxBuffer: 16 * 1024 * 1024 });
211
+ const { stdout, stderr } = await execAsync(command, { cwd, timeout: timeoutMs, maxBuffer: 16 * 1024 * 1024 });
211
212
  return { ok: true, out: `${stdout}\n${stderr}`.trim() };
212
213
  } catch (e) {
213
214
  const err = e as { stdout?: string; stderr?: string; message?: string };
@@ -717,13 +718,69 @@ function reflectNote(root: string, sess: Session, note: string[], forced: Reflec
717
718
  return { text: `reflected (${sections.join(" + ")} — ${why}): ${line}` + (closed ? `\n${reflectionsTidyHint(closed)}` : "") };
718
719
  }
719
720
 
720
- /** `flow reflect list` — the queue numbered, so `move <n>` can address an item (same numbering as `flow roadmap`). */
721
- function reflectList(root: string): RunResult {
721
+ /** In-process TTL cache per repo slug — repeat doctor runs in one session must not re-hit the API. */
722
+ const ghFoldCache = new Map<string, { at: number; issues: GhIssue[] }>();
723
+ const GH_FOLD_TTL_MS = 5 * 60_000;
724
+
725
+ /** Open GitHub issues of the repo's own origin — the channel external parties can file through.
726
+ * Three outcomes, only the third ever speaks: absent (no GitHub remote — not every repo has one,
727
+ * say nothing), skipped (gh missing / unauthenticated / offline / DEV_FLOW_NO_ISSUES — one line
728
+ * with the reason, never a guess), ok (the parsed list). */
729
+ async function fetchUpstream(root: string): Promise<{ slug: string; issues: GhIssue[] } | { skipped: string } | { absent: true }> {
730
+ if (process.env.DEV_FLOW_NO_ISSUES) return { skipped: "disabled (DEV_FLOW_NO_ISSUES)" };
731
+ const origin = await sh("git remote get-url origin", root, 10_000);
732
+ const slug = origin.ok ? githubSlug(origin.out) : "";
733
+ if (!slug) return { absent: true };
734
+ const hit = ghFoldCache.get(slug);
735
+ if (hit && Date.now() - hit.at < GH_FOLD_TTL_MS) return { slug, issues: hit.issues };
736
+ const r = await sh(`gh issue list --repo ${slug} --state open --json number,title,body --limit 100`, root, 10_000);
737
+ if (!r.ok) return { skipped: `gh: ${r.out.split("\n").find(Boolean)?.slice(0, 140) || "failed"}` };
738
+ const parsed = parseGhIssues(r.out);
739
+ if (parsed === null) return { skipped: "unparseable gh output" };
740
+ ghFoldCache.set(slug, { at: Date.now(), issues: parsed });
741
+ return { slug, issues: parsed };
742
+ }
743
+
744
+ type FoldView = { state: "absent" } | { state: "skipped"; why: string } | { state: "ok"; slug: string; result: FoldResult; open: number };
745
+
746
+ async function foldView(root: string, items: ReflectItem[], selfRepo: boolean): Promise<FoldView> {
747
+ const up = await fetchUpstream(root);
748
+ if ("absent" in up) return { state: "absent" };
749
+ if ("skipped" in up) return { state: "skipped", why: up.skipped };
750
+ return { state: "ok", slug: up.slug, result: dedupeReflections(items, up.issues), open: up.issues.length };
751
+ }
752
+
753
+ /** The fold block shared by flow doctor and flow reflect list: header, one row per unmatched
754
+ * issue with its route, then the unmerged near-miss hints. Local rows carry their ⟷ gh#N tag
755
+ * at the call site — the fold lists upstream items, it never re-numbers the local queue. */
756
+ function foldRows(fold: FoldView, selfRepo: boolean): string[] {
757
+ if (fold.state === "absent") return [];
758
+ if (fold.state === "skipped") return [`upstream issues: skipped (${fold.why})`];
759
+ if (!fold.open) return [];
760
+ const rows = [`upstream on ${fold.slug} — ${fold.open} open issue(s) on GitHub (canonical there — close on GitHub, never here; this is a fold, not a copy):`];
761
+ for (const i of fold.result.upstreamOnly) rows.push(` gh#${i.number} ${i.title} → ${selfRepo ? "fix in a flow here (patch flow if small)" : "fix in a flow here, or close won't-fix on GitHub"}`);
762
+ for (const s of fold.result.similar) rows.push(` ${similarNote(s, s.item + 1)}`);
763
+ return rows;
764
+ }
765
+
766
+ /** `flow reflect list` — the queue numbered, so `move <n>` can address an item (same numbering as
767
+ * `flow roadmap`). Upstream items ride below the local queue as gh#N — never numbered, never
768
+ * addressable by move: each item keeps the home it is resolved in. */
769
+ async function reflectList(root: string): Promise<RunResult> {
722
770
  const items = readReflections(root);
723
- if (!items.length) return { text: "reflections: nothing open" };
724
- return {
725
- text: [`reflections — ${items.length} open:`, ...items.map((it, i) => ` ${i + 1}. [${it.section}] ${it.line.replace(/^- \[ \] /, "")}`)].join("\n"),
726
- };
771
+ const fold = await foldView(root, items, isSelfRepo(root));
772
+ const local = items.length
773
+ ? [
774
+ `reflections — ${items.length} open:`,
775
+ ...items.map((it, i) => {
776
+ const link = fold.state === "ok" ? fold.result.linked.find((l) => l.item === i) : undefined;
777
+ return ` ${i + 1}. [${it.section}] ${it.line.replace(/^- \[ \] /, "")}${link ? linkedTag(link.issue) : ""}`;
778
+ }),
779
+ ]
780
+ : fold.state === "absent" || fold.state === "skipped"
781
+ ? ["reflections: nothing open"]
782
+ : ["reflections: nothing open locally"];
783
+ return { text: [...local, ...foldRows(fold, isSelfRepo(root))].join("\n") };
727
784
  }
728
785
 
729
786
  /** `flow reflect move <n> --plugin|--playbook` — re-file an item under the other heading, so fixing a
@@ -1642,13 +1699,22 @@ async function gateReflect(o: GateCtx): Promise<RunResult> {
1642
1699
  : null;
1643
1700
  // single words are verbs (roadmap-style); a note merely starting with one stays a note
1644
1701
  if (words.length === 1 && words[0] === "tidy") return reflectTidy(root);
1645
- if (words.length === 1 && words[0] === "list") return reflectList(root);
1702
+ if (words.length === 1 && words[0] === "list") return await reflectList(root);
1646
1703
  if (words[0] === "move") return reflectMoveNote(root, words.slice(1), forced);
1647
1704
  if (words.length) return reflectNote(root, sess, words, forced);
1648
1705
  // upstream for the update probe: the manifest's repository field; the dev-flow checkout itself falls back to its origin
1649
1706
  const self = pluginVersion(import.meta.dirname);
1650
1707
  const upstream = self.repo || (isSelfRepo(root) ? githubSlug((await sh("git remote get-url origin", root)).out) : "");
1651
- return { text: reflectProtocol(readReflections(root), isSelfRepo(root), { version: self.version, upstream, closed: closedReflectionCount(readReflectionsText(root)) }).join("\n") };
1708
+ const refl = readReflections(root);
1709
+ const fold = await foldView(root, refl, isSelfRepo(root));
1710
+ return {
1711
+ text: reflectProtocol(refl, isSelfRepo(root), {
1712
+ version: self.version,
1713
+ upstream,
1714
+ closed: closedReflectionCount(readReflectionsText(root)),
1715
+ ghFold: fold.state === "ok" && fold.open ? { repo: fold.slug, open: fold.open, similar: fold.result.similar.length } : undefined,
1716
+ }).join("\n"),
1717
+ };
1652
1718
  }
1653
1719
 
1654
1720
  async function gateRoadmap(o: GateCtx): Promise<RunResult> {
@@ -1703,12 +1769,17 @@ async function gateDoctor(o: GateCtx): Promise<RunResult> {
1703
1769
  const findings = doctorFindings(root, loaded.cfg, loaded.md);
1704
1770
  findings.push(...(await gitConsistency(root, loaded.cfg)));
1705
1771
  const refl = readReflections(root);
1772
+ const fold = await foldView(root, refl, isSelfRepo(root));
1706
1773
  if (refl.length) {
1707
1774
  findings.push(`reflection review — ${refl.length} open item(s); doctor never implements: investigate each, present the fix, the operator confirms, then the routed flow implements it:`);
1708
1775
  // labelled from the heading each item sits under — the file is the record, re-guessing from the
1709
1776
  // note text made doctor's table disagree with where the note was actually filed
1710
- for (const r of reflectionRoutes(refl, isSelfRepo(root))) findings.push(` [${r.sections.join("+")}] ${r.text}\n → ${r.route}`);
1777
+ reflectionRoutes(refl, isSelfRepo(root)).forEach((r, i) => {
1778
+ const link = fold.state === "ok" ? fold.result.linked.find((l) => l.item === i) : undefined;
1779
+ findings.push(` [${r.sections.join("+")}] ${r.text}${link ? linkedTag(link.issue) : ""}\n → ${r.route}${link ? ` — already upstream (gh#${link.issue}); check off with — filed: gh#${link.issue} once it lands` : ""}`);
1780
+ });
1711
1781
  }
1782
+ findings.push(...foldRows(fold, isSelfRepo(root)));
1712
1783
  const unfiled = reflectUnfiledCount(readReflectionsText(root));
1713
1784
  if (unfiled) findings.push(` reflections: ${unfiled} open item(s) sit outside ## playbook / ## plugin — flow reflect list shows them, flow reflect move <n> --plugin|--playbook files them`);
1714
1785
  const closedRefl = closedReflectionCount(readReflectionsText(root));
package/package.json CHANGED
@@ -1,62 +1,62 @@
1
1
  {
2
- "name": "pi-dev-flow",
3
- "version": "0.64.5",
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
- "type": "module",
6
- "keywords": [
7
- "pi-package",
8
- "pi",
9
- "pi-coding-agent",
10
- "extension",
11
- "workflow",
12
- "dev-flow",
13
- "spec",
14
- "plan",
15
- "release",
16
- "semver",
17
- "changelog",
18
- "git-worktree",
19
- "guardrails"
20
- ],
21
- "license": "MIT",
22
- "repository": "https://github.com/dmarchevsky/pi-dev-flow",
23
- "engines": {
24
- "node": ">=22.19.0"
25
- },
26
- "files": [
27
- "extensions/",
28
- "src/",
29
- "skills/",
30
- "docs/",
31
- "banner.svg",
32
- "banner.png",
33
- "README.md",
34
- "CHANGELOG.md",
35
- "LICENSE"
36
- ],
37
- "pi": {
38
- "extensions": [
39
- "./extensions/dev-flow.ts"
40
- ],
41
- "skills": [
42
- "./skills"
43
- ],
44
- "image": "./banner.png"
45
- },
46
- "peerDependencies": {
47
- "@earendil-works/pi-ai": "*",
48
- "@earendil-works/pi-coding-agent": "*",
49
- "@earendil-works/pi-tui": "*"
50
- },
51
- "devDependencies": {
52
- "@earendil-works/pi-ai": "*",
53
- "@earendil-works/pi-coding-agent": "*",
54
- "@earendil-works/pi-tui": "*",
55
- "@types/node": "^22.0.0",
56
- "typescript": "^7.0.2"
57
- },
58
- "scripts": {
59
- "build": "tsc --noEmit",
60
- "test": "node --test"
61
- }
2
+ "name": "pi-dev-flow",
3
+ "version": "0.65.0",
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
+ "type": "module",
6
+ "keywords": [
7
+ "pi-package",
8
+ "pi",
9
+ "pi-coding-agent",
10
+ "extension",
11
+ "workflow",
12
+ "dev-flow",
13
+ "spec",
14
+ "plan",
15
+ "release",
16
+ "semver",
17
+ "changelog",
18
+ "git-worktree",
19
+ "guardrails"
20
+ ],
21
+ "license": "MIT",
22
+ "repository": "https://github.com/dmarchevsky/pi-dev-flow",
23
+ "engines": {
24
+ "node": ">=22.19.0"
25
+ },
26
+ "files": [
27
+ "extensions/",
28
+ "src/",
29
+ "skills/",
30
+ "docs/",
31
+ "banner.svg",
32
+ "banner.png",
33
+ "README.md",
34
+ "CHANGELOG.md",
35
+ "LICENSE"
36
+ ],
37
+ "pi": {
38
+ "extensions": [
39
+ "./extensions/dev-flow.ts"
40
+ ],
41
+ "skills": [
42
+ "./skills"
43
+ ],
44
+ "image": "./banner.png"
45
+ },
46
+ "peerDependencies": {
47
+ "@earendil-works/pi-ai": "*",
48
+ "@earendil-works/pi-coding-agent": "*",
49
+ "@earendil-works/pi-tui": "*"
50
+ },
51
+ "devDependencies": {
52
+ "@earendil-works/pi-ai": "*",
53
+ "@earendil-works/pi-coding-agent": "*",
54
+ "@earendil-works/pi-tui": "*",
55
+ "@types/node": "^22.0.0",
56
+ "typescript": "^7.0.2"
57
+ },
58
+ "scripts": {
59
+ "build": "tsc --noEmit",
60
+ "test": "node --test"
61
+ }
62
62
  }
@@ -16,7 +16,19 @@ invent one mid-release. Sequence:
16
16
  2. Update documentation to reflect the change.
17
17
  3. Update the changelog and bump the manifest to the exact version you will
18
18
  tag — manifest, changelog and tag must agree; commit the prep on the feature
19
- branch. A versioned release **folds the `Unreleased` section** (entries
19
+ branch. **The changelog writer reviews the branch, not its commit list**:
20
+ read `git log <default>..HEAD` *and* `git diff <default>…HEAD` first and
21
+ write the entry from the net change the branch delivers, in the reader's
22
+ terms (what was broken, what works now) — this entry is also the forge
23
+ release body, so it publishes verbatim. **One entry per net change, never
24
+ one per commit:** a feature that needed iteration commits (the fix, its
25
+ follow-up, the test that chases it) is **one** line telling the final state;
26
+ two lines sharing a subject are the tell to merge them. Work that never
27
+ reached the reader — reverted mid-branch, dropped on the way, pure moves —
28
+ gets no line. Consolidating your own entry is fold-safe: the fold proofs
29
+ below guard lines that were already pending under `Unreleased` (another
30
+ flow's), which you move verbatim; your own prose is yours until the heading
31
+ ships. A versioned release **folds the `Unreleased` section** (entries
20
32
  `--no-version` flows left there) under the new version heading: the gate
21
33
  refuses while entries remain, refuses a fold that **drops or rewrites** one
22
34
  (move the lines as they are and reword afterwards in a follow-up), and
@@ -46,6 +46,14 @@ and stage context; the operator decides:
46
46
  items off in `.dev-flow/reflections.md` (your queue, gitignored, yours to
47
47
  edit; not `project.md`) with `- [x]` and a `— folded: <what>` or
48
48
  `— fixed: <what>` note.
49
+ - **Open GitHub issues fold into the view** when the repo has a GitHub remote: `flow doctor` and
50
+ `flow reflect list` list them under the local queue (read-time fold — issues are never imported,
51
+ each item keeps one home). A local row an open issue already covers carries `⟷ gh#NNN` — fold it
52
+ by checking the row off `— filed: gh#NNN` and resolving on GitHub. Unmatched upstream rows get a
53
+ route, but their resolution is on GitHub (close there, never in reflections.md). A
54
+ `~ gh#NNN may duplicate` hint is your verdict to make, never an auto-merge. When you file an
55
+ issue for a local item, end its body with `— reflection from <slug> <date>` so future folds
56
+ match it. No GitHub remote = silent; missing/offline `gh` or `DEV_FLOW_NO_ISSUES=1` = one skip line.
49
57
  - `## plugin` items, on the operator's go: search upstream first —
50
58
  `gh issue list --repo <dev-flow repo> --state all --search "<keywords>"` —
51
59
  an issue the author already answered (fixed or won't-fix) is reported back,
package/src/core.ts CHANGED
@@ -1590,7 +1590,7 @@ export function investigationBrief(note: string, selfRepo: boolean): string[] {
1590
1590
  /** Bare `flow reflect`: the full session-reflection protocol for the agent (the plugin has no LLM —
1591
1591
  * the agent reviews the session log, re-checks open items against shipped fixes, dedupes new
1592
1592
  * findings and puts the fix decision to the operator). Writes nothing, runs no network calls. */
1593
- export function reflectProtocol(items: ReflectItem[], selfRepo: boolean, facts: { version: string | null; upstream: string; closed?: number }): string[] {
1593
+ export function reflectProtocol(items: ReflectItem[], selfRepo: boolean, facts: { version: string | null; upstream: string; closed?: number; ghFold?: { repo: string; open: number; similar: number } }): string[] {
1594
1594
  const ver = facts.version ? `dev-flow ${facts.version}` : "dev-flow version unknown";
1595
1595
  const up = facts.upstream || "<upstream — ask the operator for the dev-flow repo>";
1596
1596
  const url = facts.upstream ? `https://github.com/${facts.upstream}` : "<upstream-url>";
@@ -1605,6 +1605,10 @@ export function reflectProtocol(items: ReflectItem[], selfRepo: boolean, facts:
1605
1605
  ` a. plugin items: search upstream first — gh issue list --repo ${up} --state all --search "<keywords>" — an author-addressed match → report the verdict back to the operator (fixed in v… / closed won't-fix + reason), do not re-file; no match → gh issue create --repo ${up} with a detailed description, session evidence and a suggested fix.`,
1606
1606
  " b. playbook items: run flow doctor — it reviews each open item and routes it to the docs flow that implements the fix.",
1607
1607
  ];
1608
+ if (facts.ghFold)
1609
+ lines.push(
1610
+ `upstream fold: ${facts.ghFold.open} open issue(s) on ${facts.ghFold.repo} ride along in flow doctor and flow reflect list — treat them as already filed: never file a finding an open issue covers, resolve upstream items on GitHub (close there, never in reflections.md)${facts.ghFold.similar ? `; ${facts.ghFold.similar} flagged near-duplicate(s) of local items need your verdict before anything is fixed twice` : ""}. When filing an issue for a local item, end the body with '— reflection from <flow-slug> <date>' so future folds match it, then check the item off with '— filed: gh#NNN'.`,
1611
+ );
1608
1612
  if (facts.closed) lines.push(`${reflectionsTidyHint(facts.closed)} — check an item off only when it is handled; tidy once the checked-off pile grows.`);
1609
1613
  if (!items.length) lines.push("open items: none — steps 1 and 3 still apply.");
1610
1614
  else {
package/src/fold.ts ADDED
@@ -0,0 +1,157 @@
1
+ /**
2
+ * The read-time fold between the local reflection queue and open GitHub issues.
3
+ * Pure — no I/O: the extension fetches `gh issue list --json` output and hands it here.
4
+ * A fold merges the VIEW only: a local item lives in reflections.md (checked off there),
5
+ * an upstream item lives on GitHub (closed there). Nothing is copied into the other home,
6
+ * so an item never has two statuses to keep in sync.
7
+ */
8
+
9
+ export interface GhIssue {
10
+ number: number;
11
+ title: string;
12
+ body: string;
13
+ }
14
+
15
+ /** Parse `gh issue list --json number,title,body` output. Junk (gh's own error text, a
16
+ * truncated stream) is null — the caller decides what to report; a clean empty list is []. */
17
+ export function parseGhIssues(out: string): GhIssue[] | null {
18
+ const s = out.trim();
19
+ if (!s.startsWith("[")) return null;
20
+ let raw: unknown;
21
+ try {
22
+ raw = JSON.parse(s);
23
+ } catch {
24
+ return null;
25
+ }
26
+ if (!Array.isArray(raw)) return null;
27
+ const out_: GhIssue[] = [];
28
+ for (const e of raw as Partial<GhIssue>[]) {
29
+ const n = Number(e?.number);
30
+ if (!Number.isInteger(n) || n < 1) continue;
31
+ out_.push({
32
+ number: n,
33
+ title: typeof e?.title === "string" ? e.title : "",
34
+ body: typeof e?.body === "string" ? e.body : "",
35
+ });
36
+ }
37
+ return out_;
38
+ }
39
+
40
+ /** Comparison identity: lowercase, every non-alphanumeric run collapsed to one space —
41
+ * backticks, quotes and the two kinds of dash never decide whether a title matches. */
42
+ export const normKey = (text: string): string => text.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
43
+
44
+ /** The text a filed issue carries before the `— reflection from …` tail the filing convention
45
+ * appends — by convention exactly the reflection's own text, on whichever line it sits. */
46
+ export function issueBodyTails(issue: GhIssue): string[] {
47
+ const keys: string[] = [];
48
+ for (const line of issue.body.split("\n")) {
49
+ const m = /^(.+?)\breflection from\b/i.exec(line.trim().replace(/^#+\s*/, ""));
50
+ if (m) {
51
+ const k = normKey(m[1]);
52
+ if (k) keys.push(k);
53
+ }
54
+ }
55
+ return keys;
56
+ }
57
+
58
+ /** Issue numbers a local item references by hand (`gh#120`, bare `#120`) — the explicit link
59
+ * the agent or operator left when filing or checking off. */
60
+ export function referencedIssues(line: string): number[] {
61
+ const nums: number[] = [];
62
+ for (const m of line.matchAll(/gh#(\d+)|#(\d+)/gi)) {
63
+ const n = Number(m[1] ?? m[2]);
64
+ if (Number.isInteger(n) && n >= 1 && !nums.includes(n)) nums.push(n);
65
+ }
66
+ return nums;
67
+ }
68
+
69
+ const STOPWORDS = new Set(
70
+ "a an and are as at be but by can could do does for from here his her i in into is it its no not of on or our per than that the then there they this to up via we were what when where which who will with would you your".split(
71
+ " ",
72
+ ),
73
+ );
74
+
75
+ /** Content words for the similarity hint: normalized words minus stopwords and strays. */
76
+ export function contentTokens(text: string): Set<string> {
77
+ return new Set(normKey(text).split(" ").filter((w) => w.length > 1 && !STOPWORDS.has(w)));
78
+ }
79
+
80
+ const jaccard = (a: Set<string>, b: Set<string>): number => {
81
+ if (!a.size || !b.size) return 0;
82
+ let inter = 0;
83
+ for (const t of a) if (b.has(t)) inter++;
84
+ return inter / (a.size + b.size - inter);
85
+ };
86
+
87
+ /** A near-miss worth a human glance, never an auto-merge. */
88
+ export interface FoldSimilar {
89
+ item: number;
90
+ issue: number;
91
+ score: number;
92
+ }
93
+ export interface FoldLink {
94
+ item: number;
95
+ issue: number;
96
+ via: "ref" | "title" | "body";
97
+ }
98
+ export interface FoldResult {
99
+ /** Exact matches, in local-item order: the queue row carries `⟷ gh#N` instead of duplicating. */
100
+ linked: FoldLink[];
101
+ /** Token-similarity hints over the UNLINKED pairs — advisory, the operator decides. */
102
+ similar: FoldSimilar[];
103
+ /** Issues nothing matched, ascending — these render as upstream rows. */
104
+ upstreamOnly: GhIssue[];
105
+ }
106
+
107
+ export interface FoldItemInput {
108
+ body: string;
109
+ line: string;
110
+ }
111
+
112
+ /** Minimum content words per side before a Jaccard score is trusted as a hint. */
113
+ const SIM_MIN_TOKENS = 5;
114
+ const SIM_THRESHOLD = 0.6;
115
+
116
+ /** Match the open local items against open GitHub issues: explicit `#N` references first, then
117
+ * exact normalized equality against the issue title, then against the body's `reflection from`
118
+ * tail. One link per item and per issue (first exact hit wins, local order decides). */
119
+ export function dedupeReflections(items: FoldItemInput[], issues: GhIssue[]): FoldResult {
120
+ const byNumAsc = [...issues].sort((a, b) => a.number - b.number);
121
+ const byNum = new Map(byNumAsc.map((i) => [i.number, i]));
122
+ const used = new Set<number>();
123
+ const linked: FoldLink[] = [];
124
+ const linkedItems = new Set<number>();
125
+ items.forEach((it, idx) => {
126
+ const free = (i: GhIssue) => !used.has(i.number);
127
+ const nk = normKey(it.body);
128
+ const ref = referencedIssues(it.line).find((n) => byNum.has(n) && free(byNum.get(n)!));
129
+ const title = nk && byNumAsc.find((i) => free(i) && normKey(i.title) === nk);
130
+ const body = nk && byNumAsc.find((i) => free(i) && issueBodyTails(i).includes(nk));
131
+ const hit = ref !== undefined ? { issue: byNum.get(ref)!, via: "ref" as const } : title ? { issue: title, via: "title" as const } : body ? { issue: body, via: "body" as const } : null;
132
+ if (!hit) return;
133
+ used.add(hit.issue.number);
134
+ linkedItems.add(idx);
135
+ linked.push({ item: idx, issue: hit.issue.number, via: hit.via });
136
+ });
137
+ const similar: FoldSimilar[] = [];
138
+ items.forEach((it, idx) => {
139
+ if (linkedItems.has(idx)) return;
140
+ const itTok = contentTokens(it.body);
141
+ if (itTok.size < SIM_MIN_TOKENS) return;
142
+ for (const i of byNumAsc) {
143
+ if (used.has(i.number)) continue;
144
+ const score = jaccard(itTok, contentTokens(i.title));
145
+ if (score >= SIM_THRESHOLD) similar.push({ item: idx, issue: i.number, score });
146
+ }
147
+ });
148
+ similar.sort((a, b) => b.score - a.score || a.issue - b.issue);
149
+ return { linked, similar, upstreamOnly: byNumAsc.filter((i) => !used.has(i.number)) };
150
+ }
151
+
152
+ /** The tag a linked local row carries. */
153
+ export const linkedTag = (issue: number) => ` ⟷ gh#${issue}`;
154
+
155
+ /** One similarity hint line — an unmerged near-miss the operator has to judge. */
156
+ export const similarNote = (s: FoldSimilar, itemNumber: number) =>
157
+ `~ gh#${s.issue} may duplicate local item ${itemNumber} (${Math.round(s.score * 100)}% similar) — verify before fixing the same thing twice`;