@amsterdamdatalabs/adl-agent-control-darwin-arm64 0.1.54 → 0.1.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/bin/adl +2 -2
  2. package/bin/git-defaults +4 -1
  3. package/bin/job-watchdog +119 -0
  4. package/bin/reconcile +91 -24
  5. package/bin/reconcile-host +10 -1
  6. package/bin/repo-search-mcp +2 -2
  7. package/bin/setup +161 -26
  8. package/bin/validate-manifest +3 -1
  9. package/package.json +1 -1
  10. package/packages/agent-hooks/src/deploy/deploy.ts +39 -4
  11. package/packages/agent-hooks/src/deploy/doctor.ts +6 -1
  12. package/packages/agent-hooks/src/deploy/index.ts +1 -1
  13. package/packages/agent-hooks/src/deploy/json-merge.ts +2 -2
  14. package/packages/agent-hooks/src/deploy/list.ts +13 -0
  15. package/packages/agent-hooks/src/deploy/lock.ts +2 -0
  16. package/packages/agent-hooks/src/gating/config-schema.ts +83 -0
  17. package/packages/agent-hooks/src/gating/config.ts +56 -6
  18. package/packages/agent-hooks/src/main.ts +11 -4
  19. package/packages/agent-hooks/src/pre-tool-use/handler.ts +37 -12
  20. package/packages/agent-settings/src/deploy/agents-deploy.ts +48 -5
  21. package/packages/agent-settings/src/deploy/deployed-names.ts +22 -0
  22. package/packages/agent-settings/src/deploy/index.ts +1 -0
  23. package/packages/agent-settings/src/deploy/lock.ts +9 -2
  24. package/packages/agent-settings/src/deploy/mcp-deploy.ts +39 -4
  25. package/packages/agent-settings/src/deploy/mcp-inspect.ts +3 -11
  26. package/packages/agent-settings/src/deploy/mcp-merge.ts +14 -1
  27. package/packages/agent-settings/src/deploy/retire-lean-ctx.ts +1 -1
  28. package/packages/agent-settings/src/deploy/safe-path.ts +42 -0
  29. package/packages/agent-settings/src/deploy/settings.ts +10 -2
  30. package/packages/agent-skills/dist/deploy.d.ts +25 -0
  31. package/packages/agent-skills/dist/deploy.d.ts.map +1 -1
  32. package/packages/agent-skills/dist/deploy.js +97 -11
  33. package/packages/agent-skills/dist/deploy.js.map +1 -1
  34. package/packages/agent-skills/dist/doctor.d.ts +2 -0
  35. package/packages/agent-skills/dist/doctor.d.ts.map +1 -1
  36. package/packages/agent-skills/dist/doctor.js +1 -1
  37. package/packages/agent-skills/dist/doctor.js.map +1 -1
  38. package/packages/agent-skills/dist/index.d.ts +3 -2
  39. package/packages/agent-skills/dist/index.d.ts.map +1 -1
  40. package/packages/agent-skills/dist/index.js +3 -2
  41. package/packages/agent-skills/dist/index.js.map +1 -1
  42. package/packages/agent-skills/dist/manifest.d.ts +5 -1
  43. package/packages/agent-skills/dist/manifest.d.ts.map +1 -1
  44. package/packages/agent-skills/dist/manifest.js +29 -4
  45. package/packages/agent-skills/dist/manifest.js.map +1 -1
  46. package/packages/agent-skills/dist/safe-path.d.ts +4 -0
  47. package/packages/agent-skills/dist/safe-path.d.ts.map +1 -0
  48. package/packages/agent-skills/dist/safe-path.js +45 -0
  49. package/packages/agent-skills/dist/safe-path.js.map +1 -0
  50. package/packages/agent-skills/dist/skill-config.d.ts.map +1 -1
  51. package/packages/agent-skills/dist/skill-config.js +5 -3
  52. package/packages/agent-skills/dist/skill-config.js.map +1 -1
  53. package/packages/agent-skills/src/deploy.ts +111 -11
  54. package/packages/agent-skills/src/doctor.ts +3 -1
  55. package/packages/agent-skills/src/index.ts +5 -1
  56. package/packages/agent-skills/src/manifest.ts +29 -4
  57. package/packages/agent-skills/src/safe-path.ts +42 -0
  58. package/packages/agent-skills/src/skill-config.ts +5 -3
  59. package/packages/fleet/manifest.json +2 -0
  60. package/packages/fleet/manifest.schema.json +6 -0
  61. package/packages/fleet/src/repo-maintain.ts +16 -16
  62. package/packages/repo-controls/AGENTS.md +6 -2
  63. package/packages/repo-controls/README.md +9 -6
  64. package/packages/repo-controls/src/doctor.ts +9 -4
  65. package/packages/repo-controls/src/hook.ts +10 -3
  66. package/packages/repo-controls/src/runtime.ts +137 -8
package/bin/adl CHANGED
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/bin/adl
3
- size: 63623392 bytes
4
- sha256: 81e59e152eab082015fe9a65fa77747015c23616a2c69b369f2b6598bc17f533
3
+ size: 63654640 bytes
4
+ sha256: 5797631e8286a7b7ea106368718e4b6838cdcacfd178ca397d867af8f973598a
package/bin/git-defaults CHANGED
@@ -127,8 +127,11 @@ while IFS=$'\t' read -r key values_json; do
127
127
  if [[ "$needs_gcm" -eq 1 ]]; then
128
128
  resolve_gcm
129
129
  [[ -n "$gcm_path" ]] || continue
130
+ # The replacement is deliberately unquoted inside the outer double quotes: bash 3.2
131
+ # (macOS /bin/bash) keeps a quoted replacement's quotes literally.
132
+ gcm_placeholder='{git-credential-manager}'
130
133
  for index in "${!wanted[@]}"; do
131
- wanted[index]="${wanted[index]//'{git-credential-manager}'/"$gcm_path"}"
134
+ wanted[index]="${wanted[index]//"$gcm_placeholder"/$gcm_path}"
132
135
  done
133
136
  fi
134
137
 
