@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/client.d.ts +14 -0
- package/dist/client.js +202 -0
- package/dist/commands/apps.d.ts +2 -0
- package/dist/commands/apps.js +322 -0
- package/dist/commands/audit.d.ts +2 -0
- package/dist/commands/audit.js +77 -0
- package/dist/commands/deploy.d.ts +2 -0
- package/dist/commands/deploy.js +49 -0
- package/dist/commands/exec.d.ts +32 -0
- package/dist/commands/exec.js +156 -0
- package/dist/commands/executors.d.ts +2 -0
- package/dist/commands/executors.js +183 -0
- package/dist/commands/login.d.ts +2 -0
- package/dist/commands/login.js +116 -0
- package/dist/commands/projects.d.ts +6 -0
- package/dist/commands/projects.js +97 -0
- package/dist/commands/tasks.d.ts +2 -0
- package/dist/commands/tasks.js +625 -0
- package/dist/config.d.ts +27 -0
- package/dist/config.js +160 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +93 -0
- package/package.json +47 -0
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
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.tasksCommand = void 0;
|
|
30
|
+
const commander_1 = require("commander");
|
|
31
|
+
const cli_table3_1 = __importDefault(require("cli-table3"));
|
|
32
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
33
|
+
const ora_1 = __importDefault(require("ora"));
|
|
34
|
+
const axios_1 = __importDefault(require("axios"));
|
|
35
|
+
const child_process_1 = require("child_process");
|
|
36
|
+
const fs = __importStar(require("fs"));
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
const client_1 = require("../client");
|
|
39
|
+
function statusColor(s) {
|
|
40
|
+
if (s === 'success')
|
|
41
|
+
return chalk_1.default.green(s);
|
|
42
|
+
if (s === 'failed' || s === 'timeout' || s === 'killed')
|
|
43
|
+
return chalk_1.default.red(s);
|
|
44
|
+
if (s === 'running')
|
|
45
|
+
return chalk_1.default.cyan(s);
|
|
46
|
+
if (s === 'active')
|
|
47
|
+
return chalk_1.default.green(s);
|
|
48
|
+
if (s === 'paused')
|
|
49
|
+
return chalk_1.default.yellow(s);
|
|
50
|
+
return chalk_1.default.gray(s);
|
|
51
|
+
}
|
|
52
|
+
function tasksCommand() {
|
|
53
|
+
const cmd = new commander_1.Command('task').description('Manage tasks');
|
|
54
|
+
// acf task list
|
|
55
|
+
cmd.command('list')
|
|
56
|
+
.description('List all tasks')
|
|
57
|
+
.option('-s, --status <status>', 'Filter by status (active|paused)')
|
|
58
|
+
.option('-k, --keyword <keyword>', 'Search by name (sent as the `name` query param)')
|
|
59
|
+
.option('-p, --page <n>', 'Page number', '1')
|
|
60
|
+
.option('-n, --page-size <n>', 'Items per page', '20')
|
|
61
|
+
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
62
|
+
.action(async (opts) => {
|
|
63
|
+
const spinner = (0, ora_1.default)('Fetching tasks…').start();
|
|
64
|
+
try {
|
|
65
|
+
// ListTasksQueryDto has `name` (no `keyword`)
|
|
66
|
+
const data = await (0, client_1.get)('/tasks', {
|
|
67
|
+
page: opts.page,
|
|
68
|
+
pageSize: opts.pageSize,
|
|
69
|
+
status: opts.status,
|
|
70
|
+
name: opts.keyword,
|
|
71
|
+
});
|
|
72
|
+
spinner.stop();
|
|
73
|
+
if (opts.json) {
|
|
74
|
+
// ECO-02: --json —— CI/脚本消费面(信封已拆,直接可用负载)
|
|
75
|
+
console.log(JSON.stringify(data));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const table = new cli_table3_1.default({
|
|
79
|
+
head: ['ID', 'Name', 'Runtime', 'Status', 'Cron'],
|
|
80
|
+
colWidths: [14, 30, 12, 10, 20],
|
|
81
|
+
style: { head: ['cyan'] },
|
|
82
|
+
});
|
|
83
|
+
for (const t of data.list ?? []) {
|
|
84
|
+
table.push([t.id.slice(0, 12), t.name, t.runtime, statusColor(t.status), t.cronExpression ?? '-']);
|
|
85
|
+
}
|
|
86
|
+
console.log(table.toString());
|
|
87
|
+
console.log(chalk_1.default.gray(`Total: ${data.total} page ${data.page}/${Math.ceil(data.total / data.pageSize)}`));
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
spinner.fail('Failed to list tasks');
|
|
91
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
// acf task get <id>
|
|
96
|
+
cmd.command('get <id>')
|
|
97
|
+
.description('Show task details')
|
|
98
|
+
.action(async (id) => {
|
|
99
|
+
const spinner = (0, ora_1.default)('Fetching task…').start();
|
|
100
|
+
try {
|
|
101
|
+
const t = await (0, client_1.get)(`/tasks/${id}`);
|
|
102
|
+
spinner.stop();
|
|
103
|
+
console.log(chalk_1.default.bold('Task Details'));
|
|
104
|
+
console.log(' ID :', t.id);
|
|
105
|
+
console.log(' Name :', t.name);
|
|
106
|
+
console.log(' Runtime :', t.runtime);
|
|
107
|
+
console.log(' Status :', statusColor(t.status));
|
|
108
|
+
console.log(' Cron :', t.cronExpression ?? '-');
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
spinner.fail('Failed');
|
|
112
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
// acf task trigger <id>
|
|
117
|
+
cmd.command('trigger <id>')
|
|
118
|
+
.description('Manually trigger a task and wait for completion')
|
|
119
|
+
.option('--wait', 'Poll until execution finishes', false)
|
|
120
|
+
// NOTE: no --executor option here — TriggerTaskDto only accepts `params`
|
|
121
|
+
// and the backend ValidationPipe runs with forbidNonWhitelisted, so a
|
|
122
|
+
// per-trigger pin would be rejected with 400. Executor pinning IS
|
|
123
|
+
// supported by the backend as a task-level field (tasks.executorId) — set
|
|
124
|
+
// it via `acf task create/update --executor <id>`, not per run.
|
|
125
|
+
.action(async (id, opts) => {
|
|
126
|
+
const spinner = (0, ora_1.default)('Triggering task…').start();
|
|
127
|
+
try {
|
|
128
|
+
const exec = await (0, client_1.post)(`/tasks/${id}/trigger`);
|
|
129
|
+
spinner.succeed(`Execution started: ${exec.id}`);
|
|
130
|
+
if (opts.wait) {
|
|
131
|
+
await pollExecution(exec.id);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
spinner.fail('Failed to trigger');
|
|
136
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
// acf task executions <id>
|
|
141
|
+
cmd.command('executions <id>')
|
|
142
|
+
.description('List recent executions for a task')
|
|
143
|
+
.option('-n, --limit <n>', 'Number of results', '10')
|
|
144
|
+
.action(async (id, opts) => {
|
|
145
|
+
const spinner = (0, ora_1.default)('Fetching executions…').start();
|
|
146
|
+
try {
|
|
147
|
+
// 后端 PaginationDto 只认 page/pageSize——不发送 `limit`,
|
|
148
|
+
// 否则开启 forbidNonWhitelisted 后必然 400(N7/N10)。
|
|
149
|
+
const data = await (0, client_1.get)(`/tasks/${id}/executions`, {
|
|
150
|
+
pageSize: opts.limit,
|
|
151
|
+
page: 1,
|
|
152
|
+
});
|
|
153
|
+
spinner.stop();
|
|
154
|
+
const table = new cli_table3_1.default({
|
|
155
|
+
// U11: exitCode column — distinguishes "failed by callback
|
|
156
|
+
// report" (exit 0 / null) from "process died" (non-zero).
|
|
157
|
+
head: ['Exec ID', 'Status', 'Duration', 'Exit', 'Started'],
|
|
158
|
+
colWidths: [14, 12, 12, 6, 25],
|
|
159
|
+
style: { head: ['cyan'] },
|
|
160
|
+
});
|
|
161
|
+
for (const e of data.list ?? []) {
|
|
162
|
+
table.push([
|
|
163
|
+
e.id.slice(0, 12),
|
|
164
|
+
statusColor(e.status),
|
|
165
|
+
e.duration ? `${e.duration}ms` : '-',
|
|
166
|
+
e.exitCode ?? '-',
|
|
167
|
+
new Date(e.createdAt).toLocaleString(),
|
|
168
|
+
]);
|
|
169
|
+
}
|
|
170
|
+
console.log(table.toString());
|
|
171
|
+
}
|
|
172
|
+
catch (e) {
|
|
173
|
+
spinner.fail('Failed');
|
|
174
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
175
|
+
process.exit(1);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
// acf task logs <execId>
|
|
179
|
+
cmd.command('logs <execId>')
|
|
180
|
+
.description('Fetch execution logs (line-paginated)')
|
|
181
|
+
.option('-f, --from-line <n>', 'Start line (0-based)', '0')
|
|
182
|
+
.option('-n, --limit <n>', 'Max lines to fetch (max 2000)', '200')
|
|
183
|
+
.option('--tail <n>', 'Show last N lines (overrides --from-line)')
|
|
184
|
+
.action(async (execId, opts) => {
|
|
185
|
+
const spinner = (0, ora_1.default)('Fetching logs…').start();
|
|
186
|
+
try {
|
|
187
|
+
if (opts.tail) {
|
|
188
|
+
const tail = Math.max(1, parseInt(opts.tail, 10) || 50);
|
|
189
|
+
const head = await (0, client_1.get)(`/tasks/executions/${execId}/logs`, {
|
|
190
|
+
fromLine: 0,
|
|
191
|
+
limit: 1,
|
|
192
|
+
});
|
|
193
|
+
const from = Math.max(0, head.totalLines - tail);
|
|
194
|
+
const data = await (0, client_1.get)(`/tasks/executions/${execId}/logs`, { fromLine: from, limit: tail });
|
|
195
|
+
spinner.stop();
|
|
196
|
+
for (const l of data.lines ?? [])
|
|
197
|
+
console.log(l);
|
|
198
|
+
console.log(chalk_1.default.gray(`\n(${data.lines?.length ?? 0}/${data.totalLines} lines — last ${tail})`));
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
const fromLine = parseInt(opts.fromLine, 10) || 0;
|
|
202
|
+
const data = await (0, client_1.get)(`/tasks/executions/${execId}/logs`, { fromLine, limit: opts.limit });
|
|
203
|
+
spinner.stop();
|
|
204
|
+
for (const l of data.lines ?? [])
|
|
205
|
+
console.log(l);
|
|
206
|
+
if (data.hasMore) {
|
|
207
|
+
console.log(chalk_1.default.gray(`\n… hasMore — next: acf task logs ${execId} --from-line ${fromLine + (data.lines?.length ?? 0)}`));
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
console.log(chalk_1.default.gray(`\n(${data.totalLines} lines total)`));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
catch (e) {
|
|
215
|
+
spinner.fail('Failed to fetch logs');
|
|
216
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
217
|
+
process.exit(1);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
// acf task analyze <taskId> <execId>
|
|
221
|
+
cmd.command('analyze <taskId> <execId>')
|
|
222
|
+
.description('Run AI analysis on a failed execution')
|
|
223
|
+
.action(async (taskId, execId) => {
|
|
224
|
+
const spinner = (0, ora_1.default)('Running AI analysis…').start();
|
|
225
|
+
try {
|
|
226
|
+
const result = await (0, client_1.post)(`/tasks/${taskId}/executions/${execId}/analyze`);
|
|
227
|
+
spinner.stop();
|
|
228
|
+
console.log(chalk_1.default.bold('\nAI Analysis'));
|
|
229
|
+
console.log(result.aiAnalysis || 'No analysis available (AI not configured).');
|
|
230
|
+
}
|
|
231
|
+
catch (e) {
|
|
232
|
+
spinner.fail('Analysis failed');
|
|
233
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
234
|
+
process.exit(1);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
// acf task suggest-schedule <id>
|
|
238
|
+
cmd.command('suggest-schedule <id>')
|
|
239
|
+
.description('Ask AI to suggest an optimal cron schedule')
|
|
240
|
+
.action(async (id) => {
|
|
241
|
+
const spinner = (0, ora_1.default)('Asking AI for schedule suggestion…').start();
|
|
242
|
+
try {
|
|
243
|
+
const result = await (0, client_1.post)(`/tasks/${id}/suggest-schedule`);
|
|
244
|
+
spinner.stop();
|
|
245
|
+
console.log(chalk_1.default.bold('Schedule Suggestion'));
|
|
246
|
+
console.log(' Current :', result.currentCron ?? '(none)');
|
|
247
|
+
console.log(' Suggested :', chalk_1.default.green(result.suggestedCron));
|
|
248
|
+
console.log('\nReasoning:');
|
|
249
|
+
console.log(result.reasoning);
|
|
250
|
+
}
|
|
251
|
+
catch (e) {
|
|
252
|
+
spinner.fail('Failed');
|
|
253
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
254
|
+
process.exit(1);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
// acf task stats <id>
|
|
258
|
+
cmd.command('stats <id>')
|
|
259
|
+
.description('Show execution statistics for a task')
|
|
260
|
+
.action(async (id) => {
|
|
261
|
+
const spinner = (0, ora_1.default)('Fetching stats…').start();
|
|
262
|
+
try {
|
|
263
|
+
const s = await (0, client_1.get)(`/tasks/${id}/stats`);
|
|
264
|
+
spinner.stop();
|
|
265
|
+
console.log(chalk_1.default.bold('Execution Stats'));
|
|
266
|
+
console.log(` Success rate : ${chalk_1.default.green(s.successRate + '%')}`);
|
|
267
|
+
console.log(` Avg duration : ${s.avgDuration}ms`);
|
|
268
|
+
console.log(` Total runs : ${s.totalRuns}`);
|
|
269
|
+
}
|
|
270
|
+
catch (e) {
|
|
271
|
+
spinner.fail('Failed');
|
|
272
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
273
|
+
process.exit(1);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
// acf task versions <id>
|
|
277
|
+
cmd.command('versions <id>')
|
|
278
|
+
.description('List historical versions of a task')
|
|
279
|
+
.action(async (id) => {
|
|
280
|
+
const spinner = (0, ora_1.default)('Fetching task versions…').start();
|
|
281
|
+
try {
|
|
282
|
+
const versions = await (0, client_1.get)(`/tasks/${id}/versions`);
|
|
283
|
+
spinner.stop();
|
|
284
|
+
const table = new cli_table3_1.default({
|
|
285
|
+
head: ['Version', 'Commit', 'Created By', 'Created', 'Description'],
|
|
286
|
+
colWidths: [12, 14, 16, 25, 30],
|
|
287
|
+
style: { head: ['cyan'] },
|
|
288
|
+
});
|
|
289
|
+
for (const v of versions) {
|
|
290
|
+
table.push([
|
|
291
|
+
v.version,
|
|
292
|
+
v.gitCommit?.slice(0, 12) ?? '-',
|
|
293
|
+
v.createdBy ?? '-',
|
|
294
|
+
new Date(v.createdAt).toLocaleString(),
|
|
295
|
+
v.description ?? '-',
|
|
296
|
+
]);
|
|
297
|
+
}
|
|
298
|
+
console.log(table.toString());
|
|
299
|
+
}
|
|
300
|
+
catch (e) {
|
|
301
|
+
spinner.fail('Failed to list versions');
|
|
302
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
303
|
+
process.exit(1);
|
|
304
|
+
}
|
|
305
|
+
});
|
|
306
|
+
// acf task rollback <id>
|
|
307
|
+
cmd.command('rollback <id>')
|
|
308
|
+
.description('Roll a task back to a specific historical version snapshot')
|
|
309
|
+
.requiredOption('--version <versionId>', 'Version ID to roll back to (see: acf task versions <id>)')
|
|
310
|
+
.action(async (id, opts) => {
|
|
311
|
+
const spinner = (0, ora_1.default)('Rolling back task…').start();
|
|
312
|
+
try {
|
|
313
|
+
const t = await (0, client_1.post)(`/tasks/${id}/versions/${opts.version}/rollback`);
|
|
314
|
+
spinner.succeed(`Task rolled back: ${t.id}`);
|
|
315
|
+
console.log(chalk_1.default.gray(` name: ${t.name} status: ${statusColor(t.status)}`));
|
|
316
|
+
}
|
|
317
|
+
catch (e) {
|
|
318
|
+
spinner.fail('Failed to roll back');
|
|
319
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
320
|
+
process.exit(1);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
// acf task compare <id> <versionId1> <versionId2>
|
|
324
|
+
cmd.command('compare <id> <versionId1> <versionId2>')
|
|
325
|
+
.description('Diff two task versions (shows fields whose values differ)')
|
|
326
|
+
.action(async (id, versionId1, versionId2) => {
|
|
327
|
+
const spinner = (0, ora_1.default)('Comparing versions…').start();
|
|
328
|
+
try {
|
|
329
|
+
const diff = await (0, client_1.get)(`/tasks/${id}/versions/${versionId1}/compare/${versionId2}`);
|
|
330
|
+
spinner.stop();
|
|
331
|
+
const keys = Object.keys(diff ?? {});
|
|
332
|
+
if (keys.length === 0) {
|
|
333
|
+
console.log(chalk_1.default.green('No differences between the two versions.'));
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
const table = new cli_table3_1.default({
|
|
337
|
+
head: ['Field', 'Version 1', 'Version 2'],
|
|
338
|
+
colWidths: [24, 38, 38],
|
|
339
|
+
style: { head: ['cyan'] },
|
|
340
|
+
wordWrap: true,
|
|
341
|
+
});
|
|
342
|
+
for (const k of keys) {
|
|
343
|
+
table.push([
|
|
344
|
+
k,
|
|
345
|
+
JSON.stringify(diff[k].old) ?? '-',
|
|
346
|
+
JSON.stringify(diff[k].new) ?? '-',
|
|
347
|
+
]);
|
|
348
|
+
}
|
|
349
|
+
console.log(table.toString());
|
|
350
|
+
}
|
|
351
|
+
catch (e) {
|
|
352
|
+
spinner.fail('Failed to compare versions');
|
|
353
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
354
|
+
process.exit(1);
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
// acf task create
|
|
358
|
+
cmd.command('create')
|
|
359
|
+
.description('Create a new task (JSON payload via --json or --file)')
|
|
360
|
+
.requiredOption('--json <body>', 'Task body as JSON string')
|
|
361
|
+
.option('--file <path>', 'Read task body from a JSON file (overrides --json)')
|
|
362
|
+
.option('--executor <id>', 'Pin the task to a specific executor ID (uuid); mutually exclusive with executeMode=broadcast')
|
|
363
|
+
.action(async (opts) => {
|
|
364
|
+
const spinner = (0, ora_1.default)('Creating task…').start();
|
|
365
|
+
try {
|
|
366
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
|
|
367
|
+
const raw = opts.file
|
|
368
|
+
? await fs.readFile(opts.file, 'utf-8')
|
|
369
|
+
: opts.json;
|
|
370
|
+
const body = JSON.parse(raw);
|
|
371
|
+
// R7 (N20): 显式 --executor 覆盖/补写 body.executorId(pinning)。
|
|
372
|
+
if (opts.executor)
|
|
373
|
+
body.executorId = opts.executor;
|
|
374
|
+
const t = await (0, client_1.post)('/tasks', body);
|
|
375
|
+
spinner.succeed(`Task created: ${t.id}`);
|
|
376
|
+
console.log(chalk_1.default.gray(` name: ${t.name} status: ${statusColor(t.status)}`));
|
|
377
|
+
}
|
|
378
|
+
catch (e) {
|
|
379
|
+
spinner.fail('Failed to create task');
|
|
380
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
381
|
+
process.exit(1);
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
// acf task update <id>
|
|
385
|
+
cmd.command('update <id>')
|
|
386
|
+
.description('Update a task (JSON payload via --json or --file)')
|
|
387
|
+
.requiredOption('--json <body>', 'Task patch body as JSON string')
|
|
388
|
+
.option('--file <path>', 'Read task patch body from a JSON file (overrides --json)')
|
|
389
|
+
.option('--executor <id>', 'Pin the task to a specific executor ID (uuid); pass --json {"executorId":null} to clear. Mutually exclusive with executeMode=broadcast')
|
|
390
|
+
.action(async (id, opts) => {
|
|
391
|
+
const spinner = (0, ora_1.default)('Updating task…').start();
|
|
392
|
+
try {
|
|
393
|
+
const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
|
|
394
|
+
const raw = opts.file
|
|
395
|
+
? await fs.readFile(opts.file, 'utf-8')
|
|
396
|
+
: opts.json;
|
|
397
|
+
const body = JSON.parse(raw);
|
|
398
|
+
// R7 (N20): 显式 --executor 覆盖/补写 body.executorId(pinning)。
|
|
399
|
+
if (opts.executor)
|
|
400
|
+
body.executorId = opts.executor;
|
|
401
|
+
const t = await (0, client_1.patch)(`/tasks/${id}`, body);
|
|
402
|
+
spinner.succeed(`Task updated: ${t.id}`);
|
|
403
|
+
console.log(chalk_1.default.gray(` name: ${t.name} status: ${statusColor(t.status)}`));
|
|
404
|
+
}
|
|
405
|
+
catch (e) {
|
|
406
|
+
spinner.fail('Failed to update task');
|
|
407
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
408
|
+
process.exit(1);
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
// acf task delete <id>
|
|
412
|
+
cmd.command('delete <id>')
|
|
413
|
+
.description('Delete a task (force-terminates running executions)')
|
|
414
|
+
.option('-y, --yes', 'Skip confirmation prompt', false)
|
|
415
|
+
.action(async (id, opts) => {
|
|
416
|
+
if (!opts.yes) {
|
|
417
|
+
const readline = await Promise.resolve().then(() => __importStar(require('readline/promises')));
|
|
418
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
419
|
+
const answer = await rl.question(`Delete task ${id}? Running executions will be force-terminated. [y/N] `);
|
|
420
|
+
rl.close();
|
|
421
|
+
if (!/^y(es)?$/i.test(answer)) {
|
|
422
|
+
console.log(chalk_1.default.yellow('Aborted.'));
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
const spinner = (0, ora_1.default)('Deleting task…').start();
|
|
427
|
+
try {
|
|
428
|
+
await (0, client_1.del)(`/tasks/${id}`);
|
|
429
|
+
spinner.succeed(`Task ${id} deleted`);
|
|
430
|
+
}
|
|
431
|
+
catch (e) {
|
|
432
|
+
spinner.fail('Failed to delete task');
|
|
433
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
434
|
+
process.exit(1);
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
// acf task pause <id>
|
|
438
|
+
cmd.command('pause <id>')
|
|
439
|
+
.description('Pause task scheduled execution')
|
|
440
|
+
.action(async (id) => {
|
|
441
|
+
const spinner = (0, ora_1.default)('Pausing task…').start();
|
|
442
|
+
try {
|
|
443
|
+
const t = await (0, client_1.post)(`/tasks/${id}/pause`);
|
|
444
|
+
spinner.succeed(`Task ${id} paused`);
|
|
445
|
+
console.log(chalk_1.default.gray(` status: ${statusColor(t.status)}`));
|
|
446
|
+
}
|
|
447
|
+
catch (e) {
|
|
448
|
+
spinner.fail('Failed to pause task');
|
|
449
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
450
|
+
process.exit(1);
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
// acf task resume <id>
|
|
454
|
+
cmd.command('resume <id>')
|
|
455
|
+
.description('Resume task scheduled execution')
|
|
456
|
+
.action(async (id) => {
|
|
457
|
+
const spinner = (0, ora_1.default)('Resuming task…').start();
|
|
458
|
+
try {
|
|
459
|
+
const t = await (0, client_1.post)(`/tasks/${id}/resume`);
|
|
460
|
+
spinner.succeed(`Task ${id} resumed`);
|
|
461
|
+
console.log(chalk_1.default.gray(` status: ${statusColor(t.status)}`));
|
|
462
|
+
}
|
|
463
|
+
catch (e) {
|
|
464
|
+
spinner.fail('Failed to resume task');
|
|
465
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
466
|
+
process.exit(1);
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
// acf task kill <taskId> <execId>
|
|
470
|
+
cmd.command('kill <taskId> <execId>')
|
|
471
|
+
.description('Force-cancel a running or pending execution')
|
|
472
|
+
.action(async (taskId, execId) => {
|
|
473
|
+
const spinner = (0, ora_1.default)('Cancelling execution…').start();
|
|
474
|
+
try {
|
|
475
|
+
const r = await (0, client_1.post)(`/tasks/${taskId}/executions/${execId}/kill`);
|
|
476
|
+
spinner.succeed(r.message || 'Execution cancelled');
|
|
477
|
+
}
|
|
478
|
+
catch (e) {
|
|
479
|
+
spinner.fail('Failed to cancel execution');
|
|
480
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
481
|
+
process.exit(1);
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
// ECO-02: acf task lint <file> —— 本地语法检查(node: 语法编译不执行;
|
|
485
|
+
// python: ast.parse;shell: bash -n)。上传 glue 前把语法错误挡在本地。
|
|
486
|
+
cmd
|
|
487
|
+
.command('lint <file>')
|
|
488
|
+
.description('Syntax-check a glue script locally (js/mjs/cjs/py/sh) without executing it')
|
|
489
|
+
.option('--language <lang>', 'Override language detection (node/python/shell)')
|
|
490
|
+
.action((file, opts) => {
|
|
491
|
+
let source;
|
|
492
|
+
try {
|
|
493
|
+
source = fs.readFileSync(file, 'utf-8');
|
|
494
|
+
}
|
|
495
|
+
catch {
|
|
496
|
+
console.error(chalk_1.default.red(`Cannot read file: ${file}`));
|
|
497
|
+
process.exit(1);
|
|
498
|
+
}
|
|
499
|
+
const ext = path.extname(file).toLowerCase();
|
|
500
|
+
const lang = opts.language ??
|
|
501
|
+
(['.js', '.mjs', '.cjs'].includes(ext)
|
|
502
|
+
? 'node'
|
|
503
|
+
: ext === '.py'
|
|
504
|
+
? 'python'
|
|
505
|
+
: ['.sh', '.bash'].includes(ext)
|
|
506
|
+
? 'shell'
|
|
507
|
+
: undefined);
|
|
508
|
+
if (!lang) {
|
|
509
|
+
console.error(chalk_1.default.red(`Cannot infer language from extension "${ext}" — pass --language node|python|shell`));
|
|
510
|
+
process.exit(1);
|
|
511
|
+
}
|
|
512
|
+
const ok = (msg) => {
|
|
513
|
+
console.log(chalk_1.default.green(`✔ ${file}: ${msg}`));
|
|
514
|
+
process.exit(0);
|
|
515
|
+
};
|
|
516
|
+
if (lang === 'node') {
|
|
517
|
+
try {
|
|
518
|
+
// new Function 编译函数体但不调用——纯语法检查,零执行副作用。
|
|
519
|
+
// 包裹 try/catch 形态的 glue 源码同样能被编译。
|
|
520
|
+
// eslint-disable-next-line no-new-func
|
|
521
|
+
new Function(source);
|
|
522
|
+
}
|
|
523
|
+
catch (err) {
|
|
524
|
+
console.error(chalk_1.default.red(`✗ ${file}: syntax error`));
|
|
525
|
+
console.error(chalk_1.default.red(err instanceof Error ? err.message : String(err)));
|
|
526
|
+
process.exit(1);
|
|
527
|
+
}
|
|
528
|
+
ok('syntax OK (node)');
|
|
529
|
+
}
|
|
530
|
+
else if (lang === 'python') {
|
|
531
|
+
const py = ['python3', 'python'].find((bin) => {
|
|
532
|
+
const r = (0, child_process_1.spawnSync)(bin, ['--version'], { stdio: 'ignore' });
|
|
533
|
+
return r.status === 0;
|
|
534
|
+
});
|
|
535
|
+
if (!py) {
|
|
536
|
+
console.error(chalk_1.default.red('python not found on PATH — install Python 3 to lint python glue'));
|
|
537
|
+
process.exit(1);
|
|
538
|
+
}
|
|
539
|
+
const r = (0, child_process_1.spawnSync)(py, ['-c', `import ast,sys; ast.parse(open(sys.argv[1],encoding='utf-8').read())`, file], {
|
|
540
|
+
stdio: 'pipe',
|
|
541
|
+
});
|
|
542
|
+
if (r.status !== 0) {
|
|
543
|
+
console.error(chalk_1.default.red(`✗ ${file}: syntax error`));
|
|
544
|
+
process.stderr.write(r.stderr?.toString() ?? '');
|
|
545
|
+
process.exit(1);
|
|
546
|
+
}
|
|
547
|
+
ok('syntax OK (python, ast.parse)');
|
|
548
|
+
}
|
|
549
|
+
else {
|
|
550
|
+
const r = (0, child_process_1.spawnSync)('bash', ['-n', file], { stdio: 'pipe' });
|
|
551
|
+
if (r.status !== 0) {
|
|
552
|
+
console.error(chalk_1.default.red(`✗ ${file}: syntax error`));
|
|
553
|
+
process.stderr.write(r.stderr?.toString() ?? '');
|
|
554
|
+
process.exit(1);
|
|
555
|
+
}
|
|
556
|
+
ok('syntax OK (bash -n)');
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
return cmd;
|
|
560
|
+
}
|
|
561
|
+
exports.tasksCommand = tasksCommand;
|
|
562
|
+
async function pollExecution(execId) {
|
|
563
|
+
const INTERVAL = 2000;
|
|
564
|
+
const MAX_WAIT = 10 * 60 * 1000; // 10 min
|
|
565
|
+
const spinner = (0, ora_1.default)('Waiting for execution…').start();
|
|
566
|
+
const start = Date.now();
|
|
567
|
+
while (Date.now() - start < MAX_WAIT) {
|
|
568
|
+
await sleep(INTERVAL);
|
|
569
|
+
try {
|
|
570
|
+
const exec = await (0, client_1.get)(`/tasks/executions/${execId}`);
|
|
571
|
+
// killed 是后端 ExecutionStatus 的合法终态(acf task kill / Web 端),
|
|
572
|
+
// 遗漏会让 --wait 在被 kill 后空转到 MAX_WAIT 并误报超时(N10)。
|
|
573
|
+
if (['success', 'failed', 'timeout', 'cancelled', 'killed'].includes(exec.status)) {
|
|
574
|
+
if (exec.status === 'success') {
|
|
575
|
+
spinner.succeed(`Execution ${exec.status} in ${exec.duration ?? '?'}ms`);
|
|
576
|
+
}
|
|
577
|
+
else {
|
|
578
|
+
spinner.fail(`Execution ${exec.status}`);
|
|
579
|
+
// CLI-EXIT-01(本轮审计):--wait 的契约是「等完并给出结果」,
|
|
580
|
+
// 但此前失败终态只打印原因就 return,退出码依旧是 0——CI 里
|
|
581
|
+
// `acf task trigger <id> --wait && echo ok` 在任务失败时照样打印
|
|
582
|
+
// ok,整条 --wait 通道对自动化不可用。与 `acf exec tail` 同场景
|
|
583
|
+
// 的语义对齐(那里已是 status==='success' ? 0 : 1):失败终态
|
|
584
|
+
// 置 exitCode=1,成功保持 0。
|
|
585
|
+
// 用 exitCode 赋值而非 process.exit(1):让调用方(trigger 的
|
|
586
|
+
// action、以及将来任何组合命令)仍能走完自己的收尾路径。
|
|
587
|
+
process.exitCode = 1;
|
|
588
|
+
// U11: surface the structured failure cause the executor reported
|
|
589
|
+
// (exitCode / failureReason) — previously only aiAnalysis printed,
|
|
590
|
+
// so a non-zero exit or timeout reason was invisible without
|
|
591
|
+
// digging through `acf task logs`.
|
|
592
|
+
if (exec.exitCode !== null && exec.exitCode !== undefined) {
|
|
593
|
+
console.log(chalk_1.default.yellow(' Exit code :'), exec.exitCode);
|
|
594
|
+
}
|
|
595
|
+
if (exec.failureReason) {
|
|
596
|
+
console.log(chalk_1.default.yellow(' Failure reason :'), exec.failureReason);
|
|
597
|
+
}
|
|
598
|
+
if (exec.errorMessage) {
|
|
599
|
+
console.log(chalk_1.default.yellow(' Error :'), exec.errorMessage);
|
|
600
|
+
}
|
|
601
|
+
if (exec.aiAnalysis) {
|
|
602
|
+
console.log(chalk_1.default.yellow('\nAI Analysis:'), exec.aiAnalysis);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
spinner.text = `Status: ${exec.status}…`;
|
|
608
|
+
}
|
|
609
|
+
catch (e) {
|
|
610
|
+
// 4xx(除 429)是确定性失败(token 失效/执行不存在等)——继续轮询只会
|
|
611
|
+
// 空转到 MAX_WAIT 并误报超时,掩盖真实错误;立即退出并透出后端消息。
|
|
612
|
+
const status = axios_1.default.isAxiosError(e) ? e.response?.status : undefined;
|
|
613
|
+
if (status && status >= 400 && status < 500 && status !== 429) {
|
|
614
|
+
spinner.fail('Waiting for execution failed');
|
|
615
|
+
console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
|
|
616
|
+
process.exit(1);
|
|
617
|
+
}
|
|
618
|
+
// transient (network / 429 / 5xx), keep polling
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
spinner.fail('Timed out waiting for execution');
|
|
622
|
+
}
|
|
623
|
+
function sleep(ms) {
|
|
624
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
625
|
+
}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** Absolute path of the on-disk config file (diagnostics / tests / showConfig). */
|
|
3
|
+
export declare function getConfigPath(): string;
|
|
4
|
+
/**
|
|
5
|
+
* SEC-NEW-4: best-effort hardening of an existing config file to owner-only
|
|
6
|
+
* permissions. conf applies `configFileMode` when it *writes*, but it never
|
|
7
|
+
* rewrites a file it only *reads* — so installs created before this change keep
|
|
8
|
+
* their 0666/0644 mode unless we chmod once here (the store constructor does
|
|
9
|
+
* write a defaults-bearing file, so a fresh install is already 0600).
|
|
10
|
+
* Never throws: the chmod can legitimately fail (Windows ACL semantics,
|
|
11
|
+
* read-only mounts) and must not break the CLI. Credentials are never moved or
|
|
12
|
+
* deleted by this repair — only the file mode changes.
|
|
13
|
+
*/
|
|
14
|
+
export declare function hardenConfigPermissions(): void;
|
|
15
|
+
export declare function getApiUrl(): string;
|
|
16
|
+
export declare function getToken(): string;
|
|
17
|
+
export declare function getRefreshToken(): string;
|
|
18
|
+
export declare function setApiUrl(url: string): void;
|
|
19
|
+
export declare function setToken(token: string): void;
|
|
20
|
+
export declare function setRefreshToken(token: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* BUG-13: 刷新彻底失败(refresh token 也已过期/被轮换掉)时清除本地凭据,
|
|
23
|
+
* 后续请求返回到「未登录」状态——避免拿着必死 token 反复打 401。
|
|
24
|
+
* apiUrl 保留(用户环境不丢)。
|
|
25
|
+
*/
|
|
26
|
+
export declare function clearAuth(): void;
|
|
27
|
+
export declare function showConfig(): void;
|