@osfactory/har 0.54.0 → 0.55.0

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.
@@ -326,6 +326,49 @@ har_regenerate_agent_env_file() {
326
326
  fi
327
327
  }
328
328
 
329
+ # Untracked (not ignored) paths stay in the main checkout when a session
330
+ # worktree is created from HEAD. Advisory — never fails the launch.
331
+ har_warn_untracked_worktree() {
332
+ case "${USE_WORKTREE:-${HARNESS_USE_WORKTREE:-true}}" in
333
+ true|TRUE|yes|YES|1) ;;
334
+ *) return 0 ;;
335
+ esac
336
+ local root="${REPO_ROOT:-}"
337
+ if [ -z "$root" ] && [ -n "${SCRIPT_DIR:-}" ]; then
338
+ root="$(cd "$SCRIPT_DIR/.." && pwd)"
339
+ fi
340
+ [ -n "$root" ] || return 0
341
+ git -C "$root" rev-parse --is-inside-work-tree >/dev/null 2>&1 || return 0
342
+
343
+ local paths=()
344
+ local entry
345
+ while IFS= read -r -d '' entry; do
346
+ paths+=("$entry")
347
+ done < <(git -C "$root" --literal-pathspecs ls-files --others --exclude-standard --directory -z 2>/dev/null || true)
348
+
349
+ local count="${#paths[@]}"
350
+ [ "$count" -gt 0 ] || return 0
351
+
352
+ local max=8
353
+ local listed=""
354
+ local i
355
+ for ((i = 0; i < count && i < max; i++)); do
356
+ [ -n "$listed" ] && listed+=", "
357
+ listed+="${paths[$i]}"
358
+ done
359
+ if [ "$count" -gt "$max" ]; then
360
+ listed+=" (+$((count - max)) more)"
361
+ fi
362
+
363
+ local noun="paths"
364
+ local them="They are"
365
+ if [ "$count" -eq 1 ]; then
366
+ noun="path"
367
+ them="It is"
368
+ fi
369
+ echo "WARN: ${count} untracked ${noun} will not appear in the session worktree: ${listed}. ${them} only in the main checkout — track them, or launch with --no-worktree." >&2
370
+ }
371
+
329
372
  # har_launch_preflight <agent_id> [resume]
330
373
  # Exit 0 when ready; 2 when occupied (free the slot first) or not resumable; 1 on machine blockers.
331
374
  # Sets FE_PORT/API_PORT/DEBUG_PORT when this harness uses PM2.
@@ -364,6 +407,7 @@ har_launch_preflight() {
364
407
  fi
365
408
  done
366
409
  fi
410
+ har_warn_untracked_worktree
367
411
  return 0
368
412
  }
369
413
 
