@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
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PrintEventStreamV1 = void 0;
|
|
4
|
+
const tool_serializer_1 = require("../framework/tool-serializer");
|
|
5
|
+
const tool_receipt_validator_1 = require("../runtime/tool-receipt-validator");
|
|
4
6
|
const tool_transcript_entry_1 = require("../runtime/tool-transcript-entry");
|
|
5
7
|
const turn_commit_1 = require("../runtime/turn-commit");
|
|
6
8
|
const redaction_1 = require("../services/redaction");
|
|
@@ -32,8 +34,9 @@ function decisionOutcome(decision) {
|
|
|
32
34
|
}
|
|
33
35
|
/** Versioned shell protocol. Internal receipts, tool arguments and reasoning stay in Runtime. */
|
|
34
36
|
class PrintEventStreamV1 {
|
|
35
|
-
constructor(writeLine) {
|
|
37
|
+
constructor(writeLine, captureFinalReply = false) {
|
|
36
38
|
this.writeLine = writeLine;
|
|
39
|
+
this.captureFinalReply = captureFinalReply;
|
|
37
40
|
this.sessionId = null;
|
|
38
41
|
this.threadId = null;
|
|
39
42
|
this.turnId = null;
|
|
@@ -50,6 +53,8 @@ class PrintEventStreamV1 {
|
|
|
50
53
|
this.items.clear();
|
|
51
54
|
this.committedOutcome = undefined;
|
|
52
55
|
this.terminalOutcome = undefined;
|
|
56
|
+
this.lastAssistantReply = undefined;
|
|
57
|
+
this.committedReply = undefined;
|
|
53
58
|
this.emit({ type: 'thread.ready', resumed });
|
|
54
59
|
}
|
|
55
60
|
return thread.observeLiveEvents(events => {
|
|
@@ -70,21 +75,30 @@ class PrintEventStreamV1 {
|
|
|
70
75
|
this.approvalRequired = true;
|
|
71
76
|
this.emit({ type: 'approval.requested', requestId: request.id, name: request.name });
|
|
72
77
|
}
|
|
78
|
+
finalReply() {
|
|
79
|
+
return this.terminalOutcome?.status === 'completed' ? this.committedReply : undefined;
|
|
80
|
+
}
|
|
81
|
+
resolveOutcome(fallback, forced = false) {
|
|
82
|
+
if (forced)
|
|
83
|
+
return fallback;
|
|
84
|
+
if (this.approvalRequired) {
|
|
85
|
+
return { status: 'approval_required', reasonCode: 'approval_required', resumable: true };
|
|
86
|
+
}
|
|
87
|
+
if (this.projectionFailed) {
|
|
88
|
+
return { status: 'failed', reasonCode: 'event_projection_failed', resumable: false };
|
|
89
|
+
}
|
|
90
|
+
return this.terminalOutcome ?? fallback;
|
|
91
|
+
}
|
|
73
92
|
/** Terminate an invocation once, after all live events have drained. */
|
|
74
93
|
finish(fallback, forced = false) {
|
|
75
94
|
if (this.exitCode !== undefined)
|
|
76
95
|
return this.exitCode;
|
|
77
|
-
const outcome = forced
|
|
78
|
-
? fallback
|
|
79
|
-
: this.approvalRequired
|
|
80
|
-
? { status: 'approval_required', reasonCode: 'approval_required', resumable: true }
|
|
81
|
-
: this.projectionFailed
|
|
82
|
-
? { status: 'failed', reasonCode: 'event_projection_failed', resumable: false }
|
|
83
|
-
: (this.terminalOutcome ?? fallback);
|
|
96
|
+
const outcome = this.resolveOutcome(fallback, forced);
|
|
84
97
|
const exitCode = EXIT_CODES[outcome.status];
|
|
85
98
|
const committed = this.committedOutcome;
|
|
86
99
|
const metrics = committed?.metrics;
|
|
87
|
-
const reasonMessage =
|
|
100
|
+
const reasonMessage = outcome.reasonMessage ??
|
|
101
|
+
(committed?.reasonCode === outcome.reasonCode ? committed.reasonMessage : undefined);
|
|
88
102
|
this.emit({
|
|
89
103
|
type: 'result',
|
|
90
104
|
...outcome,
|
|
@@ -115,6 +129,8 @@ class PrintEventStreamV1 {
|
|
|
115
129
|
this.turnId = turnId;
|
|
116
130
|
this.committedOutcome = undefined;
|
|
117
131
|
this.terminalOutcome = undefined;
|
|
132
|
+
this.lastAssistantReply = undefined;
|
|
133
|
+
this.committedReply = undefined;
|
|
118
134
|
this.items.clear();
|
|
119
135
|
this.emit({ type: 'turn.started', mode: payload.data.mode });
|
|
120
136
|
return;
|
|
@@ -127,8 +143,14 @@ class PrintEventStreamV1 {
|
|
|
127
143
|
if (commit.stopDecision) {
|
|
128
144
|
this.committedOutcome = decisionOutcome(JSON.parse(commit.stopDecision));
|
|
129
145
|
}
|
|
146
|
+
if (this.captureFinalReply && commit.terminal === 'completed') {
|
|
147
|
+
this.committedReply = this.lastAssistantReply;
|
|
148
|
+
}
|
|
130
149
|
return;
|
|
131
150
|
}
|
|
151
|
+
case 'step.snapshot':
|
|
152
|
+
this.lastAssistantReply = undefined;
|
|
153
|
+
return;
|
|
132
154
|
case 'turn.completed':
|
|
133
155
|
this.terminalOutcome = this.committedOutcome ?? {
|
|
134
156
|
status: 'completed',
|
|
@@ -137,6 +159,7 @@ class PrintEventStreamV1 {
|
|
|
137
159
|
};
|
|
138
160
|
return;
|
|
139
161
|
case 'turn.failed':
|
|
162
|
+
this.committedReply = undefined;
|
|
140
163
|
this.terminalOutcome = this.committedOutcome ?? {
|
|
141
164
|
status: 'failed',
|
|
142
165
|
reasonCode: 'runtime_failure',
|
|
@@ -144,6 +167,7 @@ class PrintEventStreamV1 {
|
|
|
144
167
|
};
|
|
145
168
|
return;
|
|
146
169
|
case 'turn.interrupted':
|
|
170
|
+
this.committedReply = undefined;
|
|
147
171
|
this.terminalOutcome = this.committedOutcome ?? {
|
|
148
172
|
status: 'cancelled',
|
|
149
173
|
reasonCode: 'cancelled',
|
|
@@ -151,7 +175,7 @@ class PrintEventStreamV1 {
|
|
|
151
175
|
};
|
|
152
176
|
return;
|
|
153
177
|
}
|
|
154
|
-
if (!this.writeLine || !itemId)
|
|
178
|
+
if ((!this.writeLine && !this.captureFinalReply) || !itemId)
|
|
155
179
|
return;
|
|
156
180
|
if (payload.type === 'item.started') {
|
|
157
181
|
if (payload.data.kind === 'message' && payload.data.role === 'assistant') {
|
|
@@ -159,6 +183,7 @@ class PrintEventStreamV1 {
|
|
|
159
183
|
this.emit({ type: 'item.started', itemId, role: 'assistant' });
|
|
160
184
|
}
|
|
161
185
|
else if ((0, tool_transcript_entry_1.isToolTranscriptItem)(payload.data.kind)) {
|
|
186
|
+
this.lastAssistantReply = undefined;
|
|
162
187
|
const name = payload.data.name ?? payload.data.kind;
|
|
163
188
|
this.items.set(itemId, { tool: name });
|
|
164
189
|
this.emit({ type: 'tool.started', itemId, name });
|
|
@@ -173,6 +198,9 @@ class PrintEventStreamV1 {
|
|
|
173
198
|
}
|
|
174
199
|
else if (payload.type === 'tool.receipt' && item.tool) {
|
|
175
200
|
item.receiptDigest = payload.data.receiptDigest;
|
|
201
|
+
if (item.tool === 'exec_command' || item.tool === 'process_session') {
|
|
202
|
+
item.processReceiptEvent = event;
|
|
203
|
+
}
|
|
176
204
|
}
|
|
177
205
|
else if (payload.type === 'item.completed' ||
|
|
178
206
|
payload.type === 'item.failed' ||
|
|
@@ -191,9 +219,12 @@ class PrintEventStreamV1 {
|
|
|
191
219
|
name: item.tool,
|
|
192
220
|
status: status[payload.type],
|
|
193
221
|
...(item.receiptDigest ? { receiptDigest: item.receiptDigest } : {}),
|
|
222
|
+
...readProcessMetadata(item, itemId, event),
|
|
194
223
|
});
|
|
195
224
|
}
|
|
196
225
|
else if (payload.type === 'item.completed') {
|
|
226
|
+
if (this.captureFinalReply)
|
|
227
|
+
this.lastAssistantReply = payload.data.content;
|
|
197
228
|
this.emit({ type: 'item.completed', itemId, content: payload.data.content });
|
|
198
229
|
}
|
|
199
230
|
this.items.delete(itemId);
|
|
@@ -201,4 +232,19 @@ class PrintEventStreamV1 {
|
|
|
201
232
|
}
|
|
202
233
|
}
|
|
203
234
|
exports.PrintEventStreamV1 = PrintEventStreamV1;
|
|
235
|
+
function readProcessMetadata(item, itemId, event) {
|
|
236
|
+
if (!item.tool || !item.processReceiptEvent)
|
|
237
|
+
return undefined;
|
|
238
|
+
try {
|
|
239
|
+
const receipt = (0, tool_receipt_validator_1.validateDurableToolInvocationReceiptV1)({
|
|
240
|
+
item: { itemId, toolName: item.tool },
|
|
241
|
+
terminalEvent: event,
|
|
242
|
+
factEvent: item.processReceiptEvent,
|
|
243
|
+
});
|
|
244
|
+
return (0, tool_serializer_1.projectProcessMetadata)(receipt.result.metadata);
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
return undefined;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
204
250
|
//# sourceMappingURL=event-stream.js.map
|
|
@@ -4,11 +4,13 @@ import type { ResearchLifecycleEvent } from '../runtime/subagents/research-rende
|
|
|
4
4
|
import { type ResearchStatusProjection } from '../runtime/ui-view-model';
|
|
5
5
|
import { type UIRenderer } from '../services/global-config';
|
|
6
6
|
import { PrintEventStreamV1 } from './event-stream';
|
|
7
|
+
import { type PrintDelivery } from './delivery';
|
|
7
8
|
export type PrintOutputFormat = 'text' | 'json' | 'jsonl';
|
|
8
9
|
export interface PrintModeOptions {
|
|
9
10
|
outputFormat?: PrintOutputFormat;
|
|
10
11
|
resumeSessionId?: string;
|
|
11
12
|
eventStream?: PrintEventStreamV1;
|
|
13
|
+
delivery?: PrintDelivery;
|
|
12
14
|
}
|
|
13
15
|
export interface PrintModeResult {
|
|
14
16
|
content: string;
|
|
@@ -73,5 +75,8 @@ export declare function runPrintCommand(promptArgs: readonly string[], options:
|
|
|
73
75
|
outputFormat: PrintOutputFormat;
|
|
74
76
|
strictExit: boolean;
|
|
75
77
|
resumeSessionId?: string;
|
|
78
|
+
outputSchemaPath?: string;
|
|
79
|
+
lastMessagePath?: string;
|
|
80
|
+
outputOptionError?: string;
|
|
76
81
|
}): Promise<number>;
|
|
77
82
|
//# sourceMappingURL=launch.d.ts.map
|
package/dist/print-ui/launch.js
CHANGED
|
@@ -46,6 +46,7 @@ const ui_view_model_1 = require("../runtime/ui-view-model");
|
|
|
46
46
|
const style_1 = require("../tui-core/style");
|
|
47
47
|
const global_config_1 = require("../services/global-config");
|
|
48
48
|
const event_stream_1 = require("./event-stream");
|
|
49
|
+
const delivery_1 = require("./delivery");
|
|
49
50
|
function stripTrailingNewlines(text) {
|
|
50
51
|
return text.replace(/\n+$/g, '');
|
|
51
52
|
}
|
|
@@ -406,6 +407,32 @@ async function launchPrintMode(runtime, input, options = {}) {
|
|
|
406
407
|
process.removeListener('SIGTERM', interrupt);
|
|
407
408
|
}
|
|
408
409
|
}
|
|
410
|
+
let deliveryError;
|
|
411
|
+
const completed = {
|
|
412
|
+
status: 'completed',
|
|
413
|
+
reasonCode: 'completed',
|
|
414
|
+
resumable: false,
|
|
415
|
+
};
|
|
416
|
+
const observedOutcome = options.eventStream?.resolveOutcome(completed);
|
|
417
|
+
if (options.delivery &&
|
|
418
|
+
!cancelled &&
|
|
419
|
+
!hasLifecycleError &&
|
|
420
|
+
!failureReason &&
|
|
421
|
+
requestedExitCode !== 1 &&
|
|
422
|
+
!events.hasErrors() &&
|
|
423
|
+
observedOutcome?.status === 'completed') {
|
|
424
|
+
try {
|
|
425
|
+
options.delivery.deliver(options.eventStream?.finalReply());
|
|
426
|
+
}
|
|
427
|
+
catch (error) {
|
|
428
|
+
if (!(error instanceof delivery_1.PrintDeliveryError))
|
|
429
|
+
throw error;
|
|
430
|
+
deliveryError = error;
|
|
431
|
+
events.append({ role: 'error', content: error.message });
|
|
432
|
+
if (outputFormat !== 'text')
|
|
433
|
+
stderrLine(error.message);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
409
436
|
let outputError;
|
|
410
437
|
let hasOutputError = false;
|
|
411
438
|
try {
|
|
@@ -441,14 +468,18 @@ async function launchPrintMode(runtime, input, options = {}) {
|
|
|
441
468
|
if (hasOutputError)
|
|
442
469
|
throw outputError;
|
|
443
470
|
if (options.eventStream) {
|
|
444
|
-
let fallback =
|
|
445
|
-
status: 'completed',
|
|
446
|
-
reasonCode: 'completed',
|
|
447
|
-
resumable: false,
|
|
448
|
-
};
|
|
471
|
+
let fallback = completed;
|
|
449
472
|
if (cancelled) {
|
|
450
473
|
fallback = { status: 'cancelled', reasonCode: 'cancelled', resumable: true };
|
|
451
474
|
}
|
|
475
|
+
else if (deliveryError) {
|
|
476
|
+
fallback = {
|
|
477
|
+
status: 'failed',
|
|
478
|
+
reasonCode: deliveryError.reasonCode,
|
|
479
|
+
reasonMessage: (0, style_1.sanitizeTerminalText)(deliveryError.message),
|
|
480
|
+
resumable: false,
|
|
481
|
+
};
|
|
482
|
+
}
|
|
452
483
|
else if (hasLifecycleError ||
|
|
453
484
|
failureReason ||
|
|
454
485
|
events.hasErrors() ||
|
|
@@ -459,7 +490,13 @@ async function launchPrintMode(runtime, input, options = {}) {
|
|
|
459
490
|
resumable: false,
|
|
460
491
|
};
|
|
461
492
|
}
|
|
462
|
-
return options.eventStream.finish(fallback, cancelled ||
|
|
493
|
+
return options.eventStream.finish(fallback, cancelled ||
|
|
494
|
+
hasLifecycleError ||
|
|
495
|
+
!!failureReason ||
|
|
496
|
+
!!deliveryError ||
|
|
497
|
+
(options.delivery !== undefined &&
|
|
498
|
+
observedOutcome?.status === 'completed' &&
|
|
499
|
+
(events.hasErrors() || requestedExitCode === 1)));
|
|
463
500
|
}
|
|
464
501
|
if (failureReason || events.hasErrors())
|
|
465
502
|
return 1;
|
|
@@ -471,13 +508,28 @@ async function runPrintCommand(promptArgs, options) {
|
|
|
471
508
|
const stdout = process.stdout;
|
|
472
509
|
const originalWrite = stdout.write;
|
|
473
510
|
const write = originalWrite.bind(stdout);
|
|
474
|
-
const
|
|
475
|
-
|
|
511
|
+
const deliveryRequested = options.outputSchemaPath !== undefined ||
|
|
512
|
+
options.lastMessagePath !== undefined ||
|
|
513
|
+
options.outputOptionError !== undefined;
|
|
514
|
+
const stream = jsonl || options.strictExit || deliveryRequested
|
|
515
|
+
? new event_stream_1.PrintEventStreamV1(jsonl ? line => write(line) : undefined, deliveryRequested)
|
|
476
516
|
: undefined;
|
|
477
|
-
const fail = (reasonCode) =>
|
|
517
|
+
const fail = (reasonCode, message) => {
|
|
518
|
+
if (message)
|
|
519
|
+
stderrLine(message);
|
|
520
|
+
return (stream?.finish({
|
|
521
|
+
status: 'failed',
|
|
522
|
+
reasonCode,
|
|
523
|
+
...(message ? { reasonMessage: (0, style_1.sanitizeTerminalText)(message) } : {}),
|
|
524
|
+
resumable: false,
|
|
525
|
+
}, true) ?? 1);
|
|
526
|
+
};
|
|
478
527
|
if (jsonl)
|
|
479
528
|
stdout.write = process.stderr.write.bind(process.stderr);
|
|
480
529
|
try {
|
|
530
|
+
if (options.outputOptionError) {
|
|
531
|
+
return fail('invalid_output_option', options.outputOptionError);
|
|
532
|
+
}
|
|
481
533
|
const prompt = promptArgs.join(' ').trim() || (await readPromptFromStdinIfAvailable());
|
|
482
534
|
if (!prompt) {
|
|
483
535
|
stderrLine('Print mode requires a prompt argument or piped stdin.');
|
|
@@ -487,11 +539,13 @@ async function runPrintCommand(promptArgs, options) {
|
|
|
487
539
|
stderrLine('Use a saved session UUID with --resume.');
|
|
488
540
|
return fail('invalid_session_id');
|
|
489
541
|
}
|
|
542
|
+
const delivery = await (0, delivery_1.preparePrintDelivery)(options);
|
|
490
543
|
const { createProductUiRuntime } = await Promise.resolve().then(() => __importStar(require('../runtime/product-bootstrap')));
|
|
491
544
|
const runtime = await createProductUiRuntime({
|
|
492
545
|
cwd: process.cwd(),
|
|
493
546
|
uiRenderer: options.uiRenderer,
|
|
494
547
|
shutdownReason: 'Orion CLI shutdown',
|
|
548
|
+
outputSchema: delivery?.schema,
|
|
495
549
|
...(stream && {
|
|
496
550
|
onActiveSessionRuntime: (active, sessionId) => stream.attach(active.thread, sessionId, sessionId === options.resumeSessionId),
|
|
497
551
|
}),
|
|
@@ -500,9 +554,12 @@ async function runPrintCommand(promptArgs, options) {
|
|
|
500
554
|
outputFormat: options.outputFormat,
|
|
501
555
|
resumeSessionId: options.resumeSessionId,
|
|
502
556
|
eventStream: stream,
|
|
557
|
+
delivery,
|
|
503
558
|
});
|
|
504
559
|
}
|
|
505
560
|
catch (error) {
|
|
561
|
+
if (error instanceof delivery_1.PrintDeliveryError)
|
|
562
|
+
return fail(error.reasonCode, error.message);
|
|
506
563
|
if (!jsonl)
|
|
507
564
|
throw error;
|
|
508
565
|
if (error instanceof global_config_1.GlobalConfigDocumentValidationError) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type LoopBudget, type LoopStats, type QueryEvent, type QueryParams } from '../framework/query';
|
|
2
2
|
import type { ToolContext } from '../framework/tool';
|
|
3
|
-
import type { LLMService, Message, StreamCallbacks } from '../services/llm';
|
|
3
|
+
import type { LLMService, Message, StreamCallbacks, StructuredOutputSchema } from '../services/llm';
|
|
4
4
|
import type { TaskContextCompletionDecisionV1, TaskContextService } from './task-context-service';
|
|
5
5
|
import type { StepSnapshotV1, ToolBindingV1 } from './step-snapshot';
|
|
6
6
|
import type { ThreadEventStore } from './thread-event-store';
|
|
@@ -42,6 +42,7 @@ export declare function isFailedLoopStats(stats?: LoopStats): boolean;
|
|
|
42
42
|
export declare function serializeAgentLoopOutcome(stats: LoopStats | undefined, showBudgetStop: boolean): string;
|
|
43
43
|
export interface AgentLoopOptionsV1 {
|
|
44
44
|
readonly llm: LLMService;
|
|
45
|
+
readonly outputSchema?: StructuredOutputSchema;
|
|
45
46
|
readonly taskContext: TaskContextService;
|
|
46
47
|
readonly steps: AgentLoopStepFactoryV1;
|
|
47
48
|
readonly gateway: ToolGateway;
|
|
@@ -77,6 +78,7 @@ export declare class AgentLoopV1 implements ThreadTurnRunnerV1 {
|
|
|
77
78
|
readonly serviceId: "agent-loop";
|
|
78
79
|
constructor(options: AgentLoopOptionsV1);
|
|
79
80
|
run(context: ThreadTurnExecutionContextV1): Promise<ThreadTurnOutcomeV1>;
|
|
81
|
+
private runTurn;
|
|
80
82
|
private bindStep;
|
|
81
83
|
private invokeTool;
|
|
82
84
|
}
|
|
@@ -9,6 +9,7 @@ const query_1 = require("../framework/query");
|
|
|
9
9
|
const terminal_text_1 = require("../utils/terminal-text");
|
|
10
10
|
const task_checklist_1 = require("../harness/task-checklist");
|
|
11
11
|
const ui_view_model_1 = require("./ui-view-model");
|
|
12
|
+
const shell_process_sessions_1 = require("./shell-process-sessions");
|
|
12
13
|
const tool_serializer_1 = require("../framework/tool-serializer");
|
|
13
14
|
const redaction_1 = require("../services/redaction");
|
|
14
15
|
const bash_security_1 = require("../tools/bash_security");
|
|
@@ -44,6 +45,15 @@ class AgentLoopV1 {
|
|
|
44
45
|
this.serviceId = 'agent-loop';
|
|
45
46
|
}
|
|
46
47
|
async run(context) {
|
|
48
|
+
const shellProcesses = new shell_process_sessions_1.TurnShellProcesses(context.abortSignal);
|
|
49
|
+
try {
|
|
50
|
+
return await this.runTurn(context, shellProcesses);
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
await shellProcesses.close();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async runTurn(context, shellProcesses) {
|
|
47
57
|
const progressAtAdmission = this.options.taskContext.progressState();
|
|
48
58
|
const bindRecovery = this.options.previousCommitDigest
|
|
49
59
|
? (0, task_context_recovery_1.createTaskRecoveryBinder)(this.options.taskContext, this.options.previousCommitDigest, progressAtAdmission)
|
|
@@ -155,12 +165,13 @@ class AgentLoopV1 {
|
|
|
155
165
|
activeStep = await this.bindStep(context, prepared, router, bindingInput);
|
|
156
166
|
return {
|
|
157
167
|
receiptDigest: activeStep.digest,
|
|
158
|
-
toolExecutor: (name, args, abortSignal, metadata) => this.invokeTool(context, activeStep, name, args, answeringQuestion, bindRecovery, abortSignal, metadata),
|
|
168
|
+
toolExecutor: (name, args, abortSignal, metadata) => this.invokeTool(context, shellProcesses, activeStep, name, args, answeringQuestion, bindRecovery, abortSignal, metadata),
|
|
159
169
|
};
|
|
160
170
|
},
|
|
161
171
|
};
|
|
162
172
|
},
|
|
163
173
|
llm: this.options.llm,
|
|
174
|
+
outputSchema: this.options.outputSchema,
|
|
164
175
|
abortSignal: context.abortSignal,
|
|
165
176
|
streamCallbacks,
|
|
166
177
|
harness,
|
|
@@ -308,17 +319,16 @@ class AgentLoopV1 {
|
|
|
308
319
|
await this.options.onStepCaptured?.(snapshot);
|
|
309
320
|
return snapshot;
|
|
310
321
|
}
|
|
311
|
-
async invokeTool(context, snapshot, name, args, answeringQuestion, bindRecovery, abortSignal, metadata) {
|
|
322
|
+
async invokeTool(context, shellProcesses, snapshot, name, args, answeringQuestion, bindRecovery, abortSignal, metadata) {
|
|
312
323
|
if (!metadata)
|
|
313
324
|
throw new Error('ToolGateway execution requires provider call identity');
|
|
314
325
|
const executionChecklist = this.options.enableTaskTodos === true && (0, task_checklist_1.supportsExecutionChecklist)(context.mode);
|
|
315
326
|
const descriptor = snapshot.toolRouter.resolveDescriptor(name);
|
|
316
327
|
const workspaceWrite = mayChangeWorkspace(descriptor, args);
|
|
328
|
+
const readOnlyShellCall = (descriptor?.name === 'exec_command' || descriptor?.name === 'process_session') &&
|
|
329
|
+
!workspaceWrite;
|
|
317
330
|
let prerequisiteFailure;
|
|
318
|
-
if (answeringQuestion &&
|
|
319
|
-
descriptor &&
|
|
320
|
-
!descriptor.risk.readOnly &&
|
|
321
|
-
(descriptor.name !== 'exec_command' || workspaceWrite)) {
|
|
331
|
+
if (answeringQuestion && descriptor && !descriptor.risk.readOnly && !readOnlyShellCall) {
|
|
322
332
|
prerequisiteFailure = 'Answer the current question without modifying the task or workspace.';
|
|
323
333
|
}
|
|
324
334
|
else if (executionChecklist && workspaceWrite) {
|
|
@@ -349,7 +359,7 @@ class AgentLoopV1 {
|
|
|
349
359
|
snapshot,
|
|
350
360
|
toolName: name,
|
|
351
361
|
args,
|
|
352
|
-
context: toolContext,
|
|
362
|
+
context: { ...toolContext, shellProcesses },
|
|
353
363
|
abortSignal,
|
|
354
364
|
prerequisiteFailure,
|
|
355
365
|
taskRecovery: answeringQuestion
|
|
@@ -380,10 +390,12 @@ exports.AgentLoopV1 = AgentLoopV1;
|
|
|
380
390
|
function mayChangeWorkspace(descriptor, args) {
|
|
381
391
|
if (descriptor?.risk.effect !== 'workspace_write')
|
|
382
392
|
return false;
|
|
393
|
+
if (descriptor.name === 'process_session')
|
|
394
|
+
return args.action === 'write';
|
|
383
395
|
if (descriptor.name === 'edit_file' && args.preview === true)
|
|
384
396
|
return false;
|
|
385
397
|
if (descriptor.name === 'exec_command' && typeof args.command === 'string') {
|
|
386
|
-
return !(0, bash_security_1.isReadOnlyCommand)(args.command);
|
|
398
|
+
return args.interactive === true || !(0, bash_security_1.isReadOnlyCommand)(args.command);
|
|
387
399
|
}
|
|
388
400
|
return true;
|
|
389
401
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { AgentMode } from '../commands/types';
|
|
2
2
|
import type { AgentRuntimeEventSink, AgentRuntimeInput, AgentRuntimeInputResult, AgentRuntimeInterruptResult, AgentRuntimeSubmitResult } from './agent-runtime-protocol';
|
|
3
|
-
import type
|
|
3
|
+
import { type AgentRuntimeRunnerV1, type AgentRuntimeRunInputOptionsV1 } from './agent-runtime-runner';
|
|
4
|
+
import type { ThreadTranscriptHistorySource } from './thread-session-index';
|
|
4
5
|
import type { OrionCodeUiRuntime, FollowupQueueItem, FollowupQueueSnapshot, UiEventSink, UiRendererCapabilities } from './ui-events';
|
|
5
6
|
import type { CommandUiRenderer } from '../commands/types';
|
|
6
7
|
import { type TurnControllerOptions } from './turn-controller';
|
|
@@ -42,6 +43,8 @@ export interface AgentRuntimeControllerOptions extends TurnControllerOptions {
|
|
|
42
43
|
uiCapabilities?: UiRendererCapabilities;
|
|
43
44
|
/** Active renderer adapter identity for renderer-layer diagnostics. */
|
|
44
45
|
uiRenderer?: CommandUiRenderer;
|
|
46
|
+
/** Hand a resumed TUI its process-local durable history reader. */
|
|
47
|
+
onRestoreTranscriptHistory?: (source: ThreadTranscriptHistorySource | undefined) => void;
|
|
45
48
|
echoSubmittedInput?: boolean;
|
|
46
49
|
runningStatus?: string | ((input: string) => string);
|
|
47
50
|
readyStatus?: string | (() => string);
|
|
@@ -8,6 +8,7 @@ const retired_commands_1 = require("../commands/retired-commands");
|
|
|
8
8
|
const target_command_1 = require("../commands/target-command");
|
|
9
9
|
const agent_runtime_protocol_1 = require("./agent-runtime-protocol");
|
|
10
10
|
const agent_status_1 = require("./agent-status");
|
|
11
|
+
const agent_runtime_runner_1 = require("./agent-runtime-runner");
|
|
11
12
|
const ui_events_1 = require("./ui-events");
|
|
12
13
|
const turn_controller_1 = require("./turn-controller");
|
|
13
14
|
const agent_mode_1 = require("../framework/agent-mode");
|
|
@@ -372,7 +373,7 @@ class AgentRuntimeController {
|
|
|
372
373
|
if (this.followupsPaused || !item || sessionId !== this.followupSessionId)
|
|
373
374
|
return;
|
|
374
375
|
return {
|
|
375
|
-
|
|
376
|
+
item,
|
|
376
377
|
request: {
|
|
377
378
|
inputKind: 'user',
|
|
378
379
|
text: item.resolvedText,
|
|
@@ -394,7 +395,7 @@ class AgentRuntimeController {
|
|
|
394
395
|
this.followupsPaused = false;
|
|
395
396
|
const pending = this.nextPendingFollowup();
|
|
396
397
|
if (pending)
|
|
397
|
-
return this.submitTurnRequest(pending.request, pending.
|
|
398
|
+
return this.submitTurnRequest(pending.request, pending.item);
|
|
398
399
|
}
|
|
399
400
|
else if (this.followupQueue.length > 0) {
|
|
400
401
|
try {
|
|
@@ -559,7 +560,7 @@ class AgentRuntimeController {
|
|
|
559
560
|
if (!this.stopping) {
|
|
560
561
|
const pending = this.nextPendingFollowup();
|
|
561
562
|
if (pending)
|
|
562
|
-
await this.runTurn(pending.request, pending.
|
|
563
|
+
await this.runTurn(pending.request, pending.item);
|
|
563
564
|
}
|
|
564
565
|
}
|
|
565
566
|
async runCommand(command, args, abortSignal) {
|
|
@@ -619,7 +620,7 @@ class AgentRuntimeController {
|
|
|
619
620
|
if (command.name === 'compact' && !this.stopping) {
|
|
620
621
|
const pending = this.nextPendingFollowup();
|
|
621
622
|
if (pending)
|
|
622
|
-
await this.runTurn(pending.request, pending.
|
|
623
|
+
await this.runTurn(pending.request, pending.item);
|
|
623
624
|
}
|
|
624
625
|
if (result.continueAsChat) {
|
|
625
626
|
const session = this.options.runtime.getSession() ?? this.options.runtime.ensureSession();
|
|
@@ -720,6 +721,7 @@ class AgentRuntimeController {
|
|
|
720
721
|
...((renderer === 'terminal' || renderer === 'tui') && {
|
|
721
722
|
replaceTranscript: (entries) => this.eventSink.emit({ type: 'transcript_replace', entries: [...entries] }),
|
|
722
723
|
}),
|
|
724
|
+
onRestoreTranscriptHistory: renderer === 'tui' ? this.options.onRestoreTranscriptHistory : undefined,
|
|
723
725
|
getSession: this.options.runtime.getSession,
|
|
724
726
|
writeOutput: text => {
|
|
725
727
|
if (text.trim())
|
|
@@ -748,12 +750,12 @@ class AgentRuntimeController {
|
|
|
748
750
|
: undefined,
|
|
749
751
|
};
|
|
750
752
|
}
|
|
751
|
-
submitTurnRequest(request,
|
|
753
|
+
submitTurnRequest(request, followup) {
|
|
752
754
|
if (this.hasActiveTurn())
|
|
753
755
|
return { type: 'command_ignored' };
|
|
754
756
|
if (!this.requestIsCurrent(request))
|
|
755
757
|
return { type: 'command_ignored' };
|
|
756
|
-
this.activeRun = this.runTurn(request,
|
|
758
|
+
this.activeRun = this.runTurn(request, followup)
|
|
757
759
|
.catch(error => {
|
|
758
760
|
this.handleRunLoopError(error);
|
|
759
761
|
})
|
|
@@ -802,7 +804,7 @@ class AgentRuntimeController {
|
|
|
802
804
|
const result = await this.runTrackedCompact({});
|
|
803
805
|
const pending = this.nextPendingFollowup();
|
|
804
806
|
if (pending && !this.stopping)
|
|
805
|
-
this.submitTurnRequest(pending.request, pending.
|
|
807
|
+
this.submitTurnRequest(pending.request, pending.item);
|
|
806
808
|
return result;
|
|
807
809
|
}
|
|
808
810
|
async runTrackedCompact(input) {
|
|
@@ -835,21 +837,32 @@ class AgentRuntimeController {
|
|
|
835
837
|
throw new Error('Plan review is unavailable for this Runtime.');
|
|
836
838
|
return this.runner.reviewPlan(input);
|
|
837
839
|
}
|
|
838
|
-
async runTurn(firstRequest,
|
|
840
|
+
async runTurn(firstRequest, firstFollowup) {
|
|
839
841
|
let nextRequest = firstRequest;
|
|
840
|
-
let
|
|
842
|
+
let nextFollowup = firstFollowup;
|
|
841
843
|
while (nextRequest && !this.stopping) {
|
|
842
844
|
if (!this.requestIsCurrent(nextRequest))
|
|
843
845
|
break;
|
|
844
846
|
const request = nextRequest;
|
|
845
|
-
const
|
|
846
|
-
|
|
847
|
+
const followup = nextFollowup;
|
|
848
|
+
nextFollowup = undefined;
|
|
847
849
|
let followupAdmitted = false;
|
|
850
|
+
let followupChangedBeforeAdmission = false;
|
|
851
|
+
const isPending = () => {
|
|
852
|
+
const first = this.followupQueue[0];
|
|
853
|
+
return Boolean(followup &&
|
|
854
|
+
first &&
|
|
855
|
+
!this.stopping &&
|
|
856
|
+
!this.followupsPaused &&
|
|
857
|
+
this.requestIsCurrent(request) &&
|
|
858
|
+
first.id === followup.id &&
|
|
859
|
+
first.revision === followup.revision);
|
|
860
|
+
};
|
|
848
861
|
const onFollowupAdmitted = () => {
|
|
849
862
|
if ((this.followupSessionId ?? 'pending-session') !== request.sessionId)
|
|
850
863
|
return;
|
|
851
864
|
try {
|
|
852
|
-
this.saveFollowupQueue(this.followupQueue.filter(item => item.id !==
|
|
865
|
+
this.saveFollowupQueue(this.followupQueue.filter(item => item.id !== followup?.id));
|
|
853
866
|
followupAdmitted = true;
|
|
854
867
|
}
|
|
855
868
|
catch (error) {
|
|
@@ -872,23 +885,22 @@ class AgentRuntimeController {
|
|
|
872
885
|
if (!settingsReady)
|
|
873
886
|
break;
|
|
874
887
|
}
|
|
888
|
+
if (followup && !isPending())
|
|
889
|
+
throw new agent_runtime_runner_1.PendingFollowupChangedError();
|
|
875
890
|
this.options.runtime.store.setProcessing(true);
|
|
876
891
|
this.emitProcessing(true);
|
|
877
892
|
const runningStatus = statusText(this.options.runningStatus, nextInput);
|
|
878
893
|
if (runningStatus)
|
|
879
894
|
this.emitStatus(runningStatus);
|
|
880
|
-
const durableFollowup =
|
|
895
|
+
const durableFollowup = followup && this.options.runtime.followupQueueStore;
|
|
881
896
|
const options = {
|
|
882
897
|
abortSignal: turn.abortSignal,
|
|
883
898
|
turnId: turn.id,
|
|
884
899
|
...(durableFollowup && {
|
|
885
900
|
followup: {
|
|
886
|
-
id:
|
|
901
|
+
id: followup.id,
|
|
887
902
|
sessionId: request.sessionId,
|
|
888
|
-
isPending
|
|
889
|
-
this.requestIsCurrent(request) &&
|
|
890
|
-
this.followupQueue[0]?.id === followupId &&
|
|
891
|
-
this.followupQueue[0].resolvedText === request.text,
|
|
903
|
+
isPending,
|
|
892
904
|
onAdmitted: onFollowupAdmitted,
|
|
893
905
|
},
|
|
894
906
|
}),
|
|
@@ -903,11 +915,12 @@ class AgentRuntimeController {
|
|
|
903
915
|
inputKind: request.inputKind,
|
|
904
916
|
});
|
|
905
917
|
}
|
|
906
|
-
if (
|
|
918
|
+
if (followup && !durableFollowup)
|
|
907
919
|
onFollowupAdmitted();
|
|
908
920
|
}
|
|
909
921
|
catch (error) {
|
|
910
|
-
|
|
922
|
+
followupChangedBeforeAdmission = error instanceof agent_runtime_runner_1.PendingFollowupChangedError;
|
|
923
|
+
if (!turn.abortSignal.aborted && !followupChangedBeforeAdmission) {
|
|
911
924
|
if (this.options.onTurnError)
|
|
912
925
|
this.options.onTurnError(error);
|
|
913
926
|
else {
|
|
@@ -918,8 +931,9 @@ class AgentRuntimeController {
|
|
|
918
931
|
}
|
|
919
932
|
finally {
|
|
920
933
|
const revision = this.turnController.finishTurn(turn.id);
|
|
921
|
-
if (
|
|
934
|
+
if (followup && !followupAdmitted && !followupChangedBeforeAdmission) {
|
|
922
935
|
this.followupsPaused = true;
|
|
936
|
+
}
|
|
923
937
|
if (settingsReady) {
|
|
924
938
|
// Durable request runners commit and enqueue Plan execution at the Thread boundary.
|
|
925
939
|
// The legacy runInput path still needs the controller-owned compatibility follow-up.
|
|
@@ -967,7 +981,7 @@ class AgentRuntimeController {
|
|
|
967
981
|
else {
|
|
968
982
|
const queuedCommand = this.queuedCommands.shift();
|
|
969
983
|
const pending = queuedCommand ? undefined : this.nextPendingFollowup();
|
|
970
|
-
|
|
984
|
+
nextFollowup = pending?.item;
|
|
971
985
|
nextRequest = queuedCommand
|
|
972
986
|
? {
|
|
973
987
|
inputKind: 'user',
|
|
@@ -3,6 +3,10 @@ import type { GoalRuntimeControlResultV2, GoalRuntimeControlV2 } from './goal-ru
|
|
|
3
3
|
import type { ThreadSessionRuntimeActivationV1 } from './thread-session-view';
|
|
4
4
|
import type { PlanReviewActionV1, PlanReviewResolutionReceiptV1 } from './plan-review';
|
|
5
5
|
import type { PlanReviewProjectionV1 } from './thread-projection';
|
|
6
|
+
/** The queue changed before this selection crossed the durable admission boundary. */
|
|
7
|
+
export declare class PendingFollowupChangedError extends Error {
|
|
8
|
+
constructor();
|
|
9
|
+
}
|
|
6
10
|
/** Renderer-neutral options for one admitted runtime request. */
|
|
7
11
|
export interface AgentRuntimeRunInputOptionsV1 {
|
|
8
12
|
readonly abortSignal?: AbortSignal;
|
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PendingFollowupChangedError = void 0;
|
|
4
|
+
/** The queue changed before this selection crossed the durable admission boundary. */
|
|
5
|
+
class PendingFollowupChangedError extends Error {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('Pending follow-up changed before admission.');
|
|
8
|
+
this.name = 'PendingFollowupChangedError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.PendingFollowupChangedError = PendingFollowupChangedError;
|
|
3
12
|
//# sourceMappingURL=agent-runtime-runner.js.map
|