Skip to content

refactor: pass git diff root path over IPC#32

Merged
Cheezeiii365 merged 4 commits into
mainfrom
codex/refactor-git_diff_original-to-use-rootpath
Mar 28, 2026
Merged

refactor: pass git diff root path over IPC#32
Cheezeiii365 merged 4 commits into
mainfrom
codex/refactor-git_diff_original-to-use-rootpath

Conversation

@Cheezeiii365
Copy link
Copy Markdown
Owner

@Cheezeiii365 Cheezeiii365 commented Mar 28, 2026

Motivation

  • Fix GitHub issue refactor: pass rootPath as IPC argument to GIT_DIFF_ORIGINAL handler #25 by removing module-level git diff root state and passing the workspace root explicitly over the IPC boundary to make git original lookups deterministic and avoid hidden main-process state.
  • Ensure the renderer can request HEAD/original file contents for any workspace by providing the workspace root where needed.

Description

  • Removed currentRoot and setDiffRoot() from packages/main/src/gitDiff.ts and changed the GIT_DIFF_ORIGINAL IPC handler to accept (rootPath, filePath) and use that to compute the original content.
  • Updated the preload API and shared WindowApi signature so getGitFileOriginal now accepts (rootPath: string | null, filePath: string) and forwards both args via IPC. (files: packages/main/src/preload.ts, packages/shared/src/index.ts).
  • Threaded the workspace root into the renderer: toggleInlineDiff now takes rootPath, EditorPane panel params include workspaceRoot and pass it to inline-diff calls, and AppShell injects workspaceRoot when creating editor panels. (files: packages/renderer/src/lib/editorInlineDiff.ts, packages/renderer/src/components/panes/EditorPane.tsx, packages/renderer/src/components/AppShell.tsx).
  • Removed the setDiffRoot() call from workspace activation in packages/main/src/index.ts and adjusted imports accordingly.
  • Committed with prefix refactor: pass git diff root path over IPC.

Testing

  • Ran pnpm typecheck which failed due to existing, unrelated TypeScript errors in packages/renderer/src/hooks/useSettings.ts, so type-checking did not fully pass (failure is unrelated to this change).
  • No other automated tests were executed as part of this change set.

Codex Task

Summary by CodeRabbit

  • Refactor

    • Editor panels now carry workspace root info when opening files, so views have workspace context.
    • Inline-diff actions now pass workspace context when requesting original file content.
  • Bug Fix

    • Inline diffs correctly show or hide based on the active workspace/root, reducing incorrect diff results when switching workspaces.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 28, 2026

Warning

Rate limit exceeded

@Cheezeiii365 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 1 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 5 minutes and 1 seconds.

⌛ 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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a9e771e7-4c65-4330-ae00-8fc3657db0a1

📥 Commits

Reviewing files that changed from the base of the PR and between 888e7b5 and 5ad0b8f.

📒 Files selected for processing (1)
  • packages/renderer/src/components/AppShell.tsx
📝 Walkthrough

Walkthrough

This PR removes module-level git-diff root state and threads rootPath explicitly from renderer → preload → main IPC handler, updating signatures and call sites to pass the root path when requesting a file's original (HEAD) content.

Changes

