bmad-plus 0.12.1 → 0.13.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 (176) hide show
  1. package/CHANGELOG.md +637 -580
  2. package/README.md +123 -120
  3. package/osint-agent-package/agents/osint-investigator.md +12 -0
  4. package/osint-agent-package/skills/bmad-osint-investigate/osint/SKILL.md +491 -482
  5. package/osint-agent-package/skills/bmad-osint-investigate/osint/assets/dossier-template.md +126 -126
  6. package/osint-agent-package/skills/bmad-osint-investigate/osint/assets/lawful-basis-record.md +48 -48
  7. package/osint-agent-package/skills/bmad-osint-investigate/osint/references/content-extraction.md +100 -100
  8. package/osint-agent-package/skills/bmad-osint-investigate/osint/references/gdpr-osint.md +48 -48
  9. package/osint-agent-package/skills/bmad-osint-investigate/osint/references/platforms.md +130 -130
  10. package/osint-agent-package/skills/bmad-osint-investigate/osint/references/psychoprofile.md +69 -69
  11. package/osint-agent-package/skills/bmad-osint-investigate/osint/references/tools.md +281 -281
  12. package/osint-agent-package/skills/bmad-osint-investigate/osint/scripts/mcp-client.py +136 -136
  13. package/package.json +106 -91
  14. package/readme-international/README.de.md +625 -594
  15. package/readme-international/README.es.md +642 -611
  16. package/readme-international/README.fr.md +640 -609
  17. package/src/bmad-plus/agents/agent-orchestrator/SKILL.md +2 -0
  18. package/src/bmad-plus/agents/agent-shadow/SKILL.md +18 -0
  19. package/src/bmad-plus/data/role-triggers.yaml +52 -0
  20. package/src/bmad-plus/module.yaml +333 -283
  21. package/src/bmad-plus/packs/pack-animated/animated-website-agent.md +325 -325
  22. package/src/bmad-plus/packs/pack-animated/templates/animated-website-workflow.md +55 -55
  23. package/src/bmad-plus/packs/pack-backup/backup-agent.md +71 -71
  24. package/src/bmad-plus/packs/pack-backup/templates/backup-workflow.md +51 -51
  25. package/src/bmad-plus/packs/pack-dev-studio/README.md +162 -162
  26. package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/analyst-agent.md +73 -73
  27. package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/document-project.md +61 -61
  28. package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/domain-research.md +95 -95
  29. package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/market-research.md +95 -95
  30. package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/prfaq.md +134 -134
  31. package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/product-brief.md +80 -80
  32. package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/tech-writer-agent.md +73 -73
  33. package/src/bmad-plus/packs/pack-dev-studio/categories/analysis/technical-research.md +95 -95
  34. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/architect-agent.md +73 -73
  35. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/create-architecture.md +73 -73
  36. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/create-epics-stories.md +92 -92
  37. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/generate-project-context.md +80 -80
  38. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/implementation-readiness.md +90 -90
  39. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-01-init.md +153 -153
  40. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-01b-continue.md +173 -173
  41. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-02-context.md +224 -224
  42. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-03-starter.md +329 -329
  43. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-04-decisions.md +318 -318
  44. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-05-patterns.md +359 -359
  45. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-06-structure.md +379 -379
  46. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-07-validation.md +361 -361
  47. package/src/bmad-plus/packs/pack-dev-studio/categories/architecture/steps/step-08-complete.md +81 -81
  48. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/checkpoint-preview.md +67 -67
  49. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/code-review-steps/step-01-gather-context.md +85 -85
  50. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/code-review-steps/step-02-review.md +35 -35
  51. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/code-review-steps/step-03-triage.md +49 -49
  52. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/code-review-steps/step-04-present.md +131 -131
  53. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/code-review.md +89 -89
  54. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/correct-course.md +300 -300
  55. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/create-story.md +428 -428
  56. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/dev-agent.md +73 -73
  57. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/dev-story-checklist.md +80 -80
  58. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/dev-story.md +484 -484
  59. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/investigate.md +193 -193
  60. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/qa-e2e-tests.md +175 -175
  61. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/quick-dev.md +110 -110
  62. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/retrospective.md +1511 -1511
  63. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/sprint-planning.md +298 -298
  64. package/src/bmad-plus/packs/pack-dev-studio/categories/implementation/sprint-status.md +296 -296
  65. package/src/bmad-plus/packs/pack-dev-studio/categories/planning/create-prd.md +29 -29
  66. package/src/bmad-plus/packs/pack-dev-studio/categories/planning/create-ux-design.md +74 -74
  67. package/src/bmad-plus/packs/pack-dev-studio/categories/planning/edit-prd.md +29 -29
  68. package/src/bmad-plus/packs/pack-dev-studio/categories/planning/pm-agent.md +73 -73
  69. package/src/bmad-plus/packs/pack-dev-studio/categories/planning/prd.md +89 -89
  70. package/src/bmad-plus/packs/pack-dev-studio/categories/planning/ux-designer-agent.md +73 -73
  71. package/src/bmad-plus/packs/pack-dev-studio/categories/planning/validate-prd.md +29 -29
  72. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/advanced-elicitation.md +141 -141
  73. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/adversarial-review.md +37 -37
  74. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/bmad-help.md +75 -75
  75. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/brainstorming.md +6 -6
  76. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/customize.md +110 -110
  77. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/distillator.md +176 -176
  78. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/edge-case-hunter.md +67 -67
  79. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/editorial-review-prose.md +86 -86
  80. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/editorial-review-structure.md +179 -179
  81. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/index-docs.md +66 -66
  82. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/party-mode.md +127 -127
  83. package/src/bmad-plus/packs/pack-dev-studio/categories/utilities/shard-doc.md +105 -105
  84. package/src/bmad-plus/packs/pack-dev-studio/dev-studio-orchestrator.md +120 -120
  85. package/src/bmad-plus/packs/pack-dev-studio/shared/architecture-decision-template.md +12 -12
  86. package/src/bmad-plus/packs/pack-dev-studio/shared/bwml-spec.md +328 -328
  87. package/src/bmad-plus/packs/pack-dev-studio/shared/module-help.csv +32 -32
  88. package/src/bmad-plus/packs/pack-dev-studio/upstream-sync.yaml +81 -81
  89. package/src/bmad-plus/packs/pack-seo/SKILL.md +171 -171
  90. package/src/bmad-plus/packs/pack-seo/checklist.md +140 -140
  91. package/src/bmad-plus/packs/pack-seo/pagespeed-playbook.md +320 -320
  92. package/src/bmad-plus/packs/pack-seo/ref/audit-schema.json +187 -187
  93. package/src/bmad-plus/packs/pack-seo/ref/cwv-thresholds.md +87 -87
  94. package/src/bmad-plus/packs/pack-seo/ref/eeat-criteria.md +123 -123
  95. package/src/bmad-plus/packs/pack-seo/ref/geo-signals.md +167 -167
  96. package/src/bmad-plus/packs/pack-seo/ref/hreflang-rules.md +153 -153
  97. package/src/bmad-plus/packs/pack-seo/ref/quality-gates.md +133 -133
  98. package/src/bmad-plus/packs/pack-seo/ref/schema-catalog.md +91 -91
  99. package/src/bmad-plus/packs/pack-seo/ref/schema-templates.json +356 -356
  100. package/src/bmad-plus/packs/pack-seo/requirements.txt +17 -0
  101. package/src/bmad-plus/packs/pack-seo/scripts/seo_apis.py +456 -0
  102. package/src/bmad-plus/packs/pack-seo/scripts/seo_crawl.py +359 -0
  103. package/src/bmad-plus/packs/pack-seo/scripts/seo_fetch.py +303 -0
  104. package/src/bmad-plus/packs/pack-seo/scripts/seo_parse.py +255 -0
  105. package/src/bmad-plus/packs/pack-seo/scripts/seo_report.py +409 -0
  106. package/src/bmad-plus/packs/pack-seo/scripts/seo_screenshot.py +202 -0
  107. package/src/bmad-plus/packs/pack-seo/seo-chief.md +294 -294
  108. package/src/bmad-plus/packs/pack-seo/seo-judge.md +241 -241
  109. package/src/bmad-plus/packs/pack-seo/seo-scout.md +171 -171
  110. package/src/bmad-plus/packs/pack-seo/templates/seo-audit-workflow.md +241 -241
  111. package/src/bmad-plus/packs/pack-shield/README.md +6 -6
  112. package/src/bmad-plus/packs/pack-shield/SKILL.md +2 -2
  113. package/src/bmad-plus/packs/pack-shield/categories/accessibility-esg/csrd-agent.md +11 -11
  114. package/src/bmad-plus/packs/pack-shield/categories/accessibility-esg/section508-agent.md +11 -11
  115. package/src/bmad-plus/packs/pack-shield/categories/accessibility-esg/wcag-agent.md +11 -11
  116. package/src/bmad-plus/packs/pack-shield/categories/ai-governance/eu-ai-act-agent.md +11 -11
  117. package/src/bmad-plus/packs/pack-shield/categories/ai-governance/iso42001-agent.md +11 -11
  118. package/src/bmad-plus/packs/pack-shield/categories/ai-governance/nist-ai-rmf-agent.md +11 -11
  119. package/src/bmad-plus/packs/pack-shield/categories/cybersecurity/cis-controls-agent.md +11 -11
  120. package/src/bmad-plus/packs/pack-shield/categories/cybersecurity/ism-agent.md +11 -11
  121. package/src/bmad-plus/packs/pack-shield/categories/cybersecurity/iso27001-agent.md +11 -11
  122. package/src/bmad-plus/packs/pack-shield/categories/cybersecurity/nis2-agent.md +11 -11
  123. package/src/bmad-plus/packs/pack-shield/categories/cybersecurity/nist-800-53-agent.md +11 -11
  124. package/src/bmad-plus/packs/pack-shield/categories/cybersecurity/nist-csf-agent.md +11 -11
  125. package/src/bmad-plus/packs/pack-shield/categories/defense-export/cmmc-agent.md +11 -11
  126. package/src/bmad-plus/packs/pack-shield/categories/defense-export/ear-agent.md +11 -11
  127. package/src/bmad-plus/packs/pack-shield/categories/defense-export/itar-agent.md +11 -11
  128. package/src/bmad-plus/packs/pack-shield/categories/defense-export/tsa-agent.md +11 -11
  129. package/src/bmad-plus/packs/pack-shield/categories/industry-compliance/dora-agent.md +11 -11
  130. package/src/bmad-plus/packs/pack-shield/categories/industry-compliance/fedramp-agent.md +11 -11
  131. package/src/bmad-plus/packs/pack-shield/categories/industry-compliance/hipaa-agent.md +11 -11
  132. package/src/bmad-plus/packs/pack-shield/categories/industry-compliance/pci-dss-agent.md +11 -11
  133. package/src/bmad-plus/packs/pack-shield/categories/industry-compliance/soc2-agent.md +11 -11
  134. package/src/bmad-plus/packs/pack-shield/categories/industry-compliance/swift-csp-agent.md +11 -11
  135. package/src/bmad-plus/packs/pack-shield/shield-orchestrator.md +1 -1
  136. package/src/bmad-plus/skills/bmad-plus-autopilot/SKILL.md +1 -1
  137. package/tools/bmad-plus-npx.js +4 -2
  138. package/tools/build/adapters.config.js +60 -51
  139. package/tools/build/check-counts.js +626 -0
  140. package/tools/build/check-install-contract.js +298 -0
  141. package/tools/build/generate-adapters.js +252 -56
  142. package/tools/build/generate.js +187 -10
  143. package/tools/build/generated-adapters/.codex/AGENTS.md +20 -7
  144. package/tools/build/generated-adapters/.cursor/rules/bmad-plus.mdc +20 -7
  145. package/tools/build/generated-adapters/.opencode/AGENTS.md +20 -7
  146. package/tools/build/generated-adapters/AGENTS.md +20 -7
  147. package/tools/build/generated-adapters/CLAUDE.md +20 -7
  148. package/tools/build/generated-adapters/CONVENTIONS.md +20 -7
  149. package/tools/build/generated-adapters/GEMINI.md +20 -7
  150. package/tools/build/module.template.yaml +82 -0
  151. package/tools/cli/bmad-plus-cli.js +16 -1
  152. package/tools/cli/commands/autoconfig.js +470 -470
  153. package/tools/cli/commands/doctor.js +205 -233
  154. package/tools/cli/commands/install.js +543 -501
  155. package/tools/cli/commands/memory-journal-cmd.js +311 -311
  156. package/tools/cli/commands/memory.js +195 -195
  157. package/tools/cli/commands/scan.js +348 -348
  158. package/tools/cli/commands/uninstall.js +209 -101
  159. package/tools/cli/commands/update-check.js +31 -0
  160. package/tools/cli/commands/update-policy.js +39 -0
  161. package/tools/cli/commands/update.js +123 -134
  162. package/tools/cli/i18n.js +905 -845
  163. package/tools/cli/lib/README-memory-journal.md +125 -125
  164. package/tools/cli/lib/ide-config.js +10 -259
  165. package/tools/cli/lib/install-manifest.js +17 -0
  166. package/tools/cli/lib/installed-adapters.js +89 -0
  167. package/tools/cli/lib/npm-runner.js +177 -0
  168. package/tools/cli/lib/pack-copy.js +62 -66
  169. package/tools/cli/lib/packs.js +437 -3
  170. package/tools/cli/lib/python-provision.js +508 -508
  171. package/tools/cli/lib/stack-detect.js +102 -102
  172. package/tools/cli/lib/update-check.js +153 -0
  173. package/tools/cli/lib/update-dispatch.js +182 -0
  174. package/tools/cli/lib/update-policy.js +90 -0
  175. package/tools/cli/lib/update-transaction.js +334 -0
  176. package/tools/cli/lib/validate.js +50 -50
