octocode-cli 1.2.6 → 1.2.8
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 +21 -63
- package/README.md +85 -142
- package/out/octocode-cli.js +7063 -6934
- package/package.json +8 -6
- package/skills/README.md +97 -120
- package/skills/octocode-code-engineer/.claude/settings.local.json +18 -0
- package/skills/octocode-code-engineer/.octocode/rfc/RFC-code-engineer-weakness-fixes.md +255 -0
- package/skills/octocode-code-engineer/.plan/VALIDATED_PLAN.md +223 -0
- package/skills/octocode-code-engineer/README.md +178 -0
- package/skills/octocode-code-engineer/SKILL.md +418 -0
- package/skills/octocode-code-engineer/coverage/architecture.ts.html +7828 -0
- package/skills/octocode-code-engineer/coverage/ast-helpers.ts.html +211 -0
- package/skills/octocode-code-engineer/coverage/ast-search.ts.html +1795 -0
- package/skills/octocode-code-engineer/coverage/base.css +224 -0
- package/skills/octocode-code-engineer/coverage/block-navigation.js +87 -0
- package/skills/octocode-code-engineer/coverage/cache.ts.html +376 -0
- package/skills/octocode-code-engineer/coverage/cli.ts.html +982 -0
- package/skills/octocode-code-engineer/coverage/clover.xml +3217 -0
- package/skills/octocode-code-engineer/coverage/collect-effects.ts.html +664 -0
- package/skills/octocode-code-engineer/coverage/collect-input-sources.ts.html +577 -0
- package/skills/octocode-code-engineer/coverage/collect-performance.ts.html +331 -0
- package/skills/octocode-code-engineer/coverage/collect-prototype-pollution.ts.html +421 -0
- package/skills/octocode-code-engineer/coverage/collect-security.ts.html +604 -0
- package/skills/octocode-code-engineer/coverage/collect-test-profile.ts.html +589 -0
- package/skills/octocode-code-engineer/coverage/coverage-final.json +30 -0
- package/skills/octocode-code-engineer/coverage/dependencies.ts.html +997 -0
- package/skills/octocode-code-engineer/coverage/dependency-summary.ts.html +688 -0
- package/skills/octocode-code-engineer/coverage/discovery.ts.html +322 -0
- package/skills/octocode-code-engineer/coverage/favicon.png +0 -0
- package/skills/octocode-code-engineer/coverage/graph-analytics.ts.html +1510 -0
- package/skills/octocode-code-engineer/coverage/index.html +536 -0
- package/skills/octocode-code-engineer/coverage/index.ts.html +826 -0
- package/skills/octocode-code-engineer/coverage/metrics.ts.html +553 -0
- package/skills/octocode-code-engineer/coverage/pipeline.ts.html +2044 -0
- package/skills/octocode-code-engineer/coverage/prettify.css +1 -0
- package/skills/octocode-code-engineer/coverage/prettify.js +2 -0
- package/skills/octocode-code-engineer/coverage/report-analysis.ts.html +1570 -0
- package/skills/octocode-code-engineer/coverage/report-writer.ts.html +1102 -0
- package/skills/octocode-code-engineer/coverage/security-detectors.ts.html +1747 -0
- package/skills/octocode-code-engineer/coverage/semantic-detectors.ts.html +2152 -0
- package/skills/octocode-code-engineer/coverage/semantic.ts.html +1897 -0
- package/skills/octocode-code-engineer/coverage/sort-arrow-sprite.png +0 -0
- package/skills/octocode-code-engineer/coverage/sorter.js +210 -0
- package/skills/octocode-code-engineer/coverage/summary-md.ts.html +1222 -0
- package/skills/octocode-code-engineer/coverage/test-quality-detectors.ts.html +1039 -0
- package/skills/octocode-code-engineer/coverage/tree-sitter-analyzer.ts.html +955 -0
- package/skills/octocode-code-engineer/coverage/ts-analyzer.ts.html +1213 -0
- package/skills/octocode-code-engineer/coverage/types.ts.html +2473 -0
- package/skills/octocode-code-engineer/coverage/utils.ts.html +820 -0
- package/skills/octocode-code-engineer/eslint.config.mjs +54 -0
- package/skills/octocode-code-engineer/minify-scripts.mjs +32 -0
- package/skills/octocode-code-engineer/package.json +54 -0
- package/skills/octocode-code-engineer/references/agent-ast-reading-rfc.md +95 -0
- package/skills/octocode-code-engineer/references/architecture-techniques.md +121 -0
- package/skills/octocode-code-engineer/references/ast-search.md +210 -0
- package/skills/octocode-code-engineer/references/ast-tree-search.md +151 -0
- package/skills/octocode-code-engineer/references/cli-reference.md +167 -0
- package/skills/octocode-code-engineer/references/concepts.md +107 -0
- package/skills/octocode-code-engineer/references/finding-categories.md +128 -0
- package/skills/octocode-code-engineer/references/improvement-roadmap.md +304 -0
- package/skills/octocode-code-engineer/references/output-files.md +144 -0
- package/skills/octocode-code-engineer/references/playbooks.md +204 -0
- package/skills/octocode-code-engineer/references/present-results.md +136 -0
- package/skills/octocode-code-engineer/references/tool-workflows.md +566 -0
- package/skills/octocode-code-engineer/references/validate-investigate.md +225 -0
- package/skills/octocode-code-engineer/scripts/analysis/dependencies.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/dependency-summary.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/discovery.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/graph-analytics.js +1 -0
- package/skills/octocode-code-engineer/scripts/analysis/semantic.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/helpers.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/metrics.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/search.js +2 -0
- package/skills/octocode-code-engineer/scripts/ast/tree-search.js +2 -0
- package/skills/octocode-code-engineer/scripts/ast/tree-sitter.js +1 -0
- package/skills/octocode-code-engineer/scripts/ast/ts-analyzer.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/chains.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/effects.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/input-sources.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/performance.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/prototype-pollution.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/security.js +1 -0
- package/skills/octocode-code-engineer/scripts/collectors/test-profile.js +1 -0
- package/skills/octocode-code-engineer/scripts/common/is-direct-run.js +1 -0
- package/skills/octocode-code-engineer/scripts/common/utils.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/code-quality.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/cohesion.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/coupling.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/cycle.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/dead-code.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/import-style.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/index.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/security.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/semantic.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/shared.js +1 -0
- package/skills/octocode-code-engineer/scripts/detectors/test-quality.js +1 -0
- package/skills/octocode-code-engineer/scripts/index.js +1 -0
- package/skills/octocode-code-engineer/scripts/pipeline/cache.js +1 -0
- package/skills/octocode-code-engineer/scripts/pipeline/cli.js +1 -0
- package/skills/octocode-code-engineer/scripts/pipeline/main.js +2 -0
- package/skills/octocode-code-engineer/scripts/reporting/analysis.js +1 -0
- package/skills/octocode-code-engineer/scripts/reporting/summary-md.js +1 -0
- package/skills/octocode-code-engineer/scripts/reporting/writer.js +1 -0
- package/skills/octocode-code-engineer/scripts/types/constants.js +1 -0
- package/skills/octocode-code-engineer/scripts/types/index.js +1 -0
- package/skills/octocode-code-engineer/scripts/types/interfaces.js +1 -0
- package/skills/octocode-code-engineer/src/analysis/dependencies.test.ts +545 -0
- package/skills/octocode-code-engineer/src/analysis/dependencies.ts +406 -0
- package/skills/octocode-code-engineer/src/analysis/dependency-summary.test.ts +566 -0
- package/skills/octocode-code-engineer/src/analysis/dependency-summary.ts +257 -0
- package/skills/octocode-code-engineer/src/analysis/discovery.test.ts +420 -0
- package/skills/octocode-code-engineer/src/analysis/discovery.ts +87 -0
- package/skills/octocode-code-engineer/src/analysis/graph-analytics.test.ts +449 -0
- package/skills/octocode-code-engineer/src/analysis/graph-analytics.ts +534 -0
- package/skills/octocode-code-engineer/src/analysis/semantic.test.ts +1533 -0
- package/skills/octocode-code-engineer/src/analysis/semantic.ts +830 -0
- package/skills/octocode-code-engineer/src/ast/helpers.test.ts +185 -0
- package/skills/octocode-code-engineer/src/ast/helpers.ts +62 -0
- package/skills/octocode-code-engineer/src/ast/metrics.test.ts +304 -0
- package/skills/octocode-code-engineer/src/ast/metrics.ts +204 -0
- package/skills/octocode-code-engineer/src/ast/search.test.ts +647 -0
- package/skills/octocode-code-engineer/src/ast/search.ts +648 -0
- package/skills/octocode-code-engineer/src/ast/tree-search.test.ts +199 -0
- package/skills/octocode-code-engineer/src/ast/tree-search.ts +392 -0
- package/skills/octocode-code-engineer/src/ast/tree-sitter.test.ts +407 -0
- package/skills/octocode-code-engineer/src/ast/tree-sitter.ts +402 -0
- package/skills/octocode-code-engineer/src/ast/ts-analyzer.test.ts +1864 -0
- package/skills/octocode-code-engineer/src/ast/ts-analyzer.ts +509 -0
- package/skills/octocode-code-engineer/src/collectors/chains.ts +74 -0
- package/skills/octocode-code-engineer/src/collectors/effects.test.ts +490 -0
- package/skills/octocode-code-engineer/src/collectors/effects.ts +332 -0
- package/skills/octocode-code-engineer/src/collectors/input-sources.test.ts +144 -0
- package/skills/octocode-code-engineer/src/collectors/input-sources.ts +196 -0
- package/skills/octocode-code-engineer/src/collectors/performance.test.ts +82 -0
- package/skills/octocode-code-engineer/src/collectors/performance.ts +141 -0
- package/skills/octocode-code-engineer/src/collectors/prototype-pollution.test.ts +55 -0
- package/skills/octocode-code-engineer/src/collectors/prototype-pollution.ts +162 -0
- package/skills/octocode-code-engineer/src/collectors/security.test.ts +124 -0
- package/skills/octocode-code-engineer/src/collectors/security.ts +309 -0
- package/skills/octocode-code-engineer/src/collectors/test-profile.test.ts +97 -0
- package/skills/octocode-code-engineer/src/collectors/test-profile.ts +269 -0
- package/skills/octocode-code-engineer/src/common/is-direct-run.test.ts +32 -0
- package/skills/octocode-code-engineer/src/common/is-direct-run.ts +13 -0
- package/skills/octocode-code-engineer/src/common/utils.test.ts +463 -0
- package/skills/octocode-code-engineer/src/common/utils.ts +304 -0
- package/skills/octocode-code-engineer/src/detectors/code-quality.ts +966 -0
- package/skills/octocode-code-engineer/src/detectors/cohesion.ts +539 -0
- package/skills/octocode-code-engineer/src/detectors/coupling.ts +323 -0
- package/skills/octocode-code-engineer/src/detectors/cycle.ts +349 -0
- package/skills/octocode-code-engineer/src/detectors/dead-code.ts +320 -0
- package/skills/octocode-code-engineer/src/detectors/import-style.ts +376 -0
- package/skills/octocode-code-engineer/src/detectors/index.test.ts +3061 -0
- package/skills/octocode-code-engineer/src/detectors/index.ts +88 -0
- package/skills/octocode-code-engineer/src/detectors/security.test.ts +882 -0
- package/skills/octocode-code-engineer/src/detectors/security.ts +821 -0
- package/skills/octocode-code-engineer/src/detectors/semantic.ts +758 -0
- package/skills/octocode-code-engineer/src/detectors/shared.ts +49 -0
- package/skills/octocode-code-engineer/src/detectors/test-quality.test.ts +388 -0
- package/skills/octocode-code-engineer/src/detectors/test-quality.ts +367 -0
- package/skills/octocode-code-engineer/src/index.test.ts +4425 -0
- package/skills/octocode-code-engineer/src/index.ts +403 -0
- package/skills/octocode-code-engineer/src/pipeline/cache.test.ts +199 -0
- package/skills/octocode-code-engineer/src/pipeline/cache.ts +130 -0
- package/skills/octocode-code-engineer/src/pipeline/cli.test.ts +493 -0
- package/skills/octocode-code-engineer/src/pipeline/cli.ts +344 -0
- package/skills/octocode-code-engineer/src/pipeline/main.test.ts +174 -0
- package/skills/octocode-code-engineer/src/pipeline/main.ts +1074 -0
- package/skills/octocode-code-engineer/src/pipeline.test.ts +84 -0
- package/skills/octocode-code-engineer/src/reporting/analysis.test.ts +782 -0
- package/skills/octocode-code-engineer/src/reporting/analysis.ts +688 -0
- package/skills/octocode-code-engineer/src/reporting/output-contract.test.ts +463 -0
- package/skills/octocode-code-engineer/src/reporting/summary-md.test.ts +421 -0
- package/skills/octocode-code-engineer/src/reporting/summary-md.ts +714 -0
- package/skills/octocode-code-engineer/src/reporting/writer.ts +430 -0
- package/skills/octocode-code-engineer/src/sanity.test.ts +47 -0
- package/skills/octocode-code-engineer/src/types/constants.ts +248 -0
- package/skills/octocode-code-engineer/src/types/index.ts +80 -0
- package/skills/octocode-code-engineer/src/types/interfaces.ts +682 -0
- package/skills/octocode-code-engineer/tsconfig.json +17 -0
- package/skills/octocode-code-engineer/vitest.config.ts +8 -0
- package/skills/octocode-documentation-writer/README.md +113 -0
- package/skills/octocode-documentation-writer/SKILL.md +886 -0
- package/skills/octocode-documentation-writer/references/agent-discovery-analysis.md +453 -0
- package/skills/octocode-documentation-writer/references/agent-documentation-writer.md +255 -0
- package/skills/octocode-documentation-writer/references/agent-engineer-questions.md +247 -0
- package/skills/octocode-documentation-writer/references/agent-orchestrator.md +370 -0
- package/skills/octocode-documentation-writer/references/agent-qa-validator.md +227 -0
- package/skills/octocode-documentation-writer/references/agent-researcher.md +250 -0
- package/skills/octocode-documentation-writer/schemas/analysis-schema.json +886 -0
- package/skills/octocode-documentation-writer/schemas/discovery-tasks.json +96 -0
- package/skills/octocode-documentation-writer/schemas/documentation-structure.json +373 -0
- package/skills/octocode-documentation-writer/schemas/partial-discovery-schema.json +102 -0
- package/skills/octocode-documentation-writer/schemas/partial-research-schema.json +98 -0
- package/skills/octocode-documentation-writer/schemas/qa-results-schema.json +113 -0
- package/skills/octocode-documentation-writer/schemas/questions-schema.json +228 -0
- package/skills/octocode-documentation-writer/schemas/research-schema.json +104 -0
- package/skills/octocode-documentation-writer/schemas/state-schema.json +222 -0
- package/skills/octocode-documentation-writer/schemas/work-assignments-schema.json +74 -0
- package/skills/octocode-plan/SKILL.md +122 -116
- package/skills/octocode-prompt-optimizer/SKILL.md +617 -0
- package/skills/octocode-pull-request-reviewer/README.md +249 -0
- package/skills/octocode-pull-request-reviewer/SKILL.md +479 -0
- package/skills/octocode-pull-request-reviewer/references/dependency-check.md +74 -0
- package/skills/octocode-pull-request-reviewer/references/domain-reviewers.md +24 -0
- package/skills/octocode-pull-request-reviewer/references/execution-lifecycle.md +441 -0
- package/skills/octocode-pull-request-reviewer/references/flow-analysis-protocol.md +64 -0
- package/skills/octocode-pull-request-reviewer/references/output-template.md +174 -0
- package/skills/octocode-pull-request-reviewer/references/parallel-agent-protocol.md +182 -0
- package/skills/octocode-pull-request-reviewer/references/review-guidelines.md +26 -0
- package/skills/octocode-pull-request-reviewer/references/verification-checklist.md +40 -0
- package/skills/octocode-research/.claude/settings.local.json +46 -0
- package/skills/octocode-research/.octocode/plan/code-review-fixes/plan.md +312 -0
- package/skills/octocode-research/.octocode/plan/code-review-fixes/research.md +212 -0
- package/skills/octocode-research/.octocode/plans/NODE_SERVER_START_PLAN.md +755 -0
- package/skills/octocode-research/.octocode/research/code-review/research.md +371 -0
- package/skills/octocode-research/.octocode/review/IMPROVEMENTS.md +391 -0
- package/skills/octocode-research/.octocode/review/REVIEW_PLAN.md +289 -0
- package/skills/octocode-research/.octocode/review/REVIEW_REPORT.md +356 -0
- package/skills/octocode-research/AGENTS.md +349 -0
- package/skills/octocode-research/README.md +494 -0
- package/skills/octocode-research/SKILL.md +652 -274
- package/skills/octocode-research/docs/API_REFERENCE.md +562 -0
- package/skills/octocode-research/docs/ARCHITECTURE.md +554 -0
- package/skills/octocode-research/docs/FLOWS.md +577 -0
- package/skills/octocode-research/docs/OVERVIEW.md +564 -0
- package/skills/octocode-research/docs/SERVER_FLOWS.md +631 -0
- package/skills/octocode-research/ecosystem.config.cjs +88 -0
- package/skills/octocode-research/eslint.config.mjs +27 -0
- package/skills/octocode-research/package.json +84 -0
- package/skills/octocode-research/references/GUARDRAILS.md +40 -0
- package/skills/octocode-research/references/PARALLEL_AGENT_PROTOCOL.md +178 -0
- package/skills/octocode-research/references/roast-prompt.md +149 -0
- package/skills/octocode-research/scripts/server-init.d.ts +2 -0
- package/skills/octocode-research/scripts/server-init.js +2 -0
- package/skills/octocode-research/scripts/server.d.ts +8 -0
- package/skills/octocode-research/scripts/server.js +445 -0
- package/skills/octocode-research/src/__tests__/integration/circuitBreaker.test.ts +205 -0
- package/skills/octocode-research/src/__tests__/integration/routes.test.ts +374 -0
- package/skills/octocode-research/src/__tests__/unit/circuitBreaker.test.ts +245 -0
- package/skills/octocode-research/src/__tests__/unit/errorHandler.test.ts +183 -0
- package/skills/octocode-research/src/__tests__/unit/httpPreprocess.test.ts +157 -0
- package/skills/octocode-research/src/__tests__/unit/logger.test.ts +143 -0
- package/skills/octocode-research/src/__tests__/unit/queryParser.test.ts +130 -0
- package/skills/octocode-research/src/__tests__/unit/responseBuilder.test.ts +469 -0
- package/skills/octocode-research/src/__tests__/unit/retry.test.ts +205 -0
- package/skills/octocode-research/src/index.ts +186 -0
- package/skills/octocode-research/src/mcpCache.ts +49 -0
- package/skills/octocode-research/src/middleware/errorHandler.ts +65 -0
- package/skills/octocode-research/src/middleware/logger.ts +61 -0
- package/skills/octocode-research/src/middleware/queryParser.ts +115 -0
- package/skills/octocode-research/src/middleware/readiness.ts +17 -0
- package/skills/octocode-research/src/routes/github.ts +197 -0
- package/skills/octocode-research/src/routes/local.ts +175 -0
- package/skills/octocode-research/src/routes/lsp.ts +177 -0
- package/skills/octocode-research/src/routes/package.ts +127 -0
- package/skills/octocode-research/src/routes/prompts.ts +138 -0
- package/skills/octocode-research/src/routes/tools.ts +677 -0
- package/skills/octocode-research/src/server-init.ts +363 -0
- package/skills/octocode-research/src/server.ts +285 -0
- package/skills/octocode-research/src/types/errorGuards.ts +151 -0
- package/skills/octocode-research/src/types/express.d.ts +76 -0
- package/skills/octocode-research/src/types/guards.ts +98 -0
- package/skills/octocode-research/src/types/mcp.ts +119 -0
- package/skills/octocode-research/src/types/responses.ts +199 -0
- package/skills/octocode-research/src/types/toolTypes.ts +33 -0
- package/skills/octocode-research/src/utils/asyncTimeout.ts +116 -0
- package/skills/octocode-research/src/utils/circuitBreaker.ts +492 -0
- package/skills/octocode-research/src/utils/colors.ts +53 -0
- package/skills/octocode-research/src/utils/errorQueue.ts +71 -0
- package/skills/octocode-research/src/utils/logEmoji.ts +103 -0
- package/skills/octocode-research/src/utils/logger.ts +413 -0
- package/skills/octocode-research/src/utils/resilience.ts +169 -0
- package/skills/octocode-research/src/utils/responseBuilder.ts +495 -0
- package/skills/octocode-research/src/utils/responseFactory.ts +100 -0
- package/skills/octocode-research/src/utils/responseParser.ts +272 -0
- package/skills/octocode-research/src/utils/retry.ts +280 -0
- package/skills/octocode-research/src/utils/routeFactory.ts +117 -0
- package/skills/octocode-research/src/utils/url.ts +20 -0
- package/skills/octocode-research/src/validation/httpPreprocess.ts +155 -0
- package/skills/octocode-research/src/validation/index.ts +2 -0
- package/skills/octocode-research/src/validation/schemas.ts +578 -0
- package/skills/octocode-research/src/validation/toolCallSchema.ts +132 -0
- package/skills/octocode-research/tsconfig.json +21 -0
- package/skills/octocode-research/tsdown.config.ts +42 -0
- package/skills/octocode-research/vitest.config.ts +20 -0
- package/skills/octocode-researcher/SKILL.md +461 -0
- package/skills/octocode-researcher/references/fallbacks.md +120 -0
- package/skills/{octocode-local-search → octocode-researcher}/references/tool-reference.md +132 -49
- package/skills/{octocode-local-search → octocode-researcher}/references/workflow-patterns.md +204 -4
- package/skills/octocode-rfc-generator/SKILL.md +223 -0
- package/skills/octocode-rfc-generator/references/rfc-template.md +193 -0
- package/skills/octocode-roast/SKILL.md +63 -21
- package/skills/octocode-implement/SKILL.md +0 -293
- package/skills/octocode-implement/references/execution-phases.md +0 -317
- package/skills/octocode-implement/references/tool-reference.md +0 -403
- package/skills/octocode-implement/references/workflow-patterns.md +0 -385
- package/skills/octocode-local-search/SKILL.md +0 -449
- package/skills/octocode-pr-review/SKILL.md +0 -391
- package/skills/octocode-pr-review/references/domain-reviewers.md +0 -105
- package/skills/octocode-pr-review/references/execution-lifecycle.md +0 -116
- package/skills/octocode-pr-review/references/research-flows.md +0 -75
- package/skills/octocode-research/references/tool-reference.md +0 -304
- package/skills/octocode-research/references/workflow-patterns.md +0 -325
|
@@ -0,0 +1,714 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
import { PILLAR_CATEGORIES, SEVERITY_ORDER } from '../types/index.js';
|
|
5
|
+
|
|
6
|
+
import type { ReportAnalysisSummary } from './analysis.js';
|
|
7
|
+
import type { Finding } from '../types/index.js';
|
|
8
|
+
|
|
9
|
+
export function severityBreakdown(findings: Finding[]): Record<string, number> {
|
|
10
|
+
const counts: Record<string, number> = {
|
|
11
|
+
critical: 0,
|
|
12
|
+
high: 0,
|
|
13
|
+
medium: 0,
|
|
14
|
+
low: 0,
|
|
15
|
+
info: 0,
|
|
16
|
+
};
|
|
17
|
+
for (const f of findings) counts[f.severity] = (counts[f.severity] || 0) + 1;
|
|
18
|
+
return counts;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function categoryBreakdown(findings: Finding[]): Record<string, number> {
|
|
22
|
+
const counts: Record<string, number> = {};
|
|
23
|
+
for (const f of findings) counts[f.category] = (counts[f.category] || 0) + 1;
|
|
24
|
+
return counts;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function computeHealthScore(
|
|
28
|
+
findings: Finding[],
|
|
29
|
+
totalFiles: number
|
|
30
|
+
): number {
|
|
31
|
+
return computeHealthScoreFromSeverityBreakdown(
|
|
32
|
+
severityBreakdown(findings),
|
|
33
|
+
totalFiles
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function computeHealthScoreFromSeverityBreakdown(
|
|
38
|
+
breakdown: Record<string, number>,
|
|
39
|
+
totalFiles: number
|
|
40
|
+
): number {
|
|
41
|
+
if (totalFiles === 0) return 100;
|
|
42
|
+
const weights = { critical: 25, high: 10, medium: 3, low: 1, info: 0 };
|
|
43
|
+
let penalty = 0;
|
|
44
|
+
for (const [severity, count] of Object.entries(breakdown)) {
|
|
45
|
+
penalty += (weights[severity as keyof typeof weights] || 0) * count;
|
|
46
|
+
}
|
|
47
|
+
const weightedFindingsPerFile = penalty / totalFiles;
|
|
48
|
+
return Math.max(
|
|
49
|
+
0,
|
|
50
|
+
Math.min(100, Math.round(100 / (1 + weightedFindingsPerFile / 10)))
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function collectTagCloud(
|
|
55
|
+
findings: Finding[]
|
|
56
|
+
): { tag: string; count: number }[] {
|
|
57
|
+
const tagCounts = new Map<string, number>();
|
|
58
|
+
for (const f of findings) {
|
|
59
|
+
if (!f.tags) continue;
|
|
60
|
+
for (const tag of f.tags) {
|
|
61
|
+
tagCounts.set(tag, (tagCounts.get(tag) || 0) + 1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return [...tagCounts.entries()]
|
|
65
|
+
.map(([tag, count]) => ({ tag, count }))
|
|
66
|
+
.sort((a, b) => b.count - a.count);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function formatFileSize(bytes: number): string {
|
|
70
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
71
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
72
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function summarizeActiveFeatures(activeFeatures: Set<string>): string[] {
|
|
76
|
+
const remaining = new Set(activeFeatures);
|
|
77
|
+
const labels: string[] = [];
|
|
78
|
+
|
|
79
|
+
for (const [pillar, categories] of Object.entries(PILLAR_CATEGORIES)) {
|
|
80
|
+
if (categories.length > 0 && categories.every(cat => remaining.has(cat))) {
|
|
81
|
+
labels.push(pillar);
|
|
82
|
+
for (const cat of categories) remaining.delete(cat);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return [...labels, ...[...remaining].sort()];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function isPillarActive(
|
|
90
|
+
pillarKey: string,
|
|
91
|
+
activeFeatures: Set<string> | null
|
|
92
|
+
): boolean {
|
|
93
|
+
if (!activeFeatures) return true;
|
|
94
|
+
const pillarCats = PILLAR_CATEGORIES[pillarKey] || [];
|
|
95
|
+
return pillarCats.some(cat => activeFeatures.has(cat));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
type FindingLike = Omit<Finding, 'id'> & { id?: string };
|
|
99
|
+
|
|
100
|
+
export function diversifyFindings<T extends FindingLike>(
|
|
101
|
+
sorted: T[],
|
|
102
|
+
limit: number
|
|
103
|
+
): T[] {
|
|
104
|
+
if (!Number.isFinite(limit) || limit >= sorted.length) return sorted;
|
|
105
|
+
|
|
106
|
+
const groups = new Map<string, T[]>();
|
|
107
|
+
for (const f of sorted) {
|
|
108
|
+
const cat = f.category;
|
|
109
|
+
if (!groups.has(cat)) groups.set(cat, []);
|
|
110
|
+
groups.get(cat)!.push(f);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const categoryOrder = [...groups.entries()].sort((a, b) => {
|
|
114
|
+
const aTop = SEVERITY_ORDER[a[1][0].severity] ?? 0;
|
|
115
|
+
const bTop = SEVERITY_ORDER[b[1][0].severity] ?? 0;
|
|
116
|
+
return bTop - aTop;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const result: T[] = [];
|
|
120
|
+
const cursors = new Map<string, number>();
|
|
121
|
+
for (const [cat] of categoryOrder) cursors.set(cat, 0);
|
|
122
|
+
|
|
123
|
+
while (result.length < limit) {
|
|
124
|
+
let picked = false;
|
|
125
|
+
for (const [cat, items] of categoryOrder) {
|
|
126
|
+
if (result.length >= limit) break;
|
|
127
|
+
const cursor = cursors.get(cat)!;
|
|
128
|
+
if (cursor < items.length) {
|
|
129
|
+
result.push(items[cursor]);
|
|
130
|
+
cursors.set(cat, cursor + 1);
|
|
131
|
+
picked = true;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (!picked) break;
|
|
135
|
+
}
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function diverseTopRecommendations(
|
|
140
|
+
findings: Finding[],
|
|
141
|
+
limit: number = 20,
|
|
142
|
+
maxPerCategory: number = 2
|
|
143
|
+
): Finding[] {
|
|
144
|
+
const result: Finding[] = [];
|
|
145
|
+
const countByCategory = new Map<string, number>();
|
|
146
|
+
for (const f of findings) {
|
|
147
|
+
const catCount = countByCategory.get(f.category) || 0;
|
|
148
|
+
if (catCount >= maxPerCategory) continue;
|
|
149
|
+
result.push(f);
|
|
150
|
+
countByCategory.set(f.category, catCount + 1);
|
|
151
|
+
if (result.length >= limit) break;
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export interface SummaryMdOptions {
|
|
157
|
+
dir: string;
|
|
158
|
+
report: import('./writer.js').FullReport;
|
|
159
|
+
outputFiles: Record<string, string>;
|
|
160
|
+
architectureFindings: Finding[];
|
|
161
|
+
codeQualityFindings: Finding[];
|
|
162
|
+
deadCodeFindings: Finding[];
|
|
163
|
+
hotFiles?: import('../types/index.js').HotFile[];
|
|
164
|
+
activeFeatures?: Set<string> | null;
|
|
165
|
+
scope?: string[] | null;
|
|
166
|
+
root?: string;
|
|
167
|
+
scopeSymbols?: Map<string, string[]> | null;
|
|
168
|
+
semanticEnabled?: boolean;
|
|
169
|
+
securityFindings?: Finding[];
|
|
170
|
+
testQualityFindings?: Finding[];
|
|
171
|
+
reportAnalysis?: ReportAnalysisSummary;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function formatCliPath(filePath: string): string {
|
|
175
|
+
return JSON.stringify(filePath.replace(/\\/g, '/'));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function generateSummaryMd(opts: SummaryMdOptions): string {
|
|
179
|
+
const {
|
|
180
|
+
dir,
|
|
181
|
+
report,
|
|
182
|
+
outputFiles,
|
|
183
|
+
architectureFindings,
|
|
184
|
+
codeQualityFindings,
|
|
185
|
+
deadCodeFindings,
|
|
186
|
+
hotFiles = [],
|
|
187
|
+
activeFeatures = null,
|
|
188
|
+
scope = null,
|
|
189
|
+
root = process.cwd(),
|
|
190
|
+
scopeSymbols = null,
|
|
191
|
+
semanticEnabled = false,
|
|
192
|
+
securityFindings = [],
|
|
193
|
+
testQualityFindings = [],
|
|
194
|
+
reportAnalysis = null,
|
|
195
|
+
} = opts;
|
|
196
|
+
const allFindings = report.optimizationFindings || [];
|
|
197
|
+
const summary = report.summary as Record<string, unknown>;
|
|
198
|
+
const agentOutput = report.agentOutput as Record<string, unknown>;
|
|
199
|
+
const findingStats = (agentOutput?.findingStats ??
|
|
200
|
+
null) as
|
|
201
|
+
| {
|
|
202
|
+
overall?: {
|
|
203
|
+
totalFindings: number;
|
|
204
|
+
severityBreakdown: Record<string, number>;
|
|
205
|
+
};
|
|
206
|
+
pillars?: Record<
|
|
207
|
+
string,
|
|
208
|
+
{
|
|
209
|
+
totalFindings: number;
|
|
210
|
+
severityBreakdown: Record<string, number>;
|
|
211
|
+
}
|
|
212
|
+
>;
|
|
213
|
+
}
|
|
214
|
+
| null;
|
|
215
|
+
const depGraph = report.dependencyGraph;
|
|
216
|
+
const relativeScanDir = path.relative(root, dir) || '.';
|
|
217
|
+
const exampleFileFilter = ((scope?.[0] ?? 'src/index').split(':')[0] || 'src/index')
|
|
218
|
+
.replace(/\\/g, '/');
|
|
219
|
+
const overallFindingStats = findingStats?.overall ?? {
|
|
220
|
+
totalFindings: allFindings.length,
|
|
221
|
+
severityBreakdown: severityBreakdown(allFindings),
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const lines: string[] = [];
|
|
225
|
+
lines.push('# Code Quality Scan Report\n');
|
|
226
|
+
lines.push(`**Generated**: ${report.generatedAt} `);
|
|
227
|
+
lines.push(`**Root**: \`${report.repoRoot}\`\n`);
|
|
228
|
+
|
|
229
|
+
lines.push('## Scan Scope\n');
|
|
230
|
+
lines.push(`| Metric | Count |`);
|
|
231
|
+
lines.push(`|--------|-------|`);
|
|
232
|
+
lines.push(`| Files analyzed | ${summary.totalFiles ?? '—'} |`);
|
|
233
|
+
lines.push(`| Functions | ${summary.totalFunctions ?? '—'} |`);
|
|
234
|
+
lines.push(`| Flow nodes | ${summary.totalFlows ?? '—'} |`);
|
|
235
|
+
lines.push(`| Dependency files | ${summary.totalDependencyFiles ?? '—'} |`);
|
|
236
|
+
lines.push(`| Packages | ${summary.totalPackages ?? '—'} |`);
|
|
237
|
+
lines.push('');
|
|
238
|
+
|
|
239
|
+
lines.push('## Findings Overview\n');
|
|
240
|
+
lines.push(`| Severity | Count |`);
|
|
241
|
+
lines.push(`|----------|-------|`);
|
|
242
|
+
lines.push(`| Critical | ${overallFindingStats.severityBreakdown.critical ?? 0} |`);
|
|
243
|
+
lines.push(`| High | ${overallFindingStats.severityBreakdown.high ?? 0} |`);
|
|
244
|
+
lines.push(`| Medium | ${overallFindingStats.severityBreakdown.medium ?? 0} |`);
|
|
245
|
+
lines.push(`| Low | ${overallFindingStats.severityBreakdown.low ?? 0} |`);
|
|
246
|
+
lines.push(`| **Total** | **${overallFindingStats.totalFindings}** |`);
|
|
247
|
+
lines.push('');
|
|
248
|
+
|
|
249
|
+
const totalBefore = overallFindingStats.totalFindings || (agentOutput as Record<string, unknown>)
|
|
250
|
+
?.totalBeforeTruncation as number | undefined;
|
|
251
|
+
const dropped = (agentOutput as Record<string, unknown>)
|
|
252
|
+
?.droppedCategories as string[] | undefined;
|
|
253
|
+
if (totalBefore && totalBefore > allFindings.length) {
|
|
254
|
+
lines.push(
|
|
255
|
+
`> **Truncated**: Showing ${allFindings.length} of ${totalBefore} findings (\`--findings-limit ${allFindings.length}\`).`
|
|
256
|
+
);
|
|
257
|
+
if (dropped && dropped.length > 0) {
|
|
258
|
+
lines.push(
|
|
259
|
+
`> Dropped categories: ${dropped.map(c => `\`${c}\``).join(', ')}`
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
lines.push('');
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (activeFeatures) {
|
|
266
|
+
const featureLabels = summarizeActiveFeatures(activeFeatures);
|
|
267
|
+
lines.push(
|
|
268
|
+
`> **Features filter**: \`--features=${featureLabels.join(',')}\``
|
|
269
|
+
);
|
|
270
|
+
lines.push('');
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (scope && scope.length > 0) {
|
|
274
|
+
const scopeDisplay = scope.map(s => path.relative(root, s)).filter(Boolean);
|
|
275
|
+
if (scopeDisplay.length > 0) {
|
|
276
|
+
let scopeLabel = scopeDisplay.map(p => `\`${p}\``).join(', ');
|
|
277
|
+
if (scopeSymbols && scopeSymbols.size > 0) {
|
|
278
|
+
const symParts: string[] = [];
|
|
279
|
+
for (const [absFile, names] of scopeSymbols) {
|
|
280
|
+
const rel = path.relative(root, absFile);
|
|
281
|
+
symParts.push(...names.map(n => `\`${rel}:${n}\``));
|
|
282
|
+
}
|
|
283
|
+
scopeLabel = symParts.join(', ');
|
|
284
|
+
}
|
|
285
|
+
lines.push(`> **Scoped scan**: Only showing findings for: ${scopeLabel}`);
|
|
286
|
+
lines.push('');
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (semanticEnabled) {
|
|
291
|
+
lines.push(
|
|
292
|
+
'> **Semantic analysis**: TypeChecker + LanguageService enabled (14 additional categories)'
|
|
293
|
+
);
|
|
294
|
+
lines.push('');
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const renderPillarCategories = (
|
|
298
|
+
pillarKey: string,
|
|
299
|
+
findings: Finding[]
|
|
300
|
+
): void => {
|
|
301
|
+
const breakdown = categoryBreakdown(findings);
|
|
302
|
+
const pillarCats = PILLAR_CATEGORIES[pillarKey] || [];
|
|
303
|
+
const isFiltered = activeFeatures !== null;
|
|
304
|
+
for (const cat of pillarCats) {
|
|
305
|
+
const count = breakdown[cat] || 0;
|
|
306
|
+
const skipped = isFiltered && !activeFeatures!.has(cat);
|
|
307
|
+
if (skipped) {
|
|
308
|
+
lines.push(`- \`${cat}\`: — *(skipped)*`);
|
|
309
|
+
} else {
|
|
310
|
+
lines.push(`- \`${cat}\`: ${count}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
lines.push('');
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
const totalFiles = (summary.totalFiles as number) || 1;
|
|
317
|
+
const archStats = findingStats?.pillars?.['architecture'];
|
|
318
|
+
const qualStats = findingStats?.pillars?.['code-quality'];
|
|
319
|
+
const deadStats = findingStats?.pillars?.['dead-code'];
|
|
320
|
+
const secStats = findingStats?.pillars?.['security'];
|
|
321
|
+
const testStats = findingStats?.pillars?.['test-quality'];
|
|
322
|
+
const overallHealth = computeHealthScoreFromSeverityBreakdown(
|
|
323
|
+
overallFindingStats.severityBreakdown,
|
|
324
|
+
totalFiles
|
|
325
|
+
);
|
|
326
|
+
const archHealth = computeHealthScoreFromSeverityBreakdown(
|
|
327
|
+
archStats?.severityBreakdown ?? severityBreakdown(architectureFindings),
|
|
328
|
+
totalFiles
|
|
329
|
+
);
|
|
330
|
+
const qualHealth = computeHealthScoreFromSeverityBreakdown(
|
|
331
|
+
qualStats?.severityBreakdown ?? severityBreakdown(codeQualityFindings),
|
|
332
|
+
totalFiles
|
|
333
|
+
);
|
|
334
|
+
const deadHealth = computeHealthScoreFromSeverityBreakdown(
|
|
335
|
+
deadStats?.severityBreakdown ?? severityBreakdown(deadCodeFindings),
|
|
336
|
+
totalFiles
|
|
337
|
+
);
|
|
338
|
+
const secHealth = computeHealthScoreFromSeverityBreakdown(
|
|
339
|
+
secStats?.severityBreakdown ?? severityBreakdown(securityFindings),
|
|
340
|
+
totalFiles
|
|
341
|
+
);
|
|
342
|
+
const testHealth = computeHealthScoreFromSeverityBreakdown(
|
|
343
|
+
testStats?.severityBreakdown ?? severityBreakdown(testQualityFindings),
|
|
344
|
+
totalFiles
|
|
345
|
+
);
|
|
346
|
+
|
|
347
|
+
lines.push('## Health Scores\n');
|
|
348
|
+
lines.push('| Pillar | Score | Grade |');
|
|
349
|
+
lines.push('|--------|-------|-------|');
|
|
350
|
+
const grade = (s: number) =>
|
|
351
|
+
s >= 80 ? 'A' : s >= 60 ? 'B' : s >= 40 ? 'C' : s >= 20 ? 'D' : 'F';
|
|
352
|
+
const pushHealthRow = (label: string, pillarKey: string, score: number): void => {
|
|
353
|
+
if (!isPillarActive(pillarKey, activeFeatures)) {
|
|
354
|
+
lines.push(`| ${label} | — | skipped |`);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
lines.push(`| ${label} | ${score}/100 | ${grade(score)} |`);
|
|
358
|
+
};
|
|
359
|
+
const pushPillarSummary = (
|
|
360
|
+
pillarKey: string,
|
|
361
|
+
findingsCount: number,
|
|
362
|
+
score: number,
|
|
363
|
+
artifactKey?: string,
|
|
364
|
+
artifactName?: string
|
|
365
|
+
): void => {
|
|
366
|
+
if (!isPillarActive(pillarKey, activeFeatures)) {
|
|
367
|
+
lines.push('> skipped by feature filter\n');
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
if (artifactKey && outputFiles[artifactKey]) {
|
|
372
|
+
lines.push(
|
|
373
|
+
`> ${findingsCount} findings (score: ${score}/100) — see [\`${artifactName}\`](./${outputFiles[artifactKey]})\n`
|
|
374
|
+
);
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (artifactName) {
|
|
379
|
+
lines.push(
|
|
380
|
+
`> ${findingsCount} findings (score: ${score}/100) — no \`${artifactName}\` written for this scan\n`
|
|
381
|
+
);
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
lines.push(`> ${findingsCount} findings (score: ${score}/100)\n`);
|
|
386
|
+
};
|
|
387
|
+
lines.push(
|
|
388
|
+
`| **Overall** | **${overallHealth}/100** | **${grade(overallHealth)}** |`
|
|
389
|
+
);
|
|
390
|
+
pushHealthRow('Architecture', 'architecture', archHealth);
|
|
391
|
+
pushHealthRow('Code Quality', 'code-quality', qualHealth);
|
|
392
|
+
pushHealthRow('Dead Code & Hygiene', 'dead-code', deadHealth);
|
|
393
|
+
pushHealthRow('Security', 'security', secHealth);
|
|
394
|
+
pushHealthRow('Test Quality', 'test-quality', testHealth);
|
|
395
|
+
lines.push('');
|
|
396
|
+
|
|
397
|
+
const tagCloud = collectTagCloud(allFindings);
|
|
398
|
+
if (tagCloud.length > 0) {
|
|
399
|
+
lines.push('## Top Concern Tags\n');
|
|
400
|
+
lines.push(
|
|
401
|
+
'Searchable tags across all findings — use to filter `findings.json` with `jq`.\n'
|
|
402
|
+
);
|
|
403
|
+
for (const { tag, count } of tagCloud.slice(0, 12)) {
|
|
404
|
+
lines.push(`- \`${tag}\`: ${count} findings`);
|
|
405
|
+
}
|
|
406
|
+
lines.push('');
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
if (reportAnalysis) {
|
|
410
|
+
lines.push('## Analysis Signals\n');
|
|
411
|
+
lines.push(
|
|
412
|
+
`- **Graph Signal**: ${reportAnalysis.strongestGraphSignal?.summary || 'No dominant graph signal in this scan.'}`
|
|
413
|
+
);
|
|
414
|
+
lines.push(
|
|
415
|
+
`- **AST Signal**: ${reportAnalysis.strongestAstSignal?.summary || 'No dominant AST signal in this scan.'}`
|
|
416
|
+
);
|
|
417
|
+
lines.push(
|
|
418
|
+
`- **Combined Interpretation**: ${reportAnalysis.combinedInterpretation?.summary || 'No combined interpretation available yet.'}`
|
|
419
|
+
);
|
|
420
|
+
lines.push(
|
|
421
|
+
`- **Confidence**: ${reportAnalysis.combinedInterpretation?.confidence || reportAnalysis.strongestGraphSignal?.confidence || reportAnalysis.strongestAstSignal?.confidence || 'low'}`
|
|
422
|
+
);
|
|
423
|
+
const validationSummary = reportAnalysis.recommendedValidation
|
|
424
|
+
? `${reportAnalysis.recommendedValidation.summary} (tools: ${reportAnalysis.recommendedValidation.tools.join(' -> ')})`
|
|
425
|
+
: 'Use Octocode local tools to confirm the strongest signal before presenting it as fact.';
|
|
426
|
+
lines.push(`- **Recommended Validation**: ${validationSummary}`);
|
|
427
|
+
const megaFolderSignal = reportAnalysis.graphSignals.find(
|
|
428
|
+
signal => signal.kind === 'mega-folder-cluster'
|
|
429
|
+
);
|
|
430
|
+
if (megaFolderSignal) {
|
|
431
|
+
lines.push(`- **Structural Layout Alert**: ${megaFolderSignal.summary}`);
|
|
432
|
+
}
|
|
433
|
+
if (reportAnalysis.investigationPrompts.length > 0) {
|
|
434
|
+
lines.push('');
|
|
435
|
+
lines.push('**Investigation Prompts**');
|
|
436
|
+
for (const prompt of reportAnalysis.investigationPrompts.slice(0, 4)) {
|
|
437
|
+
lines.push(`- ${prompt}`);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
lines.push('');
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
lines.push('## Architecture Health\n');
|
|
444
|
+
pushPillarSummary(
|
|
445
|
+
'architecture',
|
|
446
|
+
archStats?.totalFindings ?? architectureFindings.length,
|
|
447
|
+
archHealth,
|
|
448
|
+
'architecture',
|
|
449
|
+
'architecture.json'
|
|
450
|
+
);
|
|
451
|
+
if (depGraph) {
|
|
452
|
+
lines.push(`| Metric | Value |`);
|
|
453
|
+
lines.push(`|--------|-------|`);
|
|
454
|
+
lines.push(`| Modules | ${depGraph.totalModules} |`);
|
|
455
|
+
lines.push(`| Import edges | ${depGraph.totalEdges} |`);
|
|
456
|
+
lines.push(`| Cycles | ${depGraph.cycles?.length ?? 0} |`);
|
|
457
|
+
lines.push(`| Critical paths | ${depGraph.criticalPaths?.length ?? 0} |`);
|
|
458
|
+
lines.push(`| Root modules | ${depGraph.rootsCount} |`);
|
|
459
|
+
lines.push(`| Leaf modules | ${depGraph.leavesCount} |`);
|
|
460
|
+
lines.push(
|
|
461
|
+
`| Test-only modules | ${depGraph.testOnlyModules?.length ?? 0} |`
|
|
462
|
+
);
|
|
463
|
+
lines.push(`| Unresolved imports | ${depGraph.unresolvedEdgeCount} |`);
|
|
464
|
+
lines.push('');
|
|
465
|
+
}
|
|
466
|
+
renderPillarCategories('architecture', architectureFindings);
|
|
467
|
+
|
|
468
|
+
renderHotspots(lines, hotFiles);
|
|
469
|
+
|
|
470
|
+
renderPillarSections(lines, {
|
|
471
|
+
architectureFindings,
|
|
472
|
+
codeQualityFindings,
|
|
473
|
+
deadCodeFindings,
|
|
474
|
+
securityFindings,
|
|
475
|
+
testQualityFindings,
|
|
476
|
+
archStats,
|
|
477
|
+
qualStats,
|
|
478
|
+
deadStats,
|
|
479
|
+
secStats,
|
|
480
|
+
testStats,
|
|
481
|
+
archHealth,
|
|
482
|
+
qualHealth,
|
|
483
|
+
deadHealth,
|
|
484
|
+
secHealth,
|
|
485
|
+
testHealth,
|
|
486
|
+
activeFeatures,
|
|
487
|
+
outputFiles,
|
|
488
|
+
renderPillarCategories,
|
|
489
|
+
pushPillarSummary,
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
renderRecommendations(lines, agentOutput);
|
|
493
|
+
|
|
494
|
+
if (outputFiles.astTrees) {
|
|
495
|
+
renderAstTreesSection(lines, dir, outputFiles, root, relativeScanDir, exampleFileFilter);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
renderOutputFilesTable(lines, dir, outputFiles);
|
|
499
|
+
|
|
500
|
+
if (report.parseErrors?.length > 0) {
|
|
501
|
+
lines.push('## Parse Errors\n');
|
|
502
|
+
lines.push(`${report.parseErrors.length} file(s) failed to parse:\n`);
|
|
503
|
+
for (const err of report.parseErrors.slice(0, 10)) {
|
|
504
|
+
lines.push(`- \`${err.file}\`: ${err.message}`);
|
|
505
|
+
}
|
|
506
|
+
lines.push('');
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
return lines.join('\n');
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function renderHotspots(
|
|
513
|
+
lines: string[],
|
|
514
|
+
hotFiles: SummaryMdOptions['hotFiles']
|
|
515
|
+
): void {
|
|
516
|
+
if (!hotFiles || hotFiles.length === 0) return;
|
|
517
|
+
lines.push('## Change Risk Hotspots\n');
|
|
518
|
+
lines.push(
|
|
519
|
+
'Files most dangerous to change — high fan-in, complexity, or cycle membership.\n'
|
|
520
|
+
);
|
|
521
|
+
lines.push(
|
|
522
|
+
'| File | Risk | Fan-In | Fan-Out | Complexity | Exports | Cycle | Critical Path |'
|
|
523
|
+
);
|
|
524
|
+
lines.push(
|
|
525
|
+
'|------|------|--------|---------|------------|---------|-------|---------------|'
|
|
526
|
+
);
|
|
527
|
+
for (const hf of hotFiles.slice(0, 15)) {
|
|
528
|
+
lines.push(
|
|
529
|
+
`| \`${hf.file}\` | ${hf.riskScore} | ${hf.fanIn} | ${hf.fanOut} | ${hf.complexityScore} | ${hf.exportCount} | ${hf.inCycle ? 'Y' : '-'} | ${hf.onCriticalPath ? 'Y' : '-'} |`
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
lines.push('');
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function renderPillarSections(
|
|
536
|
+
lines: string[],
|
|
537
|
+
ctx: {
|
|
538
|
+
architectureFindings: Finding[];
|
|
539
|
+
codeQualityFindings: Finding[];
|
|
540
|
+
deadCodeFindings: Finding[];
|
|
541
|
+
securityFindings: Finding[];
|
|
542
|
+
testQualityFindings: Finding[];
|
|
543
|
+
archStats: { totalFindings: number; severityBreakdown: Record<string, number> } | undefined;
|
|
544
|
+
qualStats: { totalFindings: number; severityBreakdown: Record<string, number> } | undefined;
|
|
545
|
+
deadStats: { totalFindings: number; severityBreakdown: Record<string, number> } | undefined;
|
|
546
|
+
secStats: { totalFindings: number; severityBreakdown: Record<string, number> } | undefined;
|
|
547
|
+
testStats: { totalFindings: number; severityBreakdown: Record<string, number> } | undefined;
|
|
548
|
+
archHealth: number;
|
|
549
|
+
qualHealth: number;
|
|
550
|
+
deadHealth: number;
|
|
551
|
+
secHealth: number;
|
|
552
|
+
testHealth: number;
|
|
553
|
+
activeFeatures: Set<string> | null;
|
|
554
|
+
outputFiles: Record<string, string>;
|
|
555
|
+
renderPillarCategories: (pillarKey: string, findings: Finding[]) => void;
|
|
556
|
+
pushPillarSummary: (pillarKey: string, count: number, score: number, artifactKey?: string, artifactName?: string) => void;
|
|
557
|
+
}
|
|
558
|
+
): void {
|
|
559
|
+
const { architectureFindings, codeQualityFindings, deadCodeFindings, securityFindings, testQualityFindings } = ctx;
|
|
560
|
+
const { qualStats, deadStats, secStats, testStats } = ctx;
|
|
561
|
+
const { qualHealth, deadHealth, secHealth, testHealth } = ctx;
|
|
562
|
+
const { renderPillarCategories, pushPillarSummary } = ctx;
|
|
563
|
+
|
|
564
|
+
lines.push('## Code Quality\n');
|
|
565
|
+
pushPillarSummary(
|
|
566
|
+
'code-quality',
|
|
567
|
+
qualStats?.totalFindings ?? codeQualityFindings.length,
|
|
568
|
+
qualHealth,
|
|
569
|
+
'codeQuality',
|
|
570
|
+
'code-quality.json'
|
|
571
|
+
);
|
|
572
|
+
renderPillarCategories('code-quality', codeQualityFindings);
|
|
573
|
+
|
|
574
|
+
lines.push('## Dead Code & Hygiene\n');
|
|
575
|
+
pushPillarSummary(
|
|
576
|
+
'dead-code',
|
|
577
|
+
deadStats?.totalFindings ?? deadCodeFindings.length,
|
|
578
|
+
deadHealth,
|
|
579
|
+
'deadCode',
|
|
580
|
+
'dead-code.json'
|
|
581
|
+
);
|
|
582
|
+
renderPillarCategories('dead-code', deadCodeFindings);
|
|
583
|
+
|
|
584
|
+
lines.push('## Security\n');
|
|
585
|
+
pushPillarSummary(
|
|
586
|
+
'security',
|
|
587
|
+
secStats?.totalFindings ?? securityFindings.length,
|
|
588
|
+
secHealth,
|
|
589
|
+
'security',
|
|
590
|
+
'security.json'
|
|
591
|
+
);
|
|
592
|
+
renderPillarCategories('security', securityFindings);
|
|
593
|
+
|
|
594
|
+
lines.push('## Test Quality\n');
|
|
595
|
+
pushPillarSummary(
|
|
596
|
+
'test-quality',
|
|
597
|
+
testStats?.totalFindings ?? testQualityFindings.length,
|
|
598
|
+
testHealth,
|
|
599
|
+
'testQuality',
|
|
600
|
+
'test-quality.json'
|
|
601
|
+
);
|
|
602
|
+
renderPillarCategories('test-quality', testQualityFindings);
|
|
603
|
+
|
|
604
|
+
const untestedCount = architectureFindings.filter(
|
|
605
|
+
f => f.category === 'untested-critical-code'
|
|
606
|
+
).length;
|
|
607
|
+
if (
|
|
608
|
+
untestedCount > 0 &&
|
|
609
|
+
(testStats?.totalFindings ?? testQualityFindings.length) === 0
|
|
610
|
+
) {
|
|
611
|
+
lines.push(
|
|
612
|
+
`> **Note**: Test Quality reflects analyzed test files only. ${untestedCount} modules flagged as \`untested-critical-code\` (architecture pillar) have no test coverage — use \`--include-tests\` for test-quality analysis.\n`
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
function renderRecommendations(
|
|
618
|
+
lines: string[],
|
|
619
|
+
agentOutput: Record<string, unknown>
|
|
620
|
+
): void {
|
|
621
|
+
const topRecs = (agentOutput?.topRecommendations ?? []) as Array<{
|
|
622
|
+
severity: string;
|
|
623
|
+
title: string;
|
|
624
|
+
file: string;
|
|
625
|
+
category: string;
|
|
626
|
+
}>;
|
|
627
|
+
if (topRecs.length > 0) {
|
|
628
|
+
lines.push('## Top Recommendations\n');
|
|
629
|
+
for (const rec of topRecs.slice(0, 10)) {
|
|
630
|
+
lines.push(
|
|
631
|
+
`- **[${rec.severity.toUpperCase()}]** \`${rec.file}\` — ${rec.title} *(${rec.category})* `
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
lines.push('');
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
function renderAstTreesSection(
|
|
639
|
+
lines: string[],
|
|
640
|
+
dir: string,
|
|
641
|
+
outputFiles: Record<string, string>,
|
|
642
|
+
root: string,
|
|
643
|
+
relativeScanDir: string,
|
|
644
|
+
exampleFileFilter: string
|
|
645
|
+
): void {
|
|
646
|
+
const astTreePath = path.resolve(dir, outputFiles.astTrees);
|
|
647
|
+
const astTreeArg = formatCliPath(astTreePath);
|
|
648
|
+
lines.push('## AST Trees (`ast-trees.txt`)\n');
|
|
649
|
+
lines.push(
|
|
650
|
+
'Compact indented text format — each node is `Kind[startLine:endLine]`, nesting = indentation.\n'
|
|
651
|
+
);
|
|
652
|
+
lines.push(
|
|
653
|
+
`Run these commands from the skill directory. Current scan: \`${relativeScanDir}\`.\n`
|
|
654
|
+
);
|
|
655
|
+
lines.push('```');
|
|
656
|
+
lines.push('SourceFile[1:152]');
|
|
657
|
+
lines.push(' ImportDeclaration[1]');
|
|
658
|
+
lines.push(' FunctionDeclaration[3:20]');
|
|
659
|
+
lines.push(' Block[4:19]');
|
|
660
|
+
lines.push(' IfStatement[5:12] ...');
|
|
661
|
+
lines.push('```\n');
|
|
662
|
+
lines.push('**Smart navigation:**\n');
|
|
663
|
+
lines.push(
|
|
664
|
+
`- Find functions: \`node scripts/ast/tree-search.js -i ${astTreeArg} -k function_declaration --limit 25\``
|
|
665
|
+
);
|
|
666
|
+
lines.push(
|
|
667
|
+
`- Find classes: \`node scripts/ast/tree-search.js -i ${astTreeArg} -k class_declaration --limit 25\``
|
|
668
|
+
);
|
|
669
|
+
lines.push(
|
|
670
|
+
`- Find control flow: \`node scripts/ast/tree-search.js -i ${astTreeArg} -p 'IfStatement|SwitchStatement|ForStatement|WhileStatement' --limit 25\``
|
|
671
|
+
);
|
|
672
|
+
lines.push(
|
|
673
|
+
`- Narrow to one file: \`node scripts/ast/tree-search.js -i ${astTreeArg} --file "${exampleFileFilter}" -k function_declaration --limit 10\``
|
|
674
|
+
);
|
|
675
|
+
lines.push(
|
|
676
|
+
`- Raw text fallback: \`rg 'FunctionDeclaration|IfStatement' ${astTreeArg}\``
|
|
677
|
+
);
|
|
678
|
+
lines.push('');
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
function renderOutputFilesTable(
|
|
682
|
+
lines: string[],
|
|
683
|
+
dir: string,
|
|
684
|
+
outputFiles: Record<string, string>
|
|
685
|
+
): void {
|
|
686
|
+
lines.push('## Output Files\n');
|
|
687
|
+
lines.push('| File | Size | Description |');
|
|
688
|
+
lines.push('|------|------|-------------|');
|
|
689
|
+
const descriptions: Record<string, string> = {
|
|
690
|
+
summary: 'Scan metadata, agent output, parse errors',
|
|
691
|
+
architecture:
|
|
692
|
+
'Dependency graph, cycles, critical paths, architecture findings',
|
|
693
|
+
codeQuality: 'Duplicate detection, complexity, god modules/functions',
|
|
694
|
+
deadCode: 'Dead files/exports/re-exports, unused deps, boundary violations',
|
|
695
|
+
fileInventory: 'Per-file function/flow/dependency details',
|
|
696
|
+
findings: 'All findings across all categories (master list)',
|
|
697
|
+
graph: 'Mermaid dependency graph',
|
|
698
|
+
astTrees:
|
|
699
|
+
'AST tree snapshots (compact indented text — grep/regex friendly)',
|
|
700
|
+
summaryMd: 'This file — human-readable overview',
|
|
701
|
+
};
|
|
702
|
+
for (const [key, file] of Object.entries(outputFiles)) {
|
|
703
|
+
let size = '—';
|
|
704
|
+
try {
|
|
705
|
+
size = formatFileSize(fs.statSync(path.join(dir, file)).size);
|
|
706
|
+
} catch {
|
|
707
|
+
size = '—';
|
|
708
|
+
}
|
|
709
|
+
lines.push(
|
|
710
|
+
`| [\`${file}\`](./${file}) | ${size} | ${descriptions[key] || key} |`
|
|
711
|
+
);
|
|
712
|
+
}
|
|
713
|
+
lines.push('');
|
|
714
|
+
}
|