diff --git a/src/commands/remote.ts b/src/commands/remote.ts
index 63cabe6a8..54a45ad3e 100644
--- a/src/commands/remote.ts
+++ b/src/commands/remote.ts
@@ -6,6 +6,7 @@ import { telemetryService } from "../telemetry/telemetryService.js";
import { startRemoteTUIChat } from "../ui/index.js";
import { getRepoUrl } from "../util/git.js";
import { logger } from "../util/logger.js";
+import { readStdinSync } from "../util/stdin.js";
export async function remote(
prompt: string | undefined,
@@ -16,6 +17,22 @@ export async function remote(
branch?: string;
} = {},
) {
+ // Check if prompt should come from stdin instead of parameter
+ let actualPrompt = prompt;
+ if (prompt) {
+ // If prompt is provided, still check for stdin and combine them
+ const stdinInput = readStdinSync();
+ if (stdinInput) {
+ // Combine stdin and prompt argument - stdin comes first in XML block
+ actualPrompt = `\n${stdinInput}\n\n\n${prompt}`;
+ }
+ } else {
+ // Try to read from stdin (for piped input like: echo "hello" | cn remote -s)
+ const stdinInput = readStdinSync();
+ if (stdinInput) {
+ actualPrompt = stdinInput;
+ }
+ }
// If --url is provided, connect directly to that URL
if (options.url) {
if (options.start) {
@@ -41,7 +58,7 @@ export async function remote(
try {
// Start the TUI in remote mode
- await startRemoteTUIChat(options.url, prompt);
+ await startRemoteTUIChat(options.url, actualPrompt);
} finally {
telemetryService.stopActiveTime();
}
@@ -64,7 +81,7 @@ export async function remote(
const requestBody: any = {
repoUrl: getRepoUrl(),
name: `devbox-${Date.now()}`,
- prompt: prompt,
+ prompt: actualPrompt,
idempotencyKey: options.idempotencyKey,
};
@@ -123,7 +140,7 @@ export async function remote(
try {
// Start the TUI in remote mode (prompt is optional)
- await startRemoteTUIChat(remoteUrl, prompt);
+ await startRemoteTUIChat(remoteUrl, actualPrompt);
} finally {
telemetryService.stopActiveTime();
}
diff --git a/src/e2e/remote-stdin.test.ts b/src/e2e/remote-stdin.test.ts
new file mode 100644
index 000000000..ae8b43fb3
--- /dev/null
+++ b/src/e2e/remote-stdin.test.ts
@@ -0,0 +1,83 @@
+import { createTestContext, cleanupTestContext, runCLI } from "../test-helpers/cli-helpers.js";
+
+describe("E2E: Remote Command - Stdin Support", () => {
+ let context: any;
+
+ beforeEach(async () => {
+ context = await createTestContext();
+ });
+
+ afterEach(async () => {
+ await cleanupTestContext(context);
+ });
+
+ it("should work correctly when prompt is provided via stdin with remote -s flag", async () => {
+ const result = await runCLI(context, {
+ args: ["remote", "-s", "--url", "http://example.com"],
+ input: "Hello from stdin",
+ expectError: false,
+ timeout: 5000,
+ });
+
+ // Should succeed with direct URL connection
+ expect(result.exitCode).toBe(0);
+
+ // Should output JSON response for --start mode
+ const output = result.stdout;
+ expect(output).toContain('"status":"success"');
+ expect(output).toContain('"url":"http://example.com"');
+ expect(output).toContain('"mode":"direct_url"');
+ });
+
+ it("should combine stdin and command line prompt when both are provided", async () => {
+ const result = await runCLI(context, {
+ args: ["remote", "-s", "--url", "http://example.com", "Command line prompt"],
+ input: "Stdin input",
+ expectError: false,
+ timeout: 5000,
+ });
+
+ // Should succeed with direct URL connection
+ expect(result.exitCode).toBe(0);
+
+ // Should output JSON response for --start mode
+ const output = result.stdout;
+ expect(output).toContain('"status":"success"');
+ expect(output).toContain('"url":"http://example.com"');
+ expect(output).toContain('"mode":"direct_url"');
+ });
+
+ it("should work with just command line prompt (no stdin)", async () => {
+ const result = await runCLI(context, {
+ args: ["remote", "-s", "--url", "http://example.com", "Just command line"],
+ expectError: false,
+ timeout: 5000,
+ });
+
+ // Should succeed with direct URL connection
+ expect(result.exitCode).toBe(0);
+
+ // Should output JSON response for --start mode
+ const output = result.stdout;
+ expect(output).toContain('"status":"success"');
+ expect(output).toContain('"url":"http://example.com"');
+ expect(output).toContain('"mode":"direct_url"');
+ });
+
+ it("should work with no prompt at all", async () => {
+ const result = await runCLI(context, {
+ args: ["remote", "-s", "--url", "http://example.com"],
+ expectError: false,
+ timeout: 5000,
+ });
+
+ // Should succeed with direct URL connection
+ expect(result.exitCode).toBe(0);
+
+ // Should output JSON response for --start mode
+ const output = result.stdout;
+ expect(output).toContain('"status":"success"');
+ expect(output).toContain('"url":"http://example.com"');
+ expect(output).toContain('"mode":"direct_url"');
+ });
+});
\ No newline at end of file
diff --git a/src/tools/edit.test.ts b/src/tools/edit.test.ts
index 1ad8f7d23..088738d29 100644
--- a/src/tools/edit.test.ts
+++ b/src/tools/edit.test.ts
@@ -170,7 +170,7 @@ describe("editTool", () => {
const result = await editTool.run(args);
- expect(result).toBe(`Successfully edited ${testFilePath}`);
+ expect(result).toBe(`Successfully edited ${testFilePath}\nDiff:\nmocked diff`);
expect(fs.writeFileSync).toHaveBeenCalledWith(testFilePath, newContent, "utf-8");
});
diff --git a/src/tools/edit.ts b/src/tools/edit.ts
index 9b073adfe..f45acf6cc 100644
--- a/src/tools/edit.ts
+++ b/src/tools/edit.ts
@@ -178,7 +178,10 @@ parameter is useful if you want to rename a variable for instance.`,
);
}
- return `Successfully edited ${args.file_path}`;
+ // Generate diff for result display
+ const diff = generateDiff(args.oldContent, args.newContent, args.file_path);
+
+ return `Successfully edited ${args.file_path}\nDiff:\n${diff}`;
} catch (error) {
throw new Error(
`Error: failed to edit ${args.file_path}: ${
diff --git a/src/tools/multiEdit.test.ts b/src/tools/multiEdit.test.ts
index e4547a5e7..39b43642b 100644
--- a/src/tools/multiEdit.test.ts
+++ b/src/tools/multiEdit.test.ts
@@ -327,7 +327,7 @@ describe("multiEditTool", () => {
const result = await multiEditTool.run(args);
- expect(result).toBe(`Successfully edited ${testFilePath} with 1 edit`);
+ expect(result).toBe(`Successfully edited ${testFilePath} with 1 edit\nDiff:\nmocked diff`);
expect(fs.writeFileSync).toHaveBeenCalledWith(testFilePath, newContent, "utf-8");
});
@@ -342,7 +342,7 @@ describe("multiEditTool", () => {
const result = await multiEditTool.run(args);
- expect(result).toBe(`Successfully edited ${testFilePath} with 3 edits`);
+ expect(result).toBe(`Successfully edited ${testFilePath} with 3 edits\nDiff:\nmocked diff`);
});
it("should return correct message for new file creation", async () => {
@@ -356,7 +356,7 @@ describe("multiEditTool", () => {
const result = await multiEditTool.run(args);
- expect(result).toBe(`Successfully created /tmp/new-file.txt with 1 edit`);
+ expect(result).toBe(`Successfully created /tmp/new-file.txt with 1 edit\nDiff:\nmocked diff`);
});
it("should throw error if file write fails", async () => {
diff --git a/src/tools/multiEdit.ts b/src/tools/multiEdit.ts
index 2e5ac024f..bc7b8298a 100644
--- a/src/tools/multiEdit.ts
+++ b/src/tools/multiEdit.ts
@@ -309,8 +309,11 @@ If you want to create a new file, use:
);
}
+ // Generate diff for result display
+ const diff = generateDiff(args.originalContent, args.newContent, args.file_path);
+
const action = args.isCreatingNewFile ? "created" : "edited";
- return `Successfully ${action} ${args.file_path} with ${args.editCount} edit${args.editCount === 1 ? "" : "s"}`;
+ return `Successfully ${action} ${args.file_path} with ${args.editCount} edit${args.editCount === 1 ? "" : "s"}\nDiff:\n${diff}`;
} catch (error) {
throw new Error(
`Error: failed to edit ${args.file_path}: ${
diff --git a/src/tools/writeFile.ts b/src/tools/writeFile.ts
index 2d3ad8377..f1404386f 100644
--- a/src/tools/writeFile.ts
+++ b/src/tools/writeFile.ts
@@ -139,7 +139,10 @@ export const writeFileTool: Tool = {
);
}
- return `Successfully wrote to file: ${args.filepath}`;
+ // Generate diff for result display
+ const diff = generateDiff(oldContent, args.content, args.filepath);
+
+ return `Successfully wrote to file: ${args.filepath}\nDiff:\n${diff}`;
} else {
// New file creation - count all lines as added
const lineCount = args.content.split("\n").length;
diff --git a/src/ui/ToolResultSummary.tsx b/src/ui/ToolResultSummary.tsx
index 4c7a439f8..c608d298b 100644
--- a/src/ui/ToolResultSummary.tsx
+++ b/src/ui/ToolResultSummary.tsx
@@ -43,9 +43,9 @@ const ToolResultSummary: React.FC = ({
);
}
- // Handle Write/Edit with diff specially
+ // Handle Write/Edit/MultiEdit with diff specially
if (
- (toolName === "Write" || toolName === "Edit") &&
+ (toolName === "Write" || toolName === "Edit" || toolName === "MultiEdit") &&
content.includes("Diff:\n")
) {
const diffSection = content.split("Diff:\n")[1];
@@ -56,6 +56,8 @@ const ToolResultSummary: React.FC = ({
⎿
{toolName === "Edit"
+ ? " File edited successfully"
+ : toolName === "MultiEdit"
? " File edited successfully"
: " File written successfully"}
@@ -147,6 +149,9 @@ const ToolResultSummary: React.FC = ({
case "Edit":
return "File edited successfully";
+ case "MultiEdit":
+ return "File edited successfully";
+
case "List":
return `Listed ${lines} ${lines === 1 ? "item" : "items"}`;