@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,120 @@
|
|
|
1
|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
|
|
3
|
+
export function up(db: Database.Database): void {
|
|
4
|
+
db.exec(`
|
|
5
|
+
CREATE TABLE IF NOT EXISTS projects (
|
|
6
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
7
|
+
name TEXT NOT NULL UNIQUE,
|
|
8
|
+
path TEXT,
|
|
9
|
+
language TEXT,
|
|
10
|
+
framework TEXT,
|
|
11
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
12
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
CREATE TABLE IF NOT EXISTS terminals (
|
|
16
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
17
|
+
uuid TEXT NOT NULL UNIQUE,
|
|
18
|
+
project_id INTEGER,
|
|
19
|
+
pid INTEGER,
|
|
20
|
+
shell TEXT,
|
|
21
|
+
cwd TEXT,
|
|
22
|
+
connected_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
23
|
+
last_seen TEXT NOT NULL DEFAULT (datetime('now')),
|
|
24
|
+
disconnected_at TEXT,
|
|
25
|
+
FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE SET NULL
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
CREATE TABLE IF NOT EXISTS errors (
|
|
29
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
30
|
+
project_id INTEGER NOT NULL,
|
|
31
|
+
terminal_id INTEGER,
|
|
32
|
+
fingerprint TEXT NOT NULL,
|
|
33
|
+
type TEXT NOT NULL,
|
|
34
|
+
message TEXT NOT NULL,
|
|
35
|
+
raw_output TEXT NOT NULL,
|
|
36
|
+
context TEXT,
|
|
37
|
+
file_path TEXT,
|
|
38
|
+
line_number INTEGER,
|
|
39
|
+
column_number INTEGER,
|
|
40
|
+
occurrence_count INTEGER NOT NULL DEFAULT 1,
|
|
41
|
+
first_seen TEXT NOT NULL DEFAULT (datetime('now')),
|
|
42
|
+
last_seen TEXT NOT NULL DEFAULT (datetime('now')),
|
|
43
|
+
resolved INTEGER NOT NULL DEFAULT 0,
|
|
44
|
+
resolved_at TEXT,
|
|
45
|
+
FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE,
|
|
46
|
+
FOREIGN KEY (terminal_id) REFERENCES terminals(id) ON DELETE SET NULL
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
CREATE TABLE IF NOT EXISTS stack_frames (
|
|
50
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
51
|
+
error_id INTEGER NOT NULL,
|
|
52
|
+
frame_index INTEGER NOT NULL,
|
|
53
|
+
file TEXT NOT NULL,
|
|
54
|
+
line INTEGER NOT NULL,
|
|
55
|
+
"column" INTEGER,
|
|
56
|
+
function_name TEXT,
|
|
57
|
+
source TEXT,
|
|
58
|
+
FOREIGN KEY (error_id) REFERENCES errors(id) ON DELETE CASCADE
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
CREATE TABLE IF NOT EXISTS solutions (
|
|
62
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
63
|
+
description TEXT NOT NULL,
|
|
64
|
+
commands TEXT,
|
|
65
|
+
code_change TEXT,
|
|
66
|
+
source TEXT NOT NULL DEFAULT 'manual',
|
|
67
|
+
confidence REAL NOT NULL DEFAULT 0.5,
|
|
68
|
+
success_count INTEGER NOT NULL DEFAULT 0,
|
|
69
|
+
fail_count INTEGER NOT NULL DEFAULT 0,
|
|
70
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
71
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
CREATE TABLE IF NOT EXISTS error_solutions (
|
|
75
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
76
|
+
error_id INTEGER NOT NULL,
|
|
77
|
+
solution_id INTEGER NOT NULL,
|
|
78
|
+
applied_at TEXT,
|
|
79
|
+
success INTEGER,
|
|
80
|
+
FOREIGN KEY (error_id) REFERENCES errors(id) ON DELETE CASCADE,
|
|
81
|
+
FOREIGN KEY (solution_id) REFERENCES solutions(id) ON DELETE CASCADE,
|
|
82
|
+
UNIQUE(error_id, solution_id)
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
CREATE TABLE IF NOT EXISTS solution_attempts (
|
|
86
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
87
|
+
error_solution_id INTEGER NOT NULL,
|
|
88
|
+
terminal_id INTEGER,
|
|
89
|
+
attempted_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
90
|
+
success INTEGER NOT NULL DEFAULT 0,
|
|
91
|
+
output TEXT,
|
|
92
|
+
duration_ms INTEGER,
|
|
93
|
+
FOREIGN KEY (error_solution_id) REFERENCES error_solutions(id) ON DELETE CASCADE,
|
|
94
|
+
FOREIGN KEY (terminal_id) REFERENCES terminals(id) ON DELETE SET NULL
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
CREATE TABLE IF NOT EXISTS error_chains (
|
|
98
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
99
|
+
parent_error_id INTEGER NOT NULL,
|
|
100
|
+
child_error_id INTEGER NOT NULL,
|
|
101
|
+
relationship TEXT NOT NULL DEFAULT 'causes',
|
|
102
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
103
|
+
FOREIGN KEY (parent_error_id) REFERENCES errors(id) ON DELETE CASCADE,
|
|
104
|
+
FOREIGN KEY (child_error_id) REFERENCES errors(id) ON DELETE CASCADE,
|
|
105
|
+
UNIQUE(parent_error_id, child_error_id)
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
CREATE INDEX IF NOT EXISTS idx_errors_fingerprint ON errors(fingerprint);
|
|
109
|
+
CREATE INDEX IF NOT EXISTS idx_errors_project ON errors(project_id);
|
|
110
|
+
CREATE INDEX IF NOT EXISTS idx_errors_type ON errors(type);
|
|
111
|
+
CREATE INDEX IF NOT EXISTS idx_errors_resolved ON errors(resolved);
|
|
112
|
+
CREATE INDEX IF NOT EXISTS idx_errors_last_seen ON errors(last_seen);
|
|
113
|
+
CREATE INDEX IF NOT EXISTS idx_stack_frames_error ON stack_frames(error_id);
|
|
114
|
+
CREATE INDEX IF NOT EXISTS idx_error_solutions_error ON error_solutions(error_id);
|
|
115
|
+
CREATE INDEX IF NOT EXISTS idx_error_solutions_solution ON error_solutions(solution_id);
|
|
116
|
+
CREATE INDEX IF NOT EXISTS idx_solution_attempts_es ON solution_attempts(error_solution_id);
|
|
117
|
+
CREATE INDEX IF NOT EXISTS idx_terminals_uuid ON terminals(uuid);
|
|
118
|
+
CREATE INDEX IF NOT EXISTS idx_terminals_project ON terminals(project_id);
|
|
119
|
+
`);
|
|
120
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
|
|
3
|
+
export function up(db: Database.Database): void {
|
|
4
|
+
db.exec(`
|
|
5
|
+
CREATE TABLE IF NOT EXISTS rules (
|
|
6
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
7
|
+
pattern TEXT NOT NULL,
|
|
8
|
+
action TEXT NOT NULL,
|
|
9
|
+
description TEXT,
|
|
10
|
+
confidence REAL NOT NULL DEFAULT 0.5,
|
|
11
|
+
occurrences INTEGER NOT NULL DEFAULT 0,
|
|
12
|
+
active INTEGER NOT NULL DEFAULT 1,
|
|
13
|
+
project_id INTEGER,
|
|
14
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
15
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
16
|
+
FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE SET NULL
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
CREATE TABLE IF NOT EXISTS antipatterns (
|
|
20
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
21
|
+
pattern TEXT NOT NULL,
|
|
22
|
+
description TEXT NOT NULL,
|
|
23
|
+
severity TEXT NOT NULL DEFAULT 'warning',
|
|
24
|
+
suggestion TEXT,
|
|
25
|
+
occurrences INTEGER NOT NULL DEFAULT 0,
|
|
26
|
+
project_id INTEGER,
|
|
27
|
+
global INTEGER NOT NULL DEFAULT 0,
|
|
28
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
29
|
+
FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE SET NULL
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
CREATE INDEX IF NOT EXISTS idx_rules_pattern ON rules(pattern);
|
|
33
|
+
CREATE INDEX IF NOT EXISTS idx_rules_active ON rules(active);
|
|
34
|
+
CREATE INDEX IF NOT EXISTS idx_rules_project ON rules(project_id);
|
|
35
|
+
CREATE INDEX IF NOT EXISTS idx_antipatterns_project ON antipatterns(project_id);
|
|
36
|
+
CREATE INDEX IF NOT EXISTS idx_antipatterns_global ON antipatterns(global);
|
|
37
|
+
`);
|
|
38
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
|
|
3
|
+
export function up(db: Database.Database): void {
|
|
4
|
+
db.exec(`
|
|
5
|
+
CREATE TABLE IF NOT EXISTS code_modules (
|
|
6
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
7
|
+
project_id INTEGER NOT NULL,
|
|
8
|
+
name TEXT NOT NULL,
|
|
9
|
+
file_path TEXT NOT NULL,
|
|
10
|
+
language TEXT NOT NULL,
|
|
11
|
+
fingerprint TEXT NOT NULL,
|
|
12
|
+
description TEXT,
|
|
13
|
+
source_hash TEXT NOT NULL,
|
|
14
|
+
lines_of_code INTEGER NOT NULL DEFAULT 0,
|
|
15
|
+
complexity INTEGER,
|
|
16
|
+
reusability_score REAL NOT NULL DEFAULT 0.0,
|
|
17
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
18
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
19
|
+
FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
CREATE TABLE IF NOT EXISTS module_usages (
|
|
23
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
24
|
+
module_id INTEGER NOT NULL,
|
|
25
|
+
used_in_project_id INTEGER NOT NULL,
|
|
26
|
+
used_in_file TEXT NOT NULL,
|
|
27
|
+
usage_type TEXT NOT NULL DEFAULT 'import',
|
|
28
|
+
first_used TEXT NOT NULL DEFAULT (datetime('now')),
|
|
29
|
+
last_used TEXT NOT NULL DEFAULT (datetime('now')),
|
|
30
|
+
FOREIGN KEY (module_id) REFERENCES code_modules(id) ON DELETE CASCADE,
|
|
31
|
+
FOREIGN KEY (used_in_project_id) REFERENCES projects(id) ON DELETE CASCADE
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
CREATE TABLE IF NOT EXISTS module_similarities (
|
|
35
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
36
|
+
module_a_id INTEGER NOT NULL,
|
|
37
|
+
module_b_id INTEGER NOT NULL,
|
|
38
|
+
similarity_score REAL NOT NULL,
|
|
39
|
+
computed_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
40
|
+
FOREIGN KEY (module_a_id) REFERENCES code_modules(id) ON DELETE CASCADE,
|
|
41
|
+
FOREIGN KEY (module_b_id) REFERENCES code_modules(id) ON DELETE CASCADE,
|
|
42
|
+
UNIQUE(module_a_id, module_b_id)
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
CREATE INDEX IF NOT EXISTS idx_code_modules_project ON code_modules(project_id);
|
|
46
|
+
CREATE INDEX IF NOT EXISTS idx_code_modules_fingerprint ON code_modules(fingerprint);
|
|
47
|
+
CREATE INDEX IF NOT EXISTS idx_code_modules_language ON code_modules(language);
|
|
48
|
+
CREATE INDEX IF NOT EXISTS idx_module_usages_module ON module_usages(module_id);
|
|
49
|
+
CREATE INDEX IF NOT EXISTS idx_module_usages_project ON module_usages(used_in_project_id);
|
|
50
|
+
CREATE INDEX IF NOT EXISTS idx_module_similarities_a ON module_similarities(module_a_id);
|
|
51
|
+
CREATE INDEX IF NOT EXISTS idx_module_similarities_b ON module_similarities(module_b_id);
|
|
52
|
+
`);
|
|
53
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
|
|
3
|
+
export function up(db: Database.Database): void {
|
|
4
|
+
db.exec(`
|
|
5
|
+
CREATE TABLE IF NOT EXISTS synapses (
|
|
6
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
7
|
+
source_type TEXT NOT NULL,
|
|
8
|
+
source_id INTEGER NOT NULL,
|
|
9
|
+
target_type TEXT NOT NULL,
|
|
10
|
+
target_id INTEGER NOT NULL,
|
|
11
|
+
synapse_type TEXT NOT NULL,
|
|
12
|
+
weight REAL NOT NULL DEFAULT 0.5,
|
|
13
|
+
metadata TEXT,
|
|
14
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
15
|
+
updated_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
16
|
+
UNIQUE(source_type, source_id, target_type, target_id, synapse_type)
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
CREATE TABLE IF NOT EXISTS insights (
|
|
20
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
21
|
+
type TEXT NOT NULL,
|
|
22
|
+
title TEXT NOT NULL,
|
|
23
|
+
description TEXT NOT NULL,
|
|
24
|
+
evidence TEXT NOT NULL DEFAULT '[]',
|
|
25
|
+
priority INTEGER NOT NULL DEFAULT 0,
|
|
26
|
+
project_id INTEGER,
|
|
27
|
+
active INTEGER NOT NULL DEFAULT 1,
|
|
28
|
+
expires_at TEXT,
|
|
29
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
30
|
+
FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE SET NULL
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
CREATE TABLE IF NOT EXISTS notifications (
|
|
34
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
35
|
+
type TEXT NOT NULL,
|
|
36
|
+
title TEXT NOT NULL,
|
|
37
|
+
message TEXT NOT NULL,
|
|
38
|
+
priority INTEGER NOT NULL DEFAULT 0,
|
|
39
|
+
project_id INTEGER,
|
|
40
|
+
acknowledged INTEGER NOT NULL DEFAULT 0,
|
|
41
|
+
acknowledged_at TEXT,
|
|
42
|
+
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
|
43
|
+
FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE SET NULL
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
CREATE INDEX IF NOT EXISTS idx_synapses_source ON synapses(source_type, source_id);
|
|
47
|
+
CREATE INDEX IF NOT EXISTS idx_synapses_target ON synapses(target_type, target_id);
|
|
48
|
+
CREATE INDEX IF NOT EXISTS idx_synapses_type ON synapses(synapse_type);
|
|
49
|
+
CREATE INDEX IF NOT EXISTS idx_synapses_weight ON synapses(weight);
|
|
50
|
+
CREATE INDEX IF NOT EXISTS idx_insights_type ON insights(type);
|
|
51
|
+
CREATE INDEX IF NOT EXISTS idx_insights_project ON insights(project_id);
|
|
52
|
+
CREATE INDEX IF NOT EXISTS idx_insights_active ON insights(active);
|
|
53
|
+
CREATE INDEX IF NOT EXISTS idx_insights_priority ON insights(priority);
|
|
54
|
+
CREATE INDEX IF NOT EXISTS idx_notifications_acknowledged ON notifications(acknowledged);
|
|
55
|
+
CREATE INDEX IF NOT EXISTS idx_notifications_project ON notifications(project_id);
|
|
56
|
+
`);
|
|
57
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
|
|
3
|
+
export function up(db: Database.Database): void {
|
|
4
|
+
db.exec(`
|
|
5
|
+
-- Full-text search for errors
|
|
6
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS errors_fts USING fts5(
|
|
7
|
+
type, message, raw_output, context, file_path,
|
|
8
|
+
content='errors',
|
|
9
|
+
content_rowid='id'
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
-- Sync triggers for errors_fts
|
|
13
|
+
CREATE TRIGGER IF NOT EXISTS errors_ai AFTER INSERT ON errors BEGIN
|
|
14
|
+
INSERT INTO errors_fts(rowid, type, message, raw_output, context, file_path)
|
|
15
|
+
VALUES (new.id, new.type, new.message, new.raw_output, new.context, new.file_path);
|
|
16
|
+
END;
|
|
17
|
+
|
|
18
|
+
CREATE TRIGGER IF NOT EXISTS errors_ad AFTER DELETE ON errors BEGIN
|
|
19
|
+
INSERT INTO errors_fts(errors_fts, rowid, type, message, raw_output, context, file_path)
|
|
20
|
+
VALUES ('delete', old.id, old.type, old.message, old.raw_output, old.context, old.file_path);
|
|
21
|
+
END;
|
|
22
|
+
|
|
23
|
+
CREATE TRIGGER IF NOT EXISTS errors_au AFTER UPDATE ON errors BEGIN
|
|
24
|
+
INSERT INTO errors_fts(errors_fts, rowid, type, message, raw_output, context, file_path)
|
|
25
|
+
VALUES ('delete', old.id, old.type, old.message, old.raw_output, old.context, old.file_path);
|
|
26
|
+
INSERT INTO errors_fts(rowid, type, message, raw_output, context, file_path)
|
|
27
|
+
VALUES (new.id, new.type, new.message, new.raw_output, new.context, new.file_path);
|
|
28
|
+
END;
|
|
29
|
+
|
|
30
|
+
-- Full-text search for solutions
|
|
31
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS solutions_fts USING fts5(
|
|
32
|
+
description, commands, code_change,
|
|
33
|
+
content='solutions',
|
|
34
|
+
content_rowid='id'
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
CREATE TRIGGER IF NOT EXISTS solutions_ai AFTER INSERT ON solutions BEGIN
|
|
38
|
+
INSERT INTO solutions_fts(rowid, description, commands, code_change)
|
|
39
|
+
VALUES (new.id, new.description, new.commands, new.code_change);
|
|
40
|
+
END;
|
|
41
|
+
|
|
42
|
+
CREATE TRIGGER IF NOT EXISTS solutions_ad AFTER DELETE ON solutions BEGIN
|
|
43
|
+
INSERT INTO solutions_fts(solutions_fts, rowid, description, commands, code_change)
|
|
44
|
+
VALUES ('delete', old.id, old.description, old.commands, old.code_change);
|
|
45
|
+
END;
|
|
46
|
+
|
|
47
|
+
CREATE TRIGGER IF NOT EXISTS solutions_au AFTER UPDATE ON solutions BEGIN
|
|
48
|
+
INSERT INTO solutions_fts(solutions_fts, rowid, description, commands, code_change)
|
|
49
|
+
VALUES ('delete', old.id, old.description, old.commands, old.code_change);
|
|
50
|
+
INSERT INTO solutions_fts(rowid, description, commands, code_change)
|
|
51
|
+
VALUES (new.id, new.description, new.commands, new.code_change);
|
|
52
|
+
END;
|
|
53
|
+
|
|
54
|
+
-- Full-text search for code modules
|
|
55
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS code_modules_fts USING fts5(
|
|
56
|
+
name, file_path, description, language,
|
|
57
|
+
content='code_modules',
|
|
58
|
+
content_rowid='id'
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
CREATE TRIGGER IF NOT EXISTS code_modules_ai AFTER INSERT ON code_modules BEGIN
|
|
62
|
+
INSERT INTO code_modules_fts(rowid, name, file_path, description, language)
|
|
63
|
+
VALUES (new.id, new.name, new.file_path, new.description, new.language);
|
|
64
|
+
END;
|
|
65
|
+
|
|
66
|
+
CREATE TRIGGER IF NOT EXISTS code_modules_ad AFTER DELETE ON code_modules BEGIN
|
|
67
|
+
INSERT INTO code_modules_fts(code_modules_fts, rowid, name, file_path, description, language)
|
|
68
|
+
VALUES ('delete', old.id, old.name, old.file_path, old.description, old.language);
|
|
69
|
+
END;
|
|
70
|
+
|
|
71
|
+
CREATE TRIGGER IF NOT EXISTS code_modules_au AFTER UPDATE ON code_modules BEGIN
|
|
72
|
+
INSERT INTO code_modules_fts(code_modules_fts, rowid, name, file_path, description, language)
|
|
73
|
+
VALUES ('delete', old.id, old.name, old.file_path, old.description, old.language);
|
|
74
|
+
INSERT INTO code_modules_fts(rowid, name, file_path, description, language)
|
|
75
|
+
VALUES (new.id, new.name, new.file_path, new.description, new.language);
|
|
76
|
+
END;
|
|
77
|
+
`);
|
|
78
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
|
|
3
|
+
export function up(db: Database.Database): void {
|
|
4
|
+
// Add activation_count and last_activated_at columns
|
|
5
|
+
const columns = db.pragma('table_info(synapses)') as Array<{ name: string }>;
|
|
6
|
+
const colNames = columns.map(c => c.name);
|
|
7
|
+
|
|
8
|
+
if (!colNames.includes('activation_count')) {
|
|
9
|
+
db.exec(`ALTER TABLE synapses ADD COLUMN activation_count INTEGER NOT NULL DEFAULT 1`);
|
|
10
|
+
}
|
|
11
|
+
if (!colNames.includes('last_activated_at')) {
|
|
12
|
+
db.exec(`ALTER TABLE synapses ADD COLUMN last_activated_at TEXT NOT NULL DEFAULT (datetime('now'))`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Add index for decay queries
|
|
16
|
+
db.exec(`CREATE INDEX IF NOT EXISTS idx_synapses_last_activated ON synapses(last_activated_at)`);
|
|
17
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
import { getLogger } from '../../utils/logger.js';
|
|
3
|
+
import { up as coreSchema } from './001_core_schema.js';
|
|
4
|
+
import { up as learningSchema } from './002_learning_schema.js';
|
|
5
|
+
import { up as codeSchema } from './003_code_schema.js';
|
|
6
|
+
import { up as synapsesSchema } from './004_synapses_schema.js';
|
|
7
|
+
import { up as ftsIndexes } from './005_fts_indexes.js';
|
|
8
|
+
import { up as synapsesPhase3 } from './006_synapses_phase3.js';
|
|
9
|
+
|
|
10
|
+
interface Migration {
|
|
11
|
+
version: number;
|
|
12
|
+
name: string;
|
|
13
|
+
up: (db: Database.Database) => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const migrations: Migration[] = [
|
|
17
|
+
{ version: 1, name: '001_core_schema', up: coreSchema },
|
|
18
|
+
{ version: 2, name: '002_learning_schema', up: learningSchema },
|
|
19
|
+
{ version: 3, name: '003_code_schema', up: codeSchema },
|
|
20
|
+
{ version: 4, name: '004_synapses_schema', up: synapsesSchema },
|
|
21
|
+
{ version: 5, name: '005_fts_indexes', up: ftsIndexes },
|
|
22
|
+
{ version: 6, name: '006_synapses_phase3', up: synapsesPhase3 },
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
function ensureMigrationsTable(db: Database.Database): void {
|
|
26
|
+
db.exec(`
|
|
27
|
+
CREATE TABLE IF NOT EXISTS migrations (
|
|
28
|
+
version INTEGER PRIMARY KEY,
|
|
29
|
+
name TEXT NOT NULL,
|
|
30
|
+
applied_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
31
|
+
);
|
|
32
|
+
`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getCurrentVersion(db: Database.Database): number {
|
|
36
|
+
const row = db.prepare('SELECT MAX(version) as version FROM migrations').get() as { version: number | null } | undefined;
|
|
37
|
+
return row?.version ?? 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function runMigrations(db: Database.Database): void {
|
|
41
|
+
const logger = getLogger();
|
|
42
|
+
ensureMigrationsTable(db);
|
|
43
|
+
|
|
44
|
+
const currentVersion = getCurrentVersion(db);
|
|
45
|
+
const pending = migrations.filter(m => m.version > currentVersion);
|
|
46
|
+
|
|
47
|
+
if (pending.length === 0) {
|
|
48
|
+
logger.info('Database is up to date');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
logger.info(`Running ${pending.length} migration(s) from version ${currentVersion}`);
|
|
53
|
+
|
|
54
|
+
const runAll = db.transaction(() => {
|
|
55
|
+
for (const migration of pending) {
|
|
56
|
+
logger.info(`Applying migration ${migration.name}`);
|
|
57
|
+
migration.up(db);
|
|
58
|
+
db.prepare('INSERT INTO migrations (version, name) VALUES (?, ?)').run(migration.version, migration.name);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
runAll();
|
|
63
|
+
logger.info(`Migrations complete. Now at version ${pending[pending.length - 1]!.version}`);
|
|
64
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
import type { Statement } from 'better-sqlite3';
|
|
3
|
+
|
|
4
|
+
export interface AntipatternRecord {
|
|
5
|
+
id: number;
|
|
6
|
+
pattern: string;
|
|
7
|
+
description: string;
|
|
8
|
+
severity: string;
|
|
9
|
+
suggestion: string | null;
|
|
10
|
+
occurrences: number;
|
|
11
|
+
project_id: number | null;
|
|
12
|
+
global: number;
|
|
13
|
+
created_at: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type AntipatternCreate = Omit<AntipatternRecord, 'id' | 'created_at'>;
|
|
17
|
+
type AntipatternUpdate = Partial<Omit<AntipatternRecord, 'id' | 'created_at'>>;
|
|
18
|
+
|
|
19
|
+
export class AntipatternRepository {
|
|
20
|
+
private stmts: Record<string, Statement>;
|
|
21
|
+
|
|
22
|
+
constructor(private db: Database.Database) {
|
|
23
|
+
this.stmts = {
|
|
24
|
+
create: db.prepare(`
|
|
25
|
+
INSERT INTO antipatterns (pattern, description, severity, suggestion, occurrences, project_id, global)
|
|
26
|
+
VALUES (@pattern, @description, @severity, @suggestion, @occurrences, @project_id, @global)
|
|
27
|
+
`),
|
|
28
|
+
getById: db.prepare('SELECT * FROM antipatterns WHERE id = ?'),
|
|
29
|
+
delete: db.prepare('DELETE FROM antipatterns WHERE id = ?'),
|
|
30
|
+
findByProject: db.prepare('SELECT * FROM antipatterns WHERE project_id = ? ORDER BY occurrences DESC'),
|
|
31
|
+
findGlobal: db.prepare('SELECT * FROM antipatterns WHERE global = 1 ORDER BY occurrences DESC'),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
create(data: AntipatternCreate): number {
|
|
36
|
+
const result = this.stmts.create.run(data);
|
|
37
|
+
return result.lastInsertRowid as number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getById(id: number): AntipatternRecord | undefined {
|
|
41
|
+
return this.stmts.getById.get(id) as AntipatternRecord | undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
update(id: number, data: AntipatternUpdate): boolean {
|
|
45
|
+
const fields = Object.keys(data).filter((key) => (data as Record<string, unknown>)[key] !== undefined);
|
|
46
|
+
if (fields.length === 0) return false;
|
|
47
|
+
|
|
48
|
+
const setClauses = fields.map((field) => `${field} = @${field}`).join(', ');
|
|
49
|
+
const stmt = this.db.prepare(`UPDATE antipatterns SET ${setClauses} WHERE id = @id`);
|
|
50
|
+
const result = stmt.run({ ...data, id });
|
|
51
|
+
return result.changes > 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
delete(id: number): boolean {
|
|
55
|
+
const result = this.stmts.delete.run(id);
|
|
56
|
+
return result.changes > 0;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
findByProject(projectId: number): AntipatternRecord[] {
|
|
60
|
+
return this.stmts.findByProject.all(projectId) as AntipatternRecord[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
findGlobal(): AntipatternRecord[] {
|
|
64
|
+
return this.stmts.findGlobal.all() as AntipatternRecord[];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type Database from 'better-sqlite3';
|
|
2
|
+
import type { Statement } from 'better-sqlite3';
|
|
3
|
+
import type { CodeModuleRecord } from '../../types/code.types.js';
|
|
4
|
+
|
|
5
|
+
type CodeModuleCreate = Omit<CodeModuleRecord, 'id' | 'created_at' | 'updated_at'>;
|
|
6
|
+
type CodeModuleUpdate = Partial<Omit<CodeModuleRecord, 'id' | 'created_at'>>;
|
|
7
|
+
|
|
8
|
+
export class CodeModuleRepository {
|
|
9
|
+
private stmts: Record<string, Statement>;
|
|
10
|
+
|
|
11
|
+
constructor(private db: Database.Database) {
|
|
12
|
+
this.stmts = {
|
|
13
|
+
create: db.prepare(`
|
|
14
|
+
INSERT INTO code_modules (project_id, name, file_path, language, fingerprint, description, source_hash, lines_of_code, complexity, reusability_score)
|
|
15
|
+
VALUES (@project_id, @name, @file_path, @language, @fingerprint, @description, @source_hash, @lines_of_code, @complexity, @reusability_score)
|
|
16
|
+
`),
|
|
17
|
+
getById: db.prepare('SELECT * FROM code_modules WHERE id = ?'),
|
|
18
|
+
delete: db.prepare('DELETE FROM code_modules WHERE id = ?'),
|
|
19
|
+
findByFingerprint: db.prepare('SELECT * FROM code_modules WHERE fingerprint = ?'),
|
|
20
|
+
findByProject: db.prepare('SELECT * FROM code_modules WHERE project_id = ? ORDER BY name ASC'),
|
|
21
|
+
countAll: db.prepare('SELECT COUNT(*) as count FROM code_modules'),
|
|
22
|
+
search: db.prepare(`
|
|
23
|
+
SELECT cm.* FROM code_modules cm
|
|
24
|
+
JOIN code_modules_fts fts ON cm.id = fts.rowid
|
|
25
|
+
WHERE code_modules_fts MATCH ?
|
|
26
|
+
ORDER BY rank
|
|
27
|
+
`),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
create(data: CodeModuleCreate): number {
|
|
32
|
+
const result = this.stmts.create.run(data);
|
|
33
|
+
return result.lastInsertRowid as number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
getById(id: number): CodeModuleRecord | undefined {
|
|
37
|
+
return this.stmts.getById.get(id) as CodeModuleRecord | undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
update(id: number, data: CodeModuleUpdate): boolean {
|
|
41
|
+
const fields = Object.keys(data).filter((key) => (data as Record<string, unknown>)[key] !== undefined);
|
|
42
|
+
if (fields.length === 0) return false;
|
|
43
|
+
|
|
44
|
+
const setClauses = fields.map((field) => `${field} = @${field}`).join(', ');
|
|
45
|
+
const stmt = this.db.prepare(
|
|
46
|
+
`UPDATE code_modules SET ${setClauses}, updated_at = datetime('now') WHERE id = @id`
|
|
47
|
+
);
|
|
48
|
+
const result = stmt.run({ ...data, id });
|
|
49
|
+
return result.changes > 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
delete(id: number): boolean {
|
|
53
|
+
const result = this.stmts.delete.run(id);
|
|
54
|
+
return result.changes > 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
findByFingerprint(fingerprint: string): CodeModuleRecord | undefined {
|
|
58
|
+
return this.stmts.findByFingerprint.get(fingerprint) as CodeModuleRecord | undefined;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
findByLanguage(language: string, limit?: number): CodeModuleRecord[] {
|
|
62
|
+
const sql = limit
|
|
63
|
+
? 'SELECT * FROM code_modules WHERE language = ? ORDER BY name ASC LIMIT ?'
|
|
64
|
+
: 'SELECT * FROM code_modules WHERE language = ? ORDER BY name ASC';
|
|
65
|
+
const stmt = this.db.prepare(sql);
|
|
66
|
+
return (limit ? stmt.all(language, limit) : stmt.all(language)) as CodeModuleRecord[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
findByProject(projectId: number): CodeModuleRecord[] {
|
|
70
|
+
return this.stmts.findByProject.all(projectId) as CodeModuleRecord[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
search(query: string): CodeModuleRecord[] {
|
|
74
|
+
return this.stmts.search.all(query) as CodeModuleRecord[];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
countAll(): number {
|
|
78
|
+
return (this.stmts.countAll.get() as { count: number }).count;
|
|
79
|
+
}
|
|
80
|
+
}
|