yadflow 4.5.2 → 4.7.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 (101) hide show
  1. package/CHANGELOG.md +206 -0
  2. package/README.md +4 -1
  3. package/bin/commands.mjs +5 -1
  4. package/bin/yad.mjs +174 -18
  5. package/cli/artifact-status.mjs +88 -20
  6. package/cli/build.mjs +1372 -0
  7. package/cli/checkpoint.mjs +2 -2
  8. package/cli/commit.mjs +1 -0
  9. package/cli/dial.mjs +21 -1
  10. package/cli/docs.mjs +6 -1
  11. package/cli/doctor.mjs +133 -26
  12. package/cli/epic-state.mjs +396 -123
  13. package/cli/errors.mjs +2 -0
  14. package/cli/find-product.mjs +36 -2
  15. package/cli/fold.mjs +9 -5
  16. package/cli/gate-local.mjs +9 -1
  17. package/cli/gate.mjs +442 -33
  18. package/cli/history.mjs +22 -2
  19. package/cli/hook.mjs +3 -1
  20. package/cli/index-command.mjs +2 -2
  21. package/cli/ledger.mjs +60 -0
  22. package/cli/lib.mjs +12 -1
  23. package/cli/lifecycle/defaults/1.json +96 -0
  24. package/cli/lifecycle/lifecycle.schema.json +121 -0
  25. package/cli/lifecycle.mjs +695 -0
  26. package/cli/next.mjs +34 -11
  27. package/cli/openpr.mjs +81 -5
  28. package/cli/platform.mjs +21 -0
  29. package/cli/pr-list.mjs +49 -3
  30. package/cli/product-index.mjs +6 -3
  31. package/cli/product-token.mjs +186 -0
  32. package/cli/productcommit.mjs +33 -0
  33. package/cli/recommend.mjs +3 -1
  34. package/cli/repo-publish.mjs +2 -2
  35. package/cli/run-checks.mjs +586 -0
  36. package/cli/ship-drift.mjs +384 -0
  37. package/cli/standup.mjs +1 -1
  38. package/cli/status.mjs +282 -0
  39. package/cli/test-build.mjs +1559 -0
  40. package/cli/test-run-checks.mjs +603 -0
  41. package/cli/test-worktree.mjs +520 -0
  42. package/cli/thread.mjs +50 -3
  43. package/cli/tidy.mjs +2 -2
  44. package/cli/toolbox.mjs +36 -5
  45. package/cli/workspace.mjs +4 -1
  46. package/cli/worktree-record.mjs +53 -0
  47. package/cli/worktree.mjs +379 -0
  48. package/package.json +4 -3
  49. package/skills/sdlc/config.yaml +28 -20
  50. package/skills/sdlc/module-help.csv +1 -1
  51. package/skills/yad-backfill/references/backfill.md +8 -1
  52. package/skills/yad-backfill/templates/checks/backfill-check.sh +54 -6
  53. package/skills/yad-change/SKILL.md +3 -0
  54. package/skills/yad-checks/SKILL.md +47 -5
  55. package/skills/yad-checks/references/check-gates.md +124 -12
  56. package/skills/yad-checks/templates/checks/build-test-lint.sh +22 -3
  57. package/skills/yad-checks/templates/checks/commit-message.sh +8 -2
  58. package/skills/yad-checks/templates/checks/contract-check.sh +354 -48
  59. package/skills/yad-checks/templates/checks/epic-open.sh +87 -14
  60. package/skills/yad-checks/templates/checks/ledger-guard.sh +3 -3
  61. package/skills/yad-checks/templates/checks/lineage-check.sh +88 -15
  62. package/skills/yad-checks/templates/checks/member-check.mjs +206 -35
  63. package/skills/yad-checks/templates/checks/package-manager.sh +41 -4
  64. package/skills/yad-checks/templates/checks/product-checkout.sh +161 -13
  65. package/skills/yad-checks/templates/checks/reconcile-debt-check.sh +94 -15
  66. package/skills/yad-checks/templates/checks/risk-map-check.sh +2 -2
  67. package/skills/yad-checks/templates/checks/spec-link.sh +63 -4
  68. package/skills/yad-checks/templates/checks/verified-commits.sh +23 -5
  69. package/skills/yad-checks/templates/github/yad-checks.yml +8 -8
  70. package/skills/yad-checks/templates/gitlab/.gitlab-ci.yml +3 -0
  71. package/skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml +4 -4
  72. package/skills/yad-checks/templates/gitlab/yad-product-checks.gitlab-ci.yml +16 -3
  73. package/skills/yad-checks/templates/gitlab/yad-update-guard.gitlab-ci.yml +5 -1
  74. package/skills/yad-checks/templates/gitlab/yad-verified-commits.gitlab-ci.yml +5 -1
  75. package/skills/yad-commit/SKILL.md +4 -2
  76. package/skills/yad-docs/templates/app/package-lock.json +395 -106
  77. package/skills/yad-docs/templates/app/package.json +2 -2
  78. package/skills/yad-engineer-review/SKILL.md +45 -20
  79. package/skills/yad-engineer-review/references/ship-and-record.md +42 -8
  80. package/skills/yad-epic/references/state-schema.md +83 -20
  81. package/skills/yad-implement/SKILL.md +75 -13
  82. package/skills/yad-implement/references/implement-conventions.md +8 -1
  83. package/skills/yad-implement/templates/.gitmessage +3 -0
  84. package/skills/yad-open-pr/SKILL.md +21 -0
  85. package/skills/yad-pr-template/SKILL.md +6 -2
  86. package/skills/yad-pr-template/templates/checks/pr-template.sh +85 -4
  87. package/skills/yad-pr-template/templates/checks/pr-title.sh +1 -1
  88. package/skills/yad-pr-template/templates/github/pull_request_template.md +1 -1
  89. package/skills/yad-pr-template/templates/gitlab/merge_request_templates/Default.md +1 -1
  90. package/skills/yad-product-bridge/SKILL.md +14 -1
  91. package/skills/yad-product-bridge/references/bridge.md +29 -5
  92. package/skills/yad-product-bridge/templates/gitlab/yad-gate-sync.gitlab-ci.yml +9 -4
  93. package/skills/yad-reconcile/SKILL.md +30 -0
  94. package/skills/yad-review-gate/SKILL.md +8 -2
  95. package/skills/yad-review-gate/references/gating.md +26 -1
  96. package/skills/yad-run/SKILL.md +52 -28
  97. package/skills/yad-run/references/run-loop.md +42 -21
  98. package/skills/yad-spec/SKILL.md +142 -17
  99. package/skills/yad-spec/references/spec-handoff.md +68 -5
  100. package/skills/yad-status/SKILL.md +7 -0
  101. package/skills/yad-stories/references/story-schema.md +1 -1
