@saturn-universe/cli 0.0.0-stage → 0.1.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/LICENSE +661 -0
- package/dist/attach.d.ts +9 -0
- package/dist/attach.js +80 -0
- package/dist/auth-config.d.ts +31 -0
- package/dist/auth-config.js +285 -0
- package/dist/choice-menu.d.ts +13 -0
- package/dist/choice-menu.js +238 -0
- package/dist/cli-diagnostics.d.ts +23 -0
- package/dist/cli-diagnostics.js +42 -0
- package/dist/cli-help.d.ts +6 -0
- package/dist/cli-help.js +163 -0
- package/dist/client.d.ts +13 -0
- package/dist/client.js +90 -0
- package/dist/commands.d.ts +64 -0
- package/dist/commands.js +299 -0
- package/dist/compaction-command.d.ts +16 -0
- package/dist/compaction-command.js +16 -0
- package/dist/composer.d.ts +88 -0
- package/dist/composer.js +124 -0
- package/dist/config-cli.d.ts +1 -0
- package/dist/config-cli.js +47 -0
- package/dist/config-file.d.ts +1 -0
- package/dist/config-file.js +43 -0
- package/dist/config-lock.d.ts +5 -0
- package/dist/config-lock.js +45 -0
- package/dist/duration.d.ts +2 -0
- package/dist/duration.js +11 -0
- package/dist/export.d.ts +19 -0
- package/dist/export.js +66 -0
- package/dist/host-command.d.ts +40 -0
- package/dist/host-command.js +48 -0
- package/dist/host-launcher.d.ts +22 -0
- package/dist/host-launcher.js +300 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +400 -0
- package/dist/markdown.d.ts +1 -0
- package/dist/markdown.js +118 -0
- package/dist/mcp-cli.d.ts +44 -0
- package/dist/mcp-cli.js +647 -0
- package/dist/menu.d.ts +7 -0
- package/dist/menu.js +91 -0
- package/dist/project-mcp-config.d.ts +9 -0
- package/dist/project-mcp-config.js +98 -0
- package/dist/provider-discovery.d.ts +26 -0
- package/dist/provider-discovery.js +138 -0
- package/dist/provider-pricing.d.ts +3 -0
- package/dist/provider-pricing.js +130 -0
- package/dist/provider.d.ts +16 -0
- package/dist/provider.js +370 -0
- package/dist/reconcile-command.d.ts +36 -0
- package/dist/reconcile-command.js +64 -0
- package/dist/renderer.d.ts +204 -0
- package/dist/renderer.js +1134 -0
- package/dist/repl-host.d.ts +22 -0
- package/dist/repl-host.js +51 -0
- package/dist/repl-run-observer.d.ts +27 -0
- package/dist/repl-run-observer.js +86 -0
- package/dist/repl.d.ts +12 -0
- package/dist/repl.js +1834 -0
- package/dist/results.d.ts +23 -0
- package/dist/results.js +1 -0
- package/dist/sandbox-cli.d.ts +39 -0
- package/dist/sandbox-cli.js +324 -0
- package/dist/session-history.d.ts +17 -0
- package/dist/session-history.js +76 -0
- package/dist/settings-menu.d.ts +2 -0
- package/dist/settings-menu.js +111 -0
- package/dist/skill-cli.d.ts +25 -0
- package/dist/skill-cli.js +355 -0
- package/dist/slash-commands.d.ts +66 -0
- package/dist/slash-commands.js +1449 -0
- package/dist/terminal-input.d.ts +24 -0
- package/dist/terminal-input.js +111 -0
- package/dist/terminal-selection.d.ts +21 -0
- package/dist/terminal-selection.js +72 -0
- package/dist/terminal-text.d.ts +38 -0
- package/dist/terminal-text.js +238 -0
- package/dist/tui.d.ts +170 -0
- package/dist/tui.js +2559 -0
- package/dist/usage.d.ts +13 -0
- package/dist/usage.js +46 -0
- package/dist/user-config.d.ts +48 -0
- package/dist/user-config.js +188 -0
- package/package.json +18 -3
- package/README.md +0 -3
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Key } from 'node:readline';
|
|
2
|
+
export declare function decodeEnhancedKey(sequence: string): {
|
|
3
|
+
text?: string;
|
|
4
|
+
key: Key;
|
|
5
|
+
} | undefined;
|
|
6
|
+
export interface TerminalWheelEvent {
|
|
7
|
+
readonly x: number;
|
|
8
|
+
readonly y: number;
|
|
9
|
+
readonly direction: -1 | 1;
|
|
10
|
+
}
|
|
11
|
+
export interface TerminalSelectionEvent {
|
|
12
|
+
readonly x: number;
|
|
13
|
+
readonly y: number;
|
|
14
|
+
readonly kind: 'down' | 'drag' | 'up';
|
|
15
|
+
}
|
|
16
|
+
export interface TerminalRightClickEvent {
|
|
17
|
+
readonly x: number;
|
|
18
|
+
readonly y: number;
|
|
19
|
+
readonly kind: 'down' | 'up';
|
|
20
|
+
}
|
|
21
|
+
export declare function createTerminalInput(keyboard: (text: string) => void, wheel: (event: TerminalWheelEvent) => void, select?: (event: TerminalSelectionEvent) => void, rightClick?: (event: TerminalRightClickEvent) => void): {
|
|
22
|
+
write(chunk: Buffer | string): void;
|
|
23
|
+
reset(): void;
|
|
24
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
2
|
+
const mousePrefix = '\x1b[<';
|
|
3
|
+
const mouseReport = /^(\d{1,3});(\d{1,7});(\d{1,7})([Mm])$/;
|
|
4
|
+
const partialReportTimeout = 50;
|
|
5
|
+
const csi = '\x1b[';
|
|
6
|
+
const csiFields = /^[0-?]*[ -/]*/;
|
|
7
|
+
export function decodeEnhancedKey(sequence) {
|
|
8
|
+
const kitty = /^\x1b\[(\d+)(?::[\d:]*)?(?:;(\d+)(?::[12])?)?u$/.exec(sequence);
|
|
9
|
+
const xterm = /^\x1b\[27;(\d+);(\d+)~$/.exec(sequence);
|
|
10
|
+
if (!kitty && !xterm)
|
|
11
|
+
return;
|
|
12
|
+
const code = Number(kitty?.[1] ?? xterm?.[2]);
|
|
13
|
+
if (code > 0x10ffff)
|
|
14
|
+
return;
|
|
15
|
+
const modifiers = Number(kitty?.[2] ?? xterm?.[1] ?? 1) - 1;
|
|
16
|
+
const ctrl = Boolean(modifiers & 4);
|
|
17
|
+
const meta = Boolean(modifiers & (2 | 32));
|
|
18
|
+
const shift = Boolean(modifiers & 1);
|
|
19
|
+
const char = String.fromCodePoint(code);
|
|
20
|
+
const aliases = {
|
|
21
|
+
8: 'backspace',
|
|
22
|
+
9: 'tab',
|
|
23
|
+
10: 'enter',
|
|
24
|
+
13: 'return',
|
|
25
|
+
27: 'escape',
|
|
26
|
+
32: 'space',
|
|
27
|
+
127: 'backspace',
|
|
28
|
+
57414: 'return',
|
|
29
|
+
};
|
|
30
|
+
const name = aliases[code] ?? char.toLowerCase();
|
|
31
|
+
const key = { sequence, name, ctrl, meta, shift };
|
|
32
|
+
return !ctrl && !meta && code >= 32 && code !== 127 && !(code >= 57344 && code <= 63743)
|
|
33
|
+
? { key, text: char }
|
|
34
|
+
: { key };
|
|
35
|
+
}
|
|
36
|
+
export function createTerminalInput(keyboard, wheel, select, rightClick) {
|
|
37
|
+
let decoder = new StringDecoder('utf8');
|
|
38
|
+
let pending = '';
|
|
39
|
+
let timer;
|
|
40
|
+
function flushPartial() {
|
|
41
|
+
const partial = pending;
|
|
42
|
+
pending = '';
|
|
43
|
+
// A truncated mouse report has no keyboard meaning. A bare Escape still does.
|
|
44
|
+
if (partial && !partial.startsWith(mousePrefix))
|
|
45
|
+
keyboard(partial);
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
write(chunk) {
|
|
49
|
+
clearTimeout(timer);
|
|
50
|
+
const input = pending + (typeof chunk === 'string' ? chunk : decoder.write(chunk));
|
|
51
|
+
pending = '';
|
|
52
|
+
let cursor = 0;
|
|
53
|
+
for (let start = input.indexOf(csi); start >= 0; start = input.indexOf(csi, cursor)) {
|
|
54
|
+
if (start > cursor)
|
|
55
|
+
keyboard(input.slice(cursor, start));
|
|
56
|
+
const isMouse = input.startsWith(mousePrefix, start);
|
|
57
|
+
const prefixLength = isMouse ? mousePrefix.length : csi.length;
|
|
58
|
+
const fields = (isMouse ? /^[0-9;]*/ : csiFields).exec(input.slice(start + prefixLength))[0];
|
|
59
|
+
const end = start + prefixLength + fields.length;
|
|
60
|
+
if (end === input.length) {
|
|
61
|
+
// Keep only plausible incomplete reports between input chunks.
|
|
62
|
+
if (fields.length <= (isMouse ? 19 : 64))
|
|
63
|
+
pending = input.slice(start);
|
|
64
|
+
cursor = end;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
const terminator = input[end];
|
|
68
|
+
cursor = end;
|
|
69
|
+
if (!isMouse) {
|
|
70
|
+
if (terminator >= '@' && terminator <= '~')
|
|
71
|
+
cursor++;
|
|
72
|
+
keyboard(input.slice(start, cursor));
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (terminator !== 'M' && terminator !== 'm')
|
|
76
|
+
continue;
|
|
77
|
+
cursor++;
|
|
78
|
+
const report = mouseReport.exec(fields + terminator);
|
|
79
|
+
if (!report)
|
|
80
|
+
continue;
|
|
81
|
+
const button = Number(report[1]) & ~28; // Strip Shift, Alt and Ctrl.
|
|
82
|
+
const point = { x: Number(report[2]), y: Number(report[3]) };
|
|
83
|
+
if (report[4] === 'M' && (button === 64 || button === 65)) {
|
|
84
|
+
wheel({ ...point, direction: button === 64 ? -1 : 1 });
|
|
85
|
+
}
|
|
86
|
+
else if (button === 0 || (button === 32 && report[4] === 'M')) {
|
|
87
|
+
select?.({ ...point, kind: report[4] === 'm' ? 'up' : button === 32 ? 'drag' : 'down' });
|
|
88
|
+
}
|
|
89
|
+
else if (button === 2) {
|
|
90
|
+
rightClick?.({ ...point, kind: report[4] === 'm' ? 'up' : 'down' });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const tail = input.slice(cursor);
|
|
94
|
+
const partialPrefix = tail.endsWith('\x1b[') ? 2 : tail.endsWith('\x1b') ? 1 : 0;
|
|
95
|
+
if (partialPrefix)
|
|
96
|
+
pending = tail.slice(-partialPrefix);
|
|
97
|
+
const keys = tail.slice(0, tail.length - partialPrefix);
|
|
98
|
+
if (keys)
|
|
99
|
+
keyboard(keys);
|
|
100
|
+
if (pending) {
|
|
101
|
+
timer = setTimeout(flushPartial, partialReportTimeout);
|
|
102
|
+
timer.unref();
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
reset() {
|
|
106
|
+
clearTimeout(timer);
|
|
107
|
+
pending = '';
|
|
108
|
+
decoder = new StringDecoder('utf8');
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface SelectionRow {
|
|
2
|
+
readonly text: string;
|
|
3
|
+
readonly indent: number;
|
|
4
|
+
readonly soft: boolean;
|
|
5
|
+
readonly columns: number;
|
|
6
|
+
}
|
|
7
|
+
export interface SelectionPoint {
|
|
8
|
+
readonly x: number;
|
|
9
|
+
readonly y: number;
|
|
10
|
+
}
|
|
11
|
+
export declare function selectRows(rows: readonly SelectionRow[], anchor: SelectionPoint, end: SelectionPoint): {
|
|
12
|
+
firstRow: number;
|
|
13
|
+
parts: {
|
|
14
|
+
from: number;
|
|
15
|
+
to: number;
|
|
16
|
+
text: string;
|
|
17
|
+
soft: boolean;
|
|
18
|
+
}[];
|
|
19
|
+
text: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function copySelection(text: string, send: (sequence: string) => void): Promise<"unavailable" | "copied" | "sent">;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { constants } from 'node:fs';
|
|
3
|
+
import { access } from 'node:fs/promises';
|
|
4
|
+
import { displayGraphemes, stripAnsi } from './terminal-text.js';
|
|
5
|
+
export function selectRows(rows, anchor, end) {
|
|
6
|
+
const [first, last] = anchor.y < end.y || (anchor.y === end.y && anchor.x <= end.x) ? [anchor, end] : [end, anchor];
|
|
7
|
+
const parts = [];
|
|
8
|
+
for (let y = first.y; y <= last.y; y++) {
|
|
9
|
+
const row = rows[y - 1];
|
|
10
|
+
const start = y === first.y ? first.x - 1 : 0;
|
|
11
|
+
const stop = Math.min(row.columns, y === last.y ? last.x : Infinity);
|
|
12
|
+
let column = row.indent;
|
|
13
|
+
let from = -1;
|
|
14
|
+
let to = -1;
|
|
15
|
+
let text = '';
|
|
16
|
+
for (const { segment, width } of displayGraphemes(stripAnsi(row.text))) {
|
|
17
|
+
if (column + width > row.columns || column >= stop)
|
|
18
|
+
break;
|
|
19
|
+
if (column + width > start) {
|
|
20
|
+
if (from < 0)
|
|
21
|
+
from = column;
|
|
22
|
+
to = column + width;
|
|
23
|
+
text += segment;
|
|
24
|
+
}
|
|
25
|
+
column += width;
|
|
26
|
+
}
|
|
27
|
+
parts.push({ from, to, text, soft: row.soft });
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
firstRow: first.y - 1,
|
|
31
|
+
parts,
|
|
32
|
+
text: parts.map((part, i) => (i && !part.soft ? '\n' : '') + part.text).join(''),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
async function writeWindowsClipboard(text) {
|
|
36
|
+
const system32 = process.platform === 'win32'
|
|
37
|
+
? (process.env.SystemRoot ?? 'C:\\Windows') + '\\System32\\'
|
|
38
|
+
: '/mnt/c/Windows/System32/';
|
|
39
|
+
const executable = system32 +
|
|
40
|
+
(process.platform === 'win32'
|
|
41
|
+
? 'WindowsPowerShell\\v1.0\\powershell.exe'
|
|
42
|
+
: 'WindowsPowerShell/v1.0/powershell.exe');
|
|
43
|
+
try {
|
|
44
|
+
await access(executable, constants.X_OK);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return new Promise((resolve) => {
|
|
50
|
+
const child = spawn(executable, [
|
|
51
|
+
'-NoProfile',
|
|
52
|
+
'-NonInteractive',
|
|
53
|
+
'-Command',
|
|
54
|
+
"[Console]::InputEncoding = [Text.Encoding]::UTF8; $ErrorActionPreference = 'Stop'; Set-Clipboard -Value ([Console]::In.ReadToEnd())",
|
|
55
|
+
], { stdio: ['pipe', 'ignore', 'ignore'], windowsHide: true, timeout: 3000 });
|
|
56
|
+
child.once('error', () => resolve(false));
|
|
57
|
+
child.once('close', (code) => resolve(code === 0));
|
|
58
|
+
child.stdin.on('error', () => resolve(false));
|
|
59
|
+
child.stdin.end(text, 'utf8');
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
export async function copySelection(text, send) {
|
|
63
|
+
if ((process.platform === 'win32' || process.env.WSL_DISTRO_NAME || process.env.WSL_INTEROP) &&
|
|
64
|
+
(await writeWindowsClipboard(text)))
|
|
65
|
+
return 'copied';
|
|
66
|
+
if (process.env.TERM === 'dumb' || Buffer.byteLength(text) > 64 * 1024)
|
|
67
|
+
return 'unavailable';
|
|
68
|
+
const payload = Buffer.from(text, 'utf8').toString('base64');
|
|
69
|
+
const sequence = '\x1b]52;c;' + payload + '\x07';
|
|
70
|
+
send(process.env.TMUX ? '\x1bPtmux;\x1b' + sequence + '\x1b\\' : sequence);
|
|
71
|
+
return 'sent';
|
|
72
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare function terminalColorEnabled(override?: boolean): boolean;
|
|
2
|
+
export declare function paintSgr(code: string, text: string, colored: boolean): string;
|
|
3
|
+
export declare function createTerminalPainter(override?: boolean): {
|
|
4
|
+
readonly colored: boolean;
|
|
5
|
+
bold: (text: string) => string;
|
|
6
|
+
dim: (text: string) => string;
|
|
7
|
+
dimItalic: (text: string) => string;
|
|
8
|
+
thinkingItalic: (text: string) => string;
|
|
9
|
+
light: (text: string) => string;
|
|
10
|
+
cyan: (text: string) => string;
|
|
11
|
+
brightCyan: (text: string) => string;
|
|
12
|
+
green: (text: string) => string;
|
|
13
|
+
yellow: (text: string) => string;
|
|
14
|
+
gold: (text: string) => string;
|
|
15
|
+
red: (text: string) => string;
|
|
16
|
+
magenta: (text: string) => string;
|
|
17
|
+
white: (text: string) => string;
|
|
18
|
+
whiteBold: (text: string) => string;
|
|
19
|
+
};
|
|
20
|
+
export type TerminalPainter = ReturnType<typeof createTerminalPainter>;
|
|
21
|
+
export declare function segmentGraphemes(text: string): Intl.Segments;
|
|
22
|
+
export declare function stripAnsi(text: string): string;
|
|
23
|
+
export declare function displayGraphemes(text: string): Generator<{
|
|
24
|
+
index: number;
|
|
25
|
+
segment: string;
|
|
26
|
+
width: number;
|
|
27
|
+
}, void, unknown>;
|
|
28
|
+
export declare function stringDisplayWidth(text: string): number;
|
|
29
|
+
export declare function truncateDisplay(text: string, maxWidth: number): string;
|
|
30
|
+
export declare function truncateMiddle(text: string, maxWidth: number): string;
|
|
31
|
+
export declare function truncateDisplayPath(text: string, maxWidth: number): string;
|
|
32
|
+
export declare function wrapDisplayRanges(text: string, maxWidth: number): Generator<{
|
|
33
|
+
start: number;
|
|
34
|
+
end: number;
|
|
35
|
+
soft: boolean;
|
|
36
|
+
}, void, unknown>;
|
|
37
|
+
export declare function wrapTextByWidth(text: string, maxWidth: number, softWraps?: Set<number>): string[];
|
|
38
|
+
export declare function padEndDisplay(text: string, width: number): string;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
const ANSI_ESCAPE = /\x1b(?:\[[0-9;?]*[A-Za-z]|\][^\x07]*?(?:\x07|\x1b\\))/g;
|
|
2
|
+
const graphemes = new Intl.Segmenter();
|
|
3
|
+
const emojiPresentation = new RegExp('^\\p{RGI_Emoji}$', 'v');
|
|
4
|
+
const printableAscii = /^[\x20-\x7e]*$/;
|
|
5
|
+
const SGR_RESET = '\x1b[0m';
|
|
6
|
+
export function terminalColorEnabled(override) {
|
|
7
|
+
if (override !== undefined)
|
|
8
|
+
return override;
|
|
9
|
+
return Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
|
|
10
|
+
}
|
|
11
|
+
export function paintSgr(code, text, colored) {
|
|
12
|
+
return colored ? `\x1b[${code}m${text}${SGR_RESET}` : text;
|
|
13
|
+
}
|
|
14
|
+
export function createTerminalPainter(override) {
|
|
15
|
+
const paint = (code, text) => paintSgr(code, text, terminalColorEnabled(override));
|
|
16
|
+
return {
|
|
17
|
+
get colored() {
|
|
18
|
+
return terminalColorEnabled(override);
|
|
19
|
+
},
|
|
20
|
+
bold: (text) => paint('1', text),
|
|
21
|
+
dim: (text) => paint('2', text),
|
|
22
|
+
dimItalic: (text) => paint('2;3', text),
|
|
23
|
+
thinkingItalic: (text) => paint('3;38;2;168;178;195', text),
|
|
24
|
+
light: (text) => paint('38;2;226;232;240', text),
|
|
25
|
+
cyan: (text) => paint('36', text),
|
|
26
|
+
brightCyan: (text) => paint('96', text),
|
|
27
|
+
green: (text) => paint('32', text),
|
|
28
|
+
yellow: (text) => paint('33', text),
|
|
29
|
+
gold: (text) => paint('1;33', text),
|
|
30
|
+
red: (text) => paint('31', text),
|
|
31
|
+
magenta: (text) => paint('35', text),
|
|
32
|
+
white: (text) => paint('97', text),
|
|
33
|
+
whiteBold: (text) => paint('1;97', text),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export function segmentGraphemes(text) {
|
|
37
|
+
return graphemes.segment(text);
|
|
38
|
+
}
|
|
39
|
+
export function stripAnsi(text) {
|
|
40
|
+
return text.replace(ANSI_ESCAPE, '');
|
|
41
|
+
}
|
|
42
|
+
function isZeroWidthCodePoint(cp) {
|
|
43
|
+
return (cp < 0x20 ||
|
|
44
|
+
(cp >= 0x7f && cp < 0xa0) ||
|
|
45
|
+
(cp >= 0x0300 && cp <= 0x036f) ||
|
|
46
|
+
(cp >= 0x1ab0 && cp <= 0x1aff) ||
|
|
47
|
+
(cp >= 0x1dc0 && cp <= 0x1dff) ||
|
|
48
|
+
(cp >= 0x200b && cp <= 0x200f) ||
|
|
49
|
+
(cp >= 0x2028 && cp <= 0x202e) ||
|
|
50
|
+
(cp >= 0x2060 && cp <= 0x206f) ||
|
|
51
|
+
(cp >= 0x20d0 && cp <= 0x20ff) ||
|
|
52
|
+
(cp >= 0xfe00 && cp <= 0xfe0f) ||
|
|
53
|
+
(cp >= 0xfe20 && cp <= 0xfe2f) ||
|
|
54
|
+
cp === 0xfeff);
|
|
55
|
+
}
|
|
56
|
+
function isWideCodePoint(cp) {
|
|
57
|
+
return ((cp >= 0x1100 && cp <= 0x115f) ||
|
|
58
|
+
cp === 0x2329 ||
|
|
59
|
+
cp === 0x232a ||
|
|
60
|
+
(cp >= 0x2e80 && cp <= 0x303e) ||
|
|
61
|
+
(cp >= 0x3040 && cp <= 0x3247) ||
|
|
62
|
+
(cp >= 0x3250 && cp <= 0x4dbf) ||
|
|
63
|
+
(cp >= 0x4e00 && cp <= 0xa4c6) ||
|
|
64
|
+
(cp >= 0xa960 && cp <= 0xa97c) ||
|
|
65
|
+
(cp >= 0xac00 && cp <= 0xd7a3) ||
|
|
66
|
+
(cp >= 0xf900 && cp <= 0xfaff) ||
|
|
67
|
+
(cp >= 0xfe10 && cp <= 0xfe19) ||
|
|
68
|
+
(cp >= 0xfe30 && cp <= 0xfe6b) ||
|
|
69
|
+
(cp >= 0xff01 && cp <= 0xff60) ||
|
|
70
|
+
(cp >= 0xffe0 && cp <= 0xffe6) ||
|
|
71
|
+
(cp >= 0x1b000 && cp <= 0x1b001) ||
|
|
72
|
+
(cp >= 0x1f200 && cp <= 0x1f251) ||
|
|
73
|
+
(cp >= 0x1f300 && cp <= 0x1f9ff) ||
|
|
74
|
+
(cp >= 0x1fa00 && cp <= 0x1faff) ||
|
|
75
|
+
(cp >= 0x20000 && cp <= 0x2fffd) ||
|
|
76
|
+
(cp >= 0x30000 && cp <= 0x3fffd));
|
|
77
|
+
}
|
|
78
|
+
function charDisplayWidth(ch) {
|
|
79
|
+
const cp = ch.codePointAt(0);
|
|
80
|
+
if (cp === undefined || isZeroWidthCodePoint(cp))
|
|
81
|
+
return 0;
|
|
82
|
+
return isWideCodePoint(cp) ? 2 : 1;
|
|
83
|
+
}
|
|
84
|
+
export function* displayGraphemes(text) {
|
|
85
|
+
if (printableAscii.test(text)) {
|
|
86
|
+
for (let index = 0; index < text.length; index++)
|
|
87
|
+
yield { index, segment: text[index], width: 1 };
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
for (const { index, segment } of segmentGraphemes(text)) {
|
|
91
|
+
let width = 0;
|
|
92
|
+
if (emojiPresentation.test(segment))
|
|
93
|
+
width = 2;
|
|
94
|
+
else
|
|
95
|
+
for (const ch of segment)
|
|
96
|
+
width += charDisplayWidth(ch);
|
|
97
|
+
yield { index, segment, width };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
export function stringDisplayWidth(text) {
|
|
101
|
+
const visible = stripAnsi(text);
|
|
102
|
+
if (printableAscii.test(visible))
|
|
103
|
+
return visible.length;
|
|
104
|
+
let width = 0;
|
|
105
|
+
for (const grapheme of displayGraphemes(visible))
|
|
106
|
+
width += grapheme.width;
|
|
107
|
+
return width;
|
|
108
|
+
}
|
|
109
|
+
function* displayTokens(text) {
|
|
110
|
+
const escapes = text.matchAll(ANSI_ESCAPE);
|
|
111
|
+
let escape = escapes.next().value;
|
|
112
|
+
const visible = escape ? stripAnsi(text) : text;
|
|
113
|
+
let hidden = 0;
|
|
114
|
+
for (const { index, segment, width } of displayGraphemes(visible)) {
|
|
115
|
+
// Standalone controls keep their original position at a wrapping boundary.
|
|
116
|
+
while (escape && escape.index === index + hidden) {
|
|
117
|
+
yield { end: escape.index + escape[0].length, width: 0, hasAnsi: true };
|
|
118
|
+
hidden += escape[0].length;
|
|
119
|
+
escape = escapes.next().value;
|
|
120
|
+
}
|
|
121
|
+
const hiddenBefore = hidden;
|
|
122
|
+
const end = index + segment.length;
|
|
123
|
+
while (escape && escape.index < end + hidden) {
|
|
124
|
+
hidden += escape[0].length;
|
|
125
|
+
escape = escapes.next().value;
|
|
126
|
+
}
|
|
127
|
+
yield { end: end + hidden, width, hasAnsi: hidden !== hiddenBefore };
|
|
128
|
+
}
|
|
129
|
+
while (escape) {
|
|
130
|
+
yield { end: escape.index + escape[0].length, width: 0, hasAnsi: true };
|
|
131
|
+
escape = escapes.next().value;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export function truncateDisplay(text, maxWidth) {
|
|
135
|
+
if (maxWidth <= 0)
|
|
136
|
+
return '';
|
|
137
|
+
let width = 0;
|
|
138
|
+
let end = 0;
|
|
139
|
+
let hasAnsi = false;
|
|
140
|
+
for (const token of displayTokens(text)) {
|
|
141
|
+
if (width + token.width > maxWidth)
|
|
142
|
+
return text.slice(0, end) + (hasAnsi ? SGR_RESET : '');
|
|
143
|
+
end = token.end;
|
|
144
|
+
width += token.width;
|
|
145
|
+
hasAnsi ||= token.hasAnsi;
|
|
146
|
+
}
|
|
147
|
+
return text;
|
|
148
|
+
}
|
|
149
|
+
export function truncateMiddle(text, maxWidth) {
|
|
150
|
+
if (stringDisplayWidth(text) <= maxWidth)
|
|
151
|
+
return text;
|
|
152
|
+
if (maxWidth <= 3)
|
|
153
|
+
return truncateDisplay(text, maxWidth);
|
|
154
|
+
return abbreviateMiddle(stripAnsi(text), maxWidth, '...');
|
|
155
|
+
}
|
|
156
|
+
function abbreviateMiddle(text, maxWidth, marker) {
|
|
157
|
+
const characters = [...displayGraphemes(text)];
|
|
158
|
+
const remaining = maxWidth - stringDisplayWidth(marker);
|
|
159
|
+
const leftBudget = Math.max(1, Math.floor(remaining * 0.4));
|
|
160
|
+
const rightBudget = Math.max(0, remaining - leftBudget);
|
|
161
|
+
let left = '';
|
|
162
|
+
let lw = 0;
|
|
163
|
+
for (const { segment, width } of characters) {
|
|
164
|
+
if (lw + width > leftBudget)
|
|
165
|
+
break;
|
|
166
|
+
left += segment;
|
|
167
|
+
lw += width;
|
|
168
|
+
}
|
|
169
|
+
let right = '';
|
|
170
|
+
let rw = 0;
|
|
171
|
+
for (let i = characters.length - 1; i >= 0; i--) {
|
|
172
|
+
const { segment, width } = characters[i];
|
|
173
|
+
if (rw + width > rightBudget)
|
|
174
|
+
break;
|
|
175
|
+
right = segment + right;
|
|
176
|
+
rw += width;
|
|
177
|
+
}
|
|
178
|
+
return left + marker + right;
|
|
179
|
+
}
|
|
180
|
+
export function truncateDisplayPath(text, maxWidth) {
|
|
181
|
+
if (stringDisplayWidth(text) <= maxWidth)
|
|
182
|
+
return text;
|
|
183
|
+
if (maxWidth <= 1)
|
|
184
|
+
return truncateDisplay(text, maxWidth);
|
|
185
|
+
const lastSeparator = Math.max(text.lastIndexOf('/'), text.lastIndexOf('\\'));
|
|
186
|
+
if (lastSeparator > 0) {
|
|
187
|
+
const tail = text.slice(lastSeparator);
|
|
188
|
+
const tailWidth = stringDisplayWidth(tail);
|
|
189
|
+
if (tailWidth <= maxWidth - 3) {
|
|
190
|
+
const leftBudget = maxWidth - 1 - tailWidth;
|
|
191
|
+
let prefix = truncateDisplay(text.slice(0, lastSeparator), leftBudget);
|
|
192
|
+
const separator = Math.max(prefix.lastIndexOf('/'), prefix.lastIndexOf('\\'));
|
|
193
|
+
const parent = prefix.slice(0, separator + 1);
|
|
194
|
+
if (stringDisplayWidth(parent) >= Math.ceil(leftBudget / 2))
|
|
195
|
+
prefix = parent;
|
|
196
|
+
if (prefix)
|
|
197
|
+
return `${prefix}…${tail}`;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return abbreviateMiddle(text, maxWidth, '…');
|
|
201
|
+
}
|
|
202
|
+
// Offsets refer to the original string, excluding hard newlines. Soft marks a continuation row.
|
|
203
|
+
export function* wrapDisplayRanges(text, maxWidth) {
|
|
204
|
+
const limit = Math.max(1, maxWidth);
|
|
205
|
+
let paragraphStart = 0;
|
|
206
|
+
for (const paragraph of text.split('\n')) {
|
|
207
|
+
let start = paragraphStart;
|
|
208
|
+
let end = paragraphStart;
|
|
209
|
+
let lineWidth = 0;
|
|
210
|
+
for (const { end: tokenEnd, width } of displayTokens(paragraph)) {
|
|
211
|
+
if (lineWidth > 0 && width > 0 && lineWidth + width > limit) {
|
|
212
|
+
yield { start, end, soft: start !== paragraphStart };
|
|
213
|
+
start = end;
|
|
214
|
+
lineWidth = 0;
|
|
215
|
+
}
|
|
216
|
+
end = paragraphStart + tokenEnd;
|
|
217
|
+
lineWidth += width;
|
|
218
|
+
}
|
|
219
|
+
yield { start, end, soft: start !== paragraphStart };
|
|
220
|
+
paragraphStart = end + 1;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
export function wrapTextByWidth(text, maxWidth, softWraps) {
|
|
224
|
+
const normalized = text.replace(/\r\n?/g, '\n').replace(/\t/g, ' ');
|
|
225
|
+
const out = [];
|
|
226
|
+
for (const { start, end, soft } of wrapDisplayRanges(normalized, maxWidth)) {
|
|
227
|
+
if (soft)
|
|
228
|
+
softWraps?.add(out.length);
|
|
229
|
+
out.push(normalized.slice(start, end));
|
|
230
|
+
}
|
|
231
|
+
return out;
|
|
232
|
+
}
|
|
233
|
+
export function padEndDisplay(text, width) {
|
|
234
|
+
const current = stringDisplayWidth(text);
|
|
235
|
+
if (current >= width)
|
|
236
|
+
return text;
|
|
237
|
+
return text + ' '.repeat(width - current);
|
|
238
|
+
}
|
package/dist/tui.d.ts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import type { AgentContextMetrics, HostSandboxStatus, PermissionMode, RunProgressPage, SessionListItem, TodoItem } from '@saturn-universe/protocol';
|
|
2
|
+
import type { ChoicePrompt, PaletteState, SlashCommandContext, SlashCommandHint } from './composer.js';
|
|
3
|
+
import type { ConversationEntry, PendingApprovalView } from './renderer.js';
|
|
4
|
+
import type { SelectionRow } from './terminal-selection.js';
|
|
5
|
+
export type HostPhase = 'connecting' | 'ready' | 'attached' | 'error';
|
|
6
|
+
export type TuiFocusArea = 'composer' | 'sidebar';
|
|
7
|
+
interface SidebarNavigation {
|
|
8
|
+
readonly memberIds: readonly string[];
|
|
9
|
+
readonly selectedIndex: number;
|
|
10
|
+
}
|
|
11
|
+
export interface SidebarTarget {
|
|
12
|
+
readonly row: number;
|
|
13
|
+
readonly colStart: number;
|
|
14
|
+
readonly colEnd: number;
|
|
15
|
+
readonly memberId: string;
|
|
16
|
+
}
|
|
17
|
+
export type OrbitalEntryKind = 'user' | 'assistant' | 'thinking' | 'planner' | 'team' | 'tool' | 'ledger' | 'skill' | 'web' | 'approval' | 'error' | 'system';
|
|
18
|
+
export interface OrbitalEntry extends ConversationEntry {
|
|
19
|
+
readonly kind: OrbitalEntryKind;
|
|
20
|
+
}
|
|
21
|
+
export interface ThinkingPhase {
|
|
22
|
+
readonly label: string;
|
|
23
|
+
readonly startedAt: number;
|
|
24
|
+
readonly tone?: 'thinking' | 'planner' | 'tool' | 'team';
|
|
25
|
+
}
|
|
26
|
+
export interface OrbitalSatellite {
|
|
27
|
+
readonly id: string;
|
|
28
|
+
readonly role: 'main' | 'worker';
|
|
29
|
+
readonly status: string;
|
|
30
|
+
readonly task?: string | undefined;
|
|
31
|
+
readonly parentMemberId?: string | undefined;
|
|
32
|
+
readonly depth?: number | undefined;
|
|
33
|
+
}
|
|
34
|
+
export interface OrbitalViewModel extends SlashCommandContext {
|
|
35
|
+
readonly workdir: string;
|
|
36
|
+
readonly hostPhase: HostPhase;
|
|
37
|
+
readonly hostError?: string | undefined;
|
|
38
|
+
readonly spinnerFrame?: number | undefined;
|
|
39
|
+
readonly profileLabel: string;
|
|
40
|
+
readonly contextWindow?: number | undefined;
|
|
41
|
+
readonly usage?: AgentContextMetrics | undefined;
|
|
42
|
+
readonly stepCount?: number | undefined;
|
|
43
|
+
readonly mainTurn?: {
|
|
44
|
+
readonly ordinal: number;
|
|
45
|
+
readonly status: string;
|
|
46
|
+
} | undefined;
|
|
47
|
+
readonly latestRunStatus?: string | undefined;
|
|
48
|
+
readonly credReady: boolean;
|
|
49
|
+
readonly warning?: string | undefined;
|
|
50
|
+
readonly permissionMode?: PermissionMode;
|
|
51
|
+
readonly workspaceTools: boolean;
|
|
52
|
+
readonly sandbox?: HostSandboxStatus | undefined;
|
|
53
|
+
readonly sessionId?: string | undefined;
|
|
54
|
+
readonly teamMember?: string | undefined;
|
|
55
|
+
readonly runCount: number;
|
|
56
|
+
readonly turnCount: number;
|
|
57
|
+
readonly todos: readonly TodoItem[];
|
|
58
|
+
readonly inboxCount: number;
|
|
59
|
+
readonly activeRun: boolean;
|
|
60
|
+
readonly pauseReason?: string | undefined;
|
|
61
|
+
readonly thinking?: ThinkingPhase | undefined;
|
|
62
|
+
readonly nowMs?: number | undefined;
|
|
63
|
+
readonly runStartedAt?: number | undefined;
|
|
64
|
+
readonly satellites: readonly OrbitalSatellite[];
|
|
65
|
+
readonly liveAgents?: RunProgressPage['liveAgents'];
|
|
66
|
+
readonly entries: readonly OrbitalEntry[];
|
|
67
|
+
readonly scrollOffset: number;
|
|
68
|
+
readonly showSidebar: boolean;
|
|
69
|
+
readonly showDetails?: boolean;
|
|
70
|
+
readonly focusArea?: TuiFocusArea | undefined;
|
|
71
|
+
readonly focusedSatelliteId?: string | undefined;
|
|
72
|
+
readonly buffer: string;
|
|
73
|
+
readonly cursor: number;
|
|
74
|
+
readonly composerScrollOffset?: number | undefined;
|
|
75
|
+
readonly queuedCount?: number | undefined;
|
|
76
|
+
readonly queuedPrompt?: {
|
|
77
|
+
readonly text: string;
|
|
78
|
+
readonly count: number;
|
|
79
|
+
} | undefined;
|
|
80
|
+
readonly sideQuestion?: SideQuestion | undefined;
|
|
81
|
+
readonly paletteDismissed?: boolean | undefined;
|
|
82
|
+
readonly paletteState?: PaletteState | undefined;
|
|
83
|
+
readonly paletteIndex?: number | undefined;
|
|
84
|
+
readonly approvalPrompt?: PendingApprovalView | undefined;
|
|
85
|
+
readonly choicePicker?: ChoicePicker | undefined;
|
|
86
|
+
readonly secretPrompt?: {
|
|
87
|
+
readonly label: string;
|
|
88
|
+
readonly maskLength: number;
|
|
89
|
+
} | undefined;
|
|
90
|
+
readonly statusHint?: string | undefined;
|
|
91
|
+
readonly color?: boolean | undefined;
|
|
92
|
+
}
|
|
93
|
+
export type ResumeSessionChoice = Pick<SessionListItem, 'id' | 'title' | 'status' | 'updatedAt' | 'modeRef' | 'firstUserMessage' | 'runCount' | 'latestRunStatus'>;
|
|
94
|
+
interface ChoicePicker extends ChoicePrompt {
|
|
95
|
+
readonly selectedIndex: number;
|
|
96
|
+
}
|
|
97
|
+
interface SideQuestion {
|
|
98
|
+
readonly question: string;
|
|
99
|
+
readonly result?: string;
|
|
100
|
+
readonly scroll: number;
|
|
101
|
+
}
|
|
102
|
+
export interface ComposerRegion {
|
|
103
|
+
readonly topRow: number;
|
|
104
|
+
readonly bottomRow: number;
|
|
105
|
+
readonly colStart: number;
|
|
106
|
+
readonly colEnd: number;
|
|
107
|
+
readonly scrollOffset: number;
|
|
108
|
+
readonly maxScroll: number;
|
|
109
|
+
readonly rows: readonly SelectionRow[];
|
|
110
|
+
}
|
|
111
|
+
export interface OrbitalFrame {
|
|
112
|
+
readonly sideQuestionMaxScroll?: number;
|
|
113
|
+
readonly lines: string[];
|
|
114
|
+
readonly cursorRow: number;
|
|
115
|
+
readonly cursorCol: number;
|
|
116
|
+
readonly cursorVisible?: boolean | undefined;
|
|
117
|
+
readonly selectionRows: readonly SelectionRow[];
|
|
118
|
+
readonly allSelectionRows: readonly SelectionRow[];
|
|
119
|
+
readonly feedStartIndex: number;
|
|
120
|
+
readonly composerRegion: ComposerRegion;
|
|
121
|
+
readonly sidebarTargets: readonly SidebarTarget[];
|
|
122
|
+
readonly sidebarNavigation?: SidebarNavigation | undefined;
|
|
123
|
+
readonly viewport: {
|
|
124
|
+
readonly columns: number;
|
|
125
|
+
readonly rows: number;
|
|
126
|
+
readonly offset: number;
|
|
127
|
+
readonly maxOffset: number;
|
|
128
|
+
readonly anchor?: FeedAnchor;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
interface FeedAnchor {
|
|
132
|
+
readonly entry: number;
|
|
133
|
+
readonly line: number;
|
|
134
|
+
}
|
|
135
|
+
export type OrbitalTelemetryPatch = Omit<Partial<OrbitalViewModel>, 'entries' | 'buffer' | 'cursor' | 'paletteDismissed' | 'paletteState' | 'paletteIndex' | 'showDetails'>;
|
|
136
|
+
export interface OrbitalTuiOptions {
|
|
137
|
+
readonly hints: readonly SlashCommandHint[];
|
|
138
|
+
readonly initialModel: Omit<OrbitalViewModel, 'entries' | 'scrollOffset' | 'buffer' | 'cursor' | 'paletteDismissed' | 'paletteState' | 'paletteIndex' | 'showDetails'>;
|
|
139
|
+
}
|
|
140
|
+
export interface OrbitalTui {
|
|
141
|
+
enter(): void;
|
|
142
|
+
leave(): void;
|
|
143
|
+
appendEntry(kind: OrbitalEntryKind, text: string): void;
|
|
144
|
+
setEntry(entry: OrbitalEntry, key?: string, beforeKey?: string): void;
|
|
145
|
+
rekeyEntry(from: string, to: string): void;
|
|
146
|
+
removeEntry(key: string): void;
|
|
147
|
+
clearEntries(): void;
|
|
148
|
+
prependHistory(entries: readonly (OrbitalEntry & {
|
|
149
|
+
readonly key: string;
|
|
150
|
+
})[]): void;
|
|
151
|
+
onOlderHistory(fn: () => void): void;
|
|
152
|
+
updateTelemetry(patch: OrbitalTelemetryPatch): void;
|
|
153
|
+
waitForSubmission(): Promise<string | null>;
|
|
154
|
+
promptApproval(pending: PendingApprovalView, signal?: AbortSignal): Promise<'y' | 'n' | 'd' | null>;
|
|
155
|
+
promptChoice(prompt: ChoicePrompt): Promise<string | null>;
|
|
156
|
+
promptSecret(label: string): Promise<string | null>;
|
|
157
|
+
promptResumeSession?(items: readonly ResumeSessionChoice[]): Promise<string | null>;
|
|
158
|
+
onDetach(fn: () => void): void;
|
|
159
|
+
onInterrupt?(fn: () => void): void;
|
|
160
|
+
onImmediateSubmission(fn: (value: string) => void): void;
|
|
161
|
+
onSteer(fn: (text: string) => Promise<boolean>): void;
|
|
162
|
+
showSideQuestion(question: string, ask: (signal: AbortSignal) => Promise<string>): void;
|
|
163
|
+
closeSideQuestion(): void;
|
|
164
|
+
onNavigation?(fn: (value: string) => boolean): void;
|
|
165
|
+
onSelectSatellite?(fn: (memberId: string) => void): void;
|
|
166
|
+
renderNow(): void;
|
|
167
|
+
}
|
|
168
|
+
export declare function renderOrbitalFrame(model: OrbitalViewModel, cols: number, rows: number, anchor?: FeedAnchor): OrbitalFrame;
|
|
169
|
+
export declare function createOrbitalTui(options: OrbitalTuiOptions): OrbitalTui;
|
|
170
|
+
export {};
|