yadflow 4.10.0 → 4.12.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 (120) hide show
  1. package/CHANGELOG.md +152 -0
  2. package/README.md +14 -3
  3. package/bin/commands.mjs +7 -1
  4. package/bin/yad.mjs +163 -16
  5. package/cli/agent-guard-worker.mjs +13 -0
  6. package/cli/agent-guard.mjs +1053 -57
  7. package/cli/agent-rules.mjs +59 -3
  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 +345 -0
  26. package/cli/brain.mjs +810 -0
  27. package/cli/brand-cmd.mjs +326 -0
  28. package/cli/brand.mjs +327 -0
  29. package/cli/ci-check.mjs +3 -3
  30. package/cli/doctor.mjs +145 -14
  31. package/cli/epic-state.mjs +93 -1
  32. package/cli/epic.mjs +15 -3
  33. package/cli/errors.mjs +2 -1
  34. package/cli/find-product.mjs +69 -15
  35. package/cli/foundation-publish.mjs +256 -0
  36. package/cli/gate.mjs +29 -3
  37. package/cli/git-read.mjs +38 -0
  38. package/cli/guard-stream.mjs +409 -0
  39. package/cli/guide.mjs +26 -3
  40. package/cli/hook.mjs +59 -9
  41. package/cli/issues-act.mjs +57 -13
  42. package/cli/issues-write.mjs +19 -6
  43. package/cli/issues.mjs +69 -24
  44. package/cli/lib.mjs +37 -2
  45. package/cli/local-page.mjs +138 -0
  46. package/cli/local-setup-record.mjs +71 -0
  47. package/cli/local-setup-steps.mjs +186 -0
  48. package/cli/local-setup.mjs +611 -0
  49. package/cli/machine.mjs +1 -1
  50. package/cli/manifest.mjs +55 -0
  51. package/cli/map/view/app.js +712 -0
  52. package/cli/map/view/index.html +50 -0
  53. package/cli/map/view/style.css +142 -0
  54. package/cli/map-view.mjs +190 -0
  55. package/cli/map.mjs +637 -0
  56. package/cli/members.mjs +9 -15
  57. package/cli/next.mjs +1 -1
  58. package/cli/openpr.mjs +2 -2
  59. package/cli/plain-text.mjs +22 -0
  60. package/cli/plan.mjs +310 -36
  61. package/cli/platform.mjs +5 -5
  62. package/cli/product-index.mjs +1 -1
  63. package/cli/protection.mjs +32 -0
  64. package/cli/reconcile.mjs +61 -13
  65. package/cli/report.mjs +9 -3
  66. package/cli/reports-dir.mjs +393 -0
  67. package/cli/reports.mjs +65 -0
  68. package/cli/run-checks.mjs +5 -2
  69. package/cli/scan.mjs +4 -6
  70. package/cli/secret-text.mjs +66 -0
  71. package/cli/setup.mjs +54 -8
  72. package/cli/standup.mjs +94 -72
  73. package/cli/status.mjs +6 -5
  74. package/cli/test-agents-file.mjs +614 -8
  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-brand.mjs +558 -0
  79. package/cli/test-guide.mjs +438 -0
  80. package/cli/test-local-setup.mjs +1188 -0
  81. package/cli/test-machine.mjs +59 -0
  82. package/cli/test-map.mjs +615 -0
  83. package/cli/test-reports.mjs +382 -0
  84. package/cli/test-run-checks.mjs +4 -0
  85. package/cli/test-worktree.mjs +24 -3
  86. package/cli/toolbox-connect.mjs +21 -6
  87. package/cli/toolbox.mjs +74 -5
  88. package/cli/update-commit.mjs +118 -9
  89. package/cli/usage.mjs +17 -7
  90. package/cli/workspace.mjs +11 -2
  91. package/package.json +8 -4
  92. package/skills/sdlc/module-help.csv +1 -0
  93. package/skills/yad-architecture/SKILL.md +22 -4
  94. package/skills/yad-brand/SKILL.md +69 -0
  95. package/skills/yad-change/SKILL.md +3 -1
  96. package/skills/yad-change/references/triage.md +2 -0
  97. package/skills/yad-checks/SKILL.md +2 -0
  98. package/skills/yad-checks/references/check-gates.md +8 -5
  99. package/skills/yad-checks/templates/checks/build-test-lint.sh +7 -0
  100. package/skills/yad-checks/templates/checks/install-deps.sh +6 -0
  101. package/skills/yad-checks/templates/checks/package-manager.sh +42 -0
  102. package/skills/yad-checks/templates/github/yad-checks.yml +3 -2
  103. package/skills/yad-checks/templates/gitlab/yad-checks.gitlab-ci.yml +3 -2
  104. package/skills/yad-checks/templates/hooks/local-setup-notice.mjs +96 -0
  105. package/skills/yad-checks/templates/hooks/yad-activity.mjs +238 -0
  106. package/skills/yad-connect-repos/SKILL.md +14 -0
  107. package/skills/yad-discovery/SKILL.md +11 -0
  108. package/skills/yad-discovery/references/foundation-schema.md +11 -0
  109. package/skills/yad-docs/templates/app/package-lock.json +18 -10
  110. package/skills/yad-docs/templates/app/package.json +6 -1
  111. package/skills/yad-epic/SKILL.md +3 -0
  112. package/skills/yad-epic/references/state-schema.md +35 -1
  113. package/skills/yad-guide/SKILL.md +10 -7
  114. package/skills/yad-implement/SKILL.md +76 -15
  115. package/skills/yad-issues/SKILL.md +2 -1
  116. package/skills/yad-pr-template/templates/checks/pr-template.sh +8 -4
  117. package/skills/yad-pr-template/templates/checks/pr-title.sh +8 -4
  118. package/skills/yad-spec/SKILL.md +19 -0
  119. package/skills/yad-stories/SKILL.md +22 -4
  120. package/skills/yad-stories/references/story-schema.md +1 -1
