Skip to content

Commit be199c3

Browse files
Tighten agy launcher edge cases
1 parent 3fe56b4 commit be199c3

4 files changed

Lines changed: 40 additions & 32 deletions

File tree

scripts/generated/internal_checksums.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
declare -gA ACFS_INTERNAL_CHECKSUMS=(
1111
[scripts/lib/security.sh]="95366fc1c2497ff0e36a1f59f34621fdcec06f4da0ed439828ad601a626f4f75"
1212
[scripts/lib/agents.sh]="a6485afa0cf17d636ad7f049796a23821fb9c5dbf3640ec42ee9b1bb0a8628b4"
13-
[scripts/lib/update.sh]="2ae92228e90810354ad392d8d5763b1ef14686ea61a95d63e0304eed5060c418"
13+
[scripts/lib/update.sh]="b693b08ec49e822dcb540e94f8e8c6c6616ce79f31ac95d95cebcc4125d773d8"
1414
[scripts/lib/doctor.sh]="0bb0626aba495c6688c2880db3306ff9a7f9b803d6ebf9d8ff8ddcc931e4ea79"
1515
[scripts/lib/doctor_fix.sh]="31a44ab36fe980d5c41edc6d25d88280f6d8d6bd1abc40ecac1a8e3e74bb864c"
1616
[scripts/lib/offline_artifact_pack.sh]="5f6fa7e5a9e115904656a627853b2c7d556183532a3d8fd42a0363bf3570c7eb"

scripts/lib/agy_locked.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -191,40 +191,40 @@ def command_parts(tokens):
191191
def env_invokes_dcg(tokens, depth):
192192
index = 0
193193
while index < len(tokens):
194-
token = tokens[index]
195-
if token == "--":
194+
arg = tokens[index]
195+
if arg in {"--"}:
196196
index += 1
197197
break
198-
if is_assignment(token):
198+
if is_assignment(arg):
199199
index += 1
200200
continue
201-
if token in {"-i", "-0", "--ignore-environment", "--null"}:
201+
if arg in {"-i", "-0", "--ignore-environment", "--null"}:
202202
index += 1
203203
continue
204-
if token in {"-u", "--unset", "-C", "--chdir"}:
204+
if arg in {"-u", "--unset", "-C", "--chdir"}:
205205
index += 2
206206
continue
207-
if token in {"-S", "--split-string"}:
207+
if arg in {"-S", "--split-string"}:
208208
if index + 1 >= len(tokens):
209209
return False
210210
try:
211211
split_tokens = shlex.split(tokens[index + 1])
212212
except ValueError:
213213
return False
214214
return tokens_invoke_dcg(split_tokens, depth)
215-
if token.startswith("-u") and len(token) > 2:
215+
if arg.startswith("-u") and len(arg) > 2:
216216
index += 1
217217
continue
218-
if token.startswith("--split-string="):
218+
if arg.startswith("--split-string="):
219219
try:
220-
split_tokens = shlex.split(token.partition("=")[2])
220+
split_tokens = shlex.split(arg.partition("=")[2])
221221
except ValueError:
222222
return False
223223
return tokens_invoke_dcg(split_tokens, depth)
224-
if token.startswith("--unset=") or token.startswith("--chdir="):
224+
if arg.startswith("--unset=") or arg.startswith("--chdir="):
225225
index += 1
226226
continue
227-
if token.startswith("-"):
227+
if arg.startswith("-"):
228228
return False
229229
break
230230
return tokens_invoke_dcg(tokens[index:], depth) if index < len(tokens) else False
@@ -233,17 +233,17 @@ def env_invokes_dcg(tokens, depth):
233233
def shell_invokes_dcg(tokens, depth):
234234
index = 0
235235
while index < len(tokens):
236-
token = tokens[index]
237-
if token == "-c" or (token.startswith("-") and "c" in token[1:]):
236+
arg = tokens[index]
237+
if arg.startswith("-") and "c" in arg[1:]:
238238
if index + 1 >= len(tokens):
239239
return False
240240
try:
241-
script_tokens = shlex.split(tokens[index + 1])
241+
script_args = shlex.split(tokens[index + 1])
242242
except ValueError:
243243
return False
244-
if script_tokens and script_tokens[0] == "exec":
245-
script_tokens = script_tokens[1:]
246-
return tokens_invoke_dcg(script_tokens, depth)
244+
if script_args and script_args[0] == "exec":
245+
script_args = script_args[1:]
246+
return tokens_invoke_dcg(script_args, depth)
247247
index += 1
248248
return False
249249

@@ -265,8 +265,8 @@ def tokens_invoke_dcg(tokens, depth=0):
265265
return shell_invokes_dcg(remaining, depth + 1)
266266
if executable.startswith("python"):
267267
return any(
268-
pathlib.Path(os.path.expanduser(token)).name == "dcg-antigravity-hook.py"
269-
for token in remaining
268+
pathlib.Path(os.path.expanduser(arg)).name == "dcg-antigravity-hook.py"
269+
for arg in remaining
270270
)
271271
return False
272272

@@ -376,21 +376,21 @@ def filtered_args(argv):
376376

377377

378378
def run_real_agy(args):
379-
proc = subprocess.Popen(args)
380-
previous_handlers = {}
381-
for sig in (signal.SIGINT, signal.SIGQUIT):
382-
previous_handlers[sig] = signal.getsignal(sig)
383-
signal.signal(sig, signal.SIG_IGN)
384-
try:
385-
status = proc.wait()
386-
finally:
387-
for sig, handler in previous_handlers.items():
388-
signal.signal(sig, handler)
379+
with subprocess.Popen(args) as proc:
380+
previous_handlers = {}
381+
for sig in (signal.SIGINT, signal.SIGQUIT):
382+
previous_handlers[sig] = signal.getsignal(sig)
383+
signal.signal(sig, signal.SIG_IGN)
384+
try:
385+
status = proc.wait()
386+
finally:
387+
for sig, handler in previous_handlers.items():
388+
signal.signal(sig, handler)
389389
return 128 - status if status < 0 else status
390390

391391

392392
def main():
393-
if PRIME_SETTINGS_FLAG in sys.argv[1:]:
393+
if sys.argv[1:] == [PRIME_SETTINGS_FLAG]:
394394
ensure_settings()
395395
ensure_dcg_hook()
396396
return 0

scripts/lib/update.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5116,7 +5116,11 @@ update_agents() {
51165116
local bun_bin=""
51175117
bun_bin="$(update_binary_path bun 2>/dev/null || true)"
51185118
if [[ -z "$bun_bin" ]]; then
5119-
log_item "fail" "Bun not installed" "required for Codex updates"
5119+
if update_binary_exists codex || [[ "$FORCE_MODE" == "true" ]]; then
5120+
log_item "fail" "Bun not installed" "required for Codex updates"
5121+
else
5122+
log_item "skip" "Bun" "not installed; Codex CLI not installed"
5123+
fi
51205124
fi
51215125

51225126
# Codex CLI via bun (--trust allows postinstall scripts)

tests/unit/test_agy_install.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ check "agy locked launcher installs dcg hook support" \
6262
"grep -q 'dcg-antigravity-hook.py' scripts/lib/agy_locked.py"
6363
check "agy locked launcher supports installer priming" \
6464
"grep -q -- '--acfs-prime-settings' scripts/lib/agy_locked.py"
65+
check "agy locked launcher only treats priming as an exact invocation" \
66+
"grep -Fq 'sys.argv[1:] == [PRIME_SETTINGS_FLAG]' scripts/lib/agy_locked.py"
6567
check "agy locked launcher is valid Python" \
6668
"python3 -m py_compile scripts/lib/agy_locked.py"
69+
check "agents-only update does not fail on missing Bun when Codex is absent" \
70+
"grep -q 'not installed; Codex CLI not installed' scripts/lib/update.sh"
6771
check "doctor checks for the agy alias" \
6872
"grep -q 'agent.alias.agy' scripts/lib/doctor.sh"
6973

0 commit comments

Comments
 (0)