Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { Button } from "@superset/ui/button";
import { Card } from "@superset/ui/card";
import { HiExclamationTriangle } from "react-icons/hi2";
import { LuPower, LuTerminal } from "react-icons/lu";

interface OverlayContainerProps {
children: React.ReactNode;
}

/**
* Common overlay container with centered positioning and backdrop.
*/
function OverlayContainer({ children }: OverlayContainerProps) {
return (
<div className="absolute inset-0 z-10 flex items-center justify-center bg-black/50">
{children}
</div>
);
}

interface KilledOverlayProps {
onRestart: () => void;
}

/**
* Overlay shown when terminal session was killed by user.
*/
export function KilledOverlay({ onRestart }: KilledOverlayProps) {
return (
<OverlayContainer>
<Card className="gap-3 py-4 px-2">
<div className="flex flex-col items-center text-center gap-1.5 px-4">
<LuPower className="size-5 text-muted-foreground" />
<div className="space-y-0.5">
<p className="text-sm font-medium">Session killed</p>
<p className="text-xs text-muted-foreground">
You terminated this shell session
</p>
</div>
</div>
<div className="px-4">
<Button size="sm" className="w-full" onClick={onRestart}>
Restart
</Button>
</div>
</Card>
</OverlayContainer>
);
}

interface ConnectionErrorOverlayProps {
onRetry: () => void;
}

/**
* Overlay shown when connection to terminal daemon is lost.
*/
export function ConnectionErrorOverlay({
onRetry,
}: ConnectionErrorOverlayProps) {
return (
<OverlayContainer>
<Card className="gap-3 py-4 px-2 max-w-xs">
<div className="flex flex-col items-center text-center gap-1.5 px-4">
<HiExclamationTriangle className="size-5 text-destructive" />
<div className="space-y-0.5">
<p className="text-sm font-medium">Connection error</p>
<p className="text-xs text-muted-foreground">
Lost connection to terminal daemon
</p>
</div>
</div>
<div className="px-4">
<Button size="sm" className="w-full" onClick={onRetry}>
Retry
</Button>
</div>
</Card>
</OverlayContainer>
);
}

interface RestoredOverlayProps {
onStartShell: () => void;
}

/**
* Overlay shown after cold restore (reboot recovery).
* Previous scrollback is preserved and displayed read-only until user starts new shell.
*/
export function RestoredOverlay({ onStartShell }: RestoredOverlayProps) {
return (
<OverlayContainer>
<Card className="gap-3 py-4 px-2">
<div className="flex flex-col items-center text-center gap-1.5 px-4">
<LuTerminal className="size-5 text-primary" />
<div className="space-y-0.5">
<p className="text-sm font-medium">Session restored</p>
<p className="text-xs text-muted-foreground">
Previous scrollback preserved after restart
</p>
</div>
</div>
<div className="px-4">
<Button size="sm" className="w-full" onClick={onStartShell}>
Start Shell
</Button>
</div>
</Card>
</OverlayContainer>
);
}
Comment on lines +6 to +112

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# Check if OverlayContainer or individual overlays are imported elsewhere
rg "from.*TerminalOverlays|import.*TerminalOverlays" --type ts --type tsx

Repository: superset-sh/superset

Length of output: 91


🏁 Script executed:

# Check if there are re-exports or if these are used individually
rg "KilledOverlay|ConnectionErrorOverlay|RestoredOverlay|OverlayContainer" --type ts --type tsx -l

Repository: superset-sh/superset

Length of output: 91


🏁 Script executed:

# Check similar component structures in the codebase for patterns
fd "components" -t d apps/desktop/src/renderer --max-depth 5 | head -20

Repository: superset-sh/superset

Length of output: 1030


🏁 Script executed:

# Search for imports of components from this file
rg "TerminalOverlays|KilledOverlay|ConnectionErrorOverlay|RestoredOverlay" --glob "*.{ts,tsx}" -B2 -A2 | head -100

Repository: superset-sh/superset

Length of output: 8507


🏁 Script executed:

# Check the directory structure to understand the file organization
cat apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/TerminalOverlays/TerminalOverlays.tsx | head -20

Repository: superset-sh/superset

Length of output: 596


🏁 Script executed:

# Look for files importing from the TerminalOverlays directory/file
fd . apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/ -type f | head -20

Repository: superset-sh/superset

Length of output: 234


🏁 Script executed:

# Check the index.ts file to see how components are exported
cat apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/TerminalOverlays/index.ts

Repository: superset-sh/superset

Length of output: 160


Split into one component per file.

This file defines three exported components (KilledOverlay, ConnectionErrorOverlay, RestoredOverlay) in a single .tsx file, violating the one-component-per-file rule. Each overlay should be in its own file. The internal OverlayContainer helper can be extracted to a shared utility file or colocated with one of the overlays if used by only that component.

