@jaimevalasek/aioson 1.3.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 (288) hide show
  1. package/CHANGELOG.md +456 -0
  2. package/CODE_OF_CONDUCT.md +12 -0
  3. package/CONTRIBUTING.md +13 -0
  4. package/LICENSE +21 -0
  5. package/README.md +254 -0
  6. package/bin/aioson.js +4 -0
  7. package/docs/en/cli-reference.md +398 -0
  8. package/docs/en/i18n.md +52 -0
  9. package/docs/en/json-schemas.md +41 -0
  10. package/docs/en/mcp.md +56 -0
  11. package/docs/en/parallel.md +82 -0
  12. package/docs/en/qa-browser.md +339 -0
  13. package/docs/en/release-flow.md +22 -0
  14. package/docs/en/release-notes-template.md +41 -0
  15. package/docs/en/release.md +28 -0
  16. package/docs/en/schemas/agent-prompt.schema.json +17 -0
  17. package/docs/en/schemas/agents.schema.json +32 -0
  18. package/docs/en/schemas/context-validate.schema.json +36 -0
  19. package/docs/en/schemas/doctor.schema.json +89 -0
  20. package/docs/en/schemas/error.schema.json +24 -0
  21. package/docs/en/schemas/i18n-add.schema.json +15 -0
  22. package/docs/en/schemas/index.json +116 -0
  23. package/docs/en/schemas/info.schema.json +39 -0
  24. package/docs/en/schemas/init.schema.json +48 -0
  25. package/docs/en/schemas/install.schema.json +60 -0
  26. package/docs/en/schemas/locale-apply.schema.json +30 -0
  27. package/docs/en/schemas/mcp-doctor.schema.json +95 -0
  28. package/docs/en/schemas/mcp-init.schema.json +122 -0
  29. package/docs/en/schemas/package-test.schema.json +24 -0
  30. package/docs/en/schemas/parallel-assign.schema.json +57 -0
  31. package/docs/en/schemas/parallel-doctor.schema.json +86 -0
  32. package/docs/en/schemas/parallel-init.schema.json +53 -0
  33. package/docs/en/schemas/parallel-status.schema.json +94 -0
  34. package/docs/en/schemas/setup-context.schema.json +39 -0
  35. package/docs/en/schemas/smoke.schema.json +23 -0
  36. package/docs/en/schemas/update.schema.json +48 -0
  37. package/docs/en/schemas/workflow-plan.schema.json +30 -0
  38. package/docs/en/web3.md +54 -0
  39. package/docs/pt/README.md +46 -0
  40. package/docs/pt/advisor-spec.md +335 -0
  41. package/docs/pt/agentes.md +453 -0
  42. package/docs/pt/cenarios.md +1230 -0
  43. package/docs/pt/clientes-ai.md +224 -0
  44. package/docs/pt/comandos-cli.md +511 -0
  45. package/docs/pt/genome-3.0-spec.md +296 -0
  46. package/docs/pt/guia-engineer.md +226 -0
  47. package/docs/pt/inicio-rapido.md +138 -0
  48. package/docs/pt/profiler-system.md +214 -0
  49. package/docs/pt/runtime-observability.md +72 -0
  50. package/docs/pt/squad-genoma.md +777 -0
  51. package/docs/pt/web3.md +797 -0
  52. package/docs/testing/genome-2.0-manual-regression.md +23 -0
  53. package/docs/testing/genome-2.0-matrix.md +36 -0
  54. package/docs/testing/genome-2.0-rollout.md +184 -0
  55. package/package.json +50 -0
  56. package/src/agents.js +56 -0
  57. package/src/cli.js +497 -0
  58. package/src/commands/agents.js +142 -0
  59. package/src/commands/cloud.js +1767 -0
  60. package/src/commands/config.js +90 -0
  61. package/src/commands/context-validate.js +91 -0
  62. package/src/commands/doctor.js +123 -0
  63. package/src/commands/genome-doctor.js +41 -0
  64. package/src/commands/genome-migrate.js +49 -0
  65. package/src/commands/i18n-add.js +56 -0
  66. package/src/commands/info.js +41 -0
  67. package/src/commands/init.js +75 -0
  68. package/src/commands/install.js +68 -0
  69. package/src/commands/locale-apply.js +51 -0
  70. package/src/commands/locale-diff.js +126 -0
  71. package/src/commands/mcp-doctor.js +406 -0
  72. package/src/commands/mcp-init.js +379 -0
  73. package/src/commands/package-e2e.js +273 -0
  74. package/src/commands/parallel-assign.js +403 -0
  75. package/src/commands/parallel-doctor.js +437 -0
  76. package/src/commands/parallel-init.js +249 -0
  77. package/src/commands/parallel-status.js +290 -0
  78. package/src/commands/qa-doctor.js +185 -0
  79. package/src/commands/qa-init.js +161 -0
  80. package/src/commands/qa-report.js +58 -0
  81. package/src/commands/qa-run.js +873 -0
  82. package/src/commands/qa-scan.js +337 -0
  83. package/src/commands/runtime.js +948 -0
  84. package/src/commands/scan-project.js +1107 -0
  85. package/src/commands/setup-context.js +650 -0
  86. package/src/commands/smoke.js +426 -0
  87. package/src/commands/squad-doctor.js +358 -0
  88. package/src/commands/squad-export.js +46 -0
  89. package/src/commands/squad-pipeline.js +97 -0
  90. package/src/commands/squad-repair-genomes.js +39 -0
  91. package/src/commands/squad-status.js +424 -0
  92. package/src/commands/squad-validate.js +230 -0
  93. package/src/commands/test-agents.js +194 -0
  94. package/src/commands/update.js +55 -0
  95. package/src/commands/workflow-next.js +594 -0
  96. package/src/commands/workflow-plan.js +108 -0
  97. package/src/constants.js +314 -0
  98. package/src/context-parse-reason.js +22 -0
  99. package/src/context-writer.js +150 -0
  100. package/src/context.js +217 -0
  101. package/src/detector.js +261 -0
  102. package/src/doctor.js +289 -0
  103. package/src/execution-gateway.js +461 -0
  104. package/src/genome-files.js +198 -0
  105. package/src/genome-format.js +442 -0
  106. package/src/genome-schema.js +215 -0
  107. package/src/genomes/bindings.js +281 -0
  108. package/src/genomes.js +467 -0
  109. package/src/i18n/index.js +103 -0
  110. package/src/i18n/messages/en.js +784 -0
  111. package/src/i18n/messages/es.js +718 -0
  112. package/src/i18n/messages/fr.js +725 -0
  113. package/src/i18n/messages/pt-BR.js +818 -0
  114. package/src/i18n/scaffold.js +64 -0
  115. package/src/installer.js +232 -0
  116. package/src/lib/genomes/compat.js +206 -0
  117. package/src/lib/genomes/migrate.js +90 -0
  118. package/src/lib/squads/genome-repair.js +49 -0
  119. package/src/locales.js +84 -0
  120. package/src/onboarding.js +305 -0
  121. package/src/parser.js +53 -0
  122. package/src/prompt-tool.js +20 -0
  123. package/src/qa-html-report.js +472 -0
  124. package/src/runtime-store.js +1527 -0
  125. package/src/squads/apply-genome.js +21 -0
  126. package/src/squads/genome-binding-service.js +154 -0
  127. package/src/updater.js +32 -0
  128. package/src/utils.js +46 -0
  129. package/src/version.js +50 -0
  130. package/template/.aioson/advisors/.gitkeep +1 -0
  131. package/template/.aioson/agents/analyst.md +225 -0
  132. package/template/.aioson/agents/architect.md +221 -0
  133. package/template/.aioson/agents/dev.md +201 -0
  134. package/template/.aioson/agents/discovery-design-doc.md +196 -0
  135. package/template/.aioson/agents/genoma.md +300 -0
  136. package/template/.aioson/agents/orchestrator.md +107 -0
  137. package/template/.aioson/agents/pm.md +89 -0
  138. package/template/.aioson/agents/product.md +361 -0
  139. package/template/.aioson/agents/profiler-enricher.md +266 -0
  140. package/template/.aioson/agents/profiler-forge.md +188 -0
  141. package/template/.aioson/agents/profiler-researcher.md +245 -0
  142. package/template/.aioson/agents/qa.md +344 -0
  143. package/template/.aioson/agents/setup.md +381 -0
  144. package/template/.aioson/agents/squad.md +837 -0
  145. package/template/.aioson/agents/ux-ui.md +416 -0
  146. package/template/.aioson/config.md +56 -0
  147. package/template/.aioson/context/.gitkeep +0 -0
  148. package/template/.aioson/context/parallel/.gitkeep +0 -0
  149. package/template/.aioson/context/spec.md.template +37 -0
  150. package/template/.aioson/genomas/.gitkeep +0 -0
  151. package/template/.aioson/locales/en/agents/analyst.md +214 -0
  152. package/template/.aioson/locales/en/agents/architect.md +210 -0
  153. package/template/.aioson/locales/en/agents/dev.md +187 -0
  154. package/template/.aioson/locales/en/agents/discovery-design-doc.md +27 -0
  155. package/template/.aioson/locales/en/agents/genoma.md +212 -0
  156. package/template/.aioson/locales/en/agents/orchestrator.md +105 -0
  157. package/template/.aioson/locales/en/agents/pm.md +77 -0
  158. package/template/.aioson/locales/en/agents/product.md +310 -0
  159. package/template/.aioson/locales/en/agents/profiler-enricher.md +5 -0
  160. package/template/.aioson/locales/en/agents/profiler-forge.md +5 -0
  161. package/template/.aioson/locales/en/agents/profiler-researcher.md +5 -0
  162. package/template/.aioson/locales/en/agents/qa.md +214 -0
  163. package/template/.aioson/locales/en/agents/setup.md +342 -0
  164. package/template/.aioson/locales/en/agents/squad.md +247 -0
  165. package/template/.aioson/locales/en/agents/ux-ui.md +320 -0
  166. package/template/.aioson/locales/es/agents/analyst.md +203 -0
  167. package/template/.aioson/locales/es/agents/architect.md +208 -0
  168. package/template/.aioson/locales/es/agents/dev.md +183 -0
  169. package/template/.aioson/locales/es/agents/discovery-design-doc.md +19 -0
  170. package/template/.aioson/locales/es/agents/genoma.md +102 -0
  171. package/template/.aioson/locales/es/agents/orchestrator.md +108 -0
  172. package/template/.aioson/locales/es/agents/pm.md +81 -0
  173. package/template/.aioson/locales/es/agents/product.md +310 -0
  174. package/template/.aioson/locales/es/agents/profiler-enricher.md +5 -0
  175. package/template/.aioson/locales/es/agents/profiler-forge.md +5 -0
  176. package/template/.aioson/locales/es/agents/profiler-researcher.md +5 -0
  177. package/template/.aioson/locales/es/agents/qa.md +163 -0
  178. package/template/.aioson/locales/es/agents/setup.md +347 -0
  179. package/template/.aioson/locales/es/agents/squad.md +247 -0
  180. package/template/.aioson/locales/es/agents/ux-ui.md +201 -0
  181. package/template/.aioson/locales/fr/agents/analyst.md +203 -0
  182. package/template/.aioson/locales/fr/agents/architect.md +208 -0
  183. package/template/.aioson/locales/fr/agents/dev.md +183 -0
  184. package/template/.aioson/locales/fr/agents/discovery-design-doc.md +19 -0
  185. package/template/.aioson/locales/fr/agents/genoma.md +102 -0
  186. package/template/.aioson/locales/fr/agents/orchestrator.md +108 -0
  187. package/template/.aioson/locales/fr/agents/pm.md +81 -0
  188. package/template/.aioson/locales/fr/agents/product.md +310 -0
  189. package/template/.aioson/locales/fr/agents/profiler-enricher.md +5 -0
  190. package/template/.aioson/locales/fr/agents/profiler-forge.md +5 -0
  191. package/template/.aioson/locales/fr/agents/profiler-researcher.md +5 -0
  192. package/template/.aioson/locales/fr/agents/qa.md +163 -0
  193. package/template/.aioson/locales/fr/agents/setup.md +347 -0
  194. package/template/.aioson/locales/fr/agents/squad.md +247 -0
  195. package/template/.aioson/locales/fr/agents/ux-ui.md +201 -0
  196. package/template/.aioson/locales/pt-BR/agents/analyst.md +217 -0
  197. package/template/.aioson/locales/pt-BR/agents/architect.md +213 -0
  198. package/template/.aioson/locales/pt-BR/agents/dev.md +198 -0
  199. package/template/.aioson/locales/pt-BR/agents/discovery-design-doc.md +198 -0
  200. package/template/.aioson/locales/pt-BR/agents/genoma.md +297 -0
  201. package/template/.aioson/locales/pt-BR/agents/orchestrator.md +108 -0
  202. package/template/.aioson/locales/pt-BR/agents/pm.md +81 -0
  203. package/template/.aioson/locales/pt-BR/agents/product.md +316 -0
  204. package/template/.aioson/locales/pt-BR/agents/profiler-enricher.md +5 -0
  205. package/template/.aioson/locales/pt-BR/agents/profiler-forge.md +5 -0
  206. package/template/.aioson/locales/pt-BR/agents/profiler-researcher.md +5 -0
  207. package/template/.aioson/locales/pt-BR/agents/qa.md +217 -0
  208. package/template/.aioson/locales/pt-BR/agents/setup.md +371 -0
  209. package/template/.aioson/locales/pt-BR/agents/squad.md +772 -0
  210. package/template/.aioson/locales/pt-BR/agents/ux-ui.md +322 -0
  211. package/template/.aioson/mcp/servers.md +24 -0
  212. package/template/.aioson/profiler-reports/.gitkeep +1 -0
  213. package/template/.aioson/schemas/content-blueprint.schema.json +30 -0
  214. package/template/.aioson/schemas/genome-meta.schema.json +150 -0
  215. package/template/.aioson/schemas/genome.schema.json +115 -0
  216. package/template/.aioson/schemas/readiness.schema.json +27 -0
  217. package/template/.aioson/schemas/squad-blueprint.schema.json +172 -0
  218. package/template/.aioson/schemas/squad-manifest.schema.json +276 -0
  219. package/template/.aioson/skills/dynamic/README.md +30 -0
  220. package/template/.aioson/skills/dynamic/cardano-docs.md +16 -0
  221. package/template/.aioson/skills/dynamic/ethereum-docs.md +17 -0
  222. package/template/.aioson/skills/dynamic/flux-ui-docs.md +13 -0
  223. package/template/.aioson/skills/dynamic/laravel-docs.md +41 -0
  224. package/template/.aioson/skills/dynamic/npm-packages.md +16 -0
  225. package/template/.aioson/skills/dynamic/solana-docs.md +16 -0
  226. package/template/.aioson/skills/references/premium-command-center-ui/master-application-prompt.md +79 -0
  227. package/template/.aioson/skills/references/premium-command-center-ui/operational-ux-playbook.md +253 -0
  228. package/template/.aioson/skills/references/premium-command-center-ui/quality-validation-checklist.md +82 -0
  229. package/template/.aioson/skills/references/premium-command-center-ui/visual-system-and-component-patterns.md +270 -0
  230. package/template/.aioson/skills/static/django-patterns.md +342 -0
  231. package/template/.aioson/skills/static/fastapi-patterns.md +344 -0
  232. package/template/.aioson/skills/static/filament-patterns.md +267 -0
  233. package/template/.aioson/skills/static/flux-ui-components.md +262 -0
  234. package/template/.aioson/skills/static/git-conventions.md +227 -0
  235. package/template/.aioson/skills/static/interface-design.md +372 -0
  236. package/template/.aioson/skills/static/jetstream-setup.md +200 -0
  237. package/template/.aioson/skills/static/laravel-conventions.md +491 -0
  238. package/template/.aioson/skills/static/nextjs-patterns.md +321 -0
  239. package/template/.aioson/skills/static/node-express-patterns.md +317 -0
  240. package/template/.aioson/skills/static/node-typescript-patterns.md +282 -0
  241. package/template/.aioson/skills/static/premium-command-center-ui.md +190 -0
  242. package/template/.aioson/skills/static/rails-conventions.md +307 -0
  243. package/template/.aioson/skills/static/react-motion-patterns.md +577 -0
  244. package/template/.aioson/skills/static/static-html-patterns.md +1935 -0
  245. package/template/.aioson/skills/static/tall-stack-patterns.md +286 -0
  246. package/template/.aioson/skills/static/ui-ux-modern.md +75 -0
  247. package/template/.aioson/skills/static/web3-cardano-patterns.md +337 -0
  248. package/template/.aioson/skills/static/web3-ethereum-patterns.md +310 -0
  249. package/template/.aioson/skills/static/web3-security-checklist.md +284 -0
  250. package/template/.aioson/skills/static/web3-solana-patterns.md +324 -0
  251. package/template/.aioson/squads/.artisan/.gitkeep +0 -0
  252. package/template/.aioson/squads/.gitkeep +0 -0
  253. package/template/.aioson/squads/memory.md +5 -0
  254. package/template/.aioson/tasks/squad-analyze.md +83 -0
  255. package/template/.aioson/tasks/squad-create.md +99 -0
  256. package/template/.aioson/tasks/squad-design.md +100 -0
  257. package/template/.aioson/tasks/squad-export.md +20 -0
  258. package/template/.aioson/tasks/squad-extend.md +68 -0
  259. package/template/.aioson/tasks/squad-pipeline.md +122 -0
  260. package/template/.aioson/tasks/squad-repair.md +85 -0
  261. package/template/.aioson/tasks/squad-validate.md +58 -0
  262. package/template/.aioson/templates/squads/content-basic/template.json +21 -0
  263. package/template/.aioson/templates/squads/media-channel/template.json +24 -0
  264. package/template/.aioson/templates/squads/research-analysis/template.json +22 -0
  265. package/template/.aioson/templates/squads/software-delivery/template.json +21 -0
  266. package/template/.claude/commands/aioson/analyst.md +5 -0
  267. package/template/.claude/commands/aioson/architect.md +5 -0
  268. package/template/.claude/commands/aioson/dev.md +5 -0
  269. package/template/.claude/commands/aioson/orchestrator.md +5 -0
  270. package/template/.claude/commands/aioson/pm.md +5 -0
  271. package/template/.claude/commands/aioson/qa.md +5 -0
  272. package/template/.claude/commands/aioson/setup.md +5 -0
  273. package/template/.claude/commands/aioson/ux-ui.md +5 -0
  274. package/template/.gemini/GEMINI.md +10 -0
  275. package/template/.gemini/commands/aios-analyst.toml +4 -0
  276. package/template/.gemini/commands/aios-architect.toml +7 -0
  277. package/template/.gemini/commands/aios-dev.toml +8 -0
  278. package/template/.gemini/commands/aios-discovery-design-doc.toml +4 -0
  279. package/template/.gemini/commands/aios-orchestrator.toml +8 -0
  280. package/template/.gemini/commands/aios-pm.toml +8 -0
  281. package/template/.gemini/commands/aios-product.toml +4 -0
  282. package/template/.gemini/commands/aios-qa.toml +6 -0
  283. package/template/.gemini/commands/aios-setup.toml +3 -0
  284. package/template/.gemini/commands/aios-ux-ui.toml +8 -0
  285. package/template/AGENTS.md +67 -0
  286. package/template/CLAUDE.md +31 -0
  287. package/template/OPENCODE.md +24 -0
  288. package/template/aioson-models.json +40 -0
