@autocodeflow/cli 1.9.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/README.md +46 -3
- package/dist/commands/apps.js +130 -30
- 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 +41 -0
- package/dist/commands/login.js +139 -5
- package/dist/commands/tasks.d.ts +10 -0
- package/dist/commands/tasks.js +142 -33
- package/dist/config.d.ts +10 -1
- package/dist/config.js +22 -5
- package/dist/help.js +35 -7
- package/dist/index.js +43 -4
- package/dist/ui.d.ts +25 -0
- package/dist/ui.js +48 -0
- package/package.json +1 -1
package/dist/commands/login.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import * as readline from 'readline';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import ora from 'ora';
|
|
4
|
+
import axios from 'axios';
|
|
5
|
+
import { post, get, resetClient } from '../client.js';
|
|
6
|
+
import { setApiUrl, setToken, setRefreshToken, showConfig, getApiUrl, clearAuth } from '../config.js';
|
|
5
7
|
import { emitError, interruptExit, UsageError } from '../ui.js';
|
|
6
8
|
import chalk from 'chalk';
|
|
7
9
|
function prompt(question) {
|
|
@@ -36,6 +38,10 @@ export function maskEcho(rl, isTTY = process.stdin.isTTY === true) {
|
|
|
36
38
|
return '';
|
|
37
39
|
};
|
|
38
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* 交互式密码输入(回显遮蔽)。非交互路径不再走这里——由 promptOrFail 在
|
|
43
|
+
* 更外层拦下并提示改用 ACF_PASSWORD(见 login action 的 password 分支)。
|
|
44
|
+
*/
|
|
39
45
|
function hiddenPrompt(question) {
|
|
40
46
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
41
47
|
// 同上:raw 模式 Ctrl+C 显式接住,避免密码输入中 Ctrl+C 假死。
|
|
@@ -46,6 +52,34 @@ function hiddenPrompt(question) {
|
|
|
46
52
|
resolve(ans);
|
|
47
53
|
}));
|
|
48
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* P0(CLI-AGENT-UX-AUDIT):登录地址解析的单一事实源(导出供单测)。
|
|
57
|
+
*
|
|
58
|
+
* 优先级:显式 `--url` > `ACF_API_URL` env > 已存配置 > 内置默认值。
|
|
59
|
+
* 前两者与磁盘配置都由 getApiUrl() 归一(其自身就是 env || store),
|
|
60
|
+
* 因此这里只需在「显式 --url」与「其余」之间分流。
|
|
61
|
+
*
|
|
62
|
+
* 关键点:**不再对地址发交互 prompt**。地址有合理默认值,为它中断整条登录
|
|
63
|
+
* 在自动化面只会制造困惑(旧行为下 agent 会拿到空串兜底的默认地址 + 假 exit 0)。
|
|
64
|
+
*/
|
|
65
|
+
export function resolveLoginUrl(explicit) {
|
|
66
|
+
return explicit?.trim() || getApiUrl() || 'http://localhost:3105';
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* P0(CLI-AGENT-UX-AUDIT):非交互下需要人工输入时给出**可操作**的用法错误,
|
|
70
|
+
* 而不是让 prompt 拿到 EOF 空串后静默继续。契约与 resolveTotpCode 的
|
|
71
|
+
* 「stdin 非交互且缺 --code」分支完全一致(UsageError → 退出码 2)。
|
|
72
|
+
*
|
|
73
|
+
* @param question 交互提示语
|
|
74
|
+
* @param alternative 非交互时应改用的旗标/环境变量(写进错误消息)
|
|
75
|
+
*/
|
|
76
|
+
export async function promptOrFail(question, alternative, promptFn = prompt) {
|
|
77
|
+
if (process.stdin.isTTY !== true) {
|
|
78
|
+
throw new UsageError(`Cannot prompt for "${question.trim()}" — stdin is not interactive. ` +
|
|
79
|
+
`Provide it with ${alternative} instead (required for CI / agent use).`);
|
|
80
|
+
}
|
|
81
|
+
return promptFn(question);
|
|
82
|
+
}
|
|
49
83
|
// 6 位码形态校验(TOTP 契约:HMAC-SHA1/6 位数字)。本地只判「形态」,
|
|
50
84
|
// 码对不对由服务端 /auth/totp/verify 判(错码 → 401 → 退出码 3)。
|
|
51
85
|
function assertTotpCodeFormat(code, source) {
|
|
@@ -92,20 +126,39 @@ export function loginCommand() {
|
|
|
92
126
|
.option('--code <code>', '6-digit TOTP code (second factor). Required in non-interactive sessions when the account has TOTP enabled')
|
|
93
127
|
.action(async (opts) => {
|
|
94
128
|
try {
|
|
95
|
-
|
|
129
|
+
// P0(CLI-AGENT-UX-AUDIT):URL 解析优先级此前是 `--url || prompt`——
|
|
130
|
+
// 只要没传 --url 就一定发问,即便 ACF_API_URL / 磁盘配置已经给了地址。
|
|
131
|
+
// stdin 非交互(agent / CI / `< NUL`)时 prompt 拿到空串、被
|
|
132
|
+
// `|| 'http://localhost:3105'` 兜底,后续 username/password 同样问不出来,
|
|
133
|
+
// 进程在某个 prompt 处静默 exit 0——**agent 以为自己登录成功了**,而
|
|
134
|
+
// 落盘的 token 是空的,错误被推迟到下一个命令的 401 才暴露。
|
|
135
|
+
//
|
|
136
|
+
// 收敛为纯函数(可单测):显式 --url > ACF_API_URL > 已存配置 > 默认值。
|
|
137
|
+
// 只有四者都拿不到「非默认」地址、且 stdin 是 TTY 时才会问人;非 TTY
|
|
138
|
+
// 一律用默认值继续(地址本就有合理默认,不该因为它中断整条登录)。
|
|
139
|
+
const url = resolveLoginUrl(opts.url);
|
|
96
140
|
setApiUrl(url.trim());
|
|
97
141
|
resetClient();
|
|
98
|
-
|
|
142
|
+
// 非交互下 username 无法发问:此时必须由 --user 提供,否则可操作报错
|
|
143
|
+
// (与 TOTP 的 --code 同款契约),不再静默拿到空用户名。
|
|
144
|
+
const username = opts.user || (await promptOrFail('Username: ', '--user <username>'));
|
|
99
145
|
// PK-27 凭据来源优先级:--password(deprecated,告警) > ACF_PASSWORD env > 隐藏交互 prompt。
|
|
100
146
|
let password;
|
|
101
147
|
if (opts.password) {
|
|
102
|
-
process.stderr.write(chalk.yellow('⚠ --password
|
|
148
|
+
process.stderr.write(chalk.yellow('⚠ --password is visible in the process list and shell history — prefer ACF_PASSWORD env in CI.\n'));
|
|
103
149
|
password = opts.password;
|
|
104
150
|
}
|
|
105
151
|
else if (process.env.ACF_PASSWORD) {
|
|
106
152
|
password = process.env.ACF_PASSWORD;
|
|
107
153
|
}
|
|
108
154
|
else {
|
|
155
|
+
// 非交互下必须走 ACF_PASSWORD env(不进 argv、不落 shell history),
|
|
156
|
+
// 不能退化成「问不出来就空密码发一次必然 401 的请求」。
|
|
157
|
+
// 交互路径继续用 hiddenPrompt —— PK-27 的回显遮蔽不能因这次改造丢掉。
|
|
158
|
+
if (process.stdin.isTTY !== true) {
|
|
159
|
+
throw new UsageError('Cannot prompt for the password — stdin is not interactive. ' +
|
|
160
|
+
'Provide it with the ACF_PASSWORD environment variable instead (required for CI / agent use).');
|
|
161
|
+
}
|
|
109
162
|
password = await hiddenPrompt('Password: ');
|
|
110
163
|
}
|
|
111
164
|
// --code 形态本地预检(在发起任何网络请求之前):坏格式直接报用法错误,
|
|
@@ -153,3 +206,84 @@ export function loginCommand() {
|
|
|
153
206
|
});
|
|
154
207
|
return cmd;
|
|
155
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* P1(CLI-AGENT-UX-AUDIT):`acf whoami` —— 打印当前凭据的身份与角色。
|
|
211
|
+
*
|
|
212
|
+
* 为什么 agent 需要它:后端有大量 ADMIN-only 面(audit / sop / notification /
|
|
213
|
+
* agent / executor-packages 全模块,以及所有应用写操作)。此前 agent 无法在
|
|
214
|
+
* 开工前自检权限,只能靠「调用 → 403」逐个试错。profile 返回的是 AuthUser,
|
|
215
|
+
* 其中 `role` 是**单值**(不是 roles 数组),ADMIN 判定按此单值。
|
|
216
|
+
*/
|
|
217
|
+
export function whoamiCommand() {
|
|
218
|
+
return new Command('whoami')
|
|
219
|
+
.description('Show the identity and role behind the current credential (preflight before ADMIN-only commands)')
|
|
220
|
+
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
221
|
+
.action(async (opts) => {
|
|
222
|
+
const spinner = ora('Fetching profile…').start();
|
|
223
|
+
try {
|
|
224
|
+
const me = await get('/auth/profile');
|
|
225
|
+
spinner.stop();
|
|
226
|
+
if (opts.json) {
|
|
227
|
+
console.log(JSON.stringify(me, null, 2));
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const isAdmin = me?.role === 'admin' || me?.role === 'ADMIN';
|
|
231
|
+
console.log(chalk.bold('Current identity'));
|
|
232
|
+
console.log(' Username :', me?.username ?? '-');
|
|
233
|
+
console.log(' User ID :', me?.id ?? '-');
|
|
234
|
+
console.log(' Role :', isAdmin ? chalk.yellow(me?.role) : (me?.role ?? '-'));
|
|
235
|
+
console.log(' Email :', me?.email ?? '-');
|
|
236
|
+
console.log(' API URL :', getApiUrl());
|
|
237
|
+
if (!isAdmin) {
|
|
238
|
+
console.log(chalk.gray(' (not an ADMIN — audit / sop / notification / agent / executor-packages and application writes will answer 403)'));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
catch (e) {
|
|
242
|
+
emitError('Failed to fetch profile', e, { spinner });
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* P1(CLI-AGENT-UX-AUDIT):`acf logout` —— 服务端吊销 refresh token 家族的
|
|
248
|
+
* 同时清空本地凭据。
|
|
249
|
+
*
|
|
250
|
+
* 为什么 agent 需要它:access + refresh **双 token** 都落在磁盘 0600 文件里,
|
|
251
|
+
* refresh 是长效的。共享机器 / 一次性容器上跑完不清,等于把一枚长效凭证留在
|
|
252
|
+
* 盘上。此前面只有「再 login 一次覆盖」,没有出口。
|
|
253
|
+
*
|
|
254
|
+
* 语义:先尽力通知服务端(revoke all refresh tokens),**网络失败也照常清本地**
|
|
255
|
+
* ——本地凭据必须确保被抹掉,不能因为服务端不可达就把 token 留在盘上。
|
|
256
|
+
*/
|
|
257
|
+
export function logoutCommand() {
|
|
258
|
+
return new Command('logout')
|
|
259
|
+
.description('Revoke the session server-side and clear the locally stored credentials')
|
|
260
|
+
.action(async () => {
|
|
261
|
+
// ⚠ 顺序至关重要:client 的请求拦截器是**逐请求**读 token 的
|
|
262
|
+
//(client.ts request interceptor → getToken()),所以必须先带着 token
|
|
263
|
+
// 完成服务端吊销,**再**清本地。反过来(先 clearAuth 再 POST)会让注销
|
|
264
|
+
// 请求不带 Authorization 头 → 必然 401 → 服务端吊销实际从未发生。
|
|
265
|
+
let warned = false;
|
|
266
|
+
try {
|
|
267
|
+
// POST /auth/logout —— 吊销该用户的全部 refresh token(服务端语义)。
|
|
268
|
+
await post('/auth/logout');
|
|
269
|
+
}
|
|
270
|
+
catch (e) {
|
|
271
|
+
// 401 = 本来就没登录 / token 已失效,没有可吊销的会话,属正常收尾,
|
|
272
|
+
// 不打扰用户。其余(网络不可达 / 5xx)才值得告警——注意此时本地凭据
|
|
273
|
+
// **仍然会被清掉**(下方 finally),不能因为服务端不可达就把 token 留盘。
|
|
274
|
+
const status = axios.isAxiosError(e) ? e.response?.status : undefined;
|
|
275
|
+
if (status !== 401) {
|
|
276
|
+
warned = true;
|
|
277
|
+
process.stderr.write(chalk.yellow('⚠ Could not reach the API to revoke the session server-side (the access token may remain valid until it expires) — local credentials were still cleared.\n'));
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
finally {
|
|
281
|
+
// 无论服务端结果如何,盘上的凭据都必须抹掉。
|
|
282
|
+
clearAuth();
|
|
283
|
+
}
|
|
284
|
+
if (!warned)
|
|
285
|
+
console.log(chalk.green('✔ Logged out — local credentials cleared'));
|
|
286
|
+
else
|
|
287
|
+
console.log(chalk.green('✔ Local credentials cleared'));
|
|
288
|
+
});
|
|
289
|
+
}
|
package/dist/commands/tasks.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* 结构化失败原因(failureReason,执行器回调上报)→ 可直接照做的建议。
|
|
4
|
+
*
|
|
5
|
+
* 2026-10 开发人员实测:任务声明 runtimeVersion=3.12 派到无该解释器的执行器
|
|
6
|
+
* 秒失败且执行日志 0 行——failureReason=interpreter_unavailable 只有 --json
|
|
7
|
+
* 里能看到,中文详情还得再查一次文档。把最常见的几个失败原因翻译成"下一步
|
|
8
|
+
* 怎么做",随 `--wait` 的失败终态直接打出来(键集对齐 executor-node
|
|
9
|
+
* protocol.schemas.ts 的 CallbackFailureReason 枚举)。
|
|
10
|
+
*/
|
|
11
|
+
export declare const FAILURE_REASON_HINTS: Record<string, string>;
|
|
2
12
|
/**
|
|
3
13
|
* E-1:`acf task import -` 的 stdin 读取。"-" 是 CI/管道惯例;stdin 是 TTY
|
|
4
14
|
* 时(用户忘了给文件、手敲 `-`)拒绝而不是挂死等待 EOF。流参数可注入——
|
package/dist/commands/tasks.js
CHANGED
|
@@ -7,7 +7,23 @@ import { spawnSync } from 'child_process';
|
|
|
7
7
|
import * as fs from 'fs';
|
|
8
8
|
import * as path from 'path';
|
|
9
9
|
import { get, post, put, patch, del, ANALYZE_TIMEOUT_MS } from '../client.js';
|
|
10
|
-
import { emitError, emitUsageError, UsageError,
|
|
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
|
+
};
|
|
11
27
|
// P3 glue:执行器侧运行时白名单(executor-node execute.ts 的 glueLanguage 分支
|
|
12
28
|
// —— javascript/python/shell,另有 glue_node 等旧别名)。注意 node 脚本的合法
|
|
13
29
|
// 值是 `javascript`:发 `node` 执行器会在运行时抛 "Unsupported glue language",
|
|
@@ -63,19 +79,21 @@ export function tasksCommand() {
|
|
|
63
79
|
cmd.command('list')
|
|
64
80
|
.description('List all tasks')
|
|
65
81
|
.option('-s, --status <status>', 'Filter by status (active|paused)')
|
|
66
|
-
.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)')
|
|
67
84
|
.option('-p, --page <n>', 'Page number', '1')
|
|
68
85
|
.option('-n, --page-size <n>', 'Items per page', '20')
|
|
69
86
|
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
70
87
|
.action(async (opts) => {
|
|
71
88
|
const spinner = ora('Fetching tasks…').start();
|
|
72
89
|
try {
|
|
73
|
-
// ListTasksQueryDto
|
|
90
|
+
// ListTasksQueryDto: `name`(按名,向后兼容)+ `q`(name OR description)
|
|
74
91
|
const data = await get('/tasks', {
|
|
75
92
|
page: opts.page,
|
|
76
93
|
pageSize: opts.pageSize,
|
|
77
94
|
status: opts.status,
|
|
78
95
|
name: opts.keyword,
|
|
96
|
+
q: opts.search,
|
|
79
97
|
});
|
|
80
98
|
spinner.stop();
|
|
81
99
|
if (opts.json) {
|
|
@@ -114,11 +132,17 @@ export function tasksCommand() {
|
|
|
114
132
|
return;
|
|
115
133
|
}
|
|
116
134
|
console.log(chalk.bold('Task Details'));
|
|
117
|
-
console.log(' ID
|
|
118
|
-
console.log(' Name
|
|
119
|
-
console.log(' Runtime
|
|
120
|
-
console.log(' Status
|
|
121
|
-
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')));
|
|
122
146
|
}
|
|
123
147
|
catch (e) {
|
|
124
148
|
emitError('Failed', e, { spinner });
|
|
@@ -126,7 +150,7 @@ export function tasksCommand() {
|
|
|
126
150
|
});
|
|
127
151
|
// acf task trigger <id>
|
|
128
152
|
cmd.command('trigger <id>')
|
|
129
|
-
.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')
|
|
130
154
|
.option('--wait', 'Poll until execution finishes', false)
|
|
131
155
|
// NETOPT-2①: --wait 的轮询上限可调(秒)。默认 600 保持既有行为;
|
|
132
156
|
// 非正值直接报参数错误而不是静默回落默认值——CI 里写错单位(毫秒当秒)
|
|
@@ -143,24 +167,49 @@ export function tasksCommand() {
|
|
|
143
167
|
// per-trigger pin would be rejected with 400. Executor pinning IS
|
|
144
168
|
// supported by the backend as a task-level field (tasks.executorId) — set
|
|
145
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)')
|
|
146
174
|
// 第四轮审计(--json 补面):trigger 响应(execution 对象)直出 JSON,
|
|
147
175
|
// CI 拿 executionId 做后续断言无需解析人读文本。
|
|
148
176
|
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
149
177
|
.action(async (id, opts) => {
|
|
150
178
|
const spinner = ora('Triggering task…').start();
|
|
151
179
|
try {
|
|
152
|
-
|
|
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`);
|
|
153
194
|
if (opts.json) {
|
|
154
|
-
// ECO-02 同款:--json —— ora 默认写 stderr,stdout 仍是干净 JSON
|
|
155
|
-
// --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 解析器必崩。
|
|
156
200
|
spinner.stop();
|
|
157
|
-
|
|
201
|
+
if (!opts.wait) {
|
|
202
|
+
console.log(JSON.stringify(exec, null, 2));
|
|
203
|
+
}
|
|
158
204
|
}
|
|
159
205
|
else {
|
|
160
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
|
+
}
|
|
161
210
|
}
|
|
162
211
|
if (opts.wait) {
|
|
163
|
-
await pollExecution(exec.id, opts.waitTimeout);
|
|
212
|
+
await pollExecution(exec.id, opts.waitTimeout, { json: !!opts.json });
|
|
164
213
|
}
|
|
165
214
|
}
|
|
166
215
|
catch (e) {
|
|
@@ -191,8 +240,11 @@ export function tasksCommand() {
|
|
|
191
240
|
const table = new Table({
|
|
192
241
|
// U11: exitCode column — distinguishes "failed by callback
|
|
193
242
|
// report" (exit 0 / null) from "process died" (non-zero).
|
|
194
|
-
|
|
195
|
-
|
|
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],
|
|
196
248
|
style: { head: ['cyan'] },
|
|
197
249
|
});
|
|
198
250
|
for (const e of data.list ?? []) {
|
|
@@ -201,6 +253,7 @@ export function tasksCommand() {
|
|
|
201
253
|
statusColor(e.status),
|
|
202
254
|
e.duration ? `${e.duration}ms` : '-',
|
|
203
255
|
e.exitCode ?? '-',
|
|
256
|
+
e.failureReason ?? '-',
|
|
204
257
|
new Date(e.createdAt).toLocaleString(),
|
|
205
258
|
]);
|
|
206
259
|
}
|
|
@@ -512,18 +565,9 @@ export function tasksCommand() {
|
|
|
512
565
|
.description('Delete a task (force-terminates running executions)')
|
|
513
566
|
.option('-y, --yes', 'Skip confirmation prompt', false)
|
|
514
567
|
.action(async (id, opts) => {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
// raw 模式下 Ctrl+C 触发 rl 'SIGINT' 而非进程信号;无监听只会 pause,
|
|
519
|
-
// 确认提示处会假死。接住并走统一中断出口(130)。
|
|
520
|
-
rl.on('SIGINT', () => interruptExit());
|
|
521
|
-
const answer = await rl.question(`Delete task ${id}? Running executions will be force-terminated. [y/N] `);
|
|
522
|
-
rl.close();
|
|
523
|
-
if (!/^y(es)?$/i.test(answer)) {
|
|
524
|
-
console.log(chalk.yellow('Aborted.'));
|
|
525
|
-
return;
|
|
526
|
-
}
|
|
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;
|
|
527
571
|
}
|
|
528
572
|
const spinner = ora('Deleting task…').start();
|
|
529
573
|
try {
|
|
@@ -633,6 +677,7 @@ export function tasksCommand() {
|
|
|
633
677
|
.description('Batch trigger/pause/resume/delete tasks (partial failures do not affect the other tasks)')
|
|
634
678
|
.option('--ids <ids>', 'Comma-separated task IDs (merged with any positional ids, deduplicated)')
|
|
635
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)
|
|
636
681
|
.action(async (action, ids, opts) => {
|
|
637
682
|
const ACTIONS = ['trigger', 'pause', 'resume', 'delete'];
|
|
638
683
|
if (!ACTIONS.includes(action)) {
|
|
@@ -650,6 +695,15 @@ export function tasksCommand() {
|
|
|
650
695
|
if (taskIds.length > 500) {
|
|
651
696
|
emitUsageError(`Batch is limited to 500 task IDs per request (got ${taskIds.length})`);
|
|
652
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
|
+
}
|
|
653
707
|
const spinner = ora(`Batch ${action} (${taskIds.length} task(s))…`).start();
|
|
654
708
|
try {
|
|
655
709
|
// Promise.all 保序:results[i] 对应 taskIds[i](失败项为 { id, error })。
|
|
@@ -867,10 +921,14 @@ export function tasksCommand() {
|
|
|
867
921
|
return r.status === 0;
|
|
868
922
|
});
|
|
869
923
|
if (!py) {
|
|
870
|
-
|
|
871
|
-
|
|
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)');
|
|
872
927
|
}
|
|
873
|
-
|
|
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,
|
|
874
932
|
stdio: 'pipe',
|
|
875
933
|
});
|
|
876
934
|
if (r.status !== 0) {
|
|
@@ -881,7 +939,18 @@ export function tasksCommand() {
|
|
|
881
939
|
ok('syntax OK (python, ast.parse)');
|
|
882
940
|
}
|
|
883
941
|
else {
|
|
884
|
-
|
|
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' });
|
|
885
954
|
if (r.status !== 0) {
|
|
886
955
|
console.error(chalk.red(`✗ ${file}: syntax error`));
|
|
887
956
|
process.stderr.write(r.stderr?.toString() ?? '');
|
|
@@ -892,7 +961,7 @@ export function tasksCommand() {
|
|
|
892
961
|
});
|
|
893
962
|
return cmd;
|
|
894
963
|
}
|
|
895
|
-
async function pollExecution(execId, waitTimeoutSeconds = 600) {
|
|
964
|
+
async function pollExecution(execId, waitTimeoutSeconds = 600, opts = {}) {
|
|
896
965
|
const INTERVAL = 2000;
|
|
897
966
|
const MAX_WAIT = waitTimeoutSeconds * 1000;
|
|
898
967
|
const spinner = ora('Waiting for execution…').start();
|
|
@@ -904,6 +973,21 @@ async function pollExecution(execId, waitTimeoutSeconds = 600) {
|
|
|
904
973
|
// killed 是后端 ExecutionStatus 的合法终态(acf task kill / Web 端),
|
|
905
974
|
// 遗漏会让 --wait 在被 kill 后空转到 MAX_WAIT 并误报超时(N10)。
|
|
906
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
|
+
}
|
|
907
991
|
if (exec.status === 'success') {
|
|
908
992
|
spinner.succeed(`Execution ${exec.status} in ${exec.duration ?? '?'}ms`);
|
|
909
993
|
}
|
|
@@ -927,6 +1011,10 @@ async function pollExecution(execId, waitTimeoutSeconds = 600) {
|
|
|
927
1011
|
}
|
|
928
1012
|
if (exec.failureReason) {
|
|
929
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);
|
|
930
1018
|
}
|
|
931
1019
|
if (exec.errorMessage) {
|
|
932
1020
|
console.log(chalk.yellow(' Error :'), exec.errorMessage);
|
|
@@ -957,6 +1045,14 @@ async function pollExecution(execId, waitTimeoutSeconds = 600) {
|
|
|
957
1045
|
// 与上方失败终态的 CLI-EXIT-01 语义对齐:置 exitCode=1,并明示执行仍在
|
|
958
1046
|
// 运行、如何继续观察(exec tail)或放宽等待上限(--wait-timeout)。
|
|
959
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
|
+
}
|
|
960
1056
|
console.error(chalk.red(`The execution is still running — no terminal status within ${waitTimeoutSeconds}s. ` +
|
|
961
1057
|
`Follow it later with 'acf exec tail ${execId}' or raise --wait-timeout.`));
|
|
962
1058
|
process.exitCode = 1;
|
|
@@ -964,3 +1060,16 @@ async function pollExecution(execId, waitTimeoutSeconds = 600) {
|
|
|
964
1060
|
function sleep(ms) {
|
|
965
1061
|
return new Promise((r) => setTimeout(r, ms));
|
|
966
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
|
+
}
|
package/dist/config.d.ts
CHANGED
|
@@ -24,4 +24,13 @@ export declare function setRefreshToken(token: string): void;
|
|
|
24
24
|
* apiUrl 保留(用户环境不丢)。
|
|
25
25
|
*/
|
|
26
26
|
export declare function clearAuth(): void;
|
|
27
|
-
|
|
27
|
+
/**
|
|
28
|
+
* 打印当前配置。
|
|
29
|
+
*
|
|
30
|
+
* `--json`(P2,CLI-AGENT-UX-AUDIT):agent 排障第一步就是读当前配置,
|
|
31
|
+
* 而此前只能 grep 人读文本。**token 永不明文输出**——只给 set/not set,
|
|
32
|
+
* 与既有 `[set]` 口径一致(凭据本身在文件里,不该顺带打到日志/终端)。
|
|
33
|
+
*/
|
|
34
|
+
export declare function showConfig(opts?: {
|
|
35
|
+
json?: boolean;
|
|
36
|
+
}): void;
|
package/dist/config.js
CHANGED
|
@@ -176,9 +176,26 @@ export function clearAuth() {
|
|
|
176
176
|
store.set('token', '');
|
|
177
177
|
store.set('refreshToken', '');
|
|
178
178
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
179
|
+
/**
|
|
180
|
+
* 打印当前配置。
|
|
181
|
+
*
|
|
182
|
+
* `--json`(P2,CLI-AGENT-UX-AUDIT):agent 排障第一步就是读当前配置,
|
|
183
|
+
* 而此前只能 grep 人读文本。**token 永不明文输出**——只给 set/not set,
|
|
184
|
+
* 与既有 `[set]` 口径一致(凭据本身在文件里,不该顺带打到日志/终端)。
|
|
185
|
+
*/
|
|
186
|
+
export function showConfig(opts = {}) {
|
|
187
|
+
const snapshot = {
|
|
188
|
+
apiUrl: getApiUrl(),
|
|
189
|
+
token: getToken() ? '[set]' : '[not set]',
|
|
190
|
+
refreshToken: getRefreshToken() ? '[set]' : '[not set]',
|
|
191
|
+
configFile: store.path,
|
|
192
|
+
};
|
|
193
|
+
if (opts.json) {
|
|
194
|
+
console.log(JSON.stringify(snapshot));
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
console.log('API URL :', snapshot.apiUrl);
|
|
198
|
+
console.log('Token :', snapshot.token);
|
|
199
|
+
console.log('Refresh :', snapshot.refreshToken);
|
|
200
|
+
console.log('Config file:', snapshot.configFile);
|
|
184
201
|
}
|