amalfa 1.0.0 → 1.0.2

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 (85) hide show
  1. package/README.md +226 -247
  2. package/amalfa.config.example.ts +8 -6
  3. package/docs/AGENT-METADATA-PATTERNS.md +1021 -0
  4. package/docs/CONFIG_E2E_VALIDATION.md +147 -0
  5. package/docs/CONFIG_UNIFICATION.md +187 -0
  6. package/docs/CONFIG_VALIDATION.md +103 -0
  7. package/docs/LEGACY_DEPRECATION.md +174 -0
  8. package/docs/MCP_SETUP.md +317 -0
  9. package/docs/QUICK_START_MCP.md +168 -0
  10. package/docs/SESSION-2026-01-06-METADATA-PATTERNS.md +346 -0
  11. package/docs/SETUP.md +464 -0
  12. package/docs/SETUP_COMPLETE.md +464 -0
  13. package/docs/VISION-AGENT-LEARNING.md +1242 -0
  14. package/docs/_current-config-status.md +93 -0
  15. package/package.json +6 -3
  16. package/polyvis.settings.json.bak +38 -0
  17. package/src/cli.ts +159 -31
  18. package/src/config/defaults.ts +73 -15
  19. package/src/core/VectorEngine.ts +18 -9
  20. package/src/daemon/index.ts +12 -8
  21. package/src/mcp/index.ts +62 -7
  22. package/src/pipeline/AmalfaIngestor.ts +22 -12
  23. package/src/pipeline/PreFlightAnalyzer.ts +434 -0
  24. package/src/resonance/DatabaseFactory.ts +3 -4
  25. package/src/resonance/db.ts +8 -6
  26. package/src/resonance/schema.ts +19 -1
  27. package/src/resonance/services/vector-daemon.ts +151 -0
  28. package/src/utils/DaemonManager.ts +147 -0
  29. package/src/utils/ZombieDefense.ts +5 -1
  30. package/:memory: +0 -0
  31. package/:memory:-shm +0 -0
  32. package/:memory:-wal +0 -0
  33. package/README.old.md +0 -112
  34. package/agents.config.json +0 -11
  35. package/drizzle/0000_minor_iron_fist.sql +0 -19
  36. package/drizzle/meta/0000_snapshot.json +0 -139
  37. package/drizzle/meta/_journal.json +0 -13
  38. package/example_usage.ts +0 -39
  39. package/experiment.sh +0 -35
  40. package/hello +0 -2
  41. package/index.html +0 -52
  42. package/knowledge/excalibur.md +0 -12
  43. package/plans/experience-graph-integration.md +0 -60
  44. package/prompts/gemini-king-mode-prompt.md +0 -46
  45. package/public/docs/MCP_TOOLS.md +0 -372
  46. package/schemas/README.md +0 -20
  47. package/schemas/cda.schema.json +0 -84
  48. package/schemas/conceptual-lexicon.schema.json +0 -75
  49. package/scratchpads/dummy-debrief-boxed.md +0 -39
  50. package/scratchpads/dummy-debrief.md +0 -27
  51. package/scratchpads/scratchpad-design.md +0 -50
  52. package/scratchpads/scratchpad-scrolling.md +0 -20
  53. package/scratchpads/scratchpad-toc-disappearance.md +0 -23
  54. package/scratchpads/scratchpad-toc.md +0 -28
  55. package/scratchpads/test_gardener.md +0 -7
  56. package/src/core/LLMClient.ts +0 -93
  57. package/src/core/TagEngine.ts +0 -56
  58. package/src/db/schema.ts +0 -46
  59. package/src/gardeners/AutoTagger.ts +0 -116
  60. package/src/pipeline/HarvesterPipeline.ts +0 -101
  61. package/src/pipeline/Ingestor.ts +0 -555
  62. package/src/resonance/cli/ingest.ts +0 -41
  63. package/src/resonance/cli/migrate.ts +0 -54
  64. package/src/resonance/config.ts +0 -40
  65. package/src/resonance/daemon.ts +0 -236
  66. package/src/resonance/pipeline/extract.ts +0 -89
  67. package/src/resonance/pipeline/transform_docs.ts +0 -60
  68. package/src/resonance/services/tokenizer.ts +0 -159
  69. package/src/resonance/transform/cda.ts +0 -393
  70. package/src/utils/EnvironmentVerifier.ts +0 -67
  71. package/substack/substack-playbook-1.md +0 -95
  72. package/substack/substack-playbook-2.md +0 -78
  73. package/tasks/ui-investigation.md +0 -26
  74. package/test-db +0 -0
  75. package/test-db-shm +0 -0
  76. package/test-db-wal +0 -0
  77. package/tests/canary/verify_pinch_check.ts +0 -44
  78. package/tests/fixtures/ingest_test.md +0 -12
  79. package/tests/fixtures/ingest_test_boxed.md +0 -13
  80. package/tests/fixtures/safety_test.md +0 -45
  81. package/tests/fixtures/safety_test_boxed.md +0 -49
  82. package/tests/fixtures/tagged_output.md +0 -49
  83. package/tests/fixtures/tagged_test.md +0 -49
  84. package/tests/mcp-server-settings.json +0 -8
  85. package/verify-embedder.ts +0 -54
