@rbalchii/anchor-engine 4.7.0 → 4.8.1

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 (141) hide show
  1. package/LICENSE +608 -608
  2. package/README.md +513 -317
  3. package/anchor.bat +5 -5
  4. package/docs/AGENT_CONTROLLED_ENGINE.md +581 -0
  5. package/docs/API.md +314 -314
  6. package/docs/DEPLOYMENT.md +448 -448
  7. package/docs/INDEX.md +226 -226
  8. package/docs/MD_FILES_INVENTORY.md +166 -0
  9. package/docs/STAR_Whitepaper_Executive.md +216 -216
  10. package/docs/TROUBLESHOOTING.md +535 -535
  11. package/docs/arxiv/BIBLIOGRAPHY.bib +145 -145
  12. package/docs/arxiv/RELATED_WORK.tex +38 -38
  13. package/docs/arxiv/compile.bat +48 -48
  14. package/docs/arxiv/joss_response.md +32 -32
  15. package/docs/arxiv/prepare-submission.bat +46 -46
  16. package/docs/arxiv/review.md +127 -127
  17. package/docs/arxiv/star-whitepaper.tex +656 -656
  18. package/docs/code-patterns.md +289 -289
  19. package/docs/daily/TODAY_SUMMARY.md +245 -0
  20. package/docs/guides/BUILDING.md +64 -0
  21. package/docs/guides/INSTALL_NPM.md +160 -0
  22. package/docs/guides/NPM_PUBLISH_SUMMARY.md +231 -0
  23. package/docs/paper.md +124 -0
  24. package/docs/project/PROJECT_STATE_ASSESSMENT.md +312 -0
  25. package/docs/reviews/code-review-v4.8.1-decision-record.md +165 -0
  26. package/docs/testing/TESTING.md +213 -0
  27. package/docs/testing/TESTING_FRAMEWORK_COMPLETE.md +271 -0
  28. package/docs/testing/search-test-report.md +76 -0
  29. package/docs/whitepaper.md +445 -445
  30. package/engine/dist/commands/distill.js +21 -21
  31. package/engine/dist/config/index.d.ts +7 -0
  32. package/engine/dist/config/index.d.ts.map +1 -1
  33. package/engine/dist/config/index.js +22 -0
  34. package/engine/dist/config/index.js.map +1 -1
  35. package/engine/dist/config/paths.d.ts +1 -1
  36. package/engine/dist/config/paths.js +3 -3
  37. package/engine/dist/config/paths.js.map +1 -1
  38. package/engine/dist/core/db.js +131 -131
  39. package/engine/dist/mcp/server.d.ts +44 -0
  40. package/engine/dist/mcp/server.d.ts.map +1 -0
  41. package/engine/dist/mcp/server.js +427 -0
  42. package/engine/dist/mcp/server.js.map +1 -0
  43. package/engine/dist/native/index.d.ts +20 -21
  44. package/engine/dist/native/index.d.ts.map +1 -1
  45. package/engine/dist/profiling/atomization-profiling.js +3 -3
  46. package/engine/dist/profiling/bottleneck-identification.js +35 -35
  47. package/engine/dist/profiling/content-sanitization-profiling.js +86 -86
  48. package/engine/dist/routes/monitoring.js +8 -8
  49. package/engine/dist/routes/v1/admin.js +8 -8
  50. package/engine/dist/routes/v1/atoms.js +15 -15
  51. package/engine/dist/routes/v1/ingest.d.ts.map +1 -1
  52. package/engine/dist/routes/v1/ingest.js +39 -0
  53. package/engine/dist/routes/v1/ingest.js.map +1 -1
  54. package/engine/dist/routes/v1/system.d.ts.map +1 -1
  55. package/engine/dist/routes/v1/system.js +305 -6
  56. package/engine/dist/routes/v1/system.js.map +1 -1
  57. package/engine/dist/routes/v1/tags.js +2 -2
  58. package/engine/dist/services/backup/backup-restore.js +23 -23
  59. package/engine/dist/services/backup/backup.js +14 -14
  60. package/engine/dist/services/distillation/radial-distiller.d.ts +1 -0
  61. package/engine/dist/services/distillation/radial-distiller.d.ts.map +1 -1
  62. package/engine/dist/services/distillation/radial-distiller.js +23 -16
  63. package/engine/dist/services/distillation/radial-distiller.js.map +1 -1
  64. package/engine/dist/services/ingest/github-ingest-service.js +18 -18
  65. package/engine/dist/services/ingest/ingest-atomic.js +79 -79
  66. package/engine/dist/services/ingest/ingest.d.ts.map +1 -1
  67. package/engine/dist/services/ingest/ingest.js +28 -25
  68. package/engine/dist/services/ingest/ingest.js.map +1 -1
  69. package/engine/dist/services/ingest/watchdog.d.ts.map +1 -1
  70. package/engine/dist/services/ingest/watchdog.js +14 -24
  71. package/engine/dist/services/ingest/watchdog.js.map +1 -1
  72. package/engine/dist/services/llm/reader.js +9 -9
  73. package/engine/dist/services/mirror/mirror.js +5 -5
  74. package/engine/dist/services/mirror/mirror.js.map +1 -1
  75. package/engine/dist/services/research/researcher.js +8 -8
  76. package/engine/dist/services/scribe/scribe.js +27 -27
  77. package/engine/dist/services/search/context-inflator.js +34 -34
  78. package/engine/dist/services/search/explore.js +20 -20
  79. package/engine/dist/services/search/physics-tag-walker.js +208 -208
  80. package/engine/dist/services/search/query-parser.js +5 -5
  81. package/engine/dist/services/search/search-utils.js +3 -3
  82. package/engine/dist/services/search/search.js +36 -36
  83. package/engine/dist/services/search/sovereign-system-prompt.js +22 -22
  84. package/engine/dist/services/semantic/semantic-ingestion-service.js +47 -47
  85. package/engine/dist/services/semantic/semantic-search.js +21 -21
  86. package/engine/dist/services/synonyms/auto-synonym-generator.js +35 -35
  87. package/engine/dist/services/system-status.d.ts +34 -0
  88. package/engine/dist/services/system-status.d.ts.map +1 -1
  89. package/engine/dist/services/system-status.js +57 -1
  90. package/engine/dist/services/system-status.js.map +1 -1
  91. package/engine/dist/services/tags/discovery.js +5 -5
  92. package/engine/dist/services/tags/infector.js +6 -6
  93. package/engine/dist/services/tags/tag-auditor.js +51 -51
  94. package/engine/dist/services/taxonomy/taxonomy-manager.js +6 -6
  95. package/engine/dist/utils/tag-cleanup.js +5 -5
  96. package/engine/dist/utils/tag-modulation.js +1 -1
  97. package/engine/dist/utils/tag-modulation.js.map +1 -1
  98. package/engine/package.json +104 -105
  99. package/mcp-server/README.md +404 -0
  100. package/mcp-server/dist/index.d.ts +16 -0
  101. package/mcp-server/dist/index.d.ts.map +1 -0
  102. package/mcp-server/dist/index.js +709 -0
  103. package/mcp-server/dist/index.js.map +1 -0
  104. package/mcp-server/package.json +34 -0
  105. package/package.json +10 -2
  106. package/docs/archive/GIT_BACKUP_VERIFICATION.md +0 -297
  107. package/docs/archive/adoption-guide.md +0 -264
  108. package/docs/archive/adoption-preparation.md +0 -179
  109. package/docs/archive/agent-harness-integration.md +0 -227
  110. package/docs/archive/api-reference.md +0 -106
  111. package/docs/archive/api_flows_diagram.md +0 -118
  112. package/docs/archive/architecture.md +0 -410
  113. package/docs/archive/architecture_diagram.md +0 -174
  114. package/docs/archive/broader-adoption-preparation.md +0 -175
  115. package/docs/archive/browser-paradigm-architecture.md +0 -163
  116. package/docs/archive/chat-integration.md +0 -124
  117. package/docs/archive/community-adoption-materials.md +0 -103
  118. package/docs/archive/community-adoption.md +0 -147
  119. package/docs/archive/comparison-with-siloed-solutions.md +0 -192
  120. package/docs/archive/comprehensive-docs.md +0 -156
  121. package/docs/archive/data_flow_diagram.md +0 -251
  122. package/docs/archive/enhancement-implementation-summary.md +0 -146
  123. package/docs/archive/evolution-summary.md +0 -141
  124. package/docs/archive/ingestion_pipeline_diagram.md +0 -198
  125. package/docs/archive/native-module-profiling-results.md +0 -135
  126. package/docs/archive/positioning-document.md +0 -158
  127. package/docs/archive/positioning.md +0 -175
  128. package/docs/archive/query-builder-documentation.md +0 -218
  129. package/docs/archive/quick-reference.md +0 -40
  130. package/docs/archive/quickstart.md +0 -63
  131. package/docs/archive/relationship-narrative-discovery.md +0 -141
  132. package/docs/archive/search-logic-improvement-plan.md +0 -336
  133. package/docs/archive/search_architecture_diagram.md +0 -212
  134. package/docs/archive/semantic-architecture-guide.md +0 -97
  135. package/docs/archive/sequence-diagrams.md +0 -128
  136. package/docs/archive/system_components_diagram.md +0 -296
  137. package/docs/archive/test-framework-integration.md +0 -109
  138. package/docs/archive/testing-framework-documentation.md +0 -397
  139. package/docs/archive/testing-framework-summary.md +0 -121
  140. package/docs/archive/testing-framework.md +0 -377
  141. package/docs/archive/ui-architecture.md +0 -75
