yadflow 4.9.0 → 4.11.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 (155) hide show
  1. package/CHANGELOG.md +184 -0
  2. package/README.md +15 -5
  3. package/bin/commands.mjs +11 -1
  4. package/bin/yad.mjs +203 -14
  5. package/cli/agent-guard-worker.mjs +13 -0
  6. package/cli/agent-guard.mjs +1797 -73
  7. package/cli/agent-rules.mjs +64 -5
  8. package/cli/argv-flags.mjs +2 -2
  9. package/cli/brain/vendor/LICENSE-graphology-library.txt +21 -0
  10. package/cli/brain/vendor/LICENSE-graphology.txt +21 -0
  11. package/cli/brain/vendor/LICENSE-sigma.txt +12 -0
  12. package/cli/brain/vendor/graphology-library.min.js +2 -0
  13. package/cli/brain/vendor/graphology.umd.min.js +2 -0
  14. package/cli/brain/vendor/sigma.min.js +1369 -0
  15. package/cli/brain/view/app.js +382 -0
  16. package/cli/brain/view/index.html +63 -0
  17. package/cli/brain/view/live.css +228 -0
  18. package/cli/brain/view/live.html +110 -0
  19. package/cli/brain/view/live.js +884 -0
  20. package/cli/brain/view/style.css +141 -0
  21. package/cli/brain-about.mjs +206 -0
  22. package/cli/brain-activity.mjs +285 -0
  23. package/cli/brain-skills.mjs +118 -0
  24. package/cli/brain-vendor.mjs +71 -0
  25. package/cli/brain-view.mjs +344 -0
  26. package/cli/brain.mjs +810 -0
  27. package/cli/ci-check.mjs +48 -4
  28. package/cli/codeowners-command.mjs +72 -6
  29. package/cli/commit.mjs +17 -3
  30. package/cli/docs.mjs +2 -0
  31. package/cli/doctor.mjs +151 -25
  32. package/cli/epic-state.mjs +186 -4
  33. package/cli/epic.mjs +26 -10
  34. package/cli/errors.mjs +2 -1
  35. package/cli/find-product.mjs +69 -15
  36. package/cli/fold.mjs +31 -6
  37. package/cli/foundation-publish.mjs +256 -0
  38. package/cli/gate.mjs +29 -3
  39. package/cli/git-read.mjs +38 -0
  40. package/cli/guard-stream.mjs +409 -0
  41. package/cli/guide.mjs +3 -1
  42. package/cli/hook.mjs +102 -9
  43. package/cli/issue-links.mjs +61 -0
  44. package/cli/issues-act.mjs +371 -0
  45. package/cli/issues-write.mjs +441 -0
  46. package/cli/issues.mjs +513 -0
  47. package/cli/lib.mjs +37 -2
  48. package/cli/lifecycle.mjs +7 -0
  49. package/cli/local-page.mjs +138 -0
  50. package/cli/machine.mjs +1 -1
  51. package/cli/manifest.mjs +59 -3
  52. package/cli/map/view/app.js +712 -0
  53. package/cli/map/view/index.html +50 -0
  54. package/cli/map/view/style.css +142 -0
  55. package/cli/map-view.mjs +186 -0
  56. package/cli/map.mjs +637 -0
  57. package/cli/members.mjs +9 -15
  58. package/cli/next.mjs +1 -1
  59. package/cli/openpr.mjs +26 -6
  60. package/cli/plan.mjs +127 -0
  61. package/cli/platform.mjs +159 -4
  62. package/cli/product-index.mjs +1 -1
  63. package/cli/protection.mjs +53 -3
  64. package/cli/reconcile.mjs +9 -3
  65. package/cli/report.mjs +9 -3
  66. package/cli/reports-dir.mjs +391 -0
  67. package/cli/reports.mjs +65 -0
  68. package/cli/run-checks.mjs +15 -4
  69. package/cli/scan.mjs +314 -0
  70. package/cli/setup.mjs +42 -8
  71. package/cli/standup.mjs +120 -78
  72. package/cli/status.mjs +6 -5
  73. package/cli/story-frames.mjs +17 -6
  74. package/cli/test-agents-file.mjs +985 -12
  75. package/cli/test-brain-activity.mjs +753 -0
  76. package/cli/test-brain-view.mjs +381 -0
  77. package/cli/test-brain.mjs +795 -0
  78. package/cli/test-build.mjs +25 -0
  79. package/cli/test-ci-check.mjs +469 -10
  80. package/cli/test-guide.mjs +218 -0
  81. package/cli/test-machine.mjs +59 -0
  82. package/cli/test-map.mjs +615 -0
  83. package/cli/test-node.mjs +15 -0
  84. package/cli/test-reports.mjs +382 -0
  85. package/cli/test-run-checks.mjs +21 -0
  86. package/cli/test-setup-agent.mjs +14 -0
  87. package/cli/test-story-frames.mjs +74 -4
  88. package/cli/test-worktree.mjs +24 -3
  89. package/cli/toolbox-connect.mjs +259 -0
  90. package/cli/toolbox.mjs +187 -12
  91. package/cli/update-commit.mjs +101 -9
  92. package/cli/usage.mjs +8 -4
  93. package/package.json +12 -4
  94. package/skills/sdlc/config.yaml +1 -1
  95. package/skills/sdlc/module-help.csv +3 -1
  96. package/skills/yad-analysis/SKILL.md +4 -0
  97. package/skills/yad-architecture/SKILL.md +22 -4
  98. package/skills/yad-backfill/SKILL.md +4 -0
  99. package/skills/yad-change/SKILL.md +7 -1
  100. package/skills/yad-change/references/triage.md +2 -0
  101. package/skills/yad-checks/SKILL.md +15 -7
  102. package/skills/yad-checks/references/check-gates.md +70 -35
  103. package/skills/yad-checks/templates/checks/build-test-lint.sh +7 -0
  104. package/skills/yad-checks/templates/checks/install-deps.sh +6 -0
  105. package/skills/yad-checks/templates/checks/member-check.mjs +3 -2
  106. package/skills/yad-checks/templates/checks/package-manager.sh +42 -0
  107. package/skills/yad-checks/templates/checks/risk-map-check.sh +2 -2
  108. package/skills/yad-checks/templates/checks/verified-commits.sh +3 -3
  109. package/skills/yad-checks/templates/github/yad-checks.yml +358 -69
  110. package/skills/yad-checks/templates/github/yad-pr-text.yml +118 -0
  111. package/skills/yad-checks/templates/github/yad-product-checks.yml +130 -54
  112. package/skills/yad-checks/templates/github/yad-product-pr-text.yml +131 -0
  113. package/skills/yad-checks/templates/github/yad-update-guard.yml +2 -1
  114. package/skills/yad-checks/templates/github/yad-verified-commits.yml +49 -3
  115. package/skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml +80 -20
  116. package/skills/yad-checks/templates/gitlab/yad-product-checks.gitlab-ci.yml +59 -9
  117. package/skills/yad-checks/templates/gitlab/yad-update-guard.gitlab-ci.yml +1 -0
  118. package/skills/yad-checks/templates/gitlab/yad-verified-commits.gitlab-ci.yml +49 -1
  119. package/skills/yad-checks/templates/hooks/agent-guard.mjs +44 -10
  120. package/skills/yad-checks/templates/hooks/ledger-guard-cursor.mjs +12 -6
  121. package/skills/yad-checks/templates/hooks/yad-activity.mjs +238 -0
  122. package/skills/yad-commit/SKILL.md +3 -1
  123. package/skills/yad-connect-design/SKILL.md +42 -10
  124. package/skills/yad-connect-design/references/design-context.md +35 -5
  125. package/skills/yad-connect-design/references/design-registry.md +3 -3
  126. package/skills/yad-connect-learning/SKILL.md +12 -2
  127. package/skills/yad-connect-repos/SKILL.md +18 -0
  128. package/skills/yad-connect-testing/SKILL.md +22 -5
  129. package/skills/yad-connect-testing/references/testing-context.md +1 -1
  130. package/skills/yad-discovery/SKILL.md +11 -0
  131. package/skills/yad-discovery/references/foundation-schema.md +11 -0
  132. package/skills/yad-docs/templates/app/package-lock.json +18 -10
  133. package/skills/yad-docs/templates/app/package.json +6 -1
  134. package/skills/yad-epic/SKILL.md +7 -0
  135. package/skills/yad-epic/references/state-schema.md +50 -1
  136. package/skills/yad-guide/SKILL.md +8 -4
  137. package/skills/yad-implement/SKILL.md +117 -4
  138. package/skills/yad-implement/references/implement-conventions.md +2 -1
  139. package/skills/yad-issues/SKILL.md +54 -0
  140. package/skills/yad-learn/SKILL.md +4 -0
  141. package/skills/yad-open-pr/SKILL.md +6 -0
  142. package/skills/yad-pr-template/SKILL.md +2 -1
  143. package/skills/yad-pr-template/templates/checks/pr-template.sh +8 -4
  144. package/skills/yad-pr-template/templates/checks/pr-title.sh +42 -6
  145. package/skills/yad-product-bridge/references/bridge.md +28 -0
  146. package/skills/yad-product-bridge/templates/github/yad-gate-sync.yml +25 -11
  147. package/skills/yad-product-bridge/templates/gitlab/yad-gate-sync.gitlab-ci.yml +38 -14
  148. package/skills/yad-run/SKILL.md +5 -0
  149. package/skills/yad-scan/SKILL.md +51 -0
  150. package/skills/yad-spec/SKILL.md +32 -2
  151. package/skills/yad-stories/SKILL.md +22 -4
  152. package/skills/yad-stories/references/story-schema.md +1 -1
  153. package/skills/yad-test-cases/SKILL.md +18 -2
  154. package/skills/yad-ui/SKILL.md +43 -8
  155. package/skills/yad-checks/templates/gitlab/.gitlab-ci.yml +0 -49
