Skip to content

crimson wind 37#151

Closed
Kitenite wants to merge 1 commit intomainfrom
crimson-wind-37
Closed

crimson wind 37#151
Kitenite wants to merge 1 commit intomainfrom
crimson-wind-37

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Nov 26, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Increased terminal scrollback capacity to preserve more historical output
    • Removed "Recovered session history" banner from terminal display
  • Refactor

    • Simplified terminal history storage mechanism
    • Enhanced tab rendering and active state management

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 26, 2025

Walkthrough

The PR simplifies terminal history handling by removing metadata streaming and I/O logic, updates scrollback truncation limits, removes recovered session display headers, and substantially refactors tab rendering to track active tab state while pre-rendering all workspace tabs with conditional visibility.

Changes

Cohort / File(s) Change Summary
Terminal History Simplification
apps/desktop/src/main/lib/terminal-history.ts
Removed metadata handling, streaming I/O, and file-size tracking. Simplified file reading to full-content load. Updated HistoryWriter constructor to accept only workspaceId and tabId. Changed finalize() signature to return Promise<void> instead of accepting exitCode. Removed public exports: getMetadataPath() function and SessionMetadata interface. Updated HistoryReader.getLatestSession return shape to omit metadata field.
Terminal Manager Scrollback
apps/desktop/src/main/lib/terminal-manager.ts
Added private constant MAX_SCROLLBACK_CHARS (100000). Updated scrollback truncation logic to use new class-level constant instead of inline value.
Terminal Recovered Session
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
Removed "[Recovered session history]" header banner from initial scrollback display for recovered sessions.
Tab Rendering Refactor
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/index.tsx
Added activeTabId property to RenderTabContentProps interface. Refactored renderTabContent to compute visibility and content based on active state, returning a styled wrapper div instead of direct component. Replaced renderTabs function with unified allTabs pre-rendering approach. Changed tab computation to build allTabs from all top-level tabs and compute tabToRender based on active workspace and tab IDs. Updated all render paths to map over allTabs with active tab propagation.
Colors Formatting
apps/desktop/src/lib/trpc/routers/projects/utils/colors/colors.ts
Minor formatting: wrapped multi-line return expression without logic changes.

Sequence Diagram(s)

sequenceDiagram
    participant OldRenderer as Old: TabsContent
    participant NewRenderer as New: TabsContent
    participant TabComponent as Tab Component

    rect rgb(100, 150, 200)
    Note over OldRenderer: Old Flow: Per-Workspace Rendering
    OldRenderer->>OldRenderer: Get active workspace
    OldRenderer->>OldRenderer: Filter tabs for workspace
    OldRenderer->>TabComponent: Render only active workspace tabs
    end

    rect rgb(150, 200, 150)
    Note over NewRenderer: New Flow: All Tabs Pre-Rendered
    NewRenderer->>NewRenderer: Build allTabs (all top-level)
    NewRenderer->>NewRenderer: Compute activeTabId
    loop For each tab in allTabs
        NewRenderer->>NewRenderer: Compute isActive
        NewRenderer->>NewRenderer: Set visibility style
        NewRenderer->>TabComponent: Render with visibility control
        TabComponent->>TabComponent: Hidden if not active
    end
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • terminal-history.ts requires careful verification of all callers updated to handle removed exports (getMetadataPath, SessionMetadata) and new constructor/finalize signatures
  • TabsContent/index.tsx refactor involves significant rendering logic changes; verify pre-rendering of all tabs doesn't impact performance and activeTabId propagation works across nested components
  • Public API removals (getMetadataPath, SessionMetadata) need confirmation that no external code depends on these exports

Possibly related PRs

  • xterm ui #115: Both PRs modify terminal subsystem components including terminal-history, Terminal.tsx, and terminal-manager.ts with overlapping code changes
  • persist process history #120: Both PRs make direct changes to terminal-history implementation, modifying the same HistoryWriter/HistoryReader classes and exported function signatures
  • keep terminal tabs rendered #147: Both PRs modify TabsContent/index.tsx rendering logic and terminal-manager.ts, affecting tab visibility and scrollback handling

Poem

🐰 Through history streams now simplified flows,
Tab rendering dances where activeTabId glows,
Metadata melts, headers fade away,
Scrollback limits rise—a cleaner display! ✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description lists related issues but lacks structured content following the template (missing sections for Type of Change, Testing, and detailed Description). Expand the description to include all template sections: provide a clear description of changes, specify the type of change, document testing steps, and add any additional context.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'crimson wind 37' is vague and does not convey meaningful information about the changeset; it appears to be a branch name rather than a descriptive PR title. Replace with a descriptive title summarizing the main change, such as 'Render all tabs and simplify terminal history handling'.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch crimson-wind-37

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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 (2)
apps/desktop/src/main/lib/terminal-history.ts (2)

