Skip to content

fix: replace dirname with POSIX parameter expansion in issue-sync scripts#2607

Closed
marcusquinn wants to merge 1 commit intomainfrom
bugfix/dirname-posix-fix
Closed

fix: replace dirname with POSIX parameter expansion in issue-sync scripts#2607
marcusquinn wants to merge 1 commit intomainfrom
bugfix/dirname-posix-fix

Conversation

@marcusquinn
Copy link
Copy Markdown
Owner

@marcusquinn marcusquinn commented Feb 28, 2026

Summary

  • Replace $(dirname "${BASH_SOURCE[0]}") with ${BASH_SOURCE[0]%/*} in issue-sync-helper.sh (line 21) and issue-sync-lib.sh (line 31)
  • The dirname command is an external binary not available in stripped PATH environments (e.g., Claude Code MCP pulse sessions), causing all TODO-to-GitHub issue syncs to fail silently across all 6 pulse-enabled repos
  • The %/* parameter expansion is a bash builtin that performs identical directory extraction without requiring any external command

Verification

Tested with PATH="" — old version fails at line 21 with dirname: No such file or directory, new version passes through successfully. ShellCheck clean (zero new warnings).

Note

~200 other scripts in .agents/scripts/ use the same dirname pattern. This PR fixes only the two scripts in the critical pulse path. A follow-up issue should address the systemic pattern across all scripts.

Closes #2605

Summary by CodeRabbit

  • Chores
    • Improved internal script execution path resolution for build and synchronization utilities.

…ipts

Replace $(dirname "${BASH_SOURCE[0]}") with ${BASH_SOURCE[0]%/*} in
issue-sync-helper.sh and issue-sync-lib.sh. The dirname command is not
available in stripped PATH environments (e.g., Claude Code MCP pulse
sessions), causing all TODO-to-GitHub issue syncs to fail silently.

The %/* parameter expansion is a bash builtin that performs the same
directory extraction without requiring an external command in PATH.

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 enhances the reliability of the issue synchronization scripts by refactoring how script directories are determined. By replacing an external command with a native bash parameter expansion, the scripts are now resilient to environments with restricted PATH variables, ensuring consistent operation and preventing silent failures in critical automated workflows.

Highlights

  • Script Directory Resolution: Replaced the external dirname command with the POSIX parameter expansion ${BASH_SOURCE[0]%/*} in issue-sync-helper.sh and issue-sync-lib.sh.
  • Environment Robustness: This change prevents script failures in stripped PATH environments, such as Claude Code MCP pulse sessions, where the dirname binary might be unavailable.
  • Performance and Reliability: Utilized a bash builtin for directory extraction, which is more robust and efficient than relying on an external command.
Changelog
  • .agents/scripts/issue-sync-helper.sh
    • Replaced $(dirname "${BASH_SOURCE[0]}") with ${BASH_SOURCE[0]%/*} for SCRIPT_DIR assignment.
  • .agents/scripts/issue-sync-lib.sh
    • Replaced $(dirname "${BASH_SOURCE[0]}") with ${BASH_SOURCE[0]%/*} for SCRIPT_DIR assignment within the if [[ -z "${SCRIPT_DIR:-}" ]]; then block.
Activity
  • No human activity has occurred on 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 70d0bce.

📒 Files selected for processing (2)
  • .agents/scripts/issue-sync-helper.sh
  • .agents/scripts/issue-sync-lib.sh

Walkthrough

Fixed two bash scripts that fail in stripped PATH environments by replacing dirname command calls with POSIX-compatible parameter expansion ${BASH_SOURCE[0]%/*} to resolve script directory paths without external dependencies.

Changes

Cohort / File(s) Summary
Shell Script Path Resolution
.agents/scripts/issue-sync-helper.sh, .agents/scripts/issue-sync-lib.sh
Replaced dirname invocation with parameter expansion for SCRIPT_DIR calculation. Eliminates dependency on external command in PATH-restricted environments (e.g., Claude Code MCP contexts).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Possibly related PRs

Poem

\🔧 No more dirname, stripped PATH can't win,
Parameter expansion takes us in,
POSIX-pure and lean and tight,
Pulse syncs flow—pulse cycles light! 🚀

✨ 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-posix-fix

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

Closing as duplicate of #2608, which fixes the same issue but also covers session-miner-pulse.sh (3 files vs 2). Superseded by #2608.

@alex-solovyev
Copy link
Copy Markdown
Collaborator

Duplicate of #2608 — closing in favour of the more complete fix.

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 replaces the external dirname command with the more robust and performant POSIX parameter expansion ${BASH_SOURCE[0]%/*}. This is a great improvement, especially for environments with a minimal PATH. However, the current implementation is not a direct equivalent of dirname and introduces a regression in an edge case: when a script is executed from within its own directory without a path prefix. In this scenario, the parameter expansion returns the script name itself, causing the cd command to fail. I've provided suggestions to make the implementation fully robust and handle this case 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.

high

While using parameter expansion is a great improvement for performance and robustness in minimal environments, this specific implementation isn't a fully equivalent replacement for dirname. It introduces a failure case when the script is executed from its own directory without a path prefix (e.g., cd .agents/scripts && ./issue-sync-helper.sh would work, but issue-sync-helper.sh would fail if it's in the PATH and called from within its directory).

If ${BASH_SOURCE[0]} contains no slashes (e.g., just issue-sync-helper.sh), the expansion ${BASH_SOURCE[0]%/*} returns the script name itself. cding to a file will fail. dirname correctly returns . in this case.

To make this more robust and handle all invocation scenarios correctly, you could add a check for this edge case.

Suggested change
SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)" || exit
SCRIPT_DIR="$(cd "$( [[ "${BASH_SOURCE[0]}" == */* ]] && echo "${BASH_SOURCE[0]%/*}" || echo "." )" && 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.

high

Similar to the other file, this change introduces a regression. While using parameter expansion is a great improvement, this specific implementation isn't a fully equivalent replacement for dirname. It introduces a failure case when the script is sourced from its own directory without a path prefix.

If ${BASH_SOURCE[0]} contains no slashes (e.g., just issue-sync-lib.sh), the expansion ${BASH_SOURCE[0]%/*} returns the script name itself. cding to a file will fail. dirname correctly returns . in this case.

To make this more robust and handle all invocation scenarios correctly, you could add a check for this edge case.

Suggested change
SCRIPT_DIR="$(cd "${BASH_SOURCE[0]%/*}" && pwd)"
SCRIPT_DIR="$(cd "$( [[ "${BASH_SOURCE[0]}" == */* ]] && echo "${BASH_SOURCE[0]%/*}" || echo "." )" && pwd)"

@marcusquinn marcusquinn deleted the bugfix/dirname-posix-fix 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

2 participants