@orion-agents/orion-code 0.4.8 → 0.5.0
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 +13 -0
- package/README.md +5 -5
- package/README.zh-CN.md +5 -5
- package/dist/acp/sessions.js +1 -1
- package/dist/acp/stdio.js +17 -2
- package/dist/cli.js +45 -4
- 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/release-receipts.d.ts +0 -1
- package/dist/runtime/release-receipts.js +8 -3
- 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
|
@@ -3,72 +3,43 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.layoutTuiStartupBanner = layoutTuiStartupBanner;
|
|
7
7
|
exports.shouldRenderTuiMascot = shouldRenderTuiMascot;
|
|
8
8
|
const os_1 = require("os");
|
|
9
9
|
const string_width_1 = __importDefault(require("string-width"));
|
|
10
10
|
const style_1 = require("../tui-core/style");
|
|
11
11
|
const pixel_mascot_1 = require("./pixel-mascot");
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
const TITLE_STYLE = {
|
|
13
|
+
bold: true,
|
|
14
|
+
foreground: { kind: 'rgb', r: 88, g: 190, b: 255 },
|
|
15
|
+
};
|
|
16
|
+
const DETAIL_STYLE = { dim: true };
|
|
17
|
+
/** Build startup rows in the same cell model as the conversation. */
|
|
18
|
+
function layoutTuiStartupBanner(options) {
|
|
19
|
+
const width = Math.max(1, Math.floor(options.terminalWidth));
|
|
20
|
+
return startupLines(options).map((line, index) => [
|
|
21
|
+
{
|
|
22
|
+
text: truncateCells(line, width),
|
|
23
|
+
style: options.suppressColor ? style_1.DEFAULT_STYLE : index === 0 ? TITLE_STYLE : DETAIL_STYLE,
|
|
24
|
+
},
|
|
25
|
+
]);
|
|
25
26
|
}
|
|
26
27
|
function startupLines(options) {
|
|
27
28
|
const version = sanitizeBannerField(options.version);
|
|
28
|
-
const model = sanitizeBannerField(options.model);
|
|
29
29
|
const cwd = sanitizeBannerField(shortenHomePath(options.cwd));
|
|
30
30
|
const mascot = shouldRenderTuiMascot(options) && options.terminalWidth >= 54;
|
|
31
|
-
const
|
|
32
|
-
const details = [
|
|
33
|
-
'ORION CODE | 猎户座',
|
|
34
|
-
`v${version} model ${model}`,
|
|
35
|
-
`project ${cwd}`,
|
|
36
|
-
...packBannerHints(['/ commands', '@ files', '? shortcuts', 'Ctrl+O tools'], ' ', textWidth),
|
|
37
|
-
...packBannerHints(['Enter steer', 'Tab queue while working', 'Ctrl+C twice exits'], ' · ', textWidth),
|
|
38
|
-
];
|
|
31
|
+
const details = ['ORION CODE | 猎户座', `v${version} · ${cwd}`, '/ commands · ? shortcuts'];
|
|
39
32
|
if (!mascot)
|
|
40
33
|
return details;
|
|
41
34
|
const sprite = (0, pixel_mascot_1.pixelHunterSprite)('ready');
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
function packBannerHints(hints, separator, width) {
|
|
45
|
-
const lines = [];
|
|
46
|
-
let line = '';
|
|
47
|
-
for (const hint of hints) {
|
|
48
|
-
const next = line ? `${line}${separator}${hint}` : hint;
|
|
49
|
-
if (line && (0, string_width_1.default)(next) > width) {
|
|
50
|
-
lines.push(line);
|
|
51
|
-
line = hint;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
line = next;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (line)
|
|
58
|
-
lines.push(line);
|
|
59
|
-
return lines;
|
|
35
|
+
return sprite.map((line, index) => `${line} ${details[index] ?? ''}`);
|
|
60
36
|
}
|
|
61
37
|
function sanitizeBannerField(value) {
|
|
62
38
|
return (0, style_1.sanitizeTerminalText)(value).replace(/\s+/gu, ' ').trim();
|
|
63
39
|
}
|
|
64
40
|
/** Keep the brand character optional and textual in accessibility/fallback modes. */
|
|
65
41
|
function shouldRenderTuiMascot(options) {
|
|
66
|
-
return options.mascot
|
|
67
|
-
}
|
|
68
|
-
function styleBannerLine(line, index, suppressColor) {
|
|
69
|
-
if (suppressColor)
|
|
70
|
-
return line;
|
|
71
|
-
return index === 0 ? `${SKY_BLUE}\x1b[1m${line}${RESET_STYLE}` : `${DIM}${line}${RESET_STYLE}`;
|
|
42
|
+
return options.mascot === true && !options.suppressColor && options.theme !== 'classic';
|
|
72
43
|
}
|
|
73
44
|
function shortenHomePath(path) {
|
|
74
45
|
const home = (0, os_1.homedir)();
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { type TuiFrame } from '../tui-core/frame';
|
|
3
|
+
import { type StyledRow } from '../tui-core/style';
|
|
4
|
+
export type SurfaceOutputEvent = 'drain' | 'error' | 'close';
|
|
5
|
+
export interface SurfaceOutput {
|
|
6
|
+
write(chunk: string | Uint8Array): boolean;
|
|
7
|
+
on(event: SurfaceOutputEvent, listener: (error?: unknown) => void): this;
|
|
8
|
+
off(event: SurfaceOutputEvent, listener: (error?: unknown) => void): this;
|
|
9
|
+
readonly writable: boolean;
|
|
10
|
+
}
|
|
11
|
+
/** Restore terminal modes after both normal operation and a partial screen write. */
|
|
12
|
+
export declare const TERMINAL_RESTORE: string;
|
|
13
|
+
/**
|
|
14
|
+
* Projects the app's current frame onto one alternate screen. The terminal
|
|
15
|
+
* never owns interactive history. The primary screen is only used to replay
|
|
16
|
+
* finalized rows once, after releasing our screen on exit.
|
|
17
|
+
*/
|
|
18
|
+
export declare class TerminalViewport {
|
|
19
|
+
private readonly options;
|
|
20
|
+
private phase;
|
|
21
|
+
private previous;
|
|
22
|
+
private generation;
|
|
23
|
+
private queue;
|
|
24
|
+
private pendingPaint;
|
|
25
|
+
private failed;
|
|
26
|
+
private readonly suppressColor;
|
|
27
|
+
constructor(options: {
|
|
28
|
+
output: SurfaceOutput;
|
|
29
|
+
});
|
|
30
|
+
mount(): Promise<void>;
|
|
31
|
+
/** Invalidate immediately when the host resizes, including A → B → A bursts. */
|
|
32
|
+
invalidate(): void;
|
|
33
|
+
/** While a write is pending, keep only the latest frame before each lifecycle transition. */
|
|
34
|
+
render(frame: TuiFrame): Promise<void>;
|
|
35
|
+
writeClipboardControl(sequence: string): Promise<void>;
|
|
36
|
+
/** Wait for all writes enqueued before this call. Each operation reports its own errors. */
|
|
37
|
+
whenIdle(): Promise<void>;
|
|
38
|
+
suspend(): Promise<void>;
|
|
39
|
+
restore(): Promise<void>;
|
|
40
|
+
unmount(history?: StyledRow[]): Promise<void>;
|
|
41
|
+
private enter;
|
|
42
|
+
private lifecycle;
|
|
43
|
+
private enqueue;
|
|
44
|
+
private encodeFrame;
|
|
45
|
+
private encodeSpans;
|
|
46
|
+
private write;
|
|
47
|
+
}
|
|
48
|
+
/** In-memory output stream for inspecting the terminal protocol in tests. */
|
|
49
|
+
export declare class MemoryOutput extends EventEmitter implements SurfaceOutput {
|
|
50
|
+
chunks: string[];
|
|
51
|
+
writable: boolean;
|
|
52
|
+
write(chunk: string | Uint8Array): boolean;
|
|
53
|
+
text(): string;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=terminal-viewport.d.ts.map
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoryOutput = exports.TerminalViewport = exports.TERMINAL_RESTORE = void 0;
|
|
4
|
+
const node_events_1 = require("node:events");
|
|
5
|
+
const frame_1 = require("../tui-core/frame");
|
|
6
|
+
const style_1 = require("../tui-core/style");
|
|
7
|
+
const terminal_writer_1 = require("../tui-core/terminal-writer");
|
|
8
|
+
const SYNC_START = '\x1b[?2026h';
|
|
9
|
+
const SYNC_END = '\x1b[?2026l';
|
|
10
|
+
const ENTER_SCREEN = '\x1b[?1049h\x1b[?6l\x1b[r\x1b[?2004h\x1b[?1006h\x1b[?1000h';
|
|
11
|
+
const CLEAR_SCREEN = '\x1b[H\x1b[2J';
|
|
12
|
+
const ERASE_TO_LINE_END = '\x1b[K';
|
|
13
|
+
/** Restore terminal modes after both normal operation and a partial screen write. */
|
|
14
|
+
exports.TERMINAL_RESTORE = `\x1b[?1000l\x1b[?1006l\x1b[?2004l${SYNC_END}\x1b[?1049l` +
|
|
15
|
+
style_1.SGR_RESET +
|
|
16
|
+
(0, terminal_writer_1.enableAutoWrap)() +
|
|
17
|
+
(0, terminal_writer_1.cursorShow)();
|
|
18
|
+
/**
|
|
19
|
+
* Projects the app's current frame onto one alternate screen. The terminal
|
|
20
|
+
* never owns interactive history. The primary screen is only used to replay
|
|
21
|
+
* finalized rows once, after releasing our screen on exit.
|
|
22
|
+
*/
|
|
23
|
+
class TerminalViewport {
|
|
24
|
+
constructor(options) {
|
|
25
|
+
this.options = options;
|
|
26
|
+
this.phase = 'idle';
|
|
27
|
+
this.previous = null;
|
|
28
|
+
this.generation = 0;
|
|
29
|
+
this.queue = Promise.resolve();
|
|
30
|
+
this.pendingPaint = null;
|
|
31
|
+
this.failed = false;
|
|
32
|
+
this.suppressColor = (0, style_1.shouldSuppressColor)();
|
|
33
|
+
}
|
|
34
|
+
mount() {
|
|
35
|
+
return this.lifecycle(async () => {
|
|
36
|
+
if (this.phase === 'idle' && !this.failed)
|
|
37
|
+
await this.enter();
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/** Invalidate immediately when the host resizes, including A → B → A bursts. */
|
|
41
|
+
invalidate() {
|
|
42
|
+
this.generation += 1;
|
|
43
|
+
this.previous = null;
|
|
44
|
+
}
|
|
45
|
+
/** While a write is pending, keep only the latest frame before each lifecycle transition. */
|
|
46
|
+
render(frame) {
|
|
47
|
+
if (this.pendingPaint) {
|
|
48
|
+
this.pendingPaint.frame = frame;
|
|
49
|
+
this.pendingPaint.generation = this.generation;
|
|
50
|
+
return this.pendingPaint.completion;
|
|
51
|
+
}
|
|
52
|
+
const paint = {
|
|
53
|
+
frame,
|
|
54
|
+
generation: this.generation,
|
|
55
|
+
completion: this.enqueue(async () => {
|
|
56
|
+
if (this.pendingPaint === paint)
|
|
57
|
+
this.pendingPaint = null;
|
|
58
|
+
if (this.phase !== 'mounted' || this.failed || paint.generation !== this.generation)
|
|
59
|
+
return;
|
|
60
|
+
const { frame, generation } = paint;
|
|
61
|
+
await this.write(this.encodeFrame(frame));
|
|
62
|
+
// The write may have waited for drain while the host resized.
|
|
63
|
+
if (generation === this.generation)
|
|
64
|
+
this.previous = frame;
|
|
65
|
+
}),
|
|
66
|
+
};
|
|
67
|
+
this.pendingPaint = paint;
|
|
68
|
+
return paint.completion;
|
|
69
|
+
}
|
|
70
|
+
async writeClipboardControl(sequence) {
|
|
71
|
+
let delivered = false;
|
|
72
|
+
await this.enqueue(async () => {
|
|
73
|
+
if (this.phase !== 'mounted' || this.failed)
|
|
74
|
+
return;
|
|
75
|
+
await this.write(sequence);
|
|
76
|
+
delivered = true;
|
|
77
|
+
});
|
|
78
|
+
if (!delivered)
|
|
79
|
+
throw new Error('terminal clipboard is unavailable');
|
|
80
|
+
}
|
|
81
|
+
/** Wait for all writes enqueued before this call. Each operation reports its own errors. */
|
|
82
|
+
whenIdle() {
|
|
83
|
+
return this.queue;
|
|
84
|
+
}
|
|
85
|
+
suspend() {
|
|
86
|
+
return this.lifecycle(async () => {
|
|
87
|
+
if (this.phase !== 'mounted')
|
|
88
|
+
return;
|
|
89
|
+
await this.write(exports.TERMINAL_RESTORE);
|
|
90
|
+
this.phase = 'suspended';
|
|
91
|
+
this.previous = null;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
restore() {
|
|
95
|
+
return this.lifecycle(async () => {
|
|
96
|
+
if (this.phase === 'suspended' && !this.failed)
|
|
97
|
+
await this.enter();
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
unmount(history = []) {
|
|
101
|
+
return this.lifecycle(async () => {
|
|
102
|
+
const phase = this.phase;
|
|
103
|
+
if (phase === 'closed')
|
|
104
|
+
return;
|
|
105
|
+
this.phase = 'closed';
|
|
106
|
+
this.previous = null;
|
|
107
|
+
if (phase === 'mounted')
|
|
108
|
+
await this.write(exports.TERMINAL_RESTORE);
|
|
109
|
+
if (phase === 'idle' || this.failed || history.length === 0)
|
|
110
|
+
return;
|
|
111
|
+
// Start below the restored shell cursor. Explicit CRLF fences each
|
|
112
|
+
// prewrapped row and cancels a pending wrap in the last column.
|
|
113
|
+
const rows = history.map(row => this.encodeSpans(row));
|
|
114
|
+
await this.write(`\r\n${rows.join('\r\n')}\r\n`);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
async enter() {
|
|
118
|
+
this.phase = 'mounted';
|
|
119
|
+
this.previous = null;
|
|
120
|
+
await this.write(ENTER_SCREEN + style_1.SGR_RESET + (0, terminal_writer_1.cursorHide)());
|
|
121
|
+
}
|
|
122
|
+
lifecycle(operation) {
|
|
123
|
+
// A future frame belongs on the other side of this transition.
|
|
124
|
+
this.pendingPaint = null;
|
|
125
|
+
return this.enqueue(operation);
|
|
126
|
+
}
|
|
127
|
+
enqueue(operation) {
|
|
128
|
+
const completion = this.queue.then(operation);
|
|
129
|
+
this.queue = completion.catch(() => {
|
|
130
|
+
this.failed = true;
|
|
131
|
+
});
|
|
132
|
+
return completion;
|
|
133
|
+
}
|
|
134
|
+
encodeFrame(frame) {
|
|
135
|
+
const diff = (0, frame_1.diffTuiFrames)(this.previous, frame);
|
|
136
|
+
if (!diff.cursorChanged && diff.changedRows.length === 0)
|
|
137
|
+
return '';
|
|
138
|
+
const geometryChanged = this.previous?.width !== frame.width || this.previous?.height !== frame.height;
|
|
139
|
+
const chunks = [SYNC_START, (0, terminal_writer_1.cursorHide)(), (0, terminal_writer_1.disableAutoWrap)()];
|
|
140
|
+
if (geometryChanged)
|
|
141
|
+
chunks.push(style_1.SGR_RESET, CLEAR_SCREEN);
|
|
142
|
+
for (const index of diff.changedRows) {
|
|
143
|
+
const row = frame.rows[index];
|
|
144
|
+
const printed = (0, frame_1.trimFrameRow)(row);
|
|
145
|
+
const background = this.suppressColor ? undefined : row[printed.length]?.style.background;
|
|
146
|
+
if (geometryChanged && printed.length === 0 && !background)
|
|
147
|
+
continue;
|
|
148
|
+
chunks.push((0, terminal_writer_1.moveTo)(index, 0));
|
|
149
|
+
if (!geometryChanged)
|
|
150
|
+
chunks.push((0, terminal_writer_1.clearLine)());
|
|
151
|
+
chunks.push(this.encodeSpans((0, frame_1.renderStyledFrameRow)(printed)));
|
|
152
|
+
if (background) {
|
|
153
|
+
chunks.push((0, style_1.encodeStyleToSgr)({ background }, false), ERASE_TO_LINE_END, style_1.SGR_RESET);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
chunks.push((0, terminal_writer_1.moveTo)(frame.cursor.row, frame.cursor.column), (0, terminal_writer_1.enableAutoWrap)(), frame.cursor.visible ? (0, terminal_writer_1.cursorShow)() : (0, terminal_writer_1.cursorHide)(), SYNC_END);
|
|
157
|
+
return chunks.join('');
|
|
158
|
+
}
|
|
159
|
+
encodeSpans(row) {
|
|
160
|
+
return row
|
|
161
|
+
.map(({ text, style }) => {
|
|
162
|
+
const sgr = style ? (0, style_1.encodeStyleToSgr)(style, this.suppressColor) : '';
|
|
163
|
+
const literal = (0, style_1.sanitizeTerminalText)(text).replace(/\n/gu, '');
|
|
164
|
+
return sgr ? `${sgr}${literal}${style_1.SGR_RESET}` : literal;
|
|
165
|
+
})
|
|
166
|
+
.join('');
|
|
167
|
+
}
|
|
168
|
+
write(chunk) {
|
|
169
|
+
if (!chunk)
|
|
170
|
+
return Promise.resolve();
|
|
171
|
+
const { output } = this.options;
|
|
172
|
+
if (!output.writable)
|
|
173
|
+
return Promise.reject(new Error('terminal output is not writable'));
|
|
174
|
+
return new Promise((resolve, reject) => {
|
|
175
|
+
const settle = (error) => {
|
|
176
|
+
output.off('drain', onDrain);
|
|
177
|
+
output.off('error', onError);
|
|
178
|
+
output.off('close', onClose);
|
|
179
|
+
if (error)
|
|
180
|
+
reject(error);
|
|
181
|
+
else
|
|
182
|
+
resolve();
|
|
183
|
+
};
|
|
184
|
+
const onDrain = () => (output.writable ? settle() : onClose());
|
|
185
|
+
const onError = (error) => {
|
|
186
|
+
settle(error instanceof Error ? error : new Error(String(error ?? 'terminal output error')));
|
|
187
|
+
};
|
|
188
|
+
const onClose = () => settle(new Error('terminal output closed before drain'));
|
|
189
|
+
output.on('drain', onDrain);
|
|
190
|
+
output.on('error', onError);
|
|
191
|
+
output.on('close', onClose);
|
|
192
|
+
try {
|
|
193
|
+
if (output.write(chunk) !== false)
|
|
194
|
+
settle();
|
|
195
|
+
else if (!output.writable)
|
|
196
|
+
onClose();
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
onError(error);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
exports.TerminalViewport = TerminalViewport;
|
|
205
|
+
/** In-memory output stream for inspecting the terminal protocol in tests. */
|
|
206
|
+
class MemoryOutput extends node_events_1.EventEmitter {
|
|
207
|
+
constructor() {
|
|
208
|
+
super(...arguments);
|
|
209
|
+
this.chunks = [];
|
|
210
|
+
this.writable = true;
|
|
211
|
+
}
|
|
212
|
+
write(chunk) {
|
|
213
|
+
this.chunks.push(typeof chunk === 'string' ? chunk : Buffer.from(chunk).toString('utf8'));
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
text() {
|
|
217
|
+
return this.chunks.join('');
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
exports.MemoryOutput = MemoryOutput;
|
|
221
|
+
//# sourceMappingURL=terminal-viewport.js.map
|
|
@@ -11,12 +11,17 @@ export interface TranscriptLayoutOptions {
|
|
|
11
11
|
width: number;
|
|
12
12
|
theme?: TuiTheme;
|
|
13
13
|
toolOutputMode?: 'adaptive' | 'collapsed' | 'full';
|
|
14
|
+
nativeWrap?: boolean;
|
|
15
|
+
history?: boolean;
|
|
16
|
+
artifactOutput?: string;
|
|
14
17
|
}
|
|
15
18
|
/**
|
|
16
19
|
* Convert one transcript record into terminal-safe visual rows.
|
|
17
20
|
* The function is deterministic and has no frame, cache, state, or stdout side effects.
|
|
18
21
|
*/
|
|
19
22
|
export declare function layoutTranscriptEntry(entry: TranscriptLayoutEntry, options: TranscriptLayoutOptions): StyledRow[];
|
|
23
|
+
export declare function recordedThinking(entry: Pick<TranscriptEntry, 'role' | 'title' | 'content'>): string | undefined;
|
|
20
24
|
/** Paint one styled transcript row into a frame using terminal cell widths. */
|
|
21
25
|
export declare function writeStyledRowToFrame(frame: TuiFrame, row: number, spans: StyledRow): void;
|
|
26
|
+
export declare function truncateText(text: string, width: number): string;
|
|
22
27
|
//# sourceMappingURL=transcript-layout.d.ts.map
|
|
@@ -5,7 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.layoutTranscriptEntry = layoutTranscriptEntry;
|
|
8
|
+
exports.recordedThinking = recordedThinking;
|
|
8
9
|
exports.writeStyledRowToFrame = writeStyledRowToFrame;
|
|
10
|
+
exports.truncateText = truncateText;
|
|
9
11
|
const string_width_1 = __importDefault(require("string-width"));
|
|
10
12
|
const grapheme_1 = require("../runtime/composer/grapheme");
|
|
11
13
|
const ansi_parser_1 = require("../runtime/rich-text/ansi-parser");
|
|
@@ -26,12 +28,21 @@ function layoutTranscriptEntry(entry, options) {
|
|
|
26
28
|
rows = layoutLiteralRole(entry.content, width, '⏸ ', theme.warning, theme.warning);
|
|
27
29
|
}
|
|
28
30
|
else if (entry.role === 'assistant' && entry.title === 'reasoning') {
|
|
29
|
-
const content = (
|
|
30
|
-
if (!content
|
|
31
|
+
const content = recordedThinking(entry);
|
|
32
|
+
if (!content)
|
|
31
33
|
return [];
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
if (options.history) {
|
|
35
|
+
rows = [
|
|
36
|
+
[{ text: '· Thinking', style: theme.toolName }],
|
|
37
|
+
...(0, layout_1.layoutRichText)((0, markdown_parser_1.parseRichText)((0, style_1.sanitizeTerminalText)(content)), {
|
|
38
|
+
width,
|
|
39
|
+
indent: width > 2 ? 2 : 0,
|
|
40
|
+
theme: () => theme.toolMeta,
|
|
41
|
+
}),
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
else if (entry.finalized === false) {
|
|
45
|
+
const preview = `· Thinking ${sanitizeInlineText(content.slice(0, 512))}`;
|
|
35
46
|
const clipped = content.length > 512 || (0, string_width_1.default)(preview) > width;
|
|
36
47
|
rows = [
|
|
37
48
|
[
|
|
@@ -43,19 +54,16 @@ function layoutTranscriptEntry(entry, options) {
|
|
|
43
54
|
];
|
|
44
55
|
}
|
|
45
56
|
else {
|
|
46
|
-
|
|
47
|
-
[{ text: label, style: theme.toolMeta }],
|
|
48
|
-
...layoutLiteralRole(content, width, ' ', theme.toolMeta, theme.toolMeta),
|
|
49
|
-
];
|
|
57
|
+
return [];
|
|
50
58
|
}
|
|
51
59
|
}
|
|
52
60
|
else if (isToolEntry(entry)) {
|
|
53
|
-
rows = layoutToolEntry(entry, width, theme, options
|
|
61
|
+
rows = layoutToolEntry(entry, width, theme, options);
|
|
54
62
|
}
|
|
55
63
|
else {
|
|
56
64
|
switch (entry.role) {
|
|
57
65
|
case 'assistant':
|
|
58
|
-
rows = layoutAssistantEntry(entry.content, width, theme);
|
|
66
|
+
rows = layoutAssistantEntry(entry.content, width, theme, options.nativeWrap);
|
|
59
67
|
break;
|
|
60
68
|
case 'user':
|
|
61
69
|
rows = layoutUserEntry(entry.content, width, theme);
|
|
@@ -80,13 +88,20 @@ function layoutTranscriptEntry(entry, options) {
|
|
|
80
88
|
}
|
|
81
89
|
}
|
|
82
90
|
const spacedRows = entry.role === 'user' && !isToolEntry(entry) ? [[], ...rows, []] : rows;
|
|
83
|
-
return spacedRows.map(row => normalizeOutputRow(row, width));
|
|
91
|
+
return spacedRows.map(row => normalizeOutputRow(row, options.nativeWrap ? undefined : width));
|
|
84
92
|
}
|
|
85
|
-
function
|
|
93
|
+
function recordedThinking(entry) {
|
|
94
|
+
if (entry.role !== 'assistant' || entry.title !== 'reasoning')
|
|
95
|
+
return undefined;
|
|
96
|
+
const content = entry.content.trim();
|
|
97
|
+
return content && content !== 'Model reasoning started' ? content : undefined;
|
|
98
|
+
}
|
|
99
|
+
function layoutAssistantEntry(content, width, theme, nativeWrap) {
|
|
86
100
|
const gutter = width >= 6 ? 2 : 0;
|
|
87
101
|
const rows = (0, layout_1.layoutRichText)((0, markdown_parser_1.parseRichText)(content), {
|
|
88
102
|
width: width - gutter,
|
|
89
103
|
theme: (0, theme_1.richTextThemeResolver)(theme),
|
|
104
|
+
nativeWrap,
|
|
90
105
|
});
|
|
91
106
|
if (!gutter)
|
|
92
107
|
return rows;
|
|
@@ -136,7 +151,8 @@ function layoutLiteralRole(content, width, marker, markerStyle, textStyle) {
|
|
|
136
151
|
const continuationPrefix = [{ text: ' '.repeat(markerWidth), style: markerStyle }];
|
|
137
152
|
return layoutPrefixedSpans([{ text: (0, style_1.sanitizeTerminalText)(content, 2), style: textStyle }], width, firstPrefix, continuationPrefix);
|
|
138
153
|
}
|
|
139
|
-
function layoutToolEntry(entry, width, theme,
|
|
154
|
+
function layoutToolEntry(entry, width, theme, options) {
|
|
155
|
+
const viewMode = options.history ? 'full' : (options.toolOutputMode ?? 'adaptive');
|
|
140
156
|
const activity = entry.toolActivity;
|
|
141
157
|
if (!activity && entry.role === 'tool') {
|
|
142
158
|
return layoutLiteralRole(entry.content, width, '• ', theme.toolName, theme.toolMeta);
|
|
@@ -170,17 +186,15 @@ function layoutToolEntry(entry, width, theme, viewMode) {
|
|
|
170
186
|
], width));
|
|
171
187
|
}
|
|
172
188
|
}
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
? activity.body
|
|
183
|
-
: entry.content;
|
|
189
|
+
const fullOutput = options.artifactOutput ?? activity?.transcriptOutput ?? activity?.body;
|
|
190
|
+
const bodyText = viewMode === 'full'
|
|
191
|
+
? (fullOutput ?? outputView?.preview ?? entry.content)
|
|
192
|
+
: outputView
|
|
193
|
+
? viewMode !== 'collapsed' &&
|
|
194
|
+
(outputView.mode === 'inline' || outputView.mode === 'preview')
|
|
195
|
+
? outputView.preview
|
|
196
|
+
: ''
|
|
197
|
+
: (activity?.body ?? entry.content);
|
|
184
198
|
if (bodyText) {
|
|
185
199
|
const safeAnsi = retainSafeToolSgr(bodyText);
|
|
186
200
|
const body = (0, ansi_parser_1.parseAnsiToStyledSpans)(safeAnsi).map(span => ({
|
|
@@ -203,7 +217,7 @@ function layoutToolEntry(entry, width, theme, viewMode) {
|
|
|
203
217
|
: '';
|
|
204
218
|
rows.push(...wrapStyledSpans([
|
|
205
219
|
{
|
|
206
|
-
text: ` ↳ collapsed${more} · ${omitted} · Ctrl+
|
|
220
|
+
text: ` ↳ collapsed${more} · ${omitted} · Ctrl+T history`,
|
|
207
221
|
style: theme.toolMeta,
|
|
208
222
|
},
|
|
209
223
|
], width));
|
|
@@ -366,10 +380,11 @@ function fillRowBackground(row, width, background) {
|
|
|
366
380
|
return styled;
|
|
367
381
|
}
|
|
368
382
|
function normalizeOutputRow(row, width) {
|
|
369
|
-
|
|
383
|
+
const safeRow = row.map(span => ({
|
|
370
384
|
text: (0, style_1.sanitizeTerminalText)(span.text, 2).replace(/\n/gu, ''),
|
|
371
385
|
style: span.style,
|
|
372
|
-
}))
|
|
386
|
+
}));
|
|
387
|
+
return mergeAdjacentSpans(width === undefined ? safeRow : clampRow(safeRow, width));
|
|
373
388
|
}
|
|
374
389
|
function clampRow(row, width) {
|
|
375
390
|
const result = [];
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { StyledRow } from '../tui-core/style';
|
|
2
|
+
import type { TuiTranscriptRecord } from './state';
|
|
3
|
+
type LayoutRecord = (record: TuiTranscriptRecord, width: number) => StyledRow[];
|
|
4
|
+
export interface ExplorationCounts {
|
|
5
|
+
reads: number;
|
|
6
|
+
searches: number;
|
|
7
|
+
listings: number;
|
|
8
|
+
}
|
|
9
|
+
interface TranscriptPageOptions {
|
|
10
|
+
head?: readonly TuiTranscriptRecord[];
|
|
11
|
+
tail?: readonly TuiTranscriptRecord[];
|
|
12
|
+
hasEarlier?: boolean;
|
|
13
|
+
onVisibleRecord?: (record: TuiTranscriptRecord) => void;
|
|
14
|
+
layoutExploration?: (counts: ExplorationCounts, width: number) => StyledRow[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* An application-owned viewport into semantic history. Following the tail is
|
|
18
|
+
* explicit; while reading, the first visible row is anchored to its record.
|
|
19
|
+
*/
|
|
20
|
+
export declare class TranscriptPager {
|
|
21
|
+
private anchor;
|
|
22
|
+
private pendingRows;
|
|
23
|
+
private pageRows;
|
|
24
|
+
private earlierAnchor?;
|
|
25
|
+
get isFollowing(): boolean;
|
|
26
|
+
get nearStart(): boolean;
|
|
27
|
+
/** Keep the visible passage when older records are about to be prepended. */
|
|
28
|
+
keepEarlierAnchor(): void;
|
|
29
|
+
reset(): void;
|
|
30
|
+
first(): void;
|
|
31
|
+
last(): void;
|
|
32
|
+
scroll(deltaRows: number): void;
|
|
33
|
+
page(direction: -1 | 1, overlap?: number): void;
|
|
34
|
+
halfPage(direction: -1 | 1): void;
|
|
35
|
+
rows(records: readonly TuiTranscriptRecord[], width: number, height: number, layout: LayoutRecord, options?: TranscriptPageOptions): StyledRow[];
|
|
36
|
+
private rememberEarlierAnchor;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=transcript-pager.d.ts.map
|