Skip to content
Merged
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
12 changes: 12 additions & 0 deletions apps/web/src/components/chat/MessagesTimeline.logic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
resolveAssistantMessageCopyState,
type MessagesTimelineRow,
workEntryDisplayLabel,
workEntryReadOutput,
} from "./MessagesTimeline.logic";
import { workEntryIconName } from "./TimelineWorkEntryRow.logic";

Expand Down Expand Up @@ -5158,3 +5159,14 @@ describe("isTimelineMinimapTurnVisible", () => {
expect(isTimelineMinimapTurnVisible(10, 500, null, null)).toBe(false);
});
});

describe("workEntryReadOutput", () => {
it("joins relative paths to the workspace root but keeps home paths as written", () => {
expect(
workEntryReadOutput(
{ changedFiles: ["src/app.ts", "~/.claude/CLAUDE.md", "~\\.gitconfig"] },
"/workspace/t3code",
),
).toBe("/workspace/t3code/src/app.ts\n~/.claude/CLAUDE.md\n~/.gitconfig");
});
});
4 changes: 2 additions & 2 deletions apps/web/src/components/chat/MessagesTimeline.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import {
formatReadToolLabel,
formatSearchToolLabel,
} from "@t3tools/shared/toolActivityCopy";
import { isWindowsAbsolutePath } from "@t3tools/shared/path";
import { isHostPath } from "@t3tools/shared/path";

