Skip to content

fix: replace dirname with parameter expansion for stripped PATH compatibility#2608

Closed
alex-solovyev wants to merge 1 commit intomainfrom
bugfix/dirname-stripped-path
Closed

fix: replace dirname with parameter expansion for stripped PATH compatibility#2608
alex-solovyev wants to merge 1 commit intomainfrom
bugfix/dirname-stripped-path

Conversation

@alex-solovyev
Copy link
Copy Markdown
Collaborator

@alex-solovyev alex-solovyev commented Feb 28, 2026

Summary

  • Replaces dirname (external command) with ${BASH_SOURCE[0]%/*} (bash parameter expansion) in 3 scripts
  • dirname is not available in stripped PATH environments (e.g., pulse sessions via Claude Code MCP)
  • This caused all pulse TODO syncs to fail silently — no tasks were synced to GitHub issues

Files Changed

  • .agents/scripts/issue-sync-helper.sh line 21
  • .agents/scripts/issue-sync-lib.sh line 31
  • .agents/scripts/session-miner-pulse.sh line 22

Verification

env -i HOME="$HOME" PATH="/usr/bin:/bin" bash issue-sync-helper.sh --help
# Output: Issue Sync Helper — stateless TODO.md <-> GitHub Issues sync via gh CLI.

Closes #2605

Summary by CodeRabbit

  • Chores
    • Optimized internal build and deployment scripts for improved portability and efficiency. No user-facing changes.

…tibility

dirname is an external command not available in stripped PATH environments
(e.g., pulse sessions via Claude Code MCP). Replace with ${BASH_SOURCE[0]%/*}
which is a bash builtin parameter expansion requiring no external commands.

Fixes: issue-sync-helper.sh, issue-sync-lib.sh, session-miner-pulse.sh
Closes #2605
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical compatibility issue in shell scripts that prevented proper execution in environments with stripped PATH variables. By replacing the external dirname command with a robust bash parameter expansion, the changes ensure that scripts can reliably determine their directory, thereby resolving silent failures in pulse TODO synchronization and improving overall script resilience.

Highlights

  • Replaced dirname command: Replaced the external dirname command with bash parameter expansion (${BASH_SOURCE[0]%/*}) in three shell scripts.
  • Improved PATH compatibility: Ensured compatibility with stripped PATH environments where dirname might be unavailable, such as in pulse sessions via Claude Code MCP.
  • Fixed silent failures: Resolved an issue where pulse TODO syncs were silently failing, preventing tasks from being synced to GitHub issues.
Changelog
  • .agents/scripts/issue-sync-helper.sh
    • Replaced dirname command with bash parameter expansion for SCRIPT_DIR assignment.
  • .agents/scripts/issue-sync-lib.sh
    • Updated SCRIPT_DIR assignment to use bash parameter expansion instead of dirname.
  • .agents/scripts/session-miner-pulse.sh
    • Modified SCRIPT_DIR calculation to use bash parameter expansion, removing the dependency on dirname.
Activity
  • No specific human activity (comments, reviews) has been provided for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 28, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3dd5b1e and 14561d2.

📒 Files selected for processing (3)
  • .agents/scripts/issue-sync-helper.sh
  • .agents/scripts/issue-sync-lib.sh
  • .agents/scripts/session-miner-pulse.sh

Walkthrough

Three shell scripts replace dirname invocations with POSIX-compatible parameter expansion to resolve script directories. This eliminates dependency on the dirname command, enabling execution in stripped-PATH environments where external utilities are unavailable.

Changes

Cohort / File(s) Summary
POSIX Path Resolution
.agents/scripts/issue-sync-helper.sh, .agents/scripts/issue-sync-lib.sh, .agents/scripts/session-miner-pulse.sh
Replaced dirname calls with parameter expansion ${BASH_SOURCE[0]%/*} for SCRIPT_DIR computation, removing external command dependency and improving portability in stripped-PATH environments.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

🔧 When dirname went missing in the stripped-down night,
Parameter expansion stepped in—POSIX-clean and tight.
Three scripts now whisper their paths without a call,
Silent, portable, and bulletproof through it all. ✨

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/dirname-stripped-path

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.

@alex-solovyev
Copy link
Copy Markdown
Collaborator Author

Closing — the issue-sync-helper.sh and issue-sync-lib.sh fixes were already delivered via #2603 (merged into main) using a different approach. This PR has merge conflicts as a result. The session-miner-pulse.sh fix is still needed and will be addressed in a separate targeted PR.

@alex-solovyev
Copy link
Copy Markdown
Collaborator Author

Superseded by #2603 for the issue-sync scripts. Merge conflict prevents merging. Will create a targeted fix for session-miner-pulse.sh separately.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request aims to improve script portability by replacing the external dirname command with bash parameter expansion. This is a good improvement for compatibility with environments that have a stripped PATH. However, the current implementation has a flaw where it can fail if scripts are invoked without a path prefix. I've provided critical feedback with suggestions to make the implementation more robust and handle all invocation scenarios correctly.

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit
SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)" || exit
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The parameter expansion ${BASH_SOURCE[0]%/*} can be problematic. If the script is invoked from the PATH without a directory prefix (e.g., myscript.sh instead of ./myscript.sh), this expansion results in the script's filename itself. The subsequent cd command will then fail because it's a file, not a directory.

A more robust approach is to check if the expansion modified the string and fall back to . if it didn't, which correctly handles all invocation scenarios.

Suggested change
SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)" || exit
dir="${BASH_SOURCE[0]%/*}"
if [[ "$dir" == "${BASH_SOURCE[0]}" ]]; then
dir="."
fi
SCRIPT_DIR="$(cd "$dir" && pwd)" || exit

# Resolves SCRIPT_DIR from BASH_SOURCE so it works when sourced from any location.
if [[ -z "${SCRIPT_DIR:-}" ]]; then
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The parameter expansion ${BASH_SOURCE[0]%/*} can be problematic. If the script is invoked from the PATH without a directory prefix (e.g., myscript.sh instead of ./myscript.sh), this expansion results in the script's filename itself. The subsequent cd command will then fail because it's a file, not a directory.

A more robust approach is to check if the expansion modified the string and fall back to . if it didn't, which correctly handles all invocation scenarios.

Suggested change
SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)"
dir="${BASH_SOURCE[0]%/*}"
if [[ "$dir" == "${BASH_SOURCE[0]}" ]]; then
dir="."
fi
SCRIPT_DIR="$(cd "$dir" && pwd)"

# --- Configuration ---

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The parameter expansion ${BASH_SOURCE[0]%/*} can be problematic. If the script is invoked from the PATH without a directory prefix (e.g., myscript.sh instead of ./myscript.sh), this expansion results in the script's filename itself. The subsequent cd command will then fail because it's a file, not a directory.

A more robust approach is to check if the expansion modified the string and fall back to . if it didn't, which correctly handles all invocation scenarios.

Suggested change
SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)"
dir="${BASH_SOURCE[0]%/*}"
if [[ "$dir" == "${BASH_SOURCE[0]}" ]]; then
dir="."
fi
SCRIPT_DIR="$(cd "$dir" && pwd)"

@marcusquinn marcusquinn deleted the bugfix/dirname-stripped-path branch March 3, 2026 03:23
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.

fix: issue-sync-helper.sh fails with 'dirname: command not found' in stripped PATH environments

1 participant