@orion-agents/orion-code 0.4.8 → 0.4.9
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/CHANGELOG.md +8 -0
- package/README.md +5 -5
- package/README.zh-CN.md +5 -5
- package/dist/cli.js +42 -3
- package/dist/commands/session-command-handlers.js +8 -3
- package/dist/commands/system-commands.js +3 -3
- package/dist/commands/types.d.ts +3 -0
- package/dist/framework/loop-progress.js +3 -1
- package/dist/framework/query.d.ts +3 -1
- package/dist/framework/query.js +18 -3
- package/dist/framework/tool-serializer.d.ts +12 -0
- package/dist/framework/tool-serializer.js +35 -0
- package/dist/framework/tool.d.ts +2 -0
- package/dist/harness/ledger.js +2 -1
- package/dist/print-ui/delivery.d.ts +15 -0
- package/dist/print-ui/delivery.js +131 -0
- package/dist/print-ui/event-stream.d.ts +6 -1
- package/dist/print-ui/event-stream.js +56 -10
- package/dist/print-ui/launch.d.ts +5 -0
- package/dist/print-ui/launch.js +66 -9
- package/dist/runtime/agent-loop.d.ts +3 -1
- package/dist/runtime/agent-loop.js +20 -8
- package/dist/runtime/agent-runtime-controller.d.ts +4 -1
- package/dist/runtime/agent-runtime-controller.js +36 -22
- package/dist/runtime/agent-runtime-runner.d.ts +4 -0
- package/dist/runtime/agent-runtime-runner.js +9 -0
- package/dist/runtime/builtin-tool-provider.js +6 -5
- package/dist/runtime/composer/layout.d.ts +1 -1
- package/dist/runtime/composer/layout.js +5 -5
- package/dist/runtime/core-tools/descriptors.d.ts +1 -1
- package/dist/runtime/core-tools/descriptors.js +39 -1
- package/dist/runtime/first-party-core-provider.js +1 -0
- package/dist/runtime/first-party-tool-services.js +10 -0
- package/dist/runtime/goals/evidence.js +2 -0
- package/dist/runtime/legacy-thread-materializer.d.ts +7 -0
- package/dist/runtime/legacy-thread-materializer.js +32 -6
- package/dist/runtime/orion-runtime-v1.d.ts +2 -1
- package/dist/runtime/orion-runtime-v1.js +1 -0
- package/dist/runtime/product-bootstrap.d.ts +2 -0
- package/dist/runtime/product-bootstrap.js +1 -0
- package/dist/runtime/product-orion-runtime.d.ts +2 -1
- package/dist/runtime/product-orion-runtime.js +1 -0
- package/dist/runtime/rich-text/layout.d.ts +3 -1
- package/dist/runtime/rich-text/layout.js +37 -22
- package/dist/runtime/shell-process-sessions.d.ts +41 -0
- package/dist/runtime/shell-process-sessions.js +258 -0
- package/dist/runtime/step-snapshot.js +4 -1
- package/dist/runtime/subagents/presets.d.ts +1 -1
- package/dist/runtime/subagents/presets.js +1 -0
- package/dist/runtime/task-context-recovery.js +7 -0
- package/dist/runtime/thread-event-store.d.ts +3 -0
- package/dist/runtime/thread-event-store.js +35 -22
- package/dist/runtime/thread-session-index.d.ts +15 -3
- package/dist/runtime/thread-session-index.js +152 -45
- package/dist/runtime/thread-session-view.js +1 -1
- package/dist/runtime/thread-ui-adapter.d.ts +1 -1
- package/dist/runtime/thread-ui-adapter.js +14 -8
- package/dist/runtime/tool-gateway.d.ts +1 -0
- package/dist/runtime/tool-gateway.js +1 -0
- package/dist/runtime/tool-transcript-entry.d.ts +8 -1
- package/dist/runtime/tool-transcript-entry.js +35 -7
- package/dist/runtime/ui-events.d.ts +7 -0
- package/dist/services/global-config.d.ts +1 -1
- package/dist/services/global-config.js +2 -0
- package/dist/services/llm.d.ts +3 -0
- package/dist/services/llm.js +48 -4
- package/dist/terminal-ui/raw-editor.js +2 -1
- package/dist/tools/core/exec-command.js +51 -42
- package/dist/tools/core/index.d.ts +2 -1
- package/dist/tools/core/index.js +4 -1
- package/dist/tools/core/process-session.d.ts +2 -0
- package/dist/tools/core/process-session.js +54 -0
- package/dist/tui-core/frame.d.ts +2 -0
- package/dist/tui-core/frame.js +19 -0
- package/dist/tui-core/input-parser.d.ts +4 -1
- package/dist/tui-core/input-parser.js +22 -0
- package/dist/tui-ui/chrome-view-model.d.ts +0 -2
- package/dist/tui-ui/chrome-view-model.js +54 -56
- package/dist/tui-ui/launch.js +133 -202
- package/dist/tui-ui/layout.d.ts +16 -41
- package/dist/tui-ui/layout.js +408 -295
- package/dist/tui-ui/render-scheduler.d.ts +2 -5
- package/dist/tui-ui/render-scheduler.js +10 -10
- package/dist/tui-ui/response-clipboard.d.ts +17 -0
- package/dist/tui-ui/response-clipboard.js +201 -0
- package/dist/tui-ui/runner.d.ts +65 -80
- package/dist/tui-ui/runner.js +545 -738
- package/dist/tui-ui/session-picker-preview.d.ts +8 -0
- package/dist/tui-ui/session-picker-preview.js +119 -0
- package/dist/tui-ui/session-picker.d.ts +20 -0
- package/dist/tui-ui/session-picker.js +42 -0
- package/dist/tui-ui/state.d.ts +34 -81
- package/dist/tui-ui/state.js +155 -288
- package/dist/tui-ui/terminal-image.d.ts +3 -7
- package/dist/tui-ui/terminal-image.js +18 -47
- package/dist/tui-ui/terminal-viewport.d.ts +55 -0
- package/dist/tui-ui/terminal-viewport.js +221 -0
- package/dist/tui-ui/transcript-layout.d.ts +5 -0
- package/dist/tui-ui/transcript-layout.js +43 -28
- package/dist/tui-ui/transcript-pager.d.ts +39 -0
- package/dist/tui-ui/transcript-pager.js +278 -0
- package/dist/tui-ui/transcript-tool-output.d.ts +16 -0
- package/dist/tui-ui/transcript-tool-output.js +102 -0
- package/dist/utils/bounded-file.d.ts +4 -0
- package/dist/utils/bounded-file.js +30 -0
- package/dist/utils/command-process.d.ts +4 -0
- package/dist/utils/command-process.js +23 -0
- package/docs/cli-guide.md +50 -6
- package/npm-shrinkwrap.json +115 -15
- package/package.json +4 -1
- package/dist/tui-ui/inline-surface.d.ts +0 -191
- package/dist/tui-ui/inline-surface.js +0 -644
- package/dist/tui-ui/input-ownership.d.ts +0 -46
- package/dist/tui-ui/input-ownership.js +0 -74
- package/dist/tui-ui/transcript-inspector-layout.d.ts +0 -9
- package/dist/tui-ui/transcript-inspector-layout.js +0 -107
- package/dist/tui-ui/transcript-inspector-surface.d.ts +0 -18
- package/dist/tui-ui/transcript-inspector-surface.js +0 -91
- package/dist/tui-ui/transcript-inspector.d.ts +0 -36
- package/dist/tui-ui/transcript-inspector.js +0 -129
|
@@ -11,8 +11,11 @@ exports.projectTranscriptMessages = projectTranscriptMessages;
|
|
|
11
11
|
const fs_1 = require("fs");
|
|
12
12
|
const path_1 = require("path");
|
|
13
13
|
const atomic_write_1 = require("../services/atomic-write");
|
|
14
|
+
const bounded_file_1 = require("../utils/bounded-file");
|
|
15
|
+
const terminal_text_1 = require("../utils/terminal-text");
|
|
14
16
|
const canonical_1 = require("./protocol/canonical");
|
|
15
17
|
const tool_transcript_entry_1 = require("./tool-transcript-entry");
|
|
18
|
+
const tool_receipt_validator_1 = require("./tool-receipt-validator");
|
|
16
19
|
const TRANSCRIPT_PAGE_ITEMS = 100;
|
|
17
20
|
const MAX_MANIFEST_PAGES = 100000;
|
|
18
21
|
const threadSessionIndexPerformance = {
|
|
@@ -26,52 +29,148 @@ function threadSessionIndexPerformanceCountersV1() {
|
|
|
26
29
|
return Object.freeze({ ...threadSessionIndexPerformance });
|
|
27
30
|
}
|
|
28
31
|
exports.RESUME_TRANSCRIPT_WINDOW_MESSAGES = 50;
|
|
29
|
-
/** UI-only window
|
|
30
|
-
function projectThreadResumeDisplay(items) {
|
|
32
|
+
/** UI-only window and lazy history pages. Model recovery uses its own durable history. */
|
|
33
|
+
function projectThreadResumeDisplay(items, events = []) {
|
|
31
34
|
const ordered = Object.values(items)
|
|
32
35
|
.filter(item => {
|
|
33
36
|
if (item.status === 'started')
|
|
34
37
|
return false;
|
|
35
38
|
return ((item.kind === 'message' && isMessageRole(item.role)) ||
|
|
36
39
|
item.kind === 'reasoning' ||
|
|
40
|
+
item.kind === 'plan' ||
|
|
37
41
|
(0, tool_transcript_entry_1.isToolTranscriptItem)(item.kind));
|
|
38
42
|
})
|
|
39
43
|
.sort((left, right) => left.startedSeq - right.startedSeq);
|
|
44
|
+
const readBefore = cursor => {
|
|
45
|
+
if (!Number.isSafeInteger(cursor) || cursor < 0 || cursor > ordered.length) {
|
|
46
|
+
throw new RangeError('Transcript history cursor is outside the restored snapshot.');
|
|
47
|
+
}
|
|
48
|
+
const before = Math.max(0, cursor - exports.RESUME_TRANSCRIPT_WINDOW_MESSAGES);
|
|
49
|
+
const entries = ordered
|
|
50
|
+
.slice(before, cursor)
|
|
51
|
+
.map(item => projectResumeTranscriptEntry(item, events));
|
|
52
|
+
return { entries, before };
|
|
53
|
+
};
|
|
54
|
+
const { entries, before } = readBefore(ordered.length);
|
|
55
|
+
const latestCompletedReply = findLatestCompletedReply(ordered);
|
|
40
56
|
return {
|
|
41
57
|
totalEntries: ordered.length,
|
|
42
|
-
entries
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
...(role === 'user' ? { title: 'you' } : {}),
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
if (item.kind === 'reasoning') {
|
|
54
|
-
return {
|
|
55
|
-
id: item.itemId,
|
|
56
|
-
role: 'assistant',
|
|
57
|
-
title: 'reasoning',
|
|
58
|
-
content: item.content ?? item.summary ?? '',
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
id: item.itemId,
|
|
63
|
-
...(0, tool_transcript_entry_1.toolTranscriptEntry)({
|
|
64
|
-
name: item.name ?? item.kind,
|
|
65
|
-
callId: item.itemId,
|
|
66
|
-
sequence: item.startedSeq,
|
|
67
|
-
success: item.status === 'completed',
|
|
68
|
-
command: (0, tool_transcript_entry_1.toolCommandFromIntent)(item.intent),
|
|
69
|
-
output: item.summary ?? item.error,
|
|
58
|
+
entries,
|
|
59
|
+
...(ordered.length > 0
|
|
60
|
+
? {
|
|
61
|
+
historySource: Object.freeze({
|
|
62
|
+
before,
|
|
63
|
+
recentEntries: entries,
|
|
64
|
+
readBefore,
|
|
65
|
+
latestCompletedReply,
|
|
70
66
|
}),
|
|
71
|
-
}
|
|
67
|
+
}
|
|
68
|
+
: {}),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function findLatestCompletedReply(items) {
|
|
72
|
+
let latest;
|
|
73
|
+
for (let index = items.length - 1; index >= 0; index -= 1) {
|
|
74
|
+
const item = items[index];
|
|
75
|
+
if (item.status !== 'completed' ||
|
|
76
|
+
(item.kind !== 'plan' && (item.kind !== 'message' || item.role !== 'assistant'))) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const sequence = item.terminalSeq ?? item.startedSeq;
|
|
80
|
+
if (latest && sequence <= latest.sequence)
|
|
81
|
+
continue;
|
|
82
|
+
const legacy = item.kind === 'message' ? parseLegacyTranscriptReceipt(item.receipt) : undefined;
|
|
83
|
+
if (legacy && legacy.role !== 'assistant')
|
|
84
|
+
continue;
|
|
85
|
+
const content = legacy?.content ?? item.content ?? item.summary ?? '';
|
|
86
|
+
if ((0, terminal_text_1.hasVisibleAssistantText)(content))
|
|
87
|
+
latest = { sequence, content };
|
|
88
|
+
}
|
|
89
|
+
return latest?.content;
|
|
90
|
+
}
|
|
91
|
+
function projectResumeTranscriptEntry(item, events) {
|
|
92
|
+
const failure = item.status !== 'completed';
|
|
93
|
+
const failurePresentation = failure ? { errorLayer: 'runtime' } : {};
|
|
94
|
+
if (item.kind === 'message') {
|
|
95
|
+
const legacy = parseLegacyTranscriptReceipt(item.receipt);
|
|
96
|
+
const role = legacy?.role ?? item.role;
|
|
97
|
+
const source = legacy?.content ?? item.content ?? item.summary ?? item.error ?? '';
|
|
98
|
+
return {
|
|
99
|
+
id: item.itemId,
|
|
100
|
+
role,
|
|
101
|
+
content: failure ? item.error || source : source,
|
|
102
|
+
...(role === 'user' ? { title: 'you' } : {}),
|
|
103
|
+
...failurePresentation,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
if (item.kind === 'reasoning' || item.kind === 'plan') {
|
|
107
|
+
return {
|
|
108
|
+
id: item.itemId,
|
|
109
|
+
role: 'assistant',
|
|
110
|
+
title: item.kind,
|
|
111
|
+
content: item.content ?? item.summary ?? '',
|
|
112
|
+
...failurePresentation,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
const receipt = restoredToolReceipt(item, events);
|
|
116
|
+
return {
|
|
117
|
+
id: item.itemId,
|
|
118
|
+
...(0, tool_transcript_entry_1.toolTranscriptEntry)({
|
|
119
|
+
name: item.name ?? item.kind,
|
|
120
|
+
callId: item.itemId,
|
|
121
|
+
turnId: item.turnId,
|
|
122
|
+
sequence: item.startedSeq,
|
|
123
|
+
success: receipt?.success ?? !failure,
|
|
124
|
+
command: (0, tool_transcript_entry_1.toolCommandFromIntent)(item.intent),
|
|
125
|
+
output: item.summary ?? item.error,
|
|
126
|
+
historyOutput: item.content || receipt?.result.output || item.summary || item.error,
|
|
127
|
+
artifactRef: receipt?.result.artifactRef,
|
|
72
128
|
}),
|
|
73
129
|
};
|
|
74
130
|
}
|
|
131
|
+
function resumeEventAt(events, sequence) {
|
|
132
|
+
const candidate = events[sequence - 1];
|
|
133
|
+
if (candidate?.seq === sequence)
|
|
134
|
+
return candidate;
|
|
135
|
+
// The captured replay is contiguous. A caller may also pass an ordered subset.
|
|
136
|
+
let first = 0;
|
|
137
|
+
let last = events.length - 1;
|
|
138
|
+
while (first <= last) {
|
|
139
|
+
const index = Math.floor((first + last) / 2);
|
|
140
|
+
const event = events[index];
|
|
141
|
+
if (event.seq === sequence)
|
|
142
|
+
return event;
|
|
143
|
+
if (event.seq < sequence) {
|
|
144
|
+
first = index + 1;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
last = index - 1;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
function restoredToolReceipt(item, events) {
|
|
153
|
+
const sequence = item.terminalSeq;
|
|
154
|
+
if (sequence === undefined || !item.receipt || !item.name)
|
|
155
|
+
return undefined;
|
|
156
|
+
const terminalEvent = resumeEventAt(events, sequence);
|
|
157
|
+
const factEvent = resumeEventAt(events, sequence - 1);
|
|
158
|
+
if (!terminalEvent || !factEvent)
|
|
159
|
+
return undefined;
|
|
160
|
+
try {
|
|
161
|
+
return (0, tool_receipt_validator_1.validateDurableToolInvocationReceiptV1)({
|
|
162
|
+
terminalEvent,
|
|
163
|
+
factEvent,
|
|
164
|
+
item: { itemId: item.itemId, toolName: item.name },
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
if (!(error instanceof tool_receipt_validator_1.DurableToolReceiptValidationError))
|
|
169
|
+
throw error;
|
|
170
|
+
// The bounded transcript can still show the projected summary without the unverified reference.
|
|
171
|
+
return undefined;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
75
174
|
class ThreadSessionIndexError extends Error {
|
|
76
175
|
constructor(code, message) {
|
|
77
176
|
super(message);
|
|
@@ -162,8 +261,8 @@ function advanceThreadSessionIndexV1(input) {
|
|
|
162
261
|
writeManifest(input.rootDir, manifest);
|
|
163
262
|
return true;
|
|
164
263
|
}
|
|
165
|
-
function loadThreadSessionIndexManifestV1(rootDir, threadId, head) {
|
|
166
|
-
const manifest = readManifest(manifestPath(rootDir, threadId), threadId);
|
|
264
|
+
function loadThreadSessionIndexManifestV1(rootDir, threadId, head, maxFileBytes) {
|
|
265
|
+
const manifest = readManifest(manifestPath(rootDir, threadId), threadId, maxFileBytes);
|
|
167
266
|
return manifest && manifestMatchesHead(manifest, head) ? manifest : undefined;
|
|
168
267
|
}
|
|
169
268
|
function loadThreadSessionIndexedPageV1(input) {
|
|
@@ -171,7 +270,7 @@ function loadThreadSessionIndexedPageV1(input) {
|
|
|
171
270
|
if (!Number.isSafeInteger(pageSize) || pageSize < 1 || pageSize > TRANSCRIPT_PAGE_ITEMS) {
|
|
172
271
|
throw new ThreadSessionIndexError('ORION_THREAD_SESSION_CURSOR_INVALID', 'Transcript pageSize must be an integer from 1 through 100.');
|
|
173
272
|
}
|
|
174
|
-
const manifest = loadThreadSessionIndexManifestV1(input.rootDir, input.threadId, input.head);
|
|
273
|
+
const manifest = loadThreadSessionIndexManifestV1(input.rootDir, input.threadId, input.head, input.maxFileBytes);
|
|
175
274
|
if (!manifest)
|
|
176
275
|
return undefined;
|
|
177
276
|
const end = input.cursor ? decodeCursor(input.cursor, manifest) : manifest.messageCount;
|
|
@@ -180,7 +279,7 @@ function loadThreadSessionIndexedPageV1(input) {
|
|
|
180
279
|
for (const pointer of manifest.pages) {
|
|
181
280
|
if (pointer.end <= offset || pointer.start >= end)
|
|
182
281
|
continue;
|
|
183
|
-
const page = readPage(input.rootDir, input.threadId, pointer);
|
|
282
|
+
const page = readPage(input.rootDir, input.threadId, pointer, input.maxFileBytes);
|
|
184
283
|
const from = Math.max(offset, pointer.start) - pointer.start;
|
|
185
284
|
const to = Math.min(end, pointer.end) - pointer.start;
|
|
186
285
|
items.push(...page.items.slice(from, to));
|
|
@@ -302,8 +401,8 @@ function writeManifest(rootDir, manifest) {
|
|
|
302
401
|
(0, atomic_write_1.atomicWriteFileSync)(manifestPath(rootDir, manifest.threadId), `${(0, canonical_1.canonicalRuntimeJson)(manifest)}\n`, { mode: 0o600, fsync: true });
|
|
303
402
|
fsyncDirectory(rootDir);
|
|
304
403
|
}
|
|
305
|
-
function readManifest(path, threadId) {
|
|
306
|
-
const value = readRegularJson(path, 'manifest');
|
|
404
|
+
function readManifest(path, threadId, maxFileBytes) {
|
|
405
|
+
const value = readRegularJson(path, 'manifest', maxFileBytes);
|
|
307
406
|
if (!isRecord(value))
|
|
308
407
|
return null;
|
|
309
408
|
const { digest: _digest, ...content } = value;
|
|
@@ -371,10 +470,10 @@ function isLatestTurn(value) {
|
|
|
371
470
|
positiveSafeInteger(value.startedSeq) &&
|
|
372
471
|
(value.terminalSeq === undefined || positiveSafeInteger(value.terminalSeq)));
|
|
373
472
|
}
|
|
374
|
-
function readPage(rootDir, threadId, pointer) {
|
|
473
|
+
function readPage(rootDir, threadId, pointer, maxFileBytes) {
|
|
375
474
|
if ((0, path_1.basename)(pointer.file) !== pointer.file)
|
|
376
475
|
throw indexCorrupt('Transcript page path escaped.');
|
|
377
|
-
const page = readStoredPage((0, path_1.join)(pagesDir(rootDir, threadId), pointer.file), threadId);
|
|
476
|
+
const page = readStoredPage((0, path_1.join)(pagesDir(rootDir, threadId), pointer.file), threadId, maxFileBytes);
|
|
378
477
|
if (!page ||
|
|
379
478
|
page.start !== pointer.start ||
|
|
380
479
|
page.end !== pointer.end ||
|
|
@@ -383,8 +482,8 @@ function readPage(rootDir, threadId, pointer) {
|
|
|
383
482
|
}
|
|
384
483
|
return page;
|
|
385
484
|
}
|
|
386
|
-
function readStoredPage(path, threadId) {
|
|
387
|
-
const value = readRegularJson(path, 'page');
|
|
485
|
+
function readStoredPage(path, threadId, maxFileBytes) {
|
|
486
|
+
const value = readRegularJson(path, 'page', maxFileBytes);
|
|
388
487
|
if (!isRecord(value))
|
|
389
488
|
return null;
|
|
390
489
|
const { digest: _digest, ...content } = value;
|
|
@@ -561,13 +660,21 @@ function isItemTerminalEvent(event) {
|
|
|
561
660
|
function isMessageRole(value) {
|
|
562
661
|
return value === 'system' || value === 'user' || value === 'assistant' || value === 'tool';
|
|
563
662
|
}
|
|
564
|
-
function readRegularJson(path, kind) {
|
|
663
|
+
function readRegularJson(path, kind, maxFileBytes) {
|
|
565
664
|
let fd;
|
|
566
665
|
try {
|
|
567
|
-
|
|
568
|
-
if (
|
|
666
|
+
let bytes;
|
|
667
|
+
if (maxFileBytes === undefined) {
|
|
668
|
+
fd = (0, fs_1.openSync)(path, fs_1.constants.O_RDONLY | (typeof fs_1.constants.O_NOFOLLOW === 'number' ? fs_1.constants.O_NOFOLLOW : 0));
|
|
669
|
+
if (!(0, fs_1.fstatSync)(fd).isFile())
|
|
670
|
+
return undefined;
|
|
671
|
+
bytes = (0, fs_1.readFileSync)(fd);
|
|
672
|
+
}
|
|
673
|
+
else {
|
|
674
|
+
bytes = (0, bounded_file_1.readBoundedRegularFileSync)(path, maxFileBytes);
|
|
675
|
+
}
|
|
676
|
+
if (!bytes)
|
|
569
677
|
return undefined;
|
|
570
|
-
const bytes = (0, fs_1.readFileSync)(fd);
|
|
571
678
|
threadSessionIndexPerformance.bytesRead += bytes.byteLength;
|
|
572
679
|
if (kind === 'manifest')
|
|
573
680
|
threadSessionIndexPerformance.manifestReads += 1;
|
|
@@ -203,7 +203,7 @@ function captureThreadSessionV1(projectPath, sessionId, includeDurableHistory) {
|
|
|
203
203
|
}),
|
|
204
204
|
durableHistory,
|
|
205
205
|
...(includeDurableHistory
|
|
206
|
-
? { resumeDisplay: (0, thread_session_index_1.projectThreadResumeDisplay)(projection.items) }
|
|
206
|
+
? { resumeDisplay: (0, thread_session_index_1.projectThreadResumeDisplay)(projection.items, events) }
|
|
207
207
|
: {}),
|
|
208
208
|
store,
|
|
209
209
|
cutoverGeneration: resolution.generation,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type AgentRuntimeRunnerV1, type AgentRuntimeRunInputOptionsV1 } from './agent-runtime-runner';
|
|
2
2
|
import { type AgentRuntimeEventSink } from './agent-runtime-protocol';
|
|
3
3
|
import type { AgentTurnRequest } from './goals/types';
|
|
4
4
|
import type { RuntimeEventBufferOptionsV1 } from './runtime-event-buffer';
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ThreadUiAdmissionError = exports.ThreadUiAdapterError = exports.ThreadUiAdapterV1 = exports.THREAD_UI_ADAPTER_VERSION = void 0;
|
|
4
4
|
const verification_command_1 = require("../framework/verification-command");
|
|
5
|
+
const agent_runtime_runner_1 = require("./agent-runtime-runner");
|
|
5
6
|
const agent_runtime_protocol_1 = require("./agent-runtime-protocol");
|
|
6
7
|
const goal_runtime_coordinator_1 = require("./goal-runtime-coordinator");
|
|
7
8
|
const runtime_protocol_v1_1 = require("./protocol/runtime-protocol-v1");
|
|
@@ -163,7 +164,7 @@ class ThreadUiAdapterV1 {
|
|
|
163
164
|
this.assertOpen();
|
|
164
165
|
throwIfAborted(signal);
|
|
165
166
|
if (!pending.isPending())
|
|
166
|
-
throw new
|
|
167
|
+
throw new agent_runtime_runner_1.PendingFollowupChangedError();
|
|
167
168
|
return this.runtime.startPendingFollowup(pending.id, input, mode);
|
|
168
169
|
}
|
|
169
170
|
async waitForIdleAndFlush() {
|
|
@@ -458,6 +459,7 @@ class ThreadUiAdapterV1 {
|
|
|
458
459
|
}
|
|
459
460
|
this.toolReceiptFacts.delete(presentation.itemId);
|
|
460
461
|
const success = receipt?.success ?? event.payload.type === 'item.completed';
|
|
462
|
+
const output = presentation.content || terminal.error;
|
|
461
463
|
const verification = receipt?.toolName === 'exec_command'
|
|
462
464
|
? (0, verification_command_1.verificationToolStatus)(receipt.result.metadata?.verification)
|
|
463
465
|
: undefined;
|
|
@@ -477,9 +479,12 @@ class ThreadUiAdapterV1 {
|
|
|
477
479
|
...(terminal.summary ? { summary: terminal.summary } : {}),
|
|
478
480
|
...(terminal.error ? { error: terminal.error } : {}),
|
|
479
481
|
...(verification ? { verification } : {}),
|
|
480
|
-
...(
|
|
481
|
-
|
|
482
|
-
:
|
|
482
|
+
...(receipt?.result.artifactRef ? { artifactRef: receipt.result.artifactRef } : {}),
|
|
483
|
+
...(receipt?.result.outputBytes !== undefined
|
|
484
|
+
? { outputBytes: receipt.result.outputBytes }
|
|
485
|
+
: presentation.content
|
|
486
|
+
? { outputBytes: Buffer.byteLength(presentation.content, 'utf8') }
|
|
487
|
+
: {}),
|
|
483
488
|
...(receipt
|
|
484
489
|
? {
|
|
485
490
|
authorization: projectToolAuthorization(receipt),
|
|
@@ -494,15 +499,16 @@ class ThreadUiAdapterV1 {
|
|
|
494
499
|
entry: {
|
|
495
500
|
...(0, tool_transcript_entry_1.toolTranscriptEntry)({
|
|
496
501
|
callId: presentation.itemId,
|
|
502
|
+
turnId: event.turnId,
|
|
497
503
|
sequence: presentation.sequence,
|
|
498
504
|
name: presentation.name,
|
|
499
505
|
success,
|
|
500
506
|
command: presentation.command,
|
|
501
507
|
output: verificationNote
|
|
502
|
-
? [
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
508
|
+
? [output, verificationNote].filter(Boolean).join('\n')
|
|
509
|
+
: output,
|
|
510
|
+
historyOutput: receipt?.result.output || output,
|
|
511
|
+
artifactRef: receipt?.result.artifactRef,
|
|
506
512
|
}),
|
|
507
513
|
live: false,
|
|
508
514
|
},
|
|
@@ -55,6 +55,7 @@ export interface SandboxServiceV1 {
|
|
|
55
55
|
readonly snapshot: StepSnapshotV1;
|
|
56
56
|
readonly descriptor: ToolBindingDescriptorV1;
|
|
57
57
|
readonly args: Readonly<Record<string, unknown>>;
|
|
58
|
+
readonly context?: ToolContext;
|
|
58
59
|
readonly abortSignal?: AbortSignal;
|
|
59
60
|
}): Promise<SandboxPreparationV1> | SandboxPreparationV1;
|
|
60
61
|
}
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import type { TranscriptAppendEntry } from './ui-events';
|
|
2
|
+
export declare const MAX_TOOL_TRANSCRIPT_OUTPUT_BYTES: number;
|
|
2
3
|
/** Bounded display text only. Credential-bearing invocations retain the tool name. */
|
|
3
4
|
export declare function toolCommandForDisplay(command: unknown): string | undefined;
|
|
4
5
|
/** Read the optional display label in a durable intent; older records have none. */
|
|
5
6
|
export declare function toolCommandFromIntent(intent: string | undefined): string | undefined;
|
|
6
7
|
export declare function isToolTranscriptItem(kind: string): boolean;
|
|
7
|
-
/** A
|
|
8
|
+
/** A compact chat row with a separate, bounded source for expanded history. */
|
|
8
9
|
export declare function toolTranscriptEntry(input: {
|
|
9
10
|
callId: string;
|
|
11
|
+
turnId?: string;
|
|
10
12
|
sequence: number;
|
|
11
13
|
name: string;
|
|
12
14
|
success: boolean;
|
|
13
15
|
command?: string;
|
|
14
16
|
output?: string;
|
|
17
|
+
historyOutput?: string;
|
|
18
|
+
artifactRef?: {
|
|
19
|
+
id: string;
|
|
20
|
+
outputBytes: number;
|
|
21
|
+
};
|
|
15
22
|
}): TranscriptAppendEntry;
|
|
16
23
|
//# sourceMappingURL=tool-transcript-entry.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MAX_TOOL_TRANSCRIPT_OUTPUT_BYTES = void 0;
|
|
3
4
|
exports.toolCommandForDisplay = toolCommandForDisplay;
|
|
4
5
|
exports.toolCommandFromIntent = toolCommandFromIntent;
|
|
5
6
|
exports.isToolTranscriptItem = isToolTranscriptItem;
|
|
@@ -7,6 +8,8 @@ exports.toolTranscriptEntry = toolTranscriptEntry;
|
|
|
7
8
|
const redaction_1 = require("../services/redaction");
|
|
8
9
|
const style_1 = require("../tui-core/style");
|
|
9
10
|
const SENSITIVE_COMMAND_ARGUMENT = /(?:^|\s)--(?:password|passphrase|token|api[-_]?key|secret|authorization|cookie|credentials?)(?:[=\s]|$)/iu;
|
|
11
|
+
exports.MAX_TOOL_TRANSCRIPT_OUTPUT_BYTES = 64 * 1024;
|
|
12
|
+
const TRANSCRIPT_OMISSION = '\n… tool output omitted …\n';
|
|
10
13
|
/** Bounded display text only. Credential-bearing invocations retain the tool name. */
|
|
11
14
|
function toolCommandForDisplay(command) {
|
|
12
15
|
if (typeof command !== 'string')
|
|
@@ -37,17 +40,20 @@ function toolCommandFromIntent(intent) {
|
|
|
37
40
|
function isToolTranscriptItem(kind) {
|
|
38
41
|
return kind === 'command' || kind === 'file_change' || kind === 'mcp';
|
|
39
42
|
}
|
|
40
|
-
/** A
|
|
43
|
+
/** A compact chat row with a separate, bounded source for expanded history. */
|
|
41
44
|
function toolTranscriptEntry(input) {
|
|
42
45
|
const name = /^[A-Za-z0-9_.:/-]{1,120}$/u.test(input.name) ? input.name : 'tool';
|
|
43
46
|
const command = toolCommandForDisplay(input.command);
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
:
|
|
47
|
+
const displayOutput = input.command === undefined || command !== undefined;
|
|
48
|
+
const compactOutput = command && input.output ? sanitizeToolOutput(input.output) : '';
|
|
49
|
+
const history = displayOutput ? (input.historyOutput ?? input.output) : undefined;
|
|
50
|
+
const transcriptOutput = history
|
|
51
|
+
? boundToolTranscriptOutput(command && history === input.output ? compactOutput : sanitizeToolOutput(history))
|
|
52
|
+
: undefined;
|
|
49
53
|
// Prefer the final lines, where test runners usually print their verdict.
|
|
50
|
-
const body =
|
|
54
|
+
const body = compactOutput
|
|
55
|
+
.split('\n')
|
|
56
|
+
.filter(line => line.trim())
|
|
51
57
|
.slice(-2)
|
|
52
58
|
.map(line => clipDisplayText(line, 120))
|
|
53
59
|
.join('\n');
|
|
@@ -61,11 +67,33 @@ function toolTranscriptEntry(input) {
|
|
|
61
67
|
detail: '',
|
|
62
68
|
...(command ? { command } : {}),
|
|
63
69
|
body,
|
|
70
|
+
...(transcriptOutput ? { transcriptOutput } : {}),
|
|
71
|
+
...(displayOutput && input.artifactRef ? { artifactRef: { ...input.artifactRef } } : {}),
|
|
64
72
|
callId: input.callId,
|
|
73
|
+
...(input.turnId ? { turnId: input.turnId } : {}),
|
|
65
74
|
seq: input.sequence,
|
|
66
75
|
},
|
|
67
76
|
};
|
|
68
77
|
}
|
|
78
|
+
function sanitizeToolOutput(text) {
|
|
79
|
+
return (0, redaction_1.redactTraceText)((0, style_1.sanitizeTerminalText)(text));
|
|
80
|
+
}
|
|
81
|
+
function boundToolTranscriptOutput(text) {
|
|
82
|
+
if (Buffer.byteLength(text, 'utf8') <= exports.MAX_TOOL_TRANSCRIPT_OUTPUT_BYTES)
|
|
83
|
+
return text;
|
|
84
|
+
const output = Buffer.from(text, 'utf8');
|
|
85
|
+
const bodyBudget = exports.MAX_TOOL_TRANSCRIPT_OUTPUT_BYTES - Buffer.byteLength(TRANSCRIPT_OMISSION);
|
|
86
|
+
let headEnd = Math.floor(bodyBudget / 2);
|
|
87
|
+
let tailStart = output.length - (bodyBudget - headEnd);
|
|
88
|
+
// Both ends must land before the lead byte of a complete UTF-8 character.
|
|
89
|
+
while ((output[headEnd] & 0xc0) === 0x80)
|
|
90
|
+
headEnd -= 1;
|
|
91
|
+
while ((output[tailStart] & 0xc0) === 0x80)
|
|
92
|
+
tailStart += 1;
|
|
93
|
+
return (output.subarray(0, headEnd).toString('utf8') +
|
|
94
|
+
TRANSCRIPT_OMISSION +
|
|
95
|
+
output.subarray(tailStart).toString('utf8'));
|
|
96
|
+
}
|
|
69
97
|
function clipDisplayText(text, limit) {
|
|
70
98
|
const characters = [...text];
|
|
71
99
|
return characters.length > limit ? `${characters.slice(0, limit - 1).join('')}…` : text;
|
|
@@ -57,6 +57,13 @@ export interface StructuredToolActivity {
|
|
|
57
57
|
outputBytes?: number;
|
|
58
58
|
/** Structured display body. When present, TUI ignores legacy TranscriptEntry.content. */
|
|
59
59
|
body?: string;
|
|
60
|
+
/** Bounded, terminal-safe output for the expanded transcript view. */
|
|
61
|
+
transcriptOutput?: string;
|
|
62
|
+
/** Project-local sanitized artifact, obtained from a validated durable receipt. */
|
|
63
|
+
artifactRef?: {
|
|
64
|
+
id: string;
|
|
65
|
+
outputBytes: number;
|
|
66
|
+
};
|
|
60
67
|
error?: string;
|
|
61
68
|
seq?: number;
|
|
62
69
|
artifactHint?: string;
|
|
@@ -56,7 +56,7 @@ export type TuiThemePreference = 'orion-pixel' | 'classic' | 'high-contrast' | '
|
|
|
56
56
|
export type TuiMotionPreference = 'full' | 'reduced' | 'off';
|
|
57
57
|
export type TuiStatusItem = 'mode' | 'goal' | 'model' | 'effort' | 'context' | 'queue' | 'activity';
|
|
58
58
|
/** Semantic keymap actions. Raw escape sequences are deliberately unsupported. */
|
|
59
|
-
export type TuiKeymapAction = 'submit' | 'queue' | 'interrupt' | 'history-search' | 'external-editor' | 'transcript' | 'redraw' | 'exit';
|
|
59
|
+
export type TuiKeymapAction = 'submit' | 'queue' | 'interrupt' | 'history-search' | 'external-editor' | 'transcript' | 'copy' | 'redraw' | 'exit';
|
|
60
60
|
/** UI configuration that is safe to persist globally. */
|
|
61
61
|
export interface UIConfig {
|
|
62
62
|
/** Runtime-only renderer override; rejected in persisted orion.yaml. */
|
|
@@ -508,6 +508,7 @@ const TUI_KEYMAP_ACTIONS = new Set([
|
|
|
508
508
|
'history-search',
|
|
509
509
|
'external-editor',
|
|
510
510
|
'transcript',
|
|
511
|
+
'copy',
|
|
511
512
|
'redraw',
|
|
512
513
|
'exit',
|
|
513
514
|
]);
|
|
@@ -521,6 +522,7 @@ const TUI_KEY_BINDINGS = new Set([
|
|
|
521
522
|
'ctrl+l',
|
|
522
523
|
'ctrl+o',
|
|
523
524
|
'ctrl+r',
|
|
525
|
+
'ctrl+t',
|
|
524
526
|
]);
|
|
525
527
|
function sanitizeUiConfig(value) {
|
|
526
528
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
package/dist/services/llm.d.ts
CHANGED
|
@@ -185,8 +185,10 @@ export interface StreamCallbacks {
|
|
|
185
185
|
*/
|
|
186
186
|
onThinkingText?: StreamCallback;
|
|
187
187
|
}
|
|
188
|
+
export type StructuredOutputSchema = boolean | Readonly<Record<string, unknown>>;
|
|
188
189
|
export interface StreamOptions {
|
|
189
190
|
abortSignal?: AbortSignal;
|
|
191
|
+
outputSchema?: StructuredOutputSchema;
|
|
190
192
|
}
|
|
191
193
|
export interface ProviderRequestPreflightContext {
|
|
192
194
|
operation: 'chat' | 'chat_stream';
|
|
@@ -212,6 +214,7 @@ export declare class LLMService {
|
|
|
212
214
|
private consecutive529Errors;
|
|
213
215
|
private usingFallback;
|
|
214
216
|
private lastRequestDiagnostics;
|
|
217
|
+
private readonly structuredOutputFallbackRoutes;
|
|
215
218
|
private usageObservers;
|
|
216
219
|
private providerRequestPreflight?;
|
|
217
220
|
private effortContext;
|
package/dist/services/llm.js
CHANGED
|
@@ -277,12 +277,22 @@ function normalizeCompleteStreamToolCall(call) {
|
|
|
277
277
|
call.function.arguments = JSON.stringify(args);
|
|
278
278
|
return true;
|
|
279
279
|
}
|
|
280
|
+
function rejectsStructuredOutput(error) {
|
|
281
|
+
if (!(error instanceof openai_1.default.APIError) || (error.status !== 400 && error.status !== 422)) {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
return (error.param === 'response_format' ||
|
|
285
|
+
error.param?.startsWith('response_format.') === true ||
|
|
286
|
+
error.code === 'unsupported_response_format' ||
|
|
287
|
+
/(?:response[_ ]format|json_schema).{0,100}(?:unsupported|not supported|not recognized|unknown)|(?:unsupported|unknown).{0,100}(?:response[_ ]format|json_schema)/iu.test(error.message));
|
|
288
|
+
}
|
|
280
289
|
class LLMService {
|
|
281
290
|
constructor(config) {
|
|
282
291
|
this.providerKey = 'default';
|
|
283
292
|
this.compactTransportRevision = 0;
|
|
284
293
|
this.consecutive529Errors = 0;
|
|
285
294
|
this.usingFallback = false;
|
|
295
|
+
this.structuredOutputFallbackRoutes = new Set();
|
|
286
296
|
this.usageObservers = new Set();
|
|
287
297
|
// v0.2.25: disable SDK built-in retry (maxRetries=0). Orion Code owns retry policy.
|
|
288
298
|
this.client = new openai_1.default({
|
|
@@ -500,7 +510,7 @@ class LLMService {
|
|
|
500
510
|
return visibleStreamText;
|
|
501
511
|
};
|
|
502
512
|
let incompleteAttempt;
|
|
503
|
-
const readAttempt = async (route, model, signal, reporter) => {
|
|
513
|
+
const readAttempt = async (route, model, attempt, signal, reporter) => {
|
|
504
514
|
const params = {
|
|
505
515
|
model,
|
|
506
516
|
messages: this.toOpenAIMessages(messages),
|
|
@@ -511,8 +521,42 @@ class LLMService {
|
|
|
511
521
|
...(0, effort_1.buildProviderEffortParams)(route.effort),
|
|
512
522
|
...(tools?.length ? { tools: tools } : {}),
|
|
513
523
|
};
|
|
524
|
+
const schema = options?.outputSchema;
|
|
525
|
+
const routeKey = typeof schema === 'object' &&
|
|
526
|
+
schema.type === 'object' &&
|
|
527
|
+
route.effort.protocol === 'openai-completions'
|
|
528
|
+
? JSON.stringify([route.providerKey, model])
|
|
529
|
+
: undefined;
|
|
530
|
+
if (routeKey !== undefined && !this.structuredOutputFallbackRoutes.has(routeKey)) {
|
|
531
|
+
params.response_format = {
|
|
532
|
+
type: 'json_schema',
|
|
533
|
+
json_schema: { name: 'orion_print_result', schema, strict: false },
|
|
534
|
+
};
|
|
535
|
+
}
|
|
514
536
|
onThinking?.();
|
|
515
|
-
const
|
|
537
|
+
const openStream = async () => (await route.client.chat.completions.create(params, {
|
|
538
|
+
...(signal ? { signal } : {}),
|
|
539
|
+
__streamClass: chat_completion_sse_1.ChatCompletionSseStream,
|
|
540
|
+
}));
|
|
541
|
+
let stream;
|
|
542
|
+
try {
|
|
543
|
+
stream = await openStream();
|
|
544
|
+
}
|
|
545
|
+
catch (error) {
|
|
546
|
+
if (routeKey === undefined || !params.response_format || !rejectsStructuredOutput(error)) {
|
|
547
|
+
throw error;
|
|
548
|
+
}
|
|
549
|
+
this.structuredOutputFallbackRoutes.add(routeKey);
|
|
550
|
+
delete params.response_format;
|
|
551
|
+
throwIfAborted(signal);
|
|
552
|
+
await this.assertProviderRequestAllowed('chat_stream', attempt + 1, messages, model);
|
|
553
|
+
const diagnostic = (0, provider_diagnostics_1.diagnoseProviderError)(error);
|
|
554
|
+
requestDiagnostics.retryCount++;
|
|
555
|
+
requestDiagnostics.retryErrorTypes.push(diagnostic.type);
|
|
556
|
+
requestDiagnostics.lastRetryErrorType = diagnostic.type;
|
|
557
|
+
requestDiagnostics.lastRetryStatus = diagnostic.status;
|
|
558
|
+
stream = await openStream();
|
|
559
|
+
}
|
|
516
560
|
let content = '';
|
|
517
561
|
let usedModel = model;
|
|
518
562
|
let usage;
|
|
@@ -657,7 +701,7 @@ class LLMService {
|
|
|
657
701
|
throwIfAborted(signal);
|
|
658
702
|
await this.assertProviderRequestAllowed('chat_stream', attempt, messages, model);
|
|
659
703
|
const route = this.requestRoute(modelSnapshot, model, providerKey);
|
|
660
|
-
return readAttempt(route, model, signal, reporter);
|
|
704
|
+
return readAttempt(route, model, attempt, signal, reporter);
|
|
661
705
|
});
|
|
662
706
|
// Unpack resilience result
|
|
663
707
|
const response = streamResult.result;
|
|
@@ -678,7 +722,7 @@ class LLMService {
|
|
|
678
722
|
const route = this.usingFallback && modelSnapshot.fallback
|
|
679
723
|
? modelSnapshot.fallback
|
|
680
724
|
: this.requestRoute(modelSnapshot, this.config.model);
|
|
681
|
-
const { response } = await readAttempt(route, this.config.model, options?.abortSignal);
|
|
725
|
+
const { response } = await readAttempt(route, this.config.model, attempt, options?.abortSignal);
|
|
682
726
|
this.consecutive529Errors = 0;
|
|
683
727
|
return response;
|
|
684
728
|
}, retryConfig);
|
|
@@ -227,7 +227,8 @@ class RawTerminalEditor {
|
|
|
227
227
|
}
|
|
228
228
|
return;
|
|
229
229
|
}
|
|
230
|
-
|
|
230
|
+
if (event.type === 'key')
|
|
231
|
+
this.applyKey(event.key);
|
|
231
232
|
}
|
|
232
233
|
emitPasteNotice(value) {
|
|
233
234
|
const lines = (0, input_parser_1.normalizePastedText)(value).split('\n').length;
|