flow-workflows 0.114.0 → 0.116.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.
Files changed (122) hide show
  1. package/README.md +10 -4
  2. package/adapters/codex/CORE.md +224 -135
  3. package/adapters/codex/skills/flow-bug-fix/SKILL.md +2 -2
  4. package/adapters/codex/skills/flow-bug-investigate/SKILL.md +1 -1
  5. package/adapters/codex/skills/flow-bug-postmortem/SKILL.md +1 -1
  6. package/adapters/codex/skills/flow-bug-review/SKILL.md +1 -1
  7. package/adapters/codex/skills/flow-bug-ship/SKILL.md +2 -2
  8. package/adapters/codex/skills/flow-bug-start/SKILL.md +1 -1
  9. package/adapters/codex/skills/flow-bug-validate/SKILL.md +1 -1
  10. package/adapters/codex/skills/flow-doctor/SKILL.md +1 -1
  11. package/adapters/codex/skills/flow-feat-build/SKILL.md +3 -3
  12. package/adapters/codex/skills/flow-feat-design/SKILL.md +1 -1
  13. package/adapters/codex/skills/flow-feat-plan/SKILL.md +1 -1
  14. package/adapters/codex/skills/flow-feat-review/SKILL.md +1 -1
  15. package/adapters/codex/skills/flow-feat-ship/SKILL.md +3 -3
  16. package/adapters/codex/skills/flow-feat-start/SKILL.md +2 -2
  17. package/adapters/codex/skills/flow-feat-validate/SKILL.md +1 -1
  18. package/adapters/codex/skills/flow-next/SKILL.md +1 -1
  19. package/adapters/codex/skills/flow-work-README/SKILL.md +8 -8
  20. package/adapters/codex/skills/flow-work-abandon/SKILL.md +2 -2
  21. package/adapters/codex/skills/flow-work-clean/SKILL.md +1 -1
  22. package/adapters/codex/skills/flow-work-daily/SKILL.md +3 -3
  23. package/adapters/codex/skills/flow-work-green/SKILL.md +1 -1
  24. package/adapters/codex/skills/flow-work-handoff/SKILL.md +5 -4
  25. package/adapters/codex/skills/flow-work-query/SKILL.md +1 -1
  26. package/adapters/codex/skills/flow-work-respond/SKILL.md +1 -1
  27. package/adapters/codex/skills/flow-work-resume/SKILL.md +9 -25
  28. package/adapters/codex/skills/flow-work-run/SKILL.md +1 -1
  29. package/adapters/codex/skills/flow-work-try/SKILL.md +1 -1
  30. package/adapters/codex/skills/flow-work-watch/SKILL.md +1 -1
  31. package/adapters/gemini/CORE.md +224 -135
  32. package/adapters/gemini/commands/flow/bug/fix.toml +2 -2
  33. package/adapters/gemini/commands/flow/bug/investigate.toml +1 -1
  34. package/adapters/gemini/commands/flow/bug/postmortem.toml +1 -1
  35. package/adapters/gemini/commands/flow/bug/review.toml +1 -1
  36. package/adapters/gemini/commands/flow/bug/ship.toml +2 -2
  37. package/adapters/gemini/commands/flow/bug/start.toml +1 -1
  38. package/adapters/gemini/commands/flow/bug/validate.toml +1 -1
  39. package/adapters/gemini/commands/flow/doctor.toml +1 -1
  40. package/adapters/gemini/commands/flow/feat/build.toml +3 -3
  41. package/adapters/gemini/commands/flow/feat/design.toml +1 -1
  42. package/adapters/gemini/commands/flow/feat/plan.toml +1 -1
  43. package/adapters/gemini/commands/flow/feat/review.toml +1 -1
  44. package/adapters/gemini/commands/flow/feat/ship.toml +3 -3
  45. package/adapters/gemini/commands/flow/feat/start.toml +2 -2
  46. package/adapters/gemini/commands/flow/feat/validate.toml +1 -1
  47. package/adapters/gemini/commands/flow/next.toml +1 -1
  48. package/adapters/gemini/commands/flow/work/README.toml +8 -8
  49. package/adapters/gemini/commands/flow/work/abandon.toml +2 -2
  50. package/adapters/gemini/commands/flow/work/clean.toml +1 -1
  51. package/adapters/gemini/commands/flow/work/daily.toml +3 -3
  52. package/adapters/gemini/commands/flow/work/green.toml +1 -1
  53. package/adapters/gemini/commands/flow/work/handoff.toml +5 -4
  54. package/adapters/gemini/commands/flow/work/query.toml +1 -1
  55. package/adapters/gemini/commands/flow/work/respond.toml +1 -1
  56. package/adapters/gemini/commands/flow/work/resume.toml +9 -25
  57. package/adapters/gemini/commands/flow/work/run.toml +1 -1
  58. package/adapters/gemini/commands/flow/work/try.toml +1 -1
  59. package/adapters/gemini/commands/flow/work/watch.toml +1 -1
  60. package/adapters/hermes/CORE.md +224 -135
  61. package/adapters/hermes/skills/flow-bug-fix/SKILL.md +2 -2
  62. package/adapters/hermes/skills/flow-bug-investigate/SKILL.md +1 -1
  63. package/adapters/hermes/skills/flow-bug-postmortem/SKILL.md +1 -1
  64. package/adapters/hermes/skills/flow-bug-review/SKILL.md +1 -1
  65. package/adapters/hermes/skills/flow-bug-ship/SKILL.md +2 -2
  66. package/adapters/hermes/skills/flow-bug-start/SKILL.md +1 -1
  67. package/adapters/hermes/skills/flow-bug-validate/SKILL.md +1 -1
  68. package/adapters/hermes/skills/flow-doctor/SKILL.md +1 -1
  69. package/adapters/hermes/skills/flow-feat-build/SKILL.md +3 -3
  70. package/adapters/hermes/skills/flow-feat-design/SKILL.md +1 -1
  71. package/adapters/hermes/skills/flow-feat-plan/SKILL.md +1 -1
  72. package/adapters/hermes/skills/flow-feat-review/SKILL.md +1 -1
  73. package/adapters/hermes/skills/flow-feat-ship/SKILL.md +3 -3
  74. package/adapters/hermes/skills/flow-feat-start/SKILL.md +2 -2
  75. package/adapters/hermes/skills/flow-feat-validate/SKILL.md +1 -1
  76. package/adapters/hermes/skills/flow-next/SKILL.md +1 -1
  77. package/adapters/hermes/skills/flow-work-README/SKILL.md +8 -8
  78. package/adapters/hermes/skills/flow-work-abandon/SKILL.md +2 -2
  79. package/adapters/hermes/skills/flow-work-clean/SKILL.md +1 -1
  80. package/adapters/hermes/skills/flow-work-daily/SKILL.md +3 -3
  81. package/adapters/hermes/skills/flow-work-green/SKILL.md +1 -1
  82. package/adapters/hermes/skills/flow-work-handoff/SKILL.md +5 -4
  83. package/adapters/hermes/skills/flow-work-query/SKILL.md +1 -1
  84. package/adapters/hermes/skills/flow-work-respond/SKILL.md +1 -1
  85. package/adapters/hermes/skills/flow-work-resume/SKILL.md +9 -25
  86. package/adapters/hermes/skills/flow-work-run/SKILL.md +1 -1
  87. package/adapters/hermes/skills/flow-work-try/SKILL.md +1 -1
  88. package/adapters/hermes/skills/flow-work-watch/SKILL.md +1 -1
  89. package/adapters/opencode/CORE.md +224 -135
  90. package/adapters/opencode/commands/flow-bug-fix.md +2 -2
  91. package/adapters/opencode/commands/flow-bug-investigate.md +1 -1
  92. package/adapters/opencode/commands/flow-bug-postmortem.md +1 -1
  93. package/adapters/opencode/commands/flow-bug-review.md +1 -1
  94. package/adapters/opencode/commands/flow-bug-ship.md +2 -2
  95. package/adapters/opencode/commands/flow-bug-start.md +1 -1
  96. package/adapters/opencode/commands/flow-bug-validate.md +1 -1
  97. package/adapters/opencode/commands/flow-doctor.md +1 -1
  98. package/adapters/opencode/commands/flow-feat-build.md +3 -3
  99. package/adapters/opencode/commands/flow-feat-design.md +1 -1
  100. package/adapters/opencode/commands/flow-feat-plan.md +1 -1
  101. package/adapters/opencode/commands/flow-feat-review.md +1 -1
  102. package/adapters/opencode/commands/flow-feat-ship.md +3 -3
  103. package/adapters/opencode/commands/flow-feat-start.md +2 -2
  104. package/adapters/opencode/commands/flow-feat-validate.md +1 -1
  105. package/adapters/opencode/commands/flow-next.md +1 -1
  106. package/adapters/opencode/commands/flow-work-README.md +8 -8
  107. package/adapters/opencode/commands/flow-work-abandon.md +2 -2
  108. package/adapters/opencode/commands/flow-work-clean.md +1 -1
  109. package/adapters/opencode/commands/flow-work-daily.md +3 -3
  110. package/adapters/opencode/commands/flow-work-green.md +1 -1
  111. package/adapters/opencode/commands/flow-work-handoff.md +5 -4
  112. package/adapters/opencode/commands/flow-work-query.md +1 -1
  113. package/adapters/opencode/commands/flow-work-respond.md +1 -1
  114. package/adapters/opencode/commands/flow-work-resume.md +9 -25
  115. package/adapters/opencode/commands/flow-work-run.md +1 -1
  116. package/adapters/opencode/commands/flow-work-try.md +1 -1
  117. package/adapters/opencode/commands/flow-work-watch.md +1 -1
  118. package/bin/cli.mjs +572 -12
  119. package/package.json +1 -1
  120. package/plugins/flow/.claude-plugin/plugin.json +1 -1
  121. package/plugins/flow/CHANGELOG.md +49 -0
  122. package/plugins/flow/examples/FLOW.template.md +2 -1