@@ -0,0 +1,119 @@
1
+ #!/bin/sh
2
+ # Why: packages/fleet/README.md#self-healing-the-watchdog (POSIX sh, run as `/bin/sh bin/job-watchdog`)
3
+
4
+ if [ -n "${ADL_SETUP_TEST_ROOT:-}" ]; then
5
+ root="${ADL_SETUP_TEST_ROOT%/}"
6
+ else
7
+ root=""
8
+ PATH="/usr/local/bin:/opt/homebrew/bin:/home/linuxbrew/.linuxbrew/bin:/usr/bin:/bin:/usr/sbin:/sbin"
9
+ export PATH
10
+ fi
11
+
12
+ label=com.adl.global-tools
13
+ plist="$root/Library/LaunchDaemons/$label.plist"
14
+ service_unit=adl-global-tools.service
15
+ timer_unit=adl-global-tools.timer
16
+ systemd_dir="$root/etc/systemd/system"
17
+ state_dir="$root/var/lib/adl"
18
+ last_success="$state_dir/last-success"
19
+ kick_stamp="$state_dir/watchdog-last-rearm"
20
+ max_age_minutes=1500
21
+ kick_gap_minutes=360
22
+
23
+ log() { printf '%s %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$*" >&2; }
24
+ fail() { log "ERROR watchdog: $*"; exit 1; }
25
+
26
+ # True when FILE exists and was modified within the last MINUTES minutes.
27
+ fresh() { [ -f "$1" ] && [ -n "$(find "$1" -mmin "-$2" 2>/dev/null)" ]; }
28
+
29
+ [ "$(id -u)" -eq 0 ] || fail "must run as root"
30
+
31
+ # Log modes repaired every run, whatever the health: packages/fleet/README.md#self-healing-the-watchdog
32
+ log_dir="$root/var/log/adl"
33
+ fix_mode() {
34
+ [ -e "$1" ] || return 0
35
+ [ -n "$(find "$1" -maxdepth 0 -perm "$2" 2>/dev/null)" ] && return 0
36
+ chmod "$2" "$1" || fail "cannot chmod $2 $1"
37
+ log "WARN watchdog: fixed the mode of $1 to 0$2"
38
+ }
39
+ fix_mode "$log_dir" 755
40
+ fix_mode "$log_dir/stdout.log" 644
41
+ fix_mode "$log_dir/stderr.log" 644
42
+
43
+ os="$(uname -s)"
44
+ cause=""
45
+
46
+ case "$os" in
47
+ Darwin)
48
+ [ -f "$plist" ] || fail "$plist is missing; run: sudo adl fleet setup NAME --rearm"
49
+ if printed="$(launchctl print "system/$label" 2>&1)"; then
50
+ job_state="$(printf '%s\n' "$printed" | sed -n 's/^[[:space:]]*state = //p' | head -n 1)"
51
+ [ "$job_state" = running ] && exit 0
52
+ exit_code="$(printf '%s\n' "$printed" | sed -n 's/^[[:space:]]*last exit code = \([0-9][0-9]*\).*/\1/p' | head -n 1)"
53
+ if [ "$exit_code" = 78 ]; then cause="launchd could not spawn the program (last exit code 78 EX_CONFIG)"; fi
54
+ # Incident state as launchd reports it (m3, 2026-10-24): packages/fleet/README.md#self-healing-the-watchdog
55
+ case "$printed" in *"needs LWCR update"*) cause="launchd reports the job needs an LWCR update (properties: needs LWCR update)" ;; esac
56
+ else
57
+ cause="$label is not loaded"
58
+ fi
59
+ ;;
60
+ Linux)
61
+ [ -f "$systemd_dir/$service_unit" ] && [ -f "$systemd_dir/$timer_unit" ] || fail "$service_unit / $timer_unit are missing in $systemd_dir; run: sudo adl fleet setup NAME --rearm"
62
+ service_state="$(systemctl is-active "$service_unit" 2>/dev/null)"
63
+ case "$service_state" in active|activating) exit 0 ;; esac
64
+ timer_state="$(systemctl is-active "$timer_unit" 2>/dev/null)"
65
+ timer_enabled="$(systemctl is-enabled "$timer_unit" 2>/dev/null)"
66
+ if [ "$timer_state" != active ]; then cause="$timer_unit is $timer_state"
67
+ elif [ "$timer_enabled" != enabled ]; then cause="$timer_unit is $timer_enabled, not enabled"
68
+ fi
69
+ ;;
70
+ *) fail "unsupported operating system: $os" ;;
71
+ esac
72
+
73
+ stale_only=0
74
+ if [ -z "$cause" ]; then
75
+ if fresh "$last_success" "$max_age_minutes"; then exit 0; fi
76
+ cause="no successful reconcile in the last 25 hours ($last_success)"
77
+ stale_only=1
78
+ fi
79
+
80
+ # Stale last-success alone re-arms at most once per 6 hours: packages/fleet/README.md#self-healing-the-watchdog
81
+ if [ "$stale_only" -eq 1 ] && fresh "$kick_stamp" "$kick_gap_minutes"; then exit 0; fi
82
+
83
+ log "WARN watchdog: re-arming the scheduled job: $cause"
84
+
85
+ case "$os" in
86
+ Darwin)
87
+ if rechecked="$(launchctl print "system/$label" 2>&1)"; then
88
+ # Re-check right before bootout: a run may have started since the first look.
89
+ recheck_state="$(printf '%s\n' "$rechecked" | sed -n 's/^[[:space:]]*state = //p' | head -n 1)"
90
+ if [ "$recheck_state" = running ]; then
91
+ log "WARN watchdog: $label started running meanwhile; not booting it out"
92
+ exit 0
93
+ fi
94
+ launchctl bootout "system/$label" || fail "launchctl bootout system/$label failed"
95
+ gone=0
96
+ for _ in 1 2 3 4 5 6 7 8 9 10; do
97
+ if ! launchctl print "system/$label" >/dev/null 2>&1; then gone=1; break; fi
98
+ sleep 0.5
99
+ done
100
+ [ "$gone" -eq 1 ] || fail "$label is still loaded after bootout (waited 5s); not bootstrapping"
101
+ fi
102
+ # A disabled service cannot be loaded (launchctl(1), enable | disable).
103
+ launchctl enable "system/$label" || fail "launchctl enable system/$label failed"
104
+ launchctl bootstrap system "$plist" || fail "launchctl bootstrap system $plist failed"
105
+ ;;
106
+ Linux)
107
+ systemctl daemon-reload || fail "systemctl daemon-reload failed"
108
+ systemctl enable --now "$timer_unit" || fail "systemctl enable --now $timer_unit failed"
109
+ systemctl restart "$timer_unit" || fail "systemctl restart $timer_unit failed"
110
+ ;;
111
+ esac
112
+
113
+ mkdir -p "$state_dir" || fail "cannot create $state_dir"
114
+ : >"$kick_stamp" || fail "cannot write $kick_stamp"
115
+ case "$os" in
116
+ Darwin) launchctl kickstart "system/$label" || fail "launchctl kickstart system/$label failed" ;;
117
+ Linux) systemctl start --no-block "$service_unit" || fail "systemctl start $service_unit failed" ;;
118
+ esac
119
+ log "WARN watchdog: re-armed and started $label"
package/bin/reconcile CHANGED
@@ -34,6 +34,13 @@ if [[ -z "${RECONCILE_REEXEC_BASH:-}" ]]; then
34
34
  if [[ "$reconcile_bash_major" -lt 4 || ( "$reconcile_bash_major" -eq 4 && "$reconcile_bash_minor" -lt 4 ) ]]; then
