pi-dev-flow 0.95.0 → 0.95.2

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,25 @@ Format: newest first. `Unreleased` collects what's merged but not yet tagged.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.95.2] - 2026-11-20
8
+
9
+ **`flow release` stops waiting on a check that GitHub left stuck at "in progress" after its job finished.**
10
+
11
+ ### Fixed
12
+ - **`flow release` no longer waits on a check that GitHub left stuck at "in progress" (gh#275).** Sometimes a check run on the PR keeps saying `in_progress` after its Actions job has finished. In one case the gate spent three 30-minute waits on `actionlint` this way. Now, when a check has been pending for 5 minutes, the gate asks GitHub for the job's own result (`gh api …/actions/jobs/<id>`). If the job has finished, the gate uses that result, so a pass counts as green and a failure counts as red, and the release note names the stale check. A wait that still runs out of time now also says how to clear a stale check: push a new commit to the branch.
13
+
14
+ ## [0.95.1] - 2026-11-20
15
+
16
+ **`flow release` waits for the merge commit's CI to go green before it cuts the tag; `tagWait = none` opts out.**
17
+
18
+ ### Fixed
19
+ - **`flow release` tags only once the merge commit's CI is green (gh#271).** The gate merged, then cut and pushed the tag in the same call. A playbook rule like "test green on the merge commit before the tag" could therefore never be met, and the checklist printed it as open next to "tag pushed". The gate now waits for the CI that the merge commit started.
20
+ - Green, or no CI on that commit after a minute: it tags.
21
+ - Still running: it reports `publish waiting`, and a re-run resumes at the tag step.
22
+ - Red: it stops with the PR merged and no tag, and says what to do: re-run a flaky job, or fix forward and tag on the operator's word.
23
+
24
+ `tagWait = none` under `## release` keeps the old behavior, for a project whose tag publishes nothing.
25
+
7
26
  ## [0.95.0] - 2026-11-20
8
27
 
9
28
  **Reflections are tied to the flow that fixes them: `flow start --reflections` links rows and `finish` closes them, rows have ids that never change, `tidy` archives and `reopen` undoes, repeats count on their row, evidence is kept, and `flow reflect plan` groups the open rows into flows. Also: a long reflection keeps what it found when it runs out of time, `flow release` checks for merge conflicts before waiting on CI, a fresh clone no longer blocks `finish`, and a docs flow that edits code runs the checks.**
package/docs/gates.md CHANGED
@@ -162,10 +162,14 @@ On GitHub, the same `flow release` call then publishes. Your Release? answer is
162
162
  wrote one, else the changelog entry. If the repo has a pull-request template
163
163
  (`.github/pull_request_template.md`), the gate refuses until `pr-body.md` exists, before
164
164
  Release? is asked, so the template's sections are filled before the merge.
165
- 2. Waits for the PR's CI, up to 30 minutes. A repo with no CI is given a minute for checks to show up.
166
- 3. Merges in the playbook's `merge` style.
167
- 4. Creates an annotated tag on the PR's merge commit and pushes it (versioned flows).
168
- 5. Records the release (below).
165
+ 2. Checks the branch merges cleanly into the default branch. On a conflict it names the files and pushes nothing.
166
+ 3. Waits for the PR's CI, up to 30 minutes. A repo with no CI is given a minute for checks to show up. A check pending for 5 minutes has its Actions job asked directly: GitHub can leave a check run `in_progress` after its job finished, and the job's result is used then.
167
+ 4. Merges in the playbook's `merge` style.
168
+ 5. Waits for the merge commit's own CI to go green, because the tag publishes from that commit. If it's red, the
169
+ gate stops without tagging. If no CI runs on that commit, it tags after a minute. `tagWait = none` under
170
+ `## release` skips this wait.
171
+ 6. Creates an annotated tag on the PR's merge commit and pushes it (versioned flows).
172
+ 7. Records the release (below).
169
173
 
170
174
  Each step first asks GitHub whether it's already done, so a re-run picks up where it stopped, and a
171
175
  step you did by hand (merging a PR that needed your review, for example) is accepted. The gate stops
package/docs/playbook.md CHANGED
@@ -175,6 +175,7 @@ These go under `## pre-release` or `## release`. Either section works.
175
175
  | `ask` | `on-change` | `on-change`: Release? answers itself when only release prep changed. `always`: ask every time. |
176
176
  | `finish` | `on-change` | `on-change`: Finish? answers itself when nothing is open (see [gates](gates.md#finish-finish)). `always`: ask every time. |
177
177
  | `publish` | `gate` | `gate`: on GitHub, `flow release` pushes, opens the PR, waits for CI, merges and tags itself. `manual`: the agent runs those steps. Other forges are always manual. |
178
+ | `tagWait` | `ci` | `ci`: the gate cuts the tag only once the merge commit's CI is green. The tag publishes from that commit, so a red build is never released. `none`: tag right after the merge. |
178
179
  | `recheck` | `prep-skip` | `prep-skip`: checks stay green across a commit that holds only the version bump and changelog. `always`: re-run them. |
179
180
  | `yolo` | `all` | `until-release`: a yolo given earlier never answers Release?. The gate asks, and only your answer to that question releases. |
180
181
  | `reflect` | `on-friction` | `always`: run the closing reflection on every finish |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-dev-flow",
3
- "version": "0.95.0",
3
+ "version": "0.95.2",
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": [
@@ -10,8 +10,9 @@ gate's stage line, **🚀 release · `<slug>`**; no `Done:` / `Next steps:` bloc
10
10
 
11
11
  `flow release` does the whole stage in the same call that passed Release?: it
12
12
  pushes the branch, opens the PR (changelog entry as body), waits for the PR's
13
- CI, merges in the playbook's style, cuts and pushes the annotated tag on the
14
- merge commit, then records the release (tag on origin, artifact, forge release
13
+ CI, merges in the playbook's style, waits for the merge commit's own CI to go
14
+ green, cuts and pushes the annotated tag on the merge commit, then records the
15
+ release (tag on origin, artifact, forge release
15
16
  created from the changelog entry and read back). You run no git or `gh` step.
16
17
 
17
18
  It stops with one of two results, and **re-running `flow release` resumes** —
package/src/core.ts CHANGED
@@ -155,7 +155,7 @@ export interface Config {
155
155
  /** Bytes one dev instance needs (playbook `instanceMem` / `instanceDisk`, e.g. 2G) — the side-by-side feasibility check. */
156
156
  instanceMem?: number;
157
157
  instanceDisk?: number;
158
- release: { review: string; changelog?: string; releases?: boolean; artifact?: string; preflight?: string; merge?: MergeStyle | "any"; /** `until-release`: a standing yolo never answers Release? (gh#176) */ yolo?: "all" | "until-release"; /** `always`: finish runs the closing reflection even on a flow with no friction */ reflect?: "always" | "on-friction"; /** who decides versioned vs unreleased: asked with Verified? (`ask`, default) or fixed by the playbook (gh#198) */ version?: "ask" | "versioned" | "unversioned"; /** `on-change` (default): Release? answers itself when nothing but release prep changed since Verified? and the version choice is on record; `always` asks it every time (gh#198) */ ask?: "always" | "on-change"; /** `prep-skip` (default): green checks survive a commit that touches only release-prep files; `always` re-runs them */ recheck?: "always" | "prep-skip"; /** `on-change` (default): Finish? answers itself on a clean flow (quiet reflection, no open release items, nothing skipped); `always` asks it every time */ finish?: "always" | "on-change"; /** `gate` (default): on GitHub `flow release` pushes, opens the PR, waits for CI, merges and tags itself; `manual`: the agent runs those steps */ publish?: "gate" | "manual" };
158
+ release: { review: string; changelog?: string; releases?: boolean; artifact?: string; preflight?: string; merge?: MergeStyle | "any"; /** `until-release`: a standing yolo never answers Release? (gh#176) */ yolo?: "all" | "until-release"; /** `always`: finish runs the closing reflection even on a flow with no friction */ reflect?: "always" | "on-friction"; /** who decides versioned vs unreleased: asked with Verified? (`ask`, default) or fixed by the playbook (gh#198) */ version?: "ask" | "versioned" | "unversioned"; /** `on-change` (default): Release? answers itself when nothing but release prep changed since Verified? and the version choice is on record; `always` asks it every time (gh#198) */ ask?: "always" | "on-change"; /** `prep-skip` (default): green checks survive a commit that touches only release-prep files; `always` re-runs them */ recheck?: "always" | "prep-skip"; /** `on-change` (default): Finish? answers itself on a clean flow (quiet reflection, no open release items, nothing skipped); `always` asks it every time */ finish?: "always" | "on-change"; /** `gate` (default): on GitHub `flow release` pushes, opens the PR, waits for CI, merges and tags itself; `manual`: the agent runs those steps */ publish?: "gate" | "manual"; /** `ci` (default): the gate tags only once the merge commit's CI is green — a tag publishes from it (gh#271); `none`: tag right after the merge */ tagWait?: "ci" | "none" };
159
159
  mainHook: boolean; // flow init installs a pre-commit hook blocking main commits
160
160
  /** `inject` (default): the class default timeout is armed silently on every shell call.
161
161
  * `require`: a shell call without its own visible timeout is refused (costs a turn per miss). */
package/src/projectmd.ts CHANGED
@@ -73,6 +73,7 @@ const KEYMAP: Record<string, Record<string, string>> = {
73
73
  finish: "release.finish", // when Finish? is asked: on-change (default, a clean flow closes itself) | always
74
74
  publish: "release.publish", // who runs push, PR, merge and tag after Release?: gate (default on GitHub) | manual
75
75
  recheck: "release.recheck", // checks after a release-prep-only commit: prep-skip (default, keep the green records) | always
76
+ tagWait: "release.tagWait", // before the gate tags: ci (default — the merge commit's CI must be green) | none (gh#271)
76
77
  },
77
78
  };
78
79
  // pre-release owns release preparation; the release keys are accepted under both sections so
@@ -207,6 +208,10 @@ export function parseProjectMd(text: string): ParsedMd {
207
208
  p.warn.push(`${where}: publish = "${m[2]}" — expected gate or manual, keeping gate`);
208
209
  return;
209
210
  }
211
+ if (mapped === "release.tagWait" && !/^(ci|none)$/.test(m[2].trim())) {
212
+ p.warn.push(`${where}: tagWait = "${m[2]}" — expected ci or none, keeping ci`);
213
+ return;
214
+ }
210
215
  if (mapped === "release.recheck" && !/^(always|prep-skip)$/.test(m[2].trim())) {
211
216
  p.warn.push(`${where}: recheck = "${m[2]}" — expected prep-skip or always, keeping prep-skip`);
212
217
  return;
@@ -17,8 +17,36 @@ export const publishWait = {
17
17
  sleep: (ms: number) => new Promise<void>((r) => setTimeout(r, ms)),
18
18
  clock: () => Date.now(),
19
19
  checks: (pr: number, cwd: string): Promise<PrCheck[] | null> => prChecks(pr, cwd),
20
+ /** the CI runs a commit started — the merge commit, before it is tagged (gh#271) */
21
+ commitChecks: (sha: string, cwd: string): Promise<PrCheck[] | null> => commitRuns(sha, cwd),
22
+ /** gh#275: a check pending this long has its Actions job asked directly — GitHub can leave a check run
23
+ * `in_progress` for good after its job concluded */
24
+ staleMs: 5 * 60_000,
25
+ /** the bucket of the Actions job or run behind a check's link once it has concluded; null while it runs or when
26
+ * the link is not an Actions one */
27
+ probe: (link: string, cwd: string): Promise<string | null> => actionsConclusion(link, cwd),
20
28
  };
21
29
 
30
+ /** gh#275: the Actions job (or run) a check links to — its own conclusion, which GitHub sets even when the check
31
+ * run shown on the PR is stuck at in_progress. */
32
+ async function actionsConclusion(link: string, cwd: string): Promise<string | null> {
33
+ const m = /github\.com\/([^/]+)\/([^/]+)\/actions\/runs\/(\d+)(?:\/job\/(\d+))?/.exec(link);
34
+ if (!m) return null;
35
+ const api = m[4] ? `repos/${m[1]}/${m[2]}/actions/jobs/${m[4]}` : `repos/${m[1]}/${m[2]}/actions/runs/${m[3]}`;
36
+ const r = await sh(`gh api ${sq(api)} --jq '.conclusion // ""'`, cwd, 60_000);
37
+ const k = r.ok ? r.out.trim() : "";
38
+ return /^[a-z_]+$/.test(k) ? checkBucket({ status: "COMPLETED", conclusion: k.toUpperCase() }) : null;
39
+ }
40
+
41
+ /** Workflow runs of one commit as checks; [] when none started, null when gh cannot say. */
42
+ async function commitRuns(sha: string, cwd: string): Promise<PrCheck[] | null> {
43
+ const r = await sh(`gh run list --commit ${sha} --limit 50 --json status,conclusion,name,url`, cwd, 60_000);
44
+ if (!r.ok) return null;
45
+ const rows = jsonArray<{ status?: string; conclusion?: string; name?: string; url?: string }>(r.out);
46
+ if (rows === null) return r.out.trim() ? null : [];
47
+ return rows.map((x) => ({ name: x.name ?? "run", bucket: checkBucket({ status: (x.status ?? "").toUpperCase(), conclusion: (x.conclusion ?? "").toUpperCase() }), link: x.url ?? "" }));
48
+ }
49
+
22
50
  export interface PrCheck { name: string; bucket: string; link: string }
23
51
  interface Pr { number: number; state: string; url: string; headRefOid: string; mergeCommit: { oid: string } | null }
24
52
 
@@ -70,21 +98,58 @@ async function prChecks(pr: number, cwd: string): Promise<PrCheck[] | null> {
70
98
  export type CiVerdict = { state: "green" | "none"; note: string } | { state: "red" | "running" | "unknown"; why: string };
71
99
 
72
100
  /** Wait (bounded) for the PR's checks to settle. */
73
- export async function awaitPrChecks(pr: number, cwd: string): Promise<CiVerdict> {
101
+ export const awaitPrChecks = (pr: number, cwd: string): Promise<CiVerdict> =>
102
+ awaitChecks(() => publishWait.checks(pr, cwd), cwd, {
103
+ who: `PR #${pr}`,
104
+ read: `gh pr view ${pr} --json statusCheckRollup`,
105
+ none: "no CI checks on the PR",
106
+ green: "CI green",
107
+ stuck: "a check whose job already finished on GitHub but still shows in_progress is a stale check run: pushing a new commit to the branch clears it",
108
+ });
109
+
110
+ /** gh#271: wait (bounded) for the CI the merge commit started — a tag publishes from it, so it is cut on green only. */
111
+ export const awaitCommitChecks = (sha: string, cwd: string): Promise<CiVerdict> =>
112
+ awaitChecks(() => publishWait.commitChecks(sha, cwd), cwd, { who: `merge commit ${sha.slice(0, 9)}`, read: `gh run list --commit ${sha}`, none: "no CI ran on the merge commit", green: "merge-commit CI green" });
113
+
114
+ async function awaitChecks(read: () => Promise<PrCheck[] | null>, cwd: string, l: { who: string; read: string; none: string; green: string; stuck?: string }): Promise<CiVerdict> {
74
115
  const start = publishWait.clock();
75
116
  const mins = () => `${Math.max(1, Math.round((publishWait.clock() - start) / 60_000))} min`;
117
+ // gh#275: when each check was first seen pending, and what its job concluded once asked — a check run GitHub left
118
+ // at in_progress after its job finished burned three 30-min waits; it is taken at its job's word instead
119
+ const since = new Map<string, number>();
120
+ const settled = new Map<string, string>();
121
+ const stale: string[] = [];
76
122
  for (;;) {
77
- const rows = await publishWait.checks(pr, cwd);
123
+ const raw = await read();
78
124
  const elapsed = publishWait.clock() - start;
79
- if (rows === null) return { state: "unknown", why: `cannot read the checks of PR #${pr} (gh pr view ${pr} --json statusCheckRollup)` };
125
+ const rows = raw?.map((c) => {
126
+ if (c.bucket !== "pending") return c;
127
+ const key = `${c.name}\u0000${c.link}`;
128
+ const b = settled.get(key);
129
+ return b ? { ...c, bucket: b } : c;
130
+ }) ?? null;
131
+ for (const c of rows ?? []) {
132
+ if (c.bucket !== "pending" || !c.link) continue;
133
+ const key = `${c.name}\u0000${c.link}`;
134
+ const first = since.get(key) ?? elapsed;
135
+ since.set(key, first);
136
+ if (elapsed - first < publishWait.staleMs) continue;
137
+ const b = await publishWait.probe(c.link, cwd);
138
+ if (!b || b === "pending") continue;
139
+ settled.set(key, b);
140
+ stale.push(`${c.name}: its job concluded ${b} while the check still said in_progress`);
141
+ c.bucket = b;
142
+ }
143
+ const staleNote = stale.length ? `; ${stale.join(", ")}` : "";
144
+ if (rows === null) return { state: "unknown", why: `cannot read the checks of ${l.who} (${l.read})` };
80
145
  if (!rows.length) {
81
- if (elapsed >= publishWait.appearMs) return { state: "none", note: "no CI checks on the PR" };
146
+ if (elapsed >= publishWait.appearMs) return { state: "none", note: l.none };
82
147
  } else {
83
148
  const failed = rows.filter((c) => c.bucket === "fail" || c.bucket === "cancel");
84
- if (failed.length) return { state: "red", why: `PR #${pr} checks failed — ${failed.map((c) => `${c.name}: ${c.bucket}${c.link ? ` (${c.link})` : ""}`).join(", ")}` };
149
+ if (failed.length) return { state: "red", why: `${l.who} checks failed — ${failed.map((c) => `${c.name}: ${c.bucket}${c.link ? ` (${c.link})` : ""}`).join(", ")}${staleNote}` };
85
150
  const pending = rows.filter((c) => c.bucket !== "pass" && c.bucket !== "skipping");
86
- if (!pending.length) return { state: "green", note: `CI green (${rows.length} check${rows.length === 1 ? "" : "s"}${elapsed >= 60_000 ? `, waited ${mins()}` : ""})` };
87
- if (elapsed >= publishWait.budgetMs) return { state: "running", why: `PR #${pr} checks still running after ${mins()} (${pending.map((c) => c.name).join(", ")})` };
151
+ if (!pending.length) return { state: "green", note: `${l.green} (${rows.length} check${rows.length === 1 ? "" : "s"}${elapsed >= 60_000 ? `, waited ${mins()}` : ""}${staleNote})` };
152
+ if (elapsed >= publishWait.budgetMs) return { state: "running", why: `${l.who} checks still running after ${mins()} (${pending.map((c) => c.name).join(", ")})${l.stuck ? ` — ${l.stuck}` : ""}` };
88
153
  }
89
154
  await publishWait.sleep(publishWait.pollMs);
90
155
  }
@@ -256,6 +321,16 @@ export async function publishRelease(root: string, state: FlowState, cfg: Config
256
321
  if (tags === null) return stop("cannot list tags on origin", "check the network and git credentials");
257
322
  if (tags.includes(tag)) steps.push(`tag ${tag} already on origin`);
258
323
  else {
324
+ // gh#271: the tag publishes from the merge commit — wait for that commit's own CI before cutting it, so a
325
+ // playbook rule "test green on the merge commit before the tag" is something this gate can honour
326
+ if (oid && cfg.release.tagWait !== "none") {
327
+ const ci = await awaitCommitChecks(oid, root);
328
+ if (!("why" in ci)) steps.push(ci.note);
329
+ else if (ci.state === "running") return { ok: false, text: `publish waiting — ${ci.why}; the tag waits for it${steps.length ? `\ndone so far: ${steps.join(" · ")}` : ""}\n↪ next: re-run flow release to keep waiting — do not end the turn on a promise to watch` };
330
+ else if (ci.state === "red")
331
+ return stop(`${ci.why} — merged, but the tag was not cut: it would publish a red build`, `tell the operator. A flaky job: re-run it (gh run rerun --failed <run>), then re-run flow release, which tags on green. A real failure is fixed forward in a new flow, and the tag goes on the fix by the operator's word (or tagWait = none under ## release for a project whose tag publishes nothing)`);
332
+ else return stop(ci.why, "check gh auth status, or tag the merge commit yourself once its CI is green");
333
+ }
259
334
  if (!oid) return stop(`PR #${merged.number} shows no merge commit to tag`, `tag what shipped yourself (git tag -a ${tag}) and push it`);
260
335
  if (!(await sh(`git cat-file -e ${sq(`${oid}^{commit}`)}`, root)).ok) return stop(`the merge commit ${oid.slice(0, 9)} of PR #${merged.number} is not in this clone after a fetch`, `git fetch origin ${cfg.defaultBranch}`);
261
336
  if (!(await sh(`git rev-parse -q --verify ${sq(`refs/tags/${tag}`)}`, root)).ok) {