Skip to content

Conversation

@helizaga
Copy link
Collaborator

@helizaga helizaga commented Nov 14, 2025

Summary by CodeRabbit

  • New Features

    • Added config add action; introduced editor subcommand (replacing open) and PATH-based fallback for editors and AI tools.
  • Bug Fixes

    • Improved visibility of error/info messages by redirecting relevant output to stderr.
  • Documentation

    • Updated help text, usage examples and shell completions to use gtr editor and the new config/adapter behaviors.

…pdate README to replace 'git config' with 'gtr config' for clarity and consistency. Enhance gtr script to support 'add' action in config management, allowing multi-valued configurations. Update error messages and documentation for better user guidance.
…rom potentially multi-word editor strings to ensure proper detection and execution. Update dynamic function definitions to accommodate editor arguments, improving compatibility with various editor commands.
…from potentially multi-word AI tool strings to ensure accurate detection. Update dynamic function definitions to handle arguments correctly, enhancing compatibility with various AI tools.
…e function to capture worktree path and redirect error output to stderr for better logging. Enhance log functions in ui.sh to ensure consistent error reporting.
@helizaga helizaga requested a review from NatoBoram November 14, 2025 00:27
@coderabbitai
Copy link

coderabbitai bot commented Nov 14, 2025

Warning

Rate limit exceeded

@helizaga has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 21 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 251a8d4 and 9e1ba7c.

📒 Files selected for processing (2)
  • README.md (13 hunks)
  • bin/gtr (14 hunks)
📝 Walkthrough

Walkthrough

Replaces the top-level "open" command with "editor", adds a config "add" action, implements PATH-based fallback for editor and AI adapters, captures created worktree paths, and redirects several outputs/logs to stderr; documentation and shell completions updated to match.

Changes

Cohort / File(s) Summary
CLI dispatcher & adapter logic
bin/gtr
Renamed top-level subcommand from openeditor and handler cmd_opencmd_editor; capture worktree path from create_worktree; add config add action; implement PATH-based fallback for editor and AI adapters with generic wrapper functions; update help/usage text.
Documentation & manuals
README.md, CLAUDE.md
Replace examples and narrative references from gtr opengtr editor; update usage examples to use gtr config add/set instead of git config; document PATH-based adapter fallback and updated command syntax.
Shell completions
completions/_gtr, completions/gtr.bash, completions/gtr.fish
Replace open with editor in completion lists and case branches; update descriptions and subcommand aggregation to include editor.
Core scripts: output/log redirection
lib/core.sh, lib/ui.sh
Change git worktree creation redirection from 2>/dev/null to >&2; route log_info and log_step output to stderr.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant gtr as bin/gtr
    participant Explicit as Explicit Adapter
    participant PATH as PATH-based Adapter

    User->>gtr: request editor for worktree
    gtr->>gtr: load_editor_adapter(editor_name)
    alt explicit adapter file exists
        gtr->>Explicit: load explicit adapter
        Explicit-->>gtr: provides editor_can_open / editor_open
    else no explicit adapter
        gtr->>PATH: check editor command in PATH
        PATH-->>gtr: provide generic editor_can_open / editor_open wrappers
    end
    gtr-->>User: invoke editor_open to open worktree
