Changesets · Branches · Tags · Compare
| Changeset | e1e7a7d5fb5561e71a38e76102a0d392f18c4eb77125cb9e63e4c62ba013086a |
|---|---|
| Author | Nate <sestinj@gmail.com> · 2025-08-23 11:28 -07:00 |
| Committer | Nate <sestinj@gmail.com> · 2025-08-23 11:28 -07:00 |
| Parents | 58306607ad94 |
7 files changed
modified extensions/cli/src/args.prompt.test.ts +33 −5
| @@ -22,13 +22,28 @@ | ||
| 22 | 22 | }); |
| 23 | 23 | |
| 24 | 24 | it("should parse multiple prompts from multiple --prompt flags", () => { |
| 25 | - process.argv = ["node", "script.js", "--prompt", "prompt1", "--prompt", "prompt2"]; | |
| 25 | + process.argv = [ | |
| 26 | + "node", | |
| 27 | + "script.js", | |
| 28 | + "--prompt", | |
| 29 | + "prompt1", | |
| 30 | + "--prompt", | |
| 31 | + "prompt2", | |
| 32 | + ]; | |
| 26 | 33 | const result = parseArgs(); |
| 27 | 34 | expect(result.prompts).toEqual(["prompt1", "prompt2"]); |
| 28 | 35 | }); |
| 29 | 36 | |
| 30 | 37 | it("should handle mixed flags including --prompt", () => { |
| 31 | - process.argv = ["node", "script.js", "--config", "myconfig", "--prompt", "myprompt", "--resume"]; | |
| 38 | + process.argv = [ | |
| 39 | + "node", | |
| 40 | + "script.js", | |
| 41 | + "--config", | |
| 42 | + "myconfig", | |
| 43 | + "--prompt", | |
| 44 | + "myprompt", | |
| 45 | + "--resume", | |
| 46 | + ]; | |
| 32 | 47 | const result = parseArgs(); |
| 33 | 48 | expect(result.configPath).toBe("myconfig"); |
| 34 | 49 | expect(result.prompts).toEqual(["myprompt"]); |
| @@ -36,14 +51,27 @@ | ||
| 36 | 51 | }); |
| 37 | 52 | |
| 38 | 53 | it("should not include --prompt value in non-flag arguments", () => { |
| 39 | - process.argv = ["node", "script.js", "--prompt", "prompt-value", "actual-prompt"]; | |
| 54 | + process.argv = [ | |
| 55 | + "node", | |
| 56 | + "script.js", | |
| 57 | + "--prompt", | |
| 58 | + "prompt-value", | |
| 59 | + "actual-prompt", | |
| 60 | + ]; | |
| 40 | 61 | const result = parseArgs(); |
| 41 | 62 | expect(result.prompts).toEqual(["prompt-value"]); |
| 42 | 63 | expect(result.prompt).toBe("actual-prompt"); |
| 43 | 64 | }); |
| 44 | 65 | |
| 45 | 66 | it("should handle both --rule and --prompt flags", () => { |
| 46 | - process.argv = ["node", "script.js", "--rule", "my-rule", "--prompt", "my-prompt"]; | |
| 67 | + process.argv = [ | |
| 68 | + "node", | |
| 69 | + "script.js", | |
| 70 | + "--rule", | |
| 71 | + "my-rule", | |
| 72 | + "--prompt", | |
| 73 | + "my-prompt", | |
| 74 | + ]; | |
| 47 | 75 | const result = parseArgs(); |
| 48 | 76 | expect(result.rules).toEqual(["my-rule"]); |
| 49 | 77 | expect(result.prompts).toEqual(["my-prompt"]); |
| @@ -53,4 +81,4 @@ | ||
| 53 | 81 | const result = await processPromptOrRule("This is a direct prompt"); |
| 54 | 82 | expect(result).toBe("This is a direct prompt"); |
| 55 | 83 | }); |
| 56 | -}); | |
| No newline at the end of the file | ||
| 84 | +}); |
modified extensions/cli/src/args.test.ts +18 −6
| @@ -269,7 +269,9 @@ | ||
| 269 | 269 | statusText: "Not Found", |
| 270 | 270 | } as Response); |
| 271 | 271 | |
| 272 | - await expect(processPromptOrRule("continuedev/nonexistent-rule")).rejects.toThrow( | |
| 272 | + await expect( | |
| 273 | + processPromptOrRule("continuedev/nonexistent-rule"), | |
| 274 | + ).rejects.toThrow( | |
| 273 | 275 | 'Failed to load rule from hub "continuedev/nonexistent-rule": HTTP 404: Not Found', |
| 274 | 276 | ); |
| 275 | 277 | }); |
| @@ -277,7 +279,9 @@ | ||
| 277 | 279 | it("should handle network errors when loading from hub", async () => { |
| 278 | 280 | mockFetch.mockRejectedValue(new Error("Network error")); |
| 279 | 281 | |
| 280 | - await expect(processPromptOrRule("continuedev/sentry-nextjs")).rejects.toThrow( | |
| 282 | + await expect( | |
| 283 | + processPromptOrRule("continuedev/sentry-nextjs"), | |
| 284 | + ).rejects.toThrow( | |
| 281 | 285 | 'Failed to load rule from hub "continuedev/sentry-nextjs": Network error', |
| 282 | 286 | ); |
| 283 | 287 | }); |
| @@ -285,7 +289,9 @@ | ||
| 285 | 289 | it("should handle invalid slug format", async () => { |
| 286 | 290 | // "invalid-slug" doesn't contain "/" so it's treated as direct content, not a hub slug |
| 287 | 291 | // Let's test with a slug that has wrong format but contains "/" |
| 288 | - await expect(processPromptOrRule("invalid/slug/too/many/parts")).rejects.toThrow( | |
| 292 | + await expect( | |
| 293 | + processPromptOrRule("invalid/slug/too/many/parts"), | |
| 294 | + ).rejects.toThrow( | |
| 289 | 295 | 'Invalid hub slug format. Expected "owner/package", got: invalid/slug/too/many/parts', |
| 290 | 296 | ); |
| 291 | 297 | }); |
| @@ -300,7 +306,9 @@ | ||
| 300 | 306 | arrayBuffer: () => Promise.resolve(zipBuffer), |
| 301 | 307 | } as Response); |
| 302 | 308 | |
| 303 | - await expect(processPromptOrRule("continuedev/empty-rule")).rejects.toThrow( | |
| 309 | + await expect( | |
| 310 | + processPromptOrRule("continuedev/empty-rule"), | |
| 311 | + ).rejects.toThrow( | |
| 304 | 312 | 'Failed to load rule from hub "continuedev/empty-rule": No rule content found in downloaded zip file', |
| 305 | 313 | ); |
| 306 | 314 | }); |
| @@ -316,7 +324,9 @@ | ||
| 316 | 324 | arrayBuffer: () => Promise.resolve(zipBuffer), |
| 317 | 325 | } as Response); |
| 318 | 326 | |
| 319 | - await expect(processPromptOrRule("continuedev/directory-only")).rejects.toThrow( | |
| 327 | + await expect( | |
| 328 | + processPromptOrRule("continuedev/directory-only"), | |
| 329 | + ).rejects.toThrow( | |
| 320 | 330 | 'Failed to load rule from hub "continuedev/directory-only": No rule content found in downloaded zip file', |
| 321 | 331 | ); |
| 322 | 332 | }); |
| @@ -373,7 +383,9 @@ | ||
| 373 | 383 | arrayBuffer: () => Promise.resolve(invalidZipBuffer), |
| 374 | 384 | } as Response); |
| 375 | 385 | |
| 376 | - await expect(processPromptOrRule("continuedev/corrupted-zip")).rejects.toThrow( | |
| 386 | + await expect( | |
| 387 | + processPromptOrRule("continuedev/corrupted-zip"), | |
| 388 | + ).rejects.toThrow( | |
| 377 | 389 | 'Failed to load rule from hub "continuedev/corrupted-zip"', |
| 378 | 390 | ); |
| 379 | 391 | }); |
modified extensions/cli/src/args.ts +12 −14
| @@ -90,20 +90,12 @@ | ||
| 90 | 90 | */ |
| 91 | 91 | export async function processPromptOrRule(spec: string): Promise<string> { |
| 92 | 92 | // If it looks like a hub slug (contains / but doesn't start with . or /) |
| 93 | - if ( | |
| 94 | - spec.includes("/") && | |
| 95 | - !spec.startsWith(".") && | |
| 96 | - !spec.startsWith("/") | |
| 97 | - ) { | |
| 93 | + if (spec.includes("/") && !spec.startsWith(".") && !spec.startsWith("/")) { | |
| 98 | 94 | return await loadRuleFromHub(spec); |
| 99 | 95 | } |
| 100 | 96 | |
| 101 | 97 | // If it looks like a file path (contains . or / or ends with common file extensions) |
| 102 | - if ( | |
| 103 | - spec.includes(".") || | |
| 104 | - spec.includes("/") || | |
| 105 | - spec.includes("\\") | |
| 106 | - ) { | |
| 98 | + if (spec.includes(".") || spec.includes("/") || spec.includes("\\")) { | |
| 107 | 99 | return loadRuleFromFile(spec); |
| 108 | 100 | } |
| 109 | 101 | |
| @@ -186,20 +178,26 @@ | ||
| 186 | 178 | if (promptIndex + 1 >= args.length) { |
| 187 | 179 | throw new Error("--prompt flag requires a value"); |
| 188 | 180 | } |
| 189 | - | |
| 181 | + | |
| 190 | 182 | const promptValue = args[promptIndex + 1]; |
| 191 | - | |
| 183 | + | |
| 192 | 184 | // Check if the next argument is actually another flag |
| 193 | 185 | if (promptValue.startsWith("--")) { |
| 194 | 186 | throw new Error("--prompt flag requires a value, found flag instead"); |
| 195 | 187 | } |
| 196 | - | |
| 188 | + | |
| 197 | 189 | result.prompts.push(promptValue); |
| 198 | 190 | } |
| 199 | 191 | } |
| 200 | 192 | |
| 201 | 193 | // Find the last argument that's not a flag or a flag value |
| 202 | - const flagsWithValues = ["--config", "--org", "--rule", "--prompt", "--format"]; | |
| 194 | + const flagsWithValues = [ | |
| 195 | + "--config", | |
| 196 | + "--org", | |
| 197 | + "--rule", | |
| 198 | + "--prompt", | |
| 199 | + "--format", | |
| 200 | + ]; | |
| 203 | 201 | const nonFlagArgs = args.filter((arg, index) => { |
| 204 | 202 | // Skip flags (starting with --) |
| 205 | 203 | if (arg.startsWith("--") || arg === "-p") return false; |
modified extensions/cli/src/commands/chat.ts +7 −2
| @@ -397,8 +397,13 @@ | ||
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | // Handle additional prompts from --prompt flags |
| 400 | - const { processAndCombinePrompts } = await import("../util/promptProcessor.js"); | |
| 401 | - const initialUserInput = await processAndCombinePrompts(options.prompt, prompt); | |
| 400 | + const { processAndCombinePrompts } = await import( | |
| 401 | + "../util/promptProcessor.js" | |
| 402 | + ); | |
| 403 | + const initialUserInput = await processAndCombinePrompts( | |
| 404 | + options.prompt, | |
| 405 | + prompt, | |
| 406 | + ); | |
| 402 | 407 | |
| 403 | 408 | let isFirstMessage = true; |
| 404 | 409 | while (true) { |
modified extensions/cli/src/ui/hooks/useChat.ts +13 −5
| @@ -164,16 +164,24 @@ | ||
| 164 | 164 | useEffect(() => { |
| 165 | 165 | // Only handle initial prompt after chat history is initialized |
| 166 | 166 | // This prevents race conditions where the prompt runs before system message is loaded |
| 167 | - if ((initialPrompt || (additionalPrompts && additionalPrompts.length > 0)) && isChatHistoryInitialized) { | |
| 167 | + if ( | |
| 168 | + (initialPrompt || (additionalPrompts && additionalPrompts.length > 0)) && | |
| 169 | + isChatHistoryInitialized | |
| 170 | + ) { | |
| 168 | 171 | const processPrompts = async () => { |
| 169 | - const { processAndCombinePrompts } = await import("../../util/promptProcessor.js"); | |
| 170 | - const finalMessage = await processAndCombinePrompts(additionalPrompts, initialPrompt); | |
| 171 | - | |
| 172 | + const { processAndCombinePrompts } = await import( | |
| 173 | + "../../util/promptProcessor.js" | |
| 174 | + ); | |
| 175 | + const finalMessage = await processAndCombinePrompts( | |
| 176 | + additionalPrompts, | |
| 177 | + initialPrompt, | |
| 178 | + ); | |
| 179 | + | |
| 172 | 180 | if (finalMessage) { |
| 173 | 181 | await handleUserMessage(finalMessage); |
| 174 | 182 | } |
| 175 | 183 | }; |
| 176 | - | |
| 184 | + | |
| 177 | 185 | processPrompts().catch(console.error); |
| 178 | 186 | } |
| 179 | 187 | }, [initialPrompt, additionalPrompts, isChatHistoryInitialized]); |
modified extensions/cli/src/util/promptProcessor.test.ts +6 −7
| @@ -82,11 +82,7 @@ | ||
| 82 | 82 | .mockRejectedValueOnce(new Error("processing failed")) |
| 83 | 83 | .mockResolvedValueOnce("success2"); |
| 84 | 84 | |
| 85 | - const result = await processAndCombinePrompts([ | |
| 86 | - "good1", | |
| 87 | - "bad", | |
| 88 | - "good2", | |
| 89 | - ]); | |
| 85 | + const result = await processAndCombinePrompts(["good1", "bad", "good2"]); | |
| 90 | 86 | |
| 91 | 87 | expect(mockProcessPromptOrRule).toHaveBeenCalledTimes(3); |
| 92 | 88 | expect(result).toBe("success1\n\nsuccess2"); |
| @@ -98,7 +94,10 @@ | ||
| 98 | 94 | .mockRejectedValueOnce(new Error("fail1")) |
| 99 | 95 | .mockRejectedValueOnce(new Error("fail2")); |
| 100 | 96 | |
| 101 | - const result = await processAndCombinePrompts(["bad1", "bad2"], "initial"); | |
| 97 | + const result = await processAndCombinePrompts( | |
| 98 | + ["bad1", "bad2"], | |
| 99 | + "initial", | |
| 100 | + ); | |
| 102 | 101 | |
| 103 | 102 | expect(result).toBe("initial"); |
| 104 | 103 | }); |
| @@ -125,4 +124,4 @@ | ||
| 125 | 124 | ); |
| 126 | 125 | }); |
| 127 | 126 | }); |
| 128 | -}); | |
| No newline at the end of the file | ||
| 127 | +}); |
modified extensions/cli/src/util/promptProcessor.ts +2 −4
| @@ -22,9 +22,7 @@ | ||
| 22 | 22 | const processed = await processPromptOrRule(promptSpec); |
| 23 | 23 | processedPrompts.push(processed); |
| 24 | 24 | } catch (error: any) { |
| 25 | - logger.warn( | |
| 26 | - `Failed to process prompt "${promptSpec}": ${error.message}`, | |
| 27 | - ); | |
| 25 | + logger.warn(`Failed to process prompt "${promptSpec}": ${error.message}`); | |
| 28 | 26 | } |
| 29 | 27 | } |
| 30 | 28 | |
| @@ -36,4 +34,4 @@ | ||
| 36 | 34 | return initialPrompt |
| 37 | 35 | ? `${combinedPrompts}\n\n${initialPrompt}` |
| 38 | 36 | : combinedPrompts; |
| 39 | -} | |
| No newline at the end of the file | ||
| 37 | +} |