@@ -32,6 +32,7 @@ const { buildGuide, stepFacts, playbook, tok, agentRun } = await import('./guide
32
32
  const COMMAND_CLASS_MODULE = await import('./agent-rules.mjs');
33
33
  const { COMMAND_CLASS, CLASSES, ASK, RULES, HUMAN_ONLY_ACTS, NEVER, classify, askFor } = await import('./agent-rules.mjs');
34
34
  const { DEFAULT_LIFECYCLE } = await import('./lifecycle.mjs');
35
+ const TOOLBOX_IDS = (await import('./toolbox.mjs')).TOOLBOX.map((t) => t.id);
35
36
  const { runEpicNew } = await import('./epic.mjs');
36
37
  const { gateOpen } = await import('./gate.mjs');
37
38
 
@@ -608,6 +609,52 @@ test('an install behind yadflow: the guide says so, from what is committed, and
608
609
  } finally { fs.rmSync(T, { recursive: true, force: true }); }
609
610
  });
610
611
 
612
+ test('local setup steps waiting for this machine ride the upkeep, after the update, and the guide starts no gh (E185)', async () => {
613
+ const { localSetupActions, runLocalSetupSkip } = await import('./local-setup.mjs');
614
+ const { VERSION } = await import('./manifest.mjs');
615
+ const T = await product();
616
+ const saved = [console.log, process.exitCode, process.env.PATH];
617
+ console.log = () => {};
618
+ try {
619
+ put(path.join(T, '.sdlc/cli-version.json'), { version: VERSION });
620
+ // Every shipped tool skipped, and one team step.
621
+ put(path.join(T, '.sdlc/toolbox.json'), { shipped: Object.fromEntries(TOOLBOX_IDS.map((id) => [id, 'skip'])) });
622
+ for (const a of localSetupActions(T)) if (!a.writesNothing) a.apply();
623
+ const file = path.join(T, '.sdlc/local-setup.json');
624
+ const team = { id: 'docker', title: 'Install Docker', purpose: 'runs the API', impact: 'adds Docker', when: 'optional', commands: ['brew install docker'], check: { run: 'docker --version' } };
625
+ put(file, { ...JSON.parse(fs.readFileSync(file, 'utf8')), team: [team] });
626
+ git(T, ['add', '-A']); git(T, ['commit', '-q', '-m', 'chore: local setup']);
627
+
628
+ // A gh or glab the guide started would leave a mark: none may (the login check can reach the network).
629
+ const calls = path.join(T, '.calls');
630
+ if (process.platform !== 'win32') {
631
+ const bin = path.join(T, '.bin');
632
+ fs.mkdirSync(bin);
633
+ for (const name of ['gh', 'glab']) { const f = path.join(bin, name); fs.writeFileSync(f, `#!/bin/sh\necho ${name} >> '${calls}'\nexit 1\n`); fs.chmodSync(f, 0o755); }
634
+ process.env.PATH = `${bin}${path.delimiter}${saved[2]}`;
635
+ }
636
+ const g = buildGuide(T, { epic: 'EP-pay' });
637
+ assert.ok(!fs.existsSync(calls), 'the guide started gh or glab');
638
+ assert.ok(g.upkeep.localSetup.ask.includes('platform-login'), 'judged by the record: not checked here');
639
+ assert.ok(g.upkeep.localSetup.ask.includes('docker'));
640
+ assert.equal(g.upkeep.agent.length, 1, 'not behind: only the local setup');
641
+ const run = g.upkeep.agent[0];
642
+ assert.deepEqual([run.run, run.class, run.ask], ['yad local-setup list --json', 'read', 'never']);
643
+ assert.match(run.why, /docker/);
644
+ assert.ok(RULES.some((r) => r.id === 'local-setup'));
645
+
646
+ // The person said no: it waits no more.
647
+ runLocalSetupSkip(T, { ids: ['docker'], reason: 'not for me' });
648
+ assert.ok(!buildGuide(T, { epic: 'EP-pay' }).upkeep.localSetup.ask.includes('docker'));
649
+
650
+ // Behind as well: the update comes first.
651
+ put(path.join(T, '.sdlc/cli-version.json'), { version: '4.0.0' });
652
+ git(T, ['add', '-A']); git(T, ['commit', '-q', '-m', 'chore: old stamp']);
653
+ const both = buildGuide(T, { epic: 'EP-pay' }).upkeep;
654
+ assert.deepEqual(both.agent.map((x) => x.run), ['yad update --open-pr --json', 'yad local-setup list --json']);
655
+ } finally { [console.log, process.exitCode, process.env.PATH] = saved; fs.rmSync(T, { recursive: true, force: true }); }
656
+ });
657
+
611
658
  // Two clones of one Product with an origin, for the run's own reading of what origin holds.
