@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/README.md
CHANGED
|
@@ -30,11 +30,36 @@ CLI 的非零退出码按失败类别区分,脚本/CI 可以只按码分支处
|
|
|
30
30
|
| --- | --- | --- |
|
|
31
31
|
| `0` | 成功 | 含 `--help` / `--version` / 主动放弃确认(`Aborted.`) |
|
|
32
32
|
| `1` | 运行失败 | 服务端拒绝(400/403/404/409/5xx,错误行透出后端 message);`--wait` 等到失败终态;`acf task lint` 检出语法错误 |
|
|
33
|
-
| `2` | 用法 / 参数错误 | 缺参、未知命令/选项、非法取值(如 `--wait-timeout abc`);本地 payload 问题(JSON 解析失败、`--file` 读不了、`task lint`
|
|
33
|
+
| `2` | 用法 / 参数错误 | 缺参、未知命令/选项、非法取值(如 `--wait-timeout abc`);本地 payload 问题(JSON 解析失败、`--file` 读不了、`task lint` 无法推断语言);**非交互 stdin 下的破坏性操作缺 `--yes`**(见下) |
|
|
34
34
|
| `3` | 认证失败 | 401:凭据缺失/过期且自动刷新失败 → 运行 `acf login` |
|
|
35
35
|
| `4` | 网络失败 | 连接不通 / 超时 / DNS → 检查 `--api-url`、`ACF_API_URL`;`acf exec tail` 流中断或空闲超时 |
|
|
36
36
|
| `130` | 中断(SIGINT) | Ctrl+C。输出会补一个换行,不留半行 spinner |
|
|
37
37
|
|
|
38
|
+
### 退出码 1 的两个高频非「失败」通道(CI 必读)
|
|
39
|
+
|
|
40
|
+
同样是 `1`,但语义**不是**「操作失败」,不要据此触发回滚/告警:
|
|
41
|
+
|
|
42
|
+
- **`--wait` 轮询超时**:执行**仍在运行**,CLI 只是放弃了等待(默认 600s,
|
|
43
|
+
用 `--wait-timeout <s>` 放宽)。此时输出会明确写「The execution is still
|
|
44
|
+
running」,跟进用 `acf exec tail <execId>`。**结果未知 ≠ 失败**。
|
|
45
|
+
- **批量部分失败**:`acf task batch <action>` 与 `acf app upgrade-all` 在
|
|
46
|
+
「部分目标被拒」时返回 1(服务端 HTTP 仍是 2xx)。逐项结果看 stdout 的
|
|
47
|
+
`✗ <id>: <reason>` 行或 `--json` 输出。
|
|
48
|
+
|
|
49
|
+
### 破坏性操作的 `--yes`(非交互必读)
|
|
50
|
+
|
|
51
|
+
`app delete` / `task delete` / `deploy remove` 有交互确认。**stdin 非 TTY 时
|
|
52
|
+
(CI、agent、`< NUL`、管道)它们不会静默放行也不会静默取消,而是以退出码 2
|
|
53
|
+
拒绝**,要求显式传 `-y/--yes`:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
acf task delete <id> -y # 非交互下唯一被接受的确认方式
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
判据是 `process.stdin.isTTY`。同族纪律:`acf login` 在非交互下同样不会对
|
|
60
|
+
地址/用户名/密码发问,缺少 `--user` 或 `ACF_PASSWORD` 时直接以退出码 2 报
|
|
61
|
+
可操作错误(不再出现「exit 0 但其实没登录」)。
|
|
62
|
+
|
|
38
63
|
单一事实源在 `src/ui.ts` 的 `EXIT_CODES`;错误分类(401/网络/服务端)在
|
|
39
64
|
`src/client.ts` 的 `classifyApiError` 做一次,命令层统一经 `emitError` 出口
|
|
40
65
|
消费。
|
|
@@ -44,8 +69,8 @@ CLI 的非零退出码按失败类别区分,脚本/CI 可以只按码分支处
|
|
|
44
69
|
所有只读命令都支持 `--json`(CI/脚本消费面,错误仍走 stderr + 非零退出码):
|
|
45
70
|
|
|
46
71
|
- 列表 / 信封形态(`task list`、`task executions`、`app list`、
|
|
47
|
-
`app deployments`、`executor list`、`sop list
|
|
48
|
-
`audit list`)→ 单行紧凑 JSON,信封(`{list|data|items, total}`)原样直出;
|
|
72
|
+
`app deployments`、`app releases`、`deploy list`、`executor list`、`sop list`、
|
|
73
|
+
`agent sessions`、`audit list`)→ 单行紧凑 JSON,信封(`{list|data|items, total}`)原样直出;
|
|
49
74
|
- 单对象 / 详情形态(`task get`、`task stats`、`task versions`、
|
|
50
75
|
`task compare`、`task logs`、`task trigger`、`app get`、`app versions`、
|
|
51
76
|
`executor get`、`sop show`、`project list`、`project members`)→
|
|
@@ -76,6 +101,24 @@ CLI 的非零退出码按失败类别区分,脚本/CI 可以只按码分支处
|
|
|
76
101
|
- Access token 过期时自动用 refresh token 换发并重放一次;刷新失败才要求
|
|
77
102
|
重新登录(此时退出码为 3)。
|
|
78
103
|
|
|
104
|
+
## 应用部署(run-mode 语义,2026-10 实测修复)
|
|
105
|
+
|
|
106
|
+
- `acf app deploy <appId>`:缺省 `-m scheduled` —— **仅部署、由中台/任务调度触发,部署后不自跑**(批处理/中台定时触发场景的正确模式,存量部署 11/12 用它)。三档语义:
|
|
107
|
+
- `once`:启动入口脚本一次,退出不重启;
|
|
108
|
+
- `daemon`:常驻进程——**部署时立刻启动入口脚本**,异常退出自动重启(退出码 0 不重启);
|
|
109
|
+
- `scheduled`(别名 `deploy-only`):只下发代码、**不启动进程**,由任务调度触发。
|
|
110
|
+
- 显式传 `once`/`daemon` 时,CLI 会在发请求前打黄色预警「将立刻启动入口脚本」——避免"部署即跑"与后续 `task trigger` 双跑、并发写同一产物目录。
|
|
111
|
+
- 部署列表:`acf app deployments [appId]`,或 `acf deploy list [appId]`(同源同契约,deploy 组下的可发现入口)。
|
|
112
|
+
- 版本发布追溯:`acf app releases <appId>`(DEP-01 统一视图:版本 × 最近部署——状态/次数/执行器/runMode/触发方式;`app versions` 是过渡期 legacy alias)。
|
|
113
|
+
- 清理遗留记录:`acf deploy remove <deploymentId> -y` —— 删除**已终结**的部署记录(failed/stopped);在途/运行/待审批行服务端 409(先 `stop`,或走审批 `reject`/`cancel`)。
|
|
114
|
+
|
|
115
|
+
## 任务参数注入(params → AUTOFLOW_\*)
|
|
116
|
+
|
|
117
|
+
`task create`/`update` 的 `body.params` 在每次执行时注入为 `AUTOFLOW_<KEY>` 环境变量(键名转大写),值 JSON 序列化:布尔/数字是裸值(`true`/`3`),**字符串带双引号**(`"yes"`),对象/数组为 JSON —— 脚本侧请按 JSON 解析,不要当普通字符串(两执行器契约向量见 contract-fixtures 的 `executorEnvSerialization`)。
|
|
118
|
+
|
|
119
|
+
- **按 run 覆盖参数**:`acf task trigger <id> --params '{"KEY":"value"}'` 覆盖任务默认 params(TriggerTaskDto 同 webhook 面;缺省不发 body,用任务默认值)。block-strategy 闸(N-14)按生效参数判重。
|
|
120
|
+
- **按名/描述搜任务**:`acf task list --search <kw>` 走 `q` 参数(name OR description,控制台搜索框同款);`-k/--keyword` 仍只搜 name(向后兼容通道)。
|
|
121
|
+
|
|
79
122
|
## 应用包上传 / 灰度升级 / 审批 / webhook / glue
|
|
80
123
|
|
|
81
124
|
- `acf app upload <pkg.zip> --name <name>`:multipart 上传应用包(按名称
|
package/dist/commands/apps.js
CHANGED
|
@@ -4,7 +4,7 @@ import chalk from 'chalk';
|
|
|
4
4
|
import ora from 'ora';
|
|
5
5
|
import * as path from 'path';
|
|
6
6
|
import { get, post, put, del, ANALYZE_TIMEOUT_MS, UPLOAD_TIMEOUT_MS } from '../client.js';
|
|
7
|
-
import { emitError, emitUsageError, UsageError,
|
|
7
|
+
import { emitError, emitUsageError, UsageError, confirmDestructive } from '../ui.js';
|
|
8
8
|
function statusColor(s) {
|
|
9
9
|
if (s === 'running')
|
|
10
10
|
return chalk.green(s);
|
|
@@ -108,14 +108,27 @@ export function appsCommand() {
|
|
|
108
108
|
}
|
|
109
109
|
});
|
|
110
110
|
// acf app create
|
|
111
|
+
// 2026-10-07 对齐 task create 的载荷旗标改名:--json <body> → --body。
|
|
112
|
+
//(task 侧先改,app 侧本轮补齐——--json 在其余命令都是「输出 JSON」布尔
|
|
113
|
+
// 旗标,载荷语义的 --json 是历史包袱,下一大版本收敛为布尔。)
|
|
111
114
|
cmd.command('create')
|
|
112
|
-
.description('Create an application (JSON payload via --
|
|
113
|
-
.
|
|
114
|
-
.option('--
|
|
115
|
+
.description('Create an application (JSON payload via --body or --file; required: name, version, runtime)')
|
|
116
|
+
.option('--body <json>', 'Application body as JSON string (required unless --file is given)')
|
|
117
|
+
.option('--json <body>', 'DEPRECATED (renamed to --body): Application body as JSON string. In the next major version --json becomes a boolean output flag')
|
|
118
|
+
.option('--file <path>', 'Read application body from a JSON file (overrides --body/--json)')
|
|
115
119
|
.action(async (opts) => {
|
|
120
|
+
if (opts.body !== undefined && opts.json !== undefined) {
|
|
121
|
+
emitUsageError('--body and --json (deprecated alias) are mutually exclusive — pass only --body');
|
|
122
|
+
}
|
|
123
|
+
if (opts.body === undefined && opts.json === undefined && !opts.file) {
|
|
124
|
+
emitUsageError('Missing required application body — pass --body <json> (or --file <path>)');
|
|
125
|
+
}
|
|
116
126
|
const spinner = ora('Creating application…').start();
|
|
117
127
|
try {
|
|
118
|
-
|
|
128
|
+
if (opts.json !== undefined) {
|
|
129
|
+
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'));
|
|
130
|
+
}
|
|
131
|
+
const body = await loadJsonBody(opts.json ?? opts.body, opts.file);
|
|
119
132
|
const a = await post('/applications', body);
|
|
120
133
|
spinner.succeed(`Application created: ${a.id}`);
|
|
121
134
|
console.log(chalk.gray(` name: ${a.name} version: ${a.version ?? '-'} status: ${statusColor(a.status)}`));
|
|
@@ -181,15 +194,25 @@ export function appsCommand() {
|
|
|
181
194
|
});
|
|
182
195
|
// acf app update <id>
|
|
183
196
|
cmd.command('update <id>')
|
|
184
|
-
.description('Update an application (JSON payload via --
|
|
197
|
+
.description('Update an application (JSON payload via --body or --file). ' +
|
|
185
198
|
'Accepted fields: description, version, runtime, status, gitRepo, gitBranch, gitCommit, manifest, env, entrypoint, packageUrl, webhookSecret. ' +
|
|
186
199
|
'NOTE: the backend UpdateApplicationDto has no `name` field — renaming is not supported.')
|
|
187
|
-
.
|
|
188
|
-
.option('--
|
|
200
|
+
.option('--body <json>', 'Application patch body as JSON string (required unless --file is given)')
|
|
201
|
+
.option('--json <body>', 'DEPRECATED (renamed to --body): Application patch body as JSON string. In the next major version --json becomes a boolean output flag')
|
|
202
|
+
.option('--file <path>', 'Read application patch body from a JSON file (overrides --body/--json)')
|
|
189
203
|
.action(async (id, opts) => {
|
|
204
|
+
if (opts.body !== undefined && opts.json !== undefined) {
|
|
205
|
+
emitUsageError('--body and --json (deprecated alias) are mutually exclusive — pass only --body');
|
|
206
|
+
}
|
|
207
|
+
if (opts.body === undefined && opts.json === undefined && !opts.file) {
|
|
208
|
+
emitUsageError('Missing required application patch body — pass --body <json> (or --file <path>)');
|
|
209
|
+
}
|
|
190
210
|
const spinner = ora('Updating application…').start();
|
|
191
211
|
try {
|
|
192
|
-
|
|
212
|
+
if (opts.json !== undefined) {
|
|
213
|
+
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'));
|
|
214
|
+
}
|
|
215
|
+
const body = (await loadJsonBody(opts.json ?? opts.body, opts.file));
|
|
193
216
|
// UpdateApplicationDto has no `name` — with forbidNonWhitelisted the
|
|
194
217
|
// API would answer 400 "property name should not exist". Fail early
|
|
195
218
|
// with an actionable message instead.
|
|
@@ -211,19 +234,9 @@ export function appsCommand() {
|
|
|
211
234
|
.description('Delete an application')
|
|
212
235
|
.option('-y, --yes', 'Skip confirmation prompt', false)
|
|
213
236
|
.action(async (id, opts) => {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
// raw 模式下 Ctrl+C 触发 rl 'SIGINT' 而非进程信号;无监听只会 pause,
|
|
218
|
-
// 确认提示处会假死。接住并走统一中断出口(130)。
|
|
219
|
-
rl.on('SIGINT', () => interruptExit());
|
|
220
|
-
const answer = await rl.question(`Delete application ${id}? [y/N] `);
|
|
221
|
-
rl.close();
|
|
222
|
-
if (!/^y(es)?$/i.test(answer)) {
|
|
223
|
-
console.log(chalk.yellow('Aborted.'));
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
237
|
+
// P0(CLI-AGENT-UX-AUDIT):非交互 stdin 下必须显式拒绝,不能静默假绿。
|
|
238
|
+
if (!(await confirmDestructive(`Delete application ${id}?`, { yes: opts.yes })))
|
|
239
|
+
return;
|
|
227
240
|
const spinner = ora('Deleting application…').start();
|
|
228
241
|
try {
|
|
229
242
|
await del(`/applications/${id}`);
|
|
@@ -259,22 +272,56 @@ export function appsCommand() {
|
|
|
259
272
|
}
|
|
260
273
|
});
|
|
261
274
|
// acf app deploy <id>
|
|
275
|
+
//
|
|
276
|
+
// P0(2026-10 开发人员实测):`--run-mode` 的语义此前只列枚举值、不解释
|
|
277
|
+
// 行为差异,且默认值 `daemon` 恰好是"部署即立刻执行入口脚本"的模式——中台
|
|
278
|
+
// 定时触发场景(存量部署 11/12 是 scheduled)按"部署 = 待命"理解却不传 -m,
|
|
279
|
+
// 部署时自跑了一次完整任务,28s 后再 trigger 又跑一次,两边并发写同一云盘
|
|
280
|
+
// 目录。修复三管齐下:
|
|
281
|
+
// ① 默认值改为 `scheduled`(仅下发、由中台/定时触发,部署后不自跑);
|
|
282
|
+
// ② 帮助文本写清三档的真实行为(语义见 docs/deployment.md §runMode);
|
|
283
|
+
// ③ 显式传 once/daemon 时在发请求前打黄色预警"将立刻启动入口脚本"。
|
|
284
|
+
// `deploy-only` 是 scheduled 的自解释别名("仅部署、不自动运行")——服务端
|
|
285
|
+
// RunMode 枚举没有该值,CLI 在本地归一为 scheduled 后发送。
|
|
262
286
|
cmd.command('deploy <id>')
|
|
263
287
|
.description('Deploy an application to an executor (auto-selects the lowest-load online executor when --executor is omitted)')
|
|
264
288
|
.option('-e, --executor <executorId>', 'Pin to a specific executor')
|
|
265
|
-
.option('-m, --run-mode <mode>', 'Run mode: once | daemon | scheduled',
|
|
289
|
+
.option('-m, --run-mode <mode>', 'Run mode: once (run the entry script once, no restart) | daemon (resident process — the entry script STARTS at deploy and auto-restarts on crash) | scheduled (deploy-only — no process at deploy; middleware/cron triggers it later; default) | deploy-only (alias of scheduled)', (v) => {
|
|
290
|
+
const m = v.toLowerCase();
|
|
291
|
+
if (!['once', 'daemon', 'scheduled', 'deploy-only'].includes(m)) {
|
|
292
|
+
throw new InvalidArgumentError('must be one of: once | daemon | scheduled | deploy-only (deploy-only = scheduled — deploy without auto-run)');
|
|
293
|
+
}
|
|
294
|
+
return m;
|
|
295
|
+
}, 'scheduled')
|
|
266
296
|
.option('--env <json>', 'Env var overrides as JSON, e.g. \'{"KEY":"value"}\'')
|
|
267
297
|
.option('--start-command <cmd>', 'Startup command override (defaults to manifest entrypoint)')
|
|
268
298
|
.action(async (id, opts) => {
|
|
299
|
+
// deploy-only → scheduled:本地别名归一(服务端 RunMode 枚举无 deploy-only)。
|
|
300
|
+
const runMode = opts.runMode === 'deploy-only' ? 'scheduled' : opts.runMode;
|
|
301
|
+
if (runMode === 'daemon' || runMode === 'once') {
|
|
302
|
+
// 预警在请求发出之前给出:once/daemon 会在部署时立刻启动入口脚本
|
|
303
|
+
//(daemon 异常退出还会自动重启)——"部署即跑"是双跑事故的根源。
|
|
304
|
+
process.stderr.write(chalk.yellow(`⚠ run-mode "${opts.runMode}" starts the entry script immediately at deploy — for deploy-only (middleware/cron triggers later), use --run-mode scheduled.\n`));
|
|
305
|
+
}
|
|
269
306
|
const spinner = ora('Triggering deployment…').start();
|
|
270
307
|
try {
|
|
271
|
-
const body = { runMode
|
|
308
|
+
const body = { runMode };
|
|
272
309
|
if (opts.executor)
|
|
273
310
|
body.executorId = opts.executor;
|
|
274
|
-
if (opts.env)
|
|
275
|
-
body.env = JSON.parse(opts.env);
|
|
276
311
|
if (opts.startCommand)
|
|
277
312
|
body.startCommand = opts.startCommand;
|
|
313
|
+
// P2(CLI-AGENT-UX-AUDIT):--env 的 JSON 解析此前裸放在 try 里,坏 JSON
|
|
314
|
+
// 被当成「部署失败」报退出码 1——agent 会去查服务端日志,而实际是自己
|
|
315
|
+
// 参数写错了。与 `task trigger --params` 同口径:本地 payload 错误是
|
|
316
|
+
// 用法错误(退出码 2),且请求不发出。
|
|
317
|
+
if (opts.env) {
|
|
318
|
+
try {
|
|
319
|
+
body.env = JSON.parse(opts.env);
|
|
320
|
+
}
|
|
321
|
+
catch (err) {
|
|
322
|
+
throw new UsageError(`Invalid --env JSON: ${err instanceof Error ? err.message : String(err)}`);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
278
325
|
const dep = await post(`/app-deployments/applications/${id}/deploy`, body);
|
|
279
326
|
spinner.succeed('Deployment triggered');
|
|
280
327
|
console.log(chalk.gray(` deployment: ${dep?.id ?? '-'} status: ${dep?.status ?? '-'} executor: ${dep?.executorId ?? 'auto'}`));
|
|
@@ -285,10 +332,10 @@ export function appsCommand() {
|
|
|
285
332
|
});
|
|
286
333
|
// P2: acf app upgrade-all <appId> —— POST /applications/:id/upgrade-all(DEP-02
|
|
287
334
|
// 灰度)。契约:请求体全可选,缺省(不传 body)= all 全量升级,既有语义逐字节
|
|
288
|
-
// 保持;canary 传 { rollout: { strategy: 'canary', percentage? } }
|
|
289
|
-
// UpgradeAllDto
|
|
290
|
-
//
|
|
291
|
-
//
|
|
335
|
+
// 保持;canary 传 { rollout: { strategy: 'canary', percentage? } }。
|
|
336
|
+
// 2026-10-07:UpgradeAllDto 增可选 version(版本定向灰度/渐进回滚)——
|
|
337
|
+
// --version <v> 时 body 带顶层 version;缺省不带(升级目标恒为应用当前版本)。
|
|
338
|
+
// 批次由服务端异步推进(心跳确认 → 健康探测 → 提升),受理 ≠ 完成。
|
|
292
339
|
cmd.command('upgrade-all <appId>')
|
|
293
340
|
.description("Trigger a rolling upgrade of all RUNNING deployments to the application's current version (or --version). Default = full upgrade (pre-DEP-02 semantics, no body). Canary batches advance asynchronously on the server — acceptance is not completion")
|
|
294
341
|
.option('--strategy <strategy>', 'Rollout strategy: all (default) | canary (first batch → heartbeat confirm → health probe → auto-promote the rest, DEP-02)')
|
|
@@ -301,6 +348,7 @@ export function appsCommand() {
|
|
|
301
348
|
})
|
|
302
349
|
.option('--version <version>', 'Target a historical released version (version string, not uuid) — enables gradual rollback. Default: the application\'s current version. The app record is restored from that version snapshot before the rollout starts')
|
|
303
350
|
.option('--json', 'Emit raw JSON (CI-consumable)')
|
|
351
|
+
.option('-y, --yes', 'Skip the confirmation prompt for a FULL upgrade (all strategy)', false)
|
|
304
352
|
.action(async (appId, opts) => {
|
|
305
353
|
const strategy = opts.strategy ?? 'all';
|
|
306
354
|
if (strategy !== 'all' && strategy !== 'canary') {
|
|
@@ -309,6 +357,14 @@ export function appsCommand() {
|
|
|
309
357
|
if (opts.percentage !== undefined && strategy !== 'canary') {
|
|
310
358
|
emitUsageError('--percentage only applies to --strategy canary (the full-upgrade path never reads it)');
|
|
311
359
|
}
|
|
360
|
+
// P1(CLI-AGENT-UX-AUDIT):全量滚动升级会重启该应用**所有 RUNNING 部署**,
|
|
361
|
+
// 此前零确认。canary 天然是低风险首步(且服务端会自动提升/回滚),不设门;
|
|
362
|
+
// all 是「一次性动全量」,需要显式表态——与三处 delete 共用同一套非交互语义。
|
|
363
|
+
if (strategy === 'all') {
|
|
364
|
+
if (!(await confirmDestructive(`Roll out the upgrade to ALL running deployments of ${appId}?`, { yes: opts.yes }))) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
312
368
|
const spinner = ora('Triggering upgrade…').start();
|
|
313
369
|
try {
|
|
314
370
|
// all:不传 body —— 与既有全量升级语义逐字节一致;canary:rollout
|
|
@@ -441,5 +497,49 @@ export function appsCommand() {
|
|
|
441
497
|
emitError('Failed to list versions', e, { spinner });
|
|
442
498
|
}
|
|
443
499
|
});
|
|
500
|
+
cmd.command('releases <appId>')
|
|
501
|
+
.description('List unified release history (version × latest deployment) for an application — the modern DEP-01 view; `app versions` is the legacy alias')
|
|
502
|
+
.option('-p, --page <n>', 'Page number', '1')
|
|
503
|
+
.option('-n, --page-size <n>', 'Page size (max 200, default 50)', '50')
|
|
504
|
+
// --json 补面(UX 统一):列表/信封形态 → 单行紧凑 JSON
|
|
505
|
+
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
506
|
+
.action(async (appId, opts) => {
|
|
507
|
+
const spinner = ora('Fetching releases…').start();
|
|
508
|
+
try {
|
|
509
|
+
// getReleases returns `{ data, total, page, pageSize }`
|
|
510
|
+
const data = await get(`/applications/${appId}/releases`, { page: opts.page, pageSize: opts.pageSize });
|
|
511
|
+
spinner.stop();
|
|
512
|
+
if (opts.json) {
|
|
513
|
+
console.log(JSON.stringify(data));
|
|
514
|
+
return;
|
|
515
|
+
}
|
|
516
|
+
const list = Array.isArray(data) ? data : (data.data ?? data.list ?? []);
|
|
517
|
+
if (!list.length) {
|
|
518
|
+
console.log(chalk.gray('No releases recorded for this application.'));
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
const table = new Table({
|
|
522
|
+
head: ['Version', 'Deployed', 'Status', 'Count', 'Executor', 'RunMode', 'Trigger'],
|
|
523
|
+
colWidths: [12, 20, 12, 8, 18, 10, 12],
|
|
524
|
+
style: { head: ['cyan'] },
|
|
525
|
+
});
|
|
526
|
+
for (const r of list) {
|
|
527
|
+
table.push([
|
|
528
|
+
r.version ?? '-',
|
|
529
|
+
r.deployedAt ? new Date(r.deployedAt).toLocaleString() : '-',
|
|
530
|
+
statusColor(r.deploymentStatus ?? r.status),
|
|
531
|
+
String(r.deploymentCount),
|
|
532
|
+
r.executorAddress ?? '-',
|
|
533
|
+
r.runMode ?? '-',
|
|
534
|
+
r.triggerType ?? '-',
|
|
535
|
+
]);
|
|
536
|
+
}
|
|
537
|
+
console.log(table.toString());
|
|
538
|
+
console.log(chalk.gray(`Total: ${data.total ?? list.length} page ${opts.page}`));
|
|
539
|
+
}
|
|
540
|
+
catch (e) {
|
|
541
|
+
emitError('Failed to list releases', e, { spinner });
|
|
542
|
+
}
|
|
543
|
+
});
|
|
444
544
|
return cmd;
|
|
445
545
|
}
|
package/dist/commands/audit.js
CHANGED
|
@@ -44,9 +44,10 @@ export function auditCommand() {
|
|
|
44
44
|
});
|
|
45
45
|
spinner.stop();
|
|
46
46
|
if (opts.json) {
|
|
47
|
-
// ECO-02
|
|
48
|
-
//
|
|
49
|
-
|
|
47
|
+
// ECO-02 同款:列表/信封形态 → 单行紧凑 JSON(此前误用 pretty(2),
|
|
48
|
+
// 与 task list / agent sessions / sop list 的列表直出口径不一致——
|
|
49
|
+
// README 明确列表形态是「单行紧凑 JSON」)。
|
|
50
|
+
console.log(JSON.stringify(data));
|
|
50
51
|
return;
|
|
51
52
|
}
|
|
52
53
|
const rows = Array.isArray(data) ? data : (data.data ?? []);
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
/**
|
|
3
|
+
* acf deploy 组 —— 部署行的干预/查询面。
|
|
4
|
+
*
|
|
5
|
+
* 2026-10 开发人员实测的可发现性缺口:`acf deploy --help` 只有 upgrade/stop,
|
|
6
|
+
* 被误读成"CLI 没有部署状态查询";实际列表在 `acf app deployments`。修复:
|
|
7
|
+
* ① deploy 组补 `list`(与 app deployments 同源——同一个 GET /app-deployments
|
|
8
|
+
* 契约,改动需两边同步);② 组描述里交叉引用。
|
|
9
|
+
*/
|
|
2
10
|
export declare function deployCommand(): Command;
|
package/dist/commands/deploy.js
CHANGED
|
@@ -1,10 +1,72 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import Table from 'cli-table3';
|
|
2
3
|
import chalk from 'chalk';
|
|
3
4
|
import ora from 'ora';
|
|
4
|
-
import { post } from '../client.js';
|
|
5
|
-
import { emitError } from '../ui.js';
|
|
5
|
+
import { get, post, del } from '../client.js';
|
|
6
|
+
import { emitError, confirmDestructive } from '../ui.js';
|
|
7
|
+
function statusColor(s) {
|
|
8
|
+
if (s === 'running')
|
|
9
|
+
return chalk.green(s);
|
|
10
|
+
if (s === 'stopped')
|
|
11
|
+
return chalk.gray(s);
|
|
12
|
+
if (s === 'error' || s === 'failed')
|
|
13
|
+
return chalk.red(s);
|
|
14
|
+
if (s === 'deploying')
|
|
15
|
+
return chalk.cyan(s);
|
|
16
|
+
return chalk.yellow(s);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* acf deploy 组 —— 部署行的干预/查询面。
|
|
20
|
+
*
|
|
21
|
+
* 2026-10 开发人员实测的可发现性缺口:`acf deploy --help` 只有 upgrade/stop,
|
|
22
|
+
* 被误读成"CLI 没有部署状态查询";实际列表在 `acf app deployments`。修复:
|
|
23
|
+
* ① deploy 组补 `list`(与 app deployments 同源——同一个 GET /app-deployments
|
|
24
|
+
* 契约,改动需两边同步);② 组描述里交叉引用。
|
|
25
|
+
*/
|
|
6
26
|
export function deployCommand() {
|
|
7
|
-
const cmd = new Command('deploy').description('Manage application deployments (upgrade / stop
|
|
27
|
+
const cmd = new Command('deploy').description('Manage application deployments (upgrade / stop / list / remove records). List all deployments with: acf deploy list (same data as acf app deployments)');
|
|
28
|
+
// acf deploy list [appId] —— 与 apps.ts 的 `app deployments` 同源同契约。
|
|
29
|
+
cmd.command('list [appId]')
|
|
30
|
+
.description('List deployments (optionally filtered by application) — same data as: acf app deployments')
|
|
31
|
+
.option('-p, --page <n>', 'Page number', '1')
|
|
32
|
+
.option('-n, --page-size <n>', 'Page size', '20')
|
|
33
|
+
// --json 补面(UX 统一):列表/信封形态 → 单行紧凑 JSON
|
|
34
|
+
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
35
|
+
.action(async (appId, opts) => {
|
|
36
|
+
const spinner = ora('Fetching deployments…').start();
|
|
37
|
+
try {
|
|
38
|
+
// app-deployment.service.findAll returns `{ data, total }`
|
|
39
|
+
const data = await get('/app-deployments', {
|
|
40
|
+
...(appId ? { applicationId: appId } : {}),
|
|
41
|
+
page: opts.page,
|
|
42
|
+
pageSize: opts.pageSize,
|
|
43
|
+
});
|
|
44
|
+
spinner.stop();
|
|
45
|
+
if (opts.json) {
|
|
46
|
+
console.log(JSON.stringify(data));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const list = Array.isArray(data) ? data : (data.data ?? data.list ?? []);
|
|
50
|
+
const table = new Table({
|
|
51
|
+
head: ['Deployment', 'App', 'Executor', 'Status', 'RunMode'],
|
|
52
|
+
colWidths: [14, 14, 14, 12, 11],
|
|
53
|
+
style: { head: ['cyan'] },
|
|
54
|
+
});
|
|
55
|
+
for (const d of list) {
|
|
56
|
+
table.push([
|
|
57
|
+
d.id.slice(0, 12),
|
|
58
|
+
d.applicationId?.slice(0, 12) ?? '-',
|
|
59
|
+
d.executorId?.slice(0, 12) ?? '-',
|
|
60
|
+
statusColor(d.status),
|
|
61
|
+
d.runMode ?? '-',
|
|
62
|
+
]);
|
|
63
|
+
}
|
|
64
|
+
console.log(table.toString());
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
emitError('Failed to list deployments', e, { spinner });
|
|
68
|
+
}
|
|
69
|
+
});
|
|
8
70
|
// acf deploy upgrade <deploymentId>
|
|
9
71
|
cmd.command('upgrade <deploymentId>')
|
|
10
72
|
.description('Trigger an overlay upgrade for a running deployment (pulls the latest application version)')
|
|
@@ -35,5 +97,28 @@ export function deployCommand() {
|
|
|
35
97
|
emitError('Failed to stop deployment', e, { spinner });
|
|
36
98
|
}
|
|
37
99
|
});
|
|
100
|
+
// acf deploy remove <deploymentId> —— DELETE /app-deployments/:id
|
|
101
|
+
//
|
|
102
|
+
// 2026-10 开发人员遗留噪音:一条 stopped + daemon 的旧部署记录无法删除
|
|
103
|
+
//(CLI 只有 stop)。服务端早已提供 DELETE /app-deployments/:id(仅终态行
|
|
104
|
+
// FAILED/STOPPED,在途/运行/待审批 409 并说明正确出口),CLI 补齐此面。
|
|
105
|
+
cmd.command('remove <deploymentId>')
|
|
106
|
+
.description('Delete a FINISHED deployment record (failed/stopped only). In-flight, running and pending-approval rows are refused with 409 — stop a running one first, use approval reject/cancel for a pending one')
|
|
107
|
+
.option('-y, --yes', 'Skip confirmation prompt', false)
|
|
108
|
+
.action(async (deploymentId, opts) => {
|
|
109
|
+
// P0(CLI-AGENT-UX-AUDIT):非交互 stdin 下必须显式拒绝,不能静默假绿。
|
|
110
|
+
if (!(await confirmDestructive(`Delete deployment record ${deploymentId}? (terminal rows only: failed/stopped)`, { yes: opts.yes }))) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const spinner = ora('Deleting deployment record…').start();
|
|
114
|
+
try {
|
|
115
|
+
// DELETE /app-deployments/:id — AppDeploymentController.remove
|
|
116
|
+
const r = await del(`/app-deployments/${deploymentId}`);
|
|
117
|
+
spinner.succeed(`Deployment record ${r?.deletedId ?? deploymentId} removed`);
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
emitError('Failed to remove deployment record', e, { spinner });
|
|
121
|
+
}
|
|
122
|
+
});
|
|
38
123
|
return cmd;
|
|
39
124
|
}
|
package/dist/commands/exec.js
CHANGED
|
@@ -20,9 +20,11 @@
|
|
|
20
20
|
import { Command } from 'commander';
|
|
21
21
|
import axios from 'axios';
|
|
22
22
|
import chalk from 'chalk';
|
|
23
|
-
import { get, post } from '../client.js';
|
|
23
|
+
import { get, post, normalizeApiBase } from '../client.js';
|
|
24
24
|
import { getApiUrl } from '../config.js';
|
|
25
25
|
import { emitError, EXIT_CODES } from '../ui.js';
|
|
26
|
+
// 失败原因 → 可操作建议(与 task trigger --wait 的出口同源,见 tasks.ts)。
|
|
27
|
+
import { FAILURE_REASON_HINTS } from './tasks.js';
|
|
26
28
|
const TERMINAL = new Set(['success', 'failed', 'timeout', 'killed', 'cancelled']);
|
|
27
29
|
/**
|
|
28
30
|
* 增量 SSE 解析器:feed(chunk) → 完整消息数组。跨 chunk 半行/半消息安全;
|
|
@@ -101,6 +103,22 @@ export function execCommand() {
|
|
|
101
103
|
break;
|
|
102
104
|
fromLine = printed;
|
|
103
105
|
}
|
|
106
|
+
// 失败终态:透出结构化原因 + 可操作建议(与 task trigger --wait 同源,
|
|
107
|
+
// 此前 tail 只打日志不解释失败,CI 里只能靠人肉读日志)。
|
|
108
|
+
if (exec.status !== 'success') {
|
|
109
|
+
if (exec.exitCode !== null && exec.exitCode !== undefined) {
|
|
110
|
+
process.stderr.write(chalk.yellow(`Exit code : ${exec.exitCode}\n`));
|
|
111
|
+
}
|
|
112
|
+
if (exec.failureReason) {
|
|
113
|
+
process.stderr.write(chalk.yellow(`Failure reason : ${exec.failureReason}\n`));
|
|
114
|
+
const hint = FAILURE_REASON_HINTS[exec.failureReason];
|
|
115
|
+
if (hint)
|
|
116
|
+
process.stderr.write(chalk.yellow(`Suggestion : ${hint}\n`));
|
|
117
|
+
}
|
|
118
|
+
if (exec.errorMessage) {
|
|
119
|
+
process.stderr.write(chalk.yellow(`Error : ${exec.errorMessage}\n`));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
104
122
|
process.exitCode = exec.status === 'success' ? 0 : 1;
|
|
105
123
|
return;
|
|
106
124
|
}
|
|
@@ -108,8 +126,12 @@ export function execCommand() {
|
|
|
108
126
|
// SEC-CLI-01: 先换一枚 30s TTL 的专用 SSE 票据(走常规 Authorization
|
|
109
127
|
// 头的 POST),再以 ?ticket= 建流——`?access_token=` 通道已被服务端撤销,
|
|
110
128
|
// 旧写法会让每次非终态 tail 直接 401。与 admin-web/src/api/sse.ts 同流程。
|
|
129
|
+
// API-PREFIX-01(本轮):建流 URL 必须走 normalizeApiBase——admin-api
|
|
130
|
+
// 有全局 /api 前缀(main.ts setGlobalPrefix),此前用裸 getApiUrl()
|
|
131
|
+
// 拼 URL,默认 http://localhost:3105 对标准部署恒 404(与 client.ts
|
|
132
|
+
// 2026-10-07 修过的普通请求同类缺陷,SSE 直连 axios 绕过了归一)。
|
|
111
133
|
const { ticket } = await post('/auth/sse-ticket');
|
|
112
|
-
const base = getApiUrl()
|
|
134
|
+
const base = normalizeApiBase(getApiUrl());
|
|
113
135
|
const url = `${base}/tasks/${exec.taskId}/executions/${execId}/logs/stream?ticket=${encodeURIComponent(ticket)}`;
|
|
114
136
|
const res = await axios.get(url, { responseType: 'stream', timeout: 0 });
|
|
115
137
|
process.stderr.write(chalk.gray(`[tail] following execution ${execId} (status: ${exec.status ?? 'unknown'}) — Ctrl+C to detach\n`));
|
|
@@ -3,7 +3,7 @@ import Table from 'cli-table3';
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import ora from 'ora';
|
|
5
5
|
import { get, post } from '../client.js';
|
|
6
|
-
import { emitError } from '../ui.js';
|
|
6
|
+
import { emitError, confirmDestructive } from '../ui.js';
|
|
7
7
|
function statusColor(s) {
|
|
8
8
|
if (s === 'online')
|
|
9
9
|
return chalk.green(s);
|
|
@@ -137,7 +137,14 @@ export function executorsCommand() {
|
|
|
137
137
|
cmd.command('rotate <nameOrId>')
|
|
138
138
|
.description('Rotate an executor token (ADMIN; new token is shown ONCE in this output)')
|
|
139
139
|
.option('--reason <reason>', 'Optional rotation reason (≤200 chars, recorded in the audit log)')
|
|
140
|
+
.option('-y, --yes', 'Skip confirmation prompt', false)
|
|
140
141
|
.action(async (nameOrId, opts) => {
|
|
142
|
+
// P1(CLI-AGENT-UX-AUDIT):轮换是**不可逆**的——旧 token 立即失效,
|
|
143
|
+
// 而新 token 只在本命令输出里出现一次,没被捕获就永久丢失(只能再轮换)。
|
|
144
|
+
// 此前零确认。补确认,并复用统一的非交互语义(非 TTY 缺 --yes → 码 2)。
|
|
145
|
+
if (!(await confirmDestructive(`Rotate the token for "${nameOrId}"? The old token stops working immediately and the new one is shown only once.`, { yes: opts.yes }))) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
141
148
|
const spinner = ora('Rotating executor token…').start();
|
|
142
149
|
try {
|
|
143
150
|
const id = await resolveExecutorId(nameOrId);
|
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;
|