@librechat/agents 3.2.31 → 3.2.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/cjs/agents/AgentContext.cjs +844 -1046
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/common/constants.cjs +13 -13
- package/dist/cjs/common/constants.cjs.map +1 -1
- package/dist/cjs/common/enum.cjs +233 -240
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/common/index.cjs +2 -0
- package/dist/cjs/events.cjs +121 -169
- package/dist/cjs/events.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +1389 -1807
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +713 -945
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/graphs/index.cjs +2 -0
- package/dist/cjs/hitl/askUserQuestion.cjs +60 -62
- package/dist/cjs/hitl/askUserQuestion.cjs.map +1 -1
- package/dist/cjs/hitl/index.cjs +1 -0
- package/dist/cjs/hooks/HookRegistry.cjs +176 -202
- package/dist/cjs/hooks/HookRegistry.cjs.map +1 -1
- package/dist/cjs/hooks/createToolPolicyHook.cjs +71 -101
- package/dist/cjs/hooks/createToolPolicyHook.cjs.map +1 -1
- package/dist/cjs/hooks/createWorkspacePolicyHook.cjs +170 -273
- package/dist/cjs/hooks/createWorkspacePolicyHook.cjs.map +1 -1
- package/dist/cjs/hooks/executeHooks.cjs +227 -282
- package/dist/cjs/hooks/executeHooks.cjs.map +1 -1
- package/dist/cjs/hooks/index.cjs +6 -0
- package/dist/cjs/hooks/matchers.cjs +196 -230
- package/dist/cjs/hooks/matchers.cjs.map +1 -1
- package/dist/cjs/hooks/types.cjs +24 -24
- package/dist/cjs/hooks/types.cjs.map +1 -1
- package/dist/cjs/instrumentation.cjs +110 -137
- package/dist/cjs/instrumentation.cjs.map +1 -1
- package/dist/cjs/langchain/google-common.cjs +0 -3
- package/dist/cjs/langchain/index.cjs +80 -43
- package/dist/cjs/langchain/language_models/chat_models.cjs +0 -3
- package/dist/cjs/langchain/messages/tool.cjs +0 -3
- package/dist/cjs/langchain/messages.cjs +35 -18
- package/dist/cjs/langchain/openai.cjs +0 -3
- package/dist/cjs/langchain/prompts.cjs +5 -8
- package/dist/cjs/langchain/runnables.cjs +11 -10
- package/dist/cjs/langchain/tools.cjs +14 -11
- package/dist/cjs/langchain/utils/env.cjs +5 -8
- package/dist/cjs/langfuse.cjs +60 -79
- package/dist/cjs/langfuse.cjs.map +1 -1
- package/dist/cjs/langfuseToolOutputTracing.cjs +267 -399
- package/dist/cjs/langfuseToolOutputTracing.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/index.cjs +432 -562
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/types.cjs +23 -47
- package/dist/cjs/llm/anthropic/types.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +441 -696
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +171 -252
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/output_parsers.cjs +2 -0
- package/dist/cjs/llm/anthropic/utils/tools.cjs +12 -26
- package/dist/cjs/llm/anthropic/utils/tools.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +195 -240
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/toolCache.cjs +84 -106
- package/dist/cjs/llm/bedrock/toolCache.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/utils/index.cjs +2 -0
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs +357 -620
- package/dist/cjs/llm/bedrock/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/utils/message_outputs.cjs +105 -149
- package/dist/cjs/llm/bedrock/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/llm/fake.cjs +86 -96
- package/dist/cjs/llm/fake.cjs.map +1 -1
- package/dist/cjs/llm/google/index.cjs +183 -237
- package/dist/cjs/llm/google/index.cjs.map +1 -1
- package/dist/cjs/llm/google/utils/common.cjs +398 -674
- package/dist/cjs/llm/google/utils/common.cjs.map +1 -1
- package/dist/cjs/llm/google/utils/zod_to_genai_parameters.cjs +2 -0
- package/dist/cjs/llm/init.cjs +44 -53
- package/dist/cjs/llm/init.cjs.map +1 -1
- package/dist/cjs/llm/invoke.cjs +142 -182
- package/dist/cjs/llm/invoke.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +991 -1276
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs +189 -316
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
- package/dist/cjs/llm/openrouter/index.cjs +102 -153
- package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
- package/dist/cjs/llm/openrouter/toolCache.cjs +35 -44
- package/dist/cjs/llm/openrouter/toolCache.cjs.map +1 -1
- package/dist/cjs/llm/providers.cjs +29 -37
- package/dist/cjs/llm/providers.cjs.map +1 -1
- package/dist/cjs/llm/request.cjs +20 -33
- package/dist/cjs/llm/request.cjs.map +1 -1
- package/dist/cjs/llm/vertexai/index.cjs +427 -453
- package/dist/cjs/llm/vertexai/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +547 -528
- package/dist/cjs/messages/anthropicToolCache.cjs +68 -119
- package/dist/cjs/messages/anthropicToolCache.cjs.map +1 -1
- package/dist/cjs/messages/cache.cjs +308 -401
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/content.cjs +36 -49
- package/dist/cjs/messages/content.cjs.map +1 -1
- package/dist/cjs/messages/contextPruning.cjs +112 -145
- package/dist/cjs/messages/contextPruning.cjs.map +1 -1
- package/dist/cjs/messages/contextPruningSettings.cjs +36 -46
- package/dist/cjs/messages/contextPruningSettings.cjs.map +1 -1
- package/dist/cjs/messages/core.cjs +256 -397
- package/dist/cjs/messages/core.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +904 -1382
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/messages/ids.cjs +16 -20
- package/dist/cjs/messages/ids.cjs.map +1 -1
- package/dist/cjs/messages/index.cjs +12 -0
- package/dist/cjs/messages/langchain.cjs +18 -18
- package/dist/cjs/messages/langchain.cjs.map +1 -1
- package/dist/cjs/messages/prune.cjs +1054 -1517
- package/dist/cjs/messages/prune.cjs.map +1 -1
- package/dist/cjs/messages/recency.cjs +77 -95
- package/dist/cjs/messages/recency.cjs.map +1 -1
- package/dist/cjs/messages/reducer.cjs +63 -78
- package/dist/cjs/messages/reducer.cjs.map +1 -1
- package/dist/cjs/messages/tools.cjs +51 -79
- package/dist/cjs/messages/tools.cjs.map +1 -1
- package/dist/cjs/openai/index.cjs +171 -217
- package/dist/cjs/openai/index.cjs.map +1 -1
- package/dist/cjs/responses/index.cjs +302 -391
- package/dist/cjs/responses/index.cjs.map +1 -1
- package/dist/cjs/run.cjs +903 -1113
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/session/AgentSession.cjs +805 -986
- package/dist/cjs/session/AgentSession.cjs.map +1 -1
- package/dist/cjs/session/JsonlSessionStore.cjs +327 -410
- package/dist/cjs/session/JsonlSessionStore.cjs.map +1 -1
- package/dist/cjs/session/handlers.cjs +192 -208
- package/dist/cjs/session/handlers.cjs.map +1 -1
- package/dist/cjs/session/ids.cjs +9 -10
- package/dist/cjs/session/ids.cjs.map +1 -1
- package/dist/cjs/session/index.cjs +4 -0
- package/dist/cjs/session/messageSerialization.cjs +94 -156
- package/dist/cjs/session/messageSerialization.cjs.map +1 -1
- package/dist/cjs/splitStream.cjs +147 -206
- package/dist/cjs/splitStream.cjs.map +1 -1
- package/dist/cjs/stream.cjs +856 -1344
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/summarization/index.cjs +57 -101
- package/dist/cjs/summarization/index.cjs.map +1 -1
- package/dist/cjs/summarization/node.cjs +643 -796
- package/dist/cjs/summarization/node.cjs.map +1 -1
- package/dist/cjs/tools/BashExecutor.cjs +110 -136
- package/dist/cjs/tools/BashExecutor.cjs.map +1 -1
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +165 -245
- package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/Calculator.cjs +36 -57
- package/dist/cjs/tools/Calculator.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +126 -168
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/CodeSessionFileSummary.cjs +36 -46
- package/dist/cjs/tools/CodeSessionFileSummary.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +459 -649
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/ReadFile.cjs +17 -20
- package/dist/cjs/tools/ReadFile.cjs.map +1 -1
- package/dist/cjs/tools/SkillTool.cjs +26 -27
- package/dist/cjs/tools/SkillTool.cjs.map +1 -1
- package/dist/cjs/tools/SubagentTool.cjs +59 -61
- package/dist/cjs/tools/SubagentTool.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +2109 -2686
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/ToolSearch.cjs +663 -825
- package/dist/cjs/tools/ToolSearch.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareBridgeRuntime.cjs +248 -340
- package/dist/cjs/tools/cloudflare/CloudflareBridgeRuntime.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareProgrammaticToolCalling.cjs +170 -197
- package/dist/cjs/tools/cloudflare/CloudflareProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs +425 -520
- package/dist/cjs/tools/cloudflare/CloudflareSandboxExecutionEngine.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/CloudflareSandboxTools.cjs +91 -124
- package/dist/cjs/tools/cloudflare/CloudflareSandboxTools.cjs.map +1 -1
- package/dist/cjs/tools/cloudflare/index.cjs +4 -0
- package/dist/cjs/tools/eagerEventExecution.cjs +75 -99
- package/dist/cjs/tools/eagerEventExecution.cjs.map +1 -1
- package/dist/cjs/tools/handlers.cjs +200 -262
- package/dist/cjs/tools/handlers.cjs.map +1 -1
- package/dist/cjs/tools/local/CompileCheckTool.cjs +150 -212
- package/dist/cjs/tools/local/CompileCheckTool.cjs.map +1 -1
- package/dist/cjs/tools/local/FileCheckpointer.cjs +77 -85
- package/dist/cjs/tools/local/FileCheckpointer.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalCodingTools.cjs +763 -1022
- package/dist/cjs/tools/local/LocalCodingTools.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs +666 -941
- package/dist/cjs/tools/local/LocalExecutionEngine.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalExecutionTools.cjs +49 -92
- package/dist/cjs/tools/local/LocalExecutionTools.cjs.map +1 -1
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs +286 -354
- package/dist/cjs/tools/local/LocalProgrammaticToolCalling.cjs.map +1 -1
- package/dist/cjs/tools/local/attachments.cjs +108 -165
- package/dist/cjs/tools/local/attachments.cjs.map +1 -1
- package/dist/cjs/tools/local/bashAst.cjs +99 -113
- package/dist/cjs/tools/local/bashAst.cjs.map +1 -1
- package/dist/cjs/tools/local/editStrategies.cjs +126 -169
- package/dist/cjs/tools/local/editStrategies.cjs.map +1 -1
- package/dist/cjs/tools/local/index.cjs +12 -0
- package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs +136 -218
- package/dist/cjs/tools/local/resolveLocalExecutionTools.cjs.map +1 -1
- package/dist/cjs/tools/local/syntaxCheck.cjs +142 -161
- package/dist/cjs/tools/local/syntaxCheck.cjs.map +1 -1
- package/dist/cjs/tools/local/textEncoding.cjs +25 -23
- package/dist/cjs/tools/local/textEncoding.cjs.map +1 -1
- package/dist/cjs/tools/local/workspaceFS.cjs +38 -46
- package/dist/cjs/tools/local/workspaceFS.cjs.map +1 -1
- package/dist/cjs/tools/ptcTimeout.cjs +27 -47
- package/dist/cjs/tools/ptcTimeout.cjs.map +1 -1
- package/dist/cjs/tools/schema.cjs +24 -23
- package/dist/cjs/tools/schema.cjs.map +1 -1
- package/dist/cjs/tools/search/anthropic.cjs +24 -33
- package/dist/cjs/tools/search/anthropic.cjs.map +1 -1
- package/dist/cjs/tools/search/content.cjs +95 -137
- package/dist/cjs/tools/search/content.cjs.map +1 -1
- package/dist/cjs/tools/search/firecrawl.cjs +141 -172
- package/dist/cjs/tools/search/firecrawl.cjs.map +1 -1
- package/dist/cjs/tools/search/format.cjs +128 -196
- package/dist/cjs/tools/search/format.cjs.map +1 -1
- package/dist/cjs/tools/search/highlights.cjs +165 -232
- package/dist/cjs/tools/search/highlights.cjs.map +1 -1
- package/dist/cjs/tools/search/index.cjs +2 -0
- package/dist/cjs/tools/search/rerankers.cjs +151 -174
- package/dist/cjs/tools/search/rerankers.cjs.map +1 -1
- package/dist/cjs/tools/search/schema.cjs +40 -39
- package/dist/cjs/tools/search/schema.cjs.map +1 -1
- package/dist/cjs/tools/search/search.cjs +428 -530
- package/dist/cjs/tools/search/search.cjs.map +1 -1
- package/dist/cjs/tools/search/serper-scraper.cjs +106 -127
- package/dist/cjs/tools/search/serper-scraper.cjs.map +1 -1
- package/dist/cjs/tools/search/tavily-scraper.cjs +129 -181
- package/dist/cjs/tools/search/tavily-scraper.cjs.map +1 -1
- package/dist/cjs/tools/search/tavily-search.cjs +295 -359
- package/dist/cjs/tools/search/tavily-search.cjs.map +1 -1
- package/dist/cjs/tools/search/tool.cjs +260 -299
- package/dist/cjs/tools/search/tool.cjs.map +1 -1
- package/dist/cjs/tools/search/utils.cjs +74 -117
- package/dist/cjs/tools/search/utils.cjs.map +1 -1
- package/dist/cjs/tools/skillCatalog.cjs +54 -72
- package/dist/cjs/tools/skillCatalog.cjs.map +1 -1
- package/dist/cjs/tools/streamedToolCallSeals.cjs +19 -36
- package/dist/cjs/tools/streamedToolCallSeals.cjs.map +1 -1
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs +612 -771
- package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -1
- package/dist/cjs/tools/subagent/index.cjs +1 -0
- package/dist/cjs/tools/toolOutputReferences.cjs +523 -630
- package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -1
- package/dist/cjs/utils/callbacks.cjs +11 -21
- package/dist/cjs/utils/callbacks.cjs.map +1 -1
- package/dist/cjs/utils/errors.cjs +70 -95
- package/dist/cjs/utils/errors.cjs.map +1 -1
- package/dist/cjs/utils/events.cjs +32 -42
- package/dist/cjs/utils/events.cjs.map +1 -1
- package/dist/cjs/utils/graph.cjs +8 -12
- package/dist/cjs/utils/graph.cjs.map +1 -1
- package/dist/cjs/utils/handlers.cjs +60 -82
- package/dist/cjs/utils/handlers.cjs.map +1 -1
- package/dist/cjs/utils/index.cjs +9 -0
- package/dist/cjs/utils/llm.cjs +19 -27
- package/dist/cjs/utils/llm.cjs.map +1 -1
- package/dist/cjs/utils/misc.cjs +30 -46
- package/dist/cjs/utils/misc.cjs.map +1 -1
- package/dist/cjs/utils/run.cjs +50 -66
- package/dist/cjs/utils/run.cjs.map +1 -1
- package/dist/cjs/utils/schema.cjs +11 -19
- package/dist/cjs/utils/schema.cjs.map +1 -1
- package/dist/cjs/utils/title.cjs +71 -106
- package/dist/cjs/utils/title.cjs.map +1 -1
- package/dist/cjs/utils/tokens.cjs +186 -283
- package/dist/cjs/utils/tokens.cjs.map +1 -1
- package/dist/cjs/utils/truncation.cjs +95 -114
- package/dist/cjs/utils/truncation.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +844 -1044
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/common/constants.mjs +13 -11
- package/dist/esm/common/constants.mjs.map +1 -1
- package/dist/esm/common/enum.mjs +221 -238
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/common/index.mjs +3 -0
- package/dist/esm/events.mjs +121 -167
- package/dist/esm/events.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +1388 -1804
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +713 -943
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/graphs/index.mjs +3 -0
- package/dist/esm/hitl/askUserQuestion.mjs +60 -60
- package/dist/esm/hitl/askUserQuestion.mjs.map +1 -1
- package/dist/esm/hitl/index.mjs +2 -0
- package/dist/esm/hooks/HookRegistry.mjs +176 -200
- package/dist/esm/hooks/HookRegistry.mjs.map +1 -1
- package/dist/esm/hooks/createToolPolicyHook.mjs +71 -99
- package/dist/esm/hooks/createToolPolicyHook.mjs.map +1 -1
- package/dist/esm/hooks/createWorkspacePolicyHook.mjs +170 -271
- package/dist/esm/hooks/createWorkspacePolicyHook.mjs.map +1 -1
- package/dist/esm/hooks/executeHooks.mjs +227 -280
- package/dist/esm/hooks/executeHooks.mjs.map +1 -1
- package/dist/esm/hooks/index.mjs +7 -0
- package/dist/esm/hooks/matchers.mjs +196 -228
- package/dist/esm/hooks/matchers.mjs.map +1 -1
- package/dist/esm/hooks/types.mjs +24 -22
- package/dist/esm/hooks/types.mjs.map +1 -1
- package/dist/esm/instrumentation.mjs +109 -132
- package/dist/esm/instrumentation.mjs.map +1 -1
- package/dist/esm/langchain/google-common.mjs +1 -2
- package/dist/esm/langchain/index.mjs +5 -5
- package/dist/esm/langchain/language_models/chat_models.mjs +1 -2
- package/dist/esm/langchain/messages/tool.mjs +1 -2
- package/dist/esm/langchain/messages.mjs +2 -2
- package/dist/esm/langchain/openai.mjs +1 -2
- package/dist/esm/langchain/prompts.mjs +2 -2
- package/dist/esm/langchain/runnables.mjs +2 -2
- package/dist/esm/langchain/tools.mjs +2 -2
- package/dist/esm/langchain/utils/env.mjs +2 -2
- package/dist/esm/langfuse.mjs +60 -76
- package/dist/esm/langfuse.mjs.map +1 -1
- package/dist/esm/langfuseToolOutputTracing.mjs +267 -395
- package/dist/esm/langfuseToolOutputTracing.mjs.map +1 -1
- package/dist/esm/llm/anthropic/index.mjs +432 -559
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/anthropic/types.mjs +23 -45
- package/dist/esm/llm/anthropic/types.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs +439 -690
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs +171 -249
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/output_parsers.mjs +3 -0
- package/dist/esm/llm/anthropic/utils/tools.mjs +12 -24
- package/dist/esm/llm/anthropic/utils/tools.mjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +195 -238
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/llm/bedrock/toolCache.mjs +84 -104
- package/dist/esm/llm/bedrock/toolCache.mjs.map +1 -1
- package/dist/esm/llm/bedrock/utils/index.mjs +3 -0
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs +357 -618
- package/dist/esm/llm/bedrock/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/bedrock/utils/message_outputs.mjs +105 -147
- package/dist/esm/llm/bedrock/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/llm/fake.mjs +86 -94
- package/dist/esm/llm/fake.mjs.map +1 -1
- package/dist/esm/llm/google/index.mjs +183 -235
- package/dist/esm/llm/google/index.mjs.map +1 -1
- package/dist/esm/llm/google/utils/common.mjs +397 -666
- package/dist/esm/llm/google/utils/common.mjs.map +1 -1
- package/dist/esm/llm/google/utils/zod_to_genai_parameters.mjs +3 -0
- package/dist/esm/llm/init.mjs +44 -51
- package/dist/esm/llm/init.mjs.map +1 -1
- package/dist/esm/llm/invoke.mjs +142 -180
- package/dist/esm/llm/invoke.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +991 -1271
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/utils/index.mjs +188 -312
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
- package/dist/esm/llm/openrouter/index.mjs +102 -151
- package/dist/esm/llm/openrouter/index.mjs.map +1 -1
- package/dist/esm/llm/openrouter/toolCache.mjs +35 -42
- package/dist/esm/llm/openrouter/toolCache.mjs.map +1 -1
- package/dist/esm/llm/providers.mjs +29 -34
- package/dist/esm/llm/providers.mjs.map +1 -1
- package/dist/esm/llm/request.mjs +20 -31
- package/dist/esm/llm/request.mjs.map +1 -1
- package/dist/esm/llm/vertexai/index.mjs +427 -449
- package/dist/esm/llm/vertexai/index.mjs.map +1 -1
- package/dist/esm/main.mjs +99 -87
- package/dist/esm/messages/anthropicToolCache.mjs +68 -117
- package/dist/esm/messages/anthropicToolCache.mjs.map +1 -1
- package/dist/esm/messages/cache.mjs +308 -399
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/content.mjs +36 -47
- package/dist/esm/messages/content.mjs.map +1 -1
- package/dist/esm/messages/contextPruning.mjs +112 -143
- package/dist/esm/messages/contextPruning.mjs.map +1 -1
- package/dist/esm/messages/contextPruningSettings.mjs +36 -44
- package/dist/esm/messages/contextPruningSettings.mjs.map +1 -1
- package/dist/esm/messages/core.mjs +254 -393
- package/dist/esm/messages/core.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +902 -1378
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/messages/ids.mjs +16 -18
- package/dist/esm/messages/ids.mjs.map +1 -1
- package/dist/esm/messages/index.mjs +13 -0
- package/dist/esm/messages/langchain.mjs +18 -16
- package/dist/esm/messages/langchain.mjs.map +1 -1
- package/dist/esm/messages/prune.mjs +1053 -1514
- package/dist/esm/messages/prune.mjs.map +1 -1
- package/dist/esm/messages/recency.mjs +77 -93
- package/dist/esm/messages/recency.mjs.map +1 -1
- package/dist/esm/messages/reducer.mjs +63 -76
- package/dist/esm/messages/reducer.mjs.map +1 -1
- package/dist/esm/messages/tools.mjs +49 -75
- package/dist/esm/messages/tools.mjs.map +1 -1
- package/dist/esm/openai/index.mjs +170 -215
- package/dist/esm/openai/index.mjs.map +1 -1
- package/dist/esm/responses/index.mjs +301 -389
- package/dist/esm/responses/index.mjs.map +1 -1
- package/dist/esm/run.mjs +903 -1111
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/session/AgentSession.mjs +806 -985
- package/dist/esm/session/AgentSession.mjs.map +1 -1
- package/dist/esm/session/JsonlSessionStore.mjs +326 -407
- package/dist/esm/session/JsonlSessionStore.mjs.map +1 -1
- package/dist/esm/session/handlers.mjs +192 -206
- package/dist/esm/session/handlers.mjs.map +1 -1
- package/dist/esm/session/ids.mjs +9 -8
- package/dist/esm/session/ids.mjs.map +1 -1
- package/dist/esm/session/index.mjs +5 -0
- package/dist/esm/session/messageSerialization.mjs +94 -154
- package/dist/esm/session/messageSerialization.mjs.map +1 -1
- package/dist/esm/splitStream.mjs +147 -204
- package/dist/esm/splitStream.mjs.map +1 -1
- package/dist/esm/stream.mjs +854 -1341
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/summarization/index.mjs +57 -99
- package/dist/esm/summarization/index.mjs.map +1 -1
- package/dist/esm/summarization/node.mjs +640 -790
- package/dist/esm/summarization/node.mjs.map +1 -1
- package/dist/esm/tools/BashExecutor.mjs +103 -129
- package/dist/esm/tools/BashExecutor.mjs.map +1 -1
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs +162 -239
- package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/Calculator.mjs +34 -36
- package/dist/esm/tools/Calculator.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +123 -164
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/CodeSessionFileSummary.mjs +36 -44
- package/dist/esm/tools/CodeSessionFileSummary.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +454 -644
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/ReadFile.mjs +17 -18
- package/dist/esm/tools/ReadFile.mjs.map +1 -1
- package/dist/esm/tools/SkillTool.mjs +26 -25
- package/dist/esm/tools/SkillTool.mjs.map +1 -1
- package/dist/esm/tools/SubagentTool.mjs +59 -59
- package/dist/esm/tools/SubagentTool.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +2107 -2684
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/ToolSearch.mjs +659 -804
- package/dist/esm/tools/ToolSearch.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareBridgeRuntime.mjs +248 -338
- package/dist/esm/tools/cloudflare/CloudflareBridgeRuntime.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareProgrammaticToolCalling.mjs +170 -195
- package/dist/esm/tools/cloudflare/CloudflareProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs +424 -517
- package/dist/esm/tools/cloudflare/CloudflareSandboxExecutionEngine.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/CloudflareSandboxTools.mjs +91 -122
- package/dist/esm/tools/cloudflare/CloudflareSandboxTools.mjs.map +1 -1
- package/dist/esm/tools/cloudflare/index.mjs +5 -0
- package/dist/esm/tools/eagerEventExecution.mjs +75 -96
- package/dist/esm/tools/eagerEventExecution.mjs.map +1 -1
- package/dist/esm/tools/handlers.mjs +200 -260
- package/dist/esm/tools/handlers.mjs.map +1 -1
- package/dist/esm/tools/local/CompileCheckTool.mjs +150 -210
- package/dist/esm/tools/local/CompileCheckTool.mjs.map +1 -1
- package/dist/esm/tools/local/FileCheckpointer.mjs +77 -83
- package/dist/esm/tools/local/FileCheckpointer.mjs.map +1 -1
- package/dist/esm/tools/local/LocalCodingTools.mjs +760 -1017
- package/dist/esm/tools/local/LocalCodingTools.mjs.map +1 -1
- package/dist/esm/tools/local/LocalExecutionEngine.mjs +663 -936
- package/dist/esm/tools/local/LocalExecutionEngine.mjs.map +1 -1
- package/dist/esm/tools/local/LocalExecutionTools.mjs +49 -90
- package/dist/esm/tools/local/LocalExecutionTools.mjs.map +1 -1
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs +283 -349
- package/dist/esm/tools/local/LocalProgrammaticToolCalling.mjs.map +1 -1
- package/dist/esm/tools/local/attachments.mjs +108 -163
- package/dist/esm/tools/local/attachments.mjs.map +1 -1
- package/dist/esm/tools/local/bashAst.mjs +99 -111
- package/dist/esm/tools/local/bashAst.mjs.map +1 -1
- package/dist/esm/tools/local/editStrategies.mjs +126 -167
- package/dist/esm/tools/local/editStrategies.mjs.map +1 -1
- package/dist/esm/tools/local/index.mjs +13 -0
- package/dist/esm/tools/local/resolveLocalExecutionTools.mjs +136 -216
- package/dist/esm/tools/local/resolveLocalExecutionTools.mjs.map +1 -1
- package/dist/esm/tools/local/syntaxCheck.mjs +138 -155
- package/dist/esm/tools/local/syntaxCheck.mjs.map +1 -1
- package/dist/esm/tools/local/textEncoding.mjs +25 -21
- package/dist/esm/tools/local/textEncoding.mjs.map +1 -1
- package/dist/esm/tools/local/workspaceFS.mjs +38 -44
- package/dist/esm/tools/local/workspaceFS.mjs.map +1 -1
- package/dist/esm/tools/ptcTimeout.mjs +27 -42
- package/dist/esm/tools/ptcTimeout.mjs.map +1 -1
- package/dist/esm/tools/schema.mjs +24 -21
- package/dist/esm/tools/schema.mjs.map +1 -1
- package/dist/esm/tools/search/anthropic.mjs +24 -31
- package/dist/esm/tools/search/anthropic.mjs.map +1 -1
- package/dist/esm/tools/search/content.mjs +93 -116
- package/dist/esm/tools/search/content.mjs.map +1 -1
- package/dist/esm/tools/search/firecrawl.mjs +139 -169
- package/dist/esm/tools/search/firecrawl.mjs.map +1 -1
- package/dist/esm/tools/search/format.mjs +128 -194
- package/dist/esm/tools/search/format.mjs.map +1 -1
- package/dist/esm/tools/search/highlights.mjs +165 -230
- package/dist/esm/tools/search/highlights.mjs.map +1 -1
- package/dist/esm/tools/search/index.mjs +3 -0
- package/dist/esm/tools/search/rerankers.mjs +149 -168
- package/dist/esm/tools/search/rerankers.mjs.map +1 -1
- package/dist/esm/tools/search/schema.mjs +39 -37
- package/dist/esm/tools/search/schema.mjs.map +1 -1
- package/dist/esm/tools/search/search.mjs +426 -528
- package/dist/esm/tools/search/search.mjs.map +1 -1
- package/dist/esm/tools/search/serper-scraper.mjs +104 -124
- package/dist/esm/tools/search/serper-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/tavily-scraper.mjs +127 -178
- package/dist/esm/tools/search/tavily-scraper.mjs.map +1 -1
- package/dist/esm/tools/search/tavily-search.mjs +293 -357
- package/dist/esm/tools/search/tavily-search.mjs.map +1 -1
- package/dist/esm/tools/search/tool.mjs +259 -297
- package/dist/esm/tools/search/tool.mjs.map +1 -1
- package/dist/esm/tools/search/utils.mjs +74 -115
- package/dist/esm/tools/search/utils.mjs.map +1 -1
- package/dist/esm/tools/skillCatalog.mjs +54 -70
- package/dist/esm/tools/skillCatalog.mjs.map +1 -1
- package/dist/esm/tools/streamedToolCallSeals.mjs +19 -31
- package/dist/esm/tools/streamedToolCallSeals.mjs.map +1 -1
- package/dist/esm/tools/subagent/SubagentExecutor.mjs +612 -768
- package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -1
- package/dist/esm/tools/subagent/index.mjs +2 -0
- package/dist/esm/tools/toolOutputReferences.mjs +523 -624
- package/dist/esm/tools/toolOutputReferences.mjs.map +1 -1
- package/dist/esm/utils/callbacks.mjs +11 -19
- package/dist/esm/utils/callbacks.mjs.map +1 -1
- package/dist/esm/utils/errors.mjs +70 -93
- package/dist/esm/utils/errors.mjs.map +1 -1
- package/dist/esm/utils/events.mjs +32 -40
- package/dist/esm/utils/events.mjs.map +1 -1
- package/dist/esm/utils/graph.mjs +8 -10
- package/dist/esm/utils/graph.mjs.map +1 -1
- package/dist/esm/utils/handlers.mjs +60 -80
- package/dist/esm/utils/handlers.mjs.map +1 -1
- package/dist/esm/utils/index.mjs +10 -0
- package/dist/esm/utils/llm.mjs +19 -25
- package/dist/esm/utils/llm.mjs.map +1 -1
- package/dist/esm/utils/misc.mjs +30 -44
- package/dist/esm/utils/misc.mjs.map +1 -1
- package/dist/esm/utils/run.mjs +50 -64
- package/dist/esm/utils/run.mjs.map +1 -1
- package/dist/esm/utils/schema.mjs +11 -17
- package/dist/esm/utils/schema.mjs.map +1 -1
- package/dist/esm/utils/title.mjs +71 -104
- package/dist/esm/utils/title.mjs.map +1 -1
- package/dist/esm/utils/tokens.mjs +186 -281
- package/dist/esm/utils/tokens.mjs.map +1 -1
- package/dist/esm/utils/truncation.mjs +95 -112
- package/dist/esm/utils/truncation.mjs.map +1 -1
- package/dist/types/messages/format.d.ts +5 -0
- package/dist/types/tools/search/tool.d.ts +17 -0
- package/dist/types/tools/search/types.d.ts +4 -0
- package/package.json +11 -17
- package/src/llm/anthropic/llm.spec.ts +36 -0
- package/src/llm/anthropic/utils/message_inputs.ts +45 -3
- package/src/llm/anthropic/utils/message_outputs.ts +6 -2
- package/src/llm/anthropic/utils/streaming-tool-input.test.ts +186 -0
- package/src/messages/cache.test.ts +122 -0
- package/src/messages/cache.ts +25 -1
- package/src/messages/format.ts +9 -0
- package/src/messages/formatAgentMessages.skills.test.ts +100 -0
- package/src/tools/search/highlights.ts +9 -1
- package/src/tools/search/search.ts +41 -3
- package/src/tools/search/source-processing.test.ts +373 -0
- package/src/tools/search/tool.ts +22 -2
- package/src/tools/search/types.ts +4 -0
- package/dist/cjs/langchain/google-common.cjs.map +0 -1
- package/dist/cjs/langchain/index.cjs.map +0 -1
- package/dist/cjs/langchain/language_models/chat_models.cjs.map +0 -1
- package/dist/cjs/langchain/messages/tool.cjs.map +0 -1
- package/dist/cjs/langchain/messages.cjs.map +0 -1
- package/dist/cjs/langchain/openai.cjs.map +0 -1
- package/dist/cjs/langchain/prompts.cjs.map +0 -1
- package/dist/cjs/langchain/runnables.cjs.map +0 -1
- package/dist/cjs/langchain/tools.cjs.map +0 -1
- package/dist/cjs/langchain/utils/env.cjs.map +0 -1
- package/dist/cjs/main.cjs.map +0 -1
- package/dist/esm/langchain/google-common.mjs.map +0 -1
- package/dist/esm/langchain/index.mjs.map +0 -1
- package/dist/esm/langchain/language_models/chat_models.mjs.map +0 -1
- package/dist/esm/langchain/messages/tool.mjs.map +0 -1
- package/dist/esm/langchain/messages.mjs.map +0 -1
- package/dist/esm/langchain/openai.mjs.map +0 -1
- package/dist/esm/langchain/prompts.mjs.map +0 -1
- package/dist/esm/langchain/runnables.mjs.map +0 -1
- package/dist/esm/langchain/tools.mjs.map +0 -1
- package/dist/esm/langchain/utils/env.mjs.map +0 -1
- package/dist/esm/main.mjs.map +0 -1
|
@@ -1,1101 +1,844 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { classifyAttachment, imageAttachmentContent } from
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import "../../common/enum.mjs";
|
|
2
|
+
import "../../common/index.mjs";
|
|
3
|
+
import { getSpawn, getWorkspaceFS, resolveWorkspacePathSafe, spawnLocalProcess, truncateLocalOutput } from "./LocalExecutionEngine.mjs";
|
|
4
|
+
import { createCompileCheckTool, createCompileCheckToolDefinition } from "./CompileCheckTool.mjs";
|
|
5
|
+
import { createLocalFileCheckpointer } from "./FileCheckpointer.mjs";
|
|
6
|
+
import { createLocalBashProgrammaticToolCallingTool, createLocalProgrammaticToolCallingTool } from "./LocalProgrammaticToolCalling.mjs";
|
|
7
|
+
import { createLocalBashExecutionTool, createLocalCodeExecutionTool } from "./LocalExecutionTools.mjs";
|
|
8
|
+
import { classifyAttachment, imageAttachmentContent } from "./attachments.mjs";
|
|
9
|
+
import { applyEdit, locateEdit } from "./editStrategies.mjs";
|
|
10
|
+
import { decodeFile, encodeFile } from "./textEncoding.mjs";
|
|
11
|
+
import { runPostEditSyntaxCheck } from "./syntaxCheck.mjs";
|
|
12
|
+
import { tool } from "@langchain/core/tools";
|
|
13
|
+
import { basename, dirname } from "path";
|
|
14
|
+
import { createTwoFilesPatch } from "diff";
|
|
15
|
+
//#region src/tools/local/LocalCodingTools.ts
|
|
16
|
+
const MAX_READ_CHARS = 256e3;
|
|
16
17
|
const DEFAULT_MAX_RESULTS = 200;
|
|
17
18
|
const DEFAULT_MAX_READ_BYTES = 10 * 1024 * 1024;
|
|
18
|
-
const BINARY_DETECTION_BYTES =
|
|
19
|
+
const BINARY_DETECTION_BYTES = 8e3;
|
|
19
20
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const LocalWriteFileToolName =
|
|
26
|
-
const LocalEditFileToolName =
|
|
27
|
-
const LocalGrepSearchToolName =
|
|
28
|
-
const LocalGlobSearchToolName =
|
|
29
|
-
const LocalListDirectoryToolName =
|
|
21
|
+
* Tool name aliases retained for back-compat with consumers that imported
|
|
22
|
+
* the per-file `Local*ToolName` constants. The canonical names live on
|
|
23
|
+
* `Constants.*` (see `src/common/enum.ts`); these aliases just point at
|
|
24
|
+
* them so a typo upstream gets caught at the type level.
|
|
25
|
+
*/
|
|
26
|
+
const LocalWriteFileToolName = "write_file";
|
|
27
|
+
const LocalEditFileToolName = "edit_file";
|
|
28
|
+
const LocalGrepSearchToolName = "grep_search";
|
|
29
|
+
const LocalGlobSearchToolName = "glob_search";
|
|
30
|
+
const LocalListDirectoryToolName = "list_directory";
|
|
30
31
|
const LocalReadFileToolSchema = {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
32
|
+
type: "object",
|
|
33
|
+
properties: {
|
|
34
|
+
file_path: {
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "Path to a local file, relative to the configured cwd unless absolute paths are allowed."
|
|
37
|
+
},
|
|
38
|
+
offset: {
|
|
39
|
+
type: "integer",
|
|
40
|
+
description: "Optional 1-indexed line offset for large files."
|
|
41
|
+
},
|
|
42
|
+
limit: {
|
|
43
|
+
type: "integer",
|
|
44
|
+
description: "Optional maximum number of lines to return."
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
required: ["file_path"]
|
|
47
48
|
};
|
|
48
49
|
const LocalWriteFileToolSchema = {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
type: "object",
|
|
51
|
+
properties: {
|
|
52
|
+
file_path: {
|
|
53
|
+
type: "string",
|
|
54
|
+
description: "Path to write, relative to the configured cwd unless absolute paths are allowed."
|
|
55
|
+
},
|
|
56
|
+
content: {
|
|
57
|
+
type: "string",
|
|
58
|
+
description: "Complete file contents to write."
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
required: ["file_path", "content"]
|
|
61
62
|
};
|
|
62
63
|
const LocalEditFileToolSchema = {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
64
|
+
type: "object",
|
|
65
|
+
properties: {
|
|
66
|
+
file_path: {
|
|
67
|
+
type: "string",
|
|
68
|
+
description: "Path to edit, relative to the configured cwd unless absolute paths are allowed."
|
|
69
|
+
},
|
|
70
|
+
old_text: {
|
|
71
|
+
type: "string",
|
|
72
|
+
description: "Exact text to replace. Must appear exactly once."
|
|
73
|
+
},
|
|
74
|
+
new_text: {
|
|
75
|
+
type: "string",
|
|
76
|
+
description: "Replacement text."
|
|
77
|
+
},
|
|
78
|
+
edits: {
|
|
79
|
+
type: "array",
|
|
80
|
+
description: "Optional batch of exact replacements. Each old_text must appear exactly once in the original file.",
|
|
81
|
+
items: {
|
|
82
|
+
type: "object",
|
|
83
|
+
properties: {
|
|
84
|
+
old_text: { type: "string" },
|
|
85
|
+
new_text: { type: "string" }
|
|
86
|
+
},
|
|
87
|
+
required: ["old_text", "new_text"]
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
required: ["file_path"]
|
|
91
92
|
};
|
|
92
93
|
const LocalGrepSearchToolSchema = {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
94
|
+
type: "object",
|
|
95
|
+
properties: {
|
|
96
|
+
pattern: {
|
|
97
|
+
type: "string",
|
|
98
|
+
description: "Regex pattern to search for."
|
|
99
|
+
},
|
|
100
|
+
path: {
|
|
101
|
+
type: "string",
|
|
102
|
+
description: "Directory or file to search. Defaults to cwd."
|
|
103
|
+
},
|
|
104
|
+
glob: {
|
|
105
|
+
type: "string",
|
|
106
|
+
description: "Optional file glob passed to rg -g."
|
|
107
|
+
},
|
|
108
|
+
max_results: {
|
|
109
|
+
type: "integer",
|
|
110
|
+
description: "Maximum matching lines to return."
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
required: ["pattern"]
|
|
113
114
|
};
|
|
114
115
|
const LocalGlobSearchToolSchema = {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
116
|
+
type: "object",
|
|
117
|
+
properties: {
|
|
118
|
+
pattern: {
|
|
119
|
+
type: "string",
|
|
120
|
+
description: "File glob pattern, for example \"src/**/*.ts\"."
|
|
121
|
+
},
|
|
122
|
+
path: {
|
|
123
|
+
type: "string",
|
|
124
|
+
description: "Directory to search. Defaults to cwd."
|
|
125
|
+
},
|
|
126
|
+
max_results: {
|
|
127
|
+
type: "integer",
|
|
128
|
+
description: "Maximum file paths to return."
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
required: ["pattern"]
|
|
131
132
|
};
|
|
132
133
|
const LocalListDirectoryToolSchema = {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
},
|
|
139
|
-
},
|
|
134
|
+
type: "object",
|
|
135
|
+
properties: { path: {
|
|
136
|
+
type: "string",
|
|
137
|
+
description: "Directory to list. Defaults to cwd."
|
|
138
|
+
} }
|
|
140
139
|
};
|
|
141
140
|
function lineWindow(content, offset, limit) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
out.push(content.slice(pos));
|
|
178
|
-
break;
|
|
179
|
-
}
|
|
180
|
-
out.push(content.slice(pos, next));
|
|
181
|
-
pos = next + 1;
|
|
182
|
-
if (k === limit - 1 && pos < content.length) {
|
|
183
|
-
exhausted = false;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
const numbered = out
|
|
187
|
-
.map((text, index) => `${String(start + index + 1).padStart(6, ' ')}\t${text}`)
|
|
188
|
-
.join('\n');
|
|
189
|
-
return {
|
|
190
|
-
text: truncateLocalOutput(numbered, MAX_READ_CHARS),
|
|
191
|
-
truncated: !exhausted || numbered.length > MAX_READ_CHARS,
|
|
192
|
-
};
|
|
141
|
+
const start = Math.max((offset ?? 1) - 1, 0);
|
|
142
|
+
if (limit == null || limit <= 0) {
|
|
143
|
+
const numbered = content.split("\n").slice(start).map((line, index) => `${String(start + index + 1).padStart(6, " ")}\t${line}`).join("\n");
|
|
144
|
+
return {
|
|
145
|
+
text: truncateLocalOutput(numbered, MAX_READ_CHARS),
|
|
146
|
+
truncated: numbered.length > MAX_READ_CHARS
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
let cursor = 0;
|
|
150
|
+
for (let i = 0; i < start; i++) {
|
|
151
|
+
const next = content.indexOf("\n", cursor);
|
|
152
|
+
if (next === -1) return {
|
|
153
|
+
text: "",
|
|
154
|
+
truncated: false
|
|
155
|
+
};
|
|
156
|
+
cursor = next + 1;
|
|
157
|
+
}
|
|
158
|
+
const out = [];
|
|
159
|
+
let pos = cursor;
|
|
160
|
+
let exhausted = true;
|
|
161
|
+
for (let k = 0; k < limit; k++) {
|
|
162
|
+
const next = content.indexOf("\n", pos);
|
|
163
|
+
if (next === -1) {
|
|
164
|
+
out.push(content.slice(pos));
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
out.push(content.slice(pos, next));
|
|
168
|
+
pos = next + 1;
|
|
169
|
+
if (k === limit - 1 && pos < content.length) exhausted = false;
|
|
170
|
+
}
|
|
171
|
+
const numbered = out.map((text, index) => `${String(start + index + 1).padStart(6, " ")}\t${text}`).join("\n");
|
|
172
|
+
return {
|
|
173
|
+
text: truncateLocalOutput(numbered, MAX_READ_CHARS),
|
|
174
|
+
truncated: !exhausted || numbered.length > MAX_READ_CHARS
|
|
175
|
+
};
|
|
193
176
|
}
|
|
194
|
-
const MAX_DIFF_CHARS =
|
|
177
|
+
const MAX_DIFF_CHARS = 4e3;
|
|
195
178
|
async function maybeRunSyntaxCheck(path, config) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
179
|
+
const mode = config.postEditSyntaxCheck ?? "off";
|
|
180
|
+
if (mode === "off") return void 0;
|
|
181
|
+
const outcome = await runPostEditSyntaxCheck(path, config);
|
|
182
|
+
if (outcome == null) return void 0;
|
|
183
|
+
return {
|
|
184
|
+
mode,
|
|
185
|
+
outcome
|
|
186
|
+
};
|
|
203
187
|
}
|
|
204
188
|
function appendSyntaxCheckSummary(base, run) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return base;
|
|
209
|
-
const banner = run.mode === 'strict'
|
|
210
|
-
? `\n\n[syntax-check FAILED via ${run.outcome.checker}]\n`
|
|
211
|
-
: `\n\n[syntax-check warning via ${run.outcome.checker}]\n`;
|
|
212
|
-
return `${base}${banner}${run.outcome.output}`;
|
|
189
|
+
if (run == null) return base;
|
|
190
|
+
if (run.outcome.ok) return base;
|
|
191
|
+
return `${base}${run.mode === "strict" ? `\n\n[syntax-check FAILED via ${run.outcome.checker}]\n` : `\n\n[syntax-check warning via ${run.outcome.checker}]\n`}${run.outcome.output}`;
|
|
213
192
|
}
|
|
214
193
|
/**
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
194
|
+
* Revert a write_file/edit_file mutation in `postEditSyntaxCheck:
|
|
195
|
+
* 'strict'` mode after the post-write syntax check failed. Strict
|
|
196
|
+
* mode advertises a safety gate, so leaving the corrupted file on
|
|
197
|
+
* disk + throwing is a half-broken contract — the model "reacts" to
|
|
198
|
+
* the error but the next call sees broken on-disk state. Codex P2
|
|
199
|
+
* [49]. Best-effort: a swallowed error here means the workspace is
|
|
200
|
+
* still in the bad post-write state, but we still throw the
|
|
201
|
+
* original syntax-check error so the caller knows.
|
|
202
|
+
*
|
|
203
|
+
* - If the file existed pre-write: restore the previous bytes with
|
|
204
|
+
* the original encoding.
|
|
205
|
+
* - If the file is brand-new: unlink it.
|
|
206
|
+
*/
|
|
228
207
|
async function revertStrictWrite(fs, path, existed, before, encoding) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
else {
|
|
237
|
-
await fs.unlink(path);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
catch {
|
|
241
|
-
/* best-effort: caller still sees the original syntax error */
|
|
242
|
-
}
|
|
208
|
+
try {
|
|
209
|
+
if (existed) await fs.writeFile(path, encodeFile(before, {
|
|
210
|
+
...encoding,
|
|
211
|
+
text: before
|
|
212
|
+
}), "utf8");
|
|
213
|
+
else await fs.unlink(path);
|
|
214
|
+
} catch {}
|
|
243
215
|
}
|
|
244
216
|
function summariseDiff(filePath, before, after) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
context: 3,
|
|
251
|
-
});
|
|
252
|
-
if (patch.length <= MAX_DIFF_CHARS) {
|
|
253
|
-
return patch;
|
|
254
|
-
}
|
|
255
|
-
return (patch.slice(0, MAX_DIFF_CHARS) +
|
|
256
|
-
`\n[... diff truncated, ${patch.length - MAX_DIFF_CHARS} more chars ...]`);
|
|
217
|
+
if (before === after) return "(no textual changes)";
|
|
218
|
+
const name = basename(filePath);
|
|
219
|
+
const patch = createTwoFilesPatch(name, name, before, after, "", "", { context: 3 });
|
|
220
|
+
if (patch.length <= MAX_DIFF_CHARS) return patch;
|
|
221
|
+
return patch.slice(0, MAX_DIFF_CHARS) + `\n[... diff truncated, ${patch.length - MAX_DIFF_CHARS} more chars ...]`;
|
|
257
222
|
}
|
|
258
223
|
function normalizeEdits(input) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
newText: input.new_text ?? '',
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
return edits;
|
|
224
|
+
const edits = Array.isArray(input.edits) ? input.edits.map((edit) => ({
|
|
225
|
+
oldText: edit.old_text ?? "",
|
|
226
|
+
newText: edit.new_text ?? ""
|
|
227
|
+
})) : [];
|
|
228
|
+
if (input.old_text != null || input.new_text != null) edits.push({
|
|
229
|
+
oldText: input.old_text ?? "",
|
|
230
|
+
newText: input.new_text ?? ""
|
|
231
|
+
});
|
|
232
|
+
return edits;
|
|
272
233
|
}
|
|
273
234
|
function toolDefinition(name, description, parameters) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
235
|
+
return {
|
|
236
|
+
name,
|
|
237
|
+
description,
|
|
238
|
+
parameters,
|
|
239
|
+
allowed_callers: ["direct", "code_execution"],
|
|
240
|
+
responseFormat: "content_and_artifact",
|
|
241
|
+
toolType: "builtin"
|
|
242
|
+
};
|
|
282
243
|
}
|
|
283
244
|
async function looksBinary(path, fs) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
return false;
|
|
295
|
-
}
|
|
296
|
-
finally {
|
|
297
|
-
await handle?.close();
|
|
298
|
-
}
|
|
245
|
+
let handle;
|
|
246
|
+
try {
|
|
247
|
+
handle = await fs.open(path, "r");
|
|
248
|
+
const sample = Buffer.alloc(BINARY_DETECTION_BYTES);
|
|
249
|
+
const { bytesRead } = await handle.read(sample, 0, BINARY_DETECTION_BYTES, 0);
|
|
250
|
+
for (let i = 0; i < bytesRead; i++) if (sample[i] === 0) return true;
|
|
251
|
+
return false;
|
|
252
|
+
} finally {
|
|
253
|
+
await handle?.close();
|
|
254
|
+
}
|
|
299
255
|
}
|
|
300
256
|
const DEFAULT_MAX_ATTACHMENT_BYTES = 5 * 1024 * 1024;
|
|
301
257
|
function createLocalReadFileTool(config = {}) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
return [
|
|
372
|
-
`Refusing to read binary file (${fileStat.size} bytes, ${attachment.mime}): ${path}`,
|
|
373
|
-
{
|
|
374
|
-
path,
|
|
375
|
-
bytes: fileStat.size,
|
|
376
|
-
mime: attachment.mime,
|
|
377
|
-
binary: true,
|
|
378
|
-
},
|
|
379
|
-
];
|
|
380
|
-
}
|
|
381
|
-
// text-or-unknown falls through to the text-read path below.
|
|
382
|
-
}
|
|
383
|
-
else {
|
|
384
|
-
return [
|
|
385
|
-
`Refusing to read binary file (${fileStat.size} bytes): ${path}`,
|
|
386
|
-
{ path, bytes: fileStat.size, binary: true },
|
|
387
|
-
];
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
const content = await fs.readFile(path, 'utf8');
|
|
391
|
-
const result = lineWindow(content, input.offset, input.limit);
|
|
392
|
-
return [
|
|
393
|
-
result.truncated ? `${result.text}\n[truncated]` : result.text,
|
|
394
|
-
{ path, bytes: fileStat.size },
|
|
395
|
-
];
|
|
396
|
-
}, {
|
|
397
|
-
name: Constants.READ_FILE,
|
|
398
|
-
description: 'Read a local text file from the configured working directory with line numbers. ' +
|
|
399
|
-
'When `attachReadAttachments` is enabled (e.g. images-only), reading an image returns an ' +
|
|
400
|
-
'`image_url` content block so vision-capable models can see the file directly.',
|
|
401
|
-
schema: LocalReadFileToolSchema,
|
|
402
|
-
responseFormat: Constants.CONTENT_AND_ARTIFACT,
|
|
403
|
-
});
|
|
258
|
+
const fs = getWorkspaceFS(config);
|
|
259
|
+
return tool(async (rawInput) => {
|
|
260
|
+
const input = rawInput;
|
|
261
|
+
const path = await resolveWorkspacePathSafe(input.file_path, config, "read");
|
|
262
|
+
const fileStat = await fs.stat(path);
|
|
263
|
+
if (!fileStat.isFile()) throw new Error(`Path is not a file: ${input.file_path}`);
|
|
264
|
+
const maxBytes = Math.max(config.maxReadBytes ?? DEFAULT_MAX_READ_BYTES, 1);
|
|
265
|
+
if (fileStat.size > maxBytes) return [`File is ${fileStat.size} bytes, exceeds the ${maxBytes}-byte read cap. Read a slice via bash (e.g. head/sed) or raise local.maxReadBytes.`, {
|
|
266
|
+
path,
|
|
267
|
+
bytes: fileStat.size,
|
|
268
|
+
truncated: true
|
|
269
|
+
}];
|
|
270
|
+
if (await looksBinary(path, fs)) {
|
|
271
|
+
const attachmentMode = config.attachReadAttachments ?? "off";
|
|
272
|
+
if (attachmentMode !== "off") {
|
|
273
|
+
const attachment = await classifyAttachment({
|
|
274
|
+
path,
|
|
275
|
+
bytes: fileStat.size,
|
|
276
|
+
mode: attachmentMode,
|
|
277
|
+
maxBytes: config.maxAttachmentBytes ?? DEFAULT_MAX_ATTACHMENT_BYTES,
|
|
278
|
+
fs
|
|
279
|
+
});
|
|
280
|
+
if (attachment.kind === "image") return [imageAttachmentContent(path, attachment), {
|
|
281
|
+
path,
|
|
282
|
+
bytes: fileStat.size,
|
|
283
|
+
mime: attachment.mime,
|
|
284
|
+
attachment: "image"
|
|
285
|
+
}];
|
|
286
|
+
if (attachment.kind === "pdf") return [[{
|
|
287
|
+
type: "text",
|
|
288
|
+
text: `Read ${path} (application/pdf, ${fileStat.size} bytes). PDF attached as base64 data URL; vision-capable models that accept PDF will render it.`
|
|
289
|
+
}, {
|
|
290
|
+
type: "image_url",
|
|
291
|
+
image_url: { url: attachment.dataUrl }
|
|
292
|
+
}], {
|
|
293
|
+
path,
|
|
294
|
+
bytes: fileStat.size,
|
|
295
|
+
mime: attachment.mime,
|
|
296
|
+
attachment: "pdf"
|
|
297
|
+
}];
|
|
298
|
+
if (attachment.kind === "oversize") return [`Refusing to embed ${attachment.mime} attachment (${attachment.bytes} bytes exceeds ${attachment.maxBytes}-byte cap).`, {
|
|
299
|
+
path,
|
|
300
|
+
bytes: fileStat.size,
|
|
301
|
+
mime: attachment.mime,
|
|
302
|
+
attachment: "oversize"
|
|
303
|
+
}];
|
|
304
|
+
if (attachment.kind === "binary") return [`Refusing to read binary file (${fileStat.size} bytes, ${attachment.mime}): ${path}`, {
|
|
305
|
+
path,
|
|
306
|
+
bytes: fileStat.size,
|
|
307
|
+
mime: attachment.mime,
|
|
308
|
+
binary: true
|
|
309
|
+
}];
|
|
310
|
+
} else return [`Refusing to read binary file (${fileStat.size} bytes): ${path}`, {
|
|
311
|
+
path,
|
|
312
|
+
bytes: fileStat.size,
|
|
313
|
+
binary: true
|
|
314
|
+
}];
|
|
315
|
+
}
|
|
316
|
+
const result = lineWindow(await fs.readFile(path, "utf8"), input.offset, input.limit);
|
|
317
|
+
return [result.truncated ? `${result.text}\n[truncated]` : result.text, {
|
|
318
|
+
path,
|
|
319
|
+
bytes: fileStat.size
|
|
320
|
+
}];
|
|
321
|
+
}, {
|
|
322
|
+
name: "read_file",
|
|
323
|
+
description: "Read a local text file from the configured working directory with line numbers. When `attachReadAttachments` is enabled (e.g. images-only), reading an image returns an `image_url` content block so vision-capable models can see the file directly.",
|
|
324
|
+
schema: LocalReadFileToolSchema,
|
|
325
|
+
responseFormat: "content_and_artifact"
|
|
326
|
+
});
|
|
404
327
|
}
|
|
405
328
|
function createLocalWriteFileTool(config = {}, checkpointer) {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
bytes: finalText.length,
|
|
452
|
-
new_file: !existed,
|
|
453
|
-
newline: encoding.newline === '\r\n' ? 'CRLF' : 'LF',
|
|
454
|
-
had_bom: encoding.hasBom,
|
|
455
|
-
...(syntax != null && syntax.outcome.ok === false
|
|
456
|
-
? { syntax_error: syntax.outcome.checker }
|
|
457
|
-
: {}),
|
|
458
|
-
},
|
|
459
|
-
];
|
|
460
|
-
}, {
|
|
461
|
-
name: LocalWriteFileToolName,
|
|
462
|
-
description: 'Create or overwrite a local text file in the configured working directory. ' +
|
|
463
|
-
'Preserves the existing BOM and line endings when overwriting; defaults to LF without BOM for new files. ' +
|
|
464
|
-
'Returns a unified diff of the changes when overwriting.',
|
|
465
|
-
schema: LocalWriteFileToolSchema,
|
|
466
|
-
responseFormat: Constants.CONTENT_AND_ARTIFACT,
|
|
467
|
-
});
|
|
329
|
+
const fs = getWorkspaceFS(config);
|
|
330
|
+
return tool(async (rawInput) => {
|
|
331
|
+
const input = rawInput;
|
|
332
|
+
if (config.readOnly === true) throw new Error("write_file is blocked in read-only local mode.");
|
|
333
|
+
const path = await resolveWorkspacePathSafe(input.file_path, config, "write");
|
|
334
|
+
if (checkpointer != null) await checkpointer.captureBeforeWrite(path);
|
|
335
|
+
let before = "";
|
|
336
|
+
let encoding = {
|
|
337
|
+
text: "",
|
|
338
|
+
hasBom: false,
|
|
339
|
+
newline: "\n"
|
|
340
|
+
};
|
|
341
|
+
let existed = false;
|
|
342
|
+
try {
|
|
343
|
+
const decoded = decodeFile(await fs.readFile(path, "utf8"));
|
|
344
|
+
before = decoded.text;
|
|
345
|
+
encoding = decoded;
|
|
346
|
+
existed = true;
|
|
347
|
+
} catch {
|
|
348
|
+
existed = false;
|
|
349
|
+
}
|
|
350
|
+
await fs.mkdir(dirname(path), { recursive: true });
|
|
351
|
+
const finalText = encodeFile(input.content, encoding);
|
|
352
|
+
await fs.writeFile(path, finalText, "utf8");
|
|
353
|
+
const syntax = await maybeRunSyntaxCheck(path, config);
|
|
354
|
+
const diff = existed ? summariseDiff(path, before, input.content) : `(new file, ${input.content.length} chars)`;
|
|
355
|
+
const summary = appendSyntaxCheckSummary(existed ? `Overwrote ${path} (${input.content.length} chars). Diff:\n${diff}` : `Created ${path} (${input.content.length} chars).`, syntax);
|
|
356
|
+
if (syntax?.outcome.ok === false && syntax.mode === "strict") {
|
|
357
|
+
await revertStrictWrite(fs, path, existed, before, encoding);
|
|
358
|
+
throw new Error(`write_file syntax check failed (${syntax.outcome.checker}); reverted to pre-write state.\n${syntax.outcome.output}`);
|
|
359
|
+
}
|
|
360
|
+
return [summary, {
|
|
361
|
+
path,
|
|
362
|
+
bytes: finalText.length,
|
|
363
|
+
new_file: !existed,
|
|
364
|
+
newline: encoding.newline === "\r\n" ? "CRLF" : "LF",
|
|
365
|
+
had_bom: encoding.hasBom,
|
|
366
|
+
...syntax != null && syntax.outcome.ok === false ? { syntax_error: syntax.outcome.checker } : {}
|
|
367
|
+
}];
|
|
368
|
+
}, {
|
|
369
|
+
name: LocalWriteFileToolName,
|
|
370
|
+
description: "Create or overwrite a local text file in the configured working directory. Preserves the existing BOM and line endings when overwriting; defaults to LF without BOM for new files. Returns a unified diff of the changes when overwriting.",
|
|
371
|
+
schema: LocalWriteFileToolSchema,
|
|
372
|
+
responseFormat: "content_and_artifact"
|
|
373
|
+
});
|
|
468
374
|
}
|
|
469
375
|
function createLocalEditFileTool(config = {}, checkpointer) {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
await revertStrictWrite(fs, path, true, original, encoding);
|
|
514
|
-
throw new Error(`edit_file syntax check failed (${syntax.outcome.checker}); reverted to pre-edit state.\n${syntax.outcome.output}`);
|
|
515
|
-
}
|
|
516
|
-
return [
|
|
517
|
-
summary,
|
|
518
|
-
{
|
|
519
|
-
path,
|
|
520
|
-
edits: edits.length,
|
|
521
|
-
strategies: strategiesUsed,
|
|
522
|
-
newline: encoding.newline === '\r\n' ? 'CRLF' : 'LF',
|
|
523
|
-
had_bom: encoding.hasBom,
|
|
524
|
-
...(syntax != null && syntax.outcome.ok === false
|
|
525
|
-
? { syntax_error: syntax.outcome.checker }
|
|
526
|
-
: {}),
|
|
527
|
-
},
|
|
528
|
-
];
|
|
529
|
-
}, {
|
|
530
|
-
name: LocalEditFileToolName,
|
|
531
|
-
description: 'Apply exact text replacements to a local file. The matcher tries exact, line-trimmed, whitespace-normalized, and indentation-flexible strategies in order so common LLM whitespace mistakes are recoverable. Each old_text must still match exactly one location. Returns a unified diff of the changes.',
|
|
532
|
-
schema: LocalEditFileToolSchema,
|
|
533
|
-
responseFormat: Constants.CONTENT_AND_ARTIFACT,
|
|
534
|
-
});
|
|
376
|
+
const fs = getWorkspaceFS(config);
|
|
377
|
+
return tool(async (rawInput) => {
|
|
378
|
+
const input = rawInput;
|
|
379
|
+
if (config.readOnly === true) throw new Error("edit_file is blocked in read-only local mode.");
|
|
380
|
+
const edits = normalizeEdits(input);
|
|
381
|
+
if (edits.length === 0) throw new Error("edit_file requires old_text/new_text or edits[].");
|
|
382
|
+
const path = await resolveWorkspacePathSafe(input.file_path, config, "write");
|
|
383
|
+
const encoding = decodeFile(await fs.readFile(path, "utf8"));
|
|
384
|
+
const original = encoding.text;
|
|
385
|
+
let next = original;
|
|
386
|
+
const strategiesUsed = [];
|
|
387
|
+
for (let i = 0; i < edits.length; i++) {
|
|
388
|
+
const edit = edits[i];
|
|
389
|
+
const match = locateEdit(next, edit.oldText);
|
|
390
|
+
if (match == null) throw new Error(`Edit ${i + 1}/${edits.length}: could not locate old_text in ${input.file_path}. Tried exact, line-trimmed, whitespace-normalized, and indentation-flexible matching. Re-read the file and copy the literal lines.`);
|
|
391
|
+
strategiesUsed.push(match.strategy);
|
|
392
|
+
next = applyEdit(next, match, edit.newText);
|
|
393
|
+
}
|
|
394
|
+
if (checkpointer != null) await checkpointer.captureBeforeWrite(path);
|
|
395
|
+
const finalText = encodeFile(next, encoding);
|
|
396
|
+
await fs.writeFile(path, finalText, "utf8");
|
|
397
|
+
const syntax = await maybeRunSyntaxCheck(path, config);
|
|
398
|
+
const diff = summariseDiff(path, original, next);
|
|
399
|
+
const fuzzy = strategiesUsed.some((s) => s !== "exact");
|
|
400
|
+
const summary = appendSyntaxCheckSummary(`Applied ${edits.length} edit(s) to ${path}` + (fuzzy ? ` (strategies: ${strategiesUsed.join(", ")})` : "") + `. Diff:\n${diff}`, syntax);
|
|
401
|
+
if (syntax?.outcome.ok === false && syntax.mode === "strict") {
|
|
402
|
+
await revertStrictWrite(fs, path, true, original, encoding);
|
|
403
|
+
throw new Error(`edit_file syntax check failed (${syntax.outcome.checker}); reverted to pre-edit state.\n${syntax.outcome.output}`);
|
|
404
|
+
}
|
|
405
|
+
return [summary, {
|
|
406
|
+
path,
|
|
407
|
+
edits: edits.length,
|
|
408
|
+
strategies: strategiesUsed,
|
|
409
|
+
newline: encoding.newline === "\r\n" ? "CRLF" : "LF",
|
|
410
|
+
had_bom: encoding.hasBom,
|
|
411
|
+
...syntax != null && syntax.outcome.ok === false ? { syntax_error: syntax.outcome.checker } : {}
|
|
412
|
+
}];
|
|
413
|
+
}, {
|
|
414
|
+
name: LocalEditFileToolName,
|
|
415
|
+
description: "Apply exact text replacements to a local file. The matcher tries exact, line-trimmed, whitespace-normalized, and indentation-flexible strategies in order so common LLM whitespace mistakes are recoverable. Each old_text must still match exactly one location. Returns a unified diff of the changes.",
|
|
416
|
+
schema: LocalEditFileToolSchema,
|
|
417
|
+
responseFormat: "content_and_artifact"
|
|
418
|
+
});
|
|
535
419
|
}
|
|
536
420
|
/**
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
// backend alone misses the case where two Runs share a backend but
|
|
549
|
-
// vary `local.env` (especially PATH). Stale cache then claims `rg`
|
|
550
|
-
// is available, the rg path runs, and the spawn fails with ENOENT
|
|
551
|
-
// instead of falling back to the Node walker. The inner Map is
|
|
552
|
-
// keyed by a stable JSON hash of the effective env so each unique
|
|
553
|
-
// env gets its own probe.
|
|
554
|
-
let ripgrepAvailabilityByBackend = new WeakMap();
|
|
421
|
+
* Ripgrep availability cache, keyed on the *effective execution
|
|
422
|
+
* backend* — whatever function `getSpawn(config)` returns. Without
|
|
423
|
+
* the backend key, a Run that probes `rg` over Node's
|
|
424
|
+
* `child_process.spawn` would poison subsequent Runs whose
|
|
425
|
+
* `local.exec.spawn` routes to a remote sandbox or container that
|
|
426
|
+
* doesn't have rg installed: the cached `true` would skip the probe,
|
|
427
|
+
* the rg invocation would throw, and the Node fallback wouldn't be
|
|
428
|
+
* reached. Per-backend caching avoids that without paying for a
|
|
429
|
+
* spawn-per-search.
|
|
430
|
+
*/
|
|
431
|
+
let ripgrepAvailabilityByBackend = /* @__PURE__ */ new WeakMap();
|
|
555
432
|
function envCacheKey(env) {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
if (env == null)
|
|
561
|
-
return '';
|
|
562
|
-
const sorted = {};
|
|
563
|
-
for (const k of Object.keys(env).sort()) {
|
|
564
|
-
sorted[k] = env[k];
|
|
565
|
-
}
|
|
566
|
-
return JSON.stringify(sorted);
|
|
433
|
+
if (env == null) return "";
|
|
434
|
+
const sorted = {};
|
|
435
|
+
for (const k of Object.keys(env).sort()) sorted[k] = env[k];
|
|
436
|
+
return JSON.stringify(sorted);
|
|
567
437
|
}
|
|
568
438
|
async function isRipgrepAvailable(config) {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
439
|
+
const backend = getSpawn(config);
|
|
440
|
+
let envMap = ripgrepAvailabilityByBackend.get(backend);
|
|
441
|
+
if (envMap == null) {
|
|
442
|
+
envMap = /* @__PURE__ */ new Map();
|
|
443
|
+
ripgrepAvailabilityByBackend.set(backend, envMap);
|
|
444
|
+
}
|
|
445
|
+
const envKey = envCacheKey(config.env);
|
|
446
|
+
let probePromise = envMap.get(envKey);
|
|
447
|
+
if (probePromise == null) {
|
|
448
|
+
probePromise = spawnLocalProcess("rg", ["--version"], {
|
|
449
|
+
...config,
|
|
450
|
+
timeoutMs: 5e3,
|
|
451
|
+
sandbox: { enabled: false }
|
|
452
|
+
}, { internal: true }).then((probe) => probe.exitCode === 0).catch(() => false);
|
|
453
|
+
envMap.set(envKey, probePromise);
|
|
454
|
+
}
|
|
455
|
+
return probePromise;
|
|
584
456
|
}
|
|
585
457
|
/**
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
458
|
+
* Test-only reset hook. Clears the ripgrep-availability cache so
|
|
459
|
+
* tests can swap in mocked spawn backends and reprobe deterministically.
|
|
460
|
+
*
|
|
461
|
+
* @internal Not part of the public SDK surface; the leading underscore
|
|
462
|
+
* and `@internal` tag together signal that consumers should not call
|
|
463
|
+
* this. Tests import it via the module path directly.
|
|
464
|
+
*/
|
|
593
465
|
function _resetRipgrepCacheForTests() {
|
|
594
|
-
|
|
466
|
+
ripgrepAvailabilityByBackend = /* @__PURE__ */ new WeakMap();
|
|
595
467
|
}
|
|
596
|
-
// Skipped by the Node-fallback walker (used when ripgrep is
|
|
597
|
-
// unavailable). Covers common build outputs, virtualenvs, and
|
|
598
|
-
// caches so a `grep_search`/`glob_search` on a large monorepo or a
|
|
599
|
-
// Python project with `.venv/` doesn't read every file under those
|
|
600
|
-
// trees. ripgrep itself respects .gitignore so it doesn't need this
|
|
601
|
-
// list. Audit follow-up from the comprehensive review (finding #3).
|
|
602
468
|
const SKIP_DIRS = new Set([
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
469
|
+
".git",
|
|
470
|
+
".svn",
|
|
471
|
+
".hg",
|
|
472
|
+
"node_modules",
|
|
473
|
+
".next",
|
|
474
|
+
".nuxt",
|
|
475
|
+
".cache",
|
|
476
|
+
".parcel-cache",
|
|
477
|
+
".turbo",
|
|
478
|
+
"dist",
|
|
479
|
+
"build",
|
|
480
|
+
"out",
|
|
481
|
+
"target",
|
|
482
|
+
"vendor",
|
|
483
|
+
"coverage",
|
|
484
|
+
".nyc_output",
|
|
485
|
+
"__pycache__",
|
|
486
|
+
".venv",
|
|
487
|
+
"venv",
|
|
488
|
+
"env",
|
|
489
|
+
".tox",
|
|
490
|
+
".mypy_cache",
|
|
491
|
+
".pytest_cache",
|
|
492
|
+
".ruff_cache"
|
|
627
493
|
]);
|
|
628
494
|
function globToRegExp(pattern) {
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
}
|
|
644
|
-
else if (c === '?') {
|
|
645
|
-
result += '[^/]';
|
|
646
|
-
}
|
|
647
|
-
else if ('.+^$|(){}[]\\'.includes(c)) {
|
|
648
|
-
result += '\\' + c;
|
|
649
|
-
}
|
|
650
|
-
else {
|
|
651
|
-
result += c;
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
result += '$';
|
|
655
|
-
return new RegExp(result);
|
|
495
|
+
let result = "^";
|
|
496
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
497
|
+
const c = pattern[i];
|
|
498
|
+
if (c === "*") if (pattern[i + 1] === "*") {
|
|
499
|
+
result += ".*";
|
|
500
|
+
i += 1;
|
|
501
|
+
if (pattern[i + 1] === "/") i += 1;
|
|
502
|
+
} else result += "[^/]*";
|
|
503
|
+
else if (c === "?") result += "[^/]";
|
|
504
|
+
else if (".+^$|(){}[]\\".includes(c)) result += "\\" + c;
|
|
505
|
+
else result += c;
|
|
506
|
+
}
|
|
507
|
+
result += "$";
|
|
508
|
+
return new RegExp(result);
|
|
656
509
|
}
|
|
657
510
|
async function* walkFiles(root, fs) {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
stack.push(full);
|
|
675
|
-
}
|
|
676
|
-
else if (entry.isFile()) {
|
|
677
|
-
yield full;
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
}
|
|
511
|
+
const stack = [root];
|
|
512
|
+
while (stack.length > 0) {
|
|
513
|
+
const dir = stack.pop();
|
|
514
|
+
let entries;
|
|
515
|
+
try {
|
|
516
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
517
|
+
} catch {
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
for (const entry of entries) {
|
|
521
|
+
if (entry.name.startsWith(".git") || SKIP_DIRS.has(entry.name)) continue;
|
|
522
|
+
const full = `${dir}/${entry.name}`;
|
|
523
|
+
if (entry.isDirectory()) stack.push(full);
|
|
524
|
+
else if (entry.isFile()) yield full;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
681
527
|
}
|
|
682
528
|
/**
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
529
|
+
* Catastrophic-backtracking guardrails for the fallback grep path.
|
|
530
|
+
*
|
|
531
|
+
* Without ripgrep we run the model-supplied pattern through Node's
|
|
532
|
+
* `RegExp` engine, which uses a backtracking implementation. Patterns
|
|
533
|
+
* with nested unbounded quantifiers (`(a+)+`, `(.*)*`, etc.) can
|
|
534
|
+
* monopolise the event loop for arbitrary wall-clock time on
|
|
535
|
+
* pathological input, and `setTimeout` cannot interrupt a synchronous
|
|
536
|
+
* `RegExp.exec`. Manual review (finding D) flagged this as a real DoS.
|
|
537
|
+
*
|
|
538
|
+
* Mitigations applied here, in order of severity:
|
|
539
|
+
* 1. Cap pattern length so an obviously oversize regex is rejected
|
|
540
|
+
* before compile.
|
|
541
|
+
* 2. Reject patterns that contain a nested unbounded quantifier of
|
|
542
|
+
* the form `(...+|*)([+*]|{n,})` — the standard pathological
|
|
543
|
+
* shape. Still a heuristic (not a full safety proof), but blocks
|
|
544
|
+
* every common DoS construction we've seen in coding-agent logs.
|
|
545
|
+
* 3. Wall-clock budget for the overall search: each file's regex
|
|
546
|
+
* pass is checked against a deadline; once exceeded the search
|
|
547
|
+
* bails with a partial result. Doesn't interrupt a stuck
|
|
548
|
+
* `exec()` call, but stops a slow pattern from making the whole
|
|
549
|
+
* Run hang once the first hung file finishes.
|
|
550
|
+
*
|
|
551
|
+
* Hosts that need bulletproof regex safety should install `rg` —
|
|
552
|
+
* ripgrep uses RE2 internally and has no backtracking.
|
|
553
|
+
*/
|
|
708
554
|
const MAX_FALLBACK_PATTERN_LENGTH = 1024;
|
|
709
|
-
const FALLBACK_GREP_BUDGET_MS =
|
|
710
|
-
// Per-file byte cap. Codex P2 #41 — without it, the whole-file
|
|
711
|
-
// `readFile` + `split('\n')` for a multi-GB log is an unbounded
|
|
712
|
-
// allocation that the wall-clock budget (checked between files)
|
|
713
|
-
// can't interrupt. Hosts that need to grep large files should
|
|
714
|
-
// install ripgrep.
|
|
555
|
+
const FALLBACK_GREP_BUDGET_MS = 5e3;
|
|
715
556
|
const FALLBACK_GREP_MAX_FILE_BYTES = 5 * 1024 * 1024;
|
|
716
557
|
/**
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
558
|
+
* Heuristic: walks `pattern` to find any `(<contents>)<quant>` where
|
|
559
|
+
* `<contents>` itself has an unbounded quantifier. Catches the
|
|
560
|
+
* classic `(a+)+` form AND the double-nested `((a+)+)` form (which a
|
|
561
|
+
* single-pass regex misses because `[^)]*` stops at the first inner
|
|
562
|
+
* close-paren). Misses sufficiently obfuscated cases — bulletproof
|
|
563
|
+
* ReDoS detection requires a real parser. The 5 s wall-clock budget
|
|
564
|
+
* is the hard backstop for anything this slip past.
|
|
565
|
+
*/
|
|
725
566
|
function hasNestedUnboundedQuantifier(pattern) {
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
}
|
|
750
|
-
j--;
|
|
751
|
-
}
|
|
752
|
-
if (j < 0)
|
|
753
|
-
continue;
|
|
754
|
-
const inner = pattern.slice(j + 1, i);
|
|
755
|
-
if (/(?<!\\)[+*]/.test(inner))
|
|
756
|
-
return true;
|
|
757
|
-
}
|
|
758
|
-
return false;
|
|
759
|
-
}
|
|
760
|
-
class FallbackGrepError extends Error {
|
|
761
|
-
kind;
|
|
762
|
-
constructor(kind, message) {
|
|
763
|
-
super(message);
|
|
764
|
-
this.kind = kind;
|
|
765
|
-
}
|
|
567
|
+
for (let i = 1; i < pattern.length - 1; i++) {
|
|
568
|
+
if (pattern[i] !== ")") continue;
|
|
569
|
+
if (pattern[i - 1] === "\\") continue;
|
|
570
|
+
const next = pattern[i + 1];
|
|
571
|
+
if (next !== "+" && next !== "*" && next !== "{") continue;
|
|
572
|
+
let depth = 1;
|
|
573
|
+
let j = i - 1;
|
|
574
|
+
while (j >= 0) {
|
|
575
|
+
const c = pattern[j];
|
|
576
|
+
if (!(j > 0 && pattern[j - 1] === "\\")) {
|
|
577
|
+
if (c === ")") depth++;
|
|
578
|
+
else if (c === "(") {
|
|
579
|
+
depth--;
|
|
580
|
+
if (depth === 0) break;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
j--;
|
|
584
|
+
}
|
|
585
|
+
if (j < 0) continue;
|
|
586
|
+
const inner = pattern.slice(j + 1, i);
|
|
587
|
+
if (/(?<!\\)[+*]/.test(inner)) return true;
|
|
588
|
+
}
|
|
589
|
+
return false;
|
|
766
590
|
}
|
|
591
|
+
var FallbackGrepError = class extends Error {
|
|
592
|
+
kind;
|
|
593
|
+
constructor(kind, message) {
|
|
594
|
+
super(message);
|
|
595
|
+
this.kind = kind;
|
|
596
|
+
}
|
|
597
|
+
};
|
|
767
598
|
function compileFallbackRegex(pattern) {
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
return new RegExp(pattern);
|
|
776
|
-
}
|
|
777
|
-
catch (e) {
|
|
778
|
-
throw new FallbackGrepError('invalid-pattern', `Invalid regex: ${e.message}`);
|
|
779
|
-
}
|
|
599
|
+
if (pattern.length > MAX_FALLBACK_PATTERN_LENGTH) throw new FallbackGrepError("pattern-too-long", `Pattern exceeds ${MAX_FALLBACK_PATTERN_LENGTH}-char fallback cap (install ripgrep for unbounded patterns).`);
|
|
600
|
+
if (hasNestedUnboundedQuantifier(pattern)) throw new FallbackGrepError("unsafe-pattern", "Pattern contains a nested unbounded quantifier (e.g. `(a+)+` or `((a+)+)`) which can cause catastrophic backtracking in the Node fallback. Install ripgrep for RE2-safe matching.");
|
|
601
|
+
try {
|
|
602
|
+
return new RegExp(pattern);
|
|
603
|
+
} catch (e) {
|
|
604
|
+
throw new FallbackGrepError("invalid-pattern", `Invalid regex: ${e.message}`);
|
|
605
|
+
}
|
|
780
606
|
}
|
|
781
607
|
/** Renders fallback-grep output: real matches first, skip diagnostics appended. */
|
|
782
608
|
function formatFallbackGrepDisplay(result) {
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
if (result.skipped.length > 0) {
|
|
787
|
-
return result.skipped.join('\n');
|
|
788
|
-
}
|
|
789
|
-
return 'No matches found.';
|
|
609
|
+
if (result.matches.length > 0) return [...result.matches, ...result.skipped].join("\n");
|
|
610
|
+
if (result.skipped.length > 0) return result.skipped.join("\n");
|
|
611
|
+
return "No matches found.";
|
|
790
612
|
}
|
|
791
613
|
async function fallbackGrep(root, pattern, globFilter, maxResults, fs) {
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
catch {
|
|
841
|
-
continue;
|
|
842
|
-
}
|
|
843
|
-
if (content.includes('\0')) {
|
|
844
|
-
continue;
|
|
845
|
-
}
|
|
846
|
-
// Re-check the deadline AFTER the read — a slow disk on one
|
|
847
|
-
// file can blow the budget without us noticing.
|
|
848
|
-
if (Date.now() > deadline) {
|
|
849
|
-
return { matches, skipped: skippedDiagnostics };
|
|
850
|
-
}
|
|
851
|
-
const lines = content.split('\n');
|
|
852
|
-
for (let i = 0; i < lines.length; i++) {
|
|
853
|
-
if (rx.test(lines[i])) {
|
|
854
|
-
matches.push(`${file}:${i + 1}:${lines[i]}`);
|
|
855
|
-
if (matches.length >= maxResults) {
|
|
856
|
-
return { matches, skipped: skippedDiagnostics };
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
return { matches, skipped: skippedDiagnostics };
|
|
614
|
+
const rx = compileFallbackRegex(pattern);
|
|
615
|
+
const deadline = Date.now() + FALLBACK_GREP_BUDGET_MS;
|
|
616
|
+
const globRx = globFilter != null && globFilter !== "" ? globToRegExp(globFilter) : void 0;
|
|
617
|
+
const matches = [];
|
|
618
|
+
const skippedDiagnostics = [];
|
|
619
|
+
for await (const file of walkFiles(root, fs)) {
|
|
620
|
+
if (Date.now() > deadline) return {
|
|
621
|
+
matches,
|
|
622
|
+
skipped: skippedDiagnostics
|
|
623
|
+
};
|
|
624
|
+
if (globRx != null) {
|
|
625
|
+
const rel = file.startsWith(root + "/") ? file.slice(root.length + 1) : file;
|
|
626
|
+
if (!globRx.test(rel)) continue;
|
|
627
|
+
}
|
|
628
|
+
let stat;
|
|
629
|
+
try {
|
|
630
|
+
stat = await fs.stat(file);
|
|
631
|
+
} catch {
|
|
632
|
+
continue;
|
|
633
|
+
}
|
|
634
|
+
if (stat.size > FALLBACK_GREP_MAX_FILE_BYTES) {
|
|
635
|
+
skippedDiagnostics.push(`${file}:0:[skipped: file > ${FALLBACK_GREP_MAX_FILE_BYTES} bytes; install ripgrep for unbounded grep]`);
|
|
636
|
+
continue;
|
|
637
|
+
}
|
|
638
|
+
let content;
|
|
639
|
+
try {
|
|
640
|
+
content = await fs.readFile(file, "utf8");
|
|
641
|
+
} catch {
|
|
642
|
+
continue;
|
|
643
|
+
}
|
|
644
|
+
if (content.includes("\0")) continue;
|
|
645
|
+
if (Date.now() > deadline) return {
|
|
646
|
+
matches,
|
|
647
|
+
skipped: skippedDiagnostics
|
|
648
|
+
};
|
|
649
|
+
const lines = content.split("\n");
|
|
650
|
+
for (let i = 0; i < lines.length; i++) if (rx.test(lines[i])) {
|
|
651
|
+
matches.push(`${file}:${i + 1}:${lines[i]}`);
|
|
652
|
+
if (matches.length >= maxResults) return {
|
|
653
|
+
matches,
|
|
654
|
+
skipped: skippedDiagnostics
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
return {
|
|
659
|
+
matches,
|
|
660
|
+
skipped: skippedDiagnostics
|
|
661
|
+
};
|
|
862
662
|
}
|
|
863
663
|
async function fallbackGlob(root, pattern, maxResults, fs) {
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
return out;
|
|
664
|
+
const rx = globToRegExp(pattern);
|
|
665
|
+
const out = [];
|
|
666
|
+
for await (const file of walkFiles(root, fs)) {
|
|
667
|
+
const rel = file.startsWith(root + "/") ? file.slice(root.length + 1) : file;
|
|
668
|
+
if (rx.test(rel)) {
|
|
669
|
+
out.push(file);
|
|
670
|
+
if (out.length >= maxResults) break;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
return out;
|
|
878
674
|
}
|
|
879
675
|
function createLocalGrepSearchTool(config = {}) {
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
const { matches, skipped } = await fallbackGrep(target, input.pattern, input.glob, maxResults, fs);
|
|
941
|
-
// Artifact count: ONLY real matches (Codex P2 [43] —
|
|
942
|
-
// skip sentinels used to inflate the count and the budget).
|
|
943
|
-
const display = formatFallbackGrepDisplay({ matches, skipped });
|
|
944
|
-
return [
|
|
945
|
-
display,
|
|
946
|
-
{
|
|
947
|
-
matches: matches.length,
|
|
948
|
-
skipped: skipped.length,
|
|
949
|
-
engine: 'node-fallback',
|
|
950
|
-
},
|
|
951
|
-
];
|
|
952
|
-
}
|
|
953
|
-
catch (e) {
|
|
954
|
-
if (e instanceof FallbackGrepError) {
|
|
955
|
-
return [
|
|
956
|
-
`grep_search refused the pattern: ${e.message}`,
|
|
957
|
-
{
|
|
958
|
-
matches: 0,
|
|
959
|
-
engine: 'node-fallback',
|
|
960
|
-
error: e.message,
|
|
961
|
-
kind: e.kind,
|
|
962
|
-
},
|
|
963
|
-
];
|
|
964
|
-
}
|
|
965
|
-
throw e;
|
|
966
|
-
}
|
|
967
|
-
}, {
|
|
968
|
-
name: LocalGrepSearchToolName,
|
|
969
|
-
description: 'Search local files for a regex pattern (ripgrep when available, Node fallback otherwise).',
|
|
970
|
-
schema: LocalGrepSearchToolSchema,
|
|
971
|
-
responseFormat: Constants.CONTENT_AND_ARTIFACT,
|
|
972
|
-
});
|
|
676
|
+
const fs = getWorkspaceFS(config);
|
|
677
|
+
return tool(async (rawInput) => {
|
|
678
|
+
const input = rawInput;
|
|
679
|
+
const target = await resolveWorkspacePathSafe(input.path ?? ".", config, "read");
|
|
680
|
+
const maxResults = Math.max(input.max_results ?? DEFAULT_MAX_RESULTS, 1);
|
|
681
|
+
if (await isRipgrepAvailable(config)) {
|
|
682
|
+
const result = await spawnLocalProcess("rg", [
|
|
683
|
+
"--line-number",
|
|
684
|
+
"--column",
|
|
685
|
+
"--hidden",
|
|
686
|
+
"--glob",
|
|
687
|
+
"!.git/**",
|
|
688
|
+
...input.glob != null && input.glob !== "" ? ["--glob", input.glob] : [],
|
|
689
|
+
"-e",
|
|
690
|
+
input.pattern,
|
|
691
|
+
target
|
|
692
|
+
], {
|
|
693
|
+
...config,
|
|
694
|
+
timeoutMs: config.timeoutMs ?? 3e4
|
|
695
|
+
});
|
|
696
|
+
if (result.timedOut || result.exitCode != null && result.exitCode > 1) {
|
|
697
|
+
const detail = result.stderr.trim() || `rg exited ${result.exitCode}`;
|
|
698
|
+
return [`grep_search failed: ${detail}`, {
|
|
699
|
+
matches: 0,
|
|
700
|
+
engine: "ripgrep",
|
|
701
|
+
error: detail,
|
|
702
|
+
exitCode: result.exitCode
|
|
703
|
+
}];
|
|
704
|
+
}
|
|
705
|
+
const lines = result.stdout.split("\n").filter(Boolean).slice(0, maxResults);
|
|
706
|
+
return [lines.length > 0 ? lines.join("\n") : result.stderr.trim() || "No matches found.", {
|
|
707
|
+
matches: lines.length,
|
|
708
|
+
engine: "ripgrep"
|
|
709
|
+
}];
|
|
710
|
+
}
|
|
711
|
+
try {
|
|
712
|
+
const { matches, skipped } = await fallbackGrep(target, input.pattern, input.glob, maxResults, fs);
|
|
713
|
+
return [formatFallbackGrepDisplay({
|
|
714
|
+
matches,
|
|
715
|
+
skipped
|
|
716
|
+
}), {
|
|
717
|
+
matches: matches.length,
|
|
718
|
+
skipped: skipped.length,
|
|
719
|
+
engine: "node-fallback"
|
|
720
|
+
}];
|
|
721
|
+
} catch (e) {
|
|
722
|
+
if (e instanceof FallbackGrepError) return [`grep_search refused the pattern: ${e.message}`, {
|
|
723
|
+
matches: 0,
|
|
724
|
+
engine: "node-fallback",
|
|
725
|
+
error: e.message,
|
|
726
|
+
kind: e.kind
|
|
727
|
+
}];
|
|
728
|
+
throw e;
|
|
729
|
+
}
|
|
730
|
+
}, {
|
|
731
|
+
name: LocalGrepSearchToolName,
|
|
732
|
+
description: "Search local files for a regex pattern (ripgrep when available, Node fallback otherwise).",
|
|
733
|
+
schema: LocalGrepSearchToolSchema,
|
|
734
|
+
responseFormat: "content_and_artifact"
|
|
735
|
+
});
|
|
973
736
|
}
|
|
974
737
|
function createLocalGlobSearchTool(config = {}) {
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
const files = await fallbackGlob(target, input.pattern, maxResults, fs);
|
|
1020
|
-
return [
|
|
1021
|
-
files.length > 0 ? files.join('\n') : 'No files found.',
|
|
1022
|
-
{ files, engine: 'node-fallback' },
|
|
1023
|
-
];
|
|
1024
|
-
}, {
|
|
1025
|
-
name: LocalGlobSearchToolName,
|
|
1026
|
-
description: 'Find local files matching a glob pattern (ripgrep when available, Node fallback otherwise).',
|
|
1027
|
-
schema: LocalGlobSearchToolSchema,
|
|
1028
|
-
responseFormat: Constants.CONTENT_AND_ARTIFACT,
|
|
1029
|
-
});
|
|
738
|
+
const fs = getWorkspaceFS(config);
|
|
739
|
+
return tool(async (rawInput) => {
|
|
740
|
+
const input = rawInput;
|
|
741
|
+
const target = await resolveWorkspacePathSafe(input.path ?? ".", config, "read");
|
|
742
|
+
const maxResults = Math.max(input.max_results ?? DEFAULT_MAX_RESULTS, 1);
|
|
743
|
+
if (await isRipgrepAvailable(config)) {
|
|
744
|
+
const result = await spawnLocalProcess("rg", [
|
|
745
|
+
"--files",
|
|
746
|
+
"--hidden",
|
|
747
|
+
"--glob",
|
|
748
|
+
"!.git/**",
|
|
749
|
+
"--glob",
|
|
750
|
+
input.pattern,
|
|
751
|
+
target
|
|
752
|
+
], {
|
|
753
|
+
...config,
|
|
754
|
+
timeoutMs: config.timeoutMs ?? 3e4
|
|
755
|
+
});
|
|
756
|
+
if (result.timedOut || result.exitCode != null && result.exitCode > 1) {
|
|
757
|
+
const detail = result.stderr.trim() || `rg exited ${result.exitCode}`;
|
|
758
|
+
return [`glob_search failed: ${detail}`, {
|
|
759
|
+
files: [],
|
|
760
|
+
engine: "ripgrep",
|
|
761
|
+
error: detail,
|
|
762
|
+
exitCode: result.exitCode
|
|
763
|
+
}];
|
|
764
|
+
}
|
|
765
|
+
const lines = result.stdout.split("\n").filter(Boolean).slice(0, maxResults);
|
|
766
|
+
return [lines.length > 0 ? lines.join("\n") : "No files found.", {
|
|
767
|
+
files: lines,
|
|
768
|
+
engine: "ripgrep"
|
|
769
|
+
}];
|
|
770
|
+
}
|
|
771
|
+
const files = await fallbackGlob(target, input.pattern, maxResults, fs);
|
|
772
|
+
return [files.length > 0 ? files.join("\n") : "No files found.", {
|
|
773
|
+
files,
|
|
774
|
+
engine: "node-fallback"
|
|
775
|
+
}];
|
|
776
|
+
}, {
|
|
777
|
+
name: LocalGlobSearchToolName,
|
|
778
|
+
description: "Find local files matching a glob pattern (ripgrep when available, Node fallback otherwise).",
|
|
779
|
+
schema: LocalGlobSearchToolSchema,
|
|
780
|
+
responseFormat: "content_and_artifact"
|
|
781
|
+
});
|
|
1030
782
|
}
|
|
1031
783
|
function createLocalListDirectoryTool(config = {}) {
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
});
|
|
784
|
+
const fs = getWorkspaceFS(config);
|
|
785
|
+
return tool(async (rawInput) => {
|
|
786
|
+
const path = await resolveWorkspacePathSafe(rawInput.path ?? ".", config, "read");
|
|
787
|
+
const entries = await fs.readdir(path, { withFileTypes: true });
|
|
788
|
+
return [entries.map((entry) => `${entry.isDirectory() ? "dir " : "file"}\t${entry.name}`).join("\n") || "Directory is empty.", {
|
|
789
|
+
path,
|
|
790
|
+
count: entries.length
|
|
791
|
+
}];
|
|
792
|
+
}, {
|
|
793
|
+
name: LocalListDirectoryToolName,
|
|
794
|
+
description: "List files and directories in a local directory.",
|
|
795
|
+
schema: LocalListDirectoryToolSchema,
|
|
796
|
+
responseFormat: "content_and_artifact"
|
|
797
|
+
});
|
|
1047
798
|
}
|
|
1048
799
|
function createLocalCodingTools(config = {}, options = {}) {
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
createLocalProgrammaticToolCallingTool(config),
|
|
1064
|
-
createLocalBashProgrammaticToolCallingTool(config),
|
|
1065
|
-
];
|
|
800
|
+
const checkpointer = options.checkpointer ?? (config.fileCheckpointing === true ? createLocalFileCheckpointer({ fs: config.exec?.fs }) : void 0);
|
|
801
|
+
return [
|
|
802
|
+
createLocalReadFileTool(config),
|
|
803
|
+
createLocalWriteFileTool(config, checkpointer),
|
|
804
|
+
createLocalEditFileTool(config, checkpointer),
|
|
805
|
+
createLocalGrepSearchTool(config),
|
|
806
|
+
createLocalGlobSearchTool(config),
|
|
807
|
+
createLocalListDirectoryTool(config),
|
|
808
|
+
createCompileCheckTool(config),
|
|
809
|
+
createLocalBashExecutionTool({ config }),
|
|
810
|
+
createLocalCodeExecutionTool(config),
|
|
811
|
+
createLocalProgrammaticToolCallingTool(config),
|
|
812
|
+
createLocalBashProgrammaticToolCallingTool(config)
|
|
813
|
+
];
|
|
1066
814
|
}
|
|
1067
815
|
/**
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
816
|
+
* Variant of `createLocalCodingTools` that returns the bundle alongside
|
|
817
|
+
* the file checkpointer so callers can later call
|
|
818
|
+
* `bundle.checkpointer?.rewind()`.
|
|
819
|
+
*/
|
|
1072
820
|
function createLocalCodingToolBundle(config = {}, options = {}) {
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
tools: createLocalCodingTools(config, { checkpointer }),
|
|
1079
|
-
checkpointer,
|
|
1080
|
-
};
|
|
821
|
+
const checkpointer = options.checkpointer ?? (config.fileCheckpointing === true ? createLocalFileCheckpointer({ fs: config.exec?.fs }) : void 0);
|
|
822
|
+
return {
|
|
823
|
+
tools: createLocalCodingTools(config, { checkpointer }),
|
|
824
|
+
checkpointer
|
|
825
|
+
};
|
|
1081
826
|
}
|
|
1082
827
|
function createLocalCodingToolDefinitions() {
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
828
|
+
return [
|
|
829
|
+
toolDefinition("read_file", "Read a local text file from the configured working directory with line numbers.", LocalReadFileToolSchema),
|
|
830
|
+
toolDefinition(LocalWriteFileToolName, "Create or overwrite a local text file in the configured working directory.", LocalWriteFileToolSchema),
|
|
831
|
+
toolDefinition(LocalEditFileToolName, "Apply exact text replacements to a local file.", LocalEditFileToolSchema),
|
|
832
|
+
toolDefinition(LocalGrepSearchToolName, "Search local files with ripgrep and return matching lines.", LocalGrepSearchToolSchema),
|
|
833
|
+
toolDefinition(LocalGlobSearchToolName, "Find local files matching a glob pattern.", LocalGlobSearchToolSchema),
|
|
834
|
+
toolDefinition(LocalListDirectoryToolName, "List files and directories in a local directory.", LocalListDirectoryToolSchema),
|
|
835
|
+
createCompileCheckToolDefinition()
|
|
836
|
+
];
|
|
1092
837
|
}
|
|
1093
838
|
function createLocalCodingToolRegistry() {
|
|
1094
|
-
|
|
1095
|
-
definition.name,
|
|
1096
|
-
definition,
|
|
1097
|
-
]));
|
|
839
|
+
return new Map(createLocalCodingToolDefinitions().map((definition) => [definition.name, definition]));
|
|
1098
840
|
}
|
|
1099
|
-
|
|
841
|
+
//#endregion
|
|
1100
842
|
export { LocalEditFileToolName, LocalEditFileToolSchema, LocalGlobSearchToolName, LocalGlobSearchToolSchema, LocalGrepSearchToolName, LocalGrepSearchToolSchema, LocalListDirectoryToolName, LocalListDirectoryToolSchema, LocalReadFileToolSchema, LocalWriteFileToolName, LocalWriteFileToolSchema, _resetRipgrepCacheForTests, createLocalCodingToolBundle, createLocalCodingToolDefinitions, createLocalCodingToolRegistry, createLocalCodingTools, createLocalEditFileTool, createLocalGlobSearchTool, createLocalGrepSearchTool, createLocalListDirectoryTool, createLocalReadFileTool, createLocalWriteFileTool };
|
|
1101
|
-
|
|
843
|
+
|
|
844
|
+
//# sourceMappingURL=LocalCodingTools.mjs.map
|