fix(clients): stop repeating expanded commands (#9120)
Expanded command rows use a neutral Command label and keep the full command plus real output in the detail area. Claude Bash results now cross the wire as a bounded summary. Truncated Claude echoes and ACP echoes without a kind are dropped as synthetic. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
1 parent
cdbf324aa0
commit
083d4de5b0
11 files changed
+685
-115
No files matched your search
@@ -338,7 +338,8 @@ export function ThreadWorkLog(props: {
|
||||
const canExpand = row.canExpand;
|
||||
const fullDetail = expanded ? row.getFullDetail() : null;
|
||||
const viewedImagePath = workEntryViewedImagePath(row.workEntry);
|
||||
const displayText = row.detail ?? row.summary;
|
||||
const previewText = row.detail ?? row.summary;
|
||||
const displayText = expanded && row.workEntry.command?.trim() ? "Command" : previewText;
|
||||
const iconIsDestructive = row.icon === "alert" || row.icon === "warning";
|
||||
const failed = row.status === "failure";
|
||||
const showIcon = !row.groupedToolDetail || iconIsDestructive || failed;
|
||||
@@ -352,7 +353,7 @@ export function ThreadWorkLog(props: {
|
||||
>
|
||||
<Pressable
|
||||
accessibilityRole={canExpand ? "button" : undefined}
|
||||
accessibilityLabel={failed ? `${displayText}, tool call failed` : displayText}
|
||||
accessibilityLabel={failed ? `${previewText}, tool call failed` : previewText}
|
||||
accessibilityHint={
|
||||
canExpand
|
||||
? "Double tap to show full details. Long press to copy."
|
||||
|
||||
@@ -234,6 +234,222 @@ function makeThread(
|
||||
}
|
||||
|
||||
describe("buildThreadFeed", () => {
|
||||
it("keeps long Claude commands expandable without repeating them in full detail", () => {
|
||||
const command = `printf 'first line\nsecond line'\n&& printf done`;
|
||||
const thread = makeThread({
|
||||
id: ThreadId.make("thread-long-command"),
|
||||
projectId: ProjectId.make("project-1"),
|
||||
title: "Long command",
|
||||
activities: [
|
||||
makeActivity({
|
||||
id: EventId.make("long-command"),
|
||||
kind: "tool.completed",
|
||||
tone: "tool",
|
||||
summary: "Command run",
|
||||
createdAt: "2026-09-01T00:00:00.000Z",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
title: "Command run",
|
||||
detail: `Bash: ${command}`,
|
||||
data: { toolName: "Bash", command },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const [group] = buildThreadFeed(thread);
|
||||
expect(group?.type).toBe("activity-group");
|
||||
if (group?.type !== "activity-group") return;
|
||||
const [row] = group.activities;
|
||||
expect(row).toMatchObject({ detail: command, canExpand: true });
|
||||
expect(row?.getFullDetail()).toBe(command);
|
||||
expect(row?.getCopyText()).toBe(`Command run\n${command}`);
|
||||
});
|
||||
|
||||
it("keeps command output when it equals the displayed command", () => {
|
||||
const command = "printf hello";
|
||||
const thread = makeThread({
|
||||
id: ThreadId.make("thread-matching-command-output"),
|
||||
projectId: ProjectId.make("project-1"),
|
||||
title: "Matching output",
|
||||
activities: [
|
||||
makeActivity({
|
||||
id: EventId.make("matching-command-output"),
|
||||
kind: "tool.completed",
|
||||
tone: "tool",
|
||||
summary: "Command run",
|
||||
createdAt: "2026-09-01T00:00:00.000Z",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
title: "Command run",
|
||||
detail: `Bash: ${command}`,
|
||||
data: { toolName: "Bash", command, rawOutput: { content: command } },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const [group] = buildThreadFeed(thread);
|
||||
expect(group?.type).toBe("activity-group");
|
||||
if (group?.type !== "activity-group") return;
|
||||
const [row] = group.activities;
|
||||
expect(row?.detail).toBe(command);
|
||||
expect(row?.getFullDetail()).toBe(`${command}\n\n${command}`);
|
||||
expect(row?.getCopyText()).toBe(`Command run\n${command}\n\n${command}`);
|
||||
});
|
||||
|
||||
it("keeps OpenCode detail-only output when it equals the command", () => {
|
||||
const command = "printf hello";
|
||||
const thread = makeThread({
|
||||
id: ThreadId.make("thread-opencode-detail-output"),
|
||||
projectId: ProjectId.make("project-1"),
|
||||
title: "OpenCode detail output",
|
||||
activities: [
|
||||
makeActivity({
|
||||
id: EventId.make("opencode-detail-output"),
|
||||
kind: "tool.completed",
|
||||
tone: "tool",
|
||||
summary: "bash",
|
||||
createdAt: "2026-09-01T00:00:00.000Z",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
title: "bash",
|
||||
detail: command,
|
||||
data: { command },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const [group] = buildThreadFeed(thread);
|
||||
expect(group?.type).toBe("activity-group");
|
||||
if (group?.type !== "activity-group") return;
|
||||
const [row] = group.activities;
|
||||
expect(row?.workEntry.detail).toBe(command);
|
||||
expect(row?.getFullDetail()).toBe(`${command}\n\n${command}`);
|
||||
});
|
||||
|
||||
it("drops a truncated Claude echo of a long command", () => {
|
||||
const command = `git add -A && git commit -m "${"x".repeat(200)}"`;
|
||||
const thread = makeThread({
|
||||
id: ThreadId.make("thread-truncated-echo"),
|
||||
projectId: ProjectId.make("project-1"),
|
||||
title: "Truncated echo",
|
||||
activities: [
|
||||
makeActivity({
|
||||
id: EventId.make("truncated-echo"),
|
||||
kind: "tool.completed",
|
||||
tone: "tool",
|
||||
summary: "Command run",
|
||||
createdAt: "2026-09-01T00:00:00.000Z",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
title: "Command run",
|
||||
detail: `Bash: ${command}`.slice(0, 177) + "...",
|
||||
data: { toolName: "Bash", command },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const [group] = buildThreadFeed(thread);
|
||||
expect(group?.type).toBe("activity-group");
|
||||
if (group?.type !== "activity-group") return;
|
||||
const [row] = group.activities;
|
||||
expect(row?.workEntry.detail).toBeUndefined();
|
||||
expect(row?.getFullDetail()).toBe(command);
|
||||
});
|
||||
|
||||
it("drops an ACP command echo when the update omits the tool kind", () => {
|
||||
const command = "pnpm test";
|
||||
const thread = makeThread({
|
||||
id: ThreadId.make("thread-acp-no-kind"),
|
||||
projectId: ProjectId.make("project-1"),
|
||||
title: "ACP no kind",
|
||||
activities: [
|
||||
makeActivity({
|
||||
id: EventId.make("acp-no-kind"),
|
||||
kind: "tool.completed",
|
||||
tone: "tool",
|
||||
summary: "Terminal",
|
||||
createdAt: "2026-09-01T00:00:00.000Z",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
title: "Terminal",
|
||||
detail: command,
|
||||
data: { toolCallId: "tool-1", command },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const [group] = buildThreadFeed(thread);
|
||||
expect(group?.type).toBe("activity-group");
|
||||
if (group?.type !== "activity-group") return;
|
||||
const [row] = group.activities;
|
||||
expect(row?.workEntry.detail).toBeUndefined();
|
||||
expect(row?.getFullDetail()).toBe(command);
|
||||
});
|
||||
|
||||
it("drops ACP command metadata when detail only repeats the command", () => {
|
||||
const command = "printf hello";
|
||||
const thread = makeThread({
|
||||
id: ThreadId.make("thread-acp-command-detail"),
|
||||
projectId: ProjectId.make("project-1"),
|
||||
title: "ACP command detail",
|
||||
activities: [
|
||||
makeActivity({
|
||||
id: EventId.make("acp-command-detail"),
|
||||
kind: "tool.completed",
|
||||
tone: "tool",
|
||||
summary: "Terminal",
|
||||
createdAt: "2026-09-01T00:00:00.000Z",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
title: "Terminal",
|
||||
detail: command,
|
||||
data: { kind: "execute", command },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const [group] = buildThreadFeed(thread);
|
||||
expect(group?.type).toBe("activity-group");
|
||||
if (group?.type !== "activity-group") return;
|
||||
const [row] = group.activities;
|
||||
expect(row?.workEntry.detail).toBeUndefined();
|
||||
expect(row?.getFullDetail()).toBe(command);
|
||||
});
|
||||
|
||||
it("does not show command output when the command input is missing", () => {
|
||||
const thread = makeThread({
|
||||
id: ThreadId.make("thread-command-without-input"),
|
||||
projectId: ProjectId.make("project-1"),
|
||||
title: "Missing command input",
|
||||
activities: [
|
||||
makeActivity({
|
||||
id: EventId.make("command-without-input"),
|
||||
kind: "tool.completed",
|
||||
tone: "tool",
|
||||
summary: "Command run",
|
||||
createdAt: "2026-09-01T00:00:00.000Z",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
title: "Command run",
|
||||
data: { rawOutput: { content: "output without command metadata" } },
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const [group] = buildThreadFeed(thread);
|
||||
expect(group?.type).toBe("activity-group");
|
||||
if (group?.type !== "activity-group") return;
|
||||
expect(group.activities[0]?.detail).toBeNull();
|
||||
expect(group.activities[0]?.getFullDetail()).toBeNull();
|
||||
});
|
||||
|
||||
it("keeps setup failures visible without routine setup notices before or after a turn", () => {
|
||||
const thread = makeThread({
|
||||
id: ThreadId.make("thread-worktree-setup"),
|
||||
|
||||
@@ -14,6 +14,8 @@ import type {
|
||||
} from "@t3tools/contracts";
|
||||
import { formatDuration } from "@t3tools/shared/orchestrationTiming";
|
||||
import {
|
||||
commandDetailRepeatsCommand,
|
||||
extractCommandOutputText,
|
||||
isWorktreeSetupActivity,
|
||||
normalizeCompactToolLabel,
|
||||
omitSupersededLifecycleMarkers,
|
||||
@@ -440,16 +442,23 @@ function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWo
|
||||
const itemType = extractWorkLogItemType(payload);
|
||||
const requestKind = extractWorkLogRequestKind(payload);
|
||||
const viewedImagePath = asTrimmedString(asRecord(payload?.data)?.imagePath);
|
||||
if (
|
||||
!taskDetailAsLabel &&
|
||||
payload &&
|
||||
typeof payload.detail === "string" &&
|
||||
payload.detail.length > 0
|
||||
) {
|
||||
const commandOutput = commandPreview.command ? extractCommandOutputText(payload?.data) : null;
|
||||
const output = commandOutput ? stripTrailingExitCode(commandOutput).output : null;
|
||||
if (!taskDetailAsLabel && output) {
|
||||
entry.detail = output;
|
||||
} else if (!taskDetailAsLabel && typeof payload?.detail === "string") {
|
||||
const detail = stripTrailingExitCode(payload.detail).output;
|
||||
if (detail) {
|
||||
entry.detail = detail;
|
||||
}
|
||||
const data = asRecord(payload.data);
|
||||
const repeatsCommand =
|
||||
detail !== null &&
|
||||
commandDetailRepeatsCommand({
|
||||
detail,
|
||||
command: commandPreview.command,
|
||||
rawCommand: commandPreview.rawCommand,
|
||||
toolName: data?.toolName,
|
||||
data,
|
||||
});
|
||||
if (detail && !repeatsCommand) entry.detail = detail;
|
||||
}
|
||||
if (viewedImagePath) {
|
||||
entry.viewedImagePath = viewedImagePath;
|
||||
@@ -757,20 +766,18 @@ function workEntryIcon(entry: DerivedWorkLogEntry): ThreadFeedActivity["icon"] {
|
||||
|
||||
function buildWorkEntryExpandedBody(entry: WorkLogEntry): string | null {
|
||||
const blocks: string[] = [];
|
||||
const appendUniqueBlock = (value: string | null | undefined) => {
|
||||
const appendBlock = (value: string | null | undefined) => {
|
||||
const trimmed = value?.trim();
|
||||
if (trimmed && !blocks.includes(trimmed)) {
|
||||
blocks.push(trimmed);
|
||||
}
|
||||
if (trimmed && (entry.command || !blocks.includes(trimmed))) blocks.push(trimmed);
|
||||
};
|
||||
|
||||
if (entry.itemType === "mcp_tool_call" && entry.toolData !== undefined) {
|
||||
appendUniqueBlock(`MCP call\n${JSON.stringify(entry.toolData, null, 2)}`);
|
||||
appendBlock(`MCP call\n${JSON.stringify(entry.toolData, null, 2)}`);
|
||||
}
|
||||
appendUniqueBlock(entry.rawCommand ?? entry.command);
|
||||
appendUniqueBlock(entry.detail);
|
||||
appendBlock(entry.rawCommand ?? entry.command);
|
||||
appendBlock(entry.detail);
|
||||
if ((entry.changedFiles?.length ?? 0) > 0) {
|
||||
appendUniqueBlock(entry.changedFiles!.join("\n"));
|
||||
appendBlock(entry.changedFiles!.join("\n"));
|
||||
}
|
||||
|
||||
return blocks.length > 0 ? blocks.join("\n\n") : null;
|
||||
@@ -1765,13 +1772,21 @@ export function buildThreadFeed(
|
||||
const summary = workEntryHeading(entry);
|
||||
const detail = workEntryPreview(entry);
|
||||
const getFullDetail = memoizeValue(() => buildWorkEntryExpandedBody(entry));
|
||||
const getCopyText = memoizeValue(() =>
|
||||
[summary, detail, getFullDetail()]
|
||||
const getCopyText = memoizeValue(() => {
|
||||
const fullDetail = getFullDetail();
|
||||
if (entry.command) {
|
||||
const normalizedCommand =
|
||||
entry.rawCommand && summary.trim() !== entry.command.trim() ? entry.command : null;
|
||||
return [summary, normalizedCommand, fullDetail ?? entry.command]
|
||||
.filter((value): value is string => Boolean(value))
|
||||
.join("\n");
|
||||
}
|
||||
return [summary, detail, fullDetail]
|
||||
.filter((value, index, values): value is string => {
|
||||
return Boolean(value) && values.indexOf(value) === index;
|
||||
})
|
||||
.join("\n"),
|
||||
);
|
||||
.join("\n");
|
||||
});
|
||||
return {
|
||||
type: "activity",
|
||||
id: entry.id,
|
||||
|
||||
@@ -119,7 +119,7 @@ describe("projectActivityPayload", () => {
|
||||
expect(JSON.stringify(acp.payload).length).toBeLessThan(500);
|
||||
});
|
||||
|
||||
it("normalizes Claude and OpenCode command inputs before slimming provider data", () => {
|
||||
it("keeps bounded Claude command input and result summaries", () => {
|
||||
const claude = projectActivityPayload(
|
||||
activity({
|
||||
itemType: "command_execution",
|
||||
@@ -127,7 +127,13 @@ describe("projectActivityPayload", () => {
|
||||
data: {
|
||||
toolName: "Bash",
|
||||
input: { command: "vp test run" },
|
||||
result: { content: "x".repeat(5_000) },
|
||||
result: {
|
||||
type: "tool_result",
|
||||
content: [
|
||||
{ type: "text", text: "tests passed" },
|
||||
{ type: "text", text: "x".repeat(5_000) },
|
||||
],
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
@@ -148,13 +154,17 @@ describe("projectActivityPayload", () => {
|
||||
|
||||
expect(claude.payload).toMatchObject({
|
||||
toolCallId: "claude-call-1",
|
||||
data: { command: "vp test run" },
|
||||
data: {
|
||||
toolName: "Bash",
|
||||
command: "vp test run",
|
||||
rawOutput: { content: "tests passed" },
|
||||
},
|
||||
});
|
||||
expect(openCode.payload).toMatchObject({
|
||||
toolCallId: "opencode-call-1",
|
||||
data: { command: "vp lint" },
|
||||
});
|
||||
expect(JSON.stringify(claude.payload).length).toBeLessThan(200);
|
||||
expect(JSON.stringify(claude.payload).length).toBeLessThan(250);
|
||||
expect(JSON.stringify(openCode.payload).length).toBeLessThan(200);
|
||||
});
|
||||
|
||||
|
||||
@@ -408,8 +408,14 @@ export function projectActivityPayload(
|
||||
if ("kind" in data) {
|
||||
projectedData.kind = data.kind;
|
||||
}
|
||||
if ("toolName" in data) {
|
||||
projectedData.toolName = data.toolName;
|
||||
}
|
||||
|
||||
const rawOutput = projectRawOutput(data.rawOutput) ?? projectAcpContent(data.content);
|
||||
const rawOutput =
|
||||
projectRawOutput(data.rawOutput) ??
|
||||
projectAcpContent(data.content) ??
|
||||
(payload.itemType === "command_execution" ? summarizeMcpResult(data.result) : undefined);
|
||||
if (rawOutput) {
|
||||
projectedData.rawOutput = rawOutput;
|
||||
}
|
||||
|
||||
@@ -184,6 +184,52 @@ describe("projectActivityPayload", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("projects a Claude Bash result for the web and mobile expanded rows", () => {
|
||||
const command = `printf 'first line\nsecond line'\n&& printf done`;
|
||||
const source: OrchestrationThreadActivity = {
|
||||
...makeActivity("claude-bash", "command_execution", {}),
|
||||
summary: "Command run",
|
||||
payload: {
|
||||
itemType: "command_execution",
|
||||
title: "Command run",
|
||||
detail: `Bash: ${command}`,
|
||||
status: "completed",
|
||||
data: {
|
||||
toolName: "Bash",
|
||||
input: { command },
|
||||
result: {
|
||||
type: "tool_result",
|
||||
tool_use_id: "toolu_1",
|
||||
content: [
|
||||
{ type: "text", text: "first output line" },
|
||||
{ type: "text", text: "x".repeat(5_000) },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const projected = projectActivityPayload(source);
|
||||
|
||||
expect(projected.payload).toMatchObject({
|
||||
data: {
|
||||
toolName: "Bash",
|
||||
command,
|
||||
rawOutput: { content: "first output line" },
|
||||
},
|
||||
});
|
||||
|
||||
const [webEntry] = deriveWorkLogEntries([projected]);
|
||||
expect(webEntry).toMatchObject({ command, detail: "first output line" });
|
||||
|
||||
const [mobileGroup] = buildThreadFeed(makeThread([projected]));
|
||||
expect(mobileGroup?.type).toBe("activity-group");
|
||||
if (mobileGroup?.type !== "activity-group") return;
|
||||
const [mobileRow] = mobileGroup.activities;
|
||||
expect(mobileRow).toMatchObject({ detail: command, canExpand: true });
|
||||
expect(mobileRow?.getFullDetail()).toBe(`${command}\n\nfirst output line`);
|
||||
expect(mobileRow?.getCopyText()).toBe(`Command run\n${command}\n\nfirst output line`);
|
||||
});
|
||||
|
||||
it("slims MCP tool data to the fields the expanded row renders", () => {
|
||||
expect(projectActivityPayload(fixtures[4]!).payload).toEqual({
|
||||
itemType: "mcp_tool_call",
|
||||
@@ -201,9 +247,30 @@ describe("projectActivityPayload", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps current web and mobile derived output identical for every tool item type", () => {
|
||||
it("keeps current web and mobile derived fields for every tool item type", () => {
|
||||
for (const activity of fixtures) {
|
||||
const projected = projectActivityPayload(activity);
|
||||
if (activity === fixtures[0]) {
|
||||
expect(deriveWorkLogEntries([projected])).toMatchObject([
|
||||
{
|
||||
command: "pnpm test",
|
||||
rawCommand: 'bash -lc "pnpm test"',
|
||||
detail: "first useful line",
|
||||
},
|
||||
]);
|
||||
expect(comparableThreadFeed([projected])).toMatchObject([
|
||||
{
|
||||
type: "activity-group",
|
||||
activities: [
|
||||
{
|
||||
detail: "pnpm test",
|
||||
fullDetail: 'bash -lc "pnpm test"\n\nfirst useful line',
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
continue;
|
||||
}
|
||||
if (activity === fixtures[4]) {
|
||||
// MCP is the one deliberate difference: the expanded row's toolData
|
||||
// loses result bulk but keeps the rendered identity fields.
|
||||
|
||||
@@ -2448,7 +2448,8 @@ const PlainWorkEntryRow = memo(function PlainWorkEntryRow(props: {
|
||||
const showFailedIndicator = workEntryDisplayIndicatesToolFailure(workEntry);
|
||||
const entryIconName =
|
||||
showWarningIndicator || showFailedIndicator ? "circle-alert" : workEntryIconName(workEntry);
|
||||
const displayText = workEntryPreview(workEntry, workspaceRoot) ?? toolWorkEntryHeading(workEntry);
|
||||
const previewText = workEntryPreview(workEntry, workspaceRoot) ?? toolWorkEntryHeading(workEntry);
|
||||
const displayText = expanded && workEntry.command?.trim() ? "Command" : previewText;
|
||||
const expandedBody = buildToolCallExpandedBody(workEntry, workspaceRoot);
|
||||
const viewedImagePath = workEntryViewedImagePath(workEntry);
|
||||
const viewedImage =
|
||||
@@ -2483,8 +2484,8 @@ const PlainWorkEntryRow = memo(function PlainWorkEntryRow(props: {
|
||||
: "text-foreground/80";
|
||||
const showEntryIcon = !isExpandedToolGroupEntry || showWarningIndicator || showFailedIndicator;
|
||||
const accessibleDisplayText = showFailedIndicator
|
||||
? `${displayText}, tool call failed`
|
||||
: displayText;
|
||||
? `${previewText}, tool call failed`
|
||||
: previewText;
|
||||
const rowToggleProps = canExpand
|
||||
? {
|
||||
role: "button" as const,
|
||||
|
||||
@@ -66,6 +66,93 @@ describe("deriveWorkLogEntries command output", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps command output that equals the command text", () => {
|
||||
const [entry] = deriveWorkLogEntries([
|
||||
makeCommandActivity("matching-output", {
|
||||
itemType: "command_execution",
|
||||
title: "Ran command",
|
||||
detail: "printf hello",
|
||||
data: {
|
||||
command: "printf hello",
|
||||
rawOutput: { content: "printf hello" },
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
expect(entry).toMatchObject({
|
||||
command: "printf hello",
|
||||
detail: "printf hello",
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps OpenCode detail-only output when it equals the command", () => {
|
||||
const [entry] = deriveWorkLogEntries([
|
||||
makeCommandActivity("opencode-detail-output", {
|
||||
itemType: "command_execution",
|
||||
title: "bash",
|
||||
detail: "printf hello",
|
||||
data: { command: "printf hello" },
|
||||
}),
|
||||
]);
|
||||
|
||||
expect(entry).toMatchObject({
|
||||
command: "printf hello",
|
||||
detail: "printf hello",
|
||||
});
|
||||
});
|
||||
|
||||
it("drops a Claude tool-name detail when there is no output", () => {
|
||||
const [entry] = deriveWorkLogEntries([
|
||||
makeCommandActivity("claude-no-output", {
|
||||
itemType: "command_execution",
|
||||
title: "Command run",
|
||||
detail: "Bash: printf hello",
|
||||
data: {
|
||||
toolName: "Bash",
|
||||
command: "printf hello",
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
expect(entry?.command).toBe("printf hello");
|
||||
expect(entry?.detail).toBeUndefined();
|
||||
});
|
||||
|
||||
it("drops a truncated Claude tool-name detail for a long command", () => {
|
||||
const command = `git add -A && git commit -m "${"x".repeat(200)}"`;
|
||||
const [entry] = deriveWorkLogEntries([
|
||||
makeCommandActivity("claude-long-command", {
|
||||
itemType: "command_execution",
|
||||
title: "Command run",
|
||||
detail: `Bash: ${command}`.slice(0, 177) + "...",
|
||||
data: {
|
||||
toolName: "Bash",
|
||||
command,
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
expect(entry?.command).toBe(command);
|
||||
expect(entry?.detail).toBeUndefined();
|
||||
});
|
||||
|
||||
it("drops an ACP command echo when the update omits the tool kind", () => {
|
||||
const [entry] = deriveWorkLogEntries([
|
||||
makeCommandActivity("acp-no-kind", {
|
||||
itemType: "command_execution",
|
||||
title: "Terminal",
|
||||
detail: "pnpm test",
|
||||
data: {
|
||||
toolCallId: "tool-1",
|
||||
command: "pnpm test",
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
expect(entry?.command).toBe("pnpm test");
|
||||
expect(entry?.detail).toBeUndefined();
|
||||
});
|
||||
|
||||
it("drops duplicated command detail when the command has no output", () => {
|
||||
const [entry] = deriveWorkLogEntries([
|
||||
makeCommandActivity("empty-command", {
|
||||
|
||||
@@ -2,7 +2,11 @@ import * as Option from "effect/Option";
|
||||
import * as Arr from "effect/Array";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { isBackgroundTaskActivity } from "@t3tools/client-runtime/state/subagentRuntime";
|
||||
import { isWorktreeSetupActivity } from "@t3tools/client-runtime/work-log/presentation";
|
||||
import {
|
||||
commandDetailRepeatsCommand,
|
||||
extractCommandOutputText,
|
||||
isWorktreeSetupActivity,
|
||||
} from "@t3tools/client-runtime/work-log/presentation";
|
||||
import {
|
||||
ApprovalRequestId,
|
||||
isToolLifecycleItemType,
|
||||
@@ -1514,68 +1518,9 @@ function summarizeToolRawOutput(payload: Record<string, unknown> | null): string
|
||||
return null;
|
||||
}
|
||||
|
||||
function extractAcpTextContent(value: unknown): string | null {
|
||||
if (!Array.isArray(value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const chunks: string[] = [];
|
||||
for (const entryValue of value) {
|
||||
const entry = asRecord(entryValue);
|
||||
if (entry?.type !== "content") {
|
||||
continue;
|
||||
}
|
||||
const content = asRecord(entry.content);
|
||||
if (content?.type !== "text") {
|
||||
continue;
|
||||
}
|
||||
const text = asTrimmedString(content.text);
|
||||
if (text) {
|
||||
chunks.push(text);
|
||||
}
|
||||
}
|
||||
|
||||
return chunks.length > 0 ? chunks.join("\n") : null;
|
||||
}
|
||||
|
||||
function extractToolOutput(payload: Record<string, unknown> | null): string | null {
|
||||
const data = asRecord(payload?.data);
|
||||
const item = asRecord(data?.item);
|
||||
const itemResult = asRecord(item?.result);
|
||||
const rawOutput = asRecord(data?.rawOutput);
|
||||
|
||||
const outputStreams: string[] = [];
|
||||
const stdout = asTrimmedString(rawOutput?.stdout);
|
||||
const stderr = asTrimmedString(rawOutput?.stderr);
|
||||
if (stdout) {
|
||||
outputStreams.push(stdout);
|
||||
}
|
||||
if (stderr) {
|
||||
outputStreams.push(stderr);
|
||||
}
|
||||
|
||||
const candidates: unknown[] = [
|
||||
item?.aggregatedOutput,
|
||||
itemResult?.content,
|
||||
data?.rawOutput,
|
||||
rawOutput?.content,
|
||||
outputStreams.length > 0 ? outputStreams.join("\n") : null,
|
||||
rawOutput?.output,
|
||||
extractAcpTextContent(data?.content),
|
||||
];
|
||||
|
||||
for (const candidate of candidates) {
|
||||
const text = asTrimmedString(candidate);
|
||||
if (!text) {
|
||||
continue;
|
||||
}
|
||||
const output = stripTrailingExitCode(text).output;
|
||||
if (output) {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
const output = extractCommandOutputText(payload?.data);
|
||||
return output ? stripTrailingExitCode(output).output : null;
|
||||
}
|
||||
|
||||
function isCommandToolDetail(payload: Record<string, unknown> | null, heading: string): boolean {
|
||||
@@ -1603,32 +1548,28 @@ function extractToolDetail(
|
||||
? extractToolCommand(payload)
|
||||
: { command: null, rawCommand: null };
|
||||
const command = commandPreview.command;
|
||||
const normalizedCommand = normalizePreviewForComparison(command);
|
||||
const normalizedRawCommand = normalizePreviewForComparison(commandPreview.rawCommand);
|
||||
|
||||
if (
|
||||
detail &&
|
||||
normalizedHeading !== normalizedDetail &&
|
||||
(!commandTool ||
|
||||
(normalizedCommand !== normalizedDetail && normalizedRawCommand !== normalizedDetail))
|
||||
) {
|
||||
if (commandTool && command) {
|
||||
const output = extractToolOutput(payload);
|
||||
if (output) return output;
|
||||
}
|
||||
|
||||
const data = asRecord(payload?.data);
|
||||
const repeatsCommand =
|
||||
detail !== null &&
|
||||
commandDetailRepeatsCommand({
|
||||
detail,
|
||||
command,
|
||||
rawCommand: commandPreview.rawCommand,
|
||||
toolName: data?.toolName,
|
||||
data,
|
||||
});
|
||||
|
||||
if (detail && normalizedHeading !== normalizedDetail && (!commandTool || !repeatsCommand)) {
|
||||
return detail;
|
||||
}
|
||||
|
||||
if (commandTool) {
|
||||
if (!command) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const output = extractToolOutput(payload);
|
||||
const normalizedOutput = normalizePreviewForComparison(output);
|
||||
if (
|
||||
output &&
|
||||
normalizedOutput !== normalizedHeading &&
|
||||
normalizedOutput !== normalizedCommand
|
||||
) {
|
||||
return output;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,11 +3,96 @@ import { describe, expect, it } from "vite-plus/test";
|
||||
import { ThreadId } from "@t3tools/contracts";
|
||||
|
||||
import {
|
||||
commandDetailRepeatsCommand,
|
||||
extractCommandOutputText,
|
||||
resolveViewedImageAsset,
|
||||
toolGroupAction,
|
||||
workEntryViewedImagePath,
|
||||
} from "./presentation.js";
|
||||
|
||||
describe("command work-log details", () => {
|
||||
it("extracts Claude result blocks and projected output", () => {
|
||||
expect(
|
||||
extractCommandOutputText({
|
||||
result: {
|
||||
content: [
|
||||
{ type: "text", text: "first" },
|
||||
{ type: "text", text: "second" },
|
||||
],
|
||||
},
|
||||
}),
|
||||
).toBe("first\nsecond");
|
||||
expect(extractCommandOutputText({ rawOutput: { content: "projected summary" } })).toBe(
|
||||
"projected summary",
|
||||
);
|
||||
});
|
||||
|
||||
it("only removes a detail with the matching tool-name prefix", () => {
|
||||
expect(
|
||||
commandDetailRepeatsCommand({
|
||||
detail: "Bash: printf hello",
|
||||
command: "printf hello",
|
||||
rawCommand: null,
|
||||
toolName: "Bash",
|
||||
data: { toolName: "Bash", command: "printf hello" },
|
||||
}),
|
||||
).toBe(true);
|
||||
expect(
|
||||
commandDetailRepeatsCommand({
|
||||
detail: "warning: printf hello",
|
||||
command: "printf hello",
|
||||
rawCommand: null,
|
||||
toolName: "Bash",
|
||||
data: { toolName: "Bash", command: "printf hello" },
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("treats an ingestion-truncated echo of a long command as a repeat", () => {
|
||||
const command = `git add -A && git commit -m "${"x".repeat(200)}"`;
|
||||
const truncated = `Bash: ${command}`.slice(0, 177) + "...";
|
||||
expect(
|
||||
commandDetailRepeatsCommand({
|
||||
detail: truncated,
|
||||
command,
|
||||
rawCommand: null,
|
||||
toolName: "Bash",
|
||||
data: { toolName: "Bash", command },
|
||||
}),
|
||||
).toBe(true);
|
||||
expect(
|
||||
commandDetailRepeatsCommand({
|
||||
detail: "Bash: printf hello...",
|
||||
command: "printf goodbye",
|
||||
rawCommand: null,
|
||||
toolName: "Bash",
|
||||
data: { toolName: "Bash", command: "printf goodbye" },
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("treats ACP command echoes as synthetic even without a tool kind", () => {
|
||||
expect(
|
||||
commandDetailRepeatsCommand({
|
||||
detail: "pnpm test",
|
||||
command: "pnpm test",
|
||||
rawCommand: null,
|
||||
toolName: undefined,
|
||||
data: { toolCallId: "tool-1", command: "pnpm test" },
|
||||
}),
|
||||
).toBe(true);
|
||||
expect(
|
||||
commandDetailRepeatsCommand({
|
||||
detail: "pnpm test",
|
||||
command: "pnpm test",
|
||||
rawCommand: null,
|
||||
toolName: undefined,
|
||||
data: { command: "pnpm test" },
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("workEntryViewedImagePath", () => {
|
||||
const entry = { label: "Read", tone: "tool" } as const;
|
||||
|
||||
|
||||
@@ -51,6 +51,147 @@ export function normalizeCompactToolLabel(value: string): string {
|
||||
return value.replace(/\s+(?:complete|completed)\s*$/i, "").trim();
|
||||
}
|
||||
|
||||
function asRecord(value: unknown): Record<string, unknown> | null {
|
||||
return value !== null && typeof value === "object" && !Array.isArray(value)
|
||||
? (value as Record<string, unknown>)
|
||||
: null;
|
||||
}
|
||||
|
||||
function nonEmptyString(value: unknown): string | null {
|
||||
return typeof value === "string" && value.trim().length > 0 ? value : null;
|
||||
}
|
||||
|
||||
function commandResultContent(value: unknown): string | null {
|
||||
const direct = nonEmptyString(value);
|
||||
if (direct) return direct;
|
||||
|
||||
const directContent = Array.isArray(value) ? value : null;
|
||||
const record = asRecord(value);
|
||||
const content = record?.content;
|
||||
const contentText = nonEmptyString(content);
|
||||
if (contentText) return contentText;
|
||||
const blocks = directContent ?? (Array.isArray(content) ? content : null);
|
||||
if (!blocks) return null;
|
||||
|
||||
const chunks = blocks.flatMap((entry) => {
|
||||
const text = nonEmptyString(entry) ?? nonEmptyString(asRecord(entry)?.text);
|
||||
return text ? [text] : [];
|
||||
});
|
||||
return chunks.length > 0 ? chunks.join("\n") : null;
|
||||
}
|
||||
|
||||
/** Returns provider command output before it is formatted for a work-log row. */
|
||||
export function extractCommandOutputText(dataValue: unknown): string | null {
|
||||
const data = asRecord(dataValue);
|
||||
const item = asRecord(data?.item);
|
||||
const itemResult = asRecord(item?.result);
|
||||
const rawOutput = asRecord(data?.rawOutput);
|
||||
const outputStreams = [
|
||||
nonEmptyString(rawOutput?.stdout),
|
||||
nonEmptyString(rawOutput?.stderr),
|
||||
].filter((value): value is string => value !== null);
|
||||
const acpContent = Array.isArray(data?.content)
|
||||
? data.content
|
||||
.flatMap((entryValue) => {
|
||||
const entry = asRecord(entryValue);
|
||||
const content = asRecord(entry?.content);
|
||||
const text = entry?.type === "content" ? nonEmptyString(content?.text) : null;
|
||||
return text ? [text] : [];
|
||||
})
|
||||
.join("\n")
|
||||
: null;
|
||||
|
||||
const candidates = [
|
||||
item?.aggregatedOutput,
|
||||
itemResult?.content,
|
||||
data?.rawOutput,
|
||||
rawOutput?.content,
|
||||
outputStreams.length > 0 ? outputStreams.join("\n") : null,
|
||||
rawOutput?.output,
|
||||
acpContent,
|
||||
data?.result,
|
||||
];
|
||||
for (const candidate of candidates) {
|
||||
const text = commandResultContent(candidate);
|
||||
if (text) return text;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ingestion caps tool details at 180 chars and appends "...", so a long command
|
||||
* echo no longer equals the command it repeats. Treat a truncated prefix of the
|
||||
* command as the same echo.
|
||||
*/
|
||||
function textRepeatsCommand(text: string, commands: ReadonlyArray<string | null>): boolean {
|
||||
const truncated = text.endsWith("...")
|
||||
? text.slice(0, -3)
|
||||
: text.endsWith("\u2026")
|
||||
? text.slice(0, -1)
|
||||
: null;
|
||||
return commands.some((candidate) => {
|
||||
const command = candidate?.trim();
|
||||
if (!command) return false;
|
||||
if (command === text) return true;
|
||||
return (
|
||||
truncated !== null &&
|
||||
truncated.length > 0 &&
|
||||
command.length > truncated.length &&
|
||||
command.startsWith(truncated)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Decides whether a command row's `detail` is a synthetic echo of the command
|
||||
* rather than real output. OpenCode stores completed output in `detail` with no
|
||||
* other output channel, so plain equality is only treated as synthetic when the
|
||||
* payload shape shows the detail came from the command: Codex item metadata,
|
||||
* an ACP tool call (`data.toolCallId`, `kind: "execute"`), a Claude tool-name
|
||||
* prefix, or no structured command at all.
|
||||
*/
|
||||
export function commandDetailRepeatsCommand(input: {
|
||||
readonly detail: string;
|
||||
readonly command: string | null;
|
||||
readonly rawCommand: string | null;
|
||||
readonly toolName: unknown;
|
||||
readonly data: unknown;
|
||||
}): boolean {
|
||||
const toolName = nonEmptyString(input.toolName)?.trim();
|
||||
const detail = input.detail.trim();
|
||||
const commands = [input.command, input.rawCommand];
|
||||
if (toolName) {
|
||||
const prefix = `${toolName}:`;
|
||||
if (detail.toLowerCase().startsWith(prefix.toLowerCase())) {
|
||||
const unprefixed = detail.slice(prefix.length).trim();
|
||||
if (textRepeatsCommand(unprefixed, commands)) return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!textRepeatsCommand(detail, commands)) return false;
|
||||
|
||||
const data = asRecord(input.data);
|
||||
const item = asRecord(data?.item);
|
||||
const itemInput = asRecord(item?.input);
|
||||
const itemResult = asRecord(item?.result);
|
||||
const hasStructuredCommand = [
|
||||
item?.command,
|
||||
itemInput?.command,
|
||||
itemResult?.command,
|
||||
data?.command,
|
||||
].some((value) =>
|
||||
Array.isArray(value)
|
||||
? value.some((part) => nonEmptyString(part) !== null)
|
||||
: nonEmptyString(value) !== null,
|
||||
);
|
||||
return (
|
||||
!hasStructuredCommand ||
|
||||
item !== null ||
|
||||
data?.toolCallId !== undefined ||
|
||||
nonEmptyString(data?.kind)?.toLowerCase() === "execute"
|
||||
);
|
||||
}
|
||||
|
||||
function workLogEntryIsToolLike(entry: WorkLogPresentationEntry): boolean {
|
||||
if (entry.tone === "tool" || entry.tone === "thinking" || entry.tone === "error") return true;
|
||||
if (entry.command !== undefined && entry.command.trim().length > 0) return true;
|
||||
|
||||
Reference in new issue
Block a user