@clipy/cli 0.5.0 → 0.8.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.
Files changed (4) hide show
  1. package/README.md +209 -10
  2. package/dist/index.js +1163 -64
  3. package/dist/skill.js +141 -0
  4. package/package.json +4 -2
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,8 +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
77
76
  clipy doctor # health check: key, Mac bridge, Playwright, install mode
77
+ clipy playwright-path # node_modules dir of the Playwright this CLI resolves
78
78
  clipy mcp # run the Clipy MCP server (npx -y @clipy/mcp)
79
79
  ```
80
80
 
@@ -126,6 +126,66 @@ still-compiling dev server's blank screen.
126
126
  notes (and session marks, below) as the recording's transcript, summary input, and
127
127
  agent-context — clearly marked as agent narration, never passed off as speech-to-text.
128
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
+ - `--user-data-dir <dir>` — launch a **persistent** Chromium profile from `dir` instead
150
+ of an ephemeral context (`launchPersistentContext`), so the recording carries that
151
+ profile's whole logged-in identity. Web only; **mutually exclusive with
152
+ `--storage-state`** (a profile already carries its own storage). `--cookie` /
153
+ `--local-storage` / `--init-script` still compose. Point it at a **copy** or a
154
+ dedicated profile — never your live Chrome's default profile: Chrome locks a profile
155
+ while it's open, so Clipy refuses a dir that has a `SingletonLock`/`SingletonSocket`.
156
+
157
+ ```bash
158
+ # Reuse a saved Playwright login
159
+ clipy record --url https://app.example.com/dashboard --for 20 \
160
+ --storage-state ./auth.json
161
+
162
+ # Or seed a token directly
163
+ clipy record --url https://app.example.com/dashboard \
164
+ --local-storage "authToken=eyJ…" --cookie "sid=abc; Domain=app.example.com; Secure"
165
+
166
+ # Or record a persistent logged-in profile
167
+ clipy record --url https://app.example.com/dashboard --for 20 \
168
+ --user-data-dir ./clipy-profile
169
+ ```
170
+
171
+ #### The auth boundary
172
+
173
+ `--storage-state` seeds only the cookies and `localStorage` the **file contains** — it
174
+ can't conjure a whole browser identity, so an app that also needs cross-origin or
175
+ auth-host cookies (SSO, a separate API domain) can still bounce to `/login`. Three
176
+ reliable ways to get a real logged-in recording:
177
+
178
+ 1. **Produce the state file with a real interactive login** (it captures cross-domain
179
+ cookies a hand-built file misses):
180
+ ```bash
181
+ npx playwright open --save-storage=auth.json https://login.example.com
182
+ # sign in, close the window, then:
183
+ clipy record --url https://app.example.com/dashboard --storage-state auth.json
184
+ ```
185
+ 2. **`--user-data-dir <dedicated-profile>`** — a persistent profile you logged into once.
186
+ 3. **`--source mac-screen --window "Chrome"`** — record your real, already-logged-in
187
+ Chrome window through the Mac app; there's no headless auth to reproduce at all.
188
+
129
189
  ## Session mode — you work, Clipy records
130
190
 
131
191
  For recordings where an agent (or you) drives the app live, don't script the capture:
@@ -159,19 +219,151 @@ clipy session start --url http://localhost:3000 --expose-cdp --title "Overflow f
159
219
  ```js
160
220
  const { chromium } = require("playwright");
161
221
  const browser = await chromium.connectOverCDP(cdpHttpUrl); // from `clipy session status --json`
162
- const page = browser.contexts()[0].pages()[0]; // the page being recorded
163
- await page.goto("http://localhost:3000/settings");
222
+ const page = browser.contexts()[0].pages()[0]; // the page being recorded (a NEW context is not captured)
223
+ await page.goto("http://localhost:3000/settings"); // navigate / click / fill as usual
224
+
225
+ // page.viewportSize() is null over a CDP attach — resize via the device-metrics override:
226
+ const cdp = await browser.newCDPSession(page);
227
+ await cdp.send("Emulation.setDeviceMetricsOverride", { width: 1280, height: 720, deviceScaleFactor: 1, mobile: false });
228
+
164
229
  await browser.close(); // detaches; the recording keeps going
