@autocodeflow/cli 1.8.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/LICENSE +21 -0
- package/README.md +80 -3
- package/dist/client.d.ts +18 -0
- package/dist/client.js +34 -1
- 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 +266 -28
- 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 +44 -0
- package/dist/commands/login.js +203 -12
- package/dist/commands/tasks.d.ts +16 -0
- package/dist/commands/tasks.js +455 -43
- package/dist/config.d.ts +10 -1
- package/dist/config.js +22 -5
- package/dist/help.js +81 -7
- package/dist/index.d.ts +9 -1
- package/dist/index.js +60 -5
- package/dist/ui.d.ts +25 -0
- package/dist/ui.js +48 -0
- package/package.json +1 -1
package/dist/config.d.ts
CHANGED
|
@@ -24,4 +24,13 @@ export declare function setRefreshToken(token: string): void;
|
|
|
24
24
|
* apiUrl 保留(用户环境不丢)。
|
|
25
25
|
*/
|
|
26
26
|
export declare function clearAuth(): void;
|
|
27
|
-
|
|
27
|
+
/**
|
|
28
|
+
* 打印当前配置。
|
|
29
|
+
*
|
|
30
|
+
* `--json`(P2,CLI-AGENT-UX-AUDIT):agent 排障第一步就是读当前配置,
|
|
31
|
+
* 而此前只能 grep 人读文本。**token 永不明文输出**——只给 set/not set,
|
|
32
|
+
* 与既有 `[set]` 口径一致(凭据本身在文件里,不该顺带打到日志/终端)。
|
|
33
|
+
*/
|
|
34
|
+
export declare function showConfig(opts?: {
|
|
35
|
+
json?: boolean;
|
|
36
|
+
}): void;
|
package/dist/config.js
CHANGED
|
@@ -176,9 +176,26 @@ export function clearAuth() {
|
|
|
176
176
|
store.set('token', '');
|
|
177
177
|
store.set('refreshToken', '');
|
|
178
178
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
179
|
+
/**
|
|
180
|
+
* 打印当前配置。
|
|
181
|
+
*
|
|
182
|
+
* `--json`(P2,CLI-AGENT-UX-AUDIT):agent 排障第一步就是读当前配置,
|
|
183
|
+
* 而此前只能 grep 人读文本。**token 永不明文输出**——只给 set/not set,
|
|
184
|
+
* 与既有 `[set]` 口径一致(凭据本身在文件里,不该顺带打到日志/终端)。
|
|
185
|
+
*/
|
|
186
|
+
export function showConfig(opts = {}) {
|
|
187
|
+
const snapshot = {
|
|
188
|
+
apiUrl: getApiUrl(),
|
|
189
|
+
token: getToken() ? '[set]' : '[not set]',
|
|
190
|
+
refreshToken: getRefreshToken() ? '[set]' : '[not set]',
|
|
191
|
+
configFile: store.path,
|
|
192
|
+
};
|
|
193
|
+
if (opts.json) {
|
|
194
|
+
console.log(JSON.stringify(snapshot));
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
console.log('API URL :', snapshot.apiUrl);
|
|
198
|
+
console.log('Token :', snapshot.token);
|
|
199
|
+
console.log('Refresh :', snapshot.refreshToken);
|
|
200
|
+
console.log('Config file:', snapshot.configFile);
|
|
184
201
|
}
|
package/dist/help.js
CHANGED
|
@@ -4,18 +4,28 @@ export const EXAMPLES = {
|
|
|
4
4
|
'acf task trigger <taskId> --wait',
|
|
5
5
|
'acf exec tail <execId>',
|
|
6
6
|
],
|
|
7
|
+
whoami: [
|
|
8
|
+
'acf whoami # preflight: role + API URL behind the current credential',
|
|
9
|
+
'acf whoami --json',
|
|
10
|
+
],
|
|
11
|
+
logout: [
|
|
12
|
+
'acf logout # revoke server-side + clear the local credential file',
|
|
13
|
+
],
|
|
7
14
|
login: [
|
|
8
15
|
'acf login',
|
|
9
16
|
'acf login --url https://acf.example.com --user admin',
|
|
10
17
|
'ACF_PASSWORD=... acf login --user admin # CI: password via env, not argv',
|
|
18
|
+
'acf login --user admin --code 123456 # TOTP-enabled account (second factor)',
|
|
11
19
|
],
|
|
12
20
|
'task list': [
|
|
13
21
|
'acf task list --status active --page 1',
|
|
14
22
|
'acf task list --json',
|
|
23
|
+
'acf task list --search nightly # matches name OR description (q param)',
|
|
15
24
|
],
|
|
16
25
|
'task get': ['acf task get <taskId>', 'acf task get <taskId> --json'],
|
|
17
26
|
'task trigger': [
|
|
18
27
|
'acf task trigger <taskId> --wait --wait-timeout 900',
|
|
28
|
+
'acf task trigger <taskId> --params \'{"KEY":"value"}\' # per-run param overrides (replaces task defaults)',
|
|
19
29
|
],
|
|
20
30
|
'task executions': [
|
|
21
31
|
'acf task executions <taskId> -n 5',
|
|
@@ -34,14 +44,37 @@ export const EXAMPLES = {
|
|
|
34
44
|
],
|
|
35
45
|
'task compare': ['acf task compare <taskId> <versionId1> <versionId2>'],
|
|
36
46
|
'task create': [
|
|
37
|
-
'acf task create --file task.json # required: name,
|
|
38
|
-
"acf task create --
|
|
47
|
+
'acf task create --file task.json # required: name, triggerType (runtime is optional server-side)',
|
|
48
|
+
"acf task create --body '{\"name\":\"nightly\",\"runtime\":\"node\",\"triggerType\":\"cron\",\"cronExpression\":\"0 2 * * *\"}' # note: there is NO `version` field on the task body — use `currentVersion` if you need one",
|
|
49
|
+
"acf task create --body '{\"name\":\"sync\",\"runtime\":\"python\",\"triggerType\":\"cron\",\"cronExpression\":\"0 8 * * *\",\"params\":{\"REPLACE_EXISTING\":true,\"retries\":3,\"target\":\"nightly\"}}' # params inject as AUTOFLOW_<KEY> env vars, JSON-stringified: booleans/numbers bare ('true','3'), strings quoted ('\"nightly\"')",
|
|
39
50
|
],
|
|
40
51
|
'task update': ['acf task update <taskId> --file patch.json'],
|
|
41
52
|
'task delete': ['acf task delete <taskId> -y'],
|
|
42
53
|
'task pause': ['acf task pause <taskId>'],
|
|
43
54
|
'task resume': ['acf task resume <taskId>'],
|
|
55
|
+
'task export': [
|
|
56
|
+
'acf task export <taskId>',
|
|
57
|
+
'acf task export <taskId> -o task.json # payload is accepted verbatim by: acf task import task.json',
|
|
58
|
+
],
|
|
59
|
+
'task import': [
|
|
60
|
+
'acf task import task.json',
|
|
61
|
+
'cat task.json | acf task import - # "-" reads stdin; the new task starts paused',
|
|
62
|
+
],
|
|
63
|
+
'task batch': [
|
|
64
|
+
'acf task batch trigger --ids id1,id2,id3',
|
|
65
|
+
'acf task batch pause <id1> <id2>',
|
|
66
|
+
],
|
|
44
67
|
'task kill': ['acf task kill <taskId> <execId>'],
|
|
68
|
+
'task webhook': [
|
|
69
|
+
'acf task webhook enable <taskId> # prints the webhook URL + secret ONCE',
|
|
70
|
+
'acf task webhook rotate <taskId> # old secret dies immediately, new one printed once',
|
|
71
|
+
'acf task webhook status <taskId> # url + enabled, without touching the secret',
|
|
72
|
+
'acf task webhook disable <taskId>',
|
|
73
|
+
],
|
|
74
|
+
'task glue': [
|
|
75
|
+
'acf task glue <taskId> -f glue.js # language inferred from the extension (.js → javascript)',
|
|
76
|
+
'cat glue.py | acf task glue <taskId> --stdin --language python',
|
|
77
|
+
],
|
|
45
78
|
'task lint': [
|
|
46
79
|
'acf task lint glue.js',
|
|
47
80
|
'acf task lint script.py --language python',
|
|
@@ -49,18 +82,32 @@ export const EXAMPLES = {
|
|
|
49
82
|
'app list': ['acf app list', 'acf app list --json'],
|
|
50
83
|
'app get': ['acf app get <appId> --json'],
|
|
51
84
|
'app create': [
|
|
52
|
-
'acf app create --
|
|
85
|
+
'acf app create --body \'{"name":"my-app","version":"1.0.0","runtime":"python"}\' # required: name, version, runtime',
|
|
53
86
|
],
|
|
54
87
|
'app update': [
|
|
55
|
-
'acf app update <appId> --
|
|
88
|
+
'acf app update <appId> --body \'{"version":"2.0.0"}\' # renaming is not supported by the backend',
|
|
56
89
|
],
|
|
57
90
|
'app delete': ['acf app delete <appId> -y'],
|
|
58
91
|
'app analyze': ['acf app analyze <appId>'],
|
|
92
|
+
'app releases': [
|
|
93
|
+
'acf app releases <appId> # DEP-01 unified view: version × latest deployment (modern; `app versions` is the legacy alias)',
|
|
94
|
+
'acf app releases <appId> -n 200 --json',
|
|
95
|
+
],
|
|
59
96
|
'app deploy': [
|
|
60
|
-
"acf app deploy <appId> -
|
|
97
|
+
"acf app deploy <appId> -m scheduled # deploy-only — middleware/cron triggers it later (default; entry script does NOT start at deploy)",
|
|
98
|
+
"acf app deploy <appId> -m daemon --env '{\"KEY\":\"value\"}' # resident process — entry script STARTS at deploy, auto-restarts on crash (CLI warns)",
|
|
99
|
+
"acf app deploy <appId> -m deploy-only # alias of scheduled — self-documenting 'deploy, don't run'",
|
|
61
100
|
],
|
|
62
101
|
'app deployments': ['acf app deployments <appId> -n 50 --json'],
|
|
63
102
|
'app versions': ['acf app versions <appId> --json'],
|
|
103
|
+
'app upload': [
|
|
104
|
+
'acf app upload ./dist/app.zip --name my-app',
|
|
105
|
+
'acf app upload ./dist/app.zip --name my-app --runtime python --version 1.2.0 --json',
|
|
106
|
+
],
|
|
107
|
+
'app upgrade-all': [
|
|
108
|
+
'acf app upgrade-all <appId> # full rolling upgrade (default, no body)',
|
|
109
|
+
'acf app upgrade-all <appId> --strategy canary --percentage 20 # canary first, auto-promote after probe',
|
|
110
|
+
],
|
|
64
111
|
'executor list': ['acf executor list', 'acf executor list --json'],
|
|
65
112
|
'executor get': ['acf executor get <executorId> --json'],
|
|
66
113
|
'executor rotate': [
|
|
@@ -69,6 +116,13 @@ export const EXAMPLES = {
|
|
|
69
116
|
'executor offline': ['acf executor offline executor-node'],
|
|
70
117
|
'deploy upgrade': ['acf deploy upgrade <deploymentId>'],
|
|
71
118
|
'deploy stop': ['acf deploy stop <deploymentId>'],
|
|
119
|
+
'deploy list': [
|
|
120
|
+
'acf deploy list # same data as: acf app deployments (deployments live under app in the command tree)',
|
|
121
|
+
'acf deploy list <appId> -n 50 --json',
|
|
122
|
+
],
|
|
123
|
+
'deploy remove': [
|
|
124
|
+
'acf deploy remove <deploymentId> -y # delete a FINISHED record (failed/stopped only); running/in-flight rows are refused with 409',
|
|
125
|
+
],
|
|
72
126
|
'audit list': [
|
|
73
127
|
'acf audit list --action task.trigger --start-time 2026-01-01T00:00:00Z',
|
|
74
128
|
'acf audit list --json',
|
|
@@ -82,9 +136,29 @@ export const EXAMPLES = {
|
|
|
82
136
|
'acf agent sessions --status waiting_input',
|
|
83
137
|
'acf agent sessions --json',
|
|
84
138
|
],
|
|
85
|
-
'
|
|
139
|
+
'apikey create': [
|
|
140
|
+
'acf apikey create --name ci-deploy --scope trigger',
|
|
141
|
+
'acf apikey create --name nightly --scope readonly --expires 90 # plaintext is echoed ONCE',
|
|
142
|
+
],
|
|
143
|
+
'apikey list': ['acf apikey list', 'acf apikey list --json'],
|
|
144
|
+
'apikey revoke': ['acf apikey revoke 3'],
|
|
145
|
+
'approval list': [
|
|
146
|
+
'acf approval list # pending queue (default)',
|
|
147
|
+
'acf approval list --status rejected --json',
|
|
148
|
+
],
|
|
149
|
+
'approval approve': [
|
|
150
|
+
'acf approval approve <deploymentId> --note "change window approved" # second person: approver ≠ requester',
|
|
151
|
+
],
|
|
152
|
+
'approval reject': ['acf approval reject <deploymentId> --note "wrong version"'],
|
|
153
|
+
'approval cancel': ['acf approval cancel <deploymentId> # withdraw your own pending request'],
|
|
154
|
+
'config show': ['acf config show', 'acf config show --json'],
|
|
86
155
|
'config set-url': ['acf config set-url http://localhost:3105'],
|
|
87
|
-
|
|
156
|
+
// 刻意**不**演示 `set-token <明文>`:命令行 token 会进 shell history 与进程列表。
|
|
157
|
+
// 帮助里的示例是 agent 最常照抄的东西,所以这里只给安全通路。
|
|
158
|
+
'config set-token': [
|
|
159
|
+
'ACF_TOKEN=<jwt> acf task list # preferred: env var, never touches argv/history',
|
|
160
|
+
'acf login # or: interactive hidden prompt, stored 0600',
|
|
161
|
+
],
|
|
88
162
|
};
|
|
89
163
|
/**
|
|
90
164
|
* Walk the whole command tree and attach the matching Examples block to every
|
package/dist/index.d.ts
CHANGED
|
@@ -3,14 +3,20 @@
|
|
|
3
3
|
* ACF CLI — AutoCodeFlow command-line interface
|
|
4
4
|
*
|
|
5
5
|
* Usage:
|
|
6
|
-
* acf login
|
|
6
|
+
* acf login # TOTP accounts: add --code <6 digits> (or prompt)
|
|
7
7
|
* acf task list
|
|
8
8
|
* acf task trigger <id> --wait
|
|
9
|
+
* acf task export <id> [-o file] | import <file> | batch <trigger|pause|resume|delete> --ids id1,id2
|
|
9
10
|
* acf task versions <id> | compare <id> <v1> <v2> | rollback <id> --version <vid>
|
|
10
11
|
* acf task analyze <taskId> <execId>
|
|
11
12
|
* acf task suggest-schedule <id>
|
|
12
13
|
* acf app list | create | update <id> | delete <id>
|
|
14
|
+
* acf app upload <pkg.zip> --name <name>
|
|
15
|
+
* acf app upgrade-all <appId> [--strategy canary --percentage N]
|
|
13
16
|
* acf app analyze <id>
|
|
17
|
+
* acf task webhook <enable|rotate|disable|status> <taskId>
|
|
18
|
+
* acf task glue <taskId> -f <file>
|
|
19
|
+
* acf approval list | approve <id> --note … | reject <id> | cancel <id>
|
|
14
20
|
* acf deploy upgrade <deploymentId> | stop <deploymentId>
|
|
15
21
|
* acf executor list | get <id> | rotate <name|id> | offline <name|id>
|
|
16
22
|
* acf exec tail <execId>
|
|
@@ -18,6 +24,8 @@
|
|
|
18
24
|
* acf audit list
|
|
19
25
|
* acf sop list | show <sopId>
|
|
20
26
|
* acf agent sessions
|
|
27
|
+
* acf apikey create --name <name> --scope <readonly|trigger|manage> [--expires <days>]
|
|
28
|
+
* acf apikey list | revoke <id>
|
|
21
29
|
* acf config show
|
|
22
30
|
*
|
|
23
31
|
* 退出码表(docs 详见 README.md「Exit codes」,单一事实源在 src/ui.ts 的
|
package/dist/index.js
CHANGED
|
@@ -3,14 +3,20 @@
|
|
|
3
3
|
* ACF CLI — AutoCodeFlow command-line interface
|
|
4
4
|
*
|
|
5
5
|
* Usage:
|
|
6
|
-
* acf login
|
|
6
|
+
* acf login # TOTP accounts: add --code <6 digits> (or prompt)
|
|
7
7
|
* acf task list
|
|
8
8
|
* acf task trigger <id> --wait
|
|
9
|
+
* acf task export <id> [-o file] | import <file> | batch <trigger|pause|resume|delete> --ids id1,id2
|
|
9
10
|
* acf task versions <id> | compare <id> <v1> <v2> | rollback <id> --version <vid>
|
|
10
11
|
* acf task analyze <taskId> <execId>
|
|
11
12
|
* acf task suggest-schedule <id>
|
|
12
13
|
* acf app list | create | update <id> | delete <id>
|
|
14
|
+
* acf app upload <pkg.zip> --name <name>
|
|
15
|
+
* acf app upgrade-all <appId> [--strategy canary --percentage N]
|
|
13
16
|
* acf app analyze <id>
|
|
17
|
+
* acf task webhook <enable|rotate|disable|status> <taskId>
|
|
18
|
+
* acf task glue <taskId> -f <file>
|
|
19
|
+
* acf approval list | approve <id> --note … | reject <id> | cancel <id>
|
|
14
20
|
* acf deploy upgrade <deploymentId> | stop <deploymentId>
|
|
15
21
|
* acf executor list | get <id> | rotate <name|id> | offline <name|id>
|
|
16
22
|
* acf exec tail <execId>
|
|
@@ -18,6 +24,8 @@
|
|
|
18
24
|
* acf audit list
|
|
19
25
|
* acf sop list | show <sopId>
|
|
20
26
|
* acf agent sessions
|
|
27
|
+
* acf apikey create --name <name> --scope <readonly|trigger|manage> [--expires <days>]
|
|
28
|
+
* acf apikey list | revoke <id>
|
|
21
29
|
* acf config show
|
|
22
30
|
*
|
|
23
31
|
* 退出码表(docs 详见 README.md「Exit codes」,单一事实源在 src/ui.ts 的
|
|
@@ -27,7 +35,7 @@
|
|
|
27
35
|
import { Command, CommanderError } from 'commander';
|
|
28
36
|
import { pathToFileURL } from 'node:url';
|
|
29
37
|
import chalk from 'chalk';
|
|
30
|
-
import { loginCommand } from './commands/login.js';
|
|
38
|
+
import { loginCommand, whoamiCommand, logoutCommand } from './commands/login.js';
|
|
31
39
|
import { tasksCommand } from './commands/tasks.js';
|
|
32
40
|
import { appsCommand } from './commands/apps.js';
|
|
33
41
|
import { executorsCommand } from './commands/executors.js';
|
|
@@ -37,6 +45,8 @@ import { execCommand } from './commands/exec.js';
|
|
|
37
45
|
import { projectsCommand } from './commands/projects.js';
|
|
38
46
|
import { sopCommand } from './commands/sop.js';
|
|
39
47
|
import { agentCommand } from './commands/agent.js';
|
|
48
|
+
import { apikeysCommand } from './commands/apikeys.js';
|
|
49
|
+
import { approvalCommand } from './commands/approval.js';
|
|
40
50
|
import { showConfig, setApiUrl, setToken } from './config.js';
|
|
41
51
|
import { applyExamples } from './help.js';
|
|
42
52
|
import { EXIT_CODES, interruptExit } from './ui.js';
|
|
@@ -50,14 +60,46 @@ import { EXIT_CODES, interruptExit } from './ui.js';
|
|
|
50
60
|
// `resolveJsonModule` 已在 tsconfig 打开;tsc 的 rootDir=src 会把 package.json
|
|
51
61
|
// 视为 src 之外的输入,故走运行时解析(发布物里 package.json 与 dist/ 同级,
|
|
52
62
|
// 路径稳定)。本包为 ESM(type: module),JSON 导入须带 import attribute。
|
|
63
|
+
// 2026-10 起不再经 Commander .version() 注册(详见下方 VERSION-HIJACK 注释),
|
|
64
|
+
// 但 pkg.version 仍是版本输出的唯一事实源——行为层守卫跑真实构建产物钉死。
|
|
53
65
|
import pkg from '../package.json' with { type: 'json' };
|
|
54
66
|
// 导出命令树供测试复用(结构守卫:每个叶子命令都必须有 Examples)。配合底部
|
|
55
67
|
// 的 main-guard,import 本文件不会触发 parseAsync。
|
|
56
68
|
export const program = new Command();
|
|
57
69
|
program
|
|
58
70
|
.name('acf')
|
|
59
|
-
.description('AutoCodeFlow CLI — manage tasks, executions, applications and projects')
|
|
60
|
-
|
|
71
|
+
.description('AutoCodeFlow CLI — manage tasks, executions, applications and projects');
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
// 版本号处理(VERSION-HIJACK,P1 修复)
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// 根命令**不**注册 --version 选项:commander 的根层 parseOptions 会在派发子
|
|
76
|
+
// 命令之前扫描**全部**参数,一旦经 .version() 注册,`acf app upload --version
|
|
77
|
+
// 1.2.0` / `acf app upgrade-all --version 1.9.0` / `acf task rollback --version
|
|
78
|
+
// v9` 里的 --version 会在根层被匹配并 exit 0 打印 CLI 版本——上传/升级/回滚
|
|
79
|
+
// 根本没发生却不报错(2026-10 开发人员实测,三个子命令全部中招)。
|
|
80
|
+
//
|
|
81
|
+
// 修法:版本输出改由根命令的 unknownOption 覆盖接管——只有到达根层仍未被
|
|
82
|
+
// 任何子命令消费的 --version / -V(即 `acf --version` / `acf -V` 这类根级
|
|
83
|
+
// 请求)才打印 pkg.version 并以 0 退出;子命令自己的 --version 选项由各自的
|
|
84
|
+
// parseOptions 消费,互不干扰。pkg.version 仍是唯一事实源(行为层守卫
|
|
85
|
+
// release-metadata.test.ts 跑真实构建产物钉死,改回硬编码会转红)。
|
|
86
|
+
// 'before' 只挂在根命令的帮助上(子命令 help 不显示版本横幅——原 .version()
|
|
87
|
+
// 的版本 banner 同样是根级专属;'beforeAll' 会传播到所有子命令,太吵)。
|
|
88
|
+
program.addHelpText('before', `acf v${pkg.version}\n`);
|
|
89
|
+
// 根级 unknownOption 覆盖:`acf --version` / `acf -V` 会在根 _parseCommand 的
|
|
90
|
+
// checkForUnknownOptions 里走到这里(无子命令可派发),此时按 CLI 版本处理;
|
|
91
|
+
// 其余未知选项(含"某子命令树里没有 --version 选项"的情形)走 commander
|
|
92
|
+
// 原逻辑(报错 + 完整 help + 退出码 2)。
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
|
+
const programAny = program;
|
|
95
|
+
const rootUnknownOption = programAny.unknownOption.bind(program);
|
|
96
|
+
programAny.unknownOption = (flag) => {
|
|
97
|
+
if (flag === '--version' || flag === '-V') {
|
|
98
|
+
console.log(pkg.version);
|
|
99
|
+
process.exit(0);
|
|
100
|
+
}
|
|
101
|
+
return rootUnknownOption(flag);
|
|
102
|
+
};
|
|
61
103
|
// ---------------------------------------------------------------------------
|
|
62
104
|
// 解析期行为统一(全树,见下方 applyParseErrorBehavior 的说明)
|
|
63
105
|
// ---------------------------------------------------------------------------
|
|
@@ -74,6 +116,8 @@ program.hook('preAction', (thisCommand) => {
|
|
|
74
116
|
});
|
|
75
117
|
// ---- sub-commands ----
|
|
76
118
|
program.addCommand(loginCommand());
|
|
119
|
+
program.addCommand(whoamiCommand());
|
|
120
|
+
program.addCommand(logoutCommand());
|
|
77
121
|
program.addCommand(tasksCommand());
|
|
78
122
|
program.addCommand(appsCommand());
|
|
79
123
|
program.addCommand(executorsCommand());
|
|
@@ -83,9 +127,16 @@ program.addCommand(execCommand());
|
|
|
83
127
|
program.addCommand(projectsCommand());
|
|
84
128
|
program.addCommand(sopCommand());
|
|
85
129
|
program.addCommand(agentCommand());
|
|
130
|
+
program.addCommand(apikeysCommand());
|
|
131
|
+
program.addCommand(approvalCommand());
|
|
86
132
|
// acf config show / set
|
|
87
133
|
const configCmd = new Command('config').description('View or update CLI configuration');
|
|
88
|
-
configCmd
|
|
134
|
+
configCmd
|
|
135
|
+
.command('show')
|
|
136
|
+
.description('Show current config (token is always masked — [set] / [not set])')
|
|
137
|
+
// P2(CLI-AGENT-UX-AUDIT):--json 让 agent 能解析当前配置(不改 [set]/[not set] 口径)
|
|
138
|
+
.option('--json', 'Emit raw JSON (CI-consumable)')
|
|
139
|
+
.action((opts) => showConfig({ json: opts.json }));
|
|
89
140
|
configCmd.command('set-url <url>').description('Set API base URL').action((url) => {
|
|
90
141
|
setApiUrl(url);
|
|
91
142
|
console.log(chalk.green(`✔ API URL set to ${url}`));
|
|
@@ -93,6 +144,10 @@ configCmd.command('set-url <url>').description('Set API base URL').action((url)
|
|
|
93
144
|
configCmd.command('set-token <token>').description('Set auth token directly').action((token) => {
|
|
94
145
|
setToken(token);
|
|
95
146
|
console.log(chalk.green('✔ Token saved'));
|
|
147
|
+
// 安全提示(与 login 的 --password 告警同风格):命令行明文 token 会留在
|
|
148
|
+
// shell history 与进程列表里;login(交互隐藏输入 + 落 0600 配置文件)或
|
|
149
|
+
// ACF_TOKEN 环境变量(不进 argv)是更安全的通路。
|
|
150
|
+
process.stderr.write(chalk.yellow('⚠ A token passed on the command line can leak into shell history and the process list — prefer `acf login` or the ACF_TOKEN environment variable.\n'));
|
|
96
151
|
});
|
|
97
152
|
program.addCommand(configCmd);
|
|
98
153
|
// 集中式 help:把 help.ts 的 EXAMPLES 表按命令路径走树注入(每个命令至少一个
|
package/dist/ui.d.ts
CHANGED
|
@@ -52,4 +52,29 @@ export declare function emitUsageError(message: string): never;
|
|
|
52
52
|
* `rl.on('SIGINT')` 共用这一个出口。
|
|
53
53
|
*/
|
|
54
54
|
export declare function interruptExit(): never;
|
|
55
|
+
/**
|
|
56
|
+
* 破坏性操作的交互确认 —— 三处 delete 此前各自内联 readline.question,
|
|
57
|
+
* 在 stdin 非交互(agent / CI / `< NUL`)时会**静默假绿**:
|
|
58
|
+
*
|
|
59
|
+
* $ acf app delete <id> < NUL
|
|
60
|
+
* Delete application <id>? [y/N] <- 提示打出后立刻 EOF
|
|
61
|
+
* $ echo $? -> 0,且既无 "Aborted." 也无错误行
|
|
62
|
+
*
|
|
63
|
+
* 后果是自动化面最危险的一类失败:agent 把「什么都没删」读成「删除成功」,
|
|
64
|
+
* 继续跑下游步骤。根因是 readline 在 EOF 时以空串 resolve(不是 reject),
|
|
65
|
+
* 调用方的 `/^y(es)?$/` 判否后走 "Aborted." 分支——而该分支在 Windows 上
|
|
66
|
+
* 连输出都会丢,进程以 0 收场。
|
|
67
|
+
*
|
|
68
|
+
* 语义(与 login 的 TOTP 非交互分支同一思路,收敛到一处):
|
|
69
|
+
* - `--yes` 给定 → 直接放行,不碰 stdin(脚本显式表态的唯一通路);
|
|
70
|
+
* - stdin 非 TTY → **拒绝**并给可操作错误(UsageError → 退出码 2)。既不
|
|
71
|
+
* 静默通过(会误删)也不静默取消(会假绿);
|
|
72
|
+
* - stdin 是 TTY → 交互提问;除 y/yes 外一律视为主动放弃,返回 false,
|
|
73
|
+
* 由调用方原样 return(退出码 0 —— README 已把「主动放弃确认」归入成功)。
|
|
74
|
+
*
|
|
75
|
+
* @returns true = 继续执行;false = 用户主动放弃(调用方应直接 return)。
|
|
76
|
+
*/
|
|
77
|
+
export declare function confirmDestructive(question: string, opts?: {
|
|
78
|
+
yes?: boolean;
|
|
79
|
+
}): Promise<boolean>;
|
|
55
80
|
export {};
|
package/dist/ui.js
CHANGED
|
@@ -85,3 +85,51 @@ export function interruptExit() {
|
|
|
85
85
|
process.stderr.write('\n');
|
|
86
86
|
process.exit(EXIT_CODES.INTERRUPTED);
|
|
87
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* 破坏性操作的交互确认 —— 三处 delete 此前各自内联 readline.question,
|
|
90
|
+
* 在 stdin 非交互(agent / CI / `< NUL`)时会**静默假绿**:
|
|
91
|
+
*
|
|
92
|
+
* $ acf app delete <id> < NUL
|
|
93
|
+
* Delete application <id>? [y/N] <- 提示打出后立刻 EOF
|
|
94
|
+
* $ echo $? -> 0,且既无 "Aborted." 也无错误行
|
|
95
|
+
*
|
|
96
|
+
* 后果是自动化面最危险的一类失败:agent 把「什么都没删」读成「删除成功」,
|
|
97
|
+
* 继续跑下游步骤。根因是 readline 在 EOF 时以空串 resolve(不是 reject),
|
|
98
|
+
* 调用方的 `/^y(es)?$/` 判否后走 "Aborted." 分支——而该分支在 Windows 上
|
|
99
|
+
* 连输出都会丢,进程以 0 收场。
|
|
100
|
+
*
|
|
101
|
+
* 语义(与 login 的 TOTP 非交互分支同一思路,收敛到一处):
|
|
102
|
+
* - `--yes` 给定 → 直接放行,不碰 stdin(脚本显式表态的唯一通路);
|
|
103
|
+
* - stdin 非 TTY → **拒绝**并给可操作错误(UsageError → 退出码 2)。既不
|
|
104
|
+
* 静默通过(会误删)也不静默取消(会假绿);
|
|
105
|
+
* - stdin 是 TTY → 交互提问;除 y/yes 外一律视为主动放弃,返回 false,
|
|
106
|
+
* 由调用方原样 return(退出码 0 —— README 已把「主动放弃确认」归入成功)。
|
|
107
|
+
*
|
|
108
|
+
* @returns true = 继续执行;false = 用户主动放弃(调用方应直接 return)。
|
|
109
|
+
*/
|
|
110
|
+
export async function confirmDestructive(question, opts = {}) {
|
|
111
|
+
if (opts.yes)
|
|
112
|
+
return true;
|
|
113
|
+
if (process.stdin.isTTY !== true) {
|
|
114
|
+
emitUsageError('Confirmation cannot be read: stdin is not interactive. ' +
|
|
115
|
+
'Re-run with --yes (-y) to confirm this destructive operation in non-interactive use ' +
|
|
116
|
+
'(CI / agent / piped stdin).');
|
|
117
|
+
}
|
|
118
|
+
const readline = await import('readline/promises');
|
|
119
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
120
|
+
// raw 模式下 Ctrl+C 触发 rl 'SIGINT' 而非进程信号;无监听只会 pause,
|
|
121
|
+
// 确认提示处会假死。接住并走统一中断出口(130)。
|
|
122
|
+
rl.on('SIGINT', () => interruptExit());
|
|
123
|
+
let answer;
|
|
124
|
+
try {
|
|
125
|
+
answer = await rl.question(`${question} [y/N] `);
|
|
126
|
+
}
|
|
127
|
+
finally {
|
|
128
|
+
rl.close();
|
|
129
|
+
}
|
|
130
|
+
if (!/^y(es)?$/i.test(answer)) {
|
|
131
|
+
console.log(chalk.yellow('Aborted.'));
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
return true;
|
|
135
|
+
}
|