@su-record/vibe 2.7.14 → 2.7.15
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/.env.example +37 -37
- package/CLAUDE.md +134 -126
- package/LICENSE +21 -21
- package/README.md +449 -449
- package/agents/architect-low.md +41 -41
- package/agents/architect-medium.md +59 -59
- package/agents/architect.md +80 -80
- package/agents/build-error-resolver.md +115 -115
- package/agents/compounder.md +261 -261
- package/agents/diagrammer.md +178 -178
- package/agents/docs/api-documenter.md +99 -99
- package/agents/docs/changelog-writer.md +93 -93
- package/agents/e2e-tester.md +294 -294
- package/agents/explorer-low.md +42 -42
- package/agents/explorer-medium.md +59 -59
- package/agents/explorer.md +48 -48
- package/agents/implementer-low.md +43 -43
- package/agents/implementer-medium.md +52 -52
- package/agents/implementer.md +54 -54
- package/agents/junior-mentor.md +141 -141
- package/agents/planning/requirements-analyst.md +84 -84
- package/agents/planning/ux-advisor.md +83 -83
- package/agents/qa/acceptance-tester.md +86 -86
- package/agents/qa/edge-case-finder.md +93 -93
- package/agents/refactor-cleaner.md +143 -143
- package/agents/research/best-practices-agent.md +199 -199
- package/agents/research/codebase-patterns-agent.md +157 -157
- package/agents/research/framework-docs-agent.md +188 -188
- package/agents/research/security-advisory-agent.md +213 -213
- package/agents/review/architecture-reviewer.md +107 -107
- package/agents/review/complexity-reviewer.md +116 -116
- package/agents/review/data-integrity-reviewer.md +88 -88
- package/agents/review/git-history-reviewer.md +103 -103
- package/agents/review/performance-reviewer.md +86 -86
- package/agents/review/python-reviewer.md +150 -150
- package/agents/review/rails-reviewer.md +139 -139
- package/agents/review/react-reviewer.md +144 -144
- package/agents/review/security-reviewer.md +80 -80
- package/agents/review/simplicity-reviewer.md +140 -140
- package/agents/review/test-coverage-reviewer.md +116 -116
- package/agents/review/typescript-reviewer.md +127 -127
- package/agents/searcher.md +54 -54
- package/agents/simplifier.md +120 -120
- package/agents/tester.md +49 -49
- package/agents/ui/ui-a11y-auditor.md +93 -93
- package/agents/ui/ui-antipattern-detector.md +94 -94
- package/agents/ui/ui-dataviz-advisor.md +69 -69
- package/agents/ui/ui-design-system-gen.md +57 -57
- package/agents/ui/ui-industry-analyzer.md +49 -49
- package/agents/ui/ui-layout-architect.md +65 -65
- package/agents/ui/ui-stack-implementer.md +68 -68
- package/agents/ui/ux-compliance-reviewer.md +81 -81
- package/agents/ui-previewer.md +258 -258
- package/commands/vibe.analyze.md +11 -13
- package/commands/vibe.review.md +43 -1
- package/commands/vibe.run.md +2124 -2078
- package/commands/vibe.spec.md +9 -4
- package/commands/vibe.spec.review.md +569 -565
- package/commands/vibe.utils.md +413 -413
- package/commands/vibe.verify.md +33 -8
- package/dist/cli/collaborator.js +52 -52
- package/dist/cli/commands/evolution.js +12 -12
- package/dist/cli/commands/info.js +54 -54
- package/dist/cli/commands/init.js +5 -5
- package/dist/cli/commands/remove.js +14 -14
- package/dist/cli/commands/sentinel.js +27 -27
- package/dist/cli/commands/skills.js +5 -5
- package/dist/cli/commands/slack.js +10 -10
- package/dist/cli/commands/telegram.js +12 -12
- package/dist/cli/detect.js +32 -32
- package/dist/cli/index.js +51 -51
- package/dist/cli/llm/claude-commands.js +16 -16
- package/dist/cli/llm/config.js +18 -18
- package/dist/cli/llm/gemini-commands.js +16 -16
- package/dist/cli/llm/gpt-commands.js +19 -19
- package/dist/cli/llm/help.js +21 -21
- package/dist/cli/postinstall/cursor-agents.js +32 -32
- package/dist/cli/postinstall/cursor-rules.js +83 -83
- package/dist/cli/postinstall/cursor-skills.js +743 -743
- package/dist/cli/setup/Provisioner.js +42 -42
- package/dist/infra/lib/DeepInit.js +24 -24
- package/dist/infra/lib/IterationTracker.js +11 -11
- package/dist/infra/lib/PythonParser.js +108 -108
- package/dist/infra/lib/ReviewRace.js +96 -96
- package/dist/infra/lib/SkillFrontmatter.js +28 -28
- package/dist/infra/lib/SkillQualityGate.js +9 -9
- package/dist/infra/lib/SkillRepository.js +159 -159
- package/dist/infra/lib/UltraQA.js +99 -99
- package/dist/infra/lib/autonomy/AuditStore.js +41 -41
- package/dist/infra/lib/autonomy/ConfirmationStore.js +30 -30
- package/dist/infra/lib/autonomy/EventOutbox.js +38 -38
- package/dist/infra/lib/autonomy/PolicyEngine.js +18 -18
- package/dist/infra/lib/autonomy/SecuritySentinel.js +1 -1
- package/dist/infra/lib/autonomy/SuggestionStore.js +33 -33
- package/dist/infra/lib/embedding/VectorStore.js +22 -22
- package/dist/infra/lib/evolution/AgentAnalyzer.js +10 -10
- package/dist/infra/lib/evolution/DescriptionOptimizer.js +21 -21
- package/dist/infra/lib/evolution/GenerationRegistry.js +36 -36
- package/dist/infra/lib/evolution/InsightStore.js +90 -90
- package/dist/infra/lib/evolution/RollbackManager.js +5 -5
- package/dist/infra/lib/evolution/SkillBenchmark.js +23 -23
- package/dist/infra/lib/evolution/SkillEvalRunner.js +50 -50
- package/dist/infra/lib/evolution/SkillGapDetector.js +10 -10
- package/dist/infra/lib/evolution/UsageTracker.js +28 -28
- package/dist/infra/lib/gemini/orchestration.js +5 -5
- package/dist/infra/lib/gpt/orchestration.js +4 -4
- package/dist/infra/lib/memory/KnowledgeGraph.js +4 -4
- package/dist/infra/lib/memory/MemorySearch.js +57 -57
- package/dist/infra/lib/memory/MemoryStorage.js +181 -181
- package/dist/infra/lib/memory/ObservationStore.js +28 -28
- package/dist/infra/lib/memory/ReflectionStore.js +30 -30
- package/dist/infra/lib/memory/SessionRAGRetriever.js +7 -7
- package/dist/infra/lib/memory/SessionRAGStore.js +225 -225
- package/dist/infra/lib/memory/SessionSummarizer.js +9 -9
- package/dist/infra/orchestrator/AgentManager.js +12 -12
- package/dist/infra/orchestrator/AgentRegistry.js +65 -65
- package/dist/infra/orchestrator/MultiLlmResearch.js +8 -8
- package/dist/infra/orchestrator/SwarmOrchestrator.test.js +16 -16
- package/dist/infra/orchestrator/parallelResearch.js +24 -24
- package/dist/tools/convention/analyzeComplexity.test.js +115 -115
- package/dist/tools/convention/validateCodeQuality.test.js +104 -104
- package/dist/tools/memory/createMemoryTimeline.js +10 -10
- package/dist/tools/memory/getMemoryGraph.js +12 -12
- package/dist/tools/memory/getSessionContext.js +9 -9
- package/dist/tools/memory/linkMemories.js +14 -14
- package/dist/tools/memory/listMemories.js +4 -4
- package/dist/tools/memory/recallMemory.js +4 -4
- package/dist/tools/memory/saveMemory.js +4 -4
- package/dist/tools/memory/searchMemoriesAdvanced.js +23 -23
- package/dist/tools/semantic/analyzeDependencyGraph.js +12 -12
- package/dist/tools/semantic/astGrep.test.js +6 -6
- package/dist/tools/spec/prdParser.test.js +171 -171
- package/dist/tools/spec/specGenerator.js +169 -169
- package/dist/tools/spec/traceabilityMatrix.js +64 -64
- package/dist/tools/spec/traceabilityMatrix.test.js +28 -28
- package/hooks/gemini-hooks.json +73 -73
- package/hooks/hooks.json +137 -137
- package/hooks/scripts/code-check.js +77 -70
- package/hooks/scripts/context-save.js +212 -212
- package/hooks/scripts/hud-status.js +291 -291
- package/hooks/scripts/keyword-detector.js +214 -214
- package/hooks/scripts/llm-orchestrate.js +475 -475
- package/hooks/scripts/post-edit.js +32 -32
- package/hooks/scripts/pre-tool-guard.js +125 -125
- package/hooks/scripts/prompt-dispatcher.js +185 -185
- package/hooks/scripts/sentinel-guard.js +104 -104
- package/hooks/scripts/session-start.js +106 -106
- package/hooks/scripts/stop-notify.js +209 -209
- package/hooks/scripts/utils.js +100 -100
- package/languages/csharp-unity.md +515 -515
- package/languages/gdscript-godot.md +470 -470
- package/languages/ruby-rails.md +489 -489
- package/languages/typescript-angular.md +433 -433
- package/languages/typescript-astro.md +416 -416
- package/languages/typescript-electron.md +406 -406
- package/languages/typescript-nestjs.md +524 -524
- package/languages/typescript-svelte.md +407 -407
- package/languages/typescript-tauri.md +365 -365
- package/package.json +121 -121
- package/skills/agents-md/SKILL.md +120 -120
- package/skills/arch-guard/SKILL.md +180 -180
- package/skills/brand-assets/SKILL.md +146 -146
- package/skills/capability-loop/SKILL.md +167 -167
- package/skills/characterization-test/SKILL.md +206 -206
- package/skills/commerce-patterns/SKILL.md +59 -59
- package/skills/commit-push-pr/SKILL.md +75 -75
- package/skills/context7-usage/SKILL.md +105 -105
- package/skills/core-capabilities/SKILL.md +48 -48
- package/skills/e2e-commerce/SKILL.md +57 -57
- package/skills/exec-plan/SKILL.md +147 -147
- package/skills/frontend-design/SKILL.md +73 -73
- package/skills/git-worktree/SKILL.md +72 -72
- package/skills/handoff/SKILL.md +109 -109
- package/skills/parallel-research/SKILL.md +87 -87
- package/skills/priority-todos/SKILL.md +63 -63
- package/skills/seo-checklist/SKILL.md +57 -57
- package/skills/techdebt/SKILL.md +122 -122
- package/skills/tool-fallback/SKILL.md +103 -103
- package/skills/typescript-advanced-types/SKILL.md +66 -66
- package/skills/ui-ux-pro-max/SKILL.md +206 -206
- package/skills/vercel-react-best-practices/SKILL.md +59 -59
- package/skills/video-production/SKILL.md +51 -51
- package/vibe/config.json +29 -29
- package/vibe/constitution.md +227 -227
- package/vibe/rules/principles/communication-guide.md +98 -98
- package/vibe/rules/principles/development-philosophy.md +52 -52
- package/vibe/rules/principles/quick-start.md +102 -102
- package/vibe/rules/quality/bdd-contract-testing.md +393 -393
- package/vibe/rules/quality/checklist.md +276 -276
- package/vibe/rules/quality/performance.md +236 -236
- package/vibe/rules/quality/testing-strategy.md +440 -440
- package/vibe/rules/standards/anti-patterns.md +541 -541
- package/vibe/rules/standards/code-structure.md +291 -291
- package/vibe/rules/standards/complexity-metrics.md +313 -313
- package/vibe/rules/standards/git-workflow.md +237 -237
- package/vibe/rules/standards/naming-conventions.md +198 -198
- package/vibe/rules/standards/security.md +305 -305
- package/vibe/rules/writing/document-style.md +74 -74
- package/vibe/setup.sh +31 -31
- package/vibe/templates/constitution-template.md +252 -252
- package/vibe/templates/contract-backend-template.md +526 -526
- package/vibe/templates/contract-frontend-template.md +599 -599
- package/vibe/templates/feature-template.md +96 -96
- package/vibe/templates/spec-template.md +221 -221
- package/vibe/ui-ux-data/charts.csv +26 -26
- package/vibe/ui-ux-data/colors.csv +97 -97
- package/vibe/ui-ux-data/icons.csv +101 -101
- package/vibe/ui-ux-data/landing.csv +31 -31
- package/vibe/ui-ux-data/products.csv +96 -96
- package/vibe/ui-ux-data/react-performance.csv +45 -45
- package/vibe/ui-ux-data/stacks/astro.csv +54 -54
- package/vibe/ui-ux-data/stacks/flutter.csv +53 -53
- package/vibe/ui-ux-data/stacks/html-tailwind.csv +56 -56
- package/vibe/ui-ux-data/stacks/jetpack-compose.csv +53 -53
- package/vibe/ui-ux-data/stacks/nextjs.csv +53 -53
- package/vibe/ui-ux-data/stacks/nuxt-ui.csv +51 -51
- package/vibe/ui-ux-data/stacks/nuxtjs.csv +59 -59
- package/vibe/ui-ux-data/stacks/react-native.csv +52 -52
- package/vibe/ui-ux-data/stacks/react.csv +54 -54
- package/vibe/ui-ux-data/stacks/shadcn.csv +61 -61
- package/vibe/ui-ux-data/stacks/svelte.csv +54 -54
- package/vibe/ui-ux-data/stacks/swiftui.csv +51 -51
- package/vibe/ui-ux-data/stacks/vue.csv +50 -50
- package/vibe/ui-ux-data/styles.csv +68 -68
- package/vibe/ui-ux-data/typography.csv +57 -57
- package/vibe/ui-ux-data/ui-reasoning.csv +101 -101
- package/vibe/ui-ux-data/ux-guidelines.csv +99 -99
- package/vibe/ui-ux-data/version.json +31 -31
- package/vibe/ui-ux-data/web-interface.csv +31 -31
|
@@ -40,111 +40,111 @@ export class MemoryStorage {
|
|
|
40
40
|
}
|
|
41
41
|
initializeDatabase() {
|
|
42
42
|
// Create memories table
|
|
43
|
-
this.db.exec(`
|
|
44
|
-
CREATE TABLE IF NOT EXISTS memories (
|
|
45
|
-
key TEXT PRIMARY KEY,
|
|
46
|
-
value TEXT NOT NULL,
|
|
47
|
-
category TEXT NOT NULL DEFAULT 'general',
|
|
48
|
-
timestamp TEXT NOT NULL,
|
|
49
|
-
lastAccessed TEXT NOT NULL,
|
|
50
|
-
priority INTEGER DEFAULT 0
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
CREATE INDEX IF NOT EXISTS idx_category ON memories(category);
|
|
54
|
-
CREATE INDEX IF NOT EXISTS idx_timestamp ON memories(timestamp);
|
|
55
|
-
CREATE INDEX IF NOT EXISTS idx_priority ON memories(priority);
|
|
56
|
-
CREATE INDEX IF NOT EXISTS idx_lastAccessed ON memories(lastAccessed);
|
|
43
|
+
this.db.exec(`
|
|
44
|
+
CREATE TABLE IF NOT EXISTS memories (
|
|
45
|
+
key TEXT PRIMARY KEY,
|
|
46
|
+
value TEXT NOT NULL,
|
|
47
|
+
category TEXT NOT NULL DEFAULT 'general',
|
|
48
|
+
timestamp TEXT NOT NULL,
|
|
49
|
+
lastAccessed TEXT NOT NULL,
|
|
50
|
+
priority INTEGER DEFAULT 0
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
CREATE INDEX IF NOT EXISTS idx_category ON memories(category);
|
|
54
|
+
CREATE INDEX IF NOT EXISTS idx_timestamp ON memories(timestamp);
|
|
55
|
+
CREATE INDEX IF NOT EXISTS idx_priority ON memories(priority);
|
|
56
|
+
CREATE INDEX IF NOT EXISTS idx_lastAccessed ON memories(lastAccessed);
|
|
57
57
|
`);
|
|
58
58
|
// Create memory_relations table for Knowledge Graph
|
|
59
|
-
this.db.exec(`
|
|
60
|
-
CREATE TABLE IF NOT EXISTS memory_relations (
|
|
61
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
62
|
-
sourceKey TEXT NOT NULL,
|
|
63
|
-
targetKey TEXT NOT NULL,
|
|
64
|
-
relationType TEXT NOT NULL,
|
|
65
|
-
strength REAL DEFAULT 1.0,
|
|
66
|
-
metadata TEXT,
|
|
67
|
-
timestamp TEXT NOT NULL,
|
|
68
|
-
UNIQUE(sourceKey, targetKey, relationType)
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
CREATE INDEX IF NOT EXISTS idx_rel_source ON memory_relations(sourceKey);
|
|
72
|
-
CREATE INDEX IF NOT EXISTS idx_rel_target ON memory_relations(targetKey);
|
|
73
|
-
CREATE INDEX IF NOT EXISTS idx_rel_type ON memory_relations(relationType);
|
|
59
|
+
this.db.exec(`
|
|
60
|
+
CREATE TABLE IF NOT EXISTS memory_relations (
|
|
61
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
62
|
+
sourceKey TEXT NOT NULL,
|
|
63
|
+
targetKey TEXT NOT NULL,
|
|
64
|
+
relationType TEXT NOT NULL,
|
|
65
|
+
strength REAL DEFAULT 1.0,
|
|
66
|
+
metadata TEXT,
|
|
67
|
+
timestamp TEXT NOT NULL,
|
|
68
|
+
UNIQUE(sourceKey, targetKey, relationType)
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
CREATE INDEX IF NOT EXISTS idx_rel_source ON memory_relations(sourceKey);
|
|
72
|
+
CREATE INDEX IF NOT EXISTS idx_rel_target ON memory_relations(targetKey);
|
|
73
|
+
CREATE INDEX IF NOT EXISTS idx_rel_type ON memory_relations(relationType);
|
|
74
74
|
`);
|
|
75
75
|
// Create observations table for structured observation capture
|
|
76
|
-
this.db.exec(`
|
|
77
|
-
CREATE TABLE IF NOT EXISTS observations (
|
|
78
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
79
|
-
sessionId TEXT,
|
|
80
|
-
type TEXT NOT NULL CHECK(type IN ('decision','bugfix','feature','refactor','discovery')),
|
|
81
|
-
title TEXT NOT NULL,
|
|
82
|
-
narrative TEXT,
|
|
83
|
-
facts TEXT,
|
|
84
|
-
concepts TEXT,
|
|
85
|
-
filesModified TEXT,
|
|
86
|
-
timestamp TEXT NOT NULL,
|
|
87
|
-
projectPath TEXT
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
CREATE INDEX IF NOT EXISTS idx_obs_session ON observations(sessionId);
|
|
91
|
-
CREATE INDEX IF NOT EXISTS idx_obs_type ON observations(type);
|
|
92
|
-
CREATE INDEX IF NOT EXISTS idx_obs_timestamp ON observations(timestamp);
|
|
76
|
+
this.db.exec(`
|
|
77
|
+
CREATE TABLE IF NOT EXISTS observations (
|
|
78
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
79
|
+
sessionId TEXT,
|
|
80
|
+
type TEXT NOT NULL CHECK(type IN ('decision','bugfix','feature','refactor','discovery')),
|
|
81
|
+
title TEXT NOT NULL,
|
|
82
|
+
narrative TEXT,
|
|
83
|
+
facts TEXT,
|
|
84
|
+
concepts TEXT,
|
|
85
|
+
filesModified TEXT,
|
|
86
|
+
timestamp TEXT NOT NULL,
|
|
87
|
+
projectPath TEXT
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
CREATE INDEX IF NOT EXISTS idx_obs_session ON observations(sessionId);
|
|
91
|
+
CREATE INDEX IF NOT EXISTS idx_obs_type ON observations(type);
|
|
92
|
+
CREATE INDEX IF NOT EXISTS idx_obs_timestamp ON observations(timestamp);
|
|
93
93
|
`);
|
|
94
94
|
// Create session_summaries table
|
|
95
|
-
this.db.exec(`
|
|
96
|
-
CREATE TABLE IF NOT EXISTS session_summaries (
|
|
97
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
98
|
-
sessionId TEXT UNIQUE NOT NULL,
|
|
99
|
-
request TEXT,
|
|
100
|
-
investigated TEXT,
|
|
101
|
-
learned TEXT,
|
|
102
|
-
completed TEXT,
|
|
103
|
-
nextSteps TEXT,
|
|
104
|
-
filesRead TEXT,
|
|
105
|
-
filesEdited TEXT,
|
|
106
|
-
timestamp TEXT NOT NULL
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
CREATE INDEX IF NOT EXISTS idx_ss_session ON session_summaries(sessionId);
|
|
110
|
-
CREATE INDEX IF NOT EXISTS idx_ss_timestamp ON session_summaries(timestamp);
|
|
95
|
+
this.db.exec(`
|
|
96
|
+
CREATE TABLE IF NOT EXISTS session_summaries (
|
|
97
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
98
|
+
sessionId TEXT UNIQUE NOT NULL,
|
|
99
|
+
request TEXT,
|
|
100
|
+
investigated TEXT,
|
|
101
|
+
learned TEXT,
|
|
102
|
+
completed TEXT,
|
|
103
|
+
nextSteps TEXT,
|
|
104
|
+
filesRead TEXT,
|
|
105
|
+
filesEdited TEXT,
|
|
106
|
+
timestamp TEXT NOT NULL
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
CREATE INDEX IF NOT EXISTS idx_ss_session ON session_summaries(sessionId);
|
|
110
|
+
CREATE INDEX IF NOT EXISTS idx_ss_timestamp ON session_summaries(timestamp);
|
|
111
111
|
`);
|
|
112
112
|
// Create usage_events table for self-evolution (Phase 4)
|
|
113
|
-
this.db.exec(`
|
|
114
|
-
CREATE TABLE IF NOT EXISTS usage_events (
|
|
115
|
-
id TEXT PRIMARY KEY,
|
|
116
|
-
generationId TEXT NOT NULL,
|
|
117
|
-
sessionId TEXT,
|
|
118
|
-
matchedPrompt TEXT,
|
|
119
|
-
feedback TEXT CHECK(feedback IN ('positive','negative','neutral') OR feedback IS NULL),
|
|
120
|
-
createdAt TEXT NOT NULL
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
CREATE INDEX IF NOT EXISTS idx_ue_gen ON usage_events(generationId);
|
|
124
|
-
CREATE INDEX IF NOT EXISTS idx_ue_session ON usage_events(sessionId);
|
|
125
|
-
CREATE INDEX IF NOT EXISTS idx_ue_feedback ON usage_events(feedback);
|
|
126
|
-
CREATE INDEX IF NOT EXISTS idx_ue_created ON usage_events(createdAt);
|
|
113
|
+
this.db.exec(`
|
|
114
|
+
CREATE TABLE IF NOT EXISTS usage_events (
|
|
115
|
+
id TEXT PRIMARY KEY,
|
|
116
|
+
generationId TEXT NOT NULL,
|
|
117
|
+
sessionId TEXT,
|
|
118
|
+
matchedPrompt TEXT,
|
|
119
|
+
feedback TEXT CHECK(feedback IN ('positive','negative','neutral') OR feedback IS NULL),
|
|
120
|
+
createdAt TEXT NOT NULL
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
CREATE INDEX IF NOT EXISTS idx_ue_gen ON usage_events(generationId);
|
|
124
|
+
CREATE INDEX IF NOT EXISTS idx_ue_session ON usage_events(sessionId);
|
|
125
|
+
CREATE INDEX IF NOT EXISTS idx_ue_feedback ON usage_events(feedback);
|
|
126
|
+
CREATE INDEX IF NOT EXISTS idx_ue_created ON usage_events(createdAt);
|
|
127
127
|
`);
|
|
128
128
|
// Create reflections table for self-evolution (Phase 1)
|
|
129
|
-
this.db.exec(`
|
|
130
|
-
CREATE TABLE IF NOT EXISTS reflections (
|
|
131
|
-
id TEXT PRIMARY KEY,
|
|
132
|
-
sessionId TEXT,
|
|
133
|
-
type TEXT NOT NULL CHECK(type IN ('minor','major')),
|
|
134
|
-
trigger TEXT NOT NULL CHECK(trigger IN ('context_pressure','session_end','manual')),
|
|
135
|
-
insights TEXT,
|
|
136
|
-
decisions TEXT,
|
|
137
|
-
patterns TEXT,
|
|
138
|
-
filesContext TEXT,
|
|
139
|
-
score REAL DEFAULT 0.5 CHECK(score >= 0 AND score <= 1),
|
|
140
|
-
createdAt TEXT NOT NULL
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
CREATE INDEX IF NOT EXISTS idx_refl_session ON reflections(sessionId);
|
|
144
|
-
CREATE INDEX IF NOT EXISTS idx_refl_type ON reflections(type);
|
|
145
|
-
CREATE INDEX IF NOT EXISTS idx_refl_trigger ON reflections(trigger);
|
|
146
|
-
CREATE INDEX IF NOT EXISTS idx_refl_score ON reflections(score);
|
|
147
|
-
CREATE INDEX IF NOT EXISTS idx_refl_created ON reflections(createdAt);
|
|
129
|
+
this.db.exec(`
|
|
130
|
+
CREATE TABLE IF NOT EXISTS reflections (
|
|
131
|
+
id TEXT PRIMARY KEY,
|
|
132
|
+
sessionId TEXT,
|
|
133
|
+
type TEXT NOT NULL CHECK(type IN ('minor','major')),
|
|
134
|
+
trigger TEXT NOT NULL CHECK(trigger IN ('context_pressure','session_end','manual')),
|
|
135
|
+
insights TEXT,
|
|
136
|
+
decisions TEXT,
|
|
137
|
+
patterns TEXT,
|
|
138
|
+
filesContext TEXT,
|
|
139
|
+
score REAL DEFAULT 0.5 CHECK(score >= 0 AND score <= 1),
|
|
140
|
+
createdAt TEXT NOT NULL
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
CREATE INDEX IF NOT EXISTS idx_refl_session ON reflections(sessionId);
|
|
144
|
+
CREATE INDEX IF NOT EXISTS idx_refl_type ON reflections(type);
|
|
145
|
+
CREATE INDEX IF NOT EXISTS idx_refl_trigger ON reflections(trigger);
|
|
146
|
+
CREATE INDEX IF NOT EXISTS idx_refl_score ON reflections(score);
|
|
147
|
+
CREATE INDEX IF NOT EXISTS idx_refl_created ON reflections(createdAt);
|
|
148
148
|
`);
|
|
149
149
|
// Enable WAL mode for better concurrency
|
|
150
150
|
this.db.pragma('journal_mode = WAL');
|
|
@@ -156,56 +156,56 @@ export class MemoryStorage {
|
|
|
156
156
|
initializeFTS5() {
|
|
157
157
|
try {
|
|
158
158
|
// Create FTS5 virtual table for memories
|
|
159
|
-
this.db.exec(`
|
|
160
|
-
CREATE VIRTUAL TABLE IF NOT EXISTS memories_fts
|
|
161
|
-
USING fts5(key, value, content=memories, content_rowid=rowid);
|
|
159
|
+
this.db.exec(`
|
|
160
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS memories_fts
|
|
161
|
+
USING fts5(key, value, content=memories, content_rowid=rowid);
|
|
162
162
|
`);
|
|
163
163
|
// Triggers to keep FTS5 in sync with memories table
|
|
164
|
-
this.db.exec(`
|
|
165
|
-
CREATE TRIGGER IF NOT EXISTS memories_ai AFTER INSERT ON memories BEGIN
|
|
166
|
-
INSERT INTO memories_fts(rowid, key, value) VALUES (new.rowid, new.key, new.value);
|
|
167
|
-
END;
|
|
168
|
-
CREATE TRIGGER IF NOT EXISTS memories_ad AFTER DELETE ON memories BEGIN
|
|
169
|
-
INSERT INTO memories_fts(memories_fts, rowid, key, value) VALUES('delete', old.rowid, old.key, old.value);
|
|
170
|
-
END;
|
|
171
|
-
CREATE TRIGGER IF NOT EXISTS memories_au AFTER UPDATE ON memories BEGIN
|
|
172
|
-
INSERT INTO memories_fts(memories_fts, rowid, key, value) VALUES('delete', old.rowid, old.key, old.value);
|
|
173
|
-
INSERT INTO memories_fts(rowid, key, value) VALUES (new.rowid, new.key, new.value);
|
|
174
|
-
END;
|
|
164
|
+
this.db.exec(`
|
|
165
|
+
CREATE TRIGGER IF NOT EXISTS memories_ai AFTER INSERT ON memories BEGIN
|
|
166
|
+
INSERT INTO memories_fts(rowid, key, value) VALUES (new.rowid, new.key, new.value);
|
|
167
|
+
END;
|
|
168
|
+
CREATE TRIGGER IF NOT EXISTS memories_ad AFTER DELETE ON memories BEGIN
|
|
169
|
+
INSERT INTO memories_fts(memories_fts, rowid, key, value) VALUES('delete', old.rowid, old.key, old.value);
|
|
170
|
+
END;
|
|
171
|
+
CREATE TRIGGER IF NOT EXISTS memories_au AFTER UPDATE ON memories BEGIN
|
|
172
|
+
INSERT INTO memories_fts(memories_fts, rowid, key, value) VALUES('delete', old.rowid, old.key, old.value);
|
|
173
|
+
INSERT INTO memories_fts(rowid, key, value) VALUES (new.rowid, new.key, new.value);
|
|
174
|
+
END;
|
|
175
175
|
`);
|
|
176
176
|
// Create FTS5 for observations
|
|
177
|
-
this.db.exec(`
|
|
178
|
-
CREATE VIRTUAL TABLE IF NOT EXISTS observations_fts
|
|
179
|
-
USING fts5(title, narrative, facts, concepts, content=observations, content_rowid=id);
|
|
180
|
-
|
|
181
|
-
CREATE TRIGGER IF NOT EXISTS observations_ai AFTER INSERT ON observations BEGIN
|
|
182
|
-
INSERT INTO observations_fts(rowid, title, narrative, facts, concepts)
|
|
183
|
-
VALUES (new.id, new.title, new.narrative, new.facts, new.concepts);
|
|
184
|
-
END;
|
|
185
|
-
CREATE TRIGGER IF NOT EXISTS observations_ad AFTER DELETE ON observations BEGIN
|
|
186
|
-
INSERT INTO observations_fts(observations_fts, rowid, title, narrative, facts, concepts)
|
|
187
|
-
VALUES('delete', old.id, old.title, old.narrative, old.facts, old.concepts);
|
|
188
|
-
END;
|
|
177
|
+
this.db.exec(`
|
|
178
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS observations_fts
|
|
179
|
+
USING fts5(title, narrative, facts, concepts, content=observations, content_rowid=id);
|
|
180
|
+
|
|
181
|
+
CREATE TRIGGER IF NOT EXISTS observations_ai AFTER INSERT ON observations BEGIN
|
|
182
|
+
INSERT INTO observations_fts(rowid, title, narrative, facts, concepts)
|
|
183
|
+
VALUES (new.id, new.title, new.narrative, new.facts, new.concepts);
|
|
184
|
+
END;
|
|
185
|
+
CREATE TRIGGER IF NOT EXISTS observations_ad AFTER DELETE ON observations BEGIN
|
|
186
|
+
INSERT INTO observations_fts(observations_fts, rowid, title, narrative, facts, concepts)
|
|
187
|
+
VALUES('delete', old.id, old.title, old.narrative, old.facts, old.concepts);
|
|
188
|
+
END;
|
|
189
189
|
`);
|
|
190
190
|
// Create FTS5 for reflections
|
|
191
|
-
this.db.exec(`
|
|
192
|
-
CREATE VIRTUAL TABLE IF NOT EXISTS reflections_fts
|
|
193
|
-
USING fts5(insights, decisions, patterns, content=reflections, content_rowid=rowid);
|
|
194
|
-
|
|
195
|
-
CREATE TRIGGER IF NOT EXISTS reflections_ai AFTER INSERT ON reflections BEGIN
|
|
196
|
-
INSERT INTO reflections_fts(rowid, insights, decisions, patterns)
|
|
197
|
-
VALUES (new.rowid, new.insights, new.decisions, new.patterns);
|
|
198
|
-
END;
|
|
199
|
-
CREATE TRIGGER IF NOT EXISTS reflections_ad AFTER DELETE ON reflections BEGIN
|
|
200
|
-
INSERT INTO reflections_fts(reflections_fts, rowid, insights, decisions, patterns)
|
|
201
|
-
VALUES('delete', old.rowid, old.insights, old.decisions, old.patterns);
|
|
202
|
-
END;
|
|
203
|
-
CREATE TRIGGER IF NOT EXISTS reflections_au AFTER UPDATE ON reflections BEGIN
|
|
204
|
-
INSERT INTO reflections_fts(reflections_fts, rowid, insights, decisions, patterns)
|
|
205
|
-
VALUES('delete', old.rowid, old.insights, old.decisions, old.patterns);
|
|
206
|
-
INSERT INTO reflections_fts(rowid, insights, decisions, patterns)
|
|
207
|
-
VALUES (new.rowid, new.insights, new.decisions, new.patterns);
|
|
208
|
-
END;
|
|
191
|
+
this.db.exec(`
|
|
192
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS reflections_fts
|
|
193
|
+
USING fts5(insights, decisions, patterns, content=reflections, content_rowid=rowid);
|
|
194
|
+
|
|
195
|
+
CREATE TRIGGER IF NOT EXISTS reflections_ai AFTER INSERT ON reflections BEGIN
|
|
196
|
+
INSERT INTO reflections_fts(rowid, insights, decisions, patterns)
|
|
197
|
+
VALUES (new.rowid, new.insights, new.decisions, new.patterns);
|
|
198
|
+
END;
|
|
199
|
+
CREATE TRIGGER IF NOT EXISTS reflections_ad AFTER DELETE ON reflections BEGIN
|
|
200
|
+
INSERT INTO reflections_fts(reflections_fts, rowid, insights, decisions, patterns)
|
|
201
|
+
VALUES('delete', old.rowid, old.insights, old.decisions, old.patterns);
|
|
202
|
+
END;
|
|
203
|
+
CREATE TRIGGER IF NOT EXISTS reflections_au AFTER UPDATE ON reflections BEGIN
|
|
204
|
+
INSERT INTO reflections_fts(reflections_fts, rowid, insights, decisions, patterns)
|
|
205
|
+
VALUES('delete', old.rowid, old.insights, old.decisions, old.patterns);
|
|
206
|
+
INSERT INTO reflections_fts(rowid, insights, decisions, patterns)
|
|
207
|
+
VALUES (new.rowid, new.insights, new.decisions, new.patterns);
|
|
208
|
+
END;
|
|
209
209
|
`);
|
|
210
210
|
// Migrate existing data into FTS5 index
|
|
211
211
|
const ftsCount = this.db.prepare(`SELECT COUNT(*) as cnt FROM memories_fts`).get().cnt;
|
|
@@ -227,10 +227,10 @@ export class MemoryStorage {
|
|
|
227
227
|
}
|
|
228
228
|
initializePreparedStatements() {
|
|
229
229
|
try {
|
|
230
|
-
this.recallStmt = this.db.prepare(`
|
|
231
|
-
UPDATE memories SET lastAccessed = ?
|
|
232
|
-
WHERE key = ?
|
|
233
|
-
RETURNING *
|
|
230
|
+
this.recallStmt = this.db.prepare(`
|
|
231
|
+
UPDATE memories SET lastAccessed = ?
|
|
232
|
+
WHERE key = ?
|
|
233
|
+
RETURNING *
|
|
234
234
|
`);
|
|
235
235
|
}
|
|
236
236
|
catch {
|
|
@@ -239,9 +239,9 @@ export class MemoryStorage {
|
|
|
239
239
|
this.recallSelectStmt = this.db.prepare(`SELECT * FROM memories WHERE key = ?`);
|
|
240
240
|
this.recallUpdateStmt = this.db.prepare(`UPDATE memories SET lastAccessed = ? WHERE key = ?`);
|
|
241
241
|
}
|
|
242
|
-
this.saveStmt = this.db.prepare(`
|
|
243
|
-
INSERT OR REPLACE INTO memories (key, value, category, timestamp, lastAccessed, priority)
|
|
244
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
242
|
+
this.saveStmt = this.db.prepare(`
|
|
243
|
+
INSERT OR REPLACE INTO memories (key, value, category, timestamp, lastAccessed, priority)
|
|
244
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
245
245
|
`);
|
|
246
246
|
}
|
|
247
247
|
migrateFromJSON() {
|
|
@@ -253,9 +253,9 @@ export class MemoryStorage {
|
|
|
253
253
|
const memories = JSON.parse(jsonData);
|
|
254
254
|
if (memories.length === 0)
|
|
255
255
|
return;
|
|
256
|
-
const insert = this.db.prepare(`
|
|
257
|
-
INSERT OR REPLACE INTO memories (key, value, category, timestamp, lastAccessed, priority)
|
|
258
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
256
|
+
const insert = this.db.prepare(`
|
|
257
|
+
INSERT OR REPLACE INTO memories (key, value, category, timestamp, lastAccessed, priority)
|
|
258
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
259
259
|
`);
|
|
260
260
|
const insertMany = this.db.transaction((items) => {
|
|
261
261
|
for (const item of items) {
|
|
@@ -331,9 +331,9 @@ export class MemoryStorage {
|
|
|
331
331
|
this.saveStmt.run(key, value, category, timestamp, timestamp, priority);
|
|
332
332
|
}
|
|
333
333
|
else {
|
|
334
|
-
const stmt = this.db.prepare(`
|
|
335
|
-
INSERT OR REPLACE INTO memories (key, value, category, timestamp, lastAccessed, priority)
|
|
336
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
334
|
+
const stmt = this.db.prepare(`
|
|
335
|
+
INSERT OR REPLACE INTO memories (key, value, category, timestamp, lastAccessed, priority)
|
|
336
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
337
337
|
`);
|
|
338
338
|
stmt.run(key, value, category, timestamp, timestamp, priority);
|
|
339
339
|
}
|
|
@@ -376,10 +376,10 @@ export class MemoryStorage {
|
|
|
376
376
|
*/
|
|
377
377
|
update(key, value) {
|
|
378
378
|
const timestamp = new Date().toISOString();
|
|
379
|
-
const stmt = this.db.prepare(`
|
|
380
|
-
UPDATE memories
|
|
381
|
-
SET value = ?, timestamp = ?, lastAccessed = ?
|
|
382
|
-
WHERE key = ?
|
|
379
|
+
const stmt = this.db.prepare(`
|
|
380
|
+
UPDATE memories
|
|
381
|
+
SET value = ?, timestamp = ?, lastAccessed = ?
|
|
382
|
+
WHERE key = ?
|
|
383
383
|
`);
|
|
384
384
|
const result = stmt.run(value, timestamp, timestamp, key);
|
|
385
385
|
return result.changes > 0;
|
|
@@ -389,16 +389,16 @@ export class MemoryStorage {
|
|
|
389
389
|
*/
|
|
390
390
|
list(category) {
|
|
391
391
|
if (category) {
|
|
392
|
-
const stmt = this.db.prepare(`
|
|
393
|
-
SELECT * FROM memories WHERE category = ?
|
|
394
|
-
ORDER BY priority DESC, timestamp DESC
|
|
392
|
+
const stmt = this.db.prepare(`
|
|
393
|
+
SELECT * FROM memories WHERE category = ?
|
|
394
|
+
ORDER BY priority DESC, timestamp DESC
|
|
395
395
|
`);
|
|
396
396
|
return stmt.all(category);
|
|
397
397
|
}
|
|
398
398
|
else {
|
|
399
|
-
const stmt = this.db.prepare(`
|
|
400
|
-
SELECT * FROM memories
|
|
401
|
-
ORDER BY priority DESC, timestamp DESC
|
|
399
|
+
const stmt = this.db.prepare(`
|
|
400
|
+
SELECT * FROM memories
|
|
401
|
+
ORDER BY priority DESC, timestamp DESC
|
|
402
402
|
`);
|
|
403
403
|
return stmt.all();
|
|
404
404
|
}
|
|
@@ -434,13 +434,13 @@ export class MemoryStorage {
|
|
|
434
434
|
if (!this.fts5Available) {
|
|
435
435
|
return this.searchLike(query);
|
|
436
436
|
}
|
|
437
|
-
const stmt = this.db.prepare(`
|
|
438
|
-
SELECT m.*, bm25(memories_fts) as rank
|
|
439
|
-
FROM memories_fts fts
|
|
440
|
-
JOIN memories m ON m.rowid = fts.rowid
|
|
441
|
-
WHERE memories_fts MATCH ?
|
|
442
|
-
ORDER BY rank
|
|
443
|
-
LIMIT ?
|
|
437
|
+
const stmt = this.db.prepare(`
|
|
438
|
+
SELECT m.*, bm25(memories_fts) as rank
|
|
439
|
+
FROM memories_fts fts
|
|
440
|
+
JOIN memories m ON m.rowid = fts.rowid
|
|
441
|
+
WHERE memories_fts MATCH ?
|
|
442
|
+
ORDER BY rank
|
|
443
|
+
LIMIT ?
|
|
444
444
|
`);
|
|
445
445
|
return stmt.all(MemoryStorage.sanitizeFTS5Query(query), limit);
|
|
446
446
|
}
|
|
@@ -451,10 +451,10 @@ export class MemoryStorage {
|
|
|
451
451
|
return this.fts5Available;
|
|
452
452
|
}
|
|
453
453
|
searchLike(query) {
|
|
454
|
-
const stmt = this.db.prepare(`
|
|
455
|
-
SELECT * FROM memories
|
|
456
|
-
WHERE key LIKE ? OR value LIKE ?
|
|
457
|
-
ORDER BY priority DESC, timestamp DESC
|
|
454
|
+
const stmt = this.db.prepare(`
|
|
455
|
+
SELECT * FROM memories
|
|
456
|
+
WHERE key LIKE ? OR value LIKE ?
|
|
457
|
+
ORDER BY priority DESC, timestamp DESC
|
|
458
458
|
`);
|
|
459
459
|
const pattern = `%${query}%`;
|
|
460
460
|
return stmt.all(pattern, pattern);
|
|
@@ -463,10 +463,10 @@ export class MemoryStorage {
|
|
|
463
463
|
* Get memories by priority level
|
|
464
464
|
*/
|
|
465
465
|
getByPriority(priority) {
|
|
466
|
-
const stmt = this.db.prepare(`
|
|
467
|
-
SELECT * FROM memories
|
|
468
|
-
WHERE priority = ?
|
|
469
|
-
ORDER BY timestamp DESC
|
|
466
|
+
const stmt = this.db.prepare(`
|
|
467
|
+
SELECT * FROM memories
|
|
468
|
+
WHERE priority = ?
|
|
469
|
+
ORDER BY timestamp DESC
|
|
470
470
|
`);
|
|
471
471
|
return stmt.all(priority);
|
|
472
472
|
}
|
|
@@ -482,10 +482,10 @@ export class MemoryStorage {
|
|
|
482
482
|
* Get memory statistics
|
|
483
483
|
*/
|
|
484
484
|
getStats() {
|
|
485
|
-
const categories = this.db.prepare(`
|
|
486
|
-
SELECT category, COUNT(*) as count
|
|
487
|
-
FROM memories
|
|
488
|
-
GROUP BY category
|
|
485
|
+
const categories = this.db.prepare(`
|
|
486
|
+
SELECT category, COUNT(*) as count
|
|
487
|
+
FROM memories
|
|
488
|
+
GROUP BY category
|
|
489
489
|
`).all();
|
|
490
490
|
const byCategory = {};
|
|
491
491
|
let total = 0;
|
|
@@ -9,9 +9,9 @@ export class ObservationStore {
|
|
|
9
9
|
*/
|
|
10
10
|
add(input) {
|
|
11
11
|
const timestamp = new Date().toISOString();
|
|
12
|
-
const stmt = this.db.prepare(`
|
|
13
|
-
INSERT INTO observations (sessionId, type, title, narrative, facts, concepts, filesModified, timestamp, projectPath)
|
|
14
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
12
|
+
const stmt = this.db.prepare(`
|
|
13
|
+
INSERT INTO observations (sessionId, type, title, narrative, facts, concepts, filesModified, timestamp, projectPath)
|
|
14
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
15
15
|
`);
|
|
16
16
|
const result = stmt.run(input.sessionId || null, input.type, input.title, input.narrative || null, input.facts ? JSON.stringify(input.facts) : null, input.concepts ? JSON.stringify(input.concepts) : null, input.filesModified ? JSON.stringify(input.filesModified) : null, timestamp, input.projectPath || null);
|
|
17
17
|
return result.lastInsertRowid;
|
|
@@ -20,9 +20,9 @@ export class ObservationStore {
|
|
|
20
20
|
* Get observations by session ID
|
|
21
21
|
*/
|
|
22
22
|
getBySession(sessionId, limit = 50) {
|
|
23
|
-
const rows = this.db.prepare(`
|
|
24
|
-
SELECT * FROM observations WHERE sessionId = ?
|
|
25
|
-
ORDER BY timestamp DESC LIMIT ?
|
|
23
|
+
const rows = this.db.prepare(`
|
|
24
|
+
SELECT * FROM observations WHERE sessionId = ?
|
|
25
|
+
ORDER BY timestamp DESC LIMIT ?
|
|
26
26
|
`).all(sessionId, limit);
|
|
27
27
|
return rows.map(this.rowToObservation);
|
|
28
28
|
}
|
|
@@ -31,15 +31,15 @@ export class ObservationStore {
|
|
|
31
31
|
*/
|
|
32
32
|
getRecent(limit = 10, type) {
|
|
33
33
|
if (type) {
|
|
34
|
-
const rows = this.db.prepare(`
|
|
35
|
-
SELECT * FROM observations WHERE type = ?
|
|
36
|
-
ORDER BY timestamp DESC LIMIT ?
|
|
34
|
+
const rows = this.db.prepare(`
|
|
35
|
+
SELECT * FROM observations WHERE type = ?
|
|
36
|
+
ORDER BY timestamp DESC LIMIT ?
|
|
37
37
|
`).all(type, limit);
|
|
38
38
|
return rows.map(this.rowToObservation);
|
|
39
39
|
}
|
|
40
|
-
const rows = this.db.prepare(`
|
|
41
|
-
SELECT * FROM observations
|
|
42
|
-
ORDER BY timestamp DESC LIMIT ?
|
|
40
|
+
const rows = this.db.prepare(`
|
|
41
|
+
SELECT * FROM observations
|
|
42
|
+
ORDER BY timestamp DESC LIMIT ?
|
|
43
43
|
`).all(limit);
|
|
44
44
|
return rows.map(this.rowToObservation);
|
|
45
45
|
}
|
|
@@ -47,9 +47,9 @@ export class ObservationStore {
|
|
|
47
47
|
* Get observations by type
|
|
48
48
|
*/
|
|
49
49
|
getByType(type, limit = 20) {
|
|
50
|
-
const rows = this.db.prepare(`
|
|
51
|
-
SELECT * FROM observations WHERE type = ?
|
|
52
|
-
ORDER BY timestamp DESC LIMIT ?
|
|
50
|
+
const rows = this.db.prepare(`
|
|
51
|
+
SELECT * FROM observations WHERE type = ?
|
|
52
|
+
ORDER BY timestamp DESC LIMIT ?
|
|
53
53
|
`).all(type, limit);
|
|
54
54
|
return rows.map(this.rowToObservation);
|
|
55
55
|
}
|
|
@@ -58,23 +58,23 @@ export class ObservationStore {
|
|
|
58
58
|
*/
|
|
59
59
|
search(query, limit = 20) {
|
|
60
60
|
try {
|
|
61
|
-
const rows = this.db.prepare(`
|
|
62
|
-
SELECT o.*, bm25(observations_fts) as rank
|
|
63
|
-
FROM observations_fts fts
|
|
64
|
-
JOIN observations o ON o.id = fts.rowid
|
|
65
|
-
WHERE observations_fts MATCH ?
|
|
66
|
-
ORDER BY rank
|
|
67
|
-
LIMIT ?
|
|
61
|
+
const rows = this.db.prepare(`
|
|
62
|
+
SELECT o.*, bm25(observations_fts) as rank
|
|
63
|
+
FROM observations_fts fts
|
|
64
|
+
JOIN observations o ON o.id = fts.rowid
|
|
65
|
+
WHERE observations_fts MATCH ?
|
|
66
|
+
ORDER BY rank
|
|
67
|
+
LIMIT ?
|
|
68
68
|
`).all(query, limit);
|
|
69
69
|
return rows.map(this.rowToObservation);
|
|
70
70
|
}
|
|
71
71
|
catch {
|
|
72
72
|
// FTS5 not available, fallback to LIKE
|
|
73
73
|
const pattern = `%${query}%`;
|
|
74
|
-
const rows = this.db.prepare(`
|
|
75
|
-
SELECT * FROM observations
|
|
76
|
-
WHERE title LIKE ? OR narrative LIKE ? OR facts LIKE ? OR concepts LIKE ?
|
|
77
|
-
ORDER BY timestamp DESC LIMIT ?
|
|
74
|
+
const rows = this.db.prepare(`
|
|
75
|
+
SELECT * FROM observations
|
|
76
|
+
WHERE title LIKE ? OR narrative LIKE ? OR facts LIKE ? OR concepts LIKE ?
|
|
77
|
+
ORDER BY timestamp DESC LIMIT ?
|
|
78
78
|
`).all(pattern, pattern, pattern, pattern, limit);
|
|
79
79
|
return rows.map(this.rowToObservation);
|
|
80
80
|
}
|
|
@@ -83,8 +83,8 @@ export class ObservationStore {
|
|
|
83
83
|
* Get observation statistics
|
|
84
84
|
*/
|
|
85
85
|
getStats() {
|
|
86
|
-
const types = this.db.prepare(`
|
|
87
|
-
SELECT type, COUNT(*) as count FROM observations GROUP BY type
|
|
86
|
+
const types = this.db.prepare(`
|
|
87
|
+
SELECT type, COUNT(*) as count FROM observations GROUP BY type
|
|
88
88
|
`).all();
|
|
89
89
|
const byType = {};
|
|
90
90
|
let total = 0;
|