Skip to content

fix starting zsh profile - #199

Closed
Kitenite wants to merge 1 commit into
mainfrom
teal-cloud-63
Closed

Kitenite wants to merge 1 commit into
mainfrom
teal-cloud-63

Conversation

@Kitenite

@Kitenite Kitenite commented Dec 1, 2025 •

Copy link
Copy Markdown
Member

Description

Related Issues

Type of Change

  • Bug fix
  • New feature
  • Documentation
  • Refactor
  • Other (please describe):

Testing

Screenshots (if applicable)

Additional Notes

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced shell environment initialization to properly load all configuration settings during startup, ensuring more comprehensive and reliable shell setup.

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

@vercel

vercel Bot commented Dec 1, 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 1, 2025 2:39am

@coderabbitai

coderabbitai Bot commented Dec 1, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

A single file modification to the zsh shell initialization wrapper script in the agent setup. The wrapper now sets ZDOTDIR for nested shells, conditionally sources multiple initialization files (.zshenv, .zshrc, .zlogin), and prepends Superset's bin directory to PATH, replacing the previous simpler approach.

Changes

Cohort / File(s) Summary
Zsh wrapper initialization
apps/desktop/src/main/lib/agent-setup.ts
Modified zsh wrapper script to enhance shell initialization: sets ZDOTDIR for nested shells, conditionally sources .zshenv, .zshrc, and .zlogin files, prepends Superset bin to PATH, and removed old ZDOTDIR export logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10–15 minutes

  • Verify shell script syntax and correct conditional logic for sourcing initialization files
  • Confirm ZDOTDIR behavior with nested shells and interaction with existing zsh startup sequence
  • Test PATH prepending doesn't interfere with user's existing shell configuration

Possibly related PRs

Poem

🐰 A rabbit hops through shells with glee,
Setting ZDOTDIR so paths align just right,
Sourcing files—.zshenv, .zshrc, .zlogin—
Prepending Superset's bins to the flight,
Initialization now crisp and clean! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is entirely empty—all template sections contain only placeholders with no substantive content provided by the author. Fill in all required sections: provide a clear description of the zsh profile fix, link any related issues, mark the change type (appears to be a bug fix), describe testing steps, and add any relevant context.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix starting zsh profile' directly relates to the main change: improvements to zsh shell initialization in agent-setup.ts.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ 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 teal-cloud-63

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.

@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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 325d518 and 506f40d.

📒 Files selected for processing (1)
  • apps/desktop/src/main/lib/agent-setup.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
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/main/lib/agent-setup.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/main/lib/agent-setup.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Avoid using any type - use explicit types instead for type safety
Use camelCase for variable and function names following existing codebase patterns
Keep diffs minimal with targeted edits only - avoid unnecessary changes when making modifications
Follow existing patterns and match the codebase style when writing new code

Files:

  • apps/desktop/src/main/lib/agent-setup.ts
apps/desktop/src/main/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Node.js modules (fs, path, os, net, etc.) can be used in main process code only

Files:

  • apps/desktop/src/main/lib/agent-setup.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

Comment on lines +125 to 152
const zshrcScript = `# Superset zsh initialization wrapper
# This file intercepts zsh startup to ensure ~/.superset/bin is in PATH

# Restore original ZDOTDIR for any nested shells
export ZDOTDIR="\${SUPERSET_ORIG_ZDOTDIR:-$HOME}"

ORIG_ZDOTDIR="$ZDOTDIR"

# Source the same user-level startup files zsh normally would
if [[ -f "$ORIG_ZDOTDIR/.zshenv" ]]; then
source "$ORIG_ZDOTDIR/.zshenv"
fi

# Source user's real zshrc if it exists
if [[ -f "$ORIG_ZDOTDIR/.zshrc" ]]; then
source "$ORIG_ZDOTDIR/.zshrc"
fi

# Finish login shell sequence
if [[ -o login && -f "$ORIG_ZDOTDIR/.zlogin" ]]; then
source "$ORIG_ZDOTDIR/.zlogin"
fi

# Prepend superset bin to PATH (after user's rc has run)
export PATH="$HOME/${SUPERSET_DIR_NAME}/bin:$PATH"
export ZDOTDIR="$_superset_home"
`;
fs.writeFileSync(zshrcPath, zshrcScript, { mode: 0o644 });
console.log("[agent-setup] Created zsh wrapper");

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 | 🔴 Critical

Fix the zsh startup sequence violation.

The current implementation sources .zshenv and .zlogin from within .zshrc, which violates zsh's expected startup order and can cause initialization issues.

Expected zsh startup sequence: .zshenv → .zprofile → .zshrc → .zlogin

Current sequence with wrappers:

  1. zsh sources our .zprofile → sources user's .zprofile
  2. zsh sources our .zshrc → sources user's .zshenv ❌ (too late), .zshrc ✓, .zlogin ❌ (too early)

Impact:

  • Environment variables in user's .zshenv are unavailable when their .zprofile runs (breaks PATH setup dependencies)
  • Commands in user's .zlogin run before .zshrc completes (breaks timing assumptions)

Recommended fix:

