fusion-agent 1.1.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 (142) hide show
  1. package/README.md +467 -0
  2. package/REQUIREMENTS.md +158 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +500 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/cluster-monitor/cluster-monitor.d.ts +49 -0
  8. package/dist/cluster-monitor/cluster-monitor.d.ts.map +1 -0
  9. package/dist/cluster-monitor/cluster-monitor.js +374 -0
  10. package/dist/cluster-monitor/cluster-monitor.js.map +1 -0
  11. package/dist/cluster-monitor/index.d.ts +9 -0
  12. package/dist/cluster-monitor/index.d.ts.map +1 -0
  13. package/dist/cluster-monitor/index.js +19 -0
  14. package/dist/cluster-monitor/index.js.map +1 -0
  15. package/dist/cluster-monitor/kubernetes-connector.d.ts +21 -0
  16. package/dist/cluster-monitor/kubernetes-connector.d.ts.map +1 -0
  17. package/dist/cluster-monitor/kubernetes-connector.js +109 -0
  18. package/dist/cluster-monitor/kubernetes-connector.js.map +1 -0
  19. package/dist/cluster-monitor/notifications.d.ts +26 -0
  20. package/dist/cluster-monitor/notifications.d.ts.map +1 -0
  21. package/dist/cluster-monitor/notifications.js +182 -0
  22. package/dist/cluster-monitor/notifications.js.map +1 -0
  23. package/dist/cluster-monitor/remediation.d.ts +33 -0
  24. package/dist/cluster-monitor/remediation.d.ts.map +1 -0
  25. package/dist/cluster-monitor/remediation.js +134 -0
  26. package/dist/cluster-monitor/remediation.js.map +1 -0
  27. package/dist/cluster-monitor/rules.d.ts +26 -0
  28. package/dist/cluster-monitor/rules.d.ts.map +1 -0
  29. package/dist/cluster-monitor/rules.js +133 -0
  30. package/dist/cluster-monitor/rules.js.map +1 -0
  31. package/dist/cluster-monitor/types.d.ts +184 -0
  32. package/dist/cluster-monitor/types.d.ts.map +1 -0
  33. package/dist/cluster-monitor/types.js +3 -0
  34. package/dist/cluster-monitor/types.js.map +1 -0
  35. package/dist/index.d.ts +47 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +115 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/live-debugger/index.d.ts +32 -0
  40. package/dist/live-debugger/index.d.ts.map +1 -0
  41. package/dist/live-debugger/index.js +119 -0
  42. package/dist/live-debugger/index.js.map +1 -0
  43. package/dist/live-debugger/log-watcher.d.ts +19 -0
  44. package/dist/live-debugger/log-watcher.d.ts.map +1 -0
  45. package/dist/live-debugger/log-watcher.js +77 -0
  46. package/dist/live-debugger/log-watcher.js.map +1 -0
  47. package/dist/live-debugger/service-connector.d.ts +33 -0
  48. package/dist/live-debugger/service-connector.d.ts.map +1 -0
  49. package/dist/live-debugger/service-connector.js +123 -0
  50. package/dist/live-debugger/service-connector.js.map +1 -0
  51. package/dist/providers/anthropic.d.ts +9 -0
  52. package/dist/providers/anthropic.d.ts.map +1 -0
  53. package/dist/providers/anthropic.js +71 -0
  54. package/dist/providers/anthropic.js.map +1 -0
  55. package/dist/providers/base.d.ts +29 -0
  56. package/dist/providers/base.d.ts.map +1 -0
  57. package/dist/providers/base.js +14 -0
  58. package/dist/providers/base.js.map +1 -0
  59. package/dist/providers/gemini.d.ts +11 -0
  60. package/dist/providers/gemini.d.ts.map +1 -0
  61. package/dist/providers/gemini.js +73 -0
  62. package/dist/providers/gemini.js.map +1 -0
  63. package/dist/providers/index.d.ts +14 -0
  64. package/dist/providers/index.d.ts.map +1 -0
  65. package/dist/providers/index.js +38 -0
  66. package/dist/providers/index.js.map +1 -0
  67. package/dist/providers/openai.d.ts +9 -0
  68. package/dist/providers/openai.d.ts.map +1 -0
  69. package/dist/providers/openai.js +59 -0
  70. package/dist/providers/openai.js.map +1 -0
  71. package/dist/session/guardrails.d.ts +20 -0
  72. package/dist/session/guardrails.d.ts.map +1 -0
  73. package/dist/session/guardrails.js +83 -0
  74. package/dist/session/guardrails.js.map +1 -0
  75. package/dist/session/index.d.ts +6 -0
  76. package/dist/session/index.d.ts.map +1 -0
  77. package/dist/session/index.js +12 -0
  78. package/dist/session/index.js.map +1 -0
  79. package/dist/session/session-manager.d.ts +15 -0
  80. package/dist/session/session-manager.d.ts.map +1 -0
  81. package/dist/session/session-manager.js +89 -0
  82. package/dist/session/session-manager.js.map +1 -0
  83. package/dist/session/session.d.ts +63 -0
  84. package/dist/session/session.d.ts.map +1 -0
  85. package/dist/session/session.js +123 -0
  86. package/dist/session/session.js.map +1 -0
  87. package/dist/speckits/base.d.ts +9 -0
  88. package/dist/speckits/base.d.ts.map +1 -0
  89. package/dist/speckits/base.js +3 -0
  90. package/dist/speckits/base.js.map +1 -0
  91. package/dist/speckits/cluster-debugger.d.ts +3 -0
  92. package/dist/speckits/cluster-debugger.d.ts.map +1 -0
  93. package/dist/speckits/cluster-debugger.js +48 -0
  94. package/dist/speckits/cluster-debugger.js.map +1 -0
  95. package/dist/speckits/code-review.d.ts +3 -0
  96. package/dist/speckits/code-review.d.ts.map +1 -0
  97. package/dist/speckits/code-review.js +41 -0
  98. package/dist/speckits/code-review.js.map +1 -0
  99. package/dist/speckits/debugger.d.ts +3 -0
  100. package/dist/speckits/debugger.d.ts.map +1 -0
  101. package/dist/speckits/debugger.js +38 -0
  102. package/dist/speckits/debugger.js.map +1 -0
  103. package/dist/speckits/index.d.ts +11 -0
  104. package/dist/speckits/index.d.ts.map +1 -0
  105. package/dist/speckits/index.js +40 -0
  106. package/dist/speckits/index.js.map +1 -0
  107. package/dist/speckits/more-speckits.d.ts +6 -0
  108. package/dist/speckits/more-speckits.d.ts.map +1 -0
  109. package/dist/speckits/more-speckits.js +136 -0
  110. package/dist/speckits/more-speckits.js.map +1 -0
  111. package/dist/speckits/vibe-coder.d.ts +3 -0
  112. package/dist/speckits/vibe-coder.d.ts.map +1 -0
  113. package/dist/speckits/vibe-coder.js +32 -0
  114. package/dist/speckits/vibe-coder.js.map +1 -0
  115. package/dist/utils/config.d.ts +18 -0
  116. package/dist/utils/config.d.ts.map +1 -0
  117. package/dist/utils/config.js +107 -0
  118. package/dist/utils/config.js.map +1 -0
  119. package/dist/utils/file-ops.d.ts +15 -0
  120. package/dist/utils/file-ops.d.ts.map +1 -0
  121. package/dist/utils/file-ops.js +109 -0
  122. package/dist/utils/file-ops.js.map +1 -0
  123. package/dist/utils/logger.d.ts +4 -0
  124. package/dist/utils/logger.d.ts.map +1 -0
  125. package/dist/utils/logger.js +25 -0
  126. package/dist/utils/logger.js.map +1 -0
  127. package/dist/web/public/css/app.css +370 -0
  128. package/dist/web/public/index.html +91 -0
  129. package/dist/web/public/js/app.js +212 -0
  130. package/dist/web/routes/sessions.d.ts +4 -0
  131. package/dist/web/routes/sessions.d.ts.map +1 -0
  132. package/dist/web/routes/sessions.js +51 -0
  133. package/dist/web/routes/sessions.js.map +1 -0
  134. package/dist/web/routes/settings.d.ts +3 -0
  135. package/dist/web/routes/settings.d.ts.map +1 -0
  136. package/dist/web/routes/settings.js +33 -0
  137. package/dist/web/routes/settings.js.map +1 -0
  138. package/dist/web/server.d.ts +16 -0
  139. package/dist/web/server.d.ts.map +1 -0
  140. package/dist/web/server.js +76 -0
  141. package/dist/web/server.js.map +1 -0
  142. package/package.json +86 -0
