@autocodeflow/cli 1.9.0 → 1.10.0
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 +71 -3
- package/dist/client.d.ts +11 -1
- package/dist/client.js +12 -2
- package/dist/commands/apps.js +135 -32
- 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/mutex.d.ts +2 -0
- package/dist/commands/mutex.js +194 -0
- 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 +52 -7
- package/dist/index.js +45 -4
- package/dist/ui.d.ts +25 -0
- package/dist/ui.js +48 -0
- package/package.json +1 -1
package/dist/commands/login.d.ts
CHANGED
|
@@ -1,7 +1,48 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import * as readline from 'readline';
|
|
3
3
|
export declare function maskEcho(rl: readline.Interface, isTTY?: boolean): void;
|
|
4
|
+
/**
|
|
5
|
+
* P0(CLI-AGENT-UX-AUDIT):登录地址解析的单一事实源(导出供单测)。
|
|
6
|
+
*
|
|
7
|
+
* 优先级:显式 `--url` > `ACF_API_URL` env > 已存配置 > 内置默认值。
|
|
8
|
+
* 前两者与磁盘配置都由 getApiUrl() 归一(其自身就是 env || store),
|
|
9
|
+
* 因此这里只需在「显式 --url」与「其余」之间分流。
|
|
10
|
+
*
|
|
11
|
+
* 关键点:**不再对地址发交互 prompt**。地址有合理默认值,为它中断整条登录
|
|
12
|
+
* 在自动化面只会制造困惑(旧行为下 agent 会拿到空串兜底的默认地址 + 假 exit 0)。
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveLoginUrl(explicit?: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* P0(CLI-AGENT-UX-AUDIT):非交互下需要人工输入时给出**可操作**的用法错误,
|
|
17
|
+
* 而不是让 prompt 拿到 EOF 空串后静默继续。契约与 resolveTotpCode 的
|
|
18
|
+
* 「stdin 非交互且缺 --code」分支完全一致(UsageError → 退出码 2)。
|
|
19
|
+
*
|
|
20
|
+
* @param question 交互提示语
|
|
21
|
+
* @param alternative 非交互时应改用的旗标/环境变量(写进错误消息)
|
|
22
|
+
*/
|
|
23
|
+
export declare function promptOrFail(question: string, alternative: string, promptFn?: (question: string) => Promise<string>): Promise<string>;
|
|
4
24
|
export declare function resolveTotpCode(opts: {
|
|
5
25
|
code?: string;
|
|
6
26
|
}, promptFn?: (question: string) => Promise<string>): Promise<string>;
|
|
7
27
|
export declare function loginCommand(): Command;
|
|
28
|
+
/**
|
|
29
|
+
* P1(CLI-AGENT-UX-AUDIT):`acf whoami` —— 打印当前凭据的身份与角色。
|
|
30
|
+
*
|
|
31
|
+
* 为什么 agent 需要它:后端有大量 ADMIN-only 面(audit / sop / notification /
|
|
32
|
+
* agent / executor-packages 全模块,以及所有应用写操作)。此前 agent 无法在
|
|
33
|
+
* 开工前自检权限,只能靠「调用 → 403」逐个试错。profile 返回的是 AuthUser,
|
|
34
|
+
* 其中 `role` 是**单值**(不是 roles 数组),ADMIN 判定按此单值。
|
|
35
|
+
*/
|
|
36
|
+
export declare function whoamiCommand(): Command;
|
|
37
|
+
/**
|
|
38
|
+
* P1(CLI-AGENT-UX-AUDIT):`acf logout` —— 服务端吊销 refresh token 家族的
|
|
39
|
+
* 同时清空本地凭据。
|
|
40
|
+
*
|
|
41
|
+
* 为什么 agent 需要它:access + refresh **双 token** 都落在磁盘 0600 文件里,
|
|
42
|
+
* refresh 是长效的。共享机器 / 一次性容器上跑完不清,等于把一枚长效凭证留在
|
|
43
|
+
* 盘上。此前面只有「再 login 一次覆盖」,没有出口。
|
|
44
|
+
*
|
|
45
|
+
* 语义:先尽力通知服务端(revoke all refresh tokens),**网络失败也照常清本地**
|
|
46
|
+
* ——本地凭据必须确保被抹掉,不能因为服务端不可达就把 token 留在盘上。
|
|
47
|
+
*/
|
|
48
|
+
export declare function logoutCommand(): Command;
|
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
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { Command, InvalidArgumentError } from 'commander';
|
|
2
|
+
import Table from 'cli-table3';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import ora from 'ora';
|
|
5
|
+
import { get, post, put, del } from '../client.js';
|
|
6
|
+
import { emitError, emitUsageError, confirmDestructive } from '../ui.js';
|
|
7
|
+
/**
|
|
8
|
+
* 组作用域(后端 MUTEX_GROUP_SCOPES 的镜像)。本地预检只为报错快一点,
|
|
9
|
+
* 服务端 @IsIn 仍是权威;与 apikeys.ts 的 SCOPES 同一纪律。
|
|
10
|
+
*/
|
|
11
|
+
const SCOPES = ['device', 'global'];
|
|
12
|
+
/** 组内并发上界(后端 MUTEX_GROUP_MAX_CONCURRENT_CEILING 的镜像)。 */
|
|
13
|
+
const MAX_CONCURRENT_CEILING = 100;
|
|
14
|
+
/** `--scope` 解析:非法值在 commander 层就报错(退出码 2),不发请求。 */
|
|
15
|
+
function parseScope(v) {
|
|
16
|
+
if (!SCOPES.includes(v)) {
|
|
17
|
+
throw new InvalidArgumentError(`must be one of: ${SCOPES.join(' | ')}`);
|
|
18
|
+
}
|
|
19
|
+
return v;
|
|
20
|
+
}
|
|
21
|
+
/** `--max-concurrent` 解析:1..100 的整数(与后端 @Min/@Max 同界)。 */
|
|
22
|
+
function parseMaxConcurrent(v) {
|
|
23
|
+
const n = Number.parseInt(v, 10);
|
|
24
|
+
if (!Number.isInteger(n) || n < 1 || n > MAX_CONCURRENT_CEILING) {
|
|
25
|
+
throw new InvalidArgumentError(`must be an integer between 1 and ${MAX_CONCURRENT_CEILING}`);
|
|
26
|
+
}
|
|
27
|
+
return n;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* scope 的人类可读注解。两种作用域的语义差别很大(一个管单机串行、一个管
|
|
31
|
+
* 全平台单点登录顶号),只打 "device"/"global" 用户看不懂,故列表里带注解。
|
|
32
|
+
*/
|
|
33
|
+
function scopeText(scope) {
|
|
34
|
+
if (scope === 'global')
|
|
35
|
+
return chalk.yellow('global') + chalk.gray(' (全平台串行)');
|
|
36
|
+
if (scope === 'device')
|
|
37
|
+
return chalk.cyan('device') + chalk.gray(' (单机串行)');
|
|
38
|
+
return scope;
|
|
39
|
+
}
|
|
40
|
+
export function mutexCommand() {
|
|
41
|
+
const cmd = new Command('mutex').description('Manage application mutex groups (apps in one group never run concurrently on the same device)');
|
|
42
|
+
// acf mutex list
|
|
43
|
+
cmd
|
|
44
|
+
.command('list')
|
|
45
|
+
.description('List mutex groups (the same options the console shows in the app form dropdown)')
|
|
46
|
+
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
47
|
+
.action(async (opts) => {
|
|
48
|
+
const spinner = ora('Fetching mutex groups…').start();
|
|
49
|
+
try {
|
|
50
|
+
const groups = await get('/mutex-groups');
|
|
51
|
+
spinner.stop();
|
|
52
|
+
if (opts.json) {
|
|
53
|
+
console.log(JSON.stringify(groups ?? []));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (!groups?.length) {
|
|
57
|
+
console.log(chalk.gray('No mutex groups yet.'));
|
|
58
|
+
console.log(chalk.gray("Create one with: acf mutex create --name <name>"));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const table = new Table({
|
|
62
|
+
head: ['ID', 'Name', 'Max/Device', 'Scope', 'Apps', 'Description'],
|
|
63
|
+
colWidths: [38, 22, 12, 26, 6, 30],
|
|
64
|
+
style: { head: ['cyan'] },
|
|
65
|
+
});
|
|
66
|
+
for (const g of groups) {
|
|
67
|
+
table.push([
|
|
68
|
+
g.id,
|
|
69
|
+
g.name,
|
|
70
|
+
String(g.maxConcurrentPerDevice),
|
|
71
|
+
scopeText(g.scope),
|
|
72
|
+
g.applicationCount === undefined ? '-' : String(g.applicationCount),
|
|
73
|
+
g.description ?? '-',
|
|
74
|
+
]);
|
|
75
|
+
}
|
|
76
|
+
console.log(table.toString());
|
|
77
|
+
console.log(chalk.gray('Attach an app with: acf app update <appId> --body \'{"mutexGroupId":"<ID>"}\''));
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
emitError('Failed to list mutex groups', e, { spinner });
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
// acf mutex create
|
|
84
|
+
cmd
|
|
85
|
+
.command('create')
|
|
86
|
+
.description('Create a mutex group (ADMIN)')
|
|
87
|
+
.requiredOption('--name <name>', 'Group name (unique, max 64 chars)')
|
|
88
|
+
.option('--max-concurrent <n>', `Concurrent runs allowed per device (1-${MAX_CONCURRENT_CEILING}, default 1 = serial)`, parseMaxConcurrent)
|
|
89
|
+
.option('--scope <scope>', 'device = serial per device, cross-device concurrent (default) | global = serial platform-wide (e.g. single-sign-on takeover)', parseScope)
|
|
90
|
+
.option('--description <text>', 'What the group is for (max 500 chars)')
|
|
91
|
+
.option('--json', 'Emit raw JSON (CI-consumable)')
|
|
92
|
+
.action(async (opts) => {
|
|
93
|
+
const spinner = ora('Creating mutex group…').start();
|
|
94
|
+
try {
|
|
95
|
+
// CreateMutexGroupDto 白名单:{ name, maxConcurrentPerDevice?, scope?, description? }。
|
|
96
|
+
// 不发送 undefined 键(forbidNonWhitelisted 下无意义)。
|
|
97
|
+
const body = { name: opts.name };
|
|
98
|
+
if (opts.maxConcurrent !== undefined) {
|
|
99
|
+
body.maxConcurrentPerDevice = opts.maxConcurrent;
|
|
100
|
+
}
|
|
101
|
+
if (opts.scope !== undefined)
|
|
102
|
+
body.scope = opts.scope;
|
|
103
|
+
if (opts.description !== undefined)
|
|
104
|
+
body.description = opts.description;
|
|
105
|
+
const group = await post('/mutex-groups', body);
|
|
106
|
+
spinner.stop();
|
|
107
|
+
if (opts.json) {
|
|
108
|
+
console.log(JSON.stringify(group));
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
console.log(chalk.green(`✔ Mutex group created: ${group.name}`));
|
|
112
|
+
console.log(' ID :', group.id);
|
|
113
|
+
console.log(' Max/Device :', group.maxConcurrentPerDevice);
|
|
114
|
+
console.log(' Scope :', group.scope);
|
|
115
|
+
console.log(chalk.gray(` Attach an app: acf app update <appId> --body '{"mutexGroupId":"${group.id}"}'`));
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
emitError('Failed to create mutex group', e, { spinner });
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
// acf mutex update <id>
|
|
122
|
+
cmd
|
|
123
|
+
.command('update <id>')
|
|
124
|
+
.description('Update a mutex group (name / max-concurrent / scope / description; ADMIN)')
|
|
125
|
+
.option('--name <name>', 'New group name (unique, max 64 chars)')
|
|
126
|
+
.option('--max-concurrent <n>', `New per-device concurrency (1-${MAX_CONCURRENT_CEILING})`, parseMaxConcurrent)
|
|
127
|
+
.option('--scope <scope>', 'New scope: device | global', parseScope)
|
|
128
|
+
.option('--description <text>', 'New description (max 500 chars)')
|
|
129
|
+
.option('--json', 'Emit raw JSON (CI-consumable)')
|
|
130
|
+
.action(async (id, opts) => {
|
|
131
|
+
// 空 patch(一个字段都没给)在服务端的语义是「什么都不改」却仍算成功,
|
|
132
|
+
// 容易被误读为「已生效」。本地拦下并给出可操作提示(退出码 2)。
|
|
133
|
+
if (opts.name === undefined &&
|
|
134
|
+
opts.maxConcurrent === undefined &&
|
|
135
|
+
opts.scope === undefined &&
|
|
136
|
+
opts.description === undefined) {
|
|
137
|
+
emitUsageError('Nothing to update — pass at least one of: --name, --max-concurrent, --scope, --description');
|
|
138
|
+
}
|
|
139
|
+
const spinner = ora('Updating mutex group…').start();
|
|
140
|
+
try {
|
|
141
|
+
const body = {};
|
|
142
|
+
if (opts.name !== undefined)
|
|
143
|
+
body.name = opts.name;
|
|
144
|
+
if (opts.maxConcurrent !== undefined) {
|
|
145
|
+
body.maxConcurrentPerDevice = opts.maxConcurrent;
|
|
146
|
+
}
|
|
147
|
+
if (opts.scope !== undefined)
|
|
148
|
+
body.scope = opts.scope;
|
|
149
|
+
if (opts.description !== undefined)
|
|
150
|
+
body.description = opts.description;
|
|
151
|
+
const group = await put(`/mutex-groups/${id}`, body);
|
|
152
|
+
spinner.stop();
|
|
153
|
+
if (opts.json) {
|
|
154
|
+
console.log(JSON.stringify(group));
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
console.log(chalk.green(`✔ Mutex group updated: ${group.name}`));
|
|
158
|
+
console.log(' ID :', group.id);
|
|
159
|
+
console.log(' Max/Device :', group.maxConcurrentPerDevice);
|
|
160
|
+
console.log(' Scope :', group.scope);
|
|
161
|
+
}
|
|
162
|
+
catch (e) {
|
|
163
|
+
emitError('Failed to update mutex group', e, { spinner });
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
// acf mutex delete <id>
|
|
167
|
+
cmd
|
|
168
|
+
.command('delete <id>')
|
|
169
|
+
.description('Delete a mutex group (ADMIN) — attached apps become ungrouped; refuses with 409 while apps are still attached unless --force')
|
|
170
|
+
.option('-f, --force', 'Delete even when apps are still attached (they silently lose the constraint)', false)
|
|
171
|
+
.option('-y, --yes', 'Skip confirmation prompt', false)
|
|
172
|
+
.action(async (id, opts) => {
|
|
173
|
+
// 破坏性动作:先要交互确认(非 TTY 且无 --yes 时由 confirmDestructive
|
|
174
|
+
// 以退出码 2 拒绝,不会静默假绿)。
|
|
175
|
+
const warning = opts.force
|
|
176
|
+
? `Delete mutex group ${id}? Attached apps will lose the mutual-exclusion constraint (--force given).`
|
|
177
|
+
: `Delete mutex group ${id}?`;
|
|
178
|
+
const proceed = await confirmDestructive(warning, { yes: opts.yes });
|
|
179
|
+
if (!proceed)
|
|
180
|
+
return;
|
|
181
|
+
const spinner = ora('Deleting mutex group…').start();
|
|
182
|
+
try {
|
|
183
|
+
// 服务端:组上仍挂应用时返回 409,需显式 force=true 才放行。
|
|
184
|
+
// 查询串交给 del() 的 params(不在路径字面量里拼 `?`)——见 client.ts
|
|
185
|
+
// 的 del() 注释:手工拼串会让 consumer-routes 守卫无法静态解析该路由。
|
|
186
|
+
await del(`/mutex-groups/${id}`, opts.force ? { force: 'true' } : undefined);
|
|
187
|
+
spinner.succeed(`Mutex group ${id} deleted`);
|
|
188
|
+
}
|
|
189
|
+
catch (e) {
|
|
190
|
+
emitError('Failed to delete mutex group', e, { spinner });
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
return cmd;
|
|
194
|
+
}
|
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。流参数可注入——
|