@autocodeflow/cli 1.5.0 → 1.5.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/dist/client.d.ts +10 -1
- package/dist/client.js +13 -3
- package/dist/commands/apps.js +3 -1
- package/dist/commands/exec.js +21 -1
- package/dist/commands/tasks.js +27 -6
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NETOPT-6④:analyze/suggest 类调用的 per-call 超时预算。
|
|
3
|
+
*
|
|
4
|
+
* admin 侧同步 AI 预算是 60s×2(两次 LLM 往返),实例默认 30s 结构性小于
|
|
5
|
+
* 服务端预算——AI 跑满预算成功返回时 CLI 早已放弃。task analyze /
|
|
6
|
+
* suggest-schedule / app analyze 用 120s 覆盖(axios per-request timeout
|
|
7
|
+
* 覆盖实例默认),其余端点维持 30s。
|
|
8
|
+
*/
|
|
9
|
+
export declare const ANALYZE_TIMEOUT_MS = 120000;
|
|
1
10
|
/** Reset client (needed after config changes in same process). */
|
|
2
11
|
export declare function resetClient(): void;
|
|
3
12
|
export declare function unwrap<T>(raw: unknown): T;
|
|
4
13
|
export declare function get<T>(path: string, params?: Record<string, string | number | undefined>): Promise<T>;
|
|
5
|
-
export declare function post<T>(path: string, body?: unknown): Promise<T>;
|
|
14
|
+
export declare function post<T>(path: string, body?: unknown, timeoutMs?: number): Promise<T>;
|
|
6
15
|
export declare function put<T>(path: string, body?: unknown): Promise<T>;
|
|
7
16
|
export declare function patch<T>(path: string, body?: unknown): Promise<T>;
|
|
8
17
|
export declare function del<T>(path: string): Promise<T>;
|
package/dist/client.js
CHANGED
|
@@ -3,13 +3,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.formatApiError = exports.del = exports.patch = exports.put = exports.post = exports.get = exports.unwrap = exports.resetClient = void 0;
|
|
6
|
+
exports.formatApiError = exports.del = exports.patch = exports.put = exports.post = exports.get = exports.unwrap = exports.resetClient = exports.ANALYZE_TIMEOUT_MS = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* Thin HTTP client wrapper for the AutoCodeFlow Admin API.
|
|
9
9
|
*/
|
|
10
10
|
const axios_1 = __importDefault(require("axios"));
|
|
11
11
|
const config_1 = require("./config");
|
|
12
12
|
let _client = null;
|
|
13
|
+
/**
|
|
14
|
+
* NETOPT-6④:analyze/suggest 类调用的 per-call 超时预算。
|
|
15
|
+
*
|
|
16
|
+
* admin 侧同步 AI 预算是 60s×2(两次 LLM 往返),实例默认 30s 结构性小于
|
|
17
|
+
* 服务端预算——AI 跑满预算成功返回时 CLI 早已放弃。task analyze /
|
|
18
|
+
* suggest-schedule / app analyze 用 120s 覆盖(axios per-request timeout
|
|
19
|
+
* 覆盖实例默认),其余端点维持 30s。
|
|
20
|
+
*/
|
|
21
|
+
exports.ANALYZE_TIMEOUT_MS = 120000;
|
|
13
22
|
/** base URL without trailing slashes(/auth/refresh 直连拼接用) */
|
|
14
23
|
function baseUrl() {
|
|
15
24
|
return (0, config_1.getApiUrl)().replace(/\/+$/, "");
|
|
@@ -127,8 +136,9 @@ async function get(path, params) {
|
|
|
127
136
|
return unwrap(r.data);
|
|
128
137
|
}
|
|
129
138
|
exports.get = get;
|
|
130
|
-
async function post(path, body) {
|
|
131
|
-
|
|
139
|
+
async function post(path, body, timeoutMs) {
|
|
140
|
+
// per-request timeout 覆盖实例默认(undefined 时 axios 回落实例默认 30s)。
|
|
141
|
+
const r = await getClient().post(path, body, { timeout: timeoutMs });
|
|
132
142
|
return unwrap(r.data);
|
|
133
143
|
}
|
|
134
144
|
exports.post = post;
|
package/dist/commands/apps.js
CHANGED
|
@@ -203,7 +203,9 @@ function appsCommand() {
|
|
|
203
203
|
.action(async (id) => {
|
|
204
204
|
const spinner = (0, ora_1.default)('Running AI health analysis…').start();
|
|
205
205
|
try {
|
|
206
|
-
|
|
206
|
+
// NETOPT-6④:同步 AI 端点(服务端预算 60s×2)用 120s per-call 覆盖,
|
|
207
|
+
// 否则默认 30s 结构性小于服务端预算,AI 跑满预算成功返回时 CLI 已超时。
|
|
208
|
+
const result = await (0, client_1.post)(`/applications/${id}/analyze`, undefined, client_1.ANALYZE_TIMEOUT_MS);
|
|
207
209
|
spinner.stop();
|
|
208
210
|
console.log(chalk_1.default.bold(`\nAI Health Analysis — ${result.appName}`));
|
|
209
211
|
console.log(chalk_1.default.gray('─'.repeat(60)));
|
package/dist/commands/exec.js
CHANGED
|
@@ -120,8 +120,15 @@ function execCommand() {
|
|
|
120
120
|
const url = `${base}/tasks/${exec.taskId}/executions/${execId}/logs/stream?ticket=${encodeURIComponent(ticket)}`;
|
|
121
121
|
const res = await axios_1.default.get(url, { responseType: 'stream', timeout: 0 });
|
|
122
122
|
process.stderr.write(chalk_1.default.gray(`[tail] following execution ${execId} (status: ${exec.status ?? 'unknown'}) — Ctrl+C to detach\n`));
|
|
123
|
+
// NETOPT-2②:done 帧是「日志流完整收尾」的唯一判据。此前 stream
|
|
124
|
+
// 'end' 一律 process.exit(0)——服务端/网络在 done 帧之前断流(反代
|
|
125
|
+
// 超时、进程重启)时,tail 静默以 0 退出,CI 里 `acf exec tail … &&
|
|
126
|
+
// …` 把断流当成功。sawDone 记录是否见过 done 帧:见过才 exit(0),
|
|
127
|
+
// 否则明示日志流中断并以非零码退出。
|
|
128
|
+
let sawDone = false;
|
|
123
129
|
const parser = createSseParser((msg) => {
|
|
124
130
|
if (msg.event === 'done') {
|
|
131
|
+
sawDone = true;
|
|
125
132
|
process.stderr.write(chalk_1.default.gray('[tail] done\n'));
|
|
126
133
|
process.exit(0);
|
|
127
134
|
}
|
|
@@ -140,7 +147,20 @@ function execCommand() {
|
|
|
140
147
|
stream.on('data', (chunk) => {
|
|
141
148
|
parser.feed(chunk.toString('utf-8'));
|
|
142
149
|
});
|
|
143
|
-
stream.on('end', () =>
|
|
150
|
+
stream.on('end', () => {
|
|
151
|
+
if (sawDone) {
|
|
152
|
+
process.exit(0);
|
|
153
|
+
// 防穿透:测试里 process.exit 常被钉成桩(正常返回),结构上
|
|
154
|
+
// 也不能让「完整收尾」落进下面的失败路径。
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
// 断流且没有 done 帧:执行可能仍在运行。用 exitCode 赋值而非
|
|
158
|
+
// process.exit(1),让事件循环自然收尾(流已 end,无挂起句柄)。
|
|
159
|
+
process.stderr.write(chalk_1.default.red('[tail] log stream interrupted before a done frame — the execution may still be running. Retry with `acf exec tail ' +
|
|
160
|
+
execId +
|
|
161
|
+
'`.\n'));
|
|
162
|
+
process.exitCode = 1;
|
|
163
|
+
});
|
|
144
164
|
stream.on('error', (err) => {
|
|
145
165
|
process.stderr.write(chalk_1.default.red(`[tail] stream error: ${err.message}\n`));
|
|
146
166
|
process.exit(1);
|
package/dist/commands/tasks.js
CHANGED
|
@@ -117,6 +117,16 @@ function tasksCommand() {
|
|
|
117
117
|
cmd.command('trigger <id>')
|
|
118
118
|
.description('Manually trigger a task and wait for completion')
|
|
119
119
|
.option('--wait', 'Poll until execution finishes', false)
|
|
120
|
+
// NETOPT-2①: --wait 的轮询上限可调(秒)。默认 600 保持既有行为;
|
|
121
|
+
// 非正值直接报参数错误而不是静默回落默认值——CI 里写错单位(毫秒当秒)
|
|
122
|
+
// 若被静默吞掉,长任务又会掉回「假超时假绿」的老坑。
|
|
123
|
+
.option('--wait-timeout <seconds>', 'Max seconds to keep polling with --wait before giving up (default 600)', (v) => {
|
|
124
|
+
const n = Number.parseInt(v, 10);
|
|
125
|
+
if (!Number.isFinite(n) || n <= 0) {
|
|
126
|
+
throw new commander_1.InvalidArgumentError('must be a positive integer (seconds)');
|
|
127
|
+
}
|
|
128
|
+
return n;
|
|
129
|
+
}, 600)
|
|
120
130
|
// NOTE: no --executor option here — TriggerTaskDto only accepts `params`
|
|
121
131
|
// and the backend ValidationPipe runs with forbidNonWhitelisted, so a
|
|
122
132
|
// per-trigger pin would be rejected with 400. Executor pinning IS
|
|
@@ -128,7 +138,7 @@ function tasksCommand() {
|
|
|
128
138
|
const exec = await (0, client_1.post)(`/tasks/${id}/trigger`);
|
|
129
139
|
spinner.succeed(`Execution started: ${exec.id}`);
|
|
130
140
|
if (opts.wait) {
|
|
131
|
-
await pollExecution(exec.id);
|
|
141
|
+
await pollExecution(exec.id, opts.waitTimeout);
|
|
132
142
|
}
|
|
133
143
|
}
|
|
134
144
|
catch (e) {
|
|
@@ -223,7 +233,9 @@ function tasksCommand() {
|
|
|
223
233
|
.action(async (taskId, execId) => {
|
|
224
234
|
const spinner = (0, ora_1.default)('Running AI analysis…').start();
|
|
225
235
|
try {
|
|
226
|
-
|
|
236
|
+
// NETOPT-6④:同步 AI 端点(服务端预算 60s×2)用 120s per-call 覆盖,
|
|
237
|
+
// 否则默认 30s 结构性小于服务端预算,AI 跑满预算成功返回时 CLI 已超时。
|
|
238
|
+
const result = await (0, client_1.post)(`/tasks/${taskId}/executions/${execId}/analyze`, undefined, client_1.ANALYZE_TIMEOUT_MS);
|
|
227
239
|
spinner.stop();
|
|
228
240
|
console.log(chalk_1.default.bold('\nAI Analysis'));
|
|
229
241
|
console.log(result.aiAnalysis || 'No analysis available (AI not configured).');
|
|
@@ -240,7 +252,8 @@ function tasksCommand() {
|
|
|
240
252
|
.action(async (id) => {
|
|
241
253
|
const spinner = (0, ora_1.default)('Asking AI for schedule suggestion…').start();
|
|
242
254
|
try {
|
|
243
|
-
|
|
255
|
+
// NETOPT-6④:同上——suggest-schedule 也是同步 AI 端点。
|
|
256
|
+
const result = await (0, client_1.post)(`/tasks/${id}/suggest-schedule`, undefined, client_1.ANALYZE_TIMEOUT_MS);
|
|
244
257
|
spinner.stop();
|
|
245
258
|
console.log(chalk_1.default.bold('Schedule Suggestion'));
|
|
246
259
|
console.log(' Current :', result.currentCron ?? '(none)');
|
|
@@ -559,9 +572,9 @@ function tasksCommand() {
|
|
|
559
572
|
return cmd;
|
|
560
573
|
}
|
|
561
574
|
exports.tasksCommand = tasksCommand;
|
|
562
|
-
async function pollExecution(execId) {
|
|
575
|
+
async function pollExecution(execId, waitTimeoutSeconds = 600) {
|
|
563
576
|
const INTERVAL = 2000;
|
|
564
|
-
const MAX_WAIT =
|
|
577
|
+
const MAX_WAIT = waitTimeoutSeconds * 1000;
|
|
565
578
|
const spinner = (0, ora_1.default)('Waiting for execution…').start();
|
|
566
579
|
const start = Date.now();
|
|
567
580
|
while (Date.now() - start < MAX_WAIT) {
|
|
@@ -618,7 +631,15 @@ async function pollExecution(execId) {
|
|
|
618
631
|
// transient (network / 429 / 5xx), keep polling
|
|
619
632
|
}
|
|
620
633
|
}
|
|
621
|
-
|
|
634
|
+
// NETOPT-2①:--wait 的承诺是「等完并给出结果」,但轮询窗口耗尽时此前只
|
|
635
|
+
// spinner.fail 就返回,退出码依旧是 0——执行明明还在跑,CI 里
|
|
636
|
+
// `acf task trigger <id> --wait && …` 对任何超过等待上限的真实长任务假绿。
|
|
637
|
+
// 与上方失败终态的 CLI-EXIT-01 语义对齐:置 exitCode=1,并明示执行仍在
|
|
638
|
+
// 运行、如何继续观察(exec tail)或放宽等待上限(--wait-timeout)。
|
|
639
|
+
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. ` +
|
|
641
|
+
`Follow it later with 'acf exec tail ${execId}' or raise --wait-timeout.`));
|
|
642
|
+
process.exitCode = 1;
|
|
622
643
|
}
|
|
623
644
|
function sleep(ms) {
|
|
624
645
|
return new Promise((r) => setTimeout(r, ms));
|