yadflow 4.7.0 → 4.9.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 +116 -0
- package/README.md +43 -4
- package/bin/commands.mjs +5 -1
- package/bin/yad.mjs +169 -22
- package/cli/agent-guard.mjs +511 -0
- package/cli/agent-guide.mjs +83 -0
- package/cli/agent-rules.mjs +388 -0
- package/cli/argv-flags.mjs +7 -0
- package/cli/build.mjs +1 -1
- package/cli/ci-check.mjs +492 -0
- package/cli/docs.mjs +1 -1
- package/cli/doctor.mjs +148 -7
- package/cli/epic-state.mjs +3 -3
- package/cli/errors.mjs +1 -0
- package/cli/guide.mjs +549 -0
- package/cli/hook.mjs +32 -3
- package/cli/lib.mjs +46 -0
- package/cli/lifecycle/defaults/2.json +124 -0
- package/cli/lifecycle/lifecycle.schema.json +5 -2
- package/cli/lifecycle.mjs +16 -3
- package/cli/machine.mjs +141 -0
- package/cli/manifest.mjs +75 -0
- package/cli/marked-block.mjs +48 -0
- package/cli/members.mjs +19 -5
- package/cli/migrate.mjs +17 -19
- package/cli/next.mjs +1 -1
- package/cli/openpr.mjs +46 -6
- package/cli/plan.mjs +326 -22
- package/cli/preview.mjs +253 -0
- package/cli/protection.mjs +50 -0
- package/cli/reconcile.mjs +187 -26
- package/cli/repo.mjs +64 -3
- package/cli/report.mjs +62 -14
- package/cli/review.mjs +4 -0
- package/cli/setup.mjs +244 -25
- package/cli/signing.mjs +377 -0
- package/cli/story-frames.mjs +296 -0
- package/cli/test-agents-file.mjs +993 -0
- package/cli/test-ci-check.mjs +616 -0
- package/cli/test-guide.mjs +1267 -0
- package/cli/test-machine.mjs +140 -0
- package/cli/test-node.mjs +129 -0
- package/cli/test-preview.mjs +511 -0
- package/cli/test-setup-agent.mjs +352 -0
- package/cli/test-signing.mjs +524 -0
- package/cli/test-story-frames.mjs +339 -0
- package/cli/toolbox.mjs +35 -1
- package/cli/update-commit.mjs +313 -11
- package/cli/workspace.mjs +37 -12
- package/package.json +6 -4
- package/skills/sdlc/config.yaml +4 -4
- package/skills/sdlc/module-help.csv +1 -0
- package/skills/yad-change/SKILL.md +3 -2
- package/skills/yad-checks/SKILL.md +29 -9
- package/skills/yad-checks/references/check-gates.md +9 -4
- package/skills/yad-checks/templates/checks/package-manager.sh +1 -1
- package/skills/yad-checks/templates/github/yad-checks.yml +1 -1
- package/skills/yad-checks/templates/gitlab/.gitlab-ci.yml +1 -1
- package/skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml +1 -1
- package/skills/yad-checks/templates/gitlab/yad-product-checks.gitlab-ci.yml +1 -1
- package/skills/yad-checks/templates/gitlab/yad-update-guard.gitlab-ci.yml +1 -1
- package/skills/yad-checks/templates/gitlab/yad-verified-commits.gitlab-ci.yml +1 -1
- package/skills/yad-checks/templates/hooks/agent-guard.mjs +116 -0
- package/skills/yad-commit/SKILL.md +4 -3
- package/skills/yad-connect-design/SKILL.md +7 -4
- package/skills/yad-connect-design/references/design-context.md +23 -0
- package/skills/yad-connect-design/references/design-registry.md +3 -3
- package/skills/yad-connect-repos/SKILL.md +13 -3
- package/skills/yad-connect-repos/references/code-context.md +2 -1
- package/skills/yad-connect-repos/references/repos-registry.md +2 -1
- package/skills/yad-docs-overview/references/pipeline-model.md +2 -2
- package/skills/yad-engineer-review/SKILL.md +25 -7
- package/skills/yad-engineer-review/references/ship-and-record.md +7 -4
- package/skills/yad-epic/SKILL.md +2 -1
- package/skills/yad-epic/references/state-schema.md +7 -1
- package/skills/yad-guide/SKILL.md +192 -0
- package/skills/yad-implement/SKILL.md +14 -0
- package/skills/yad-open-pr/SKILL.md +5 -2
- package/skills/yad-pair-review/SKILL.md +19 -5
- package/skills/yad-pr-template/templates/github/pull_request_template.md +1 -0
- package/skills/yad-pr-template/templates/gitlab/merge_request_templates/Default.md +1 -0
- package/skills/yad-product-bridge/SKILL.md +32 -13
- package/skills/yad-product-bridge/references/bridge.md +6 -3
- package/skills/yad-product-bridge/templates/github/yad-gate-sync.yml +2 -2
- package/skills/yad-product-bridge/templates/gitlab/yad-gate-sync.gitlab-ci.yml +1 -1
- package/skills/yad-report/SKILL.md +15 -0
- package/skills/yad-review-companion/SKILL.md +9 -4
- package/skills/yad-review-gate/SKILL.md +13 -9
- package/skills/yad-review-gate/references/gating.md +1 -1
- package/skills/yad-run/SKILL.md +10 -6
- package/skills/yad-run/references/run-loop.md +2 -1
- package/skills/yad-spec/SKILL.md +21 -0
- package/skills/yad-stories/SKILL.md +22 -0
- package/skills/yad-stories/references/story-schema.md +1 -0
- package/skills/yad-sync-repos/SKILL.md +2 -1
- package/skills/yad-ui/SKILL.md +7 -2
package/cli/preview.mjs
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
// The preview address of a PR/MR (#359): a live copy of the app that a service (Vercel, Netlify, a
|
|
2
|
+
// review app) deploys for each PR/MR, so a live design check — the page at several screen widths — can
|
|
3
|
+
// run against it instead of only on the developer's machine.
|
|
4
|
+
//
|
|
5
|
+
// Where it comes from, in order (the user's decision, 2026-11-02):
|
|
6
|
+
// 1. a per-repo pattern, `preview_url` in the Product's `.sdlc/repos.json`
|
|
7
|
+
// (`https://pr-{pr}.myapp.dev`), set with `yad repo preview`;
|
|
8
|
+
// 2. else the platform: the newest successful, non-production deployment GitHub/GitLab records for
|
|
9
|
+
// the PR's head (what Vercel/Netlify/review apps report);
|
|
10
|
+
// 3. else none — and the answer says the check runs locally only, and why.
|
|
11
|
+
//
|
|
12
|
+
// One rule (`patternProblems`) is shared by the command that writes a pattern, doctor that reads it and
|
|
13
|
+
// the resolver that fills it, so the three never disagree.
|
|
14
|
+
import { run } from './lib.mjs';
|
|
15
|
+
|
|
16
|
+
export const PREVIEW_KEY = 'preview_url';
|
|
17
|
+
export const PLACEHOLDERS = ['pr', 'branch', 'repo'];
|
|
18
|
+
const MAX_LEN = 2048;
|
|
19
|
+
|
|
20
|
+
// A name made safe for a host name or a path: lowercase, every run of other characters one `-`.
|
|
21
|
+
export const slug = (s) => String(s ?? '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
22
|
+
|
|
23
|
+
// Is this a URL yad may print and write into a PR/MR description? https, or http on this machine
|
|
24
|
+
// (a local preview server). Printable ASCII only, and none of the characters that end a Markdown link
|
|
25
|
+
// or an HTML attribute — the text comes from a shared file or a deployment service.
|
|
26
|
+
export function urlProblem(u) {
|
|
27
|
+
if (typeof u !== 'string' || !u) return 'is not a URL';
|
|
28
|
+
if (u.length > MAX_LEN) return `longer than ${MAX_LEN} characters`;
|
|
29
|
+
if (!/^[\x21-\x7e]+$/.test(u)) return 'has a space, a control character or a non-ASCII character';
|
|
30
|
+
if (/[<>"'`\\]/.test(u)) return 'has a character that is not allowed in it (< > " \' ` \\)';
|
|
31
|
+
let p;
|
|
32
|
+
try { p = new URL(u); } catch { return 'is not a URL'; }
|
|
33
|
+
if (p.username || p.password) return 'carries a user name or password';
|
|
34
|
+
if (p.protocol === 'https:') return null;
|
|
35
|
+
if (p.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(p.hostname)) return null;
|
|
36
|
+
return 'must start with https:// (or http://localhost)';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Why a pattern cannot be used, or [] when it can. The placeholders are filled with harmless sample
|
|
40
|
+
// values, so the URL check sees what a filled pattern would be.
|
|
41
|
+
export function patternProblems(p) {
|
|
42
|
+
if (typeof p !== 'string') return ['is not text'];
|
|
43
|
+
const problems = [];
|
|
44
|
+
const unknown = [...p.matchAll(/\{([^}]*)\}/g)].map((m) => m[1]).filter((n) => !PLACEHOLDERS.includes(n));
|
|
45
|
+
if (unknown.length) problems.push(`has an unknown placeholder ${[...new Set(unknown)].map((n) => `{${n}}`).join(', ')} (use {pr}, {branch} or {repo})`);
|
|
46
|
+
if (/[{}]/.test(p.replace(/\{(pr|branch|repo)\}/g, ''))) {
|
|
47
|
+
if (!unknown.length) problems.push('has a lone { or }');
|
|
48
|
+
}
|
|
49
|
+
const sample = p.replace(/\{pr\}/g, '1').replace(/\{branch\}/g, 'branch').replace(/\{repo\}/g, 'repo');
|
|
50
|
+
if (!unknown.length && !/[{}]/.test(sample)) {
|
|
51
|
+
const why = urlProblem(sample);
|
|
52
|
+
if (why) problems.push(why);
|
|
53
|
+
}
|
|
54
|
+
return problems;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// The pattern recorded for a repo entry: { pattern } when there is a usable one, { problems } when one
|
|
58
|
+
// is recorded but cannot be used, {} when none is recorded.
|
|
59
|
+
export function previewPattern(meta) {
|
|
60
|
+
if (!meta || typeof meta !== 'object' || !(PREVIEW_KEY in meta) || meta[PREVIEW_KEY] == null) return {};
|
|
61
|
+
const p = meta[PREVIEW_KEY];
|
|
62
|
+
const problems = patternProblems(p);
|
|
63
|
+
return problems.length ? { problems } : { pattern: p };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// The pattern with its placeholders filled, or null when it needs a value that is missing ({pr} before
|
|
67
|
+
// the PR exists) or the result is not a URL yad would write.
|
|
68
|
+
export function fillPattern(p, { pr, branch, repo } = {}) {
|
|
69
|
+
if (patternProblems(p).length) return null;
|
|
70
|
+
const vals = { pr: pr == null || pr === '' ? null : String(pr), branch: slug(branch) || null, repo: slug(repo) || null };
|
|
71
|
+
if (vals.pr != null && !/^\d+$/.test(vals.pr)) return null;
|
|
72
|
+
let missing = false;
|
|
73
|
+
const out = p.replace(/\{(pr|branch|repo)\}/g, (_m, k) => { if (vals[k] == null) { missing = true; return ''; } return vals[k]; });
|
|
74
|
+
if (missing) return null;
|
|
75
|
+
return urlProblem(out) ? null : out;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export const needs = (p, key) => typeof p === 'string' && p.includes(`{${key}}`);
|
|
79
|
+
|
|
80
|
+
const parse = (s) => { try { return JSON.parse(s); } catch { return undefined; } };
|
|
81
|
+
// A review must not stall on a slow or unreachable host: one budget covers every call the lookup makes
|
|
82
|
+
// (the PR's head, the deployments, their statuses), and each call gets only the time that is left.
|
|
83
|
+
// Spent, the answer is local-only, with why.
|
|
84
|
+
const PLATFORM_TIMEOUT = 8000;
|
|
85
|
+
export const PLATFORM_BUDGET = 15000;
|
|
86
|
+
const MIN_CALL = 500;
|
|
87
|
+
export function budget(now = Date.now, total = PLATFORM_BUDGET) {
|
|
88
|
+
const until = now() + total;
|
|
89
|
+
return { now, left: () => Math.min(PLATFORM_TIMEOUT, until - now()), spent: () => until - now() < MIN_CALL };
|
|
90
|
+
}
|
|
91
|
+
export const isPrNumber = (pr) => pr != null && /^\d+$/.test(String(pr));
|
|
92
|
+
const isSha = (s) => typeof s === 'string' && /^[0-9a-f]{7,64}$/i.test(s);
|
|
93
|
+
// A production environment is the live site, never a PR's preview — however the integration marked it.
|
|
94
|
+
// `production`, `prod`, and names that start with them: Vercel's `Production – app`, `production-eu`, `prod_us`.
|
|
95
|
+
const isProduction = (name) => typeof name === 'string' && /^prod(uction)?(?![a-z0-9])/i.test(name.trim());
|
|
96
|
+
|
|
97
|
+
// The newest successful, non-production deployment the platform records for the PR's head commit
|
|
98
|
+
// (GitHub) or branch (GitLab). Never throws: { url } or { url: null, why }.
|
|
99
|
+
export function platformPreview(platform, { cwd, sha, branch, pr = null, runner = run, clock = budget() } = {}) {
|
|
100
|
+
const opts = () => ({ cwd, timeout: clock.left() });
|
|
101
|
+
const slow = (host) => ({ url: null, why: `${host} was too slow to answer about deployments` });
|
|
102
|
+
if (platform === 'github') {
|
|
103
|
+
if (!isSha(sha)) return { url: null, why: 'the PR\'s head commit is not known' };
|
|
104
|
+
if (clock.spent()) return slow('GitHub');
|
|
105
|
+
const r = runner('gh', ['api', `repos/{owner}/{repo}/deployments?sha=${sha}&per_page=20`], opts());
|
|
106
|
+
if (!r.ok) return { url: null, why: 'GitHub could not be asked for deployments (gh not signed in, offline, or no GitHub remote)' };
|
|
107
|
+
const list = parse(r.stdout);
|
|
108
|
+
if (!Array.isArray(list)) return { url: null, why: 'GitHub gave an answer yad cannot read' };
|
|
109
|
+
// Newest first, as GitHub lists them.
|
|
110
|
+
const candidates = list.filter((d) => d && typeof d === 'object' && Number.isInteger(d.id)
|
|
111
|
+
&& d.production_environment !== true && !isProduction(d.environment));
|
|
112
|
+
let asked = 0, failed = 0;
|
|
113
|
+
for (const d of candidates.slice(0, 3)) {
|
|
114
|
+
if (clock.spent()) return slow('GitHub');
|
|
115
|
+
asked++;
|
|
116
|
+
const s = runner('gh', ['api', `repos/{owner}/{repo}/deployments/${d.id}/statuses?per_page=20`], opts());
|
|
117
|
+
const statuses = s.ok ? parse(s.stdout) : undefined;
|
|
118
|
+
if (!Array.isArray(statuses)) { failed++; continue; }
|
|
119
|
+
// The newest status decides (GitHub lists them newest first): not success now is not live now.
|
|
120
|
+
const latest = statuses.find((x) => x && typeof x === 'object' && typeof x.state === 'string');
|
|
121
|
+
if (!latest || latest.state !== 'success') continue;
|
|
122
|
+
const url = latest.environment_url;
|
|
123
|
+
if (!url) continue;
|
|
124
|
+
if (urlProblem(url)) return { url: null, why: 'GitHub reports a deployment address yad will not use (not https, or an odd character in it)' };
|
|
125
|
+
return { url };
|
|
126
|
+
}
|
|
127
|
+
if (asked && failed === asked) return { url: null, why: 'GitHub could not be asked for the deployments\' status' };
|
|
128
|
+
return { url: null, why: candidates.length ? 'GitHub lists no successful deployment with an address for this commit' : 'GitHub lists no preview deployment for this commit' };
|
|
129
|
+
}
|
|
130
|
+
if (platform === 'gitlab') {
|
|
131
|
+
if (!branch && !pr) return { url: null, why: 'the PR\'s branch is not known' };
|
|
132
|
+
if (clock.spent()) return slow('GitLab');
|
|
133
|
+
// The deployments list has no branch filter: the newest 100 successful ones are read, and only this
|
|
134
|
+
// branch's (at its head commit, when known) are kept. A deployment's environment there is a short
|
|
135
|
+
// record, so the environment itself is asked whether it is still running and not production.
|
|
136
|
+
const r = runner('glab', ['api', 'projects/:id/deployments?status=success&order_by=id&sort=desc&per_page=100'], opts());
|
|
137
|
+
if (!r.ok) return { url: null, why: 'GitLab could not be asked for deployments (glab not signed in, offline, or no GitLab remote)' };
|
|
138
|
+
const list = parse(r.stdout);
|
|
139
|
+
if (!Array.isArray(list)) return { url: null, why: 'GitLab gave an answer yad cannot read' };
|
|
140
|
+
const env = (x) => (x && typeof x === 'object' && x.environment && typeof x.environment === 'object' ? x.environment : null);
|
|
141
|
+
const seen = new Set();
|
|
142
|
+
// A merge-request pipeline deploys from `refs/merge-requests/<iid>/head` (a merged-results one, a
|
|
143
|
+
// merge commit whose id is not the MR head's): for that ref the commit is not compared. The skills
|
|
144
|
+
// still treat a page that does not show the change as local-only. Newest first: the answer is the
|
|
145
|
+
// newest one whose environment is still running.
|
|
146
|
+
const mrRef = pr ? `refs/merge-requests/${pr}/head` : null;
|
|
147
|
+
const candidates = list.filter((x) => env(x) && ((x.ref === branch && (!sha || x.sha === sha)) || (mrRef && x.ref === mrRef))
|
|
148
|
+
&& Number.isInteger(env(x).id) && !isProduction(env(x).name) && !seen.has(env(x).id) && seen.add(env(x).id));
|
|
149
|
+
let asked = 0, failed = 0;
|
|
150
|
+
for (const d of candidates.slice(0, 3)) {
|
|
151
|
+
if (clock.spent()) return slow('GitLab');
|
|
152
|
+
asked++;
|
|
153
|
+
const e = runner('glab', ['api', `projects/:id/environments/${env(d).id}`], opts());
|
|
154
|
+
const full = e.ok ? parse(e.stdout) : undefined;
|
|
155
|
+
if (!full || typeof full !== 'object') { failed++; continue; }
|
|
156
|
+
if (full.state !== 'available' || isProduction(full.tier) || isProduction(full.name) || !full.external_url) continue;
|
|
157
|
+
if (urlProblem(full.external_url)) return { url: null, why: 'GitLab reports a deployment address yad will not use (not https, or an odd character in it)' };
|
|
158
|
+
return { url: full.external_url };
|
|
159
|
+
}
|
|
160
|
+
if (asked && failed === asked) return { url: null, why: 'GitLab could not be asked about the review environments' };
|
|
161
|
+
// `listedNone`: GitLab answered and listed nothing that fits — the one answer --pr could change.
|
|
162
|
+
return { url: null, listedNone: true, why: 'GitLab lists no successful, running review deployment with an address for this branch or MR among its newest 100 deployments' };
|
|
163
|
+
}
|
|
164
|
+
return { url: null, why: 'the platform is not GitHub or GitLab' };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// The PR/MR's head commit and branch. With a PR number they are asked of the platform, and only the
|
|
168
|
+
// platform's answer counts: this checkout may be on another branch (main, a detached worktree), and its
|
|
169
|
+
// preview is not the PR's. Without one, this checkout's (the review of the branch you are on).
|
|
170
|
+
// { sha, branch } or { sha: null, branch: null, why }.
|
|
171
|
+
export function prHead(platform, pr, { cwd, runner = run, clock = budget(), base = null } = {}) {
|
|
172
|
+
if (!pr) {
|
|
173
|
+
const sha = runner('git', ['rev-parse', 'HEAD'], { cwd }).stdout || null;
|
|
174
|
+
const b = runner('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd }).stdout || null;
|
|
175
|
+
// The default branch is not a PR's branch: its deployment is the main site, never a preview.
|
|
176
|
+
// Detached is no PR's either: yad's worktrees are detached at the default branch (#115).
|
|
177
|
+
if (b && base && b === base) return { sha: null, branch: null, why: `this checkout is on the default branch (${base}), not the PR's` };
|
|
178
|
+
if (b === 'HEAD') return { sha: null, branch: null, why: 'this checkout is on no branch (detached)' };
|
|
179
|
+
if (!b) return { sha: null, branch: null, why: 'this checkout\'s branch could not be read' };
|
|
180
|
+
return { sha: isSha(sha) ? sha : null, branch: b };
|
|
181
|
+
}
|
|
182
|
+
const none = (why) => ({ sha: null, branch: null, why });
|
|
183
|
+
if (!isPrNumber(pr)) return none('the PR number given (--pr) is not a number');
|
|
184
|
+
if (clock.spent()) return none('the platform was too slow to answer');
|
|
185
|
+
const opts = { cwd, timeout: clock.left() };
|
|
186
|
+
if (platform === 'github') {
|
|
187
|
+
const r = runner('gh', ['pr', 'view', String(pr), '--json', 'headRefOid,headRefName'], opts);
|
|
188
|
+
const j = r.ok ? parse(r.stdout) : null;
|
|
189
|
+
if (j && isSha(j.headRefOid)) return { sha: j.headRefOid, branch: typeof j.headRefName === 'string' && j.headRefName ? j.headRefName : null };
|
|
190
|
+
return none(`GitHub could not be asked for PR #${pr}'s head branch (gh not signed in, offline, or no such PR)`);
|
|
191
|
+
}
|
|
192
|
+
if (platform === 'gitlab') {
|
|
193
|
+
const r = runner('glab', ['mr', 'view', String(pr), '-F', 'json'], opts);
|
|
194
|
+
const j = r.ok ? parse(r.stdout) : null;
|
|
195
|
+
if (j && isSha(j.sha)) return { sha: j.sha, branch: typeof j.source_branch === 'string' && j.source_branch ? j.source_branch : null };
|
|
196
|
+
return none(`GitLab could not be asked for MR !${pr}'s source branch (glab not signed in, offline, or no such MR)`);
|
|
197
|
+
}
|
|
198
|
+
return none('the platform is not GitHub or GitLab');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// The answer a review step uses: { url, source: 'pattern'|'platform' } or
|
|
202
|
+
// { url: null, source: 'local-only', why }. `why` says what was tried and how to set a pattern.
|
|
203
|
+
// The PR's head is asked only when it is needed: a {pr} or {repo} pattern answers with no network call.
|
|
204
|
+
export function resolvePreview({ meta, platform, pr, base = null, cwd, runner = run, lookup = platformPreview, clock = budget(), head: given } = {}) {
|
|
205
|
+
const repo = meta?.name;
|
|
206
|
+
let head = given || null;
|
|
207
|
+
const getHead = () => (head ||= prHead(platform, pr, { cwd, runner, clock, base }));
|
|
208
|
+
const tried = [];
|
|
209
|
+
const pat = previewPattern(meta);
|
|
210
|
+
if (pat.pattern) {
|
|
211
|
+
const h = needs(pat.pattern, 'branch') ? getHead() : {};
|
|
212
|
+
const url = fillPattern(pat.pattern, { pr, branch: h.branch, repo });
|
|
213
|
+
if (url) return { url, source: 'pattern' };
|
|
214
|
+
if (needs(pat.pattern, 'pr') && pr && !isPrNumber(pr)) tried.push('the PR number given (--pr) is not a number');
|
|
215
|
+
else if (needs(pat.pattern, 'pr') && !pr) tried.push('the repo\'s preview_url pattern needs the PR number ({pr}), and none was given (--pr)');
|
|
216
|
+
else if (needs(pat.pattern, 'branch') && !h.branch) tried.push(`the repo's preview_url pattern needs the PR's branch ({branch}), and it is not known: ${h.why || 'no branch'}`);
|
|
217
|
+
else tried.push('the repo\'s preview_url pattern could not be filled');
|
|
218
|
+
} else if (pat.problems) {
|
|
219
|
+
tried.push(`the repo's preview_url pattern cannot be used: it ${pat.problems.join('; ')}`);
|
|
220
|
+
} else {
|
|
221
|
+
tried.push(`no preview_url pattern is recorded for ${repo ? 'this repo' : 'a repo outside the registry'}`);
|
|
222
|
+
}
|
|
223
|
+
const h = getHead();
|
|
224
|
+
const p = h.sha || h.branch ? lookup(platform, { cwd, sha: h.sha, branch: h.branch, pr, runner, clock }) : { url: null, why: h.why };
|
|
225
|
+
if (p?.url) return { url: p.url, source: 'platform' };
|
|
226
|
+
if (p?.why && !tried.some((t) => t === p.why || t.endsWith(p.why))) tried.push(p.why);
|
|
227
|
+
// GitLab's merge-request pipelines deploy under the MR's own ref, which only its number finds — said
|
|
228
|
+
// only when GitLab was asked and listed nothing (a GitLab it could not ask, --pr would not help).
|
|
229
|
+
const gitlabNoPr = !pr && platform === 'gitlab' && p?.listedNone === true;
|
|
230
|
+
if (gitlabNoPr) tried.push('a merge-request pipeline\'s deployment is found only with --pr');
|
|
231
|
+
const fix = repo ? 'set one with `yad repo preview <repo> <pattern>`' : 'register the repo, then set one with `yad repo preview <repo> <pattern>`';
|
|
232
|
+
// One next step, chosen here, the one that most likely unblocks the answer: a --pr that is missing
|
|
233
|
+
// or wrong when it is what stopped it, then a pattern to fix, then --pr for GitLab's MR pipelines.
|
|
234
|
+
const badPr = pr && !isPrNumber(pr);
|
|
235
|
+
const next = badPr || (!pr && ((pat.pattern && needs(pat.pattern, 'pr')) || (head && !head.branch && !head.sha))) ? 'pass --pr <n>'
|
|
236
|
+
: pat.pattern ? 'check the pattern with `yad repo preview <repo>`'
|
|
237
|
+
: pat.problems ? 'set it again with `yad repo preview <repo> <pattern>`'
|
|
238
|
+
: gitlabNoPr ? 'pass --pr <n>' : fix;
|
|
239
|
+
return { url: null, source: 'local-only', why: `${tried.join('; ')} — ${next}` };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// The PR/MR description's Preview line, at open time: a pattern that can be filled now, else a note
|
|
243
|
+
// that says which case it is. A {pr} pattern is filled after the PR exists (`runOpenPr` edits the body).
|
|
244
|
+
export const PREVIEW_NONE = 'none recorded — a live design check runs locally only, unless the platform reports a deployment for this PR';
|
|
245
|
+
export const PREVIEW_UNFILLED = 'a preview_url pattern is recorded but could not be filled here — `yad review context --pr <n>` gives the address';
|
|
246
|
+
export const PREVIEW_UNUSABLE = 'the recorded preview_url pattern cannot be used — a live design check runs locally only, unless the platform reports a deployment for this PR; fix it with `yad repo preview <repo> <pattern>`';
|
|
247
|
+
export function previewLine(meta, { pr, branch } = {}) {
|
|
248
|
+
const pat = previewPattern(meta);
|
|
249
|
+
if (pat.problems) return PREVIEW_UNUSABLE;
|
|
250
|
+
if (!pat.pattern) return PREVIEW_NONE;
|
|
251
|
+
const url = fillPattern(pat.pattern, { pr, branch, repo: meta?.name });
|
|
252
|
+
return url ? `<${url}>` : PREVIEW_UNFILLED;
|
|
253
|
+
}
|
package/cli/protection.mjs
CHANGED
|
@@ -714,3 +714,53 @@ function unknownHint(r) {
|
|
|
714
714
|
default: return 'fix what the message names, then run `yad doctor` again; nothing about this repo\'s protection is assumed meanwhile';
|
|
715
715
|
}
|
|
716
716
|
}
|
|
717
|
+
|
|
718
|
+
// E160b — what `yad ci check` reads beyond protection and approvals: the rules that make yad's checks hold a
|
|
719
|
+
// merge. Read-only, the same calls `readProtection` makes plus a few GETs, and the same trap: a failed call is
|
|
720
|
+
// never "none". `readProtection` runs first, so a repo that cannot be read (no platform, reads turned off,
|
|
721
|
+
// no login…) comes back with only `protection`, and every platform row is "not known" with its reason.
|
|
722
|
+
// GitHub — `rules`: the active rules on the branch (null when not read; `full` when a whole page came
|
|
723
|
+
// back, which proves nothing about what is past it). `classic`: classic branch protection, the
|
|
724
|
+
// string 'none' when PROVEN absent (the branch reads `protected: false`, or GitHub answers 404 with
|
|
725
|
+
// exactly "Branch not protected"), or null — GitHub answers a bare 404 to anyone who is not an
|
|
726
|
+
// admin, even on a protected branch.
|
|
727
|
+
// GitLab — the project's merge settings, the protected-branch entries that match the branch (null when not
|
|
728
|
+
// read), the approval settings (Premium) and the push rule (Premium; a 404 is "no push rule").
|
|
729
|
+
export function readCiSettings(target, { runner: ask = run, env = process.env, authCache = new Map() } = {}) {
|
|
730
|
+
// One answer per call for this repo: `readProtection` and the reads below ask some of the same paths, and
|
|
731
|
+
// two answers to one question could disagree.
|
|
732
|
+
const answers = new Map();
|
|
733
|
+
const runner = (cmd, args, opts) => {
|
|
734
|
+
if (args[0] !== 'api') return ask(cmd, args, opts);
|
|
735
|
+
const key = [cmd, ...args].join('\0');
|
|
736
|
+
if (!answers.has(key)) answers.set(key, ask(cmd, args, opts));
|
|
737
|
+
return answers.get(key);
|
|
738
|
+
};
|
|
739
|
+
const protection = readProtection(target, { runner, env, authCache });
|
|
740
|
+
if (!protection.known) return { protection };
|
|
741
|
+
const { platform, host, repo, branch } = protection;
|
|
742
|
+
if (platform === 'github') {
|
|
743
|
+
const at = `repos/${repo.split('/').map(encodeURIComponent).join('/')}`;
|
|
744
|
+
const r = api(runner, 'gh', host, `${at}/rules/branches/${segment(branch)}?per_page=${PAGE}`);
|
|
745
|
+
const rules = r.ok && Array.isArray(r.body) ? r.body : null;
|
|
746
|
+
let classic = null;
|
|
747
|
+
if (protection.protected === false) classic = 'none';
|
|
748
|
+
else {
|
|
749
|
+
const c = api(runner, 'gh', host, `${at}/branches/${segment(branch)}/protection`);
|
|
750
|
+
if (c.ok && c.body && typeof c.body === 'object' && !Array.isArray(c.body)) classic = c.body;
|
|
751
|
+
else if (c.status === 404 && c.body?.message === 'Branch not protected') classic = 'none';
|
|
752
|
+
}
|
|
753
|
+
return { protection, rules, rulesFull: !!rules && rules.length >= PAGE, classic };
|
|
754
|
+
}
|
|
755
|
+
const at = `projects/${encodeURIComponent(repo)}`;
|
|
756
|
+
const obj = (res) => (res.ok && res.body && typeof res.body === 'object' && !Array.isArray(res.body) ? res.body : null);
|
|
757
|
+
const project = obj(api(runner, 'glab', host, at));
|
|
758
|
+
const pb = api(runner, 'glab', host, `${at}/protected_branches?per_page=${PAGE}`);
|
|
759
|
+
const list = pb.ok && Array.isArray(pb.body) ? pb.body : null;
|
|
760
|
+
const matched = list ? list.filter((p) => branchMatches(p?.name, branch)) : null;
|
|
761
|
+
const approvals = obj(api(runner, 'glab', host, `${at}/approvals`));
|
|
762
|
+
const pr = api(runner, 'glab', host, `${at}/push_rule`);
|
|
763
|
+
// No push rule is set: GitLab answers 404, or (on some versions) 200 with an empty body.
|
|
764
|
+
const pushRule = obj(pr) ?? (pr.ok || pr.status === 404 ? 'none' : null);
|
|
765
|
+
return { protection, project, matched, matchedFull: !!list && list.length >= PAGE, approvals, pushRule };
|
|
766
|
+
}
|
package/cli/reconcile.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// `yad check` (report) and `yad check --fix` (reconcile) — and `yad update`
|
|
2
2
|
// as a thin alias (--scope=changed). Inspects actual project state against the
|
|
3
3
|
// manifest: missing setup, drifted files, stale code-context.
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
4
5
|
import fs from 'node:fs';
|
|
5
6
|
import path from 'node:path';
|
|
6
7
|
import {
|
|
7
|
-
c, log, ok, info, warn, hand, readJSON, writeJSON, exists, forTerminal,
|
|
8
|
+
c, log, ok, info, warn, fail, hand, readJSON, writeJSON, exists, forTerminal, run, samePath,
|
|
8
9
|
} from './lib.mjs';
|
|
9
10
|
|
|
10
11
|
const readFileSafe = (p) => { try { return fs.readFileSync(p, 'utf8'); } catch { return ''; } };
|
|
@@ -12,12 +13,13 @@ const readFileSafe = (p) => { try { return fs.readFileSync(p, 'utf8'); } catch {
|
|
|
12
13
|
import { preflightGuardReadiness } from './productcommit.mjs';
|
|
13
14
|
import { VERSION, PROJECT_FILES, MANAGED_LEDGER, BACKUP_SUFFIX , productConfigPath, PRODUCT_LINK } from './manifest.mjs';
|
|
14
15
|
import {
|
|
15
|
-
moduleActions, repoActions, productActions, hookActions,
|
|
16
|
+
moduleActions, repoActions, productActions, hookActions, agentFileActions, agentGuardActions, orphanAgentGuardActions, allowListActions, orphanAllowListActions, repoOrphanAgentGuardActions,
|
|
16
17
|
legacyModuleActions, removedModuleActions, orphanHookActions, captureHookActions, orphanCaptureHookActions, legacyHookScriptActions, legacyRepoActions, legacyProductActions,
|
|
17
18
|
ideTargetStateFor, recordManagedWrites, gitHookActions, orphanGitHookActions, gitHookState, gitHookAdvice, renamedNameHits, withoutKeptRenames, PRODUCT_PROFILE_GATES, productProfileGap, productProfileEffect, PRODUCT_PROFILE_FIX, workflowsPassingProduct, productGateBlockers, oldProfileAdvice,
|
|
18
19
|
} from './plan.mjs';
|
|
19
20
|
import { gitHead, packRepo } from './setup.mjs';
|
|
20
|
-
import { groupByRoot, commitUpdates, repoLabel } from './update-commit.mjs';
|
|
21
|
+
import { groupByRoot, commitUpdates, openUpdatePrs, repoLabel, updatePrBlocker, updateTargets, HELD_KINDS } from './update-commit.mjs';
|
|
22
|
+
import { createPr } from './platform.mjs';
|
|
21
23
|
import { hasSiblingRepo, workspaceFileState, writeWorkspaceFile, WORKSPACE_FILE } from './find-product.mjs';
|
|
22
24
|
import { offerToolbox } from './toolbox.mjs';
|
|
23
25
|
|
|
@@ -31,7 +33,7 @@ const repoShown = (repo) => `product (the code repo at ${forTerminal(repo.path)}
|
|
|
31
33
|
const shown = (a) => a.shownScope ?? a.scope;
|
|
32
34
|
const itemsOf = (actions) => actions.map((a) => ({ scope: a.scope, item: a.item, status: a.status, product: !a.fromRepo }));
|
|
33
35
|
|
|
34
|
-
export async function reconcile(root, { fix = false, scope = 'all', force = false, push = false, allowBranch = false, overwriteLocal = false, toolbox: toolboxAt = null } = {}) {
|
|
36
|
+
export async function reconcile(root, { fix = false, scope = 'all', force = false, push = false, openPr = false, allowBranch = false, overwriteLocal = false, toolbox: toolboxAt = null, creator = createPr } = {}) {
|
|
35
37
|
log(c.bold(`\nSDLC reconcile ${c.dim('v' + VERSION)}`));
|
|
36
38
|
log(c.dim(`target: ${root}\n`));
|
|
37
39
|
|
|
@@ -60,6 +62,12 @@ export async function reconcile(root, { fix = false, scope = 'all', force = fals
|
|
|
60
62
|
...moduleActions(root, ideTargets), ...legacyModuleActions(root, ideTargets), ...removedModuleActions(root, ideTargets),
|
|
61
63
|
// E123: a renamed CI file the team edited is kept, and its new name is not installed beside it.
|
|
62
64
|
...withoutKeptRenames([...productActions(root), ...legacyProductActions(root)]), ...hookActions(root, ideTargets),
|
|
65
|
+
// E158: the rules block in AGENTS.md (and CLAUDE.md importing it), which every agent reads first.
|
|
66
|
+
...agentFileActions(root, ideTargets),
|
|
67
|
+
// E158: the agent guard, before every shell command the agent runs.
|
|
68
|
+
...agentGuardActions(root, ideTargets), ...orphanAgentGuardActions(root, ideTargets),
|
|
69
|
+
// E158 (#353): the read-only yad commands, pre-approved for Claude Code.
|
|
70
|
+
...allowListActions(root, ideTargets), ...orphanAllowListActions(root, ideTargets),
|
|
63
71
|
...orphanHookActions(root, ideTargets),
|
|
64
72
|
// E48: this clone's git pre-commit hook — the person's half of the ledger guard.
|
|
65
73
|
...gitHookActions(root), ...orphanGitHookActions(root),
|
|
@@ -80,7 +88,10 @@ export async function reconcile(root, { fix = false, scope = 'all', force = fals
|
|
|
80
88
|
});
|
|
81
89
|
}
|
|
82
90
|
for (const repo of registry.repos) {
|
|
83
|
-
const
|
|
91
|
+
const repoRoot = path.resolve(root, repo.path);
|
|
92
|
+
// E158b: a target that left takes yad's guard and allow-list entries out of the repo's own settings too.
|
|
93
|
+
const orphans = samePath(repoRoot, path.resolve(root)) ? [] : repoOrphanAgentGuardActions(repoRoot, ideTargets, { scope: repo.name });
|
|
94
|
+
const own = withoutKeptRenames([...repoActions(root, repo), ...legacyRepoActions(root, repo)]).concat(orphans);
|
|
84
95
|
// Set on the action itself: later steps compare actions by identity. `true`, not the name, which may be empty.
|
|
85
96
|
for (const a of own) { a.fromRepo = true; if (repo.name === 'product') a.shownScope = repoShown(repo); }
|
|
86
97
|
actions.push(...own);
|
|
@@ -169,7 +180,10 @@ export async function reconcile(root, { fix = false, scope = 'all', force = fals
|
|
|
169
180
|
// A managed file the team edited is NEVER rewritten by a plain update — that silent clobber is what
|
|
170
181
|
// #164 reported. It is reported on every run (honest drift) until either the edit is dropped or
|
|
171
182
|
// `--overwrite-local` replaces it, which still saves the previous content beside it.
|
|
172
|
-
|
|
183
|
+
// An action that writes nothing (`writesNothing`: a settings file that does not parse, rules-block markers yad
|
|
184
|
+
// cannot trust) has said why at plan time, and `--overwrite-local` cannot fix it either: it is left out here
|
|
185
|
+
// and from what --fix applies, so no run says it was fixed.
|
|
186
|
+
const modified = actions.filter((a) => a.status === 'modified' && !a.writesNothing);
|
|
173
187
|
for (const m of modified) {
|
|
174
188
|
// The product-link record has no template: it is `modified` only when it is not a JSON object (E120).
|
|
175
189
|
warn(m.item === PRODUCT_LINK
|
|
@@ -224,8 +238,9 @@ export async function reconcile(root, { fix = false, scope = 'all', force = fals
|
|
|
224
238
|
hand(`keep the edits (reported as \`modified\` on every check), or replace them with \`yad update --overwrite-local\` — each previous version is saved beside the file as <file>${BACKUP_SUFFIX}`);
|
|
225
239
|
}
|
|
226
240
|
|
|
227
|
-
|
|
241
|
+
let fixable = actions.filter((a) =>
|
|
228
242
|
a.status !== 'ok'
|
|
243
|
+
&& !a.writesNothing
|
|
229
244
|
&& (a.status !== 'modified' || overwriteLocal)
|
|
230
245
|
&& (scope === 'all' ? true : a.status !== 'missing'),
|
|
231
246
|
);
|
|
@@ -238,21 +253,110 @@ export async function reconcile(root, { fix = false, scope = 'all', force = fals
|
|
|
238
253
|
let workspaceFile = wsNeeded ? workspaceFileState(root) : null;
|
|
239
254
|
if (!fix) {
|
|
240
255
|
if (workspaceFile === 'missing') info(`no ${WORKSPACE_FILE} beside the Product — \`yad check --fix\` writes it, so yad finds the Product from its code repos`);
|
|
241
|
-
if (push) warn('--push has no effect without --fix (there is nothing applied to commit)
|
|
256
|
+
if (push || openPr) warn(`${push ? '--push' : '--open-pr'} has no effect without --fix (there is nothing applied to commit).`);
|
|
242
257
|
if (fixable.length || gaps.length) hand('run `yad check --fix` to reconcile (or `yad setup` for missing one-time setup).');
|
|
243
258
|
// After the --fix hint, never above it: --fix installs no tool, and must not read as if it did.
|
|
244
259
|
const toolbox = toolboxSection(root, toolboxAt);
|
|
245
260
|
return { fix: false, counts, gaps, items: itemsOf(actions), applied: 0, modified: modified.length, commits: [], workspaceFile, toolbox };
|
|
246
261
|
}
|
|
247
262
|
|
|
263
|
+
// Each repo's default branch and platform, for --push and --open-pr.
|
|
264
|
+
const productSettings = readJSON(productConfigPath(root), {});
|
|
265
|
+
const defByRoot = new Map([[root, productSettings?.default_branch]]);
|
|
266
|
+
const platformByRoot = new Map([[root, productSettings?.platform]]);
|
|
267
|
+
for (const repo of registry.repos) {
|
|
268
|
+
const repoRoot = path.resolve(root, repo.path);
|
|
269
|
+
// A monorepo entry (`path: "."`) is the Product itself: its settings are the Product's.
|
|
270
|
+
if (repoRoot === root) continue;
|
|
271
|
+
defByRoot.set(repoRoot, repo.default_branch);
|
|
272
|
+
platformByRoot.set(repoRoot, repo.platform);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// --open-pr is all or nothing (E157 update reviews 2 and 3). The Product and every connected repo cloned
|
|
276
|
+
// here (`updateTargets`, the one list the guide reads too) are checked BEFORE anything is written: each must
|
|
277
|
+
// be on its default branch, not detached, with an origin and no local commits origin lacks. One that is not
|
|
278
|
+
// stops the whole run with nothing written, so no repo is left half updated, no one's feature work rides an
|
|
279
|
+
// update PR/MR, and no one is moved off their branch: the person fixes it and runs it again. A repo whose
|
|
280
|
+
// update is already on review (`open`) is left alone (`held`): nothing is written there until it merges.
|
|
281
|
+
let held = new Set();
|
|
282
|
+
let heldRows = [];
|
|
283
|
+
let reached = null;
|
|
284
|
+
if (openPr) {
|
|
285
|
+
const targets = updateTargets(root);
|
|
286
|
+
reached = new Set(targets.map((t) => t.root));
|
|
287
|
+
const checks = targets.map((t) => [t.root, updatePrBlocker(t.root, { defaultBranch: t.defaultBranch ?? defByRoot.get(t.root), productRoot: root, file: t.file })]);
|
|
288
|
+
const stop = checks.filter(([, b]) => b && !HELD_KINDS.includes(b.kind));
|
|
289
|
+
// Every row says why, in `reason` (a word) and `hint` (what to do): the agent relays it to the person.
|
|
290
|
+
const row = (r, b) => ({ label: b.label, product: r === root, branch: b.branch ?? null, committed: false, pushed: false, opened: false, pr: null, skipped: true, error: !HELD_KINDS.includes(b.kind), reason: b.kind, hint: b.message });
|
|
291
|
+
if (stop.length) {
|
|
292
|
+
log('');
|
|
293
|
+
for (const [, b] of stop) fail(`${b.label}: ${b.message}`);
|
|
294
|
+
fail(`--open-pr: ${stop.length} repo(s) cannot take the update as a PR/MR now — nothing was written; fix the above, then run it again`);
|
|
295
|
+
process.exitCode = 1;
|
|
296
|
+
const toolbox = toolboxSection(root, toolboxAt);
|
|
297
|
+
return { fix: true, counts, gaps, items: itemsOf(actions), applied: 0, modified: modified.length, commits: stop.map(([r, b]) => row(r, b)), workspaceFile, toolbox };
|
|
298
|
+
}
|
|
299
|
+
held = new Set(checks.filter(([, b]) => b).map(([r]) => r));
|
|
300
|
+
heldRows = checks.filter(([, b]) => b).map(([r, b]) => row(r, b));
|
|
301
|
+
for (const [, b] of checks) if (b) info(`${b.label}: ${b.message}`);
|
|
302
|
+
if (held.size === checks.length) {
|
|
303
|
+
info('every repo\'s update is already merged or on review — nothing written');
|
|
304
|
+
const toolbox = toolboxSection(root, toolboxAt);
|
|
305
|
+
return { fix: true, counts, gaps, items: itemsOf(actions), applied: 0, modified: modified.length, commits: checks.map(([r, b]) => row(r, b)), workspaceFile, toolbox };
|
|
306
|
+
}
|
|
307
|
+
fixable = fixable.filter((a) => (!a.root || reached.has(a.root)) && !held.has(a.root) && (!a.managed?.root || reached.has(a.managed.root)) && !held.has(a.managed?.root));
|
|
308
|
+
}
|
|
309
|
+
// Under --open-pr, only a repo it checked and did not hold is written (a registered repo not cloned here is
|
|
310
|
+
// `yad repo clone`'s business).
|
|
311
|
+
const reaches = (r) => !r || ((!reached || reached.has(r)) && !held.has(r));
|
|
312
|
+
const live = (a) => reaches(a.root) && reaches(a.managed?.root);
|
|
313
|
+
|
|
314
|
+
// A file the team co-owns (the agent settings that run yad's hooks) is never staged by `--push`. Under
|
|
315
|
+
// --open-pr it rides the PR/MR when it is yad's alone: exactly what is committed (or nothing) with yad's
|
|
316
|
+
// entries merged in — so a file this run creates rides too, and so does one a failed push left behind.
|
|
317
|
+
// Otherwise the person has their own edits in it, which never ride an update: said in a row of its own.
|
|
318
|
+
// Read BEFORE anything is applied. Several adapters can share one file, so it is one entry per file
|
|
319
|
+
// (E157 update review 11).
|
|
320
|
+
const shared = new Map();
|
|
321
|
+
const sharedText = (f) => (exists(f) ? fs.readFileSync(f, 'utf8') : null);
|
|
322
|
+
if (openPr) {
|
|
323
|
+
for (const a of actions) {
|
|
324
|
+
// Only a file this run writes, or one already right: a rules block `yad update` leaves out (an unwired
|
|
325
|
+
// repo's AGENTS.md is `missing`) or one it cannot write (`writesNothing`) is never staged or reported
|
|
326
|
+
// (E158 review 4).
|
|
327
|
+
if (!a.shared || !a.root || !live(a) || (a.status !== 'ok' && !fixable.includes(a))) continue;
|
|
328
|
+
const file = path.join(a.root, a.shared);
|
|
329
|
+
if (!shared.has(file)) {
|
|
330
|
+
// A text file is read as committed, not trimmed (`run` trims): its trailing lines are part of the text
|
|
331
|
+
// yad's block is merged into (E158 review 1).
|
|
332
|
+
let head;
|
|
333
|
+
if (a.kind === 'text') {
|
|
334
|
+
const r = spawnSync('git', ['show', `HEAD:${a.shared}`], { cwd: a.root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, windowsHide: true });
|
|
335
|
+
head = r.status === 0 ? r.stdout : null;
|
|
336
|
+
} else {
|
|
337
|
+
const r = run('git', ['show', `HEAD:${a.shared}`], { cwd: a.root, maxBuffer: 64 * 1024 * 1024 });
|
|
338
|
+
head = r.ok ? r.stdout : null;
|
|
339
|
+
}
|
|
340
|
+
shared.set(file, { a, merges: [], disk: sharedText(file), head });
|
|
341
|
+
}
|
|
342
|
+
shared.get(file).merges.push(a.mergeShared);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
248
345
|
// --- apply --- (collect the applied actions so --push can stage each repo's exact allowlist) ---
|
|
249
346
|
log('');
|
|
250
347
|
let applied = 0;
|
|
251
348
|
const appliedActions = [];
|
|
349
|
+
// Under --open-pr a skill folder keeps a person's own files and is staged by the template's files only, so
|
|
350
|
+
// nothing of theirs is deleted from disk or rides the PR/MR (E157 update review 7).
|
|
351
|
+
const keepOwn = (a) => {
|
|
352
|
+
if (!openPr || typeof a.applyKeepingOwn !== 'function') { a.apply(); return a; }
|
|
353
|
+
const kept = a.applyKeepingOwn();
|
|
354
|
+
if (kept.length) info(`kept ${kept.length} file(s) the template does not have in ${shown(a)}/${a.item} — delete any that an older yadflow shipped`);
|
|
355
|
+
return { ...a, paths: a.ownPaths() };
|
|
356
|
+
};
|
|
252
357
|
for (const a of fixable) {
|
|
253
|
-
|
|
358
|
+
appliedActions.push(keepOwn(a));
|
|
254
359
|
applied++;
|
|
255
|
-
appliedActions.push(a);
|
|
256
360
|
// A backup means the replaced content was not provably ours (a pre-ledger install, or an edit
|
|
257
361
|
// --overwrite-local was told to discard). Never report that as an ordinary template adoption.
|
|
258
362
|
info(`${a.status} → fixed: ${shown(a)}/${a.item}${a.backup ? ` ${c.yellow(`(previous content saved to ${path.basename(a.backup)})`)}` : ''}`);
|
|
@@ -260,19 +364,80 @@ export async function reconcile(root, { fix = false, scope = 'all', force = fals
|
|
|
260
364
|
if (force) {
|
|
261
365
|
// --force re-copies what is already correct; it deliberately does NOT reach a `modified` file —
|
|
262
366
|
// only --overwrite-local discards a local edit, and only after backing it up.
|
|
263
|
-
for (const a of actions.filter((a) => a.status === 'ok'
|
|
367
|
+
for (const a of actions.filter((a) => a.status === 'ok' && live(a))) appliedActions.push(keepOwn(a));
|
|
264
368
|
}
|
|
265
369
|
// A file that is right on disk but not committed as it stands, which --push must still commit: the
|
|
266
370
|
// product-link record (E120) — the gates read it from the default branch, not from anyone's disk.
|
|
267
|
-
if (push) for (const a of actions) if (a.pendingCommit && !appliedActions.includes(a)) appliedActions.push(a);
|
|
371
|
+
if (push || openPr) for (const a of actions) if (a.pendingCommit && live(a) && !appliedActions.includes(a)) appliedActions.push(a);
|
|
372
|
+
// --open-pr also stages every managed file already right on disk: `stageAllowlist` keeps only what differs
|
|
373
|
+
// from the commit, so an update a failed commit or push left in the working tree is carried by the next run.
|
|
374
|
+
// A folder is staged by its template's own files only, never the folder: a person's own file beside them
|
|
375
|
+
// (notes in a skill folder) must not ride an update PR/MR.
|
|
376
|
+
if (openPr) {
|
|
377
|
+
for (const a of actions) {
|
|
378
|
+
if (a.status !== 'ok' || !a.root || !Array.isArray(a.paths) || !live(a) || appliedActions.includes(a)) continue;
|
|
379
|
+
appliedActions.push(typeof a.ownPaths === 'function' ? { ...a, paths: a.ownPaths() } : a);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
const sharedRows = [];
|
|
383
|
+
const lf = (t) => t.replace(/\r\n/g, '\n');
|
|
384
|
+
const parse = (t) => { try { const v = JSON.parse(t); return v && typeof v === 'object' && !Array.isArray(v) ? v : null; } catch { return null; } };
|
|
385
|
+
// A settings file is JSON, merged as objects; a rules file (AGENTS.md, CLAUDE.md, E158) is text, with yad's
|
|
386
|
+
// block put into it. Each kind: how to read it, merge yad's part in, and compare.
|
|
387
|
+
const KINDS = {
|
|
388
|
+
// `eq` compares a file's text with what is committed: JSON trimmed (`run` trims git's output), text with its
|
|
389
|
+
// line endings evened out, since git may store LF where the disk holds CRLF (`core.autocrlf`).
|
|
390
|
+
json: { read: (t) => parse(t), empty: {}, merge: (o, m) => { if (!o) return undefined; const r = m(o); return r.unreadable ? undefined : r.settings; }, same: (a, b) => JSON.stringify(a) === JSON.stringify(b), eq: (a, b) => a.trim() === b.trim(), what: 'its entries (hooks, the read-only allow list)', reason: 'settings-uncommitted' },
|
|
391
|
+
text: { read: (t) => t, empty: null, merge: (t, m) => { const r = m(t); return r.refused ? undefined : r.text; }, same: (a, b) => lf(a) === lf(b), eq: (a, b) => lf(a) === lf(b), what: 'its yadflow rules block', reason: 'agents-uncommitted' },
|
|
392
|
+
};
|
|
393
|
+
for (const [file, e] of shared) {
|
|
394
|
+
const k = KINDS[e.a.kind ?? 'json'];
|
|
395
|
+
const now = sharedText(file);
|
|
396
|
+
if (now === null || (e.head !== null && k.eq(now, e.head))) continue;
|
|
397
|
+
const base = e.head === null ? k.empty : k.read(e.head);
|
|
398
|
+
// What yad alone would make of it: each adapter's part merged into what is committed.
|
|
399
|
+
// `undefined` when yad's part cannot be merged (a file that does not parse, markers it cannot trust).
|
|
400
|
+
const ours = e.merges.reduce((o, merge) => (o === undefined ? undefined : k.merge(o, merge)), base);
|
|
401
|
+
// yad's parts are all committed already: nothing of yad's is left out, and the person's own edits in the
|
|
402
|
+
// file are theirs to keep or share — no row (E157 update review 12).
|
|
403
|
+
if (ours !== undefined && base !== null && k.same(ours, base)) continue;
|
|
404
|
+
const was = e.disk === null ? null : k.read(e.disk);
|
|
405
|
+
const yadsAlone = e.disk === null ? e.head === null
|
|
406
|
+
: e.head !== null && k.eq(e.disk, e.head) ? true
|
|
407
|
+
: !!(ours !== undefined && was !== null && k.same(was, ours));
|
|
408
|
+
if (yadsAlone) { appliedActions.push({ ...e.a, paths: [e.a.shared] }); continue; }
|
|
409
|
+
const hint = `${e.a.shared} has changes that are not committed, so the update left ${k.what} out of the PR/MR: commit ${e.a.shared} as it now stands, through review on a branch of your own`;
|
|
410
|
+
info(`${repoLabel(root, e.a.root)}: ${hint}`);
|
|
411
|
+
sharedRows.push({ label: repoLabel(root, e.a.root), product: e.a.root === root, branch: null, committed: false, pushed: false, opened: false, pr: null, skipped: true, error: false, reason: k.reason, hint });
|
|
412
|
+
}
|
|
268
413
|
// Refresh the version stamp and persist only the canonical targets used to build actions. This also
|
|
269
414
|
// completes legacy/corrupt target migration even when no skill content itself needed an update.
|
|
270
|
-
|
|
271
|
-
|
|
415
|
+
if (!held.has(root)) {
|
|
416
|
+
writeCanonicalStamp();
|
|
417
|
+
appliedActions.push({ scope: 'product', item: PROJECT_FILES.version, status: 'stamp', root, paths: [PROJECT_FILES.version] });
|
|
418
|
+
}
|
|
272
419
|
// Record what we wrote (and what was already correct) so the NEXT update can tell a stale managed
|
|
273
420
|
// file from an edited one. Seeding the already-correct files is what migrates a pre-ledger install.
|
|
274
421
|
// A file left as `modified` records nothing — it differs from the template by definition.
|
|
275
|
-
|
|
422
|
+
const ledgerRoots = recordManagedWrites(actions.filter(live));
|
|
423
|
+
// A connected repo whose every managed file is the team's own (`modified`) records nothing above, so its
|
|
424
|
+
// ledger would name an older yadflow for good — and read as behind on every `yad guide`. Its version is
|
|
425
|
+
// brought up all the same: this release did look at it.
|
|
426
|
+
for (const repo of registry.repos) {
|
|
427
|
+
const repoRoot = path.resolve(root, repo.path);
|
|
428
|
+
const ledgerFile = path.join(repoRoot, MANAGED_LEDGER);
|
|
429
|
+
if (repoRoot === root || ledgerRoots.includes(repoRoot) || !reaches(repoRoot) || !exists(ledgerFile)) continue;
|
|
430
|
+
const ledger = readJSON(ledgerFile, null);
|
|
431
|
+
if (ledger && typeof ledger === 'object' && !Array.isArray(ledger) && ledger.version !== VERSION) {
|
|
432
|
+
writeJSON(ledgerFile, { ...ledger, version: VERSION });
|
|
433
|
+
ledgerRoots.push(repoRoot);
|
|
434
|
+
} else if (ledger && (push || openPr)) {
|
|
435
|
+
// Already restamped on disk by a run whose commit or push failed: still staged, so the next run carries
|
|
436
|
+
// it (staging keeps only what differs from the commit).
|
|
437
|
+
ledgerRoots.push(repoRoot);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
for (const ledgerRoot of ledgerRoots) {
|
|
276
441
|
appliedActions.push({
|
|
277
442
|
scope: repoLabel(root, ledgerRoot), item: MANAGED_LEDGER, status: 'stamp',
|
|
278
443
|
root: ledgerRoot, paths: [MANAGED_LEDGER],
|
|
@@ -293,17 +458,13 @@ export async function reconcile(root, { fix = false, scope = 'all', force = fals
|
|
|
293
458
|
// Each repo's `{ label, committed, pushed }`, for the --json answer (E1): a push that failed after a
|
|
294
459
|
// commit landed is said per repo.
|
|
295
460
|
let commits = [];
|
|
296
|
-
if (push) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
defByRoot.set(repoRoot, repo.default_branch);
|
|
304
|
-
platformByRoot.set(repoRoot, repo.platform);
|
|
305
|
-
}
|
|
306
|
-
commits = commitUpdates(root, groupByRoot(appliedActions), {
|
|
461
|
+
if (push || openPr) {
|
|
462
|
+
// Both commit: an unsigned commit fails the verified-commits check, on the default branch or on the PR/MR.
|
|
463
|
+
preflightGuardReadiness(root, openPr ? 'the PR/MR\'s verified-commits check requires a platform-Verified signature; an unsigned update commit fails it' : undefined);
|
|
464
|
+
// --open-pr: each repo's changes on their own branch, with a PR/MR a person merges.
|
|
465
|
+
// Every repo has a row: the held ones (with their reason and hint) first, then what was opened.
|
|
466
|
+
if (openPr) commits = heldRows.concat(openUpdatePrs(root, groupByRoot(appliedActions), { defaultBranchFor: (r) => defByRoot.get(r), platformFor: (r) => platformByRoot.get(r), creator, checked: true }), sharedRows);
|
|
467
|
+
else commits = commitUpdates(root, groupByRoot(appliedActions), {
|
|
307
468
|
push: true, allowBranch,
|
|
308
469
|
defaultBranchFor: (r) => defByRoot.get(r),
|
|
309
470
|
// GitLab's yad-update-guard is an includable fragment: unlike a GitHub workflow it does nothing
|