Skip to content

fix: make ypi launcher work on macOS bash 3.2#3

Open
BleedingDev wants to merge 1 commit into
rawwerks:masterfrom
BleedingDev:fix/macos-bash32-launcher
Open

fix: make ypi launcher work on macOS bash 3.2#3
BleedingDev wants to merge 1 commit into
rawwerks:masterfrom
BleedingDev:fix/macos-bash32-launcher

Conversation

@BleedingDev

Copy link
Copy Markdown

Summary

Fixes macOS startup failures in the ypi launcher by addressing two shell-compatibility issues:

  1. set -u + empty array expansion on Bash 3.2 (PASS_ARGS[@]: unbound variable)
  2. Non-portable mktemp template usage on BSD/macOS

Changes

  • Use portable temp-file template:
    • mktemp "${TMPDIR:-/tmp}/ypi_system_prompt.XXXXXX"
  • Build pi argv incrementally and only append optional arrays when non-empty:
    • avoids "${empty_array[@]}" nounset crash on macOS system Bash 3.2
  • Add unit regression test in tests/test_unit.sh:
    • invokes ypi with no pass-through args and asserts it reaches mock pi

Repro verified

On macOS with /bin/bash 3.2:

  • ypi no longer crashes with PASS_ARGS[@]: unbound variable
  • repeated ypi invocations no longer fail with mktemp ... File exists

Related issues

@csaroff csaroff left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Real human here:

I can confirm that your fixes worked for me, but I think you could make it slightly more concise :)

Comment thread ypi
Comment on lines +119 to +128
# Bash 3.2 (macOS) + `set -u` treats `${empty_array[@]}` as unbound.
# Build argv incrementally so zero-length arrays stay zero-arg.
PI_ARGS=(pi --system-prompt "$COMBINED_PROMPT")
if [ ${#YPI_EXT_ARGS[@]} -gt 0 ]; then
PI_ARGS+=("${YPI_EXT_ARGS[@]}")
fi
if [ ${#PASS_ARGS[@]} -gt 0 ]; then
PI_ARGS+=("${PASS_ARGS[@]}")
fi
exec "${PI_ARGS[@]}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
# Bash 3.2 (macOS) + `set -u` treats `${empty_array[@]}` as unbound.
# Build argv incrementally so zero-length arrays stay zero-arg.
PI_ARGS=(pi --system-prompt "$COMBINED_PROMPT")
if [ ${#YPI_EXT_ARGS[@]} -gt 0 ]; then
PI_ARGS+=("${YPI_EXT_ARGS[@]}")
fi
if [ ${#PASS_ARGS[@]} -gt 0 ]; then
PI_ARGS+=("${PASS_ARGS[@]}")
fi
exec "${PI_ARGS[@]}"
exec pi --system-prompt "$COMBINED_PROMPT" "${YPI_EXT_ARGS[@]:-}" "${PASS_ARGS[@]:-}"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'll leave that to real maintainer of the codebase. :) My goal was to just show possible fix. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants