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,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guards for safe error handling.
|
|
3
|
+
*
|
|
4
|
+
* Replaces unsafe type coercion (err as { status?: number }) with
|
|
5
|
+
* proper runtime type checking for better type safety.
|
|
6
|
+
*
|
|
7
|
+
* @module types/errorGuards
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// =============================================================================
|
|
11
|
+
// Error Interfaces
|
|
12
|
+
// =============================================================================
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Error with HTTP status code (e.g., from API responses)
|
|
16
|
+
*/
|
|
17
|
+
export interface ErrorWithStatus {
|
|
18
|
+
status: number;
|
|
19
|
+
message?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Error with error code (e.g., Node.js system errors)
|
|
24
|
+
*/
|
|
25
|
+
export interface ErrorWithCode {
|
|
26
|
+
code: string;
|
|
27
|
+
message?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Error with headers (e.g., rate limit responses)
|
|
32
|
+
*/
|
|
33
|
+
export interface ErrorWithHeaders {
|
|
34
|
+
headers: Record<string, string>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// =============================================================================
|
|
38
|
+
// Type Guards
|
|
39
|
+
// =============================================================================
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Check if error has a status property (number)
|
|
43
|
+
*/
|
|
44
|
+
export function isErrorWithStatus(err: unknown): err is ErrorWithStatus {
|
|
45
|
+
return (
|
|
46
|
+
err !== null &&
|
|
47
|
+
typeof err === 'object' &&
|
|
48
|
+
'status' in err &&
|
|
49
|
+
typeof (err as ErrorWithStatus).status === 'number'
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Check if error has a code property (string)
|
|
55
|
+
*/
|
|
56
|
+
export function isErrorWithCode(err: unknown): err is ErrorWithCode {
|
|
57
|
+
return (
|
|
58
|
+
err !== null &&
|
|
59
|
+
typeof err === 'object' &&
|
|
60
|
+
'code' in err &&
|
|
61
|
+
typeof (err as ErrorWithCode).code === 'string'
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Check if error has a message property (string)
|
|
67
|
+
*/
|
|
68
|
+
export function hasMessage(err: unknown): err is { message: string } {
|
|
69
|
+
return (
|
|
70
|
+
err !== null &&
|
|
71
|
+
typeof err === 'object' &&
|
|
72
|
+
'message' in err &&
|
|
73
|
+
typeof (err as { message: unknown }).message === 'string'
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Check if error has headers property (object)
|
|
79
|
+
*/
|
|
80
|
+
export function hasHeaders(err: unknown): err is ErrorWithHeaders {
|
|
81
|
+
return (
|
|
82
|
+
err !== null &&
|
|
83
|
+
typeof err === 'object' &&
|
|
84
|
+
'headers' in err &&
|
|
85
|
+
typeof (err as { headers: unknown }).headers === 'object' &&
|
|
86
|
+
(err as ErrorWithHeaders).headers !== null
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// =============================================================================
|
|
91
|
+
// Safe Property Accessors
|
|
92
|
+
// =============================================================================
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Safely get status from error (undefined if not present)
|
|
96
|
+
*/
|
|
97
|
+
export function getErrorStatus(err: unknown): number | undefined {
|
|
98
|
+
return isErrorWithStatus(err) ? err.status : undefined;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Safely get code from error (undefined if not present)
|
|
103
|
+
*/
|
|
104
|
+
export function getErrorCode(err: unknown): string | undefined {
|
|
105
|
+
return isErrorWithCode(err) ? err.code : undefined;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Safely get message from error (undefined if not present)
|
|
110
|
+
*/
|
|
111
|
+
export function getErrorMessage(err: unknown): string | undefined {
|
|
112
|
+
return hasMessage(err) ? err.message : undefined;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Safely get header value from error (undefined if not present)
|
|
117
|
+
*/
|
|
118
|
+
export function getErrorHeader(err: unknown, header: string): string | undefined {
|
|
119
|
+
if (hasHeaders(err)) {
|
|
120
|
+
return err.headers[header];
|
|
121
|
+
}
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// =============================================================================
|
|
126
|
+
// Composite Checks
|
|
127
|
+
// =============================================================================
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Check if error status is in a given list
|
|
131
|
+
*/
|
|
132
|
+
export function hasStatusIn(err: unknown, statuses: readonly number[]): boolean {
|
|
133
|
+
const status = getErrorStatus(err);
|
|
134
|
+
return status !== undefined && statuses.includes(status);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Check if error code is in a given list
|
|
139
|
+
*/
|
|
140
|
+
export function hasCodeIn(err: unknown, codes: readonly string[]): boolean {
|
|
141
|
+
const code = getErrorCode(err);
|
|
142
|
+
return code !== undefined && codes.includes(code);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Check if error message matches any pattern
|
|
147
|
+
*/
|
|
148
|
+
export function messageMatches(err: unknown, patterns: readonly RegExp[]): boolean {
|
|
149
|
+
const message = getErrorMessage(err);
|
|
150
|
+
return message !== undefined && patterns.some((p) => p.test(message));
|
|
151
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
declare module 'express' {
|
|
3
|
+
import { IncomingMessage, ServerResponse, Server } from 'http';
|
|
4
|
+
|
|
5
|
+
export interface ResearchContext {
|
|
6
|
+
sessionId: string;
|
|
7
|
+
mainGoal: string;
|
|
8
|
+
toolChain: string[];
|
|
9
|
+
startTime: number;
|
|
10
|
+
lastActivity: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Request extends IncomingMessage {
|
|
14
|
+
query: Record<string, any>;
|
|
15
|
+
params: Record<string, string>;
|
|
16
|
+
body: any;
|
|
17
|
+
method: string;
|
|
18
|
+
path: string;
|
|
19
|
+
researchContext?: ResearchContext;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface Response extends ServerResponse {
|
|
23
|
+
status(code: number): Response;
|
|
24
|
+
json(body: any): Response;
|
|
25
|
+
send(body: any): Response;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type NextFunction = (err?: any) => void;
|
|
29
|
+
|
|
30
|
+
export type RequestHandler = (
|
|
31
|
+
req: Request,
|
|
32
|
+
res: Response,
|
|
33
|
+
next: NextFunction
|
|
34
|
+
) => void | Promise<void>;
|
|
35
|
+
|
|
36
|
+
export type ErrorRequestHandler = (
|
|
37
|
+
err: any,
|
|
38
|
+
req: Request,
|
|
39
|
+
res: Response,
|
|
40
|
+
next: NextFunction
|
|
41
|
+
) => void | Promise<void>;
|
|
42
|
+
|
|
43
|
+
export interface Router {
|
|
44
|
+
get(path: string, ...handlers: RequestHandler[]): Router;
|
|
45
|
+
post(path: string, ...handlers: RequestHandler[]): Router;
|
|
46
|
+
put(path: string, ...handlers: RequestHandler[]): Router;
|
|
47
|
+
delete(path: string, ...handlers: RequestHandler[]): Router;
|
|
48
|
+
use(...handlers: (RequestHandler | ErrorRequestHandler)[]): Router;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface Express {
|
|
52
|
+
listen(port: number, hostname: string, backlog: number, callback?: () => void): Server;
|
|
53
|
+
listen(port: number, hostname: string, callback?: () => void): Server;
|
|
54
|
+
listen(port: number, callback?: () => void): Server;
|
|
55
|
+
listen(callback?: () => void): Server;
|
|
56
|
+
get(path: string, handler: RequestHandler): Express;
|
|
57
|
+
use(path: string, router: Router): Express;
|
|
58
|
+
use(handler: RequestHandler | ErrorRequestHandler): Express;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface ExpressFunction {
|
|
62
|
+
(): Express;
|
|
63
|
+
Router(): Router;
|
|
64
|
+
json(): RequestHandler;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const express: ExpressFunction;
|
|
68
|
+
export default express;
|
|
69
|
+
export function Router(): Router;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
declare module 'qs' {
|
|
73
|
+
export interface ParsedQs {
|
|
74
|
+
[key: string]: any;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guard utilities for consistent runtime type checking.
|
|
3
|
+
* Use these instead of inline typeof checks across routes.
|
|
4
|
+
*
|
|
5
|
+
* @module types/guards
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Check if value is a non-empty string
|
|
10
|
+
*/
|
|
11
|
+
export function isNonEmptyString(value: unknown): value is string {
|
|
12
|
+
return typeof value === 'string' && value.length > 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Check if value is a positive finite number
|
|
17
|
+
*/
|
|
18
|
+
export function isPositiveNumber(value: unknown): value is number {
|
|
19
|
+
return typeof value === 'number' && value > 0 && Number.isFinite(value);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Check if value is a non-negative finite number
|
|
24
|
+
*/
|
|
25
|
+
export function isNonNegativeNumber(value: unknown): value is number {
|
|
26
|
+
return typeof value === 'number' && value >= 0 && Number.isFinite(value);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Check if value is an array of non-empty strings
|
|
31
|
+
*/
|
|
32
|
+
export function isStringArray(value: unknown): value is string[] {
|
|
33
|
+
return Array.isArray(value) && value.every(isNonEmptyString);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Check if value is an array (of any type)
|
|
38
|
+
*/
|
|
39
|
+
export function isArray(value: unknown): value is unknown[] {
|
|
40
|
+
return Array.isArray(value);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Check if value is a non-null object
|
|
45
|
+
*/
|
|
46
|
+
export function isObject(value: unknown): value is Record<string, unknown> {
|
|
47
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Check if object has a specific property
|
|
52
|
+
*/
|
|
53
|
+
export function hasProperty<K extends string>(
|
|
54
|
+
obj: unknown,
|
|
55
|
+
key: K
|
|
56
|
+
): obj is Record<K, unknown> {
|
|
57
|
+
return typeof obj === 'object' && obj !== null && key in obj;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Check if object has a string property
|
|
62
|
+
*/
|
|
63
|
+
export function hasStringProperty<K extends string>(
|
|
64
|
+
obj: unknown,
|
|
65
|
+
key: K
|
|
66
|
+
): obj is Record<K, string> {
|
|
67
|
+
return hasProperty(obj, key) && typeof obj[key] === 'string';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Check if object has a number property
|
|
72
|
+
*/
|
|
73
|
+
export function hasNumberProperty<K extends string>(
|
|
74
|
+
obj: unknown,
|
|
75
|
+
key: K
|
|
76
|
+
): obj is Record<K, number> {
|
|
77
|
+
return hasProperty(obj, key) && typeof obj[key] === 'number';
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Check if object has a boolean property
|
|
82
|
+
*/
|
|
83
|
+
export function hasBooleanProperty<K extends string>(
|
|
84
|
+
obj: unknown,
|
|
85
|
+
key: K
|
|
86
|
+
): obj is Record<K, boolean> {
|
|
87
|
+
return hasProperty(obj, key) && typeof obj[key] === 'boolean';
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Check if object has an array property
|
|
92
|
+
*/
|
|
93
|
+
export function hasArrayProperty<K extends string>(
|
|
94
|
+
obj: unknown,
|
|
95
|
+
key: K
|
|
96
|
+
): obj is Record<K, unknown[]> {
|
|
97
|
+
return hasProperty(obj, key) && Array.isArray(obj[key]);
|
|
98
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Protocol Types for /tools/list and /prompts/list endpoints
|
|
3
|
+
* Based on: https://modelcontextprotocol.io/docs/concepts/tools
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// JSON Schema type for tool input schemas
|
|
7
|
+
export interface JsonSchema {
|
|
8
|
+
$schema?: string;
|
|
9
|
+
type: 'object';
|
|
10
|
+
properties: Record<string, JsonSchemaProperty>;
|
|
11
|
+
required?: string[];
|
|
12
|
+
additionalProperties?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface JsonSchemaProperty {
|
|
16
|
+
type: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
items?: JsonSchemaProperty;
|
|
19
|
+
properties?: Record<string, JsonSchemaProperty>;
|
|
20
|
+
required?: string[];
|
|
21
|
+
minItems?: number;
|
|
22
|
+
maxItems?: number;
|
|
23
|
+
minimum?: number;
|
|
24
|
+
maximum?: number;
|
|
25
|
+
minLength?: number;
|
|
26
|
+
maxLength?: number;
|
|
27
|
+
enum?: (string | number | boolean)[];
|
|
28
|
+
default?: unknown;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* MCP Tool representation for /tools/list
|
|
33
|
+
*/
|
|
34
|
+
interface McpTool {
|
|
35
|
+
name: string;
|
|
36
|
+
description: string;
|
|
37
|
+
inputSchema: JsonSchema;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* MCP Prompt argument for /prompts/list
|
|
42
|
+
*/
|
|
43
|
+
export interface McpPromptArgument {
|
|
44
|
+
name: string;
|
|
45
|
+
description: string;
|
|
46
|
+
required?: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* MCP Prompt representation for /prompts/list
|
|
51
|
+
*/
|
|
52
|
+
export interface McpPrompt {
|
|
53
|
+
name: string;
|
|
54
|
+
description: string;
|
|
55
|
+
arguments?: McpPromptArgument[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Response metadata
|
|
60
|
+
*/
|
|
61
|
+
export interface ListResponseMeta {
|
|
62
|
+
totalCount: number;
|
|
63
|
+
version: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Response type for GET /tools/list
|
|
68
|
+
*/
|
|
69
|
+
export interface ListToolsResponse {
|
|
70
|
+
tools: McpTool[];
|
|
71
|
+
_meta?: ListResponseMeta;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Response type for GET /prompts/list
|
|
76
|
+
*/
|
|
77
|
+
export interface ListPromptsResponse {
|
|
78
|
+
prompts: McpPrompt[];
|
|
79
|
+
_meta?: ListResponseMeta;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Transform description-based schema to JSON Schema format
|
|
84
|
+
* This is a fallback transformer when full JSON schemas are not available
|
|
85
|
+
*/
|
|
86
|
+
export function transformToJsonSchema(
|
|
87
|
+
schemaDescriptions: Record<string, string>,
|
|
88
|
+
toolName: string
|
|
89
|
+
): JsonSchema {
|
|
90
|
+
const properties: Record<string, JsonSchemaProperty> = {};
|
|
91
|
+
|
|
92
|
+
// Create properties from descriptions
|
|
93
|
+
for (const [key, description] of Object.entries(schemaDescriptions)) {
|
|
94
|
+
properties[key] = {
|
|
95
|
+
type: 'string', // Default type - could be enhanced with type inference
|
|
96
|
+
description,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Wrap in queries array structure (standard MCP bulk query pattern)
|
|
101
|
+
return {
|
|
102
|
+
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
103
|
+
type: 'object',
|
|
104
|
+
properties: {
|
|
105
|
+
queries: {
|
|
106
|
+
type: 'array',
|
|
107
|
+
description: `Research queries for ${toolName} (1-3 queries per call for optimal resource management). Review schema before use for optimal results`,
|
|
108
|
+
items: {
|
|
109
|
+
type: 'object',
|
|
110
|
+
properties,
|
|
111
|
+
required: ['mainResearchGoal', 'researchGoal', 'reasoning'],
|
|
112
|
+
},
|
|
113
|
+
minItems: 1,
|
|
114
|
+
maxItems: 3,
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
required: ['queries'],
|
|
118
|
+
};
|
|
119
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response types for MCP tool results.
|
|
3
|
+
* Use these instead of Record<string, unknown> for type-safe data handling.
|
|
4
|
+
*
|
|
5
|
+
* @module types/responses
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { hasProperty, hasArrayProperty } from './guards.js';
|
|
9
|
+
|
|
10
|
+
// =============================================================================
|
|
11
|
+
// File and Search Types
|
|
12
|
+
// =============================================================================
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A match within a file
|
|
16
|
+
*/
|
|
17
|
+
export interface MatchLocation {
|
|
18
|
+
line: number;
|
|
19
|
+
column?: number;
|
|
20
|
+
value?: string;
|
|
21
|
+
byteOffset?: number;
|
|
22
|
+
charOffset?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A file with matches from search results
|
|
27
|
+
*/
|
|
28
|
+
export interface FileMatch {
|
|
29
|
+
path: string;
|
|
30
|
+
line?: number;
|
|
31
|
+
column?: number;
|
|
32
|
+
matchText?: string;
|
|
33
|
+
matchCount?: number;
|
|
34
|
+
contextBefore?: string[];
|
|
35
|
+
contextAfter?: string[];
|
|
36
|
+
allMatches?: MatchLocation[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Pagination info for paginated results
|
|
41
|
+
*/
|
|
42
|
+
export interface PaginationInfo {
|
|
43
|
+
page?: number;
|
|
44
|
+
currentPage?: number;
|
|
45
|
+
totalPages?: number;
|
|
46
|
+
totalMatches?: number;
|
|
47
|
+
totalFiles?: number;
|
|
48
|
+
hasMore?: boolean;
|
|
49
|
+
nextCursor?: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Search result from localSearchCode or githubSearchCode
|
|
54
|
+
*/
|
|
55
|
+
interface SearchResult {
|
|
56
|
+
files?: FileMatch[];
|
|
57
|
+
totalMatches?: number;
|
|
58
|
+
totalFiles?: number;
|
|
59
|
+
pagination?: PaginationInfo;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// =============================================================================
|
|
63
|
+
// LSP Types
|
|
64
|
+
// =============================================================================
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* LSP position
|
|
68
|
+
*/
|
|
69
|
+
interface LspPosition {
|
|
70
|
+
line: number;
|
|
71
|
+
character: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* LSP range
|
|
76
|
+
*/
|
|
77
|
+
interface LspRange {
|
|
78
|
+
start: LspPosition;
|
|
79
|
+
end: LspPosition;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* LSP definition location
|
|
84
|
+
*/
|
|
85
|
+
interface LspDefinition {
|
|
86
|
+
uri: string;
|
|
87
|
+
range: LspRange;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* LSP reference location
|
|
92
|
+
*/
|
|
93
|
+
export interface LspReference extends LspDefinition {
|
|
94
|
+
context?: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* LSP call hierarchy item
|
|
99
|
+
*/
|
|
100
|
+
export interface LspCallHierarchyItem {
|
|
101
|
+
name: string;
|
|
102
|
+
kind?: number;
|
|
103
|
+
uri: string;
|
|
104
|
+
range?: LspRange;
|
|
105
|
+
selectionRange?: LspRange;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// =============================================================================
|
|
109
|
+
// Repository Structure Types
|
|
110
|
+
// =============================================================================
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Repository structure result
|
|
114
|
+
*/
|
|
115
|
+
export interface RepoStructure {
|
|
116
|
+
files?: string[];
|
|
117
|
+
folders?: string[];
|
|
118
|
+
totalFiles?: number;
|
|
119
|
+
totalDirectories?: number;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// =============================================================================
|
|
123
|
+
// Type Guards
|
|
124
|
+
// =============================================================================
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Check if an object is a FileMatch
|
|
128
|
+
*/
|
|
129
|
+
function isFileMatch(obj: unknown): obj is FileMatch {
|
|
130
|
+
return (
|
|
131
|
+
typeof obj === 'object' &&
|
|
132
|
+
obj !== null &&
|
|
133
|
+
'path' in obj &&
|
|
134
|
+
typeof (obj as FileMatch).path === 'string'
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Check if an object has valid pagination info
|
|
140
|
+
*/
|
|
141
|
+
function hasValidPagination(obj: unknown): obj is { pagination: PaginationInfo } {
|
|
142
|
+
if (!hasProperty(obj, 'pagination')) return false;
|
|
143
|
+
const p = obj.pagination;
|
|
144
|
+
return typeof p === 'object' && p !== null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Check if an object is a SearchResult
|
|
149
|
+
*/
|
|
150
|
+
export function isSearchResult(obj: unknown): obj is SearchResult {
|
|
151
|
+
if (typeof obj !== 'object' || obj === null) return false;
|
|
152
|
+
if (hasArrayProperty(obj, 'files')) {
|
|
153
|
+
const files = (obj as { files: unknown[] }).files;
|
|
154
|
+
return files.every(isFileMatch);
|
|
155
|
+
}
|
|
156
|
+
return hasProperty(obj, 'totalMatches') || hasProperty(obj, 'totalFiles');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Check if an object is an LspDefinition
|
|
161
|
+
*/
|
|
162
|
+
export function isLspDefinition(obj: unknown): obj is LspDefinition {
|
|
163
|
+
return (
|
|
164
|
+
typeof obj === 'object' &&
|
|
165
|
+
obj !== null &&
|
|
166
|
+
'uri' in obj &&
|
|
167
|
+
'range' in obj &&
|
|
168
|
+
typeof (obj as LspDefinition).uri === 'string'
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Extract files array from data safely
|
|
174
|
+
*/
|
|
175
|
+
export function extractFiles(data: unknown): FileMatch[] {
|
|
176
|
+
if (!hasArrayProperty(data, 'files')) return [];
|
|
177
|
+
return (data as { files: unknown[] }).files.filter(isFileMatch);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Extract pagination from data safely
|
|
182
|
+
*/
|
|
183
|
+
export function extractPagination(data: unknown): PaginationInfo | undefined {
|
|
184
|
+
if (!hasValidPagination(data)) return undefined;
|
|
185
|
+
return data.pagination;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Extract total matches from data safely
|
|
190
|
+
*/
|
|
191
|
+
export function extractTotalMatches(data: unknown): number {
|
|
192
|
+
if (hasProperty(data, 'totalMatches') && typeof data.totalMatches === 'number') {
|
|
193
|
+
return data.totalMatches;
|
|
194
|
+
}
|
|
195
|
+
if (hasValidPagination(data) && typeof data.pagination.totalMatches === 'number') {
|
|
196
|
+
return data.pagination.totalMatches;
|
|
197
|
+
}
|
|
198
|
+
return 0;
|
|
199
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type adapter for converting validated query inputs to MCP tool parameters.
|
|
3
|
+
* All MCP tools expect { queries: T[] } format.
|
|
4
|
+
*
|
|
5
|
+
* @module types/toolTypes
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Base query parameters that all tool queries may include.
|
|
10
|
+
*/
|
|
11
|
+
export interface BaseQueryParams {
|
|
12
|
+
mainResearchGoal?: string;
|
|
13
|
+
researchGoal?: string;
|
|
14
|
+
reasoning?: string;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Result type for tool query parameters.
|
|
20
|
+
*/
|
|
21
|
+
export interface QueryParamsResult<T extends BaseQueryParams = BaseQueryParams> {
|
|
22
|
+
queries: T[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Convert validated query to MCP tool format.
|
|
27
|
+
* Works for all tools - local, GitHub, LSP, and package search.
|
|
28
|
+
*/
|
|
29
|
+
export function toQueryParams<T extends BaseQueryParams>(
|
|
30
|
+
validated: T[]
|
|
31
|
+
): QueryParamsResult<T> {
|
|
32
|
+
return { queries: validated };
|
|
33
|
+
}
|