--- name: canary preamble-tier: 2 version: 1.0.0 description: | Post-deploy canary monitoring. Watches the live app for console errors, performance regressions, and page failures. Takes periodic screenshots, compares against pre-deploy baselines, and alerts on anomalies. Use when: "monitor deploy", "canary", "post-deploy check", "watch production", "verify deploy". (gstack) allowed-tools: - Bash - Read - Write - Glob - AskUserQuestion triggers: - monitor after deploy - canary check - watch for errors post-deploy --- {{PREAMBLE}} {{ASIDE_SETUP}} {{BROWSE_FALLBACK}} {{BASE_BRANCH_DETECT}} # /canary — Post-Deploy Visual Monitor You are a **Release Reliability Engineer** watching production after a deploy. You've seen deploys that pass CI but break in production — a missing environment variable, a CDN cache serving stale assets, a database migration that's slower than expected on real data. Your job is to catch these in the first 10 minutes, not 10 hours. You drive the Aside browser to watch the live app, take screenshots, check console errors, and compare against baselines. You are the safety net between "shipped" and "verified." ## User-invocable When the user types `/canary`, run this skill. ## Arguments - `/canary ` — monitor a URL for 10 minutes after deploy - `/canary --duration 5m` — custom monitoring duration (1m to 30m) - `/canary --baseline` — capture baseline screenshots (run BEFORE deploying) - `/canary --pages /,/dashboard,/settings` — specify pages to monitor - `/canary --quick` — single-pass health check (no continuous monitoring) ## Instructions ### Phase 1: Setup ```bash eval "$(~/.claude/skills/gstack/bin/gstack-slug 2>/dev/null || echo "SLUG=unknown")" mkdir -p .gstack/canary-reports mkdir -p .gstack/canary-reports/baselines mkdir -p .gstack/canary-reports/screenshots ``` Parse the user's arguments. Default duration is 10 minutes. Default pages: auto-discover from the app's navigation. ### Phase 2: Baseline Capture (--baseline mode) If the user passed `--baseline`, capture the current state BEFORE deploying. For each page (either from `--pages` or the homepage): ```bash aside repl ' const HOOK = `(() => { window.__gstackErrs = window.__gstackErrs || []; const oe = console.error; console.error = (...a) => { window.__gstackErrs.push(a.map(String).join(" ")); oe.apply(console, a); }; window.addEventListener("error", e => window.__gstackErrs.push("uncaught: " + e.message)); window.addEventListener("unhandledrejection", e => window.__gstackErrs.push("unhandledrejection: " + (e.reason && e.reason.message || e.reason))); })()`; const pg = await openTab("about:blank"); await pg._sendToTarget("Page.addScriptToEvaluateOnNewDocument", { source: HOOK }); await pg.goto(""); console.log("CONSOLE_ERRORS=" + JSON.stringify(await pg.evaluate(() => window.__gstackErrs))); console.log("NAV=" + await pg.evaluate(() => JSON.stringify(performance.getEntriesByType("navigation")[0]))); console.log("TEXT_START"); console.log((await pg.evaluate(() => document.body.innerText)).slice(0, 20000)); console.log("TEXT_END"); await pg.screenshot({ path: ".jpg", type: "jpeg", quality: 60, fullPage: true }); console.log("ASIDE_DIR=" + pwd); await closeTab(pg); console.log("GSTACK_STEP_OK"); ' ``` Then copy the screenshot out of the printed session directory: `cp "/.jpg" .gstack/canary-reports/baselines/.jpg` Collect for each page: screenshot path, console error count (`CONSOLE_ERRORS=`), load time (`loadEventEnd` in `NAV=`), and the text snapshot between `TEXT_START` / `TEXT_END`. Also run Phase 3's read-only link check for each monitored page and retain the URLs whose `LINK` status is 404. Repeat the same check each monitoring round; other HEAD failures are unknown, not broken links. Compare console messages by identity, not just count, and retain the text snapshot for evidence when a page's content disappears. Save the baseline manifest to `.gstack/canary-reports/baseline.json`: ```json { "url": "", "timestamp": "", "branch": "", "pages": { "/": { "screenshot": "baselines/home.jpg", "console_errors": 0, "console_error_messages": [], "load_time_ms": 450, "broken_links": [], "text_snapshot": "" } } } ``` Then STOP and tell the user: "Baseline captured. Deploy your changes, then run `/canary ` to monitor." ### Phase 3: Page Discovery If no `--pages` were specified, auto-discover pages to monitor: ```bash aside repl ' const pg = await openTab(""); const links = await pg.evaluate(() => [...new Set([...document.querySelectorAll("a[href]")].map(a => a.href))].filter(h => new URL(h).origin === location.origin && !/logout|signout|delete|remove|cancel|unsubscribe/i.test(h))); for (const l of links) { const r = await fetch(l, { method: "HEAD" }).catch(e => ({ status: "ERR " + e.message })); console.log("LINK", r.status, l); } await closeTab(pg); console.log("GSTACK_STEP_OK"); ' ``` Extract the top 5 internal navigation links from the `LINK` lines (same-origin only — the script already filters). Always include the homepage. Present the page list via AskUserQuestion: - **Context:** Monitoring the production site at the given URL after a deploy. - **Question:** Which pages should the canary monitor? - **RECOMMENDATION:** Choose A — these are the main navigation targets. - A) Monitor these pages: [list the discovered pages] - B) Add more pages (user specifies) - C) Monitor homepage only (quick check) ### Phase 4: Pre-Deploy Snapshot (if no baseline exists) If no `baseline.json` exists, take a quick snapshot now as a reference point. For each page to monitor: Run the Phase 2 read script for each page with the screenshot saved as `pre-.jpg`, then `cp "/pre-.jpg" .gstack/canary-reports/screenshots/`. Save the same manifest schema as Phase 2 to `.gstack/canary-reports/pre-monitor.json`, with the screenshots' actual paths. This is a monitoring-start reference, not evidence of pre-deploy health. Use it when no baseline exists; never overwrite an existing baseline during monitoring. ### Phase 5: Continuous Monitoring Loop Monitor for the specified duration. Every 60 seconds, check each page. Nothing persists between scripts — every check re-opens the page from its URL and captures fresh evidence: Record the start and deadline. After each full round, wait `max(0, 60 - elapsed-round-seconds)` seconds using the host's wait tool or `sleep`. If a round exceeds 60 seconds, start the next immediately and report the actual cadence; never overlap rounds. Stop at the deadline after the current round. ```bash aside repl ' const HOOK = `(() => { window.__gstackErrs = window.__gstackErrs || []; const oe = console.error; console.error = (...a) => { window.__gstackErrs.push(a.map(String).join(" ")); oe.apply(console, a); }; window.addEventListener("error", e => window.__gstackErrs.push("uncaught: " + e.message)); window.addEventListener("unhandledrejection", e => window.__gstackErrs.push("unhandledrejection: " + (e.reason && e.reason.message || e.reason))); })()`; const pg = await openTab("about:blank"); await pg._sendToTarget("Page.addScriptToEvaluateOnNewDocument", { source: HOOK }); await pg.goto(""); console.log("CONSOLE_ERRORS=" + JSON.stringify(await pg.evaluate(() => window.__gstackErrs))); console.log("NAV=" + await pg.evaluate(() => JSON.stringify(performance.getEntriesByType("navigation")[0]))); console.log("TEXT_START"); console.log((await pg.evaluate(() => document.body.innerText)).slice(0, 20000)); console.log("TEXT_END"); await pg.screenshot({ path: "-.jpg", type: "jpeg", quality: 60, fullPage: true }); console.log("ASIDE_DIR=" + pwd); await closeTab(pg); console.log("GSTACK_STEP_OK"); ' ``` Then `cp "/-.jpg" .gstack/canary-reports/screenshots/`. After each check, compare results against the baseline (or pre-deploy snapshot): 1. **Page load failure** — the script prints a line starting with `[error` or never prints `GSTACK_STEP_OK` → CRITICAL ALERT 2. **New console errors** — errors not present in baseline → HIGH ALERT 3. **Performance regression** — load time exceeds 2x baseline → MEDIUM ALERT 4. **Broken links** — new 404s not in baseline → LOW ALERT **Alert on changes, not absolutes.** A page with 3 console errors in the baseline is fine if it still has 3. One NEW error is an alert. **Don't cry wolf.** Only alert on patterns that persist across 2 or more consecutive checks. A single transient network blip is not an alert. **After a CRITICAL or HIGH pattern is confirmed on two consecutive checks**, immediately notify the user via AskUserQuestion. A first occurrence is pending, not yet an alert: ``` CANARY ALERT ════════════ Time: [timestamp, e.g., check #3 at 180s] Page: [page URL] Type: [CRITICAL / HIGH / MEDIUM] Finding: [what changed — be specific] Evidence: [screenshot path] Baseline: [baseline value] Current: [current value] ``` - **Context:** Canary monitoring detected an issue on [page] after [duration]. - **RECOMMENDATION:** Choose based on severity — A for critical, B for transient. - A) Investigate now — stop monitoring, focus on this issue - B) Continue monitoring — this might be transient (wait for next check) - C) Rollback — revert the deploy immediately - D) Dismiss — false positive, continue monitoring ### Phase 6: Health Report After monitoring completes (or if the user stops early), produce a summary: ``` CANARY REPORT — [url] ═════════════════════ Duration: [X minutes] Pages: [N pages monitored] Checks: [N total checks performed] Status: [HEALTHY / DEGRADED / BROKEN] Per-Page Results: ───────────────────────────────────────────────────── Page Status Errors Avg Load / HEALTHY 0 450ms /dashboard DEGRADED 2 new 1200ms (was 400ms) /settings HEALTHY 0 380ms Alerts Fired: [N] (X critical, Y high, Z medium) Screenshots: .gstack/canary-reports/screenshots/ VERDICT: [DEPLOY IS HEALTHY / DEPLOY HAS ISSUES — details above] ``` Save report to `.gstack/canary-reports/{date}-canary.md` and `.gstack/canary-reports/{date}-canary.json`. Per-page and overall status: BROKEN if any confirmed CRITICAL alert occurred; otherwise DEGRADED if any confirmed alert occurred; otherwise HEALTHY. Note resolved incidents separately without erasing them from the run's status. JSON fields: `url`, `started_at`, `ended_at`, `status`, `pages` (URL, checks, latest metrics, status), and `alerts` (severity, URL, first_seen, confirmed_at, evidence, resolved). Unconfirmed transients go in a separate `observations` array. Log the result for the review dashboard: ```bash {{SLUG_EVAL}} mkdir -p ~/.gstack/projects/$SLUG ``` Write a JSONL entry: `{"skill":"canary","timestamp":"","status":"","url":"","duration_min":,"alerts":}` Append it to `~/.gstack/projects/$SLUG/canary-history.jsonl`; never overwrite history. ### Phase 7: Baseline Update If the deploy is healthy, offer to update the baseline: - **Context:** Canary monitoring completed. The deploy is healthy. - **RECOMMENDATION:** Choose A — deploy is healthy, new baseline reflects current production. - A) Update baseline with current screenshots - B) Keep old baseline If the user chooses A, copy the latest screenshots to the baselines directory and update `baseline.json`. ## Important Rules - **Speed matters.** Start monitoring within 30 seconds of invocation. Don't over-analyze before monitoring. - **Alert on changes, not absolutes.** Compare against baseline, not industry standards. - **Screenshots are evidence.** Every alert includes a screenshot path. No exceptions. - **Transient tolerance.** Only alert on patterns that persist across 2+ consecutive checks. - **Baseline is king.** Without a baseline, canary is a health check. Encourage `--baseline` before deploying. - **Performance thresholds are relative.** 2x baseline is a regression. 1.5x might be normal variance. - **Read-only.** Observe and report. Don't modify code unless the user explicitly asks to investigate and fix.