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