popeye-cli 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 (209) hide show
  1. package/.env.example +25 -0
  2. package/.prettierrc +8 -0
  3. package/README.md +320 -0
  4. package/dist/adapters/claude.d.ts +82 -0
  5. package/dist/adapters/claude.d.ts.map +1 -0
  6. package/dist/adapters/claude.js +230 -0
  7. package/dist/adapters/claude.js.map +1 -0
  8. package/dist/adapters/openai.d.ts +48 -0
  9. package/dist/adapters/openai.d.ts.map +1 -0
  10. package/dist/adapters/openai.js +257 -0
  11. package/dist/adapters/openai.js.map +1 -0
  12. package/dist/auth/claude.d.ts +44 -0
  13. package/dist/auth/claude.d.ts.map +1 -0
  14. package/dist/auth/claude.js +139 -0
  15. package/dist/auth/claude.js.map +1 -0
  16. package/dist/auth/index.d.ts +61 -0
  17. package/dist/auth/index.d.ts.map +1 -0
  18. package/dist/auth/index.js +141 -0
  19. package/dist/auth/index.js.map +1 -0
  20. package/dist/auth/keychain.d.ts +66 -0
  21. package/dist/auth/keychain.d.ts.map +1 -0
  22. package/dist/auth/keychain.js +125 -0
  23. package/dist/auth/keychain.js.map +1 -0
  24. package/dist/auth/openai-entry.d.ts +9 -0
  25. package/dist/auth/openai-entry.d.ts.map +1 -0
  26. package/dist/auth/openai-entry.js +410 -0
  27. package/dist/auth/openai-entry.js.map +1 -0
  28. package/dist/auth/openai.d.ts +71 -0
  29. package/dist/auth/openai.d.ts.map +1 -0
  30. package/dist/auth/openai.js +212 -0
  31. package/dist/auth/openai.js.map +1 -0
  32. package/dist/auth/server.d.ts +32 -0
  33. package/dist/auth/server.d.ts.map +1 -0
  34. package/dist/auth/server.js +213 -0
  35. package/dist/auth/server.js.map +1 -0
  36. package/dist/cli/commands/auth.d.ts +10 -0
  37. package/dist/cli/commands/auth.d.ts.map +1 -0
  38. package/dist/cli/commands/auth.js +162 -0
  39. package/dist/cli/commands/auth.js.map +1 -0
  40. package/dist/cli/commands/config.d.ts +10 -0
  41. package/dist/cli/commands/config.d.ts.map +1 -0
  42. package/dist/cli/commands/config.js +215 -0
  43. package/dist/cli/commands/config.js.map +1 -0
  44. package/dist/cli/commands/create.d.ts +10 -0
  45. package/dist/cli/commands/create.d.ts.map +1 -0
  46. package/dist/cli/commands/create.js +240 -0
  47. package/dist/cli/commands/create.js.map +1 -0
  48. package/dist/cli/commands/index.d.ts +10 -0
  49. package/dist/cli/commands/index.d.ts.map +1 -0
  50. package/dist/cli/commands/index.js +10 -0
  51. package/dist/cli/commands/index.js.map +1 -0
  52. package/dist/cli/commands/resume.d.ts +18 -0
  53. package/dist/cli/commands/resume.d.ts.map +1 -0
  54. package/dist/cli/commands/resume.js +241 -0
  55. package/dist/cli/commands/resume.js.map +1 -0
  56. package/dist/cli/commands/status.d.ts +18 -0
  57. package/dist/cli/commands/status.d.ts.map +1 -0
  58. package/dist/cli/commands/status.js +154 -0
  59. package/dist/cli/commands/status.js.map +1 -0
  60. package/dist/cli/index.d.ts +17 -0
  61. package/dist/cli/index.d.ts.map +1 -0
  62. package/dist/cli/index.js +71 -0
  63. package/dist/cli/index.js.map +1 -0
  64. package/dist/cli/interactive.d.ts +9 -0
  65. package/dist/cli/interactive.d.ts.map +1 -0
  66. package/dist/cli/interactive.js +330 -0
  67. package/dist/cli/interactive.js.map +1 -0
  68. package/dist/cli/output.d.ts +182 -0
  69. package/dist/cli/output.d.ts.map +1 -0
  70. package/dist/cli/output.js +355 -0
  71. package/dist/cli/output.js.map +1 -0
  72. package/dist/config/defaults.d.ts +57 -0
  73. package/dist/config/defaults.d.ts.map +1 -0
  74. package/dist/config/defaults.js +103 -0
  75. package/dist/config/defaults.js.map +1 -0
  76. package/dist/config/index.d.ts +138 -0
  77. package/dist/config/index.d.ts.map +1 -0
  78. package/dist/config/index.js +244 -0
  79. package/dist/config/index.js.map +1 -0
  80. package/dist/config/schema.d.ts +220 -0
  81. package/dist/config/schema.d.ts.map +1 -0
  82. package/dist/config/schema.js +141 -0
  83. package/dist/config/schema.js.map +1 -0
  84. package/dist/generators/index.d.ts +101 -0
  85. package/dist/generators/index.d.ts.map +1 -0
  86. package/dist/generators/index.js +200 -0
  87. package/dist/generators/index.js.map +1 -0
  88. package/dist/generators/python.d.ts +48 -0
  89. package/dist/generators/python.d.ts.map +1 -0
  90. package/dist/generators/python.js +262 -0
  91. package/dist/generators/python.js.map +1 -0
  92. package/dist/generators/templates/index.d.ts +6 -0
  93. package/dist/generators/templates/index.d.ts.map +1 -0
  94. package/dist/generators/templates/index.js +6 -0
  95. package/dist/generators/templates/index.js.map +1 -0
  96. package/dist/generators/templates/python.d.ts +53 -0
  97. package/dist/generators/templates/python.d.ts.map +1 -0
  98. package/dist/generators/templates/python.js +454 -0
  99. package/dist/generators/templates/python.js.map +1 -0
  100. package/dist/generators/templates/typescript.d.ts +53 -0
  101. package/dist/generators/templates/typescript.d.ts.map +1 -0
  102. package/dist/generators/templates/typescript.js +394 -0
  103. package/dist/generators/templates/typescript.js.map +1 -0
  104. package/dist/generators/typescript.d.ts +64 -0
  105. package/dist/generators/typescript.d.ts.map +1 -0
  106. package/dist/generators/typescript.js +271 -0
  107. package/dist/generators/typescript.js.map +1 -0
  108. package/dist/index.d.ts +7 -0
  109. package/dist/index.d.ts.map +1 -0
  110. package/dist/index.js +12 -0
  111. package/dist/index.js.map +1 -0
  112. package/dist/state/index.d.ts +168 -0
  113. package/dist/state/index.d.ts.map +1 -0
  114. package/dist/state/index.js +338 -0
  115. package/dist/state/index.js.map +1 -0
  116. package/dist/state/persistence.d.ts +91 -0
  117. package/dist/state/persistence.d.ts.map +1 -0
  118. package/dist/state/persistence.js +201 -0
  119. package/dist/state/persistence.js.map +1 -0
  120. package/dist/types/cli.d.ts +132 -0
  121. package/dist/types/cli.d.ts.map +1 -0
  122. package/dist/types/cli.js +17 -0
  123. package/dist/types/cli.js.map +1 -0
  124. package/dist/types/consensus.d.ts +111 -0
  125. package/dist/types/consensus.d.ts.map +1 -0
  126. package/dist/types/consensus.js +29 -0
  127. package/dist/types/consensus.js.map +1 -0
  128. package/dist/types/index.d.ts +9 -0
  129. package/dist/types/index.d.ts.map +1 -0
  130. package/dist/types/index.js +13 -0
  131. package/dist/types/index.js.map +1 -0
  132. package/dist/types/project.d.ts +73 -0
  133. package/dist/types/project.d.ts.map +1 -0
  134. package/dist/types/project.js +55 -0
  135. package/dist/types/project.js.map +1 -0
  136. package/dist/types/workflow.d.ts +236 -0
  137. package/dist/types/workflow.d.ts.map +1 -0
  138. package/dist/types/workflow.js +74 -0
  139. package/dist/types/workflow.js.map +1 -0
  140. package/dist/workflow/consensus.d.ts +89 -0
  141. package/dist/workflow/consensus.d.ts.map +1 -0
  142. package/dist/workflow/consensus.js +220 -0
  143. package/dist/workflow/consensus.js.map +1 -0
  144. package/dist/workflow/execution-mode.d.ts +82 -0
  145. package/dist/workflow/execution-mode.d.ts.map +1 -0
  146. package/dist/workflow/execution-mode.js +346 -0
  147. package/dist/workflow/execution-mode.js.map +1 -0
  148. package/dist/workflow/index.d.ts +110 -0
  149. package/dist/workflow/index.d.ts.map +1 -0
  150. package/dist/workflow/index.js +283 -0
  151. package/dist/workflow/index.js.map +1 -0
  152. package/dist/workflow/plan-mode.d.ts +83 -0
  153. package/dist/workflow/plan-mode.d.ts.map +1 -0
  154. package/dist/workflow/plan-mode.js +241 -0
  155. package/dist/workflow/plan-mode.js.map +1 -0
  156. package/dist/workflow/test-runner.d.ts +87 -0
  157. package/dist/workflow/test-runner.d.ts.map +1 -0
  158. package/dist/workflow/test-runner.js +273 -0
  159. package/dist/workflow/test-runner.js.map +1 -0
  160. package/eslint.config.js +25 -0
  161. package/package.json +66 -0
  162. package/src/adapters/claude.ts +298 -0
  163. package/src/adapters/openai.ts +300 -0
  164. package/src/auth/claude.ts +166 -0
  165. package/src/auth/index.ts +171 -0
  166. package/src/auth/keychain.ts +138 -0
  167. package/src/auth/openai-entry.ts +410 -0
  168. package/src/auth/openai.ts +260 -0
  169. package/src/auth/server.ts +252 -0
  170. package/src/cli/commands/auth.ts +194 -0
  171. package/src/cli/commands/config.ts +241 -0
  172. package/src/cli/commands/create.ts +308 -0
  173. package/src/cli/commands/index.ts +10 -0
  174. package/src/cli/commands/resume.ts +304 -0
  175. package/src/cli/commands/status.ts +189 -0
  176. package/src/cli/index.ts +90 -0
  177. package/src/cli/interactive.ts +418 -0
  178. package/src/cli/output.ts +410 -0
  179. package/src/config/defaults.ts +114 -0
  180. package/src/config/index.ts +315 -0
  181. package/src/config/schema.ts +164 -0
  182. package/src/generators/index.ts +251 -0
  183. package/src/generators/python.ts +318 -0
  184. package/src/generators/templates/index.ts +6 -0
  185. package/src/generators/templates/python.ts +465 -0
  186. package/src/generators/templates/typescript.ts +417 -0
  187. package/src/generators/typescript.ts +340 -0
  188. package/src/index.ts +13 -0
  189. package/src/state/index.ts +454 -0
  190. package/src/state/persistence.ts +230 -0
  191. package/src/types/cli.ts +146 -0
  192. package/src/types/consensus.ts +116 -0
  193. package/src/types/index.ts +64 -0
  194. package/src/types/project.ts +85 -0
  195. package/src/types/workflow.ts +149 -0
  196. package/src/workflow/consensus.ts +299 -0
  197. package/src/workflow/execution-mode.ts +517 -0
  198. package/src/workflow/index.ts +396 -0
  199. package/src/workflow/plan-mode.ts +356 -0
  200. package/src/workflow/test-runner.ts +345 -0
  201. package/tests/adapters/openai.test.ts +145 -0
  202. package/tests/config/config.test.ts +208 -0
  203. package/tests/generators/generators.test.ts +185 -0
  204. package/tests/types/consensus.test.ts +152 -0
  205. package/tests/types/project.test.ts +134 -0
  206. package/tests/workflow/consensus.test.ts +221 -0
  207. package/tests/workflow/test-runner.test.ts +214 -0
  208. package/tsconfig.json +25 -0
  209. package/vitest.config.ts +22 -0
