toc-ocra 0.2.28 → 0.2.29
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/cli/cli.mjs +283 -103
- package/dist/service/agent.mjs +283 -103
- package/dist/src/providers/cli/claude.js +95 -18
- package/dist/src/providers/cli/claude.js.map +1 -1
- package/dist/src/providers/cli/kiro.d.ts +8 -1
- package/dist/src/providers/cli/kiro.js +156 -100
- package/dist/src/providers/cli/kiro.js.map +1 -1
- package/dist/src/providers/provider.d.ts +57 -2
- package/dist/src/providers/provider.js +59 -0
- package/dist/src/providers/provider.js.map +1 -1
- package/dist/src/runs/run-supervisor.js +55 -8
- package/dist/src/runs/run-supervisor.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
-
import {
|
|
4
|
+
import { providerEnvironment, resolveExecutable, runLog, str, toolCallRows, tryJson } from '../provider.js';
|
|
5
5
|
// `claude -p --output-format stream-json --verbose`: the init/system event
|
|
6
6
|
// carries session_id, assistant events carry text/tool use, and the final
|
|
7
7
|
// `result` event carries the answer.
|
|
@@ -36,34 +36,111 @@ export const claudeProvider = {
|
|
|
36
36
|
return resolveExecutable('claude', args, env, process.env.TOC_OCRA_CLAUDE_PATH);
|
|
37
37
|
},
|
|
38
38
|
parseLine(line) {
|
|
39
|
+
return claudeLineParser()(line);
|
|
40
|
+
},
|
|
41
|
+
createLineParser: () => claudeLineParser()
|
|
42
|
+
};
|
|
43
|
+
const record = (value) => value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
44
|
+
function toolResultText(content) {
|
|
45
|
+
if (typeof content === 'string')
|
|
46
|
+
return content;
|
|
47
|
+
if (Array.isArray(content))
|
|
48
|
+
return content.map((part) => str(record(part).text) ?? '').filter(Boolean).join('\n');
|
|
49
|
+
return '';
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* One turn of `stream-json`, rendered into the shared run-log rows the same
|
|
53
|
+
* way Codex runs are: shell calls as commands with their output and exit,
|
|
54
|
+
* edits as file changes, thinking folded, replies as replies. Tool results
|
|
55
|
+
* arrive in later `user` events, so the parser remembers each call.
|
|
56
|
+
*/
|
|
57
|
+
function claudeLineParser() {
|
|
58
|
+
const shells = new Map();
|
|
59
|
+
/** The shell call whose rows were printed last; its output can follow directly. */
|
|
60
|
+
let lastShell = '';
|
|
61
|
+
let started = false;
|
|
62
|
+
return (line) => {
|
|
39
63
|
const event = tryJson(line);
|
|
40
64
|
if (!event)
|
|
41
65
|
return { display: line.trim() ? [line] : [] };
|
|
66
|
+
// Sub-agents spawned by the CLI have their own transcript; show the main one.
|
|
67
|
+
if (event.parent_tool_use_id)
|
|
68
|
+
return { display: [] };
|
|
42
69
|
const sessionId = str(event.session_id);
|
|
43
70
|
const base = sessionId ? { sessionId } : {};
|
|
44
71
|
switch (str(event.type)) {
|
|
45
|
-
case '
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return { ...base,
|
|
72
|
+
case 'system': {
|
|
73
|
+
if (started || str(event.subtype) !== 'init')
|
|
74
|
+
return { ...base, display: [] };
|
|
75
|
+
started = true;
|
|
76
|
+
return { ...base, display: [`● 会话 ${sessionId ?? ''}`, runLog.event('开始处理')] };
|
|
50
77
|
}
|
|
51
78
|
case 'assistant': {
|
|
52
|
-
const content = (event.message
|
|
53
|
-
const rows =
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (part.type === '
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
79
|
+
const content = (record(event.message).content ?? []);
|
|
80
|
+
const rows = [];
|
|
81
|
+
for (const value of Array.isArray(content) ? content : []) {
|
|
82
|
+
const part = record(value);
|
|
83
|
+
if (part.type === 'text') {
|
|
84
|
+
if (str(part.text))
|
|
85
|
+
rows.push(...runLog.reply(String(part.text)));
|
|
86
|
+
lastShell = '';
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (part.type === 'thinking') {
|
|
90
|
+
if (str(part.thinking))
|
|
91
|
+
rows.push(...runLog.thinking(String(part.thinking)));
|
|
92
|
+
lastShell = '';
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (part.type !== 'tool_use')
|
|
96
|
+
continue;
|
|
97
|
+
const name = str(part.name) ?? 'tool';
|
|
98
|
+
const input = record(part.input);
|
|
99
|
+
const id = str(part.id) ?? '';
|
|
100
|
+
if (name === 'Bash') {
|
|
101
|
+
const command = str(input.command) ?? '';
|
|
102
|
+
shells.set(id, command);
|
|
103
|
+
rows.push(runLog.command(command));
|
|
104
|
+
lastShell = id;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
rows.push(...toolCallRows(name, str(input.file_path) ?? str(input.notebook_path)));
|
|
108
|
+
lastShell = '';
|
|
109
|
+
}
|
|
110
|
+
return { ...base, display: rows };
|
|
111
|
+
}
|
|
112
|
+
case 'user': {
|
|
113
|
+
const content = (record(event.message).content ?? []);
|
|
114
|
+
const rows = [];
|
|
115
|
+
for (const value of Array.isArray(content) ? content : []) {
|
|
116
|
+
const part = record(value);
|
|
117
|
+
if (part.type !== 'tool_result')
|
|
118
|
+
continue;
|
|
119
|
+
const id = str(part.tool_use_id) ?? '';
|
|
120
|
+
const command = shells.get(id);
|
|
121
|
+
if (command === undefined) {
|
|
122
|
+
if (part.is_error === true)
|
|
123
|
+
rows.push(runLog.error(toolResultText(part.content) || '工具调用失败'));
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
shells.delete(id);
|
|
127
|
+
// Parallel calls can interleave: restate the command its output belongs to.
|
|
128
|
+
if (lastShell !== id)
|
|
129
|
+
rows.push(runLog.command(command));
|
|
130
|
+
rows.push(...runLog.commandOutput(toolResultText(part.content)), runLog.commandExit(part.is_error === true ? 1 : 0));
|
|
131
|
+
lastShell = '';
|
|
132
|
+
}
|
|
60
133
|
return { ...base, display: rows };
|
|
61
134
|
}
|
|
62
|
-
case '
|
|
63
|
-
|
|
135
|
+
case 'result': {
|
|
136
|
+
const text = str(event.result) ?? '';
|
|
137
|
+
if (event.is_error === true)
|
|
138
|
+
return { ...base, turnError: text || 'claude failed', display: [runLog.error(text || 'Claude 本轮执行失败')] };
|
|
139
|
+
return { ...base, message: text, turnCompleted: true, display: [runLog.event('本轮完成')] };
|
|
140
|
+
}
|
|
64
141
|
default:
|
|
65
142
|
return { ...base, display: [] };
|
|
66
143
|
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
144
|
+
};
|
|
145
|
+
}
|
|
69
146
|
//# sourceMappingURL=claude.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude.js","sourceRoot":"","sources":["../../../../src/providers/cli/claude.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"claude.js","sourceRoot":"","sources":["../../../../src/providers/cli/claude.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAE3G,2EAA2E;AAC3E,0EAA0E;AAC1E,qCAAqC;AACrC,MAAM,CAAC,MAAM,cAAc,GAAqB;IAC9C,EAAE,EAAE,QAAQ;IACZ,WAAW,CAAC,OAAO;QACjB,MAAM,IAAI,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,EA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AM,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;oBACpH,SAAS,GAAG,EAAE,CAAA;gBAChB,CAAC;gBACD,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;YACnC,CAAC;YACD,KAAK,QAAQ,CAAC,CAAC,CAAC;gBACd,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;gBACpC,IAAI,KAAK,CAAC,QAAQ,KAAK,IAAI;oBAAE,OAAO,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,IAAI,IAAI,eAAe,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,IAAI,eAAe,CAAC,CAAC,EAAE,CAAA;gBACrI,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAA;YACzF,CAAC;YACD;gBACE,OAAO,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAA;QACnC,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import type { HeadlessProvider } from '../provider.js';
|
|
1
|
+
import type { HeadlessProvider, SavedSession } from '../provider.js';
|
|
2
|
+
/**
|
|
3
|
+
* Saved chats for the directory, limited to ones headless
|
|
4
|
+
* `chat --no-interactive` can resume. `v3` entries are Kiro IDE / ACP sessions
|
|
5
|
+
* (`sess_…`) sharing the folder: resuming one switches to the v3 engine, which
|
|
6
|
+
* rejects the trust flags, and would also write into someone's IDE chat.
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseKiroSessions(stdout: string): SavedSession[];
|
|
2
9
|
export declare const kiroProvider: HeadlessProvider;
|
|
3
10
|
/**
|
|
4
11
|
* True business-error text to surface when Kiro exits 0 but did nothing
|
|
@@ -1,80 +1,159 @@
|
|
|
1
|
-
import { execFile
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
2
|
import { promisify } from 'node:util';
|
|
3
|
-
import { providerEnvironment, resolveExecutable, str,
|
|
3
|
+
import { providerEnvironment, resolveExecutable, runLog, str, toolCallRows, tryJson } from '../provider.js';
|
|
4
4
|
const execFileAsync = promisify(execFile);
|
|
5
5
|
/**
|
|
6
6
|
* Kiro CLI, run headless via `kiro-cli chat --no-interactive`.
|
|
7
7
|
*
|
|
8
8
|
* Unlike Claude/Codex, Kiro's non-interactive mode does NOT emit a
|
|
9
|
-
* machine-readable event stream: stdout carries human-readable text
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* machine-readable event stream: stdout carries colored human-readable text
|
|
10
|
+
* (replies on `> ` lines, tool calls announced with `(using tool: …)` or
|
|
11
|
+
* `Running tool …`, ` - Completed in …` after each), and the `▸ Credits`
|
|
12
|
+
* footer goes to stderr.
|
|
13
|
+
*
|
|
14
|
+
* The native session id is never printed and cannot be chosen up front, and
|
|
15
|
+
* Kiro keeps chats per working directory only. `listSessions` lets the
|
|
16
|
+
* supervisor find the one chat a fresh turn created (snapshot diff), instead
|
|
17
|
+
* of taking the folder's newest chat — which belongs to whichever workstation
|
|
18
|
+
* in that folder ran last.
|
|
13
19
|
*
|
|
14
20
|
* Business errors (quota exhausted, auth) are written to stderr while the
|
|
15
21
|
* process still exits 0, so the supervisor must inspect stderr rather than
|
|
16
22
|
* trust the exit code alone — see `kiroStderrError`.
|
|
17
23
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (!text)
|
|
21
|
-
return true;
|
|
22
|
-
if (text.startsWith('⋮') || text.startsWith('▸') || text.startsWith('●'))
|
|
23
|
-
return true;
|
|
24
|
-
if (/^Running tool\b/.test(text))
|
|
25
|
-
return true;
|
|
26
|
-
if (/^- Completed in\b/.test(text))
|
|
27
|
-
return true;
|
|
28
|
-
if (/^All tools are now trusted\b/.test(text))
|
|
29
|
-
return true;
|
|
30
|
-
if (/^Agents can sometimes do unexpected things\b/.test(text))
|
|
31
|
-
return true;
|
|
32
|
-
if (/^Learn more at\b/.test(text))
|
|
33
|
-
return true;
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
24
|
+
// eslint-disable-next-line no-control-regex
|
|
25
|
+
const ANSI = /\u001b(?:\][^\u0007]*?(?:\u0007|\u001b\\)|\[[0-?]*[ -/]*[@-~]|[@-Z\\-_])/g;
|
|
36
26
|
/** Resolve the Kiro CLI launch for arbitrary arguments (chat turns, queries). */
|
|
37
27
|
function kiroLaunch(args) {
|
|
38
28
|
return resolveExecutable('kiro-cli', args, providerEnvironment(), process.env.TOC_OCRA_KIRO_PATH);
|
|
39
29
|
}
|
|
40
30
|
const LIST_SESSIONS = ['chat', '--list-sessions', '--format', 'json'];
|
|
41
31
|
/**
|
|
42
|
-
* Saved chats for the directory,
|
|
32
|
+
* Saved chats for the directory, limited to ones headless
|
|
43
33
|
* `chat --no-interactive` can resume. `v3` entries are Kiro IDE / ACP sessions
|
|
44
34
|
* (`sess_…`) sharing the folder: resuming one switches to the v3 engine, which
|
|
45
35
|
* rejects the trust flags, and would also write into someone's IDE chat.
|
|
46
36
|
*/
|
|
47
|
-
function
|
|
37
|
+
export function parseKiroSessions(stdout) {
|
|
48
38
|
const parsed = JSON.parse(stdout);
|
|
49
39
|
return parsed.flatMap((entry) => entry.sessions ?? [])
|
|
50
|
-
.filter((entry) => entry.source !== 'v3' && !entry.sessionId
|
|
51
|
-
.
|
|
40
|
+
.filter((entry) => entry.source !== 'v3' && entry.sessionId && !entry.sessionId.startsWith('sess_'))
|
|
41
|
+
.map((entry) => ({ id: entry.sessionId, ...(entry.title ? { title: entry.title } : {}) }));
|
|
52
42
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
return undefined;
|
|
61
|
-
}
|
|
43
|
+
/** Lines that are UI chrome or tool framing, never part of the run log. */
|
|
44
|
+
function isChrome(text) {
|
|
45
|
+
return /^(⋮|▸|●)/.test(text) || /^Purpose:/.test(text)
|
|
46
|
+
|| /^All tools are now trusted\b/.test(text) || /^Agents can sometimes do unexpected things\b/.test(text)
|
|
47
|
+
|| /^Learn more at\b/.test(text);
|
|
62
48
|
}
|
|
63
49
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
50
|
+
* One turn of Kiro's text output as the shared run-log rows: replies as
|
|
51
|
+
* replies (the last one is the final answer), shell calls as commands with
|
|
52
|
+
* their output, writes as file changes, MCP calls as tool rows. Reads and
|
|
53
|
+
* tool arguments are left out, as in Codex runs.
|
|
68
54
|
*/
|
|
69
|
-
function
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
55
|
+
function kiroLineParser() {
|
|
56
|
+
let mode = 'none';
|
|
57
|
+
/** A shell call still waiting for ` - Completed`; its output may interleave with a parallel read. */
|
|
58
|
+
let command = '';
|
|
59
|
+
/** Whether the row printed last belongs to `command`, so output can follow it directly. */
|
|
60
|
+
let commandLast = false;
|
|
61
|
+
let reply = [];
|
|
62
|
+
const commandRows = (text) => {
|
|
63
|
+
const rows = commandLast ? [] : [runLog.command(command)];
|
|
64
|
+
commandLast = true;
|
|
65
|
+
return [...rows, ...runLog.commandOutput(text)];
|
|
66
|
+
};
|
|
67
|
+
const parse = (raw) => {
|
|
68
|
+
// Some builds can emit JSON result lines; keep supporting them first.
|
|
69
|
+
const event = tryJson(raw);
|
|
70
|
+
if (event && raw.trim().startsWith('{'))
|
|
71
|
+
return jsonLine(event, raw);
|
|
72
|
+
const text = raw.replace(ANSI, '').replace(/^λ↯\s*/, '').replace(/\s+$/, '');
|
|
73
|
+
const trimmed = text.trim();
|
|
74
|
+
if (!trimmed) {
|
|
75
|
+
if (mode === 'reply')
|
|
76
|
+
reply.push('');
|
|
77
|
+
return { display: [] };
|
|
78
|
+
}
|
|
79
|
+
const answer = /^>\s?(.*)$/.exec(trimmed);
|
|
80
|
+
// Command output can contain `> ` rows too; Kiro's own reply marker is colored.
|
|
81
|
+
if (answer && !(command && !raw.includes('\u001b'))) {
|
|
82
|
+
mode = 'reply';
|
|
83
|
+
commandLast = false;
|
|
84
|
+
reply = [answer[1] ?? ''];
|
|
85
|
+
return { message: reply.join('\n').trim(), display: runLog.reply(answer[1] ?? '') };
|
|
86
|
+
}
|
|
87
|
+
// `I will run the following command: ls -la (using tool: shell)<output glued on>`
|
|
88
|
+
const using = /^(.*?)\s*\(using tool: ([\w@/.-]+)\)(.*)$/.exec(trimmed);
|
|
89
|
+
if (using) {
|
|
90
|
+
const [, head = '', tool = '', rest = ''] = using;
|
|
91
|
+
mode = 'tool';
|
|
92
|
+
let rows;
|
|
93
|
+
if (tool === 'shell' || tool === 'execute_bash') {
|
|
94
|
+
command = head.replace(/^I will run the following command:\s*/i, '').trim();
|
|
95
|
+
commandLast = false;
|
|
96
|
+
rows = commandRows('');
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const path = /:\s*(\S+?)(?:,|$)/.exec(head)?.[1];
|
|
100
|
+
rows = toolCallRows(tool, path);
|
|
101
|
+
if (rows.length)
|
|
102
|
+
commandLast = false;
|
|
103
|
+
}
|
|
104
|
+
const more = rest.trim() ? parse(rest).display : [];
|
|
105
|
+
return { display: [...rows, ...more] };
|
|
106
|
+
}
|
|
107
|
+
if (/^Running tool\b/.test(trimmed)) {
|
|
108
|
+
mode = 'tool';
|
|
109
|
+
commandLast = false;
|
|
110
|
+
return { display: [/\(from mcp server:/.test(trimmed) ? runLog.tool('mcp_tool_call') : runLog.tool('tool_call')] };
|
|
111
|
+
}
|
|
112
|
+
if (/^- Completed in\b/.test(trimmed)) {
|
|
113
|
+
const done = command && commandLast ? [runLog.commandExit(0)] : [];
|
|
114
|
+
if (command && commandLast) {
|
|
115
|
+
command = '';
|
|
116
|
+
commandLast = false;
|
|
117
|
+
}
|
|
118
|
+
mode = 'none';
|
|
119
|
+
return { display: done };
|
|
120
|
+
}
|
|
121
|
+
if (isChrome(trimmed))
|
|
122
|
+
return { display: [] };
|
|
123
|
+
// Tool result summaries: success is implied by the step, a failure is shown.
|
|
124
|
+
if (/^✓/.test(trimmed))
|
|
125
|
+
return { display: [] };
|
|
126
|
+
if (/^[✗❗]/.test(trimmed) && mode !== 'reply' && !command)
|
|
127
|
+
return { display: [runLog.error(trimmed.replace(/^[✗❗]\s*/, ''))] };
|
|
128
|
+
if (mode === 'reply') {
|
|
129
|
+
reply.push(text);
|
|
130
|
+
return { message: reply.join('\n').trim(), display: runLog.replyMore(text) };
|
|
131
|
+
}
|
|
132
|
+
if (command)
|
|
133
|
+
return { display: commandRows(text) };
|
|
134
|
+
// Tool bodies (diffs, `Creating: …`, `✓ Successfully read …`) stay out.
|
|
135
|
+
if (mode === 'tool')
|
|
136
|
+
return { display: [] };
|
|
137
|
+
return { display: [text] };
|
|
138
|
+
};
|
|
139
|
+
return parse;
|
|
140
|
+
}
|
|
141
|
+
function jsonLine(event, line) {
|
|
142
|
+
const sessionId = str(event.session_id) ?? str(event.sessionId);
|
|
143
|
+
const message = str(event.response) ?? str(event.message) ?? str(event.text);
|
|
144
|
+
const error = typeof event.error === 'string'
|
|
145
|
+
? event.error
|
|
146
|
+
: event.error && typeof event.error === 'object'
|
|
147
|
+
? str(event.error.message)
|
|
148
|
+
: undefined;
|
|
149
|
+
const type = str(event.type) ?? '';
|
|
150
|
+
return {
|
|
151
|
+
...(sessionId ? { sessionId } : {}),
|
|
152
|
+
...(message ? { message } : {}),
|
|
153
|
+
...(error ? { turnError: error } : {}),
|
|
154
|
+
...(message && (type === 'result' || type === 'turn.completed') ? { turnCompleted: true } : {}),
|
|
155
|
+
display: message ? runLog.reply(message) : error ? [runLog.error(error)] : [line]
|
|
156
|
+
};
|
|
78
157
|
}
|
|
79
158
|
export const kiroProvider = {
|
|
80
159
|
id: 'kiro',
|
|
@@ -88,66 +167,43 @@ export const kiroProvider = {
|
|
|
88
167
|
args.push('--model', request.model);
|
|
89
168
|
if (request.reasoningEffort)
|
|
90
169
|
args.push('--effort', request.reasoningEffort);
|
|
91
|
-
|
|
170
|
+
// The supervisor only passes a session it found saved for this folder;
|
|
171
|
+
// an IDE (v3) id would switch engines and reject the trust flags.
|
|
172
|
+
if (request.sessionId && !request.sessionId.startsWith('sess_'))
|
|
92
173
|
args.push('--resume-id', request.sessionId);
|
|
93
174
|
// Echo prompts start with `---payload---`; without `--` the CLI parses the
|
|
94
175
|
// prompt as an unknown flag and exits 2 ("unexpected argument").
|
|
95
176
|
args.push('--', request.prompt);
|
|
96
177
|
return kiroLaunch(args);
|
|
97
178
|
},
|
|
98
|
-
async
|
|
99
|
-
const
|
|
179
|
+
async listSessions(workdir) {
|
|
180
|
+
const { executable, args, env } = kiroLaunch(LIST_SESSIONS);
|
|
181
|
+
try {
|
|
182
|
+
const { stdout } = await execFileAsync(executable, args, { cwd: workdir, env, timeout: 15_000, maxBuffer: 8 * 1024 * 1024 });
|
|
183
|
+
return parseKiroSessions(stdout);
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
inspectExit(context) {
|
|
100
190
|
const businessError = kiroStderrError(context.stderr);
|
|
101
191
|
if (businessError)
|
|
102
|
-
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (sessionId)
|
|
108
|
-
inspection.sessionId = sessionId;
|
|
109
|
-
}
|
|
110
|
-
return inspection;
|
|
192
|
+
return { turnError: businessError };
|
|
193
|
+
// `▸ Credits: 0.34 • Time: 16s` (stderr) closes a turn that did run. Shown
|
|
194
|
+
// at exit: stderr can arrive before the last stdout rows of the reply.
|
|
195
|
+
const credits = context.stderr.map((line) => /^\s*▸\s*(Credits:.*)$/.exec(line.replace(ANSI, ''))?.[1]).find(Boolean);
|
|
196
|
+
return credits ? { display: [runLog.event(`本轮完成(${credits.trim().replace(/\s*•\s*/g, ' · ')})`)] } : {};
|
|
111
197
|
},
|
|
112
198
|
parseLine(line) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const sessionId = str(event.session_id) ?? str(event.sessionId);
|
|
122
|
-
const message = str(event.response) ?? str(event.message) ?? str(event.text);
|
|
123
|
-
const error = typeof event.error === 'string'
|
|
124
|
-
? event.error
|
|
125
|
-
: event.error && typeof event.error === 'object'
|
|
126
|
-
? str(event.error.message)
|
|
127
|
-
: undefined;
|
|
128
|
-
const type = str(event.type) ?? '';
|
|
129
|
-
return {
|
|
130
|
-
...(sessionId ? { sessionId } : {}),
|
|
131
|
-
...(message ? { message } : {}),
|
|
132
|
-
...(error ? { turnError: error } : {}),
|
|
133
|
-
...(message && (type === 'result' || type === 'turn.completed') ? { turnCompleted: true } : {}),
|
|
134
|
-
display: message ? textRows('› ', message) : error ? [`✗ ${error}`] : [line]
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
// Human-readable text output (the common path on Kiro CLI 2.18+). Strip the
|
|
138
|
-
// leading `λ↯` banner the CLI prints before its first line.
|
|
139
|
-
const text = line.replace(/^λ↯\s*/, '').trim();
|
|
140
|
-
if (!text)
|
|
141
|
-
return { display: [] };
|
|
142
|
-
// The final answer is printed on a `> ` line. Capture it as the message
|
|
143
|
-
// without declaring the turn complete (process exit decides completion).
|
|
144
|
-
const answer = text.match(/^>\s?(.*)$/);
|
|
145
|
-
if (answer && answer[1]?.trim()) {
|
|
146
|
-
return { message: answer[1].trim(), display: [`› ${answer[1].trim()}`] };
|
|
147
|
-
}
|
|
148
|
-
if (isNoiseLine(text))
|
|
149
|
-
return { display: [] };
|
|
150
|
-
return { display: [line.replace(/^λ↯\s*/, '')] };
|
|
199
|
+
return kiroLineParser()(line);
|
|
200
|
+
},
|
|
201
|
+
createLineParser: () => kiroLineParser(),
|
|
202
|
+
stderrDisplay(line) {
|
|
203
|
+
const text = line.replace(ANSI, '').trim();
|
|
204
|
+
if (!text || isChrome(text))
|
|
205
|
+
return [];
|
|
206
|
+
return [line];
|
|
151
207
|
}
|
|
152
208
|
};
|
|
153
209
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kiro.js","sourceRoot":"","sources":["../../../../src/providers/cli/kiro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"kiro.js","sourceRoot":"","sources":["../../../../src/providers/cli/kiro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAGrC,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAE3G,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAA;AAEzC;;;;;;;;;;;;;;;;;;GAkBG;AAEH,4CAA4C;AAC5C,MAAM,IAAI,GAAG,2EAA2E,CAAA;AAExF,iFAAiF;AACjF,SAAS,UAAU,CAAC,IAAc;IAChC,OAAO,iBAAiB,CAAC,UAAU,EAAE,IAAI,EAAE,mBAAmB,EAAE,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAA;AACnG,CAAC;AAGD,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,CAAC,CAAA;AAErE;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,MAAM,MAA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AC,IAAI,CAAC,CAAA;IAC/B,CAAC;IACD,gBAAgB,EAAE,GAAG,EAAE,CAAC,cAAc,EAAE;IACxC,aAAa,CAAC,IAAI;QAChB,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;QAC1C,IAAI,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,CAAC;YAAE,OAAO,EAAE,CAAA;QACtC,OAAO,CAAC,IAAI,CAAC,CAAA;IACf,CAAC;CACF,CAAA;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,WAA8B;IAC5D,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACnC,IAAI,sDAAsD,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACtE,OAAO,8BAA8B,CAAA;IACvC,CAAC;IACD,IAAI,mEAAmE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACnF,OAAO,gCAAgC,CAAA;IACzC,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
|
@@ -43,6 +43,8 @@ export type ParsedLine = {
|
|
|
43
43
|
export type ExitInspection = {
|
|
44
44
|
/** Fail the turn with this reason even if the process exited 0. */
|
|
45
45
|
turnError?: string;
|
|
46
|
+
/** Run-log rows to add once all output is read (e.g. a usage footer). */
|
|
47
|
+
display?: string[];
|
|
46
48
|
/** Native session id discovered after the turn (CLIs that do not print it). */
|
|
47
49
|
sessionId?: string;
|
|
48
50
|
};
|
|
@@ -54,20 +56,73 @@ export type ExitContext = {
|
|
|
54
56
|
/** The session id already known from stdout, if any. */
|
|
55
57
|
sessionId: string;
|
|
56
58
|
};
|
|
59
|
+
/** One chat the CLI saved for a working directory. */
|
|
60
|
+
export type SavedSession = {
|
|
61
|
+
id: string;
|
|
62
|
+
title?: string;
|
|
63
|
+
};
|
|
57
64
|
export interface HeadlessProvider {
|
|
58
65
|
readonly id: string;
|
|
59
66
|
buildLaunch(request: HeadlessRunRequest): LaunchSpec;
|
|
60
67
|
/** Parses one stdout line; non-JSON lines are shown as-is. */
|
|
61
68
|
parseLine(line: string): ParsedLine;
|
|
69
|
+
/**
|
|
70
|
+
* Optional per-turn parser for output that needs state across lines (a
|
|
71
|
+
* tool result that refers back to its call, a reply spread over rows).
|
|
72
|
+
* Each turn gets its own, so concurrent runs never share state.
|
|
73
|
+
*/
|
|
74
|
+
createLineParser?(): (line: string) => ParsedLine;
|
|
75
|
+
/** Optional stderr rendering for the run log; default shows the row as-is. */
|
|
76
|
+
stderrDisplay?(line: string): string[];
|
|
62
77
|
/** Optional app-server handshake; task-chain exec providers have no stdin. */
|
|
63
78
|
startInput?(write: (message: string) => void): void;
|
|
64
79
|
/**
|
|
65
80
|
* Optional post-exit inspection for CLIs whose stdout is not machine
|
|
66
|
-
* readable: detect business errors behind a zero exit code
|
|
67
|
-
*
|
|
81
|
+
* readable: detect business errors behind a zero exit code. Runs once
|
|
82
|
+
* after the process closes.
|
|
68
83
|
*/
|
|
69
84
|
inspectExit?(context: ExitContext): Promise<ExitInspection> | ExitInspection;
|
|
85
|
+
/**
|
|
86
|
+
* For CLIs that never print their native session id: the chats saved for
|
|
87
|
+
* `workdir`. The supervisor lists them before and after a fresh turn and
|
|
88
|
+
* keeps only the chat this turn created, so workstations sharing a folder
|
|
89
|
+
* never pick up each other's session. Resolves undefined when unreadable.
|
|
90
|
+
*/
|
|
91
|
+
listSessions?(workdir: string): Promise<SavedSession[] | undefined>;
|
|
70
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* The session a fresh turn created: the one id missing from the snapshot
|
|
95
|
+
* taken before launch. Several new ids mean another turn in the same folder
|
|
96
|
+
* also started a chat; the one titled with this prompt wins, otherwise none
|
|
97
|
+
* is chosen (the next turn starts fresh rather than joining someone else).
|
|
98
|
+
*/
|
|
99
|
+
export declare function pickCreatedSession(before: ReadonlySet<string>, after: readonly SavedSession[], prompt: string): string | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* Run-log rows. The 运行日志 view in every Echo client reads these markers
|
|
102
|
+
* (see echo_web `runLog.ts`), so all providers render through them:
|
|
103
|
+
*
|
|
104
|
+
* ● event ✗ error $ command › reply … thinking ✎ file change · tool kind
|
|
105
|
+
* " " continues the previous reply / thinking / command, " (exit N)" ends a command.
|
|
106
|
+
*/
|
|
107
|
+
export declare const runLog: {
|
|
108
|
+
event: (text: string) => string;
|
|
109
|
+
error: (text: string) => string;
|
|
110
|
+
reply: (text: string) => string[];
|
|
111
|
+
/** Rows continuing the previous reply. */
|
|
112
|
+
replyMore: (text: string) => string[];
|
|
113
|
+
thinking: (text: string) => string[];
|
|
114
|
+
command: (command: string) => string;
|
|
115
|
+
commandOutput: (output: string) => string[];
|
|
116
|
+
commandExit: (code?: number) => string;
|
|
117
|
+
fileChange: (path?: string) => string;
|
|
118
|
+
/** A tool call without its own row type, by the kinds the clients name. */
|
|
119
|
+
tool: (kind: "mcp_tool_call" | "web_search" | "todo_list" | "tool_call" | "image_generation") => string;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Run-log rows for a named tool call other than a shell command. Reads and
|
|
123
|
+
* searches are silent, like Codex (which reads through shell commands).
|
|
124
|
+
*/
|
|
125
|
+
export declare function toolCallRows(name: string, path?: string): string[];
|
|
71
126
|
export declare function providerEnvironment(): NodeJS.ProcessEnv;
|
|
72
127
|
/**
|
|
73
128
|
* Resolves a CLI on PATH. npm-installed CLIs are often `.js` shims; those are
|