Problem
The handleTool() switch statement in src/toolLayer.ts has 45 cases and a default branch that throws "Unknown tool: {name}" at runtime. There is no compile-time check that all tools listed in src/toolSpecs.ts have a corresponding handler.
Adding a new tool to toolSpecs.ts (or renaming one) without updating the switch silently compiles and only fails at runtime — either via the "Unknown tool" error path or, worse, hitting the wrong handler if case strings drift.
Proposed Approach
- Narrow the
name parameter type in the switch to the union of all tool name string literals (derive it from toolSpecs with typeof TOOLS[number]["name"]).
- Add an exhaustiveness assertion on the default branch:
default: {
const _never: never = name;
throw new Error(`Unknown tool: ${_never}`);
}
With the name type narrowed, TypeScript will error at compile time if any case is missing — the never assignment fails to type-check.
This is a one-time safety net: every future tool addition either gets a handler or breaks bun run typecheck.
Affected Files
src/toolLayer.ts — default branch of the handleTool switch
src/toolSpecs.ts — source of the tool name union type
Problem
The
handleTool()switch statement insrc/toolLayer.tshas 45 cases and a default branch that throws"Unknown tool: {name}"at runtime. There is no compile-time check that all tools listed insrc/toolSpecs.tshave a corresponding handler.Adding a new tool to
toolSpecs.ts(or renaming one) without updating the switch silently compiles and only fails at runtime — either via the"Unknown tool"error path or, worse, hitting the wrong handler if case strings drift.Proposed Approach
nameparameter type in the switch to the union of all tool name string literals (derive it fromtoolSpecswithtypeof TOOLS[number]["name"]).With the name type narrowed, TypeScript will error at compile time if any case is missing — the
neverassignment fails to type-check.This is a one-time safety net: every future tool addition either gets a handler or breaks
bun run typecheck.Affected Files
src/toolLayer.ts— default branch of thehandleToolswitchsrc/toolSpecs.ts— source of the tool name union type