Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .agents/scripts/issue-sync-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

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

source "${SCRIPT_DIR}/shared-constants.sh"
# shellcheck source=issue-sync-lib.sh
source "${SCRIPT_DIR}/issue-sync-lib.sh"
Expand Down
2 changes: 1 addition & 1 deletion .agents/scripts/issue-sync-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ _ISSUE_SYNC_LIB_LOADED=1
# Source shared-constants.sh to make the library self-contained.
# 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)"

fi
source "${SCRIPT_DIR}/shared-constants.sh"

Expand Down