Skip to content

Commit db9fb09

Browse files
fix(scripts): track agent file existence before update and avoid top-level globals
- _update_if_new now records the path and sets _found_agent before calling update_agent_file, so that failures do not cause duplicate attempts on aliased paths (AMP/KIRO/BOB -> AGENTS_FILE) or false "no agent files found" fallback triggers - Remove top-level initialisation of _updated_paths and _found_agent; they are now created exclusively inside update_all_existing_agents, keeping the script side-effect free when sourced
1 parent 7601f7b commit db9fb09

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎scripts/bash/update-agent-context.sh‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -690,13 +690,10 @@ update_specific_agent() {
690690
# realpath so that variables pointing to the same file — e.g. AMP_FILE,
691691
# KIRO_FILE, BOB_FILE all resolving to AGENTS_FILE — are only written once).
692692
# Uses a linear array instead of associative array for bash 3.2 compatibility.
693-
# Note: defined at top level because bash does not support true nested/local
694-
# functions. _updated_paths and _found_agent are reset at the start of each
695-
# update_all_existing_agents call.
696-
_updated_paths=()
697-
_found_agent=false
698-
# Note: both variables are reset at the start of update_all_existing_agents;
699-
# do not rely on these top-level values outside that function.
693+
# Note: defined at top level because bash 3.2 does not support true
694+
# nested/local functions. _updated_paths, _found_agent, and _all_ok are
695+
# initialised exclusively inside update_all_existing_agents so that
696+
# sourcing this script has no side effects on the caller's environment.
700697

701698
_update_if_new() {
702699
local file="$1" name="$2"
@@ -709,9 +706,12 @@ _update_if_new() {
709706
[[ "$p" == "$real_path" ]] && return 0
710707
done
711708
fi
712-
update_agent_file "$file" "$name" || return 1
709+
# Record the file as seen before attempting the update so that:
710+
# (a) aliases pointing to the same path are not retried on failure
711+
# (b) _found_agent reflects file existence, not update success
713712
_updated_paths+=("$real_path")
714713
_found_agent=true
714+
update_agent_file "$file" "$name"
715715
}
716716

717717
update_all_existing_agents() {

0 commit comments

Comments
 (0)