Skip to content

refactor: Replace ALL_INTERNAL_TOOL_NAMES_CACHE lazy-init with eager top-level const #769

@jirispilka

Description

@jirispilka

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomers.t-aiIssues owned by the AI team.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions