Atom eve seo
This commit is contained in:
19
agent/sandbox/sandbox.ts
Normal file
19
agent/sandbox/sandbox.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { defineSandbox, defaultBackend } from "eve/sandbox";
|
||||
|
||||
export default defineSandbox({
|
||||
backend: defaultBackend({
|
||||
// The auditor must reach any site it is pointed at, so it keeps an
|
||||
// open network policy rather than an allowlist.
|
||||
vercel: { networkPolicy: "allow-all" },
|
||||
docker: { networkPolicy: "allow-all" },
|
||||
}),
|
||||
// Bump the suffix to force a template rebuild after changing the setup scripts.
|
||||
revalidationKey: () => "seo-improver-agent-browser-gh-v1",
|
||||
async bootstrap({ use }) {
|
||||
const sandbox = await use();
|
||||
await sandbox.run({ command: "bash setup-agent-browser.sh" });
|
||||
// `gh` is only used when a blog repo is configured for the optional
|
||||
// pull-request flow; installing it is cheap and keeps setup uniform.
|
||||
await sandbox.run({ command: "bash setup-gh.sh seo-improver" });
|
||||
},
|
||||
});
|
||||
88
agent/sandbox/workspace/setup-agent-browser.sh
Normal file
88
agent/sandbox/workspace/setup-agent-browser.sh
Normal file
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
|
||||
mkdir -p "${AGENT_BROWSER_ASSETS_DIR:-reports/assets}"
|
||||
if [ ! -f package.json ]; then
|
||||
npm init -y >/dev/null
|
||||
fi
|
||||
if [ ! -x node_modules/.bin/agent-browser ]; then
|
||||
npm install agent-browser@latest playwright@latest "$@"
|
||||
fi
|
||||
|
||||
install_agent_browser_shim() {
|
||||
local bin_dir="/usr/local/bin"
|
||||
mkdir -p "$bin_dir"
|
||||
cat > "$bin_dir/agent-browser" <<'SHIM'
|
||||
#!/usr/bin/env bash
|
||||
exec /workspace/node_modules/.bin/agent-browser "$@"
|
||||
SHIM
|
||||
chmod +x "$bin_dir/agent-browser"
|
||||
}
|
||||
|
||||
install_agent_browser_shim
|
||||
|
||||
run_agent_browser_setup_check() {
|
||||
if command -v timeout >/dev/null 2>&1; then
|
||||
timeout 60s npx agent-browser --session setup-check open about:blank >/tmp/agent-browser-setup-check.log 2>&1
|
||||
else
|
||||
npx agent-browser --session setup-check open about:blank >/tmp/agent-browser-setup-check.log 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
validate_agent_browser_config() {
|
||||
echo "[setup-agent-browser] validating browser launch..."
|
||||
if run_agent_browser_setup_check; then
|
||||
npx agent-browser --session setup-check close >/dev/null 2>&1 || true
|
||||
echo "[setup-agent-browser] browser launch validation passed."
|
||||
return 0
|
||||
fi
|
||||
|
||||
npx agent-browser --session setup-check close >/dev/null 2>&1 || true
|
||||
echo "[setup-agent-browser] browser launch validation failed:" >&2
|
||||
cat /tmp/agent-browser-setup-check.log >&2 || true
|
||||
rm -f agent-browser.json
|
||||
return 1
|
||||
}
|
||||
|
||||
if [ -f .agent-browser-ready ] && validate_agent_browser_config; then
|
||||
exit 0
|
||||
fi
|
||||
rm -f .agent-browser-ready
|
||||
|
||||
install_system_chromium() {
|
||||
if ! command -v apt-get >/dev/null 2>&1; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
echo "[setup-agent-browser] installing system Chromium..."
|
||||
apt-get update
|
||||
if ! apt-get install -y --no-install-recommends chromium; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
CHROMIUM_PATH="$(command -v chromium || command -v chromium-browser || true)"
|
||||
if [ -z "$CHROMIUM_PATH" ]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
printf '{"executablePath":"%s","args":"--no-sandbox"}\n' "$CHROMIUM_PATH" > agent-browser.json
|
||||
echo "[setup-agent-browser] using Chromium at $CHROMIUM_PATH"
|
||||
validate_agent_browser_config
|
||||
}
|
||||
|
||||
install_playwright_chromium() {
|
||||
echo "[setup-agent-browser] installing Playwright Chromium fallback..."
|
||||
npx playwright install --with-deps chromium
|
||||
CHROMIUM_PATH="$(node -e "const { chromium } = require('playwright'); console.log(chromium.executablePath())")"
|
||||
printf '{"executablePath":"%s","args":"--no-sandbox"}\n' "$CHROMIUM_PATH" > agent-browser.json
|
||||
echo "[setup-agent-browser] using Playwright Chromium at $CHROMIUM_PATH"
|
||||
validate_agent_browser_config
|
||||
}
|
||||
|
||||
if ! install_system_chromium; then
|
||||
echo "[setup-agent-browser] system Chromium unavailable or unusable; falling back to Playwright Chromium..."
|
||||
install_playwright_chromium
|
||||
fi
|
||||
touch .agent-browser-ready
|
||||
32
agent/sandbox/workspace/setup-gh.sh
Normal file
32
agent/sandbox/workspace/setup-gh.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
AGENT_NAME="${1:-atom-eve-agent}"
|
||||
|
||||
if ! command -v gh >/dev/null 2>&1; then
|
||||
GH_VERSION="2.62.0"
|
||||
TARBALL="gh_${GH_VERSION}_linux_amd64.tar.gz"
|
||||
URL="https://github.com/cli/cli/releases/download/v${GH_VERSION}/${TARBALL}"
|
||||
|
||||
mkdir -p "$HOME/.local"
|
||||
curl -fsSL "$URL" -o "/tmp/${TARBALL}"
|
||||
tar -xzf "/tmp/${TARBALL}" -C "$HOME/.local" --strip-components=1
|
||||
rm -f "/tmp/${TARBALL}"
|
||||
|
||||
export PATH="$HOME/.local/bin:$PATH"
|
||||
if ! grep -qs '.local/bin' "$HOME/.profile" 2>/dev/null; then
|
||||
printf '\nexport PATH="$HOME/.local/bin:$PATH"\n' >> "$HOME/.profile"
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! command -v gh >/dev/null 2>&1; then
|
||||
echo "gh installed but not found on PATH; expected $HOME/.local/bin/gh" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git config --global user.name "$AGENT_NAME"
|
||||
git config --global user.email "${AGENT_NAME}@users.noreply.github.com"
|
||||
|
||||
if gh auth status >/dev/null 2>&1; then
|
||||
gh auth setup-git >/dev/null 2>&1 || true
|
||||
fi
|
||||
Reference in New Issue
Block a user