symbiote-cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/bin/symbiote.d.ts +3 -0
- package/dist/bin/symbiote.d.ts.map +1 -0
- package/dist/bin/symbiote.js +202 -0
- package/dist/bin/symbiote.js.map +1 -0
- package/dist/bin/synapse.d.ts +3 -0
- package/dist/bin/synapse.d.ts.map +1 -0
- package/dist/bin/synapse.js +369 -0
- package/dist/bin/synapse.js.map +1 -0
- package/dist/src/brain/embeddings.d.ts +9 -0
- package/dist/src/brain/embeddings.d.ts.map +1 -0
- package/dist/src/brain/embeddings.js +24 -0
- package/dist/src/brain/embeddings.js.map +1 -0
- package/dist/src/brain/health/constraint-checker.d.ts +16 -0
- package/dist/src/brain/health/constraint-checker.d.ts.map +1 -0
- package/dist/src/brain/health/constraint-checker.js +93 -0
- package/dist/src/brain/health/constraint-checker.js.map +1 -0
- package/dist/src/brain/health/coupling-analyzer.d.ts +9 -0
- package/dist/src/brain/health/coupling-analyzer.d.ts.map +1 -0
- package/dist/src/brain/health/coupling-analyzer.js +105 -0
- package/dist/src/brain/health/coupling-analyzer.js.map +1 -0
- package/dist/src/brain/health/cycle-detector.d.ts +12 -0
- package/dist/src/brain/health/cycle-detector.d.ts.map +1 -0
- package/dist/src/brain/health/cycle-detector.js +79 -0
- package/dist/src/brain/health/cycle-detector.js.map +1 -0
- package/dist/src/brain/health/dead-code-detector.d.ts +9 -0
- package/dist/src/brain/health/dead-code-detector.d.ts.map +1 -0
- package/dist/src/brain/health/dead-code-detector.js +72 -0
- package/dist/src/brain/health/dead-code-detector.js.map +1 -0
- package/dist/src/brain/health/history.d.ts +21 -0
- package/dist/src/brain/health/history.d.ts.map +1 -0
- package/dist/src/brain/health/history.js +35 -0
- package/dist/src/brain/health/history.js.map +1 -0
- package/dist/src/brain/health/index.d.ts +25 -0
- package/dist/src/brain/health/index.d.ts.map +1 -0
- package/dist/src/brain/health/index.js +76 -0
- package/dist/src/brain/health/index.js.map +1 -0
- package/dist/src/brain/health/scorer.d.ts +19 -0
- package/dist/src/brain/health/scorer.d.ts.map +1 -0
- package/dist/src/brain/health/scorer.js +47 -0
- package/dist/src/brain/health/scorer.js.map +1 -0
- package/dist/src/brain/health/types.d.ts +67 -0
- package/dist/src/brain/health/types.d.ts.map +1 -0
- package/dist/src/brain/health/types.js +2 -0
- package/dist/src/brain/health/types.js.map +1 -0
- package/dist/src/brain/health.d.ts +30 -0
- package/dist/src/brain/health.d.ts.map +1 -0
- package/dist/src/brain/health.js +147 -0
- package/dist/src/brain/health.js.map +1 -0
- package/dist/src/brain/index.d.ts +3 -0
- package/dist/src/brain/index.d.ts.map +1 -0
- package/dist/src/brain/index.js +3 -0
- package/dist/src/brain/index.js.map +1 -0
- package/dist/src/brain/intent.d.ts +31 -0
- package/dist/src/brain/intent.d.ts.map +1 -0
- package/dist/src/brain/intent.js +120 -0
- package/dist/src/brain/intent.js.map +1 -0
- package/dist/src/commands/dna.d.ts +2 -0
- package/dist/src/commands/dna.d.ts.map +1 -0
- package/dist/src/commands/dna.js +128 -0
- package/dist/src/commands/dna.js.map +1 -0
- package/dist/src/commands/hooks.d.ts +6 -0
- package/dist/src/commands/hooks.d.ts.map +1 -0
- package/dist/src/commands/hooks.js +210 -0
- package/dist/src/commands/hooks.js.map +1 -0
- package/dist/src/commands/impact.d.ts +2 -0
- package/dist/src/commands/impact.d.ts.map +1 -0
- package/dist/src/commands/impact.js +50 -0
- package/dist/src/commands/impact.js.map +1 -0
- package/dist/src/commands/index.d.ts +9 -0
- package/dist/src/commands/index.d.ts.map +1 -0
- package/dist/src/commands/index.js +9 -0
- package/dist/src/commands/index.js.map +1 -0
- package/dist/src/commands/init.d.ts +2 -0
- package/dist/src/commands/init.d.ts.map +1 -0
- package/dist/src/commands/init.js +132 -0
- package/dist/src/commands/init.js.map +1 -0
- package/dist/src/commands/install.d.ts +2 -0
- package/dist/src/commands/install.d.ts.map +1 -0
- package/dist/src/commands/install.js +67 -0
- package/dist/src/commands/install.js.map +1 -0
- package/dist/src/commands/mcp.d.ts +2 -0
- package/dist/src/commands/mcp.d.ts.map +1 -0
- package/dist/src/commands/mcp.js +51 -0
- package/dist/src/commands/mcp.js.map +1 -0
- package/dist/src/commands/scan.d.ts +2 -0
- package/dist/src/commands/scan.d.ts.map +1 -0
- package/dist/src/commands/scan.js +46 -0
- package/dist/src/commands/scan.js.map +1 -0
- package/dist/src/commands/serve.d.ts +2 -0
- package/dist/src/commands/serve.d.ts.map +1 -0
- package/dist/src/commands/serve.js +93 -0
- package/dist/src/commands/serve.js.map +1 -0
- package/dist/src/commands/shared.d.ts +11 -0
- package/dist/src/commands/shared.d.ts.map +1 -0
- package/dist/src/commands/shared.js +137 -0
- package/dist/src/commands/shared.js.map +1 -0
- package/dist/src/commands/unbond.d.ts +2 -0
- package/dist/src/commands/unbond.d.ts.map +1 -0
- package/dist/src/commands/unbond.js +29 -0
- package/dist/src/commands/unbond.js.map +1 -0
- package/dist/src/core/algorithms.d.ts +19 -0
- package/dist/src/core/algorithms.d.ts.map +1 -0
- package/dist/src/core/algorithms.js +98 -0
- package/dist/src/core/algorithms.js.map +1 -0
- package/dist/src/core/embeddings.d.ts +12 -0
- package/dist/src/core/embeddings.d.ts.map +1 -0
- package/dist/src/core/embeddings.js +64 -0
- package/dist/src/core/embeddings.js.map +1 -0
- package/dist/src/core/git-impact.d.ts +25 -0
- package/dist/src/core/git-impact.d.ts.map +1 -0
- package/dist/src/core/git-impact.js +97 -0
- package/dist/src/core/git-impact.js.map +1 -0
- package/dist/src/core/graph-builder.d.ts +5 -0
- package/dist/src/core/graph-builder.d.ts.map +1 -0
- package/dist/src/core/graph-builder.js +88 -0
- package/dist/src/core/graph-builder.js.map +1 -0
- package/dist/src/core/graph.d.ts +34 -0
- package/dist/src/core/graph.d.ts.map +1 -0
- package/dist/src/core/graph.js +95 -0
- package/dist/src/core/graph.js.map +1 -0
- package/dist/src/core/impact.d.ts +22 -0
- package/dist/src/core/impact.d.ts.map +1 -0
- package/dist/src/core/impact.js +68 -0
- package/dist/src/core/impact.js.map +1 -0
- package/dist/src/core/languages.d.ts +4 -0
- package/dist/src/core/languages.d.ts.map +1 -0
- package/dist/src/core/languages.js +59 -0
- package/dist/src/core/languages.js.map +1 -0
- package/dist/src/core/parser.d.ts +16 -0
- package/dist/src/core/parser.d.ts.map +1 -0
- package/dist/src/core/parser.js +689 -0
- package/dist/src/core/parser.js.map +1 -0
- package/dist/src/core/scanner.d.ts +26 -0
- package/dist/src/core/scanner.d.ts.map +1 -0
- package/dist/src/core/scanner.js +87 -0
- package/dist/src/core/scanner.js.map +1 -0
- package/dist/src/core/search.d.ts +34 -0
- package/dist/src/core/search.d.ts.map +1 -0
- package/dist/src/core/search.js +146 -0
- package/dist/src/core/search.js.map +1 -0
- package/dist/src/core/types.d.ts +29 -0
- package/dist/src/core/types.d.ts.map +1 -0
- package/dist/src/core/types.js +12 -0
- package/dist/src/core/types.js.map +1 -0
- package/dist/src/cortex/engine.d.ts +10 -0
- package/dist/src/cortex/engine.d.ts.map +1 -0
- package/dist/src/cortex/engine.js +93 -0
- package/dist/src/cortex/engine.js.map +1 -0
- package/dist/src/cortex/index.d.ts +13 -0
- package/dist/src/cortex/index.d.ts.map +1 -0
- package/dist/src/cortex/index.js +12 -0
- package/dist/src/cortex/index.js.map +1 -0
- package/dist/src/cortex/patterns.d.ts +63 -0
- package/dist/src/cortex/patterns.d.ts.map +1 -0
- package/dist/src/cortex/patterns.js +242 -0
- package/dist/src/cortex/patterns.js.map +1 -0
- package/dist/src/cortex/pgq-queries.d.ts +11 -0
- package/dist/src/cortex/pgq-queries.d.ts.map +1 -0
- package/dist/src/cortex/pgq-queries.js +23 -0
- package/dist/src/cortex/pgq-queries.js.map +1 -0
- package/dist/src/cortex/pgq.d.ts +5 -0
- package/dist/src/cortex/pgq.d.ts.map +1 -0
- package/dist/src/cortex/pgq.js +54 -0
- package/dist/src/cortex/pgq.js.map +1 -0
- package/dist/src/cortex/real-time-enrichment.d.ts +20 -0
- package/dist/src/cortex/real-time-enrichment.d.ts.map +1 -0
- package/dist/src/cortex/real-time-enrichment.js +96 -0
- package/dist/src/cortex/real-time-enrichment.js.map +1 -0
- package/dist/src/cortex/repository.d.ts +231 -0
- package/dist/src/cortex/repository.d.ts.map +1 -0
- package/dist/src/cortex/repository.js +1078 -0
- package/dist/src/cortex/repository.js.map +1 -0
- package/dist/src/cortex/schema.d.ts +9 -0
- package/dist/src/cortex/schema.d.ts.map +1 -0
- package/dist/src/cortex/schema.js +364 -0
- package/dist/src/cortex/schema.js.map +1 -0
- package/dist/src/cortex/stage-0-structure.d.ts +7 -0
- package/dist/src/cortex/stage-0-structure.d.ts.map +1 -0
- package/dist/src/cortex/stage-0-structure.js +119 -0
- package/dist/src/cortex/stage-0-structure.js.map +1 -0
- package/dist/src/cortex/stage-1-symbols.d.ts +7 -0
- package/dist/src/cortex/stage-1-symbols.d.ts.map +1 -0
- package/dist/src/cortex/stage-1-symbols.js +605 -0
- package/dist/src/cortex/stage-1-symbols.js.map +1 -0
- package/dist/src/cortex/stage-2-resolution.d.ts +7 -0
- package/dist/src/cortex/stage-2-resolution.d.ts.map +1 -0
- package/dist/src/cortex/stage-2-resolution.js +469 -0
- package/dist/src/cortex/stage-2-resolution.js.map +1 -0
- package/dist/src/cortex/stage-3-callgraph.d.ts +7 -0
- package/dist/src/cortex/stage-3-callgraph.d.ts.map +1 -0
- package/dist/src/cortex/stage-3-callgraph.js +323 -0
- package/dist/src/cortex/stage-3-callgraph.js.map +1 -0
- package/dist/src/cortex/stage-4-types.d.ts +7 -0
- package/dist/src/cortex/stage-4-types.d.ts.map +1 -0
- package/dist/src/cortex/stage-4-types.js +462 -0
- package/dist/src/cortex/stage-4-types.js.map +1 -0
- package/dist/src/cortex/stage-5-flow.d.ts +7 -0
- package/dist/src/cortex/stage-5-flow.d.ts.map +1 -0
- package/dist/src/cortex/stage-5-flow.js +702 -0
- package/dist/src/cortex/stage-5-flow.js.map +1 -0
- package/dist/src/cortex/stage-6-topology.d.ts +15 -0
- package/dist/src/cortex/stage-6-topology.d.ts.map +1 -0
- package/dist/src/cortex/stage-6-topology.js +382 -0
- package/dist/src/cortex/stage-6-topology.js.map +1 -0
- package/dist/src/cortex/stage-7-intelligence.d.ts +34 -0
- package/dist/src/cortex/stage-7-intelligence.d.ts.map +1 -0
- package/dist/src/cortex/stage-7-intelligence.js +258 -0
- package/dist/src/cortex/stage-7-intelligence.js.map +1 -0
- package/dist/src/cortex/topology-types.d.ts +78 -0
- package/dist/src/cortex/topology-types.d.ts.map +1 -0
- package/dist/src/cortex/topology-types.js +2 -0
- package/dist/src/cortex/topology-types.js.map +1 -0
- package/dist/src/cortex/types.d.ts +250 -0
- package/dist/src/cortex/types.d.ts.map +1 -0
- package/dist/src/cortex/types.js +2 -0
- package/dist/src/cortex/types.js.map +1 -0
- package/dist/src/dna/embeddings.d.ts +10 -0
- package/dist/src/dna/embeddings.d.ts.map +1 -0
- package/dist/src/dna/embeddings.js +46 -0
- package/dist/src/dna/embeddings.js.map +1 -0
- package/dist/src/dna/engine.d.ts +30 -0
- package/dist/src/dna/engine.d.ts.map +1 -0
- package/dist/src/dna/engine.js +254 -0
- package/dist/src/dna/engine.js.map +1 -0
- package/dist/src/dna/index.d.ts +5 -0
- package/dist/src/dna/index.d.ts.map +1 -0
- package/dist/src/dna/index.js +5 -0
- package/dist/src/dna/index.js.map +1 -0
- package/dist/src/dna/storage.d.ts +19 -0
- package/dist/src/dna/storage.d.ts.map +1 -0
- package/dist/src/dna/storage.js +112 -0
- package/dist/src/dna/storage.js.map +1 -0
- package/dist/src/dna/types.d.ts +38 -0
- package/dist/src/dna/types.d.ts.map +1 -0
- package/dist/src/dna/types.js +114 -0
- package/dist/src/dna/types.js.map +1 -0
- package/dist/src/events/bus.d.ts +10 -0
- package/dist/src/events/bus.d.ts.map +1 -0
- package/dist/src/events/bus.js +36 -0
- package/dist/src/events/bus.js.map +1 -0
- package/dist/src/events/ipc.d.ts +3 -0
- package/dist/src/events/ipc.d.ts.map +1 -0
- package/dist/src/events/ipc.js +25 -0
- package/dist/src/events/ipc.js.map +1 -0
- package/dist/src/events/session.d.ts +21 -0
- package/dist/src/events/session.d.ts.map +1 -0
- package/dist/src/events/session.js +39 -0
- package/dist/src/events/session.js.map +1 -0
- package/dist/src/events/types.d.ts +15 -0
- package/dist/src/events/types.d.ts.map +1 -0
- package/dist/src/events/types.js +26 -0
- package/dist/src/events/types.js.map +1 -0
- package/dist/src/hooks/attention.d.ts +26 -0
- package/dist/src/hooks/attention.d.ts.map +1 -0
- package/dist/src/hooks/attention.js +90 -0
- package/dist/src/hooks/attention.js.map +1 -0
- package/dist/src/hooks/handlers/post-tool-use-failure.d.ts +20 -0
- package/dist/src/hooks/handlers/post-tool-use-failure.d.ts.map +1 -0
- package/dist/src/hooks/handlers/post-tool-use-failure.js +60 -0
- package/dist/src/hooks/handlers/post-tool-use-failure.js.map +1 -0
- package/dist/src/hooks/handlers/post-tool-use.d.ts +22 -0
- package/dist/src/hooks/handlers/post-tool-use.d.ts.map +1 -0
- package/dist/src/hooks/handlers/post-tool-use.js +96 -0
- package/dist/src/hooks/handlers/post-tool-use.js.map +1 -0
- package/dist/src/hooks/handlers/pre-compact.d.ts +17 -0
- package/dist/src/hooks/handlers/pre-compact.d.ts.map +1 -0
- package/dist/src/hooks/handlers/pre-compact.js +28 -0
- package/dist/src/hooks/handlers/pre-compact.js.map +1 -0
- package/dist/src/hooks/handlers/pre-tool-use.d.ts +32 -0
- package/dist/src/hooks/handlers/pre-tool-use.d.ts.map +1 -0
- package/dist/src/hooks/handlers/pre-tool-use.js +219 -0
- package/dist/src/hooks/handlers/pre-tool-use.js.map +1 -0
- package/dist/src/hooks/handlers/session-end.d.ts +18 -0
- package/dist/src/hooks/handlers/session-end.d.ts.map +1 -0
- package/dist/src/hooks/handlers/session-end.js +42 -0
- package/dist/src/hooks/handlers/session-end.js.map +1 -0
- package/dist/src/hooks/handlers/session-start.d.ts +25 -0
- package/dist/src/hooks/handlers/session-start.d.ts.map +1 -0
- package/dist/src/hooks/handlers/session-start.js +61 -0
- package/dist/src/hooks/handlers/session-start.js.map +1 -0
- package/dist/src/hooks/handlers/stop.d.ts +21 -0
- package/dist/src/hooks/handlers/stop.d.ts.map +1 -0
- package/dist/src/hooks/handlers/stop.js +40 -0
- package/dist/src/hooks/handlers/stop.js.map +1 -0
- package/dist/src/hooks/handlers/subagent-start.d.ts +17 -0
- package/dist/src/hooks/handlers/subagent-start.d.ts.map +1 -0
- package/dist/src/hooks/handlers/subagent-start.js +48 -0
- package/dist/src/hooks/handlers/subagent-start.js.map +1 -0
- package/dist/src/hooks/handlers/user-prompt-submit.d.ts +12 -0
- package/dist/src/hooks/handlers/user-prompt-submit.d.ts.map +1 -0
- package/dist/src/hooks/handlers/user-prompt-submit.js +31 -0
- package/dist/src/hooks/handlers/user-prompt-submit.js.map +1 -0
- package/dist/src/hooks/index.d.ts +14 -0
- package/dist/src/hooks/index.d.ts.map +1 -0
- package/dist/src/hooks/index.js +13 -0
- package/dist/src/hooks/index.js.map +1 -0
- package/dist/src/hooks/post-tool-use.d.ts +12 -0
- package/dist/src/hooks/post-tool-use.d.ts.map +1 -0
- package/dist/src/hooks/post-tool-use.js +33 -0
- package/dist/src/hooks/post-tool-use.js.map +1 -0
- package/dist/src/hooks/pre-tool-use.d.ts +24 -0
- package/dist/src/hooks/pre-tool-use.d.ts.map +1 -0
- package/dist/src/hooks/pre-tool-use.js +117 -0
- package/dist/src/hooks/pre-tool-use.js.map +1 -0
- package/dist/src/hooks/session-store.d.ts +55 -0
- package/dist/src/hooks/session-store.d.ts.map +1 -0
- package/dist/src/hooks/session-store.js +69 -0
- package/dist/src/hooks/session-store.js.map +1 -0
- package/dist/src/hooks/types.d.ts +67 -0
- package/dist/src/hooks/types.d.ts.map +1 -0
- package/dist/src/hooks/types.js +28 -0
- package/dist/src/hooks/types.js.map +1 -0
- package/dist/src/index.d.ts +16 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +16 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/init/agent-connector.d.ts +43 -0
- package/dist/src/init/agent-connector.d.ts.map +1 -0
- package/dist/src/init/agent-connector.js +338 -0
- package/dist/src/init/agent-connector.js.map +1 -0
- package/dist/src/init/dna-bootstrap.d.ts +10 -0
- package/dist/src/init/dna-bootstrap.d.ts.map +1 -0
- package/dist/src/init/dna-bootstrap.js +32 -0
- package/dist/src/init/dna-bootstrap.js.map +1 -0
- package/dist/src/init/index.d.ts +29 -0
- package/dist/src/init/index.d.ts.map +1 -0
- package/dist/src/init/index.js +81 -0
- package/dist/src/init/index.js.map +1 -0
- package/dist/src/init/overview-generator.d.ts +5 -0
- package/dist/src/init/overview-generator.d.ts.map +1 -0
- package/dist/src/init/overview-generator.js +85 -0
- package/dist/src/init/overview-generator.js.map +1 -0
- package/dist/src/init/parsers/eslint-config.d.ts +10 -0
- package/dist/src/init/parsers/eslint-config.d.ts.map +1 -0
- package/dist/src/init/parsers/eslint-config.js +50 -0
- package/dist/src/init/parsers/eslint-config.js.map +1 -0
- package/dist/src/init/parsers/markdown-rules.d.ts +3 -0
- package/dist/src/init/parsers/markdown-rules.d.ts.map +1 -0
- package/dist/src/init/parsers/markdown-rules.js +90 -0
- package/dist/src/init/parsers/markdown-rules.js.map +1 -0
- package/dist/src/init/parsers/package-json.d.ts +17 -0
- package/dist/src/init/parsers/package-json.d.ts.map +1 -0
- package/dist/src/init/parsers/package-json.js +75 -0
- package/dist/src/init/parsers/package-json.js.map +1 -0
- package/dist/src/init/parsers/prettier-config.d.ts +16 -0
- package/dist/src/init/parsers/prettier-config.d.ts.map +1 -0
- package/dist/src/init/parsers/prettier-config.js +30 -0
- package/dist/src/init/parsers/prettier-config.js.map +1 -0
- package/dist/src/init/parsers/tsconfig.d.ts +32 -0
- package/dist/src/init/parsers/tsconfig.d.ts.map +1 -0
- package/dist/src/init/parsers/tsconfig.js +64 -0
- package/dist/src/init/parsers/tsconfig.js.map +1 -0
- package/dist/src/init/parsers/types.d.ts +27 -0
- package/dist/src/init/parsers/types.d.ts.map +1 -0
- package/dist/src/init/parsers/types.js +2 -0
- package/dist/src/init/parsers/types.js.map +1 -0
- package/dist/src/init/project-analyzer.d.ts +3 -0
- package/dist/src/init/project-analyzer.d.ts.map +1 -0
- package/dist/src/init/project-analyzer.js +102 -0
- package/dist/src/init/project-analyzer.js.map +1 -0
- package/dist/src/init/rule-importer.d.ts +3 -0
- package/dist/src/init/rule-importer.d.ts.map +1 -0
- package/dist/src/init/rule-importer.js +101 -0
- package/dist/src/init/rule-importer.js.map +1 -0
- package/dist/src/mcp/context.d.ts +43 -0
- package/dist/src/mcp/context.d.ts.map +1 -0
- package/dist/src/mcp/context.js +167 -0
- package/dist/src/mcp/context.js.map +1 -0
- package/dist/src/mcp/http-api.d.ts +10 -0
- package/dist/src/mcp/http-api.d.ts.map +1 -0
- package/dist/src/mcp/http-api.js +580 -0
- package/dist/src/mcp/http-api.js.map +1 -0
- package/dist/src/mcp/index.d.ts +8 -0
- package/dist/src/mcp/index.d.ts.map +1 -0
- package/dist/src/mcp/index.js +8 -0
- package/dist/src/mcp/index.js.map +1 -0
- package/dist/src/mcp/resources.d.ts +5 -0
- package/dist/src/mcp/resources.d.ts.map +1 -0
- package/dist/src/mcp/resources.js +78 -0
- package/dist/src/mcp/resources.js.map +1 -0
- package/dist/src/mcp/server.d.ts +6 -0
- package/dist/src/mcp/server.d.ts.map +1 -0
- package/dist/src/mcp/server.js +265 -0
- package/dist/src/mcp/server.js.map +1 -0
- package/dist/src/mcp/tool-response.d.ts +6 -0
- package/dist/src/mcp/tool-response.d.ts.map +1 -0
- package/dist/src/mcp/tool-response.js +19 -0
- package/dist/src/mcp/tool-response.js.map +1 -0
- package/dist/src/mcp/tools/architecture-tools.d.ts +15 -0
- package/dist/src/mcp/tools/architecture-tools.d.ts.map +1 -0
- package/dist/src/mcp/tools/architecture-tools.js +56 -0
- package/dist/src/mcp/tools/architecture-tools.js.map +1 -0
- package/dist/src/mcp/tools/dna-tools.d.ts +21 -0
- package/dist/src/mcp/tools/dna-tools.d.ts.map +1 -0
- package/dist/src/mcp/tools/dna-tools.js +15 -0
- package/dist/src/mcp/tools/dna-tools.js.map +1 -0
- package/dist/src/mcp/tools/graph-tools.d.ts +49 -0
- package/dist/src/mcp/tools/graph-tools.d.ts.map +1 -0
- package/dist/src/mcp/tools/graph-tools.js +45 -0
- package/dist/src/mcp/tools/graph-tools.js.map +1 -0
- package/dist/src/mcp/tools/health-tools.d.ts +5 -0
- package/dist/src/mcp/tools/health-tools.d.ts.map +1 -0
- package/dist/src/mcp/tools/health-tools.js +7 -0
- package/dist/src/mcp/tools/health-tools.js.map +1 -0
- package/dist/src/mcp/tools/impact-tools.d.ts +21 -0
- package/dist/src/mcp/tools/impact-tools.d.ts.map +1 -0
- package/dist/src/mcp/tools/impact-tools.js +23 -0
- package/dist/src/mcp/tools/impact-tools.js.map +1 -0
- package/dist/src/mcp/tools/intent-tools.d.ts +32 -0
- package/dist/src/mcp/tools/intent-tools.d.ts.map +1 -0
- package/dist/src/mcp/tools/intent-tools.js +77 -0
- package/dist/src/mcp/tools/intent-tools.js.map +1 -0
- package/dist/src/mcp/tools/project-tools.d.ts +53 -0
- package/dist/src/mcp/tools/project-tools.d.ts.map +1 -0
- package/dist/src/mcp/tools/project-tools.js +91 -0
- package/dist/src/mcp/tools/project-tools.js.map +1 -0
- package/dist/src/mcp/tools/rename-tool.d.ts +25 -0
- package/dist/src/mcp/tools/rename-tool.d.ts.map +1 -0
- package/dist/src/mcp/tools/rename-tool.js +106 -0
- package/dist/src/mcp/tools/rename-tool.js.map +1 -0
- package/dist/src/mcp/tools/trace-tools.d.ts +4 -0
- package/dist/src/mcp/tools/trace-tools.d.ts.map +1 -0
- package/dist/src/mcp/tools/trace-tools.js +268 -0
- package/dist/src/mcp/tools/trace-tools.js.map +1 -0
- package/dist/src/storage/db.d.ts +13 -0
- package/dist/src/storage/db.d.ts.map +1 -0
- package/dist/src/storage/db.js +230 -0
- package/dist/src/storage/db.js.map +1 -0
- package/dist/src/storage/repository.d.ts +54 -0
- package/dist/src/storage/repository.d.ts.map +1 -0
- package/dist/src/storage/repository.js +257 -0
- package/dist/src/storage/repository.js.map +1 -0
- package/dist/src/utils/config.d.ts +18 -0
- package/dist/src/utils/config.d.ts.map +1 -0
- package/dist/src/utils/config.js +93 -0
- package/dist/src/utils/config.js.map +1 -0
- package/dist/src/utils/files.d.ts +3 -0
- package/dist/src/utils/files.d.ts.map +1 -0
- package/dist/src/utils/files.js +52 -0
- package/dist/src/utils/files.js.map +1 -0
- package/dist/src/utils/strings.d.ts +2 -0
- package/dist/src/utils/strings.d.ts.map +1 -0
- package/dist/src/utils/strings.js +11 -0
- package/dist/src/utils/strings.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/hooks/post-tool-use.sh +37 -0
- package/hooks/pre-tool-use.sh +43 -0
- package/hooks/session-start.sh +67 -0
- package/package.json +103 -0
- package/skills/symbiote-init/SKILL.md +104 -0
|
@@ -0,0 +1,702 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { getGrammar } from '#core/languages.js';
|
|
5
|
+
const cjsRequire = createRequire(import.meta.url);
|
|
6
|
+
const Parser = cjsRequire('tree-sitter');
|
|
7
|
+
const TAINT_SOURCE_PATTERNS = ['req.body', 'req.params', 'req.query'];
|
|
8
|
+
const ENTRY_POINT_PATTERNS = [/^handle/, /^on[A-Z]/, /Controller$/, /Handler$/];
|
|
9
|
+
export async function runStage5(repo, rootDir, options) {
|
|
10
|
+
const start = Date.now();
|
|
11
|
+
const errors = [];
|
|
12
|
+
let filesProcessed = 0;
|
|
13
|
+
let edgesCreated = 0;
|
|
14
|
+
const allFiles = options?.force
|
|
15
|
+
? await repo.getAllFileNodes()
|
|
16
|
+
: await repo.getFilesByMaxDepth(5);
|
|
17
|
+
const files = options?.force ? allFiles : allFiles.filter((f) => f.depthLevel >= 4);
|
|
18
|
+
const targetSet = options?.targetFiles ? new Set(options.targetFiles) : null;
|
|
19
|
+
const eligibleFiles = files.filter((f) => {
|
|
20
|
+
if (targetSet && !targetSet.has(f.path))
|
|
21
|
+
return false;
|
|
22
|
+
if (!f.language)
|
|
23
|
+
return false;
|
|
24
|
+
return isJsTs(f.language);
|
|
25
|
+
});
|
|
26
|
+
const callGraph = await buildCallGraph(repo, eligibleFiles);
|
|
27
|
+
const processingOrder = reverseTopologicalSort(callGraph);
|
|
28
|
+
const processedFiles = new Set();
|
|
29
|
+
const ctx = {
|
|
30
|
+
flowsTo: [],
|
|
31
|
+
reads: [],
|
|
32
|
+
writes: [],
|
|
33
|
+
returns: [],
|
|
34
|
+
asyncCalls: [],
|
|
35
|
+
};
|
|
36
|
+
for (const symbolId of processingOrder) {
|
|
37
|
+
const filePath = extractFilePath(symbolId);
|
|
38
|
+
if (!filePath)
|
|
39
|
+
continue;
|
|
40
|
+
const file = eligibleFiles.find((f) => f.path === filePath);
|
|
41
|
+
if (!file)
|
|
42
|
+
continue;
|
|
43
|
+
if (!processedFiles.has(filePath)) {
|
|
44
|
+
processedFiles.add(filePath);
|
|
45
|
+
try {
|
|
46
|
+
await processFile(repo, rootDir, file, callGraph, ctx);
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
errors.push({
|
|
50
|
+
filePath: file.path,
|
|
51
|
+
stage: 5,
|
|
52
|
+
message: err instanceof Error ? err.message : String(err),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
for (const file of eligibleFiles) {
|
|
58
|
+
if (processedFiles.has(file.path))
|
|
59
|
+
continue;
|
|
60
|
+
try {
|
|
61
|
+
await processFile(repo, rootDir, file, callGraph, ctx);
|
|
62
|
+
processedFiles.add(file.path);
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
errors.push({
|
|
66
|
+
filePath: file.path,
|
|
67
|
+
stage: 5,
|
|
68
|
+
message: err instanceof Error ? err.message : String(err),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
propagateTaintLabels(ctx.flowsTo);
|
|
73
|
+
for (const file of eligibleFiles) {
|
|
74
|
+
if (!processedFiles.has(file.path))
|
|
75
|
+
continue;
|
|
76
|
+
try {
|
|
77
|
+
await repo.deleteFlowEdgesForFile(file.path);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// ignore cleanup errors
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (ctx.flowsTo.length > 0) {
|
|
84
|
+
await repo.insertFlowsToEdges(ctx.flowsTo);
|
|
85
|
+
edgesCreated += ctx.flowsTo.length;
|
|
86
|
+
}
|
|
87
|
+
if (ctx.reads.length > 0) {
|
|
88
|
+
await repo.insertReadsEdges(ctx.reads);
|
|
89
|
+
edgesCreated += ctx.reads.length;
|
|
90
|
+
}
|
|
91
|
+
if (ctx.writes.length > 0) {
|
|
92
|
+
await repo.insertWritesEdges(ctx.writes);
|
|
93
|
+
edgesCreated += ctx.writes.length;
|
|
94
|
+
}
|
|
95
|
+
if (ctx.returns.length > 0) {
|
|
96
|
+
await repo.insertReturnsEdges(ctx.returns);
|
|
97
|
+
edgesCreated += ctx.returns.length;
|
|
98
|
+
}
|
|
99
|
+
for (const ac of ctx.asyncCalls) {
|
|
100
|
+
await repo.updateCallEdgeAsync(ac.sourceId, ac.targetId, true);
|
|
101
|
+
}
|
|
102
|
+
for (const file of eligibleFiles) {
|
|
103
|
+
if (!processedFiles.has(file.path))
|
|
104
|
+
continue;
|
|
105
|
+
const functions = await repo.getFunctionsByFile(file.path);
|
|
106
|
+
await scoreEntryPoints(repo, functions);
|
|
107
|
+
await repo.upsertFileNode({ ...file, depthLevel: 5 });
|
|
108
|
+
filesProcessed++;
|
|
109
|
+
await repo.deleteFlowsForFile(file.path);
|
|
110
|
+
const entryPoints = functions.filter((fn) => fn.isEntryPoint);
|
|
111
|
+
if (entryPoints.length > 0) {
|
|
112
|
+
const flows = await discoverFlows(repo, entryPoints, callGraph);
|
|
113
|
+
if (flows.length > 0) {
|
|
114
|
+
await repo.insertFlows(flows);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
stage: 5,
|
|
120
|
+
filesProcessed,
|
|
121
|
+
nodesCreated: 0,
|
|
122
|
+
edgesCreated,
|
|
123
|
+
durationMs: Date.now() - start,
|
|
124
|
+
errors,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function isJsTs(language) {
|
|
128
|
+
return language === 'javascript' || language === 'typescript' || language === 'tsx';
|
|
129
|
+
}
|
|
130
|
+
function extractFilePath(symbolId) {
|
|
131
|
+
const parts = symbolId.split(':');
|
|
132
|
+
if (parts.length < 3)
|
|
133
|
+
return null;
|
|
134
|
+
return parts[1];
|
|
135
|
+
}
|
|
136
|
+
async function buildCallGraph(repo, files) {
|
|
137
|
+
const graph = new Map();
|
|
138
|
+
for (const file of files) {
|
|
139
|
+
const functions = await repo.getFunctionsByFile(file.path);
|
|
140
|
+
const methods = await repo.getMethodsByFile(file.path);
|
|
141
|
+
const allCallables = [...functions, ...methods];
|
|
142
|
+
for (const callable of allCallables) {
|
|
143
|
+
const callsFrom = await repo.getCallsFrom(callable.id);
|
|
144
|
+
const callsTo = await repo.getCallsTo(callable.id);
|
|
145
|
+
graph.set(callable.id, { callsFrom, callsTo });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return graph;
|
|
149
|
+
}
|
|
150
|
+
function reverseTopologicalSort(graph) {
|
|
151
|
+
const inDegree = new Map();
|
|
152
|
+
const adjacency = new Map();
|
|
153
|
+
for (const [id] of graph) {
|
|
154
|
+
if (!inDegree.has(id))
|
|
155
|
+
inDegree.set(id, 0);
|
|
156
|
+
if (!adjacency.has(id))
|
|
157
|
+
adjacency.set(id, []);
|
|
158
|
+
}
|
|
159
|
+
for (const [id, entry] of graph) {
|
|
160
|
+
for (const call of entry.callsFrom) {
|
|
161
|
+
if (graph.has(call.targetId)) {
|
|
162
|
+
adjacency.get(id).push(call.targetId);
|
|
163
|
+
inDegree.set(call.targetId, (inDegree.get(call.targetId) ?? 0) + 1);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const queue = [];
|
|
168
|
+
for (const [id, deg] of inDegree) {
|
|
169
|
+
if (deg === 0)
|
|
170
|
+
queue.push(id);
|
|
171
|
+
}
|
|
172
|
+
const sorted = [];
|
|
173
|
+
while (queue.length > 0) {
|
|
174
|
+
const node = queue.shift();
|
|
175
|
+
sorted.push(node);
|
|
176
|
+
for (const neighbor of adjacency.get(node) ?? []) {
|
|
177
|
+
const newDeg = (inDegree.get(neighbor) ?? 1) - 1;
|
|
178
|
+
inDegree.set(neighbor, newDeg);
|
|
179
|
+
if (newDeg === 0)
|
|
180
|
+
queue.push(neighbor);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
for (const [id] of graph) {
|
|
184
|
+
if (!sorted.includes(id))
|
|
185
|
+
sorted.push(id);
|
|
186
|
+
}
|
|
187
|
+
return sorted.reverse();
|
|
188
|
+
}
|
|
189
|
+
async function processFile(repo, rootDir, file, callGraph, ctx) {
|
|
190
|
+
const absPath = resolve(rootDir, file.path);
|
|
191
|
+
const content = readFileSync(absPath, 'utf-8');
|
|
192
|
+
const grammar = getGrammar(file.language);
|
|
193
|
+
if (!grammar)
|
|
194
|
+
return;
|
|
195
|
+
const parser = new Parser();
|
|
196
|
+
parser.setLanguage(grammar);
|
|
197
|
+
const tree = parser.parse(content);
|
|
198
|
+
const root = tree.rootNode;
|
|
199
|
+
const functions = await repo.getFunctionsByFile(file.path);
|
|
200
|
+
const methods = await repo.getMethodsByFile(file.path);
|
|
201
|
+
for (const fn of functions) {
|
|
202
|
+
const fnNode = findFunctionNode(root, fn.name, fn.lineStart);
|
|
203
|
+
if (!fnNode)
|
|
204
|
+
continue;
|
|
205
|
+
analyzeCallable(fn.id, fnNode, file.path, callGraph, ctx);
|
|
206
|
+
}
|
|
207
|
+
for (const method of methods) {
|
|
208
|
+
const methodNode = findMethodNode(root, method.name, method.className, method.lineStart);
|
|
209
|
+
if (!methodNode)
|
|
210
|
+
continue;
|
|
211
|
+
analyzeCallable(method.id, methodNode, file.path, callGraph, ctx);
|
|
212
|
+
}
|
|
213
|
+
connectCrossCallFlows(file.path, functions, methods, callGraph, ctx, root);
|
|
214
|
+
}
|
|
215
|
+
function findFunctionNode(root, name, lineStart) {
|
|
216
|
+
const cursor = root.walk();
|
|
217
|
+
let done = false;
|
|
218
|
+
while (!done) {
|
|
219
|
+
const node = cursor.currentNode;
|
|
220
|
+
if ((node.type === 'function_declaration' || node.type === 'function') &&
|
|
221
|
+
node.startPosition.row + 1 === lineStart) {
|
|
222
|
+
const nameNode = node.childForFieldName('name');
|
|
223
|
+
if (nameNode?.text === name)
|
|
224
|
+
return node;
|
|
225
|
+
}
|
|
226
|
+
if (node.type === 'lexical_declaration' && node.startPosition.row + 1 === lineStart) {
|
|
227
|
+
for (const child of node.children) {
|
|
228
|
+
if (child.type === 'variable_declarator') {
|
|
229
|
+
const nameNode = child.childForFieldName('name');
|
|
230
|
+
if (nameNode?.text === name) {
|
|
231
|
+
const value = child.childForFieldName('value');
|
|
232
|
+
if (value?.type === 'arrow_function' || value?.type === 'function') {
|
|
233
|
+
return value;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (cursor.gotoFirstChild())
|
|
240
|
+
continue;
|
|
241
|
+
if (cursor.gotoNextSibling())
|
|
242
|
+
continue;
|
|
243
|
+
while (true) {
|
|
244
|
+
if (!cursor.gotoParent()) {
|
|
245
|
+
done = true;
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
if (cursor.gotoNextSibling())
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
function findMethodNode(root, name, className, lineStart) {
|
|
255
|
+
const cursor = root.walk();
|
|
256
|
+
let done = false;
|
|
257
|
+
while (!done) {
|
|
258
|
+
const node = cursor.currentNode;
|
|
259
|
+
if (node.type === 'method_definition' && node.startPosition.row + 1 === lineStart) {
|
|
260
|
+
const nameNode = node.childForFieldName('name');
|
|
261
|
+
if (nameNode?.text === name) {
|
|
262
|
+
const classNode = findParentClass(node);
|
|
263
|
+
if (classNode) {
|
|
264
|
+
const classNameNode = classNode.childForFieldName('name');
|
|
265
|
+
if (classNameNode?.text === className)
|
|
266
|
+
return node;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (cursor.gotoFirstChild())
|
|
271
|
+
continue;
|
|
272
|
+
if (cursor.gotoNextSibling())
|
|
273
|
+
continue;
|
|
274
|
+
while (true) {
|
|
275
|
+
if (!cursor.gotoParent()) {
|
|
276
|
+
done = true;
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
if (cursor.gotoNextSibling())
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return null;
|
|
284
|
+
}
|
|
285
|
+
function findParentClass(node) {
|
|
286
|
+
let parent = node.parent;
|
|
287
|
+
while (parent) {
|
|
288
|
+
if (parent.type === 'class_declaration' || parent.type === 'class')
|
|
289
|
+
return parent;
|
|
290
|
+
parent = parent.parent;
|
|
291
|
+
}
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
function analyzeCallable(symbolId, node, filePath, callGraph, ctx) {
|
|
295
|
+
extractParameters(symbolId, node, filePath, ctx);
|
|
296
|
+
extractReturnStatements(symbolId, node, filePath, ctx);
|
|
297
|
+
extractFieldAccess(symbolId, node, filePath, ctx);
|
|
298
|
+
detectAsyncCalls(symbolId, node, callGraph, ctx);
|
|
299
|
+
detectErrorPaths(symbolId, node, filePath, ctx);
|
|
300
|
+
markTaintOnParameters(symbolId, node, ctx);
|
|
301
|
+
}
|
|
302
|
+
function extractParameters(symbolId, node, filePath, ctx) {
|
|
303
|
+
const params = node.childForFieldName('parameters');
|
|
304
|
+
if (!params)
|
|
305
|
+
return;
|
|
306
|
+
let paramIndex = 0;
|
|
307
|
+
for (const param of params.children) {
|
|
308
|
+
if (param.type === 'required_parameter' ||
|
|
309
|
+
param.type === 'optional_parameter' ||
|
|
310
|
+
param.type === 'identifier') {
|
|
311
|
+
const nameNode = param.type === 'identifier'
|
|
312
|
+
? param
|
|
313
|
+
: (param.childForFieldName('pattern') ??
|
|
314
|
+
param.children.find((c) => c.type === 'identifier'));
|
|
315
|
+
if (!nameNode)
|
|
316
|
+
continue;
|
|
317
|
+
ctx.flowsTo.push({
|
|
318
|
+
sourceId: symbolId,
|
|
319
|
+
targetId: `param:${filePath}:${symbolId}:${nameNode.text}`,
|
|
320
|
+
parameterIndex: paramIndex,
|
|
321
|
+
transform: 'passthrough',
|
|
322
|
+
taintLabel: null,
|
|
323
|
+
confidence: 0.9,
|
|
324
|
+
stage: 5,
|
|
325
|
+
reason: 'parameter',
|
|
326
|
+
});
|
|
327
|
+
paramIndex++;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function extractReturnStatements(symbolId, node, _filePath, ctx) {
|
|
332
|
+
const returnNodes = collectNodes(node, 'return_statement');
|
|
333
|
+
for (const ret of returnNodes) {
|
|
334
|
+
if (isInsideNestedFunction(ret, node))
|
|
335
|
+
continue;
|
|
336
|
+
const expr = ret.children.length > 1 ? ret.children[1] : null;
|
|
337
|
+
const returnType = expr ? expr.type : null;
|
|
338
|
+
ctx.returns.push({
|
|
339
|
+
sourceId: symbolId,
|
|
340
|
+
targetId: symbolId,
|
|
341
|
+
line: ret.startPosition.row + 1,
|
|
342
|
+
returnType,
|
|
343
|
+
confidence: 0.9,
|
|
344
|
+
stage: 5,
|
|
345
|
+
reason: 'return',
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
function extractFieldAccess(symbolId, node, filePath, ctx) {
|
|
350
|
+
const memberExprs = collectNodes(node, 'member_expression');
|
|
351
|
+
for (const mem of memberExprs) {
|
|
352
|
+
if (isInsideNestedFunction(mem, node))
|
|
353
|
+
continue;
|
|
354
|
+
const obj = mem.childForFieldName('object');
|
|
355
|
+
const prop = mem.childForFieldName('property');
|
|
356
|
+
if (!obj || !prop)
|
|
357
|
+
continue;
|
|
358
|
+
const field = prop.text;
|
|
359
|
+
const parent = mem.parent;
|
|
360
|
+
if (parent?.type === 'assignment_expression' && parent.childForFieldName('left') === mem) {
|
|
361
|
+
ctx.writes.push({
|
|
362
|
+
sourceId: symbolId,
|
|
363
|
+
targetId: `field:${filePath}:${obj.text}.${field}`,
|
|
364
|
+
line: mem.startPosition.row + 1,
|
|
365
|
+
field,
|
|
366
|
+
confidence: 0.85,
|
|
367
|
+
stage: 5,
|
|
368
|
+
reason: 'field_write',
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
else if (parent?.type === 'member_expression' && isMutatingCall(parent)) {
|
|
372
|
+
const outerProp = parent.childForFieldName('property');
|
|
373
|
+
if (outerProp) {
|
|
374
|
+
ctx.writes.push({
|
|
375
|
+
sourceId: symbolId,
|
|
376
|
+
targetId: `field:${filePath}:${obj.text}.${field}`,
|
|
377
|
+
line: mem.startPosition.row + 1,
|
|
378
|
+
field,
|
|
379
|
+
confidence: 0.8,
|
|
380
|
+
stage: 5,
|
|
381
|
+
reason: `field_write_via_${outerProp.text}`,
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
else if (parent?.type !== 'call_expression' ||
|
|
386
|
+
parent.childForFieldName('function') !== mem) {
|
|
387
|
+
ctx.reads.push({
|
|
388
|
+
sourceId: symbolId,
|
|
389
|
+
targetId: `field:${filePath}:${obj.text}.${field}`,
|
|
390
|
+
line: mem.startPosition.row + 1,
|
|
391
|
+
field,
|
|
392
|
+
confidence: 0.85,
|
|
393
|
+
stage: 5,
|
|
394
|
+
reason: isTaintSource(mem) ? 'taint_source' : 'field_read',
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
function isTaintSource(node) {
|
|
400
|
+
return TAINT_SOURCE_PATTERNS.some((pattern) => node.text.startsWith(pattern));
|
|
401
|
+
}
|
|
402
|
+
const MUTATING_METHODS = new Set([
|
|
403
|
+
'set',
|
|
404
|
+
'push',
|
|
405
|
+
'delete',
|
|
406
|
+
'splice',
|
|
407
|
+
'pop',
|
|
408
|
+
'shift',
|
|
409
|
+
'unshift',
|
|
410
|
+
'add',
|
|
411
|
+
'clear',
|
|
412
|
+
]);
|
|
413
|
+
function isMutatingCall(memberExpr) {
|
|
414
|
+
const prop = memberExpr.childForFieldName('property');
|
|
415
|
+
if (!prop)
|
|
416
|
+
return false;
|
|
417
|
+
const parent = memberExpr.parent;
|
|
418
|
+
if (parent?.type !== 'call_expression')
|
|
419
|
+
return false;
|
|
420
|
+
return MUTATING_METHODS.has(prop.text);
|
|
421
|
+
}
|
|
422
|
+
function markTaintOnParameters(symbolId, node, ctx) {
|
|
423
|
+
const memberExprs = collectNodes(node, 'member_expression');
|
|
424
|
+
const hasTaintAccess = memberExprs.some((mem) => {
|
|
425
|
+
if (isInsideNestedFunction(mem, node))
|
|
426
|
+
return false;
|
|
427
|
+
return isTaintSource(mem);
|
|
428
|
+
});
|
|
429
|
+
if (!hasTaintAccess)
|
|
430
|
+
return;
|
|
431
|
+
for (const flow of ctx.flowsTo) {
|
|
432
|
+
if (flow.sourceId === symbolId && flow.reason === 'parameter' && !flow.taintLabel) {
|
|
433
|
+
flow.taintLabel = 'user_input';
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
function detectAsyncCalls(symbolId, node, callGraph, ctx) {
|
|
438
|
+
const awaitExprs = collectNodes(node, 'await_expression');
|
|
439
|
+
const entry = callGraph.get(symbolId);
|
|
440
|
+
if (!entry)
|
|
441
|
+
return;
|
|
442
|
+
for (const awaitExpr of awaitExprs) {
|
|
443
|
+
if (isInsideNestedFunction(awaitExpr, node))
|
|
444
|
+
continue;
|
|
445
|
+
const callExpr = awaitExpr.children.find((c) => c.type === 'call_expression');
|
|
446
|
+
if (!callExpr)
|
|
447
|
+
continue;
|
|
448
|
+
const fnNode = callExpr.childForFieldName('function');
|
|
449
|
+
if (!fnNode)
|
|
450
|
+
continue;
|
|
451
|
+
const callName = extractCallName(fnNode);
|
|
452
|
+
if (!callName)
|
|
453
|
+
continue;
|
|
454
|
+
for (const call of entry.callsFrom) {
|
|
455
|
+
if (call.targetId.includes(callName)) {
|
|
456
|
+
ctx.asyncCalls.push({ sourceId: symbolId, targetId: call.targetId });
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function extractCallName(node) {
|
|
462
|
+
if (node.type === 'identifier')
|
|
463
|
+
return node.text;
|
|
464
|
+
if (node.type === 'member_expression') {
|
|
465
|
+
const prop = node.childForFieldName('property');
|
|
466
|
+
return prop?.text ?? null;
|
|
467
|
+
}
|
|
468
|
+
return null;
|
|
469
|
+
}
|
|
470
|
+
function detectErrorPaths(symbolId, node, filePath, ctx) {
|
|
471
|
+
const tryCatches = collectNodes(node, 'try_statement');
|
|
472
|
+
for (const tc of tryCatches) {
|
|
473
|
+
if (isInsideNestedFunction(tc, node))
|
|
474
|
+
continue;
|
|
475
|
+
ctx.flowsTo.push({
|
|
476
|
+
sourceId: symbolId,
|
|
477
|
+
targetId: `error:${filePath}:${symbolId}:try`,
|
|
478
|
+
parameterIndex: null,
|
|
479
|
+
transform: 'passthrough',
|
|
480
|
+
taintLabel: null,
|
|
481
|
+
confidence: 0.8,
|
|
482
|
+
stage: 5,
|
|
483
|
+
reason: 'try_catch',
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
const throwStmts = collectNodes(node, 'throw_statement');
|
|
487
|
+
for (const ts of throwStmts) {
|
|
488
|
+
if (isInsideNestedFunction(ts, node))
|
|
489
|
+
continue;
|
|
490
|
+
ctx.flowsTo.push({
|
|
491
|
+
sourceId: symbolId,
|
|
492
|
+
targetId: `error:${filePath}:${symbolId}:throw`,
|
|
493
|
+
parameterIndex: null,
|
|
494
|
+
transform: 'passthrough',
|
|
495
|
+
taintLabel: null,
|
|
496
|
+
confidence: 0.8,
|
|
497
|
+
stage: 5,
|
|
498
|
+
reason: 'throw',
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
function connectCrossCallFlows(_filePath, functions, methods, callGraph, ctx, root) {
|
|
503
|
+
const allCallables = [...functions, ...methods];
|
|
504
|
+
for (const callable of allCallables) {
|
|
505
|
+
const entry = callGraph.get(callable.id);
|
|
506
|
+
if (!entry)
|
|
507
|
+
continue;
|
|
508
|
+
for (const call of entry.callsFrom) {
|
|
509
|
+
const targetEntry = callGraph.get(call.targetId);
|
|
510
|
+
if (!targetEntry)
|
|
511
|
+
continue;
|
|
512
|
+
const callExprNode = findCallExpressionAtLine(root, call.line);
|
|
513
|
+
const args = callExprNode ? extractCallArguments(callExprNode) : [];
|
|
514
|
+
for (let i = 0; i < args.length; i++) {
|
|
515
|
+
const taintLabel = isTaintSourceText(args[i]) ? 'user_input' : null;
|
|
516
|
+
ctx.flowsTo.push({
|
|
517
|
+
sourceId: callable.id,
|
|
518
|
+
targetId: call.targetId,
|
|
519
|
+
parameterIndex: i,
|
|
520
|
+
transform: 'passthrough',
|
|
521
|
+
taintLabel,
|
|
522
|
+
confidence: 0.85,
|
|
523
|
+
stage: 5,
|
|
524
|
+
reason: 'call_arg',
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
ctx.returns.push({
|
|
528
|
+
sourceId: call.targetId,
|
|
529
|
+
targetId: callable.id,
|
|
530
|
+
line: call.line,
|
|
531
|
+
returnType: null,
|
|
532
|
+
confidence: 0.85,
|
|
533
|
+
stage: 5,
|
|
534
|
+
reason: 'call_return',
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
function findCallExpressionAtLine(root, line) {
|
|
540
|
+
if (line === null)
|
|
541
|
+
return null;
|
|
542
|
+
const cursor = root.walk();
|
|
543
|
+
let done = false;
|
|
544
|
+
while (!done) {
|
|
545
|
+
const node = cursor.currentNode;
|
|
546
|
+
if (node.type === 'call_expression' && node.startPosition.row + 1 === line) {
|
|
547
|
+
return node;
|
|
548
|
+
}
|
|
549
|
+
if (cursor.gotoFirstChild())
|
|
550
|
+
continue;
|
|
551
|
+
if (cursor.gotoNextSibling())
|
|
552
|
+
continue;
|
|
553
|
+
while (true) {
|
|
554
|
+
if (!cursor.gotoParent()) {
|
|
555
|
+
done = true;
|
|
556
|
+
break;
|
|
557
|
+
}
|
|
558
|
+
if (cursor.gotoNextSibling())
|
|
559
|
+
break;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
return null;
|
|
563
|
+
}
|
|
564
|
+
function extractCallArguments(callExpr) {
|
|
565
|
+
const args = callExpr.childForFieldName('arguments');
|
|
566
|
+
if (!args)
|
|
567
|
+
return [];
|
|
568
|
+
const result = [];
|
|
569
|
+
for (const child of args.children) {
|
|
570
|
+
if (child.type !== '(' && child.type !== ')' && child.type !== ',') {
|
|
571
|
+
result.push(child.text);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
return result;
|
|
575
|
+
}
|
|
576
|
+
function isTaintSourceText(text) {
|
|
577
|
+
return TAINT_SOURCE_PATTERNS.some((p) => text.includes(p));
|
|
578
|
+
}
|
|
579
|
+
function propagateTaintLabels(flows) {
|
|
580
|
+
const taintedSources = new Set();
|
|
581
|
+
for (const flow of flows) {
|
|
582
|
+
if (flow.taintLabel) {
|
|
583
|
+
taintedSources.add(flow.sourceId);
|
|
584
|
+
taintedSources.add(flow.targetId);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
if (taintedSources.size === 0)
|
|
588
|
+
return;
|
|
589
|
+
let changed = true;
|
|
590
|
+
let iterations = 0;
|
|
591
|
+
const maxIterations = 10;
|
|
592
|
+
while (changed && iterations < maxIterations) {
|
|
593
|
+
changed = false;
|
|
594
|
+
iterations++;
|
|
595
|
+
for (const flow of flows) {
|
|
596
|
+
if (!flow.taintLabel && taintedSources.has(flow.sourceId)) {
|
|
597
|
+
flow.taintLabel = 'user_input';
|
|
598
|
+
taintedSources.add(flow.targetId);
|
|
599
|
+
changed = true;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
async function scoreEntryPoints(repo, functions) {
|
|
605
|
+
for (const fn of functions) {
|
|
606
|
+
let score = 0;
|
|
607
|
+
if (ENTRY_POINT_PATTERNS.some((p) => p.test(fn.name))) {
|
|
608
|
+
score += 0.3;
|
|
609
|
+
}
|
|
610
|
+
if (fn.isExported) {
|
|
611
|
+
score += 0.1;
|
|
612
|
+
}
|
|
613
|
+
const callsFrom = await repo.getCallsFrom(fn.id);
|
|
614
|
+
const callsTo = await repo.getCallsTo(fn.id);
|
|
615
|
+
if (callsFrom.length > 0 && callsTo.length <= 1) {
|
|
616
|
+
score += 0.2;
|
|
617
|
+
}
|
|
618
|
+
if (fn.isAsync) {
|
|
619
|
+
score += 0.1;
|
|
620
|
+
}
|
|
621
|
+
if (score > 0) {
|
|
622
|
+
await repo.updateEntryPointScore(fn.id, score, score > 0.5);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
function collectNodes(root, type) {
|
|
627
|
+
const result = [];
|
|
628
|
+
const cursor = root.walk();
|
|
629
|
+
let done = false;
|
|
630
|
+
while (!done) {
|
|
631
|
+
const node = cursor.currentNode;
|
|
632
|
+
if (node.type === type)
|
|
633
|
+
result.push(node);
|
|
634
|
+
if (cursor.gotoFirstChild())
|
|
635
|
+
continue;
|
|
636
|
+
if (cursor.gotoNextSibling())
|
|
637
|
+
continue;
|
|
638
|
+
while (true) {
|
|
639
|
+
if (!cursor.gotoParent()) {
|
|
640
|
+
done = true;
|
|
641
|
+
break;
|
|
642
|
+
}
|
|
643
|
+
if (cursor.gotoNextSibling())
|
|
644
|
+
break;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
return result;
|
|
648
|
+
}
|
|
649
|
+
function isInsideNestedFunction(node, container) {
|
|
650
|
+
let parent = node.parent;
|
|
651
|
+
while (parent && parent !== container) {
|
|
652
|
+
if (parent.type === 'function_declaration' ||
|
|
653
|
+
parent.type === 'function' ||
|
|
654
|
+
parent.type === 'arrow_function' ||
|
|
655
|
+
parent.type === 'method_definition') {
|
|
656
|
+
return true;
|
|
657
|
+
}
|
|
658
|
+
parent = parent.parent;
|
|
659
|
+
}
|
|
660
|
+
return false;
|
|
661
|
+
}
|
|
662
|
+
async function discoverFlows(repo, entryPoints, callGraph) {
|
|
663
|
+
const flows = [];
|
|
664
|
+
for (const ep of entryPoints) {
|
|
665
|
+
const visited = new Set();
|
|
666
|
+
const queue = [{ id: ep.id, depth: 0 }];
|
|
667
|
+
let hasAsync = false;
|
|
668
|
+
let hasErrorPath = false;
|
|
669
|
+
while (queue.length > 0) {
|
|
670
|
+
const { id, depth } = queue.shift();
|
|
671
|
+
if (visited.has(id) || depth > 10)
|
|
672
|
+
continue;
|
|
673
|
+
visited.add(id);
|
|
674
|
+
const entry = callGraph.get(id);
|
|
675
|
+
if (!entry)
|
|
676
|
+
continue;
|
|
677
|
+
for (const call of entry.callsFrom) {
|
|
678
|
+
if (call.isAsync)
|
|
679
|
+
hasAsync = true;
|
|
680
|
+
if (!visited.has(call.targetId) && depth + 1 <= 10) {
|
|
681
|
+
queue.push({ id: call.targetId, depth: depth + 1 });
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
const flowsTo = await repo.getFlowsFrom(id);
|
|
685
|
+
for (const flow of flowsTo) {
|
|
686
|
+
if (flow.reason === 'try_catch' || flow.reason === 'throw') {
|
|
687
|
+
hasErrorPath = true;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
flows.push({
|
|
692
|
+
id: `flow:${ep.id}`,
|
|
693
|
+
name: ep.name,
|
|
694
|
+
entryPointId: ep.id,
|
|
695
|
+
nodeIds: [...visited],
|
|
696
|
+
hasAsync,
|
|
697
|
+
hasErrorPath,
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
return flows;
|
|
701
|
+
}
|
|
702
|
+
//# sourceMappingURL=stage-5-flow.js.map
|