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
package/cli/members.mjs CHANGED
@@ -42,11 +42,12 @@ import os from 'node:os';
42
42
  import path from 'node:path';
43
43
  import { createHash } from 'node:crypto';
44
44
  import { spawnSync } from 'node:child_process';
45
+ import { readBlobsAt } from './git-read.mjs';
45
46
 
46
47
  import { c, log, ok, info, warn, fail, hand, run, readJSON, forTerminal, isPlainObject, asset, inJSON, refuse as refuseJSON } from './lib.mjs';
47
48
  import { productConfigPath, isVerifiedLedger, SCHEMA_VERSION } from './manifest.mjs';
48
49
  import { LOGIN_RE, hostFromGitUrl, plainHost } from './platform.mjs';
49
- import { repoPathFromGitUrl, httpStatus } from './protection.mjs';
50
+ import { repoPathFromGitUrl, configuredGitUrl, httpStatus } from './protection.mjs';
50
51
  import { readRegistry, judgeRepo, runnable } from './workspace.mjs';
51
52
  import { resolveDefaultBranch } from './productcommit.mjs';
52
53
 
@@ -83,8 +84,10 @@ export const accountLabel = (a) => `${a.platform === 'github' ? 'GitHub' : 'GitL
83
84
  // clone's `origin`. `platform` is null on a Product with no platform: then nothing can be proven.
84
85
  export function productIdentity(root, { runner = run, productConfig = readJSON(productConfigPath(root), null) } = {}) {
85
86
  const platform = PLATFORMS.includes(productConfig?.platform) ? productConfig.platform : null;
86
- let url = typeof productConfig?.git_url === 'string' ? productConfig.git_url : '';
87
- if (!url) url = runner('git', ['remote', 'get-url', 'origin'], { cwd: root }).stdout || '';
87
+ // A git_url that names only a host is no repo: its repo path comes from origin then, and the host stays
88
+ // the settings' — the order the CI member check reads it in (#513, review 1).
89
+ const set = typeof productConfig?.git_url === 'string' ? productConfig.git_url : '';
90
+ const url = configuredGitUrl(set, () => runner('git', ['remote', 'get-url', 'origin'], { cwd: root }).stdout) || set;
88
91
  const host = plainHost(hostFromGitUrl(url)) || (platform ? DEFAULT_HOST[platform] : null);
89
92
  return { platform, host, repo: repoPathFromGitUrl(url), defaultBranch: typeof productConfig?.default_branch === 'string' ? productConfig.default_branch : null, verified: isVerifiedLedger(productConfig) };
90
93
  }
@@ -265,20 +268,11 @@ export function judgedMemberFiles(root, identity) {
265
268
  // Each candidate must be on disk byte for byte as origin holds it (review 5): an untracked copy, or an edit
266
269
  // git was told to ignore (`--assume-unchanged`), is not what the gate judged. One git run for them all.
267
270
  const cands = [...new Set(changed.out.split('\n').filter(Boolean))];
268
- const batch = spawnSync('git', ['cat-file', '--batch'], { cwd: root, input: cands.map((f) => `${base}:./${f}\n`).join(''), maxBuffer: 1 << 28 });
269
- const out = batch.status === 0 ? batch.stdout : Buffer.alloc(0);
271
+ const blobs = readBlobsAt(root, cands.map((f) => `${base}:./${f}`));
270
272
  const files = new Set();
271
- let at = 0;
272
273
  for (const f of cands) {
273
- const nl = out.indexOf(10, at);
274
- if (nl < 0) break;
275
- const header = out.subarray(at, nl).toString();
276
- at = nl + 1;
277
- const m = header.match(/^[0-9a-f]+ (\w+) (\d+)$/);
278
- if (!m) continue; // `<name> missing`: deleted at origin, and no body follows
279
- const blob = out.subarray(at, at + Number(m[2]));
280
- at += Number(m[2]) + 1; // every body is skipped, whatever its type (review 6)
281
- if (m[1] !== 'blob') continue;
274
+ const blob = blobs.get(`${base}:./${f}`);
275
+ if (!blob) continue; // deleted at origin, or not a file there
282
276
  let disk;
283
277
  try { if (fs.lstatSync(path.join(root, f)).isSymbolicLink()) continue; disk = fs.readFileSync(path.join(root, f)); } catch { continue; }
284
278
  if (sameText(disk.toString('utf8'), blob.toString('utf8'))) files.add(f);
package/cli/next.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  // `yad next` — the unified next-step driver. Read-only: it never writes state or acts. It reads the
2
2
  // file ledger and prints the ONE concrete, copy-pasteable next action (and a one-line why), so a user
3
- // never has to remember which of the 39 skills / gate commands comes next. "Guide, don't act" — the
3
+ // never has to remember which of the 41 skills / gate commands comes next. "Guide, don't act" — the
4
4
  // Shape still never auto-advances. Once an epic is `ready-for-build`, it reads each story's
5
5
  // build-state and prints the next BUILD sub-step per repo (spec → tasks → implement → checks → engineer-review)
6
6
  // plus the remaining chain — so Build is guided too, not just hinted at.
package/cli/openpr.mjs CHANGED
@@ -35,8 +35,8 @@ function resolveRepo(root, { repo, dir, product }) {
35
35
  if (found) return { repoRoot: path.resolve(productRoot, found.path), meta: found };
36
36
  }
37
37
  const here = path.resolve(root, dir || '.');
38
- // The checkout it runs in, when that checkout is a registered repo: worked at its top, from any
39
- // folder inside it. Anything else (a worktree, a nested repo) stays exactly where it is.
38
+ // The checkout it runs in, when that checkout is a registered repo or a git worktree of one (#515): worked
39
+ // at its own top, from any folder inside it. A nested repo stays exactly where it is, with no entry.
40
40
  const hit = registryEntryFor(product, here);
41
41
  return { repoRoot: hit ? hit.top : here, meta: hit ? hit.meta : null };
42
42
  }
@@ -0,0 +1,22 @@
1
+ // Text a person reads and an agent acts on, with nothing hidden in it (E185). Shared by the local setup script and
2
+ // the toolbox's own tools, whose words become setup steps every member's agent reads.
3
+ import { forTerminal } from './lib.mjs';
4
+
5
+ // Every character a reader cannot see: control, format and separator characters (zero-width spaces, soft hyphens,
6
+ // tag characters, direction marks), every space but the plain one, variation selectors (which can carry text an
7
+ // agent reads and a person never sees), the fillers that render blank (Hangul, braille), and half a character
8
+ // pair (a lone surrogate).
9
+ // `Default_Ignorable_Code_Point` names the rest, now and as Unicode adds them (U+034F, U+17B4, …; review 2).
10
+ const INVISIBLE = String.raw`\p{Cf}\p{Zl}\p{Zp}\p{Cs}\p{Default_Ignorable_Code_Point}\u{FE00}-\u{FE0F}\u{E0100}-\u{E01EF}\u115F\u1160\u3164\uFFA0\u2800`;
11
+ export const HIDDEN = new RegExp(String.raw`[\p{Cc}${INVISIBLE}]|(?! )\p{Zs}`, 'u');
12
+ // Prose may wrap: a newline is its one allowed control character.
13
+ const HIDDEN_IN_PROSE = new RegExp(String.raw`[${INVISIBLE}]|[^\P{Cc}\n]|(?! )\p{Zs}`, 'u');
14
+
15
+ export const isText = (v) => typeof v === 'string' && v.trim().length > 0;
16
+ // One plain line: nothing `forTerminal` would change, and nothing hidden.
17
+ export const plainLine = (v) => isText(v) && forTerminal(v) === v && !HIDDEN.test(v);
18
+ // Plain prose: lines of text, nothing hidden.
19
+ export const plainProse = (v) => isText(v) && !HIDDEN_IN_PROSE.test(v);
20
+
21
+ // How long each part of a step may be: a step is read by every member, so it stays readable.
22
+ export const STEP_LIMITS = Object.freeze({ title: 120, text: 600, commands: 10, command: 500 });
package/cli/plan.mjs CHANGED
@@ -10,6 +10,7 @@ import {
10
10
  import {
11
11
  VERSION, SKILLS, IDE_TARGETS, IDE_OPENCODE_DIR, IDE_OPENCODE_TARGET, IDE_RECOVERY_TARGET, MODULE_CONFIG, wiringFor, PRODUCT_WIRING, PROJECT_FILES, isVerifiedLedger,
12
12
  HOOK_WIRING, HOOK_ADAPTERS, CLAUDE_HOOK_ADAPTER, CAPTURE_WIRING, CAPTURE_ADAPTERS, AGENT_GUARD_WIRING, AGENT_GUARD_ADAPTERS, REPO_AGENT_GUARD_DEST, agentGuardAdapters,
13
+ ACTIVITY_WIRING, ACTIVITY_ADAPTERS, REPO_ACTIVITY_DEST, activityAdapters,
13
14
  legacySkillPairs, REMOVED_SKILLS, LEGACY_REPO_FILES, LEGACY_PRODUCT_FILES, LEGACY_HOOK_SCRIPTS, MANAGED_LEDGER, BACKUP_SUFFIX,
14
15
  productConfigPath, PRODUCT_LINK, PRODUCT_LINK_DEFAULT_PATH,
15
16
  } from './manifest.mjs';
@@ -918,6 +919,8 @@ export function repoActions(root, repo) {
918
919
  actions.push(...agentFileActions(repoRoot, ideTargetsFor(root), { scope: repo.name, lines: pointerBlock(), relabel: false }));
919
920
  // E158b: the agent guard and the read-only allow list, so a session opened in the code repo has them too.
920
921
  actions.push(...repoAgentGuardActions(repoRoot, ideTargetsFor(root), { scope: repo.name, ledger }));
922
+ // E178: the live activity record, while the Product says `"activity": true`.
923
+ actions.push(...repoActivityActions(root, repoRoot, ideTargetsFor(root), { scope: repo.name, ledger }));
921
924
  }
922
925
  if (!wired) return actions;
923
926
  // The record is not a template: an absent one on a wired repo is always `new` (nothing to respect).
@@ -1302,15 +1305,17 @@ function blockState(dest, opts) {
1302
1305
  return { raw, state: now.status === 'ok' ? 'ok' : now.status === 'new' ? 'missing' : 'outdated', refused: null, exists: raw !== null };
1303
1306
  }
1304
1307
 
1305
- function markedBlockAction(root, relDest, lines, { scope = 'product' } = {}) {
1308
+ // `markers` is AGENTS_MARKERS unless named: the local setup script's view (LOCAL-SETUP.md, E185) has its own.
1309
+ export function markedBlockAction(root, relDest, lines, { scope = 'product', markers = AGENTS_MARKERS, what = 'the yadflow rules block' } = {}) {
1306
1310
  const dest = path.join(root, relDest);
1307
- const opts = { ...AGENTS_MARKERS, lines };
1308
- const base = { scope, item: relDest, root, paths: [], shared: relDest, kind: 'text', mergeShared: (text) => applyMarkedBlock(text, opts) };
1311
+ const opts = { ...markers, lines };
1312
+ // `what` names the block in the row `yad update --open-pr` gives a file it leaves out ("its yadflow rules block").
1313
+ const base = { scope, item: relDest, root, paths: [], shared: relDest, kind: 'text', what: what.replace(/^the /, 'its '), mergeShared: (text) => applyMarkedBlock(text, opts) };
1309
1314
  const { state, refused } = blockState(dest, opts);
1310
1315
  // Never written, said once at plan time. Markers yad cannot trust are never guessed around: the team's
1311
1316
  // text is left as it is (as a broken config.yaml region is, cli/lifecycle.mjs).
1312
1317
  if (refused) {
1313
- warn(`${scope}/${relDest}: ${refused} — the yadflow rules block was left out; ${state === 'refused' ? 'fix the markers (or delete both to have the block added again)' : 'make it a plain file'}, then re-run \`yad check --fix\``);
1318
+ warn(`${scope}/${relDest}: ${refused} — ${what} was left out; ${state === 'refused' ? 'fix the markers (or delete both to have the block added again)' : 'make it a plain file'}, then re-run \`yad check --fix\``);
1314
1319
  return { ...base, status: 'modified', writesNothing: true, apply: () => {} };
