yadflow 4.6.0 → 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.
- package/CHANGELOG.md +170 -0
- package/README.md +4 -1
- package/bin/commands.mjs +5 -1
- package/bin/yad.mjs +167 -15
- package/cli/artifact-status.mjs +88 -20
- package/cli/build.mjs +1372 -0
- package/cli/checkpoint.mjs +2 -2
- package/cli/commit.mjs +1 -0
- package/cli/dial.mjs +21 -1
- package/cli/docs.mjs +6 -1
- package/cli/doctor.mjs +133 -26
- package/cli/epic-state.mjs +357 -9
- package/cli/errors.mjs +2 -0
- package/cli/find-product.mjs +36 -2
- package/cli/fold.mjs +9 -5
- package/cli/gate-local.mjs +9 -1
- package/cli/gate.mjs +364 -22
- package/cli/history.mjs +22 -2
- package/cli/hook.mjs +3 -1
- package/cli/index-command.mjs +2 -2
- package/cli/ledger.mjs +60 -0
- package/cli/next.mjs +34 -11
- package/cli/openpr.mjs +81 -5
- package/cli/platform.mjs +21 -0
- package/cli/pr-list.mjs +5 -3
- package/cli/product-index.mjs +6 -3
- package/cli/product-token.mjs +186 -0
- package/cli/productcommit.mjs +33 -0
- package/cli/recommend.mjs +3 -1
- package/cli/repo-publish.mjs +2 -2
- package/cli/run-checks.mjs +586 -0
- package/cli/ship-drift.mjs +49 -18
- package/cli/standup.mjs +1 -1
- package/cli/status.mjs +282 -0
- package/cli/test-build.mjs +1559 -0
- package/cli/test-run-checks.mjs +603 -0
- package/cli/test-worktree.mjs +520 -0
- package/cli/thread.mjs +4 -0
- package/cli/tidy.mjs +2 -2
- package/cli/toolbox.mjs +36 -5
- package/cli/workspace.mjs +4 -1
- package/cli/worktree-record.mjs +53 -0
- package/cli/worktree.mjs +379 -0
- package/package.json +3 -3
- package/skills/sdlc/config.yaml +1 -1
- package/skills/sdlc/module-help.csv +1 -1
- package/skills/yad-backfill/templates/checks/backfill-check.sh +9 -9
- package/skills/yad-change/SKILL.md +3 -0
- package/skills/yad-checks/SKILL.md +34 -5
- package/skills/yad-checks/references/check-gates.md +69 -10
- package/skills/yad-checks/templates/checks/build-test-lint.sh +22 -3
- package/skills/yad-checks/templates/checks/commit-message.sh +8 -2
- package/skills/yad-checks/templates/checks/contract-check.sh +61 -33
- package/skills/yad-checks/templates/checks/epic-open.sh +87 -14
- package/skills/yad-checks/templates/checks/ledger-guard.sh +3 -3
- package/skills/yad-checks/templates/checks/lineage-check.sh +88 -15
- package/skills/yad-checks/templates/checks/member-check.mjs +206 -35
- package/skills/yad-checks/templates/checks/package-manager.sh +41 -4
- package/skills/yad-checks/templates/checks/product-checkout.sh +161 -13
- package/skills/yad-checks/templates/checks/reconcile-debt-check.sh +94 -15
- package/skills/yad-checks/templates/checks/risk-map-check.sh +2 -2
- package/skills/yad-checks/templates/checks/spec-link.sh +63 -4
- package/skills/yad-checks/templates/checks/verified-commits.sh +23 -5
- package/skills/yad-checks/templates/github/yad-checks.yml +8 -8
- package/skills/yad-checks/templates/gitlab/.gitlab-ci.yml +3 -0
- package/skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml +4 -4
- package/skills/yad-checks/templates/gitlab/yad-product-checks.gitlab-ci.yml +16 -3
- package/skills/yad-checks/templates/gitlab/yad-update-guard.gitlab-ci.yml +5 -1
- package/skills/yad-checks/templates/gitlab/yad-verified-commits.gitlab-ci.yml +5 -1
- package/skills/yad-commit/SKILL.md +4 -2
- package/skills/yad-docs/templates/app/package-lock.json +395 -106
- package/skills/yad-docs/templates/app/package.json +2 -2
- package/skills/yad-engineer-review/SKILL.md +45 -20
- package/skills/yad-engineer-review/references/ship-and-record.md +42 -8
- package/skills/yad-epic/references/state-schema.md +75 -16
- package/skills/yad-implement/SKILL.md +75 -13
- package/skills/yad-implement/references/implement-conventions.md +8 -1
- package/skills/yad-implement/templates/.gitmessage +3 -0
- package/skills/yad-open-pr/SKILL.md +21 -0
- package/skills/yad-pr-template/SKILL.md +6 -2
- package/skills/yad-pr-template/templates/checks/pr-template.sh +85 -4
- package/skills/yad-pr-template/templates/checks/pr-title.sh +1 -1
- package/skills/yad-pr-template/templates/github/pull_request_template.md +1 -1
- package/skills/yad-pr-template/templates/gitlab/merge_request_templates/Default.md +1 -1
- package/skills/yad-product-bridge/SKILL.md +14 -1
- package/skills/yad-product-bridge/references/bridge.md +5 -2
- package/skills/yad-product-bridge/templates/gitlab/yad-gate-sync.gitlab-ci.yml +9 -4
- package/skills/yad-reconcile/SKILL.md +9 -3
- package/skills/yad-review-gate/SKILL.md +4 -0
- package/skills/yad-review-gate/references/gating.md +26 -1
- package/skills/yad-run/SKILL.md +52 -28
- package/skills/yad-run/references/run-loop.md +42 -21
- package/skills/yad-spec/SKILL.md +137 -16
- package/skills/yad-spec/references/spec-handoff.md +50 -3
- package/skills/yad-status/SKILL.md +7 -0
- package/skills/yad-stories/references/story-schema.md +1 -1
package/cli/ship-drift.mjs
CHANGED
|
@@ -39,6 +39,17 @@ const SHA = /^[0-9a-f]{7,64}$/;
|
|
|
39
39
|
// A branch NAME, never revision syntax: `main~1`, `main@{1}`, `HEAD` or a leading `-` would read another
|
|
40
40
|
// commit than the branch's tip, and hide what merged (review 3).
|
|
41
41
|
const BRANCH = /^(?!-)(?!HEAD$)(?!.*(?:\.\.|@\{|\/\/|\.lock$|\/$|\.$))[A-Za-z0-9._/-]+$/;
|
|
42
|
+
// The PR/MR a commit says it merged. `certain` for GitHub's "Merge pull request #N from …" and GitLab's
|
|
43
|
+
// "See merge request <project>!N" body line; a squash subject ending "(#N)" is only a maybe — that is also
|
|
44
|
+
// how an issue is cited.
|
|
45
|
+
export function prOfCommit(subject = '', body = '') {
|
|
46
|
+
const gh = String(subject).match(/^Merge pull request #(\d+) from /);
|
|
47
|
+
if (gh) return { pr: Number(gh[1]), certain: true };
|
|
48
|
+
const gl = String(body).match(/^See merge request \S+!(\d+)\s*$/m);
|
|
49
|
+
if (gl) return { pr: Number(gl[1]), certain: true };
|
|
50
|
+
const sq = String(subject).match(/\(#(\d+)\)\s*$/);
|
|
51
|
+
return sq ? { pr: Number(sq[1]), certain: false } : { pr: null, certain: false };
|
|
52
|
+
}
|
|
42
53
|
const storyOf = (task) => task.replace(/-T\d+$/, '');
|
|
43
54
|
const shaOf = (v) => (typeof v === 'string' && SHA.test(v.toLowerCase()) ? v.toLowerCase() : null);
|
|
44
55
|
|
|
@@ -71,6 +82,33 @@ function mergedBranches(subject) {
|
|
|
71
82
|
return head ? [...head[1].matchAll(/'(?:origin\/)?([^']+)'/g)].map((m) => m[1]) : [];
|
|
72
83
|
}
|
|
73
84
|
|
|
85
|
+
// The tasks one commit is evidence of, and how: a `Task:` trailer; a task branch a merge commit brought in;
|
|
86
|
+
// or a full task ID in the subject (a squash titled with its task, a merge titled with its pull request,
|
|
87
|
+
// review 5) — never in a "Merge branch 'x' into 'y'" subject's "into …" part (review 4), a revert's, or one
|
|
88
|
+
// of the Product's own records. A story ID only in a commit body is not evidence. ONE reader of these rules:
|
|
89
|
+
// `yad reconcile check` and `yad build ship --merge-commit` (#346) agree on what names a task.
|
|
90
|
+
export function tasksOfCommit({ parents = [], subject = '', trailers = '' }, { ownRecord = false } = {}) {
|
|
91
|
+
const out = [];
|
|
92
|
+
const add = (task, via) => { if (!out.some((x) => x.task === task)) out.push({ task, via }); };
|
|
93
|
+
for (const v of String(trailers).split('\x1e').map((x) => x.trim())) if (TASK_ID_RE.test(v)) add(v, 'trailer');
|
|
94
|
+
const brought = parents.length > 1 ? mergedBranches(subject) : [];
|
|
95
|
+
for (const b of brought) {
|
|
96
|
+
const branchTask = taskFromBranch(b);
|
|
97
|
+
if (branchTask && TASK_ID_RE.test(branchTask)) add(branchTask, 'merge commit');
|
|
98
|
+
}
|
|
99
|
+
if (!brought.length && !/^Merge (?:remote-tracking branch|branch(?:es)?|commit|tag)s? '/.test(subject) && !/^Revert\b/i.test(subject) && !ownRecord) {
|
|
100
|
+
for (const t of subject.match(TASK_IN_TEXT) || []) add(t, 'task ID in the subject');
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// One commit, read the way `yad reconcile check` reads every commit: { sha, date, parents, subject, trailers },
|
|
106
|
+
// or null.
|
|
107
|
+
export function readCommit(dir, sha) {
|
|
108
|
+
const recs = logRecords(dir, ['-1', '--end-of-options', sha, '--'], { skipped: 0 });
|
|
109
|
+
return recs?.[0] || null;
|
|
110
|
+
}
|
|
111
|
+
|
|
74
112
|
// The commits of one `git log`, as { sha, date, parents, subject, trailers } — or null when git could not
|
|
75
113
|
// read them. `skipped` counts a record that cannot be read safely (a 0x1f in a subject or trailer makes
|
|
76
114
|
// more fields).
|
|
@@ -131,22 +169,9 @@ export function readRepoMerges(root, repo) {
|
|
|
131
169
|
// work (review 3).
|
|
132
170
|
const ownRecord = (subject) => judged.state === 'product' && /^chore\(product\):/.test(subject);
|
|
133
171
|
for (const { sha, date, parents, subject, trailers } of records) {
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (TASK_ID_RE.test(v)) { add(v, { sha, date, via: 'trailer' }); hadTask = true; }
|
|
138
|
-
}
|
|
139
|
-
const brought = isMerge ? mergedBranches(subject) : [];
|
|
140
|
-
for (const b of brought) {
|
|
141
|
-
const branchTask = taskFromBranch(b);
|
|
142
|
-
if (branchTask && TASK_ID_RE.test(branchTask)) { add(branchTask, { sha, date, via: 'merge commit' }); hadTask = true; }
|
|
143
|
-
}
|
|
144
|
-
// A subject may carry a full task ID: a squash titled with its task, or a merge titled with its pull
|
|
145
|
-
// request (review 5). A "Merge branch 'x' into 'y'" subject is read only for the branches it brought
|
|
146
|
-
// in, never for an ID in its "into …" part (review 4).
|
|
147
|
-
if (!brought.length && !/^Merge (?:remote-tracking branch|branch(?:es)?|commit|tag)s? '/.test(subject) && !/^Revert\b/i.test(subject) && !ownRecord(subject)) {
|
|
148
|
-
for (const t of subject.match(TASK_IN_TEXT) || []) { add(t, { sha, date, via: 'task ID in the subject' }); hadTask = true; }
|
|
149
|
-
}
|
|
172
|
+
const found = tasksOfCommit({ parents, subject, trailers }, { ownRecord: ownRecord(subject) });
|
|
173
|
+
for (const { task, via } of found) add(task, { sha, date, via, subject });
|
|
174
|
+
const hadTask = found.length > 0;
|
|
150
175
|
if (hadTask || ownRecord(subject)) continue;
|
|
151
176
|
for (const id of subject.match(STORY_IN_TEXT) || []) possible.push({ sha, story: id, via: 'story ID in the subject' });
|
|
152
177
|
const tag = subject.match(SHORT_TAG);
|
|
@@ -315,9 +340,15 @@ export function shipDrift(root, { platform = true, epics = null, runner, env = p
|
|
|
315
340
|
// `yad checkpoint --retro-ship` records ONE ship per (story, repo), marked as a pre-tracking backfill,
|
|
316
341
|
// and needs the story `in-build` or `shipped` first. So it is offered once, only while (story, repo)
|
|
317
342
|
// has no ship at all and the story's file carries its ID, and only for a story that predates
|
|
318
|
-
// tracking; every other line
|
|
319
|
-
|
|
343
|
+
// tracking; every other line names the `yad build ship` command for it (#346): from its PR when one is
|
|
344
|
+
// known, else from the merge commit (a task merged with no PR).
|
|
320
345
|
const evSha = shaOf(ev.sha);
|
|
346
|
+
const prNo = Number.isInteger(ev.pr) ? ev.pr : null;
|
|
347
|
+
const said = prOfCommit(ev.subject || '');
|
|
348
|
+
const viaPr = prNo || (said.certain ? said.pr : null);
|
|
349
|
+
const base = `yad build ship ${s.story} --task ${t} --repo ${repoName}`;
|
|
350
|
+
const engineer = viaPr ? `record the ship with \`${base} --pr ${viaPr}\``
|
|
351
|
+
: `record the ship with \`${base} --pr <n>\` (the PR/MR that merged it)${evSha ? `, or \`${base} --merge-commit ${evSha.slice(0, 12)}\` if it merged with no PR/MR` : ''}`;
|
|
321
352
|
let fix = engineer;
|
|
322
353
|
if (!recorded.length && !suggested && s.sameFile && asArg(repoName) === repoName) {
|
|
323
354
|
fix = `if ${s.story} predates ledger tracking: yad checkpoint --retro-ship ${s.epic}/${s.story} --repo ${repoName} --task ${t}${evSha ? ` --merge-commit ${evSha.slice(0, 12)}` : ''} (the story's status must be in-build or shipped first); otherwise ${engineer}`;
|
package/cli/standup.mjs
CHANGED
|
@@ -168,7 +168,7 @@ function wipSaves(root, env, startMs) {
|
|
|
168
168
|
|
|
169
169
|
// The repos to read: the Product and every registered repo. `dir` is set only when git may run there
|
|
170
170
|
// (judged first, E81); `gitUrl` is what the platform is asked about.
|
|
171
|
-
function repoSources(root, identity, productConfig, notRead, env) {
|
|
171
|
+
export function repoSources(root, identity, productConfig, notRead, env) {
|
|
172
172
|
const productUrl = typeof productConfig?.git_url === 'string' && productConfig.git_url ? productConfig.git_url
|
|
173
173
|
: (gitIn(root, env)(['remote', 'get-url', 'origin']).out.trim() || '');
|
|
174
174
|
const out = [{ label: 'Product', dir: root, gitUrl: productUrl, platform: identity.platform }];
|
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
|
+
}
|