@orion-agents/orion-code 0.4.7 → 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 +17 -1
- package/README.md +8 -9
- package/README.zh-CN.md +8 -8
- package/dist/acp/session-updates.js +1 -0
- 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 +6 -8
- package/dist/framework/query.js +39 -76
- 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/framework/verification-command.d.ts +21 -0
- package/dist/framework/verification-command.js +53 -4
- package/dist/harness/context-harness.d.ts +3 -9
- package/dist/harness/context-harness.js +43 -163
- package/dist/harness/ledger.js +2 -1
- package/dist/harness/state.d.ts +3 -0
- package/dist/harness/state.js +37 -4
- package/dist/harness/task-checklist.d.ts +1 -1
- package/dist/harness/task-checklist.js +1 -1
- package/dist/harness/types.d.ts +1 -0
- package/dist/harness/verification.js +5 -4
- 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 +26 -41
- 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/goal-lifecycle-v2.js +5 -0
- package/dist/runtime/goal-runtime-coordinator.js +6 -2
- 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 +34 -6
- 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 +7 -2
- 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 +61 -11
- package/dist/runtime/subagents/presets.d.ts +1 -1
- package/dist/runtime/subagents/presets.js +1 -0
- package/dist/runtime/task-context-recovery.js +14 -3
- package/dist/runtime/task-context-service.d.ts +2 -6
- package/dist/runtime/task-context-service.js +3 -12
- 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 +23 -5
- 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 +10 -0
- package/dist/runtime/verification-feedback.d.ts +4 -0
- package/dist/runtime/verification-feedback.js +61 -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/bash_security.d.ts +1 -24
- package/dist/tools/bash_security.js +7 -124
- 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/tools/todo.js +9 -13
- 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/dist/utils/shell-command.d.ts +29 -0
- package/dist/utils/shell-command.js +185 -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,6 @@
|
|
|
1
1
|
import type { TodoItem } from '../framework/tool-state';
|
|
2
2
|
import type { TaskTodoItem } from './types';
|
|
3
|
-
export declare const TASK_CHECKLIST_REQUIRED = "
|
|
3
|
+
export declare const TASK_CHECKLIST_REQUIRED = "Consider using todo_write to track implementation paths and verification for this multi-step task.";
|
|
4
4
|
export declare function supportsExecutionChecklist(mode: string): boolean;
|
|
5
5
|
export declare const TASK_RECOVERY_STRATEGY_HISTORY_LIMIT = 4;
|
|
6
6
|
/** Deferral is applied from explicit user input. Tool arguments cannot defer work. */
|
|
@@ -19,7 +19,7 @@ const fileExtension = /\.[a-z][a-z0-9]{0,7}$/iu;
|
|
|
19
19
|
const referenceClause = /\s+(?:to (?:match|follow|use)|based on|according to|using|after reading|as (?:in|described in))\s+|(?:,|\s)*(?:参考|参照|依据|基于|对照|按照)/iu;
|
|
20
20
|
const checkInstruction = /^(?:(?:verify|validate|check|review)\b|验收|验证|核对|检查|审阅)/iu;
|
|
21
21
|
const sameFileScope = /^(?:(?:edit|modify|change|update)\s+(?:only\s+)?(?:this|that|the same)\s+file(?:\s+only)?|(?:只)?(?:修改|编辑|更新)(?:这个|该|同一)文件)[.,,。]?$/iu;
|
|
22
|
-
exports.TASK_CHECKLIST_REQUIRED = '
|
|
22
|
+
exports.TASK_CHECKLIST_REQUIRED = 'Consider using todo_write to track implementation paths and verification for this multi-step task.';
|
|
23
23
|
function supportsExecutionChecklist(mode) {
|
|
24
24
|
return mode === 'build' || mode === 'auto' || mode === 'goal';
|
|
25
25
|
}
|
package/dist/harness/types.d.ts
CHANGED
|
@@ -289,6 +289,7 @@ export interface HarnessConfig {
|
|
|
289
289
|
maxRecentTurns?: number;
|
|
290
290
|
evidenceBudgetRatio?: number;
|
|
291
291
|
driftGuard?: 'off' | 'warn' | 'block';
|
|
292
|
+
/** @deprecated Accepted for older callers. Completion evidence is advisory. */
|
|
292
293
|
completionGate?: boolean | 'off' | 'warn' | 'block';
|
|
293
294
|
}
|
|
294
295
|
export interface DriftCheckResult {
|
|
@@ -82,11 +82,13 @@ function uniqueKinds(kinds) {
|
|
|
82
82
|
}
|
|
83
83
|
function classifyVerificationCommand(command) {
|
|
84
84
|
const normalized = command?.trim();
|
|
85
|
-
if (!normalized
|
|
85
|
+
if (!normalized)
|
|
86
86
|
return 'generic';
|
|
87
87
|
const local = (0, verification_command_1.classifyDirectVerificationCommand)(normalized);
|
|
88
88
|
if (local)
|
|
89
89
|
return local;
|
|
90
|
+
if (verification_command_1.SHELL_CONTROL_OPERATOR.test(normalized))
|
|
91
|
+
return 'generic';
|
|
90
92
|
if (/^(?:npm\s+publish|gh\s+release|git\s+tag)(?=\s|$)/u.test(normalized)) {
|
|
91
93
|
return 'release';
|
|
92
94
|
}
|
|
@@ -228,9 +230,8 @@ function matchesRequestedCheck(entry, check, workspace) {
|
|
|
228
230
|
}
|
|
229
231
|
function matchesRequestedCheckInvocation(command, cwd, check, workspace) {
|
|
230
232
|
return (command.trim() === check.command &&
|
|
231
|
-
(check.kind
|
|
232
|
-
|
|
233
|
-
: !check.cwd || (0, path_1.resolve)(workspace, cwd ?? '.') === (0, path_1.resolve)(workspace, check.cwd)));
|
|
233
|
+
(check.kind !== 'generic' || cwd !== undefined) &&
|
|
234
|
+
(0, path_1.resolve)(workspace, cwd ?? '.') === (0, path_1.resolve)(workspace, check.cwd ?? '.'));
|
|
234
235
|
}
|
|
235
236
|
function verificationKindForEntry(entry, requireLocalReceipt = false) {
|
|
236
237
|
const stored = entry.metadata?.verificationKind;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { StructuredOutputSchema } from '../services/llm';
|
|
2
|
+
export declare class PrintDeliveryError extends Error {
|
|
3
|
+
readonly reasonCode: 'invalid_output_schema' | 'missing_final_output' | 'invalid_final_json' | 'output_schema_mismatch' | 'output_write_failed';
|
|
4
|
+
constructor(reasonCode: 'invalid_output_schema' | 'missing_final_output' | 'invalid_final_json' | 'output_schema_mismatch' | 'output_write_failed', message: string);
|
|
5
|
+
}
|
|
6
|
+
export interface PrintDelivery {
|
|
7
|
+
readonly schema?: StructuredOutputSchema;
|
|
8
|
+
deliver(finalReply: string | undefined): void;
|
|
9
|
+
}
|
|
10
|
+
/** Load and compile the requested schema before any provider request. */
|
|
11
|
+
export declare function preparePrintDelivery(options: {
|
|
12
|
+
outputSchemaPath?: string;
|
|
13
|
+
lastMessagePath?: string;
|
|
14
|
+
}): Promise<PrintDelivery | undefined>;
|
|
15
|
+
//# sourceMappingURL=delivery.d.ts.map
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.PrintDeliveryError = void 0;
|
|
37
|
+
exports.preparePrintDelivery = preparePrintDelivery;
|
|
38
|
+
const node_fs_1 = require("node:fs");
|
|
39
|
+
const node_path_1 = require("node:path");
|
|
40
|
+
const atomic_write_1 = require("../services/atomic-write");
|
|
41
|
+
class PrintDeliveryError extends Error {
|
|
42
|
+
constructor(reasonCode, message) {
|
|
43
|
+
super(message);
|
|
44
|
+
this.reasonCode = reasonCode;
|
|
45
|
+
this.name = 'PrintDeliveryError';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.PrintDeliveryError = PrintDeliveryError;
|
|
49
|
+
/** Load and compile the requested schema before any provider request. */
|
|
50
|
+
async function preparePrintDelivery(options) {
|
|
51
|
+
if (options.outputSchemaPath === undefined && options.lastMessagePath === undefined) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
const schema = options.outputSchemaPath && (await compileSchema(options.outputSchemaPath));
|
|
55
|
+
const outputFile = options.lastMessagePath && (0, node_path_1.resolve)(options.lastMessagePath);
|
|
56
|
+
return {
|
|
57
|
+
schema: schema ? schema.document : undefined,
|
|
58
|
+
deliver(finalReply) {
|
|
59
|
+
if (!finalReply?.trim()) {
|
|
60
|
+
throw new PrintDeliveryError('missing_final_output', 'The completed Print turn has no final model reply to deliver.');
|
|
61
|
+
}
|
|
62
|
+
if (schema)
|
|
63
|
+
validateFinalOutput(finalReply, schema.validate);
|
|
64
|
+
if (!outputFile)
|
|
65
|
+
return;
|
|
66
|
+
try {
|
|
67
|
+
const content = finalReply.endsWith('\n') ? finalReply : `${finalReply}\n`;
|
|
68
|
+
(0, atomic_write_1.atomicWriteFileSync)(outputFile, content, { mode: 0o600, fsync: true });
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
throw new PrintDeliveryError('output_write_failed', `Cannot write the final Print reply. ${errorMessage(error)}`);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
async function compileSchema(path) {
|
|
77
|
+
try {
|
|
78
|
+
if (!(0, node_fs_1.statSync)(path).isFile())
|
|
79
|
+
throw new Error('Expected a regular JSON Schema file.');
|
|
80
|
+
const document = JSON.parse((0, node_fs_1.readFileSync)(path, 'utf8'));
|
|
81
|
+
if (typeof document !== 'boolean' &&
|
|
82
|
+
(document === null || typeof document !== 'object' || Array.isArray(document))) {
|
|
83
|
+
throw new Error('A JSON Schema must be an object or boolean.');
|
|
84
|
+
}
|
|
85
|
+
const schema = document;
|
|
86
|
+
const dialect = typeof schema === 'object' ? schema.$schema : undefined;
|
|
87
|
+
const draft2020 = typeof dialect === 'string' &&
|
|
88
|
+
/^https:\/\/json-schema\.org\/draft\/2020-12\/schema#?$/u.test(dialect);
|
|
89
|
+
const [{ default: Ajv }, { default: addFormats }] = await Promise.all([
|
|
90
|
+
draft2020 ? Promise.resolve().then(() => __importStar(require('ajv/dist/2020'))) : Promise.resolve().then(() => __importStar(require('ajv'))),
|
|
91
|
+
Promise.resolve().then(() => __importStar(require('ajv-formats'))),
|
|
92
|
+
]);
|
|
93
|
+
const compiler = new Ajv({
|
|
94
|
+
strictSchema: true,
|
|
95
|
+
strictTypes: false,
|
|
96
|
+
strictTuples: false,
|
|
97
|
+
ownProperties: true,
|
|
98
|
+
});
|
|
99
|
+
addFormats(compiler);
|
|
100
|
+
if (dialect === 'https://json-schema.org/draft-07/schema#' ||
|
|
101
|
+
dialect === 'https://json-schema.org/draft-07/schema') {
|
|
102
|
+
compiler.addSchema({ $ref: 'http://json-schema.org/draft-07/schema#' }, 'https://json-schema.org/draft-07/schema');
|
|
103
|
+
}
|
|
104
|
+
const validate = compiler.compile(schema);
|
|
105
|
+
if ('$async' in validate && validate.$async) {
|
|
106
|
+
throw new Error('Asynchronous JSON Schema extensions are unsupported.');
|
|
107
|
+
}
|
|
108
|
+
return { document: schema, validate };
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
throw new PrintDeliveryError('invalid_output_schema', `Cannot load the Print output schema. ${errorMessage(error)}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function validateFinalOutput(reply, validate) {
|
|
115
|
+
let value;
|
|
116
|
+
try {
|
|
117
|
+
value = JSON.parse(reply);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
throw new PrintDeliveryError('invalid_final_json', 'The final Print reply is not valid JSON.');
|
|
121
|
+
}
|
|
122
|
+
if (validate(value))
|
|
123
|
+
return;
|
|
124
|
+
const issue = validate.errors?.[0];
|
|
125
|
+
const detail = issue ? ` ${issue.instancePath || '/'} ${issue.message ?? 'is invalid'}.` : '';
|
|
126
|
+
throw new PrintDeliveryError('output_schema_mismatch', `The final Print reply does not match the JSON Schema.${detail}`);
|
|
127
|
+
}
|
|
128
|
+
function errorMessage(error) {
|
|
129
|
+
return error instanceof Error ? error.message : String(error);
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=delivery.js.map
|
|
@@ -20,6 +20,7 @@ export interface PrintOutcome {
|
|
|
20
20
|
/** Versioned shell protocol. Internal receipts, tool arguments and reasoning stay in Runtime. */
|
|
21
21
|
export declare class PrintEventStreamV1 {
|
|
22
22
|
private readonly writeLine?;
|
|
23
|
+
private readonly captureFinalReply;
|
|
23
24
|
private sessionId;
|
|
24
25
|
private threadId;
|
|
25
26
|
private turnId;
|
|
@@ -27,13 +28,17 @@ export declare class PrintEventStreamV1 {
|
|
|
27
28
|
private readonly items;
|
|
28
29
|
private committedOutcome?;
|
|
29
30
|
private terminalOutcome?;
|
|
31
|
+
private lastAssistantReply?;
|
|
32
|
+
private committedReply?;
|
|
30
33
|
private approvalRequired;
|
|
31
34
|
private projectionFailed;
|
|
32
35
|
private exitCode?;
|
|
33
|
-
constructor(writeLine?: ((line: string) => void) | undefined);
|
|
36
|
+
constructor(writeLine?: ((line: string) => void) | undefined, captureFinalReply?: boolean);
|
|
34
37
|
attach(thread: ThreadRuntimeV1, sessionId: string, resumed: boolean): () => void;
|
|
35
38
|
output(content: string): void;
|
|
36
39
|
approval(request: ToolPermissionRequest): void;
|
|
40
|
+
finalReply(): string | undefined;
|
|
41
|
+
resolveOutcome(fallback: PrintOutcome, forced?: boolean): PrintOutcome;
|
|
37
42
|
/** Terminate an invocation once, after all live events have drained. */
|
|
38
43
|
finish(fallback: PrintOutcome, forced?: boolean): number;
|
|
39
44
|
private emit;
|
|
@@ -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
|
}
|