Skip to content

refactor(desktop): modularize PresetsSettings into component folder structure - #288

Merged
Kitenite merged 11 commits into
mainfrom
unlikely-ermine-5ff844
Dec 9, 2025
Merged

Kitenite merged 11 commits into
mainfrom
unlikely-ermine-5ff844

Conversation

@Kitenite

@Kitenite Kitenite commented Dec 8, 2025 •

Copy link
Copy Markdown
Member

Summary

  • Split monolithic PresetsSettings.tsx into separate components following co-location pattern
  • Added types.ts with shared types (TerminalPreset, PresetColumnConfig) and column configuration
  • Created CommandsEditor/ component for multi-command input with Enter/Backspace handling
  • Created PresetRow/ with PresetCell for programmatic column rendering
  • Added unique IDs to TerminalPreset for stable React keys

Test plan

  • Verify PresetsSettings renders correctly in settings view
  • Test adding/editing/deleting presets
  • Test command editing with Enter to add and Backspace to remove
  • Verify input fields don't blur while typing

🤖 Generated with Claude Code

Summary by CodeRabbit

New Features

  • Added terminal presets management—create, edit, and delete reusable preset configurations with name, working directory, and commands
  • Enhanced command palette with preset selection when creating new terminals
  • Presets automatically apply to new terminal sessions with preconfigured commands and working directories
  • Added Presets settings section for managing terminal configurations

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel

vercel Bot commented Dec 8, 2025 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
website Ready Ready Preview Comment Dec 9, 2025 3:09am

@coderabbitai

coderabbitai Bot commented Dec 8, 2025 •

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@Kitenite has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 16 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 405233d and 308309a.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx (4 hunks)
  • apps/desktop/src/renderer/stores/tabs/store.ts (3 hunks)
  • apps/desktop/src/renderer/stores/tabs/types.ts (3 hunks)
  • apps/desktop/src/renderer/stores/tabs/utils.ts (3 hunks)

Walkthrough

This PR introduces a complete terminal presets feature enabling users to save and reuse terminal configurations with custom names, working directories, and command sequences. It adds UI components for preset management, server-side CRUD operations, a command palette integration, and logic to apply presets when creating new terminal sessions with proper cwd resolution and command execution.

Changes

Cohort / File(s) Summary
Terminal Presets UI Components
apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/CommandsEditor.tsx, apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/index.ts, apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/PresetRow.tsx, apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/index.ts, apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx, apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/index.ts, apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts
Creates new React components for managing terminal presets: CommandsEditor (dynamic command list editing), PresetRow (editable preset table row), PresetsSettings (main presets management view with add/delete functionality). Defines column configuration and types.
Settings Integration
apps/desktop/src/renderer/screens/main/components/SettingsView/SettingsContent.tsx, apps/desktop/src/renderer/screens/main/components/SettingsView/SettingsSidebar/GeneralSettings.tsx, apps/desktop/src/renderer/stores/app-state.ts
Integrates presets into settings UI by adding PresetsSettings render branch, new Presets sidebar menu item, and expanding SettingsSection union type to include "presets".
Shared UI Command Component
packages/ui/package.json, packages/ui/src/components/command.tsx
Introduces reusable command palette UI library with Command, CommandDialog, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandSeparator, CommandItem, and CommandShortcut components built on cmdk library.
Tabs & Terminal Command Palette
apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx, apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/index.tsx
Enhances TabsCommandDialog to display terminal presets and handle preset selection; reorganizes TabsView to integrate command dialog with ellipsis menu for tab operations.
Server-side Preset API
apps/desktop/src/lib/trpc/routers/settings/index.ts, apps/desktop/src/main/lib/db/schemas.ts
Adds TRPC endpoints (getTerminalPresets, createTerminalPreset, updateTerminalPreset, deleteTerminalPreset) and extends Settings schema with optional terminalPresets array; TerminalPreset type includes id, name, cwd, and commands.
Terminal Session Management
apps/desktop/src/main/lib/terminal-manager.ts
Refactors TerminalManager.createOrAttach to support initialCommands parameter; introduces pendingSessions deduplication map to prevent concurrent session creation; adds logic to execute initialCommands after first shell output only on new (non-recovered) sessions.
Terminal Router & CWD Resolution
apps/desktop/src/lib/trpc/routers/terminal/terminal.ts, apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts, apps/desktop/src/lib/trpc/routers/terminal/utils/index.ts, apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.test.ts
Updates terminal router to pass initialCommands to session creation; implements resolveCwd utility for robust cwd resolution (handles absolute/relative paths, fallback to worktreePath or homedir); includes comprehensive test suite.
Terminal UI Component
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
Refactors Terminal component to extract initialCommands and initialCwd from pane, pass them to createOrAttach, and clear pane initial data after successful session creation; buffers pending stream events until terminal is ready.
Tab Store & Types
apps/desktop/src/renderer/stores/tabs/store.ts, apps/desktop/src/renderer/stores/tabs/types.ts, apps/desktop/src/renderer/stores/tabs/utils.ts
Extends Pane interface with optional initialCommands and initialCwd fields; updates addTab, createTabWithPane, and createPane to accept and propagate CreatePaneOptions; adds clearPaneInitialData(paneId) operation to reset initial data after use.
React Query Presets Hooks
apps/desktop/src/renderer/react-query/presets/index.ts
Implements usePresets, useCreateTerminalPreset, useUpdateTerminalPreset, and useDeleteTerminalPreset hooks; manages preset data fetching and mutations with automatic query invalidation.

Sequence Diagram

sequenceDiagram
    actor User
    participant TabsView as Tabs View
    participant Dialog as TabsCommandDialog
    participant TabsStore as Tabs Store
    participant Terminal as Terminal Component
    participant TermMgr as Terminal Manager
    participant TRPC as TRPC Router
    participant Shell as Shell Process

    User->>Dialog: Select preset from command palette
    Dialog->>TabsStore: handleSelectPreset(preset)
    TabsStore->>TabsStore: addTab(workspaceId, {<br/>initialCommands: preset.commands,<br/>initialCwd: preset.cwd<br/>})
    TabsStore-->>TabsView: Tab created with pane.initialCommands/cwd
    
    TabsView->>Terminal: Render new terminal pane
    Terminal->>Terminal: Extract paneInitialCommands & paneInitialCwd
    Terminal->>TRPC: createOrAttach({<br/>initialCommands, cwd<br/>})
    
    TRPC->>TRPC: resolveCwd(cwd, worktreePath)
    TRPC-->>TermMgr: Create session with resolved cwd
    
    TermMgr->>TermMgr: Check pendingSessions for dedup
    TermMgr->>Shell: Spawn shell at resolved cwd
    Shell-->>TermMgr: Shell ready (first output)
    
    TermMgr->>TermMgr: Send initialCommands joined with &&
    TermMgr->>Shell: Execute commands
    Shell->>Shell: Run commands in sequence
    
    Terminal->>Terminal: clearPaneInitialData(paneId)
    Terminal-->>User: Terminal ready with preset applied
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

  • TerminalManager.createOrAttach refactoring: Complex deduplication logic with pendingSessions map and post-output command dispatch—verify session tracking correctness and timing of initialCommands execution
  • Terminal.tsx initial data flow: Significant refactoring of initialization logic with refs, clearing state, and event buffering—ensure initial data clears properly and doesn't re-run on reattach
  • resolveCwd utility logic: Multiple fallback paths (absolute/relative, worktreePath, homedir)—verify edge cases in path resolution and the extensive test coverage
  • State propagation chain: initialCommands/initialCwd threading through Pane → Terminal → TerminalManager—ensure data flows correctly through all layers
  • Preset application integration: Multiple UI and store updates coordinating preset selection into tab creation—verify preset data reaches terminal properly

Possibly related PRs

Poem

🐰 A preset path through terminal lands,
Commands bundled in hoppy hands,
Save your cwd, commands so true,
Presets spring up, tab creation new!
Reuse and race where workflows bloom,
Less typing in the terminal room! 🌱

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: modularizing PresetsSettings into a component folder structure.
Description check ✅ Passed The description covers the key changes (component split, types, CommandsEditor, PresetRow), test plan, and references the source tool, but lacks related issues and detailed testing procedures.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Dec 8, 2025 •

Copy link
Copy Markdown
Contributor

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ✅ Neon database branch

Thank you for your contribution! 🎉

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 3

🧹 Nitpick comments (2)
apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/PresetRow.tsx (1)

20-48: Consider refining type assertions for better type safety.

The type assertions on lines 32 and 42 are necessary due to the generic column iteration, but they bypass type checking. While the current implementation works, a discriminated union or type guards could eliminate the need for as casts.

Example with type guards:

