monomind 1.10.0 → 1.10.2
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/.claude/commands/monomind/understand.md +111 -70
- package/.claude/settings.local.json +1 -2
- package/package.json +1 -1
- package/packages/@monomind/cli/bundled-graph/dist/src/analyze.d.ts +32 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/analyze.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/analyze.js +297 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/analyze.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/build.d.ts +8 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/build.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/build.js +73 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/build.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/cache.d.ts +12 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/cache.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/cache.js +43 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/cache.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/cluster.d.ts +5 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/cluster.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/cluster.js +120 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/cluster.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/detect.d.ts +21 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/detect.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/detect.js +195 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/detect.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/export.d.ts +21 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/export.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/export.js +68 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/export.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/index.d.ts +20 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/index.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/index.js +158 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/index.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/c.d.ts +3 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/c.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/c.js +88 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/c.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/cpp.d.ts +3 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/cpp.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/cpp.js +121 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/cpp.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/csharp.d.ts +3 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/csharp.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/csharp.js +121 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/csharp.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/go.d.ts +3 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/go.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/go.js +181 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/go.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/java.d.ts +3 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/java.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/java.js +117 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/java.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/kotlin.d.ts +3 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/kotlin.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/kotlin.js +112 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/kotlin.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/php.d.ts +3 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/php.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/php.js +130 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/php.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/python.d.ts +3 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/python.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/python.js +230 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/python.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/ruby.d.ts +3 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/ruby.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/ruby.js +120 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/ruby.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/rust.d.ts +3 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/rust.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/rust.js +195 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/rust.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/scala.d.ts +3 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/scala.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/scala.js +110 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/scala.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/swift.d.ts +3 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/swift.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/swift.js +122 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/swift.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/typescript.d.ts +3 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/typescript.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/typescript.js +295 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/languages/typescript.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/semantic.d.ts +38 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/semantic.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/semantic.js +242 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/semantic.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/tree-sitter-runner.d.ts +48 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/tree-sitter-runner.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/tree-sitter-runner.js +137 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/tree-sitter-runner.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/types.d.ts +7 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/types.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/types.js +2 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/extract/types.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/index.d.ts +28 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/index.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/index.js +26 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/index.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/pipeline.d.ts +27 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/pipeline.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/pipeline.js +269 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/pipeline.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/report.d.ts +26 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/report.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/report.js +214 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/report.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/types.d.ts +124 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/types.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/types.js +2 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/types.js.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/visualize.d.ts +4 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/visualize.d.ts.map +1 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/visualize.js +574 -0
- package/packages/@monomind/cli/bundled-graph/dist/src/visualize.js.map +1 -0
- package/packages/@monomind/cli/dist/src/agents/halt-signal.d.ts +25 -0
- package/packages/@monomind/cli/dist/src/agents/halt-signal.js +76 -0
- package/packages/@monomind/cli/dist/src/agents/index.d.ts +18 -0
- package/packages/@monomind/cli/dist/src/agents/index.js +13 -0
- package/packages/@monomind/cli/dist/src/agents/managed-agent.d.ts +41 -0
- package/packages/@monomind/cli/dist/src/agents/managed-agent.js +69 -0
- package/packages/@monomind/cli/dist/src/agents/prompt-experiment.d.ts +23 -0
- package/packages/@monomind/cli/dist/src/agents/prompt-experiment.js +49 -0
- package/packages/@monomind/cli/dist/src/agents/prompt-version-manager.d.ts +22 -0
- package/packages/@monomind/cli/dist/src/agents/prompt-version-manager.js +80 -0
- package/packages/@monomind/cli/dist/src/agents/registry-builder.d.ts +36 -0
- package/packages/@monomind/cli/dist/src/agents/registry-builder.js +200 -0
- package/packages/@monomind/cli/dist/src/agents/registry-query.d.ts +71 -0
- package/packages/@monomind/cli/dist/src/agents/registry-query.js +125 -0
- package/packages/@monomind/cli/dist/src/agents/score-decay.d.ts +19 -0
- package/packages/@monomind/cli/dist/src/agents/score-decay.js +22 -0
- package/packages/@monomind/cli/dist/src/agents/shared-instructions-loader.d.ts +13 -0
- package/packages/@monomind/cli/dist/src/agents/shared-instructions-loader.js +40 -0
- package/packages/@monomind/cli/dist/src/agents/specialization-scorer.d.ts +54 -0
- package/packages/@monomind/cli/dist/src/agents/specialization-scorer.js +212 -0
- package/packages/@monomind/cli/dist/src/agents/termination-watcher.d.ts +30 -0
- package/packages/@monomind/cli/dist/src/agents/termination-watcher.js +84 -0
- package/packages/@monomind/cli/dist/src/agents/trigger-index.d.ts +20 -0
- package/packages/@monomind/cli/dist/src/agents/trigger-index.js +38 -0
- package/packages/@monomind/cli/dist/src/agents/trigger-scanner.d.ts +64 -0
- package/packages/@monomind/cli/dist/src/agents/trigger-scanner.js +308 -0
- package/packages/@monomind/cli/dist/src/agents/version-diff.d.ts +18 -0
- package/packages/@monomind/cli/dist/src/agents/version-diff.js +64 -0
- package/packages/@monomind/cli/dist/src/agents/version-store.d.ts +60 -0
- package/packages/@monomind/cli/dist/src/agents/version-store.js +235 -0
- package/packages/@monomind/cli/dist/src/autopilot-state.d.ts +77 -0
- package/packages/@monomind/cli/dist/src/autopilot-state.js +330 -0
- package/packages/@monomind/cli/dist/src/benchmarks/benchmark-runner.d.ts +87 -0
- package/packages/@monomind/cli/dist/src/benchmarks/benchmark-runner.js +273 -0
- package/packages/@monomind/cli/dist/src/benchmarks/metric-evaluators.d.ts +36 -0
- package/packages/@monomind/cli/dist/src/benchmarks/metric-evaluators.js +114 -0
- package/packages/@monomind/cli/dist/src/benchmarks/pretrain/index.d.ts +58 -0
- package/packages/@monomind/cli/dist/src/benchmarks/pretrain/index.js +404 -0
- package/packages/@monomind/cli/dist/src/commands/agent-wasm.d.ts +14 -0
- package/packages/@monomind/cli/dist/src/commands/agent-wasm.js +333 -0
- package/packages/@monomind/cli/dist/src/commands/agent.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/agent.js +943 -0
- package/packages/@monomind/cli/dist/src/commands/analyze.d.ts +19 -0
- package/packages/@monomind/cli/dist/src/commands/analyze.js +2048 -0
- package/packages/@monomind/cli/dist/src/commands/appliance-advanced.d.ts +9 -0
- package/packages/@monomind/cli/dist/src/commands/appliance-advanced.js +238 -0
- package/packages/@monomind/cli/dist/src/commands/appliance.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/appliance.js +406 -0
- package/packages/@monomind/cli/dist/src/commands/autopilot.d.ts +15 -0
- package/packages/@monomind/cli/dist/src/commands/autopilot.js +362 -0
- package/packages/@monomind/cli/dist/src/commands/benchmark.d.ts +10 -0
- package/packages/@monomind/cli/dist/src/commands/benchmark.js +571 -0
- package/packages/@monomind/cli/dist/src/commands/claims.d.ts +10 -0
- package/packages/@monomind/cli/dist/src/commands/claims.js +632 -0
- package/packages/@monomind/cli/dist/src/commands/cleanup.d.ts +13 -0
- package/packages/@monomind/cli/dist/src/commands/cleanup.js +218 -0
- package/packages/@monomind/cli/dist/src/commands/completions.d.ts +10 -0
- package/packages/@monomind/cli/dist/src/commands/completions.js +539 -0
- package/packages/@monomind/cli/dist/src/commands/config.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/config.js +460 -0
- package/packages/@monomind/cli/dist/src/commands/daemon.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/daemon.js +671 -0
- package/packages/@monomind/cli/dist/src/commands/deployment.d.ts +10 -0
- package/packages/@monomind/cli/dist/src/commands/deployment.js +691 -0
- package/packages/@monomind/cli/dist/src/commands/doctor.d.ts +10 -0
- package/packages/@monomind/cli/dist/src/commands/doctor.js +647 -0
- package/packages/@monomind/cli/dist/src/commands/embeddings.d.ts +18 -0
- package/packages/@monomind/cli/dist/src/commands/embeddings.js +1652 -0
- package/packages/@monomind/cli/dist/src/commands/guidance.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/guidance.js +560 -0
- package/packages/@monomind/cli/dist/src/commands/hive-mind.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/hive-mind.js +1238 -0
- package/packages/@monomind/cli/dist/src/commands/hooks.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/hooks.js +4446 -0
- package/packages/@monomind/cli/dist/src/commands/index.d.ts +119 -0
- package/packages/@monomind/cli/dist/src/commands/index.js +404 -0
- package/packages/@monomind/cli/dist/src/commands/init.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/init.js +853 -0
- package/packages/@monomind/cli/dist/src/commands/issues.d.ts +21 -0
- package/packages/@monomind/cli/dist/src/commands/issues.js +567 -0
- package/packages/@monomind/cli/dist/src/commands/mcp.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/mcp.js +705 -0
- package/packages/@monomind/cli/dist/src/commands/memory.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/memory.js +1596 -0
- package/packages/@monomind/cli/dist/src/commands/migrate.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/migrate.js +790 -0
- package/packages/@monomind/cli/dist/src/commands/monograph.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/monograph.js +526 -0
- package/packages/@monomind/cli/dist/src/commands/neural.d.ts +10 -0
- package/packages/@monomind/cli/dist/src/commands/neural.js +1494 -0
- package/packages/@monomind/cli/dist/src/commands/performance.d.ts +10 -0
- package/packages/@monomind/cli/dist/src/commands/performance.js +601 -0
- package/packages/@monomind/cli/dist/src/commands/plugins.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/plugins.js +796 -0
- package/packages/@monomind/cli/dist/src/commands/process.d.ts +10 -0
- package/packages/@monomind/cli/dist/src/commands/process.js +718 -0
- package/packages/@monomind/cli/dist/src/commands/progress.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/progress.js +259 -0
- package/packages/@monomind/cli/dist/src/commands/providers.d.ts +10 -0
- package/packages/@monomind/cli/dist/src/commands/providers.js +391 -0
- package/packages/@monomind/cli/dist/src/commands/replay.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/replay.js +60 -0
- package/packages/@monomind/cli/dist/src/commands/route.d.ts +16 -0
- package/packages/@monomind/cli/dist/src/commands/route.js +939 -0
- package/packages/@monomind/cli/dist/src/commands/ruvector/backup.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/ruvector/backup.js +746 -0
- package/packages/@monomind/cli/dist/src/commands/ruvector/benchmark.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/ruvector/benchmark.js +489 -0
- package/packages/@monomind/cli/dist/src/commands/ruvector/import.d.ts +18 -0
- package/packages/@monomind/cli/dist/src/commands/ruvector/import.js +359 -0
- package/packages/@monomind/cli/dist/src/commands/ruvector/index.d.ts +29 -0
- package/packages/@monomind/cli/dist/src/commands/ruvector/index.js +129 -0
- package/packages/@monomind/cli/dist/src/commands/ruvector/init.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/ruvector/init.js +481 -0
- package/packages/@monomind/cli/dist/src/commands/ruvector/migrate.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/ruvector/migrate.js +497 -0
- package/packages/@monomind/cli/dist/src/commands/ruvector/optimize.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/ruvector/optimize.js +504 -0
- package/packages/@monomind/cli/dist/src/commands/ruvector/setup.d.ts +18 -0
- package/packages/@monomind/cli/dist/src/commands/ruvector/setup.js +765 -0
- package/packages/@monomind/cli/dist/src/commands/ruvector/status.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/commands/ruvector/status.js +491 -0
- package/packages/@monomind/cli/dist/src/commands/security.d.ts +10 -0
- package/packages/@monomind/cli/dist/src/commands/security.js +943 -0
- package/packages/@monomind/cli/dist/src/commands/session.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/session.js +793 -0
- package/packages/@monomind/cli/dist/src/commands/start.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/start.js +432 -0
- package/packages/@monomind/cli/dist/src/commands/status.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/status.js +591 -0
- package/packages/@monomind/cli/dist/src/commands/swarm.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/swarm.js +812 -0
- package/packages/@monomind/cli/dist/src/commands/task.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/task.js +671 -0
- package/packages/@monomind/cli/dist/src/commands/tokens.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/tokens.js +107 -0
- package/packages/@monomind/cli/dist/src/commands/transfer-store.d.ts +13 -0
- package/packages/@monomind/cli/dist/src/commands/transfer-store.js +428 -0
- package/packages/@monomind/cli/dist/src/commands/ui.js +68 -0
- package/packages/@monomind/cli/dist/src/commands/update.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/update.js +276 -0
- package/packages/@monomind/cli/dist/src/commands/workflow.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/commands/workflow.js +644 -0
- package/packages/@monomind/cli/dist/src/config-adapter.d.ts +16 -0
- package/packages/@monomind/cli/dist/src/config-adapter.js +186 -0
- package/packages/@monomind/cli/dist/src/consensus/audit-writer.d.ts +50 -0
- package/packages/@monomind/cli/dist/src/consensus/audit-writer.js +142 -0
- package/packages/@monomind/cli/dist/src/consensus/index.d.ts +7 -0
- package/packages/@monomind/cli/dist/src/consensus/index.js +6 -0
- package/packages/@monomind/cli/dist/src/consensus/vote-signer.d.ts +36 -0
- package/packages/@monomind/cli/dist/src/consensus/vote-signer.js +71 -0
- package/packages/@monomind/cli/dist/src/context/context-provider.d.ts +44 -0
- package/packages/@monomind/cli/dist/src/context/context-provider.js +25 -0
- package/packages/@monomind/cli/dist/src/context/git-state-provider.d.ts +12 -0
- package/packages/@monomind/cli/dist/src/context/git-state-provider.js +34 -0
- package/packages/@monomind/cli/dist/src/context/index.d.ts +12 -0
- package/packages/@monomind/cli/dist/src/context/index.js +12 -0
- package/packages/@monomind/cli/dist/src/context/project-conventions-provider.d.ts +15 -0
- package/packages/@monomind/cli/dist/src/context/project-conventions-provider.js +19 -0
- package/packages/@monomind/cli/dist/src/context/prompt-assembler.d.ts +26 -0
- package/packages/@monomind/cli/dist/src/context/prompt-assembler.js +93 -0
- package/packages/@monomind/cli/dist/src/context/task-history-provider.d.ts +24 -0
- package/packages/@monomind/cli/dist/src/context/task-history-provider.js +32 -0
- package/packages/@monomind/cli/dist/src/context/user-preferences-provider.d.ts +14 -0
- package/packages/@monomind/cli/dist/src/context/user-preferences-provider.js +27 -0
- package/packages/@monomind/cli/dist/src/dlq/dlq-reader.d.ts +31 -0
- package/packages/@monomind/cli/dist/src/dlq/dlq-reader.js +81 -0
- package/packages/@monomind/cli/dist/src/dlq/dlq-replayer.d.ts +27 -0
- package/packages/@monomind/cli/dist/src/dlq/dlq-replayer.js +90 -0
- package/packages/@monomind/cli/dist/src/dlq/dlq-writer.d.ts +24 -0
- package/packages/@monomind/cli/dist/src/dlq/dlq-writer.js +65 -0
- package/packages/@monomind/cli/dist/src/dlq/index.d.ts +10 -0
- package/packages/@monomind/cli/dist/src/dlq/index.js +7 -0
- package/packages/@monomind/cli/dist/src/eval/dataset-manager.d.ts +33 -0
- package/packages/@monomind/cli/dist/src/eval/dataset-manager.js +107 -0
- package/packages/@monomind/cli/dist/src/eval/dataset-runner.d.ts +23 -0
- package/packages/@monomind/cli/dist/src/eval/dataset-runner.js +59 -0
- package/packages/@monomind/cli/dist/src/eval/index.d.ts +10 -0
- package/packages/@monomind/cli/dist/src/eval/index.js +7 -0
- package/packages/@monomind/cli/dist/src/eval/trace-collector.d.ts +40 -0
- package/packages/@monomind/cli/dist/src/eval/trace-collector.js +102 -0
- package/packages/@monomind/cli/dist/src/index.d.ts +82 -0
- package/packages/@monomind/cli/dist/src/index.js +580 -0
- package/packages/@monomind/cli/dist/src/infrastructure/in-memory-repositories.d.ts +68 -0
- package/packages/@monomind/cli/dist/src/infrastructure/in-memory-repositories.js +264 -0
- package/packages/@monomind/cli/dist/src/init/claudemd-generator.d.ts +25 -0
- package/packages/@monomind/cli/dist/src/init/claudemd-generator.js +558 -0
- package/packages/@monomind/cli/dist/src/init/executor.d.ts +38 -0
- package/packages/@monomind/cli/dist/src/init/executor.js +2172 -0
- package/packages/@monomind/cli/dist/src/init/helpers-generator.d.ts +60 -0
- package/packages/@monomind/cli/dist/src/init/helpers-generator.js +1235 -0
- package/packages/@monomind/cli/dist/src/init/index.d.ts +13 -0
- package/packages/@monomind/cli/dist/src/init/index.js +15 -0
- package/packages/@monomind/cli/dist/src/init/mcp-generator.d.ts +26 -0
- package/packages/@monomind/cli/dist/src/init/mcp-generator.js +99 -0
- package/packages/@monomind/cli/dist/src/init/settings-generator.d.ts +14 -0
- package/packages/@monomind/cli/dist/src/init/settings-generator.js +417 -0
- package/packages/@monomind/cli/dist/src/init/shared-instructions-generator.d.ts +38 -0
- package/packages/@monomind/cli/dist/src/init/shared-instructions-generator.js +586 -0
- package/packages/@monomind/cli/dist/src/init/statusline-generator.d.ts +25 -0
- package/packages/@monomind/cli/dist/src/init/statusline-generator.js +1171 -0
- package/packages/@monomind/cli/dist/src/init/types.d.ts +315 -0
- package/packages/@monomind/cli/dist/src/init/types.js +254 -0
- package/packages/@monomind/cli/dist/src/interactive/interrupt.d.ts +22 -0
- package/packages/@monomind/cli/dist/src/interactive/interrupt.js +71 -0
- package/packages/@monomind/cli/dist/src/mcp/deprecation-injector.d.ts +25 -0
- package/packages/@monomind/cli/dist/src/mcp/deprecation-injector.js +48 -0
- package/packages/@monomind/cli/dist/src/mcp/tool-registry.d.ts +61 -0
- package/packages/@monomind/cli/dist/src/mcp/tool-registry.js +246 -0
- package/packages/@monomind/cli/dist/src/mcp-client.d.ts +92 -0
- package/packages/@monomind/cli/dist/src/mcp-client.js +270 -0
- package/packages/@monomind/cli/dist/src/mcp-server.d.ts +170 -0
- package/packages/@monomind/cli/dist/src/mcp-server.js +829 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/a2a-tools.d.ts +14 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/a2a-tools.js +244 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/agent-tools.d.ts +9 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/agent-tools.js +607 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/agentdb-tools.d.ts +30 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/agentdb-tools.js +596 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/analyze-tools.d.ts +38 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/analyze-tools.js +326 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/auto-install.d.ts +83 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/auto-install.js +129 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/autopilot-tools.d.ts +12 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/autopilot-tools.js +237 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/browser-tools.d.ts +13 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/browser-tools.js +729 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/claims-tools.d.ts +12 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/claims-tools.js +797 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/config-tools.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/config-tools.js +381 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/coordination-tools.d.ts +13 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/coordination-tools.js +728 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/daa-tools.d.ts +13 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/daa-tools.js +509 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/embeddings-tools.d.ts +9 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/embeddings-tools.js +823 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/github-tools.d.ts +9 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/github-tools.js +485 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/graphify-tools.d.ts +10 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/graphify-tools.js +49 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/guidance-tools.d.ts +15 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/guidance-tools.js +646 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/hive-mind-tools.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/hive-mind-tools.js +957 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/hooks-tools.d.ts +44 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/hooks-tools.js +3440 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/index.d.ts +39 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/index.js +41 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/memory-tools.d.ts +14 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/memory-tools.js +530 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/monograph-tools.d.ts +9 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/monograph-tools.js +6306 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/neural-tools.d.ts +16 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/neural-tools.js +718 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/performance-tools.d.ts +16 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/performance-tools.js +656 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/progress-tools.d.ts +14 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/progress-tools.js +350 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/request-tracker.d.ts +17 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/request-tracker.js +30 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/ruvllm-tools.d.ts +9 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/ruvllm-tools.js +295 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/security-tools.d.ts +18 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/security-tools.js +434 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/session-tools.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/session-tools.js +378 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/swarm-tools.d.ts +9 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/swarm-tools.js +317 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/system-tools.d.ts +13 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/system-tools.js +552 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/task-tools.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/task-tools.js +446 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/terminal-tools.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/terminal-tools.js +309 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/transfer-tools.d.ts +14 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/transfer-tools.js +401 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/types.d.ts +37 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/types.js +14 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/wasm-agent-tools.d.ts +9 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/wasm-agent-tools.js +230 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/workflow-tools.d.ts +8 -0
- package/packages/@monomind/cli/dist/src/mcp-tools/workflow-tools.js +631 -0
- package/packages/@monomind/cli/dist/src/memory/ewc-consolidation.d.ts +295 -0
- package/packages/@monomind/cli/dist/src/memory/ewc-consolidation.js +632 -0
- package/packages/@monomind/cli/dist/src/memory/intelligence.d.ts +338 -0
- package/packages/@monomind/cli/dist/src/memory/intelligence.js +1049 -0
- package/packages/@monomind/cli/dist/src/memory/memory-bridge.d.ts +410 -0
- package/packages/@monomind/cli/dist/src/memory/memory-bridge.js +1654 -0
- package/packages/@monomind/cli/dist/src/memory/memory-initializer.d.ts +414 -0
- package/packages/@monomind/cli/dist/src/memory/memory-initializer.js +2284 -0
- package/packages/@monomind/cli/dist/src/memory/sona-optimizer.d.ts +234 -0
- package/packages/@monomind/cli/dist/src/memory/sona-optimizer.js +650 -0
- package/packages/@monomind/cli/dist/src/model/complexity-scorer.d.ts +21 -0
- package/packages/@monomind/cli/dist/src/model/complexity-scorer.js +106 -0
- package/packages/@monomind/cli/dist/src/model/index.d.ts +4 -0
- package/packages/@monomind/cli/dist/src/model/index.js +4 -0
- package/packages/@monomind/cli/dist/src/model/model-settings.d.ts +22 -0
- package/packages/@monomind/cli/dist/src/model/model-settings.js +33 -0
- package/packages/@monomind/cli/dist/src/model/model-tier-resolver.d.ts +24 -0
- package/packages/@monomind/cli/dist/src/model/model-tier-resolver.js +65 -0
- package/packages/@monomind/cli/dist/src/observability/replay-reader.d.ts +40 -0
- package/packages/@monomind/cli/dist/src/observability/replay-reader.js +138 -0
- package/packages/@monomind/cli/dist/src/orchestration/index.d.ts +7 -0
- package/packages/@monomind/cli/dist/src/orchestration/index.js +6 -0
- package/packages/@monomind/cli/dist/src/orchestration/mode-dispatcher.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/orchestration/mode-dispatcher.js +31 -0
- package/packages/@monomind/cli/dist/src/orchestration/routing-modes.d.ts +68 -0
- package/packages/@monomind/cli/dist/src/orchestration/routing-modes.js +180 -0
- package/packages/@monomind/cli/dist/src/output.d.ts +133 -0
- package/packages/@monomind/cli/dist/src/output.js +514 -0
- package/packages/@monomind/cli/dist/src/parser.d.ts +59 -0
- package/packages/@monomind/cli/dist/src/parser.js +459 -0
- package/packages/@monomind/cli/dist/src/plugins/manager.d.ts +133 -0
- package/packages/@monomind/cli/dist/src/plugins/manager.js +493 -0
- package/packages/@monomind/cli/dist/src/plugins/store/discovery.d.ts +88 -0
- package/packages/@monomind/cli/dist/src/plugins/store/discovery.js +859 -0
- package/packages/@monomind/cli/dist/src/plugins/store/index.d.ts +76 -0
- package/packages/@monomind/cli/dist/src/plugins/store/index.js +141 -0
- package/packages/@monomind/cli/dist/src/plugins/store/search.d.ts +46 -0
- package/packages/@monomind/cli/dist/src/plugins/store/search.js +230 -0
- package/packages/@monomind/cli/dist/src/plugins/store/types.d.ts +274 -0
- package/packages/@monomind/cli/dist/src/plugins/store/types.js +7 -0
- package/packages/@monomind/cli/dist/src/plugins/tests/demo-plugin-store.d.ts +7 -0
- package/packages/@monomind/cli/dist/src/plugins/tests/demo-plugin-store.js +126 -0
- package/packages/@monomind/cli/dist/src/plugins/tests/standalone-test.d.ts +12 -0
- package/packages/@monomind/cli/dist/src/plugins/tests/standalone-test.js +188 -0
- package/packages/@monomind/cli/dist/src/plugins/tests/test-plugin-store.d.ts +7 -0
- package/packages/@monomind/cli/dist/src/plugins/tests/test-plugin-store.js +206 -0
- package/packages/@monomind/cli/dist/src/production/circuit-breaker.d.ts +101 -0
- package/packages/@monomind/cli/dist/src/production/circuit-breaker.js +248 -0
- package/packages/@monomind/cli/dist/src/production/error-handler.d.ts +94 -0
- package/packages/@monomind/cli/dist/src/production/error-handler.js +321 -0
- package/packages/@monomind/cli/dist/src/production/index.d.ts +23 -0
- package/packages/@monomind/cli/dist/src/production/index.js +18 -0
- package/packages/@monomind/cli/dist/src/production/monitoring.d.ts +161 -0
- package/packages/@monomind/cli/dist/src/production/monitoring.js +360 -0
- package/packages/@monomind/cli/dist/src/production/rate-limiter.d.ts +80 -0
- package/packages/@monomind/cli/dist/src/production/rate-limiter.js +209 -0
- package/packages/@monomind/cli/dist/src/production/retry.d.ts +48 -0
- package/packages/@monomind/cli/dist/src/production/retry.js +179 -0
- package/packages/@monomind/cli/dist/src/prompt.d.ts +44 -0
- package/packages/@monomind/cli/dist/src/prompt.js +501 -0
- package/packages/@monomind/cli/dist/src/runtime/headless.d.ts +60 -0
- package/packages/@monomind/cli/dist/src/runtime/headless.js +284 -0
- package/packages/@monomind/cli/dist/src/ruvector/agent-wasm.d.ts +182 -0
- package/packages/@monomind/cli/dist/src/ruvector/agent-wasm.js +316 -0
- package/packages/@monomind/cli/dist/src/ruvector/ast-analyzer.d.ts +67 -0
- package/packages/@monomind/cli/dist/src/ruvector/ast-analyzer.js +277 -0
- package/packages/@monomind/cli/dist/src/ruvector/coverage-router.d.ts +160 -0
- package/packages/@monomind/cli/dist/src/ruvector/coverage-router.js +539 -0
- package/packages/@monomind/cli/dist/src/ruvector/coverage-tools.d.ts +33 -0
- package/packages/@monomind/cli/dist/src/ruvector/coverage-tools.js +157 -0
- package/packages/@monomind/cli/dist/src/ruvector/diff-classifier.d.ts +176 -0
- package/packages/@monomind/cli/dist/src/ruvector/diff-classifier.js +718 -0
- package/packages/@monomind/cli/dist/src/ruvector/enhanced-model-router.d.ts +146 -0
- package/packages/@monomind/cli/dist/src/ruvector/enhanced-model-router.js +551 -0
- package/packages/@monomind/cli/dist/src/ruvector/flash-attention.d.ts +195 -0
- package/packages/@monomind/cli/dist/src/ruvector/flash-attention.js +643 -0
- package/packages/@monomind/cli/dist/src/ruvector/graph-analyzer.d.ts +187 -0
- package/packages/@monomind/cli/dist/src/ruvector/graph-analyzer.js +929 -0
- package/packages/@monomind/cli/dist/src/ruvector/index.d.ts +39 -0
- package/packages/@monomind/cli/dist/src/ruvector/index.js +76 -0
- package/packages/@monomind/cli/dist/src/ruvector/lora-adapter.d.ts +218 -0
- package/packages/@monomind/cli/dist/src/ruvector/lora-adapter.js +455 -0
- package/packages/@monomind/cli/dist/src/ruvector/model-router.d.ts +222 -0
- package/packages/@monomind/cli/dist/src/ruvector/model-router.js +512 -0
- package/packages/@monomind/cli/dist/src/ruvector/moe-router.d.ts +213 -0
- package/packages/@monomind/cli/dist/src/ruvector/moe-router.js +649 -0
- package/packages/@monomind/cli/dist/src/ruvector/q-learning-router.d.ts +217 -0
- package/packages/@monomind/cli/dist/src/ruvector/q-learning-router.js +712 -0
- package/packages/@monomind/cli/dist/src/ruvector/ruvllm-wasm.d.ts +179 -0
- package/packages/@monomind/cli/dist/src/ruvector/ruvllm-wasm.js +363 -0
- package/packages/@monomind/cli/dist/src/ruvector/semantic-router.d.ts +77 -0
- package/packages/@monomind/cli/dist/src/ruvector/semantic-router.js +178 -0
- package/packages/@monomind/cli/dist/src/ruvector/vector-db.d.ts +69 -0
- package/packages/@monomind/cli/dist/src/ruvector/vector-db.js +243 -0
- package/packages/@monomind/cli/dist/src/services/agentic-flow-bridge.d.ts +50 -0
- package/packages/@monomind/cli/dist/src/services/agentic-flow-bridge.js +95 -0
- package/packages/@monomind/cli/dist/src/services/claim-service.d.ts +206 -0
- package/packages/@monomind/cli/dist/src/services/claim-service.js +849 -0
- package/packages/@monomind/cli/dist/src/services/config-file-manager.d.ts +51 -0
- package/packages/@monomind/cli/dist/src/services/config-file-manager.js +312 -0
- package/packages/@monomind/cli/dist/src/services/container-worker-pool.d.ts +197 -0
- package/packages/@monomind/cli/dist/src/services/container-worker-pool.js +623 -0
- package/packages/@monomind/cli/dist/src/services/headless-worker-executor.d.ts +311 -0
- package/packages/@monomind/cli/dist/src/services/headless-worker-executor.js +1167 -0
- package/packages/@monomind/cli/dist/src/services/index.d.ts +13 -0
- package/packages/@monomind/cli/dist/src/services/index.js +11 -0
- package/packages/@monomind/cli/dist/src/services/registry-api.d.ts +58 -0
- package/packages/@monomind/cli/dist/src/services/registry-api.js +199 -0
- package/packages/@monomind/cli/dist/src/services/ruvector-training.d.ts +222 -0
- package/packages/@monomind/cli/dist/src/services/ruvector-training.js +696 -0
- package/packages/@monomind/cli/dist/src/services/worker-daemon.d.ts +248 -0
- package/packages/@monomind/cli/dist/src/services/worker-daemon.js +1083 -0
- package/packages/@monomind/cli/dist/src/services/worker-queue.d.ts +201 -0
- package/packages/@monomind/cli/dist/src/services/worker-queue.js +594 -0
- package/packages/@monomind/cli/dist/src/suggest.d.ts +53 -0
- package/packages/@monomind/cli/dist/src/suggest.js +209 -0
- package/packages/@monomind/cli/dist/src/swarm/communication-graph.d.ts +25 -0
- package/packages/@monomind/cli/dist/src/swarm/communication-graph.js +77 -0
- package/packages/@monomind/cli/dist/src/swarm/flow-enforcer.d.ts +31 -0
- package/packages/@monomind/cli/dist/src/swarm/flow-enforcer.js +61 -0
- package/packages/@monomind/cli/dist/src/swarm/flow-visualizer.d.ts +19 -0
- package/packages/@monomind/cli/dist/src/swarm/flow-visualizer.js +68 -0
- package/packages/@monomind/cli/dist/src/transfer/anonymization/index.d.ts +25 -0
- package/packages/@monomind/cli/dist/src/transfer/anonymization/index.js +177 -0
- package/packages/@monomind/cli/dist/src/transfer/deploy-seraphine.d.ts +13 -0
- package/packages/@monomind/cli/dist/src/transfer/deploy-seraphine.js +205 -0
- package/packages/@monomind/cli/dist/src/transfer/export.d.ts +25 -0
- package/packages/@monomind/cli/dist/src/transfer/export.js +115 -0
- package/packages/@monomind/cli/dist/src/transfer/index.d.ts +12 -0
- package/packages/@monomind/cli/dist/src/transfer/index.js +31 -0
- package/packages/@monomind/cli/dist/src/transfer/ipfs/client.d.ts +109 -0
- package/packages/@monomind/cli/dist/src/transfer/ipfs/client.js +384 -0
- package/packages/@monomind/cli/dist/src/transfer/ipfs/upload.d.ts +95 -0
- package/packages/@monomind/cli/dist/src/transfer/ipfs/upload.js +420 -0
- package/packages/@monomind/cli/dist/src/transfer/models/seraphine.d.ts +72 -0
- package/packages/@monomind/cli/dist/src/transfer/models/seraphine.js +373 -0
- package/packages/@monomind/cli/dist/src/transfer/serialization/cfp.d.ts +49 -0
- package/packages/@monomind/cli/dist/src/transfer/serialization/cfp.js +183 -0
- package/packages/@monomind/cli/dist/src/transfer/storage/gcs.d.ts +82 -0
- package/packages/@monomind/cli/dist/src/transfer/storage/gcs.js +281 -0
- package/packages/@monomind/cli/dist/src/transfer/storage/index.d.ts +6 -0
- package/packages/@monomind/cli/dist/src/transfer/storage/index.js +6 -0
- package/packages/@monomind/cli/dist/src/transfer/store/discovery.d.ts +91 -0
- package/packages/@monomind/cli/dist/src/transfer/store/discovery.js +437 -0
- package/packages/@monomind/cli/dist/src/transfer/store/download.d.ts +79 -0
- package/packages/@monomind/cli/dist/src/transfer/store/download.js +423 -0
- package/packages/@monomind/cli/dist/src/transfer/store/index.d.ts +84 -0
- package/packages/@monomind/cli/dist/src/transfer/store/index.js +153 -0
- package/packages/@monomind/cli/dist/src/transfer/store/publish.d.ts +76 -0
- package/packages/@monomind/cli/dist/src/transfer/store/publish.js +293 -0
- package/packages/@monomind/cli/dist/src/transfer/store/registry.d.ts +58 -0
- package/packages/@monomind/cli/dist/src/transfer/store/registry.js +301 -0
- package/packages/@monomind/cli/dist/src/transfer/store/search.d.ts +54 -0
- package/packages/@monomind/cli/dist/src/transfer/store/search.js +232 -0
- package/packages/@monomind/cli/dist/src/transfer/store/tests/standalone-test.d.ts +12 -0
- package/packages/@monomind/cli/dist/src/transfer/store/tests/standalone-test.js +190 -0
- package/packages/@monomind/cli/dist/src/transfer/store/types.d.ts +193 -0
- package/packages/@monomind/cli/dist/src/transfer/store/types.js +6 -0
- package/packages/@monomind/cli/dist/src/transfer/test-seraphine.d.ts +6 -0
- package/packages/@monomind/cli/dist/src/transfer/test-seraphine.js +105 -0
- package/packages/@monomind/cli/dist/src/transfer/tests/test-store.d.ts +7 -0
- package/packages/@monomind/cli/dist/src/transfer/tests/test-store.js +214 -0
- package/packages/@monomind/cli/dist/src/transfer/types.d.ts +245 -0
- package/packages/@monomind/cli/dist/src/transfer/types.js +6 -0
- package/packages/@monomind/cli/dist/src/types.d.ts +198 -0
- package/packages/@monomind/cli/dist/src/types.js +38 -0
- package/packages/@monomind/cli/dist/src/update/checker.d.ts +34 -0
- package/packages/@monomind/cli/dist/src/update/checker.js +198 -0
- package/packages/@monomind/cli/dist/src/update/executor.d.ts +32 -0
- package/packages/@monomind/cli/dist/src/update/executor.js +186 -0
- package/packages/@monomind/cli/dist/src/update/index.d.ts +33 -0
- package/packages/@monomind/cli/dist/src/update/index.js +64 -0
- package/packages/@monomind/cli/dist/src/update/rate-limiter.d.ts +31 -0
- package/packages/@monomind/cli/dist/src/update/rate-limiter.js +116 -0
- package/packages/@monomind/cli/dist/src/update/validator.d.ts +17 -0
- package/packages/@monomind/cli/dist/src/update/validator.js +118 -0
- package/packages/@monomind/cli/dist/src/utils/parse-jsonl.d.ts +6 -0
- package/packages/@monomind/cli/dist/src/utils/parse-jsonl.js +22 -0
- package/packages/@monomind/cli/dist/src/workflow/condition-evaluator.d.ts +10 -0
- package/packages/@monomind/cli/dist/src/workflow/condition-evaluator.js +82 -0
- package/packages/@monomind/cli/dist/src/workflow/context-resolver.d.ts +12 -0
- package/packages/@monomind/cli/dist/src/workflow/context-resolver.js +23 -0
- package/packages/@monomind/cli/dist/src/workflow/dag-builder.d.ts +17 -0
- package/packages/@monomind/cli/dist/src/workflow/dag-builder.js +129 -0
- package/packages/@monomind/cli/dist/src/workflow/dag-executor.d.ts +9 -0
- package/packages/@monomind/cli/dist/src/workflow/dag-executor.js +116 -0
- package/packages/@monomind/cli/dist/src/workflow/dag-types.d.ts +41 -0
- package/packages/@monomind/cli/dist/src/workflow/dag-types.js +8 -0
- package/packages/@monomind/cli/dist/src/workflow/dsl-parser.d.ts +12 -0
- package/packages/@monomind/cli/dist/src/workflow/dsl-parser.js +20 -0
- package/packages/@monomind/cli/dist/src/workflow/dsl-schema.d.ts +165 -0
- package/packages/@monomind/cli/dist/src/workflow/dsl-schema.js +82 -0
- package/packages/@monomind/cli/dist/src/workflow/index.d.ts +13 -0
- package/packages/@monomind/cli/dist/src/workflow/index.js +11 -0
- package/packages/@monomind/cli/dist/src/workflow/template-engine.d.ts +11 -0
- package/packages/@monomind/cli/dist/src/workflow/template-engine.js +40 -0
- package/packages/@monomind/cli/dist/src/workflow/workflow-executor.d.ts +29 -0
- package/packages/@monomind/cli/dist/src/workflow/workflow-executor.js +227 -0
- package/packages/@monomind/cli/package.json +2 -1
|
@@ -0,0 +1,1167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless Worker Executor
|
|
3
|
+
* Enables workers to invoke Claude Code in headless mode with configurable sandbox profiles.
|
|
4
|
+
*
|
|
5
|
+
* ADR-020: Headless Worker Integration Architecture
|
|
6
|
+
* - Integrates with CLAUDE_CODE_HEADLESS and CLAUDE_CODE_SANDBOX_MODE environment variables
|
|
7
|
+
* - Provides process pool for concurrent execution
|
|
8
|
+
* - Builds context from file glob patterns
|
|
9
|
+
* - Supports prompt templates and output parsing
|
|
10
|
+
* - Implements timeout and graceful error handling
|
|
11
|
+
*
|
|
12
|
+
* Key Features:
|
|
13
|
+
* - Process pool with configurable maxConcurrent
|
|
14
|
+
* - Context building from file glob patterns with caching
|
|
15
|
+
* - Prompt template system with context injection
|
|
16
|
+
* - Output parsing (text, json, markdown)
|
|
17
|
+
* - Timeout handling with graceful termination
|
|
18
|
+
* - Execution logging for debugging
|
|
19
|
+
* - Event emission for monitoring
|
|
20
|
+
*/
|
|
21
|
+
import { spawn, execSync } from 'child_process';
|
|
22
|
+
import { EventEmitter } from 'events';
|
|
23
|
+
import { existsSync, readFileSync, readdirSync, mkdirSync, writeFileSync, renameSync } from 'fs';
|
|
24
|
+
import { join } from 'path';
|
|
25
|
+
// ============================================
|
|
26
|
+
// Constants
|
|
27
|
+
// ============================================
|
|
28
|
+
/**
|
|
29
|
+
* Array of headless worker types for runtime checking
|
|
30
|
+
*/
|
|
31
|
+
export const HEADLESS_WORKER_TYPES = [
|
|
32
|
+
'audit',
|
|
33
|
+
'optimize',
|
|
34
|
+
'testgaps',
|
|
35
|
+
'document',
|
|
36
|
+
'ultralearn',
|
|
37
|
+
'refactor',
|
|
38
|
+
'deepdive',
|
|
39
|
+
'predict',
|
|
40
|
+
];
|
|
41
|
+
/**
|
|
42
|
+
* Array of local worker types
|
|
43
|
+
*/
|
|
44
|
+
export const LOCAL_WORKER_TYPES = [
|
|
45
|
+
'map',
|
|
46
|
+
'consolidate',
|
|
47
|
+
'benchmark',
|
|
48
|
+
'preload',
|
|
49
|
+
];
|
|
50
|
+
/**
|
|
51
|
+
* Model ID mapping
|
|
52
|
+
*/
|
|
53
|
+
/**
|
|
54
|
+
* Model ID mapping — use short aliases so they auto-resolve to the latest
|
|
55
|
+
* snapshot. Hardcoded dated IDs (e.g. claude-sonnet-4-5-20250929) go stale
|
|
56
|
+
* when Anthropic retires them, causing 100% worker failure (#1431).
|
|
57
|
+
*
|
|
58
|
+
* Users can override per-worker via the `model` field in daemon-state.json
|
|
59
|
+
* or the ANTHROPIC_MODEL environment variable.
|
|
60
|
+
*/
|
|
61
|
+
const MODEL_IDS = {
|
|
62
|
+
sonnet: 'sonnet',
|
|
63
|
+
opus: 'opus',
|
|
64
|
+
haiku: 'haiku',
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Default headless worker configurations based on ADR-020
|
|
68
|
+
*/
|
|
69
|
+
export const HEADLESS_WORKER_CONFIGS = {
|
|
70
|
+
audit: {
|
|
71
|
+
type: 'audit',
|
|
72
|
+
mode: 'headless',
|
|
73
|
+
intervalMs: 30 * 60 * 1000,
|
|
74
|
+
priority: 'critical',
|
|
75
|
+
description: 'AI-powered security analysis',
|
|
76
|
+
enabled: true,
|
|
77
|
+
headless: {
|
|
78
|
+
promptTemplate: `Analyze this codebase for security vulnerabilities:
|
|
79
|
+
- Check for hardcoded secrets (API keys, passwords)
|
|
80
|
+
- Identify SQL injection risks
|
|
81
|
+
- Find XSS vulnerabilities
|
|
82
|
+
- Check for insecure dependencies
|
|
83
|
+
- Identify authentication/authorization issues
|
|
84
|
+
|
|
85
|
+
Provide a JSON report with:
|
|
86
|
+
{
|
|
87
|
+
"vulnerabilities": [{ "severity": "high|medium|low", "file": "...", "line": N, "description": "..." }],
|
|
88
|
+
"riskScore": 0-100,
|
|
89
|
+
"recommendations": ["..."]
|
|
90
|
+
}`,
|
|
91
|
+
sandbox: 'strict',
|
|
92
|
+
model: 'haiku',
|
|
93
|
+
outputFormat: 'json',
|
|
94
|
+
contextPatterns: ['**/*.ts', '**/*.js', '**/package.json'],
|
|
95
|
+
timeoutMs: 5 * 60 * 1000,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
optimize: {
|
|
99
|
+
type: 'optimize',
|
|
100
|
+
mode: 'headless',
|
|
101
|
+
intervalMs: 60 * 60 * 1000,
|
|
102
|
+
priority: 'high',
|
|
103
|
+
description: 'AI optimization suggestions',
|
|
104
|
+
enabled: true,
|
|
105
|
+
headless: {
|
|
106
|
+
promptTemplate: `Analyze this codebase for performance optimizations:
|
|
107
|
+
- Identify N+1 query patterns
|
|
108
|
+
- Find unnecessary re-renders in React
|
|
109
|
+
- Suggest caching opportunities
|
|
110
|
+
- Identify memory leaks
|
|
111
|
+
- Find redundant computations
|
|
112
|
+
|
|
113
|
+
Provide actionable suggestions with code examples.`,
|
|
114
|
+
sandbox: 'permissive',
|
|
115
|
+
model: 'sonnet',
|
|
116
|
+
outputFormat: 'markdown',
|
|
117
|
+
contextPatterns: ['src/**/*.ts', 'src/**/*.tsx'],
|
|
118
|
+
timeoutMs: 10 * 60 * 1000,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
testgaps: {
|
|
122
|
+
type: 'testgaps',
|
|
123
|
+
mode: 'headless',
|
|
124
|
+
intervalMs: 60 * 60 * 1000,
|
|
125
|
+
priority: 'normal',
|
|
126
|
+
description: 'AI test gap analysis',
|
|
127
|
+
enabled: true,
|
|
128
|
+
headless: {
|
|
129
|
+
promptTemplate: `Analyze test coverage and identify gaps:
|
|
130
|
+
- Find untested functions and classes
|
|
131
|
+
- Identify edge cases not covered
|
|
132
|
+
- Suggest new test scenarios
|
|
133
|
+
- Check for missing error handling tests
|
|
134
|
+
- Identify integration test gaps
|
|
135
|
+
|
|
136
|
+
For each gap, provide a test skeleton.`,
|
|
137
|
+
sandbox: 'permissive',
|
|
138
|
+
model: 'sonnet',
|
|
139
|
+
outputFormat: 'markdown',
|
|
140
|
+
contextPatterns: ['src/**/*.ts', 'tests/**/*.ts', '__tests__/**/*.ts'],
|
|
141
|
+
timeoutMs: 10 * 60 * 1000,
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
document: {
|
|
145
|
+
type: 'document',
|
|
146
|
+
mode: 'headless',
|
|
147
|
+
intervalMs: 120 * 60 * 1000,
|
|
148
|
+
priority: 'low',
|
|
149
|
+
description: 'AI documentation generation',
|
|
150
|
+
enabled: false,
|
|
151
|
+
headless: {
|
|
152
|
+
promptTemplate: `Generate documentation for undocumented code:
|
|
153
|
+
- Add JSDoc comments to functions
|
|
154
|
+
- Create README sections for modules
|
|
155
|
+
- Document API endpoints
|
|
156
|
+
- Add inline comments for complex logic
|
|
157
|
+
- Generate usage examples
|
|
158
|
+
|
|
159
|
+
Focus on public APIs and exported functions.`,
|
|
160
|
+
sandbox: 'permissive',
|
|
161
|
+
model: 'haiku',
|
|
162
|
+
outputFormat: 'markdown',
|
|
163
|
+
contextPatterns: ['src/**/*.ts'],
|
|
164
|
+
timeoutMs: 10 * 60 * 1000,
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
ultralearn: {
|
|
168
|
+
type: 'ultralearn',
|
|
169
|
+
mode: 'headless',
|
|
170
|
+
intervalMs: 0, // Manual trigger only
|
|
171
|
+
priority: 'normal',
|
|
172
|
+
description: 'Deep knowledge acquisition',
|
|
173
|
+
enabled: false,
|
|
174
|
+
headless: {
|
|
175
|
+
promptTemplate: `Deeply analyze this codebase to learn:
|
|
176
|
+
- Architectural patterns used
|
|
177
|
+
- Coding conventions
|
|
178
|
+
- Domain-specific terminology
|
|
179
|
+
- Common patterns and idioms
|
|
180
|
+
- Team preferences
|
|
181
|
+
|
|
182
|
+
Provide insights as JSON:
|
|
183
|
+
{
|
|
184
|
+
"architecture": { "patterns": [...], "style": "..." },
|
|
185
|
+
"conventions": { "naming": "...", "formatting": "..." },
|
|
186
|
+
"domains": ["..."],
|
|
187
|
+
"insights": ["..."]
|
|
188
|
+
}`,
|
|
189
|
+
sandbox: 'strict',
|
|
190
|
+
model: 'opus',
|
|
191
|
+
outputFormat: 'json',
|
|
192
|
+
contextPatterns: ['**/*.ts', '**/CLAUDE.md', '**/README.md'],
|
|
193
|
+
timeoutMs: 15 * 60 * 1000,
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
refactor: {
|
|
197
|
+
type: 'refactor',
|
|
198
|
+
mode: 'headless',
|
|
199
|
+
intervalMs: 0, // Manual trigger only
|
|
200
|
+
priority: 'normal',
|
|
201
|
+
description: 'AI refactoring suggestions',
|
|
202
|
+
enabled: false,
|
|
203
|
+
headless: {
|
|
204
|
+
promptTemplate: `Suggest refactoring opportunities:
|
|
205
|
+
- Identify code duplication
|
|
206
|
+
- Suggest better abstractions
|
|
207
|
+
- Find opportunities for design patterns
|
|
208
|
+
- Identify overly complex functions
|
|
209
|
+
- Suggest module reorganization
|
|
210
|
+
|
|
211
|
+
Provide before/after code examples.`,
|
|
212
|
+
sandbox: 'permissive',
|
|
213
|
+
model: 'sonnet',
|
|
214
|
+
outputFormat: 'markdown',
|
|
215
|
+
contextPatterns: ['src/**/*.ts'],
|
|
216
|
+
timeoutMs: 10 * 60 * 1000,
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
deepdive: {
|
|
220
|
+
type: 'deepdive',
|
|
221
|
+
mode: 'headless',
|
|
222
|
+
intervalMs: 0, // Manual trigger only
|
|
223
|
+
priority: 'normal',
|
|
224
|
+
description: 'Deep code analysis',
|
|
225
|
+
enabled: false,
|
|
226
|
+
headless: {
|
|
227
|
+
promptTemplate: `Perform deep analysis of this codebase:
|
|
228
|
+
- Understand data flow
|
|
229
|
+
- Map dependencies
|
|
230
|
+
- Identify architectural issues
|
|
231
|
+
- Find potential bugs
|
|
232
|
+
- Analyze error handling
|
|
233
|
+
|
|
234
|
+
Provide comprehensive report.`,
|
|
235
|
+
sandbox: 'strict',
|
|
236
|
+
model: 'opus',
|
|
237
|
+
outputFormat: 'markdown',
|
|
238
|
+
contextPatterns: ['src/**/*.ts'],
|
|
239
|
+
timeoutMs: 15 * 60 * 1000,
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
predict: {
|
|
243
|
+
type: 'predict',
|
|
244
|
+
mode: 'headless',
|
|
245
|
+
intervalMs: 10 * 60 * 1000,
|
|
246
|
+
priority: 'low',
|
|
247
|
+
description: 'Predictive preloading',
|
|
248
|
+
enabled: false,
|
|
249
|
+
headless: {
|
|
250
|
+
promptTemplate: `Based on recent activity, predict what the developer needs:
|
|
251
|
+
- Files likely to be edited next
|
|
252
|
+
- Tests that should be run
|
|
253
|
+
- Documentation to reference
|
|
254
|
+
- Dependencies to check
|
|
255
|
+
|
|
256
|
+
Provide preload suggestions as JSON:
|
|
257
|
+
{
|
|
258
|
+
"filesToPreload": ["..."],
|
|
259
|
+
"testsToRun": ["..."],
|
|
260
|
+
"docsToReference": ["..."],
|
|
261
|
+
"confidence": 0.0-1.0
|
|
262
|
+
}`,
|
|
263
|
+
sandbox: 'strict',
|
|
264
|
+
model: 'haiku',
|
|
265
|
+
outputFormat: 'json',
|
|
266
|
+
contextPatterns: ['.monomind/metrics/*.json'],
|
|
267
|
+
timeoutMs: 2 * 60 * 1000,
|
|
268
|
+
},
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* Local worker configurations
|
|
273
|
+
*/
|
|
274
|
+
export const LOCAL_WORKER_CONFIGS = {
|
|
275
|
+
map: {
|
|
276
|
+
type: 'map',
|
|
277
|
+
mode: 'local',
|
|
278
|
+
intervalMs: 15 * 60 * 1000,
|
|
279
|
+
priority: 'normal',
|
|
280
|
+
description: 'Codebase mapping',
|
|
281
|
+
enabled: true,
|
|
282
|
+
},
|
|
283
|
+
consolidate: {
|
|
284
|
+
type: 'consolidate',
|
|
285
|
+
mode: 'local',
|
|
286
|
+
intervalMs: 30 * 60 * 1000,
|
|
287
|
+
priority: 'low',
|
|
288
|
+
description: 'Memory consolidation',
|
|
289
|
+
enabled: true,
|
|
290
|
+
},
|
|
291
|
+
benchmark: {
|
|
292
|
+
type: 'benchmark',
|
|
293
|
+
mode: 'local',
|
|
294
|
+
intervalMs: 60 * 60 * 1000,
|
|
295
|
+
priority: 'low',
|
|
296
|
+
description: 'Performance benchmarking',
|
|
297
|
+
enabled: false,
|
|
298
|
+
},
|
|
299
|
+
preload: {
|
|
300
|
+
type: 'preload',
|
|
301
|
+
mode: 'local',
|
|
302
|
+
intervalMs: 5 * 60 * 1000,
|
|
303
|
+
priority: 'low',
|
|
304
|
+
description: 'Resource preloading',
|
|
305
|
+
enabled: false,
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
/**
|
|
309
|
+
* Combined worker configurations
|
|
310
|
+
*/
|
|
311
|
+
export const ALL_WORKER_CONFIGS = [
|
|
312
|
+
...Object.values(HEADLESS_WORKER_CONFIGS),
|
|
313
|
+
...Object.values(LOCAL_WORKER_CONFIGS),
|
|
314
|
+
];
|
|
315
|
+
// ============================================
|
|
316
|
+
// Utility Functions
|
|
317
|
+
// ============================================
|
|
318
|
+
/**
|
|
319
|
+
* Check if a worker type is a headless worker
|
|
320
|
+
*/
|
|
321
|
+
export function isHeadlessWorker(type) {
|
|
322
|
+
return HEADLESS_WORKER_TYPES.includes(type);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Check if a worker type is a local worker
|
|
326
|
+
*/
|
|
327
|
+
export function isLocalWorker(type) {
|
|
328
|
+
return LOCAL_WORKER_TYPES.includes(type);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Get model ID from model type
|
|
332
|
+
*/
|
|
333
|
+
export function getModelId(model) {
|
|
334
|
+
return MODEL_IDS[model];
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Get worker configuration by type
|
|
338
|
+
*/
|
|
339
|
+
export function getWorkerConfig(type) {
|
|
340
|
+
if (isHeadlessWorker(type)) {
|
|
341
|
+
return HEADLESS_WORKER_CONFIGS[type];
|
|
342
|
+
}
|
|
343
|
+
if (isLocalWorker(type)) {
|
|
344
|
+
return LOCAL_WORKER_CONFIGS[type];
|
|
345
|
+
}
|
|
346
|
+
return undefined;
|
|
347
|
+
}
|
|
348
|
+
// ============================================
|
|
349
|
+
// HeadlessWorkerExecutor Class
|
|
350
|
+
// ============================================
|
|
351
|
+
/**
|
|
352
|
+
* HeadlessWorkerExecutor - Executes workers using Claude Code in headless mode
|
|
353
|
+
*
|
|
354
|
+
* Features:
|
|
355
|
+
* - Process pool with configurable concurrency limit
|
|
356
|
+
* - Pending queue for overflow requests
|
|
357
|
+
* - Context caching with configurable TTL
|
|
358
|
+
* - Execution logging for debugging
|
|
359
|
+
* - Event emission for monitoring
|
|
360
|
+
* - Graceful termination
|
|
361
|
+
*/
|
|
362
|
+
export class HeadlessWorkerExecutor extends EventEmitter {
|
|
363
|
+
projectRoot;
|
|
364
|
+
config;
|
|
365
|
+
processPool = new Map();
|
|
366
|
+
pendingQueue = [];
|
|
367
|
+
contextCache = new Map();
|
|
368
|
+
claudeCodeAvailable = null;
|
|
369
|
+
claudeCodeAvailableCheckedAt = null;
|
|
370
|
+
claudeCodeVersion = null;
|
|
371
|
+
// SECURITY: synchronous reservation counter so processQueue() does not
|
|
372
|
+
// drain the entire pendingQueue before async pool insertions catch up.
|
|
373
|
+
// Without this, a single processQueue() iteration could spawn hundreds of
|
|
374
|
+
// claude child processes simultaneously (DoS amplifier: 1 dequeue → 500 spawns).
|
|
375
|
+
activeReservations = 0;
|
|
376
|
+
constructor(projectRoot, options) {
|
|
377
|
+
super();
|
|
378
|
+
this.projectRoot = projectRoot;
|
|
379
|
+
// Merge with defaults
|
|
380
|
+
this.config = {
|
|
381
|
+
maxConcurrent: options?.maxConcurrent ?? 2,
|
|
382
|
+
defaultTimeoutMs: options?.defaultTimeoutMs ?? 5 * 60 * 1000,
|
|
383
|
+
maxContextFiles: options?.maxContextFiles ?? 20,
|
|
384
|
+
maxCharsPerFile: options?.maxCharsPerFile ?? 5000,
|
|
385
|
+
logDir: options?.logDir ?? join(projectRoot, '.monomind', 'logs', 'headless'),
|
|
386
|
+
cacheContext: options?.cacheContext ?? true,
|
|
387
|
+
cacheTtlMs: options?.cacheTtlMs ?? 60000, // 1 minute default
|
|
388
|
+
};
|
|
389
|
+
// Ensure log directory exists
|
|
390
|
+
this.ensureLogDir();
|
|
391
|
+
}
|
|
392
|
+
// ============================================
|
|
393
|
+
// Public API
|
|
394
|
+
// ============================================
|
|
395
|
+
/**
|
|
396
|
+
* Check if Claude Code CLI is available
|
|
397
|
+
*/
|
|
398
|
+
async isAvailable() {
|
|
399
|
+
const NEGATIVE_CACHE_TTL_MS = 60_000; // re-check after 1 min on negative result
|
|
400
|
+
if (this.claudeCodeAvailable === true) {
|
|
401
|
+
return true;
|
|
402
|
+
}
|
|
403
|
+
if (this.claudeCodeAvailable === false && this.claudeCodeAvailableCheckedAt !== null) {
|
|
404
|
+
if (Date.now() - this.claudeCodeAvailableCheckedAt < NEGATIVE_CACHE_TTL_MS) {
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
try {
|
|
409
|
+
const output = execSync('claude --version', {
|
|
410
|
+
encoding: 'utf-8',
|
|
411
|
+
stdio: 'pipe',
|
|
412
|
+
timeout: 5000,
|
|
413
|
+
windowsHide: true, // Prevent phantom console windows on Windows
|
|
414
|
+
});
|
|
415
|
+
this.claudeCodeAvailable = true;
|
|
416
|
+
this.claudeCodeAvailableCheckedAt = Date.now();
|
|
417
|
+
this.claudeCodeVersion = output.trim();
|
|
418
|
+
this.emit('status', { available: true, version: this.claudeCodeVersion });
|
|
419
|
+
return true;
|
|
420
|
+
}
|
|
421
|
+
catch {
|
|
422
|
+
this.claudeCodeAvailable = false;
|
|
423
|
+
this.claudeCodeAvailableCheckedAt = Date.now();
|
|
424
|
+
this.emit('status', { available: false });
|
|
425
|
+
return false;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Get Claude Code version
|
|
430
|
+
*/
|
|
431
|
+
async getVersion() {
|
|
432
|
+
await this.isAvailable();
|
|
433
|
+
return this.claudeCodeVersion;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Execute a headless worker
|
|
437
|
+
*/
|
|
438
|
+
async execute(workerType, configOverrides) {
|
|
439
|
+
const baseConfig = HEADLESS_WORKER_CONFIGS[workerType];
|
|
440
|
+
if (!baseConfig) {
|
|
441
|
+
throw new Error(`Unknown headless worker type: ${workerType}`);
|
|
442
|
+
}
|
|
443
|
+
// Check availability
|
|
444
|
+
const available = await this.isAvailable();
|
|
445
|
+
if (!available) {
|
|
446
|
+
const result = this.createErrorResult(workerType, 'Claude Code CLI not available. Install with: npm install -g @anthropic-ai/claude-code');
|
|
447
|
+
this.emit('error', result);
|
|
448
|
+
return result;
|
|
449
|
+
}
|
|
450
|
+
// Check concurrent limit using activeReservations (synchronous counter)
|
|
451
|
+
// rather than processPool.size (which is updated only after async setup).
|
|
452
|
+
if (this.activeReservations >= this.config.maxConcurrent) {
|
|
453
|
+
// Queue the request
|
|
454
|
+
const MAX_PENDING = 500;
|
|
455
|
+
if (this.pendingQueue.length >= MAX_PENDING) {
|
|
456
|
+
return this.createErrorResult(workerType, 'Pending queue is full');
|
|
457
|
+
}
|
|
458
|
+
return new Promise((resolve, reject) => {
|
|
459
|
+
const entry = {
|
|
460
|
+
workerType,
|
|
461
|
+
config: configOverrides,
|
|
462
|
+
resolve,
|
|
463
|
+
reject,
|
|
464
|
+
queuedAt: new Date(),
|
|
465
|
+
};
|
|
466
|
+
this.pendingQueue.push(entry);
|
|
467
|
+
this.emit('queued', {
|
|
468
|
+
workerType,
|
|
469
|
+
queuePosition: this.pendingQueue.length,
|
|
470
|
+
});
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
// Reserve the slot synchronously and release it (regardless of success
|
|
474
|
+
// or failure) so processQueue can pull the next pending item.
|
|
475
|
+
this.activeReservations++;
|
|
476
|
+
try {
|
|
477
|
+
return await this.executeInternal(workerType, configOverrides);
|
|
478
|
+
}
|
|
479
|
+
finally {
|
|
480
|
+
this.activeReservations--;
|
|
481
|
+
this.processQueue();
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Get pool status
|
|
486
|
+
*/
|
|
487
|
+
getPoolStatus() {
|
|
488
|
+
const now = Date.now();
|
|
489
|
+
return {
|
|
490
|
+
activeCount: this.processPool.size,
|
|
491
|
+
queueLength: this.pendingQueue.length,
|
|
492
|
+
maxConcurrent: this.config.maxConcurrent,
|
|
493
|
+
activeWorkers: Array.from(this.processPool.values()).map((entry) => ({
|
|
494
|
+
executionId: entry.executionId,
|
|
495
|
+
workerType: entry.workerType,
|
|
496
|
+
startTime: entry.startTime,
|
|
497
|
+
elapsedMs: now - entry.startTime.getTime(),
|
|
498
|
+
})),
|
|
499
|
+
queuedWorkers: this.pendingQueue.map((entry) => ({
|
|
500
|
+
workerType: entry.workerType,
|
|
501
|
+
queuedAt: entry.queuedAt,
|
|
502
|
+
waitingMs: now - entry.queuedAt.getTime(),
|
|
503
|
+
})),
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Get number of active executions
|
|
508
|
+
*/
|
|
509
|
+
getActiveCount() {
|
|
510
|
+
return this.processPool.size;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* Cancel a running execution
|
|
514
|
+
*/
|
|
515
|
+
cancel(executionId) {
|
|
516
|
+
const entry = this.processPool.get(executionId);
|
|
517
|
+
if (!entry) {
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
clearTimeout(entry.timeout);
|
|
521
|
+
let exited = false;
|
|
522
|
+
entry.process.once('exit', () => { exited = true; });
|
|
523
|
+
try {
|
|
524
|
+
entry.process.kill('SIGTERM');
|
|
525
|
+
}
|
|
526
|
+
catch { /* may already be dead */ }
|
|
527
|
+
const killTimer = setTimeout(() => {
|
|
528
|
+
if (!exited) {
|
|
529
|
+
try {
|
|
530
|
+
entry.process.kill('SIGKILL');
|
|
531
|
+
}
|
|
532
|
+
catch { /* ignore */ }
|
|
533
|
+
}
|
|
534
|
+
}, 5000);
|
|
535
|
+
killTimer.unref();
|
|
536
|
+
entry.process.once('exit', () => clearTimeout(killTimer));
|
|
537
|
+
this.processPool.delete(executionId);
|
|
538
|
+
this.emit('cancelled', { executionId });
|
|
539
|
+
// Process next in queue
|
|
540
|
+
this.processQueue();
|
|
541
|
+
return true;
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* Cancel all running executions for a specific worker type.
|
|
545
|
+
* Used by the timeout handler in worker-daemon to avoid killing unrelated workers.
|
|
546
|
+
*/
|
|
547
|
+
cancelByType(workerType) {
|
|
548
|
+
let cancelled = false;
|
|
549
|
+
const entries = Array.from(this.processPool.entries());
|
|
550
|
+
for (const [executionId, entry] of entries) {
|
|
551
|
+
if (entry.workerType !== workerType)
|
|
552
|
+
continue;
|
|
553
|
+
clearTimeout(entry.timeout);
|
|
554
|
+
let exited = false;
|
|
555
|
+
entry.process.once('exit', () => { exited = true; });
|
|
556
|
+
try {
|
|
557
|
+
entry.process.kill('SIGTERM');
|
|
558
|
+
}
|
|
559
|
+
catch { /* may already be dead */ }
|
|
560
|
+
const killTimer = setTimeout(() => {
|
|
561
|
+
if (!exited) {
|
|
562
|
+
try {
|
|
563
|
+
entry.process.kill('SIGKILL');
|
|
564
|
+
}
|
|
565
|
+
catch { /* ignore */ }
|
|
566
|
+
}
|
|
567
|
+
}, 5000);
|
|
568
|
+
killTimer.unref();
|
|
569
|
+
entry.process.once('exit', () => clearTimeout(killTimer));
|
|
570
|
+
this.processPool.delete(executionId);
|
|
571
|
+
this.emit('cancelled', { executionId });
|
|
572
|
+
cancelled = true;
|
|
573
|
+
}
|
|
574
|
+
if (cancelled)
|
|
575
|
+
this.processQueue();
|
|
576
|
+
return cancelled;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Cancel all running executions
|
|
580
|
+
*/
|
|
581
|
+
cancelAll() {
|
|
582
|
+
let cancelled = 0;
|
|
583
|
+
// Cancel active processes (convert to array to avoid iterator issues)
|
|
584
|
+
const entries = Array.from(this.processPool.entries());
|
|
585
|
+
for (const [executionId, entry] of entries) {
|
|
586
|
+
clearTimeout(entry.timeout);
|
|
587
|
+
// Track exit so the SIGKILL fallback can't be sent to a recycled PID.
|
|
588
|
+
// entry.process.killed is set by Node when .kill() was called, NOT when
|
|
589
|
+
// the OS process actually exited — without an explicit 'exit' listener,
|
|
590
|
+
// a recycled PID can receive our SIGKILL.
|
|
591
|
+
let exited = false;
|
|
592
|
+
entry.process.once('exit', () => { exited = true; });
|
|
593
|
+
try {
|
|
594
|
+
entry.process.kill('SIGTERM');
|
|
595
|
+
}
|
|
596
|
+
catch { /* may already be dead */ }
|
|
597
|
+
const killTimer = setTimeout(() => {
|
|
598
|
+
if (exited)
|
|
599
|
+
return;
|
|
600
|
+
try {
|
|
601
|
+
entry.process.kill('SIGKILL');
|
|
602
|
+
}
|
|
603
|
+
catch { /* already dead */ }
|
|
604
|
+
}, 5000);
|
|
605
|
+
killTimer.unref();
|
|
606
|
+
entry.process.once('exit', () => clearTimeout(killTimer));
|
|
607
|
+
this.emit('cancelled', { executionId });
|
|
608
|
+
cancelled++;
|
|
609
|
+
}
|
|
610
|
+
this.processPool.clear();
|
|
611
|
+
// Reject pending queue
|
|
612
|
+
for (const entry of this.pendingQueue) {
|
|
613
|
+
entry.reject(new Error('Executor cancelled all executions'));
|
|
614
|
+
}
|
|
615
|
+
this.pendingQueue = [];
|
|
616
|
+
this.emit('allCancelled', { count: cancelled });
|
|
617
|
+
return cancelled;
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Clear context cache
|
|
621
|
+
*/
|
|
622
|
+
clearContextCache() {
|
|
623
|
+
this.contextCache.clear();
|
|
624
|
+
this.emit('cacheClear', {});
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Get worker configuration
|
|
628
|
+
*/
|
|
629
|
+
getConfig(workerType) {
|
|
630
|
+
return HEADLESS_WORKER_CONFIGS[workerType];
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Get all headless worker types
|
|
634
|
+
*/
|
|
635
|
+
getHeadlessWorkerTypes() {
|
|
636
|
+
return [...HEADLESS_WORKER_TYPES];
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Get all local worker types
|
|
640
|
+
*/
|
|
641
|
+
getLocalWorkerTypes() {
|
|
642
|
+
return [...LOCAL_WORKER_TYPES];
|
|
643
|
+
}
|
|
644
|
+
// ============================================
|
|
645
|
+
// Private Methods
|
|
646
|
+
// ============================================
|
|
647
|
+
/**
|
|
648
|
+
* Ensure log directory exists
|
|
649
|
+
*/
|
|
650
|
+
ensureLogDir() {
|
|
651
|
+
try {
|
|
652
|
+
if (!existsSync(this.config.logDir)) {
|
|
653
|
+
mkdirSync(this.config.logDir, { recursive: true });
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
catch (error) {
|
|
657
|
+
this.emit('warning', { message: 'Failed to create log directory', error });
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Internal execution logic
|
|
662
|
+
*/
|
|
663
|
+
async executeInternal(workerType, configOverrides) {
|
|
664
|
+
const baseConfig = HEADLESS_WORKER_CONFIGS[workerType];
|
|
665
|
+
const headless = { ...baseConfig.headless, ...configOverrides };
|
|
666
|
+
const startTime = Date.now();
|
|
667
|
+
const executionId = `${workerType}_${startTime}_${Math.random().toString(36).slice(2, 8)}`;
|
|
668
|
+
this.emit('start', { executionId, workerType, config: headless });
|
|
669
|
+
try {
|
|
670
|
+
// Build context from file patterns
|
|
671
|
+
const context = await this.buildContext(headless.contextPatterns || []);
|
|
672
|
+
// Build the full prompt
|
|
673
|
+
const fullPrompt = this.buildPrompt(headless.promptTemplate, context);
|
|
674
|
+
// Log prompt for debugging
|
|
675
|
+
this.logExecution(executionId, 'prompt', fullPrompt);
|
|
676
|
+
// Execute Claude Code headlessly
|
|
677
|
+
const result = await this.executeClaudeCode(fullPrompt, {
|
|
678
|
+
sandbox: headless.sandbox,
|
|
679
|
+
model: headless.model || 'sonnet',
|
|
680
|
+
timeoutMs: headless.timeoutMs || this.config.defaultTimeoutMs,
|
|
681
|
+
executionId,
|
|
682
|
+
workerType,
|
|
683
|
+
});
|
|
684
|
+
// Parse output based on format
|
|
685
|
+
let parsedOutput;
|
|
686
|
+
if (headless.outputFormat === 'json' && result.output) {
|
|
687
|
+
parsedOutput = this.parseJsonOutput(result.output);
|
|
688
|
+
}
|
|
689
|
+
else if (headless.outputFormat === 'markdown' && result.output) {
|
|
690
|
+
parsedOutput = this.parseMarkdownOutput(result.output);
|
|
691
|
+
}
|
|
692
|
+
const executionResult = {
|
|
693
|
+
success: result.success,
|
|
694
|
+
output: result.output,
|
|
695
|
+
parsedOutput,
|
|
696
|
+
durationMs: Date.now() - startTime,
|
|
697
|
+
tokensUsed: result.tokensUsed,
|
|
698
|
+
model: headless.model || 'sonnet',
|
|
699
|
+
sandboxMode: headless.sandbox,
|
|
700
|
+
workerType,
|
|
701
|
+
timestamp: new Date(),
|
|
702
|
+
executionId,
|
|
703
|
+
error: result.error,
|
|
704
|
+
};
|
|
705
|
+
// Log result
|
|
706
|
+
this.logExecution(executionId, 'result', JSON.stringify(executionResult, null, 2));
|
|
707
|
+
this.emit('complete', executionResult);
|
|
708
|
+
return executionResult;
|
|
709
|
+
}
|
|
710
|
+
catch (error) {
|
|
711
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
712
|
+
const executionResult = this.createErrorResult(workerType, errorMessage);
|
|
713
|
+
executionResult.executionId = executionId;
|
|
714
|
+
executionResult.durationMs = Date.now() - startTime;
|
|
715
|
+
this.logExecution(executionId, 'error', errorMessage);
|
|
716
|
+
this.emit('error', executionResult);
|
|
717
|
+
return executionResult;
|
|
718
|
+
}
|
|
719
|
+
finally {
|
|
720
|
+
// Process next in queue
|
|
721
|
+
this.processQueue();
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* Process the pending queue
|
|
726
|
+
*/
|
|
727
|
+
processQueue() {
|
|
728
|
+
// Gate on activeReservations (synchronous counter) so we cannot
|
|
729
|
+
// accidentally drain the queue past maxConcurrent before async setup
|
|
730
|
+
// populates processPool.
|
|
731
|
+
while (this.pendingQueue.length > 0 &&
|
|
732
|
+
this.activeReservations < this.config.maxConcurrent) {
|
|
733
|
+
const next = this.pendingQueue.shift();
|
|
734
|
+
if (!next)
|
|
735
|
+
break;
|
|
736
|
+
this.activeReservations++;
|
|
737
|
+
this.executeInternal(next.workerType, next.config)
|
|
738
|
+
.then(next.resolve, next.reject)
|
|
739
|
+
.finally(() => {
|
|
740
|
+
this.activeReservations--;
|
|
741
|
+
this.processQueue();
|
|
742
|
+
});
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Build context from file patterns
|
|
747
|
+
*/
|
|
748
|
+
async buildContext(patterns) {
|
|
749
|
+
if (patterns.length === 0)
|
|
750
|
+
return '';
|
|
751
|
+
// Check cache
|
|
752
|
+
const cacheKey = patterns.sort().join('|');
|
|
753
|
+
if (this.config.cacheContext) {
|
|
754
|
+
const cached = this.contextCache.get(cacheKey);
|
|
755
|
+
if (cached && Date.now() - cached.timestamp < this.config.cacheTtlMs) {
|
|
756
|
+
return cached.content;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
// Collect files matching patterns
|
|
760
|
+
const files = [];
|
|
761
|
+
for (const pattern of patterns) {
|
|
762
|
+
const matches = this.simpleGlob(pattern);
|
|
763
|
+
files.push(...matches);
|
|
764
|
+
}
|
|
765
|
+
// Deduplicate and limit
|
|
766
|
+
const uniqueFiles = Array.from(new Set(files)).slice(0, this.config.maxContextFiles);
|
|
767
|
+
// Build context
|
|
768
|
+
const { resolve: resolvePath, sep } = await import('path');
|
|
769
|
+
const contextParts = [];
|
|
770
|
+
for (const file of uniqueFiles) {
|
|
771
|
+
try {
|
|
772
|
+
const fullPath = join(this.projectRoot, file);
|
|
773
|
+
const resolvedFull = resolvePath(fullPath);
|
|
774
|
+
const resolvedRoot = resolvePath(this.projectRoot);
|
|
775
|
+
if (!resolvedFull.startsWith(resolvedRoot + sep) && resolvedFull !== resolvedRoot)
|
|
776
|
+
continue;
|
|
777
|
+
if (!existsSync(resolvedFull))
|
|
778
|
+
continue;
|
|
779
|
+
const content = readFileSync(resolvedFull, 'utf-8');
|
|
780
|
+
const truncated = content.slice(0, this.config.maxCharsPerFile);
|
|
781
|
+
const wasTruncated = content.length > this.config.maxCharsPerFile;
|
|
782
|
+
contextParts.push(`--- ${file}${wasTruncated ? ' (truncated)' : ''} ---\n${truncated}`);
|
|
783
|
+
}
|
|
784
|
+
catch {
|
|
785
|
+
// Skip unreadable files
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
const contextContent = contextParts.join('\n\n');
|
|
789
|
+
// Cache the result (evict oldest when at capacity)
|
|
790
|
+
if (this.config.cacheContext) {
|
|
791
|
+
if (this.contextCache.size >= 50) {
|
|
792
|
+
const oldestKey = this.contextCache.keys().next().value;
|
|
793
|
+
if (oldestKey !== undefined)
|
|
794
|
+
this.contextCache.delete(oldestKey);
|
|
795
|
+
}
|
|
796
|
+
this.contextCache.set(cacheKey, {
|
|
797
|
+
content: contextContent,
|
|
798
|
+
timestamp: Date.now(),
|
|
799
|
+
patterns,
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
return contextContent;
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Simple glob implementation for file matching
|
|
806
|
+
*/
|
|
807
|
+
simpleGlob(pattern) {
|
|
808
|
+
const results = [];
|
|
809
|
+
// Handle simple patterns (no wildcards)
|
|
810
|
+
if (!pattern.includes('*')) {
|
|
811
|
+
const fullPath = join(this.projectRoot, pattern);
|
|
812
|
+
if (existsSync(fullPath)) {
|
|
813
|
+
results.push(pattern);
|
|
814
|
+
}
|
|
815
|
+
return results;
|
|
816
|
+
}
|
|
817
|
+
// Parse pattern parts
|
|
818
|
+
const parts = pattern.split('/');
|
|
819
|
+
const scanDir = (dir, remainingParts) => {
|
|
820
|
+
if (remainingParts.length === 0)
|
|
821
|
+
return;
|
|
822
|
+
if (results.length >= 100)
|
|
823
|
+
return; // Limit results
|
|
824
|
+
try {
|
|
825
|
+
const fullDir = join(this.projectRoot, dir);
|
|
826
|
+
if (!existsSync(fullDir))
|
|
827
|
+
return;
|
|
828
|
+
const entries = readdirSync(fullDir, { withFileTypes: true });
|
|
829
|
+
const currentPart = remainingParts[0];
|
|
830
|
+
const isLastPart = remainingParts.length === 1;
|
|
831
|
+
for (const entry of entries) {
|
|
832
|
+
// Skip common non-code directories
|
|
833
|
+
if (entry.name === 'node_modules' ||
|
|
834
|
+
entry.name === '.git' ||
|
|
835
|
+
entry.name === 'dist' ||
|
|
836
|
+
entry.name === 'build' ||
|
|
837
|
+
entry.name === 'coverage' ||
|
|
838
|
+
entry.name === '.next' ||
|
|
839
|
+
entry.name === '.cache') {
|
|
840
|
+
continue;
|
|
841
|
+
}
|
|
842
|
+
const entryPath = dir ? `${dir}/${entry.name}` : entry.name;
|
|
843
|
+
if (currentPart === '**') {
|
|
844
|
+
// Recursive glob
|
|
845
|
+
if (entry.isDirectory()) {
|
|
846
|
+
scanDir(entryPath, remainingParts); // Continue with **
|
|
847
|
+
scanDir(entryPath, remainingParts.slice(1)); // Try next part
|
|
848
|
+
}
|
|
849
|
+
else if (entry.isFile() && remainingParts.length > 1) {
|
|
850
|
+
// Check if file matches next pattern part
|
|
851
|
+
const nextPart = remainingParts[1];
|
|
852
|
+
if (this.matchesPattern(entry.name, nextPart)) {
|
|
853
|
+
results.push(entryPath);
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
else if (this.matchesPattern(entry.name, currentPart)) {
|
|
858
|
+
if (isLastPart && entry.isFile()) {
|
|
859
|
+
results.push(entryPath);
|
|
860
|
+
}
|
|
861
|
+
else if (!isLastPart && entry.isDirectory()) {
|
|
862
|
+
scanDir(entryPath, remainingParts.slice(1));
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
catch {
|
|
868
|
+
// Skip unreadable directories
|
|
869
|
+
}
|
|
870
|
+
};
|
|
871
|
+
scanDir('', parts);
|
|
872
|
+
return results;
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Match filename against a simple pattern
|
|
876
|
+
*/
|
|
877
|
+
matchesPattern(name, pattern) {
|
|
878
|
+
if (pattern === '*')
|
|
879
|
+
return true;
|
|
880
|
+
if (pattern === '**')
|
|
881
|
+
return true;
|
|
882
|
+
// Handle *.ext patterns
|
|
883
|
+
if (pattern.startsWith('*.')) {
|
|
884
|
+
return name.endsWith(pattern.slice(1));
|
|
885
|
+
}
|
|
886
|
+
// Handle prefix* patterns
|
|
887
|
+
if (pattern.endsWith('*')) {
|
|
888
|
+
return name.startsWith(pattern.slice(0, -1));
|
|
889
|
+
}
|
|
890
|
+
// Handle *suffix patterns
|
|
891
|
+
if (pattern.startsWith('*')) {
|
|
892
|
+
return name.endsWith(pattern.slice(1));
|
|
893
|
+
}
|
|
894
|
+
// Exact match
|
|
895
|
+
return name === pattern;
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* Build full prompt with context
|
|
899
|
+
*/
|
|
900
|
+
buildPrompt(template, context) {
|
|
901
|
+
if (!context) {
|
|
902
|
+
return `${template}
|
|
903
|
+
|
|
904
|
+
## Instructions
|
|
905
|
+
|
|
906
|
+
Analyze the codebase and provide your response following the format specified in the task.`;
|
|
907
|
+
}
|
|
908
|
+
return `${template}
|
|
909
|
+
|
|
910
|
+
## Codebase Context
|
|
911
|
+
|
|
912
|
+
${context}
|
|
913
|
+
|
|
914
|
+
## Instructions
|
|
915
|
+
|
|
916
|
+
Analyze the above codebase context and provide your response following the format specified in the task.`;
|
|
917
|
+
}
|
|
918
|
+
/**
|
|
919
|
+
* Execute Claude Code in headless mode
|
|
920
|
+
*/
|
|
921
|
+
executeClaudeCode(prompt, options) {
|
|
922
|
+
return new Promise((resolve) => {
|
|
923
|
+
// SECURITY: in strict sandbox mode, build a minimal env allowlist instead
|
|
924
|
+
// of forwarding the entire parent env. The previous spread also passed
|
|
925
|
+
// LD_PRELOAD, NODE_OPTIONS, DYLD_INSERT_LIBRARIES, PYTHONPATH, HTTP_PROXY,
|
|
926
|
+
// etc. — which means "strict" was a label, not a control. Now it actually
|
|
927
|
+
// strips dangerous loaders/proxies even when the parent has them set.
|
|
928
|
+
const STRICT_ENV_ALLOWLIST = new Set([
|
|
929
|
+
'PATH', 'HOME', 'USER', 'LOGNAME', 'LANG', 'LC_ALL', 'TZ', 'TERM', 'SHELL',
|
|
930
|
+
'TMPDIR', 'TMP', 'TEMP',
|
|
931
|
+
'ANTHROPIC_API_KEY', 'ANTHROPIC_MODEL', 'ANTHROPIC_BASE_URL',
|
|
932
|
+
]);
|
|
933
|
+
const FORBIDDEN_ENV = new Set([
|
|
934
|
+
'LD_PRELOAD', 'LD_LIBRARY_PATH', 'LD_AUDIT',
|
|
935
|
+
'DYLD_INSERT_LIBRARIES', 'DYLD_LIBRARY_PATH', 'DYLD_FALLBACK_LIBRARY_PATH',
|
|
936
|
+
'NODE_OPTIONS', 'NODE_PATH',
|
|
937
|
+
'PYTHONPATH', 'PYTHONHOME', 'PYTHONSTARTUP',
|
|
938
|
+
'HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY',
|
|
939
|
+
'BASH_ENV', 'ENV', 'CDPATH',
|
|
940
|
+
'PERL5OPT', 'RUBYOPT',
|
|
941
|
+
'JAVA_TOOL_OPTIONS', '_JAVA_OPTIONS', 'JDK_JAVA_OPTIONS',
|
|
942
|
+
]);
|
|
943
|
+
const baseEnv = {};
|
|
944
|
+
if (options.sandbox === 'strict') {
|
|
945
|
+
for (const k of STRICT_ENV_ALLOWLIST) {
|
|
946
|
+
const v = process.env[k];
|
|
947
|
+
if (typeof v === 'string')
|
|
948
|
+
baseEnv[k] = v;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
else {
|
|
952
|
+
for (const [k, v] of Object.entries(process.env)) {
|
|
953
|
+
if (typeof v !== 'string')
|
|
954
|
+
continue;
|
|
955
|
+
if (FORBIDDEN_ENV.has(k))
|
|
956
|
+
continue; // always strip in any mode
|
|
957
|
+
baseEnv[k] = v;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
const env = {
|
|
961
|
+
...baseEnv,
|
|
962
|
+
CLAUDE_CODE_HEADLESS: 'true',
|
|
963
|
+
CLAUDE_CODE_SANDBOX_MODE: options.sandbox,
|
|
964
|
+
// Fix #1395 Bug 2: Workers fail inside active Claude Code session.
|
|
965
|
+
// Claude Code detects nested sessions and exits immediately.
|
|
966
|
+
// Setting CLAUDE_ENTRYPOINT=worker bypasses the nested-session check,
|
|
967
|
+
// and unsetting CLAUDE_SESSION_ID prevents parent session detection.
|
|
968
|
+
CLAUDE_ENTRYPOINT: 'worker',
|
|
969
|
+
};
|
|
970
|
+
// Remove parent session markers so the child doesn't detect a "nested" session
|
|
971
|
+
delete env.CLAUDE_SESSION_ID;
|
|
972
|
+
delete env.CLAUDE_PARENT_SESSION_ID;
|
|
973
|
+
// Set model
|
|
974
|
+
// Resolve model: user env override > config override > default alias
|
|
975
|
+
env.ANTHROPIC_MODEL = process.env.ANTHROPIC_MODEL || MODEL_IDS[options.model];
|
|
976
|
+
// Spawn claude CLI process — `--` terminates option parsing so prompt can't smuggle flags
|
|
977
|
+
const child = spawn('claude', ['--print', '--', prompt], {
|
|
978
|
+
cwd: this.projectRoot,
|
|
979
|
+
env,
|
|
980
|
+
stdio: ['ignore', 'pipe', 'pipe'], // 'ignore' closes stdin at spawn — fixes #1395 where claude --print blocks on EOF
|
|
981
|
+
windowsHide: true, // Prevent phantom console windows on Windows
|
|
982
|
+
});
|
|
983
|
+
// Setup timeout — track real exit via 'exit' listener.
|
|
984
|
+
// child.killed is set by Node when .kill() is called (signal sent), NOT
|
|
985
|
+
// when the OS process exited. Without an explicit `exited` flag the
|
|
986
|
+
// SIGKILL fallback never fires for a process that ignores SIGTERM, and
|
|
987
|
+
// the slot leaks indefinitely.
|
|
988
|
+
let sigkillTimer;
|
|
989
|
+
let childExited = false;
|
|
990
|
+
child.once('exit', () => { childExited = true; });
|
|
991
|
+
const timeoutHandle = setTimeout(() => {
|
|
992
|
+
if (this.processPool.has(options.executionId)) {
|
|
993
|
+
try {
|
|
994
|
+
child.kill('SIGTERM');
|
|
995
|
+
}
|
|
996
|
+
catch { /* may already be dead */ }
|
|
997
|
+
sigkillTimer = setTimeout(() => {
|
|
998
|
+
if (childExited)
|
|
999
|
+
return;
|
|
1000
|
+
try {
|
|
1001
|
+
child.kill('SIGKILL');
|
|
1002
|
+
}
|
|
1003
|
+
catch { /* already dead */ }
|
|
1004
|
+
}, 5000);
|
|
1005
|
+
sigkillTimer.unref();
|
|
1006
|
+
}
|
|
1007
|
+
}, options.timeoutMs);
|
|
1008
|
+
// Track in process pool
|
|
1009
|
+
const poolEntry = {
|
|
1010
|
+
process: child,
|
|
1011
|
+
executionId: options.executionId,
|
|
1012
|
+
workerType: options.workerType,
|
|
1013
|
+
startTime: new Date(),
|
|
1014
|
+
timeout: timeoutHandle,
|
|
1015
|
+
};
|
|
1016
|
+
this.processPool.set(options.executionId, poolEntry);
|
|
1017
|
+
let stdout = '';
|
|
1018
|
+
let stderr = '';
|
|
1019
|
+
let resolved = false;
|
|
1020
|
+
const cleanup = () => {
|
|
1021
|
+
clearTimeout(timeoutHandle);
|
|
1022
|
+
clearTimeout(sigkillTimer);
|
|
1023
|
+
this.processPool.delete(options.executionId);
|
|
1024
|
+
};
|
|
1025
|
+
child.stdout?.on('data', (data) => {
|
|
1026
|
+
const chunk = data.toString();
|
|
1027
|
+
stdout += chunk;
|
|
1028
|
+
this.emit('output', {
|
|
1029
|
+
executionId: options.executionId,
|
|
1030
|
+
type: 'stdout',
|
|
1031
|
+
data: chunk,
|
|
1032
|
+
});
|
|
1033
|
+
});
|
|
1034
|
+
child.stderr?.on('data', (data) => {
|
|
1035
|
+
const chunk = data.toString();
|
|
1036
|
+
stderr += chunk;
|
|
1037
|
+
this.emit('output', {
|
|
1038
|
+
executionId: options.executionId,
|
|
1039
|
+
type: 'stderr',
|
|
1040
|
+
data: chunk,
|
|
1041
|
+
});
|
|
1042
|
+
});
|
|
1043
|
+
child.on('close', (code) => {
|
|
1044
|
+
if (resolved)
|
|
1045
|
+
return;
|
|
1046
|
+
resolved = true;
|
|
1047
|
+
cleanup();
|
|
1048
|
+
resolve({
|
|
1049
|
+
success: code === 0,
|
|
1050
|
+
output: stdout || stderr,
|
|
1051
|
+
error: code !== 0 ? stderr || `Process exited with code ${code}` : undefined,
|
|
1052
|
+
});
|
|
1053
|
+
});
|
|
1054
|
+
child.on('error', (error) => {
|
|
1055
|
+
if (resolved)
|
|
1056
|
+
return;
|
|
1057
|
+
resolved = true;
|
|
1058
|
+
cleanup();
|
|
1059
|
+
resolve({
|
|
1060
|
+
success: false,
|
|
1061
|
+
output: '',
|
|
1062
|
+
error: error.message,
|
|
1063
|
+
});
|
|
1064
|
+
});
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
/**
|
|
1068
|
+
* Parse JSON output from Claude Code
|
|
1069
|
+
*/
|
|
1070
|
+
parseJsonOutput(output) {
|
|
1071
|
+
try {
|
|
1072
|
+
// Try to find JSON in code blocks first
|
|
1073
|
+
const codeBlockMatch = output.match(/```(?:json)?\s*([\s\S]*?)```/);
|
|
1074
|
+
if (codeBlockMatch) {
|
|
1075
|
+
return JSON.parse(codeBlockMatch[1].trim());
|
|
1076
|
+
}
|
|
1077
|
+
// Try to find any JSON object
|
|
1078
|
+
const jsonMatch = output.match(/\{[\s\S]*\}/);
|
|
1079
|
+
if (jsonMatch) {
|
|
1080
|
+
return JSON.parse(jsonMatch[0]);
|
|
1081
|
+
}
|
|
1082
|
+
// Try direct parse
|
|
1083
|
+
return JSON.parse(output.trim());
|
|
1084
|
+
}
|
|
1085
|
+
catch {
|
|
1086
|
+
return {
|
|
1087
|
+
parseError: true,
|
|
1088
|
+
rawOutput: output,
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* Parse markdown output into sections
|
|
1094
|
+
*/
|
|
1095
|
+
parseMarkdownOutput(output) {
|
|
1096
|
+
const sections = [];
|
|
1097
|
+
const codeBlocks = [];
|
|
1098
|
+
// Extract code blocks first
|
|
1099
|
+
const codeBlockRegex = /```(\w*)\n([\s\S]*?)```/g;
|
|
1100
|
+
let codeMatch;
|
|
1101
|
+
while ((codeMatch = codeBlockRegex.exec(output)) !== null) {
|
|
1102
|
+
codeBlocks.push({
|
|
1103
|
+
language: codeMatch[1] || 'text',
|
|
1104
|
+
code: codeMatch[2].trim(),
|
|
1105
|
+
});
|
|
1106
|
+
}
|
|
1107
|
+
// Parse sections
|
|
1108
|
+
const lines = output.split('\n');
|
|
1109
|
+
let currentSection = null;
|
|
1110
|
+
for (const line of lines) {
|
|
1111
|
+
const headerMatch = line.match(/^(#{1,6})\s+(.+)$/);
|
|
1112
|
+
if (headerMatch) {
|
|
1113
|
+
if (currentSection) {
|
|
1114
|
+
sections.push(currentSection);
|
|
1115
|
+
}
|
|
1116
|
+
currentSection = {
|
|
1117
|
+
title: headerMatch[2].trim(),
|
|
1118
|
+
content: '',
|
|
1119
|
+
level: headerMatch[1].length,
|
|
1120
|
+
};
|
|
1121
|
+
}
|
|
1122
|
+
else if (currentSection) {
|
|
1123
|
+
currentSection.content += line + '\n';
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
if (currentSection) {
|
|
1127
|
+
currentSection.content = currentSection.content.trim();
|
|
1128
|
+
sections.push(currentSection);
|
|
1129
|
+
}
|
|
1130
|
+
return { sections, codeBlocks };
|
|
1131
|
+
}
|
|
1132
|
+
/**
|
|
1133
|
+
* Create an error result
|
|
1134
|
+
*/
|
|
1135
|
+
createErrorResult(workerType, error) {
|
|
1136
|
+
return {
|
|
1137
|
+
success: false,
|
|
1138
|
+
output: '',
|
|
1139
|
+
durationMs: 0,
|
|
1140
|
+
model: 'unknown',
|
|
1141
|
+
sandboxMode: 'strict',
|
|
1142
|
+
workerType,
|
|
1143
|
+
timestamp: new Date(),
|
|
1144
|
+
executionId: `error_${Date.now()}`,
|
|
1145
|
+
error,
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* Log execution details for debugging
|
|
1150
|
+
*/
|
|
1151
|
+
logExecution(executionId, type, content) {
|
|
1152
|
+
try {
|
|
1153
|
+
const timestamp = new Date().toISOString();
|
|
1154
|
+
const logFile = join(this.config.logDir, `${executionId}_${type}.log`);
|
|
1155
|
+
const logContent = `[${timestamp}] ${type.toUpperCase()}\n${'='.repeat(60)}\n${content}\n`;
|
|
1156
|
+
const tmpLog = logFile + '.tmp';
|
|
1157
|
+
writeFileSync(tmpLog, logContent);
|
|
1158
|
+
renameSync(tmpLog, logFile);
|
|
1159
|
+
}
|
|
1160
|
+
catch {
|
|
1161
|
+
// Ignore log write errors
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
// Export default
|
|
1166
|
+
export default HeadlessWorkerExecutor;
|
|
1167
|
+
//# sourceMappingURL=headless-worker-executor.js.map
|