@@ -0,0 +1,379 @@
1
+ 'use strict';
2
+
3
+ const fs = require('node:fs/promises');
4
+ const path = require('node:path');
5
+ const { validateProjectContextFile } = require('../context');
6
+ const { createTranslator } = require('../i18n');
7
+ const { ensureDir, readTextIfExists } = require('../utils');
8
+
9
+ const TOOL_PRESET_DEFINITIONS = [
10
+ {
11
+ id: 'claude',
12
+ label: 'Claude Code',
13
+ suggestedTargetFile: '.mcp.json'
14
+ },
15
+ {
16
+ id: 'codex',
17
+ label: 'Codex CLI',
18
+ suggestedTargetFile: '.codex/mcp.json'
19
+ },
20
+ {
21
+ id: 'gemini',
22
+ label: 'Gemini CLI',
23
+ suggestedTargetFile: '.gemini/mcp.json'
24
+ },
25
+ {
26
+ id: 'opencode',
27
+ label: 'OpenCode',
28
+ suggestedTargetFile: '.opencode/mcp.json'
29
+ }
30
+ ];
31
+
32
+ function normalizeList(value) {
33
+ return String(value || '')
34
+ .split(',')
35
+ .map((item) => item.trim().toLowerCase())
36
+ .filter(Boolean);
37
+ }
38
+
39
+ function extractStackValue(markdown, fieldLabel) {
40
+ const text = String(markdown || '');
41
+ const regex = new RegExp(`^-\\s*${fieldLabel}:\\s*(.*)$`, 'im');
42
+ const match = text.match(regex);
43
+ if (!match) return '';
44
+ return String(match[1] || '').trim();
45
+ }
46
+
47
+ function normalizeDatabaseEngine(input) {
48
+ const value = String(input || '').trim().toLowerCase();
49
+ if (!value) return '';
50
+ if (
51
+ ['n/a', 'na', 'none', '-', '[not applicable]', 'not applicable'].includes(value)
52
+ ) {
53
+ return '';
54
+ }
55
+ if (value.includes('postgres') || value.includes('supabase')) return 'postgresql';
56
+ if (value.includes('mysql') || value.includes('planetscale')) return 'mysql';
57
+ if (value.includes('sqlite')) return 'sqlite';
58
+ if (value.includes('mongo')) return 'mongodb';
59
+ return value;
60
+ }
61
+
62
+ function inferWeb3Networks(contextData) {
63
+ const frontmatterNetworks = normalizeList(contextData.web3_networks);
64
+ if (frontmatterNetworks.length > 0) return frontmatterNetworks;
65
+
66
+ const framework = String(contextData.framework || '').toLowerCase();
67
+ if (['hardhat', 'foundry', 'truffle'].some((token) => framework.includes(token))) return ['ethereum'];
68
+ if (framework.includes('anchor') || framework.includes('solana')) return ['solana'];
69
+ if (framework.includes('cardano')) return ['cardano'];
70
+ return ['ethereum'];
71
+ }
72
+
73
+ function resolveTranslator(t) {
74
+ return typeof t === 'function' ? t : createTranslator('en').t;
75
+ }
76
+
77
+ function buildDatabaseServer(databaseEngine, t) {
78
+ const translate = resolveTranslator(t);
79
+ if (!databaseEngine) {
80
+ return {
81
+ id: 'database',
82
+ enabled: false,
83
+ recommended: false,
84
+ reason: translate('mcp_init.reason_database_none'),
85
+ engine: '',
86
+ env: []
87
+ };
88
+ }
89
+
90
+ return {
91
+ id: 'database',
92
+ enabled: true,
93
+ recommended: true,
94
+ reason: translate('mcp_init.reason_database_enabled'),
95
+ engine: databaseEngine,
96
+ env: ['DATABASE_MCP_URL']
97
+ };
98
+ }
99
+
100
+ function buildChainRpcServer(web3Enabled, networks, t) {
101
+ const translate = resolveTranslator(t);
102
+ if (!web3Enabled) {
103
+ return {
104
+ id: 'chain-rpc',
105
+ enabled: false,
106
+ recommended: false,
107
+ reason: translate('mcp_init.reason_chain_rpc_disabled'),
108
+ networks: [],
109
+ env: []
110
+ };
111
+ }
112
+
113
+ return {
114
+ id: 'chain-rpc',
115
+ enabled: true,
116
+ recommended: true,
117
+ reason: translate('mcp_init.reason_chain_rpc_enabled'),
118
+ networks,
119
+ env: ['RPC_URL', 'CHAIN_ID', 'PRIVATE_KEY']
120
+ };
121
+ }
122
+
123
+ function buildMcpPlan(targetDir, contextData, contextMarkdown, t) {
124
+ const translate = resolveTranslator(t);
125
+ const databaseValue = extractStackValue(contextMarkdown, 'Database');
126
+ const databaseEngine = normalizeDatabaseEngine(databaseValue);
127
+ const web3Enabled = Boolean(contextData.web3_enabled) || String(contextData.project_type) === 'dapp';
128
+ const networks = web3Enabled ? inferWeb3Networks(contextData) : [];
129
+
130
+ const servers = [
131
+ {
132
+ id: 'filesystem',
133
+ enabled: true,
134
+ recommended: true,
135
+ reason: translate('mcp_init.reason_filesystem'),
136
+ env: []
137
+ },
138
+ {
139
+ id: 'context7',
140
+ enabled: true,
141
+ recommended: true,
142
+ reason: translate('mcp_init.reason_context7'),
143
+ env: ['CONTEXT7_MCP_URL'],
144
+ optional_env: ['CONTEXT7_API_KEY']
145
+ },
146
+ buildDatabaseServer(databaseEngine, t),
147
+ {
148
+ id: 'web-search',
149
+ enabled: true,
150
+ recommended: true,
151
+ reason: translate('mcp_init.reason_web_search'),
152
+ env: []
153
+ },
154
+ buildChainRpcServer(web3Enabled, networks, t),
155
+ {
156
+ id: 'makopy',
157
+ enabled: false,
158
+ recommended: false,
159
+ reason: translate('mcp_init.reason_makopy'),
160
+ env: ['MAKOPY_API_KEY']
161
+ }
162
+ ];
163
+
164
+ return {
165
+ generated_at: new Date().toISOString(),
166
+ project: {
167
+ path: targetDir,
168
+ framework: contextData.framework || '',
169
+ project_type: contextData.project_type || '',
170
+ conversation_language: contextData.conversation_language || 'en'
171
+ },
172
+ database_engine: databaseEngine,
173
+ web3_enabled: web3Enabled,
174
+ web3_networks: networks,
175
+ servers
176
+ };
177
+ }
178
+
179
+ function envTemplate(keys) {
180
+ const output = {};
181
+ for (const key of keys || []) {
182
+ output[key] = `$${key}`;
183
+ }
184
+ return output;
185
+ }
186
+
187
+ function mergeEnvKeys(server) {
188
+ const required = Array.isArray(server && server.env) ? server.env : [];
189
+ const optional = Array.isArray(server && server.optional_env) ? server.optional_env : [];
190
+ return Array.from(new Set([...required, ...optional]));
191
+ }
192
+
193
+ function serverTemplate(server) {
194
+ if (server.id === 'filesystem') {
195
+ return {
196
+ transport: 'stdio',
197
+ command: '<filesystem-mcp-command>',
198
+ args: ['<project-root>'],
199
+ env: {}
200
+ };
201
+ }
202
+
203
+ if (server.id === 'context7') {
204
+ return {
205
+ transport: 'stdio',
206
+ command: 'npx',
207
+ args: ['-y', 'mcp-remote', '$CONTEXT7_MCP_URL'],
208
+ env: envTemplate(mergeEnvKeys(server))
209
+ };
210
+ }
211
+
212
+ if (server.id === 'database') {
213
+ const env = envTemplate(mergeEnvKeys(server));
214
+ env.DATABASE_ENGINE = server.engine || '<engine>';
215
+ return {
216
+ transport: 'stdio',
217
+ command: 'npx',
218
+ args: ['-y', 'mcp-remote', '$DATABASE_MCP_URL'],
219
+ env
220
+ };
221
+ }
222
+
223
+ if (server.id === 'chain-rpc') {
224
+ return {
225
+ transport: 'stdio',
226
+ command: '<chain-rpc-mcp-command>',
227
+ args: server.networks || [],
228
+ env: envTemplate(server.env)
229
+ };
230
+ }
231
+
232
+ return {
233
+ transport: 'stdio',
234
+ command: `<${server.id}-mcp-command>`,
235
+ args: [],
236
+ env: envTemplate(server.env)
237
+ };
238
+ }
239
+
240
+ function normalizeTool(tool) {
241
+ const value = String(tool || '').trim().toLowerCase();
242
+ if (!value) return '';
243
+ return value;
244
+ }
245
+
246
+ function resolveToolDefinitions(tool, t) {
247
+ const normalized = normalizeTool(tool);
248
+ if (!normalized) return TOOL_PRESET_DEFINITIONS;
249
+
250
+ const found = TOOL_PRESET_DEFINITIONS.find((item) => item.id === normalized);
251
+ if (!found) {
252
+ const expected = TOOL_PRESET_DEFINITIONS.map((item) => item.id).join(', ');
253
+ const translate = resolveTranslator(t);
254
+ throw new Error(
255
+ translate('mcp_init.invalid_tool', {
256
+ tool: String(tool || ''),
257
+ expected
258
+ })
259
+ );
260
+ }
261
+ return [found];
262
+ }
263
+
264
+ function buildToolPresets(plan, options = {}) {
265
+ const selectedTools = resolveToolDefinitions(options.tool, options.t);
266
+ const enabledServers = plan.servers.filter((server) => server.enabled);
267
+ const translate = resolveTranslator(options.t);
268
+
269
+ return selectedTools.map((tool) => {
270
+ const mcpServers = {};
271
+ for (const server of enabledServers) {
272
+ mcpServers[server.id] = serverTemplate(server);
273
+ }
274
+
275
+ const envRequired = Array.from(
276
+ new Set(
277
+ enabledServers.flatMap((server) => server.env || [])
278
+ )
279
+ );
280
+
281
+ return {
282
+ tool: tool.id,
283
+ tool_label: tool.label,
284
+ generated_at: new Date().toISOString(),
285
+ source_plan: '.aioson/mcp/servers.local.json',
286
+ suggested_target_file: tool.suggestedTargetFile,
287
+ notes: [
288
+ translate('mcp_init.note_workspace_local'),
289
+ translate('mcp_init.note_replace_placeholders'),
290
+ translate('mcp_init.note_keep_secrets_env')
291
+ ],
292
+ env_required: envRequired,
293
+ mcpServers
294
+ };
295
+ });
296
+ }
297
+
298
+ async function runMcpInit({ args, options = {}, logger, t }) {
299
+ const targetDir = path.resolve(process.cwd(), args[0] || '.');
300
+ const dryRun = Boolean(options['dry-run']);
301
+ const jsonMode = Boolean(options.json);
302
+ const requestedTool = normalizeTool(options.tool);
303
+ const contextResult = await validateProjectContextFile(targetDir);
304
+ const contextMarkdown = await readTextIfExists(
305
+ path.join(targetDir, '.aioson/context/project.context.md')
306
+ );
307
+ const contextData = contextResult.parsed && contextResult.data ? contextResult.data : {};
308
+
309
+ const plan = buildMcpPlan(targetDir, contextData, contextMarkdown || '', t);
310
+ const filePath = path.join(targetDir, '.aioson/mcp/servers.local.json');
311
+ const presets = buildToolPresets(plan, { tool: requestedTool, t });
312
+ const presetDir = path.join(targetDir, '.aioson/mcp/presets');
313
+ const presetFiles = presets.map((preset) => ({
314
+ tool: preset.tool,
315
+ path: path.join(presetDir, `${preset.tool}.json`)
316
+ }));
317
+
318
+ if (!dryRun) {
319
+ await ensureDir(path.dirname(filePath));
320
+ await fs.writeFile(filePath, `${JSON.stringify(plan, null, 2)}\n`, 'utf8');
321
+
322
+ await ensureDir(presetDir);
323
+ for (const presetFile of presetFiles) {
324
+ const preset = presets.find((item) => item.tool === presetFile.tool);
325
+ await fs.writeFile(presetFile.path, `${JSON.stringify(preset, null, 2)}\n`, 'utf8');
326
+ }
327
+ }
328
+
329
+ const output = {
330
+ ok: true,
331
+ targetDir,
332
+ filePath,
333
+ dryRun,
334
+ written: !dryRun,
335
+ contextExists: contextResult.exists,
336
+ contextParsed: contextResult.parsed,
337
+ serverCount: plan.servers.length,
338
+ presetCount: presets.length,
339
+ presetFiles: presetFiles.map((item) => ({
340
+ tool: item.tool,
341
+ path: item.path
342
+ })),
343
+ plan,
344
+ presets
345
+ };
346
+
347
+ if (jsonMode) {
348
+ return output;
349
+ }
350
+
351
+ if (!contextResult.exists) {
352
+ logger.log(t('mcp_init.context_missing'));
353
+ }
354
+ logger.log(
355
+ dryRun
356
+ ? t('mcp_init.dry_run_generated', { path: filePath })
357
+ : t('mcp_init.generated', { path: filePath })
358
+ );
359
+ logger.log(t('mcp_init.server_count', { count: plan.servers.length }));
360
+ logger.log(t('mcp_init.preset_count', { count: presets.length }));
361
+ for (const presetFile of output.presetFiles) {
362
+ logger.log(
363
+ dryRun
364
+ ? t('mcp_init.preset_dry_run', { tool: presetFile.tool, path: presetFile.path })
365
+ : t('mcp_init.preset_written', { tool: presetFile.tool, path: presetFile.path })
366
+ );
367
+ }
368
+
369
+ return output;
370
+ }
371
+
372
+ module.exports = {
373
+ runMcpInit,
374
+ normalizeDatabaseEngine,
375
+ extractStackValue,
376
+ buildMcpPlan,
377
+ buildToolPresets,
378
+ resolveToolDefinitions
379
+ };
@@ -0,0 +1,273 @@
1
+ 'use strict';
2
+
3
+ const fs = require('node:fs/promises');
4
+ const os = require('node:os');
5
+ const path = require('node:path');
6
+ const { spawn } = require('node:child_process');
7
+ const { ensureDir } = require('../utils');
8
+
9
+ function toArg(value) {
10
+ return typeof value === 'string' ? value : String(value);
11
+ }
12
+
13
+ function commandFailureDetail(result, t) {
14
+ const stderr = String((result && result.stderr) || '').trim();
15
+ const stdout = String((result && result.stdout) || '').trim();
16
+ return stderr || stdout || t('package_test.error_unknown_detail');
17
+ }
18
+
19
+ async function runCommand(cmd, args, options = {}) {
20
+ const cwd = options.cwd || process.cwd();
21
+ const env = { ...process.env, ...(options.env || {}) };
22
+ return new Promise((resolve, reject) => {
23
+ const child = spawn(cmd, args.map((arg) => toArg(arg)), {
24
+ cwd,
25
+ env
26
+ });
27
+
28
+ let stdout = '';
29
+ let stderr = '';
30
+
31
+ child.stdout.on('data', (chunk) => {
32
+ stdout += String(chunk);
33
+ });
34
+ child.stderr.on('data', (chunk) => {
35
+ stderr += String(chunk);
36
+ });
37
+ child.on('error', reject);
38
+ child.on('close', (code) => {
39
+ resolve({
40
+ code: Number(code || 0),
41
+ stdout,
42
+ stderr
43
+ });
44
+ });
45
+ });
46
+ }
47
+
48
+ function parsePackResult(stdout) {
49
+ const lines = String(stdout || '')
50
+ .split(/\r?\n/)
51
+ .map((line) => line.trim())
52
+ .filter(Boolean);
53
+ if (lines.length === 0) return '';
54
+ return lines[lines.length - 1];
55
+ }
56
+
57
+ async function resolveTarballFromDir(packDir) {
58
+ const files = await fs.readdir(packDir);
59
+ const tgz = files.filter((file) => file.endsWith('.tgz'));
60
+ if (tgz.length === 0) return '';
61
+
62
+ let latestName = '';
63
+ let latestTime = -1;
64
+ for (const file of tgz) {
65
+ const stat = await fs.stat(path.join(packDir, file));
66
+ if (stat.mtimeMs >= latestTime) {
67
+ latestTime = stat.mtimeMs;
68
+ latestName = file;
69
+ }
70
+ }
71
+ return latestName;
72
+ }
73
+
74
+ async function runPackageTest({ args, options = {}, logger, t }) {
75
+ const sourceDir = path.resolve(process.cwd(), args[0] || '.');
76
+ const keep = Boolean(options.keep);
77
+ const dryRun = Boolean(options['dry-run']);
78
+ const jsonMode = Boolean(options.json);
79
+
80
+ const workspaceRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'aioson-package-test-'));
81
+ const projectName = 'sample-app';
82
+ const projectDir = path.join(workspaceRoot, projectName);
83
+ const packDir = path.join(workspaceRoot, 'dist');
84
+ const npmCacheDir = path.join(workspaceRoot, '.npm-cache');
85
+ await ensureDir(packDir);
86
+ await ensureDir(npmCacheDir);
87
+
88
+ const steps = [];
89
+ let tarballName = '';
90
+ let tarballPath = '';
91
+ let doctorResult = null;
92
+ let mcpResult = null;
93
+
94
+ try {
95
+ if (dryRun) {
96
+ steps.push('dry-run:plan-only');
97
+ return {
98
+ ok: true,
99
+ dryRun: true,
100
+ keep,
101
+ sourceDir,
102
+ workspaceRoot,
103
+ projectDir,
104
+ steps
105
+ };
106
+ }
107
+
108
+ const pack = await runCommand('npm', ['pack', '--silent', '--pack-destination', packDir], {
109
+ cwd: sourceDir,
110
+ env: {
111
+ NPM_CONFIG_CACHE: npmCacheDir,
112
+ npm_config_cache: npmCacheDir
113
+ }
114
+ });
115
+ if (pack.code !== 0) {
116
+ throw new Error(
117
+ t('package_test.error_npm_pack', {
118
+ detail: commandFailureDetail(pack, t)
119
+ })
120
+ );
121
+ }
122
+ tarballName = parsePackResult(pack.stdout);
123
+ if (!tarballName) {
124
+ tarballName = await resolveTarballFromDir(packDir);
125
+ }
126
+ if (!tarballName) {
127
+ throw new Error(t('package_test.error_tarball_missing'));
128
+ }
129
+ tarballPath = path.join(packDir, tarballName);
130
+ steps.push('pack');
131
+
132
+ const init = await runCommand(
133
+ 'npx',
134
+ ['--yes', '--package', tarballPath, 'aioson', 'init', projectName, '--locale=en'],
135
+ {
136
+ cwd: workspaceRoot,
137
+ env: {
138
+ NPM_CONFIG_CACHE: npmCacheDir,
139
+ npm_config_cache: npmCacheDir
140
+ }
141
+ }
142
+ );
143
+ if (init.code !== 0) {
144
+ throw new Error(
145
+ t('package_test.error_npx_init', {
146
+ detail: commandFailureDetail(init, t)
147
+ })
148
+ );
149
+ }
150
+ steps.push('npx:init');
151
+
152
+ const setup = await runCommand(
153
+ 'npx',
154
+ [
155
+ '--yes',
156
+ '--package',
157
+ tarballPath,
158
+ 'aioson',
159
+ 'setup:context',
160
+ projectDir,
161
+ '--defaults',
162
+ '--project-name=sample-app',
163
+ '--project-type=web_app',
164
+ '--profile=developer',
165
+ '--framework=Node/Express',
166
+ '--framework-installed=true',
167
+ '--language=en',
168
+ '--backend-choice=4',
169
+ '--database-choice=3'
170
+ ],
171
+ {
172
+ cwd: workspaceRoot,
173
+ env: {
174
+ NPM_CONFIG_CACHE: npmCacheDir,
175
+ npm_config_cache: npmCacheDir
176
+ }
177
+ }
178
+ );
179
+ if (setup.code !== 0) {
180
+ throw new Error(
181
+ t('package_test.error_npx_setup_context', {
182
+ detail: commandFailureDetail(setup, t)
183
+ })
184
+ );
185
+ }
186
+ steps.push('npx:setup-context');
187
+
188
+ const doctor = await runCommand(
189
+ 'npx',
190
+ ['--yes', '--package', tarballPath, 'aioson', 'doctor', projectDir, '--json'],
191
+ {
192
+ cwd: workspaceRoot,
193
+ env: {
194
+ NPM_CONFIG_CACHE: npmCacheDir,
195
+ npm_config_cache: npmCacheDir
196
+ }
197
+ }
198
+ );
199
+ if (doctor.code !== 0) {
200
+ throw new Error(
201
+ t('package_test.error_npx_doctor', {
202
+ detail: commandFailureDetail(doctor, t)
203
+ })
204
+ );
205
+ }
206
+ doctorResult = JSON.parse(doctor.stdout);
207
+ if (!doctorResult.ok) {
208
+ throw new Error(t('package_test.error_doctor_not_ok'));
209
+ }
210
+ steps.push('npx:doctor');
211
+
212
+ const mcp = await runCommand(
213
+ 'npx',
214
+ ['--yes', '--package', tarballPath, 'aioson', 'mcp:init', projectDir, '--json'],
215
+ {
216
+ cwd: workspaceRoot,
217
+ env: {
218
+ NPM_CONFIG_CACHE: npmCacheDir,
219
+ npm_config_cache: npmCacheDir
220
+ }
221
+ }
222
+ );
223
+ if (mcp.code !== 0) {
224
+ throw new Error(
225
+ t('package_test.error_npx_mcp_init', {
226
+ detail: commandFailureDetail(mcp, t)
227
+ })
228
+ );
229
+ }
230
+ mcpResult = JSON.parse(mcp.stdout);
231
+ if (!mcpResult.ok) {
232
+ throw new Error(t('package_test.error_mcp_not_ok'));
233
+ }
234
+ steps.push('npx:mcp-init');
235
+
236
+ const output = {
237
+ ok: true,
238
+ dryRun: false,
239
+ keep,
240
+ sourceDir,
241
+ workspaceRoot,
242
+ projectDir,
243
+ tarballName,
244
+ tarballPath,
245
+ steps,
246
+ doctorOk: doctorResult.ok,
247
+ mcpServerCount: mcpResult.serverCount
248
+ };
249
+
250
+ if (jsonMode) {
251
+ return output;
252
+ }
253
+
254
+ logger.log(t('package_test.start', { sourceDir }));
255
+ logger.log(t('package_test.pack_done', { tarball: tarballName }));
256
+ logger.log(t('package_test.completed', { count: steps.length }));
257
+ logger.log(t('package_test.workspace', { path: workspaceRoot }));
258
+
259
+ return output;
260
+ } finally {
261
+ if (!keep && !dryRun) {
262
+ await fs.rm(workspaceRoot, { recursive: true, force: true });
263
+ }
264
+ }
265
+ }
266
+
267
+ module.exports = {
268
+ runPackageTest,
269
+ runCommand,
270
+ commandFailureDetail,
271
+ parsePackResult,
272
+ resolveTarballFromDir
273
+ };