@autocodeflow/cli 1.5.2 → 1.6.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.
@@ -1,56 +1,27 @@
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");
1
+ import { Command, InvalidArgumentError } from 'commander';
2
+ import Table from 'cli-table3';
3
+ import chalk from 'chalk';
4
+ import ora from 'ora';
5
+ import axios from 'axios';
6
+ import { spawnSync } from 'child_process';
7
+ import * as fs from 'fs';
8
+ import * as path from 'path';
9
+ import { get, post, patch, del, formatApiError, ANALYZE_TIMEOUT_MS } from '../client.js';
39
10
  function statusColor(s) {
40
11
  if (s === 'success')
41
- return chalk_1.default.green(s);
12
+ return chalk.green(s);
42
13
  if (s === 'failed' || s === 'timeout' || s === 'killed')
43
- return chalk_1.default.red(s);
14
+ return chalk.red(s);
44
15
  if (s === 'running')
45
- return chalk_1.default.cyan(s);
16
+ return chalk.cyan(s);
46
17
  if (s === 'active')
47
- return chalk_1.default.green(s);
18
+ return chalk.green(s);
48
19
  if (s === 'paused')
49
- return chalk_1.default.yellow(s);
50
- return chalk_1.default.gray(s);
20
+ return chalk.yellow(s);
21
+ return chalk.gray(s);
51
22
  }
