The module-level `let ALL_INTERNAL_TOOL_NAMES_CACHE: Set | null = null`
pattern in `src/utils/tools_loader.ts` uses lazy initialization unnecessarily.
All inputs (`getCategoryTools`, `CATEGORY_NAMES`, `WIDGET_BY_BASE_TOOL`) are
module-level constants available at import time. The computation is cheap and
always runs on the first request anyway.
Replace with an eager top-level `const` built via an IIFE:
const ALL_INTERNAL_TOOL_NAMES: Set<string> = (() => {
const names = new Set<string>();
for (const mode of SERVER_MODES) {
const categories = getCategoryTools(mode);
for (const name of CATEGORY_NAMES) {
for (const tool of categories[name]) names.add(tool.name);
}
}
for (const widget of WIDGET_BY_BASE_TOOL.values()) names.add(widget.name);
return names;
})();
Benefits:
- Removes mutable global state (`let` → `const`)
- Removes the null-check indirection
- Makes the invariant explicit: the set is stable for the process lifetime
The module-level `let ALL_INTERNAL_TOOL_NAMES_CACHE: Set | null = null`
pattern in `src/utils/tools_loader.ts` uses lazy initialization unnecessarily.
All inputs (`getCategoryTools`, `CATEGORY_NAMES`, `WIDGET_BY_BASE_TOOL`) are
module-level constants available at import time. The computation is cheap and
always runs on the first request anyway.
Replace with an eager top-level `const` built via an IIFE:
Benefits: