Update files
This commit is contained in:
@@ -2,6 +2,7 @@ import { describe, expect, test } from "vitest";
|
||||
import {
|
||||
stripShellWrapperPrefix,
|
||||
extractPrincipalParam,
|
||||
normalizeToolDisplayName,
|
||||
stripCwdPrefix,
|
||||
} from "./tool-call-parsers.js";
|
||||
|
||||
@@ -90,6 +91,26 @@ describe("extractPrincipalParam", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("normalizeToolDisplayName", () => {
|
||||
test("normalizes plain speak name", () => {
|
||||
expect(normalizeToolDisplayName("speak")).toBe("Speak");
|
||||
});
|
||||
|
||||
test("normalizes codex namespaced speak name", () => {
|
||||
expect(normalizeToolDisplayName("paseo_voice.speak")).toBe("Speak");
|
||||
});
|
||||
|
||||
test("normalizes claude mcp speak name", () => {
|
||||
expect(normalizeToolDisplayName("mcp__paseo_voice__speak")).toBe("Speak");
|
||||
});
|
||||
|
||||
test("keeps non-speak names unchanged", () => {
|
||||
expect(normalizeToolDisplayName("paseo__create_agent")).toBe(
|
||||
"paseo__create_agent"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("stripCwdPrefix", () => {
|
||||
test("strips cwd prefix from file path", () => {
|
||||
expect(stripCwdPrefix("/Users/dev/project/src/file.ts", "/Users/dev/project")).toBe("src/file.ts");
|
||||
|
||||
@@ -63,6 +63,21 @@ export function stripCwdPrefix(filePath: string, cwd?: string): string {
|
||||
// This is used for display purposes to show the actual command being run.
|
||||
const SHELL_WRAPPER_PREFIX_PATTERN = /^\/bin\/(?:zsh|bash|sh)\s+(?:-[a-zA-Z]+\s+)?/;
|
||||
const CD_AND_PATTERN = /^cd\s+(?:"[^"]+"|'[^']+'|\S+)\s+&&\s+/;
|
||||
const TOOL_TOKEN_REGEX = /[a-z0-9]+/g;
|
||||
|
||||
export function normalizeToolDisplayName(toolName: string): string {
|
||||
const normalized = toolName.trim().toLowerCase();
|
||||
if (!normalized) {
|
||||
return toolName;
|
||||
}
|
||||
|
||||
const tokens = normalized.match(TOOL_TOKEN_REGEX) ?? [];
|
||||
const leaf = tokens[tokens.length - 1];
|
||||
if (leaf === "speak") {
|
||||
return "Speak";
|
||||
}
|
||||
return toolName;
|
||||
}
|
||||
|
||||
export function stripShellWrapperPrefix(command: string): string {
|
||||
const prefixMatch = command.match(SHELL_WRAPPER_PREFIX_PATTERN);
|
||||
|
||||
Reference in New Issue
Block a user