function PresetCell({
	column,
	preset,
	rowIndex,
	onChange,
	onCommandsChange,
}: PresetCellProps) {
	if (column.key === "commands") {
		const commands = preset.commands; // TypeScript narrows this
		return (
			<CommandsEditor
				commands={commands}
				onChange={(commands) => onCommandsChange(rowIndex, commands)}
				placeholder={column.placeholder}
			/>
		);
	}

	const value = preset[column.key]; // string after narrowing
	return (
		<Input
			variant="ghost"
			value={value}
			onChange={(e) => onChange(rowIndex, column.key, e.target.value)}
			className={`h-8 px-2 text-sm w-full ${column.mono ? "font-mono" : ""}`}
			placeholder={column.placeholder}
		/>
	);
}
apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/CommandsEditor.tsx (1)

59-61: Consider adding stable IDs to commands for better React reconciliation.

While the biome-ignore acknowledges the index key limitation, using array indices can cause React to lose input focus or misapply state when commands are reordered or deleted.

If feasible, update the data model to assign each command a stable ID:

// In types.ts
export interface TerminalPreset {
	id: string;
	name: string;
	cwd: string;
-	commands: string[];
+	commands: Array<{ id: string; value: string }>;
}

Then use command.id as the key. If that's too invasive, at minimum use the command value + index:

-<div key={`${baseId}-${index}`} className="flex items-center gap-2">
+<div key={command || `${baseId}-${index}`} className="flex items-center gap-2">
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0109b87 and 74a9d11.

