@timmeck/brain 1.0.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/BRAIN_PLAN.md +3324 -0
- package/LICENSE +21 -0
- package/README.md +188 -0
- package/dist/brain.d.ts +11 -0
- package/dist/brain.js +166 -0
- package/dist/brain.js.map +1 -0
- package/dist/cli/commands/dashboard.d.ts +2 -0
- package/dist/cli/commands/dashboard.js +457 -0
- package/dist/cli/commands/dashboard.js.map +1 -0
- package/dist/cli/commands/export.d.ts +2 -0
- package/dist/cli/commands/export.js +25 -0
- package/dist/cli/commands/export.js.map +1 -0
- package/dist/cli/commands/import.d.ts +2 -0
- package/dist/cli/commands/import.js +173 -0
- package/dist/cli/commands/import.js.map +1 -0
- package/dist/cli/commands/insights.d.ts +2 -0
- package/dist/cli/commands/insights.js +32 -0
- package/dist/cli/commands/insights.js.map +1 -0
- package/dist/cli/commands/modules.d.ts +2 -0
- package/dist/cli/commands/modules.js +29 -0
- package/dist/cli/commands/modules.js.map +1 -0
- package/dist/cli/commands/network.d.ts +2 -0
- package/dist/cli/commands/network.js +56 -0
- package/dist/cli/commands/network.js.map +1 -0
- package/dist/cli/commands/query.d.ts +2 -0
- package/dist/cli/commands/query.js +40 -0
- package/dist/cli/commands/query.js.map +1 -0
- package/dist/cli/commands/start.d.ts +2 -0
- package/dist/cli/commands/start.js +56 -0
- package/dist/cli/commands/start.js.map +1 -0
- package/dist/cli/commands/status.d.ts +2 -0
- package/dist/cli/commands/status.js +60 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/cli/commands/stop.d.ts +2 -0
- package/dist/cli/commands/stop.js +34 -0
- package/dist/cli/commands/stop.js.map +1 -0
- package/dist/cli/ipc-helper.d.ts +2 -0
- package/dist/cli/ipc-helper.js +25 -0
- package/dist/cli/ipc-helper.js.map +1 -0
- package/dist/code/analyzer.d.ts +12 -0
- package/dist/code/analyzer.js +58 -0
- package/dist/code/analyzer.js.map +1 -0
- package/dist/code/fingerprint.d.ts +2 -0
- package/dist/code/fingerprint.js +84 -0
- package/dist/code/fingerprint.js.map +1 -0
- package/dist/code/matcher.d.ts +9 -0
- package/dist/code/matcher.js +37 -0
- package/dist/code/matcher.js.map +1 -0
- package/dist/code/parsers/generic.d.ts +7 -0
- package/dist/code/parsers/generic.js +22 -0
- package/dist/code/parsers/generic.js.map +1 -0
- package/dist/code/parsers/python.d.ts +7 -0
- package/dist/code/parsers/python.js +45 -0
- package/dist/code/parsers/python.js.map +1 -0
- package/dist/code/parsers/typescript.d.ts +7 -0
- package/dist/code/parsers/typescript.js +58 -0
- package/dist/code/parsers/typescript.js.map +1 -0
- package/dist/code/registry.d.ts +22 -0
- package/dist/code/registry.js +31 -0
- package/dist/code/registry.js.map +1 -0
- package/dist/code/scorer.d.ts +15 -0
- package/dist/code/scorer.js +103 -0
- package/dist/code/scorer.js.map +1 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +110 -0
- package/dist/config.js.map +1 -0
- package/dist/db/connection.d.ts +2 -0
- package/dist/db/connection.js +19 -0
- package/dist/db/connection.js.map +1 -0
- package/dist/db/migrations/001_core_schema.d.ts +2 -0
- package/dist/db/migrations/001_core_schema.js +119 -0
- package/dist/db/migrations/001_core_schema.js.map +1 -0
- package/dist/db/migrations/002_learning_schema.d.ts +2 -0
- package/dist/db/migrations/002_learning_schema.js +37 -0
- package/dist/db/migrations/002_learning_schema.js.map +1 -0
- package/dist/db/migrations/003_code_schema.d.ts +2 -0
- package/dist/db/migrations/003_code_schema.js +52 -0
- package/dist/db/migrations/003_code_schema.js.map +1 -0
- package/dist/db/migrations/004_synapses_schema.d.ts +2 -0
- package/dist/db/migrations/004_synapses_schema.js +56 -0
- package/dist/db/migrations/004_synapses_schema.js.map +1 -0
- package/dist/db/migrations/005_fts_indexes.d.ts +2 -0
- package/dist/db/migrations/005_fts_indexes.js +77 -0
- package/dist/db/migrations/005_fts_indexes.js.map +1 -0
- package/dist/db/migrations/006_synapses_phase3.d.ts +2 -0
- package/dist/db/migrations/006_synapses_phase3.js +14 -0
- package/dist/db/migrations/006_synapses_phase3.js.map +1 -0
- package/dist/db/migrations/index.d.ts +2 -0
- package/dist/db/migrations/index.js +49 -0
- package/dist/db/migrations/index.js.map +1 -0
- package/dist/db/repositories/antipattern.repository.d.ts +26 -0
- package/dist/db/repositories/antipattern.repository.js +44 -0
- package/dist/db/repositories/antipattern.repository.js.map +1 -0
- package/dist/db/repositories/code-module.repository.d.ts +19 -0
- package/dist/db/repositories/code-module.repository.js +64 -0
- package/dist/db/repositories/code-module.repository.js.map +1 -0
- package/dist/db/repositories/error.repository.d.ts +20 -0
- package/dist/db/repositories/error.repository.js +134 -0
- package/dist/db/repositories/error.repository.js.map +1 -0
- package/dist/db/repositories/insight.repository.d.ts +18 -0
- package/dist/db/repositories/insight.repository.js +57 -0
- package/dist/db/repositories/insight.repository.js.map +1 -0
- package/dist/db/repositories/notification.repository.d.ts +24 -0
- package/dist/db/repositories/notification.repository.js +40 -0
- package/dist/db/repositories/notification.repository.js.map +1 -0
- package/dist/db/repositories/project.repository.d.ts +25 -0
- package/dist/db/repositories/project.repository.js +72 -0
- package/dist/db/repositories/project.repository.js.map +1 -0
- package/dist/db/repositories/rule.repository.d.ts +31 -0
- package/dist/db/repositories/rule.repository.js +81 -0
- package/dist/db/repositories/rule.repository.js.map +1 -0
- package/dist/db/repositories/solution.repository.d.ts +27 -0
- package/dist/db/repositories/solution.repository.js +132 -0
- package/dist/db/repositories/solution.repository.js.map +1 -0
- package/dist/db/repositories/synapse.repository.d.ts +25 -0
- package/dist/db/repositories/synapse.repository.js +115 -0
- package/dist/db/repositories/synapse.repository.js.map +1 -0
- package/dist/db/repositories/terminal.repository.d.ts +27 -0
- package/dist/db/repositories/terminal.repository.js +78 -0
- package/dist/db/repositories/terminal.repository.js.map +1 -0
- package/dist/hooks/post-tool-use.d.ts +2 -0
- package/dist/hooks/post-tool-use.js +77 -0
- package/dist/hooks/post-tool-use.js.map +1 -0
- package/dist/hooks/post-write.d.ts +2 -0
- package/dist/hooks/post-write.js +102 -0
- package/dist/hooks/post-write.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/ipc/client.d.ts +16 -0
- package/dist/ipc/client.js +101 -0
- package/dist/ipc/client.js.map +1 -0
- package/dist/ipc/protocol.d.ts +8 -0
- package/dist/ipc/protocol.js +29 -0
- package/dist/ipc/protocol.js.map +1 -0
- package/dist/ipc/router.d.ts +28 -0
- package/dist/ipc/router.js +70 -0
- package/dist/ipc/router.js.map +1 -0
- package/dist/ipc/server.d.ts +14 -0
- package/dist/ipc/server.js +98 -0
- package/dist/ipc/server.js.map +1 -0
- package/dist/learning/confidence-scorer.d.ts +13 -0
- package/dist/learning/confidence-scorer.js +35 -0
- package/dist/learning/confidence-scorer.js.map +1 -0
- package/dist/learning/decay.d.ts +13 -0
- package/dist/learning/decay.js +37 -0
- package/dist/learning/decay.js.map +1 -0
- package/dist/learning/learning-engine.d.ts +30 -0
- package/dist/learning/learning-engine.js +121 -0
- package/dist/learning/learning-engine.js.map +1 -0
- package/dist/learning/pattern-extractor.d.ts +16 -0
- package/dist/learning/pattern-extractor.js +61 -0
- package/dist/learning/pattern-extractor.js.map +1 -0
- package/dist/learning/rule-generator.d.ts +18 -0
- package/dist/learning/rule-generator.js +50 -0
- package/dist/learning/rule-generator.js.map +1 -0
- package/dist/matching/error-matcher.d.ts +13 -0
- package/dist/matching/error-matcher.js +84 -0
- package/dist/matching/error-matcher.js.map +1 -0
- package/dist/matching/fingerprint.d.ts +3 -0
- package/dist/matching/fingerprint.js +23 -0
- package/dist/matching/fingerprint.js.map +1 -0
- package/dist/matching/similarity.d.ts +3 -0
- package/dist/matching/similarity.js +53 -0
- package/dist/matching/similarity.js.map +1 -0
- package/dist/matching/tfidf.d.ts +15 -0
- package/dist/matching/tfidf.js +68 -0
- package/dist/matching/tfidf.js.map +1 -0
- package/dist/matching/tokenizer.d.ts +4 -0
- package/dist/matching/tokenizer.js +36 -0
- package/dist/matching/tokenizer.js.map +1 -0
- package/dist/mcp/auto-detect.d.ts +1 -0
- package/dist/mcp/auto-detect.js +81 -0
- package/dist/mcp/auto-detect.js.map +1 -0
- package/dist/mcp/server.d.ts +1 -0
- package/dist/mcp/server.js +68 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools.d.ts +3 -0
- package/dist/mcp/tools.js +201 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/parsing/error-parser.d.ts +3 -0
- package/dist/parsing/error-parser.js +26 -0
- package/dist/parsing/error-parser.js.map +1 -0
- package/dist/parsing/parsers/compiler.d.ts +2 -0
- package/dist/parsing/parsers/compiler.js +83 -0
- package/dist/parsing/parsers/compiler.js.map +1 -0
- package/dist/parsing/parsers/generic.d.ts +2 -0
- package/dist/parsing/parsers/generic.js +23 -0
- package/dist/parsing/parsers/generic.js.map +1 -0
- package/dist/parsing/parsers/go.d.ts +2 -0
- package/dist/parsing/parsers/go.js +85 -0
- package/dist/parsing/parsers/go.js.map +1 -0
- package/dist/parsing/parsers/node.d.ts +2 -0
- package/dist/parsing/parsers/node.js +61 -0
- package/dist/parsing/parsers/node.js.map +1 -0
- package/dist/parsing/parsers/python.d.ts +2 -0
- package/dist/parsing/parsers/python.js +50 -0
- package/dist/parsing/parsers/python.js.map +1 -0
- package/dist/parsing/parsers/rust.d.ts +2 -0
- package/dist/parsing/parsers/rust.js +43 -0
- package/dist/parsing/parsers/rust.js.map +1 -0
- package/dist/parsing/parsers/shell.d.ts +2 -0
- package/dist/parsing/parsers/shell.js +36 -0
- package/dist/parsing/parsers/shell.js.map +1 -0
- package/dist/parsing/types.d.ts +28 -0
- package/dist/parsing/types.js +21 -0
- package/dist/parsing/types.js.map +1 -0
- package/dist/research/gap-analyzer.d.ts +23 -0
- package/dist/research/gap-analyzer.js +119 -0
- package/dist/research/gap-analyzer.js.map +1 -0
- package/dist/research/insight-generator.d.ts +23 -0
- package/dist/research/insight-generator.js +107 -0
- package/dist/research/insight-generator.js.map +1 -0
- package/dist/research/research-engine.d.ts +31 -0
- package/dist/research/research-engine.js +97 -0
- package/dist/research/research-engine.js.map +1 -0
- package/dist/research/synergy-detector.d.ts +24 -0
- package/dist/research/synergy-detector.js +109 -0
- package/dist/research/synergy-detector.js.map +1 -0
- package/dist/research/template-extractor.d.ts +18 -0
- package/dist/research/template-extractor.js +116 -0
- package/dist/research/template-extractor.js.map +1 -0
- package/dist/research/trend-analyzer.d.ts +20 -0
- package/dist/research/trend-analyzer.js +111 -0
- package/dist/research/trend-analyzer.js.map +1 -0
- package/dist/services/analytics.service.d.ts +52 -0
- package/dist/services/analytics.service.js +59 -0
- package/dist/services/analytics.service.js.map +1 -0
- package/dist/services/code.service.d.ts +39 -0
- package/dist/services/code.service.js +98 -0
- package/dist/services/code.service.js.map +1 -0
- package/dist/services/error.service.d.ts +35 -0
- package/dist/services/error.service.js +118 -0
- package/dist/services/error.service.js.map +1 -0
- package/dist/services/notification.service.d.ts +17 -0
- package/dist/services/notification.service.js +29 -0
- package/dist/services/notification.service.js.map +1 -0
- package/dist/services/prevention.service.d.ts +35 -0
- package/dist/services/prevention.service.js +82 -0
- package/dist/services/prevention.service.js.map +1 -0
- package/dist/services/research.service.d.ts +35 -0
- package/dist/services/research.service.js +60 -0
- package/dist/services/research.service.js.map +1 -0
- package/dist/services/solution.service.d.ts +30 -0
- package/dist/services/solution.service.js +73 -0
- package/dist/services/solution.service.js.map +1 -0
- package/dist/services/synapse.service.d.ts +30 -0
- package/dist/services/synapse.service.js +25 -0
- package/dist/services/synapse.service.js.map +1 -0
- package/dist/services/terminal.service.d.ts +20 -0
- package/dist/services/terminal.service.js +66 -0
- package/dist/services/terminal.service.js.map +1 -0
- package/dist/synapses/activation.d.ts +13 -0
- package/dist/synapses/activation.js +50 -0
- package/dist/synapses/activation.js.map +1 -0
- package/dist/synapses/decay.d.ts +11 -0
- package/dist/synapses/decay.js +27 -0
- package/dist/synapses/decay.js.map +1 -0
- package/dist/synapses/hebbian.d.ts +13 -0
- package/dist/synapses/hebbian.js +36 -0
- package/dist/synapses/hebbian.js.map +1 -0
- package/dist/synapses/pathfinder.d.ts +14 -0
- package/dist/synapses/pathfinder.js +50 -0
- package/dist/synapses/pathfinder.js.map +1 -0
- package/dist/synapses/synapse-manager.d.ts +30 -0
- package/dist/synapses/synapse-manager.js +72 -0
- package/dist/synapses/synapse-manager.js.map +1 -0
- package/dist/types/code.types.d.ts +47 -0
- package/dist/types/code.types.js +2 -0
- package/dist/types/code.types.js.map +1 -0
- package/dist/types/config.types.d.ts +70 -0
- package/dist/types/config.types.js +2 -0
- package/dist/types/config.types.js.map +1 -0
- package/dist/types/error.types.d.ts +60 -0
- package/dist/types/error.types.js +2 -0
- package/dist/types/error.types.js.map +1 -0
- package/dist/types/ipc.types.d.ts +11 -0
- package/dist/types/ipc.types.js +2 -0
- package/dist/types/ipc.types.js.map +1 -0
- package/dist/types/mcp.types.d.ts +46 -0
- package/dist/types/mcp.types.js +2 -0
- package/dist/types/mcp.types.js.map +1 -0
- package/dist/types/research.types.d.ts +25 -0
- package/dist/types/research.types.js +2 -0
- package/dist/types/research.types.js.map +1 -0
- package/dist/types/solution.types.d.ts +28 -0
- package/dist/types/solution.types.js +2 -0
- package/dist/types/solution.types.js.map +1 -0
- package/dist/types/synapse.types.d.ts +37 -0
- package/dist/types/synapse.types.js +2 -0
- package/dist/types/synapse.types.js.map +1 -0
- package/dist/utils/events.d.ts +59 -0
- package/dist/utils/events.js +23 -0
- package/dist/utils/events.js.map +1 -0
- package/dist/utils/hash.d.ts +1 -0
- package/dist/utils/hash.js +5 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/logger.d.ts +8 -0
- package/dist/utils/logger.js +39 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/paths.d.ts +3 -0
- package/dist/utils/paths.js +18 -0
- package/dist/utils/paths.js.map +1 -0
- package/package.json +43 -0
- package/src/brain.ts +220 -0
- package/src/cli/commands/dashboard.ts +495 -0
- package/src/cli/commands/export.ts +27 -0
- package/src/cli/commands/import.ts +190 -0
- package/src/cli/commands/insights.ts +33 -0
- package/src/cli/commands/modules.ts +30 -0
- package/src/cli/commands/network.ts +61 -0
- package/src/cli/commands/query.ts +43 -0
- package/src/cli/commands/start.ts +59 -0
- package/src/cli/commands/status.ts +69 -0
- package/src/cli/commands/stop.ts +33 -0
- package/src/cli/ipc-helper.ts +21 -0
- package/src/code/analyzer.ts +77 -0
- package/src/code/fingerprint.ts +87 -0
- package/src/code/matcher.ts +64 -0
- package/src/code/parsers/generic.ts +29 -0
- package/src/code/parsers/python.ts +54 -0
- package/src/code/parsers/typescript.ts +65 -0
- package/src/code/registry.ts +60 -0
- package/src/code/scorer.ts +108 -0
- package/src/config.ts +111 -0
- package/src/db/connection.ts +22 -0
- package/src/db/migrations/001_core_schema.ts +120 -0
- package/src/db/migrations/002_learning_schema.ts +38 -0
- package/src/db/migrations/003_code_schema.ts +53 -0
- package/src/db/migrations/004_synapses_schema.ts +57 -0
- package/src/db/migrations/005_fts_indexes.ts +78 -0
- package/src/db/migrations/006_synapses_phase3.ts +17 -0
- package/src/db/migrations/index.ts +64 -0
- package/src/db/repositories/antipattern.repository.ts +66 -0
- package/src/db/repositories/code-module.repository.ts +80 -0
- package/src/db/repositories/error.repository.ts +149 -0
- package/src/db/repositories/insight.repository.ts +78 -0
- package/src/db/repositories/notification.repository.ts +66 -0
- package/src/db/repositories/project.repository.ts +93 -0
- package/src/db/repositories/rule.repository.ts +108 -0
- package/src/db/repositories/solution.repository.ts +154 -0
- package/src/db/repositories/synapse.repository.ts +153 -0
- package/src/db/repositories/terminal.repository.ts +101 -0
- package/src/hooks/post-tool-use.ts +90 -0
- package/src/hooks/post-write.ts +117 -0
- package/src/index.ts +53 -0
- package/src/ipc/client.ts +118 -0
- package/src/ipc/protocol.ts +35 -0
- package/src/ipc/router.ts +106 -0
- package/src/ipc/server.ts +110 -0
- package/src/learning/confidence-scorer.ts +47 -0
- package/src/learning/decay.ts +46 -0
- package/src/learning/learning-engine.ts +162 -0
- package/src/learning/pattern-extractor.ts +90 -0
- package/src/learning/rule-generator.ts +74 -0
- package/src/main.rs:10:5 +0 -0
- package/src/matching/error-matcher.ts +115 -0
- package/src/matching/fingerprint.ts +29 -0
- package/src/matching/similarity.ts +61 -0
- package/src/matching/tfidf.ts +74 -0
- package/src/matching/tokenizer.ts +41 -0
- package/src/mcp/auto-detect.ts +93 -0
- package/src/mcp/server.ts +73 -0
- package/src/mcp/tools.ts +290 -0
- package/src/parsing/error-parser.ts +28 -0
- package/src/parsing/parsers/compiler.ts +93 -0
- package/src/parsing/parsers/generic.ts +28 -0
- package/src/parsing/parsers/go.ts +97 -0
- package/src/parsing/parsers/node.ts +69 -0
- package/src/parsing/parsers/python.ts +62 -0
- package/src/parsing/parsers/rust.ts +50 -0
- package/src/parsing/parsers/shell.ts +42 -0
- package/src/parsing/types.ts +47 -0
- package/src/research/gap-analyzer.ts +135 -0
- package/src/research/insight-generator.ts +123 -0
- package/src/research/research-engine.ts +116 -0
- package/src/research/synergy-detector.ts +126 -0
- package/src/research/template-extractor.ts +130 -0
- package/src/research/trend-analyzer.ts +127 -0
- package/src/services/analytics.service.ts +87 -0
- package/src/services/code.service.ts +140 -0
- package/src/services/error.service.ts +164 -0
- package/src/services/notification.service.ts +41 -0
- package/src/services/prevention.service.ts +119 -0
- package/src/services/research.service.ts +93 -0
- package/src/services/solution.service.ts +116 -0
- package/src/services/synapse.service.ts +59 -0
- package/src/services/terminal.service.ts +81 -0
- package/src/synapses/activation.ts +80 -0
- package/src/synapses/decay.ts +38 -0
- package/src/synapses/hebbian.ts +69 -0
- package/src/synapses/pathfinder.ts +81 -0
- package/src/synapses/synapse-manager.ts +109 -0
- package/src/types/code.types.ts +52 -0
- package/src/types/config.types.ts +79 -0
- package/src/types/error.types.ts +67 -0
- package/src/types/ipc.types.ts +8 -0
- package/src/types/mcp.types.ts +53 -0
- package/src/types/research.types.ts +28 -0
- package/src/types/solution.types.ts +30 -0
- package/src/types/synapse.types.ts +49 -0
- package/src/utils/events.ts +45 -0
- package/src/utils/hash.ts +5 -0
- package/src/utils/logger.ts +48 -0
- package/src/utils/paths.ts +19 -0
- package/tests/fixtures/code-modules/modules.ts +83 -0
- package/tests/fixtures/errors/go.ts +9 -0
- package/tests/fixtures/errors/node.ts +24 -0
- package/tests/fixtures/errors/python.ts +21 -0
- package/tests/fixtures/errors/rust.ts +25 -0
- package/tests/fixtures/errors/shell.ts +15 -0
- package/tests/fixtures/solutions/solutions.ts +27 -0
- package/tests/helpers/setup-db.ts +52 -0
- package/tests/integration/code-flow.test.ts +86 -0
- package/tests/integration/error-flow.test.ts +83 -0
- package/tests/integration/ipc-flow.test.ts +166 -0
- package/tests/integration/learning-cycle.test.ts +82 -0
- package/tests/integration/synapse-flow.test.ts +117 -0
- package/tests/unit/code/analyzer.test.ts +58 -0
- package/tests/unit/code/fingerprint.test.ts +51 -0
- package/tests/unit/code/scorer.test.ts +55 -0
- package/tests/unit/learning/confidence-scorer.test.ts +60 -0
- package/tests/unit/learning/decay.test.ts +45 -0
- package/tests/unit/learning/pattern-extractor.test.ts +50 -0
- package/tests/unit/matching/error-matcher.test.ts +69 -0
- package/tests/unit/matching/fingerprint.test.ts +47 -0
- package/tests/unit/matching/similarity.test.ts +65 -0
- package/tests/unit/matching/tfidf.test.ts +71 -0
- package/tests/unit/matching/tokenizer.test.ts +83 -0
- package/tests/unit/parsing/parsers.test.ts +113 -0
- package/tests/unit/research/gap-analyzer.test.ts +45 -0
- package/tests/unit/research/trend-analyzer.test.ts +45 -0
- package/tests/unit/synapses/activation.test.ts +80 -0
- package/tests/unit/synapses/decay.test.ts +27 -0
- package/tests/unit/synapses/hebbian.test.ts +96 -0
- package/tests/unit/synapses/pathfinder.test.ts +72 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { getLogger } from '../utils/logger.js';
|
|
2
|
+
/**
|
|
3
|
+
* Analyzes error frequency and solution success rate trends over time windows.
|
|
4
|
+
*/
|
|
5
|
+
export class TrendAnalyzer {
|
|
6
|
+
errorRepo;
|
|
7
|
+
solutionRepo;
|
|
8
|
+
projectRepo;
|
|
9
|
+
insightRepo;
|
|
10
|
+
config;
|
|
11
|
+
logger = getLogger();
|
|
12
|
+
constructor(errorRepo, solutionRepo, projectRepo, insightRepo, config) {
|
|
13
|
+
this.errorRepo = errorRepo;
|
|
14
|
+
this.solutionRepo = solutionRepo;
|
|
15
|
+
this.projectRepo = projectRepo;
|
|
16
|
+
this.insightRepo = insightRepo;
|
|
17
|
+
this.config = config;
|
|
18
|
+
}
|
|
19
|
+
analyze() {
|
|
20
|
+
const projects = this.projectRepo.getAll();
|
|
21
|
+
let insightsCreated = 0;
|
|
22
|
+
for (const project of projects) {
|
|
23
|
+
insightsCreated += this.analyzeErrorTrend(project.id, project.name);
|
|
24
|
+
insightsCreated += this.analyzeSolutionTrend(project.id, project.name);
|
|
25
|
+
}
|
|
26
|
+
this.logger.info(`Trend analysis complete: ${insightsCreated} insights`);
|
|
27
|
+
return insightsCreated;
|
|
28
|
+
}
|
|
29
|
+
analyzeErrorTrend(projectId, projectName) {
|
|
30
|
+
const windowDays = this.config.trendWindowDays;
|
|
31
|
+
const now = Date.now();
|
|
32
|
+
const recentSince = new Date(now - windowDays * 86400000).toISOString();
|
|
33
|
+
const previousSince = new Date(now - windowDays * 2 * 86400000).toISOString();
|
|
34
|
+
const recentErrors = this.errorRepo.countSince(recentSince, projectId);
|
|
35
|
+
const allSinceDouble = this.errorRepo.countSince(previousSince, projectId);
|
|
36
|
+
const previousErrors = allSinceDouble - recentErrors;
|
|
37
|
+
if (previousErrors <= 0)
|
|
38
|
+
return 0;
|
|
39
|
+
const changeRate = (recentErrors - previousErrors) / previousErrors;
|
|
40
|
+
const expiresAt = new Date(Date.now() + this.config.insightExpiryDays * 86400000).toISOString();
|
|
41
|
+
if (changeRate > 0.5) {
|
|
42
|
+
this.insightRepo.create({
|
|
43
|
+
type: 'warning',
|
|
44
|
+
title: `Error rate rising in ${projectName}`,
|
|
45
|
+
description: `${Math.round(changeRate * 100)}% more errors in the last ${windowDays} days vs previous window. Check recent changes: new dependencies, refactoring, or API changes.`,
|
|
46
|
+
evidence: JSON.stringify({ recentErrors, previousErrors, changeRate, windowDays }),
|
|
47
|
+
priority: Math.min(90, 50 + Math.round(changeRate * 30)),
|
|
48
|
+
project_id: projectId,
|
|
49
|
+
active: 1,
|
|
50
|
+
expires_at: expiresAt,
|
|
51
|
+
});
|
|
52
|
+
return 1;
|
|
53
|
+
}
|
|
54
|
+
if (changeRate < -0.3) {
|
|
55
|
+
this.insightRepo.create({
|
|
56
|
+
type: 'pattern',
|
|
57
|
+
title: `Error rate declining in ${projectName}`,
|
|
58
|
+
description: `${Math.round(-changeRate * 100)}% fewer errors in the last ${windowDays} days. Whatever you're doing is working.`,
|
|
59
|
+
evidence: JSON.stringify({ recentErrors, previousErrors, changeRate, windowDays }),
|
|
60
|
+
priority: 20,
|
|
61
|
+
project_id: projectId,
|
|
62
|
+
active: 1,
|
|
63
|
+
expires_at: expiresAt,
|
|
64
|
+
});
|
|
65
|
+
return 1;
|
|
66
|
+
}
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
analyzeSolutionTrend(projectId, projectName) {
|
|
70
|
+
const errors = this.errorRepo.findByProject(projectId);
|
|
71
|
+
if (errors.length < this.config.minDataPoints)
|
|
72
|
+
return 0;
|
|
73
|
+
let totalRate = 0;
|
|
74
|
+
let recentRate = 0;
|
|
75
|
+
let totalCount = 0;
|
|
76
|
+
let recentCount = 0;
|
|
77
|
+
const recentCutoff = new Date(Date.now() - this.config.trendWindowDays * 86400000).toISOString();
|
|
78
|
+
for (const error of errors) {
|
|
79
|
+
const solutions = this.solutionRepo.findForError(error.id);
|
|
80
|
+
for (const sol of solutions) {
|
|
81
|
+
const rate = this.solutionRepo.successRate(sol.id);
|
|
82
|
+
totalRate += rate;
|
|
83
|
+
totalCount++;
|
|
84
|
+
if (sol.updated_at >= recentCutoff) {
|
|
85
|
+
recentRate += rate;
|
|
86
|
+
recentCount++;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (totalCount === 0 || recentCount === 0)
|
|
91
|
+
return 0;
|
|
92
|
+
const avgTotal = totalRate / totalCount;
|
|
93
|
+
const avgRecent = recentRate / recentCount;
|
|
94
|
+
if (avgRecent < avgTotal - 0.15 && totalCount >= this.config.minDataPoints) {
|
|
95
|
+
const expiresAt = new Date(Date.now() + this.config.insightExpiryDays * 86400000).toISOString();
|
|
96
|
+
this.insightRepo.create({
|
|
97
|
+
type: 'warning',
|
|
98
|
+
title: `Solution quality declining in ${projectName}`,
|
|
99
|
+
description: `Recent success rate ${Math.round(avgRecent * 100)}% vs overall ${Math.round(avgTotal * 100)}%. Solutions are becoming less effective.`,
|
|
100
|
+
evidence: JSON.stringify({ avgRecent, avgTotal, recentCount, totalCount }),
|
|
101
|
+
priority: 60,
|
|
102
|
+
project_id: projectId,
|
|
103
|
+
active: 1,
|
|
104
|
+
expires_at: expiresAt,
|
|
105
|
+
});
|
|
106
|
+
return 1;
|
|
107
|
+
}
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=trend-analyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trend-analyzer.js","sourceRoot":"","sources":["../../src/research/trend-analyzer.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C;;GAEG;AACH,MAAM,OAAO,aAAa;IAId;IACA;IACA;IACA;IACA;IAPF,MAAM,GAAG,SAAS,EAAE,CAAC;IAE7B,YACU,SAA0B,EAC1B,YAAgC,EAChC,WAA8B,EAC9B,WAA8B,EAC9B,MAAsB;QAJtB,cAAS,GAAT,SAAS,CAAiB;QAC1B,iBAAY,GAAZ,YAAY,CAAoB;QACh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AAM,QAAQ,GAAG,SAAS,GAAG,UAAU,CAAC;QACxC,MAAM,SAAS,GAAG,UAAU,GAAG,WAAW,CAAC;QAE3C,IAAI,SAAS,GAAG,QAAQ,GAAG,IAAI,IAAI,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;YAC3E,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAiB,GAAG,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;YAChG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;gBACtB,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,iCAAiC,WAAW,EAAE;gBACrD,WAAW,EAAE,uBAAuB,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,GAAG,CAAC,gBAAgB,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,GAAG,CAAC,2CAA2C;gBACpJ,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;gBAC1E,QAAQ,EAAE,EAAE;gBACZ,UAAU,EAAE,SAAS;gBACrB,MAAM,EAAE,CAAC;gBACT,UAAU,EAAE,SAAS;aACtB,CAAC,CAAC;YACH,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO,CAAC,CAAC;IACX,CAAC;CACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ErrorRepository } from '../db/repositories/error.repository.js';
|
|
2
|
+
import type { SolutionRepository } from '../db/repositories/solution.repository.js';
|
|
3
|
+
import type { CodeModuleRepository } from '../db/repositories/code-module.repository.js';
|
|
4
|
+
import type { RuleRepository } from '../db/repositories/rule.repository.js';
|
|
5
|
+
import type { AntipatternRepository } from '../db/repositories/antipattern.repository.js';
|
|
6
|
+
import type { InsightRepository } from '../db/repositories/insight.repository.js';
|
|
7
|
+
import type { SynapseManager } from '../synapses/synapse-manager.js';
|
|
8
|
+
import type { NetworkStats } from '../types/synapse.types.js';
|
|
9
|
+
export interface ProjectSummary {
|
|
10
|
+
errors: {
|
|
11
|
+
total: number;
|
|
12
|
+
unresolved: number;
|
|
13
|
+
last7d: number;
|
|
14
|
+
};
|
|
15
|
+
solutions: {
|
|
16
|
+
total: number;
|
|
17
|
+
};
|
|
18
|
+
rules: {
|
|
19
|
+
active: number;
|
|
20
|
+
};
|
|
21
|
+
antipatterns: {
|
|
22
|
+
total: number;
|
|
23
|
+
};
|
|
24
|
+
modules: {
|
|
25
|
+
total: number;
|
|
26
|
+
};
|
|
27
|
+
insights: {
|
|
28
|
+
active: number;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export interface NetworkOverview {
|
|
32
|
+
stats: NetworkStats;
|
|
33
|
+
strongestSynapses: Array<{
|
|
34
|
+
id: number;
|
|
35
|
+
source: string;
|
|
36
|
+
target: string;
|
|
37
|
+
type: string;
|
|
38
|
+
weight: number;
|
|
39
|
+
}>;
|
|
40
|
+
}
|
|
41
|
+
export declare class AnalyticsService {
|
|
42
|
+
private errorRepo;
|
|
43
|
+
private solutionRepo;
|
|
44
|
+
private codeModuleRepo;
|
|
45
|
+
private ruleRepo;
|
|
46
|
+
private antipatternRepo;
|
|
47
|
+
private insightRepo;
|
|
48
|
+
private synapseManager;
|
|
49
|
+
constructor(errorRepo: ErrorRepository, solutionRepo: SolutionRepository, codeModuleRepo: CodeModuleRepository, ruleRepo: RuleRepository, antipatternRepo: AntipatternRepository, insightRepo: InsightRepository, synapseManager: SynapseManager);
|
|
50
|
+
getSummary(projectId?: number): ProjectSummary;
|
|
51
|
+
getNetworkOverview(limit?: number): NetworkOverview;
|
|
52
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export class AnalyticsService {
|
|
2
|
+
errorRepo;
|
|
3
|
+
solutionRepo;
|
|
4
|
+
codeModuleRepo;
|
|
5
|
+
ruleRepo;
|
|
6
|
+
antipatternRepo;
|
|
7
|
+
insightRepo;
|
|
8
|
+
synapseManager;
|
|
9
|
+
constructor(errorRepo, solutionRepo, codeModuleRepo, ruleRepo, antipatternRepo, insightRepo, synapseManager) {
|
|
10
|
+
this.errorRepo = errorRepo;
|
|
11
|
+
this.solutionRepo = solutionRepo;
|
|
12
|
+
this.codeModuleRepo = codeModuleRepo;
|
|
13
|
+
this.ruleRepo = ruleRepo;
|
|
14
|
+
this.antipatternRepo = antipatternRepo;
|
|
15
|
+
this.insightRepo = insightRepo;
|
|
16
|
+
this.synapseManager = synapseManager;
|
|
17
|
+
}
|
|
18
|
+
getSummary(projectId) {
|
|
19
|
+
const sevenDaysAgo = new Date(Date.now() - 7 * 86400000).toISOString();
|
|
20
|
+
const unresolvedErrors = this.errorRepo.findUnresolved(projectId);
|
|
21
|
+
const allErrors = projectId ? this.errorRepo.findByProject(projectId) : [];
|
|
22
|
+
const last7dCount = this.errorRepo.countSince(sevenDaysAgo, projectId);
|
|
23
|
+
const rules = this.ruleRepo.findActive(projectId);
|
|
24
|
+
const antipatterns = projectId
|
|
25
|
+
? this.antipatternRepo.findByProject(projectId)
|
|
26
|
+
: this.antipatternRepo.findGlobal();
|
|
27
|
+
const moduleCount = projectId
|
|
28
|
+
? this.codeModuleRepo.findByProject(projectId).length
|
|
29
|
+
: this.codeModuleRepo.countAll();
|
|
30
|
+
const insights = this.insightRepo.findActive(projectId);
|
|
31
|
+
return {
|
|
32
|
+
errors: {
|
|
33
|
+
total: allErrors.length,
|
|
34
|
+
unresolved: unresolvedErrors.length,
|
|
35
|
+
last7d: last7dCount,
|
|
36
|
+
},
|
|
37
|
+
solutions: { total: 0 }, // solutions are global, not per-project
|
|
38
|
+
rules: { active: rules.length },
|
|
39
|
+
antipatterns: { total: antipatterns.length },
|
|
40
|
+
modules: { total: moduleCount },
|
|
41
|
+
insights: { active: insights.length },
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
getNetworkOverview(limit = 10) {
|
|
45
|
+
const stats = this.synapseManager.getNetworkStats();
|
|
46
|
+
const strongest = this.synapseManager.getStrongestSynapses(limit);
|
|
47
|
+
return {
|
|
48
|
+
stats,
|
|
49
|
+
strongestSynapses: strongest.map(s => ({
|
|
50
|
+
id: s.id,
|
|
51
|
+
source: `${s.source_type}:${s.source_id}`,
|
|
52
|
+
target: `${s.target_type}:${s.target_id}`,
|
|
53
|
+
type: s.synapse_type,
|
|
54
|
+
weight: s.weight,
|
|
55
|
+
})),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=analytics.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics.service.js","sourceRoot":"","sources":["../../src/services/analytics.service.ts"],"names":[],"mappings":"AA6BA,MAAM,OAAO,gBAAgB;IAEjB;IACA;IACA;IACA;IACA;IACA;IACA;IAPV,YACU,SAA0B,EAC1B,YAAgC,EAChC,cAAoC,EACpC,QAAwB,EACxB,eAAsC,EACtC,WAA8B,EAC9B,cAA8B;QAN9B,cAAS,GAAT,SAAS,CAAiB;QAC1B,iBAAY,GAAZ,YAAY,CAAoB;QAChC,mBAAc,GAAd,cAAc,CAAsB;QACpC,aAAQ,GAAR,QAAQ,CAAgB;QACxB,oBAAe,GAAf,eAAe,CAAuB;QACtC,gBAAW,GAAX,WAAW,CAAmB;QAC9B,mBAAc,GAAd,cAAc,CAAgB;IACrC,CAAC;IAEJ,UAAU,CAAC,SAAkB;QAC3B,MAAM,YAAY,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;QAEvE,MAAM,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QAClE,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,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ElE,OAAO;YACL,KAAK;YACL,iBAAiB,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBACrC,EAAE,EAAE,CAAC,CAAC,EAAE;gBACR,MAAM,EAAE,GAAG,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,SAAS,EAAE;gBACzC,MAAM,EAAE,GAAG,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,SAAS,EAAE;gBACzC,IAAI,EAAE,CAAC,CAAC,YAAY;gBACpB,MAAM,EAAE,CAAC,CAAC,MAAM;aACjB,CAAC,CAAC;SACJ,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CodeModuleRecord } from '../types/code.types.js';
|
|
2
|
+
import type { CodeModuleRepository } from '../db/repositories/code-module.repository.js';
|
|
3
|
+
import type { ProjectRepository } from '../db/repositories/project.repository.js';
|
|
4
|
+
import type { SynapseManager } from '../synapses/synapse-manager.js';
|
|
5
|
+
export interface AnalyzeInput {
|
|
6
|
+
project: string;
|
|
7
|
+
name: string;
|
|
8
|
+
filePath: string;
|
|
9
|
+
language: string;
|
|
10
|
+
source: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface FindReusableInput {
|
|
14
|
+
query?: string;
|
|
15
|
+
language?: string;
|
|
16
|
+
projectId?: number;
|
|
17
|
+
limit?: number;
|
|
18
|
+
}
|
|
19
|
+
export declare class CodeService {
|
|
20
|
+
private codeModuleRepo;
|
|
21
|
+
private projectRepo;
|
|
22
|
+
private synapseManager;
|
|
23
|
+
private logger;
|
|
24
|
+
private eventBus;
|
|
25
|
+
constructor(codeModuleRepo: CodeModuleRepository, projectRepo: ProjectRepository, synapseManager: SynapseManager);
|
|
26
|
+
analyzeAndRegister(input: AnalyzeInput): {
|
|
27
|
+
moduleId: number;
|
|
28
|
+
isNew: boolean;
|
|
29
|
+
reusabilityScore: number;
|
|
30
|
+
};
|
|
31
|
+
findReusable(input: FindReusableInput): CodeModuleRecord[];
|
|
32
|
+
checkSimilarity(source: string, language: string): Array<{
|
|
33
|
+
moduleId: number;
|
|
34
|
+
score: number;
|
|
35
|
+
matchType: string;
|
|
36
|
+
}>;
|
|
37
|
+
listModules(projectId?: number): CodeModuleRecord[];
|
|
38
|
+
getById(id: number): CodeModuleRecord | undefined;
|
|
39
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { analyzeCode } from '../code/analyzer.js';
|
|
2
|
+
import { fingerprintCode } from '../code/fingerprint.js';
|
|
3
|
+
import { computeReusabilityScore } from '../code/scorer.js';
|
|
4
|
+
import { detectGranularity } from '../code/registry.js';
|
|
5
|
+
import { findExactMatches, findSemanticMatches } from '../code/matcher.js';
|
|
6
|
+
import { sha256 } from '../utils/hash.js';
|
|
7
|
+
import { getEventBus } from '../utils/events.js';
|
|
8
|
+
import { getLogger } from '../utils/logger.js';
|
|
9
|
+
export class CodeService {
|
|
10
|
+
codeModuleRepo;
|
|
11
|
+
projectRepo;
|
|
12
|
+
synapseManager;
|
|
13
|
+
logger = getLogger();
|
|
14
|
+
eventBus = getEventBus();
|
|
15
|
+
constructor(codeModuleRepo, projectRepo, synapseManager) {
|
|
16
|
+
this.codeModuleRepo = codeModuleRepo;
|
|
17
|
+
this.projectRepo = projectRepo;
|
|
18
|
+
this.synapseManager = synapseManager;
|
|
19
|
+
}
|
|
20
|
+
analyzeAndRegister(input) {
|
|
21
|
+
// Ensure project exists
|
|
22
|
+
let project = this.projectRepo.findByName(input.project);
|
|
23
|
+
if (!project) {
|
|
24
|
+
const id = this.projectRepo.create({ name: input.project, path: null, language: input.language, framework: null });
|
|
25
|
+
project = this.projectRepo.getById(id);
|
|
26
|
+
}
|
|
27
|
+
// Analyze the code
|
|
28
|
+
const analysis = analyzeCode(input.source, input.language);
|
|
29
|
+
const fingerprint = fingerprintCode(input.source, input.language);
|
|
30
|
+
const sourceHash = sha256(input.source);
|
|
31
|
+
// Check if module already exists (by fingerprint)
|
|
32
|
+
const existing = this.codeModuleRepo.findByFingerprint(fingerprint);
|
|
33
|
+
if (existing) {
|
|
34
|
+
this.codeModuleRepo.update(existing.id, {
|
|
35
|
+
source_hash: sourceHash,
|
|
36
|
+
updated_at: new Date().toISOString(),
|
|
37
|
+
});
|
|
38
|
+
this.synapseManager.strengthen({ type: 'code_module', id: existing.id }, { type: 'project', id: project.id }, 'uses_module');
|
|
39
|
+
return { moduleId: existing.id, isNew: false, reusabilityScore: existing.reusability_score };
|
|
40
|
+
}
|
|
41
|
+
// Compute reusability score
|
|
42
|
+
const reusabilityScore = computeReusabilityScore({
|
|
43
|
+
source: input.source,
|
|
44
|
+
filePath: input.filePath,
|
|
45
|
+
exports: analysis.exports,
|
|
46
|
+
internalDeps: analysis.internalDeps,
|
|
47
|
+
hasTypeAnnotations: analysis.hasTypeAnnotations,
|
|
48
|
+
});
|
|
49
|
+
const granularity = detectGranularity(input.source, input.language);
|
|
50
|
+
const moduleId = this.codeModuleRepo.create({
|
|
51
|
+
project_id: project.id,
|
|
52
|
+
name: input.name,
|
|
53
|
+
file_path: input.filePath,
|
|
54
|
+
language: input.language,
|
|
55
|
+
fingerprint,
|
|
56
|
+
description: input.description ?? null,
|
|
57
|
+
source_hash: sourceHash,
|
|
58
|
+
lines_of_code: analysis.linesOfCode,
|
|
59
|
+
complexity: null,
|
|
60
|
+
reusability_score: reusabilityScore,
|
|
61
|
+
});
|
|
62
|
+
// Create synapse: module ↔ project
|
|
63
|
+
this.synapseManager.strengthen({ type: 'code_module', id: moduleId }, { type: 'project', id: project.id }, 'uses_module');
|
|
64
|
+
this.eventBus.emit('module:registered', { moduleId, projectId: project.id });
|
|
65
|
+
this.logger.info(`Code module registered (id=${moduleId}, name=${input.name}, granularity=${granularity}, score=${reusabilityScore.toFixed(2)})`);
|
|
66
|
+
return { moduleId, isNew: true, reusabilityScore };
|
|
67
|
+
}
|
|
68
|
+
findReusable(input) {
|
|
69
|
+
if (input.query) {
|
|
70
|
+
return this.codeModuleRepo.search(input.query);
|
|
71
|
+
}
|
|
72
|
+
if (input.language) {
|
|
73
|
+
return this.codeModuleRepo.findByLanguage(input.language, input.limit);
|
|
74
|
+
}
|
|
75
|
+
if (input.projectId) {
|
|
76
|
+
return this.codeModuleRepo.findByProject(input.projectId);
|
|
77
|
+
}
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
checkSimilarity(source, language) {
|
|
81
|
+
const fingerprint = fingerprintCode(source, language);
|
|
82
|
+
const allModules = this.codeModuleRepo.findByLanguage(language);
|
|
83
|
+
const exact = findExactMatches(fingerprint, allModules);
|
|
84
|
+
if (exact.length > 0)
|
|
85
|
+
return exact;
|
|
86
|
+
return findSemanticMatches(source, allModules, 0.5);
|
|
87
|
+
}
|
|
88
|
+
listModules(projectId) {
|
|
89
|
+
if (projectId) {
|
|
90
|
+
return this.codeModuleRepo.findByProject(projectId);
|
|
91
|
+
}
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
getById(id) {
|
|
95
|
+
return this.codeModuleRepo.getById(id);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=code.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.service.js","sourceRoot":"","sources":["../../src/services/code.service.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAA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AAC,WAAW,EAAE,UAAU,CAAC,CAAC;QACxD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;QAEnC,OAAO,mBAAmB,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;IACtD,CAAC;IAED,WAAW,CAAC,SAAkB;QAC5B,IAAI,SAAS,EAAE,CAAC;YACd,OAAO,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,CAAC,EAAU;QAChB,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACzC,CAAC;CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ErrorRecord } from '../types/error.types.js';
|
|
2
|
+
import type { ErrorRepository } from '../db/repositories/error.repository.js';
|
|
3
|
+
import type { ProjectRepository } from '../db/repositories/project.repository.js';
|
|
4
|
+
import type { SynapseManager } from '../synapses/synapse-manager.js';
|
|
5
|
+
import { type MatchResult } from '../matching/error-matcher.js';
|
|
6
|
+
export interface ReportErrorInput {
|
|
7
|
+
project: string;
|
|
8
|
+
errorOutput: string;
|
|
9
|
+
filePath?: string;
|
|
10
|
+
terminalId?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ErrorQueryInput {
|
|
13
|
+
projectId?: number;
|
|
14
|
+
resolved?: boolean;
|
|
15
|
+
search?: string;
|
|
16
|
+
limit?: number;
|
|
17
|
+
}
|
|
18
|
+
export declare class ErrorService {
|
|
19
|
+
private errorRepo;
|
|
20
|
+
private projectRepo;
|
|
21
|
+
private synapseManager;
|
|
22
|
+
private logger;
|
|
23
|
+
private eventBus;
|
|
24
|
+
constructor(errorRepo: ErrorRepository, projectRepo: ProjectRepository, synapseManager: SynapseManager);
|
|
25
|
+
report(input: ReportErrorInput): {
|
|
26
|
+
errorId: number;
|
|
27
|
+
isNew: boolean;
|
|
28
|
+
matches: MatchResult[];
|
|
29
|
+
};
|
|
30
|
+
query(input: ErrorQueryInput): ErrorRecord[];
|
|
31
|
+
matchSimilar(errorId: number): MatchResult[];
|
|
32
|
+
resolve(errorId: number, solutionId?: number): void;
|
|
33
|
+
getById(id: number): ErrorRecord | undefined;
|
|
34
|
+
countSince(since: string, projectId?: number): number;
|
|
35
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { parseError } from '../parsing/error-parser.js';
|
|
2
|
+
import { generateFingerprint } from '../matching/fingerprint.js';
|
|
3
|
+
import { matchError } from '../matching/error-matcher.js';
|
|
4
|
+
import { getEventBus } from '../utils/events.js';
|
|
5
|
+
import { getLogger } from '../utils/logger.js';
|
|
6
|
+
export class ErrorService {
|
|
7
|
+
errorRepo;
|
|
8
|
+
projectRepo;
|
|
9
|
+
synapseManager;
|
|
10
|
+
logger = getLogger();
|
|
11
|
+
eventBus = getEventBus();
|
|
12
|
+
constructor(errorRepo, projectRepo, synapseManager) {
|
|
13
|
+
this.errorRepo = errorRepo;
|
|
14
|
+
this.projectRepo = projectRepo;
|
|
15
|
+
this.synapseManager = synapseManager;
|
|
16
|
+
}
|
|
17
|
+
report(input) {
|
|
18
|
+
// 1. Ensure project exists
|
|
19
|
+
let project = this.projectRepo.findByName(input.project);
|
|
20
|
+
if (!project) {
|
|
21
|
+
const id = this.projectRepo.create({ name: input.project, path: null, language: null, framework: null });
|
|
22
|
+
project = this.projectRepo.getById(id);
|
|
23
|
+
}
|
|
24
|
+
// 2. Parse the error
|
|
25
|
+
const parsed = parseError(input.errorOutput);
|
|
26
|
+
if (!parsed) {
|
|
27
|
+
this.logger.warn('Could not parse error output');
|
|
28
|
+
const errorId = this.errorRepo.create({
|
|
29
|
+
project_id: project.id,
|
|
30
|
+
terminal_id: input.terminalId ?? null,
|
|
31
|
+
fingerprint: '',
|
|
32
|
+
type: 'UnknownError',
|
|
33
|
+
message: input.errorOutput.split('\n')[0] ?? input.errorOutput,
|
|
34
|
+
raw_output: input.errorOutput,
|
|
35
|
+
context: null,
|
|
36
|
+
file_path: input.filePath ?? null,
|
|
37
|
+
line_number: null,
|
|
38
|
+
column_number: null,
|
|
39
|
+
});
|
|
40
|
+
return { errorId, isNew: true, matches: [] };
|
|
41
|
+
}
|
|
42
|
+
// 3. Generate fingerprint
|
|
43
|
+
const fingerprint = generateFingerprint(parsed.errorType, parsed.message, parsed.frames);
|
|
44
|
+
// 4. Check for existing error with same fingerprint
|
|
45
|
+
const existing = this.errorRepo.findByFingerprint(fingerprint);
|
|
46
|
+
if (existing.length > 0) {
|
|
47
|
+
const err = existing[0];
|
|
48
|
+
this.errorRepo.incrementOccurrence(err.id);
|
|
49
|
+
this.logger.info(`Known error (id=${err.id}), occurrence incremented`);
|
|
50
|
+
// Strengthen synapse
|
|
51
|
+
this.synapseManager.strengthen({ type: 'error', id: err.id }, { type: 'project', id: project.id }, 'co_occurs');
|
|
52
|
+
return { errorId: err.id, isNew: false, matches: [] };
|
|
53
|
+
}
|
|
54
|
+
// 5. Create new error record
|
|
55
|
+
const errorId = this.errorRepo.create({
|
|
56
|
+
project_id: project.id,
|
|
57
|
+
terminal_id: input.terminalId ?? null,
|
|
58
|
+
fingerprint,
|
|
59
|
+
type: parsed.errorType,
|
|
60
|
+
message: parsed.message,
|
|
61
|
+
raw_output: input.errorOutput,
|
|
62
|
+
context: null,
|
|
63
|
+
file_path: parsed.sourceFile ?? input.filePath ?? null,
|
|
64
|
+
line_number: parsed.sourceLine ?? null,
|
|
65
|
+
column_number: null,
|
|
66
|
+
});
|
|
67
|
+
// 6. Create synapse: error ↔ project
|
|
68
|
+
this.synapseManager.strengthen({ type: 'error', id: errorId }, { type: 'project', id: project.id }, 'co_occurs');
|
|
69
|
+
// 7. Find similar errors
|
|
70
|
+
const candidates = this.errorRepo.findByProject(project.id)
|
|
71
|
+
.filter(e => e.id !== errorId);
|
|
72
|
+
const newError = this.errorRepo.getById(errorId);
|
|
73
|
+
const matches = matchError(newError, candidates);
|
|
74
|
+
// 8. Create similarity synapses for strong matches
|
|
75
|
+
for (const match of matches.filter(m => m.isStrong)) {
|
|
76
|
+
this.synapseManager.strengthen({ type: 'error', id: errorId }, { type: 'error', id: match.errorId }, 'similar_to');
|
|
77
|
+
}
|
|
78
|
+
this.eventBus.emit('error:reported', { errorId, projectId: project.id, fingerprint });
|
|
79
|
+
this.logger.info(`New error reported (id=${errorId}, type=${parsed.errorType})`);
|
|
80
|
+
return { errorId, isNew: true, matches };
|
|
81
|
+
}
|
|
82
|
+
query(input) {
|
|
83
|
+
if (input.search) {
|
|
84
|
+
return this.errorRepo.search(input.search);
|
|
85
|
+
}
|
|
86
|
+
if (input.resolved === false) {
|
|
87
|
+
return this.errorRepo.findUnresolved(input.projectId);
|
|
88
|
+
}
|
|
89
|
+
if (input.projectId) {
|
|
90
|
+
return this.errorRepo.findByProject(input.projectId);
|
|
91
|
+
}
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
matchSimilar(errorId) {
|
|
95
|
+
const error = this.errorRepo.getById(errorId);
|
|
96
|
+
if (!error)
|
|
97
|
+
return [];
|
|
98
|
+
const candidates = this.errorRepo.findByProject(error.project_id)
|
|
99
|
+
.filter(e => e.id !== errorId);
|
|
100
|
+
return matchError(error, candidates);
|
|
101
|
+
}
|
|
102
|
+
resolve(errorId, solutionId) {
|
|
103
|
+
this.errorRepo.update(errorId, {
|
|
104
|
+
resolved: 1,
|
|
105
|
+
resolved_at: new Date().toISOString(),
|
|
106
|
+
});
|
|
107
|
+
if (solutionId) {
|
|
108
|
+
this.eventBus.emit('error:resolved', { errorId, solutionId });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
getById(id) {
|
|
112
|
+
return this.errorRepo.getById(id);
|
|
113
|
+
}
|
|
114
|
+
countSince(since, projectId) {
|
|
115
|
+
return this.errorRepo.countSince(since, projectId);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=error.service.js.map
|
|
@@ -0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,KAAK;YAAE,OAAO,EAAE,CAAC;QAEtB,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC;aAC9D,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC;QACjC,OAAO,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,CAAC,OAAe,EAAE,UAAmB;QAC1C,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE;YAC7B,QAAQ,EAAE,CAAC;YACX,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACtC,CAAC,CAAC;QAEH,IAAI,UAAU,EAAE,CAAC;YACf,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IAED,OAAO,CAAC,EAAU;QAChB,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC;IAED,UAAU,CAAC,KAAa,EAAE,SAAkB;QAC1C,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IACrD,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { NotificationRepository, NotificationRecord } from '../db/repositories/notification.repository.js';
|
|
2
|
+
export interface CreateNotificationInput {
|
|
3
|
+
type: string;
|
|
4
|
+
title: string;
|
|
5
|
+
message: string;
|
|
6
|
+
priority?: number;
|
|
7
|
+
projectId?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class NotificationService {
|
|
10
|
+
private notificationRepo;
|
|
11
|
+
private logger;
|
|
12
|
+
constructor(notificationRepo: NotificationRepository);
|
|
13
|
+
create(input: CreateNotificationInput): number;
|
|
14
|
+
list(projectId?: number): NotificationRecord[];
|
|
15
|
+
acknowledge(id: number): void;
|
|
16
|
+
getById(id: number): NotificationRecord | undefined;
|
|
17
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getLogger } from '../utils/logger.js';
|
|
2
|
+
export class NotificationService {
|
|
3
|
+
notificationRepo;
|
|
4
|
+
logger = getLogger();
|
|
5
|
+
constructor(notificationRepo) {
|
|
6
|
+
this.notificationRepo = notificationRepo;
|
|
7
|
+
}
|
|
8
|
+
create(input) {
|
|
9
|
+
const id = this.notificationRepo.create({
|
|
10
|
+
type: input.type,
|
|
11
|
+
title: input.title,
|
|
12
|
+
message: input.message,
|
|
13
|
+
priority: input.priority ?? 0,
|
|
14
|
+
project_id: input.projectId ?? null,
|
|
15
|
+
});
|
|
16
|
+
this.logger.info(`Notification created (id=${id}, type=${input.type})`);
|
|
17
|
+
return id;
|
|
18
|
+
}
|
|
19
|
+
list(projectId) {
|
|
20
|
+
return this.notificationRepo.findUnacknowledged(projectId);
|
|
21
|
+
}
|
|
22
|
+
acknowledge(id) {
|
|
23
|
+
this.notificationRepo.acknowledge(id);
|
|
24
|
+
}
|
|
25
|
+
getById(id) {
|
|
26
|
+
return this.notificationRepo.getById(id);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=notification.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification.service.js","sourceRoot":"","sources":["../../src/services/notification.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAU/C,MAAM,OAAO,mBAAmB;IAGV;IAFZ,MAAM,GAAG,SAAS,EAAE,CAAC;IAE7B,YAAoB,gBAAwC;QAAxC,qBAAgB,GAAhB,gBAAgB,CAAwB;IAAG,CAAC;IAEhE,MAAM,CAAC,KAA8B;QACnC,MAAM,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC;YACtC,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,CAAC;YAC7B,UAAU,EAAE,KAAK,CAAC,SAAS,IAAI,IAAI;SACpC,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,4BAA4B,EAAE,UAAU,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC;QACxE,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,CAAC,SAAkB;QACrB,OAAO,IAAI,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC7D,CAAC;IAED,WAAW,CAAC,EAAU;QACpB,IAAI,CAAC,gBAAgB,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,CAAC,EAAU;QAChB,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC3C,CAAC;CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { RuleRepository } from '../db/repositories/rule.repository.js';
|
|
2
|
+
import type { AntipatternRepository } from '../db/repositories/antipattern.repository.js';
|
|
3
|
+
import type { SynapseManager } from '../synapses/synapse-manager.js';
|
|
4
|
+
export interface RuleCheckResult {
|
|
5
|
+
matched: boolean;
|
|
6
|
+
ruleId: number;
|
|
7
|
+
action: string;
|
|
8
|
+
description: string | null;
|
|
9
|
+
confidence: number;
|
|
10
|
+
}
|
|
11
|
+
export interface AntipatternCheckResult {
|
|
12
|
+
matched: boolean;
|
|
13
|
+
antipatternId: number;
|
|
14
|
+
pattern: string;
|
|
15
|
+
description: string;
|
|
16
|
+
severity: string;
|
|
17
|
+
suggestion: string | null;
|
|
18
|
+
}
|
|
19
|
+
export declare class PreventionService {
|
|
20
|
+
private ruleRepo;
|
|
21
|
+
private antipatternRepo;
|
|
22
|
+
private synapseManager;
|
|
23
|
+
private logger;
|
|
24
|
+
constructor(ruleRepo: RuleRepository, antipatternRepo: AntipatternRepository, synapseManager: SynapseManager);
|
|
25
|
+
checkRules(errorType: string, message: string, projectId?: number): RuleCheckResult[];
|
|
26
|
+
checkAntipatterns(errorType: string, message: string, projectId?: number): AntipatternCheckResult[];
|
|
27
|
+
createRule(data: {
|
|
28
|
+
pattern: string;
|
|
29
|
+
action: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
confidence?: number;
|
|
32
|
+
projectId?: number;
|
|
33
|
+
}): number;
|
|
34
|
+
reportPrevention(ruleId: number, errorId: number): void;
|
|
35
|
+
}
|