/ tools / REPLTool / primitiveTools.ts
primitiveTools.ts
 1  import type { Tool } from '../../Tool.js'
 2  import { AgentTool } from '../AgentTool/AgentTool.js'
 3  import { BashTool } from '../BashTool/BashTool.js'
 4  import { FileEditTool } from '../FileEditTool/FileEditTool.js'
 5  import { FileReadTool } from '../FileReadTool/FileReadTool.js'
 6  import { FileWriteTool } from '../FileWriteTool/FileWriteTool.js'
 7  import { GlobTool } from '../GlobTool/GlobTool.js'
 8  import { GrepTool } from '../GrepTool/GrepTool.js'
 9  import { NotebookEditTool } from '../NotebookEditTool/NotebookEditTool.js'
10  
11  let _primitiveTools: readonly Tool[] | undefined
12  
13  /**
14   * Primitive tools hidden from direct model use when REPL mode is on
15   * (REPL_ONLY_TOOLS) but still accessible inside the REPL VM context.
16   * Exported so display-side code (collapseReadSearch, renderers) can
17   * classify/render virtual messages for these tools even when they're
18   * absent from the filtered execution tools list.
19   *
20   * Lazy getter — the import chain collapseReadSearch.ts → primitiveTools.ts
21   * → FileReadTool.tsx → ... loops back through the tool registry, so a
22   * top-level const hits "Cannot access before initialization". Deferring
23   * to call time avoids the TDZ.
24   *
25   * Referenced directly rather than via getAllBaseTools() because that
26   * excludes Glob/Grep when hasEmbeddedSearchTools() is true.
27   */
28  export function getReplPrimitiveTools(): readonly Tool[] {
29    return (_primitiveTools ??= [
30      FileReadTool,
31      FileWriteTool,
32      FileEditTool,
33      GlobTool,
34      GrepTool,
35      BashTool,
36      NotebookEditTool,
37      AgentTool,
38    ])
39  }