autonomous-flow-daemon 1.0.0 → 1.6.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 (59) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.ko.md +142 -125
  3. package/README.md +119 -134
  4. package/package.json +11 -5
  5. package/src/adapters/index.ts +247 -35
  6. package/src/cli.ts +79 -1
  7. package/src/commands/benchmark.ts +187 -0
  8. package/src/commands/diagnose.ts +56 -14
  9. package/src/commands/doctor.ts +243 -0
  10. package/src/commands/evolution.ts +107 -0
  11. package/src/commands/fix.ts +22 -2
  12. package/src/commands/hooks.ts +136 -0
  13. package/src/commands/lang.ts +41 -0
  14. package/src/commands/mcp.ts +129 -0
  15. package/src/commands/restart.ts +14 -0
  16. package/src/commands/score.ts +192 -64
  17. package/src/commands/start.ts +137 -37
  18. package/src/commands/stats.ts +103 -0
  19. package/src/commands/status.ts +157 -0
  20. package/src/commands/stop.ts +42 -9
  21. package/src/commands/sync.ts +253 -20
  22. package/src/commands/vaccine.ts +177 -0
  23. package/src/constants.ts +26 -1
  24. package/src/core/boast.ts +280 -0
  25. package/src/core/config.ts +49 -0
  26. package/src/core/db.ts +74 -3
  27. package/src/core/discovery.ts +65 -0
  28. package/src/core/evolution.ts +215 -0
  29. package/src/core/hologram/engine.ts +71 -0
  30. package/src/core/hologram/fallback.ts +11 -0
  31. package/src/core/hologram/incremental.ts +227 -0
  32. package/src/core/hologram/py-extractor.ts +132 -0
  33. package/src/core/hologram/ts-extractor.ts +320 -0
  34. package/src/core/hologram/types.ts +25 -0
  35. package/src/core/hologram.ts +64 -236
  36. package/src/core/hook-manager.ts +259 -0
  37. package/src/core/i18n/messages.ts +309 -0
  38. package/src/core/immune.ts +8 -123
  39. package/src/core/locale.ts +88 -0
  40. package/src/core/log-rotate.ts +33 -0
  41. package/src/core/log-utils.ts +38 -0
  42. package/src/core/lru-map.ts +61 -0
  43. package/src/core/notify.ts +53 -14
  44. package/src/core/rule-engine.ts +287 -0
  45. package/src/core/semantic-diff.ts +432 -0
  46. package/src/core/telemetry.ts +94 -0
  47. package/src/core/vaccine-registry.ts +212 -0
  48. package/src/core/workspace.ts +28 -0
  49. package/src/core/yaml-minimal.ts +176 -0
  50. package/src/daemon/client.ts +34 -6
  51. package/src/daemon/event-batcher.ts +108 -0
  52. package/src/daemon/guards.ts +13 -0
  53. package/src/daemon/http-routes.ts +293 -0
  54. package/src/daemon/mcp-handler.ts +270 -0
  55. package/src/daemon/server.ts +492 -273
  56. package/src/daemon/types.ts +100 -0
  57. package/src/daemon/workspace-map.ts +92 -0
  58. package/src/platform.ts +60 -0
  59. package/src/version.ts +15 -0
package/README.md CHANGED
@@ -6,7 +6,16 @@
6
6
  <p align="center"><strong>Self-healing AI development environments in < 270ms.</strong></p>
7
7
 
8
8
  <p align="center">
9
- <img src="https://img.shields.io/badge/version-1.0.0-blue?style=flat-square" alt="version" />
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
+ ---
15
+
16
+ <p align="center">
17
+ <img src="https://img.shields.io/badge/version-1.6.0-blue?style=flat-square" alt="version" />
18
+ <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>
10
19
  <img src="https://img.shields.io/badge/runtime-Bun-f472b6?style=flat-square&logo=bun" alt="Bun" />
11
20
  <img src="https://img.shields.io/badge/license-MIT-green?style=flat-square" alt="MIT" />
12
21
  <img src="https://img.shields.io/badge/built%20for-Claude%20Code-7c3aed?style=flat-square" alt="Claude Code" />
@@ -20,24 +29,75 @@
20
29
 
21
30
  ## Why afd?
22
31
 
23
- > [afd] 🛡️ AI agent deleted '.claudeignore' | 🩹 Self-healed in 184ms | Context preserved.
32
+ > [afd] AI agent deleted '.claudeignore' | Self-healed in 184ms | Context preserved.
24
33
 
25
- 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**.
34
+ Your AI agent deletes a config, corrupts a hook file, wipes `.cursorrules`. Without `afd`, you stop everything, diagnose the breakage, manually fix it: **30 minutes gone**.
26
35
 
27
- With `afd`, the daemon noticed in 10ms, restored the file in 184ms, and logged it silently. **You never even saw it happen.**
36
+ With `afd`, the daemon noticed in 10ms, restored the file in 184ms, and logged it silently. **You never even saw it happen.** Running as a native Bun daemon, it consumes < 0.1% CPU and ~40MB RAM — zero interference with your workflow.
28
37
 
29
38
  | Situation | Without afd | With afd |
30
39
  |:----------|:------------|:---------|
31
40
  | AI deletes `.claudeignore` | 30 min manual fix | **0.2s auto-heal** |
32
41
  | Hook file corrupted | Re-inject hooks, restart session | **Silent background repair** |
33
42
  | `git checkout` triggers 50 file events | AI goes haywire | **Mass-event suppressor kicks in** |
34
- | New team member, missing context | Tribal knowledge required | **`afd sync` vaccines the setup** |
43
+ | AI reads 8 large files (114KB) | ~28,600 tokens consumed | **~1,700 tokens via hologram (94% saved)** |
35
44
 
36
45
  ---
37
46
 
38
- ## The One-Command Experience
47
+ ## Key Features
48
+
49
+ | Feature | What it does |
50
+ |:--------|:-------------|
51
+ | **S.E.A.M Auto-Heal** | Detects file deletion/corruption and restores it in < 270ms |
52
+ | **Hologram Extraction** | Serves 80-93% lighter file skeletons to AI agents via MCP, slashing token costs |
53
+ | **Smart File Reader** | `afd_read` — small files served raw, large files auto-compressed; supports line-range reads |
54
+ | **Workspace Map** | `afd://workspace-map` — full file tree + export signatures in one call |
55
+ | **Hologram L1** | Import-aware compression — only imported symbols get full signatures (85%+ savings) |
56
+ | **Quarantine Zone** | Backs up corrupted files to `.afd/quarantine/` before restoring |
57
+ | **Self-Evolution** | Analyzes quarantined failures and writes prevention rules to `afd-lessons.md` |
58
+ | **Mistake History** | PreToolUse hook injects past mistakes as warnings before file edits |
59
+ | **Double-Tap Heuristic** | Delete once = auto-heal; delete again within 30s = respected as intent |
60
+ | **Vaccine Network** | Export learned antibodies via `afd sync` for cross-project immunity |
61
+ | **MCP Integration** | `afd mcp install` auto-registers the daemon as an MCP server |
62
+ | **HUD Defense Counter** | Status bar shows defense count + reason summary at a glance |
63
+
64
+ ---
39
65
 
40
- > **Zero-Config. Total Protection.**
66
+ ## Token Savings — Real Measured Data
67
+
68
+ The hologram system is afd's biggest value driver for AI-assisted development. Here's what we measured in a real session:
69
+
70
+ ### Session Snapshot (measured during a real coding session)
71
+
72
+ | Metric | Value |
73
+ |:-------|:------|
74
+ | Hologram requests | 8 calls |
75
+ | Target files total size | ~114.5 KB (8 files, avg 14.3 KB each) |
76
+ | Original token cost | ~28,600 tokens |
77
+ | After hologram compression | ~1,700 tokens |
78
+ | **Tokens saved** | **~26,900 tokens (94% reduction)** |
79
+
80
+ ### How It Scales
81
+
82
+ ```
83
+ Session tokens (at ctx ~15%): ~150,000 ████████████████
84
+ Tokens saved by hologram: ~26,900 ██░░░░░░░░░░░░░░ (18% of session)
85
+ ```
86
+
87
+ At ctx 50%+, file reads dominate the token budget. Without hologram, reading 8 large files costs ~28.6K tokens each time. With hologram, **each file costs 1/16th** of its original footprint — and the gap widens with every repeated read.
88
+
89
+ ### Three Layers of Token Optimization
90
+
91
+ | Layer | Tool | Savings | How |
92
+ |:------|:-----|:--------|:----|
93
+ | **L0 Hologram** | `afd_hologram` | 80%+ | Strip function bodies, keep type signatures |
94
+ | **L1 Hologram** | `afd_hologram` + `contextFile` | 85%+ | Filter to only imported symbols |
95
+ | **Smart Reader** | `afd_read` | Auto | Files < 10KB raw, >= 10KB auto-hologram |
96
+ | **Workspace Map** | `afd://workspace-map` | N/A | Entire project structure in one call |
97
+
98
+ ---
99
+
100
+ ## The One-Command Experience
41
101
 
