oc-pilot 0.5.1 → 0.88.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +683 -0
- package/CONTRIBUTING.md +4 -2
- package/README.md +588 -20
- package/README.ru.md +572 -10
- package/dist/cli.js +185 -1
- package/dist/cli.js.map +1 -1
- package/dist/cli.test.js +1211 -1
- package/dist/cli.test.js.map +1 -1
- package/dist/commands/anti-regression.js +97 -0
- package/dist/commands/anti-regression.js.map +1 -0
- package/dist/commands/arch-diff.js +80 -0
- package/dist/commands/arch-diff.js.map +1 -0
- package/dist/commands/authz.js +167 -0
- package/dist/commands/authz.js.map +1 -0
- package/dist/commands/autopsy.js +64 -0
- package/dist/commands/autopsy.js.map +1 -0
- package/dist/commands/bankruptcy.js +60 -0
- package/dist/commands/bankruptcy.js.map +1 -0
- package/dist/commands/battle.js +119 -0
- package/dist/commands/battle.js.map +1 -0
- package/dist/commands/boundaries.js +114 -0
- package/dist/commands/boundaries.js.map +1 -0
- package/dist/commands/bounty.js +56 -0
- package/dist/commands/bounty.js.map +1 -0
- package/dist/commands/brag.js +62 -0
- package/dist/commands/brag.js.map +1 -0
- package/dist/commands/cache.js +62 -0
- package/dist/commands/cache.js.map +1 -0
- package/dist/commands/cinema.js +61 -0
- package/dist/commands/cinema.js.map +1 -0
- package/dist/commands/cleanup.js +110 -0
- package/dist/commands/cleanup.js.map +1 -0
- package/dist/commands/commit.js +177 -0
- package/dist/commands/commit.js.map +1 -0
- package/dist/commands/commit.test.js +160 -0
- package/dist/commands/commit.test.js.map +1 -0
- package/dist/commands/compliance.js +121 -0
- package/dist/commands/compliance.js.map +1 -0
- package/dist/commands/contract-drift.js +97 -0
- package/dist/commands/contract-drift.js.map +1 -0
- package/dist/commands/coverage.js +137 -0
- package/dist/commands/coverage.js.map +1 -0
- package/dist/commands/day.js +116 -0
- package/dist/commands/day.js.map +1 -0
- package/dist/commands/day.test.js +45 -0
- package/dist/commands/day.test.js.map +1 -0
- package/dist/commands/deps.js +245 -0
- package/dist/commands/deps.js.map +1 -0
- package/dist/commands/docgen.js +4 -2
- package/dist/commands/docgen.js.map +1 -1
- package/dist/commands/doctor.js +146 -2
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/doctor.test.js +69 -0
- package/dist/commands/doctor.test.js.map +1 -0
- package/dist/commands/echo.js +78 -0
- package/dist/commands/echo.js.map +1 -0
- package/dist/commands/ecosystem-verify.js +113 -0
- package/dist/commands/ecosystem-verify.js.map +1 -0
- package/dist/commands/env-sync.js +102 -0
- package/dist/commands/env-sync.js.map +1 -0
- package/dist/commands/explain.js +115 -0
- package/dist/commands/explain.js.map +1 -0
- package/dist/commands/fix.js +145 -3
- package/dist/commands/fix.js.map +1 -1
- package/dist/commands/flaky.js +111 -0
- package/dist/commands/flaky.js.map +1 -0
- package/dist/commands/fuzz.js +119 -0
- package/dist/commands/fuzz.js.map +1 -0
- package/dist/commands/hivemind.js +124 -0
- package/dist/commands/hivemind.js.map +1 -0
- package/dist/commands/impact.js +73 -0
- package/dist/commands/impact.js.map +1 -0
- package/dist/commands/init.js +73 -11
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/init.test.js +138 -0
- package/dist/commands/init.test.js.map +1 -0
- package/dist/commands/install-hook.js +161 -0
- package/dist/commands/install-hook.js.map +1 -0
- package/dist/commands/install-hook.test.js +100 -0
- package/dist/commands/install-hook.test.js.map +1 -0
- package/dist/commands/invariants.js +103 -0
- package/dist/commands/invariants.js.map +1 -0
- package/dist/commands/mock-leak.js +97 -0
- package/dist/commands/mock-leak.js.map +1 -0
- package/dist/commands/mutate.js +99 -0
- package/dist/commands/mutate.js.map +1 -0
- package/dist/commands/pack.js +144 -0
- package/dist/commands/pack.js.map +1 -0
- package/dist/commands/preflight.js +137 -0
- package/dist/commands/preflight.js.map +1 -0
- package/dist/commands/query.js +57 -0
- package/dist/commands/query.js.map +1 -0
- package/dist/commands/ready.js +152 -0
- package/dist/commands/ready.js.map +1 -0
- package/dist/commands/receipt.js +289 -0
- package/dist/commands/receipt.js.map +1 -0
- package/dist/commands/replay.js +112 -0
- package/dist/commands/replay.js.map +1 -0
- package/dist/commands/replay.test.js +125 -0
- package/dist/commands/replay.test.js.map +1 -0
- package/dist/commands/restore.js +54 -0
- package/dist/commands/restore.js.map +1 -0
- package/dist/commands/review.js +263 -4
- package/dist/commands/review.js.map +1 -1
- package/dist/commands/review.test.js +160 -0
- package/dist/commands/review.test.js.map +1 -0
- package/dist/commands/reviewers.js +86 -0
- package/dist/commands/reviewers.js.map +1 -0
- package/dist/commands/roast.js +102 -0
- package/dist/commands/roast.js.map +1 -0
- package/dist/commands/sandbox.js +82 -0
- package/dist/commands/sandbox.js.map +1 -0
- package/dist/commands/sast.js +162 -0
- package/dist/commands/sast.js.map +1 -0
- package/dist/commands/scan.js +47 -12
- package/dist/commands/scan.js.map +1 -1
- package/dist/commands/slop.js +145 -0
- package/dist/commands/slop.js.map +1 -0
- package/dist/commands/slop.test.js +135 -0
- package/dist/commands/slop.test.js.map +1 -0
- package/dist/commands/stats.js +61 -0
- package/dist/commands/stats.js.map +1 -0
- package/dist/commands/test-gen.js +372 -0
- package/dist/commands/test-gen.js.map +1 -0
- package/dist/commands/test-guard.js +89 -0
- package/dist/commands/test-guard.js.map +1 -0
- package/dist/commands/test-plan.js +133 -0
- package/dist/commands/test-plan.js.map +1 -0
- package/dist/commands/zoom-symbol.js +52 -0
- package/dist/commands/zoom-symbol.js.map +1 -0
- package/dist/core/agent-rules.js +35 -0
- package/dist/core/agent-rules.js.map +1 -0
- package/dist/core/anthropic.test.js +116 -0
- package/dist/core/anthropic.test.js.map +1 -0
- package/dist/core/anti-regression.js +161 -0
- package/dist/core/anti-regression.js.map +1 -0
- package/dist/core/anti-regression.test.js +154 -0
- package/dist/core/anti-regression.test.js.map +1 -0
- package/dist/core/aql.js +220 -0
- package/dist/core/aql.js.map +1 -0
- package/dist/core/aql.test.js +64 -0
- package/dist/core/aql.test.js.map +1 -0
- package/dist/core/arch-diff.js +122 -0
- package/dist/core/arch-diff.js.map +1 -0
- package/dist/core/arch-diff.test.js +93 -0
- package/dist/core/arch-diff.test.js.map +1 -0
- package/dist/core/authz.js +292 -0
- package/dist/core/authz.js.map +1 -0
- package/dist/core/authz.test.js +115 -0
- package/dist/core/authz.test.js.map +1 -0
- package/dist/core/autopsy.js +230 -0
- package/dist/core/autopsy.js.map +1 -0
- package/dist/core/autopsy.test.js +106 -0
- package/dist/core/autopsy.test.js.map +1 -0
- package/dist/core/bankruptcy.js +232 -0
- package/dist/core/bankruptcy.js.map +1 -0
- package/dist/core/bankruptcy.test.js +91 -0
- package/dist/core/bankruptcy.test.js.map +1 -0
- package/dist/core/baseline.js +131 -0
- package/dist/core/baseline.js.map +1 -0
- package/dist/core/baseline.test.js +91 -0
- package/dist/core/baseline.test.js.map +1 -0
- package/dist/core/battle.js +213 -0
- package/dist/core/battle.js.map +1 -0
- package/dist/core/battle.test.js +116 -0
- package/dist/core/battle.test.js.map +1 -0
- package/dist/core/boundaries.js +200 -0
- package/dist/core/boundaries.js.map +1 -0
- package/dist/core/boundaries.test.js +62 -0
- package/dist/core/boundaries.test.js.map +1 -0
- package/dist/core/bounty.js +128 -0
- package/dist/core/bounty.js.map +1 -0
- package/dist/core/bounty.test.js +82 -0
- package/dist/core/bounty.test.js.map +1 -0
- package/dist/core/brag.js +174 -0
- package/dist/core/brag.js.map +1 -0
- package/dist/core/brag.test.js +43 -0
- package/dist/core/brag.test.js.map +1 -0
- package/dist/core/cache.js +189 -0
- package/dist/core/cache.js.map +1 -0
- package/dist/core/cache.test.js +159 -0
- package/dist/core/cache.test.js.map +1 -0
- package/dist/core/cinema.js +242 -0
- package/dist/core/cinema.js.map +1 -0
- package/dist/core/cinema.test.js +73 -0
- package/dist/core/cinema.test.js.map +1 -0
- package/dist/core/cleanup.js +107 -0
- package/dist/core/cleanup.js.map +1 -0
- package/dist/core/compliance.js +193 -0
- package/dist/core/compliance.js.map +1 -0
- package/dist/core/compliance.test.js +123 -0
- package/dist/core/compliance.test.js.map +1 -0
- package/dist/core/config.js +78 -0
- package/dist/core/config.js.map +1 -1
- package/dist/core/config.test.js +66 -0
- package/dist/core/config.test.js.map +1 -1
- package/dist/core/contract-drift.js +296 -0
- package/dist/core/contract-drift.js.map +1 -0
- package/dist/core/contract-drift.test.js +166 -0
- package/dist/core/contract-drift.test.js.map +1 -0
- package/dist/core/cost.test.js +103 -0
- package/dist/core/cost.test.js.map +1 -0
- package/dist/core/coverage.js +335 -0
- package/dist/core/coverage.js.map +1 -0
- package/dist/core/coverage.test.js +190 -0
- package/dist/core/coverage.test.js.map +1 -0
- package/dist/core/deps-fix.js +169 -0
- package/dist/core/deps-fix.js.map +1 -0
- package/dist/core/deps-fix.test.js +176 -0
- package/dist/core/deps-fix.test.js.map +1 -0
- package/dist/core/deps-health.js +353 -0
- package/dist/core/deps-health.js.map +1 -0
- package/dist/core/deps-health.test.js +230 -0
- package/dist/core/deps-health.test.js.map +1 -0
- package/dist/core/deps-why.js +260 -0
- package/dist/core/deps-why.js.map +1 -0
- package/dist/core/deps-why.test.js +175 -0
- package/dist/core/deps-why.test.js.map +1 -0
- package/dist/core/deps.js +179 -0
- package/dist/core/deps.js.map +1 -0
- package/dist/core/deps.test.js +88 -0
- package/dist/core/deps.test.js.map +1 -0
- package/dist/core/diff-source.js +4 -2
- package/dist/core/diff-source.js.map +1 -1
- package/dist/core/echo.js +151 -0
- package/dist/core/echo.js.map +1 -0
- package/dist/core/echo.test.js +90 -0
- package/dist/core/echo.test.js.map +1 -0
- package/dist/core/ecosystem-verify.js +331 -0
- package/dist/core/ecosystem-verify.js.map +1 -0
- package/dist/core/ecosystem-verify.test.js +158 -0
- package/dist/core/ecosystem-verify.test.js.map +1 -0
- package/dist/core/engine-preset.test.js +60 -0
- package/dist/core/engine-preset.test.js.map +1 -0
- package/dist/core/engine.js +278 -32
- package/dist/core/engine.js.map +1 -1
- package/dist/core/engine.test.js +63 -0
- package/dist/core/engine.test.js.map +1 -1
- package/dist/core/env-sync.js +122 -0
- package/dist/core/env-sync.js.map +1 -0
- package/dist/core/env-sync.test.js +99 -0
- package/dist/core/env-sync.test.js.map +1 -0
- package/dist/core/file-context.js +4 -2
- package/dist/core/file-context.js.map +1 -1
- package/dist/core/findings-baseline.js +60 -0
- package/dist/core/findings-baseline.js.map +1 -0
- package/dist/core/findings-baseline.test.js +77 -0
- package/dist/core/findings-baseline.test.js.map +1 -0
- package/dist/core/findings.js +68 -21
- package/dist/core/findings.js.map +1 -1
- package/dist/core/flaky.js +137 -0
- package/dist/core/flaky.js.map +1 -0
- package/dist/core/flaky.test.js +97 -0
- package/dist/core/flaky.test.js.map +1 -0
- package/dist/core/format.js +5 -3
- package/dist/core/format.js.map +1 -1
- package/dist/core/fuzz.js +306 -0
- package/dist/core/fuzz.js.map +1 -0
- package/dist/core/fuzz.test.js +121 -0
- package/dist/core/fuzz.test.js.map +1 -0
- package/dist/core/git.js +22 -0
- package/dist/core/git.js.map +1 -1
- package/dist/core/gitlab.js +176 -0
- package/dist/core/gitlab.js.map +1 -0
- package/dist/core/gitlab.test.js +199 -0
- package/dist/core/gitlab.test.js.map +1 -0
- package/dist/core/hivemind.js +250 -0
- package/dist/core/hivemind.js.map +1 -0
- package/dist/core/hivemind.test.js +79 -0
- package/dist/core/hivemind.test.js.map +1 -0
- package/dist/core/hologram.js +463 -0
- package/dist/core/hologram.js.map +1 -0
- package/dist/core/hologram.test.js +124 -0
- package/dist/core/hologram.test.js.map +1 -0
- package/dist/core/impact.js +240 -0
- package/dist/core/impact.js.map +1 -0
- package/dist/core/impact.test.js +105 -0
- package/dist/core/impact.test.js.map +1 -0
- package/dist/core/import-graph.js +170 -0
- package/dist/core/import-graph.js.map +1 -0
- package/dist/core/import-graph.test.js +52 -0
- package/dist/core/import-graph.test.js.map +1 -0
- package/dist/core/injection.js +55 -0
- package/dist/core/injection.js.map +1 -0
- package/dist/core/injection.test.js +45 -0
- package/dist/core/injection.test.js.map +1 -0
- package/dist/core/invariants.js +286 -0
- package/dist/core/invariants.js.map +1 -0
- package/dist/core/invariants.test.js +87 -0
- package/dist/core/invariants.test.js.map +1 -0
- package/dist/core/last-review.js +92 -0
- package/dist/core/last-review.js.map +1 -0
- package/dist/core/last-review.test.js +97 -0
- package/dist/core/last-review.test.js.map +1 -0
- package/dist/core/lockfile-support.test.js +112 -0
- package/dist/core/lockfile-support.test.js.map +1 -0
- package/dist/core/lockfile.js +284 -0
- package/dist/core/lockfile.js.map +1 -0
- package/dist/core/lockfile.test.js +203 -0
- package/dist/core/lockfile.test.js.map +1 -0
- package/dist/core/mock-leak.js +120 -0
- package/dist/core/mock-leak.js.map +1 -0
- package/dist/core/mock-leak.test.js +79 -0
- package/dist/core/mock-leak.test.js.map +1 -0
- package/dist/core/mutation.js +206 -0
- package/dist/core/mutation.js.map +1 -0
- package/dist/core/mutation.test.js +104 -0
- package/dist/core/mutation.test.js.map +1 -0
- package/dist/core/opencode.js +15 -2
- package/dist/core/opencode.js.map +1 -1
- package/dist/core/opencode.test.js +10 -1
- package/dist/core/opencode.test.js.map +1 -1
- package/dist/core/options.js +51 -3
- package/dist/core/options.js.map +1 -1
- package/dist/core/osv.js +202 -0
- package/dist/core/osv.js.map +1 -0
- package/dist/core/osv.test.js +173 -0
- package/dist/core/osv.test.js.map +1 -0
- package/dist/core/output-format.test.js +102 -0
- package/dist/core/output-format.test.js.map +1 -0
- package/dist/core/pack.js +212 -0
- package/dist/core/pack.js.map +1 -0
- package/dist/core/pack.test.js +129 -0
- package/dist/core/pack.test.js.map +1 -0
- package/dist/core/phantom.js +155 -0
- package/dist/core/phantom.js.map +1 -0
- package/dist/core/phantom.test.js +58 -0
- package/dist/core/phantom.test.js.map +1 -0
- package/dist/core/pr-comment.js +116 -0
- package/dist/core/pr-comment.js.map +1 -0
- package/dist/core/pr-comment.test.js +53 -0
- package/dist/core/pr-comment.test.js.map +1 -0
- package/dist/core/pr-review.js +160 -0
- package/dist/core/pr-review.js.map +1 -0
- package/dist/core/pr-review.test.js +62 -0
- package/dist/core/pr-review.test.js.map +1 -0
- package/dist/core/preflight-run.js +106 -0
- package/dist/core/preflight-run.js.map +1 -0
- package/dist/core/preflight.js +173 -0
- package/dist/core/preflight.js.map +1 -0
- package/dist/core/preflight.test.js +187 -0
- package/dist/core/preflight.test.js.map +1 -0
- package/dist/core/presets.js +408 -0
- package/dist/core/presets.js.map +1 -0
- package/dist/core/presets.test.js +79 -0
- package/dist/core/presets.test.js.map +1 -0
- package/dist/core/prompt.golden.test.js +74 -0
- package/dist/core/prompt.golden.test.js.map +1 -0
- package/dist/core/prompt.js +43 -4
- package/dist/core/prompt.js.map +1 -1
- package/dist/core/prompt.test.js +16 -0
- package/dist/core/prompt.test.js.map +1 -1
- package/dist/core/readiness-fix.js +111 -0
- package/dist/core/readiness-fix.js.map +1 -0
- package/dist/core/readiness-fix.test.js +99 -0
- package/dist/core/readiness-fix.test.js.map +1 -0
- package/dist/core/readiness.js +189 -0
- package/dist/core/readiness.js.map +1 -0
- package/dist/core/readiness.test.js +199 -0
- package/dist/core/readiness.test.js.map +1 -0
- package/dist/core/receipt.js +193 -0
- package/dist/core/receipt.js.map +1 -0
- package/dist/core/receipt.test.js +193 -0
- package/dist/core/receipt.test.js.map +1 -0
- package/dist/core/reviewers.js +179 -0
- package/dist/core/reviewers.js.map +1 -0
- package/dist/core/reviewers.test.js +105 -0
- package/dist/core/reviewers.test.js.map +1 -0
- package/dist/core/roast.js +27 -0
- package/dist/core/roast.js.map +1 -0
- package/dist/core/roast.test.js +19 -0
- package/dist/core/roast.test.js.map +1 -0
- package/dist/core/router.js +8 -0
- package/dist/core/router.js.map +1 -0
- package/dist/core/router.test.js +157 -0
- package/dist/core/router.test.js.map +1 -0
- package/dist/core/rules.js +2 -2
- package/dist/core/rules.js.map +1 -1
- package/dist/core/run.js +322 -20
- package/dist/core/run.js.map +1 -1
- package/dist/core/sarif.js +125 -0
- package/dist/core/sarif.js.map +1 -0
- package/dist/core/sarif.test.js +60 -0
- package/dist/core/sarif.test.js.map +1 -0
- package/dist/core/sast.js +324 -0
- package/dist/core/sast.js.map +1 -0
- package/dist/core/sast.test.js +105 -0
- package/dist/core/sast.test.js.map +1 -0
- package/dist/core/sbom.js +121 -0
- package/dist/core/sbom.js.map +1 -0
- package/dist/core/sbom.test.js +81 -0
- package/dist/core/sbom.test.js.map +1 -0
- package/dist/core/second-opinion.js +88 -0
- package/dist/core/second-opinion.js.map +1 -0
- package/dist/core/second-opinion.test.js +89 -0
- package/dist/core/second-opinion.test.js.map +1 -0
- package/dist/core/secrets.js +120 -5
- package/dist/core/secrets.js.map +1 -1
- package/dist/core/secrets.test.js +74 -1
- package/dist/core/secrets.test.js.map +1 -1
- package/dist/core/shadow.js +94 -0
- package/dist/core/shadow.js.map +1 -0
- package/dist/core/shadow.test.js +50 -0
- package/dist/core/shadow.test.js.map +1 -0
- package/dist/core/slicing.js +110 -0
- package/dist/core/slicing.js.map +1 -0
- package/dist/core/slicing.test.js +287 -0
- package/dist/core/slicing.test.js.map +1 -0
- package/dist/core/slop/churn.js +49 -0
- package/dist/core/slop/churn.js.map +1 -0
- package/dist/core/slop/collect.js +186 -0
- package/dist/core/slop/collect.js.map +1 -0
- package/dist/core/slop/dead-exports.js +101 -0
- package/dist/core/slop/dead-exports.js.map +1 -0
- package/dist/core/slop/duplicates.js +155 -0
- package/dist/core/slop/duplicates.js.map +1 -0
- package/dist/core/slop/index.js +72 -0
- package/dist/core/slop/index.js.map +1 -0
- package/dist/core/slop/model.js +2 -0
- package/dist/core/slop/model.js.map +1 -0
- package/dist/core/slop/score.js +185 -0
- package/dist/core/slop/score.js.map +1 -0
- package/dist/core/slop/slop.test.js +160 -0
- package/dist/core/slop/slop.test.js.map +1 -0
- package/dist/core/slop/source.js +129 -0
- package/dist/core/slop/source.js.map +1 -0
- package/dist/core/slop/test-debt.js +178 -0
- package/dist/core/slop/test-debt.js.map +1 -0
- package/dist/core/slop/test-debt.test.js +114 -0
- package/dist/core/slop/test-debt.test.js.map +1 -0
- package/dist/core/slop/todos.js +117 -0
- package/dist/core/slop/todos.js.map +1 -0
- package/dist/core/snapshot.js +214 -0
- package/dist/core/snapshot.js.map +1 -0
- package/dist/core/snapshot.test.js +101 -0
- package/dist/core/snapshot.test.js.map +1 -0
- package/dist/core/stats.js +119 -0
- package/dist/core/stats.js.map +1 -0
- package/dist/core/stats.test.js +86 -0
- package/dist/core/stats.test.js.map +1 -0
- package/dist/core/suppressions.js +96 -0
- package/dist/core/suppressions.js.map +1 -0
- package/dist/core/suppressions.test.js +90 -0
- package/dist/core/suppressions.test.js.map +1 -0
- package/dist/core/test-delta.js +53 -0
- package/dist/core/test-delta.js.map +1 -0
- package/dist/core/test-delta.test.js +41 -0
- package/dist/core/test-delta.test.js.map +1 -0
- package/dist/core/test-plan.js +212 -0
- package/dist/core/test-plan.js.map +1 -0
- package/dist/core/test-plan.test.js +94 -0
- package/dist/core/test-plan.test.js.map +1 -0
- package/dist/core/test-weakening.js +191 -0
- package/dist/core/test-weakening.js.map +1 -0
- package/dist/core/test-weakening.test.js +114 -0
- package/dist/core/test-weakening.test.js.map +1 -0
- package/dist/core/tree-scan.js +77 -0
- package/dist/core/tree-scan.js.map +1 -0
- package/dist/core/tree-scan.test.js +58 -0
- package/dist/core/tree-scan.test.js.map +1 -0
- package/dist/mcp-prompts.test.js +133 -0
- package/dist/mcp-prompts.test.js.map +1 -0
- package/dist/mcp.js +3303 -240
- package/dist/mcp.js.map +1 -1
- package/dist/mcp.test.js +1739 -1
- package/dist/mcp.test.js.map +1 -1
- package/dist/skills.test.js +221 -0
- package/dist/skills.test.js.map +1 -0
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/docs/integrations.md +151 -7
- package/package.json +2 -1
- package/prompts/oc-pilot.en.md +8 -1
- package/prompts/oc-pilot.ru.md +8 -1
- package/server.json +2 -2
- package/skills/agent-self-review/SKILL.md +87 -0
- package/skills/commit-discipline/SKILL.md +86 -0
- package/skills/oc-pilot/SKILL.md +86 -0
- package/skills/secure-diff-gate/SKILL.md +101 -0
- package/skills/stack-review-packs/SKILL.md +76 -0
- package/skills/test-failure-triage/SKILL.md +88 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dependency provenance: answers "why is this package here?" from local data only.
|
|
3
|
+
* Combines the manifest, the imports in the code and the lockfile graph, so an
|
|
4
|
+
* agent can see direct imports, every dependent package and the chains that pull
|
|
5
|
+
* a transitive dependency in. Offline and deterministic.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { packageNameOf } from "./deps-health.js";
|
|
10
|
+
import { PilotError } from "./errors.js";
|
|
11
|
+
import { readLockfile } from "./lockfile.js";
|
|
12
|
+
import { readRepository } from "./slop/collect.js";
|
|
13
|
+
const IMPORT_PATTERNS = [
|
|
14
|
+
/\bfrom\s+["']([^"']+)["']/g,
|
|
15
|
+
/\brequire\s*\(\s*["']([^"']+)["']\s*\)/g,
|
|
16
|
+
/\bimport\s*\(\s*["']([^"']+)["']\s*\)/g,
|
|
17
|
+
/\bimport\s+["']([^"']+)["']/g,
|
|
18
|
+
];
|
|
19
|
+
function readJsonFile(path) {
|
|
20
|
+
try {
|
|
21
|
+
return JSON.parse(readFileSync(path, "utf8").replace(/^\uFEFF/, ""));
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function recordOf(value) {
|
|
28
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
29
|
+
}
|
|
30
|
+
function manifestFields(manifest) {
|
|
31
|
+
return [
|
|
32
|
+
["prod", recordOf(manifest.dependencies)],
|
|
33
|
+
["dev", recordOf(manifest.devDependencies)],
|
|
34
|
+
["optional", recordOf(manifest.optionalDependencies)],
|
|
35
|
+
["peer", recordOf(manifest.peerDependencies)],
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
function readManifest(cwd) {
|
|
39
|
+
const path = join(cwd, "package.json");
|
|
40
|
+
if (!existsSync(path)) {
|
|
41
|
+
throw new PilotError("package.json не найден", {
|
|
42
|
+
hint: "Запустите команду в корне npm-проекта или укажите --cwd.",
|
|
43
|
+
exitCode: 2,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const parsed = readJsonFile(path);
|
|
47
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
48
|
+
throw new PilotError("Не удалось прочитать package.json", {
|
|
49
|
+
hint: "Проверьте, что файл содержит корректный JSON.",
|
|
50
|
+
exitCode: 2,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return parsed;
|
|
54
|
+
}
|
|
55
|
+
function nameFromKey(key) {
|
|
56
|
+
const match = /(?:^|\/)node_modules\/((?:@[^/]+\/)?[^/]+)$/.exec(key);
|
|
57
|
+
return match?.[1];
|
|
58
|
+
}
|
|
59
|
+
function loadV1(deps, parentKey, nodes) {
|
|
60
|
+
for (const [name, raw] of Object.entries(deps ?? {})) {
|
|
61
|
+
if (!raw || typeof raw !== "object")
|
|
62
|
+
continue;
|
|
63
|
+
const entry = raw;
|
|
64
|
+
const key = parentKey ? `${parentKey}/node_modules/${name}` : `node_modules/${name}`;
|
|
65
|
+
nodes.set(key, {
|
|
66
|
+
name,
|
|
67
|
+
version: typeof entry.version === "string" ? entry.version : undefined,
|
|
68
|
+
deps: recordOf(entry.dependencies),
|
|
69
|
+
});
|
|
70
|
+
loadV1(entry.dependencies, key, nodes);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function lockNodes(lock) {
|
|
74
|
+
const nodes = new Map();
|
|
75
|
+
if (!lock || typeof lock !== "object")
|
|
76
|
+
return nodes;
|
|
77
|
+
const packages = lock.packages;
|
|
78
|
+
if (packages && typeof packages === "object" && !Array.isArray(packages)) {
|
|
79
|
+
for (const [key, raw] of Object.entries(packages)) {
|
|
80
|
+
if (!key || !raw || typeof raw !== "object")
|
|
81
|
+
continue;
|
|
82
|
+
const name = nameFromKey(key);
|
|
83
|
+
if (!name)
|
|
84
|
+
continue;
|
|
85
|
+
const entry = raw;
|
|
86
|
+
nodes.set(key, {
|
|
87
|
+
name,
|
|
88
|
+
version: typeof entry.version === "string" ? entry.version : undefined,
|
|
89
|
+
deps: { ...recordOf(entry.dependencies), ...recordOf(entry.optionalDependencies) },
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return nodes;
|
|
93
|
+
}
|
|
94
|
+
loadV1(lock.dependencies, "", nodes);
|
|
95
|
+
return nodes;
|
|
96
|
+
}
|
|
97
|
+
/** pnpm and yarn lockfiles list every resolved package by name, without nesting. */
|
|
98
|
+
function flatNodes(packages) {
|
|
99
|
+
const nodes = new Map();
|
|
100
|
+
for (const entry of packages) {
|
|
101
|
+
if (!nodes.has(entry.name)) {
|
|
102
|
+
nodes.set(entry.name, { name: entry.name, version: entry.version, deps: entry.deps });
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return nodes;
|
|
106
|
+
}
|
|
107
|
+
/** npm resolution: nested copy first, then walk up to the root node_modules. */
|
|
108
|
+
function resolveKey(nodes, fromKey, dep) {
|
|
109
|
+
// Flat lockfiles (pnpm, yarn) are keyed by package name.
|
|
110
|
+
if (nodes.has(dep))
|
|
111
|
+
return dep;
|
|
112
|
+
let current = fromKey;
|
|
113
|
+
while (current) {
|
|
114
|
+
const candidate = `${current}/node_modules/${dep}`;
|
|
115
|
+
if (nodes.has(candidate))
|
|
116
|
+
return candidate;
|
|
117
|
+
const index = current.lastIndexOf("/node_modules/");
|
|
118
|
+
if (index <= 0)
|
|
119
|
+
break;
|
|
120
|
+
current = current.slice(0, index);
|
|
121
|
+
}
|
|
122
|
+
const root = `node_modules/${dep}`;
|
|
123
|
+
return nodes.has(root) ? root : undefined;
|
|
124
|
+
}
|
|
125
|
+
function rootDependencies(manifest) {
|
|
126
|
+
const names = new Set();
|
|
127
|
+
for (const [, record] of manifestFields(manifest)) {
|
|
128
|
+
for (const name of Object.keys(record))
|
|
129
|
+
names.add(name);
|
|
130
|
+
}
|
|
131
|
+
return [...names];
|
|
132
|
+
}
|
|
133
|
+
function collectChains(nodes, roots, target, maxChains, maxDepth) {
|
|
134
|
+
const chains = [];
|
|
135
|
+
const queue = [];
|
|
136
|
+
for (const dep of roots) {
|
|
137
|
+
const key = resolveKey(nodes, "", dep);
|
|
138
|
+
if (!key)
|
|
139
|
+
continue;
|
|
140
|
+
const node = nodes.get(key);
|
|
141
|
+
queue.push({ key, path: [node.name] });
|
|
142
|
+
}
|
|
143
|
+
while (queue.length > 0 && chains.length < maxChains) {
|
|
144
|
+
const item = queue.shift();
|
|
145
|
+
const node = nodes.get(item.key);
|
|
146
|
+
if (node.name === target) {
|
|
147
|
+
chains.push(item.path);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (item.path.length >= maxDepth)
|
|
151
|
+
continue;
|
|
152
|
+
for (const dep of Object.keys(node.deps)) {
|
|
153
|
+
const childKey = resolveKey(nodes, item.key, dep);
|
|
154
|
+
if (!childKey)
|
|
155
|
+
continue;
|
|
156
|
+
const child = nodes.get(childKey);
|
|
157
|
+
if (item.path.includes(child.name))
|
|
158
|
+
continue;
|
|
159
|
+
queue.push({ key: childKey, path: [...item.path, child.name] });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return chains;
|
|
163
|
+
}
|
|
164
|
+
function importedBy(cwd, name) {
|
|
165
|
+
const files = readRepository(cwd).files;
|
|
166
|
+
const paths = new Set();
|
|
167
|
+
for (const file of files) {
|
|
168
|
+
for (const pattern of IMPORT_PATTERNS) {
|
|
169
|
+
pattern.lastIndex = 0;
|
|
170
|
+
let match;
|
|
171
|
+
while ((match = pattern.exec(file.text)) !== null) {
|
|
172
|
+
if (packageNameOf(match[1] ?? "") === name) {
|
|
173
|
+
paths.add(file.path);
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (paths.has(file.path))
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return [...paths].sort();
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Explains where a package comes from. Returns undefined when the name appears
|
|
185
|
+
* nowhere: not declared, not imported and not installed per the lockfile.
|
|
186
|
+
*/
|
|
187
|
+
export function explainDependency(cwd, name, options = {}) {
|
|
188
|
+
const packageName = name.trim();
|
|
189
|
+
if (!packageName)
|
|
190
|
+
throw new PilotError("Не указано имя пакета для --why", { exitCode: 2 });
|
|
191
|
+
const manifest = readManifest(cwd);
|
|
192
|
+
const declaredEntry = manifestFields(manifest)
|
|
193
|
+
.map(([field, record]) => ({ field, spec: record[packageName] }))
|
|
194
|
+
.find((entry) => entry.spec !== undefined);
|
|
195
|
+
const lock = readLockfile(cwd);
|
|
196
|
+
const npmNodes = lock?.kind === "npm" ? lockNodes(readJsonFile(join(cwd, lock.file))) : undefined;
|
|
197
|
+
const nodes = npmNodes ?? flatNodes(lock?.packages ?? []);
|
|
198
|
+
const installed = npmNodes
|
|
199
|
+
? [...npmNodes.values()].filter((node) => node.name === packageName)
|
|
200
|
+
: (lock?.packages ?? [])
|
|
201
|
+
.filter((entry) => entry.name === packageName)
|
|
202
|
+
.map((entry) => ({ name: entry.name, version: entry.version, deps: entry.deps }));
|
|
203
|
+
const imports = importedBy(cwd, packageName);
|
|
204
|
+
if (!declaredEntry && installed.length === 0 && imports.length === 0)
|
|
205
|
+
return undefined;
|
|
206
|
+
const versions = [...new Set(installed.map((node) => node.version).filter((value) => Boolean(value)))].sort();
|
|
207
|
+
const dependents = new Set();
|
|
208
|
+
for (const [, node] of nodes) {
|
|
209
|
+
if (node.name === packageName)
|
|
210
|
+
continue;
|
|
211
|
+
if (Object.keys(node.deps).includes(packageName))
|
|
212
|
+
dependents.add(node.name);
|
|
213
|
+
}
|
|
214
|
+
const roots = rootDependencies(manifest);
|
|
215
|
+
const chains = installed.length > 0
|
|
216
|
+
? collectChains(nodes, roots, packageName, options.maxChains ?? 5, options.maxDepth ?? 10)
|
|
217
|
+
: [];
|
|
218
|
+
const declared = declaredEntry ? { field: declaredEntry.field, spec: declaredEntry.spec } : null;
|
|
219
|
+
return {
|
|
220
|
+
name: packageName,
|
|
221
|
+
versions,
|
|
222
|
+
copies: installed.length,
|
|
223
|
+
declared,
|
|
224
|
+
importedBy: imports,
|
|
225
|
+
dependents: [...dependents].sort(),
|
|
226
|
+
chains,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
/** Human-readable report for the terminal. */
|
|
230
|
+
export function renderDependencyWhy(result) {
|
|
231
|
+
const fields = {
|
|
232
|
+
prod: "dependencies",
|
|
233
|
+
dev: "devDependencies",
|
|
234
|
+
optional: "optionalDependencies",
|
|
235
|
+
peer: "peerDependencies",
|
|
236
|
+
};
|
|
237
|
+
const lines = [`Пакет: ${result.name}`];
|
|
238
|
+
if (result.copies > 0) {
|
|
239
|
+
const copies = result.copies === 1 ? "1 копия" : `${result.copies} копии`;
|
|
240
|
+
lines.push(`Версии в lockfile: ${result.versions.join(", ") || "без версии"} (${copies})`);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
lines.push("В lockfile не найден");
|
|
244
|
+
}
|
|
245
|
+
lines.push(result.declared
|
|
246
|
+
? `Объявлен: ${fields[result.declared.field]} ${result.declared.spec}`
|
|
247
|
+
: "В package.json не объявлен");
|
|
248
|
+
lines.push(result.importedBy.length > 0 ? `Импортируется: ${result.importedBy.join(", ")}` : "Прямых импортов нет");
|
|
249
|
+
lines.push(result.dependents.length > 0 ? `Зависит от него: ${result.dependents.join(", ")}` : "Никто не зависит");
|
|
250
|
+
if (result.chains.length > 0) {
|
|
251
|
+
lines.push("Цепочки от корня:");
|
|
252
|
+
for (const chain of result.chains)
|
|
253
|
+
lines.push(` ${chain.join(" → ")}`);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
lines.push("Цепочки от корня: нет — из package.json пакет недостижим");
|
|
257
|
+
}
|
|
258
|
+
return `${lines.join("\n")}\n`;
|
|
259
|
+
}
|
|
260
|
+
//# sourceMappingURL=deps-why.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deps-why.js","sourceRoot":"","sources":["../../src/core/deps-why.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,aAAa,EAAiB,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAkCnD,MAAM,eAAe,GAAG;IACtB,4BAA4B;IAC5B,yCAAyC;IACzC,wCAAwC;IACxC,8BAA8B;CAC/B,CAAC;AAEF,SAAS,YAAY,CAAC,IAAY;IAChC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC;IACvE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAE,KAAgC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC9G,CAAC;AAED,SAAS,cAAc,CAAC,QAAyB;IAC/C,OAAO;QACL,CAAC,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;QACzC,CAAC,KAAK,EAAE,QAAQ,CAAC,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AAC;IACzE,CAAC;IACD,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { dirname, join } from "node:path";
|
|
6
|
+
import test from "node:test";
|
|
7
|
+
import { explainDependency, renderDependencyWhy } from "./deps-why.js";
|
|
8
|
+
function makeRepo(files) {
|
|
9
|
+
const dir = mkdtempSync(join(tmpdir(), "oc-pilot-deps-why-"));
|
|
10
|
+
spawnSync("git", ["init", "-q"], { cwd: dir });
|
|
11
|
+
for (const [path, text] of Object.entries(files)) {
|
|
12
|
+
const target = join(dir, path);
|
|
13
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
14
|
+
writeFileSync(target, text, "utf8");
|
|
15
|
+
}
|
|
16
|
+
return dir;
|
|
17
|
+
}
|
|
18
|
+
function manifest(value) {
|
|
19
|
+
return JSON.stringify({ name: "demo", private: true, ...value }, null, 2);
|
|
20
|
+
}
|
|
21
|
+
function lockfile(packages) {
|
|
22
|
+
return JSON.stringify({ name: "demo", lockfileVersion: 3, packages: { "": { name: "demo" }, ...packages } }, null, 2);
|
|
23
|
+
}
|
|
24
|
+
test("explainDependency follows a transitive chain from package.json", () => {
|
|
25
|
+
const dir = makeRepo({
|
|
26
|
+
"package.json": manifest({ dependencies: { express: "^4.18.0" } }),
|
|
27
|
+
"package-lock.json": lockfile({
|
|
28
|
+
"node_modules/express": { version: "4.18.2", dependencies: { "body-parser": "1.20.1" } },
|
|
29
|
+
"node_modules/body-parser": { version: "1.20.1", dependencies: { qs: "6.11.0" } },
|
|
30
|
+
"node_modules/qs": { version: "6.11.0" },
|
|
31
|
+
}),
|
|
32
|
+
"src/app.ts": 'import express from "express";\n',
|
|
33
|
+
});
|
|
34
|
+
try {
|
|
35
|
+
const why = explainDependency(dir, "qs");
|
|
36
|
+
assert.ok(why);
|
|
37
|
+
assert.deepEqual(why.versions, ["6.11.0"]);
|
|
38
|
+
assert.equal(why.copies, 1);
|
|
39
|
+
assert.equal(why.declared, null);
|
|
40
|
+
assert.deepEqual(why.importedBy, []);
|
|
41
|
+
assert.deepEqual(why.dependents, ["body-parser"]);
|
|
42
|
+
assert.deepEqual(why.chains, [["express", "body-parser", "qs"]]);
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
rmSync(dir, { recursive: true, force: true });
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
test("explainDependency reports a declared dev dependency and its import", () => {
|
|
49
|
+
const dir = makeRepo({
|
|
50
|
+
"package.json": manifest({ devDependencies: { vitest: "^1.6.0" } }),
|
|
51
|
+
"package-lock.json": lockfile({ "node_modules/vitest": { version: "1.6.0" } }),
|
|
52
|
+
"src/a.test.ts": 'import { test } from "vitest";\n',
|
|
53
|
+
});
|
|
54
|
+
try {
|
|
55
|
+
const why = explainDependency(dir, "vitest");
|
|
56
|
+
assert.ok(why);
|
|
57
|
+
assert.deepEqual(why.declared, { field: "dev", spec: "^1.6.0" });
|
|
58
|
+
assert.deepEqual(why.importedBy, ["src/a.test.ts"]);
|
|
59
|
+
assert.deepEqual(why.chains, [["vitest"]]);
|
|
60
|
+
assert.deepEqual(why.dependents, []);
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
rmSync(dir, { recursive: true, force: true });
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
test("explainDependency counts nested copies and resolves each chain", () => {
|
|
67
|
+
const dir = makeRepo({
|
|
68
|
+
"package.json": manifest({ dependencies: { a: "^1.0.0", b: "^1.0.0" } }),
|
|
69
|
+
"package-lock.json": lockfile({
|
|
70
|
+
"node_modules/a": { version: "1.0.0", dependencies: { shared: "^2.0.0" } },
|
|
71
|
+
"node_modules/a/node_modules/shared": { version: "2.0.0" },
|
|
72
|
+
"node_modules/b": { version: "1.0.0", dependencies: { shared: "^1.0.0" } },
|
|
73
|
+
"node_modules/shared": { version: "1.0.0" },
|
|
74
|
+
}),
|
|
75
|
+
"src/app.ts": 'import a from "a";\nimport b from "b";\n',
|
|
76
|
+
});
|
|
77
|
+
try {
|
|
78
|
+
const why = explainDependency(dir, "shared");
|
|
79
|
+
assert.ok(why);
|
|
80
|
+
assert.equal(why.copies, 2);
|
|
81
|
+
assert.deepEqual(why.versions, ["1.0.0", "2.0.0"]);
|
|
82
|
+
assert.deepEqual(why.dependents, ["a", "b"]);
|
|
83
|
+
assert.deepEqual(why.chains, [
|
|
84
|
+
["a", "shared"],
|
|
85
|
+
["b", "shared"],
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
rmSync(dir, { recursive: true, force: true });
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
test("explainDependency reads a v1 lockfile tree", () => {
|
|
93
|
+
const dir = makeRepo({
|
|
94
|
+
"package.json": manifest({ dependencies: { express: "^4.18.0" } }),
|
|
95
|
+
"package-lock.json": JSON.stringify({
|
|
96
|
+
name: "demo",
|
|
97
|
+
lockfileVersion: 1,
|
|
98
|
+
dependencies: {
|
|
99
|
+
express: { version: "4.18.2", dependencies: { qs: { version: "6.11.0" } } },
|
|
100
|
+
},
|
|
101
|
+
}),
|
|
102
|
+
"src/app.ts": 'const express = require("express");\n',
|
|
103
|
+
});
|
|
104
|
+
try {
|
|
105
|
+
const why = explainDependency(dir, "qs");
|
|
106
|
+
assert.ok(why);
|
|
107
|
+
assert.deepEqual(why.versions, ["6.11.0"]);
|
|
108
|
+
assert.deepEqual(why.chains, [["express", "qs"]]);
|
|
109
|
+
assert.deepEqual(why.importedBy, []);
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
rmSync(dir, { recursive: true, force: true });
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
test("explainDependency returns undefined for a package that is nowhere", () => {
|
|
116
|
+
const dir = makeRepo({
|
|
117
|
+
"package.json": manifest({ dependencies: { react: "^18.0.0" } }),
|
|
118
|
+
"src/app.ts": 'import react from "react";\n',
|
|
119
|
+
});
|
|
120
|
+
try {
|
|
121
|
+
assert.equal(explainDependency(dir, "left-pad"), undefined);
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
rmSync(dir, { recursive: true, force: true });
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
test("explainDependency handles a declared package without a lockfile", () => {
|
|
128
|
+
const dir = makeRepo({
|
|
129
|
+
"package.json": manifest({ dependencies: { react: "^18.0.0" } }),
|
|
130
|
+
"src/app.ts": 'import react from "react";\n',
|
|
131
|
+
});
|
|
132
|
+
try {
|
|
133
|
+
const why = explainDependency(dir, "react");
|
|
134
|
+
assert.ok(why);
|
|
135
|
+
assert.deepEqual(why.declared, { field: "prod", spec: "^18.0.0" });
|
|
136
|
+
assert.equal(why.copies, 0);
|
|
137
|
+
assert.deepEqual(why.versions, []);
|
|
138
|
+
assert.deepEqual(why.chains, []);
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
rmSync(dir, { recursive: true, force: true });
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
test("explainDependency rejects an empty package name", () => {
|
|
145
|
+
const dir = makeRepo({ "package.json": manifest({}) });
|
|
146
|
+
try {
|
|
147
|
+
assert.throws(() => explainDependency(dir, " "), /Не указано имя пакета/);
|
|
148
|
+
}
|
|
149
|
+
finally {
|
|
150
|
+
rmSync(dir, { recursive: true, force: true });
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
test("renderDependencyWhy prints chains and declaration", () => {
|
|
154
|
+
const dir = makeRepo({
|
|
155
|
+
"package.json": manifest({ dependencies: { express: "^4.18.0" } }),
|
|
156
|
+
"package-lock.json": lockfile({
|
|
157
|
+
"node_modules/express": { version: "4.18.2", dependencies: { qs: "6.11.0" } },
|
|
158
|
+
"node_modules/qs": { version: "6.11.0" },
|
|
159
|
+
}),
|
|
160
|
+
});
|
|
161
|
+
try {
|
|
162
|
+
const why = explainDependency(dir, "qs");
|
|
163
|
+
assert.ok(why);
|
|
164
|
+
const text = renderDependencyWhy(why);
|
|
165
|
+
assert.match(text, /Пакет: qs/);
|
|
166
|
+
assert.match(text, /Версии в lockfile: 6\.11\.0 \(1 копия\)/);
|
|
167
|
+
assert.match(text, /В package\.json не объявлен/);
|
|
168
|
+
assert.match(text, /Зависит от него: express/);
|
|
169
|
+
assert.match(text, /express → qs/);
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
rmSync(dir, { recursive: true, force: true });
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
//# sourceMappingURL=deps-why.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deps-why.test.js","sourceRoot":"","sources":["../../src/core/deps-why.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAMvE,SAAS,QAAQ,CAAC,KAAgB;IAChC,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,oBAAoB,CAAC,CAAC,CAAC;IAC9D,SAAS,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;IAC/C,KAAK,MAAM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B,sBAAsB,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE;YAC7E,iBAAiB,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE;SACzC,CAAC;KACH,CAAC,CAAC;IACH,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,iBAAiB,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACzC,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;QACf,MAAM,IAAI,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC;QACtC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAChC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,yCAAyC,CAAC,CAAC;QAC9D,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,6BAA6B,CAAC,CAAC;QAClD,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,0BAA0B,CAAC,CAAC;QAC/C,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IACrC,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAChD,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
const POPULAR_PACKAGES = {
|
|
2
|
+
npm: [
|
|
3
|
+
"react", "react-dom", "vue", "express", "axios", "lodash", "underscore",
|
|
4
|
+
"chalk", "commander", "typescript", "webpack", "vite", "jest", "mocha",
|
|
5
|
+
"eslint", "prettier", "dotenv", "mongoose", "sequelize", "prisma",
|
|
6
|
+
"next", "svelte", "zod", "uuid", "glob", "minimist", "qs", "cross-env",
|
|
7
|
+
"nanoid", "fs-extra", "dayjs", "moment", "ramda", "jquery", "core-js",
|
|
8
|
+
"tslib", "got", "node-fetch", "yaml", "joi", "winston", "pino",
|
|
9
|
+
],
|
|
10
|
+
pypi: [
|
|
11
|
+
"requests", "flask", "django", "numpy", "pandas", "pytest", "urllib3",
|
|
12
|
+
"cryptography", "pyyaml", "sqlalchemy", "pillow", "click", "fastapi",
|
|
13
|
+
"httpx", "aiohttp", "boto3", "botocore", "redis", "celery", "marshmallow",
|
|
14
|
+
],
|
|
15
|
+
};
|
|
16
|
+
function levenshtein(a, b) {
|
|
17
|
+
if (a === b)
|
|
18
|
+
return 0;
|
|
19
|
+
if (a.length === 0)
|
|
20
|
+
return b.length;
|
|
21
|
+
if (b.length === 0)
|
|
22
|
+
return a.length;
|
|
23
|
+
let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
24
|
+
for (let i = 1; i <= a.length; i += 1) {
|
|
25
|
+
const current = [i];
|
|
26
|
+
for (let j = 1; j <= b.length; j += 1) {
|
|
27
|
+
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
28
|
+
current[j] = Math.min(current[j - 1] + 1, previous[j] + 1, previous[j - 1] + cost);
|
|
29
|
+
}
|
|
30
|
+
previous = current;
|
|
31
|
+
}
|
|
32
|
+
return previous[b.length];
|
|
33
|
+
}
|
|
34
|
+
/** Near-match against well-known package names (edit distance 1-2, length >= 4). */
|
|
35
|
+
function typosquatOf(name, ecosystem) {
|
|
36
|
+
const popular = POPULAR_PACKAGES[ecosystem];
|
|
37
|
+
if (!popular || name.length < 4)
|
|
38
|
+
return undefined;
|
|
39
|
+
for (const candidate of popular) {
|
|
40
|
+
if (candidate === name)
|
|
41
|
+
return undefined;
|
|
42
|
+
const distance = levenshtein(name, candidate);
|
|
43
|
+
if (distance > 0 && distance <= 2 && Math.abs(name.length - candidate.length) <= 2) {
|
|
44
|
+
return candidate;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
function specRisks(spec) {
|
|
50
|
+
const risks = [];
|
|
51
|
+
const value = spec.trim();
|
|
52
|
+
if (value === "" || value === "*" || value === "latest")
|
|
53
|
+
risks.push("unpinned");
|
|
54
|
+
if (/^(git\+|github:|git@|https?:\/\/|file:)/i.test(value))
|
|
55
|
+
risks.push("vcs-or-url reference");
|
|
56
|
+
return risks;
|
|
57
|
+
}
|
|
58
|
+
const JSON_DEPENDENCY_LINE = /^\+\s*"([^"@][^"]*)"\s*:\s*"([^"]*)"/;
|
|
59
|
+
const MANIFESTS = [
|
|
60
|
+
{
|
|
61
|
+
ecosystem: "npm",
|
|
62
|
+
match: (file) => file.endsWith("package.json") || file.endsWith("package-lock.json") === false && file.endsWith("npm-shrinkwrap.json") === false && /(^|\/)package\.json$/.test(file),
|
|
63
|
+
parse: (line) => {
|
|
64
|
+
const match = JSON_DEPENDENCY_LINE.exec(line);
|
|
65
|
+
if (!match)
|
|
66
|
+
return undefined;
|
|
67
|
+
const name = match[1].trim();
|
|
68
|
+
if (!name || name.startsWith("@types/") === false && !/^[@a-zA-Z]/.test(name))
|
|
69
|
+
return undefined;
|
|
70
|
+
return { name, spec: match[2] };
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
ecosystem: "pypi",
|
|
75
|
+
match: (file) => file === "requirements.txt" || file.endsWith("/requirements.txt") || file.endsWith("pyproject.toml"),
|
|
76
|
+
parse: (line) => {
|
|
77
|
+
const requirement = /^\+\s*([A-Za-z0-9_.\-]+)\s*(?:[=<>~!]=?|\[)[^\s]*/.exec(line);
|
|
78
|
+
if (requirement)
|
|
79
|
+
return { name: requirement[1], spec: line.slice(1).trim() };
|
|
80
|
+
const pyproject = /^\+\s*([A-Za-z0-9_.\-]+)\s*=\s*"[^"]*"/.exec(line);
|
|
81
|
+
if (pyproject)
|
|
82
|
+
return { name: pyproject[1], spec: line.slice(1).trim() };
|
|
83
|
+
return undefined;
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
ecosystem: "go",
|
|
88
|
+
match: (file) => file === "go.mod" || file.endsWith("/go.mod"),
|
|
89
|
+
parse: (line) => {
|
|
90
|
+
const require = /^\+\s*([\w./~-]+)\s+(v[\w.\-+]+)/.exec(line);
|
|
91
|
+
return require ? { name: require[1], spec: require[2] } : undefined;
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
ecosystem: "cargo",
|
|
96
|
+
match: (file) => file === "Cargo.toml" || file.endsWith("/Cargo.toml"),
|
|
97
|
+
parse: (line) => {
|
|
98
|
+
const crate = /^\+\s*([\w-]+)\s*=\s*(".*|\{.*)/.exec(line);
|
|
99
|
+
return crate ? { name: crate[1], spec: line.slice(1).trim() } : undefined;
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
ecosystem: "rubygems",
|
|
104
|
+
match: (file) => file === "Gemfile" || file.endsWith("/Gemfile"),
|
|
105
|
+
parse: (line) => {
|
|
106
|
+
const gem = /^\+\s*gem\s+"([^"]+)"(.*)/.exec(line);
|
|
107
|
+
return gem ? { name: gem[1], spec: gem[2].trim().replace(/[",]/g, "") } : undefined;
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
ecosystem: "packagist",
|
|
112
|
+
match: (file) => file.endsWith("composer.json"),
|
|
113
|
+
parse: (line) => {
|
|
114
|
+
const match = JSON_DEPENDENCY_LINE.exec(line);
|
|
115
|
+
return match ? { name: match[1].trim(), spec: match[2] } : undefined;
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
ecosystem: "maven",
|
|
120
|
+
match: (file) => file.endsWith("pom.xml") || file.endsWith(".gradle") || file.endsWith(".gradle.kts"),
|
|
121
|
+
parse: (line) => {
|
|
122
|
+
const artifact = /^\+\s*(?:<artifactId>|["'])([\w.-]+)(?:<\/artifactId>|["'])/.exec(line);
|
|
123
|
+
return artifact ? { name: artifact[1], spec: "" } : undefined;
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
ecosystem: "nuget",
|
|
128
|
+
match: (file) => file.endsWith(".csproj") || file.endsWith("packages.config"),
|
|
129
|
+
parse: (line) => {
|
|
130
|
+
const reference = /^\+\s*<PackageReference\s+Include="([^"]+)"/.exec(line);
|
|
131
|
+
if (reference)
|
|
132
|
+
return { name: reference[1], spec: "" };
|
|
133
|
+
const legacy = /^\+\s*<package\s+id="([^"]+)"/.exec(line);
|
|
134
|
+
return legacy ? { name: legacy[1], spec: "" } : undefined;
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
];
|
|
138
|
+
const MAX_DEPENDENCY_FINDINGS = 50;
|
|
139
|
+
/** Scans a unified diff for added dependency declarations and risk signals. */
|
|
140
|
+
export function analyzeDependencyChanges(diff) {
|
|
141
|
+
const findings = [];
|
|
142
|
+
const seen = new Set();
|
|
143
|
+
let file = "";
|
|
144
|
+
for (const rawLine of diff.split(/\r?\n/)) {
|
|
145
|
+
if (rawLine.startsWith("+++ ")) {
|
|
146
|
+
file = rawLine.slice(4).replace(/^b\//, "").trim();
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
if (!rawLine.startsWith("+") || rawLine.startsWith("+++"))
|
|
150
|
+
continue;
|
|
151
|
+
if (file === "/dev/null")
|
|
152
|
+
continue;
|
|
153
|
+
const manifest = MANIFESTS.find((rule) => rule.match(file));
|
|
154
|
+
if (!manifest)
|
|
155
|
+
continue;
|
|
156
|
+
const parsed = manifest.parse(rawLine);
|
|
157
|
+
if (!parsed)
|
|
158
|
+
continue;
|
|
159
|
+
const risks = ["new dependency", ...specRisks(parsed.spec)];
|
|
160
|
+
const typosquat = typosquatOf(parsed.name, manifest.ecosystem);
|
|
161
|
+
if (typosquat)
|
|
162
|
+
risks.push(`possible typosquat of ${typosquat}`);
|
|
163
|
+
const key = `${manifest.ecosystem}:${parsed.name}`;
|
|
164
|
+
if (seen.has(key))
|
|
165
|
+
continue;
|
|
166
|
+
seen.add(key);
|
|
167
|
+
findings.push({ ecosystem: manifest.ecosystem, name: parsed.name, spec: parsed.spec, risks, file });
|
|
168
|
+
if (findings.length >= MAX_DEPENDENCY_FINDINGS)
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
return findings;
|
|
172
|
+
}
|
|
173
|
+
/** Renders findings for the prompt context block. */
|
|
174
|
+
export function describeDependencyFindings(findings) {
|
|
175
|
+
return findings
|
|
176
|
+
.map((finding) => `- ${finding.ecosystem}: ${finding.name}${finding.spec ? ` (${finding.spec})` : ""} — ${finding.risks.join(", ")}`)
|
|
177
|
+
.join("\n");
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=deps.js.map
|