@saccolabs/tars 1.35.1 → 1.37.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/dist/channels/channel-manager.d.ts +5 -0
- package/dist/channels/channel-manager.js +7 -0
- package/dist/channels/channel-manager.js.map +1 -1
- package/dist/channels/tui/tui-channel.d.ts +98 -0
- package/dist/channels/tui/tui-channel.js +362 -0
- package/dist/channels/tui/tui-channel.js.map +1 -0
- package/dist/channels/tui/tui-renderer.d.ts +49 -0
- package/dist/channels/tui/tui-renderer.js +112 -0
- package/dist/channels/tui/tui-renderer.js.map +1 -0
- package/dist/cli/commands/chat.d.ts +9 -0
- package/dist/cli/commands/chat.js +51 -0
- package/dist/cli/commands/chat.js.map +1 -0
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +9 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/suppress-warnings.d.ts +1 -0
- package/dist/cli/suppress-warnings.js +9 -0
- package/dist/cli/suppress-warnings.js.map +1 -0
- package/dist/supervisor/bootstrap.d.ts +48 -0
- package/dist/supervisor/bootstrap.js +596 -0
- package/dist/supervisor/bootstrap.js.map +1 -0
- package/dist/supervisor/main.js +5 -529
- package/dist/supervisor/main.js.map +1 -1
- package/dist/supervisor/mcp-bridge.js +10 -1
- package/dist/supervisor/mcp-bridge.js.map +1 -1
- package/dist/supervisor/supervisor.js +3 -3
- package/dist/supervisor/supervisor.js.map +1 -1
- package/dist/supervisor/tars-engine.js +1 -1
- package/dist/supervisor/tars-engine.js.map +1 -1
- package/dist/utils/logger.d.ts +5 -0
- package/dist/utils/logger.js +23 -0
- package/dist/utils/logger.js.map +1 -1
- package/package.json +2 -1
|
@@ -12,6 +12,11 @@ export declare class ChannelManager {
|
|
|
12
12
|
* Initialize enabled channels based on configuration
|
|
13
13
|
*/
|
|
14
14
|
private initializeChannels;
|
|
15
|
+
/**
|
|
16
|
+
* Register an additional communication channel at runtime.
|
|
17
|
+
* Used to add channels like the TUI that aren't config-driven.
|
|
18
|
+
*/
|
|
19
|
+
registerChannel(channel: CommunicationChannel): void;
|
|
15
20
|
/**
|
|
16
21
|
* Start all enabled channels
|
|
17
22
|
*/
|
|
@@ -23,6 +23,13 @@ export class ChannelManager {
|
|
|
23
23
|
this.channels.set(discord.id, discord);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Register an additional communication channel at runtime.
|
|
28
|
+
* Used to add channels like the TUI that aren't config-driven.
|
|
29
|
+
*/
|
|
30
|
+
registerChannel(channel) {
|
|
31
|
+
this.channels.set(channel.id, channel);
|
|
32
|
+
}
|
|
26
33
|
/**
|
|
27
34
|
* Start all enabled channels
|
|
28
35
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel-manager.js","sourceRoot":"","sources":["../../src/channels/channel-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C;;GAEG;AACH,MAAM,OAAO,cAAc;IACN,QAAQ,GAAsC,IAAI,GAAG,EAAE,CAAC;IACxD,MAAM,CAAS;IACxB,cAAc,CAA8C;IAC5D,mBAAmB,CAAU;IAErC;QACI,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;QACnC,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC9B,CAAC;IAED;;OAEG;IACK,kBAAkB;QACtB,wBAAwB;QACxB,MAAM,OAAO,GAAG,IAAI,cAAc,EAAE,CAAC;QACrC,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;YACpB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QAC3C,CAAC;IACL,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,KAAK;QACd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+
import type { Terminal } from '@earendil-works/pi-tui';
|
|
2
|
+
import { CommunicationChannel, ChannelMessage } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Custom Terminal implementation wrapping Readable and Writable streams.
|
|
5
|
+
* Used for testing and custom I/O redirection.
|
|
6
|
+
*/
|
|
7
|
+
export declare class StreamTerminal implements Terminal {
|
|
8
|
+
private readonly input;
|
|
9
|
+
private readonly output;
|
|
10
|
+
private inputHandler?;
|
|
11
|
+
private wasRaw;
|
|
12
|
+
constructor(input: NodeJS.ReadableStream, output: NodeJS.WritableStream);
|
|
13
|
+
start(onInput: (data: string) => void, onResize: () => void): void;
|
|
14
|
+
private handleData;
|
|
15
|
+
stop(): void;
|
|
16
|
+
drainInput(maxMs?: number, idleMs?: number): Promise<void>;
|
|
17
|
+
write(data: string): void;
|
|
18
|
+
get columns(): number;
|
|
19
|
+
get rows(): number;
|
|
20
|
+
get kittyProtocolActive(): boolean;
|
|
21
|
+
moveBy(lines: number): void;
|
|
22
|
+
hideCursor(): void;
|
|
23
|
+
showCursor(): void;
|
|
24
|
+
clearLine(): void;
|
|
25
|
+
clearFromCursor(): void;
|
|
26
|
+
clearScreen(): void;
|
|
27
|
+
setTitle(title: string): void;
|
|
28
|
+
setProgress(active: boolean): void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Terminal UI (TUI) Channel Implementation for Tars.
|
|
32
|
+
* Provides an interactive chat experience in the terminal with
|
|
33
|
+
* real-time token streaming, status updates, and markdown rendering.
|
|
34
|
+
*/
|
|
35
|
+
export declare class TuiChannel implements CommunicationChannel {
|
|
36
|
+
readonly id = "tui";
|
|
37
|
+
readonly isEnabled = true;
|
|
38
|
+
private messageHandler?;
|
|
39
|
+
private terminal;
|
|
40
|
+
private tui;
|
|
41
|
+
private chatContainer;
|
|
42
|
+
private statusContainer;
|
|
43
|
+
private editor;
|
|
44
|
+
private isProcessing;
|
|
45
|
+
private onExitCallback?;
|
|
46
|
+
private isStopped;
|
|
47
|
+
private activeStreamingComponent?;
|
|
48
|
+
private activeStreamingText;
|
|
49
|
+
private activeStatusComponent?;
|
|
50
|
+
private loader?;
|
|
51
|
+
private lastStatusLineCount;
|
|
52
|
+
private readonly input;
|
|
53
|
+
private readonly output;
|
|
54
|
+
constructor(opts?: {
|
|
55
|
+
input?: NodeJS.ReadableStream;
|
|
56
|
+
output?: NodeJS.WritableStream;
|
|
57
|
+
onExit?: () => Promise<void>;
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* Start the TUI — render logo, show header, enter TUI rendering loop.
|
|
61
|
+
*/
|
|
62
|
+
start(): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Stop the TUI channel.
|
|
65
|
+
*/
|
|
66
|
+
stop(): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Send a proactive notification to the terminal.
|
|
69
|
+
* Used for status updates (first send) and background task notifications.
|
|
70
|
+
*/
|
|
71
|
+
notify(content: string): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Edit the last status notification in-place using TUI states.
|
|
74
|
+
* Returns true if the edit succeeded.
|
|
75
|
+
*/
|
|
76
|
+
editStatus(content: string): Promise<boolean>;
|
|
77
|
+
/**
|
|
78
|
+
* Clear the tracked status message.
|
|
79
|
+
*/
|
|
80
|
+
clearStatus(): void;
|
|
81
|
+
/**
|
|
82
|
+
* Register message handler.
|
|
83
|
+
*/
|
|
84
|
+
onMessage(handler: (message: ChannelMessage) => Promise<void>): void;
|
|
85
|
+
/**
|
|
86
|
+
* Stream a text chunk directly to the terminal (no buffering).
|
|
87
|
+
* Called by the event handler in bootstrap for real-time token streaming.
|
|
88
|
+
*/
|
|
89
|
+
streamText(text: string): void;
|
|
90
|
+
/**
|
|
91
|
+
* Write directly to output stream (utility for commands).
|
|
92
|
+
*/
|
|
93
|
+
private write;
|
|
94
|
+
/**
|
|
95
|
+
* Clear last status lines (legacy compatibility helper).
|
|
96
|
+
*/
|
|
97
|
+
private clearLastStatus;
|
|
98
|
+
}
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { TUI, ProcessTerminal, Editor, Markdown, Loader, CombinedAutocompleteProvider, Container } from '@earendil-works/pi-tui';
|
|
3
|
+
import { TuiRenderer } from './tui-renderer.js';
|
|
4
|
+
import { versionString } from '../../utils/version.js';
|
|
5
|
+
import { Config } from '../../config/config.js';
|
|
6
|
+
/**
|
|
7
|
+
* Custom Terminal implementation wrapping Readable and Writable streams.
|
|
8
|
+
* Used for testing and custom I/O redirection.
|
|
9
|
+
*/
|
|
10
|
+
export class StreamTerminal {
|
|
11
|
+
input;
|
|
12
|
+
output;
|
|
13
|
+
inputHandler;
|
|
14
|
+
wasRaw = false;
|
|
15
|
+
constructor(input, output) {
|
|
16
|
+
this.input = input;
|
|
17
|
+
this.output = output;
|
|
18
|
+
}
|
|
19
|
+
start(onInput, onResize) {
|
|
20
|
+
this.inputHandler = onInput;
|
|
21
|
+
this.wasRaw = this.input.isRaw || false;
|
|
22
|
+
if (this.input.setRawMode) {
|
|
23
|
+
try {
|
|
24
|
+
this.input.setRawMode(true);
|
|
25
|
+
}
|
|
26
|
+
catch { }
|
|
27
|
+
}
|
|
28
|
+
if (typeof this.input.resume === 'function') {
|
|
29
|
+
this.input.resume();
|
|
30
|
+
}
|
|
31
|
+
this.input.on('data', this.handleData);
|
|
32
|
+
}
|
|
33
|
+
handleData = (chunk) => {
|
|
34
|
+
if (this.inputHandler) {
|
|
35
|
+
this.inputHandler(chunk.toString('utf8'));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
stop() {
|
|
39
|
+
this.input.removeListener('data', this.handleData);
|
|
40
|
+
if (this.input.setRawMode) {
|
|
41
|
+
try {
|
|
42
|
+
this.input.setRawMode(this.wasRaw);
|
|
43
|
+
}
|
|
44
|
+
catch { }
|
|
45
|
+
}
|
|
46
|
+
if (typeof this.input.pause === 'function') {
|
|
47
|
+
this.input.pause();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async drainInput(maxMs = 1000, idleMs = 50) {
|
|
51
|
+
await new Promise((resolve) => setTimeout(resolve, idleMs));
|
|
52
|
+
}
|
|
53
|
+
write(data) {
|
|
54
|
+
this.output.write(data);
|
|
55
|
+
}
|
|
56
|
+
get columns() {
|
|
57
|
+
return this.output.columns || 80;
|
|
58
|
+
}
|
|
59
|
+
get rows() {
|
|
60
|
+
return this.output.rows || 24;
|
|
61
|
+
}
|
|
62
|
+
get kittyProtocolActive() {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
moveBy(lines) {
|
|
66
|
+
if (lines > 0) {
|
|
67
|
+
this.write(`\x1b[${lines}B`);
|
|
68
|
+
}
|
|
69
|
+
else if (lines < 0) {
|
|
70
|
+
this.write(`\x1b[${-lines}A`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
hideCursor() {
|
|
74
|
+
this.write('\x1b[?25l');
|
|
75
|
+
}
|
|
76
|
+
showCursor() {
|
|
77
|
+
this.write('\x1b[?25h');
|
|
78
|
+
}
|
|
79
|
+
clearLine() {
|
|
80
|
+
this.write('\x1b[K');
|
|
81
|
+
}
|
|
82
|
+
clearFromCursor() {
|
|
83
|
+
this.write('\x1b[J');
|
|
84
|
+
}
|
|
85
|
+
clearScreen() {
|
|
86
|
+
this.write('\x1b[2J\x1b[H');
|
|
87
|
+
}
|
|
88
|
+
setTitle(title) {
|
|
89
|
+
this.write(`\x1b]0;${title}\x07`);
|
|
90
|
+
}
|
|
91
|
+
setProgress(active) { }
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Terminal UI (TUI) Channel Implementation for Tars.
|
|
95
|
+
* Provides an interactive chat experience in the terminal with
|
|
96
|
+
* real-time token streaming, status updates, and markdown rendering.
|
|
97
|
+
*/
|
|
98
|
+
export class TuiChannel {
|
|
99
|
+
id = 'tui';
|
|
100
|
+
isEnabled = true;
|
|
101
|
+
messageHandler;
|
|
102
|
+
terminal;
|
|
103
|
+
tui;
|
|
104
|
+
chatContainer;
|
|
105
|
+
statusContainer;
|
|
106
|
+
editor;
|
|
107
|
+
isProcessing = false;
|
|
108
|
+
onExitCallback;
|
|
109
|
+
isStopped = false;
|
|
110
|
+
activeStreamingComponent;
|
|
111
|
+
activeStreamingText = '';
|
|
112
|
+
activeStatusComponent;
|
|
113
|
+
loader;
|
|
114
|
+
lastStatusLineCount = 0;
|
|
115
|
+
// Allow injecting custom streams for testing
|
|
116
|
+
input;
|
|
117
|
+
output;
|
|
118
|
+
constructor(opts = {}) {
|
|
119
|
+
this.input = opts.input || process.stdin;
|
|
120
|
+
this.output = opts.output || process.stdout;
|
|
121
|
+
this.onExitCallback = opts.onExit;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Start the TUI — render logo, show header, enter TUI rendering loop.
|
|
125
|
+
*/
|
|
126
|
+
async start() {
|
|
127
|
+
const config = Config.getInstance();
|
|
128
|
+
// 1. Initialize Terminal layer
|
|
129
|
+
if (this.input === process.stdin && this.output === process.stdout) {
|
|
130
|
+
this.terminal = new ProcessTerminal();
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
this.terminal = new StreamTerminal(this.input, this.output);
|
|
134
|
+
}
|
|
135
|
+
// 2. Initialize TUI manager
|
|
136
|
+
this.tui = new TUI(this.terminal);
|
|
137
|
+
// 3. Create initial static components (Logo & Header)
|
|
138
|
+
const logo = TuiRenderer.renderLogo();
|
|
139
|
+
const header = TuiRenderer.renderHeader({
|
|
140
|
+
version: versionString,
|
|
141
|
+
provider: config.piProvider,
|
|
142
|
+
model: config.piModel,
|
|
143
|
+
contextWindow: config.contextWindowTokens,
|
|
144
|
+
assistantName: config.assistantName
|
|
145
|
+
});
|
|
146
|
+
this.tui.addChild(new Markdown(logo + '\n' + header + '\n', 1, 0, TuiRenderer.markdownTheme));
|
|
147
|
+
// 4. Create Chat History Container
|
|
148
|
+
this.chatContainer = new Container();
|
|
149
|
+
this.tui.addChild(this.chatContainer);
|
|
150
|
+
// 5. Create Status updates Container (keeps status below chat but above editor)
|
|
151
|
+
this.statusContainer = new Container();
|
|
152
|
+
this.tui.addChild(this.statusContainer);
|
|
153
|
+
// 6. Create Input Editor
|
|
154
|
+
this.editor = new Editor(this.tui, TuiRenderer.editorTheme);
|
|
155
|
+
// Configure Autocomplete
|
|
156
|
+
const autocomplete = new CombinedAutocompleteProvider([
|
|
157
|
+
{ name: 'help', description: 'Show list of available commands and usage guide' },
|
|
158
|
+
{ name: 'exit', description: 'Gracefully shut down the session and exit the TUI' },
|
|
159
|
+
{
|
|
160
|
+
name: 'stats',
|
|
161
|
+
description: 'Display current session status and token statistics'
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: 'reset',
|
|
165
|
+
description: 'Clear session context and reset conversation history'
|
|
166
|
+
}
|
|
167
|
+
], process.cwd());
|
|
168
|
+
this.editor.setAutocompleteProvider(autocomplete);
|
|
169
|
+
// Setup Submit handler
|
|
170
|
+
this.editor.onSubmit = async (value) => {
|
|
171
|
+
if (this.isProcessing)
|
|
172
|
+
return;
|
|
173
|
+
const trimmed = value.trim();
|
|
174
|
+
if (!trimmed)
|
|
175
|
+
return;
|
|
176
|
+
// Handle TUI-local commands
|
|
177
|
+
const lowerVal = trimmed.toLowerCase();
|
|
178
|
+
if (lowerVal === '/exit' || lowerVal === '/quit') {
|
|
179
|
+
this.write('\n👋 Goodbye.\n');
|
|
180
|
+
if (this.onExitCallback) {
|
|
181
|
+
await this.onExitCallback();
|
|
182
|
+
}
|
|
183
|
+
await this.stop();
|
|
184
|
+
process.exit(0);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (!this.messageHandler)
|
|
188
|
+
return;
|
|
189
|
+
// Clear input box
|
|
190
|
+
this.editor.setText('');
|
|
191
|
+
this.isProcessing = true;
|
|
192
|
+
this.editor.disableSubmit = true;
|
|
193
|
+
// Reset active stream states
|
|
194
|
+
this.activeStreamingComponent = undefined;
|
|
195
|
+
this.activeStreamingText = '';
|
|
196
|
+
// Add user message to history
|
|
197
|
+
this.chatContainer.addChild(new Markdown(`**❯** ${trimmed}`, 1, 0, TuiRenderer.markdownTheme));
|
|
198
|
+
this.tui.requestRender();
|
|
199
|
+
// Display "Thinking..." Loader
|
|
200
|
+
this.loader = new Loader(this.tui, (s) => chalk.yellow(s), (s) => chalk.dim(s), 'Thinking...');
|
|
201
|
+
this.tui.addChild(this.loader);
|
|
202
|
+
this.tui.requestRender();
|
|
203
|
+
const channelMessage = {
|
|
204
|
+
content: trimmed,
|
|
205
|
+
senderId: 'tui-user',
|
|
206
|
+
senderName: 'user',
|
|
207
|
+
channelId: 'tui',
|
|
208
|
+
reply: async (content) => {
|
|
209
|
+
this.clearLastStatus();
|
|
210
|
+
if (!this.tui) {
|
|
211
|
+
const formatted = TuiRenderer.formatMarkdown(content);
|
|
212
|
+
this.write(formatted + '\n');
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (this.loader) {
|
|
216
|
+
this.tui.removeChild(this.loader);
|
|
217
|
+
this.loader = undefined;
|
|
218
|
+
}
|
|
219
|
+
// Format and append response to chat history
|
|
220
|
+
this.chatContainer.addChild(new Markdown(content, 1, 0, TuiRenderer.markdownTheme));
|
|
221
|
+
this.tui.requestRender();
|
|
222
|
+
},
|
|
223
|
+
startTyping: () => { },
|
|
224
|
+
stopTyping: () => {
|
|
225
|
+
if (!this.tui) {
|
|
226
|
+
this.isProcessing = false;
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if (this.loader) {
|
|
230
|
+
this.tui.removeChild(this.loader);
|
|
231
|
+
this.loader = undefined;
|
|
232
|
+
}
|
|
233
|
+
this.isProcessing = false;
|
|
234
|
+
this.editor.disableSubmit = false;
|
|
235
|
+
this.tui.setFocus(this.editor);
|
|
236
|
+
this.tui.requestRender();
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
await this.messageHandler(channelMessage);
|
|
240
|
+
};
|
|
241
|
+
this.tui.addChild(this.editor);
|
|
242
|
+
this.tui.setFocus(this.editor);
|
|
243
|
+
// 7. Start TUI loop
|
|
244
|
+
this.tui.start();
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Stop the TUI channel.
|
|
248
|
+
*/
|
|
249
|
+
async stop() {
|
|
250
|
+
if (this.isStopped)
|
|
251
|
+
return;
|
|
252
|
+
this.isStopped = true;
|
|
253
|
+
this.tui?.stop();
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Send a proactive notification to the terminal.
|
|
257
|
+
* Used for status updates (first send) and background task notifications.
|
|
258
|
+
*/
|
|
259
|
+
async notify(content) {
|
|
260
|
+
if (!content.trim())
|
|
261
|
+
return;
|
|
262
|
+
if (!this.tui) {
|
|
263
|
+
const formatted = TuiRenderer.formatMarkdown(content);
|
|
264
|
+
this.write(formatted + '\n');
|
|
265
|
+
this.lastStatusLineCount = TuiRenderer.countLines(formatted, this.output.columns || 80);
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
// Clear existing status component if present
|
|
269
|
+
this.statusContainer.clear();
|
|
270
|
+
const statusMarkdown = new Markdown(content, 1, 0, TuiRenderer.markdownTheme);
|
|
271
|
+
this.statusContainer.addChild(statusMarkdown);
|
|
272
|
+
this.activeStatusComponent = statusMarkdown;
|
|
273
|
+
this.tui.requestRender();
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Edit the last status notification in-place using TUI states.
|
|
277
|
+
* Returns true if the edit succeeded.
|
|
278
|
+
*/
|
|
279
|
+
async editStatus(content) {
|
|
280
|
+
if (!this.tui) {
|
|
281
|
+
if (this.lastStatusLineCount <= 0)
|
|
282
|
+
return false;
|
|
283
|
+
try {
|
|
284
|
+
TuiRenderer.clearLines(this.output, this.lastStatusLineCount);
|
|
285
|
+
const formatted = TuiRenderer.formatMarkdown(content);
|
|
286
|
+
this.write(formatted + '\n');
|
|
287
|
+
this.lastStatusLineCount = TuiRenderer.countLines(formatted, this.output.columns || 80);
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
catch {
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (!this.activeStatusComponent)
|
|
295
|
+
return false;
|
|
296
|
+
this.activeStatusComponent.setText(content);
|
|
297
|
+
this.tui.requestRender();
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Clear the tracked status message.
|
|
302
|
+
*/
|
|
303
|
+
clearStatus() {
|
|
304
|
+
if (!this.tui) {
|
|
305
|
+
if (this.lastStatusLineCount > 0) {
|
|
306
|
+
try {
|
|
307
|
+
TuiRenderer.clearLines(this.output, this.lastStatusLineCount);
|
|
308
|
+
}
|
|
309
|
+
catch { }
|
|
310
|
+
}
|
|
311
|
+
this.lastStatusLineCount = 0;
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
this.statusContainer.clear();
|
|
315
|
+
this.activeStatusComponent = undefined;
|
|
316
|
+
this.tui.requestRender();
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Register message handler.
|
|
320
|
+
*/
|
|
321
|
+
onMessage(handler) {
|
|
322
|
+
this.messageHandler = handler;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Stream a text chunk directly to the terminal (no buffering).
|
|
326
|
+
* Called by the event handler in bootstrap for real-time token streaming.
|
|
327
|
+
*/
|
|
328
|
+
streamText(text) {
|
|
329
|
+
if (!this.tui) {
|
|
330
|
+
this.write(text);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
// Remove loader spinner if active
|
|
334
|
+
if (this.loader) {
|
|
335
|
+
this.tui.removeChild(this.loader);
|
|
336
|
+
this.loader = undefined;
|
|
337
|
+
}
|
|
338
|
+
if (!this.activeStreamingComponent) {
|
|
339
|
+
this.activeStreamingComponent = new Markdown(text, 1, 0, TuiRenderer.markdownTheme);
|
|
340
|
+
this.chatContainer.addChild(this.activeStreamingComponent);
|
|
341
|
+
this.activeStreamingText = text;
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
this.activeStreamingText += text;
|
|
345
|
+
this.activeStreamingComponent.setText(this.activeStreamingText);
|
|
346
|
+
}
|
|
347
|
+
this.tui.requestRender();
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Write directly to output stream (utility for commands).
|
|
351
|
+
*/
|
|
352
|
+
write(text) {
|
|
353
|
+
this.output.write(text);
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Clear last status lines (legacy compatibility helper).
|
|
357
|
+
*/
|
|
358
|
+
clearLastStatus() {
|
|
359
|
+
this.clearStatus();
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
//# sourceMappingURL=tui-channel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tui-channel.js","sourceRoot":"","sources":["../../../src/channels/tui/tui-channel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACH,GAAG,EACH,eAAe,EACf,MAAM,EACN,QAAQ,EACR,MAAM,EACN,4BAA4B,EAC5B,SAAS,EACZ,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD;;;GAGG;AACH,MAAM,OAAO,cAAc;IACN,KAAK,CAAwB;IAC7B,MAAM,CAAwB;IACvC,YAAY,CAA0B;IACtC,MAAM,GAAG,KAAK,CAAC;IAEvB,YAAY,KAA4B,EAAE,MAA6B;QACnE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,OAA+B,EAAE,QAAoB;QACvD,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC;QAC5B,IA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AAI,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;YAC3D,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC;QACpC,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,mBAAmB,IAAI,IAAI,CAAC;YACjC,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACpE,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;IAC7B,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,IAAY;QACtB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAED;;OAEG;IACK,eAAe;QACnB,IAAI,CAAC,WAAW,EAAE,CAAC;IACvB,CAAC;CACJ"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { EditorTheme, MarkdownTheme, SelectListTheme } from '@earendil-works/pi-tui';
|
|
2
|
+
/**
|
|
3
|
+
* Terminal rendering utilities and themes for the Tars TUI chat interface.
|
|
4
|
+
*/
|
|
5
|
+
export declare class TuiRenderer {
|
|
6
|
+
/**
|
|
7
|
+
* Render the ASCII logo in cyan.
|
|
8
|
+
*/
|
|
9
|
+
static renderLogo(): string;
|
|
10
|
+
/**
|
|
11
|
+
* Render the session metadata header.
|
|
12
|
+
*/
|
|
13
|
+
static renderHeader(opts: {
|
|
14
|
+
version: string;
|
|
15
|
+
provider: string;
|
|
16
|
+
model: string;
|
|
17
|
+
contextWindow: number;
|
|
18
|
+
assistantName: string;
|
|
19
|
+
}): string;
|
|
20
|
+
/**
|
|
21
|
+
* Tars custom SelectListTheme.
|
|
22
|
+
*/
|
|
23
|
+
static readonly selectListTheme: SelectListTheme;
|
|
24
|
+
/**
|
|
25
|
+
* Tars custom MarkdownTheme.
|
|
26
|
+
*/
|
|
27
|
+
static readonly markdownTheme: MarkdownTheme;
|
|
28
|
+
/**
|
|
29
|
+
* Tars custom EditorTheme.
|
|
30
|
+
*/
|
|
31
|
+
static readonly editorTheme: EditorTheme;
|
|
32
|
+
/**
|
|
33
|
+
* Render the token stats in the footer.
|
|
34
|
+
*/
|
|
35
|
+
static renderFooter(tokens: number, contextLimit: number, cost: number): string;
|
|
36
|
+
/**
|
|
37
|
+
* Format basic Markdown syntax (bold, inline code) for non-TUI fallback output.
|
|
38
|
+
*/
|
|
39
|
+
static formatMarkdown(text: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Count the number of terminal lines required to display the text, accounting for wrapping.
|
|
42
|
+
*/
|
|
43
|
+
static countLines(text: string, columns?: number): number;
|
|
44
|
+
/**
|
|
45
|
+
* Clear the specified number of lines from the terminal.
|
|
46
|
+
*/
|
|
47
|
+
static clearLines(stream: NodeJS.WritableStream, linesCount: number): void;
|
|
48
|
+
}
|
|
49
|
+
export default TuiRenderer;
|