Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conn updates 4 #1726

Merged
merged 17 commits into from
Jan 14, 2025
Merged

conn updates 4 #1726

merged 17 commits into from
Jan 14, 2025

Conversation

sawka
Copy link
Member

@sawka sawka commented Jan 14, 2025

No description provided.

Copy link
Contributor

coderabbitai bot commented Jan 14, 2025

Warning

Rate limit exceeded

@sawka has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 20 minutes and 57 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 9fafb65 and 59198f8.

📒 Files selected for processing (1)
  • pkg/genconn/quote.go (2 hunks)

Walkthrough

The pull request introduces a comprehensive set of modifications across multiple files in the Wave Terminal project. The changes primarily focus on enhancing shell integration, improving connection management, and refining error handling and logging mechanisms. Key modifications include updating function signatures to incorporate context management, adding new shell type constants, introducing more robust path resolution for shell binaries, and expanding connection configuration options.

The modifications span various components of the application, including remote connection handling, shell execution, utility functions, and frontend components. Notable additions include new constants for shell types, methods for detecting shell paths, and expanded connection keyword structures. The changes aim to improve the flexibility, maintainability, and robustness of the Wave Terminal's shell interaction and connection management capabilities.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
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

🔭 Outside diff range comments (1)
pkg/shellexec/shellexec.go (1)

Line range hint 272-314: Utilize context parameter within StartRemoteShellProcNoWsh for cancellation

The ctx context.Context parameter is introduced to StartRemoteShellProcNoWsh but isn't used within the function body. To fully leverage context benefits, consider checking ctx.Done() at appropriate points and passing ctx to dependent functions to handle cancellations and timeouts during SSH session creation and command execution.

🧹 Nitpick comments (8)
pkg/shellexec/shellexec.go (3)

161-176: Ensure robust shell detection with case-insensitive matching

The getShellTypeFromShellPath function uses strings.Contains to detect shell types, which may fail for shell paths with different casing (e.g., "Bash", "ZSH"). Consider normalizing shellBase to lower case to handle case variations.

Proposed change:

func getShellTypeFromShellPath(shellPath string) string {
    shellBase := filepath.Base(shellPath)
+   shellBase = strings.ToLower(shellBase)
    if strings.Contains(shellBase, "bash") {
        return ShellType_bash
    }
    if strings.Contains(shellBase, "zsh") {
        return ShellType_zsh
    }
    // Apply similar changes for other shell types

Line range hint 315-393: Incorporate context into StartRemoteShellProc for better control flow

Similar to StartRemoteShellProcNoWsh, StartRemoteShellProc accepts ctx context.Context but doesn't utilize it. Integrate ctx into the function logic to manage execution flow, especially during network operations that might benefit from context-based cancellation and timeout handling.


466-500: Refactor shell option construction to reduce code duplication

The conditional logic for constructing shellOpts based on shellType has repetitive patterns across different shells. Consider refactoring this logic into a separate helper function to improve code maintainability and readability.

pkg/genconn/ssh-impl.go (1)

45-45: Consider using structured logging.

While adding logging for SSH session creation is valuable, consider using structured logging with additional context (e.g., client ID or connection details) to make debugging easier.

-log.Printf("SSH-NEWSESSION (cmdclient)\n")
+log.Printf("SSH-NEWSESSION (cmdclient) client=%v\n", client.RemoteAddr())
pkg/remote/connutil.go (1)

90-93: Consider using && for fail-fast behavior.

While adding semicolons improves shell compatibility, using && would ensure the script stops on the first failure.

-mkdir -p {{.installDir}} || exit 1;
-cat > {{.tempPath}} || exit 1;
-mv {{.tempPath}} {{.installPath}} || exit 1;
-chmod a+x {{.installPath}} || exit 1;
+mkdir -p {{.installDir}} || exit 1 && \
+cat > {{.tempPath}} || exit 1 && \
+mv {{.tempPath}} {{.installPath}} || exit 1 && \
+chmod a+x {{.installPath}} || exit 1
pkg/blockcontroller/blockcontroller.go (1)

372-386: Consider enhancing error handling in WSH fallback scenario.

While the addition of context support is good, the error handling in the WSH fallback scenario could be improved. When WSH fails and falls back to no-WSH mode, we should consider:

  1. Logging the original WSH error for debugging
  2. Adding more detailed error information in the connection status

Consider updating the error handling:

 } else {
     shellProc, err = shellexec.StartRemoteShellProc(ctx, rc.TermSize, cmdStr, cmdOpts, conn)
     if err != nil {
         conn.SetWshError(err)
         conn.WshEnabled.Store(false)
-        log.Printf("error starting remote shell proc with wsh: %v", err)
-        log.Print("attempting install without wsh")
+        log.Printf("error starting remote shell proc with wsh (falling back to no-wsh mode): %v", err)
         shellProc, err = shellexec.StartRemoteShellProcNoWsh(ctx, rc.TermSize, cmdStr, cmdOpts, conn)
         if err != nil {
+            // Combine both errors for better debugging
+            return nil, fmt.Errorf("shell process start failed: with-wsh: %v, no-wsh: %v", conn.GetWshError(), err)
         }
     }
 }
