popeye-cli 1.0.1 → 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 (166) hide show
  1. package/README.md +521 -125
  2. package/dist/adapters/claude.d.ts +16 -4
  3. package/dist/adapters/claude.d.ts.map +1 -1
  4. package/dist/adapters/claude.js +679 -33
  5. package/dist/adapters/claude.js.map +1 -1
  6. package/dist/adapters/gemini.d.ts +55 -0
  7. package/dist/adapters/gemini.d.ts.map +1 -0
  8. package/dist/adapters/gemini.js +318 -0
  9. package/dist/adapters/gemini.js.map +1 -0
  10. package/dist/adapters/openai.d.ts.map +1 -1
  11. package/dist/adapters/openai.js +41 -7
  12. package/dist/adapters/openai.js.map +1 -1
  13. package/dist/auth/claude.d.ts +11 -9
  14. package/dist/auth/claude.d.ts.map +1 -1
  15. package/dist/auth/claude.js +107 -71
  16. package/dist/auth/claude.js.map +1 -1
  17. package/dist/auth/gemini.d.ts +58 -0
  18. package/dist/auth/gemini.d.ts.map +1 -0
  19. package/dist/auth/gemini.js +172 -0
  20. package/dist/auth/gemini.js.map +1 -0
  21. package/dist/auth/index.d.ts +11 -7
  22. package/dist/auth/index.d.ts.map +1 -1
  23. package/dist/auth/index.js +23 -5
  24. package/dist/auth/index.js.map +1 -1
  25. package/dist/auth/keychain.d.ts +20 -7
  26. package/dist/auth/keychain.d.ts.map +1 -1
  27. package/dist/auth/keychain.js +85 -29
  28. package/dist/auth/keychain.js.map +1 -1
  29. package/dist/auth/openai.d.ts +2 -2
  30. package/dist/auth/openai.d.ts.map +1 -1
  31. package/dist/auth/openai.js +30 -32
  32. package/dist/auth/openai.js.map +1 -1
  33. package/dist/cli/interactive.d.ts.map +1 -1
  34. package/dist/cli/interactive.js +1151 -110
  35. package/dist/cli/interactive.js.map +1 -1
  36. package/dist/config/defaults.d.ts +6 -1
  37. package/dist/config/defaults.d.ts.map +1 -1
  38. package/dist/config/defaults.js +10 -2
  39. package/dist/config/defaults.js.map +1 -1
  40. package/dist/config/index.d.ts +10 -0
  41. package/dist/config/index.d.ts.map +1 -1
  42. package/dist/config/index.js +19 -0
  43. package/dist/config/index.js.map +1 -1
  44. package/dist/config/schema.d.ts +20 -0
  45. package/dist/config/schema.d.ts.map +1 -1
  46. package/dist/config/schema.js +7 -0
  47. package/dist/config/schema.js.map +1 -1
  48. package/dist/generators/python.d.ts.map +1 -1
  49. package/dist/generators/python.js +1 -0
  50. package/dist/generators/python.js.map +1 -1
  51. package/dist/generators/typescript.d.ts.map +1 -1
  52. package/dist/generators/typescript.js +1 -0
  53. package/dist/generators/typescript.js.map +1 -1
  54. package/dist/state/index.d.ts +108 -0
  55. package/dist/state/index.d.ts.map +1 -1
  56. package/dist/state/index.js +551 -4
  57. package/dist/state/index.js.map +1 -1
  58. package/dist/state/registry.d.ts +52 -0
  59. package/dist/state/registry.d.ts.map +1 -0
  60. package/dist/state/registry.js +215 -0
  61. package/dist/state/registry.js.map +1 -0
  62. package/dist/types/cli.d.ts +4 -0
  63. package/dist/types/cli.d.ts.map +1 -1
  64. package/dist/types/cli.js.map +1 -1
  65. package/dist/types/consensus.d.ts +69 -4
  66. package/dist/types/consensus.d.ts.map +1 -1
  67. package/dist/types/consensus.js +24 -3
  68. package/dist/types/consensus.js.map +1 -1
  69. package/dist/types/workflow.d.ts +55 -0
  70. package/dist/types/workflow.d.ts.map +1 -1
  71. package/dist/types/workflow.js +16 -0
  72. package/dist/types/workflow.js.map +1 -1
  73. package/dist/workflow/auto-fix.d.ts +45 -0
  74. package/dist/workflow/auto-fix.d.ts.map +1 -0
  75. package/dist/workflow/auto-fix.js +274 -0
  76. package/dist/workflow/auto-fix.js.map +1 -0
  77. package/dist/workflow/consensus.d.ts +44 -2
  78. package/dist/workflow/consensus.d.ts.map +1 -1
  79. package/dist/workflow/consensus.js +565 -17
  80. package/dist/workflow/consensus.js.map +1 -1
  81. package/dist/workflow/execution-mode.d.ts +10 -4
  82. package/dist/workflow/execution-mode.d.ts.map +1 -1
  83. package/dist/workflow/execution-mode.js +547 -58
  84. package/dist/workflow/execution-mode.js.map +1 -1
  85. package/dist/workflow/index.d.ts +14 -2
  86. package/dist/workflow/index.d.ts.map +1 -1
  87. package/dist/workflow/index.js +69 -6
  88. package/dist/workflow/index.js.map +1 -1
  89. package/dist/workflow/milestone-workflow.d.ts +34 -0
  90. package/dist/workflow/milestone-workflow.d.ts.map +1 -0
  91. package/dist/workflow/milestone-workflow.js +414 -0
  92. package/dist/workflow/milestone-workflow.js.map +1 -0
  93. package/dist/workflow/plan-mode.d.ts +14 -1
  94. package/dist/workflow/plan-mode.d.ts.map +1 -1
  95. package/dist/workflow/plan-mode.js +589 -47
  96. package/dist/workflow/plan-mode.js.map +1 -1
  97. package/dist/workflow/plan-storage.d.ts +142 -0
  98. package/dist/workflow/plan-storage.d.ts.map +1 -0
  99. package/dist/workflow/plan-storage.js +331 -0
  100. package/dist/workflow/plan-storage.js.map +1 -0
  101. package/dist/workflow/project-verification.d.ts +37 -0
  102. package/dist/workflow/project-verification.d.ts.map +1 -0
  103. package/dist/workflow/project-verification.js +381 -0
  104. package/dist/workflow/project-verification.js.map +1 -0
  105. package/dist/workflow/task-workflow.d.ts +37 -0
  106. package/dist/workflow/task-workflow.d.ts.map +1 -0
  107. package/dist/workflow/task-workflow.js +383 -0
  108. package/dist/workflow/task-workflow.js.map +1 -0
  109. package/dist/workflow/test-runner.d.ts +1 -0
  110. package/dist/workflow/test-runner.d.ts.map +1 -1
  111. package/dist/workflow/test-runner.js +9 -5
  112. package/dist/workflow/test-runner.js.map +1 -1
  113. package/dist/workflow/ui-designer.d.ts +82 -0
  114. package/dist/workflow/ui-designer.d.ts.map +1 -0
  115. package/dist/workflow/ui-designer.js +234 -0
  116. package/dist/workflow/ui-designer.js.map +1 -0
  117. package/dist/workflow/ui-setup.d.ts +58 -0
  118. package/dist/workflow/ui-setup.d.ts.map +1 -0
  119. package/dist/workflow/ui-setup.js +685 -0
  120. package/dist/workflow/ui-setup.js.map +1 -0
  121. package/dist/workflow/ui-verification.d.ts +114 -0
  122. package/dist/workflow/ui-verification.d.ts.map +1 -0
  123. package/dist/workflow/ui-verification.js +258 -0
  124. package/dist/workflow/ui-verification.js.map +1 -0
  125. package/dist/workflow/workflow-logger.d.ts +110 -0
  126. package/dist/workflow/workflow-logger.d.ts.map +1 -0
  127. package/dist/workflow/workflow-logger.js +267 -0
  128. package/dist/workflow/workflow-logger.js.map +1 -0
  129. package/package.json +2 -2
  130. package/src/adapters/claude.ts +815 -34
  131. package/src/adapters/gemini.ts +373 -0
  132. package/src/adapters/openai.ts +40 -7
  133. package/src/auth/claude.ts +120 -78
  134. package/src/auth/gemini.ts +207 -0
  135. package/src/auth/index.ts +28 -8
  136. package/src/auth/keychain.ts +95 -28
  137. package/src/auth/openai.ts +29 -36
  138. package/src/cli/interactive.ts +1357 -115
  139. package/src/config/defaults.ts +10 -2
  140. package/src/config/index.ts +21 -0
  141. package/src/config/schema.ts +7 -0
  142. package/src/generators/python.ts +1 -0
  143. package/src/generators/typescript.ts +1 -0
  144. package/src/state/index.ts +713 -4
  145. package/src/state/registry.ts +278 -0
  146. package/src/types/cli.ts +4 -0
  147. package/src/types/consensus.ts +65 -6
  148. package/src/types/workflow.ts +35 -0
  149. package/src/workflow/auto-fix.ts +340 -0
  150. package/src/workflow/consensus.ts +750 -16
  151. package/src/workflow/execution-mode.ts +673 -74
  152. package/src/workflow/index.ts +95 -6
  153. package/src/workflow/milestone-workflow.ts +576 -0
  154. package/src/workflow/plan-mode.ts +696 -50
  155. package/src/workflow/plan-storage.ts +482 -0
  156. package/src/workflow/project-verification.ts +471 -0
  157. package/src/workflow/task-workflow.ts +525 -0
  158. package/src/workflow/test-runner.ts +10 -5
  159. package/src/workflow/ui-designer.ts +337 -0
  160. package/src/workflow/ui-setup.ts +797 -0
  161. package/src/workflow/ui-verification.ts +357 -0
  162. package/src/workflow/workflow-logger.ts +353 -0
  163. package/tests/config/config.test.ts +1 -1
  164. package/tests/types/consensus.test.ts +3 -3
  165. package/tests/workflow/plan-mode.test.ts +213 -0
  166. package/tests/workflow/test-runner.test.ts +5 -3