@@ -0,0 +1,177 @@
1
+ /** Run npm through Node with bounded output and no shell interpolation. */
2
+ const fs = require('node:fs');
3
+ const path = require('node:path');
4
+ const childProcess = require('node:child_process');
5
+
6
+ function resolveNpmCli({
7
+ env = process.env,
8
+ execPath = process.execPath,
9
+ platform = process.platform,
10
+ realpath = fs.realpathSync,
11
+ isFile = (file) => fs.statSync(file).isFile(),
12
+ } = {}) {
13
+ const paths = platform === 'win32' ? path.win32 : path.posix;
14
+ const searchPath = Object.entries(env).find(([key]) => key.toLowerCase() === 'path')?.[1] || '';
15
+ const directories = searchPath.split(platform === 'win32' ? ';' : ':').filter(Boolean);
16
+ const nodeDir = paths.dirname(execPath);
17
+ const candidates = [
18
+ env.npm_execpath,
19
+ paths.join(nodeDir, 'node_modules', 'npm', 'bin', 'npm-cli.js'),
20
+ paths.resolve(nodeDir, '..', 'lib', 'node_modules', 'npm', 'bin', 'npm-cli.js'),
21
+ ...directories.flatMap((dir) => [
22
+ paths.join(dir, 'npm'),
23
+ paths.join(dir, 'node_modules', 'npm', 'bin', 'npm-cli.js'),
24
+ ]),
25
+ ];
26
+ for (const candidate of candidates) {
27
+ if (!candidate) continue;
28
+ try {
29
+ const resolved = realpath(candidate);
30
+ if (paths.basename(resolved).toLowerCase() === 'npm-cli.js' && isFile(resolved))
31
+ return resolved;
32
+ } catch {
33
+ /* Try the next standard npm installation location. */
34
+ }
35
+ }
36
+ throw new Error('npm-cli.js was not found. Install Node.js with npm or repair its PATH.');
37
+ }
38
+
39
+ /** Injectable process boundary; tests never need to fetch a package. */
40
+ function createNpmRunner({
41
+ spawn = childProcess.spawn,
42
+ resolveCli = resolveNpmCli,
43
+ platform = process.platform,
44
+ execPath = process.execPath,
45
+ kill = process.kill.bind(process),
46
+ } = {}) {
47
+ return async function runNpm(
48
+ args,
49
+ { cwd, timeout = 6000, env = process.env, maxBuffer = 1024 * 1024, signal } = {}
50
+ ) {
51
+ if (!Array.isArray(args) || args.some((arg) => typeof arg !== 'string' || arg.includes('\0'))) {
52
+ throw new Error('npm arguments must be an array of strings without NUL bytes.');
53
+ }
54
+ if (
55
+ !Number.isSafeInteger(timeout) ||
56
+ timeout <= 0 ||
57
+ !Number.isSafeInteger(maxBuffer) ||
58
+ maxBuffer <= 0
59
+ ) {
60
+ throw new Error('npm timeout and maxBuffer must be positive integers.');
61
+ }
62
+ if (signal?.aborted)
63
+ throw Object.assign(new Error('npm operation was cancelled.'), { code: 'ABORT_ERR' });
64
+ const cli = resolveCli({ env, execPath, platform });
65
+
66
+ return new Promise((resolve, reject) => {
67
+ let child;
68
+ try {
69
+ child = spawn(execPath, [cli, ...args], {
70
+ cwd,
71
+ env,
72
+ shell: false,
73
+ windowsHide: true,
74
+ detached: platform !== 'win32',
75
+ stdio: ['ignore', 'pipe', 'pipe'],
76
+ });
77
+ } catch (error) {
78
+ reject(new Error('Could not start npm.', { cause: error }));
79
+ return;
80
+ }
81
+ let settled = false;
82
+ let bytes = 0;
83
+ const stdout = [];
84
+ const stderr = [];
85
+ let timer;
86
+ const finish = (error, output) => {
87
+ if (settled) return;
88
+ settled = true;
89
+ clearTimeout(timer);
90
+ signal?.removeEventListener('abort', abort);
91
+ if (error) {
92
+ error.stdout = Buffer.concat(stdout).toString('utf8');
93
+ error.stderr = Buffer.concat(stderr).toString('utf8');
94
+ const diagnostic = [error.stdout.trim(), error.stderr.trim()].filter(Boolean).join('\n');
95
+ if (diagnostic) error.message += '\n' + diagnostic;
96
+ reject(error);
97
+ } else resolve(output);
98
+ };
99
+ const killChild = () => {
100
+ try {
101
+ child.kill('SIGKILL');
102
+ } catch {
103
+ /* The process may already have exited. */
104
+ }
105
+ };
106
+ const stop = () => {
107
+ if (!Number.isInteger(child.pid) || child.pid <= 0) return killChild();
108
+ if (platform !== 'win32') {
109
+ // A detached npm owns this process group, including its updater child.
110
+ try {
111
+ kill(-child.pid, 'SIGKILL');
112
+ } catch {
113
+ killChild();
114
+ }
115
+ return;
116
+ }
117
+ try {
118
+ const terminator = spawn('taskkill.exe', ['/pid', String(child.pid), '/t', '/f'], {
119
+ shell: false,
120
+ windowsHide: true,
121
+ stdio: 'ignore',
122
+ env,
123
+ });
124
+ terminator.once('error', killChild);
125
+ terminator.once('close', (code) => {
126
+ if (code !== 0) killChild();
127
+ });
128
+ } catch {
129
+ killChild();
130
+ }
131
+ };
132
+ const cancel = (message, code) => {
133
+ if (settled) return;
134
+ stop();
135
+ finish(Object.assign(new Error(message), { code }));
136
+ };
137
+ const abort = () =>
138
+ cancel('npm operation was cancelled; child termination requested.', 'ABORT_ERR');
139
+ const collect = (chunk, save) => {
140
+ if (settled) return;
141
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
142
+ bytes += buffer.length;
143
+ if (bytes > maxBuffer)
144
+ return cancel('npm output exceeded the configured buffer limit.', 'ENOBUFS');
145
+ (save ? stdout : stderr).push(buffer);
146
+ };
147
+ child.stdout.on('data', (chunk) => collect(chunk, true));
148
+ child.stderr.on('data', (chunk) => collect(chunk, false));
149
+ child.once('error', (error) => finish(new Error('Could not run npm.', { cause: error })));
150
+ child.once('close', (code, exitSignal) => {
151
+ if (code !== 0 || exitSignal) {
152
+ finish(
153
+ Object.assign(new Error(`npm exited unsuccessfully (${exitSignal || code}).`), {
154
+ code: 'NPM_EXIT',
155
+ exitCode: code,
156
+ signal: exitSignal,
157
+ })
158
+ );
159
+ } else finish(null, Buffer.concat(stdout).toString('utf8'));
160
+ });
161
+ timer = setTimeout(
162
+ () =>
163
+ cancel(
164
+ `npm exceeded its ${timeout} ms deadline; child termination requested.`,
165
+ 'ETIMEDOUT'
166
+ ),
167
+ timeout
168
+ );
169
+ timer.unref?.();
170
+ signal?.addEventListener('abort', abort, { once: true });
171
+ if (signal?.aborted) abort();
172
+ });
173
+ };
174
+ }
175
+
176
+ const runNpm = createNpmRunner();
177
+ module.exports = { runNpm, resolveNpmCli, createNpmRunner };
@@ -1,84 +1,80 @@
1
1
  /**
2
- * BMAD+ Shared Pack-Copy Module
3
- * Extracted duplicate file-copy loops from install.js and update.js.
4
- *
2
+ * Shared deterministic pack enumeration and conservative installation copying.
5
3
  * Author: Laurent Rochetta
6
4
  */
