From 0ce336463526ba0905b1a743d26aa4e512311fd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=AC=E6=98=8E?= <83812544+Ed1s0nZ@users.noreply.github.com> Date: Tue, 18 Nov 2025 23:51:51 +0800 Subject: [PATCH] Add files via upload --- tools/execute-python-script.yaml | 39 ++++++++++++++++++++++-- tools/install-python-package.yaml | 50 +++++++++++++++++++++++-------- 2 files changed, 73 insertions(+), 16 deletions(-) diff --git a/tools/execute-python-script.yaml b/tools/execute-python-script.yaml index 86b4f4c2..a56d8635 100644 --- a/tools/execute-python-script.yaml +++ b/tools/execute-python-script.yaml @@ -1,8 +1,33 @@ name: "execute-python-script" -command: "python3" -args: ["-c"] +command: "/bin/bash" +args: + - "-c" + - | + set -euo pipefail + + SCRIPT_CONTENT="$1" + ENV_NAME="${2:-default}" + ADDITIONAL_ARGS="${3:-}" + + BASE_DIR="${HOME}/.cyberstrike/venvs" + ENV_DIR="${BASE_DIR}/${ENV_NAME}" + + mkdir -p "$BASE_DIR" + if [ ! -d "$ENV_DIR" ]; then + python3 -m venv "$ENV_DIR" + fi + + # shellcheck disable=SC1090 + source "$ENV_DIR/bin/activate" + + if [ -n "$ADDITIONAL_ARGS" ]; then + python3 $ADDITIONAL_ARGS -c "$SCRIPT_CONTENT" + else + python3 -c "$SCRIPT_CONTENT" + fi + - "_" enabled: true -short_description: "执行Python脚本工具" +short_description: "在指定虚拟环境中编写并执行Python脚本" description: | 在虚拟环境中执行Python脚本。 @@ -29,6 +54,13 @@ parameters: required: true position: 0 format: "positional" + - name: "env_name" + type: "string" + description: "虚拟环境名称(默认default)" + required: false + default: "default" + position: 1 + format: "positional" - name: "additional_args" type: "string" description: | @@ -43,3 +75,4 @@ parameters: - 此参数会直接追加到命令末尾 required: false format: "positional" + default: "" diff --git a/tools/install-python-package.yaml b/tools/install-python-package.yaml index 3aa9e80e..4b7c7987 100644 --- a/tools/install-python-package.yaml +++ b/tools/install-python-package.yaml @@ -1,22 +1,45 @@ name: "install-python-package" -command: "pip" +command: "/bin/bash" +args: + - "-c" + - | + set -euo pipefail + + PACKAGE="$1" + ENV_NAME="${2:-default}" + ADDITIONAL_ARGS="${3:-}" + + BASE_DIR="${HOME}/.cyberstrike/venvs" + ENV_DIR="${BASE_DIR}/${ENV_NAME}" + + mkdir -p "$BASE_DIR" + if [ ! -d "$ENV_DIR" ]; then + python3 -m venv "$ENV_DIR" + fi + + # shellcheck disable=SC1090 + source "$ENV_DIR/bin/activate" + + if [ -n "$ADDITIONAL_ARGS" ]; then + pip install "$PACKAGE" $ADDITIONAL_ARGS + else + pip install "$PACKAGE" + fi + - "_" enabled: true - -short_description: "安装Python包工具" - +short_description: "在指定虚拟环境中创建/激活并安装Python依赖" description: | 在虚拟环境中安装Python包。 - + **主要功能:** - 安装Python包 - 虚拟环境支持 - 依赖管理 - + **使用场景:** - 环境配置 - 依赖安装 - 工具安装 - parameters: - name: "package" type: "string" @@ -24,24 +47,25 @@ parameters: required: true position: 0 format: "positional" - - name: "env_name" type: "string" - description: "虚拟环境名称" + description: "虚拟环境名称(默认default)" required: false default: "default" - + position: 1 + format: "positional" - name: "additional_args" type: "string" description: | 额外的install-python-package参数。用于传递未在参数列表中定义的install-python-package选项。 - + **示例值:** - 根据工具特性添加常用参数示例 - + **注意事项:** - 多个参数用空格分隔 - 确保参数格式正确,避免命令注入 - 此参数会直接追加到命令末尾 required: false - format: "positional" \ No newline at end of file + format: "positional" + default: ""