From 4a7a0b04264b7a7edd4e2f7e2537feb182984ad0 Mon Sep 17 00:00:00 2001 From: Roy Osherove <575051+royosherove@users.noreply.github.com> Date: Sun, 23 Aug 2026 00:14:12 +0000 Subject: [PATCH] fix(kirocrew): make Playwright reachable + install Chromium deps on AL2023 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to #94 addressing three Codex P1s posted on commit 3e4984a814 after that PR was merged. All three affect the KiroCrew Playwright preinstall on the AL2023 ARM64 production target. P1 #1 — playwright-cli not on the gateway service PATH packs/kirocrew/install.sh:346 (before this commit) mise's global npm prefix is only on PATH during install; the systemd unit hardcodes PATH and does not activate mise, so the global playwright-cli was unreachable from gateway-spawned agents. P1 #2 — mise node binary also missing from the gateway PATH packs/kirocrew/install.sh:358 (before this commit) playwright-cli's launcher uses '#!/usr/bin/env node'; symlinking the launcher alone still fails with 'node: No such file or directory' because node itself only lives under mise. P1 #3 — --with-deps only supports apt-get; target is AL2023 (dnf) packs/kirocrew/install.sh:367 (before this commit) Playwright's Linux dependency phase queues apt-get update/install. On AL2023 this silently no-ops or errors and leaves Chromium's system libs unavailable. Two-layer fix for #1 + #2: a) packs/kirocrew/resources/kirocrew-gateway.service — prepend the mise shims directory (/home/ec2-user/.local/share/mise/shims) to the unit's Environment=PATH so node, npm and playwright-cli all resolve at service runtime the same way they do in an interactive shell. b) packs/kirocrew/install.sh — belt-and-suspenders: symlink both playwright-cli AND node into ~/.local/bin (already on the unit's PATH) in case shim generation lags or the user's mise layout differs. Fix for #3: Replace 'playwright-cli install-browser --with-deps' with an explicit dnf install of the AL2023 package names Playwright needs for Chromium (nss, nspr, atk, at-spi2-atk, cups-libs, libdrm, libxkbcommon, libX {composite,damage,fixes,randr}, mesa-libgbm, alsa-lib, pango, cairo), then run 'install-browser chromium' without --with-deps for the browser binary itself. Non-fatal warn paths preserved so a partial failure doesn't take down the whole install. bash -n clean on install.sh; systemd-analyze verify clean on the .service (existing __HOME__ placeholder warning is pre-existing and expected — deploy/bootstrap.sh substitutes it before enabling the unit). Refs: https://github.com/inceptionstack/lowkey/pull/94#discussion (P1 x3 on 3e4984a814) --- packs/kirocrew/install.sh | 66 ++++++++++++++----- .../resources/kirocrew-gateway.service | 2 +- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/packs/kirocrew/install.sh b/packs/kirocrew/install.sh index 12f0d69..1f98a12 100755 --- a/packs/kirocrew/install.sh +++ b/packs/kirocrew/install.sh @@ -347,27 +347,63 @@ if command -v npm >/dev/null 2>&1; then if command -v playwright-cli >/dev/null 2>&1; then ok "@playwright/cli installed: $(playwright-cli --version 2>/dev/null || echo unknown)" - # Ensure the kirocrew-gateway systemd unit can resolve playwright-cli. - # The unit's PATH is hardcoded to /home/ec2-user/.local/bin:/usr/local/bin: - # /usr/bin:/bin (see resources/kirocrew-gateway.service) and does NOT - # activate mise, so the mise-managed npm prefix isn't on the unit's PATH. - # Symlink the binary into ~/.local/bin, which the unit already includes. + # Ensure the kirocrew-gateway systemd unit can resolve BOTH playwright-cli + # AND its node runtime. playwright-cli's launcher uses `#!/usr/bin/env node`, + # so a symlink of the launcher alone isn't enough — node itself lives under + # mise and isn't on the unit's PATH by default. Two-layer fix: + # (a) The unit's PATH now includes ~/.local/share/mise/shims (see + # resources/kirocrew-gateway.service), so mise-managed node + npm + # binaries resolve at service runtime. + # (b) As a belt-and-suspenders (in case shim generation lags or the + # user's mise layout differs), symlink node + playwright-cli into + # ~/.local/bin which the unit's PATH also includes. _pw_bin="$(command -v playwright-cli)" + _node_bin="$(command -v node 2>/dev/null || true)" _pw_link_dir="${HOME:-/home/ec2-user}/.local/bin" mkdir -p "${_pw_link_dir}" ln -sfn "${_pw_bin}" "${_pw_link_dir}/playwright-cli" - ok "Symlinked ${_pw_link_dir}/playwright-cli -> ${_pw_bin} (for kirocrew-gateway systemd unit PATH)" - - # 2. Install Chromium + system deps. --with-deps invokes sudo to install - # system libraries via the OS package manager (dnf on AL2023). - # Chromium binary goes to ~/.cache/ms-playwright/ (per-user cache, - # which is what the kirocrew-gateway process reads since it runs - # as ec2-user). - log "Installing Chromium browser + system dependencies (may take 1-3 minutes)..." - if playwright-cli install-browser --with-deps 2>&1 | while IFS= read -r line; do log " playwright: ${line}"; done; then + if [[ -n "${_node_bin}" ]]; then + ln -sfn "${_node_bin}" "${_pw_link_dir}/node" + ok "Symlinked ${_pw_link_dir}/{playwright-cli,node} for kirocrew-gateway systemd unit PATH" + else + warn "node binary not found on PATH at install time — gateway will rely on mise shims dir" + fi + + # 2. Install Chromium system dependencies via dnf (AL2023 ARM64). + # Playwright's built-in `--with-deps` only supports apt-get, so on + # AL2023 we install the required libraries explicitly, then run + # `install-browser` WITHOUT `--with-deps` (browser binary only). + # Package list derived from Playwright's Linux dependency map for + # Chromium, translated to the AL2023 package names. + log "Installing Chromium system dependencies via dnf (AL2023 ARM64)..." + _chromium_deps=( + nss + nspr + atk + at-spi2-atk + cups-libs + libdrm + libxkbcommon + libXcomposite + libXdamage + libXfixes + libXrandr + mesa-libgbm + alsa-lib + pango + cairo + ) + if sudo dnf install -y "${_chromium_deps[@]}" 2>&1 | while IFS= read -r line; do log " dnf: ${line}"; done; then + ok "Chromium system dependencies installed" + else + warn "dnf install for Chromium deps failed — browser install may still succeed if libs pre-exist (non-fatal)" + fi + + log "Installing Chromium browser binary (may take 1-3 minutes)..." + if playwright-cli install-browser chromium 2>&1 | while IFS= read -r line; do log " playwright: ${line}"; done; then ok "Chromium browser installed under ~/.cache/ms-playwright/" else - warn "playwright-cli install-browser failed — agent can retry on first use, but may need sudo for --with-deps (non-fatal)" + warn "playwright-cli install-browser failed — agent can retry on first use (non-fatal)" fi else warn "@playwright/cli installed but 'playwright-cli' not on PATH; skipping browser install" diff --git a/packs/kirocrew/resources/kirocrew-gateway.service b/packs/kirocrew/resources/kirocrew-gateway.service index 6e75770..545ef9a 100644 --- a/packs/kirocrew/resources/kirocrew-gateway.service +++ b/packs/kirocrew/resources/kirocrew-gateway.service @@ -11,7 +11,7 @@ Environment=KIROCREW_PORT=__PORT__ Environment=KIROCREW_HOME=__HOME__ Environment=KIROCREW_HOST=0.0.0.0 Environment=KIROCREW_BIND=0.0.0.0 -Environment=PATH=/home/ec2-user/.local/bin:/usr/local/bin:/usr/bin:/bin +Environment=PATH=/home/ec2-user/.local/share/mise/shims:/home/ec2-user/.local/bin:/usr/local/bin:/usr/bin:/bin # Source ~/.kiro/env for KIRO_API_KEY (headless mode). Wrapping in bash # because systemd EnvironmentFile doesn't support 'export' prefix syntax. ExecStart=/bin/bash -c 'if [[ -f /home/ec2-user/.kiro/env ]]; then source /home/ec2-user/.kiro/env; fi && exec __BINPATH__ gateway'