Create separate wrapper files for each startup file to maintain the correct sequence:

 function createZshWrapper(): void {
+	// Create .zshenv wrapper (runs first, always)
+	const zshenvPath = path.join(ZSH_DIR, ".zshenv");
+	const zshenvScript = `# Superset zsh environment wrapper
+# Restore original ZDOTDIR for nested shells
+export ZDOTDIR="\${SUPERSET_ORIG_ZDOTDIR:-$HOME}"
+
+# Source user's .zshenv if it exists
+[[ -f "$ZDOTDIR/.zshenv" ]] && source "$ZDOTDIR/.zshenv"
+`;
+	fs.writeFileSync(zshenvPath, zshenvScript, { mode: 0o644 });
+
 	// Create .zprofile to source user's .zprofile (runs for login shells before .zshrc)
 	// This is critical - without it, brew/nvm PATH setup in ~/.zprofile is skipped
 	const zprofilePath = path.join(ZSH_DIR, ".zprofile");
 	const zprofileScript = `# Superset zsh profile wrapper
-_superset_home="\${SUPERSET_ORIG_ZDOTDIR:-$HOME}"
-[[ -f "$_superset_home/.zprofile" ]] && source "$_superset_home/.zprofile"
+[[ -f "$ZDOTDIR/.zprofile" ]] && source "$ZDOTDIR/.zprofile"
 `;
 	fs.writeFileSync(zprofilePath, zprofileScript, { mode: 0o644 });
 
 	// Create .zshrc to source user's .zshrc then prepend our bin
 	const zshrcPath = path.join(ZSH_DIR, ".zshrc");
 	const zshrcScript = `# Superset zsh initialization wrapper
-# This file intercepts zsh startup to ensure ~/.superset/bin is in PATH
-
-# Restore original ZDOTDIR for any nested shells
-export ZDOTDIR="\${SUPERSET_ORIG_ZDOTDIR:-$HOME}"
-
-ORIG_ZDOTDIR="$ZDOTDIR"
-
-# Source the same user-level startup files zsh normally would
-if [[ -f "$ORIG_ZDOTDIR/.zshenv" ]]; then
-  source "$ORIG_ZDOTDIR/.zshenv"
-fi
-
 # Source user's real zshrc if it exists
-if [[ -f "$ORIG_ZDOTDIR/.zshrc" ]]; then
-  source "$ORIG_ZDOTDIR/.zshrc"
-fi
-
-# Finish login shell sequence
-if [[ -o login && -f "$ORIG_ZDOTDIR/.zlogin" ]]; then
-  source "$ORIG_ZDOTDIR/.zlogin"
-fi
-
-# Prepend superset bin to PATH (after user's rc has run)
-export PATH="$HOME/${SUPERSET_DIR_NAME}/bin:$PATH"
+[[ -f "$ZDOTDIR/.zshrc" ]] && source "$ZDOTDIR/.zshrc"
 `;
 	fs.writeFileSync(zshrcPath, zshrcScript, { mode: 0o644 });
+
+	// Create .zlogin wrapper (runs last for login shells)
+	const zloginPath = path.join(ZSH_DIR, ".zlogin");
+	const zloginScript = `# Superset zsh login wrapper
+# Source user's .zlogin if it exists
+[[ -f "$ZDOTDIR/.zlogin" ]] && source "$ZDOTDIR/.zlogin"
+
+# Prepend superset bin to PATH (runs at the very end)
+export PATH="$HOME/${SUPERSET_DIR_NAME}/bin:$PATH"
+`;
+	fs.writeFileSync(zloginPath, zloginScript, { mode: 0o644 });
+
 	console.log("[agent-setup] Created zsh wrapper");
 }

Note: By setting ZDOTDIR once in .zshenv and using $ZDOTDIR in subsequent wrappers, nested shells automatically use the original ZDOTDIR without needing to re-export it in every file.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In apps/desktop/src/main/lib/agent-setup.ts around lines 125-152, the zsh
wrapper currently sources the user's .zshenv and .zlogin from inside the .zshrc
wrapper, violating zsh's startup order; instead create separate wrapper files
that preserve the correct sequence: write a .zshenv wrapper that sets
SUPERSET_ORIG_ZDOTDIR (if not already set) and exports ZDOTDIR to point to the
wrapper directory, then write a .zprofile wrapper that sources
"$ZDOTDIR/.zprofile" if present and then runs any superset .zprofile logic,
write a .zshrc wrapper that sources "$ZDOTDIR/.zshrc" (do not source .zshenv or
.zlogin here) and finally write a .zlogin wrapper that sources
"$ZDOTDIR/.zlogin" after .zshrc; ensure each wrapper reads $ZDOTDIR (so nested
shells inherit original location), prepend the superset bin to PATH only in the
appropriate wrapper (e.g., .zprofile or .zshrc as needed), and write each file
with correct permissions and a console log for creation.

@AviPeltz AviPeltz closed this Dec 8, 2025
@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! 🎉

@Kitenite
Kitenite deleted the teal-cloud-63 branch December 9, 2025 00:47

This branch was successfully deployed

1 active deployment
Preview — 506f40dd Deployed Dec 1, 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.

2 participants