Changesets · Branches · Tags · Compare
| Changeset | 8eb3ae7b8d169d05f7e0159cdae8cfe3eef416dbb6cfed1a085b268879db451b |
|---|---|
| Author | Nate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-08-23 11:43 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-08-23 11:43 -07:00 |
| Parents | 44c49c17ea96, c04584525d2e |
20 files changed
modified .github/workflows/compliance.yaml +1 −1
| @@ -36,7 +36,7 @@ | ||
| 36 | 36 | else |
| 37 | 37 | echo "❌ PR title does not follow conventional commit format" |
| 38 | 38 | echo "valid=false" >> $GITHUB_OUTPUT |
| 39 | - exit 1 | |
| 39 | + # Don't exit with failure - just mark as invalid for comment | |
| 40 | 40 | fi |
| 41 | 41 | |
| 42 | 42 | - name: Add PR title guidance comment |
modified extensions/cli/src/__mocks__/args.ts +3 −1
| @@ -1,3 +1,5 @@ | ||
| 1 | 1 | import { vi } from "vitest"; |
| 2 | 2 | |
| 3 | -export const processRule = vi.fn<(rule: string) => Promise<string>>(); | |
| 3 | +export const processPromptOrRule = vi.fn<(spec: string) => Promise<string>>(); | |
| 4 | + | |
| 5 | +export const processPrompt = vi.fn<(prompt: string) => Promise<string>>(); |
added extensions/cli/src/args.prompt.test.ts +84 −0
| @@ -0,0 +1,84 @@ | ||
| 1 | +import { describe, it, expect, beforeEach, afterAll } from "vitest"; | |
| 2 | + | |
| 3 | +import { parseArgs, processPromptOrRule } from "./args.js"; | |
| 4 | + | |
| 5 | +describe("args --prompt flag", () => { | |
| 6 | + const originalArgv = process.argv; | |
| 7 | + | |
| 8 | + beforeEach(() => { | |
| 9 | + // Reset process.argv for each test | |
| 10 | + process.argv = ["node", "script.js"]; | |
| 11 | + }); | |
| 12 | + | |
| 13 | + afterAll(() => { | |
| 14 | + // Restore original process.argv after all tests | |
| 15 | + process.argv = originalArgv; | |
| 16 | + }); | |
| 17 | + | |
| 18 | + it("should parse single prompt from --prompt flag", () => { | |
| 19 | + process.argv = ["node", "script.js", "--prompt", "my-prompt"]; | |
| 20 | + const result = parseArgs(); | |
| 21 | + expect(result.prompts).toEqual(["my-prompt"]); | |
| 22 | + }); | |
| 23 | + | |
| 24 | + it("should parse multiple prompts from multiple --prompt flags", () => { | |
| 25 | + process.argv = [ | |
| 26 | + "node", | |
| 27 | + "script.js", | |
| 28 | + "--prompt", | |
| 29 | + "prompt1", | |
| 30 | + "--prompt", | |
| 31 | + "prompt2", | |
| 32 | + ]; | |
| 33 | + const result = parseArgs(); | |
| 34 | + expect(result.prompts).toEqual(["prompt1", "prompt2"]); | |
| 35 | + }); | |
| 36 | + | |
| 37 | + it("should handle mixed flags including --prompt", () => { | |
| 38 | + process.argv = [ | |
| 39 | + "node", | |
| 40 | + "script.js", | |
| 41 | + "--config", | |
| 42 | + "myconfig", | |
| 43 | + "--prompt", | |
| 44 | + "myprompt", | |
| 45 | + "--resume", | |
| 46 | + ]; | |
| 47 | + const result = parseArgs(); | |
| 48 | + expect(result.configPath).toBe("myconfig"); | |
| 49 | + expect(result.prompts).toEqual(["myprompt"]); | |
| 50 | + expect(result.resume).toBe(true); | |
| 51 | + }); | |
| 52 | + | |
| 53 | + it("should not include --prompt value in non-flag arguments", () => { | |
| 54 | + process.argv = [ | |
| 55 | + "node", | |
| 56 | + "script.js", | |
| 57 | + "--prompt", | |
| 58 | + "prompt-value", | |
| 59 | + "actual-prompt", | |
| 60 | + ]; | |
| 61 | + const result = parseArgs(); | |
| 62 | + expect(result.prompts).toEqual(["prompt-value"]); | |
| 63 | + expect(result.prompt).toBe("actual-prompt"); | |
| 64 | + }); | |
| 65 | + | |
| 66 | + it("should handle both --rule and --prompt flags", () => { | |
| 67 | + process.argv = [ | |
| 68 | + "node", | |
| 69 | + "script.js", | |
| 70 | + "--rule", | |
| 71 | + "my-rule", | |
| 72 | + "--prompt", | |
| 73 | + "my-prompt", | |
| 74 | + ]; | |
| 75 | + const result = parseArgs(); | |
| 76 | + expect(result.rules).toEqual(["my-rule"]); | |
| 77 | + expect(result.prompts).toEqual(["my-prompt"]); | |
| 78 | + }); | |
| 79 | + | |
| 80 | + it("should process direct string content", async () => { | |
| 81 | + const result = await processPromptOrRule("This is a direct prompt"); | |
| 82 | + expect(result).toBe("This is a direct prompt"); | |
| 83 | + }); | |
| 84 | +}); |
modified extensions/cli/src/args.test.ts +27 −15
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | import { vi } from "vitest"; |
| 2 | 2 | |
| 3 | -import { parseArgs, processRule } from "./args.js"; | |
| 3 | +import { parseArgs, processPromptOrRule } from "./args.js"; | |
| 4 | 4 | |
| 5 | 5 | describe("parseArgs", () => { |
| 6 | 6 | const originalArgv = process.argv; |
| @@ -217,7 +217,7 @@ | ||
| 217 | 217 | }); |
| 218 | 218 | }); |
| 219 | 219 | |
| 220 | -describe("processRule (loadRuleFromHub integration)", () => { | |
| 220 | +describe("processPromptOrRule (loadRuleFromHub integration)", () => { | |
| 221 | 221 | // Mock fetch for hub tests |
| 222 | 222 | const originalFetch = global.fetch; |
| 223 | 223 | const mockFetch = vi.fn() as any; |
| @@ -251,7 +251,7 @@ | ||
| 251 | 251 | arrayBuffer: () => Promise.resolve(zipBuffer), |
| 252 | 252 | } as Response); |
| 253 | 253 | |
| 254 | - const result = await processRule("continuedev/sentry-nextjs"); | |
| 254 | + const result = await processPromptOrRule("continuedev/sentry-nextjs"); | |
| 255 | 255 | |
| 256 | 256 | expect(result).toBe(ruleContent); |
| 257 | 257 | expect(mockFetch).toHaveBeenCalledWith( |
| @@ -269,7 +269,9 @@ | ||
| 269 | 269 | statusText: "Not Found", |
| 270 | 270 | } as Response); |
| 271 | 271 | |
| 272 | - await expect(processRule("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(processRule("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(processRule("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(processRule("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(processRule("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 | }); |
| @@ -338,7 +348,7 @@ | ||
| 338 | 348 | arrayBuffer: () => Promise.resolve(zipBuffer), |
| 339 | 349 | } as Response); |
| 340 | 350 | |
| 341 | - const result = await processRule("continuedev/mixed-files"); | |
| 351 | + const result = await processPromptOrRule("continuedev/mixed-files"); | |
| 342 | 352 | |
| 343 | 353 | expect(result).toBe(mdContent); |
| 344 | 354 | }); |
| @@ -359,7 +369,7 @@ | ||
| 359 | 369 | arrayBuffer: () => Promise.resolve(zipBuffer), |
| 360 | 370 | } as Response); |
| 361 | 371 | |
| 362 | - const result = await processRule("continuedev/multiple-rules"); | |
| 372 | + const result = await processPromptOrRule("continuedev/multiple-rules"); | |
| 363 | 373 | |
| 364 | 374 | // Should use the first markdown file found (alphabetically) |
| 365 | 375 | expect(result).toBe(rule1Content); |
| @@ -373,13 +383,15 @@ | ||
| 373 | 383 | arrayBuffer: () => Promise.resolve(invalidZipBuffer), |
| 374 | 384 | } as Response); |
| 375 | 385 | |
| 376 | - await expect(processRule("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 | }); |
| 380 | 392 | }); |
| 381 | 393 | |
| 382 | - describe("processRule logic", () => { | |
| 394 | + describe("processPromptOrRule logic", () => { | |
| 383 | 395 | it("should identify hub slugs correctly", async () => { |
| 384 | 396 | const JSZip = (await import("jszip")).default; |
| 385 | 397 | const zip = new JSZip(); |
| @@ -391,14 +403,14 @@ | ||
| 391 | 403 | arrayBuffer: () => Promise.resolve(zipBuffer), |
| 392 | 404 | } as Response); |
| 393 | 405 | |
| 394 | - const result = await processRule("owner/package"); | |
| 406 | + const result = await processPromptOrRule("owner/package"); | |
| 395 | 407 | expect(result).toBe("# Hub Rule"); |
| 396 | 408 | expect(mockFetch).toHaveBeenCalled(); |
| 397 | 409 | }); |
| 398 | 410 | |
| 399 | 411 | it("should treat direct strings as content", async () => { |
| 400 | 412 | const directContent = "This is direct rule content"; |
| 401 | - const result = await processRule(directContent); | |
| 413 | + const result = await processPromptOrRule(directContent); | |
| 402 | 414 | expect(result).toBe(directContent); |
| 403 | 415 | expect(mockFetch).not.toHaveBeenCalled(); |
| 404 | 416 | }); |
| @@ -406,7 +418,7 @@ | ||
| 406 | 418 | it("should distinguish between hub slugs and file paths", async () => { |
| 407 | 419 | // This would be treated as a file path, not a hub slug |
| 408 | 420 | // since it starts with "." |
| 409 | - await expect(processRule("./owner/package")).rejects.toThrow( | |
| 421 | + await expect(processPromptOrRule("./owner/package")).rejects.toThrow( | |
| 410 | 422 | 'Failed to read rule file "./owner/package": Rule file not found', |
| 411 | 423 | ); |
| 412 | 424 | expect(mockFetch).not.toHaveBeenCalled(); |
modified extensions/cli/src/args.ts +44 −18
| @@ -12,6 +12,7 @@ | ||
| 12 | 12 | resume?: boolean; // Resume from last session |
| 13 | 13 | readonly?: boolean; // Start in plan mode (backward compatibility) |
| 14 | 14 | rules?: string[]; // Array of rule specifications |
| 15 | + prompts?: string[]; // Array of prompt specifications | |
| 15 | 16 | format?: "json"; // Output format for headless mode |
| 16 | 17 | } |
| 17 | 18 | |
| @@ -83,31 +84,23 @@ | ||
| 83 | 84 | } |
| 84 | 85 | |
| 85 | 86 | /** |
| 86 | - * Process a rule specification and return its content | |
| 87 | - * @param ruleSpec - Can be a file path, hub slug, or direct string content | |
| 88 | - * @returns The processed rule content | |
| 87 | + * Process a specification (rule or prompt) and return its content | |
| 88 | + * @param spec - Can be a file path, hub slug, or direct string content | |
| 89 | + * @returns The processed content | |
| 89 | 90 | */ |
| 90 | -export async function processRule(ruleSpec: string): Promise<string> { | |
| 91 | +export async function processPromptOrRule(spec: string): Promise<string> { | |
| 91 | 92 | // If it looks like a hub slug (contains / but doesn't start with . or /) |
| 92 | - if ( | |
| 93 | - ruleSpec.includes("/") && | |
| 94 | - !ruleSpec.startsWith(".") && | |
| 95 | - !ruleSpec.startsWith("/") | |
| 96 | - ) { | |
| 97 | - return await loadRuleFromHub(ruleSpec); | |
| 93 | + if (spec.includes("/") && !spec.startsWith(".") && !spec.startsWith("/")) { | |
| 94 | + return await loadRuleFromHub(spec); | |
| 98 | 95 | } |
| 99 | 96 | |
| 100 | 97 | // If it looks like a file path (contains . or / or ends with common file extensions) |
| 101 | - if ( | |
| 102 | - ruleSpec.includes(".") || | |
| 103 | - ruleSpec.includes("/") || | |
| 104 | - ruleSpec.includes("\\") | |
| 105 | - ) { | |
| 106 | - return loadRuleFromFile(ruleSpec); | |
| 98 | + if (spec.includes(".") || spec.includes("/") || spec.includes("\\")) { | |
| 99 | + return loadRuleFromFile(spec); | |
| 107 | 100 | } |
| 108 | 101 | |
| 109 | 102 | // Otherwise, treat it as direct string content |
| 110 | - return ruleSpec; | |
| 103 | + return spec; | |
| 111 | 104 | } |
| 112 | 105 | |
| 113 | 106 | /** |
| @@ -115,6 +108,7 @@ | ||
| 115 | 108 | * @deprecated Most functionality has been moved to services. This is only kept for backward compatibility. |
| 116 | 109 | * @returns Parsed command line arguments |
| 117 | 110 | */ |
| 111 | +/* eslint-disable */ | |
| 118 | 112 | export function parseArgs(): CommandLineArgs { |
| 119 | 113 | const args = process.argv.slice(2); |
| 120 | 114 | |
| @@ -170,8 +164,40 @@ | ||
| 170 | 164 | } |
| 171 | 165 | } |
| 172 | 166 | |
| 167 | + // Get prompts from --prompt flags (can be specified multiple times) | |
| 168 | + const promptIndices: number[] = []; | |
| 169 | + for (let i = 0; i < args.length; i++) { | |
| 170 | + if (args[i] === "--prompt") { | |
| 171 | + promptIndices.push(i); | |
| 172 | + } | |
| 173 | + } | |
| 174 | + | |
| 175 | + if (promptIndices.length > 0) { | |
| 176 | + result.prompts = []; | |
| 177 | + for (const promptIndex of promptIndices) { | |
| 178 | + if (promptIndex + 1 >= args.length) { | |
| 179 | + throw new Error("--prompt flag requires a value"); | |
| 180 | + } | |
| 181 | + | |
| 182 | + const promptValue = args[promptIndex + 1]; | |
| 183 | + | |
| 184 | + // Check if the next argument is actually another flag | |
| 185 | + if (promptValue.startsWith("--")) { | |
| 186 | + throw new Error("--prompt flag requires a value, found flag instead"); | |
| 187 | + } | |
| 188 | + | |
| 189 | + result.prompts.push(promptValue); | |
| 190 | + } | |
| 191 | + } | |
| 192 | + | |
| 173 | 193 | // Find the last argument that's not a flag or a flag value |
| 174 | - const flagsWithValues = ["--config", "--org", "--rule", "--format"]; | |
| 194 | + const flagsWithValues = [ | |
| 195 | + "--config", | |
| 196 | + "--org", | |
| 197 | + "--rule", | |
| 198 | + "--prompt", | |
| 199 | + "--format", | |
| 200 | + ]; | |
| 175 | 201 | const nonFlagArgs = args.filter((arg, index) => { |
| 176 | 202 | // Skip flags (starting with --) |
| 177 | 203 | if (arg.startsWith("--") || arg === "-p") return false; |
modified extensions/cli/src/commands/chat.ts +14 −3
| @@ -78,6 +78,7 @@ | ||
| 78 | 78 | headless?: boolean; |
| 79 | 79 | resume?: boolean; |
| 80 | 80 | rule?: string[]; // Array of rule specifications |
| 81 | + prompt?: string[]; // Array of prompt specifications | |
| 81 | 82 | format?: "json"; // Output format for headless mode |
| 82 | 83 | silent?: boolean; // Strip <think></think> tags and excess whitespace |
| 83 | 84 | org?: string; // Organization slug to use for this session |
| @@ -395,17 +396,26 @@ | ||
| 395 | 396 | compactionIndex = findCompactionIndex(chatHistory); |
| 396 | 397 | } |
| 397 | 398 | |
| 399 | + // Handle additional prompts from --prompt flags | |
| 400 | + const { processAndCombinePrompts } = await import( | |
| 401 | + "../util/promptProcessor.js" | |
| 402 | + ); | |
| 403 | + const initialUserInput = await processAndCombinePrompts( | |
| 404 | + options.prompt, | |
| 405 | + prompt, | |
| 406 | + ); | |
| 407 | + | |
| 398 | 408 | let isFirstMessage = true; |
| 399 | 409 | while (true) { |
| 400 | 410 | // When in headless mode, don't ask for user input |
| 401 | - if (!isFirstMessage && prompt && options.headless) { | |
| 411 | + if (!isFirstMessage && initialUserInput && options.headless) { | |
| 402 | 412 | break; |
| 403 | 413 | } |
| 404 | 414 | |
| 405 | 415 | // Get user input |
| 406 | 416 | const userInput = |
| 407 | - isFirstMessage && prompt | |
| 408 | - ? prompt | |
| 417 | + isFirstMessage && initialUserInput | |
| 418 | + ? initialUserInput | |
| 409 | 419 | : readlineSync.question(`\n${chalk.bold.green("You:")} `); |
| 410 | 420 | |
| 411 | 421 | isFirstMessage = false; |
| @@ -472,6 +482,7 @@ | ||
| 472 | 482 | configPath: options.config, |
| 473 | 483 | organizationSlug: options.org, |
| 474 | 484 | additionalRules: options.rule, |
| 485 | + additionalPrompts: options.prompt, | |
| 475 | 486 | toolPermissionOverrides: permissionOverrides, |
| 476 | 487 | skipOnboarding: true, |
| 477 | 488 | }; |
modified extensions/cli/src/e2e/basic-commands.test.ts +1 −0
| @@ -40,6 +40,7 @@ | ||
| 40 | 40 | expect(result.stdout).toContain("--readonly"); |
| 41 | 41 | expect(result.stdout).toContain("--auto"); |
| 42 | 42 | expect(result.stdout).toContain("--rule <rule>"); |
| 43 | + expect(result.stdout).toContain("--prompt <prompt>"); | |
| 43 | 44 | }); |
| 44 | 45 | |
| 45 | 46 | it("should show available commands", async () => { |
modified extensions/cli/src/onboarding.ts +2 −2
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | import chalk from "chalk"; |
| 8 | 8 | import * as readlineSync from "readline-sync"; |
| 9 | 9 | |
| 10 | -import { processRule } from "./args.js"; | |
| 10 | +import { processPromptOrRule } from "./args.js"; | |
| 11 | 11 | import { AuthConfig, isAuthenticated, login } from "./auth/workos.js"; |
| 12 | 12 | import { initialize } from "./config.js"; |
| 13 | 13 | import { env } from "./env.js"; |
| @@ -239,7 +239,7 @@ | ||
| 239 | 239 | const processedRules: string[] = []; |
| 240 | 240 | for (const ruleSpec of rules) { |
| 241 | 241 | try { |
| 242 | - const processedRule = await processRule(ruleSpec); | |
| 242 | + const processedRule = await processPromptOrRule(ruleSpec); | |
| 243 | 243 | processedRules.push(processedRule); |
| 244 | 244 | } catch (error: any) { |
| 245 | 245 | console.warn( |
modified extensions/cli/src/services/ConfigService.test.ts +1 −1
| @@ -73,7 +73,7 @@ | ||
| 73 | 73 | config: mockConfig as any, |
| 74 | 74 | source: { type: "cli-flag", path: "/config.yaml" } as any, |
| 75 | 75 | }); |
| 76 | - vi.mocked(args.processRule).mockImplementation( | |
| 76 | + vi.mocked(args.processPromptOrRule).mockImplementation( | |
| 77 | 77 | async (rule) => `Processed: ${rule}`, |
| 78 | 78 | ); |
| 79 | 79 |
modified extensions/cli/src/services/ConfigService.ts +2 −2
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | import { AssistantUnrolled } from "@continuedev/config-yaml"; |
| 2 | 2 | import { DefaultApiInterface } from "@continuedev/sdk/dist/api/dist/index.js"; |
| 3 | 3 | |
| 4 | -import { processRule } from "../args.js"; | |
| 4 | +import { processPromptOrRule } from "../args.js"; | |
| 5 | 5 | import { AuthConfig, loadAuthConfig } from "../auth/workos.js"; |
| 6 | 6 | import { logger } from "../util/logger.js"; |
| 7 | 7 | |
| @@ -155,7 +155,7 @@ | ||
| 155 | 155 | |
| 156 | 156 | for (const ruleSpec of rules) { |
| 157 | 157 | try { |
| 158 | - const processedRule = await processRule(ruleSpec); | |
| 158 | + const processedRule = await processPromptOrRule(ruleSpec); | |
| 159 | 159 | processedRules.push(processedRule); |
| 160 | 160 | } catch (error: any) { |
| 161 | 161 | logger.warn(`Failed to process rule "${ruleSpec}": ${error.message}`); |
modified extensions/cli/src/shared-options.ts +11 −0
| @@ -24,6 +24,16 @@ | ||
| 24 | 24 | }, |
| 25 | 25 | [] as string[], |
| 26 | 26 | ) |
| 27 | + .option( | |
| 28 | + "--prompt <prompt>", | |
| 29 | + "Add to the initial user message (can be a file path, hub slug, or string content). Can be specified multiple times.", | |
| 30 | + (value: string, previous: string[] | undefined) => { | |
| 31 | + const array = Array.isArray(previous) ? previous : []; | |
| 32 | + array.push(value); | |
| 33 | + return array; | |
| 34 | + }, | |
| 35 | + [] as string[], | |
| 36 | + ) | |
| 27 | 37 | .option( |
| 28 | 38 | "--allow <tool>", |
| 29 | 39 | "Allow specified tool (overrides default policies). Can be specified multiple times.", |
| @@ -70,6 +80,7 @@ | ||
| 70 | 80 | "tools", |
| 71 | 81 | "verbose", |
| 72 | 82 | "rule", |
| 83 | + "prompt", | |
| 73 | 84 | "allow", |
| 74 | 85 | "ask", |
| 75 | 86 | "exclude", |
modified extensions/cli/src/systemMessage.test.ts +3 −3
| @@ -11,11 +11,11 @@ | ||
| 11 | 11 | }, |
| 12 | 12 | })); |
| 13 | 13 | |
| 14 | -// Mock processRule to avoid file system operations in tests | |
| 14 | +// Mock processPromptOrRule to avoid file system operations in tests | |
| 15 | 15 | vi.mock("./args.js", () => ({ |
| 16 | - processRule: vi | |
| 16 | + processPromptOrRule: vi | |
| 17 | 17 | .fn() |
| 18 | - .mockImplementation((rule: string) => Promise.resolve(rule)), | |
| 18 | + .mockImplementation((spec: string) => Promise.resolve(spec)), | |
| 19 | 19 | })); |
| 20 | 20 | |
| 21 | 21 | describe("constructSystemMessage", () => { |
modified extensions/cli/src/systemMessage.ts +2 −2
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | import pkg from "ignore-walk"; |
| 6 | 6 | import { Minimatch } from "minimatch"; |
| 7 | 7 | |
| 8 | -import { processRule } from "./args.js"; | |
| 8 | +import { processPromptOrRule } from "./args.js"; | |
| 9 | 9 | import { serviceContainer } from "./services/ServiceContainer.js"; |
| 10 | 10 | import { ConfigServiceState, SERVICE_NAMES } from "./services/types.js"; |
| 11 | 11 | const { WalkerSync } = pkg; |
| @@ -150,7 +150,7 @@ | ||
| 150 | 150 | if (additionalRules && additionalRules.length > 0) { |
| 151 | 151 | for (const ruleSpec of additionalRules) { |
| 152 | 152 | try { |
| 153 | - const processedRule = await processRule(ruleSpec); | |
| 153 | + const processedRule = await processPromptOrRule(ruleSpec); | |
| 154 | 154 | processedRules.push(processedRule); |
| 155 | 155 | } catch (error: any) { |
| 156 | 156 | console.warn( |
modified extensions/cli/src/ui/AppRoot.tsx +1 −0
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | initialPrompt?: string; |
| 10 | 10 | resume?: boolean; |
| 11 | 11 | additionalRules?: string[]; |
| 12 | + additionalPrompts?: string[]; | |
| 12 | 13 | } |
| 13 | 14 | |
| 14 | 15 | /** |
modified extensions/cli/src/ui/TUIChat.tsx +3 −0
| @@ -36,6 +36,7 @@ | ||
| 36 | 36 | initialPrompt?: string; |
| 37 | 37 | resume?: boolean; |
| 38 | 38 | additionalRules?: string[]; |
| 39 | + additionalPrompts?: string[]; | |
| 39 | 40 | } |
| 40 | 41 | |
| 41 | 42 | const TUIChat: React.FC<TUIChatProps> = ({ |
| @@ -44,6 +45,7 @@ | ||
| 44 | 45 | initialPrompt, |
| 45 | 46 | resume, |
| 46 | 47 | additionalRules, |
| 48 | + additionalPrompts, | |
| 47 | 49 | }) => { |
| 48 | 50 | // Check if we're in remote mode |
| 49 | 51 | const isRemoteMode = useMemo(() => { |
| @@ -126,6 +128,7 @@ | ||
| 126 | 128 | initialPrompt, |
| 127 | 129 | resume, |
| 128 | 130 | additionalRules, |
| 131 | + additionalPrompts, | |
| 129 | 132 | onShowConfigSelector: () => navigateTo("config"), |
| 130 | 133 | onShowModelSelector: () => navigateTo("model"), |
| 131 | 134 | onShowMCPSelector: () => navigateTo("mcp"), |
modified extensions/cli/src/ui/hooks/useChat.ts +21 −3
| @@ -42,6 +42,7 @@ | ||
| 42 | 42 | initialPrompt, |
| 43 | 43 | resume, |
| 44 | 44 | additionalRules, |
| 45 | + additionalPrompts, | |
| 45 | 46 | onShowConfigSelector, |
| 46 | 47 | onShowModelSelector, |
| 47 | 48 | onShowMCPSelector, |
| @@ -163,10 +164,27 @@ | ||
| 163 | 164 | useEffect(() => { |
| 164 | 165 | // Only handle initial prompt after chat history is initialized |
| 165 | 166 | // This prevents race conditions where the prompt runs before system message is loaded |
| 166 | - if (initialPrompt && isChatHistoryInitialized) { | |
| 167 | - handleUserMessage(initialPrompt); | |
| 167 | + if ( | |
| 168 | + (initialPrompt || (additionalPrompts && additionalPrompts.length > 0)) && | |
| 169 | + isChatHistoryInitialized | |
| 170 | + ) { | |
| 171 | + const processPrompts = async () => { | |
| 172 | + const { processAndCombinePrompts } = await import( | |
| 173 | + "../../util/promptProcessor.js" | |
| 174 | + ); | |
| 175 | + const finalMessage = await processAndCombinePrompts( | |
| 176 | + additionalPrompts, | |
| 177 | + initialPrompt, | |
| 178 | + ); | |
| 179 | + | |
| 180 | + if (finalMessage) { | |
| 181 | + await handleUserMessage(finalMessage); | |
| 182 | + } | |
| 183 | + }; | |
| 184 | + | |
| 185 | + processPrompts().catch(console.error); | |
| 168 | 186 | } |
| 169 | - }, [initialPrompt, isChatHistoryInitialized]); | |
| 187 | + }, [initialPrompt, additionalPrompts, isChatHistoryInitialized]); | |
| 170 | 188 | |
| 171 | 189 | const executeStreamingResponse = async ( |
| 172 | 190 | newHistory: ChatCompletionMessageParam[], |
modified extensions/cli/src/ui/hooks/useChat.types.ts +1 −0
| @@ -11,6 +11,7 @@ | ||
| 11 | 11 | initialPrompt?: string; |
| 12 | 12 | resume?: boolean; |
| 13 | 13 | additionalRules?: string[]; |
| 14 | + additionalPrompts?: string[]; | |
| 14 | 15 | onShowConfigSelector: () => void; |
| 15 | 16 | onShowMCPSelector: () => void; |
| 16 | 17 | onShowModelSelector?: () => void; |
modified extensions/cli/src/ui/index.ts +3 −0
| @@ -15,6 +15,7 @@ | ||
| 15 | 15 | configPath?: string; |
| 16 | 16 | organizationSlug?: string; |
| 17 | 17 | additionalRules?: string[]; |
| 18 | + additionalPrompts?: string[]; | |
| 18 | 19 | toolPermissionOverrides?: { |
| 19 | 20 | allow?: string[]; |
| 20 | 21 | ask?: string[]; |
| @@ -33,6 +34,7 @@ | ||
| 33 | 34 | configPath, |
| 34 | 35 | organizationSlug, |
| 35 | 36 | additionalRules, |
| 37 | + additionalPrompts, | |
| 36 | 38 | toolPermissionOverrides, |
| 37 | 39 | skipOnboarding, |
| 38 | 40 | customStdin, |
| @@ -64,6 +66,7 @@ | ||
| 64 | 66 | initialPrompt, |
| 65 | 67 | resume, |
| 66 | 68 | additionalRules, |
| 69 | + additionalPrompts, | |
| 67 | 70 | }), |
| 68 | 71 | }), |
| 69 | 72 | renderOptions, |
added extensions/cli/src/util/promptProcessor.test.ts +127 −0
| @@ -0,0 +1,127 @@ | ||
| 1 | +import { describe, it, expect, vi, beforeEach } from "vitest"; | |
| 2 | + | |
| 3 | +import * as args from "../args.js"; | |
| 4 | + | |
| 5 | +import { processAndCombinePrompts } from "./promptProcessor.js"; | |
| 6 | + | |
| 7 | +// Mock the args module | |
| 8 | +vi.mock("../args.js", () => ({ | |
| 9 | + processPromptOrRule: vi.fn(), | |
| 10 | +})); | |
| 11 | + | |
| 12 | +// Mock the logger | |
| 13 | +vi.mock("./logger.js", () => ({ | |
| 14 | + logger: { | |
| 15 | + warn: vi.fn(), | |
| 16 | + }, | |
| 17 | +})); | |
| 18 | + | |
| 19 | +describe("promptProcessor", () => { | |
| 20 | + beforeEach(() => { | |
| 21 | + vi.clearAllMocks(); | |
| 22 | + }); | |
| 23 | + | |
| 24 | + describe("processAndCombinePrompts", () => { | |
| 25 | + it("should return initial prompt when no additional prompts", async () => { | |
| 26 | + const result = await processAndCombinePrompts(undefined, "initial"); | |
| 27 | + expect(result).toBe("initial"); | |
| 28 | + }); | |
| 29 | + | |
| 30 | + it("should return initial prompt when empty additional prompts array", async () => { | |
| 31 | + const result = await processAndCombinePrompts([], "initial"); | |
| 32 | + expect(result).toBe("initial"); | |
| 33 | + }); | |
| 34 | + | |
| 35 | + it("should return undefined when no prompts at all", async () => { | |
| 36 | + const result = await processAndCombinePrompts(); | |
| 37 | + expect(result).toBeUndefined(); | |
| 38 | + }); | |
| 39 | + | |
| 40 | + it("should process single additional prompt without initial", async () => { | |
| 41 | + const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule); | |
| 42 | + mockProcessPromptOrRule.mockResolvedValue("processed prompt"); | |
| 43 | + | |
| 44 | + const result = await processAndCombinePrompts(["prompt1"]); | |
| 45 | + | |
| 46 | + expect(mockProcessPromptOrRule).toHaveBeenCalledWith("prompt1"); | |
| 47 | + expect(result).toBe("processed prompt"); | |
| 48 | + }); | |
| 49 | + | |
| 50 | + it("should combine multiple processed prompts", async () => { | |
| 51 | + const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule); | |
| 52 | + mockProcessPromptOrRule | |
| 53 | + .mockResolvedValueOnce("first prompt") | |
| 54 | + .mockResolvedValueOnce("second prompt"); | |
| 55 | + | |
| 56 | + const result = await processAndCombinePrompts(["prompt1", "prompt2"]); | |
| 57 | + | |
| 58 | + expect(mockProcessPromptOrRule).toHaveBeenCalledTimes(2); | |
| 59 | + expect(mockProcessPromptOrRule).toHaveBeenNthCalledWith(1, "prompt1"); | |
| 60 | + expect(mockProcessPromptOrRule).toHaveBeenNthCalledWith(2, "prompt2"); | |
| 61 | + expect(result).toBe("first prompt\n\nsecond prompt"); | |
| 62 | + }); | |
| 63 | + | |
| 64 | + it("should combine processed prompts with initial prompt", async () => { | |
| 65 | + const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule); | |
| 66 | + mockProcessPromptOrRule | |
| 67 | + .mockResolvedValueOnce("processed1") | |
| 68 | + .mockResolvedValueOnce("processed2"); | |
| 69 | + | |
| 70 | + const result = await processAndCombinePrompts( | |
| 71 | + ["prompt1", "prompt2"], | |
| 72 | + "initial", | |
| 73 | + ); | |
| 74 | + | |
| 75 | + expect(result).toBe("processed1\n\nprocessed2\n\ninitial"); | |
| 76 | + }); | |
| 77 | + | |
| 78 | + it("should handle processing errors and continue with successful ones", async () => { | |
| 79 | + const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule); | |
| 80 | + mockProcessPromptOrRule | |
| 81 | + .mockResolvedValueOnce("success1") | |
| 82 | + .mockRejectedValueOnce(new Error("processing failed")) | |
| 83 | + .mockResolvedValueOnce("success2"); | |
| 84 | + | |
| 85 | + const result = await processAndCombinePrompts(["good1", "bad", "good2"]); | |
| 86 | + | |
| 87 | + expect(mockProcessPromptOrRule).toHaveBeenCalledTimes(3); | |
| 88 | + expect(result).toBe("success1\n\nsuccess2"); | |
| 89 | + }); | |
| 90 | + | |
| 91 | + it("should return initial prompt when all processing fails", async () => { | |
| 92 | + const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule); | |
| 93 | + mockProcessPromptOrRule | |
| 94 | + .mockRejectedValueOnce(new Error("fail1")) | |
| 95 | + .mockRejectedValueOnce(new Error("fail2")); | |
| 96 | + | |
| 97 | + const result = await processAndCombinePrompts( | |
| 98 | + ["bad1", "bad2"], | |
| 99 | + "initial", | |
| 100 | + ); | |
| 101 | + | |
| 102 | + expect(result).toBe("initial"); | |
| 103 | + }); | |
| 104 | + | |
| 105 | + it("should return undefined when all processing fails and no initial", async () => { | |
| 106 | + const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule); | |
| 107 | + mockProcessPromptOrRule.mockRejectedValue(new Error("processing failed")); | |
| 108 | + | |
| 109 | + const result = await processAndCombinePrompts(["bad"]); | |
| 110 | + | |
| 111 | + expect(result).toBeUndefined(); | |
| 112 | + }); | |
| 113 | + | |
| 114 | + it("should warn when processing fails", async () => { | |
| 115 | + const mockProcessPromptOrRule = vi.mocked(args.processPromptOrRule); | |
| 116 | + mockProcessPromptOrRule.mockRejectedValue(new Error("test error")); | |
| 117 | + | |
| 118 | + const { logger } = await import("./logger.js"); | |
| 119 | + | |
| 120 | + await processAndCombinePrompts(["bad-prompt"]); | |
| 121 | + | |
| 122 | + expect(logger.warn).toHaveBeenCalledWith( | |
| 123 | + 'Failed to process prompt "bad-prompt": test error', | |
| 124 | + ); | |
| 125 | + }); | |
| 126 | + }); | |
| 127 | +}); |
added extensions/cli/src/util/promptProcessor.ts +38 −0
| @@ -0,0 +1,38 @@ | ||
| 1 | +import { processPromptOrRule } from "../args.js"; | |
| 2 | + | |
| 3 | +import { logger } from "./logger.js"; | |
| 4 | + | |
| 5 | +/** | |
| 6 | + * Process additional prompts from --prompt flags and combine with initial prompt | |
| 7 | + * @param additionalPrompts - Array of prompt specifications to process | |
| 8 | + * @param initialPrompt - Optional initial prompt to combine with | |
| 9 | + * @returns Combined prompt string or undefined if no prompts | |
| 10 | + */ | |
| 11 | +export async function processAndCombinePrompts( | |
| 12 | + additionalPrompts?: string[], | |
| 13 | + initialPrompt?: string, | |
| 14 | +): Promise<string | undefined> { | |
| 15 | + if (!additionalPrompts || additionalPrompts.length === 0) { | |
| 16 | + return initialPrompt; | |
| 17 | + } | |
| 18 | + | |
| 19 | + const processedPrompts: string[] = []; | |
| 20 | + | |
| 21 | + for (const promptSpec of additionalPrompts) { | |
| 22 | + try { | |
| 23 | + const processed = await processPromptOrRule(promptSpec); | |
| 24 | + processedPrompts.push(processed); | |
| 25 | + } catch (error: any) { | |
| 26 | + logger.warn(`Failed to process prompt "${promptSpec}": ${error.message}`); | |
| 27 | + } | |
| 28 | + } | |
| 29 | + | |
| 30 | + if (processedPrompts.length === 0) { | |
| 31 | + return initialPrompt; | |
| 32 | + } | |
| 33 | + | |
| 34 | + const combinedPrompts = processedPrompts.join("\n\n"); | |
| 35 | + return initialPrompt | |
| 36 | + ? `${combinedPrompts}\n\n${initialPrompt}` | |
| 37 | + : combinedPrompts; | |
| 38 | +} |