package/README.md ADDED
@@ -0,0 +1,467 @@
1
+ # fusion-agent
2
+
3
+ > ⚠️ **Package renamed:** The previous npm package `polyai-agent` has been deprecated and replaced by **`fusion-agent`**.
4
+ > Please install the new package: `npm install -g fusion-agent`
5
+
6
+ An AI-powered **vibe coder**, **live service debugger**, and **agent session manager** deployable, usable as a CLI or importable library.
7
+
8
+ Supports **OpenAI**, **Anthropic**, and **Google Gemini** with streaming responses.
9
+
10
+ ---
11
+
12
+ ## Features
13
+
14
+ | Feature | Description |
15
+ |---------|-------------|
16
+ | 🤖 Vibe Coder | AI pair-programmer that reads your project context and generates/refactors code |
17
+ | 🔍 Live Debugger | Attach to running services (log files, Docker, processes) and get real-time AI analysis |
18
+ | 📦 Speckits | 7 prebuilt agent configurations: vibe-coder, debugger, code-review, doc-writer, test-writer, refactor, security-audit |
19
+ | 🛡 Guardrails | Per-session rules the AI must follow (allowed paths, denied operations, style rules, custom rules) |
20
+ | 💾 Sessions | Named, persistent sessions with full conversation history and file-change tracking |
21
+ | 🌐 Web UI | Built-in web dashboard to view, manage and export sessions |
22
+ | 📚 Library API | Importable TypeScript module for programmatic use |
23
+
24
+ ---
25
+
26
+ ## Architecture & Flow
27
+
28
+ ### High-Level Architecture
29
+
30
+ ```mermaid
31
+ flowchart TD
32
+ User([👤 User]) --> CLI["CLI\n<code>ai-agent</code>"]
33
+ User --> LibAPI["Library API\n<code>import { AgentCLI }</code>"]
34
+
35
+ CLI --> Chat["<code>chat</code>\nvibe-coder / speckit"]
36
+ CLI --> Debug["<code>debug</code>\nLive Debugger"]
37
+ CLI --> UI["<code>ui</code>\nWeb Dashboard"]
38
+ CLI --> SessionCmd["<code>session</code>\nSession Manager"]
39
+ CLI --> Speckit["<code>speckit</code>\nSpeckit Browser"]
40
+ CLI --> Config["<code>config</code>\nConfiguration"]
41
+
42
+ Chat --> SM[Session Manager]
43
+ LibAPI --> SM
44
+
45
+ SM --> Guardrails[🛡 Guardrails]
46
+ SM --> SpeckitConf[📦 Speckit Config]
47
+ SM --> Providers
48
+
49
+ Debug --> LiveDbg[Live Debugger]
50
+ LiveDbg --> Providers
51
+ LiveDbg --> LogSrc[Log Sources]
52
+
53
+ LogSrc --> LogFile[📄 Log File]
54
+ LogSrc --> DockerSrc[🐳 Docker Container]
55
+ LogSrc --> ProcSrc[⚙️ Process / Command]
56
+ LogSrc --> HTTPSrc[🌐 HTTP Poll]
57
+
58
+ Providers[AI Providers] --> OpenAI[OpenAI]
59
+ Providers --> Anthropic[Anthropic]
60
+ Providers --> Gemini[Google Gemini]
61
+
62
+ SM --> Storage[(💾 &lt;home&gt;/.fusion-agent/\nsessions)]
63
+
64
+ UI --> WebServer["Express + Socket.IO\nWeb Server"]
65
+ WebServer --> SM
66
+ SessionCmd --> SM
67
+ ```
68
+
69
+ ---
70
+
71
+ ### Chat Session Flow
72
+
73
+ ```mermaid
74
+ sequenceDiagram
75
+ actor U as User
76
+ participant CLI as CLI
77
+ participant SM as Session Manager
78
+ participant SK as Speckit
79
+ participant G as Guardrails
80
+ participant P as AI Provider
81
+
82
+ U->>CLI: ai-agent chat --speckit vibe-coder --session my-project
83
+ CLI->>SM: Create or resume session "my-project"
84
+ SM->>SK: Load speckit system prompt (vibe-coder)
85
+ SM->>G: Inject guardrail rules into system prompt
86
+
87
+ loop Interactive conversation
88
+ U->>CLI: Enter message / code request
89
+ CLI->>P: Send (system prompt + history + message)
90
+ P-->>CLI: Stream response tokens
91
+ CLI-->>U: Display streamed response
92
+ CLI->>SM: Record turn + any file changes
93
+ end
94
+
95
+ U->>CLI: /exit
96
+ CLI->>SM: Persist session to <home>/.fusion-agent/sessions/
97
+ SM-->>U: Session saved ✓
98
+ ```
99
+
100
+ ---
101
+
102
+ ### Live Debugger Flow
103
+
104
+ ```mermaid
105
+ flowchart LR
106
+ subgraph Sources["Log Sources"]
107
+ LF[📄 Log File]
108
+ DC[🐳 Docker Logs]
109
+ PR[⚙️ Process stdout]
110
+ HP[🌐 HTTP Health Poll]
111
+ end
112
+
113
+ subgraph Debugger["Live Debugger"]
114
+ Collector[Log Collector]
115
+ Batcher["Batch Buffer\n(configurable size)"]
116
+ Analyzer[AI Analysis]
117
+ end
118
+
119
+ subgraph Output["Output"]
120
+ Terminal[Terminal / onAnalysis callback]
121
+ Session[Session Turn Record]
122
+ end
123
+
124
+ LF --> Collector
125
+ DC --> Collector
126
+ PR --> Collector
127
+ HP --> Collector
128
+
129
+ Collector --> Batcher
130
+ Batcher -->|"batch full or timeout"| Analyzer
131
+ Analyzer -->|AI Provider| Terminal
132
+ Analyzer --> Session
133
+ ```
134
+
135
+ ---
136
+
137
+ ## Installation
138
+
139
+ ```bash
140
+ # Global install (recommended for CLI use)
141
+ npm install -g fusion-agent
142
+
143
+ # Dev dependency (for programmatic use)
144
+ npm install --save-dev fusion-agent
145
+ ```
146
+
147
+ ---
148
+
149
+ ## Quick Start
150
+
151
+ ### Set your API key
152
+
153
+ ```bash
154
+ export OPENAI_API_KEY=sk-...
155
+ # or
156
+ export ANTHROPIC_API_KEY=sk-ant-...
157
+ # or
158
+ export GEMINI_API_KEY=AIza...
159
+ ```
160
+
161
+ ### Start coding
162
+
163
+ ```bash
164
+ ai-agent chat
165
+ ```
166
+
167
+ ### Debug a live service
168
+
169
+ ```bash
170
+ ai-agent debug --file /var/log/myapp.log
171
+ ai-agent debug --docker my-container
172
+ ai-agent debug --cmd "node server.js"
173
+ ```
174
+
175
+ ### Launch Web UI
176
+
177
+ ```bash
178
+ ai-agent ui
179
+ # Open http://localhost:3000
180
+ ```
181
+
182
+ ---
183
+
184
+ ## CLI Reference
185
+
186
+ ```
187
+ Usage: ai-agent [options] [command]
188
+
189
+ Commands:
190
+ chat [options] Start an interactive chat session (vibe coder mode)
191
+ speckit [name] List or run a prebuilt speckit
192
+ debug [options] Attach to a live service and start AI-assisted debugging
193
+ session [options] Manage sessions (list, delete, export)
194
+ ui [options] Launch the Web UI
195
+ config [options] Configure default settings
196
+
197
+ Options:
198
+ -V, --version output the version number
199
+ -h, --help display help for command
200
+ ```
201
+
202
+ ### `ai-agent chat`
203
+
204
+ ```bash
205
+ ai-agent chat [options]
206
+
207
+ Options:
208
+ -p, --provider <provider> AI provider (openai|anthropic|gemini)
209
+ -m, --model <model> Model name (e.g. gpt-4o)
210
+ -s, --session <name> Session name — creates or resumes (default: "default")
211
+ -k, --speckit <speckit> Speckit to use (default: vibe-coder)
212
+ -g, --guardrail <rule> Add a guardrail rule (repeatable)
213
+ --context Inject project directory structure as context
214
+ ```
215
+
216
+ #### Interactive commands
217
+
218
+ Inside a chat session:
219
+
220
+ | Command | Action |
221
+ |---------|--------|
222
+ | `/exit` or `/quit` | End session and save |
223
+ | `/save` | Save current session |
224
+ | `/turns` | Show conversation history |
225
+ | `/context` | Inject current project context |
226
+
227
+ ### `ai-agent speckit`
228
+
229
+ ```bash
230
+ ai-agent speckit # list all speckits
231
+ ai-agent speckit vibe-coder # show details of a speckit
232
+ ```
233
+
234
+ ### `ai-agent debug`
235
+
236
+ ```bash
237
+ ai-agent debug --file /var/log/app.log # Watch a log file
238
+ ai-agent debug --docker my-container # Docker container logs
239
+ ai-agent debug --cmd "node server.js" # Attach to a process
240
+ ai-agent debug --batch 30 --session my-debug # Custom batch size
241
+ ```
242
+
243
+ ### `ai-agent session`
244
+
245
+ ```bash
246
+ ai-agent session --list # List all sessions
247
+ ai-agent session --delete <id> # Delete a session
248
+ ai-agent session --export <id> # Print session JSON
249
+ ```
250
+
251
+ ### `ai-agent ui`
252
+
253
+ ```bash
254
+ ai-agent ui # Start on default port 3000
255
+ ai-agent ui --port 8080 # Custom port
256
+ ```
257
+
258
+ ### `ai-agent config`
259
+
260
+ ```bash
261
+ ai-agent config --show # Show current config
262
+ ai-agent config --provider openai # Set default provider
263
+ ai-agent config --model gpt-4o # Set default model
264
+ ai-agent config --port 3000 # Set default Web UI port
265
+ ```
266
+
267
+ ---
268
+
269
+ ## Speckits
270
+
271
+ Speckits are pre-configured agent personas. Use `--speckit <name>` with `chat`.
272
+
273
+ | Name | Description |
274
+ |------|-------------|
275
+ | `vibe-coder` | Full-stack AI pair programmer (default) |
276
+ | `debugger` | Root-cause analysis and targeted code fixes |
277
+ | `code-review` | OWASP/quality review with severity grading |
278
+ | `doc-writer` | JSDoc, README, OpenAPI docs generation |
279
+ | `test-writer` | Unit and integration test generation |
280
+ | `refactor` | Structural refactoring without changing behavior |
281
+ | `security-audit` | OWASP Top 10 security vulnerability scan |
282
+
283
+ ```bash
284
+ ai-agent chat --speckit security-audit
285
+ ```
286
+
287
+ ---
288
+
289
+ ## Guardrails
290
+
291
+ Guardrails are rules injected into the AI's system prompt to constrain its behavior.
292
+
293
+ ```bash
294
+ # Only allow changes in src/
295
+ ai-agent chat -g "Only modify files within the src/ directory"
296
+
297
+ # Enforce code style
298
+ ai-agent chat -g "Always use TypeScript strict mode" -g "Prefer async/await over callbacks"
299
+
300
+ # Multiple guardrails
301
+ ai-agent chat \
302
+ -g "Never delete files" \
303
+ -g "Always write unit tests for new functions" \
304
+ -g "Use camelCase for all variable names"
305
+ ```
306
+
307
+ ### Guardrail types (programmatic API)
308
+
309
+ ```typescript
310
+ import { createGuardrail } from 'fusion-agent';
311
+
312
+ createGuardrail('allow-paths', ['./src', './tests'])
313
+ createGuardrail('deny-paths', ['./node_modules', './.env'])
314
+ createGuardrail('deny-operations', ['delete', 'overwrite'])
315
+ createGuardrail('max-tokens', 2000)
316
+ createGuardrail('style', 'Use functional programming patterns')
317
+ createGuardrail('custom', 'Always add JSDoc to exported functions')
318
+ ```
319
+
320
+ ---
321
+
322
+ ## Configuration File
323
+
324
+ Create `.fusion-agent.json` in your project root:
325
+
326
+ ```json
327
+ {
328
+ "provider": "openai",
329
+ "model": "gpt-4o",
330
+ "port": 3000,
331
+ "guardrails": [
332
+ { "type": "custom", "value": "Always use TypeScript" }
333
+ ]
334
+ }
335
+ ```
336
+
337
+ Or `~/.fusion-agent/config.json` for global settings.
338
+
339
+ **API keys are never stored in config files** — use environment variables:
340
+
341
+ ```bash
342
+ OPENAI_API_KEY=sk-...
343
+ ANTHROPIC_API_KEY=sk-ant-...
344
+ GEMINI_API_KEY=AIza...
345
+ AI_PROVIDER=openai
346
+ AI_MODEL=gpt-4o
347
+ AI_AGENT_PORT=3000
348
+ ```
349
+
350
+ ---
351
+
352
+ ## Library / Programmatic API
353
+
354
+ ```typescript
355
+ import { AgentCLI, createGuardrail } from 'fusion-agent';
356
+
357
+ // Create an agent instance
358
+ const agent = new AgentCLI({
359
+ provider: 'openai', // or 'anthropic', 'gemini'
360
+ model: 'gpt-4o',
361
+ apiKey: process.env.OPENAI_API_KEY,
362
+ });
363
+
364
+ // One-shot chat
365
+ const response = await agent.chat('Write a hello world in Rust');
366
+ console.log(response);
367
+
368
+ // Session-based chat with guardrails
369
+ const session = agent.createSession({
370
+ name: 'my-project',
371
+ speckit: 'vibe-coder',
372
+ guardrails: [
373
+ createGuardrail('allow-paths', ['./src']),
374
+ createGuardrail('custom', 'Always add TypeScript types'),
375
+ ],
376
+ });
377
+
378
+ const turn = await session.chat('Add a user authentication middleware');
379
+ console.log(turn.assistantMessage);
380
+
381
+ // Apply a file change
382
+ session.applyFileChange('./src/middleware/auth.ts', '// new content...');
383
+
384
+ // Revert the change
385
+ session.revertTurnChanges(turn.id);
386
+
387
+ // Save session
388
+ agent.sessionManager.persistSession(session);
389
+ ```
390
+
391
+ ### Live Debugger API
392
+
393
+ ```typescript
394
+ import { AgentCLI, LiveDebugger } from 'fusion-agent';
395
+
396
+ const agent = new AgentCLI({ provider: 'openai' });
397
+ const session = agent.createSession({ name: 'debug', speckit: 'debugger' });
398
+
399
+ const debugger_ = new LiveDebugger({
400
+ session,
401
+ batchSize: 20,
402
+ onLog: (line) => console.log(line),
403
+ onAnalysis: (analysis) => console.log('AI:', analysis),
404
+ });
405
+
406
+ // Watch a log file
407
+ debugger_.watchLogFile('/var/log/app.log');
408
+
409
+ // Or connect to a service
410
+ debugger_.connectToService({ type: 'docker', container: 'my-app' });
411
+ debugger_.connectToService({ type: 'process', command: 'node', args: ['server.js'] });
412
+ debugger_.connectToService({ type: 'http-poll', url: 'http://localhost:8080/health' });
413
+
414
+ // Stop
415
+ process.on('SIGINT', () => debugger_.stop());
416
+ ```
417
+
418
+ ### Web Server API
419
+
420
+ ```typescript
421
+ import { AgentCLI, createWebServer } from 'fusion-agent';
422
+
423
+ const agent = new AgentCLI({ provider: 'openai' });
424
+ const server = createWebServer({ port: 3000, sessionManager: agent.sessionManager });
425
+ await server.start();
426
+ ```
427
+
428
+ ---
429
+
430
+ ## Web UI
431
+
432
+ Start with `ai-agent ui` and open `http://localhost:3000`.
433
+
434
+ - **Sessions Dashboard** — view all sessions, status, provider, model
435
+ - **Session Detail** — browse conversation turns, guardrails, file changes
436
+ - **Settings** — configure default provider and model
437
+ - **Export** — download any session as JSON
438
+ - **Real-time updates** — via Socket.IO
439
+
440
+ ---
441
+
442
+ ## Providers & Models
443
+
444
+ | Provider | Env Variable | Recommended Models |
445
+ |----------|-------------|-------------------|
446
+ | OpenAI | `OPENAI_API_KEY` | `gpt-4o`, `gpt-4o-mini`, `gpt-4-turbo` |
447
+ | Anthropic | `ANTHROPIC_API_KEY` | `claude-3-5-sonnet-20241022`, `claude-3-5-haiku-20241022` |
448
+ | Google Gemini | `GEMINI_API_KEY` | `gemini-1.5-pro`, `gemini-1.5-flash` |
449
+
450
+ ---
451
+
452
+ ## Development
453
+
454
+ ```bash
455
+ git clone https://github.com/fury-r/ai-agent-cli.git
456
+ cd ai-agent-cli
457
+ npm install
458
+ npm run build
459
+ npm test
460
+ npm run dev -- chat # run CLI in dev mode
461
+ ```
462
+
463
+ ---
464
+
465
+ ## License
466
+
467
+ MIT
@@ -0,0 +1,158 @@
1
+ # AI Agent CLI — Requirements Document
2
+
3
+ ## Overview
4
+ **fusion-agent** is an npm-deployable TypeScript tool that integrates with top AI providers and acts as a _vibe coder_, session manager, live-service debugger, and provides a Web UI for managing AI agent sessions.
5
+
6
+ ---
7
+
8
+ ## 1. Functional Requirements
9
+
10
+ ### 1.1 Multi-Provider AI Integration
11
+ - Support **OpenAI** (GPT-4o, GPT-4-turbo, GPT-3.5-turbo)
12
+ - Support **Anthropic** (Claude 3.5 Sonnet, Claude 3 Haiku)
13
+ - Support **Google Gemini** (gemini-1.5-pro, gemini-1.5-flash)
14
+ - Provider selection via config file, environment variable, or CLI flag
15
+ - Streaming responses supported for all providers
16
+
17
+ ### 1.2 Vibe Coder Mode
18
+ - Acts as an AI pair-programmer that understands project context
19
+ - Reads local files and directory structures to build context
20
+ - Generates, modifies, and refactors code based on natural-language prompts
21
+ - Applies changes to files automatically with user confirmation step
22
+ - Uses speckit templates for common coding patterns
23
+
24
+ ### 1.3 Prebuilt Speckits
25
+ Speckits are pre-configured agent configurations (similar to GitHub speckit concept — opinionated starter templates):
26
+ - **vibe-coder**: Full-stack code generation and refactoring
27
+ - **debugger**: Analyze logs, traces, and errors to suggest fixes
28
+ - **code-review**: Review code for quality, security, and best practices
29
+ - **doc-writer**: Generate or improve documentation
30
+ - **test-writer**: Generate unit and integration tests
31
+ - **refactor**: Suggest and apply structural refactoring
32
+ - **security-audit**: Scan code for security vulnerabilities
33
+
34
+ ### 1.4 Live Service Debugger
35
+ - Connect to a running service via:
36
+ - Log file watching (tail -f)
37
+ - HTTP endpoint polling
38
+ - Docker container log streaming
39
+ - Process stdout/stderr attachment
40
+ - Stream logs to the AI provider in real time
41
+ - AI analyzes errors and proposes code fixes
42
+ - Apply fixes directly to the codebase
43
+ - Supports rollback of applied fixes
44
+
45
+ ### 1.5 Session Management
46
+ - Create named agent sessions with unique IDs
47
+ - Persist session history (conversation, files changed, fixes applied)
48
+ - Resume interrupted sessions
49
+ - Sessions stored in `~/.fusion-agent/sessions/`
50
+ - Session export to JSON
51
+
52
+ ### 1.6 Guardrails & Rules
53
+ Configurable per-session rules that the AI must follow or must not violate:
54
+ - **Allowed file paths**: restrict file access to specific directories
55
+ - **Forbidden operations**: prevent deletion, overwrite of certain files
56
+ - **Max tokens / cost limit**: cap spending per session
57
+ - **Style rules**: enforce coding style (language, framework, patterns)
58
+ - **Custom rules**: free-text rules injected into system prompt
59
+ - Rules defined in `.fusion-agent.json` or per-session config
60
+
61
+ ### 1.7 Web UI
62
+ - Built-in Express + Socket.IO web server
63
+ - **Sessions Dashboard**: list all sessions, status, timestamps
64
+ - **Session Detail**: conversation history, file diffs, guardrails
65
+ - **Live Debugger View**: real-time log stream + AI analysis
66
+ - **Settings**: configure API keys, default provider, global guardrails
67
+ - Accessible at `http://localhost:PORT` (default 3000)
68
+
69
+ ### 1.8 CLI Interface
70
+ ```
71
+ ai-agent [command] [options]
72
+
73
+ Commands:
74
+ chat Start an interactive chat session (vibe coder mode)
75
+ speckit List or run a prebuilt speckit
76
+ debug Attach to a live service and start debugging
77
+ session Manage sessions (list, resume, delete, export)
78
+ ui Launch the Web UI
79
+ config Configure API keys and settings
80
+
81
+ Options:
82
+ --provider AI provider (openai|anthropic|gemini)
83
+ --model Specific model to use
84
+ --session Session name or ID
85
+ --speckit Speckit to use
86
+ --guardrail Add a guardrail rule
87
+ --port Web UI port (default: 3000)
88
+ ```
89
+
90
+ ### 1.9 Library / Programmatic API
91
+ ```typescript
92
+ import { AgentCLI, Session, providers, speckits } from 'fusion-agent';
93
+
94
+ const agent = new AgentCLI({ provider: 'openai', model: 'gpt-4o' });
95
+ const session = await agent.createSession({ name: 'my-session', guardrails: [...] });
96
+ const response = await session.chat('Refactor this function...');
97
+ ```
98
+
99
+ ---
100
+
101
+ ## 2. Non-Functional Requirements
102
+
103
+ - **Language**: TypeScript (compiled to JS for distribution)
104
+ - **Node.js**: >=18.0.0
105
+ - **Streaming**: All AI calls support streaming output
106
+ - **Security**: API keys never logged or stored in plaintext in session files
107
+ - **Configuration**: `.fusion-agent.json` in project root or `~/.fusion-agent/config.json`
108
+ - **Error handling**: Graceful fallback, meaningful error messages
109
+ - **Extensibility**: Provider and speckit plug-in architecture
110
+
111
+ ---
112
+
113
+ ## 3. Architecture
114
+
115
+ ```
116
+ src/
117
+ ├── index.ts # Library entry point
118
+ ├── cli.ts # CLI entry point (bin)
119
+ ├── providers/ # AI provider adapters
120
+ │ ├── base.ts
121
+ │ ├── openai.ts
122
+ │ ├── anthropic.ts
123
+ │ └── gemini.ts
124
+ ├── session/ # Session management
125
+ │ ├── session.ts
126
+ │ ├── session-manager.ts
127
+ │ └── guardrails.ts
128
+ ├── speckits/ # Prebuilt speckit templates
129
+ │ ├── index.ts
130
+ │ ├── vibe-coder.ts
131
+ │ ├── debugger.ts
132
+ │ ├── code-review.ts
133
+ │ ├── doc-writer.ts
134
+ │ ├── test-writer.ts
135
+ │ ├── refactor.ts
136
+ │ └── security-audit.ts
137
+ ├── live-debugger/ # Live service debugger
138
+ │ ├── index.ts
139
+ │ ├── log-watcher.ts
140
+ │ └── service-connector.ts
141
+ ├── web/ # Web UI
142
+ │ ├── server.ts
143
+ │ ├── routes/
144
+ │ └── public/
145
+ └── utils/
146
+ ├── config.ts
147
+ ├── file-ops.ts
148
+ └── logger.ts
149
+ ```
150
+
151
+ ---
152
+
153
+ ## 4. Deployment
154
+
155
+ - Published to **npm** as `fusion-agent`
156
+ - Global install: `npm install -g fusion-agent`
157
+ - Local dev dependency: `npm install --save-dev fusion-agent`
158
+ - Binary: `ai-agent` (aliased as `aac`)
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}