yadflow 4.6.0 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/CHANGELOG.md +170 -0
  2. package/README.md +4 -1
  3. package/bin/commands.mjs +5 -1
  4. package/bin/yad.mjs +167 -15
  5. package/cli/artifact-status.mjs +88 -20
  6. package/cli/build.mjs +1372 -0
  7. package/cli/checkpoint.mjs +2 -2
  8. package/cli/commit.mjs +1 -0
  9. package/cli/dial.mjs +21 -1
  10. package/cli/docs.mjs +6 -1
  11. package/cli/doctor.mjs +133 -26
  12. package/cli/epic-state.mjs +357 -9
  13. package/cli/errors.mjs +2 -0
  14. package/cli/find-product.mjs +36 -2
  15. package/cli/fold.mjs +9 -5
  16. package/cli/gate-local.mjs +9 -1
  17. package/cli/gate.mjs +364 -22
  18. package/cli/history.mjs +22 -2
  19. package/cli/hook.mjs +3 -1
  20. package/cli/index-command.mjs +2 -2
  21. package/cli/ledger.mjs +60 -0
  22. package/cli/next.mjs +34 -11
  23. package/cli/openpr.mjs +81 -5
  24. package/cli/platform.mjs +21 -0
  25. package/cli/pr-list.mjs +5 -3
  26. package/cli/product-index.mjs +6 -3
  27. package/cli/product-token.mjs +186 -0
  28. package/cli/productcommit.mjs +33 -0
  29. package/cli/recommend.mjs +3 -1
  30. package/cli/repo-publish.mjs +2 -2
  31. package/cli/run-checks.mjs +586 -0
  32. package/cli/ship-drift.mjs +49 -18
  33. package/cli/standup.mjs +1 -1
  34. package/cli/status.mjs +282 -0
  35. package/cli/test-build.mjs +1559 -0
  36. package/cli/test-run-checks.mjs +603 -0
  37. package/cli/test-worktree.mjs +520 -0
  38. package/cli/thread.mjs +4 -0
  39. package/cli/tidy.mjs +2 -2
  40. package/cli/toolbox.mjs +36 -5
  41. package/cli/workspace.mjs +4 -1
  42. package/cli/worktree-record.mjs +53 -0
  43. package/cli/worktree.mjs +379 -0
  44. package/package.json +3 -3
  45. package/skills/sdlc/config.yaml +1 -1
  46. package/skills/sdlc/module-help.csv +1 -1
  47. package/skills/yad-backfill/templates/checks/backfill-check.sh +9 -9
  48. package/skills/yad-change/SKILL.md +3 -0
  49. package/skills/yad-checks/SKILL.md +34 -5
  50. package/skills/yad-checks/references/check-gates.md +69 -10
  51. package/skills/yad-checks/templates/checks/build-test-lint.sh +22 -3
  52. package/skills/yad-checks/templates/checks/commit-message.sh +8 -2
  53. package/skills/yad-checks/templates/checks/contract-check.sh +61 -33
  54. package/skills/yad-checks/templates/checks/epic-open.sh +87 -14
  55. package/skills/yad-checks/templates/checks/ledger-guard.sh +3 -3
  56. package/skills/yad-checks/templates/checks/lineage-check.sh +88 -15
  57. package/skills/yad-checks/templates/checks/member-check.mjs +206 -35
  58. package/skills/yad-checks/templates/checks/package-manager.sh +41 -4
  59. package/skills/yad-checks/templates/checks/product-checkout.sh +161 -13
  60. package/skills/yad-checks/templates/checks/reconcile-debt-check.sh +94 -15
  61. package/skills/yad-checks/templates/checks/risk-map-check.sh +2 -2
  62. package/skills/yad-checks/templates/checks/spec-link.sh +63 -4
  63. package/skills/yad-checks/templates/checks/verified-commits.sh +23 -5
  64. package/skills/yad-checks/templates/github/yad-checks.yml +8 -8
  65. package/skills/yad-checks/templates/gitlab/.gitlab-ci.yml +3 -0
  66. package/skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml +4 -4
  67. package/skills/yad-checks/templates/gitlab/yad-product-checks.gitlab-ci.yml +16 -3
  68. package/skills/yad-checks/templates/gitlab/yad-update-guard.gitlab-ci.yml +5 -1
  69. package/skills/yad-checks/templates/gitlab/yad-verified-commits.gitlab-ci.yml +5 -1
  70. package/skills/yad-commit/SKILL.md +4 -2
  71. package/skills/yad-docs/templates/app/package-lock.json +395 -106
  72. package/skills/yad-docs/templates/app/package.json +2 -2
  73. package/skills/yad-engineer-review/SKILL.md +45 -20
  74. package/skills/yad-engineer-review/references/ship-and-record.md +42 -8
  75. package/skills/yad-epic/references/state-schema.md +75 -16
  76. package/skills/yad-implement/SKILL.md +75 -13
  77. package/skills/yad-implement/references/implement-conventions.md +8 -1
  78. package/skills/yad-implement/templates/.gitmessage +3 -0
  79. package/skills/yad-open-pr/SKILL.md +21 -0
  80. package/skills/yad-pr-template/SKILL.md +6 -2
  81. package/skills/yad-pr-template/templates/checks/pr-template.sh +85 -4
  82. package/skills/yad-pr-template/templates/checks/pr-title.sh +1 -1
  83. package/skills/yad-pr-template/templates/github/pull_request_template.md +1 -1
  84. package/skills/yad-pr-template/templates/gitlab/merge_request_templates/Default.md +1 -1
  85. package/skills/yad-product-bridge/SKILL.md +14 -1
  86. package/skills/yad-product-bridge/references/bridge.md +5 -2
  87. package/skills/yad-product-bridge/templates/gitlab/yad-gate-sync.gitlab-ci.yml +9 -4
  88. package/skills/yad-reconcile/SKILL.md +9 -3
  89. package/skills/yad-review-gate/SKILL.md +4 -0
  90. package/skills/yad-review-gate/references/gating.md +26 -1
  91. package/skills/yad-run/SKILL.md +52 -28
  92. package/skills/yad-run/references/run-loop.md +42 -21
  93. package/skills/yad-spec/SKILL.md +137 -16
  94. package/skills/yad-spec/references/spec-handoff.md +50 -3
  95. package/skills/yad-status/SKILL.md +7 -0
  96. package/skills/yad-stories/references/story-schema.md +1 -1
