@saturn-universe/cli 0.1.2-dev.1 → 0.1.2-dev.10
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/attach.d.ts +3 -1
- package/dist/attach.js +4 -1
- package/dist/cli-help.js +1 -1
- package/dist/config-cli.js +16 -4
- package/dist/host-launcher.d.ts +2 -1
- package/dist/host-launcher.js +16 -1
- package/dist/provider-discovery.d.ts +1 -0
- package/dist/provider-discovery.js +2 -1
- package/dist/provider-pricing.d.ts +1 -1
- package/dist/provider-pricing.js +3 -2
- package/dist/provider-wizard.d.ts +18 -0
- package/dist/provider-wizard.js +109 -0
- package/dist/provider.js +95 -37
- package/dist/renderer.d.ts +1 -1
- package/dist/renderer.js +5 -3
- package/dist/repl-host.d.ts +2 -0
- package/dist/repl-host.js +9 -1
- package/dist/repl-run-observer.js +1 -0
- package/dist/repl.js +118 -23
- package/dist/session-history.d.ts +4 -2
- package/dist/session-history.js +42 -10
- package/dist/slash-commands.d.ts +1 -0
- package/dist/slash-commands.js +16 -2
- package/dist/terminal-text.js +33 -7
- package/dist/tui.d.ts +2 -0
- package/dist/tui.js +87 -42
- package/package.json +4 -3
package/dist/repl.js
CHANGED
|
@@ -4,7 +4,7 @@ import { isTerminalRunEventType, MAX_SESSION_HISTORY_PAGE_SIZE, mergeAgentContex
|
|
|
4
4
|
import { formatDuration } from './duration.js';
|
|
5
5
|
import { CliError, formatDiagnosticReference } from './cli-diagnostics.js';
|
|
6
6
|
import { approvalCommand, sendHostCommand } from './host-command.js';
|
|
7
|
-
import { createReplHostConnection } from './repl-host.js';
|
|
7
|
+
import { applyReplSessionMode, createReplHostConnection } from './repl-host.js';
|
|
8
8
|
import { createReplRunObserver } from './repl-run-observer.js';
|
|
9
9
|
import { renderApprovalPrompt, renderAssistantText, renderBanner, renderConversationEvent, renderProgressEvent, renderUnifiedToolBlock, } from './renderer.js';
|
|
10
10
|
import { createSessionHistoryLoader, historyEntryKey, messageEntryKey } from './session-history.js';
|
|
@@ -14,18 +14,16 @@ function replSubmission(state, runOptions, target) {
|
|
|
14
14
|
const config = {};
|
|
15
15
|
if (target.streamText)
|
|
16
16
|
config.streamText = target.streamText;
|
|
17
|
-
if (target.modeRef)
|
|
18
|
-
config.modeRef = target.modeRef;
|
|
19
17
|
if (runOptions.team)
|
|
20
18
|
config.team = { ...runOptions.team, members: [...runOptions.team.members] };
|
|
21
|
-
const reasoningEffort = state.
|
|
19
|
+
const reasoningEffort = state.userMutatedDefaults?.has('effort') ? state.reasoningEffort : undefined;
|
|
22
20
|
if (reasoningEffort !== undefined) {
|
|
23
21
|
config.responses = {
|
|
24
22
|
storage: 'local_stateless',
|
|
25
23
|
...(reasoningEffort && reasoningEffort !== 'off' ? { reasoning: { effort: reasoningEffort } } : {}),
|
|
26
24
|
};
|
|
27
25
|
}
|
|
28
|
-
if (state.workerReasoningEffort !== undefined)
|
|
26
|
+
if (state.userMutatedDefaults?.has('workerEffort') && state.workerReasoningEffort !== undefined)
|
|
29
27
|
config.workerReasoningEffort = state.workerReasoningEffort;
|
|
30
28
|
if (state.disabledSkills?.length)
|
|
31
29
|
config.disabledSkills = [...state.disabledSkills];
|
|
@@ -68,6 +66,8 @@ function formatCliError(error) {
|
|
|
68
66
|
if (error.code === 'CREDENTIAL_UNAVAILABLE') {
|
|
69
67
|
return `Error: ${error.code} (diagnosticId=${error.diagnosticId}). Configure credentials in ~/.saturn/credentials.toml or run \`/config check\`.`;
|
|
70
68
|
}
|
|
69
|
+
if (error.code === 'SESSION_BUSY')
|
|
70
|
+
return '当前会话有正在执行的任务,请等待完成或先 /cancel 后再切换 Mode';
|
|
71
71
|
if (error.code === 'MODE_MISMATCH') {
|
|
72
72
|
return `Error: MODE_MISMATCH (diagnosticId=${error.diagnosticId}). 当前工作区 Host 运行在其他 Mode 下;请使用 \`/mode <target>\` 切换或重启 Host。`;
|
|
73
73
|
}
|
|
@@ -189,7 +189,7 @@ export function showTeamEvent(event, member) {
|
|
|
189
189
|
return !event.memberId || event.memberId === 'main' || event.memberId === 'planner';
|
|
190
190
|
}
|
|
191
191
|
function activeModeRef(state, status) {
|
|
192
|
-
return status?.activeMode?.ref ?? state.activeMode?.ref ?? state.modeRef;
|
|
192
|
+
return state.sessionModeRef ?? status?.activeMode?.ref ?? state.activeMode?.ref ?? state.modeRef;
|
|
193
193
|
}
|
|
194
194
|
function hydrateDefaultsFromStatus(state, status) {
|
|
195
195
|
const defaults = status?.runDefaults;
|
|
@@ -342,6 +342,7 @@ async function runPipedRepl(options, hostOptions) {
|
|
|
342
342
|
sessionId: state.sessionId,
|
|
343
343
|
});
|
|
344
344
|
state.member = session.member;
|
|
345
|
+
applyReplSessionMode(state, session.modeRef);
|
|
345
346
|
if (session.member)
|
|
346
347
|
state.lastRunId = session.latestRun?.id;
|
|
347
348
|
await printMemberHistory();
|
|
@@ -557,7 +558,6 @@ async function runPipedRepl(options, hostOptions) {
|
|
|
557
558
|
const input = replSubmission(state, runOptions, {
|
|
558
559
|
workspaceId,
|
|
559
560
|
sessionId,
|
|
560
|
-
modeRef: state.activeMode?.ref ?? state.modeRef,
|
|
561
561
|
});
|
|
562
562
|
const result = await sendHostCommand(state.workdir, {
|
|
563
563
|
type: 'run.submit',
|
|
@@ -636,8 +636,14 @@ 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();
|
|
642
|
+
let liveParentSessionId;
|
|
643
|
+
let liveStatus;
|
|
644
|
+
let liveAgents;
|
|
645
|
+
// Keep only a small tail of the first history page for recently viewed sessions.
|
|
646
|
+
const recentPages = new Map();
|
|
641
647
|
let interruptingRun;
|
|
642
648
|
let latestRunPausedOrCheckpoint = false;
|
|
643
649
|
const tui = createOrbitalTui({
|
|
@@ -670,7 +676,7 @@ async function runTtyRepl(options, hostOptions) {
|
|
|
670
676
|
usage: retainedContextTelemetry,
|
|
671
677
|
permissionMode: state.permissionMode,
|
|
672
678
|
...(activeModeRef(state, status) ? { modeRef: activeModeRef(state, status) } : { modeRef: undefined }),
|
|
673
|
-
activeMode:
|
|
679
|
+
activeMode: state.activeMode ?? status?.activeMode,
|
|
674
680
|
sandbox: status?.sandbox,
|
|
675
681
|
skillRefs: [...state.skillRefs],
|
|
676
682
|
...(state.disabledSkills?.length ? { disabledSkills: [...state.disabledSkills] } : {}),
|
|
@@ -782,6 +788,7 @@ async function runTtyRepl(options, hostOptions) {
|
|
|
782
788
|
return;
|
|
783
789
|
if (info.member)
|
|
784
790
|
state.member = info.member;
|
|
791
|
+
applyReplSessionMode(state, info.modeRef);
|
|
785
792
|
if (history)
|
|
786
793
|
bindHistory(targetId);
|
|
787
794
|
if ((info.runCount ?? 0) > 0 || info.latestRun?.id)
|
|
@@ -857,14 +864,57 @@ async function runTtyRepl(options, hostOptions) {
|
|
|
857
864
|
return history.loader;
|
|
858
865
|
history?.loader.close();
|
|
859
866
|
const route = agentSessionId === undefined ? { sessionId } : { sessionId, agentSessionId };
|
|
867
|
+
const cached = recentPages.get(targetId);
|
|
868
|
+
const agent = member && liveAgents?.[member.id];
|
|
869
|
+
if (cached?.length)
|
|
870
|
+
tui.showHistoryPreview(cached);
|
|
871
|
+
else if (agent?.agentSessionId && agent.agentSessionId === agentSessionId) {
|
|
872
|
+
if (agent.reasoningSummary && (agent.phase === 'thinking' || agent.phase === 'streaming')) {
|
|
873
|
+
tui.showHistoryPreview([
|
|
874
|
+
{ kind: 'thinking', text: agent.reasoningSummary, streaming: agent.phase === 'thinking' },
|
|
875
|
+
]);
|
|
876
|
+
}
|
|
877
|
+
else if (agent.phase === 'tool' && agent.currentTool) {
|
|
878
|
+
tui.showHistoryPreview([{ kind: 'tool', text: agent.currentTool }]);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
let firstPage = true;
|
|
860
882
|
const loader = createSessionHistoryLoader(state.workdir, route, {
|
|
861
|
-
onPage: (messages) =>
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
883
|
+
onPage: (messages) => {
|
|
884
|
+
const entries = messages.map((message) => {
|
|
885
|
+
const key = historyEntryKey(message);
|
|
886
|
+
const entry = formatHistoryEntry(message, member?.id);
|
|
887
|
+
// The TUI caches Markdown layouts by entry identity. Tools have additional mutable fields.
|
|
888
|
+
if (firstPage && message.role !== 'tool') {
|
|
889
|
+
const previous = cached?.find((item) => item.key === key);
|
|
890
|
+
if (previous && previous.kind === entry.kind && previous.text === entry.text)
|
|
891
|
+
return previous;
|
|
892
|
+
}
|
|
893
|
+
return { ...entry, key };
|
|
894
|
+
});
|
|
895
|
+
if (firstPage) {
|
|
896
|
+
firstPage = false;
|
|
897
|
+
recentPages.delete(targetId);
|
|
898
|
+
if (entries.length) {
|
|
899
|
+
if (recentPages.size >= 16)
|
|
900
|
+
recentPages.delete(recentPages.keys().next().value);
|
|
901
|
+
recentPages.set(targetId, entries
|
|
902
|
+
.slice(-8)
|
|
903
|
+
.map((entry) => entry.text.length + (entry.detail?.length ?? 0) + (entry.header?.length ?? 0) <= 6144
|
|
904
|
+
? entry
|
|
905
|
+
: { kind: entry.kind, key: entry.key, text: entry.text.slice(0, 2048) }));
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
tui.prependHistory(entries);
|
|
909
|
+
},
|
|
865
910
|
onMessage: (message, text) => tui.setEntry(formatHistoryEntry(message, member?.id, text), historyEntryKey(message)),
|
|
866
|
-
onError: (error) =>
|
|
867
|
-
|
|
911
|
+
onError: (error) => {
|
|
912
|
+
tui.showHistoryPreview([]);
|
|
913
|
+
tui.appendEntry('error', `历史加载失败 · ${formatCliError(error)}`);
|
|
914
|
+
},
|
|
915
|
+
}, navigationPausesHistory ? 8 : MAX_SESSION_HISTORY_PAGE_SIZE);
|
|
916
|
+
if (navigationPausesHistory)
|
|
917
|
+
loader.pause();
|
|
868
918
|
history = { sessionId, agentSessionId, loader };
|
|
869
919
|
return loader;
|
|
870
920
|
}
|
|
@@ -878,8 +928,14 @@ async function runTtyRepl(options, hostOptions) {
|
|
|
878
928
|
const info = sessionSummary?.id === targetId ? sessionSummary : await refreshSummary(true);
|
|
879
929
|
if (signal.aborted || exiting || state.sessionId !== targetId)
|
|
880
930
|
return;
|
|
931
|
+
const hadFollowingRun = Boolean(followingRun);
|
|
881
932
|
await bindHistory(targetId).load();
|
|
882
|
-
if (signal.aborted || exiting
|
|
933
|
+
if (signal.aborted || exiting)
|
|
934
|
+
return;
|
|
935
|
+
// Live membership identifies the route; only the Host summary carries a storage cursor.
|
|
936
|
+
if (hadFollowingRun && info?.member && !info.cursor)
|
|
937
|
+
void refreshSummary();
|
|
938
|
+
if (hadFollowingRun || followingRun || openingMember)
|
|
883
939
|
return;
|
|
884
940
|
const followStatuses = state.member
|
|
885
941
|
? ['created', 'running', 'paused', 'cancelling']
|
|
@@ -997,10 +1053,15 @@ async function runTtyRepl(options, hostOptions) {
|
|
|
997
1053
|
throw error;
|
|
998
1054
|
}
|
|
999
1055
|
}
|
|
1000
|
-
async function followRun(runId, initialAfter = '0', initialInputKey) {
|
|
1056
|
+
async function followRun(runId, initialAfter = '0', initialInputKey, submittedSessionId) {
|
|
1001
1057
|
if (followingRun)
|
|
1002
1058
|
throw new Error('当前正在跟随一个任务');
|
|
1003
1059
|
followingRun = runId;
|
|
1060
|
+
liveParentSessionId =
|
|
1061
|
+
submittedSessionId ??
|
|
1062
|
+
(sessionSummary?.latestRun?.id === runId
|
|
1063
|
+
? (state.member?.parentSessionId ?? state.sessionId)
|
|
1064
|
+
: undefined);
|
|
1004
1065
|
let pendingInputKey = initialInputKey;
|
|
1005
1066
|
let terminalAt;
|
|
1006
1067
|
const satellites = [{ id: 'main', role: 'main', status: 'running' }];
|
|
@@ -1401,6 +1462,8 @@ async function runTtyRepl(options, hostOptions) {
|
|
|
1401
1462
|
});
|
|
1402
1463
|
telemetryDirty = true;
|
|
1403
1464
|
}
|
|
1465
|
+
liveStatus = page.status;
|
|
1466
|
+
liveAgents = page.liveAgents;
|
|
1404
1467
|
for (const [memberId, agent] of Object.entries(page.liveAgents ?? {})) {
|
|
1405
1468
|
if (memberId === 'planner')
|
|
1406
1469
|
continue;
|
|
@@ -1553,6 +1616,9 @@ async function runTtyRepl(options, hostOptions) {
|
|
|
1553
1616
|
interruptingRun = undefined;
|
|
1554
1617
|
followingRun = undefined;
|
|
1555
1618
|
liveMemberSessions.clear();
|
|
1619
|
+
liveParentSessionId = undefined;
|
|
1620
|
+
liveStatus = undefined;
|
|
1621
|
+
liveAgents = undefined;
|
|
1556
1622
|
runningModel = undefined;
|
|
1557
1623
|
if (!exiting) {
|
|
1558
1624
|
const startedAt = runStarts.get(runId);
|
|
@@ -1612,7 +1678,6 @@ async function runTtyRepl(options, hostOptions) {
|
|
|
1612
1678
|
const input = replSubmission(state, runOptions, {
|
|
1613
1679
|
workspaceId,
|
|
1614
1680
|
sessionId,
|
|
1615
|
-
modeRef: activeModeRef(state, state.host?.status),
|
|
1616
1681
|
streamText: true,
|
|
1617
1682
|
});
|
|
1618
1683
|
tui.updateTelemetry({
|
|
@@ -1639,7 +1704,7 @@ async function runTtyRepl(options, hostOptions) {
|
|
|
1639
1704
|
const inputKey = `input:${result.runId}`;
|
|
1640
1705
|
tui.setEntry({ kind: 'user', text: runOptions.text }, inputKey);
|
|
1641
1706
|
tui.setEntry({ kind: 'system', text: '', detail: `Run ${result.runId} submitted.` });
|
|
1642
|
-
await followRun(result.runId, '0', inputKey);
|
|
1707
|
+
await followRun(result.runId, '0', inputKey, sessionId);
|
|
1643
1708
|
}
|
|
1644
1709
|
const hooks = {
|
|
1645
1710
|
promptMcpSecret: (label) => tui.promptSecret(label),
|
|
@@ -1681,7 +1746,25 @@ async function runTtyRepl(options, hostOptions) {
|
|
|
1681
1746
|
if (followingRun && info.latestRun?.id !== followingRun)
|
|
1682
1747
|
throw new Error('请先按 Ctrl+C 分离当前任务,再切换到其他任务的会话');
|
|
1683
1748
|
},
|
|
1749
|
+
getLiveMemberSession(sessionId) {
|
|
1750
|
+
if (!followingRun || !liveParentSessionId || liveStatus !== 'running')
|
|
1751
|
+
return;
|
|
1752
|
+
for (const [id, agentSessionId] of liveMemberSessions) {
|
|
1753
|
+
if (id !== 'main' && agentSessionId === sessionId)
|
|
1754
|
+
return {
|
|
1755
|
+
id: sessionId,
|
|
1756
|
+
member: { id, agentSessionId, parentSessionId: liveParentSessionId },
|
|
1757
|
+
latestRun: { id: followingRun, status: liveStatus },
|
|
1758
|
+
...(state.sessionModeRef ? { modeRef: state.sessionModeRef } : {}),
|
|
1759
|
+
};
|
|
1760
|
+
}
|
|
1761
|
+
},
|
|
1684
1762
|
onSessionChanged(info) {
|
|
1763
|
+
if (followingRun && info.latestRun?.id === followingRun) {
|
|
1764
|
+
liveParentSessionId = info.member?.parentSessionId ?? info.id;
|
|
1765
|
+
if (info.member)
|
|
1766
|
+
liveMemberSessions.set(info.member.id, info.member.agentSessionId);
|
|
1767
|
+
}
|
|
1685
1768
|
latestRunPausedOrCheckpoint = info.latestRun?.status === 'paused';
|
|
1686
1769
|
if (restoredSessionId !== info.id) {
|
|
1687
1770
|
viewGeneration += 1;
|
|
@@ -1706,7 +1789,15 @@ async function runTtyRepl(options, hostOptions) {
|
|
|
1706
1789
|
navigationAbort?.abort();
|
|
1707
1790
|
const navAbort = new AbortController();
|
|
1708
1791
|
navigationAbort = navAbort;
|
|
1709
|
-
|
|
1792
|
+
navigationPausesHistory = Boolean(label) || /^\/session\s+\S|^\/team\s+.*--member(?:\s|=)/i.test(command);
|
|
1793
|
+
if (navigationPausesHistory)
|
|
1794
|
+
history?.loader.pause();
|
|
1795
|
+
else
|
|
1796
|
+
history?.loader.resume();
|
|
1797
|
+
tui.updateTelemetry({
|
|
1798
|
+
pendingSatellite: label,
|
|
1799
|
+
statusHint: label ? `正在切换到 ${label}...` : '正在切换会话...',
|
|
1800
|
+
});
|
|
1710
1801
|
void handleSlashCommand(command, state, hooks)
|
|
1711
1802
|
.catch((error) => {
|
|
1712
1803
|
if (!exiting &&
|
|
@@ -1717,10 +1808,14 @@ async function runTtyRepl(options, hostOptions) {
|
|
|
1717
1808
|
}
|
|
1718
1809
|
})
|
|
1719
1810
|
.finally(() => {
|
|
1720
|
-
if (navigationAbort
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1811
|
+
if (navigationAbort !== navAbort)
|
|
1812
|
+
return;
|
|
1813
|
+
navigationAbort = undefined;
|
|
1814
|
+
navigationPausesHistory = false;
|
|
1815
|
+
if (!exiting) {
|
|
1816
|
+
history?.loader.resume();
|
|
1817
|
+
tui.updateTelemetry({ pendingSatellite: undefined, statusHint: undefined });
|
|
1818
|
+
}
|
|
1724
1819
|
});
|
|
1725
1820
|
}
|
|
1726
1821
|
tui.onSelectSatellite?.((memberId) => {
|
|
@@ -10,8 +10,10 @@ interface HistoryOutput {
|
|
|
10
10
|
}
|
|
11
11
|
export declare function messageEntryKey(messageId: string): string;
|
|
12
12
|
export declare function historyEntryKey(message: SessionHistoryMessage): string;
|
|
13
|
-
export declare function createSessionHistoryLoader(workdir: string, route: HistoryRoute, output: HistoryOutput): {
|
|
13
|
+
export declare function createSessionHistoryLoader(workdir: string, route: HistoryRoute, output: HistoryOutput, firstPageLimit?: number): {
|
|
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
|
@@ -11,13 +11,15 @@ export function historyEntryKey(message) {
|
|
|
11
11
|
return `tool:${message.runId}:${message.toolCallId}`;
|
|
12
12
|
return messageEntryKey(message.id);
|
|
13
13
|
}
|
|
14
|
-
export function createSessionHistoryLoader(workdir, route, output) {
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
export function createSessionHistoryLoader(workdir, route, output, firstPageLimit = MAX_SESSION_HISTORY_PAGE_SIZE) {
|
|
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,12 +35,12 @@ 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',
|
|
40
42
|
...route,
|
|
41
|
-
limit: MAX_SESSION_HISTORY_PAGE_SIZE,
|
|
43
|
+
limit: cursor?.before ? MAX_SESSION_HISTORY_PAGE_SIZE : firstPageLimit,
|
|
42
44
|
...(cursor ? { through: cursor.through } : {}),
|
|
43
45
|
...(cursor?.before ? { before: cursor.before } : {}),
|
|
44
46
|
}, { signal });
|
|
@@ -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/slash-commands.d.ts
CHANGED
|
@@ -53,6 +53,7 @@ export interface ReplHooks {
|
|
|
53
53
|
restartHost?(): Promise<HostStatusSnapshot>;
|
|
54
54
|
promptMcpSecret?(label: string): Promise<string | null>;
|
|
55
55
|
persistDefaults?(patch: UserConfigDefaultsPatch): Promise<SaveUserConfigResult>;
|
|
56
|
+
getLiveMemberSession?(sessionId: string): SessionSummary | undefined;
|
|
56
57
|
onSessionChanged?(info: SessionSummary): void;
|
|
57
58
|
checkSessionSwitch?(info: SessionSummary): void;
|
|
58
59
|
getNavigationSignal?(): AbortSignal | undefined;
|
package/dist/slash-commands.js
CHANGED
|
@@ -7,7 +7,7 @@ import { compactionArguments, compactionOptions, compactionOptionUsage } from '.
|
|
|
7
7
|
import { ensureHostWorkspace, reconcileRunTool, resolveRunApproval, sendHostCommand, } from './host-command.js';
|
|
8
8
|
import { stopHost } from './host-launcher.js';
|
|
9
9
|
import { reconciliationCommand, reconciliationOptions } from './reconcile-command.js';
|
|
10
|
-
import { applyReplMode } from './repl-host.js';
|
|
10
|
+
import { applyReplMode, applyReplSessionMode } from './repl-host.js';
|
|
11
11
|
import { renderConfigCheck, renderConfigInit, renderConfigSummary, renderReplHelp, renderShortcutHelp, renderTeamBoard, renderUsageCard, } from './renderer.js';
|
|
12
12
|
import { initUserConfig, inspectUserConfig, syncUserConfigDefaults, } from './user-config.js';
|
|
13
13
|
import { authenticateMcpServer, formatMcpServerStatus, listMcpServersInfo, setWorkspaceMcpTrust, } from './mcp-cli.js';
|
|
@@ -364,6 +364,7 @@ export async function ensureWorkspaceId(state) {
|
|
|
364
364
|
function selectSession(state, hooks, sessionId, summary) {
|
|
365
365
|
state.sessionId = sessionId;
|
|
366
366
|
state.member = summary.member;
|
|
367
|
+
applyReplSessionMode(state, summary.modeRef);
|
|
367
368
|
state.lastRunId = summary.latestRun?.id;
|
|
368
369
|
state.hasRunHistory = (summary.runCount ?? 0) > 0 || state.lastRunId !== undefined;
|
|
369
370
|
hooks.onSessionChanged?.({ ...summary, id: sessionId });
|
|
@@ -371,7 +372,8 @@ function selectSession(state, hooks, sessionId, summary) {
|
|
|
371
372
|
async function switchSession(state, hooks, sessionId, signal) {
|
|
372
373
|
if (signal?.aborted)
|
|
373
374
|
return;
|
|
374
|
-
const
|
|
375
|
+
const live = hooks.getLiveMemberSession?.(sessionId);
|
|
376
|
+
const session = live ?? (await sendHostCommand(state.workdir, { type: 'session.query', sessionId }, { signal }));
|
|
375
377
|
if (signal?.aborted)
|
|
376
378
|
return;
|
|
377
379
|
hooks.checkSessionSwitch?.(session);
|
|
@@ -1158,6 +1160,18 @@ export async function handleSlashCommand(line, state, hooks) {
|
|
|
1158
1160
|
if (hooks.isRunActive?.()) {
|
|
1159
1161
|
throw new Error('当前有正在执行的任务,请等待完成或先 /cancel 后再切换 Mode');
|
|
1160
1162
|
}
|
|
1163
|
+
if (state.sessionId) {
|
|
1164
|
+
await hooks.ensureConnected();
|
|
1165
|
+
const { mode } = await sendHostCommand(state.workdir, {
|
|
1166
|
+
type: 'session.mode.select',
|
|
1167
|
+
sessionId: state.member?.parentSessionId ?? state.sessionId,
|
|
1168
|
+
modeRef: normalizedInput,
|
|
1169
|
+
});
|
|
1170
|
+
state.sessionModeRef = mode.ref;
|
|
1171
|
+
applyReplMode(state, mode);
|
|
1172
|
+
hooks.writeLine('已切换当前会话的 Mode 为 ' + mode.displayName + ' (' + mode.ref + ')');
|
|
1173
|
+
return 'continue';
|
|
1174
|
+
}
|
|
1161
1175
|
if (state.lastRunId) {
|
|
1162
1176
|
try {
|
|
1163
1177
|
const run = await sendHostCommand(state.workdir, {
|
package/dist/terminal-text.js
CHANGED
|
@@ -2,6 +2,8 @@ const ANSI_ESCAPE = /\x1b(?:\[[0-9;?]*[A-Za-z]|\][^\x07]*?(?:\x07|\x1b\\))/g;
|
|
|
2
2
|
const graphemes = new Intl.Segmenter();
|
|
3
3
|
const emojiPresentation = new RegExp('^\\p{RGI_Emoji}$', 'v');
|
|
4
4
|
const printableAscii = /^[\x20-\x7e]*$/;
|
|
5
|
+
// These terminal cells cannot form combining or emoji sequences.
|
|
6
|
+
const simpleCells = /^[\x20-\x7e\u00b7\u2500-\u259f\u4e00-\u9fff]*$/;
|
|
5
7
|
const SGR_RESET = '\x1b[0m';
|
|
6
8
|
export function terminalColorEnabled(override) {
|
|
7
9
|
if (override !== undefined)
|
|
@@ -101,6 +103,13 @@ export function stringDisplayWidth(text) {
|
|
|
101
103
|
const visible = stripAnsi(text);
|
|
102
104
|
if (printableAscii.test(visible))
|
|
103
105
|
return visible.length;
|
|
106
|
+
if (simpleCells.test(visible)) {
|
|
107
|
+
let width = visible.length;
|
|
108
|
+
for (let i = 0; i < visible.length; i++)
|
|
109
|
+
if (visible.charCodeAt(i) >= 0x4e00)
|
|
110
|
+
width++;
|
|
111
|
+
return width;
|
|
112
|
+
}
|
|
104
113
|
let width = 0;
|
|
105
114
|
for (const grapheme of displayGraphemes(visible))
|
|
106
115
|
width += grapheme.width;
|
|
@@ -134,6 +143,8 @@ function* displayTokens(text) {
|
|
|
134
143
|
export function truncateDisplay(text, maxWidth) {
|
|
135
144
|
if (maxWidth <= 0)
|
|
136
145
|
return '';
|
|
146
|
+
if (printableAscii.test(text))
|
|
147
|
+
return text.slice(0, maxWidth);
|
|
137
148
|
let width = 0;
|
|
138
149
|
let end = 0;
|
|
139
150
|
let hasAnsi = false;
|
|
@@ -207,14 +218,29 @@ export function* wrapDisplayRanges(text, maxWidth) {
|
|
|
207
218
|
let start = paragraphStart;
|
|
208
219
|
let end = paragraphStart;
|
|
209
220
|
let lineWidth = 0;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
lineWidth
|
|
221
|
+
if (simpleCells.test(paragraph)) {
|
|
222
|
+
// Each code unit is one complete grapheme here. Only the CJK range occupies two cells.
|
|
223
|
+
for (let i = 0; i < paragraph.length; i++) {
|
|
224
|
+
const width = paragraph.charCodeAt(i) >= 0x4e00 ? 2 : 1;
|
|
225
|
+
if (lineWidth > 0 && lineWidth + width > limit) {
|
|
226
|
+
yield { start, end, soft: start !== paragraphStart };
|
|
227
|
+
start = end;
|
|
228
|
+
lineWidth = 0;
|
|
229
|
+
}
|
|
230
|
+
end++;
|
|
231
|
+
lineWidth += width;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
for (const { end: tokenEnd, width } of displayTokens(paragraph)) {
|
|
236
|
+
if (lineWidth > 0 && width > 0 && lineWidth + width > limit) {
|
|
237
|
+
yield { start, end, soft: start !== paragraphStart };
|
|
238
|
+
start = end;
|
|
239
|
+
lineWidth = 0;
|
|
240
|
+
}
|
|
241
|
+
end = paragraphStart + tokenEnd;
|
|
242
|
+
lineWidth += width;
|
|
215
243
|
}
|
|
216
|
-
end = paragraphStart + tokenEnd;
|
|
217
|
-
lineWidth += width;
|
|
218
244
|
}
|
|
219
245
|
yield { start, end, soft: start !== paragraphStart };
|
|
220
246
|
paragraphStart = end + 1;
|
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'>;
|
|
@@ -145,6 +146,7 @@ export interface OrbitalTui {
|
|
|
145
146
|
rekeyEntry(from: string, to: string): void;
|
|
146
147
|
removeEntry(key: string): void;
|
|
147
148
|
clearEntries(): void;
|
|
149
|
+
showHistoryPreview(entries: readonly OrbitalEntry[]): void;
|
|
148
150
|
prependHistory(entries: readonly (OrbitalEntry & {
|
|
149
151
|
readonly key: string;
|
|
150
152
|
})[]): void;
|