@@ -445,6 +489,35 @@ try {
445
489
  # optional: SLOT_SUFFIX, SLOT_WORKTREE_PATH, SLOT_BRANCH, SLOT_BASE_BRANCH,
446
490
  # SLOT_BASE_COMMIT, SLOT_PORTS_JSON, SLOT_PREVIEW_URLS_JSON,
447
491
  # SLOT_STATUS, SLOT_LAST_ERROR, SLOT_WORK_UNIT_ID, SLOT_ATTEMPT_ID
492
+ # Mission Control re-reads slot state only when something syncs, and a sync takes
493
+ # about twenty seconds — too long to make a slot change wait for it. Detached, and
494
+ # coalesced so a run of slot changes leaves one sync going, then one more if needed.
495
+ har_notify_control() {
496
+ local root bin lock
497
+ root="$(cd "${SCRIPT_DIR}/.." && pwd)"
498
+ bin="$(command -v har 2>/dev/null || echo "${root}/node_modules/.bin/har")"
499
+ [ -x "$bin" ] || return 0
500
+
501
+ lock="${TMPDIR:-/tmp}/har-control-sync.$(id -u)"
502
+ : > "${lock}.pending"
503
+ mkdir "$lock" 2>/dev/null || return 0
504
+ (
505
+ trap "" HUP
506
+ trap 'rmdir "$lock" 2>/dev/null || true' EXIT
507
+ cd "$root" || exit 0
508
+ while [ -f "${lock}.pending" ]; do
509
+ rm -f "${lock}.pending"
510
+ if command -v timeout >/dev/null 2>&1; then
511
+ timeout 120 "$bin" control sync || true
512
+ else
513
+ "$bin" control sync || true
514
+ fi
515
+ done
516
+ # Redirected as a whole, not per command: a background job that keeps the inherited
517
+ # stdout open makes any caller reading that pipe wait for it.
518
+ ) >/dev/null 2>&1 &
519
+ }
520
+
448
521
  write_slot_registry() {
449
522
  local file
450
523
  file="$(slot_registry_file "$SLOT_AGENT_ID")"
@@ -474,10 +547,12 @@ for (const [key, env] of [["ports", "SLOT_PORTS_JSON"], ["previewUrls", "SLOT_PR
474
547
  }
475
548
  fs.writeFileSync(process.argv[1], JSON.stringify(entry, null, 2) + "\n");
476
549
  ' "$file"
550
+ har_notify_control
477
551
  }
478
552
 
479
553
  remove_slot_registry() {
480
554
  rm -f "$(slot_registry_file "$1")"
555
+ har_notify_control
481
556
  }
482
557
 
483
558
  # Exit 0 when the worktree has uncommitted or untracked changes.
@@ -310,6 +310,49 @@ EOF
310
310
  fi
311
311
  }
312
312
 
313
+ # Untracked (not ignored) paths stay in the main checkout when a session
314
+ # worktree is created from HEAD. Advisory — never fails the launch.
315
+ har_warn_untracked_worktree() {
316
+ case "${USE_WORKTREE:-${HARNESS_USE_WORKTREE:-true}}" in
317
+ true|TRUE|yes|YES|1) ;;
318
+ *) return 0 ;;
319
+ esac
320
+ local root="${REPO_ROOT:-}"
321
+ if [ -z "$root" ] && [ -n "${SCRIPT_DIR:-}" ]; then
322
+ root="$(cd "$SCRIPT_DIR/.." && pwd)"
323
+ fi
324
+ [ -n "$root" ] || return 0
325
+ git -C "$root" rev-parse --is-inside-work-tree >/dev/null 2>&1 || return 0
326
+
327
+ local paths=()
328
+ local entry
329
+ while IFS= read -r -d '' entry; do
330
+ paths+=("$entry")
331
+ done < <(git -C "$root" --literal-pathspecs ls-files --others --exclude-standard --directory -z 2>/dev/null || true)
332
+
333
+ local count="${#paths[@]}"
334
+ [ "$count" -gt 0 ] || return 0
335
+
336
+ local max=8
337
+ local listed=""
338
+ local i
339
+ for ((i = 0; i < count && i < max; i++)); do
340
+ [ -n "$listed" ] && listed+=", "
341
+ listed+="${paths[$i]}"
342
+ done
343
+ if [ "$count" -gt "$max" ]; then
344
+ listed+=" (+$((count - max)) more)"
345
+ fi
346
+
347
+ local noun="paths"
348
+ local them="They are"
349
+ if [ "$count" -eq 1 ]; then
350
+ noun="path"
351
+ them="It is"
352
+ fi
353
+ echo "WARN: ${count} untracked ${noun} will not appear in the session worktree: ${listed}. ${them} only in the main checkout — track them, or launch with --no-worktree." >&2
354
+ }
355
+
313
356
  # har_launch_preflight <agent_id> [resume]
314
357
  # Exit 0 when ready; 2 when occupied (free the slot first) or not resumable; 1 on machine blockers.
