@autocodeflow/cli 1.5.1 → 1.5.3
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/dist/client.js +25 -39
- package/dist/commands/apps.js +53 -83
- package/dist/commands/audit.js +14 -21
- package/dist/commands/deploy.js +14 -21
- package/dist/commands/exec.js +47 -27
- package/dist/commands/executors.js +36 -43
- package/dist/commands/login.js +17 -47
- package/dist/commands/projects.js +20 -27
- package/dist/commands/tasks.js +115 -145
- package/dist/config.js +14 -53
- package/dist/index.js +31 -37
- package/package.json +14 -12
package/dist/commands/exec.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.execCommand = exports.createSseParser = void 0;
|
|
7
1
|
/**
|
|
8
2
|
* ECO-02: acf exec tail <execId> —— 实时跟随执行日志(SSE)。
|
|
9
3
|
*
|
|
@@ -23,18 +17,18 @@ exports.execCommand = exports.createSseParser = void 0;
|
|
|
23
17
|
* 循环在第一轮就 break,打出**空输出**后静默退出。
|
|
24
18
|
* 两者叠加使 `acf exec tail` 在任何路径上都不工作。
|
|
25
19
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
import { Command } from 'commander';
|
|
21
|
+
import axios from 'axios';
|
|
22
|
+
import chalk from 'chalk';
|
|
23
|
+
import { get, post } from '../client.js';
|
|
24
|
+
import { getApiUrl } from '../config.js';
|
|
25
|
+
import { formatApiError } from '../client.js';
|
|
32
26
|
const TERMINAL = new Set(['success', 'failed', 'timeout', 'killed', 'cancelled']);
|
|
33
27
|
/**
|
|
34
28
|
* 增量 SSE 解析器:feed(chunk) → 完整消息数组。跨 chunk 半行/半消息安全;
|
|
35
29
|
* 注释行(: ping)忽略;event 行只影响下一条 data 消息的事件名。
|
|
36
30
|
*/
|
|
37
|
-
function createSseParser(onMessage) {
|
|
31
|
+
export function createSseParser(onMessage) {
|
|
38
32
|
let buffer = '';
|
|
39
33
|
let eventName = 'message';
|
|
40
34
|
let dataLines = [];
|
|
@@ -70,7 +64,6 @@ function createSseParser(onMessage) {
|
|
|
70
64
|
},
|
|
71
65
|
};
|
|
72
66
|
}
|
|
73
|
-
exports.createSseParser = createSseParser;
|
|
74
67
|
/** 把服务端行数组(或旧字符串形态)规整为 string[]。 */
|
|
75
68
|
function toLines(lines) {
|
|
76
69
|
if (Array.isArray(lines))
|
|
@@ -79,15 +72,15 @@ function toLines(lines) {
|
|
|
79
72
|
return lines.split('\n');
|
|
80
73
|
return [];
|
|
81
74
|
}
|
|
82
|
-
function execCommand() {
|
|
83
|
-
const cmd = new
|
|
75
|
+
export function execCommand() {
|
|
76
|
+
const cmd = new Command('exec').description('Follow or inspect executions');
|
|
84
77
|
cmd
|
|
85
78
|
.command('tail <execId>')
|
|
86
79
|
.description('Follow execution logs live (SSE); terminal executions print their logs and exit')
|
|
87
80
|
.option('--json', 'Emit raw JSON lines instead of plain text')
|
|
88
81
|
.action(async (execId, opts) => {
|
|
89
82
|
try {
|
|
90
|
-
const exec = await
|
|
83
|
+
const exec = await get(`/tasks/executions/${execId}`);
|
|
91
84
|
if (!exec?.taskId) {
|
|
92
85
|
throw new Error(`Execution ${execId} not found`);
|
|
93
86
|
}
|
|
@@ -96,7 +89,7 @@ function execCommand() {
|
|
|
96
89
|
let fromLine = 0;
|
|
97
90
|
let printed = 0;
|
|
98
91
|
for (;;) {
|
|
99
|
-
const page = await
|
|
92
|
+
const page = await get(`/tasks/executions/${execId}/logs?fromLine=${fromLine}&limit=2000`);
|
|
100
93
|
const lines = toLines(page?.lines);
|
|
101
94
|
if (lines.length > 0) {
|
|
102
95
|
for (const line of lines) {
|
|
@@ -115,11 +108,11 @@ function execCommand() {
|
|
|
115
108
|
// SEC-CLI-01: 先换一枚 30s TTL 的专用 SSE 票据(走常规 Authorization
|
|
116
109
|
// 头的 POST),再以 ?ticket= 建流——`?access_token=` 通道已被服务端撤销,
|
|
117
110
|
// 旧写法会让每次非终态 tail 直接 401。与 admin-web/src/api/sse.ts 同流程。
|
|
118
|
-
const { ticket } = await
|
|
119
|
-
const base =
|
|
111
|
+
const { ticket } = await post('/auth/sse-ticket');
|
|
112
|
+
const base = getApiUrl().replace(/\/+$/, '');
|
|
120
113
|
const url = `${base}/tasks/${exec.taskId}/executions/${execId}/logs/stream?ticket=${encodeURIComponent(ticket)}`;
|
|
121
|
-
const res = await
|
|
122
|
-
process.stderr.write(
|
|
114
|
+
const res = await axios.get(url, { responseType: 'stream', timeout: 0 });
|
|
115
|
+
process.stderr.write(chalk.gray(`[tail] following execution ${execId} (status: ${exec.status ?? 'unknown'}) — Ctrl+C to detach\n`));
|
|
123
116
|
// NETOPT-2②:done 帧是「日志流完整收尾」的唯一判据。此前 stream
|
|
124
117
|
// 'end' 一律 process.exit(0)——服务端/网络在 done 帧之前断流(反代
|
|
125
118
|
// 超时、进程重启)时,tail 静默以 0 退出,CI 里 `acf exec tail … &&
|
|
@@ -129,7 +122,7 @@ function execCommand() {
|
|
|
129
122
|
const parser = createSseParser((msg) => {
|
|
130
123
|
if (msg.event === 'done') {
|
|
131
124
|
sawDone = true;
|
|
132
|
-
process.stderr.write(
|
|
125
|
+
process.stderr.write(chalk.gray('[tail] done\n'));
|
|
133
126
|
process.exit(0);
|
|
134
127
|
}
|
|
135
128
|
if (msg.event !== 'message')
|
|
@@ -143,11 +136,38 @@ function execCommand() {
|
|
|
143
136
|
process.stdout.write(msg.data + '\n');
|
|
144
137
|
}
|
|
145
138
|
});
|
|
139
|
+
// D1-P2-3: 客户端空闲兜底。SSE 长连在反代静默丢包 / 执行器卡死 /
|
|
140
|
+
// 网络静默分区时既不 end 也不发帧——旧代码会永久挂起(CI/脚本里 tail
|
|
141
|
+
// 永不返回)。自收到首帧起,任意数据帧重置窗口;连续 60s 无任何数据帧
|
|
142
|
+
// 即判静默,以非零码退出并提示重连。
|
|
143
|
+
const IDLE_TIMEOUT_MS = 60_000;
|
|
144
|
+
let idleTimer;
|
|
145
|
+
const armIdleTimer = () => {
|
|
146
|
+
if (idleTimer)
|
|
147
|
+
clearTimeout(idleTimer);
|
|
148
|
+
idleTimer = setTimeout(() => {
|
|
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(1);
|
|
151
|
+
}, IDLE_TIMEOUT_MS);
|
|
152
|
+
// unref:看门狗不得阻止进程在无其他活动句柄时退出(生产上流挂死
|
|
153
|
+
// 不绑架退出;测试里不残留挂起定时器拖慢 vitest)。
|
|
154
|
+
if (typeof idleTimer.unref === 'function')
|
|
155
|
+
idleTimer.unref();
|
|
156
|
+
};
|
|
157
|
+
const clearIdleTimer = () => {
|
|
158
|
+
if (idleTimer) {
|
|
159
|
+
clearTimeout(idleTimer);
|
|
160
|
+
idleTimer = undefined;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
armIdleTimer();
|
|
146
164
|
const stream = res.data;
|
|
147
165
|
stream.on('data', (chunk) => {
|
|
166
|
+
armIdleTimer(); // 任意数据帧(含心跳注释行)都重置空闲窗口
|
|
148
167
|
parser.feed(chunk.toString('utf-8'));
|
|
149
168
|
});
|
|
150
169
|
stream.on('end', () => {
|
|
170
|
+
clearIdleTimer();
|
|
151
171
|
if (sawDone) {
|
|
152
172
|
process.exit(0);
|
|
153
173
|
// 防穿透:测试里 process.exit 常被钉成桩(正常返回),结构上
|
|
@@ -156,21 +176,21 @@ function execCommand() {
|
|
|
156
176
|
}
|
|
157
177
|
// 断流且没有 done 帧:执行可能仍在运行。用 exitCode 赋值而非
|
|
158
178
|
// process.exit(1),让事件循环自然收尾(流已 end,无挂起句柄)。
|
|
159
|
-
process.stderr.write(
|
|
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 ' +
|
|
160
180
|
execId +
|
|
161
181
|
'`.\n'));
|
|
162
182
|
process.exitCode = 1;
|
|
163
183
|
});
|
|
164
184
|
stream.on('error', (err) => {
|
|
165
|
-
|
|
185
|
+
clearIdleTimer();
|
|
186
|
+
process.stderr.write(chalk.red(`[tail] stream error: ${err.message}\n`));
|
|
166
187
|
process.exit(1);
|
|
167
188
|
});
|
|
168
189
|
}
|
|
169
190
|
catch (e) {
|
|
170
|
-
console.error(
|
|
191
|
+
console.error(chalk.red('✗ tail failed:'), formatApiError(e));
|
|
171
192
|
process.exit(1);
|
|
172
193
|
}
|
|
173
194
|
});
|
|
174
195
|
return cmd;
|
|
175
196
|
}
|
|
176
|
-
exports.execCommand = execCommand;
|
|
@@ -1,30 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.executorsCommand = void 0;
|
|
7
|
-
const commander_1 = require("commander");
|
|
8
|
-
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
9
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
-
const ora_1 = __importDefault(require("ora"));
|
|
11
|
-
const client_1 = require("../client");
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import Table from 'cli-table3';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import ora from 'ora';
|
|
5
|
+
import { get, post, formatApiError } from '../client.js';
|
|
12
6
|
function statusColor(s) {
|
|
13
7
|
if (s === 'online')
|
|
14
|
-
return
|
|
8
|
+
return chalk.green(s);
|
|
15
9
|
if (s === 'offline')
|
|
16
|
-
return
|
|
17
|
-
return
|
|
10
|
+
return chalk.red(s);
|
|
11
|
+
return chalk.yellow(s);
|
|
18
12
|
}
|
|
19
13
|
function heartbeatAge(ts) {
|
|
20
14
|
if (!ts)
|
|
21
15
|
return '-';
|
|
22
16
|
const diff = Date.now() - new Date(ts).getTime();
|
|
23
|
-
if (diff <
|
|
24
|
-
return
|
|
25
|
-
if (diff <
|
|
26
|
-
return
|
|
27
|
-
return
|
|
17
|
+
if (diff < 60_000)
|
|
18
|
+
return chalk.green(`${Math.round(diff / 1000)}s ago`);
|
|
19
|
+
if (diff < 300_000)
|
|
20
|
+
return chalk.yellow(`${Math.round(diff / 60000)}m ago`);
|
|
21
|
+
return chalk.red(`${Math.round(diff / 60000)}m ago`);
|
|
28
22
|
}
|
|
29
23
|
function pct(v) {
|
|
30
24
|
return v === null || v === undefined ? '-' : `${v}%`;
|
|
@@ -33,22 +27,22 @@ function pct(v) {
|
|
|
33
27
|
// ExecutorDetailPage semantics for the heartbeat-reported id list.
|
|
34
28
|
function runningExecutionIdsText(ids) {
|
|
35
29
|
if (ids === null || ids === undefined) {
|
|
36
|
-
return
|
|
30
|
+
return chalk.gray('not reported (older executor)');
|
|
37
31
|
}
|
|
38
32
|
if (ids.length === 0) {
|
|
39
|
-
return
|
|
33
|
+
return chalk.gray('idle (none running)');
|
|
40
34
|
}
|
|
41
35
|
return `${ids.length} running: ${ids.join(', ')}`;
|
|
42
36
|
}
|
|
43
|
-
function executorsCommand() {
|
|
44
|
-
const cmd = new
|
|
37
|
+
export function executorsCommand() {
|
|
38
|
+
const cmd = new Command('executor').description('View registered executors');
|
|
45
39
|
cmd.command('list')
|
|
46
40
|
.description('List all executors and their status')
|
|
47
41
|
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
48
42
|
.action(async (opts) => {
|
|
49
|
-
const spinner = (
|
|
43
|
+
const spinner = ora('Fetching executors…').start();
|
|
50
44
|
try {
|
|
51
|
-
const data = await
|
|
45
|
+
const data = await get('/executors');
|
|
52
46
|
spinner.stop();
|
|
53
47
|
if (opts.json) {
|
|
54
48
|
// ECO-02: --json —— CI/脚本消费面
|
|
@@ -56,7 +50,7 @@ function executorsCommand() {
|
|
|
56
50
|
return;
|
|
57
51
|
}
|
|
58
52
|
const executors = Array.isArray(data) ? data : (data.list ?? []);
|
|
59
|
-
const table = new
|
|
53
|
+
const table = new Table({
|
|
60
54
|
head: ['ID', 'App Name', 'Status', 'Address', 'Last Heartbeat', 'CPU', 'Running'],
|
|
61
55
|
colWidths: [14, 20, 10, 22, 18, 8, 9],
|
|
62
56
|
style: { head: ['cyan'] },
|
|
@@ -76,7 +70,7 @@ function executorsCommand() {
|
|
|
76
70
|
}
|
|
77
71
|
catch (e) {
|
|
78
72
|
spinner.fail('Failed');
|
|
79
|
-
console.error(
|
|
73
|
+
console.error(chalk.red(formatApiError(e)));
|
|
80
74
|
process.exit(1);
|
|
81
75
|
}
|
|
82
76
|
});
|
|
@@ -84,11 +78,11 @@ function executorsCommand() {
|
|
|
84
78
|
cmd.command('get <id>')
|
|
85
79
|
.description('Show details of a single executor (config, status, metrics)')
|
|
86
80
|
.action(async (id) => {
|
|
87
|
-
const spinner = (
|
|
81
|
+
const spinner = ora('Fetching executor…').start();
|
|
88
82
|
try {
|
|
89
|
-
const e = await
|
|
83
|
+
const e = await get(`/executors/${id}`);
|
|
90
84
|
spinner.stop();
|
|
91
|
-
console.log(
|
|
85
|
+
console.log(chalk.bold('Executor Details'));
|
|
92
86
|
console.log(' ID :', e.id);
|
|
93
87
|
console.log(' App Name :', e.appName ?? '-');
|
|
94
88
|
console.log(' Address :', e.address ?? '-');
|
|
@@ -109,7 +103,7 @@ function executorsCommand() {
|
|
|
109
103
|
}
|
|
110
104
|
catch (e) {
|
|
111
105
|
spinner.fail('Failed');
|
|
112
|
-
console.error(
|
|
106
|
+
console.error(chalk.red(formatApiError(e)));
|
|
113
107
|
process.exit(1);
|
|
114
108
|
}
|
|
115
109
|
});
|
|
@@ -119,14 +113,14 @@ function executorsCommand() {
|
|
|
119
113
|
async function resolveExecutorId(nameOrId) {
|
|
120
114
|
let exec;
|
|
121
115
|
try {
|
|
122
|
-
exec = await
|
|
116
|
+
exec = await get(`/executors/${nameOrId}`);
|
|
123
117
|
}
|
|
124
118
|
catch {
|
|
125
119
|
exec = undefined;
|
|
126
120
|
}
|
|
127
121
|
if (exec?.id)
|
|
128
122
|
return exec.id;
|
|
129
|
-
const data = await
|
|
123
|
+
const data = await get('/executors');
|
|
130
124
|
const executors = Array.isArray(data) ? data : (data.list ?? []);
|
|
131
125
|
const byName = executors.find((e) => e.appName === nameOrId);
|
|
132
126
|
const byShortId = executors.find((e) => e.id.startsWith(nameOrId));
|
|
@@ -141,20 +135,20 @@ function executorsCommand() {
|
|
|
141
135
|
.description('Rotate an executor token (ADMIN; new token is shown ONCE in this output)')
|
|
142
136
|
.option('--reason <reason>', 'Optional rotation reason (≤200 chars, recorded in the audit log)')
|
|
143
137
|
.action(async (nameOrId, opts) => {
|
|
144
|
-
const spinner = (
|
|
138
|
+
const spinner = ora('Rotating executor token…').start();
|
|
145
139
|
try {
|
|
146
140
|
const id = await resolveExecutorId(nameOrId);
|
|
147
141
|
// POST /executors/:id/rotate-token — ExecutorController.rotateToken
|
|
148
142
|
// (ADMIN-only). Returns { token } — the plaintext is persisted nowhere
|
|
149
143
|
// and never shown again (AUTH-05: optional reason goes to the audit).
|
|
150
|
-
const r = await
|
|
144
|
+
const r = await post(`/executors/${id}/rotate-token`, opts.reason ? { reason: opts.reason } : undefined);
|
|
151
145
|
spinner.succeed(`Token rotated for executor ${id}`);
|
|
152
|
-
console.log(
|
|
153
|
-
console.log(
|
|
146
|
+
console.log(chalk.bold('New token (shown only once — store it now):'));
|
|
147
|
+
console.log(chalk.green(r?.token ?? ''));
|
|
154
148
|
}
|
|
155
149
|
catch (e) {
|
|
156
150
|
spinner.fail('Failed to rotate token');
|
|
157
|
-
console.error(
|
|
151
|
+
console.error(chalk.red(formatApiError(e)));
|
|
158
152
|
process.exit(1);
|
|
159
153
|
}
|
|
160
154
|
});
|
|
@@ -162,22 +156,21 @@ function executorsCommand() {
|
|
|
162
156
|
cmd.command('offline <nameOrId>')
|
|
163
157
|
.description('Mark an executor offline (ADMIN; does not interrupt running tasks — for stale records after a crash)')
|
|
164
158
|
.action(async (nameOrId) => {
|
|
165
|
-
const spinner = (
|
|
159
|
+
const spinner = ora('Marking executor offline…').start();
|
|
166
160
|
try {
|
|
167
161
|
const id = await resolveExecutorId(nameOrId);
|
|
168
162
|
// POST /executors/:id/set-offline — ExecutorController.setOffline
|
|
169
163
|
// (ADMIN-only; distinct from the @Public /executors/offline
|
|
170
164
|
// executor-shutdown callback which is not an admin surface).
|
|
171
|
-
const e = await
|
|
165
|
+
const e = await post(`/executors/${id}/set-offline`);
|
|
172
166
|
spinner.succeed(`Executor ${id} marked offline`);
|
|
173
|
-
console.log(
|
|
167
|
+
console.log(chalk.gray(` status: ${e?.status ?? 'offline'} address: ${e?.address ?? '-'}`));
|
|
174
168
|
}
|
|
175
169
|
catch (e) {
|
|
176
170
|
spinner.fail('Failed to mark executor offline');
|
|
177
|
-
console.error(
|
|
171
|
+
console.error(chalk.red(formatApiError(e)));
|
|
178
172
|
process.exit(1);
|
|
179
173
|
}
|
|
180
174
|
});
|
|
181
175
|
return cmd;
|
|
182
176
|
}
|
|
183
|
-
exports.executorsCommand = executorsCommand;
|
package/dist/commands/login.js
CHANGED
|
@@ -1,38 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.loginCommand = void 0;
|
|
30
|
-
const commander_1 = require("commander");
|
|
31
|
-
const readline = __importStar(require("readline"));
|
|
32
|
-
const client_1 = require("../client");
|
|
33
|
-
const config_1 = require("../config");
|
|
34
|
-
const client_2 = require("../client");
|
|
35
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import * as readline from 'readline';
|
|
3
|
+
import { post, formatApiError } from '../client.js';
|
|
4
|
+
import { setApiUrl, setToken, setRefreshToken, showConfig } from '../config.js';
|
|
5
|
+
import { resetClient } from '../client.js';
|
|
6
|
+
import chalk from 'chalk';
|
|
36
7
|
function prompt(question) {
|
|
37
8
|
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
38
9
|
return new Promise((resolve) => rl.question(question, (ans) => { rl.close(); resolve(ans); }));
|
|
@@ -64,8 +35,8 @@ function hiddenPrompt(question) {
|
|
|
64
35
|
resolve(ans);
|
|
65
36
|
}));
|
|
66
37
|
}
|
|
67
|
-
function loginCommand() {
|
|
68
|
-
const cmd = new
|
|
38
|
+
export function loginCommand() {
|
|
39
|
+
const cmd = new Command('login')
|
|
69
40
|
.description('Authenticate with the AutoCodeFlow API and save credentials')
|
|
70
41
|
.option('--url <url>', 'API base URL (default: http://localhost:3105)')
|
|
71
42
|
.option('--user <username>', 'Username')
|
|
@@ -75,13 +46,13 @@ function loginCommand() {
|
|
|
75
46
|
.action(async (opts) => {
|
|
76
47
|
try {
|
|
77
48
|
const url = opts.url || await prompt('API URL [http://localhost:3105]: ') || 'http://localhost:3105';
|
|
78
|
-
|
|
79
|
-
|
|
49
|
+
setApiUrl(url.trim());
|
|
50
|
+
resetClient();
|
|
80
51
|
const username = opts.user || await prompt('Username: ');
|
|
81
52
|
// PK-27 凭据来源优先级:--password(deprecated,告警) > ACF_PASSWORD env > 隐藏交互 prompt。
|
|
82
53
|
let password;
|
|
83
54
|
if (opts.password) {
|
|
84
|
-
process.stderr.write(
|
|
55
|
+
process.stderr.write(chalk.yellow('⚠ --password 会出现在进程列表与 shell 历史中;CI 场景请改用 ACF_PASSWORD 环境变量。\n'));
|
|
85
56
|
password = opts.password;
|
|
86
57
|
}
|
|
87
58
|
else if (process.env.ACF_PASSWORD) {
|
|
@@ -91,26 +62,25 @@ function loginCommand() {
|
|
|
91
62
|
password = await hiddenPrompt('Password: ');
|
|
92
63
|
}
|
|
93
64
|
// admin-api auth.service.generateTokens returns camelCase { accessToken, refreshToken }
|
|
94
|
-
const data = await
|
|
65
|
+
const data = await post('/auth/login', {
|
|
95
66
|
username: username.trim(),
|
|
96
67
|
password,
|
|
97
68
|
});
|
|
98
69
|
if (!data.accessToken) {
|
|
99
70
|
throw new Error('Login response missing accessToken (unexpected auth payload)');
|
|
100
71
|
}
|
|
101
|
-
|
|
72
|
+
setToken(data.accessToken);
|
|
102
73
|
// BUG-13: refreshToken 一并入库——access token 默认 15m 过期,
|
|
103
74
|
// client 的 401 单飞自愈(/auth/refresh + 重放一次)依赖它,
|
|
104
75
|
// 否则过期后全命令 401 只能重新 login。
|
|
105
|
-
|
|
106
|
-
console.log(
|
|
107
|
-
|
|
76
|
+
setRefreshToken(data.refreshToken ?? '');
|
|
77
|
+
console.log(chalk.green('✔ Logged in successfully'));
|
|
78
|
+
showConfig();
|
|
108
79
|
}
|
|
109
80
|
catch (e) {
|
|
110
|
-
console.error(
|
|
81
|
+
console.error(chalk.red('✗ Login failed:'), formatApiError(e));
|
|
111
82
|
process.exit(1);
|
|
112
83
|
}
|
|
113
84
|
});
|
|
114
85
|
return cmd;
|
|
115
86
|
}
|
|
116
|
-
exports.loginCommand = loginCommand;
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.projectsCommand = void 0;
|
|
7
|
-
const commander_1 = require("commander");
|
|
8
|
-
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
9
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
-
const ora_1 = __importDefault(require("ora"));
|
|
11
|
-
const client_1 = require("../client");
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import Table from 'cli-table3';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import ora from 'ora';
|
|
5
|
+
import { get, formatApiError } from '../client.js';
|
|
12
6
|
const ROLE_COLOR = {
|
|
13
|
-
admin:
|
|
14
|
-
editor:
|
|
15
|
-
viewer:
|
|
7
|
+
admin: chalk.yellow,
|
|
8
|
+
editor: chalk.cyan,
|
|
9
|
+
viewer: chalk.gray,
|
|
16
10
|
};
|
|
17
11
|
function roleText(role) {
|
|
18
12
|
if (!role)
|
|
@@ -23,26 +17,26 @@ function roleText(role) {
|
|
|
23
17
|
* AUTH-02-B(R18):项目域只读命令。读面与后端一致(列表按主体过滤;
|
|
24
18
|
* 成员列表要求成员身份)。成员写面为 ADMIN-only,不在 CLI 暴露。
|
|
25
19
|
*/
|
|
26
|
-
function projectsCommand() {
|
|
27
|
-
const cmd = new
|
|
20
|
+
export function projectsCommand() {
|
|
21
|
+
const cmd = new Command('project').description('Inspect projects and members (read-only)');
|
|
28
22
|
cmd
|
|
29
23
|
.command('list')
|
|
30
24
|
.description('List projects visible to the current credential (with your role)')
|
|
31
25
|
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
32
26
|
.action(async (opts) => {
|
|
33
|
-
const spinner = (
|
|
27
|
+
const spinner = ora('Fetching projects…').start();
|
|
34
28
|
try {
|
|
35
|
-
const rows = (await
|
|
29
|
+
const rows = (await get('/projects'));
|
|
36
30
|
spinner.stop();
|
|
37
31
|
if (opts.json) {
|
|
38
32
|
console.log(JSON.stringify(rows, null, 2));
|
|
39
33
|
return;
|
|
40
34
|
}
|
|
41
35
|
if (!rows.length) {
|
|
42
|
-
console.log(
|
|
36
|
+
console.log(chalk.gray('No projects visible.'));
|
|
43
37
|
return;
|
|
44
38
|
}
|
|
45
|
-
const table = new
|
|
39
|
+
const table = new Table({
|
|
46
40
|
head: ['Name', 'My role', 'Description', 'Created'],
|
|
47
41
|
});
|
|
48
42
|
for (const r of rows) {
|
|
@@ -57,7 +51,7 @@ function projectsCommand() {
|
|
|
57
51
|
}
|
|
58
52
|
catch (e) {
|
|
59
53
|
spinner.stop();
|
|
60
|
-
console.error(
|
|
54
|
+
console.error(chalk.red(formatApiError(e)));
|
|
61
55
|
process.exitCode = 1;
|
|
62
56
|
}
|
|
63
57
|
});
|
|
@@ -66,19 +60,19 @@ function projectsCommand() {
|
|
|
66
60
|
.description('List members (userId + role) of one project')
|
|
67
61
|
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
68
62
|
.action(async (projectId, opts) => {
|
|
69
|
-
const spinner = (
|
|
63
|
+
const spinner = ora('Fetching members…').start();
|
|
70
64
|
try {
|
|
71
|
-
const rows = (await
|
|
65
|
+
const rows = (await get(`/projects/${projectId}/members`));
|
|
72
66
|
spinner.stop();
|
|
73
67
|
if (opts.json) {
|
|
74
68
|
console.log(JSON.stringify(rows, null, 2));
|
|
75
69
|
return;
|
|
76
70
|
}
|
|
77
71
|
if (!rows.length) {
|
|
78
|
-
console.log(
|
|
72
|
+
console.log(chalk.gray('No members.'));
|
|
79
73
|
return;
|
|
80
74
|
}
|
|
81
|
-
const table = new
|
|
75
|
+
const table = new Table({
|
|
82
76
|
head: ['User ID', 'Role', 'Since'],
|
|
83
77
|
});
|
|
84
78
|
for (const r of rows) {
|
|
@@ -88,10 +82,9 @@ function projectsCommand() {
|
|
|
88
82
|
}
|
|
89
83
|
catch (e) {
|
|
90
84
|
spinner.stop();
|
|
91
|
-
console.error(
|
|
85
|
+
console.error(chalk.red(formatApiError(e)));
|
|
92
86
|
process.exitCode = 1;
|
|
93
87
|
}
|
|
94
88
|
});
|
|
95
89
|
return cmd;
|
|
96
90
|
}
|
|
97
|
-
exports.projectsCommand = projectsCommand;
|