Example structure:
TerminalOverlays/
├── KilledOverlay.tsx
├── ConnectionErrorOverlay.tsx
├── RestoredOverlay.tsx
├── OverlayContainer.tsx (or merge into a shared utility)
└── index.ts
🤖 Prompt for AI Agents
In
`@apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/TerminalOverlays/TerminalOverlays.tsx`
around lines 6 - 112, This file bundles three exported components in one module;
split KilledOverlay, ConnectionErrorOverlay, and RestoredOverlay into their own
files (KilledOverlay.tsx, ConnectionErrorOverlay.tsx, RestoredOverlay.tsx) and
move the shared OverlayContainer into OverlayContainer.tsx (or colocate with one
overlay) then create an index.ts that re-exports the three overlays; update each
new file to import OverlayContainer and ensure the exported component names
(KilledOverlay, ConnectionErrorOverlay, RestoredOverlay) and prop interfaces
(KilledOverlayProps, ConnectionErrorOverlayProps, RestoredOverlayProps) match
the originals so existing consumers keep working.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export {
ConnectionErrorOverlay,
KilledOverlay,
RestoredOverlay,
} from "./TerminalOverlays";
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
export type { UseTerminalConnectionOptions } from "./useTerminalConnection";
export { useTerminalConnection } from "./useTerminalConnection";
export type {
UseTerminalCwdOptions,
UseTerminalCwdResult,
} from "./useTerminalCwd";
export { useTerminalCwd } from "./useTerminalCwd";
export type {
UseTerminalFileLinksOptions,
UseTerminalFileLinksResult,
} from "./useTerminalFileLinks";
export { useTerminalFileLinks } from "./useTerminalFileLinks";
export type {
UseTerminalInputOptions,
UseTerminalInputResult,
} from "./useTerminalInput";
export { useTerminalInput } from "./useTerminalInput";
export type {
CreateOrAttachResult,
UseTerminalSessionOptions,
UseTerminalSessionRefs,
UseTerminalSessionResult,
} from "./useTerminalSession";
export {
coldRestoreState,
pendingDetaches,
useTerminalSession,
} from "./useTerminalSession";
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import debounce from "lodash/debounce";
import { useCallback, useEffect, useRef, useState } from "react";
import { useTabsStore } from "renderer/stores/tabs/store";
import { parseCwd } from "../parseCwd";

export interface UseTerminalCwdOptions {
paneId: string;
/** Initial CWD from pane data (e.g., initialCwd) */
initialCwd?: string | null;
/** Workspace CWD as fallback seed */
workspaceCwd?: string | null;
}

export interface UseTerminalCwdResult {
/** Current terminal CWD */
terminalCwd: string | null;
/** Whether CWD has been confirmed by OSC-7 (vs seeded from initialCwd) */
cwdConfirmed: boolean;
/** Update CWD from terminal output data (parses OSC-7 sequences) */
updateCwdFromData: (data: string) => void;
/** Ref to updateCwdFromData for use inside effects */
updateCwdRef: React.RefObject<(data: string) => void>;
/** Set CWD directly (e.g., from restore data) */
setTerminalCwd: (cwd: string | null) => void;
}

