Files
kandev/apps/web/lib/pretty-tool-title.ts
T
José Almeida 1733014721 feat(web): prettify Kandev MCP tool titles in chat (#858)
* feat(web): prettify Kandev MCP tool titles in chat

Render `create_task_kandev` as "Kandev: Create Task" instead of the
raw underscored tool name. Frontend-only display transform via a
regex-gated helper so non-Kandev tool names (Read, Bash, other MCP
servers, Claude-supplied human titles) pass through unchanged.

* fix(web): update e2e assertions for prettified Kandev tool titles + trim pass-through

- E2E `config-management.spec.ts` asserted raw `*_kandev` names in chat;
  update to the new "Kandev: ..." display so Shard 6/10 passes.
- `prettifyToolTitle` now returns `trimmed` instead of `raw` on the
  non-match path so whitespace handling is symmetric across both
  branches (Greptile review).

* fix(web): expand collapsed tool-call groups in e2e config-management assertions

Once a turn completes, consecutive tool-call messages collapse into a
"{N} tool call(s)" group header, hiding the individual prettified titles
the test asserts against. The previous tests passed by lucky substring
match against the script directives in the user prompt; once
prettification removed `*_kandev` from the chat surface that
coincidence broke. Add an `expandToolCallGroups` helper that clicks
each group header before running the title visibility assertions.

* refactor(web): trim ACRONYMS to only entries used by current Kandev tool catalog

Per "no speculative code" guideline (Claude review): only `mcp` is
produced by the current 29-tool catalog. Remove the unused
id/url/api/ui/vs/ide/cli entries; add new ones when a catalog tool
first needs them.

* fix(web): strip MCP namespace prefix when prettifying Kandev tool titles

Codex passes the tool name as `<server>/<tool>` (e.g.
`kandev/get_task_plan_kandev`), so the bare-suffix regex didn't match
and the raw underscored name leaked through to the chat. Split on
`/` or `__` and prettify the trailing segment, covering Codex's
`server/tool` and Claude's `mcp__server__tool` naming alike.
2026-05-10 18:50:32 +01:00

20 lines
775 B
TypeScript

const KANDEV_TOOL_RE = /^[a-z][a-z0-9_]*_kandev$/;
// Different agents prefix MCP tools differently: Claude Code passes the bare
// tool name, Codex passes `<server>/<tool>`, others may use `mcp__<server>__`.
const NAMESPACE_SEP = /\/|__/;
const ACRONYMS = new Set(["mcp"]);
export function prettifyToolTitle(raw: string): string {
if (!raw) return raw;
const trimmed = raw.trim();
const segments = trimmed.split(NAMESPACE_SEP);
const tail = segments[segments.length - 1];
if (!KANDEV_TOOL_RE.test(tail)) return trimmed;
const stem = tail.slice(0, -"_kandev".length);
const words = stem
.split("_")
.filter(Boolean)
.map((w) => (ACRONYMS.has(w) ? w.toUpperCase() : w.charAt(0).toUpperCase() + w.slice(1)));
return `Kandev: ${words.join(" ")}`;
}