opencode-agent-harness 0.0.0-stage → 0.2.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.
Files changed (169) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/LICENSE +21 -0
  3. package/README.md +590 -2
  4. package/bin/agent-harness.js +3059 -0
  5. package/contrib/global-plugins/README.md +49 -0
  6. package/contrib/global-plugins/harness-freshness.ts +355 -0
  7. package/package.json +48 -4
  8. package/templates/.agents/AGENTS.md +204 -0
  9. package/templates/.agents/features/INDEX.md +10 -0
  10. package/templates/.agents/handoffs/README.md +87 -0
  11. package/templates/.agents/memory/dev-loop.md +59 -0
  12. package/templates/.agents/memory/domain-map.md +29 -0
  13. package/templates/.agents/memory/environments.md +35 -0
  14. package/templates/.agents/memory/flow-map.md +23 -0
  15. package/templates/.agents/memory/history.md +7 -0
  16. package/templates/.agents/memory/locations.md +14 -0
  17. package/templates/.agents/memory/model-routing.md +261 -0
  18. package/templates/.agents/memory/orchestration.md +183 -0
  19. package/templates/.agents/memory/owned-files.md +19 -0
  20. package/templates/.agents/memory/product-principles.md +37 -0
  21. package/templates/.agents/memory/quality-parameters.md +37 -0
  22. package/templates/.agents/memory/stack-versions.md +35 -0
  23. package/templates/.agents/memory/test-design-parameters.md +36 -0
  24. package/templates/.agents/nightly.json +17 -0
  25. package/templates/.agents/qa-plans/README.md +70 -0
  26. package/templates/.agents/qa-runs/README.md +21 -0
  27. package/templates/.agents/reviews/README.md +47 -0
  28. package/templates/.agents/rules/00-operating.md +199 -0
  29. package/templates/.agents/skills/data-engineer/SKILL.md +31 -0
  30. package/templates/.agents/skills/devops-engineer/SKILL.md +50 -0
  31. package/templates/.agents/skills/diagnostics-expert/SKILL.md +44 -0
  32. package/templates/.agents/skills/docs/SKILL.md +140 -0
  33. package/templates/.agents/skills/features/SKILL.md +187 -0
  34. package/templates/.agents/skills/frontend-engineer/SKILL.md +81 -0
  35. package/templates/.agents/skills/handoff/SKILL.md +85 -0
  36. package/templates/.agents/skills/mobile-engineer/SKILL.md +101 -0
  37. package/templates/.agents/skills/planner/SKILL.md +112 -0
  38. package/templates/.agents/skills/product-manager/SKILL.md +115 -0
  39. package/templates/.agents/skills/qa-architect/SKILL.md +224 -0
  40. package/templates/.agents/skills/qa-runner/SKILL.md +64 -0
  41. package/templates/.agents/skills/security-engineer/SKILL.md +53 -0
  42. package/templates/.agents/skills/system-architect/SKILL.md +42 -0
  43. package/templates/.agents/skills/ui-designer/SKILL.md +71 -0
  44. package/templates/.github/workflows/ci.yml +148 -0
  45. package/templates/.github/workflows/deploy-uat.yml +95 -0
  46. package/templates/.github/workflows/nightly.yml +83 -0
  47. package/templates/.github/workflows/uat-health.yml +41 -0
  48. package/templates/.husky/pre-push +23 -0
  49. package/templates/.ignore +28 -0
  50. package/templates/.opencode/agents/data-engineer.md +37 -0
  51. package/templates/.opencode/agents/devops-engineer.md +37 -0
  52. package/templates/.opencode/agents/diagnostics-expert.md +37 -0
  53. package/templates/.opencode/agents/docs.md +37 -0
  54. package/templates/.opencode/agents/features.md +21 -0
  55. package/templates/.opencode/agents/frontend-engineer.md +37 -0
  56. package/templates/.opencode/agents/handoff.md +21 -0
  57. package/templates/.opencode/agents/mobile-engineer.md +37 -0
  58. package/templates/.opencode/agents/planner.md +34 -0
  59. package/templates/.opencode/agents/product-manager.md +29 -0
  60. package/templates/.opencode/agents/qa-architect.md +27 -0
  61. package/templates/.opencode/agents/qa-runner.md +17 -0
  62. package/templates/.opencode/agents/security-engineer.md +37 -0
  63. package/templates/.opencode/agents/system-architect.md +37 -0
  64. package/templates/.opencode/agents/ui-designer.md +37 -0
  65. package/templates/.opencode/commands/board.md +15 -0
  66. package/templates/.opencode/commands/checkpoint.md +25 -0
  67. package/templates/.opencode/commands/feature.md +56 -0
  68. package/templates/.opencode/commands/finish.md +36 -0
  69. package/templates/.opencode/commands/next.md +49 -0
  70. package/templates/.opencode/commands/report.md +55 -0
  71. package/templates/.opencode/commands/resume.md +39 -0
  72. package/templates/.opencode/commands/switch-model.md +34 -0
  73. package/templates/.opencode/commands/tidy.md +49 -0
  74. package/templates/.opencode/plugins/backlog-notify.ts +57 -0
  75. package/templates/.opencode/plugins/backlog.ts +272 -0
  76. package/templates/.opencode/plugins/checkpoint.ts +160 -0
  77. package/templates/.opencode/plugins/context-guard.ts +1164 -0
  78. package/templates/.opencode/plugins/diff.ts +85 -0
  79. package/templates/.opencode/plugins/gates.ts +71 -0
  80. package/templates/.opencode/plugins/job-notify.ts +241 -0
  81. package/templates/.opencode/plugins/orient.ts +67 -0
  82. package/templates/.opencode/plugins/session.ts +89 -0
  83. package/templates/.opencode/plugins/wait.ts +101 -0
  84. package/templates/.opencode/plugins/where.ts +70 -0
  85. package/templates/.opencode/skills/bounded-explore/SKILL.md +38 -0
  86. package/templates/.opencode/skills/dev-loop/SKILL.md +87 -0
  87. package/templates/.vercelignore +16 -0
  88. package/templates/AGENTS.md +27 -0
  89. package/templates/BACKLOG.md +95 -0
  90. package/templates/docs/ci-cd-pipeline.md +81 -0
  91. package/templates/docs/gates.md +128 -0
  92. package/templates/docs/mcp-integrations.md +97 -0
  93. package/templates/docs/mobile-testing.md +555 -0
  94. package/templates/docs/nightly-testing.md +106 -0
  95. package/templates/docs/wsl-optimizations.md +290 -0
  96. package/templates/opencode.json +188 -0
  97. package/templates/scripts/agent-report.js +541 -0
  98. package/templates/scripts/agent-search.sh +117 -0
  99. package/templates/scripts/backlog.js +1864 -0
  100. package/templates/scripts/board-service.sh +207 -0
  101. package/templates/scripts/checkpoint.js +290 -0
  102. package/templates/scripts/finalize.js +277 -0
  103. package/templates/scripts/nightly.js +913 -0
  104. package/templates/scripts/orient.js +514 -0
  105. package/templates/scripts/qa/board-client.js +260 -0
  106. package/templates/scripts/qa/board-lib.js +96 -0
  107. package/templates/scripts/qa/board-sync.js +469 -0
  108. package/templates/scripts/qa/capacity-lib.js +916 -0
  109. package/templates/scripts/qa/check-backlog.js +427 -0
  110. package/templates/scripts/qa/check-capacity.js +85 -0
  111. package/templates/scripts/qa/check-ci-policy.js +164 -0
  112. package/templates/scripts/qa/check-concurrency.js +344 -0
  113. package/templates/scripts/qa/check-dispatch-config.js +296 -0
  114. package/templates/scripts/qa/check-docs.js +284 -0
  115. package/templates/scripts/qa/check-integrate.js +98 -0
  116. package/templates/scripts/qa/check-linger.js +160 -0
  117. package/templates/scripts/qa/check-prefix-stability.js +183 -0
  118. package/templates/scripts/qa/check-product.js +177 -0
  119. package/templates/scripts/qa/check-qa-plan.js +378 -0
  120. package/templates/scripts/qa/check-qa-scripts.js +85 -0
  121. package/templates/scripts/qa/check-quality.js +249 -0
  122. package/templates/scripts/qa/check-test-wiring.js +253 -0
  123. package/templates/scripts/qa/ci-triage.js +346 -0
  124. package/templates/scripts/qa/ci-usage-lib.js +185 -0
  125. package/templates/scripts/qa/ci-wait-lib.js +294 -0
  126. package/templates/scripts/qa/command-classifier.js +552 -0
  127. package/templates/scripts/qa/context-guard-core.js +1618 -0
  128. package/templates/scripts/qa/diff.js +174 -0
  129. package/templates/scripts/qa/feature-scaffold.js +224 -0
  130. package/templates/scripts/qa/fixtures/backlog.md +104 -0
  131. package/templates/scripts/qa/governance.js +174 -0
  132. package/templates/scripts/qa/hash-file.js +32 -0
  133. package/templates/scripts/qa/lease-lib.js +263 -0
  134. package/templates/scripts/qa/merge-backlog.js +324 -0
  135. package/templates/scripts/qa/mobile-e2e/analyze-timings.js +300 -0
  136. package/templates/scripts/qa/mobile-e2e/apk-cache.js +420 -0
  137. package/templates/scripts/qa/mobile-e2e/backend-build-cache.js +203 -0
  138. package/templates/scripts/qa/mobile-e2e/boot-emulator.sh +432 -0
  139. package/templates/scripts/qa/mobile-e2e/build-apk.sh +210 -0
  140. package/templates/scripts/qa/mobile-e2e/check-flows.js +453 -0
  141. package/templates/scripts/qa/mobile-e2e/config.yaml +18 -0
  142. package/templates/scripts/qa/mobile-e2e/device-down.sh +88 -0
  143. package/templates/scripts/qa/mobile-e2e/device-up.sh +258 -0
  144. package/templates/scripts/qa/mobile-e2e/ios-simulator-down.sh +72 -0
  145. package/templates/scripts/qa/mobile-e2e/ios-simulator-up.sh +153 -0
  146. package/templates/scripts/qa/mobile-e2e/job-events.js +181 -0
  147. package/templates/scripts/qa/mobile-e2e/prewarm.sh +56 -0
  148. package/templates/scripts/qa/mobile-e2e/run-detached.sh +222 -0
  149. package/templates/scripts/qa/mobile-e2e/run-maestro.js +1543 -0
  150. package/templates/scripts/qa/mobile-e2e/ui-dump.js +327 -0
  151. package/templates/scripts/qa/models.allowlist.txt +32 -0
  152. package/templates/scripts/qa/provider-stats.js +878 -0
  153. package/templates/scripts/qa/run-clean.js +83 -0
  154. package/templates/scripts/qa/run-gates.js +212 -0
  155. package/templates/scripts/qa/run-loop.js +220 -0
  156. package/templates/scripts/qa/session-recon.js +512 -0
  157. package/templates/scripts/qa/store-lib.js +324 -0
  158. package/templates/scripts/qa/tool-lib.js +134 -0
  159. package/templates/scripts/qa/where.js +214 -0
  160. package/templates/scripts/qa/wslconfig-merge.js +157 -0
  161. package/templates/scripts/serve.js +1328 -0
  162. package/templates/scripts/setup-nightly.sh +185 -0
  163. package/templates/scripts/setup-tmpfs.sh +374 -0
  164. package/templates/scripts/ship.js +586 -0
  165. package/templates/scripts/switch-reasoning-model.ps1 +101 -0
  166. package/templates/scripts/switch-reasoning-model.sh +104 -0
  167. package/templates/scripts/wait-for.js +342 -0
  168. package/templates/scripts/wsl-gpu.sh +180 -0
  169. package/templates/scripts/wsl-tune.sh +261 -0
