@autocodeflow/cli 1.5.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/dist/config.js ADDED
@@ -0,0 +1,160 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ var __importDefault = (this && this.__importDefault) || function (mod) {
27
+ return (mod && mod.__esModule) ? mod : { "default": mod };
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.showConfig = exports.clearAuth = exports.setRefreshToken = exports.setToken = exports.setApiUrl = exports.getRefreshToken = exports.getToken = exports.getApiUrl = exports.hardenConfigPermissions = exports.getConfigPath = void 0;
31
+ /**
32
+ * Persistent config store for the ACF CLI.
33
+ * Stores API URL and tokens in the user's config directory.
34
+ *
35
+ * SEC-NEW-4 (SEC-01 v2 / N-SEC01-v2-1): the on-disk store holds BOTH the
36
+ * short-lived access token and the long-lived refresh token, so at-rest
37
+ * protection matters. Node has no cross-platform OS keyring (unlike Electron's
38
+ * safeStorage — see ADR-012; acf-cli is plain Node, not Electron), so the CLI
39
+ * cannot encrypt at rest without pulling a native keytar dependency. The chosen
40
+ * minimum posture — explicitly allowed by docs/SEC-01-复审报告.md §四 — is:
41
+ * 1. the config file is created with 0600 (owner read/write only), and any
42
+ * legacy group/world-readable file is repaired to 0600 on load;
43
+ * 2. credentials can be injected per-invocation via ACF_TOKEN /
44
+ * ACF_REFRESH_TOKEN (URL via ACF_API_URL) without ever touching disk —
45
+ * the recommended mode for CI / cron (see README "CLI 工具 (acf)").
46
+ */
47
+ const conf_1 = __importDefault(require("conf"));
48
+ const fs = __importStar(require("fs"));
49
+ /** Owner-only (rw-------). Mirrors the private-credential intent of ADR-012. */
50
+ const CONFIG_FILE_MODE = 0o600;
51
+ /**
52
+ * Optional config-directory override (absolute path). Confined to tests and
53
+ * air-gapped CI, where ~/.config may be read-only or shared; unset in normal
54
+ * interactive use so conf keeps resolving the platform default directory.
55
+ */
56
+ const configDir = process.env.ACF_CONFIG_DIR;
57
+ /**
58
+ * Construct the config store. conf applies `configFileMode` while *writing* the
59
+ * defaults-bearing file at construction time; on platforms where that chmod is
60
+ * unsupported or momentarily blocked (Windows ACL semantics, parallel-load disk
61
+ * contention in tests, read-only mounts) the constructor can throw. Fall back to
62
+ * a mode-less store rather than crashing the CLI — `hardenConfigPermissions()`
63
+ * repairs the on-disk mode separately when the platform allows it.
64
+ */
65
+ function createStore() {
66
+ const base = {
67
+ // ⚠ 刻意保持 'acf-cli',**不随包名改成 '@autocodeflow/cli'**。
68
+ // 这个值决定凭据文件的磁盘位置(如 ~/.config/acf-cli/config.json),
69
+ // 而它是**用户机器上的持久状态**:改名会让既有用户下次运行时读不到旧配置,
70
+ // 表现为"莫名掉登录"(access/refresh token 都还在旧目录里)。
71
+ // 包名只是 npm 上的标识,与磁盘布局不必一致;新建目录带来的唯一收益是好看,
72
+ // 代价却是每个已装用户重新登录一次。
73
+ // 若将来确需迁移,必须配套"读旧目录 → 写新目录"的一次性搬迁,不能只改这里。
74
+ projectName: 'acf-cli',
75
+ ...(configDir ? { cwd: configDir } : {}),
76
+ defaults: {
77
+ apiUrl: 'http://localhost:3105',
78
+ token: '',
79
+ refreshToken: '',
80
+ },
81
+ };
82
+ try {
83
+ return new conf_1.default({ ...base, configFileMode: CONFIG_FILE_MODE });
84
+ }
85
+ catch {
86
+ return new conf_1.default(base);
87
+ }
88
+ }
89
+ const store = createStore();
90
+ /** Absolute path of the on-disk config file (diagnostics / tests / showConfig). */
91
+ function getConfigPath() {
92
+ return store.path;
93
+ }
94
+ exports.getConfigPath = getConfigPath;
95
+ /**
96
+ * SEC-NEW-4: best-effort hardening of an existing config file to owner-only
97
+ * permissions. conf applies `configFileMode` when it *writes*, but it never
98
+ * rewrites a file it only *reads* — so installs created before this change keep
99
+ * their 0666/0644 mode unless we chmod once here (the store constructor does
100
+ * write a defaults-bearing file, so a fresh install is already 0600).
101
+ * Never throws: the chmod can legitimately fail (Windows ACL semantics,
102
+ * read-only mounts) and must not break the CLI. Credentials are never moved or
103
+ * deleted by this repair — only the file mode changes.
104
+ */
105
+ function hardenConfigPermissions() {
106
+ try {
107
+ if (!fs.existsSync(store.path))
108
+ return;
109
+ if ((fs.statSync(store.path).mode & 0o777) !== CONFIG_FILE_MODE) {
110
+ fs.chmodSync(store.path, CONFIG_FILE_MODE);
111
+ }
112
+ }
113
+ catch {
114
+ // best-effort: leave the file as-is when the platform refuses the chmod.
115
+ }
116
+ }
117
+ exports.hardenConfigPermissions = hardenConfigPermissions;
118
+ // Run once at module load so every CLI invocation repairs a stale mode.
119
+ hardenConfigPermissions();
120
+ function getApiUrl() {
121
+ return process.env.ACF_API_URL || store.get('apiUrl');
122
+ }
123
+ exports.getApiUrl = getApiUrl;
124
+ function getToken() {
125
+ return process.env.ACF_TOKEN || store.get('token');
126
+ }
127
+ exports.getToken = getToken;
128
+ function getRefreshToken() {
129
+ return process.env.ACF_REFRESH_TOKEN || store.get('refreshToken');
130
+ }
131
+ exports.getRefreshToken = getRefreshToken;
132
+ function setApiUrl(url) {
133
+ store.set('apiUrl', url);
134
+ }
135
+ exports.setApiUrl = setApiUrl;
136
+ function setToken(token) {
137
+ store.set('token', token);
138
+ }
139
+ exports.setToken = setToken;
140
+ function setRefreshToken(token) {
141
+ store.set('refreshToken', token);
142
+ }
143
+ exports.setRefreshToken = setRefreshToken;
144
+ /**
145
+ * BUG-13: 刷新彻底失败(refresh token 也已过期/被轮换掉)时清除本地凭据,
146
+ * 后续请求返回到「未登录」状态——避免拿着必死 token 反复打 401。
147
+ * apiUrl 保留(用户环境不丢)。
148
+ */
149
+ function clearAuth() {
150
+ store.set('token', '');
151
+ store.set('refreshToken', '');
152
+ }
153
+ exports.clearAuth = clearAuth;
154
+ function showConfig() {
155
+ console.log('API URL :', getApiUrl());
156
+ console.log('Token :', getToken() ? '[set]' : '[not set]');
157
+ console.log('Refresh :', getRefreshToken() ? '[set]' : '[not set]');
158
+ console.log('Config file:', store.path);
159
+ }
160
+ exports.showConfig = showConfig;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ /**
8
+ * ACF CLI — AutoCodeFlow command-line interface
9
+ *
10
+ * Usage:
11
+ * acf login
12
+ * acf task list
13
+ * acf task trigger <id> --wait
14
+ * acf task versions <id> | compare <id> <v1> <v2> | rollback <id> --version <vid>
15
+ * acf task analyze <taskId> <execId>
16
+ * acf task suggest-schedule <id>
17
+ * acf app list | create | update <id> | delete <id>
18
+ * acf app analyze <id>
19
+ * acf deploy upgrade <deploymentId> | stop <deploymentId>
20
+ * acf executor list | get <id> | rotate <name|id> | offline <name|id>
21
+ * acf exec tail <execId>
22
+ * acf task lint <file>
23
+ * acf audit list
24
+ * acf config show
25
+ */
26
+ const commander_1 = require("commander");
27
+ const chalk_1 = __importDefault(require("chalk"));
28
+ const login_1 = require("./commands/login");
29
+ const tasks_1 = require("./commands/tasks");
30
+ const apps_1 = require("./commands/apps");
31
+ const executors_1 = require("./commands/executors");
32
+ const deploy_1 = require("./commands/deploy");
33
+ const audit_1 = require("./commands/audit");
34
+ const exec_1 = require("./commands/exec");
35
+ const projects_1 = require("./commands/projects");
36
+ const config_1 = require("./config");
37
+ // 版本号单一事实源:直接读 package.json,而不是硬编码字面量。
38
+ //
39
+ // 原实现写死 `.version('1.0.0')`,而 package.json 是 `version-guard` 与
40
+ // release-please 唯一会 bump 的地方——两者必然漂移。实测证据:包名/版本改成
41
+ // `@autocodeflow/cli@1.4.3` 后,`npx acf --version` 仍打印 **1.0.0**。
42
+ // 这是发布物里最不该出错的一处:用户报 issue、我们排查兼容性、`acf` 自身
43
+ // 做版本相关的行为分支,读的都是这个数。
44
+ // `resolveJsonModule` 已在 tsconfig 打开;tsc 的 rootDir=src 会把 package.json
45
+ // 视为 src 之外的输入,故用 require 走运行时解析(发布物里 package.json 与
46
+ // dist/ 同级,路径稳定)。
47
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
48
+ const pkg = require('../package.json');
49
+ const program = new commander_1.Command();
50
+ program
51
+ .name('acf')
52
+ .description('AutoCodeFlow CLI — manage tasks, executions, applications and projects')
53
+ .version(pkg.version);
54
+ // Global options that override stored config
55
+ program
56
+ .option('--api-url <url>', 'Override API URL for this invocation (or set ACF_API_URL env var)')
57
+ .option('--token <token>', 'Override auth token for this invocation (or set ACF_TOKEN env var)');
58
+ program.hook('preAction', (thisCommand) => {
59
+ const opts = thisCommand.opts();
60
+ if (opts.apiUrl)
61
+ process.env['ACF_API_URL'] = opts.apiUrl;
62
+ if (opts.token)
63
+ process.env['ACF_TOKEN'] = opts.token;
64
+ });
65
+ // ---- sub-commands ----
66
+ program.addCommand((0, login_1.loginCommand)());
67
+ program.addCommand((0, tasks_1.tasksCommand)());
68
+ program.addCommand((0, apps_1.appsCommand)());
69
+ program.addCommand((0, executors_1.executorsCommand)());
70
+ program.addCommand((0, deploy_1.deployCommand)());
71
+ program.addCommand((0, audit_1.auditCommand)());
72
+ program.addCommand((0, exec_1.execCommand)());
73
+ program.addCommand((0, projects_1.projectsCommand)());
74
+ // acf config show / set
75
+ const configCmd = new commander_1.Command('config').description('View or update CLI configuration');
76
+ configCmd.command('show').description('Show current config').action(() => (0, config_1.showConfig)());
77
+ configCmd.command('set-url <url>').description('Set API base URL').action((url) => {
78
+ (0, config_1.setApiUrl)(url);
79
+ console.log(chalk_1.default.green(`✔ API URL set to ${url}`));
80
+ });
81
+ configCmd.command('set-token <token>').description('Set auth token directly').action((token) => {
82
+ (0, config_1.setToken)(token);
83
+ console.log(chalk_1.default.green('✔ Token saved'));
84
+ });
85
+ program.addCommand(configCmd);
86
+ // Better error display
87
+ program.configureOutput({
88
+ outputError: (str, write) => write(chalk_1.default.red(str)),
89
+ });
90
+ program.parseAsync(process.argv).catch((e) => {
91
+ console.error(chalk_1.default.red('Error:'), e instanceof Error ? e.message : String(e));
92
+ process.exit(1);
93
+ });
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@autocodeflow/cli",
3
+ "version": "1.5.0",
4
+ "description": "AutoCodeFlow CLI — manage tasks, executions and applications from the terminal",
5
+ "license": "MIT",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "acf": "dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "!dist/__tests__"
13
+ ],
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/LuluDeer/AutoCodeFlow.git",
20
+ "directory": "packages/acf-cli"
21
+ },
22
+ "scripts": {
23
+ "build": "tsc",
24
+ "prepublishOnly": "npm run build",
25
+ "dev": "ts-node src/index.ts",
26
+ "start": "node dist/index.js",
27
+ "test": "vitest run",
28
+ "typecheck": "tsc --noEmit"
29
+ },
30
+ "dependencies": {
31
+ "axios": "1.20.0",
32
+ "chalk": "4.1.2",
33
+ "cli-table3": "0.6.5",
34
+ "commander": "12.0.0",
35
+ "conf": "10.2.0",
36
+ "ora": "5.4.1"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node": "24.13.3",
40
+ "ts-node": "10.9.2",
41
+ "typescript": "5.4.5",
42
+ "vitest": "^3.2.4"
43
+ },
44
+ "engines": {
45
+ "node": ">=18"
46
+ }
47
+ }