35
35
  reconcile_bash_candidates="${RECONCILE_TEST_BASH_CANDIDATES:-/opt/homebrew/bin/bash /usr/local/bin/bash /home/linuxbrew/.linuxbrew/bin/bash}"
36
36
  reconcile_newer_bash=""
37
+ # Sourced (the RECONCILE_SOURCE_ONLY test seam) there is no script to re-exec:
38
+ # $0 is the caller's shell, so `exec ... "$0"` would run that shell binary as a
39
+ # script. Fail loud and return instead.
40
+ if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then
41
+ echo "ERROR bin/reconcile was sourced under bash ${BASH_VERSION:-unknown}; it requires bash >= 4.4 and cannot re-exec when sourced. Run the sourcing shell under a newer bash (e.g. /opt/homebrew/bin/bash)." >&2
42
+ return 1 2>/dev/null || exit 1
43
+ fi
37
44
  for reconcile_bash_candidate in $reconcile_bash_candidates; do
38
45
  if [[ -x "$reconcile_bash_candidate" ]]; then
39
46
  reconcile_newer_bash="$reconcile_bash_candidate"
@@ -42,7 +49,7 @@ if [[ -z "${RECONCILE_REEXEC_BASH:-}" ]]; then
42
49
  done
43
50
  if [[ -n "$reconcile_newer_bash" ]]; then
44
51
  export RECONCILE_REEXEC_BASH=1
45
- exec "$reconcile_newer_bash" "$0" "$@"
52
+ exec "$reconcile_newer_bash" "${BASH_SOURCE[0]}" "$@"
46
53
  fi
47
54
  echo "ERROR bin/reconcile requires bash >= 4.4 (this run is bash ${BASH_VERSION:-unknown} -- empty-array expansions are unsafe under set -u before 4.4). No newer bash was found at: $reconcile_bash_candidates. Install one (e.g. 'brew install bash') and re-run, or put a newer bash earlier on PATH -- refusing to start rather than risk an 'unbound variable' abort mid-run after state has already changed." >&2
48
55
  exit 1
@@ -300,12 +307,30 @@ run_brew() {
300
307
  return 0
301
308
  fi
302
309
  [[ "$(id -u)" -eq 0 ]] || { echo "ERROR apply mode must run as root" >&2; exit 1; }
310
+ # brew_eula_active is set only around an operation on a package the manifest lists in
311
+ # devices.<name>.brew_accept_eula: the licence answer is a declared value, never an operator env var.
312
+ local -a eula_env=()
313
+ [[ -z "${brew_eula_active:-}" ]] || eula_env=(HOMEBREW_ACCEPT_EULA=Y)
303
314
  if [[ -n "${brew_noninteractive_dir:-}" ]]; then
304
315
  # The upgrade step: no sudo Homebrew spawns may prompt (see run_brew_upgrade_all).
305
- (cd /tmp && sudo -u "$brew_owner" -H env -u SUDO_ASKPASS NONINTERACTIVE=1 HOMEBREW_NO_SUDO=1 HOMEBREW_NO_ENV_HINTS=1 PATH="$brew_noninteractive_dir:${brew_bin%/*}:/usr/bin:/bin" "$brew_bin" "$@" </dev/null)
316
+ (cd /tmp && sudo -u "$brew_owner" -H env -u SUDO_ASKPASS NONINTERACTIVE=1 HOMEBREW_NO_SUDO=1 HOMEBREW_NO_ENV_HINTS=1 ${eula_env[@]+"${eula_env[@]}"} PATH="$brew_noninteractive_dir:${brew_bin%/*}:/usr/bin:/bin" "$brew_bin" "$@" </dev/null)
306
317
  return
307
318
  fi
308
- (cd /tmp && sudo -u "$brew_owner" -H env NONINTERACTIVE=1 PATH="${brew_bin%/*}:/usr/bin:/bin" "$brew_bin" "$@" </dev/null)
319
+ (cd /tmp && sudo -u "$brew_owner" -H env NONINTERACTIVE=1 ${eula_env[@]+"${eula_env[@]}"} PATH="${brew_bin%/*}:/usr/bin:/bin" "$brew_bin" "$@" </dev/null)
320
+ }
321
+
322
+ # Names (one per line) of the casks among "$@" that Homebrew itself marks as needing sudo, read from
323
+ # `brew info --cask --json=v2` artifacts: `pkg` (Library/Homebrew/cask/artifact/pkg.rb:16, always),
324
+ # `keyboard_layout` (keyboard_layout.rb:11, always) and `installer` only with `sudo: true`
325
+ # (installer.rb:87, args[:sudo] == true; cask/installer.rb:395 is where brew acts on it).
326
+ # dotnet-sdk and git-credential-manager list `pkg`; visual-studio-code and codex do not.
327
+ brew_sudo_casks() {
328
+ brew_query info --cask --json=v2 "$@" | jq -r '
329
+ .casks[]?
330
+ | select(any(.artifacts[]?; type == "object" and (
331
+ has("pkg") or has("keyboard_layout")
332
+ or (has("installer") and any(.installer[]?; [.. | objects | .sudo?] | any(. == true))))))
333
+ | .token'
309
334
  }
