@librechat/agents 3.2.32 → 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 -731
- package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs +171 -256
- 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 +305 -418
- 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 -1387
- 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 -725
- package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs +171 -253
- 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 +305 -416
- 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 -1383
- 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/tools/search/tool.d.ts +17 -0
- package/dist/types/tools/search/types.d.ts +4 -0
- package/package.json +4 -10
- 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,1104 +1,844 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const MAX_READ_CHARS = 256000;
|
|
1
|
+
require("../../common/enum.cjs");
|
|
2
|
+
require("../../common/index.cjs");
|
|
3
|
+
const require_LocalExecutionEngine = require("./LocalExecutionEngine.cjs");
|
|
4
|
+
const require_CompileCheckTool = require("./CompileCheckTool.cjs");
|
|
5
|
+
const require_FileCheckpointer = require("./FileCheckpointer.cjs");
|
|
6
|
+
const require_LocalProgrammaticToolCalling = require("./LocalProgrammaticToolCalling.cjs");
|
|
7
|
+
const require_LocalExecutionTools = require("./LocalExecutionTools.cjs");
|
|
8
|
+
const require_attachments = require("./attachments.cjs");
|
|
9
|
+
const require_editStrategies = require("./editStrategies.cjs");
|
|
10
|
+
const require_textEncoding = require("./textEncoding.cjs");
|
|
11
|
+
const require_syntaxCheck = require("./syntaxCheck.cjs");
|
|
12
|
+
let _langchain_core_tools = require("@langchain/core/tools");
|
|
13
|
+
let path = require("path");
|
|
14
|
+
let diff = require("diff");
|
|
15
|
+
//#region src/tools/local/LocalCodingTools.ts
|
|
16
|
+
const MAX_READ_CHARS = 256e3;
|
|
18
17
|
const DEFAULT_MAX_RESULTS = 200;
|
|
19
18
|
const DEFAULT_MAX_READ_BYTES = 10 * 1024 * 1024;
|
|
20
|
-
const BINARY_DETECTION_BYTES =
|
|
19
|
+
const BINARY_DETECTION_BYTES = 8e3;
|
|
21
20
|
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const LocalWriteFileToolName =
|
|
28
|
-
const LocalEditFileToolName =
|
|
29
|
-
const LocalGrepSearchToolName =
|
|
30
|
-
const LocalGlobSearchToolName =
|
|
31
|
-
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";
|
|
32
31
|
const LocalReadFileToolSchema = {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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"]
|
|
49
48
|
};
|
|
50
49
|
const LocalWriteFileToolSchema = {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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"]
|
|
63
62
|
};
|
|
64
63
|
const LocalEditFileToolSchema = {
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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"]
|
|
93
92
|
};
|
|
94
93
|
const LocalGrepSearchToolSchema = {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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"]
|
|
115
114
|
};
|
|
116
115
|
const LocalGlobSearchToolSchema = {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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"]
|
|
133
132
|
};
|
|
134
133
|
const LocalListDirectoryToolSchema = {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
},
|
|
141
|
-
},
|
|
134
|
+
type: "object",
|
|
135
|
+
properties: { path: {
|
|
136
|
+
type: "string",
|
|
137
|
+
description: "Directory to list. Defaults to cwd."
|
|
138
|
+
} }
|
|
142
139
|
};
|
|
143
140
|
function lineWindow(content, offset, limit) {
|
|
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
|
-
|
|
178
|
-
|
|
179
|
-
out.push(content.slice(pos));
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
out.push(content.slice(pos, next));
|
|
183
|
-
pos = next + 1;
|
|
184
|
-
if (k === limit - 1 && pos < content.length) {
|
|
185
|
-
exhausted = false;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
const numbered = out
|
|
189
|
-
.map((text, index) => `${String(start + index + 1).padStart(6, ' ')}\t${text}`)
|
|
190
|
-
.join('\n');
|
|
191
|
-
return {
|
|
192
|
-
text: LocalExecutionEngine.truncateLocalOutput(numbered, MAX_READ_CHARS),
|
|
193
|
-
truncated: !exhausted || numbered.length > MAX_READ_CHARS,
|
|
194
|
-
};
|
|
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: require_LocalExecutionEngine.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: require_LocalExecutionEngine.truncateLocalOutput(numbered, MAX_READ_CHARS),
|
|
174
|
+
truncated: !exhausted || numbered.length > MAX_READ_CHARS
|
|
175
|
+
};
|
|
195
176
|
}
|
|
196
|
-
const MAX_DIFF_CHARS =
|
|
197
|
-
async function maybeRunSyntaxCheck(path, config) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
177
|
+
const MAX_DIFF_CHARS = 4e3;
|
|
178
|
+
async function maybeRunSyntaxCheck(path$1, config) {
|
|
179
|
+
const mode = config.postEditSyntaxCheck ?? "off";
|
|
180
|
+
if (mode === "off") return void 0;
|
|
181
|
+
const outcome = await require_syntaxCheck.runPostEditSyntaxCheck(path$1, config);
|
|
182
|
+
if (outcome == null) return void 0;
|
|
183
|
+
return {
|
|
184
|
+
mode,
|
|
185
|
+
outcome
|
|
186
|
+
};
|
|
205
187
|
}
|
|
206
188
|
function appendSyntaxCheckSummary(base, run) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
return base;
|
|
211
|
-
const banner = run.mode === 'strict'
|
|
212
|
-
? `\n\n[syntax-check FAILED via ${run.outcome.checker}]\n`
|
|
213
|
-
: `\n\n[syntax-check warning via ${run.outcome.checker}]\n`;
|
|
214
|
-
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}`;
|
|
215
192
|
}
|
|
216
193
|
/**
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
async function revertStrictWrite(fs, path, existed, before, encoding) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
else {
|
|
239
|
-
await fs.unlink(path);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
catch {
|
|
243
|
-
/* best-effort: caller still sees the original syntax error */
|
|
244
|
-
}
|
|
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
|
+
*/
|
|
207
|
+
async function revertStrictWrite(fs, path$2, existed, before, encoding) {
|
|
208
|
+
try {
|
|
209
|
+
if (existed) await fs.writeFile(path$2, require_textEncoding.encodeFile(before, {
|
|
210
|
+
...encoding,
|
|
211
|
+
text: before
|
|
212
|
+
}), "utf8");
|
|
213
|
+
else await fs.unlink(path$2);
|
|
214
|
+
} catch {}
|
|
245
215
|
}
|
|
246
216
|
function summariseDiff(filePath, before, after) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
context: 3,
|
|
253
|
-
});
|
|
254
|
-
if (patch.length <= MAX_DIFF_CHARS) {
|
|
255
|
-
return patch;
|
|
256
|
-
}
|
|
257
|
-
return (patch.slice(0, MAX_DIFF_CHARS) +
|
|
258
|
-
`\n[... diff truncated, ${patch.length - MAX_DIFF_CHARS} more chars ...]`);
|
|
217
|
+
if (before === after) return "(no textual changes)";
|
|
218
|
+
const name = (0, path.basename)(filePath);
|
|
219
|
+
const patch = (0, diff.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 ...]`;
|
|
259
222
|
}
|
|
260
223
|
function normalizeEdits(input) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
newText: input.new_text ?? '',
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
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;
|
|
274
233
|
}
|
|
275
234
|
function toolDefinition(name, description, parameters) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
235
|
+
return {
|
|
236
|
+
name,
|
|
237
|
+
description,
|
|
238
|
+
parameters,
|
|
239
|
+
allowed_callers: ["direct", "code_execution"],
|
|
240
|
+
responseFormat: "content_and_artifact",
|
|
241
|
+
toolType: "builtin"
|
|
242
|
+
};
|
|
284
243
|
}
|
|
285
|
-
async function looksBinary(path, fs) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
return false;
|
|
297
|
-
}
|
|
298
|
-
finally {
|
|
299
|
-
await handle?.close();
|
|
300
|
-
}
|
|
244
|
+
async function looksBinary(path$3, fs) {
|
|
245
|
+
let handle;
|
|
246
|
+
try {
|
|
247
|
+
handle = await fs.open(path$3, "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
|
+
}
|
|
301
255
|
}
|
|
302
256
|
const DEFAULT_MAX_ATTACHMENT_BYTES = 5 * 1024 * 1024;
|
|
303
257
|
function createLocalReadFileTool(config = {}) {
|
|
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
|
-
|
|
372
|
-
|
|
373
|
-
return [
|
|
374
|
-
`Refusing to read binary file (${fileStat.size} bytes, ${attachment.mime}): ${path}`,
|
|
375
|
-
{
|
|
376
|
-
path,
|
|
377
|
-
bytes: fileStat.size,
|
|
378
|
-
mime: attachment.mime,
|
|
379
|
-
binary: true,
|
|
380
|
-
},
|
|
381
|
-
];
|
|
382
|
-
}
|
|
383
|
-
// text-or-unknown falls through to the text-read path below.
|
|
384
|
-
}
|
|
385
|
-
else {
|
|
386
|
-
return [
|
|
387
|
-
`Refusing to read binary file (${fileStat.size} bytes): ${path}`,
|
|
388
|
-
{ path, bytes: fileStat.size, binary: true },
|
|
389
|
-
];
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
const content = await fs.readFile(path, 'utf8');
|
|
393
|
-
const result = lineWindow(content, input.offset, input.limit);
|
|
394
|
-
return [
|
|
395
|
-
result.truncated ? `${result.text}\n[truncated]` : result.text,
|
|
396
|
-
{ path, bytes: fileStat.size },
|
|
397
|
-
];
|
|
398
|
-
}, {
|
|
399
|
-
name: _enum.Constants.READ_FILE,
|
|
400
|
-
description: 'Read a local text file from the configured working directory with line numbers. ' +
|
|
401
|
-
'When `attachReadAttachments` is enabled (e.g. images-only), reading an image returns an ' +
|
|
402
|
-
'`image_url` content block so vision-capable models can see the file directly.',
|
|
403
|
-
schema: LocalReadFileToolSchema,
|
|
404
|
-
responseFormat: _enum.Constants.CONTENT_AND_ARTIFACT,
|
|
405
|
-
});
|
|
258
|
+
const fs = require_LocalExecutionEngine.getWorkspaceFS(config);
|
|
259
|
+
return (0, _langchain_core_tools.tool)(async (rawInput) => {
|
|
260
|
+
const input = rawInput;
|
|
261
|
+
const path$4 = await require_LocalExecutionEngine.resolveWorkspacePathSafe(input.file_path, config, "read");
|
|
262
|
+
const fileStat = await fs.stat(path$4);
|
|
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: path$4,
|
|
267
|
+
bytes: fileStat.size,
|
|
268
|
+
truncated: true
|
|
269
|
+
}];
|
|
270
|
+
if (await looksBinary(path$4, fs)) {
|
|
271
|
+
const attachmentMode = config.attachReadAttachments ?? "off";
|
|
272
|
+
if (attachmentMode !== "off") {
|
|
273
|
+
const attachment = await require_attachments.classifyAttachment({
|
|
274
|
+
path: path$4,
|
|
275
|
+
bytes: fileStat.size,
|
|
276
|
+
mode: attachmentMode,
|
|
277
|
+
maxBytes: config.maxAttachmentBytes ?? DEFAULT_MAX_ATTACHMENT_BYTES,
|
|
278
|
+
fs
|
|
279
|
+
});
|
|
280
|
+
if (attachment.kind === "image") return [require_attachments.imageAttachmentContent(path$4, attachment), {
|
|
281
|
+
path: path$4,
|
|
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$4} (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: path$4,
|
|
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: path$4,
|
|
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$4}`, {
|
|
305
|
+
path: path$4,
|
|
306
|
+
bytes: fileStat.size,
|
|
307
|
+
mime: attachment.mime,
|
|
308
|
+
binary: true
|
|
309
|
+
}];
|
|
310
|
+
} else return [`Refusing to read binary file (${fileStat.size} bytes): ${path$4}`, {
|
|
311
|
+
path: path$4,
|
|
312
|
+
bytes: fileStat.size,
|
|
313
|
+
binary: true
|
|
314
|
+
}];
|
|
315
|
+
}
|
|
316
|
+
const result = lineWindow(await fs.readFile(path$4, "utf8"), input.offset, input.limit);
|
|
317
|
+
return [result.truncated ? `${result.text}\n[truncated]` : result.text, {
|
|
318
|
+
path: path$4,
|
|
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
|
+
});
|
|
406
327
|
}
|
|
407
328
|
function createLocalWriteFileTool(config = {}, checkpointer) {
|
|
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
|
-
|
|
452
|
-
|
|
453
|
-
bytes: finalText.length,
|
|
454
|
-
new_file: !existed,
|
|
455
|
-
newline: encoding.newline === '\r\n' ? 'CRLF' : 'LF',
|
|
456
|
-
had_bom: encoding.hasBom,
|
|
457
|
-
...(syntax != null && syntax.outcome.ok === false
|
|
458
|
-
? { syntax_error: syntax.outcome.checker }
|
|
459
|
-
: {}),
|
|
460
|
-
},
|
|
461
|
-
];
|
|
462
|
-
}, {
|
|
463
|
-
name: LocalWriteFileToolName,
|
|
464
|
-
description: 'Create or overwrite a local text file in the configured working directory. ' +
|
|
465
|
-
'Preserves the existing BOM and line endings when overwriting; defaults to LF without BOM for new files. ' +
|
|
466
|
-
'Returns a unified diff of the changes when overwriting.',
|
|
467
|
-
schema: LocalWriteFileToolSchema,
|
|
468
|
-
responseFormat: _enum.Constants.CONTENT_AND_ARTIFACT,
|
|
469
|
-
});
|
|
329
|
+
const fs = require_LocalExecutionEngine.getWorkspaceFS(config);
|
|
330
|
+
return (0, _langchain_core_tools.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$5 = await require_LocalExecutionEngine.resolveWorkspacePathSafe(input.file_path, config, "write");
|
|
334
|
+
if (checkpointer != null) await checkpointer.captureBeforeWrite(path$5);
|
|
335
|
+
let before = "";
|
|
336
|
+
let encoding = {
|
|
337
|
+
text: "",
|
|
338
|
+
hasBom: false,
|
|
339
|
+
newline: "\n"
|
|
340
|
+
};
|
|
341
|
+
let existed = false;
|
|
342
|
+
try {
|
|
343
|
+
const decoded = require_textEncoding.decodeFile(await fs.readFile(path$5, "utf8"));
|
|
344
|
+
before = decoded.text;
|
|
345
|
+
encoding = decoded;
|
|
346
|
+
existed = true;
|
|
347
|
+
} catch {
|
|
348
|
+
existed = false;
|
|
349
|
+
}
|
|
350
|
+
await fs.mkdir((0, path.dirname)(path$5), { recursive: true });
|
|
351
|
+
const finalText = require_textEncoding.encodeFile(input.content, encoding);
|
|
352
|
+
await fs.writeFile(path$5, finalText, "utf8");
|
|
353
|
+
const syntax = await maybeRunSyntaxCheck(path$5, config);
|
|
354
|
+
const diff$1 = existed ? summariseDiff(path$5, before, input.content) : `(new file, ${input.content.length} chars)`;
|
|
355
|
+
const summary = appendSyntaxCheckSummary(existed ? `Overwrote ${path$5} (${input.content.length} chars). Diff:\n${diff$1}` : `Created ${path$5} (${input.content.length} chars).`, syntax);
|
|
356
|
+
if (syntax?.outcome.ok === false && syntax.mode === "strict") {
|
|
357
|
+
await revertStrictWrite(fs, path$5, 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: path$5,
|
|
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
|
+
});
|
|
470
374
|
}
|
|
471
375
|
function createLocalEditFileTool(config = {}, checkpointer) {
|
|
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
|
-
|
|
514
|
-
|
|
515
|
-
await revertStrictWrite(fs, path, true, original, encoding);
|
|
516
|
-
throw new Error(`edit_file syntax check failed (${syntax.outcome.checker}); reverted to pre-edit state.\n${syntax.outcome.output}`);
|
|
517
|
-
}
|
|
518
|
-
return [
|
|
519
|
-
summary,
|
|
520
|
-
{
|
|
521
|
-
path,
|
|
522
|
-
edits: edits.length,
|
|
523
|
-
strategies: strategiesUsed,
|
|
524
|
-
newline: encoding.newline === '\r\n' ? 'CRLF' : 'LF',
|
|
525
|
-
had_bom: encoding.hasBom,
|
|
526
|
-
...(syntax != null && syntax.outcome.ok === false
|
|
527
|
-
? { syntax_error: syntax.outcome.checker }
|
|
528
|
-
: {}),
|
|
529
|
-
},
|
|
530
|
-
];
|
|
531
|
-
}, {
|
|
532
|
-
name: LocalEditFileToolName,
|
|
533
|
-
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.',
|
|
534
|
-
schema: LocalEditFileToolSchema,
|
|
535
|
-
responseFormat: _enum.Constants.CONTENT_AND_ARTIFACT,
|
|
536
|
-
});
|
|
376
|
+
const fs = require_LocalExecutionEngine.getWorkspaceFS(config);
|
|
377
|
+
return (0, _langchain_core_tools.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$6 = await require_LocalExecutionEngine.resolveWorkspacePathSafe(input.file_path, config, "write");
|
|
383
|
+
const encoding = require_textEncoding.decodeFile(await fs.readFile(path$6, "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 = require_editStrategies.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 = require_editStrategies.applyEdit(next, match, edit.newText);
|
|
393
|
+
}
|
|
394
|
+
if (checkpointer != null) await checkpointer.captureBeforeWrite(path$6);
|
|
395
|
+
const finalText = require_textEncoding.encodeFile(next, encoding);
|
|
396
|
+
await fs.writeFile(path$6, finalText, "utf8");
|
|
397
|
+
const syntax = await maybeRunSyntaxCheck(path$6, config);
|
|
398
|
+
const diff$2 = summariseDiff(path$6, original, next);
|
|
399
|
+
const fuzzy = strategiesUsed.some((s) => s !== "exact");
|
|
400
|
+
const summary = appendSyntaxCheckSummary(`Applied ${edits.length} edit(s) to ${path$6}` + (fuzzy ? ` (strategies: ${strategiesUsed.join(", ")})` : "") + `. Diff:\n${diff$2}`, syntax);
|
|
401
|
+
if (syntax?.outcome.ok === false && syntax.mode === "strict") {
|
|
402
|
+
await revertStrictWrite(fs, path$6, 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: path$6,
|
|
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
|
+
});
|
|
537
419
|
}
|
|
538
420
|
/**
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
// backend alone misses the case where two Runs share a backend but
|
|
551
|
-
// vary `local.env` (especially PATH). Stale cache then claims `rg`
|
|
552
|
-
// is available, the rg path runs, and the spawn fails with ENOENT
|
|
553
|
-
// instead of falling back to the Node walker. The inner Map is
|
|
554
|
-
// keyed by a stable JSON hash of the effective env so each unique
|
|
555
|
-
// env gets its own probe.
|
|
556
|
-
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();
|
|
557
432
|
function envCacheKey(env) {
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
if (env == null)
|
|
563
|
-
return '';
|
|
564
|
-
const sorted = {};
|
|
565
|
-
for (const k of Object.keys(env).sort()) {
|
|
566
|
-
sorted[k] = env[k];
|
|
567
|
-
}
|
|
568
|
-
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);
|
|
569
437
|
}
|
|
570
438
|
async function isRipgrepAvailable(config) {
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
439
|
+
const backend = require_LocalExecutionEngine.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 = require_LocalExecutionEngine.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;
|
|
586
456
|
}
|
|
587
457
|
/**
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
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
|
+
*/
|
|
595
465
|
function _resetRipgrepCacheForTests() {
|
|
596
|
-
|
|
466
|
+
ripgrepAvailabilityByBackend = /* @__PURE__ */ new WeakMap();
|
|
597
467
|
}
|
|
598
|
-
// Skipped by the Node-fallback walker (used when ripgrep is
|
|
599
|
-
// unavailable). Covers common build outputs, virtualenvs, and
|
|
600
|
-
// caches so a `grep_search`/`glob_search` on a large monorepo or a
|
|
601
|
-
// Python project with `.venv/` doesn't read every file under those
|
|
602
|
-
// trees. ripgrep itself respects .gitignore so it doesn't need this
|
|
603
|
-
// list. Audit follow-up from the comprehensive review (finding #3).
|
|
604
468
|
const SKIP_DIRS = new Set([
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
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"
|
|
629
493
|
]);
|
|
630
494
|
function globToRegExp(pattern) {
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
}
|
|
646
|
-
else if (c === '?') {
|
|
647
|
-
result += '[^/]';
|
|
648
|
-
}
|
|
649
|
-
else if ('.+^$|(){}[]\\'.includes(c)) {
|
|
650
|
-
result += '\\' + c;
|
|
651
|
-
}
|
|
652
|
-
else {
|
|
653
|
-
result += c;
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
result += '$';
|
|
657
|
-
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);
|
|
658
509
|
}
|
|
659
510
|
async function* walkFiles(root, fs) {
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
stack.push(full);
|
|
677
|
-
}
|
|
678
|
-
else if (entry.isFile()) {
|
|
679
|
-
yield full;
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
}
|
|
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
|
+
}
|
|
683
527
|
}
|
|
684
528
|
/**
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
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
|
+
*/
|
|
710
554
|
const MAX_FALLBACK_PATTERN_LENGTH = 1024;
|
|
711
|
-
const FALLBACK_GREP_BUDGET_MS =
|
|
712
|
-
// Per-file byte cap. Codex P2 #41 — without it, the whole-file
|
|
713
|
-
// `readFile` + `split('\n')` for a multi-GB log is an unbounded
|
|
714
|
-
// allocation that the wall-clock budget (checked between files)
|
|
715
|
-
// can't interrupt. Hosts that need to grep large files should
|
|
716
|
-
// install ripgrep.
|
|
555
|
+
const FALLBACK_GREP_BUDGET_MS = 5e3;
|
|
717
556
|
const FALLBACK_GREP_MAX_FILE_BYTES = 5 * 1024 * 1024;
|
|
718
557
|
/**
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
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
|
+
*/
|
|
727
566
|
function hasNestedUnboundedQuantifier(pattern) {
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
}
|
|
752
|
-
j--;
|
|
753
|
-
}
|
|
754
|
-
if (j < 0)
|
|
755
|
-
continue;
|
|
756
|
-
const inner = pattern.slice(j + 1, i);
|
|
757
|
-
if (/(?<!\\)[+*]/.test(inner))
|
|
758
|
-
return true;
|
|
759
|
-
}
|
|
760
|
-
return false;
|
|
761
|
-
}
|
|
762
|
-
class FallbackGrepError extends Error {
|
|
763
|
-
kind;
|
|
764
|
-
constructor(kind, message) {
|
|
765
|
-
super(message);
|
|
766
|
-
this.kind = kind;
|
|
767
|
-
}
|
|
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;
|
|
768
590
|
}
|
|
591
|
+
var FallbackGrepError = class extends Error {
|
|
592
|
+
kind;
|
|
593
|
+
constructor(kind, message) {
|
|
594
|
+
super(message);
|
|
595
|
+
this.kind = kind;
|
|
596
|
+
}
|
|
597
|
+
};
|
|
769
598
|
function compileFallbackRegex(pattern) {
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
return new RegExp(pattern);
|
|
778
|
-
}
|
|
779
|
-
catch (e) {
|
|
780
|
-
throw new FallbackGrepError('invalid-pattern', `Invalid regex: ${e.message}`);
|
|
781
|
-
}
|
|
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
|
+
}
|
|
782
606
|
}
|
|
783
607
|
/** Renders fallback-grep output: real matches first, skip diagnostics appended. */
|
|
784
608
|
function formatFallbackGrepDisplay(result) {
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
if (result.skipped.length > 0) {
|
|
789
|
-
return result.skipped.join('\n');
|
|
790
|
-
}
|
|
791
|
-
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.";
|
|
792
612
|
}
|
|
793
613
|
async function fallbackGrep(root, pattern, globFilter, maxResults, fs) {
|
|
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
|
-
|
|
841
|
-
|
|
842
|
-
catch {
|
|
843
|
-
continue;
|
|
844
|
-
}
|
|
845
|
-
if (content.includes('\0')) {
|
|
846
|
-
continue;
|
|
847
|
-
}
|
|
848
|
-
// Re-check the deadline AFTER the read — a slow disk on one
|
|
849
|
-
// file can blow the budget without us noticing.
|
|
850
|
-
if (Date.now() > deadline) {
|
|
851
|
-
return { matches, skipped: skippedDiagnostics };
|
|
852
|
-
}
|
|
853
|
-
const lines = content.split('\n');
|
|
854
|
-
for (let i = 0; i < lines.length; i++) {
|
|
855
|
-
if (rx.test(lines[i])) {
|
|
856
|
-
matches.push(`${file}:${i + 1}:${lines[i]}`);
|
|
857
|
-
if (matches.length >= maxResults) {
|
|
858
|
-
return { matches, skipped: skippedDiagnostics };
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
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
|
+
};
|
|
864
662
|
}
|
|
865
663
|
async function fallbackGlob(root, pattern, maxResults, fs) {
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
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;
|
|
880
674
|
}
|
|
881
675
|
function createLocalGrepSearchTool(config = {}) {
|
|
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
|
-
|
|
941
|
-
|
|
942
|
-
const { matches, skipped } = await fallbackGrep(target, input.pattern, input.glob, maxResults, fs);
|
|
943
|
-
// Artifact count: ONLY real matches (Codex P2 [43] —
|
|
944
|
-
// skip sentinels used to inflate the count and the budget).
|
|
945
|
-
const display = formatFallbackGrepDisplay({ matches, skipped });
|
|
946
|
-
return [
|
|
947
|
-
display,
|
|
948
|
-
{
|
|
949
|
-
matches: matches.length,
|
|
950
|
-
skipped: skipped.length,
|
|
951
|
-
engine: 'node-fallback',
|
|
952
|
-
},
|
|
953
|
-
];
|
|
954
|
-
}
|
|
955
|
-
catch (e) {
|
|
956
|
-
if (e instanceof FallbackGrepError) {
|
|
957
|
-
return [
|
|
958
|
-
`grep_search refused the pattern: ${e.message}`,
|
|
959
|
-
{
|
|
960
|
-
matches: 0,
|
|
961
|
-
engine: 'node-fallback',
|
|
962
|
-
error: e.message,
|
|
963
|
-
kind: e.kind,
|
|
964
|
-
},
|
|
965
|
-
];
|
|
966
|
-
}
|
|
967
|
-
throw e;
|
|
968
|
-
}
|
|
969
|
-
}, {
|
|
970
|
-
name: LocalGrepSearchToolName,
|
|
971
|
-
description: 'Search local files for a regex pattern (ripgrep when available, Node fallback otherwise).',
|
|
972
|
-
schema: LocalGrepSearchToolSchema,
|
|
973
|
-
responseFormat: _enum.Constants.CONTENT_AND_ARTIFACT,
|
|
974
|
-
});
|
|
676
|
+
const fs = require_LocalExecutionEngine.getWorkspaceFS(config);
|
|
677
|
+
return (0, _langchain_core_tools.tool)(async (rawInput) => {
|
|
678
|
+
const input = rawInput;
|
|
679
|
+
const target = await require_LocalExecutionEngine.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 require_LocalExecutionEngine.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
|
+
});
|
|
975
736
|
}
|
|
976
737
|
function createLocalGlobSearchTool(config = {}) {
|
|
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
|
-
|
|
1020
|
-
|
|
1021
|
-
const files = await fallbackGlob(target, input.pattern, maxResults, fs);
|
|
1022
|
-
return [
|
|
1023
|
-
files.length > 0 ? files.join('\n') : 'No files found.',
|
|
1024
|
-
{ files, engine: 'node-fallback' },
|
|
1025
|
-
];
|
|
1026
|
-
}, {
|
|
1027
|
-
name: LocalGlobSearchToolName,
|
|
1028
|
-
description: 'Find local files matching a glob pattern (ripgrep when available, Node fallback otherwise).',
|
|
1029
|
-
schema: LocalGlobSearchToolSchema,
|
|
1030
|
-
responseFormat: _enum.Constants.CONTENT_AND_ARTIFACT,
|
|
1031
|
-
});
|
|
738
|
+
const fs = require_LocalExecutionEngine.getWorkspaceFS(config);
|
|
739
|
+
return (0, _langchain_core_tools.tool)(async (rawInput) => {
|
|
740
|
+
const input = rawInput;
|
|
741
|
+
const target = await require_LocalExecutionEngine.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 require_LocalExecutionEngine.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
|
+
});
|
|
1032
782
|
}
|
|
1033
783
|
function createLocalListDirectoryTool(config = {}) {
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
});
|
|
784
|
+
const fs = require_LocalExecutionEngine.getWorkspaceFS(config);
|
|
785
|
+
return (0, _langchain_core_tools.tool)(async (rawInput) => {
|
|
786
|
+
const path$7 = await require_LocalExecutionEngine.resolveWorkspacePathSafe(rawInput.path ?? ".", config, "read");
|
|
787
|
+
const entries = await fs.readdir(path$7, { withFileTypes: true });
|
|
788
|
+
return [entries.map((entry) => `${entry.isDirectory() ? "dir " : "file"}\t${entry.name}`).join("\n") || "Directory is empty.", {
|
|
789
|
+
path: path$7,
|
|
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
|
+
});
|
|
1049
798
|
}
|
|
1050
799
|
function createLocalCodingTools(config = {}, options = {}) {
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
LocalProgrammaticToolCalling.createLocalProgrammaticToolCallingTool(config),
|
|
1066
|
-
LocalProgrammaticToolCalling.createLocalBashProgrammaticToolCallingTool(config),
|
|
1067
|
-
];
|
|
800
|
+
const checkpointer = options.checkpointer ?? (config.fileCheckpointing === true ? require_FileCheckpointer.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
|
+
require_CompileCheckTool.createCompileCheckTool(config),
|
|
809
|
+
require_LocalExecutionTools.createLocalBashExecutionTool({ config }),
|
|
810
|
+
require_LocalExecutionTools.createLocalCodeExecutionTool(config),
|
|
811
|
+
require_LocalProgrammaticToolCalling.createLocalProgrammaticToolCallingTool(config),
|
|
812
|
+
require_LocalProgrammaticToolCalling.createLocalBashProgrammaticToolCallingTool(config)
|
|
813
|
+
];
|
|
1068
814
|
}
|
|
1069
815
|
/**
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
816
|
+
* Variant of `createLocalCodingTools` that returns the bundle alongside
|
|
817
|
+
* the file checkpointer so callers can later call
|
|
818
|
+
* `bundle.checkpointer?.rewind()`.
|
|
819
|
+
*/
|
|
1074
820
|
function createLocalCodingToolBundle(config = {}, options = {}) {
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
tools: createLocalCodingTools(config, { checkpointer }),
|
|
1081
|
-
checkpointer,
|
|
1082
|
-
};
|
|
821
|
+
const checkpointer = options.checkpointer ?? (config.fileCheckpointing === true ? require_FileCheckpointer.createLocalFileCheckpointer({ fs: config.exec?.fs }) : void 0);
|
|
822
|
+
return {
|
|
823
|
+
tools: createLocalCodingTools(config, { checkpointer }),
|
|
824
|
+
checkpointer
|
|
825
|
+
};
|
|
1083
826
|
}
|
|
1084
827
|
function createLocalCodingToolDefinitions() {
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
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
|
+
require_CompileCheckTool.createCompileCheckToolDefinition()
|
|
836
|
+
];
|
|
1094
837
|
}
|
|
1095
838
|
function createLocalCodingToolRegistry() {
|
|
1096
|
-
|
|
1097
|
-
definition.name,
|
|
1098
|
-
definition,
|
|
1099
|
-
]));
|
|
839
|
+
return new Map(createLocalCodingToolDefinitions().map((definition) => [definition.name, definition]));
|
|
1100
840
|
}
|
|
1101
|
-
|
|
841
|
+
//#endregion
|
|
1102
842
|
exports.LocalEditFileToolName = LocalEditFileToolName;
|
|
1103
843
|
exports.LocalEditFileToolSchema = LocalEditFileToolSchema;
|
|
1104
844
|
exports.LocalGlobSearchToolName = LocalGlobSearchToolName;
|
|
@@ -1121,4 +861,5 @@ exports.createLocalGrepSearchTool = createLocalGrepSearchTool;
|
|
|
1121
861
|
exports.createLocalListDirectoryTool = createLocalListDirectoryTool;
|
|
1122
862
|
exports.createLocalReadFileTool = createLocalReadFileTool;
|
|
1123
863
|
exports.createLocalWriteFileTool = createLocalWriteFileTool;
|
|
1124
|
-
|
|
864
|
+
|
|
865
|
+
//# sourceMappingURL=LocalCodingTools.cjs.map
|