package/cli/status.mjs ADDED
@@ -0,0 +1,282 @@
1
+ // `yad status [--brief]` (#349) — where the work stands, in about 20 lines: the story this checkout is on,
2
+ // each open epic and its next action, the open PRs/MRs, and what is still owed. Read-only. It exists for
3
+ // the moment after a context reset (a person back from a break, an agent whose memory was summarised):
4
+ // one command instead of rebuilding the picture from several files and acting on a stale one.
5
+ //
6
+ // It reuses what the other views already compute — `yad next`'s action per epic, `yad standup`'s PR/MR
7
+ // reading — and adds no state of its own. `--brief` is the only form today, so `yad status` prints the same.
8
+ //
9
+ // here the task branch this checkout is on (feat/<story>-<task>-…) and its Build lane step
10
+ // epics each open epic: its step and the next action
11
+ // prs your open PRs/MRs on the Product and every registered repo (asked of the platform)
12
+ // owed steps deferred as debt, recorded blockers (Shape and Build), open hotfix debt, open
13
+ // follow-up PRs/MRs (fix/<story>-<task>-followup-…)
14
+ import fs from 'node:fs';
15
+ import path from 'node:path';
16
+ import { c, log, info, hand, readJSON, exists, forTerminal, stripAnsi, run } from './lib.mjs';
17
+ import { isVerifiedLedger, productConfigPath, PROJECT_FILES } from './manifest.mjs';
18
+ import { epicRoot, epicStories, featureStatus, isPassed, loadLedger, doneStepUnapproved, reviewAsItStands, loadSkillBindings, buildNextForRepo, stepStatus, isValidEpicId, PRODUCT_DONE, PRODUCT_EPICS, STEPS } from './epic-state.mjs';
19
+ import { listEpics, epicAction, actionLine, skillPhrase, soloOf } from './next.mjs';
20
+ import { productGit, resolveDefaultBranch } from './productcommit.mjs';
21
+ import { repoSources } from './standup.mjs';
22
+ import { listPrs, prTarget } from './pr-list.mjs';
23
+ import { platformLogin } from './platform.mjs';
24
+ import { productIdentity } from './members.mjs';
25
+ import { taskFromBranch } from './commit.mjs';
26
+ import { isFollowUpBranch, storyEpic } from './build.mjs';
27
+ import { loadDebt } from './thread.mjs';
28
+ import { registryEntryFor } from './find-product.mjs';
29
+ import { readRegistry } from './workspace.mjs';
30
+
31
+ // How many rows each section shows before "+N more": the whole view stays near 20 lines (#349).
32
+ export const BUDGET = { epics: 5, prs: 4, owed: 4 };
33
+
34
+ const safe = (v) => forTerminal(String(v ?? ''));
35
+ const prWord = (platform) => (platform === 'gitlab' ? 'MR !' : 'PR #');
36
+ // A task id inside any follow-up branch name; `isFollowUpBranch` (#350's one rule) then confirms it.
37
+ // Case-sensitive, as a story id is (E117) — the same rule the task branch above is read by.
38
+ const FOLLOW_UP_ID = /(?:^|[/_])(EP-[a-z0-9-]+-S\d+-T\d+)-followup(?=$|[-_/])/;
39
+ export function followUpTask(branch) {
40
+ const m = FOLLOW_UP_ID.exec(branch || '');
41
+ if (!m) return null;
42
+ const [, story, task] = /^(.+)-(T\d+)$/.exec(m[1]) || [];
43
+ return story && isFollowUpBranch(branch, story, task) ? `${story}-${task}` : null;
44
+ }
45
+
46
+ // Finished epics are counted, not listed: the view is for what is still moving. "Shipped" is the engine's
47
+ // own rule (`featureStatus`: every story has every lane it declares, all shipped), never the lanes on disk
48
+ // alone — a story that has not begun Build has none. A shipped epic whose parallel test-cases track is
49
+ // still open is not finished, nor is one with a step re-opened behind it (E41), nor one with any Shape
50
+ // step not yet passed (a test-cases review still in review is not on `parallel`); a documented brownfield
51
+ // anchor is.
52
+ function finished(root, id, ledger, a) {
53
+ if (PRODUCT_DONE.includes(a.kind) || a.kind === 'backfill-done') return true;
54
+ if (a.kind !== 'build' || a.parallel || a.reopened?.length) return false;
55
+ if ((Array.isArray(ledger?.state?.steps) ? ledger.state.steps : []).some((s) => s && !isPassed(s))) return false;
56
+ return featureStatus(ledger, { stories: epicStories(epicRoot(root, id)) }) === 'shipped';
57
+ }
58
+ // A lane's steps, only when they are a list of steps with an id (build-state is advisory: a bad file is
59
+ // skipped, never a crash — `loadBuildStates`).
60
+ const laneSteps = (lane) => (Array.isArray(lane?.steps) ? lane.steps.filter((s) => s && typeof s.id === 'string') : []);
61
+ const real = (p) => { try { return fs.realpathSync(p); } catch { return path.resolve(p); } };
62
+
63
+ // The registered repo this checkout is. A monorepo registers the Product's own folder (`path: "."`), which
64
+ // `registryEntryFor` never answers (it is a code-repo command's guard), so that one case is matched here.
65
+ // So is a git worktree of a registered repo (agents often work in one): `registryEntryFor` refuses it on
66
+ // purpose — a command that WRITES must not swap one checkout for another — but this view only reads, and
67
+ // the branch it reports is the worktree's own. The worktree's main checkout names the repo.
68
+ function repoHere(root, cwd, top) {
69
+ const hit = registryEntryFor(root, cwd)?.meta?.name;
70
+ if (typeof hit === 'string') return hit;
71
+ const common = run('git', ['rev-parse', '--git-common-dir'], { cwd });
72
+ const gitDir = common.ok && common.stdout ? path.resolve(cwd, common.stdout) : null;
73
+ if (gitDir && path.basename(gitDir) === '.git' && real(path.dirname(gitDir)) !== real(top)) {
74
+ const main = registryEntryFor(root, path.dirname(gitDir))?.meta?.name;
75
+ if (typeof main === 'string') return main;
76
+ }
77
+ if (real(top) !== real(root)) return null;
78
+ const own = readRegistry(root).registry.repos.find((r) => typeof r?.path === 'string' && typeof r.name === 'string' && real(path.resolve(root, r.path)) === real(root));
79
+ return own?.name ?? null;
80
+ }
81
+
82
+ // The checkout this was run in: its branch, and — on a task branch — the story's lane in this repo.
83
+ function hereOf(root, cwd, ledgers, views) {
84
+ const top = run('git', ['rev-parse', '--show-toplevel'], { cwd });
85
+ if (!top.ok) return { branch: null, task: null, why: 'not inside a git repo' };
86
+ // `symbolic-ref` names the branch on a repo with no commit yet too; a detached HEAD has none.
87
+ const head = run('git', ['symbolic-ref', '--short', '-q', 'HEAD'], { cwd });
88
+ const branch = head.ok && head.stdout ? head.stdout : null;
89
+ const repo = repoHere(root, cwd, top.stdout);
90
+ const id = branch ? taskFromBranch(branch) : null;
91
+ // Case-sensitive, as story ids are (E117): `feat/ep-pay-s01-t02` names no story, so it is not a task branch.
92
+ const m = id ? /^(EP-[a-z0-9-]+-S\d+)-(T\d+)$/.exec(id) : null;
93
+ if (!m) return { branch, task: null, repo, why: branch ? 'not a task branch' : 'no branch checked out' };
94
+ const [, story, task] = m;
95
+ const epic = storyEpic(story);
96
+ const here = { branch, task, story, epic, repo, followUp: !!followUpTask(branch), step: null, status: null, reason: null };
97
+ if (!repo) return { ...here, why: 'this checkout is not a repo the Product registers' };
98
+ const bs = (ledgers.get(epic)?.buildStates || []).find((b) => b?.story === story);
99
+ const lane = bs?.repos?.[repo];
100
+ if (!lane || typeof lane !== 'object') return { ...here, why: `${story} has no Build lane in ${repo} yet` };
101
+ // Only the steps that are steps: a `null` or a bare word in the list is not one (build-state is advisory).
102
+ // With the epic's own skill bindings, as `yad next` reads the lane — a project may bind another skill.
103
+ const next = buildNextForRepo({ ...lane, steps: laneSteps(lane) }, { bindings: views.get(epic) ?? null });
104
+ if (next.status === 'skipped') return { ...here, why: `the lane is skipped in ${repo}${next.record?.reason ? ` — ${next.record.reason}` : ''}` };
105
+ if (next.status === 'unknown') return { ...here, why: `the lane in ${repo} has no steps yet` };
106
+ const active = laneSteps(lane).find((s) => s.id === next.step);
107
+ return { ...here, step: next.step, status: next.status, shipped: !!next.shipped, skill: next.skill ?? null,
108
+ reason: stepStatus(active) === 'blocked' ? active?.record?.reason ?? null : null };
109
+ }
110
+
111
+ // What is still owed, from the files: debt steps, recorded blockers, open hotfix debt.
112
+ function owedOf(root, id, ledger, action, { solo = false, trunk = () => 'main' } = {}) {
113
+ const out = [];
114
+ for (const d of action.debt || []) out.push({ kind: 'debt', epic: id, step: d.step, status: d.status, reason: d.record?.reason ?? null });
115
+ // A blocker is `blocked` WITH a record (E38); a bare `blocked` is the old spelling of `todo`.
116
+ for (const s of Array.isArray(ledger?.state?.steps) ? ledger.state.steps : []) {
117
+ if (s && typeof s.id === 'string' && stepStatus(s) === 'blocked') out.push({ kind: 'blocked', epic: id, step: s.id, reason: s.record?.reason ?? null });
118
+ }
119
+ for (const bs of ledger?.buildStates || []) {
120
+ for (const [repo, lane] of Object.entries(bs?.repos || {})) {
121
+ if (lane?.status === 'skipped') continue;
122
+ for (const s of laneSteps(lane)) {
123
+ if (stepStatus(s) === 'blocked') out.push({ kind: 'blocked', epic: id, story: bs.story ?? null, repo, step: s.id, reason: s.record?.reason ?? null });
124
+ }
125
+ }
126
+ }
127
+ // A done review whose artifact changed after it was approved (#418): owed a fresh review, with the steps
128
+ // the gate prints. Not in solo mode, where no approval is counted and the gate says nothing either.
129
+ for (const s of !solo && Array.isArray(ledger?.state?.steps) ? ledger.state.steps : []) {
130
+ if (doneStepUnapproved(epicRoot(root, id), s, ledger?.approvals)) out.push({ kind: 'unapproved-change', epic: id, step: s.id, artifact: s.artifact, fix: reviewAsItStands(id, s.artifact, trunk()) });
131
+ }
132
+ const open = loadDebt(root, id).filter((d) => d?.status === 'open');
133
+ if (open.length) out.push({ kind: 'hotfix-debt', epic: id, count: open.length });
134
+ return out;
135
+ }
136
+
137
+ // The open PRs/MRs of the Product and every registered repo, read the way `yad standup` reads them.
138
+ function prsOf(root, { env, runner }) {
139
+ const productConfig = readJSON(productConfigPath(root), null);
140
+ const identity = productIdentity(root, { productConfig, ...(runner ? { runner } : {}) });
141
+ const notRead = [];
142
+ const sources = repoSources(root, identity, productConfig, notRead, env);
143
+ // An unreadable registry means no code repo was asked at all: their PRs/MRs are unknown, not none.
144
+ const registry = readRegistry(root);
145
+ const missing = registry.problem ? [{ label: 'the registered repos', why: registry.problem }] : [];
146
+ const seen = new Set();
147
+ const authCache = new Map();
148
+ const logins = new Map();
149
+ const read = [];
150
+ for (const s of sources) {
151
+ const target = prTarget({ platform: s.platform, gitUrl: s.gitUrl }, { env, authCache, ...(runner ? { runner } : {}) });
152
+ const key = target.host && target.repo ? `${target.host}/${target.repo}`.toLowerCase() : null;
153
+ if (key && seen.has(key)) continue;
154
+ if (key) seen.add(key);
155
+ const t = target.ok ? listPrs(target, { sinceMs: Date.now(), env, authCache, ...(runner ? { runner } : {}) }) : target;
156
+ if (!t.ok) { missing.push({ label: s.label, why: t.why }); continue; }
157
+ const who = `${t.platform}\0${t.host}`;
158
+ if (!logins.has(who)) logins.set(who, platformLogin(root, t.platform, { env, host: t.host, ...(runner ? { runner } : {}) }));
159
+ read.push({ label: s.label, platform: t.platform, login: logins.get(who), open: t.open, partial: !!t.openPartial });
160
+ }
161
+ const all = read.flatMap((p) => p.open.map((pr) => ({ repo: p.label, platform: p.platform, number: pr.number, author: pr.author, draft: !!pr.draft,
162
+ checks: pr.checks ?? null, review: pr.review ?? null, branch: pr.branch ?? null, task: pr.branch ? taskFromBranch(pr.branch) : null,
163
+ mine: p.login && pr.author ? p.login.toLowerCase() === String(pr.author).toLowerCase() : null })));
164
+ const known = read.length > 0 && read.every((p) => p.login);
165
+ return {
166
+ asked: true,
167
+ // Yours, when every platform said who you are; else every open one, and the view says so. `none` when
168
+ // no repo answered at all: the count is unknown, not 0.
169
+ listed: known ? all.filter((p) => p.mine) : all,
170
+ whose: !read.length ? 'none' : known ? 'yours' : 'all',
171
+ others: known ? all.filter((p) => !p.mine).length : 0,
172
+ followUps: all.filter((p) => followUpTask(p.branch)).map((p) => ({ ...p, task: followUpTask(p.branch) })),
173
+ partial: read.filter((p) => p.partial).map((p) => p.label),
174
+ notRead: missing,
175
+ };
176
+ }
177
+
178
+ // The whole view as data — what `--json` answers and the lines are drawn from.
179
+ export function buildStatus(root, { cwd = root, fetch = true, env = process.env, runner } = {}) {
180
+ const productConfig = readJSON(productConfigPath(root), null);
181
+ const setUp = exists(path.join(root, PROJECT_FILES.version)) || !!productConfig;
182
+ if (!setUp) return { setUp: false };
183
+ const bindings = loadSkillBindings(root);
184
+ const solo = soloOf(productConfig);
185
+ let trunkName = null; // asked of git only when a fresh review is owed
186
+ const trunk = () => (trunkName ??= resolveDefaultBranch(productGit(root), productConfig));
187
+ const verified = isVerifiedLedger(productConfig);
188
+ const ledgers = new Map();
189
+ const views = new Map();
190
+ const epics = [];
191
+ const owed = [];
192
+ let finishedCount = 0;
193
+ for (const id of listEpics(root)) {
194
+ if (!isValidEpicId(id)) continue;
195
+ let ledger;
196
+ try { ledger = loadLedger(epicRoot(root, id)); } catch { epics.push({ epic: id, problem: 'its ledger does not load — run `yad doctor`' }); continue; }
197
+ ledgers.set(id, ledger);
198
+ const { action, view } = epicAction(root, id, undefined, bindings);
199
+ views.set(id, view);
200
+ owed.push(...owedOf(root, id, ledger, action, { solo, trunk }));
201
+ if (finished(root, id, ledger, action)) { finishedCount += 1; continue; }
202
+ // The same words `yad next` prints, with the parallel test-cases track and any re-opened step beside
203
+ // the chain's own action — they are what keeps a shipped epic open.
204
+ // A step already named, and the review of an author step already named: that review cannot start
205
+ // before its author step is done, so it is not "open" beside it.
206
+ const named = new Set([action.parallel?.step, ...(action.reopened || []).map((l) => l?.step)].filter(Boolean));
207
+ for (const r of STEPS) if (r.kind === 'review' && named.has(r.reviews)) named.add(r.id);
208
+ const also = [
209
+ ...(action.parallel ? [`parallel: invoke ${skillPhrase(action.parallel)}`] : []),
210
+ ...(action.reopened || []).map((l) => `re-opened: ${actionLine({ ...l, epicId: id }, { solo, bindings: view, verified })}`),
211
+ // In Build, any other Shape step not yet passed (a test-cases review still in review, say) is what
212
+ // keeps the epic open, so it is named too — the Build line alone would read "every lane shipped".
213
+ ...(action.kind === 'build' ? (Array.isArray(ledger?.state?.steps) ? ledger.state.steps : [])
214
+ .filter((s) => s && typeof s.id === 'string' && !isPassed(s) && !named.has(s.id))
215
+ .map((s) => `open: ${s.id} (${stepStatus(s) ?? (typeof s.status === 'string' ? s.status : 'no status')})`) : []),
216
+ ];
217
+ epics.push({ epic: id, product: PRODUCT_EPICS.includes(id), kind: action.kind, step: action.step ?? null, status: action.status ?? null,
218
+ next: stripAnsi([actionLine(action, { solo, bindings: view, verified }), ...also].join(' · ')) });
219
+ }
220
+ const here = hereOf(root, cwd, ledgers, views);
221
+ const prs = fetch ? prsOf(root, { env, runner }) : { asked: false };
222
+ for (const f of prs.followUps || []) owed.push({ kind: 'follow-up-pr', repo: f.repo, platform: f.platform, number: f.number, task: f.task });
223
+ return { setUp: true, here, epics, finished: finishedCount, prs, owed };
224
+ }
225
+
226
+ // The view as lines, each section held to its budget.
227
+ export function briefLines(m) {
228
+ if (!m.setUp) return ['Project not set up yet — run yad setup'];
229
+ const out = [];
230
+ const more = (n, where) => (n > 0 ? [` … +${n} more — ${where}`] : []);
231
+ const h = m.here;
232
+ if (h.task) {
233
+ // A blocked step names what it waits on, not a skill to run (#349).
234
+ const at = h.step ? `${h.step} (${h.status})${h.reason ? ` — blocked: ${safe(h.reason)}` : h.skill ? ` — next: ${h.skill}` : ''}`
235
+ : h.shipped ? 'every step done' : safe(h.why);
236
+ out.push(`here: ${h.story} ${h.task}${h.followUp ? ' follow-up' : ''}${h.repo ? ` in ${safe(h.repo)}` : ''} — ${at}`);
237
+ } else out.push(`here: ${h.branch ? `${safe(h.branch)}, ` : ''}${safe(h.why)}`);
238
+ out.push(`epics: ${m.epics.length} open${m.finished ? `, ${m.finished} finished (not shown)` : ''}`);
239
+ for (const e of m.epics.slice(0, BUDGET.epics)) {
240
+ out.push(e.problem ? ` ${e.epic} — ${e.problem}` : ` ${e.epic} ${e.step ?? '—'}${e.status && e.status !== e.step ? ` (${e.status})` : ''} — next: ${e.next}`);
241
+ }
242
+ out.push(...more(m.epics.length - BUDGET.epics, 'yad next --all'));
243
+ const p = m.prs;
244
+ if (!p.asked) out.push('open PRs/MRs: not asked (--no-fetch)');
245
+ else {
246
+ if (p.whose === 'none') out.push('open PRs/MRs: unknown — no repo could be read');
247
+ else out.push(`open PRs/MRs (${p.whose}): ${p.listed.length}${p.whose === 'yours' && p.others ? ` — ${p.others} by others` : ''}${p.whose === 'all' ? ' — who you are on the platform is not known, so every open one is listed' : ''}`);
248
+ for (const x of p.listed.slice(0, BUDGET.prs)) {
249
+ const facts = [x.draft ? 'draft' : null, x.checks ? `checks ${x.checks}` : null, x.review ? `review ${x.review}` : null].filter(Boolean);
250
+ out.push(` ${safe(x.repo)} ${prWord(x.platform)}${x.number}${x.task ? ` ${x.task}` : ''}${facts.length ? ` — ${facts.join(', ')}` : ''}`);
251
+ }
252
+ out.push(...more(p.listed.length - BUDGET.prs, 'yad standup'));
253
+ // Only one page of open PRs/MRs is read per repo: the counts above are then too low, and say so.
254
+ if (p.partial.length) out.push(` more open PRs/MRs than one page holds in ${p.partial.map(safe).join(', ')} — only the newest were read`);
255
+ // One line for every repo not read, so a team with many repos offline does not fill the view.
256
+ if (p.notRead.length) out.push(` platform not read for ${p.notRead.map((n) => safe(n.label)).join(', ')} — PR/MR facts there are unknown, not none`);
257
+ }
258
+ out.push(`owed: ${m.owed.length ? m.owed.length : 'nothing'}`);
259
+ for (const o of m.owed.slice(0, BUDGET.owed)) out.push(` ${owedLine(o)}`);
260
+ out.push(...more(m.owed.length - BUDGET.owed, 'yad next --all, yad reconcile check, yad standup'));
261
+ // Every line is made safe at the end, in one place: values from shared files and from the platform (a
262
+ // branch name, a record's author, a skill name) reach the terminal only as plain text.
263
+ return out.map(forTerminal);
264
+ }
265
+
266
+ function owedLine(o) {
267
+ if (o.kind === 'debt') return `${o.epic}: ${o.step.replace(/-review$/, '')} owed as debt (${o.status})${o.reason ? ` — ${safe(o.reason)}` : ''}`;
268
+ if (o.kind === 'blocked') return `${o.epic}${o.story ? ` ${o.story} in ${safe(o.repo)}` : ''}: ${o.step} blocked${o.reason ? ` — ${safe(o.reason)}` : ''}`;
269
+ if (o.kind === 'hotfix-debt') return `${o.epic}: ${o.count} open hotfix debt — yad reconcile check`;
270
+ if (o.kind === 'unapproved-change') return `${o.epic}: ${safe(o.step)} is done, but ${safe(o.artifact)} changed after it was approved — ${safe(o.fix)}`;
271
+ return `${safe(o.repo)} ${prWord(o.platform)}${o.number}: open follow-up of ${o.task}`;
272
+ }
273
+
274
+ export async function runStatus(root, { cwd = root, json = false, fetch = true, env = process.env, runner } = {}) {
275
+ const m = buildStatus(root, { cwd, fetch, env, runner });
276
+ if (json) return m;
277
+ log('');
278
+ for (const line of briefLines(m)) log(` ${line}`);
279
+ if (m.setUp) info(c.dim('detail: yad next <epic> · yad standup · yad doctor'));
280
+ else hand(`run ${c.bold('yad setup')}`);
281
+ return undefined;
282
+ }