pkg/wshrpc/wshserver/wshserver.go (1)

713-716: Consider utilizing the discarded architecture information.

The additional return value (architecture information) is being discarded. This information could be useful for logging or debugging when WSH is not installed.

Consider logging the architecture information when WSH is not up to date:

-    upToDate, _, _, err := conncontroller.IsWshVersionUpToDate(remoteInfo.ClientVersion)
+    upToDate, _, osArchStr, err := conncontroller.IsWshVersionUpToDate(remoteInfo.ClientVersion)
     if err != nil {
         return false, fmt.Errorf("unable to compare wsh version: %w", err)
     }
     if upToDate {
         // no need to update
         log.Printf("wsh is already up to date for connection %s", connName)
         return false, nil
     }
+    if !upToDate {
+        log.Printf("wsh needs update for connection %s (arch: %s)", connName, osArchStr)
+    }
frontend/app/view/preview/preview.tsx (1)

41-42: Address the TODO comment for configuration-driven bookmarks.

The bookmarks should be driven by configuration to allow users to customize their navigation shortcuts.

Would you like me to help implement a configuration-driven solution? I can:

  1. Add a new setting type for bookmarks in the configuration.
  2. Create a function to load bookmarks from the configuration.
  3. Add a UI for managing bookmarks.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a44a1a4 and 9fafb65.

📒 Files selected for processing (17)
  • cmd/wsh/cmd/wshcmd-ai.go (1 hunks)
  • cmd/wsh/cmd/wshcmd-rcfiles.go (1 hunks)
  • cmd/wsh/cmd/wshcmd-setbg.go (1 hunks)
  • frontend/app/view/preview/preview.tsx (2 hunks)
  • frontend/app/view/waveai/waveai.tsx (0 hunks)
  • frontend/types/gotypes.d.ts (1 hunks)
  • pkg/blockcontroller/blockcontroller.go (2 hunks)
  • pkg/genconn/quote.go (2 hunks)
  • pkg/genconn/ssh-impl.go (2 hunks)
  • pkg/remote/conncontroller/conncontroller.go (8 hunks)
  • pkg/remote/connutil.go (4 hunks)
  • pkg/shellexec/shellexec.go (7 hunks)
  • pkg/util/shellutil/shellutil.go (10 hunks)
  • pkg/wshrpc/wshrpctypes.go (1 hunks)
  • pkg/wshrpc/wshserver/wshserver.go (2 hunks)
  • pkg/wshutil/wshutil.go (1 hunks)
  • pkg/wsl/wsl.go (1 hunks)
💤 Files with no reviewable changes (1)
  • frontend/app/view/waveai/waveai.tsx
✅ Files skipped from review due to trivial changes (2)
  • cmd/wsh/cmd/wshcmd-setbg.go
  • pkg/wshutil/wshutil.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build for TestDriver.ai
🔇 Additional comments (23)
pkg/shellexec/shellexec.go (1)

38-44: Introduce shell type constants for clarity and maintainability

Defining shell type constants enhances code readability and maintainability by avoiding magic strings. It also simplifies future updates when supporting additional shells.

pkg/remote/conncontroller/conncontroller.go (6)

72-77: Enhance readability by using strings.Join in command template

The restructured ConnServerCmdTemplate using strings.Join improves code clarity, making the multi-line command easier to read and maintain.


232-246: Update IsWshVersionUpToDate to provide detailed version info

Modifying IsWshVersionUpToDate to return osArchStr along with the version enhances error handling by supplying additional context when wsh is not installed, facilitating better decision-making downstream.


249-255: Encapsulate WSH path logic in getWshPath method

Introducing the getWshPath function centralizes WSH path determination logic, improving code modularity and simplifying maintenance by avoiding repeated code.


Line range hint 268-379: Adjust StartConnServer to return osArchStr for installation flow

By updating StartConnServer to return osArchStr, the code can better handle WSH installation scenarios when the client version is not up to date. This change enhances error handling and allows for prompt installation of the correct WSH version.


462-475: Modify InstallWsh to use osArchStr for accurate installation

Updating InstallWsh to accept osArchStr allows for precise detection of the client's OS and architecture, ensuring that the correct version of WSH is installed. This change improves the reliability of the installation process.


576-579: ⚠️ Potential issue

Fix uninitialized err variable in error handling

The err variable is checked but hasn't been assigned a value, which will cause a compilation error. Ensure err is properly assigned before usage.

Proposed fix:

 existingConnection, ok := conn.getConnectionConfig()
-if err != nil {
-    // i do not consider this a critical failure
-    log.Printf("config read error: unable to save connection %s: %v", conn.GetName(), err)
-}
+if !ok {
+    // i do not consider this a critical failure
+    log.Printf("config read error: unable to save connection %s", conn.GetName())
+}

Alternatively, remove the unused error handling if err is not applicable.

Likely invalid or redundant comment.

cmd/wsh/cmd/wshcmd-rcfiles.go (1)

22-22: Correct WriteStderr function usage by adding format specifier

Adding the format string to WriteStderr ensures proper formatting of the error message and prevents runtime errors due to missing format specifiers.

pkg/genconn/quote.go (3)

9-10: LGTM! Clear distinction between Unix and PowerShell patterns.

The psSafePattern correctly excludes forward slash since PowerShell uses backslash as path separator.


26-38: Improved escape handling with better structure.

The switch-case structure makes the code more maintainable and the newline handling is now explicit.


Line range hint 40-65: Consider adding unit tests for PowerShell quoting.

The PowerShell-specific quoting implementation looks correct, using backtick as escape character and handling special cases appropriately. However, this new functionality should be thoroughly tested.

Would you like me to help generate comprehensive unit tests for the PowerShell quoting functionality?

cmd/wsh/cmd/wshcmd-ai.go (1)

145-146: Verify memory impact of increased message size.

The message size limit has been increased from 10KB to 50KB. While this provides more flexibility for users, we should verify that this doesn't cause memory pressure, especially in concurrent scenarios.

✅ Verification successful

Message size increase to 50KB is safe

The increase from 10KB to 50KB is safe as messages are processed synchronously and the limit is well within the global 64MB threshold. There's no evidence of concurrent processing or complex buffering that could amplify memory impact.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any memory-related configurations or limitations in the codebase
rg -A 3 'memory|heap|buffer.*size|maxSize'

# Look for similar size limits in other parts of the code
rg '(\d+)\s*\*\s*1024'

Length of output: 119535


Script:

#!/bin/bash
# Check message handling patterns and buffering
rg -A 5 'message.*process|buffer.*message|message.*buffer|message.*pool|message.*queue'

# Look for concurrent message handling
rg -A 5 'go\s+func.*message|chan.*message|mutex.*message'

# Check for memory management patterns
rg -A 5 'sync\.Pool|buffer\.Pool|memory.*limit|memory.*manage'

Length of output: 117083


Script:

#!/bin/bash
# Check message processing implementation in wshcmd-ai.go
rg -A 10 'func.*message|process.*message' cmd/wsh/cmd/wshcmd-ai.go

# Look for goroutine patterns and channel usage
rg -A 5 'go\s+func|chan\s+\w+|make\(chan' cmd/wsh/cmd/wshcmd-ai.go

# Check buffer management
rg -A 5 'buffer.*size|maxBuffer|MaxBuffer' cmd/wsh/cmd/

Length of output: 642

pkg/remote/connutil.go (2)

77-87: LGTM! Well-structured platform parsing.

The function properly normalizes and validates the OS/architecture string input.


98-98: LGTM! Improved path handling and logging.

The changes simplify path handling and add helpful debug logging. The switch to GetLocalWshBinaryPath aligns with the broader changes in the codebase.

Also applies to: 109-110, 116-116

pkg/util/shellutil/shellutil.go (4)

50-53: LGTM! Improved Zsh shell integration with proper ZDOTDIR handling.

The changes correctly handle the ZDOTDIR environment variable across Zsh startup files, ensuring proper sourcing of user configuration files while maintaining shell environment consistency.

Also applies to: 65-69, 73-84


41-41: LGTM! Added comprehensive Fish shell support.

The changes introduce proper Fish shell integration with:

  • Integration directory setup
  • PATH management
  • Wave completions support

Also applies to: 109-116, 247-249, 291-295


119-123: LGTM! Enhanced PowerShell integration with proper path handling.

The changes improve PowerShell support with:

  • OS-aware path separator handling
  • PowerShell-specific environment setup
  • Proper quoting for PowerShell paths

Also applies to: 302-312


277-279: LGTM! Improved path safety in InitRcFiles.

The function signature now explicitly requires an absolute, expanded path for absWshBinDir, preventing potential path resolution issues.

pkg/wsl/wsl.go (1)

340-340: LGTM! Updated function call to match new naming convention.

The change correctly uses the renamed GetLocalWshBinaryPath function, maintaining consistency with the changes in shellutil.go.

pkg/wshrpc/wshrpctypes.go (1)

478-478: LGTM! Added shell path configuration support.

The new ConnShellPath field properly extends connection configuration options, following the existing field naming convention and JSON tag patterns.

frontend/types/gotypes.d.ts (1)

307-307: LGTM! The new property follows the established conventions.

The addition of the optional "conn:shellpath" property to ConnKeywords type is well-structured and maintains backward compatibility.

pkg/wshrpc/wshserver/wshserver.go (1)

699-699: Verify the empty string parameter usage.

The empty string parameter passed to InstallWsh might indicate a missing value. Consider whether a meaningful value should be provided instead.

Run this script to check if there are any references to this parameter in the codebase:

frontend/app/view/preview/preview.tsx (1)

197-201: LGTM! The context menu implementation is clean and maintainable.

The dynamic generation of menu items from the BOOKMARKS array:

  • Improves code maintainability by centralizing the bookmark definitions
  • Enhances user experience by showing both the label and path
  • Makes the code more DRY by eliminating repetitive menu item definitions

@sawka sawka merged commit a24fe75 into main Jan 14, 2025
6 of 7 checks passed
@sawka sawka deleted the sawka/conn-updates-4 branch January 14, 2025 22:09
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