@@ -0,0 +1,340 @@
1
+ /**
2
+ * Auto-fix module for automatically fixing build and TypeScript errors
3
+ * Uses Claude to analyze errors and apply fixes
4
+ */
5
+
6
+ import { promises as fs } from 'node:fs';
7
+ import path from 'node:path';
8
+ import { executePrompt } from '../adapters/claude.js';
9
+
10
+ /**
11
+ * Build error details
12
+ */
13
+ export interface BuildError {
14
+ file: string;
15
+ line?: number;
16
+ column?: number;
17
+ message: string;
18
+ code?: string;
19
+ }
20
+
21
+ /**
22
+ * Auto-fix result
23
+ */
24
+ export interface AutoFixResult {
25
+ success: boolean;
26
+ fixedErrors: number;
27
+ remainingErrors: number;
28
+ attempts: number;
29
+ fixes: Array<{
30
+ file: string;
31
+ description: string;
32
+ }>;
33
+ error?: string;
34
+ }
35
+
36
+ /**
37
+ * Parse TypeScript compiler errors from output
38
+ */
39
+ export function parseTypeScriptErrors(output: string): BuildError[] {
40
+ const errors: BuildError[] = [];
41
+ const errorPattern = /^(.+?)\((\d+),(\d+)\): error (TS\d+): (.+)$/gm;
42
+
43
+ let match;
44
+ while ((match = errorPattern.exec(output)) !== null) {
45
+ errors.push({
46
+ file: match[1],
47
+ line: parseInt(match[2], 10),
48
+ column: parseInt(match[3], 10),
49
+ code: match[4],
50
+ message: match[5],
51
+ });
52
+ }
53
+
54
+ return errors;
55
+ }
56
+
57
+ /**
58
+ * Group errors by file for efficient fixing
59
+ */
60
+ function groupErrorsByFile(errors: BuildError[]): Map<string, BuildError[]> {
61
+ const grouped = new Map<string, BuildError[]>();
62
+
63
+ for (const error of errors) {
64
+ const existing = grouped.get(error.file) || [];
65
+ existing.push(error);
66
+ grouped.set(error.file, existing);
67
+ }
68
+
69
+ return grouped;
70
+ }
71
+
72
+ /**
73
+ * Generate fix prompt for a file with errors
74
+ */
75
+ function generateFixPrompt(filePath: string, fileContent: string, errors: BuildError[]): string {
76
+ const errorList = errors
77
+ .map(e => `- Line ${e.line}: ${e.code} - ${e.message}`)
78
+ .join('\n');
79
+
80
+ return `
81
+ Fix the following TypeScript errors in this file. Return ONLY the complete fixed file content, no explanations.
82
+
83
+ ## File: ${filePath}
84
+
85
+ ## Errors to fix:
86
+ ${errorList}
87
+
88
+ ## Current file content:
89
+ \`\`\`typescript
90
+ ${fileContent}
91
+ \`\`\`
92
+
93
+ ## Instructions:
94
+ 1. Fix ALL the errors listed above
95
+ 2. Do not change any working code
96
+ 3. Preserve all imports, exports, and functionality
97
+ 4. For type-only exports (interfaces, types), use \`export type { ... }\` syntax
98
+ 5. For unused variables, either use them or prefix with underscore
99
+ 6. For missing properties, add them with appropriate default values
100
+ 7. Return ONLY the fixed TypeScript code, no markdown formatting
101
+
102
+ Fixed code:
103
+ `.trim();
104
+ }
105
+
106
+ /**
107
+ * Extract code from Claude's response
108
+ */
109
+ function extractCodeFromResponse(response: string): string {
110
+ // Try to extract from code block first
111
+ const codeBlockMatch = response.match(/```(?:typescript|ts)?\n([\s\S]*?)\n```/);
112
+ if (codeBlockMatch) {
113
+ return codeBlockMatch[1].trim();
114
+ }
115
+
116
+ // If no code block, assume the entire response is code
117
+ // But strip any leading/trailing explanation text
118
+ const lines = response.split('\n');
119
+
120
+ // Find first line that looks like code (import, export, const, etc.)
121
+ const codeStartPatterns = [
122
+ /^import\s/,
123
+ /^export\s/,
124
+ /^const\s/,
125
+ /^let\s/,
126
+ /^var\s/,
127
+ /^function\s/,
128
+ /^class\s/,
129
+ /^interface\s/,
130
+ /^type\s/,
131
+ /^\/\//,
132
+ /^\/\*/,
133
+ /^['"`]/,
134
+ ];
135
+
136
+ let startIndex = 0;
137
+ for (let i = 0; i < lines.length; i++) {
138
+ const line = lines[i].trim();
139
+ if (codeStartPatterns.some(p => p.test(line))) {
140
+ startIndex = i;
141
+ break;
142
+ }
143
+ }
144
+
145
+ return lines.slice(startIndex).join('\n').trim();
146
+ }
147
+
148
+ /**
149
+ * Auto-fix TypeScript errors in a project
150
+ */
151
+ export async function autoFixTypeScriptErrors(
152
+ projectDir: string,
153
+ buildOutput: string,
154
+ maxAttempts: number = 3,
155
+ onProgress?: (message: string) => void
156
+ ): Promise<AutoFixResult> {
157
+ const fixes: Array<{ file: string; description: string }> = [];
158
+ let attempts = 0;
159
+ let currentOutput = buildOutput;
160
+
161
+ while (attempts < maxAttempts) {
162
+ attempts++;
163
+ onProgress?.(`Auto-fix attempt ${attempts}/${maxAttempts}...`);
164
+
165
+ const errors = parseTypeScriptErrors(currentOutput);
166
+
167
+ if (errors.length === 0) {
168
+ onProgress?.('No TypeScript errors found');
169
+ return {
170
+ success: true,
171
+ fixedErrors: fixes.length,
172
+ remainingErrors: 0,
173
+ attempts,
174
+ fixes,
175
+ };
176
+ }
177
+
178
+ onProgress?.(`Found ${errors.length} TypeScript error(s) to fix`);
179
+
180
+ // Group errors by file
181
+ const errorsByFile = groupErrorsByFile(errors);
182
+ let fixedInThisAttempt = 0;
183
+
184
+ // Fix each file
185
+ for (const [filePath, fileErrors] of errorsByFile) {
186
+ const absolutePath = path.isAbsolute(filePath) ? filePath : path.join(projectDir, filePath);
187
+
188
+ try {
189
+ // Read current file content
190
+ const fileContent = await fs.readFile(absolutePath, 'utf-8');
191
+
192
+ onProgress?.(`Fixing ${fileErrors.length} error(s) in ${path.basename(filePath)}...`);
193
+
194
+ // Generate fix prompt
195
+ const prompt = generateFixPrompt(filePath, fileContent, fileErrors);
196
+
197
+ // Ask Claude to fix
198
+ const result = await executePrompt(prompt, {
199
+ allowedTools: [],
200
+ permissionMode: 'default',
201
+ });
202
+
203
+ if (result.success && result.response) {
204
+ const fixedCode = extractCodeFromResponse(result.response);
205
+
206
+ // Validate the fix is not empty and looks like code
207
+ if (fixedCode.length > 100 && (fixedCode.includes('import') || fixedCode.includes('export'))) {
208
+ // Write fixed content
209
+ await fs.writeFile(absolutePath, fixedCode, 'utf-8');
210
+
211
+ fixes.push({
212
+ file: filePath,
213
+ description: `Fixed ${fileErrors.length} error(s): ${fileErrors.map(e => e.code).join(', ')}`,
214
+ });
215
+
216
+ fixedInThisAttempt += fileErrors.length;
217
+ onProgress?.(`Fixed ${path.basename(filePath)}`);
218
+ } else {
219
+ onProgress?.(`Skipped ${path.basename(filePath)} - fix doesn't look valid`);
220
+ }
221
+ } else {
222
+ onProgress?.(`Failed to get fix for ${path.basename(filePath)}: ${result.error}`);
223
+ }
224
+ } catch (err) {
225
+ onProgress?.(`Error fixing ${filePath}: ${err instanceof Error ? err.message : 'Unknown error'}`);
226
+ }
227
+ }
228
+
229
+ if (fixedInThisAttempt === 0) {
230
+ onProgress?.('No fixes were applied in this attempt');
231
+ break;
232
+ }
233
+
234
+ // Re-run TypeScript check to get remaining errors
235
+ onProgress?.('Re-checking for remaining errors...');
236
+ const { exec } = await import('node:child_process');
237
+ const { promisify } = await import('node:util');
238
+ const execAsync = promisify(exec);
239
+
240
+ try {
241
+ await execAsync('npx tsc --noEmit', { cwd: projectDir });
242
+ currentOutput = '';
243
+ } catch (err: unknown) {
244
+ if (err && typeof err === 'object' && 'stdout' in err) {
245
+ currentOutput = (err as { stdout: string; stderr: string }).stdout + (err as { stdout: string; stderr: string }).stderr;
246
+ } else {
247
+ currentOutput = '';
248
+ }
249
+ }
250
+ }
251
+
252
+ // Final error count
253
+ const remainingErrors = parseTypeScriptErrors(currentOutput);
254
+
255
+ return {
256
+ success: remainingErrors.length === 0,
257
+ fixedErrors: fixes.length,
258
+ remainingErrors: remainingErrors.length,
259
+ attempts,
260
+ fixes,
261
+ error: remainingErrors.length > 0
262
+ ? `${remainingErrors.length} error(s) remain after ${attempts} fix attempt(s)`
263
+ : undefined,
264
+ };
265
+ }
266
+
267
+ /**
268
+ * Run build with auto-fix
269
+ */
270
+ export async function buildWithAutoFix(
271
+ projectDir: string,
272
+ language: string,
273
+ maxAttempts: number = 3,
274
+ onProgress?: (message: string) => void
275
+ ): Promise<{ success: boolean; output: string; autoFixed: boolean }> {
276
+ const { exec } = await import('node:child_process');
277
+ const { promisify } = await import('node:util');
278
+ const execAsync = promisify(exec);
279
+
280
+ // Determine build command based on language
281
+ let buildCommand: string;
282
+ if (language === 'typescript' || language === 'javascript') {
283
+ // Check for package.json build script
284
+ try {
285
+ const pkgJson = JSON.parse(await fs.readFile(path.join(projectDir, 'package.json'), 'utf-8'));
286
+ if (pkgJson.scripts?.build) {
287
+ buildCommand = 'npm run build';
288
+ } else {
289
+ buildCommand = 'npx tsc --noEmit';
290
+ }
291
+ } catch {
292
+ buildCommand = 'npx tsc --noEmit';
293
+ }
294
+ } else if (language === 'python') {
295
+ buildCommand = 'python -m py_compile $(find . -name "*.py" -not -path "./venv/*")';
296
+ } else {
297
+ buildCommand = 'npm run build';
298
+ }
299
+
300
+ // Initial build attempt
301
+ onProgress?.(`Running build: ${buildCommand}`);
302
+
303
+ try {
304
+ const { stdout, stderr } = await execAsync(buildCommand, {
305
+ cwd: projectDir,
306
+ timeout: 120000,
307
+ });
308
+ return { success: true, output: stdout + stderr, autoFixed: false };
309
+ } catch (err: unknown) {
310
+ const output = err && typeof err === 'object' && 'stdout' in err
311
+ ? (err as { stdout: string; stderr: string }).stdout + (err as { stdout: string; stderr: string }).stderr
312
+ : String(err);
313
+
314
+ onProgress?.('Build failed, attempting auto-fix...');
315
+
316
+ // Try auto-fix for TypeScript errors
317
+ if (language === 'typescript' || language === 'javascript') {
318
+ const fixResult = await autoFixTypeScriptErrors(projectDir, output, maxAttempts, onProgress);
319
+
320
+ if (fixResult.success) {
321
+ // Retry build after fixes
322
+ onProgress?.('Auto-fix successful, retrying build...');
323
+ try {
324
+ const { stdout: retryStdout, stderr: retryStderr } = await execAsync(buildCommand, {
325
+ cwd: projectDir,
326
+ timeout: 120000,
327
+ });
328
+ return { success: true, output: retryStdout + retryStderr, autoFixed: true };
329
+ } catch (retryErr: unknown) {
330
+ const retryOutput = retryErr && typeof retryErr === 'object' && 'stdout' in retryErr
331
+ ? (retryErr as { stdout: string; stderr: string }).stdout + (retryErr as { stdout: string; stderr: string }).stderr
332
+ : String(retryErr);
333
+ return { success: false, output: retryOutput, autoFixed: true };
334
+ }
335
+ }
336
+ }
337
+
338
+ return { success: false, output, autoFixed: false };
339
+ }
340
+ }