@autocodeflow/cli 1.5.3 → 1.7.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/commands/agent.d.ts +2 -0
- package/dist/commands/agent.js +59 -0
- package/dist/commands/audit.js +8 -0
- package/dist/commands/sop.d.ts +2 -0
- package/dist/commands/sop.js +79 -0
- package/dist/commands/tasks.js +31 -2
- package/dist/index.js +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import Table from 'cli-table3';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import ora from 'ora';
|
|
5
|
+
import { get, formatApiError } from '../client.js';
|
|
6
|
+
export function agentCommand() {
|
|
7
|
+
const cmd = new Command('agent').description('Inspect agent sessions');
|
|
8
|
+
// acf agent sessions
|
|
9
|
+
cmd.command('sessions')
|
|
10
|
+
.description('List agent sessions (newest first; waiting_input = paused on a human decision)')
|
|
11
|
+
.option('--kind <kind>', 'Filter by kind (ops_watch | incident | sop_authoring)')
|
|
12
|
+
.option('--status <status>', 'Filter by status (pending | running | waiting_input | succeeded | failed | aborted)')
|
|
13
|
+
.option('-p, --page <n>', 'Page number', '1')
|
|
14
|
+
.option('-n, --page-size <n>', 'Page size (max 100)', '20')
|
|
15
|
+
.action(async (opts) => {
|
|
16
|
+
const spinner = ora('Fetching agent sessions…').start();
|
|
17
|
+
try {
|
|
18
|
+
const data = await get('/agent/sessions', {
|
|
19
|
+
page: opts.page,
|
|
20
|
+
pageSize: opts.pageSize,
|
|
21
|
+
kind: opts.kind,
|
|
22
|
+
status: opts.status,
|
|
23
|
+
});
|
|
24
|
+
spinner.stop();
|
|
25
|
+
const items = data.items ?? data.data ?? [];
|
|
26
|
+
const table = new Table({
|
|
27
|
+
head: ['Time', 'Kind', 'Status', 'Title', 'ID'],
|
|
28
|
+
colWidths: [22, 14, 14, 36, 20],
|
|
29
|
+
style: { head: ['cyan'] },
|
|
30
|
+
});
|
|
31
|
+
for (const s of items) {
|
|
32
|
+
table.push([
|
|
33
|
+
s.createdAt ? new Date(s.createdAt).toLocaleString() : '-',
|
|
34
|
+
s.kind,
|
|
35
|
+
statusColor(s.status),
|
|
36
|
+
s.title ?? '-',
|
|
37
|
+
s.id,
|
|
38
|
+
]);
|
|
39
|
+
}
|
|
40
|
+
console.log(table.toString());
|
|
41
|
+
console.log(chalk.gray(`Total: ${data.total ?? items.length} page ${opts.page}`));
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
spinner.fail('Failed to list agent sessions');
|
|
45
|
+
console.error(chalk.red(formatApiError(e)));
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return cmd;
|
|
50
|
+
}
|
|
51
|
+
function statusColor(s) {
|
|
52
|
+
if (s === 'succeeded')
|
|
53
|
+
return chalk.green(s);
|
|
54
|
+
if (s === 'failed' || s === 'aborted')
|
|
55
|
+
return chalk.red(s);
|
|
56
|
+
if (s === 'waiting_input')
|
|
57
|
+
return chalk.yellow(s);
|
|
58
|
+
return s;
|
|
59
|
+
}
|
package/dist/commands/audit.js
CHANGED
|
@@ -23,6 +23,8 @@ export function auditCommand() {
|
|
|
23
23
|
.option('--end-time <iso>', 'Only entries created at/before this time (ISO 8601)')
|
|
24
24
|
.option('-p, --page <n>', 'Page number', '1')
|
|
25
25
|
.option('-n, --page-size <n>', 'Page size (max 100)', '20')
|
|
26
|
+
// 第四轮审计(--json 补面):对齐 task list 的 ECO-02 CI 消费面
|
|
27
|
+
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
26
28
|
.action(async (opts) => {
|
|
27
29
|
const spinner = ora('Fetching audit logs…').start();
|
|
28
30
|
try {
|
|
@@ -40,6 +42,12 @@ export function auditCommand() {
|
|
|
40
42
|
endTime: opts.endTime,
|
|
41
43
|
});
|
|
42
44
|
spinner.stop();
|
|
45
|
+
if (opts.json) {
|
|
46
|
+
// ECO-02 同款:--json —— 后端返回的信封({ data, total },旧后端可
|
|
47
|
+
// 能是裸数组)原样直出,不做任何字段裁剪。
|
|
48
|
+
console.log(JSON.stringify(data, null, 2));
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
43
51
|
const rows = Array.isArray(data) ? data : (data.data ?? []);
|
|
44
52
|
const total = Array.isArray(data) ? rows.length : (data.total ?? rows.length);
|
|
45
53
|
const table = new Table({
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import Table from 'cli-table3';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import ora from 'ora';
|
|
5
|
+
import { get, formatApiError } from '../client.js';
|
|
6
|
+
export function sopCommand() {
|
|
7
|
+
const cmd = new Command('sop').description('Inspect SOP definitions');
|
|
8
|
+
// acf sop list
|
|
9
|
+
cmd.command('list')
|
|
10
|
+
.description('List SOP definitions (newest update first)')
|
|
11
|
+
.option('--status <status>', 'Filter by SOP status (draft | published | deprecated)')
|
|
12
|
+
.option('-p, --page <n>', 'Page number', '1')
|
|
13
|
+
.option('-n, --page-size <n>', 'Page size (max 100)', '20')
|
|
14
|
+
.action(async (opts) => {
|
|
15
|
+
const spinner = ora('Fetching SOPs…').start();
|
|
16
|
+
try {
|
|
17
|
+
const data = await get('/sop', {
|
|
18
|
+
page: opts.page,
|
|
19
|
+
pageSize: opts.pageSize,
|
|
20
|
+
status: opts.status,
|
|
21
|
+
});
|
|
22
|
+
spinner.stop();
|
|
23
|
+
const items = data.items ?? [];
|
|
24
|
+
const table = new Table({
|
|
25
|
+
head: ['Title', 'Slug', 'Status', 'Version', 'Updated'],
|
|
26
|
+
colWidths: [32, 24, 12, 12, 24],
|
|
27
|
+
style: { head: ['cyan'] },
|
|
28
|
+
});
|
|
29
|
+
for (const s of items) {
|
|
30
|
+
table.push([
|
|
31
|
+
s.title,
|
|
32
|
+
s.slug,
|
|
33
|
+
statusColor(s.status),
|
|
34
|
+
s.currentVersion ?? '-',
|
|
35
|
+
s.updatedAt ? new Date(s.updatedAt).toLocaleString() : '-',
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
console.log(table.toString());
|
|
39
|
+
console.log(chalk.gray(`Total: ${data.total ?? items.length} page ${opts.page}`));
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
spinner.fail('Failed to list SOPs');
|
|
43
|
+
console.error(chalk.red(formatApiError(e)));
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
// acf sop show <id>
|
|
48
|
+
cmd.command('show <sopId>')
|
|
49
|
+
.description('Show one SOP: status, current version and markdown body')
|
|
50
|
+
.action(async (sopId) => {
|
|
51
|
+
const spinner = ora('Fetching SOP…').start();
|
|
52
|
+
try {
|
|
53
|
+
const s = await get(`/sop/${sopId}`);
|
|
54
|
+
spinner.stop();
|
|
55
|
+
console.log(chalk.bold(s.title));
|
|
56
|
+
console.log(chalk.gray(`slug: ${s.slug} status: ${s.status} version: ${s.currentVersion ?? '-'} updated: ${s.updatedAt ?? '-'}`));
|
|
57
|
+
if (s.bodyMarkdown) {
|
|
58
|
+
console.log('');
|
|
59
|
+
console.log(s.bodyMarkdown);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
console.log(chalk.gray('(no body — the SOP has no published version yet)'));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
spinner.fail('Failed to show SOP');
|
|
67
|
+
console.error(chalk.red(formatApiError(e)));
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
return cmd;
|
|
72
|
+
}
|
|
73
|
+
function statusColor(s) {
|
|
74
|
+
if (s === 'published')
|
|
75
|
+
return chalk.green(s);
|
|
76
|
+
if (s === 'deprecated')
|
|
77
|
+
return chalk.red(s);
|
|
78
|
+
return s;
|
|
79
|
+
}
|
package/dist/commands/tasks.js
CHANGED
|
@@ -66,11 +66,18 @@ export function tasksCommand() {
|
|
|
66
66
|
// acf task get <id>
|
|
67
67
|
cmd.command('get <id>')
|
|
68
68
|
.description('Show task details')
|
|
69
|
-
|
|
69
|
+
// 第四轮审计(--json 补面):对齐 task list 的 ECO-02 CI 消费面
|
|
70
|
+
.option('--json', 'Emit raw JSON (CI-consumable, no table)')
|
|
71
|
+
.action(async (id, opts) => {
|
|
70
72
|
const spinner = ora('Fetching task…').start();
|
|
71
73
|
try {
|
|
72
74
|
const t = await get(`/tasks/${id}`);
|
|
73
75
|
spinner.stop();
|
|
76
|
+
if (opts.json) {
|
|
77
|
+
// ECO-02: --json —— CI/脚本消费面(pretty print 便于人工核查)
|
|
78
|
+
console.log(JSON.stringify(t, null, 2));
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
74
81
|
console.log(chalk.bold('Task Details'));
|
|
75
82
|
console.log(' ID :', t.id);
|
|
76
83
|
console.log(' Name :', t.name);
|
|
@@ -103,11 +110,22 @@ export function tasksCommand() {
|
|
|
103
110
|
// per-trigger pin would be rejected with 400. Executor pinning IS
|
|
104
111
|
// supported by the backend as a task-level field (tasks.executorId) — set
|
|
105
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)')
|
|
106
116
|
.action(async (id, opts) => {
|
|
107
117
|
const spinner = ora('Triggering task…').start();
|
|
108
118
|
try {
|
|
109
119
|
const exec = await post(`/tasks/${id}/trigger`);
|
|
110
|
-
|
|
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
|
+
}
|
|
111
129
|
if (opts.wait) {
|
|
112
130
|
await pollExecution(exec.id, opts.waitTimeout);
|
|
113
131
|
}
|
|
@@ -162,6 +180,8 @@ export function tasksCommand() {
|
|
|
162
180
|
.option('-f, --from-line <n>', 'Start line (0-based)', '0')
|
|
163
181
|
.option('-n, --limit <n>', 'Max lines to fetch (max 2000)', '200')
|
|
164
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)')
|
|
165
185
|
.action(async (execId, opts) => {
|
|
166
186
|
const spinner = ora('Fetching logs…').start();
|
|
167
187
|
try {
|
|
@@ -174,6 +194,11 @@ export function tasksCommand() {
|
|
|
174
194
|
const from = Math.max(0, head.totalLines - tail);
|
|
175
195
|
const data = await get(`/tasks/executions/${execId}/logs`, { fromLine: from, limit: tail });
|
|
176
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
|
+
}
|
|
177
202
|
for (const l of data.lines ?? [])
|
|
178
203
|
console.log(l);
|
|
179
204
|
console.log(chalk.gray(`\n(${data.lines?.length ?? 0}/${data.totalLines} lines — last ${tail})`));
|
|
@@ -182,6 +207,10 @@ export function tasksCommand() {
|
|
|
182
207
|
const fromLine = parseInt(opts.fromLine, 10) || 0;
|
|
183
208
|
const data = await get(`/tasks/executions/${execId}/logs`, { fromLine, limit: opts.limit });
|
|
184
209
|
spinner.stop();
|
|
210
|
+
if (opts.json) {
|
|
211
|
+
console.log(JSON.stringify(data, null, 2));
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
185
214
|
for (const l of data.lines ?? [])
|
|
186
215
|
console.log(l);
|
|
187
216
|
if (data.hasMore) {
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
* acf exec tail <execId>
|
|
17
17
|
* acf task lint <file>
|
|
18
18
|
* acf audit list
|
|
19
|
+
* acf sop list | show <sopId>
|
|
20
|
+
* acf agent sessions
|
|
19
21
|
* acf config show
|
|
20
22
|
*/
|
|
21
23
|
import { Command } from 'commander';
|
|
@@ -28,6 +30,8 @@ import { deployCommand } from './commands/deploy.js';
|
|
|
28
30
|
import { auditCommand } from './commands/audit.js';
|
|
29
31
|
import { execCommand } from './commands/exec.js';
|
|
30
32
|
import { projectsCommand } from './commands/projects.js';
|
|
33
|
+
import { sopCommand } from './commands/sop.js';
|
|
34
|
+
import { agentCommand } from './commands/agent.js';
|
|
31
35
|
import { showConfig, setApiUrl, setToken } from './config.js';
|
|
32
36
|
// 版本号单一事实源:直接读 package.json,而不是硬编码字面量。
|
|
33
37
|
//
|
|
@@ -65,6 +69,8 @@ program.addCommand(deployCommand());
|
|
|
65
69
|
program.addCommand(auditCommand());
|
|
66
70
|
program.addCommand(execCommand());
|
|
67
71
|
program.addCommand(projectsCommand());
|
|
72
|
+
program.addCommand(sopCommand());
|
|
73
|
+
program.addCommand(agentCommand());
|
|
68
74
|
// acf config show / set
|
|
69
75
|
const configCmd = new Command('config').description('View or update CLI configuration');
|
|
70
76
|
configCmd.command('show').description('Show current config').action(() => showConfig());
|