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,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local filesystem routes using route factory pattern.
|
|
3
|
+
*
|
|
4
|
+
* @module routes/local
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Router } from 'express';
|
|
8
|
+
import {
|
|
9
|
+
localSearchCode,
|
|
10
|
+
localGetFileContent,
|
|
11
|
+
localFindFiles,
|
|
12
|
+
localViewStructure,
|
|
13
|
+
} from '../index.js';
|
|
14
|
+
import {
|
|
15
|
+
localSearchSchema,
|
|
16
|
+
localContentSchema,
|
|
17
|
+
localFindSchema,
|
|
18
|
+
localStructureSchema,
|
|
19
|
+
} from '../validation/index.js';
|
|
20
|
+
import { ResearchResponse, detectLanguageFromPath } from '../utils/responseBuilder.js';
|
|
21
|
+
import { withLocalResilience } from '../utils/resilience.js';
|
|
22
|
+
import { createRouteHandler } from '../utils/routeFactory.js';
|
|
23
|
+
import {
|
|
24
|
+
safeString,
|
|
25
|
+
safeNumber,
|
|
26
|
+
safeArray,
|
|
27
|
+
extractMatchLocations,
|
|
28
|
+
transformPagination,
|
|
29
|
+
} from '../utils/responseFactory.js';
|
|
30
|
+
import { isObject, hasNumberProperty, hasBooleanProperty } from '../types/guards.js';
|
|
31
|
+
|
|
32
|
+
export const localRoutes = Router();
|
|
33
|
+
|
|
34
|
+
// GET /localSearchCode - Search code with ripgrep
|
|
35
|
+
localRoutes.get(
|
|
36
|
+
'/localSearchCode',
|
|
37
|
+
createRouteHandler({
|
|
38
|
+
schema: localSearchSchema,
|
|
39
|
+
toolFn: localSearchCode,
|
|
40
|
+
toolName: 'localSearchCode',
|
|
41
|
+
resilience: withLocalResilience,
|
|
42
|
+
transform: (parsed, queries) => {
|
|
43
|
+
const { data, hints, research } = parsed;
|
|
44
|
+
const files = safeArray<Record<string, unknown>>(data, 'files');
|
|
45
|
+
const pagination = isObject(data.pagination) ? data.pagination : {};
|
|
46
|
+
|
|
47
|
+
return ResearchResponse.searchResults({
|
|
48
|
+
files: files.map((f) => {
|
|
49
|
+
const matchesArray = safeArray<Record<string, unknown>>(f, 'matches');
|
|
50
|
+
const firstMatch = matchesArray[0];
|
|
51
|
+
return {
|
|
52
|
+
path: safeString(f, 'path'),
|
|
53
|
+
matches: hasNumberProperty(f, 'matchCount') ? f.matchCount : matchesArray.length,
|
|
54
|
+
line: isObject(firstMatch) && hasNumberProperty(firstMatch, 'line') ? firstMatch.line : undefined,
|
|
55
|
+
preview: isObject(firstMatch) && typeof firstMatch.value === 'string' ? firstMatch.value.trim() : undefined,
|
|
56
|
+
allMatches: extractMatchLocations(matchesArray),
|
|
57
|
+
};
|
|
58
|
+
}),
|
|
59
|
+
totalMatches: safeNumber(data, 'totalMatches', 0),
|
|
60
|
+
pagination: transformPagination(pagination),
|
|
61
|
+
searchPattern: queries[0]?.pattern,
|
|
62
|
+
mcpHints: hints,
|
|
63
|
+
research,
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
// GET /localGetFileContent - Read file contents
|
|
70
|
+
localRoutes.get(
|
|
71
|
+
'/localGetFileContent',
|
|
72
|
+
createRouteHandler({
|
|
73
|
+
schema: localContentSchema,
|
|
74
|
+
toolFn: localGetFileContent,
|
|
75
|
+
toolName: 'localGetFileContent',
|
|
76
|
+
resilience: withLocalResilience,
|
|
77
|
+
transform: (parsed, queries) => {
|
|
78
|
+
const { data, hints, research } = parsed;
|
|
79
|
+
|
|
80
|
+
return ResearchResponse.fileContent({
|
|
81
|
+
path: safeString(data, 'path', queries[0]?.path || 'unknown'),
|
|
82
|
+
content: safeString(data, 'content'),
|
|
83
|
+
lines: hasNumberProperty(data, 'startLine')
|
|
84
|
+
? {
|
|
85
|
+
start: data.startLine,
|
|
86
|
+
end: hasNumberProperty(data, 'endLine') ? data.endLine : data.startLine,
|
|
87
|
+
}
|
|
88
|
+
: undefined,
|
|
89
|
+
language: detectLanguageFromPath(queries[0]?.path || ''),
|
|
90
|
+
totalLines: hasNumberProperty(data, 'totalLines') ? data.totalLines : undefined,
|
|
91
|
+
isPartial: hasBooleanProperty(data, 'isPartial') ? data.isPartial : undefined,
|
|
92
|
+
mcpHints: hints,
|
|
93
|
+
research,
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// GET /localFindFiles - Find files by metadata
|
|
100
|
+
localRoutes.get(
|
|
101
|
+
'/localFindFiles',
|
|
102
|
+
createRouteHandler({
|
|
103
|
+
schema: localFindSchema,
|
|
104
|
+
toolFn: localFindFiles,
|
|
105
|
+
toolName: 'localFindFiles',
|
|
106
|
+
resilience: withLocalResilience,
|
|
107
|
+
transform: (parsed) => {
|
|
108
|
+
const { data, hints } = parsed;
|
|
109
|
+
const files = safeArray<Record<string, unknown>>(data, 'files');
|
|
110
|
+
|
|
111
|
+
const summary = files.length > 0
|
|
112
|
+
? `Found ${files.length} files:\n` +
|
|
113
|
+
files
|
|
114
|
+
.slice(0, 20)
|
|
115
|
+
.map((f) =>
|
|
116
|
+
`- ${safeString(f, 'path')}${hasNumberProperty(f, 'size') ? ` (${formatSize(f.size)})` : ''}`
|
|
117
|
+
)
|
|
118
|
+
.join('\n')
|
|
119
|
+
: 'No files found';
|
|
120
|
+
|
|
121
|
+
const defaultHints = ['Use localGetFileContent to read file contents', 'Use localSearchCode to search within files'];
|
|
122
|
+
const emptyHints = ['Try different name pattern', 'Check path filter', 'Use -iname for case-insensitive search'];
|
|
123
|
+
|
|
124
|
+
return files.length === 0
|
|
125
|
+
? { content: [{ type: 'text' as const, text: summary }], structuredContent: { status: 'empty', hints: emptyHints, data } }
|
|
126
|
+
: { content: [{ type: 'text' as const, text: summary }], structuredContent: { status: 'hasResults', hints: hints.length > 0 ? hints : defaultHints, data } };
|
|
127
|
+
},
|
|
128
|
+
})
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
// GET /localViewStructure - View directory structure
|
|
132
|
+
localRoutes.get(
|
|
133
|
+
'/localViewStructure',
|
|
134
|
+
createRouteHandler({
|
|
135
|
+
schema: localStructureSchema,
|
|
136
|
+
toolFn: localViewStructure,
|
|
137
|
+
toolName: 'localViewStructure',
|
|
138
|
+
resilience: withLocalResilience,
|
|
139
|
+
transform: (parsed, queries) => {
|
|
140
|
+
const { data, hints, research } = parsed;
|
|
141
|
+
const structuredOutput = safeString(data, 'structuredOutput');
|
|
142
|
+
const files: string[] = [];
|
|
143
|
+
const folders: string[] = [];
|
|
144
|
+
|
|
145
|
+
// Extract files and folders from output
|
|
146
|
+
const lines = structuredOutput.split('\n');
|
|
147
|
+
for (const line of lines) {
|
|
148
|
+
if (line.includes('[FILE]')) {
|
|
149
|
+
const match = line.match(/\[FILE\]\s+(.+?)(?:\s+\(|$)/);
|
|
150
|
+
if (match) files.push(match[1].trim());
|
|
151
|
+
} else if (line.includes('[DIR]')) {
|
|
152
|
+
const match = line.match(/\[DIR\]\s+(.+?)(?:\s*$)/);
|
|
153
|
+
if (match) folders.push(match[1].trim());
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return ResearchResponse.repoStructure({
|
|
158
|
+
path: queries[0]?.path || '.',
|
|
159
|
+
structure: { files, folders },
|
|
160
|
+
depth: hasNumberProperty(queries[0], 'depth') ? queries[0].depth : undefined,
|
|
161
|
+
totalFiles: hasNumberProperty(data, 'totalFiles') ? data.totalFiles : undefined,
|
|
162
|
+
totalFolders: hasNumberProperty(data, 'totalDirectories') ? data.totalDirectories : undefined,
|
|
163
|
+
mcpHints: hints,
|
|
164
|
+
research,
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
})
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
// Helper: Format file size
|
|
171
|
+
function formatSize(bytes: number): string {
|
|
172
|
+
if (bytes < 1024) return `${bytes}B`;
|
|
173
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)}KB`;
|
|
174
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
175
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LSP routes using route factory pattern.
|
|
3
|
+
*
|
|
4
|
+
* @module routes/lsp
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Router } from 'express';
|
|
8
|
+
import {
|
|
9
|
+
lspGotoDefinition,
|
|
10
|
+
lspFindReferences,
|
|
11
|
+
lspCallHierarchy,
|
|
12
|
+
} from '../index.js';
|
|
13
|
+
import {
|
|
14
|
+
lspDefinitionSchema,
|
|
15
|
+
lspReferencesSchema,
|
|
16
|
+
lspCallsSchema,
|
|
17
|
+
} from '../validation/index.js';
|
|
18
|
+
import { ResearchResponse } from '../utils/responseBuilder.js';
|
|
19
|
+
import { withLspResilience } from '../utils/resilience.js';
|
|
20
|
+
import { createRouteHandler } from '../utils/routeFactory.js';
|
|
21
|
+
import { safeString, safeArray } from '../utils/responseFactory.js';
|
|
22
|
+
import { isObject, hasProperty, hasNumberProperty, hasStringProperty } from '../types/guards.js';
|
|
23
|
+
|
|
24
|
+
export const lspRoutes = Router();
|
|
25
|
+
|
|
26
|
+
// GET /lspGotoDefinition - Go to symbol definition
|
|
27
|
+
lspRoutes.get(
|
|
28
|
+
'/lspGotoDefinition',
|
|
29
|
+
createRouteHandler({
|
|
30
|
+
schema: lspDefinitionSchema,
|
|
31
|
+
toolFn: lspGotoDefinition,
|
|
32
|
+
toolName: 'lspGotoDefinition',
|
|
33
|
+
resilience: withLspResilience,
|
|
34
|
+
transform: (parsed, queries) => {
|
|
35
|
+
const { data, hints, research } = parsed;
|
|
36
|
+
const locations = extractLocations(data, 'definition');
|
|
37
|
+
|
|
38
|
+
return ResearchResponse.lspResult({
|
|
39
|
+
symbol: queries[0]?.symbolName || 'unknown',
|
|
40
|
+
locations,
|
|
41
|
+
type: 'definition',
|
|
42
|
+
mcpHints: hints,
|
|
43
|
+
research,
|
|
44
|
+
});
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
// GET /lspFindReferences - Find all references to a symbol
|
|
50
|
+
lspRoutes.get(
|
|
51
|
+
'/lspFindReferences',
|
|
52
|
+
createRouteHandler({
|
|
53
|
+
schema: lspReferencesSchema,
|
|
54
|
+
toolFn: lspFindReferences,
|
|
55
|
+
toolName: 'lspFindReferences',
|
|
56
|
+
resilience: withLspResilience,
|
|
57
|
+
transform: (parsed, queries) => {
|
|
58
|
+
const { data, hints, research } = parsed;
|
|
59
|
+
const locations = extractLocations(data, 'references');
|
|
60
|
+
|
|
61
|
+
return ResearchResponse.lspResult({
|
|
62
|
+
symbol: queries[0]?.symbolName || 'unknown',
|
|
63
|
+
locations,
|
|
64
|
+
type: 'references',
|
|
65
|
+
mcpHints: hints,
|
|
66
|
+
research,
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
})
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
// GET /lspCallHierarchy - Get call hierarchy (incoming/outgoing)
|
|
73
|
+
lspRoutes.get(
|
|
74
|
+
'/lspCallHierarchy',
|
|
75
|
+
createRouteHandler({
|
|
76
|
+
schema: lspCallsSchema,
|
|
77
|
+
toolFn: lspCallHierarchy,
|
|
78
|
+
toolName: 'lspCallHierarchy',
|
|
79
|
+
resilience: withLspResilience,
|
|
80
|
+
transform: (parsed, queries) => {
|
|
81
|
+
const { data, hints, research } = parsed;
|
|
82
|
+
const locations = extractCallHierarchyLocations(data);
|
|
83
|
+
const direction = queries[0]?.direction || 'incoming';
|
|
84
|
+
|
|
85
|
+
return ResearchResponse.lspResult({
|
|
86
|
+
symbol: queries[0]?.symbolName || 'unknown',
|
|
87
|
+
locations,
|
|
88
|
+
type: direction as 'incoming' | 'outgoing',
|
|
89
|
+
mcpHints: hints,
|
|
90
|
+
research,
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
})
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
// Helper: Extract locations from LSP result
|
|
97
|
+
function extractLocations(
|
|
98
|
+
data: Record<string, unknown>,
|
|
99
|
+
type: 'definition' | 'references'
|
|
100
|
+
): Array<{ uri: string; line: number; preview?: string }> {
|
|
101
|
+
// Handle definition results
|
|
102
|
+
if (type === 'definition' && hasProperty(data, 'definition') && isObject(data.definition)) {
|
|
103
|
+
const def = data.definition as Record<string, unknown>;
|
|
104
|
+
if (typeof def.uri === 'string') {
|
|
105
|
+
const range = isObject(def.range) ? def.range as Record<string, unknown> : {};
|
|
106
|
+
const start = isObject(range.start) ? range.start as Record<string, unknown> : {};
|
|
107
|
+
return [
|
|
108
|
+
{
|
|
109
|
+
uri: def.uri,
|
|
110
|
+
line: (typeof start.line === 'number' ? start.line : 0) + 1,
|
|
111
|
+
preview: typeof def.preview === 'string' ? def.preview : undefined,
|
|
112
|
+
},
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Handle references results
|
|
118
|
+
if (type === 'references' && hasProperty(data, 'references')) {
|
|
119
|
+
const refs = safeArray<Record<string, unknown>>(data, 'references');
|
|
120
|
+
return refs.map((ref) => {
|
|
121
|
+
const range = isObject(ref.range) ? ref.range : {};
|
|
122
|
+
const start = isObject(range.start) ? range.start : {};
|
|
123
|
+
return {
|
|
124
|
+
uri: safeString(ref, 'uri'),
|
|
125
|
+
line: (hasNumberProperty(start, 'line') ? start.line : 0) + 1,
|
|
126
|
+
preview: hasStringProperty(ref, 'preview') ? ref.preview : undefined,
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Handle locations array (generic) - MCP returns range.start.line
|
|
132
|
+
if (hasProperty(data, 'locations')) {
|
|
133
|
+
const locs = safeArray<Record<string, unknown>>(data, 'locations');
|
|
134
|
+
return locs.map((loc) => {
|
|
135
|
+
const range = isObject(loc.range) ? loc.range : {};
|
|
136
|
+
const start = isObject(range.start) ? range.start : {};
|
|
137
|
+
return {
|
|
138
|
+
uri: safeString(loc, 'uri'),
|
|
139
|
+
line: (hasNumberProperty(start, 'line') ? start.line : 0) + 1,
|
|
140
|
+
preview: hasStringProperty(loc, 'content') ? loc.content : undefined,
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return [];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Helper: Extract locations from call hierarchy result
|
|
149
|
+
function extractCallHierarchyLocations(
|
|
150
|
+
data: Record<string, unknown>
|
|
151
|
+
): Array<{ uri: string; line: number; preview?: string }> {
|
|
152
|
+
// Handle calls array
|
|
153
|
+
let calls: Record<string, unknown>[] = [];
|
|
154
|
+
if (hasProperty(data, 'calls') && Array.isArray(data.calls)) {
|
|
155
|
+
calls = data.calls;
|
|
156
|
+
} else if (hasProperty(data, 'incomingCalls') && Array.isArray(data.incomingCalls)) {
|
|
157
|
+
calls = data.incomingCalls;
|
|
158
|
+
} else if (hasProperty(data, 'outgoingCalls') && Array.isArray(data.outgoingCalls)) {
|
|
159
|
+
calls = data.outgoingCalls;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return calls.map((call) => {
|
|
163
|
+
const item = isObject(call.from) ? call.from : isObject(call.to) ? call.to : call;
|
|
164
|
+
const itemObj = isObject(item) ? item : {};
|
|
165
|
+
const range = isObject(itemObj.range) ? itemObj.range : {};
|
|
166
|
+
const start = isObject(range.start) ? range.start : {};
|
|
167
|
+
|
|
168
|
+
const lineFromStart = hasNumberProperty(start, 'line') ? start.line : 0;
|
|
169
|
+
const lineFromItem = hasNumberProperty(itemObj, 'line') ? itemObj.line : 0;
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
uri: safeString(itemObj, 'uri'),
|
|
173
|
+
line: (lineFromStart || lineFromItem) + 1,
|
|
174
|
+
preview: hasStringProperty(itemObj, 'name') ? itemObj.name : undefined,
|
|
175
|
+
};
|
|
176
|
+
});
|
|
177
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Router, type Request, type Response, type NextFunction } from 'express';
|
|
2
|
+
import { packageSearch } from '../index.js';
|
|
3
|
+
import { parseAndValidate } from '../middleware/queryParser.js';
|
|
4
|
+
import { packageSearchSchema } from '../validation/index.js';
|
|
5
|
+
import { ResearchResponse } from '../utils/responseBuilder.js';
|
|
6
|
+
import { parseToolResponse } from '../utils/responseParser.js';
|
|
7
|
+
import { withPackageResilience } from '../utils/resilience.js';
|
|
8
|
+
|
|
9
|
+
import { safeString, safeArray } from '../utils/responseFactory.js';
|
|
10
|
+
import { isObject, hasProperty, hasStringProperty } from '../types/guards.js';
|
|
11
|
+
|
|
12
|
+
export const packageRoutes = Router();
|
|
13
|
+
|
|
14
|
+
// GET /packageSearch - Search npm/pypi packages
|
|
15
|
+
packageRoutes.get(
|
|
16
|
+
'/packageSearch',
|
|
17
|
+
async (req: Request, res: Response, next: NextFunction) => {
|
|
18
|
+
try {
|
|
19
|
+
const queries = parseAndValidate(
|
|
20
|
+
req.query as Record<string, unknown>,
|
|
21
|
+
packageSearchSchema
|
|
22
|
+
);
|
|
23
|
+
type PackageSearchParams = Parameters<typeof packageSearch>[0];
|
|
24
|
+
const rawResult = await withPackageResilience(
|
|
25
|
+
() => packageSearch({ queries } as PackageSearchParams),
|
|
26
|
+
'packageSearch'
|
|
27
|
+
);
|
|
28
|
+
const { data, isError, hints, research } = parseToolResponse(rawResult);
|
|
29
|
+
|
|
30
|
+
// Extract packages from result
|
|
31
|
+
const packages = extractPackages(data);
|
|
32
|
+
const query = queries[0] as Record<string, unknown>;
|
|
33
|
+
const registry = query.ecosystem === 'python' ? 'pypi' : 'npm';
|
|
34
|
+
|
|
35
|
+
const response = ResearchResponse.packageSearch({
|
|
36
|
+
packages,
|
|
37
|
+
registry,
|
|
38
|
+
query: safeString(query, 'name'),
|
|
39
|
+
mcpHints: hints,
|
|
40
|
+
research,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
res.status(isError ? 500 : 200).json(response);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
next(error);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
// Helper: Extract packages from result
|
|
51
|
+
function extractPackages(
|
|
52
|
+
data: Record<string, unknown>
|
|
53
|
+
): Array<{
|
|
54
|
+
name: string;
|
|
55
|
+
version?: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
repository?: string;
|
|
58
|
+
}> {
|
|
59
|
+
// Handle npm results
|
|
60
|
+
if (hasProperty(data, 'npmResults') && Array.isArray(data.npmResults)) {
|
|
61
|
+
return data.npmResults.map((pkg: unknown) => {
|
|
62
|
+
if (!isObject(pkg)) return { name: '' };
|
|
63
|
+
return {
|
|
64
|
+
name: safeString(pkg, 'name'),
|
|
65
|
+
version: hasStringProperty(pkg, 'version') ? pkg.version : undefined,
|
|
66
|
+
description: hasStringProperty(pkg, 'description') ? pkg.description : undefined,
|
|
67
|
+
repository: extractRepositoryUrl(pkg),
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Handle pypi results
|
|
73
|
+
if (hasProperty(data, 'pypiResults') && Array.isArray(data.pypiResults)) {
|
|
74
|
+
return data.pypiResults.map((pkg: unknown) => {
|
|
75
|
+
if (!isObject(pkg)) return { name: '' };
|
|
76
|
+
return {
|
|
77
|
+
name: safeString(pkg, 'name'),
|
|
78
|
+
version: hasStringProperty(pkg, 'version') ? pkg.version : undefined,
|
|
79
|
+
description: hasStringProperty(pkg, 'description') ? pkg.description : undefined,
|
|
80
|
+
repository: hasStringProperty(pkg, 'homepage')
|
|
81
|
+
? pkg.homepage
|
|
82
|
+
: hasStringProperty(pkg, 'project_url')
|
|
83
|
+
? pkg.project_url
|
|
84
|
+
: undefined,
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Handle generic packages array (MCP uses 'path' for package name, 'repoUrl' for repository)
|
|
90
|
+
if (hasProperty(data, 'packages') && Array.isArray(data.packages)) {
|
|
91
|
+
return data.packages.map((pkg: unknown) => {
|
|
92
|
+
if (!isObject(pkg)) return { name: '' };
|
|
93
|
+
return {
|
|
94
|
+
name: safeString(pkg, 'name') || safeString(pkg, 'path'),
|
|
95
|
+
version: hasStringProperty(pkg, 'version') ? pkg.version : undefined,
|
|
96
|
+
description: hasStringProperty(pkg, 'description') ? pkg.description : undefined,
|
|
97
|
+
repository: extractRepositoryUrl(pkg),
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Handle results array (fallback)
|
|
103
|
+
const results = safeArray<Record<string, unknown>>(data, 'results');
|
|
104
|
+
return results.map((pkg) => ({
|
|
105
|
+
name: safeString(pkg, 'name'),
|
|
106
|
+
version: hasStringProperty(pkg, 'version') ? pkg.version : undefined,
|
|
107
|
+
description: hasStringProperty(pkg, 'description') ? pkg.description : undefined,
|
|
108
|
+
repository: hasStringProperty(pkg, 'repository') ? pkg.repository : undefined,
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Helper: Extract repository URL from various formats
|
|
113
|
+
function extractRepositoryUrl(pkg: Record<string, unknown>): string | undefined {
|
|
114
|
+
if (hasStringProperty(pkg, 'repository')) {
|
|
115
|
+
return pkg.repository;
|
|
116
|
+
}
|
|
117
|
+
if (hasStringProperty(pkg, 'repoUrl')) {
|
|
118
|
+
return pkg.repoUrl;
|
|
119
|
+
}
|
|
120
|
+
if (hasProperty(pkg, 'repository') && isObject(pkg.repository)) {
|
|
121
|
+
const repo = pkg.repository;
|
|
122
|
+
if (hasStringProperty(repo, 'url')) {
|
|
123
|
+
return repo.url;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Router, type Request, type Response, type NextFunction } from 'express';
|
|
2
|
+
import { getMcpContent } from '../mcpCache.js';
|
|
3
|
+
import { logPromptCall } from '../index.js';
|
|
4
|
+
import { fireAndForgetWithTimeout } from '../utils/asyncTimeout.js';
|
|
5
|
+
import { checkReadiness } from '../middleware/readiness.js';
|
|
6
|
+
|
|
7
|
+
export const promptsRoutes = Router();
|
|
8
|
+
|
|
9
|
+
// Apply readiness check middleware to all prompts routes
|
|
10
|
+
promptsRoutes.use(checkReadiness);
|
|
11
|
+
|
|
12
|
+
// Package version for response metadata
|
|
13
|
+
const PACKAGE_VERSION = '2.0.0';
|
|
14
|
+
|
|
15
|
+
interface PromptArg {
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
required: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface PromptInfo {
|
|
22
|
+
name: string;
|
|
23
|
+
description: string;
|
|
24
|
+
arguments?: PromptArg[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* GET /prompts/list - List all prompts (MCP-compatible format)
|
|
29
|
+
*
|
|
30
|
+
* Returns prompt names, descriptions, and arguments following MCP protocol.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* GET /prompts/list
|
|
34
|
+
*
|
|
35
|
+
* Response:
|
|
36
|
+
* {
|
|
37
|
+
* "prompts": [
|
|
38
|
+
* {
|
|
39
|
+
* "name": "research",
|
|
40
|
+
* "description": "Start a code research session",
|
|
41
|
+
* "arguments": [
|
|
42
|
+
* { "name": "goal", "description": "The research goal", "required": true }
|
|
43
|
+
* ]
|
|
44
|
+
* }
|
|
45
|
+
* ],
|
|
46
|
+
* "_meta": { "totalCount": 5, "version": "2.0.0" }
|
|
47
|
+
* }
|
|
48
|
+
*/
|
|
49
|
+
promptsRoutes.get('/list', async (
|
|
50
|
+
_req: Request,
|
|
51
|
+
res: Response,
|
|
52
|
+
next: NextFunction
|
|
53
|
+
) => {
|
|
54
|
+
try {
|
|
55
|
+
const content = getMcpContent();
|
|
56
|
+
|
|
57
|
+
// Use Object.entries to get both key and prompt
|
|
58
|
+
// The key is what's used for lookup in /prompts/info/:promptName
|
|
59
|
+
const prompts: PromptInfo[] = Object.entries(content.prompts).map(([key, prompt]) => ({
|
|
60
|
+
name: key, // Use the key (lookup name), not prompt.name (display name may differ)
|
|
61
|
+
description: prompt.description,
|
|
62
|
+
arguments: prompt.args?.map(arg => ({
|
|
63
|
+
name: arg.name,
|
|
64
|
+
description: arg.description,
|
|
65
|
+
required: arg.required ?? false,
|
|
66
|
+
})),
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
res.json({
|
|
70
|
+
success: true,
|
|
71
|
+
data: {
|
|
72
|
+
prompts,
|
|
73
|
+
totalCount: prompts.length,
|
|
74
|
+
version: PACKAGE_VERSION,
|
|
75
|
+
},
|
|
76
|
+
hints: ['Use /prompts/info/{name} to get prompt content'],
|
|
77
|
+
});
|
|
78
|
+
} catch (error) {
|
|
79
|
+
next(error);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* GET /prompts/info/:promptName - Get specific prompt details
|
|
85
|
+
*
|
|
86
|
+
* Returns detailed information about a specific prompt.
|
|
87
|
+
*/
|
|
88
|
+
promptsRoutes.get('/info/:promptName', async (
|
|
89
|
+
req: Request,
|
|
90
|
+
res: Response,
|
|
91
|
+
next: NextFunction
|
|
92
|
+
) => {
|
|
93
|
+
try {
|
|
94
|
+
const content = getMcpContent();
|
|
95
|
+
const { promptName } = req.params;
|
|
96
|
+
|
|
97
|
+
const prompt = content.prompts[promptName];
|
|
98
|
+
|
|
99
|
+
if (!prompt) {
|
|
100
|
+
const availablePrompts = Object.keys(content.prompts);
|
|
101
|
+
res.status(404).json({
|
|
102
|
+
success: false,
|
|
103
|
+
data: null,
|
|
104
|
+
hints: [
|
|
105
|
+
`Prompt not found: ${promptName}`,
|
|
106
|
+
`Available prompts: ${availablePrompts.slice(0, 5).join(', ')}`,
|
|
107
|
+
'Check spelling and case sensitivity',
|
|
108
|
+
'Use /prompts/list to see all available prompts',
|
|
109
|
+
],
|
|
110
|
+
});
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Log prompt call for session telemetry
|
|
115
|
+
fireAndForgetWithTimeout(
|
|
116
|
+
() => logPromptCall(promptName),
|
|
117
|
+
5000,
|
|
118
|
+
'logPromptCall'
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
res.json({
|
|
122
|
+
success: true,
|
|
123
|
+
data: {
|
|
124
|
+
name: prompt.name,
|
|
125
|
+
description: prompt.description,
|
|
126
|
+
arguments: prompt.args?.map(arg => ({
|
|
127
|
+
name: arg.name,
|
|
128
|
+
description: arg.description,
|
|
129
|
+
required: arg.required ?? false,
|
|
130
|
+
})),
|
|
131
|
+
content: prompt.content,
|
|
132
|
+
},
|
|
133
|
+
hints: ['Follow the prompt instructions for best results'],
|
|
134
|
+
});
|
|
135
|
+
} catch (error) {
|
|
136
|
+
next(error);
|
|
137
|
+
}
|
|
138
|
+
});
|