@jaimevalasek/aioson 1.4.0 → 1.6.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.
- package/CHANGELOG.md +31 -1
- package/LICENSE +661 -21
- package/README.md +9 -1
- package/docs/design-previews/aurora-command-ui-website.html +884 -0
- package/docs/design-previews/aurora-command-ui.html +682 -0
- package/docs/design-previews/bold-editorial-ui-website.html +658 -0
- package/docs/design-previews/bold-editorial-ui.html +717 -0
- package/docs/design-previews/clean-saas-ui-website.html +1202 -0
- package/docs/design-previews/clean-saas-ui.html +549 -0
- package/docs/design-previews/cognitive-core-ui-website.html +1009 -0
- package/docs/design-previews/cognitive-core-ui.html +463 -0
- package/docs/design-previews/glassmorphism-ui-website.html +572 -0
- package/docs/design-previews/glassmorphism-ui.html +886 -0
- package/docs/design-previews/index.html +699 -0
- package/docs/design-previews/interface-design-website.html +1187 -0
- package/docs/design-previews/interface-design.html +513 -0
- package/docs/design-previews/neo-brutalist-ui-website.html +621 -0
- package/docs/design-previews/neo-brutalist-ui.html +797 -0
- package/docs/design-previews/premium-command-center-ui-website.html +1217 -0
- package/docs/design-previews/premium-command-center-ui.html +552 -0
- package/docs/design-previews/warm-craft-ui-website.html +684 -0
- package/docs/design-previews/warm-craft-ui.html +739 -0
- package/docs/en/cli-reference.md +20 -9
- package/docs/en/squad-dashboard.md +372 -0
- package/docs/openclaw-bridge.md +308 -0
- package/docs/pt/README.md +7 -0
- package/docs/pt/agent-sharding.md +132 -0
- package/docs/pt/agentes.md +131 -11
- package/docs/pt/busca-de-contexto.md +129 -0
- package/docs/pt/cache-de-contexto.md +156 -0
- package/docs/pt/cenarios.md +46 -2
- package/docs/pt/comandos-cli.md +88 -1
- package/docs/pt/design-hybrid-forge.md +107 -0
- package/docs/pt/inicio-rapido.md +72 -5
- package/docs/pt/inteligencia-adaptativa.md +324 -0
- package/docs/pt/monitor-de-contexto.md +104 -0
- package/docs/pt/recuperacao-de-sessao.md +125 -0
- package/docs/pt/sandbox.md +125 -0
- package/docs/pt/skills.md +98 -6
- package/docs/pt/squad-dashboard.md +373 -0
- package/docs/testing/genome-2.0-matrix.md +5 -5
- package/docs/testing/genome-2.0-rollout.md +9 -9
- package/package.json +2 -2
- package/src/agent-loader.js +280 -0
- package/src/backup-local.js +74 -0
- package/src/cli.js +192 -0
- package/src/commands/agent-loader.js +85 -0
- package/src/commands/backup-local-cmd.js +25 -0
- package/src/commands/context-cache.js +90 -0
- package/src/commands/context-monitor.js +92 -0
- package/src/commands/context-search.js +66 -0
- package/src/commands/design-hybrid-options.js +385 -0
- package/src/commands/health.js +214 -0
- package/src/commands/init.js +54 -13
- package/src/commands/install.js +52 -13
- package/src/commands/learning-evolve.js +355 -0
- package/src/commands/live.js +34 -0
- package/src/commands/recovery.js +43 -0
- package/src/commands/runtime.js +242 -0
- package/src/commands/sandbox.js +37 -0
- package/src/commands/setup-context.js +29 -4
- package/src/commands/setup.js +178 -0
- package/src/commands/skill.js +79 -32
- package/src/commands/squad-daemon.js +209 -0
- package/src/commands/squad-dashboard.js +39 -0
- package/src/commands/squad-deploy.js +64 -0
- package/src/commands/squad-doctor.js +52 -0
- package/src/commands/squad-mcp.js +270 -0
- package/src/commands/squad-processes.js +56 -0
- package/src/commands/squad-recovery.js +42 -0
- package/src/commands/squad-roi.js +291 -0
- package/src/commands/squad-score.js +250 -0
- package/src/commands/squad-status.js +37 -1
- package/src/commands/squad-validate.js +62 -1
- package/src/commands/squad-webhook.js +160 -0
- package/src/commands/squad-worker.js +191 -0
- package/src/commands/squad-worktrees.js +75 -0
- package/src/commands/tool-registry-cmd.js +232 -0
- package/src/commands/update.js +7 -0
- package/src/commands/web-map.js +70 -0
- package/src/commands/web-scrape.js +71 -0
- package/src/constants.js +17 -0
- package/src/context-cache.js +159 -0
- package/src/context-search.js +326 -0
- package/src/context-writer.js +45 -1
- package/src/design-variation-catalog.js +503 -0
- package/src/i18n/messages/en.js +159 -3
- package/src/i18n/messages/es.js +147 -2
- package/src/i18n/messages/fr.js +147 -2
- package/src/i18n/messages/pt-BR.js +158 -3
- package/src/install-animation.js +260 -0
- package/src/install-profile.js +143 -0
- package/src/install-wizard.js +474 -0
- package/src/installer.js +38 -10
- package/src/lib/webhook-server.js +328 -0
- package/src/mcp-connectors/registry.js +602 -0
- package/src/parser.js +7 -1
- package/src/recovery-context-session.js +154 -0
- package/src/runtime-store.js +355 -2
- package/src/sandbox.js +177 -0
- package/src/squad/external-session.js +180 -0
- package/src/squad/inter-squad.js +74 -0
- package/src/squad/recovery-context.js +201 -0
- package/src/squad/worktree-manager.js +114 -0
- package/src/squad-daemon.js +490 -0
- package/src/squad-dashboard/api.js +223 -0
- package/src/squad-dashboard/attachment-handler.js +93 -0
- package/src/squad-dashboard/context-monitor.js +157 -0
- package/src/squad-dashboard/execution-logs.js +115 -0
- package/src/squad-dashboard/hunk-review.js +209 -0
- package/src/squad-dashboard/metrics.js +133 -0
- package/src/squad-dashboard/process-monitor.js +125 -0
- package/src/squad-dashboard/renderer.js +858 -0
- package/src/squad-dashboard/server.js +232 -0
- package/src/squad-dashboard/styles.js +525 -0
- package/src/squad-dashboard/token-tracker.js +99 -0
- package/src/tool-executor.js +94 -0
- package/src/updater.js +11 -3
- package/src/web.js +284 -0
- package/src/worker-runner.js +339 -0
- package/template/.aioson/agents/analyst.md +62 -3
- package/template/.aioson/agents/architect.md +42 -0
- package/template/.aioson/agents/design-hybrid-forge.md +127 -0
- package/template/.aioson/agents/dev.md +223 -11
- package/template/.aioson/agents/deyvin.md +65 -0
- package/template/.aioson/agents/neo.md +152 -0
- package/template/.aioson/agents/orache.md +17 -0
- package/template/.aioson/agents/orchestrator.md +26 -0
- package/template/.aioson/agents/pm.md +58 -0
- package/template/.aioson/agents/product.md +88 -12
- package/template/.aioson/agents/qa.md +80 -0
- package/template/.aioson/agents/setup.md +128 -22
- package/template/.aioson/agents/sheldon.md +704 -0
- package/template/.aioson/agents/squad.md +191 -0
- package/template/.aioson/agents/tester.md +410 -0
- package/template/.aioson/agents/ux-ui.md +12 -0
- package/template/.aioson/config.md +21 -0
- package/template/.aioson/context/forensics/.gitkeep +0 -0
- package/template/.aioson/context/seeds/seed-example.md +27 -0
- package/template/.aioson/context/user-profile.md +42 -0
- package/template/.aioson/locales/en/agents/analyst.md +8 -0
- package/template/.aioson/locales/en/agents/architect.md +8 -0
- package/template/.aioson/locales/en/agents/dev.md +66 -7
- package/template/.aioson/locales/en/agents/deyvin.md +8 -0
- package/template/.aioson/locales/en/agents/neo.md +8 -0
- package/template/.aioson/locales/en/agents/orchestrator.md +26 -0
- package/template/.aioson/locales/en/agents/qa.md +49 -0
- package/template/.aioson/locales/en/agents/setup.md +35 -2
- package/template/.aioson/locales/en/agents/sheldon.md +340 -0
- package/template/.aioson/locales/en/agents/ux-ui.md +8 -0
- package/template/.aioson/locales/es/agents/analyst.md +8 -0
- package/template/.aioson/locales/es/agents/architect.md +8 -0
- package/template/.aioson/locales/es/agents/dev.md +66 -7
- package/template/.aioson/locales/es/agents/deyvin.md +8 -0
- package/template/.aioson/locales/es/agents/neo.md +48 -0
- package/template/.aioson/locales/es/agents/orchestrator.md +26 -0
- package/template/.aioson/locales/es/agents/qa.md +26 -0
- package/template/.aioson/locales/es/agents/setup.md +35 -2
- package/template/.aioson/locales/es/agents/sheldon.md +192 -0
- package/template/.aioson/locales/es/agents/squad.md +63 -0
- package/template/.aioson/locales/es/agents/ux-ui.md +8 -0
- package/template/.aioson/locales/fr/agents/analyst.md +8 -0
- package/template/.aioson/locales/fr/agents/architect.md +8 -0
- package/template/.aioson/locales/fr/agents/dev.md +66 -7
- package/template/.aioson/locales/fr/agents/deyvin.md +8 -0
- package/template/.aioson/locales/fr/agents/neo.md +48 -0
- package/template/.aioson/locales/fr/agents/orchestrator.md +26 -0
- package/template/.aioson/locales/fr/agents/qa.md +26 -0
- package/template/.aioson/locales/fr/agents/setup.md +35 -2
- package/template/.aioson/locales/fr/agents/sheldon.md +192 -0
- package/template/.aioson/locales/fr/agents/squad.md +63 -0
- package/template/.aioson/locales/fr/agents/ux-ui.md +8 -0
- package/template/.aioson/locales/pt-BR/agents/analyst.md +19 -0
- package/template/.aioson/locales/pt-BR/agents/architect.md +19 -0
- package/template/.aioson/locales/pt-BR/agents/dev.md +75 -12
- package/template/.aioson/locales/pt-BR/agents/deyvin.md +8 -0
- package/template/.aioson/locales/pt-BR/agents/neo.md +147 -0
- package/template/.aioson/locales/pt-BR/agents/orchestrator.md +26 -0
- package/template/.aioson/locales/pt-BR/agents/product.md +8 -3
- package/template/.aioson/locales/pt-BR/agents/qa.md +60 -0
- package/template/.aioson/locales/pt-BR/agents/setup.md +35 -2
- package/template/.aioson/locales/pt-BR/agents/sheldon.md +192 -0
- package/template/.aioson/locales/pt-BR/agents/squad.md +105 -0
- package/template/.aioson/locales/pt-BR/agents/ux-ui.md +8 -0
- package/template/.aioson/schemas/squad-blueprint.schema.json +21 -0
- package/template/.aioson/schemas/squad-manifest.schema.json +178 -1
- package/template/.aioson/skills/design/aurora-command-ui/SKILL.md +243 -0
- package/template/.aioson/skills/design/aurora-command-ui/references/art-direction.md +293 -0
- package/template/.aioson/skills/design/aurora-command-ui/references/components.md +827 -0
- package/template/.aioson/skills/design/aurora-command-ui/references/dashboards.md +250 -0
- package/template/.aioson/skills/design/aurora-command-ui/references/design-tokens.md +585 -0
- package/template/.aioson/skills/design/aurora-command-ui/references/motion.md +365 -0
- package/template/.aioson/skills/design/aurora-command-ui/references/patterns.md +482 -0
- package/template/.aioson/skills/design/aurora-command-ui/references/websites.md +387 -0
- package/template/.aioson/skills/design/bold-editorial-ui/SKILL.md +205 -0
- package/template/.aioson/skills/design/bold-editorial-ui/references/art-direction.md +338 -0
- package/template/.aioson/skills/design/bold-editorial-ui/references/components.md +977 -0
- package/template/.aioson/skills/design/bold-editorial-ui/references/dashboards.md +218 -0
- package/template/.aioson/skills/design/bold-editorial-ui/references/design-tokens.md +326 -0
- package/template/.aioson/skills/design/bold-editorial-ui/references/motion.md +461 -0
- package/template/.aioson/skills/design/bold-editorial-ui/references/patterns.md +293 -0
- package/template/.aioson/skills/design/bold-editorial-ui/references/websites.md +352 -0
- package/template/.aioson/skills/design/clean-saas-ui/SKILL.md +210 -0
- package/template/.aioson/skills/design/clean-saas-ui/references/art-direction.md +319 -0
- package/template/.aioson/skills/design/clean-saas-ui/references/components.md +365 -0
- package/template/.aioson/skills/design/clean-saas-ui/references/dashboards.md +196 -0
- package/template/.aioson/skills/design/clean-saas-ui/references/design-tokens.md +244 -0
- package/template/.aioson/skills/design/clean-saas-ui/references/motion.md +235 -0
- package/template/.aioson/skills/design/clean-saas-ui/references/patterns.md +215 -0
- package/template/.aioson/skills/design/clean-saas-ui/references/websites.md +295 -0
- package/template/.aioson/skills/design/cognitive-core-ui/SKILL.md +55 -9
- package/template/.aioson/skills/design/cognitive-core-ui/references/art-direction.md +339 -0
- package/template/.aioson/skills/design/cognitive-core-ui/references/components.md +1 -1
- package/template/.aioson/skills/design/cognitive-core-ui/references/dashboards.md +100 -0
- package/template/.aioson/skills/design/cognitive-core-ui/references/design-tokens.md +43 -9
- package/template/.aioson/skills/design/cognitive-core-ui/references/motion.md +40 -0
- package/template/.aioson/skills/design/cognitive-core-ui/references/patterns.md +1 -1
- package/template/.aioson/skills/design/cognitive-core-ui/references/websites.md +99 -12
- package/template/.aioson/skills/design/glassmorphism-ui/SKILL.md +222 -0
- package/template/.aioson/skills/design/glassmorphism-ui/references/art-direction.md +159 -0
- package/template/.aioson/skills/design/glassmorphism-ui/references/components.md +498 -0
- package/template/.aioson/skills/design/glassmorphism-ui/references/dashboards.md +236 -0
- package/template/.aioson/skills/design/glassmorphism-ui/references/design-tokens.md +274 -0
- package/template/.aioson/skills/design/glassmorphism-ui/references/motion.md +355 -0
- package/template/.aioson/skills/design/glassmorphism-ui/references/patterns.md +198 -0
- package/template/.aioson/skills/design/glassmorphism-ui/references/websites.md +307 -0
- package/template/.aioson/skills/design/neo-brutalist-ui/SKILL.md +213 -0
- package/template/.aioson/skills/design/neo-brutalist-ui/references/art-direction.md +228 -0
- package/template/.aioson/skills/design/neo-brutalist-ui/references/components.md +855 -0
- package/template/.aioson/skills/design/neo-brutalist-ui/references/dashboards.md +334 -0
- package/template/.aioson/skills/design/neo-brutalist-ui/references/design-tokens.md +342 -0
- package/template/.aioson/skills/design/neo-brutalist-ui/references/motion.md +286 -0
- package/template/.aioson/skills/design/neo-brutalist-ui/references/patterns.md +458 -0
- package/template/.aioson/skills/design/neo-brutalist-ui/references/websites.md +723 -0
- package/template/.aioson/skills/design/warm-craft-ui/SKILL.md +209 -0
- package/template/.aioson/skills/design/warm-craft-ui/references/art-direction.md +324 -0
- package/template/.aioson/skills/design/warm-craft-ui/references/components.md +508 -0
- package/template/.aioson/skills/design/warm-craft-ui/references/dashboards.md +223 -0
- package/template/.aioson/skills/design/warm-craft-ui/references/design-tokens.md +374 -0
- package/template/.aioson/skills/design/warm-craft-ui/references/motion.md +356 -0
- package/template/.aioson/skills/design/warm-craft-ui/references/patterns.md +288 -0
- package/template/.aioson/skills/design/warm-craft-ui/references/websites.md +289 -0
- package/template/.aioson/skills/premium-visual-design/SKILL.md +83 -0
- package/template/.aioson/skills/premium-visual-design/components/agent-badge.md +92 -0
- package/template/.aioson/skills/premium-visual-design/components/dependency-node.md +102 -0
- package/template/.aioson/skills/premium-visual-design/components/mention-autocomplete.md +136 -0
- package/template/.aioson/skills/premium-visual-design/components/notification-center.md +136 -0
- package/template/.aioson/skills/premium-visual-design/components/review-action-bar.md +188 -0
- package/template/.aioson/skills/premium-visual-design/components/team-switcher.md +131 -0
- package/template/.aioson/skills/premium-visual-design/patterns/agent-message-thread.md +198 -0
- package/template/.aioson/skills/premium-visual-design/patterns/notification-panel.md +275 -0
- package/template/.aioson/skills/premium-visual-design/patterns/review-workflow-ui.md +234 -0
- package/template/.aioson/skills/premium-visual-design/patterns/task-dependency-graph.md +147 -0
- package/template/.aioson/skills/premium-visual-design/tokens/status-extended.md +142 -0
- package/template/.aioson/skills/process/aioson-spec-driven/SKILL.md +45 -0
- package/template/.aioson/skills/process/aioson-spec-driven/references/approval-gates.md +109 -0
- package/template/.aioson/skills/process/aioson-spec-driven/references/artifact-map.md +44 -0
- package/template/.aioson/skills/process/aioson-spec-driven/references/classification-map.md +37 -0
- package/template/.aioson/skills/process/aioson-spec-driven/references/hardening-lane.md +49 -0
- package/template/.aioson/skills/process/aioson-spec-driven/references/maintenance-and-state.md +66 -0
- package/template/.aioson/skills/process/aioson-spec-driven/references/ui-language.md +75 -0
- package/template/.aioson/skills/process/design-hybrid-forge/SKILL.md +144 -0
- package/template/.aioson/skills/process/design-hybrid-forge/references/crossover-protocol.md +221 -0
- package/template/.aioson/skills/process/design-hybrid-forge/references/naming-registry.md +88 -0
- package/template/.aioson/skills/process/design-hybrid-forge/references/output-contract.md +291 -0
- package/template/.aioson/skills/process/design-hybrid-forge/references/pair-compatibility.md +117 -0
- package/template/.aioson/skills/process/design-hybrid-forge/references/quality-gates.md +188 -0
- package/template/.aioson/skills/process/design-hybrid-forge/references/variation-library.md +125 -0
- package/template/.aioson/skills/squad/formats/catalog.json +15 -0
- package/template/.aioson/skills/squad/formats/content/blog-post.md +47 -0
- package/template/.aioson/skills/squad/formats/content/newsletter.md +47 -0
- package/template/.aioson/skills/squad/formats/creative/podcast-script.md +43 -0
- package/template/.aioson/skills/squad/formats/creative/video-script.md +41 -0
- package/template/.aioson/skills/squad/formats/social/instagram-feed.md +42 -0
- package/template/.aioson/skills/squad/formats/social/linkedin-post.md +42 -0
- package/template/.aioson/skills/squad/formats/social/tiktok.md +39 -0
- package/template/.aioson/skills/squad/formats/social/twitter-thread.md +39 -0
- package/template/.aioson/skills/squad/formats/social/youtube-long.md +47 -0
- package/template/.aioson/skills/squad/formats/social/youtube-shorts.md +39 -0
- package/template/.aioson/skills/squad/patterns/multi-platform-pattern.md +108 -0
- package/template/.aioson/skills/squad/patterns/persona-based-pattern.md +98 -0
- package/template/.aioson/skills/squad/patterns/pipeline-pattern.md +106 -0
- package/template/.aioson/skills/squad/patterns/review-loop-pattern.md +81 -0
- package/template/.aioson/skills/squad/references/checklist-templates.md +122 -0
- package/template/.aioson/skills/squad/references/executor-archetypes.md +123 -0
- package/template/.aioson/skills/squad/references/workflow-templates.md +169 -0
- package/template/.aioson/skills/static/debugging-protocol.md +42 -0
- package/template/.aioson/skills/static/git-worktrees.md +36 -0
- package/template/.aioson/tasks/implementation-plan.md +19 -0
- package/template/.aioson/tasks/squad-design.md +28 -0
- package/template/.aioson/tasks/squad-profile.md +48 -0
- package/template/.aioson/tasks/squad-review.md +61 -0
- package/template/.aioson/tasks/squad-task-decompose.md +66 -0
- package/template/.claude/commands/aioson/agent/neo.md +5 -0
- package/template/.claude/commands/aioson/agent/tester.md +5 -0
- package/template/.gemini/GEMINI.md +1 -0
- package/template/.gemini/commands/aios-neo.toml +4 -0
- package/template/.gemini/commands/aios-tester.toml +6 -0
- package/template/AGENTS.md +26 -1
- package/template/CLAUDE.md +6 -2
- package/template/OPENCODE.md +2 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const { openRuntimeDb, upsertMcpStatus, listMcpStatus, getMcpStatus } = require('../runtime-store');
|
|
5
|
+
const {
|
|
6
|
+
listBuiltInConnectors,
|
|
7
|
+
getBuiltInConnector,
|
|
8
|
+
loadIntegrationConfig,
|
|
9
|
+
saveIntegrationConfig,
|
|
10
|
+
listIntegrations,
|
|
11
|
+
resolveConnectorEnv,
|
|
12
|
+
runHealthCheck,
|
|
13
|
+
runAction
|
|
14
|
+
} = require('../mcp-connectors/registry');
|
|
15
|
+
|
|
16
|
+
async function runSquadMcp({ args, options, logger, t }) {
|
|
17
|
+
const projectDir = path.resolve(args[0] || options.path || '.');
|
|
18
|
+
const squadSlug = options.squad;
|
|
19
|
+
const sub = options.sub || 'status';
|
|
20
|
+
|
|
21
|
+
if (!squadSlug) {
|
|
22
|
+
logger.log(t('squad_mcp.squad_required'));
|
|
23
|
+
return { ok: false, error: 'squad_required' };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (sub === 'connectors') {
|
|
27
|
+
return handleConnectors({ logger, t });
|
|
28
|
+
}
|
|
29
|
+
if (sub === 'status') {
|
|
30
|
+
return handleStatus({ projectDir, squadSlug, logger, t });
|
|
31
|
+
}
|
|
32
|
+
if (sub === 'configure') {
|
|
33
|
+
return handleConfigure({ projectDir, squadSlug, options, logger, t });
|
|
34
|
+
}
|
|
35
|
+
if (sub === 'test') {
|
|
36
|
+
return handleTest({ projectDir, squadSlug, options, logger, t });
|
|
37
|
+
}
|
|
38
|
+
if (sub === 'call') {
|
|
39
|
+
return handleCall({ projectDir, squadSlug, options, logger, t });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
logger.log(t('squad_mcp.unknown_sub', { sub }));
|
|
43
|
+
return { ok: false, error: 'unknown_sub' };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function handleConnectors({ logger, t }) {
|
|
47
|
+
const connectors = listBuiltInConnectors();
|
|
48
|
+
logger.log(t('squad_mcp.connectors_title'));
|
|
49
|
+
for (const c of connectors) {
|
|
50
|
+
logger.log(` ${c.id} — ${c.name}`);
|
|
51
|
+
logger.log(` ${t('squad_mcp.actions')}: ${c.actions.join(', ')}`);
|
|
52
|
+
logger.log(` ${t('squad_mcp.required_config')}: ${c.requiredConfig.join(', ') || 'none'}`);
|
|
53
|
+
logger.log('');
|
|
54
|
+
}
|
|
55
|
+
return { ok: true, connectors };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function handleStatus({ projectDir, squadSlug, logger, t }) {
|
|
59
|
+
const integrations = await listIntegrations(projectDir, squadSlug);
|
|
60
|
+
|
|
61
|
+
if (integrations.length === 0) {
|
|
62
|
+
logger.log(t('squad_mcp.no_integrations', { squad: squadSlug }));
|
|
63
|
+
return { ok: true, integrations: [] };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
let handle;
|
|
67
|
+
try {
|
|
68
|
+
handle = await openRuntimeDb(projectDir);
|
|
69
|
+
} catch {
|
|
70
|
+
handle = null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const results = [];
|
|
74
|
+
for (const integ of integrations) {
|
|
75
|
+
const connectorDef = getBuiltInConnector(integ.connector);
|
|
76
|
+
let status = 'unknown';
|
|
77
|
+
let missing = [];
|
|
78
|
+
if (connectorDef) {
|
|
79
|
+
const env = resolveConnectorEnv(connectorDef, integ.config);
|
|
80
|
+
status = env.status;
|
|
81
|
+
missing = env.missing;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let dbStatus = null;
|
|
85
|
+
if (handle) {
|
|
86
|
+
dbStatus = getMcpStatus(handle.db, squadSlug, integ.slug);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const entry = {
|
|
90
|
+
slug: integ.slug,
|
|
91
|
+
connector: integ.connector,
|
|
92
|
+
status: dbStatus ? dbStatus.status : status,
|
|
93
|
+
missing,
|
|
94
|
+
calls_total: dbStatus ? dbStatus.calls_total : 0,
|
|
95
|
+
calls_failed: dbStatus ? dbStatus.calls_failed : 0
|
|
96
|
+
};
|
|
97
|
+
results.push(entry);
|
|
98
|
+
|
|
99
|
+
const statusIcon = entry.status === 'connected' ? '+' : entry.status === 'configured' ? '~' : '-';
|
|
100
|
+
logger.log(` [${statusIcon}] ${integ.slug} (${integ.connector}) — ${entry.status}`);
|
|
101
|
+
if (missing.length > 0) {
|
|
102
|
+
logger.log(` ${t('squad_mcp.missing_config')}: ${missing.join(', ')}`);
|
|
103
|
+
}
|
|
104
|
+
if (entry.calls_total > 0) {
|
|
105
|
+
logger.log(` ${t('squad_mcp.calls')}: ${entry.calls_total} (${entry.calls_failed} failed)`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (handle) handle.db.close();
|
|
110
|
+
return { ok: true, integrations: results };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function handleConfigure({ projectDir, squadSlug, options, logger, t }) {
|
|
114
|
+
const mcpSlug = options.mcp;
|
|
115
|
+
const connector = options.connector;
|
|
116
|
+
|
|
117
|
+
if (!mcpSlug) {
|
|
118
|
+
logger.log(t('squad_mcp.mcp_required'));
|
|
119
|
+
return { ok: false, error: 'mcp_required' };
|
|
120
|
+
}
|
|
121
|
+
if (!connector) {
|
|
122
|
+
logger.log(t('squad_mcp.connector_required'));
|
|
123
|
+
return { ok: false, error: 'connector_required' };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const connectorDef = getBuiltInConnector(connector);
|
|
127
|
+
if (!connectorDef) {
|
|
128
|
+
logger.log(t('squad_mcp.unknown_connector', { connector }));
|
|
129
|
+
return { ok: false, error: 'unknown_connector' };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Build config from --key=value options
|
|
133
|
+
const config = {};
|
|
134
|
+
for (const [key] of Object.entries(connectorDef.configSchema)) {
|
|
135
|
+
if (options[key] !== undefined) {
|
|
136
|
+
config[key] = options[key];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const integrationConfig = { connector, config };
|
|
141
|
+
await saveIntegrationConfig(projectDir, squadSlug, mcpSlug, integrationConfig);
|
|
142
|
+
|
|
143
|
+
// Check resolution
|
|
144
|
+
const { status, missing } = resolveConnectorEnv(connectorDef, config);
|
|
145
|
+
|
|
146
|
+
// Update SQLite status
|
|
147
|
+
try {
|
|
148
|
+
const handle = await openRuntimeDb(projectDir);
|
|
149
|
+
upsertMcpStatus(handle.db, { squadSlug, mcpSlug, connector, status, lastError: null });
|
|
150
|
+
handle.db.close();
|
|
151
|
+
} catch { /* SQLite optional */ }
|
|
152
|
+
|
|
153
|
+
logger.log(t('squad_mcp.configured', { mcp: mcpSlug, connector, status }));
|
|
154
|
+
if (missing.length > 0) {
|
|
155
|
+
logger.log(t('squad_mcp.still_missing', { keys: missing.join(', ') }));
|
|
156
|
+
}
|
|
157
|
+
return { ok: true, slug: mcpSlug, connector, status, missing };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function handleTest({ projectDir, squadSlug, options, logger, t }) {
|
|
161
|
+
const mcpSlug = options.mcp;
|
|
162
|
+
if (!mcpSlug) {
|
|
163
|
+
logger.log(t('squad_mcp.mcp_required'));
|
|
164
|
+
return { ok: false, error: 'mcp_required' };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const config = await loadIntegrationConfig(projectDir, squadSlug, mcpSlug);
|
|
168
|
+
if (!config) {
|
|
169
|
+
logger.log(t('squad_mcp.not_configured', { mcp: mcpSlug }));
|
|
170
|
+
return { ok: false, error: 'not_configured' };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const connectorDef = getBuiltInConnector(config.connector);
|
|
174
|
+
if (!connectorDef) {
|
|
175
|
+
logger.log(t('squad_mcp.unknown_connector', { connector: config.connector }));
|
|
176
|
+
return { ok: false, error: 'unknown_connector' };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const { resolved, missing, status } = resolveConnectorEnv(connectorDef, config.config);
|
|
180
|
+
|
|
181
|
+
if (missing.length > 0) {
|
|
182
|
+
logger.log(t('squad_mcp.test_missing', { mcp: mcpSlug, keys: missing.join(', ') }));
|
|
183
|
+
|
|
184
|
+
try {
|
|
185
|
+
const handle = await openRuntimeDb(projectDir);
|
|
186
|
+
upsertMcpStatus(handle.db, { squadSlug, mcpSlug, connector: config.connector, status: 'unconfigured', lastError: `Missing: ${missing.join(', ')}` });
|
|
187
|
+
handle.db.close();
|
|
188
|
+
} catch { /* optional */ }
|
|
189
|
+
|
|
190
|
+
return { ok: false, error: 'missing_config', missing };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
logger.log(t('squad_mcp.testing_connection'));
|
|
194
|
+
const health = await runHealthCheck(config.connector, resolved);
|
|
195
|
+
|
|
196
|
+
const healthStatus = health.ok ? 'connected' : 'error';
|
|
197
|
+
try {
|
|
198
|
+
const handle = await openRuntimeDb(projectDir);
|
|
199
|
+
upsertMcpStatus(handle.db, {
|
|
200
|
+
squadSlug, mcpSlug,
|
|
201
|
+
connector: config.connector,
|
|
202
|
+
status: healthStatus,
|
|
203
|
+
lastCheck: new Date().toISOString(),
|
|
204
|
+
lastError: health.ok ? null : (health.error || String(health.statusCode))
|
|
205
|
+
});
|
|
206
|
+
handle.db.close();
|
|
207
|
+
} catch { /* optional */ }
|
|
208
|
+
|
|
209
|
+
if (health.skipped) {
|
|
210
|
+
logger.log(t('squad_mcp.health_skipped'));
|
|
211
|
+
return { ok: true, slug: mcpSlug, status: 'skipped' };
|
|
212
|
+
}
|
|
213
|
+
if (health.ok) {
|
|
214
|
+
logger.log(t('squad_mcp.health_ok', { statusCode: health.statusCode }));
|
|
215
|
+
return { ok: true, slug: mcpSlug, status: 'connected', statusCode: health.statusCode };
|
|
216
|
+
}
|
|
217
|
+
logger.log(t('squad_mcp.health_error', { error: health.error || health.statusCode }));
|
|
218
|
+
return { ok: false, slug: mcpSlug, status: 'error', error: health.error };
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async function handleCall({ projectDir, squadSlug, options, logger, t }) {
|
|
222
|
+
const mcpSlug = options.mcp;
|
|
223
|
+
const actionSlug = options.action;
|
|
224
|
+
|
|
225
|
+
if (!mcpSlug) {
|
|
226
|
+
logger.log(t('squad_mcp.mcp_required'));
|
|
227
|
+
return { ok: false, error: 'mcp_required' };
|
|
228
|
+
}
|
|
229
|
+
if (!actionSlug) {
|
|
230
|
+
logger.log(t('squad_mcp.action_required'));
|
|
231
|
+
return { ok: false, error: 'action_required' };
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
let input;
|
|
235
|
+
try {
|
|
236
|
+
input = JSON.parse(options.input || '{}');
|
|
237
|
+
} catch {
|
|
238
|
+
logger.log(t('squad_mcp.invalid_input'));
|
|
239
|
+
return { ok: false, error: 'invalid_input' };
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const config = await loadIntegrationConfig(projectDir, squadSlug, mcpSlug);
|
|
243
|
+
if (!config) {
|
|
244
|
+
logger.log(t('squad_mcp.not_configured', { mcp: mcpSlug }));
|
|
245
|
+
return { ok: false, error: 'not_configured' };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const connectorDef = getBuiltInConnector(config.connector);
|
|
249
|
+
if (!connectorDef) {
|
|
250
|
+
logger.log(t('squad_mcp.unknown_connector', { connector: config.connector }));
|
|
251
|
+
return { ok: false, error: 'unknown_connector' };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const { resolved, missing } = resolveConnectorEnv(connectorDef, config.config);
|
|
255
|
+
if (missing.length > 0) {
|
|
256
|
+
logger.log(t('squad_mcp.test_missing', { mcp: mcpSlug, keys: missing.join(', ') }));
|
|
257
|
+
return { ok: false, error: 'missing_config', missing };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const result = await runAction(config.connector, actionSlug, input, resolved);
|
|
261
|
+
|
|
262
|
+
if (result.ok) {
|
|
263
|
+
logger.log(JSON.stringify(result.result, null, 2));
|
|
264
|
+
} else {
|
|
265
|
+
logger.log(`Error: ${result.error}`);
|
|
266
|
+
}
|
|
267
|
+
return result;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
module.exports = { runSquadMcp };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const { getActiveProcesses, stopProcess, stopSquadProcesses } = require('../squad-dashboard/process-monitor');
|
|
5
|
+
|
|
6
|
+
function formatElapsed(seconds) {
|
|
7
|
+
if (seconds == null) return '-';
|
|
8
|
+
if (seconds < 60) return `${seconds}s`;
|
|
9
|
+
if (seconds < 3600) return `${Math.floor(seconds / 60)}m${seconds % 60}s`;
|
|
10
|
+
return `${Math.floor(seconds / 3600)}h${Math.floor((seconds % 3600) / 60)}m`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async function runSquadProcesses({ args, options, logger }) {
|
|
14
|
+
const projectDir = path.resolve(process.cwd(), args[0] || '.');
|
|
15
|
+
const squadFilter = options.squad || null;
|
|
16
|
+
|
|
17
|
+
// --stop <pid>
|
|
18
|
+
if (options.stop && options.stop !== true) {
|
|
19
|
+
const result = await stopProcess(projectDir, options.stop);
|
|
20
|
+
if (result.ok) {
|
|
21
|
+
logger.log(`Process ${options.stop} stopped.`);
|
|
22
|
+
} else {
|
|
23
|
+
logger.error(`Failed to stop ${options.stop}: ${result.error}`);
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// --stop-squad <squad>
|
|
29
|
+
if (options['stop-squad']) {
|
|
30
|
+
const slug = options['stop-squad'];
|
|
31
|
+
const results = await stopSquadProcesses(projectDir, slug);
|
|
32
|
+
const stopped = results.filter(r => r.ok).length;
|
|
33
|
+
logger.log(`Stopped ${stopped}/${results.length} processes for squad "${slug}".`);
|
|
34
|
+
return { ok: true, results };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// List
|
|
38
|
+
const processes = await getActiveProcesses(projectDir, squadFilter);
|
|
39
|
+
if (processes.length === 0) {
|
|
40
|
+
logger.log(squadFilter ? `No active processes for squad "${squadFilter}".` : 'No active processes.');
|
|
41
|
+
return { ok: true, processes: [] };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
logger.log(`Active processes (${processes.length}):`);
|
|
45
|
+
for (const proc of processes) {
|
|
46
|
+
const status = proc.alive ? '[*]' : '[ ]';
|
|
47
|
+
const elapsed = formatElapsed(proc.elapsedSeconds);
|
|
48
|
+
const ctx = proc.contextPct != null ? ` ctx:${proc.contextPct}%` : '';
|
|
49
|
+
const url = proc.url ? ` ${proc.url}` : '';
|
|
50
|
+
logger.log(` ${status} [${proc.squadSlug}] ${proc.agentSlug} pid:${proc.pid} elapsed:${elapsed}${ctx}${url}`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return { ok: true, processes };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = { runSquadProcesses };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const { generateRecovery, readRecovery } = require('../squad/recovery-context');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* aioson squad:recovery <project> --squad <squad> --agent <agent> [--show]
|
|
8
|
+
*
|
|
9
|
+
* Generates (or re-generates) the recovery-context.md for an agent.
|
|
10
|
+
* --show: print the generated content to stdout instead of just confirming.
|
|
11
|
+
*/
|
|
12
|
+
async function runSquadRecovery({ args, options, logger }) {
|
|
13
|
+
const projectDir = path.resolve(process.cwd(), args[0] || '.');
|
|
14
|
+
const squadSlug = options.squad || args[1];
|
|
15
|
+
const agentSlug = options.agent || args[2];
|
|
16
|
+
|
|
17
|
+
if (!squadSlug || !agentSlug) {
|
|
18
|
+
logger.error('Usage: aioson squad:recovery <project> --squad <squad> --agent <agent> [--show]');
|
|
19
|
+
return { ok: false };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const result = await generateRecovery(projectDir, squadSlug, agentSlug);
|
|
23
|
+
|
|
24
|
+
if (!result.ok) {
|
|
25
|
+
logger.error(`Failed to generate recovery context: ${result.error}`);
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
logger.log(`Recovery context generated: ${result.path} (~${result.tokens} tokens)`);
|
|
30
|
+
|
|
31
|
+
if (options.show) {
|
|
32
|
+
const content = await readRecovery(projectDir, squadSlug);
|
|
33
|
+
if (content) {
|
|
34
|
+
logger.log('');
|
|
35
|
+
logger.log(content);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = { runSquadRecovery };
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const {
|
|
5
|
+
openRuntimeDb,
|
|
6
|
+
upsertSquadMetric,
|
|
7
|
+
listSquadMetrics,
|
|
8
|
+
upsertROIConfig,
|
|
9
|
+
getROIConfig
|
|
10
|
+
} = require('../runtime-store');
|
|
11
|
+
|
|
12
|
+
async function runSquadRoi({ args, options, logger, t }) {
|
|
13
|
+
const projectDir = path.resolve(args[0] || options.path || '.');
|
|
14
|
+
const squadSlug = options.squad;
|
|
15
|
+
const sub = options.sub || 'report';
|
|
16
|
+
|
|
17
|
+
if (!squadSlug) {
|
|
18
|
+
logger.log(t('squad_roi.squad_required'));
|
|
19
|
+
return { ok: false, error: 'squad_required' };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (sub === 'config') {
|
|
23
|
+
return handleConfig({ projectDir, squadSlug, options, logger, t });
|
|
24
|
+
}
|
|
25
|
+
if (sub === 'metric') {
|
|
26
|
+
return handleMetric({ projectDir, squadSlug, options, logger, t });
|
|
27
|
+
}
|
|
28
|
+
if (sub === 'report') {
|
|
29
|
+
return handleReport({ projectDir, squadSlug, options, logger, t });
|
|
30
|
+
}
|
|
31
|
+
if (sub === 'export') {
|
|
32
|
+
return handleExport({ projectDir, squadSlug, options, logger, t });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
logger.log(t('squad_roi.unknown_sub', { sub }));
|
|
36
|
+
return { ok: false, error: 'unknown_sub' };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function handleConfig({ projectDir, squadSlug, options, logger, t }) {
|
|
40
|
+
const handle = await openRuntimeDb(projectDir);
|
|
41
|
+
|
|
42
|
+
upsertROIConfig(handle.db, {
|
|
43
|
+
squadSlug,
|
|
44
|
+
pricingModel: options.pricing || options.pricing_model,
|
|
45
|
+
setupFee: options.setup ? parseFloat(options.setup) : undefined,
|
|
46
|
+
monthlyFee: options.monthly ? parseFloat(options.monthly) : undefined,
|
|
47
|
+
percentageFee: options.percentage ? parseFloat(options.percentage) : undefined,
|
|
48
|
+
percentageBase: options.base,
|
|
49
|
+
currency: options.currency,
|
|
50
|
+
contractMonths: options.months ? parseInt(options.months, 10) : undefined
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const config = getROIConfig(handle.db, squadSlug);
|
|
54
|
+
handle.db.close();
|
|
55
|
+
|
|
56
|
+
logger.log(t('squad_roi.config_saved', { squad: squadSlug }));
|
|
57
|
+
logger.log(` ${t('squad_roi.pricing_model')}: ${config.pricing_model}`);
|
|
58
|
+
if (config.setup_fee) logger.log(` ${t('squad_roi.setup_fee')}: ${config.currency} ${config.setup_fee}`);
|
|
59
|
+
if (config.monthly_fee) logger.log(` ${t('squad_roi.monthly_fee')}: ${config.currency} ${config.monthly_fee}`);
|
|
60
|
+
if (config.percentage_fee) logger.log(` ${t('squad_roi.percentage')}: ${config.percentage_fee}% (${config.percentage_base || 'n/a'})`);
|
|
61
|
+
logger.log(` ${t('squad_roi.contract')}: ${config.contract_months} months`);
|
|
62
|
+
|
|
63
|
+
return { ok: true, config };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function handleMetric({ projectDir, squadSlug, options, logger, t }) {
|
|
67
|
+
const key = options.key;
|
|
68
|
+
const value = options.value;
|
|
69
|
+
const period = options.period;
|
|
70
|
+
|
|
71
|
+
if (!key || value === undefined) {
|
|
72
|
+
logger.log(t('squad_roi.metric_required'));
|
|
73
|
+
return { ok: false, error: 'metric_required' };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const handle = await openRuntimeDb(projectDir);
|
|
77
|
+
upsertSquadMetric(handle.db, {
|
|
78
|
+
squadSlug,
|
|
79
|
+
metricKey: key,
|
|
80
|
+
value: parseFloat(value),
|
|
81
|
+
unit: options.unit || null,
|
|
82
|
+
period: period || null,
|
|
83
|
+
baseline: options.baseline ? parseFloat(options.baseline) : null,
|
|
84
|
+
target: options.target ? parseFloat(options.target) : null,
|
|
85
|
+
source: options.source || 'manual',
|
|
86
|
+
notes: options.notes || null
|
|
87
|
+
});
|
|
88
|
+
handle.db.close();
|
|
89
|
+
|
|
90
|
+
logger.log(t('squad_roi.metric_saved', { key, value, squad: squadSlug }));
|
|
91
|
+
return { ok: true, key, value: parseFloat(value), period };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function calculateROI(metrics, config) {
|
|
95
|
+
if (!config) return null;
|
|
96
|
+
|
|
97
|
+
const improvements = [];
|
|
98
|
+
for (const m of metrics) {
|
|
99
|
+
if (m.baseline === null || m.baseline === undefined) continue;
|
|
100
|
+
const improvement = m.baseline - m.metric_value;
|
|
101
|
+
improvements.push({
|
|
102
|
+
key: m.metric_key,
|
|
103
|
+
baseline: m.baseline,
|
|
104
|
+
actual: m.metric_value,
|
|
105
|
+
target: m.target,
|
|
106
|
+
improvement,
|
|
107
|
+
unit: m.metric_unit,
|
|
108
|
+
period: m.period
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const monthlyCost = (config.monthly_fee || 0) + ((config.setup_fee || 0) / (config.contract_months || 12));
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
improvements,
|
|
116
|
+
monthly_cost: monthlyCost,
|
|
117
|
+
pricing: {
|
|
118
|
+
model: config.pricing_model,
|
|
119
|
+
setup_fee: config.setup_fee,
|
|
120
|
+
monthly_fee: config.monthly_fee,
|
|
121
|
+
percentage_fee: config.percentage_fee,
|
|
122
|
+
currency: config.currency
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function handleReport({ projectDir, squadSlug, options, logger, t }) {
|
|
128
|
+
const handle = await openRuntimeDb(projectDir);
|
|
129
|
+
const config = getROIConfig(handle.db, squadSlug);
|
|
130
|
+
const metrics = listSquadMetrics(handle.db, squadSlug);
|
|
131
|
+
handle.db.close();
|
|
132
|
+
|
|
133
|
+
if (metrics.length === 0) {
|
|
134
|
+
logger.log(t('squad_roi.no_metrics', { squad: squadSlug }));
|
|
135
|
+
return { ok: true, metrics: [], roi: null };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const period = options.period || null;
|
|
139
|
+
const filtered = period ? metrics.filter(m => m.period === period) : metrics;
|
|
140
|
+
|
|
141
|
+
logger.log(t('squad_roi.report_title', { squad: squadSlug }));
|
|
142
|
+
logger.log('');
|
|
143
|
+
|
|
144
|
+
// Group by metric_key
|
|
145
|
+
const byKey = {};
|
|
146
|
+
for (const m of filtered) {
|
|
147
|
+
if (!byKey[m.metric_key]) byKey[m.metric_key] = [];
|
|
148
|
+
byKey[m.metric_key].push(m);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
for (const [key, entries] of Object.entries(byKey)) {
|
|
152
|
+
const latest = entries[entries.length - 1];
|
|
153
|
+
logger.log(` ${key}`);
|
|
154
|
+
if (latest.baseline !== null) {
|
|
155
|
+
logger.log(` ${t('squad_roi.baseline')}: ${latest.baseline}${latest.metric_unit || ''}`);
|
|
156
|
+
}
|
|
157
|
+
logger.log(` ${t('squad_roi.actual')}: ${latest.metric_value}${latest.metric_unit || ''}`);
|
|
158
|
+
if (latest.target !== null) {
|
|
159
|
+
logger.log(` ${t('squad_roi.target')}: ${latest.target}${latest.metric_unit || ''}`);
|
|
160
|
+
// Progress bar
|
|
161
|
+
if (latest.baseline !== null && latest.baseline !== latest.target) {
|
|
162
|
+
const totalGap = Math.abs(latest.baseline - latest.target);
|
|
163
|
+
const achieved = Math.abs(latest.baseline - latest.metric_value);
|
|
164
|
+
const pct = Math.min(100, Math.round((achieved / totalGap) * 100));
|
|
165
|
+
const filled = Math.round(pct / 5);
|
|
166
|
+
const bar = '#'.repeat(filled) + '.'.repeat(20 - filled);
|
|
167
|
+
logger.log(` [${bar}] ${pct}%`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (latest.period) {
|
|
171
|
+
logger.log(` ${t('squad_roi.period')}: ${latest.period}`);
|
|
172
|
+
}
|
|
173
|
+
logger.log('');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const roi = calculateROI(filtered, config);
|
|
177
|
+
if (roi && config) {
|
|
178
|
+
logger.log(t('squad_roi.cost_section'));
|
|
179
|
+
logger.log(` ${t('squad_roi.monthly_cost')}: ${config.currency} ${roi.monthly_cost.toFixed(2)}`);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return { ok: true, metrics: filtered, roi };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function renderReportHtml(squadSlug, metrics, config) {
|
|
186
|
+
const roi = calculateROI(metrics, config);
|
|
187
|
+
const currency = (config && config.currency) || 'BRL';
|
|
188
|
+
|
|
189
|
+
const byKey = {};
|
|
190
|
+
for (const m of metrics) {
|
|
191
|
+
if (!byKey[m.metric_key]) byKey[m.metric_key] = [];
|
|
192
|
+
byKey[m.metric_key].push(m);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const metricsHtml = Object.entries(byKey).map(([key, entries]) => {
|
|
196
|
+
const latest = entries[entries.length - 1];
|
|
197
|
+
let progressBar = '';
|
|
198
|
+
if (latest.baseline !== null && latest.target !== null && latest.baseline !== latest.target) {
|
|
199
|
+
const totalGap = Math.abs(latest.baseline - latest.target);
|
|
200
|
+
const achieved = Math.abs(latest.baseline - latest.metric_value);
|
|
201
|
+
const pct = Math.min(100, Math.round((achieved / totalGap) * 100));
|
|
202
|
+
progressBar = `<div style="background:#333;border-radius:4px;overflow:hidden;height:8px;margin-top:4px">
|
|
203
|
+
<div style="background:#4ade80;height:100%;width:${pct}%"></div>
|
|
204
|
+
</div><small>${pct}% of target</small>`;
|
|
205
|
+
}
|
|
206
|
+
return `<div style="background:#1e1e2e;padding:16px;border-radius:8px;margin-bottom:12px">
|
|
207
|
+
<h3 style="margin:0 0 8px">${esc(key)}</h3>
|
|
208
|
+
${latest.baseline !== null ? `<p>Baseline: <strong>${latest.baseline}${latest.metric_unit || ''}</strong></p>` : ''}
|
|
209
|
+
<p>Current: <strong>${latest.metric_value}${latest.metric_unit || ''}</strong></p>
|
|
210
|
+
${latest.target !== null ? `<p>Target: <strong>${latest.target}${latest.metric_unit || ''}</strong></p>` : ''}
|
|
211
|
+
${progressBar}
|
|
212
|
+
${latest.period ? `<small>Period: ${esc(latest.period)}</small>` : ''}
|
|
213
|
+
</div>`;
|
|
214
|
+
}).join('\n');
|
|
215
|
+
|
|
216
|
+
const costHtml = roi && config ? `
|
|
217
|
+
<div style="background:#1e1e2e;padding:16px;border-radius:8px;margin-top:16px">
|
|
218
|
+
<h3>Cost Summary</h3>
|
|
219
|
+
<p>Pricing: ${esc(config.pricing_model)}</p>
|
|
220
|
+
${config.setup_fee ? `<p>Setup: ${currency} ${config.setup_fee}</p>` : ''}
|
|
221
|
+
${config.monthly_fee ? `<p>Monthly: ${currency} ${config.monthly_fee}</p>` : ''}
|
|
222
|
+
<p>Monthly effective cost: <strong>${currency} ${roi.monthly_cost.toFixed(2)}</strong></p>
|
|
223
|
+
</div>` : '';
|
|
224
|
+
|
|
225
|
+
return `<!DOCTYPE html>
|
|
226
|
+
<html lang="en">
|
|
227
|
+
<head>
|
|
228
|
+
<meta charset="UTF-8">
|
|
229
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
230
|
+
<title>ROI Report — ${esc(squadSlug)}</title>
|
|
231
|
+
<style>
|
|
232
|
+
body{font-family:system-ui,sans-serif;background:#0d1117;color:#e6edf3;margin:0;padding:24px}
|
|
233
|
+
.container{max-width:720px;margin:0 auto}
|
|
234
|
+
h1{border-bottom:1px solid #30363d;padding-bottom:12px}
|
|
235
|
+
h3{color:#58a6ff}
|
|
236
|
+
p{margin:4px 0}
|
|
237
|
+
small{color:#8b949e}
|
|
238
|
+
</style>
|
|
239
|
+
</head>
|
|
240
|
+
<body>
|
|
241
|
+
<div class="container">
|
|
242
|
+
<h1>ROI Report — ${esc(squadSlug)}</h1>
|
|
243
|
+
<p style="color:#8b949e">Generated: ${new Date().toISOString().slice(0, 10)}</p>
|
|
244
|
+
<h2>Metrics</h2>
|
|
245
|
+
${metricsHtml}
|
|
246
|
+
${costHtml}
|
|
247
|
+
<footer style="margin-top:32px;color:#8b949e;font-size:12px">
|
|
248
|
+
Generated by aioson squad:roi:export
|
|
249
|
+
</footer>
|
|
250
|
+
</div>
|
|
251
|
+
</body>
|
|
252
|
+
</html>`;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function esc(str) {
|
|
256
|
+
if (!str) return '';
|
|
257
|
+
return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
async function handleExport({ projectDir, squadSlug, options, logger, t }) {
|
|
261
|
+
const format = options.format || 'html';
|
|
262
|
+
const handle = await openRuntimeDb(projectDir);
|
|
263
|
+
const config = getROIConfig(handle.db, squadSlug);
|
|
264
|
+
const metrics = listSquadMetrics(handle.db, squadSlug);
|
|
265
|
+
handle.db.close();
|
|
266
|
+
|
|
267
|
+
if (metrics.length === 0) {
|
|
268
|
+
logger.log(t('squad_roi.no_metrics', { squad: squadSlug }));
|
|
269
|
+
return { ok: true, exported: false };
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const period = options.period || null;
|
|
273
|
+
const filtered = period ? metrics.filter(m => m.period === period) : metrics;
|
|
274
|
+
|
|
275
|
+
if (format === 'json') {
|
|
276
|
+
const roi = calculateROI(filtered, config);
|
|
277
|
+
const output = JSON.stringify({ squad: squadSlug, metrics: filtered, roi, config }, null, 2);
|
|
278
|
+
logger.log(output);
|
|
279
|
+
return { ok: true, exported: true, format: 'json' };
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// HTML
|
|
283
|
+
const html = renderReportHtml(squadSlug, filtered, config);
|
|
284
|
+
const fs = require('node:fs/promises');
|
|
285
|
+
const outFile = options.output || `roi-report-${squadSlug}.html`;
|
|
286
|
+
await fs.writeFile(outFile, html);
|
|
287
|
+
logger.log(t('squad_roi.exported', { file: outFile, format: 'html' }));
|
|
288
|
+
return { ok: true, exported: true, format: 'html', file: outFile };
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
module.exports = { runSquadRoi, calculateROI, renderReportHtml, esc };
|