Files
NetMesh/components/systemManager/openInteractiveTerminal.ts
zhaolei 3c72efcb7f
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
[Init] Initial commit - NetMesh terminal manager
2026-09-13 18:24:01 +08:00

80 lines
2.7 KiB
TypeScript

import { canReuseTerminalConnection } from '../../application/state/terminalConnectionReuse';
import { writeSystemManagerDiagnostic } from '../../application/state/systemManagerDiagnostics';
import type { TerminalSession } from '../../types';
import type { TerminalPopupIcon } from '../../domain/systemManager/types';
import type { useSystemManagerBackend } from '../../application/state/useSystemManagerBackend';
type Backend = ReturnType<typeof useSystemManagerBackend>;
function buildPopupTitle(parentSession: TerminalSession, title: string): string {
const hostLabel = parentSession.hostLabel.trim();
const cleanTitle = title.trim();
if (!hostLabel || !cleanTitle) return cleanTitle || hostLabel;
if (cleanTitle === hostLabel || cleanTitle.startsWith(`${hostLabel} · `)) return cleanTitle;
return `${hostLabel} · ${cleanTitle}`;
}
function buildCommandPopupSourceSession(
parentSession: TerminalSession,
startupCommand: string,
canReuseConnection: boolean,
): TerminalSession {
const runtimeProtocol = parentSession.protocol as TerminalSession['protocol'] | 'mosh' | 'et' | undefined;
const shouldUseSshShell =
runtimeProtocol === undefined ||
runtimeProtocol === 'ssh' ||
runtimeProtocol === 'mosh' ||
runtimeProtocol === 'et' ||
parentSession.moshEnabled === true ||
parentSession.etEnabled === true;
return {
...parentSession,
...(shouldUseSshShell
? {
protocol: 'ssh' as const,
moshEnabled: false,
etEnabled: false,
}
: {}),
startupCommand,
reuseConnectionFromSessionId: canReuseConnection
? parentSession.id
: undefined,
};
}
export async function openInteractiveTerminal(
backend: Backend,
parentSession: TerminalSession,
title: string,
startupCommand: string,
options?: { icon?: TerminalPopupIcon },
): Promise<{ success: boolean; error?: string }> {
const canReuseConnection = canReuseTerminalConnection(parentSession);
const popupTitle = buildPopupTitle(parentSession, title);
await writeSystemManagerDiagnostic('openInteractiveTerminal requested', {
title: popupTitle,
parentSessionId: parentSession.id,
parentProtocol: parentSession.protocol,
parentHostLabel: parentSession.hostLabel,
startupCommand,
canReuseConnection,
hasIcon: !!options?.icon,
});
const result = await backend.openTerminalPopup({
title: popupTitle,
icon: options?.icon,
parentSessionId: parentSession.id,
startupCommand,
sourceSession: buildCommandPopupSourceSession(parentSession, startupCommand, canReuseConnection),
});
await writeSystemManagerDiagnostic('openInteractiveTerminal result', {
title: popupTitle,
success: result.success,
error: result.error,
popupId: result.popupId,
});
return result;
}