@saturn-universe/cli 0.1.2-dev.4 → 0.1.2-dev.5
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/renderer.js +1 -1
- package/dist/repl.js +20 -5
- package/dist/session-history.d.ts +3 -1
- package/dist/session-history.js +40 -8
- package/dist/tui.d.ts +1 -0
- package/dist/tui.js +63 -37
- package/package.json +3 -3
package/dist/renderer.js
CHANGED
|
@@ -4,7 +4,7 @@ import { reconciliationUsage } from './reconcile-command.js';
|
|
|
4
4
|
import { createTerminalPainter, padEndDisplay, paintSgr, stringDisplayWidth, stripAnsi, terminalColorEnabled, } from './terminal-text.js';
|
|
5
5
|
import { formatDuration } from './duration.js';
|
|
6
6
|
import { estimateUsageCostUsd, formatCacheRate, formatTokenCompact, formatTokenExact, formatUsd, resolveModelPricing, } from './usage.js';
|
|
7
|
-
const SATURN_CLI_VERSION = '0.1.2-dev.
|
|
7
|
+
const SATURN_CLI_VERSION = '0.1.2-dev.5';
|
|
8
8
|
const { bold, dim, cyan, brightCyan, green, yellow, red, magenta, whiteBold } = createTerminalPainter();
|
|
9
9
|
function padLogoLines(lines) {
|
|
10
10
|
const maxWidth = Math.max(0, ...lines.map(stringDisplayWidth));
|
package/dist/repl.js
CHANGED
|
@@ -636,6 +636,7 @@ async function runTtyRepl(options, hostOptions) {
|
|
|
636
636
|
let openingMember = false;
|
|
637
637
|
let navigationSeq = 0;
|
|
638
638
|
let navigationAbort;
|
|
639
|
+
let navigationPausesHistory = false;
|
|
639
640
|
let lastHostConnectedAt = 0;
|
|
640
641
|
const liveMemberSessions = new Map();
|
|
641
642
|
let interruptingRun;
|
|
@@ -865,6 +866,8 @@ async function runTtyRepl(options, hostOptions) {
|
|
|
865
866
|
onMessage: (message, text) => tui.setEntry(formatHistoryEntry(message, member?.id, text), historyEntryKey(message)),
|
|
866
867
|
onError: (error) => tui.appendEntry('error', `历史加载失败 · ${formatCliError(error)}`),
|
|
867
868
|
});
|
|
869
|
+
if (navigationPausesHistory)
|
|
870
|
+
loader.pause();
|
|
868
871
|
history = { sessionId, agentSessionId, loader };
|
|
869
872
|
return loader;
|
|
870
873
|
}
|
|
@@ -1706,7 +1709,15 @@ async function runTtyRepl(options, hostOptions) {
|
|
|
1706
1709
|
navigationAbort?.abort();
|
|
1707
1710
|
const navAbort = new AbortController();
|
|
1708
1711
|
navigationAbort = navAbort;
|
|
1709
|
-
|
|
1712
|
+
navigationPausesHistory = Boolean(label) || /^\/session\s+\S|^\/team\s+.*--member(?:\s|=)/i.test(command);
|
|
1713
|
+
if (navigationPausesHistory)
|
|
1714
|
+
history?.loader.pause();
|
|
1715
|
+
else
|
|
1716
|
+
history?.loader.resume();
|
|
1717
|
+
tui.updateTelemetry({
|
|
1718
|
+
pendingSatellite: label,
|
|
1719
|
+
statusHint: label ? `正在切换到 ${label}...` : '正在切换会话...',
|
|
1720
|
+
});
|
|
1710
1721
|
void handleSlashCommand(command, state, hooks)
|
|
1711
1722
|
.catch((error) => {
|
|
1712
1723
|
if (!exiting &&
|
|
@@ -1717,10 +1728,14 @@ async function runTtyRepl(options, hostOptions) {
|
|
|
1717
1728
|
}
|
|
1718
1729
|
})
|
|
1719
1730
|
.finally(() => {
|
|
1720
|
-
if (navigationAbort
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1731
|
+
if (navigationAbort !== navAbort)
|
|
1732
|
+
return;
|
|
1733
|
+
navigationAbort = undefined;
|
|
1734
|
+
navigationPausesHistory = false;
|
|
1735
|
+
if (!exiting) {
|
|
1736
|
+
history?.loader.resume();
|
|
1737
|
+
tui.updateTelemetry({ pendingSatellite: undefined, statusHint: undefined });
|
|
1738
|
+
}
|
|
1724
1739
|
});
|
|
1725
1740
|
}
|
|
1726
1741
|
tui.onSelectSatellite?.((memberId) => {
|
|
@@ -12,6 +12,8 @@ export declare function messageEntryKey(messageId: string): string;
|
|
|
12
12
|
export declare function historyEntryKey(message: SessionHistoryMessage): string;
|
|
13
13
|
export declare function createSessionHistoryLoader(workdir: string, route: HistoryRoute, output: HistoryOutput): {
|
|
14
14
|
load(): Promise<void>;
|
|
15
|
-
|
|
15
|
+
pause(): void;
|
|
16
|
+
resume: () => void;
|
|
17
|
+
close(): void;
|
|
16
18
|
};
|
|
17
19
|
export {};
|
package/dist/session-history.js
CHANGED
|
@@ -12,12 +12,14 @@ export function historyEntryKey(message) {
|
|
|
12
12
|
return messageEntryKey(message.id);
|
|
13
13
|
}
|
|
14
14
|
export function createSessionHistoryLoader(workdir, route, output) {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
let controller = new AbortController();
|
|
16
|
+
let closed = false;
|
|
17
|
+
let paused;
|
|
18
|
+
let resume;
|
|
17
19
|
// An undefined boundary starts at the snapshot head. A null boundary marks a completed history.
|
|
18
20
|
let cursor;
|
|
19
21
|
let pending;
|
|
20
|
-
async function completeMessage(message) {
|
|
22
|
+
async function completeMessage(message, signal) {
|
|
21
23
|
let text = message.text;
|
|
22
24
|
let offset = message.nextOffset;
|
|
23
25
|
while (offset !== undefined) {
|
|
@@ -33,7 +35,7 @@ export function createSessionHistoryLoader(workdir, route, output) {
|
|
|
33
35
|
}
|
|
34
36
|
return text;
|
|
35
37
|
}
|
|
36
|
-
async function readPage() {
|
|
38
|
+
async function readPage(signal) {
|
|
37
39
|
try {
|
|
38
40
|
const page = await sendHostCommand(workdir, {
|
|
39
41
|
type: 'session.history',
|
|
@@ -49,7 +51,7 @@ export function createSessionHistoryLoader(workdir, route, output) {
|
|
|
49
51
|
for (const message of page.messages) {
|
|
50
52
|
if (message.nextOffset === undefined)
|
|
51
53
|
continue;
|
|
52
|
-
const text = await completeMessage(message);
|
|
54
|
+
const text = await completeMessage(message, signal);
|
|
53
55
|
if (signal.aborted)
|
|
54
56
|
return;
|
|
55
57
|
output.onMessage(message, text);
|
|
@@ -62,15 +64,45 @@ export function createSessionHistoryLoader(workdir, route, output) {
|
|
|
62
64
|
output.onError(error);
|
|
63
65
|
}
|
|
64
66
|
}
|
|
67
|
+
// Retry only the interrupted page, at the same snapshot and pagination boundary.
|
|
68
|
+
async function loadPage() {
|
|
69
|
+
while (!closed) {
|
|
70
|
+
if (paused) {
|
|
71
|
+
await paused;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
const { signal } = controller;
|
|
75
|
+
await readPage(signal);
|
|
76
|
+
if (!signal.aborted)
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function resumeLoading() {
|
|
81
|
+
paused = undefined;
|
|
82
|
+
resume?.();
|
|
83
|
+
resume = undefined;
|
|
84
|
+
}
|
|
65
85
|
return {
|
|
66
86
|
load() {
|
|
67
|
-
if (
|
|
87
|
+
if (closed || cursor?.before === null)
|
|
68
88
|
return Promise.resolve();
|
|
69
|
-
pending ??=
|
|
89
|
+
pending ??= loadPage().finally(() => {
|
|
70
90
|
pending = undefined;
|
|
71
91
|
});
|
|
72
92
|
return pending;
|
|
73
93
|
},
|
|
74
|
-
|
|
94
|
+
pause() {
|
|
95
|
+
if (closed || paused)
|
|
96
|
+
return;
|
|
97
|
+
paused = new Promise((resolve) => (resume = resolve));
|
|
98
|
+
controller.abort();
|
|
99
|
+
controller = new AbortController();
|
|
100
|
+
},
|
|
101
|
+
resume: resumeLoading,
|
|
102
|
+
close() {
|
|
103
|
+
closed = true;
|
|
104
|
+
controller.abort();
|
|
105
|
+
resumeLoading();
|
|
106
|
+
},
|
|
75
107
|
};
|
|
76
108
|
}
|
package/dist/tui.d.ts
CHANGED
|
@@ -88,6 +88,7 @@ export interface OrbitalViewModel extends SlashCommandContext {
|
|
|
88
88
|
readonly maskLength: number;
|
|
89
89
|
} | undefined;
|
|
90
90
|
readonly statusHint?: string | undefined;
|
|
91
|
+
readonly pendingSatellite?: string | undefined;
|
|
91
92
|
readonly color?: boolean | undefined;
|
|
92
93
|
}
|
|
93
94
|
export type ResumeSessionChoice = Pick<SessionListItem, 'id' | 'title' | 'status' | 'updatedAt' | 'modeRef' | 'firstUserMessage' | 'runCount' | 'latestRunStatus'>;
|
package/dist/tui.js
CHANGED
|
@@ -459,7 +459,7 @@ function renderSidebarLines(model, tree, width, height, p, colStart) {
|
|
|
459
459
|
? rootStatus
|
|
460
460
|
: truncateDisplay(terminalText(label).replace(/\s+/g, ' '), inner - 8);
|
|
461
461
|
const statusWidth = stringDisplayWidth(status);
|
|
462
|
-
const indent = isFocusedItem && !p.colored ? '▸' : ' ';
|
|
462
|
+
const indent = sat.id === model.pendingSatellite || (isFocusedItem && !p.colored) ? '▸' : ' ';
|
|
463
463
|
const prefix = `${indent}${branch ? p.dim(branch.trimEnd()) + ' ' : ''}${isRoot ? p.gold('◎') : glyph} `;
|
|
464
464
|
const contentWidth = width - statusWidth - 2;
|
|
465
465
|
const id = truncateDisplay(terminalText(sat.id).replace(/\s+/g, ' '), contentWidth - stringDisplayWidth(prefix));
|
|
@@ -778,7 +778,67 @@ function formatToolSummaryLines(plain, maxWidth, p, soft) {
|
|
|
778
778
|
}
|
|
779
779
|
return out;
|
|
780
780
|
}
|
|
781
|
+
const thinkingPreviewRows = 5;
|
|
782
|
+
const thinkingLayouts = new WeakMap();
|
|
783
|
+
function thinkingLayout(entry, width, expanded) {
|
|
784
|
+
const cached = thinkingLayouts.get(entry);
|
|
785
|
+
if (cached?.width === width && cached.expanded === expanded)
|
|
786
|
+
return cached;
|
|
787
|
+
let text = terminalText(entry.text);
|
|
788
|
+
let clipped = false;
|
|
789
|
+
if (entry.streaming && !expanded) {
|
|
790
|
+
// Keep one overflow row. Also bound a single newline-free paragraph, allowing room
|
|
791
|
+
// for multi-unit graphemes. Expansion always uses the original text.
|
|
792
|
+
let end = text.length;
|
|
793
|
+
for (let row = 0; row <= thinkingPreviewRows && end > 0; row++) {
|
|
794
|
+
end = text.lastIndexOf('\n', end - 1);
|
|
795
|
+
if (end < 0)
|
|
796
|
+
break;
|
|
797
|
+
if (row === thinkingPreviewRows) {
|
|
798
|
+
text = text.slice(end + 1);
|
|
799
|
+
clipped = true;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
const budget = (thinkingPreviewRows + 1) * width * 4;
|
|
803
|
+
const cut = Math.floor((text.length - budget) / width) * width;
|
|
804
|
+
if (cut > 0) {
|
|
805
|
+
const segment = segmentGraphemes(text).containing(cut);
|
|
806
|
+
text = text.slice(segment.index);
|
|
807
|
+
clipped ||= segment.index > 0;
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
const wraps = new Set();
|
|
811
|
+
const lines = wrapTextByWidth(text, width, wraps);
|
|
812
|
+
const collapsed = !expanded && (clipped || lines.length > thinkingPreviewRows);
|
|
813
|
+
const visible = thinkingPreviewRows - 1;
|
|
814
|
+
const start = collapsed && entry.streaming ? Math.max(0, lines.length - visible) : 0;
|
|
815
|
+
const body = collapsed ? lines.slice(start, start + visible) : lines;
|
|
816
|
+
const soft = [...wraps]
|
|
817
|
+
.filter((row) => row >= start && row < start + body.length)
|
|
818
|
+
.map((row) => row - start + (collapsed && entry.streaming ? 2 : 1));
|
|
819
|
+
const fold = clipped ? '较早内容' : `+${lines.length - body.length} 行`;
|
|
820
|
+
const layout = { width, expanded, body, soft, ...(collapsed ? { fold } : {}) };
|
|
821
|
+
thinkingLayouts.set(entry, layout);
|
|
822
|
+
return layout;
|
|
823
|
+
}
|
|
781
824
|
function formatEntryLines(entry, leftWidth, p, soft, showDetails = false, spinnerFrame = 0) {
|
|
825
|
+
if (entry.kind === 'thinking') {
|
|
826
|
+
const layout = thinkingLayout(entry, Math.max(4, leftWidth - 2), showDetails);
|
|
827
|
+
for (const row of layout.soft)
|
|
828
|
+
soft.add(row);
|
|
829
|
+
const header = entry.streaming
|
|
830
|
+
? `${THINKING_SPINNER[Math.max(0, Math.floor(spinnerFrame)) % THINKING_SPINNER.length]} Thinking…`
|
|
831
|
+
: '✦ Thinking';
|
|
832
|
+
const body = layout.body.map((line) => `${p.dim('│ ')}${p.thinkingItalic(line)}`);
|
|
833
|
+
if (layout.fold) {
|
|
834
|
+
const fold = p.dim(`│ … ${layout.fold} · Ctrl+O 展开`);
|
|
835
|
+
if (entry.streaming)
|
|
836
|
+
body.unshift(fold);
|
|
837
|
+
else
|
|
838
|
+
body.push(fold);
|
|
839
|
+
}
|
|
840
|
+
return [p.magenta(header), ...body];
|
|
841
|
+
}
|
|
782
842
|
const plain = terminalText(entry.text);
|
|
783
843
|
const out = [];
|
|
784
844
|
switch (entry.kind) {
|
|
@@ -806,40 +866,6 @@ function formatEntryLines(entry, leftWidth, p, soft, showDetails = false, spinne
|
|
|
806
866
|
markdownLayouts.set(entry, { width: leftWidth, colored: p.colored, lines, soft });
|
|
807
867
|
return lines;
|
|
808
868
|
}
|
|
809
|
-
case 'thinking': {
|
|
810
|
-
const frame = Math.max(0, Math.floor(spinnerFrame));
|
|
811
|
-
const wraps = new Set();
|
|
812
|
-
const lines = wrapTextByWidth(plain, Math.max(4, leftWidth - 2), wraps);
|
|
813
|
-
const bodyLine = (line) => `${p.dim('│ ')}${p.thinkingItalic(line)}`;
|
|
814
|
-
const collapseLine = (omitted) => p.dim(`│ … +${omitted} 行 · Ctrl+O 展开`);
|
|
815
|
-
if (entry.streaming) {
|
|
816
|
-
const header = p.magenta(`${THINKING_SPINNER[frame % THINKING_SPINNER.length]} Thinking…`);
|
|
817
|
-
if (!showDetails && lines.length > 5) {
|
|
818
|
-
const tailCount = 4;
|
|
819
|
-
const omitted = lines.length - tailCount;
|
|
820
|
-
const tail = lines.slice(-tailCount);
|
|
821
|
-
const offset = lines.length - tail.length;
|
|
822
|
-
for (const index of wraps)
|
|
823
|
-
if (index >= offset)
|
|
824
|
-
soft.add(index - offset + 2);
|
|
825
|
-
return [header, collapseLine(omitted), ...tail.map(bodyLine)];
|
|
826
|
-
}
|
|
827
|
-
for (const index of wraps)
|
|
828
|
-
soft.add(index + 1);
|
|
829
|
-
return [header, ...lines.map(bodyLine)];
|
|
830
|
-
}
|
|
831
|
-
const header = p.magenta('✦ Thinking');
|
|
832
|
-
const collapsed = !showDetails && lines.length > 5;
|
|
833
|
-
const visible = collapsed ? lines.slice(0, 4) : lines;
|
|
834
|
-
for (const index of wraps)
|
|
835
|
-
if (index < visible.length)
|
|
836
|
-
soft.add(index + 1);
|
|
837
|
-
return [
|
|
838
|
-
header,
|
|
839
|
-
...visible.map(bodyLine),
|
|
840
|
-
...(collapsed ? [collapseLine(lines.length - visible.length)] : []),
|
|
841
|
-
];
|
|
842
|
-
}
|
|
843
869
|
case 'planner': {
|
|
844
870
|
const text = plain.startsWith('[Planner]') ? plain : `[Planner] ${plain}`;
|
|
845
871
|
const wrapped = wrapTextByWidth(text, Math.max(4, leftWidth - 2), soft);
|
|
@@ -1651,8 +1677,8 @@ export function createOrbitalTui(options) {
|
|
|
1651
1677
|
if (hit) {
|
|
1652
1678
|
selection = undefined;
|
|
1653
1679
|
focusedSatelliteId = hit.memberId;
|
|
1654
|
-
renderNow();
|
|
1655
1680
|
selectSatelliteHandler?.(hit.memberId);
|
|
1681
|
+
queueRender();
|
|
1656
1682
|
return;
|
|
1657
1683
|
}
|
|
1658
1684
|
if (lastFrame &&
|
|
@@ -2107,7 +2133,7 @@ export function createOrbitalTui(options) {
|
|
|
2107
2133
|
focusArea = 'composer';
|
|
2108
2134
|
if (selected)
|
|
2109
2135
|
selectSatelliteHandler?.(selected);
|
|
2110
|
-
|
|
2136
|
+
queueRender();
|
|
2111
2137
|
return;
|
|
2112
2138
|
}
|
|
2113
2139
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saturn-universe/cli",
|
|
3
|
-
"version": "0.1.2-dev.
|
|
3
|
+
"version": "0.1.2-dev.5",
|
|
4
4
|
"description": "Saturn local multi-agent runtime CLI",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"type": "module",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@clack/prompts": "1.9.0",
|
|
12
|
-
"@saturn-universe/protocol": "0.1.2-dev.
|
|
13
|
-
"@saturn-universe/runtime-host": "0.1.2-dev.
|
|
12
|
+
"@saturn-universe/protocol": "0.1.2-dev.5",
|
|
13
|
+
"@saturn-universe/runtime-host": "0.1.2-dev.5",
|
|
14
14
|
"mdast-util-from-markdown": "^2.1.0",
|
|
15
15
|
"mdast-util-gfm": "^3.1.0",
|
|
16
16
|
"micromark-extension-gfm": "^3.0.0",
|