package/.env.example ADDED
@@ -0,0 +1,25 @@
1
+ # Popeye CLI Environment Variables
2
+ # Copy this file to .env and fill in your values
3
+
4
+ # OpenAI API Key (optional - can also use keychain)
5
+ # Get your key from: https://platform.openai.com/api-keys
6
+ POPEYE_OPENAI_KEY=
7
+
8
+ # Default output language for generated projects
9
+ # Options: python, typescript
10
+ POPEYE_DEFAULT_LANGUAGE=python
11
+
12
+ # Default OpenAI model for consensus reviews
13
+ # Options: gpt-4o, gpt-4o-mini, gpt-4-turbo, o1-preview, o1-mini
14
+ POPEYE_OPENAI_MODEL=gpt-4o
15
+
16
+ # Consensus threshold (percentage required for approval)
17
+ # Default: 95
18
+ POPEYE_CONSENSUS_THRESHOLD=95
19
+
20
+ # Maximum consensus iterations before escalating to user
21
+ # Default: 5
22
+ POPEYE_MAX_DISAGREEMENTS=5
23
+
24
+ # Log level (debug, info, warn, error)
25
+ POPEYE_LOG_LEVEL=info
package/.prettierrc ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "semi": true,
3
+ "trailingComma": "es5",
4
+ "singleQuote": true,
5
+ "printWidth": 100,
6
+ "tabWidth": 2,
7
+ "useTabs": false
8
+ }
package/README.md ADDED
@@ -0,0 +1,320 @@
1
+ # Popeye CLI
2
+
3
+ A fully autonomous TypeScript CLI tool that transforms your ideas into complete, tested, deployable code projects using AI-powered code generation and review.
4
+
5
+ ## Overview
6
+
7
+ Popeye orchestrates two AI systems to ensure high-quality code generation:
8
+
9
+ - **Claude (via Claude Agent SDK)**: Primary code execution engine that generates, implements, and tests code
10
+ - **OpenAI**: Review and validation partner that ensures plans meet quality standards through consensus
11
+
12
+ The workflow ensures 95%+ consensus between both AI systems before code execution begins, resulting in well-planned, thoroughly vetted implementations.
13
+
14
+ ## Features
15
+
16
+ - **Dual-AI Consensus System**: Plans are iteratively refined until both Claude and OpenAI agree on the approach
17
+ - **Multi-Language Support**: Generate projects in Python or TypeScript
18
+ - **Secure Authentication**: Browser-based OAuth for Claude, secure API key storage for OpenAI
19
+ - **Interactive Mode**: REPL-style interface with slash commands for ongoing work
20
+ - **One-Shot Creation**: `popeye create` command for quick project generation
21
+ - **Progress Tracking**: Visual feedback with spinners and progress bars
22
+ - **Automatic Testing**: Generated code includes tests that are run and verified
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ npm install -g popeye-cli
28
+ ```
29
+
30
+ Or use directly with npx:
31
+
32
+ ```bash
33
+ npx popeye-cli create "my project idea"
34
+ ```
35
+
36
+ ## Quick Start
37
+
38
+ ### 1. Authenticate
39
+
40
+ First, set up authentication with both AI services:
41
+
42
+ ```bash
43
+ # Authenticate with Claude (browser-based OAuth)
44
+ popeye auth claude
45
+
46
+ # Authenticate with OpenAI (API key)
47
+ popeye auth openai
48
+ ```
49
+
50
+ ### 2. Create a Project
51
+
52
+ Generate a complete project from an idea:
53
+
54
+ ```bash
55
+ # Create a Python project
56
+ popeye create "A REST API for managing todo items with SQLite storage" --language python
57
+
58
+ # Create a TypeScript project
59
+ popeye create "A React component library for data visualization" --language typescript
60
+ ```
61
+
62
+ ### 3. Interactive Mode
63
+
64
+ For ongoing work and experimentation:
65
+
66
+ ```bash
67
+ popeye
68
+ ```
69
+
70
+ In interactive mode, use slash commands:
71
+
72
+ ```
73
+ /help Show available commands
74
+ /create <idea> Start a new project
75
+ /status Check current project status
76
+ /auth Manage authentication
77
+ /config View/edit configuration
78
+ /exit Exit interactive mode
79
+ ```
80
+
81
+ ## Commands
82
+
83
+ ### `popeye create <idea>`
84
+
85
+ Create a new project from an idea.
86
+
87
+ **Options:**
88
+ - `-n, --name <name>`: Project name (default: derived from idea)
89
+ - `-l, --language <lang>`: Output language: `python` or `typescript` (default: python)
90
+ - `-d, --directory <dir>`: Output directory (default: current directory)
91
+ - `-m, --model <model>`: OpenAI model for consensus (default: gpt-4o)
92
+
93
+ **Example:**
94
+ ```bash
95
+ popeye create "A CLI tool for converting markdown to PDF" --name md2pdf --language python
96
+ ```
97
+
98
+ ### `popeye auth <service>`
99
+
100
+ Authenticate with Claude or OpenAI.
101
+
102
+ **Services:**
103
+ - `claude`: Opens browser for OAuth authentication
104
+ - `openai`: Prompts for API key entry via local web interface
105
+
106
+ **Options:**
107
+ - `--check`: Verify stored credentials without re-authenticating
108
+ - `--logout`: Remove stored credentials
109
+
110
+ ### `popeye status`
111
+
112
+ Check the status of the current project.
113
+
114
+ **Options:**
115
+ - `-p, --project <dir>`: Project directory to check
116
+
117
+ ### `popeye resume`
118
+
119
+ Resume an interrupted project from where it left off.
120
+
121
+ **Options:**
122
+ - `-p, --project <dir>`: Project directory to resume
123
+
124
+ ### `popeye config`
125
+
126
+ View or modify configuration.
127
+
128
+ **Subcommands:**
129
+ - `config show`: Display current configuration
130
+ - `config set <key> <value>`: Set a configuration value
131
+ - `config reset`: Reset to default configuration
132
+
133
+ ## Workflow
134
+
135
+ ### Plan Mode
136
+
137
+ 1. **Idea Expansion**: Your brief idea is expanded into a detailed specification by OpenAI
138
+ 2. **Plan Creation**: Claude creates a structured development plan with milestones and tasks
139
+ 3. **Consensus Loop**:
140
+ - OpenAI reviews the plan and provides feedback
141
+ - Claude revises based on concerns
142
+ - Repeats until 95%+ consensus is reached
143
+ 4. **Plan Documentation**: The approved plan is saved to `PLAN.md`
144
+
145
+ ### Execution Mode
146
+
147
+ 1. **Task Execution**: Claude implements each task sequentially
148
+ 2. **Test Creation**: Tests are generated alongside implementation
149
+ 3. **Test Verification**: Tests are run after each task
150
+ 4. **Error Recovery**: Failed tests trigger automatic fix attempts (up to 3 retries)
151
+ 5. **Completion**: Project marked complete when all tasks pass
152
+
153
+ ## Configuration
154
+
155
+ Popeye looks for configuration in the following order:
156
+
157
+ 1. Environment variables (highest priority)
158
+ 2. Project-level `popeye.config.yaml` or `.popeyerc.yaml`
159
+ 3. Global `~/.popeye/config.yaml`
160
+ 4. Built-in defaults (lowest priority)
161
+
162
+ ### Configuration File
163
+
164
+ ```yaml
165
+ # popeye.config.yaml
166
+ consensus:
167
+ threshold: 95
168
+ max_disagreements: 5
169
+ escalation_action: pause
170
+
171
+ apis:
172
+ openai:
173
+ model: gpt-4o
174
+ temperature: 0.3
175
+ max_tokens: 4096
176
+
177
+ project:
178
+ default_language: python
179
+
180
+ output:
181
+ verbose: false
182
+ timestamps: true
183
+ show_consensus_dialog: true
184
+ ```
185
+
186
+ ### Environment Variables
187
+
188
+ ```bash
189
+ POPEYE_OPENAI_KEY=sk-... # OpenAI API key
190
+ POPEYE_DEFAULT_LANGUAGE=python # Default output language
191
+ POPEYE_OPENAI_MODEL=gpt-4o # OpenAI model
192
+ POPEYE_CONSENSUS_THRESHOLD=95 # Consensus threshold (0-100)
193
+ POPEYE_MAX_DISAGREEMENTS=5 # Max iterations before escalation
194
+ POPEYE_LOG_LEVEL=debug # Enable verbose logging
195
+ ```
196
+
197
+ ## Generated Project Structure
198
+
199
+ ### Python Projects
200
+
201
+ ```
202
+ my-project/
203
+ ├── src/
204
+ │ ├── __init__.py
205
+ │ └── main.py
206
+ ├── tests/
207
+ │ ├── __init__.py
208
+ │ └── conftest.py
209
+ ├── pyproject.toml
210
+ ├── requirements.txt
211
+ ├── README.md
212
+ ├── .gitignore
213
+ ├── .env.example
214
+ ├── Dockerfile
215
+ └── .popeye/
216
+ └── state.json
217
+ ```
218
+
219
+ ### TypeScript Projects
220
+
221
+ ```
222
+ my-project/
223
+ ├── src/
224
+ │ └── index.ts
225
+ ├── tests/
226
+ │ └── index.test.ts
227
+ ├── package.json
228
+ ├── tsconfig.json
229
+ ├── README.md
230
+ ├── .gitignore
231
+ ├── .env.example
232
+ ├── Dockerfile
233
+ └── .popeye/
234
+ └── state.json
235
+ ```
236
+
237
+ ## State Management
238
+
239
+ Project state is persisted in `.popeye/state.json`, allowing you to:
240
+
241
+ - Resume interrupted projects
242
+ - Track progress across sessions
243
+ - Review consensus history
244
+ - Debug issues
245
+
246
+ ## Requirements
247
+
248
+ - Node.js 18.0 or higher
249
+ - npm or yarn
250
+ - Claude CLI access (for code generation)
251
+ - OpenAI API key (for consensus review)
252
+
253
+ ## Development
254
+
255
+ ```bash
256
+ # Clone the repository
257
+ git clone https://github.com/your-org/popeye-cli.git
258
+ cd popeye-cli
259
+
260
+ # Install dependencies
261
+ npm install
262
+
263
+ # Build
264
+ npm run build
265
+
266
+ # Run tests
267
+ npm test
268
+
269
+ # Run linting
270
+ npm run lint
271
+
272
+ # Run in development mode
273
+ npm run dev
274
+ ```
275
+
276
+ ## Architecture
277
+
278
+ ```
279
+ src/
280
+ ├── index.ts # Entry point
281
+ ├── cli/ # CLI interface
282
+ │ ├── index.ts # Command setup
283
+ │ ├── output.ts # Output formatting
284
+ │ ├── interactive.ts # REPL mode
285
+ │ └── commands/ # Individual commands
286
+ ├── adapters/ # AI service adapters
287
+ │ ├── claude.ts # Claude Agent SDK
288
+ │ └── openai.ts # OpenAI API
289
+ ├── auth/ # Authentication
290
+ │ ├── keychain.ts # Credential storage
291
+ │ └── server.ts # OAuth callback server
292
+ ├── config/ # Configuration
293
+ │ ├── schema.ts # Zod schemas
294
+ │ ├── defaults.ts # Default values
295
+ │ └── index.ts # Config loading
296
+ ├── generators/ # Project generators
297
+ │ ├── python.ts # Python scaffolding
298
+ │ ├── typescript.ts # TypeScript scaffolding
299
+ │ └── templates/ # File templates
300
+ ├── state/ # State management
301
+ │ ├── persistence.ts # File operations
302
+ │ └── index.ts # State API
303
+ ├── workflow/ # Workflow engine
304
+ │ ├── consensus.ts # Consensus loop
305
+ │ ├── plan-mode.ts # Planning phase
306
+ │ ├── execution-mode.ts # Execution phase
307
+ │ └── test-runner.ts # Test execution
308
+ └── types/ # TypeScript types
309
+ ├── project.ts # Project types
310
+ ├── workflow.ts # Workflow types
311
+ └── consensus.ts # Consensus types
312
+ ```
313
+
314
+ ## License
315
+
316
+ MIT
317
+
318
+ ## Contributing
319
+
320
+ Contributions are welcome! Please read our contributing guidelines before submitting PRs.
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Claude Agent SDK adapter
3
+ * Wraps the Claude Agent SDK for code execution and generation
4
+ */
5
+ import { type SDKMessage } from '@anthropic-ai/claude-agent-sdk';
6
+ /**
7
+ * Options for executing a prompt through Claude
8
+ */
9
+ export interface ClaudeExecuteOptions {
10
+ cwd?: string;
11
+ allowedTools?: string[];
12
+ permissionMode?: 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan';
13
+ systemPrompt?: string;
14
+ timeout?: number;
15
+ onMessage?: (message: SDKMessage) => void;
16
+ }
17
+ /**
18
+ * Result from Claude execution
19
+ */
20
+ export interface ClaudeExecuteResult {
21
+ success: boolean;
22
+ response: string;
23
+ toolCalls: ToolCallRecord[];
24
+ error?: string;
25
+ }
26
+ /**
27
+ * Record of a tool call made by Claude
28
+ */
29
+ export interface ToolCallRecord {
30
+ tool: string;
31
+ input: Record<string, unknown>;
32
+ output?: string;
33
+ }
34
+ /**
35
+ * Default allowed tools for autonomous operation
36
+ */
37
+ export declare const DEFAULT_ALLOWED_TOOLS: string[];
38
+ /**
39
+ * Execute a prompt through the Claude Agent SDK
40
+ *
41
+ * @param prompt - The prompt to execute
42
+ * @param options - Execution options
43
+ * @returns The execution result
44
+ */
45
+ export declare function executePrompt(prompt: string, options?: ClaudeExecuteOptions): Promise<ClaudeExecuteResult>;
46
+ /**
47
+ * Execute code generation for a specific task
48
+ *
49
+ * @param task - The task description
50
+ * @param context - Additional context about the project
51
+ * @param options - Execution options
52
+ */
53
+ export declare function generateCode(task: string, context: string, options?: ClaudeExecuteOptions): Promise<ClaudeExecuteResult>;
54
+ /**
55
+ * Run tests and capture results
56
+ *
57
+ * @param testCommand - The test command to run
58
+ * @param cwd - Working directory
59
+ */
60
+ export declare function runTests(testCommand: string, cwd?: string): Promise<ClaudeExecuteResult>;
61
+ /**
62
+ * Analyze codebase to understand structure and patterns
63
+ *
64
+ * @param cwd - Working directory of the project
65
+ */
66
+ export declare function analyzeCodebase(cwd: string): Promise<ClaudeExecuteResult>;
67
+ /**
68
+ * Create a development plan from a specification
69
+ *
70
+ * @param specification - The project specification
71
+ * @param context - Additional context (existing code, etc.)
72
+ */
73
+ export declare function createPlan(specification: string, context?: string): Promise<ClaudeExecuteResult>;
74
+ /**
75
+ * Revise a plan based on feedback
76
+ *
77
+ * @param originalPlan - The original plan
78
+ * @param feedback - Feedback to incorporate
79
+ * @param concerns - Specific concerns to address
80
+ */
81
+ export declare function revisePlan(originalPlan: string, feedback: string, concerns: string[]): Promise<ClaudeExecuteResult>;
82
+ //# sourceMappingURL=claude.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../src/adapters/claude.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAS,KAAK,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,cAAc,CAAC,EAAE,SAAS,GAAG,aAAa,GAAG,mBAAmB,GAAG,MAAM,CAAC;IAC1E,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,IAAI,CAAC;CAC3C;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,cAAc,EAAE,CAAC;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,UAWjC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,mBAAmB,CAAC,CAiE9B;AAED;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,mBAAmB,CAAC,CAyB9B;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC5B,WAAW,EAAE,MAAM,EACnB,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,mBAAmB,CAAC,CAoB9B;AAED;;;;GAIG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAmB/E;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,MAAW,GACnB,OAAO,CAAC,mBAAmB,CAAC,CAyB9B;AAED;;;;;;GAMG;AACH,wBAAsB,UAAU,CAC9B,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAAE,GACjB,OAAO,CAAC,mBAAmB,CAAC,CAwB9B"}
@@ -0,0 +1,230 @@
1
+ /**
2
+ * Claude Agent SDK adapter
3
+ * Wraps the Claude Agent SDK for code execution and generation
4
+ */
5
+ import { query } from '@anthropic-ai/claude-agent-sdk';
6
+ /**
7
+ * Default allowed tools for autonomous operation
8
+ */
9
+ export const DEFAULT_ALLOWED_TOOLS = [
10
+ 'Read',
11
+ 'Write',
12
+ 'Edit',
13
+ 'MultiEdit',
14
+ 'Bash',
15
+ 'Grep',
16
+ 'Glob',
17
+ 'LS',
18
+ 'TodoRead',
19
+ 'TodoWrite',
20
+ ];
21
+ /**
22
+ * Execute a prompt through the Claude Agent SDK
23
+ *
24
+ * @param prompt - The prompt to execute
25
+ * @param options - Execution options
26
+ * @returns The execution result
27
+ */
28
+ export async function executePrompt(prompt, options = {}) {
29
+ const { cwd, allowedTools = DEFAULT_ALLOWED_TOOLS, permissionMode = 'bypassPermissions', systemPrompt, onMessage, } = options;
30
+ const toolCalls = [];
31
+ let response = '';
32
+ let error;
33
+ try {
34
+ const result = query({
35
+ prompt,
36
+ options: {
37
+ cwd,
38
+ allowedTools,
39
+ permissionMode,
40
+ systemPrompt: systemPrompt || { type: 'preset', preset: 'claude_code' },
41
+ },
42
+ });
43
+ for await (const message of result) {
44
+ // Call the message handler if provided
45
+ if (onMessage) {
46
+ onMessage(message);
47
+ }
48
+ // Process different message types
49
+ if (message.type === 'assistant') {
50
+ const assistantMessage = message;
51
+ if (typeof assistantMessage.message.content === 'string') {
52
+ response += assistantMessage.message.content;
53
+ }
54
+ else if (Array.isArray(assistantMessage.message.content)) {
55
+ for (const block of assistantMessage.message.content) {
56
+ if (block.type === 'text' && block.text) {
57
+ response += block.text;
58
+ }
59
+ }
60
+ }
61
+ }
62
+ else if (message.type === 'result') {
63
+ // Handle result messages which may contain tool information
64
+ const resultMessage = message;
65
+ if (resultMessage.error) {
66
+ error = resultMessage.error.message;
67
+ }
68
+ }
69
+ }
70
+ return {
71
+ success: !error,
72
+ response: response.trim(),
73
+ toolCalls,
74
+ error,
75
+ };
76
+ }
77
+ catch (err) {
78
+ return {
79
+ success: false,
80
+ response: '',
81
+ toolCalls,
82
+ error: err instanceof Error ? err.message : 'Unknown error executing prompt',
83
+ };
84
+ }
85
+ }
86
+ /**
87
+ * Execute code generation for a specific task
88
+ *
89
+ * @param task - The task description
90
+ * @param context - Additional context about the project
91
+ * @param options - Execution options
92
+ */
93
+ export async function generateCode(task, context, options = {}) {
94
+ const prompt = `
95
+ ## Task
96
+ ${task}
97
+
98
+ ## Project Context
99
+ ${context}
100
+
101
+ ## Instructions
102
+ 1. Implement the task following best practices
103
+ 2. Write clean, well-documented code
104
+ 3. Include appropriate error handling
105
+ 4. Follow the project's existing patterns and style
106
+
107
+ Please implement this task now.
108
+ `.trim();
109
+ return executePrompt(prompt, {
110
+ ...options,
111
+ allowedTools: options.allowedTools || [
112
+ ...DEFAULT_ALLOWED_TOOLS,
113
+ 'WebSearch',
114
+ 'WebFetch',
115
+ ],
116
+ });
117
+ }
118
+ /**
119
+ * Run tests and capture results
120
+ *
121
+ * @param testCommand - The test command to run
122
+ * @param cwd - Working directory
123
+ */
124
+ export async function runTests(testCommand, cwd) {
125
+ const prompt = `
126
+ Run the following test command and report the results:
127
+
128
+ \`\`\`bash
129
+ ${testCommand}
130
+ \`\`\`
131
+
132
+ After running the tests:
133
+ 1. Report the total number of tests
134
+ 2. Report how many passed and failed
135
+ 3. If there are failures, summarize what failed
136
+ 4. Provide any relevant error messages
137
+ `.trim();
138
+ return executePrompt(prompt, {
139
+ cwd,
140
+ allowedTools: ['Bash', 'Read'],
141
+ permissionMode: 'bypassPermissions',
142
+ });
143
+ }
144
+ /**
145
+ * Analyze codebase to understand structure and patterns
146
+ *
147
+ * @param cwd - Working directory of the project
148
+ */
149
+ export async function analyzeCodebase(cwd) {
150
+ const prompt = `
151
+ Analyze this codebase and provide:
152
+
153
+ 1. **Project Structure**: Overview of directories and their purposes
154
+ 2. **Key Technologies**: Languages, frameworks, and major dependencies
155
+ 3. **Architecture Patterns**: Design patterns and architectural decisions observed
156
+ 4. **Code Style**: Naming conventions, formatting, and documentation style
157
+ 5. **Test Setup**: Testing framework and test organization
158
+ 6. **Build/Deploy**: Build tools and deployment configuration
159
+
160
+ Be concise but thorough in your analysis.
161
+ `.trim();
162
+ return executePrompt(prompt, {
163
+ cwd,
164
+ allowedTools: ['Read', 'Glob', 'Grep', 'LS'],
165
+ permissionMode: 'default', // Read-only analysis
166
+ });
167
+ }
168
+ /**
169
+ * Create a development plan from a specification
170
+ *
171
+ * @param specification - The project specification
172
+ * @param context - Additional context (existing code, etc.)
173
+ */
174
+ export async function createPlan(specification, context = '') {
175
+ const prompt = `
176
+ Create a detailed development plan for the following specification:
177
+
178
+ ## Specification
179
+ ${specification}
180
+
181
+ ${context ? `## Additional Context\n${context}` : ''}
182
+
183
+ ## Required Plan Sections
184
+
185
+ 1. **Background & Context**: Summarize the project requirements
186
+ 2. **Goals & Objectives**: List measurable objectives
187
+ 3. **Milestones**: Break down into major phases
188
+ 4. **Tasks**: Detail specific tasks for each milestone
189
+ 5. **Test Plan**: Define tests for each task
190
+ 6. **Risks & Mitigations**: Identify potential issues
191
+
192
+ Format the plan as markdown with clear sections and bullet points.
193
+ `.trim();
194
+ return executePrompt(prompt, {
195
+ allowedTools: ['Read', 'Glob'],
196
+ permissionMode: 'plan',
197
+ });
198
+ }
199
+ /**
200
+ * Revise a plan based on feedback
201
+ *
202
+ * @param originalPlan - The original plan
203
+ * @param feedback - Feedback to incorporate
204
+ * @param concerns - Specific concerns to address
205
+ */
206
+ export async function revisePlan(originalPlan, feedback, concerns) {
207
+ const prompt = `
208
+ Revise the following plan based on the feedback provided:
209
+
210
+ ## Original Plan
211
+ ${originalPlan}
212
+
213
+ ## Feedback
214
+ ${feedback}
215
+
216
+ ## Specific Concerns to Address
217
+ ${concerns.map((c, i) => `${i + 1}. ${c}`).join('\n')}
218
+
219
+ ## Instructions
220
+ 1. Address each concern specifically
221
+ 2. Maintain the same plan structure
222
+ 3. Note what changed from the original
223
+ 4. Ensure the revised plan is complete and actionable
224
+ `.trim();
225
+ return executePrompt(prompt, {
226
+ allowedTools: [],
227
+ permissionMode: 'plan',
228
+ });
229
+ }
230
+ //# sourceMappingURL=claude.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claude.js","sourceRoot":"","sources":["../../src/adapters/claude.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,EAAmB,MAAM,gCAAgC,CAAC;AAiCxE;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,MAAM;IACN,OAAO;IACP,MAAM;IACN,WAAW;IACX,MAAM;IACN,MAAM;IACN,MAAM;IACN,IAAI;IACJ,UAAU;IACV,WAAW;CACZ,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAc,EACd,UAAgC,EAAE;IAElC,MAAM,EACJ,GAAG,EACH,YAAY,GAAG,qBAAqB,EACpC,cAAc,GAAG,mBAAmB,EACpC,YAAY,EACZ,SAAS,GACV,GAAG,OAAO,CA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