Cohort / File(s) Summary
Core Git Diff IPC Layer
packages/main/src/gitDiff.ts, packages/main/src/index.ts
Removed module-level currentRoot and exported setDiffRoot. IpcChannels.GIT_DIFF_ORIGINAL handler now accepts `rootPath: string

|IPC Preload Bridge & Shared Types
packages/main/src/preload.ts, packages/shared/src/index.ts|api.getGitFileOriginal signature updated to (rootPath: string | null, filePath: string). preload now invokes IPC with (rootPath, filePath). WindowApi type updated accordingly.|

|Renderer - Editor Integration
packages/renderer/src/components/AppShell.tsx, packages/renderer/src/components/panes/EditorPane.tsx, packages/renderer/src/lib/defaultCommands.ts|Editor panel creation now includes workspaceRoot in panel params. AppShell passes workspaceRoot when opening files; EditorPane adds workspaceRoot?: string | null param and uses it when resolving diff root for inline-diff toggles.|

|Inline Diff Implementation
packages/renderer/src/lib/editorInlineDiff.ts|toggleInlineDiff signature changed to accept rootPath: string | null and forwards it to window.api.getGitFileOriginal(rootPath, filePath). All toggle call sites updated to pass rootPath.|

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Renderer
participant Preload
participant Main
participant GitRepo as Git/FS
Renderer->>Preload: api.getGitFileOriginal(rootPath, filePath)
Preload->>Main: ipcRenderer.invoke(GIT_DIFF_ORIGINAL, rootPath, filePath)
Main->>GitRepo: read HEAD content using rootPath + filePath
GitRepo-->>Main: content | null
Main-->>Preload: { content }
Preload-->>Renderer: Promise resolves { content }

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Poem

🐰 I hopped from pane to IPC line,
No hidden root, parameters shine.
From renderer to main I bound the root,
Clean threads of state, a tidy route —
A carrot-coded, bug-free sign! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: pass git diff root path over IPC' directly and clearly summarizes the main change: removing module-level state and passing workspace root explicitly over IPC for deterministic git-original lookups.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/refactor-git_diff_original-to-use-rootpath

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b90253ffa3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/renderer/src/components/panes/EditorPane.tsx Outdated
Comment thread packages/renderer/src/components/AppShell.tsx
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.

Caution

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

⚠️ Outside diff range comments (1)
packages/renderer/src/components/AppShell.tsx (1)

831-842: ⚠️ Potential issue | 🟠 Major

Split editor commands are missing the required workspaceRoot field.

The onFileOpen callback in AppShell.tsx correctly includes workspaceRoot in the panel params. However, the split editor commands in packages/renderer/src/lib/defaultCommands.ts (lines 22 and 40) still create panels with only { filePath }. Since EditorPaneParams requires workspaceRoot: string | null, split editors will fail to instantiate properly.

Update both split commands to extract and pass workspaceRoot from the active panel's params:

  • Line 22 (editor.splitVertical): Change params: { filePath } to params: { filePath, workspaceRoot: (active.params as Record<string, unknown>)?.workspaceRoot ?? null }
  • Line 40 (editor.splitHorizontal): Apply the same fix
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/renderer/src/components/AppShell.tsx` around lines 831 - 842, Split
editor commands (editor.splitVertical and editor.splitHorizontal in
defaultCommands.ts) create panels with params missing required
EditorPaneParams.workspaceRoot; update both to read workspaceRoot from the
current active panel params and pass it into the new panel params. Specifically,
replace params: { filePath } with params: { filePath, workspaceRoot:
(active.params as Record<string, unknown>)?.workspaceRoot ?? null } for both
editor.splitVertical and editor.splitHorizontal so the new split editor panels
include workspaceRoot and can instantiate correctly.
🧹 Nitpick comments (1)
packages/renderer/src/components/panes/EditorPane.tsx (1)

149-158: Consider stale closure if workspaceRoot changes without filePath changing.

The keybinding at line 152 captures workspaceRoot from the closure when the editor initializes. The effect only re-runs when filePath changes (line 243), so if workspaceRoot were to change independently (e.g., worktree switch), the keybinding would use the stale value.

In practice, workspace/worktree changes likely cause panel recreation, making this a low-risk edge case. If this is intentional, no changes needed.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/renderer/src/components/panes/EditorPane.tsx` around lines 149 -
158, The keybinding's run closure captures workspaceRoot at setup time which can
become stale; update the handler so it always uses the current workspaceRoot —
either by adding workspaceRoot to the dependency list that creates the
keybinding (so the binding is re-created when workspaceRoot changes) or by
reading workspaceRoot at invocation time via a stable ref/getter before calling
toggleInlineDiff (identify the keybinding object and its run method, and the
symbols toggleInlineDiff, workspaceRoot, filePath, setDiffActive, showToast).
Ensure the change avoids introducing memory leaks (clean up/re-register the
keybinding when dependencies change) and keeps the existing post-toggle behavior
(setDiffActive and showToast).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@packages/renderer/src/components/AppShell.tsx`:
- Around line 831-842: Split editor commands (editor.splitVertical and
editor.splitHorizontal in defaultCommands.ts) create panels with params missing
required EditorPaneParams.workspaceRoot; update both to read workspaceRoot from
the current active panel params and pass it into the new panel params.
Specifically, replace params: { filePath } with params: { filePath,
workspaceRoot: (active.params as Record<string, unknown>)?.workspaceRoot ?? null
} for both editor.splitVertical and editor.splitHorizontal so the new split
editor panels include workspaceRoot and can instantiate correctly.

---