package/cli/test-node.mjs CHANGED
@@ -127,3 +127,18 @@ test('E161: the error catalogue, docs/CLI.md and the docs site list the same YAD
127
127
  assert.deepEqual(site, env);
128
128
  });
129
129
 
130
+ test('#427: npm run coverage runs exactly the test files npm test runs — CI skips npm test on the coverage leg', () => {
131
+ // ci.yml's test (ubuntu-latest, node 24) job and release-check.sh run only `npm run coverage`. A test file
132
+ // listed in `test` but not in `coverage` would never run there, so the two lists must stay the same.
133
+ const { scripts } = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8'));
134
+ const files = (s) => s.split(/\s+/).filter((w) => /^cli\/test[^ ]*\.(mjs|js)$/.test(w));
135
+ assert.ok(files(scripts.test).length > 10, scripts.test);
136
+ assert.deepEqual(files(scripts.coverage), files(scripts.test), 'the coverage script must list the same test files as npm test');
137
+ // A new test file left out of both lists would run nowhere: every cli/test* file on disk is listed.
138
+ const onDisk = fs.readdirSync(path.join(ROOT, 'cli')).filter((f) => /^test[^/]*\.(mjs|js)$/.test(f)).map((f) => `cli/${f}`);
139
+ assert.deepEqual([...files(scripts.test)].sort(), onDisk.sort(), 'every cli/test* file must be listed in npm test');
140
+ const ci = fs.readFileSync(path.join(ROOT, '.github/workflows/ci.yml'), 'utf8');
141
+ const has = (re, what) => assert.ok(re.test(ci), `ci.yml: ${what}`);
142
+ has(/- name: Test\n {8}if: \$\{\{ !\(matrix\.os == 'ubuntu-latest' && matrix\.node-version == 24\) \}\}\n {8}run: npm test\n/, 'the Test step skips only the ubuntu/24 coverage leg');
143
+ has(/\n {8}if: matrix\.os == 'ubuntu-latest' && matrix\.node-version == 24\n {8}run: npm run coverage\n/, 'the coverage step runs on the ubuntu/24 leg');
144
+ });
@@ -0,0 +1,382 @@
1
+ // E180 — the local reports folder: where it is, how a file is named, the catalog, and `yad reports`.
2
+ import { test } from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+ import { spawnSync } from 'node:child_process';
5
+ import fs from 'node:fs';
6
+ import os from 'node:os';
7
+ import path from 'node:path';
8
+ import { fileURLToPath } from 'node:url';
9
+
10
+ if (process.env.NODE_TEST_CONTEXT) {
11
+ const write = process.stdout.write;
12
+ for (const k of ['log', 'info']) {
13
+ const orig = console[k];
14
+ console[k] = (...a) => (process.stdout.write === write ? console.error(...a) : orig(...a));
15
+ }
16
+ }
17
+ process.env.YAD_NO_UPDATE_NOTIFIER = '1';
18
+
19
+ const { withCatalogLock, reportsDir, mainCheckout, reportName, slug, stamp, saveReport, readCatalog, listReports, pruneReports, freshness, renderIndex, writeOrSave, REPORTS_ENV, CATALOG_FILE } = await import('./reports-dir.mjs');
20
+ const { runReports } = await import('./reports.mjs');
21
+ const { classify } = await import('./agent-rules.mjs');
22
+ const { endJSON } = await import('./lib.mjs');
23
+
24
+ const HERE = path.dirname(fileURLToPath(import.meta.url));
25
+ const YAD = path.join(HERE, '..', 'bin', 'yad.mjs');
26
+
27
+ const tmp = () => fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'yad-reports-')));
28
+ const put = (file, data) => { fs.mkdirSync(path.dirname(file), { recursive: true }); fs.writeFileSync(file, typeof data === 'string' ? data : JSON.stringify(data)); };
29
+ const done = (...dirs) => dirs.forEach((d) => fs.rmSync(d, { recursive: true, force: true }));
30
+ const git = (cwd, ...a) => spawnSync('git', ['-c', 'user.email=t@example.com', '-c', 'user.name=t', '-c', 'commit.gpgsign=false', ...a], { cwd, encoding: 'utf8' });
31
+ const noEnv = {};
32
+ const AT = new Date(2026, 10, 14, 9, 5); // local time, 2026-11-14 09:05
33
+
34
+ // A Product checkout with one commit, inside a fresh workspace folder.
35
+ function product() {
36
+ const ws = tmp();
37
+ const root = path.join(ws, 'product');
38
+ put(path.join(root, '.sdlc', 'product.json'), { name: 'demo' });
39
+ put(path.join(root, 'epics', 'EP-x', 'epic.md'), '# x\n');
40
+ git(root, 'init', '-q', '-b', 'main');
41
+ git(root, 'add', '-A');
42
+ git(root, 'commit', '-q', '-m', 'start');
43
+ return { ws, root };
44
+ }
45
+
46
+ async function captured(fn) {
47
+ const out = []; const orig = console.log;
48
+ console.log = (s) => out.push(String(s));
49
+ try { await fn(); } finally { console.log = orig; endJSON(); }
50
+ return JSON.parse(out.join('\n'));
51
+ }
52
+
53
+ test('the folder sits beside the main checkout — also from a worktree — and the env var wins', () => {
54
+ const { ws, root } = product();
55
+ try {
56
+ assert.equal(reportsDir(root, { env: noEnv }).dir, path.join(ws, 'product--reports'));
57
+ const wt = path.join(ws, 'product--EP-x');
58
+ assert.equal(git(root, 'worktree', 'add', '-q', '--detach', wt).status, 0);
59
+ assert.equal(mainCheckout(wt), root, 'a worktree finds its main checkout');
60
+ assert.equal(reportsDir(wt, { env: noEnv }).dir, path.join(ws, 'product--reports'), 'and saves into the same folder');
61
+ const mine = path.join(ws, 'elsewhere');
62
+ assert.deepEqual(reportsDir(root, { env: { [REPORTS_ENV]: mine } }), { dir: mine, via: 'env' });
63
+ assert.equal(reportsDir(root, { env: { [REPORTS_ENV]: ' ' } }).via, 'beside', 'a blank value is not a choice');
64
+ // A Product folder inside another repo (not its top) keeps its reports beside itself.
65
+ const inner = path.join(root, 'nested');
66
+ fs.mkdirSync(inner);
67
+ assert.equal(mainCheckout(inner), inner);
68
+ // Not a repo at all: beside the folder.
69
+ const plain = path.join(ws, 'plain');
70
+ fs.mkdirSync(plain);
71
+ assert.equal(reportsDir(plain, { env: noEnv }).dir, path.join(ws, 'plain--reports'));
72
+ } finally { done(ws); }
73
+ });
74
+
75
+ test('a name says the time, kind, scope and state, in characters every system accepts', () => {
76
+ assert.equal(stamp(AT), '2026-11-14-0905');
77
+ assert.equal(reportName({ kind: 'standup', scope: 'Ahmed Zaki', state: '3 waiting', at: AT, ext: 'md' }), '2026-11-14-0905--standup--ahmed-zaki--3-waiting.md');
78
+ assert.equal(reportName({ kind: 'usage', scope: 'team', state: '2026-10-01 → 2026-11-14', at: AT, ext: 'html' }), '2026-11-14-0905--usage--team--2026-10-01-2026-11-14.html');
79
+ assert.equal(slug('Ünïcödé: a/b\\c*?"<>|'), 'unicode-a-b-c');
80
+ assert.equal(slug(''), 'none');
81
+ assert.equal(slug('-'.repeat(9)), 'none');
82
+ assert.ok(slug('x'.repeat(200)).length <= 40);
83
+ assert.ok(!slug('ab '.repeat(30), 10).endsWith('-'), 'a cut never ends on a dash');
84
+ const long = reportName({ kind: 'progress-map', scope: 'y'.repeat(300), state: 'z'.repeat(300), at: AT, ext: 'html' });
85
+ assert.ok(long.length <= 120, long.length);
86
+ assert.throws(() => reportName({ kind: '../x', scope: 'a', state: 'b', at: AT, ext: 'md' }), /unknown report kind/);
87
+ assert.throws(() => reportName({ kind: 'usage', scope: 'a', state: 'b', at: AT, ext: 'h/tml' }), /bad report extension/);
88
+ });
89
+
90
+ test('saving writes the file, the ignore file, the catalog and its page; a clash gets -2', () => {
91
+ const { ws, root } = product();
92
+ try {
93
+ const a = saveReport(root, { kind: 'standup', scope: 'team', state: '2 waiting', ext: 'md', content: '# one\n', command: 'standup', at: AT, env: noEnv });
94
+ const dir = path.join(ws, 'product--reports');
95
+ assert.equal(a.file, path.join(dir, 'standup', '2026-11-14-0905--standup--team--2-waiting.md'));
96
+ assert.equal(fs.readFileSync(a.file, 'utf8'), '# one\n');
97
+ assert.match(fs.readFileSync(path.join(dir, '.gitignore'), 'utf8'), /^\*$/m);
98
+ const b = saveReport(root, { kind: 'standup', scope: 'team', state: '2 waiting', ext: 'md', content: '# two\n', at: AT, env: noEnv });
99
+ assert.equal(path.basename(b.file), '2026-11-14-0905--standup--team--2-waiting-2.md');
100
+ const cat = readCatalog(dir);
101
+ assert.equal(cat.entries.length, 2);
102
+ const sha = git(root, 'rev-parse', 'HEAD').stdout.trim();
103
+ assert.deepEqual(cat.entries[0], { file: 'standup/2026-11-14-0905--standup--team--2-waiting.md', kind: 'standup', scope: 'team', state: '2 waiting', createdAt: AT.toISOString(), productSha: sha, productBranch: 'main', anonymous: false, command: 'standup' });
104
+ const page = fs.readFileSync(path.join(dir, 'index.html'), 'utf8');
105
+ assert.match(page, /href="standup\/2026-11-14-0905--standup--team--2-waiting\.md"/);
106
+ assert.match(page, /default-src 'none'/, 'the catalog page runs no script');
107
+ // Inside a git tree, the folder's own ignore file keeps every report out of it.
108
+ git(ws, 'init', '-q');
109
+ assert.equal(git(ws, 'check-ignore', '-q', path.join('product--reports', 'standup', path.basename(a.file))).status, 0);
110
+ } finally { done(ws); }
111
+ });
112
+
113
+ test('a broken catalog is never overwritten: the report is still saved, and the problem is said', () => {
114
+ const { ws, root } = product();
115
+ try {
116
+ const dir = path.join(ws, 'product--reports');
117
+ put(path.join(dir, CATALOG_FILE), '{ not json');
118
+ const r = saveReport(root, { kind: 'usage', scope: 'team', state: 'all time', ext: 'html', content: '<p>x</p>', at: AT, env: noEnv });
119
+ assert.ok(fs.existsSync(r.file));
120
+ assert.match(r.warnings[0], /cannot be read .* the catalog was not changed/);
121
+ assert.equal(fs.readFileSync(path.join(dir, CATALOG_FILE), 'utf8'), '{ not json');
122
+ put(path.join(dir, CATALOG_FILE), { version: 9, entries: [] });
123
+ assert.match(readCatalog(dir).problem, /version 9/);
124
+ put(path.join(dir, CATALOG_FILE), [1, 2]);
125
+ assert.match(readCatalog(dir).problem, /not a reports catalog/);
126
+ // A file where the folder should be is refused, not written through.
127
+ const other = product();
128
+ put(path.join(other.ws, 'product--reports'), 'a file');
129
+ assert.match(saveReport(other.root, { kind: 'usage', scope: 't', state: 's', ext: 'md', content: 'x', env: noEnv }).problem, /not a plain folder/);
130
+ done(other.ws);
131
+ } finally { done(ws); }
132
+ });
133
+
134
+ test('fresh until the Product\'s epics or .sdlc change; a missing or foreign sha is unknown', () => {
135
+ const { ws, root } = product();
136
+ try {
137
+ saveReport(root, { kind: 'standup', scope: 'team', state: '0 waiting', ext: 'md', content: 'x', at: AT, env: noEnv });
138
+ assert.equal(listReports(root, { env: noEnv }).entries[0].freshness, 'fresh');
139
+ put(path.join(root, 'README.md'), 'not the record\n');
140
+ git(root, 'add', '-A'); git(root, 'commit', '-q', '-m', 'readme');
141
+ assert.equal(listReports(root, { env: noEnv }).entries[0].freshness, 'fresh', 'a change outside the record does not make it stale');
142
+ put(path.join(root, 'epics', 'EP-x', 'epic.md'), '# x moved\n');
143
+ assert.equal(listReports(root, { env: noEnv }).entries[0].freshness, 'fresh', 'an uncommitted change is not the record yet');
144
+ git(root, 'add', '-A'); git(root, 'commit', '-q', '-m', 'move');
145
+ assert.equal(listReports(root, { env: noEnv }).entries[0].freshness, 'stale');
146
+ assert.equal(freshness(root, null), 'unknown');
147
+ assert.equal(freshness(root, 'f'.repeat(40)), 'unknown');
148
+ assert.equal(freshness(root, '--output=x'), 'unknown', 'never passed to git as an option');
149
+ } finally { done(ws); }
150
+ });
151
+
152
+ test('prune is a dry run until --apply, and only ever deletes what the catalog lists inside the folder', () => {
153
+ const { ws, root } = product();
154
+ try {
155
+ const old = saveReport(root, { kind: 'usage', scope: 'team', state: 'old', ext: 'md', content: 'x', at: new Date(2026, 0, 1), env: noEnv });
156
+ const recent = saveReport(root, { kind: 'usage', scope: 'team', state: 'new', ext: 'md', content: 'y', at: AT, env: noEnv });
157
+ const dir = path.join(ws, 'product--reports');
158
+ const outside = path.join(ws, 'keep-me.txt');
159
+ put(outside, 'keep');
160
+ const cat = JSON.parse(fs.readFileSync(path.join(dir, CATALOG_FILE), 'utf8'));
161
+ cat.entries.push({ file: '../keep-me.txt', kind: 'usage', scope: 'x', state: 'x', createdAt: '2000-01-01T00:00:00.000Z' });
162
+ fs.writeFileSync(path.join(dir, CATALOG_FILE), JSON.stringify(cat));
163
+ const now = AT.getTime() + 864e5;
164
+ const dry = pruneReports(root, { days: 30, now, env: noEnv });
165
+ assert.deepEqual(dry.removed.map((e) => [e.file, e.reason]).sort(), [['../keep-me.txt', 'outside'], [path.posix.join('usage', path.basename(old.file)), 'old']].sort());
166
+ assert.ok(fs.existsSync(old.file), 'a dry run deletes nothing');
167
+ const applied = pruneReports(root, { days: 30, now, apply: true, env: noEnv });
168
+ assert.equal(applied.removed.find((e) => e.reason === 'old').file, path.posix.join('usage', path.basename(old.file)), 'review 1: the reason is decided before the delete, so a removed file reads "old"');
169
+ assert.equal(fs.existsSync(old.file), false);
170
+ assert.ok(fs.existsSync(recent.file));
171
+ assert.equal(fs.readFileSync(outside, 'utf8'), 'keep', 'a path that leaves the folder is dropped from the catalog, never deleted');
172
+ assert.equal(readCatalog(dir).entries.length, 1);
173
+ } finally { done(ws); }
174
+ });
175
+
176
+ test('--out still writes exactly the file named, and leaves the catalog alone', () => {
177
+ const { ws, root } = product();
178
+ try {
179
+ const out = path.join(ws, 'sub', 'mine.md');
180
+ const r = writeOrSave(root, { out, kind: 'standup', scope: 'team', state: 's', ext: 'md', content: 'z', env: noEnv });
181
+ assert.equal(r.file, out);
182
+ assert.equal(fs.readFileSync(out, 'utf8'), 'z');
183
+ assert.equal(fs.existsSync(path.join(ws, 'product--reports')), false);
184
+ } finally { done(ws); }
185
+ });
186
+
187
+ test('the catalog page escapes what it shows', () => {
188
+ const page = renderIndex([{ file: 'usage/a"b<c>.md', kind: 'usage', scope: '<script>', state: '"x"', createdAt: AT.toISOString(), productSha: null, anonymous: true }]);
189
+ assert.equal(page.includes('<script>'), false);
190
+ assert.match(page, /&lt;script&gt;/);
191
+ assert.match(page, /anonymous/);
192
+ assert.match(renderIndex([]), /No reports saved yet/);
193
+ });
194
+
195
+ test('yad reports list | open | prune answer in JSON, and refuse what they do not take', async () => {
196
+ const { ws, root } = product();
197
+ try {
198
+ const env = { [REPORTS_ENV]: path.join(ws, 'chosen') };
199
+ saveReport(root, { kind: 'issues', scope: 'all repos', state: '4 items', ext: 'md', content: 'x', at: AT, env });
200
+ const list = await captured(() => runReports(root, { action: 'list', json: true, env }));
201
+ assert.equal(list.command, null);
202
+ assert.equal(list.via, 'env');
203
+ assert.equal(list.entries[0].n, 1);
204
+ assert.equal(list.entries[0].present, true);
205
+ let opened = null;
206
+ const open = await captured(() => runReports(root, { action: 'open', args: ['1'], json: true, env, opener: (f) => { opened = f; return true; } }));
207
+ assert.equal(open.opened, true);
208
+ assert.equal(opened, path.join(ws, 'chosen', list.entries[0].file));
209
+ assert.equal((await captured(() => runReports(root, { action: 'open', args: ['9'], json: true, env }))).ok, false);
210
+ const bad = await captured(() => runReports(root, { action: 'prune', olderThan: 'soon', json: true, env }));
211
+ assert.match(bad.error, /--older-than <days>/);
212
+ const prune = await captured(() => runReports(root, { action: 'prune', olderThan: '0', json: true, env }));
213
+ assert.equal(prune.applied, false);
214
+ // review 2: --missing drops only entries whose file is gone, and deletes no report.
215
+ const kept = path.join(ws, 'chosen', list.entries[0].file);
216
+ saveReport(root, { kind: 'issues', scope: 'all repos', state: 'gone', ext: 'md', content: 'x', at: AT, env });
217
+ const goner = listReports(root, { env }).entries.find((e) => e.state === 'gone');
218
+ fs.rmSync(path.join(ws, 'chosen', goner.file));
219
+ const miss = await captured(() => runReports(root, { action: 'prune', missing: true, apply: true, json: true, env }));
220
+ assert.deepEqual(miss.removed.map((e) => e.reason), ['missing']);
221
+ assert.ok(fs.existsSync(kept), 'the report whose file is there stays');
222
+ assert.equal((await captured(() => runReports(root, { action: 'prune', missing: true, olderThan: '3', json: true, env }))).ok, false, 'not both');
223
+ assert.equal((await captured(() => runReports(root, { action: 'frob', json: true, env }))).ok, false);
224
+ process.exitCode = 0;
225
+ } finally { done(ws); }
226
+ });
227
+
228
+ test('yad reports runs from the CLI, and agents may list but must be asked to delete', () => {
229
+ const { ws, root } = product();
230
+ try {
231
+ const r = spawnSync(process.execPath, [YAD, 'reports', '--json'], { cwd: root, encoding: 'utf8', env: { ...process.env, NO_COLOR: '1', SDLC_NONINTERACTIVE: '1', YAD_NO_REPORT: '1', [REPORTS_ENV]: '' } });
232
+ assert.equal(r.status, 0, r.stderr);
233
+ const out = JSON.parse(r.stdout);
234
+ assert.equal(out.command, 'reports list');
235
+ assert.deepEqual(out.entries, []);
236
+ assert.equal(classify(['reports', 'list']), 'read');
237
+ assert.equal(classify(['reports', 'prune']), 'read', 'a dry run');
238
+ assert.equal(classify(['reports', 'prune'], ['apply']), 'on-request');
239
+ } finally { done(ws); }
240
+ });
241
+
242
+ test('review 1: a linked kind folder, a linked reports folder or a bare file name never lets prune, list or open leave the folder', { skip: process.platform === 'win32' && 'making a folder link needs extra rights on Windows' }, () => {
243
+ const { ws, root } = product();
244
+ try {
245
+ const dir = path.join(ws, 'product--reports');
246
+ saveReport(root, { kind: 'usage', scope: 'team', state: 's', ext: 'md', content: 'x', at: AT, env: noEnv });
247
+ const outside = path.join(ws, 'outside');
248
+ put(path.join(outside, 'keep.txt'), 'keep');
249
+ fs.symlinkSync(outside, path.join(dir, 'standup'));
250
+ const cat = JSON.parse(fs.readFileSync(path.join(dir, CATALOG_FILE), 'utf8'));
251
+ cat.entries.push({ file: 'standup/keep.txt', kind: 'standup', scope: 'x', state: 'x', createdAt: '2000-01-01T00:00:00.000Z' });
252
+ cat.entries.push({ file: '.gitignore', kind: 'usage', scope: 'x', state: 'x', createdAt: '2000-01-01T00:00:00.000Z' });
253
+ cat.entries.push({ file: 'catalog.json', kind: 'usage', scope: 'x', state: 'x', createdAt: '2000-01-01T00:00:00.000Z' });
254
+ fs.writeFileSync(path.join(dir, CATALOG_FILE), JSON.stringify(cat));
255
+ const listed = listReports(root, { env: noEnv }).entries;
256
+ assert.equal(listed.find((e) => e.file === 'standup/keep.txt').present, false, 'a file through a linked folder is not "present"');
257
+ const r = pruneReports(root, { days: 1, now: AT.getTime() + 864e5, apply: true, env: noEnv });
258
+ assert.deepEqual(r.removed.map((e) => e.reason).sort(), ['outside', 'outside', 'outside']);
259
+ assert.equal(fs.readFileSync(path.join(outside, 'keep.txt'), 'utf8'), 'keep', 'never deleted through the link');
260
+ assert.ok(fs.existsSync(path.join(dir, '.gitignore')), 'the folder\'s own files are never pruned');
261
+ assert.equal(readCatalog(dir).entries.length, 1);
262
+ // The reports folder itself a link: said, and nothing read or changed through it.
263
+ const real = path.join(ws, 'real-reports');
264
+ fs.mkdirSync(real);
265
+ const env = { [REPORTS_ENV]: path.join(ws, 'linked-reports') };
266
+ fs.symlinkSync(real, env[REPORTS_ENV]);
267
+ assert.match(listReports(root, { env }).problem, /not a plain folder/);
268
+ assert.match(pruneReports(root, { days: 0, apply: true, env }).problem, /not a plain folder/);
269
+ assert.match(saveReport(root, { kind: 'usage', scope: 't', state: 's', ext: 'md', content: 'x', env }).problem, /not a plain folder/);
270
+ } finally { done(ws); }
271
+ });
272
+
273
+ test('review 1: a folder that cannot be written is a refusal with the way out, never a crash', { skip: process.platform === 'win32' || process.getuid?.() === 0 }, () => {
274
+ const { ws, root } = product();
275
+ try {
276
+ const locked = path.join(ws, 'locked');
277
+ fs.mkdirSync(locked);
278
+ fs.chmodSync(locked, 0o500);
279
+ try {
280
+ const r = saveReport(root, { kind: 'usage', scope: 't', state: 's', ext: 'md', content: 'x', env: { [REPORTS_ENV]: path.join(locked, 'reports') } });
281
+ assert.match(r.problem, /cannot save the report .* set YAD_REPORTS_DIR .* or pass --out/);
282
+ } finally { fs.chmodSync(locked, 0o700); }
283
+ } finally { done(ws); }
284
+ });
285
+
286
+ test('review 1: a name already taken is never overwritten, and a held catalog lock waits, then is said', () => {
287
+ const { ws, root } = product();
288
+ try {
289
+ const dir = path.join(ws, 'product--reports');
290
+ const a = saveReport(root, { kind: 'usage', scope: 'team', state: 's', ext: 'md', content: 'first', at: AT, env: noEnv });
291
+ const b = saveReport(root, { kind: 'usage', scope: 'team', state: 's', ext: 'md', content: 'second', at: AT, env: noEnv });
292
+ assert.equal(fs.readFileSync(a.file, 'utf8'), 'first');
293
+ assert.equal(fs.readFileSync(b.file, 'utf8'), 'second');
294
+ // A lock held by a run that is still going (this test's own pid): the report is saved, the catalog is
295
+ // left, and the warning says where the report is — never "try again", which would save a second copy.
296
+ fs.writeFileSync(path.join(dir, 'catalog.lock'), `${process.pid} ${'a'.repeat(16)}`);
297
+ const held = saveReport(root, { kind: 'usage', scope: 'team', state: 'held', ext: 'md', content: 'x', at: AT, env: noEnv, lockWaitMs: 200 });
298
+ assert.ok(fs.existsSync(held.file));
299
+ assert.match(held.warnings[0], /the report was saved at .*held.*not added to the catalog: .*catalog\.lock is held by another yad run that is still going/);
300
+ assert.equal(readCatalog(dir).entries.length, 2);
301
+ assert.equal(fs.readFileSync(path.join(dir, 'catalog.lock'), 'utf8'), `${process.pid} ${'a'.repeat(16)}`, 'a lock that is not ours is never removed');
302
+ // A lock whose run is gone (no such process) is taken over at once, and ours is removed after.
303
+ fs.writeFileSync(path.join(dir, 'catalog.lock'), `2147483646 ${'b'.repeat(16)}`);
304
+ saveReport(root, { kind: 'usage', scope: 'team', state: 'after', ext: 'md', content: 'x', at: AT, env: noEnv });
305
+ assert.equal(readCatalog(dir).entries.length, 3);
306
+ assert.equal(fs.existsSync(path.join(dir, 'catalog.lock')), false);
307
+ assert.deepEqual(fs.readdirSync(dir).filter((n) => n.includes('.stale')), [], 'the set-aside lock is gone too');
308
+ } finally { done(ws); }
309
+ });
310
+
311
+ test('review 3: a young lock yad cannot judge is waited on, never taken; a lock it cannot read ends at the deadline', () => {
312
+ const ws = tmp();
313
+ try {
314
+ const lock = path.join(ws, 'catalog.lock');
315
+ let ran = 0;
316
+ for (const odd of ['', 'half', '0 x']) {
317
+ fs.writeFileSync(lock, odd);
318
+ const r = withCatalogLock(ws, () => { ran++; return {}; }, { waitMs: 150 });
319
+ assert.equal(r.held, true, `${JSON.stringify(odd)} is not taken over while young`);
320
+ assert.equal(fs.readFileSync(lock, 'utf8'), odd);
321
+ }
322
+ // The same content, older than 5 minutes: taken over, used, and released.
323
+ const old = new Date(Date.now() - 6 * 60 * 1000);
324
+ fs.utimesSync(lock, old, old);
325
+ assert.deepEqual(withCatalogLock(ws, () => { ran++; return { ok: 1 }; }, { waitMs: 150 }), { ok: 1 });
326
+ assert.equal(ran, 1);
327
+ assert.equal(fs.existsSync(lock), false);
328
+ // A folder where the lock should be: the loop ends, with the reason.
329
+ fs.mkdirSync(lock);
330
+ const t0 = Date.now();
331
+ const r = withCatalogLock(ws, () => { ran++; return {}; }, { waitMs: 150 });
332
+ assert.ok(Date.now() - t0 < 3000, 'no endless spin');
333
+ assert.equal(r.held, true);
334
+ assert.equal(ran, 1);
335
+ assert.deepEqual(fs.readdirSync(ws).filter((n) => /\.(new|stale)$/.test(n)), [], 'no temp lock files left');
336
+ } finally { done(ws); }
337
+ });
338
+
339
+ test('review 4: on a disk with no hard links the lock falls back to a plain create, and the catalog still updates', () => {
340
+ const { ws, root } = product();
341
+ const link = fs.linkSync;
342
+ fs.linkSync = () => { const e = new Error('operation not permitted'); e.code = 'EPERM'; throw e; };
343
+ try {
344
+ saveReport(root, { kind: 'usage', scope: 'team', state: 'a', ext: 'md', content: 'x', at: AT, env: noEnv });
345
+ const b = saveReport(root, { kind: 'usage', scope: 'team', state: 'b', ext: 'md', content: 'y', at: AT, env: noEnv });
346
+ assert.deepEqual(b.warnings, []);
347
+ const dir = path.join(ws, 'product--reports');
348
+ assert.equal(readCatalog(dir).entries.length, 2);
349
+ assert.equal(fs.existsSync(path.join(dir, 'catalog.lock')), false);
350
+ assert.deepEqual(fs.readdirSync(dir).filter((n) => /\.(new|stale)$/.test(n)), [], 'no temp lock file left');
351
+ assert.equal(pruneReports(root, { days: 0, now: AT.getTime() + 864e5, apply: true, env: noEnv }).removed.length, 2, 'prune works there too');
352
+ } finally { fs.linkSync = link; done(ws); }
353
+ });
354
+
355
+ test('review 5: a takeover that moved a fresh lock puts it back, also on a disk with no hard links', () => {
356
+ const ws = tmp();
357
+ const link = fs.linkSync, rename = fs.renameSync;
358
+ try {
359
+ const lock = path.join(ws, 'catalog.lock');
360
+ const fresh = `${process.pid} ${'c'.repeat(16)}`;
361
+ fs.writeFileSync(lock, `2147483646 ${'d'.repeat(16)}`); // judged stale (its run is gone)…
362
+ fs.renameSync = (from, to) => { fs.writeFileSync(from, fresh); fs.renameSync = rename; return rename(from, to); }; // …but replaced before the move
363
+ fs.linkSync = () => { const e = new Error('no links'); e.code = 'ENOTSUP'; throw e; };
364
+ const r = withCatalogLock(ws, () => ({ ran: true }), { waitMs: 150 });
365
+ assert.equal(r.held, true, 'the live lock is waited on, never taken');
366
+ assert.equal(fs.readFileSync(lock, 'utf8'), fresh, 'and it is back in place');
367
+ } finally { fs.linkSync = link; fs.renameSync = rename; done(ws); }
368
+ });
369
+
370
+ test('E181: prune removes a report\'s digest side file with it, and nothing else', () => {
371
+ const { ws, root } = product();
372
+ try {
373
+ const r = saveReport(root, { kind: 'progress-map', scope: 'all epics', state: '1 of 2', ext: 'html', content: 'x', at: new Date(2026, 0, 1), env: noEnv });
374
+ fs.writeFileSync(`${r.file}.digest.json`, '{}');
375
+ const other = path.join(path.dirname(r.file), 'keep.digest.json');
376
+ fs.writeFileSync(other, '{}');
377
+ pruneReports(root, { days: 30, now: AT.getTime(), apply: true, env: noEnv });
378
+ assert.equal(fs.existsSync(r.file), false);
379
+ assert.equal(fs.existsSync(`${r.file}.digest.json`), false);
380
+ assert.ok(fs.existsSync(other));
381
+ } finally { done(ws); }
382
+ });
@@ -460,6 +460,10 @@ test('yad run checks: the base follows the registry like yad open-pr, and GitLab
460
460
  const r = yad(backend, ['run', 'checks', '--no-build', '--body', body]);
461
461
  assert.match(r.out, /base origin\/develop/);
462
462
  assert.match(r.out, /the description is \d+ characters; GitLab hands CI only the first 2700/);
463
+ // From a plain git worktree of backend, beside it, too: it is backend, so the registry's base (#515).
464
+ git(backend, 'worktree', 'add', '-q', path.join(W, 'backend-wt'), '-b', 'feat/wt');
465
+ const wt = yad(path.join(W, 'backend-wt'), ['run', 'checks', '--no-build', '--body', body]);
466
+ assert.match(wt.out, /base origin\/develop/, wt.out);
463
467
  } finally { fs.rmSync(W, { recursive: true, force: true }); }
