@autocodeflow/cli 1.7.0 → 1.9.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/LICENSE +21 -0
- package/README.md +104 -0
- package/dist/client.d.ts +37 -0
- package/dist/client.js +56 -1
- package/dist/commands/agent.js +9 -4
- package/dist/commands/apikeys.d.ts +2 -0
- package/dist/commands/apikeys.js +104 -0
- package/dist/commands/approval.d.ts +2 -0
- package/dist/commands/approval.js +122 -0
- package/dist/commands/apps.js +186 -35
- package/dist/commands/audit.js +3 -4
- package/dist/commands/deploy.js +4 -7
- package/dist/commands/exec.js +4 -5
- package/dist/commands/executors.js +13 -14
- package/dist/commands/login.d.ts +5 -0
- package/dist/commands/login.js +93 -24
- package/dist/commands/projects.js +4 -7
- package/dist/commands/sop.js +17 -8
- package/dist/commands/tasks.d.ts +6 -0
- package/dist/commands/tasks.js +398 -77
- package/dist/config.js +65 -2
- package/dist/help.d.ts +21 -0
- package/dist/help.js +151 -0
- package/dist/index.d.ts +41 -1
- package/dist/index.js +90 -11
- package/dist/ui.d.ts +55 -0
- package/dist/ui.js +87 -0
- package/package.json +1 -1
package/dist/commands/apps.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { Command } from 'commander';
|
|
1
|
+
import { Command, InvalidArgumentError } from 'commander';
|
|
2
2
|
import Table from 'cli-table3';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import ora from 'ora';
|
|
5
|
-
import
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import { get, post, put, del, ANALYZE_TIMEOUT_MS, UPLOAD_TIMEOUT_MS } from '../client.js';
|
|
7
|
+
import { emitError, emitUsageError, UsageError, interruptExit } from '../ui.js';
|
|
6
8
|
function statusColor(s) {
|
|
7
9
|
if (s === 'running')
|
|
8
10
|
return chalk.green(s);
|
|
@@ -17,15 +19,23 @@ function statusColor(s) {
|
|
|
17
19
|
/** Load a JSON payload from --file (preferred) or --json. */
|
|
18
20
|
async function loadJsonBody(json, file) {
|
|
19
21
|
const fs = await import('fs/promises');
|
|
20
|
-
|
|
22
|
+
// 本地 payload 层错误(文件读不了/JSON 坏)= 用法错误(退出码 2),与
|
|
23
|
+
// 服务端拒绝(1)区分;tasks.ts 的 create/update 同口径。
|
|
24
|
+
let raw;
|
|
25
|
+
try {
|
|
26
|
+
raw = file ? await fs.readFile(file, 'utf-8') : json;
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
throw new UsageError(`Cannot read payload file: ${file} (${err instanceof Error ? err.message : String(err)})`);
|
|
30
|
+
}
|
|
21
31
|
if (raw === undefined) {
|
|
22
|
-
throw new
|
|
32
|
+
throw new UsageError('Missing JSON payload (provide --json or --file)');
|
|
23
33
|
}
|
|
24
34
|
try {
|
|
25
35
|
return JSON.parse(raw);
|
|
26
36
|
}
|
|
27
37
|
catch (e) {
|
|
28
|
-
throw new
|
|
38
|
+
throw new UsageError(`Invalid JSON payload: ${e instanceof Error ? e.message : String(e)}`);
|
|
29
39
|
}
|
|
30
40
|
}
|
|
31
41
|
export function appsCommand() {
|
|
@@ -63,19 +73,23 @@ export function appsCommand() {
|
|
|
63
73
|
console.log(table.toString());
|
|
64
74
|
}
|
|
65
75
|
catch (e) {
|
|
66
|
-
|
|
67
|
-
console.error(chalk.red(formatApiError(e)));
|
|
68
|
-
process.exit(1);
|
|
76
|
+
emitError('Failed to list applications', e, { spinner });
|
|
69
77
|
}
|
|
70
78
|
});
|
|
71
79
|
// acf app get <id>
|
|
72
80
|
cmd.command('get <id>')
|
|
73
81
|
.description('Show application details')
|
|
74
|
-
|
|
82
|
+
// --json 补面(本轮 UX 统一):单对象形态 → pretty JSON
|
|
83
|
+
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
84
|
+
.action(async (id, opts) => {
|
|
75
85
|
const spinner = ora('Fetching application…').start();
|
|
76
86
|
try {
|
|
77
87
|
const a = await get(`/applications/${id}`);
|
|
78
88
|
spinner.stop();
|
|
89
|
+
if (opts.json) {
|
|
90
|
+
console.log(JSON.stringify(a, null, 2));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
79
93
|
console.log(chalk.bold('Application Details'));
|
|
80
94
|
console.log(' ID :', a.id);
|
|
81
95
|
console.log(' Name :', a.name);
|
|
@@ -90,9 +104,7 @@ export function appsCommand() {
|
|
|
90
104
|
console.log(' Description :', a.description ?? '-');
|
|
91
105
|
}
|
|
92
106
|
catch (e) {
|
|
93
|
-
|
|
94
|
-
console.error(chalk.red(formatApiError(e)));
|
|
95
|
-
process.exit(1);
|
|
107
|
+
emitError('Failed', e, { spinner });
|
|
96
108
|
}
|
|
97
109
|
});
|
|
98
110
|
// acf app create
|
|
@@ -109,9 +121,62 @@ export function appsCommand() {
|
|
|
109
121
|
console.log(chalk.gray(` name: ${a.name} version: ${a.version ?? '-'} status: ${statusColor(a.status)}`));
|
|
110
122
|
}
|
|
111
123
|
catch (e) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
124
|
+
emitError('Failed to create application', e, { spinner });
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
// P2: acf app upload <zip> —— POST /applications/upload(multipart/form-data,
|
|
128
|
+
// 按名称 upsert:应用已存在只更新 packageUrl(可选 runtime/version),不存在
|
|
129
|
+
// 则创建)。入参白名单以服务端 UploadApplicationDto 为准:file/name 必填、
|
|
130
|
+
// runtime/version 可选——forbidNonWhitelisted 下多一个字段都 400,故可选字段
|
|
131
|
+
// 只在用户给出时才 append。zip 魔数/大小/zip 炸弹校验是服务端职责(400/503
|
|
132
|
+
// 契约语义),CLI 不复刻,只做廉价的扩展名/可读性预检(退出码 2,请求不发)。
|
|
133
|
+
cmd.command('upload <zip>')
|
|
134
|
+
.description('Upload an application package (.zip, max 200 MB) and upsert it by name: an existing app only gets its packageUrl (and runtime/version) updated, a new one is created. ZIP magic/size/zip-bomb checks are server-side')
|
|
135
|
+
.requiredOption('--name <name>', 'Application name (1-100 chars) — the upsert key')
|
|
136
|
+
.option('--runtime <runtime>', 'Runtime type (max 50 chars; a NEW app defaults to python when omitted)')
|
|
137
|
+
.option('--version <version>', 'Version to record for this upload (e.g. 1.2.0); omit to keep the current version')
|
|
138
|
+
.option('--json', 'Emit raw JSON (CI-consumable)')
|
|
139
|
+
.action(async (zip, opts) => {
|
|
140
|
+
const spinner = ora('Uploading package…').start();
|
|
141
|
+
try {
|
|
142
|
+
if (!/\.zip$/i.test(zip)) {
|
|
143
|
+
throw new UsageError(`Only .zip packages are accepted (got "${zip}") — the server validates both extension and ZIP magic`);
|
|
144
|
+
}
|
|
145
|
+
const fsPromises = await import('fs/promises');
|
|
146
|
+
let buf;
|
|
147
|
+
try {
|
|
148
|
+
buf = await fsPromises.readFile(zip);
|
|
149
|
+
}
|
|
150
|
+
catch (err) {
|
|
151
|
+
// 本地文件层错误 = 用法错误(退出码 2),与服务端拒绝(1)区分;
|
|
152
|
+
// 口径与 loadJsonBody / task import 一致。
|
|
153
|
+
throw new UsageError(`Cannot read package file: ${zip} (${err instanceof Error ? err.message : String(err)})`);
|
|
154
|
+
}
|
|
155
|
+
// Node 内置 FormData/Blob(undici,Node >=18 全局可用):axios 1.x 识别
|
|
156
|
+
// spec FormData 后自动补 multipart boundary 与 Content-Type,无需引入
|
|
157
|
+
// form-data 依赖。字段名 file/name/runtime/version 是服务端 multer +
|
|
158
|
+
// DTO 白名单;不手动设 Content-Type(会把 boundary 写死)。
|
|
159
|
+
const form = new FormData();
|
|
160
|
+
form.append('file', new Blob([buf], { type: 'application/zip' }), path.basename(zip));
|
|
161
|
+
form.append('name', opts.name);
|
|
162
|
+
if (opts.runtime)
|
|
163
|
+
form.append('runtime', opts.runtime);
|
|
164
|
+
if (opts.version)
|
|
165
|
+
form.append('version', opts.version);
|
|
166
|
+
// NETOPT-6④ 同款思路:200MB 上限下实例默认 30s 结构性不够,用
|
|
167
|
+
// UPLOAD_TIMEOUT_MS(300s)per-call 覆盖。
|
|
168
|
+
const a = await post('/applications/upload', form, UPLOAD_TIMEOUT_MS);
|
|
169
|
+
spinner.stop();
|
|
170
|
+
if (opts.json) {
|
|
171
|
+
// ECO-02:单对象形态 → pretty JSON
|
|
172
|
+
console.log(JSON.stringify(a, null, 2));
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
spinner.succeed(`Package uploaded: ${a.name}`);
|
|
176
|
+
console.log(chalk.gray(` id: ${a.id} version: ${a.version ?? '-'} status: ${statusColor(a.status)} packageUrl: ${a.packageUrl ?? '-'}`));
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
179
|
+
emitError('Failed to upload package', e, { spinner });
|
|
115
180
|
}
|
|
116
181
|
});
|
|
117
182
|
// acf app update <id>
|
|
@@ -129,7 +194,8 @@ export function appsCommand() {
|
|
|
129
194
|
// API would answer 400 "property name should not exist". Fail early
|
|
130
195
|
// with an actionable message instead.
|
|
131
196
|
if (body && typeof body === 'object' && 'name' in body) {
|
|
132
|
-
|
|
197
|
+
// 本地 payload 语义错误 = 用法错误(退出码 2),不必等服务端 400。
|
|
198
|
+
throw new UsageError('Application update does not support renaming: the backend UpdateApplicationDto has no `name` field. ' +
|
|
133
199
|
'Remove "name" from the payload.');
|
|
134
200
|
}
|
|
135
201
|
const a = await put(`/applications/${id}`, body);
|
|
@@ -137,9 +203,7 @@ export function appsCommand() {
|
|
|
137
203
|
console.log(chalk.gray(` name: ${a.name} version: ${a.version ?? '-'} status: ${statusColor(a.status)}`));
|
|
138
204
|
}
|
|
139
205
|
catch (e) {
|
|
140
|
-
|
|
141
|
-
console.error(chalk.red(formatApiError(e)));
|
|
142
|
-
process.exit(1);
|
|
206
|
+
emitError('Failed to update application', e, { spinner });
|
|
143
207
|
}
|
|
144
208
|
});
|
|
145
209
|
// acf app delete <id>
|
|
@@ -150,6 +214,9 @@ export function appsCommand() {
|
|
|
150
214
|
if (!opts.yes) {
|
|
151
215
|
const readline = await import('readline/promises');
|
|
152
216
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
217
|
+
// raw 模式下 Ctrl+C 触发 rl 'SIGINT' 而非进程信号;无监听只会 pause,
|
|
218
|
+
// 确认提示处会假死。接住并走统一中断出口(130)。
|
|
219
|
+
rl.on('SIGINT', () => interruptExit());
|
|
153
220
|
const answer = await rl.question(`Delete application ${id}? [y/N] `);
|
|
154
221
|
rl.close();
|
|
155
222
|
if (!/^y(es)?$/i.test(answer)) {
|
|
@@ -163,9 +230,7 @@ export function appsCommand() {
|
|
|
163
230
|
spinner.succeed(`Application ${id} deleted`);
|
|
164
231
|
}
|
|
165
232
|
catch (e) {
|
|
166
|
-
|
|
167
|
-
console.error(chalk.red(formatApiError(e)));
|
|
168
|
-
process.exit(1);
|
|
233
|
+
emitError('Failed to delete application', e, { spinner });
|
|
169
234
|
}
|
|
170
235
|
});
|
|
171
236
|
// acf app analyze <id>
|
|
@@ -190,9 +255,7 @@ export function appsCommand() {
|
|
|
190
255
|
console.log(result.analysis);
|
|
191
256
|
}
|
|
192
257
|
catch (e) {
|
|
193
|
-
|
|
194
|
-
console.error(chalk.red(formatApiError(e)));
|
|
195
|
-
process.exit(1);
|
|
258
|
+
emitError('Analysis failed', e, { spinner });
|
|
196
259
|
}
|
|
197
260
|
});
|
|
198
261
|
// acf app deploy <id>
|
|
@@ -217,9 +280,89 @@ export function appsCommand() {
|
|
|
217
280
|
console.log(chalk.gray(` deployment: ${dep?.id ?? '-'} status: ${dep?.status ?? '-'} executor: ${dep?.executorId ?? 'auto'}`));
|
|
218
281
|
}
|
|
219
282
|
catch (e) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
283
|
+
emitError('Deployment failed', e, { spinner });
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
// P2: acf app upgrade-all <appId> —— POST /applications/:id/upgrade-all(DEP-02
|
|
287
|
+
// 灰度)。契约:请求体全可选,缺省(不传 body)= all 全量升级,既有语义逐字节
|
|
288
|
+
// 保持;canary 传 { rollout: { strategy: 'canary', percentage? } }。注意
|
|
289
|
+
// UpgradeAllDto 只认 rollout —— 没有 per-call 版本覆盖(升级目标恒为应用当前
|
|
290
|
+
// 版本),发送未声明字段会被 forbidNonWhitelisted 400,故本命令不提供
|
|
291
|
+
// --version。批次由服务端异步推进(心跳确认 → 健康探测 → 提升),受理 ≠ 完成。
|
|
292
|
+
cmd.command('upgrade-all <appId>')
|
|
293
|
+
.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
|
+
.option('--strategy <strategy>', 'Rollout strategy: all (default) | canary (first batch → heartbeat confirm → health probe → auto-promote the rest, DEP-02)')
|
|
295
|
+
.option('--percentage <n>', 'Canary first-batch percentage, int 1-100 (default 50 — first batch = ceil(N × p%), at least 1)', (v) => {
|
|
296
|
+
const n = Number.parseInt(v, 10);
|
|
297
|
+
if (!Number.isInteger(n) || n < 1 || n > 100) {
|
|
298
|
+
throw new InvalidArgumentError('must be an integer between 1 and 100');
|
|
299
|
+
}
|
|
300
|
+
return n;
|
|
301
|
+
})
|
|
302
|
+
.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
|
+
.option('--json', 'Emit raw JSON (CI-consumable)')
|
|
304
|
+
.action(async (appId, opts) => {
|
|
305
|
+
const strategy = opts.strategy ?? 'all';
|
|
306
|
+
if (strategy !== 'all' && strategy !== 'canary') {
|
|
307
|
+
emitUsageError(`Unknown rollout strategy "${strategy}" — expected one of: all | canary`);
|
|
308
|
+
}
|
|
309
|
+
if (opts.percentage !== undefined && strategy !== 'canary') {
|
|
310
|
+
emitUsageError('--percentage only applies to --strategy canary (the full-upgrade path never reads it)');
|
|
311
|
+
}
|
|
312
|
+
const spinner = ora('Triggering upgrade…').start();
|
|
313
|
+
try {
|
|
314
|
+
// all:不传 body —— 与既有全量升级语义逐字节一致;canary:rollout
|
|
315
|
+
// 白名单体,percentage 仅在给出时携带(服务端缺省 50)。
|
|
316
|
+
const body = strategy === 'canary'
|
|
317
|
+
? {
|
|
318
|
+
...(opts.version !== undefined ? { version: opts.version } : {}),
|
|
319
|
+
rollout: {
|
|
320
|
+
strategy,
|
|
321
|
+
...(opts.percentage !== undefined ? { percentage: opts.percentage } : {}),
|
|
322
|
+
},
|
|
323
|
+
}
|
|
324
|
+
: opts.version !== undefined
|
|
325
|
+
? { version: opts.version }
|
|
326
|
+
: undefined;
|
|
327
|
+
const r = await post(`/applications/${appId}/upgrade-all`, body);
|
|
328
|
+
spinner.stop();
|
|
329
|
+
if (opts.json) {
|
|
330
|
+
// ECO-02:响应对象直出(含 rollout 批次信息),退出码语义与下面的人读
|
|
331
|
+
// 路径一致(受理被拒/批次失败 → 1)。
|
|
332
|
+
console.log(JSON.stringify(r, null, 2));
|
|
333
|
+
if (r.ok === false || (r.failed ?? 0) > 0)
|
|
334
|
+
process.exitCode = 1;
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (r.ok === false) {
|
|
338
|
+
// 受理被拒(ARCH-31 在途批次互斥 / canary 首批失败 ok=false,failed=1):
|
|
339
|
+
// HTTP 仍是 2xx,但 CLI 要让 CI 看得见(对齐 task batch 部分失败语义)。
|
|
340
|
+
spinner.fail('Upgrade batch not started');
|
|
341
|
+
console.error(chalk.red(` ${r.rollout?.blockedReason ?? `first canary batch failed (${r.failed}/${r.total}) — see rolloutMeta on the app's deployments for the reason`}`));
|
|
342
|
+
process.exitCode = 1;
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (strategy === 'canary') {
|
|
346
|
+
spinner.succeed(`Canary batch accepted: first batch ${r.succeeded}/${r.total} deployment(s)`);
|
|
347
|
+
console.log(chalk.gray(` batchId: ${r.rollout?.batchId ?? '-'} strategy: ${r.rollout?.strategy ?? strategy}`));
|
|
348
|
+
if (r.rollout?.canaryIds?.length) {
|
|
349
|
+
console.log(chalk.gray(` canary: ${r.rollout.canaryIds.map((x) => x.slice(0, 12)).join(', ')}`));
|
|
350
|
+
}
|
|
351
|
+
if (r.rollout?.promotedIds?.length) {
|
|
352
|
+
console.log(chalk.gray(` promoted so far: ${r.rollout.promotedIds.length}`));
|
|
353
|
+
}
|
|
354
|
+
console.log(chalk.yellow(` ⚠ Accepted is not finished — the batch advances asynchronously (heartbeat confirm → health probe → promote). Follow progress in the admin console or: acf app deployments ${appId}`));
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
spinner.succeed(`Upgrade triggered: ${r.succeeded}/${r.total} deployment(s) accepted, ${r.failed} failed`);
|
|
358
|
+
if ((r.failed ?? 0) > 0) {
|
|
359
|
+
console.error(chalk.red(` ${r.failed} deployment(s) failed to accept the upgrade — inspect with: acf app deployments ${appId}`));
|
|
360
|
+
process.exitCode = 1;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
catch (e) {
|
|
365
|
+
emitError('Failed to trigger upgrade-all', e, { spinner });
|
|
223
366
|
}
|
|
224
367
|
});
|
|
225
368
|
// acf app deployments [appId]
|
|
@@ -227,6 +370,8 @@ export function appsCommand() {
|
|
|
227
370
|
.description('List deployments (optionally filtered by application)')
|
|
228
371
|
.option('-p, --page <n>', 'Page number', '1')
|
|
229
372
|
.option('-n, --page-size <n>', 'Page size', '20')
|
|
373
|
+
// --json 补面(本轮 UX 统一):列表/信封形态 → 单行紧凑 JSON
|
|
374
|
+
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
230
375
|
.action(async (appId, opts) => {
|
|
231
376
|
const spinner = ora('Fetching deployments…').start();
|
|
232
377
|
try {
|
|
@@ -237,6 +382,10 @@ export function appsCommand() {
|
|
|
237
382
|
pageSize: opts.pageSize,
|
|
238
383
|
});
|
|
239
384
|
spinner.stop();
|
|
385
|
+
if (opts.json) {
|
|
386
|
+
console.log(JSON.stringify(data));
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
240
389
|
const list = Array.isArray(data) ? data : (data.data ?? data.list ?? []);
|
|
241
390
|
const table = new Table({
|
|
242
391
|
head: ['Deployment', 'App', 'Executor', 'Status', 'RunMode'],
|
|
@@ -255,20 +404,24 @@ export function appsCommand() {
|
|
|
255
404
|
console.log(table.toString());
|
|
256
405
|
}
|
|
257
406
|
catch (e) {
|
|
258
|
-
|
|
259
|
-
console.error(chalk.red(formatApiError(e)));
|
|
260
|
-
process.exit(1);
|
|
407
|
+
emitError('Failed to list deployments', e, { spinner });
|
|
261
408
|
}
|
|
262
409
|
});
|
|
263
410
|
// acf app versions <id>
|
|
264
411
|
cmd.command('versions <id>')
|
|
265
412
|
.description('Show application version history')
|
|
266
|
-
|
|
413
|
+
// --json 补面(本轮 UX 统一):数组形态 → pretty JSON
|
|
414
|
+
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
415
|
+
.action(async (id, opts) => {
|
|
267
416
|
const spinner = ora('Fetching version history…').start();
|
|
268
417
|
try {
|
|
269
418
|
// getVersionHistory returns `commit` / `deployedAt` (no gitCommit / changeNote)
|
|
270
419
|
const versions = await get(`/applications/${id}/versions`);
|
|
271
420
|
spinner.stop();
|
|
421
|
+
if (opts.json) {
|
|
422
|
+
console.log(JSON.stringify(versions, null, 2));
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
272
425
|
const table = new Table({
|
|
273
426
|
head: ['Version', 'Commit', 'Deployed', 'Status'],
|
|
274
427
|
colWidths: [12, 14, 25, 12],
|
|
@@ -285,9 +438,7 @@ export function appsCommand() {
|
|
|
285
438
|
console.log(table.toString());
|
|
286
439
|
}
|
|
287
440
|
catch (e) {
|
|
288
|
-
|
|
289
|
-
console.error(chalk.red(formatApiError(e)));
|
|
290
|
-
process.exit(1);
|
|
441
|
+
emitError('Failed to list versions', e, { spinner });
|
|
291
442
|
}
|
|
292
443
|
});
|
|
293
444
|
return cmd;
|
package/dist/commands/audit.js
CHANGED
|
@@ -2,7 +2,8 @@ import { Command } from 'commander';
|
|
|
2
2
|
import Table from 'cli-table3';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import ora from 'ora';
|
|
5
|
-
import { get
|
|
5
|
+
import { get } from '../client.js';
|
|
6
|
+
import { emitError } from '../ui.js';
|
|
6
7
|
function resultColor(r) {
|
|
7
8
|
if (r === 'success')
|
|
8
9
|
return chalk.green(r);
|
|
@@ -69,9 +70,7 @@ export function auditCommand() {
|
|
|
69
70
|
console.log(chalk.gray(`Total: ${total} page ${opts.page}`));
|
|
70
71
|
}
|
|
71
72
|
catch (e) {
|
|
72
|
-
|
|
73
|
-
console.error(chalk.red(formatApiError(e)));
|
|
74
|
-
process.exit(1);
|
|
73
|
+
emitError('Failed to list audit logs', e, { spinner });
|
|
75
74
|
}
|
|
76
75
|
});
|
|
77
76
|
return cmd;
|
package/dist/commands/deploy.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import ora from 'ora';
|
|
4
|
-
import { post
|
|
4
|
+
import { post } from '../client.js';
|
|
5
|
+
import { emitError } from '../ui.js';
|
|
5
6
|
export function deployCommand() {
|
|
6
7
|
const cmd = new Command('deploy').description('Manage application deployments (upgrade / stop running instances)');
|
|
7
8
|
// acf deploy upgrade <deploymentId>
|
|
@@ -16,9 +17,7 @@ export function deployCommand() {
|
|
|
16
17
|
console.log(chalk.gray(` status: ${dep?.status ?? '-'} executor: ${dep?.executorId ?? '-'}`));
|
|
17
18
|
}
|
|
18
19
|
catch (e) {
|
|
19
|
-
|
|
20
|
-
console.error(chalk.red(formatApiError(e)));
|
|
21
|
-
process.exit(1);
|
|
20
|
+
emitError('Failed to trigger upgrade', e, { spinner });
|
|
22
21
|
}
|
|
23
22
|
});
|
|
24
23
|
// acf deploy stop <deploymentId>
|
|
@@ -33,9 +32,7 @@ export function deployCommand() {
|
|
|
33
32
|
console.log(chalk.gray(` status: ${dep?.status ?? '-'}`));
|
|
34
33
|
}
|
|
35
34
|
catch (e) {
|
|
36
|
-
|
|
37
|
-
console.error(chalk.red(formatApiError(e)));
|
|
38
|
-
process.exit(1);
|
|
35
|
+
emitError('Failed to stop deployment', e, { spinner });
|
|
39
36
|
}
|
|
40
37
|
});
|
|
41
38
|
return cmd;
|
package/dist/commands/exec.js
CHANGED
|
@@ -22,7 +22,7 @@ import axios from 'axios';
|
|
|
22
22
|
import chalk from 'chalk';
|
|
23
23
|
import { get, post } from '../client.js';
|
|
24
24
|
import { getApiUrl } from '../config.js';
|
|
25
|
-
import {
|
|
25
|
+
import { emitError, EXIT_CODES } from '../ui.js';
|
|
26
26
|
const TERMINAL = new Set(['success', 'failed', 'timeout', 'killed', 'cancelled']);
|
|
27
27
|
/**
|
|
28
28
|
* 增量 SSE 解析器:feed(chunk) → 完整消息数组。跨 chunk 半行/半消息安全;
|
|
@@ -147,7 +147,7 @@ export function execCommand() {
|
|
|
147
147
|
clearTimeout(idleTimer);
|
|
148
148
|
idleTimer = setTimeout(() => {
|
|
149
149
|
process.stderr.write(chalk.red(`[tail] no data frame for ${IDLE_TIMEOUT_MS / 1000}s — the stream went silent; retry \`acf exec tail ${execId}\`.\n`));
|
|
150
|
-
process.exit(
|
|
150
|
+
process.exit(EXIT_CODES.NETWORK);
|
|
151
151
|
}, IDLE_TIMEOUT_MS);
|
|
152
152
|
// unref:看门狗不得阻止进程在无其他活动句柄时退出(生产上流挂死
|
|
153
153
|
// 不绑架退出;测试里不残留挂起定时器拖慢 vitest)。
|
|
@@ -179,7 +179,7 @@ export function execCommand() {
|
|
|
179
179
|
process.stderr.write(chalk.red('[tail] log stream interrupted before a done frame — the execution may still be running. Retry with `acf exec tail ' +
|
|
180
180
|
execId +
|
|
181
181
|
'`.\n'));
|
|
182
|
-
process.exitCode =
|
|
182
|
+
process.exitCode = EXIT_CODES.NETWORK;
|
|
183
183
|
});
|
|
184
184
|
stream.on('error', (err) => {
|
|
185
185
|
clearIdleTimer();
|
|
@@ -188,8 +188,7 @@ export function execCommand() {
|
|
|
188
188
|
});
|
|
189
189
|
}
|
|
190
190
|
catch (e) {
|
|
191
|
-
|
|
192
|
-
process.exit(1);
|
|
191
|
+
emitError('tail failed', e);
|
|
193
192
|
}
|
|
194
193
|
});
|
|
195
194
|
return cmd;
|
|
@@ -2,7 +2,8 @@ import { Command } from 'commander';
|
|
|
2
2
|
import Table from 'cli-table3';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
4
|
import ora from 'ora';
|
|
5
|
-
import { get, post
|
|
5
|
+
import { get, post } from '../client.js';
|
|
6
|
+
import { emitError } from '../ui.js';
|
|
6
7
|
function statusColor(s) {
|
|
7
8
|
if (s === 'online')
|
|
8
9
|
return chalk.green(s);
|
|
@@ -69,19 +70,23 @@ export function executorsCommand() {
|
|
|
69
70
|
console.log(table.toString());
|
|
70
71
|
}
|
|
71
72
|
catch (e) {
|
|
72
|
-
|
|
73
|
-
console.error(chalk.red(formatApiError(e)));
|
|
74
|
-
process.exit(1);
|
|
73
|
+
emitError('Failed to list executors', e, { spinner });
|
|
75
74
|
}
|
|
76
75
|
});
|
|
77
76
|
// acf executor get <id>
|
|
78
77
|
cmd.command('get <id>')
|
|
79
78
|
.description('Show details of a single executor (config, status, metrics)')
|
|
80
|
-
|
|
79
|
+
// --json 补面(本轮 UX 统一):单对象形态 → pretty JSON
|
|
80
|
+
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
81
|
+
.action(async (id, opts) => {
|
|
81
82
|
const spinner = ora('Fetching executor…').start();
|
|
82
83
|
try {
|
|
83
84
|
const e = await get(`/executors/${id}`);
|
|
84
85
|
spinner.stop();
|
|
86
|
+
if (opts.json) {
|
|
87
|
+
console.log(JSON.stringify(e, null, 2));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
85
90
|
console.log(chalk.bold('Executor Details'));
|
|
86
91
|
console.log(' ID :', e.id);
|
|
87
92
|
console.log(' App Name :', e.appName ?? '-');
|
|
@@ -102,9 +107,7 @@ export function executorsCommand() {
|
|
|
102
107
|
console.log(' Last Heartbeat :', e.lastHeartbeat ? `${new Date(e.lastHeartbeat).toLocaleString()} (${heartbeatAge(e.lastHeartbeat)})` : '-');
|
|
103
108
|
}
|
|
104
109
|
catch (e) {
|
|
105
|
-
|
|
106
|
-
console.error(chalk.red(formatApiError(e)));
|
|
107
|
-
process.exit(1);
|
|
110
|
+
emitError('Failed to fetch executor', e, { spinner });
|
|
108
111
|
}
|
|
109
112
|
});
|
|
110
113
|
// NF-07: name|id resolution — rotate/offline/set-offline are ADMIN-only
|
|
@@ -147,9 +150,7 @@ export function executorsCommand() {
|
|
|
147
150
|
console.log(chalk.green(r?.token ?? ''));
|
|
148
151
|
}
|
|
149
152
|
catch (e) {
|
|
150
|
-
|
|
151
|
-
console.error(chalk.red(formatApiError(e)));
|
|
152
|
-
process.exit(1);
|
|
153
|
+
emitError('Failed to rotate token', e, { spinner });
|
|
153
154
|
}
|
|
154
155
|
});
|
|
155
156
|
// acf executor offline <name|id>
|
|
@@ -167,9 +168,7 @@ export function executorsCommand() {
|
|
|
167
168
|
console.log(chalk.gray(` status: ${e?.status ?? 'offline'} address: ${e?.address ?? '-'}`));
|
|
168
169
|
}
|
|
169
170
|
catch (e) {
|
|
170
|
-
|
|
171
|
-
console.error(chalk.red(formatApiError(e)));
|
|
172
|
-
process.exit(1);
|
|
171
|
+
emitError('Failed to mark executor offline', e, { spinner });
|
|
173
172
|
}
|
|
174
173
|
});
|
|
175
174
|
return cmd;
|
package/dist/commands/login.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import * as readline from 'readline';
|
|
3
|
+
export declare function maskEcho(rl: readline.Interface, isTTY?: boolean): void;
|
|
4
|
+
export declare function resolveTotpCode(opts: {
|
|
5
|
+
code?: string;
|
|
6
|
+
}, promptFn?: (question: string) => Promise<string>): Promise<string>;
|
|
2
7
|
export declare function loginCommand(): Command;
|