1315
1320
  }
1316
1321
  return {
@@ -1502,18 +1507,27 @@ export const gitHookLine = (prefix = '') => {
1502
1507
  return `[ ! -f ${guard} ] || node ${guard} --staged || [ $? -ne 2 ] || exit 1`;
1503
1508
  };
1504
1509
 
1505
- // Where this clone's pre-commit hook is, and whose it is. `{ applies: false }` when there is nothing to
1506
- // install (a local ledger, or no git). Otherwise `{ applies: true, file, expected, prefix, state }` with
1507
- // `state` one of: 'missing' | 'ok' | 'outdated' (ours, different bytes) | 'foreign' (a hook that is not
1508
- // ours) | 'hooks-path' (core.hooksPath is set). The last two carry `line`, the one to add by hand.
1509
- export function gitHookState(root) {
1510
- if (!isVerifiedLedger(readJSON(productConfigPath(root)))) return { applies: false };
1511
- const where = run('git', ['-C', root, 'rev-parse', '--git-path', 'hooks/pre-commit', '--show-prefix']);
1510
+ // A git hook yad writes into this clone, described once: the pre-commit ledger guard (E48) and the pull notices
1511
+ // (E185) take every rule below the same way. `spec`:
1512
+ // name the hook's file name in git's hooks folder ('pre-commit')
1513
+ // marker the line that makes a copy yad's own
1514
+ // scripts (prefix) → every text yad has written for it, today's first
1515
+ // line (prefix) → the one line a person adds to a hook yad will not touch
1516
+ // applies (root) → whether this Product wants the hook at all
1517
+ // item the action's name in `yad check`
1518
+ // advice (st) → the sentence for a hook yad may not write
1519
+ // Where the hook is, and whose it is. `{ applies: false }` when there is nothing to install (the spec says no,
1520
+ // or no git). Otherwise `{ applies: true, file, expected, prefix, state }` with `state` one of: 'missing' | 'ok'
1521
+ // | 'outdated' (ours, different bytes) | 'foreign' (a hook that is not ours) | 'hooks-path' (core.hooksPath is
1522
+ // set). The last two carry `line`, the one to add by hand.
1523
+ function hookStateFor(spec, root) {
1524
+ if (!spec.applies(root)) return { applies: false };
1525
+ const where = run('git', ['-C', root, 'rev-parse', '--git-path', `hooks/${spec.name}`, '--show-prefix']);
1512
1526
  if (!where.ok) return { applies: false };
1513
1527
  const [hookRel, prefix = ''] = where.stdout.split('\n');
1514
1528
  const file = path.resolve(root, hookRel);
1515
- const expected = gitPreCommitScript(prefix);
1516
- const line = gitHookLine(prefix);
1529
+ const [expected] = spec.scripts(prefix);
1530
+ const line = spec.line(prefix);
1517
1531
  const hooksPath = run('git', ['-C', root, 'config', '--get', 'core.hooksPath']);
1518
1532
  // A core.hooksPath that names the default folder anyway (some tools set it so) is not a tool's folder.
1519
1533
  // `--path-format` needs git 2.31; an older git fails the call, and the setting is then treated as a tool's.
@@ -1527,30 +1541,49 @@ export function gitHookState(root) {
1527
1541
  || (path.basename(hooksDir) === 'hooks' && samePath(path.dirname(hooksDir), common.stdout)));
1528
1542
  if (hooksPath.ok && hooksPath.stdout && !isDefault) {
1529
1543
  // husky points core.hooksPath at `.husky/_`, a folder it generates; the hook a person edits is the one
1530
- // beside it, `.husky/pre-commit`. Name that one, or the advice sends them to a file husky rewrites.
1544
+ // beside it, `.husky/<name>`. Name that one, or the advice sends them to a file husky rewrites.
1531
1545
  const dir = hooksPath.stdout.replace(/[\\/]+$/, '');
1532
- const edit = /(^|[\\/])_$/.test(dir) ? `${dir.replace(/[\\/]?_$/, '') || '.'}/pre-commit` : `${dir}/pre-commit`;
1546
+ const edit = /(^|[\\/])_$/.test(dir) ? `${dir.replace(/[\\/]?_$/, '') || '.'}/${spec.name}` : `${dir}/${spec.name}`;
1547
+ // The hook the person edits there may already hold yad's line (reviews 3, 4). Read where git itself resolved
1548
+ // it (`file`: `~`, relative and absolute settings alike), husky's beside its `_` folder. husky's runner calls
1549
+ // its hook with sh, so its execute bit is husky's business; in any other folder git runs it, and skips one it
1550
+ // cannot run (everywhere but Windows).
1551
+ if (spec.wired) {
1552
+ const husky = /(^|[\\/])_$/.test(dir);
1553
+ const read = husky ? path.join(path.dirname(path.dirname(file)), spec.name) : file;
1554
+ let edited = null;
1555
+ try { edited = fs.readFileSync(read, 'utf8'); } catch { /* none */ }
1556
+ let canRun = true;
1557
+ if (!husky && process.platform !== 'win32') { try { canRun = (fs.statSync(read).mode & 0o111) !== 0; } catch { canRun = false; } }
1558
+ if (edited !== null && canRun && spec.wired(edited, prefix)) return { applies: true, file, expected, prefix, line, hooksPath: hooksPath.stdout, editFile: edit, state: 'hand-wired' };
1559
+ }
1533
1560
  return { applies: true, file, expected, prefix, line, hooksPath: hooksPath.stdout, editFile: edit, state: 'hooks-path' };
1534
1561
  }
1535
1562
  let text = null;
1536
1563
  try { text = fs.readFileSync(file, 'utf8'); } catch { /* absent */ }
1537
1564
  if (text === null) return { applies: true, file, expected, prefix, state: 'missing' };
1538
- if (!text.includes(GIT_HOOK_MARKER)) return { applies: true, file, expected, prefix, line, state: 'foreign' };
1565
+ // A hook of the team's own that already runs ours by the line yad gave (`spec.wired`), and that git can run (its
1566
+ // execute bit, everywhere but Windows): nothing to say (reviews 2, 3).
1567
+ if (!text.includes(spec.marker)) {
1568
+ let canRun = true;
1569
+ if (process.platform !== 'win32') { try { canRun = (fs.statSync(file).mode & 0o111) !== 0; } catch { canRun = false; } }
1570
+ return { applies: true, file, expected, prefix, line, state: canRun && spec.wired?.(text, prefix) ? 'hand-wired' : 'foreign' };
1571
+ }
1539
1572
  // Git silently skips a hook that is not executable (everywhere but Windows), so right bytes without the
1540
1573
  // bit are not an installed hook.
1541
1574
  let runnable = true;
1542
1575
  if (process.platform !== 'win32') { try { runnable = (fs.statSync(file).mode & 0o111) !== 0; } catch { runnable = false; } }
1543
1576
  if (text === expected && runnable) return { applies: true, file, expected, prefix, state: 'ok' };
1544
1577
  // `earlier`: a text an earlier yad wrote, so nothing in it is anyone's edit.
1545
- const why = text === expected ? 'not-executable' : gitPreCommitScripts(prefix).includes(text) ? 'earlier' : 'changed';
1578
+ const why = text === expected ? 'not-executable' : spec.scripts(prefix).includes(text) ? 'earlier' : 'changed';
1546
1579
  return { applies: true, file, expected, prefix, state: 'outdated', why };
1547
1580
  }
1548
1581
 
1549
1582
  // The install action. 'foreign' and 'hooks-path' build no action — there is nothing yad may write —
1550
- // and are reported by `gitHookAdvice` instead.
1551
- export function gitHookActions(root) {
1552
- const st = gitHookState(root);
1553
- if (!st.applies || st.state === 'foreign' || st.state === 'hooks-path') return [];
1583
+ // and are reported by the spec's advice instead.
1584
+ function hookActionsFor(spec, root) {
1585
+ const st = hookStateFor(spec, root);
1586
+ if (!st.applies || st.state === 'foreign' || st.state === 'hooks-path' || st.state === 'hand-wired') return [];
1554
1587
  const status = st.state === 'missing' ? 'new' : st.state;
1555
1588
  // An outdated copy may carry a person's edit below our marker, so it is saved beside itself first —
1556
1589
  // the same rule `wiredFileAction` keeps for content it cannot prove it wrote. Not when only the execute
@@ -1558,7 +1591,7 @@ export function gitHookActions(root) {
1558
1591
  const backup = st.state === 'outdated' && st.why === 'changed' ? backupPathFor(st.file) : null;
1559
1592
  return [{
1560
1593
  scope: 'product',
1561
- item: 'pre-commit git hook (this clone)',
1594
+ item: spec.item,
1562
1595
  status,
1563
1596
  root,
1564
1597
  paths: [],
@@ -1572,27 +1605,146 @@ export function gitHookActions(root) {
1572
1605
  }];
1573
1606
  }
1574
1607
 
1575
- // A local ledger: the hook yad installed while the Product was verified has nothing to guard. Removed
1576
- // only when its bytes are exactly what yad writes — an edited copy is left for its owner.
1577
- export function orphanGitHookActions(root) {
1578
- if (isVerifiedLedger(readJSON(productConfigPath(root)))) return [];
1579
- const where = run('git', ['-C', root, 'rev-parse', '--git-path', 'hooks/pre-commit', '--show-prefix']);
1608
+ // A hook the Product no longer wants (the spec says no): removed only when its bytes are exactly what yad
1609
+ // writes — an edited copy is left for its owner. Only on a Product: elsewhere nothing of yad's was written.
1610
+ function orphanHookActionsFor(spec, root) {
1611
+ if (!exists(productConfigPath(root)) || spec.applies(root)) return [];
1612
+ const where = run('git', ['-C', root, 'rev-parse', '--git-path', `hooks/${spec.name}`, '--show-prefix']);
1580
1613
  if (!where.ok) return [];
1581
1614
  const [hookRel, prefix = ''] = where.stdout.split('\n');
1582
1615
  const file = path.resolve(root, hookRel);
1583
1616
  let text;
1584
1617
  try { text = fs.readFileSync(file, 'utf8'); } catch { return []; }
1585
- if (!gitPreCommitScripts(prefix).includes(text)) return [];
1586
- return [{ scope: 'product', item: 'pre-commit git hook (this clone) (removed)', status: 'removed', root, paths: [], apply: () => fs.rmSync(file, { force: true }) }];
1587
- }
1618
+ if (!spec.scripts(prefix).includes(text)) return [];
1619
+ return [{ scope: 'product', item: `${spec.item} (removed)`, status: 'removed', root, paths: [], apply: () => fs.rmSync(file, { force: true }) }];
1620
+ }
1621
+
1622
+ const PRE_COMMIT_HOOK = Object.freeze({
1623
+ name: 'pre-commit',
1624
+ marker: GIT_HOOK_MARKER,
1625
+ scripts: (prefix) => gitPreCommitScripts(prefix),
1626
+ line: (prefix) => gitHookLine(prefix),
1627
+ applies: (root) => isVerifiedLedger(readJSON(productConfigPath(root))),
1628
+ item: 'pre-commit git hook (this clone)',
1629
+ // A tool that owns the hook (the pre-commit framework, husky v4) may rewrite it on reinstall, which drops
1630
+ // an added line, so the advice says to check after one.
1631
+ advice: (st) => (st?.state === 'hooks-path' ? `git's core.hooksPath is set (${st.hooksPath}), so yad did not install its pre-commit ledger guard; add this line to ${st.editFile}: ${st.line}`
1632
+ : st?.state === 'foreign' ? `${st.file} is not yad's, so yad left it alone; add this line to it to refuse a hand commit to the CI-owned ledger (and again if a tool rewrites the hook): ${st.line}` : null),
1633
+ });
1588
1634
 
1635
+ // The pre-commit hook (E48), as it always was.
1636
+ export const gitHookState = (root) => hookStateFor(PRE_COMMIT_HOOK, root);
1637
+ export const gitHookActions = (root) => hookActionsFor(PRE_COMMIT_HOOK, root);
1638
+ // A local ledger: the hook yad installed while the Product was verified has nothing to guard.
1639
+ export const orphanGitHookActions = (root) => orphanHookActionsFor(PRE_COMMIT_HOOK, root);
1589
1640
  // The sentence for a clone where yad may not write the hook, or null.
1590
- // A tool that owns the hook (the pre-commit framework, husky v4) may rewrite it on reinstall, which drops
1591
- // an added line, so the advice says to check after one.
1592
- export function gitHookAdvice(st) {
1593
- if (st?.state === 'hooks-path') return `git's core.hooksPath is set (${st.hooksPath}), so yad did not install its pre-commit ledger guard; add this line to ${st.editFile}: ${st.line}`;
1594
- if (st?.state === 'foreign') return `${st.file} is not yad's, so yad left it alone; add this line to it to refuse a hand commit to the CI-owned ledger (and again if a tool rewrites the hook): ${st.line}`;
1595
- return null;
1641
+ export const gitHookAdvice = (st) => PRE_COMMIT_HOOK.advice(st);
1642
+
1643
+ // ---- the local setup notice after a pull (E185 part 4) -----------------------------------------------
1644
+ //
1645
+ // git's post-merge hook (after `git pull`, `git merge`) and post-rewrite hook (after `git pull --rebase`; an
1646
+ // `--amend` is left alone) say in one line which local setup steps the pull brought for this machine. They only
1647
+ // print and never fail the pull. Per clone like the pre-commit hook: each machine's `yad check --fix` (or setup,
1648
+ // update, join) installs them; every ledger mode; `"localSetupNotice": false` turns them off, and yad's exact
1649
+ // copies are then removed.
1650
+ //
1651
+ // The script they run is yad's own, copied from its package into this clone's git folder
1652
+ // (`<git-common-dir>/yad/local-setup-notice.mjs`), never a file of the Product's: a pull never changes git's
1653
+ // folder, so a pull can never make a teammate's machine run code the pull brought (review 1).
1654
+ export const NOTICE_HOOK_MARKER = '# yadflow local-setup notice (E185)';
1655
+ const NOTICE_ASSET = 'skills/yad-checks/templates/hooks/local-setup-notice.mjs';
1656
+ const noticeWanted = (root) => {
1657
+ if (!exists(productConfigPath(root))) return false;
1658
+ const cfg = readJSON(productConfigPath(root), null);
1659
+ return !(cfg && cfg.localSetupNotice === false);
1660
+ };
1661
+ // Where this clone keeps its copy, or null outside git.
1662
+ function noticeCopyPath(root) {
1663
+ const r = run('git', ['-C', root, 'rev-parse', '--git-common-dir']);
1664
+ return r.ok && r.stdout ? path.join(path.resolve(root, r.stdout), 'yad', 'local-setup-notice.mjs') : null;
1665
+ }
1666
+ // The hook finds the copy through git at run time, and tells it where the Product is within the repo.
1667
+ // When git cannot say where its folder is, nothing runs: never a fixed path (review 2).
1668
+ const NOTICE_FIND = 'd="$(git rev-parse --git-common-dir 2>/dev/null)" && [ -n "$d" ] || exit 0; notice="$d/yad/local-setup-notice.mjs"';
1669
+ // `|| d=`: a failing git never stops a team's hook that runs under `set -e` (review 3).
1670
+ const NOTICE_FIND_LINE = 'd="$(git rev-parse --git-common-dir 2>/dev/null)" || d=; notice="$d/yad/local-setup-notice.mjs"';
1671
+ const noticeHookScript = (name, prefix = '') => [
1672
+ '#!/bin/sh',
1673
+ `${NOTICE_HOOK_MARKER} — installed in this clone by \`yad check --fix\`.`,
1674
+ '# After a pull, says in one line which local setup steps it brought for this machine. It only prints and',
1675
+ '# never fails the pull. Skip it once with YAD_HOOK_DISABLE=1. yad rewrites this file; to stop it for the',
1676
+ '# whole team, set "localSetupNotice": false in .sdlc/product.json.',
1677
+ ...(name === 'post-rewrite' ? ['[ "$1" = rebase ] || exit 0'] : []),
1678
+ NOTICE_FIND,
1679
+ 'command -v node >/dev/null 2>&1 || exit 0',
1680
+ '[ -f "$notice" ] || exit 0',
1681
+ `node "$notice" ${shQuote(prefix || '.')} || true`,
1682
+ 'exit 0',
1683
+ '',
1684
+ ].join('\n');
1685
+ // The one line a person adds to a hook yad will not touch. post-rewrite's keeps the rebase-only rule.
1686
+ const noticeLine = (name, prefix = '') => {
1687
+ const body = `{ ${NOTICE_FIND_LINE}; [ -z "$d" ] || [ ! -f "$notice" ] || node "$notice" ${shQuote(prefix || '.')} || true; }`;
1688
+ return name === 'post-rewrite' ? `[ "$1" != rebase ] || ${body}` : body;
1689
+ };
1690
+ const NOTICE_HOOKS = Object.freeze(['post-merge', 'post-rewrite'].map((name) => Object.freeze({
1691
+ name,
1692
+ marker: NOTICE_HOOK_MARKER,
1693
+ scripts: (prefix) => [noticeHookScript(name, prefix)],
1694
+ line: (prefix) => noticeLine(name, prefix),
1695
+ applies: noticeWanted,
1696
+ // Wired by hand: a line that is not a comment and runs our copy for this Product's folder — and, for
1697
+ // post-rewrite, only on a rebase (review 3: a mention of the path alone is not enough).
1698
+ // A file with any carriage return is read as not wired: a CR after `}` breaks yad's line under sh, and one after
1699
+ // the `#!` line stops git running the file (reviews 4, 5). husky's sh would tolerate a CR on the `#!` or a comment
1700
+ // line alone — there yad only repeats its advice, the safe side (review 6).
1701
+ wired: (text, prefix) => !text.includes('\r') && text.split('\n').some((l) => !/^\s*#/.test(l) && l.includes('/yad/local-setup-notice.mjs')
1702
+ && l.includes(`node "$notice" ${shQuote(prefix || '.')}`) && (name !== 'post-rewrite' || l.includes('[ "$1" != rebase ]'))),
1703
+ item: `${name} git hook (this clone)`,
1704
+ advice: () => null,
1705
+ })));
1706
+
1707
+ // The copy's state: { file, state: 'ok' | 'missing' | 'outdated' } | null outside git.
1708
+ export function noticeCopyState(root) {
1709
+ const file = noticeCopyPath(root);
1710
+ if (!file) return null;
1711
+ let text = null;
1712
+ try { text = fs.readFileSync(file, 'utf8'); } catch { /* absent */ }
1713
+ const want = fs.readFileSync(asset(NOTICE_ASSET), 'utf8');
1714
+ return { file, want, state: text === null ? 'missing' : text === want ? 'ok' : 'outdated' };
1715
+ }
1716
+
1717
+ // This clone's copy of the script, then both hooks. None of it is committed (`paths` is empty).
1718
+ export function localSetupNoticeActions(root) {
1719
+ if (!noticeWanted(root)) return [];
1720
+ const copy = noticeCopyState(root);
1721
+ const out = [];
1722
+ if (copy && copy.state !== 'ok') {
1723
+ out.push({ scope: 'product', item: 'local setup notice script (this clone, in git\'s folder)', status: copy.state === 'missing' ? 'new' : 'outdated', root, paths: [],
1724
+ apply: () => { fs.mkdirSync(path.dirname(copy.file), { recursive: true }); fs.writeFileSync(copy.file, copy.want); } });
1725
+ }
1726
+ return [...out, ...NOTICE_HOOKS.flatMap((spec) => hookActionsFor(spec, root))];
1727
+ }
1728
+ // Turned off: yad's exact hook copies come out, and the script's copy with them.
1729
+ export function orphanLocalSetupNoticeActions(root) {
1730
+ const out = NOTICE_HOOKS.flatMap((spec) => orphanHookActionsFor(spec, root));
1731
+ if (exists(productConfigPath(root)) && !noticeWanted(root)) {
1732
+ const copy = noticeCopyState(root);
1733
+ // yad's own file in git's folder, which nobody edits: removed whatever its version (review 2).
1734
+ if (copy && copy.state !== 'missing') out.push({ scope: 'product', item: 'local setup notice script (this clone) (removed)', status: 'removed', root, paths: [], apply: () => fs.rmSync(copy.file, { force: true }) });
1735
+ }
1736
+ return out;
1737
+ }
1738
+ // Each hook's state, for doctor: [{ name, ...hook state }].
1739
+ export const localSetupNoticeStates = (root) => NOTICE_HOOKS.map((spec) => ({ name: spec.name, ...hookStateFor(spec, root) }));
1740
+ // ONE sentence for the hooks yad may not write here (a team's own, or core.hooksPath), or null. A convenience,
1741
+ // not a guard: said by check --fix, update, setup and doctor, never on a plain `yad check` (review 1).
1742
+ export function localSetupNoticeAdvice(root) {
1743
+ const blocked = localSetupNoticeStates(root).filter((st) => st.applies && (st.state === 'foreign' || st.state === 'hooks-path'));
1744
+ if (!blocked.length) return null;
1745
+ const where = blocked.map((st) => (st.state === 'hooks-path' ? st.editFile : st.file));
1746
+ const lines = blocked.map((st) => `${st.name}: ${st.line}`).join(' · ');
1747
+ return `yad left ${blocked.map((st) => st.name).join(' and ')} alone (${blocked[0].state === 'hooks-path' ? `core.hooksPath is ${blocked[0].hooksPath}` : 'not yad\'s'}); for the local setup notice after a pull, add to ${where.join(' and ')} — ${lines}`;
1596
1748
  }
1597
1749
 
1598
1750
  // ---- background capture wiring (E43) -----------------------------------------------------------
@@ -1664,6 +1816,128 @@ export function orphanCaptureHookActions(root, ideTargets = ideTargetsFor(root))
1664
1816
  return actions;
1665
1817
  }
1666
1818
 
1819
+ // ---- the live activity record (E178) -------------------------------------------------------------
1820
+ //
1821
+ // OFF by default: wired only while the Product config says `"activity": true` (`yad brain view --live` draws
1822
+ // it). The opposite polarity of capture's switch, read the same way: only the committed CONFIG decides, so two
1823
+ // people's `yad check` never disagree.
1824
+ export function activityWanted(root) {
1825
+ const cfgPath = productConfigPath(root);
1826
+ if (!exists(cfgPath)) return false;
1827
+ const cfg = readJSON(cfgPath, null);
1828
+ return !!(cfg && cfg.activity === true);
1829
+ }
1830
+
1831
+ // Is any folder on the way to `rel` under `root` a link (or not a folder)? Then nothing is written or removed
1832
+ // there: it would land wherever the link points (E178 review 1).
1833
+ function linkOnTheWay(root, rel) {
1834
+ let cur = root;
1835
+ const parts = rel.split('/');
1836
+ for (const part of parts.slice(0, -1)) {
1837
+ cur = path.join(cur, part);
1838
+ const st = lstatIfPresent(cur);
1839
+ if (st && (st.isSymbolicLink() || !st.isDirectory())) return true;
1840
+ }
1841
+ const last = lstatIfPresent(path.join(root, rel));
1842
+ return !!last && last.isSymbolicLink();
1843
+ }
1844
+ const keptSaid = new Set();
1845
+ function sayKept(where, rel) {
1846
+ if (keptSaid.has(`${where}\0${rel}`)) return;
1847
+ keptSaid.add(`${where}\0${rel}`);
1848
+ info(`${where}: ${rel} is not yad's copy (edited, or from before yad recorded it), so it is left in place; nothing runs it now — delete it if it is not yours`);
1849
+ }
1850
+ const linkSaid = new Set();
1851
+ function sayLinked(where, rel) {
1852
+ if (linkSaid.has(`${where}\0${rel}`)) return;
1853
+ linkSaid.add(`${where}\0${rel}`);
1854
+ warn(`${where}: a folder on the way to ${rel} is a link (or not a folder) — the live activity record is not wired there; make it a plain folder, then re-run \`yad check --fix\``);
1855
+ }
1856
+
1857
+ // The script and one entry per adapter whose target this Product uses. Landed together, as capture's are.
1858
+ export function activityHookActions(root, ideTargets = ideTargetsFor(root)) {
1859
+ if (!activityWanted(root)) return [];
1860
+ if (linkOnTheWay(root, ACTIVITY_WIRING[0].dest)) { sayLinked('the Product', ACTIVITY_WIRING[0].dest); return []; }
1861
+ const ledger = readManagedLedger(root);
1862
+ const actions = ACTIVITY_WIRING.map((w) =>
1863
+ wiredFileAction('product', w.dest, asset(w.src), path.join(root, w.dest), { root, exec: !!w.exec, ledger }),
1864
+ );
1865
+ const targets = new Set(safeIdeTargetsFor(root, ideTargets));
1866
+ for (const adapter of ACTIVITY_ADAPTERS) if (targets.has(adapter.target)) actions.push({ ...hookSettingsAction(root, adapter), item: `${path.basename(adapter.settings)} (activity: ${adapter.event})` });
1867
+ return actions.map(asNew);
1868
+ }
1869
+
1870
+ // Our entries for a target that left, or every entry and the script once `activity` is off.
1871
+ export function orphanActivityHookActions(root, ideTargets = ideTargetsFor(root)) {
1872
+ if (!exists(productConfigPath(root))) return [];
1873
+ const on = activityWanted(root);
1874
+ const kept = on ? new Set(safeIdeTargetsFor(root, ideTargets)) : new Set();
1875
+ return activityOrphans(root, kept, ACTIVITY_ADAPTERS, ACTIVITY_WIRING[0].dest, { removeScript: !on, scope: null });
1876
+ }
1877
+
1878
+ // The entries to unmerge (every adapter whose target is not kept), and the script when asked.
1879
+ function activityOrphans(root, kept, adapters, dest, { removeScript, scope }) {
1880
+ const actions = [];
1881
+ for (const adapter of adapters) {
1882
+ if (kept.has(adapter.target)) continue;
1883
+ const settingsPath = path.join(root, adapter.settings);
1884
+ if (!exists(settingsPath)) continue;
1885
+ let parsed;
1886
+ try { parsed = JSON.parse(fs.readFileSync(settingsPath, 'utf8')); } catch { continue; }
1887
+ if (!isPlainObject(parsed) || !unmergeHookSettings(parsed, adapter).changed) continue;
1888
+ actions.push({
1889
+ scope: scope || adapter.target,
1890
+ item: `${path.basename(adapter.settings)} (activity entry removed: ${adapter.event})`,
1891
+ status: 'removed',
1892
+ root,
1893
+ paths: [],
1894
+ apply: () => {
1895
+ let current;
1896
+ try { current = JSON.parse(fs.readFileSync(settingsPath, 'utf8')); } catch { return; }
1897
+ if (!isPlainObject(current)) return;
1898
+ const { settings, changed } = unmergeHookSettings(current, adapter);
1899
+ if (changed) writeJSON(settingsPath, settings);
1900
+ },
1901
+ });
1902
+ }
1903
+ // ONLY A COPY YAD PROVABLY WROTE, reached with no link on the way (E178 review 1, the E113 rule): its sha is
1904
+ // the one `.sdlc/managed.json` recorded, or it is byte for byte the script this release ships. A team's own
1905
+ // edited copy is theirs — their hook may run it — and a `checks/` or `hooks/` that is a link would take the
1906
+ // removal to wherever it points.
1907
+ if (removeScript && !linkOnTheWay(root, dest)) {
1908
+ const file = path.join(root, dest);
1909
+ const st = lstatIfPresent(file);
1910
+ const sha = st && st.isFile() ? contentSha(file) : null;
1911
+ const ours = sha && (readManagedLedger(root)[dest] === sha || sha === contentSha(asset(ACTIVITY_WIRING[0].src)));
1912
+ if (ours) actions.push({ scope: scope || 'product', item: `${dest} (removed)`, status: 'removed', root, paths: scope ? [] : [dest], apply: () => fs.rmSync(file, { force: true }) });
1913
+ else if (sha) sayKept(scope || 'the Product', dest);
1914
+ }
1915
+ return actions;
1916
+ }
1917
+
1918
+ // In a connected code repo cloned here: the script in `checks/` and the entries in the repo's own settings
1919
+ // files, for the Product's targets, as the agent guard's are (`repoAgentGuardActions`).
1920
+ export function repoActivityActions(productRoot, repoRoot, ideTargets, { scope, ledger = readManagedLedger(repoRoot) }) {
1921
+ if (!activityWanted(productRoot)) return [];
1922
+ if (linkOnTheWay(repoRoot, REPO_ACTIVITY_DEST)) { sayLinked(scope, REPO_ACTIVITY_DEST); return []; }
1923
+ const targets = new Set(repoTargets(repoRoot, ideTargets, scope));
1924
+ const settings = activityAdapters(REPO_ACTIVITY_DEST).filter((a) => targets.has(a.target))
1925
+ .map((a) => ({ ...hookSettingsAction(repoRoot, a, undefined, scope), scope, item: `${a.settings} (activity: ${a.event})` }));
1926
+ if (!settings.length) return [];
1927
+ return [wiredFileAction(scope, REPO_ACTIVITY_DEST, asset(ACTIVITY_WIRING[0].src), path.join(repoRoot, REPO_ACTIVITY_DEST), { root: repoRoot, ledger }), ...settings];
1928
+ }
1929
+
1930
+ // The same, taken out of a code repo: a target that left, or everything once `activity` is off. A tool folder
1931
+ // that is a link or not a folder is never written through.
1932
+ export function repoOrphanActivityActions(productRoot, repoRoot, ideTargets, { scope }) {
1933
+ if (!isDirectory(repoRoot)) return [];
1934
+ const on = activityWanted(productRoot);
1935
+ const kept = on ? new Set(repoTargets(repoRoot, ideTargets, null)) : new Set();
1936
+ const linked = (ide) => { const st = lstatIfPresent(path.join(repoRoot, ide)); return !!st && (st.isSymbolicLink() || !st.isDirectory()); };
1937
+ const adapters = activityAdapters(REPO_ACTIVITY_DEST).filter((a) => !linked(a.target));
1938
+ return activityOrphans(repoRoot, kept, adapters, REPO_ACTIVITY_DEST, { removeScript: !on, scope });
1939
+ }
1940
+
1667
1941
  // The read-only yad commands, pre-approved for Claude Code (E158, issue #353): `readAllowList` added to
1668
1942
  // `permissions.allow` in `.claude/settings.json`. Additive: the team's own entries are kept, and an entry of
1669
1943
  // ours already there is not added twice. A shape it cannot read is refused, as the hook merge refuses one.
package/cli/platform.mjs CHANGED
@@ -639,7 +639,7 @@ export function createPr(platform, opts = {}) {
639
639
  if (platform === 'github') {
640
640
  const r = run('gh', buildPrArgs('github', { ...opts, reviewers: [] }), { cwd: opts.cwd });
641
641
  if (!r.ok) return { ok: false, reason: r.stderr };
642
- const url = r.stdout.split('\n').pop();
642
+ const url = urlFromStdout(r.stdout);
643
643
  const number = prNumberFromUrl(url);
644
644
  const added = []; const dropped = [];
645
645
  if (number) {
@@ -652,7 +652,7 @@ export function createPr(platform, opts = {}) {
652
652
  // gitlab
653
653
  const r = run('glab', buildPrArgs('gitlab', opts), { cwd: opts.cwd });
654
654
  if (!r.ok) return { ok: false, reason: r.stderr };
655
- const url = r.stdout.split('\n').pop();
655
+ const url = urlFromStdout(r.stdout);
656
656
  const iid = prNumberFromUrl(url);
657
657
  const rest = reviewers.slice(1);
658
658
  // Only report a reviewer as `mentioned` if the @-mention note actually posted; otherwise they were
@@ -790,12 +790,12 @@ export function createDraftAdvisory(t, { summary, description, severity, cwe },
790
790
  // ---- acting on an item when a person asks (E173) -------------------------------------------------------
791
791
  // Each returns the runner's result. A GitLab list field cannot be sent through `glab api` (it refuses a
792
792
  // bracketed field name), so GitLab takes one assignee by id.
793
- export function newItem(t, { title, body, labels, assignee = null, confidential = false }, { runner = run } = {}) {
793
+ export function newItem(t, { title, body, labels, assignee = null, confidential = false, milestone = null }, { runner = run } = {}) {
794
794
  if (t.platform === 'github') {
795
- const fields = ['-f', `title=${title}`, '-f', `body=${body}`, ...labels.flatMap((l) => ['-f', `labels[]=${l}`]), ...(assignee ? ['-f', `assignees[]=${assignee}`] : [])];
795
+ const fields = ['-f', `title=${title}`, '-f', `body=${body}`, ...labels.flatMap((l) => ['-f', `labels[]=${l}`]), ...(assignee ? ['-f', `assignees[]=${assignee}`] : []), ...(milestone !== null ? ['-F', `milestone=${milestone}`] : [])];
796
796
  return runner('gh', ['api', '--hostname', t.host, '-X', 'POST', `repos/${t.repo}/issues`, ...fields], { timeout: 30000 });
797
797
  }
798
- const fields = ['-f', `title=${title}`, '-f', `description=${body}`, '-f', `labels=${labels.join(',')}`, ...(assignee ? ['-F', `assignee_id=${assignee}`] : []), ...(confidential ? ['-F', 'confidential=true'] : [])];
798
+ const fields = ['-f', `title=${title}`, '-f', `description=${body}`, '-f', `labels=${labels.join(',')}`, ...(assignee ? ['-F', `assignee_id=${assignee}`] : []), ...(confidential ? ['-F', 'confidential=true'] : []), ...(milestone !== null ? ['-F', `milestone_id=${milestone}`] : [])];
799
799
  return runner('glab', ['api', '--hostname', t.host, '-X', 'POST', `projects/${encodeURIComponent(t.repo)}/issues`, ...fields], { timeout: 30000 });
800
800
  }
801
801
 
@@ -43,7 +43,7 @@ export const INDEX_FORMAT = 'e111-1';
43
43
  // Line endings are made `\n` before anything else: a checkout with `core.autocrlf` (the Windows default)
44
44
  // holds CRLF where git stores LF, and the same Product must hash the same on every machine — and parse
45
45
  // the same, since the frontmatter reader expects `\n`. Nothing else in the bytes is touched.
46
- function readInput(file) {
46
+ export function readInput(file) {
47
47
  try {
48
48
  const raw = fs.readFileSync(file);
49
49
  return { bytes: raw.includes(13) ? Buffer.from(raw.toString('latin1').replace(/\r\n/g, '\n'), 'latin1') : raw };
@@ -54,6 +54,38 @@ export function repoPathFromGitUrl(url = '') {
54
54
  return parts.length >= 2 ? parts.join('/') : null;
55
55
  }
56
56
 
57
+ // A git_url that names a repo, as written (trimmed), else ''. A url that names only a host
58
+ // (`https://gitlab.example.com`, `git@host:`) says where the platform is but not which repo, so a reader
59
+ // that falls back to the clone's origin remote must fall back for it too (#513) — through `configuredGitUrl`.
60
+ export const repoGitUrl = (u) => (typeof u === 'string' && repoPathFromGitUrl(u) ? u.trim() : '');
61
+
62
+ // The address to ask the platform about, from a settings `git_url` and the clone's origin remote (#513):
63
+ // - the settings' url when it names a repo;
64
+ // - else origin — but the HOST stays the settings' when they name one: origin can be a person's own SSH
65
+ // alias (`git@gitlab-work:acme/product.git`), and the CI member check reads the host from the settings
66
+ // first. So a host-only url and origin on another host give the settings' host with origin's repo path.
67
+ // - else '' when neither names anything.
68
+ // `origin` is the url, or a function that reads it — asked only when the settings name no repo. A rebuilt url
69
+ // is for asking the platform (host + repo path) only, never for git to clone: the login name is dropped, and
70
+ // a GitLab installed under a sub-path (`https://example.com/gitlab`) is not kept. An origin with no plain host
71
+ // (`file://`, a local path) is never rebuilt onto the platform's host: it names no repo there.
72
+ export function configuredGitUrl(set, origin) {
73
+ const own = repoGitUrl(set);
74
+ if (own) return own;
75
+ const read = typeof origin === 'function' ? origin() : origin;
76
+ const o = typeof read === 'string' ? read.trim() : '';
77
+ const repo = repoPathFromGitUrl(o);
78
+ const host = plainHost(hostFromGitUrl(typeof set === 'string' ? set : ''));
79
+ const originHost = plainHost(hostFromGitUrl(o));
80
+ if (!repo || !host || !originHost || originHost === host) return o;
81
+ const s = set.trim();
82
+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(s)) {
83
+ try { const u = new URL(s); u.username = ''; u.password = ''; u.search = ''; u.hash = ''; u.pathname = `/${repo}.git`; return u.toString(); } catch { /* below */ }
84
+ }
85
+ const scp = s.match(/^((?:[^@/]+@)?[^/:]+):/);
86
+ return scp ? `${scp[1]}:${repo}.git` : `https://${host}/${repo}.git`;
87
+ }
88
+
57
89
  // The HTTP status of a failed `gh api` / `glab api` call, or null when there was none (offline, a timeout,
58
90
  // the host is down). gh ends with `gh: Not Found (HTTP 404)`; glab with `glab: 404 Not Found (HTTP 404)`
59
91
  // and prints the body `{"message":"401 Unauthorized"}` on stdout.