@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,83 @@
|
|
|
1
|
+
export const retryModule = {
|
|
2
|
+
name: 'retry',
|
|
3
|
+
language: 'typescript',
|
|
4
|
+
filePath: 'src/utils/retry.ts',
|
|
5
|
+
source: `export async function retry<T>(
|
|
6
|
+
fn: () => Promise<T>,
|
|
7
|
+
maxAttempts: number = 3,
|
|
8
|
+
delayMs: number = 1000,
|
|
9
|
+
): Promise<T> {
|
|
10
|
+
let lastError: Error | undefined;
|
|
11
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
12
|
+
try {
|
|
13
|
+
return await fn();
|
|
14
|
+
} catch (err) {
|
|
15
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
16
|
+
if (attempt < maxAttempts) {
|
|
17
|
+
await new Promise(r => setTimeout(r, delayMs * attempt));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
throw lastError;
|
|
22
|
+
}`,
|
|
23
|
+
description: 'Retry function with exponential backoff',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const loggerModule = {
|
|
27
|
+
name: 'logger',
|
|
28
|
+
language: 'typescript',
|
|
29
|
+
filePath: 'src/utils/logger.ts',
|
|
30
|
+
source: `import winston from 'winston';
|
|
31
|
+
|
|
32
|
+
export function createLogger(name: string, level: string = 'info') {
|
|
33
|
+
return winston.createLogger({
|
|
34
|
+
level,
|
|
35
|
+
format: winston.format.combine(
|
|
36
|
+
winston.format.timestamp(),
|
|
37
|
+
winston.format.printf(({ timestamp, level, message }) =>
|
|
38
|
+
\`[\${timestamp}] [\${level}] [\${name}] \${message}\`
|
|
39
|
+
),
|
|
40
|
+
),
|
|
41
|
+
transports: [new winston.transports.Console()],
|
|
42
|
+
});
|
|
43
|
+
}`,
|
|
44
|
+
description: 'Winston logger factory with timestamp formatting',
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const hashModule = {
|
|
48
|
+
name: 'hash',
|
|
49
|
+
language: 'python',
|
|
50
|
+
filePath: 'utils/hash.py',
|
|
51
|
+
source: `import hashlib
|
|
52
|
+
|
|
53
|
+
def sha256(data: str) -> str:
|
|
54
|
+
return hashlib.sha256(data.encode()).hexdigest()
|
|
55
|
+
|
|
56
|
+
def md5(data: str) -> str:
|
|
57
|
+
return hashlib.md5(data.encode()).hexdigest()
|
|
58
|
+
`,
|
|
59
|
+
description: 'Hash utility functions',
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export const similarRetryModule = {
|
|
63
|
+
name: 'retryWithBackoff',
|
|
64
|
+
language: 'typescript',
|
|
65
|
+
filePath: 'lib/retry-with-backoff.ts',
|
|
66
|
+
source: `export async function retryWithBackoff<T>(
|
|
67
|
+
operation: () => Promise<T>,
|
|
68
|
+
retries: number = 3,
|
|
69
|
+
baseDelay: number = 500,
|
|
70
|
+
): Promise<T> {
|
|
71
|
+
let error: Error | undefined;
|
|
72
|
+
for (let i = 0; i < retries; i++) {
|
|
73
|
+
try {
|
|
74
|
+
return await operation();
|
|
75
|
+
} catch (e) {
|
|
76
|
+
error = e instanceof Error ? e : new Error(String(e));
|
|
77
|
+
await new Promise(r => setTimeout(r, baseDelay * Math.pow(2, i)));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
throw error;
|
|
81
|
+
}`,
|
|
82
|
+
description: 'Retry with exponential backoff',
|
|
83
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const goCompileError = `./main.go:15:2: undefined: fmt.Prinln
|
|
2
|
+
./main.go:20:5: cannot use "hello" (untyped string constant) as int value in assignment`;
|
|
3
|
+
|
|
4
|
+
export const goPanicError = `goroutine 1 [running]:
|
|
5
|
+
main.main()
|
|
6
|
+
/app/main.go:12 +0x40
|
|
7
|
+
panic: runtime error: index out of range [5] with length 3`;
|
|
8
|
+
|
|
9
|
+
export const goTypeError = `./handler.go:25:15: cannot convert result (variable of type string) to type int`;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export const nodeTypeError = `TypeError: Cannot read properties of undefined (reading 'map')
|
|
2
|
+
at UserList (/app/src/components/UserList.tsx:15:23)
|
|
3
|
+
at renderWithHooks (/app/node_modules/react-dom/cjs/react-dom.development.js:14985:18)
|
|
4
|
+
at mountIndeterminateComponent (/app/node_modules/react-dom/cjs/react-dom.development.js:17811:13)`;
|
|
5
|
+
|
|
6
|
+
export const nodeModuleNotFound = `Error: Cannot find module './config'
|
|
7
|
+
Require stack:
|
|
8
|
+
- /app/src/server.ts
|
|
9
|
+
- /app/src/index.ts
|
|
10
|
+
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:995:15)
|
|
11
|
+
at Function.Module._load (node:internal/modules/cjs/loader:841:27)`;
|
|
12
|
+
|
|
13
|
+
export const nodeReferenceError = `ReferenceError: process is not defined
|
|
14
|
+
at Object.<anonymous> (/app/src/utils/env.ts:3:18)
|
|
15
|
+
at Module._compile (node:internal/modules/cjs/loader:1234:14)`;
|
|
16
|
+
|
|
17
|
+
export const nodeSyntaxError = `SyntaxError: Unexpected token '}'
|
|
18
|
+
at wrapSafe (node:internal/modules/cjs/loader:1278:20)
|
|
19
|
+
at Module._compile (node:internal/modules/cjs/loader:1320:27)
|
|
20
|
+
at /app/src/parser.ts:42:5`;
|
|
21
|
+
|
|
22
|
+
export const nodeEnoent = `Error: ENOENT: no such file or directory, open '/app/data/config.json'
|
|
23
|
+
at Object.openSync (node:fs:600:3)
|
|
24
|
+
at Object.readFileSync (node:fs:468:35)`;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export const pythonTraceback = `Traceback (most recent call last):
|
|
2
|
+
File "/app/main.py", line 42, in <module>
|
|
3
|
+
result = process_data(data)
|
|
4
|
+
File "/app/processor.py", line 15, in process_data
|
|
5
|
+
return data["key"]["nested"]
|
|
6
|
+
KeyError: 'nested'`;
|
|
7
|
+
|
|
8
|
+
export const pythonImportError = `Traceback (most recent call last):
|
|
9
|
+
File "/app/server.py", line 1, in <module>
|
|
10
|
+
from flask import Flask
|
|
11
|
+
ModuleNotFoundError: No module named 'flask'`;
|
|
12
|
+
|
|
13
|
+
export const pythonTypeError = `Traceback (most recent call last):
|
|
14
|
+
File "/app/calc.py", line 10, in compute
|
|
15
|
+
return x + y
|
|
16
|
+
TypeError: unsupported operand type(s) for +: 'int' and 'str'`;
|
|
17
|
+
|
|
18
|
+
export const pythonValueError = `Traceback (most recent call last):
|
|
19
|
+
File "/app/parser.py", line 25, in parse_int
|
|
20
|
+
return int(value)
|
|
21
|
+
ValueError: invalid literal for int() with base 10: 'abc'`;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const rustCompilerError = `error[E0308]: mismatched types
|
|
2
|
+
--> src/main.rs:10:5
|
|
3
|
+
|
|
|
4
|
+
9 | fn get_count() -> u32 {
|
|
5
|
+
| --- expected \`u32\` because of return type
|
|
6
|
+
10| "hello"
|
|
7
|
+
| ^^^^^^^ expected \`u32\`, found \`&str\``;
|
|
8
|
+
|
|
9
|
+
export const rustBorrowError = `error[E0502]: cannot borrow \`v\` as mutable because it is also borrowed as immutable
|
|
10
|
+
--> src/main.rs:6:5
|
|
11
|
+
|
|
|
12
|
+
4 | let first = &v[0];
|
|
13
|
+
| - immutable borrow occurs here
|
|
14
|
+
5 |
|
|
15
|
+
6 | v.push(4);
|
|
16
|
+
| ^^^^^^^^^ mutable borrow occurs here
|
|
17
|
+
7 |
|
|
18
|
+
8 | println!("{}", first);
|
|
19
|
+
| ----- immutable borrow later used here`;
|
|
20
|
+
|
|
21
|
+
export const rustLifetimeError = `error[E0106]: missing lifetime specifier
|
|
22
|
+
--> src/lib.rs:5:16
|
|
23
|
+
|
|
|
24
|
+
5 | fn longest(x: &str, y: &str) -> &str {
|
|
25
|
+
| ---- ---- ^ expected named lifetime parameter`;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const shellCommandNotFound = `bash: docker-compose: command not found`;
|
|
2
|
+
|
|
3
|
+
export const shellPermissionDenied = `bash: ./deploy.sh: Permission denied`;
|
|
4
|
+
|
|
5
|
+
export const npmError = `npm ERR! code ERESOLVE
|
|
6
|
+
npm ERR! ERESOLVE unable to resolve dependency tree
|
|
7
|
+
npm ERR!
|
|
8
|
+
npm ERR! While resolving: my-app@1.0.0
|
|
9
|
+
npm ERR! Found: react@18.2.0
|
|
10
|
+
npm ERR! node_modules/react
|
|
11
|
+
npm ERR! react@"^18.2.0" from the root project`;
|
|
12
|
+
|
|
13
|
+
export const buildFailed = `BUILD FAILED in 2.3s
|
|
14
|
+
Error: Module build failed (from ./node_modules/ts-loader/index.js):
|
|
15
|
+
Error: TypeScript compilation failed`;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export const solutionFixtures = [
|
|
2
|
+
{
|
|
3
|
+
description: 'Add null check before accessing .map() on potentially undefined array',
|
|
4
|
+
commands: '',
|
|
5
|
+
codeChange: 'const items = data?.items ?? [];\nconst mapped = items.map(fn);',
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
description: 'Install missing module with npm install',
|
|
9
|
+
commands: 'npm install flask',
|
|
10
|
+
codeChange: '',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
description: 'Fix type mismatch by converting string to number',
|
|
14
|
+
commands: '',
|
|
15
|
+
codeChange: 'return parseInt(value, 10);',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
description: 'Add missing lifetime annotation to function signature',
|
|
19
|
+
commands: '',
|
|
20
|
+
codeChange: "fn longest<'a>(x: &'a str, y: &'a str) -> &'a str {",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
description: 'Grant execute permission to script',
|
|
24
|
+
commands: 'chmod +x deploy.sh',
|
|
25
|
+
codeChange: '',
|
|
26
|
+
},
|
|
27
|
+
];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import Database from 'better-sqlite3';
|
|
2
|
+
import { runMigrations } from '../../src/db/migrations/index.js';
|
|
3
|
+
import { ProjectRepository } from '../../src/db/repositories/project.repository.js';
|
|
4
|
+
import { ErrorRepository } from '../../src/db/repositories/error.repository.js';
|
|
5
|
+
import { SolutionRepository } from '../../src/db/repositories/solution.repository.js';
|
|
6
|
+
import { RuleRepository } from '../../src/db/repositories/rule.repository.js';
|
|
7
|
+
import { AntipatternRepository } from '../../src/db/repositories/antipattern.repository.js';
|
|
8
|
+
import { TerminalRepository } from '../../src/db/repositories/terminal.repository.js';
|
|
9
|
+
import { CodeModuleRepository } from '../../src/db/repositories/code-module.repository.js';
|
|
10
|
+
import { SynapseRepository } from '../../src/db/repositories/synapse.repository.js';
|
|
11
|
+
import { NotificationRepository } from '../../src/db/repositories/notification.repository.js';
|
|
12
|
+
import { InsightRepository } from '../../src/db/repositories/insight.repository.js';
|
|
13
|
+
|
|
14
|
+
export interface TestDb {
|
|
15
|
+
db: Database.Database;
|
|
16
|
+
repos: {
|
|
17
|
+
project: ProjectRepository;
|
|
18
|
+
error: ErrorRepository;
|
|
19
|
+
solution: SolutionRepository;
|
|
20
|
+
rule: RuleRepository;
|
|
21
|
+
antipattern: AntipatternRepository;
|
|
22
|
+
terminal: TerminalRepository;
|
|
23
|
+
codeModule: CodeModuleRepository;
|
|
24
|
+
synapse: SynapseRepository;
|
|
25
|
+
notification: NotificationRepository;
|
|
26
|
+
insight: InsightRepository;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function createTestDb(): TestDb {
|
|
31
|
+
const db = new Database(':memory:');
|
|
32
|
+
db.pragma('journal_mode = WAL');
|
|
33
|
+
db.pragma('foreign_keys = ON');
|
|
34
|
+
|
|
35
|
+
runMigrations(db);
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
db,
|
|
39
|
+
repos: {
|
|
40
|
+
project: new ProjectRepository(db),
|
|
41
|
+
error: new ErrorRepository(db),
|
|
42
|
+
solution: new SolutionRepository(db),
|
|
43
|
+
rule: new RuleRepository(db),
|
|
44
|
+
antipattern: new AntipatternRepository(db),
|
|
45
|
+
terminal: new TerminalRepository(db),
|
|
46
|
+
codeModule: new CodeModuleRepository(db),
|
|
47
|
+
synapse: new SynapseRepository(db),
|
|
48
|
+
notification: new NotificationRepository(db),
|
|
49
|
+
insight: new InsightRepository(db),
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { createTestDb, type TestDb } from '../helpers/setup-db.js';
|
|
3
|
+
import { CodeService } from '../../src/services/code.service.js';
|
|
4
|
+
import { SynapseManager } from '../../src/synapses/synapse-manager.js';
|
|
5
|
+
import { retryModule, hashModule } from '../fixtures/code-modules/modules.js';
|
|
6
|
+
|
|
7
|
+
const synapsesConfig = {
|
|
8
|
+
initialWeight: 0.1,
|
|
9
|
+
learningRate: 0.15,
|
|
10
|
+
decayHalfLifeDays: 45,
|
|
11
|
+
pruneThreshold: 0.05,
|
|
12
|
+
decayAfterDays: 14,
|
|
13
|
+
maxDepth: 3,
|
|
14
|
+
minActivationWeight: 0.2,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
describe('Code Flow Integration', () => {
|
|
18
|
+
let testDb: TestDb;
|
|
19
|
+
let codeService: CodeService;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
testDb = createTestDb();
|
|
23
|
+
const synapseManager = new SynapseManager(testDb.repos.synapse, synapsesConfig);
|
|
24
|
+
codeService = new CodeService(testDb.repos.codeModule, testDb.repos.project, synapseManager);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('registers a code module and retrieves it', () => {
|
|
28
|
+
const result = codeService.analyzeAndRegister({
|
|
29
|
+
project: 'utils-lib',
|
|
30
|
+
name: retryModule.name,
|
|
31
|
+
filePath: retryModule.filePath,
|
|
32
|
+
language: retryModule.language,
|
|
33
|
+
source: retryModule.source,
|
|
34
|
+
description: retryModule.description,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
expect(result.moduleId).toBeTruthy();
|
|
38
|
+
expect(result.isNew).toBe(true);
|
|
39
|
+
expect(result.reusabilityScore).toBeGreaterThan(0);
|
|
40
|
+
|
|
41
|
+
const mod = codeService.getById(result.moduleId);
|
|
42
|
+
expect(mod).toBeTruthy();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('finds reusable modules by query', () => {
|
|
46
|
+
codeService.analyzeAndRegister({
|
|
47
|
+
project: 'utils-lib',
|
|
48
|
+
name: retryModule.name,
|
|
49
|
+
filePath: retryModule.filePath,
|
|
50
|
+
language: retryModule.language,
|
|
51
|
+
source: retryModule.source,
|
|
52
|
+
description: retryModule.description,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const results = codeService.findReusable({ query: 'retry backoff' });
|
|
56
|
+
// FTS matching may or may not find results
|
|
57
|
+
expect(results).toBeDefined();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('lists all modules', () => {
|
|
61
|
+
codeService.analyzeAndRegister({
|
|
62
|
+
project: 'project-a',
|
|
63
|
+
name: retryModule.name,
|
|
64
|
+
filePath: retryModule.filePath,
|
|
65
|
+
language: retryModule.language,
|
|
66
|
+
source: retryModule.source,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// listModules requires a projectId — project is created with id=1 by analyzeAndRegister
|
|
70
|
+
const modules = codeService.listModules(1);
|
|
71
|
+
expect(modules.length).toBe(1);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('detects similar code', () => {
|
|
75
|
+
codeService.analyzeAndRegister({
|
|
76
|
+
project: 'project-a',
|
|
77
|
+
name: retryModule.name,
|
|
78
|
+
filePath: retryModule.filePath,
|
|
79
|
+
language: retryModule.language,
|
|
80
|
+
source: retryModule.source,
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const similarities = codeService.checkSimilarity(retryModule.source, 'typescript');
|
|
84
|
+
expect(similarities).toBeDefined();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { createTestDb, type TestDb } from '../helpers/setup-db.js';
|
|
3
|
+
import { ErrorService } from '../../src/services/error.service.js';
|
|
4
|
+
import { SolutionService } from '../../src/services/solution.service.js';
|
|
5
|
+
import { SynapseManager } from '../../src/synapses/synapse-manager.js';
|
|
6
|
+
|
|
7
|
+
const synapsesConfig = {
|
|
8
|
+
initialWeight: 0.1,
|
|
9
|
+
learningRate: 0.15,
|
|
10
|
+
decayHalfLifeDays: 45,
|
|
11
|
+
pruneThreshold: 0.05,
|
|
12
|
+
decayAfterDays: 14,
|
|
13
|
+
maxDepth: 3,
|
|
14
|
+
minActivationWeight: 0.2,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
describe('Error Flow Integration', () => {
|
|
18
|
+
let testDb: TestDb;
|
|
19
|
+
let errorService: ErrorService;
|
|
20
|
+
let solutionService: SolutionService;
|
|
21
|
+
let synapseManager: SynapseManager;
|
|
22
|
+
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
testDb = createTestDb();
|
|
25
|
+
synapseManager = new SynapseManager(testDb.repos.synapse, synapsesConfig);
|
|
26
|
+
errorService = new ErrorService(testDb.repos.error, testDb.repos.project, synapseManager);
|
|
27
|
+
solutionService = new SolutionService(testDb.repos.solution, synapseManager);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('reports error and queries it back', () => {
|
|
31
|
+
const result = errorService.report({
|
|
32
|
+
project: 'test-project',
|
|
33
|
+
errorOutput: "TypeError: Cannot read properties of undefined (reading 'map')",
|
|
34
|
+
});
|
|
35
|
+
expect(result.errorId).toBeTruthy();
|
|
36
|
+
expect(result.isNew).toBe(true);
|
|
37
|
+
|
|
38
|
+
const errors = errorService.query({ resolved: false });
|
|
39
|
+
expect(errors.length).toBe(1);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('adds and finds solutions for errors', () => {
|
|
43
|
+
const errResult = errorService.report({
|
|
44
|
+
project: 'test-project',
|
|
45
|
+
errorOutput: "TypeError: Cannot read properties of undefined",
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const solutionId = solutionService.report({
|
|
49
|
+
errorId: errResult.errorId,
|
|
50
|
+
description: 'Add null check before accessing .map()',
|
|
51
|
+
});
|
|
52
|
+
expect(solutionId).toBeTruthy();
|
|
53
|
+
|
|
54
|
+
const solutions = solutionService.findForError(errResult.errorId);
|
|
55
|
+
expect(solutions.length).toBeGreaterThanOrEqual(0); // may need error_solution join
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('matches similar errors', () => {
|
|
59
|
+
const first = errorService.report({
|
|
60
|
+
project: 'project-a',
|
|
61
|
+
errorOutput: "TypeError: Cannot read properties of undefined (reading 'map')",
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const second = errorService.report({
|
|
65
|
+
project: 'project-a',
|
|
66
|
+
errorOutput: "TypeError: Cannot read properties of undefined (reading 'filter')",
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const matches = errorService.matchSimilar(second.errorId);
|
|
70
|
+
expect(matches).toBeDefined();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('creates project on first error report', () => {
|
|
74
|
+
errorService.report({
|
|
75
|
+
project: 'new-project',
|
|
76
|
+
errorOutput: 'Error: something broke',
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const projects = testDb.repos.project.getAll();
|
|
80
|
+
expect(projects.length).toBe(1);
|
|
81
|
+
expect(projects[0].name).toBe('new-project');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import { encodeMessage, MessageDecoder } from '../../src/ipc/protocol.js';
|
|
3
|
+
import type { IpcMessage } from '../../src/types/ipc.types.js';
|
|
4
|
+
|
|
5
|
+
describe('IPC Protocol', () => {
|
|
6
|
+
it('round-trips a request message', () => {
|
|
7
|
+
const msg: IpcMessage = {
|
|
8
|
+
id: 'test-123',
|
|
9
|
+
type: 'request',
|
|
10
|
+
method: 'error.report',
|
|
11
|
+
params: { project: 'test', errorOutput: 'Error: something' },
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const encoded = encodeMessage(msg);
|
|
15
|
+
const decoder = new MessageDecoder();
|
|
16
|
+
const decoded = decoder.feed(encoded);
|
|
17
|
+
|
|
18
|
+
expect(decoded.length).toBe(1);
|
|
19
|
+
expect(decoded[0].id).toBe('test-123');
|
|
20
|
+
expect(decoded[0].type).toBe('request');
|
|
21
|
+
expect(decoded[0].method).toBe('error.report');
|
|
22
|
+
expect(decoded[0].params).toEqual(msg.params);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('round-trips a response message', () => {
|
|
26
|
+
const msg: IpcMessage = {
|
|
27
|
+
id: 'test-456',
|
|
28
|
+
type: 'response',
|
|
29
|
+
result: { errorId: 42, isNew: true },
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const encoded = encodeMessage(msg);
|
|
33
|
+
const decoder = new MessageDecoder();
|
|
34
|
+
const decoded = decoder.feed(encoded);
|
|
35
|
+
|
|
36
|
+
expect(decoded.length).toBe(1);
|
|
37
|
+
expect(decoded[0].result).toEqual({ errorId: 42, isNew: true });
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('round-trips an error response', () => {
|
|
41
|
+
const msg: IpcMessage = {
|
|
42
|
+
id: 'test-789',
|
|
43
|
+
type: 'response',
|
|
44
|
+
error: { code: -1, message: 'Unknown method' },
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const encoded = encodeMessage(msg);
|
|
48
|
+
const decoder = new MessageDecoder();
|
|
49
|
+
const decoded = decoder.feed(encoded);
|
|
50
|
+
|
|
51
|
+
expect(decoded[0].error?.code).toBe(-1);
|
|
52
|
+
expect(decoded[0].error?.message).toBe('Unknown method');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('handles multiple messages in one feed', () => {
|
|
56
|
+
const msg1: IpcMessage = { id: '1', type: 'request', method: 'a' };
|
|
57
|
+
const msg2: IpcMessage = { id: '2', type: 'request', method: 'b' };
|
|
58
|
+
|
|
59
|
+
const buf = Buffer.concat([encodeMessage(msg1), encodeMessage(msg2)]);
|
|
60
|
+
const decoder = new MessageDecoder();
|
|
61
|
+
const decoded = decoder.feed(buf);
|
|
62
|
+
|
|
63
|
+
expect(decoded.length).toBe(2);
|
|
64
|
+
expect(decoded[0].id).toBe('1');
|
|
65
|
+
expect(decoded[1].id).toBe('2');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('handles partial messages across feeds', () => {
|
|
69
|
+
const msg: IpcMessage = { id: 'partial', type: 'request', method: 'test' };
|
|
70
|
+
const encoded = encodeMessage(msg);
|
|
71
|
+
|
|
72
|
+
const decoder = new MessageDecoder();
|
|
73
|
+
// Split buffer in half
|
|
74
|
+
const mid = Math.floor(encoded.length / 2);
|
|
75
|
+
const part1 = encoded.subarray(0, mid);
|
|
76
|
+
const part2 = encoded.subarray(mid);
|
|
77
|
+
|
|
78
|
+
const decoded1 = decoder.feed(part1);
|
|
79
|
+
expect(decoded1.length).toBe(0); // incomplete
|
|
80
|
+
|
|
81
|
+
const decoded2 = decoder.feed(part2);
|
|
82
|
+
expect(decoded2.length).toBe(1);
|
|
83
|
+
expect(decoded2[0].id).toBe('partial');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('decoder reset clears buffer', () => {
|
|
87
|
+
const msg: IpcMessage = { id: 'x', type: 'request', method: 'y' };
|
|
88
|
+
const encoded = encodeMessage(msg);
|
|
89
|
+
const partial = encoded.subarray(0, 5);
|
|
90
|
+
|
|
91
|
+
const decoder = new MessageDecoder();
|
|
92
|
+
decoder.feed(partial);
|
|
93
|
+
decoder.reset();
|
|
94
|
+
|
|
95
|
+
// After reset, feeding a complete message should work
|
|
96
|
+
const decoded = decoder.feed(encodeMessage(msg));
|
|
97
|
+
expect(decoded.length).toBe(1);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe('IPC Router', () => {
|
|
102
|
+
it('routes methods to services', async () => {
|
|
103
|
+
const { createTestDb } = await import('../helpers/setup-db.js');
|
|
104
|
+
const { IpcRouter } = await import('../../src/ipc/router.js');
|
|
105
|
+
const { ErrorService } = await import('../../src/services/error.service.js');
|
|
106
|
+
const { SolutionService } = await import('../../src/services/solution.service.js');
|
|
107
|
+
const { TerminalService } = await import('../../src/services/terminal.service.js');
|
|
108
|
+
const { PreventionService } = await import('../../src/services/prevention.service.js');
|
|
109
|
+
const { CodeService } = await import('../../src/services/code.service.js');
|
|
110
|
+
const { SynapseService } = await import('../../src/services/synapse.service.js');
|
|
111
|
+
const { ResearchService } = await import('../../src/services/research.service.js');
|
|
112
|
+
const { NotificationService } = await import('../../src/services/notification.service.js');
|
|
113
|
+
const { AnalyticsService } = await import('../../src/services/analytics.service.js');
|
|
114
|
+
const { SynapseManager } = await import('../../src/synapses/synapse-manager.js');
|
|
115
|
+
|
|
116
|
+
const testDb = createTestDb();
|
|
117
|
+
const synapsesConfig = {
|
|
118
|
+
initialWeight: 0.1, learningRate: 0.15, decayHalfLifeDays: 45,
|
|
119
|
+
pruneThreshold: 0.05, decayAfterDays: 14, maxDepth: 3, minActivationWeight: 0.2,
|
|
120
|
+
};
|
|
121
|
+
const sm = new SynapseManager(testDb.repos.synapse, synapsesConfig);
|
|
122
|
+
|
|
123
|
+
const services = {
|
|
124
|
+
error: new ErrorService(testDb.repos.error, testDb.repos.project, sm),
|
|
125
|
+
solution: new SolutionService(testDb.repos.solution, sm),
|
|
126
|
+
terminal: new TerminalService(testDb.repos.terminal, 300000),
|
|
127
|
+
prevention: new PreventionService(testDb.repos.rule, testDb.repos.antipattern, sm),
|
|
128
|
+
code: new CodeService(testDb.repos.codeModule, testDb.repos.project, sm),
|
|
129
|
+
synapse: new SynapseService(sm),
|
|
130
|
+
research: new ResearchService(testDb.repos.insight, testDb.repos.error, sm),
|
|
131
|
+
notification: new NotificationService(testDb.repos.notification),
|
|
132
|
+
analytics: new AnalyticsService(
|
|
133
|
+
testDb.repos.error, testDb.repos.solution, testDb.repos.codeModule,
|
|
134
|
+
testDb.repos.rule, testDb.repos.antipattern, testDb.repos.insight, sm,
|
|
135
|
+
),
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const router = new IpcRouter(services);
|
|
139
|
+
|
|
140
|
+
// Test analytics.summary
|
|
141
|
+
const summary = router.handle('analytics.summary', {});
|
|
142
|
+
expect(summary).toBeTruthy();
|
|
143
|
+
|
|
144
|
+
// Test synapse.stats
|
|
145
|
+
const stats = router.handle('synapse.stats', {});
|
|
146
|
+
expect(stats).toBeTruthy();
|
|
147
|
+
|
|
148
|
+
// Test error.report
|
|
149
|
+
const result = router.handle('error.report', {
|
|
150
|
+
project: 'test',
|
|
151
|
+
errorOutput: 'Error: test error',
|
|
152
|
+
}) as any;
|
|
153
|
+
expect(result.errorId).toBeTruthy();
|
|
154
|
+
|
|
155
|
+
// Test unknown method throws
|
|
156
|
+
expect(() => router.handle('nonexistent.method', {})).toThrow('Unknown method');
|
|
157
|
+
|
|
158
|
+
// Test listMethods
|
|
159
|
+
const methods = router.listMethods();
|
|
160
|
+
expect(methods.length).toBeGreaterThan(20);
|
|
161
|
+
expect(methods).toContain('error.report');
|
|
162
|
+
expect(methods).toContain('analytics.summary');
|
|
163
|
+
|
|
164
|
+
testDb.db.close();
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { createTestDb, type TestDb } from '../helpers/setup-db.js';
|
|
3
|
+
import { LearningEngine } from '../../src/learning/learning-engine.js';
|
|
4
|
+
import { SynapseManager } from '../../src/synapses/synapse-manager.js';
|
|
5
|
+
|
|
6
|
+
const learningConfig = {
|
|
7
|
+
intervalMs: 900000,
|
|
8
|
+
minOccurrences: 3,
|
|
9
|
+
minSuccessRate: 0.7,
|
|
10
|
+
minConfidence: 0.6,
|
|
11
|
+
pruneThreshold: 0.2,
|
|
12
|
+
maxRejectionRate: 0.5,
|
|
13
|
+
decayHalfLifeDays: 30,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const synapsesConfig = {
|
|
17
|
+
initialWeight: 0.1,
|
|
18
|
+
learningRate: 0.15,
|
|
19
|
+
decayHalfLifeDays: 45,
|
|
20
|
+
pruneThreshold: 0.05,
|
|
21
|
+
decayAfterDays: 14,
|
|
22
|
+
maxDepth: 3,
|
|
23
|
+
minActivationWeight: 0.2,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
describe('Learning Cycle Integration', () => {
|
|
27
|
+
let testDb: TestDb;
|
|
28
|
+
let learningEngine: LearningEngine;
|
|
29
|
+
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
testDb = createTestDb();
|
|
32
|
+
const synapseManager = new SynapseManager(testDb.repos.synapse, synapsesConfig);
|
|
33
|
+
|
|
34
|
+
learningEngine = new LearningEngine(
|
|
35
|
+
learningConfig,
|
|
36
|
+
testDb.repos.error,
|
|
37
|
+
testDb.repos.solution,
|
|
38
|
+
testDb.repos.rule,
|
|
39
|
+
testDb.repos.antipattern,
|
|
40
|
+
synapseManager,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
// Seed data
|
|
44
|
+
testDb.repos.project.create({ name: 'test', path: '/test' } as any);
|
|
45
|
+
for (let i = 0; i < 5; i++) {
|
|
46
|
+
testDb.repos.error.create({
|
|
47
|
+
project_id: 1,
|
|
48
|
+
terminal_id: null,
|
|
49
|
+
type: 'TypeError',
|
|
50
|
+
message: "Cannot read properties of undefined (reading 'map')",
|
|
51
|
+
fingerprint: 'fp_type_error',
|
|
52
|
+
raw_output: `TypeError: Cannot read properties of undefined`,
|
|
53
|
+
context: null,
|
|
54
|
+
file_path: null,
|
|
55
|
+
line_number: null,
|
|
56
|
+
column_number: null,
|
|
57
|
+
} as any);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('runs a learning cycle without error', () => {
|
|
62
|
+
const result = learningEngine.runCycle();
|
|
63
|
+
expect(result).toBeTruthy();
|
|
64
|
+
expect(typeof result.newPatterns).toBe('number');
|
|
65
|
+
expect(typeof result.updatedRules).toBe('number');
|
|
66
|
+
expect(typeof result.prunedRules).toBe('number');
|
|
67
|
+
expect(typeof result.duration).toBe('number');
|
|
68
|
+
expect(result.duration).toBeGreaterThan(0);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('tracks last cycle time', () => {
|
|
72
|
+
expect(learningEngine.getLastCycleAt()).toBeNull();
|
|
73
|
+
learningEngine.runCycle();
|
|
74
|
+
expect(learningEngine.getLastCycleAt()).toBeTruthy();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('start/stop controls scheduling', () => {
|
|
78
|
+
learningEngine.start();
|
|
79
|
+
learningEngine.stop();
|
|
80
|
+
// Should not throw
|
|
81
|
+
});
|
|
82
|
+
});
|