@@ -0,0 +1,520 @@
1
+ // `yad worktree add|list|remove` (issue #115): one git worktree per epic, beside the Product and each code
2
+ // repo, so parallel agents never share a folder or a HEAD. The planners are tested with plain facts; the
3
+ // commands run against a real workspace — a Product and a code repo, each with a bare origin.
4
+ import './fixtures/git-quiet.mjs';
5
+ import { test } from 'node:test';
6
+ import assert from 'node:assert/strict';
7
+ import { execFileSync, spawnSync } from 'node:child_process';
8
+ import fs from 'node:fs';
9
+ import os from 'node:os';
10
+ import path from 'node:path';
11
+ import { fileURLToPath } from 'node:url';
12
+ import { worktreePath, planAdd, planRemove, YAD_LOCAL_FILES } from './worktree.mjs';
13
+ import { worktreeAt } from './worktree-record.mjs';
14
+ import { registryEntryFor, findProduct } from './find-product.mjs';
15
+ import { branchToCommitOn, YAD_COMMIT_SUBJECT } from './productcommit.mjs';
16
+ import { refreshIndexAfterWrite, INDEX_FILE } from './product-index.mjs';
17
+ import { run } from './lib.mjs';
18
+
19
+ const ROOT = fileURLToPath(new URL('..', import.meta.url));
20
+ const YAD = path.join(ROOT, 'bin/yad.mjs');
21
+ const ENV = Object.fromEntries(Object.entries(process.env).filter(([k]) =>
22
+ !/^GIT_(AUTHOR|COMMITTER)_/.test(k) && !/^(CI|GITLAB_CI|GITHUB_ACTIONS|SDLC_BASE|SDLC_HUB_CONFIG|SDLC_PRODUCT_CONFIG)$/.test(k) && !/^(CI_|GITHUB_)/.test(k)));
23
+ ENV.GIT_CONFIG_GLOBAL = '/dev/null';
24
+ const git = (cwd, ...a) => execFileSync('git', a, { cwd, stdio: 'pipe', env: ENV }).toString().trim();
25
+ const yadWith = (env, cwd, ...args) => {
26
+ const r = spawnSync(process.execPath, [YAD, ...args], { cwd, env: { ...ENV, ...env, PWD: cwd, YAD_NO_REPORT: '1', YAD_NO_UPDATE_CHECK: '1', NO_COLOR: '1' }, encoding: 'utf8' });
27
+ return { code: r.status, out: `${r.stdout}${r.stderr}`, stdout: r.stdout, stderr: r.stderr };
28
+ };
29
+ const yad = (cwd, ...args) => yadWith({}, cwd, ...args);
30
+ const json = (r) => JSON.parse(r.stdout);
31
+
32
+ function write(dir, files) {
33
+ for (const [rel, content] of Object.entries(files)) {
34
+ const p = path.join(dir, rel);
35
+ fs.mkdirSync(path.dirname(p), { recursive: true });
36
+ fs.writeFileSync(p, content);
37
+ }
38
+ }
39
+ function repoWithOrigin(W, name, files) {
40
+ const dir = path.join(W, name);
41
+ fs.mkdirSync(dir, { recursive: true });
42
+ git(dir, 'init', '-q', '-b', 'main');
43
+ git(dir, 'config', 'user.name', 'alice');
44
+ git(dir, 'config', 'user.email', 'alice@corp.io');
45
+ write(dir, files);
46
+ git(dir, 'add', '-A');
47
+ git(dir, 'commit', '-q', '-m', 'seed');
48
+ git(W, 'init', '-q', '--bare', '-b', 'main', `${name}.git`);
49
+ git(dir, 'remote', 'add', 'origin', path.join(W, `${name}.git`));
50
+ git(dir, 'push', '-q', '-u', 'origin', 'main');
51
+ git(dir, 'remote', 'set-head', 'origin', 'main');
52
+ return dir;
53
+ }
54
+
55
+ // A workspace: the Product (one epic naming api) and api (a package.json, an ignored node_modules).
56
+ function workspace({ product = {} } = {}) {
57
+ const W = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'yad-wt-')));
58
+ fs.writeFileSync(path.join(W, '.yad-workspace.json'), JSON.stringify({ version: 1, product: 'product' }));
59
+ const st = (id, type, status) => ({ id, type, artifact: 'epic.md', status, risk_tags: [] });
60
+ const P = repoWithOrigin(W, 'product', {
61
+ '.sdlc/product.json': JSON.stringify({ name: 'p', ...product }),
62
+ '.sdlc/repos.json': JSON.stringify({ repos: [{ name: 'api', path: '../api' }] }),
63
+ 'epics/EP-x/epic.md': '---\nid: EP-x\ntype: chore\nstatus: draft\nrepos: [api]\n---\n# EP-x\n',
64
+ 'epics/EP-x/.sdlc/state.json': JSON.stringify({ epicId: 'EP-x', profile: 'chore', currentStep: 'epic', steps: [st('epic', 'author', 'in_progress'), st('epic-review', 'review+approve', 'todo')] }),
65
+ 'epics/EP-x/.sdlc/approvals.json': '[]',
66
+ });
67
+ const api = repoWithOrigin(W, 'api', { 'package.json': '{}\n', '.gitignore': 'node_modules/\n', 'src/a.js': 'a\n' });
68
+ write(api, { 'node_modules/dep/index.js': 'dep\n' });
69
+ return { W, P, api, pwt: path.join(W, 'product--EP-x'), awt: path.join(W, 'api--EP-x') };
70
+ }
71
+
72
+ test('worktree planners: the path beside the checkout, the refusals, and yad\'s own files named apart (#115)', () => {
73
+ assert.equal(worktreePath('/ws/product', 'EP-x'), path.join('/ws', 'product--EP-x'));
74
+ const base = { main: '/ws/api', epic: 'EP-x', repo: 'api', hasOrigin: true, pathTaken: false, existing: null, mainIsLinked: false };
75
+ assert.deepEqual(planAdd(base), { path: path.join('/ws', 'api--EP-x'), skip: false, refuse: null });
76
+ assert.deepEqual(planAdd({ ...base, existing: { path: '/ws/api--EP-x', missing: false } }), { path: '/ws/api--EP-x', skip: true, refuse: null }, 'a re-run goes on');
77
+ assert.match(planAdd({ ...base, existing: { path: '/ws/api--EP-x', missing: true } }).refuse.hint, /git worktree prune/);
78
+ assert.match(planAdd({ ...base, nested: true }).refuse.message, /kept inside the Product's folder/);
79
+ assert.match(planAdd({ ...base, pathTaken: true }).refuse.message, /is already there/);
80
+ assert.match(planAdd({ ...base, hasOrigin: false }).refuse.message, /no origin remote/);
81
+ assert.match(planAdd({ ...base, mainIsLinked: true }).refuse.message, /itself a worktree/);
82
+ assert.deepEqual(planRemove({ path: '/w' }), []);
83
+ assert.equal(planRemove({ path: '/w', missing: true })[0].fix, 'run `git worktree prune` in the main checkout');
84
+ assert.match(planRemove({ path: '/w', unpushed: null })[0].reason, /could not count/, 'unknown is not 0');
85
+ const why = planRemove({ path: '/w', inside: true, locked: 'agent 2', busy: 'MERGE_HEAD', changes: ['a.js', ...YAD_LOCAL_FILES], unpushed: 2 });
86
+ assert.equal(why.length, 6);
87
+ assert.match(why.map((y) => y.reason).join('\n'), /you are inside it\nit is locked \(agent 2\)\na MERGE_HEAD is half done in it\n1 uncommitted or untracked file\(s\): a\.js\nyad's own working file\(s\) are there: \.specify\/feature\.json, \.gitmessage\n2 commit\(s\) are on no remote/);
88
+ assert.match(why[4].fix, /safe to delete/);
89
+ });
90
+
91
+ test('yad worktree add --all, list and remove: beside each checkout, detached, node_modules linked, the main tree untouched (#115)', () => {
92
+ const { W, P, api, pwt, awt } = workspace();
93
+ try {
94
+ let r = yad(P, 'worktree', 'add', 'EP-x', '--all', '--dry-run', '--json');
95
+ assert.equal(r.code, 0, r.out);
96
+ assert.deepEqual(json(r).worktrees.map((w) => [w.repo, w.path, w.added, w.links, w.existing]), [[null, pwt, false, [], false], ['api', awt, false, ['node_modules'], false]]);
97
+ assert.equal(fs.existsSync(pwt) || fs.existsSync(awt), false, 'a dry run makes nothing');
98
+
99
+ r = yad(P, 'worktree', 'add', 'EP-x', '--all', '--json');
100
+ assert.equal(r.code, 0, r.out);
101
+ for (const [at, repo] of [[pwt, null], [awt, 'api']]) {
102
+ const rec = worktreeAt(at);
103
+ assert.deepEqual([rec.epic, rec.repo, rec.base], ['EP-x', repo, 'main']);
104
+ assert.equal(git(at, 'rev-parse', '--abbrev-ref', 'HEAD'), 'HEAD', 'detached');
105
+ assert.equal(git(at, 'rev-parse', 'HEAD'), git(at, 'rev-parse', 'origin/main'));
106
+ }
107
+ assert.equal(fs.lstatSync(path.join(awt, 'node_modules')).isSymbolicLink(), true);
108
+ assert.equal(fs.readFileSync(path.join(awt, 'node_modules/dep/index.js'), 'utf8'), 'dep\n');
109
+ assert.match(r.out, /node_modules is a link to the main checkout's — do not `npm install` in the worktree/);
110
+ assert.match(r.out, /open each agent's session IN its worktree folder/);
111
+
112
+ // The link is never staged: `node_modules/` matches folders only, so yad excludes the link itself.
113
+ assert.equal(git(awt, 'status', '--porcelain'), '');
114
+ git(awt, 'add', '-A');
115
+ assert.equal(git(awt, 'diff', '--cached', '--name-only'), '', 'git add -A stages nothing');
116
+
117
+ r = yad(P, 'worktree', 'add', 'EP-x', '--all', '--json');
118
+ assert.equal(r.code, 0, r.out);
119
+ assert.deepEqual(json(r).worktrees.map((w) => [w.repo, w.added, w.existing]), [[null, false, true], ['api', false, true]], 'a re-run finds them there');
120
+
121
+ r = yad(P, 'worktree', 'list', '--json');
122
+ assert.equal(r.code, 0, r.out);
123
+ assert.deepEqual(json(r).worktrees.map((w) => [w.epic, w.repo, w.branch, w.changes, w.unpushed, w.locked, w.missing]),
124
+ [['EP-x', null, null, 0, 0, false, false], ['EP-x', 'api', null, 0, 0, false, false]], 'the node_modules link is not a change');
125
+
126
+ r = yad(P, 'worktree', 'remove', 'EP-x', '--all', '--json');
127
+ assert.equal(r.code, 0, r.out);
128
+ assert.deepEqual(json(r).removed.map((x) => x.path), [pwt, awt]);
129
+ assert.equal(fs.existsSync(pwt) || fs.existsSync(awt), false);
130
+ assert.equal(fs.readFileSync(path.join(api, 'node_modules/dep/index.js'), 'utf8'), 'dep\n', 'only the link went');
131
+ assert.equal(git(api, 'worktree', 'list').split('\n').length, 1);
132
+ assert.equal(git(P, 'worktree', 'list').split('\n').length, 1);
133
+ } finally { fs.rmSync(W, { recursive: true, force: true }); }
134
+ });
135
+
136
+ test('yad worktree remove refuses, removing nothing, while a worktree holds work — and names yad\'s own files (#115)', () => {
137
+ const { W, P, pwt, awt } = workspace();
138
+ const refused = (re, cwd = P) => {
139
+ const r = yad(cwd, 'worktree', 'remove', 'EP-x', '--all');
140
+ assert.equal(r.code, 1, r.out);
141
+ assert.match(r.out, re);
142
+ assert.match(r.out, /nothing was removed/);
143
+ assert.ok(fs.existsSync(pwt) && fs.existsSync(awt), 'both still there: one refusal removes nothing');
144
+ };
145
+ try {
146
+ assert.equal(yad(P, 'worktree', 'add', 'EP-x', '--all').code, 0);
147
+ write(awt, { 'new.txt': 'x\n' });
148
+ refused(/1 uncommitted or untracked file\(s\): new\.txt; commit and push them, or `git -C .* stash -u`/);
149
+ fs.rmSync(path.join(awt, 'new.txt'));
150
+ write(awt, { 'src/a.js': 'changed\n' });
151
+ refused(/1 uncommitted or untracked file\(s\): src\/a\.js/);
152
+ git(awt, 'checkout', '--', 'src/a.js');
153
+ write(awt, { '.gitmessage': 'Task:\n', '.specify/feature.json': '{}' });
154
+ refused(/yad's own working file\(s\) are there: \.gitmessage, \.specify\/feature\.json; they are local state, safe to delete/);
155
+ fs.rmSync(path.join(awt, '.gitmessage'));
156
+ fs.rmSync(path.join(awt, '.specify'), { recursive: true });
157
+ git(pwt, 'config', 'user.name', 'bob');
158
+ git(pwt, 'config', 'user.email', 'bob@corp.io');
159
+ write(pwt, { 'epics/EP-x/epic.md': '---\nid: EP-x\n---\n# edited\n' });
160
+ git(pwt, 'commit', '-qam', 'edit');
161
+ refused(/1 commit\(s\) are on no remote/);
162
+ git(pwt, 'reset', '-q', '--hard', 'origin/main');
163
+ git(P, 'worktree', 'lock', '--reason', 'agent 2 is here', pwt);
164
+ refused(/it is locked \(agent 2 is here\)/);
165
+ git(P, 'worktree', 'unlock', pwt);
166
+ refused(/you are inside it; cd out of/, path.join(awt, 'src'));
167
+ assert.equal(yad(P, 'worktree', 'remove', 'EP-x', '--all').code, 0);
168
+ const r = yad(P, 'worktree', 'remove', 'EP-x');
169
+ assert.equal(r.code, 1, r.out);
170
+ assert.match(r.out, /no yad worktree for EP-x/);
171
+ } finally { fs.rmSync(W, { recursive: true, force: true }); }
172
+ });
173
+
174
+ test('yad worktree: an epic that is not there, a repo not registered, and a repo with no origin are refused (#115)', () => {
175
+ const { W, P, api } = workspace();
176
+ try {
177
+ let r = yad(P, 'worktree', 'add', 'EP-nope');
178
+ assert.match(r.out, /no epic EP-nope on the Product/);
179
+ r = yad(P, 'worktree', 'add', 'EP-x', '--repo', 'web');
180
+ assert.match(r.out, /web is not a registered repo/);
181
+ r = yad(P, 'worktree', 'add', 'EP-x', '--repo', 'api', '--all');
182
+ assert.match(r.out, /--repo and --all name different targets/);
183
+ git(api, 'remote', 'remove', 'origin');
184
+ r = yad(P, 'worktree', 'add', 'EP-x', '--all');
185
+ assert.equal(r.code, 1, r.out);
186
+ assert.match(r.out, /api has no origin remote/);
187
+ assert.equal(fs.existsSync(path.join(W, 'product--EP-x')), false, 'checked before any is made');
188
+ } finally { fs.rmSync(W, { recursive: true, force: true }); }
189
+ });
190
+
191
+ test('from an epic\'s code worktree: the registry knows the repo, and Product commands go to the epic\'s Product worktree (#115)', () => {
192
+ const { W, P, api, pwt, awt } = workspace();
193
+ try {
194
+ assert.equal(yad(P, 'worktree', 'add', 'EP-x', '--repo', 'api').code, 0);
195
+ assert.equal(registryEntryFor(P, path.join(awt, 'src'))?.meta?.name, 'api');
196
+ assert.equal(findProduct(awt).root, P, 'no Product worktree yet: the main Product');
197
+ assert.equal(yad(P, 'worktree', 'add', 'EP-x').code, 0);
198
+ const found = findProduct(path.join(awt, 'src'));
199
+ assert.deepEqual([found.root, found.worktree, found.repo?.name], [pwt, 'EP-x', 'api']);
200
+ const r = yad(awt, 'worktree', 'list');
201
+ assert.match(r.stderr, /Product: \.\.\/product--EP-x \(EP-x's worktree\)/);
202
+ // A worktree yad did not make maps nothing: E80 review 3 still holds for it.
203
+ git(api, 'worktree', 'add', '-q', '--detach', path.join(W, 'api-other'));
204
+ assert.equal(registryEntryFor(P, path.join(W, 'api-other')), null);
205
+ // Nor does a record copied into some other repo's worktree.
206
+ const other = repoWithOrigin(W, 'other', { f: 'x\n' });
207
+ git(other, 'worktree', 'add', '-q', '--detach', path.join(W, 'other--EP-x'));
208
+ const gitDir = path.resolve(path.join(W, 'other--EP-x'), fs.readFileSync(path.join(W, 'other--EP-x', '.git'), 'utf8').match(/gitdir:\s*(.+)/)[1].trim());
209
+ fs.writeFileSync(path.join(gitDir, 'yad-worktree.json'), JSON.stringify({ epic: 'EP-x', repo: 'api' }));
210
+ assert.equal(registryEntryFor(P, path.join(W, 'other--EP-x')), null);
211
+ } finally { fs.rmSync(W, { recursive: true, force: true }); }
212
+ });
213
+
214
+ test('default-branch commands: an epic Product worktree commits on the default branch; nothing else detached does (#115)', () => {
215
+ const { W, P, pwt } = workspace();
216
+ try {
217
+ assert.equal(yad(P, 'worktree', 'add', 'EP-x').code, 0);
218
+ const g = (root) => (...a) => run('git', a, { cwd: root });
219
+ assert.equal(branchToCommitOn(pwt, g(pwt), 'main'), 'main');
220
+ // A commit the default branch lacks: refused, so a step's unreviewed work never reaches it.
221
+ git(pwt, 'config', 'user.name', 'bob');
222
+ git(pwt, 'config', 'user.email', 'bob@corp.io');
223
+ write(pwt, { 'notes.md': 'x\n' });
224
+ git(pwt, 'add', 'notes.md');
225
+ git(pwt, 'commit', '-qm', 'unreviewed');
226
+ assert.equal(branchToCommitOn(pwt, g(pwt), 'main'), 'HEAD');
227
+ git(pwt, 'reset', '-q', '--hard', 'origin/main');
228
+ // Behind the default branch is fine: the push rebases.
229
+ write(P, { 'later.md': 'y\n' });
230
+ git(P, 'add', 'later.md');
231
+ git(P, 'commit', '-qm', 'later');
232
+ git(P, 'push', '-q', 'origin', 'main');
233
+ assert.equal(branchToCommitOn(pwt, g(pwt), 'main'), 'main');
234
+ // A detached main checkout is not an epic worktree: refused as before.
235
+ git(P, 'switch', '-q', '--detach');
236
+ assert.equal(branchToCommitOn(P, g(P), 'main'), 'HEAD');
237
+ git(P, 'switch', '-q', 'main');
238
+
239
+ // End to end: a Build record checkpointed from the worktree lands on origin/main.
240
+ write(pwt, { 'epics/EP-x/.sdlc/build-log/EP-x-S01-T01-api.json': JSON.stringify({ story: 'EP-x-S01', task: 'T01', repo: 'api', mergeCommit: 'abc', date: '2026-10-25' }) });
241
+ let r = yad(pwt, 'checkpoint', '--push');
242
+ assert.equal(r.code, 0, r.out);
243
+ assert.match(r.out, /pushed to origin\/main/);
244
+ assert.match(git(path.join(W, 'product.git'), 'log', '-1', '--format=%s', 'main'), /sync Build state/);
245
+ // On a step branch it is refused, as in the main checkout.
246
+ git(pwt, 'switch', '-q', '-c', 'epic/EP-x');
247
+ r = yad(pwt, 'checkpoint', '--push');
248
+ assert.equal(r.code, 1, r.out);
249
+ assert.match(r.out, /on 'epic\/EP-x', not the default branch 'main'/);
250
+ git(pwt, 'switch', '-q', '--detach', 'origin/main');
251
+ write(pwt, { 'x.md': 'x\n' });
252
+ git(pwt, 'add', 'x.md');
253
+ git(pwt, 'commit', '-qm', 'unreviewed');
254
+ write(pwt, { 'epics/EP-x/.sdlc/build-log/EP-x-S01-T02-api.json': JSON.stringify({ story: 'EP-x-S01', task: 'T02', repo: 'api', mergeCommit: 'def', date: '2026-10-25' }) });
255
+ r = yad(pwt, 'checkpoint', '--push');
256
+ assert.equal(r.code, 1, r.out);
257
+ assert.match(r.out, /this epic worktree's HEAD has commits origin\/main does not/);
258
+ } finally { fs.rmSync(W, { recursive: true, force: true }); }
259
+ });
260
+
261
+ test('yad gate ci refuses to push from a named branch other than the default; a detached HEAD may (#115)', () => {
262
+ const { W, P } = workspace({ product: { platform: 'github', git_url: 'https://github.com/acme/product', default_branch: 'main' } });
263
+ try {
264
+ git(P, 'switch', '-q', '-c', 'epic/EP-x');
265
+ let r = yad(P, 'gate', 'ci', '--branch', 'review/EP-x/epic', '--pr', '1', '--merged');
266
+ assert.equal(r.code, 1, r.out);
267
+ assert.match(r.out, /on 'epic\/EP-x', not the default branch 'main' — yad gate ci pushes HEAD to the default branch/);
268
+ r = yad(P, 'gate', 'ci');
269
+ assert.match(r.out, /on 'epic\/EP-x', not the default branch 'main'/, 'the sweep pushes too');
270
+ git(P, 'switch', '-q', '--detach', 'main');
271
+ r = yad(P, 'gate', 'ci', '--branch', 'review/EP-x/epic', '--pr', '1', '--merged');
272
+ assert.doesNotMatch(r.out, /not the default branch/);
273
+ } finally { fs.rmSync(W, { recursive: true, force: true }); }
274
+ });
275
+
276
+ test('yad build step spec in_progress pins the epic\'s code worktree when there is one (#115)', () => {
277
+ const { W, P, api, awt } = workspace();
278
+ try {
279
+ // A story whose stories review passed, so a lane can start.
280
+ const st = (id, type, status) => ({ id, type, artifact: id.startsWith('stories') ? 'stories/' : 'epic.md', status, risk_tags: [] });
281
+ write(P, {
282
+ 'epics/EP-x/.sdlc/state.json': JSON.stringify({ epicId: 'EP-x', profile: 'chore', currentStep: 'ready-for-build', steps: [st('epic', 'author', 'done'), st('epic-review', 'review+approve', 'done'), st('stories', 'author', 'done'), st('stories-review', 'review+approve', 'done')] }),
283
+ 'epics/EP-x/stories/EP-x-S01.md': '---\nid: EP-x-S01\nepic: EP-x\nstatus: approved\nrepos: [api]\n---\n# S01\n',
284
+ });
285
+ git(P, 'add', '-A');
286
+ git(P, 'commit', '-qm', 'stories');
287
+ git(P, 'push', '-q', 'origin', 'main');
288
+ write(api, { '.specify/memory/constitution.md': '# c\n' });
289
+ git(api, 'add', '.specify');
290
+ git(api, 'commit', '-qm', 'spec kit');
291
+ git(api, 'push', '-q', 'origin', 'main');
292
+ assert.equal(yad(P, 'worktree', 'add', 'EP-x', '--repo', 'api').code, 0);
293
+ assert.equal(yad(P, 'build', 'start', 'EP-x-S01', '--repo', 'api').code, 0);
294
+ const r = yad(P, 'build', 'step', 'EP-x-S01', '--repo', 'api', 'spec', 'in_progress', '--json');
295
+ assert.equal(r.code, 0, r.out);
296
+ assert.deepEqual(json(r).specKit, { file: 'api--EP-x/.specify/feature.json', featureDirectory: 'specs/EP-x-S01', changed: true });
297
+ assert.equal(JSON.parse(fs.readFileSync(path.join(awt, '.specify/feature.json'), 'utf8')).feature_directory, 'specs/EP-x-S01');
298
+ assert.equal(fs.existsSync(path.join(api, '.specify/feature.json')), false, 'the main checkout is left alone');
299
+ } finally { fs.rmSync(W, { recursive: true, force: true }); }
300
+ });
301
+
302
+ test('yad worktree add --all makes nothing when one target cannot be fetched, and a repo inside the Product is refused (#115 review 1)', () => {
303
+ const { W, P, api, pwt } = workspace();
304
+ try {
305
+ git(api, 'remote', 'set-url', 'origin', path.join(W, 'gone.git'));
306
+ let r = yad(P, 'worktree', 'add', 'EP-x', '--all');
307
+ assert.equal(r.code, 1, r.out);
308
+ assert.match(r.out, /could not fetch main for api/);
309
+ assert.equal(fs.existsSync(pwt), false, 'the Product worktree was not made either');
310
+ git(api, 'remote', 'set-url', 'origin', path.join(W, 'api.git'));
311
+ assert.equal(yad(P, 'worktree', 'add', 'EP-x', '--all').code, 0, 'and a re-run makes both');
312
+ // A code repo kept inside the Product's folder: its worktree could not find the Product.
313
+ write(P, { '.sdlc/repos.json': JSON.stringify({ repos: [{ name: 'api', path: '../api' }, { name: 'inner', path: 'inner' }] }) });
314
+ repoWithOrigin(P, 'inner', { f: 'x\n' });
315
+ r = yad(P, 'worktree', 'add', 'EP-x', '--repo', 'inner');
316
+ assert.equal(r.code, 1, r.out);
317
+ assert.match(r.out, /inner is kept inside the Product's folder/);
318
+ } finally { fs.rmSync(W, { recursive: true, force: true }); }
319
+ });
320
+
321
+ test('an epic Product worktree: yad\'s own unpushed commit is pushed by the next run; gate ci there refuses a step\'s commits (#115 review 1)', () => {
322
+ const { W, P, pwt } = workspace({ product: { platform: 'github', git_url: 'https://github.com/acme/product', default_branch: 'main' } });
323
+ try {
324
+ assert.equal(yad(P, 'worktree', 'add', 'EP-x').code, 0);
325
+ git(pwt, 'config', 'user.name', 'bob');
326
+ git(pwt, 'config', 'user.email', 'bob@corp.io');
327
+ write(pwt, { 'epics/EP-x/.sdlc/build-log/EP-x-S01-T01-api.json': JSON.stringify({ story: 'EP-x-S01', task: 'T01', repo: 'api', mergeCommit: 'abc', date: '2026-10-25' }) });
328
+ let r = yad(pwt, 'checkpoint');
329
+ assert.equal(r.code, 0, r.out);
330
+ // The next run, with something new, is not refused for that unpushed yad commit, and pushes both.
331
+ write(pwt, { 'epics/EP-x/.sdlc/build-log/EP-x-S01-T02-api.json': JSON.stringify({ story: 'EP-x-S01', task: 'T02', repo: 'api', mergeCommit: 'def', date: '2026-10-25' }) });
332
+ r = yad(pwt, 'checkpoint', '--push');
333
+ assert.equal(r.code, 0, r.out);
334
+ assert.deepEqual(git(path.join(W, 'product.git'), 'log', '-2', '--format=%s', 'main').split('\n').map((x) => /sync Build state/.test(x)), [true, true], 'the earlier commit went up too');
335
+ // gate ci from the worktree with a step's commit on its detached HEAD: refused, nothing pushed.
336
+ write(pwt, { 'epics/EP-x/epic.md': '---\nid: EP-x\n---\n# unreviewed\n' });
337
+ git(pwt, 'commit', '-qam', 'author epic');
338
+ const head = git(path.join(W, 'product.git'), 'rev-parse', 'main');
339
+ r = yad(pwt, 'gate', 'ci');
340
+ assert.equal(r.code, 1, r.out);
341
+ assert.match(r.out, /a detached HEAD with commits of its own', not the default branch 'main'/);
342
+ assert.equal(git(path.join(W, 'product.git'), 'rev-parse', 'main'), head);
343
+ } finally { fs.rmSync(W, { recursive: true, force: true }); }
344
+ });
345
+
346
+ test('yad worktree remove says which ignored files go with it (#115 review 1)', () => {
347
+ const { W, P, awt } = workspace();
348
+ try {
349
+ assert.equal(yad(P, 'worktree', 'add', 'EP-x', '--repo', 'api').code, 0);
350
+ git(awt, 'config', 'user.name', 'bob');
351
+ git(awt, 'config', 'user.email', 'bob@corp.io');
352
+ fs.appendFileSync(path.join(awt, '.gitignore'), '.env\n');
353
+ git(awt, 'commit', '-qam', 'ignore env');
354
+ git(awt, 'push', '-q', 'origin', 'HEAD:refs/heads/ignore-env');
355
+ write(awt, { '.env': 'SECRET=1\n' });
356
+ const r = yad(P, 'worktree', 'remove', 'EP-x', '--repo', 'api');
357
+ assert.equal(r.code, 0, r.out);
358
+ assert.match(r.out, /removed with it, as git ignores them: \.env/);
359
+ assert.doesNotMatch(r.out, /removed with it, as git ignores them: .*node_modules/, 'yad\'s own link is not listed');
360
+ } finally { fs.rmSync(W, { recursive: true, force: true }); }
361
+ });
362
+
363
+ test('yad\'s own commit is the exact subject yad writes — a revert of one, or a step\'s commit with the marker, is not (#115 review 2)', () => {
364
+ for (const ok of ['chore(product): sync Build state — EP-x/EP-x-S01 by bob [skip ci]', 'chore(gate): repair epic state — close stranded author step(s) [skip ci]'])
365
+ assert.ok(YAD_COMMIT_SUBJECT.test(ok), ok);
366
+ for (const no of ['Revert "chore(product): sync Build state — x by y [skip ci]"', 'docs(ep-x): author epic [skip ci]', 'chore(product): sync Build state'])
367
+ assert.equal(YAD_COMMIT_SUBJECT.test(no), false, no);
368
+ const { W, P, pwt } = workspace();
369
+ try {
370
+ assert.equal(yad(P, 'worktree', 'add', 'EP-x').code, 0);
371
+ git(pwt, 'config', 'user.name', 'bob');
372
+ git(pwt, 'config', 'user.email', 'bob@corp.io');
373
+ write(pwt, { 'notes.md': 'x\n' });
374
+ git(pwt, 'add', 'notes.md');
375
+ git(pwt, 'commit', '-qm', 'docs(ep-x): author epic [skip ci]');
376
+ assert.equal(branchToCommitOn(pwt, (...a) => run('git', a, { cwd: pwt }), 'main'), 'HEAD');
377
+ } finally { fs.rmSync(W, { recursive: true, force: true }); }
378
+ });
379
+
380
+ test('gate ci in an epic Product worktree with no default branch set still refuses a step\'s commits (#115 review 3)', () => {
381
+ const { W, P, pwt } = workspace({ product: { platform: 'github', git_url: 'https://github.com/acme/product' } });
382
+ try {
383
+ assert.equal(yad(P, 'worktree', 'add', 'EP-x').code, 0);
384
+ git(pwt, 'remote', 'set-head', 'origin', '-d');
385
+ git(pwt, 'config', 'user.name', 'bob');
386
+ git(pwt, 'config', 'user.email', 'bob@corp.io');
387
+ write(pwt, { 'notes.md': 'x\n' });
388
+ git(pwt, 'add', 'notes.md');
389
+ git(pwt, 'commit', '-qm', 'docs(ep-x): author epic');
390
+ const head = git(path.join(W, 'product.git'), 'rev-parse', 'main');
391
+ const r = yad(pwt, 'gate', 'ci');
392
+ assert.equal(r.code, 1, r.out);
393
+ assert.match(r.out, /a detached HEAD with commits of its own', not the default branch 'main'/);
394
+ assert.equal(git(path.join(W, 'product.git'), 'rev-parse', 'main'), head);
395
+ } finally { fs.rmSync(W, { recursive: true, force: true }); }
396
+ });
397
+
398
+ test('the index refresh in an epic Product worktree asks no network: offline, it still rebuilds (#115 follow-up)', () => {
399
+ const { W, P, pwt } = workspace();
400
+ try {
401
+ assert.equal(yad(P, 'worktree', 'add', 'EP-x').code, 0);
402
+ git(pwt, 'remote', 'set-url', 'origin', path.join(W, 'gone.git')); // offline: every fetch fails
403
+ const g = (...a) => run('git', a, { cwd: pwt });
404
+ assert.equal(branchToCommitOn(pwt, g, 'main'), 'HEAD', 'a command that pushes still fetches first, and refuses');
405
+ assert.equal(refreshIndexAfterWrite(pwt, null, { quiet: true }), true, 'a derived file is judged by the local origin/main');
406
+ assert.equal(fs.existsSync(path.join(pwt, INDEX_FILE)), true);
407
+ // A step's commit: the local ref says no, as the fetched one would.
408
+ git(pwt, 'config', 'user.name', 'bob');
409
+ git(pwt, 'config', 'user.email', 'bob@corp.io');
410
+ git(pwt, 'add', INDEX_FILE);
411
+ git(pwt, 'commit', '-qm', 'docs(ep-x): author epic');
412
+ fs.rmSync(path.join(pwt, INDEX_FILE));
413
+ assert.equal(refreshIndexAfterWrite(pwt, null), false);
414
+ assert.equal(fs.existsSync(path.join(pwt, INDEX_FILE)), false);
415
+ } finally { fs.rmSync(W, { recursive: true, force: true }); }
416
+ });
417
+
418
+ test('yad worktree remove drops yad\'s exclude lines once no worktree of the repo has the link; a person\'s own line stays (#115 follow-up)', () => {
419
+ const { W, P, api, awt } = workspace();
420
+ try {
421
+ write(P, {
422
+ 'epics/EP-y/epic.md': '---\nid: EP-y\ntype: chore\nstatus: draft\nrepos: [api]\n---\n# EP-y\n',
423
+ 'epics/EP-y/.sdlc/state.json': fs.readFileSync(path.join(P, 'epics/EP-x/.sdlc/state.json'), 'utf8').replace('"EP-x"', '"EP-y"'),
424
+ 'epics/EP-y/.sdlc/approvals.json': '[]',
425
+ });
426
+ git(P, 'add', '-A');
427
+ git(P, 'commit', '-qm', 'EP-y');
428
+ git(P, 'push', '-q', 'origin', 'main');
429
+ const exclude = path.join(api, '.git/info/exclude');
430
+ fs.appendFileSync(exclude, '/scratch\n');
431
+ const mark = '# yad worktree (#115): the node_modules link\n/node_modules\n';
432
+ assert.equal(yad(P, 'worktree', 'add', 'EP-x', '--repo', 'api').code, 0);
433
+ assert.equal(yad(P, 'worktree', 'add', 'EP-y', '--repo', 'api').code, 0);
434
+ assert.equal(fs.readFileSync(exclude, 'utf8').split(mark).length, 2, 'the pair is written once, and shared');
435
+
436
+ let r = yad(P, 'worktree', 'remove', 'EP-x', '--repo', 'api');
437
+ assert.equal(r.code, 0, r.out);
438
+ assert.match(fs.readFileSync(exclude, 'utf8'), /# yad worktree \(#115\)/, 'EP-y still has the link');
439
+ assert.equal(git(path.join(W, 'api--EP-y'), 'status', '--porcelain'), '', 'so it is still never staged');
440
+
441
+ r = yad(P, 'worktree', 'remove', 'EP-y', '--repo', 'api');
442
+ assert.equal(r.code, 0, r.out);
443
+ const left = fs.readFileSync(exclude, 'utf8');
444
+ assert.doesNotMatch(left, /yad worktree|^\/node_modules$/m, 'the last link gone: so is the pair');
445
+ assert.match(left, /^\/scratch$/m, 'the person\'s own line stays');
446
+ assert.equal(fs.existsSync(awt) || fs.existsSync(path.join(W, 'api--EP-y')), false);
447
+ } finally { fs.rmSync(W, { recursive: true, force: true }); }
448
+ });
449
+
450
+ test('yad worktree add --all takes back what it made when git fails — also the half-made worktree git keeps (#115 follow-up)', { skip: process.platform === 'win32' && 'a sh hook' }, () => {
451
+ const { W, P, api, pwt, awt } = workspace();
452
+ try {
453
+ // A second repo, last: api is made and linked before web fails.
454
+ const web = repoWithOrigin(W, 'web', { 'package.json': '{}\n', '.gitignore': 'node_modules/\n' });
455
+ write(P, {
456
+ '.sdlc/repos.json': JSON.stringify({ repos: [{ name: 'api', path: '../api' }, { name: 'web', path: '../web' }] }),
457
+ 'epics/EP-x/epic.md': '---\nid: EP-x\ntype: chore\nstatus: draft\nrepos: [api, web]\n---\n# EP-x\n',
458
+ });
459
+ // git keeps a worktree whose post-checkout hook fails, and still exits 1.
460
+ write(web, { '.git/hooks/post-checkout': '#!/bin/sh\nexit 1\n' });
461
+ fs.chmodSync(path.join(web, '.git/hooks/post-checkout'), 0o755);
462
+ const r = yad(P, 'worktree', 'add', 'EP-x', '--all');
463
+ assert.equal(r.code, 1, r.out);
464
+ assert.match(r.out, /git could not add .*web--EP-x[\s\S]*were taken back/);
465
+ assert.equal(fs.existsSync(pwt) || fs.existsSync(awt), false, 'the worktrees made first are gone');
466
+ assert.equal(fs.existsSync(path.join(W, 'web--EP-x')), false, 'and so is the one git kept');
467
+ for (const at of [P, api, web]) assert.equal(git(at, 'worktree', 'list').split('\n').length, 1);
468
+ assert.doesNotMatch(fs.readFileSync(path.join(api, '.git/info/exclude'), 'utf8'), /yad worktree/, 'api\'s exclude pair went with it');
469
+ assert.equal(fs.readFileSync(path.join(api, 'node_modules/dep/index.js'), 'utf8'), 'dep\n', 'only the link went');
470
+ } finally { fs.rmSync(W, { recursive: true, force: true }); }
471
+ });
472
+
473
+ test('yad worktree remove puts the node_modules link back when git cannot remove the worktree (#115 follow-up)', { skip: process.platform === 'win32' && 'a sh shim for git' }, () => {
474
+ const { W, P, api, awt } = workspace();
475
+ try {
476
+ assert.equal(yad(P, 'worktree', 'add', 'EP-x', '--repo', 'api').code, 0);
477
+ // A git that refuses `worktree remove` and runs everything else: yad's own checks all pass.
478
+ const bin = path.join(W, 'bin');
479
+ const real = execFileSync('sh', ['-c', 'command -v git'], { encoding: 'utf8' }).trim();
480
+ write(bin, { git: `#!/bin/sh\nif [ "$1" = worktree ] && [ "$2" = remove ]; then echo 'fatal: refused by the test' >&2; exit 128; fi\nexec '${real}' "$@"\n` });
481
+ fs.chmodSync(path.join(bin, 'git'), 0o755);
482
+ let r = yadWith({ PATH: `${bin}${path.delimiter}${process.env.PATH}` }, P, 'worktree', 'remove', 'EP-x', '--repo', 'api');
483
+ assert.equal(r.code, 1, r.out);
484
+ assert.match(r.out, /git could not remove .*api--EP-x: fatal: refused by the test/);
485
+ assert.equal(fs.lstatSync(path.join(awt, 'node_modules')).isSymbolicLink(), true, 'the link is back');
486
+ assert.equal(fs.readFileSync(path.join(awt, 'node_modules/dep/index.js'), 'utf8'), 'dep\n');
487
+ assert.equal(worktreeAt(awt)?.epic, 'EP-x', 'still yad\'s worktree');
488
+ assert.match(fs.readFileSync(path.join(api, '.git/info/exclude'), 'utf8'), /# yad worktree \(#115\)/, 'its exclude pair is kept');
489
+ r = yad(P, 'worktree', 'remove', 'EP-x', '--repo', 'api');
490
+ assert.equal(r.code, 0, r.out);
491
+ assert.equal(fs.existsSync(awt), false);
492
+ } finally { fs.rmSync(W, { recursive: true, force: true }); }
493
+ });
494
+
495
+ test('the add rollback never unlinks a node_modules symlink git tracks at origin/<default> (#115 follow-ups review 2)', { skip: process.platform === 'win32' && 'a sh hook and a tracked symlink' }, () => {
496
+ const { W, P, api, awt } = workspace();
497
+ try {
498
+ // origin/main now tracks a node_modules symlink; the main checkout, not yet merged, has its ignored folder.
499
+ const other = path.join(W, 'other');
500
+ git(W, 'clone', '-q', path.join(W, 'api.git'), other);
501
+ git(other, 'config', 'user.name', 'bob');
502
+ git(other, 'config', 'user.email', 'bob@corp.io');
503
+ fs.symlinkSync('src', path.join(other, 'node_modules'));
504
+ git(other, 'add', 'node_modules');
505
+ git(other, 'commit', '-qm', 'a tracked link');
506
+ git(other, 'push', '-q', 'origin', 'main');
507
+ const web = repoWithOrigin(W, 'web', { f: 'x\n' });
508
+ write(P, {
509
+ '.sdlc/repos.json': JSON.stringify({ repos: [{ name: 'api', path: '../api' }, { name: 'web', path: '../web' }] }),
510
+ 'epics/EP-x/epic.md': '---\nid: EP-x\ntype: chore\nstatus: draft\nrepos: [api, web]\n---\n# EP-x\n',
511
+ });
512
+ write(web, { '.git/hooks/post-checkout': '#!/bin/sh\nexit 1\n' });
513
+ fs.chmodSync(path.join(web, '.git/hooks/post-checkout'), 0o755);
514
+ const r = yad(P, 'worktree', 'add', 'EP-x', '--all');
515
+ assert.equal(r.code, 1, r.out);
516
+ assert.doesNotMatch(r.out, /could not take back/);
517
+ assert.equal(fs.existsSync(awt), false, 'api\'s worktree was taken back: its tracked link was left for git');
518
+ for (const at of [P, api, web]) assert.equal(git(at, 'worktree', 'list').split('\n').length, 1);
519
+ } finally { fs.rmSync(W, { recursive: true, force: true }); }
520
+ });
package/cli/thread.mjs CHANGED
@@ -227,6 +227,10 @@ export async function runReconcile(root, { action = 'check', thread = null, runn
227
227
  // Never an all-clear over what was not read, or read in part (review 2): each such repo, ledger or
228
228
  // registry is counted as unknown, and the closing line says so too.
229
229
  unknown = drift.repos.filter((r) => !r.read || r.partial).length + drift.unreadEpics.length + drift.uncompared.length + (drift.registry ? 1 : 0);
230
+ // The merged tasks it can record on its own: `yad build sync` (#365) runs `yad build ship` for each.
231
+ const syncEpics = [...new Set(drift.findings.filter((f) => f.kind === 'merged-no-ship').map((f) => f.epic))].sort();
232
+ // Scoped to a thread, it names those epics: a bare `yad build sync` would sync every epic.
233
+ if (syncEpics.length) hand(`${thread ? syncEpics.map((e) => `\`yad build sync ${e}\``).join(', ') : '`yad build sync`'} records these through \`yad build ship\`, and sets each story shipped once every task is — what it cannot record, it lists`);
230
234
  if (!counted && !unknown) ok('every merged task has a ship record');
231
235
  else if (!counted) info(`no merged task without a ship record in what was read — ${unknown} repo(s), ledger(s), stories or registry not read in full, so merged work there is unknown`);
232
236
  }
package/cli/tidy.mjs CHANGED
@@ -13,7 +13,7 @@ import { productConfigPath } from './manifest.mjs';
13
13
  import { loadProduct } from './gate.mjs';
14
14
  import { platformLogin } from './platform.mjs';
15
15
  import { checkpointAuthor } from './checkpoint.mjs';
16
- import { productGit, resolveDefaultBranch, guardDefaultBranch } from './productcommit.mjs';
16
+ import { productGit, resolveDefaultBranch, guardDefaultBranch, branchToCommitOn } from './productcommit.mjs';
17
17
  import { foldTrust, foldBuild } from './ledger.mjs';
18
18
  import { epicRoot, isValidEpicId, readFrontmatter } from './epic-state.mjs';
19
19
 
@@ -47,8 +47,8 @@ export async function runTidy(root, opts = {}) {
47
47
 
48
48
  const { productConfig } = loadProduct(root);
49
49
  const git = productGit(root);
50
- const branch = git('rev-parse', '--abbrev-ref', 'HEAD').stdout;
51
50
  const defaultBranch = resolveDefaultBranch(git, productConfig);
51
+ const branch = branchToCommitOn(root, git, defaultBranch);
52
52
  if (!guardDefaultBranch(branch, defaultBranch, { allowBranch: opts.allowBranch, cmd: 'yad tidy up', root })) return;
53
53
 
54
54
  if (opts.epic && !isValidEpicId(opts.epic)) { fail(`invalid epic id '${opts.epic}'`); process.exitCode = 1; return; }