7
-
8
5
  const path = require('node:path');
9
6
  const fs = require('node:fs');
10
- const fsExtra = require('fs-extra');
11
-
12
- /**
13
- * Copy files for a single pack definition into the target directories.
14
- *
15
- * @param {object} opts
16
- * @param {string} opts.bmadSrc - Path to src/bmad-plus/
17
- * @param {string} opts.targetAgentsDir - Destination for agents / skills
18
- * @param {string} opts.targetDataDir - Destination for data files
19
- * @param {string} opts.projectRoot - Project root (for external package resolution)
20
- * @param {object} opts.pack - Pack definition from PACKS
21
- * @returns {{ copiedAgents: number, copiedSkills: number, copiedFiles: number }}
22
- */
23
- function copyPackFiles({ bmadSrc, targetAgentsDir, targetDataDir, projectRoot, pack }) {
24
- let copiedAgents = 0;
25
- let copiedSkills = 0;
26
- let copiedFiles = 0;
7
+ const crypto = require('node:crypto');
8
+ const { safeTarget } = require('../../build/generate-adapters');
27
9
 
28
- if (!pack) return { copiedAgents, copiedSkills, copiedFiles };
10
+ const fileHash = content => crypto.createHash('sha256').update(content).digest('hex');
29
11
 
30
- // Copy agents
31
- for (const agent of (pack.agents || [])) {
32
- const src = path.join(bmadSrc, 'agents', agent);
33
- const dest = path.join(targetAgentsDir, agent);
34
- if (fs.existsSync(src)) {
35
- fsExtra.copySync(src, dest, { overwrite: true });
36
- copiedAgents++;
12
+ function listPackFiles({ bmadSrc, targetAgentsDir, targetDataDir, projectRoot, pack }) {
13
+ const result = { copiedAgents: 0, copiedSkills: 0, copiedFiles: 0, files: [] };
14
+ if (!pack) return result;
15
+ function walk(source, target) {
16
+ let stat;
17
+ try { stat = fs.lstatSync(source); } catch (error) {
18
+ if (error.code === 'ENOENT') return false;
19
+ throw error;
37
20
  }
21
+ if (stat.isSymbolicLink()) throw new Error('Pack source is a symbolic link: ' + source);
22
+ if (stat.isDirectory()) {
23
+ for (const name of fs.readdirSync(source).sort()) walk(path.join(source, name), path.join(target, name));
24
+ } else if (stat.isFile()) {
25
+ result.files.push({ source, target });
26
+ } else throw new Error('Pack source is not a regular file: ' + source);
27
+ return true;
38
28
  }
39
-
40
- // Copy skills
41
- for (const skill of (pack.skills || [])) {
42
- const src = path.join(bmadSrc, 'skills', skill);
43
- const dest = path.join(targetAgentsDir, skill);
44
- if (fs.existsSync(src)) {
45
- fsExtra.copySync(src, dest, { overwrite: true });
46
- copiedSkills++;
47
- }
29
+ for (const name of pack.agents || []) {
30
+ if (walk(path.join(bmadSrc, 'agents', name), path.join(targetAgentsDir, name))) result.copiedAgents++;
48
31
  }
49
-
50
- // Copy data files
51
- for (const dataFile of (pack.data || [])) {
52
- const src = path.join(bmadSrc, 'data', dataFile);
53
- const dest = path.join(targetDataDir, dataFile);
54
- if (fs.existsSync(src)) {
55
- fsExtra.copySync(src, dest, { overwrite: true });
56
- copiedFiles++;
57
- }
32
+ for (const name of pack.skills || []) {
33
+ if (walk(path.join(bmadSrc, 'skills', name), path.join(targetAgentsDir, name))) result.copiedSkills++;
58
34
  }
59
-
60
- // Copy external package (e.g. OSINT)
61
- if (pack.externalPackage) {
62
- const extSrc = path.join(projectRoot, pack.externalPackage, 'skills');
63
- if (fs.existsSync(extSrc)) {
64
- fsExtra.copySync(extSrc, targetAgentsDir, { overwrite: true });
65
- copiedSkills++;
66
- }
35
+ for (const name of pack.data || []) {
36
+ if (walk(path.join(bmadSrc, 'data', name), path.join(targetDataDir, name))) result.copiedFiles++;
37
+ }
38
+ if (pack.externalPackage && walk(path.join(projectRoot, pack.externalPackage, 'skills'), targetAgentsDir)) result.copiedSkills++;
39
+ if (pack.packDir && walk(path.join(bmadSrc, pack.packSrcDir || 'agents', pack.packDir), path.join(targetAgentsDir, pack.packDir))) {
40
+ result.copiedAgents++;
41
+ result.copiedFiles++;
67
42
  }
43
+ return result;
44
+ }
68
45
 
69
- // Copy pack directory (SEO, Backup, Animated, Shield, etc.)
70
- if (pack.packDir) {
71
- const srcParent = pack.packSrcDir || 'agents';
72
- const packSrc = path.join(bmadSrc, srcParent, pack.packDir);
73
- const packDest = path.join(targetAgentsDir, pack.packDir);
74
- if (fs.existsSync(packSrc)) {
75
- fsExtra.copySync(packSrc, packDest, { overwrite: true });
76
- copiedAgents++;
77
- copiedFiles++;
46
+ function copyManagedFile({ source, target, projectDir, inventory, previousInventory = {}, onConflict = () => {} }) {
47
+ const file = path.relative(projectDir, target).split(path.sep).join('/');
48
+ safeTarget(projectDir, file);
49
+ const sourceStat = fs.lstatSync(source);
50
+ if (!sourceStat.isFile() || sourceStat.isSymbolicLink()) throw new Error('Pack source is not a regular file: ' + source);
51
+ const content = fs.readFileSync(source);
52
+ const hash = fileHash(content);
53
+ if (fs.existsSync(target)) {
54
+ const existingHash = fileHash(fs.readFileSync(target));
55
+ if (existingHash === hash) {
56
+ if (inventory) inventory[file] = hash;
57
+ return false;
58
+ }
59
+ if (previousInventory[file] !== existingHash) {
60
+ if (inventory && previousInventory[file]) inventory[file] = previousInventory[file];
61
+ onConflict(file);
62
+ return false;
78
63
  }
79
64
  }
65
+ fs.mkdirSync(path.dirname(target), { recursive: true });
66
+ safeTarget(projectDir, file);
67
+ fs.writeFileSync(target, content, { mode: sourceStat.mode });
68
+ if (inventory) inventory[file] = hash;
69
+ return true;
70
+ }
80
71
 
81
- return { copiedAgents, copiedSkills, copiedFiles };
72
+ function copyPackFiles(options) {
73
+ const { files, ...counts } = listPackFiles(options);
74
+ const projectDir = options.projectDir || path.dirname(options.targetAgentsDir);
75
+ for (const { target } of files) safeTarget(projectDir, path.relative(projectDir, target).split(path.sep).join('/'));
76
+ for (const entry of files) copyManagedFile({ ...options, ...entry, projectDir });
77
+ return counts;
82
78
  }
83
79
 
84
- module.exports = { copyPackFiles };
80
+ module.exports = { copyPackFiles, listPackFiles, copyManagedFile, fileHash };