@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,126 @@
1
+ 'use strict';
2
+
3
+ const fs = require('node:fs/promises');
4
+ const path = require('node:path');
5
+ const { TEMPLATE_DIR } = require('../installer');
6
+
7
+ const AGENTS = ['setup', 'analyst', 'architect', 'pm', 'ux-ui', 'dev', 'qa', 'orchestrator'];
8
+ const LOCALES = ['en', 'pt-BR', 'es', 'fr'];
9
+
10
+ // Extract ## Section headings from markdown content
11
+ function extractSections(content) {
12
+ const sections = [];
13
+ for (const line of content.split('\n')) {
14
+ if (/^#{1,3} /.test(line)) {
15
+ sections.push(line.trim());
16
+ }
17
+ }
18
+ return sections;
19
+ }
20
+
21
+ // Normalize a heading to a comparable key (remove locale-specific punctuation/accents)
22
+ function normalizeHeading(heading) {
23
+ return heading
24
+ .toLowerCase()
25
+ .replace(/[áàâãä]/g, 'a')
26
+ .replace(/[éèêë]/g, 'e')
27
+ .replace(/[íìîï]/g, 'i')
28
+ .replace(/[óòôõö]/g, 'o')
29
+ .replace(/[úùûü]/g, 'u')
30
+ .replace(/[ç]/g, 'c')
31
+ .replace(/[ñ]/g, 'n')
32
+ .replace(/[^a-z0-9# ]/g, '')
33
+ .replace(/\s+/g, ' ')
34
+ .trim();
35
+ }
36
+
37
+ async function readFile(filePath) {
38
+ try {
39
+ return await fs.readFile(filePath, 'utf8');
40
+ } catch {
41
+ return null;
42
+ }
43
+ }
44
+
45
+ async function runLocaleDiff({ args, options, logger }) {
46
+ const jsonMode = Boolean(options.json);
47
+ const log = jsonMode ? () => {} : logger.log.bind(logger);
48
+
49
+ const filterAgent = args[0] || null; // optional: check only one agent
50
+ const filterLocale = options.lang || options.language || null;
51
+
52
+ const baseAgentsDir = path.join(TEMPLATE_DIR, '.aioson', 'agents');
53
+ const localesDir = path.join(TEMPLATE_DIR, '.aioson', 'locales');
54
+
55
+ const agentsToCheck = filterAgent
56
+ ? AGENTS.filter(a => a === filterAgent)
57
+ : AGENTS;
58
+ const localesToCheck = filterLocale
59
+ ? LOCALES.filter(l => l === filterLocale)
60
+ : LOCALES;
61
+
62
+ const report = [];
63
+ let totalMissing = 0;
64
+
65
+ for (const agent of agentsToCheck) {
66
+ const baseFile = path.join(baseAgentsDir, `${agent}.md`);
67
+ const baseContent = await readFile(baseFile);
68
+ if (!baseContent) {
69
+ log(`WARN: base agent @${agent} not found`);
70
+ continue;
71
+ }
72
+
73
+ const baseSections = extractSections(baseContent);
74
+ const baseNorm = baseSections.map(s => ({ original: s, key: normalizeHeading(s) }));
75
+
76
+ for (const locale of localesToCheck) {
77
+ const localeFile = path.join(localesDir, locale, 'agents', `${agent}.md`);
78
+ const localeContent = await readFile(localeFile);
79
+ if (!localeContent) {
80
+ log(`WARN: @${agent} (${locale}) not found`);
81
+ continue;
82
+ }
83
+
84
+ const localeSections = extractSections(localeContent);
85
+ const localeNormSet = new Set(localeSections.map(s => normalizeHeading(s)));
86
+
87
+ const missing = baseNorm.filter(({ key }) => !localeNormSet.has(key));
88
+
89
+ if (missing.length > 0) {
90
+ totalMissing += missing.length;
91
+ const entry = {
92
+ agent,
93
+ locale,
94
+ missingSections: missing.map(m => m.original)
95
+ };
96
+ report.push(entry);
97
+ if (!jsonMode) {
98
+ log(`@${agent} (${locale}) — ${missing.length} section(s) missing in locale:`);
99
+ for (const m of missing) {
100
+ log(` - ${m.original}`);
101
+ }
102
+ }
103
+ }
104
+ }
105
+ }
106
+
107
+ if (!jsonMode) {
108
+ log('');
109
+ if (totalMissing === 0) {
110
+ log('No drift detected — all locale files contain equivalent sections to base.');
111
+ } else {
112
+ log(`${totalMissing} section(s) present in base but missing in locale files.`);
113
+ log('These may be intentional simplifications or unintentional drift.');
114
+ }
115
+ }
116
+
117
+ return {
118
+ ok: totalMissing === 0,
119
+ totalMissing,
120
+ agents: agentsToCheck,
121
+ locales: localesToCheck,
122
+ drifts: report
123
+ };
124
+ }
125
+
126
+ module.exports = { runLocaleDiff };
@@ -0,0 +1,406 @@
1
+ 'use strict';
2
+
3
+ const fs = require('node:fs/promises');
4
+ const path = require('node:path');
5
+ const { validateProjectContextFile } = require('../context');
6
+ const { localizeContextParseReason } = require('../context-parse-reason');
7
+ const { exists, readTextIfExists } = require('../utils');
8
+ const { extractStackValue, normalizeDatabaseEngine } = require('./mcp-init');
9
+
10
+ const REQUIRED_CORE_SERVERS = ['filesystem', 'context7'];
11
+ const TOOL_PRESETS = ['claude', 'codex', 'gemini', 'opencode'];
12
+
13
+ function normalizeBoolean(value, fallback = false) {
14
+ if (typeof value === 'boolean') return value;
15
+ if (value === undefined || value === null) return fallback;
16
+ const text = String(value).trim().toLowerCase();
17
+ if (['1', 'true', 'yes', 'y', 'on'].includes(text)) return true;
18
+ if (['0', 'false', 'no', 'n', 'off'].includes(text)) return false;
19
+ return fallback;
20
+ }
21
+
22
+ function makeCheck(id, ok, severity, message, hint = '') {
23
+ return {
24
+ id,
25
+ ok: Boolean(ok),
26
+ severity,
27
+ message: String(message || ''),
28
+ hint: String(hint || '')
29
+ };
30
+ }
31
+
32
+ function uniqueStrings(values) {
33
+ return Array.from(new Set((values || []).filter(Boolean).map((value) => String(value))));
34
+ }
35
+
36
+ async function readJsonFileIfExists(filePath) {
37
+ if (!(await exists(filePath))) {
38
+ return {
39
+ exists: false,
40
+ parsed: false,
41
+ data: null,
42
+ error: ''
43
+ };
44
+ }
45
+
46
+ const raw = await fs.readFile(filePath, 'utf8');
47
+ try {
48
+ return {
49
+ exists: true,
50
+ parsed: true,
51
+ data: JSON.parse(raw),
52
+ error: ''
53
+ };
54
+ } catch (error) {
55
+ return {
56
+ exists: true,
57
+ parsed: false,
58
+ data: null,
59
+ error: error.message
60
+ };
61
+ }
62
+ }
63
+
64
+ function summarizeChecks(checks) {
65
+ const passed = checks.filter((item) => item.ok).length;
66
+ const failed = checks.filter((item) => !item.ok && item.severity === 'error').length;
67
+ const warnings = checks.filter((item) => !item.ok && item.severity === 'warn').length;
68
+ return {
69
+ total: checks.length,
70
+ passed,
71
+ failed,
72
+ warnings
73
+ };
74
+ }
75
+
76
+ function buildServerMap(plan) {
77
+ const servers = Array.isArray(plan && plan.servers) ? plan.servers : [];
78
+ const map = new Map();
79
+ for (const server of servers) {
80
+ const id = String(server && server.id ? server.id : '').trim();
81
+ if (!id) continue;
82
+ map.set(id, server);
83
+ }
84
+ return map;
85
+ }
86
+
87
+ function isWeb3Context(contextData) {
88
+ if (!contextData || typeof contextData !== 'object') return false;
89
+ return Boolean(contextData.web3_enabled) || String(contextData.project_type) === 'dapp';
90
+ }
91
+
92
+ function formatCheckPrefix(check, t) {
93
+ if (check.ok) return t('mcp_doctor.prefix_ok');
94
+ if (check.severity === 'warn') return t('mcp_doctor.prefix_warn');
95
+ return t('mcp_doctor.prefix_fail');
96
+ }
97
+
98
+ async function runMcpDoctor({ args, options = {}, logger, t }) {
99
+ const targetDir = path.resolve(process.cwd(), args[0] || '.');
100
+ const strictEnv = normalizeBoolean(options['strict-env'], false);
101
+ const planPath = path.join(targetDir, '.aioson/mcp/servers.local.json');
102
+ const presetsDir = path.join(targetDir, '.aioson/mcp/presets');
103
+ const contextPath = path.join(targetDir, '.aioson/context/project.context.md');
104
+
105
+ const checks = [];
106
+
107
+ const contextResult = await validateProjectContextFile(targetDir);
108
+ const contextMarkdown = (await readTextIfExists(contextPath)) || '';
109
+ const contextData = contextResult.parsed && contextResult.data ? contextResult.data : {};
110
+
111
+ if (!contextResult.exists) {
112
+ checks.push(
113
+ makeCheck(
114
+ 'context.exists',
115
+ false,
116
+ 'warn',
117
+ t('mcp_doctor.context_missing'),
118
+ t('mcp_doctor.context_missing_hint')
119
+ )
120
+ );
121
+ } else if (!contextResult.parsed) {
122
+ checks.push(
123
+ makeCheck(
124
+ 'context.parsed',
125
+ false,
126
+ 'warn',
127
+ t('mcp_doctor.context_parse_invalid', {
128
+ reason: localizeContextParseReason(contextResult.parseError, t)
129
+ }),
130
+ t('mcp_doctor.context_parse_invalid_hint')
131
+ )
132
+ );
133
+ } else {
134
+ checks.push(
135
+ makeCheck(
136
+ 'context.parsed',
137
+ true,
138
+ 'info',
139
+ t('mcp_doctor.context_ok')
140
+ )
141
+ );
142
+ }
143
+
144
+ const planFile = await readJsonFileIfExists(planPath);
145
+ if (!planFile.exists) {
146
+ checks.push(
147
+ makeCheck(
148
+ 'plan.exists',
149
+ false,
150
+ 'error',
151
+ t('mcp_doctor.plan_missing'),
152
+ t('mcp_doctor.plan_missing_hint')
153
+ )
154
+ );
155
+ } else if (!planFile.parsed) {
156
+ checks.push(
157
+ makeCheck(
158
+ 'plan.parsed',
159
+ false,
160
+ 'error',
161
+ t('mcp_doctor.plan_invalid', { error: planFile.error }),
162
+ t('mcp_doctor.plan_invalid_hint')
163
+ )
164
+ );
165
+ } else {
166
+ checks.push(
167
+ makeCheck(
168
+ 'plan.parsed',
169
+ true,
170
+ 'info',
171
+ t('mcp_doctor.plan_ok')
172
+ )
173
+ );
174
+ }
175
+
176
+ const plan = planFile.parsed && planFile.data ? planFile.data : {};
177
+ const serverMap = buildServerMap(plan);
178
+ const enabledServers = Array.from(serverMap.values()).filter((server) => server.enabled);
179
+
180
+ if (planFile.parsed) {
181
+ checks.push(
182
+ makeCheck(
183
+ 'plan.servers',
184
+ serverMap.size > 0,
185
+ 'error',
186
+ serverMap.size > 0
187
+ ? t('mcp_doctor.plan_servers_ok', { count: serverMap.size })
188
+ : t('mcp_doctor.plan_servers_missing'),
189
+ serverMap.size > 0 ? '' : t('mcp_doctor.plan_servers_hint')
190
+ )
191
+ );
192
+
193
+ for (const serverId of REQUIRED_CORE_SERVERS) {
194
+ const server = serverMap.get(serverId);
195
+ const ok = Boolean(server && server.enabled === true);
196
+ checks.push(
197
+ makeCheck(
198
+ `plan.core.${serverId}`,
199
+ ok,
200
+ 'error',
201
+ ok
202
+ ? t('mcp_doctor.core_enabled', { server: serverId })
203
+ : t('mcp_doctor.core_missing', { server: serverId }),
204
+ ok ? '' : t('mcp_doctor.core_missing_hint')
205
+ )
206
+ );
207
+ }
208
+ }
209
+
210
+ const presetChecks = [];
211
+ for (const tool of TOOL_PRESETS) {
212
+ const presetPath = path.join(presetsDir, `${tool}.json`);
213
+ const present = await exists(presetPath);
214
+ presetChecks.push({
215
+ tool,
216
+ path: presetPath,
217
+ exists: present
218
+ });
219
+ }
220
+
221
+ const existingPresetCount = presetChecks.filter((item) => item.exists).length;
222
+ checks.push(
223
+ makeCheck(
224
+ 'presets.any',
225
+ existingPresetCount > 0,
226
+ 'error',
227
+ existingPresetCount > 0
228
+ ? t('mcp_doctor.presets_any_ok', { count: existingPresetCount })
229
+ : t('mcp_doctor.presets_any_missing'),
230
+ existingPresetCount > 0 ? '' : t('mcp_doctor.presets_any_hint')
231
+ )
232
+ );
233
+
234
+ if (existingPresetCount > 0 && existingPresetCount < TOOL_PRESETS.length) {
235
+ checks.push(
236
+ makeCheck(
237
+ 'presets.coverage',
238
+ false,
239
+ 'warn',
240
+ t('mcp_doctor.presets_coverage_partial', {
241
+ existing: existingPresetCount,
242
+ total: TOOL_PRESETS.length
243
+ }),
244
+ t('mcp_doctor.presets_coverage_partial_hint')
245
+ )
246
+ );
247
+ } else if (existingPresetCount === TOOL_PRESETS.length) {
248
+ checks.push(
249
+ makeCheck(
250
+ 'presets.coverage',
251
+ true,
252
+ 'info',
253
+ t('mcp_doctor.presets_coverage_full')
254
+ )
255
+ );
256
+ }
257
+
258
+ const requiredEnv = uniqueStrings(enabledServers.flatMap((server) => server.env || []));
259
+ const missingEnv = requiredEnv.filter((key) => !process.env[key]);
260
+ const envSeverity = strictEnv ? 'error' : 'warn';
261
+ if (requiredEnv.length === 0) {
262
+ checks.push(
263
+ makeCheck(
264
+ 'env.required',
265
+ true,
266
+ 'info',
267
+ t('mcp_doctor.env_none_required')
268
+ )
269
+ );
270
+ } else if (missingEnv.length > 0) {
271
+ checks.push(
272
+ makeCheck(
273
+ 'env.required',
274
+ false,
275
+ envSeverity,
276
+ t('mcp_doctor.env_missing', {
277
+ missing: missingEnv.length,
278
+ total: requiredEnv.length,
279
+ vars: missingEnv.join(', ')
280
+ }),
281
+ strictEnv
282
+ ? t('mcp_doctor.env_missing_hint_strict')
283
+ : t('mcp_doctor.env_missing_hint_relaxed')
284
+ )
285
+ );
286
+ } else {
287
+ checks.push(
288
+ makeCheck(
289
+ 'env.required',
290
+ true,
291
+ 'info',
292
+ t('mcp_doctor.env_all_present', { count: requiredEnv.length })
293
+ )
294
+ );
295
+ }
296
+
297
+ if (contextResult.parsed && planFile.parsed) {
298
+ const stackDatabase = normalizeDatabaseEngine(extractStackValue(contextMarkdown, 'Database'));
299
+ if (stackDatabase) {
300
+ const databaseServer = serverMap.get('database');
301
+ const actualEngine = String(databaseServer && databaseServer.engine ? databaseServer.engine : '');
302
+ const matches = Boolean(databaseServer && databaseServer.enabled && actualEngine === stackDatabase);
303
+ checks.push(
304
+ makeCheck(
305
+ 'compat.database',
306
+ matches,
307
+ matches ? 'info' : 'warn',
308
+ matches
309
+ ? t('mcp_doctor.compat_database_ok', { engine: stackDatabase })
310
+ : t('mcp_doctor.compat_database_mismatch', { engine: stackDatabase }),
311
+ matches
312
+ ? ''
313
+ : t('mcp_doctor.compat_database_hint')
314
+ )
315
+ );
316
+ }
317
+
318
+ const web3Enabled = isWeb3Context(contextData);
319
+ const chainRpcServer = serverMap.get('chain-rpc');
320
+ if (web3Enabled) {
321
+ const chainOk = Boolean(chainRpcServer && chainRpcServer.enabled);
322
+ checks.push(
323
+ makeCheck(
324
+ 'compat.web3',
325
+ chainOk,
326
+ 'error',
327
+ chainOk
328
+ ? t('mcp_doctor.compat_web3_ok')
329
+ : t('mcp_doctor.compat_web3_missing'),
330
+ chainOk ? '' : t('mcp_doctor.compat_web3_missing_hint')
331
+ )
332
+ );
333
+ } else if (chainRpcServer && chainRpcServer.enabled) {
334
+ checks.push(
335
+ makeCheck(
336
+ 'compat.web3',
337
+ false,
338
+ 'warn',
339
+ t('mcp_doctor.compat_web3_unneeded'),
340
+ t('mcp_doctor.compat_web3_unneeded_hint')
341
+ )
342
+ );
343
+ }
344
+ }
345
+
346
+ const summary = summarizeChecks(checks);
347
+ const output = {
348
+ ok: summary.failed === 0,
349
+ targetDir,
350
+ strictEnv,
351
+ context: {
352
+ exists: contextResult.exists,
353
+ parsed: contextResult.parsed,
354
+ filePath: contextPath,
355
+ projectType: String(contextData.project_type || ''),
356
+ framework: String(contextData.framework || ''),
357
+ conversationLanguage: String(contextData.conversation_language || '')
358
+ },
359
+ plan: {
360
+ filePath: planPath,
361
+ exists: planFile.exists,
362
+ parsed: planFile.parsed,
363
+ serverCount: serverMap.size,
364
+ enabledServers: enabledServers.map((server) => String(server.id || ''))
365
+ },
366
+ env: {
367
+ required: requiredEnv,
368
+ missing: missingEnv
369
+ },
370
+ presets: presetChecks,
371
+ checks,
372
+ summary
373
+ };
374
+
375
+ if (options.json) {
376
+ return output;
377
+ }
378
+
379
+ logger.log(t('mcp_doctor.report_title', { path: targetDir }));
380
+ for (const check of checks) {
381
+ logger.log(
382
+ t('mcp_doctor.check_line', {
383
+ prefix: formatCheckPrefix(check, t),
384
+ id: check.id,
385
+ message: check.message
386
+ })
387
+ );
388
+ if (check.hint) {
389
+ logger.log(t('mcp_doctor.hint_line', { hint: check.hint }));
390
+ }
391
+ }
392
+ logger.log(
393
+ t('mcp_doctor.summary', {
394
+ passed: summary.passed,
395
+ failed: summary.failed,
396
+ warnings: summary.warnings
397
+ })
398
+ );
399
+
400
+ return output;
401
+ }
402
+
403
+ module.exports = {
404
+ runMcpDoctor,
405
+ summarizeChecks
406
+ };