[Init] Initial commit - NetMesh terminal manager
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
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
This commit is contained in:
139
domain/sftpDualPaneOpen.ts
Normal file
139
domain/sftpDualPaneOpen.ts
Normal file
@@ -0,0 +1,139 @@
|
||||
import { isPluginHostProtocol } from "./pluginConnection";
|
||||
|
||||
export type DualPaneSftpTab = {
|
||||
id: string;
|
||||
isLocal: boolean;
|
||||
hostId: string | null;
|
||||
endpointKey: string | null;
|
||||
hasConnection: boolean;
|
||||
};
|
||||
|
||||
export function isReusableSftpConnectionStatus(
|
||||
status?: string | null,
|
||||
): boolean {
|
||||
return status === "connected" || status === "connecting";
|
||||
}
|
||||
|
||||
export function dualPaneTabFromPane(pane: {
|
||||
id: string;
|
||||
connection: {
|
||||
isLocal?: boolean;
|
||||
hostId?: string | null;
|
||||
status?: string | null;
|
||||
} | null;
|
||||
}, endpointKey: string | null = null): DualPaneSftpTab {
|
||||
const live = isReusableSftpConnectionStatus(pane.connection?.status);
|
||||
return {
|
||||
id: pane.id,
|
||||
isLocal: live && !!pane.connection?.isLocal,
|
||||
hostId: pane.connection?.isLocal
|
||||
? "local"
|
||||
: pane.connection?.hostId ?? null,
|
||||
endpointKey,
|
||||
hasConnection: live,
|
||||
};
|
||||
}
|
||||
|
||||
export type DualPaneSftpPlan = {
|
||||
selectLeftTabId: string | null;
|
||||
connectLeftLocal: boolean;
|
||||
addLeftTab: boolean;
|
||||
selectRightTabId: string | null;
|
||||
connectRightHost: boolean;
|
||||
addRightTab: boolean;
|
||||
};
|
||||
|
||||
export function canOpenDualPaneSftp(host: { protocol?: string }): boolean {
|
||||
const protocol = host.protocol ?? "ssh";
|
||||
if (protocol === "serial") return false;
|
||||
if (isPluginHostProtocol(protocol)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
export function planDualPaneSftpOpen(params: {
|
||||
leftTabs: DualPaneSftpTab[];
|
||||
rightTabs: DualPaneSftpTab[];
|
||||
hostId: string;
|
||||
hostEndpointKey: string;
|
||||
}): DualPaneSftpPlan {
|
||||
const localLeft = params.leftTabs.find((tab) => tab.isLocal);
|
||||
const idleLeft = params.leftTabs.find((tab) => !tab.hasConnection);
|
||||
const matchingRight = params.rightTabs.find(
|
||||
(tab) => tab.hostId === params.hostId
|
||||
&& tab.endpointKey === params.hostEndpointKey
|
||||
&& tab.hasConnection,
|
||||
);
|
||||
const matchingDeadRight = params.rightTabs.find(
|
||||
(tab) => tab.hostId === params.hostId && !tab.hasConnection,
|
||||
);
|
||||
const idleRight = params.rightTabs.find((tab) => !tab.hasConnection);
|
||||
|
||||
const leftReuse = localLeft ?? idleLeft;
|
||||
const rightReuse = matchingRight ?? matchingDeadRight ?? idleRight;
|
||||
|
||||
return {
|
||||
selectLeftTabId: leftReuse?.id ?? null,
|
||||
connectLeftLocal: !localLeft,
|
||||
addLeftTab: !leftReuse && params.leftTabs.length > 0,
|
||||
selectRightTabId: rightReuse?.id ?? null,
|
||||
connectRightHost: !matchingRight,
|
||||
addRightTab: !rightReuse && params.rightTabs.length > 0,
|
||||
};
|
||||
}
|
||||
|
||||
export type DualPaneSftpApi = {
|
||||
leftTabs: DualPaneSftpTab[];
|
||||
rightTabs: DualPaneSftpTab[];
|
||||
selectTab: (side: "left" | "right", tabId: string) => void;
|
||||
connect: (
|
||||
side: "left" | "right",
|
||||
host: { id: string } | "local",
|
||||
options?: { forceNewTab?: boolean; tabId?: string },
|
||||
) => void;
|
||||
};
|
||||
|
||||
function connectOptions(plan: {
|
||||
addTab: boolean;
|
||||
selectTabId: string | null;
|
||||
}): { forceNewTab?: boolean; tabId?: string } | undefined {
|
||||
if (plan.addTab) return { forceNewTab: true };
|
||||
if (plan.selectTabId) return { tabId: plan.selectTabId };
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function applyDualPaneSftpOpen<THost extends { id: string }>(
|
||||
api: DualPaneSftpApi,
|
||||
host: THost,
|
||||
hostEndpointKey: string,
|
||||
): DualPaneSftpPlan {
|
||||
const plan = planDualPaneSftpOpen({
|
||||
leftTabs: api.leftTabs,
|
||||
rightTabs: api.rightTabs,
|
||||
hostId: host.id,
|
||||
hostEndpointKey,
|
||||
});
|
||||
|
||||
if (plan.selectLeftTabId) {
|
||||
api.selectTab("left", plan.selectLeftTabId);
|
||||
}
|
||||
if (plan.connectLeftLocal) {
|
||||
api.connect(
|
||||
"left",
|
||||
"local",
|
||||
connectOptions({ addTab: plan.addLeftTab, selectTabId: plan.selectLeftTabId }),
|
||||
);
|
||||
}
|
||||
|
||||
if (plan.selectRightTabId) {
|
||||
api.selectTab("right", plan.selectRightTabId);
|
||||
}
|
||||
if (plan.connectRightHost) {
|
||||
api.connect(
|
||||
"right",
|
||||
host,
|
||||
connectOptions({ addTab: plan.addRightTab, selectTabId: plan.selectRightTabId }),
|
||||
);
|
||||
}
|
||||
|
||||
return plan;
|
||||
}
|
||||
Reference in New Issue
Block a user