42
102
  ```bash
43
103
  npx @dotoricode/afd start
@@ -49,27 +109,24 @@ Or install locally:
49
109
  bun link && afd start
50
110
  ```
51
111
 
52
- That's it. One command. `afd` takes over from here:
112
+ That's it. `afd` takes over from here:
53
113
 
54
- - **Auto-Injection** — Installs `PreToolUse` hooks into Claude Code silently. No manual config editing.
55
- - **Sense (Watcher)** — 10ms real-time monitoring of critical configs: `.claude/`, `CLAUDE.md`, `.cursorrules`.
56
- - **Auto-Heal** — Silent background repair of missing or corrupted files using the **S.E.A.M cycle**. You won't even notice it happened.
114
+ - **Auto-Injection** — Installs `PreToolUse` hooks into Claude Code silently.
115
+ - **Sense (Watcher)** — 10ms real-time monitoring of critical configs.
116
+ - **Auto-Heal** — Silent background repair using the S.E.A.M cycle.
57
117
 
58
118
  ```
59
119
  $ afd start
60
- afd daemon started (pid 4812, port 52413)
120
+ Daemon started (pid 4812, port 52413)
121
+ Smart Discovery: Watching 7 AI-context targets
61
122
  Hook injected into .claude/hooks.json
62
- Watching: .claude/, CLAUDE.md, .cursorrules
63
- Ready.
64
123
  ```
65
124
 
66
- > You type `afd start`. Then you forget about it. That's the entire UX.
67
-
68
125
  ---
69
126
 
70
127
  ## The S.E.A.M Cycle
71
128
 
72
- The intelligence inside `afd`. Every file event flows through four stages:
129
+ Every file event flows through four stages:
73
130
 