464
468
  });
465
469
 
@@ -601,3 +605,20 @@ test('yad run checks: a folder read as it was, removed while the Product gates r
601
605
  assert.equal(JSON.parse(r.stdout).product.vanished, true);
602
606
  } finally { fs.rmSync(W, { recursive: true, force: true }); }
603
607
  });
608
+
609
+ test('#450 yad run checks: a branch cut from another branch, with a base nobody chose, is warned about once — and the run goes on', () => {
610
+ const { W, backend } = workspace();
611
+ try {
612
+ git(backend, 'checkout', '-q', '-b', 'develop', 'main');
613
+ commitAll(backend, 'feat: other\n\nTask: EP-demo-S01-T09', { 'src/other.js': 'o\n' });
614
+ git(backend, 'push', '-q', 'origin', 'develop');
615
+ git(backend, 'checkout', '-q', '-b', 'feature-2');
616
+ commitAll(backend, 'feat: two\n\nTask: EP-demo-S01-T02', { 'src/two.js': 't\n' });
617
+ const r = yad(backend, ['run', 'checks', '--no-build']);
618
+ const hits = r.out.match(/this branch holds 1 commit of other tasks from origin\/develop that origin\/main does not have, so it was likely cut from origin\/develop — pass --base origin\/develop, or --base origin\/main to check against main anyway/g) || [];
619
+ assert.equal(hits.length, 1, r.out);
620
+ assert.match(r.out, /PASS \[spec-link\]: \w+ EP-demo-S01-T02/, 'the gates still run');
621
+ // A base someone chose is trusted: no warning.
622
+ assert.doesNotMatch(yad(backend, ['run', 'checks', '--no-build', '--base', 'origin/main']).out, /likely cut from/);
623
+ } finally { fs.rmSync(W, { recursive: true, force: true }); }
624
+ });
@@ -350,3 +350,17 @@ test('E159 case 13 (join): join --json never starts a login; its member step is
350
350
  assert.deepEqual(r.json.member.person.commands, ['gh auth login --hostname github.com --scopes user:email']);
351
351
  } finally { fs.rmSync(T, { recursive: true, force: true }); }
