hivemind-pipeline 0.1.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/LICENSE +63 -0
- package/README.md +352 -0
- package/dist/bin/swarm.d.ts +3 -0
- package/dist/bin/swarm.d.ts.map +1 -0
- package/dist/bin/swarm.js +293 -0
- package/dist/bin/swarm.js.map +1 -0
- package/dist/dashboard/assets/index-Cf_KwDES.js +359 -0
- package/dist/dashboard/assets/index-SatEQz0u.css +1 -0
- package/dist/dashboard/index.html +16 -0
- package/dist/prompts/Architect-Go.md +455 -0
- package/dist/prompts/Architect-Node.md +379 -0
- package/dist/prompts/Architect-Python.md +63 -0
- package/dist/prompts/Architect-React.md +352 -0
- package/dist/prompts/Architect-Rust.md +63 -0
- package/dist/prompts/Architect-Swift.md +61 -0
- package/dist/prompts/Software-engineer-go.md +254 -0
- package/dist/prompts/Software-engineer-node.md +241 -0
- package/dist/prompts/Software-engineer-python.md +70 -0
- package/dist/prompts/Software-engineer-react.md +167 -0
- package/dist/prompts/Software-engineer-rust.md +69 -0
- package/dist/prompts/Software-engineer-swift.md +69 -0
- package/dist/prompts/Software-lead-go.md +247 -0
- package/dist/prompts/Software-lead-node.md +238 -0
- package/dist/prompts/Software-lead-python.md +53 -0
- package/dist/prompts/Software-lead-react.md +229 -0
- package/dist/prompts/Software-lead-rust.md +53 -0
- package/dist/prompts/Software-lead-swift.md +53 -0
- package/dist/prompts/analyst-go.md +351 -0
- package/dist/prompts/analyst-node.md +317 -0
- package/dist/prompts/analyst-python.md +139 -0
- package/dist/prompts/analyst-react.md +428 -0
- package/dist/prompts/analyst-rust.md +125 -0
- package/dist/prompts/analyst-swift.md +125 -0
- package/dist/prompts/test-engineer-go.md +99 -0
- package/dist/prompts/test-engineer-node.md +97 -0
- package/dist/prompts/test-engineer-python.md +61 -0
- package/dist/prompts/test-engineer-react.md +104 -0
- package/dist/prompts/test-engineer-rust.md +62 -0
- package/dist/prompts/test-engineer-swift.md +66 -0
- package/dist/src/__tests__/commands/analyze.test.d.ts +2 -0
- package/dist/src/__tests__/commands/analyze.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/analyze.test.js +61 -0
- package/dist/src/__tests__/commands/analyze.test.js.map +1 -0
- package/dist/src/__tests__/commands/architect.test.d.ts +2 -0
- package/dist/src/__tests__/commands/architect.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/architect.test.js +46 -0
- package/dist/src/__tests__/commands/architect.test.js.map +1 -0
- package/dist/src/__tests__/commands/build.test.d.ts +2 -0
- package/dist/src/__tests__/commands/build.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/build.test.js +69 -0
- package/dist/src/__tests__/commands/build.test.js.map +1 -0
- package/dist/src/__tests__/commands/dashboard.test.d.ts +2 -0
- package/dist/src/__tests__/commands/dashboard.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/dashboard.test.js +95 -0
- package/dist/src/__tests__/commands/dashboard.test.js.map +1 -0
- package/dist/src/__tests__/commands/doctor.test.d.ts +2 -0
- package/dist/src/__tests__/commands/doctor.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/doctor.test.js +69 -0
- package/dist/src/__tests__/commands/doctor.test.js.map +1 -0
- package/dist/src/__tests__/commands/fix.test.d.ts +2 -0
- package/dist/src/__tests__/commands/fix.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/fix.test.js +147 -0
- package/dist/src/__tests__/commands/fix.test.js.map +1 -0
- package/dist/src/__tests__/commands/init.test.d.ts +2 -0
- package/dist/src/__tests__/commands/init.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/init.test.js +79 -0
- package/dist/src/__tests__/commands/init.test.js.map +1 -0
- package/dist/src/__tests__/commands/learn.test.d.ts +2 -0
- package/dist/src/__tests__/commands/learn.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/learn.test.js +64 -0
- package/dist/src/__tests__/commands/learn.test.js.map +1 -0
- package/dist/src/__tests__/commands/mayday.test.d.ts +2 -0
- package/dist/src/__tests__/commands/mayday.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/mayday.test.js +115 -0
- package/dist/src/__tests__/commands/mayday.test.js.map +1 -0
- package/dist/src/__tests__/commands/memory.test.d.ts +2 -0
- package/dist/src/__tests__/commands/memory.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/memory.test.js +80 -0
- package/dist/src/__tests__/commands/memory.test.js.map +1 -0
- package/dist/src/__tests__/commands/plan.test.d.ts +2 -0
- package/dist/src/__tests__/commands/plan.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/plan.test.js +46 -0
- package/dist/src/__tests__/commands/plan.test.js.map +1 -0
- package/dist/src/__tests__/commands/pr.test.d.ts +2 -0
- package/dist/src/__tests__/commands/pr.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/pr.test.js +170 -0
- package/dist/src/__tests__/commands/pr.test.js.map +1 -0
- package/dist/src/__tests__/commands/refactor.test.d.ts +2 -0
- package/dist/src/__tests__/commands/refactor.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/refactor.test.js +107 -0
- package/dist/src/__tests__/commands/refactor.test.js.map +1 -0
- package/dist/src/__tests__/commands/review.test.d.ts +2 -0
- package/dist/src/__tests__/commands/review.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/review.test.js +125 -0
- package/dist/src/__tests__/commands/review.test.js.map +1 -0
- package/dist/src/__tests__/commands/shared.test.d.ts +2 -0
- package/dist/src/__tests__/commands/shared.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/shared.test.js +112 -0
- package/dist/src/__tests__/commands/shared.test.js.map +1 -0
- package/dist/src/__tests__/commands/spike.test.d.ts +2 -0
- package/dist/src/__tests__/commands/spike.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/spike.test.js +75 -0
- package/dist/src/__tests__/commands/spike.test.js.map +1 -0
- package/dist/src/__tests__/commands/stats.test.d.ts +2 -0
- package/dist/src/__tests__/commands/stats.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/stats.test.js +82 -0
- package/dist/src/__tests__/commands/stats.test.js.map +1 -0
- package/dist/src/__tests__/commands/status.test.d.ts +2 -0
- package/dist/src/__tests__/commands/status.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/status.test.js +60 -0
- package/dist/src/__tests__/commands/status.test.js.map +1 -0
- package/dist/src/__tests__/commands/test-cmd.test.d.ts +2 -0
- package/dist/src/__tests__/commands/test-cmd.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/test-cmd.test.js +76 -0
- package/dist/src/__tests__/commands/test-cmd.test.js.map +1 -0
- package/dist/src/__tests__/commands/test-gen.test.d.ts +2 -0
- package/dist/src/__tests__/commands/test-gen.test.d.ts.map +1 -0
- package/dist/src/__tests__/commands/test-gen.test.js +151 -0
- package/dist/src/__tests__/commands/test-gen.test.js.map +1 -0
- package/dist/src/__tests__/core/agent-manager.test.d.ts +2 -0
- package/dist/src/__tests__/core/agent-manager.test.d.ts.map +1 -0
- package/dist/src/__tests__/core/agent-manager.test.js +167 -0
- package/dist/src/__tests__/core/agent-manager.test.js.map +1 -0
- package/dist/src/__tests__/core/agent-process.test.d.ts +2 -0
- package/dist/src/__tests__/core/agent-process.test.d.ts.map +1 -0
- package/dist/src/__tests__/core/agent-process.test.js +178 -0
- package/dist/src/__tests__/core/agent-process.test.js.map +1 -0
- package/dist/src/__tests__/core/guardrails.test.d.ts +2 -0
- package/dist/src/__tests__/core/guardrails.test.d.ts.map +1 -0
- package/dist/src/__tests__/core/guardrails.test.js +249 -0
- package/dist/src/__tests__/core/guardrails.test.js.map +1 -0
- package/dist/src/__tests__/core/pipeline.test.d.ts +2 -0
- package/dist/src/__tests__/core/pipeline.test.d.ts.map +1 -0
- package/dist/src/__tests__/core/pipeline.test.js +331 -0
- package/dist/src/__tests__/core/pipeline.test.js.map +1 -0
- package/dist/src/__tests__/core/state.test.d.ts +2 -0
- package/dist/src/__tests__/core/state.test.d.ts.map +1 -0
- package/dist/src/__tests__/core/state.test.js +132 -0
- package/dist/src/__tests__/core/state.test.js.map +1 -0
- package/dist/src/__tests__/core/ws-server.test.d.ts +2 -0
- package/dist/src/__tests__/core/ws-server.test.d.ts.map +1 -0
- package/dist/src/__tests__/core/ws-server.test.js +177 -0
- package/dist/src/__tests__/core/ws-server.test.js.map +1 -0
- package/dist/src/__tests__/helpers/temp-dir.d.ts +8 -0
- package/dist/src/__tests__/helpers/temp-dir.d.ts.map +1 -0
- package/dist/src/__tests__/helpers/temp-dir.js +25 -0
- package/dist/src/__tests__/helpers/temp-dir.js.map +1 -0
- package/dist/src/commands/agent.d.ts +3 -0
- package/dist/src/commands/agent.d.ts.map +1 -0
- package/dist/src/commands/agent.js +103 -0
- package/dist/src/commands/agent.js.map +1 -0
- package/dist/src/commands/allocate.d.ts +3 -0
- package/dist/src/commands/allocate.d.ts.map +1 -0
- package/dist/src/commands/allocate.js +229 -0
- package/dist/src/commands/allocate.js.map +1 -0
- package/dist/src/commands/analyze.d.ts +3 -0
- package/dist/src/commands/analyze.d.ts.map +1 -0
- package/dist/src/commands/analyze.js +63 -0
- package/dist/src/commands/analyze.js.map +1 -0
- package/dist/src/commands/architect-review.d.ts +3 -0
- package/dist/src/commands/architect-review.d.ts.map +1 -0
- package/dist/src/commands/architect-review.js +695 -0
- package/dist/src/commands/architect-review.js.map +1 -0
- package/dist/src/commands/architect.d.ts +3 -0
- package/dist/src/commands/architect.d.ts.map +1 -0
- package/dist/src/commands/architect.js +49 -0
- package/dist/src/commands/architect.js.map +1 -0
- package/dist/src/commands/audit.d.ts +3 -0
- package/dist/src/commands/audit.d.ts.map +1 -0
- package/dist/src/commands/audit.js +55 -0
- package/dist/src/commands/audit.js.map +1 -0
- package/dist/src/commands/autopilot.d.ts +7 -0
- package/dist/src/commands/autopilot.d.ts.map +1 -0
- package/dist/src/commands/autopilot.js +377 -0
- package/dist/src/commands/autopilot.js.map +1 -0
- package/dist/src/commands/babysit-prs.d.ts +13 -0
- package/dist/src/commands/babysit-prs.d.ts.map +1 -0
- package/dist/src/commands/babysit-prs.js +283 -0
- package/dist/src/commands/babysit-prs.js.map +1 -0
- package/dist/src/commands/benchmark.d.ts +34 -0
- package/dist/src/commands/benchmark.d.ts.map +1 -0
- package/dist/src/commands/benchmark.js +534 -0
- package/dist/src/commands/benchmark.js.map +1 -0
- package/dist/src/commands/build.d.ts +3 -0
- package/dist/src/commands/build.d.ts.map +1 -0
- package/dist/src/commands/build.js +63 -0
- package/dist/src/commands/build.js.map +1 -0
- package/dist/src/commands/check.d.ts +3 -0
- package/dist/src/commands/check.d.ts.map +1 -0
- package/dist/src/commands/check.js +102 -0
- package/dist/src/commands/check.js.map +1 -0
- package/dist/src/commands/ci.d.ts +3 -0
- package/dist/src/commands/ci.d.ts.map +1 -0
- package/dist/src/commands/ci.js +124 -0
- package/dist/src/commands/ci.js.map +1 -0
- package/dist/src/commands/compete.d.ts +3 -0
- package/dist/src/commands/compete.d.ts.map +1 -0
- package/dist/src/commands/compete.js +164 -0
- package/dist/src/commands/compete.js.map +1 -0
- package/dist/src/commands/compliance.d.ts +3 -0
- package/dist/src/commands/compliance.d.ts.map +1 -0
- package/dist/src/commands/compliance.js +722 -0
- package/dist/src/commands/compliance.js.map +1 -0
- package/dist/src/commands/context.d.ts +3 -0
- package/dist/src/commands/context.d.ts.map +1 -0
- package/dist/src/commands/context.js +171 -0
- package/dist/src/commands/context.js.map +1 -0
- package/dist/src/commands/contract.d.ts +3 -0
- package/dist/src/commands/contract.d.ts.map +1 -0
- package/dist/src/commands/contract.js +384 -0
- package/dist/src/commands/contract.js.map +1 -0
- package/dist/src/commands/dashboard.d.ts +3 -0
- package/dist/src/commands/dashboard.d.ts.map +1 -0
- package/dist/src/commands/dashboard.js +114 -0
- package/dist/src/commands/dashboard.js.map +1 -0
- package/dist/src/commands/delegate.d.ts +3 -0
- package/dist/src/commands/delegate.d.ts.map +1 -0
- package/dist/src/commands/delegate.js +474 -0
- package/dist/src/commands/delegate.js.map +1 -0
- package/dist/src/commands/deploy.d.ts +17 -0
- package/dist/src/commands/deploy.d.ts.map +1 -0
- package/dist/src/commands/deploy.js +163 -0
- package/dist/src/commands/deploy.js.map +1 -0
- package/dist/src/commands/deps.d.ts +3 -0
- package/dist/src/commands/deps.d.ts.map +1 -0
- package/dist/src/commands/deps.js +548 -0
- package/dist/src/commands/deps.js.map +1 -0
- package/dist/src/commands/doctor.d.ts +3 -0
- package/dist/src/commands/doctor.d.ts.map +1 -0
- package/dist/src/commands/doctor.js +120 -0
- package/dist/src/commands/doctor.js.map +1 -0
- package/dist/src/commands/empathize.d.ts +3 -0
- package/dist/src/commands/empathize.d.ts.map +1 -0
- package/dist/src/commands/empathize.js +253 -0
- package/dist/src/commands/empathize.js.map +1 -0
- package/dist/src/commands/evaluate.d.ts +3 -0
- package/dist/src/commands/evaluate.d.ts.map +1 -0
- package/dist/src/commands/evaluate.js +49 -0
- package/dist/src/commands/evaluate.js.map +1 -0
- package/dist/src/commands/evolve.d.ts +3 -0
- package/dist/src/commands/evolve.d.ts.map +1 -0
- package/dist/src/commands/evolve.js +841 -0
- package/dist/src/commands/evolve.js.map +1 -0
- package/dist/src/commands/experiment.d.ts +3 -0
- package/dist/src/commands/experiment.d.ts.map +1 -0
- package/dist/src/commands/experiment.js +286 -0
- package/dist/src/commands/experiment.js.map +1 -0
- package/dist/src/commands/explain.d.ts +3 -0
- package/dist/src/commands/explain.d.ts.map +1 -0
- package/dist/src/commands/explain.js +159 -0
- package/dist/src/commands/explain.js.map +1 -0
- package/dist/src/commands/federate.d.ts +3 -0
- package/dist/src/commands/federate.d.ts.map +1 -0
- package/dist/src/commands/federate.js +148 -0
- package/dist/src/commands/federate.js.map +1 -0
- package/dist/src/commands/fingerprint.d.ts +3 -0
- package/dist/src/commands/fingerprint.d.ts.map +1 -0
- package/dist/src/commands/fingerprint.js +65 -0
- package/dist/src/commands/fingerprint.js.map +1 -0
- package/dist/src/commands/fix.d.ts +3 -0
- package/dist/src/commands/fix.d.ts.map +1 -0
- package/dist/src/commands/fix.js +160 -0
- package/dist/src/commands/fix.js.map +1 -0
- package/dist/src/commands/fleet.d.ts +3 -0
- package/dist/src/commands/fleet.d.ts.map +1 -0
- package/dist/src/commands/fleet.js +311 -0
- package/dist/src/commands/fleet.js.map +1 -0
- package/dist/src/commands/forecast.d.ts +3 -0
- package/dist/src/commands/forecast.d.ts.map +1 -0
- package/dist/src/commands/forecast.js +522 -0
- package/dist/src/commands/forecast.js.map +1 -0
- package/dist/src/commands/govern.d.ts +3 -0
- package/dist/src/commands/govern.d.ts.map +1 -0
- package/dist/src/commands/govern.js +280 -0
- package/dist/src/commands/govern.js.map +1 -0
- package/dist/src/commands/health.d.ts +17 -0
- package/dist/src/commands/health.d.ts.map +1 -0
- package/dist/src/commands/health.js +491 -0
- package/dist/src/commands/health.js.map +1 -0
- package/dist/src/commands/impact.d.ts +3 -0
- package/dist/src/commands/impact.d.ts.map +1 -0
- package/dist/src/commands/impact.js +186 -0
- package/dist/src/commands/impact.js.map +1 -0
- package/dist/src/commands/improve.d.ts +3 -0
- package/dist/src/commands/improve.d.ts.map +1 -0
- package/dist/src/commands/improve.js +240 -0
- package/dist/src/commands/improve.js.map +1 -0
- package/dist/src/commands/inbox.d.ts +29 -0
- package/dist/src/commands/inbox.d.ts.map +1 -0
- package/dist/src/commands/inbox.js +538 -0
- package/dist/src/commands/inbox.js.map +1 -0
- package/dist/src/commands/incident.d.ts +15 -0
- package/dist/src/commands/incident.d.ts.map +1 -0
- package/dist/src/commands/incident.js +318 -0
- package/dist/src/commands/incident.js.map +1 -0
- package/dist/src/commands/init.d.ts +3 -0
- package/dist/src/commands/init.d.ts.map +1 -0
- package/dist/src/commands/init.js +97 -0
- package/dist/src/commands/init.js.map +1 -0
- package/dist/src/commands/journal.d.ts +3 -0
- package/dist/src/commands/journal.d.ts.map +1 -0
- package/dist/src/commands/journal.js +146 -0
- package/dist/src/commands/journal.js.map +1 -0
- package/dist/src/commands/learn.d.ts +9 -0
- package/dist/src/commands/learn.d.ts.map +1 -0
- package/dist/src/commands/learn.js +107 -0
- package/dist/src/commands/learn.js.map +1 -0
- package/dist/src/commands/mayday.d.ts +3 -0
- package/dist/src/commands/mayday.d.ts.map +1 -0
- package/dist/src/commands/mayday.js +145 -0
- package/dist/src/commands/mayday.js.map +1 -0
- package/dist/src/commands/memory.d.ts +3 -0
- package/dist/src/commands/memory.d.ts.map +1 -0
- package/dist/src/commands/memory.js +113 -0
- package/dist/src/commands/memory.js.map +1 -0
- package/dist/src/commands/mentor.d.ts +3 -0
- package/dist/src/commands/mentor.d.ts.map +1 -0
- package/dist/src/commands/mentor.js +225 -0
- package/dist/src/commands/mentor.js.map +1 -0
- package/dist/src/commands/migrate.d.ts +3 -0
- package/dist/src/commands/migrate.d.ts.map +1 -0
- package/dist/src/commands/migrate.js +169 -0
- package/dist/src/commands/migrate.js.map +1 -0
- package/dist/src/commands/models.d.ts +3 -0
- package/dist/src/commands/models.d.ts.map +1 -0
- package/dist/src/commands/models.js +396 -0
- package/dist/src/commands/models.js.map +1 -0
- package/dist/src/commands/multi-repo.d.ts +18 -0
- package/dist/src/commands/multi-repo.d.ts.map +1 -0
- package/dist/src/commands/multi-repo.js +423 -0
- package/dist/src/commands/multi-repo.js.map +1 -0
- package/dist/src/commands/negotiate.d.ts +3 -0
- package/dist/src/commands/negotiate.d.ts.map +1 -0
- package/dist/src/commands/negotiate.js +239 -0
- package/dist/src/commands/negotiate.js.map +1 -0
- package/dist/src/commands/observe.d.ts +3 -0
- package/dist/src/commands/observe.d.ts.map +1 -0
- package/dist/src/commands/observe.js +445 -0
- package/dist/src/commands/observe.js.map +1 -0
- package/dist/src/commands/onboard.d.ts +3 -0
- package/dist/src/commands/onboard.d.ts.map +1 -0
- package/dist/src/commands/onboard.js +263 -0
- package/dist/src/commands/onboard.js.map +1 -0
- package/dist/src/commands/optimize.d.ts +3 -0
- package/dist/src/commands/optimize.d.ts.map +1 -0
- package/dist/src/commands/optimize.js +340 -0
- package/dist/src/commands/optimize.js.map +1 -0
- package/dist/src/commands/own.d.ts +3 -0
- package/dist/src/commands/own.d.ts.map +1 -0
- package/dist/src/commands/own.js +499 -0
- package/dist/src/commands/own.js.map +1 -0
- package/dist/src/commands/pair.d.ts +3 -0
- package/dist/src/commands/pair.d.ts.map +1 -0
- package/dist/src/commands/pair.js +206 -0
- package/dist/src/commands/pair.js.map +1 -0
- package/dist/src/commands/pipeline.d.ts +3 -0
- package/dist/src/commands/pipeline.d.ts.map +1 -0
- package/dist/src/commands/pipeline.js +143 -0
- package/dist/src/commands/pipeline.js.map +1 -0
- package/dist/src/commands/plan.d.ts +3 -0
- package/dist/src/commands/plan.d.ts.map +1 -0
- package/dist/src/commands/plan.js +49 -0
- package/dist/src/commands/plan.js.map +1 -0
- package/dist/src/commands/plugin.d.ts +3 -0
- package/dist/src/commands/plugin.d.ts.map +1 -0
- package/dist/src/commands/plugin.js +114 -0
- package/dist/src/commands/plugin.js.map +1 -0
- package/dist/src/commands/pm.d.ts +38 -0
- package/dist/src/commands/pm.d.ts.map +1 -0
- package/dist/src/commands/pm.js +664 -0
- package/dist/src/commands/pm.js.map +1 -0
- package/dist/src/commands/pr.d.ts +3 -0
- package/dist/src/commands/pr.d.ts.map +1 -0
- package/dist/src/commands/pr.js +225 -0
- package/dist/src/commands/pr.js.map +1 -0
- package/dist/src/commands/prompt-guard.d.ts +3 -0
- package/dist/src/commands/prompt-guard.d.ts.map +1 -0
- package/dist/src/commands/prompt-guard.js +54 -0
- package/dist/src/commands/prompt-guard.js.map +1 -0
- package/dist/src/commands/provenance.d.ts +3 -0
- package/dist/src/commands/provenance.d.ts.map +1 -0
- package/dist/src/commands/provenance.js +96 -0
- package/dist/src/commands/provenance.js.map +1 -0
- package/dist/src/commands/recover.d.ts +3 -0
- package/dist/src/commands/recover.d.ts.map +1 -0
- package/dist/src/commands/recover.js +32 -0
- package/dist/src/commands/recover.js.map +1 -0
- package/dist/src/commands/refactor.d.ts +3 -0
- package/dist/src/commands/refactor.d.ts.map +1 -0
- package/dist/src/commands/refactor.js +143 -0
- package/dist/src/commands/refactor.js.map +1 -0
- package/dist/src/commands/report.d.ts +66 -0
- package/dist/src/commands/report.d.ts.map +1 -0
- package/dist/src/commands/report.js +493 -0
- package/dist/src/commands/report.js.map +1 -0
- package/dist/src/commands/retro.d.ts +71 -0
- package/dist/src/commands/retro.d.ts.map +1 -0
- package/dist/src/commands/retro.js +449 -0
- package/dist/src/commands/retro.js.map +1 -0
- package/dist/src/commands/review.d.ts +3 -0
- package/dist/src/commands/review.d.ts.map +1 -0
- package/dist/src/commands/review.js +202 -0
- package/dist/src/commands/review.js.map +1 -0
- package/dist/src/commands/risk.d.ts +3 -0
- package/dist/src/commands/risk.d.ts.map +1 -0
- package/dist/src/commands/risk.js +110 -0
- package/dist/src/commands/risk.js.map +1 -0
- package/dist/src/commands/roadmap.d.ts +3 -0
- package/dist/src/commands/roadmap.d.ts.map +1 -0
- package/dist/src/commands/roadmap.js +506 -0
- package/dist/src/commands/roadmap.js.map +1 -0
- package/dist/src/commands/runtime-monitor.d.ts +3 -0
- package/dist/src/commands/runtime-monitor.d.ts.map +1 -0
- package/dist/src/commands/runtime-monitor.js +154 -0
- package/dist/src/commands/runtime-monitor.js.map +1 -0
- package/dist/src/commands/sandbox.d.ts +3 -0
- package/dist/src/commands/sandbox.d.ts.map +1 -0
- package/dist/src/commands/sandbox.js +201 -0
- package/dist/src/commands/sandbox.js.map +1 -0
- package/dist/src/commands/scope.d.ts +3 -0
- package/dist/src/commands/scope.d.ts.map +1 -0
- package/dist/src/commands/scope.js +192 -0
- package/dist/src/commands/scope.js.map +1 -0
- package/dist/src/commands/secrets.d.ts +3 -0
- package/dist/src/commands/secrets.d.ts.map +1 -0
- package/dist/src/commands/secrets.js +99 -0
- package/dist/src/commands/secrets.js.map +1 -0
- package/dist/src/commands/secure.d.ts +3 -0
- package/dist/src/commands/secure.d.ts.map +1 -0
- package/dist/src/commands/secure.js +215 -0
- package/dist/src/commands/secure.js.map +1 -0
- package/dist/src/commands/server.d.ts +3 -0
- package/dist/src/commands/server.d.ts.map +1 -0
- package/dist/src/commands/server.js +228 -0
- package/dist/src/commands/server.js.map +1 -0
- package/dist/src/commands/shared.d.ts +18 -0
- package/dist/src/commands/shared.d.ts.map +1 -0
- package/dist/src/commands/shared.js +61 -0
- package/dist/src/commands/shared.js.map +1 -0
- package/dist/src/commands/simplify.d.ts +3 -0
- package/dist/src/commands/simplify.d.ts.map +1 -0
- package/dist/src/commands/simplify.js +194 -0
- package/dist/src/commands/simplify.js.map +1 -0
- package/dist/src/commands/simulate.d.ts +3 -0
- package/dist/src/commands/simulate.d.ts.map +1 -0
- package/dist/src/commands/simulate.js +275 -0
- package/dist/src/commands/simulate.js.map +1 -0
- package/dist/src/commands/slo.d.ts +3 -0
- package/dist/src/commands/slo.d.ts.map +1 -0
- package/dist/src/commands/slo.js +341 -0
- package/dist/src/commands/slo.js.map +1 -0
- package/dist/src/commands/spawn-capability.d.ts +3 -0
- package/dist/src/commands/spawn-capability.d.ts.map +1 -0
- package/dist/src/commands/spawn-capability.js +153 -0
- package/dist/src/commands/spawn-capability.js.map +1 -0
- package/dist/src/commands/specialize.d.ts +3 -0
- package/dist/src/commands/specialize.d.ts.map +1 -0
- package/dist/src/commands/specialize.js +266 -0
- package/dist/src/commands/specialize.js.map +1 -0
- package/dist/src/commands/spike.d.ts +3 -0
- package/dist/src/commands/spike.d.ts.map +1 -0
- package/dist/src/commands/spike.js +109 -0
- package/dist/src/commands/spike.js.map +1 -0
- package/dist/src/commands/standup.d.ts +3 -0
- package/dist/src/commands/standup.d.ts.map +1 -0
- package/dist/src/commands/standup.js +76 -0
- package/dist/src/commands/standup.js.map +1 -0
- package/dist/src/commands/stats.d.ts +39 -0
- package/dist/src/commands/stats.d.ts.map +1 -0
- package/dist/src/commands/stats.js +185 -0
- package/dist/src/commands/stats.js.map +1 -0
- package/dist/src/commands/status.d.ts +3 -0
- package/dist/src/commands/status.d.ts.map +1 -0
- package/dist/src/commands/status.js +65 -0
- package/dist/src/commands/status.js.map +1 -0
- package/dist/src/commands/supply-chain.d.ts +3 -0
- package/dist/src/commands/supply-chain.d.ts.map +1 -0
- package/dist/src/commands/supply-chain.js +110 -0
- package/dist/src/commands/supply-chain.js.map +1 -0
- package/dist/src/commands/system.d.ts +3 -0
- package/dist/src/commands/system.d.ts.map +1 -0
- package/dist/src/commands/system.js +582 -0
- package/dist/src/commands/system.js.map +1 -0
- package/dist/src/commands/teach.d.ts +3 -0
- package/dist/src/commands/teach.d.ts.map +1 -0
- package/dist/src/commands/teach.js +420 -0
- package/dist/src/commands/teach.js.map +1 -0
- package/dist/src/commands/team.d.ts +44 -0
- package/dist/src/commands/team.d.ts.map +1 -0
- package/dist/src/commands/team.js +355 -0
- package/dist/src/commands/team.js.map +1 -0
- package/dist/src/commands/telemetry.d.ts +3 -0
- package/dist/src/commands/telemetry.d.ts.map +1 -0
- package/dist/src/commands/telemetry.js +87 -0
- package/dist/src/commands/telemetry.js.map +1 -0
- package/dist/src/commands/test-gen.d.ts +3 -0
- package/dist/src/commands/test-gen.d.ts.map +1 -0
- package/dist/src/commands/test-gen.js +541 -0
- package/dist/src/commands/test-gen.js.map +1 -0
- package/dist/src/commands/test.d.ts +3 -0
- package/dist/src/commands/test.d.ts.map +1 -0
- package/dist/src/commands/test.js +84 -0
- package/dist/src/commands/test.js.map +1 -0
- package/dist/src/commands/watch.d.ts +11 -0
- package/dist/src/commands/watch.d.ts.map +1 -0
- package/dist/src/commands/watch.js +317 -0
- package/dist/src/commands/watch.js.map +1 -0
- package/dist/src/core/activity-tracker.d.ts +70 -0
- package/dist/src/core/activity-tracker.d.ts.map +1 -0
- package/dist/src/core/activity-tracker.js +294 -0
- package/dist/src/core/activity-tracker.js.map +1 -0
- package/dist/src/core/agent-bus.d.ts +38 -0
- package/dist/src/core/agent-bus.d.ts.map +1 -0
- package/dist/src/core/agent-bus.js +128 -0
- package/dist/src/core/agent-bus.js.map +1 -0
- package/dist/src/core/agent-loop.d.ts +79 -0
- package/dist/src/core/agent-loop.d.ts.map +1 -0
- package/dist/src/core/agent-loop.js +225 -0
- package/dist/src/core/agent-loop.js.map +1 -0
- package/dist/src/core/agent-manager.d.ts +90 -0
- package/dist/src/core/agent-manager.d.ts.map +1 -0
- package/dist/src/core/agent-manager.js +549 -0
- package/dist/src/core/agent-manager.js.map +1 -0
- package/dist/src/core/agent-process.d.ts +95 -0
- package/dist/src/core/agent-process.d.ts.map +1 -0
- package/dist/src/core/agent-process.js +428 -0
- package/dist/src/core/agent-process.js.map +1 -0
- package/dist/src/core/ambiguity-detector.d.ts +31 -0
- package/dist/src/core/ambiguity-detector.d.ts.map +1 -0
- package/dist/src/core/ambiguity-detector.js +286 -0
- package/dist/src/core/ambiguity-detector.js.map +1 -0
- package/dist/src/core/anomaly-detector.d.ts +30 -0
- package/dist/src/core/anomaly-detector.d.ts.map +1 -0
- package/dist/src/core/anomaly-detector.js +300 -0
- package/dist/src/core/anomaly-detector.js.map +1 -0
- package/dist/src/core/api-lifecycle.d.ts +11 -0
- package/dist/src/core/api-lifecycle.d.ts.map +1 -0
- package/dist/src/core/api-lifecycle.js +178 -0
- package/dist/src/core/api-lifecycle.js.map +1 -0
- package/dist/src/core/audit.d.ts +36 -0
- package/dist/src/core/audit.d.ts.map +1 -0
- package/dist/src/core/audit.js +88 -0
- package/dist/src/core/audit.js.map +1 -0
- package/dist/src/core/capability-spawner.d.ts +17 -0
- package/dist/src/core/capability-spawner.d.ts.map +1 -0
- package/dist/src/core/capability-spawner.js +170 -0
- package/dist/src/core/capability-spawner.js.map +1 -0
- package/dist/src/core/codebase-index.d.ts +53 -0
- package/dist/src/core/codebase-index.d.ts.map +1 -0
- package/dist/src/core/codebase-index.js +540 -0
- package/dist/src/core/codebase-index.js.map +1 -0
- package/dist/src/core/codebase-scanner.d.ts +3 -0
- package/dist/src/core/codebase-scanner.d.ts.map +1 -0
- package/dist/src/core/codebase-scanner.js +179 -0
- package/dist/src/core/codebase-scanner.js.map +1 -0
- package/dist/src/core/competitive-intel.d.ts +18 -0
- package/dist/src/core/competitive-intel.d.ts.map +1 -0
- package/dist/src/core/competitive-intel.js +167 -0
- package/dist/src/core/competitive-intel.js.map +1 -0
- package/dist/src/core/config.d.ts +14 -0
- package/dist/src/core/config.d.ts.map +1 -0
- package/dist/src/core/config.js +116 -0
- package/dist/src/core/config.js.map +1 -0
- package/dist/src/core/convention-extractor.d.ts +8 -0
- package/dist/src/core/convention-extractor.d.ts.map +1 -0
- package/dist/src/core/convention-extractor.js +382 -0
- package/dist/src/core/convention-extractor.js.map +1 -0
- package/dist/src/core/cost-tracker.d.ts +23 -0
- package/dist/src/core/cost-tracker.d.ts.map +1 -0
- package/dist/src/core/cost-tracker.js +83 -0
- package/dist/src/core/cost-tracker.js.map +1 -0
- package/dist/src/core/decision-journal.d.ts +41 -0
- package/dist/src/core/decision-journal.d.ts.map +1 -0
- package/dist/src/core/decision-journal.js +204 -0
- package/dist/src/core/decision-journal.js.map +1 -0
- package/dist/src/core/experiment-engine.d.ts +31 -0
- package/dist/src/core/experiment-engine.d.ts.map +1 -0
- package/dist/src/core/experiment-engine.js +248 -0
- package/dist/src/core/experiment-engine.js.map +1 -0
- package/dist/src/core/federation.d.ts +18 -0
- package/dist/src/core/federation.d.ts.map +1 -0
- package/dist/src/core/federation.js +202 -0
- package/dist/src/core/federation.js.map +1 -0
- package/dist/src/core/fingerprint.d.ts +42 -0
- package/dist/src/core/fingerprint.d.ts.map +1 -0
- package/dist/src/core/fingerprint.js +316 -0
- package/dist/src/core/fingerprint.js.map +1 -0
- package/dist/src/core/git.d.ts +50 -0
- package/dist/src/core/git.d.ts.map +1 -0
- package/dist/src/core/git.js +342 -0
- package/dist/src/core/git.js.map +1 -0
- package/dist/src/core/governance.d.ts +53 -0
- package/dist/src/core/governance.d.ts.map +1 -0
- package/dist/src/core/governance.js +276 -0
- package/dist/src/core/governance.js.map +1 -0
- package/dist/src/core/guardrails.d.ts +34 -0
- package/dist/src/core/guardrails.d.ts.map +1 -0
- package/dist/src/core/guardrails.js +575 -0
- package/dist/src/core/guardrails.js.map +1 -0
- package/dist/src/core/impact-analyzer.d.ts +56 -0
- package/dist/src/core/impact-analyzer.d.ts.map +1 -0
- package/dist/src/core/impact-analyzer.js +309 -0
- package/dist/src/core/impact-analyzer.js.map +1 -0
- package/dist/src/core/input-listener.d.ts +45 -0
- package/dist/src/core/input-listener.d.ts.map +1 -0
- package/dist/src/core/input-listener.js +116 -0
- package/dist/src/core/input-listener.js.map +1 -0
- package/dist/src/core/memory-store.d.ts +61 -0
- package/dist/src/core/memory-store.d.ts.map +1 -0
- package/dist/src/core/memory-store.js +195 -0
- package/dist/src/core/memory-store.js.map +1 -0
- package/dist/src/core/observability.d.ts +56 -0
- package/dist/src/core/observability.d.ts.map +1 -0
- package/dist/src/core/observability.js +305 -0
- package/dist/src/core/observability.js.map +1 -0
- package/dist/src/core/pair-engine.d.ts +47 -0
- package/dist/src/core/pair-engine.d.ts.map +1 -0
- package/dist/src/core/pair-engine.js +355 -0
- package/dist/src/core/pair-engine.js.map +1 -0
- package/dist/src/core/perf-analyzer.d.ts +35 -0
- package/dist/src/core/perf-analyzer.d.ts.map +1 -0
- package/dist/src/core/perf-analyzer.js +598 -0
- package/dist/src/core/perf-analyzer.js.map +1 -0
- package/dist/src/core/pipeline-loader.d.ts +46 -0
- package/dist/src/core/pipeline-loader.d.ts.map +1 -0
- package/dist/src/core/pipeline-loader.js +182 -0
- package/dist/src/core/pipeline-loader.js.map +1 -0
- package/dist/src/core/pipeline.d.ts +183 -0
- package/dist/src/core/pipeline.d.ts.map +1 -0
- package/dist/src/core/pipeline.js +2264 -0
- package/dist/src/core/pipeline.js.map +1 -0
- package/dist/src/core/plugins.d.ts +61 -0
- package/dist/src/core/plugins.d.ts.map +1 -0
- package/dist/src/core/plugins.js +114 -0
- package/dist/src/core/plugins.js.map +1 -0
- package/dist/src/core/preflight.d.ts +7 -0
- package/dist/src/core/preflight.d.ts.map +1 -0
- package/dist/src/core/preflight.js +35 -0
- package/dist/src/core/preflight.js.map +1 -0
- package/dist/src/core/prompt-guard.d.ts +44 -0
- package/dist/src/core/prompt-guard.d.ts.map +1 -0
- package/dist/src/core/prompt-guard.js +274 -0
- package/dist/src/core/prompt-guard.js.map +1 -0
- package/dist/src/core/provenance.d.ts +39 -0
- package/dist/src/core/provenance.d.ts.map +1 -0
- package/dist/src/core/provenance.js +115 -0
- package/dist/src/core/provenance.js.map +1 -0
- package/dist/src/core/providers/anthropic-api.d.ts +34 -0
- package/dist/src/core/providers/anthropic-api.d.ts.map +1 -0
- package/dist/src/core/providers/anthropic-api.js +522 -0
- package/dist/src/core/providers/anthropic-api.js.map +1 -0
- package/dist/src/core/providers/api-agent-backend.d.ts +31 -0
- package/dist/src/core/providers/api-agent-backend.d.ts.map +1 -0
- package/dist/src/core/providers/api-agent-backend.js +127 -0
- package/dist/src/core/providers/api-agent-backend.js.map +1 -0
- package/dist/src/core/providers/api-text-backend.d.ts +35 -0
- package/dist/src/core/providers/api-text-backend.d.ts.map +1 -0
- package/dist/src/core/providers/api-text-backend.js +145 -0
- package/dist/src/core/providers/api-text-backend.js.map +1 -0
- package/dist/src/core/providers/claude-cli.d.ts +80 -0
- package/dist/src/core/providers/claude-cli.d.ts.map +1 -0
- package/dist/src/core/providers/claude-cli.js +489 -0
- package/dist/src/core/providers/claude-cli.js.map +1 -0
- package/dist/src/core/providers/cost-table.d.ts +46 -0
- package/dist/src/core/providers/cost-table.d.ts.map +1 -0
- package/dist/src/core/providers/cost-table.js +136 -0
- package/dist/src/core/providers/cost-table.js.map +1 -0
- package/dist/src/core/providers/google.d.ts +26 -0
- package/dist/src/core/providers/google.d.ts.map +1 -0
- package/dist/src/core/providers/google.js +165 -0
- package/dist/src/core/providers/google.js.map +1 -0
- package/dist/src/core/providers/model-catalog.d.ts +72 -0
- package/dist/src/core/providers/model-catalog.d.ts.map +1 -0
- package/dist/src/core/providers/model-catalog.js +290 -0
- package/dist/src/core/providers/model-catalog.js.map +1 -0
- package/dist/src/core/providers/openai-compat.d.ts +35 -0
- package/dist/src/core/providers/openai-compat.d.ts.map +1 -0
- package/dist/src/core/providers/openai-compat.js +479 -0
- package/dist/src/core/providers/openai-compat.js.map +1 -0
- package/dist/src/core/providers/prompt-adapter.d.ts +42 -0
- package/dist/src/core/providers/prompt-adapter.d.ts.map +1 -0
- package/dist/src/core/providers/prompt-adapter.js +282 -0
- package/dist/src/core/providers/prompt-adapter.js.map +1 -0
- package/dist/src/core/providers/registry.d.ts +93 -0
- package/dist/src/core/providers/registry.d.ts.map +1 -0
- package/dist/src/core/providers/registry.js +191 -0
- package/dist/src/core/providers/registry.js.map +1 -0
- package/dist/src/core/providers/types.d.ts +165 -0
- package/dist/src/core/providers/types.d.ts.map +1 -0
- package/dist/src/core/providers/types.js +13 -0
- package/dist/src/core/providers/types.js.map +1 -0
- package/dist/src/core/quality.d.ts +22 -0
- package/dist/src/core/quality.d.ts.map +1 -0
- package/dist/src/core/quality.js +209 -0
- package/dist/src/core/quality.js.map +1 -0
- package/dist/src/core/resource-allocator.d.ts +37 -0
- package/dist/src/core/resource-allocator.d.ts.map +1 -0
- package/dist/src/core/resource-allocator.js +480 -0
- package/dist/src/core/resource-allocator.js.map +1 -0
- package/dist/src/core/risk-scorer.d.ts +35 -0
- package/dist/src/core/risk-scorer.d.ts.map +1 -0
- package/dist/src/core/risk-scorer.js +226 -0
- package/dist/src/core/risk-scorer.js.map +1 -0
- package/dist/src/core/runtime-monitor.d.ts +49 -0
- package/dist/src/core/runtime-monitor.d.ts.map +1 -0
- package/dist/src/core/runtime-monitor.js +235 -0
- package/dist/src/core/runtime-monitor.js.map +1 -0
- package/dist/src/core/sandbox.d.ts +47 -0
- package/dist/src/core/sandbox.d.ts.map +1 -0
- package/dist/src/core/sandbox.js +277 -0
- package/dist/src/core/sandbox.js.map +1 -0
- package/dist/src/core/secret-detector.d.ts +25 -0
- package/dist/src/core/secret-detector.d.ts.map +1 -0
- package/dist/src/core/secret-detector.js +307 -0
- package/dist/src/core/secret-detector.js.map +1 -0
- package/dist/src/core/security-scanner.d.ts +36 -0
- package/dist/src/core/security-scanner.d.ts.map +1 -0
- package/dist/src/core/security-scanner.js +366 -0
- package/dist/src/core/security-scanner.js.map +1 -0
- package/dist/src/core/self-improvement.d.ts +26 -0
- package/dist/src/core/self-improvement.d.ts.map +1 -0
- package/dist/src/core/self-improvement.js +356 -0
- package/dist/src/core/self-improvement.js.map +1 -0
- package/dist/src/core/simulator.d.ts +28 -0
- package/dist/src/core/simulator.d.ts.map +1 -0
- package/dist/src/core/simulator.js +334 -0
- package/dist/src/core/simulator.js.map +1 -0
- package/dist/src/core/specialization.d.ts +47 -0
- package/dist/src/core/specialization.d.ts.map +1 -0
- package/dist/src/core/specialization.js +239 -0
- package/dist/src/core/specialization.js.map +1 -0
- package/dist/src/core/stakeholder-engine.d.ts +47 -0
- package/dist/src/core/stakeholder-engine.d.ts.map +1 -0
- package/dist/src/core/stakeholder-engine.js +380 -0
- package/dist/src/core/stakeholder-engine.js.map +1 -0
- package/dist/src/core/state.d.ts +99 -0
- package/dist/src/core/state.d.ts.map +1 -0
- package/dist/src/core/state.js +545 -0
- package/dist/src/core/state.js.map +1 -0
- package/dist/src/core/supply-chain.d.ts +26 -0
- package/dist/src/core/supply-chain.d.ts.map +1 -0
- package/dist/src/core/supply-chain.js +332 -0
- package/dist/src/core/supply-chain.js.map +1 -0
- package/dist/src/core/telemetry.d.ts +110 -0
- package/dist/src/core/telemetry.d.ts.map +1 -0
- package/dist/src/core/telemetry.js +276 -0
- package/dist/src/core/telemetry.js.map +1 -0
- package/dist/src/core/tools/definitions.d.ts +10 -0
- package/dist/src/core/tools/definitions.d.ts.map +1 -0
- package/dist/src/core/tools/definitions.js +165 -0
- package/dist/src/core/tools/definitions.js.map +1 -0
- package/dist/src/core/tools/executor.d.ts +27 -0
- package/dist/src/core/tools/executor.d.ts.map +1 -0
- package/dist/src/core/tools/executor.js +306 -0
- package/dist/src/core/tools/executor.js.map +1 -0
- package/dist/src/core/tools/sandbox.d.ts +41 -0
- package/dist/src/core/tools/sandbox.d.ts.map +1 -0
- package/dist/src/core/tools/sandbox.js +106 -0
- package/dist/src/core/tools/sandbox.js.map +1 -0
- package/dist/src/core/training-pipeline.d.ts +66 -0
- package/dist/src/core/training-pipeline.d.ts.map +1 -0
- package/dist/src/core/training-pipeline.js +267 -0
- package/dist/src/core/training-pipeline.js.map +1 -0
- package/dist/src/core/triage.d.ts +56 -0
- package/dist/src/core/triage.d.ts.map +1 -0
- package/dist/src/core/triage.js +227 -0
- package/dist/src/core/triage.js.map +1 -0
- package/dist/src/core/user-intelligence.d.ts +29 -0
- package/dist/src/core/user-intelligence.d.ts.map +1 -0
- package/dist/src/core/user-intelligence.js +172 -0
- package/dist/src/core/user-intelligence.js.map +1 -0
- package/dist/src/core/webhooks.d.ts +32 -0
- package/dist/src/core/webhooks.d.ts.map +1 -0
- package/dist/src/core/webhooks.js +126 -0
- package/dist/src/core/webhooks.js.map +1 -0
- package/dist/src/core/ws-server.d.ts +43 -0
- package/dist/src/core/ws-server.d.ts.map +1 -0
- package/dist/src/core/ws-server.js +3278 -0
- package/dist/src/core/ws-server.js.map +1 -0
- package/dist/src/prompts/loader.d.ts +36 -0
- package/dist/src/prompts/loader.d.ts.map +1 -0
- package/dist/src/prompts/loader.js +156 -0
- package/dist/src/prompts/loader.js.map +1 -0
- package/dist/src/types.d.ts +2539 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +62 -0
- package/dist/src/types.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { execSync } from 'node:child_process';
|
|
2
|
+
import { readdirSync, statSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
const RISK_KEYWORDS = ['auth', 'payment', 'billing', 'database', 'migration', 'deploy', 'security', 'delete', 'remove'];
|
|
5
|
+
const GENERIC_TERMS = ['add', 'fix', 'update', 'change', 'improve', 'make', 'do', 'create', 'build', 'handle'];
|
|
6
|
+
const SPECIFIC_INDICATORS = ['.ts', '.tsx', '.js', '.py', '.go', '.rs', 'function', 'class', 'component', 'endpoint', 'api', 'route', 'hook', 'middleware', 'handler', 'service', 'module'];
|
|
7
|
+
function countProjectFiles(cwd) {
|
|
8
|
+
try {
|
|
9
|
+
const output = execSync('git ls-files | wc -l', { cwd, encoding: 'utf-8', timeout: 5000 }).trim();
|
|
10
|
+
return parseInt(output, 10) || 0;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
// Fallback: count files in top-level dirs (shallow)
|
|
14
|
+
try {
|
|
15
|
+
let count = 0;
|
|
16
|
+
const entries = readdirSync(cwd);
|
|
17
|
+
for (const entry of entries) {
|
|
18
|
+
if (entry.startsWith('.') || entry === 'node_modules' || entry === 'dist')
|
|
19
|
+
continue;
|
|
20
|
+
try {
|
|
21
|
+
const st = statSync(join(cwd, entry));
|
|
22
|
+
if (st.isFile())
|
|
23
|
+
count++;
|
|
24
|
+
else if (st.isDirectory()) {
|
|
25
|
+
count += readdirSync(join(cwd, entry)).length;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch { /* skip */ }
|
|
29
|
+
}
|
|
30
|
+
return count;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return 50; // fallback estimate
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function scoreVagueness(request) {
|
|
38
|
+
let score = 0;
|
|
39
|
+
const lower = request.toLowerCase().trim();
|
|
40
|
+
const words = lower.split(/\s+/);
|
|
41
|
+
// Short requests are vague
|
|
42
|
+
if (lower.length < 20)
|
|
43
|
+
score += 35;
|
|
44
|
+
else if (lower.length < 50)
|
|
45
|
+
score += 20;
|
|
46
|
+
else if (lower.length < 100)
|
|
47
|
+
score += 10;
|
|
48
|
+
// Word count
|
|
49
|
+
if (words.length < 5)
|
|
50
|
+
score += 20;
|
|
51
|
+
else if (words.length < 10)
|
|
52
|
+
score += 10;
|
|
53
|
+
// Generic verbs without specifics
|
|
54
|
+
const startsWithGeneric = GENERIC_TERMS.some(t => lower.startsWith(t));
|
|
55
|
+
if (startsWithGeneric)
|
|
56
|
+
score += 10;
|
|
57
|
+
const genericCount = words.filter(w => GENERIC_TERMS.includes(w)).length;
|
|
58
|
+
score += Math.min(genericCount * 5, 15);
|
|
59
|
+
// Specific indicators reduce vagueness
|
|
60
|
+
const specificCount = SPECIFIC_INDICATORS.filter(s => lower.includes(s)).length;
|
|
61
|
+
score -= Math.min(specificCount * 8, 30);
|
|
62
|
+
// No file/path mentions = more vague
|
|
63
|
+
const hasPath = /[\/\\]/.test(request) || /\.\w{1,4}$/.test(request.trim());
|
|
64
|
+
if (!hasPath)
|
|
65
|
+
score += 10;
|
|
66
|
+
return Math.max(0, Math.min(100, score));
|
|
67
|
+
}
|
|
68
|
+
function detectRiskFactors(request) {
|
|
69
|
+
const lower = request.toLowerCase();
|
|
70
|
+
const factors = [];
|
|
71
|
+
for (const keyword of RISK_KEYWORDS) {
|
|
72
|
+
if (lower.includes(keyword)) {
|
|
73
|
+
const descriptions = {
|
|
74
|
+
auth: 'Authentication changes can break user access',
|
|
75
|
+
payment: 'Payment logic is business-critical and legally sensitive',
|
|
76
|
+
billing: 'Billing changes affect revenue and compliance',
|
|
77
|
+
database: 'Database changes can cause data loss if not migrated properly',
|
|
78
|
+
migration: 'Migrations are destructive and hard to reverse',
|
|
79
|
+
deploy: 'Deployment changes affect production availability',
|
|
80
|
+
security: 'Security changes require careful review',
|
|
81
|
+
delete: 'Deletion operations can cause permanent data loss',
|
|
82
|
+
remove: 'Removal operations can break dependent features',
|
|
83
|
+
};
|
|
84
|
+
factors.push(descriptions[keyword] || `Involves ${keyword} — requires careful review`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return factors;
|
|
88
|
+
}
|
|
89
|
+
function findMissingContext(request) {
|
|
90
|
+
const lower = request.toLowerCase();
|
|
91
|
+
const missing = [];
|
|
92
|
+
if (!SPECIFIC_INDICATORS.some(s => lower.includes(s))) {
|
|
93
|
+
missing.push('No specific files or components mentioned');
|
|
94
|
+
}
|
|
95
|
+
if (!/\b(api|endpoint|route|page|view|component|service|model|schema)\b/.test(lower)) {
|
|
96
|
+
missing.push('No architectural layer specified (API, UI, service, model)');
|
|
97
|
+
}
|
|
98
|
+
if (!/\b(user|admin|public|internal|customer)\b/.test(lower)) {
|
|
99
|
+
missing.push('No target audience or access level specified');
|
|
100
|
+
}
|
|
101
|
+
if (!/\b(must|should|require|need|want)\b/.test(lower)) {
|
|
102
|
+
missing.push('No explicit requirements or constraints stated');
|
|
103
|
+
}
|
|
104
|
+
if (!/\b(test|verify|validate|check)\b/.test(lower)) {
|
|
105
|
+
missing.push('No success criteria or testing approach mentioned');
|
|
106
|
+
}
|
|
107
|
+
return missing;
|
|
108
|
+
}
|
|
109
|
+
function generateQuestions(request, missing, riskFactors) {
|
|
110
|
+
const questions = [];
|
|
111
|
+
const lower = request.toLowerCase();
|
|
112
|
+
if (missing.some(m => m.includes('files or components'))) {
|
|
113
|
+
questions.push('Which specific files or components should be changed?');
|
|
114
|
+
}
|
|
115
|
+
if (missing.some(m => m.includes('architectural layer'))) {
|
|
116
|
+
questions.push('Should this change the API, the UI, both, or just internal logic?');
|
|
117
|
+
}
|
|
118
|
+
if (missing.some(m => m.includes('audience'))) {
|
|
119
|
+
questions.push('Who is the target user for this change?');
|
|
120
|
+
}
|
|
121
|
+
if (missing.some(m => m.includes('requirements'))) {
|
|
122
|
+
questions.push('What are the must-have requirements vs nice-to-haves?');
|
|
123
|
+
}
|
|
124
|
+
if (missing.some(m => m.includes('success criteria'))) {
|
|
125
|
+
questions.push('How will you verify this change works correctly?');
|
|
126
|
+
}
|
|
127
|
+
if (riskFactors.length > 0) {
|
|
128
|
+
questions.push('Are there existing tests covering the affected area?');
|
|
129
|
+
questions.push('Is there a rollback plan if something goes wrong?');
|
|
130
|
+
}
|
|
131
|
+
if (lower.includes('add') || lower.includes('create') || lower.includes('build')) {
|
|
132
|
+
questions.push('Should this integrate with existing patterns or introduce a new approach?');
|
|
133
|
+
}
|
|
134
|
+
if (lower.includes('fix') || lower.includes('bug')) {
|
|
135
|
+
questions.push('Can you provide steps to reproduce the issue?');
|
|
136
|
+
}
|
|
137
|
+
return questions.slice(0, 6); // Cap at 6 questions
|
|
138
|
+
}
|
|
139
|
+
function generateOptions(request, vagueness, fileCount, riskFactors) {
|
|
140
|
+
const isRisky = riskFactors.length > 0;
|
|
141
|
+
const baseCost = fileCount > 200 ? 2.0 : fileCount > 50 ? 1.0 : 0.5;
|
|
142
|
+
const options = [];
|
|
143
|
+
// Minimal option
|
|
144
|
+
options.push({
|
|
145
|
+
name: 'Minimal',
|
|
146
|
+
description: 'Smallest viable change — only the core requirement with no extras',
|
|
147
|
+
estimatedCost: baseCost,
|
|
148
|
+
estimatedTime: fileCount > 200 ? '10-20 min' : '5-10 min',
|
|
149
|
+
risk: 'low',
|
|
150
|
+
tradeoffs: [
|
|
151
|
+
'Fastest and cheapest',
|
|
152
|
+
'May miss edge cases',
|
|
153
|
+
'No additional tests or documentation',
|
|
154
|
+
'Might need follow-up work',
|
|
155
|
+
],
|
|
156
|
+
recommended: !isRisky && vagueness < 40,
|
|
157
|
+
});
|
|
158
|
+
// Balanced option
|
|
159
|
+
options.push({
|
|
160
|
+
name: 'Balanced',
|
|
161
|
+
description: 'Core requirement plus tests, error handling, and basic documentation',
|
|
162
|
+
estimatedCost: baseCost * 2.5,
|
|
163
|
+
estimatedTime: fileCount > 200 ? '20-40 min' : '10-25 min',
|
|
164
|
+
risk: isRisky ? 'medium' : 'low',
|
|
165
|
+
tradeoffs: [
|
|
166
|
+
'Good balance of speed and quality',
|
|
167
|
+
'Includes test coverage',
|
|
168
|
+
'Handles common edge cases',
|
|
169
|
+
'Moderate cost',
|
|
170
|
+
],
|
|
171
|
+
recommended: true, // default recommendation
|
|
172
|
+
});
|
|
173
|
+
// Comprehensive option
|
|
174
|
+
options.push({
|
|
175
|
+
name: 'Comprehensive',
|
|
176
|
+
description: 'Full implementation with tests, docs, error handling, logging, and review',
|
|
177
|
+
estimatedCost: baseCost * 5,
|
|
178
|
+
estimatedTime: fileCount > 200 ? '40-90 min' : '25-50 min',
|
|
179
|
+
risk: isRisky ? 'medium' : 'low',
|
|
180
|
+
tradeoffs: [
|
|
181
|
+
'Most thorough approach',
|
|
182
|
+
'Full test coverage',
|
|
183
|
+
'Documentation included',
|
|
184
|
+
'Higher cost and time',
|
|
185
|
+
],
|
|
186
|
+
recommended: isRisky,
|
|
187
|
+
});
|
|
188
|
+
// If risky, mark balanced as not recommended in favor of comprehensive
|
|
189
|
+
if (isRisky) {
|
|
190
|
+
options[1].recommended = false;
|
|
191
|
+
}
|
|
192
|
+
return options;
|
|
193
|
+
}
|
|
194
|
+
function classifyRequest(vagueness, riskFactors, fileCount) {
|
|
195
|
+
if (riskFactors.length > 0)
|
|
196
|
+
return 'risky';
|
|
197
|
+
if (vagueness > 50)
|
|
198
|
+
return 'ambiguous';
|
|
199
|
+
if (fileCount > 200)
|
|
200
|
+
return 'clear-large';
|
|
201
|
+
return 'clear-small';
|
|
202
|
+
}
|
|
203
|
+
function estimateScopeSize(fileCount, vagueness) {
|
|
204
|
+
if (fileCount > 200 || vagueness > 60)
|
|
205
|
+
return 'large';
|
|
206
|
+
if (fileCount > 50 || vagueness > 30)
|
|
207
|
+
return 'medium';
|
|
208
|
+
return 'small';
|
|
209
|
+
}
|
|
210
|
+
export function analyzeAmbiguity(request, cwd) {
|
|
211
|
+
const fileCount = countProjectFiles(cwd);
|
|
212
|
+
const vaguenessScore = scoreVagueness(request);
|
|
213
|
+
const riskFactors = detectRiskFactors(request);
|
|
214
|
+
const missingContext = findMissingContext(request);
|
|
215
|
+
const classification = classifyRequest(vaguenessScore, riskFactors, fileCount);
|
|
216
|
+
const scopeSize = estimateScopeSize(fileCount, vaguenessScore);
|
|
217
|
+
const questions = generateQuestions(request, missingContext, riskFactors);
|
|
218
|
+
const options = generateOptions(request, vaguenessScore, fileCount, riskFactors);
|
|
219
|
+
const baseCost = fileCount > 200 ? 2.0 : fileCount > 50 ? 1.0 : 0.5;
|
|
220
|
+
const estimatedCost = baseCost * (vaguenessScore > 50 ? 3 : vaguenessScore > 30 ? 2 : 1.5);
|
|
221
|
+
const estimatedFiles = Math.max(1, Math.round(fileCount * (vaguenessScore > 50 ? 0.1 : 0.03)));
|
|
222
|
+
return {
|
|
223
|
+
vaguenessScore,
|
|
224
|
+
scopeSize,
|
|
225
|
+
riskFactors,
|
|
226
|
+
missingContext,
|
|
227
|
+
classification,
|
|
228
|
+
estimatedCost,
|
|
229
|
+
estimatedFiles,
|
|
230
|
+
questions,
|
|
231
|
+
options,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
export function generateScopeDocument(request, chosenOption, analysis) {
|
|
235
|
+
const willBuild = [];
|
|
236
|
+
const willNotBuild = [];
|
|
237
|
+
const assumptions = [];
|
|
238
|
+
// Build items based on option level
|
|
239
|
+
willBuild.push(`Core: ${request}`);
|
|
240
|
+
if (chosenOption.name === 'Balanced' || chosenOption.name === 'Comprehensive') {
|
|
241
|
+
willBuild.push('Unit tests for new/changed code');
|
|
242
|
+
willBuild.push('Error handling for common failure modes');
|
|
243
|
+
}
|
|
244
|
+
if (chosenOption.name === 'Comprehensive') {
|
|
245
|
+
willBuild.push('Integration tests');
|
|
246
|
+
willBuild.push('Documentation updates');
|
|
247
|
+
willBuild.push('Logging and observability');
|
|
248
|
+
}
|
|
249
|
+
// Will NOT build
|
|
250
|
+
if (chosenOption.name === 'Minimal') {
|
|
251
|
+
willNotBuild.push('Tests (follow up separately)');
|
|
252
|
+
willNotBuild.push('Documentation updates');
|
|
253
|
+
willNotBuild.push('Error handling beyond basic cases');
|
|
254
|
+
}
|
|
255
|
+
if (chosenOption.name !== 'Comprehensive') {
|
|
256
|
+
willNotBuild.push('Performance optimization');
|
|
257
|
+
willNotBuild.push('Migration scripts (if applicable)');
|
|
258
|
+
}
|
|
259
|
+
willNotBuild.push('Unrelated refactoring');
|
|
260
|
+
// Assumptions
|
|
261
|
+
assumptions.push('Existing codebase patterns will be followed');
|
|
262
|
+
assumptions.push('Current dependencies are sufficient');
|
|
263
|
+
if (analysis.riskFactors.length > 0) {
|
|
264
|
+
assumptions.push('Risk areas will be reviewed manually before merge');
|
|
265
|
+
}
|
|
266
|
+
if (analysis.missingContext.length > 0) {
|
|
267
|
+
assumptions.push('Ambiguous requirements will be interpreted conservatively');
|
|
268
|
+
}
|
|
269
|
+
// Risk description
|
|
270
|
+
let risk = 'Low — straightforward change with minimal dependencies';
|
|
271
|
+
if (analysis.riskFactors.length > 0) {
|
|
272
|
+
risk = `Medium-High — ${analysis.riskFactors[0]}`;
|
|
273
|
+
}
|
|
274
|
+
else if (analysis.vaguenessScore > 50) {
|
|
275
|
+
risk = 'Medium — vague requirements may lead to rework';
|
|
276
|
+
}
|
|
277
|
+
return {
|
|
278
|
+
willBuild,
|
|
279
|
+
willNotBuild,
|
|
280
|
+
assumptions,
|
|
281
|
+
estimatedCost: chosenOption.estimatedCost,
|
|
282
|
+
approach: `${chosenOption.name}: ${chosenOption.description}`,
|
|
283
|
+
risk,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
//# sourceMappingURL=ambiguity-detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ambiguity-detector.js","sourceRoot":"","sources":["../../../src/core/ambiguity-detector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAiCjC,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACxH,MAAM,aAAa,GAAG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ACxE,CAAC;IACD,IAAI,QAAQ,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvC,WAAW,CAAC,IAAI,CAAC,2DAA2D,CAAC,CAAC;IAChF,CAAC;IAED,mBAAmB;IACnB,IAAI,IAAI,GAAG,wDAAwD,CAAC;IACpE,IAAI,QAAQ,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpC,IAAI,GAAG,iBAAiB,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC;IACpD,CAAC;SAAM,IAAI,QAAQ,CAAC,cAAc,GAAG,EAAE,EAAE,CAAC;QACxC,IAAI,GAAG,gDAAgD,CAAC;IAC1D,CAAC;IAED,OAAO;QACL,SAAS;QACT,YAAY;QACZ,WAAW;QACX,aAAa,EAAE,YAAY,CAAC,aAAa;QACzC,QAAQ,EAAE,GAAG,YAAY,CAAC,IAAI,KAAK,YAAY,CAAC,WAAW,EAAE;QAC7D,IAAI;KACL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { MetricDataPoint, DeployMarker, AnomalyAlert, PredictiveAlert } from '../types.js';
|
|
2
|
+
export declare class AnomalyDetector {
|
|
3
|
+
private sigma;
|
|
4
|
+
constructor(sigma?: number);
|
|
5
|
+
/** Detect anomalies in a set of metric data points using Z-score */
|
|
6
|
+
detect(metrics: MetricDataPoint[]): AnomalyAlert[];
|
|
7
|
+
/** Correlate an anomaly with nearby deploys */
|
|
8
|
+
correlateWithDeploys(anomaly: AnomalyAlert, deploys: DeployMarker[], windowMs?: number): AnomalyAlert;
|
|
9
|
+
/** Predict future issues based on metric trends */
|
|
10
|
+
predict(metrics: MetricDataPoint[]): PredictiveAlert[];
|
|
11
|
+
/** Compute baseline statistics for a set of values */
|
|
12
|
+
private computeBaseline;
|
|
13
|
+
/** Classify severity based on Z-score magnitude */
|
|
14
|
+
private classifySeverity;
|
|
15
|
+
/** Detect sustained trend drift */
|
|
16
|
+
private detectTrend;
|
|
17
|
+
/** Detect periodic patterns (e.g., daily spikes) */
|
|
18
|
+
private detectPattern;
|
|
19
|
+
/** Get the next occurrence of a given hour */
|
|
20
|
+
private nextOccurrence;
|
|
21
|
+
/** Simple linear regression */
|
|
22
|
+
private linearRegression;
|
|
23
|
+
/** Deduplicate alerts: keep most severe per metric per hour */
|
|
24
|
+
private deduplicateAlerts;
|
|
25
|
+
/** Format a duration in milliseconds to human-readable */
|
|
26
|
+
private formatDuration;
|
|
27
|
+
/** Group metric data points by name */
|
|
28
|
+
private groupByName;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=anomaly-detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anomaly-detector.d.ts","sourceRoot":"","sources":["../../../src/core/anomaly-detector.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,eAAe,EAChB,MAAM,aAAa,CAAC;AAUrB,qBAAa,eAAe;IAC1B,OAAO,CAAC,KAAK,CAAS;gBAEV,KAAK,GAAE,MAAU;IAI7B,oEAAoE;IACpE,MAAM,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,YAAY,EAAE;IAoDlD,+CAA+C;IAC/C,oBAAoB,CAClB,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,YAAY,EAAE,EACvB,QAAQ,GAAE,MAAgB,GACzB,YAAY;IA6Bf,mDAAmD;IACnD,OAAO,CAAC,OAAO,EAAE,eAAe,EAAE,GAAG,eAAe,EAAE;IAoEtD,sDAAsD;IACtD,OAAO,CAAC,eAAe;IAmBvB,mDAAmD;IACnD,OAAO,CAAC,gBAAgB;IAMxB,mCAAmC;IACnC,OAAO,CAAC,WAAW;IA0BnB,oDAAoD;IACpD,OAAO,CAAC,aAAa;IA4CrB,8CAA8C;IAC9C,OAAO,CAAC,cAAc;IAUtB,+BAA+B;IAC/B,OAAO,CAAC,gBAAgB;IA4BxB,+DAA+D;IAC/D,OAAO,CAAC,iBAAiB;IAiBzB,0DAA0D;IAC1D,OAAO,CAAC,cAAc;IAYtB,uCAAuC;IACvC,OAAO,CAAC,WAAW;CAQpB"}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
export class AnomalyDetector {
|
|
3
|
+
sigma;
|
|
4
|
+
constructor(sigma = 3) {
|
|
5
|
+
this.sigma = sigma;
|
|
6
|
+
}
|
|
7
|
+
/** Detect anomalies in a set of metric data points using Z-score */
|
|
8
|
+
detect(metrics) {
|
|
9
|
+
if (metrics.length < 5)
|
|
10
|
+
return [];
|
|
11
|
+
const alerts = [];
|
|
12
|
+
// Group metrics by name
|
|
13
|
+
const grouped = this.groupByName(metrics);
|
|
14
|
+
for (const [name, points] of Object.entries(grouped)) {
|
|
15
|
+
if (points.length < 5)
|
|
16
|
+
continue;
|
|
17
|
+
// Sort by timestamp
|
|
18
|
+
const sorted = [...points].sort((a, b) => a.timestamp - b.timestamp);
|
|
19
|
+
// Use the first 80% as baseline, check the last 20%
|
|
20
|
+
const splitIdx = Math.floor(sorted.length * 0.8);
|
|
21
|
+
const baseline = sorted.slice(0, splitIdx);
|
|
22
|
+
const recent = sorted.slice(splitIdx);
|
|
23
|
+
const stats = this.computeBaseline(baseline.map(p => p.value));
|
|
24
|
+
if (stats.stddev === 0)
|
|
25
|
+
continue;
|
|
26
|
+
for (const point of recent) {
|
|
27
|
+
const zScore = Math.abs((point.value - stats.mean) / stats.stddev);
|
|
28
|
+
if (zScore >= this.sigma) {
|
|
29
|
+
const isSpike = point.value > stats.mean;
|
|
30
|
+
alerts.push({
|
|
31
|
+
id: randomUUID(),
|
|
32
|
+
metric: name,
|
|
33
|
+
type: isSpike ? 'spike' : 'drop',
|
|
34
|
+
severity: this.classifySeverity(zScore),
|
|
35
|
+
value: point.value,
|
|
36
|
+
baseline: stats.mean,
|
|
37
|
+
deviation: zScore,
|
|
38
|
+
timestamp: point.timestamp,
|
|
39
|
+
resolved: false,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Check for trend anomalies (consistent drift)
|
|
44
|
+
const trendAlert = this.detectTrend(name, sorted, stats);
|
|
45
|
+
if (trendAlert) {
|
|
46
|
+
alerts.push(trendAlert);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// Deduplicate: keep only the most severe alert per metric per hour
|
|
50
|
+
return this.deduplicateAlerts(alerts);
|
|
51
|
+
}
|
|
52
|
+
/** Correlate an anomaly with nearby deploys */
|
|
53
|
+
correlateWithDeploys(anomaly, deploys, windowMs = 3600000) {
|
|
54
|
+
const nearbyDeploys = deploys.filter(d => Math.abs(d.timestamp - anomaly.timestamp) <= windowMs);
|
|
55
|
+
if (nearbyDeploys.length === 0)
|
|
56
|
+
return anomaly;
|
|
57
|
+
// Find the closest deploy
|
|
58
|
+
const closest = nearbyDeploys.reduce((best, d) => {
|
|
59
|
+
const dist = Math.abs(d.timestamp - anomaly.timestamp);
|
|
60
|
+
const bestDist = Math.abs(best.timestamp - anomaly.timestamp);
|
|
61
|
+
return dist < bestDist ? d : best;
|
|
62
|
+
});
|
|
63
|
+
// Confidence is higher when deploy is closer in time
|
|
64
|
+
const timeDiff = Math.abs(closest.timestamp - anomaly.timestamp);
|
|
65
|
+
const confidence = Math.max(0.1, 1 - timeDiff / windowMs);
|
|
66
|
+
return {
|
|
67
|
+
...anomaly,
|
|
68
|
+
type: 'correlation',
|
|
69
|
+
deployCorrelation: {
|
|
70
|
+
sha: closest.sha,
|
|
71
|
+
confidence: Math.round(confidence * 100) / 100,
|
|
72
|
+
filesChanged: closest.filesChanged,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** Predict future issues based on metric trends */
|
|
77
|
+
predict(metrics) {
|
|
78
|
+
if (metrics.length < 10)
|
|
79
|
+
return [];
|
|
80
|
+
const alerts = [];
|
|
81
|
+
const grouped = this.groupByName(metrics);
|
|
82
|
+
for (const [name, points] of Object.entries(grouped)) {
|
|
83
|
+
if (points.length < 10)
|
|
84
|
+
continue;
|
|
85
|
+
const sorted = [...points].sort((a, b) => a.timestamp - b.timestamp);
|
|
86
|
+
const values = sorted.map(p => p.value);
|
|
87
|
+
const timestamps = sorted.map(p => p.timestamp);
|
|
88
|
+
// Linear regression for trend extrapolation
|
|
89
|
+
const regression = this.linearRegression(timestamps, values);
|
|
90
|
+
if (Math.abs(regression.slope) < 0.0001)
|
|
91
|
+
continue;
|
|
92
|
+
const stats = this.computeBaseline(values);
|
|
93
|
+
// Capacity alert: predict when metric will exceed 2 sigma
|
|
94
|
+
const upperThreshold = stats.mean + this.sigma * stats.stddev;
|
|
95
|
+
const lowerThreshold = stats.mean - this.sigma * stats.stddev;
|
|
96
|
+
if (regression.slope > 0) {
|
|
97
|
+
// Growing trend — predict when it crosses upper threshold
|
|
98
|
+
const currentValue = regression.slope * timestamps[timestamps.length - 1] + regression.intercept;
|
|
99
|
+
if (currentValue < upperThreshold) {
|
|
100
|
+
const timeToThreshold = (upperThreshold - currentValue) / regression.slope;
|
|
101
|
+
if (timeToThreshold > 0 && timeToThreshold < 7 * 86400000) {
|
|
102
|
+
alerts.push({
|
|
103
|
+
metric: name,
|
|
104
|
+
type: 'capacity',
|
|
105
|
+
message: `${name} is trending up — predicted to breach threshold in ${this.formatDuration(timeToThreshold)}`,
|
|
106
|
+
predictedAt: Date.now() + timeToThreshold,
|
|
107
|
+
confidence: Math.min(0.95, regression.r2),
|
|
108
|
+
timeToImpact: this.formatDuration(timeToThreshold),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
// Decreasing trend — predict when it crosses lower threshold
|
|
115
|
+
const currentValue = regression.slope * timestamps[timestamps.length - 1] + regression.intercept;
|
|
116
|
+
if (currentValue > lowerThreshold) {
|
|
117
|
+
const timeToThreshold = (lowerThreshold - currentValue) / regression.slope;
|
|
118
|
+
if (timeToThreshold > 0 && timeToThreshold < 7 * 86400000) {
|
|
119
|
+
alerts.push({
|
|
120
|
+
metric: name,
|
|
121
|
+
type: 'trend',
|
|
122
|
+
message: `${name} is trending down — predicted to breach threshold in ${this.formatDuration(timeToThreshold)}`,
|
|
123
|
+
predictedAt: Date.now() + timeToThreshold,
|
|
124
|
+
confidence: Math.min(0.95, regression.r2),
|
|
125
|
+
timeToImpact: this.formatDuration(timeToThreshold),
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// Pattern detection: check for periodic spikes
|
|
131
|
+
const patternAlert = this.detectPattern(name, sorted);
|
|
132
|
+
if (patternAlert) {
|
|
133
|
+
alerts.push(patternAlert);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return alerts;
|
|
137
|
+
}
|
|
138
|
+
/** Compute baseline statistics for a set of values */
|
|
139
|
+
computeBaseline(values) {
|
|
140
|
+
if (values.length === 0) {
|
|
141
|
+
return { mean: 0, stddev: 0, count: 0, min: 0, max: 0 };
|
|
142
|
+
}
|
|
143
|
+
const count = values.length;
|
|
144
|
+
const mean = values.reduce((sum, v) => sum + v, 0) / count;
|
|
145
|
+
const variance = values.reduce((sum, v) => sum + (v - mean) ** 2, 0) / count;
|
|
146
|
+
const stddev = Math.sqrt(variance);
|
|
147
|
+
return {
|
|
148
|
+
mean,
|
|
149
|
+
stddev,
|
|
150
|
+
count,
|
|
151
|
+
min: Math.min(...values),
|
|
152
|
+
max: Math.max(...values),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/** Classify severity based on Z-score magnitude */
|
|
156
|
+
classifySeverity(zScore) {
|
|
157
|
+
if (zScore >= this.sigma * 2)
|
|
158
|
+
return 'critical';
|
|
159
|
+
if (zScore >= this.sigma * 1.5)
|
|
160
|
+
return 'warning';
|
|
161
|
+
return 'info';
|
|
162
|
+
}
|
|
163
|
+
/** Detect sustained trend drift */
|
|
164
|
+
detectTrend(name, sorted, stats) {
|
|
165
|
+
if (sorted.length < 10)
|
|
166
|
+
return null;
|
|
167
|
+
// Check if the last 5 points are all above or below the mean
|
|
168
|
+
const lastN = sorted.slice(-5);
|
|
169
|
+
const allAbove = lastN.every(p => p.value > stats.mean + stats.stddev);
|
|
170
|
+
const allBelow = lastN.every(p => p.value < stats.mean - stats.stddev);
|
|
171
|
+
if (!allAbove && !allBelow)
|
|
172
|
+
return null;
|
|
173
|
+
const avgRecent = lastN.reduce((s, p) => s + p.value, 0) / lastN.length;
|
|
174
|
+
const deviation = Math.abs((avgRecent - stats.mean) / (stats.stddev || 1));
|
|
175
|
+
return {
|
|
176
|
+
id: randomUUID(),
|
|
177
|
+
metric: name,
|
|
178
|
+
type: 'trend',
|
|
179
|
+
severity: deviation >= this.sigma * 1.5 ? 'warning' : 'info',
|
|
180
|
+
value: avgRecent,
|
|
181
|
+
baseline: stats.mean,
|
|
182
|
+
deviation,
|
|
183
|
+
timestamp: lastN[lastN.length - 1].timestamp,
|
|
184
|
+
resolved: false,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/** Detect periodic patterns (e.g., daily spikes) */
|
|
188
|
+
detectPattern(name, sorted) {
|
|
189
|
+
if (sorted.length < 24)
|
|
190
|
+
return null;
|
|
191
|
+
// Simple approach: check if there's a clear hourly periodicity
|
|
192
|
+
const hourBuckets = {};
|
|
193
|
+
for (const p of sorted) {
|
|
194
|
+
const hour = new Date(p.timestamp).getHours();
|
|
195
|
+
if (!hourBuckets[hour])
|
|
196
|
+
hourBuckets[hour] = [];
|
|
197
|
+
hourBuckets[hour].push(p.value);
|
|
198
|
+
}
|
|
199
|
+
// Find the hour with the highest average
|
|
200
|
+
let peakHour = -1;
|
|
201
|
+
let peakAvg = -Infinity;
|
|
202
|
+
let overallAvg = 0;
|
|
203
|
+
let totalPoints = 0;
|
|
204
|
+
for (const [hour, values] of Object.entries(hourBuckets)) {
|
|
205
|
+
const avg = values.reduce((s, v) => s + v, 0) / values.length;
|
|
206
|
+
overallAvg += values.reduce((s, v) => s + v, 0);
|
|
207
|
+
totalPoints += values.length;
|
|
208
|
+
if (avg > peakAvg) {
|
|
209
|
+
peakAvg = avg;
|
|
210
|
+
peakHour = parseInt(hour);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
overallAvg /= totalPoints;
|
|
214
|
+
// If peak hour is >50% above overall average, report pattern
|
|
215
|
+
if (peakAvg > overallAvg * 1.5 && peakHour >= 0) {
|
|
216
|
+
return {
|
|
217
|
+
metric: name,
|
|
218
|
+
type: 'pattern',
|
|
219
|
+
message: `${name} shows recurring peak at hour ${peakHour}:00 (${((peakAvg / overallAvg - 1) * 100).toFixed(0)}% above avg)`,
|
|
220
|
+
predictedAt: this.nextOccurrence(peakHour),
|
|
221
|
+
confidence: 0.6,
|
|
222
|
+
timeToImpact: this.formatDuration(this.nextOccurrence(peakHour) - Date.now()),
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
/** Get the next occurrence of a given hour */
|
|
228
|
+
nextOccurrence(hour) {
|
|
229
|
+
const now = new Date();
|
|
230
|
+
const next = new Date(now);
|
|
231
|
+
next.setHours(hour, 0, 0, 0);
|
|
232
|
+
if (next.getTime() <= now.getTime()) {
|
|
233
|
+
next.setDate(next.getDate() + 1);
|
|
234
|
+
}
|
|
235
|
+
return next.getTime();
|
|
236
|
+
}
|
|
237
|
+
/** Simple linear regression */
|
|
238
|
+
linearRegression(x, y) {
|
|
239
|
+
const n = x.length;
|
|
240
|
+
if (n < 2)
|
|
241
|
+
return { slope: 0, intercept: 0, r2: 0 };
|
|
242
|
+
// Normalize x values to avoid numerical overflow
|
|
243
|
+
const xMin = x[0];
|
|
244
|
+
const xNorm = x.map(v => v - xMin);
|
|
245
|
+
const sumX = xNorm.reduce((s, v) => s + v, 0);
|
|
246
|
+
const sumY = y.reduce((s, v) => s + v, 0);
|
|
247
|
+
const sumXY = xNorm.reduce((s, v, i) => s + v * y[i], 0);
|
|
248
|
+
const sumX2 = xNorm.reduce((s, v) => s + v * v, 0);
|
|
249
|
+
const denom = n * sumX2 - sumX * sumX;
|
|
250
|
+
if (Math.abs(denom) < 1e-10)
|
|
251
|
+
return { slope: 0, intercept: sumY / n, r2: 0 };
|
|
252
|
+
const slope = (n * sumXY - sumX * sumY) / denom;
|
|
253
|
+
const intercept = (sumY - slope * sumX) / n;
|
|
254
|
+
// R-squared
|
|
255
|
+
const meanY = sumY / n;
|
|
256
|
+
const ssRes = y.reduce((s, v, i) => s + (v - (slope * xNorm[i] + intercept)) ** 2, 0);
|
|
257
|
+
const ssTot = y.reduce((s, v) => s + (v - meanY) ** 2, 0);
|
|
258
|
+
const r2 = ssTot > 0 ? 1 - ssRes / ssTot : 0;
|
|
259
|
+
return { slope, intercept, r2: Math.max(0, r2) };
|
|
260
|
+
}
|
|
261
|
+
/** Deduplicate alerts: keep most severe per metric per hour */
|
|
262
|
+
deduplicateAlerts(alerts) {
|
|
263
|
+
const byKey = new Map();
|
|
264
|
+
const severityRank = { critical: 3, warning: 2, info: 1 };
|
|
265
|
+
for (const alert of alerts) {
|
|
266
|
+
const hourBucket = Math.floor(alert.timestamp / 3600000);
|
|
267
|
+
const key = `${alert.metric}:${hourBucket}`;
|
|
268
|
+
const existing = byKey.get(key);
|
|
269
|
+
if (!existing || severityRank[alert.severity] > severityRank[existing.severity]) {
|
|
270
|
+
byKey.set(key, alert);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return [...byKey.values()].sort((a, b) => b.timestamp - a.timestamp);
|
|
274
|
+
}
|
|
275
|
+
/** Format a duration in milliseconds to human-readable */
|
|
276
|
+
formatDuration(ms) {
|
|
277
|
+
if (ms < 0)
|
|
278
|
+
return 'now';
|
|
279
|
+
const hours = Math.floor(ms / 3600000);
|
|
280
|
+
if (hours < 1) {
|
|
281
|
+
const mins = Math.floor(ms / 60000);
|
|
282
|
+
return `${mins}m`;
|
|
283
|
+
}
|
|
284
|
+
if (hours < 24)
|
|
285
|
+
return `${hours}h`;
|
|
286
|
+
const days = Math.floor(hours / 24);
|
|
287
|
+
return `${days}d`;
|
|
288
|
+
}
|
|
289
|
+
/** Group metric data points by name */
|
|
290
|
+
groupByName(metrics) {
|
|
291
|
+
const grouped = {};
|
|
292
|
+
for (const m of metrics) {
|
|
293
|
+
if (!grouped[m.name])
|
|
294
|
+
grouped[m.name] = [];
|
|
295
|
+
grouped[m.name].push(m);
|
|
296
|
+
}
|
|
297
|
+
return grouped;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
//# sourceMappingURL=anomaly-detector.js.map
|