Prepare datamodel for multi-environment (#1765)
Co-authored-by: justsomelegs <[email protected]> Co-authored-by: codex <[email protected]> Co-authored-by: Cursor Agent <[email protected]> Co-authored-by: cursor[bot] <206951365+cursor[bot]@users.noreply.github.com>
This commit is contained in:
121 files changed
+10195
-4958
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { FitAddon } from "@xterm/addon-fit";
|
||||
import { Plus, SquareSplitHorizontal, TerminalSquare, Trash2, XIcon } from "lucide-react";
|
||||
import {
|
||||
type ScopedThreadRef,
|
||||
type TerminalEvent,
|
||||
type TerminalSessionSnapshot,
|
||||
type ThreadId,
|
||||
@@ -31,7 +32,8 @@ import {
|
||||
MAX_TERMINALS_PER_GROUP,
|
||||
type ThreadTerminalGroup,
|
||||
} from "../types";
|
||||
import { readNativeApi } from "~/nativeApi";
|
||||
import { readEnvironmentApi } from "~/environmentApi";
|
||||
import { readLocalApi } from "~/localApi";
|
||||
import { selectTerminalEventEntries, useTerminalStateStore } from "../terminalStateStore";
|
||||
|
||||
const MIN_DRAWER_HEIGHT = 180;
|
||||
@@ -208,6 +210,7 @@ export function shouldHandleTerminalSelectionMouseUp(
|
||||
}
|
||||
|
||||
interface TerminalViewportProps {
|
||||
threadRef: ScopedThreadRef;
|
||||
threadId: ThreadId;
|
||||
terminalId: string;
|
||||
terminalLabel: string;
|
||||
@@ -222,7 +225,8 @@ interface TerminalViewportProps {
|
||||
drawerHeight: number;
|
||||
}
|
||||
|
||||
function TerminalViewport({
|
||||
export function TerminalViewport({
|
||||
threadRef,
|
||||
threadId,
|
||||
terminalId,
|
||||
terminalLabel,
|
||||
@@ -260,6 +264,9 @@ function TerminalViewport({
|
||||
if (!mount) return;
|
||||
|
||||
let disposed = false;
|
||||
const api = readEnvironmentApi(threadRef.environmentId);
|
||||
const localApi = readLocalApi();
|
||||
if (!api || !localApi) return;
|
||||
|
||||
const fitAddon = new FitAddon();
|
||||
const terminal = new Terminal({
|
||||
@@ -277,9 +284,6 @@ function TerminalViewport({
|
||||
terminalRef.current = terminal;
|
||||
fitAddonRef.current = fitAddon;
|
||||
|
||||
const api = readNativeApi();
|
||||
if (!api) return;
|
||||
|
||||
const clearSelectionAction = () => {
|
||||
selectionActionRequestIdRef.current += 1;
|
||||
if (selectionActionTimerRef.current !== null) {
|
||||
@@ -340,7 +344,7 @@ function TerminalViewport({
|
||||
const requestId = ++selectionActionRequestIdRef.current;
|
||||
selectionActionOpenRef.current = true;
|
||||
try {
|
||||
const clicked = await api.contextMenu.show(
|
||||
const clicked = await localApi.contextMenu.show(
|
||||
[{ id: "add-to-chat", label: "Add to chat" }],
|
||||
nextAction.position,
|
||||
);
|
||||
@@ -416,7 +420,7 @@ function TerminalViewport({
|
||||
if (!latestTerminal) return;
|
||||
|
||||
if (match.kind === "url") {
|
||||
void api.shell.openExternal(match.text).catch((error) => {
|
||||
void localApi.shell.openExternal(match.text).catch((error: unknown) => {
|
||||
writeSystemMessage(
|
||||
latestTerminal,
|
||||
error instanceof Error ? error.message : "Unable to open link",
|
||||
@@ -426,7 +430,7 @@ function TerminalViewport({
|
||||
}
|
||||
|
||||
const target = resolvePathLinkTarget(match.text, cwd);
|
||||
void openInPreferredEditor(api, target).catch((error) => {
|
||||
void openInPreferredEditor(localApi, target).catch((error) => {
|
||||
writeSystemMessage(
|
||||
latestTerminal,
|
||||
error instanceof Error ? error.message : "Unable to open path",
|
||||
@@ -573,12 +577,12 @@ function TerminalViewport({
|
||||
const previousLastEntryId =
|
||||
selectTerminalEventEntries(
|
||||
previousState.terminalEventEntriesByKey,
|
||||
threadId,
|
||||
threadRef,
|
||||
terminalId,
|
||||
).at(-1)?.id ?? 0;
|
||||
const nextEntries = selectTerminalEventEntries(
|
||||
state.terminalEventEntriesByKey,
|
||||
threadId,
|
||||
threadRef,
|
||||
terminalId,
|
||||
);
|
||||
const nextLastEntryId = nextEntries.at(-1)?.id ?? 0;
|
||||
@@ -608,7 +612,7 @@ function TerminalViewport({
|
||||
writeTerminalSnapshot(activeTerminal, snapshot);
|
||||
const bufferedEntries = selectTerminalEventEntries(
|
||||
useTerminalStateStore.getState().terminalEventEntriesByKey,
|
||||
threadId,
|
||||
threadRef,
|
||||
terminalId,
|
||||
);
|
||||
const replayEntries = selectTerminalEventEntriesAfterSnapshot(
|
||||
@@ -677,7 +681,7 @@ function TerminalViewport({
|
||||
// autoFocus is intentionally omitted;
|
||||
// it is only read at mount time and must not trigger terminal teardown/recreation.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [cwd, runtimeEnv, terminalId, threadId]);
|
||||
}, [cwd, runtimeEnv, terminalId, threadId, threadRef]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!autoFocus) return;
|
||||
@@ -692,7 +696,7 @@ function TerminalViewport({
|
||||
}, [autoFocus, focusRequestId]);
|
||||
|
||||
useEffect(() => {
|
||||
const api = readNativeApi();
|
||||
const api = readEnvironmentApi(threadRef.environmentId);
|
||||
const terminal = terminalRef.current;
|
||||
const fitAddon = fitAddonRef.current;
|
||||
if (!api || !terminal || !fitAddon) return;
|
||||
@@ -714,13 +718,14 @@ function TerminalViewport({
|
||||
return () => {
|
||||
window.cancelAnimationFrame(frame);
|
||||
};
|
||||
}, [drawerHeight, resizeEpoch, terminalId, threadId]);
|
||||
}, [drawerHeight, resizeEpoch, terminalId, threadId, threadRef]);
|
||||
return (
|
||||
<div ref={containerRef} className="relative h-full w-full overflow-hidden rounded-[4px]" />
|
||||
);
|
||||
}
|
||||
|
||||
interface ThreadTerminalDrawerProps {
|
||||
threadRef: ScopedThreadRef;
|
||||
threadId: ThreadId;
|
||||
cwd: string;
|
||||
worktreePath?: string | null;
|
||||
@@ -773,6 +778,7 @@ function TerminalActionButton({ label, className, onClick, children }: TerminalA
|
||||
}
|
||||
|
||||
export default function ThreadTerminalDrawer({
|
||||
threadRef,
|
||||
threadId,
|
||||
cwd,
|
||||
worktreePath,
|
||||
@@ -1098,6 +1104,7 @@ export default function ThreadTerminalDrawer({
|
||||
>
|
||||
<div className="h-full p-1">
|
||||
<TerminalViewport
|
||||
threadRef={threadRef}
|
||||
threadId={threadId}
|
||||
terminalId={terminalId}
|
||||
terminalLabel={terminalLabelById.get(terminalId) ?? "Terminal"}
|
||||
@@ -1119,6 +1126,7 @@ export default function ThreadTerminalDrawer({
|
||||
<div className="h-full p-1">
|
||||
<TerminalViewport
|
||||
key={resolvedActiveTerminalId}
|
||||
threadRef={threadRef}
|
||||
threadId={threadId}
|
||||
terminalId={resolvedActiveTerminalId}
|
||||
terminalLabel={terminalLabelById.get(resolvedActiveTerminalId) ?? "Terminal"}
|
||||
|
||||
Reference in new issue
Block a user