52
- function tasksCommand() {
53
- const cmd = new commander_1.Command('task').description('Manage tasks');
23
+ export function tasksCommand() {
24
+ const cmd = new Command('task').description('Manage tasks');
54
25
  // acf task list
55
26
  cmd.command('list')
56
27
  .description('List all tasks')
@@ -60,10 +31,10 @@ function tasksCommand() {
60
31
  .option('-n, --page-size <n>', 'Items per page', '20')
61
32
  .option('--json', 'Emit raw JSON (CI-consumable, no table)')
62
33
  .action(async (opts) => {
63
- const spinner = (0, ora_1.default)('Fetching tasks…').start();
34
+ const spinner = ora('Fetching tasks…').start();
64
35
  try {
65
36
  // ListTasksQueryDto has `name` (no `keyword`)
66
- const data = await (0, client_1.get)('/tasks', {
37
+ const data = await get('/tasks', {
67
38
  page: opts.page,
68
39
  pageSize: opts.pageSize,
69
40
  status: opts.status,
@@ -75,7 +46,7 @@ function tasksCommand() {
75
46
  console.log(JSON.stringify(data));
76
47
  return;
77
48
  }
78
- const table = new cli_table3_1.default({
49
+ const table = new Table({
79
50
  head: ['ID', 'Name', 'Runtime', 'Status', 'Cron'],
80
51
  colWidths: [14, 30, 12, 10, 20],
81
52
  style: { head: ['cyan'] },
@@ -84,23 +55,30 @@ function tasksCommand() {
84
55
  table.push([t.id.slice(0, 12), t.name, t.runtime, statusColor(t.status), t.cronExpression ?? '-']);
85
56
  }
86
57
  console.log(table.toString());
87
- console.log(chalk_1.default.gray(`Total: ${data.total} page ${data.page}/${Math.ceil(data.total / data.pageSize)}`));
58
+ console.log(chalk.gray(`Total: ${data.total} page ${data.page}/${Math.ceil(data.total / data.pageSize)}`));
88
59
  }
89
60
  catch (e) {
90
61
  spinner.fail('Failed to list tasks');
91
- console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
62
+ console.error(chalk.red(formatApiError(e)));
92
63
  process.exit(1);
93
64
  }
94
65
  });
95
66
  // acf task get <id>
96
67
  cmd.command('get <id>')
97
68
  .description('Show task details')
98
- .action(async (id) => {
99
- const spinner = (0, ora_1.default)('Fetching task…').start();
69
+ // 第四轮审计(--json 补面):对齐 task list 的 ECO-02 CI 消费面
70
+ .option('--json', 'Emit raw JSON (CI-consumable, no table)')
71
+ .action(async (id, opts) => {
72
+ const spinner = ora('Fetching task…').start();
100
73
  try {
101
- const t = await (0, client_1.get)(`/tasks/${id}`);
74
+ const t = await get(`/tasks/${id}`);
102
75
  spinner.stop();
103
- console.log(chalk_1.default.bold('Task Details'));
76
+ if (opts.json) {
77
+ // ECO-02: --json —— CI/脚本消费面(pretty print 便于人工核查)
78
+ console.log(JSON.stringify(t, null, 2));
79
+ return;
80
+ }
81
+ console.log(chalk.bold('Task Details'));
104
82
  console.log(' ID :', t.id);
105
83
  console.log(' Name :', t.name);
106
84
  console.log(' Runtime :', t.runtime);
@@ -109,7 +87,7 @@ function tasksCommand() {
109
87
  }
110
88
  catch (e) {
111
89
  spinner.fail('Failed');
112
- console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
90
+ console.error(chalk.red(formatApiError(e)));
113
91
  process.exit(1);
114
92
  }
115
93
  });
@@ -123,7 +101,7 @@ function tasksCommand() {
123
101
  .option('--wait-timeout <seconds>', 'Max seconds to keep polling with --wait before giving up (default 600)', (v) => {
124
102
  const n = Number.parseInt(v, 10);
125
103
  if (!Number.isFinite(n) || n <= 0) {
126
- throw new commander_1.InvalidArgumentError('must be a positive integer (seconds)');
104
+ throw new InvalidArgumentError('must be a positive integer (seconds)');
127
105
  }
128
106
  return n;
129
107
  }, 600)
@@ -132,18 +110,29 @@ function tasksCommand() {
132
110
  // per-trigger pin would be rejected with 400. Executor pinning IS
133
111
  // supported by the backend as a task-level field (tasks.executorId) — set
134
112
  // it via `acf task create/update --executor <id>`, not per run.
113
+ // 第四轮审计(--json 补面):trigger 响应(execution 对象)直出 JSON,
114
+ // CI 拿 executionId 做后续断言无需解析人读文本。
115
+ .option('--json', 'Emit raw JSON (CI-consumable, no table)')
135
116
  .action(async (id, opts) => {
136
- const spinner = (0, ora_1.default)('Triggering task…').start();
117
+ const spinner = ora('Triggering task…').start();
137
118
  try {
138
- const exec = await (0, client_1.post)(`/tasks/${id}/trigger`);
139
- spinner.succeed(`Execution started: ${exec.id}`);
119
+ const exec = await post(`/tasks/${id}/trigger`);
120
+ if (opts.json) {
121
+ // ECO-02 同款:--json —— ora 默认写 stderr,stdout 仍是干净 JSON;
122
+ // --wait 语义不变(等终态 + 非零退出码逻辑照旧生效)。
123
+ spinner.stop();
124
+ console.log(JSON.stringify(exec, null, 2));
125
+ }
126
+ else {
127
+ spinner.succeed(`Execution started: ${exec.id}`);
128
+ }
140
129
  if (opts.wait) {
141
130
  await pollExecution(exec.id, opts.waitTimeout);
142
131
  }
143
132
  }
144
133
  catch (e) {
145
134
  spinner.fail('Failed to trigger');
146
- console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
135
+ console.error(chalk.red(formatApiError(e)));
147
136
  process.exit(1);
148
137
  }
149
138
  });
@@ -152,16 +141,16 @@ function tasksCommand() {
152
141
  .description('List recent executions for a task')
153
142
  .option('-n, --limit <n>', 'Number of results', '10')
154
143
  .action(async (id, opts) => {
155
- const spinner = (0, ora_1.default)('Fetching executions…').start();
144
+ const spinner = ora('Fetching executions…').start();
156
145
  try {
157
146
  // 后端 PaginationDto 只认 page/pageSize——不发送 `limit`,
158
147
  // 否则开启 forbidNonWhitelisted 后必然 400(N7/N10)。
159
- const data = await (0, client_1.get)(`/tasks/${id}/executions`, {
148
+ const data = await get(`/tasks/${id}/executions`, {
160
149
  pageSize: opts.limit,
161
150
  page: 1,
162
151
  });
163
152
  spinner.stop();
164
- const table = new cli_table3_1.default({
153
+ const table = new Table({
165
154
  // U11: exitCode column — distinguishes "failed by callback
166
155
  // report" (exit 0 / null) from "process died" (non-zero).
167
156
  head: ['Exec ID', 'Status', 'Duration', 'Exit', 'Started'],
@@ -181,7 +170,7 @@ function tasksCommand() {
181
170
  }
182
171
  catch (e) {
183
172
  spinner.fail('Failed');
184
- console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
173
+ console.error(chalk.red(formatApiError(e)));
185
174
  process.exit(1);
186
175
  }
187
176
  });
@@ -191,39 +180,50 @@ function tasksCommand() {
191
180
  .option('-f, --from-line <n>', 'Start line (0-based)', '0')
192
181
  .option('-n, --limit <n>', 'Max lines to fetch (max 2000)', '200')
193
182
  .option('--tail <n>', 'Show last N lines (overrides --from-line)')
183
+ // 第四轮审计(--json 补面):行页对象(lines/totalLines/hasMore)直出 JSON
184
+ .option('--json', 'Emit raw JSON (CI-consumable, no table)')
194
185
  .action(async (execId, opts) => {
195
- const spinner = (0, ora_1.default)('Fetching logs…').start();
186
+ const spinner = ora('Fetching logs…').start();
196
187
  try {
197
188
  if (opts.tail) {
198
189
  const tail = Math.max(1, parseInt(opts.tail, 10) || 50);
199
- const head = await (0, client_1.get)(`/tasks/executions/${execId}/logs`, {
190
+ const head = await get(`/tasks/executions/${execId}/logs`, {
200
191
  fromLine: 0,
201
192
  limit: 1,
202
193
  });
203
194
  const from = Math.max(0, head.totalLines - tail);
204
- const data = await (0, client_1.get)(`/tasks/executions/${execId}/logs`, { fromLine: from, limit: tail });
195
+ const data = await get(`/tasks/executions/${execId}/logs`, { fromLine: from, limit: tail });
205
196
  spinner.stop();
197
+ if (opts.json) {
198
+ // ECO-02 同款:--json —— 附 fromLine 便于消费方续读
199
+ console.log(JSON.stringify({ ...data, fromLine: from }, null, 2));
200
+ return;
201
+ }
206
202
  for (const l of data.lines ?? [])
207
203
  console.log(l);
208
- console.log(chalk_1.default.gray(`\n(${data.lines?.length ?? 0}/${data.totalLines} lines — last ${tail})`));
204
+ console.log(chalk.gray(`\n(${data.lines?.length ?? 0}/${data.totalLines} lines — last ${tail})`));
209
205
  }
210
206
  else {
211
207
  const fromLine = parseInt(opts.fromLine, 10) || 0;
212
- const data = await (0, client_1.get)(`/tasks/executions/${execId}/logs`, { fromLine, limit: opts.limit });
208
+ const data = await get(`/tasks/executions/${execId}/logs`, { fromLine, limit: opts.limit });
213
209
  spinner.stop();
210
+ if (opts.json) {
211
+ console.log(JSON.stringify(data, null, 2));
212
+ return;
213
+ }
214
214
  for (const l of data.lines ?? [])
215
215
  console.log(l);
216
216
  if (data.hasMore) {
217
- console.log(chalk_1.default.gray(`\n… hasMore — next: acf task logs ${execId} --from-line ${fromLine + (data.lines?.length ?? 0)}`));
217
+ console.log(chalk.gray(`\n… hasMore — next: acf task logs ${execId} --from-line ${fromLine + (data.lines?.length ?? 0)}`));
218
218
  }
219
219
  else {
220
- console.log(chalk_1.default.gray(`\n(${data.totalLines} lines total)`));
220
+ console.log(chalk.gray(`\n(${data.totalLines} lines total)`));
221
221
  }
222
222
  }
223
223
  }
224
224
  catch (e) {
225
225
  spinner.fail('Failed to fetch logs');
226
- console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
226
+ console.error(chalk.red(formatApiError(e)));
227
227
  process.exit(1);
228
228
  }
229
229
  });
@@ -231,18 +231,18 @@ function tasksCommand() {
231
231
  cmd.command('analyze <taskId> <execId>')
232
232
  .description('Run AI analysis on a failed execution')
233
233
  .action(async (taskId, execId) => {
234
- const spinner = (0, ora_1.default)('Running AI analysis…').start();
234
+ const spinner = ora('Running AI analysis…').start();
235
235
  try {
236
236
  // NETOPT-6④:同步 AI 端点(服务端预算 60s×2)用 120s per-call 覆盖,
237
237
  // 否则默认 30s 结构性小于服务端预算,AI 跑满预算成功返回时 CLI 已超时。
238
- const result = await (0, client_1.post)(`/tasks/${taskId}/executions/${execId}/analyze`, undefined, client_1.ANALYZE_TIMEOUT_MS);
238
+ const result = await post(`/tasks/${taskId}/executions/${execId}/analyze`, undefined, ANALYZE_TIMEOUT_MS);
239
239
  spinner.stop();
240
- console.log(chalk_1.default.bold('\nAI Analysis'));
240
+ console.log(chalk.bold('\nAI Analysis'));
241
241
  console.log(result.aiAnalysis || 'No analysis available (AI not configured).');
242
242
  }
243
243
  catch (e) {
244
244
  spinner.fail('Analysis failed');
245
- console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
245
+ console.error(chalk.red(formatApiError(e)));
246
246
  process.exit(1);
247
247
  }
248
248
  });
@@ -250,20 +250,20 @@ function tasksCommand() {
250
250
  cmd.command('suggest-schedule <id>')
251
251
  .description('Ask AI to suggest an optimal cron schedule')
252
252
  .action(async (id) => {
253
- const spinner = (0, ora_1.default)('Asking AI for schedule suggestion…').start();
253
+ const spinner = ora('Asking AI for schedule suggestion…').start();
254
254
  try {
255
255
  // NETOPT-6④:同上——suggest-schedule 也是同步 AI 端点。
256
- const result = await (0, client_1.post)(`/tasks/${id}/suggest-schedule`, undefined, client_1.ANALYZE_TIMEOUT_MS);
256
+ const result = await post(`/tasks/${id}/suggest-schedule`, undefined, ANALYZE_TIMEOUT_MS);
257
257
  spinner.stop();
258
- console.log(chalk_1.default.bold('Schedule Suggestion'));
258
+ console.log(chalk.bold('Schedule Suggestion'));
259
259
  console.log(' Current :', result.currentCron ?? '(none)');
260
- console.log(' Suggested :', chalk_1.default.green(result.suggestedCron));
260
+ console.log(' Suggested :', chalk.green(result.suggestedCron));
261
261
  console.log('\nReasoning:');
262
262
  console.log(result.reasoning);
263
263
  }
264
264
  catch (e) {
265
265
  spinner.fail('Failed');
266
- console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
266
+ console.error(chalk.red(formatApiError(e)));
267
267
  process.exit(1);
268
268
  }
269
269
  });
@@ -271,18 +271,18 @@ function tasksCommand() {
271
271
  cmd.command('stats <id>')
272
272
  .description('Show execution statistics for a task')
273
273
  .action(async (id) => {
274
- const spinner = (0, ora_1.default)('Fetching stats…').start();
274
+ const spinner = ora('Fetching stats…').start();
275
275
  try {
276
- const s = await (0, client_1.get)(`/tasks/${id}/stats`);
276
+ const s = await get(`/tasks/${id}/stats`);
277
277
  spinner.stop();
278
- console.log(chalk_1.default.bold('Execution Stats'));
279
- console.log(` Success rate : ${chalk_1.default.green(s.successRate + '%')}`);
278
+ console.log(chalk.bold('Execution Stats'));
279
+ console.log(` Success rate : ${chalk.green(s.successRate + '%')}`);
280
280
  console.log(` Avg duration : ${s.avgDuration}ms`);
281
281
  console.log(` Total runs : ${s.totalRuns}`);
282
282
  }
283
283
  catch (e) {
284
284
  spinner.fail('Failed');
285
- console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
285
+ console.error(chalk.red(formatApiError(e)));
286
286
  process.exit(1);
287
287
  }
288
288
  });
@@ -290,11 +290,11 @@ function tasksCommand() {
290
290
  cmd.command('versions <id>')
291
291
  .description('List historical versions of a task')
292
292
  .action(async (id) => {
293
- const spinner = (0, ora_1.default)('Fetching task versions…').start();
293
+ const spinner = ora('Fetching task versions…').start();
294
294
  try {
295
- const versions = await (0, client_1.get)(`/tasks/${id}/versions`);
295
+ const versions = await get(`/tasks/${id}/versions`);
296
296
  spinner.stop();
297
- const table = new cli_table3_1.default({
297
+ const table = new Table({
298
298
  head: ['Version', 'Commit', 'Created By', 'Created', 'Description'],
299
299
  colWidths: [12, 14, 16, 25, 30],
300
300
  style: { head: ['cyan'] },
@@ -312,7 +312,7 @@ function tasksCommand() {
312
312
  }
313
313
  catch (e) {
314
314
  spinner.fail('Failed to list versions');
315
- console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
315
+ console.error(chalk.red(formatApiError(e)));
316
316
  process.exit(1);
317
317
  }
318
318
  });
@@ -321,15 +321,15 @@ function tasksCommand() {
321
321
  .description('Roll a task back to a specific historical version snapshot')
322
322
  .requiredOption('--version <versionId>', 'Version ID to roll back to (see: acf task versions <id>)')
323
323
  .action(async (id, opts) => {
324
- const spinner = (0, ora_1.default)('Rolling back task…').start();
324
+ const spinner = ora('Rolling back task…').start();
325
325
  try {
326
- const t = await (0, client_1.post)(`/tasks/${id}/versions/${opts.version}/rollback`);
326
+ const t = await post(`/tasks/${id}/versions/${opts.version}/rollback`);
327
327
  spinner.succeed(`Task rolled back: ${t.id}`);
328
- console.log(chalk_1.default.gray(` name: ${t.name} status: ${statusColor(t.status)}`));
328
+ console.log(chalk.gray(` name: ${t.name} status: ${statusColor(t.status)}`));
329
329
  }
330
330
  catch (e) {
331
331
  spinner.fail('Failed to roll back');
332
- console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
332
+ console.error(chalk.red(formatApiError(e)));
333
333
  process.exit(1);
334
334
  }
335
335
  });
@@ -337,16 +337,16 @@ function tasksCommand() {
337
337
  cmd.command('compare <id> <versionId1> <versionId2>')
338
338
  .description('Diff two task versions (shows fields whose values differ)')
339
339
  .action(async (id, versionId1, versionId2) => {
340
- const spinner = (0, ora_1.default)('Comparing versions…').start();
340
+ const spinner = ora('Comparing versions…').start();
341
341
  try {
342
- const diff = await (0, client_1.get)(`/tasks/${id}/versions/${versionId1}/compare/${versionId2}`);
342
+ const diff = await get(`/tasks/${id}/versions/${versionId1}/compare/${versionId2}`);
343
343
  spinner.stop();
344
344
  const keys = Object.keys(diff ?? {});
345
345
  if (keys.length === 0) {
346
- console.log(chalk_1.default.green('No differences between the two versions.'));
346
+ console.log(chalk.green('No differences between the two versions.'));
347
347
  return;
348
348
  }
349
- const table = new cli_table3_1.default({
349
+ const table = new Table({
350
350
  head: ['Field', 'Version 1', 'Version 2'],
351
351
  colWidths: [24, 38, 38],
352
352
  style: { head: ['cyan'] },
@@ -363,7 +363,7 @@ function tasksCommand() {
363
363
  }
364
364
  catch (e) {
365
365
  spinner.fail('Failed to compare versions');
366
- console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
366
+ console.error(chalk.red(formatApiError(e)));
367
367
  process.exit(1);
368
368
  }
369
369
  });
@@ -374,9 +374,9 @@ function tasksCommand() {
374
374
  .option('--file <path>', 'Read task body from a JSON file (overrides --json)')
375
375
  .option('--executor <id>', 'Pin the task to a specific executor ID (uuid); mutually exclusive with executeMode=broadcast')
376
376
  .action(async (opts) => {
377
- const spinner = (0, ora_1.default)('Creating task…').start();
377
+ const spinner = ora('Creating task…').start();
378
378
  try {
379
- const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
379
+ const fs = await import('fs/promises');
380
380
  const raw = opts.file
381
381
  ? await fs.readFile(opts.file, 'utf-8')
382
382
  : opts.json;
@@ -384,13 +384,13 @@ function tasksCommand() {
384
384
  // R7 (N20): 显式 --executor 覆盖/补写 body.executorId(pinning)。
385
385
  if (opts.executor)
386
386
  body.executorId = opts.executor;
387
- const t = await (0, client_1.post)('/tasks', body);
387
+ const t = await post('/tasks', body);
388
388
  spinner.succeed(`Task created: ${t.id}`);
389
- console.log(chalk_1.default.gray(` name: ${t.name} status: ${statusColor(t.status)}`));
389
+ console.log(chalk.gray(` name: ${t.name} status: ${statusColor(t.status)}`));
390
390
  }
391
391
  catch (e) {
392
392
  spinner.fail('Failed to create task');
393
- console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
393
+ console.error(chalk.red(formatApiError(e)));
394
394
  process.exit(1);
395
395
  }
396
396
  });
@@ -401,9 +401,9 @@ function tasksCommand() {
401
401
  .option('--file <path>', 'Read task patch body from a JSON file (overrides --json)')
402
402
  .option('--executor <id>', 'Pin the task to a specific executor ID (uuid); pass --json {"executorId":null} to clear. Mutually exclusive with executeMode=broadcast')
403
403
  .action(async (id, opts) => {
404
- const spinner = (0, ora_1.default)('Updating task…').start();
404
+ const spinner = ora('Updating task…').start();
405
405
  try {
406
- const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
406
+ const fs = await import('fs/promises');
407
407
  const raw = opts.file
408
408
  ? await fs.readFile(opts.file, 'utf-8')
409
409
  : opts.json;
@@ -411,13 +411,13 @@ function tasksCommand() {
411
411
  // R7 (N20): 显式 --executor 覆盖/补写 body.executorId(pinning)。
412
412
  if (opts.executor)
413
413
  body.executorId = opts.executor;
414
- const t = await (0, client_1.patch)(`/tasks/${id}`, body);
414
+ const t = await patch(`/tasks/${id}`, body);
415
415
  spinner.succeed(`Task updated: ${t.id}`);
416
- console.log(chalk_1.default.gray(` name: ${t.name} status: ${statusColor(t.status)}`));
416
+ console.log(chalk.gray(` name: ${t.name} status: ${statusColor(t.status)}`));
417
417
  }
418
418
  catch (e) {
419
419
  spinner.fail('Failed to update task');
420
- console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
420
+ console.error(chalk.red(formatApiError(e)));
421
421
  process.exit(1);
422
422
  }
423
423
  });
@@ -427,23 +427,23 @@ function tasksCommand() {
427
427
  .option('-y, --yes', 'Skip confirmation prompt', false)
428
428
  .action(async (id, opts) => {
429
429
  if (!opts.yes) {
430
- const readline = await Promise.resolve().then(() => __importStar(require('readline/promises')));
430
+ const readline = await import('readline/promises');
431
431
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
432
432
  const answer = await rl.question(`Delete task ${id}? Running executions will be force-terminated. [y/N] `);
433
433
  rl.close();
434
434
  if (!/^y(es)?$/i.test(answer)) {
435
- console.log(chalk_1.default.yellow('Aborted.'));
435
+ console.log(chalk.yellow('Aborted.'));
436
436
  return;
437
437
  }
438
438
  }
439
- const spinner = (0, ora_1.default)('Deleting task…').start();
439
+ const spinner = ora('Deleting task…').start();
440
440
  try {
441
- await (0, client_1.del)(`/tasks/${id}`);
441
+ await del(`/tasks/${id}`);
442
442
  spinner.succeed(`Task ${id} deleted`);
443
443
  }
444
444
  catch (e) {
445
445
  spinner.fail('Failed to delete task');
446
- console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
446
+ console.error(chalk.red(formatApiError(e)));
447
447
  process.exit(1);
448
448
  }
449
449
  });
@@ -451,15 +451,15 @@ function tasksCommand() {
451
451
  cmd.command('pause <id>')
452
452
  .description('Pause task scheduled execution')
453
453
  .action(async (id) => {
454
- const spinner = (0, ora_1.default)('Pausing task…').start();
454
+ const spinner = ora('Pausing task…').start();
455
455
  try {
456
- const t = await (0, client_1.post)(`/tasks/${id}/pause`);
456
+ const t = await post(`/tasks/${id}/pause`);
457
457
  spinner.succeed(`Task ${id} paused`);
458
- console.log(chalk_1.default.gray(` status: ${statusColor(t.status)}`));
458
+ console.log(chalk.gray(` status: ${statusColor(t.status)}`));
459
459
  }
460
460
  catch (e) {
461
461
  spinner.fail('Failed to pause task');
462
- console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
462
+ console.error(chalk.red(formatApiError(e)));
463
463
  process.exit(1);
464
464
  }
465
465
  });
@@ -467,15 +467,15 @@ function tasksCommand() {
467
467
  cmd.command('resume <id>')
468
468
  .description('Resume task scheduled execution')
469
469
  .action(async (id) => {
470
- const spinner = (0, ora_1.default)('Resuming task…').start();
470
+ const spinner = ora('Resuming task…').start();
471
471
  try {
472
- const t = await (0, client_1.post)(`/tasks/${id}/resume`);
472
+ const t = await post(`/tasks/${id}/resume`);
473
473
  spinner.succeed(`Task ${id} resumed`);
474
- console.log(chalk_1.default.gray(` status: ${statusColor(t.status)}`));
474
+ console.log(chalk.gray(` status: ${statusColor(t.status)}`));
475
475
  }
476
476
  catch (e) {
477
477
  spinner.fail('Failed to resume task');
478
- console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
478
+ console.error(chalk.red(formatApiError(e)));
479
479
  process.exit(1);
480
480
  }
481
481
  });
@@ -483,14 +483,14 @@ function tasksCommand() {
483
483
  cmd.command('kill <taskId> <execId>')
484
484
  .description('Force-cancel a running or pending execution')
485
485
  .action(async (taskId, execId) => {
486
- const spinner = (0, ora_1.default)('Cancelling execution…').start();
486
+ const spinner = ora('Cancelling execution…').start();
487
487
  try {
488
- const r = await (0, client_1.post)(`/tasks/${taskId}/executions/${execId}/kill`);
488
+ const r = await post(`/tasks/${taskId}/executions/${execId}/kill`);
489
489
  spinner.succeed(r.message || 'Execution cancelled');
490
490
  }
491
491
  catch (e) {
492
492
  spinner.fail('Failed to cancel execution');
493
- console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
493
+ console.error(chalk.red(formatApiError(e)));
494
494
  process.exit(1);
495
495
  }
496
496
  });
@@ -506,7 +506,7 @@ function tasksCommand() {
506
506
  source = fs.readFileSync(file, 'utf-8');
507
507
  }
508
508
  catch {
509
- console.error(chalk_1.default.red(`Cannot read file: ${file}`));
509
+ console.error(chalk.red(`Cannot read file: ${file}`));
510
510
  process.exit(1);
511
511
  }
512
512
  const ext = path.extname(file).toLowerCase();
@@ -519,11 +519,11 @@ function tasksCommand() {
519
519
  ? 'shell'
520
520
  : undefined);
521
521
  if (!lang) {
522
- console.error(chalk_1.default.red(`Cannot infer language from extension "${ext}" — pass --language node|python|shell`));
522
+ console.error(chalk.red(`Cannot infer language from extension "${ext}" — pass --language node|python|shell`));
523
523
  process.exit(1);
524
524
  }
525
525
  const ok = (msg) => {
526
- console.log(chalk_1.default.green(`✔ ${file}: ${msg}`));
526
+ console.log(chalk.green(`✔ ${file}: ${msg}`));
527
527
  process.exit(0);
528
528
  };
529
529
  if (lang === 'node') {
@@ -534,35 +534,35 @@ function tasksCommand() {
534
534
  new Function(source);
535
535
  }
536
536
  catch (err) {
537
- console.error(chalk_1.default.red(`✗ ${file}: syntax error`));
538
- console.error(chalk_1.default.red(err instanceof Error ? err.message : String(err)));
537
+ console.error(chalk.red(`✗ ${file}: syntax error`));
538
+ console.error(chalk.red(err instanceof Error ? err.message : String(err)));
539
539
  process.exit(1);
540
540
  }
541
541
  ok('syntax OK (node)');
542
542
  }
543
543
  else if (lang === 'python') {
544
544
  const py = ['python3', 'python'].find((bin) => {
545
- const r = (0, child_process_1.spawnSync)(bin, ['--version'], { stdio: 'ignore' });
545
+ const r = spawnSync(bin, ['--version'], { stdio: 'ignore' });
546
546
  return r.status === 0;
547
547
  });
548
548
  if (!py) {
549
- console.error(chalk_1.default.red('python not found on PATH — install Python 3 to lint python glue'));
549
+ console.error(chalk.red('python not found on PATH — install Python 3 to lint python glue'));
550
550
  process.exit(1);
551
551
  }
552
- const r = (0, child_process_1.spawnSync)(py, ['-c', `import ast,sys; ast.parse(open(sys.argv[1],encoding='utf-8').read())`, file], {
552
+ const r = spawnSync(py, ['-c', `import ast,sys; ast.parse(open(sys.argv[1],encoding='utf-8').read())`, file], {
553
553
  stdio: 'pipe',
554
554
  });
555
555
  if (r.status !== 0) {
556
- console.error(chalk_1.default.red(`✗ ${file}: syntax error`));
556
+ console.error(chalk.red(`✗ ${file}: syntax error`));
557
557
  process.stderr.write(r.stderr?.toString() ?? '');
558
558
  process.exit(1);
559
559
  }
560
560
  ok('syntax OK (python, ast.parse)');
561
561
  }
562
562
  else {
563
- const r = (0, child_process_1.spawnSync)('bash', ['-n', file], { stdio: 'pipe' });
563
+ const r = spawnSync('bash', ['-n', file], { stdio: 'pipe' });
564
564
  if (r.status !== 0) {
565
- console.error(chalk_1.default.red(`✗ ${file}: syntax error`));
565
+ console.error(chalk.red(`✗ ${file}: syntax error`));
566
566
  process.stderr.write(r.stderr?.toString() ?? '');
567
567
  process.exit(1);
568
568
  }
@@ -571,16 +571,15 @@ function tasksCommand() {
571
571
  });
572
572
  return cmd;
573
573
  }
574
- exports.tasksCommand = tasksCommand;
575
574
  async function pollExecution(execId, waitTimeoutSeconds = 600) {
576
575
  const INTERVAL = 2000;
577
576
  const MAX_WAIT = waitTimeoutSeconds * 1000;
578
- const spinner = (0, ora_1.default)('Waiting for execution…').start();
577
+ const spinner = ora('Waiting for execution…').start();
579
578
  const start = Date.now();
580
579
  while (Date.now() - start < MAX_WAIT) {
581
580
  await sleep(INTERVAL);
582
581
  try {
583
- const exec = await (0, client_1.get)(`/tasks/executions/${execId}`);
582
+ const exec = await get(`/tasks/executions/${execId}`);
584
583
  // killed 是后端 ExecutionStatus 的合法终态(acf task kill / Web 端),
585
584
  // 遗漏会让 --wait 在被 kill 后空转到 MAX_WAIT 并误报超时(N10)。
586
585
  if (['success', 'failed', 'timeout', 'cancelled', 'killed'].includes(exec.status)) {
@@ -603,16 +602,16 @@ async function pollExecution(execId, waitTimeoutSeconds = 600) {
603
602
  // so a non-zero exit or timeout reason was invisible without
604
603
  // digging through `acf task logs`.
605
604
  if (exec.exitCode !== null && exec.exitCode !== undefined) {
606
- console.log(chalk_1.default.yellow(' Exit code :'), exec.exitCode);
605
+ console.log(chalk.yellow(' Exit code :'), exec.exitCode);
607
606
  }
608
607
  if (exec.failureReason) {
609
- console.log(chalk_1.default.yellow(' Failure reason :'), exec.failureReason);
608
+ console.log(chalk.yellow(' Failure reason :'), exec.failureReason);
610
609
  }
611
610
  if (exec.errorMessage) {
612
- console.log(chalk_1.default.yellow(' Error :'), exec.errorMessage);
611
+ console.log(chalk.yellow(' Error :'), exec.errorMessage);
613
612
  }
614
613
  if (exec.aiAnalysis) {
615
- console.log(chalk_1.default.yellow('\nAI Analysis:'), exec.aiAnalysis);
614
+ console.log(chalk.yellow('\nAI Analysis:'), exec.aiAnalysis);
616
615
  }
617
616
  }
618
617
  return;
@@ -622,10 +621,10 @@ async function pollExecution(execId, waitTimeoutSeconds = 600) {
622
621
  catch (e) {
623
622
  // 4xx(除 429)是确定性失败(token 失效/执行不存在等)——继续轮询只会
624
623
  // 空转到 MAX_WAIT 并误报超时,掩盖真实错误;立即退出并透出后端消息。
625
- const status = axios_1.default.isAxiosError(e) ? e.response?.status : undefined;
624
+ const status = axios.isAxiosError(e) ? e.response?.status : undefined;
626
625
  if (status && status >= 400 && status < 500 && status !== 429) {
627
626
  spinner.fail('Waiting for execution failed');
628
- console.error(chalk_1.default.red((0, client_1.formatApiError)(e)));
627
+ console.error(chalk.red(formatApiError(e)));
629
628
  process.exit(1);
630
629
  }
631
630
  // transient (network / 429 / 5xx), keep polling
@@ -637,7 +636,7 @@ async function pollExecution(execId, waitTimeoutSeconds = 600) {
637
636
  // 与上方失败终态的 CLI-EXIT-01 语义对齐:置 exitCode=1,并明示执行仍在
638
637
  // 运行、如何继续观察(exec tail)或放宽等待上限(--wait-timeout)。
639
638
  spinner.fail(`Timed out waiting for execution after ${waitTimeoutSeconds}s`);
640
- console.error(chalk_1.default.red(`The execution is still running — no terminal status within ${waitTimeoutSeconds}s. ` +
639
+ console.error(chalk.red(`The execution is still running — no terminal status within ${waitTimeoutSeconds}s. ` +
641
640
  `Follow it later with 'acf exec tail ${execId}' or raise --wait-timeout.`));
642
641
  process.exitCode = 1;
643
642
  }