@@ -319,23 +319,22 @@ umgpt_models_file_value() {
319319
320320umgpt_repository_default_model () {
321321 local scope=" $1 "
322- local key model
322+ local key
323323 [[ -f " $UMGPT_REPOSITORY_MODELS_FILE " ]] ||
324324 die " repository U-M GPT defaults not found: $UMGPT_REPOSITORY_MODELS_FILE "
325325 case " $scope " in
326326 openai-only) key=" umgpt" ;;
327327 low-sensitivity) key=" umgpt_low" ;;
328328 * ) die " unknown U-M GPT model scope: $scope " ;;
329329 esac
330- model=" $( umgpt_models_file_value " $UMGPT_REPOSITORY_MODELS_FILE " " $key " ) "
331- printf ' %s\n' " $model "
330+ umgpt_models_file_value " $UMGPT_REPOSITORY_MODELS_FILE " " $key "
332331}
333332
334333ensure_umgpt_models_file () {
335334 local openai_model low_model home candidate base_url
336335 if [[ ! -e " $UMGPT_MODELS_FILE " ]]; then
337- openai_model=" $( umgpt_repository_default_model " openai-only" ) "
338- low_model=" $( umgpt_repository_default_model " low-sensitivity" ) "
336+ openai_model=" $( umgpt_repository_default_model " openai-only" ) " || return
337+ low_model=" $( umgpt_repository_default_model " low-sensitivity" ) " || return
339338 home=" $( identity_home " umgpt" ) "
340339 if [[ -f " $home /config.toml" ]]; then
341340 candidate=" $( config_value " $home /config.toml" " model" ) "
@@ -362,15 +361,14 @@ ensure_umgpt_models_file() {
362361
363362umgpt_default_model () {
364363 local scope=" $1 "
365- local key model
366- ensure_umgpt_models_file
364+ local key
365+ ensure_umgpt_models_file || return
367366 case " $scope " in
368367 openai-only) key=" umgpt" ;;
369368 low-sensitivity) key=" umgpt_low" ;;
370369 * ) die " unknown U-M GPT model scope: $scope " ;;
371370 esac
372- model=" $( umgpt_models_file_value " $UMGPT_MODELS_FILE " " $key " ) "
373- printf ' %s\n' " $model "
371+ umgpt_models_file_value " $UMGPT_MODELS_FILE " " $key "
374372}
375373
376374replace_identity_model () {
@@ -624,6 +622,9 @@ create_umgpt() {
624622 fi
625623 local name=" ${2:- umgpt} "
626624 validate_umgpt_model " openai-only" " $model "
625+ if [[ " $name " == " umgpt" && " $explicit " -eq 1 && -e " $UMGPT_MODELS_FILE " ]]; then
626+ umgpt_models_file_value " $UMGPT_MODELS_FILE " umgpt > /dev/null || return
627+ fi
627628 create_api_identity \
628629 " $name " \
629630 " $UMGPT_BASE_URL " \
@@ -649,6 +650,9 @@ create_umgpt_low() {
649650 fi
650651 local name=" ${2:- umgpt-low} "
651652 validate_umgpt_model " low-sensitivity" " $model "
653+ if [[ " $name " == " umgpt-low" && " $explicit " -eq 1 && -e " $UMGPT_MODELS_FILE " ]]; then
654+ umgpt_models_file_value " $UMGPT_MODELS_FILE " umgpt_low > /dev/null || return
655+ fi
652656 create_api_identity \
653657 " $name " \
654658 " $UMGPT_BASE_URL " \
@@ -673,7 +677,8 @@ config_values() {
673677}
674678
675679config_value () {
676- config_values " $1 " " $2 " | head -n 1
680+ # Drain the producer so large configs cannot fail with SIGPIPE under pipefail.
681+ config_values " $1 " " $2 " | sed -n ' 1p'
677682}
678683
679684set_umgpt_scope () {
@@ -744,16 +749,18 @@ load_secret_env() {
744749fetch_model_ids () {
745750 local base_url=" $1 "
746751 local api_key=" $2 "
747- local url response ids status
752+ local url quoted_url quoted_header response ids status
748753
749754 command -v curl > /dev/null 2>&1 || die " curl is required for model discovery"
750755 command -v jq > /dev/null 2>&1 || die " jq is required for model discovery"
751756 url=" ${base_url%/ } /models"
757+ quoted_url=" $( curl_config_quote " $url " ) " || return
758+ quoted_header=" $( curl_config_quote " Authorization: Bearer $api_key " ) " || return
752759
753760 response=" $(
754761 {
755- printf ' url = %s\n' " $( curl_config_quote " $url " ) "
756- printf ' header = %s\n' " $( curl_config_quote " Authorization: Bearer $api_key " ) "
762+ printf ' url = %s\n' " $quoted_url "
763+ printf ' header = %s\n' " $quoted_header "
757764 printf ' %s\n' ' silent' ' show-error' ' fail-with-body'
758765 } | curl --config -
759766 ) " || {
@@ -1822,8 +1829,8 @@ ensure_macos_vscode_open_with() (
18221829 local plist_buddy=" /usr/libexec/PlistBuddy"
18231830 local runtime_app=" $home /vscode-editor/VS Code - $name .app"
18241831 [[ " ${CODEX_MACOS_SKIP_REGISTER:- 0} " != " 1" ]] || return 0
1825- app_dir =" $HOME /Applications "
1826- app =" $( macos_vscode_open_with_path " $name " ) "
1832+ app =" $( macos_vscode_open_with_path " $name " ) " || die " could not determine the VS Code Finder app path "
1833+ app_dir =" $( dirname " $app " ) "
18271834 source=" $SCRIPT_DIR /VSCodeIdentity.applescript"
18281835 [[ -f " $source " ]] || source=" $REPOSITORY_ROOT /macos/VSCodeIdentity.applescript"
18291836 [[ -f " $source " ]] || die " missing the VS Code Finder handler source"
@@ -1832,7 +1839,7 @@ ensure_macos_vscode_open_with() (
18321839 [[ -x /usr/bin/codesign && -x " $plist_buddy " ]] || die " required macOS application tools were not found"
18331840 [[ ! -L " $app_dir " ]] || die " refusing a symbolic link at $app_dir "
18341841 mkdir -p " $app_dir " || die " could not create $app_dir "
1835- app_dir=" $( cd " $app_dir " && pwd -P) "
1842+ app_dir=" $( cd " $app_dir " && pwd -P) " || die " could not open $app_dir "
18361843 app=" $app_dir /VS Code - $name .app"
18371844 [[ ! -L " $app " ]] || die " refusing a symbolic link at $app "
18381845 metadata=" $( shasum -a 256 " $source " " $SCRIPT_DIR /$( basename " ${BASH_SOURCE[0]} " ) " " $SCRIPT_DIR /../config/umgpt-models.toml" ) " || return 1
@@ -1850,40 +1857,52 @@ ensure_macos_vscode_open_with() (
18501857 build=" $( mktemp -d " $app_dir /.vscode-open-with.XXXXXX" ) " || die " could not stage the VS Code Finder app"
18511858 cleanup_vscode_open_with () {
18521859 local status=$?
1853- if [[ " $status " -ne 0 && -d " $build /previous.app" && ! -e " $app " ]]; then
1860+ if [[ " $status " -ne 0 && -d " $build /previous.app" && ! -e " $app " && ! -L " $app " ]]; then
18541861 mv " $build /previous.app" " $app " || true
18551862 fi
1856- rm -rf -- " $build "
1863+ if [[ " $status " -ne 0 && -e " $build /previous.app" ]]; then
1864+ printf ' Previous Finder app preserved at %s; restore it to %s after resolving the installation failure.\n' \
1865+ " $build /previous.app" " $app " >&2
1866+ else
1867+ rm -rf -- " $build "
1868+ fi
18571869 return " $status "
18581870 }
1859- trap cleanup_vscode_open_with EXIT HUP INT TERM
1871+ trap cleanup_vscode_open_with EXIT
1872+ trap ' exit 129' HUP
1873+ trap ' exit 130' INT
1874+ trap ' exit 143' TERM
18601875 candidate=" $build /VS Code - $name .app"
18611876 osacompile -o " $candidate " " $source " || die " could not compile the VS Code Finder app"
1862- mkdir -p " $candidate /Contents/config"
1863- cp " $SCRIPT_DIR /$( basename " ${BASH_SOURCE[0]} " ) " " $candidate /Contents/Resources/codex-home"
1864- cp " $SCRIPT_DIR /VSCodeIdentity.applescript" " $candidate /Contents/Resources/VSCodeIdentity.applescript" 2> /dev/null || \
1865- cp " $REPOSITORY_ROOT /macos/VSCodeIdentity.applescript" " $candidate /Contents/Resources/VSCodeIdentity.applescript"
1866- cp " $SCRIPT_DIR /../config/umgpt-models.toml" " $candidate /Contents/config/umgpt-models.toml"
1867- printf ' %s\n' " $name " > " $candidate /Contents/Resources/identity"
1868- printf ' %s\n' " $metadata " > " $candidate /Contents/Resources/codex-contexts-open-with"
1877+ # Callers may handle failure with ||, which disables Bash's errexit here.
1878+ mkdir -p " $candidate /Contents/config" || die " could not create the Finder app config directory"
1879+ cp " $SCRIPT_DIR /$( basename " ${BASH_SOURCE[0]} " ) " " $candidate /Contents/Resources/codex-home" ||
1880+ die " could not bundle the Finder app helper"
1881+ cp " $source " " $candidate /Contents/Resources/VSCodeIdentity.applescript" ||
1882+ die " could not bundle the Finder handler source"
1883+ cp " $SCRIPT_DIR /../config/umgpt-models.toml" " $candidate /Contents/config/umgpt-models.toml" ||
1884+ die " could not bundle the U-M GPT model defaults"
1885+ printf ' %s\n' " $name " > " $candidate /Contents/Resources/identity" || die " could not record the Finder app identity"
1886+ printf ' %s\n' " $metadata " > " $candidate /Contents/Resources/codex-contexts-open-with" ||
1887+ die " could not record the Finder app ownership marker"
18691888 info_plist=" $candidate /Contents/Info.plist"
18701889 " $plist_buddy " -c ' Delete :CFBundleIdentifier' " $info_plist " > /dev/null 2>&1 || true
1871- " $plist_buddy " -c " Add :CFBundleIdentifier string org.codex-contexts.vscode.$name " " $info_plist "
1890+ " $plist_buddy " -c " Add :CFBundleIdentifier string org.codex-contexts.vscode.$name " " $info_plist " || die " could not configure the Finder app identifier "
18721891 " $plist_buddy " -c ' Delete :CFBundleName' " $info_plist " > /dev/null 2>&1 || true
1873- " $plist_buddy " -c " Add :CFBundleName string VS Code - $name " " $info_plist "
1892+ " $plist_buddy " -c " Add :CFBundleName string VS Code - $name " " $info_plist " || die " could not configure the Finder app name "
18741893 " $plist_buddy " -c ' Delete :CFBundleDisplayName' " $info_plist " > /dev/null 2>&1 || true
1875- " $plist_buddy " -c " Add :CFBundleDisplayName string VS Code - $name " " $info_plist "
1894+ " $plist_buddy " -c " Add :CFBundleDisplayName string VS Code - $name " " $info_plist " || die " could not configure the Finder app display name "
18761895 " $plist_buddy " -c ' Delete :LSUIElement' " $info_plist " > /dev/null 2>&1 || true
1877- " $plist_buddy " -c ' Add :LSUIElement bool true' " $info_plist "
1896+ " $plist_buddy " -c ' Add :LSUIElement bool true' " $info_plist " || die " could not configure the Finder app UI behavior "
18781897 " $plist_buddy " -c ' Delete :CFBundleDocumentTypes' " $info_plist " > /dev/null 2>&1 || true
1879- " $plist_buddy " -c ' Add :CFBundleDocumentTypes array' " $info_plist "
1880- " $plist_buddy " -c ' Add :CFBundleDocumentTypes:0 dict' " $info_plist "
1881- " $plist_buddy " -c ' Add :CFBundleDocumentTypes:0:CFBundleTypeName string Folder' " $info_plist "
1882- " $plist_buddy " -c ' Add :CFBundleDocumentTypes:0:CFBundleTypeRole string Editor' " $info_plist "
1883- " $plist_buddy " -c ' Add :CFBundleDocumentTypes:0:LSHandlerRank string Alternate' " $info_plist "
1884- " $plist_buddy " -c ' Add :CFBundleDocumentTypes:0:LSItemContentTypes array' " $info_plist "
1885- " $plist_buddy " -c ' Add :CFBundleDocumentTypes:0:LSItemContentTypes:0 string public.folder' " $info_plist "
1886- chmod 700 " $candidate /Contents/Resources/codex-home"
1898+ " $plist_buddy " -c ' Add :CFBundleDocumentTypes array' " $info_plist " || die " could not configure Finder document types "
1899+ " $plist_buddy " -c ' Add :CFBundleDocumentTypes:0 dict' " $info_plist " || die " could not configure the Finder folder handler "
1900+ " $plist_buddy " -c ' Add :CFBundleDocumentTypes:0:CFBundleTypeName string Folder' " $info_plist " || die " could not configure the Finder folder type "
1901+ " $plist_buddy " -c ' Add :CFBundleDocumentTypes:0:CFBundleTypeRole string Editor' " $info_plist " || die " could not configure the Finder folder role "
1902+ " $plist_buddy " -c ' Add :CFBundleDocumentTypes:0:LSHandlerRank string Alternate' " $info_plist " || die " could not configure the Finder handler rank "
1903+ " $plist_buddy " -c ' Add :CFBundleDocumentTypes:0:LSItemContentTypes array' " $info_plist " || die " could not configure Finder content types "
1904+ " $plist_buddy " -c ' Add :CFBundleDocumentTypes:0:LSItemContentTypes:0 string public.folder' " $info_plist " || die " could not configure the Finder folder content type "
1905+ chmod 700 " $candidate /Contents/Resources/codex-home" || die " could not make the Finder app helper executable "
18871906 /usr/bin/codesign --force --deep --sign - " $candidate " > /dev/null || die " could not sign the VS Code Finder app"
18881907 macos_vscode_unregister_editor " $runtime_app "
18891908 if [[ -e " $app " ]]; then mv " $app " " $build /previous.app" || die " could not stage the old VS Code Finder app" ; fi
0 commit comments