@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/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 上传应用包(按名称
|
|
@@ -95,6 +138,31 @@ CLI 的非零退出码按失败类别区分,脚本/CI 可以只按码分支处
|
|
|
95
138
|
语言按扩展名推断(`.js/.mjs/.cjs` → `javascript`),或 `--language
|
|
96
139
|
python|javascript|shell` 显式指定(执行器运行时白名单);空脚本本地即拒。
|
|
97
140
|
|
|
141
|
+
## 应用互斥组(MUTEX-01,2026-10 补齐 CLI 面)
|
|
142
|
+
|
|
143
|
+
同一组内的应用在**同一台设备上永不并发**(组内并发数默认 1 = 串行)——典型场景
|
|
144
|
+
是独占型资源:浏览器实例、单点登录账号(顶号)、GPU 槽位。后端 `mutex-groups`
|
|
145
|
+
四端点自 MUTEX-01 起就存在且中台在用,此前 CLI 零接入。
|
|
146
|
+
|
|
147
|
+
- `acf mutex list`:拉取可选组(**与中台应用表单下拉同源**),列出 `id` / 名称 /
|
|
148
|
+
每设备并发 / 作用域 / 已挂应用数。挂应用时用这里的 `id`。
|
|
149
|
+
- `acf mutex create --name <name> [--max-concurrent N] [--scope device|global] [--description <text>]`
|
|
150
|
+
:建组。`--max-concurrent` 取值 1-100(与后端 `@Min/@Max` 同界);
|
|
151
|
+
`--scope` 两档语义差别很大:
|
|
152
|
+
- `device`(默认):**单机串行、跨设备并发**——每台设备上同时最多 N 条;
|
|
153
|
+
- `global`:**全平台串行**——整平台同时最多 N 条(单点登录顶号类场景)。
|
|
154
|
+
- `acf mutex update <groupId> [--name] [--max-concurrent] [--scope] [--description]`:
|
|
155
|
+
改组。至少给一个字段(空 patch 本地即拒,退出码 2——服务端会「成功但什么都没改」,
|
|
156
|
+
容易被误读为已生效)。`--scope` 可即时收紧,在途 WAITING 执行由 sweep 重派自愈。
|
|
157
|
+
- `acf mutex delete <groupId> [-f|--force] [-y|--yes]`:删组。组上仍挂应用时服务端
|
|
158
|
+
返回 409 并告知挂载数量;确认后用 `--force` 放行(挂载应用经 FK `SET NULL`
|
|
159
|
+
自动回到「不参与互斥」)。属破坏性操作,非交互场景必须显式 `-y`。
|
|
160
|
+
- **把应用挂进组**(沿用既有 `app update`,字段此前未在帮助里列出):
|
|
161
|
+
`acf app update <appId> --body '{"mutexGroupId":"<acf mutex list 的 id>"}'`;
|
|
162
|
+
传 `null` 摘组。`acf app get <appId> --json` 可读出当前挂的组(表格视图不显示)。
|
|
163
|
+
组不存在时服务端 404(`assertMutexGroupExists` 前置校验)。
|
|
164
|
+
- 写面(create/update/delete)要求 **ADMIN** 角色;`list` 任意登录用户可读。
|
|
165
|
+
|
|
98
166
|
## 开发
|
|
99
167
|
|
|
100
168
|
```bash
|
package/dist/client.d.ts
CHANGED
|
@@ -32,7 +32,17 @@ export declare function get<T>(path: string, params?: Record<string, string | nu
|
|
|
32
32
|
export declare function post<T>(path: string, body?: unknown, timeoutMs?: number): Promise<T>;
|
|
33
33
|
export declare function put<T>(path: string, body?: unknown): Promise<T>;
|
|
34
34
|
export declare function patch<T>(path: string, body?: unknown): Promise<T>;
|
|
35
|
-
|
|
35
|
+
/**
|
|
36
|
+
* DELETE。可选 `params` 与 get() 同形——把查询串交给 axios 序列化,而不是
|
|
37
|
+
* 在调用点手工拼 `?a=b`。
|
|
38
|
+
*
|
|
39
|
+
* 为什么不让调用点拼:`del(\`/mutex-groups/${id}${opts.force ? '?force=true' : ''}\`)`
|
|
40
|
+
* 这种写法会让 consumer-routes 守卫(scripts/check-consumer-routes.mjs)误判
|
|
41
|
+
* ——它按 `?` 切分后再归一路径,字面量里的 `?` 会把路径截成
|
|
42
|
+
* `/mutex-groups/{}${opts.force ` 而报「路由不在 openapi 中」。守卫的判据是
|
|
43
|
+
* 「用到的每条路由都必须在 openapi 里」,故路径字面量必须保持干净可解析。
|
|
44
|
+
*/
|
|
45
|
+
export declare function del<T>(path: string, params?: Record<string, string | number | undefined>): Promise<T>;
|
|
36
46
|
/**
|
|
37
47
|
* Error class taxonomy shared by the whole CLI. Classification is done ONCE,
|
|
38
48
|
* here at the HTTP-client layer (the only place that knows axios shapes), so
|
package/dist/client.js
CHANGED
|
@@ -173,8 +173,18 @@ export async function patch(path, body) {
|
|
|
173
173
|
const r = await getClient().patch(path, body);
|
|
174
174
|
return unwrap(r.data);
|
|
175
175
|
}
|
|
176
|
-
|
|
177
|
-
|
|
176
|
+
/**
|
|
177
|
+
* DELETE。可选 `params` 与 get() 同形——把查询串交给 axios 序列化,而不是
|
|
178
|
+
* 在调用点手工拼 `?a=b`。
|
|
179
|
+
*
|
|
180
|
+
* 为什么不让调用点拼:`del(\`/mutex-groups/${id}${opts.force ? '?force=true' : ''}\`)`
|
|
181
|
+
* 这种写法会让 consumer-routes 守卫(scripts/check-consumer-routes.mjs)误判
|
|
182
|
+
* ——它按 `?` 切分后再归一路径,字面量里的 `?` 会把路径截成
|
|
183
|
+
* `/mutex-groups/{}${opts.force ` 而报「路由不在 openapi 中」。守卫的判据是
|
|
184
|
+
* 「用到的每条路由都必须在 openapi 里」,故路径字面量必须保持干净可解析。
|
|
185
|
+
*/
|
|
186
|
+
export async function del(path, params) {
|
|
187
|
+
const r = await getClient().delete(path, { params });
|
|
178
188
|
return unwrap(r.data);
|
|
179
189
|
}
|
|
180
190
|
// ---------------------------------------------------------------------------
|
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,28 @@ 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
|
+
'Optional: mutexGroupId (uuid from `acf mutex list` to join a mutex group), approvalRequired (gate deploys behind a second person).')
|
|
117
|
+
.option('--body <json>', 'Application body as JSON string (required unless --file is given)')
|
|
118
|
+
.option('--json <body>', 'DEPRECATED (renamed to --body): Application body as JSON string. In the next major version --json becomes a boolean output flag')
|
|
119
|
+
.option('--file <path>', 'Read application body from a JSON file (overrides --body/--json)')
|
|
115
120
|
.action(async (opts) => {
|
|
121
|
+
if (opts.body !== undefined && opts.json !== undefined) {
|
|
122
|
+
emitUsageError('--body and --json (deprecated alias) are mutually exclusive — pass only --body');
|
|
123
|
+
}
|
|
124
|
+
if (opts.body === undefined && opts.json === undefined && !opts.file) {
|
|
125
|
+
emitUsageError('Missing required application body — pass --body <json> (or --file <path>)');
|
|
126
|
+
}
|
|
116
127
|
const spinner = ora('Creating application…').start();
|
|
117
128
|
try {
|
|
118
|
-
|
|
129
|
+
if (opts.json !== undefined) {
|
|
130
|
+
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'));
|
|
131
|
+
}
|
|
132
|
+
const body = await loadJsonBody(opts.json ?? opts.body, opts.file);
|
|
119
133
|
const a = await post('/applications', body);
|
|
120
134
|
spinner.succeed(`Application created: ${a.id}`);
|
|
121
135
|
console.log(chalk.gray(` name: ${a.name} version: ${a.version ?? '-'} status: ${statusColor(a.status)}`));
|
|
@@ -181,15 +195,27 @@ export function appsCommand() {
|
|
|
181
195
|
});
|
|
182
196
|
// acf app update <id>
|
|
183
197
|
cmd.command('update <id>')
|
|
184
|
-
.description('Update an application (JSON payload via --
|
|
185
|
-
'Accepted fields: description, version, runtime, status, gitRepo, gitBranch, gitCommit, manifest, env, entrypoint, packageUrl, webhookSecret
|
|
186
|
-
'
|
|
187
|
-
|
|
188
|
-
|
|
198
|
+
.description('Update an application (JSON payload via --body or --file). ' +
|
|
199
|
+
'Accepted fields: description, version, runtime, status, gitRepo, gitBranch, gitCommit, manifest, env, entrypoint, packageUrl, webhookSecret, ' +
|
|
200
|
+
'approvalRequired, mutexGroupId. ' +
|
|
201
|
+
'NOTE: the backend UpdateApplicationDto has no `name` field — renaming is not supported. ' +
|
|
202
|
+
'mutexGroupId takes a group uuid from `acf mutex list` (null detaches); `acf mutex` also manages the groups themselves.')
|
|
203
|
+
.option('--body <json>', 'Application patch body as JSON string (required unless --file is given)')
|
|
204
|
+
.option('--json <body>', 'DEPRECATED (renamed to --body): Application patch body as JSON string. In the next major version --json becomes a boolean output flag')
|
|
205
|
+
.option('--file <path>', 'Read application patch body from a JSON file (overrides --body/--json)')
|
|
189
206
|
.action(async (id, opts) => {
|
|
207
|
+
if (opts.body !== undefined && opts.json !== undefined) {
|
|
208
|
+
emitUsageError('--body and --json (deprecated alias) are mutually exclusive — pass only --body');
|
|
209
|
+
}
|
|
210
|
+
if (opts.body === undefined && opts.json === undefined && !opts.file) {
|
|
211
|
+
emitUsageError('Missing required application patch body — pass --body <json> (or --file <path>)');
|
|
212
|
+
}
|
|
190
213
|
const spinner = ora('Updating application…').start();
|
|
191
214
|
try {
|
|
192
|
-
|
|
215
|
+
if (opts.json !== undefined) {
|
|
216
|
+
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'));
|
|
217
|
+
}
|
|
218
|
+
const body = (await loadJsonBody(opts.json ?? opts.body, opts.file));
|
|
193
219
|
// UpdateApplicationDto has no `name` — with forbidNonWhitelisted the
|
|
194
220
|
// API would answer 400 "property name should not exist". Fail early
|
|
195
221
|
// with an actionable message instead.
|
|
@@ -211,19 +237,9 @@ export function appsCommand() {
|
|
|
211
237
|
.description('Delete an application')
|
|
212
238
|
.option('-y, --yes', 'Skip confirmation prompt', false)
|
|
213
239
|
.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
|
-
}
|
|
240
|
+
// P0(CLI-AGENT-UX-AUDIT):非交互 stdin 下必须显式拒绝,不能静默假绿。
|
|
241
|
+
if (!(await confirmDestructive(`Delete application ${id}?`, { yes: opts.yes })))
|
|
242
|
+
return;
|
|
227
243
|
const spinner = ora('Deleting application…').start();
|
|
228
244
|
try {
|
|
229
245
|
await del(`/applications/${id}`);
|
|
@@ -259,22 +275,56 @@ export function appsCommand() {
|
|
|
259
275
|
}
|
|
260
276
|
});
|
|
261
277
|
// acf app deploy <id>
|
|
278
|
+
//
|
|
279
|
+
// P0(2026-10 开发人员实测):`--run-mode` 的语义此前只列枚举值、不解释
|
|
280
|
+
// 行为差异,且默认值 `daemon` 恰好是"部署即立刻执行入口脚本"的模式——中台
|
|
281
|
+
// 定时触发场景(存量部署 11/12 是 scheduled)按"部署 = 待命"理解却不传 -m,
|
|
282
|
+
// 部署时自跑了一次完整任务,28s 后再 trigger 又跑一次,两边并发写同一云盘
|
|
283
|
+
// 目录。修复三管齐下:
|
|
284
|
+
// ① 默认值改为 `scheduled`(仅下发、由中台/定时触发,部署后不自跑);
|
|
285
|
+
// ② 帮助文本写清三档的真实行为(语义见 docs/deployment.md §runMode);
|
|
286
|
+
// ③ 显式传 once/daemon 时在发请求前打黄色预警"将立刻启动入口脚本"。
|
|
287
|
+
// `deploy-only` 是 scheduled 的自解释别名("仅部署、不自动运行")——服务端
|
|
288
|
+
// RunMode 枚举没有该值,CLI 在本地归一为 scheduled 后发送。
|
|
262
289
|
cmd.command('deploy <id>')
|
|
263
290
|
.description('Deploy an application to an executor (auto-selects the lowest-load online executor when --executor is omitted)')
|
|
264
291
|
.option('-e, --executor <executorId>', 'Pin to a specific executor')
|
|
265
|
-
.option('-m, --run-mode <mode>', 'Run mode: once | daemon | scheduled',
|
|
292
|
+
.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) => {
|
|
293
|
+
const m = v.toLowerCase();
|
|
294
|
+
if (!['once', 'daemon', 'scheduled', 'deploy-only'].includes(m)) {
|
|
295
|
+
throw new InvalidArgumentError('must be one of: once | daemon | scheduled | deploy-only (deploy-only = scheduled — deploy without auto-run)');
|
|
296
|
+
}
|
|
297
|
+
return m;
|
|
298
|
+
}, 'scheduled')
|
|
266
299
|
.option('--env <json>', 'Env var overrides as JSON, e.g. \'{"KEY":"value"}\'')
|
|
267
300
|
.option('--start-command <cmd>', 'Startup command override (defaults to manifest entrypoint)')
|
|
268
301
|
.action(async (id, opts) => {
|
|
302
|
+
// deploy-only → scheduled:本地别名归一(服务端 RunMode 枚举无 deploy-only)。
|
|
303
|
+
const runMode = opts.runMode === 'deploy-only' ? 'scheduled' : opts.runMode;
|
|
304
|
+
if (runMode === 'daemon' || runMode === 'once') {
|
|
305
|
+
// 预警在请求发出之前给出:once/daemon 会在部署时立刻启动入口脚本
|
|
306
|
+
//(daemon 异常退出还会自动重启)——"部署即跑"是双跑事故的根源。
|
|
307
|
+
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`));
|
|
308
|
+
}
|
|
269
309
|
const spinner = ora('Triggering deployment…').start();
|
|
270
310
|
try {
|
|
271
|
-
const body = { runMode
|
|
311
|
+
const body = { runMode };
|
|
272
312
|
if (opts.executor)
|
|
273
313
|
body.executorId = opts.executor;
|
|
274
|
-
if (opts.env)
|
|
275
|
-
body.env = JSON.parse(opts.env);
|
|
276
314
|
if (opts.startCommand)
|
|
277
315
|
body.startCommand = opts.startCommand;
|
|
316
|
+
// P2(CLI-AGENT-UX-AUDIT):--env 的 JSON 解析此前裸放在 try 里,坏 JSON
|
|
317
|
+
// 被当成「部署失败」报退出码 1——agent 会去查服务端日志,而实际是自己
|
|
318
|
+
// 参数写错了。与 `task trigger --params` 同口径:本地 payload 错误是
|
|
319
|
+
// 用法错误(退出码 2),且请求不发出。
|
|
320
|
+
if (opts.env) {
|
|
321
|
+
try {
|
|
322
|
+
body.env = JSON.parse(opts.env);
|
|
323
|
+
}
|
|
324
|
+
catch (err) {
|
|
325
|
+
throw new UsageError(`Invalid --env JSON: ${err instanceof Error ? err.message : String(err)}`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
278
328
|
const dep = await post(`/app-deployments/applications/${id}/deploy`, body);
|
|
279
329
|
spinner.succeed('Deployment triggered');
|
|
280
330
|
console.log(chalk.gray(` deployment: ${dep?.id ?? '-'} status: ${dep?.status ?? '-'} executor: ${dep?.executorId ?? 'auto'}`));
|
|
@@ -285,10 +335,10 @@ export function appsCommand() {
|
|
|
285
335
|
});
|
|
286
336
|
// P2: acf app upgrade-all <appId> —— POST /applications/:id/upgrade-all(DEP-02
|
|
287
337
|
// 灰度)。契约:请求体全可选,缺省(不传 body)= all 全量升级,既有语义逐字节
|
|
288
|
-
// 保持;canary 传 { rollout: { strategy: 'canary', percentage? } }
|
|
289
|
-
// UpgradeAllDto
|
|
290
|
-
//
|
|
291
|
-
//
|
|
338
|
+
// 保持;canary 传 { rollout: { strategy: 'canary', percentage? } }。
|
|
339
|
+
// 2026-10-07:UpgradeAllDto 增可选 version(版本定向灰度/渐进回滚)——
|
|
340
|
+
// --version <v> 时 body 带顶层 version;缺省不带(升级目标恒为应用当前版本)。
|
|
341
|
+
// 批次由服务端异步推进(心跳确认 → 健康探测 → 提升),受理 ≠ 完成。
|
|
292
342
|
cmd.command('upgrade-all <appId>')
|
|
293
343
|
.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
344
|
.option('--strategy <strategy>', 'Rollout strategy: all (default) | canary (first batch → heartbeat confirm → health probe → auto-promote the rest, DEP-02)')
|
|
@@ -301,6 +351,7 @@ export function appsCommand() {
|
|
|
301
351
|
})
|
|
302
352
|
.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
353
|
.option('--json', 'Emit raw JSON (CI-consumable)')
|
|
354
|
+
.option('-y, --yes', 'Skip the confirmation prompt for a FULL upgrade (all strategy)', false)
|
|
304
355
|
.action(async (appId, opts) => {
|
|
305
356
|
const strategy = opts.strategy ?? 'all';
|
|
306
357
|
if (strategy !== 'all' && strategy !== 'canary') {
|
|
@@ -309,6 +360,14 @@ export function appsCommand() {
|
|
|
309
360
|
if (opts.percentage !== undefined && strategy !== 'canary') {
|
|
310
361
|
emitUsageError('--percentage only applies to --strategy canary (the full-upgrade path never reads it)');
|
|
311
362
|
}
|
|
363
|
+
// P1(CLI-AGENT-UX-AUDIT):全量滚动升级会重启该应用**所有 RUNNING 部署**,
|
|
364
|
+
// 此前零确认。canary 天然是低风险首步(且服务端会自动提升/回滚),不设门;
|
|
365
|
+
// all 是「一次性动全量」,需要显式表态——与三处 delete 共用同一套非交互语义。
|
|
366
|
+
if (strategy === 'all') {
|
|
367
|
+
if (!(await confirmDestructive(`Roll out the upgrade to ALL running deployments of ${appId}?`, { yes: opts.yes }))) {
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
312
371
|
const spinner = ora('Triggering upgrade…').start();
|
|
313
372
|
try {
|
|
314
373
|
// all:不传 body —— 与既有全量升级语义逐字节一致;canary:rollout
|
|
@@ -441,5 +500,49 @@ export function appsCommand() {
|
|
|
441
500
|
emitError('Failed to list versions', e, { spinner });
|
|
442
501
|
}
|
|
443
502
|
});
|
|
503
|
+
cmd.command('releases <appId>')
|
|
504
|
+
.description('List unified release history (version × latest deployment) for an application — the modern DEP-01 view; `app versions` is the legacy alias')
|
|
505
|
+
.option('-p, --page <n>', 'Page number', '1')
|
|
506
|
+
.option('-n, --page-size <n>', 'Page size (max 200, default 50)', '50')
|
|
507
|
+
// --json 补面(UX 统一):列表/信封形态 → 单行紧凑 JSON
|
|
508
|
+
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
509
|
+
.action(async (appId, opts) => {
|
|
510
|
+
const spinner = ora('Fetching releases…').start();
|
|
511
|
+
try {
|
|
512
|
+
// getReleases returns `{ data, total, page, pageSize }`
|
|
513
|
+
const data = await get(`/applications/${appId}/releases`, { page: opts.page, pageSize: opts.pageSize });
|
|
514
|
+
spinner.stop();
|
|
515
|
+
if (opts.json) {
|
|
516
|
+
console.log(JSON.stringify(data));
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
const list = Array.isArray(data) ? data : (data.data ?? data.list ?? []);
|
|
520
|
+
if (!list.length) {
|
|
521
|
+
console.log(chalk.gray('No releases recorded for this application.'));
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
const table = new Table({
|
|
525
|
+
head: ['Version', 'Deployed', 'Status', 'Count', 'Executor', 'RunMode', 'Trigger'],
|
|
526
|
+
colWidths: [12, 20, 12, 8, 18, 10, 12],
|
|
527
|
+
style: { head: ['cyan'] },
|
|
528
|
+
});
|
|
529
|
+
for (const r of list) {
|
|
530
|
+
table.push([
|
|
531
|
+
r.version ?? '-',
|
|
532
|
+
r.deployedAt ? new Date(r.deployedAt).toLocaleString() : '-',
|
|
533
|
+
statusColor(r.deploymentStatus ?? r.status),
|
|
534
|
+
String(r.deploymentCount),
|
|
535
|
+
r.executorAddress ?? '-',
|
|
536
|
+
r.runMode ?? '-',
|
|
537
|
+
r.triggerType ?? '-',
|
|
538
|
+
]);
|
|
539
|
+
}
|
|
540
|
+
console.log(table.toString());
|
|
541
|
+
console.log(chalk.gray(`Total: ${data.total ?? list.length} page ${opts.page}`));
|
|
542
|
+
}
|
|
543
|
+
catch (e) {
|
|
544
|
+
emitError('Failed to list releases', e, { spinner });
|
|
545
|
+
}
|
|
546
|
+
});
|
|
444
547
|
return cmd;
|
|
445
548
|
}
|
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);
|