-
Notifications
You must be signed in to change notification settings - Fork 246
Add CLI command to send task input #423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
finallylly
wants to merge
6
commits into
cline:main
Choose a base branch
from
finallylly:feat/task-send-cli
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+291
−0
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
84f14ab
Add CLI task send command
finallylly 8a9fa3c
Handle task send stdin edge cases
finallylly faa145b
Merge branch 'main' into feat/task-send-cli
finallylly 23bef76
Merge branch 'main' into feat/task-send-cli
finallylly b54f6fd
Merge branch 'main' into feat/task-send-cli
finallylly ee22b42
Merge branch 'main' into feat/task-send-cli
finallylly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| import { Command } from "commander"; | ||
| import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { registerTaskCommand } from "../../src/commands/task"; | ||
|
|
||
| const sendTaskSessionInput = vi.fn(); | ||
| const projectsAdd = vi.fn(); | ||
|
|
||
| vi.mock("@trpc/client", () => ({ | ||
| createTRPCProxyClient: vi.fn(() => ({ | ||
| projects: { | ||
| add: { | ||
| mutate: projectsAdd, | ||
| }, | ||
| }, | ||
| runtime: { | ||
| sendTaskSessionInput: { | ||
| mutate: sendTaskSessionInput, | ||
| }, | ||
| }, | ||
| })), | ||
| httpBatchLink: vi.fn((input: unknown) => input), | ||
| })); | ||
|
|
||
| vi.mock("../../src/state/workspace-state", () => ({ | ||
| loadWorkspaceContext: vi.fn(async (repoPath: string) => ({ | ||
| repoPath, | ||
| workspaceId: "workspace-1", | ||
| statePath: `${repoPath}/.cline/kanban/workspaces/workspace-1`, | ||
| git: { | ||
| currentBranch: "main", | ||
| defaultBranch: "main", | ||
| branches: ["main"], | ||
| }, | ||
| })), | ||
| mutateWorkspaceState: vi.fn(), | ||
| })); | ||
|
|
||
| function createProgram(): Command { | ||
| const program = new Command(); | ||
| program.exitOverride(); | ||
| program.configureOutput({ | ||
| writeErr: () => {}, | ||
| writeOut: () => {}, | ||
| }); | ||
| registerTaskCommand(program); | ||
| return program; | ||
| } | ||
|
|
||
| describe("task command", () => { | ||
| let stdout = ""; | ||
| let originalWrite: typeof process.stdout.write; | ||
|
|
||
| beforeEach(() => { | ||
| stdout = ""; | ||
| originalWrite = process.stdout.write; | ||
| process.stdout.write = ((chunk: string | Uint8Array) => { | ||
| stdout += chunk.toString(); | ||
| return true; | ||
| }) as typeof process.stdout.write; | ||
| projectsAdd.mockResolvedValue({ | ||
| ok: true, | ||
| project: { | ||
| id: "workspace-1", | ||
| }, | ||
| }); | ||
| sendTaskSessionInput.mockResolvedValue({ | ||
| ok: true, | ||
| summary: { | ||
| agentId: "claude", | ||
| state: "running", | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| process.stdout.write = originalWrite; | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it("submits terminal task input with a carriage return", async () => { | ||
| await createProgram().parseAsync( | ||
| ["task", "send", "--task-id", "task-1", "--text", "Continue", "--project-path", "/repo"], | ||
| { from: "user" }, | ||
| ); | ||
|
|
||
| expect(sendTaskSessionInput).toHaveBeenCalledTimes(2); | ||
| expect(sendTaskSessionInput).toHaveBeenNthCalledWith(1, { | ||
| appendNewline: false, | ||
| taskId: "task-1", | ||
| text: "Continue", | ||
| }); | ||
| expect(sendTaskSessionInput).toHaveBeenNthCalledWith(2, { | ||
| appendNewline: false, | ||
| taskId: "task-1", | ||
| text: "\r", | ||
| }); | ||
| expect(JSON.parse(stdout)).toMatchObject({ | ||
| ok: true, | ||
| submitted: true, | ||
| taskId: "task-1", | ||
| }); | ||
| }); | ||
|
|
||
| it("can type terminal task input without submitting", async () => { | ||
| await createProgram().parseAsync( | ||
| ["task", "send", "--task-id", "task-1", "--text", "Continue", "--project-path", "/repo", "--no-submit"], | ||
| { from: "user" }, | ||
| ); | ||
|
|
||
| expect(sendTaskSessionInput).toHaveBeenCalledTimes(1); | ||
| expect(sendTaskSessionInput).toHaveBeenCalledWith({ | ||
| appendNewline: false, | ||
| taskId: "task-1", | ||
| text: "Continue", | ||
| }); | ||
| expect(JSON.parse(stdout)).toMatchObject({ | ||
| ok: true, | ||
| submitted: false, | ||
| taskId: "task-1", | ||
| }); | ||
| }); | ||
|
|
||
| it("does not send a carriage return after Cline task input", async () => { | ||
| sendTaskSessionInput.mockResolvedValue({ | ||
| ok: true, | ||
| summary: { | ||
| agentId: "cline", | ||
| state: "running", | ||
| }, | ||
| }); | ||
|
|
||
| await createProgram().parseAsync( | ||
| ["task", "send", "--task-id", "task-1", "--text", "Continue", "--project-path", "/repo"], | ||
| { from: "user" }, | ||
| ); | ||
|
|
||
| expect(sendTaskSessionInput).toHaveBeenCalledTimes(1); | ||
| expect(sendTaskSessionInput).toHaveBeenCalledWith({ | ||
| appendNewline: false, | ||
| taskId: "task-1", | ||
| text: "Continue", | ||
| }); | ||
| expect(JSON.parse(stdout)).toMatchObject({ | ||
| ok: true, | ||
| submitted: true, | ||
| taskId: "task-1", | ||
| }); | ||
| }); | ||
|
|
||
| it("trims one trailing newline from stdin input", async () => { | ||
| const originalIsTty = process.stdin.isTTY; | ||
| const originalAsyncIterator = process.stdin[Symbol.asyncIterator]; | ||
| Object.defineProperty(process.stdin, "isTTY", { | ||
| configurable: true, | ||
| value: false, | ||
| }); | ||
| process.stdin[Symbol.asyncIterator] = async function* () { | ||
| yield Buffer.from("Continue\n"); | ||
| }; | ||
|
|
||
| try { | ||
| await createProgram().parseAsync(["task", "send", "--task-id", "task-1", "--project-path", "/repo"], { | ||
| from: "user", | ||
| }); | ||
| } finally { | ||
| Object.defineProperty(process.stdin, "isTTY", { | ||
| configurable: true, | ||
| value: originalIsTty, | ||
| }); | ||
| process.stdin[Symbol.asyncIterator] = originalAsyncIterator; | ||
| } | ||
|
|
||
| expect(sendTaskSessionInput).toHaveBeenNthCalledWith(1, { | ||
| appendNewline: false, | ||
| taskId: "task-1", | ||
| text: "Continue", | ||
| }); | ||
| expect(sendTaskSessionInput).toHaveBeenNthCalledWith(2, { | ||
| appendNewline: false, | ||
| taskId: "task-1", | ||
| text: "\r", | ||
| }); | ||
| }); | ||
|
|
||
| it("rejects an empty text option", async () => { | ||
| await createProgram().parseAsync( | ||
| ["task", "send", "--task-id", "task-1", "--text", "", "--project-path", "/repo"], | ||
| { from: "user" }, | ||
| ); | ||
|
|
||
| expect(sendTaskSessionInput).not.toHaveBeenCalled(); | ||
| expect(JSON.parse(stdout)).toMatchObject({ | ||
| ok: false, | ||
| error: expect.stringContaining("--text value cannot be empty"), | ||
| }); | ||
| expect(process.exitCode).toBe(1); | ||
| process.exitCode = undefined; | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.