@@ -1,448 +1,448 @@
1
- # Anchor Engine - Deployment Guide
2
-
3
- **Version:** 4.8.0 | **Last Updated:** March 18, 2026
4
-
5
- ---
6
-
7
- ## Quick Deploy
8
-
9
- ### Local Development
10
- ```bash
11
- git clone https://github.com/RSBalchII/anchor-engine-node.git
12
- cd anchor-engine-node
13
- pnpm install
14
- pnpm build
15
- pnpm start
16
- ```
17
-
18
- ### Docker (Recommended for Production)
19
- ```bash
20
- docker-compose up -d
21
- docker-compose logs -f
22
- ```
23
-
24
- ---
25
-
26
- ## Deployment Options
27
-
28
- ### Option 1: Local Machine
29
-
30
- **Best for:** Personal use, development, testing
31
-
32
- **Requirements:**
33
- - Node.js v18+ (v20+ recommended)
34
- - PNPM package manager
35
- - 1GB RAM minimum (4GB+ recommended)
36
- - 10GB free storage
37
-
38
- **Steps:**
39
- 1. Clone repository
40
- 2. Install dependencies: `pnpm install`
41
- 3. Build: `pnpm build`
42
- 4. Start: `pnpm start`
43
- 5. Open: http://localhost:3160
44
-
45
- **Configuration:** Edit `user_settings.json`
46
-
47
- ---
48
-
49
- ### Option 2: Docker
50
-
51
- **Best for:** Production, isolated environments
52
-
53
- **Requirements:**
54
- - Docker 20.10+
55
- - Docker Compose 2.0+
56
- - 2GB RAM allocated to container
57
-
58
- **Steps:**
59
- ```bash
60
- # Build and run
61
- docker-compose up -d
62
-
63
- # View logs
64
- docker-compose logs -f
65
-
66
- # Stop
67
- docker-compose down
68
- ```
69
-
70
- **Volumes:**
71
- - `./inbox` → Auto-ingested files
72
- - `./external-inbox` → External sources
73
- - `./mirrored_brain` → Source of truth
74
- - `./backups` → Phoenix Protocol backups
75
- - `anchor-data` → PGlite database (persistent)
76
-
77
- **Environment Variables:**
78
- ```yaml
79
- environment:
80
- - PROJECT_ROOT=/app
81
- - CONTEXT_DIR=/app/engine/context_data
82
- - NOTEBOOK_DIR=/app/notebook
83
- ```
84
-
85
- ---
86
-
87
- ### Option 3: Cloud VPS
88
-
89
- **Best for:** Team access, 24/7 availability
90
-
91
- **Recommended Providers:**
92
- - DigitalOcean Droplet ($12/mo - 2GB RAM)
93
- - Linode Nanode ($5/mo - 1GB RAM)
94
- - AWS EC2 t3.small ($15/mo - 2GB RAM)
95
-
96
- **Steps:**
97
- 1. Provision Ubuntu 22.04 server
98
- 2. Install Node.js:
99
- ```bash
100
- curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
101
- sudo apt-get install -y nodejs
102
- ```
103
- 3. Install PNPM:
104
- ```bash
105
- sudo npm install -g pnpm
106
- ```
107
- 4. Clone and setup:
108
- ```bash
109
- git clone https://github.com/RSBalchII/anchor-engine-node.git
110
- cd anchor-engine-node
111
- pnpm install
112
- pnpm build
113
- ```
114
- 5. Run as systemd service:
115
- ```bash
116
- sudo nano /etc/systemd/system/anchor-engine.service
117
- ```
118
-
119
- ```ini
120
- [Unit]
121
- Description=Anchor Engine
122
- After=network.target
123
-
124
- [Service]
125
- Type=simple
126
- User=ubuntu
127
- WorkingDirectory=/home/ubuntu/anchor-engine-node
128
- ExecStart=/usr/bin/pnpm start
129
- Restart=always
130
-
131
- [Install]
132
- WantedBy=multi-user.target
133
- ```
134
-
135
- ```bash
136
- sudo systemctl enable anchor-engine
137
- sudo systemctl start anchor-engine
138
- sudo systemctl status anchor-engine
139
- ```
140
-
141
- 6. Configure firewall:
142
- ```bash
143
- sudo ufw allow 3160/tcp
144
- sudo ufw enable
145
- ```
146
-
147
- ---
148
-
149
- ### Option 4: Kubernetes
150
-
151
- **Best for:** Enterprise, auto-scaling
152
-
153
- **Requirements:**
154
- - Kubernetes 1.25+
155
- - PersistentVolume for data
156
-
157
- **Deployment YAML:**
158
- ```yaml
159
- apiVersion: apps/v1
160
- kind: Deployment
161
- metadata:
162
- name: anchor-engine
163
- spec:
164
- replicas: 1
165
- selector:
166
- matchLabels:
167
- app: anchor-engine
168
- template:
169
- metadata:
170
- labels:
171
- app: anchor-engine
172
- spec:
173
- containers:
174
- - name: anchor-engine
175
- image: anchor-engine:latest
176
- ports:
177
- - containerPort: 3160
178
- volumeMounts:
179
- - name: data
180
- mountPath: /app/mirrored_brain
181
- - name: backups
182
- mountPath: /app/backups
183
- resources:
184
- requests:
185
- memory: "1Gi"
186
- cpu: "500m"
187
- limits:
188
- memory: "2Gi"
189
- cpu: "1000m"
190
- volumes:
191
- - name: data
192
- persistentVolumeClaim:
193
- claimName: anchor-data-pvc
194
- - name: backups
195
- persistentVolumeClaim:
196
- claimName: anchor-backups-pvc
197
- ```
198
-
199
- ---
200
-
201
- ## Configuration
202
-
203
- ### user_settings.json
204
-
205
- **Location:** `~/.config/anchor/user_settings.json` or project root
206
-
207
- **Key Settings:**
208
- ```json
209
- {
210
- "server": {
211
- "host": "0.0.0.0",
212
- "port": 3160,
213
- "api_key": "your-secret-key"
214
- },
215
- "database": {
216
- "wipe_on_startup": false
217
- },
218
- "watcher": {
219
- "debounce_ms": 2000,
220
- "exclude_patterns": ["**/*.log", "**/node_modules/**"]
221
- },
222
- "search": {
223
- "max_chars_default": 524288,
224
- "strategy": "hybrid"
225
- },
226
- "adaptive_concurrency": {
227
- "environment": "auto",
228
- "sequential_threshold_mb": 2048,
229
- "parallel_threshold_mb": 8192
230
- }
231
- }
232
- ```
233
-
234
- ### Environment Variables
235
-
236
- | Variable | Default | Description |
237
- |----------|---------|-------------|
238
- | `ANCHOR_URL` | `http://localhost:3160` | API endpoint |
239
- | `ANCHOR_API_KEY` | (none) | API authentication |
240
- | `PROJECT_ROOT` | (auto-detect) | Project root path |
241
- | `CONTEXT_DIR` | (auto-detect) | Context data directory |
242
-
243
- ---
244
-
245
- ## Security
246
-
247
- ### Firewall Rules
248
-
249
- **Minimum Required:**
250
- ```bash
251
- # Allow Anchor Engine port
252
- sudo ufw allow 3160/tcp
253
-
254
- # If using MCP remotely (not recommended)
255
- sudo ufw allow 3161/tcp
256
- ```
257
-
258
- ### API Key Authentication
259
-
260
- 1. Generate key:
261
- ```bash
262
- openssl rand -hex 32
263
- ```
264
-
265
- 2. Add to `user_settings.json`:
266
- ```json
267
- {
268
- "server": {
269
- "api_key": "your-generated-key"
270
- }
271
- }
272
- ```
273
-
274
- 3. Use in requests:
275
- ```bash
276
- curl -H "Authorization: Bearer your-key" \
277
- http://localhost:3160/v1/stats
278
- ```
279
-
280
- ### HTTPS/TLS (Production)
281
-
282
- **With Nginx Reverse Proxy:**
283
- ```nginx
284
- server {
285
- listen 443 ssl;
286
- server_name anchor.yourdomain.com;
287
-
288
- ssl_certificate /etc/letsencrypt/live/anchor.yourdomain.com/fullchain.pem;
289
- ssl_certificate_key /etc/letsencrypt/live/anchor.yourdomain.com/privkey.pem;
290
-
291
- location / {
292
- proxy_pass http://localhost:3160;
293
- proxy_http_version 1.1;
294
- proxy_set_header Upgrade $http_upgrade;
295
- proxy_set_header Connection 'upgrade';
296
- proxy_set_header Host $host;
297
- proxy_cache_bypass $http_upgrade;
298
- }
299
- }
300
- ```
301
-
302
- ---
303
-
304
- ## Monitoring
305
-
306
- ### Health Checks
307
-
308
- **Endpoint:** `GET /health`
309
-
310
- **Response:**
311
- ```json
312
- {
313
- "status": "ok",
314
- "uptime": "2d 4h 15m",
315
- "memory_mb": 512
316
- }
317
- ```
318
-
319
- **Uptime Monitoring:**
320
- ```bash
321
- # Cron job every 5 minutes
322
- */5 * * * * curl -f http://localhost:3160/health || echo "Anchor Engine DOWN" | mail -s "Alert" admin@example.com
323
- ```
324
-
325
- ### Logs
326
-
327
- **Location:** `engine/logs/server.log`
328
-
329
- **Log Rotation:**
330
- ```bash
331
- sudo nano /etc/logrotate.d/anchor-engine
332
- ```
333
-
334
- ```
335
- /var/log/anchor-engine/*.log {
336
- daily
337
- rotate 7
338
- compress
339
- delaycompress
340
- notifempty
341
- create 0640 ubuntu ubuntu
342
- }
343
- ```
344
-
345
- ---
346
-
347
- ## Backup & Restore
348
-
349
- ### Manual Backup
350
- ```bash
351
- # Create backup
352
- curl -X POST http://localhost:3160/v1/backup
353
-
354
- # Backup location: ./backups/backup-YYYY-MM-DDTHH-MM-SS/
355
- ```
356
-
357
- ### Automated Backup
358
- ```bash
359
- # Cron job daily at 2am
360
- 0 2 * * * curl -X POST http://localhost:3160/v1/backup
361
- ```
362
-
363
- ### Restore
364
- ```bash
365
- curl -X POST http://localhost:3160/v1/backup/restore \
366
- -H "Content-Type: application/json" \
367
- -d '{"filename": "backup-2026-03-18T02-00-00"}'
368
- ```
369
-
370
- ---
371
-
372
- ## Troubleshooting
373
-
374
- ### Port Already in Use
375
- ```bash
376
- # Find process using port 3160
377
- lsof -i :3160
378
-
379
- # Kill process
380
- kill -9 <PID>
381
- ```
382
-
383
- ### Out of Memory
384
- ```json
385
- {
386
- "adaptive_concurrency": {
387
- "environment": "low_memory"
388
- }
389
- }
390
- ```
391
-
392
- ### Database Corruption
393
- ```bash
394
- # Stop engine
395
- pnpm stop
396
-
397
- # Delete database (data preserved in mirrored_brain/)
398
- rm -rf engine/context_data
399
-
400
- # Restart (auto-rebuilds)
401
- pnpm start
402
- ```
403
-
404
- ### Permission Errors
405
- ```bash
406
- # Fix ownership
407
- sudo chown -R $USER:$USER ~/.config/anchor
408
- sudo chown -R $USER:$USER ~/.local/share/anchor
409
- ```
410
-
411
- ---
412
-
413
- ## Performance Tuning
414
-
415
- ### Low Memory (<2GB RAM)
416
- ```json
417
- {
418
- "adaptive_concurrency": {
419
- "environment": "low_memory",
420
- "sequential_threshold_mb": 512
421
- },
422
- "search": {
423
- "max_chars_default": 262144
424
- }
425
- }
426
- ```
427
-
428
- ### High Performance (>8GB RAM)
429
- ```json
430
- {
431
- "adaptive_concurrency": {
432
- "environment": "high_memory",
433
- "parallel_threshold_mb": 4096,
434
- "max_concurrency": 10
435
- },
436
- "search": {
437
- "max_chars_default": 1048576
438
- }
439
- }
440
- ```
441
-
442
- ---
443
-
444
- ## Support
445
-
446
- - **Documentation:** [`docs/`](./)
447
- - **Issues:** https://github.com/RSBalchII/anchor-engine-node/issues
448
- - **Discussions:** https://github.com/RSBalchII/anchor-engine-node/discussions
1
+ # Anchor Engine - Deployment Guide
2
+
3
+ **Version:** 4.8.0 | **Last Updated:** March 18, 2026
4
+
5
+ ---
6
+
7
+ ## Quick Deploy
8
+
9
+ ### Local Development
10
+ ```bash
11
+ git clone https://github.com/RSBalchII/anchor-engine-node.git
12
+ cd anchor-engine-node
13
+ pnpm install
14
+ pnpm build
15
+ pnpm start
16
+ ```
17
+
18
+ ### Docker (Recommended for Production)
19
+ ```bash
20
+ docker-compose up -d
21
+ docker-compose logs -f
22
+ ```
23
+
24
+ ---
25
+
26
+ ## Deployment Options
27
+
28
+ ### Option 1: Local Machine
29
+
30
+ **Best for:** Personal use, development, testing
31
+
32
+ **Requirements:**
33
+ - Node.js v18+ (v20+ recommended)
34
+ - PNPM package manager
35
+ - 1GB RAM minimum (4GB+ recommended)
36
+ - 10GB free storage
37
+
38
+ **Steps:**
39
+ 1. Clone repository
40
+ 2. Install dependencies: `pnpm install`
41
+ 3. Build: `pnpm build`
42
+ 4. Start: `pnpm start`
43
+ 5. Open: http://localhost:3160
44
+
45
+ **Configuration:** Edit `user_settings.json`
46
+
47
+ ---
48
+
49
+ ### Option 2: Docker
50
+
51
+ **Best for:** Production, isolated environments
52
+
53
+ **Requirements:**
54
+ - Docker 20.10+
55
+ - Docker Compose 2.0+
56
+ - 2GB RAM allocated to container
57
+
58
+ **Steps:**
59
+ ```bash
60
+ # Build and run
61
+ docker-compose up -d
62
+
63
+ # View logs
64
+ docker-compose logs -f
65
+
66
+ # Stop
67
+ docker-compose down
68
+ ```
69
+
70
+ **Volumes:**
71
+ - `./inbox` → Auto-ingested files
72
+ - `./external-inbox` → External sources
73
+ - `./mirrored_brain` → Source of truth
74
+ - `./backups` → Phoenix Protocol backups
75
+ - `anchor-data` → PGlite database (persistent)
76
+
77
+ **Environment Variables:**
78
+ ```yaml
79
+ environment:
80
+ - PROJECT_ROOT=/app
81
+ - CONTEXT_DIR=/app/engine/context_data
82
+ - NOTEBOOK_DIR=/app/notebook
83
+ ```
84
+
85
+ ---
86
+
87
+ ### Option 3: Cloud VPS
88
+
89
+ **Best for:** Team access, 24/7 availability
90
+
91
+ **Recommended Providers:**
92
+ - DigitalOcean Droplet ($12/mo - 2GB RAM)
93
+ - Linode Nanode ($5/mo - 1GB RAM)
94
+ - AWS EC2 t3.small ($15/mo - 2GB RAM)
95
+
96
+ **Steps:**
97
+ 1. Provision Ubuntu 22.04 server
98
+ 2. Install Node.js:
99
+ ```bash
100
+ curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
101
+ sudo apt-get install -y nodejs
102
+ ```
103
+ 3. Install PNPM:
104
+ ```bash
105
+ sudo npm install -g pnpm
106
+ ```
107
+ 4. Clone and setup:
108
+ ```bash
109
+ git clone https://github.com/RSBalchII/anchor-engine-node.git
110
+ cd anchor-engine-node
111
+ pnpm install
112
+ pnpm build
113
+ ```
114
+ 5. Run as systemd service:
115
+ ```bash
116
+ sudo nano /etc/systemd/system/anchor-engine.service
117
+ ```
118
+
119
+ ```ini
120
+ [Unit]
121
+ Description=Anchor Engine
122
+ After=network.target
123
+
124
+ [Service]
125
+ Type=simple
126
+ User=ubuntu
127
+ WorkingDirectory=/home/ubuntu/anchor-engine-node
128
+ ExecStart=/usr/bin/pnpm start
129
+ Restart=always
130
+
131
+ [Install]
132
+ WantedBy=multi-user.target
133
+ ```
134
+
135
+ ```bash
136
+ sudo systemctl enable anchor-engine
137
+ sudo systemctl start anchor-engine
138
+ sudo systemctl status anchor-engine
139
+ ```
140
+
141
+ 6. Configure firewall:
142
+ ```bash
143
+ sudo ufw allow 3160/tcp
144
+ sudo ufw enable
145
+ ```
146
+
147
+ ---
148
+
149
+ ### Option 4: Kubernetes
150
+
151
+ **Best for:** Enterprise, auto-scaling
152
+
153
+ **Requirements:**
154
+ - Kubernetes 1.25+
155
+ - PersistentVolume for data
156
+
157
+ **Deployment YAML:**
158
+ ```yaml
159
+ apiVersion: apps/v1
160
+ kind: Deployment
161
+ metadata:
162
+ name: anchor-engine
163
+ spec:
164
+ replicas: 1
165
+ selector:
166
+ matchLabels:
167
+ app: anchor-engine
168
+ template:
169
+ metadata:
170
+ labels:
171
+ app: anchor-engine
172
+ spec:
173
+ containers:
174
+ - name: anchor-engine
175
+ image: anchor-engine:latest
176
+ ports:
177
+ - containerPort: 3160
178
+ volumeMounts:
179
+ - name: data
180
+ mountPath: /app/mirrored_brain
181
+ - name: backups
182
+ mountPath: /app/backups
183
+ resources:
184
+ requests:
185
+ memory: "1Gi"
186
+ cpu: "500m"
187
+ limits:
188
+ memory: "2Gi"
189
+ cpu: "1000m"
190
+ volumes:
191
+ - name: data
192
+ persistentVolumeClaim:
193
+ claimName: anchor-data-pvc
194
+ - name: backups
195
+ persistentVolumeClaim:
196
+ claimName: anchor-backups-pvc
197
+ ```
198
+
199
+ ---
200
+
201
+ ## Configuration
202
+
203
+ ### user_settings.json
204
+
205
+ **Location:** `~/.config/anchor/user_settings.json` or project root
206
+
207
+ **Key Settings:**
208
+ ```json
209
+ {
210
+ "server": {
211
+ "host": "0.0.0.0",
212
+ "port": 3160,
213
+ "api_key": "your-secret-key"
214
+ },
215
+ "database": {
216
+ "wipe_on_startup": false
217
+ },
218
+ "watcher": {
219
+ "debounce_ms": 2000,
220
+ "exclude_patterns": ["**/*.log", "**/node_modules/**"]
221
+ },
222
+ "search": {
223
+ "max_chars_default": 524288,
224
+ "strategy": "hybrid"
225
+ },
226
+ "adaptive_concurrency": {
227
+ "environment": "auto",
228
+ "sequential_threshold_mb": 2048,
229
+ "parallel_threshold_mb": 8192
230
+ }
231
+ }
232
+ ```
233
+
234
+ ### Environment Variables
235
+
236
+ | Variable | Default | Description |
237
+ |----------|---------|-------------|
238
+ | `ANCHOR_URL` | `http://localhost:3160` | API endpoint |
239
+ | `ANCHOR_API_KEY` | (none) | API authentication |
240
+ | `PROJECT_ROOT` | (auto-detect) | Project root path |
241
+ | `CONTEXT_DIR` | (auto-detect) | Context data directory |
242
+
243
+ ---
244
+
245
+ ## Security
246
+
247
+ ### Firewall Rules
248
+
249
+ **Minimum Required:**
250
+ ```bash
251
+ # Allow Anchor Engine port
252
+ sudo ufw allow 3160/tcp
253
+
254
+ # If using MCP remotely (not recommended)
255
+ sudo ufw allow 3161/tcp
256
+ ```
257
+
258
+ ### API Key Authentication
259
+
260
+ 1. Generate key:
261
+ ```bash
262
+ openssl rand -hex 32
263
+ ```
264
+
265
+ 2. Add to `user_settings.json`:
266
+ ```json
267
+ {
268
+ "server": {
269
+ "api_key": "your-generated-key"
270
+ }
271
+ }
272
+ ```
273
+
274
+ 3. Use in requests:
275
+ ```bash
276
+ curl -H "Authorization: Bearer your-key" \
277
+ http://localhost:3160/v1/stats
278
+ ```
279
+
280
+ ### HTTPS/TLS (Production)
281
+
282
+ **With Nginx Reverse Proxy:**
283
+ ```nginx
284
+ server {
285
+ listen 443 ssl;
286
+ server_name anchor.yourdomain.com;
287
+
288
+ ssl_certificate /etc/letsencrypt/live/anchor.yourdomain.com/fullchain.pem;
289
+ ssl_certificate_key /etc/letsencrypt/live/anchor.yourdomain.com/privkey.pem;
290
+
291
+ location / {
292
+ proxy_pass http://localhost:3160;
293
+ proxy_http_version 1.1;
294
+ proxy_set_header Upgrade $http_upgrade;
295
+ proxy_set_header Connection 'upgrade';
296
+ proxy_set_header Host $host;
297
+ proxy_cache_bypass $http_upgrade;
298
+ }
299
+ }
300
+ ```
301
+
302
+ ---
303
+
304
+ ## Monitoring
305
+
306
+ ### Health Checks
307
+
308
+ **Endpoint:** `GET /health`
309
+
310
+ **Response:**
311
+ ```json
312
+ {
313
+ "status": "ok",
314
+ "uptime": "2d 4h 15m",
315
+ "memory_mb": 512
316
+ }
317
+ ```
318
+
319
+ **Uptime Monitoring:**
320
+ ```bash
321
+ # Cron job every 5 minutes
322
+ */5 * * * * curl -f http://localhost:3160/health || echo "Anchor Engine DOWN" | mail -s "Alert" admin@example.com
323
+ ```
324
+
325
+ ### Logs
326
+
327
+ **Location:** `engine/logs/server.log`
328
+
329
+ **Log Rotation:**
330
+ ```bash
331
+ sudo nano /etc/logrotate.d/anchor-engine
332
+ ```
333
+
334
+ ```
335
+ /var/log/anchor-engine/*.log {
336
+ daily
337
+ rotate 7
338
+ compress
339
+ delaycompress
340
+ notifempty
341
+ create 0640 ubuntu ubuntu
342
+ }
343
+ ```
344
+
345
+ ---
346
+
347
+ ## Backup & Restore
348
+
349
+ ### Manual Backup
350
+ ```bash
351
+ # Create backup
352
+ curl -X POST http://localhost:3160/v1/backup
353
+
354
+ # Backup location: ./backups/backup-YYYY-MM-DDTHH-MM-SS/
355
+ ```
356
+
357
+ ### Automated Backup
358
+ ```bash
359
+ # Cron job daily at 2am
360
+ 0 2 * * * curl -X POST http://localhost:3160/v1/backup
361
+ ```
362
+
363
+ ### Restore
364
+ ```bash
365
+ curl -X POST http://localhost:3160/v1/backup/restore \
366
+ -H "Content-Type: application/json" \
367
+ -d '{"filename": "backup-2026-03-18T02-00-00"}'
368
+ ```
369
+
370
+ ---
371
+
372
+ ## Troubleshooting
373
+
374
+ ### Port Already in Use
375
+ ```bash
376
+ # Find process using port 3160
377
+ lsof -i :3160
378
+
379
+ # Kill process
380
+ kill -9 <PID>
381
+ ```
382
+
383
+ ### Out of Memory
384
+ ```json
385
+ {
386
+ "adaptive_concurrency": {
387
+ "environment": "low_memory"
388
+ }
389
+ }
390
+ ```
391
+
392
+ ### Database Corruption
393
+ ```bash
394
+ # Stop engine
395
+ pnpm stop
396
+
397
+ # Delete database (data preserved in mirrored_brain/)
398
+ rm -rf engine/context_data
399
+
400
+ # Restart (auto-rebuilds)
401
+ pnpm start
402
+ ```
403
+
404
+ ### Permission Errors
405
+ ```bash
406
+ # Fix ownership
407
+ sudo chown -R $USER:$USER ~/.config/anchor
408
+ sudo chown -R $USER:$USER ~/.local/share/anchor
409
+ ```
410
+
411
+ ---
412
+
413
+ ## Performance Tuning
414
+
415
+ ### Low Memory (<2GB RAM)
416
+ ```json
417
+ {
418
+ "adaptive_concurrency": {
419
+ "environment": "low_memory",
420
+ "sequential_threshold_mb": 512
421
+ },
422
+ "search": {
423
+ "max_chars_default": 262144
424
+ }
425
+ }
426
+ ```
427
+
428
+ ### High Performance (>8GB RAM)
429
+ ```json
430
+ {
431
+ "adaptive_concurrency": {
432
+ "environment": "high_memory",
433
+ "parallel_threshold_mb": 4096,
434
+ "max_concurrency": 10
435
+ },
436
+ "search": {
437
+ "max_chars_default": 1048576
438
+ }
439
+ }
440
+ ```
441
+
442
+ ---
443
+
444
+ ## Support
445
+
446
+ - **Documentation:** [`docs/`](./)
447
+ - **Issues:** https://github.com/RSBalchII/anchor-engine-node/issues
448
+ - **Discussions:** https://github.com/RSBalchII/anchor-engine-node/discussions