mixgram 1.3.7 → 2.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.
Files changed (37) hide show
  1. package/README.md +68 -345
  2. package/bin/mixgram.js +51 -160
  3. package/examples/embedding-demo.js +22 -142
  4. package/package.json +19 -19
  5. package/spec/bench-indexing.js +23 -211
  6. package/spec/bench-search.js +26 -212
  7. package/spec/run-tests.js +1 -214
  8. package/spec/scenarios/scenarios.js +277 -607
  9. package/spec/sdd.md +14 -988
  10. package/spec/tdd.md +15 -1232
  11. package/spec/test-large-document.js +20 -91
  12. package/src/config.js +57 -48
  13. package/src/core/documents/documents.js +62 -224
  14. package/src/core/embeddings/embedder.js +14 -54
  15. package/src/core/embeddings/queue.js +33 -106
  16. package/src/core/embeddings/vectorStore.js +30 -111
  17. package/src/core/embeddings/worker-process.js +23 -74
  18. package/src/core/indexing/indexer.js +51 -237
  19. package/src/core/indexing/parser.js +13 -114
  20. package/src/core/indexing/reindex.js +28 -137
  21. package/src/core/search/search.js +64 -158
  22. package/src/db/migrations/001_initial.sql +14 -63
  23. package/src/db/sqlite.js +19 -29
  24. package/src/fs/paths.js +11 -101
  25. package/src/fs/watcher.js +15 -48
  26. package/src/mcp/cli-adapter.js +32 -110
  27. package/src/mcp/server.js +64 -141
  28. package/src/mcp/tool-registry.js +21 -132
  29. package/src/mcp/tools.js +27 -199
  30. package/src/utils/markdown.js +15 -82
  31. package/spec/fixtures/realistic-content.js +0 -106
  32. package/spec/reporter.js +0 -127
  33. package/spec/run-tests-runner.js +0 -40
  34. package/src/core/embeddings/worker.js +0 -27
  35. package/src/core/prompts/prompts.js +0 -15
  36. package/src/core/sessions/sessions.js +0 -27
  37. package/src/utils/ids.js +0 -27
package/spec/run-tests.js CHANGED
@@ -1,215 +1,2 @@
1
1
  #!/usr/bin/env node