export function timelineEntryRunId(entry: TimelineEntry): RunId | null {
if (entry.kind === "message") {
Expand Down Expand Up @@ -231,7 +231,7 @@ export function workEntryReadOutput(
workEntryReadRawPaths(entry as WorkLogEntry)
.map((path) => {
const trimmed = path.trim().replaceAll("\\", "/");
if (!workspaceRoot || trimmed.startsWith("/") || isWindowsAbsolutePath(trimmed)) {
if (!workspaceRoot || isHostPath(trimmed)) {
return trimmed;
}
const root = workspaceRoot.replaceAll("\\", "/").replace(/\/+$/, "");
Expand Down
9 changes: 9 additions & 0 deletions apps/web/src/filePathDisplay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ describe("formatWorkspaceRelativePath", () => {
);
expect(formatWorkspaceRelativePath("src/app.ts", workspaceRoot)).toBe("t3code/src/app.ts");
});

it("keeps home paths as written instead of labelling them as workspace paths", () => {
expect(formatWorkspaceRelativePath("~/.claude/CLAUDE.md", "/workspace/t3code")).toBe(
"~/.claude/CLAUDE.md",
);
expect(formatWorkspaceRelativePath("~\\.claude\\CLAUDE.md:3", "C:\\dev\\t3code")).toBe(
"~/.claude/CLAUDE.md:3",
);
});
});
3 changes: 2 additions & 1 deletion apps/web/src/filePathDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { pipe } from "effect/Function";
import {
fileBasename,
stripSlashPrefixedWindowsDrive,
isHostPath,
isWindowsAbsolutePath,
} from "@t3tools/shared/path";
import { formatFilePathPosition, splitFilePathPosition } from "@t3tools/shared/fileLinks";
Expand Down Expand Up @@ -46,7 +47,7 @@ export function formatWorkspaceRelativePath(
} else if (pathForCompare.startsWith(workspaceWithSeparator)) {
const relativeSuffix = normalizedPath.slice(normalizedWorkspaceRoot.length + 1);
displayPath = `${workspaceLabel}/${relativeSuffix}`;
} else if (!normalizedPath.startsWith("/") && !isWindowsAbsolutePath(normalizedPath)) {
} else if (!isHostPath(normalizedPath)) {
const relativePath = stripRelativePrefixes(normalizedPath);
displayPath = pathForCompare.startsWith(workspaceLabelWithSeparator)
? normalizedPath
Expand Down
115 changes: 115 additions & 0 deletions scripts/scenarios/home-path-tool-rows-show-as-written.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// @effect-diagnostics nodeBuiltinImport:off -- The scenario stages a local ACP executable.
import * as NodeFSP from "node:fs/promises";
import * as NodePath from "node:path";

import { expect } from "e2e";

import { T3_HOME } from "../e2e.config.ts";
import { makeState, runPromise, test, WEB } from "./t3.ts";

const HOME_PATH = "~/.claude/CLAUDE.md";
const REPLY = "Updated your global instructions.";
const ACP = `
import { createInterface } from "node:readline";

const sessionId = "home-path-scenario";
const path = ${JSON.stringify(HOME_PATH)};
const send = (message) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", ...message }) + "\\n");
const update = (value) => send({ method: "session/update", params: { sessionId, update: value } });
for await (const line of createInterface({ input: process.stdin })) {
const { id, method } = JSON.parse(line);
if (id === undefined) continue;
if (method === "initialize") {
send({ id, result: { protocolVersion: 1, agentCapabilities: {}, authMethods: [] } });
} else if (method === "session/new") {
send({ id, result: { sessionId } });
} else if (method === "session/prompt") {
update({ sessionUpdate: "tool_call", toolCallId: "read", kind: "read", title: "Read", status: "pending", rawInput: { path } });
update({
sessionUpdate: "tool_call_update",
toolCallId: "read",
status: "completed",
content: [{ type: "content", content: { type: "text", text: "# Global instructions" } }],
});
update({
sessionUpdate: "tool_call",
toolCallId: "edit",
kind: "edit",
title: "Edit global instructions",
status: "completed",
content: [{
type: "diff",
path,
oldText: "# Global instructions\\n",
newText: "# Global instructions\\nPrefer small diffs.\\n",
changes: [{ operation: "update", path }],
}],
});
update({ sessionUpdate: "agent_message_chunk", content: { type: "text", text: ${JSON.stringify(REPLY)} } });
send({ id, result: { stopReason: "end_turn" } });
} else {
send({ id, error: { code: -32601, message: "Method not found" } });
}
}
`;

test(
"Files an agent read and edited in the home folder show their ~/ paths, not paths under the project",
WEB,
async ({ t3, app, screen }) => {
const project = await t3.project("demo");
const script = NodePath.join(project, "home-path-acp.mjs");
const settingsPath = NodePath.join(T3_HOME, "userdata/settings.json");
const originalSettings = await NodeFSP.readFile(settingsPath, "utf8");
const settings = JSON.parse(originalSettings);
await NodeFSP.writeFile(script, ACP);
settings.providerInstances["home-path-agent"] = {
driver: "acpRegistry",
displayName: "Home path agent",
enabled: true,
config: { source: "local", commandPath: process.execPath, commandArgs: [script] },
};
try {
await NodeFSP.writeFile(settingsPath, JSON.stringify(settings));
const { cli } = makeState(T3_HOME);
// The watcher reloads settings asynchronously. Retry only before a thread was created.
let threadId: string | undefined;
for (let attempt = 0; attempt < 8 && threadId === undefined; attempt++) {
const started = await runPromise(
cli(
[
"thread",
"start",
project,
"Tidy up my global instructions",
"--title",
"Home path tools",
"--provider",
"home-path-agent",
"--model",
"default",
"--wait",
"--json",
],
[0, 1],
),
);
if (!started.stdout.includes("threadId")) continue;
threadId = (JSON.parse(started.stdout) as { threadId: string }).threadId;
}
if (threadId === undefined) throw new Error("Could not start the home path turn.");

await t3.open({ threadId });
await screen.getByText(REPLY, { exact: true }).waitFor({ timeout: 60_000 });
await screen.getByRole("button", "Worked for", { exact: false }).tap();
await screen.getByRole("button", "Read 1 file and changed 1 file").tap();
await screen.getByRole("button", /^Read .*CLAUDE\.md/).tap();
await screen.getByText('"# Global instructions"', { exact: true }).waitFor();
await app.screenshot("read-and-edit-rows");
await expect(screen.getByText("/~/", { exact: false })).toHaveCount(0);
await expect(screen.getByText(HOME_PATH, { exact: true })).toHaveCount(2);
} finally {
await NodeFSP.writeFile(settingsPath, originalSettings);
}
},
);
Loading