@clipy/cli 0.4.1 → 0.8.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.
package/README.md CHANGED
@@ -1,9 +1,5 @@
1
1
  # @clipy/cli
2
2
 
3
- > This repository is the public mirror of **`@clipy/cli`**. The package is developed in
4
- > the Clipy monorepo and synced here with each npm release — browse the source or file
5
- > issues here.
6
-
7
3
  [![npm version](https://img.shields.io/npm/v/%40clipy%2Fcli)](https://www.npmjs.com/package/@clipy/cli)
8
4
  [![license: MIT](https://img.shields.io/npm/l/%40clipy%2Fcli)](https://github.com/manovagyanik1/clipy-cli/blob/main/LICENSE)
9
5
  [![node >= 18](https://img.shields.io/node/v/%40clipy%2Fcli)](https://www.npmjs.com/package/@clipy/cli)
@@ -73,7 +69,12 @@ clipy wait <id> --for both # block until transcript/summary are ready
73
69
  clipy record --url <app> [--for 15] # record a web app headlessly → a Clipy recording
74
70
  clipy session start --url <app> # start recording in the background while you work
75
71
  clipy mark "reproduced the bug" # drop a live-timestamped note into the session
72
+ clipy mark "on redemptions" --assert-url '**/redemptions' # assert what you claim
73
+ clipy chapter "AFTER — fix applied" # split the recording into before/after sections
74
+ clipy session run --url <app> -- npm run demo # start, run a command, auto stop/abort
76
75
  clipy session stop # finish + upload; your marks become the transcript
76
+ clipy doctor # health check: key, Mac bridge, Playwright, install mode
77
+ clipy playwright-path # node_modules dir of the Playwright this CLI resolves
77
78
  clipy mcp # run the Clipy MCP server (npx -y @clipy/mcp)
78
79
  ```
79
80
 
@@ -101,16 +102,61 @@ It needs two things beyond a normal install:
101
102
  create the key at [clipy.online/settings/api-keys](https://clipy.online/settings/api-keys).
102
103
 
103
104
  Flags: `--for <sec>` (record duration after load, default 15; per viewport), `--title <t>`
104
- / `--description <d>`, `--viewports mobile,tablet,desktop` (or `390x844,1440x900` — records
105
- every size sequentially into ONE video with a transcript chapter per pass),
106
- `--note "12: opened settings"` (repeatable timestamped narration notes),
107
- `--width`/`--height` (viewport + video size, default 1280×720), `--wait` (block until the
108
- transcript is ready), `--json` (print `{id, shareUrl, contextUrl, sizeBytes}`).
105
+ / `--description <d>`, `--type <kind>` (what the recording IS — see below),
106
+ `--viewports mobile,tablet,desktop` (or `390x844,1440x900` — records every size sequentially
107
+ into ONE video with a transcript chapter per pass), `--note "12: opened settings"` (repeatable
108
+ timestamped narration notes), `--width`/`--height` (viewport + video size, default 1280×720),
109
+ `--wait` (block until the transcript is ready), `--json` (print `{id, shareUrl, contextUrl, sizeBytes}`).
110
+
111
+ **`--type <kind>` declares what the recording is** so the AI summary reads it correctly (a demo
112
+ isn't a bug report). Accepts `bug_report`, `feature_request`, `product_demo`,
113
+ `walkthrough_tutorial`, `feedback_review`, `discussion_talk`, `other` — and the short aliases
114
+ `bug`, `feature`, `demo`/`product`, `walkthrough`/`tutorial`/`guide`, `feedback`/`review`,
115
+ `discussion`/`talk`/`meeting`. An unrecognized value is a usage error. (Applied on the web path
116
+ today; `--source mac-screen` support is pending a Clipy app update.)
117
+
118
+ **Note timestamps.** A `--note` is absolute by default (`"12: opened settings"` → 12s).
119
+ With `--viewports`, anchor a note to a pass instead so it can't drift when load time
120
+ shifts the pass boundaries: `--note "pass2: mobile layout"` lands at the real start of
121
+ pass 2, and `--note "pass2@5: after scrolling"` lands 5s into it. Recording starts the
122
+ note clock on the first non-blank frame (up to a 10s wait), so `"0: …"` isn't pinned to a
123
+ still-compiling dev server's blank screen.
109
124
 
110
125
  **Narration = the transcript.** Headless captures have no audio, so Clipy uses your
111
126
  notes (and session marks, below) as the recording's transcript, summary input, and
112
127
  agent-context — clearly marked as agent narration, never passed off as speech-to-text.
113
128
 
129
+ ### Recording a logged-in app
130
+
131
+ To record an authenticated SPA, seed the session **before** the browser navigates —
132
+ Clipy applies all of these to the Playwright context ahead of the first page load, so the
133
+ app's route guard sees the auth state on first paint (seeding `localStorage` *after*
134
+ visiting a guarded route loses that race and bounces you to `/login`). These flags apply
135
+ to headless web capture on `record` and `session start`; they're rejected on
136
+ `--source mac-screen` (which records the real, already-logged-in screen).
137
+
138
+ - `--storage-state <file>` — a Playwright [`storageState`](https://playwright.dev/docs/auth)
139
+ JSON (cookies + per-origin `localStorage`), passed straight to `browser.newContext()`.
140
+ The easiest path: log in once with Playwright and save `context.storageState({ path })`,
141
+ then hand that file to Clipy. Its contents are never printed or logged.
142
+ - `--cookie "name=value[; Domain=d; Path=p; Secure; HttpOnly; SameSite=Lax]"` — set one
143
+ cookie (repeatable). Without a `Domain` it's scoped to the target URL; with one it's
144
+ domain-scoped.
145
+ - `--local-storage "key=value"` — set one `localStorage` pair for the target origin
146
+ (repeatable).
147
+ - `--init-script <file>` — run a JS file in every page before its own scripts (e.g. to
148
+ stub a feature flag or inject a token).
149
+
150
+ ```bash
151
+ # Reuse a saved Playwright login
152
+ clipy record --url https://app.example.com/dashboard --for 20 \
153
+ --storage-state ./auth.json
154
+
155
+ # Or seed a token directly
156
+ clipy record --url https://app.example.com/dashboard \
157
+ --local-storage "authToken=eyJ…" --cookie "sid=abc; Domain=app.example.com; Secure"
158
+ ```
159
+
114
160
  ## Session mode — you work, Clipy records
115
161
 
116
162
  For recordings where an agent (or you) drives the app live, don't script the capture:
@@ -128,11 +174,136 @@ The session records in a detached background daemon, so every command returns
128
174
  immediately. `clipy mark` stamps notes against the live recording clock; navigations and
129
175
  console errors are added automatically as `[auto]` marks. One session per directory.
130
176
 
177
+ **Drive the recorded browser (opt-in).** Pass `--expose-cdp` to `session start` and the
178
+ daemon's headless Chromium opens a CDP endpoint you can attach to and drive navigation, clicks,
179
+ and viewport while Clipy records the same page. It's **off by default** — while it's open, any
180
+ local process can attach to and control that browser, so only enable it when you intend to drive
181
+ the session. `clipy session start --expose-cdp` prints the endpoint (and `session start --json`
182
+ / `session status --json` return it as `cdpHttpUrl` / `cdpUrl`, also written to the `0600`
183
+ session state file). The env var `CLIPY_DISABLE_CDP=1` is a hard kill switch that overrides the
184
+ flag.
185
+
186
+ ```bash
187
+ clipy session start --url http://localhost:3000 --expose-cdp --title "Overflow fix"
188
+ ```
189
+
190
+ ```js
191
+ const { chromium } = require("playwright");
192
+ const browser = await chromium.connectOverCDP(cdpHttpUrl); // from `clipy session status --json`
193
+ const page = browser.contexts()[0].pages()[0]; // the page being recorded (a NEW context is not captured)
194
+ await page.goto("http://localhost:3000/settings"); // navigate / click / fill as usual
195
+
196
+ // page.viewportSize() is null over a CDP attach — resize via the device-metrics override:
197
+ const cdp = await browser.newCDPSession(page);
198
+ await cdp.send("Emulation.setDeviceMetricsOverride", { width: 1280, height: 720, deviceScaleFactor: 1, mobile: false });
199
+
200
+ await browser.close(); // detaches; the recording keeps going
201
+ ```
202
+
203
+ Four things that otherwise cost a debugging round: attach with `connectOverCDP`; the
204
+ recorded page is `browser.contexts()[0].pages()[0]` (a brand-new context/page you open
205
+ won't be captured); `page.viewportSize()` is `null` on a CDP attach; and a resize needs a
206
+ CDP `Emulation.setDeviceMetricsOverride`, not `setViewportSize`. Your driver script
207
+ resolves Playwright from **its own** directory — if `require("playwright")` can't find it,
208
+ run the script with `NODE_PATH=$(clipy playwright-path) node driver.js`.
209
+
210
+ **In-page marks (zero spawn latency).** While `--expose-cdp` is on, the daemon also exposes
211
+ `window.__clipyMark("text")` and `window.__clipyChapter("label")` in the recorded page.
212
+ Calling them from your driver (`page.evaluate(() => window.__clipyMark("clicked Export"))`)
213
+ emits a mark or chapter *without* spawning a `clipy mark` process, so it lands exactly when
214
+ your code runs. These marks land in the same transcript and count toward the same 200-mark
215
+ cap. Note: while CDP is exposed the page's **own** scripts can call these too — that's the
216
+ same trust boundary as `--expose-cdp` itself (any local process can already drive the
217
+ browser), so only enable it when you intend to drive the session.
218
+
219
+ `session start` also accepts the same auth flags as `record`
220
+ (`--storage-state` / `--cookie` / `--local-storage` / `--init-script`) to record a
221
+ logged-in app; see [Recording a logged-in app](#recording-a-logged-in-app).
222
+
131
223
  Safety rails are built in: the session **auto-stops and uploads** at `--max <sec>`
132
224
  (default 600, hard cap 1800) so a forgotten session can never run away; `clipy session
133
225
  abort` discards everything; a crashed daemon is detected and cleared on the next command;
134
226
  corrupt captures are refused before upload, and a failed upload keeps the local file.
135
227
 
228
+ ### Assertion marks — recordings as evidence
229
+
230
+ A plain mark is an unverified claim: an agent can write `clipy mark "the Redemptions
231
+ tab is active"` whether or not it is, and the transcript reads as authoritative either
232
+ way. Assertion marks fix that. The recording daemon owns the live Playwright page, so it
233
+ can **check the claim against the real DOM** and annotate the mark with what it actually
234
+ observed — a false claim can't pass as fact.
235
+
236
+ ```bash
237
+ # Assert a URL (globs: ** = anything, * = any non-slash segment, no * = substring)
238
+ clipy mark "opened the redemptions tab" --assert-url "**/redemptions"
239
+
240
+ # Assert an element exists and contains text
241
+ clipy mark "status flipped to Active" --assert-selector ".status-badge" --assert-text "Active"
242
+ ```
243
+
244
+ - **Pass** → the mark is stored as `status flipped to Active [assert ✓ .status-badge="Active"]`
245
+ and the CLI prints a green `✓`.
246
+ - **Fail** → it's stored as
247
+ `status flipped to Active [ASSERT ✗ expected "Active"; observed .status-badge="Pending"]`
248
+ and the CLI prints a red `✗`. The wrong claim is preserved *as a failed assertion*, not
249
+ as a fact.
250
+
251
+ `--assert-selector <css>` checks an element matches (its trimmed text becomes the
252
+ `observed` value); `--assert-text <substr>` requires that element's text to contain a
253
+ substring (it needs a selector); `--assert-url <glob>` matches the page URL. Combine them
254
+ freely — all provided checks must pass.
255
+
256
+ `--fail-mode` decides what a failed assertion does: `warn` (default) records the `✗` and
257
+ keeps recording; **`abort` discards the whole session** — nothing is uploaded and the CLI
258
+ exits non-zero, so a driver that asserts its way to a broken state doesn't ship a misleading
259
+ clip. If any assertions ran, a leading `[verification] N assertion(s): P passed, F failed`
260
+ note is prepended at 0 ms, so the transcript and the `.md` context open with the scorecard.
261
+
262
+ Assertions evaluate against a real page, so they need a **web** session (they're rejected on
263
+ `--source mac-screen`, which records the real screen with no page to probe).
264
+
265
+ ### Before/after in one recording — `clipy chapter`
266
+
267
+ `clipy chapter "<label>"` drops a section boundary so a single video can carry both a
268
+ BEFORE and an AFTER state — exactly the shape of a PR-review recording:
269
+
270
+ ```bash
271
+ clipy session start --url http://localhost:3000/settings --title "Sidebar overflow fix"
272
+ # … demo the bug on the base branch …
273
+ clipy mark "sidebar overflows on mobile" --assert-selector ".sidebar.is-overflowing"
274
+ clipy chapter "AFTER — fix applied"
275
+ # … git switch fix-branch, restart the dev server, reload …
276
+ clipy mark "sidebar wraps correctly" --assert-selector ".sidebar:not(.is-overflowing)"
277
+ clipy session stop
278
+ ```
279
+
280
+ ### `session run` — crash-safe wrapping
281
+
282
+ If a driver script crashes mid-session, a plain `session start` keeps recording dead air
283
+ up to `--max` and then uploads it. `session run` wraps a command so cleanup is guaranteed:
284
+
285
+ ```bash
286
+ clipy session run --url http://localhost:3000 --expose-cdp -- node driver.js
287
+ ```
288
+
289
+ It starts the session, runs everything after `--` with inherited stdio, and then: **exit 0
290
+ → `session stop`** (upload + share link); **any non-zero exit or a signal → `session abort`**
291
+ (discard) and the child's exit code is propagated. The command runs with `CLIPY_SESSION=1`
292
+ in its environment (and `CLIPY_CDP_URL=<cdpHttpUrl>` when `--expose-cdp` is set, so the
293
+ driver knows where to attach). `Ctrl-C` is forwarded to the child, then the session is
294
+ discarded. All the `session start` flags (`--url`, `--title`, `--max`, `--type`,
295
+ `--expose-cdp`, auth flags) apply before the `--`.
296
+
297
+ ### Backdating a mark
298
+
299
+ Each `clipy mark` is a short process spawn (~100–300 ms), so a mark can land slightly after
300
+ the state it describes. Backdate it onto the recording clock:
301
+
302
+ ```bash
303
+ clipy mark "the toast appeared" --ago 2 # 2 seconds before now
304
+ clipy mark "page finished loading" --at 4 # at an absolute 4s on the recording clock
305
+ ```
306
+
136
307
  ## Record the real screen — a window, a display (Mac)
137
308
 
138
309
  `--source mac-screen` on `record` / `session start` records through the **running Clipy
@@ -157,8 +328,12 @@ clipy session stop # uploads, prints the share link
157
328
 
158
329
  ## Scripting
159
330
 
160
- `--json` prints the raw API response for `list`, `search`, `show`, `transcript`,
161
- `summary`, `moments`, and `wait`:
331
+ Every command has machine-readable output. `--json` is supported on **`list`, `search`,
332
+ `show`, `transcript`, `summary`, `moments`, `wait`, `record`, `session start/stop/status`,
333
+ `mark`, `chapter`, `doctor`, and `playwright-path`** — stdout is the JSON payload, stderr is progress
334
+ and hints, and errors exit non-zero with a message on stderr prefixed `error:`. For the
335
+ full capability manifest (every command, flag, env var, and exit code) run
336
+ `clipy guide --json`.
162
337
 
163
338
  ```bash
164
339
  # Newest recording's id
@@ -167,6 +342,9 @@ clipy list -n 1 --json | jq -r '.recordings[0].id'
167
342
  # Export subtitles for a recording
168
343
  clipy transcript 3kelcef8wo8h --srt > recording.srt
169
344
 
345
+ # Record headlessly and capture the share link
346
+ clipy record --url http://localhost:3000 --for 20 --json | jq -r '.shareUrl'
347
+
170
348
  # Record with anything, then block until Clipy finished transcribing
171
349
  clipy wait 3kelcef8wo8h --for both && clipy summary 3kelcef8wo8h
172
350
  ```