98-117: I need to correct my previous analysis. The second batch of shell results clearly shows the issue that the review comment identified:

The review comment is CORRECT - there IS a critical signature mismatch.

Evidence:

  • Line 393 in terminal-manager.ts: await writer.finalize(params.exitCode); - passes an argument
  • Line 98 in terminal-history.ts: async finalize(): Promise<void> - takes NO parameters
  • Line 291 in terminal-history.test.ts: await writer.finalize(0); - also incorrectly passes an argument

The finalize() method signature was changed to accept no parameters, but call sites at line 393 (terminal-manager.ts) and line 291 (terminal-history.test.ts) still pass exitCode/0 as arguments.

Both locations must be fixed:

  1. apps/desktop/src/main/lib/terminal-manager.ts line 393: Remove the params.exitCode argument
  2. apps/desktop/src/main/lib/terminal-history.test.ts line 291: Remove the 0 argument
-await writer.finalize(params.exitCode);
+await writer.finalize();

and

-await writer.finalize(0);
+await writer.finalize();

This would be caught by bun run typecheck as a TypeScript error.


48-52: Based on my verification:

Constructor signature mismatch confirmed - call site in terminal-manager.ts passes 5 arguments to constructor accepting only 2 parameters.

The evidence is clear:

  • Constructor (terminal-history.ts lines 48-51): Accepts workspaceId and tabId only
  • Call site (terminal-manager.ts lines 105-111): Passes workspaceId, tabId, workingDir, terminalCols, terminalRows
  • Test files: All use the correct 2-parameter signature, confirming the constructor is correct

The three extra arguments (workingDir, terminalCols, terminalRows) at lines 108-110 have no corresponding constructor parameters and will cause a TypeScript compilation error.

🧹 Nitpick comments (2)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/index.tsx (1)

91-100: Consider removing redundant wrapper divs.

The <div key={tab.id}> wrapper around each renderTabContent call appears unnecessary since renderTabContent already returns a keyed element. You can simplify to:

-{allTabs.map((tab) => {
-  return (
-    <div key={tab.id}>
-      {renderTabContent({
-        tab,
-        activeTabId: null,
-        isDropZone: false,
-      })}
-    </div>
-  );
-})}
+{allTabs.map((tab) =>
+  renderTabContent({
+    tab,
+    activeTabId: null,
+    isDropZone: false,
+  })
+)}

Apply the same pattern on lines 113-122.

Also applies to: 113-122

apps/desktop/src/main/lib/terminal-history.ts (1)

155-180: Consider memory implications for large history files.

The refactored implementation loads the entire history file into memory, which simplifies the code but could be memory-intensive for long-running terminal sessions with high output. Given the MAX_SCROLLBACK_CHARS limit of 100k characters in terminal-manager.ts, a typical history file should remain manageable, but very long sessions could accumulate large files.

Consider adding a file size check or streaming approach if memory usage becomes a concern with production usage patterns.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ffd7da6 and e9788d5.

📒 Files selected for processing (5)
  • apps/desktop/src/lib/trpc/routers/projects/utils/colors/colors.ts (1 hunks)
  • apps/desktop/src/main/lib/terminal-history.ts (4 hunks)
  • apps/desktop/src/main/lib/terminal-manager.ts (4 hunks)
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx (0 hunks)
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/index.tsx (2 hunks)
💤 Files with no reviewable changes (1)
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/Terminal/Terminal.tsx
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{ts,tsx,js,jsx,json}

📄 CodeRabbit inference engine (AGENTS.md)

Apply Biome formatting, linting, and import organization at the root level for all code files

Files:

  • apps/desktop/src/lib/trpc/routers/projects/utils/colors/colors.ts
  • apps/desktop/src/main/lib/terminal-manager.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/index.tsx
  • apps/desktop/src/main/lib/terminal-history.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Avoid using any type; use type-safe approaches instead, unless necessary
Ensure TypeScript type checking passes across all packages using bun run typecheck

Files:

  • apps/desktop/src/lib/trpc/routers/projects/utils/colors/colors.ts
  • apps/desktop/src/main/lib/terminal-manager.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/index.tsx
  • apps/desktop/src/main/lib/terminal-history.ts
apps/**/*.{tsx,ts}

📄 CodeRabbit inference engine (AGENTS.md)

apps/**/*.{tsx,ts}: Structure React applications with one folder per component following the pattern: ComponentName/ComponentName.tsx with index.ts barrel export
Co-locate component dependencies (hooks, utils, constants, tests, stories) next to the file using them