Loading
sequenceDiagram
    participant User
    participant gtr as bin/gtr
    participant ExplicitAI as Explicit AI Adapter
    participant PATHAI as PATH-based AI

    User->>gtr: request AI tool start
    gtr->>gtr: load_ai_adapter(ai_tool)
    alt explicit AI adapter exists
        gtr->>ExplicitAI: load adapter
        ExplicitAI-->>gtr: ai_can_start / ai_start
    else fallback to PATH
        gtr->>PATHAI: extract command, verify in PATH
        PATHAI-->>gtr: supply generic ai_can_start / ai_start wrappers
    end
    gtr-->>User: start AI tool
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay attention to adapter fallback functions in bin/gtr (edge cases: quoting, PATH lookup, command arguments).
  • Verify config add parsing and help text consistency.
  • Confirm stderr redirection changes in lib/core.sh and lib/ui.sh do not break scripts or consumptive parsing.
  • Check completion scripts (completions/*) for consistency with new subcommand list.

Poem

A rabbit hops through code at night, 🐇
Swapping "open" for "editor" just right,
Config gains an "add" to tuck in new keys,
Adapters fall back to PATH with ease,
Logs whisper to stderr — soft moonlight. 🌙

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'fixes discussed in call' is vague and does not clearly describe the actual changes, which involve renaming the 'open' command to 'editor' and related updates across the codebase. Provide a more descriptive title that summarizes the main change, such as 'Rename open command to editor and update related configuration' or 'Replace open command with editor and add config management'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

Copy link

@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

🧹 Nitpick comments (4)
lib/core.sh (1)

293-368: git worktree add output to stderr matches the new “stdout is data” contract

Routing all git worktree add calls through >&2 is a good fit with the new usage where create_worktree’s stdout is consumed programmatically (captured in bin/gtr). This keeps git’s messages on stderr while create_worktree itself prints only $worktree_path on stdout.

To keep this contract robust over time, it’s worth double-checking that no other commands inside create_worktree ever emit to stdout (now or in future refactors), otherwise callers that capture stdout may end up with mixed output instead of a clean path.

bin/gtr (2)

186-215: Capturing create_worktree output is correct but makes its stdout contract important

Using worktree_path=$(create_worktree ...) and then passing that to copy_patterns and run_hooks_in is a solid improvement; hooks and copy now work with the actual created path instead of recomputing it.

Because of this, create_worktree’s stdout effectively becomes an API (must be exactly the worktree path, nothing else). You’ve already redirected the git worktree add calls to stderr; I’d just recommend:

  • Add a short comment to create_worktree documenting that it must only print the path on stdout, or
  • Proactively redirect any other potentially chatty commands in that function to stderr as well.

That will make future edits less likely to accidentally break worktree_path capture.


802-856: Generic editor/AI adapters via PATH are handy; consider reducing eval and hardening quoting

The PATH-based fallbacks in load_editor_adapter and load_ai_adapter are a nice usability improvement and align with the docs (any command in PATH, multi-word commands like code --wait or bunx @github/copilot@latest). Functionally this should work as intended.

A couple of refinements would make this more robust:

  • Both functions use eval with interpolated $editor / $ai_tool and $cmd_name. If these ever contain quotes, braces, or other shell metacharacters (e.g., from a malicious repo-local config), the generated function bodies can break or behave unexpectedly.
  • You can avoid eval entirely by storing the command and its first word in globals and writing simple wrappers, e.g.:
 load_editor_adapter() {
   local editor="$1"
   local adapter_file="$GTR_DIR/adapters/editor/${editor}.sh"

   if [ -f "$adapter_file" ]; then
     . "$adapter_file"
     return 0
   fi

   local cmd_name="${editor%% *}"

   if ! command -v "$cmd_name" >/dev/null 2>&1; then
     log_error "Editor '$editor' not found"
     log_info "Built-in adapters: cursor, vscode, zed, idea, pycharm, webstorm, vim, nvim, emacs, sublime, nano, atom"
     log_info "Or use any editor command available in your PATH (e.g., code-insiders, fleet)"
     exit 1
   fi

+  GTR_EDITOR_CMD="$editor"
+  GTR_EDITOR_CMD_NAME="$cmd_name"
+}
+
+editor_can_open() {
+  command -v "$GTR_EDITOR_CMD_NAME" >/dev/null 2>&1
+}
+
+editor_open() {
+  # $GTR_EDITOR_CMD may contain arguments (e.g., "code --wait")
+  eval "$GTR_EDITOR_CMD \"\$1\""
 }

A similar pattern can be applied to load_ai_adapter/ai_can_start/ai_start.

Not strictly required for this PR, but it would remove eval from function-definition paths and make behavior more predictable, especially when config comes from a cloned repo.

README.md (1)

223-231: Include add in the gtr config command signature for consistency

This section still shows:

gtr config {get|set|unset} <key> [value] [--global]

Everywhere else (CLI help and examples) now documents add as a first-class action, and the implementation supports it. Consider updating this line to:

gtr config {get|set|add|unset} <key> [value] [--global]

to keep the README consistent with the tool’s capabilities.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fbb7cc3 and d4bd5aa.

📒 Files selected for processing (4)
  • README.md (5 hunks)
  • bin/gtr (6 hunks)
  • lib/core.sh (4 hunks)
  • lib/ui.sh (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
lib/core.sh (1)
lib/ui.sh (2)
  • log_info (4-6)
  • log_step (16-18)
🔍 Remote MCP Exa

Based on my research, I have gathered sufficient context about the PR changes and best practices. Let me compile the relevant findings for the pull request review.

Summary of Relevant Context for PR #5 Review

Output Redirection and Error Handling Best Practices

The PR changes in lib/core.sh and lib/ui.sh redirect output to stderr using >&2 instead of suppressing it with 2>/dev/null. This aligns with bash shell scripting best practices:

  • Error visibility: Redirecting to stderr (>&2) preserves error information for debugging and logging, which is preferable to suppressing errors unless there's a specific reason
  • Logging separation: Best practice is to separate standard output (informational messages) from standard error (diagnostic/error messages), allowing flexible handling downstream
  • Logging functions: Modern shell scripts typically implement error logging functions that explicitly write to stderr using >&2 for diagnostic messages

Git Worktree Command Patterns and Configuration

The changes in bin/gtr align with standard git worktree management patterns:

  • Worktree path capturing: The change to capture the worktree path from create_worktree output is consistent with practical worktree workflows where the path is needed for subsequent operations
  • Configuration management: Git worktrees support flexible configuration including per-worktree settings. The extension of cmd_config to support add action alongside set and unset follows standard configuration management practices
  • Fallback adapter patterns: The implementation of PATH-based fallback adapters for editor and AI tools is consistent with flexible tool integration patterns in shell scripts, allowing users to specify any command available in their PATH

Configuration Command Syntax

The README changes replacing git config syntax with gtr config add/set/get commands represent a significant public API update. Key review considerations:

  • Clarity and consistency of the new gtr syntax across documentation examples
  • Backward compatibility impact if this replaces previous configuration methods
  • Documentation completeness for the new add action capability

Code Quality Observations

Based on the changes:

  • bin/gtr: High effort review justified by multiple behavioral changes including new add action and fallback adapter logic
  • lib/core.sh & lib/ui.sh: Medium effort review appropriate for focused output redirection changes
  • README.md: Medium effort review appropriate for documentation updates affecting user guidance
🔇 Additional comments (4)
lib/ui.sh (1)

4-18: Logging info/step messages to stderr is consistent and helpful

Redirecting log_info and log_step to stderr keeps stdout clean for command-substitution/machine output and aligns them with log_warn/log_error. log_question correctly stays on stdout for prompts. Looks good.

bin/gtr (2)

728-800: cmd_config “add” action wiring looks good

Extending cmd_config to support add alongside get|set|unset is wired correctly:

  • Argument parsing only captures value when action is set or add.
  • The add branch validates both key and value and delegates to cfg_add.
  • Usage/help strings are updated to mention add.

Assuming cfg_add is implemented to mirror git config --add semantics for multi-valued keys, this looks consistent with the README examples using gtr config add ....


922-937: Help text correctly documents config add and PATH-based adapters

The cmd_help section now:

  • Lists config {get|set|add|unset} and explains add as “multi-valued configs like hooks, copy patterns”.
  • Explicitly notes that any command in PATH can be used for adapters (e.g., code-insiders, bunx).

This matches the behavior in cmd_config, load_editor_adapter, and load_ai_adapter and keeps the CLI self-documenting.

README.md (1)

321-402: README config examples align with new config add behavior

The updated examples under “File Copying”, “Hooks”, “Configuration Examples”, and .gtr-setup.sh all use gtr config add for multi-valued keys (gtr.copy.include, gtr.copy.exclude, gtr.hook.postCreate, gtr.hook.postRemove, etc.), which matches the new cmd_config + cfg_add semantics and the way cfg_get_all is used in the code.

This makes it much clearer how to manage multi-valued settings and is consistent with the CLI help.

…mentation and scripts for consistency. Modify completions and command handling in gtr script to reflect the new editor command. Enhance README and CLAUDE.md to guide users on the updated command usage.
Copy link

@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

🧹 Nitpick comments (1)
CLAUDE.md (1)

207-213: Consider adding a language specifier to the code block.

The fenced code block showing the command flow would benefit from a language specifier for consistency with the rest of the document.

Apply this diff:

-```
+```text
 bin/gtr main()
   → cmd_editor()
   → resolve_target() [lib/core.sh]
   → load_editor_adapter()
   → editor_open() [adapters/editor/*.sh]

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used**: CodeRabbit UI

**Review profile**: CHILL

**Plan**: Pro

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between d4bd5aa31044fae7dcbb02edc346cb3b560f7c55 and 251a8d4458ca05005521729c5b8fb288bba4f3a7.

</details>

<details>
<summary>📒 Files selected for processing (6)</summary>

* `CLAUDE.md` (6 hunks)
* `README.md` (12 hunks)
* `bin/gtr` (13 hunks)
* `completions/_gtr` (2 hunks)
* `completions/gtr.bash` (1 hunks)
* `completions/gtr.fish` (2 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🪛 markdownlint-cli2 (0.18.1)</summary>

<details>
<summary>CLAUDE.md</summary>

207-207: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</details>

</details>
<details>
<summary>🪛 Shellcheck (0.11.0)</summary>

<details>
<summary>completions/gtr.bash</summary>

[warning] 12-12: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)

</details>

</details><details>
<summary>🔍 Remote MCP Context7, Exa, Linear</summary>

## Additional context gathered (concise, review-focused)

- Practical git-worktree usage and patterns (creates/removes worktrees, recommended workflows for reviewing PRs without stashing). Useful to verify gtr's worktree creation/capture changes and PATH-based editor-open behavior against common expectations for worktree tools.

- Related community projects and tooling (gwtm, gwt) that implement similar CLI wrappers for git worktree; helpful for UX/CLI-pattern comparisons (e.g., how they handle defaults, editor integration). Use this when reviewing CLI semantics, completions, and README examples.

- General git worktree tutorials and docs explaining add/remove/view semantics and cleanup considerations (prune, removing by path). Relevant to validating the PR change that now captures created worktree path and to ensure removal/prune flows remain correct.

- Linear documentation search returned general product docs (creating issues, parent/sub-issues, integrations) but no repository- or PR-specific Linear item was found. This indicates no discoverable Linear tickets linked to this PR in the workspace documentation; recommend checking the project’s Linear board directly if needed.

- Context7 library lookup failed due to an authorization error when attempting to resolve a library ID; I could not fetch Context7 docs. Please provide a valid Context7 API key or a direct Context7 library ID if you want documentation lookups (e.g., '/org/project' format).

Sources/tools used:
- Exa_web_search_exa (web searches for git-worktree, gwtm/gwt, tutorials) —
- Linear_search_documentation (broad Linear docs search) —
- Context7_resolve-library-id (attempt; returned auth error) —

</details>

</details>

<details>
<summary>🔇 Additional comments (11)</summary><blockquote>

<details>
<summary>completions/gtr.bash (1)</summary><blockquote>

`12-18`: **LGTM!**

The completion updates correctly reflect the command rename from `open` to `editor`. The changes are consistent with the pattern used in other completion files.

</blockquote></details>
<details>
<summary>completions/gtr.fish (1)</summary><blockquote>

`7-7`: **LGTM!**

The Fish completion correctly reflects the command rename from `open` to `editor`. Both the command definition and the branch completion helper are properly updated.




Also applies to: 55-55

</blockquote></details>
<details>
<summary>completions/_gtr (1)</summary><blockquote>

`10-10`: **LGTM!**

The Zsh completion correctly reflects the command rename from `open` to `editor`. The changes are consistent with the Bash and Fish completion updates.




Also applies to: 32-32

</blockquote></details>
<details>
<summary>README.md (1)</summary><blockquote>

`178-185`: **LGTM!**

The README updates are comprehensive and consistent:
- Command signature properly updated from `gtr open` to `gtr editor`
- Configuration examples correctly migrate from `git config --add` to `gtr config add`
- Configuration examples correctly migrate from `git config set` to `gtr config set`

These documentation changes align well with the functional updates in bin/gtr.




Also applies to: 327-374, 381-410

</blockquote></details>
<details>
<summary>bin/gtr (7)</summary><blockquote>

`46-47`: **LGTM!**

The command dispatcher correctly routes the new `editor` command to `cmd_editor`. The change maintains consistency with the existing case statement pattern.

---

`187-187`: **Good fix!**

Capturing the `worktree_path` from `create_worktree` is essential for the subsequent `copy_patterns` (line 199) and `run_hooks_in` (line 204) calls to work correctly. This addresses a critical issue where the worktree path was needed but not captured.

---

`335-391`: **LGTM!**

The function rename from `cmd_open` to `cmd_editor` correctly aligns with the new command name. The function logic remains unchanged, maintaining the same behavior.

---

`807-828`: **Approve with awareness of eval usage.**

The PATH-based fallback for editor adapters is well-implemented and provides excellent flexibility. The code correctly:
- Tries explicit adapters first
- Falls back to PATH-based commands
- Extracts the command name for validation
- Supports commands with arguments (e.g., "code --wait")

Note: The `eval` usage (lines 826-827) with user-provided editor names is acceptable here since the values come from git config (trusted source), but be mindful of this pattern if extending to untrusted input.

---

`835-856`: **LGTM!**

The PATH-based fallback for AI adapters follows the same pattern as the editor adapters and is well-implemented. The code correctly:
- Tries explicit adapters first
- Falls back to PATH-based commands
- Uses a subshell to change directory without affecting the current shell
- Supports commands with arguments

The consistency between editor and AI adapter loading is excellent.

---

`872-872`: **LGTM!**

The help text updates comprehensively document the changes:
- Command examples updated from `open` to `editor`
- Config action documentation includes the new `add` action with clear descriptions
- Note about PATH-based commands provides helpful guidance to users

The documentation is clear and consistent with the implemented functionality.




Also applies to: 898-898, 924-929, 936-936

---

`740-785`: **Code changes verified—no issues found.**

The `cfg_add` function is properly defined in `lib/config.sh` (lines 96-109) and correctly implements the add functionality for git config. The integration in `bin/gtr` is sound.

</blockquote></details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

…ool integration. Update README to reflect new configuration command options, including 'add'. Improve command handling for better compatibility with multi-word commands.
@helizaga helizaga merged commit ab4fde1 into main Nov 14, 2025
1 check passed
@helizaga helizaga deleted the tommy-fix branch November 14, 2025 00:42
NatoBoram pushed a commit that referenced this pull request Nov 14, 2025
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.

3 participants