/**
* Hook to manage terminal current working directory.
*
* Encapsulates:
* - OSC-7 parsing to extract CWD from terminal output
* - CWD seeding from initialCwd or workspaceCwd
* - Debounced store updates to reduce store churn
* - CWD confirmation tracking (seeded vs OSC-7 confirmed)
*/
export function useTerminalCwd({
paneId,
initialCwd,
workspaceCwd,
}: UseTerminalCwdOptions): UseTerminalCwdResult {
const [terminalCwd, setTerminalCwd] = useState<string | null>(null);
const [cwdConfirmed, setCwdConfirmed] = useState(false);

const updatePaneCwd = useTabsStore((s) => s.updatePaneCwd);

// Debounced CWD update to reduce store updates during rapid directory changes
const debouncedUpdatePaneCwdRef = useRef(
debounce((id: string, cwd: string | null, confirmed: boolean) => {
updatePaneCwd(id, cwd, confirmed);
}, 150),
);

// Parse terminal data for cwd (OSC 7 sequences)
const updateCwdFromData = useCallback((data: string) => {
const cwd = parseCwd(data);
if (cwd !== null) {
setTerminalCwd(cwd);
setCwdConfirmed(true); // Confirmed by OSC-7
}
}, []);

// Ref for use inside effects
const updateCwdRef = useRef(updateCwdFromData);
updateCwdRef.current = updateCwdFromData;

// Seed cwd from initialCwd or workspace path (shell spawns there)
// OSC-7 will override if/when the shell reports directory changes
useEffect(() => {
if (terminalCwd) return; // Already have a cwd, don't override
const seedCwd = initialCwd || workspaceCwd;
if (seedCwd) {
setTerminalCwd(seedCwd);
setCwdConfirmed(false); // Seeded, not confirmed by OSC-7
}
}, [initialCwd, workspaceCwd, terminalCwd]);

// Sync terminal cwd to store for DirectoryNavigator (debounced)
useEffect(() => {
debouncedUpdatePaneCwdRef.current(paneId, terminalCwd, cwdConfirmed);
}, [terminalCwd, cwdConfirmed, paneId]);

// Cleanup debounced function on unmount
useEffect(() => {
const debouncedFn = debouncedUpdatePaneCwdRef.current;
return () => {
debouncedFn.cancel();
};
}, []);

return {
terminalCwd,
cwdConfirmed,
updateCwdFromData,
updateCwdRef,
setTerminalCwd,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { toast } from "@superset/ui/sonner";
import { useCallback, useRef } from "react";
import { electronTrpc } from "renderer/lib/electron-trpc";
import { electronTrpcClient as trpcClient } from "renderer/lib/trpc-client";
import { useTabsStore } from "renderer/stores/tabs/store";
import { normalizeFilePath } from "../normalizeFilePath";

export interface UseTerminalFileLinksOptions {
workspaceId: string;
/** Ref to workspace CWD (use ref to avoid terminal recreation) */
workspaceCwdRef: React.RefObject<string | null | undefined>;
}

export interface UseTerminalFileLinksResult {
/** Handler for file link clicks in terminal */
handleFileLinkClick: (path: string, line?: number, column?: number) => void;
/** Ref to handleFileLinkClick for use in terminal instance creation */
handleFileLinkClickRef: React.RefObject<
(path: string, line?: number, column?: number) => void
>;
Comment on lines +14 to +20

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's read the file to understand the current implementation
cat -n apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/useTerminalFileLinks.ts

Repository: superset-sh/superset

Length of output: 184


🏁 Script executed:

# Search for all usages of handleFileLinkClick in the codebase
rg "handleFileLinkClick" --type ts --type tsx -A 2 -B 2

Repository: superset-sh/superset

Length of output: 91


🏁 Script executed:

# Also search for any console logging in this file to check the logging prefix
rg "console\.(error|warn|log)" apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/useTerminalFileLinks.ts -A 1 -B 1

Repository: superset-sh/superset

Length of output: 285


🏁 Script executed:

# Read the file directly with cat
cat -n "apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/useTerminalFileLinks.ts"

Repository: superset-sh/superset

Length of output: 4203


🏁 Script executed:

# Search for handleFileLinkClick usage more broadly (all file types)
rg "handleFileLinkClick" -A 3 -B 1

Repository: superset-sh/superset

Length of output: 4853


🏁 Script executed:

# Find all files in the Terminal hooks directory
fd . "apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal"

Repository: superset-sh/superset

Length of output: 5265


Switch file-link handlers to a params object.

The callback currently takes positional parameters (path, line, column). Per coding guidelines, functions with 2+ parameters should accept a single params object with named properties. Refactor the interface definitions and implementation, then update the call site in Terminal.tsx.

♻️ Proposed refactor
+export interface TerminalFileLinkClickParams {
+	path: string;
+	line?: number;
+	column?: number;
+}
+
 export interface UseTerminalFileLinksResult {
 	/** Handler for file link clicks in terminal */
-	handleFileLinkClick: (path: string, line?: number, column?: number) => void;
+	handleFileLinkClick: (params: TerminalFileLinkClickParams) => void;
 	/** Ref to handleFileLinkClick for use in terminal instance creation */
 	handleFileLinkClickRef: React.RefObject<
-		(path: string, line?: number, column?: number) => void
+		(params: TerminalFileLinkClickParams) => void
 	>;
 }

 const handleFileLinkClick = useCallback(
-	(path: string, line?: number, column?: number) => {
+	({ path, line, column }: TerminalFileLinkClickParams) => {

Then in Terminal.tsx, update the call site from:

-onFileLinkClick: (path, line, column) =>
-	handleFileLinkClickRef.current(path, line, column),
+onFileLinkClick: (path, line, column) =>
+	handleFileLinkClickRef.current({ path, line, column }),
🤖 Prompt for AI Agents
In
`@apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/useTerminalFileLinks.ts`
around lines 14 - 20, Change the positional params on the terminal file-link
handler to a single params object: update the UseTerminalFileLinksResult
interface to have handleFileLinkClick: (args: { path: string; line?: number;
column?: number }) => void and update handleFileLinkClickRef to
React.RefObject<(args: { path: string; line?: number; column?: number }) =>
void>; then refactor the implementation in useTerminalFileLinks (replace usages
of (path, line, column) with a single args object destructured as { path, line,
column }) and update the call site in Terminal.tsx to call handleFileLinkClick({
path, line, column }) instead of positional arguments. Ensure all references and
types are adjusted to the new named-params shape.

}

/**
* Hook to manage terminal file link handling.
*
* Encapsulates:
* - Terminal link behavior setting query
* - File path normalization for file viewer
* - External editor fallback
* - Toast notifications for errors
*/
export function useTerminalFileLinks({
workspaceId,
workspaceCwdRef,
}: UseTerminalFileLinksOptions): UseTerminalFileLinksResult {
const addFileViewerPane = useTabsStore((s) => s.addFileViewerPane);

// Query terminal link behavior setting
const { data: terminalLinkBehavior } =
electronTrpc.settings.getTerminalLinkBehavior.useQuery();

const handleFileLinkClick = useCallback(
(path: string, line?: number, column?: number) => {
const behavior = terminalLinkBehavior ?? "external-editor";
const workspaceCwd = workspaceCwdRef.current;

// Helper to open in external editor
const openInExternalEditor = () => {
trpcClient.external.openFileInEditor
.mutate({
path,
line,
column,
cwd: workspaceCwd ?? undefined,
})
.catch((error) => {
console.error(
"[Terminal] Failed to open file in editor:",
path,
error,
);
const errorMessage =
error instanceof Error ? error.message : String(error);
toast.error("Failed to open file in editor", {
description: errorMessage,
});
});
};

if (behavior === "file-viewer") {
// If workspaceCwd is not loaded yet, fall back to external editor
if (!workspaceCwd) {
console.warn(
"[Terminal] workspaceCwd not loaded, falling back to external editor",
);
Comment on lines +57 to +75

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Align console prefixes with [domain/operation] convention.

The current log prefixes don’t include an operation identifier. Please adjust to the required format. As per coding guidelines, ...

💡 Suggested tweak
-						console.error(
-							"[Terminal] Failed to open file in editor:",
+						console.error(
+							"[terminal/open-file] Failed to open file in editor:",
 							path,
 							error,
 						);
@@
-					console.warn(
-						"[Terminal] workspaceCwd not loaded, falling back to external editor",
-					);
+					console.warn(
+						"[terminal/file-link] workspaceCwd not loaded, falling back to external editor",
+					);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.error(
"[Terminal] Failed to open file in editor:",
path,
error,
);
const errorMessage =
error instanceof Error ? error.message : String(error);
toast.error("Failed to open file in editor", {
description: errorMessage,
});
});
};
if (behavior === "file-viewer") {
// If workspaceCwd is not loaded yet, fall back to external editor
if (!workspaceCwd) {
console.warn(
"[Terminal] workspaceCwd not loaded, falling back to external editor",
);
console.error(
"[terminal/open-file] Failed to open file in editor:",
path,
error,
);
const errorMessage =
error instanceof Error ? error.message : String(error);
toast.error("Failed to open file in editor", {
description: errorMessage,
});
});
};
if (behavior === "file-viewer") {
// If workspaceCwd is not loaded yet, fall back to external editor
if (!workspaceCwd) {
console.warn(
"[terminal/file-link] workspaceCwd not loaded, falling back to external editor",
);
🤖 Prompt for AI Agents
In
`@apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/hooks/useTerminalFileLinks.ts`
around lines 57 - 75, Update the console log prefixes to follow the
"[domain/operation]" convention: replace console.error("[Terminal] Failed to
open file in editor:", ...) with something like
console.error("[terminal/open-file] Failed to open file in editor:", ...) and
replace console.warn("[Terminal] workspaceCwd not loaded, falling back to
external editor", ...) with console.warn("[terminal/workspace-cwd] workspaceCwd
not loaded, falling back to external editor", ...). Search within
useTerminalFileLinks (and the surrounding functions open-file handling) for
other "[Terminal]" logs and rename them to the domain/operation format
(lowercase domain, concise operation name) so all logs in this file follow the
same convention.

openInExternalEditor();
return;
}

// Normalize path for file viewer
const normalized = normalizeFilePath(path, workspaceCwd);

if (normalized.type === "absolute-outside-workspace") {
toast.warning("File is outside the workspace", {
description:
"Switch to 'External editor' in Settings to open this file",
});
return;
}

const filePath =
normalized.type === "workspace-root" ? "." : normalized.path;
addFileViewerPane(workspaceId, { filePath, line, column });
} else {
openInExternalEditor();
}
},
[terminalLinkBehavior, workspaceId, workspaceCwdRef, addFileViewerPane],
);

// Ref to avoid terminal recreation when callback changes
const handleFileLinkClickRef = useRef(handleFileLinkClick);
handleFileLinkClickRef.current = handleFileLinkClick;

return {
handleFileLinkClick,
handleFileLinkClickRef,
};
}
Loading
Loading