📒 Files selected for processing (7)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/CommandsEditor.tsx (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/index.ts (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/PresetRow.tsx (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/index.ts (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/index.ts (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
apps/desktop/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)

For Electron interprocess communication, ALWAYS use tRPC as defined in src/lib/trpc

Files:

  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/index.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/index.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/CommandsEditor.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/PresetRow.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/index.ts
apps/desktop/**/*.{ts,tsx}

📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)

apps/desktop/**/*.{ts,tsx}: Please use alias as defined in tsconfig.json when possible
Prefer zustand for state management if it makes sense. Do not use effect unless absolutely necessary

Files:

  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/index.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/index.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/CommandsEditor.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/PresetRow.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/index.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Co-locate component dependencies (utils, hooks, constants, config, tests, stories) next to the file using them
Avoid any type in TypeScript unless absolutely necessary

Files:

  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/index.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/index.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/CommandsEditor.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/PresetRow.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/index.ts
apps/desktop/src/{renderer,shared,preload}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Never import Node.js modules in renderer process code or shared code in the desktop app

Files:

  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/index.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/index.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/CommandsEditor.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/PresetRow.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/index.ts
apps/desktop/src/{main,renderer,shared}/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

Use type-safe IPC system for communication between Electron main and renderer processes

Files:

  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/index.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/index.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/index.ts
**/{components,pages}/**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

**/{components,pages}/**/*.tsx: Use one folder per component with structure ComponentName/ComponentName.tsx plus index.ts for barrel export
Create one component per file - do not use multi-component files

Files:

  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/CommandsEditor.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/PresetRow.tsx
🧠 Learnings (3)
📚 Learning: 2025-12-06T18:44:13.290Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-06T18:44:13.290Z
Learning: Applies to **/{components,pages}/**/*.tsx : Use one folder per component with structure `ComponentName/ComponentName.tsx` plus `index.ts` for barrel export

Applied to files:

  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/index.ts
📚 Learning: 2025-12-06T18:44:13.290Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-06T18:44:13.290Z
Learning: Applies to src/components/{ui,ai-elements,react-flow}/**/*.tsx : Shadcn/ui components in `src/components/ui/`, `src/components/ai-elements`, and `src/components/react-flow/` use kebab-case single files (e.g., `button.tsx`) for shadcn CLI compatibility

Applied to files:

  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/CommandsEditor.tsx
📚 Learning: 2025-11-24T21:33:13.267Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: apps/desktop/AGENTS.md:0-0
Timestamp: 2025-11-24T21:33:13.267Z
Learning: Applies to apps/desktop/**/*.{ts,tsx} : Please use alias as defined in `tsconfig.json` when possible

Applied to files:

  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/index.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (8)
apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/index.ts (1)

1-1: LGTM!

Clean barrel export following the component folder structure pattern.

apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/index.ts (1)

1-1: LGTM!

Clean barrel export following the component folder structure pattern.

apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/index.ts (1)

1-1: LGTM!

Clean barrel export following the component folder structure pattern.

apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx (1)

44-101: Clean component structure and render logic.

The UI layout, event handler wiring, and conditional rendering are well-implemented. Using preset.id as the React key ensures stable component identity.

apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/PresetRow.tsx (1)

59-97: Well-structured row component with proper accessibility.

The component correctly iterates columns, applies alternating row styles, and includes an accessible delete button with appropriate ARIA labels.

apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/CommandsEditor.tsx (1)

18-55: Handler logic correctly implements add/delete behavior.

The command change, deletion, and keyboard event handlers properly manage the commands array and enforce the minimum-one-command constraint.

apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts (2)

1-21: Well-designed type system with proper column configuration.

The types are cleanly structured, PresetColumnKey correctly excludes the id field, and PRESET_COLUMNS provides a clear configuration for rendering.


23-28: Use Web Crypto API or move UUID generation to main process via IPC.

The code uses crypto.randomUUID(), which is a Node.js module API. This violates the coding guideline: "Never import Node.js modules in renderer process code." The renderer process has no explicit crypto exposure via the preload bridge. Replace with crypto.getRandomValues() from the Web Crypto API (which is available globally in modern Electron renderer contexts), or use tRPC to generate UUIDs in the main process and invoke them from the renderer.

⛔ Skipped due to learnings
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-06T18:44:13.290Z
Learning: Applies to apps/desktop/src/{renderer,shared,preload}/**/*.{ts,tsx} : Never import Node.js modules in renderer process code or shared code in the desktop app
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-06T18:44:13.290Z
Learning: Applies to apps/desktop/src/lib/electron-router-dom.ts : Never import Node.js modules (like `node:path` or `dotenv`) in `src/lib/electron-router-dom.ts` as it's shared between main and renderer processes
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-06T18:44:13.290Z
Learning: Applies to apps/desktop/src/{main,renderer,shared}/**/*.ts : Use type-safe IPC system for communication between Electron main and renderer processes
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: apps/desktop/AGENTS.md:0-0
Timestamp: 2025-11-24T21:33:13.267Z
Learning: Applies to apps/desktop/**/*.{ts,tsx,js,jsx} : For Electron interprocess communication, ALWAYS use tRPC as defined in `src/lib/trpc`

Kitenite and others added 2 commits December 8, 2025 15:35
…tructure

Split monolithic PresetsSettings.tsx into separate components following co-location pattern:
- types.ts: Shared types and column configuration
- CommandsEditor/: Multi-command input with Enter/Backspace handling
- PresetRow/: Row and cell components with programmatic column rendering
- PresetsSettings.tsx: Main component using column config for headers/rows

Added unique IDs to TerminalPreset for stable React keys.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add "presets" to SettingsSection type in app-state
- Add Presets section to settings sidebar with cog icon
- Render PresetsSettings component in SettingsContent
- Add TabsCommandDialog with quick actions for tabs view
- Add command component to UI package

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 3

♻️ Duplicate comments (1)
apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts (1)

30-55: Move MOCK_PRESETS to separate file and use stable IDs.

Two issues with the current implementation:

  1. Duplicate concern: As noted in a previous review, mock data should be separated from production type files.

  2. Unstable IDs: Using crypto.randomUUID() in a module-level constant means new IDs are generated each time the module loads (e.g., during hot reload), which can cause React key instability and state loss.

Create a separate mock data file with stable, hardcoded UUIDs:

// mockData.ts (for development/testing only)
import type { TerminalPreset } from "./types";

export const MOCK_PRESETS: TerminalPreset[] = [
	{
		id: "550e8400-e29b-41d4-a716-446655440001",
		name: "Dev Server",
		cwd: "apps/website",
		commands: ["bun dev"],
	},
	{
		id: "550e8400-e29b-41d4-a716-446655440002",
		name: "Build",
		cwd: ".",
		commands: ["bun run build"],
	},
	{
		id: "550e8400-e29b-41d4-a716-446655440003",
		name: "Test",
		cwd: ".",
		commands: ["bun test"],
	},
	{
		id: "550e8400-e29b-41d4-a716-446655440004",
		name: "Lint",
		cwd: ".",
		commands: ["bun run lint"],
	},
];

Then remove MOCK_PRESETS from types.ts and update imports in consuming files to use the new mockData.ts.

🧹 Nitpick comments (4)
PRESETS_PLAN.md (4)

8-24: Consider null handling alongside undefined in backwards compatibility.

The plan correctly emphasizes optional fields and null-safe reads with ?? []. However, it should clarify handling of both null and undefined values, as corrupted or partially migrated databases might have terminalPresets: null. Consider updating the fallback pattern to: presets = db.data.settings.terminalPresets ?? [] (which works for both cases) or explicitly document the assumption that only undefined is expected, never null.


164-171: Add safety guard for mutation hook onSuccess callback.

Lines 166-168 conditionally call options?.onSuccess?.(...args) without error handling. If either the invalidate calls or the onSuccess callback throws, the promise will reject without cleanup. Consider wrapping in try-catch or adding explicit error handling.

Also verify that the spread ...args on line 168 matches the expected return type from tRPC mutations (typically [data, variables, context] for React Query v5).


150-217: Consider extracting shared mutation hook pattern.

The three mutation hooks (useCreateTerminalPreset, useUpdateTerminalPreset, useDeleteTerminalPreset) follow an identical pattern: accept options, wrap with query invalidation on success. This violates DRY and makes future maintenance harder.

Consider creating a higher-order hook factory or a shared utility to reduce duplication:

function createPresetMutationHook(mutationKey: keyof typeof trpc.settings) {
  return (options?: any) => {
    const utils = trpc.useUtils();
    return trpc.settings[mutationKey].useMutation({
      ...options,
      onSuccess: async (...args) => {
        await utils.settings.getTerminalPresets.invalidate();
        await options?.onSuccess?.(...args);
      },
    });
  };
}

Alternatively, document why the pattern must be repeated.


341-352: Implementation checklist is thorough but missing items.

The checklist covers major milestones well. Consider adding:

  • Handle error responses from tRPC procedures (user-facing error messages)
  • Add loading/disabled states to UI during mutations
  • Verify import paths work across Electron IPC boundaries
  • Test concurrent mutations (e.g., user edits multiple presets rapidly)
  • Test with large preset lists (performance/pagination)
  • Document the max number of presets or characters allowed
  • Consider adding unique constraint on preset names (or document why duplicates are allowed)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 74a9d11 and a406211.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (15)
  • PRESETS_PLAN.md (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/CommandsEditor.tsx (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/index.ts (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/PresetRow.tsx (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/index.ts (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/index.ts (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/SettingsContent.tsx (2 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/SettingsSidebar/GeneralSettings.tsx (2 hunks)
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/index.tsx (4 hunks)
  • apps/desktop/src/renderer/stores/app-state.ts (1 hunks)
  • packages/ui/package.json (2 hunks)
  • packages/ui/src/components/command.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/index.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/index.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/PresetRow.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/index.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/CommandsEditor.tsx
🧰 Additional context used
📓 Path-based instructions (5)
apps/desktop/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)

For Electron interprocess communication, ALWAYS use tRPC as defined in src/lib/trpc

Files:

  • apps/desktop/src/renderer/stores/app-state.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/SettingsSidebar/GeneralSettings.tsx
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/SettingsContent.tsx
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/index.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts
apps/desktop/**/*.{ts,tsx}

📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)

apps/desktop/**/*.{ts,tsx}: Please use alias as defined in tsconfig.json when possible
Prefer zustand for state management if it makes sense. Do not use effect unless absolutely necessary

Files:

  • apps/desktop/src/renderer/stores/app-state.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/SettingsSidebar/GeneralSettings.tsx
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/SettingsContent.tsx
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/index.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Maintain type safety and avoid using any unless absolutely necessary in TypeScript code

Files:

  • apps/desktop/src/renderer/stores/app-state.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/SettingsSidebar/GeneralSettings.tsx
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx
  • packages/ui/src/components/command.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/SettingsContent.tsx
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/index.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts
apps/desktop/src/renderer/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Never import Node.js modules in renderer process or shared code - only in src/main/

Files:

  • apps/desktop/src/renderer/stores/app-state.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/SettingsSidebar/GeneralSettings.tsx
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/SettingsContent.tsx
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/index.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts
**/components/**/[A-Z]*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

Use one folder per component with structure ComponentName/ComponentName.tsx + index.ts barrel export

Files:

  • apps/desktop/src/renderer/screens/main/components/SettingsView/SettingsSidebar/GeneralSettings.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/SettingsContent.tsx
🧠 Learnings (12)
📓 Common learnings
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to apps/desktop/src/main/lib/terminal-*.ts : Use node-pty for terminal session management in the desktop app
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Add shadcn/ui components using npx shadcnlatest add <component> command run in packages/ui/ directory

Applied to files:

  • packages/ui/package.json
  • packages/ui/src/components/command.tsx
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to src/components/{ui,ai-elements,react-flow}/**/*.tsx : Use kebab-case single files for shadcn/ui components in src/components/ui/, src/components/ai-elements, and src/components/react-flow/

Applied to files:

  • packages/ui/package.json
  • packages/ui/src/components/command.tsx
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to **/components/**/[A-Z]*.tsx : Use one folder per component with structure ComponentName/ComponentName.tsx + index.ts barrel export

Applied to files:

  • packages/ui/package.json
  • packages/ui/src/components/command.tsx
📚 Learning: 2025-11-24T21:33:13.267Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: apps/desktop/AGENTS.md:0-0
Timestamp: 2025-11-24T21:33:13.267Z
Learning: Applies to apps/desktop/**/*.{ts,tsx} : Please use alias as defined in `tsconfig.json` when possible

Applied to files:

  • packages/ui/package.json
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to **/components/**/*.test.{ts,tsx} : Co-locate tests with components using the naming pattern ComponentName.test.tsx

Applied to files:

  • packages/ui/package.json
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to apps/desktop/src/lib/**/*.{ts,tsx} : Never import Node.js modules like node:fs, node:path, node:os in src/lib/electron-router-dom.ts or similar shared code

Applied to files:

  • packages/ui/package.json
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to apps/desktop/src/renderer/**/*.{ts,tsx} : Never import Node.js modules in renderer process or shared code - only in src/main/

Applied to files:

  • packages/ui/package.json
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to apps/desktop/src/main/lib/*{workspace,worktree}-*.ts : Use git worktree-based workspace management in the desktop app through workspace-manager.ts and worktree-manager.ts

Applied to files:

  • packages/ui/package.json
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to **/*.{ts,tsx} : Maintain type safety and avoid using `any` unless absolutely necessary in TypeScript code

Applied to files:

  • packages/ui/package.json
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Use React + TailwindCSS v4 + shadcn/ui for UI components

Applied to files:

  • packages/ui/package.json
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/index.tsx
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to apps/desktop/src/main/lib/terminal-*.ts : Use node-pty for terminal session management in the desktop app

Applied to files:

  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts
  • PRESETS_PLAN.md
🧬 Code graph analysis (3)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx (1)
packages/ui/src/components/command.tsx (6)
  • CommandDialog (143-143)
  • CommandInput (144-144)
  • CommandList (145-145)
  • CommandEmpty (146-146)
  • CommandGroup (147-147)
  • CommandItem (148-148)
packages/ui/src/components/command.tsx (2)
packages/ui/src/lib/utils.ts (1)
  • cn (4-6)
packages/ui/src/components/dialog.tsx (2)
  • Dialog (132-132)
  • DialogContent (134-134)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/index.tsx (2)
apps/desktop/src/renderer/stores/app-state.ts (1)
  • useOpenSettings (66-66)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx (1)
  • TabsCommandDialog (18-44)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (11)
packages/ui/package.json (1)

28-28: LGTM!

The new command export and cmdk dependency addition are correctly configured to support the command palette primitives.

Also applies to: 52-52

packages/ui/src/components/command.tsx (1)

1-151: LGTM!

This is a well-structured shadcn/ui style command palette implementation. All components correctly use forwardRef, set displayName, and follow consistent styling patterns with the cn utility.

apps/desktop/src/renderer/screens/main/components/SettingsView/SettingsContent.tsx (1)

4-4: LGTM!

The PresetsSettings integration follows the established pattern for other settings sections.

Also applies to: 19-19

apps/desktop/src/renderer/screens/main/components/SettingsView/SettingsSidebar/GeneralSettings.tsx (1)

2-6: LGTM!

The new Presets sidebar entry is correctly implemented and follows the established pattern for other settings sections.

Also applies to: 29-33

apps/desktop/src/renderer/stores/app-state.ts (1)

9-10: LGTM!

The addition of "presets" to the SettingsSection union type correctly enables the new presets settings section.

apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/index.tsx (1)

2-2: LGTM!

The TabsCommandDialog integration is well-implemented with proper state management, appropriate handlers that close the dialog after actions, and clean UI structure using ButtonGroup and motion components.

Also applies to: 6-6, 8-8, 11-11, 30-31, 42-52, 106-135

apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts (2)

1-21: LGTM!

The type definitions and column configuration are well-structured and provide good type safety for the presets UI.


23-28: LGTM!

The createEmptyPreset factory function correctly generates unique IDs for new preset instances.

PRESETS_PLAN.md (3)

29-53: Schema design is sound.

The TerminalPreset interface is minimal and complete (id, name, cwd, commands). The optional field on Settings maintains backwards compatibility. The instruction to keep defaultDatabase unchanged is correct.


221-249: The import path is correct and follows established patterns in the codebase.

The "main/lib/db/schemas" path is accessible from the renderer process via type-only imports. Multiple renderer files already import types from this location (ExternalApp, CheckItem), confirming this is a safe and established pattern. When implementing this refactoring, ensure TerminalPreset is added to apps/desktop/src/main/lib/db/schemas.ts before the renderer imports it.


106-132: Error handling in updateTerminalPreset follows the established codebase pattern.

Throwing new Error() for not-found cases is consistent across all tRPC procedures in this codebase (see workspaces.ts, projects.ts, and others). The error will automatically be converted to a typed TRPCError by tRPC's error formatter and safely propagated to the client. Using plain Error() for business logic validation is the established convention here; TRPCError is reserved for authentication concerns in middleware.

Likely an incorrect or invalid review comment.

Comment on lines +1 to +44
import {
CommandDialog,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
} from "@superset/ui/command";
import { HiMiniPlus, HiOutlineCog6Tooth } from "react-icons/hi2";

interface TabsCommandDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onAddTab: () => void;
onOpenPresetsSettings: () => void;
}

export function TabsCommandDialog({
open,
onOpenChange,
onAddTab,
onOpenPresetsSettings,
}: TabsCommandDialogProps) {
return (
<CommandDialog open={open} onOpenChange={onOpenChange}>
<CommandInput placeholder="Type a command or search..." />
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandGroup heading="Terminal">
<CommandItem onSelect={onAddTab}>
<HiMiniPlus className="size-4" />
New Terminal
</CommandItem>
</CommandGroup>
<CommandGroup heading="Presets">
<CommandItem onSelect={onOpenPresetsSettings}>
<HiOutlineCog6Tooth className="size-4" />
Configure Presets
</CommandItem>
</CommandGroup>
</CommandList>
</CommandDialog>
);
}

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

Restructure to follow component folder convention.

The component implementation is correct, but the file structure violates the coding guidelines. According to the guidelines, components should follow the pattern ComponentName/ComponentName.tsx with a separate index.ts barrel export.

Based on coding guidelines, the component folder structure should follow the established pattern.

Restructure the files as follows:

  1. Rename index.tsx to TabsCommandDialog.tsx:
// TabsCommandDialog/TabsCommandDialog.tsx
import {
	CommandDialog,
	CommandEmpty,
	CommandGroup,
	CommandInput,
	CommandItem,
	CommandList,
} from "@superset/ui/command";
import { HiMiniPlus, HiOutlineCog6Tooth } from "react-icons/hi2";

interface TabsCommandDialogProps {
	open: boolean;
	onOpenChange: (open: boolean) => void;
	onAddTab: () => void;
	onOpenPresetsSettings: () => void;
}

export function TabsCommandDialog({
	open,
	onOpenChange,
	onAddTab,
	onOpenPresetsSettings,
}: TabsCommandDialogProps) {
	return (
		<CommandDialog open={open} onOpenChange={onOpenChange}>
			<CommandInput placeholder="Type a command or search..." />
			<CommandList>
				<CommandEmpty>No results found.</CommandEmpty>
				<CommandGroup heading="Terminal">
					<CommandItem onSelect={onAddTab}>
						<HiMiniPlus className="size-4" />
						New Terminal
					</CommandItem>
				</CommandGroup>
				<CommandGroup heading="Presets">
					<CommandItem onSelect={onOpenPresetsSettings}>
						<HiOutlineCog6Tooth className="size-4" />
						Configure Presets
					</CommandItem>
				</CommandGroup>
			</CommandList>
		</CommandDialog>
	);
}
  1. Create a barrel export index.ts:
// TabsCommandDialog/index.ts
export { TabsCommandDialog } from "./TabsCommandDialog";
🤖 Prompt for AI Agents
In
apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx
(lines 1-44): the component file is incorrectly named and placed; rename
index.tsx to TabsCommandDialog/TabsCommandDialog.tsx containing the component
implementation, and add a new barrel export file TabsCommandDialog/index.ts that
re-exports TabsCommandDialog; update any imports across the codebase that
referenced the old path to use the new folder path (or keep importing from the
new folder index) so consumers continue to import from .../TabsCommandDialog.

Comment thread PRESETS_PLAN.md Outdated
Comment on lines +274 to +336
export function PresetsSettings() {
// Fetch presets from database
const { data: presets = [], isLoading } = trpc.settings.getTerminalPresets.useQuery();

// Mutation hooks
const createPreset = useCreateTerminalPreset();
const updatePreset = useUpdateTerminalPreset();
const deletePreset = useDeleteTerminalPreset();

const handleCellChange = (
rowIndex: number,
column: PresetColumnKey,
value: string,
) => {
const preset = presets[rowIndex];
if (!preset) return;

updatePreset.mutate({
id: preset.id,
patch: { [column]: value },
});
};

const handleCommandsChange = (rowIndex: number, commands: string[]) => {
const preset = presets[rowIndex];
if (!preset) return;

updatePreset.mutate({
id: preset.id,
patch: { commands },
});
};

const handleAddRow = () => {
createPreset.mutate({
name: "",
cwd: "",
commands: [""],
});
};

const handleDeleteRow = (rowIndex: number) => {
const preset = presets[rowIndex];
if (!preset) return;

deletePreset.mutate({ id: preset.id });
};

if (isLoading) {
return (
<div className="p-6 w-full max-w-6xl">
<div className="animate-pulse space-y-4">
<div className="h-8 bg-muted rounded w-1/3" />
<div className="h-32 bg-muted rounded" />
</div>
</div>
);
}

return (
// ... rest of JSX unchanged
);
}

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

Plan lacks error handling, feedback, and optimistic updates.

The PresetsSettings component plan is missing:

  1. Error handling: What happens if updatePreset.mutate() fails? Should toast/error message display?
  2. Mutation states: Are loading states shown while mutations are in-flight? Should buttons be disabled?
  3. Optimistic updates: Consider showing the new value immediately (via useOptimistic or React Query's onMutate) for better UX.
  4. Incomplete JSX: Line 334 says // ... rest of JSX unchanged — clarify what this includes (table, buttons, column layout, etc.).

These gaps could lead to a confusing UX if mutations fail or take time.

Do you want me to propose an enhanced component structure that includes error states, loading indicators, and optimistic updates?

🤖 Prompt for AI Agents
In PRESETS_PLAN.md around lines 274 to 336, the PresetsSettings plan omits
handling mutation errors, mutation loading states, optimistic updates, and the
detailed JSX structure; update the implementation to (1) handle errors from
create/update/delete by showing user feedback (toasts or inline error messages)
and logging the error, (2) reflect mutation loading states in the UI (disable
buttons/inputs and show spinners when a mutation is pending), (3) implement
optimistic updates for edits/add/delete using either React Query's
onMutate/onError/onSettled callbacks (or useOptimistic) to update the local
presets immediately and roll back on failure, and (4) replace the placeholder
comment with a clear JSX outline (table/list rendering presets, editable cells,
add/delete buttons, and loading/error UI) so reviewers know exact elements to
wire to the mutation handlers and states.

Comment thread PRESETS_PLAN.md Outdated
Comment on lines +283 to +313
const handleCellChange = (
rowIndex: number,
column: PresetColumnKey,
value: string,
) => {
const preset = presets[rowIndex];
if (!preset) return;

updatePreset.mutate({
id: preset.id,
patch: { [column]: value },
});
};

const handleCommandsChange = (rowIndex: number, commands: string[]) => {
const preset = presets[rowIndex];
if (!preset) return;

updatePreset.mutate({
id: preset.id,
patch: { commands },
});
};

const handleAddRow = () => {
createPreset.mutate({
name: "",
cwd: "",
commands: [""],
});
};

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

Add input validation and clarify preset creation logic.

The mutation handlers lack validation:

  1. Line 286-294 (handleCellChange): Verify that column is a valid PresetColumnKey that maps to a patchable field. The type system should enforce this, but document the contract.

  2. Line 308-312 (handleAddRow): Creates a preset with empty name, cwd, and commands: [""]. Should this:

    • Validate that name is non-empty before creating?
    • Focus the new row's name input automatically?
    • Show a placeholder to guide the user?

Consider adding client-side validation or document the UX flow for empty presets (are they saved but disabled until filled in?).

🤖 Prompt for AI Agents
In PRESETS_PLAN.md around lines 283 to 313, the handlers mutate presets without
input validation or clear UX for creating empty presets: ensure handleCellChange
first asserts that the provided column is one of the allowed PresetColumnKey
values (or map the column to a patchable field) and early-return or reject the
update if it is invalid; add a client-side validation step to sanitize/trim
value and prevent mutating when the value is empty or unchanged. For
handleCommandsChange apply the same validation for commands (ensure array
non-empty and entries are non-empty strings) before calling updatePreset.mutate.
For handleAddRow stop directly persisting an empty preset: either require a
non-empty name before calling createPreset.mutate or create the new row locally
(with a temporary UUID or draft flag) and focus its name input with a
placeholder, then only call createPreset.mutate once validation passes; document
the chosen UX (autofocus/placeholder or draft flow) and enforce validation in
the createPreset call.

- Add presets list to TabsCommandDialog for quick terminal creation
- Pass initialCommands/initialCwd through pane state to fix race condition
  where both TabsView and Terminal component called createOrAttach
- Add resolveCwd utility to handle relative paths against worktree
- Add combined usePresets hook for simplified preset access
- Terminal now reads initial data from pane state and clears after use

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/desktop/src/main/lib/terminal-manager.ts (1)

162-186: Extract magic number and note shell-specific behavior.

The initial command execution logic correctly gates on session recovery and waits for shell readiness. However, consider the following improvements:

  1. The 100ms delay is a magic number that should be extracted as a named constant for clarity and maintainability.
  2. The && operator for joining commands is shell-specific (works in bash/zsh/sh) and creates fail-fast behavior where subsequent commands won't run if an earlier one fails.

Apply this diff to extract the magic number:

+	private readonly INITIAL_COMMAND_DELAY_MS = 100;
+
 	async createOrAttach(params: {
		// Small delay ensures shell is fully ready to accept input
		setTimeout(() => {
			if (session.isAlive) {
				const cmdString = `${initialCommands.join(" && ")}\n`;
				session.pty.write(cmdString);
			}
-		}, 100);
+		}, this.INITIAL_COMMAND_DELAY_MS);
♻️ Duplicate comments (1)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx (1)

1-73: Restructure to follow component folder convention.

The component implementation is correct, but the file structure violates the coding guidelines. According to the guidelines, components should follow the pattern ComponentName/ComponentName.tsx with a separate index.ts barrel export.

Based on coding guidelines, the component folder structure should follow the established pattern. Rename index.tsx to TabsCommandDialog.tsx and create a separate index.ts barrel export.

🧹 Nitpick comments (4)
apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts (1)

36-38: Consider normalizing both path forms upfront.

The logic strips ./ from relative paths but handles it in the resolution phase. For clarity, consider normalizing at the input boundary.

 // Relative path - resolve against worktree
-// Handles both "apps/foo" and "./apps/foo"
-const relativePath = cwdOverride.startsWith("./")
-	? cwdOverride.slice(2)
-	: cwdOverride;
+// Normalize relative paths by removing leading "./"
+const relativePath = cwdOverride.replace(/^\.\//, "");
apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx (1)

11-23: Consider optimistic updates for better UX.

Cell changes trigger server mutations immediately, which could feel sluggish. Consider implementing optimistic updates to make the UI feel more responsive.

Update the useUpdateTerminalPreset hook to include optimistic cache updates:

// In useUpdateTerminalPreset.ts
onMutate: async (variables) => {
  await utils.settings.getTerminalPresets.cancel();
  const previous = utils.settings.getTerminalPresets.getData();
  
  utils.settings.getTerminalPresets.setData(undefined, (old) =>
    old?.map(p => p.id === variables.id ? { ...p, ...variables.patch } : p)
  );
  
  return { previous };
},
onError: (err, variables, context) => {
  if (context?.previous) {
    utils.settings.getTerminalPresets.setData(undefined, context.previous);
  }
},
apps/desktop/src/renderer/react-query/presets/usePresets.ts (1)

10-25: LGTM! Consider explicit return type for better type safety.

The hook properly aggregates presets data and mutations. The default empty array prevents undefined handling issues.

Optionally, add an explicit return type to improve IDE support and catch type regressions:

+import type { TerminalPreset } from "main/lib/db/schemas";
+
+interface UsePresetsReturn {
+	presets: TerminalPreset[];
+	isLoading: boolean;
+	createPreset: ReturnType<typeof useCreateTerminalPreset>;
+	updatePreset: ReturnType<typeof useUpdateTerminalPreset>;
+	deletePreset: ReturnType<typeof useDeleteTerminalPreset>;
+}
+
-export function usePresets() {
+export function usePresets(): UsePresetsReturn {
apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx (1)

9-9: Consider importing TerminalPreset from renderer-side types.

While the type-only import from main/lib/db/schemas is technically safe (TypeScript strips type imports at compile time), it's better to import from the renderer-side re-export in PresetsSettings/types.ts for clearer separation of concerns.

Apply this diff:

-import type { TerminalPreset } from "main/lib/db/schemas";
+import type { TerminalPreset } from "../../SettingsView/PresetsSettings/types";

Or create a shared types location if TerminalPreset is used across multiple renderer components.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a406211 and 1d685e6.

📒 Files selected for processing (20)
  • apps/desktop/src/lib/trpc/routers/settings/index.ts (1 hunks)
  • apps/desktop/src/lib/trpc/routers/terminal/terminal.ts (3 hunks)
  • apps/desktop/src/lib/trpc/routers/terminal/utils/index.ts (1 hunks)
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.test.ts (1 hunks)
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts (1 hunks)
  • apps/desktop/src/main/lib/db/schemas.ts (1 hunks)
  • apps/desktop/src/main/lib/terminal-manager.ts (4 hunks)
  • apps/desktop/src/renderer/react-query/presets/index.ts (1 hunks)
  • apps/desktop/src/renderer/react-query/presets/useCreateTerminalPreset.ts (1 hunks)
  • apps/desktop/src/renderer/react-query/presets/useDeleteTerminalPreset.ts (1 hunks)
  • apps/desktop/src/renderer/react-query/presets/usePresets.ts (1 hunks)
  • apps/desktop/src/renderer/react-query/presets/useUpdateTerminalPreset.ts (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx (3 hunks)
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/index.tsx (4 hunks)
  • apps/desktop/src/renderer/stores/tabs/store.ts (3 hunks)
  • apps/desktop/src/renderer/stores/tabs/types.ts (3 hunks)
  • apps/desktop/src/renderer/stores/tabs/utils.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
apps/desktop/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)

For Electron interprocess communication, ALWAYS use tRPC as defined in src/lib/trpc

Files:

  • apps/desktop/src/renderer/react-query/presets/useDeleteTerminalPreset.ts
  • apps/desktop/src/lib/trpc/routers/terminal/utils/index.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
  • apps/desktop/src/renderer/react-query/presets/useCreateTerminalPreset.ts
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts
  • apps/desktop/src/lib/trpc/routers/settings/index.ts
  • apps/desktop/src/main/lib/db/schemas.ts
  • apps/desktop/src/main/lib/terminal-manager.ts
  • apps/desktop/src/renderer/react-query/presets/useUpdateTerminalPreset.ts
  • apps/desktop/src/renderer/stores/tabs/store.ts
  • apps/desktop/src/renderer/react-query/presets/usePresets.ts
  • apps/desktop/src/renderer/stores/tabs/types.ts
  • apps/desktop/src/renderer/stores/tabs/utils.ts
  • apps/desktop/src/renderer/react-query/presets/index.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.test.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/index.tsx
  • apps/desktop/src/lib/trpc/routers/terminal/terminal.ts
apps/desktop/**/*.{ts,tsx}

📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)

apps/desktop/**/*.{ts,tsx}: Please use alias as defined in tsconfig.json when possible
Prefer zustand for state management if it makes sense. Do not use effect unless absolutely necessary

Files:

  • apps/desktop/src/renderer/react-query/presets/useDeleteTerminalPreset.ts
  • apps/desktop/src/lib/trpc/routers/terminal/utils/index.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
  • apps/desktop/src/renderer/react-query/presets/useCreateTerminalPreset.ts
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts
  • apps/desktop/src/lib/trpc/routers/settings/index.ts
  • apps/desktop/src/main/lib/db/schemas.ts
  • apps/desktop/src/main/lib/terminal-manager.ts
  • apps/desktop/src/renderer/react-query/presets/useUpdateTerminalPreset.ts
  • apps/desktop/src/renderer/stores/tabs/store.ts
  • apps/desktop/src/renderer/react-query/presets/usePresets.ts
  • apps/desktop/src/renderer/stores/tabs/types.ts
  • apps/desktop/src/renderer/stores/tabs/utils.ts
  • apps/desktop/src/renderer/react-query/presets/index.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.test.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/index.tsx
  • apps/desktop/src/lib/trpc/routers/terminal/terminal.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Maintain type safety and avoid using any unless absolutely necessary in TypeScript code

Files:

  • apps/desktop/src/renderer/react-query/presets/useDeleteTerminalPreset.ts
  • apps/desktop/src/lib/trpc/routers/terminal/utils/index.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
  • apps/desktop/src/renderer/react-query/presets/useCreateTerminalPreset.ts
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts
  • apps/desktop/src/lib/trpc/routers/settings/index.ts
  • apps/desktop/src/main/lib/db/schemas.ts
  • apps/desktop/src/main/lib/terminal-manager.ts
  • apps/desktop/src/renderer/react-query/presets/useUpdateTerminalPreset.ts
  • apps/desktop/src/renderer/stores/tabs/store.ts
  • apps/desktop/src/renderer/react-query/presets/usePresets.ts
  • apps/desktop/src/renderer/stores/tabs/types.ts
  • apps/desktop/src/renderer/stores/tabs/utils.ts
  • apps/desktop/src/renderer/react-query/presets/index.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.test.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/index.tsx
  • apps/desktop/src/lib/trpc/routers/terminal/terminal.ts
apps/desktop/src/renderer/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Never import Node.js modules in renderer process or shared code - only in src/main/

Files:

  • apps/desktop/src/renderer/react-query/presets/useDeleteTerminalPreset.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
  • apps/desktop/src/renderer/react-query/presets/useCreateTerminalPreset.ts
  • apps/desktop/src/renderer/react-query/presets/useUpdateTerminalPreset.ts
  • apps/desktop/src/renderer/stores/tabs/store.ts
  • apps/desktop/src/renderer/react-query/presets/usePresets.ts
  • apps/desktop/src/renderer/stores/tabs/types.ts
  • apps/desktop/src/renderer/stores/tabs/utils.ts
  • apps/desktop/src/renderer/react-query/presets/index.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/index.tsx
apps/desktop/src/lib/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Never import Node.js modules like node:fs, node:path, node:os in src/lib/electron-router-dom.ts or similar shared code

Files:

  • apps/desktop/src/lib/trpc/routers/terminal/utils/index.ts
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts
  • apps/desktop/src/lib/trpc/routers/settings/index.ts
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.test.ts
  • apps/desktop/src/lib/trpc/routers/terminal/terminal.ts
**/components/**/[A-Z]*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

Use one folder per component with structure ComponentName/ComponentName.tsx + index.ts barrel export

Files:

  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx
apps/desktop/src/main/lib/terminal-*.ts

📄 CodeRabbit inference engine (AGENTS.md)

Use node-pty for terminal session management in the desktop app

Files:

  • apps/desktop/src/main/lib/terminal-manager.ts
apps/desktop/**/*.test.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)

apps/desktop/**/*.test.{ts,tsx,js,jsx}: Tests should have one assert per test
Tests should be readable
Tests should be fast
Tests should be independent
Tests should be repeatable

Files:

  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.test.ts
🧠 Learnings (13)
📓 Common learnings
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to apps/desktop/src/main/lib/terminal-*.ts : Use node-pty for terminal session management in the desktop app
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to apps/desktop/src/main/lib/*{workspace,worktree}-*.ts : Use git worktree-based workspace management in the desktop app through workspace-manager.ts and worktree-manager.ts

Applied to files:

  • apps/desktop/src/lib/trpc/routers/terminal/utils/index.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts
  • apps/desktop/src/main/lib/db/schemas.ts
  • apps/desktop/src/main/lib/terminal-manager.ts
  • apps/desktop/src/renderer/stores/tabs/store.ts
  • apps/desktop/src/renderer/stores/tabs/types.ts
  • apps/desktop/src/renderer/stores/tabs/utils.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.test.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/index.tsx
  • apps/desktop/src/lib/trpc/routers/terminal/terminal.ts
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to apps/desktop/src/main/lib/terminal-*.ts : Use node-pty for terminal session management in the desktop app

Applied to files:

  • apps/desktop/src/lib/trpc/routers/terminal/utils/index.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
  • apps/desktop/src/renderer/react-query/presets/useCreateTerminalPreset.ts
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts
  • apps/desktop/src/lib/trpc/routers/settings/index.ts
  • apps/desktop/src/main/lib/db/schemas.ts
  • apps/desktop/src/main/lib/terminal-manager.ts
  • apps/desktop/src/renderer/stores/tabs/utils.ts
  • apps/desktop/src/renderer/react-query/presets/index.ts
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.test.ts
  • apps/desktop/src/lib/trpc/routers/terminal/terminal.ts
📚 Learning: 2025-11-24T21:33:13.267Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: apps/desktop/AGENTS.md:0-0
Timestamp: 2025-11-24T21:33:13.267Z
Learning: Applies to apps/desktop/**/*.{ts,tsx} : Please use alias as defined in `tsconfig.json` when possible

Applied to files:

  • apps/desktop/src/lib/trpc/routers/terminal/utils/index.ts
  • apps/desktop/src/renderer/react-query/presets/index.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to apps/desktop/src/lib/**/*.{ts,tsx} : Never import Node.js modules like node:fs, node:path, node:os in src/lib/electron-router-dom.ts or similar shared code

Applied to files:

  • apps/desktop/src/lib/trpc/routers/terminal/utils/index.ts
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to apps/desktop/src/main/index.ts : Load environment variables from monorepo root .env file in src/main/index.ts with override: true

Applied to files:

  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts
  • apps/desktop/src/lib/trpc/routers/terminal/terminal.ts
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to **/components/**/[A-Z]*.tsx : Use one folder per component with structure ComponentName/ComponentName.tsx + index.ts barrel export

Applied to files:

  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to src/components/{ui,ai-elements,react-flow}/**/*.tsx : Use kebab-case single files for shadcn/ui components in src/components/ui/, src/components/ai-elements, and src/components/react-flow/

Applied to files:

  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to **/components/**/*.test.{ts,tsx} : Co-locate tests with components using the naming pattern ComponentName.test.tsx

Applied to files:

  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx
📚 Learning: 2025-11-24T21:33:13.267Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: apps/desktop/AGENTS.md:0-0
Timestamp: 2025-11-24T21:33:13.267Z
Learning: Applies to apps/desktop/**/*.{ts,tsx} : Prefer zustand for state management if it makes sense. Do not use effect unless absolutely necessary

Applied to files:

  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx
📚 Learning: 2025-11-24T21:33:13.267Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: apps/desktop/AGENTS.md:0-0
Timestamp: 2025-11-24T21:33:13.267Z
Learning: Applies to apps/desktop/**/*.test.{ts,tsx,js,jsx} : Tests should be repeatable

Applied to files:

  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.test.ts
📚 Learning: 2025-11-24T21:33:13.267Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: apps/desktop/AGENTS.md:0-0
Timestamp: 2025-11-24T21:33:13.267Z
Learning: Applies to apps/desktop/**/*.test.{ts,tsx,js,jsx} : Tests should be independent

Applied to files:

  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.test.ts
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Use React + TailwindCSS v4 + shadcn/ui for UI components

Applied to files:

  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/index.tsx
🧬 Code graph analysis (13)
apps/desktop/src/renderer/react-query/presets/useDeleteTerminalPreset.ts (1)
apps/desktop/src/renderer/react-query/presets/index.ts (1)
  • useDeleteTerminalPreset (2-2)
apps/desktop/src/renderer/react-query/presets/useCreateTerminalPreset.ts (1)
apps/desktop/src/renderer/react-query/presets/index.ts (1)
  • useCreateTerminalPreset (1-1)
apps/desktop/src/lib/trpc/routers/settings/index.ts (1)
apps/desktop/src/lib/trpc/index.ts (1)
  • router (15-15)
apps/desktop/src/main/lib/db/schemas.ts (1)
apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts (1)
  • TerminalPreset (3-3)
apps/desktop/src/renderer/react-query/presets/useUpdateTerminalPreset.ts (1)
apps/desktop/src/renderer/react-query/presets/index.ts (1)
  • useUpdateTerminalPreset (4-4)
apps/desktop/src/renderer/stores/tabs/store.ts (1)
apps/desktop/src/renderer/stores/tabs/utils.ts (2)
  • CreatePaneOptions (38-41)
  • createTabWithPane (89-111)
apps/desktop/src/renderer/react-query/presets/usePresets.ts (1)
apps/desktop/src/renderer/react-query/presets/index.ts (4)
  • usePresets (3-3)
  • useCreateTerminalPreset (1-1)
  • useUpdateTerminalPreset (4-4)
  • useDeleteTerminalPreset (2-2)
apps/desktop/src/renderer/stores/tabs/utils.ts (1)
apps/desktop/src/renderer/stores/tabs/types.ts (2)
  • PaneType (6-6)
  • Pane (12-21)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx (1)
packages/ui/src/components/command.tsx (6)
  • CommandDialog (143-143)
  • CommandInput (144-144)
  • CommandList (145-145)
  • CommandEmpty (146-146)
  • CommandGroup (147-147)
  • CommandItem (148-148)
apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx (3)
apps/desktop/src/renderer/react-query/presets/usePresets.ts (1)
  • usePresets (10-25)
apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts (2)
  • PresetColumnKey (5-5)
  • PRESET_COLUMNS (14-18)
apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/PresetRow.tsx (1)
  • PresetRow (59-97)
apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts (1)
apps/desktop/src/main/lib/db/schemas.ts (1)
  • TerminalPreset (99-104)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/index.tsx (5)
apps/desktop/src/renderer/stores/app-state.ts (1)
  • useOpenSettings (66-66)
apps/desktop/src/renderer/react-query/presets/index.ts (1)
  • usePresets (3-3)
apps/desktop/src/renderer/react-query/presets/usePresets.ts (1)
  • usePresets (10-25)
apps/desktop/src/main/lib/db/schemas.ts (1)
  • TerminalPreset (99-104)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx (1)
  • TabsCommandDialog (25-73)
apps/desktop/src/lib/trpc/routers/terminal/terminal.ts (2)
apps/desktop/src/lib/trpc/routers/workspaces/utils/worktree.ts (1)
  • getWorktreePath (6-9)
apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts (1)
  • resolveCwd (13-48)
🔇 Additional comments (32)
apps/desktop/src/renderer/react-query/presets/useDeleteTerminalPreset.ts (1)

1-17: LGTM!

The hook correctly wraps the tRPC mutation and ensures cache consistency by invalidating the terminal presets query before calling user-provided callbacks.

apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts (1)

1-2: Node.js imports are appropriate here.

These Node.js module imports are safe in this context since tRPC routers execute in the main process where Node.js APIs are available. The coding guideline restriction applies to renderer-shared code like electron-router-dom.ts, not to server-side router utilities.

apps/desktop/src/lib/trpc/routers/terminal/utils/index.ts (1)

1-1: LGTM!

Standard barrel export for the utility module.

apps/desktop/src/main/lib/db/schemas.ts (2)

99-104: LGTM!

The TerminalPreset interface is well-structured with all required fields for the presets feature. The id field ensures stable React keys as noted in the PR objectives.


109-109: LGTM!

Correctly extends Settings with optional terminal presets array, maintaining backward compatibility.

apps/desktop/src/lib/trpc/routers/terminal/terminal.ts (2)

57-61: LGTM!

The cwd resolution logic correctly computes worktreePath and uses resolveCwd to handle both absolute and relative paths appropriately.


78-78: LGTM!

Properly passes initialCommands to TerminalManager, enabling preset command execution on terminal creation.

apps/desktop/src/lib/trpc/routers/settings/index.ts (4)

12-14: LGTM!

Returns an empty array as a safe default when terminal presets haven't been initialized yet.


16-38: LGTM!

The create mutation properly initializes the presets array if needed and uses nanoid for generating unique IDs. The probability of ID collision with nanoid is negligible for this use case.


40-67: LGTM!

Update logic correctly validates the preset exists and only updates provided fields, following a proper patch pattern.


69-80: LGTM!

Delete mutation safely filters out the target preset. Using filter is more robust than splice since it handles the case where the ID doesn't exist.

apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx (1)

7-118: LGTM!

The component follows best practices:

  • Uses React Query for server state management (appropriate for this use case)
  • Avoids unnecessary effects per coding guidelines
  • Properly handles loading and empty states
  • Follows the one-folder-per-component structure
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx (4)

29-31: LGTM!

Retrieves initial commands and cwd from the pane state, along with the clear function for cleanup.


52-57: LGTM!

Using refs to capture initial data prevents effect re-runs when these values change, which is the correct pattern here since initial data should only apply once.


249-250: LGTM!

Correctly passes the captured initial commands and cwd to the terminal creation mutation.


233-240: The initial data is safely captured before being cleared from store state.

Lines 234–235 capture initialCommands and initialCwd into local variables from refs before the store state is cleared at line 239. The mutation call at line 242 uses these locally captured values, so the initial data is guaranteed to be passed to createOrAttach even though the store has been cleared. This is intentional: initial commands run exactly once on first attachment, and clearing prevents re-running if the component re-renders during the mutation.

However, if the mutation fails (see onError at line 262), there is no recovery mechanism to retry with the initial data—the data is permanently lost from the store and cannot be restored. This may be acceptable for one-time setup commands, but it means failed terminal creation cannot automatically retry initial commands without user intervention.

apps/desktop/src/renderer/react-query/presets/useUpdateTerminalPreset.ts (1)

3-17: LGTM!

The mutation hook correctly invalidates the presets cache on success and chains any user-provided callbacks. This ensures the UI stays in sync with backend state.

apps/desktop/src/renderer/stores/tabs/store.ts (2)

83-118: LGTM!

The addTab method properly accepts and propagates CreatePaneOptions to the pane creation flow, enabling initial commands and cwd to be set when creating terminals from presets.


433-446: LGTM!

The clearPaneInitialData method correctly resets initial commands and cwd while preserving other pane properties, following the established pattern for pane mutations in the store.

apps/desktop/src/renderer/react-query/presets/useCreateTerminalPreset.ts (1)

3-17: LGTM!

The create mutation hook follows the same pattern as the update hook, properly invalidating the cache and chaining user callbacks.

apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.test.ts (1)

1-78: LGTM! Comprehensive test coverage.

The tests follow best practices with clear names, one assertion per test, proper setup/teardown, and comprehensive coverage of edge cases including undefined values, absolute/relative paths, and path existence checks.

As per coding guidelines, the tests are readable, independent, and repeatable with real filesystem usage for accurate behavior verification.

apps/desktop/src/renderer/stores/tabs/types.ts (3)

19-20: LGTM!

The optional initialCommands and initialCwd fields properly support the terminal presets feature by carrying preset configuration through the pane lifecycle.


46-62: LGTM!

The AddTabOptions interface and updated addTab signature provide a clean API for creating tabs with preset configuration, maintaining type safety throughout the flow.


80-80: LGTM!

The clearPaneInitialData method signature aligns with the implementation and provides a clean way to reset initial data after it's been consumed.

apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/index.tsx (2)

59-74: Clarify cwd handling logic.

The preset selection logic correctly passes initialCommands and renames the tab. However, line 65 uses preset.cwd || undefined which converts empty strings to undefined.

Based on the TerminalPreset schema (cwd: string), this logic will convert empty strings to undefined. Is this intentional to handle empty cwd values, or should empty strings be preserved? If empty cwd should fall back to default behavior, this is correct. Otherwise, consider:

-		const { tabId } = addTab(activeWorkspaceId, {
-			initialCommands: preset.commands,
-			initialCwd: preset.cwd || undefined,
-		});
+		const { tabId } = addTab(activeWorkspaceId, {
+			initialCommands: preset.commands,
+			initialCwd: preset.cwd || undefined,  // Falls back to default cwd if empty
+		});

If the empty string conversion is intentional, consider adding a comment explaining this behavior.


128-159: LGTM! Clean integration of presets UI.

The ButtonGroup and TabsCommandDialog integration provides a polished UX for accessing terminal presets, with proper state management and callback wiring.

apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts (1)

1-18: LGTM!

The type definitions and column configuration are clean and well-structured. The use of Exclude<keyof TerminalPreset, "id"> properly ensures type safety for column keys.

apps/desktop/src/renderer/react-query/presets/index.ts (1)

1-4: LGTM!

Clean barrel export following standard patterns. This centralizes the preset hooks for convenient importing across the UI.

apps/desktop/src/renderer/stores/tabs/utils.ts (3)

35-41: LGTM!

The CreatePaneOptions interface is clean and properly typed with optional fields that align with the preset feature requirements.


46-62: LGTM!

The createPane function correctly accepts and applies the options to the returned Pane object. The optional spreading of initialCommands and initialCwd is properly implemented.


89-111: LGTM!

The createTabWithPane function properly forwards the options parameter to createPane, maintaining the flow for preset initialization.

apps/desktop/src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/TabsCommandDialog/index.tsx (1)

44-63: LGTM!

The preset rendering logic is well-implemented:

  • Proper use of preset.id as key for stable React rendering
  • Good fallback for missing preset name
  • Appropriate conditional rendering of cwd
  • Clean UI layout with icons and truncation

Add pendingSessions map to deduplicate concurrent createOrAttach calls
for the same tabId. When React Strict Mode double-runs effects, the
second call now returns the same promise as the first instead of
creating a duplicate session.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Move clearPaneInitialData to onSuccess callback (cleaner timing)
- Remove comments that describe "what" rather than "why"
- Consolidate event queueing logic

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx (1)

282-282: Verify if terminalTheme should be in the main effect's dependency array.

Including terminalTheme in the dependency array causes the entire terminal setup effect (lines 126-282) to re-run when the theme changes, which will detach and recreate the terminal session. This seems unintentional since there's already a separate effect (lines 284-288) that handles theme changes without recreating the terminal.

Consider removing terminalTheme from this dependency array:

-	}, [paneId, workspaceId, workspaceCwd, paneName, terminalTheme]);
+	}, [paneId, workspaceId, workspaceCwd, paneName]);
🧹 Nitpick comments (2)
apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx (2)

59-62: Consider a more robust array comparison for commands.

JSON.stringify comparison works for simple string arrays but is sensitive to element order and could be slow for large arrays. Since commands are simple string arrays and order matters, this is acceptable for the current use case.

If you want a slightly cleaner comparison:

const arraysEqual = (a: string[], b: string[]) =>
  a.length === b.length && a.every((v, i) => v === b[i]);

// Usage:
if (arraysEqual(preset.commands, serverPreset.commands)) return;

70-76: Consider focusing the new preset row after creation.

When adding a new preset, it might improve UX to automatically focus the first input field of the newly created row. Currently the row is added but the user must manually click to start editing.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1d685e6 and 405233d.

📒 Files selected for processing (9)
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.test.ts (1 hunks)
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts (1 hunks)
  • apps/desktop/src/main/lib/terminal-manager.ts (6 hunks)
  • apps/desktop/src/renderer/react-query/presets/index.ts (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/CommandsEditor.tsx (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/PresetRow.tsx (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts (1 hunks)
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/CommandsEditor/CommandsEditor.tsx
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.test.ts
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetRow/PresetRow.tsx
  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/types.ts
🧰 Additional context used
📓 Path-based instructions (7)
apps/desktop/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)

For Electron interprocess communication, ALWAYS use tRPC as defined in src/lib/trpc

Files:

  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx
  • apps/desktop/src/main/lib/terminal-manager.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts
  • apps/desktop/src/renderer/react-query/presets/index.ts
apps/desktop/**/*.{ts,tsx}

📄 CodeRabbit inference engine (apps/desktop/AGENTS.md)

apps/desktop/**/*.{ts,tsx}: Please use alias as defined in tsconfig.json when possible
Prefer zustand for state management if it makes sense. Do not use effect unless absolutely necessary

Files:

  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx
  • apps/desktop/src/main/lib/terminal-manager.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts
  • apps/desktop/src/renderer/react-query/presets/index.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Maintain type safety and avoid using any unless absolutely necessary in TypeScript code

Files:

  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx
  • apps/desktop/src/main/lib/terminal-manager.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts
  • apps/desktop/src/renderer/react-query/presets/index.ts
**/components/**/[A-Z]*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

Use one folder per component with structure ComponentName/ComponentName.tsx + index.ts barrel export

Files:

  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
apps/desktop/src/renderer/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Never import Node.js modules in renderer process or shared code - only in src/main/

Files:

  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
  • apps/desktop/src/renderer/react-query/presets/index.ts
apps/desktop/src/main/lib/terminal-*.ts

📄 CodeRabbit inference engine (AGENTS.md)

Use node-pty for terminal session management in the desktop app

Files:

  • apps/desktop/src/main/lib/terminal-manager.ts
apps/desktop/src/lib/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Never import Node.js modules like node:fs, node:path, node:os in src/lib/electron-router-dom.ts or similar shared code

Files:

  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts
🧠 Learnings (4)
📚 Learning: 2025-11-24T21:33:13.267Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: apps/desktop/AGENTS.md:0-0
Timestamp: 2025-11-24T21:33:13.267Z
Learning: Applies to apps/desktop/**/*.{ts,tsx} : Prefer zustand for state management if it makes sense. Do not use effect unless absolutely necessary

Applied to files:

  • apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to apps/desktop/src/main/lib/terminal-*.ts : Use node-pty for terminal session management in the desktop app

Applied to files:

  • apps/desktop/src/main/lib/terminal-manager.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts
  • apps/desktop/src/renderer/react-query/presets/index.ts
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to apps/desktop/src/main/lib/*{workspace,worktree}-*.ts : Use git worktree-based workspace management in the desktop app through workspace-manager.ts and worktree-manager.ts

Applied to files:

  • apps/desktop/src/main/lib/terminal-manager.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts
📚 Learning: 2025-12-08T23:32:32.232Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-12-08T23:32:32.232Z
Learning: Applies to apps/desktop/src/main/index.ts : Load environment variables from monorepo root .env file in src/main/index.ts with override: true

Applied to files:

  • apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts
🔇 Additional comments (12)
apps/desktop/src/lib/trpc/routers/terminal/utils/resolve-cwd.ts (1)

1-54: Well-structured path resolution with comprehensive validation.

The implementation correctly handles all edge cases: absolute paths, relative paths, missing paths, and provides safe fallbacks. The previous review concern about unvalidated paths has been properly addressed with existsSync checks throughout.

One note: This file uses Node.js modules (node:fs, node:os, node:path), which is acceptable since it's under src/lib/trpc/routers/ (server-side tRPC router code), not in renderer or shared electron-router-dom code.

apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx (3)

28-30: Clean integration of initial commands and cwd from pane state.

The new properties are correctly extracted from the pane and properly wired to refs to avoid stale closures in the effect callbacks.


49-54: Good use of refs to capture current values without triggering effect re-runs.

This pattern correctly avoids re-running the main terminal setup effect when these values change, while still ensuring the latest values are used when the callbacks execute.


211-229: Correct handling of initial commands and cleanup.

The logic properly:

  1. Captures initial values at effect start
  2. Passes them to createOrAttach
  3. Clears them after successful creation to prevent re-execution on reattach
apps/desktop/src/main/lib/terminal-manager.ts (4)

40-43: Good deduplication mechanism for concurrent session creation.

The pendingSessions map effectively prevents race conditions from React Strict Mode's double-mounting or rapid re-renders, ensuring only one terminal session is created per tabId.


74-78: Correct early return for pending sessions.

Returning the existing promise ensures all concurrent callers receive the same result without creating duplicate sessions.


108-112: Proper cleanup in finally block.

Using finally ensures pendingSessions is cleaned up even if doCreateSession throws, preventing memory leaks and stale entries.


220-244: Initial commands execution looks correct, with one minor note.

The logic properly:

  1. Only runs commands for new sessions (not recovered)
  2. Guards against re-execution via commandsSent flag
  3. Checks session.isAlive before writing

The 100ms delay is a reasonable heuristic for shell readiness. Note that initialCommands is captured in the outer scope and is guaranteed non-empty due to shouldRunCommands check, so the access in the setTimeout callback is safe.

apps/desktop/src/renderer/screens/main/components/SettingsView/PresetsSettings/PresetsSettings.tsx (2)

20-25: Potential initial state mismatch.

The initial value of useState(serverPresets) is only evaluated once on mount. If serverPresets is initially an empty array (while isLoading is true) and then populates, the useEffect will sync it. However, this creates a brief moment where localPresets could be out of sync.

This works correctly because:

  1. The loading state (lines 85-94) renders before showing presets
  2. Once isLoading becomes false, serverPresets will have data and the effect will sync

The pattern is acceptable here.


96-155: Well-structured component with proper separation of concerns.

The component correctly:

  • Uses stable keys (preset.id) for list rendering
  • Separates loading/empty states
  • Delegates row rendering to PresetRow
  • Provides comprehensive handlers for CRUD operations
apps/desktop/src/renderer/react-query/presets/index.ts (2)

3-17: Clean mutation hook with proper cache invalidation.

The pattern correctly:

  1. Spreads caller options to preserve customization
  2. Invalidates cache before calling caller's onSuccess
  3. Uses await to ensure sequential execution

55-70: Well-designed composite hook.

The usePresets hook provides a clean, unified API for preset management. Returning the full mutation objects allows callers to access isPending, isError, etc. for UI feedback.

One consideration: the internal hooks are called unconditionally on every render of components using usePresets, which is fine for tRPC mutations but worth noting.

@Kitenite
Kitenite merged commit 5f89c95 into main Dec 9, 2025
8 checks passed

This branch was successfully deployed

1 active deployment
Preview — 308309a3 Deployed Dec 9, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant