diff --git a/tools/execute-python-script.yaml b/tools/execute-python-script.yaml index c5e4c10a..86b4f4c2 100644 --- a/tools/execute-python-script.yaml +++ b/tools/execute-python-script.yaml @@ -1,50 +1,45 @@ name: "execute-python-script" command: "python3" +args: ["-c"] enabled: true - short_description: "执行Python脚本工具" - description: | 在虚拟环境中执行Python脚本。 - + **主要功能:** - 执行Python脚本 - 虚拟环境支持 - 脚本内容执行 - + **使用场景:** - 脚本执行 - 自动化任务 - 数据处理 - parameters: - name: "script" type: "string" - description: "要执行的Python脚本内容" - required: true - - - name: "env_name" - type: "string" - description: "虚拟环境名称" - required: false - default: "default" - - - name: "filename" - type: "string" - description: "自定义脚本文件名(为空则自动生成)" - required: false + description: | + 要执行的Python脚本内容,支持多行。 + **示例:** + ``` + for i in range(1, 10): + print(i) + ``` + required: true + position: 0 + format: "positional" - name: "additional_args" type: "string" description: | 额外的execute-python-script参数。用于传递未在参数列表中定义的execute-python-script选项。 - + **示例值:** - 根据工具特性添加常用参数示例 - + **注意事项:** - 多个参数用空格分隔 - 确保参数格式正确,避免命令注入 - 此参数会直接追加到命令末尾 required: false - format: "positional" \ No newline at end of file + format: "positional" diff --git a/tools/modify-file.yaml b/tools/modify-file.yaml index 550b3703..e11e4d0f 100644 --- a/tools/modify-file.yaml +++ b/tools/modify-file.yaml @@ -1,50 +1,76 @@ name: "modify-file" -command: "sh" +command: "python3" +args: + - "-c" + - | + import sys + from pathlib import Path + + if len(sys.argv) < 3: + sys.stderr.write("Usage: modify-file [append]\n") + sys.exit(1) + + filename = sys.argv[1] + content = sys.argv[2] + append_arg = sys.argv[3].lower() if len(sys.argv) > 3 else "false" + append = append_arg in ("1", "true", "yes", "on") + + path = Path(filename) + if not path.is_absolute(): + path = Path.cwd() / path + path.parent.mkdir(parents=True, exist_ok=True) + + mode = "a" if append else "w" + with path.open(mode, encoding="utf-8") as f: + f.write(content) + + action = "追加" if append else "覆盖" + print(f"{action}写入完成: {path}") enabled: true - short_description: "修改文件工具" - description: | 修改服务器上的现有文件。 - + **主要功能:** - 修改文件 - 追加内容 - 覆盖内容 - + **使用场景:** - 文件编辑 - 内容追加 - 配置修改 - parameters: - name: "filename" type: "string" description: "要修改的文件名" required: true - + position: 0 + format: "positional" - name: "content" type: "string" description: "要写入或追加的内容" required: true - + position: 1 + format: "positional" - name: "append" type: "bool" description: "是否追加(true)或覆盖(false)" required: false default: false - + position: 2 + format: "positional" - name: "additional_args" type: "string" description: | 额外的modify-file参数。用于传递未在参数列表中定义的modify-file选项。 - + **示例值:** - 根据工具特性添加常用参数示例 - + **注意事项:** - 多个参数用空格分隔 - 确保参数格式正确,避免命令注入 - 此参数会直接追加到命令末尾 required: false - format: "positional" \ No newline at end of file + format: "positional"