diff --git a/.github/workflows/pr-description.yml.disabled b/.github/workflows/pr-description.yml.disabled index 95d9f7744..24e87c4dd 100644 --- a/.github/workflows/pr-description.yml.disabled +++ b/.github/workflows/pr-description.yml.disabled @@ -53,7 +53,7 @@ jobs: - name: Analyze PR with Continue id: analyze run: | - continue-cli --headless --assistant "starter/nextjs-assistant" "$(cat prompt.txt)" > analysis.txt + continue-cli -p --assistant "starter/nextjs-assistant" "$(cat prompt.txt)" > analysis.txt echo "analysis_file=analysis.txt" >> $GITHUB_OUTPUT env: ## TODO: This needs to be set on the repo diff --git a/.github/workflows/review.yaml b/.github/workflows/review.yaml index bb33f2aaa..f86791437 100644 --- a/.github/workflows/review.yaml +++ b/.github/workflows/review.yaml @@ -25,6 +25,6 @@ jobs: npm run build - name: Run Continue CLI - run: npm run start -- --config nate/default-assistant --headless "Please review the last changes to this codebase and provide some feedback. Then, if the changes had problems that indicate they should not be merged into production, then please call the 'exit' tool to fail the GitHub Action." + run: npm run start -- --config nate/default-assistant -p "Please review the last changes to this codebase and provide some feedback. Then, if the changes had problems that indicate they should not be merged into production, then please call the 'exit' tool to fail the GitHub Action." env: CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }} diff --git a/.vscode/launch.json b/.vscode/launch.json index c1b7d0175..5b8b7d2e1 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -65,7 +65,7 @@ "program": "${workspaceFolder}/dist/index.js", "preLaunchTask": "npm: build", "args": [ - "--headless", + "-p", "--config", "nate/default-assistant", "--prompt", diff --git a/README.md b/README.md index 4ba9e0ca7..210f1e035 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ cn ### Headless Mode ```bash -cn --headless "Generate a conventional commit name for the current git changes." +cn -p "Generate a conventional commit name for the current git changes." ``` ### Session Management @@ -38,12 +38,12 @@ Each terminal window maintains its own separate session, so you can have multipl cn --resume --config my-assistant # Resume session in headless mode -cn --resume --headless +cn --resume -p ``` ## Command Line Options -- `--headless`: Run in headless mode (no TUI) +- `-p`: Run in headless mode (no TUI) - `--config `: Specify assistant configuration path - `--resume`: Resume the last session for this terminal - ``: Optional prompt to start with @@ -51,8 +51,9 @@ cn --resume --headless ## Session Storage Sessions are stored in `~/.continue-cli/sessions/` and are automatically managed per terminal window using environment variables like: + - `TERM_SESSION_ID` -- `SSH_TTY` +- `SSH_TTY` - `TMUX` - `STY` diff --git a/src/args.test.ts b/src/args.test.ts index 4ebb8822b..3d7c64baa 100644 --- a/src/args.test.ts +++ b/src/args.test.ts @@ -1,11 +1,11 @@ -import { parseArgs } from './args.js'; +import { parseArgs } from "./args.js"; -describe('parseArgs', () => { +describe("parseArgs", () => { const originalArgv = process.argv; beforeEach(() => { // Reset process.argv before each test - process.argv = ['node', 'script.js']; + process.argv = ["node", "script.js"]; }); afterAll(() => { @@ -13,63 +13,69 @@ describe('parseArgs', () => { process.argv = originalArgv; }); - it('should return default values when no arguments provided', () => { + it("should return default values when no arguments provided", () => { const result = parseArgs(); expect(result).toEqual({ isHeadless: false, }); }); - it('should set isHeadless to true when --headless flag is present', () => { - process.argv = ['node', 'script.js', '--headless']; + it("should set isHeadless to true when --print flag is present", () => { + process.argv = ["node", "script.js", "--print"]; const result = parseArgs(); expect(result.isHeadless).toBe(true); }); - it('should set resume to true when --resume flag is present', () => { - process.argv = ['node', 'script.js', '--resume']; + it("should set isHeadless to true when -p flag is present", () => { + process.argv = ["node", "script.js", "-p"]; + const result = parseArgs(); + expect(result.isHeadless).toBe(true); + }); + + it("should set resume to true when --resume flag is present", () => { + process.argv = ["node", "script.js", "--resume"]; const result = parseArgs(); expect(result.resume).toBe(true); }); - it('should set readonly to true when --readonly flag is present', () => { - process.argv = ['node', 'script.js', '--readonly']; + it("should set readonly to true when --readonly flag is present", () => { + process.argv = ["node", "script.js", "--readonly"]; const result = parseArgs(); expect(result.readonly).toBe(true); }); - it('should set noTools to true when --no-tools flag is present', () => { - process.argv = ['node', 'script.js', '--no-tools']; + it("should set noTools to true when --no-tools flag is present", () => { + process.argv = ["node", "script.js", "--no-tools"]; const result = parseArgs(); expect(result.noTools).toBe(true); }); - it('should parse config path from --config flag', () => { - process.argv = ['node', 'script.js', '--config', '/path/to/config.yaml']; + it("should parse config path from --config flag", () => { + process.argv = ["node", "script.js", "--config", "/path/to/config.yaml"]; const result = parseArgs(); - expect(result.configPath).toBe('/path/to/config.yaml'); + expect(result.configPath).toBe("/path/to/config.yaml"); }); - it('should parse single rule from --rule flag', () => { - process.argv = ['node', 'script.js', '--rule', 'my-rule']; + it("should parse single rule from --rule flag", () => { + process.argv = ["node", "script.js", "--rule", "my-rule"]; const result = parseArgs(); - expect(result.rules).toEqual(['my-rule']); + expect(result.rules).toEqual(["my-rule"]); }); - it('should parse multiple rules from multiple --rule flags', () => { - process.argv = ['node', 'script.js', '--rule', 'rule1', '--rule', 'rule2']; + it("should parse multiple rules from multiple --rule flags", () => { + process.argv = ["node", "script.js", "--rule", "rule1", "--rule", "rule2"]; const result = parseArgs(); - expect(result.rules).toEqual(['rule1', 'rule2']); + expect(result.rules).toEqual(["rule1", "rule2"]); }); - it('should parse prompt from last non-flag argument', () => { - process.argv = ['node', 'script.js', 'Hello world']; + it("should parse prompt from last non-flag argument", () => { + process.argv = ["node", "script.js", "Hello world"]; const result = parseArgs(); - expect(result.prompt).toBe('Hello world'); + expect(result.prompt).toBe("Hello world"); }); - it('should handle multiple flags together', () => { - process.argv = ['node', 'script.js', '--headless', '--readonly', '--resume']; + it("should handle multiple flags together", () => { + process.argv = ["node", "script.js", "--print", "--readonly", "--resume"]; const result = parseArgs(); expect(result).toEqual({ isHeadless: true, @@ -78,124 +84,164 @@ describe('parseArgs', () => { }); }); - it('should handle config flag with other flags', () => { - process.argv = ['node', 'script.js', '--config', 'config.yaml', '--headless']; + it("should handle config flag with other flags", () => { + process.argv = ["node", "script.js", "--config", "config.yaml", "--print"]; const result = parseArgs(); expect(result).toEqual({ isHeadless: true, - configPath: 'config.yaml', + configPath: "config.yaml", }); }); - it('should handle rule flag with other flags', () => { - process.argv = ['node', 'script.js', '--rule', 'my-rule', '--headless']; + it("should handle rule flag with other flags", () => { + process.argv = ["node", "script.js", "--rule", "my-rule", "--print"]; const result = parseArgs(); expect(result).toEqual({ isHeadless: true, - rules: ['my-rule'], + rules: ["my-rule"], }); }); - it('should handle prompt with flags', () => { - process.argv = ['node', 'script.js', '--headless', 'What is the weather?']; + it("should handle prompt with flags", () => { + process.argv = ["node", "script.js", "--print", "What is the weather?"]; const result = parseArgs(); expect(result).toEqual({ isHeadless: true, - prompt: 'What is the weather?', + prompt: "What is the weather?", }); }); - it('should handle config flag with prompt', () => { - process.argv = ['node', 'script.js', '--config', 'config.yaml', 'Test prompt']; + it("should handle config flag with prompt", () => { + process.argv = [ + "node", + "script.js", + "--config", + "config.yaml", + "Test prompt", + ]; const result = parseArgs(); expect(result).toEqual({ isHeadless: false, - configPath: 'config.yaml', - prompt: 'Test prompt', + configPath: "config.yaml", + prompt: "Test prompt", }); }); - it('should handle rule flag with prompt', () => { - process.argv = ['node', 'script.js', '--rule', 'my-rule', 'Test prompt']; + it("should handle rule flag with prompt", () => { + process.argv = ["node", "script.js", "--rule", "my-rule", "Test prompt"]; const result = parseArgs(); expect(result).toEqual({ isHeadless: false, - rules: ['my-rule'], - prompt: 'Test prompt', + rules: ["my-rule"], + prompt: "Test prompt", }); }); - it('should ignore config and rule flag values when extracting prompt', () => { - process.argv = ['node', 'script.js', '--config', 'config.yaml', '--rule', 'my-rule', 'actual-prompt']; + it("should ignore config and rule flag values when extracting prompt", () => { + process.argv = [ + "node", + "script.js", + "--config", + "config.yaml", + "--rule", + "my-rule", + "actual-prompt", + ]; const result = parseArgs(); - expect(result.prompt).toBe('actual-prompt'); - expect(result.configPath).toBe('config.yaml'); - expect(result.rules).toEqual(['my-rule']); + expect(result.prompt).toBe("actual-prompt"); + expect(result.configPath).toBe("config.yaml"); + expect(result.rules).toEqual(["my-rule"]); }); - it('should handle multiple non-flag arguments and use the last one as prompt', () => { - process.argv = ['node', 'script.js', 'first', 'second', 'third']; + it("should handle multiple non-flag arguments and use the last one as prompt", () => { + process.argv = ["node", "script.js", "first", "second", "third"]; const result = parseArgs(); - expect(result.prompt).toBe('third'); + expect(result.prompt).toBe("third"); }); - it('should handle complex argument combinations', () => { - process.argv = ['node', 'script.js', '--headless', '--config', 'my-config.yaml', '--rule', 'rule1', '--rule', 'rule2', '--readonly', '--resume', 'Complex prompt with spaces']; + it("should handle complex argument combinations", () => { + process.argv = [ + "node", + "script.js", + "--print", + "--config", + "my-config.yaml", + "--rule", + "rule1", + "--rule", + "rule2", + "--readonly", + "--resume", + "Complex prompt with spaces", + ]; const result = parseArgs(); expect(result).toEqual({ isHeadless: true, - configPath: 'my-config.yaml', - rules: ['rule1', 'rule2'], + configPath: "my-config.yaml", + rules: ["rule1", "rule2"], readonly: true, resume: true, - prompt: 'Complex prompt with spaces', + prompt: "Complex prompt with spaces", }); }); - it('should handle config flag without value', () => { - process.argv = ['node', 'script.js', '--config']; + it("should handle config flag without value", () => { + process.argv = ["node", "script.js", "--config"]; const result = parseArgs(); expect(result.configPath).toBeUndefined(); }); - it('should handle rule flag without value', () => { - process.argv = ['node', 'script.js', '--rule']; + it("should handle rule flag without value", () => { + process.argv = ["node", "script.js", "--rule"]; const result = parseArgs(); expect(result.rules).toEqual([]); }); - it('should handle config flag at the end without value', () => { - process.argv = ['node', 'script.js', '--headless', '--config']; + it("should handle config flag at the end without value", () => { + process.argv = ["node", "script.js", "--print", "--config"]; const result = parseArgs(); expect(result.isHeadless).toBe(true); expect(result.configPath).toBeUndefined(); }); - it('should handle rule flag at the end without value', () => { - process.argv = ['node', 'script.js', '--headless', '--rule']; + it("should handle rule flag at the end without value", () => { + process.argv = ["node", "script.js", "--print", "--rule"]; const result = parseArgs(); expect(result.isHeadless).toBe(true); expect(result.rules).toEqual([]); }); - it('should handle empty arguments array', () => { - process.argv = ['node', 'script.js']; + it("should handle empty arguments array", () => { + process.argv = ["node", "script.js"]; const result = parseArgs(); expect(result).toEqual({ isHeadless: false, }); }); - it('should handle flags with similar names', () => { - process.argv = ['node', 'script.js', '--no-tools', '--readonly']; + it("should handle flags with similar names", () => { + process.argv = ["node", "script.js", "--no-tools", "--readonly"]; const result = parseArgs(); expect(result.noTools).toBe(true); expect(result.readonly).toBe(true); }); - it('should handle multiple rules with complex combinations', () => { - process.argv = ['node', 'script.js', '--rule', 'file.txt', '--rule', 'owner/package', '--rule', 'direct string rule']; + it("should handle multiple rules with complex combinations", () => { + process.argv = [ + "node", + "script.js", + "--rule", + "file.txt", + "--rule", + "owner/package", + "--rule", + "direct string rule", + ]; const result = parseArgs(); - expect(result.rules).toEqual(['file.txt', 'owner/package', 'direct string rule']); + expect(result.rules).toEqual([ + "file.txt", + "owner/package", + "direct string rule", + ]); }); -}); \ No newline at end of file +}); diff --git a/src/args.ts b/src/args.ts index 75a7f8c58..169ccbc24 100644 --- a/src/args.ts +++ b/src/args.ts @@ -45,15 +45,23 @@ function loadRuleFromHub(slug: string): string { */ export function processRule(ruleSpec: string): string { // If it looks like a hub slug (contains / but doesn't start with . or /) - if (ruleSpec.includes("/") && !ruleSpec.startsWith(".") && !ruleSpec.startsWith("/")) { + if ( + ruleSpec.includes("/") && + !ruleSpec.startsWith(".") && + !ruleSpec.startsWith("/") + ) { return loadRuleFromHub(ruleSpec); } - + // If it looks like a file path (contains . or / or ends with common file extensions) - if (ruleSpec.includes(".") || ruleSpec.includes("/") || ruleSpec.includes("\\")) { + if ( + ruleSpec.includes(".") || + ruleSpec.includes("/") || + ruleSpec.includes("\\") + ) { return loadRuleFromFile(ruleSpec); } - + // Otherwise, treat it as direct string content return ruleSpec; } @@ -71,7 +79,7 @@ export function parseArgs(): CommandLineArgs { }; // Parse flags - if (args.includes("--headless")) { + if (args.includes("--print") || args.includes("-p")) { result.isHeadless = true; } @@ -114,7 +122,7 @@ export function parseArgs(): CommandLineArgs { const flagsWithValues = ["--config", "--rule"]; const nonFlagArgs = args.filter((arg, index) => { // Skip flags (starting with --) - if (arg.startsWith("--")) return false; + if (arg.startsWith("--") || arg === "-p") return false; // Skip flag values const prevArg = index > 0 ? args[index - 1] : ""; @@ -129,4 +137,4 @@ export function parseArgs(): CommandLineArgs { } return result; -} \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index 86486d402..f5a7eec13 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,23 +21,29 @@ const program = new Command(); program .name("cn") - .description("Continue CLI - AI-powered development assistant") + .description( + "Continue CLI - AI-powered development assistant. Starts an interactive session by default, use -p/--print for non-interactive output." + ) .version(getVersion()); // Root command - chat functionality (default) program .argument("[prompt]", "Optional prompt to send to the assistant") - .option("--headless", "Run in headless mode (non-interactive)") + .option("-p, --print", "Print response and exit (useful for pipes)") .option("--config ", "Path to configuration file") .option("--resume", "Resume from last session") .option("--readonly", "Only allow readonly tools") .option("--no-tools", "Disable all tools") - .option("--rule ", "Add a rule (can be a file path, hub slug, or string content). Can be specified multiple times.", + .option( + "--rule ", + "Add a rule (can be a file path, hub slug, or string content). Can be specified multiple times.", (value: string, previous: string[] | undefined) => { const array = Array.isArray(previous) ? previous : []; array.push(value); return array; - }, [] as string[]) + }, + [] as string[] + ) .action(async (prompt, options) => { await chat(prompt, options); }); @@ -58,4 +64,4 @@ program await logout(); }); -program.parse(); \ No newline at end of file +program.parse();