165
230
  ```
166
231
 
167
- Drive the existing context/page (above) so your actions land in the recording — a brand-new
168
- context you open won't be captured.
232
+ Four things that otherwise cost a debugging round: attach with `connectOverCDP`; the
233
+ recorded page is `browser.contexts()[0].pages()[0]` (a brand-new context/page you open
234
+ won't be captured); `page.viewportSize()` is `null` on a CDP attach; and a resize needs a
235
+ CDP `Emulation.setDeviceMetricsOverride`, not `setViewportSize`. Your driver script
236
+ resolves Playwright from **its own** directory — if `require("playwright")` can't find it,
237
+ run the script with `NODE_PATH=$(clipy playwright-path) node driver.js`.
238
+
239
+ **In-page marks (zero spawn latency).** While `--expose-cdp` is on, the daemon also exposes
240
+ `window.__clipyMark("text", opts?)` and `window.__clipyChapter("label")` in the recorded
241
+ page. Calling them from your driver emits a mark/chapter *without* spawning a `clipy mark`
242
+ process, so it lands exactly when your code runs, and it runs **daemon-side with the page in
243
+ hand**. `__clipyMark`'s second argument takes the same assertions as the CLI flags —
244
+ evaluated and annotated ✓/✗ identically:
245
+
246
+ ```js
247
+ await page.evaluate(() => window.__clipyMark("clicked Export"));
248
+ await page.evaluate(() =>
249
+ window.__clipyMark("status is Active", {
250
+ assertSelector: ".status-badge",
251
+ assertText: "Active", // needs assertSelector — otherwise the call rejects
252
+ assertUrl: "**/redemptions", // optional
253
+ failMode: "abort", // optional; "warn" is the default
254
+ }),
255
+ );
256
+ ```
257
+
258
+ It returns the annotated `{ tMs, text, assert }`; `failMode: "abort"` discards the session
259
+ just like the flag. These marks land in the same transcript and count toward the same
260
+ 200-mark cap. Note: while CDP is exposed the page's **own** scripts can call these too —
261
+ the same trust boundary as `--expose-cdp` itself (any local process can already drive the
262
+ browser), so only enable it when you intend to drive the session.
263
+
264
+ `session start` also accepts the same auth flags as `record`
265
+ (`--storage-state` / `--cookie` / `--local-storage` / `--init-script`) to record a
266
+ logged-in app; see [Recording a logged-in app](#recording-a-logged-in-app).
169
267
 
170
268
  Safety rails are built in: the session **auto-stops and uploads** at `--max <sec>`
171
269
  (default 600, hard cap 1800) so a forgotten session can never run away; `clipy session