352
352
  });
353
+
354
+ test('E167 (#353): setup shows what the agent guard pre-approves, and what it never does, beside the allow list', async () => {
355
+ const { PREAPPROVED } = await import('./agent-guard.mjs');
356
+ const T = tmp();
357
+ try {
358
+ const P = path.join(T, 'p');
359
+ fs.mkdirSync(P);
360
+ const r = yad(T, P, ['setup', '--solo', '--greenfield', '--monorepo', '--no-tools', '--git-init', '--ide-targets', '.claude', '--platform', 'none', '--connect', 'none'], { SDLC_NONINTERACTIVE: '1' });
361
+ assert.equal(r.code, 0, r.out + r.err);
362
+ assert.match(r.out, /Bash\(yad guide:\*\)/, 'the allow list first');
363
+ assert.match(r.out, /judged by the agent guard each time \(YAD_NO_PREAPPROVE=1 turns this off\)/);
364
+ for (const [k, text] of Object.entries(PREAPPROVED)) assert.ok(r.out.includes(k === 'never' ? `never: ${text}` : `- ${text}`), `${k}: ${r.out}`);
365
+ } finally { fs.rmSync(T, { recursive: true, force: true }); }
366
+ });
@@ -248,10 +248,13 @@ test('#358: designPreflight — Pencil is read through the app; Figma only throu
248
248
  assert.deepEqual([pencil.reachable, pencil.appBound, pencil.frame, pencil.file], ['check', true, '12:34', 'design/app.pen'], 'the first frame that resolves is the one probed');
249
249
  assert.match(pencil.stop, /^Open the Pencil desktop app with `design\/app\.pen` loaded/);
250
250
  assert.match(pencil.probe, /get_app_state/);
251
+ // E165: the command to connect the tool, when it is not on this machine at all.
252
+ assert.equal(pencil.connect, 'yad toolbox connect pencil --json');
251
253
  const desk = designPreflight({ state: 'ok', data: { tool: 'figma', provider: 'figma-desktop' } }, links, frames);
252
254
  assert.deepEqual([desk.appBound, /desktop app/.test(desk.stop)], [true, true]);
255
+ assert.equal(desk.connect, undefined, 'the desktop app\'s own server: open the app, never the hosted plugin\'s recipe');
253
256
  const cloud = designPreflight({ state: 'ok', data: { tool: 'figma', provider: 'figma' } }, links, frames);
254
- assert.deepEqual([cloud.appBound, /^Sign in to Figma/.test(cloud.stop)], [false, true]);
257
+ assert.deepEqual([cloud.appBound, /^Sign in to Figma/.test(cloud.stop), cloud.connect], [false, true, 'yad toolbox connect figma --json']);
255
258
  assert.match(cloud.probe, /`12:34`/);
256
259
  const old = designPreflight({ state: 'ok', data: { tool: 'figma', provider: 'figma-mcp' } }, links, frames);
257
260
  assert.deepEqual([old.appBound, /desktop app.*or sign in/.test(old.stop)], [null, true], 'the older figma-mcp: yad cannot tell, so both');
@@ -268,13 +271,38 @@ test('#358: designPreflight — Pencil is read through the app; Figma only throu
268
271
  assert.equal(designPreflight({ state: 'ok', data: { tool: 'figma', provider } }, links, frames).reachable, 'not-checkable', provider);
269
272
  }
270
273
  assert.equal(designPreflight({ state: 'ok', data: { tool: 'figma' } }, { ...links, tool: 'Figma' }, frames).reachable, 'check', 'the same tool in other letters is not a switch');
274
+ for (const r of [pencil, desk, cloud, old]) assert.equal(r.local, false, 'only a provider in reach.local is local');
275
+ });
276
+
277
+ test('E164: designPreflight — OpenPencil\'s CLI needs no app and no sign-in; its MCP server needs the app', () => {
278
+ const frames = [{ id: 'login-mobile', found: true }];
279
+ const links = { state: 'ok', tool: 'openpencil', fileUrl: 'epics/EP-shop/design/screens.fig', screens: [] };
280
+ const cli = designPreflight({ state: 'ok', data: { tool: 'openpencil', provider: 'openpencil-cli' } }, links, frames);
281
+ assert.deepEqual([cli.reachable, cli.appBound, cli.local, cli.frame], ['check', false, true, 'login-mobile']);
282
+ assert.match(cli.probe, /^check that `epics\/EP-shop\/design\/screens\.fig` is in the Product checkout and that `openpencil --version` runs/);
283
+ assert.match(cli.probe, /shared plugin data `yad`\/`nodeId` is `login-mobile`/, 'the frame is found by the ID yad stored on it');
284
+ assert.match(cli.stop, /^Pull the Product so that `epics\/EP-shop\/design\/screens\.fig` is there with frame `login-mobile` in it/);
285
+ for (const text of [cli.probe, cli.stop]) assert.doesNotMatch(text, /desktop app|sign in/i, 'the CLI path never asks for an app or a sign-in');
286
+ assert.equal(cli.connect, 'yad toolbox connect openpencil --json');
287
+ const mcp = designPreflight({ state: 'ok', data: { tool: 'openpencil', provider: 'openpencil-mcp' } }, links, frames);
288
+ assert.deepEqual([mcp.appBound, mcp.local], [true, false]);
289
+ assert.match(mcp.probe, /OpenPencil MCP: its eval tool/);
290
+ assert.match(mcp.stop, /^Open the OpenPencil desktop app with `epics\/EP-shop\/design\/screens\.fig` loaded \(the file must be inside OPENPENCIL_MCP_ROOT\)/);
291
+ assert.equal(mcp.connect, 'yad toolbox connect openpencil --json', 'OpenPencil\'s recipe adds its MCP server, so it is offered');
292
+ const unknown = designPreflight({ state: 'ok', data: { tool: 'openpencil' } }, links, frames);
293
+ assert.deepEqual([unknown.appBound, unknown.local, /runs in your terminal \(the CLI\), or open the OpenPencil desktop app/.test(unknown.stop)], [null, false, true], 'no provider: both ways');
294
+ assert.match(unknown.probe, /^try the CLI first: .*`openpencil eval`.* if that does not find it, find frame .* through the OpenPencil MCP's eval tool.*It fails only when neither finds it/, 'reviews 1-2: the check tries both ways the stop text names, the MCP whenever the CLI does not find the frame');
295
+ assert.equal(designPreflight({ state: 'ok', data: { tool: 'figma', provider: 'figma-mcp' } }, { ...links, tool: 'figma' }, frames).probe.includes('get_metadata'), true, 'a tool with no eitherProbe keeps its probe');
296
+ assert.equal(designPreflight({ state: 'ok', data: { tool: 'openpencil', provider: 'OpenPencil_CLI' } }, links, frames).local, true, 'names are compared on letters and digits');
271
297
  });
272
298
 
273
299
  test('#358: designPreflight — nothing to probe is not-checkable, and no frame means no preflight', () => {
274
300
  const frames = [{ id: '12:34', found: true }];
275
301
  const links = { state: 'ok', fileUrl: 'f', screens: [] };
276
302
  for (const design of [{ state: 'missing' }, { state: 'unreadable' }, { state: 'ok', data: { tool: 'none' } }, { state: 'ok', data: { tool: 'pencil', source: 'unavailable' } }, { state: 'ok', data: { tool: 'sketch' } }]) {
277
- assert.equal(designPreflight(design, links, frames).reachable, 'not-checkable', JSON.stringify(design));
303
+ const r = designPreflight(design, links, frames);
304
+ assert.equal(r.reachable, 'not-checkable', JSON.stringify(design));
305
+ assert.equal(r.connect, undefined, 'nothing to probe, nothing to connect: connecting the team\'s tool is yad-connect-design\'s');
278
306
  }
279
307
  assert.equal(designPreflight({ state: 'ok', data: { tool: 'pencil' } }, links, []), null);
280
308
  const writer = designPreflight({ state: 'ok', data: { tool: 'figma', provider: 'html-to-design' } }, links, frames);
@@ -295,7 +323,16 @@ test('#358: designPreflight — nothing to probe is not-checkable, and no frame
295
323
  test('#358: readDesignConfig, the reach data, and preflight through the command', () => {
296
324
  for (const t of TOOLBOX.filter((x) => x.reach)) assert.deepEqual(toolProblems(t), [], t.id);
297
325
  const figma = TOOLBOX.find((x) => x.id === 'figma');
298
- assert.deepEqual(toolProblems({ ...figma, reach: { app: 'F', probe: 'p', open: 'o', readers: true, appBound: ['x'] } }), ['reach.signIn and reach.either say what to do when the provider needs no app, or yad cannot tell']);
326
+ assert.deepEqual(toolProblems({ ...figma, reach: { app: 'F', probe: 'p', open: 'o', readers: true, appBound: ['x'] } }), ['reach.either says what to do when yad cannot tell whether the provider needs the app']);
327
+ assert.deepEqual(toolProblems({ ...figma, reach: { app: 'F', probe: 'p', open: 'o', appBound: ['x'], either: 'e', signInOnly: ['y'] } }), ['reach.signIn says what to do for a provider in signInOnly']);
328
+ // E164: a local provider (a CLI on the file) carries its own probe and stop text.
329
+ const op = TOOLBOX.find((x) => x.id === 'openpencil');
330
+ assert.deepEqual(toolProblems({ ...op, reach: { ...op.reach, localStop: undefined } }), ['reach.localProbe and reach.localStop say how to check a provider in local, and what to do when that fails']);
331
+ assert.deepEqual(toolProblems({ ...op, reach: { ...op.reach, local: 'openpencil-cli' } }), ['reach.local is absent or a list of providers']);
332
+ assert.deepEqual(toolProblems({ ...figma, reach: { ...figma.reach, ownServer: [1] } }), ['reach.ownServer is absent or a list of providers']);
333
+ assert.deepEqual(toolProblems({ ...op, reach: { ...op.reach, eitherProbe: '' } }), ['reach.eitherProbe is absent or how to check when yad cannot tell the provider']);
334
+ assert.deepEqual(toolProblems({ ...op, reach: { ...op.reach, local: ['openpencil-mcp'] } }), ['a provider is in reach.local or reach.appBound, not both']);
335
+ assert.deepEqual(toolProblems({ ...op, reach: { ...op.reach, local: ['OpenPencil_MCP'] } }), ['a provider is in reach.local or reach.appBound, not both'], 'review 2: compared as the preflight compares them');
299
336
  assert.ok(toolProblems({ ...figma, reach: { readers: true, appBound: true } }).includes('reach has app, probe and open'));
300
337
  assert.ok(toolProblems({ ...figma, reach: null }).length > 0);
301
338
  assert.ok(toolProblems({ ...figma, reach: { ...figma.reach, appBound: false } }).includes('reach.appBound is true, or the providers read through the app'));
@@ -308,7 +345,20 @@ test('#358: readDesignConfig, the reach data, and preflight through the command'
308
345
  put(path.join(T, '.sdlc', 'design.json'), { tool: 'pencil', provider: 'pencil-mcp', source: 'pencil-mcp', auth: 'user' });
309
346
  const j = JSON.parse(yad(T, 'story', 'frames', 'EP-shop-S01', '--json').stdout);
310
347
  assert.deepEqual([j.preflight.reachable, j.preflight.tool, j.preflight.appBound], ['check', 'pencil', true]);
311
- assert.match(yad(T, 'story', 'frames', 'EP-shop-S01').stdout, /before UI work: .* if that fails, stop: Open the Pencil desktop app/);
348
+ assert.match(yad(T, 'story', 'frames', 'EP-shop-S01').stdout, /before UI work: .* if that fails, stop: Open the Pencil desktop app[\s\S]*if pencil is not on this machine at all, your agent can offer to connect it first: `yad toolbox connect pencil --json`/);
349
+ assert.equal(j.preflight.connect, 'yad toolbox connect pencil --json');
350
+ // Review 2: no `connect`, no offer line — Figma's desktop server is opened, never connected.
351
+ put(path.join(T, '.sdlc', 'design.json'), { tool: 'figma', provider: 'figma-desktop', source: 'figma-desktop', auth: 'user' });
352
+ put(path.join(T, 'epics', 'EP-shop', '.sdlc', 'design-links.json'), { ...LINKS, tool: 'figma', source: 'figma' });
353
+ const desk = yad(T, 'story', 'frames', 'EP-shop-S01');
354
+ assert.match(desk.stdout, /before UI work: .* if that fails, stop: .*Figma desktop app/);
355
+ assert.doesNotMatch(desk.stdout, /offer to connect/);
356
+ // E164: OpenPencil's CLI — the local probe and stop, and the connect offer.
357
+ put(path.join(T, '.sdlc', 'design.json'), { tool: 'openpencil', provider: 'openpencil-cli', source: 'openpencil-cli', auth: 'user' });
358
+ put(path.join(T, 'epics', 'EP-shop', '.sdlc', 'design-links.json'), { ...LINKS, tool: 'openpencil', source: 'openpencil-cli' });
359
+ const opj = JSON.parse(yad(T, 'story', 'frames', 'EP-shop-S01', '--json').stdout).preflight;
360
+ assert.deepEqual([opj.reachable, opj.appBound, opj.local, opj.connect], ['check', false, true, 'yad toolbox connect openpencil --json']);
361
+ assert.match(yad(T, 'story', 'frames', 'EP-shop-S01').stdout, /before UI work: check that .* `openpencil --version` runs.* if that fails, stop: Pull the Product[\s\S]*offer to connect it first: `yad toolbox connect openpencil --json`/);
312
362
  assert.equal(JSON.parse(yad(T, 'story', 'frames', 'EP-shop-S02', '--json').stdout).preflight, null, 'no screens, no probe');
313
363
  } finally { done(T); }
314
364
  });
@@ -337,3 +387,23 @@ test('#358: spec and implement probe the design tool first, stop on a failure, a
337
387
  const example = connect.slice(connect.indexOf('### Step 2'), connect.indexOf('### Step 3'));
338
388
  assert.ok(example.includes('"provider": "figma-desktop"') && !example.includes('figma-mcp'), 'the registry example records a provider the preflight can read');
339
389
  });
390
+
391
+ test('E164 PR 2: the skills give each OpenPencil frame yad\'s own ID, fold takes design/, and the probe may be a CLI command', () => {
392
+ const read = (rel) => fs.readFileSync(path.join(REPO, rel), 'utf8');
393
+ const ui = read('skills/yad-ui/SKILL.md');
394
+ const ctx = read('skills/yad-connect-design/references/design-context.md');
395
+ for (const [name, text] of [['yad-ui', ui], ['design-context', ctx]]) {
396
+ assert.match(text, /setSharedPluginData\('yad', 'nodeId', '<id>'\)/, `${name}: yad stores its own ID on the frame`);
397
+ assert.match(text, /getSharedPluginData\('yad', 'nodeId'\) === '<id>'/, `${name}: and finds the frame by it`);
398
+ assert.match(text, /`yad fold` (takes that folder too|commits the\s+`design\/` folder)/, `${name}: fold takes design/`);
399
+ assert.doesNotMatch(text, /not taken by `yad fold` yet|Until E164's second PR/, `${name}: no note from before PR 2`);
400
+ }
401
+ assert.match(ui, /each screen's `nodeId` is the ID yad stored on its frame/);
402
+ assert.match(ctx, /\| `openpencil`, provider `openpencil-cli` \|/);
403
+ assert.doesNotMatch(ctx, /not checked yet: yad has no reach rule/);
404
+ for (const skill of ['yad-spec', 'yad-implement']) {
405
+ const text = read(`skills/${skill}/SKILL.md`);
406
+ assert.match(text, /make the check `preflight\.probe`\s+describes \(an MCP call, or for a tool's\s+CLI — `preflight\.local` is true — a command in your terminal\)/, skill);
407
+ assert.doesNotMatch(text, /make the MCP call/, skill);
408
+ }
409
+ });
@@ -188,7 +188,7 @@ test('yad worktree: an epic that is not there, a repo not registered, and a repo
188
188
  } finally { fs.rmSync(W, { recursive: true, force: true }); }
189
189
  });
190
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)', () => {
191
+ test('from an epic\'s code worktree: the registry knows the repo, and Product commands go to the epic\'s Product worktree (#115); a plain worktree is the repo too (#515)', () => {
192
192
  const { W, P, api, pwt, awt } = workspace();
193
193
  try {
194
194
  assert.equal(yad(P, 'worktree', 'add', 'EP-x', '--repo', 'api').code, 0);
@@ -199,9 +199,30 @@ test('from an epic\'s code worktree: the registry knows the repo, and Product co
199
199
  assert.deepEqual([found.root, found.worktree, found.repo?.name], [pwt, 'EP-x', 'api']);
200
200
  const r = yad(awt, 'worktree', 'list');
201
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.
202
+ // A plain worktree yad did not make is api too (#515), worked in its own folder (E80 review 3).
203
203
  git(api, 'worktree', 'add', '-q', '--detach', path.join(W, 'api-other'));
204
- assert.equal(registryEntryFor(P, path.join(W, 'api-other')), null);
204
+ const plain = registryEntryFor(P, path.join(W, 'api-other', 'src'));
205
+ assert.deepEqual([plain?.meta?.name, plain && fs.realpathSync(plain.top)], ['api', fs.realpathSync(path.join(W, 'api-other'))]);
206
+ assert.equal(findProduct(path.join(W, 'api-other')).repo?.name, 'api', 'beside the Product, it finds it');
207
+ // A `.git` file written by hand that points at api's worktree folder is not that worktree: git's back-link
208
+ // names another folder.
209
+ const wtGit = fs.readFileSync(path.join(W, 'api-other', '.git'), 'utf8');
210
+ fs.mkdirSync(path.join(W, 'fake'));
211
+ fs.writeFileSync(path.join(W, 'fake', '.git'), wtGit.replace(/gitdir:\s*(.+)/, (_, p) => `gitdir: ${path.resolve(path.join(W, 'api-other'), p.trim())}`));
212
+ assert.equal(registryEntryFor(P, path.join(W, 'fake')), null, 'the back-link names api-other');
213
+ // Nor a `.git` file pointing at yad's own epic worktree of api, with its record (#515 review 2).
214
+ const awtGit = fs.readFileSync(path.join(awt, '.git'), 'utf8');
215
+ fs.mkdirSync(path.join(W, 'fake-epic'));
216
+ fs.writeFileSync(path.join(W, 'fake-epic', '.git'), awtGit.replace(/gitdir:\s*(.+)/, (_, p) => `gitdir: ${path.resolve(awt, p.trim())}`));
217
+ assert.equal(registryEntryFor(P, path.join(W, 'fake-epic')), null, 'the back-link names api--EP-x');
218
+ assert.equal(findProduct(path.join(W, 'fake-epic')).repo, undefined, 'and it borrows no repo from the workspace file');
219
+ // A worktree of another clone of api is not the registered checkout.
220
+ git(W, 'clone', '-q', path.join(W, 'api.git'), 'api-clone');
221
+ git(path.join(W, 'api-clone'), 'worktree', 'add', '-q', '--detach', path.join(W, 'api-clone-wt'));
222
+ assert.equal(registryEntryFor(P, path.join(W, 'api-clone-wt')), null, 'another clone');
223
+ // Nor is a plain worktree of the Product a registered code repo.
224
+ git(P, 'worktree', 'add', '-q', '--detach', path.join(W, 'product-plain'));
225
+ assert.equal(registryEntryFor(P, path.join(W, 'product-plain')), null, 'never the Product\'s own entry');
205
226
  // Nor does a record copied into some other repo's worktree.
206
227
  const other = repoWithOrigin(W, 'other', { f: 'x\n' });
207
228
  git(other, 'worktree', 'add', '-q', '--detach', path.join(W, 'other--EP-x'));