Cluster T3.a — mechanical fixes for consistent-return and no-floating-promises. Files touched (15): - server/shared/tool-call-display.ts — default throw in buildCanonicalDetailDisplay switch - server/agent/prompt-attachments.ts — default throw in renderPromptAttachmentAsText switch - server/workspace-directory.ts — default throw in getSortValue switch - server/agent/mcp-server.ts — default throw in mcpCreateWorktreeInput switch - server/terminal/terminal-session-controller.ts — default return in dispatch switch - server/daemon-e2e/agent-configs.ts — default return false in isProviderAvailable switch - server/agent/agent-manager.ts — void dispatchSessionEvent fire-and-forget call - server/agent/mcp-shared.ts — void 4 notify() floating calls - app/agent-status-bar.utils.ts — default throw in getStatusSelectorHint switch - app/keyboard-shortcuts.ts — default throw in resolvePayload switch - app/resolve-agent-form.ts — default throw in resolveAgentForm switch - app/ui/dropdown-menu.tsx — void .then() + return undefined for promise/always-return - app/use-agent-form-state.ts — void refreshSnapshot() floating call - cli/worktree/create.ts — default throw in toDaemonCreateInput switch - cli/onboard.ts — return process.exit(1) to satisfy consistent-return in catch Deferred (outside 15-file cap or in EXCLUDE list): - server/worktree-session.ts — getSortValue (same pattern, cap reached) - Multiple files with other errors (unbound-method, unsafe-type-assertion) are separate clusters
168 lines
4.5 KiB
TypeScript
168 lines
4.5 KiB
TypeScript
import type { ToolCallTimelineItem } from "../server/agent/agent-sdk-types.js";
|
|
import { getPaseoToolLeafName, isPaseoToolName } from "../server/agent/tool-name-normalization.js";
|
|
import { stripCwdPrefix } from "./path-utils.js";
|
|
|
|
export type ToolCallDisplayInput = Pick<
|
|
ToolCallTimelineItem,
|
|
"name" | "status" | "error" | "metadata" | "detail"
|
|
> & {
|
|
cwd?: string;
|
|
};
|
|
|
|
export interface ToolCallDisplayModel {
|
|
displayName: string;
|
|
summary?: string;
|
|
errorText?: string;
|
|
}
|
|
|
|
interface DetailDisplay {
|
|
displayName?: string;
|
|
summary?: string;
|
|
}
|
|
|
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
}
|
|
|
|
function readString(value: unknown): string | undefined {
|
|
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
}
|
|
|
|
function humanizeToolName(name: string): string {
|
|
const trimmed = name.trim();
|
|
if (!trimmed) {
|
|
return name;
|
|
}
|
|
if (isPaseoToolName(trimmed)) {
|
|
const leaf = getPaseoToolLeafName(trimmed);
|
|
if (leaf) {
|
|
return humanizeToolName(leaf);
|
|
}
|
|
}
|
|
if (/[:./]/.test(trimmed) || trimmed.includes("__")) {
|
|
return trimmed;
|
|
}
|
|
|
|
return trimmed
|
|
.replace(/[._-]+/g, " ")
|
|
.split(" ")
|
|
.filter((segment) => segment.length > 0)
|
|
.map((segment) => `${segment[0]?.toUpperCase() ?? ""}${segment.slice(1)}`)
|
|
.join(" ");
|
|
}
|
|
|
|
function formatErrorText(error: unknown): string | undefined {
|
|
if (error === null || error === undefined) {
|
|
return undefined;
|
|
}
|
|
if (typeof error === "string") {
|
|
return error;
|
|
}
|
|
if (isRecord(error) && typeof error.content === "string") {
|
|
return error.content;
|
|
}
|
|
try {
|
|
return JSON.stringify(error, null, 2);
|
|
} catch {
|
|
return String(error);
|
|
}
|
|
}
|
|
|
|
function buildFilePathDisplay(
|
|
displayName: string,
|
|
filePath: string,
|
|
cwd: string | undefined,
|
|
): DetailDisplay {
|
|
return {
|
|
displayName,
|
|
summary: stripCwdPrefix(filePath, cwd),
|
|
};
|
|
}
|
|
|
|
function buildCanonicalDetailDisplay(input: ToolCallDisplayInput): DetailDisplay {
|
|
switch (input.detail.type) {
|
|
case "shell":
|
|
return {
|
|
displayName: "Shell",
|
|
summary: input.detail.command,
|
|
};
|
|
case "read":
|
|
return buildFilePathDisplay("Read", input.detail.filePath, input.cwd);
|
|
case "edit":
|
|
return buildFilePathDisplay("Edit", input.detail.filePath, input.cwd);
|
|
case "write":
|
|
return buildFilePathDisplay("Write", input.detail.filePath, input.cwd);
|
|
case "search":
|
|
return {
|
|
displayName: "Search",
|
|
summary: input.detail.query,
|
|
};
|
|
case "fetch":
|
|
return {
|
|
displayName: "Fetch",
|
|
summary: input.detail.url,
|
|
};
|
|
case "worktree_setup":
|
|
return {
|
|
displayName: "Worktree Setup",
|
|
summary: input.detail.branchName,
|
|
};
|
|
case "sub_agent":
|
|
return {
|
|
displayName: readString(input.detail.subAgentType) ?? "Task",
|
|
summary: readString(input.detail.description),
|
|
};
|
|
case "plain_text":
|
|
return {
|
|
summary: input.detail.label,
|
|
};
|
|
case "plan":
|
|
return {
|
|
displayName: "Plan",
|
|
};
|
|
case "unknown":
|
|
return {};
|
|
default:
|
|
throw new Error("unreachable");
|
|
}
|
|
}
|
|
|
|
function buildUnknownDetailOverride(input: ToolCallDisplayInput): DetailDisplay {
|
|
const lowerName = input.name.trim().toLowerCase();
|
|
if (input.detail.type === "unknown" && lowerName === "task") {
|
|
return {
|
|
displayName: "Task",
|
|
summary: isRecord(input.metadata) ? readString(input.metadata.subAgentActivity) : undefined,
|
|
};
|
|
}
|
|
if (input.detail.type === "unknown" && lowerName === "thinking") {
|
|
return {
|
|
displayName: "Thinking",
|
|
};
|
|
}
|
|
if (lowerName === "terminal") {
|
|
return {
|
|
displayName: "Terminal",
|
|
summary: input.detail.type === "plain_text" ? readString(input.detail.label) : undefined,
|
|
};
|
|
}
|
|
return {};
|
|
}
|
|
|
|
export function buildToolCallDisplayModel(input: ToolCallDisplayInput): ToolCallDisplayModel {
|
|
const canonicalDisplay = buildCanonicalDetailDisplay(input);
|
|
const unknownDetailOverride = buildUnknownDetailOverride(input);
|
|
const displayName =
|
|
unknownDetailOverride.displayName ??
|
|
canonicalDisplay.displayName ??
|
|
humanizeToolName(input.name);
|
|
const summary = unknownDetailOverride.summary ?? canonicalDisplay.summary;
|
|
const errorText = input.status === "failed" ? formatErrorText(input.error) : undefined;
|
|
|
|
return {
|
|
displayName,
|
|
...(summary ? { summary } : {}),
|
|
...(errorText ? { errorText } : {}),
|
|
};
|
|
}
|