yadflow 4.6.0 → 4.8.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 +259 -0
- package/README.md +46 -4
- package/bin/commands.mjs +9 -2
- package/bin/yad.mjs +309 -30
- package/cli/agent-guard.mjs +511 -0
- package/cli/agent-guide.mjs +83 -0
- package/cli/agent-rules.mjs +381 -0
- package/cli/argv-flags.mjs +7 -0
- package/cli/artifact-status.mjs +88 -20
- package/cli/build.mjs +1372 -0
- package/cli/checkpoint.mjs +2 -2
- package/cli/ci-check.mjs +492 -0
- package/cli/commit.mjs +1 -0
- package/cli/dial.mjs +21 -1
- package/cli/docs.mjs +7 -2
- package/cli/doctor.mjs +176 -33
- package/cli/epic-state.mjs +360 -12
- package/cli/errors.mjs +3 -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/guide.mjs +549 -0
- package/cli/history.mjs +22 -2
- package/cli/hook.mjs +35 -4
- package/cli/index-command.mjs +2 -2
- package/cli/ledger.mjs +60 -0
- 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/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 +35 -12
- package/cli/openpr.mjs +81 -5
- package/cli/plan.mjs +326 -22
- 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/protection.mjs +50 -0
- package/cli/recommend.mjs +3 -1
- package/cli/reconcile.mjs +187 -26
- package/cli/repo-publish.mjs +2 -2
- package/cli/report.mjs +62 -14
- package/cli/run-checks.mjs +586 -0
- package/cli/setup.mjs +244 -25
- package/cli/ship-drift.mjs +49 -18
- package/cli/signing.mjs +377 -0
- package/cli/standup.mjs +1 -1
- package/cli/status.mjs +282 -0
- package/cli/test-agents-file.mjs +993 -0
- package/cli/test-build.mjs +1559 -0
- package/cli/test-ci-check.mjs +616 -0
- package/cli/test-guide.mjs +1267 -0
- package/cli/test-node.mjs +129 -0
- package/cli/test-run-checks.mjs +603 -0
- package/cli/test-setup-agent.mjs +352 -0
- package/cli/test-signing.mjs +524 -0
- package/cli/test-worktree.mjs +520 -0
- package/cli/thread.mjs +4 -0
- package/cli/tidy.mjs +2 -2
- package/cli/toolbox.mjs +37 -6
- package/cli/update-commit.mjs +313 -11
- package/cli/workspace.mjs +38 -10
- package/cli/worktree-record.mjs +53 -0
- package/cli/worktree.mjs +379 -0
- package/package.json +6 -4
- package/skills/sdlc/config.yaml +5 -5
- package/skills/sdlc/module-help.csv +2 -1
- package/skills/yad-backfill/templates/checks/backfill-check.sh +9 -9
- package/skills/yad-change/SKILL.md +5 -1
- package/skills/yad-checks/SKILL.md +61 -12
- package/skills/yad-checks/references/check-gates.md +78 -14
- 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 +42 -5
- 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 +9 -9
- package/skills/yad-checks/templates/gitlab/.gitlab-ci.yml +4 -1
- package/skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml +5 -5
- 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-checks/templates/hooks/agent-guard.mjs +116 -0
- package/skills/yad-commit/SKILL.md +8 -5
- package/skills/yad-connect-repos/SKILL.md +5 -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/templates/app/package-lock.json +395 -106
- package/skills/yad-docs/templates/app/package.json +2 -2
- package/skills/yad-docs-overview/references/pipeline-model.md +2 -2
- package/skills/yad-engineer-review/SKILL.md +55 -25
- package/skills/yad-engineer-review/references/ship-and-record.md +49 -12
- package/skills/yad-epic/SKILL.md +2 -1
- package/skills/yad-epic/references/state-schema.md +76 -17
- package/skills/yad-guide/SKILL.md +192 -0
- 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-pair-review/SKILL.md +14 -5
- 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 +44 -12
- package/skills/yad-product-bridge/references/bridge.md +11 -5
- 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 +9 -4
- package/skills/yad-reconcile/SKILL.md +9 -3
- package/skills/yad-report/SKILL.md +15 -0
- package/skills/yad-review-companion/SKILL.md +5 -3
- package/skills/yad-review-gate/SKILL.md +16 -8
- package/skills/yad-review-gate/references/gating.md +26 -1
- package/skills/yad-run/SKILL.md +61 -33
- package/skills/yad-run/references/run-loop.md +44 -22
- 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/skills/yad-sync-repos/SKILL.md +2 -1
- package/skills/yad-ui/SKILL.md +2 -2
package/cli/plan.mjs
CHANGED
|
@@ -5,14 +5,16 @@ import fs from 'node:fs';
|
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { err } from './errors.mjs';
|
|
7
7
|
import {
|
|
8
|
-
asset, exists, copyDir, copyFile, dirMatches, sameContent, readJSON, readJSONStrict, writeJSON, contentSha, warn, info, isPlainObject, run, samePath,
|
|
8
|
+
asset, exists, listFiles, copyDir, copyFile, dirMatches, sameContent, readJSON, readJSONStrict, writeJSON, contentSha, warn, info, isPlainObject, run, samePath,
|
|
9
9
|
} from './lib.mjs';
|
|
10
10
|
import {
|
|
11
11
|
VERSION, SKILLS, IDE_TARGETS, IDE_OPENCODE_DIR, IDE_OPENCODE_TARGET, IDE_RECOVERY_TARGET, MODULE_CONFIG, wiringFor, PRODUCT_WIRING, PROJECT_FILES, isVerifiedLedger,
|
|
12
|
-
HOOK_WIRING, HOOK_ADAPTERS, CLAUDE_HOOK_ADAPTER, CAPTURE_WIRING, CAPTURE_ADAPTERS,
|
|
12
|
+
HOOK_WIRING, HOOK_ADAPTERS, CLAUDE_HOOK_ADAPTER, CAPTURE_WIRING, CAPTURE_ADAPTERS, AGENT_GUARD_WIRING, AGENT_GUARD_ADAPTERS, REPO_AGENT_GUARD_DEST, agentGuardAdapters,
|
|
13
13
|
legacySkillPairs, REMOVED_SKILLS, LEGACY_REPO_FILES, LEGACY_PRODUCT_FILES, LEGACY_HOOK_SCRIPTS, MANAGED_LEDGER, BACKUP_SUFFIX,
|
|
14
14
|
productConfigPath, PRODUCT_LINK, PRODUCT_LINK_DEFAULT_PATH,
|
|
15
15
|
} from './manifest.mjs';
|
|
16
|
+
import { applyMarkedBlock } from './marked-block.mjs';
|
|
17
|
+
import { AGENTS_MARKERS, agentsBlock, pointerBlock, claudeBlock, readAllowList, RETIRED_ALLOW_ENTRIES, SHIPPED_ALLOW_LISTS } from './agent-rules.mjs';
|
|
16
18
|
|
|
17
19
|
// A git pathspec (forward slashes, relative to a repo root) for `dest` under `root`. Actions carry
|
|
18
20
|
// these so `yad update --push` can stage an EXPLICIT allowlist of exactly what it wrote per repo —
|
|
@@ -52,7 +54,41 @@ const dirAction = (scope, item, src, dest, { root } = {}) => ({
|
|
|
52
54
|
status: !exists(dest) ? 'missing' : dirMatches(src, dest) ? 'ok' : 'outdated',
|
|
53
55
|
root,
|
|
54
56
|
paths: root ? [rel(root, dest)] : [],
|
|
57
|
+
// The template's own files, one path each — for staging a folder that is already right on disk without
|
|
58
|
+
// sweeping in a person's own files beside them (`yad update --open-pr` restages; E157 update review 6).
|
|
59
|
+
ownPaths: () => (root ? listFiles(src).map((f) => rel(root, path.join(dest, f))) : []),
|
|
55
60
|
apply: () => copyDir(src, dest),
|
|
61
|
+
// Writes the template but keeps every file the template does not have (a person's notes, or a file an older
|
|
62
|
+
// yadflow shipped) — for `yad update --open-pr`, which an agent runs without asking (E157 update review 7).
|
|
63
|
+
// The kept files are moved aside and back, so their bytes, modes and links are untouched. Returns them,
|
|
64
|
+
// relative to `root`.
|
|
65
|
+
applyKeepingOwn: () => {
|
|
66
|
+
const shipped = listFiles(src);
|
|
67
|
+
const theirs = new Set(shipped);
|
|
68
|
+
// A path where the template now has a folder, or under a name the template now has as a file, is an older
|
|
69
|
+
// template's shape (a file swapped for a folder): it goes, as `yad update` always did, or it could never
|
|
70
|
+
// come back.
|
|
71
|
+
const clash = (f) => shipped.some((t) => t.startsWith(`${f}${path.sep}`) || f.startsWith(`${t}${path.sep}`));
|
|
72
|
+
const own = exists(dest) ? listFiles(dest).filter((f) => !theirs.has(f) && !clash(f)) : [];
|
|
73
|
+
if (!own.length) { copyDir(src, dest); return []; }
|
|
74
|
+
const aside = `${dest}.yad-keep-${process.pid}`;
|
|
75
|
+
const moved = [];
|
|
76
|
+
const stuck = [];
|
|
77
|
+
try {
|
|
78
|
+
for (const f of own) { fs.mkdirSync(path.dirname(path.join(aside, f)), { recursive: true }); fs.renameSync(path.join(dest, f), path.join(aside, f)); moved.push(f); }
|
|
79
|
+
copyDir(src, dest);
|
|
80
|
+
} finally {
|
|
81
|
+
// Back even when the copy failed. One that cannot go back stays in the side folder, which is named, never
|
|
82
|
+
// removed.
|
|
83
|
+
for (const f of moved) {
|
|
84
|
+
try { fs.mkdirSync(path.dirname(path.join(dest, f)), { recursive: true }); fs.renameSync(path.join(aside, f), path.join(dest, f)); } catch { stuck.push(f); }
|
|
85
|
+
}
|
|
86
|
+
if (stuck.length) warn(`${stuck.length} of your own file(s) could not go back into ${dest}; they are in ${aside}`);
|
|
87
|
+
else fs.rmSync(aside, { recursive: true, force: true });
|
|
88
|
+
}
|
|
89
|
+
// Only the files back in place: one left in the side folder is said by the warning above.
|
|
90
|
+
return own.filter((f) => !stuck.includes(f)).map((f) => (root ? rel(root, path.join(dest, f)) : f));
|
|
91
|
+
},
|
|
56
92
|
});
|
|
57
93
|
|
|
58
94
|
// ---- managed-file provenance (#164) --------------------------------------------------------
|
|
@@ -145,6 +181,7 @@ const displayTarget = (value) => {
|
|
|
145
181
|
try { return JSON.stringify(value) ?? String(value); } catch { return String(value); }
|
|
146
182
|
};
|
|
147
183
|
const ideTargetError = (message) => Object.assign(new Error(message), { code: IDE_TARGET_ERROR_CODE });
|
|
184
|
+
const isDirectory = (full) => { try { return fs.statSync(full).isDirectory(); } catch { return false; } };
|
|
148
185
|
const lstatIfPresent = (full) => {
|
|
149
186
|
try {
|
|
150
187
|
return fs.lstatSync(full);
|
|
@@ -282,7 +319,7 @@ export function safeIdeTargetStateFor(root, input) {
|
|
|
282
319
|
// sight in a repo that uses Cursor for rules alone, and `.claude/` in one that only ever set
|
|
283
320
|
// permissions. Detecting on the bare directory meant that adding `.cursor` to the supported list
|
|
284
321
|
// silently enrolled every such project: no `ideTargets` in the stamp, so this fallback runs, `.cursor`
|
|
285
|
-
// is "detected", and the next `yad check --fix` writes
|
|
322
|
+
// is "detected", and the next `yad check --fix` writes 39 skill folders into `.cursor/skills/`, adds
|
|
286
323
|
// `.cursor/hooks.json`, and stamps the target permanently — for a team that never asked. Requiring
|
|
287
324
|
// `<ide>/skills/` (or `.opencode/commands/`) means detection finds only a directory yad already
|
|
288
325
|
// installs into, which is the question this function was always trying to answer.
|
|
@@ -872,6 +909,14 @@ export function repoActions(root, repo) {
|
|
|
872
909
|
|| actions.some((a) => a.status !== 'missing' && a.item.startsWith('checks/'));
|
|
873
910
|
const link = productLinkAction(root, repo, repoRoot);
|
|
874
911
|
if (link) actions.push(link);
|
|
912
|
+
// E158: the short rules block, in a repo cloned here that is not the Product itself (a monorepo entry has
|
|
913
|
+
// the Product's full block in the same file). Not relabelled here: like the wiring, it is `new` for `yad
|
|
914
|
+
// update` only on a wired repo (below), so update never does a repo's one-time setup.
|
|
915
|
+
if (!samePath(repoRoot, path.resolve(root)) && isDirectory(repoRoot)) {
|
|
916
|
+
actions.push(...agentFileActions(repoRoot, ideTargetsFor(root), { scope: repo.name, lines: pointerBlock(), relabel: false }));
|
|
917
|
+
// E158b: the agent guard and the read-only allow list, so a session opened in the code repo has them too.
|
|
918
|
+
actions.push(...repoAgentGuardActions(repoRoot, ideTargetsFor(root), { scope: repo.name, ledger }));
|
|
919
|
+
}
|
|
875
920
|
if (!wired) return actions;
|
|
876
921
|
// The record is not a template: an absent one on a wired repo is always `new` (nothing to respect).
|
|
877
922
|
const neverWritten = (a) => !a.managed || !ledger[rel(a.managed.root, a.managed.dest)];
|
|
@@ -1147,9 +1192,12 @@ export function hookMatcherFires(settings, adapter = CLAUDE_HOOK_ADAPTER) {
|
|
|
1147
1192
|
// bytes against — the file belongs to the team and we own exactly one entry inside it. So it is also
|
|
1148
1193
|
// deliberately NOT recorded in `.sdlc/managed.json` (recordManagedWrites only records a dest that
|
|
1149
1194
|
// byte-matches its src); the marker above is its provenance instead.
|
|
1150
|
-
|
|
1195
|
+
const unparsedSaid = new Set();
|
|
1196
|
+
// `where` names a connected code repo in the warnings (E158b); the Product's own files need no name.
|
|
1197
|
+
function hookSettingsAction(root, adapter, merge = (obj) => mergeHookSettings(obj, adapter), where = null) {
|
|
1151
1198
|
const ide = adapter.target;
|
|
1152
1199
|
const relDest = adapter.settings;
|
|
1200
|
+
const named = where ? `${where}/${relDest}` : relDest;
|
|
1153
1201
|
const dest = path.join(root, relDest);
|
|
1154
1202
|
const raw = exists(dest) ? fs.readFileSync(dest, 'utf8') : null;
|
|
1155
1203
|
let parsed = null;
|
|
@@ -1165,7 +1213,10 @@ function hookSettingsAction(root, adapter) {
|
|
|
1165
1213
|
// every other entry in that allowlist is a file yad wrote in full. This one the team co-owns, so
|
|
1166
1214
|
// staging it wholesale would sweep their unrelated working-tree edits into a `chore(yad-update)`
|
|
1167
1215
|
// commit pushed straight to the default branch, bypassing review. The entry is theirs to commit.
|
|
1168
|
-
|
|
1216
|
+
// `shared` names the file for `yad update --open-pr`, which stages it only when the change is yad's alone
|
|
1217
|
+
// (reconcile; E157 update review 11): without it a merged update ships a hook script nothing runs.
|
|
1218
|
+
// `mergeShared` adds yad's entry to a settings object, so reconcile can tell a file that is yad's alone.
|
|
1219
|
+
const base = { scope: ide, item: path.basename(relDest), root, paths: [], shared: relDest, mergeShared: merge };
|
|
1169
1220
|
// A settings file we cannot READ is never rewritten — not even by `--overwrite-local`.
|
|
1170
1221
|
//
|
|
1171
1222
|
// For a managed file, `--overwrite-local` restores the shipped template, which is coherent. Here
|
|
@@ -1179,15 +1230,19 @@ function hookSettingsAction(root, adapter) {
|
|
|
1179
1230
|
// hand — "replace them with `yad update --overwrite-local`" — advice that can never clear this,
|
|
1180
1231
|
// since this action deliberately writes nothing. The specific reason has to surface either way.
|
|
1181
1232
|
if (unreadable) {
|
|
1182
|
-
|
|
1183
|
-
|
|
1233
|
+
// Said once per file, not once per action: up to four share `.claude/settings.json` (E158 review 1).
|
|
1234
|
+
if (!unparsedSaid.has(`${dest}\0${raw}`)) {
|
|
1235
|
+
unparsedSaid.add(`${dest}\0${raw}`);
|
|
1236
|
+
warn(`${named} does not parse — yad's entries in it (hooks, the read-only allow list) cannot be written; fix the JSON, then re-run \`yad check --fix\``);
|
|
1237
|
+
}
|
|
1238
|
+
return { ...base, status: 'modified', writesNothing: true, apply: () => {} };
|
|
1184
1239
|
}
|
|
1185
|
-
const { changed, unreadable: unmergeable } =
|
|
1240
|
+
const { changed, unreadable: unmergeable } = merge(parsed);
|
|
1186
1241
|
// Same treatment as a file that does not parse, and for the same reason: everything in it is the
|
|
1187
1242
|
// team's, there is no shipped template to restore, and `--overwrite-local` must not invent one.
|
|
1188
1243
|
if (unmergeable) {
|
|
1189
|
-
warn(`${
|
|
1190
|
-
return { ...base, status: 'modified', apply: () => {} };
|
|
1244
|
+
warn(`${named}: ${unmergeable} — the ${adapter.label || 'ledger guard'} cannot be wired without discarding what is there; fix it by hand, then re-run \`yad check --fix\``);
|
|
1245
|
+
return { ...base, status: 'modified', writesNothing: true, apply: () => {} };
|
|
1191
1246
|
}
|
|
1192
1247
|
return {
|
|
1193
1248
|
...base,
|
|
@@ -1209,23 +1264,91 @@ function hookSettingsAction(root, adapter) {
|
|
|
1209
1264
|
let current;
|
|
1210
1265
|
try { current = JSON.parse(fs.readFileSync(dest, 'utf8')); } catch { /* unreadable — refused below */ }
|
|
1211
1266
|
if (!current || typeof current !== 'object' || Array.isArray(current)) {
|
|
1212
|
-
warn(`${
|
|
1267
|
+
warn(`${named} does not parse — left untouched; fix the JSON, then re-run \`yad check --fix\``);
|
|
1213
1268
|
return;
|
|
1214
1269
|
}
|
|
1215
|
-
const merged =
|
|
1270
|
+
const merged = merge(current);
|
|
1216
1271
|
if (merged.unreadable) {
|
|
1217
|
-
warn(`${
|
|
1272
|
+
warn(`${named}: ${merged.unreadable} — left untouched; fix it by hand, then re-run \`yad check --fix\``);
|
|
1218
1273
|
return;
|
|
1219
1274
|
}
|
|
1220
1275
|
writeJSON(dest, merged.settings);
|
|
1221
1276
|
return;
|
|
1222
1277
|
}
|
|
1223
1278
|
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
1224
|
-
writeJSON(dest,
|
|
1279
|
+
writeJSON(dest, merge({}).settings);
|
|
1225
1280
|
},
|
|
1226
1281
|
};
|
|
1227
1282
|
}
|
|
1228
1283
|
|
|
1284
|
+
// A block yad owns inside a file the team owns (E158): AGENTS.md and CLAUDE.md. Like the agent settings file
|
|
1285
|
+
// above, the file is the team's, so `paths` is EMPTY (`yad update --push` never stages it) and `shared` names it
|
|
1286
|
+
// for `yad update --open-pr`, which stages it only when the change is yad's block alone (reconcile). It is
|
|
1287
|
+
// text, not JSON: `mergeShared` puts the block into a file's text.
|
|
1288
|
+
function blockState(dest, opts) {
|
|
1289
|
+
let raw = null;
|
|
1290
|
+
try {
|
|
1291
|
+
const st = lstatIfPresent(dest);
|
|
1292
|
+
if (st) raw = st.isFile() ? fs.readFileSync(dest, 'utf8') : undefined;
|
|
1293
|
+
} catch { raw = undefined; }
|
|
1294
|
+
// Not a plain file yad can read (a folder, a symbolic link that could point anywhere, no permission).
|
|
1295
|
+
if (raw === undefined) return { raw, state: 'unreadable', refused: 'it is not a file yad can read' };
|
|
1296
|
+
const now = applyMarkedBlock(raw, opts);
|
|
1297
|
+
if (now.refused) return { raw, state: 'refused', refused: now.refused };
|
|
1298
|
+
// A file with no block is `missing` too: the BLOCK is missing. So `yad update` adds it only where it adds
|
|
1299
|
+
// other missing files (the Product, a wired repo), never to the team's own AGENTS.md in a repo yad never set up.
|
|
1300
|
+
return { raw, state: now.status === 'ok' ? 'ok' : now.status === 'new' ? 'missing' : 'outdated', refused: null, exists: raw !== null };
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
function markedBlockAction(root, relDest, lines, { scope = 'product' } = {}) {
|
|
1304
|
+
const dest = path.join(root, relDest);
|
|
1305
|
+
const opts = { ...AGENTS_MARKERS, lines };
|
|
1306
|
+
const base = { scope, item: relDest, root, paths: [], shared: relDest, kind: 'text', mergeShared: (text) => applyMarkedBlock(text, opts) };
|
|
1307
|
+
const { state, refused } = blockState(dest, opts);
|
|
1308
|
+
// Never written, said once at plan time. Markers yad cannot trust are never guessed around: the team's
|
|
1309
|
+
// text is left as it is (as a broken config.yaml region is, cli/lifecycle.mjs).
|
|
1310
|
+
if (refused) {
|
|
1311
|
+
warn(`${scope}/${relDest}: ${refused} — the yadflow rules block was left out; ${state === 'refused' ? 'fix the markers (or delete both to have the block added again)' : 'make it a plain file'}, then re-run \`yad check --fix\``);
|
|
1312
|
+
return { ...base, status: 'modified', writesNothing: true, apply: () => {} };
|
|
1313
|
+
}
|
|
1314
|
+
return {
|
|
1315
|
+
...base,
|
|
1316
|
+
status: state,
|
|
1317
|
+
// Re-read at apply() time: the file may have been written since the plan was built.
|
|
1318
|
+
apply: () => {
|
|
1319
|
+
const now = blockState(dest, opts);
|
|
1320
|
+
if (now.refused) { warn(`${scope}/${relDest}: ${now.refused} — left untouched`); return; }
|
|
1321
|
+
if (now.state === 'ok') return;
|
|
1322
|
+
const next = applyMarkedBlock(now.raw, opts);
|
|
1323
|
+
fs.mkdirSync(path.dirname(dest), { recursive: true });
|
|
1324
|
+
fs.writeFileSync(dest, next.text);
|
|
1325
|
+
},
|
|
1326
|
+
};
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
// The always-read instruction files (E158): AGENTS.md with yad's rules block, which Codex, Cursor, Copilot and
|
|
1330
|
+
// Gemini read, and, for a project that installs for Claude Code, CLAUDE.md importing it. `lines` is the
|
|
1331
|
+
// Product's full block by default; a connected code repo gets the short pointer block (`repoActions`).
|
|
1332
|
+
// Relabelled `new`, so `yad update` brings them to an install that predates them.
|
|
1333
|
+
export function agentFileActions(root, ideTargets = ideTargetsFor(root), { scope = 'product', lines = agentsBlock(), relabel = true } = {}) {
|
|
1334
|
+
const actions = [markedBlockAction(root, 'AGENTS.md', lines, { scope })];
|
|
1335
|
+
// Only the target's name is read here: nothing is written under it.
|
|
1336
|
+
if (canonicalIdeTargets(ideTargets).includes('.claude')) actions.push(markedBlockAction(root, 'CLAUDE.md', claudeBlock(), { scope }));
|
|
1337
|
+
return relabel ? actions.map(asNew) : actions;
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
// The same files, for `yad doctor`: each one's state, with nothing printed. `state` is ok | outdated | missing (no
|
|
1341
|
+
// block; `exists` says whether the file is there) | refused (markers yad cannot trust) | unreadable (not a plain
|
|
1342
|
+
// file).
|
|
1343
|
+
export function agentFilesState(root, ideTargets = ideTargetsFor(root), lines = agentsBlock()) {
|
|
1344
|
+
const files = [['AGENTS.md', lines]];
|
|
1345
|
+
if (canonicalIdeTargets(ideTargets).includes('.claude')) files.push(['CLAUDE.md', claudeBlock()]);
|
|
1346
|
+
return files.map(([file, l]) => {
|
|
1347
|
+
const { state, refused, exists = true } = blockState(path.join(root, file), { ...AGENTS_MARKERS, lines: l });
|
|
1348
|
+
return { file, state, refused, exists };
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1229
1352
|
// Harness-hook wiring on the Product: the guard script plus, per IDE target that defines a hook protocol,
|
|
1230
1353
|
// the entry that invokes it. Verified-only exactly like `productActions` — with a local ledger it is
|
|
1231
1354
|
// locally owned, the hand-edit the authoring skills describe is CORRECT, and a guard would be wrong.
|
|
@@ -1340,14 +1463,25 @@ export function orphanHookActions(root, ideTargets = ideTargetsFor(root)) {
|
|
|
1340
1463
|
// and `yad check` print it.
|
|
1341
1464
|
export const GIT_HOOK_MARKER = '# yadflow ledger-guard (E48)';
|
|
1342
1465
|
const shQuote = (s) => `'${String(s).replace(/'/g, `'\\''`)}'`;
|
|
1343
|
-
|
|
1466
|
+
// The last two comment lines of the script, today's first. The earlier ones are kept so a copy yad wrote
|
|
1467
|
+
// before is still known as yad's own (`orphanGitHookActions` removes only yad's bytes).
|
|
1468
|
+
const PRE_COMMIT_NOTES = [
|
|
1469
|
+
['# node, or no guard script, it allows. A person can skip it once with YAD_HOOK_DISABLE=1 (never an AI',
|
|
1470
|
+
'# agent). Git runs it from the top of the repo. yad rewrites this file; to stop it, delete the file.'],
|
|
1471
|
+
// Up to E158.
|
|
1472
|
+
['# node, or no guard script, it allows. Skip it once with YAD_HOOK_DISABLE=1. Git runs it from the top',
|
|
1473
|
+
'# of the repo. yad rewrites this file; to stop it, delete the file.'],
|
|
1474
|
+
];
|
|
1475
|
+
export const gitPreCommitScript = (prefix = '') => preCommitScript(prefix, PRE_COMMIT_NOTES[0]);
|
|
1476
|
+
// Every text yad has written for this hook, today's first.
|
|
1477
|
+
export const gitPreCommitScripts = (prefix = '') => PRE_COMMIT_NOTES.map((notes) => preCommitScript(prefix, notes));
|
|
1478
|
+
function preCommitScript(prefix, notes) {
|
|
1344
1479
|
return [
|
|
1345
1480
|
'#!/bin/sh',
|
|
1346
1481
|
`${GIT_HOOK_MARKER} — installed in this clone by \`yad check --fix\`.`,
|
|
1347
1482
|
'# Refuses a commit that changes a file only CI may change on a verified Product (the gate ledger and',
|
|
1348
1483
|
'# the Product index), the same files the `ledger-guard` check in CI refuses. It fails open: with no',
|
|
1349
|
-
|
|
1350
|
-
'# of the repo. yad rewrites this file; to stop it, delete the file.',
|
|
1484
|
+
...notes,
|
|
1351
1485
|
`guard=${shQuote(`${prefix}hooks/ledger-guard.mjs`)}`,
|
|
1352
1486
|
'command -v node >/dev/null 2>&1 || exit 0',
|
|
1353
1487
|
'[ -f "$guard" ] || exit 0',
|
|
@@ -1405,7 +1539,9 @@ export function gitHookState(root) {
|
|
|
1405
1539
|
let runnable = true;
|
|
1406
1540
|
if (process.platform !== 'win32') { try { runnable = (fs.statSync(file).mode & 0o111) !== 0; } catch { runnable = false; } }
|
|
1407
1541
|
if (text === expected && runnable) return { applies: true, file, expected, prefix, state: 'ok' };
|
|
1408
|
-
|
|
1542
|
+
// `earlier`: a text an earlier yad wrote, so nothing in it is anyone's edit.
|
|
1543
|
+
const why = text === expected ? 'not-executable' : gitPreCommitScripts(prefix).includes(text) ? 'earlier' : 'changed';
|
|
1544
|
+
return { applies: true, file, expected, prefix, state: 'outdated', why };
|
|
1409
1545
|
}
|
|
1410
1546
|
|
|
1411
1547
|
// The install action. 'foreign' and 'hooks-path' build no action — there is nothing yad may write —
|
|
@@ -1416,9 +1552,8 @@ export function gitHookActions(root) {
|
|
|
1416
1552
|
const status = st.state === 'missing' ? 'new' : st.state;
|
|
1417
1553
|
// An outdated copy may carry a person's edit below our marker, so it is saved beside itself first —
|
|
1418
1554
|
// the same rule `wiredFileAction` keeps for content it cannot prove it wrote. Not when only the execute
|
|
1419
|
-
// bit is missing: nothing of anyone's is being replaced then.
|
|
1420
|
-
const
|
|
1421
|
-
const backup = st.state === 'outdated' && !sameBytes ? backupPathFor(st.file) : null;
|
|
1555
|
+
// bit is missing, nor when it is a text an earlier yad wrote: nothing of anyone's is being replaced then.
|
|
1556
|
+
const backup = st.state === 'outdated' && st.why === 'changed' ? backupPathFor(st.file) : null;
|
|
1422
1557
|
return [{
|
|
1423
1558
|
scope: 'product',
|
|
1424
1559
|
item: 'pre-commit git hook (this clone)',
|
|
@@ -1445,7 +1580,7 @@ export function orphanGitHookActions(root) {
|
|
|
1445
1580
|
const file = path.resolve(root, hookRel);
|
|
1446
1581
|
let text;
|
|
1447
1582
|
try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
|
|
1448
|
-
if (
|
|
1583
|
+
if (!gitPreCommitScripts(prefix).includes(text)) return [];
|
|
1449
1584
|
return [{ scope: 'product', item: 'pre-commit git hook (this clone) (removed)', status: 'removed', root, paths: [], apply: () => fs.rmSync(file, { force: true }) }];
|
|
1450
1585
|
}
|
|
1451
1586
|
|
|
@@ -1527,6 +1662,175 @@ export function orphanCaptureHookActions(root, ideTargets = ideTargetsFor(root))
|
|
|
1527
1662
|
return actions;
|
|
1528
1663
|
}
|
|
1529
1664
|
|
|
1665
|
+
// The read-only yad commands, pre-approved for Claude Code (E158, issue #353): `readAllowList` added to
|
|
1666
|
+
// `permissions.allow` in `.claude/settings.json`. Additive: the team's own entries are kept, and an entry of
|
|
1667
|
+
// ours already there is not added twice. A shape it cannot read is refused, as the hook merge refuses one.
|
|
1668
|
+
export function mergeAllowList(input) {
|
|
1669
|
+
if (isPlainObject(input)) {
|
|
1670
|
+
if (Object.hasOwn(input, 'permissions') && !isPlainObject(input.permissions)) return { settings: input, changed: false, unreadable: 'permissions is not an object' };
|
|
1671
|
+
if (isPlainObject(input.permissions) && Object.hasOwn(input.permissions, 'allow') && !Array.isArray(input.permissions.allow)) {
|
|
1672
|
+
return { settings: input, changed: false, unreadable: 'permissions.allow is not a list' };
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
const settings = { ...(isPlainObject(input) ? input : {}) };
|
|
1676
|
+
const permissions = { ...(isPlainObject(settings.permissions) ? settings.permissions : {}) };
|
|
1677
|
+
const allow = Array.isArray(permissions.allow) ? [...permissions.allow] : [];
|
|
1678
|
+
const missing = readAllowList().filter((e) => !allow.includes(e));
|
|
1679
|
+
if (!missing.length) return { settings, changed: false };
|
|
1680
|
+
permissions.allow = [...allow, ...missing];
|
|
1681
|
+
settings.permissions = permissions;
|
|
1682
|
+
return { settings, changed: true };
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
// The settings action that writes it, for a configured Product that installs for Claude Code.
|
|
1686
|
+
export const ALLOW_LIST_ADAPTER = Object.freeze({ target: '.claude', settings: '.claude/settings.json', label: 'read-only yad allow list' });
|
|
1687
|
+
export function allowListActions(root, ideTargets = ideTargetsFor(root)) {
|
|
1688
|
+
if (!exists(productConfigPath(root)) || !safeIdeTargetsFor(root, ideTargets).includes('.claude')) return [];
|
|
1689
|
+
return [asNew(allowListAction(root))];
|
|
1690
|
+
}
|
|
1691
|
+
// `allowList` marks it for setup, which shows the list before it is first written.
|
|
1692
|
+
const allowListAction = (at) => ({ ...hookSettingsAction(at, ALLOW_LIST_ADAPTER, mergeAllowList), item: `${path.basename(ALLOW_LIST_ADAPTER.settings)} (read-only yad commands)`, allowList: true });
|
|
1693
|
+
|
|
1694
|
+
// yad's allow-list entries that should no longer be there: all of them once `.claude` has left the IDE targets,
|
|
1695
|
+
// and, while it is a target, those a later yadflow stopped pre-approving (`RETIRED_ALLOW_ENTRIES`). Only these
|
|
1696
|
+
// exact strings come out; every other entry is the team's and stays. A file that does not parse is left alone.
|
|
1697
|
+
//
|
|
1698
|
+
// A team may type one of yad's strings by hand (`Bash(yad status:*)`), so with `.claude` gone the list comes out
|
|
1699
|
+
// only when ALL the entries of a list yad wrote are there (today's, or one an older release wrote and no
|
|
1700
|
+
// `check --fix` brought up to date, `SHIPPED_ALLOW_LISTS`): that is yad's list, not a hand-picked line.
|
|
1701
|
+
export function orphanAllowListActions(root, ideTargets = ideTargetsFor(root)) {
|
|
1702
|
+
if (!exists(productConfigPath(root))) return [];
|
|
1703
|
+
return allowListOrphans(root, safeIdeTargetsFor(root, ideTargets).includes('.claude'));
|
|
1704
|
+
}
|
|
1705
|
+
// `kept`: `.claude` is still a target. `scope`: the line's scope in the report (a code repo's name, E158b).
|
|
1706
|
+
function allowListOrphans(root, kept, scope = ALLOW_LIST_ADAPTER.target) {
|
|
1707
|
+
const file = path.join(root, ALLOW_LIST_ADAPTER.settings);
|
|
1708
|
+
if (!exists(file)) return [];
|
|
1709
|
+
let wholeList = false;
|
|
1710
|
+
if (!kept) {
|
|
1711
|
+
try {
|
|
1712
|
+
const allow = JSON.parse(fs.readFileSync(file, 'utf8'))?.permissions?.allow;
|
|
1713
|
+
wholeList = Array.isArray(allow) && [readAllowList(), ...SHIPPED_ALLOW_LISTS].some((list) => list.every((e) => allow.includes(e)));
|
|
1714
|
+
} catch { return []; }
|
|
1715
|
+
}
|
|
1716
|
+
const gone = new Set(wholeList ? [...readAllowList(), ...SHIPPED_ALLOW_LISTS.flat(), ...RETIRED_ALLOW_ENTRIES] : RETIRED_ALLOW_ENTRIES);
|
|
1717
|
+
if (!gone.size) return [];
|
|
1718
|
+
const without = (obj) => {
|
|
1719
|
+
if (!isPlainObject(obj) || !isPlainObject(obj.permissions) || !Array.isArray(obj.permissions.allow)) return null;
|
|
1720
|
+
const allow = obj.permissions.allow.filter((e) => !gone.has(e));
|
|
1721
|
+
return allow.length === obj.permissions.allow.length ? null : { ...obj, permissions: { ...obj.permissions, allow } };
|
|
1722
|
+
};
|
|
1723
|
+
let parsed;
|
|
1724
|
+
try { parsed = JSON.parse(fs.readFileSync(file, 'utf8')); } catch { return []; }
|
|
1725
|
+
if (!without(parsed)) return [];
|
|
1726
|
+
return [{
|
|
1727
|
+
scope,
|
|
1728
|
+
item: `${path.basename(file)} (read-only yad commands removed)`,
|
|
1729
|
+
status: 'removed',
|
|
1730
|
+
root,
|
|
1731
|
+
paths: [],
|
|
1732
|
+
apply: () => {
|
|
1733
|
+
let current;
|
|
1734
|
+
try { current = JSON.parse(fs.readFileSync(file, 'utf8')); } catch { return; }
|
|
1735
|
+
const next = without(current);
|
|
1736
|
+
if (next) writeJSON(file, next);
|
|
1737
|
+
},
|
|
1738
|
+
}];
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
// The agent guard (E158): the script, and per IDE target with a hook protocol the entry that runs it before
|
|
1742
|
+
// every shell command the agent sends. On every configured Product, in both ledger modes (see the manifest).
|
|
1743
|
+
// The script and its entries land together, for the reason `hookActions` gives.
|
|
1744
|
+
export function agentGuardActions(root, ideTargets = ideTargetsFor(root)) {
|
|
1745
|
+
if (!exists(productConfigPath(root))) return [];
|
|
1746
|
+
const ledger = readManagedLedger(root);
|
|
1747
|
+
const actions = AGENT_GUARD_WIRING.map((w) =>
|
|
1748
|
+
wiredFileAction('product', w.dest, asset(w.src), path.join(root, w.dest), { root, exec: !!w.exec, ledger }),
|
|
1749
|
+
);
|
|
1750
|
+
for (const ide of safeIdeTargetsFor(root, ideTargets)) {
|
|
1751
|
+
const adapter = AGENT_GUARD_ADAPTERS[ide];
|
|
1752
|
+
if (adapter) actions.push(hookSettingsAction(root, adapter));
|
|
1753
|
+
}
|
|
1754
|
+
return actions.map(asNew);
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
// An agent-guard entry for a target that left `ideTargets`: only OUR entry comes out, as
|
|
1758
|
+
// `orphanCaptureHookActions` does it. The script stays while the Product is configured (a remaining target
|
|
1759
|
+
// may still run it; with none, it is one file nothing runs, and `yad check` names nothing wrong with it).
|
|
1760
|
+
export function orphanAgentGuardActions(root, ideTargets = ideTargetsFor(root)) {
|
|
1761
|
+
if (!exists(productConfigPath(root))) return [];
|
|
1762
|
+
return agentGuardOrphans(root, new Set(safeIdeTargetsFor(root, ideTargets)), AGENT_GUARD_ADAPTERS);
|
|
1763
|
+
}
|
|
1764
|
+
function agentGuardOrphans(root, kept, adapters, scope = null) {
|
|
1765
|
+
const actions = [];
|
|
1766
|
+
for (const adapter of Object.values(adapters)) {
|
|
1767
|
+
if (kept.has(adapter.target)) continue;
|
|
1768
|
+
const settingsPath = path.join(root, adapter.settings);
|
|
1769
|
+
if (!exists(settingsPath)) continue;
|
|
1770
|
+
let parsed;
|
|
1771
|
+
try { parsed = JSON.parse(fs.readFileSync(settingsPath, 'utf8')); } catch { continue; }
|
|
1772
|
+
if (!isPlainObject(parsed) || !unmergeHookSettings(parsed, adapter).changed) continue;
|
|
1773
|
+
actions.push({
|
|
1774
|
+
scope: scope || adapter.target,
|
|
1775
|
+
item: `${path.basename(adapter.settings)} (agent guard entry removed)`,
|
|
1776
|
+
status: 'removed',
|
|
1777
|
+
root,
|
|
1778
|
+
paths: [],
|
|
1779
|
+
apply: () => {
|
|
1780
|
+
let current;
|
|
1781
|
+
try { current = JSON.parse(fs.readFileSync(settingsPath, 'utf8')); } catch { return; }
|
|
1782
|
+
if (!isPlainObject(current)) return;
|
|
1783
|
+
const { settings, changed } = unmergeHookSettings(current, adapter);
|
|
1784
|
+
if (changed) writeJSON(settingsPath, settings);
|
|
1785
|
+
},
|
|
1786
|
+
});
|
|
1787
|
+
}
|
|
1788
|
+
return actions;
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
// E158b: the agent guard and the read-only allow list in a connected code repo, so a session opened there has
|
|
1792
|
+
// them too. The script goes in `checks/` (REPO_AGENT_GUARD_DEST); the entries go in the repo's own settings
|
|
1793
|
+
// files, which stay the team's: `paths` is empty, so `--push` never stages them, and `--open-pr` stages one only
|
|
1794
|
+
// when the change is yad's alone (reconcile). The tools are the Product's IDE targets, as CLAUDE.md's are. A
|
|
1795
|
+
// target folder in the repo that is a link or a file is named and skipped, never written through. Not
|
|
1796
|
+
// relabelled here: `repoActions` makes them `new` for `yad update` only on a wired repo.
|
|
1797
|
+
export function repoAgentGuardActions(repoRoot, ideTargets, { scope, ledger = readManagedLedger(repoRoot) }) {
|
|
1798
|
+
const targets = repoTargets(repoRoot, ideTargets, scope);
|
|
1799
|
+
const adapters = agentGuardAdapters(REPO_AGENT_GUARD_DEST);
|
|
1800
|
+
const settings = targets.filter((ide) => adapters[ide]).map((ide) => ({ ...hookSettingsAction(repoRoot, adapters[ide], undefined, scope), scope, item: `${adapters[ide].settings} (agent guard)` }));
|
|
1801
|
+
if (targets.includes('.claude')) settings.push({ ...hookSettingsAction(repoRoot, ALLOW_LIST_ADAPTER, mergeAllowList, scope), scope, item: `${ALLOW_LIST_ADAPTER.settings} (read-only yad commands)`, allowList: true });
|
|
1802
|
+
if (!settings.length) return [];
|
|
1803
|
+
const script = AGENT_GUARD_WIRING[0];
|
|
1804
|
+
return [wiredFileAction(scope, REPO_AGENT_GUARD_DEST, asset(script.src), path.join(repoRoot, REPO_AGENT_GUARD_DEST), { root: repoRoot, ledger }), ...settings];
|
|
1805
|
+
}
|
|
1806
|
+
|
|
1807
|
+
// The same entries for a target that left, in a connected code repo: only yad's come out. The script stays.
|
|
1808
|
+
// A tool folder that is a link or not a folder is never written through — a target or not: removing an entry
|
|
1809
|
+
// would change the file the link points at (the Product's own, when it points there).
|
|
1810
|
+
export function repoOrphanAgentGuardActions(repoRoot, ideTargets, { scope }) {
|
|
1811
|
+
if (!isDirectory(repoRoot)) return [];
|
|
1812
|
+
const kept = new Set(repoTargets(repoRoot, ideTargets, null));
|
|
1813
|
+
const linked = (ide) => { const st = lstatIfPresent(path.join(repoRoot, ide)); return !!st && (st.isSymbolicLink() || !st.isDirectory()); };
|
|
1814
|
+
const adapters = Object.fromEntries(Object.entries(agentGuardAdapters(REPO_AGENT_GUARD_DEST)).filter(([ide]) => !linked(ide)));
|
|
1815
|
+
return [
|
|
1816
|
+
...agentGuardOrphans(repoRoot, kept, adapters, scope),
|
|
1817
|
+
...(linked('.claude') ? [] : allowListOrphans(repoRoot, kept.has('.claude'), scope)),
|
|
1818
|
+
];
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
// The Product's IDE targets that are safe to write through in a code repo. An unsafe one is named once (when
|
|
1822
|
+
// `scope` is given) and left out.
|
|
1823
|
+
const unsafeRepoSaid = new Set();
|
|
1824
|
+
function repoTargets(repoRoot, ideTargets, scope) {
|
|
1825
|
+
const { targets, unsafe } = safeIdeTargetStateFor(repoRoot, ideTargets);
|
|
1826
|
+
for (const u of unsafe) {
|
|
1827
|
+
if (!scope || unsafeRepoSaid.has(`${repoRoot}\0${u.target}`)) continue;
|
|
1828
|
+
unsafeRepoSaid.add(`${repoRoot}\0${u.target}`);
|
|
1829
|
+
warn(`${scope}: ${u.message} — the agent guard and the read-only allow list are not written there`);
|
|
1830
|
+
}
|
|
1831
|
+
return targets;
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1530
1834
|
// ---- the shell-script hooks, retired (E113) -----------------------------------------------------------
|
|
1531
1835
|
//
|
|
1532
1836
|
// Every hook was a bash script until E113; each is now a Node script, and the adapters list the old
|
package/cli/platform.mjs
CHANGED
|
@@ -313,6 +313,27 @@ export function findPrForBranch(platform, branch, { cwd } = {}) {
|
|
|
313
313
|
return { ok: true, number: Number(pr.number), url: pr.url || null };
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
+
// The highest PR/MR number the repo has given out, open or not (`yad gate reopen`, #322): numbers only grow,
|
|
317
|
+
// so every review opened before the reopen is at or below it. `{ ok: true, number }` (null when the repo has
|
|
318
|
+
// none yet), or `{ ok: false, reason }`. Never throws.
|
|
319
|
+
export function newestPrNumber(platform, { cwd } = {}) {
|
|
320
|
+
if (!platformReady(platform)) return { ok: false, reason: `${cliFor(platform) || 'platform CLI'} not available` };
|
|
321
|
+
if (platform === 'gitlab') {
|
|
322
|
+
const r = run('glab', ['api', 'projects/:id/merge_requests?state=all&order_by=created_at&sort=desc&per_page=1'], { cwd });
|
|
323
|
+
if (!r.ok) return { ok: false, reason: r.stderr || 'glab api merge_requests failed' };
|
|
324
|
+
let rows;
|
|
325
|
+
try { rows = JSON.parse(r.stdout); } catch { return { ok: false, reason: 'unreadable glab api response' }; }
|
|
326
|
+
const n = Array.isArray(rows) ? Number(rows[0]?.iid) : NaN;
|
|
327
|
+
return { ok: true, number: Number.isInteger(n) && n > 0 ? n : null };
|
|
328
|
+
}
|
|
329
|
+
const r = run('gh', ['pr', 'list', '--state', 'all', '--limit', '1', '--json', 'number'], { cwd });
|
|
330
|
+
if (!r.ok) return { ok: false, reason: r.stderr || 'gh pr list failed' };
|
|
331
|
+
let rows;
|
|
332
|
+
try { rows = JSON.parse(r.stdout); } catch { return { ok: false, reason: 'unreadable gh pr list response' }; }
|
|
333
|
+
const n = Array.isArray(rows) ? Number(rows[0]?.number) : NaN;
|
|
334
|
+
return { ok: true, number: Number.isInteger(n) && n > 0 ? n : null };
|
|
335
|
+
}
|
|
336
|
+
|
|
316
337
|
// The head/source branch of a PR/MR, so a caller can confirm a number a human typed actually belongs
|
|
317
338
|
// to the review it is about to bind approvals to. Returns { ok, branch }; never throws.
|
|
318
339
|
export function prBranch(platform, n, { cwd } = {}) {
|
package/cli/pr-list.mjs
CHANGED
|
@@ -19,7 +19,7 @@ import { api, httpStatus, loggedIn, repoPathFromGitUrl, shown, whyFailed, PAGE,
|
|
|
19
19
|
const GH_CHECKS = { SUCCESS: 'passing', FAILURE: 'failing', ERROR: 'failing', PENDING: 'running', EXPECTED: 'running' };
|
|
20
20
|
|
|
21
21
|
const GH_QUERY = `query($owner:String!,$name:String!){repository(owner:$owner,name:$name){
|
|
22
|
-
open:pullRequests(states:OPEN,first:${PAGE},orderBy:{field:CREATED_AT,direction:DESC}){totalCount nodes{number isDraft author{__typename login} reviewDecision reviews{totalCount} latestOpinionatedReviews(first:100){nodes{state}} commits(last:1){nodes{commit{statusCheckRollup{state}}}}}}
|
|
22
|
+
open:pullRequests(states:OPEN,first:${PAGE},orderBy:{field:CREATED_AT,direction:DESC}){totalCount nodes{number isDraft headRefName author{__typename login} reviewDecision reviews{totalCount} latestOpinionatedReviews(first:100){nodes{state}} commits(last:1){nodes{commit{statusCheckRollup{state}}}}}}
|
|
23
23
|
merged:pullRequests(states:MERGED,first:${PAGE},orderBy:{field:UPDATED_AT,direction:DESC}){nodes{number mergedAt updatedAt author{__typename login}}}}}`;
|
|
24
24
|
|
|
25
25
|
// GitHub's review state, in the words the standup prints. `none` = no review of any kind yet.
|
|
@@ -64,7 +64,8 @@ export function prTarget({ platform = null, gitUrl = '' } = {}, { runner = run,
|
|
|
64
64
|
// The PRs/MRs of one repo: `{ ok: true, open: [...], merged: [...], openPartial, mergedPartial }` or
|
|
65
65
|
// `{ ok: false, kind, why }`. `sinceMs` bounds the merged list (epoch milliseconds).
|
|
66
66
|
// open: { number, author, draft, checks: passing|failing|running|none|null, review: none|reviewed|approved|changes-requested|null,
|
|
67
|
-
// status? (GitLab's own word), waits? (GitLab: a status that holds the merge)
|
|
67
|
+
// status? (GitLab's own word), waits? (GitLab: a status that holds the merge),
|
|
68
|
+
// branch (the head branch, or null: `yad status` finds the follow-ups by it, #349) }
|
|
68
69
|
// merged: { number, author, mergedAt (ISO) }
|
|
69
70
|
export function listPrs(target, { sinceMs, runner = run, env = process.env, authCache = new Map() } = {}) {
|
|
70
71
|
const t = target?.cli ? target : prTarget(target, { runner, env, authCache });
|
|
@@ -91,6 +92,7 @@ function listGitHub(t, sinceMs, runner) {
|
|
|
91
92
|
number: n.number, author: author(n.author), draft: n.isDraft === true,
|
|
92
93
|
checks: GH_CHECKS[n.commits?.nodes?.[0]?.commit?.statusCheckRollup?.state] || (n.commits?.nodes?.[0]?.commit?.statusCheckRollup ? null : 'none'),
|
|
93
94
|
review: ghReview(n),
|
|
95
|
+
branch: typeof n.headRefName === 'string' ? n.headRefName : null,
|
|
94
96
|
}));
|
|
95
97
|
const nodes = repo.merged.nodes;
|
|
96
98
|
const merged = nodes.filter((n) => Date.parse(n.mergedAt) >= sinceMs).map((n) => ({ number: n.number, author: author(n.author), mergedAt: n.mergedAt }));
|
|
@@ -117,7 +119,7 @@ function listGitLab(t, sinceMs, runner) {
|
|
|
117
119
|
const open = o.body.map((x) => {
|
|
118
120
|
const st = typeof x.detailed_merge_status === 'string' ? x.detailed_merge_status : null;
|
|
119
121
|
const checks = st && Object.hasOwn(GL_CHECKS, st) ? GL_CHECKS[st] : null;
|
|
120
|
-
return { number: x.iid, author: who(x.author), draft: x.draft === true, checks, review: null, ...(st && !checks ? { status: st } : {}), waits: !!st && GL_WAITS.includes(st) };
|
|
122
|
+
return { number: x.iid, author: who(x.author), draft: x.draft === true, checks, review: null, ...(st && !checks ? { status: st } : {}), waits: !!st && GL_WAITS.includes(st), branch: typeof x.source_branch === 'string' ? x.source_branch : null };
|
|
121
123
|
});
|
|
122
124
|
const merged = m.body.filter((x) => Date.parse(x.merged_at) >= sinceMs).map((x) => ({ number: x.iid, author: who(x.author), mergedAt: x.merged_at }));
|
|
123
125
|
return { ...t, ok: true, open, merged, openPartial: o.body.length >= PAGE, mergedPartial: m.body.length >= PAGE };
|
package/cli/product-index.mjs
CHANGED
|
@@ -24,7 +24,7 @@ import { createHash } from 'node:crypto';
|
|
|
24
24
|
import { spawnSync } from 'node:child_process';
|
|
25
25
|
import { isPlainObject, writeJSON, info, warn } from './lib.mjs';
|
|
26
26
|
import { isVerifiedLedger } from './manifest.mjs';
|
|
27
|
-
import { productGit, resolveDefaultBranch } from './productcommit.mjs';
|
|
27
|
+
import { productGit, resolveDefaultBranch, branchToCommitOn } from './productcommit.mjs';
|
|
28
28
|
import {
|
|
29
29
|
epicIds, epicRel, epicRoot, unlistedLedgerDirs, parseFrontmatter, lineageFrom, stepStatus, STEP_STATES,
|
|
30
30
|
FOUNDATION_EPIC, FOUNDATION_TITLE, titleOf,
|
|
@@ -273,8 +273,11 @@ export function uncommittedIndexInputs(root, commits = null) {
|
|
|
273
273
|
export function refreshIndexAfterWrite(root, productConfig, { quiet = false } = {}) {
|
|
274
274
|
if (isVerifiedLedger(productConfig) || !fs.existsSync(path.join(root, '.git'))) return false;
|
|
275
275
|
const git = productGit(root);
|
|
276
|
-
const
|
|
277
|
-
|
|
276
|
+
const defaultBranch = resolveDefaultBranch(git, productConfig);
|
|
277
|
+
// An epic worktree counts (#115), judged by the local origin/<default>: the index is a derived file this
|
|
278
|
+
// writes and never pushes — the command that commits it fetches first, and refuses on its own — so no
|
|
279
|
+
// fetch on every write.
|
|
280
|
+
if (branchToCommitOn(root, git, defaultBranch, { fetch: false }) !== defaultBranch) return false;
|
|
278
281
|
try {
|
|
279
282
|
const changed = writeIndex(root);
|
|
280
283
|
if (changed && !quiet) info(`rebuilt ${INDEX_FILE}`);
|