package/bin/cli.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { cpSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'
3
3
  import { homedir } from 'node:os'
4
- import { dirname, join, resolve } from 'node:path'
4
+ import { basename, dirname, join, resolve } from 'node:path'
5
5
  import { fileURLToPath } from 'node:url'
6
6
  import { execFileSync, spawn } from 'node:child_process'
7
7
 
@@ -299,12 +299,6 @@ function mainCheckout(repo) {
299
299
  return mainCheckouts.get(repo)
300
300
  }
301
301
 
302
- function rootHolding(repo, probe) {
303
- if (existsSync(join(repo, probe))) return repo
304
- const main = mainCheckout(repo)
305
- return main !== repo && existsSync(join(main, probe)) ? main : repo
306
- }
307
-
308
302
  // Exactly this name, case included. A case-insensitive filesystem answers `existsSync` for
309
303
  // `FLOW.CI.md` with `FLOW.ci.md`, which neither the agent's listing nor a Linux CI would read.
310
304
  function hasFile(root, name) {
@@ -438,8 +432,22 @@ function flowConfig(repo, harness, rev = null) {
438
432
  // the two things that read it fail silently when it is missing: the pack drops its `## Work`
439
433
  // section, which it advertises and no reviewer knows to miss, and `--record` used to write the
440
434
  // figure nowhere and exit 0. Same resolution as the config: here first, the main checkout otherwise.
435
+ // The work folders are the union of this checkout's and the main checkout's (flow-core §0): a
436
+ // worktree may hold a `.claude/work` of its own (an `_archive/`, a stray folder) while the work
437
+ // lives in the main checkout, and reading only the first root that exists missed it.
438
+ function workRoots(repo) {
439
+ return [...new Set([join(repo, '.claude', 'work'), join(mainCheckout(repo), '.claude', 'work')])]
440
+ }
441
+
441
442
  function workFolder(repo, branch) {
442
- const root = join(rootHolding(repo, join('.claude', 'work')), '.claude', 'work')
443
+ for (const root of workRoots(repo)) {
444
+ const found = workIn(root, branch)
445
+ if (found) return found
446
+ }
447
+ return null
448
+ }
449
+
450
+ function workIn(root, branch) {
443
451
  if (!existsSync(root)) return null
444
452
  for (const entry of readdirSync(root, { withFileTypes: true })) {
445
453
  if (!entry.isDirectory() || entry.name === '_archive') continue
@@ -1244,9 +1252,7 @@ function editMeta(work, fn) {
1244
1252
  let meta
1245
1253
  try { meta = JSON.parse(readFileSync(p, 'utf8')) } catch { return false }
1246
1254
  fn(meta)
1247
- const tmp = `${p}.tmp`
1248
- writeFileSync(tmp, `${JSON.stringify(meta, null, 2)}\n`)
1249
- renameSync(tmp, p)
1255
+ writeAtomic(p, `${JSON.stringify(meta, null, 2)}\n`)
1250
1256
  return true
1251
1257
  }
1252
1258
 
@@ -1442,7 +1448,7 @@ function canonicalOrigin(raw) {
1442
1448
  // `seen` is shared across every repo of one call: a worktree and its main checkout, or the
1443
1449
  // same path named twice, lead to the same folders and must count them once.
1444
1450
  function worksOf(repo, seen) {
1445
- const roots = new Set([join(repo, '.claude', 'work'), join(mainCheckout(repo), '.claude', 'work')])
1451
+ const roots = new Set(workRoots(repo))
1446
1452
  const works = []
1447
1453
  for (const root of roots) {
1448
1454
  for (const dir of [root, join(root, '_archive')]) {
@@ -1621,6 +1627,548 @@ function yieldOf(argv) {
1621
1627
  }
1622
1628
  }
1623
1629
 
1630
+ // --- panel -----------------------------------------------------------------------------
1631
+ // The live panel, rendered from what the work already records. The prose used to ask the agent
1632
+ // to rebuild it by hand at every stop, and the record of that is plain: since the plan-step
1633
+ // rule landed, 8 of 64 build sessions with a written plan ever published a step, and panels
1634
+ // written on other harnesses lost their clock, their links and their language. So everything
1635
+ // meta.json, the plan's ticks and the forge can say is said here; the agent writes only what
1636
+ // nobody else knows — what is running, what comes next, what it is asking — into
1637
+ // `panel-input.json`. meta.json is read, never written: its transitions belong to the phases.
1638
+
1639
+ const PANEL_INPUT_KEYS = ['phase', 'now', 'next', 'decision', 'attention', 'blocks', 'stale_after_minutes', 'labels']
1640
+ const PANEL_ATTENTION = ['wait', 'block', 'done']
1641
+ const PANEL_LABELS = {
1642
+ now: 'Now', next: 'Next', decision: 'Decision', open: 'Open', closed: 'nothing left here',
1643
+ review: 'review round', findings: 'open', followups: 'follow-ups',
1644
+ // `mrs` left empty is named from the forge the URLs point at: PRs on GitHub, MRs elsewhere.
1645
+ mrs: '', merged: 'merged', plan: 'Plan',
1646
+ }
1647
+ const HARNESS_NAMES = {
1648
+ claude: 'Claude Code', codex: 'Codex', opencode: 'OpenCode', zcode: 'zcode', gemini: 'Gemini CLI', hermes: 'Hermes',
1649
+ }
1650
+ const MAX_STEP_LINES = 5
1651
+
1652
+ function flagValue(argv, name) {
1653
+ const at = argv.indexOf(name)
1654
+ return at === -1 ? null : argv[at + 1] ?? null
1655
+ }
1656
+
1657
+ // `git@host:owner/repo.git`, `https://host/owner/repo.git`, `ssh://git@host:22/owner/repo.git`
1658
+ // → `owner.repo`; the control room groups its cards by this id (flow-core §4.6).
1659
+ function repoId(repo) {
1660
+ const url = git(['remote', 'get-url', 'origin'], repo).trim()
1661
+ let path
1662
+ if (!url) path = basename(mainCheckout(repo))
1663
+ else if (url.includes('//')) path = url.replace(/^[a-z+]+:\/\/[^/]*\//i, '')
1664
+ else path = url.replace(/^[^:]*:/, '')
1665
+ return path.replace(/\.git$/, '').replace(/\//g, '.').replace(/[^A-Za-z0-9_.~:@+-]/g, '-')
1666
+ }
1667
+
1668
+ // The id is dropped only as a whole token: `244 · Ship it` loses it, `2440 widgets` does not.
1669
+ function shortTitle(title, ticket) {
1670
+ let t = String(title ?? '').trim()
1671
+ if (ticket) {
1672
+ const id = String(ticket).replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
1673
+ t = t.replace(new RegExp(`^\\[?#?${id}\\]?(?=[\\s·:\\-–—]|$)\\s*[·:\\-–—]?\\s*`, 'i'), '')
1674
+ }
1675
+ return t
1676
+ }
1677
+
1678
+ // What a URL names: `!123` on GitLab, `#123` on GitHub, or nothing recognisable.
1679
+ function mrRef(url) {
1680
+ const m = /\/(merge_requests|pull)\/(\d+)/.exec(String(url ?? ''))
1681
+ return m ? `${m[1] === 'pull' ? '#' : '!'}${m[2]}` : null
1682
+ }
1683
+
1684
+ // The statuses meta.json really carries, not only the five the plan's table names: works in the
1685
+ // wild hold `open`, `draft`, `dropped`, `merged_into_umbrella`, `closed_superseded…`, none at
1686
+ // all, or a bare string. A status nobody listed is drawn from whether it has an MR/PR, never
1687
+ // refused — a refused panel is the hand-written one this exists to replace.
1688
+ const SETTLED_STATUS = /^(merged|closed|superseded|skipped|dropped)/
1689
+
1690
+ // What meta.json records wins over the forge: it is written only when a phase confirmed it,
1691
+ // while the forge's answer may be a cached one. A finished work's open MR/PR is a merged one.
1692
+ function trainMark(status, url, forge, done, abandoned) {
1693
+ const s = String(status ?? '')
1694
+ if (s.startsWith('merged')) return 'done'
1695
+ if (s.startsWith('closed') || s.startsWith('dropped')) return 'block'
1696
+ if (s.startsWith('superseded') || s.startsWith('skipped')) return null
1697
+ if (forge?.state === 'merged') return 'done'
1698
+ if (forge?.state === 'closed') return 'block'
1699
+ if (url) return done ? 'done' : 'wait'
1700
+ if (done) return 'done'
1701
+ if (s === 'in_progress' && !abandoned) return 'current'
1702
+ return 'pending'
1703
+ }
1704
+
1705
+ // The single MR/PR of a work without `mrs[]`, under whichever key the phase wrote it.
1706
+ function singleUrl(meta) {
1707
+ return ['mr_url', 'pr_url', 'url', 'mr'].map((k) => meta[k]).find((v) => typeof v === 'string' && /^https?:\/\//.test(v)) ?? null
1708
+ }
1709
+
1710
+ // The plan's numbered steps, as 126 real plans write them: top-level lines of its section, with
1711
+ // a checkbox or without (an unticked step is often a bare `3. …`), in file order — a step added
1712
+ // later with a lower number stays where it was written. Under a `###` only lines carrying a
1713
+ // checkbox are steps: that is how review fixes are appended (`### Arreglos de la review`), and a
1714
+ // subsection's bare numbers are notes. The repair rounds the plugin writes (`### Red suite …
1715
+ // round <k>`) count bare lines too, and restart at 1, so they are referred to as `r<k>.<n>`. A
1716
+ // step struck through (`~~…~~`) was dropped and is not drawn. Keys stay unique whatever repeats.
1717
+ function planSteps(work, heading) {
1718
+ let text
1719
+ try { text = readFileSync(join(work, heading.file), 'utf8') } catch { return [] }
1720
+ const lines = text.split('\n')
1721
+ const start = lines.findIndex((l) => heading.re.test(l))
1722
+ if (start === -1) return []
1723
+ const steps = []
1724
+ const keys = new Set()
1725
+ let fence = false
1726
+ let sub = null
1727
+ for (const line of lines.slice(start + 1)) {
1728
+ if (/^\s{0,3}(`{3,}|~{3,})/.test(line)) { fence = !fence; continue }
1729
+ if (fence) continue
1730
+ if (/^#{1,2}\s/.test(line)) break
1731
+ const h = /^#{3,6}\s+(.*)$/.exec(line)
1732
+ if (h) {
1733
+ const r = /^Red suite\b.*?\bround\s+(\d+)/i.exec(h[1])
1734
+ sub = r ? { round: Number(r[1]) } : { round: 0 }
1735
+ continue
1736
+ }
1737
+ const m = /^(?:-\s+\[([ xX])\]\s*)?(\d+)\.\s+(?:\[([ xX])\]\s*)?(.*)$/.exec(line)
1738
+ if (!m) continue
1739
+ const boxed = m[1] !== undefined || m[3] !== undefined
1740
+ if (sub && !sub.round && !boxed) continue
1741
+ if (/^~~.*~~/.test(m[4].trim())) continue
1742
+ const ref = sub?.round ? `r${sub.round}.${m[2]}` : m[2]
1743
+ let key = `step-${ref.replace('.', '-')}`
1744
+ for (let i = 2; keys.has(key); i++) key = `step-${ref.replace('.', '-')}-${i}`
1745
+ keys.add(key)
1746
+ const ticked = /x/i.test(m[1] ?? '') || /x/i.test(m[3] ?? '')
1747
+ const label = m[4].split(/\s+—\s+/)[0].replace(/`/g, '').trim()
1748
+ steps.push({ ref, key, ticked, text: label.length > 72 ? `${label.slice(0, 71)}…` : label })
1749
+ }
1750
+ return steps
1751
+ }
1752
+
1753
+ // One line per step, never ahead of the ticks, five lines at most: past three finished steps
1754
+ // they fold into one, and a long pending tail folds the same way (flow-core §4.1).
1755
+ function stepLines(steps) {
1756
+ if (!steps.length) return []
1757
+ const done = steps.filter((s) => s.ticked)
1758
+ const rest = steps.filter((s) => !s.ticked)
1759
+ // A folded range names its lowest and highest step; steps written out of order would otherwise
1760
+ // fold into a range that leaves one of them out.
1761
+ const range = (ss) => {
1762
+ if (ss.length === 1) return ss[0].ref
1763
+ const nums = ss.map((x) => Number(x.ref))
1764
+ return nums.every(Number.isFinite) ? `${Math.min(...nums)}–${Math.max(...nums)}` : `${ss[0].ref}–${ss[ss.length - 1].ref}`
1765
+ }
1766
+ const out = []
1767
+ if (done.length > 3) out.push({ key: 'steps-done', ref: range(done), text: done.map((s) => s.text).join(' · '), mark: 'done', indent: 4 })
1768
+ else done.forEach((s) => out.push({ key: s.key, ref: s.ref, text: s.text, mark: 'done', indent: 4 }))
1769
+ const [current, ...pending] = rest
1770
+ if (current) out.push({ key: current.key, ref: current.ref, text: current.text, mark: 'current', indent: 4 })
1771
+ const room = MAX_STEP_LINES - out.length
1772
+ if (pending.length > room && room > 0) {
1773
+ pending.slice(0, room - 1).forEach((s) => out.push({ key: s.key, ref: s.ref, text: s.text, mark: 'pending', indent: 4 }))
1774
+ const tail = pending.slice(room - 1)
1775
+ out.push({ key: 'steps-pending', ref: range(tail), text: tail.map((s) => s.text).join(' · '), mark: 'pending', indent: 4 })
1776
+ } else pending.forEach((s) => out.push({ key: s.key, ref: s.ref, text: s.text, mark: 'pending', indent: 4 }))
1777
+ return out
1778
+ }
1779
+
1780
+ function readPanelInput(work, warn) {
1781
+ const p = join(work, 'panel-input.json')
1782
+ if (!existsSync(p)) return { input: {} }
1783
+ let input
1784
+ try { input = JSON.parse(readFileSync(p, 'utf8')) } catch (e) { return { error: `\`${p}\` is not readable JSON (${e.message})` } }
1785
+ if (!input || typeof input !== 'object' || Array.isArray(input)) return { error: `\`${p}\` must hold one JSON object` }
1786
+ for (const k of Object.keys(input)) if (!PANEL_INPUT_KEYS.includes(k)) { warn(`panel-input.json: \`${k}\` is not a field — ignored (fields: ${PANEL_INPUT_KEYS.join(', ')})`); delete input[k] }
1787
+ if (input.attention != null && !PANEL_ATTENTION.includes(input.attention)) {
1788
+ warn(`panel-input.json: attention \`${input.attention}\` ignored — one of ${PANEL_ATTENTION.join(' · ')}, or null`)
1789
+ delete input.attention
1790
+ }
1791
+ if (input.blocks != null && !Array.isArray(input.blocks)) { warn('panel-input.json: `blocks` must be a list — ignored'); delete input.blocks }
1792
+ if (input.labels != null) {
1793
+ if (typeof input.labels !== 'object' || Array.isArray(input.labels)) { warn('panel-input.json: `labels` must be an object — ignored'); delete input.labels }
1794
+ else for (const k of Object.keys(input.labels)) if (!(k in PANEL_LABELS)) { warn(`panel-input.json: label \`${k}\` is not one — ignored (labels: ${Object.keys(PANEL_LABELS).join(', ')})`); delete input.labels[k] }
1795
+ }
1796
+ return { input }
1797
+ }
1798
+
1799
+ function renderPanel({ meta, work, input, forge = {}, foreign = false, prs = false }) {
1800
+ const labels = { ...PANEL_LABELS, ...(input.labels ?? {}) }
1801
+ const done = meta.phase === 'done'
1802
+ const abandoned = meta.phase === 'abandoned'
1803
+ const lines = [{ key: 'title', text: shortTitle(meta.title, meta.ticket) || String(meta.ticket ?? ''), style: 'title' }]
1804
+ const block = (ls) => { if (ls.length) lines.push('', ...ls) }
1805
+
1806
+ const train = []
1807
+ const marks = []
1808
+ const mrs = Array.isArray(meta.mrs) ? meta.mrs : []
1809
+ // The MR/PR being built is the first one with a written plan that is neither shipped nor
1810
+ // settled — never a status: build marks an entry `in_progress` only in a train, so a work
1811
+ // planned as one MR/PR keeps it `pending` while its steps are ticked.
1812
+ const plans = new Map()
1813
+ const planOf = (n) => {
1814
+ if (!plans.has(n)) plans.set(n, planSteps(work, { file: '05-implementation.md', re: new RegExp(`^##\\s+Plan\\s+MR(/PR)?\\s+#${n}\\b`) }))
1815
+ return plans.get(n)
1816
+ }
1817
+ const building = done || abandoned ? null : mrs.map((m, i) => (m && typeof m === 'object' ? { m, n: m.n ?? i + 1 } : null))
1818
+ .find((e) => e && !e.m.url && !SETTLED_STATUS.test(String(e.m.status ?? '')) && planOf(e.n).length)?.m
1819
+ let pendingRun = []
1820
+ const flush = () => {
1821
+ if (!pendingRun.length) return
1822
+ const first = pendingRun[0].n, last = pendingRun[pendingRun.length - 1].n
1823
+ train.push({ key: pendingRun.length === 1 ? `mr-${first}` : `mr-${first}-${last}`, ref: pendingRun.length === 1 ? `#${first}` : `#${first}–#${last}`, text: pendingRun.map((m) => m.title).join(' · '), mark: 'pending' })
1824
+ pendingRun = []
1825
+ }
1826
+ mrs.forEach((raw, i) => {
1827
+ const m = raw && typeof raw === 'object' ? raw : { n: i + 1, title: String(raw ?? '') }
1828
+ const n = m.n ?? i + 1
1829
+ const f = m.url ? forge[m.url] : null
1830
+ let mark = trainMark(m.status, m.url, f, done, abandoned)
1831
+ if (!mark) return
1832
+ if (m === building && mark === 'pending') mark = 'current'
1833
+ marks.push(mark)
1834
+ if (mark === 'pending') { pendingRun.push({ n, title: m.title }); return }
1835
+ flush()
1836
+ train.push({ key: `mr-${n}`, ref: `#${n}`, text: String(m.title ?? ''), mark, ...(m.url ? { link: m.url } : {}) })
1837
+ if (mark === 'wait' && f?.summary) train.push({ key: `mr-${n}-state`, text: f.summary, mark: 'info', indent: 4 })
1838
+ })
1839
+ flush()
1840
+ const url = !mrs.length ? singleUrl(meta) : null
1841
+ if (url) {
1842
+ const f = forge[url]
1843
+ const mark = trainMark(null, url, f, done)
1844
+ marks.push(mark)
1845
+ train.push({ key: 'mr-1', ref: mrRef(url) ?? '#1', text: shortTitle(meta.title, meta.ticket), mark, link: url })
1846
+ if (mark === 'wait' && f?.summary) train.push({ key: 'mr-1-state', text: f.summary, mark: 'info', indent: 4 })
1847
+ }
1848
+ // A bug's plan lives in 04-fix.md and is shown while fix runs: before `fix` first closes, and
1849
+ // when a review's or a red suite's steps send the work back into it — `fix` is then already in
1850
+ // phases_done, and the phase being run is the only thing that says so.
1851
+ let steps = null
1852
+ if (building) {
1853
+ const n = building.n ?? mrs.indexOf(building) + 1
1854
+ steps = { ref: `#${n}`, list: planOf(n) }
1855
+ }
1856
+ if (meta.type === 'bug' && !done && !abandoned) {
1857
+ const fixClosed = Array.isArray(meta.phases_done) && meta.phases_done.includes('fix')
1858
+ if (!fixClosed || input.phase === 'fix') steps = { ref: null, list: planSteps(work, { file: '04-fix.md', re: /^##\s+Plan\b/ }) }
1859
+ }
1860
+ // Each block opens with a header that names it and says how far along it is. The train is
1861
+ // reference once its MRs/PRs merge, so it starts folded; the plan being built is the news.
1862
+ if (train.length) {
1863
+ const forgeWord = labels.mrs || (prs || train.some((l) => /\/pulls?\/\d+/.test(l.link ?? '')) ? 'PRs' : 'MRs')
1864
+ const merged = marks.filter((k) => k === 'done').length
1865
+ block([{ key: 'mrs', text: forgeWord, style: 'section', summary: `${merged}/${marks.length} ${labels.merged}`, collapsed: true }, ...train])
1866
+ }
1867
+ if (steps?.list.length) {
1868
+ const ticked = steps.list.filter((s) => s.ticked).length
1869
+ block([{ key: 'plan', text: steps.ref ? `${labels.plan} ${steps.ref}` : labels.plan, style: 'section', summary: `${ticked}/${steps.list.length}` }, ...stepLines(steps.list)])
1870
+ }
1871
+
1872
+ // Every MR/PR merged is the end of the work's waiting, whatever meta.json.phase still says: a
1873
+ // merge done in the forge has no session to close the work, and the card it leaves behind
1874
+ // must stop claiming the person (flow-core §4.6).
1875
+ // A sibling repo's MRs/PRs keep the work open until each one merged — by the forge's word, or
1876
+ // by its entry's own `done`/`merged`. An entry with no MR/PR is a reminder `ship` and `daily`
1877
+ // carry, not something this panel waits on: no phase ever marks it done.
1878
+ const sibs = []
1879
+ let siblingOpen = false
1880
+ for (const r of Array.isArray(meta.related_repos) ? meta.related_repos : []) {
1881
+ const name = String(r?.repo ?? '').split(/[\s/]/).filter(Boolean).pop() ?? ''
1882
+ const finished = /^(done|merged)$/.test(String(r?.status ?? ''))
1883
+ for (const u of Array.isArray(r?.mrs) ? r.mrs : []) {
1884
+ const f = forge[u]
1885
+ const mark = f?.state === 'merged' || (finished && f?.state !== 'closed') ? 'done' : f?.state === 'closed' ? 'block' : 'wait'
1886
+ if (mark !== 'done') siblingOpen = true
1887
+ sibs.push({ key: `sib-${sibs.length + 1}`, ref: `${name} ${mrRef(u) ?? ''}`.trim(), text: f?.summary ?? String(r.scope ?? '').split(/[.;]/)[0], mark, link: u })
1888
+ }
1889
+ }
1890
+ block(sibs)
1891
+ const blocks = (Array.isArray(input.blocks) ? input.blocks : []).map((b, i) => {
1892
+ const o = typeof b === 'string' ? { text: b } : (b ?? {})
1893
+ return { key: `block-${i + 1}`, text: String(o.text ?? ''), mark: 'block', ...(o.link ? { link: String(o.link) } : {}) }
1894
+ }).filter((b) => b.text)
1895
+
1896
+ // … but only when nothing else is still open: a sibling repo's MR/PR, a blocker, or a
1897
+ // question the session is waiting on keeps the work claiming someone. Rendered for another
1898
+ // session (`--work`: daily, clean), the input is whatever that session last wrote, and a
1899
+ // question about an MR/PR that has since merged is not one anybody is waiting on.
1900
+ const merged = !done && marks.length > 0 && marks.every((k) => k === 'done') && !siblingOpen
1901
+ && (foreign || (!input.decision && !blocks.length))
1902
+ const closed = done || merged
1903
+ const over = closed || abandoned
1904
+
1905
+ if (!over) {
1906
+ const rows = Array.isArray(meta.review_findings) ? meta.review_findings : []
1907
+ const round = rows.reduce((n, r) => Math.max(n, Number(r?.round) || 0), 0)
1908
+ const openRows = rows.filter((r) => Number(r?.round) === round && r?.outcome === 'open').length
1909
+ const fups = (Array.isArray(meta.followups) ? meta.followups : []).filter((f) => ['proposed', 'accepted'].includes(f?.status)).length
1910
+ const parts = []
1911
+ if (openRows) parts.push(`${labels.review} ${round} · ${openRows} ${labels.findings}`)
1912
+ if (fups) parts.push(`${fups} ${labels.followups}`)
1913
+ if (parts.length) block([{ key: 'open', ref: labels.open, text: parts.join(' · '), mark: 'info' }])
1914
+ }
1915
+
1916
+ const talk = []
1917
+ if (!over && input.now) talk.push({ key: 'now', ref: labels.now, text: String(input.now), mark: 'info' })
1918
+ if (!over && input.next) talk.push({ key: 'next', ref: labels.next, text: String(input.next), mark: 'info' })
1919
+ if (!over && input.decision) talk.push({ key: 'decision', ref: labels.decision, text: String(input.decision), mark: 'wait' })
1920
+ if (closed) talk.push({ key: 'closed', text: labels.closed, mark: 'info', style: 'ok' })
1921
+ block(talk)
1922
+
1923
+ if (!closed) block(blocks)
1924
+
1925
+ const phase = done ? 'done' : (abandoned ? meta.phase : input.phase ?? meta.phase ?? null)
1926
+ const attention = closed ? 'done'
1927
+ : abandoned ? null
1928
+ : input.decision ? 'wait'
1929
+ : input.attention ?? (blocks.length ? 'block' : null)
1930
+ // Where this console works in the project's plan (flow-core §10): written into meta.json only
1931
+ // when the work's ticket is a deliverable's, and left out otherwise — the board then shows it
1932
+ // off the plan, which is the truth.
1933
+ const place = meta.roadmap && typeof meta.roadmap === 'object' ? meta.roadmap : {}
1934
+ const milestone = typeof place.milestone === 'string' && place.milestone ? place.milestone : null
1935
+ const deliverable = milestone && typeof place.deliverable === 'string' && place.deliverable ? place.deliverable : null
1936
+ return {
1937
+ updated_at: new Date().toISOString(),
1938
+ ...(phase ? { phase } : {}),
1939
+ header: true,
1940
+ ...(milestone ? { milestone } : {}),
1941
+ ...(deliverable ? { deliverable } : {}),
1942
+ ...(attention ? { attention } : {}),
1943
+ ...(Number(input.stale_after_minutes) > 0 ? { stale_after_minutes: Number(input.stale_after_minutes) } : {}),
1944
+ lines,
1945
+ }
1946
+ }
1947
+
1948
+ // `publish_cmd` runs a shell command with no one asking, after every tool call once the hook
1949
+ // is in play — so it is taken only from a FLOW file git does not track: the personal, ignored
1950
+ // one. A command committed to a repo would run on every machine that merely opened it, and
1951
+ // when git cannot say which it is, the command does not run.
1952
+ function publishCmd(repo, harness) {
1953
+ let found = null
1954
+ for (const l of flowLayers(repo, harness).layers) {
1955
+ if (!l.found) continue
1956
+ const cmd = parseFlow(l.text ?? readFileSync(join(l.root, l.name), 'utf8')).panel?.publish_cmd
1957
+ if (cmd !== undefined) found = { cmd, layer: l }
1958
+ }
1959
+ if (!found?.cmd) return {}
1960
+ let tracked
1961
+ try {
1962
+ tracked = execFileSync('git', ['ls-files', '--error-unmatch', '--', found.layer.name], { cwd: found.layer.root, stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf8' })
1963
+ } catch (e) {
1964
+ // 1 is git's own "not tracked"; anything else (128: not a repo, unsafe directory) is no answer.
1965
+ if (e.status === 1) return { cmd: found.cmd }
1966
+ return { ignored: `panel.publish_cmd in ${found.layer.name} not run: git could not say whether that file is tracked (${String(e.stderr || e.message).trim().split('\n')[0]})` }
1967
+ }
1968
+ return tracked ? { ignored: `panel.publish_cmd in ${found.layer.name} ignored: that file is tracked by git, and a committed command would run on every machine that opens the repo — set it in a git-ignored FLOW file` } : { cmd: found.cmd }
1969
+ }
1970
+
1971
+ // One panel line per text line: a reader that greps (the session-start hook looks for the
1972
+ // `now` line and takes its text) finds a line's fields together, and a diff shows a line moved.
1973
+ function panelText(doc) {
1974
+ const { lines, ...top } = doc
1975
+ const head = Object.entries(top).map(([k, v]) => ` ${JSON.stringify(k)}: ${JSON.stringify(v)},`)
1976
+ const body = lines.map((l, i) => ` ${JSON.stringify(l)}${i < lines.length - 1 ? ',' : ''}`)
1977
+ return `{\n${head.join('\n')}\n "lines": [\n${body.join('\n')}\n ]\n}\n`
1978
+ }
1979
+
1980
+ // A temp name of its own per writer: the hook can start a render while another is still
1981
+ // writing, and two renames of one shared temp file lose one of them.
1982
+ function writeAtomic(p, text) {
1983
+ const tmp = `${p}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`
1984
+ try {
1985
+ writeFileSync(tmp, text)
1986
+ renameSync(tmp, p)
1987
+ } catch (e) {
1988
+ try { rmSync(tmp, { force: true }) } catch {}
1989
+ throw e
1990
+ }
1991
+ }
1992
+
1993
+ // `--work` takes a folder's path or its name. A path must be a work folder of this repo (live,
1994
+ // never `_archive/`): the hook names the exact folder it found, so the CLI cannot settle on a
1995
+ // namesake in the other checkout, nor on one that `abandon` or `clean` just archived.
1996
+ function findWork(repo, name) {
1997
+ const roots = workRoots(repo)
1998
+ if (name.includes('/')) {
1999
+ let real
2000
+ try { real = realpathSync(name) } catch { return null }
2001
+ const inside = roots.some((r) => { try { return dirname(real) === realpathSync(r) } catch { return false } })
2002
+ return inside && existsSync(join(real, 'meta.json')) ? real : null
2003
+ }
2004
+ // By name: a live folder only — an archived namesake's card was deleted with its folder.
2005
+ for (const root of roots) if (existsSync(join(root, name, 'meta.json'))) return join(root, name)
2006
+ return null
2007
+ }
2008
+
2009
+ // What earlier `--forge` runs learnt, so a render without it — the hook's, a plan step's —
2010
+ // does not paint a merged MR/PR back to `wait`. A merge is final and kept; anything else (a
2011
+ // close can be reopened, a pipeline moves) is shown for an hour and then dropped rather than
2012
+ // passed off as current. Each entry carries its own time, so a run whose call failed keeps the
2013
+ // previous answer, and only URLs the work still records are kept.
2014
+ const FORGE_FRESH_MS = 60 * 60 * 1000
2015
+
2016
+ function workUrls(meta) {
2017
+ const mrs = Array.isArray(meta.mrs) ? meta.mrs : []
2018
+ return new Set([
2019
+ ...mrs.map((m) => m?.url).filter(Boolean),
2020
+ ...(mrs.length ? [] : [singleUrl(meta)].filter(Boolean)),
2021
+ ...(Array.isArray(meta.related_repos) ? meta.related_repos.flatMap((r) => (Array.isArray(r?.mrs) ? r.mrs : [])) : []),
2022
+ ])
2023
+ }
2024
+
2025
+ function cachedForge(work, meta, now = Date.now()) {
2026
+ let states
2027
+ try { states = JSON.parse(readFileSync(join(work, 'forge-state.json'), 'utf8')).states ?? {} } catch { return {} }
2028
+ const keep = workUrls(meta)
2029
+ const out = {}
2030
+ for (const [url, s] of Object.entries(states)) {
2031
+ if (!keep.has(url) || !s || typeof s !== 'object') continue
2032
+ if (s.state === 'merged') out[url] = { state: 'merged', summary: null, at: s.at }
2033
+ else if (now - Date.parse(s.at ?? 0) < FORGE_FRESH_MS) out[url] = s
2034
+ }
2035
+ return out
2036
+ }
2037
+
2038
+ function panel(argv) {
2039
+ const harness = flagValue(argv, '--harness')
2040
+ if (harness && !OVERLAY_HARNESSES.includes(harness)) {
2041
+ console.error(`flow panel: unknown --harness \`${harness}\` — one of ${OVERLAY_HARNESSES.join(', ')}`); process.exit(1)
2042
+ }
2043
+ // `--repo` lets the hook run this from outside the checkout, where nothing the repo commits
2044
+ // (an `.npmrc`, a `node_modules`) can choose what `npx` executes.
2045
+ const repo = git(['rev-parse', '--show-toplevel'], flagValue(argv, '--repo') ?? process.cwd()).trim()
2046
+ if (!repo) { console.error('flow panel: not a git checkout'); process.exit(1) }
2047
+ const named = flagValue(argv, '--work')
2048
+ const branch = git(['rev-parse', '--abbrev-ref', 'HEAD'], repo).trim()
2049
+ const work = named ? findWork(repo, named) : workFolder(repo, branch)
2050
+ if (!work) { console.error(named ? `flow panel: no work folder named \`${named}\`` : `flow panel: no work on \`${branch}\``); process.exit(1) }
2051
+ let meta
2052
+ try { meta = JSON.parse(readFileSync(join(work, 'meta.json'), 'utf8')) } catch (e) {
2053
+ console.error(`flow panel: \`${join(work, 'meta.json')}\` is missing or not JSON (${e.message})`); process.exit(1)
2054
+ }
2055
+ const warn = (m) => console.error(`flow panel: ${m}`)
2056
+ const { input, error } = readPanelInput(work, warn)
2057
+ if (error) { console.error(`flow panel: ${error} — nothing written`); process.exit(1) }
2058
+ let forge = cachedForge(work, meta)
2059
+ if (argv.includes('--forge')) {
2060
+ const at = new Date().toISOString()
2061
+ const fresh = Object.fromEntries(Object.entries(forgeStates(meta, warn)).map(([u, s]) => [u, { ...s, at }]))
2062
+ forge = { ...forge, ...fresh }
2063
+ writeAtomic(join(work, 'forge-state.json'), `${JSON.stringify({ states: forge }, null, 2)}\n`)
2064
+ }
2065
+ // Rendered for a work on another branch (daily, clean refreshing cards): not this pane's
2066
+ // panel, and its input is another session's. `--work` alone does not say it — the hook names
2067
+ // the folder of this branch's own work.
2068
+ const branches = [meta.branch, ...(Array.isArray(meta.mrs) ? meta.mrs.map((m) => m?.branch) : [])]
2069
+ const foreign = Boolean(named) && !branches.includes(branch)
2070
+ // The forge's own word for the train, read off the remote while no MR/PR has a URL yet.
2071
+ const prs = /github/i.test(git(['remote', 'get-url', 'origin'], repo))
2072
+ const doc = renderPanel({ meta, work, input, forge, foreign, prs })
2073
+ // Another branch's panel.json is the live pane of the session that owns it: a render made for
2074
+ // the control room (daily, clean) writes only the card, never the file that session shows.
2075
+ if (!foreign) writeAtomic(join(work, 'panel.json'), panelText(doc))
2076
+ const config = flowConfig(repo, harness).panel ?? {}
2077
+ // A terminal that paints only what reaches it over its own channel never reads panel.json,
2078
+ // and a hook cannot call an MCP tool. `publish_cmd` is that channel as a command: the
2079
+ // document on its stdin, every time this branch's panel is rendered — the agent's
2080
+ // publication and the hook's refresh alike. Another branch's work is never sent there.
2081
+ if (!foreign) {
2082
+ const publish = publishCmd(repo, harness)
2083
+ if (publish.ignored) warn(publish.ignored)
2084
+ if (publish.cmd) {
2085
+ try {
2086
+ execFileSync('sh', ['-c', publish.cmd], { input: JSON.stringify(doc), cwd: repo, stdio: ['pipe', 'ignore', 'pipe'], timeout: 10000 })
2087
+ } catch (e) { warn(`panel.publish_cmd failed (${String(e.stderr || e.message).trim().split('\n')[0]}) — panel.json is written`) }
2088
+ }
2089
+ }
2090
+ if (config.artifact) {
2091
+ writeAtomic(join(work, 'card.json'), panelText({
2092
+ ...doc, repo: repoId(repo), work: basename(work), ticket: meta.ticket ?? null, type: meta.type ?? null,
2093
+ branch: meta.branch ?? null, ...(HARNESS_NAMES[harness] ? { harness: HARNESS_NAMES[harness] } : {}),
2094
+ }))
2095
+ }
2096
+ console.log(JSON.stringify(doc))
2097
+ }
2098
+
2099
+ function forgeRun(cmd, args) {
2100
+ try {
2101
+ return execFileSync(cmd, args, { encoding: 'utf8', maxBuffer: 16 * 1024 * 1024, stdio: ['ignore', 'pipe', 'ignore'], timeout: 20000 })
2102
+ } catch { return null }
2103
+ }
2104
+
2105
+ const GH_RED = ['FAILURE', 'ERROR', 'CANCELLED', 'TIMED_OUT', 'ACTION_REQUIRED', 'STARTUP_FAILURE']
2106
+ const GH_RUNNING = ['PENDING', 'EXPECTED', 'QUEUED', 'IN_PROGRESS']
2107
+
2108
+ function ghState(url) {
2109
+ const d = firstJson(forgeRun('gh', ['pr', 'view', url, '--json', 'state,isDraft,statusCheckRollup,reviewDecision']) ?? '')
2110
+ if (!d?.state) return null
2111
+ const state = d.state === 'MERGED' ? 'merged' : d.state === 'CLOSED' ? 'closed' : 'open'
2112
+ const checks = Array.isArray(d.statusCheckRollup) ? d.statusCheckRollup : []
2113
+ const verdict = (c) => String(c.conclusion || c.state || '').toUpperCase()
2114
+ const pipeline = !checks.length ? 'none'
2115
+ : checks.some((c) => GH_RED.includes(verdict(c))) ? 'failed'
2116
+ : checks.some((c) => (c.status && c.status !== 'COMPLETED') || GH_RUNNING.includes(verdict(c))) ? 'running'
2117
+ : 'passed'
2118
+ const review = { APPROVED: 'approved', CHANGES_REQUESTED: 'changes requested', REVIEW_REQUIRED: 'review required' }[d.reviewDecision]
2119
+ return { state, parts: [d.isDraft && 'draft', `pipeline ${pipeline}`, review] }
2120
+ }
2121
+
2122
+ function glabState(url) {
2123
+ const m = /^(https?:\/\/[^/]+)\/(.+?)\/-\/merge_requests\/(\d+)/.exec(url)
2124
+ if (!m) return null
2125
+ const [, host, project, iid] = m
2126
+ const d = firstJson(forgeRun('glab', ['mr', 'view', iid, '-R', `${host}/${project}`, '-F', 'json']) ?? '')
2127
+ if (!d?.state) return null
2128
+ const state = d.state === 'merged' ? 'merged' : d.state === 'closed' ? 'closed' : 'open'
2129
+ if (state !== 'open') return { state, parts: [] }
2130
+ const hostname = host.replace(/^https?:\/\//, '')
2131
+ const api = (path) => {
2132
+ const out = forgeRun('glab', ['api', '--hostname', hostname, `projects/${encodeURIComponent(project)}/merge_requests/${iid}/${path}`])
2133
+ try { return out ? JSON.parse(out) : null } catch { return null }
2134
+ }
2135
+ const st = d.head_pipeline?.status
2136
+ const pipeline = !st ? 'none' : st === 'success' ? 'passed' : ['failed', 'canceled'].includes(st) ? 'failed' : st === 'skipped' ? 'skipped' : 'running'
2137
+ const ap = api('approvals')
2138
+ const need = Number(ap?.approvals_required) || 0
2139
+ const approvals = !ap ? null
2140
+ : need ? `${need - (Number(ap.approvals_left) || 0)}/${need} approvals`
2141
+ : (ap.approved_by?.length ? 'approved' : null)
2142
+ const disc = api('discussions?per_page=100')
2143
+ const open = Array.isArray(disc) ? disc.filter((x) => x?.notes?.[0]?.resolvable && !x.notes[0].resolved).length : 0
2144
+ return { state, parts: [d.draft && 'draft', `pipeline ${pipeline}`, approvals, open ? `${open} open threads` : null] }
2145
+ }
2146
+
2147
+ // What the forge says about each MR/PR the panel would draw as open: merged or closed in the
2148
+ // forge while meta.json still says otherwise, and for an open one what it waits on. Only
2149
+ // `ship` writes `merged` into meta.json, and a merge done in the forge has no session to tell
2150
+ // it — 34 of 75 recorded MRs/PRs were still `in_progress` when the audit read them. Asked by
2151
+ // URL, so a sibling repo's MR/PR answers like this repo's. A field the forge does not report
2152
+ // is left out, never guessed; a failed call drops that MR/PR's state and nothing else.
2153
+ function forgeStates(meta, warn) {
2154
+ const urls = new Set()
2155
+ const mrs = Array.isArray(meta.mrs) ? meta.mrs : []
2156
+ for (const m of mrs) {
2157
+ if (m && typeof m === 'object' && m.url && !SETTLED_STATUS.test(String(m.status ?? ''))) urls.add(m.url)
2158
+ }
2159
+ const single = mrs.length ? null : singleUrl(meta)
2160
+ if (single) urls.add(single)
2161
+ for (const r of Array.isArray(meta.related_repos) ? meta.related_repos : []) for (const u of Array.isArray(r?.mrs) ? r.mrs : []) urls.add(u)
2162
+ const out = {}
2163
+ for (const url of urls) {
2164
+ if (!/^https?:\/\/[^\s-]/.test(String(url))) { warn(`--forge: \`${url}\` is not an http(s) URL — skipped`); continue }
2165
+ const s = /\/pull\/\d+/.test(url) ? ghState(url) : /\/merge_requests\/\d+/.test(url) ? glabState(url) : null
2166
+ if (!s) { warn(`--forge: no state for ${url} — drawn from meta.json`); continue }
2167
+ out[url] = { state: s.state, summary: s.parts.filter(Boolean).join(' · ') || null }
2168
+ }
2169
+ return out
2170
+ }
2171
+
1624
2172
  function usage() {
1625
2173
  console.log(`flow-workflows v${version()} — guided feat/bug workflows for coding agents
1626
2174
 
@@ -1632,6 +2180,7 @@ function usage() {
1632
2180
  npx flow-workflows review [--out <file>] [--record] [same options as bundle]
1633
2181
  npx flow-workflows cost
1634
2182
  npx flow-workflows record-review --file <rows.json>
2183
+ npx flow-workflows panel [--harness <name>] [--work <folder>] [--forge] [--repo <path>]
1635
2184
  npx flow-workflows yield [<repo-path>…]
1636
2185
  npx flow-workflows escape <commit> [--file <path>]
1637
2186
 
@@ -1689,6 +2238,16 @@ Claude Code, Codex CLI and zcode have their own marketplaces:
1689
2238
  severities and outcomes come from closed lists; one value outside them and nothing is
1690
2239
  written, and the error names the values that are valid.
1691
2240
 
2241
+ "panel" renders this branch's work as its live panel — title, MR/PR train, the plan's steps
2242
+ from its ticks, sibling repos' MRs/PRs, open review findings and follow-ups — from
2243
+ meta.json and the plan, plus what the agent wrote in panel-input.json (now, next,
2244
+ decision, blockers, labels). It writes panel.json (and card.json when panel.artifact is
2245
+ set), pipes the document to panel.publish_cmd when set, and prints it — for another
2246
+ branch's work (daily, clean) it writes card.json only. --forge asks gh/glab for each open MR/PR's real state.
2247
+ --work names a work folder (another branch's is never sent to publish_cmd);
2248
+ --repo runs it on a checkout other than the current directory. A --forge run keeps its
2249
+ answers in forge-state.json for the renders that follow it. meta.json is never written.
2250
+
1692
2251
  "escape" tells whether the commit a bug investigation blamed went through a flow review:
1693
2252
  it must sit inside exactly one work's reviewed range (merge history), or carry the number
1694
2253
  of exactly one reviewed MR/PR in its subject (squash). Then it is recorded in this branch's
@@ -1712,6 +2271,7 @@ else if (cmd === 'tier') tier(process.argv.slice(3))
1712
2271
  else if (cmd === 'cost') cost(process.argv.slice(3))
1713
2272
  else if (cmd === 'yield') yieldOf(process.argv.slice(3))
1714
2273
  else if (cmd === 'record-review') recordReview(process.argv.slice(3))
2274
+ else if (cmd === 'panel') panel(process.argv.slice(3))
1715
2275
  else if (cmd === 'escape') escapeOf(process.argv.slice(3))
1716
2276
  else if (cmd === 'review') review(process.argv.slice(3)).catch((e) => { console.error(`flow review: ${e.message}`); process.exit(1) })
1717
2277
  else if (cmd === 'check') check()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flow-workflows",
3
- "version": "0.114.0",
3
+ "version": "0.116.0",
4
4
  "description": "Guided feat/bug workflows (start→ship), post-deploy monitoring and multi-agent code review, stack-agnostic. Each repo uses a shared FLOW.md plus optional harness overlay.",
5
5
  "type": "module",
6
6
  "bin": {