@jaimevalasek/aioson 1.7.2 → 1.9.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 +595 -560
- package/CODE_OF_CONDUCT.md +12 -12
- package/CONTRIBUTING.md +13 -13
- package/LICENSE +661 -661
- package/README.md +919 -776
- package/bin/aioson.js +4 -4
- package/docs/design-previews/aurora-command-ui-website.html +884 -884
- package/docs/design-previews/aurora-command-ui.html +682 -682
- package/docs/design-previews/bold-editorial-ui-website.html +658 -658
- package/docs/design-previews/bold-editorial-ui.html +717 -717
- package/docs/design-previews/clean-saas-ui-website.html +1202 -1202
- package/docs/design-previews/clean-saas-ui.html +549 -549
- package/docs/design-previews/cognitive-core-ui-website.html +1009 -1009
- package/docs/design-previews/cognitive-core-ui.html +463 -463
- package/docs/design-previews/glassmorphism-ui-website.html +572 -572
- package/docs/design-previews/glassmorphism-ui.html +886 -886
- package/docs/design-previews/index.html +699 -699
- package/docs/design-previews/interface-design-website.html +1187 -1187
- package/docs/design-previews/interface-design.html +513 -513
- package/docs/design-previews/neo-brutalist-ui-website.html +621 -621
- package/docs/design-previews/neo-brutalist-ui.html +797 -797
- package/docs/design-previews/premium-command-center-ui-website.html +1217 -1217
- package/docs/design-previews/premium-command-center-ui.html +552 -552
- package/docs/design-previews/pt.squarespace.com-homepage.html +889 -889
- package/docs/design-previews/warm-craft-ui-website.html +684 -684
- package/docs/design-previews/warm-craft-ui.html +739 -739
- package/docs/en/1-understand/ecosystem-map.md +228 -0
- package/docs/en/1-understand/glossary.md +288 -0
- package/docs/en/1-understand/what-is-aioson.md +94 -0
- package/docs/en/1-understand/why-it-exists.md +106 -0
- package/docs/en/2-start/existing-project.md +246 -0
- package/docs/en/2-start/first-project.md +307 -0
- package/docs/en/2-start/initial-decisions.md +223 -0
- package/docs/en/3-recipes/README.md +28 -0
- package/docs/en/3-recipes/continuity-between-sessions.md +303 -0
- package/docs/en/3-recipes/from-idea-to-prd-via-briefing.md +235 -0
- package/docs/en/3-recipes/full-feature-with-sheldon.md +338 -0
- package/docs/en/4-agents/README.md +56 -0
- package/docs/en/5-reference/README.md +60 -0
- package/docs/en/{cli-reference.md → 5-reference/cli-reference.md} +639 -409
- package/docs/en/5-reference/i18n.md +52 -0
- package/docs/en/{json-schemas.md → 5-reference/json-schemas.md} +41 -41
- package/docs/en/{mcp.md → 5-reference/mcp.md} +56 -56
- package/docs/en/{parallel.md → 5-reference/parallel.md} +82 -82
- package/docs/en/{qa-browser.md → 5-reference/qa-browser.md} +339 -339
- package/docs/en/{release-flow.md → 5-reference/release-flow.md} +22 -22
- package/docs/en/{release-notes-template.md → 5-reference/release-notes-template.md} +41 -41
- package/docs/en/{release.md → 5-reference/release.md} +28 -28
- package/docs/en/{schemas → 5-reference/schemas}/agent-prompt.schema.json +17 -17
- package/docs/en/{schemas → 5-reference/schemas}/agents.schema.json +32 -32
- package/docs/en/{schemas → 5-reference/schemas}/context-validate.schema.json +36 -36
- package/docs/en/{schemas → 5-reference/schemas}/doctor.schema.json +89 -89
- package/docs/en/{schemas → 5-reference/schemas}/error.schema.json +24 -24
- package/docs/en/{schemas → 5-reference/schemas}/i18n-add.schema.json +15 -15
- package/docs/en/{schemas → 5-reference/schemas}/index.json +126 -116
- package/docs/en/{schemas → 5-reference/schemas}/info.schema.json +39 -39
- package/docs/en/{schemas → 5-reference/schemas}/init.schema.json +48 -48
- package/docs/en/{schemas → 5-reference/schemas}/install.schema.json +60 -60
- package/docs/en/{schemas → 5-reference/schemas}/locale-apply.schema.json +30 -30
- package/docs/en/{schemas → 5-reference/schemas}/mcp-doctor.schema.json +95 -95
- package/docs/en/{schemas → 5-reference/schemas}/mcp-init.schema.json +122 -122
- package/docs/en/{schemas → 5-reference/schemas}/package-test.schema.json +24 -24
- package/docs/en/{schemas → 5-reference/schemas}/parallel-assign.schema.json +66 -57
- package/docs/en/{schemas → 5-reference/schemas}/parallel-doctor.schema.json +122 -86
- package/docs/en/5-reference/schemas/parallel-guard.schema.json +63 -0
- package/docs/en/{schemas → 5-reference/schemas}/parallel-init.schema.json +53 -53
- package/docs/en/5-reference/schemas/parallel-merge.schema.json +84 -0
- package/docs/en/5-reference/schemas/parallel-status.schema.json +184 -0
- package/docs/en/{schemas → 5-reference/schemas}/setup-context.schema.json +39 -39
- package/docs/en/{schemas → 5-reference/schemas}/smoke.schema.json +23 -23
- package/docs/en/{schemas → 5-reference/schemas}/update.schema.json +48 -48
- package/docs/en/{schemas → 5-reference/schemas}/workflow-plan.schema.json +30 -30
- package/docs/en/{squad-dashboard.md → 5-reference/squad-dashboard.md} +372 -372
- package/docs/en/{web3.md → 5-reference/web3.md} +54 -54
- package/docs/en/README.md +115 -0
- package/docs/en/active-learning-loop/README.md +117 -0
- package/docs/en/active-learning-loop/active-learning-loop.md +117 -0
- package/docs/en/active-learning-loop/cli-commands.md +320 -0
- package/docs/en/active-learning-loop/diagrams.md +225 -0
- package/docs/en/active-learning-loop/doctor-checks.md +151 -0
- package/docs/en/active-learning-loop/how-to-use.md +313 -0
- package/docs/en/active-learning-loop/troubleshooting.md +283 -0
- package/docs/en/deyvin-subtask-scout/README.md +109 -0
- package/docs/en/deyvin-subtask-scout/cli-commands.md +248 -0
- package/docs/en/deyvin-subtask-scout/diagrams.md +124 -0
- package/docs/en/deyvin-subtask-scout/how-to-use.md +221 -0
- package/docs/en/deyvin-subtask-scout/sub-task-scout.md +115 -0
- package/docs/en/deyvin-subtask-scout/troubleshooting.md +184 -0
- package/docs/integrations/apps-publish-marketplace.md +94 -0
- package/docs/integrations/sdlc-genius-boundary.md +76 -76
- package/docs/integrations/sdlc-genius-eval-matrix.md +75 -75
- package/docs/integrations/sdlc-genius-install-checklist.md +93 -93
- package/docs/integrations/sdlc-genius-review-samples.md +86 -86
- package/docs/openclaw-bridge.md +308 -308
- package/docs/pt/1-entender/glossario.md +288 -0
- package/docs/pt/1-entender/mapa-do-ecossistema.md +228 -0
- package/docs/pt/1-entender/o-que-e-aioson.md +94 -0
- package/docs/pt/1-entender/por-que-existe.md +107 -0
- package/docs/pt/2-comecar/decisoes-iniciais.md +223 -0
- package/docs/pt/2-comecar/primeiro-projeto.md +307 -0
- package/docs/pt/2-comecar/projeto-existente.md +245 -0
- package/docs/pt/3-receitas/README.md +28 -0
- package/docs/pt/3-receitas/app-saas-do-zero.md +324 -0
- package/docs/pt/3-receitas/auditoria-seguranca.md +254 -0
- package/docs/pt/3-receitas/clonar-design-de-site.md +211 -0
- package/docs/pt/3-receitas/continuidade-entre-sessoes.md +303 -0
- package/docs/pt/3-receitas/da-ideia-ao-prd-via-briefing.md +234 -0
- package/docs/pt/3-receitas/feature-completa-com-sheldon.md +338 -0
- package/docs/pt/3-receitas/integracao-em-codebase-grande.md +243 -0
- package/docs/pt/3-receitas/landing-page.md +281 -0
- package/docs/pt/3-receitas/plans-externos-para-product.md +191 -0
- package/docs/pt/3-receitas/publicar-no-aioson-com.md +219 -0
- package/docs/pt/3-receitas/refatoracao-grande.md +251 -0
- package/docs/pt/4-agentes/README.md +65 -0
- package/docs/pt/4-agentes/analyst.md +111 -0
- package/docs/pt/4-agentes/architect.md +113 -0
- package/docs/pt/4-agentes/briefing.md +95 -0
- package/docs/pt/4-agentes/committer.md +108 -0
- package/docs/pt/4-agentes/copywriter.md +279 -0
- package/docs/pt/4-agentes/design-hybrid-forge.md +116 -0
- package/docs/pt/4-agentes/dev.md +136 -0
- package/docs/pt/4-agentes/deyvin.md +99 -0
- package/docs/pt/4-agentes/discover.md +122 -0
- package/docs/pt/4-agentes/discovery-design-doc.md +91 -0
- package/docs/pt/4-agentes/genome.md +115 -0
- package/docs/pt/4-agentes/neo.md +93 -0
- package/docs/pt/4-agentes/orache.md +107 -0
- package/docs/pt/4-agentes/orchestrator.md +118 -0
- package/docs/pt/4-agentes/pentester.md +131 -0
- package/docs/pt/4-agentes/pm.md +97 -0
- package/docs/pt/4-agentes/product.md +114 -0
- package/docs/pt/4-agentes/profiler-enricher.md +93 -0
- package/docs/pt/4-agentes/profiler-forge.md +93 -0
- package/docs/pt/4-agentes/profiler-researcher.md +98 -0
- package/docs/pt/4-agentes/qa.md +124 -0
- package/docs/pt/4-agentes/setup.md +104 -0
- package/docs/pt/4-agentes/sheldon.md +95 -0
- package/docs/pt/4-agentes/site-forge.md +104 -0
- package/docs/pt/4-agentes/squad.md +127 -0
- package/docs/pt/4-agentes/tester.md +105 -0
- package/docs/pt/4-agentes/ux-ui.md +110 -0
- package/docs/pt/4-agentes/validator.md +118 -0
- package/docs/pt/5-referencia/README.md +88 -0
- package/docs/pt/5-referencia/agent-chain-continuity.md +124 -0
- package/docs/pt/{agent-sharding.md → 5-referencia/agent-sharding.md} +132 -132
- package/docs/pt/5-referencia/aioson-com-store.md +119 -0
- package/docs/pt/{automacao-squads.md → 5-referencia/automacao-squads.md} +407 -407
- package/docs/pt/{clientes-ai.md → 5-referencia/clientes-ai.md} +300 -286
- package/docs/pt/{comandos-cli.md → 5-referencia/comandos-cli.md} +1823 -1634
- package/docs/pt/5-referencia/compress-agents.md +304 -0
- package/docs/pt/5-referencia/design-docs-governance.md +59 -0
- package/docs/pt/{devlog-pipeline.md → 5-referencia/devlog-pipeline.md} +270 -270
- package/docs/pt/5-referencia/feature-archive.md +199 -0
- package/docs/pt/5-referencia/feature-dossier.md +121 -0
- package/docs/pt/{fluxo-artefatos.md → 5-referencia/fluxo-artefatos.md} +179 -178
- package/docs/pt/{genome-3.0-spec.md → 5-referencia/genome-4.0-spec.md} +407 -296
- package/docs/pt/5-referencia/genome-distribution.md +232 -0
- package/docs/pt/{hooks-session-guard.md → 5-referencia/hooks-session-guard.md} +454 -454
- package/docs/pt/{inteligencia-adaptativa.md → 5-referencia/inteligencia-adaptativa.md} +324 -324
- package/docs/pt/5-referencia/live-sessions.md +144 -0
- package/docs/pt/5-referencia/memoria-e-contexto.md +340 -0
- package/docs/pt/5-referencia/motor-hardening.md +493 -0
- package/docs/pt/{output-strategy-delivery.md → 5-referencia/output-strategy-delivery.md} +655 -655
- package/docs/pt/5-referencia/runner-system.md +113 -0
- package/docs/pt/{runtime-observability.md → 5-referencia/runtime-observability.md} +76 -76
- package/docs/pt/{sandbox.md → 5-referencia/sandbox.md} +125 -125
- package/docs/pt/{sdd-automation-scripts.md → 5-referencia/sdd-automation-scripts.md} +559 -557
- package/docs/pt/5-referencia/sdd-framework.md +115 -0
- package/docs/pt/5-referencia/sdd-planos-e-estrutura.md +321 -0
- package/docs/pt/5-referencia/secure-by-default.md +117 -0
- package/docs/pt/{skills.md → 5-referencia/skills.md} +275 -267
- package/docs/pt/{spec-learnings-pipeline.md → 5-referencia/spec-learnings-pipeline.md} +265 -265
- package/docs/pt/{squad-dashboard.md → 5-referencia/squad-dashboard.md} +373 -373
- package/docs/pt/{web3.md → 5-referencia/web3.md} +797 -797
- package/docs/pt/README.md +111 -116
- package/docs/pt/_arquivo/README.md +130 -0
- package/docs/pt/{advisor-spec.md → _arquivo/advisor-spec.md} +343 -335
- package/docs/pt/{agentes-customizados.md → _arquivo/agentes-customizados.md} +678 -670
- package/docs/pt/{busca-de-contexto.md → _arquivo/busca-de-contexto.md} +136 -129
- package/docs/pt/{cache-de-contexto.md → _arquivo/cache-de-contexto.md} +163 -156
- package/docs/pt/{cenarios.md → _arquivo/cenarios.md} +1282 -1274
- package/docs/pt/{design-hybrid-forge.md → _arquivo/design-hybrid-forge.md} +365 -356
- package/docs/pt/{deyvin.md → _arquivo/deyvin.md} +123 -115
- package/docs/pt/{guia-engineer.md → _arquivo/guia-engineer.md} +234 -226
- package/docs/pt/{inicio-rapido.md → _arquivo/inicio-rapido.md} +261 -250
- package/docs/pt/{memoria-contexto.md → _arquivo/memoria-contexto.md} +262 -255
- package/docs/pt/{monitor-de-contexto.md → _arquivo/monitor-de-contexto.md} +165 -158
- package/docs/pt/{profiler-system.md → _arquivo/profiler-system.md} +222 -214
- package/docs/pt/{recuperacao-de-sessao.md → _arquivo/recuperacao-de-sessao.md} +134 -125
- package/docs/pt/{site-forge.md → _arquivo/site-forge.md} +318 -309
- package/docs/pt/{squad-genome.md → _arquivo/squad-genome.md} +793 -783
- package/docs/pt/active-learning-loop/README.md +117 -0
- package/docs/pt/active-learning-loop/ativo-learning-loop.md +117 -0
- package/docs/pt/active-learning-loop/comandos-cli.md +320 -0
- package/docs/pt/active-learning-loop/como-usar.md +313 -0
- package/docs/pt/active-learning-loop/diagramas.md +225 -0
- package/docs/pt/active-learning-loop/doctor-checks.md +151 -0
- package/docs/pt/active-learning-loop/troubleshooting.md +283 -0
- package/docs/pt/agentes.md +996 -672
- package/docs/pt/deyvin-subtask-scout/README.md +109 -0
- package/docs/pt/deyvin-subtask-scout/comandos-cli.md +248 -0
- package/docs/pt/deyvin-subtask-scout/como-usar.md +221 -0
- package/docs/pt/deyvin-subtask-scout/diagramas.md +124 -0
- package/docs/pt/deyvin-subtask-scout/sub-task-scout.md +113 -0
- package/docs/pt/deyvin-subtask-scout/troubleshooting.md +184 -0
- package/docs/pt/living-memory/README.md +81 -0
- package/docs/pt/living-memory/autonomy-contract.md +206 -0
- package/docs/pt/living-memory/diagramas.md +365 -0
- package/docs/pt/living-memory/memoria-viva.md +141 -0
- package/docs/pt/living-memory/notificacoes-info.md +142 -0
- package/docs/pt/living-memory/reflexao-in-harness.md +218 -0
- package/docs/pt/living-memory/troubleshooting.md +286 -0
- package/docs/testing/genome-2.0-manual-regression.md +23 -23
- package/docs/testing/genome-2.0-matrix.md +36 -36
- package/docs/testing/genome-2.0-rollout.md +184 -184
- package/package.json +51 -50
- package/src/a2a/client.js +165 -165
- package/src/a2a/server.js +223 -223
- package/src/agent-loader.js +280 -280
- package/src/agent-manifests.js +86 -0
- package/src/agents.js +92 -72
- package/src/autonomy-policy.js +163 -0
- package/src/backup-local.js +74 -74
- package/src/backup-provider.js +303 -303
- package/src/brain-query.js +171 -0
- package/src/cli.js +1450 -1099
- package/src/commands/agent-audit.js +397 -397
- package/src/commands/agent-export-skill.js +229 -229
- package/src/commands/agent-loader.js +85 -85
- package/src/commands/agents.js +273 -160
- package/src/commands/artifact-validate.js +218 -189
- package/src/commands/auth.js +298 -0
- package/src/commands/backup-local-cmd.js +25 -25
- package/src/commands/backup.js +533 -533
- package/src/commands/brain-query.js +44 -0
- package/src/commands/brief-gen.js +405 -405
- package/src/commands/brief-validate.js +65 -65
- package/src/commands/briefing.js +344 -0
- package/src/commands/classify.js +256 -256
- package/src/commands/cloud.js +1767 -1767
- package/src/commands/commit-prepare.js +610 -0
- package/src/commands/compress-agents.js +416 -0
- package/src/commands/config.js +90 -90
- package/src/commands/context-cache.js +90 -90
- package/src/commands/context-compact.js +49 -49
- package/src/commands/context-health.js +187 -175
- package/src/commands/context-load.js +219 -0
- package/src/commands/context-monitor.js +163 -163
- package/src/commands/context-pack.js +45 -45
- package/src/commands/context-search.js +66 -66
- package/src/commands/context-trim.js +183 -177
- package/src/commands/context-validate.js +91 -91
- package/src/commands/design-hybrid-options.js +385 -385
- package/src/commands/detect-test-runner.js +55 -55
- package/src/commands/dev-resume.js +32 -0
- package/src/commands/devlog-export-brains.js +27 -27
- package/src/commands/devlog-process.js +294 -292
- package/src/commands/devlog-watch.js +131 -131
- package/src/commands/doctor.js +123 -123
- package/src/commands/dossier-add-research.js +114 -0
- package/src/commands/dossier-audit.js +222 -0
- package/src/commands/dossier.js +423 -0
- package/src/commands/feature-archive.js +513 -0
- package/src/commands/feature-close.js +554 -165
- package/src/commands/gate-approve.js +198 -0
- package/src/commands/gate-check.js +247 -228
- package/src/commands/genome-doctor.js +489 -41
- package/src/commands/genome-migrate.js +49 -49
- package/src/commands/git-guard.js +170 -0
- package/src/commands/harness.js +307 -0
- package/src/commands/health.js +214 -214
- package/src/commands/hooks-emit.js +253 -253
- package/src/commands/hooks-install.js +347 -347
- package/src/commands/i18n-add.js +56 -56
- package/src/commands/implementation-plan.js +367 -340
- package/src/commands/info.js +41 -41
- package/src/commands/init.js +120 -116
- package/src/commands/install.js +162 -107
- package/src/commands/learning-auto-promote.js +197 -195
- package/src/commands/learning-evolve.js +364 -364
- package/src/commands/learning-export.js +103 -103
- package/src/commands/learning-rollback.js +164 -164
- package/src/commands/learning.js +134 -134
- package/src/commands/live.js +2101 -1641
- package/src/commands/locale-apply.js +54 -51
- package/src/commands/locale-diff.js +25 -126
- package/src/commands/mcp-doctor.js +407 -406
- package/src/commands/mcp-init.js +373 -379
- package/src/commands/memory-archive.js +193 -0
- package/src/commands/memory-reflect-commit.js +148 -0
- package/src/commands/memory-reflect-prepare.js +97 -0
- package/src/commands/memory-restore.js +177 -0
- package/src/commands/memory-search.js +135 -0
- package/src/commands/memory.js +299 -0
- package/src/commands/notify.js +68 -0
- package/src/commands/package-e2e.js +273 -273
- package/src/commands/parallel-assign.js +483 -403
- package/src/commands/parallel-doctor.js +850 -437
- package/src/commands/parallel-guard.js +241 -0
- package/src/commands/parallel-init.js +311 -249
- package/src/commands/parallel-merge.js +299 -0
- package/src/commands/parallel-status.js +434 -290
- package/src/commands/pattern-detect.js +33 -33
- package/src/commands/preflight-context.js +30 -30
- package/src/commands/preflight.js +267 -208
- package/src/commands/pulse-update.js +130 -130
- package/src/commands/qa-doctor.js +185 -185
- package/src/commands/qa-init.js +166 -161
- package/src/commands/qa-report.js +58 -58
- package/src/commands/qa-run.js +873 -873
- package/src/commands/qa-scan.js +337 -337
- package/src/commands/recovery.js +43 -43
- package/src/commands/revision.js +235 -0
- package/src/commands/runner-daemon.js +274 -274
- package/src/commands/runner-plan.js +70 -70
- package/src/commands/runner-queue-from-plan.js +166 -166
- package/src/commands/runner-queue.js +189 -189
- package/src/commands/runner-run.js +129 -129
- package/src/commands/runtime.js +2086 -2067
- package/src/commands/sandbox.js +37 -37
- package/src/commands/scaffold-complete.js +188 -0
- package/src/commands/scan-project.js +1371 -1371
- package/src/commands/scout-commit.js +163 -0
- package/src/commands/scout-prep.js +214 -0
- package/src/commands/scout-validate.js +112 -0
- package/src/commands/security-audit.js +275 -0
- package/src/commands/security-scan.js +376 -0
- package/src/commands/self-implement-loop.js +306 -256
- package/src/commands/session-guard.js +218 -218
- package/src/commands/setup-context.js +699 -698
- package/src/commands/setup.js +178 -178
- package/src/commands/sizing.js +165 -165
- package/src/commands/skill.js +670 -670
- package/src/commands/smoke.js +426 -426
- package/src/commands/spec-checkpoint.js +177 -177
- package/src/commands/spec-status.js +79 -79
- package/src/commands/spec-sync.js +190 -190
- package/src/commands/spec-tasks.js +288 -288
- package/src/commands/squad-agent-create.js +830 -788
- package/src/commands/squad-autorun.js +1220 -1220
- package/src/commands/squad-bus.js +217 -217
- package/src/commands/squad-card.js +149 -149
- package/src/commands/squad-daemon.js +343 -343
- package/src/commands/squad-dashboard.js +39 -39
- package/src/commands/squad-dependency-graph.js +164 -164
- package/src/commands/squad-deploy.js +64 -64
- package/src/commands/squad-doctor.js +460 -460
- package/src/commands/squad-export.js +77 -46
- package/src/commands/squad-investigate.js +314 -261
- package/src/commands/squad-learning.js +209 -209
- package/src/commands/squad-mcp.js +270 -270
- package/src/commands/squad-pipeline.js +343 -343
- package/src/commands/squad-plan.js +361 -329
- package/src/commands/squad-processes.js +56 -56
- package/src/commands/squad-recovery.js +42 -42
- package/src/commands/squad-repair-genomes.js +39 -39
- package/src/commands/squad-review.js +106 -106
- package/src/commands/squad-roi.js +291 -291
- package/src/commands/squad-scaffold.js +56 -55
- package/src/commands/squad-score.js +311 -250
- package/src/commands/squad-status.js +481 -460
- package/src/commands/squad-tool-register.js +157 -157
- package/src/commands/squad-validate.js +438 -347
- package/src/commands/squad-webhook.js +160 -160
- package/src/commands/squad-worker.js +191 -191
- package/src/commands/squad-worktrees.js +75 -75
- package/src/commands/state-save.js +122 -122
- package/src/commands/store-genome.js +667 -0
- package/src/commands/store-skill.js +247 -0
- package/src/commands/store-squad.js +431 -0
- package/src/commands/store-system.js +392 -0
- package/src/commands/sync-agents-preflight.js +176 -0
- package/src/commands/test-agents.js +199 -199
- package/src/commands/tool-capabilities.js +63 -0
- package/src/commands/tool-registry-cmd.js +232 -232
- package/src/commands/update.js +64 -64
- package/src/commands/verify-gate.js +612 -572
- package/src/commands/web-map.js +70 -70
- package/src/commands/web-scrape.js +71 -71
- package/src/commands/workflow-execute.js +730 -241
- package/src/commands/workflow-harden.js +231 -0
- package/src/commands/workflow-heal.js +136 -0
- package/src/commands/workflow-next.js +1279 -601
- package/src/commands/workflow-plan.js +108 -108
- package/src/commands/workflow-status.js +440 -250
- package/src/commands/workspace.js +144 -0
- package/src/constants.js +413 -417
- package/src/context-cache.js +159 -159
- package/src/context-memory.js +975 -837
- package/src/context-parse-reason.js +22 -22
- package/src/context-search.js +326 -326
- package/src/context-writer.js +197 -196
- package/src/context.js +247 -217
- package/src/delivery-runner.js +319 -319
- package/src/design-variation-catalog.js +503 -503
- package/src/detector.js +261 -261
- package/src/doctor.js +760 -289
- package/src/dossier/codemap-store.js +267 -0
- package/src/dossier/dossier-bootstrap.js +222 -0
- package/src/dossier/dossier-compact.js +159 -0
- package/src/dossier/lock.js +128 -0
- package/src/dossier/research-index-store.js +233 -0
- package/src/dossier/revision-store.js +313 -0
- package/src/dossier/schema.js +162 -0
- package/src/dossier/scout-section.js +127 -0
- package/src/dossier/store.js +406 -0
- package/src/execution-gateway.js +464 -461
- package/src/friction-scanner.js +202 -0
- package/src/genome-files.js +198 -198
- package/src/genome-format.js +442 -442
- package/src/genome-schema.js +238 -215
- package/src/genomes/bindings.js +281 -281
- package/src/genomes.js +500 -467
- package/src/handoff-contract.js +417 -0
- package/src/handoff-validator.js +45 -0
- package/src/harness/circuit-breaker.js +135 -0
- package/src/i18n/index.js +103 -103
- package/src/i18n/messages/en.js +1541 -1139
- package/src/i18n/messages/es.js +1325 -980
- package/src/i18n/messages/fr.js +1333 -987
- package/src/i18n/messages/pt-BR.js +1561 -1166
- package/src/i18n/scaffold.js +64 -64
- package/src/install-animation.js +260 -260
- package/src/install-profile.js +127 -143
- package/src/install-wizard.js +475 -475
- package/src/installer-config-merge.js +207 -0
- package/src/installer.js +449 -294
- package/src/learning-loop-archive.js +595 -0
- package/src/learning-loop-doctor.js +217 -0
- package/src/learning-loop-engine.js +254 -0
- package/src/learning-loop-fts5.js +132 -0
- package/src/learning-loop-migration.js +163 -0
- package/src/lib/dev-resume.js +140 -0
- package/src/lib/dossier-telemetry.js +36 -0
- package/src/lib/genomes/compat.js +206 -206
- package/src/lib/genomes/migrate.js +90 -90
- package/src/lib/git-commit-guard.js +751 -0
- package/src/lib/health-check.js +158 -158
- package/src/lib/hook-protocol.js +76 -76
- package/src/lib/llm-content-sanitizer.js +44 -0
- package/src/lib/security/artifact-reader.js +167 -0
- package/src/lib/security/exit-codes.js +51 -0
- package/src/lib/security/findings-writer.js +176 -0
- package/src/lib/security/runtime-events.js +77 -0
- package/src/lib/security/secrets-regex.js +115 -0
- package/src/lib/squads/genome-repair.js +49 -49
- package/src/lib/store/security-scan.js +175 -0
- package/src/lib/terminal-checkbox.js +135 -0
- package/src/lib/terminal-picker.js +447 -0
- package/src/lib/tmux-launcher.js +163 -0
- package/src/lib/tool-capabilities.js +102 -0
- package/src/lib/webhook-server.js +328 -328
- package/src/locales.js +88 -84
- package/src/mcp/apps/squad-dashboard/app.js +163 -163
- package/src/mcp/apps/squad-dashboard/index.html +261 -261
- package/src/mcp/apps/squad-dashboard/mcp-manifest.json +23 -23
- package/src/mcp/resources/squad-state.js +130 -130
- package/src/mcp-connectors/registry.js +602 -602
- package/src/memory-reflect-engine.js +359 -0
- package/src/notify-renderer.js +32 -0
- package/src/onboarding.js +305 -305
- package/src/parallel-workspace.js +756 -0
- package/src/parser.js +66 -59
- package/src/path-guard.js +47 -0
- package/src/permissions-generator.js +400 -0
- package/src/preflight-engine.js +654 -443
- package/src/prompt-tool.js +20 -20
- package/src/qa-html-report.js +472 -472
- package/src/recovery-context-session.js +154 -154
- package/src/runner/cascade.js +97 -97
- package/src/runner/cli-launcher.js +109 -109
- package/src/runner/plan-importer.js +63 -63
- package/src/runner/queue-store.js +159 -159
- package/src/runtime-store.js +2720 -2676
- package/src/sandbox.js +194 -177
- package/src/self-healing.js +142 -0
- package/src/session-handoff.js +295 -77
- package/src/squad/agent-teams-adapter.js +270 -264
- package/src/squad/brief-validator.js +350 -350
- package/src/squad/bus-bridge.js +140 -140
- package/src/squad/context-compactor.js +265 -265
- package/src/squad/cross-ai-synthesizer.js +250 -250
- package/src/squad/external-session.js +180 -180
- package/src/squad/hooks-generator.js +196 -196
- package/src/squad/inter-squad-events.js +175 -175
- package/src/squad/inter-squad.js +74 -74
- package/src/squad/intra-bus.js +345 -345
- package/src/squad/learning-extractor.js +213 -213
- package/src/squad/pattern-detector.js +365 -365
- package/src/squad/preflight-context.js +296 -296
- package/src/squad/recovery-context.js +372 -372
- package/src/squad/reflection.js +365 -365
- package/src/squad/squad-scaffold.js +341 -177
- package/src/squad/state-manager.js +310 -310
- package/src/squad/task-decomposer.js +652 -652
- package/src/squad/verify-gate.js +303 -303
- package/src/squad/worktree-manager.js +114 -114
- package/src/squad-daemon.js +490 -490
- package/src/squad-dashboard/api.js +223 -223
- package/src/squad-dashboard/attachment-handler.js +93 -93
- package/src/squad-dashboard/context-monitor.js +157 -157
- package/src/squad-dashboard/execution-logs.js +115 -115
- package/src/squad-dashboard/hunk-review.js +209 -209
- package/src/squad-dashboard/metrics.js +133 -133
- package/src/squad-dashboard/process-monitor.js +125 -125
- package/src/squad-dashboard/renderer.js +858 -858
- package/src/squad-dashboard/server.js +232 -232
- package/src/squad-dashboard/styles.js +525 -525
- package/src/squad-dashboard/token-tracker.js +99 -99
- package/src/squads/apply-genome.js +21 -21
- package/src/squads/genome-binding-service.js +154 -154
- package/src/sub-task-engine.js +415 -0
- package/src/sub-task-schemas.js +150 -0
- package/src/sub-task-state.js +152 -0
- package/src/sub-task-telemetry.js +69 -0
- package/src/test-briefing.js +226 -0
- package/src/tool-executor.js +94 -94
- package/src/updater.js +39 -39
- package/src/utils.js +49 -46
- package/src/version.js +50 -50
- package/src/web.js +284 -284
- package/src/worker-runner.js +541 -524
- package/src/workflow-gates.js +185 -0
- package/template/.aioson/advisors/.gitkeep +1 -1
- package/template/.aioson/agents/analyst.md +333 -372
- package/template/.aioson/agents/architect.md +325 -338
- package/template/.aioson/agents/briefing.md +264 -0
- package/template/.aioson/agents/committer.md +161 -0
- package/template/.aioson/agents/copywriter.md +937 -463
- package/template/.aioson/agents/design-hybrid-forge.md +141 -141
- package/template/.aioson/agents/dev.md +295 -779
- package/template/.aioson/agents/deyvin.md +198 -290
- package/template/.aioson/agents/discover.md +235 -0
- package/template/.aioson/agents/discovery-design-doc.md +56 -264
- package/template/.aioson/agents/genome.md +1904 -314
- package/template/.aioson/agents/manifests/analyst.manifest.json +26 -0
- package/template/.aioson/agents/manifests/architect.manifest.json +23 -0
- package/template/.aioson/agents/manifests/committer.manifest.json +23 -0
- package/template/.aioson/agents/manifests/dev.manifest.json +54 -0
- package/template/.aioson/agents/manifests/deyvin.manifest.json +41 -0
- package/template/.aioson/agents/manifests/orchestrator.manifest.json +30 -0
- package/template/.aioson/agents/manifests/pentester.manifest.json +39 -0
- package/template/.aioson/agents/manifests/pm.manifest.json +26 -0
- package/template/.aioson/agents/manifests/product.manifest.json +23 -0
- package/template/.aioson/agents/manifests/qa.manifest.json +41 -0
- package/template/.aioson/agents/manifests/setup.manifest.json +20 -0
- package/template/.aioson/agents/manifests/ux-ui.manifest.json +24 -0
- package/template/.aioson/agents/neo.md +341 -233
- package/template/.aioson/agents/orache.md +430 -434
- package/template/.aioson/agents/orchestrator.md +274 -364
- package/template/.aioson/agents/pair.md +5 -5
- package/template/.aioson/agents/pentester.md +289 -0
- package/template/.aioson/agents/pm.md +141 -194
- package/template/.aioson/agents/product.md +351 -518
- package/template/.aioson/agents/profiler-enricher.md +331 -280
- package/template/.aioson/agents/profiler-forge.md +212 -202
- package/template/.aioson/agents/profiler-researcher.md +282 -259
- package/template/.aioson/agents/qa.md +432 -688
- package/template/.aioson/agents/setup.md +423 -649
- package/template/.aioson/agents/sheldon.md +259 -829
- package/template/.aioson/agents/site-forge.md +281 -1753
- package/template/.aioson/agents/squad.md +160 -2027
- package/template/.aioson/agents/tester.md +536 -463
- package/template/.aioson/agents/ux-ui.md +195 -870
- package/template/.aioson/agents/validator.md +101 -0
- package/template/.aioson/brains/README.md +132 -128
- package/template/.aioson/brains/_archived/.gitkeep +0 -0
- package/template/.aioson/brains/_index.json +34 -16
- package/template/.aioson/brains/dev/patterns.brain.json +79 -0
- package/template/.aioson/brains/scripts/query.js +107 -103
- package/template/.aioson/brains/sheldon/architecture-decisions.brain.json +79 -0
- package/template/.aioson/brains/site-forge/visual-patterns.brain.json +205 -205
- package/template/.aioson/config/autonomy-protocol.json +125 -0
- package/template/.aioson/config/learning-loop.json +10 -0
- package/template/.aioson/config/scout-engine.json +1 -0
- package/template/.aioson/config.md +410 -382
- package/template/.aioson/constitution.md +36 -33
- package/template/.aioson/context/_archived/.gitkeep +0 -0
- package/template/.aioson/context/design-doc.md +136 -0
- package/template/.aioson/context/project-map.md +57 -0
- package/template/.aioson/context/project-pulse.md +34 -34
- package/template/.aioson/context/seeds/seed-example.md +27 -27
- package/template/.aioson/context/spec.md.template +54 -54
- package/template/.aioson/context/user-profile.md +42 -42
- package/template/.aioson/design-docs/code-reuse.md +48 -0
- package/template/.aioson/design-docs/componentization.md +47 -0
- package/template/.aioson/design-docs/file-size.md +52 -0
- package/template/.aioson/design-docs/folder-structure.md +51 -0
- package/template/.aioson/design-docs/naming.md +54 -0
- package/template/.aioson/docs/LAYERS.md +89 -79
- package/template/.aioson/docs/README.md +76 -76
- package/template/.aioson/docs/autonomy-protocol.md +80 -0
- package/template/.aioson/docs/briefing/briefing-craft.md +237 -0
- package/template/.aioson/docs/dev/execution-discipline.md +106 -0
- package/template/.aioson/docs/dev/stack-conventions.md +83 -0
- package/template/.aioson/docs/deyvin/continuity-recovery.md +57 -0
- package/template/.aioson/docs/deyvin/debugging-escalation.md +30 -0
- package/template/.aioson/docs/deyvin/pair-execution.md +44 -0
- package/template/.aioson/docs/deyvin/runtime-handoffs.md +36 -0
- package/template/.aioson/docs/example-external-api-context.md +72 -72
- package/template/.aioson/docs/pentester/app-playbooks.md +206 -0
- package/template/.aioson/docs/pentester/llm-supplychain.md +165 -0
- package/template/.aioson/docs/product/conversation-playbook.md +116 -0
- package/template/.aioson/docs/product/prd-contract.md +107 -0
- package/template/.aioson/docs/product/quality-lens.md +57 -0
- package/template/.aioson/docs/product/research-loop.md +65 -0
- package/template/.aioson/docs/sheldon/enrichment-paths.md +134 -0
- package/template/.aioson/docs/sheldon/harness-contract.md +118 -0
- package/template/.aioson/docs/sheldon/quality-lens.md +57 -0
- package/template/.aioson/docs/sheldon/research-loop.md +56 -0
- package/template/.aioson/docs/sheldon/web-intelligence.md +75 -0
- package/template/.aioson/docs/site-forge-build.md +195 -0
- package/template/.aioson/docs/site-forge-extraction.md +135 -0
- package/template/.aioson/docs/site-forge-qa.md +155 -0
- package/template/.aioson/docs/site-forge-recon.md +434 -0
- package/template/.aioson/docs/site-forge-transform.md +249 -0
- package/template/.aioson/docs/squad/content-output.md +91 -0
- package/template/.aioson/docs/squad/creation-flow.md +149 -0
- package/template/.aioson/docs/squad/domain-breadth.md +322 -0
- package/template/.aioson/docs/squad/domain-classification.md +117 -0
- package/template/.aioson/docs/squad/genome-bindings.md +47 -0
- package/template/.aioson/docs/squad/package-contract.md +260 -0
- package/template/.aioson/docs/squad/quality-lens.md +60 -0
- package/template/.aioson/docs/squad/research-loop.md +59 -0
- package/template/.aioson/docs/squad/session-operations.md +117 -0
- package/template/.aioson/docs/squad/workflow-quality.md +165 -0
- package/template/.aioson/docs/tester/coverage-quality.md +351 -0
- package/template/.aioson/docs/ux-ui/accessibility-audit.md +55 -0
- package/template/.aioson/docs/ux-ui/audit-mode.md +86 -0
- package/template/.aioson/docs/ux-ui/component-map.md +35 -0
- package/template/.aioson/docs/ux-ui/design-execution.md +111 -0
- package/template/.aioson/docs/ux-ui/design-gate.md +27 -0
- package/template/.aioson/docs/ux-ui/research-mode.md +39 -0
- package/template/.aioson/docs/ux-ui/site-delivery.md +156 -0
- package/template/.aioson/docs/ux-ui/token-contract.md +57 -0
- package/template/.aioson/genomes/INDEX.md +195 -0
- package/template/.aioson/genomes/copywriting/SKILL.md +137 -0
- package/template/.aioson/genomes/copywriting/manifest.json +140 -0
- package/template/.aioson/genomes/copywriting/references/application-notes.md +145 -0
- package/template/.aioson/genomes/copywriting/references/decision-weights.md +45 -0
- package/template/.aioson/genomes/copywriting/references/frameworks/5-act-narrative.md +184 -0
- package/template/.aioson/genomes/copywriting/references/frameworks/classical-formulas.md +164 -0
- package/template/.aioson/genomes/copywriting/references/frameworks/offer-stack.md +195 -0
- package/template/.aioson/genomes/copywriting/references/frameworks/one-belief.md +135 -0
- package/template/.aioson/genomes/copywriting/references/frameworks/pms-research.md +211 -0
- package/template/.aioson/genomes/copywriting/references/frameworks/two-paths-close.md +190 -0
- package/template/.aioson/genomes/copywriting/references/heuristics.md +114 -0
- package/template/.aioson/genomes/copywriting/references/meta-axioms.md +68 -0
- package/template/.aioson/genomes/copywriting/references/methodology.md +115 -0
- package/template/.aioson/genomes/copywriting-brunson/SKILL.md +133 -0
- package/template/.aioson/genomes/copywriting-brunson/manifest.json +152 -0
- package/template/.aioson/genomes/copywriting-brunson/references/application-notes.md +113 -0
- package/template/.aioson/genomes/copywriting-brunson/references/decision-weights.md +33 -0
- package/template/.aioson/genomes/copywriting-brunson/references/evidence-and-attribution.md +81 -0
- package/template/.aioson/genomes/copywriting-brunson/references/frameworks/6-part-structure.md +136 -0
- package/template/.aioson/genomes/copywriting-brunson/references/frameworks/origin-story.md +121 -0
- package/template/.aioson/genomes/copywriting-brunson/references/frameworks/perfect-webinar-script.md +139 -0
- package/template/.aioson/genomes/copywriting-brunson/references/frameworks/persuasive-storytelling-5-structures.md +164 -0
- package/template/.aioson/genomes/copywriting-brunson/references/frameworks/value-stack.md +136 -0
- package/template/.aioson/genomes/copywriting-brunson/references/frameworks/who-what-why-how.md +110 -0
- package/template/.aioson/genomes/copywriting-brunson/references/meta-axioms.md +36 -0
- package/template/.aioson/genomes/copywriting-brunson/references/methodology.md +112 -0
- package/template/.aioson/git-guard.json +12 -0
- package/template/.aioson/mcp/servers.md +23 -24
- package/template/.aioson/profiler-reports/.gitkeep +1 -1
- package/template/.aioson/rules/README.md +69 -69
- package/template/.aioson/rules/_archived/.gitkeep +0 -0
- package/template/.aioson/rules/agent-language-policy.md +93 -0
- package/template/.aioson/rules/aioson-context-boundary.md +63 -0
- package/template/.aioson/rules/canonical-path-contract.md +47 -0
- package/template/.aioson/rules/data-format-convention.md +74 -136
- package/template/.aioson/rules/disk-first-artifacts.md +44 -0
- package/template/.aioson/rules/example-monetary-values.md +30 -30
- package/template/.aioson/rules/output-brevity.md +44 -0
- package/template/.aioson/rules/prd-section-ownership.md +49 -0
- package/template/.aioson/rules/security-baseline.md +139 -0
- package/template/.aioson/rules/spec-level-ownership.md +61 -0
- package/template/.aioson/rules/squad/README.md +50 -50
- package/template/.aioson/rules/squad-driver-pattern.md +81 -0
- package/template/.aioson/schemas/content-blueprint.schema.json +30 -30
- package/template/.aioson/schemas/genome-meta.schema.json +150 -150
- package/template/.aioson/schemas/genome.schema.json +115 -115
- package/template/.aioson/schemas/readiness.schema.json +27 -27
- package/template/.aioson/schemas/squad-blueprint.schema.json +228 -204
- package/template/.aioson/schemas/squad-manifest.schema.json +874 -830
- package/template/.aioson/skills/design/aurora-command-ui/SKILL.md +243 -243
- package/template/.aioson/skills/design/aurora-command-ui/references/art-direction.md +293 -293
- package/template/.aioson/skills/design/aurora-command-ui/references/components.md +827 -827
- package/template/.aioson/skills/design/aurora-command-ui/references/dashboards.md +250 -250
- package/template/.aioson/skills/design/aurora-command-ui/references/design-tokens.md +585 -585
- package/template/.aioson/skills/design/aurora-command-ui/references/motion.md +365 -365
- package/template/.aioson/skills/design/aurora-command-ui/references/patterns.md +482 -482
- package/template/.aioson/skills/design/aurora-command-ui/references/websites.md +387 -387
- package/template/.aioson/skills/design/bold-editorial-ui/SKILL.md +205 -205
- package/template/.aioson/skills/design/bold-editorial-ui/references/art-direction.md +338 -338
- package/template/.aioson/skills/design/bold-editorial-ui/references/components.md +977 -977
- package/template/.aioson/skills/design/bold-editorial-ui/references/dashboards.md +218 -218
- package/template/.aioson/skills/design/bold-editorial-ui/references/design-tokens.md +326 -326
- package/template/.aioson/skills/design/bold-editorial-ui/references/motion.md +461 -461
- package/template/.aioson/skills/design/bold-editorial-ui/references/patterns.md +293 -293
- package/template/.aioson/skills/design/bold-editorial-ui/references/websites.md +352 -352
- package/template/.aioson/skills/design/clean-saas-ui/SKILL.md +210 -210
- package/template/.aioson/skills/design/clean-saas-ui/references/art-direction.md +319 -319
- package/template/.aioson/skills/design/clean-saas-ui/references/components.md +365 -365
- package/template/.aioson/skills/design/clean-saas-ui/references/dashboards.md +196 -196
- package/template/.aioson/skills/design/clean-saas-ui/references/design-tokens.md +244 -244
- package/template/.aioson/skills/design/clean-saas-ui/references/motion.md +235 -235
- package/template/.aioson/skills/design/clean-saas-ui/references/patterns.md +215 -215
- package/template/.aioson/skills/design/clean-saas-ui/references/websites.md +295 -295
- package/template/.aioson/skills/design/cognitive-core-ui/SKILL.md +203 -203
- package/template/.aioson/skills/design/cognitive-core-ui/references/art-direction.md +339 -339
- package/template/.aioson/skills/design/cognitive-core-ui/references/components.md +407 -407
- package/template/.aioson/skills/design/cognitive-core-ui/references/dashboards.md +272 -272
- package/template/.aioson/skills/design/cognitive-core-ui/references/design-tokens.md +524 -524
- package/template/.aioson/skills/design/cognitive-core-ui/references/motion.md +279 -279
- package/template/.aioson/skills/design/cognitive-core-ui/references/patterns.md +289 -289
- package/template/.aioson/skills/design/cognitive-core-ui/references/websites.md +437 -437
- package/template/.aioson/skills/design/glassmorphism-ui/SKILL.md +222 -222
- package/template/.aioson/skills/design/glassmorphism-ui/references/art-direction.md +159 -159
- package/template/.aioson/skills/design/glassmorphism-ui/references/components.md +498 -498
- package/template/.aioson/skills/design/glassmorphism-ui/references/dashboards.md +236 -236
- package/template/.aioson/skills/design/glassmorphism-ui/references/design-tokens.md +274 -274
- package/template/.aioson/skills/design/glassmorphism-ui/references/motion.md +355 -355
- package/template/.aioson/skills/design/glassmorphism-ui/references/patterns.md +198 -198
- package/template/.aioson/skills/design/glassmorphism-ui/references/websites.md +307 -307
- package/template/.aioson/skills/design/interface-design/SKILL.md +47 -47
- package/template/.aioson/skills/design/interface-design/references/components-and-states.md +105 -105
- package/template/.aioson/skills/design/interface-design/references/design-directions.md +101 -101
- package/template/.aioson/skills/design/interface-design/references/handoff-and-quality.md +71 -71
- package/template/.aioson/skills/design/interface-design/references/intent-and-domain.md +74 -74
- package/template/.aioson/skills/design/interface-design/references/tokens-and-depth.md +173 -173
- package/template/.aioson/skills/design/neo-brutalist-ui/SKILL.md +213 -213
- package/template/.aioson/skills/design/neo-brutalist-ui/references/art-direction.md +228 -228
- package/template/.aioson/skills/design/neo-brutalist-ui/references/components.md +855 -855
- package/template/.aioson/skills/design/neo-brutalist-ui/references/dashboards.md +334 -334
- package/template/.aioson/skills/design/neo-brutalist-ui/references/design-tokens.md +342 -342
- package/template/.aioson/skills/design/neo-brutalist-ui/references/motion.md +286 -286
- package/template/.aioson/skills/design/neo-brutalist-ui/references/patterns.md +458 -458
- package/template/.aioson/skills/design/neo-brutalist-ui/references/websites.md +723 -723
- package/template/.aioson/skills/design/premium-command-center-ui/SKILL.md +62 -62
- package/template/.aioson/skills/design/premium-command-center-ui/references/operations.md +74 -74
- package/template/.aioson/skills/design/premium-command-center-ui/references/patterns.md +116 -116
- package/template/.aioson/skills/design/premium-command-center-ui/references/validation.md +47 -47
- package/template/.aioson/skills/design/premium-command-center-ui/references/visual-system.md +215 -215
- package/template/.aioson/skills/design/pt.squarespace.com/.skill-meta.json +31 -31
- package/template/.aioson/skills/design/pt.squarespace.com/SKILL.md +66 -66
- package/template/.aioson/skills/design/pt.squarespace.com/references/components.md +368 -368
- package/template/.aioson/skills/design/pt.squarespace.com/references/design-tokens.md +150 -150
- package/template/.aioson/skills/design/pt.squarespace.com/references/motion.md +270 -270
- package/template/.aioson/skills/design/pt.squarespace.com/references/patterns.md +189 -189
- package/template/.aioson/skills/design/pt.squarespace.com/references/websites.md +165 -165
- package/template/.aioson/skills/design/warm-craft-ui/SKILL.md +209 -209
- package/template/.aioson/skills/design/warm-craft-ui/references/art-direction.md +324 -324
- package/template/.aioson/skills/design/warm-craft-ui/references/components.md +508 -508
- package/template/.aioson/skills/design/warm-craft-ui/references/dashboards.md +223 -223
- package/template/.aioson/skills/design/warm-craft-ui/references/design-tokens.md +374 -374
- package/template/.aioson/skills/design/warm-craft-ui/references/motion.md +356 -356
- package/template/.aioson/skills/design/warm-craft-ui/references/patterns.md +288 -288
- package/template/.aioson/skills/design/warm-craft-ui/references/websites.md +289 -289
- package/template/.aioson/skills/design-system/SKILL.md +92 -92
- package/template/.aioson/skills/design-system/components/SKILL.md +274 -274
- package/template/.aioson/skills/design-system/dashboards/SKILL.md +184 -184
- package/template/.aioson/skills/design-system/foundations/SKILL.md +250 -250
- package/template/.aioson/skills/design-system/motion/SKILL.md +197 -197
- package/template/.aioson/skills/design-system/patterns/SKILL.md +231 -231
- package/template/.aioson/skills/dynamic/README.md +30 -30
- package/template/.aioson/skills/dynamic/cardano-docs.md +16 -16
- package/template/.aioson/skills/dynamic/ethereum-docs.md +17 -17
- package/template/.aioson/skills/dynamic/flux-ui-docs.md +13 -13
- package/template/.aioson/skills/dynamic/laravel-docs.md +41 -41
- package/template/.aioson/skills/dynamic/npm-packages.md +16 -16
- package/template/.aioson/skills/dynamic/solana-docs.md +16 -16
- package/template/.aioson/skills/marketing/references/anti-patterns.md +254 -254
- package/template/.aioson/skills/marketing/references/cta-matrix.md +361 -0
- package/template/.aioson/skills/marketing/references/fascinations.md +192 -192
- package/template/.aioson/skills/marketing/references/five-acts.md +248 -248
- package/template/.aioson/skills/marketing/references/headline-matrix.md +358 -0
- package/template/.aioson/skills/marketing/references/market-intelligence.md +198 -198
- package/template/.aioson/skills/marketing/references/offer-structure.md +203 -203
- package/template/.aioson/skills/marketing/references/one-belief.md +149 -149
- package/template/.aioson/skills/marketing/references/patterns.md +218 -218
- package/template/.aioson/skills/marketing/references/platform-constraints.md +337 -0
- package/template/.aioson/skills/marketing/references/pms-research.md +193 -193
- package/template/.aioson/skills/marketing/vsl-craft.md +385 -385
- package/template/.aioson/skills/premium-visual-design/SKILL.md +83 -83
- package/template/.aioson/skills/premium-visual-design/components/agent-badge.md +92 -92
- package/template/.aioson/skills/premium-visual-design/components/dependency-node.md +102 -102
- package/template/.aioson/skills/premium-visual-design/components/mention-autocomplete.md +136 -136
- package/template/.aioson/skills/premium-visual-design/components/notification-center.md +136 -136
- package/template/.aioson/skills/premium-visual-design/components/review-action-bar.md +188 -188
- package/template/.aioson/skills/premium-visual-design/components/team-switcher.md +131 -131
- package/template/.aioson/skills/premium-visual-design/patterns/agent-message-thread.md +198 -198
- package/template/.aioson/skills/premium-visual-design/patterns/notification-panel.md +275 -275
- package/template/.aioson/skills/premium-visual-design/patterns/review-workflow-ui.md +234 -234
- package/template/.aioson/skills/premium-visual-design/patterns/task-dependency-graph.md +147 -147
- package/template/.aioson/skills/premium-visual-design/tokens/status-extended.md +142 -142
- package/template/.aioson/skills/process/aioson-spec-driven/SKILL.md +46 -46
- package/template/.aioson/skills/process/aioson-spec-driven/references/analyst.md +30 -30
- package/template/.aioson/skills/process/aioson-spec-driven/references/approval-gates.md +109 -109
- package/template/.aioson/skills/process/aioson-spec-driven/references/architect.md +23 -23
- package/template/.aioson/skills/process/aioson-spec-driven/references/artifact-map.md +44 -44
- package/template/.aioson/skills/process/aioson-spec-driven/references/classification-map.md +37 -37
- package/template/.aioson/skills/process/aioson-spec-driven/references/dev.md +47 -47
- package/template/.aioson/skills/process/aioson-spec-driven/references/deyvin.md +27 -27
- package/template/.aioson/skills/process/aioson-spec-driven/references/hardening-lane.md +49 -49
- package/template/.aioson/skills/process/aioson-spec-driven/references/maintenance-and-state.md +101 -101
- package/template/.aioson/skills/process/aioson-spec-driven/references/pm.md +30 -0
- package/template/.aioson/skills/process/aioson-spec-driven/references/product.md +25 -25
- package/template/.aioson/skills/process/aioson-spec-driven/references/qa.md +30 -30
- package/template/.aioson/skills/process/aioson-spec-driven/references/sheldon.md +25 -25
- package/template/.aioson/skills/process/aioson-spec-driven/references/ui-language.md +75 -75
- package/template/.aioson/skills/process/design-hybrid-forge/SKILL.md +147 -147
- package/template/.aioson/skills/process/design-hybrid-forge/references/crossover-protocol.md +221 -221
- package/template/.aioson/skills/process/design-hybrid-forge/references/naming-registry.md +88 -88
- package/template/.aioson/skills/process/design-hybrid-forge/references/output-contract.md +306 -306
- package/template/.aioson/skills/process/design-hybrid-forge/references/pair-compatibility.md +149 -149
- package/template/.aioson/skills/process/design-hybrid-forge/references/quality-gates.md +208 -208
- package/template/.aioson/skills/process/design-hybrid-forge/references/variation-library.md +125 -125
- package/template/.aioson/skills/process/secure-tdd/SKILL.md +97 -0
- package/template/.aioson/skills/process/simplify/SKILL.md +173 -173
- package/template/.aioson/skills/references/premium-command-center-ui/master-application-prompt.md +79 -79
- package/template/.aioson/skills/references/premium-command-center-ui/operational-ux-playbook.md +253 -253
- package/template/.aioson/skills/references/premium-command-center-ui/quality-validation-checklist.md +82 -82
- package/template/.aioson/skills/references/premium-command-center-ui/visual-system-and-component-patterns.md +270 -270
- package/template/.aioson/skills/squad/SKILL.md +58 -58
- package/template/.aioson/skills/squad/formats/catalog.json +15 -15
- package/template/.aioson/skills/squad/formats/content/blog-post.md +47 -47
- package/template/.aioson/skills/squad/formats/content/newsletter.md +47 -47
- package/template/.aioson/skills/squad/formats/creative/podcast-script.md +43 -43
- package/template/.aioson/skills/squad/formats/creative/video-script.md +41 -41
- package/template/.aioson/skills/squad/formats/social/instagram-feed.md +42 -42
- package/template/.aioson/skills/squad/formats/social/linkedin-post.md +42 -42
- package/template/.aioson/skills/squad/formats/social/tiktok.md +39 -39
- package/template/.aioson/skills/squad/formats/social/twitter-thread.md +39 -39
- package/template/.aioson/skills/squad/formats/social/youtube-long.md +47 -47
- package/template/.aioson/skills/squad/formats/social/youtube-shorts.md +39 -39
- package/template/.aioson/skills/squad/patterns/multi-platform-pattern.md +108 -108
- package/template/.aioson/skills/squad/patterns/persona-based-pattern.md +98 -98
- package/template/.aioson/skills/squad/patterns/pipeline-pattern.md +106 -106
- package/template/.aioson/skills/squad/patterns/review-loop-pattern.md +81 -81
- package/template/.aioson/skills/squad/references/checklist-templates.md +122 -122
- package/template/.aioson/skills/squad/references/executor-archetypes.md +123 -123
- package/template/.aioson/skills/squad/references/workflow-templates.md +169 -169
- package/template/.aioson/skills/static/context-budget-guide.md +46 -46
- package/template/.aioson/skills/static/debugging-protocol.md +42 -42
- package/template/.aioson/skills/static/django-patterns.md +342 -342
- package/template/.aioson/skills/static/fastapi-patterns.md +344 -344
- package/template/.aioson/skills/static/filament-patterns.md +267 -267
- package/template/.aioson/skills/static/flux-ui-components.md +262 -262
- package/template/.aioson/skills/static/git-conventions.md +227 -227
- package/template/.aioson/skills/static/git-worktrees.md +36 -36
- package/template/.aioson/skills/static/harness-sensors.md +74 -74
- package/template/.aioson/skills/static/harness-validate/SKILL.md +46 -0
- package/template/.aioson/skills/static/jetstream-setup.md +200 -200
- package/template/.aioson/skills/static/landing-page-deploy.md +192 -192
- package/template/.aioson/skills/static/landing-page-forge.md +730 -730
- package/template/.aioson/skills/static/laravel-conventions.md +491 -491
- package/template/.aioson/skills/static/multi-agent-patterns.md +43 -43
- package/template/.aioson/skills/static/nextjs-patterns.md +321 -321
- package/template/.aioson/skills/static/node-express-patterns.md +317 -317
- package/template/.aioson/skills/static/node-typescript-patterns.md +282 -282
- package/template/.aioson/skills/static/rails-conventions.md +307 -307
- package/template/.aioson/skills/static/react-motion-patterns.md +599 -599
- package/template/.aioson/skills/static/static-html-patterns/checklists.md +43 -43
- package/template/.aioson/skills/static/static-html-patterns/css-tokens.md +609 -609
- package/template/.aioson/skills/static/static-html-patterns/motion.md +193 -193
- package/template/.aioson/skills/static/static-html-patterns/premium.md +711 -711
- package/template/.aioson/skills/static/static-html-patterns/structure.md +209 -209
- package/template/.aioson/skills/static/static-html-patterns/utilities.md +190 -190
- package/template/.aioson/skills/static/static-html-patterns.md +80 -80
- package/template/.aioson/skills/static/tall-stack-patterns.md +286 -286
- package/template/.aioson/skills/static/threejs-patterns.md +929 -929
- package/template/.aioson/skills/static/ui-ux-modern.md +76 -76
- package/template/.aioson/skills/static/web-research-cache.md +115 -112
- package/template/.aioson/skills/static/web3-cardano-patterns.md +337 -337
- package/template/.aioson/skills/static/web3-ethereum-patterns.md +310 -310
- package/template/.aioson/skills/static/web3-security-checklist.md +284 -284
- package/template/.aioson/skills/static/web3-solana-patterns.md +324 -324
- package/template/.aioson/squads/memory.md +5 -5
- package/template/.aioson/tasks/implementation-plan.md +327 -327
- package/template/.aioson/tasks/squad-analyze.md +83 -83
- package/template/.aioson/tasks/squad-create.md +148 -121
- package/template/.aioson/tasks/squad-design.md +206 -158
- package/template/.aioson/tasks/squad-execution-plan.md +279 -279
- package/template/.aioson/tasks/squad-export.md +20 -20
- package/template/.aioson/tasks/squad-extend.md +68 -68
- package/template/.aioson/tasks/squad-investigate.md +57 -44
- package/template/.aioson/tasks/squad-learning-review.md +44 -44
- package/template/.aioson/tasks/squad-output-config.md +177 -177
- package/template/.aioson/tasks/squad-pipeline.md +122 -122
- package/template/.aioson/tasks/squad-profile.md +48 -48
- package/template/.aioson/tasks/squad-refresh.md +236 -0
- package/template/.aioson/tasks/squad-repair.md +85 -85
- package/template/.aioson/tasks/squad-review.md +61 -61
- package/template/.aioson/tasks/squad-task-decompose.md +66 -66
- package/template/.aioson/tasks/squad-validate.md +58 -58
- package/template/.aioson/templates/reflect-prompts/current-state.md +36 -0
- package/template/.aioson/templates/reflect-prompts/how-it-works.md +23 -0
- package/template/.aioson/templates/reflect-prompts/what-it-does.md +21 -0
- package/template/.aioson/templates/squads/content-basic/template.json +21 -21
- package/template/.aioson/templates/squads/digital-marketing-agency/template.json +96 -96
- package/template/.aioson/templates/squads/media-channel/template.json +24 -24
- package/template/.aioson/templates/squads/research-analysis/template.json +22 -22
- package/template/.aioson/templates/squads/software-delivery/template.json +21 -21
- package/template/.claude/commands/aioson/agent/analyst.md +5 -5
- package/template/.claude/commands/aioson/agent/architect.md +5 -5
- package/template/.claude/commands/aioson/agent/briefing.md +5 -0
- package/template/.claude/commands/aioson/agent/committer.md +5 -0
- package/template/.claude/commands/aioson/agent/copywriter.md +5 -0
- package/template/.claude/commands/aioson/agent/design-hybrid-forge.md +5 -5
- package/template/.claude/commands/aioson/agent/dev.md +5 -5
- package/template/.claude/commands/aioson/agent/deyvin.md +5 -5
- package/template/.claude/commands/aioson/agent/discover.md +5 -0
- package/template/.claude/commands/aioson/agent/discovery-design-doc.md +5 -5
- package/template/.claude/commands/aioson/agent/genome.md +5 -5
- package/template/.claude/commands/aioson/agent/neo.md +5 -5
- package/template/.claude/commands/aioson/agent/orache.md +5 -5
- package/template/.claude/commands/aioson/agent/orchestrator.md +5 -5
- package/template/.claude/commands/aioson/agent/pair.md +5 -0
- package/template/.claude/commands/aioson/agent/pentester.md +5 -0
- package/template/.claude/commands/aioson/agent/pm.md +5 -5
- package/template/.claude/commands/aioson/agent/product.md +5 -5
- package/template/.claude/commands/aioson/agent/profiler-enricher.md +5 -5
- package/template/.claude/commands/aioson/agent/profiler-forge.md +5 -5
- package/template/.claude/commands/aioson/agent/profiler-researcher.md +5 -5
- package/template/.claude/commands/aioson/agent/qa.md +5 -5
- package/template/.claude/commands/aioson/agent/setup.md +5 -5
- package/template/.claude/commands/aioson/agent/sheldon.md +5 -5
- package/template/.claude/commands/aioson/agent/site-forge.md +5 -5
- package/template/.claude/commands/aioson/agent/squad.md +5 -5
- package/template/.claude/commands/aioson/agent/tester.md +5 -5
- package/template/.claude/commands/aioson/agent/ux-ui.md +5 -5
- package/template/.claude/commands/aioson/agent/validator.md +5 -0
- package/template/.gemini/GEMINI.md +13 -13
- package/template/.gemini/commands/aios-analyst.toml +7 -4
- package/template/.gemini/commands/aios-architect.toml +8 -7
- package/template/.gemini/commands/aios-committer.toml +7 -0
- package/template/.gemini/commands/aios-copywriter.toml +7 -0
- package/template/.gemini/commands/aios-cypher.toml +7 -0
- package/template/.gemini/commands/aios-dev.toml +9 -8
- package/template/.gemini/commands/aios-deyvin.toml +7 -6
- package/template/.gemini/commands/aios-discover.toml +6 -0
- package/template/.gemini/commands/aios-discovery-design-doc.toml +7 -4
- package/template/.gemini/commands/aios-genome.toml +7 -0
- package/template/.gemini/commands/aios-neo.toml +6 -4
- package/template/.gemini/commands/aios-orache.toml +7 -0
- package/template/.gemini/commands/aios-orchestrator.toml +9 -8
- package/template/.gemini/commands/aios-pair.toml +7 -6
- package/template/.gemini/commands/aios-pm.toml +9 -8
- package/template/.gemini/commands/aios-product.toml +6 -4
- package/template/.gemini/commands/aios-qa.toml +7 -6
- package/template/.gemini/commands/aios-setup.toml +6 -3
- package/template/.gemini/commands/aios-sheldon.toml +7 -0
- package/template/.gemini/commands/aios-site-forge.toml +7 -0
- package/template/.gemini/commands/aios-squad.toml +7 -0
- package/template/.gemini/commands/aios-tester.toml +7 -6
- package/template/.gemini/commands/aios-ux-ui.toml +9 -8
- package/template/.gemini/commands/aios-validator.toml +7 -0
- package/template/AGENTS.md +184 -172
- package/template/CLAUDE.md +98 -93
- package/template/OPENCODE.md +35 -34
- package/template/aioson-models.json +40 -40
- package/docs/en/i18n.md +0 -52
- package/docs/en/schemas/parallel-status.schema.json +0 -94
- package/template/.aioson/genomes/copywriting.md +0 -204
- package/template/.aioson/locales/en/agents/analyst.md +0 -244
- package/template/.aioson/locales/en/agents/architect.md +0 -245
- package/template/.aioson/locales/en/agents/dev.md +0 -397
- package/template/.aioson/locales/en/agents/deyvin.md +0 -137
- package/template/.aioson/locales/en/agents/discovery-design-doc.md +0 -27
- package/template/.aioson/locales/en/agents/genome.md +0 -212
- package/template/.aioson/locales/en/agents/neo.md +0 -8
- package/template/.aioson/locales/en/agents/orache.md +0 -6
- package/template/.aioson/locales/en/agents/orchestrator.md +0 -189
- package/template/.aioson/locales/en/agents/pair.md +0 -5
- package/template/.aioson/locales/en/agents/pm.md +0 -84
- package/template/.aioson/locales/en/agents/product.md +0 -378
- package/template/.aioson/locales/en/agents/profiler-enricher.md +0 -5
- package/template/.aioson/locales/en/agents/profiler-forge.md +0 -5
- package/template/.aioson/locales/en/agents/profiler-researcher.md +0 -5
- package/template/.aioson/locales/en/agents/qa.md +0 -270
- package/template/.aioson/locales/en/agents/setup.md +0 -421
- package/template/.aioson/locales/en/agents/sheldon.md +0 -455
- package/template/.aioson/locales/en/agents/squad.md +0 -449
- package/template/.aioson/locales/en/agents/tester.md +0 -6
- package/template/.aioson/locales/en/agents/ux-ui.md +0 -668
- package/template/.aioson/locales/es/agents/analyst.md +0 -225
- package/template/.aioson/locales/es/agents/architect.md +0 -245
- package/template/.aioson/locales/es/agents/dev.md +0 -370
- package/template/.aioson/locales/es/agents/deyvin.md +0 -99
- package/template/.aioson/locales/es/agents/discovery-design-doc.md +0 -21
- package/template/.aioson/locales/es/agents/genome.md +0 -104
- package/template/.aioson/locales/es/agents/neo.md +0 -50
- package/template/.aioson/locales/es/agents/orache.md +0 -105
- package/template/.aioson/locales/es/agents/orchestrator.md +0 -194
- package/template/.aioson/locales/es/agents/pair.md +0 -7
- package/template/.aioson/locales/es/agents/pm.md +0 -90
- package/template/.aioson/locales/es/agents/product.md +0 -372
- package/template/.aioson/locales/es/agents/profiler-enricher.md +0 -7
- package/template/.aioson/locales/es/agents/profiler-forge.md +0 -7
- package/template/.aioson/locales/es/agents/profiler-researcher.md +0 -7
- package/template/.aioson/locales/es/agents/qa.md +0 -198
- package/template/.aioson/locales/es/agents/setup.md +0 -405
- package/template/.aioson/locales/es/agents/sheldon.md +0 -309
- package/template/.aioson/locales/es/agents/squad.md +0 -532
- package/template/.aioson/locales/es/agents/tester.md +0 -9
- package/template/.aioson/locales/es/agents/ux-ui.md +0 -212
- package/template/.aioson/locales/fr/agents/analyst.md +0 -225
- package/template/.aioson/locales/fr/agents/architect.md +0 -245
- package/template/.aioson/locales/fr/agents/dev.md +0 -370
- package/template/.aioson/locales/fr/agents/deyvin.md +0 -99
- package/template/.aioson/locales/fr/agents/discovery-design-doc.md +0 -21
- package/template/.aioson/locales/fr/agents/genome.md +0 -104
- package/template/.aioson/locales/fr/agents/neo.md +0 -50
- package/template/.aioson/locales/fr/agents/orache.md +0 -106
- package/template/.aioson/locales/fr/agents/orchestrator.md +0 -194
- package/template/.aioson/locales/fr/agents/pair.md +0 -7
- package/template/.aioson/locales/fr/agents/pm.md +0 -90
- package/template/.aioson/locales/fr/agents/product.md +0 -372
- package/template/.aioson/locales/fr/agents/profiler-enricher.md +0 -7
- package/template/.aioson/locales/fr/agents/profiler-forge.md +0 -7
- package/template/.aioson/locales/fr/agents/profiler-researcher.md +0 -7
- package/template/.aioson/locales/fr/agents/qa.md +0 -198
- package/template/.aioson/locales/fr/agents/setup.md +0 -405
- package/template/.aioson/locales/fr/agents/sheldon.md +0 -309
- package/template/.aioson/locales/fr/agents/squad.md +0 -532
- package/template/.aioson/locales/fr/agents/tester.md +0 -9
- package/template/.aioson/locales/fr/agents/ux-ui.md +0 -212
- package/template/.aioson/locales/pt-BR/agents/analyst.md +0 -319
- package/template/.aioson/locales/pt-BR/agents/architect.md +0 -284
- package/template/.aioson/locales/pt-BR/agents/dev.md +0 -483
- package/template/.aioson/locales/pt-BR/agents/deyvin.md +0 -184
- package/template/.aioson/locales/pt-BR/agents/discovery-design-doc.md +0 -198
- package/template/.aioson/locales/pt-BR/agents/genome.md +0 -297
- package/template/.aioson/locales/pt-BR/agents/neo.md +0 -208
- package/template/.aioson/locales/pt-BR/agents/orache.md +0 -137
- package/template/.aioson/locales/pt-BR/agents/orchestrator.md +0 -324
- package/template/.aioson/locales/pt-BR/agents/pair.md +0 -5
- package/template/.aioson/locales/pt-BR/agents/pm.md +0 -182
- package/template/.aioson/locales/pt-BR/agents/product.md +0 -466
- package/template/.aioson/locales/pt-BR/agents/profiler-enricher.md +0 -5
- package/template/.aioson/locales/pt-BR/agents/profiler-forge.md +0 -5
- package/template/.aioson/locales/pt-BR/agents/profiler-researcher.md +0 -5
- package/template/.aioson/locales/pt-BR/agents/qa.md +0 -300
- package/template/.aioson/locales/pt-BR/agents/setup.md +0 -533
- package/template/.aioson/locales/pt-BR/agents/sheldon.md +0 -323
- package/template/.aioson/locales/pt-BR/agents/squad.md +0 -1330
- package/template/.aioson/locales/pt-BR/agents/tester.md +0 -449
- package/template/.aioson/locales/pt-BR/agents/ux-ui.md +0 -669
package/src/commands/live.js
CHANGED
|
@@ -1,1641 +1,2101 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fs = require('node:fs/promises');
|
|
4
|
-
const path = require('node:path');
|
|
5
|
-
const { spawn } = require('node:child_process');
|
|
6
|
-
const {
|
|
7
|
-
resolveRuntimePaths,
|
|
8
|
-
openRuntimeDb,
|
|
9
|
-
runtimeStoreExists,
|
|
10
|
-
startTask,
|
|
11
|
-
updateTask,
|
|
12
|
-
startRun,
|
|
13
|
-
updateRun,
|
|
14
|
-
appendRunEvent,
|
|
15
|
-
readAgentSession,
|
|
16
|
-
writeAgentSession,
|
|
17
|
-
clearAgentSession
|
|
18
|
-
} = require('../runtime-store');
|
|
19
|
-
const { ensureDir, exists } = require('../utils');
|
|
20
|
-
const { SUPPORTED_PROMPT_TOOLS } = require('../prompt-tool');
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
await fs.
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
path
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
let
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
if (!
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
if (!
|
|
481
|
-
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
if (run &&
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
task,
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
if (
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
if (
|
|
592
|
-
next.stats.
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
child.
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
};
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
function
|
|
676
|
-
if (!
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
const
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
const
|
|
952
|
-
const
|
|
953
|
-
const
|
|
954
|
-
const
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
if (
|
|
964
|
-
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
});
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
});
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
}
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
options.
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
if (
|
|
1306
|
-
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
|
-
const
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
taskKey
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
const
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
})
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
}
|
|
1566
|
-
}
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
})
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs/promises');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const { spawn } = require('node:child_process');
|
|
6
|
+
const {
|
|
7
|
+
resolveRuntimePaths,
|
|
8
|
+
openRuntimeDb,
|
|
9
|
+
runtimeStoreExists,
|
|
10
|
+
startTask,
|
|
11
|
+
updateTask,
|
|
12
|
+
startRun,
|
|
13
|
+
updateRun,
|
|
14
|
+
appendRunEvent,
|
|
15
|
+
readAgentSession,
|
|
16
|
+
writeAgentSession,
|
|
17
|
+
clearAgentSession
|
|
18
|
+
} = require('../runtime-store');
|
|
19
|
+
const { ensureDir, exists } = require('../utils');
|
|
20
|
+
const { SUPPORTED_PROMPT_TOOLS } = require('../prompt-tool');
|
|
21
|
+
const { isTmuxAvailable, launchTmuxSession, buildSessionName, hasSession, attachSession } = require('../lib/tmux-launcher');
|
|
22
|
+
const { resolveResumeArgs } = require('../lib/tool-capabilities');
|
|
23
|
+
|
|
24
|
+
const LIVE_EVENTS_LIMIT = 10;
|
|
25
|
+
const LIVE_MESSAGE_LIMIT = 500;
|
|
26
|
+
|
|
27
|
+
function resolveTargetDir(args) {
|
|
28
|
+
return path.resolve(process.cwd(), args[0] || '.');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function requireOption(options, key, t) {
|
|
32
|
+
const value = options[key];
|
|
33
|
+
if (value === undefined || value === null || String(value).trim() === '') {
|
|
34
|
+
throw new Error(t('runtime.option_required', { option: `--${key}` }));
|
|
35
|
+
}
|
|
36
|
+
return String(value).trim();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function normalizeAgentHandle(value) {
|
|
40
|
+
const text = String(value || '').trim();
|
|
41
|
+
if (!text) return '';
|
|
42
|
+
return text.startsWith('@') ? text : `@${text}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function makeDirectSessionKey(agentName) {
|
|
46
|
+
return `direct-session:${Date.now()}:${String(agentName || '').replace(/^@/, '')}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function parseWatchSeconds(value) {
|
|
50
|
+
if (value === undefined || value === null || value === false) return null;
|
|
51
|
+
if (value === true || value === '') return 2;
|
|
52
|
+
|
|
53
|
+
const parsed = Number(value);
|
|
54
|
+
if (!Number.isFinite(parsed) || parsed <= 0) return 2;
|
|
55
|
+
return parsed;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function sleep(ms) {
|
|
59
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function withRuntimeDb(targetDir, t) {
|
|
63
|
+
const handle = await openRuntimeDb(targetDir, { mustExist: true });
|
|
64
|
+
if (!handle) {
|
|
65
|
+
throw new Error(t('runtime.store_missing', { path: resolveRuntimePaths(targetDir).dbPath }));
|
|
66
|
+
}
|
|
67
|
+
return handle;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// bug-found-005: session keys carry the format `direct-session:{ts}:{agent}`
|
|
71
|
+
// which contains colons. NTFS reserves `:` in filenames (it's the drive-letter
|
|
72
|
+
// separator and the alternate-data-stream syntax), so any `path.join(..., 'live',
|
|
73
|
+
// 'direct-session:1234:deyvin')` would have `mkdir` fail silently in the
|
|
74
|
+
// auxiliary-filesystem catches further down — leaving the dashboard's
|
|
75
|
+
// state.json/events.ndjson/summary.md never written on Windows.
|
|
76
|
+
//
|
|
77
|
+
// We sanitize only at the filesystem boundary: the session_key stored in
|
|
78
|
+
// SQLite, returned to callers, and printed by the CLI keeps its colons (it's
|
|
79
|
+
// a documented public identifier). Colons survive on POSIX too, but `__` is
|
|
80
|
+
// safe everywhere and lets a single code path handle both platforms.
|
|
81
|
+
function sessionKeyToDirName(sessionKey) {
|
|
82
|
+
return String(sessionKey).replace(/:/g, '__');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function resolveLivePaths(runtimeDir, sessionKey) {
|
|
86
|
+
const sessionDir = path.join(runtimeDir, 'live', sessionKeyToDirName(sessionKey));
|
|
87
|
+
return {
|
|
88
|
+
sessionDir,
|
|
89
|
+
statePath: path.join(sessionDir, 'state.json'),
|
|
90
|
+
eventsPath: path.join(sessionDir, 'events.ndjson'),
|
|
91
|
+
summaryPath: path.join(sessionDir, 'summary.md')
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function truncateMessage(value, fallback = '') {
|
|
96
|
+
const text = String(value || fallback || '').trim();
|
|
97
|
+
if (!text) return '';
|
|
98
|
+
if (text.length <= LIVE_MESSAGE_LIMIT) return text;
|
|
99
|
+
return `${text.slice(0, LIVE_MESSAGE_LIMIT - 3).trimEnd()}...`;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function parseRefs(value) {
|
|
103
|
+
const text = String(value || '').trim();
|
|
104
|
+
if (!text) return [];
|
|
105
|
+
return Array.from(new Set(text.split(',').map((entry) => entry.trim()).filter(Boolean)));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function parseJsonOption(value) {
|
|
109
|
+
if (value === undefined || value === null || value === '') return null;
|
|
110
|
+
if (typeof value === 'object' && !Array.isArray(value)) return value;
|
|
111
|
+
try {
|
|
112
|
+
const parsed = JSON.parse(String(value));
|
|
113
|
+
return parsed && typeof parsed === 'object' ? parsed : { value: parsed };
|
|
114
|
+
} catch {
|
|
115
|
+
return { raw: String(value) };
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Combine `--resume` (mapped per-tool via TOOL_CAPS) with user-provided `--tool-args`.
|
|
120
|
+
// Resume args go FIRST so that codex `resume --last` (subcommand) lands at argv[1].
|
|
121
|
+
function buildLaunchArgs(options, tool) {
|
|
122
|
+
const resumeOpt = options.resume !== undefined ? options.resume : options.Resume;
|
|
123
|
+
const resumeArgs = resolveResumeArgs(tool, resumeOpt);
|
|
124
|
+
const userArgs = parseToolArgs(options['tool-args'] || options.toolArgs);
|
|
125
|
+
return [...resumeArgs, ...userArgs];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function parseToolArgs(value) {
|
|
129
|
+
if (value === undefined || value === null || value === '') return [];
|
|
130
|
+
if (Array.isArray(value)) return value.map((entry) => String(entry));
|
|
131
|
+
const text = String(value).trim();
|
|
132
|
+
if (!text) return [];
|
|
133
|
+
|
|
134
|
+
if (text.startsWith('[')) {
|
|
135
|
+
try {
|
|
136
|
+
const parsed = JSON.parse(text);
|
|
137
|
+
if (Array.isArray(parsed)) {
|
|
138
|
+
return parsed.map((entry) => String(entry));
|
|
139
|
+
}
|
|
140
|
+
} catch {
|
|
141
|
+
// fallback to whitespace split below
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return text.split(/\s+/).filter(Boolean);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function normalizeLiveTool(value, t) {
|
|
149
|
+
const tool = String(value || '').trim().toLowerCase();
|
|
150
|
+
if (SUPPORTED_PROMPT_TOOLS.has(tool)) {
|
|
151
|
+
return tool;
|
|
152
|
+
}
|
|
153
|
+
const supported = Array.from(SUPPORTED_PROMPT_TOOLS).join(', ');
|
|
154
|
+
throw new Error(t ? t('live.unsupported_tool', { tool: value, supported }) : `Unsupported live tool: ${value}. Supported: ${supported}`);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
function normalizePlanStepId(value) {
|
|
159
|
+
return String(value || '').trim().replace(/\s+/g, ' ');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function collectPlanSteps(markdown) {
|
|
163
|
+
const steps = [];
|
|
164
|
+
const seen = new Set();
|
|
165
|
+
|
|
166
|
+
function pushStep(id, title) {
|
|
167
|
+
const normalizedId = normalizePlanStepId(id);
|
|
168
|
+
const normalizedTitle = String(title || '').trim();
|
|
169
|
+
if (!normalizedId || !normalizedTitle) return;
|
|
170
|
+
const key = normalizedId.toLowerCase();
|
|
171
|
+
if (seen.has(key)) return;
|
|
172
|
+
seen.add(key);
|
|
173
|
+
steps.push({ id: normalizedId, title: normalizedTitle, done: false });
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const blockPattern = /<!--\s*aioson:steps([\s\S]*?)-->/gi;
|
|
177
|
+
let blockMatch = blockPattern.exec(markdown);
|
|
178
|
+
while (blockMatch) {
|
|
179
|
+
const lines = String(blockMatch[1] || '').split(/\r?\n/);
|
|
180
|
+
for (const line of lines) {
|
|
181
|
+
const trimmed = line.trim();
|
|
182
|
+
if (!trimmed) continue;
|
|
183
|
+
const match = trimmed.match(/^([^:]+):\s*(.+)$/);
|
|
184
|
+
if (match) {
|
|
185
|
+
pushStep(match[1], match[2]);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
blockMatch = blockPattern.exec(markdown);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const headingPattern = /^#{3,6}\s+((?:[A-Z]{2,}(?:-[A-Z0-9]+)*-\d+(?:\.\d+)?)|(?:Fase\s+\d+(?:\.\d+)?))\s*[-:]\s+(.+)$/gim;
|
|
192
|
+
let headingMatch = headingPattern.exec(markdown);
|
|
193
|
+
while (headingMatch) {
|
|
194
|
+
pushStep(headingMatch[1], headingMatch[2]);
|
|
195
|
+
headingMatch = headingPattern.exec(markdown);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return steps;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async function loadPlanReference(targetDir, planRef) {
|
|
202
|
+
if (!planRef) {
|
|
203
|
+
return { planRef: null, planPath: null, planSteps: [] };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const planPath = path.isAbsolute(planRef) ? planRef : path.resolve(targetDir, planRef);
|
|
207
|
+
let markdown = '';
|
|
208
|
+
try {
|
|
209
|
+
markdown = await fs.readFile(planPath, 'utf8');
|
|
210
|
+
} catch {
|
|
211
|
+
throw new Error(`Plan file not found: ${planRef}`); // technical message, i18n at caller level
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return {
|
|
215
|
+
planRef,
|
|
216
|
+
planPath,
|
|
217
|
+
planSteps: collectPlanSteps(markdown)
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
async function resolveExecutablePath(command) {
|
|
223
|
+
const binary = String(command || '').trim();
|
|
224
|
+
if (!binary) return null;
|
|
225
|
+
|
|
226
|
+
if (path.isAbsolute(binary) || binary.includes(path.sep)) {
|
|
227
|
+
const absolutePath = path.isAbsolute(binary) ? binary : path.resolve(binary);
|
|
228
|
+
return (await exists(absolutePath)) ? absolutePath : null;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const pathEntries = String(process.env.PATH || '')
|
|
232
|
+
.split(path.delimiter)
|
|
233
|
+
.map((entry) => entry.trim())
|
|
234
|
+
.filter(Boolean);
|
|
235
|
+
|
|
236
|
+
const extensions = process.platform === 'win32'
|
|
237
|
+
? Array.from(new Set(['', ...String(process.env.PATHEXT || '.EXE;.CMD;.BAT;.COM').split(';').map((entry) => entry.toLowerCase())]))
|
|
238
|
+
: [''];
|
|
239
|
+
|
|
240
|
+
for (const dir of pathEntries) {
|
|
241
|
+
for (const ext of extensions) {
|
|
242
|
+
const candidate = process.platform === 'win32' && ext && !binary.toLowerCase().endsWith(ext)
|
|
243
|
+
? path.join(dir, `${binary}${ext}`)
|
|
244
|
+
: path.join(dir, binary);
|
|
245
|
+
if (await exists(candidate)) {
|
|
246
|
+
return candidate;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function detectProcessState(pid) {
|
|
255
|
+
if (!pid) return 'not_tracked';
|
|
256
|
+
try {
|
|
257
|
+
process.kill(Number(pid), 0);
|
|
258
|
+
return 'alive';
|
|
259
|
+
} catch (error) {
|
|
260
|
+
if (error && error.code === 'ESRCH') {
|
|
261
|
+
return 'dead';
|
|
262
|
+
}
|
|
263
|
+
return 'unknown';
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function normalizeLiveStats(stats, fallback = {}) {
|
|
268
|
+
return {
|
|
269
|
+
tasks_completed: Number(stats?.tasks_completed || 0),
|
|
270
|
+
events_total: Number(stats?.events_total || 0),
|
|
271
|
+
plan_steps_done: Number(stats?.plan_steps_done ?? fallback.plan_steps_done ?? 0),
|
|
272
|
+
plan_steps_total: Number(stats?.plan_steps_total ?? fallback.plan_steps_total ?? 0),
|
|
273
|
+
events_by_type: stats?.events_by_type && typeof stats.events_by_type === 'object'
|
|
274
|
+
? { ...stats.events_by_type }
|
|
275
|
+
: {}
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function parseTaskMeta(task) {
|
|
280
|
+
if (!task || !task.meta_json) return {};
|
|
281
|
+
try {
|
|
282
|
+
const parsed = JSON.parse(task.meta_json);
|
|
283
|
+
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
284
|
+
} catch {
|
|
285
|
+
return {};
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function getPlanStats(meta) {
|
|
290
|
+
const steps = Array.isArray(meta?.plan_steps) ? meta.plan_steps : [];
|
|
291
|
+
const done = steps.filter((step) => step && step.done).length;
|
|
292
|
+
return {
|
|
293
|
+
plan_steps_done: done,
|
|
294
|
+
plan_steps_total: steps.length
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
async function readJsonIfExists(filePath) {
|
|
299
|
+
try {
|
|
300
|
+
const raw = await fs.readFile(filePath, 'utf8');
|
|
301
|
+
return JSON.parse(raw);
|
|
302
|
+
} catch {
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
async function readLiveState(runtimeDir, sessionKey) {
|
|
308
|
+
if (!sessionKey) return null;
|
|
309
|
+
return readJsonIfExists(resolveLivePaths(runtimeDir, sessionKey).statePath);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
async function writeLiveState(runtimeDir, sessionKey, state) {
|
|
313
|
+
try {
|
|
314
|
+
const { statePath } = resolveLivePaths(runtimeDir, sessionKey);
|
|
315
|
+
await ensureDir(path.dirname(statePath));
|
|
316
|
+
await fs.writeFile(statePath, JSON.stringify(state, null, 2), 'utf8');
|
|
317
|
+
} catch {
|
|
318
|
+
// filesystem is auxiliary — SQLite is source of truth
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async function appendLiveEvent(runtimeDir, sessionKey, record) {
|
|
323
|
+
try {
|
|
324
|
+
const { eventsPath } = resolveLivePaths(runtimeDir, sessionKey);
|
|
325
|
+
await ensureDir(path.dirname(eventsPath));
|
|
326
|
+
await fs.appendFile(eventsPath, `${JSON.stringify(record)}\n`, 'utf8');
|
|
327
|
+
} catch {
|
|
328
|
+
// filesystem is auxiliary — SQLite is source of truth
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
async function writeLiveSummary(runtimeDir, sessionKey, markdown) {
|
|
333
|
+
try {
|
|
334
|
+
const { summaryPath } = resolveLivePaths(runtimeDir, sessionKey);
|
|
335
|
+
await ensureDir(path.dirname(summaryPath));
|
|
336
|
+
await fs.writeFile(summaryPath, markdown, 'utf8');
|
|
337
|
+
return summaryPath;
|
|
338
|
+
} catch {
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
async function listLiveStates(runtimeDir) {
|
|
344
|
+
const liveRoot = path.join(runtimeDir, 'live');
|
|
345
|
+
if (!(await exists(liveRoot))) {
|
|
346
|
+
return [];
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
const entries = await fs.readdir(liveRoot, { withFileTypes: true });
|
|
350
|
+
const states = [];
|
|
351
|
+
for (const entry of entries) {
|
|
352
|
+
if (!entry.isDirectory()) continue;
|
|
353
|
+
const state = await readJsonIfExists(path.join(liveRoot, entry.name, 'state.json'));
|
|
354
|
+
if (state) {
|
|
355
|
+
states.push(state);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
states.sort((left, right) => {
|
|
360
|
+
const leftStamp = Date.parse(left.updated_at || left.closed_at || left.started_at || 0);
|
|
361
|
+
const rightStamp = Date.parse(right.updated_at || right.closed_at || right.started_at || 0);
|
|
362
|
+
return rightStamp - leftStamp;
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
return states;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function createLiveState(targetDir, run, task, options = {}) {
|
|
369
|
+
const taskMeta = parseTaskMeta(task);
|
|
370
|
+
const planStats = getPlanStats(taskMeta);
|
|
371
|
+
return {
|
|
372
|
+
session_key: run.session_key || task?.session_key || options.sessionKey || null,
|
|
373
|
+
session_task_key: task?.task_key || options.taskKey || null,
|
|
374
|
+
tool_session: options.tool || taskMeta.tool_session || null,
|
|
375
|
+
active_agent: options.activeAgent || run.agent_name || null,
|
|
376
|
+
plan_ref: options.planRef ?? taskMeta.plan_ref ?? null,
|
|
377
|
+
phase: options.phase || (run.status === 'running' || run.status === 'queued' ? 'active' : 'closed'),
|
|
378
|
+
title: options.title || task?.title || run.title || null,
|
|
379
|
+
path: options.projectPath || targetDir,
|
|
380
|
+
child_pid: options.childPid ?? taskMeta.child_pid ?? null,
|
|
381
|
+
started_at: options.startedAt || run.started_at || task?.created_at || null,
|
|
382
|
+
updated_at: options.updatedAt || run.updated_at || task?.updated_at || null,
|
|
383
|
+
closed_at: options.closedAt || (run.status === 'completed' || run.status === 'failed' ? run.finished_at || task?.finished_at || null : null),
|
|
384
|
+
current_task: options.currentTask ?? null,
|
|
385
|
+
current_run_key: options.currentRunKey || run.run_key,
|
|
386
|
+
stats: normalizeLiveStats(options.stats, planStats),
|
|
387
|
+
last_events: Array.isArray(options.lastEvents) ? options.lastEvents.slice(-LIVE_EVENTS_LIMIT) : []
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
function selectLiveRunByKey(db, runKey) {
|
|
392
|
+
if (!runKey) return null;
|
|
393
|
+
return db.prepare(`
|
|
394
|
+
SELECT
|
|
395
|
+
run_key, task_key, agent_name, agent_kind, squad_slug, session_key, source,
|
|
396
|
+
title, status, summary, output_path, started_at, updated_at, finished_at
|
|
397
|
+
FROM agent_runs
|
|
398
|
+
WHERE run_key = ? AND source = 'live'
|
|
399
|
+
LIMIT 1
|
|
400
|
+
`).get(String(runKey));
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function selectLatestLiveRun(db, options = {}) {
|
|
404
|
+
if (options.sessionKey) {
|
|
405
|
+
return db.prepare(`
|
|
406
|
+
SELECT
|
|
407
|
+
run_key, task_key, agent_name, agent_kind, squad_slug, session_key, source,
|
|
408
|
+
title, status, summary, output_path, started_at, updated_at, finished_at
|
|
409
|
+
FROM agent_runs
|
|
410
|
+
WHERE source = 'live' AND session_key = ?
|
|
411
|
+
ORDER BY updated_at DESC, started_at DESC
|
|
412
|
+
LIMIT 1
|
|
413
|
+
`).get(String(options.sessionKey));
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
if (options.agentName) {
|
|
417
|
+
return db.prepare(`
|
|
418
|
+
SELECT
|
|
419
|
+
run_key, task_key, agent_name, agent_kind, squad_slug, session_key, source,
|
|
420
|
+
title, status, summary, output_path, started_at, updated_at, finished_at
|
|
421
|
+
FROM agent_runs
|
|
422
|
+
WHERE source = 'live' AND agent_name = ?
|
|
423
|
+
ORDER BY updated_at DESC, started_at DESC
|
|
424
|
+
LIMIT 1
|
|
425
|
+
`).get(String(options.agentName));
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
return db.prepare(`
|
|
429
|
+
SELECT
|
|
430
|
+
run_key, task_key, agent_name, agent_kind, squad_slug, session_key, source,
|
|
431
|
+
title, status, summary, output_path, started_at, updated_at, finished_at
|
|
432
|
+
FROM agent_runs
|
|
433
|
+
WHERE source = 'live'
|
|
434
|
+
ORDER BY updated_at DESC, started_at DESC
|
|
435
|
+
LIMIT 1
|
|
436
|
+
`).get();
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function selectTaskByKey(db, taskKey) {
|
|
440
|
+
if (!taskKey) return null;
|
|
441
|
+
return db.prepare(`
|
|
442
|
+
SELECT
|
|
443
|
+
task_key, squad_slug, session_key, task_kind, parent_task_key,
|
|
444
|
+
title, goal, meta_json, status, created_by, created_at, updated_at, finished_at
|
|
445
|
+
FROM tasks
|
|
446
|
+
WHERE task_key = ?
|
|
447
|
+
LIMIT 1
|
|
448
|
+
`).get(String(taskKey));
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function mapRecentDbEvent(event) {
|
|
452
|
+
return {
|
|
453
|
+
ts: event.created_at,
|
|
454
|
+
type: event.event_type,
|
|
455
|
+
summary: event.message || '-'
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
async function resolveLiveContext(targetDir, db, runtimeDir, options = {}) {
|
|
460
|
+
let agentName = options.agentName ? normalizeAgentHandle(options.agentName) : null;
|
|
461
|
+
let sessionRef = agentName ? await readAgentSession(runtimeDir, agentName) : null;
|
|
462
|
+
let sessionKey = options.sessionKey ? String(options.sessionKey).trim() : null;
|
|
463
|
+
let state = null;
|
|
464
|
+
|
|
465
|
+
if (!sessionKey && sessionRef?.sessionKey) {
|
|
466
|
+
sessionKey = String(sessionRef.sessionKey).trim();
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
if (!sessionKey && !agentName) {
|
|
470
|
+
const liveStates = await listLiveStates(runtimeDir);
|
|
471
|
+
if (liveStates.length > 0) {
|
|
472
|
+
state = liveStates[0];
|
|
473
|
+
sessionKey = state.session_key || null;
|
|
474
|
+
if (state.active_agent) {
|
|
475
|
+
agentName = normalizeAgentHandle(state.active_agent);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
if (!state && sessionKey) {
|
|
481
|
+
state = await readLiveState(runtimeDir, sessionKey);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
if (!agentName && state?.active_agent) {
|
|
485
|
+
agentName = normalizeAgentHandle(state.active_agent);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
let run = sessionRef?.runKey ? selectLiveRunByKey(db, sessionRef.runKey) : null;
|
|
489
|
+
if (!run && state?.current_run_key) {
|
|
490
|
+
run = selectLiveRunByKey(db, state.current_run_key);
|
|
491
|
+
}
|
|
492
|
+
if (!run && sessionKey) {
|
|
493
|
+
run = selectLatestLiveRun(db, { sessionKey });
|
|
494
|
+
}
|
|
495
|
+
if (!run && agentName) {
|
|
496
|
+
run = selectLatestLiveRun(db, { agentName });
|
|
497
|
+
}
|
|
498
|
+
if (!run && !agentName && !sessionKey) {
|
|
499
|
+
run = selectLatestLiveRun(db);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
let task = null;
|
|
503
|
+
if (run?.task_key) {
|
|
504
|
+
task = selectTaskByKey(db, run.task_key);
|
|
505
|
+
}
|
|
506
|
+
if (!task && sessionRef?.taskKey) {
|
|
507
|
+
task = selectTaskByKey(db, sessionRef.taskKey);
|
|
508
|
+
}
|
|
509
|
+
if (!task && state?.session_task_key) {
|
|
510
|
+
task = selectTaskByKey(db, state.session_task_key);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
if (!sessionKey) {
|
|
514
|
+
sessionKey = run?.session_key || task?.session_key || state?.session_key || sessionRef?.sessionKey || null;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
if (!state && sessionKey) {
|
|
518
|
+
state = await readLiveState(runtimeDir, sessionKey);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
if (run && !state) {
|
|
522
|
+
state = createLiveState(targetDir, run, task, {
|
|
523
|
+
sessionKey,
|
|
524
|
+
activeAgent: agentName || run.agent_name,
|
|
525
|
+
projectPath: targetDir
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const recentEvents = run
|
|
530
|
+
? db.prepare(`
|
|
531
|
+
SELECT event_type, message, created_at
|
|
532
|
+
FROM execution_events
|
|
533
|
+
WHERE run_key = ?
|
|
534
|
+
ORDER BY created_at DESC, id DESC
|
|
535
|
+
LIMIT ?
|
|
536
|
+
`).all(run.run_key, Math.max(1, Math.min(Number(options.limit) || 8, 20))).reverse().map(mapRecentDbEvent)
|
|
537
|
+
: [];
|
|
538
|
+
|
|
539
|
+
const processState = detectProcessState(state?.child_pid);
|
|
540
|
+
const phase = state?.phase || (run && (run.status === 'running' || run.status === 'queued') ? 'active' : run ? 'closed' : 'idle');
|
|
541
|
+
const open = phase === 'active' && Boolean(run && (run.status === 'running' || run.status === 'queued'));
|
|
542
|
+
|
|
543
|
+
return {
|
|
544
|
+
agentName: agentName || state?.active_agent || run?.agent_name || null,
|
|
545
|
+
sessionRef,
|
|
546
|
+
sessionKey,
|
|
547
|
+
run,
|
|
548
|
+
task,
|
|
549
|
+
state,
|
|
550
|
+
recentEvents,
|
|
551
|
+
processState,
|
|
552
|
+
phase,
|
|
553
|
+
open,
|
|
554
|
+
paths: sessionKey ? resolveLivePaths(runtimeDir, sessionKey) : null
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
async function requireActiveLiveContext(targetDir, agentName, t, options = {}) {
|
|
559
|
+
const { db, dbPath, runtimeDir } = await withRuntimeDb(targetDir, t);
|
|
560
|
+
const context = await resolveLiveContext(targetDir, db, runtimeDir, {
|
|
561
|
+
agentName,
|
|
562
|
+
limit: options.limit
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
if (!context.run || context.run.source !== 'live' || !context.sessionKey || !context.task) {
|
|
566
|
+
db.close();
|
|
567
|
+
throw new Error(t('live.no_active_session', { agent: normalizeAgentHandle(agentName) }));
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
if (context.phase !== 'active') {
|
|
571
|
+
db.close();
|
|
572
|
+
throw new Error(t('live.session_not_active', { agent: normalizeAgentHandle(agentName) }));
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
return { db, dbPath, runtimeDir, context };
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function applyEventToState(state, event, updates = {}) {
|
|
579
|
+
const next = {
|
|
580
|
+
...state,
|
|
581
|
+
updated_at: event.ts,
|
|
582
|
+
stats: normalizeLiveStats(state?.stats)
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
next.last_events = [...(Array.isArray(state?.last_events) ? state.last_events : []), {
|
|
586
|
+
ts: event.ts,
|
|
587
|
+
type: event.type,
|
|
588
|
+
summary: event.summary
|
|
589
|
+
}].slice(-LIVE_EVENTS_LIMIT);
|
|
590
|
+
next.stats.events_total += 1;
|
|
591
|
+
if (event.type) {
|
|
592
|
+
next.stats.events_by_type[event.type] = (next.stats.events_by_type[event.type] || 0) + 1;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
if (event.type === 'task_completed') {
|
|
596
|
+
next.stats.tasks_completed += 1;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
if (Object.prototype.hasOwnProperty.call(updates, 'currentTask')) {
|
|
600
|
+
next.current_task = updates.currentTask;
|
|
601
|
+
}
|
|
602
|
+
if (Object.prototype.hasOwnProperty.call(updates, 'phase')) {
|
|
603
|
+
next.phase = updates.phase;
|
|
604
|
+
}
|
|
605
|
+
if (Object.prototype.hasOwnProperty.call(updates, 'closedAt')) {
|
|
606
|
+
next.closed_at = updates.closedAt;
|
|
607
|
+
}
|
|
608
|
+
if (Object.prototype.hasOwnProperty.call(updates, 'activeAgent')) {
|
|
609
|
+
next.active_agent = updates.activeAgent;
|
|
610
|
+
}
|
|
611
|
+
if (Object.prototype.hasOwnProperty.call(updates, 'currentRunKey')) {
|
|
612
|
+
next.current_run_key = updates.currentRunKey;
|
|
613
|
+
}
|
|
614
|
+
if (Object.prototype.hasOwnProperty.call(updates, 'childPid')) {
|
|
615
|
+
next.child_pid = updates.childPid;
|
|
616
|
+
}
|
|
617
|
+
if (updates.planStats) {
|
|
618
|
+
next.stats.plan_steps_done = Number(updates.planStats.plan_steps_done || 0);
|
|
619
|
+
next.stats.plan_steps_total = Number(updates.planStats.plan_steps_total || 0);
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
return next;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
function createLiveEventRecord(context, options = {}) {
|
|
626
|
+
return {
|
|
627
|
+
ts: options.ts,
|
|
628
|
+
type: options.type,
|
|
629
|
+
summary: options.summary,
|
|
630
|
+
agent: context.agentName,
|
|
631
|
+
task_key: options.taskKey || context.task?.task_key || null,
|
|
632
|
+
run_key: context.run?.run_key || null,
|
|
633
|
+
session_key: context.sessionKey,
|
|
634
|
+
refs: options.refs || [],
|
|
635
|
+
plan_step: options.planStep || null,
|
|
636
|
+
status: options.status || null,
|
|
637
|
+
meta: options.meta || null
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
function waitForChild(child) {
|
|
642
|
+
return new Promise((resolve, reject) => {
|
|
643
|
+
child.once('error', reject);
|
|
644
|
+
child.once('close', (code, signal) => {
|
|
645
|
+
resolve({ code: Number(code || 0), signal: signal || null });
|
|
646
|
+
});
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
async function runLocalProcess(command, args, options = {}) {
|
|
651
|
+
return new Promise((resolve) => {
|
|
652
|
+
const child = spawn(command, args.map((entry) => String(entry)), {
|
|
653
|
+
cwd: options.cwd || process.cwd(),
|
|
654
|
+
env: { ...process.env, ...(options.env || {}) },
|
|
655
|
+
stdio: ['ignore', 'pipe', 'pipe']
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
let stdout = '';
|
|
659
|
+
let stderr = '';
|
|
660
|
+
child.stdout.on('data', (chunk) => {
|
|
661
|
+
stdout += String(chunk);
|
|
662
|
+
});
|
|
663
|
+
child.stderr.on('data', (chunk) => {
|
|
664
|
+
stderr += String(chunk);
|
|
665
|
+
});
|
|
666
|
+
child.on('error', () => {
|
|
667
|
+
resolve({ code: 1, stdout, stderr });
|
|
668
|
+
});
|
|
669
|
+
child.on('close', (code) => {
|
|
670
|
+
resolve({ code: Number(code || 0), stdout, stderr });
|
|
671
|
+
});
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
async function collectGitSnapshot(targetDir) {
|
|
676
|
+
if (!(await exists(path.join(targetDir, '.git')))) {
|
|
677
|
+
return null;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
const [branch, commit, diffStat, status] = await Promise.all([
|
|
681
|
+
runLocalProcess('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: targetDir }),
|
|
682
|
+
runLocalProcess('git', ['rev-parse', '--short', 'HEAD'], { cwd: targetDir }),
|
|
683
|
+
runLocalProcess('git', ['diff', '--stat'], { cwd: targetDir }),
|
|
684
|
+
runLocalProcess('git', ['status', '--short'], { cwd: targetDir })
|
|
685
|
+
]);
|
|
686
|
+
|
|
687
|
+
if (branch.code !== 0 && commit.code !== 0 && diffStat.code !== 0 && status.code !== 0) {
|
|
688
|
+
return null;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
return {
|
|
692
|
+
branch: branch.code === 0 ? branch.stdout.trim() : null,
|
|
693
|
+
commit: commit.code === 0 ? commit.stdout.trim() : null,
|
|
694
|
+
diff_stat: diffStat.code === 0 ? diffStat.stdout.trim() : null,
|
|
695
|
+
changed_files: status.code === 0
|
|
696
|
+
? status.stdout.split(/\r?\n/).map((line) => line.trim()).filter(Boolean).map((line) => line.slice(3).trim() || line)
|
|
697
|
+
: []
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
function formatDuration(startedAt, closedAt) {
|
|
702
|
+
if (!startedAt || !closedAt) return null;
|
|
703
|
+
const ms = Date.parse(closedAt) - Date.parse(startedAt);
|
|
704
|
+
if (!Number.isFinite(ms) || ms < 0) return null;
|
|
705
|
+
const seconds = Math.floor(ms / 1000);
|
|
706
|
+
const hours = Math.floor(seconds / 3600);
|
|
707
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
708
|
+
const secs = seconds % 60;
|
|
709
|
+
if (hours > 0) return `${hours}h ${minutes}m`;
|
|
710
|
+
if (minutes > 0) return `${minutes}m ${secs}s`;
|
|
711
|
+
return `${secs}s`;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
function renderLiveSummary(snapshot) {
|
|
715
|
+
const duration = formatDuration(snapshot.startedAt, snapshot.closedAt);
|
|
716
|
+
const lines = [
|
|
717
|
+
'# Live Session Summary',
|
|
718
|
+
'',
|
|
719
|
+
`- Session: ${snapshot.sessionKey}`,
|
|
720
|
+
`- Agent: ${snapshot.agent}`,
|
|
721
|
+
`- Tool: ${snapshot.tool || 'unknown'}`,
|
|
722
|
+
`- Status: ${snapshot.status}`,
|
|
723
|
+
`- Started: ${snapshot.startedAt || 'unknown'}`,
|
|
724
|
+
`- Closed: ${snapshot.closedAt || 'unknown'}`,
|
|
725
|
+
...(duration ? [`- Duration: ${duration}`] : []),
|
|
726
|
+
`- Summary: ${snapshot.summary || 'n/a'}`
|
|
727
|
+
];
|
|
728
|
+
|
|
729
|
+
if (snapshot.git) {
|
|
730
|
+
lines.push('');
|
|
731
|
+
lines.push('## Git');
|
|
732
|
+
lines.push(`- Branch: ${snapshot.git.branch || 'unknown'}`);
|
|
733
|
+
lines.push(`- Commit: ${snapshot.git.commit || 'unknown'}`);
|
|
734
|
+
if (snapshot.git.diff_stat) {
|
|
735
|
+
lines.push('');
|
|
736
|
+
lines.push('```text');
|
|
737
|
+
lines.push(snapshot.git.diff_stat);
|
|
738
|
+
lines.push('```');
|
|
739
|
+
}
|
|
740
|
+
if (snapshot.git.changed_files.length > 0) {
|
|
741
|
+
lines.push('');
|
|
742
|
+
lines.push('## Changed Files');
|
|
743
|
+
for (const file of snapshot.git.changed_files) {
|
|
744
|
+
lines.push(`- ${file}`);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
if (Array.isArray(snapshot.recentEvents) && snapshot.recentEvents.length > 0) {
|
|
750
|
+
lines.push('');
|
|
751
|
+
lines.push('## Recent Events');
|
|
752
|
+
for (const event of snapshot.recentEvents) {
|
|
753
|
+
lines.push(`- ${event.ts} | ${event.type} | ${event.summary}`);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
lines.push('');
|
|
758
|
+
return lines.join('\n');
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
// ANSI color helpers (no external deps)
|
|
762
|
+
const ANSI = {
|
|
763
|
+
reset: '\x1b[0m',
|
|
764
|
+
bold: '\x1b[1m',
|
|
765
|
+
dim: '\x1b[2m',
|
|
766
|
+
green: '\x1b[32m',
|
|
767
|
+
yellow: '\x1b[33m',
|
|
768
|
+
red: '\x1b[31m',
|
|
769
|
+
cyan: '\x1b[36m',
|
|
770
|
+
magenta: '\x1b[35m',
|
|
771
|
+
blue: '\x1b[34m',
|
|
772
|
+
gray: '\x1b[90m'
|
|
773
|
+
};
|
|
774
|
+
|
|
775
|
+
function colorForContext(pct) {
|
|
776
|
+
if (pct >= 90) return ANSI.red;
|
|
777
|
+
if (pct >= 70) return ANSI.yellow;
|
|
778
|
+
return ANSI.green;
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
function colorForPhase(phase) {
|
|
782
|
+
if (phase === 'active') return ANSI.green;
|
|
783
|
+
if (phase === 'closed') return ANSI.gray;
|
|
784
|
+
return ANSI.yellow;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
function colorForProcess(state) {
|
|
788
|
+
if (state === 'alive') return ANSI.green;
|
|
789
|
+
if (state === 'dead') return ANSI.red;
|
|
790
|
+
return ANSI.gray;
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
function formatDurationCompact(startedAt) {
|
|
794
|
+
if (!startedAt) return '';
|
|
795
|
+
const ms = Date.now() - Date.parse(startedAt);
|
|
796
|
+
if (!Number.isFinite(ms) || ms < 0) return '';
|
|
797
|
+
const m = Math.floor(ms / 60000);
|
|
798
|
+
const s = Math.floor((ms % 60000) / 1000);
|
|
799
|
+
if (m > 60) {
|
|
800
|
+
const h = Math.floor(m / 60);
|
|
801
|
+
return `${h}h${m % 60}m`;
|
|
802
|
+
}
|
|
803
|
+
return `${m}m${s}s`;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* Print a one-line compact status bar with ANSI colors.
|
|
808
|
+
* Designed for small tmux panes (~4 lines).
|
|
809
|
+
*/
|
|
810
|
+
function printCompactStatus(snapshot, logger) {
|
|
811
|
+
const agent = snapshot.agent || '-';
|
|
812
|
+
const tool = snapshot.tool || '-';
|
|
813
|
+
const phase = snapshot.phase || 'idle';
|
|
814
|
+
const proc = snapshot.processState || 'not_tracked';
|
|
815
|
+
const pid = snapshot.pid || null;
|
|
816
|
+
|
|
817
|
+
// Context percentage if available
|
|
818
|
+
let ctxStr = '';
|
|
819
|
+
if (snapshot.run && snapshot.run.context_pct != null) {
|
|
820
|
+
const pct = Number(snapshot.run.context_pct) || 0;
|
|
821
|
+
ctxStr = `${colorForContext(pct)}ctx:${pct}%${ANSI.reset}`;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
// Token / cost if available
|
|
825
|
+
let costStr = '';
|
|
826
|
+
if (snapshot.stats && snapshot.stats.tokens_total) {
|
|
827
|
+
const tokens = snapshot.stats.tokens_total;
|
|
828
|
+
const cost = snapshot.stats.cost_usd;
|
|
829
|
+
costStr = `${ANSI.cyan}${tokens >= 1000 ? (tokens / 1000).toFixed(1) + 'k' : tokens}tk${ANSI.reset}`;
|
|
830
|
+
if (cost != null) {
|
|
831
|
+
costStr += `${ANSI.gray}/${ANSI.reset}${ANSI.cyan}$${cost.toFixed(3)}${ANSI.reset}`;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
// Plan progress
|
|
836
|
+
let planStr = '';
|
|
837
|
+
const planDone = snapshot.stats?.plan_steps_done ?? 0;
|
|
838
|
+
const planTotal = snapshot.stats?.plan_steps_total ?? 0;
|
|
839
|
+
if (planTotal > 0) {
|
|
840
|
+
planStr = `${ANSI.magenta}plan:${planDone}/${planTotal}${ANSI.reset}`;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
// Duration
|
|
844
|
+
const dur = formatDurationCompact(snapshot.startedAt);
|
|
845
|
+
const durStr = dur ? `${ANSI.blue}${dur}${ANSI.reset}` : '';
|
|
846
|
+
|
|
847
|
+
// Recent event
|
|
848
|
+
let eventStr = '';
|
|
849
|
+
if (snapshot.recentEvents && snapshot.recentEvents.length > 0) {
|
|
850
|
+
const ev = snapshot.recentEvents[snapshot.recentEvents.length - 1];
|
|
851
|
+
eventStr = `${ANSI.gray}${ev.type}${ANSI.reset}`;
|
|
852
|
+
if (ev.summary) {
|
|
853
|
+
const short = String(ev.summary).slice(0, 35);
|
|
854
|
+
eventStr += `:${ANSI.gray}${short}${ANSI.reset}`;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
// Warning
|
|
859
|
+
let warnStr = '';
|
|
860
|
+
if (snapshot.warning) {
|
|
861
|
+
warnStr = `${ANSI.red}⚠ ${snapshot.warning}${ANSI.reset}`;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
// Build line 1
|
|
865
|
+
const parts = [
|
|
866
|
+
`${colorForPhase(phase)}●${ANSI.reset}`,
|
|
867
|
+
`${ANSI.bold}${agent}${ANSI.reset}`,
|
|
868
|
+
`|`,
|
|
869
|
+
`${ANSI.blue}${tool}${ANSI.reset}`,
|
|
870
|
+
`|`,
|
|
871
|
+
`${colorForProcess(proc)}${proc}${ANSI.reset}`,
|
|
872
|
+
pid ? `${ANSI.gray}(pid:${pid})${ANSI.reset}` : '',
|
|
873
|
+
ctxStr,
|
|
874
|
+
costStr,
|
|
875
|
+
planStr,
|
|
876
|
+
durStr,
|
|
877
|
+
eventStr,
|
|
878
|
+
warnStr
|
|
879
|
+
].filter(Boolean);
|
|
880
|
+
|
|
881
|
+
logger.log(parts.join(' '));
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
/**
|
|
885
|
+
* Print two plain-text lines optimized for tmux status-bar.
|
|
886
|
+
* No ANSI colors — tmux handles its own styling.
|
|
887
|
+
* Designed for a 2-line pane.
|
|
888
|
+
*/
|
|
889
|
+
function renderMiniBar(pct, width = 10, usedLabel = '', totalLabel = '') {
|
|
890
|
+
const filled = Math.round((pct / 100) * width);
|
|
891
|
+
const empty = width - filled;
|
|
892
|
+
const bar = '█'.repeat(filled) + '░'.repeat(empty);
|
|
893
|
+
const color = pct > 80 ? '\x1b[31m' : pct > 50 ? '\x1b[33m' : '\x1b[32m';
|
|
894
|
+
const reset = '\x1b[0m';
|
|
895
|
+
const abs = usedLabel && totalLabel ? ` ${usedLabel}/${totalLabel}` : '';
|
|
896
|
+
return `${color}[${bar}]${reset}${abs} ${pct}%`;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
function formatProjectPath(targetDir) {
|
|
900
|
+
if (!targetDir) return '-';
|
|
901
|
+
const home = process.env.HOME || process.env.USERPROFILE || '';
|
|
902
|
+
let path = String(targetDir).replace(/\\/g, '/');
|
|
903
|
+
if (home && path.startsWith(home.replace(/\\/g, '/'))) {
|
|
904
|
+
path = '~' + path.slice(home.length);
|
|
905
|
+
}
|
|
906
|
+
if (path.length <= 28) return path;
|
|
907
|
+
// Too long: keep last 2 segments with ellipsis
|
|
908
|
+
const segments = path.split('/').filter(Boolean);
|
|
909
|
+
if (segments.length <= 2) return path;
|
|
910
|
+
const lastTwo = segments.slice(-2).join('/');
|
|
911
|
+
return `~/.../${lastTwo}`;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
function printTmuxBar(snapshot) {
|
|
915
|
+
const agent = snapshot.agent || '-';
|
|
916
|
+
const tool = snapshot.tool || '-';
|
|
917
|
+
const phase = snapshot.phase || 'idle';
|
|
918
|
+
const projectDir = formatProjectPath(snapshot.targetDir);
|
|
919
|
+
const dur = formatDurationCompact(snapshot.startedAt);
|
|
920
|
+
|
|
921
|
+
// Build core info
|
|
922
|
+
const parts = [];
|
|
923
|
+
parts.push(`\x1b[1;36m${projectDir}\x1b[0m`);
|
|
924
|
+
parts.push(`\x1b[1;35m${agent}\x1b[0m`);
|
|
925
|
+
parts.push(`\x1b[90m${tool}\x1b[0m`);
|
|
926
|
+
|
|
927
|
+
if (phase === 'active') {
|
|
928
|
+
parts.push(`\x1b[32m●\x1b[0m`);
|
|
929
|
+
} else if (phase === 'closed') {
|
|
930
|
+
parts.push(`\x1b[31m○\x1b[0m`);
|
|
931
|
+
} else {
|
|
932
|
+
parts.push(`\x1b[33m${phase}\x1b[0m`);
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
if (dur) {
|
|
936
|
+
parts.push(dur);
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
// Plan progress
|
|
940
|
+
const planDone = snapshot.stats?.plan_steps_done ?? 0;
|
|
941
|
+
const planTotal = snapshot.stats?.plan_steps_total ?? 0;
|
|
942
|
+
if (planTotal > 0) {
|
|
943
|
+
parts.push(`step ${planDone}/${planTotal}`);
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
// Context bar with absolute numbers
|
|
947
|
+
if (snapshot.run && snapshot.run.context_pct != null) {
|
|
948
|
+
const pct = Number(snapshot.run.context_pct) || 0;
|
|
949
|
+
parts.push(`ctx ${renderMiniBar(pct)}`);
|
|
950
|
+
} else if (snapshot.contextEstimated) {
|
|
951
|
+
const est = snapshot.contextEstimated;
|
|
952
|
+
const pct = est.pct ?? 0;
|
|
953
|
+
const used = est.estimatedTokens >= 1000 ? (est.estimatedTokens / 1000).toFixed(1) + 'k' : String(est.estimatedTokens);
|
|
954
|
+
const total = est.windowSize >= 1000 ? (est.windowSize / 1000).toFixed(1) + 'k' : String(est.windowSize);
|
|
955
|
+
parts.push(`ctx ${renderMiniBar(pct, 10, used, total)}`);
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
// Cost
|
|
959
|
+
if (snapshot.stats && snapshot.stats.tokens_total) {
|
|
960
|
+
const tokens = snapshot.stats.tokens_total;
|
|
961
|
+
const cost = snapshot.stats.cost_usd;
|
|
962
|
+
const tk = tokens >= 1000 ? (tokens / 1000).toFixed(1) + 'k' : tokens;
|
|
963
|
+
if (cost != null) {
|
|
964
|
+
parts.push(`$${cost.toFixed(2)} (${tk}tk)`);
|
|
965
|
+
} else {
|
|
966
|
+
parts.push(`${tk}tk`);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
// Recent useful event (skip session_started boilerplate)
|
|
971
|
+
let lastEvent = null;
|
|
972
|
+
if (snapshot.recentEvents && snapshot.recentEvents.length > 0) {
|
|
973
|
+
for (let i = snapshot.recentEvents.length - 1; i >= 0; i--) {
|
|
974
|
+
const ev = snapshot.recentEvents[i];
|
|
975
|
+
const type = String(ev.type || '');
|
|
976
|
+
if (type !== 'session_started' && type !== 'session_closed') {
|
|
977
|
+
lastEvent = ev;
|
|
978
|
+
break;
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
if (lastEvent) {
|
|
983
|
+
const short = String(lastEvent.summary || lastEvent.type || '').slice(0, 40);
|
|
984
|
+
if (short) {
|
|
985
|
+
parts.push(`\x1b[90m${short}\x1b[0m`);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
// Warning
|
|
990
|
+
if (snapshot.warning) {
|
|
991
|
+
parts.push(`\x1b[1;31m! ${snapshot.warning}\x1b[0m`);
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
// When running inside the tmux updater, omit newline so the line can be overwritten.
|
|
995
|
+
// When called directly by a user, append newline for clean shell prompt.
|
|
996
|
+
const suffix = process.env.AIOSON_TMUX_BAR ? '' : '\n';
|
|
997
|
+
process.stdout.write(parts.join(' │ ') + suffix);
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
function printLiveStatusSnapshot(snapshot, logger) {
|
|
1001
|
+
logger.log(`Live session: ${snapshot.sessionKey || 'none'}`);
|
|
1002
|
+
logger.log(`Phase: ${snapshot.phase}`);
|
|
1003
|
+
logger.log(`Tool: ${snapshot.tool || '-'}`);
|
|
1004
|
+
logger.log(`Active agent: ${snapshot.agent || '-'}`);
|
|
1005
|
+
if (snapshot.stats && Number(snapshot.stats.plan_steps_total || 0) > 0) {
|
|
1006
|
+
logger.log(`Plan: ${snapshot.stats.plan_steps_done || 0}/${snapshot.stats.plan_steps_total || 0}`);
|
|
1007
|
+
}
|
|
1008
|
+
logger.log(`Process: ${snapshot.processState}${snapshot.pid ? ` (pid ${snapshot.pid})` : ''}`);
|
|
1009
|
+
|
|
1010
|
+
if (snapshot.task) {
|
|
1011
|
+
logger.log(`Task: ${snapshot.task.task_key} | status: ${snapshot.task.status} | work: ${snapshot.task.title || '-'}`);
|
|
1012
|
+
}
|
|
1013
|
+
if (snapshot.run) {
|
|
1014
|
+
logger.log(`Run: ${snapshot.run.run_key} | status: ${snapshot.run.status} | work: ${snapshot.run.title || snapshot.run.summary || '-'}`);
|
|
1015
|
+
}
|
|
1016
|
+
if (snapshot.startedAt) {
|
|
1017
|
+
logger.log(`Started: ${snapshot.startedAt}`);
|
|
1018
|
+
}
|
|
1019
|
+
if (snapshot.updatedAt) {
|
|
1020
|
+
logger.log(`Updated: ${snapshot.updatedAt}`);
|
|
1021
|
+
}
|
|
1022
|
+
if (snapshot.closedAt) {
|
|
1023
|
+
logger.log(`Closed: ${snapshot.closedAt}`);
|
|
1024
|
+
}
|
|
1025
|
+
if (snapshot.warning) {
|
|
1026
|
+
logger.log(`Warning: ${snapshot.warning}`);
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
if (snapshot.recentEvents.length === 0) {
|
|
1030
|
+
logger.log('Recent events: none');
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
logger.log('Recent events:');
|
|
1035
|
+
for (const event of snapshot.recentEvents) {
|
|
1036
|
+
logger.log(`- ${event.ts} | ${event.type} | ${event.summary || '-'}`);
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
async function getLiveStatusSnapshot(targetDir, t, options = {}) {
|
|
1041
|
+
const { dbPath } = resolveRuntimePaths(targetDir);
|
|
1042
|
+
|
|
1043
|
+
if (!(await runtimeStoreExists(targetDir))) {
|
|
1044
|
+
throw new Error(t('runtime.store_missing', { path: dbPath }));
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
const { db, runtimeDir } = await openRuntimeDb(targetDir, { mustExist: true });
|
|
1048
|
+
try {
|
|
1049
|
+
const context = await resolveLiveContext(targetDir, db, runtimeDir, {
|
|
1050
|
+
agentName: options.agent,
|
|
1051
|
+
limit: options.limit
|
|
1052
|
+
});
|
|
1053
|
+
|
|
1054
|
+
if (!context.run && !context.state) {
|
|
1055
|
+
return {
|
|
1056
|
+
ok: true,
|
|
1057
|
+
targetDir,
|
|
1058
|
+
dbPath,
|
|
1059
|
+
agent: context.agentName,
|
|
1060
|
+
tool: null,
|
|
1061
|
+
phase: 'idle',
|
|
1062
|
+
open: false,
|
|
1063
|
+
processState: 'not_tracked',
|
|
1064
|
+
pid: null,
|
|
1065
|
+
sessionKey: null,
|
|
1066
|
+
startedAt: null,
|
|
1067
|
+
updatedAt: null,
|
|
1068
|
+
closedAt: null,
|
|
1069
|
+
title: null,
|
|
1070
|
+
currentTask: null,
|
|
1071
|
+
run: null,
|
|
1072
|
+
task: null,
|
|
1073
|
+
stats: normalizeLiveStats(null),
|
|
1074
|
+
recentEvents: []
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
const taskMeta = parseTaskMeta(context.task);
|
|
1079
|
+
const planStats = getPlanStats(taskMeta);
|
|
1080
|
+
const state = context.state || createLiveState(targetDir, context.run, context.task, {
|
|
1081
|
+
sessionKey: context.sessionKey,
|
|
1082
|
+
activeAgent: context.agentName,
|
|
1083
|
+
projectPath: targetDir
|
|
1084
|
+
});
|
|
1085
|
+
state.stats = normalizeLiveStats(state.stats, planStats);
|
|
1086
|
+
|
|
1087
|
+
// Prefer run.agent_name when no explicit --agent was passed;
|
|
1088
|
+
// this lets events emitted by other agents update the bar dynamically.
|
|
1089
|
+
const effectiveAgent = options.agent
|
|
1090
|
+
? context.agentName
|
|
1091
|
+
: (context.run?.agent_name || context.agentName);
|
|
1092
|
+
|
|
1093
|
+
const snapshot = {
|
|
1094
|
+
ok: true,
|
|
1095
|
+
targetDir,
|
|
1096
|
+
dbPath,
|
|
1097
|
+
agent: effectiveAgent,
|
|
1098
|
+
tool: state.tool_session || null,
|
|
1099
|
+
phase: context.phase,
|
|
1100
|
+
open: context.open,
|
|
1101
|
+
processState: context.processState,
|
|
1102
|
+
pid: state.child_pid || null,
|
|
1103
|
+
sessionKey: context.sessionKey,
|
|
1104
|
+
startedAt: state.started_at || null,
|
|
1105
|
+
updatedAt: state.updated_at || null,
|
|
1106
|
+
closedAt: state.closed_at || null,
|
|
1107
|
+
title: state.title || null,
|
|
1108
|
+
currentTask: state.current_task || null,
|
|
1109
|
+
run: context.run,
|
|
1110
|
+
task: context.task,
|
|
1111
|
+
stats: state.stats,
|
|
1112
|
+
recentEvents: Array.isArray(state.last_events) && state.last_events.length > 0 ? state.last_events : context.recentEvents,
|
|
1113
|
+
contextEstimated: state.context_estimated || null,
|
|
1114
|
+
warning: context.processState === 'dead' && context.phase === 'active'
|
|
1115
|
+
? t('live.process_dead_warning')
|
|
1116
|
+
: null
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
// Fallback: estimate context on-the-fly if not recorded at session start
|
|
1120
|
+
if (!snapshot.contextEstimated && snapshot.phase !== 'idle') {
|
|
1121
|
+
try {
|
|
1122
|
+
snapshot.contextEstimated = await estimateContextSize(targetDir);
|
|
1123
|
+
} catch {
|
|
1124
|
+
// non-fatal
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
return snapshot;
|
|
1129
|
+
} finally {
|
|
1130
|
+
db.close();
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1134
|
+
async function runLiveStart({ args, options = {}, logger, t }) {
|
|
1135
|
+
const targetDir = resolveTargetDir(args);
|
|
1136
|
+
const agentName = normalizeAgentHandle(requireOption(options, 'agent', t));
|
|
1137
|
+
const tool = normalizeLiveTool(requireOption(options, 'tool', t), t);
|
|
1138
|
+
const noLaunch = Boolean(options['no-launch']);
|
|
1139
|
+
|
|
1140
|
+
if (options.json && !noLaunch && !options.attach) {
|
|
1141
|
+
throw new Error(t('live.json_requires_no_launch'));
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
// ── 5.3 Ambient Intelligence health check alert ────────────────────────────
|
|
1145
|
+
if (!options.json && !options['no-health-check']) {
|
|
1146
|
+
try {
|
|
1147
|
+
const { runHealthCheck, formatHealthAlert } = require('../lib/health-check');
|
|
1148
|
+
const health = await runHealthCheck(targetDir);
|
|
1149
|
+
const alert = formatHealthAlert(health.items);
|
|
1150
|
+
if (alert) {
|
|
1151
|
+
logger.log('');
|
|
1152
|
+
logger.log(alert);
|
|
1153
|
+
logger.log('');
|
|
1154
|
+
}
|
|
1155
|
+
} catch { /* health check is non-fatal */ }
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
const toolBinary = String(options['tool-bin'] || tool).trim();
|
|
1159
|
+
const binaryPath = await resolveExecutablePath(toolBinary);
|
|
1160
|
+
if (!binaryPath) {
|
|
1161
|
+
throw new Error(t('live.tool_binary_not_found', { binary: toolBinary }));
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
const useTmux = Boolean(options.tmux) || process.env.AIOSON_TMUX === '1';
|
|
1165
|
+
|
|
1166
|
+
// Pre-check tmux availability so we can warn early
|
|
1167
|
+
if (useTmux && !noLaunch) {
|
|
1168
|
+
const tmuxOk = await isTmuxAvailable();
|
|
1169
|
+
if (!tmuxOk && !options.json) {
|
|
1170
|
+
logger.log(t('live.tmux_not_found', { tool }));
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
const { db, dbPath, runtimeDir } = await openRuntimeDb(targetDir);
|
|
1175
|
+
|
|
1176
|
+
try {
|
|
1177
|
+
const existing = await resolveLiveContext(targetDir, db, runtimeDir, {
|
|
1178
|
+
agentName,
|
|
1179
|
+
limit: options.limit
|
|
1180
|
+
});
|
|
1181
|
+
|
|
1182
|
+
if (existing.run && existing.run.source === 'live' && existing.open) {
|
|
1183
|
+
const state = existing.state || createLiveState(targetDir, existing.run, existing.task, {
|
|
1184
|
+
sessionKey: existing.sessionKey,
|
|
1185
|
+
activeAgent: existing.agentName,
|
|
1186
|
+
projectPath: targetDir
|
|
1187
|
+
});
|
|
1188
|
+
|
|
1189
|
+
// ── Tmux session recovery: if tmux was killed, close the stale live session ──
|
|
1190
|
+
if (useTmux) {
|
|
1191
|
+
const sessionName = buildSessionName(targetDir, agentName);
|
|
1192
|
+
const tmuxAlive = await hasSession(sessionName);
|
|
1193
|
+
if (!tmuxAlive) {
|
|
1194
|
+
// Tmux is gone — close the stale live session in DB and continue to create new
|
|
1195
|
+
const now = new Date().toISOString();
|
|
1196
|
+
updateRun(db, {
|
|
1197
|
+
runKey: existing.run.run_key,
|
|
1198
|
+
status: 'completed',
|
|
1199
|
+
summary: 'Closed because tmux session was terminated',
|
|
1200
|
+
eventType: 'session_closed',
|
|
1201
|
+
phase: 'live',
|
|
1202
|
+
message: 'Tmux session ended — live session auto-closed'
|
|
1203
|
+
});
|
|
1204
|
+
if (existing.task?.task_key) {
|
|
1205
|
+
updateTask(db, {
|
|
1206
|
+
taskKey: existing.task.task_key,
|
|
1207
|
+
status: 'completed',
|
|
1208
|
+
goal: 'Auto-closed after tmux termination'
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
await clearAgentSession(runtimeDir, agentName);
|
|
1212
|
+
if (!options.json) {
|
|
1213
|
+
logger.log(t('live.tmux_recreate', { agent: agentName, session: existing.sessionKey }));
|
|
1214
|
+
}
|
|
1215
|
+
// Fall through to create a new session below
|
|
1216
|
+
} else {
|
|
1217
|
+
// Tmux still alive — reattach instead of creating new
|
|
1218
|
+
if (!options.json) {
|
|
1219
|
+
logger.log(t('live.tmux_reattach', { agent: agentName, session: existing.sessionKey }));
|
|
1220
|
+
}
|
|
1221
|
+
const sessionName = buildSessionName(targetDir, agentName);
|
|
1222
|
+
await attachSession(sessionName);
|
|
1223
|
+
return {
|
|
1224
|
+
ok: true,
|
|
1225
|
+
targetDir,
|
|
1226
|
+
dbPath,
|
|
1227
|
+
tmux: true,
|
|
1228
|
+
reused: true,
|
|
1229
|
+
agent: existing.agentName,
|
|
1230
|
+
tool: state.tool_session || tool,
|
|
1231
|
+
taskKey: existing.task?.task_key || existing.sessionRef?.taskKey || null,
|
|
1232
|
+
runKey: existing.run.run_key,
|
|
1233
|
+
sessionKey: existing.sessionKey,
|
|
1234
|
+
open: true
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
} else {
|
|
1238
|
+
// Non-tmux reuse logic (original behavior)
|
|
1239
|
+
const existingTool = state.tool_session || null;
|
|
1240
|
+
if (existingTool && existingTool !== tool) {
|
|
1241
|
+
throw new Error(t('live.tool_mismatch', { existing: existingTool, requested: tool }));
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
const attach = Boolean(options.attach);
|
|
1245
|
+
let attachChild = null;
|
|
1246
|
+
let attachResult = null;
|
|
1247
|
+
|
|
1248
|
+
if (attach && !noLaunch) {
|
|
1249
|
+
attachChild = spawn(binaryPath, buildLaunchArgs(options, tool), {
|
|
1250
|
+
cwd: targetDir,
|
|
1251
|
+
env: process.env,
|
|
1252
|
+
stdio: 'inherit'
|
|
1253
|
+
});
|
|
1254
|
+
state.child_pid = attachChild.pid || null;
|
|
1255
|
+
if (existing.task?.task_key) {
|
|
1256
|
+
const taskMeta = parseTaskMeta(existing.task);
|
|
1257
|
+
taskMeta.child_pid = state.child_pid;
|
|
1258
|
+
updateTask(db, { taskKey: existing.task.task_key, metaJson: taskMeta });
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
await writeLiveState(runtimeDir, existing.sessionKey, state);
|
|
1263
|
+
|
|
1264
|
+
if (!options.json) {
|
|
1265
|
+
logger.log(t('live.session_already_active', { agent: agentName, session: existing.sessionKey, runKey: existing.run.run_key, dbPath }));
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
if (attachChild) {
|
|
1269
|
+
attachResult = await waitForChild(attachChild);
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
return {
|
|
1273
|
+
ok: true,
|
|
1274
|
+
targetDir,
|
|
1275
|
+
dbPath,
|
|
1276
|
+
agent: existing.agentName,
|
|
1277
|
+
tool: state.tool_session || tool,
|
|
1278
|
+
taskKey: existing.task?.task_key || existing.sessionRef?.taskKey || null,
|
|
1279
|
+
runKey: existing.run.run_key,
|
|
1280
|
+
sessionKey: existing.sessionKey,
|
|
1281
|
+
pid: state.child_pid || null,
|
|
1282
|
+
processState: detectProcessState(state.child_pid),
|
|
1283
|
+
reused: true,
|
|
1284
|
+
open: true,
|
|
1285
|
+
attached: attach,
|
|
1286
|
+
childExitCode: attachResult?.code ?? null,
|
|
1287
|
+
childSignal: attachResult?.signal ?? null
|
|
1288
|
+
};
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
const now = new Date().toISOString();
|
|
1293
|
+
const sessionKey = options.session ? String(options.session).trim() : makeDirectSessionKey(agentName);
|
|
1294
|
+
const title = options.title ? String(options.title).trim() : `live-${tool}-${Date.now()}`;
|
|
1295
|
+
const goal = options.goal ? String(options.goal).trim() : null;
|
|
1296
|
+
const planRef = options.plan ? String(options.plan).trim() : null;
|
|
1297
|
+
const plan = await loadPlanReference(targetDir, planRef);
|
|
1298
|
+
const startMessage = truncateMessage(options.message, `Live session started for ${agentName} with ${tool}`);
|
|
1299
|
+
const taskMeta = {
|
|
1300
|
+
tool_session: tool,
|
|
1301
|
+
plan_ref: plan.planRef,
|
|
1302
|
+
path: targetDir,
|
|
1303
|
+
child_pid: null
|
|
1304
|
+
};
|
|
1305
|
+
if (plan.planSteps.length > 0) {
|
|
1306
|
+
taskMeta.plan_steps = plan.planSteps;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
const taskKey = startTask(db, {
|
|
1310
|
+
sessionKey,
|
|
1311
|
+
title,
|
|
1312
|
+
goal,
|
|
1313
|
+
status: 'running',
|
|
1314
|
+
createdBy: agentName,
|
|
1315
|
+
taskKind: 'live_session',
|
|
1316
|
+
metaJson: taskMeta
|
|
1317
|
+
});
|
|
1318
|
+
|
|
1319
|
+
const runKey = startRun(db, {
|
|
1320
|
+
taskKey,
|
|
1321
|
+
agentName,
|
|
1322
|
+
agentKind: 'official',
|
|
1323
|
+
sessionKey,
|
|
1324
|
+
source: 'live',
|
|
1325
|
+
title,
|
|
1326
|
+
eventType: 'session_started',
|
|
1327
|
+
phase: 'live',
|
|
1328
|
+
message: startMessage,
|
|
1329
|
+
payload: {
|
|
1330
|
+
tool_session: tool,
|
|
1331
|
+
plan_ref: plan.planRef,
|
|
1332
|
+
plan_steps_total: plan.planSteps.length,
|
|
1333
|
+
path: targetDir
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1336
|
+
|
|
1337
|
+
let child = null;
|
|
1338
|
+
let childResult = null;
|
|
1339
|
+
let tmuxResult = null;
|
|
1340
|
+
if (!noLaunch) {
|
|
1341
|
+
if (useTmux) {
|
|
1342
|
+
const tmuxOk = await isTmuxAvailable();
|
|
1343
|
+
if (tmuxOk) {
|
|
1344
|
+
if (!options.json) {
|
|
1345
|
+
logger.log(t('live.tmux_starting', { agent: agentName, tool }));
|
|
1346
|
+
}
|
|
1347
|
+
tmuxResult = await launchTmuxSession({
|
|
1348
|
+
targetDir,
|
|
1349
|
+
agentName,
|
|
1350
|
+
tool,
|
|
1351
|
+
binaryPath,
|
|
1352
|
+
toolArgs: buildLaunchArgs(options, tool)
|
|
1353
|
+
});
|
|
1354
|
+
} else {
|
|
1355
|
+
// Fallback to normal spawn if tmux not available
|
|
1356
|
+
child = spawn(binaryPath, buildLaunchArgs(options, tool), {
|
|
1357
|
+
cwd: targetDir,
|
|
1358
|
+
env: process.env,
|
|
1359
|
+
stdio: 'inherit'
|
|
1360
|
+
});
|
|
1361
|
+
taskMeta.child_pid = child.pid || null;
|
|
1362
|
+
updateTask(db, {
|
|
1363
|
+
taskKey,
|
|
1364
|
+
metaJson: taskMeta
|
|
1365
|
+
});
|
|
1366
|
+
}
|
|
1367
|
+
} else {
|
|
1368
|
+
child = spawn(binaryPath, buildLaunchArgs(options, tool), {
|
|
1369
|
+
cwd: targetDir,
|
|
1370
|
+
env: process.env,
|
|
1371
|
+
stdio: 'inherit'
|
|
1372
|
+
});
|
|
1373
|
+
taskMeta.child_pid = child.pid || null;
|
|
1374
|
+
updateTask(db, {
|
|
1375
|
+
taskKey,
|
|
1376
|
+
metaJson: taskMeta
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
await writeAgentSession(runtimeDir, agentName, {
|
|
1382
|
+
runKey,
|
|
1383
|
+
taskKey,
|
|
1384
|
+
sessionKey,
|
|
1385
|
+
startedAt: now,
|
|
1386
|
+
finished: false,
|
|
1387
|
+
source: 'live'
|
|
1388
|
+
});
|
|
1389
|
+
|
|
1390
|
+
const state = createLiveState(targetDir, {
|
|
1391
|
+
run_key: runKey,
|
|
1392
|
+
session_key: sessionKey,
|
|
1393
|
+
agent_name: agentName,
|
|
1394
|
+
title,
|
|
1395
|
+
status: 'running',
|
|
1396
|
+
started_at: now,
|
|
1397
|
+
updated_at: now
|
|
1398
|
+
}, {
|
|
1399
|
+
task_key: taskKey,
|
|
1400
|
+
session_key: sessionKey,
|
|
1401
|
+
title,
|
|
1402
|
+
meta_json: JSON.stringify(taskMeta),
|
|
1403
|
+
created_at: now,
|
|
1404
|
+
updated_at: now
|
|
1405
|
+
}, {
|
|
1406
|
+
tool,
|
|
1407
|
+
planRef: plan.planRef,
|
|
1408
|
+
activeAgent: agentName,
|
|
1409
|
+
currentRunKey: runKey,
|
|
1410
|
+
projectPath: targetDir,
|
|
1411
|
+
childPid: taskMeta.child_pid,
|
|
1412
|
+
stats: {
|
|
1413
|
+
tasks_completed: 0,
|
|
1414
|
+
events_total: 1,
|
|
1415
|
+
plan_steps_done: 0,
|
|
1416
|
+
plan_steps_total: plan.planSteps.length
|
|
1417
|
+
},
|
|
1418
|
+
lastEvents: [{
|
|
1419
|
+
ts: now,
|
|
1420
|
+
type: 'session_started',
|
|
1421
|
+
summary: startMessage
|
|
1422
|
+
}]
|
|
1423
|
+
});
|
|
1424
|
+
|
|
1425
|
+
// Estimate context size for observability
|
|
1426
|
+
try {
|
|
1427
|
+
const ctxEst = await estimateContextSize(targetDir);
|
|
1428
|
+
state.context_estimated = ctxEst;
|
|
1429
|
+
} catch {
|
|
1430
|
+
// non-fatal
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
await writeLiveState(runtimeDir, sessionKey, state);
|
|
1434
|
+
await appendLiveEvent(runtimeDir, sessionKey, {
|
|
1435
|
+
ts: now,
|
|
1436
|
+
type: 'session_started',
|
|
1437
|
+
summary: startMessage,
|
|
1438
|
+
agent: agentName,
|
|
1439
|
+
task_key: taskKey,
|
|
1440
|
+
run_key: runKey,
|
|
1441
|
+
session_key: sessionKey,
|
|
1442
|
+
refs: [],
|
|
1443
|
+
plan_step: null,
|
|
1444
|
+
status: 'running',
|
|
1445
|
+
meta: {
|
|
1446
|
+
tool_session: tool,
|
|
1447
|
+
child_pid: taskMeta.child_pid,
|
|
1448
|
+
path: targetDir,
|
|
1449
|
+
plan_ref: plan.planRef,
|
|
1450
|
+
plan_steps_total: plan.planSteps.length
|
|
1451
|
+
}
|
|
1452
|
+
});
|
|
1453
|
+
|
|
1454
|
+
if (!options.json) {
|
|
1455
|
+
logger.log(t('live.session_started', { agent: agentName, tool, session: sessionKey, dbPath }));
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
// Ambient Intelligence: exibe digest de saúde ao iniciar sessão
|
|
1459
|
+
if (!options.json && !options['no-health']) {
|
|
1460
|
+
try {
|
|
1461
|
+
const { getHealthDigest } = require('./health');
|
|
1462
|
+
const items = await getHealthDigest(targetDir);
|
|
1463
|
+
if (items && items.length > 0) {
|
|
1464
|
+
logger.log('');
|
|
1465
|
+
logger.log('AIOSON Health — itens pendentes:');
|
|
1466
|
+
for (const item of items) {
|
|
1467
|
+
logger.log(` ● ${item}`);
|
|
1468
|
+
}
|
|
1469
|
+
logger.log(' → aioson health . para detalhes');
|
|
1470
|
+
logger.log('');
|
|
1471
|
+
}
|
|
1472
|
+
} catch { /* não bloqueia o start */ }
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
if (child) {
|
|
1476
|
+
childResult = await waitForChild(child);
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
if (tmuxResult) {
|
|
1480
|
+
return {
|
|
1481
|
+
ok: true,
|
|
1482
|
+
targetDir,
|
|
1483
|
+
dbPath,
|
|
1484
|
+
tmux: true,
|
|
1485
|
+
sessionName: tmuxResult.sessionName,
|
|
1486
|
+
agent: agentName,
|
|
1487
|
+
tool,
|
|
1488
|
+
taskKey,
|
|
1489
|
+
runKey,
|
|
1490
|
+
sessionKey,
|
|
1491
|
+
pid: null,
|
|
1492
|
+
processState: 'tmux',
|
|
1493
|
+
reused: false,
|
|
1494
|
+
open: true
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
return {
|
|
1499
|
+
ok: true,
|
|
1500
|
+
targetDir,
|
|
1501
|
+
dbPath,
|
|
1502
|
+
agent: agentName,
|
|
1503
|
+
tool,
|
|
1504
|
+
taskKey,
|
|
1505
|
+
runKey,
|
|
1506
|
+
sessionKey,
|
|
1507
|
+
pid: taskMeta.child_pid,
|
|
1508
|
+
processState: detectProcessState(taskMeta.child_pid),
|
|
1509
|
+
reused: false,
|
|
1510
|
+
open: true,
|
|
1511
|
+
childExitCode: childResult?.code ?? null,
|
|
1512
|
+
childSignal: childResult?.signal ?? null
|
|
1513
|
+
};
|
|
1514
|
+
} finally {
|
|
1515
|
+
db.close();
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
async function runRuntimeEmit({ args, options = {}, logger, t }) {
|
|
1520
|
+
const targetDir = resolveTargetDir(args);
|
|
1521
|
+
const agentName = normalizeAgentHandle(requireOption(options, 'agent', t));
|
|
1522
|
+
const eventType = String(options.type || 'note').trim() || 'note';
|
|
1523
|
+
|
|
1524
|
+
const { db, dbPath, runtimeDir, context } = await requireActiveLiveContext(targetDir, agentName, t, {
|
|
1525
|
+
limit: options.limit
|
|
1526
|
+
});
|
|
1527
|
+
|
|
1528
|
+
try {
|
|
1529
|
+
const now = new Date().toISOString();
|
|
1530
|
+
const refs = parseRefs(options.refs);
|
|
1531
|
+
const planStep = options['plan-step'] ? String(options['plan-step']).trim() : null;
|
|
1532
|
+
const summary = truncateMessage(
|
|
1533
|
+
options.summary || options.message || options.title || `${eventType} emitted by ${agentName}`
|
|
1534
|
+
);
|
|
1535
|
+
const meta = parseJsonOption(options.meta);
|
|
1536
|
+
const payload = meta && typeof meta === 'object' ? { ...meta } : {};
|
|
1537
|
+
if (refs.length > 0) payload.refs = refs;
|
|
1538
|
+
if (planStep) payload.plan_step = planStep;
|
|
1539
|
+
|
|
1540
|
+
const state = context.state || createLiveState(targetDir, context.run, context.task, {
|
|
1541
|
+
sessionKey: context.sessionKey,
|
|
1542
|
+
activeAgent: context.agentName,
|
|
1543
|
+
projectPath: targetDir
|
|
1544
|
+
});
|
|
1545
|
+
|
|
1546
|
+
let currentTaskKey = state.current_task || null;
|
|
1547
|
+
let nextCurrentTask = currentTaskKey;
|
|
1548
|
+
|
|
1549
|
+
if (eventType === 'task_started') {
|
|
1550
|
+
if (currentTaskKey) {
|
|
1551
|
+
throw new Error(t('live.micro_task_already_open', { agent: agentName }));
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
currentTaskKey = startTask(db, {
|
|
1555
|
+
sessionKey: context.sessionKey,
|
|
1556
|
+
title: options.title ? String(options.title).trim() : summary,
|
|
1557
|
+
goal: summary,
|
|
1558
|
+
status: 'running',
|
|
1559
|
+
createdBy: agentName,
|
|
1560
|
+
taskKind: 'micro_task',
|
|
1561
|
+
parentTaskKey: context.task.task_key,
|
|
1562
|
+
metaJson: {
|
|
1563
|
+
refs,
|
|
1564
|
+
plan_step: planStep
|
|
1565
|
+
}
|
|
1566
|
+
});
|
|
1567
|
+
nextCurrentTask = currentTaskKey;
|
|
1568
|
+
payload.micro_task_key = currentTaskKey;
|
|
1569
|
+
} else if (eventType === 'task_completed') {
|
|
1570
|
+
if (currentTaskKey) {
|
|
1571
|
+
updateTask(db, {
|
|
1572
|
+
taskKey: currentTaskKey,
|
|
1573
|
+
status: 'completed',
|
|
1574
|
+
goal: summary,
|
|
1575
|
+
metaJson: {
|
|
1576
|
+
refs,
|
|
1577
|
+
plan_step: planStep
|
|
1578
|
+
}
|
|
1579
|
+
});
|
|
1580
|
+
} else {
|
|
1581
|
+
currentTaskKey = startTask(db, {
|
|
1582
|
+
sessionKey: context.sessionKey,
|
|
1583
|
+
title: options.title ? String(options.title).trim() : summary,
|
|
1584
|
+
goal: summary,
|
|
1585
|
+
status: 'completed',
|
|
1586
|
+
createdBy: agentName,
|
|
1587
|
+
taskKind: 'micro_task',
|
|
1588
|
+
parentTaskKey: context.task.task_key,
|
|
1589
|
+
metaJson: {
|
|
1590
|
+
refs,
|
|
1591
|
+
plan_step: planStep,
|
|
1592
|
+
implicit: true
|
|
1593
|
+
}
|
|
1594
|
+
});
|
|
1595
|
+
}
|
|
1596
|
+
nextCurrentTask = null;
|
|
1597
|
+
payload.micro_task_key = currentTaskKey;
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
let planStats = null;
|
|
1601
|
+
if (eventType === 'plan_checkpoint' && planStep) {
|
|
1602
|
+
const sessionMeta = parseTaskMeta(context.task);
|
|
1603
|
+
if (Array.isArray(sessionMeta.plan_steps)) {
|
|
1604
|
+
const normalizedPlanStep = normalizePlanStepId(planStep).toLowerCase();
|
|
1605
|
+
let changed = false;
|
|
1606
|
+
sessionMeta.plan_steps = sessionMeta.plan_steps.map((step) => {
|
|
1607
|
+
if (!step || normalizePlanStepId(step.id).toLowerCase() !== normalizedPlanStep) return step;
|
|
1608
|
+
if (step.done) return step;
|
|
1609
|
+
changed = true;
|
|
1610
|
+
return { ...step, done: true };
|
|
1611
|
+
});
|
|
1612
|
+
if (changed) {
|
|
1613
|
+
updateTask(db, {
|
|
1614
|
+
taskKey: context.task.task_key,
|
|
1615
|
+
metaJson: sessionMeta
|
|
1616
|
+
});
|
|
1617
|
+
planStats = getPlanStats(sessionMeta);
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
const workerStatus = options['worker-status'] ? String(options['worker-status']).trim() : null;
|
|
1623
|
+
const verdict = options.verdict ? String(options.verdict).trim().toUpperCase() : null;
|
|
1624
|
+
const tokenCount = options['token-count'] != null ? Number(options['token-count']) || null : null;
|
|
1625
|
+
const progressPct = options['progress-pct'] != null ? Number(options['progress-pct']) || null : null;
|
|
1626
|
+
|
|
1627
|
+
appendRunEvent(db, {
|
|
1628
|
+
runKey: context.run.run_key,
|
|
1629
|
+
eventType,
|
|
1630
|
+
phase: 'live',
|
|
1631
|
+
status: context.run.status || 'running',
|
|
1632
|
+
message: summary,
|
|
1633
|
+
payload: Object.keys(payload).length > 0 ? payload : null,
|
|
1634
|
+
createdAt: now,
|
|
1635
|
+
planStepId: planStep || null,
|
|
1636
|
+
workerStatus,
|
|
1637
|
+
verdict,
|
|
1638
|
+
tokenCount,
|
|
1639
|
+
progressPct
|
|
1640
|
+
});
|
|
1641
|
+
|
|
1642
|
+
const eventRecord = createLiveEventRecord(context, {
|
|
1643
|
+
ts: now,
|
|
1644
|
+
type: eventType,
|
|
1645
|
+
summary,
|
|
1646
|
+
refs,
|
|
1647
|
+
planStep,
|
|
1648
|
+
taskKey: currentTaskKey,
|
|
1649
|
+
meta: meta && Object.keys(meta).length > 0 ? meta : null
|
|
1650
|
+
});
|
|
1651
|
+
|
|
1652
|
+
await appendLiveEvent(runtimeDir, context.sessionKey, eventRecord);
|
|
1653
|
+
|
|
1654
|
+
const nextState = applyEventToState(state, eventRecord, {
|
|
1655
|
+
currentTask: nextCurrentTask,
|
|
1656
|
+
planStats,
|
|
1657
|
+
activeAgent: context.agentName,
|
|
1658
|
+
currentRunKey: context.run.run_key
|
|
1659
|
+
});
|
|
1660
|
+
await writeLiveState(runtimeDir, context.sessionKey, nextState);
|
|
1661
|
+
|
|
1662
|
+
if (!options.json) {
|
|
1663
|
+
logger.log(t('live.event_recorded', { agent: agentName, eventType, session: context.sessionKey, dbPath }));
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
return {
|
|
1667
|
+
ok: true,
|
|
1668
|
+
targetDir,
|
|
1669
|
+
dbPath,
|
|
1670
|
+
agent: context.agentName,
|
|
1671
|
+
eventType,
|
|
1672
|
+
sessionKey: context.sessionKey,
|
|
1673
|
+
runKey: context.run.run_key,
|
|
1674
|
+
taskKey: currentTaskKey || context.task.task_key,
|
|
1675
|
+
currentTask: nextCurrentTask,
|
|
1676
|
+
open: true
|
|
1677
|
+
};
|
|
1678
|
+
} finally {
|
|
1679
|
+
db.close();
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
|
|
1684
|
+
async function runLiveHandoff({ args, options = {}, logger, t }) {
|
|
1685
|
+
const targetDir = resolveTargetDir(args);
|
|
1686
|
+
const agentName = normalizeAgentHandle(requireOption(options, 'agent', t));
|
|
1687
|
+
const nextAgent = normalizeAgentHandle(requireOption(options, 'to', t));
|
|
1688
|
+
|
|
1689
|
+
if (agentName === nextAgent) {
|
|
1690
|
+
throw new Error(t('live.handoff_same_agent'));
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
const reason = truncateMessage(
|
|
1694
|
+
options.reason || options.summary || options.message,
|
|
1695
|
+
`Handoff from ${agentName} to ${nextAgent}`
|
|
1696
|
+
);
|
|
1697
|
+
|
|
1698
|
+
const { db, dbPath, runtimeDir, context } = await requireActiveLiveContext(targetDir, agentName, t, {
|
|
1699
|
+
limit: options.limit
|
|
1700
|
+
});
|
|
1701
|
+
|
|
1702
|
+
try {
|
|
1703
|
+
if (!context.run || context.run.agent_name !== agentName) {
|
|
1704
|
+
throw new Error(t('live.handoff_agent_mismatch', { agent: agentName }));
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
const now = new Date().toISOString();
|
|
1708
|
+
const state = context.state || createLiveState(targetDir, context.run, context.task, {
|
|
1709
|
+
sessionKey: context.sessionKey,
|
|
1710
|
+
activeAgent: context.agentName,
|
|
1711
|
+
projectPath: targetDir
|
|
1712
|
+
});
|
|
1713
|
+
|
|
1714
|
+
const handoffSummary = truncateMessage(`Handoff to ${nextAgent}: ${reason}`);
|
|
1715
|
+
let currentTaskClosed = false;
|
|
1716
|
+
if (state.current_task) {
|
|
1717
|
+
updateTask(db, {
|
|
1718
|
+
taskKey: state.current_task,
|
|
1719
|
+
status: 'completed',
|
|
1720
|
+
goal: truncateMessage(`Closed on handoff to ${nextAgent}: ${reason}`)
|
|
1721
|
+
});
|
|
1722
|
+
currentTaskClosed = true;
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
updateRun(db, {
|
|
1726
|
+
runKey: context.run.run_key,
|
|
1727
|
+
status: 'completed',
|
|
1728
|
+
summary: reason,
|
|
1729
|
+
eventType: 'handoff',
|
|
1730
|
+
phase: 'live',
|
|
1731
|
+
message: handoffSummary,
|
|
1732
|
+
payload: {
|
|
1733
|
+
from: agentName,
|
|
1734
|
+
to: nextAgent,
|
|
1735
|
+
reason,
|
|
1736
|
+
previous_run_key: context.run.run_key,
|
|
1737
|
+
micro_task_key: state.current_task || null,
|
|
1738
|
+
closed_by: 'live:handoff'
|
|
1739
|
+
}
|
|
1740
|
+
});
|
|
1741
|
+
|
|
1742
|
+
const nextRunKey = startRun(db, {
|
|
1743
|
+
taskKey: context.task.task_key,
|
|
1744
|
+
agentName: nextAgent,
|
|
1745
|
+
agentKind: 'official',
|
|
1746
|
+
sessionKey: context.sessionKey,
|
|
1747
|
+
source: 'live',
|
|
1748
|
+
parentRunKey: context.run.run_key,
|
|
1749
|
+
title: nextAgent,
|
|
1750
|
+
phase: 'live',
|
|
1751
|
+
message: truncateMessage(`Live handoff from ${agentName}`),
|
|
1752
|
+
payload: {
|
|
1753
|
+
handoff_from: agentName,
|
|
1754
|
+
reason
|
|
1755
|
+
}
|
|
1756
|
+
});
|
|
1757
|
+
|
|
1758
|
+
await clearAgentSession(runtimeDir, agentName);
|
|
1759
|
+
await writeAgentSession(runtimeDir, nextAgent, {
|
|
1760
|
+
runKey: nextRunKey,
|
|
1761
|
+
taskKey: context.task.task_key,
|
|
1762
|
+
sessionKey: context.sessionKey,
|
|
1763
|
+
startedAt: now,
|
|
1764
|
+
finished: false,
|
|
1765
|
+
source: 'live'
|
|
1766
|
+
});
|
|
1767
|
+
|
|
1768
|
+
const eventRecord = createLiveEventRecord(context, {
|
|
1769
|
+
ts: now,
|
|
1770
|
+
type: 'handoff',
|
|
1771
|
+
summary: handoffSummary,
|
|
1772
|
+
taskKey: context.task.task_key,
|
|
1773
|
+
status: 'completed',
|
|
1774
|
+
meta: {
|
|
1775
|
+
from: agentName,
|
|
1776
|
+
to: nextAgent,
|
|
1777
|
+
reason,
|
|
1778
|
+
previous_run_key: context.run.run_key,
|
|
1779
|
+
current_run_key: nextRunKey,
|
|
1780
|
+
micro_task_key: state.current_task || null
|
|
1781
|
+
}
|
|
1782
|
+
});
|
|
1783
|
+
await appendLiveEvent(runtimeDir, context.sessionKey, eventRecord);
|
|
1784
|
+
|
|
1785
|
+
const nextState = applyEventToState(state, eventRecord, {
|
|
1786
|
+
currentTask: null,
|
|
1787
|
+
activeAgent: nextAgent,
|
|
1788
|
+
currentRunKey: nextRunKey
|
|
1789
|
+
});
|
|
1790
|
+
if (currentTaskClosed) {
|
|
1791
|
+
nextState.stats.tasks_completed += 1;
|
|
1792
|
+
}
|
|
1793
|
+
await writeLiveState(runtimeDir, context.sessionKey, nextState);
|
|
1794
|
+
|
|
1795
|
+
if (!options.json) {
|
|
1796
|
+
logger.log(t('live.handoff_recorded', { from: agentName, to: nextAgent, session: context.sessionKey, dbPath }));
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1799
|
+
return {
|
|
1800
|
+
ok: true,
|
|
1801
|
+
targetDir,
|
|
1802
|
+
dbPath,
|
|
1803
|
+
agent: agentName,
|
|
1804
|
+
nextAgent,
|
|
1805
|
+
taskKey: context.task.task_key,
|
|
1806
|
+
previousRunKey: context.run.run_key,
|
|
1807
|
+
runKey: nextRunKey,
|
|
1808
|
+
sessionKey: context.sessionKey,
|
|
1809
|
+
open: true
|
|
1810
|
+
};
|
|
1811
|
+
} finally {
|
|
1812
|
+
db.close();
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
async function runLiveStatus({ args, options = {}, logger, t }) {
|
|
1817
|
+
const targetDir = resolveTargetDir(args);
|
|
1818
|
+
const watchSeconds = parseWatchSeconds(options.watch);
|
|
1819
|
+
|
|
1820
|
+
if (watchSeconds && options.json) {
|
|
1821
|
+
throw new Error(t('live.watch_json_conflict'));
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
if (!watchSeconds) {
|
|
1825
|
+
const snapshot = await getLiveStatusSnapshot(targetDir, t, options);
|
|
1826
|
+
if (!options.json) {
|
|
1827
|
+
if (options.format === 'compact') {
|
|
1828
|
+
printCompactStatus(snapshot, logger);
|
|
1829
|
+
} else if (options.format === 'tmux-bar') {
|
|
1830
|
+
printTmuxBar(snapshot, logger);
|
|
1831
|
+
} else {
|
|
1832
|
+
printLiveStatusSnapshot(snapshot, logger);
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
return snapshot;
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
let stopped = false;
|
|
1839
|
+
const onSignal = () => { stopped = true; };
|
|
1840
|
+
process.on('SIGINT', onSignal);
|
|
1841
|
+
process.on('SIGTERM', onSignal);
|
|
1842
|
+
|
|
1843
|
+
try {
|
|
1844
|
+
while (!stopped) {
|
|
1845
|
+
const snapshot = await getLiveStatusSnapshot(targetDir, t, options);
|
|
1846
|
+
if (process.stdout && process.stdout.isTTY) {
|
|
1847
|
+
process.stdout.write('\x1Bc');
|
|
1848
|
+
}
|
|
1849
|
+
if (options.format === 'compact') {
|
|
1850
|
+
printCompactStatus(snapshot, logger);
|
|
1851
|
+
} else if (options.format === 'tmux-bar') {
|
|
1852
|
+
printTmuxBar(snapshot, logger);
|
|
1853
|
+
} else {
|
|
1854
|
+
printLiveStatusSnapshot(snapshot, logger);
|
|
1855
|
+
}
|
|
1856
|
+
if (stopped) break;
|
|
1857
|
+
await sleep(Math.round(watchSeconds * 1000));
|
|
1858
|
+
}
|
|
1859
|
+
} finally {
|
|
1860
|
+
process.removeListener('SIGINT', onSignal);
|
|
1861
|
+
process.removeListener('SIGTERM', onSignal);
|
|
1862
|
+
}
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1865
|
+
async function runLiveClose({ args, options = {}, logger, t }) {
|
|
1866
|
+
const targetDir = resolveTargetDir(args);
|
|
1867
|
+
const requestedAgent = options.agent ? normalizeAgentHandle(options.agent) : null;
|
|
1868
|
+
const { db, dbPath, runtimeDir } = await withRuntimeDb(targetDir, t);
|
|
1869
|
+
|
|
1870
|
+
try {
|
|
1871
|
+
const context = await resolveLiveContext(targetDir, db, runtimeDir, {
|
|
1872
|
+
agentName: requestedAgent,
|
|
1873
|
+
limit: options.limit
|
|
1874
|
+
});
|
|
1875
|
+
|
|
1876
|
+
if (!context.run || context.run.source !== 'live' || !context.sessionKey || !context.task) {
|
|
1877
|
+
throw new Error(requestedAgent
|
|
1878
|
+
? t('live.no_session_for_agent', { agent: requestedAgent })
|
|
1879
|
+
: t('live.no_session_found'));
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1882
|
+
if (context.phase !== 'active') {
|
|
1883
|
+
throw new Error(t('live.session_already_closed', { session: context.sessionKey }));
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
const status = String(options.status || 'completed').trim().toLowerCase() === 'failed' ? 'failed' : 'completed';
|
|
1887
|
+
const now = new Date().toISOString();
|
|
1888
|
+
const summary = truncateMessage(options.summary || options.message || `Live session closed for ${context.agentName}`);
|
|
1889
|
+
const state = context.state || createLiveState(targetDir, context.run, context.task, {
|
|
1890
|
+
sessionKey: context.sessionKey,
|
|
1891
|
+
activeAgent: context.agentName,
|
|
1892
|
+
projectPath: targetDir
|
|
1893
|
+
});
|
|
1894
|
+
|
|
1895
|
+
let currentTaskClosed = false;
|
|
1896
|
+
if (state.current_task) {
|
|
1897
|
+
updateTask(db, {
|
|
1898
|
+
taskKey: state.current_task,
|
|
1899
|
+
status,
|
|
1900
|
+
goal: summary
|
|
1901
|
+
});
|
|
1902
|
+
currentTaskClosed = true;
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
updateRun(db, {
|
|
1906
|
+
runKey: context.run.run_key,
|
|
1907
|
+
status,
|
|
1908
|
+
summary,
|
|
1909
|
+
eventType: 'session_closed',
|
|
1910
|
+
message: summary,
|
|
1911
|
+
payload: {
|
|
1912
|
+
closed_by: 'live:close'
|
|
1913
|
+
}
|
|
1914
|
+
});
|
|
1915
|
+
|
|
1916
|
+
updateTask(db, {
|
|
1917
|
+
taskKey: context.task.task_key,
|
|
1918
|
+
status,
|
|
1919
|
+
goal: summary
|
|
1920
|
+
});
|
|
1921
|
+
|
|
1922
|
+
const eventRecord = createLiveEventRecord(context, {
|
|
1923
|
+
ts: now,
|
|
1924
|
+
type: 'session_closed',
|
|
1925
|
+
summary,
|
|
1926
|
+
taskKey: context.task.task_key,
|
|
1927
|
+
status
|
|
1928
|
+
});
|
|
1929
|
+
await appendLiveEvent(runtimeDir, context.sessionKey, eventRecord);
|
|
1930
|
+
|
|
1931
|
+
const nextState = applyEventToState(state, eventRecord, {
|
|
1932
|
+
currentTask: null,
|
|
1933
|
+
phase: 'closed',
|
|
1934
|
+
closedAt: now,
|
|
1935
|
+
activeAgent: context.agentName,
|
|
1936
|
+
currentRunKey: context.run.run_key
|
|
1937
|
+
});
|
|
1938
|
+
if (currentTaskClosed && status === 'completed') {
|
|
1939
|
+
nextState.stats.tasks_completed += 1;
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
const git = await collectGitSnapshot(targetDir);
|
|
1943
|
+
await writeLiveState(runtimeDir, context.sessionKey, nextState);
|
|
1944
|
+
const summaryPath = await writeLiveSummary(runtimeDir, context.sessionKey, renderLiveSummary({
|
|
1945
|
+
sessionKey: context.sessionKey,
|
|
1946
|
+
agent: context.agentName,
|
|
1947
|
+
tool: nextState.tool_session,
|
|
1948
|
+
status,
|
|
1949
|
+
startedAt: nextState.started_at,
|
|
1950
|
+
closedAt: now,
|
|
1951
|
+
summary,
|
|
1952
|
+
git,
|
|
1953
|
+
recentEvents: nextState.last_events
|
|
1954
|
+
}));
|
|
1955
|
+
|
|
1956
|
+
await clearAgentSession(runtimeDir, context.agentName);
|
|
1957
|
+
|
|
1958
|
+
if (!options.json) {
|
|
1959
|
+
logger.log(t('live.session_closed', { agent: context.agentName, session: context.sessionKey, dbPath }));
|
|
1960
|
+
}
|
|
1961
|
+
|
|
1962
|
+
// Ambient Intelligence: sugere evolução se há learnings acumulados
|
|
1963
|
+
if (!options.json && !options['no-health']) {
|
|
1964
|
+
try {
|
|
1965
|
+
const { getHealthDigest } = require('./health');
|
|
1966
|
+
const items = await getHealthDigest(targetDir);
|
|
1967
|
+
if (items && items.length > 0) {
|
|
1968
|
+
logger.log('');
|
|
1969
|
+
logger.log('AIOSON Health — itens após sessão:');
|
|
1970
|
+
for (const item of items) {
|
|
1971
|
+
logger.log(` ● ${item}`);
|
|
1972
|
+
}
|
|
1973
|
+
logger.log(' → aioson health . para detalhes e ações');
|
|
1974
|
+
logger.log('');
|
|
1975
|
+
}
|
|
1976
|
+
} catch { /* não bloqueia o close */ }
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1979
|
+
return {
|
|
1980
|
+
ok: true,
|
|
1981
|
+
targetDir,
|
|
1982
|
+
dbPath,
|
|
1983
|
+
agent: context.agentName,
|
|
1984
|
+
taskKey: context.task.task_key,
|
|
1985
|
+
runKey: context.run.run_key,
|
|
1986
|
+
sessionKey: context.sessionKey,
|
|
1987
|
+
status,
|
|
1988
|
+
closed: true,
|
|
1989
|
+
summaryPath,
|
|
1990
|
+
git
|
|
1991
|
+
};
|
|
1992
|
+
} finally {
|
|
1993
|
+
db.close();
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1997
|
+
async function runLiveList({ args, options = {}, logger, t }) {
|
|
1998
|
+
const targetDir = resolveTargetDir(args);
|
|
1999
|
+
const { dbPath } = resolveRuntimePaths(targetDir);
|
|
2000
|
+
|
|
2001
|
+
if (!(await runtimeStoreExists(targetDir))) {
|
|
2002
|
+
throw new Error(t('runtime.store_missing', { path: dbPath }));
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
const { db, runtimeDir } = await openRuntimeDb(targetDir, { mustExist: true });
|
|
2006
|
+
db.close();
|
|
2007
|
+
const states = await listLiveStates(runtimeDir);
|
|
2008
|
+
|
|
2009
|
+
if (!options.json) {
|
|
2010
|
+
if (states.length === 0) {
|
|
2011
|
+
logger.log(t('live.list_empty'));
|
|
2012
|
+
} else {
|
|
2013
|
+
logger.log(t('live.list_title', { count: states.length }));
|
|
2014
|
+
for (const state of states) {
|
|
2015
|
+
logger.log(t('live.list_line', {
|
|
2016
|
+
session: state.session_key || '-',
|
|
2017
|
+
agent: state.active_agent || '-',
|
|
2018
|
+
tool: state.tool_session || '-',
|
|
2019
|
+
phase: state.phase || '-',
|
|
2020
|
+
updatedAt: state.updated_at || state.started_at || '-'
|
|
2021
|
+
}));
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
return {
|
|
2027
|
+
ok: true,
|
|
2028
|
+
targetDir,
|
|
2029
|
+
dbPath,
|
|
2030
|
+
count: states.length,
|
|
2031
|
+
sessions: states.map((state) => ({
|
|
2032
|
+
sessionKey: state.session_key,
|
|
2033
|
+
agent: state.active_agent,
|
|
2034
|
+
tool: state.tool_session,
|
|
2035
|
+
phase: state.phase,
|
|
2036
|
+
title: state.title,
|
|
2037
|
+
startedAt: state.started_at,
|
|
2038
|
+
updatedAt: state.updated_at,
|
|
2039
|
+
closedAt: state.closed_at
|
|
2040
|
+
}))
|
|
2041
|
+
};
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
module.exports = {
|
|
2045
|
+
buildLaunchArgs,
|
|
2046
|
+
runLiveStart,
|
|
2047
|
+
runRuntimeEmit,
|
|
2048
|
+
runLiveHandoff,
|
|
2049
|
+
runLiveStatus,
|
|
2050
|
+
runLiveClose,
|
|
2051
|
+
runLiveList,
|
|
2052
|
+
// Exported so callers (including tests) can resolve the on-disk directory
|
|
2053
|
+
// for a given session key without re-implementing the sanitization rules.
|
|
2054
|
+
sessionKeyToDirName,
|
|
2055
|
+
resolveLivePaths
|
|
2056
|
+
};
|
|
2057
|
+
|
|
2058
|
+
// ── Context estimation helpers ──
|
|
2059
|
+
|
|
2060
|
+
const CONTEXT_FILES = [
|
|
2061
|
+
'.aioson/context/project.context.md',
|
|
2062
|
+
'.aioson/context/spec.md',
|
|
2063
|
+
'.aioson/context/features.md',
|
|
2064
|
+
'.aioson/context/context-pack.md',
|
|
2065
|
+
'.aioson/context/discovery.md',
|
|
2066
|
+
'.aioson/context/architecture.md',
|
|
2067
|
+
'.aioson/context/readiness.md',
|
|
2068
|
+
'.aioson/context/design-doc.md',
|
|
2069
|
+
'.aioson/context/skeleton-system.md'
|
|
2070
|
+
];
|
|
2071
|
+
|
|
2072
|
+
async function estimateContextSize(projectDir) {
|
|
2073
|
+
let totalBytes = 0;
|
|
2074
|
+
const foundFiles = [];
|
|
2075
|
+
|
|
2076
|
+
for (const rel of CONTEXT_FILES) {
|
|
2077
|
+
const filePath = path.join(projectDir, rel);
|
|
2078
|
+
try {
|
|
2079
|
+
const stat = await fs.stat(filePath);
|
|
2080
|
+
if (stat.isFile()) {
|
|
2081
|
+
totalBytes += stat.size;
|
|
2082
|
+
foundFiles.push(rel);
|
|
2083
|
+
}
|
|
2084
|
+
} catch {
|
|
2085
|
+
// ignore missing files
|
|
2086
|
+
}
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
// Heuristic: ~4 chars per token (english-ish text)
|
|
2090
|
+
const estimatedTokens = Math.round(totalBytes / 4);
|
|
2091
|
+
// Default window size assumption (200k for Sonnet-class)
|
|
2092
|
+
const windowSize = 200000;
|
|
2093
|
+
|
|
2094
|
+
return {
|
|
2095
|
+
totalBytes,
|
|
2096
|
+
estimatedTokens,
|
|
2097
|
+
windowSize,
|
|
2098
|
+
pct: Math.min(100, Math.round((estimatedTokens / windowSize) * 100)),
|
|
2099
|
+
files: foundFiles
|
|
2100
|
+
};
|
|
2101
|
+
}
|