feat: 全局支持 --timeout 和 -T 参数限制运行时间

为所有 hose-use 命令增加全局参数 --timeout (或 -T),允许通过命令行参数直接指定进程运行的最长时限,超过时自动终止。适用于自动化脚本与 CI 环境的防阻塞防护。
This commit is contained in:
gitea committed 2026-11-18 19:14:32 +08:00
1 parent 6f60803c66
commit 41503917ce
2 files changed
+20 -2

No files matched your search

+1
View File
@@ -316,6 +316,7 @@ hose-use docs sync # 强制与 docs.ekuaib
## 全局选项
- `--timeout`, `-T <seconds>`:命令全局超时时间,超时后自动终止运行。
- `--corp=<id>`:临时指定操作的企业 ID(单次覆盖默认企业)
- `--json`, `-j`:以标准 JSON 结构化输出结果
- `--output-file, -o <path>`:将结果直接安全写入本地文件,仅返回精简摘要
+19 -2
View File
@@ -15,6 +15,23 @@ process.stderr.on("error", (err: any) => {
const entryFile = fileURLToPath(import.meta.url);
const appRoot = dirname(dirname(entryFile));
// 命令行参数超时处理:--timeout [秒] / -T [秒]
const args = process.argv.slice(2);
for (let i = args.length - 1; i >= 0; i--) {
if (args[i] === "--timeout" || args[i] === "-T") {
if (i + 1 < args.length) {
const timeoutSec = parseInt(args[i + 1], 10);
if (!isNaN(timeoutSec) && timeoutSec > 0) {
setTimeout(() => {
console.error(`[ERROR] 命令执行超时 (${timeoutSec}秒)`);
process.exit(1);
}, timeoutSec * 1000);
}
args.splice(i, 2);
}
}
}
// Unix Multicall Binary Pattern: 检测是否通过 hose-aipro 符号链接/别名唤起
const candidates = [process.argv0, process.argv[1], process.argv[0]].filter(Boolean) as string[];
const isAiPro = candidates.some((c) => {
@@ -23,8 +40,8 @@ const isAiPro = candidates.some((c) => {
});
const result = isAiPro
? await (await import("./aipro-cli.js")).runAiProCli(process.argv.slice(2))
: await runCli(process.argv.slice(2), {
? await (await import("./aipro-cli.js")).runAiProCli(args)
: await runCli(args, {
appRoot,
entryFile,
writeStdout: writeStdoutChunk,