Nitpick comments:
In `@packages/renderer/src/components/panes/EditorPane.tsx`:
- Around line 149-158: The keybinding's run closure captures workspaceRoot at
setup time which can become stale; update the handler so it always uses the
current workspaceRoot — either by adding workspaceRoot to the dependency list
that creates the keybinding (so the binding is re-created when workspaceRoot
changes) or by reading workspaceRoot at invocation time via a stable ref/getter
before calling toggleInlineDiff (identify the keybinding object and its run
method, and the symbols toggleInlineDiff, workspaceRoot, filePath,
setDiffActive, showToast). Ensure the change avoids introducing memory leaks
(clean up/re-register the keybinding when dependencies change) and keeps the
existing post-toggle behavior (setDiffActive and showToast).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d362dea9-c174-4773-a5c6-81fed32c5e76

📥 Commits

Reviewing files that changed from the base of the PR and between 13b2aaf and b90253f.

📒 Files selected for processing (7)
  • packages/main/src/gitDiff.ts
  • packages/main/src/index.ts
  • packages/main/src/preload.ts
  • packages/renderer/src/components/AppShell.tsx
  • packages/renderer/src/components/panes/EditorPane.tsx
  • packages/renderer/src/lib/editorInlineDiff.ts
  • packages/shared/src/index.ts
📜 Review details
⏰ 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: claude-review
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{css,scss,tsx,ts}

📄 CodeRabbit inference engine (CLAUDE.md)

Use CSS variable token system with data-theme attribute for theming, supporting dark and light mode

Files:

  • packages/renderer/src/components/AppShell.tsx
  • packages/shared/src/index.ts
  • packages/main/src/index.ts
  • packages/main/src/preload.ts
  • packages/main/src/gitDiff.ts
  • packages/renderer/src/lib/editorInlineDiff.ts
  • packages/renderer/src/components/panes/EditorPane.tsx
**/*editor*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Use CodeMirror 6 for editor implementation (not Monaco)

Files:

  • packages/renderer/src/lib/editorInlineDiff.ts
🧠 Learnings (1)
📚 Learning: 2026-03-25T11:00:59.388Z
Learnt from: Cheezeiii365
Repo: Cheezeiii365/aIDE PR: 4
File: packages/renderer/src/components/FileTree/ContextMenu.tsx:16-20
Timestamp: 2026-03-25T11:00:59.388Z
Learning: Since aIDE does not support Windows, path-handling utilities and related code should assume POSIX-style separators (`/`) (e.g., helpers like `dirname`/`basename` that split on `/`). During review, do not require Windows-style backslash (`\\`) support or `path.sep`/cross-platform normalization unless the project explicitly adds Windows support.

Applied to files:

  • packages/renderer/src/components/AppShell.tsx
  • packages/shared/src/index.ts
  • packages/main/src/index.ts
  • packages/main/src/preload.ts
  • packages/main/src/gitDiff.ts
  • packages/renderer/src/lib/editorInlineDiff.ts
  • packages/renderer/src/components/panes/EditorPane.tsx
🔇 Additional comments (9)
packages/main/src/index.ts (1)

22-22: LGTM — clean removal of setDiffRoot import.

The module-level state setter is correctly removed in favor of the explicit rootPath parameter passed via IPC. The handler registration at line 932 remains intact.

packages/shared/src/index.ts (1)

567-567: LGTM — API signature correctly updated.

The WindowApi.getGitFileOriginal type now matches the updated IPC invocation pattern with rootPath as the first parameter.

packages/main/src/preload.ts (1)

76-77: LGTM — preload bridge correctly forwards rootPath.

The IPC invocation now properly passes both rootPath and filePath arguments, matching the handler signature in gitDiff.ts and the type definition in WindowApi.

packages/renderer/src/lib/editorInlineDiff.ts (1)

69-84: LGTM — toggleInlineDiff correctly threads rootPath to the API.

The function signature and API call are properly updated. The result.content ?? '' fallback gracefully handles the null content case when no git root is available or the file is untracked.

packages/main/src/gitDiff.ts (1)

34-39: LGTM — IPC handler correctly refactored to accept explicit rootPath.

The handler now:

  1. Accepts rootPath as a parameter instead of relying on module state
  2. Returns { content: null } early when no root is provided
  3. Passes the root through to getOriginalContent which validates the path stays within the repo

This makes git diff lookups deterministic and allows targeting any workspace.

packages/renderer/src/components/panes/EditorPane.tsx (4)

22-28: LGTM — EditorPaneParams interface correctly extended.

The workspaceRoot: string | null field is appropriately typed to handle workspaces without a filesystem root.


61-61: LGTM — workspaceRoot correctly extracted from params.


354-367: LGTM — event listener correctly updated with workspaceRoot dependency.

The dependency array now includes workspaceRoot, ensuring the handler is refreshed when the workspace root changes.


397-404: LGTM — badge click handler correctly updated.

Both the toggleInlineDiff call and the useCallback dependency array properly include workspaceRoot.

Cheezeiii365 and others added 2 commits March 28, 2026 15:27
…orkspaceRoot

Previously registerAppActions was called once with an empty dependency array,
so the openFile handler captured the initial workspaceRoot closure. After a
workspace switch, split-editor panels and Quick Open would pass the stale root,
causing git-original lookups to fail (whole file shown as green/added).

Co-authored-by: BT Odoy <Cheezeiii365@users.noreply.github.com>
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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/renderer/src/components/AppShell.tsx`:
- Around line 509-516: The useEffect that calls registerAppActions references
onFileOpen in its dependency array before onFileOpen is declared (causing a TDZ
ReferenceError); move the entire useEffect block that calls registerAppActions
(the block creating openFile/openUrl handlers) so it appears after the const
onFileOpen = useCallback(...) declaration, and keep onFileOpen in the dependency
array so the registration re-runs when onFileOpen changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 14980774-54ac-475e-ac2e-fe8ffa839598

📥 Commits

Reviewing files that changed from the base of the PR and between b90253f and 888e7b5.

📒 Files selected for processing (3)
  • packages/renderer/src/components/AppShell.tsx
  • packages/renderer/src/components/panes/EditorPane.tsx
  • packages/renderer/src/lib/defaultCommands.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{css,scss,tsx,ts}

📄 CodeRabbit inference engine (CLAUDE.md)

Use CSS variable token system with data-theme attribute for theming, supporting dark and light mode

Files:

  • packages/renderer/src/lib/defaultCommands.ts
  • packages/renderer/src/components/AppShell.tsx
  • packages/renderer/src/components/panes/EditorPane.tsx
🧠 Learnings (2)
📚 Learning: 2026-03-25T11:11:52.657Z
Learnt from: CR
Repo: Cheezeiii365/aIDE PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-03-25T11:11:52.657Z
Learning: Applies to **/*layout*.{ts,tsx} : Use Dockview 5.x for layout and tiling panes