310
335
 
311
336
  # A directory holding a `sudo` that can never prompt: it execs /usr/bin/sudo -n. Put first on the
@@ -364,7 +389,8 @@ run_with_timeout() {
364
389
  # defaults for a real run (20 minutes, 5 minutes), overridable per-call-site
365
390
  # so test-manifest.sh can exercise the "hung command" branch in real time
366
391
  # instead of waiting out either default for real.
367
- BREW_UPGRADE_ALL_TIMEOUT_SECONDS="${RECONCILE_BREW_UPGRADE_TIMEOUT_SECONDS:-1200}"
392
+ BREW_UPGRADE_ALL_TIMEOUT_SECONDS="${RECONCILE_BREW_UPGRADE_TIMEOUT_SECONDS:-600}"
393
+ brew_eula_active=""
368
394
  SURFACE_UPDATE_TIMEOUT_SECONDS="${RECONCILE_SURFACE_UPDATE_TIMEOUT_SECONDS:-300}"
369
395
 
370
396
  # brew's output for a cask whose upgrade needed sudo but was not allowed to ask: Homebrew refusing
@@ -476,29 +502,66 @@ run_brew_upgrade_all_body() {
476
502
  # network-stalled `brew upgrade` cannot hang the rest of this run forever.
477
503
  # brew's output streams live -- never captured and printed at the end,
478
504
  # which left a long upgrade silent for minutes and looking stuck.
479
- echo "brew upgrade: $formulae_count formulae, $casks_count casks outdated; upgrading (timeout ${BREW_UPGRADE_ALL_TIMEOUT_SECONDS}s)"
505
+ echo "brew upgrade: $formulae_count formulae, $casks_count casks outdated; upgrading one at a time (timeout ${BREW_UPGRADE_ALL_TIMEOUT_SECONDS}s each)"
480
506
  local upgrade_status=0
481
- local failed=0 cask cask_output
507
+ local failed=0 cask cask_output formula sudo_casks eula_names pinned_names formula_deps eula_name
508
+ # Licence prompts are answered only for the packages this device's manifest entry declares
509
+ # (devices.<name>.brew_accept_eula): declaring a name is accepting its licence.
510
+ eula_names="$(jq -r --arg platform "$platform" --arg device "$device" '(.[$platform].devices[$device].brew_accept_eula // [])[]' "$manifest")"
511
+ # A pinned formula is skipped, not named: `brew upgrade <pinned>` fails ("Not upgrading ... pinned",
512
+ # Homebrew cmd/upgrade.rb:487-488), which would turn a deliberate pin into an ERROR every run.
513
+ pinned_names=""
482
514
  if [[ "$formulae_count" -gt 0 ]]; then
483
- run_with_timeout "$BREW_UPGRADE_ALL_TIMEOUT_SECONDS" run_brew upgrade --formula "${formulae[@]}" 2>&1 || upgrade_status=$?
515
+ pinned_names="$(brew_query list --pinned)" || { echo "WARN brew: could not list pinned formulae; pinned ones may fail to upgrade" >&2; pinned_names=""; }
516
+ fi
517
+ for formula in ${formulae[@]+"${formulae[@]}"}; do
518
+ upgrade_status=0
519
+ if [[ -n "$pinned_names" ]] && list_has_line "$formula" "$pinned_names"; then
520
+ echo "global-tools: brew upgrade skips pinned: $formula"
521
+ continue
522
+ fi
523
+ # The licence answer covers a declared package as the formula itself or as one of its dependencies
524
+ # (brew upgrades dependencies with it), still scoped to this one upgrade.
525
+ brew_eula_active=""
526
+ if [[ -n "$eula_names" ]]; then
527
+ if list_has_line "$formula" "$eula_names"; then
528
+ brew_eula_active=1
529
+ else
530
+ formula_deps="$(brew_query deps --formula "$formula")" || { echo "WARN brew: could not read dependencies of $formula; licence answer limited to declared names" >&2; formula_deps=""; }
531
+ while IFS= read -r eula_name; do
532
+ [[ -n "$eula_name" ]] || continue
533
+ if [[ -n "$formula_deps" ]] && list_has_line "$eula_name" "$formula_deps"; then brew_eula_active=1; break; fi
534
+ done <<<"$eula_names"
535
+ fi
536
+ fi
537
+ run_with_timeout "$BREW_UPGRADE_ALL_TIMEOUT_SECONDS" run_brew upgrade --formula "$formula" 2>&1 || upgrade_status=$?
538
+ brew_eula_active=""
484
539
  if [[ "$upgrade_status" -eq 124 ]]; then
485
- echo "ERROR brew upgrade timed out after ${BREW_UPGRADE_ALL_TIMEOUT_SECONDS}s" >&2
486
- return 1
540
+ echo "WARN brew: $formula upgrade timed out after ${BREW_UPGRADE_ALL_TIMEOUT_SECONDS}s; run: brew upgrade --formula $formula" >&2
487
541
  elif [[ "$upgrade_status" -ne 0 ]]; then
488
- echo "ERROR brew upgrade failed (exit $upgrade_status)" >&2
542
+ echo "ERROR brew upgrade failed (exit $upgrade_status): $formula" >&2
489
543
  failed=1
490
544
  fi
545
+ done
546
+ # A cask with a pkg/installer stanza runs `sudo installer` inside brew (Homebrew Cask Cookbook,
547
+ # `pkg` stanza): never run unattended. Skipped with a WARN naming the command to run by hand.
548
+ sudo_casks=""
549
+ if [[ "$casks_count" -gt 0 ]]; then
550
+ sudo_casks="$(brew_sudo_casks "${casks[@]}")" || { echo "WARN brew: could not inspect casks for sudo installers; upgrading them under the sudo -n shim" >&2; sudo_casks=""; }
491
551
  fi
492
552
  for cask in ${casks[@]+"${casks[@]}"}; do
553
+ if [[ -n "$sudo_casks" ]] && list_has_line "$cask" "$sudo_casks"; then
554
+ echo "WARN brew: $cask needs an interactive upgrade (sudo); run: brew upgrade --cask $cask" >&2
555
+ continue
556
+ fi
493
557
  upgrade_status=0
494
558
  cask_output="$(run_with_timeout "$BREW_UPGRADE_ALL_TIMEOUT_SECONDS" run_brew upgrade --cask "$cask" 2>&1)" || upgrade_status=$?
495
559
  [[ -z "$cask_output" ]] || printf '%s\n' "$cask_output"
496
560
  if [[ "$upgrade_status" -eq 124 ]]; then
497
- echo "ERROR brew upgrade timed out after ${BREW_UPGRADE_ALL_TIMEOUT_SECONDS}s ($cask)" >&2
498
- return 1
561
+ echo "WARN brew: $cask upgrade timed out after ${BREW_UPGRADE_ALL_TIMEOUT_SECONDS}s; run: brew upgrade --cask $cask" >&2
499
562
  elif [[ "$upgrade_status" -ne 0 ]]; then
500
563
  if brew_output_needs_password "$cask_output"; then
501
- echo "WARN brew: $cask needs an interactive password to upgrade; run: brew upgrade --cask $cask" >&2
564
+ echo "WARN brew: $cask needs an interactive upgrade (sudo); run: brew upgrade --cask $cask" >&2
502
565
  else
503
566
  echo "ERROR brew upgrade failed (exit $upgrade_status): $cask" >&2
504
567
  failed=1
@@ -1019,7 +1082,7 @@ resolve_surface_mode() {
1019
1082
  # root") is a real environment fault, not a flaky install, and still
1020
1083
  # aborts immediately -- `exit` is unconditional and is never caught here.
1021
1084
  install_one_tool() {
1022
- local tool_id="$1" manager package executable previous_executable migrating_from_bun=0 rc=0 npm_spec npm_allow_scripts npm_target_version npm_installed_ver brew_outdated_output brew_installed_version trust_kind
1085
+ local tool_id="$1" manager package executable previous_executable migrating_from_bun=0 rc=0 npm_spec npm_allow_scripts npm_target_version npm_installed_ver brew_outdated_output brew_outdated_status brew_installed_version trust_kind
1023
1086
  manager="$(jq -r --arg id "$tool_id" '.[$id].manager' "$resolved_file")"
1024
1087
  package="$(jq -r --arg id "$tool_id" '.[$id].package' "$resolved_file")"
1025
1088
  executable="$(jq -r --arg id "$tool_id" '.[$id].executable' "$resolved_file")"
@@ -1133,15 +1196,18 @@ install_one_tool() {
1133
1196
  elif [[ "$mode" != apply ]]; then
1134
1197
  echo "would install or upgrade Homebrew formula: $package"
1135
1198
  elif brew_query list --formula "$package" >/dev/null 2>&1; then
1136
- if brew_outdated_output="$(brew_query outdated --formula --quiet "$package")"; then
1137
- if [[ -z "$brew_outdated_output" ]]; then
1138
- brew_installed_version="$(brew_query list --formula --versions "$package" | awk '{print $2}')"
1139
- echo "already latest: $tool_id (brew:$package $brew_installed_version)"
1140
- else
1141
- run_brew upgrade "$package" || rc=1
1142
- fi
1199
+ # `brew outdated <named>` exits 1 when that package IS outdated (Homebrew cmd/outdated.rb:
1200
+ # Homebrew.failed = args.named.present? && outdated.present?) and 0 when current. A real
1201
+ # failure also exits 1 (odie), so "outdated" needs the package listed on stdout as well.
1202
+ brew_outdated_status=0
1203
+ brew_outdated_output="$(brew_query outdated --formula --quiet "$package")" || brew_outdated_status=$?
1204
+ if [[ "$brew_outdated_status" -eq 0 && -z "$brew_outdated_output" ]]; then
1205
+ brew_installed_version="$(brew_query list --formula --versions "$package" | awk '{print $2}')"
1206
+ echo "already latest: $tool_id (brew:$package $brew_installed_version)"
1207
+ elif [[ "$brew_outdated_status" -eq 1 && -n "$brew_outdated_output" ]]; then
1208
+ run_brew upgrade "$package" || rc=1
1143
1209
  else
1144
- echo "ERROR $tool_id: brew outdated check failed for $package" >&2
1210
+ echo "ERROR $tool_id: brew outdated check failed for $package (exit $brew_outdated_status)" >&2
1145
1211
  rc=1
1146
1212
  fi
1147
1213
  else
@@ -2331,7 +2397,7 @@ reconcile_bun_surface_cli() {
2331
2397
  # a command that cannot report its version is not an install.
2332
2398
  new_version="$(surface_cli_version "$bun_exe")"
2333
2399
  if [[ -z "$new_version" ]]; then
2334
- echo "ERROR surface $name: bun add -g $spec succeeded but '$bun_exe --version' printed nothing; the package's postinstall did not run (check 'bun pm default-trusted' lists $package, or add it to the global trustedDependencies)" >&2
2400
+ echo "ERROR surface $name: bun add -g $spec succeeded but '$bun_exe --version' printed nothing; the package's postinstall did not run; bun blocks it when $package is not trusted, and an explicit trustedDependencies in ~/.bun/install/global/package.json replaces bun's built-in trusted list. Run as $administrator: cd ~/.bun/install/global && bun pm untrusted && bun pm trust $package" >&2
2335
2401
  return 1
2336
2402
  fi
2337
2403
  retire_other_surface_copies "$name" "$command_name" "$package" "$bun_exe" || return 1
@@ -3142,7 +3208,6 @@ if [[ "$mode" == apply ]]; then
3142
3208
  install -m 0644 "$manifest" "$applied_manifest.new"
3143
3209
  mv "$applied_manifest.new" "$applied_manifest"
3144
3210
  printf '%s\n' "$applied_commit" >"$state_dir/applied-commit"
3145
- printf '%s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" >"$state_dir/last-success"
3146
3211
  echo "global-tools: reconciliation complete"
3147
3212
  else
3148
3213
  echo "global-tools: $mode complete; no state changed"
@@ -3163,3 +3228,5 @@ if [[ "$scratch_reap_failed" -eq 1 ]]; then
3163
3228
  echo "ERROR global-tools: scratch reap could not verify remotes; worktree removal was refused" >&2
3164
3229
  exit 1
3165
3230
  fi
3231
+
3232
+ # last-success is NOT written here: bin/reconcile-host stamps it after repository maintenance too.
@@ -118,4 +118,13 @@ else
118
118
  fi
119
119
 
120
120
  if [[ "$tools_rc" -ne 0 ]]; then exit "$tools_rc"; fi
121
- exit "$repos_rc"
121
+ if [[ "$repos_rc" -ne 0 ]]; then exit "$repos_rc"; fi
122
+
123
+ # last-success is the job watchdog's 25h staleness clock. Stamped only here, as the very last
124
+ # step of a fully successful apply run (tools AND repository maintenance), never earlier: a run
125
+ # that exits 1 must not look like a success (m3, 2026-10-24).
126
+ if [[ "$mode" != plan ]]; then
127
+ if [[ -n "${ADL_SETUP_TEST_ROOT:-}" ]]; then state_dir="${ADL_SETUP_TEST_ROOT%/}/var/lib/adl"; else state_dir=/var/lib/adl; fi
128
+ mkdir -p "$state_dir"
129
+ printf '%s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" >"$state_dir/last-success"
130
+ fi
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/bin/repo-search-mcp
3
- size: 62408624 bytes
4
- sha256: 45a5e2587987c4ef50986f1917976809c0ad9a198b6849ec9a6d1e8fbfad48e9
3
+ size: 62390624 bytes
4
+ sha256: b1c35e4c4383bc4cc9acb5a74ddffdfc87106d1fa6962e9983a885fc404a3c3f
package/bin/setup CHANGED
@@ -13,6 +13,11 @@ set -euo pipefail
13
13
  # 12 hours
14
14
  #
15
15
  # A host that cannot reconcile is never left with a timer that fails unseen.
16
+ # `--rearm` is the recovery path for a host that already ran setup: it skips the
17
+ # first reconcile and re-arms the job and its hourly watchdog (bin/job-watchdog,
18
+ # a second job whose program is /bin/sh) so a host with reconcile errors can still
19
+ # be brought back. The watchdog re-arms the main job by itself after a package
20
+ # update breaks it (packages/fleet/README.md, "Self-healing").
16
21
  # The job's program is the package's own bin/adl, not a shell script: on macOS
17
22
  # the one-time Full Disk Access grant (needed to read the repositories under the
18
23
  # host's repo_location) goes to that binary, and the launchd/systemd job and
@@ -39,13 +44,17 @@ else
39
44
  fi
40
45
 
41
46
  host=""
47
+ rearm=0
42
48
  while [[ "$#" -gt 0 ]]; do
43
49
  case "$1" in
44
50
  --host) host="${2:-}"; shift 2 ;;
51
+ # Recovery path: skip the first reconcile and re-arm the job and its watchdog
52
+ # (a host whose reconcile has errors could otherwise never be re-armed).
53
+ --rearm) rearm=1; shift ;;
45
54
  *) echo "ERROR unknown argument: $1" >&2; exit 2 ;;
46
55
  esac
47
56
  done
48
- [[ -n "$host" ]] || { echo "ERROR usage: sudo adl fleet setup NAME" >&2; exit 2; }
57
+ [[ -n "$host" ]] || { echo "ERROR usage: sudo adl fleet setup NAME [--rearm]" >&2; exit 2; }
49
58
  [[ "$(id -u)" -eq 0 ]] || { echo "ERROR adl fleet setup must run as root: sudo adl fleet setup $host" >&2; exit 1; }
50
59
 
51
60
  script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
@@ -83,6 +92,12 @@ fi
83
92
  adl_bin="$package_dir_real/bin/adl"
84
93
  [[ -x "$adl_bin" ]] || { echo "ERROR adl fleet setup: the package adl is missing or not executable: $package_dir/bin/adl" >&2; exit 1; }
85
94
  adl_check_adl_not_shadowed "$owner" "$os_name" "$owner_home" "$package_dir_real" "adl fleet setup" || exit 1
95
+ # The watchdog job's script (bin/job-watchdog) runs through /bin/sh, so -f, not -x.
96
+ # The jobs run it as ROOT, so they never point at this package copy (it sits in the
97
+ # owner's writable bun directory): setup installs a root-owned copy
98
+ # (install_watchdog_script below) and the jobs run that.
99
+ watchdog_source="$package_dir_real/bin/job-watchdog"
100
+ [[ -f "$watchdog_source" ]] || { echo "ERROR adl fleet setup: the package watchdog script is missing: $watchdog_source" >&2; exit 1; }
86
101
 
87
102
  if [[ -n "${ADL_SETUP_TEST_ROOT:-}" ]]; then
88
103
  system_root="${ADL_SETUP_TEST_ROOT%/}"
@@ -93,6 +108,8 @@ legacy_adl_sync="$system_root/usr/local/libexec/adl-sync"
93
108
  launch_daemons_dir="$system_root/Library/LaunchDaemons"
94
109
  systemd_dir="$system_root/etc/systemd/system"
95
110
  brew_prefix="$system_root/home/linuxbrew/.linuxbrew"
111
+ watchdog_dir="$system_root/usr/local/libexec/adl"
112
+ watchdog_script="$watchdog_dir/job-watchdog"
96
113
 
97
114
  # Preflight that must hold before the first reconcile: the Linux job runs
98
115
  # Homebrew as a non-root owner, and that owner needs git's safe.directory for
@@ -120,15 +137,92 @@ if [[ "$fleet_host_platform" == linux ]]; then
120
137
  fi
121
138
 
122
139
  mkdir -p "$system_root/var/lib/adl" "$system_root/var/log/adl"
140
+ # `adl logs` runs as the administrator: enforce the log directory 0755 and the
141
+ # existing logs 0644, root-owned, on every run (a macOS upgrade reset m3's to 0744).
142
+ # The watchdog (bin/job-watchdog) repairs the modes if they drift later.
143
+ if [[ "$fleet_host_platform" == mac ]]; then log_group=wheel; else log_group=root; fi
144
+ chown "root:$log_group" "$system_root/var/log/adl"
145
+ chmod 0755 "$system_root/var/log/adl"
146
+ for log_file in stdout.log stderr.log; do
147
+ if [[ -e "$system_root/var/log/adl/$log_file" ]]; then
148
+ chown "root:$log_group" "$system_root/var/log/adl/$log_file"
149
+ chmod 0644 "$system_root/var/log/adl/$log_file"
150
+ fi
151
+ done
123
152
 
124
- echo "adl fleet setup: first reconcile for $host (owner $owner)"
125
- reconcile_rc=0
126
- "$adl_bin" reconcile --host "$host" || reconcile_rc=$?
127
- if [[ "$reconcile_rc" -ne 0 ]]; then
128
- echo "ERROR adl fleet setup: first reconcile failed (exit $reconcile_rc); scheduler NOT armed. Fix the failure and re-run: sudo adl fleet setup $host" >&2
129
- exit "$reconcile_rc"
153
+ if [[ "$rearm" -eq 1 ]]; then
154
+ echo "adl fleet setup: --rearm: skipping the first reconcile; re-arming the job and its watchdog for $host"
155
+ else
156
+ echo "adl fleet setup: first reconcile for $host (owner $owner)"
157
+ reconcile_rc=0
158
+ "$adl_bin" reconcile --host "$host" || reconcile_rc=$?
159
+ if [[ "$reconcile_rc" -ne 0 ]]; then
160
+ echo "ERROR adl fleet setup: first reconcile failed (exit $reconcile_rc); scheduler NOT armed. Fix the failure and re-run: sudo adl fleet setup $host (or, to arm without a green reconcile: sudo adl fleet setup $host --rearm)" >&2
161
+ exit "$reconcile_rc"
162
+ fi
130
163
  fi
131
164
 
165
+ # Owner and octal mode of a path, "OWNER MODE", in the platform's stat dialect.
166
+ path_owner_mode() {
167
+ if [[ "$os_name" == Darwin ]]; then stat -f '%Su %Lp' "$1"; else stat -c '%U %a' "$1"; fi
168
+ }
169
+
170
+ # Every directory from $1 up to the system root must be owned by root and not
171
+ # writable by group or others, or a non-root user could swap the script that root
172
+ # runs. Fails loud, naming the directory.
173
+ require_root_only_dirs() {
174
+ local dir owner mode
175
+ dir="$(cd -P -- "$1" && pwd -P)" || { echo "ERROR adl fleet setup: cannot resolve $1" >&2; return 1; }
176
+ while :; do
177
+ read -r owner mode < <(path_owner_mode "$dir") || { echo "ERROR adl fleet setup: cannot stat $dir" >&2; return 1; }
178
+ if [[ "$owner" != root ]] || (( (8#$mode & 8#022) != 0 )); then
179
+ echo "ERROR adl fleet setup: $dir is owned by $owner with mode $mode; the watchdog runs as root, so every directory above it must be owned by root and not writable by group or others. Not installing." >&2
180
+ return 1
181
+ fi
182
+ if [[ "$dir" == "/" || "$dir" == "${system_root:-/}" ]]; then break; fi
183
+ dir="$(dirname -- "$dir")"
184
+ done
185
+ }
186
+
187
+ # Installs bin/job-watchdog as a root-owned 0755 copy, every time setup runs
188
+ # (so --rearm refreshes it). Written next to the destination then renamed, so a
189
+ # half-written script is never run.
190
+ install_watchdog_script() {
191
+ local group tmp
192
+ if [[ "$fleet_host_platform" == mac ]]; then group=wheel; else group=root; fi
193
+ mkdir -p "$watchdog_dir"
194
+ require_root_only_dirs "$watchdog_dir" || exit 1
195
+ tmp="$(mktemp "$watchdog_dir/.job-watchdog.XXXXXX")"
196
+ cp "$watchdog_source" "$tmp"
197
+ chown "root:$group" "$tmp"
198
+ chmod 0755 "$tmp"
199
+ mv -f "$tmp" "$watchdog_script"
200
+ }
201
+
202
+ # bootout fails when the job is not loaded, so ask first instead of swallowing
203
+ # the error: a bootout that fails on a loaded job must stop us. bootout returns
204
+ # before launchd has finished unloading, and a bootstrap in that window fails
205
+ # with an I/O error, so wait until the label is really gone, bounded, and fail
206
+ # loud if it is not.
207
+ launchd_rearm() {
208
+ local label="$1" job_plist="$2" unloaded
209
+ if launchctl print "system/$label" >/dev/null 2>&1; then
210
+ launchctl bootout "system/$label"
211
+ unloaded=0
212
+ for _ in 1 2 3 4 5 6 7 8 9 10; do
213
+ if ! launchctl print "system/$label" >/dev/null 2>&1; then unloaded=1; break; fi
214
+ sleep 0.5
215
+ done
216
+ [[ "$unloaded" -eq 1 ]] || {
217
+ echo "ERROR adl fleet setup: $label is still loaded after bootout (waited 5s); not bootstrapping. Run: sudo launchctl bootout system/$label" >&2
218
+ exit 1
219
+ }
220
+ fi
221
+ launchctl bootstrap system "$job_plist"
222
+ }
223
+
224
+ install_watchdog_script
225
+
132
226
  case "$fleet_host_platform" in
133
227
  mac)
134
228
  mkdir -p "$launch_daemons_dir"
@@ -153,24 +247,33 @@ case "$fleet_host_platform" in
153
247
  chown root:wheel "$plist"
154
248
  chmod 0644 "$plist"
155
249
  plutil -lint "$plist"
156
- # bootout fails when the job is not loaded, so ask first instead of
157
- # swallowing the error: a bootout that fails on a loaded job must stop us.
158
- if launchctl print system/com.adl.global-tools >/dev/null 2>&1; then
159
- launchctl bootout system/com.adl.global-tools
160
- # bootout returns before launchd has finished unloading, and a
161
- # bootstrap in that window fails with an I/O error. Wait until the
162
- # label is really gone, bounded, and fail loud if it is not.
163
- unloaded=0
164
- for _ in 1 2 3 4 5 6 7 8 9 10; do
165
- if ! launchctl print system/com.adl.global-tools >/dev/null 2>&1; then unloaded=1; break; fi
166
- sleep 0.5
167
- done
168
- [[ "$unloaded" -eq 1 ]] || {
169
- echo "ERROR adl fleet setup: com.adl.global-tools is still loaded after bootout (waited 5s); not bootstrapping. Run: sudo launchctl bootout system/com.adl.global-tools" >&2
170
- exit 1
171
- }
172
- fi
173
- launchctl bootstrap system "$plist"
250
+ launchd_rearm com.adl.global-tools "$plist"
251
+
252
+ # The watchdog (bin/job-watchdog) re-arms the job above when it stops
253
+ # running, e.g. after a package update replaced bin/adl and launchd refused to
254
+ # spawn it (exit 78). Its program is /bin/sh, a system binary whose identity
255
+ # never changes; only the script argument (this package's file) does.
256
+ watchdog_plist="$launch_daemons_dir/com.adl.global-tools-watchdog.plist"
257
+ {
258
+ printf '%s\n' '<?xml version="1.0" encoding="UTF-8"?>'
259
+ printf '%s\n' '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">'
260
+ printf '%s\n' '<plist version="1.0"><dict>'
261
+ printf '%s\n' '<key>Label</key><string>com.adl.global-tools-watchdog</string>'
262
+ printf '%s\n' '<key>ProgramArguments</key><array>'
263
+ printf '%s\n' '<string>/bin/sh</string>'
264
+ printf '<string>%s</string>\n' "$watchdog_script"
265
+ printf '%s\n' '</array>'
266
+ printf '%s\n' '<key>StartInterval</key><integer>3600</integer>'
267
+ printf '%s\n' '<key>RunAtLoad</key><true/>'
268
+ printf '%s\n' '<key>ProcessType</key><string>Background</string>'
269
+ printf '%s\n' '<key>StandardOutPath</key><string>/var/log/adl/stdout.log</string>'
270
+ printf '%s\n' '<key>StandardErrorPath</key><string>/var/log/adl/stderr.log</string>'
271
+ printf '%s\n' '</dict></plist>'
272
+ } >"$watchdog_plist"
273
+ chown root:wheel "$watchdog_plist"
274
+ chmod 0644 "$watchdog_plist"
275
+ plutil -lint "$watchdog_plist"
276
+ launchd_rearm com.adl.global-tools-watchdog "$watchdog_plist"
174
277
  ;;
175
278
  linux)
176
279
  mkdir -p "$systemd_dir"
@@ -206,6 +309,34 @@ EOF
206
309
  systemctl enable --now adl-global-tools.timer
207
310
  # enable --now leaves an already-active timer on its old schedule.
208
311
  systemctl restart adl-global-tools.timer
312
+
313
+ # The watchdog (bin/job-watchdog) re-arms the timer above if it stops, and
314
+ # starts the job when no reconcile has succeeded for 25 hours.
315
+ cat > "$systemd_dir/adl-global-tools-watchdog.service" <<EOF
316
+ [Unit]
317
+ Description=Re-arm the Adl global-tools job if it stopped (bin/job-watchdog)
318
+
319
+ [Service]
320
+ Type=oneshot
321
+ ExecStart=/bin/sh $watchdog_script
322
+ StandardOutput=append:/var/log/adl/stdout.log
323
+ StandardError=append:/var/log/adl/stderr.log
324
+ EOF
325
+ cat > "$systemd_dir/adl-global-tools-watchdog.timer" <<EOF
326
+ [Unit]
327
+ Description=Check hourly that the Adl global-tools job is armed and succeeding
328
+
329
+ [Timer]
330
+ OnCalendar=hourly
331
+ Persistent=true
332
+ Unit=adl-global-tools-watchdog.service
333
+
334
+ [Install]
335
+ WantedBy=timers.target
336
+ EOF
337
+ systemctl daemon-reload
338
+ systemctl enable --now adl-global-tools-watchdog.timer
339
+ systemctl restart adl-global-tools-watchdog.timer
209
340
  ;;
210
341
  esac
211
342
 
@@ -217,4 +348,8 @@ if [[ -e "$legacy_adl_sync" ]]; then
217
348
  echo "adl fleet setup: removed the legacy scheduler copy $legacy_adl_sync"
218
349
  fi
219
350
 
220
- echo "adl fleet setup: $host reconciled and armed (every 12 hours at minute $minute); run on demand with: sudo adl reconcile --host $host"
351
+ if [[ "$rearm" -eq 1 ]]; then
352
+ echo "adl fleet setup: $host armed without a reconcile (every 12 hours at minute $minute, watchdog hourly); run on demand with: sudo adl reconcile --host $host"
353
+ else
354
+ echo "adl fleet setup: $host reconciled and armed (every 12 hours at minute $minute, watchdog hourly); run on demand with: sudo adl reconcile --host $host"
355
+ fi
@@ -57,7 +57,9 @@ if ! jq -e '
57
57
  all((.default_agent | type) == "string" and (.default_agent | test("^agent-[a-z0-9-]+$"))) and
58
58
  all((.git_user | type == "object" and (keys | sort) == ["email", "name"] and
59
59
  all(.[]; type == "string" and length > 0))) and
60
- all((keys - ["administrator", "default_agent", "git_user", "home", "minimum_free_gib", "schedule_minute", "scratch_repos", "brew_upgrade_all", "surface_clis", "repo_location", "tools"] | length) == 0) and
60
+ all((keys - ["administrator", "default_agent", "git_user", "home", "minimum_free_gib", "schedule_minute", "scratch_repos", "brew_upgrade_all", "brew_accept_eula", "surface_clis", "repo_location", "tools"] | length) == 0) and
61
+ all((.brew_accept_eula // []) | type == "array" and (. | unique | length) == length and
62
+ all(type == "string" and test("^[A-Za-z0-9][A-Za-z0-9@._+/-]*$"))) and
61
63
  all((.scratch_repos // []) | type == "array" and (. | unique | length) == length and
62
64
  all(type == "string" and startswith("/") and . != "/" and
63
65
  (endswith("/") | not) and (contains("..") | not) and (test("\\s") | not))) and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amsterdamdatalabs/adl-agent-control-darwin-arm64",
3
- "version": "0.1.54",
3
+ "version": "0.1.59",
4
4
  "description": "adl CLI binary for darwin/arm64 (agent identity + Azure DevOps front door — see docs/architecture/cli-design.md)",
5
5
  "license": "UNLICENSED",
6
6
  "os": [