2
- /**
3
- * Black-box scenario tests for Mixgram.
4
- * Run: node spec/run-tests.js
5
- * Visual mode (narrative + inputs/outputs in console): node spec/run-tests.js --visual
6
- */
7
- import fs from 'fs';
8
- import path from 'path';
9
- import os from 'os';
10
- import { spawnSync } from 'child_process';
11
- import { fileURLToPath } from 'url';
12
- import { loadConfig } from '../src/config.js';
13
- import { createToolHandlers } from '../src/mcp/tools.js';
14
- import { getToolDefinitions } from '../src/mcp/tool-registry.js';
15
- import { closeDb, getDb } from '../src/db/sqlite.js';
16
- import { scenarios } from './scenarios/scenarios.js';
17
- import { runLargeDocumentTest } from './test-large-document.js';
18
- import * as reporter from './reporter.js';
19
-
20
- const __filename = fileURLToPath(import.meta.url);
21
- const __dirname = path.dirname(__filename);
22
-
23
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'mixgram-test-'));
24
- const config = loadConfig({
25
- homeMemoryRoot: path.join(tmpDir, 'home', 'memory'),
26
- projectMemoryRoot: path.join(tmpDir, 'docs'),
27
- sqlitePath: path.join(tmpDir, '.mixgram', 'index.db')
28
- });
29
- fs.mkdirSync(path.dirname(config.sqlitePath), { recursive: true });
30
-
31
- const h = createToolHandlers(config);
32
-
33
- // Ensure every tool in the registry has a handler (CLI and MCP both use the same registry)
34
- const definitions = getToolDefinitions();
35
- for (const def of definitions) {
36
- if (!h[def.name]) throw new Error(`Tool "${def.name}" in registry has no handler in createToolHandlers`);
37
- }
38
- if (definitions.length === 0) throw new Error('Tool registry is empty');
39
-
40
- function parse(res) {
41
- return JSON.parse(res.content[0].text);
42
- }
43
-
44
- let totalPassed = 0;
45
- let totalFailed = 0;
46
-
47
- const ctx = {
48
- h,
49
- parse,
50
- config,
51
- fs: fs,
52
- reporter,
53
- shared: {}
54
- };
55
-
56
- function runCliSetupChecks() {
57
- const cliTmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'mixgram-cli-test-'));
58
- const repoRoot = path.dirname(__dirname);
59
-
60
- if (reporter.VISUAL) {
61
- reporter.startScenario('CLI setup cursor config', 'Verify Cursor setup writes project-memory arg for project-scoped memory.');
62
- }
63
-
64
- let p = 0;
65
- let f = 0;
66
- const ok = (cond, msg) => {
67
- if (cond) p++;
68
- else f++;
69
- if (reporter.VISUAL) reporter.check(msg, cond);
70
- };
71
-
72
- try {
73
- const result = spawnSync(process.execPath, [path.join(repoRoot, 'bin', 'mixgram.js'), 'setup', 'cursor'], {
74
- cwd: repoRoot,
75
- env: { ...process.env, HOME: cliTmpDir },
76
- encoding: 'utf8'
77
- });
78
-
79
- ok(result.status === 0, 'setup cursor exits successfully');
80
-
81
- const cursorConfigPath = path.join(cliTmpDir, '.cursor', 'mcp.json');
82
- ok(fs.existsSync(cursorConfigPath), 'cursor mcp.json created');
83
-
84
- const cursorConfig = JSON.parse(fs.readFileSync(cursorConfigPath, 'utf8'));
85
- const entry = cursorConfig?.mcpServers?.mixgram;
86
- ok(entry?.command === 'mixgram', 'cursor entry command preserved');
87
- const hasProjectMemory = Array.isArray(entry?.args) && entry.args.includes('--project-memory') && entry.args.includes('${workspaceFolder}/docs');
88
- ok(hasProjectMemory, 'cursor entry uses --project-memory ${workspaceFolder}/docs');
89
- } catch (err) {
90
- if (reporter.VISUAL) reporter.check('CLI setup cursor config threw', false, err.message);
91
- f += 1;
92
- } finally {
93
- try { fs.rmSync(cliTmpDir, { recursive: true, force: true }); } catch (_) {}
94
- }
95
-
96
- if (reporter.VISUAL) reporter.endScenario(p, f);
97
- totalPassed += p;
98
- totalFailed += f;
99
- }
100
-
101
- async function runScenarios() {
102
- for (const scenario of scenarios) {
103
- if (scenario.name === 'Semantic / embeddings (save and search)' && !ctx.hSemantic) {
104
- const configSemantic = loadConfig({
105
- homeMemoryRoot: config.homeMemoryRoot,
106
- projectMemoryRoot: config.projectMemoryRoot,
107
- sqlitePath: config.sqlitePath,
108
- embeddings: { enabled: true }
109
- });
110
- ctx.hSemantic = createToolHandlers(configSemantic);
111
- }
112
-
113
- try {
114
- const { passed, failed } = await scenario.run(ctx);
115
- totalPassed += passed;
116
- totalFailed += failed;
117
- } catch (err) {
118
- if (reporter.VISUAL) {
119
- reporter.check(scenario.name + ' run', false, err.message);
120
- }
121
- console.error('Scenario "' + scenario.name + '" threw:', err.message);
122
- totalFailed += 1;
123
- }
124
- }
125
- }
126
-
127
- async function runLegacySemanticKnn() {
128
- const configSemantic = ctx.hSemantic
129
- ? loadConfig({
130
- homeMemoryRoot: config.homeMemoryRoot,
131
- projectMemoryRoot: config.projectMemoryRoot,
132
- sqlitePath: config.sqlitePath,
133
- embeddings: { enabled: true }
134
- })
135
- : null;
136
- if (!configSemantic) return;
137
-
138
- const { getEmbedder } = await import('../src/core/embeddings/embedder.js');
139
- const { getVectorStore } = await import('../src/core/embeddings/vectorStore.js');
140
- const embedder = await getEmbedder(configSemantic);
141
- const vectorStore = await getVectorStore(configSemantic);
142
-
143
- if (reporter.VISUAL) {
144
- reporter.startScenario('Embedder and vector store (KNN)', 'Verify embedder and vectorStore APIs and semantic search for persistence doc.');
145
- }
146
-
147
- let p = 0, f = 0;
148
- const ok = (cond, msg) => { if (cond) p++; else f++; if (reporter.VISUAL) reporter.check(msg, cond); };
149
-
150
- if (embedder) {
151
- const vec = await embedder.embed('Embedding test phrase.');
152
- ok(vec instanceof Float32Array && vec.length === embedder.dimensions, 'embedder.embed returns Float32Array of correct dimensions');
153
- }
154
- if (vectorStore) {
155
- ok(typeof vectorStore.insert === 'function' && typeof vectorStore.search === 'function', 'vectorStore has insert and search');
156
- }
157
-
158
- const hSemantic = ctx.hSemantic || createToolHandlers(configSemantic);
159
- const docPersistence = 'Los datos se guardan en SQLite y la búsqueda es una forma de persistencia.';
160
- const savePersist = await hSemantic.mem_save({
161
- title: 'Persistencia y búsqueda',
162
- type: 'reference',
163
- scope: 'project',
164
- project: 'castlebravo',
165
- topic_key: 'test/persistencia-sqlite',
166
- content: docPersistence
167
- });
168
- const persistId = parse(savePersist).id;
169
- ok(!!persistId, 'saved persistence doc');
170
- const db = getDb(configSemantic);
171
- const docRow = db.prepare('SELECT id, body, content_hash FROM documents WHERE id = ?').get(persistId);
172
- ok(!!docRow, 'document exists for persistence doc');
173
- if (embedder && vectorStore && docRow?.body) {
174
- const embedding = await embedder.embed(docRow.body);
175
- await vectorStore.ensureTables(configSemantic);
176
- await vectorStore.insert(configSemantic, {
177
- chunk_id: docRow.id,
178
- document_id: docRow.id,
179
- content_hash: docRow.content_hash,
180
- embedding
181
- });
182
- const queryEmb = await embedder.embed('dónde se persisten los datos');
183
- const knnResults = await vectorStore.search(configSemantic, queryEmb, 5, { similarityThreshold: 0.5 });
184
- ok(knnResults.length >= 1, 'KNN search returns at least one result');
185
- const found = knnResults.some((r) => r.document_id === persistId);
186
- ok(found, 'persistence doc found by semantic search');
187
- }
188
-
189
- if (reporter.VISUAL) reporter.endScenario(p, f);
190
- totalPassed += p;
191
- totalFailed += f;
192
- }
193
-
194
- async function run() {
195
- runCliSetupChecks();
196
- await runScenarios();
197
- await runLegacySemanticKnn();
198
-
199
- const largeResult = runLargeDocumentTest(config);
200
- totalPassed += largeResult.passed;
201
- totalFailed += largeResult.failed;
202
-
203
- closeDb();
204
- try { fs.rmSync(tmpDir, { recursive: true }); } catch (_) {}
205
-
206
- reporter.summary(totalPassed, totalFailed);
207
- process.exitCode = totalFailed > 0 ? 1 : 0;
208
- }
209
-
210
- run().catch((err) => {
211
- console.error(err);
212
- closeDb();
213
- try { fs.rmSync(tmpDir, { recursive: true }); } catch (_) {}
214
- process.exitCode = 1;
215
- });
2
+ import './scenarios/scenarios.js';