Files:

  • apps/desktop/src/lib/trpc/routers/projects/utils/colors/colors.ts
  • apps/desktop/src/main/lib/terminal-manager.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/index.tsx
  • apps/desktop/src/main/lib/terminal-history.ts
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/lib/trpc/routers/projects/utils/colors/colors.ts
  • apps/desktop/src/main/lib/terminal-manager.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/index.tsx
  • apps/desktop/src/main/lib/terminal-history.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/lib/trpc/routers/projects/utils/colors/colors.ts
  • apps/desktop/src/main/lib/terminal-manager.ts
  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/index.tsx
  • apps/desktop/src/main/lib/terminal-history.ts
apps/**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

Use one component per file; do not create multi-component files

Files:

  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/index.tsx
apps/desktop/src/renderer/**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

Define keyboard shortcuts using the centralized system in apps/desktop/src/renderer/lib/shortcuts.ts with Arc Browser-inspired shortcut definitions

Files:

  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/index.tsx
🧠 Learnings (1)
📚 Learning: 2025-11-24T21:32:46.559Z
Learnt from: CR
Repo: superset-sh/superset PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-24T21:32:46.559Z
Learning: Applies to apps/desktop/src/main/lib/*-ipcs.ts : Implement Electron IPC handlers in dedicated files under apps/desktop/src/main/lib/ (e.g., workspace-ipcs.ts, terminal-ipcs.ts)

Applied to files:

  • apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/index.tsx
  • apps/desktop/src/main/lib/terminal-history.ts
🧬 Code graph analysis (2)
apps/desktop/src/lib/trpc/routers/projects/utils/colors/colors.ts (1)
apps/desktop/src/shared/constants/project-colors.ts (1)
  • PROJECT_COLOR_VALUES (12-12)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/index.tsx (7)
apps/desktop/src/shared/types.ts (1)
  • TabType (23-30)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/SetupTabView.tsx (1)
  • SetupTabView (8-20)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/SingleTabView.tsx (1)
  • SingleTabView (16-49)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/GroupTabView/index.tsx (1)
  • GroupTabView (47-149)
apps/desktop/src/renderer/stores/tabs/hooks.ts (2)
  • useTabs (3-3)
  • useActiveTabIds (4-5)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/useTabContentDrop.ts (1)
  • useTabContentDrop (6-36)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/EmptyTabView.tsx (1)
  • EmptyTabView (1-18)
⏰ 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 (6)
apps/desktop/src/lib/trpc/routers/projects/utils/colors/colors.ts (1)

4-6: Formatting-only change; logic remains correct—just confirm non-empty color list

The multi-line formatting for the random index is fine and keeps the same behavior as before. The function correctly picks a uniform random color as long as PROJECT_COLOR_VALUES.length > 0. If there is any chance the list could be empty (e.g., configurable colors), consider asserting or guarding against that; otherwise this is good as-is.

apps/desktop/src/main/lib/terminal-manager.ts (2)

41-41: Scrollback limit doubled from 50k to 100k characters.

The increase provides more history but doubles memory usage per terminal session. Ensure this has been tested with multiple concurrent terminals to verify acceptable memory consumption.


317-330: LGTM!

The scrollback truncation correctly uses the new class constant and maintains the most recent characters by slicing from the end.

apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/index.tsx (2)

55-81: LGTM!

The memoization logic correctly computes all top-level tabs and determines the tab to render based on active workspace and tab IDs. All code paths properly return both tabToRender and allTabs.


18-47: All tabs remain mounted and active regardless of visibility; verify this performance model is acceptable for your typical use case.

The refactor changes from conditional rendering to always-render-with-CSS-visibility. Verification confirms this is intentional (Terminal.tsx line 190: "Keep PTY running for reattachment"), but the architecture has real resource implications:

  • Confirmed: All tabs render simultaneously; Terminal components never unmount when inactive
  • Confirmed: All PTY subscriptions remain enabled regardless of visibility
  • Confirmed: PTY processes continue running for hidden tabs (cleanup only on full unmount)
  • Trade-off: Instant switching + preserved state vs. constant resource consumption

No performance tests exist to validate this model. Ensure acceptable resource usage with your typical tab counts, especially with multiple simultaneous terminals. Consider adding performance monitoring or lazy detach mechanisms if users report degradation with many tabs.

apps/desktop/src/main/lib/terminal-history.ts (1)

119-121: LGTM!

The isOpen() implementation correctly checks if the write stream is still active.

@Kitenite Kitenite closed this Nov 26, 2025
@Kitenite Kitenite deleted the crimson-wind-37 branch November 26, 2025 22:53
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