autonomous-flow-daemon 1.1.0 → 1.9.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 (75) hide show
  1. package/CHANGELOG.md +85 -46
  2. package/LICENSE +21 -21
  3. package/README-ko.md +282 -0
  4. package/README.md +282 -337
  5. package/mcp-config.json +10 -10
  6. package/package.json +14 -6
  7. package/src/adapters/index.ts +370 -159
  8. package/src/cli.ts +162 -57
  9. package/src/commands/benchmark.ts +187 -0
  10. package/src/commands/correlate.ts +180 -0
  11. package/src/commands/dashboard.ts +404 -0
  12. package/src/commands/diagnose.ts +56 -14
  13. package/src/commands/doctor.ts +243 -0
  14. package/src/commands/evolution.ts +190 -0
  15. package/src/commands/fix.ts +158 -138
  16. package/src/commands/hooks.ts +136 -0
  17. package/src/commands/lang.ts +41 -41
  18. package/src/commands/mcp.ts +129 -0
  19. package/src/commands/plugin.ts +110 -0
  20. package/src/commands/restart.ts +14 -0
  21. package/src/commands/score.ts +276 -208
  22. package/src/commands/start.ts +155 -96
  23. package/src/commands/stats.ts +103 -0
  24. package/src/commands/status.ts +157 -0
  25. package/src/commands/stop.ts +68 -49
  26. package/src/commands/suggest.ts +211 -0
  27. package/src/commands/sync.ts +567 -21
  28. package/src/commands/vaccine.ts +177 -0
  29. package/src/constants.ts +32 -8
  30. package/src/core/boast.ts +280 -265
  31. package/src/core/config.ts +49 -49
  32. package/src/core/correlation-engine.ts +265 -0
  33. package/src/core/db.ts +145 -46
  34. package/src/core/discovery.ts +65 -65
  35. package/src/core/evolution.ts +215 -0
  36. package/src/core/federation.ts +129 -0
  37. package/src/core/hologram/engine.ts +71 -0
  38. package/src/core/hologram/fallback.ts +11 -0
  39. package/src/core/hologram/go-extractor.ts +203 -0
  40. package/src/core/hologram/incremental.ts +227 -0
  41. package/src/core/hologram/py-extractor.ts +132 -0
  42. package/src/core/hologram/rust-extractor.ts +244 -0
  43. package/src/core/hologram/ts-extractor.ts +406 -0
  44. package/src/core/hologram/types.ts +27 -0
  45. package/src/core/hologram.ts +73 -243
  46. package/src/core/hook-manager.ts +259 -0
  47. package/src/core/i18n/messages.ts +309 -266
  48. package/src/core/immune.ts +8 -123
  49. package/src/core/locale.ts +88 -88
  50. package/src/core/log-rotate.ts +33 -0
  51. package/src/core/log-utils.ts +38 -0
  52. package/src/core/lru-map.ts +61 -0
  53. package/src/core/notify.ts +74 -66
  54. package/src/core/plugin-manager.ts +225 -0
  55. package/src/core/rule-engine.ts +287 -0
  56. package/src/core/rule-suggestion.ts +127 -0
  57. package/src/core/semantic-diff.ts +432 -0
  58. package/src/core/telemetry.ts +94 -0
  59. package/src/core/vaccine-registry.ts +212 -0
  60. package/src/core/validator-generator.ts +224 -0
  61. package/src/core/workspace.ts +28 -0
  62. package/src/core/yaml-minimal.ts +176 -0
  63. package/src/daemon/client.ts +78 -37
  64. package/src/daemon/event-batcher.ts +108 -0
  65. package/src/daemon/guards.ts +13 -0
  66. package/src/daemon/http-routes.ts +376 -0
  67. package/src/daemon/mcp-handler.ts +575 -0
  68. package/src/daemon/mcp-subscriptions.ts +81 -0
  69. package/src/daemon/mesh.ts +51 -0
  70. package/src/daemon/server.ts +655 -504
  71. package/src/daemon/types.ts +121 -0
  72. package/src/daemon/workspace-map.ts +104 -0
  73. package/src/platform.ts +60 -39
  74. package/src/version.ts +15 -0
  75. package/README.ko.md +0 -306
package/README.md CHANGED
@@ -1,337 +1,282 @@
1
- <p align="center">
2
- <img src="https://capsule-render.vercel.app/api?type=soft&color=auto&height=200&section=header&text=afd&fontSize=90" alt="afd" />
3
- </p>
4
-
5
- <h3 align="center">The Autonomous Flow Daemon</h3>
6
- <p align="center"><strong>Self-healing AI development environments in < 270ms.</strong></p>
7
-
8
- <p align="center">
9
- <a href="https://github.com/dotoricode/autonomous-flow-daemon">
10
- <img src="demo.gif" width="850" alt="afd demo" style="border-radius: 12px; box-shadow: 0 20px 40px rgba(0,0,0,0.4);">
11
- </a>
12
- <br>
13
- <br>
14
- <b>🛡️ Immortal Context Flow:</b>
15
- <em>"afd restores critical config files with <b>near-zero latency</b>, ensuring your AI workflow remains unbroken and cost-efficient."</em>
16
- </p>
17
-
18
- ---
19
-
20
- <p align="center">
21
- <img src="https://img.shields.io/badge/version-1.1.0-blue?style=flat-square" alt="version" />
22
- <a href="https://www.npmjs.com/package/autonomous-flow-daemon"><img src="https://img.shields.io/npm/v/autonomous-flow-daemon?style=flat-square&logo=npm&color=cb0000" alt="npm" /></a>
23
- <img src="https://img.shields.io/badge/runtime-Bun-f472b6?style=flat-square&logo=bun" alt="Bun" />
24
- <img src="https://img.shields.io/badge/license-MIT-green?style=flat-square" alt="MIT" />
25
- <img src="https://img.shields.io/badge/built%20for-Claude%20Code-7c3aed?style=flat-square" alt="Claude Code" />
26
- </p>
27
-
28
- <p align="center">
29
- <a href="README.ko.md">한국어</a>
30
- </p>
31
-
32
- ---
33
-
34
- ## Why afd?
35
-
36
- > [afd] 🛡️ AI agent deleted '.claudeignore' | 🩹 Self-healed in 184ms | Context preserved.
37
-
38
- You're deep in flow. Your AI agent makes a wrong move — deletes a config, corrupts a hook file, wipes a `.cursorrules`. Without `afd`, you stop everything, diagnose the breakage, manually fix it: **30 minutes gone**.
39
-
40
- With `afd`, the daemon noticed in 10ms, restored the file in 184ms, and logged it silently. **You never even saw it happen.**
41
-
42
- | Situation | Without afd | With afd |
43
- |:----------|:------------|:---------|
44
- | AI deletes `.claudeignore` | 30 min manual fix | **0.2s auto-heal** |
45
- | Hook file corrupted | Re-inject hooks, restart session | **Silent background repair** |
46
- | `git checkout` triggers 50 file events | AI goes haywire | **Mass-event suppressor kicks in** |
47
- | New team member, missing context | Tribal knowledge required | **`afd sync` vaccines the setup** |
48
-
49
- ---
50
-
51
- ## 🚀 Zero-Interference Promise
52
-
53
- We built `afd` to protect your flow, not to slow it down.
54
-
55
- * **No Performance Hit:** Running as a native background daemon via Bun, `afd` consumes **< 0.1% CPU** and **~40MB RAM**.
56
- * **Seamless Recovery:** With **sub-millisecond healing**, files are restored before Claude Code can even register a missing context error.
57
- * **Non-Invasive:** `afd` observes file system events from the OS layer. It never intercepts or modifies Claude Code's internal execution or API calls.
58
-
59
- ---
60
-
61
- ## Key Features (v1.1.0)
62
-
63
- | Feature | What it does |
64
- |:--------|:-------------|
65
- | **🛡️ S.E.A.M Auto-Heal** | Detects file deletion and restores it in < 270ms — before your AI agent notices |
66
- | **🔍 Smart Discovery** | Automatically scans for AI-context files (`.claude/`, `.cursorrules`, `.mcp.json`, etc.) — zero config required |
67
- | **🏥 Boastful Doctor** | Real-time value tracking: saved tokens, time, and cost with witty feedback after every heal |
68
- | **🌐 Auto-Localization** | Seamlessly switches between Korean and English based on your system locale. Or set it: `afd lang ko` |
69
- | **🧬 Double-Tap Heuristic** | Distinguishes accidents from intent — delete once, afd heals it; delete again within 30s, afd respects your decision |
70
- | **💉 Vaccine Network** | Export learned antibodies via `afd sync` for cross-project, cross-team immunity |
71
- | **📊 Hologram Extraction** | Serves 80%+ lighter file skeletons to AI agents, slashing token costs |
72
-
73
- ---
74
-
75
- ## The One-Command Experience
76
-
77
- > **Zero-Config. Total Protection.**
78
-
79
- ```bash
80
- npx @dotoricode/afd start
81
- ```
82
-
83
- Or install locally:
84
-
85
- ```bash
86
- bun link && afd start
87
- ```
88
-
89
- That's it. One command. `afd` takes over from here:
90
-
91
- - **Auto-Injection** Installs `PreToolUse` hooks into Claude Code silently. No manual config editing.
92
- - **Sense (Watcher)** 10ms real-time monitoring of critical configs: `.claude/`, `CLAUDE.md`, `.cursorrules`, `.claudeignore`, `.gitignore`.
93
- - **Auto-Heal** Silent background repair of missing or corrupted files using the **S.E.A.M cycle**. You won't even notice it happened.
94
-
95
- ```
96
- $ afd start
97
- 🛡️ Daemon started (pid 4812, port 52413)
98
- 🛡️ Smart Discovery: Watching 7 AI-context targets
99
- Targets: .claude/, CLAUDE.md, .cursorrules, .claudeignore, .gitignore, mcp-config.json, .mcp.json
100
- Hook injected into .claude/hooks.json
101
- ```
102
-
103
- > You type `afd start`. Then you forget about it. That's the entire UX.
104
-
105
- ---
106
-
107
- ## The S.E.A.M Cycle
108
-
109
- The intelligence inside `afd`. Every file event flows through four stages:
110
-
111
- ```mermaid
112
- graph LR
113
- S["Sense<br/><i>File Change Detected</i>"] --> E["Extract<br/><i>Detect Symptom</i>"]
114
- E --> A["Adapt<br/><i>Select Antibody</i>"]
115
- A --> M["Mutate<br/><i>Apply JSON-Patch</i>"]
116
- M -->|"Learn"| S
117
- style S fill:#3b82f6,color:#fff,stroke:none
118
- style E fill:#f59e0b,color:#fff,stroke:none
119
- style A fill:#10b981,color:#fff,stroke:none
120
- style M fill:#ef4444,color:#fff,stroke:none
121
- ```
122
-
123
- | Stage | What Happens | Speed |
124
- |:------|:-------------|:------|
125
- | **Sense** | Chokidar watcher detects `add`, `change`, `unlink` events | < 10ms |
126
- | **Extract** | Immune engine runs 3 built-in health checks (IMM-001..003) | < 5ms |
127
- | **Adapt** | Matches symptom to stored antibody in SQLite (WAL mode) | < 1ms |
128
- | **Mutate** | Applies RFC 6902 JSON-Patch to restore the file | < 25ms |
129
-
130
- > Full cycle: **< 270ms** from file deletion to full recovery.
131
-
132
- ### Watch Targets
133
-
134
- These files are monitored in real-time. Immune files (IMM-*) are automatically restored on deletion:
135
-
136
- | Target | Type | Antibody | Auto-Restore |
137
- |:-------|:-----|:---------|:-------------|
138
- | `.claude/` | Directory | IMM-002 (`hooks.json`) | ✅ |
139
- | `CLAUDE.md` | File | IMM-003 | ✅ |
140
- | `.claudeignore` | File | IMM-001 | |
141
- | `.cursorrules` | File | — | Event logging only |
142
- | `.gitignore` | File | — | Event logging only |
143
- | `mcp-config.json` | File | — | 🔍 Smart Discovery |
144
- | `.mcp.json` | File | — | 🔍 Smart Discovery |
145
- | `.ai/` | Directory | — | 🔍 Smart Discovery |
146
- | `.windsurfrules` | File | — | 🔍 Smart Discovery |
147
-
148
- > Antibodies are **auto-seeded on startup** with each file's current content, and **refreshed on every change** — so restores always reflect the latest version.
149
- >
150
- > 🔍 **Smart Discovery** scans for 12+ known AI-config patterns at startup (< 0.1ms) and adds any found files to the active watch list automatically.
151
-
152
- ---
153
-
154
- ## Commands
155
-
156
- Everything you need. Nothing you don't.
157
-
158
- | Command | Essence | Intelligence Inside |
159
- |:--------|:--------|:--------------------|
160
- | `afd start` | **Ignite** | Daemon spawn + Smart Discovery + Hook injection |
161
- | `afd fix` | **Diagnose** | Symptom detection & Antibody learning |
162
- | `afd score` | **Vitals** | Localized health dashboard & Value metrics |
163
- | `afd sync` | **Federate** | Vaccine payload export for cross-project immunity |
164
- | `afd lang` | **Localize** | Switch display language (`afd lang ko` / `afd lang en`) |
165
- | `afd stop` | **Quarantine** | Shift summary & Graceful shutdown |
166
-
167
- ### Quick Reference
168
-
169
- ```bash
170
- afd start # Start daemon, inject hooks, begin watching
171
- afd fix # Scan for issues, auto-patch, learn antibodies
172
- afd score # Full diagnostic dashboard (localized)
173
- afd sync # Export antibodies to .afd/global-vaccine-payload.json
174
- afd lang ko # Switch to Korean / afd lang en for English
175
- afd stop # Shift summary + graceful shutdown
176
- ```
177
-
178
- ---
179
-
180
- ## Dashboard: `afd score`
181
-
182
- ```
183
- ┌──────────────────────────────────────────────┐
184
- │ afd score — Daemon Diagnostics │
185
- ├──────────────────────────────────────────────┤
186
- │ Ecosystem : Claude Code │
187
- ├──────────────────────────────────────────────┤
188
- │ Uptime : 1h 23m │
189
- │ Events : 156 │
190
- │ Files Found : 8 │
191
- ├──────────────────────────────────────────────┤
192
- Immune System │
193
- │ ────────────────────────────── │
194
- │ Antibodies : 7 │
195
- │ Level : Fortified │
196
- │ Auto-healed : 3 background events │
197
- ├──────────────────────────────────────────────┤
198
- │ 📈 Value Delivered │
199
- │ ────────────────────────────── │
200
- │ Tokens saved : ~2.9K │
201
- │ Time saved : ~40 min │
202
- │ Cost saved : ~$0.01 │
203
- ├──────────────────────────────────────────────┤
204
- │ 🗣️ The immune system holds. Another day, │
205
- │ another heal. 💪 │
206
- └──────────────────────────────────────────────┘
207
- ```
208
-
209
- > The dashboard is fully localized. Run `afd lang ko` and every label switches to Korean.
210
-
211
- ---
212
-
213
- ## Advanced Intelligence
214
-
215
- ### Double-Tap Heuristic (Immune Tolerance)
216
-
217
- `afd` distinguishes **accidents** from **intent**:
218
-
219
- ```
220
- $ rm .claudeignore # First tap → afd heals it silently
221
- $ rm .claudeignore # Second tap within 30s → "You meant it."
222
- [afd] 🫡 Antibody IMM-001 retired. Double-tap detected. Standing down.
223
- ```
224
-
225
- | Scenario | Response |
226
- |:---------|:---------|
227
- | Single delete (accident) | Auto-heal + record first tap |
228
- | Re-delete within 30s (intent) | Antibody goes dormant, deletion respected |
229
- | Re-delete after 30s | Fresh first tap, heals again |
230
- | 3+ deletes in 1s (git checkout) | Mass-event detected, all suppression paused |
231
-
232
- ### Vaccine Network (Team Federation)
233
-
234
- Export learned antibodies for your entire team:
235
-
236
- ```bash
237
- afd sync
238
- # → .afd/global-vaccine-payload.json
239
- ```
240
-
241
- The payload is sanitized (no absolute paths, no secrets) and portable. Drop it into any project, and `afd` inherits the immunity.
242
-
243
- ### Hologram Extraction
244
-
245
- When AI agents request file context, `afd` serves **token-efficient skeletons** — stripping comments and function bodies while preserving the full type signature:
246
-
247
- ```
248
- Original: 2,450 chars → Hologram: 380 chars (84% savings)
249
- ```
250
-
251
- This keeps your AI agent's context window lean without losing structural understanding.
252
-
253
- ---
254
-
255
- ## Status Line
256
-
257
- Real-time daemon status in Claude Code's status bar:
258
-
259
- ```
260
- 🛡️ afd: OFF # Daemon not running
261
- 🛡️ afd: ON # Running, no heals
262
- 🛡️ afd: ON 🩹1 # 1 auto-heal event
263
- 🛡️ afd: ON | 🩹 3 Healed | last: IMM-003 # Detailed view
264
- ```
265
-
266
- ---
267
-
268
- ## Plugin / MCP Setup
269
-
270
- `afd` can be registered as a **Model Context Protocol (MCP) server** inside Claude Code, allowing the daemon to start automatically when Claude Code launches.
271
-
272
- ### Automatic (recommended)
273
-
274
- Add to your Claude Code MCP config (`~/.claude/mcp.json` or project-level `.mcp.json`):
275
-
276
- ```json
277
- {
278
- "mcpServers": {
279
- "afd": {
280
- "command": "bun",
281
- "args": ["run", "src/cli.ts", "start"]
282
- }
283
- }
284
- }
285
- ```
286
-
287
- ### Manual
288
-
289
- ```bash
290
- afd start # starts daemon in background, injects hooks
291
- ```
292
-
293
- Once registered, Claude Code will display the live status line:
294
-
295
- ```
296
- 🛡️ afd: ON | 🩹 3 Healed | last: IMM-003
297
- ```
298
-
299
- ---
300
-
301
- ## Tech Stack
302
-
303
- | Layer | Technology | Why |
304
- |:------|:-----------|:----|
305
- | Runtime | **Bun** | Native TypeScript, fast SQLite, single binary |
306
- | Database | **Bun SQLite (WAL)** | 0.29ms reads, 24ms writes, crash-safe |
307
- | Watching | **Chokidar** | Cross-platform, battle-tested file watcher |
308
- | Patching | **RFC 6902 JSON-Patch** | Deterministic, composable file mutations |
309
- | CLI | **Commander.js** | Standard, zero-surprise command parsing |
310
- | i18n | **Built-in engine** | Zero-dependency locale switching in 0.01ms |
311
-
312
- ---
313
-
314
- ## Installation
315
-
316
- ```bash
317
- # With Bun (recommended)
318
- bun install
319
- bun link
320
- afd start
321
-
322
- # With npx (no install)
323
- npx @dotoricode/afd start
324
- ```
325
-
326
- ### Requirements
327
-
328
- - **Bun** >= 1.0
329
- - **OS**: Windows, macOS, Linux
330
- - **Target**: Claude Code, Cursor (ecosystem auto-detected)
331
-
332
- ---
333
-
334
- ## License
335
-
336
- MIT
337
-
1
+ <p align="center">
2
+ <img src="https://capsule-render.vercel.app/api?type=soft&color=auto&height=200&section=header&text=afd&fontSize=90" alt="afd" />
3
+ </p>
4
+
5
+ <h3 align="center">The Invisible Guardian for AI Agents</h3>
6
+ <p align="center"><strong>Self-healing environments + 84% token savings. Your AI breaks things — afd fixes them in 184ms.</strong></p>
7
+
8
+ <p align="center">
9
+ <a href="https://github.com/dotoricode/autonomous-flow-daemon">
10
+ <img src="demo.gif" width="850" alt="afd demo" style="border-radius: 12px; box-shadow: 0 20px 40px rgba(0,0,0,0.4);">
11
+ </a>
12
+ </p>
13
+
14
+ <p align="center">
15
+ <img src="https://img.shields.io/badge/version-1.6.0-blue?style=flat-square" alt="version" />
16
+ <a href="https://www.npmjs.com/package/autonomous-flow-daemon"><img src="https://img.shields.io/npm/v/autonomous-flow-daemon?style=flat-square&logo=npm&color=cb0000" alt="npm" /></a>
17
+ <img src="https://img.shields.io/badge/runtime-Bun-f472b6?style=flat-square&logo=bun" alt="Bun" />
18
+ <img src="https://img.shields.io/badge/license-MIT-green?style=flat-square" alt="MIT" />
19
+ <img src="https://img.shields.io/badge/built%20for-Claude%20Code-7c3aed?style=flat-square" alt="Claude Code" />
20
+ </p>
21
+
22
+ <p align="center">
23
+ <a href="README-ko.md">한국어</a>
24
+ </p>
25
+
26
+ ---
27
+
28
+ ## The Numbers Don't Lie
29
+
30
+ | Situation | Without afd | With afd |
31
+ |:----------|:------------|:---------|
32
+ | AI deletes `.claudeignore` | **30 min** manual fix | **0.2s** auto-heal |
33
+ | Hook file corrupted | Re-inject hooks, restart session | **Silent background repair** |
34
+ | `git checkout` triggers 50 events | AI goes haywire | **Mass-event suppressor** |
35
+ | AI reads 8 large files (114KB) | **~28,600 tokens** consumed | **~4,600 tokens** (84% saved) |
36
+ | Session token budget | Burns through context window | **~60,900 tokens saved per codebase scan** |
37
+
38
+ > `< 0.1% CPU` | `~40MB RAM` | `< 270ms` full heal cycle | You never even see it happen.
39
+
40
+ ---
41
+
42
+ ## One Command to Rule Them All
43
+
44
+ ```bash
45
+ npx @dotoricode/afd start
46
+ ```
47
+
48
+ That's it. Daemon spawns, hooks inject, MCP registers. You're protected.
49
+
50
+ ```
51
+ $ afd start
52
+ Daemon started (pid 4812, port 52413)
53
+ Smart Discovery: Watching 7 AI-context targets
54
+ Hook injected into .claude/hooks.json
55
+ ```
56
+
57
+ ---
58
+
59
+ ## The Problem
60
+
61
+ Your AI agent is powerful but clumsy. It deletes `.claudeignore`, corrupts `hooks.json`, wipes `.cursorrules` — and you don't notice until everything is broken. You stop coding, diagnose the mess, manually restore files. **30 minutes gone. Flow destroyed.**
62
+
63
+ And every time it reads your codebase? Full source files pumped straight into the context window. **Thousands of tokens burned on function bodies it never needed.**
64
+
65
+ ## The Solution
66
+
67
+ `afd` runs as an invisible background daemon. It watches your critical files, heals corruption in 184ms, and serves AI agents compressed type skeletons instead of raw source code. Your AI gets the structure it needs at 1/16th the token cost. Accidents get fixed before you notice. Intentional deletions are respected. Zero config, zero interference.
68
+
69
+ ---
70
+
71
+ ## What's New in v1.6.0
72
+
73
+ | Feature | What Changed |
74
+ |:--------|:-------------|
75
+ | **Tree-sitter AST Engine** | Replaced TypeScript compiler with tree-sitter — multilingual hologram support (TS/JS full, Python/Go/Rust fallback) |
76
+ | **Real-time HUD ROI** | Status bar now shows live session token savings as you work |
77
+ | **Event Batching** | 300ms debounce + dedup — no more event storms from rapid file changes |
78
+ | **Hook Manager** | Multi-owner orchestration — afd coexists cleanly with other hook providers |
79
+
80
+ ---
81
+
82
+ ## Key Features
83
+
84
+ | Feature | What it does |
85
+ |:--------|:-------------|
86
+ | **S.E.A.M Auto-Heal** | File deletion/corruption detected and restored in < 270ms |
87
+ | **Hologram Extraction** | 70-96% lighter file skeletons served to AI agents via MCP |
88
+ | **Smart Reader** | `afd_read` — small files raw, large files auto-compressed, line-range support |
89
+ | **Workspace Map** | `afd://workspace-map` full file tree + export signatures in one call |
90
+ | **Import-Aware L1** | Only imported symbols get full signatures (85%+ savings) |
91
+ | **Double-Tap** | Delete once = heal; delete again within 30s = respected as intent |
92
+ | **Vaccine Network** | `afd sync` exports learned antibodies across projects |
93
+ | **Self-Evolution** | Quarantined failures become prevention rules automatically |
94
+ | **Mistake History** | PreToolUse hook injects past mistakes as warnings before edits |
95
+ | **HUD Counter** | Status bar shows defense count + token savings at a glance |
96
+
97
+ ---
98
+
99
+ ## Token Savings Real Measured Data
100
+
101
+ The hologram system is afd's biggest value driver. Here's what we measured in a real session:
102
+
103
+ ### Session Snapshot
104
+
105
+ | Metric | Value |
106
+ |:-------|:------|
107
+ | Hologram requests | 55 files analyzed |
108
+ | Target files total size | ~290 KB (55 files, avg 5.3 KB each) |
109
+ | Original token cost | ~72,500 tokens |
110
+ | After hologram compression | ~11,600 tokens |
111
+ | **Tokens saved** | **~60,900 tokens (84% reduction)** |
112
+
113
+ ### How It Scales
114
+
115
+ ```
116
+ Session tokens (at ctx ~15%): ~150,000 ████████████████
117
+ Tokens saved by hologram: ~60,900 ████████░░░░░░░░ (41% of session)
118
+ ```
119
+
120
+ At ctx 50%+, file reads dominate the token budget. Without hologram, scanning 55 source files costs ~72.5K tokens. With hologram, **each file averages just 16% of its original footprint** — and the gap widens with every repeated read.
121
+
122
+ ### Three Layers of Token Optimization
123
+
124
+ | Layer | Tool | Savings | How |
125
+ |:------|:-----|:--------|:----|
126
+ | **L0 Hologram** | `afd_hologram` | 80%+ | Strip function bodies, keep type signatures |
127
+ | **L1 Hologram** | `afd_hologram` + `contextFile` | 85%+ | Filter to only imported symbols |
128
+ | **Smart Reader** | `afd_read` | Auto | Files < 10KB raw, >= 10KB auto-hologram |
129
+ | **Workspace Map** | `afd://workspace-map` | N/A | Entire project structure in one call |
130
+
131
+ ---
132
+
133
+ <details>
134
+ <summary><b>How S.E.A.M Works (internals)</b></summary>
135
+
136
+ Every file event flows through four stages:
137
+
138
+ ```mermaid
139
+ graph LR
140
+ S["Sense<br/><i>File Change Detected</i>"] --> E["Extract<br/><i>Detect Symptom</i>"]
141
+ E --> A["Adapt<br/><i>Select Antibody</i>"]
142
+ A --> M["Mutate<br/><i>Apply JSON-Patch</i>"]
143
+ M -->|"Learn"| S
144
+ style S fill:#3b82f6,color:#fff,stroke:none
145
+ style E fill:#f59e0b,color:#fff,stroke:none
146
+ style A fill:#10b981,color:#fff,stroke:none
147
+ style M fill:#ef4444,color:#fff,stroke:none
148
+ ```
149
+
150
+ | Stage | What Happens | Speed |
151
+ |:------|:-------------|:------|
152
+ | **Sense** | Chokidar watcher detects `add`, `change`, `unlink` events | < 10ms |
153
+ | **Extract** | Generates hologram (type skeleton) & runs health checks | < 5ms |
154
+ | **Adapt** | Matches symptom to antibody, quarantines corrupted state | < 1ms |
155
+ | **Mutate** | Applies RFC 6902 JSON-Patch to restore the file | < 25ms |
156
+
157
+ > Full cycle: **< 270ms** from file deletion to full recovery.
158
+
159
+ </details>
160
+
161
+ ---
162
+
163
+ ## Commands
164
+
165
+ | Command | What it does |
166
+ |:--------|:-------------|
167
+ | `afd start` | Daemon spawn + Smart Discovery + Hook injection + MCP registration |
168
+ | `afd stop` | Shift summary report & graceful shutdown (`--clean` to remove hooks & MCP) |
169
+ | `afd score` | Health dashboard with evolution & hologram metrics |
170
+ | `afd fix` | Symptom detection with hologram context & antibody learning |
171
+ | `afd sync` | Vaccine payload export/import (`--push`, `--pull`, `--remote <url>`) |
172
+ | `afd restart` | Stop + start in one command |
173
+ | `afd status` | Quick health check — daemon, hooks, MCP, defenses |
174
+ | `afd doctor` | Comprehensive health analysis with auto-fix recommendations |
175
+ | `afd evolution` | Analyze quarantined failures & generate prevention rules |
176
+ | `afd mcp install` | Register afd as MCP server in project + global config |
177
+ | `afd vaccine` | List, search, install, publish community antibodies |
178
+ | `afd lang` | Switch display language (`afd lang ko` / `afd lang en`) |
179
+
180
+ ---
181
+
182
+ <details>
183
+ <summary><b>Advanced Intelligence</b></summary>
184
+
185
+ ### Double-Tap Heuristic
186
+
187
+ `afd` distinguishes **accidents** from **intent**:
188
+
189
+ ```
190
+ $ rm .claudeignore # First tap -> afd heals it silently
191
+ $ rm .claudeignore # Second tap within 30s -> "You meant it."
192
+ [afd] Antibody IMM-001 retired. Double-tap detected. Standing down.
193
+ ```
194
+
195
+ | Scenario | Response |
196
+ |:---------|:---------|
197
+ | Single delete (accident) | Auto-heal + record first tap |
198
+ | Re-delete within 30s (intent) | Antibody goes dormant, deletion respected |
199
+ | 3+ deletes in 1s (git checkout) | Mass-event detected, all suppression paused |
200
+
201
+ ### Vaccine Network
202
+
203
+ ```bash
204
+ afd sync # Export to .afd/global-vaccine-payload.json
205
+ afd sync --push # Push vaccines to remote
206
+ afd sync --pull # Pull vaccines from remote
207
+ ```
208
+
209
+ The payload is sanitized (no absolute paths, no secrets) and portable.
210
+
211
+ ### Self-Evolution
212
+
213
+ ```bash
214
+ afd evolution
215
+ ```
216
+
217
+ Analyzes quarantined failures and writes prevention rules to `afd-lessons.md`. AI agents read this before editing immune-critical files — turning past failures into future prevention.
218
+
219
+ </details>
220
+
221
+ ---
222
+
223
+ ## MCP Setup
224
+
225
+ `afd` provides four MCP tools and one resource:
226
+
227
+ | MCP Tool | Purpose |
228
+ |:---------|:--------|
229
+ | `afd_read` | Smart file reader raw for small files, auto-hologram for large, optional line ranges |
230
+ | `afd_hologram` | Token-efficient type skeleton of any TS/JS file (80%+ savings) |
231
+ | `afd_diagnose` | Health diagnosis with symptoms and hologram context |
232
+ | `afd_score` | Runtime stats: uptime, heals, hologram savings |
233
+
234
+ | MCP Resource | Purpose |
235
+ |:-------------|:--------|
236
+ | `afd://workspace-map` | Full file tree with export signatures in one call |
237
+
238
+ ```bash
239
+ afd mcp install # Registers in .mcp.json + ~/.claude.json
240
+ ```
241
+
242
+ ---
243
+
244
+ <details>
245
+ <summary><b>Tech Stack</b></summary>
246
+
247
+ | Layer | Technology | Why |
248
+ |:------|:-----------|:----|
249
+ | Runtime | **Bun** | Native TypeScript, fast SQLite, single binary |
250
+ | Database | **Bun SQLite (WAL)** | 0.29ms reads, 24ms writes, crash-safe |
251
+ | Parsing | **Tree-sitter** | Multilingual AST TS, JS, Python, Go, Rust |
252
+ | Watching | **Chokidar** | Cross-platform, battle-tested file watcher |
253
+ | Patching | **RFC 6902 JSON-Patch** | Deterministic, composable file mutations |
254
+ | CLI | **Commander.js** | Standard, zero-surprise command parsing |
255
+
256
+ </details>
257
+
258
+ ---
259
+
260
+ ## Installation
261
+
262
+ ```bash
263
+ # Fastest (no install)
264
+ npx @dotoricode/afd start
265
+
266
+ # With Bun (recommended for development)
267
+ bun install
268
+ bun link
269
+ afd start
270
+ ```
271
+
272
+ ### Requirements
273
+
274
+ - **Bun** >= 1.0
275
+ - **OS**: Windows, macOS, Linux
276
+ - **Target**: Claude Code, Cursor, Windsurf, Codex (ecosystem auto-detected)
277
+
278
+ ---
279
+
280
+ ## License
281
+
282
+ MIT