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,317 @@
1
+ # AMALFA MCP Server Setup
2
+
3
+ **Guide to configuring AMALFA as an MCP server for Claude Desktop, Cursor, Windsurf, and other MCP clients.**
4
+
5
+ ---
6
+
7
+ ## Prerequisites
8
+
9
+ 1. **Bun installed** (`v1.0+`)
10
+ 2. **AMALFA repository cloned** and dependencies installed:
11
+ ```bash
12
+ git clone https://github.com/pjsvis/amalfa.git
13
+ cd amalfa
14
+ bun install
15
+ ```
16
+ 3. **Database initialized** (see Data Preparation below)
17
+
18
+ ---
19
+
20
+ ## Step 1: Prepare Your Data
21
+
22
+ Before starting the MCP server, you need to:
23
+
24
+ 1. **Configure sources** in `amalfa.config.json`:
25
+ ```json
26
+ {
27
+ "sources": ["./docs", "./playbooks"],
28
+ "database": ".amalfa/resonance.db",
29
+ "embeddings": {
30
+ "model": "BAAI/bge-small-en-v1.5",
31
+ "dimensions": 384
32
+ }
33
+ }
34
+ ```
35
+
36
+ 2. **Ingest your markdown documents**:
37
+ ```bash
38
+ bun run scripts/cli/ingest.ts
39
+ ```
40
+
41
+ This will:
42
+ - Parse all markdown files from your source directories
43
+ - Generate embeddings (first run downloads the model to `.amalfa/cache/`)
44
+ - Create the SQLite database at `.amalfa/resonance.db`
45
+
46
+ ---
47
+
48
+ ## Step 2: Generate MCP Configuration
49
+
50
+ Run the setup script to generate your machine-specific config:
51
+
52
+ ```bash
53
+ bun run scripts/setup_mcp.ts
54
+ ```
55
+
56
+ This will output configuration JSON like:
57
+
58
+ ```json
59
+ {
60
+ "mcpServers": {
61
+ "amalfa": {
62
+ "command": "bun",
63
+ "args": [
64
+ "run",
65
+ "/absolute/path/to/amalfa/src/mcp/index.ts"
66
+ ],
67
+ "env": {
68
+ "PATH": "..."
69
+ }
70
+ }
71
+ }
72
+ }
73
+ ```
74
+
75
+ **Important:** The path is absolute and machine-specific. If you move the amalfa folder, run this script again.
76
+
77
+ ---
78
+
79
+ ## Step 3: Configure Your MCP Client
80
+
81
+ ### Claude Desktop (macOS)
82
+
83
+ 1. **Open Claude Desktop config**:
84
+ ```bash
85
+ open ~/Library/Application\ Support/Claude/claude_desktop_config.json
86
+ ```
87
+
88
+ Or create it if it doesn't exist:
89
+ ```bash
90
+ mkdir -p ~/Library/Application\ Support/Claude
91
+ touch ~/Library/Application\ Support/Claude/claude_desktop_config.json
92
+ ```
93
+
94
+ 2. **Add the AMALFA server** to the `mcpServers` section:
95
+ ```json
96
+ {
97
+ "mcpServers": {
98
+ "amalfa": {
99
+ "command": "bun",
100
+ "args": [
101
+ "run",
102
+ "/Users/yourusername/path/to/amalfa/src/mcp/index.ts"
103
+ ],
104
+ "env": {
105
+ "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
106
+ }
107
+ }
108
+ }
109
+ }
110
+ ```
111
+
112
+ **Note:** Use the exact JSON output from Step 2.
113
+
114
+ 3. **Restart Claude Desktop**
115
+
116
+ 4. **Verify connection**: In Claude Desktop, check the MCP icon/status—you should see "amalfa" listed as a connected server.
117
+
118
+ ### Cursor / Windsurf
119
+
120
+ Check your IDE's MCP configuration documentation. The setup is similar—add the JSON block to the appropriate config file.
121
+
122
+ ---
123
+
124
+ ## Step 4: Test the Connection
125
+
126
+ ### From Claude Desktop
127
+
128
+ Ask Claude:
129
+
130
+ ```
131
+ Search my knowledge base for "embeddings"
132
+ ```
133
+
134
+ Claude should use the `search_documents` tool and return results from your markdown files.
135
+
136
+ ### From Command Line (Debug Mode)
137
+
138
+ You can test the MCP server directly:
139
+
140
+ ```bash
141
+ bun run src/mcp/index.ts
142
+ ```
143
+
144
+ This starts the server in stdio mode. It will log to `.mcp.log`.
145
+
146
+ Check the logs:
147
+ ```bash
148
+ tail -f .amalfa/.mcp.log
149
+ ```
150
+
151
+ ---
152
+
153
+ ## Available MCP Tools
154
+
155
+ Once connected, your AI agent can use these tools:
156
+
157
+ ### 1. `search_documents`
158
+ **Description:** Semantic search over your knowledge base
159
+ **Parameters:**
160
+ - `query` (string, required): Search query
161
+ - `limit` (number, optional): Max results (default: 20)
162
+
163
+ **Example:**
164
+ ```
165
+ Search for documents about "vector embeddings"
166
+ ```
167
+
168
+ ### 2. `read_node_content`
169
+ **Description:** Read full markdown content of a specific document
170
+ **Parameters:**
171
+ - `id` (string, required): Document ID from search results
172
+
173
+ **Example:**
174
+ ```
175
+ Read the full content of document "docs/embeddings.md"
176
+ ```
177
+
178
+ ### 3. `explore_links`
179
+ **Description:** Find related documents (graph traversal)
180
+ **Parameters:**
181
+ - `id` (string, required): Starting document ID
182
+ - `relation` (string, optional): Relationship type
183
+
184
+ **Example:**
185
+ ```
186
+ Show me documents related to "playbooks/vector-search.md"
187
+ ```
188
+
189
+ ### 4. `list_directory_structure`
190
+ **Description:** List all documents in the knowledge base
191
+ **Parameters:** None
192
+
193
+ **Example:**
194
+ ```
195
+ List all documents in my knowledge base
196
+ ```
197
+
198
+ ### 5. `inject_tags` (Experimental)
199
+ **Description:** Add semantic tags to a document
200
+ **Parameters:**
201
+ - `file_path` (string, required): Path to markdown file
202
+ - `tags` (array, required): List of tags to add
203
+
204
+ ---
205
+
206
+ ## Troubleshooting
207
+
208
+ ### "Server not connecting"
209
+
210
+ 1. **Check Bun is in PATH**:
211
+ ```bash
212
+ which bun
213
+ ```
214
+
215
+ 2. **Verify database exists**:
216
+ ```bash
217
+ ls -la .amalfa/resonance.db
218
+ ```
219
+
220
+ If missing, run ingestion again:
221
+ ```bash
222
+ bun run scripts/cli/ingest.ts
223
+ ```
224
+
225
+ 3. **Check server logs**:
226
+ ```bash
227
+ tail -n 50 .amalfa/.mcp.log
228
+ ```
229
+
230
+ ### "No results from search"
231
+
232
+ 1. **Verify database has data**:
233
+ ```bash
234
+ sqlite3 .amalfa/resonance.db "SELECT COUNT(*) FROM nodes;"
235
+ ```
236
+
237
+ Should return a number > 0.
238
+
239
+ 2. **Check embeddings**:
240
+ ```bash
241
+ sqlite3 .amalfa/resonance.db "SELECT COUNT(*) FROM node_embeddings;"
242
+ ```
243
+
244
+ 3. **Re-run ingestion** if counts are 0:
245
+ ```bash
246
+ bun run scripts/cli/ingest.ts
247
+ ```
248
+
249
+ ### "Error: ENOENT: no such file or directory"
250
+
251
+ The absolute path in your config is incorrect. Re-run:
252
+ ```bash
253
+ bun run scripts/setup_mcp.ts
254
+ ```
255
+
256
+ And update your MCP client config with the new path.
257
+
258
+ ---
259
+
260
+ ## Advanced Configuration
261
+
262
+ ### Custom Database Path
263
+
264
+ Edit `amalfa.config.json`:
265
+ ```json
266
+ {
267
+ "database": ".amalfa/my-custom.db"
268
+ }
269
+ ```
270
+
271
+ Then re-ingest and restart the MCP server.
272
+
273
+ ### Multiple Source Directories
274
+
275
+ ```json
276
+ {
277
+ "sources": [
278
+ "./docs",
279
+ "./playbooks",
280
+ "../other-project/docs"
281
+ ]
282
+ }
283
+ ```
284
+
285
+ ### Environment Variables
286
+
287
+ You can override config with environment variables in your MCP client config:
288
+
289
+ ```json
290
+ {
291
+ "mcpServers": {
292
+ "amalfa": {
293
+ "command": "bun",
294
+ "args": ["run", "/path/to/amalfa/src/mcp/index.ts"],
295
+ "env": {
296
+ "AMALFA_DB": ".amalfa/custom.db",
297
+ "PATH": "..."
298
+ }
299
+ }
300
+ }
301
+ }
302
+ ```
303
+
304
+ ---
305
+
306
+ ## Next Steps
307
+
308
+ - **[User Guide](./user-guide.md)** - Learn how to structure your markdown for best results
309
+ - **[VISION-AGENT-LEARNING.md](./VISION-AGENT-LEARNING.md)** - Understand the brief-debrief-playbook pattern
310
+ - **[Configuration Status](./docs/_current-config-status.md)** - Configuration reference
311
+
312
+ ---
313
+
314
+ ## Support
315
+
316
+ - **Issues:** https://github.com/pjsvis/amalfa/issues
317
+ - **Discussions:** https://github.com/pjsvis/amalfa/discussions
@@ -0,0 +1,168 @@
1
+ # AMALFA MCP Quick Start
2
+
3
+ **Get AMALFA running with Claude Desktop in 5 minutes.**
4
+
5
+ ---
6
+
7
+ ## Current Status
8
+
9
+ ✅ **Database exists**: `.amalfa/resonance.db` (2.4 MB)
10
+ ✅ **Dependencies installed**: `node_modules/` present
11
+ ✅ **MCP server ready**: `src/mcp/index.ts`
12
+
13
+ ---
14
+
15
+ ## Quick Setup (Claude Desktop)
16
+
17
+ ### 1. Generate your configuration
18
+
19
+ ```bash
20
+ cd /Users/petersmith/Documents/GitHub/amalfa
21
+ bun run scripts/setup_mcp.ts
22
+ ```
23
+
24
+ Copy the JSON output (will look like this):
25
+
26
+ ```json
27
+ {
28
+ "mcpServers": {
29
+ "amalfa": {
30
+ "command": "bun",
31
+ "args": [
32
+ "run",
33
+ "/Users/petersmith/Documents/GitHub/amalfa/src/mcp/index.ts"
34
+ ],
35
+ "env": {
36
+ "PATH": "..."
37
+ }
38
+ }
39
+ }
40
+ }
41
+ ```
42
+
43
+ ### 2. Add to Claude Desktop
44
+
45
+ **Open config file:**
46
+ ```bash
47
+ open ~/Library/Application\ Support/Claude/claude_desktop_config.json
48
+ ```
49
+
50
+ **Paste the JSON** from step 1. If the file already has content, merge the `amalfa` entry into the existing `mcpServers` object.
51
+
52
+ **Example final config:**
53
+ ```json
54
+ {
55
+ "mcpServers": {
56
+ "amalfa": {
57
+ "command": "bun",
58
+ "args": [
59
+ "run",
60
+ "/Users/petersmith/Documents/GitHub/amalfa/src/mcp/index.ts"
61
+ ],
62
+ "env": {
63
+ "PATH": "/usr/local/bin:/usr/bin:/bin"
64
+ }
65
+ }
66
+ }
67
+ }
68
+ ```
69
+
70
+ ### 3. Restart Claude Desktop
71
+
72
+ Quit and relaunch Claude Desktop completely (Cmd+Q, then reopen).
73
+
74
+ ### 4. Test it
75
+
76
+ In Claude Desktop, ask:
77
+
78
+ ```
79
+ Search my knowledge base for "embeddings"
80
+ ```
81
+
82
+ Claude should invoke the `search_documents` tool and return results from your markdown files.
83
+
84
+ ---
85
+
86
+ ## What's in Your Database?
87
+
88
+ Check what's indexed:
89
+
90
+ ```bash
91
+ sqlite3 .amalfa/resonance.db "SELECT COUNT(*) FROM nodes;"
92
+ sqlite3 .amalfa/resonance.db "SELECT COUNT(*) FROM node_embeddings;"
93
+ sqlite3 .amalfa/resonance.db "SELECT id, type FROM nodes LIMIT 10;"
94
+ ```
95
+
96
+ ---
97
+
98
+ ## Troubleshooting
99
+
100
+ ### "Server not connecting"
101
+
102
+ 1. **Verify Bun path in Claude config** matches your system:
103
+ ```bash
104
+ which bun
105
+ ```
106
+
107
+ 2. **Check server logs**:
108
+ ```bash
109
+ tail -f .amalfa/.mcp.log
110
+ ```
111
+
112
+ 3. **Test manually**:
113
+ ```bash
114
+ bun run src/mcp/index.ts
115
+ ```
116
+ Press Ctrl+C to stop. Check for errors in the startup output.
117
+
118
+ ### "No results from search"
119
+
120
+ **Option A: Re-ingest from current config**
121
+
122
+ Your `amalfa.config.json` currently points to:
123
+ ```json
124
+ {
125
+ "sources": ["../polyvis/docs", "../polyvis/playbooks"]
126
+ }
127
+ ```
128
+
129
+ If you want to index **local** amalfa docs instead:
130
+
131
+ 1. **Edit** `amalfa.config.json`:
132
+ ```json
133
+ {
134
+ "sources": ["./docs", "./playbooks"],
135
+ "database": ".amalfa/resonance.db"
136
+ }
137
+ ```
138
+
139
+ 2. **Re-ingest**:
140
+ ```bash
141
+ bun run scripts/cli/ingest.ts
142
+ ```
143
+
144
+ **Option B: Keep polyvis sources**
145
+
146
+ If you want to keep searching polyvis content, ensure `../polyvis` exists and contains the docs/playbooks folders.
147
+
148
+ ---
149
+
150
+ ## Next Steps
151
+
152
+ - **[Full MCP Setup Guide](./MCP_SETUP.md)** - Advanced configuration, troubleshooting
153
+ - **[User Guide](./user-guide.md)** - How to structure markdown for best results
154
+ - **[Configuration Status](./docs/_current-config-status.md)** - All config files explained
155
+
156
+ ---
157
+
158
+ ## Available Tools
159
+
160
+ Once connected, Claude can use:
161
+
162
+ - `search_documents` - Semantic search
163
+ - `read_node_content` - Read full markdown file
164
+ - `explore_links` - Graph traversal
165
+ - `list_directory_structure` - List all documents
166
+ - `inject_tags` - Add tags (experimental)
167
+
168
+ See [MCP_SETUP.md](./MCP_SETUP.md) for details.