@@ -0,0 +1,258 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # mobile E2E — bring the whole device tier UP in one idempotent command: the adb
4
+ # server, the emulator, the app build + install, and the dev server (in the same
5
+ # machine-wide `mobile` tier group), verified against a health URL.
6
+ #
7
+ # Why a wrapper: `boot-emulator.sh` covers the adb server + emulator only. The
8
+ # 2026-09 LibraryOS recon showed a device session hand-rolling 15-21 setup calls
9
+ # (adb server, emulator boot, APK build, install, dev-server start, health probe),
10
+ # each an opportunity to skip the readiness gate or the capacity check. This is
11
+ # the single entry point; the primitives stay where they are (boot-emulator.sh,
12
+ # serve.js) and this only sequences them.
13
+ #
14
+ # Order matters: the APK build (a heavy one-shot) runs BEFORE the emulator (a
15
+ # heavy long-lived tier) so the two never overlap on a ~10 GB VM — building while
16
+ # the emulator is up OOMs the build and can get the emulator killed (F-296).
17
+ #
18
+ # Speed (F-30x device-tier startup): the build reuses the content-addressed
19
+ # native base + JS bundle via `build-apk.sh`/`apk-cache.js`, so only the JS
20
+ # bundle is re-signed per feature revision; the emulator boots from a quickboot
21
+ # snapshot when one is valid; and the dev-server start overlaps the emulator
22
+ # boot (both are independent). `device-up:timings {…}` is printed per phase.
23
+ #
24
+ # Idempotent: an already-booted emulator, a live adb server, an installed APK of
25
+ # the same version, and a running dev server are all REUSED (never restarted).
26
+ #
27
+ # Project config (never hardcoded here) — `scripts/qa/mobile-e2e/local.json`:
28
+ # platform android|ios (default android; env MOBILE_E2E_PLATFORM wins)
29
+ # avd AVD name (boot-emulator.sh reads it)
30
+ # appId Android package id (install / version check)
31
+ # apk path to the APK (default: conventional Gradle path)
32
+ # devCmd dev-server command (default: npm run dev)
33
+ # devUrl dev-server health URL (default: http://localhost:3000)
34
+ # devName serve.js label (default: app-dev)
35
+ # devBuildCmd backend build (optional); when set, run ONCE before the
36
+ # server and cache it (backend-build-cache.js). For a
37
+ # production backend set devCmd: "npm run start",
38
+ # devBuildCmd: "npm run build".
39
+ # devBuildCache globs whose content invalidates devBuildCmd (required for
40
+ # caching; e.g. ["app/**","lib/**","next.config.*"]).
41
+ # devBuildOutput optional artifact a cache hit must also find present
42
+ # (e.g. ".next/BUILD_ID") — a deleted build is a miss.
43
+ # Env overrides: MOBILE_E2E_APK / MOBILE_E2E_DEV_CMD / MOBILE_E2E_DEV_URL /
44
+ # MOBILE_E2E_DEV_NAME / MOBILE_E2E_SKIP_BUILD / MOBILE_E2E_SKIP_INSTALL /
45
+ # MOBILE_E2E_OVERLAP (default 1) / MOBILE_E2E_DEV_MEM_MAX (dev-server cgroup
46
+ # cap, default 2560M) / MOBILE_E2E_DEV_BUILD_CMD / MOBILE_E2E_DEV_BUILD_FORCE.
47
+ #
48
+ # The dev server gets an EXPLICIT --mem-max: serve.js sums group member CAPS, so
49
+ # without it the dev server would claim the whole heavy_mem_max_mb default and
50
+ # the later emulator would be tightened to the tiny remainder (= its guest RAM,
51
+ # pinning qemu against its cgroup cap). 2560M covers next dev's ~1.9 GB peak and
52
+ # leaves the group budget for the emulator (see boot-emulator.sh --mem-max).
53
+ # A production backend (`next start`) is far leaner and steadier across the long
54
+ # matrix run; `devBuildCmd` opts in and is run as a capped one-shot, sequenced
55
+ # with the APK build so two heavy one-shots never overlap.
56
+ #
57
+ # Usage:
58
+ # scripts/qa/mobile-e2e/device-up.sh # full bring-up
59
+ # scripts/qa/mobile-e2e/device-up.sh --no-dev # emulator + app only (no dev server)
60
+ set -euo pipefail
61
+
62
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
63
+ cd "$ROOT"
64
+ LOCAL_CONFIG="$ROOT/scripts/qa/mobile-e2e/local.json"
65
+ SDK="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-$HOME/android-sdk}}"
66
+ ADB="$SDK/platform-tools/adb"
67
+ TIER_GROUP="${MOBILE_E2E_TIER_GROUP:-mobile}"
68
+ SERVE_DIR="$ROOT/.serve"
69
+
70
+ WITH_DEV=1
71
+ for arg in "$@"; do
72
+ case "$arg" in
73
+ --no-dev) WITH_DEV=0 ;;
74
+ -h|--help) sed -n '2,/^set -euo pipefail$/p' "${BASH_SOURCE[0]}" | sed '$d' | sed 's/^# \{0,1\}//'; exit 0 ;;
75
+ *) echo "unknown argument: $arg" >&2; exit 2 ;;
76
+ esac
77
+ done
78
+
79
+ cfg() {
80
+ node -e "try{const c=require('$LOCAL_CONFIG');const v=c['$1'];process.stdout.write(v==null?'':String(v))}catch(e){}" 2>/dev/null || true
81
+ }
82
+
83
+ APP_ID="${MOBILE_E2E_APP_ID:-$(cfg appId)}"
84
+ APK="${MOBILE_E2E_APK:-$(cfg apk)}"
85
+ DEV_CMD="${MOBILE_E2E_DEV_CMD:-$(cfg devCmd)}"
86
+ DEV_URL="${MOBILE_E2E_DEV_URL:-$(cfg devUrl)}"
87
+ DEV_NAME="${MOBILE_E2E_DEV_NAME:-$(cfg devName)}"
88
+ DEV_MEM_MAX="${MOBILE_E2E_DEV_MEM_MAX:-2560}M"
89
+ DEV_BUILD_CMD="${MOBILE_E2E_DEV_BUILD_CMD:-$(cfg devBuildCmd)}"
90
+ BUILD_CACHE_JS="$ROOT/scripts/qa/mobile-e2e/backend-build-cache.js"
91
+ [ -z "$DEV_CMD" ] && DEV_CMD="npm run dev"
92
+ [ -z "$DEV_URL" ] && DEV_URL="http://localhost:3000"
93
+ [ -z "$DEV_NAME" ] && DEV_NAME="app-dev"
94
+ # Conventional Expo/RN release output when local.json declares no `apk`.
95
+ [ -z "$APK" ] && APK="$ROOT/mobile/android/app/build/outputs/apk/release/app-release.apk"
96
+
97
+ # Platform selection: env MOBILE_E2E_PLATFORM > local.json `platform` > android.
98
+ # android = the full APK/adb/emulator tier; ios = `ios-simulator-up.sh` + the dev
99
+ # server only (no Gradle, no adb, no APK install — those are Android-only).
100
+ PLATFORM="${MOBILE_E2E_PLATFORM:-$(cfg platform)}"
101
+ case "$PLATFORM" in ios|iOS|IOS) PLATFORM=ios ;; *) PLATFORM=android ;; esac
102
+
103
+ mkdir -p "$SERVE_DIR"
104
+ now_ms() { date +%s%3N; }
105
+ T_START="$(now_ms)"
106
+ T_BUILD="$T_START"
107
+ T_BOOT="$T_START"
108
+ T_INSTALL="$T_START"
109
+ T_DEV="$T_START"
110
+
111
+ echo "device-up: platform=$PLATFORM app=${APP_ID:-?} apk=${APK:-<auto>} dev=${DEV_URL} group=${TIER_GROUP}"
112
+
113
+ # 1. Build the APK FIRST, as a capped one-shot, BEFORE the emulator exists. The
114
+ # build is a heavy one-shot (Gradle daemon + Kotlin daemon + R8/D8) and the
115
+ # emulator is a heavy long-lived tier; running both at once on a ~10 GB VM
116
+ # OOMs the build AND can get the emulator killed (F-296, 2026-09-30). Build
117
+ # then boot serializes the two heavy phases. `serve.js run` also refuses a
118
+ # build that does not fit a live group budget, so a rebuild while an emulator
119
+ # is already up fails loudly instead of thrashing the box.
120
+ #
121
+ # build-apk.sh owns the cache: it reuses a full-key hit, else overlays a fresh
122
+ # JS bundle onto the cached native base, else runs Gradle. It prints the APK
123
+ # path as `APK=…`, which we adopt (the cached/overlaid path differs from the
124
+ # conventional one).
125
+ if [ "$PLATFORM" != "ios" ] && [ "${MOBILE_E2E_SKIP_INSTALL:-0}" != "1" ] && [ "${MOBILE_E2E_SKIP_BUILD:-0}" != "1" ]; then
126
+ echo "[1/5] building the app (cached via apk-cache.js; override with MOBILE_E2E_SKIP_BUILD=1)"
127
+ BUILD_LOG="$SERVE_DIR/device-up-build.log"
128
+ if [ -x "$ROOT/scripts/qa/mobile-e2e/build-apk.sh" ]; then
129
+ bash "$ROOT/scripts/qa/mobile-e2e/build-apk.sh" 2>&1 | tee "$BUILD_LOG"
130
+ # PIPESTATUS[0] is build-apk.sh's status under `set -o pipefail`.
131
+ parsed="$(sed -n 's/^APK=//p' "$BUILD_LOG" | tail -1)"
132
+ [ -n "$parsed" ] && APK="$parsed"
133
+ elif [ -x "$ROOT/scripts/qa/mobile-e2e/build-dev-apk.sh" ]; then
134
+ echo " (using project build-dev-apk.sh — route it through \`serve.js run\` so it is capped)"
135
+ bash "$ROOT/scripts/qa/mobile-e2e/build-dev-apk.sh"
136
+ else
137
+ echo " (no build-apk.sh / build-dev-apk.sh; set MOBILE_E2E_SKIP_BUILD=1 if the APK is prebuilt)"
138
+ fi
139
+ elif [ "$PLATFORM" = "ios" ]; then
140
+ echo "[1/5] build skipped (platform=ios — the Android APK is not used)"
141
+ else
142
+ echo "[1/5] build skipped"
143
+ fi
144
+ T_BUILD="$(now_ms)"
145
+ T_BACKEND="$T_BUILD"
146
+
147
+ # 1b. Optional production backend build. It must finish before the server starts,
148
+ # and it is itself a heavy one-shot, so it runs here — after the APK build,
149
+ # before the emulator — keeping heavy one-shots from overlapping (F-296).
150
+ # Cached by input fingerprint: an unchanged tree skips it entirely. A failed
151
+ # build aborts (never a stale server); a success is recorded for next time.
152
+ if [ "$WITH_DEV" = "1" ] && [ -n "$DEV_BUILD_CMD" ]; then
153
+ echo "[1b/5] backend build: $DEV_BUILD_CMD"
154
+ if [ "${MOBILE_E2E_DEV_BUILD_FORCE:-0}" != "1" ] && [ -f "$BUILD_CACHE_JS" ] && node "$BUILD_CACHE_JS" check --cmd "$DEV_BUILD_CMD"; then
155
+ echo " (build inputs unchanged — cached)"
156
+ else
157
+ node scripts/serve.js run --name backend-build --group "$TIER_GROUP" --cmd "$DEV_BUILD_CMD" || {
158
+ echo "FAIL — backend build failed ('$DEV_BUILD_CMD'): fix it before the device tier can come up." >&2
159
+ exit 1
160
+ }
161
+ [ -f "$BUILD_CACHE_JS" ] && node "$BUILD_CACHE_JS" record --cmd "$DEV_BUILD_CMD" || true
162
+ fi
163
+ T_BACKEND="$(now_ms)"
164
+ elif [ "$WITH_DEV" = "1" ]; then
165
+ echo "[1b/5] no backend build declared (dev server only)"
166
+ fi
167
+
168
+ # 2. adb server + emulator + bounded boot gate (the primitive owns readiness).
169
+ # 4. The dev server is independent of the device, so when overlap is on it is
170
+ # started concurrently with the boot and joined after the install.
171
+ start_dev() {
172
+ echo "[4/5] dev server ($DEV_NAME) via serve.js --group $TIER_GROUP (mem<=$DEV_MEM_MAX)"
173
+ node scripts/serve.js start --cmd "$DEV_CMD" --url "$DEV_URL" --name "$DEV_NAME" --group "$TIER_GROUP" --mem-max "$DEV_MEM_MAX"
174
+ }
175
+
176
+ if [ "$PLATFORM" = "ios" ]; then
177
+ echo "[2/5] iOS Simulator (boot-emulator.sh delegates to ios-simulator-up.sh on platform=ios)"
178
+ else
179
+ echo "[2/5] adb server + emulator (boot-emulator.sh)"
180
+ fi
181
+ OVERLAP="${MOBILE_E2E_OVERLAP:-1}"
182
+ DEV_PID=""
183
+ if [ "$WITH_DEV" = "1" ] && [ "$OVERLAP" = "1" ]; then
184
+ # Boot in the foreground, dev server in the background; joined after install.
185
+ start_dev &
186
+ DEV_PID=$!
187
+ if ! bash scripts/qa/mobile-e2e/boot-emulator.sh; then
188
+ kill "$DEV_PID" 2>/dev/null || true
189
+ echo "FAIL — device bring-up failed; see boot-emulator.sh output and .serve/emulator.err.log" >&2
190
+ exit 1
191
+ fi
192
+ else
193
+ bash scripts/qa/mobile-e2e/boot-emulator.sh
194
+ fi
195
+ T_BOOT="$(now_ms)"
196
+
197
+ if [ "$PLATFORM" != "ios" ] && [ ! -x "$ADB" ]; then
198
+ echo "FAIL — adb not found at $ADB (set ANDROID_HOME)." >&2
199
+ exit 1
200
+ fi
201
+
202
+ # 3. Install the (now-built) APK onto the booted device. iOS installs the .app
203
+ # inside ios-simulator-up.sh, so there is nothing to do here.
204
+ if [ "$PLATFORM" = "ios" ]; then
205
+ echo "[3/5] install skipped (platform=ios — the app is installed by ios-simulator-up.sh)"
206
+ elif [ "${MOBILE_E2E_SKIP_INSTALL:-0}" != "1" ]; then
207
+ if [ -n "$APP_ID" ] && [ -f "$APK" ]; then
208
+ echo "[3/5] installing $APK"
209
+ timeout 300 "$ADB" install -r "$APK"
210
+ else
211
+ echo "[3/5] no APK at $APK (set local.json .apk or MOBILE_E2E_APK) — skipping install"
212
+ fi
213
+ else
214
+ echo "[3/5] install skipped"
215
+ fi
216
+ T_INSTALL="$(now_ms)"
217
+
218
+ # Join the concurrently-started dev server (its readiness is gated in step 5).
219
+ if [ "$WITH_DEV" = "1" ] && [ "$OVERLAP" != "1" ]; then
220
+ start_dev
221
+ elif [ "$WITH_DEV" != "1" ]; then
222
+ echo "[4/5] dev server skipped (--no-dev)"
223
+ elif [ -n "$DEV_PID" ]; then
224
+ # Already announced by start_dev; wait for its bounded readiness probe to end.
225
+ if ! wait "$DEV_PID"; then
226
+ echo "FAIL — dev server did not start (see .serve/$DEV_NAME.err.log)" >&2
227
+ exit 1
228
+ fi
229
+ fi
230
+ T_DEV="$(now_ms)"
231
+
232
+ # 5. Bounded readiness of the whole tier. The Android boot gate is adb-only;
233
+ # iOS readiness is the simulator install (already done) plus the dev URL.
234
+ echo "[5/5] readiness"
235
+ if [ "$PLATFORM" != "ios" ]; then
236
+ timeout 30 "$ADB" wait-for-device
237
+ boot=""
238
+ for _ in $(seq 1 30); do
239
+ boot="$(timeout 10 "$ADB" shell getprop sys.boot_completed 2>/dev/null | tr -d '\r' || true)"
240
+ [ "$boot" = "1" ] && break
241
+ sleep 2
242
+ done
243
+ [ "$boot" = "1" ] || { echo "FAIL — emulator did not finish booting." >&2; exit 1; }
244
+ fi
245
+
246
+ if [ "$WITH_DEV" = "1" ]; then
247
+ node scripts/wait-for.js --health "$DEV_URL" --timeout 120 --quiet || {
248
+ echo "FAIL — dev server not healthy at $DEV_URL (see .serve/$DEV_NAME.out.log)" >&2
249
+ exit 1
250
+ }
251
+ fi
252
+
253
+ node scripts/serve.js list
254
+ T_END="$(now_ms)"
255
+ timings="{\"build_ms\":$((T_BUILD-T_START)),\"backend_ms\":$((T_BACKEND-T_BUILD)),\"boot_ms\":$((T_BOOT-T_BACKEND)),\"install_ms\":$((T_INSTALL-T_BOOT)),\"dev_ms\":$((T_DEV-T_INSTALL)),\"ready_ms\":$((T_END-T_DEV)),\"total_ms\":$((T_END-T_START))}"
256
+ echo "device-up:timings $timings"
257
+ printf '%s\n' "$timings" >>"$SERVE_DIR/device-up-timings.jsonl" 2>/dev/null || true
258
+ echo "device-up: OK"
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # mobile E2E — bring an iOS Simulator DOWN (the iOS sibling of
4
+ # `device-down.sh`). Harness-owned; project values come from the sibling
5
+ # `local.json` `ios.deviceName` (or MOBILE_E2E_IOS_DEVICE_NAME / _UDID).
6
+ #
7
+ # Idempotent: a matching-but-already-gone simulator, a non-macOS host, or an
8
+ # unknown device all exit 0 — there is simply nothing to stop. Pass `--delete`
9
+ # to also remove the simulator device.
10
+ #
11
+ # Env overrides: MOBILE_E2E_IOS_DEVICE_NAME (and MOBILE_E2E_IOS_UDID to target
12
+ # an exact device instead of matching by name).
13
+ #
14
+ # Usage:
15
+ # scripts/qa/mobile-e2e/ios-simulator-down.sh # shutdown matching sim
16
+ # scripts/qa/mobile-e2e/ios-simulator-down.sh --delete # shutdown + delete it
17
+ set -euo pipefail
18
+
19
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
20
+ cd "$ROOT"
21
+ LOCAL_CONFIG="$ROOT/scripts/qa/mobile-e2e/local.json"
22
+
23
+ DELETE=0
24
+ for arg in "$@"; do
25
+ case "$arg" in
26
+ --delete) DELETE=1 ;;
27
+ -h|--help) sed -n '2,/^set -euo pipefail$/p' "${BASH_SOURCE[0]}" | sed '$d' | sed 's/^# \{0,1\}//'; exit 0 ;;
28
+ *) echo "unknown argument: $arg" >&2; exit 2 ;;
29
+ esac
30
+ done
31
+
32
+ # Not macOS → nothing this script owns can be running.
33
+ if ! command -v xcrun >/dev/null 2>&1; then
34
+ echo "ios-simulator-down: 'xcrun' not found (not macOS) — no iOS Simulator to stop."
35
+ exit 0
36
+ fi
37
+
38
+ DEVICE_NAME="${MOBILE_E2E_IOS_DEVICE_NAME:-$(node -e "try{const c=require('$LOCAL_CONFIG');process.stdout.write((c.ios||{}).deviceName||'')}catch(e){}" 2>/dev/null || true)}"
39
+ [ -z "$DEVICE_NAME" ] && DEVICE_NAME="iOS Simulator"
40
+ UDID="${MOBILE_E2E_IOS_UDID:-}"
41
+
42
+ if [ -z "$UDID" ]; then
43
+ UDID="$(
44
+ DEVICE_NAME="$DEVICE_NAME" node -e '
45
+ const { execFileSync } = require("child_process");
46
+ const name = process.env.DEVICE_NAME;
47
+ const list = JSON.parse(execFileSync("xcrun", ["simctl", "list", "devices", "-j"], { encoding: "utf8" }));
48
+ const all = [];
49
+ for (const devices of Object.values(list.devices || {})) {
50
+ for (const d of devices) all.push(d);
51
+ }
52
+ const booted = all.find((d) => d.name === name && d.state === "Booted");
53
+ const any = booted || all.find((d) => d.name === name);
54
+ if (any) process.stdout.write(any.udid);
55
+ ' 2>/dev/null || true
56
+ )"
57
+ fi
58
+
59
+ if [ -z "$UDID" ]; then
60
+ echo "ios-simulator-down: no simulator named '$DEVICE_NAME' — nothing to stop."
61
+ exit 0
62
+ fi
63
+
64
+ echo "ios-simulator-down: shutting down $DEVICE_NAME ($UDID)"
65
+ xcrun simctl shutdown "$UDID" 2>/dev/null || true
66
+
67
+ if [ "$DELETE" = "1" ]; then
68
+ echo "ios-simulator-down: deleting $UDID"
69
+ xcrun simctl delete "$UDID" 2>/dev/null || true
70
+ fi
71
+
72
+ echo "ios-simulator-down: OK"
@@ -0,0 +1,153 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # mobile E2E — bring an iOS Simulator UP with `xcrun simctl` (the iOS sibling of
4
+ # `boot-emulator.sh` / the device half of `device-up.sh`). Harness-owned; project
5
+ # values come from the sibling `local.json` `ios` block.
6
+ #
7
+ # What it does, idempotently:
8
+ # 1. resolve the `ios` block from `scripts/qa/mobile-e2e/local.json`
9
+ # (bundleId, deviceName, deviceType, appPath);
10
+ # 2. find a matching simulator — an already-booted one first, else any
11
+ # existing one, else CREATE it from deviceType + the newest available iOS
12
+ # runtime;
13
+ # 3. `xcrun simctl boot` + `bootstatus -b` (skip boot when already booted);
14
+ # 4. `xcrun simctl install` the unsigned `.app`;
15
+ # 5. print the device UDID + bundle id (and export them via GITHUB_ENV in CI).
16
+ #
17
+ # It fails LOUDLY when it cannot do its job: no `xcrun` (not macOS), no `.app`
18
+ # at the configured path, or no available iOS runtime. There is no silent
19
+ # fallback — a half-brought-up simulator would surface later as a mystery
20
+ # Maestro failure.
21
+ #
22
+ # Project config (never hardcoded here) — `scripts/qa/mobile-e2e/local.json`:
23
+ # ios.bundleId installed app bundle id (default com.example.app)
24
+ # ios.deviceName simulator name to find/create (default "iOS Simulator")
25
+ # ios.deviceType simctl device type (default iPhone-15)
26
+ # ios.appPath unsigned simulator .app (required; no default — fails loud)
27
+ # Env overrides: MOBILE_E2E_IOS_BUNDLE_ID / MOBILE_E2E_IOS_DEVICE_NAME /
28
+ # MOBILE_E2E_IOS_DEVICE_TYPE / MOBILE_E2E_IOS_APP / MOBILE_E2E_IOS_UDID.
29
+ #
30
+ # Usage:
31
+ # scripts/qa/mobile-e2e/ios-simulator-up.sh
32
+ set -euo pipefail
33
+
34
+ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd)"
35
+ cd "$ROOT"
36
+ LOCAL_CONFIG="$ROOT/scripts/qa/mobile-e2e/local.json"
37
+
38
+ cfg() {
39
+ node -e "try{const c=require('$LOCAL_CONFIG');const v=(c.ios||{})['$1'];process.stdout.write(v==null?'':String(v))}catch(e){}" 2>/dev/null || true
40
+ }
41
+
42
+ BUNDLE_ID="${MOBILE_E2E_IOS_BUNDLE_ID:-$(cfg bundleId)}"
43
+ DEVICE_NAME="${MOBILE_E2E_IOS_DEVICE_NAME:-$(cfg deviceName)}"
44
+ DEVICE_TYPE="${MOBILE_E2E_IOS_DEVICE_TYPE:-$(cfg deviceType)}"
45
+ APP="${MOBILE_E2E_IOS_APP:-$(cfg appPath)}"
46
+ [ -z "$BUNDLE_ID" ] && BUNDLE_ID="com.example.app"
47
+ [ -z "$DEVICE_NAME" ] && DEVICE_NAME="iOS Simulator"
48
+ [ -z "$DEVICE_TYPE" ] && DEVICE_TYPE="com.apple.CoreSimulator.SimDeviceType.iPhone-15"
49
+
50
+ # 0. macOS / Xcode tooling is a hard prerequisite. A Linux host cannot bring up
51
+ # an iOS Simulator; fail with the exact reason instead of a cryptic command
52
+ # error. (This is also why the boot path in `boot-emulator.sh` delegates
53
+ # here on `platform=ios` rather than trying any simctl logic inline.)
54
+ if ! command -v xcrun >/dev/null 2>&1; then
55
+ echo "FAIL — ios-simulator-up.sh requires macOS with Xcode command-line tools ('xcrun' not found)." >&2
56
+ echo " This route runs on a macOS host/CI runner; it cannot boot an iOS Simulator on Linux." >&2
57
+ exit 1
58
+ fi
59
+
60
+ # 1. Resolve the .app path (relative paths are repo-rooted) and require it. There
61
+ # is no default: a project must name its own simulator build artifact.
62
+ if [ -z "$APP" ]; then
63
+ echo "FAIL — no iOS simulator .app configured. Set MOBILE_E2E_IOS_APP or add" >&2
64
+ echo " \"ios\": { \"appPath\": \"<path>.app\" } to scripts/qa/mobile-e2e/local.json." >&2
65
+ exit 1
66
+ fi
67
+ case "$APP" in
68
+ /*) APP_ABS="$APP" ;;
69
+ *) APP_ABS="$ROOT/$APP" ;;
70
+ esac
71
+ if [ ! -d "$APP_ABS" ] && [ ! -f "$APP_ABS" ]; then
72
+ echo "FAIL — unsigned iOS simulator .app not found at: $APP_ABS" >&2
73
+ echo " Build it first, e.g.:" >&2
74
+ echo " cd mobile && npx eas-cli@latest build --platform ios --profile ios-simulator --local --non-interactive --output build/ios-simulator-app.app" >&2
75
+ exit 1
76
+ fi
77
+
78
+ # 2. Find or create the simulator. Prefer a booted match, then any match, then
79
+ # create one from the newest available iOS runtime. An explicit
80
+ # MOBILE_E2E_IOS_UDID targets an exact device and skips the name lookup.
81
+ find_udid() {
82
+ DEVICE_NAME="$DEVICE_NAME" node -e '
83
+ const { execFileSync } = require("child_process");
84
+ const name = process.env.DEVICE_NAME;
85
+ const list = JSON.parse(execFileSync("xcrun", ["simctl", "list", "devices", "-j"], { encoding: "utf8" }));
86
+ const all = [];
87
+ for (const devices of Object.values(list.devices || {})) {
88
+ for (const d of devices) all.push(d);
89
+ }
90
+ const booted = all.find((d) => d.name === name && d.state === "Booted");
91
+ const any = booted || all.find((d) => d.name === name);
92
+ if (any) process.stdout.write(any.udid);
93
+ ' 2>/dev/null || true
94
+ }
95
+
96
+ UDID="${MOBILE_E2E_IOS_UDID:-}"
97
+ if [ -z "$UDID" ]; then
98
+ UDID="$(find_udid)"
99
+ fi
100
+ if [ -n "$UDID" ]; then
101
+ echo "ios-simulator-up: reusing simulator '$DEVICE_NAME' ($UDID)"
102
+ else
103
+ RUNTIME="$(
104
+ node -e '
105
+ const { execFileSync } = require("child_process");
106
+ const list = JSON.parse(execFileSync("xcrun", ["simctl", "list", "runtimes", "-j"], { encoding: "utf8" }));
107
+ const ios = (list.runtimes || [])
108
+ .filter((r) => r.isAvailable !== false && /iOS/i.test(r.name || ""))
109
+ .sort((a, b) => String(b.version || "").localeCompare(String(a.version || ""), undefined, { numeric: true }));
110
+ if (ios[0]) process.stdout.write(ios[0].identifier);
111
+ ' 2>/dev/null || true
112
+ )"
113
+ if [ -z "$RUNTIME" ]; then
114
+ echo "FAIL — no available iOS Simulator runtime found (install an iOS runtime via Xcode)." >&2
115
+ exit 1
116
+ fi
117
+ UDID="$(xcrun simctl create "$DEVICE_NAME" "$DEVICE_TYPE" "$RUNTIME")"
118
+ echo "ios-simulator-up: created simulator '$DEVICE_NAME' ($UDID) on $RUNTIME"
119
+ fi
120
+
121
+ # 3. Boot (idempotent) and wait for it to finish booting.
122
+ STATE="$(
123
+ UDID="$UDID" node -e '
124
+ const { execFileSync } = require("child_process");
125
+ const list = JSON.parse(execFileSync("xcrun", ["simctl", "list", "devices", "-j"], { encoding: "utf8" }));
126
+ for (const devices of Object.values(list.devices || {})) {
127
+ for (const d of devices) if (d.udid === process.env.UDID) { process.stdout.write(d.state); return; }
128
+ }
129
+ ' 2>/dev/null || true
130
+ )"
131
+ if [ "$STATE" != "Booted" ]; then
132
+ echo "ios-simulator-up: booting $UDID"
133
+ xcrun simctl boot "$UDID"
134
+ else
135
+ echo "ios-simulator-up: already booted $UDID"
136
+ fi
137
+ xcrun simctl bootstatus "$UDID" -b
138
+
139
+ # 4. Install the unsigned .app.
140
+ echo "ios-simulator-up: installing $APP_ABS"
141
+ xcrun simctl install "$UDID" "$APP_ABS"
142
+
143
+ # 5. Report identity (machine-readable first) and export to CI.
144
+ echo "UDID=$UDID"
145
+ echo "BUNDLE_ID=$BUNDLE_ID"
146
+ echo "ios-simulator-up: device=$DEVICE_NAME udid=$UDID bundle=$BUNDLE_ID app=$APP_ABS"
147
+ if [ -n "${GITHUB_ENV:-}" ]; then
148
+ {
149
+ echo "MOBILE_E2E_IOS_UDID=$UDID"
150
+ echo "MOBILE_E2E_IOS_BUNDLE_ID=$BUNDLE_ID"
151
+ } >>"$GITHUB_ENV"
152
+ fi
153
+ echo "ios-simulator-up: OK"
@@ -0,0 +1,181 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ /**
5
+ * mobile E2E — job progress events (harness-owned).
6
+ *
7
+ * A detached device run is otherwise opaque to the agent: it can only guess a
8
+ * finish time and poll a log. This module is the machine-readable progress bus
9
+ * that makes the run OBSERVABLE without the agent polling:
10
+ *
11
+ * * `run-maestro.js` appends one JSON line per scenario as it starts/finishes;
12
+ * * `run-detached.sh` records the job (pid + log + events path) and points the
13
+ * runner at the events file;
14
+ * * the `job-notify` opencode plugin tails the events file and pushes a TUI
15
+ * notification per scenario, waking the agent (session.prompt) on the
16
+ * first failure and at completion.
17
+ *
18
+ * Pure and dependency-free so both the runner and the plugin (and the tests)
19
+ * can require it. Every write is best-effort: a missing events file must never
20
+ * fail an otherwise valid run.
21
+ */
22
+
23
+ const fs = require("fs");
24
+ const path = require("path");
25
+
26
+ /** Append one event as a JSON line. Best-effort (never throws). */
27
+ function appendEvent(file, event) {
28
+ if (!file) return false;
29
+ try {
30
+ fs.mkdirSync(path.dirname(file), { recursive: true });
31
+ fs.appendFileSync(file, `${JSON.stringify(event)}\n`, "utf8");
32
+ return true;
33
+ } catch (_) {
34
+ return false;
35
+ }
36
+ }
37
+
38
+ /** Parse a JSONL events file; corrupt/partial lines are skipped. */
39
+ function readEvents(file) {
40
+ let text;
41
+ try {
42
+ text = fs.readFileSync(file, "utf8");
43
+ } catch (_) {
44
+ return [];
45
+ }
46
+ const out = [];
47
+ for (const line of text.split(/\r?\n/)) {
48
+ const trimmed = line.trim();
49
+ if (!trimmed) continue;
50
+ try {
51
+ const event = JSON.parse(trimmed);
52
+ if (event && typeof event.type === "string") out.push(event);
53
+ } catch (_) {
54
+ /* a partially-written trailing line is expected while the run is live */
55
+ }
56
+ }
57
+ return out;
58
+ }
59
+
60
+ /** Compact duration for a progress line (`0s`, `45s`, `2m 5s`). */
61
+ function fmtDur(ms) {
62
+ const n = Number(ms);
63
+ if (!Number.isFinite(n) || n < 0) return "?";
64
+ if (n < 1000) return "0s";
65
+ const s = Math.round(n / 1000);
66
+ if (s < 60) return `${s}s`;
67
+ const m = Math.floor(s / 60);
68
+ return s % 60 ? `${m}m ${s % 60}s` : `${m}m`;
69
+ }
70
+
71
+ /** One-line, ASCII progress text for a single event, or null if not notable. */
72
+ function progressLine(event) {
73
+ if (!event || typeof event !== "object") return null;
74
+ switch (event.type) {
75
+ case "matrix_start":
76
+ return `matrix start: ${event.total} journey(s) [${event.mode || "run"}]`;
77
+ case "flow_start":
78
+ return `flow start (${event.index}/${event.total}): ${event.name}${event.actor ? ` [actor=${event.actor}]` : ""}`;
79
+ case "flow_result":
80
+ return event.status === "pass"
81
+ ? `flow pass: ${event.name}`
82
+ : `flow FAIL: ${event.name} — ${event.reason || "unknown reason"}`;
83
+ case "fail_fast":
84
+ return `FAIL-FAST: ${event.count} flow(s) share a reason — ${event.signature || ""}`;
85
+ case "matrix_done":
86
+ return `matrix done: ${event.passed} passed / ${event.failed} failed (${event.total} total)`;
87
+ case "invocation_heartbeat":
88
+ return ` … invocation (${event.index}/${event.total}) alive: ${fmtDur(event.elapsedMs)} elapsed, last output ${fmtDur(event.msSinceOutput)} ago`;
89
+ case "invocation_stalled":
90
+ return `invocation (${event.index}/${event.total}) STALLED — no output for ${fmtDur(event.msSinceOutput)} (possible hang): ${(event.flows || []).join(", ")}`;
91
+ case "matrix_aborted":
92
+ return `matrix ABORTED${event.by ? ` by ${event.by}` : ""}${event.reason ? ` — ${event.reason}` : ""}`;
93
+ default:
94
+ return null;
95
+ }
96
+ }
97
+
98
+ /** Reduce the event stream to a compact summary the notifier/agent can consume. */
99
+ function summarize(events) {
100
+ const list = Array.isArray(events) ? events : [];
101
+ const results = list.filter((e) => e.type === "flow_result");
102
+ const start = list.find((e) => e.type === "matrix_start");
103
+ const done = [...list].reverse().find((e) => e.type === "matrix_done");
104
+ const failFast = list.find((e) => e.type === "fail_fast");
105
+ const aborted = [...list].reverse().find((e) => e.type === "matrix_aborted");
106
+ const stalled = [...list].reverse().find((e) => e.type === "invocation_stalled");
107
+ const passes = results.filter((e) => e.status === "pass").map((e) => e.name);
108
+ const failures = results
109
+ .filter((e) => e.status !== "pass")
110
+ .map((e) => ({ name: e.name, reason: e.reason || "unknown reason" }));
111
+ return {
112
+ total: start ? start.total : results.length,
113
+ startedCount: results.length,
114
+ passed: passes.length,
115
+ failed: failures.length,
116
+ passes,
117
+ failures,
118
+ failFast: failFast ? { count: failFast.count, signature: failFast.signature || "" } : null,
119
+ aborted: !!aborted,
120
+ abortedReason: aborted ? aborted.reason || "" : null,
121
+ stalled: !!stalled,
122
+ done: !!done,
123
+ reportPath: done && done.report ? done.report : null,
124
+ };
125
+ }
126
+
127
+ /** The notification body injected into the session on completion / first failure. */
128
+ function notificationText(summary, opts) {
129
+ const s = summary || {};
130
+ const head = s.aborted
131
+ ? `Mobile E2E ABORTED${s.abortedReason ? ` — ${s.abortedReason}` : ""}: ${s.passed} passed / ${s.failed} failed so far (of ${s.total}).`
132
+ : s.done
133
+ ? `Mobile E2E finished: ${s.passed} passed / ${s.failed} failed (of ${s.total}).`
134
+ : `Mobile E2E progress: ${s.passed} passed / ${s.failed} failed so far (of ${s.total}).`;
135
+ const lines = [head];
136
+ if (s.stalled && !s.aborted && !s.done) {
137
+ lines.push("A stalled invocation is flagged in the events (possible hang) — stop it with: run-detached.sh --stop <job-id>.");
138
+ }
139
+ if (s.failFast) {
140
+ lines.push(`Fail-fast stop: ${s.failFast.count} flow(s) share a reason — ${s.failFast.signature}`);
141
+ }
142
+ if (s.failures && s.failures.length) {
143
+ lines.push("Failures:");
144
+ for (const f of s.failures.slice(0, 12)) lines.push(` - ${f.name}: ${f.reason}`);
145
+ if (s.failures.length > 12) lines.push(` … and ${s.failures.length - 12} more`);
146
+ }
147
+ const report = (opts && opts.reportPath) || s.reportPath;
148
+ if (report) lines.push(`Report: ${report}`);
149
+ if (opts && opts.eventsPath) lines.push(`Events: ${opts.eventsPath}`);
150
+ if (!s.aborted) {
151
+ lines.push(
152
+ "Continue F-291: classify each failure (harness-side vs mobile/**) from the report + per-flow artifacts before editing."
153
+ );
154
+ }
155
+ return lines.join("\n");
156
+ }
157
+
158
+ function main() {
159
+ const argv = process.argv.slice(2);
160
+ const cmd = argv[0];
161
+ const file = argv[1];
162
+ if (cmd === "--render") {
163
+ const skipIdx = argv.indexOf("--skip");
164
+ const skip = skipIdx >= 0 ? Number(argv[skipIdx + 1]) || 0 : 0;
165
+ for (const event of readEvents(file).slice(skip)) {
166
+ const line = progressLine(event);
167
+ if (line) console.log(line);
168
+ }
169
+ return;
170
+ }
171
+ if (cmd === "--summary") {
172
+ console.log(notificationText(summarize(readEvents(file))));
173
+ return;
174
+ }
175
+ console.error("usage: job-events.js --render <events.jsonl> [--skip N] | --summary <events.jsonl>");
176
+ process.exitCode = 2;
177
+ }
178
+
179
+ if (require.main === module) main();
180
+
181
+ module.exports = { appendEvent, readEvents, progressLine, summarize, notificationText, fmtDur };