@autocodeflow/cli 1.8.0 → 1.9.1
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 +80 -3
- package/dist/client.d.ts +18 -0
- package/dist/client.js +34 -1
- package/dist/commands/apikeys.d.ts +2 -0
- package/dist/commands/apikeys.js +104 -0
- package/dist/commands/approval.d.ts +2 -0
- package/dist/commands/approval.js +122 -0
- package/dist/commands/apps.js +266 -28
- package/dist/commands/audit.js +4 -3
- package/dist/commands/deploy.d.ts +8 -0
- package/dist/commands/deploy.js +88 -3
- package/dist/commands/exec.js +24 -2
- package/dist/commands/executors.js +8 -1
- package/dist/commands/login.d.ts +44 -0
- package/dist/commands/login.js +203 -12
- package/dist/commands/tasks.d.ts +16 -0
- package/dist/commands/tasks.js +455 -43
- package/dist/config.d.ts +10 -1
- package/dist/config.js +22 -5
- package/dist/help.js +81 -7
- package/dist/index.d.ts +9 -1
- package/dist/index.js +60 -5
- package/dist/ui.d.ts +25 -0
- package/dist/ui.js +48 -0
- package/package.json +1 -1
package/dist/commands/tasks.js
CHANGED
|
@@ -6,8 +6,60 @@ import axios from 'axios';
|
|
|
6
6
|
import { spawnSync } from 'child_process';
|
|
7
7
|
import * as fs from 'fs';
|
|
8
8
|
import * as path from 'path';
|
|
9
|
-
import { get, post, patch, del, ANALYZE_TIMEOUT_MS } from '../client.js';
|
|
10
|
-
import { emitError, emitUsageError, UsageError,
|
|
9
|
+
import { get, post, put, patch, del, ANALYZE_TIMEOUT_MS } from '../client.js';
|
|
10
|
+
import { emitError, emitUsageError, UsageError, confirmDestructive } from '../ui.js';
|
|
11
|
+
/**
|
|
12
|
+
* 结构化失败原因(failureReason,执行器回调上报)→ 可直接照做的建议。
|
|
13
|
+
*
|
|
14
|
+
* 2026-10 开发人员实测:任务声明 runtimeVersion=3.12 派到无该解释器的执行器
|
|
15
|
+
* 秒失败且执行日志 0 行——failureReason=interpreter_unavailable 只有 --json
|
|
16
|
+
* 里能看到,中文详情还得再查一次文档。把最常见的几个失败原因翻译成"下一步
|
|
17
|
+
* 怎么做",随 `--wait` 的失败终态直接打出来(键集对齐 executor-node
|
|
18
|
+
* protocol.schemas.ts 的 CallbackFailureReason 枚举)。
|
|
19
|
+
*/
|
|
20
|
+
export const FAILURE_REASON_HINTS = {
|
|
21
|
+
interpreter_unavailable: 'the interpreter requested by runtimeVersion is not available on this executor — remove runtimeVersion to use the host default interpreter',
|
|
22
|
+
runtime_missing: 'the task runtime is not available on this executor — check the task runtime field or the executor interpreter pool',
|
|
23
|
+
script_error: 'the entry script exited with a non-zero code — inspect the log with: acf task logs <execId>',
|
|
24
|
+
timeout: 'the execution exceeded its time budget — raise the task timeout or split the work',
|
|
25
|
+
sandbox_unavailable: 'the executor sandbox is not available — contact the executor operator or relax the sandbox configuration',
|
|
26
|
+
};
|
|
27
|
+
// P3 glue:执行器侧运行时白名单(executor-node execute.ts 的 glueLanguage 分支
|
|
28
|
+
// —— javascript/python/shell,另有 glue_node 等旧别名)。注意 node 脚本的合法
|
|
29
|
+
// 值是 `javascript`:发 `node` 执行器会在运行时抛 "Unsupported glue language",
|
|
30
|
+
// 与 acf task lint 的本地推断值(node|python|shell)刻意不同——lint 只做本地
|
|
31
|
+
// new Function 编译,glue 的 language 要落库给执行器消费。
|
|
32
|
+
const GLUE_LANGUAGES = ['python', 'javascript', 'shell'];
|
|
33
|
+
const GLUE_EXT_LANG = {
|
|
34
|
+
'.py': 'python',
|
|
35
|
+
'.js': 'javascript',
|
|
36
|
+
'.mjs': 'javascript',
|
|
37
|
+
'.cjs': 'javascript',
|
|
38
|
+
'.sh': 'shell',
|
|
39
|
+
'.bash': 'shell',
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* E-1:`acf task import -` 的 stdin 读取。"-" 是 CI/管道惯例;stdin 是 TTY
|
|
43
|
+
* 时(用户忘了给文件、手敲 `-`)拒绝而不是挂死等待 EOF。流参数可注入——
|
|
44
|
+
* 单测用 PassThrough 驱动,不碰真实 stdin。
|
|
45
|
+
*/
|
|
46
|
+
export function readStdin(stream = process.stdin) {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
if (stream.isTTY) {
|
|
49
|
+
reject(new UsageError('stdin is a TTY — pipe the payload (cat payload.json | acf task import -) or pass a file path'));
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
let data = '';
|
|
53
|
+
stream.setEncoding('utf-8');
|
|
54
|
+
stream.on('data', (chunk) => {
|
|
55
|
+
data += chunk;
|
|
56
|
+
});
|
|
57
|
+
stream.on('end', () => resolve(data));
|
|
58
|
+
stream.on('error', (err) => {
|
|
59
|
+
reject(new UsageError(`Cannot read stdin: ${err instanceof Error ? err.message : String(err)}`));
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
}
|
|
11
63
|
function statusColor(s) {
|
|
12
64
|
if (s === 'success')
|
|
13
65
|
return chalk.green(s);
|
|
@@ -27,19 +79,21 @@ export function tasksCommand() {
|
|
|
27
79
|
cmd.command('list')
|
|
28
80
|
.description('List all tasks')
|
|
29
81
|
.option('-s, --status <status>', 'Filter by status (active|paused)')
|
|
30
|
-
.option('-k, --keyword <keyword>', 'Search by
|
|
82
|
+
.option('-k, --keyword <keyword>', 'Search by NAME only (sent as the `name` query param; backward-compatible channel)')
|
|
83
|
+
.option('--search <keyword>', 'Search across name AND description (sent as the `q` query param — what the console search box sends; combined with --keyword both must match)')
|
|
31
84
|
.option('-p, --page <n>', 'Page number', '1')
|
|
32
85
|
.option('-n, --page-size <n>', 'Items per page', '20')
|
|
33
86
|
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
34
87
|
.action(async (opts) => {
|
|
35
88
|
const spinner = ora('Fetching tasks…').start();
|
|
36
89
|
try {
|
|
37
|
-
// ListTasksQueryDto
|
|
90
|
+
// ListTasksQueryDto: `name`(按名,向后兼容)+ `q`(name OR description)
|
|
38
91
|
const data = await get('/tasks', {
|
|
39
92
|
page: opts.page,
|
|
40
93
|
pageSize: opts.pageSize,
|
|
41
94
|
status: opts.status,
|
|
42
95
|
name: opts.keyword,
|
|
96
|
+
q: opts.search,
|
|
43
97
|
});
|
|
44
98
|
spinner.stop();
|
|
45
99
|
if (opts.json) {
|
|
@@ -78,11 +132,17 @@ export function tasksCommand() {
|
|
|
78
132
|
return;
|
|
79
133
|
}
|
|
80
134
|
console.log(chalk.bold('Task Details'));
|
|
81
|
-
console.log(' ID
|
|
82
|
-
console.log(' Name
|
|
83
|
-
console.log(' Runtime
|
|
84
|
-
console.log(' Status
|
|
85
|
-
console.log('
|
|
135
|
+
console.log(' ID :', t.id);
|
|
136
|
+
console.log(' Name :', t.name);
|
|
137
|
+
console.log(' Runtime :', t.runtime);
|
|
138
|
+
console.log(' Status :', statusColor(t.status));
|
|
139
|
+
console.log(' Trigger :', t.triggerType ?? '-');
|
|
140
|
+
console.log(' Cron :', t.cronExpression ?? '-');
|
|
141
|
+
console.log(' Description :', t.description ?? '-');
|
|
142
|
+
console.log(' App :', t.applicationId ?? '-');
|
|
143
|
+
console.log(' Timeout :', t.timeout !== undefined && t.timeout !== null ? `${t.timeout}s` : '-');
|
|
144
|
+
console.log(' Max retry :', t.maxRetry ?? '-');
|
|
145
|
+
console.log(' Enabled :', t.enabled === undefined ? '-' : (t.enabled ? chalk.green('yes') : chalk.gray('no')));
|
|
86
146
|
}
|
|
87
147
|
catch (e) {
|
|
88
148
|
emitError('Failed', e, { spinner });
|
|
@@ -90,7 +150,7 @@ export function tasksCommand() {
|
|
|
90
150
|
});
|
|
91
151
|
// acf task trigger <id>
|
|
92
152
|
cmd.command('trigger <id>')
|
|
93
|
-
.description('Manually trigger a task
|
|
153
|
+
.description('Manually trigger a task. Returns the execution id immediately; add --wait to poll until the terminal state and get its exit code')
|
|
94
154
|
.option('--wait', 'Poll until execution finishes', false)
|
|
95
155
|
// NETOPT-2①: --wait 的轮询上限可调(秒)。默认 600 保持既有行为;
|
|
96
156
|
// 非正值直接报参数错误而不是静默回落默认值——CI 里写错单位(毫秒当秒)
|
|
@@ -107,24 +167,49 @@ export function tasksCommand() {
|
|
|
107
167
|
// per-trigger pin would be rejected with 400. Executor pinning IS
|
|
108
168
|
// supported by the backend as a task-level field (tasks.executorId) — set
|
|
109
169
|
// it via `acf task create/update --executor <id>`, not per run.
|
|
170
|
+
// --params 补面(本轮):TriggerTaskDto 收 params(覆盖任务默认参数,与
|
|
171
|
+
// webhook 面同形),block-strategy 闸(N-14)按生效参数判重——CLI 此前
|
|
172
|
+
// 永远发空 body,无法按 run 覆盖参数。
|
|
173
|
+
.option('--params <json>', 'Per-run param overrides as JSON, e.g. \'{"KEY":"value"}\' (replaces the task\'s default params for this run)')
|
|
110
174
|
// 第四轮审计(--json 补面):trigger 响应(execution 对象)直出 JSON,
|
|
111
175
|
// CI 拿 executionId 做后续断言无需解析人读文本。
|
|
112
176
|
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
113
177
|
.action(async (id, opts) => {
|
|
114
178
|
const spinner = ora('Triggering task…').start();
|
|
115
179
|
try {
|
|
116
|
-
|
|
180
|
+
// 本地 JSON 预检:坏 params 是用法错误(退出码 2),请求不发出。
|
|
181
|
+
let params;
|
|
182
|
+
if (opts.params !== undefined) {
|
|
183
|
+
try {
|
|
184
|
+
params = JSON.parse(opts.params);
|
|
185
|
+
}
|
|
186
|
+
catch (e) {
|
|
187
|
+
throw new UsageError(`Invalid --params JSON: ${e instanceof Error ? e.message : String(e)}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
// 只有显式 --params 才带 body(缺省时 post 单参调用,既有语义逐字节保持)。
|
|
191
|
+
const exec = params !== undefined
|
|
192
|
+
? await post(`/tasks/${id}/trigger`, { params })
|
|
193
|
+
: await post(`/tasks/${id}/trigger`);
|
|
117
194
|
if (opts.json) {
|
|
118
|
-
// ECO-02 同款:--json —— ora 默认写 stderr,stdout 仍是干净 JSON
|
|
119
|
-
// --wait
|
|
195
|
+
// ECO-02 同款:--json —— ora 默认写 stderr,stdout 仍是干净 JSON。
|
|
196
|
+
// P2(CLI-AGENT-UX-AUDIT):--json **且** --wait 时不在这里输出中间态,
|
|
197
|
+
// 改由 pollExecution 在最末尾一次性输出**最终** execution 对象——
|
|
198
|
+
// 否则 stdout 会先来一段 execution JSON,再接死亡终态的人类可读行
|
|
199
|
+
// (Exit code / Failure reason),单行 JSON 解析器必崩。
|
|
120
200
|
spinner.stop();
|
|
121
|
-
|
|
201
|
+
if (!opts.wait) {
|
|
202
|
+
console.log(JSON.stringify(exec, null, 2));
|
|
203
|
+
}
|
|
122
204
|
}
|
|
123
205
|
else {
|
|
124
206
|
spinner.succeed(`Execution started: ${exec.id}`);
|
|
207
|
+
if (!opts.wait) {
|
|
208
|
+
process.stderr.write(chalk.gray(' (add --wait to poll until completion and get the exit code)\n'));
|
|
209
|
+
}
|
|
125
210
|
}
|
|
126
211
|
if (opts.wait) {
|
|
127
|
-
await pollExecution(exec.id, opts.waitTimeout);
|
|
212
|
+
await pollExecution(exec.id, opts.waitTimeout, { json: !!opts.json });
|
|
128
213
|
}
|
|
129
214
|
}
|
|
130
215
|
catch (e) {
|
|
@@ -155,8 +240,11 @@ export function tasksCommand() {
|
|
|
155
240
|
const table = new Table({
|
|
156
241
|
// U11: exitCode column — distinguishes "failed by callback
|
|
157
242
|
// report" (exit 0 / null) from "process died" (non-zero).
|
|
158
|
-
|
|
159
|
-
|
|
243
|
+
// 2026-10 补 failureReason 列:interpreter_unavailable 这类结构化
|
|
244
|
+
// 失败此前只在 --json 可见(executions 表格无原因),值班扫一眼
|
|
245
|
+
// 即可分流。
|
|
246
|
+
head: ['Exec ID', 'Status', 'Duration', 'Exit', 'Reason', 'Started'],
|
|
247
|
+
colWidths: [14, 12, 12, 6, 30, 25],
|
|
160
248
|
style: { head: ['cyan'] },
|
|
161
249
|
});
|
|
162
250
|
for (const e of data.list ?? []) {
|
|
@@ -165,6 +253,7 @@ export function tasksCommand() {
|
|
|
165
253
|
statusColor(e.status),
|
|
166
254
|
e.duration ? `${e.duration}ms` : '-',
|
|
167
255
|
e.exitCode ?? '-',
|
|
256
|
+
e.failureReason ?? '-',
|
|
168
257
|
new Date(e.createdAt).toLocaleString(),
|
|
169
258
|
]);
|
|
170
259
|
}
|
|
@@ -373,19 +462,34 @@ export function tasksCommand() {
|
|
|
373
462
|
});
|
|
374
463
|
// acf task create
|
|
375
464
|
cmd.command('create')
|
|
376
|
-
.description('Create a new task (JSON payload via --
|
|
377
|
-
|
|
378
|
-
|
|
465
|
+
.description('Create a new task (JSON payload via --body or --file)')
|
|
466
|
+
// 2026-10-07 deprecation:载荷旗标由 --json 更名 --body——--json 将在下一个
|
|
467
|
+
// 大版本收敛为纯布尔「输出 JSON」旗标(与 task list/show/trigger 等命令的
|
|
468
|
+
// 既有语义统一)。旧名本版本仍可用(与 --body 互斥),stderr 打警告。
|
|
469
|
+
// 二者都声明为可选(requiredOption 会让 --json 过渡路径在 commander 层就
|
|
470
|
+
// 被"缺必填"拒绝),缺一校验在 action 里做。
|
|
471
|
+
.option('--body <json>', 'Task body as JSON string (required unless --file is given)')
|
|
472
|
+
.option('--json <body>', 'DEPRECATED (renamed to --body): Task body as JSON string. In the next major version --json becomes a boolean output flag')
|
|
473
|
+
.option('--file <path>', 'Read task body from a JSON file (overrides --body/--json)')
|
|
379
474
|
.option('--executor <id>', 'Pin the task to a specific executor ID (uuid); mutually exclusive with executeMode=broadcast')
|
|
380
475
|
.action(async (opts) => {
|
|
476
|
+
if (opts.body !== undefined && opts.json !== undefined) {
|
|
477
|
+
emitUsageError('--body and --json (deprecated alias) are mutually exclusive — pass only --body');
|
|
478
|
+
}
|
|
479
|
+
if (opts.body === undefined && opts.json === undefined && !opts.file) {
|
|
480
|
+
emitUsageError('Missing required task body — pass --body <json> (or --file <path>)');
|
|
481
|
+
}
|
|
381
482
|
const spinner = ora('Creating task…').start();
|
|
382
483
|
try {
|
|
484
|
+
if (opts.json !== undefined) {
|
|
485
|
+
process.stderr.write(chalk.yellow('⚠ --json <body> is deprecated and will be removed in the next major version (it will become a boolean output flag). Use --body <json> instead.\n'));
|
|
486
|
+
}
|
|
383
487
|
const fs = await import('fs/promises');
|
|
384
488
|
// 本地 payload 层错误(文件读不了/JSON 坏)= 用法错误(退出码 2),
|
|
385
489
|
// 与服务端拒绝(1)区分;口径与 apps.ts 的 loadJsonBody 一致。
|
|
386
490
|
let raw;
|
|
387
491
|
try {
|
|
388
|
-
raw = opts.file ? await fs.readFile(opts.file, 'utf-8') : opts.json;
|
|
492
|
+
raw = opts.file ? await fs.readFile(opts.file, 'utf-8') : (opts.body ?? opts.json);
|
|
389
493
|
}
|
|
390
494
|
catch (err) {
|
|
391
495
|
throw new UsageError(`Cannot read payload file: ${opts.file} (${err instanceof Error ? err.message : String(err)})`);
|
|
@@ -410,19 +514,30 @@ export function tasksCommand() {
|
|
|
410
514
|
});
|
|
411
515
|
// acf task update <id>
|
|
412
516
|
cmd.command('update <id>')
|
|
413
|
-
.description('Update a task (JSON payload via --
|
|
414
|
-
|
|
415
|
-
.option('--
|
|
416
|
-
.option('--
|
|
517
|
+
.description('Update a task (JSON payload via --body or --file)')
|
|
518
|
+
// 2026-10-07 deprecation:同 task create——载荷更名 --body,旧名过渡一版。
|
|
519
|
+
.option('--body <json>', 'Task patch body as JSON string (required unless --file is given)')
|
|
520
|
+
.option('--json <body>', 'DEPRECATED (renamed to --body): Task patch body as JSON string. In the next major version --json becomes a boolean output flag')
|
|
521
|
+
.option('--file <path>', 'Read task patch body from a JSON file (overrides --body/--json)')
|
|
522
|
+
.option('--executor <id>', 'Pin the task to a specific executor ID (uuid); pass --body {"executorId":null} to clear. Mutually exclusive with executeMode=broadcast')
|
|
417
523
|
.action(async (id, opts) => {
|
|
524
|
+
if (opts.body !== undefined && opts.json !== undefined) {
|
|
525
|
+
emitUsageError('--body and --json (deprecated alias) are mutually exclusive — pass only --body');
|
|
526
|
+
}
|
|
527
|
+
if (opts.body === undefined && opts.json === undefined && !opts.file) {
|
|
528
|
+
emitUsageError('Missing required task patch body — pass --body <json> (or --file <path>)');
|
|
529
|
+
}
|
|
418
530
|
const spinner = ora('Updating task…').start();
|
|
419
531
|
try {
|
|
532
|
+
if (opts.json !== undefined) {
|
|
533
|
+
process.stderr.write(chalk.yellow('⚠ --json <body> is deprecated and will be removed in the next major version (it will become a boolean output flag). Use --body <json> instead.\n'));
|
|
534
|
+
}
|
|
420
535
|
const fs = await import('fs/promises');
|
|
421
536
|
// 本地 payload 层错误(文件读不了/JSON 坏)= 用法错误(退出码 2),
|
|
422
537
|
// 与服务端拒绝(1)区分;口径与 apps.ts 的 loadJsonBody 一致。
|
|
423
538
|
let raw;
|
|
424
539
|
try {
|
|
425
|
-
raw = opts.file ? await fs.readFile(opts.file, 'utf-8') : opts.json;
|
|
540
|
+
raw = opts.file ? await fs.readFile(opts.file, 'utf-8') : (opts.body ?? opts.json);
|
|
426
541
|
}
|
|
427
542
|
catch (err) {
|
|
428
543
|
throw new UsageError(`Cannot read payload file: ${opts.file} (${err instanceof Error ? err.message : String(err)})`);
|
|
@@ -450,18 +565,9 @@ export function tasksCommand() {
|
|
|
450
565
|
.description('Delete a task (force-terminates running executions)')
|
|
451
566
|
.option('-y, --yes', 'Skip confirmation prompt', false)
|
|
452
567
|
.action(async (id, opts) => {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
// raw 模式下 Ctrl+C 触发 rl 'SIGINT' 而非进程信号;无监听只会 pause,
|
|
457
|
-
// 确认提示处会假死。接住并走统一中断出口(130)。
|
|
458
|
-
rl.on('SIGINT', () => interruptExit());
|
|
459
|
-
const answer = await rl.question(`Delete task ${id}? Running executions will be force-terminated. [y/N] `);
|
|
460
|
-
rl.close();
|
|
461
|
-
if (!/^y(es)?$/i.test(answer)) {
|
|
462
|
-
console.log(chalk.yellow('Aborted.'));
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
568
|
+
// P0(CLI-AGENT-UX-AUDIT):非交互 stdin 下必须显式拒绝,不能静默假绿。
|
|
569
|
+
if (!(await confirmDestructive(`Delete task ${id}? Running executions will be force-terminated.`, { yes: opts.yes }))) {
|
|
570
|
+
return;
|
|
465
571
|
}
|
|
466
572
|
const spinner = ora('Deleting task…').start();
|
|
467
573
|
try {
|
|
@@ -500,6 +606,138 @@ export function tasksCommand() {
|
|
|
500
606
|
emitError('Failed to resume task', e, { spinner });
|
|
501
607
|
}
|
|
502
608
|
});
|
|
609
|
+
// E-1: acf task export <id> [-o file] —— 导出任务定义为 JSON(导出物即
|
|
610
|
+
// POST /tasks/import 的请求体,两端口径完全对称,CLI 不做任何本地变换)。
|
|
611
|
+
// 服务端不经统一 envelope 包裹(@Res() 直写 attachment),client 的 unwrap
|
|
612
|
+
// 判据(数值 code)不会命中,这里拿到的就是原始 { schemaVersion, exportedAt, task }。
|
|
613
|
+
cmd.command('export <id>')
|
|
614
|
+
.description('Export a task definition as JSON (the payload is accepted verbatim by `acf task import`; secrets are never part of it)')
|
|
615
|
+
.option('-o, --output <file>', 'Write the JSON payload to a file instead of stdout')
|
|
616
|
+
.action(async (id, opts) => {
|
|
617
|
+
const spinner = ora('Exporting task…').start();
|
|
618
|
+
try {
|
|
619
|
+
const payload = await get(`/tasks/${id}/export`);
|
|
620
|
+
if (opts.output) {
|
|
621
|
+
try {
|
|
622
|
+
await fs.promises.writeFile(opts.output, JSON.stringify(payload, null, 2) + '\n', 'utf-8');
|
|
623
|
+
}
|
|
624
|
+
catch (err) {
|
|
625
|
+
// 本地文件层错误 = 用法错误(退出码 2),与服务端拒绝(1)区分。
|
|
626
|
+
throw new UsageError(`Cannot write export file: ${opts.output} (${err instanceof Error ? err.message : String(err)})`);
|
|
627
|
+
}
|
|
628
|
+
spinner.succeed(`Task exported to ${opts.output}`);
|
|
629
|
+
}
|
|
630
|
+
else {
|
|
631
|
+
spinner.stop();
|
|
632
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
catch (e) {
|
|
636
|
+
emitError('Failed to export task', e, { spinner });
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
// E-1: acf task import <file> —— 从导出物创建任务("-" 读 stdin)。
|
|
640
|
+
// 请求体 = 导出物原样回放(JSON.parse 后交由 axios 序列化,键序/键值不变);
|
|
641
|
+
// 重名自动加后缀不覆盖、secrets 键整体忽略(warnings 常驻重配提示)均为服务端语义。
|
|
642
|
+
cmd.command('import <file>')
|
|
643
|
+
.description('Create a task from an export payload ("-" reads stdin). The new task starts paused; reconfigure secrets afterwards (SEC-02: they are never transferred)')
|
|
644
|
+
.action(async (file) => {
|
|
645
|
+
const spinner = ora('Importing task…').start();
|
|
646
|
+
try {
|
|
647
|
+
let raw;
|
|
648
|
+
try {
|
|
649
|
+
raw = file === '-' ? await readStdin() : await fs.promises.readFile(file, 'utf-8');
|
|
650
|
+
}
|
|
651
|
+
catch (err) {
|
|
652
|
+
// 本地 payload 层错误(文件读不了/stdin 不可用)= 用法错误(退出码 2)。
|
|
653
|
+
throw new UsageError(`Cannot read payload ${file === '-' ? 'from stdin' : `file: ${file}`} (${err instanceof Error ? err.message : String(err)})`);
|
|
654
|
+
}
|
|
655
|
+
let body;
|
|
656
|
+
try {
|
|
657
|
+
body = JSON.parse(raw);
|
|
658
|
+
}
|
|
659
|
+
catch (err) {
|
|
660
|
+
throw new UsageError(`Invalid JSON payload: ${err instanceof Error ? err.message : String(err)}`);
|
|
661
|
+
}
|
|
662
|
+
const result = await post('/tasks/import', body);
|
|
663
|
+
spinner.stop();
|
|
664
|
+
spinner.succeed(`Task imported: ${result.taskId}`);
|
|
665
|
+
console.log(chalk.gray(` name: ${result.name} status: paused`));
|
|
666
|
+
for (const w of result.warnings ?? []) {
|
|
667
|
+
console.log(chalk.yellow(` ⚠ ${w}`));
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
catch (e) {
|
|
671
|
+
emitError('Failed to import task', e, { spinner });
|
|
672
|
+
}
|
|
673
|
+
});
|
|
674
|
+
// 批量面:POST /tasks/batch/{trigger|pause|resume|delete},body = { taskIds }。
|
|
675
|
+
// 服务端逐个执行、部分失败不影响其他任务(失败项以 { id, error } 回传,恒 200)。
|
|
676
|
+
cmd.command('batch <action> [ids...]')
|
|
677
|
+
.description('Batch trigger/pause/resume/delete tasks (partial failures do not affect the other tasks)')
|
|
678
|
+
.option('--ids <ids>', 'Comma-separated task IDs (merged with any positional ids, deduplicated)')
|
|
679
|
+
.option('--json', 'Emit raw JSON (CI-consumable: the raw per-task result array)')
|
|
680
|
+
.option('-y, --yes', 'Skip the confirmation prompt for batch delete', false)
|
|
681
|
+
.action(async (action, ids, opts) => {
|
|
682
|
+
const ACTIONS = ['trigger', 'pause', 'resume', 'delete'];
|
|
683
|
+
if (!ACTIONS.includes(action)) {
|
|
684
|
+
emitUsageError(`Unknown batch action "${action}" — expected one of: ${ACTIONS.join(' | ')}`);
|
|
685
|
+
}
|
|
686
|
+
const fromFlag = (opts.ids ?? '')
|
|
687
|
+
.split(',')
|
|
688
|
+
.map((s) => s.trim())
|
|
689
|
+
.filter(Boolean);
|
|
690
|
+
// 服务端硬契约(BatchTaskIdsDto):1..500 个 uuid,单请求上限 500。
|
|
691
|
+
const taskIds = [...new Set([...(ids ?? []), ...fromFlag])];
|
|
692
|
+
if (taskIds.length === 0) {
|
|
693
|
+
emitUsageError('No task IDs given — pass them as arguments or via --ids id1,id2,id3');
|
|
694
|
+
}
|
|
695
|
+
if (taskIds.length > 500) {
|
|
696
|
+
emitUsageError(`Batch is limited to 500 task IDs per request (got ${taskIds.length})`);
|
|
697
|
+
}
|
|
698
|
+
// P1(CLI-AGENT-UX-AUDIT):`batch delete` 此前**零确认**——单个
|
|
699
|
+
// `task delete` 要确认,而 `--ids a,b,c`(上限 500 个)却能无提示抹掉
|
|
700
|
+
// 一整批任务。按「不可逆 × 影响面」补确认,且与三处 delete 共用同一个
|
|
701
|
+
// 非交互语义(缺 --yes 时以退出码 2 拒绝,不静默假绿)。
|
|
702
|
+
if (action === 'delete') {
|
|
703
|
+
if (!(await confirmDestructive(`Delete ${taskIds.length} task(s)? Running executions will be force-terminated.`, { yes: opts.yes }))) {
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
const spinner = ora(`Batch ${action} (${taskIds.length} task(s))…`).start();
|
|
708
|
+
try {
|
|
709
|
+
// Promise.all 保序:results[i] 对应 taskIds[i](失败项为 { id, error })。
|
|
710
|
+
const results = await post(`/tasks/batch/${action}`, { taskIds });
|
|
711
|
+
spinner.stop();
|
|
712
|
+
if (opts.json) {
|
|
713
|
+
console.log(JSON.stringify(results ?? []));
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
let failed = 0;
|
|
717
|
+
(results ?? []).forEach((r, i) => {
|
|
718
|
+
const tid = taskIds[i] ?? String(i);
|
|
719
|
+
if (r && typeof r === 'object' && 'error' in r) {
|
|
720
|
+
failed++;
|
|
721
|
+
console.log(chalk.red(`✗ ${tid}: ${String(r.error)}`));
|
|
722
|
+
}
|
|
723
|
+
else {
|
|
724
|
+
console.log(chalk.green(`✔ ${tid}`));
|
|
725
|
+
}
|
|
726
|
+
});
|
|
727
|
+
if (failed > 0) {
|
|
728
|
+
// 部分失败:服务端仍是 200,但 CLI 要让 CI 看得见(对齐 CLI-EXIT-01
|
|
729
|
+
// 的「--wait 失败终态 → 非零退出码」语义)。退出码 1 = 服务端拒绝类。
|
|
730
|
+
console.error(chalk.red(`Batch ${action} finished with ${failed} failure(s) out of ${taskIds.length} task(s).`));
|
|
731
|
+
process.exitCode = 1;
|
|
732
|
+
}
|
|
733
|
+
else {
|
|
734
|
+
console.log(chalk.green(`Batch ${action}: ${taskIds.length}/${taskIds.length} succeeded`));
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
catch (e) {
|
|
738
|
+
emitError(`Failed to batch ${action}`, e, { spinner });
|
|
739
|
+
}
|
|
740
|
+
});
|
|
503
741
|
// acf task kill <taskId> <execId>
|
|
504
742
|
cmd.command('kill <taskId> <execId>')
|
|
505
743
|
.description('Force-cancel a running or pending execution')
|
|
@@ -513,6 +751,125 @@ export function tasksCommand() {
|
|
|
513
751
|
emitError('Failed to cancel execution', e, { spinner });
|
|
514
752
|
}
|
|
515
753
|
});
|
|
754
|
+
// P3: acf task webhook <enable|rotate|disable|status> <taskId>(FEAT-21 任务级
|
|
755
|
+
// 入站 webhook)。契约:enable/rotate 响应 { url, secret }——secret 明文仅在
|
|
756
|
+
// 该响应出现一次,服务端只存加密信封,输出必须带一次性提示(口径同 apikey
|
|
757
|
+
// create 的 plaintext);enable 对已启用任务等价轮换;disable 清空密钥、签名
|
|
758
|
+
// 请求即刻 401;status(GET)只回 { enabled, url },secret 永不回传——查看
|
|
759
|
+
// URL 而不必轮换密钥的通路。
|
|
760
|
+
cmd.command('webhook <action> <taskId>')
|
|
761
|
+
.description('Manage the task inbound webhook (HMAC-signed). enable/rotate print the secret exactly once; status shows the URL without touching the secret; disable makes signed calls answer 401 immediately')
|
|
762
|
+
.option('--json', 'Emit raw JSON (CI-consumable; includes the one-time secret for enable/rotate)')
|
|
763
|
+
.action(async (action, taskId, opts) => {
|
|
764
|
+
const ACTIONS = ['enable', 'rotate', 'disable', 'status'];
|
|
765
|
+
if (!ACTIONS.includes(action)) {
|
|
766
|
+
emitUsageError(`Unknown webhook action "${action}" — expected one of: ${ACTIONS.join(' | ')}`);
|
|
767
|
+
}
|
|
768
|
+
const spinner = ora(`Task webhook ${action}…`).start();
|
|
769
|
+
try {
|
|
770
|
+
if (action === 'status') {
|
|
771
|
+
const s = await get(`/tasks/${taskId}/webhook`);
|
|
772
|
+
spinner.stop();
|
|
773
|
+
if (opts.json) {
|
|
774
|
+
console.log(JSON.stringify(s));
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
console.log(chalk.bold('Task Webhook'));
|
|
778
|
+
console.log(' Enabled:', s.enabled ? chalk.green('yes') : chalk.red('no'));
|
|
779
|
+
console.log(' URL :', s.url);
|
|
780
|
+
console.log(chalk.gray(' (the secret is never returned by status — run rotate to reissue one)'));
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
if (action === 'disable') {
|
|
784
|
+
const r = await post(`/tasks/${taskId}/webhook/disable`);
|
|
785
|
+
spinner.stop();
|
|
786
|
+
if (opts.json) {
|
|
787
|
+
console.log(JSON.stringify(r));
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
spinner.succeed('Task webhook disabled — signed calls now answer 401');
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
// enable | rotate:{ url, secret } 一次性回显。路径必须显式——服务端
|
|
794
|
+
// 是三条字面量路由(enable/rotate/disable),动态模板虽运行时可达,
|
|
795
|
+
// 但 consumer-routes 守卫的静态对账无法把两段参数模板对上 openapi。
|
|
796
|
+
const actionPath = action === 'enable'
|
|
797
|
+
? `/tasks/${taskId}/webhook/enable`
|
|
798
|
+
: `/tasks/${taskId}/webhook/rotate`;
|
|
799
|
+
const r = await post(actionPath);
|
|
800
|
+
spinner.stop();
|
|
801
|
+
if (opts.json) {
|
|
802
|
+
console.log(JSON.stringify(r));
|
|
803
|
+
return;
|
|
804
|
+
}
|
|
805
|
+
spinner.succeed(action === 'enable'
|
|
806
|
+
? 'Task webhook enabled'
|
|
807
|
+
: 'Task webhook secret rotated — the old secret stopped working immediately');
|
|
808
|
+
console.log(' URL :', r.url);
|
|
809
|
+
console.log(' Secret :', chalk.bold(r.secret));
|
|
810
|
+
console.log(chalk.yellow(' ⚠ The secret is shown only once — store it now (CI secret store / env file). It cannot be retrieved again; rotate to reissue.'));
|
|
811
|
+
console.log(chalk.gray(' Trigger: POST the URL with X-AutoCodeFlow-Timestamp and X-Hub-Signature-256: sha256=<hex of HMAC_SHA256(secret, "<timestamp>.<rawBody>")>'));
|
|
812
|
+
}
|
|
813
|
+
catch (e) {
|
|
814
|
+
emitError(`Failed to ${action} task webhook`, e, { spinner });
|
|
815
|
+
}
|
|
816
|
+
});
|
|
817
|
+
// P3: acf task glue <taskId> -f <file> | --stdin —— PUT /tasks/:id/glue
|
|
818
|
+
//({ source, language? })。语言按扩展名推断或 --language 显式指定(白名单
|
|
819
|
+
// 见 GLUE_LANGUAGES);空/纯空白脚本服务端 400(会让任务静默改跑 entrypoint
|
|
820
|
+
// 的自相矛盾态),CLI 本地同判提前拒绝。语法可先用 acf task lint 本地预检。
|
|
821
|
+
cmd.command('glue <taskId>')
|
|
822
|
+
.description('Update the GLUE script inline (online code edit). Language is inferred from the file extension (.js/.mjs/.cjs → javascript, .py → python, .sh/.bash → shell) or forced with --language python|javascript|shell')
|
|
823
|
+
.option('-f, --file <path>', 'Read the script from a file; "-" reads stdin (same convention as acf task import)')
|
|
824
|
+
.option('--stdin', 'Read the script from stdin (equivalent to -f -)')
|
|
825
|
+
.option('--language <lang>', 'Language: python | javascript | shell (the executor rejects anything else at run time)')
|
|
826
|
+
.action(async (taskId, opts) => {
|
|
827
|
+
if (opts.stdin && opts.file) {
|
|
828
|
+
emitUsageError('--stdin and -f/--file are mutually exclusive');
|
|
829
|
+
}
|
|
830
|
+
if (!opts.stdin && !opts.file) {
|
|
831
|
+
emitUsageError('Nothing to upload — pass -f <file> (or --stdin). Preview syntax locally first with: acf task lint <file>');
|
|
832
|
+
}
|
|
833
|
+
const fromStdin = opts.stdin || opts.file === '-';
|
|
834
|
+
const spinner = ora('Updating glue script…').start();
|
|
835
|
+
try {
|
|
836
|
+
let source;
|
|
837
|
+
try {
|
|
838
|
+
source = fromStdin ? await readStdin() : await fs.promises.readFile(opts.file, 'utf-8');
|
|
839
|
+
}
|
|
840
|
+
catch (err) {
|
|
841
|
+
// 本地 payload 层错误(文件读不了/stdin 不可用)= 用法错误(退出码 2)。
|
|
842
|
+
throw new UsageError(`Cannot read script ${fromStdin ? 'from stdin' : `file: ${opts.file}`} (${err instanceof Error ? err.message : String(err)})`);
|
|
843
|
+
}
|
|
844
|
+
if (!source.trim()) {
|
|
845
|
+
// 与服务端 P0 防线同判(service 层拒绝空脚本,语义同一条消息)。
|
|
846
|
+
throw new UsageError('Refusing to upload an empty glue script — the server would reject it (the task would silently fall back to its entrypoint)');
|
|
847
|
+
}
|
|
848
|
+
let language;
|
|
849
|
+
if (opts.language) {
|
|
850
|
+
if (!GLUE_LANGUAGES.includes(opts.language)) {
|
|
851
|
+
throw new UsageError(`Unknown glue language "${opts.language}" — expected one of: ${GLUE_LANGUAGES.join(' | ')} (the executor rejects other values at run time)`);
|
|
852
|
+
}
|
|
853
|
+
language = opts.language;
|
|
854
|
+
}
|
|
855
|
+
else if (fromStdin) {
|
|
856
|
+
throw new UsageError('Cannot infer the glue language from stdin — pass --language python|javascript|shell');
|
|
857
|
+
}
|
|
858
|
+
else {
|
|
859
|
+
const ext = path.extname(opts.file).toLowerCase();
|
|
860
|
+
language = GLUE_EXT_LANG[ext];
|
|
861
|
+
if (!language) {
|
|
862
|
+
throw new UsageError(`Cannot infer the glue language from extension "${ext}" (${opts.file}) — pass --language python|javascript|shell`);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
const t = await put(`/tasks/${taskId}/glue`, { source, language });
|
|
866
|
+
spinner.succeed(`Glue script updated: ${t.id}`);
|
|
867
|
+
console.log(chalk.gray(` name: ${t.name} language: ${language} bytes: ${Buffer.byteLength(source, 'utf-8')}`));
|
|
868
|
+
}
|
|
869
|
+
catch (e) {
|
|
870
|
+
emitError('Failed to update glue script', e, { spinner });
|
|
871
|
+
}
|
|
872
|
+
});
|
|
516
873
|
// ECO-02: acf task lint <file> —— 本地语法检查(node: 语法编译不执行;
|
|
517
874
|
// python: ast.parse;shell: bash -n)。上传 glue 前把语法错误挡在本地。
|
|
518
875
|
cmd
|
|
@@ -564,10 +921,14 @@ export function tasksCommand() {
|
|
|
564
921
|
return r.status === 0;
|
|
565
922
|
});
|
|
566
923
|
if (!py) {
|
|
567
|
-
|
|
568
|
-
|
|
924
|
+
// 环境不满足 ≠ 脚本有语法错:给退出码 2(用法/环境),让 CI 能区分
|
|
925
|
+
// 「我的脚本坏了」与「这台机器没装 Python」。
|
|
926
|
+
emitUsageError('python not found on PATH — install Python 3 to lint python glue (or pass --language to check another runtime)');
|
|
569
927
|
}
|
|
570
|
-
|
|
928
|
+
// 走 stdin 传源码而非把路径当 argv:Windows 路径的反斜杠会被 bash/python
|
|
929
|
+
// 的解析层吃掉(`C:\Users\...` → `C:Users...`),实测必假报。
|
|
930
|
+
const r = spawnSync(py, ['-c', `import ast,sys; ast.parse(sys.stdin.read())`], {
|
|
931
|
+
input: source,
|
|
571
932
|
stdio: 'pipe',
|
|
572
933
|
});
|
|
573
934
|
if (r.status !== 0) {
|
|
@@ -578,7 +939,18 @@ export function tasksCommand() {
|
|
|
578
939
|
ok('syntax OK (python, ast.parse)');
|
|
579
940
|
}
|
|
580
941
|
else {
|
|
581
|
-
|
|
942
|
+
// P1(CLI-AGENT-UX-AUDIT):此前是 spawnSync('bash', ['-n', file])——
|
|
943
|
+
// Windows 上 bash 把 `C:\Users\...` 的反斜杠当转义符吃掉,报
|
|
944
|
+
// `/bin/bash: C:Users... No such file or directory`,**任何合法脚本
|
|
945
|
+
// 都被判 syntax error**(实测 Git Bash 在场同样复现)。改成把源码经
|
|
946
|
+
// stdin 喂给 `bash -n`(等价的纯语法检查,且跨平台不依赖路径形态)。
|
|
947
|
+
//
|
|
948
|
+
// bash 不存在时(纯 Windows 无 Git Bash)改为可操作的用法错误(码 2),
|
|
949
|
+
// 而不是把 spawn 失败混同成「脚本有语法错」。
|
|
950
|
+
if (!hasCommand('bash')) {
|
|
951
|
+
emitUsageError('bash not found on PATH — install Git Bash (or WSL) to lint shell glue, or pass --language to check another runtime');
|
|
952
|
+
}
|
|
953
|
+
const r = spawnSync('bash', ['-n'], { input: source, stdio: 'pipe' });
|
|
582
954
|
if (r.status !== 0) {
|
|
583
955
|
console.error(chalk.red(`✗ ${file}: syntax error`));
|
|
584
956
|
process.stderr.write(r.stderr?.toString() ?? '');
|
|
@@ -589,7 +961,7 @@ export function tasksCommand() {
|
|
|
589
961
|
});
|
|
590
962
|
return cmd;
|
|
591
963
|
}
|
|
592
|
-
async function pollExecution(execId, waitTimeoutSeconds = 600) {
|
|
964
|
+
async function pollExecution(execId, waitTimeoutSeconds = 600, opts = {}) {
|
|
593
965
|
const INTERVAL = 2000;
|
|
594
966
|
const MAX_WAIT = waitTimeoutSeconds * 1000;
|
|
595
967
|
const spinner = ora('Waiting for execution…').start();
|
|
@@ -601,6 +973,21 @@ async function pollExecution(execId, waitTimeoutSeconds = 600) {
|
|
|
601
973
|
// killed 是后端 ExecutionStatus 的合法终态(acf task kill / Web 端),
|
|
602
974
|
// 遗漏会让 --wait 在被 kill 后空转到 MAX_WAIT 并误报超时(N10)。
|
|
603
975
|
if (['success', 'failed', 'timeout', 'cancelled', 'killed'].includes(exec.status)) {
|
|
976
|
+
if (opts.json) {
|
|
977
|
+
// P2(CLI-AGENT-UX-AUDIT):--json --wait 的唯一 stdout 出口 ——
|
|
978
|
+
// 最终 execution 对象(含 status/exitCode/failureReason/errorMessage/
|
|
979
|
+
// aiAnalysis),不再混入人类可读行。细节走 stderr 便于人眼旁读。
|
|
980
|
+
spinner.stop();
|
|
981
|
+
console.log(JSON.stringify(exec, null, 2));
|
|
982
|
+
if (exec.status !== 'success') {
|
|
983
|
+
process.stderr.write(chalk.yellow(`Execution ${exec.status}` +
|
|
984
|
+
(exec.failureReason ? ` (${exec.failureReason})` : '') +
|
|
985
|
+
'\n'));
|
|
986
|
+
}
|
|
987
|
+
if (exec.status !== 'success')
|
|
988
|
+
process.exitCode = 1;
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
604
991
|
if (exec.status === 'success') {
|
|
605
992
|
spinner.succeed(`Execution ${exec.status} in ${exec.duration ?? '?'}ms`);
|
|
606
993
|
}
|
|
@@ -624,6 +1011,10 @@ async function pollExecution(execId, waitTimeoutSeconds = 600) {
|
|
|
624
1011
|
}
|
|
625
1012
|
if (exec.failureReason) {
|
|
626
1013
|
console.log(chalk.yellow(' Failure reason :'), exec.failureReason);
|
|
1014
|
+
// 可操作建议:failureReason 是机器枚举,直接给"下一步怎么做"。
|
|
1015
|
+
const hint = FAILURE_REASON_HINTS[exec.failureReason];
|
|
1016
|
+
if (hint)
|
|
1017
|
+
console.log(chalk.yellow(' Suggestion :'), hint);
|
|
627
1018
|
}
|
|
628
1019
|
if (exec.errorMessage) {
|
|
629
1020
|
console.log(chalk.yellow(' Error :'), exec.errorMessage);
|
|
@@ -654,6 +1045,14 @@ async function pollExecution(execId, waitTimeoutSeconds = 600) {
|
|
|
654
1045
|
// 与上方失败终态的 CLI-EXIT-01 语义对齐:置 exitCode=1,并明示执行仍在
|
|
655
1046
|
// 运行、如何继续观察(exec tail)或放宽等待上限(--wait-timeout)。
|
|
656
1047
|
spinner.fail(`Timed out waiting for execution after ${waitTimeoutSeconds}s`);
|
|
1048
|
+
if (opts.json) {
|
|
1049
|
+
// --json 下超时也只留 stderr:stdout 要么是干净的最终 JSON,要么什么都没有
|
|
1050
|
+
// (此处确实没有终态可输出——超时意味着没有终态)。
|
|
1051
|
+
process.stderr.write(chalk.red(`The execution is still running — no terminal status within ${waitTimeoutSeconds}s. ` +
|
|
1052
|
+
`Follow it later with 'acf exec tail ${execId}' or raise --wait-timeout.\n`));
|
|
1053
|
+
process.exitCode = 1;
|
|
1054
|
+
return;
|
|
1055
|
+
}
|
|
657
1056
|
console.error(chalk.red(`The execution is still running — no terminal status within ${waitTimeoutSeconds}s. ` +
|
|
658
1057
|
`Follow it later with 'acf exec tail ${execId}' or raise --wait-timeout.`));
|
|
659
1058
|
process.exitCode = 1;
|
|
@@ -661,3 +1060,16 @@ async function pollExecution(execId, waitTimeoutSeconds = 600) {
|
|
|
661
1060
|
function sleep(ms) {
|
|
662
1061
|
return new Promise((r) => setTimeout(r, ms));
|
|
663
1062
|
}
|
|
1063
|
+
/**
|
|
1064
|
+
* 探测可执行文件是否在 PATH 上(`task lint` 的 shell 分支用)。
|
|
1065
|
+
* 用 `--version` 的成功退出码判定,`stdio: 'ignore'` 避免污染 lint 的输出;
|
|
1066
|
+
* 探测本身的失败(ENOENT)也统一归为「不可用」。
|
|
1067
|
+
*/
|
|
1068
|
+
function hasCommand(bin) {
|
|
1069
|
+
try {
|
|
1070
|
+
return spawnSync(bin, ['--version'], { stdio: 'ignore' }).status === 0;
|
|
1071
|
+
}
|
|
1072
|
+
catch {
|
|
1073
|
+
return false;
|
|
1074
|
+
}
|
|
1075
|
+
}
|