@usecanary/cli 0.1.0 → 0.2.1

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.
package/README.md CHANGED
@@ -1,32 +1,144 @@
1
1
  # @usecanary/cli
2
2
 
3
- `canary` — the session orchestrator for [canary](https://github.com/usecanary/canary). Drive a
4
- real browser, record QA sessions (Playwright trace, video, network HAR, console), and render a
5
- self-contained `report.html`.
3
+ > `canary` — the session orchestrator for [Canary](https://github.com/usecanary/canary). Drive a real
4
+ > browser, record capture-enabled QA sessions (Playwright trace, video, network HAR, console, per-step
5
+ > screenshots), and render a self-contained `report.html` you can open, commit, or browse in a local UI.
6
+
7
+ [![npm](https://img.shields.io/npm/v/@usecanary/cli.svg)](https://www.npmjs.com/package/@usecanary/cli)
8
+ [![license](https://img.shields.io/npm/l/@usecanary/cli.svg)](https://github.com/usecanary/canary)
9
+
10
+ Canary is built for **AI agents and developers who need verifiable, reproducible browser QA**. Every
11
+ run captures a trace, a video, a network log, console output, and per-step screenshots — and decodes
12
+ back to a reproducible Playwright script — with no instrumentation of your app. Scripts are plain
13
+ async JavaScript run in a sandboxed QuickJS runtime; a background daemon (Playwright + sandbox) starts
14
+ automatically when needed.
15
+
16
+ ## How it works
17
+
18
+ You drive the daemon through a four-step session lifecycle:
19
+
20
+ | Step | Command | Result |
21
+ | --- | --- | --- |
22
+ | 1. start | `canary session start --name "checkout"` | prints a session id |
23
+ | 2. run | `canary run step.js --session <id> --step open` | one script per step |
24
+ | 3. end | `canary session end <id>` | writes `report.html` |
25
+ | 4. view | `canary ui` | browse every session |
6
26
 
7
27
  ## Install
8
28
 
9
29
  ```bash
10
- npx @usecanary/cli install # download Chromium + the runtime into ~/.canary
11
- # or: npm i -g @usecanary/cli && canary install
30
+ npm i -g @usecanary/cli # adds the `canary` command
31
+ canary install # one-time: download Chromium + runtime (~150 MB) into ~/.canary
32
+ ```
33
+
34
+ Prefer not to install globally? Prefix anything with `npx`:
35
+
36
+ ```bash
37
+ npx @usecanary/cli install
12
38
  ```
13
39
 
14
- ## Use
40
+ Or set everything up interactively with the guided wizard — `npm create canary`.
41
+
42
+ ## Quickstart
15
43
 
16
44
  ```bash
17
- canary init # one-shot setup (runtime + agent skill)
45
+ # 1. start a capture-enabled session (prints an id)
18
46
  id=$(canary session start --name "checkout")
19
- canary run ./step.js --session "$id" --step "open"
20
- canary session end "$id" # -> ~/.canary/sessions/<id>/report.html
21
- npx @usecanary/ui # browse recorded sessions
22
- canary skills # install the canary agent skill (~/.claude/skills)
47
+
48
+ # 2. run scripts as ordered steps — one script per step (open → act → assert)
49
+ canary run ./open.js --session "$id" --step "open"
50
+ canary run ./submit.js --session "$id" --step "submit"
51
+
52
+ # inline scripts work too (read from stdin):
53
+ echo 'const p = await browser.getPage("home");
54
+ await p.goto("https://example.com");
55
+ console.log(await p.title());' | canary run --session "$id" --step "home"
56
+
57
+ # 3. finish — collects artifacts and renders the report
58
+ canary session end "$id" # -> ~/.canary/sessions/<id>/report.html
59
+
60
+ # 4. browse, search, and replay every session in a local viewer
61
+ canary ui
62
+ ```
63
+
64
+ Each `--step` is one entry in the report, with its own trace group and **one** auto-captured
65
+ screenshot (taken from the last page opened during that step). So use **one primary named page per
66
+ step**, and reuse the same page name across steps to "click through" like a user — named pages persist
67
+ across steps within a session.
68
+
69
+ ## Commands
70
+
71
+ | Command | What it does |
72
+ | --- | --- |
73
+ | `canary init` | One-shot setup: install the runtime, then print next steps. The friendlier wizard is `npm create canary`. |
74
+ | `canary install` | Install the embedded runtime (Chromium + Playwright + QuickJS) into `~/.canary`. |
75
+ | `canary session start` | Start a capture-enabled session; prints its id. Toggle capture with `--no-trace` / `--no-video` / `--no-har` / `--no-console`; `--headless` for unattended runs. |
76
+ | `canary run [FILE]` | Run a script (a file, or stdin if omitted) as one step. Requires `--session <id>`; label it with `--step <name>`; bound it with `--timeout <seconds>`. |
77
+ | `canary session end <id>` | Stop recording, collect artifacts, render `report.html` + `results.json`. `--stop-daemon` shuts the daemon down afterward if nothing else needs it. |
78
+ | `canary session abort <id>` | Best-effort teardown of a session — salvage a wedged run from whatever artifacts survived. |
79
+ | `canary session list` | List recorded sessions (table; `--json` for machine output). |
80
+ | `canary status [--session <id>]` | Daemon status, or one session's status. |
81
+ | `canary ui` | Launch the local session viewer. Options: `--dir <path>`, `--port`, `--host`, `--no-open`. |
82
+ | `canary stop` | Stop the background daemon and every browser/session it's running (alias: `canary daemon stop`). |
83
+
84
+ Global flags: `--json` (machine-readable output on stdout), `-v` / `--verbose` (more logging on
85
+ stderr). Run `canary --help` or `canary <command> --help` for the full reference.
86
+
87
+ > **Lifecycle tip:** `canary stop` aborts any live session and skips its `report.html`. For a clean
88
+ > report, always `canary session end <id>` **first**, then `canary stop`.
89
+
90
+ ## Writing scripts
91
+
92
+ Scripts are plain **async JavaScript** in a QuickJS sandbox with a Playwright-like API — no `require`,
93
+ `process`, `fs`, or `fetch`; just a pre-connected `browser`, `console`, and a few file helpers.
94
+ Top-level `await` works.
95
+
96
+ ```js
97
+ const page = await browser.getPage("home"); // named, persistent page
98
+ await page.goto("https://example.com", { waitUntil: "domcontentloaded" });
99
+ console.log(await page.title());
100
+
101
+ await page.locator("text=Sign in").click();
102
+ await saveScreenshot(await page.screenshot(), "signed-in.png"); // saveScreenshot(buffer, name)
103
+ ```
104
+
105
+ - **Pages** — `browser.getPage(name)`, `browser.newPage()`, `browser.listPages()`,
106
+ `browser.closePage(name)`. Pages are full Playwright `Page`s (`goto`, `click`, `fill`, `locator`,
107
+ `evaluate`, `getByRole`, `waitForSelector`, …).
108
+ - **Files** (sandboxed to `~/.canary/tmp/`) — `saveScreenshot(buffer, name)`, `writeFile(name, data)`,
109
+ `readFile(name)` to pass values between steps.
110
+
111
+ The engine documents the same API — run `canary-browser --help`, or read the
112
+ [canary-scripting reference](https://github.com/usecanary/canary/blob/main/skills/canary-scripting/references/REFERENCE.md).
113
+
114
+ ## Artifacts
115
+
116
+ Everything for a run lands under `~/.canary/sessions/<id>/`:
117
+
23
118
  ```
119
+ session.json session metadata + per-step record
120
+ results.json decoded results (steps, summary, artifact paths)
121
+ report.html self-contained report — open it anywhere, commit it, share it
122
+ trace.zip Playwright trace (DOM snapshots + actions, one group per step)
123
+ ```
124
+
125
+ …plus the WebM video, the network HAR, the console log, and one screenshot per step.
24
126
 
25
- Run `canary --help` for the full command list.
127
+ ## Use it from an AI agent
128
+
129
+ Canary ships skills, subagents, and `/canary:*` slash commands for Claude Code, Cursor, and Codex, so
130
+ an agent can plan and record QA for you:
131
+
132
+ ```bash
133
+ npx skills add usecanary/canary # any Agent Skills tool
134
+ # Claude Code: /plugin marketplace add usecanary/canary then /plugin install canary@canary-marketplace
135
+ ```
26
136
 
27
- ## Scripts
137
+ ## Related packages
28
138
 
29
- Plain async JS in a sandbox with a Playwright-like API: `browser.getPage(name)`, `page.goto`,
30
- `page.locator`, `page.evaluate`, `saveScreenshot(buffer, name)`, `console.log`.
139
+ - [`@usecanary/browser`](https://www.npmjs.com/package/@usecanary/browser) the engine for quick
140
+ one-off automation (no recording, no report).
141
+ - [`@usecanary/ui`](https://www.npmjs.com/package/@usecanary/ui) — the `canary-viewer` session browser.
142
+ - [`create-canary`](https://www.npmjs.com/package/create-canary) — `npm create canary` guided setup.
31
143
 
32
144
  MIT · [source](https://github.com/usecanary/canary)