Applied to files:

  • packages/renderer/src/lib/defaultCommands.ts
📚 Learning: 2026-03-25T11:00:59.388Z
Learnt from: Cheezeiii365
Repo: Cheezeiii365/aIDE PR: 4
File: packages/renderer/src/components/FileTree/ContextMenu.tsx:16-20
Timestamp: 2026-03-25T11:00:59.388Z
Learning: Since aIDE does not support Windows, path-handling utilities and related code should assume POSIX-style separators (`/`) (e.g., helpers like `dirname`/`basename` that split on `/`). During review, do not require Windows-style backslash (`\\`) support or `path.sep`/cross-platform normalization unless the project explicitly adds Windows support.

Applied to files:

  • packages/renderer/src/lib/defaultCommands.ts
  • packages/renderer/src/components/AppShell.tsx
  • packages/renderer/src/components/panes/EditorPane.tsx
🔇 Additional comments (4)
packages/renderer/src/lib/defaultCommands.ts (1)

16-24: Good propagation of workspaceRoot into split editor panels.

This keeps split-pane params aligned with the new inline-diff root-path flow and avoids relying on hidden global state.

Also applies to: 35-43

packages/renderer/src/components/AppShell.tsx (1)

832-833: Good update: workspaceRoot is now captured and forwarded with editor panel params.

Including workspaceRoot in both params and callback dependencies addresses stale-root behavior across workspace switches.

Also applies to: 843-843

packages/renderer/src/components/panes/EditorPane.tsx (2)

24-25: Nice refactor: explicit diff-root wiring with a safe fallback.

workspaceRoot in pane params plus fallback resolution keeps inline diff deterministic while still handling legacy/missing params.

Also applies to: 61-68


159-160: Good consolidation of inline-diff toggling entry points.

Routing hotkey, global command event, and badge click through one helper improves consistency and maintainability.

Also applies to: 364-368, 401-402

Comment thread packages/renderer/src/components/AppShell.tsx Outdated
The useEffect dependency array [onFileOpen] was evaluated during render
before the const declaration was reached, causing a Temporal Dead Zone
access. Moved the effect to immediately after onFileOpen is defined.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Cheezeiii365 Cheezeiii365 merged commit fb51a32 into main Mar 28, 2026
3 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Apr 8, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant