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/bin/yad.mjs CHANGED
@@ -133,6 +133,23 @@ ${c.bold('Team members')} ${c.dim('(identity only — no roles, no reviewers, no
133
133
  yad member remove [<login>] [--reason <why>]
134
134
  Delete a member file — your own, or anyone's with --reason
135
135
 
136
+ ${c.bold('Issues and work items')} ${c.dim('(read live from GitHub issues and GitLab issues, tasks and incidents)')}
137
+ yad issues [list] Items of the Product and every registered repo, with priority,
138
+ type, status, assignee and other labels. Filter with --priority
139
+ --type --status --label --assignee --me --repo --since --until
140
+ --date; order with --sort. Repeat --label to need every one.
141
+ --format html writes a page you can sort and filter; titles are
142
+ included, so check it before sharing it outside the team
143
+ yad issues labels [--dry-run] Create the predefined priority, type and status labels each repo lacks
144
+ yad scan file <f> --repo <r> File a scan's findings on the repo's tracker, by category and priority (the yad-scan skill runs it)
145
+ yad issues new --title <t> [--body-file <f>] [--type <t>] [--priority P1] [--assignee <login>|--me] [--repo <r>]
146
+ Open an issue / work item (in the Product repo unless --repo names one)
147
+ yad issues assign <ref> <login>|--me|--none · label <ref> --priority P1 --type bug --add <l> --remove <l>
148
+ yad issues edit <ref> [--title] [--body-file] · comment <ref> --body-file <f> · close <ref> · reopen <ref>
149
+ yad issues sync [--dry-run] Update linked items: status and type labels, and close once every epic shipped
150
+ yad issues show <ref> One item in full. <ref> is 12 (Product repo) or <repo>#12
151
+ yad issues link|unlink <ref> <EP> Link an item to an epic: comments on it and sets its type and status labels
152
+
136
153
  ${c.bold('Daily standup')} ${c.dim('(derived live, read-only, facts only — no score, no ranking)')}
137
154
  yad standup Each member on the team list: done since the last standup
138
155
  (commits, approvals, comments, closed steps, ships, merged
@@ -146,14 +163,39 @@ ${c.bold('Daily standup')} ${c.dim('(derived live, read-only, facts only — no
146
163
  flags: --since <YYYY-MM-DD>|<N>h|<N>d, --tz <zone> (default UTC),
147
164
  --member <login> | --me, --format md|html, --out <file>, --json
148
165
 
166
+ ${c.bold('Progress map')} ${c.dim('(E181 — read-only; names as roles, no score, no ranking)')}
167
+ yad map [--open] The road to Production as one moving picture: epics, stories, tasks
168
+ and branches flowing through each repo's Development branch into
169
+ Production, with who owns, built, reviewed and approved each part.
170
+ A local page on 127.0.0.1 with a one-time key; Ctrl-C stops it
171
+ yad map --html [<file>] [--open] The same page as one file, saved in the local reports folder; it
172
+ lights what moved since the last saved map
173
+ yad map --live [--open] The page draws itself again when the ledger or a repo changes
174
+ flags: --anonymous (every person as "Person A…", for sharing
175
+ outside the team), --fetch (git fetch origin first; downloads
176
+ only), --json. The Production branch is "map.production" in
177
+ product.json, else guessed (and the page says so)
178
+
179
+ ${c.bold('Saved reports')} ${c.dim('(E180 — on this machine only, never committed)')}
180
+ yad reports [list] [--json] Every report saved in the local reports folder, newest first, each
181
+ marked fresh or stale (the Product changed since it was made).
182
+ The folder is <product>--reports beside the Product, or
183
+ $YAD_REPORTS_DIR. Reports land there when no --out is given:
184
+ standup, usage, issues list --format, brain view --html
185
+ yad reports open <n|file> Open one in the browser
186
+ yad reports prune --older-than <days> | --missing [--apply]
187
+ Remove saved reports older than that, or with --missing only drop
188
+ catalog entries whose file is gone (a dry run without --apply)
189
+
149
190
  ${c.bold('Team usage (EM adoption & behavior report)')}
150
191
  yad usage Build a per-member report (HTML) from git + the SDLC ledgers
151
192
  (derived, read-only — writes no tracked state)
152
- flags: --out <path> (default ./usage-report.html),
193
+ flags: --out <path> (default: the local reports folder),
153
194
  --since <YYYY-MM-DD> --until <YYYY-MM-DD> | --all,
154
195
  --member <name>, --format html|json|md, --repos (code commits)
155
196
 
156
197
  ${c.bold('Where am I / what next')}
198
+ yad epic new <slug> --issue <ref> Seed from an item: its label sets the type; a defect or change finds its parent or gets a stub
157
199
  yad epic new <slug> [--type <t>] [--profile <p>] [--stub] [--parent <epic> --inherits <bases>] [--json]
158
200
  Seed a new epic's lifecycle: writes its step chain from a
159
201
  profile, plus empty approval/comment ledgers and reviews/.
@@ -179,6 +221,7 @@ ${c.bold('Where am I / what next')}
179
221
  per product, before any epic — then the yad-discovery skill
180
222
  authors its sections. Refuses a second one, and a product still
181
223
  on the old epics/EP-discovery/ (yad migrate converts that)
224
+ yad foundation publish [--dry-run] After the Foundation review: one issue / work item per roadmap feature, a milestone per phase
182
225
  yad foundation status [--json] Which roadmap features are started: reads each proposed epic id
183
226
  in roadmap.md and reports planned / in-shape / in-build /
184
227
  shipped from the epic ledgers. Read-only — the roadmap's Status
@@ -219,7 +262,7 @@ ${c.bold('Where am I / what next')}
219
262
  command (pool skill first, yadflow's skill last). Binds nothing
220
263
  yad toolbox list [--json] [--dir <folder>]
221
264
  The external tools yadflow can use — core (offered at setup),
222
- recommended (skill pools, Docker MCP), the connectors and
265
+ recommended (skill pools, Docker MCP, two Unity MCPs), the connectors and
223
266
  this project's own — whether each is found here, whether this
224
267
  project uses it, and what yadflow does without it. Installs nothing
225
268
  yad toolbox check [--json] The tools this project uses that are not ready here, each with
@@ -229,6 +272,12 @@ ${c.bold('Where am I / what next')}
229
272
  --role "<text>" --fallback "<text>" --detect <kind>:<name>[,…]
230
273
  [--install "<type>: <command>"] [--source <https URL>]
231
274
  yad toolbox remove <id> Stop using a tool in this Product, or drop one of your own
275
+ yad toolbox connect <id> [--verify [--replace]]
276
+ What putting a tool on this machine takes (E165): the steps the
277
+ agent may run after your yes (pinned installs), the ones that
278
+ are yours, and the question to ask. Runs nothing. --verify
279
+ checks it is found here, then records it as the team's choice;
280
+ --replace when that replaces the team's current tool
232
281
  yad detect [--json] [--dir <folder>] Which skills, agents, MCP servers and plugins are installed
233
282
  for the agents that work here — in this folder and in your
234
283
  home folder, and which agents read each place. Read-only;
@@ -409,6 +458,34 @@ ${c.bold('Build helpers')}
409
458
  yad history search <text> [filters] [--json]
410
459
  Match text in ids, titles, themes, types, repos, and in who
411
460
  closed or merged a step, its PR and its commit
461
+ yad brain build [--repo <name>] [--json]
462
+ The project brain (E176): run Graphify (local, no LLM) in each
463
+ connected code repo, then merge its code graph with the work items
464
+ (epics, stories, tasks, contract surfaces, ships) into
465
+ .sdlc/brain/graph.json — on this machine only, never committed
466
+ yad brain query <text> [--limit <n>] [--json]
467
+ The brain's nodes whose name holds <text>, each with its neighbours
468
+ yad brain file <repo>/<path> [--repo <name>] [--limit <n>] [--json]
469
+ One file (E179): the tasks and stories that declare it, the code it
470
+ defines, the files that use it and that it uses, its ships, and the
471
+ contract surfaces that reach it — what to know before editing it
472
+ yad brain story <story-id> [--limit <n>] [--json]
473
+ One story (E179): its epic, repos, tasks, every file they declare,
474
+ and its ships
475
+ yad brain status [--json] Is the brain current, and is each repo's code graph current
476
+ yad brain view [--open] Draw the brain in a browser (E177): a local page on 127.0.0.1 with a
477
+ one-time key, the code and the work in one graph — filter, search, a
478
+ node's neighbours. Ctrl-C stops it
479
+ yad brain view --html [<file>] [--open]
480
+ The same page as one file that needs no server and no network
481
+ (default: the local reports folder, never committed)
482
+ yad brain view --live [--open] Watch an agent work (E178): each file it reads, searches or edits and
483
+ each command it runs lights up the brain, with a Now card, Plan vs
484
+ reality and a timeline to replay. Needs "activity": true in the
485
+ Product config (then yad check --fix). Shows what, never why
486
+ yad brain view --html --live [<file>]
487
+ The recorded activity as an offline replay file
488
+ (default: the local reports folder, never committed)
412
489
  yad review trailer --repo <r> --pr <n> --body <text> Post the companion's 60-sec briefing to a code PR/MR
413
490
  yad review context --repo <r> --pr <n> Print the grounding bundle for cards/chat
414
491
  yad review walkthrough --repo <r> --pr <n> Bundle + ordered risk-tagged stops for the
@@ -494,6 +571,7 @@ ${c.bold('Environment')}
494
571
  YAD_PLATFORM_LOGIN=0 Name a record's author by git user.name; never ask gh/glab who is logged in`;
495
572
 
496
573
  const REPORT_USAGE = 'usage: yad report [-m <text>] [--kind bug|enhancement] [--json] | yad report -m <text> [--kind …] --post --confirm <value>';
574
+ const ISSUES_USAGE = 'usage: yad issues new --title <t> [--body-file <f>] [--type <t>] [--priority P0-P3] [--assignee <login>|--me] [--repo <name>] | assign <ref> <login>|--me|--none | label <ref> [--priority P0-P3] [--type <t>] [--add <label>]... [--remove <label>]... | edit <ref> [--title <t>] [--body-file <f>] | comment <ref> --body-file <f> | close <ref> | reopen <ref> | show <ref> | link <ref> <EP-id> | unlink <ref> <EP-id> | sync [--dry-run] | labels [--dry-run] | [list] [--priority P0,P1] [--type bug,feature,enhancement,security,tech-debt,suggestion] [--status todo,"in progress",done] [--label <name>[,<name>]]... [--assignee <login>|none|--me] [--repo <name>] [--since <date>] [--until <date>] [--date created|updated|due] [--sort priority|type|status|due|updated] [--closed-since <date>|<N>d] [--format md|html] [--out <file>] [--json] | yad issues labels [--dry-run] [--json]';
497
575
  const STANDUP_USAGE = 'usage: yad standup [--since <YYYY-MM-DD>|<N>h|<N>d] [--tz <zone>] [--member <login>|--me] [--format md|html] [--out <file>] [--json]';
498
576
 
499
577
 
@@ -507,6 +585,7 @@ function parseArgs(argv) {
507
585
  else if (a === '--contract-change') o.contractChange = true;
508
586
  else if (a === '--manual') o.manual = true;
509
587
  else if (a === '--me') o.me = true;
588
+ else if (a === '--none') o.none = true;
510
589
  else if (a === '--no-push') o.noPush = true;
511
590
  else if (a === '--no-fetch') o.noFetch = true;
512
591
  else if (a === '--no-build') o.noBuild = true;
@@ -527,7 +606,12 @@ function parseArgs(argv) {
527
606
  else if (a === '--check') { const v = argv[i + 1]; o.check = (o._[0] === 'next' && v !== undefined && !v.startsWith('-')) ? argv[++i] : true; }
528
607
  else if (a === '--all') o.all = true;
529
608
  else if (a === '--brief') o.brief = true;
609
+ else if (a === '--missing') o.missing = true;
530
610
  else if (a === '--open') o.open = true;
611
+ else if (a === '--html') o.html = true;
612
+ else if (a === '--live') o.live = true;
613
+ else if (a === '--anonymous') o.anonymous = true;
614
+ else if (a === '--fetch') o.fetch = true;
531
615
  else if (a === '--done') o.done = true;
532
616
  else if (a === '--undo') o.undo = true;
533
617
  else if (a === '--debt') o.debt = true;
@@ -557,6 +641,8 @@ function parseArgs(argv) {
557
641
  // say what it means rather than relying on the absence of a flag.
558
642
  else if (a === '--preview') o.apply = false;
559
643
  else if (a === '--custom') o.custom = true;
644
+ else if (a === '--verify') o.verify = true;
645
+ else if (a === '--replace') o.replace = true;
560
646
  else if (a === '--json') o.json = true;
561
647
  else if (a === '-h' || a === '--help') o.help = true;
562
648
  else if (a === '-v' || a === '--version') o.version = true;
@@ -611,12 +697,13 @@ let runningCmd = null;
611
697
  // refusal of `yad gate frobnicate` names `gate`, not a command that does not exist.
612
698
  const ACTIONS = {
613
699
  epic: { known: ['new'] },
614
- foundation: { known: ['new', 'status'] },
700
+ foundation: { known: ['new', 'status', 'publish'] },
615
701
  skill: { known: ['list', 'bind', 'unbind', 'recommend'], default: 'list' },
616
702
  gate: { known: ['open', 'sync', 'comments', 'status', 'repair', 'reopen', 'review', 'walkthrough', 'trailer', 'ci', 'approve', 'comment', 'advance'] },
617
703
  review: { known: ['trailer', 'context', 'chat', 'cards', 'walkthrough', 'nudge', 'reconcile'] },
618
704
  tidy: { known: ['up'] },
619
705
  history: { known: ['list', 'show', 'search'], default: 'list' },
706
+ brain: { known: ['build', 'query', 'file', 'story', 'status', 'view'], default: 'status' },
620
707
  repo: { known: ['list', 'refresh', 'sync', 'clone', 'preview'], default: 'list' },
621
708
  'risk-map': { known: ['check', 'draft'], default: 'check' },
622
709
  codeowners: { known: ['check'], default: 'check' },
@@ -624,13 +711,16 @@ const ACTIONS = {
624
711
  docs: { known: ['list', 'build', 'deploy', 'sync'], default: 'list' },
625
712
  reconcile: { known: ['check', 'refresh', 'wire'] },
626
713
  hook: { known: ['ledger-guard', 'agent-guard'] },
627
- toolbox: { known: ['list', 'check', 'add', 'remove'], default: 'list' },
714
+ toolbox: { known: ['list', 'check', 'add', 'remove', 'connect'], default: 'list' },
628
715
  signing: { known: ['check'], default: 'check' },
629
716
  ci: { known: ['check'], default: 'check' },
630
717
  member: { known: ['add', 'list', 'remove'], default: 'list' },
718
+ scan: { known: ['file'] },
719
+ issues: { known: ['list', 'labels', 'show', 'link', 'unlink', 'sync', 'new', 'assign', 'label', 'edit', 'comment', 'close', 'reopen'], default: 'list' },
631
720
  worktree: { known: ['add', 'list', 'remove'], default: 'list' },
632
721
  run: { known: ['checks'] },
633
722
  build: { known: ['start', 'step', 'trust', 'ship', 'merged', 'done', 'sync'] },
723
+ reports: { known: ['list', 'open', 'prune'], default: 'list' },
634
724
  };
635
725
  // E80 — how each command finds its folder. A PRODUCT command works on the Product; a REPO command works
636
726
  // on the code repo it runs in and reads the Product beside it. The rest take their folder as given:
@@ -639,8 +729,8 @@ const PRODUCT_CMDS = new Set([
639
729
  'check', 'update', 'doctor', 'migrate', 'usage', 'sync-status', 'epic', 'foundation', 'skill', 'next',
640
730
  'skip', 'unskip', 'defer', 'undefer', 'dial', 'mode', 'kill', 'unkill', 'unblock', 'gate', 'checkpoint',
641
731
  'capture', 'claims', 'assign', 'unassign', 'owners', 'fold', 'tidy', 'index', 'history', 'repo',
642
- 'risk-map', 'codeowners', 'docs', 'thread', 'reconcile', 'member', 'standup', 'build', 'worktree', 'ci',
643
- 'story',
732
+ 'risk-map', 'codeowners', 'docs', 'thread', 'reconcile', 'member', 'standup', 'issues', 'scan', 'build', 'worktree', 'ci',
733
+ 'story', 'brain', 'reports', 'map',
644
734
  ]);
645
735
  // `status` reads the Product but must keep the folder it ran in: "here" is that checkout's task branch (#349).
646
736
  const REPO_CMDS = new Set(['commit', 'open-pr', 'ship', 'review', 'run', 'status', 'guide']);
@@ -653,6 +743,9 @@ function writesProduct(cmd, o) {
653
743
  // `build merged` only asks the platform, unless --ship records what it found.
654
744
  if (cmd === 'build') return action === 'sync' ? !o.dryRun : action !== 'merged' || !!o.ship;
655
745
  if (cmd === 'check') return !!o.fix;
746
+ // `brain build` writes the brain into the Product. `brain view --html` with no file named saves into the
747
+ // Product's local reports folder (E180), so it needs the Product found too: else the shared refusal.
748
+ if (cmd === 'brain') return action === 'build' || (action === 'view' && !!o.html);
656
749
  if (cmd === 'epic' || cmd === 'foundation') return action === 'new';
657
750
  if (cmd === 'skill') return action === 'bind' || action === 'unbind';
658
751
  if (cmd === 'dial') return o.to !== undefined;
@@ -714,7 +807,7 @@ async function main() {
714
807
  // so it takes no --json (E1).
715
808
  if (inJSON()) return refuse('yad hook takes no --json — its output is the protocol the agent reads', 'run it without --json');
716
809
  // E158: the agent guard, before an agent's shell command.
717
- if (action === 'agent-guard') { runAgentGuardHook({ format: o.format ?? null }); return; }
810
+ if (action === 'agent-guard') { await runAgentGuardHook({ format: o.format ?? null }); return; }
718
811
  if (action !== 'ledger-guard') return refuse(`unknown hook: ${action ?? '(none)'} (ledger-guard, agent-guard)`);
719
812
  // `--staged` is the git pre-commit half (E48): the files come from the index, never from stdin.
720
813
  if (o.staged) { runStagedLedgerGuard(); return; }
@@ -761,14 +854,15 @@ async function main() {
761
854
  process.stderr.write(c.dim(`Product: ${shown(found.root)} (${found.worktree ? `${found.worktree}'s worktree` : found.via === 'workspace' ? `from ${commands.WORKSPACE_FILE}` : 'above this folder'})\n`));
762
855
  // Run from inside one code repo, the per-repo commands work on THAT repo, not on every one the
763
856
  // Product registers (they take the repo's name as their second word).
764
- // The CHECKOUT must be the registered repo (a worktree or nested repo inside it is another one).
857
+ // The CHECKOUT must be the registered repo's own: these commands work on `<Product>/<path>`, so from a
858
+ // worktree (on another branch) or a nested repo they cover every repo instead (E80 review 3, #515).
765
859
  if ((cmd === 'risk-map' || cmd === 'codeowners') && o._[2] === undefined) {
766
- const hit = commands.registryEntryFor(found.root, dirGiven ? o.dir : shellCwd());
860
+ const hit = commands.registeredCheckoutFor(found.root, dirGiven ? o.dir : shellCwd());
767
861
  if (typeof hit?.meta?.name === 'string') o._[2] = hit.meta.name;
768
862
  }
769
863
  // `yad ci check` the same way: that repo, unless --repo or --all says otherwise.
770
864
  if (cmd === 'ci' && o.repo === undefined && !o.all) {
771
- const hit = commands.registryEntryFor(found.root, dirGiven ? o.dir : shellCwd());
865
+ const hit = commands.registeredCheckoutFor(found.root, dirGiven ? o.dir : shellCwd());
772
866
  if (typeof hit?.meta?.name === 'string') o.repo = hit.meta.name;
773
867
  }
774
868
  }
@@ -893,8 +987,8 @@ async function main() {
893
987
  // team's choices are the Product's `.sdlc/toolbox.json`, found the way every Product command finds
894
988
  // it. So `toolbox` is not in PRODUCT_CMDS: that would move the finding to the Product's folder.
895
989
  const [, action = 'list', id, extra] = o._;
896
- const usage = 'usage: yad toolbox list | check | add <id> [--custom …] | remove <id> [--json] [--dir <folder>]';
897
- if (!['list', 'check', 'add', 'remove'].includes(action)) { refuse(`unknown toolbox action: ${action} (list, check, add, remove)`, usage); break; }
990
+ const usage = 'usage: yad toolbox list | check | add <id> [--custom …] | remove <id> | connect <id> [--verify] [--json] [--dir <folder>]';
991
+ if (!['list', 'check', 'add', 'remove', 'connect'].includes(action)) { refuse(`unknown toolbox action: ${action} (list, check, add, remove, connect)`, usage); break; }
898
992
  const found = commands.findProduct(dirGiven ? o.dir : shellCwd());
899
993
  const rel = (p) => path.relative(process.cwd(), p) || '.';
900
994
  if (action === 'list' || action === 'check') {
@@ -910,6 +1004,12 @@ async function main() {
910
1004
  break;
911
1005
  }
912
1006
  if (extra) { refuse(`yad toolbox ${action} takes one tool id (got also: ${extra})`, usage); break; }
1007
+ // E165. Without --verify it only reads (the steps, the question, what will be recorded), so it needs no
1008
+ // Product; --verify records the team's choice, so it is a writer like add.
1009
+ if (action === 'connect' && !o.verify) {
1010
+ result = commands.runToolboxConnect(commands.toolsFolder(found, o.dir || process.cwd()), found?.root ?? null, { id, json: o.json });
1011
+ break;
1012
+ }
913
1013
  // A writer: the Product's file, never a code repo's, and the same refusals every writer has. With
914
1014
  // --dir it is the Product itself, as for every other Product command (`yad skill bind --dir`) —
915
1015
  // never a folder a walk up from it happens to reach.
@@ -926,7 +1026,9 @@ async function main() {
926
1026
  commands.warnIfProjectAhead(productRoot);
927
1027
  const drift = commands.productDriftError(productRoot);
928
1028
  if (drift) throw drift;
929
- result = action === 'add'
1029
+ result = action === 'connect'
1030
+ ? commands.runToolboxConnect(commands.toolsFolder(found, o.dir || process.cwd()), productRoot, { id, verify: true, replace: o.replace, json: o.json })
1031
+ : action === 'add'
930
1032
  ? commands.runToolboxAdd(productRoot, { id, custom: o.custom, role: o.role, fallback: o.fallback, detect: o.detect, install: o.install, source: o.source, json: o.json })
931
1033
  : commands.runToolboxRemove(productRoot, { id, custom: o.custom, role: o.role, fallback: o.fallback, detect: o.detect, install: o.install, source: o.source, json: o.json });
932
1034
  break;
@@ -972,14 +1074,22 @@ async function main() {
972
1074
  break;
973
1075
  }
974
1076
  if (noProduct()) break;
1077
+ if (o.issue !== undefined) {
1078
+ const foreign = commands.seedForeign(process.argv.slice(2));
1079
+ if (foreign.length) { refuse(`yad epic new --issue does not take ${foreign.join(', ')}`); break; }
1080
+ result = await commands.runEpicNewFromIssue(o.dir, { slug, issue: o.issue, type: o.type, profile: o.profile, stub: o.stub, parent: o.parent, inherits: o.inherits, today, json: o.json });
1081
+ break;
1082
+ }
975
1083
  result = await commands.runEpicNew(o.dir, { slug, type: o.type, profile: o.profile, stub: o.stub, parent: o.parent, inherits: o.inherits, today, json: o.json });
976
1084
  break;
977
1085
  }
978
1086
  case 'foundation': {
979
1087
  const [, action] = o._;
980
1088
  if (action === 'status') { result = await commands.runFoundationStatus(o.dir, { json: o.json }); break; }
1089
+ // E174: the approved roadmap becomes work items in the Product repo.
1090
+ if (action === 'publish') { if (noProduct()) break; result = await commands.runFoundationPublish(o.dir, { dryRun: !!o.dryRun, json: !!o.json }); break; }
981
1091
  if (action !== 'new') {
982
- refuse(`unknown foundation action: ${action ?? '(none)'} (new, status)`, 'usage: yad foundation new [--json] | yad foundation status [--json]');
1092
+ refuse(`unknown foundation action: ${action ?? '(none)'} (new, status, publish)`, 'usage: yad foundation new [--json] | yad foundation status [--json] | yad foundation publish [--dry-run] [--json]');
983
1093
  break;
984
1094
  }
985
1095
  if (noProduct()) break;
@@ -1106,6 +1216,8 @@ async function main() {
1106
1216
  else if (action === 'comment') result = await commands.gateComment(o.dir, { epic, artifact, by: o.by, count: o.count ?? null, newRound: !!o.newRound, today });
1107
1217
  else if (action === 'advance') result = await commands.gateAdvance(o.dir, { epic, artifact, today });
1108
1218
  else { refuse(`unknown gate action: ${action} (open|sync|comments|status|repair|reopen|review|walkthrough|trailer|ci|approve|comment|advance)`); }
1219
+ // E171: a gate that really advanced here updates its linked items. `gate ci` is left out: CI cannot write to issues.
1220
+ if ((action === 'sync' && result?.written && result?.advanced > 0) || (action === 'advance' && result?.advanced === true)) commands.syncAfterGate(o.dir, epic);
1109
1221
  break;
1110
1222
  }
1111
1223
  case 'review': {
@@ -1222,6 +1334,56 @@ async function main() {
1222
1334
  else result = await commands.runWorktreeRemove(o.dir, { epic, repo: o.repo ?? null, all: !!o.all, cwd: shellCwd() });
1223
1335
  break;
1224
1336
  }
1337
+ case 'issues': {
1338
+ // E169. `list` reads and may write the --out file; `labels` adds the predefined labels to the repos.
1339
+ if (noProduct()) break;
1340
+ const action = o._[1] ?? 'list';
1341
+ if (!ACTIONS.issues.known.includes(action)) { refuse(`unknown issues action: ${action} (list, labels, show, link, unlink, sync, new, assign, label, edit, comment, close, reopen)`, ISSUES_USAGE); break; }
1342
+ if (commands.ACT_ACTIONS.includes(action)) {
1343
+ // E173: the agent acts on an item when an engineer asks. Before the older checks: these take a <ref> and their own flags.
1344
+ const foreign = commands.actForeignFlags(process.argv.slice(2), action);
1345
+ if (foreign.length) { refuse(`yad issues ${action} does not take ${foreign.join(', ')}`, ISSUES_USAGE); break; }
1346
+ const words = o._.slice(2);
1347
+ const wants = action === 'new' ? 0 : action === 'assign' ? (o.me || o.none ? 1 : 2) : 1;
1348
+ if (words.length !== wants) { refuse(`yad issues ${action} takes ${action === 'new' ? 'no words (use --title)' : action === 'assign' ? '<ref> <login>, or <ref> --me|--none' : '<ref>'}`, ISSUES_USAGE); break; }
1349
+ const common = { json: !!o.json };
1350
+ if (action === 'new') result = await commands.runIssuesNew(o.dir, { ...common, title: o.title, body: o.body ?? null, bodyFile: o['body-file'] ?? null, type: o.type ?? null, priority: o.priority ?? null, assignee: o.assignee ?? null, me: !!o.me, repo: o.repo ?? null });
1351
+ else if (action === 'assign') result = await commands.runIssuesAssign(o.dir, { ...common, ref: words[0], assignee: words[1] ?? null, me: !!o.me, none: !!o.none });
1352
+ else if (action === 'label') result = await commands.runIssuesLabel(o.dir, { ...common, ref: words[0], priority: o.priority ?? null, type: o.type ?? null, add: o.add ?? [], remove: o.remove ?? [] });
1353
+ else if (action === 'edit') result = await commands.runIssuesEdit(o.dir, { ...common, ref: words[0], title: o.title ?? null, body: o.body ?? null, bodyFile: o['body-file'] ?? null });
1354
+ else if (action === 'comment') result = await commands.runIssuesComment(o.dir, { ...common, ref: words[0], body: o.body ?? null, bodyFile: o['body-file'] ?? null });
1355
+ else result = await (action === 'close' ? commands.runIssuesClose : commands.runIssuesReopen)(o.dir, { ...common, ref: words[0] });
1356
+ break;
1357
+ }
1358
+ const foreign = commands.issuesForeignFlags(process.argv.slice(2), action);
1359
+ if (foreign.length) { refuse(`yad issues ${action} does not take ${foreign.join(', ')}`, ISSUES_USAGE); break; }
1360
+ if (['show', 'link', 'unlink'].includes(action)) {
1361
+ const words = o._.slice(2);
1362
+ const want = action === 'show' ? 1 : 2;
1363
+ if (words.length !== want) { refuse(`yad issues ${action} takes ${action === 'show' ? '<ref>' : '<ref> <EP-id>'}`, ISSUES_USAGE); break; }
1364
+ result = action === 'show' ? await commands.runIssuesShow(o.dir, { ref: words[0], json: !!o.json })
1365
+ : await (action === 'link' ? commands.runIssuesLink : commands.runIssuesUnlink)(o.dir, { ref: words[0], epic: words[1], json: !!o.json });
1366
+ break;
1367
+ }
1368
+ if (o._[2]) { refuse(`yad issues ${action} takes no more words (got: ${o._[2]})`, ISSUES_USAGE); break; }
1369
+ if (action === 'sync') { result = await commands.runIssuesSync(o.dir, { dryRun: !!o.dryRun, json: !!o.json }); break; }
1370
+ if (action === 'labels') { result = await commands.runIssuesLabels(o.dir, { dryRun: !!o.dryRun, json: !!o.json }); break; }
1371
+ result = await commands.runIssuesList(o.dir, {
1372
+ priority: o.priority ?? null, type: o.type ?? null, status: o.status ?? null, label: o.label ?? [], assignee: o.assignee ?? null, me: !!o.me, repo: o.repo ?? null,
1373
+ since: o.since ?? null, until: o.until ?? null, date: o.date ?? null, sort: o.sort ?? null, closedSince: o['closed-since'] ?? null,
1374
+ format: o.format ?? null, out: o.out ?? null, json: !!o.json,
1375
+ });
1376
+ break;
1377
+ }
1378
+ case 'scan': {
1379
+ // E172. The yad-scan skill judges; this files.
1380
+ const action = o._[1];
1381
+ if (action !== 'file') { refuse(`unknown scan action: ${action ?? '(none)'} (file)`, 'usage: yad scan file <findings.json> --repo <name> [--task <id>] [--dry-run] [--json]'); break; }
1382
+ if (noProduct()) break;
1383
+ if (o._[3]) { refuse(`yad scan file takes one file (got also: ${o._[3]})`); break; }
1384
+ result = await commands.runScanFile(o.dir, { file: o._[2], repo: o.repo, task: o.task ?? null, dryRun: !!o.dryRun, json: !!o.json });
1385
+ break;
1386
+ }
1225
1387
  case 'standup': {
1226
1388
  // E132. Read-only; every flag that is not standup's own is refused, as history refuses them.
1227
1389
  const foreign = commands.standupForeignFlags(process.argv.slice(2));
@@ -1234,6 +1396,21 @@ async function main() {
1234
1396
  });
1235
1397
  break;
1236
1398
  }
1399
+ case 'map': {
1400
+ // E181. Read-only, except --fetch (download only) and the file --html writes.
1401
+ const MAP_OWN = new Set(['--open', '--html', '--live', '--anonymous', '--fetch', '--json', '--dir']);
1402
+ const foreign = [...new Set(process.argv.slice(2).filter((t) => /^--./.test(t) || /^-[A-Za-z]$/.test(t)).map((t) => t.split('=')[0]).filter((f) => !MAP_OWN.has(f)))];
1403
+ if (foreign.length) { refuse(`yad map does not take ${foreign.join(', ')}`, commands.MAP_USAGE); break; }
1404
+ if (noProduct()) break;
1405
+ result = await commands.runMap(o.dir, { args: o._.slice(1), html: !!o.html, open: !!o.open, live: !!o.live, anonymous: !!o.anonymous, fetch: !!o.fetch, json: !!o.json });
1406
+ break;
1407
+ }
1408
+ case 'reports': {
1409
+ // E180. The local reports folder; nothing here touches the Product or any repo.
1410
+ const [, action, ...args] = o._;
1411
+ result = await commands.runReports(o.dir, { action: action || 'list', args, olderThan: o['older-than'] ?? null, missing: !!o.missing, apply: !!o.apply, json: !!o.json });
1412
+ break;
1413
+ }
1237
1414
  case 'claims': {
1238
1415
  // E46. Read from the capture branches; nothing is recorded here.
1239
1416
  const [, epic, extra] = o._;
@@ -1299,6 +1476,18 @@ async function main() {
1299
1476
  });
1300
1477
  break;
1301
1478
  }
1479
+ case 'brain': {
1480
+ const [, action, ...args] = o._;
1481
+ // As history does: a flag brain does not take is refused, read from the raw arguments — `parseArgs`
1482
+ // turns an unknown flag into a plain word, which `query` would take as search text.
1483
+ const BRAIN_OWN = new Set(commands.BRAIN_FLAGS);
1484
+ const unknownFlags = [...new Set(process.argv.slice(2)
1485
+ .filter((t) => /^--./.test(t) || /^-[A-Za-z]$/.test(t))
1486
+ .map((t) => t.split('=')[0])
1487
+ .filter((f) => !BRAIN_OWN.has(f)))];
1488
+ result = await commands.runBrain(o.dir, { action: action || 'status', args, repo: o.repo ?? null, limit: o.limit ?? null, json: !!o.json, open: !!o.open, html: !!o.html, live: !!o.live, unknownFlags });
1489
+ break;
1490
+ }
1302
1491
  case 'repo': {
1303
1492
  const [, action, name] = o._;
1304
1493
  // `yad repo preview <name> [<pattern>]` (#359): the one action with a third word.
@@ -0,0 +1,13 @@
1
+ // The agent guard's decision, run in a worker thread by `yad hook agent-guard` (cli/hook.mjs, #498). The worker
2
+ // has a memory cap and a time limit: a line that would run the guard out of memory, or past its time, ends the
3
+ // worker, not the hook, and the hook refuses the line. A crashed hook exits with a code the harness reads as
4
+ // "no answer", and the command runs.
5
+ import { parentPort, workerData } from 'node:worker_threads';
6
+ import { agentGuardDecision, agentGuardPreapproval } from './agent-guard.mjs';
7
+
8
+ const { command, preapproval } = workerData;
9
+ // The verdict first: pre-approval (E167) reads the same line again, under the same limits, and when it runs out
10
+ // of time the verdict stands, only not pre-approved.
11
+ const verdict = agentGuardDecision(command);
12
+ parentPort.postMessage({ verdict });
13
+ if (verdict.allow && preapproval) parentPort.postMessage({ pre: agentGuardPreapproval(command, preapproval) });