Lines 1-35javascript
1// ============================================================
3// - exec → spawn(非阻塞父进程)
5// - stdout/stderr 正确路由(避免 NotADirectoryError)
6// ============================================================
7import { spawn, execFileSync } from "child_process";
8import { stat } from "fs/promises";
HighChild Process
Package source references child process execution.
dist/tools/bash.jsView on unpkg · L6 9import { toolError, toolSuccess } from "./error-utils.js";
10import { getRuntimeRootsFromEnv, isWithinAllowedRoots, resolveToolPath } from "../runtime-paths.js";
11const MAX_COMMAND_LENGTH = 5000;
12const MAX_OUTPUT_BYTES = 1024 * 1024; // 1MB per stream
13export const bashTool = {
15 description: "Execute shell commands (git, npm, opencli, file ops). For Douyin/Xiaohongshu/Weibo/etc. run opencli after skill name=opencli; prefer opencli … -f json. Not for raw fetch of anti-bot pages.",
16 longDescription: `执行 shell 命令的万能工具。**Linux**: 通过 /bin/sh 执行。**Windows**: 通过 cmd.exe 执行(而非 PowerShell)。
17**重要 - Windows 用户**:Windows 上请使用标准的 cmd.exe 命令(dir, type, copy, del 等),不要使用 PowerShell 独有语法(Invoke-WebRequest 等)。cmd.exe 不支持 PowerShell cmdlet。
18**Linux 用户**:通过 /bin/sh 执行标准 POSIX 命令。
21- git 操作(git add, git commit, git push)
22- npm/node 命令(npm install, node scripts)
23- **opencli**(本机已安装时):opencli list / opencli douyin search … -f json(先 skill name="opencli")
24- 文件操作(ls, cp, mv, mkdir)
25- 进程管理(ps, kill, pgrep)
26- 网络工具(curl, wget, ping)— 强反爬社交站不要用 curl 硬抓
27- 编译构建(make, gcc, cargo)
30- rm -rf 等危险操作会被 Hook 拦截并要求确认
31- Windows 下需要通过 cmd.exe /c 执行
33- opencli 写操作(delete/publish)须用户确认`,