Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/assets/v11-review-ui-after.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/v11-review-ui-before.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/v11-review-ui-interaction.mp4
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dev": "node scripts/dev-server.mjs",
"postinstall": "node scripts/fix-node-pty-permissions.mjs",
"start": "node dist/cli.js serve",
"test": "tsx src/user-config.test.ts && tsx src/config.test.ts && tsx src/onboarding.test.ts && tsx src/cli-workspace.test.ts && tsx src/request-meta.test.ts && tsx src/incoming-artifacts.test.ts && tsx src/artifact-download.test.ts && tsx src/ui/card-types.test.ts && tsx src/ui/patch-display.test.ts && tsx src/ui/tool-display.test.ts && tsx src/apply-patch.test.ts && tsx src/process-platform.test.ts && tsx src/process-sessions.test.ts && tsx src/mcp-sessions.test.ts && tsx src/server-shutdown.test.ts && tsx src/local-agent-config.test.ts && tsx src/local-agent-catalog.test.ts && tsx src/local-agent-presentation.test.ts && tsx src/local-agent-runtime.test.ts && tsx src/local-agent-daemon-lifecycle.test.ts && tsx src/local-agent-daemon-protocol.test.ts && tsx src/local-agent-daemon.test.ts && tsx src/local-agent-codex.test.ts && tsx src/local-agent-opencode.test.ts && tsx src/local-agent-acp.test.ts && tsx src/local-agent-grok.test.ts && tsx src/local-agent-pi-sandbox.test.ts && tsx src/local-agent-pi.test.ts && tsx src/local-agent-claude.test.ts && tsx src/local-agent-adapters.test.ts && tsx src/local-agent-availability.test.ts && tsx src/local-agent-profiles.test.ts && tsx src/local-agent-targets.test.ts && tsx src/local-agent-store.test.ts && tsx src/local-agent-manager.test.ts && tsx src/roots.test.ts && tsx src/skills.test.ts && tsx src/workspaces.test.ts && tsx src/workspace-conversation.test.ts && tsx src/review-checkpoints.test.ts && tsx src/server.test.ts && tsx src/oauth-store.test.ts && tsx src/cli.test.ts",
"test": "tsx src/user-config.test.ts && tsx src/config.test.ts && tsx src/onboarding.test.ts && tsx src/cli-workspace.test.ts && tsx src/request-meta.test.ts && tsx src/incoming-artifacts.test.ts && tsx src/artifact-download.test.ts && tsx src/ui/card-types.test.ts && tsx src/ui/patch-display.test.ts && tsx src/apply-patch.test.ts && tsx src/process-platform.test.ts && tsx src/process-sessions.test.ts && tsx src/mcp-sessions.test.ts && tsx src/server-shutdown.test.ts && tsx src/local-agent-config.test.ts && tsx src/local-agent-catalog.test.ts && tsx src/local-agent-presentation.test.ts && tsx src/local-agent-runtime.test.ts && tsx src/local-agent-daemon-lifecycle.test.ts && tsx src/local-agent-daemon-protocol.test.ts && tsx src/local-agent-daemon.test.ts && tsx src/local-agent-codex.test.ts && tsx src/local-agent-opencode.test.ts && tsx src/local-agent-acp.test.ts && tsx src/local-agent-grok.test.ts && tsx src/local-agent-pi-sandbox.test.ts && tsx src/local-agent-pi.test.ts && tsx src/local-agent-claude.test.ts && tsx src/local-agent-adapters.test.ts && tsx src/local-agent-availability.test.ts && tsx src/local-agent-profiles.test.ts && tsx src/local-agent-targets.test.ts && tsx src/local-agent-store.test.ts && tsx src/local-agent-manager.test.ts && tsx src/roots.test.ts && tsx src/skills.test.ts && tsx src/workspaces.test.ts && tsx src/workspace-conversation.test.ts && tsx src/review-checkpoints.test.ts && tsx src/server.test.ts && tsx src/oauth-store.test.ts && tsx src/cli.test.ts",
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"keywords": [],
Expand Down
15 changes: 0 additions & 15 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import {
logToolCall,
resultOutputSchema,
textBlock,
textSummary,
workspaceAppDescriptorMeta,
} from "./tool-surfaces/shared.js";
import {
Expand Down Expand Up @@ -619,11 +618,6 @@ export function createMcpServer(
}
workspaces.markReadPathLoaded(workspace, readPath);

const summary = {
...textSummary(response.content),
offset: input.offset ?? 1,
limited: input.limit !== undefined,
};
logToolCall(config, {
tool: toolNames.read,
workspaceId,
Expand All @@ -634,15 +628,6 @@ export function createMcpServer(

return {
...response,
_meta: {
tool: toolNames.read,
card: {
workspaceId,
path: input.path,
summary,
payload: { content: response.content },
},
},
structuredContent: {
result: contentText(response.content),
},
Expand Down
60 changes: 1 addition & 59 deletions src/tool-surfaces/claude.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { existsSync } from "node:fs";
import * as z from "zod/v4";
import {
editFileTool,
Expand All @@ -15,15 +14,12 @@ import {
type ToolRegistrationContext,
} from "./types.js";
import {
contentLineCount,
contentText,
countDiffStats,
logFailedToolResponse,
logToolCall,
newFilePatch,
resultOutputSchema,
textBlock,
textSummary,
} from "./shared.js";

const CLAUDE_INSTRUCTIONS = `Use ${toolNames.read} for direct file reads, ${toolNames.shell} with command-line tools such as rg, find, ls, and tree for search and directory inspection, ${toolNames.edit} for targeted modifications, and ${toolNames.write} only for new files or complete rewrites. Use ${toolNames.shell} for tests, builds, git inspection, package scripts, and other commands, but do not create or modify files through shell commands. Shell commands run with the local user's authority and are not sandboxed; workspace validation only selects their initial working directory. Follow instructions returned by ${toolNames.openWorkspace}; read applicable instruction and skill files before working in their scope.`;
Expand Down Expand Up @@ -63,8 +59,7 @@ function registerClaudeMutationTools(context: ToolRegistrationContext): void {
async ({ workspaceId, ...input }) => {
const startedAt = performance.now();
const workspace = workspaces.getWorkspace(workspaceId);
const absolutePath = workspaces.resolvePath(workspace, input.path);
const overwritesExistingFile = existsSync(absolutePath);
workspaces.resolvePath(workspace, input.path);
const response = await writeFileTool(input, {
cwd: workspace.root,
root: workspace.root,
Expand All @@ -84,17 +79,6 @@ function registerClaudeMutationTools(context: ToolRegistrationContext): void {
return response;
}

// An aggregate review can show the real replacement diff. A new-file
// patch would misrepresent an overwrite as additions with no removals.
const patch = overwritesExistingFile
? undefined
: newFilePatch(input.path, input.content);
const stats = countDiffStats(patch);
const summary = {
...stats,
lines: contentLineCount(input.content),
characters: input.content.length,
};
logToolCall(config, {
tool: toolNames.write,
workspaceId,
Expand All @@ -105,18 +89,6 @@ function registerClaudeMutationTools(context: ToolRegistrationContext): void {

return {
...response,
_meta: {
tool: toolNames.write,
card: {
workspaceId,
path: input.path,
summary,
payload: {
content: response.content,
patch,
},
},
},
structuredContent: {
result: contentText(response.content),
},
Expand Down Expand Up @@ -178,10 +150,6 @@ function registerClaudeMutationTools(context: ToolRegistrationContext): void {
const stats = countDiffStats(
response.details?.patch ?? response.details?.diff,
);
const summary = {
...stats,
editCount: input.edits.length,
};
const editResultText = `Edited ${input.path} (+${stats.additions} -${stats.removals}).`;
const editContent = [textBlock(editResultText)];
logToolCall(config, {
Expand All @@ -194,18 +162,6 @@ function registerClaudeMutationTools(context: ToolRegistrationContext): void {

return {
content: editContent,
_meta: {
tool: toolNames.edit,
card: {
workspaceId,
path: input.path,
summary,
payload: {
diff: response.details?.diff,
patch: response.details?.patch,
},
},
},
structuredContent: {
status: "applied",
result: contentText(editContent),
Expand Down Expand Up @@ -274,11 +230,6 @@ function registerShellTool(context: ToolRegistrationContext): void {
return response;
}

const summary = {
command: input.command,
workingDirectory: workingDirectory ?? ".",
...textSummary(response.content),
};
logToolCall(config, {
tool: toolNames.shell,
workspaceId,
Expand All @@ -291,15 +242,6 @@ function registerShellTool(context: ToolRegistrationContext): void {

return {
...response,
_meta: {
tool: toolNames.shell,
card: {
workspaceId,
path: workingDirectory,
summary,
payload: { content: response.content },
},
},
structuredContent: {
result: contentText(response.content),
},
Expand Down
53 changes: 3 additions & 50 deletions src/tool-surfaces/codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
resultOutputSchema,
runLoggedToolOperation,
textBlock,
textSummary,
} from "./shared.js";

type CodexRegistration = (context: ToolRegistrationContext) => void;
Expand Down Expand Up @@ -57,27 +56,11 @@ function processOutputSchema(): z.ZodRawShape {
});
}

function processToolResponse(
tool: "exec_command" | "write_stdin",
workspaceId: string,
snapshot: ProcessSnapshot,
summary: Record<string, unknown>,
) {
function processToolResponse(snapshot: ProcessSnapshot) {
const result = processResult(snapshot);
const content = [textBlock(result)];
const outputSummary = textSummary(
snapshot.output ? [textBlock(snapshot.output)] : [],
);
return {
content,
_meta: {
tool,
card: {
workspaceId,
summary: { ...summary, ...outputSummary },
payload: { content },
},
},
structuredContent: {
result,
sessionId: snapshot.sessionId,
Expand Down Expand Up @@ -134,27 +117,9 @@ function registerApplyPatchTool(context: ToolRegistrationContext): void {
const paths = applied.files.map((file) => file.path).join(", ");
const result = `Applied patch to ${applied.files.length} file(s): ${paths}`;
const content = [textBlock(result)];
const displayPath =
applied.files.length === 1
? applied.files[0]?.path
: `${applied.files.length} files`;

return {
content,
_meta: {
tool: "apply_patch",
card: {
workspaceId,
path: displayPath,
summary: {
files: applied.files.length,
additions: applied.additions,
removals: applied.removals,
},
files: applied.files,
payload: { patch: applied.patch },
},
},
structuredContent: {
result,
additions: applied.additions,
Expand Down Expand Up @@ -265,13 +230,7 @@ function registerCodexProcessTools(context: ToolRegistrationContext): void {
},
);

return processToolResponse("exec_command", workspaceId, snapshot, {
command: cmd,
workingDirectory: workingDirectory ?? ".",
running: snapshot.running,
exitCode: snapshot.exitCode,
wallTimeMs: snapshot.wallTimeMs,
});
return processToolResponse(snapshot);
},
);

Expand Down Expand Up @@ -356,13 +315,7 @@ function registerCodexProcessTools(context: ToolRegistrationContext): void {
},
);

return processToolResponse("write_stdin", workspaceId, snapshot, {
sessionId,
charactersWritten: chars?.length ?? 0,
running: snapshot.running,
exitCode: snapshot.exitCode,
wallTimeMs: snapshot.wallTimeMs,
});
return processToolResponse(snapshot);
},
);
}
42 changes: 0 additions & 42 deletions src/tool-surfaces/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,6 @@ export function textBlock(text: string): ToolContent {
return { type: "text", text };
}

export function textSummary(content: ToolContent[]): {
lines: number;
characters: number;
} {
const text = contentText(content);
return {
lines: contentLineCount(text),
characters: text.length,
};
}

export function contentLineCount(content: string): number {
if (content.length === 0) return 0;
return content.endsWith("\n")
? content.slice(0, -1).split("\n").length
: content.split("\n").length;
}

export function countDiffStats(diff: string | undefined): DiffStats {
if (!diff) return { additions: 0, removals: 0 };

Expand All @@ -135,27 +117,3 @@ export function countDiffStats(diff: string | undefined): DiffStats {

return { additions, removals };
}

export function newFilePatch(path: string, content: string): string {
const lines =
content.length === 0
? []
: content.endsWith("\n")
? content.slice(0, -1).split("\n")
: content.split("\n");
const hunkLength = lines.length;
const hunkRange = hunkLength === 0 ? "+0,0" : `+1,${hunkLength}`;
const body = lines.map((line) => `+${line}`).join("\n");

return [
`diff --git a/${path} b/${path}`,
"new file mode 100644",
"index 0000000..0000000",
"--- /dev/null",
`+++ b/${path}`,
`@@ -0,0 ${hunkRange} @@`,
body,
]
.filter((line) => line.length > 0)
.join("\n");
}
Loading
Loading