toc-ocra 0.3.2 → 0.3.4
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/README.md +10 -1
- package/dist/cli/cli.mjs +3144 -1727
- package/dist/service/agent.mjs +4790 -3373
- package/dist/src/acp/ask-user-question.d.ts +99 -0
- package/dist/src/acp/ask-user-question.js +333 -0
- package/dist/src/acp/ask-user-question.js.map +1 -0
- package/dist/src/acp/chat-agents.d.ts +19 -1
- package/dist/src/acp/chat-agents.js +7 -3
- package/dist/src/acp/chat-agents.js.map +1 -1
- package/dist/src/acp/chat-host.d.ts +7 -1
- package/dist/src/acp/chat-host.js +11 -0
- package/dist/src/acp/chat-host.js.map +1 -1
- package/dist/src/acp/chat-session.d.ts +41 -1
- package/dist/src/acp/chat-session.js +164 -11
- package/dist/src/acp/chat-session.js.map +1 -1
- package/dist/src/acp/connection.d.ts +16 -4
- package/dist/src/acp/connection.js +25 -11
- package/dist/src/acp/connection.js.map +1 -1
- package/dist/src/acp/rpc.d.ts +8 -2
- package/dist/src/acp/rpc.js +19 -1
- package/dist/src/acp/rpc.js.map +1 -1
- package/dist/src/acp/transcript.d.ts +55 -0
- package/dist/src/acp/transcript.js +67 -14
- package/dist/src/acp/transcript.js.map +1 -1
- package/dist/src/acp/vendor.d.ts +5 -2
- package/dist/src/acp/vendor.js +6 -3
- package/dist/src/acp/vendor.js.map +1 -1
- package/dist/src/index.js +0 -0
- package/dist/src/memory/providers.d.ts +79 -0
- package/dist/src/memory/providers.js +130 -0
- package/dist/src/memory/providers.js.map +1 -0
- package/dist/src/providers/acp/acp-driver.d.ts +2 -0
- package/dist/src/providers/acp/acp-driver.js +38 -15
- package/dist/src/providers/acp/acp-driver.js.map +1 -1
- package/dist/src/providers/cli/claude.d.ts +11 -0
- package/dist/src/providers/cli/claude.js +158 -5
- package/dist/src/providers/cli/claude.js.map +1 -1
- package/dist/src/providers/cli/codex.d.ts +9 -1
- package/dist/src/providers/cli/codex.js +114 -8
- package/dist/src/providers/cli/codex.js.map +1 -1
- package/dist/src/runs/run-supervisor.d.ts +45 -5
- package/dist/src/runs/run-supervisor.js +182 -51
- package/dist/src/runs/run-supervisor.js.map +1 -1
- package/dist/src/runs/run-transcript.d.ts +182 -0
- package/dist/src/runs/run-transcript.js +550 -0
- package/dist/src/runs/run-transcript.js.map +1 -0
- package/dist/src/runtime/agent-runtime.js +34 -3
- package/dist/src/runtime/agent-runtime.js.map +1 -1
- package/dist/src/types/protocol.d.ts +31 -0
- package/dist/src/types/protocol.js +32 -1
- package/dist/src/types/protocol.js.map +1 -1
- package/package.json +1 -2
- package/scripts/installation.cjs +14 -1
- /package/{vendor → assets}/acp/claude/LICENSE +0 -0
- /package/{vendor → assets}/acp/claude/index.mjs +0 -0
- /package/{vendor → assets}/acp/claude/runtime.json +0 -0
- /package/{vendor → assets}/acp/codex/LICENSE +0 -0
- /package/{vendor → assets}/acp/codex/index.mjs +0 -0
- /package/{vendor → assets}/acp/codex/runtime.json +0 -0
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
import { chmod, mkdir, readdir, readFile, rename, stat, unlink, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { sanitizeTerminalLine } from '../session/terminal-line-sanitizer.js';
|
|
4
|
+
/**
|
|
5
|
+
* One run's 执行过程: the structured chat items (text, thought, tool calls,
|
|
6
|
+
* plan, …) and the run-log rows, for every run (task-chain headless runs and
|
|
7
|
+
* CLI-chat ACP runs alike). Items fold exactly like the server's
|
|
8
|
+
* ReportCLIChatEvents:
|
|
9
|
+
*
|
|
10
|
+
* - `text_delta` / `thought_delta` with `item_id` append to that item,
|
|
11
|
+
* creating it at the end when absent; without an id they append to the
|
|
12
|
+
* last item when it is of the same kind and was itself opened by id-less
|
|
13
|
+
* deltas, else open a new one (`auto:m<n>` / `auto:t<n>`);
|
|
14
|
+
* - `item` replaces the item with the same `itemId` in place (it keeps its
|
|
15
|
+
* first position) or appends it.
|
|
16
|
+
*
|
|
17
|
+
* Every change bumps the transcript's `revision`; each item remembers the
|
|
18
|
+
* revision of its last change, so a reader polls with `since` and gets only
|
|
19
|
+
* what changed. `TranscriptStore` keeps a copy on disk after the run is gone
|
|
20
|
+
* from memory.
|
|
21
|
+
*/
|
|
22
|
+
export const MAX_TRANSCRIPT_ITEMS = 5_000;
|
|
23
|
+
/** Characters of one text / thought item. */
|
|
24
|
+
export const MAX_TRANSCRIPT_TEXT = 200_000;
|
|
25
|
+
export const MAX_TRANSCRIPT_LINES = 20_000;
|
|
26
|
+
export const MAX_TRANSCRIPT_LINE_BYTES = 4 * 1024 * 1024;
|
|
27
|
+
/** Characters of one run-log row; a longer row is cut. */
|
|
28
|
+
const MAX_LINE_CHARS = 16_000;
|
|
29
|
+
/** JSON budget of the items of one read (at least one item is always returned). */
|
|
30
|
+
const ITEM_PAGE_BYTES = 1024 * 1024;
|
|
31
|
+
/** Budget of the run-log rows of one read (at least one row is always returned). */
|
|
32
|
+
const LINE_PAGE_BYTES = 512 * 1024;
|
|
33
|
+
/** Dropped head rows tolerated before the row array is compacted. */
|
|
34
|
+
const LINE_COMPACT_THRESHOLD = 1_024;
|
|
35
|
+
export class RunTranscript {
|
|
36
|
+
runId;
|
|
37
|
+
sessionKey;
|
|
38
|
+
agentType;
|
|
39
|
+
chat;
|
|
40
|
+
status = 'running';
|
|
41
|
+
startedAt;
|
|
42
|
+
endedAt = null;
|
|
43
|
+
exitCode = null;
|
|
44
|
+
revision = 0;
|
|
45
|
+
/** Changed since the last write to disk. */
|
|
46
|
+
dirty = false;
|
|
47
|
+
/** Called after every change (the store schedules a write). */
|
|
48
|
+
onChange;
|
|
49
|
+
entries = [];
|
|
50
|
+
positions = new Map();
|
|
51
|
+
/** Items opened by deltas without an item id. */
|
|
52
|
+
unnamed = new Set();
|
|
53
|
+
unnamedSequence = 0;
|
|
54
|
+
rows = [];
|
|
55
|
+
head = 0;
|
|
56
|
+
rowBytes = 0;
|
|
57
|
+
lineTotal = 0;
|
|
58
|
+
linesDropped = 0;
|
|
59
|
+
/** False when read back from disk: the items carry no revisions of their own. */
|
|
60
|
+
itemRevisions = true;
|
|
61
|
+
constructor(init) {
|
|
62
|
+
this.runId = init.runId;
|
|
63
|
+
this.sessionKey = init.sessionKey;
|
|
64
|
+
this.agentType = init.agentType;
|
|
65
|
+
this.chat = init.chat;
|
|
66
|
+
this.startedAt = init.startedAt ?? Date.now();
|
|
67
|
+
}
|
|
68
|
+
get running() {
|
|
69
|
+
return this.status === 'running';
|
|
70
|
+
}
|
|
71
|
+
get itemCount() {
|
|
72
|
+
return this.entries.length;
|
|
73
|
+
}
|
|
74
|
+
/** Folds one (already sanitized) chat event. */
|
|
75
|
+
fold(event) {
|
|
76
|
+
if (event.event === 'item') {
|
|
77
|
+
this.putItem(event.item);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (event.event !== 'text_delta' && event.event !== 'thought_delta')
|
|
81
|
+
return;
|
|
82
|
+
const text = typeof event.text === 'string' ? event.text : '';
|
|
83
|
+
if (!text)
|
|
84
|
+
return;
|
|
85
|
+
const type = event.event === 'text_delta' ? 'text' : 'thought';
|
|
86
|
+
let itemId = typeof event.item_id === 'string' ? event.item_id : '';
|
|
87
|
+
if (!itemId) {
|
|
88
|
+
const last = this.entries[this.entries.length - 1]?.item;
|
|
89
|
+
if (last && this.unnamed.has(last.itemId) && last.type === type)
|
|
90
|
+
itemId = last.itemId;
|
|
91
|
+
else {
|
|
92
|
+
do
|
|
93
|
+
itemId = `auto:${type === 'text' ? 'm' : 't'}${++this.unnamedSequence}`;
|
|
94
|
+
while (this.positions.has(itemId));
|
|
95
|
+
if (!this.append({ itemId, type, text: clipText(text) }))
|
|
96
|
+
return;
|
|
97
|
+
this.unnamed.add(itemId);
|
|
98
|
+
this.changed();
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const position = this.positions.get(itemId);
|
|
103
|
+
if (position === undefined) {
|
|
104
|
+
if (this.append({ itemId, type, text: clipText(text) }))
|
|
105
|
+
this.changed();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const entry = this.entries[position];
|
|
109
|
+
const current = typeof entry.item.text === 'string' ? entry.item.text : '';
|
|
110
|
+
if (current.length >= MAX_TRANSCRIPT_TEXT)
|
|
111
|
+
return;
|
|
112
|
+
this.entries[position] = { rev: ++this.revision, item: { ...entry.item, text: clipText(current + text) } };
|
|
113
|
+
this.changed();
|
|
114
|
+
}
|
|
115
|
+
/** Run-log text as appended to the run's tail (newline-terminated rows). */
|
|
116
|
+
appendLog(text) {
|
|
117
|
+
if (!text)
|
|
118
|
+
return;
|
|
119
|
+
const rows = text.split('\n');
|
|
120
|
+
if (rows[rows.length - 1] === '')
|
|
121
|
+
rows.pop();
|
|
122
|
+
this.appendLines(rows);
|
|
123
|
+
}
|
|
124
|
+
appendLines(rows) {
|
|
125
|
+
if (!rows.length)
|
|
126
|
+
return;
|
|
127
|
+
for (const raw of rows) {
|
|
128
|
+
// Like the tail buffer: a CRLF's CR goes, a bare CR rewrites the row.
|
|
129
|
+
const row = raw.endsWith('\r') ? raw.slice(0, -1) : raw;
|
|
130
|
+
const carriage = row.lastIndexOf('\r');
|
|
131
|
+
let line = sanitizeTerminalLine(carriage === -1 ? row : row.slice(carriage + 1));
|
|
132
|
+
if (line.length > MAX_LINE_CHARS)
|
|
133
|
+
line = `${line.slice(0, MAX_LINE_CHARS)}…`;
|
|
134
|
+
this.rows.push(line);
|
|
135
|
+
this.rowBytes += Buffer.byteLength(line) + 1;
|
|
136
|
+
this.lineTotal += 1;
|
|
137
|
+
}
|
|
138
|
+
while (this.rows.length - this.head > MAX_TRANSCRIPT_LINES || (this.rowBytes > MAX_TRANSCRIPT_LINE_BYTES && this.rows.length - this.head > 1)) {
|
|
139
|
+
this.rowBytes -= Buffer.byteLength(this.rows[this.head]) + 1;
|
|
140
|
+
this.rows[this.head] = '';
|
|
141
|
+
this.head += 1;
|
|
142
|
+
this.linesDropped += 1;
|
|
143
|
+
}
|
|
144
|
+
if (this.head >= LINE_COMPACT_THRESHOLD) {
|
|
145
|
+
this.rows = this.rows.slice(this.head);
|
|
146
|
+
this.head = 0;
|
|
147
|
+
}
|
|
148
|
+
this.revision += 1;
|
|
149
|
+
this.changed();
|
|
150
|
+
}
|
|
151
|
+
/** The run's outcome; the transcript stays readable afterwards. */
|
|
152
|
+
finish(status, exitCode = null, endedAt = Date.now()) {
|
|
153
|
+
this.status = status;
|
|
154
|
+
this.exitCode = exitCode;
|
|
155
|
+
this.endedAt = endedAt;
|
|
156
|
+
this.revision += 1;
|
|
157
|
+
this.changed();
|
|
158
|
+
}
|
|
159
|
+
read(options = {}) {
|
|
160
|
+
const since = whole(options.since);
|
|
161
|
+
const itemFrom = whole(options.item_from);
|
|
162
|
+
const lineFrom = whole(options.line_from);
|
|
163
|
+
const items = [];
|
|
164
|
+
let itemsMore = false;
|
|
165
|
+
// Read back from disk, items have no revisions: all of them are newer than
|
|
166
|
+
// an older `since`, none than the current revision.
|
|
167
|
+
const everyItem = !this.itemRevisions && this.revision > since;
|
|
168
|
+
if (this.itemRevisions || everyItem) {
|
|
169
|
+
let bytes = 0;
|
|
170
|
+
for (let index = itemFrom; index < this.entries.length; index += 1) {
|
|
171
|
+
const entry = this.entries[index];
|
|
172
|
+
if (this.itemRevisions && entry.rev <= since)
|
|
173
|
+
continue;
|
|
174
|
+
const size = Buffer.byteLength(JSON.stringify(entry.item)) + 16;
|
|
175
|
+
if (items.length && bytes + size > ITEM_PAGE_BYTES) {
|
|
176
|
+
itemsMore = true;
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
bytes += size;
|
|
180
|
+
items.push({ i: index, item: entry.item });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const first = this.lineTotal - (this.rows.length - this.head);
|
|
184
|
+
const lineStart = Math.min(Math.max(lineFrom, first), this.lineTotal);
|
|
185
|
+
const lines = [];
|
|
186
|
+
let cursor = lineStart;
|
|
187
|
+
let lineBytes = 0;
|
|
188
|
+
for (; cursor < this.lineTotal; cursor += 1) {
|
|
189
|
+
const line = this.rows[this.head + (cursor - first)] ?? '';
|
|
190
|
+
const size = Buffer.byteLength(line) + 1;
|
|
191
|
+
if (lines.length && lineBytes + size > LINE_PAGE_BYTES)
|
|
192
|
+
break;
|
|
193
|
+
lineBytes += size;
|
|
194
|
+
lines.push(line);
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
run_id: this.runId,
|
|
198
|
+
found: true,
|
|
199
|
+
running: this.running,
|
|
200
|
+
status: this.status,
|
|
201
|
+
agent_type: this.agentType,
|
|
202
|
+
session_key: this.sessionKey,
|
|
203
|
+
chat: this.chat,
|
|
204
|
+
started_at: this.startedAt,
|
|
205
|
+
ended_at: this.endedAt,
|
|
206
|
+
exit_code: this.exitCode,
|
|
207
|
+
revision: this.revision,
|
|
208
|
+
item_count: this.entries.length,
|
|
209
|
+
items,
|
|
210
|
+
items_more: itemsMore,
|
|
211
|
+
line_total: this.lineTotal,
|
|
212
|
+
line_start: lineStart,
|
|
213
|
+
lines,
|
|
214
|
+
lines_more: cursor < this.lineTotal,
|
|
215
|
+
lines_dropped: this.linesDropped
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
toFile() {
|
|
219
|
+
return {
|
|
220
|
+
v: 1,
|
|
221
|
+
run_id: this.runId,
|
|
222
|
+
session_key: this.sessionKey,
|
|
223
|
+
agent_type: this.agentType,
|
|
224
|
+
chat: this.chat,
|
|
225
|
+
status: this.status,
|
|
226
|
+
started_at: this.startedAt,
|
|
227
|
+
ended_at: this.endedAt,
|
|
228
|
+
exit_code: this.exitCode,
|
|
229
|
+
revision: this.revision,
|
|
230
|
+
items: this.entries.map((entry) => entry.item),
|
|
231
|
+
lines: this.rows.slice(this.head),
|
|
232
|
+
line_total: this.lineTotal,
|
|
233
|
+
lines_dropped: this.linesDropped
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* A transcript read back from disk. It is only consulted when the run is
|
|
238
|
+
* not in memory, so one still marked `running` belongs to an agent process
|
|
239
|
+
* that ended before the run did: it reads as `lost`.
|
|
240
|
+
*/
|
|
241
|
+
static fromFile(value) {
|
|
242
|
+
const data = record(value);
|
|
243
|
+
if (data.v !== 1 || typeof data.run_id !== 'string' || !data.run_id || !Array.isArray(data.items) || !Array.isArray(data.lines))
|
|
244
|
+
return undefined;
|
|
245
|
+
const transcript = new RunTranscript({
|
|
246
|
+
runId: data.run_id,
|
|
247
|
+
sessionKey: typeof data.session_key === 'string' ? data.session_key : data.run_id,
|
|
248
|
+
agentType: typeof data.agent_type === 'string' ? data.agent_type : '',
|
|
249
|
+
chat: data.chat === true,
|
|
250
|
+
startedAt: finite(data.started_at) ?? 0
|
|
251
|
+
});
|
|
252
|
+
const status = typeof data.status === 'string' && data.status ? data.status : 'lost';
|
|
253
|
+
transcript.status = status === 'running' ? 'lost' : status;
|
|
254
|
+
transcript.endedAt = finite(data.ended_at) ?? null;
|
|
255
|
+
transcript.exitCode = finite(data.exit_code) ?? null;
|
|
256
|
+
transcript.revision = whole(data.revision);
|
|
257
|
+
transcript.itemRevisions = false;
|
|
258
|
+
for (const value of data.items) {
|
|
259
|
+
const item = record(value);
|
|
260
|
+
if (typeof item.itemId !== 'string' || !item.itemId || transcript.positions.has(item.itemId))
|
|
261
|
+
continue;
|
|
262
|
+
transcript.positions.set(item.itemId, transcript.entries.length);
|
|
263
|
+
transcript.entries.push({ rev: 0, item: item });
|
|
264
|
+
}
|
|
265
|
+
transcript.rows = data.lines.filter((line) => typeof line === 'string');
|
|
266
|
+
for (const line of transcript.rows)
|
|
267
|
+
transcript.rowBytes += Buffer.byteLength(line) + 1;
|
|
268
|
+
transcript.lineTotal = Math.max(whole(data.line_total), transcript.rows.length);
|
|
269
|
+
transcript.linesDropped = whole(data.lines_dropped);
|
|
270
|
+
return transcript;
|
|
271
|
+
}
|
|
272
|
+
putItem(raw) {
|
|
273
|
+
const itemId = typeof raw?.itemId === 'string' ? raw.itemId : '';
|
|
274
|
+
if (!raw || !itemId)
|
|
275
|
+
return;
|
|
276
|
+
let item = { ...raw, itemId };
|
|
277
|
+
if ((item.type === 'text' || item.type === 'thought') && typeof item.text === 'string' && item.text.length > MAX_TRANSCRIPT_TEXT) {
|
|
278
|
+
item = { ...item, text: clipText(item.text) };
|
|
279
|
+
}
|
|
280
|
+
const position = this.positions.get(itemId);
|
|
281
|
+
if (position !== undefined)
|
|
282
|
+
this.entries[position] = { rev: ++this.revision, item };
|
|
283
|
+
else if (!this.append(item))
|
|
284
|
+
return;
|
|
285
|
+
this.changed();
|
|
286
|
+
}
|
|
287
|
+
append(item) {
|
|
288
|
+
if (this.entries.length >= MAX_TRANSCRIPT_ITEMS)
|
|
289
|
+
return false;
|
|
290
|
+
this.positions.set(item.itemId, this.entries.length);
|
|
291
|
+
this.entries.push({ rev: ++this.revision, item });
|
|
292
|
+
return true;
|
|
293
|
+
}
|
|
294
|
+
changed() {
|
|
295
|
+
this.dirty = true;
|
|
296
|
+
this.onChange?.();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/** How often a running transcript with changes is written. */
|
|
300
|
+
const FLUSH_INTERVAL_MS = 2_000;
|
|
301
|
+
/** Transcript files kept: the newest ones, within both limits. */
|
|
302
|
+
const MAX_FILES = 1_000;
|
|
303
|
+
const MAX_TOTAL_BYTES = 300 * 1024 * 1024;
|
|
304
|
+
/** Parsed files kept for repeated reads (a client paging through one run). */
|
|
305
|
+
const CACHE_SIZE = 4;
|
|
306
|
+
/** A temporary file this old is a leftover of an interrupted write. */
|
|
307
|
+
const STALE_TEMPORARY_MS = 10 * 60_000;
|
|
308
|
+
/** `TOC_OCRA_RUN_TRANSCRIPTS=0` keeps transcripts in memory only. */
|
|
309
|
+
export function transcriptsOnDisk(env = process.env) {
|
|
310
|
+
return !/^(0|false|off|no)$/i.test(env.TOC_OCRA_RUN_TRANSCRIPTS?.trim() ?? '');
|
|
311
|
+
}
|
|
312
|
+
/** `<runId>.json`, or undefined for an id that is not a plain file name. */
|
|
313
|
+
export function transcriptFileName(runId) {
|
|
314
|
+
return /^[A-Za-z0-9_-][A-Za-z0-9._-]{0,127}$/.test(runId) ? `${runId}.json` : undefined;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Transcripts on disk: `<dataDir>/transcripts/<runId>.json` (directory 0700,
|
|
318
|
+
* files 0600, written to a temporary file and renamed). A running transcript
|
|
319
|
+
* is written at most every `FLUSH_INTERVAL_MS` while it changes, and once
|
|
320
|
+
* more when the run ends. After that write (and once at startup) the
|
|
321
|
+
* directory is pruned to the newest `MAX_FILES` files within
|
|
322
|
+
* `MAX_TOTAL_BYTES`. A disk error never reaches the run.
|
|
323
|
+
*/
|
|
324
|
+
export class TranscriptStore {
|
|
325
|
+
logger;
|
|
326
|
+
enabled;
|
|
327
|
+
directory;
|
|
328
|
+
tracked = new Map();
|
|
329
|
+
timers = new Map();
|
|
330
|
+
writes = new Map();
|
|
331
|
+
cache = new Map();
|
|
332
|
+
pruning;
|
|
333
|
+
pruneAgain = false;
|
|
334
|
+
directoryReady = false;
|
|
335
|
+
warned = false;
|
|
336
|
+
constructor(dataDir, logger, env = process.env) {
|
|
337
|
+
this.logger = logger;
|
|
338
|
+
this.directory = dataDir ? join(dataDir, 'transcripts') : '';
|
|
339
|
+
this.enabled = Boolean(dataDir) && transcriptsOnDisk(env);
|
|
340
|
+
}
|
|
341
|
+
/** Writes this running transcript as it changes. */
|
|
342
|
+
track(transcript) {
|
|
343
|
+
if (!this.enabled || !transcriptFileName(transcript.runId))
|
|
344
|
+
return;
|
|
345
|
+
this.tracked.set(transcript.runId, transcript);
|
|
346
|
+
transcript.onChange = () => this.schedule(transcript);
|
|
347
|
+
if (transcript.dirty)
|
|
348
|
+
this.schedule(transcript);
|
|
349
|
+
}
|
|
350
|
+
/** Stops writing a transcript that was replaced (a run started again under its id). */
|
|
351
|
+
discard(transcript) {
|
|
352
|
+
transcript.onChange = undefined;
|
|
353
|
+
if (this.tracked.get(transcript.runId) !== transcript)
|
|
354
|
+
return;
|
|
355
|
+
this.tracked.delete(transcript.runId);
|
|
356
|
+
this.clearTimer(transcript.runId);
|
|
357
|
+
}
|
|
358
|
+
/** The final write of a finished run; then prunes. Never rejects. */
|
|
359
|
+
async flush(transcript) {
|
|
360
|
+
if (!this.enabled)
|
|
361
|
+
return;
|
|
362
|
+
this.discard(transcript);
|
|
363
|
+
await this.write(transcript);
|
|
364
|
+
void this.prune();
|
|
365
|
+
}
|
|
366
|
+
/** Writes every running transcript now (shutdown). */
|
|
367
|
+
async flushAll() {
|
|
368
|
+
await Promise.all([...this.tracked.values()].map((transcript) => {
|
|
369
|
+
this.clearTimer(transcript.runId);
|
|
370
|
+
return this.write(transcript);
|
|
371
|
+
}));
|
|
372
|
+
}
|
|
373
|
+
/** A transcript from disk, or undefined when there is none. */
|
|
374
|
+
async load(runId) {
|
|
375
|
+
const name = transcriptFileName(runId);
|
|
376
|
+
if (!this.enabled || !name)
|
|
377
|
+
return undefined;
|
|
378
|
+
const cached = this.cache.get(runId);
|
|
379
|
+
if (cached) {
|
|
380
|
+
this.cache.delete(runId);
|
|
381
|
+
this.cache.set(runId, cached);
|
|
382
|
+
return cached;
|
|
383
|
+
}
|
|
384
|
+
await this.writes.get(runId);
|
|
385
|
+
let text;
|
|
386
|
+
try {
|
|
387
|
+
text = await readFile(join(this.directory, name), 'utf8');
|
|
388
|
+
}
|
|
389
|
+
catch (error) {
|
|
390
|
+
if (errorCode(error) !== 'ENOENT')
|
|
391
|
+
this.logger.warn('run-transcript-read-failed', { runId, error: errorMessage(error) });
|
|
392
|
+
return undefined;
|
|
393
|
+
}
|
|
394
|
+
let transcript;
|
|
395
|
+
try {
|
|
396
|
+
transcript = RunTranscript.fromFile(JSON.parse(text));
|
|
397
|
+
}
|
|
398
|
+
catch {
|
|
399
|
+
transcript = undefined;
|
|
400
|
+
}
|
|
401
|
+
if (!transcript || transcript.runId !== runId) {
|
|
402
|
+
this.logger.warn('run-transcript-invalid', { runId });
|
|
403
|
+
return undefined;
|
|
404
|
+
}
|
|
405
|
+
this.cache.set(runId, transcript);
|
|
406
|
+
for (const key of this.cache.keys()) {
|
|
407
|
+
if (this.cache.size <= CACHE_SIZE)
|
|
408
|
+
break;
|
|
409
|
+
this.cache.delete(key);
|
|
410
|
+
}
|
|
411
|
+
return transcript;
|
|
412
|
+
}
|
|
413
|
+
/** Keeps the newest files within the count and size limits. Never rejects. */
|
|
414
|
+
prune() {
|
|
415
|
+
if (!this.enabled)
|
|
416
|
+
return Promise.resolve();
|
|
417
|
+
if (this.pruning) {
|
|
418
|
+
this.pruneAgain = true;
|
|
419
|
+
return this.pruning;
|
|
420
|
+
}
|
|
421
|
+
const run = (async () => {
|
|
422
|
+
do {
|
|
423
|
+
this.pruneAgain = false;
|
|
424
|
+
await this.pruneOnce();
|
|
425
|
+
} while (this.pruneAgain);
|
|
426
|
+
})().catch((error) => this.logger.warn('run-transcript-prune-failed', { error: errorMessage(error) }))
|
|
427
|
+
.finally(() => { this.pruning = undefined; });
|
|
428
|
+
this.pruning = run;
|
|
429
|
+
return run;
|
|
430
|
+
}
|
|
431
|
+
schedule(transcript) {
|
|
432
|
+
if (this.timers.has(transcript.runId) || this.tracked.get(transcript.runId) !== transcript)
|
|
433
|
+
return;
|
|
434
|
+
const timer = setTimeout(() => {
|
|
435
|
+
this.timers.delete(transcript.runId);
|
|
436
|
+
void this.write(transcript);
|
|
437
|
+
}, FLUSH_INTERVAL_MS);
|
|
438
|
+
timer.unref?.();
|
|
439
|
+
this.timers.set(transcript.runId, timer);
|
|
440
|
+
}
|
|
441
|
+
clearTimer(runId) {
|
|
442
|
+
const timer = this.timers.get(runId);
|
|
443
|
+
if (timer)
|
|
444
|
+
clearTimeout(timer);
|
|
445
|
+
this.timers.delete(runId);
|
|
446
|
+
}
|
|
447
|
+
/** Writes of one run go one after another; different runs write in parallel. */
|
|
448
|
+
write(transcript) {
|
|
449
|
+
const name = transcriptFileName(transcript.runId);
|
|
450
|
+
if (!this.enabled || !name)
|
|
451
|
+
return Promise.resolve();
|
|
452
|
+
const runId = transcript.runId;
|
|
453
|
+
const previous = this.writes.get(runId) ?? Promise.resolve();
|
|
454
|
+
const next = previous.then(async () => {
|
|
455
|
+
if (!transcript.dirty)
|
|
456
|
+
return;
|
|
457
|
+
transcript.dirty = false;
|
|
458
|
+
const body = JSON.stringify(transcript.toFile());
|
|
459
|
+
await this.ensureDirectory();
|
|
460
|
+
const file = join(this.directory, name);
|
|
461
|
+
const temporary = `${file}.${process.pid}.tmp`;
|
|
462
|
+
await writeFile(temporary, body, { mode: 0o600 });
|
|
463
|
+
await rename(temporary, file);
|
|
464
|
+
this.cache.delete(runId);
|
|
465
|
+
}).catch((error) => {
|
|
466
|
+
// Retried with the next change or the final write.
|
|
467
|
+
transcript.dirty = true;
|
|
468
|
+
const details = { runId, error: errorMessage(error) };
|
|
469
|
+
if (this.warned)
|
|
470
|
+
this.logger.debug('run-transcript-write-failed', details);
|
|
471
|
+
else {
|
|
472
|
+
this.warned = true;
|
|
473
|
+
this.logger.warn('run-transcript-write-failed', details);
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
const tracked = next.finally(() => { if (this.writes.get(runId) === tracked)
|
|
477
|
+
this.writes.delete(runId); });
|
|
478
|
+
this.writes.set(runId, tracked);
|
|
479
|
+
return tracked;
|
|
480
|
+
}
|
|
481
|
+
async ensureDirectory() {
|
|
482
|
+
if (this.directoryReady)
|
|
483
|
+
return;
|
|
484
|
+
await mkdir(this.directory, { recursive: true, mode: 0o700 });
|
|
485
|
+
await chmod(this.directory, 0o700).catch(() => undefined);
|
|
486
|
+
this.directoryReady = true;
|
|
487
|
+
}
|
|
488
|
+
async pruneOnce() {
|
|
489
|
+
let names;
|
|
490
|
+
try {
|
|
491
|
+
names = await readdir(this.directory);
|
|
492
|
+
}
|
|
493
|
+
catch (error) {
|
|
494
|
+
if (errorCode(error) === 'ENOENT')
|
|
495
|
+
return;
|
|
496
|
+
throw error;
|
|
497
|
+
}
|
|
498
|
+
const now = Date.now();
|
|
499
|
+
const files = [];
|
|
500
|
+
for (const name of names) {
|
|
501
|
+
const path = join(this.directory, name);
|
|
502
|
+
if (name.endsWith('.tmp')) {
|
|
503
|
+
const info = await stat(path).catch(() => undefined);
|
|
504
|
+
if (info?.isFile() && now - info.mtimeMs > STALE_TEMPORARY_MS)
|
|
505
|
+
await unlink(path).catch(() => undefined);
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
if (!name.endsWith('.json'))
|
|
509
|
+
continue;
|
|
510
|
+
const info = await stat(path).catch(() => undefined);
|
|
511
|
+
if (info?.isFile())
|
|
512
|
+
files.push({ runId: name.slice(0, -'.json'.length), path, mtime: info.mtimeMs, size: info.size });
|
|
513
|
+
}
|
|
514
|
+
files.sort((a, b) => b.mtime - a.mtime);
|
|
515
|
+
let count = 0;
|
|
516
|
+
let bytes = 0;
|
|
517
|
+
let full = false;
|
|
518
|
+
for (const file of files) {
|
|
519
|
+
const live = this.tracked.has(file.runId) || this.writes.has(file.runId);
|
|
520
|
+
if (!live && (full || count + 1 > MAX_FILES || bytes + file.size > MAX_TOTAL_BYTES)) {
|
|
521
|
+
// Everything older than the first file over a limit goes too.
|
|
522
|
+
full = true;
|
|
523
|
+
await unlink(file.path).catch(() => undefined);
|
|
524
|
+
this.cache.delete(file.runId);
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
count += 1;
|
|
528
|
+
bytes += file.size;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
function clipText(text) {
|
|
533
|
+
return text.length > MAX_TRANSCRIPT_TEXT ? `${text.slice(0, MAX_TRANSCRIPT_TEXT)}…` : text;
|
|
534
|
+
}
|
|
535
|
+
function whole(value) {
|
|
536
|
+
return typeof value === 'number' && Number.isFinite(value) && value > 0 ? Math.floor(value) : 0;
|
|
537
|
+
}
|
|
538
|
+
function finite(value) {
|
|
539
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
540
|
+
}
|
|
541
|
+
function record(value) {
|
|
542
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
543
|
+
}
|
|
544
|
+
function errorCode(error) {
|
|
545
|
+
return error && typeof error === 'object' && 'code' in error ? String(error.code) : undefined;
|
|
546
|
+
}
|
|
547
|
+
function errorMessage(error) {
|
|
548
|
+
return error instanceof Error ? error.message : String(error);
|
|
549
|
+
}
|
|
550
|
+
//# sourceMappingURL=run-transcript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-transcript.js","sourceRoot":"","sources":["../../../src/runs/run-transcript.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACnG,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAIhC,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAA;AAE5E;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,CAAA;AACzC,6CAA6C;AAC7C,MAAM,CAAC,MAAM,mBAAmB,GAAG,OAAO,CAAA;AAC1C,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAA;AAC1C,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAA;AACxD,0DAA0D;AAC1D,MAAM,cAAc,GAAG,MAAM,CAAA;AAC7B,mFAAmF;AACnF,MAAM,eAAe,GAAG,IAAI,GAAG,IAAI,CAAA;AACnC,oFAAoF;AACpF,MAAM,eAAe,GAAG,GAAG,GAAG,IAAI,CAAA;AAClC,qEAAqE;AACrE,MAAM,sBAAsB,GAAG,KAAK,CAAA;AA6DpC,MAAM,OAAO,aAAa;IAC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;AAED,SAAS,KAAK,CAAC,KAAc;IAC3B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AACjG,CAAC;AAED,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAA;AAChF,CAAC;AAED,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAgC,CAAC,CAAC,CAAC,EAAE,CAAA;AAC5G,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,MAAM,CAAE,KAA2B,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AACtH,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IAClC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC/D,CAAC"}
|
|
@@ -3,7 +3,9 @@ import { join } from 'node:path';
|
|
|
3
3
|
import { executeScript } from '../exec/script-runner.js';
|
|
4
4
|
import { createDiagnosticLogger } from '../logging/diagnostic-log.js';
|
|
5
5
|
import { cliDetection } from '../providers/detection.js';
|
|
6
|
+
import { acpChatEnabled } from '../acp/chat-agents.js';
|
|
6
7
|
import { CHAT_PROVIDERS } from '../providers/chat/index.js';
|
|
8
|
+
import { handleMemoryProviderRequest, MEMORY_PROVIDER_IDS } from '../memory/providers.js';
|
|
7
9
|
import { ModelCatalogCollector } from '../providers/model-catalog-collector.js';
|
|
8
10
|
import { readCLIQuotaReport } from '../providers/quota-reader.js';
|
|
9
11
|
import { runSettingsFor } from '../providers/registry.js';
|
|
@@ -13,7 +15,7 @@ import { RunSupervisor } from '../runs/run-supervisor.js';
|
|
|
13
15
|
import { GatewayClient, GatewayError } from '../transport/gateway-client.js';
|
|
14
16
|
import { listDirectory } from '../workspace/directory-browser.js';
|
|
15
17
|
import { WorkspaceManager } from '../workspace/workspace-manager.js';
|
|
16
|
-
import { CliModelsPayloadSchema, CliQuotaPayloadSchema, CliProviderControlPayloadSchema, DEFAULT_POLICY, FsListPayloadSchema, WorkspaceScanPayloadSchema, WorkspaceSyncPayloadSchema, RunCancelPayloadSchema, RunGoalPayloadSchema, RunStartPayloadSchema, RunSteerPayloadSchema, RunTailPayloadSchema, ScriptRunPayloadSchema, SqlRunPayloadSchema } from '../types/protocol.js';
|
|
18
|
+
import { CliModelsPayloadSchema, CliQuotaPayloadSchema, CliProviderControlPayloadSchema, DEFAULT_POLICY, FsListPayloadSchema, WorkspaceScanPayloadSchema, WorkspaceSyncPayloadSchema, RunCancelPayloadSchema, RunGoalPayloadSchema, RunPermissionPayloadSchema, RunStartPayloadSchema, RunSteerPayloadSchema, RunTailPayloadSchema, RunTranscriptPayloadSchema, ScriptRunPayloadSchema, SqlRunPayloadSchema } from '../types/protocol.js';
|
|
17
19
|
const sleep = (ms, signal) => new Promise((resolve) => {
|
|
18
20
|
if (signal?.aborted) {
|
|
19
21
|
resolve();
|
|
@@ -243,9 +245,14 @@ export class AgentRuntime {
|
|
|
243
245
|
return { providers: [] };
|
|
244
246
|
return {
|
|
245
247
|
providers: snapshot.providers.map((p) => ({ id: p.id, installed: p.installed, runnable: p.available, version: p.version ?? '', path: p.resolvedPath ?? '' })),
|
|
246
|
-
// `acp`: chat turns run on a long-lived ACP agent per session; `steer`: `chat.run.steer` is understood
|
|
247
|
-
|
|
248
|
+
// `acp`: chat turns run on a long-lived ACP agent per session; `steer`: `chat.run.steer` is understood;
|
|
249
|
+
// `permission`: chat turns take `permission_mode` (incl. `default`) and wait for `chat.run.permission`.
|
|
250
|
+
cli_chat: { version: 1, providers: CHAT_PROVIDERS.filter(id => snapshot.detectedIds.includes(id)), features: ['acp', 'steer', ...(acpChatEnabled() ? ['permission'] : [])] },
|
|
248
251
|
task_attachments: { version: 1 },
|
|
252
|
+
// `run.transcript`: any run's structured items and run-log rows, kept on this device after the run.
|
|
253
|
+
run_transcripts: { version: 1 },
|
|
254
|
+
// `memory.provider` commands and the `memory` field of run payloads (Lody's memoryProviders v1).
|
|
255
|
+
memory_providers: { version: 1, providers: [...MEMORY_PROVIDER_IDS] },
|
|
249
256
|
cli_execution_policy: { version: 1, modes: ['restricted', 'full'] },
|
|
250
257
|
// Session permission level / plan / fast per installed CLI; the server shows only these.
|
|
251
258
|
run_settings: { version: 1, providers: Object.fromEntries(snapshot.detectedIds.flatMap((id) => {
|
|
@@ -340,6 +347,9 @@ export class AgentRuntime {
|
|
|
340
347
|
const cancelled = await this.runs.cancel(payload.run_id);
|
|
341
348
|
return { success: true, result: { cancelled } };
|
|
342
349
|
}
|
|
350
|
+
case 'memory.provider':
|
|
351
|
+
// Status, identities, enrollment and edits of a memory provider on this computer.
|
|
352
|
+
return { success: true, result: await handleMemoryProviderRequest(command.payload) };
|
|
343
353
|
case 'chat.run.steer': {
|
|
344
354
|
// `applied` / `queued`: the running turn has the message; `not-applied`:
|
|
345
355
|
// it never reached the CLI (the client sends it as the next turn);
|
|
@@ -348,6 +358,17 @@ export class AgentRuntime {
|
|
|
348
358
|
const outcome = await this.runs.steer(payload.run_id, payload.steer_id, payload.prompt);
|
|
349
359
|
return { success: true, result: { outcome } };
|
|
350
360
|
}
|
|
361
|
+
case 'chat.run.permission': {
|
|
362
|
+
// `resolved`: the CLI has the answer and the turn continues; `not-found`:
|
|
363
|
+
// no such open request (answered, cancelled, turn over); `invalid-option`:
|
|
364
|
+
// not one of the request's options (the request stays open).
|
|
365
|
+
const payload = RunPermissionPayloadSchema.parse(command.payload);
|
|
366
|
+
const { outcome: answer } = payload;
|
|
367
|
+
const outcome = this.runs.answerPermission(payload.run_id, payload.request_id, answer.outcome === 'selected'
|
|
368
|
+
? { outcome: 'selected', optionId: answer.optionId, ...(answer._meta ? { _meta: answer._meta } : {}) }
|
|
369
|
+
: { outcome: 'cancelled' });
|
|
370
|
+
return { success: true, result: { outcome } };
|
|
371
|
+
}
|
|
351
372
|
case 'run.goal': {
|
|
352
373
|
const payload = RunGoalPayloadSchema.parse(command.payload);
|
|
353
374
|
return { success: true, result: { applied: this.runs.controlGoal(payload.run_id, payload.action) } };
|
|
@@ -357,6 +378,16 @@ export class AgentRuntime {
|
|
|
357
378
|
const tail = this.runs.tail({ ...(payload.run_id ? { runId: payload.run_id } : {}), ...(payload.task_chain_id ? { taskChainId: payload.task_chain_id } : {}) }, payload.lines ?? 200, payload.before_cursor);
|
|
358
379
|
return { success: true, result: tail };
|
|
359
380
|
}
|
|
381
|
+
case 'run.transcript': {
|
|
382
|
+
// Structured items and run-log rows of any run this device still has (memory, then disk).
|
|
383
|
+
const payload = RunTranscriptPayloadSchema.parse(command.payload);
|
|
384
|
+
const transcript = await this.runs.transcript(payload.run_id, {
|
|
385
|
+
...(payload.since !== undefined ? { since: payload.since } : {}),
|
|
386
|
+
...(payload.item_from !== undefined ? { item_from: payload.item_from } : {}),
|
|
387
|
+
...(payload.line_from !== undefined ? { line_from: payload.line_from } : {})
|
|
388
|
+
});
|
|
389
|
+
return { success: true, result: transcript };
|
|
390
|
+
}
|
|
360
391
|
case 'cli.detect':
|
|
361
392
|
this.detection = await cliDetection.detect(true);
|
|
362
393
|
void this.refreshCatalogs({ force: true });
|