mirror of
https://github.com/codeaashu/claude-code.git
synced 2026-04-08 22:28:48 +03:00
claude-code
This commit is contained in:
47
src/tools/REPLTool/constants.ts
Normal file
47
src/tools/REPLTool/constants.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { isEnvDefinedFalsy, isEnvTruthy } from '../../utils/envUtils.js'
|
||||
import { AGENT_TOOL_NAME } from '../AgentTool/constants.js'
|
||||
import { BASH_TOOL_NAME } from '../BashTool/toolName.js'
|
||||
import { FILE_EDIT_TOOL_NAME } from '../FileEditTool/constants.js'
|
||||
import { FILE_READ_TOOL_NAME } from '../FileReadTool/prompt.js'
|
||||
import { FILE_WRITE_TOOL_NAME } from '../FileWriteTool/prompt.js'
|
||||
import { GLOB_TOOL_NAME } from '../GlobTool/prompt.js'
|
||||
import { GREP_TOOL_NAME } from '../GrepTool/prompt.js'
|
||||
import { NOTEBOOK_EDIT_TOOL_NAME } from '../NotebookEditTool/constants.js'
|
||||
|
||||
export const REPL_TOOL_NAME = 'REPL'
|
||||
|
||||
/**
|
||||
* REPL mode is default-on for ants in the interactive CLI (opt out with
|
||||
* CLAUDE_CODE_REPL=0). The legacy CLAUDE_REPL_MODE=1 also forces it on.
|
||||
*
|
||||
* SDK entrypoints (sdk-ts, sdk-py, sdk-cli) are NOT defaulted on — SDK
|
||||
* consumers script direct tool calls (Bash, Read, etc.) and REPL mode
|
||||
* hides those tools. USER_TYPE is a build-time --define, so the ant-native
|
||||
* binary would otherwise force REPL mode on every SDK subprocess regardless
|
||||
* of the env the caller passes.
|
||||
*/
|
||||
export function isReplModeEnabled(): boolean {
|
||||
if (isEnvDefinedFalsy(process.env.CLAUDE_CODE_REPL)) return false
|
||||
if (isEnvTruthy(process.env.CLAUDE_REPL_MODE)) return true
|
||||
return (
|
||||
process.env.USER_TYPE === 'ant' &&
|
||||
process.env.CLAUDE_CODE_ENTRYPOINT === 'cli'
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tools that are only accessible via REPL when REPL mode is enabled.
|
||||
* When REPL mode is on, these tools are hidden from Claude's direct use,
|
||||
* forcing Claude to use REPL for batch operations.
|
||||
*/
|
||||
export const REPL_ONLY_TOOLS = new Set([
|
||||
FILE_READ_TOOL_NAME,
|
||||
FILE_WRITE_TOOL_NAME,
|
||||
FILE_EDIT_TOOL_NAME,
|
||||
GLOB_TOOL_NAME,
|
||||
GREP_TOOL_NAME,
|
||||
BASH_TOOL_NAME,
|
||||
NOTEBOOK_EDIT_TOOL_NAME,
|
||||
AGENT_TOOL_NAME,
|
||||
])
|
||||
|
||||
40
src/tools/REPLTool/primitiveTools.ts
Normal file
40
src/tools/REPLTool/primitiveTools.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import type { Tool } from '../../Tool.js'
|
||||
import { AgentTool } from '../AgentTool/AgentTool.js'
|
||||
import { BashTool } from '../BashTool/BashTool.js'
|
||||
import { FileEditTool } from '../FileEditTool/FileEditTool.js'
|
||||
import { FileReadTool } from '../FileReadTool/FileReadTool.js'
|
||||
import { FileWriteTool } from '../FileWriteTool/FileWriteTool.js'
|
||||
import { GlobTool } from '../GlobTool/GlobTool.js'
|
||||
import { GrepTool } from '../GrepTool/GrepTool.js'
|
||||
import { NotebookEditTool } from '../NotebookEditTool/NotebookEditTool.js'
|
||||
|
||||
let _primitiveTools: readonly Tool[] | undefined
|
||||
|
||||
/**
|
||||
* Primitive tools hidden from direct model use when REPL mode is on
|
||||
* (REPL_ONLY_TOOLS) but still accessible inside the REPL VM context.
|
||||
* Exported so display-side code (collapseReadSearch, renderers) can
|
||||
* classify/render virtual messages for these tools even when they're
|
||||
* absent from the filtered execution tools list.
|
||||
*
|
||||
* Lazy getter — the import chain collapseReadSearch.ts → primitiveTools.ts
|
||||
* → FileReadTool.tsx → ... loops back through the tool registry, so a
|
||||
* top-level const hits "Cannot access before initialization". Deferring
|
||||
* to call time avoids the TDZ.
|
||||
*
|
||||
* Referenced directly rather than via getAllBaseTools() because that
|
||||
* excludes Glob/Grep when hasEmbeddedSearchTools() is true.
|
||||
*/
|
||||
export function getReplPrimitiveTools(): readonly Tool[] {
|
||||
return (_primitiveTools ??= [
|
||||
FileReadTool,
|
||||
FileWriteTool,
|
||||
FileEditTool,
|
||||
GlobTool,
|
||||
GrepTool,
|
||||
BashTool,
|
||||
NotebookEditTool,
|
||||
AgentTool,
|
||||
])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user