74
131
  ```mermaid
75
132
  graph LR
@@ -86,159 +143,88 @@ graph LR
86
143
  | Stage | What Happens | Speed |
87
144
  |:------|:-------------|:------|
88
145
  | **Sense** | Chokidar watcher detects `add`, `change`, `unlink` events | < 10ms |
89
- | **Extract** | Immune engine runs 3 built-in health checks (IMM-001..003) | < 5ms |
90
- | **Adapt** | Matches symptom to stored antibody in SQLite (WAL mode) | < 1ms |
146
+ | **Extract** | Generates hologram (type skeleton) & runs health checks | < 5ms |
147
+ | **Adapt** | Matches symptom to antibody, quarantines corrupted state | < 1ms |
91
148
  | **Mutate** | Applies RFC 6902 JSON-Patch to restore the file | < 25ms |
92
149
 
93
150
  > Full cycle: **< 270ms** from file deletion to full recovery.
94
151
 
95
152
  ---
96
153
 
97
- ## The Magic 5 Commands
98
-
99
- Everything you need. Nothing you don't.
100
-
101
- | Command | Essence | Intelligence Inside |
102
- |:--------|:--------|:--------------------|
103
- | `afd start` | **Ignite** | Daemon spawn + Hook injection |
104
- | `afd fix` | **Diagnose** | Symptom detection & Antibody learning |
105
- | `afd score` | **Vitals** | Health dashboard & Auto-heal stats |
106
- | `afd sync` | **Federate** | Vaccine payload export for cross-project immunity |
107
- | `afd stop` | **Quarantine** | Graceful shutdown & cleanup |
108
-
109
- ### Quick Reference
110
-
111
- ```bash
112
- afd start # Start daemon, inject hooks, begin watching
113
- afd fix # Scan for issues, auto-patch, learn antibodies
114
- afd score # Full diagnostic dashboard
115
- afd sync # Export antibodies to .afd/global-vaccine-payload.json
116
- afd stop # Graceful shutdown
117
- ```
118
-
119
- ---
120
-
121
- ## Dashboard: `afd score`
122
-
123
- ```
124
- ┌──────────────────────────────────────────────┐
125
- │ afd score — Daemon Diagnostics │
126
- ├──────────────────────────────────────────────┤
127
- │ Ecosystem : Claude Code │
128
- ├──────────────────────────────────────────────┤
129
- │ Uptime : 1h 23m │
130
- │ Events : 156 │
131
- │ Files Found : 8 │
132
- ├──────────────────────────────────────────────┤
133
- │ Immune System │
134
- │ ────────────────────────────── │
135
- │ Antibodies : 7 │
136
- │ Level : Fortified │
137
- │ Auto-healed : 3 background events │
138
- │ Last heal : IMM-003 (12m ago) │
139
- ├──────────────────────────────────────────────┤
140
- │ Suppression Safety │
141
- │ ────────────────────────────── │
142
- │ Mass events skipped : 2 │
143
- │ Dormant transitions : 0 │
144
- │ Active first-taps : 1 │
145
- ├──────────────────────────────────────────────┤
146
- │ Hologram Budget : 84% token savings │
147
- └──────────────────────────────────────────────┘
148
- ```
154
+ ## Commands
155
+
156
+ | Command | What it does |
157
+ |:--------|:-------------|
158
+ | `afd start` | Daemon spawn + Smart Discovery + Hook injection + MCP registration |
159
+ | `afd stop` | Shift summary report & graceful shutdown (`--clean` to remove hooks & MCP) |
160
+ | `afd score` | Health dashboard with evolution & hologram metrics |
161
+ | `afd fix` | Symptom detection with hologram context & antibody learning |
162
+ | `afd sync` | Vaccine payload export/import (`--push`, `--pull`, `--remote <url>`) |
163
+ | `afd restart` | Stop + start in one command |
164
+ | `afd status` | Quick health check daemon, hooks, MCP, defenses |
165
+ | `afd doctor` | Comprehensive health analysis with auto-fix recommendations |
166
+ | `afd evolution` | Analyze quarantined failures & generate prevention rules |
167
+ | `afd mcp install` | Register afd as MCP server in project + global config |
168
+ | `afd vaccine` | List, search, install, publish community antibodies |
169
+ | `afd lang` | Switch display language (`afd lang ko` / `afd lang en`) |
149
170
 
150
171
  ---
151
172
 
152
173
  ## Advanced Intelligence
153
174
 
154
- ### Double-Tap Heuristic (Immune Tolerance)
175
+ ### Double-Tap Heuristic
155
176
 
156
177
  `afd` distinguishes **accidents** from **intent**:
157
178
 
158
179
  ```
159
- $ rm .claudeignore # First tap afd heals it silently
160
- $ rm .claudeignore # Second tap within 60s "You meant it."
161
- [afd] Antibody IMM-001 set to dormant. Delete honored.
180
+ $ rm .claudeignore # First tap -> afd heals it silently
181
+ $ rm .claudeignore # Second tap within 30s -> "You meant it."
182
+ [afd] Antibody IMM-001 retired. Double-tap detected. Standing down.
162
183
  ```
163
184
 
164
185
  | Scenario | Response |
165
186
  |:---------|:---------|
166
187
  | Single delete (accident) | Auto-heal + record first tap |
167
- | Re-delete within 60s (intent) | Antibody goes dormant, deletion respected |
168
- | Re-delete after 60s | Fresh first tap, heals again |
188
+ | Re-delete within 30s (intent) | Antibody goes dormant, deletion respected |
169
189
  | 3+ deletes in 1s (git checkout) | Mass-event detected, all suppression paused |
170
190
 
171
- ### Vaccine Network (Team Federation)
172
-
173
- Export learned antibodies for your entire team:
191
+ ### Vaccine Network
174
192
 
175
193
  ```bash
176
- afd sync
177
- # .afd/global-vaccine-payload.json
194
+ afd sync # Export to .afd/global-vaccine-payload.json
195
+ afd sync --push # Push vaccines to remote
196
+ afd sync --pull # Pull vaccines from remote
178
197
  ```
179
198
 
180
- The payload is sanitized (no absolute paths, no secrets) and portable. Drop it into any project, and `afd` inherits the immunity.
181
-
182
- ### Hologram Extraction
199
+ The payload is sanitized (no absolute paths, no secrets) and portable.
183
200
 
184
- When AI agents request file context, `afd` serves **token-efficient skeletons** — stripping comments and function bodies while preserving the full type signature:
201
+ ### Self-Evolution
185
202
 
186
- ```
187
- Original: 2,450 chars → Hologram: 380 chars (84% savings)
203
+ ```bash
204
+ afd evolution
188
205
  ```
189
206
 
190
- This keeps your AI agent's context window lean without losing structural understanding.
207
+ 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.
191
208
 
192
209
  ---
193
210
 
194
- ## Status Line
211
+ ## MCP Setup
195
212
 
196
- Real-time daemon status in Claude Code's status bar:
197
-
198
- ```
199
- 🛡️ afd: OFF # Daemon not running
200
- 🛡️ afd: ON # Running, no heals
201
- 🛡️ afd: ON 🩹1 # 1 auto-heal event
202
- 🛡️ afd: ON | 🩹 3 Healed | last: IMM-003 # Detailed view
203
- ```
204
-
205
- ---
213
+ `afd` provides four MCP tools and one resource:
206
214
 
207
- ## Plugin / MCP Setup
215
+ | MCP Tool | Purpose |
216
+ |:---------|:--------|
217
+ | `afd_read` | Smart file reader — raw for small files, auto-hologram for large, optional line ranges |
218
+ | `afd_hologram` | Token-efficient type skeleton of any TS/JS file (80%+ savings) |
219
+ | `afd_diagnose` | Health diagnosis with symptoms and hologram context |
220
+ | `afd_score` | Runtime stats: uptime, heals, hologram savings |
208
221
 
209
- `afd` can be registered as a **Model Context Protocol (MCP) server** inside Claude Code, allowing the daemon to start automatically when Claude Code launches.
210
-
211
- ### Automatic (recommended)
212
-
213
- Add to your Claude Code MCP config (`~/.claude/mcp.json` or project-level `.mcp.json`):
214
-
215
- ```json
216
- {
217
- "mcpServers": {
218
- "afd": {
219
- "command": "bun",
220
- "args": ["run", "src/cli.ts", "start"]
221
- }
222
- }
223
- }
224
- ```
225
-
226
- Or copy the included manifest directly:
227
-
228
- ```bash
229
- cp mcp-config.json .mcp.json
230
- ```
231
-
232
- ### Manual
222
+ | MCP Resource | Purpose |
223
+ |:-------------|:--------|
224
+ | `afd://workspace-map` | Full file tree with export signatures in one call |
233
225
 
234
226
  ```bash
235
- afd start # starts daemon in background, injects hooks
236
- ```
237
-
238
- Once registered, Claude Code will display the live status line:
239
-
240
- ```
241
- 🛡️ afd: ON | 🩹 3 Healed | last: IMM-003
227
+ afd mcp install # Registers in .mcp.json + ~/.claude.json
242
228
  ```
243
229
 
244
230
  ---
@@ -271,11 +257,10 @@ npx @dotoricode/afd start
271
257
 
272
258
  - **Bun** >= 1.0
273
259
  - **OS**: Windows, macOS, Linux
274
- - **Target**: Claude Code, Cursor (ecosystem auto-detected)
260
+ - **Target**: Claude Code, Cursor, Windsurf, Codex (ecosystem auto-detected)
275
261
 
276
262
  ---
277
263
 
278
264
  ## License
279
265
 
280
266
  MIT
281
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autonomous-flow-daemon",
3
- "version": "1.0.0",
3
+ "version": "1.6.0",
4
4
  "description": "Zero-config immunity for AI coding workflows. Self-heals broken configs in < 270ms.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -26,14 +26,20 @@
26
26
  "dev-tools"
27
27
  ],
28
28
  "scripts": {
29
- "start": "bun run src/cli.ts start",
30
- "dev": "bun run src/cli.ts",
29
+ "dev": "bun --watch src/cli.ts",
30
+ "score": "bun src/cli.ts score",
31
+ "start": "bun src/cli.ts start",
31
32
  "test": "bun test"
32
33
  },
33
34
  "dependencies": {
34
35
  "chokidar": "^4.0.3",
35
36
  "commander": "^13.1.0",
36
- "typescript": "^6.0.2"
37
+ "typescript": "^6.0.2",
38
+ "web-tree-sitter": "^0.26.8"
37
39
  },
38
- "license": "MIT"
40
+ "license": "MIT",
41
+ "optionalDependencies": {
42
+ "tree-sitter-python": "^0.25.0",
43
+ "tree-sitter-typescript": "^0.23.2"
44
+ }
39
45
  }