612
659
  async function twoClones() {
613
660
  const P = tmp();
@@ -737,6 +784,21 @@ test('a repo newer than the yadflow running is refused, never rolled back; a fai
737
784
  assert.match(ran.commits[0].hint, /index\.lock/);
738
785
  assert.notEqual(git(A, ['status', '--porcelain']), '', 'the update is in the working tree');
739
786
  assert.equal(git(A, ['rev-parse', '--abbrev-ref', 'HEAD']), 'main');
787
+ // #508: a person's own ignore rule hides `.claude/`, whose files the repo tracks. git add refuses; the hint
788
+ // names the rule and the way out — never a lock that is not there.
789
+ process.exitCode = 0;
790
+ git(A, ['add', '-A']); git(A, ['commit', '-q', '-m', 'chore: the install, tracked']); git(A, ['push', '-q']);
791
+ const skillFile = git(A, ['ls-files', '.claude/skills']).split('\n').find((f) => f.endsWith('/SKILL.md'));
792
+ assert.ok(skillFile, 'the install tracks a skill');
793
+ fs.appendFileSync(path.join(A, skillFile), '\nedited by hand\n');
794
+ const excludes = path.join(P, 'gitignore_global');
795
+ fs.writeFileSync(excludes, '# mine\n.claude/\n');
796
+ git(A, ['config', 'core.excludesFile', excludes]);
797
+ const hidden = await reconcile(A, { fix: true, scope: 'changed', openPr: true, creator });
798
+ assert.deepEqual(hidden.commits.map((c) => [c.reason, c.committed]), [['add-failed', false]]);
799
+ assert.match(hidden.commits[0].hint, /^git would not stage the update's files under \.claude in \.: an ignore rule hides that folder — .*gitignore_global:2 \(`\.claude\/`\), a rule outside this repo, which CI and the rest of the team do not have\. Remove or narrow that rule, or add `!\/\.claude\/` to this repo's \.gitignore; then run this again: .* \(git said: .+\)$/);
800
+ assert.doesNotMatch(hidden.commits[0].hint, /index\.lock/);
801
+ assert.equal(git(A, ['diff', '--cached', '--name-only']), '', 'nothing left staged');
740
802
  } finally { fs.rmSync(P, { recursive: true, force: true }); process.exitCode = 0; }
741
803
  });
742
804
 
@@ -882,6 +944,186 @@ test('AGENTS.md with the team\'s own uncommitted edits never rides the update: s
882
944
  } finally { fs.rmSync(P, { recursive: true, force: true }); process.exitCode = 0; }
883
945
  });
884
946
 