172
270
  abort` discards everything; a crashed daemon is detected and cleared on the next command;
173
271
  corrupt captures are refused before upload, and a failed upload keeps the local file.
174
272
 
273
+ ### Assertion marks — recordings as evidence
274
+
275
+ A plain mark is an unverified claim: an agent can write `clipy mark "the Redemptions
276
+ tab is active"` whether or not it is, and the transcript reads as authoritative either
277
+ way. Assertion marks fix that. The recording daemon owns the live Playwright page, so it
278
+ can **check the claim against the real DOM** and annotate the mark with what it actually
279
+ observed — a false claim can't pass as fact.
280
+
281
+ ```bash
282
+ # Assert a URL (globs: ** = anything, * = any non-slash segment, no * = substring)
283
+ clipy mark "opened the redemptions tab" --assert-url "**/redemptions"
284
+
285
+ # Assert an element exists and contains text
286
+ clipy mark "status flipped to Active" --assert-selector ".status-badge" --assert-text "Active"
287
+ ```
288
+
289
+ - **Pass** → the mark is stored as `status flipped to Active [assert ✓ .status-badge="Active"]`
290
+ and the CLI prints a green `✓`.
291
+ - **Fail** → it's stored as
292
+ `status flipped to Active [ASSERT ✗ expected "Active"; observed .status-badge="Pending"]`
293
+ and the CLI prints a red `✗`. The wrong claim is preserved *as a failed assertion*, not
294
+ as a fact.
295
+
296
+ `--assert-selector <css>` checks an element matches (its trimmed text becomes the
297
+ `observed` value); `--assert-text <substr>` requires that element's text to contain a
298
+ substring (it needs a selector); `--assert-url <glob>` matches the page URL. Combine them
299
+ freely — all provided checks must pass.
300
+
301
+ `--fail-mode` decides what a failed assertion does: `warn` (default) records the `✗` and
302
+ keeps recording; **`abort` discards the whole session** — nothing is uploaded and the CLI
303
+ exits non-zero, so a driver that asserts its way to a broken state doesn't ship a misleading
304
+ clip. If any assertion was attempted, a leading `[verification] N assertion(s): P passed,
305
+ F failed[, K unverified]` note is prepended at 0 ms, so the transcript and the `.md` context
306
+ open with the scorecard.
307
+
308
+ **A mark is never dropped.** If the daemon can't be reached to evaluate an assertion — its
309
+ event loop briefly starved during a heavy dev-server recompile, say — `clipy mark` doesn't
310
+ fail and lose the note. It records the narration anyway, tags it
311
+ `[ASSERT ⚠ could not evaluate — <reason>]`, prints a loud `⚠`, and exits 0. An unverified
312
+ claim is flagged as unverified (the `K` in the tally), never silently promoted to a `✓`. If
313
+ the daemon was only slow (not gone) and processes the same mark a moment later, a
314
+ client-generated id dedups the two so the evaluated copy wins and the mark appears exactly
315
+ once.
316
+
317
+ Assertions evaluate against a real page, so they need a **web** session (they're rejected on
318
+ `--source mac-screen`, which records the real screen with no page to probe).
319
+
320
+ ### Before/after in one recording — `clipy chapter`
321
+
322
+ `clipy chapter "<label>"` drops a section boundary so a single video can carry both a
323
+ BEFORE and an AFTER state — exactly the shape of a PR-review recording:
324
+
325
+ ```bash
326
+ clipy session start --url http://localhost:3000/settings --title "Sidebar overflow fix"
327
+ # … demo the bug on the base branch …
328
+ clipy mark "sidebar overflows on mobile" --assert-selector ".sidebar.is-overflowing"
329
+ clipy chapter "AFTER — fix applied"
330
+ # … git switch fix-branch, restart the dev server, reload …
331
+ clipy mark "sidebar wraps correctly" --assert-selector ".sidebar:not(.is-overflowing)"
332
+ clipy session stop
333
+ ```
334
+
335
+ ### `session run` — crash-safe wrapping
336
+
337
+ If a driver script crashes mid-session, a plain `session start` keeps recording dead air
338
+ up to `--max` and then uploads it. `session run` wraps a command so cleanup is guaranteed:
339
+
340
+ ```bash
341
+ clipy session run --url http://localhost:3000 --expose-cdp -- node driver.js
342
+ ```
343
+
344
+ It starts the session, runs everything after `--` with inherited stdio, and then: **exit 0
345
+ → `session stop`** (upload + share link); **any non-zero exit or a signal → `session abort`**
346
+ (discard) and the child's exit code is propagated. The command runs with `CLIPY_SESSION=1`,
347
+ `CLIPY_SESSION_FILE=<path>`, and (when `--expose-cdp`) `CLIPY_CDP_URL=<cdpHttpUrl>` in its
348
+ environment. `Ctrl-C` is forwarded to the child, then the session is discarded. All the
349
+ `session start` flags (`--url`, `--title`, `--max`, `--type`, `--expose-cdp`, auth flags)
350
+ apply before the `--`.
351
+
352
+ `clipy mark` / `clipy chapter` resolve the session from `CLIPY_SESSION_FILE` first and the
353
+ current directory second — so a driver you launch with `session run` can shell out
354
+ `clipy mark …` from **any working directory** and still hit the right session, instead of
355
+ failing with "no recording session in this workspace".
356
+
357
+ ### Backdating a mark
358
+
359
+ Each `clipy mark` is a short process spawn (~100–300 ms), so a mark can land slightly after
360
+ the state it describes. Backdate it onto the recording clock:
361
+
362
+ ```bash
363
+ clipy mark "the toast appeared" --ago 2 # 2 seconds before now
364
+ clipy mark "page finished loading" --at 4 # at an absolute 4s on the recording clock
365
+ ```
366
+
175
367
  ## Record the real screen — a window, a display (Mac)
176
368
 
177
369
  `--source mac-screen` on `record` / `session start` records through the **running Clipy
@@ -196,8 +388,12 @@ clipy session stop # uploads, prints the share link
196
388
 
197
389
  ## Scripting
198
390
 
199
- `--json` prints the raw API response for `list`, `search`, `show`, `transcript`,
200
- `summary`, `moments`, and `wait`:
391
+ Every command has machine-readable output. `--json` is supported on **`list`, `search`,
392
+ `show`, `transcript`, `summary`, `moments`, `wait`, `record`, `session start/stop/status`,
393
+ `mark`, `chapter`, `doctor`, and `playwright-path`** — stdout is the JSON payload, stderr is progress
394
+ and hints, and errors exit non-zero with a message on stderr prefixed `error:`. For the
395
+ full capability manifest (every command, flag, env var, and exit code) run
396
+ `clipy guide --json`.
201
397
 
202
398
  ```bash
203
399
  # Newest recording's id
@@ -206,6 +402,9 @@ clipy list -n 1 --json | jq -r '.recordings[0].id'
206
402
  # Export subtitles for a recording
207
403
  clipy transcript 3kelcef8wo8h --srt > recording.srt
208
404
 
405
+ # Record headlessly and capture the share link
406
+ clipy record --url http://localhost:3000 --for 20 --json | jq -r '.shareUrl'
407
+
209
408
  # Record with anything, then block until Clipy finished transcribing
210
409
  clipy wait 3kelcef8wo8h --for both && clipy summary 3kelcef8wo8h
211
410
  ```