@@ -0,0 +1,464 @@
1
+ # AMALFA Complete Setup Guide
2
+
3
+ **From zero to running MCP server in 5 minutes.**
4
+
5
+ ---
6
+
7
+ ## Prerequisites
8
+
9
+ - **Bun installed** (v1.0+): `curl -fsSL https://bun.sh/install | bash`
10
+ - **Git** for cloning the repository
11
+ - **Claude Desktop** (or another MCP client)
12
+
13
+ ---
14
+
15
+ ## Step 1: Install AMALFA
16
+
17
+ ### Option A: Install from npm (Recommended)
18
+
19
+ ```bash
20
+ npm install -g amalfa
21
+ # or
22
+ bun install -g amalfa
23
+ ```
24
+
25
+ **Package**: https://www.npmjs.com/package/amalfa
26
+
27
+ ### Option B: Clone from GitHub (Development)
28
+
29
+ ```bash
30
+ git clone https://github.com/pjsvis/amalfa.git
31
+ cd amalfa
32
+ bun install
33
+ ```
34
+
35
+ **Note**: Option A is recommended for users. Option B is for contributors and development.
36
+
37
+ ---
38
+
39
+ ## Step 2: Configure Sources
40
+
41
+ Create or edit `amalfa.config.json` in your project root:
42
+
43
+ ```json
44
+ {
45
+ "sources": ["./docs", "./playbooks"],
46
+ "database": ".amalfa/resonance.db",
47
+ "embeddings": {
48
+ "model": "BAAI/bge-small-en-v1.5",
49
+ "dimensions": 384
50
+ },
51
+ "watch": {
52
+ "enabled": true,
53
+ "debounce": 1000
54
+ },
55
+ "excludePatterns": ["node_modules", ".git", ".amalfa"]
56
+ }
57
+ ```
58
+
59
+ **Key fields**:
60
+ - `sources`: Directories containing your markdown files
61
+ - `database`: Where to store the SQLite database
62
+ - `embeddings.model`: Which embedding model to use (see [supported models](https://github.com/Anush008/fastembed-js))
63
+
64
+ **Example configs**:
65
+
66
+ <details>
67
+ <summary>Local Documentation</summary>
68
+
69
+ ```json
70
+ {
71
+ "sources": ["./docs", "./playbooks", "./briefs", "./debriefs"],
72
+ "database": ".amalfa/my-project.db"
73
+ }
74
+ ```
75
+ </details>
76
+
77
+ <details>
78
+ <summary>Cross-Project Knowledge</summary>
79
+
80
+ ```json
81
+ {
82
+ "sources": ["../project-a/docs", "../project-b/playbooks"],
83
+ "database": ".amalfa/shared-knowledge.db"
84
+ }
85
+ ```
86
+ </details>
87
+
88
+ ---
89
+
90
+ ## Step 3: Initialize Database
91
+
92
+ Run the init command to ingest your markdown files:
93
+
94
+ ```bash
95
+ amalfa init
96
+ ```
97
+
98
+ **What happens**:
99
+ 1. **Pre-flight analysis**: Validates all markdown files
100
+ 2. **Creates `.amalfa/` directory**
101
+ 3. **Generates embeddings**: Downloads model on first run (~90MB cache)
102
+ 4. **Creates SQLite database**: Stores graph structure and vectors
103
+ 5. **Reports stats**: Files processed, nodes created, embeddings generated
104
+
105
+ **Output example**:
106
+ ```
107
+ 🚀 AMALFA Initialization
108
+
109
+ 📁 Sources: ./docs, ./playbooks
110
+ 💾 Database: .amalfa/resonance.db
111
+ 🧠 Model: BAAI/bge-small-en-v1.5
112
+
113
+ 🔍 Running pre-flight analysis...
114
+
115
+ 📊 Pre-Flight Summary:
116
+ Total files: 96
117
+ Valid files: 96
118
+ Skipped files: 0
119
+ Total size: 0.54 MB
120
+ Estimated nodes: 96
121
+
122
+ 🗄️ Initializing database: /path/to/amalfa/.amalfa/resonance.db
123
+
124
+ 100% (96/96)
125
+
126
+ ✅ Initialization complete!
127
+
128
+ 📊 Summary:
129
+ Files processed: 96
130
+ Nodes created: 95
131
+ Edges created: 0
132
+ Embeddings: 95
133
+ Duration: 0.26s
134
+ ```
135
+
136
+ **Troubleshooting**:
137
+
138
+ <details>
139
+ <summary>⚠️ Pre-flight check failed with warnings</summary>
140
+
141
+ Fix issues or use:
142
+ ```bash
143
+ amalfa init --force
144
+ ```
145
+
146
+ Check `.amalfa-pre-flight.log` for details.
147
+ </details>
148
+
149
+ <details>
150
+ <summary>❌ No valid markdown files found</summary>
151
+
152
+ Verify your `sources` paths in `amalfa.config.json` exist and contain `.md` files.
153
+ </details>
154
+
155
+ ---
156
+
157
+ ## Step 4: Verify Installation
158
+
159
+ Run the doctor command to check everything is working:
160
+
161
+ ```bash
162
+ amalfa doctor
163
+ ```
164
+
165
+ **Expected output**:
166
+ ```
167
+ 🩺 AMALFA Health Check
168
+
169
+ ✓ Bun runtime: OK
170
+ ✓ Database found: /path/to/.amalfa/resonance.db (0.79 MB)
171
+ ✓ AMALFA directory: /path/to/.amalfa
172
+ ✓ Source directory: /path/to/docs
173
+ ✓ Source directory: /path/to/playbooks
174
+ ✓ FastEmbed: OK
175
+ ✓ MCP SDK: OK
176
+
177
+ ✅ All checks passed! AMALFA is ready to use.
178
+
179
+ Next steps:
180
+ amalfa serve # Start MCP server
181
+ amalfa stats # View database statistics
182
+ ```
183
+
184
+ **If issues are found**, the doctor will tell you what's missing and how to fix it.
185
+
186
+ ---
187
+
188
+ ## Step 5: Generate MCP Configuration
189
+
190
+ Generate the JSON configuration for your MCP client:
191
+
192
+ **If installed globally (npm/bun)**:
193
+ ```bash
194
+ amalfa setup-mcp
195
+ ```
196
+
197
+ **If cloned from GitHub**:
198
+ ```bash
199
+ bun run scripts/setup_mcp.ts
200
+ ```
201
+
202
+ **Output** (copy this JSON):
203
+ ```json
204
+ {
205
+ "mcpServers": {
206
+ "amalfa": {
207
+ "command": "bun",
208
+ "args": [
209
+ "run",
210
+ "/absolute/path/to/amalfa/src/mcp/index.ts"
211
+ ],
212
+ "env": {
213
+ "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
214
+ }
215
+ }
216
+ }
217
+ }
218
+ ```
219
+
220
+ **Note**: The path is absolute and machine-specific. If you move the `amalfa` folder, regenerate this config.
221
+
222
+ ---
223
+
224
+ ## Step 6: Configure MCP Client
225
+
226
+ ### Claude Desktop (macOS)
227
+
228
+ 1. **Open config file**:
229
+ ```bash
230
+ open ~/Library/Application\ Support/Claude/claude_desktop_config.json
231
+ ```
232
+
233
+ If it doesn't exist:
234
+ ```bash
235
+ mkdir -p ~/Library/Application\ Support/Claude
236
+ touch ~/Library/Application\ Support/Claude/claude_desktop_config.json
237
+ ```
238
+
239
+ 2. **Paste the JSON** from Step 5. If the file already has content, merge the `amalfa` entry into the existing `mcpServers` object.
240
+
241
+ 3. **Save and close**
242
+
243
+ ### Warp Preview
244
+
245
+ 1. Open Warp Preview MCP settings
246
+ 2. Toggle off any existing AMALFA server
247
+ 3. Toggle on (will reload config automatically)
248
+ 4. Check status - should show "Connected"
249
+
250
+ ### Other MCP Clients
251
+
252
+ Consult your client's documentation for MCP server configuration. The setup is similar - add the JSON block to the appropriate config file.
253
+
254
+ ---
255
+
256
+ ## Step 7: Restart Your MCP Client
257
+
258
+ **Claude Desktop**: Quit completely (Cmd+Q) and relaunch
259
+
260
+ **Warp Preview**: Toggle server off/on in MCP settings
261
+
262
+ ---
263
+
264
+ ## Step 8: Test the Connection
265
+
266
+ ### Quick Test
267
+
268
+ In your MCP client (e.g., Claude), ask:
269
+
270
+ ```
271
+ Search my knowledge base for "configuration"
272
+ ```
273
+
274
+ Claude should invoke the `search_documents` tool and return relevant results from your markdown files.
275
+
276
+ ### Detailed Test
277
+
278
+ Run the automated validation script:
279
+
280
+ ```bash
281
+ bun run scripts/test-config-search.ts
282
+ ```
283
+
284
+ This will:
285
+ - Load config
286
+ - Open database
287
+ - Run test queries
288
+ - Verify search accuracy
289
+ - Report results
290
+
291
+ **Expected**: All tests pass, 80%+ semantic accuracy
292
+
293
+ ---
294
+
295
+ ## Maintenance
296
+
297
+ ### View Statistics
298
+
299
+ ```bash
300
+ amalfa stats
301
+ ```
302
+
303
+ Shows database size, node count, embeddings, etc.
304
+
305
+ ### Re-ingest After Changes
306
+
307
+ After adding/modifying markdown files:
308
+
309
+ ```bash
310
+ amalfa init
311
+ ```
312
+
313
+ Or enable automatic watching:
314
+
315
+ ```bash
316
+ amalfa daemon start
317
+ ```
318
+
319
+ The daemon watches your source directories and auto-ingests changes.
320
+
321
+ ### Validate Configuration
322
+
323
+ ```bash
324
+ bun run validate-config
325
+ ```
326
+
327
+ Checks for config conflicts and issues.
328
+
329
+ ---
330
+
331
+ ## Available MCP Tools
332
+
333
+ Once connected, AI agents can use:
334
+
335
+ ### 1. `search_documents`
336
+ Semantic search over your knowledge base
337
+
338
+ **Parameters**:
339
+ - `query` (string): Search query
340
+ - `limit` (number, optional): Max results (default: 20)
341
+
342
+ **Example**: "Search for documents about TypeScript compilation"
343
+
344
+ ### 2. `read_node_content`
345
+ Read full markdown content of a specific document
346
+
347
+ **Parameters**:
348
+ - `id` (string): Document ID from search results
349
+
350
+ **Example**: "Read the full content of config-unification-test.md"
351
+
352
+ ### 3. `explore_links`
353
+ Find related documents (graph traversal)
354
+
355
+ **Parameters**:
356
+ - `id` (string): Starting document ID
357
+ - `relation` (string, optional): Relationship type
358
+
359
+ **Example**: "Show me documents related to embeddings-playbook.md"
360
+
361
+ ### 4. `list_directory_structure`
362
+ List all documents in the knowledge base
363
+
364
+ **Parameters**: None
365
+
366
+ **Example**: "List all documents in my knowledge base"
367
+
368
+ ### 5. `inject_tags` (Experimental)
369
+ Add semantic tags to a document
370
+
371
+ **Parameters**:
372
+ - `file_path` (string): Path to markdown file
373
+ - `tags` (array): Tags to add
374
+
375
+ **Example**: "Add #config #migration tags to the test document"
376
+
377
+ ---
378
+
379
+ ## Troubleshooting
380
+
381
+ ### Server Not Connecting
382
+
383
+ 1. **Check Bun path** matches your system:
384
+ ```bash
385
+ which bun
386
+ ```
387
+
388
+ 2. **Verify absolute path** in MCP config is correct
389
+
390
+ 3. **Check server logs**:
391
+ ```bash
392
+ tail -f .mcp.log
393
+ ```
394
+
395
+ 4. **Test manually**:
396
+ ```bash
397
+ bun run src/mcp/index.ts
398
+ ```
399
+ Press Ctrl+C to stop.
400
+
401
+ ### No Search Results
402
+
403
+ 1. **Verify database exists**:
404
+ ```bash
405
+ ls -lh .amalfa/*.db
406
+ ```
407
+
408
+ 2. **Check what's indexed**:
409
+ ```bash
410
+ amalfa stats
411
+ ```
412
+
413
+ 3. **Re-run ingestion**:
414
+ ```bash
415
+ amalfa init
416
+ ```
417
+
418
+ ### Pre-flight Errors
419
+
420
+ Check `.amalfa-pre-flight.log` for detailed analysis of markdown files:
421
+ ```bash
422
+ cat .amalfa-pre-flight.log
423
+ ```
424
+
425
+ Common issues:
426
+ - Invalid frontmatter
427
+ - Files too large (>1MB)
428
+ - Binary files in source directories
429
+
430
+ ---
431
+
432
+ ## File Structure After Setup
433
+
434
+ ```
435
+ your-project/
436
+ ├── amalfa.config.json # Your config
437
+ ├── .amalfa/
438
+ │ ├── resonance.db # SQLite database
439
+ │ ├── resonance.db-shm # WAL shared memory
440
+ │ ├── resonance.db-wal # Write-ahead log
441
+ │ └── cache/ # Embedding model cache (~90MB)
442
+ ├── .amalfa-daemon.pid # Daemon process ID (if running)
443
+ ├── .amalfa-daemon.log # Daemon logs
444
+ ├── .amalfa-pre-flight.log # Pre-flight analysis results
445
+ ├── .mcp.log # MCP server logs
446
+ └── [your markdown files]
447
+ ```
448
+
449
+ ---
450
+
451
+ ## Next Steps
452
+
453
+ - ✅ **Setup complete!**
454
+ - ⏭️ [User Guide](./user-guide.md) - Best practices for structuring markdown
455
+ - ⏭️ [MCP Tools Reference](./MCP_SETUP.md) - Detailed tool documentation
456
+ - ⏭️ [Configuration Guide](./CONFIG_UNIFICATION.md) - Advanced config options
457
+
458
+ ---
459
+
460
+ ## Getting Help
461
+
462
+ - **Issues**: https://github.com/pjsvis/amalfa/issues
463
+ - **Discussions**: https://github.com/pjsvis/amalfa/discussions
464
+ - **Documentation**: https://github.com/pjsvis/amalfa/tree/main/docs