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.
- package/CHANGELOG.md +206 -0
- package/README.md +4 -1
- package/bin/commands.mjs +5 -1
- package/bin/yad.mjs +174 -18
- 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 +396 -123
- 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 +442 -33
- 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/lib.mjs +12 -1
- package/cli/lifecycle/defaults/1.json +96 -0
- package/cli/lifecycle/lifecycle.schema.json +121 -0
- package/cli/lifecycle.mjs +695 -0
- package/cli/next.mjs +34 -11
- package/cli/openpr.mjs +81 -5
- package/cli/platform.mjs +21 -0
- package/cli/pr-list.mjs +49 -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 +384 -0
- 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 +50 -3
- 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 +4 -3
- package/skills/sdlc/config.yaml +28 -20
- package/skills/sdlc/module-help.csv +1 -1
- package/skills/yad-backfill/references/backfill.md +8 -1
- package/skills/yad-backfill/templates/checks/backfill-check.sh +54 -6
- package/skills/yad-change/SKILL.md +3 -0
- package/skills/yad-checks/SKILL.md +47 -5
- package/skills/yad-checks/references/check-gates.md +124 -12
- 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 +354 -48
- 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 +83 -20
- 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 +29 -5
- package/skills/yad-product-bridge/templates/gitlab/yad-gate-sync.gitlab-ci.yml +9 -4
- package/skills/yad-reconcile/SKILL.md +30 -0
- package/skills/yad-review-gate/SKILL.md +8 -2
- 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 +142 -17
- package/skills/yad-spec/references/spec-handoff.md +68 -5
- package/skills/yad-status/SKILL.md +7 -0
- package/skills/yad-stories/references/story-schema.md +1 -1
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
// Issue #365 — merged work the Product's build ledger does not record. When task MRs merge in the code
|
|
2
|
+
// repos, nothing writes the build-log ship or the story's `status: shipped` on its own (the
|
|
3
|
+
// yad-engineer-review skill does, by hand), and `yad reconcile check` could not see the gap. This reads
|
|
4
|
+
// what merged and compares it with the ledger. READ-ONLY: it reports, with the command that fixes each
|
|
5
|
+
// line where one exists; it never writes a ship (that is #346).
|
|
6
|
+
//
|
|
7
|
+
// What counts as merged, per repo the Product registers (.sdlc/repos.json):
|
|
8
|
+
// - on the repo's default branch, in its clone here (as the clone last saw it — nothing is fetched): a
|
|
9
|
+
// `Task: EP-<slug>-S<n>-T<n>` trailer, a merge commit naming a task branch, or a full task ID in a
|
|
10
|
+
// commit subject (a squash commit titled with its task) — the full ID only (the user's decision);
|
|
11
|
+
// - a PR/MR merged INTO the default branch whose source branch names a task (`feat/EP-x-S01-T01-…`),
|
|
12
|
+
// when the platform answers: a GitLab squash keeps only the MR title, so the branch is where a
|
|
13
|
+
// squashed task still shows (the user's decision, 2026-10-18).
|
|
14
|
+
// A full STORY ID in a subject, or a short scope tag such as `feat(s06):`, is only a POSSIBLE match: listed
|
|
15
|
+
// to check by hand, never counted (2026-10-17). A story ID only in a commit body is not evidence.
|
|
16
|
+
//
|
|
17
|
+
// git runs only in a repo `judgeRepo` finds present — the guard `yad doctor` and `yad repo clone` use: a
|
|
18
|
+
// committed folder shaped like a bare repo would have git read its config, and a path outside the
|
|
19
|
+
// workspace is not this Product's to read (review 1). Facts only: a SHA, a PR/MR number and an ID — never
|
|
20
|
+
// a subject, a body or a branch name. Never an all-clear over what was not read (review 2): a repo, a
|
|
21
|
+
// registry, a ledger or a story that could not be read or compared is said and counted as unknown.
|
|
22
|
+
import fs from 'node:fs';
|
|
23
|
+
import path from 'node:path';
|
|
24
|
+
import { spawnSync } from 'node:child_process';
|
|
25
|
+
import { readJSONStrict, exists, forTerminal, asArg } from './lib.mjs';
|
|
26
|
+
import { PROJECT_FILES, TASK_ID_RE, TASK_TRAILER } from './manifest.mjs';
|
|
27
|
+
import { taskFromBranch } from './commit.mjs';
|
|
28
|
+
import { epicIds, epicRoot, readFrontmatter, declaredRepos } from './epic-state.mjs';
|
|
29
|
+
import { readShips } from './ledger.mjs';
|
|
30
|
+
import { listMergedBranches } from './pr-list.mjs';
|
|
31
|
+
import { judgeRepo } from './workspace.mjs';
|
|
32
|
+
import { hostFromGitUrl, plainHost } from './platform.mjs';
|
|
33
|
+
import { repoPathFromGitUrl } from './protection.mjs';
|
|
34
|
+
|
|
35
|
+
const STORY_IN_TEXT = /\bEP-[a-z0-9-]+-S\d+\b(?!-T\d)/g;
|
|
36
|
+
const TASK_IN_TEXT = /\bEP-[a-z0-9-]+-S\d+-T\d+\b/g;
|
|
37
|
+
const SHORT_TAG = /^[a-z]+\(\s*(s\d+)\s*\)!?:/i;
|
|
38
|
+
const SHA = /^[0-9a-f]{7,64}$/;
|
|
39
|
+
// A branch NAME, never revision syntax: `main~1`, `main@{1}`, `HEAD` or a leading `-` would read another
|
|
40
|
+
// commit than the branch's tip, and hide what merged (review 3).
|
|
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
|
+
}
|
|
53
|
+
const storyOf = (task) => task.replace(/-T\d+$/, '');
|
|
54
|
+
const shaOf = (v) => (typeof v === 'string' && SHA.test(v.toLowerCase()) ? v.toLowerCase() : null);
|
|
55
|
+
|
|
56
|
+
// git, raw: `run()` trims its output, and these records are split on NUL and unit separators. Signatures
|
|
57
|
+
// are never checked (`log.showSignature` in a repo's config runs a program of its choosing), and a partial
|
|
58
|
+
// clone never fetches a missing object on git 2.44+ (review 2): "nothing is fetched".
|
|
59
|
+
const git = (cwd, args) => {
|
|
60
|
+
// TZ=UTC: commit dates read as the UTC day, as ship dates and the platform's are (review 4).
|
|
61
|
+
const r = spawnSync('git', ['-c', 'log.showSignature=false', ...args], { cwd, encoding: 'utf8', maxBuffer: 1 << 28, env: { ...process.env, GIT_NO_LAZY_FETCH: '1', TZ: 'UTC' } });
|
|
62
|
+
return { ok: r.status === 0, status: r.status, out: r.stdout || '' };
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// The default branch of one clone: origin's copy when the clone has one, else the local branch — named as
|
|
66
|
+
// a full ref, so no tag or other name of the same spelling is read instead. `{ ref (shown), full }`.
|
|
67
|
+
function defaultRef(dir, branch) {
|
|
68
|
+
if (!BRANCH.test(branch)) return null;
|
|
69
|
+
for (const [ref, full] of [[`origin/${branch}`, `refs/remotes/origin/${branch}`], [branch, `refs/heads/${branch}`]]) {
|
|
70
|
+
if (git(dir, ['rev-parse', '--verify', '--quiet', '--end-of-options', `${full}^{commit}`]).ok) return { ref, full };
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// The branches a merge commit's subject says it brought in — never the "into …" part: GitLab's "Merge
|
|
76
|
+
// branch 'X' into 'main'", a local merge of a remote-tracking branch, an octopus "Merge branches 'a' and
|
|
77
|
+
// 'b'", GitHub's "Merge pull request #N from owner/X".
|
|
78
|
+
function mergedBranches(subject) {
|
|
79
|
+
const gh = subject.match(/^Merge pull request #\d+ from [^/\s]+\/(\S+)/);
|
|
80
|
+
if (gh) return [gh[1]];
|
|
81
|
+
const head = subject.match(/^Merge (?:remote-tracking )?branch(?:es)? ((?:'[^']+'(?:,\s*|\s+and\s+)?)+)/);
|
|
82
|
+
return head ? [...head[1].matchAll(/'(?:origin\/)?([^']+)'/g)].map((m) => m[1]) : [];
|
|
83
|
+
}
|
|
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
|
+
|
|
112
|
+
// The commits of one `git log`, as { sha, date, parents, subject, trailers } — or null when git could not
|
|
113
|
+
// read them. `skipped` counts a record that cannot be read safely (a 0x1f in a subject or trailer makes
|
|
114
|
+
// more fields).
|
|
115
|
+
function logRecords(dir, args, counter) {
|
|
116
|
+
const log = git(dir, ['log', '--no-show-signature', '-z', '--date=format-local:%Y-%m-%d', `--format=%H%x1f%cd%x1f%P%x1f%s%x1f%(trailers:key=${TASK_TRAILER},valueonly,separator=%x1e)`, ...args]);
|
|
117
|
+
if (!log.ok) return null;
|
|
118
|
+
const out = [];
|
|
119
|
+
for (const rec of log.out.split('\0')) {
|
|
120
|
+
if (!rec.trim()) continue;
|
|
121
|
+
const fields = rec.replace(/^\n/, '').split('\x1f');
|
|
122
|
+
if (fields.length !== 5 || !/^[0-9a-f]{40,64}$/.test(fields[0])) { counter.skipped++; continue; }
|
|
123
|
+
out.push({ sha: fields[0], date: fields[1], parents: fields[2].split(' ').filter(Boolean), subject: fields[3], trailers: fields[4] });
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// One repo's merged work, read from its clone. `{ read: true, ref, sha, dir, shared, tasks: Map(task ->
|
|
129
|
+
// evidence), possible, skipped, mergesUnread? }` (`mergesUnread`: a folder, whose merge titles are not read) or `{ read: false, why }` — a repo that cannot be read says so, and is
|
|
130
|
+
// never "nothing merged".
|
|
131
|
+
export function readRepoMerges(root, repo) {
|
|
132
|
+
const judged = judgeRepo(root, repo);
|
|
133
|
+
if (judged.state === 'missing') return { read: false, why: 'not cloned here (`yad repo clone`)' };
|
|
134
|
+
// `path: "."` — the Product's own checkout IS the code repo (a supported monorepo layout, review 2). Only
|
|
135
|
+
// when the Product folder holds its own `.git`: otherwise git would walk up into whatever repo encloses
|
|
136
|
+
// it (review 3).
|
|
137
|
+
if (judged.state === 'product' && !exists(path.join(root, '.git'))) return { read: false, why: 'the Product folder is not a git checkout of its own' };
|
|
138
|
+
if (judged.state !== 'present' && judged.state !== 'product') return { read: false, why: judged.reason };
|
|
139
|
+
if (judged.linked) return { read: false, why: 'it is reached through a link inside a repo, so git would read somewhere else' };
|
|
140
|
+
const dir = judged.state === 'product' ? path.resolve(root) : judged.target;
|
|
141
|
+
const branch = typeof repo.default_branch === 'string' ? repo.default_branch : '';
|
|
142
|
+
if (branch && !BRANCH.test(branch)) return { read: false, why: 'its default_branch in repos.json is not a branch name' };
|
|
143
|
+
const found = defaultRef(dir, branch);
|
|
144
|
+
const ref = found?.ref;
|
|
145
|
+
if (!found) return { read: false, why: branch ? `no branch ${forTerminal(branch)} in the clone` : 'no default_branch in repos.json' };
|
|
146
|
+
// A shallow clone holds only its newest commits: what merged before its edge is not there, and reading it
|
|
147
|
+
// would be an all-clear over history it does not have (review 5). Said, not read.
|
|
148
|
+
const shallow = git(dir, ['rev-parse', '--is-shallow-repository']);
|
|
149
|
+
if (!shallow.ok || shallow.out.trim() !== 'false') return { read: false, why: shallow.ok ? 'a shallow clone — run `git fetch --unshallow` in it, then run again' : 'git could not tell whether it is a shallow clone' };
|
|
150
|
+
// A repo folder inside a shared checkout (the monorepo layout) reads only its own folder's NON-MERGE
|
|
151
|
+
// commits: their `Task:` trailers and task IDs in their subjects (what `yad commit` writes). The whole
|
|
152
|
+
// history would credit every other folder's tasks to it (review 1); a merge commit cannot be told to
|
|
153
|
+
// belong to one folder without edge cases that kept turning up — shallow edges, criss-cross merges, a
|
|
154
|
+
// stacked branch carrying another task's work — so a merge's title is not read for a folder (the user's
|
|
155
|
+
// decision, 2026-10-19, review 5), and the output says so. The folder is named as it is on disk (its true
|
|
156
|
+
// letter case) and matched literally (review 2).
|
|
157
|
+
let only = null;
|
|
158
|
+
if (judged.inside) {
|
|
159
|
+
try { only = path.relative(fs.realpathSync.native(judged.inside), fs.realpathSync.native(dir)).split(path.sep).join('/'); } catch { return { read: false, why: 'its folder could not be resolved' }; }
|
|
160
|
+
}
|
|
161
|
+
const counter = { skipped: 0 };
|
|
162
|
+
const spec = only ? ['--', `:(top,literal)${only}`] : ['--'];
|
|
163
|
+
const records = logRecords(dir, [...(only ? ['--no-merges'] : []), '--end-of-options', found.full, ...spec], counter);
|
|
164
|
+
if (!records) return { read: false, why: `git could not read ${forTerminal(ref)}` };
|
|
165
|
+
const tasks = new Map();
|
|
166
|
+
const possible = [];
|
|
167
|
+
const add = (task, ev) => { if (!tasks.has(task)) tasks.set(task, ev); };
|
|
168
|
+
// The Product's own checkpoint commits name a story in their subject; they are yad's records, not merged
|
|
169
|
+
// work (review 3).
|
|
170
|
+
const ownRecord = (subject) => judged.state === 'product' && /^chore\(product\):/.test(subject);
|
|
171
|
+
for (const { sha, date, parents, subject, trailers } of records) {
|
|
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;
|
|
175
|
+
if (hadTask || ownRecord(subject)) continue;
|
|
176
|
+
for (const id of subject.match(STORY_IN_TEXT) || []) possible.push({ sha, story: id, via: 'story ID in the subject' });
|
|
177
|
+
const tag = subject.match(SHORT_TAG);
|
|
178
|
+
// `s06` and `s6` name the same story number; stories are keyed by the number itself.
|
|
179
|
+
if (tag) possible.push({ sha, tag: `s${Number(tag[1].slice(1))}`, via: `short tag ${tag[1].toLowerCase()}` });
|
|
180
|
+
}
|
|
181
|
+
const sha = git(dir, ['rev-parse', '--verify', '--quiet', '--end-of-options', found.full]).out.trim();
|
|
182
|
+
return { read: true, ref, sha, dir, shared: !!only, tasks, possible, skipped: counter.skipped, ...(only ? { mergesUnread: true } : {}) };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// The task branches merged INTO the default branch that the platform knows of, when it answers. Adds to
|
|
186
|
+
// `tasks`, never replaces a commit already found. Returns `{ note, partial }`: turned off on purpose, or no
|
|
187
|
+
// platform to ask, is a note; a platform that should have answered and did not is partial. A full page is
|
|
188
|
+
// a note only: local git sees every merge but a squash, and a busy repo would otherwise never read in full.
|
|
189
|
+
function addPlatformMerges(repo, merges, { runner, env, authCache }) {
|
|
190
|
+
const t = { platform: repo.platform || null, gitUrl: repo.git_url || '' };
|
|
191
|
+
const r = listMergedBranches(t, { base: repo.default_branch, ...(runner ? { runner } : {}), env, authCache });
|
|
192
|
+
if (!r.ok) {
|
|
193
|
+
const deliberate = ['off', 'no-platform', 'no-url'].includes(r.kind);
|
|
194
|
+
const how = ['no-cli', 'no-login'].includes(r.kind) ? ' — install and log in to read squash-merged tasks, or set YAD_PLATFORM_READ=0 to read git only' : '';
|
|
195
|
+
return { note: `platform not read — ${r.why}${how}`, partial: !deliberate };
|
|
196
|
+
}
|
|
197
|
+
for (const m of r.merged) {
|
|
198
|
+
const task = m.branch ? taskFromBranch(m.branch) : null;
|
|
199
|
+
if (task && TASK_ID_RE.test(task) && !merges.tasks.has(task)) merges.tasks.set(task, { sha: m.commit, pr: m.number, date: m.date, via: 'merged branch' });
|
|
200
|
+
}
|
|
201
|
+
return { note: r.partial ? 'the platform listed only its 100 most recently updated merged PRs/MRs — an older squash merge may be missing' : null, partial: false };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Does a retroactive ship stand for this merged task? It covers what merged up to it: a task commit its
|
|
205
|
+
// merge commit holds, else one dated on or before it. Only a hex SHA that resolves to a commit here is
|
|
206
|
+
// asked about — `main` or `:/text` would cover everything (review 2); one this clone lacks falls back to the
|
|
207
|
+
// date. A retro ship with neither a commit nor a date recorded stands for the whole story here, as before;
|
|
208
|
+
// one whose recorded commit cannot be checked and has no date covers nothing it cannot prove (review 3).
|
|
209
|
+
function retroCovers(retro, ev, dir) {
|
|
210
|
+
const recorded = shaOf(retro.mergeCommit);
|
|
211
|
+
const mc = recorded && dir && git(dir, ['rev-parse', '--verify', '--quiet', '--end-of-options', `${recorded}^{commit}`]).ok ? recorded : null;
|
|
212
|
+
const evSha = shaOf(ev.sha);
|
|
213
|
+
if (mc && evSha) {
|
|
214
|
+
const r = git(dir, ['merge-base', '--is-ancestor', '--end-of-options', evSha, mc]);
|
|
215
|
+
if (r.status === 0) return true;
|
|
216
|
+
if (r.status === 1) return false;
|
|
217
|
+
// anything else (an object this clone lacks): fall back to the date
|
|
218
|
+
}
|
|
219
|
+
const shipped = typeof retro.shippedAt === 'string' ? retro.shippedAt.slice(0, 10) : null;
|
|
220
|
+
if (shipped && ev.date) return ev.date <= shipped;
|
|
221
|
+
return !retro.mergeCommit && !shipped;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// The platform repo a registry entry names, the same however its URL is spelled (review 3).
|
|
225
|
+
const platformKey = (url) => {
|
|
226
|
+
const host = plainHost(hostFromGitUrl(url || ''));
|
|
227
|
+
const repo = repoPathFromGitUrl(url || '');
|
|
228
|
+
return host && repo ? `${host}/${repo}`.toLowerCase().replace(/\.git$/, '') : null;
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
// The whole comparison. `epics` (a Set) limits it to those epics, and then only the repos their stories
|
|
232
|
+
// name are read. Returns { repos, unreadEpics, uncompared, registry, findings }:
|
|
233
|
+
// repos: [{ repo, read, why? | ref, sha, note?, partial? }]
|
|
234
|
+
// uncompared: stories that name no repo, when the registry holds more than one — they cannot be compared
|
|
235
|
+
// registry: null when it was read; else why it was not (the file does not parse, or an entry is not one)
|
|
236
|
+
// finding.kind 'merged-no-ship' { epic, story, task, repo, sha, pr, via, fix } — counted
|
|
237
|
+
// 'looks-shipped' { epic, story, status, repos } — a hint
|
|
238
|
+
// 'possible' { repo, sha, token, via, stories } — check by hand
|
|
239
|
+
// 'no-story' { repo, sha, task, epic } — a task naming a story no file holds
|
|
240
|
+
export function shipDrift(root, { platform = true, epics = null, runner, env = process.env, authCache = new Map() } = {}) {
|
|
241
|
+
// The registry first: a story that names no repo takes the one repo the Product registers, as
|
|
242
|
+
// `yad checkpoint --retro-ship` does. A file that does not parse is not "no repos" (review 2).
|
|
243
|
+
let registry = null;
|
|
244
|
+
let entries = [];
|
|
245
|
+
try {
|
|
246
|
+
const reg = readJSONStrict(path.join(root, PROJECT_FILES.reposRegistry), { repos: [] });
|
|
247
|
+
entries = Array.isArray(reg?.repos) ? reg.repos : null;
|
|
248
|
+
if (!entries) { registry = 'its `repos` is not a list'; entries = []; }
|
|
249
|
+
} catch { registry = 'it does not parse'; }
|
|
250
|
+
const usable = entries.filter((r) => r && typeof r === 'object' && typeof r.name === 'string' && r.name);
|
|
251
|
+
if (!registry && usable.length !== entries.length) registry = `${entries.length - usable.length} entry(ies) are not a repo with a name`;
|
|
252
|
+
|
|
253
|
+
const stories = [];
|
|
254
|
+
const unreadEpics = [];
|
|
255
|
+
const uncompared = [];
|
|
256
|
+
const knownEpics = new Set();
|
|
257
|
+
const knownIds = new Set();
|
|
258
|
+
for (const epic of epicIds(root)) {
|
|
259
|
+
knownEpics.add(epic);
|
|
260
|
+
if (epics && !epics.has(epic)) continue;
|
|
261
|
+
const dir = path.join(epicRoot(root, epic), 'stories');
|
|
262
|
+
if (!exists(dir)) continue;
|
|
263
|
+
const idOk = (x) => new RegExp(`^${epic}-S\\d+$`).test(x);
|
|
264
|
+
const files = fs.readdirSync(dir).filter((x) => x.endsWith('.md')).sort().map((f) => {
|
|
265
|
+
const fm = readFrontmatter(path.join(dir, f));
|
|
266
|
+
const fileId = f.replace(/\.md$/, '');
|
|
267
|
+
// An `id:` that is not this epic's story ID (a typo) falls back to the file's name (review 4).
|
|
268
|
+
const story = typeof fm.id === 'string' && idOk(fm.id) ? fm.id : fileId;
|
|
269
|
+
return { fm, fileId, story };
|
|
270
|
+
}).filter((x) => idOk(x.story));
|
|
271
|
+
// Two files claiming one story ID (an `id:` copied by hand): each falls back to its own file name; a
|
|
272
|
+
// clash that remains is not compared, and is said (review 5).
|
|
273
|
+
const claims = new Map();
|
|
274
|
+
for (const x of files) claims.set(x.story, (claims.get(x.story) || 0) + 1);
|
|
275
|
+
for (const x of files) if (claims.get(x.story) > 1 && idOk(x.fileId)) x.story = x.fileId;
|
|
276
|
+
const seenIds = new Map();
|
|
277
|
+
for (const x of files) seenIds.set(x.story, (seenIds.get(x.story) || 0) + 1);
|
|
278
|
+
// Its story IDs are known even when its ledger is not: a merged task of it is never "no such story".
|
|
279
|
+
for (const x of files) knownIds.add(x.story);
|
|
280
|
+
let ships;
|
|
281
|
+
try { ships = readShips(epicRoot(root, epic)); } catch { unreadEpics.push(epic); continue; }
|
|
282
|
+
for (const { fm, fileId, story } of files) {
|
|
283
|
+
if (seenIds.get(story) > 1) { if (!uncompared.includes(story)) uncompared.push(story); continue; }
|
|
284
|
+
let repos = declaredRepos(fm);
|
|
285
|
+
let fallback = false;
|
|
286
|
+
// A story that names no repo was never compared (review 3): with one registered repo it is that one;
|
|
287
|
+
// with more it cannot be told, and is said.
|
|
288
|
+
if (!repos.length) {
|
|
289
|
+
if (usable.length === 1) { repos = [usable[0].name]; fallback = true; } else { uncompared.push(story); continue; }
|
|
290
|
+
}
|
|
291
|
+
stories.push({ epic, story, sameFile: story === fileId, fallback, status: typeof fm.status === 'string' ? fm.status : '', repos, ships: ships.filter((s) => s.story === story) });
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const wanted = new Set(stories.flatMap((s) => s.repos));
|
|
296
|
+
const repos = usable.filter((r) => !epics || wanted.has(r.name));
|
|
297
|
+
// The same platform repo under two names (monorepo folders share their checkout's `origin`), however its
|
|
298
|
+
// URL is spelled: its merged branches cannot be told apart by name, so it is not asked for any of them.
|
|
299
|
+
const keyCount = new Map();
|
|
300
|
+
// From the whole registry, so a `--thread` run asks exactly what a full run does (review 4).
|
|
301
|
+
for (const r of usable) { const k = platformKey(r.git_url); if (k) keyCount.set(k, (keyCount.get(k) || 0) + 1); }
|
|
302
|
+
const read = new Map();
|
|
303
|
+
const reposOut = [];
|
|
304
|
+
for (const repo of repos) {
|
|
305
|
+
if (read.has(repo.name)) continue; // a name registered twice is read once
|
|
306
|
+
const m = readRepoMerges(root, repo);
|
|
307
|
+
let pl = { note: null, partial: false };
|
|
308
|
+
if (m.read && platform) {
|
|
309
|
+
const k = platformKey(repo.git_url);
|
|
310
|
+
pl = m.shared || (k && keyCount.get(k) > 1)
|
|
311
|
+
? { note: 'platform not asked — another registered repo shares this one, so a squash-merged task that shows only in its branch name is not seen here', partial: false }
|
|
312
|
+
: addPlatformMerges(repo, m, { runner, env, authCache });
|
|
313
|
+
}
|
|
314
|
+
const partial = pl.partial || (m.read && m.skipped > 0);
|
|
315
|
+
const notes = [pl.note, m.read && m.skipped ? `${m.skipped} commit(s) could not be read` : null,
|
|
316
|
+
m.mergesUnread ? 'merge-commit titles are not read for a folder in a shared checkout — a task seen only in one is not found' : null].filter(Boolean);
|
|
317
|
+
read.set(repo.name, m);
|
|
318
|
+
reposOut.push({ repo: repo.name, read: m.read, ...(m.read ? { ref: m.ref, sha: m.sha } : { why: m.why }), ...(notes.length ? { note: notes.join('; ') } : {}), ...(partial ? { partial: true } : {}) });
|
|
319
|
+
}
|
|
320
|
+
// A repo a story names that the registry does not hold is not read either — said, not assumed empty.
|
|
321
|
+
for (const name of [...wanted].sort()) {
|
|
322
|
+
if (!read.has(name)) reposOut.push({ repo: name, read: false, why: registry ? 'repos.json could not be read' : 'a story names it, but it is not in repos.json' });
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const findings = [];
|
|
326
|
+
for (const s of stories) {
|
|
327
|
+
let everyRepoHasWork = s.repos.length > 0;
|
|
328
|
+
for (const repoName of s.repos) {
|
|
329
|
+
const m = read.get(repoName);
|
|
330
|
+
const recorded = s.ships.filter((x) => x.repo === repoName);
|
|
331
|
+
const retros = recorded.filter((x) => x.retroactive);
|
|
332
|
+
const merged = m?.read ? [...m.tasks].filter(([task]) => storyOf(task) === s.story) : [];
|
|
333
|
+
if (!recorded.length && !merged.length) everyRepoHasWork = false;
|
|
334
|
+
let suggested = false;
|
|
335
|
+
for (const [task, ev] of merged) {
|
|
336
|
+
const t = task.slice(s.story.length + 1);
|
|
337
|
+
// A hand-written ship may hold the full ID as its task (review 3).
|
|
338
|
+
if (recorded.some((x) => x.task === t || x.task === task)) continue;
|
|
339
|
+
if (retros.some((x) => retroCovers(x, ev, m.dir))) continue;
|
|
340
|
+
// `yad checkpoint --retro-ship` records ONE ship per (story, repo), marked as a pre-tracking backfill,
|
|
341
|
+
// and needs the story `in-build` or `shipped` first. So it is offered once, only while (story, repo)
|
|
342
|
+
// has no ship at all and the story's file carries its ID, and only for a story that predates
|
|
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).
|
|
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` : ''}`;
|
|
352
|
+
let fix = engineer;
|
|
353
|
+
if (!recorded.length && !suggested && s.sameFile && asArg(repoName) === repoName) {
|
|
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}`;
|
|
355
|
+
suggested = true;
|
|
356
|
+
}
|
|
357
|
+
findings.push({ kind: 'merged-no-ship', epic: s.epic, story: s.story, task: t, repo: repoName, sha: evSha, pr: Number.isInteger(ev.pr) ? ev.pr : null, via: ev.via, fix });
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (everyRepoHasWork && s.status !== 'shipped') findings.push({ kind: 'looks-shipped', epic: s.epic, story: s.story, status: s.status || null, repos: s.repos, ...(s.fallback ? { fallback: true } : {}) });
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Possible matches, for stories not already shipped or recorded in that repo — a match for one that is
|
|
364
|
+
// has nothing left to check, and the list would only grow with history (review 1). A short tag names a
|
|
365
|
+
// story number, not an epic, so every such story in an epic that names the repo is a candidate.
|
|
366
|
+
const open = (repoName) => stories.filter((s) => s.repos.includes(repoName) && s.status !== 'shipped' && !s.ships.some((x) => x.repo === repoName));
|
|
367
|
+
for (const [repoName, m] of read) {
|
|
368
|
+
if (!m.read) continue;
|
|
369
|
+
const candidates = open(repoName);
|
|
370
|
+
for (const p of m.possible) {
|
|
371
|
+
const hit = candidates.filter((s) => (p.story ? s.story === p.story : `s${Number(s.story.match(/-S(\d+)$/)[1])}` === p.tag)).map((s) => s.story);
|
|
372
|
+
if (hit.length) findings.push({ kind: 'possible', repo: repoName, sha: p.sha, token: p.story || p.tag, via: p.via, stories: hit });
|
|
373
|
+
}
|
|
374
|
+
// A merged task whose story no file holds — a typo in a trailer is exactly the drift this looks for
|
|
375
|
+
// (review 3). Only for an epic that exists, and in scope.
|
|
376
|
+
for (const [task, ev] of m.tasks) {
|
|
377
|
+
const story = storyOf(task);
|
|
378
|
+
const epic = story.replace(/-S\d+$/, '');
|
|
379
|
+
if (knownIds.has(story) || !knownEpics.has(epic) || (epics && !epics.has(epic))) continue;
|
|
380
|
+
findings.push({ kind: 'no-story', repo: repoName, sha: shaOf(ev.sha), task, epic });
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return { repos: reposOut, unreadEpics, uncompared, registry, findings };
|
|
384
|
+
}
|
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 }];
|