315
358
  har_launch_preflight() {
@@ -346,6 +389,7 @@ har_launch_preflight() {
346
389
  fi
347
390
  done
348
391
  fi
392
+ har_warn_untracked_worktree
349
393
  return 0
350
394
  }
351
395
 
@@ -427,6 +471,35 @@ try {
427
471
  # optional: SLOT_SUFFIX, SLOT_WORKTREE_PATH, SLOT_BRANCH, SLOT_BASE_BRANCH,
428
472
  # SLOT_BASE_COMMIT, SLOT_PORTS_JSON, SLOT_PREVIEW_URLS_JSON,
429
473
  # SLOT_STATUS, SLOT_LAST_ERROR, SLOT_WORK_UNIT_ID, SLOT_ATTEMPT_ID
474
+ # Mission Control re-reads slot state only when something syncs, and a sync takes
475
+ # about twenty seconds — too long to make a slot change wait for it. Detached, and
476
+ # coalesced so a run of slot changes leaves one sync going, then one more if needed.
477
+ har_notify_control() {
478
+ local root bin lock
479
+ root="$(cd "${SCRIPT_DIR}/.." && pwd)"
480
+ bin="$(command -v har 2>/dev/null || echo "${root}/node_modules/.bin/har")"
481
+ [ -x "$bin" ] || return 0
482
+
483
+ lock="${TMPDIR:-/tmp}/har-control-sync.$(id -u)"
484
+ : > "${lock}.pending"
485
+ mkdir "$lock" 2>/dev/null || return 0
486
+ (
487
+ trap "" HUP
488
+ trap 'rmdir "$lock" 2>/dev/null || true' EXIT
489
+ cd "$root" || exit 0
490
+ while [ -f "${lock}.pending" ]; do
491
+ rm -f "${lock}.pending"
492
+ if command -v timeout >/dev/null 2>&1; then
493
+ timeout 120 "$bin" control sync || true
494
+ else
495
+ "$bin" control sync || true
496
+ fi
497
+ done
498
+ # Redirected as a whole, not per command: a background job that keeps the inherited
499
+ # stdout open makes any caller reading that pipe wait for it.
500
+ ) >/dev/null 2>&1 &
501
+ }
502
+
430
503
  write_slot_registry() {
431
504
  local file
432
505
  file="$(slot_registry_file "$SLOT_AGENT_ID")"
@@ -456,10 +529,12 @@ for (const [key, env] of [["ports", "SLOT_PORTS_JSON"], ["previewUrls", "SLOT_PR
456
529
  }
457
530
  fs.writeFileSync(process.argv[1], JSON.stringify(entry, null, 2) + "\n");
458
531
  ' "$file"
532
+ har_notify_control
459
533
  }
460
534
 
461
535
  remove_slot_registry() {
462
536
  rm -f "$(slot_registry_file "$1")"
537
+ har_notify_control
463
538
  }
464
539
 
465
540
  # Exit 0 when the worktree has uncommitted or untracked changes.
@@ -109,6 +109,24 @@ launch fails and lists the models this machine can create.
109
109
  If `HARNESS_SIMULATOR_NAME` is not a model but names an existing device, that
110
110
  device is used as-is and never deleted — how a hand-renamed simulator is targeted.
111
111
 
112
+ ### Running from an agent sandbox
113
+
114
+ `xcrun simctl` reaches CoreSimulatorService over XPC. Coding agents that sandbox
115
+ their shell (Codex, Claude Code and others) usually deny that lookup, so `simctl`
116
+ fails while `xcodebuild` keeps working — every simulator command then dies with
117
+ `CoreSimulatorService connection became invalid`. Nothing is missing on the machine.
118
+
119
+ Launch and teardown say so when it happens. Either run `har env launch <id>` and
120
+ `har env teardown <id>` from a normal terminal and let the agent work in the
121
+ worktree, or grant the agent unsandboxed access to `xcrun simctl` — the escalation
122
+ must cover every subcommand the harness uses (`list`, `create`, `boot`,
123
+ `bootstatus`, `shutdown`, `delete`), not just `list`.
124
+
125
+ The same messages distinguish a second cause: if `xcrun simctl` is missing from
126
+ the selected developer directory — no Xcode, or `xcode-select` pointing at the
127
+ Command Line Tools — they say so and print the current selection instead of
128
+ blaming a sandbox.
129
+
112
130
  The device lands in `.env.agent.<id>` as `HARNESS_SIMULATOR_UDID`,
113
131
  `HARNESS_SIMULATOR_DEVICE_NAME` and `HARNESS_IOS_DESTINATION` — the model stays in
114
132
  `HARNESS_SIMULATOR_NAME`, so the two never mean the same thing in one place; what a slot holds is tracked in `.har/simulators/`.
@@ -95,6 +95,35 @@ try {
95
95
  # optional: SLOT_SUFFIX, SLOT_WORKTREE_PATH, SLOT_BRANCH, SLOT_BASE_BRANCH,
96
96
  # SLOT_BASE_COMMIT, SLOT_PORTS_JSON, SLOT_PREVIEW_URLS_JSON,
97
97
  # SLOT_STATUS, SLOT_LAST_ERROR, SLOT_WORK_UNIT_ID, SLOT_ATTEMPT_ID
98
+ # Mission Control re-reads slot state only when something syncs, and a sync takes
99
+ # about twenty seconds — too long to make a slot change wait for it. Detached, and
100
+ # coalesced so a run of slot changes leaves one sync going, then one more if needed.
101
+ har_notify_control() {
102
+ local root bin lock
103
+ root="$(cd "${SCRIPT_DIR}/.." && pwd)"
104
+ bin="$(command -v har 2>/dev/null || echo "${root}/node_modules/.bin/har")"
105
+ [ -x "$bin" ] || return 0
106
+
107
+ lock="${TMPDIR:-/tmp}/har-control-sync.$(id -u)"
108
+ : > "${lock}.pending"
109
+ mkdir "$lock" 2>/dev/null || return 0
110
+ (
111
+ trap "" HUP
112
+ trap 'rmdir "$lock" 2>/dev/null || true' EXIT
113
+ cd "$root" || exit 0
114
+ while [ -f "${lock}.pending" ]; do
115
+ rm -f "${lock}.pending"
116
+ if command -v timeout >/dev/null 2>&1; then
117
+ timeout 120 "$bin" control sync || true
118
+ else
119
+ "$bin" control sync || true
120
+ fi
121
+ done
122
+ # Redirected as a whole, not per command: a background job that keeps the inherited
123
+ # stdout open makes any caller reading that pipe wait for it.
124
+ ) >/dev/null 2>&1 &
125
+ }
126
+
98
127
  write_slot_registry() {
99
128
  local file
100
129
  file="$(slot_registry_file "$SLOT_AGENT_ID")"
@@ -124,10 +153,12 @@ for (const [key, env] of [["ports", "SLOT_PORTS_JSON"], ["previewUrls", "SLOT_PR
124
153
  }
125
154
  fs.writeFileSync(process.argv[1], JSON.stringify(entry, null, 2) + "\n");
126
155
  ' "$file"
156
+ har_notify_control
127
157
  }
128
158
 
129
159
  remove_slot_registry() {
130
160
  rm -f "$(slot_registry_file "$1")"
161
+ har_notify_control
131
162
  }
132
163
 
133
164
  # Exit 0 when the worktree has uncommitted or untracked changes.
@@ -208,6 +239,49 @@ print_slot_occupied_warning() {
208
239
  echo "" >&2
209
240
  }
210
241
 
242
+ # Untracked (not ignored) paths stay in the main checkout when a session
243
+ # worktree is created from HEAD. Advisory — never fails the launch.
244
+ har_warn_untracked_worktree() {
245
+ case "${USE_WORKTREE:-${HARNESS_USE_WORKTREE:-true}}" in
246
+ true|TRUE|yes|YES|1) ;;
247
+ *) return 0 ;;
248
+ esac
249
+ local root="${REPO_ROOT:-}"
250
+ if [ -z "$root" ] && [ -n "${SCRIPT_DIR:-}" ]; then
251
+ root="$(cd "$SCRIPT_DIR/.." && pwd)"
252
+ fi
253
+ [ -n "$root" ] || return 0
254
+ git -C "$root" rev-parse --is-inside-work-tree >/dev/null 2>&1 || return 0
255
+
256
+ local paths=()
257
+ local entry
258
+ while IFS= read -r -d '' entry; do
259
+ paths+=("$entry")
260
+ done < <(git -C "$root" --literal-pathspecs ls-files --others --exclude-standard --directory -z 2>/dev/null || true)
261
+
262
+ local count="${#paths[@]}"
263
+ [ "$count" -gt 0 ] || return 0
264
+
265
+ local max=8
266
+ local listed=""
267
+ local i
268
+ for ((i = 0; i < count && i < max; i++)); do
269
+ [ -n "$listed" ] && listed+=", "
270
+ listed+="${paths[$i]}"
271
+ done
272
+ if [ "$count" -gt "$max" ]; then
273
+ listed+=" (+$((count - max)) more)"
274
+ fi
275
+
276
+ local noun="paths"
277
+ local them="They are"
278
+ if [ "$count" -eq 1 ]; then
279
+ noun="path"
280
+ them="It is"
281
+ fi
282
+ echo "WARN: ${count} untracked ${noun} will not appear in the session worktree: ${listed}. ${them} only in the main checkout — track them, or launch with --no-worktree." >&2
283
+ }
284
+
211
285
  git_common_dir() {
212
286
  local cwd="$1"
213
287
  local out
@@ -56,6 +56,8 @@ if slot_is_occupied "$AGENT_ID"; then
56
56
  exit 2
57
57
  fi
58
58
 
59
+ har_warn_untracked_worktree
60
+
59
61
  "$SCRIPT_DIR/setup-infra.sh"
60
62
 
61
63
  # Session worktree (default — use --no-worktree to work in repo root).
@@ -19,6 +19,14 @@ source "$SCRIPT_DIR/simulator.sh"
19
19
 
20
20
  log() { echo "==> $*" >&2; }
21
21
 
22
+ # simctl could not be asked, so nothing it did not return is evidence of anything
23
+ # missing on this machine. The wording lives in simulator.sh so launch and this
24
+ # script cannot drift apart on which of the two causes they name.
25
+ fail_simctl_unavailable() {
26
+ har_sim_log_simctl_unavailable
27
+ exit 1
28
+ }
29
+
22
30
  # ── Xcode check ───────────────────────────────────────────────────────────────
23
31
  if ! command -v xcodebuild >/dev/null 2>&1; then
24
32
  echo "Error: xcodebuild not found — install Xcode from the App Store." >&2
@@ -40,6 +48,8 @@ if har_sim_per_slot_enabled; then
40
48
  PLAN_STATUS="${PLAN%%$'\t'*}"
41
49
  if [ "$PLAN_STATUS" = "OK" ]; then
42
50
  log "Per-slot simulators: launch creates one $(printf '%s' "$PLAN" | cut -f3) per agent."
51
+ elif [ "$PLAN_STATUS" = "SIMCTL_UNAVAILABLE" ]; then
52
+ fail_simctl_unavailable
43
53
  elif [ "$PLAN_STATUS" = "NO_MODEL" ] && [ -n "$(har_sim_device_by_name "${HARNESS_SIMULATOR_NAME:-}")" ]; then
44
54
  # Supported fallback: the name is an existing device rather than a model.
45
55
  log "Per-slot simulators: launch reuses the existing device '${SIMULATOR_NAME}'."
@@ -63,6 +73,7 @@ else
63
73
  UDID="${RESOLVED%%$'\t'*}"
64
74
 
65
75
  if [ -z "$UDID" ]; then
76
+ har_sim_simctl_available || fail_simctl_unavailable
66
77
  echo "Error: Simulator '${SIMULATOR_NAME}' not found in available devices." >&2
67
78
  echo " Available simulators:" >&2
68
79
  xcrun simctl list devices available 2>/dev/null | grep -E 'iPhone|iPad' | head -20 >&2
@@ -108,10 +108,25 @@ har_sim_claim_owner_of() {
108
108
 
109
109
  # ── Device discovery ──────────────────────────────────────────────────────────
110
110
 
111
+ # Every simctl call goes through here, so "simctl could not be asked" stays
112
+ # distinguishable from "simctl answered, and the answer is empty" at the one place
113
+ # that still knows the difference. Non-zero means the first; callers check it
114
+ # instead of reading an empty list as a fact about the machine.
115
+ har_sim_simctl() {
116
+ local out rc=0
117
+ out="$(xcrun simctl "$@" 2>/dev/null)" || rc=$?
118
+ if [ "$rc" -ne 0 ] || [ -z "$out" ]; then
119
+ return 1
120
+ fi
121
+ printf '%s' "$out"
122
+ }
123
+
111
124
  # Unavailable devices are skipped: a device whose runtime was uninstalled must
112
125
  # not pass validation only to fail at boot.
113
126
  har_sim_device_field() {
114
- xcrun simctl list devices --json 2>/dev/null | node -e '
127
+ local devices
128
+ devices="$(har_sim_simctl list devices --json)" || return 1
129
+ printf '%s' "$devices" | node -e '
115
130
  const data = JSON.parse(require("fs").readFileSync(0, "utf8"));
116
131
  const [want, field] = process.argv.slice(1);
117
132
  const device = Object.values(data.devices || {})
@@ -128,9 +143,10 @@ har_sim_device_name() { har_sim_device_field "$1" name; }
128
143
  # UDID of an existing device with this exact name, newest runtime first.
129
144
  # A substring match would resolve "iPhone 16" to "iPhone 16 Pro Max".
130
145
  har_sim_device_by_name() {
131
- local want="${1:-}"
146
+ local want="${1:-}" devices
132
147
  [ -n "$want" ] || return 0
133
- xcrun simctl list devices available --json 2>/dev/null | node -e '
148
+ devices="$(har_sim_simctl list devices available --json)" || return 1
149
+ printf '%s' "$devices" | node -e '
134
150
  const data = JSON.parse(require("fs").readFileSync(0, "utf8"));
135
151
  const want = process.argv[1];
136
152
  const rows = [];
@@ -157,22 +173,66 @@ har_sim_resolve_configured() {
157
173
  printf '%s\t%s' "$udid" "${HARNESS_SIMULATOR_NAME}"
158
174
  }
159
175
 
160
- # `simctl list` is a subprocess and a JSON parse; neither answer changes during
161
- # a launch, so each is fetched at most once per process.
176
+ # `simctl list` is a subprocess and a JSON parse, so each answer is cached — but in
177
+ # the calling shell, not the process: `$(har_sim_runtimes_json)` fetches, then throws
178
+ # the cache and the availability flag away with the subshell that held them. Call
179
+ # these directly and read the variable whenever either one matters.
162
180
  har_sim_devicetypes_json() {
163
181
  if [ -z "${_HAR_SIM_TYPES_JSON:-}" ]; then
164
- _HAR_SIM_TYPES_JSON="$(xcrun simctl list devicetypes --json 2>/dev/null || echo '{}')"
182
+ _HAR_SIM_TYPES_JSON="$(har_sim_simctl list devicetypes --json)" || _HAR_SIM_TYPES_JSON='{}'
165
183
  fi
166
184
  printf '%s' "$_HAR_SIM_TYPES_JSON"
167
185
  }
168
186
 
169
187
  har_sim_runtimes_json() {
170
188
  if [ -z "${_HAR_SIM_RUNTIMES_JSON:-}" ]; then
171
- _HAR_SIM_RUNTIMES_JSON="$(xcrun simctl list runtimes --json 2>/dev/null || echo '{}')"
189
+ if _HAR_SIM_RUNTIMES_JSON="$(har_sim_simctl list runtimes --json)"; then
190
+ _HAR_SIM_SIMCTL_OK=true
191
+ else
192
+ _HAR_SIM_RUNTIMES_JSON='{}'
193
+ _HAR_SIM_SIMCTL_OK=false
194
+ # A second call, but only ever when simctl is already failing — and failing
195
+ # is the fast path. Its stderr is the only thing that tells the causes apart.
196
+ _HAR_SIM_SIMCTL_ERROR="$(xcrun simctl list runtimes --json 2>&1 >/dev/null || true)"
197
+ fi
172
198
  fi
173
199
  printf '%s' "$_HAR_SIM_RUNTIMES_JSON"
174
200
  }
175
201
 
202
+ # Ask simctl once, recording in this shell whether it answered and why not.
203
+ har_sim_probe_simctl() {
204
+ har_sim_runtimes_json >/dev/null
205
+ }
206
+
207
+ har_sim_simctl_available() {
208
+ har_sim_probe_simctl
209
+ [ "${_HAR_SIM_SIMCTL_OK:-true}" = "true" ]
210
+ }
211
+
212
+ # Two unrelated problems make simctl unusable — a sandbox denying the
213
+ # CoreSimulatorService lookup, and a developer directory with no simctl in it.
214
+ # Naming the wrong one costs the reader the hunt this check exists to prevent.
215
+ har_sim_log_simctl_unavailable() {
216
+ # Teardown hits two failures in a row; the cause only needs saying once.
217
+ [ -z "${_HAR_SIM_SIMCTL_CAUSE_REPORTED:-}" ] || return 0
218
+ _HAR_SIM_SIMCTL_CAUSE_REPORTED=1
219
+ # For a launch the failing call happened inside the command substitution around
220
+ # har_sim_plan_creation, so the reason died with that subshell — ask again here.
221
+ har_sim_probe_simctl
222
+ case "${_HAR_SIM_SIMCTL_ERROR:-}" in
223
+ *"not a developer tool"*|*"unable to find utility"*|*"command not found"*)
224
+ har_sim_log "'xcrun simctl' is not in the selected developer directory"
225
+ har_sim_log " install Xcode, then point the toolchain at it:"
226
+ har_sim_log " sudo xcode-select -s /Applications/Xcode.app"
227
+ har_sim_log " current selection: $(xcode-select -p 2>/dev/null || echo 'none')"
228
+ return
229
+ ;;
230
+ esac
231
+ har_sim_log "cannot reach CoreSimulatorService — 'xcrun simctl' is unusable here"
232
+ har_sim_log " this usually means the command is running inside an agent sandbox"
233
+ har_sim_log " run it from a normal terminal, or let the agent run 'xcrun simctl' unsandboxed"
234
+ }
235
+
176
236
  # Model and runtime to create this slot's device from. Failures carry the models
177
237
  # this machine can create, so the caller never has to re-derive that list.
178
238
  # Prints one of:
@@ -180,10 +240,18 @@ har_sim_runtimes_json() {
180
240
  # NO_RUNTIME no iOS runtime installed
181
241
  # NO_MODEL <models> HARNESS_SIMULATOR_NAME is not a device model
182
242
  # NO_RUNTIME_FOR_MODEL <models> model exists, no installed runtime supports it
243
+ # SIMCTL_UNAVAILABLE simctl could not be asked at all
183
244
  har_sim_plan_creation() {
184
245
  local types runtimes
185
246
  types="$(har_sim_devicetypes_json)"
186
- runtimes="$(har_sim_runtimes_json)"
247
+ # Not `$(...)`: that would discard the availability flag with the subshell.
248
+ har_sim_runtimes_json >/dev/null
249
+ runtimes="$_HAR_SIM_RUNTIMES_JSON"
250
+ # Checked before the empty lists are read as an answer about the machine.
251
+ if ! har_sim_simctl_available; then
252
+ printf 'SIMCTL_UNAVAILABLE'
253
+ return
254
+ fi
187
255
  node -e '
188
256
  const [typesRaw, runtimesRaw, wantName, family] = process.argv.slice(1);
189
257
  const types = JSON.parse(typesRaw).devicetypes || [];
@@ -240,7 +308,9 @@ process.stdout.write(plan());
240
308
  # Every device whose name is <prefix> or starts with "<prefix>-", so a slot's
241
309
  # leftovers are found whatever model they were created from.
242
310
  har_sim_devices_with_prefix() {
243
- xcrun simctl list devices --json 2>/dev/null | node -e '
311
+ local devices
312
+ devices="$(har_sim_simctl list devices --json)" || return 1
313
+ printf '%s' "$devices" | node -e '
244
314
  const data = JSON.parse(require("fs").readFileSync(0, "utf8"));
245
315
  const prefix = process.argv[1];
246
316
  const matches = Object.values(data.devices || {})
@@ -252,12 +322,19 @@ process.stdout.write(matches.join("\n"));
252
322
  ' "$1" 2>/dev/null || true
253
323
  }
254
324
 
325
+ # Returns 0 even when it could not look: teardown.sh runs under `set -e`, and
326
+ # aborting there would leave the slot registry behind on top of the device.
255
327
  har_sim_delete_devices_with_prefix() {
256
- local udid
328
+ local udid list
329
+ if ! list="$(har_sim_devices_with_prefix "$1")"; then
330
+ har_sim_log "cannot check for leftover devices named ${1}* — none were removed"
331
+ har_sim_log_simctl_unavailable
332
+ return 0
333
+ fi
257
334
  while read -r udid; do
258
335
  [ -n "$udid" ] || continue
259
336
  xcrun simctl delete "$udid" >/dev/null 2>&1 || true
260
- done <<< "$(har_sim_devices_with_prefix "$1")"
337
+ done <<< "$list"
261
338
  }
262
339
 
263
340
  # ── Boot ──────────────────────────────────────────────────────────────────────
@@ -289,7 +366,11 @@ _har_sim_select() {
289
366
 
290
367
  # An explicit UDID is a deliberate override — never fall back off it.
291
368
  if [ -n "${HARNESS_SIMULATOR_UDID:-}" ]; then
292
- name="$(har_sim_device_name "$HARNESS_SIMULATOR_UDID")"
369
+ # A failed lookup is "could not ask"; an empty one is "no such device".
370
+ name="$(har_sim_device_name "$HARNESS_SIMULATOR_UDID")" || {
371
+ har_sim_log_simctl_unavailable
372
+ return 1
373
+ }
293
374
  if [ -z "$name" ]; then
294
375
  har_sim_log "HARNESS_SIMULATOR_UDID=${HARNESS_SIMULATOR_UDID} is not a known device"
295
376
  return 1
@@ -310,6 +391,11 @@ _har_sim_select() {
310
391
  models=""
311
392
  [ "$plan" != "$status" ] && models="${plan#*$'\t'}"
312
393
 
394
+ if [ "$status" = "SIMCTL_UNAVAILABLE" ]; then
395
+ har_sim_log_simctl_unavailable
396
+ return 1
397
+ fi
398
+
313
399
  if [ "$status" = "OK" ]; then
314
400
  IFS=$'\t' read -r _ device_type model runtime _ <<< "$plan"
315
401
  label="$(har_sim_device_label "$agent_id" "$model")"
@@ -388,8 +474,14 @@ har_sim_release() {
388
474
  rm -f "$file"
389
475
  if [ "$created" = "true" ] && [ -n "$udid" ]; then
390
476
  xcrun simctl shutdown "$udid" >/dev/null 2>&1 || true
391
- xcrun simctl delete "$udid" >/dev/null 2>&1 || true
392
- echo "✓ Deleted simulator created for this slot ($udid)"
477
+ if xcrun simctl delete "$udid" >/dev/null 2>&1; then
478
+ echo "✓ Deleted simulator created for this slot ($udid)"
479
+ else
480
+ # Naming it is the whole remedy left: the claim is gone, so only the name
481
+ # prefix sweep at the next launch can still find this device.
482
+ har_sim_log "could not delete ${udid}, created for agent ${agent_id} — it is still on this machine"
483
+ har_sim_simctl_available || har_sim_log_simctl_unavailable
484
+ fi
393
485
  fi
394
486
  fi
395
487
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@osfactory/har",
3
- "version": "0.54.0",
3
+ "version": "0.55.0",
4
4
  "description": "Open harness for reproducible multi-agent coding workflows",
5
5
  "keywords": [
6
6
  "har",