947
+ // #555: a shared file the repo's own .gitignore keeps out of git can never ride a PR/MR, so it gets no row.
948
+ for (const [label, rule] of [['the file', '.claude/settings.json'], ['its folder', '.claude/']]) {
949
+ test(`#555: hook settings the Product gitignores (a rule on ${label}) get no row, and stay as they are`, async () => {
950
+ const { reconcile } = await import('./reconcile.mjs');
951
+ const { P, R, A } = await twoClones();
952
+ try {
953
+ const creator = () => ({ ok: true, url: 'https://github.com/acme/product/pull/10' });
954
+ put(path.join(A, '.gitignore'), `${rule}\n`);
955
+ git(A, ['add', '.gitignore']); git(A, ['commit', '-q', '-m', 'chore: ignore']); git(A, ['push', '-q']);
956
+ put(path.join(A, '.claude/settings.json'), { permissions: { allow: ['Bash(ls)'] } });
957
+ const r = await reconcile(A, { fix: true, scope: 'changed', openPr: true, creator });
958
+ assert.ok(!r.commits.some((c) => c.reason === 'settings-uncommitted'), JSON.stringify(r.commits));
959
+ assert.ok(r.commits.some((c) => c.opened), JSON.stringify(r.commits));
960
+ const files = git(R, ['diff', '--name-only', 'main', `chore/yad-update-v${(await import('./manifest.mjs')).VERSION}`]).split('\n');
961
+ assert.ok(!files.includes('.claude/settings.json'), files.join(', '));
962
+ assert.match(fs.readFileSync(path.join(A, '.claude/settings.json'), 'utf8'), /Bash\(ls\)/, 'their entry is still there');
963
+ } finally { fs.rmSync(P, { recursive: true, force: true }); process.exitCode = 0; }
964
+ });
965
+ }
966
+
967
+ test('#555: hook settings hidden by a rule only this machine has keep the row, naming the rule and git add -f', async () => {
968
+ const { reconcile } = await import('./reconcile.mjs');
969
+ const { P, A } = await twoClones();
970
+ try {
971
+ const creator = () => ({ ok: true, url: 'https://github.com/acme/product/pull/11' });
972
+ put(path.join(A, '.git/info/exclude'), '.claude/settings.json\n');
973
+ put(path.join(A, '.claude/settings.json'), { permissions: { allow: ['Bash(ls)'] } });
974
+ const r = await reconcile(A, { fix: true, scope: 'changed', openPr: true, creator });
975
+ const row = r.commits.find((c) => c.reason === 'settings-uncommitted');
976
+ assert.ok(row, JSON.stringify(r.commits));
977
+ assert.match(row.hint, /an ignore rule only this machine has \(\.git\/info\/exclude:1, `\.claude\/settings\.json`\) hides \.claude\/settings\.json/);
978
+ assert.match(row.hint, /git add -f \.claude\/settings\.json/);
979
+ } finally { fs.rmSync(P, { recursive: true, force: true }); process.exitCode = 0; }
980
+ });
981
+
982
+ // The settings file is yad's alone (this run writes it from nothing): a committed rule still gets no row, and a
983
+ // rule only this machine has gets the row — staging would otherwise drop it without a word (review 1).
984
+ test('#555: settings this run creates, hidden by a committed .gitignore: no row, the PR/MR opens', async () => {
985
+ const { reconcile } = await import('./reconcile.mjs');
986
+ const { P, A } = await twoClones();
987
+ try {
988
+ const creator = () => ({ ok: true, url: 'https://github.com/acme/product/pull/13' });
989
+ put(path.join(A, '.gitignore'), '.claude/settings.json\n');
990
+ git(A, ['add', '.gitignore']); git(A, ['commit', '-q', '-m', 'chore: ignore']); git(A, ['push', '-q']);
991
+ assert.ok(!fs.existsSync(path.join(A, '.claude/settings.json')));
992
+ const r = await reconcile(A, { fix: true, scope: 'changed', openPr: true, creator });
993
+ assert.ok(!r.commits.some((c) => c.reason === 'settings-uncommitted'), JSON.stringify(r.commits));
994
+ assert.ok(r.commits.some((c) => c.opened), JSON.stringify(r.commits));
995
+ assert.ok(fs.existsSync(path.join(A, '.claude/settings.json')), 'written on this machine');
996
+ } finally { fs.rmSync(P, { recursive: true, force: true }); process.exitCode = 0; }
997
+ });
998
+
999
+ for (const [label, hide, source] of [
1000
+ ['.git/info/exclude', (A) => put(path.join(A, '.git/info/exclude'), '.claude/settings.json\n'), /\.git\/info\/exclude:1/],
1001
+ ['a global ignore file', (A, P) => { put(path.join(P, 'global-ignore'), '.claude/\n'); git(A, ['config', 'core.excludesFile', path.join(P, 'global-ignore')]); }, /global-ignore:1, `\.claude\/`\)/],
1002
+ ['a .gitignore line not committed', (A) => put(path.join(A, '.gitignore'), '.claude/settings.json\n'), /\(\.gitignore:1, `\.claude\/settings\.json`, not committed\)/],
1003
+ ]) {
1004
+ test(`#555: settings this run creates, hidden by ${label}: the row names the rule and git add -f`, async () => {
1005
+ const { reconcile } = await import('./reconcile.mjs');
1006
+ const { P, A } = await twoClones();
1007
+ try {
1008
+ const creator = () => ({ ok: true, url: 'https://github.com/acme/product/pull/14' });
1009
+ hide(A, P);
1010
+ const r = await reconcile(A, { fix: true, scope: 'changed', openPr: true, creator });
1011
+ const row = r.commits.find((c) => c.reason === 'settings-uncommitted');
1012
+ assert.ok(row, JSON.stringify(r.commits));
1013
+ assert.match(row.hint, source);
1014
+ assert.match(row.hint, /hides \.claude\/settings\.json, so the update left its entries \(hooks, the read-only allow list\) out of the PR\/MR/);
1015
+ assert.match(row.hint, /git add -f \.claude\/settings\.json/);
1016
+ } finally { fs.rmSync(P, { recursive: true, force: true }); process.exitCode = 0; }
1017
+ });
1018
+ }
1019
+
1020
+ // The team's rule is a line the committed ignore file holds (review 2): an unrelated edit not yet committed, or
1021
+ // the line moved, keeps it the team's; the line added but not committed is this machine's.
1022
+ test('#555: a committed .gitignore rule stays the team\'s beside an unrelated edit not yet committed', async () => {
1023
+ const { reconcile } = await import('./reconcile.mjs');
1024
+ const { P, A } = await twoClones();
1025
+ try {
1026
+ const creator = () => ({ ok: true, url: 'https://github.com/acme/product/pull/16' });
1027
+ put(path.join(A, '.gitignore'), 'node_modules/\n.claude/settings.json\n');
1028
+ git(A, ['add', '.gitignore']); git(A, ['commit', '-q', '-m', 'chore: ignore']); git(A, ['push', '-q']);
1029
+ put(path.join(A, '.gitignore'), '.env.local\nnode_modules/\n.claude/settings.json\n');
1030
+ put(path.join(A, '.claude/settings.json'), { permissions: { allow: ['Bash(ls)'] } });
1031
+ const r = await reconcile(A, { fix: true, scope: 'changed', openPr: true, creator });
1032
+ assert.ok(!r.commits.some((c) => c.reason === 'settings-uncommitted'), JSON.stringify(r.commits));
1033
+ assert.ok(r.commits.some((c) => c.opened), JSON.stringify(r.commits));
1034
+ } finally { fs.rmSync(P, { recursive: true, force: true }); process.exitCode = 0; }
1035
+ });
1036
+
1037
+ test('#555: a committed .gitignore with a byte-order mark and Windows line endings still holds the team\'s rule', async () => {
1038
+ const { reconcile } = await import('./reconcile.mjs');
1039
+ const { P, A } = await twoClones();
1040
+ try {
1041
+ const creator = () => ({ ok: true, url: 'https://github.com/acme/product/pull/18' });
1042
+ put(path.join(A, '.gitignore'), '\uFEFF.claude/settings.json \r\nnode_modules/\r\n');
1043
+ git(A, ['add', '.gitignore']); git(A, ['commit', '-q', '-m', 'chore: ignore']); git(A, ['push', '-q']);
1044
+ put(path.join(A, '.claude/settings.json'), { permissions: { allow: ['Bash(ls)'] } });
1045
+ const r = await reconcile(A, { fix: true, scope: 'changed', openPr: true, creator });
1046
+ assert.ok(!r.commits.some((c) => c.reason === 'settings-uncommitted'), JSON.stringify(r.commits));
1047
+ assert.ok(r.commits.some((c) => c.opened), JSON.stringify(r.commits));
1048
+ } finally { fs.rmSync(P, { recursive: true, force: true }); process.exitCode = 0; }
1049
+ });
1050
+
1051
+ test('#555: a rule line added to a committed .gitignore but not committed is this machine\'s: the row stays', async () => {
1052
+ const { reconcile } = await import('./reconcile.mjs');
1053
+ const { P, A } = await twoClones();
1054
+ try {
1055
+ const creator = () => ({ ok: true, url: 'https://github.com/acme/product/pull/17' });
1056
+ put(path.join(A, '.gitignore'), 'node_modules/\n');
1057
+ git(A, ['add', '.gitignore']); git(A, ['commit', '-q', '-m', 'chore: ignore']); git(A, ['push', '-q']);
1058
+ put(path.join(A, '.gitignore'), 'node_modules/\n.claude/settings.json\n');
1059
+ put(path.join(A, '.claude/settings.json'), { permissions: { allow: ['Bash(ls)'] } });
1060
+ const r = await reconcile(A, { fix: true, scope: 'changed', openPr: true, creator });
1061
+ const row = r.commits.find((c) => c.reason === 'settings-uncommitted');
1062
+ assert.ok(row, JSON.stringify(r.commits));
1063
+ assert.match(row.hint, /\(\.gitignore:2, `\.claude\/settings\.json`, not committed\)/);
1064
+ } finally { fs.rmSync(P, { recursive: true, force: true }); process.exitCode = 0; }
1065
+ });
1066
+
1067
+ test('#555: the local setup file\'s row names its own steps, never the hook entries', async () => {
1068
+ const { reconcile } = await import('./reconcile.mjs');
1069
+ const { P, A } = await twoClones();
1070
+ try {
1071
+ const creator = () => ({ ok: true, url: 'https://github.com/acme/product/pull/15' });
1072
+ put(path.join(A, '.git/info/exclude'), '.sdlc/local-setup.json\n');
1073
+ const r = await reconcile(A, { fix: true, scope: 'changed', openPr: true, creator });
1074
+ const row = r.commits.find((c) => /local-setup\.json/.test(c.hint ?? ''));
1075
+ assert.ok(row, JSON.stringify(r.commits));
1076
+ assert.match(row.hint, /left its yadflow steps out of the PR\/MR/);
1077
+ } finally { fs.rmSync(P, { recursive: true, force: true }); process.exitCode = 0; }
1078
+ });
1079
+
1080
+ test('#555: an AGENTS.md the Product gitignores gets no agents-uncommitted row either', async () => {
1081
+ const { reconcile } = await import('./reconcile.mjs');
1082
+ const { P, R, A } = await twoClones();
1083
+ try {
1084
+ const creator = () => ({ ok: true, url: 'https://github.com/acme/product/pull/12' });
1085
+ put(path.join(A, '.gitignore'), 'AGENTS.md\n');
1086
+ git(A, ['add', '.gitignore']); git(A, ['commit', '-q', '-m', 'chore: ignore']); git(A, ['push', '-q']);
1087
+ put(path.join(A, 'AGENTS.md'), '# My own rules\n');
1088
+ const r = await reconcile(A, { fix: true, scope: 'changed', openPr: true, creator });
1089
+ assert.ok(!r.commits.some((c) => c.reason === 'agents-uncommitted'), JSON.stringify(r.commits));
1090
+ const files = git(R, ['diff', '--name-only', 'main', `chore/yad-update-v${(await import('./manifest.mjs')).VERSION}`]).split('\n');
1091
+ assert.ok(!files.includes('AGENTS.md'), files.join(', '));
1092
+ assert.match(fs.readFileSync(path.join(A, 'AGENTS.md'), 'utf8'), /# My own rules/, 'their text is still there');
1093
+ } finally { fs.rmSync(P, { recursive: true, force: true }); process.exitCode = 0; }
1094
+ });
1095
+
1096
+ test('#555: ignoreFileLines reads an ignore file\'s lines as git does', async () => {
1097
+ const { ignoreFileLines } = await import('./update-commit.mjs');
1098
+ const cases = [
1099
+ ['a ', 'a'], ['a\t', 'a\t'], ['a\\ ', 'a\\ '], ['a\\ ', 'a\\ '], ['a\\\\ ', 'a\\\\'],
1100
+ ['\\\\ ', '\\\\'], ['\\ ', '\\ '], [' ', ''], ['a\r', 'a'], ['a \r', 'a'],
1101
+ ['\\\\\\ ', '\\\\\\ '], ['a\\ \r', 'a\\ '],
1102
+ ];
1103
+ for (const [line, want] of cases) assert.deepEqual(ignoreFileLines(line), [want], JSON.stringify(line));
1104
+ assert.deepEqual(ignoreFileLines('\uFEFFx\r\ny\n'), ['x', 'y', '']);
1105
+ assert.deepEqual(ignoreFileLines('x\uFEFF'), ['x\uFEFF'], 'a mark only counts at the start');
1106
+ });
1107
+
1108
+ test('#555: ignoreRules names a file rule and a folder rule, says whose rule it is, and never counts a negation', async () => {
1109
+ const { ignoreRules } = await import('./update-commit.mjs');
1110
+ const P = tmp();
1111
+ try {
1112
+ git(P, ['init', '-q', '-b', 'main']);
1113
+ git(P, ['config', 'core.excludesFile', NO_GLOBAL_IGNORE]);
1114
+ put(path.join(P, '.gitignore'), 'secret.txt\nbuild/\n*.log\n!keep.log\n');
1115
+ put(path.join(P, '.git/info/exclude'), 'mine.md\n');
1116
+ for (const f of ['secret.txt', 'build/out.js', 'keep.log', 'mine.md', 'plain.md']) put(path.join(P, f), 'x');
1117
+ const got = ignoreRules(P, ['secret.txt', 'build/out.js', 'keep.log', 'mine.md', 'plain.md']);
1118
+ assert.deepEqual(got.get('secret.txt'), { source: '.gitignore', line: 1, pattern: 'secret.txt', outside: false });
1119
+ assert.deepEqual(got.get('build/out.js'), { source: '.gitignore', line: 2, pattern: 'build/', outside: false });
1120
+ assert.equal(got.get('mine.md').outside, true);
1121
+ assert.equal(got.get('mine.md').source, '.git/info/exclude');
1122
+ assert.ok(!got.has('keep.log') && !got.has('plain.md'), [...got.keys()].join(', '));
1123
+ assert.equal(ignoreRules(P, []).size, 0);
1124
+ } finally { fs.rmSync(P, { recursive: true, force: true }); }
1125
+ });
1126
+
885
1127
  test('a code repo yad never wired: its own AGENTS.md is left alone by update --open-pr, with no row', async () => {
886
1128
  const { reconcile } = await import('./reconcile.mjs');
887
1129
  const P = tmp();
@@ -1110,6 +1352,118 @@ test('yad update --open-pr: the update on its own branch, pushed, a PR/MR opened
1110
1352
  } finally { fs.rmSync(T, { recursive: true, force: true }); fs.rmSync(R, { recursive: true, force: true }); }
1111
1353
  });
1112
1354
 
1355
+ test('#509: yad update --open-pr with glab warning about two config files says the real reason the MR did not open', { skip: process.platform === 'win32' }, async () => {
1356
+ const { openUpdatePr } = await import('./update-commit.mjs');
1357
+ const { createPr } = await import('./platform.mjs');
1358
+ const T = tmp();
1359
+ const R = tmp();
1360
+ const bin = tmp();
1361
+ fs.writeFileSync(path.join(bin, 'glab'), [
1362
+ '#!/bin/sh',
1363
+ "echo 'Warning: Multiple config files found. Only the first one will be used.' >&2",
1364
+ "echo ' Using: /home/me/.config/glab-cli/config.yml' >&2",
1365
+ "echo ' Ignoring: /home/me/Library/Application Support/glab-cli/config.yml' >&2",
1366
+ "echo 'Consider consolidating to one location to avoid confusion.' >&2",
1367
+ "echo '401 Unauthorized' >&2",
1368
+ 'exit 1',
1369
+ ].join('\n') + '\n', { mode: 0o755 });
1370
+ const before = process.env.PATH;
1371
+ try {
1372
+ git(R, ['init', '-q', '--bare', '-b', 'main']);
1373
+ git(T, ['init', '-q', '-b', 'main']);
1374
+ git(T, ['config', 'user.name', 'Alice Smith']);
1375
+ git(T, ['config', 'user.email', 'alice@work.com']);
1376
+ git(T, ['config', 'commit.gpgsign', 'false']); git(T, ['config', 'core.excludesFile', NO_GLOBAL_IGNORE]);
1377
+ put(path.join(T, '.sdlc/cli-version.json'), { version: '4.0.0' });
1378
+ git(T, ['add', '.sdlc/cli-version.json']);
1379
+ git(T, ['commit', '-q', '-m', 'chore: start']);
1380
+ git(T, ['remote', 'add', 'origin', R]);
1381
+ git(T, ['push', '-q', '-u', 'origin', 'main']);
1382
+ put(path.join(T, '.sdlc/cli-version.json'), { version: '4.7.0' });
1383
+ process.env.PATH = `${bin}${path.delimiter}${before}`;
1384
+ const r = openUpdatePr({ root: T, paths: ['.sdlc/cli-version.json'], items: [] }, { productRoot: T, defaultBranch: 'main', platform: 'gitlab', creator: createPr, version: '4.7.0', checked: true });
1385
+ assert.deepEqual([r.pushed, r.opened, r.reason], [true, false, 'pr-not-opened']);
1386
+ assert.match(r.hint, /did not open \(glab reads only one of its two config files, so a login saved in the other is not used \(see `yad doctor`, glab-config\) — 401 Unauthorized\)/);
1387
+ assert.doesNotMatch(r.hint, /Multiple config files/);
1388
+ } finally {
1389
+ process.env.PATH = before;
1390
+ for (const d of [T, R, bin]) fs.rmSync(d, { recursive: true, force: true });
1391
+ }
1392
+ });
1393
+
1394
+ // #526: glab as git's login helper prints its two-config-files warning on every git push, and git passes it
1395
+ // through. A `pre-push` hook's stderr reaches yad the same way, so it stands in for the helper here.
1396
+ // A push runs the helper more than once (`get`, then `store` or `erase`), and glab warns each time: two blocks.
1397
+ const GLAB_BLOCK = [
1398
+ "echo 'Warning: Multiple config files found. Only the first one will be used.' >&2",
1399
+ "echo ' Using: /home/me/.config/glab-cli/config.yml' >&2",
1400
+ "echo ' Ignoring: /home/me/Library/Application Support/glab-cli/config.yml' >&2",
1401
+ "echo 'Consider consolidating to one location to avoid confusion.' >&2",
1402
+ ];
1403
+ const GLAB_WARNING_HOOK = (exit) => [
1404
+ '#!/bin/sh',
1405
+ ...GLAB_BLOCK,
1406
+ ...GLAB_BLOCK,
1407
+ ...(exit ? ["echo 'remote: HTTP Basic: Access denied' >&2"] : []),
1408
+ `exit ${exit}`,
1409
+ ].join('\n') + '\n';
1410
+ function repoWithPushHook(exit) {
1411
+ const T = tmp();
1412
+ const R = tmp();
1413
+ const hooks = tmp();
1414
+ git(R, ['init', '-q', '--bare', '-b', 'main']);
1415
+ git(T, ['init', '-q', '-b', 'main']);
1416
+ git(T, ['config', 'user.name', 'Alice Smith']);
1417
+ git(T, ['config', 'user.email', 'alice@work.com']);
1418
+ git(T, ['config', 'commit.gpgsign', 'false']); git(T, ['config', 'core.excludesFile', NO_GLOBAL_IGNORE]);
1419
+ put(path.join(T, '.sdlc/cli-version.json'), { version: '4.0.0' });
1420
+ git(T, ['add', '.sdlc/cli-version.json']);
1421
+ git(T, ['commit', '-q', '-m', 'chore: start']);
1422
+ git(T, ['remote', 'add', 'origin', R]);
1423
+ git(T, ['push', '-q', '-u', 'origin', 'main']);
1424
+ fs.writeFileSync(path.join(hooks, 'pre-push'), GLAB_WARNING_HOOK(exit), { mode: 0o755 });
1425
+ git(T, ['config', 'core.hooksPath', hooks]);
1426
+ return { T, dirs: [T, R, hooks] };
1427
+ }
1428
+
1429
+ test('#526: a git push that glab, as git\'s login helper, warns on reads the real error first, and a push that works drops the warning', { skip: process.platform === 'win32' }, async () => {
1430
+ const { run } = await import('./lib.mjs');
1431
+ for (const exit of [1, 0]) {
1432
+ const { T, dirs } = repoWithPushHook(exit);
1433
+ try {
1434
+ git(T, ['commit', '-q', '--allow-empty', '-m', 'chore: more']);
1435
+ const r = run('git', ['push', '-q', 'origin', 'main'], { cwd: T });
1436
+ assert.equal(r.ok, exit === 0);
1437
+ assert.doesNotMatch(r.stderr, /Multiple config files|Consider consolidating|Ignoring:/);
1438
+ if (exit) assert.equal(r.stderr.split('\n')[0], 'glab reads only one of its two config files, so a login saved in the other is not used (see `yad doctor`, glab-config) — remote: HTTP Basic: Access denied');
1439
+ else assert.equal(r.stderr, '');
1440
+ } finally { for (const d of dirs) fs.rmSync(d, { recursive: true, force: true }); }
1441
+ }
1442
+ });
1443
+
1444
+ test('#526: yad update --open-pr says the real reason a push failed, not glab\'s warning', { skip: process.platform === 'win32' }, async () => {
1445
+ const { openUpdatePr } = await import('./update-commit.mjs');
1446
+ const { T, dirs } = repoWithPushHook(1);
1447
+ const said = [];
1448
+ const { log: l, error: e } = console;
1449
+ const code = process.exitCode;
1450
+ try {
1451
+ put(path.join(T, '.sdlc/cli-version.json'), { version: '4.7.0' });
1452
+ console.log = (...a) => said.push(a.join(' '));
1453
+ console.error = (...a) => said.push(a.join(' '));
1454
+ const r = openUpdatePr({ root: T, paths: ['.sdlc/cli-version.json'], items: [] }, { productRoot: T, defaultBranch: 'main', platform: 'gitlab', creator: () => ({ ok: true }), version: '4.7.0', checked: true });
1455
+ console.log = l; console.error = e;
1456
+ assert.equal(r.reason, 'push-failed');
1457
+ const line = said.find((x) => /could not push/.test(x));
1458
+ assert.match(line, /could not push \S+ — glab reads only one of its two config files, .* — remote: HTTP Basic: Access denied/);
1459
+ assert.doesNotMatch(said.join('\n'), /Multiple config files/);
1460
+ } finally {
1461
+ console.log = l; console.error = e;
1462
+ process.exitCode = code;
1463
+ for (const d of dirs) fs.rmSync(d, { recursive: true, force: true });
1464
+ }
1465
+ });
1466
+
1113
1467
  test('yad update refuses --push and --open-pr together; --open-pr is the agent\'s without asking', async () => {
1114
1468
  assert.equal(classify(['update'], ['open-pr']), 'open-pr');
1115
1469
  assert.equal(askFor(classify(['update'], ['open-pr'])), 'never');
@@ -1272,3 +1626,87 @@ test('E167 (#353): yad guide --json hands agents what the agent guard pre-approv
1272
1626
  assert.deepEqual(g.preapproved, PREAPPROVED);
1273
1627
  assert.match(g.preapproved.never, /secrets, tokens/);
1274
1628
  });
1629
+
1630
+ // #508 review 1: git refuses a tracked file only over an ignored FOLDER above it — so only folders are named.
1631
+ // A rule on the file itself, a negation, and a repo rule are told apart; `.git/info/exclude` is this clone's.
1632
+ test('#508: hiddenFolders names the ignored folder above a kept path, never a file rule or a negation', async () => {
1633
+ const { hiddenFolders, hiddenFolderText } = await import('./update-commit.mjs');
1634
+ const P = tmp();
1635
+ try {
1636
+ const A = path.join(P, 'a');
1637
+ fs.mkdirSync(A);
1638
+ git(A, ['init', '-q', '-b', 'main']);
1639
+ const excludes = path.join(P, 'mine');
1640
+ fs.writeFileSync(excludes, 'CLAUDE.md\n.claude/skills/\n');
1641
+ git(A, ['config', 'core.excludesFile', excludes]);
1642
+ put(path.join(A, '.gitignore'), '!.claude/settings.json\n');
1643
+ for (const f of ['CLAUDE.md', '.claude/settings.json', '.claude/skills/x/SKILL.md', 'keep.md']) put(path.join(A, f), 'x\n');
1644
+ const got = hiddenFolders(A, ['CLAUDE.md', '.claude/settings.json', '.claude/skills/x/SKILL.md', 'keep.md']);
1645
+ assert.deepEqual(got.map((x) => [x.folder, x.paths, x.pattern, x.line, x.outside]), [['.claude/skills', ['.claude/skills/x/SKILL.md'], '.claude/skills/', 2, true]],
1646
+ 'no CLAUDE.md (a file rule never stops git add), no settings.json (a negation re-includes it)');
1647
+ // A rule in .git/info/exclude is this clone's alone: outside, like a global one.
1648
+ fs.writeFileSync(excludes, '');
1649
+ fs.appendFileSync(path.join(A, '.git/info/exclude'), 'vendor/\n');
1650
+ put(path.join(A, 'vendor/lib/a.js'), 'x\n');
1651
+ const local = hiddenFolders(A, ['vendor/lib/a.js']);
1652
+ assert.deepEqual(local.map((x) => [x.folder, x.source, x.outside]), [['vendor', '.git/info/exclude', true]]);
1653
+ // The repo's own rule is not "outside", and no `!` way out is offered for it.
1654
+ put(path.join(A, '.gitignore'), 'build/\n');
1655
+ put(path.join(A, 'build/out.txt'), 'x\n');
1656
+ const own = hiddenFolders(A, ['build/out.txt']);
1657
+ assert.deepEqual(own.map((x) => [x.folder, x.source, x.outside]), [['build', '.gitignore', false]]);
1658
+ assert.doesNotMatch(hiddenFolderText(own, '.', { staged: false }), /outside this repo|add `!/);
1659
+ // The plain push path: git staged the tracked files; only a new file there is left out.
1660
+ const pushed = hiddenFolderText(local, 'api', { staged: true });
1661
+ assert.match(pushed, /^an ignore rule hides vendor in api — \.git\/info\/exclude:\d+ \(`vendor\/`\), a rule outside this repo, which CI and the rest of the team do not have\. Its tracked files were staged, but a new file there is left out of the update: remove or narrow that rule, or add `!\/vendor\/` to this repo's \.gitignore$/);
1662
+ assert.doesNotMatch(pushed, /would not stage|next run/);
1663
+ // Review 2: a folder on disk is asked by its name — a repo `.claude/*` hides the files in `.claude`, not the
1664
+ // folder, so a kept `.claude/settings.json` names nothing; and a deletion names nothing either.
1665
+ put(path.join(A, '.gitignore'), '.claude/*\n!.claude/settings.json\n');
1666
+ assert.deepEqual(hiddenFolders(A, ['.claude/settings.json']), []);
1667
+ // A deletion in an ignored folder still on disk: git stages it but still exits 1, so the folder is named
1668
+ // (review 3). A folder that is gone is never refused, so it is never named — not `.claude` read as matching
1669
+ // `.claude/*`, not `old` beside a real refusal (review 4).
1670
+ assert.deepEqual(hiddenFolders(A, ['vendor/gone.js']).map((x) => x.folder), ['vendor']);
1671
+ put(path.join(A, '.gitignore'), '.claude/*\nold/\n');
1672
+ fs.rmSync(path.join(A, '.claude'), { recursive: true, force: true });
1673
+ assert.deepEqual(hiddenFolders(A, ['.claude/settings.json', 'old/a.md', 'vendor/lib/a.js']).map((x) => x.folder), ['vendor']);
1674
+ // A folder named with glob characters is suggested escaped, so the pattern matches it alone.
1675
+ assert.match(hiddenFolderText([{ folder: 'we ird[1]*', paths: ['we ird[1]*/a'], source: '~/mine', line: 1, pattern: 'x', outside: true }], '.', { staged: false }), /add `!\/we ird\\\[1\\\]\\\*\/` to this repo/);
1676
+ } finally { fs.rmSync(P, { recursive: true, force: true }); }
1677
+ });
1678
+
1679
+ // #508 review 2: a fatal `git add` (exit 128 — a file git cannot read) is said in git's words, even beside an
1680
+ // ignored folder: then nothing was staged, and the rule is not why. Root reads any file, so it is skipped there.
1681
+ test('#508: a git add that fails fatally beside an ignored folder names no ignore rule', { skip: (process.platform === 'win32' || process.getuid?.() === 0) && 'needs a file the user cannot read' }, async () => {
1682
+ const { stageAllowlist } = await import('./update-commit.mjs');
1683
+ const P = tmp();
1684
+ const A = path.join(P, 'a');
1685
+ try {
1686
+ fs.mkdirSync(A);
1687
+ git(A, ['init', '-q', '-b', 'main']);
1688
+ git(A, ['config', 'user.name', 'Alice Smith']); git(A, ['config', 'user.email', 'alice@work.com']); git(A, ['config', 'commit.gpgsign', 'false']);
1689
+ git(A, ['config', 'core.excludesFile', NO_GLOBAL_IGNORE]);
1690
+ put(path.join(A, '.claude/skills/x/SKILL.md'), 'x\n');
1691
+ put(path.join(A, 'keep.md'), 'k\n');
1692
+ git(A, ['add', '-A']); git(A, ['commit', '-q', '-m', 'start']);
1693
+ const excludes = path.join(P, 'mine');
1694
+ fs.writeFileSync(excludes, '.claude/skills/\n');
1695
+ git(A, ['config', 'core.excludesFile', excludes]);
1696
+ fs.appendFileSync(path.join(A, '.claude/skills/x/SKILL.md'), 'y\n');
1697
+ fs.appendFileSync(path.join(A, 'keep.md'), 'y\n');
1698
+ // An ignored folder alone: exit 1, the folder is named.
1699
+ const refused = stageAllowlist(null, A, ['.claude/skills/x/SKILL.md']);
1700
+ assert.deepEqual(refused.ignoredBy.map((x) => x.folder), ['.claude/skills']);
1701
+ git(A, ['reset', '-q']);
1702
+ // Beside a file git cannot read: exit 128, no rule named, git's words kept.
1703
+ fs.chmodSync(path.join(A, 'keep.md'), 0o000);
1704
+ const fatal = stageAllowlist(null, A, ['.claude/skills/x/SKILL.md', 'keep.md']);
1705
+ assert.match(fatal.addError, /Permission denied|keep\.md/);
1706
+ assert.deepEqual(fatal.ignoredBy, []);
1707
+ } finally {
1708
+ try { fs.chmodSync(path.join(A, 'keep.md'), 0o644); } catch { /* gone */ }
1709
+ fs.rmSync(P, { recursive: true, force: true });
1710
+ }
1711
+ });
1712
+