sema-core 1.0.2
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/LICENSE +21 -0
- package/README.md +150 -0
- package/dist/constants/config.d.ts +20 -0
- package/dist/constants/config.d.ts.map +1 -0
- package/dist/constants/config.js +31 -0
- package/dist/constants/config.js.map +1 -0
- package/dist/constants/message.d.ts +10 -0
- package/dist/constants/message.d.ts.map +1 -0
- package/dist/constants/message.js +25 -0
- package/dist/constants/message.js.map +1 -0
- package/dist/constants/product.d.ts +5 -0
- package/dist/constants/product.d.ts.map +1 -0
- package/dist/constants/product.js +8 -0
- package/dist/constants/product.js.map +1 -0
- package/dist/core/Conversation.d.ts +16 -0
- package/dist/core/Conversation.d.ts.map +1 -0
- package/dist/core/Conversation.js +226 -0
- package/dist/core/Conversation.js.map +1 -0
- package/dist/core/RunTools.d.ts +11 -0
- package/dist/core/RunTools.d.ts.map +1 -0
- package/dist/core/RunTools.js +244 -0
- package/dist/core/RunTools.js.map +1 -0
- package/dist/core/SemaCore.d.ts +49 -0
- package/dist/core/SemaCore.d.ts.map +1 -0
- package/dist/core/SemaCore.js +94 -0
- package/dist/core/SemaCore.js.map +1 -0
- package/dist/core/SemaEngine.d.ts +54 -0
- package/dist/core/SemaEngine.d.ts.map +1 -0
- package/dist/core/SemaEngine.js +335 -0
- package/dist/core/SemaEngine.js.map +1 -0
- package/dist/events/EventSystem.d.ts +42 -0
- package/dist/events/EventSystem.d.ts.map +1 -0
- package/dist/events/EventSystem.js +134 -0
- package/dist/events/EventSystem.js.map +1 -0
- package/dist/events/types.d.ts +300 -0
- package/dist/events/types.d.ts.map +1 -0
- package/dist/events/types.js +4 -0
- package/dist/events/types.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/manager/ConfManager.d.ts +76 -0
- package/dist/manager/ConfManager.d.ts.map +1 -0
- package/dist/manager/ConfManager.js +329 -0
- package/dist/manager/ConfManager.js.map +1 -0
- package/dist/manager/ModelManager.d.ts +51 -0
- package/dist/manager/ModelManager.d.ts.map +1 -0
- package/dist/manager/ModelManager.js +291 -0
- package/dist/manager/ModelManager.js.map +1 -0
- package/dist/manager/PermissionManager.d.ts +16 -0
- package/dist/manager/PermissionManager.d.ts.map +1 -0
- package/dist/manager/PermissionManager.js +308 -0
- package/dist/manager/PermissionManager.js.map +1 -0
- package/dist/manager/StateManager.d.ts +164 -0
- package/dist/manager/StateManager.d.ts.map +1 -0
- package/dist/manager/StateManager.js +357 -0
- package/dist/manager/StateManager.js.map +1 -0
- package/dist/services/agents/agentsManager.d.ts +112 -0
- package/dist/services/agents/agentsManager.d.ts.map +1 -0
- package/dist/services/agents/agentsManager.js +394 -0
- package/dist/services/agents/agentsManager.js.map +1 -0
- package/dist/services/agents/defaultBuiltInAgentsConfs.d.ts +3 -0
- package/dist/services/agents/defaultBuiltInAgentsConfs.d.ts.map +1 -0
- package/dist/services/agents/defaultBuiltInAgentsConfs.js +102 -0
- package/dist/services/agents/defaultBuiltInAgentsConfs.js.map +1 -0
- package/dist/services/agents/genSystemPrompt.d.ts +23 -0
- package/dist/services/agents/genSystemPrompt.d.ts.map +1 -0
- package/dist/services/agents/genSystemPrompt.js +189 -0
- package/dist/services/agents/genSystemPrompt.js.map +1 -0
- package/dist/services/agents/prompt.d.ts +12 -0
- package/dist/services/agents/prompt.d.ts.map +1 -0
- package/dist/services/agents/prompt.js +162 -0
- package/dist/services/agents/prompt.js.map +1 -0
- package/dist/services/api/adapt/anthropic.d.ts +10 -0
- package/dist/services/api/adapt/anthropic.d.ts.map +1 -0
- package/dist/services/api/adapt/anthropic.js +233 -0
- package/dist/services/api/adapt/anthropic.js.map +1 -0
- package/dist/services/api/adapt/openai.d.ts +8 -0
- package/dist/services/api/adapt/openai.d.ts.map +1 -0
- package/dist/services/api/adapt/openai.js +412 -0
- package/dist/services/api/adapt/openai.js.map +1 -0
- package/dist/services/api/adapt/util.d.ts +7 -0
- package/dist/services/api/adapt/util.d.ts.map +1 -0
- package/dist/services/api/adapt/util.js +24 -0
- package/dist/services/api/adapt/util.js.map +1 -0
- package/dist/services/api/apiUtil.d.ts +10 -0
- package/dist/services/api/apiUtil.d.ts.map +1 -0
- package/dist/services/api/apiUtil.js +256 -0
- package/dist/services/api/apiUtil.js.map +1 -0
- package/dist/services/api/cache.d.ts +11 -0
- package/dist/services/api/cache.d.ts.map +1 -0
- package/dist/services/api/cache.js +128 -0
- package/dist/services/api/cache.js.map +1 -0
- package/dist/services/api/queryLLM.d.ts +18 -0
- package/dist/services/api/queryLLM.d.ts.map +1 -0
- package/dist/services/api/queryLLM.js +147 -0
- package/dist/services/api/queryLLM.js.map +1 -0
- package/dist/services/command/runCommand.d.ts +18 -0
- package/dist/services/command/runCommand.d.ts.map +1 -0
- package/dist/services/command/runCommand.js +149 -0
- package/dist/services/command/runCommand.js.map +1 -0
- package/dist/services/mcp/MCPClient.d.ts +35 -0
- package/dist/services/mcp/MCPClient.d.ts.map +1 -0
- package/dist/services/mcp/MCPClient.js +166 -0
- package/dist/services/mcp/MCPClient.js.map +1 -0
- package/dist/services/mcp/MCPManager.d.ts +140 -0
- package/dist/services/mcp/MCPManager.d.ts.map +1 -0
- package/dist/services/mcp/MCPManager.js +650 -0
- package/dist/services/mcp/MCPManager.js.map +1 -0
- package/dist/services/mcp/MCPToolAdapter.d.ts +22 -0
- package/dist/services/mcp/MCPToolAdapter.d.ts.map +1 -0
- package/dist/services/mcp/MCPToolAdapter.js +177 -0
- package/dist/services/mcp/MCPToolAdapter.js.map +1 -0
- package/dist/services/plugins/customCommands.d.ts +29 -0
- package/dist/services/plugins/customCommands.d.ts.map +1 -0
- package/dist/services/plugins/customCommands.js +227 -0
- package/dist/services/plugins/customCommands.js.map +1 -0
- package/dist/services/skill/skillLoader.d.ts +17 -0
- package/dist/services/skill/skillLoader.d.ts.map +1 -0
- package/dist/services/skill/skillLoader.js +122 -0
- package/dist/services/skill/skillLoader.js.map +1 -0
- package/dist/services/skill/skillParser.d.ts +15 -0
- package/dist/services/skill/skillParser.d.ts.map +1 -0
- package/dist/services/skill/skillParser.js +66 -0
- package/dist/services/skill/skillParser.js.map +1 -0
- package/dist/services/skill/skillRegistry.d.ts +34 -0
- package/dist/services/skill/skillRegistry.d.ts.map +1 -0
- package/dist/services/skill/skillRegistry.js +98 -0
- package/dist/services/skill/skillRegistry.js.map +1 -0
- package/dist/tools/AskUserQuestion/AskUserQuestion.d.ts +179 -0
- package/dist/tools/AskUserQuestion/AskUserQuestion.d.ts.map +1 -0
- package/dist/tools/AskUserQuestion/AskUserQuestion.js +165 -0
- package/dist/tools/AskUserQuestion/AskUserQuestion.js.map +1 -0
- package/dist/tools/AskUserQuestion/prompt.d.ts +3 -0
- package/dist/tools/AskUserQuestion/prompt.d.ts.map +1 -0
- package/dist/tools/AskUserQuestion/prompt.js +17 -0
- package/dist/tools/AskUserQuestion/prompt.js.map +1 -0
- package/dist/tools/Bash/Bash.d.ts +75 -0
- package/dist/tools/Bash/Bash.d.ts.map +1 -0
- package/dist/tools/Bash/Bash.js +200 -0
- package/dist/tools/Bash/Bash.js.map +1 -0
- package/dist/tools/Bash/prompt.d.ts +8 -0
- package/dist/tools/Bash/prompt.d.ts.map +1 -0
- package/dist/tools/Bash/prompt.js +167 -0
- package/dist/tools/Bash/prompt.js.map +1 -0
- package/dist/tools/Bash/utils.d.ts +5 -0
- package/dist/tools/Bash/utils.d.ts.map +1 -0
- package/dist/tools/Bash/utils.js +21 -0
- package/dist/tools/Bash/utils.js.map +1 -0
- package/dist/tools/Edit/Edit.d.ts +110 -0
- package/dist/tools/Edit/Edit.d.ts.map +1 -0
- package/dist/tools/Edit/Edit.js +213 -0
- package/dist/tools/Edit/Edit.js.map +1 -0
- package/dist/tools/Edit/prompt.d.ts +3 -0
- package/dist/tools/Edit/prompt.d.ts.map +1 -0
- package/dist/tools/Edit/prompt.js +15 -0
- package/dist/tools/Edit/prompt.js.map +1 -0
- package/dist/tools/Edit/utils.d.ts +10 -0
- package/dist/tools/Edit/utils.d.ts.map +1 -0
- package/dist/tools/Edit/utils.js +51 -0
- package/dist/tools/Edit/utils.js.map +1 -0
- package/dist/tools/ExitPlanMode/ExitPlanMode.d.ts +42 -0
- package/dist/tools/ExitPlanMode/ExitPlanMode.d.ts.map +1 -0
- package/dist/tools/ExitPlanMode/ExitPlanMode.js +157 -0
- package/dist/tools/ExitPlanMode/ExitPlanMode.js.map +1 -0
- package/dist/tools/ExitPlanMode/prompt.d.ts +3 -0
- package/dist/tools/ExitPlanMode/prompt.d.ts.map +1 -0
- package/dist/tools/ExitPlanMode/prompt.js +28 -0
- package/dist/tools/ExitPlanMode/prompt.js.map +1 -0
- package/dist/tools/Glob/Glob.d.ts +44 -0
- package/dist/tools/Glob/Glob.d.ts.map +1 -0
- package/dist/tools/Glob/Glob.js +113 -0
- package/dist/tools/Glob/Glob.js.map +1 -0
- package/dist/tools/Glob/prompt.d.ts +3 -0
- package/dist/tools/Glob/prompt.d.ts.map +1 -0
- package/dist/tools/Glob/prompt.js +11 -0
- package/dist/tools/Glob/prompt.js.map +1 -0
- package/dist/tools/Grep/Grep.d.ts +106 -0
- package/dist/tools/Grep/Grep.d.ts.map +1 -0
- package/dist/tools/Grep/Grep.js +301 -0
- package/dist/tools/Grep/Grep.js.map +1 -0
- package/dist/tools/Grep/prompt.d.ts +3 -0
- package/dist/tools/Grep/prompt.d.ts.map +1 -0
- package/dist/tools/Grep/prompt.js +17 -0
- package/dist/tools/Grep/prompt.js.map +1 -0
- package/dist/tools/NotebookEdit/NotebookEdit.d.ts +98 -0
- package/dist/tools/NotebookEdit/NotebookEdit.d.ts.map +1 -0
- package/dist/tools/NotebookEdit/NotebookEdit.js +228 -0
- package/dist/tools/NotebookEdit/NotebookEdit.js.map +1 -0
- package/dist/tools/NotebookEdit/prompt.d.ts +3 -0
- package/dist/tools/NotebookEdit/prompt.d.ts.map +1 -0
- package/dist/tools/NotebookEdit/prompt.js +6 -0
- package/dist/tools/NotebookEdit/prompt.js.map +1 -0
- package/dist/tools/Read/Read.d.ts +107 -0
- package/dist/tools/Read/Read.d.ts.map +1 -0
- package/dist/tools/Read/Read.js +175 -0
- package/dist/tools/Read/Read.js.map +1 -0
- package/dist/tools/Read/prompt.d.ts +4 -0
- package/dist/tools/Read/prompt.d.ts.map +1 -0
- package/dist/tools/Read/prompt.js +21 -0
- package/dist/tools/Read/prompt.js.map +1 -0
- package/dist/tools/Skill/Skill.d.ts +62 -0
- package/dist/tools/Skill/Skill.d.ts.map +1 -0
- package/dist/tools/Skill/Skill.js +142 -0
- package/dist/tools/Skill/Skill.js.map +1 -0
- package/dist/tools/Skill/prompt.d.ts +3 -0
- package/dist/tools/Skill/prompt.d.ts.map +1 -0
- package/dist/tools/Skill/prompt.js +58 -0
- package/dist/tools/Skill/prompt.js.map +1 -0
- package/dist/tools/Task/Task.d.ts +59 -0
- package/dist/tools/Task/Task.d.ts.map +1 -0
- package/dist/tools/Task/Task.js +213 -0
- package/dist/tools/Task/Task.js.map +1 -0
- package/dist/tools/Task/prompt.d.ts +6 -0
- package/dist/tools/Task/prompt.d.ts.map +1 -0
- package/dist/tools/Task/prompt.js +75 -0
- package/dist/tools/Task/prompt.js.map +1 -0
- package/dist/tools/TodoWrite/TodoWrite.d.ts +92 -0
- package/dist/tools/TodoWrite/TodoWrite.d.ts.map +1 -0
- package/dist/tools/TodoWrite/TodoWrite.js +101 -0
- package/dist/tools/TodoWrite/TodoWrite.js.map +1 -0
- package/dist/tools/TodoWrite/prompt.d.ts +3 -0
- package/dist/tools/TodoWrite/prompt.d.ts.map +1 -0
- package/dist/tools/TodoWrite/prompt.js +187 -0
- package/dist/tools/TodoWrite/prompt.js.map +1 -0
- package/dist/tools/Write/Write.d.ts +77 -0
- package/dist/tools/Write/Write.d.ts.map +1 -0
- package/dist/tools/Write/Write.js +189 -0
- package/dist/tools/Write/Write.js.map +1 -0
- package/dist/tools/Write/prompt.d.ts +3 -0
- package/dist/tools/Write/prompt.d.ts.map +1 -0
- package/dist/tools/Write/prompt.js +13 -0
- package/dist/tools/Write/prompt.js.map +1 -0
- package/dist/tools/base/Tool.d.ts +36 -0
- package/dist/tools/base/Tool.d.ts.map +1 -0
- package/dist/tools/base/Tool.js +3 -0
- package/dist/tools/base/Tool.js.map +1 -0
- package/dist/tools/base/tools.d.ts +9 -0
- package/dist/tools/base/tools.d.ts.map +1 -0
- package/dist/tools/base/tools.js +105 -0
- package/dist/tools/base/tools.js.map +1 -0
- package/dist/types/agent.d.ts +30 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/agent.js +3 -0
- package/dist/types/agent.js.map +1 -0
- package/dist/types/command.d.ts +44 -0
- package/dist/types/command.d.ts.map +1 -0
- package/dist/types/command.js +6 -0
- package/dist/types/command.js.map +1 -0
- package/dist/types/config.d.ts +14 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +3 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/errors.d.ts +18 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +33 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/index.d.ts +91 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +18 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/mcp.d.ts +127 -0
- package/dist/types/mcp.d.ts.map +1 -0
- package/dist/types/mcp.js +6 -0
- package/dist/types/mcp.js.map +1 -0
- package/dist/types/message.d.ts +31 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/message.js +3 -0
- package/dist/types/message.js.map +1 -0
- package/dist/types/model.d.ts +21 -0
- package/dist/types/model.d.ts.map +1 -0
- package/dist/types/model.js +3 -0
- package/dist/types/model.js.map +1 -0
- package/dist/types/notebook.d.ts +57 -0
- package/dist/types/notebook.d.ts.map +1 -0
- package/dist/types/notebook.js +3 -0
- package/dist/types/notebook.js.map +1 -0
- package/dist/types/skill.d.ts +34 -0
- package/dist/types/skill.d.ts.map +1 -0
- package/dist/types/skill.js +8 -0
- package/dist/types/skill.js.map +1 -0
- package/dist/types/uuid.d.ts +2 -0
- package/dist/types/uuid.d.ts.map +1 -0
- package/dist/types/uuid.js +3 -0
- package/dist/types/uuid.js.map +1 -0
- package/dist/util/adapter.d.ts +11 -0
- package/dist/util/adapter.d.ts.map +1 -0
- package/dist/util/adapter.js +75 -0
- package/dist/util/adapter.js.map +1 -0
- package/dist/util/agentStats.d.ts +11 -0
- package/dist/util/agentStats.d.ts.map +1 -0
- package/dist/util/agentStats.js +60 -0
- package/dist/util/agentStats.js.map +1 -0
- package/dist/util/cacheLLM.d.ts +47 -0
- package/dist/util/cacheLLM.d.ts.map +1 -0
- package/dist/util/cacheLLM.js +154 -0
- package/dist/util/cacheLLM.js.map +1 -0
- package/dist/util/commands.d.ts +16 -0
- package/dist/util/commands.d.ts.map +1 -0
- package/dist/util/commands.js +216 -0
- package/dist/util/commands.js.map +1 -0
- package/dist/util/compact.d.ts +25 -0
- package/dist/util/compact.d.ts.map +1 -0
- package/dist/util/compact.js +451 -0
- package/dist/util/compact.js.map +1 -0
- package/dist/util/cwd.d.ts +44 -0
- package/dist/util/cwd.d.ts.map +1 -0
- package/dist/util/cwd.js +84 -0
- package/dist/util/cwd.js.map +1 -0
- package/dist/util/diff.d.ts +10 -0
- package/dist/util/diff.d.ts.map +1 -0
- package/dist/util/diff.js +127 -0
- package/dist/util/diff.js.map +1 -0
- package/dist/util/directory.d.ts +37 -0
- package/dist/util/directory.d.ts.map +1 -0
- package/dist/util/directory.js +137 -0
- package/dist/util/directory.js.map +1 -0
- package/dist/util/env.d.ts +5 -0
- package/dist/util/env.d.ts.map +1 -0
- package/dist/util/env.js +39 -0
- package/dist/util/env.js.map +1 -0
- package/dist/util/exec.d.ts +6 -0
- package/dist/util/exec.d.ts.map +1 -0
- package/dist/util/exec.js +43 -0
- package/dist/util/exec.js.map +1 -0
- package/dist/util/file.d.ts +61 -0
- package/dist/util/file.d.ts.map +1 -0
- package/dist/util/file.js +365 -0
- package/dist/util/file.js.map +1 -0
- package/dist/util/filePermission.d.ts +14 -0
- package/dist/util/filePermission.d.ts.map +1 -0
- package/dist/util/filePermission.js +45 -0
- package/dist/util/filePermission.js.map +1 -0
- package/dist/util/fileReference.d.ts +40 -0
- package/dist/util/fileReference.d.ts.map +1 -0
- package/dist/util/fileReference.js +343 -0
- package/dist/util/fileReference.js.map +1 -0
- package/dist/util/format.d.ts +9 -0
- package/dist/util/format.d.ts.map +1 -0
- package/dist/util/format.js +61 -0
- package/dist/util/format.js.map +1 -0
- package/dist/util/frontmatter.d.ts +35 -0
- package/dist/util/frontmatter.d.ts.map +1 -0
- package/dist/util/frontmatter.js +119 -0
- package/dist/util/frontmatter.js.map +1 -0
- package/dist/util/git.d.ts +4 -0
- package/dist/util/git.d.ts.map +1 -0
- package/dist/util/git.js +55 -0
- package/dist/util/git.js.map +1 -0
- package/dist/util/history.d.ts +27 -0
- package/dist/util/history.d.ts.map +1 -0
- package/dist/util/history.js +248 -0
- package/dist/util/history.js.map +1 -0
- package/dist/util/log.d.ts +23 -0
- package/dist/util/log.d.ts.map +1 -0
- package/dist/util/log.js +246 -0
- package/dist/util/log.js.map +1 -0
- package/dist/util/logLLM.d.ts +20 -0
- package/dist/util/logLLM.d.ts.map +1 -0
- package/dist/util/logLLM.js +414 -0
- package/dist/util/logLLM.js.map +1 -0
- package/dist/util/message.d.ts +12 -0
- package/dist/util/message.d.ts.map +1 -0
- package/dist/util/message.js +156 -0
- package/dist/util/message.js.map +1 -0
- package/dist/util/model.d.ts +22 -0
- package/dist/util/model.d.ts.map +1 -0
- package/dist/util/model.js +61 -0
- package/dist/util/model.js.map +1 -0
- package/dist/util/notebook.d.ts +14 -0
- package/dist/util/notebook.d.ts.map +1 -0
- package/dist/util/notebook.js +104 -0
- package/dist/util/notebook.js.map +1 -0
- package/dist/util/ripgrep.d.ts +3 -0
- package/dist/util/ripgrep.d.ts.map +1 -0
- package/dist/util/ripgrep.js +187 -0
- package/dist/util/ripgrep.js.map +1 -0
- package/dist/util/rules.d.ts +6 -0
- package/dist/util/rules.d.ts.map +1 -0
- package/dist/util/rules.js +111 -0
- package/dist/util/rules.js.map +1 -0
- package/dist/util/savePath.d.ts +73 -0
- package/dist/util/savePath.d.ts.map +1 -0
- package/dist/util/savePath.js +189 -0
- package/dist/util/savePath.js.map +1 -0
- package/dist/util/secureFile.d.ts +136 -0
- package/dist/util/secureFile.d.ts.map +1 -0
- package/dist/util/secureFile.js +496 -0
- package/dist/util/secureFile.js.map +1 -0
- package/dist/util/session.d.ts +37 -0
- package/dist/util/session.d.ts.map +1 -0
- package/dist/util/session.js +120 -0
- package/dist/util/session.js.map +1 -0
- package/dist/util/shell.d.ts +40 -0
- package/dist/util/shell.d.ts.map +1 -0
- package/dist/util/shell.js +876 -0
- package/dist/util/shell.js.map +1 -0
- package/dist/util/time.d.ts +24 -0
- package/dist/util/time.d.ts.map +1 -0
- package/dist/util/time.js +53 -0
- package/dist/util/time.js.map +1 -0
- package/dist/util/tokens.d.ts +9 -0
- package/dist/util/tokens.d.ts.map +1 -0
- package/dist/util/tokens.js +79 -0
- package/dist/util/tokens.js.map +1 -0
- package/dist/util/topic.d.ts +9 -0
- package/dist/util/topic.d.ts.map +1 -0
- package/dist/util/topic.js +52 -0
- package/dist/util/topic.js.map +1 -0
- package/package.json +83 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FileEditTool = void 0;
|
|
4
|
+
exports.getSnippet = getSnippet;
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
const file_1 = require("../../util/file");
|
|
9
|
+
const diff_1 = require("../../util/diff");
|
|
10
|
+
const cwd_1 = require("../../util/cwd");
|
|
11
|
+
const prompt_1 = require("./prompt");
|
|
12
|
+
const utils_1 = require("./utils");
|
|
13
|
+
const prompt_2 = require("../NotebookEdit/prompt");
|
|
14
|
+
const StateManager_1 = require("../../manager/StateManager");
|
|
15
|
+
const inputSchema = zod_1.z.strictObject({
|
|
16
|
+
file_path: zod_1.z.string().describe('The absolute path to the file to modify'),
|
|
17
|
+
old_string: zod_1.z.string().describe('The text to replace'),
|
|
18
|
+
new_string: zod_1.z.string().describe('The text to replace it with (must be different from old_string)'),
|
|
19
|
+
replace_all: zod_1.z.boolean().optional().default(false).describe('Replace all occurences of old_string (default false)')
|
|
20
|
+
});
|
|
21
|
+
// Number of lines of context to include before/after the change in our result message
|
|
22
|
+
const N_LINES_SNIPPET = 4;
|
|
23
|
+
// 辅助函数:生成显示标题
|
|
24
|
+
function getTitle(input) {
|
|
25
|
+
if (input?.file_path) {
|
|
26
|
+
const relativePath = (0, path_1.relative)((0, cwd_1.getCwd)(), input.file_path);
|
|
27
|
+
return `${relativePath}`;
|
|
28
|
+
}
|
|
29
|
+
return prompt_1.TOOL_NAME_FOR_PROMPT;
|
|
30
|
+
}
|
|
31
|
+
exports.FileEditTool = {
|
|
32
|
+
name: prompt_1.TOOL_NAME_FOR_PROMPT,
|
|
33
|
+
description() {
|
|
34
|
+
return prompt_1.DESCRIPTION;
|
|
35
|
+
},
|
|
36
|
+
inputSchema,
|
|
37
|
+
isReadOnly() {
|
|
38
|
+
return false;
|
|
39
|
+
},
|
|
40
|
+
genToolPermission(input) {
|
|
41
|
+
const title = getTitle(input);
|
|
42
|
+
// 读取原文件内容,生成diff预览(不应用编辑)
|
|
43
|
+
const fullFilePath = (0, file_1.normalizeFilePath)(input.file_path);
|
|
44
|
+
const enc = (0, file_1.detectFileEncoding)(fullFilePath);
|
|
45
|
+
const originalContent = (0, fs_1.readFileSync)(fullFilePath, enc);
|
|
46
|
+
const patch = (0, diff_1.getPatch)({
|
|
47
|
+
filePath: fullFilePath,
|
|
48
|
+
fileContents: originalContent,
|
|
49
|
+
oldStr: input.old_string,
|
|
50
|
+
newStr: input.new_string,
|
|
51
|
+
});
|
|
52
|
+
// 返回包含完整patch信息的JSON对象
|
|
53
|
+
const content = {
|
|
54
|
+
type: 'diff',
|
|
55
|
+
patch: patch,
|
|
56
|
+
diffText: ''
|
|
57
|
+
};
|
|
58
|
+
return { title, content };
|
|
59
|
+
},
|
|
60
|
+
genToolResultMessage({ filePath, structuredPatch }) {
|
|
61
|
+
const title = getTitle({ file_path: filePath });
|
|
62
|
+
const summary = (0, diff_1.getUpdateSummary)(filePath, structuredPatch);
|
|
63
|
+
const content = {
|
|
64
|
+
type: 'diff',
|
|
65
|
+
patch: structuredPatch,
|
|
66
|
+
diffText: ''
|
|
67
|
+
};
|
|
68
|
+
return { title, summary, content };
|
|
69
|
+
},
|
|
70
|
+
getDisplayTitle(input) {
|
|
71
|
+
return getTitle(input);
|
|
72
|
+
},
|
|
73
|
+
async validateInput({ file_path, old_string, new_string, replace_all }, agentContext) {
|
|
74
|
+
// 通过 agentContext 访问隔离状态
|
|
75
|
+
const stateManager = (0, StateManager_1.getStateManager)();
|
|
76
|
+
const agentState = stateManager.forAgent(agentContext.agentId);
|
|
77
|
+
const readFileTimestamps = agentState.getReadFileTimestamps();
|
|
78
|
+
if (old_string === new_string) {
|
|
79
|
+
return {
|
|
80
|
+
result: false,
|
|
81
|
+
message: 'No changes to make: old_string and new_string are exactly the same.',
|
|
82
|
+
meta: {
|
|
83
|
+
old_string,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const fullFilePath = (0, file_1.normalizeFilePath)(file_path);
|
|
88
|
+
if ((0, fs_1.existsSync)(fullFilePath) && old_string === '') {
|
|
89
|
+
return {
|
|
90
|
+
result: false,
|
|
91
|
+
message: 'Cannot create new file - file already exists.',
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
if (!(0, fs_1.existsSync)(fullFilePath) && old_string === '') {
|
|
95
|
+
return {
|
|
96
|
+
result: true,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (!(0, fs_1.existsSync)(fullFilePath)) {
|
|
100
|
+
// Try to find a similar file with a different extension
|
|
101
|
+
const similarFilename = (0, file_1.findSimilarFile)(fullFilePath);
|
|
102
|
+
let message = 'File does not exist.';
|
|
103
|
+
// If we found a similar file, suggest it to the assistant
|
|
104
|
+
if (similarFilename) {
|
|
105
|
+
message += ` Did you mean ${similarFilename}?`;
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
result: false,
|
|
109
|
+
message,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if (fullFilePath.endsWith('.ipynb')) {
|
|
113
|
+
return {
|
|
114
|
+
result: false,
|
|
115
|
+
message: `File is a Jupyter Notebook. Use the ${prompt_2.TOOL_NAME_FOR_PROMPT} to edit this file.`,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const readTimestamp = readFileTimestamps[fullFilePath];
|
|
119
|
+
if (!readTimestamp) {
|
|
120
|
+
return {
|
|
121
|
+
result: false,
|
|
122
|
+
message: 'File has not been read yet. Read it first before writing to it.',
|
|
123
|
+
meta: {
|
|
124
|
+
isFilePathAbsolute: String((0, path_1.isAbsolute)(file_path)),
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
// Check if file exists and get its last modified time
|
|
129
|
+
const stats = (0, fs_1.statSync)(fullFilePath);
|
|
130
|
+
const lastWriteTime = stats.mtimeMs;
|
|
131
|
+
if (lastWriteTime > readTimestamp) {
|
|
132
|
+
return {
|
|
133
|
+
result: false,
|
|
134
|
+
message: 'File has been unexpectedly modified. Read it again before attempting to write it.',
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
const enc = (0, file_1.detectFileEncoding)(fullFilePath);
|
|
138
|
+
const file = (0, fs_1.readFileSync)(fullFilePath, enc);
|
|
139
|
+
if (!file.includes(old_string)) {
|
|
140
|
+
return {
|
|
141
|
+
result: false,
|
|
142
|
+
message: `String to replace not found in file.`,
|
|
143
|
+
meta: {
|
|
144
|
+
isFilePathAbsolute: String((0, path_1.isAbsolute)(file_path)),
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
const matches = file.split(old_string).length - 1;
|
|
149
|
+
if (matches > 1 && !replace_all) {
|
|
150
|
+
return {
|
|
151
|
+
result: false,
|
|
152
|
+
message: `Found ${matches} matches of the string to replace. For safety, this tool only supports replacing exactly one occurrence at a time. Add more lines of context to your edit, or set replace_all to true to replace all occurrences.`,
|
|
153
|
+
meta: {
|
|
154
|
+
isFilePathAbsolute: String((0, path_1.isAbsolute)(file_path)),
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
return { result: true };
|
|
159
|
+
},
|
|
160
|
+
async *call({ file_path, old_string, new_string, replace_all }, agentContext) {
|
|
161
|
+
const { patch, updatedFile } = (0, utils_1.applyEdit)(file_path, old_string, new_string, replace_all);
|
|
162
|
+
const stateManager = (0, StateManager_1.getStateManager)();
|
|
163
|
+
const agentState = stateManager.forAgent(agentContext.agentId);
|
|
164
|
+
const fullFilePath = (0, file_1.normalizeFilePath)(file_path);
|
|
165
|
+
const dir = (0, path_1.dirname)(fullFilePath);
|
|
166
|
+
(0, fs_1.mkdirSync)(dir, { recursive: true });
|
|
167
|
+
const enc = (0, fs_1.existsSync)(fullFilePath)
|
|
168
|
+
? (0, file_1.detectFileEncoding)(fullFilePath)
|
|
169
|
+
: 'utf8';
|
|
170
|
+
const endings = (0, fs_1.existsSync)(fullFilePath)
|
|
171
|
+
? (0, file_1.detectLineEndings)(fullFilePath)
|
|
172
|
+
: 'LF';
|
|
173
|
+
const originalFile = (0, fs_1.existsSync)(fullFilePath)
|
|
174
|
+
? (0, fs_1.readFileSync)(fullFilePath, enc)
|
|
175
|
+
: '';
|
|
176
|
+
(0, file_1.writeTextContent)(fullFilePath, updatedFile, enc, endings);
|
|
177
|
+
// Update read timestamp, to invalidate stale writes
|
|
178
|
+
agentState.setReadFileTimestamp(fullFilePath, (0, fs_1.statSync)(fullFilePath).mtimeMs);
|
|
179
|
+
const data = {
|
|
180
|
+
filePath: file_path,
|
|
181
|
+
oldString: old_string,
|
|
182
|
+
newString: new_string,
|
|
183
|
+
originalFile,
|
|
184
|
+
structuredPatch: patch,
|
|
185
|
+
};
|
|
186
|
+
yield {
|
|
187
|
+
type: 'result',
|
|
188
|
+
data,
|
|
189
|
+
resultForAssistant: this.genResultForAssistant(data),
|
|
190
|
+
};
|
|
191
|
+
},
|
|
192
|
+
genResultForAssistant({ filePath, originalFile, oldString, newString }) {
|
|
193
|
+
const { snippet, startLine } = getSnippet(originalFile || '', oldString, newString);
|
|
194
|
+
return `The file ${filePath} has been updated. Here's the result of running \`cat -n\` on a snippet of the edited file:
|
|
195
|
+
${(0, file_1.addLineNumbers)({
|
|
196
|
+
content: snippet,
|
|
197
|
+
startLine,
|
|
198
|
+
})}`;
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
function getSnippet(initialText, oldStr, newStr) {
|
|
202
|
+
const before = initialText.split(oldStr)[0] ?? '';
|
|
203
|
+
const replacementLine = before.split(/\r?\n/).length - 1;
|
|
204
|
+
const newFileLines = initialText.replace(oldStr, newStr).split(/\r?\n/);
|
|
205
|
+
// Calculate the start and end line numbers for the snippet
|
|
206
|
+
const startLine = Math.max(0, replacementLine - N_LINES_SNIPPET);
|
|
207
|
+
const endLine = replacementLine + N_LINES_SNIPPET + newStr.split(/\r?\n/).length;
|
|
208
|
+
// Get snippet
|
|
209
|
+
const snippetLines = newFileLines.slice(startLine, endLine + 1);
|
|
210
|
+
const snippet = snippetLines.join('\n');
|
|
211
|
+
return { snippet, startLine: startLine + 1 };
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=Edit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Edit.js","sourceRoot":"","sources":["../../../src/tools/Edit/Edit.ts"],"names":[],"mappings":";;;AA6PA,gCAgBC;AA5QD,2BAAkE;AAClE,+BAAkE;AAClE,6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-0,0 +1,3 @@
|
|
|
1
|
+
export declare const TOOL_NAME_FOR_PROMPT = "Edit";
|
|
2
|
+
export declare const DESCRIPTION = "Performs exact string replacements in files. \n\nUsage:\n- You must use your `Read` tool at least once in the conversation before editing. This tool will error if you attempt an edit without reading the file. \n- When editing text from Read tool output, ensure you preserve the exact indentation (tabs/spaces) as it appears AFTER the line number prefix. The line number prefix format is: spaces + line number + tab. Everything after that tab is the actual file content to match. Never include any part of the line number prefix in the old_string or new_string.\n- ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.\n- Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked.\n- The edit will FAIL if `old_string` is not unique in the file. Either provide a larger string with more surrounding context to make it unique or use `replace_all` to change every instance of `old_string`. \n- Use `replace_all` for replacing and renaming strings across the file. This parameter is useful if you want to rename a variable for instance.";
|
|
3
|
+
//# sourceMappingURL=prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../src/tools/Edit/prompt.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,SAAS,CAAA;AAE1C,eAAO,MAAM,WAAW,mmCAQ0H,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DESCRIPTION = exports.TOOL_NAME_FOR_PROMPT = void 0;
|
|
4
|
+
const prompt_1 = require("../Read/prompt");
|
|
5
|
+
exports.TOOL_NAME_FOR_PROMPT = 'Edit';
|
|
6
|
+
exports.DESCRIPTION = `Performs exact string replacements in files.
|
|
7
|
+
|
|
8
|
+
Usage:
|
|
9
|
+
- You must use your \`${prompt_1.TOOL_NAME_FOR_PROMPT}\` tool at least once in the conversation before editing. This tool will error if you attempt an edit without reading the file.
|
|
10
|
+
- When editing text from ${prompt_1.TOOL_NAME_FOR_PROMPT} tool output, ensure you preserve the exact indentation (tabs/spaces) as it appears AFTER the line number prefix. The line number prefix format is: spaces + line number + tab. Everything after that tab is the actual file content to match. Never include any part of the line number prefix in the old_string or new_string.
|
|
11
|
+
- ALWAYS prefer editing existing files in the codebase. NEVER write new files unless explicitly required.
|
|
12
|
+
- Only use emojis if the user explicitly requests it. Avoid adding emojis to files unless asked.
|
|
13
|
+
- The edit will FAIL if \`old_string\` is not unique in the file. Either provide a larger string with more surrounding context to make it unique or use \`replace_all\` to change every instance of \`old_string\`.
|
|
14
|
+
- Use \`replace_all\` for replacing and renaming strings across the file. This parameter is useful if you want to rename a variable for instance.`;
|
|
15
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../src/tools/Edit/prompt.ts"],"names":[],"mappings":";;;AAAA,2CAAuE;AAE1D,QAAA,oBAAoB,GAAG,MAAM,CAAA;AAE7B,QAAA,WAAW,GAAG;;;wBAGH,6BAAc;2BACX,6BAAc;;;;kJAIyG,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Hunk } from 'diff';
|
|
2
|
+
/**
|
|
3
|
+
* Applies an edit to a file and returns the patch and updated file.
|
|
4
|
+
* Does not write the file to disk.
|
|
5
|
+
*/
|
|
6
|
+
export declare function applyEdit(file_path: string, old_string: string, new_string: string, replace_all?: boolean): {
|
|
7
|
+
patch: Hunk[];
|
|
8
|
+
updatedFile: string;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/tools/Edit/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,MAAM,CAAA;AAGhC;;;GAGG;AACH,wBAAgB,SAAS,CACvB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,WAAW,GAAE,OAAe,GAC3B;IAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CA4CxC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyEdit = applyEdit;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const file_1 = require("../../util/file");
|
|
6
|
+
const diff_1 = require("../../util/diff");
|
|
7
|
+
/**
|
|
8
|
+
* Applies an edit to a file and returns the patch and updated file.
|
|
9
|
+
* Does not write the file to disk.
|
|
10
|
+
*/
|
|
11
|
+
function applyEdit(file_path, old_string, new_string, replace_all = false) {
|
|
12
|
+
const fullFilePath = (0, file_1.normalizeFilePath)(file_path);
|
|
13
|
+
let originalFile;
|
|
14
|
+
let updatedFile;
|
|
15
|
+
if (old_string === '') {
|
|
16
|
+
// Create new file
|
|
17
|
+
originalFile = '';
|
|
18
|
+
updatedFile = new_string;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
// Edit existing file
|
|
22
|
+
const enc = (0, file_1.detectFileEncoding)(fullFilePath);
|
|
23
|
+
originalFile = (0, fs_1.readFileSync)(fullFilePath, enc);
|
|
24
|
+
const replaceFunc = replace_all
|
|
25
|
+
? (str, search, replacement) => str.replaceAll(search, replacement)
|
|
26
|
+
: (str, search, replacement) => str.replace(search, replacement);
|
|
27
|
+
if (new_string === '') {
|
|
28
|
+
if (!old_string.endsWith('\n') &&
|
|
29
|
+
originalFile.includes(old_string + '\n')) {
|
|
30
|
+
updatedFile = replaceFunc(originalFile, old_string + '\n', new_string);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
updatedFile = replaceFunc(originalFile, old_string, new_string);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
updatedFile = replaceFunc(originalFile, old_string, new_string);
|
|
38
|
+
}
|
|
39
|
+
if (updatedFile === originalFile) {
|
|
40
|
+
throw new Error('Original and edited file match exactly. Failed to apply edit.');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const patch = (0, diff_1.getPatch)({
|
|
44
|
+
filePath: file_path,
|
|
45
|
+
fileContents: originalFile,
|
|
46
|
+
oldStr: originalFile,
|
|
47
|
+
newStr: updatedFile,
|
|
48
|
+
});
|
|
49
|
+
return { patch, updatedFile };
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/tools/Edit/utils.ts"],"names":[],"mappings":";;AASA,8BAiDC;AA1DD,2BAAiC;AACjC,0CAAuE;AAEvE,0CAA0C;AAE1C;;;GAGG;AACH,SAAgB,SAAS,CACvB,SAAiB,EACjB,UAAkB,EAClB,UAAkB,EAClB,cAAuB,KAAK;IAE5B,MAAM,YAAY,GAAG,IAAA,wBAAiB,EAAC,SAAS,CAAC,CAAA;IAEjD,IAAI,YAAY,CAAA;IAChB,IAAI,WAAW,CAAA;IACf,IAAI,UAAU,KAAK,EAAE,EAAE,CAAC;QACtB,kBAAkB;QAClB,YAAY,GAAG,EAAE,CAAA;QACjB,WAAW,GAAG,UAAU,CAAA;IAC1B,CAAC;SAAM,CAAC;QACN,qBAAqB;QACrB,MAAM,GAAG,GAAG,IAAA,yBAAkB,EAAC,YAAY,CAAC,CAAA;QAC5C,YAAY,GAAG,IAAA,iBAAY,EAAC,YAAY,EAAE,GAAG,CAAC,CAAA;QAC9C,MAAM,WAAW,GAAG,WAAW;YAC7B,CAAC,CAAC,CAAC,GAAW,EAAE,MAAc,EAAE,WAAmB,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,MAAM,EAAE,WAAW,CAAC;YAC3F,CAAC,CAAC,CAAC,GAAW,EAAE,MAAc,EAAE,WAAmB,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;QAE1F,IAAI,UAAU,KAAK,EAAE,EAAE,CAAC;YACtB,IACE,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAC1B,YAAY,CAAC,QAAQ,CAAC,UAAU,GAAG,IAAI,CAAC,EACxC,CAAC;gBACD,WAAW,GAAG,WAAW,CAAC,YAAY,EAAE,UAAU,GAAG,IAAI,EAAE,UAAU,CAAC,CAAA;YACxE,CAAC;iBAAM,CAAC;gBACN,WAAW,GAAG,WAAW,CAAC,YAAY,EAAE,UAAU,EAAE,UAAU,CAAC,CAAA;YACjE,CAAC;QACH,CAAC;aAAM,CAAC;YACN,WAAW,GAAG,WAAW,CAAC,YAAY,EAAE,UAAU,EAAE,UAAU,CAAC,CAAA;QACjE,CAAC;QACD,IAAI,WAAW,KAAK,YAAY,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAA;QACH,CAAC;IACH,CAAC;IAED,MAAM,KAAK,GAAG,IAAA,eAAQ,EAAC;QACrB,QAAQ,EAAE,SAAS;QACnB,YAAY,EAAE,YAAY;QAC1B,MAAM,EAAE,YAAY;QACpB,MAAM,EAAE,WAAW;KACpB,CAAC,CAAA;IAEF,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,CAAA;AAC/B,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ToolControlSignal } from '../../types/message';
|
|
3
|
+
declare const inputSchema: z.ZodObject<{
|
|
4
|
+
planFilePath: z.ZodString;
|
|
5
|
+
}, "strict", z.ZodTypeAny, {
|
|
6
|
+
planFilePath: string;
|
|
7
|
+
}, {
|
|
8
|
+
planFilePath: string;
|
|
9
|
+
}>;
|
|
10
|
+
interface ExitPlanModeOutput {
|
|
11
|
+
planFilePath: string;
|
|
12
|
+
planContent: string;
|
|
13
|
+
selected: 'startEditing' | 'clearContextAndStart';
|
|
14
|
+
controlSignal: ToolControlSignal;
|
|
15
|
+
}
|
|
16
|
+
export declare const ExitPlanModeTool: {
|
|
17
|
+
name: string;
|
|
18
|
+
description(): string;
|
|
19
|
+
inputSchema: z.ZodObject<{
|
|
20
|
+
planFilePath: z.ZodString;
|
|
21
|
+
}, "strict", z.ZodTypeAny, {
|
|
22
|
+
planFilePath: string;
|
|
23
|
+
}, {
|
|
24
|
+
planFilePath: string;
|
|
25
|
+
}>;
|
|
26
|
+
isReadOnly(): true;
|
|
27
|
+
validateInput({ planFilePath }: z.infer<typeof inputSchema>, agentContext: any): Promise<{
|
|
28
|
+
result: false;
|
|
29
|
+
message: string;
|
|
30
|
+
} | {
|
|
31
|
+
result: true;
|
|
32
|
+
message?: undefined;
|
|
33
|
+
}>;
|
|
34
|
+
call({ planFilePath }: z.infer<typeof inputSchema>, agentContext: any): AsyncGenerator<{
|
|
35
|
+
type: "result";
|
|
36
|
+
data: ExitPlanModeOutput;
|
|
37
|
+
resultForAssistant: string;
|
|
38
|
+
}, void, unknown>;
|
|
39
|
+
genResultForAssistant(output: ExitPlanModeOutput): string;
|
|
40
|
+
};
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=ExitPlanMode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExitPlanMode.d.ts","sourceRoot":"","sources":["../../../src/tools/ExitPlanMode/ExitPlanMode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAOvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAQvD,QAAA,MAAM,WAAW;;;;;;EAIf,CAAA;AAGF,UAAU,kBAAkB;IAC1B,YAAY,EAAE,MAAM,CAAA;IACpB,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,cAAc,GAAG,sBAAsB,CAAA;IACjD,aAAa,EAAE,iBAAiB,CAAA;CACjC;AAED,eAAO,MAAM,gBAAgB;;;;;;;;;;;oCAUP,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,gBAC/B,GAAG;;;;;;;2BAwBC,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,gBAC/B,GAAG;;;;;kCAwGW,kBAAkB;CAwBM,CAAA"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExitPlanModeTool = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const prompt_1 = require("./prompt");
|
|
7
|
+
const file_1 = require("../../util/file");
|
|
8
|
+
const cwd_1 = require("../../util/cwd");
|
|
9
|
+
const secureFile_1 = require("../../util/secureFile");
|
|
10
|
+
const ConfManager_1 = require("../../manager/ConfManager");
|
|
11
|
+
const EventSystem_1 = require("../../events/EventSystem");
|
|
12
|
+
const errors_1 = require("../../types/errors");
|
|
13
|
+
const StateManager_1 = require("../../manager/StateManager");
|
|
14
|
+
const message_1 = require("../../util/message");
|
|
15
|
+
// 输入 schema
|
|
16
|
+
const inputSchema = zod_1.z.strictObject({
|
|
17
|
+
planFilePath: zod_1.z
|
|
18
|
+
.string()
|
|
19
|
+
.describe('The absolute path to the plan file (.md)'),
|
|
20
|
+
});
|
|
21
|
+
exports.ExitPlanModeTool = {
|
|
22
|
+
name: prompt_1.TOOL_NAME_FOR_PROMPT,
|
|
23
|
+
description() {
|
|
24
|
+
return prompt_1.DESCRIPTION;
|
|
25
|
+
},
|
|
26
|
+
inputSchema,
|
|
27
|
+
isReadOnly() {
|
|
28
|
+
return true;
|
|
29
|
+
},
|
|
30
|
+
async validateInput({ planFilePath }, agentContext) {
|
|
31
|
+
const fullFilePath = (0, file_1.normalizeFilePath)(planFilePath);
|
|
32
|
+
// 验证文件是否存在
|
|
33
|
+
const fileCheck = secureFile_1.secureFileService.safeGetFileInfo(fullFilePath);
|
|
34
|
+
if (!fileCheck.success) {
|
|
35
|
+
return {
|
|
36
|
+
result: false,
|
|
37
|
+
message: fileCheck.error || `Plan file not found: ${planFilePath}`,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// 验证文件扩展名
|
|
41
|
+
if (!planFilePath.endsWith('.md')) {
|
|
42
|
+
return {
|
|
43
|
+
result: false,
|
|
44
|
+
message: 'Plan file must be a markdown file (.md)',
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return { result: true };
|
|
48
|
+
},
|
|
49
|
+
async *call({ planFilePath }, agentContext) {
|
|
50
|
+
const fullFilePath = (0, file_1.normalizeFilePath)(planFilePath);
|
|
51
|
+
const eventBus = (0, EventSystem_1.getEventBus)();
|
|
52
|
+
const abortController = agentContext.abortController;
|
|
53
|
+
// 读取计划文件内容
|
|
54
|
+
const { content } = (0, file_1.readTextContent)(fullFilePath, 0);
|
|
55
|
+
// 获取相对路径用于事件
|
|
56
|
+
const relativePath = (0, path_1.relative)((0, cwd_1.getCwd)(), fullFilePath);
|
|
57
|
+
// 发送权限请求事件
|
|
58
|
+
const requestData = {
|
|
59
|
+
agentId: agentContext.agentId,
|
|
60
|
+
planFilePath: relativePath,
|
|
61
|
+
planContent: content,
|
|
62
|
+
options: {
|
|
63
|
+
startEditing: '开始代码编辑',
|
|
64
|
+
clearContextAndStart: '清理上下文,并开始代码编辑',
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
eventBus.emit('plan:exit:request', requestData);
|
|
68
|
+
// 等待用户响应
|
|
69
|
+
const selected = await new Promise((resolve, reject) => {
|
|
70
|
+
const handleResponse = (response) => {
|
|
71
|
+
if (response.agentId !== agentContext.agentId)
|
|
72
|
+
return;
|
|
73
|
+
eventBus.off('plan:exit:response', handleResponse);
|
|
74
|
+
resolve(response.selected);
|
|
75
|
+
};
|
|
76
|
+
// 监听中断
|
|
77
|
+
const handleAbort = () => {
|
|
78
|
+
eventBus.off('plan:exit:response', handleResponse);
|
|
79
|
+
reject(new Error('User cancelled the plan exit'));
|
|
80
|
+
};
|
|
81
|
+
if (abortController?.signal) {
|
|
82
|
+
abortController.signal.addEventListener('abort', handleAbort, {
|
|
83
|
+
once: true,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
eventBus.on('plan:exit:response', handleResponse);
|
|
87
|
+
});
|
|
88
|
+
// 检查是否被中断
|
|
89
|
+
(0, errors_1.checkAbortSignal)(abortController);
|
|
90
|
+
// 退出Plan模式,切换回Agent模式
|
|
91
|
+
(0, ConfManager_1.getConfManager)().updateAgentMode('Agent');
|
|
92
|
+
// 如果选择清理上下文
|
|
93
|
+
if (selected === 'clearContextAndStart') {
|
|
94
|
+
const stateManager = (0, StateManager_1.getStateManager)();
|
|
95
|
+
// 清空状态
|
|
96
|
+
stateManager.clearAllState();
|
|
97
|
+
// 设置新的用户消息
|
|
98
|
+
const newUserMessage = (0, message_1.createUserMessage)([
|
|
99
|
+
{
|
|
100
|
+
type: 'text',
|
|
101
|
+
text: `Implement the following plan:\n\n${content}`,
|
|
102
|
+
},
|
|
103
|
+
]);
|
|
104
|
+
stateManager.setMessageHistory([newUserMessage], StateManager_1.MAIN_AGENT_ID);
|
|
105
|
+
// 触发 plan:implement 事件
|
|
106
|
+
eventBus.emit('plan:implement', {
|
|
107
|
+
planFilePath: relativePath,
|
|
108
|
+
planContent: content,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const data = {
|
|
112
|
+
planFilePath,
|
|
113
|
+
planContent: content,
|
|
114
|
+
selected,
|
|
115
|
+
// 添加控制信号,通知 query 函数需要重建上下文
|
|
116
|
+
controlSignal: {
|
|
117
|
+
rebuildContext: {
|
|
118
|
+
reason: 'mode_changed',
|
|
119
|
+
newMode: 'Agent',
|
|
120
|
+
// 如果选择清理上下文,传递重建消息
|
|
121
|
+
rebuildMessage: selected === 'clearContextAndStart' ? [{
|
|
122
|
+
type: 'text',
|
|
123
|
+
text: `Implement the following plan:\n\n${content}`,
|
|
124
|
+
}] : undefined,
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
yield {
|
|
129
|
+
type: 'result',
|
|
130
|
+
data,
|
|
131
|
+
resultForAssistant: this.genResultForAssistant(data),
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
genResultForAssistant(output) {
|
|
135
|
+
const { planFilePath, planContent, selected } = output;
|
|
136
|
+
if (selected === 'clearContextAndStart') {
|
|
137
|
+
return `User has approved your plan and requested to clear context. The conversation history has been cleared.
|
|
138
|
+
|
|
139
|
+
You can now start implementing the plan. The plan file is located at ${planFilePath} if you need to reference it.
|
|
140
|
+
|
|
141
|
+
## Plan to Implement:
|
|
142
|
+
${planContent}`;
|
|
143
|
+
}
|
|
144
|
+
return `User has approved your plan. You can now start coding. Start with updating your todo list if applicable
|
|
145
|
+
|
|
146
|
+
Your plan has been saved to: ${planFilePath}
|
|
147
|
+
You can refer back to it if needed during implementation.
|
|
148
|
+
|
|
149
|
+
## Approved Plan:
|
|
150
|
+
${planContent}
|
|
151
|
+
|
|
152
|
+
## Exited Plan Mode
|
|
153
|
+
|
|
154
|
+
You have exited plan mode. You can now make edits, run tools, and take actions. The plan file is located at ${planFilePath} if you need to reference it.`;
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=ExitPlanMode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExitPlanMode.js","sourceRoot":"","sources":["../../../src/tools/ExitPlanMode/ExitPlanMode.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,6BAAuB;AAEvB,qCAA4D;AAC5D,0CAAoE;AACpE,wCAAuC;AACvC,sDAAyD;AACzD,2DAA0D;AAE1D,0DAAsD;AAEtD,+CAAqD;AACrD,6DAA2E;AAC3E,gDAAsD;AAEtD,YAAY;AACZ,MAAM,WAAW,GAAG,OAAC,CAAC,YAAY,CAAC;IACjC,YAAY,EAAE,OAAC;SACZ,MAAM,EAAE;SACR,QAAQ,CAAC,0CAA0C,CAAC;CACxD,CAAC,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,YAAY,+BAA+B,CAAA;IACvJ,CAAC;CACqD,CAAA"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const TOOL_NAME_FOR_PROMPT = "ExitPlanMode";
|
|
2
|
+
export declare const DESCRIPTION = "Use this tool when you are in plan mode and have finished writing your plan to the plan file and are ready for user approval.\n\n## How This Tool Works\n- You should have already written your plan to the plan file specified in the plan mode system message\n- This tool does NOT take the plan content as a parameter - it will read the plan from the file you wrote\n- This tool simply signals that you're done planning and ready for the user to review and approve\n- The user will see the contents of your plan file when they review it\n\n## When to Use This Tool\nIMPORTANT: Only use this tool when the task requires planning the implementation steps of a task that requires writing code. For research tasks where you're gathering information, searching files, reading files or in general trying to understand the codebase - do NOT use this tool.\n\n## Before Using This Tool\nEnsure your plan is complete and unambiguous:\n- If you have unresolved questions about requirements or approach, use AskUserQuestion first (in earlier phases)\n- Once your plan is finalized, use THIS tool to request approval\n\n**Important:** Do NOT use AskUserQuestion to ask \"Is this plan okay?\" or \"Should I proceed?\" - that's exactly what THIS tool does. ExitPlanMode inherently requests user approval of your plan.\n\n## Examples\n\n1. Initial task: \"Search for and understand the implementation of vim mode in the codebase\" - Do not use the exit plan mode tool because you are not planning the implementation steps of a task.\n2. Initial task: \"Help me implement yank mode for vim\" - Use the exit plan mode tool after you have finished planning the implementation steps of the task.\n3. Initial task: \"Add a new feature to handle user authentication\" - If unsure about auth method (OAuth, JWT, etc.), use AskUserQuestion first, then use exit plan mode tool after clarifying the approach.";
|
|
3
|
+
//# sourceMappingURL=prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../src/tools/ExitPlanMode/prompt.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,iBAAiB,CAAA;AAElD,eAAO,MAAM,WAAW,61DAsBoL,CAAA"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DESCRIPTION = exports.TOOL_NAME_FOR_PROMPT = void 0;
|
|
4
|
+
exports.TOOL_NAME_FOR_PROMPT = 'ExitPlanMode';
|
|
5
|
+
exports.DESCRIPTION = `Use this tool when you are in plan mode and have finished writing your plan to the plan file and are ready for user approval.
|
|
6
|
+
|
|
7
|
+
## How This Tool Works
|
|
8
|
+
- You should have already written your plan to the plan file specified in the plan mode system message
|
|
9
|
+
- This tool does NOT take the plan content as a parameter - it will read the plan from the file you wrote
|
|
10
|
+
- This tool simply signals that you're done planning and ready for the user to review and approve
|
|
11
|
+
- The user will see the contents of your plan file when they review it
|
|
12
|
+
|
|
13
|
+
## When to Use This Tool
|
|
14
|
+
IMPORTANT: Only use this tool when the task requires planning the implementation steps of a task that requires writing code. For research tasks where you're gathering information, searching files, reading files or in general trying to understand the codebase - do NOT use this tool.
|
|
15
|
+
|
|
16
|
+
## Before Using This Tool
|
|
17
|
+
Ensure your plan is complete and unambiguous:
|
|
18
|
+
- If you have unresolved questions about requirements or approach, use AskUserQuestion first (in earlier phases)
|
|
19
|
+
- Once your plan is finalized, use THIS tool to request approval
|
|
20
|
+
|
|
21
|
+
**Important:** Do NOT use AskUserQuestion to ask "Is this plan okay?" or "Should I proceed?" - that's exactly what THIS tool does. ExitPlanMode inherently requests user approval of your plan.
|
|
22
|
+
|
|
23
|
+
## Examples
|
|
24
|
+
|
|
25
|
+
1. Initial task: "Search for and understand the implementation of vim mode in the codebase" - Do not use the exit plan mode tool because you are not planning the implementation steps of a task.
|
|
26
|
+
2. Initial task: "Help me implement yank mode for vim" - Use the exit plan mode tool after you have finished planning the implementation steps of the task.
|
|
27
|
+
3. Initial task: "Add a new feature to handle user authentication" - If unsure about auth method (OAuth, JWT, etc.), use AskUserQuestion first, then use exit plan mode tool after clarifying the approach.`;
|
|
28
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../src/tools/ExitPlanMode/prompt.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,cAAc,CAAA;AAErC,QAAA,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;4MAsBiL,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
type Output = {
|
|
3
|
+
durationMs: number;
|
|
4
|
+
numFiles: number;
|
|
5
|
+
filenames: string[];
|
|
6
|
+
truncated: boolean;
|
|
7
|
+
pattern?: string;
|
|
8
|
+
path?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const GlobTool: {
|
|
11
|
+
name: string;
|
|
12
|
+
description(): string;
|
|
13
|
+
inputSchema: z.ZodObject<{
|
|
14
|
+
pattern: z.ZodString;
|
|
15
|
+
path: z.ZodOptional<z.ZodString>;
|
|
16
|
+
}, "strict", z.ZodTypeAny, {
|
|
17
|
+
pattern: string;
|
|
18
|
+
path?: string | undefined;
|
|
19
|
+
}, {
|
|
20
|
+
pattern: string;
|
|
21
|
+
path?: string | undefined;
|
|
22
|
+
}>;
|
|
23
|
+
isReadOnly(): true;
|
|
24
|
+
genToolResultMessage({ pattern, path, numFiles, filenames }: Output): {
|
|
25
|
+
title: string;
|
|
26
|
+
summary: string;
|
|
27
|
+
content: string;
|
|
28
|
+
};
|
|
29
|
+
getDisplayTitle(input: {
|
|
30
|
+
pattern: string;
|
|
31
|
+
path?: string | undefined;
|
|
32
|
+
} | undefined): string;
|
|
33
|
+
call({ pattern, path }: {
|
|
34
|
+
pattern: string;
|
|
35
|
+
path?: string | undefined;
|
|
36
|
+
}, agentContext: any): AsyncGenerator<{
|
|
37
|
+
type: "result";
|
|
38
|
+
resultForAssistant: string;
|
|
39
|
+
data: Output;
|
|
40
|
+
}, void, unknown>;
|
|
41
|
+
genResultForAssistant(output: Output): string;
|
|
42
|
+
};
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=Glob.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Glob.d.ts","sourceRoot":"","sources":["../../../src/tools/Glob/Glob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AA4CvB,KAAK,MAAM,GAAG;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,EAAE,CAAA;IACnB,SAAS,EAAE,OAAO,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;qBA8C2B,GAAG;;;;;;CAmCP,CAAA"}
|