@clipy/cli 0.8.2 → 0.8.3
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 +90 -33
- package/dist/index.js +417 -54
- package/dist/skill.js +91 -29
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -128,12 +128,27 @@ agent-context — clearly marked as agent narration, never passed off as speech-
|
|
|
128
128
|
|
|
129
129
|
### Recording a logged-in app
|
|
130
130
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
131
|
+
**If something is driving the browser — prefer that.** Clipy is a recorder, not a driver.
|
|
132
|
+
When an agent (or you) drives a real, already-logged-in browser, don't hand Clipy the
|
|
133
|
+
credentials at all: record the real screen and attach evidence as you go.
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
clipy session start --source mac-screen --window "Chrome" --title "PR-1234 verification"
|
|
137
|
+
clipy mark "redemptions tab active" --observed "tab=Redemptions, rows=14" --verdict pass
|
|
138
|
+
clipy chapter "AFTER — fix applied"
|
|
139
|
+
clipy session stop
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
No auth to reproduce, no credentials in flags, and the recording shows the real app.
|
|
143
|
+
|
|
144
|
+
**The flags below are the agentless / CI fallback** — for a one-shot `clipy record` in CI,
|
|
145
|
+
or a headless session nothing is steering, where Clipy needs its own logged-in context.
|
|
146
|
+
Seed the session **before** the browser navigates — Clipy applies all of these to the
|
|
147
|
+
Playwright context ahead of the first page load, so the app's route guard sees the auth
|
|
148
|
+
state on first paint (seeding `localStorage` *after* visiting a guarded route loses that
|
|
149
|
+
race and bounces you to `/login`). They apply to headless web capture on `record` and
|
|
150
|
+
`session start`; they're rejected on `--source mac-screen` (which records the real,
|
|
151
|
+
already-logged-in screen).
|
|
137
152
|
|
|
138
153
|
- `--storage-state <file>` — a Playwright [`storageState`](https://playwright.dev/docs/auth)
|
|
139
154
|
JSON (cookies + per-origin `localStorage`), passed straight to `browser.newContext()`.
|
|
@@ -146,19 +161,30 @@ to headless web capture on `record` and `session start`; they're rejected on
|
|
|
146
161
|
(repeatable).
|
|
147
162
|
- `--init-script <file>` — run a JS file in every page before its own scripts (e.g. to
|
|
148
163
|
stub a feature flag or inject a token).
|
|
149
|
-
- `--user-data-dir <dir>` — launch a **persistent** Chromium profile from
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
164
|
+
- `--user-data-dir <dir>` — launch a **persistent** Chromium profile from the user-data
|
|
165
|
+
**root** `dir` (`launchPersistentContext`), so the recording carries that profile's
|
|
166
|
+
whole logged-in identity. Web only; **mutually exclusive with `--storage-state`** (a
|
|
167
|
+
profile already carries its own storage). `--cookie` / `--local-storage` / `--init-script`
|
|
168
|
+
still compose. Pass the **root**, not a profile subdir — Clipy refuses a `Default`/`Profile N`
|
|
169
|
+
directory and tells you the parent dir + `--profile-directory` to use. In direct mode
|
|
170
|
+
(no `--profile-directory`) it also refuses a live-locked root (`SingletonLock`/`SingletonSocket`).
|
|
171
|
+
- `--profile-directory "<name>"` — with `--user-data-dir`, select a **named** profile
|
|
172
|
+
(e.g. `Profile 12`, from `chrome://version` → "Profile Path"). Because Playwright can't
|
|
173
|
+
select a named profile in place, Clipy **copies** that profile into a temporary recording
|
|
174
|
+
root and launches the copy — **loudly** (it prints what it's copying and the size). Your
|
|
175
|
+
real profile is never opened or written, and the copy is deleted after upload. No need to
|
|
176
|
+
quit Chrome (Clipy warns if it's running, since in-use databases may copy inconsistently —
|
|
177
|
+
quit it for a guaranteed-clean copy).
|
|
178
|
+
|
|
179
|
+
> **⚠ macOS: a copied Chrome profile can open silently signed out.** Chrome encrypts its
|
|
180
|
+
> cookies with a Keychain key scoped to *Chrome Safe Storage*; the recorder runs
|
|
181
|
+
> Playwright's **Chromium**, which reads *Chromium Safe Storage*. So a copied real-Chrome
|
|
182
|
+
> profile may open looking like you — bookmarks, preferences, `localStorage` all intact —
|
|
183
|
+
> while every cookie-based login is gone. `localStorage`/`Preferences`-based sessions
|
|
184
|
+
> survive; cookie sessions may not. Clipy prints this warning before recording whenever
|
|
185
|
+
> copy mode runs on macOS. **If the recording lands logged out, this is why** — use
|
|
186
|
+
> `--source mac-screen` with your real browser, or the agent-driven path (drive your own
|
|
187
|
+
> browser and attach evidence with `--observed`/`--verdict`).
|
|
162
188
|
|
|
163
189
|
```bash
|
|
164
190
|
# Reuse a saved Playwright login
|
|
@@ -169,9 +195,10 @@ clipy record --url https://app.example.com/dashboard --for 20 \
|
|
|
169
195
|
clipy record --url https://app.example.com/dashboard \
|
|
170
196
|
--local-storage "authToken=eyJ…" --cookie "sid=abc; Domain=app.example.com; Secure"
|
|
171
197
|
|
|
172
|
-
# Or record
|
|
198
|
+
# Or record your real logged-in Chrome profile (copied, never modified)
|
|
173
199
|
clipy record --url https://app.example.com/dashboard --for 20 \
|
|
174
|
-
--user-data-dir
|
|
200
|
+
--user-data-dir "$HOME/Library/Application Support/Google/Chrome" \
|
|
201
|
+
--profile-directory "Profile 12"
|
|
175
202
|
```
|
|
176
203
|
|
|
177
204
|
#### The auth boundary
|
|
@@ -188,7 +215,9 @@ reliable ways to get a real logged-in recording:
|
|
|
188
215
|
# sign in, close the window, then:
|
|
189
216
|
clipy record --url https://app.example.com/dashboard --storage-state auth.json
|
|
190
217
|
```
|
|
191
|
-
2.
|
|
218
|
+
2. **Your real Chrome profile, copied:** `--user-data-dir "<chrome user-data root>"
|
|
219
|
+
--profile-directory "<name>"` (name from `chrome://version`). Clipy copies that profile
|
|
220
|
+
to a temp root and records the copy — no manual export, and your real profile is untouched.
|
|
192
221
|
3. **`--source mac-screen --window "Chrome"`** — record your real, already-logged-in
|
|
193
222
|
Chrome window through the Mac app; there's no headless auth to reproduce at all.
|
|
194
223
|
|
|
@@ -276,13 +305,33 @@ Safety rails are built in: the session **auto-stops and uploads** at `--max <sec
|
|
|
276
305
|
abort` discards everything; a crashed daemon is detected and cleared on the next command;
|
|
277
306
|
corrupt captures are refused before upload, and a failed upload keeps the local file.
|
|
278
307
|
|
|
279
|
-
###
|
|
308
|
+
### Evidence marks — two provenances, never pooled
|
|
280
309
|
|
|
281
310
|
A plain mark is an unverified claim: an agent can write `clipy mark "the Redemptions
|
|
282
311
|
tab is active"` whether or not it is, and the transcript reads as authoritative either
|
|
283
|
-
way.
|
|
284
|
-
|
|
285
|
-
|
|
312
|
+
way. Evidence marks fix that — in one of two ways, and Clipy **labels which**, so a
|
|
313
|
+
claim you attested can never be read as something Clipy checked.
|
|
314
|
+
|
|
315
|
+
**Driver-attested — you brought the browser.** Clipy is a recorder, not a driver: when
|
|
316
|
+
you're driving a real browser with your own tooling (or recording the screen), attach the
|
|
317
|
+
values you observed and your verdict.
|
|
318
|
+
|
|
319
|
+
```bash
|
|
320
|
+
clipy mark "redemptions tab active" --observed "tab=Redemptions, rows=14" --verdict pass
|
|
321
|
+
clipy mark "totals still stale" --observed "total=\$0.00 (expected \$412.50)" --verdict fail
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Stored as `redemptions tab active [ASSERT ✓ driver-attested; observed=tab=Redemptions, rows=14]`
|
|
325
|
+
(or `✗`). Both flags are required together, a mark carries exactly **one** provenance
|
|
326
|
+
(mixing with `--assert-*` is a usage error), and this works in **every** session type —
|
|
327
|
+
including `--source mac-screen`.
|
|
328
|
+
|
|
329
|
+
> **The honesty rule:** driver-attested means Clipy vouches that the agent **said** it,
|
|
330
|
+
> not that Clipy verified it. Put real observed values in `--observed` — the point of the
|
|
331
|
+
> ledger is that a reviewer can check the attestation against the video.
|
|
332
|
+
|
|
333
|
+
**Clipy-verified — Clipy owns the page.** In a headless web session the daemon owns the
|
|
334
|
+
live Playwright page, so it can check the claim against the real DOM itself:
|
|
286
335
|
|
|
287
336
|
```bash
|
|
288
337
|
# Assert a URL (globs: ** = anything, * = any non-slash segment, no * = substring)
|
|
@@ -292,24 +341,32 @@ clipy mark "opened the redemptions tab" --assert-url "**/redemptions"
|
|
|
292
341
|
clipy mark "status flipped to Active" --assert-selector ".status-badge" --assert-text "Active"
|
|
293
342
|
```
|
|
294
343
|
|
|
295
|
-
- **Pass** →
|
|
344
|
+
- **Pass** → `status flipped to Active [assert ✓ verified-by-clipy; .status-badge="Active"]`
|
|
296
345
|
and the CLI prints a green `✓`.
|
|
297
|
-
- **Fail** →
|
|
298
|
-
`status flipped to Active [ASSERT ✗ expected "Active"; observed .status-badge="Pending"]`
|
|
346
|
+
- **Fail** → `status flipped to Active [ASSERT ✗ verified-by-clipy; expected "Active"; observed .status-badge="Pending"]`
|
|
299
347
|
and the CLI prints a red `✗`. The wrong claim is preserved *as a failed assertion*, not
|
|
300
348
|
as a fact.
|
|
301
349
|
|
|
302
350
|
`--assert-selector <css>` checks an element matches (its trimmed text becomes the
|
|
303
351
|
`observed` value); `--assert-text <substr>` requires that element's text to contain a
|
|
304
352
|
substring (it needs a selector); `--assert-url <glob>` matches the page URL. Combine them
|
|
305
|
-
freely — all provided checks must pass.
|
|
353
|
+
freely — all provided checks must pass. These need a Clipy-owned page, so they're rejected
|
|
354
|
+
on `--source mac-screen` (use `--observed`/`--verdict` there).
|
|
306
355
|
|
|
307
356
|
`--fail-mode` decides what a failed assertion does: `warn` (default) records the `✗` and
|
|
308
357
|
keeps recording; **`abort` discards the whole session** — nothing is uploaded and the CLI
|
|
309
358
|
exits non-zero, so a driver that asserts its way to a broken state doesn't ship a misleading
|
|
310
|
-
clip.
|
|
311
|
-
|
|
312
|
-
|
|
359
|
+
clip.
|
|
360
|
+
|
|
361
|
+
The leading `[verification]` note reports the two provenances as **separate segments** and
|
|
362
|
+
never pools them:
|
|
363
|
+
|
|
364
|
+
```text
|
|
365
|
+
[verification] 2 clipy-verified: 1 passed, 1 failed, 1 unverified · 3 driver-attested: 2 passed, 1 failed
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
An empty segment is omitted; with only clipy-verified marks the rendering stays the legacy
|
|
369
|
+
`N assertion(s): P passed, F failed[, K unverified]`.
|
|
313
370
|
|
|
314
371
|
**A mark is never dropped, and a late verdict never rewrites it.** If the daemon can't be
|
|
315
372
|
reached to evaluate an assertion — its event loop briefly starved during a heavy dev-server
|
package/dist/index.js
CHANGED
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
* override the stored key. Read-only unless the key carries the "ingest" scope.
|
|
14
14
|
*/
|
|
15
15
|
import { parseArgs } from "node:util";
|
|
16
|
-
import { appendFileSync, closeSync, createWriteStream, existsSync, mkdirSync, openSync, readFileSync, readSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, chmodSync } from "node:fs";
|
|
16
|
+
import { appendFileSync, closeSync, cpSync, createWriteStream, existsSync, mkdirSync, openSync, readdirSync, readFileSync, readSync, realpathSync, renameSync, rmSync, statSync, writeFileSync, chmodSync } from "node:fs";
|
|
17
17
|
import { homedir, tmpdir } from "node:os";
|
|
18
|
-
import { dirname, join, resolve } from "node:path";
|
|
18
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
19
19
|
import { createInterface } from "node:readline";
|
|
20
20
|
import { spawn } from "node:child_process";
|
|
21
21
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -321,9 +321,12 @@ ${c.bold("RECORD")} ${c.dim("(needs an API key with the \"ingest\" permission)")
|
|
|
321
321
|
--cookie "n=v[; Domain=d; Path=p; Secure; HttpOnly; SameSite=Lax]" (repeatable)
|
|
322
322
|
--local-storage "k=v" Seed a localStorage pair for the target origin (repeatable)
|
|
323
323
|
--init-script <f> Run a JS file before every page load
|
|
324
|
-
--user-data-dir <d> Launch a persistent Chromium
|
|
325
|
-
logged-in identity). Excl. with --storage-state;
|
|
326
|
-
|
|
324
|
+
--user-data-dir <d> Launch from a persistent Chromium user-data ROOT (its
|
|
325
|
+
whole logged-in identity). Excl. with --storage-state;
|
|
326
|
+
pass the root, not a profile subdir
|
|
327
|
+
--profile-directory <name> With --user-data-dir: pick a named profile
|
|
328
|
+
(e.g. "Profile 12"). Clipy copies it to a temp root and
|
|
329
|
+
records the copy — real profile untouched, deleted after
|
|
327
330
|
|
|
328
331
|
${c.bold("SESSION")} ${c.dim("(agent works, Clipy records — one active session per directory)")}
|
|
329
332
|
${c.dim("--source mac-screen on record/session records the REAL screen via the")}
|
|
@@ -351,8 +354,15 @@ ${c.bold("SESSION")} ${c.dim("(agent works, Clipy records — one active session
|
|
|
351
354
|
CLIPY_CDP_URL with --expose-cdp). Crash-safe
|
|
352
355
|
wrapper for driver scripts — no dead-air uploads.
|
|
353
356
|
mark "<what just happened>" Drop a live timestamped note; marks become the
|
|
354
|
-
recording's transcript.
|
|
355
|
-
|
|
357
|
+
recording's transcript. Attach evidence — one
|
|
358
|
+
provenance per mark, never pooled:
|
|
359
|
+
--observed "<values>" --verdict pass|fail
|
|
360
|
+
DRIVER-ATTESTED: you drove the browser and report
|
|
361
|
+
what you saw (works in every session type, incl.
|
|
362
|
+
--source mac-screen). Clipy vouches you SAID it,
|
|
363
|
+
not that Clipy verified it — put real values here
|
|
364
|
+
--assert-selector <css> CLIPY-VERIFIED (Clipy-owned page only): assert an
|
|
365
|
+
element exists (observed text recorded)
|
|
356
366
|
--assert-text <substr> require that element's text to contain <substr>
|
|
357
367
|
--assert-url <glob> assert the page URL matches (**/* wildcards)
|
|
358
368
|
--fail-mode warn|abort warn (default) annotates ASSERT ✗; abort
|
|
@@ -1758,12 +1768,13 @@ async function applyAuthCapture(context, auth, targetUrl) {
|
|
|
1758
1768
|
if (auth.initScriptPath)
|
|
1759
1769
|
await context.addInitScript({ path: auth.initScriptPath });
|
|
1760
1770
|
}
|
|
1761
|
-
/** Validate a --user-data-dir before launch. It must exist
|
|
1762
|
-
*
|
|
1763
|
-
*
|
|
1764
|
-
*
|
|
1765
|
-
*
|
|
1766
|
-
|
|
1771
|
+
/** Validate a --user-data-dir before launch. It must exist, must be a user-data
|
|
1772
|
+
* ROOT (not a Chrome PROFILE subdir — Chromium would silently mint a blank
|
|
1773
|
+
* logged-out Default inside it), and, in direct-open mode (no --profile-directory),
|
|
1774
|
+
* must not be a profile a live Chrome is holding open. With a profileName the
|
|
1775
|
+
* named subdir must exist; the live-lock is handled by the copy path (a warn),
|
|
1776
|
+
* not a refusal, since we never open the real root. die(2) on any miss. */
|
|
1777
|
+
function validateUserDataDir(dir, profileName) {
|
|
1767
1778
|
let st;
|
|
1768
1779
|
try {
|
|
1769
1780
|
st = statSync(dir);
|
|
@@ -1773,12 +1784,187 @@ function validateUserDataDir(dir) {
|
|
|
1773
1784
|
}
|
|
1774
1785
|
if (!st.isDirectory())
|
|
1775
1786
|
die(`--user-data-dir is not a directory: ${dir}`, 2);
|
|
1787
|
+
// Reject a Chrome PROFILE directory passed as the root. Chrome stores profiles
|
|
1788
|
+
// as subdirs (Default, Profile 1, …) of the user-data ROOT (which holds
|
|
1789
|
+
// 'Local State'); pointing --user-data-dir at a profile makes Chromium treat it
|
|
1790
|
+
// as a root and create a blank Default inside the real profile.
|
|
1791
|
+
const base = basename(dir);
|
|
1792
|
+
const looksLikeProfileName = /^(Default|Profile \d+)$/.test(base);
|
|
1793
|
+
const hasProfileFiles = existsSync(join(dir, "Preferences")) ||
|
|
1794
|
+
existsSync(join(dir, "Cookies")) ||
|
|
1795
|
+
existsSync(join(dir, "History"));
|
|
1796
|
+
if (looksLikeProfileName || (hasProfileFiles && !existsSync(join(dir, "Local State")))) {
|
|
1797
|
+
die(`--user-data-dir looks like a Chrome PROFILE directory, not a user-data root: ${dir}\n` +
|
|
1798
|
+
`Pass the PARENT directory (the one containing 'Local State') plus --profile-directory '${looksLikeProfileName ? base : "<name>"}'.`, 2);
|
|
1799
|
+
}
|
|
1800
|
+
if (profileName != null) {
|
|
1801
|
+
// Copy mode: the named profile subdir must exist inside the root.
|
|
1802
|
+
if (!existsSync(join(dir, profileName))) {
|
|
1803
|
+
const profiles = (() => {
|
|
1804
|
+
try {
|
|
1805
|
+
return readdirSync(dir, { withFileTypes: true })
|
|
1806
|
+
.filter((e) => e.isDirectory() && /^(Default|Profile \d+)$/.test(e.name))
|
|
1807
|
+
.map((e) => e.name);
|
|
1808
|
+
}
|
|
1809
|
+
catch {
|
|
1810
|
+
return [];
|
|
1811
|
+
}
|
|
1812
|
+
})();
|
|
1813
|
+
die(`--profile-directory '${profileName}' not found under ${dir}` +
|
|
1814
|
+
(profiles.length ? ` (available: ${profiles.join(", ")})` : "") +
|
|
1815
|
+
`\nFind the exact folder name at chrome://version → "Profile Path".`, 2);
|
|
1816
|
+
}
|
|
1817
|
+
return; // the copy path handles a running Chrome (a warn), never opens the root
|
|
1818
|
+
}
|
|
1819
|
+
// Direct-open mode: refuse a profile a live Chrome is holding open.
|
|
1776
1820
|
for (const lock of ["SingletonLock", "SingletonSocket"]) {
|
|
1777
1821
|
if (existsSync(join(dir, lock))) {
|
|
1778
1822
|
die(`--user-data-dir looks like a live/locked Chrome profile (${lock} present): ${dir}\n` +
|
|
1779
1823
|
`Never point Clipy at a running Chrome's profile — Chrome locks it while open. Close that Chrome, or use a COPY / a dedicated logged-in profile dir.`, 2);
|
|
1780
1824
|
}
|
|
1781
1825
|
}
|
|
1826
|
+
// A bare --user-data-dir at a REAL Chrome installation opens its Default profile
|
|
1827
|
+
// IN PLACE — the recording browser can write to it. Warn (don't refuse: a quit
|
|
1828
|
+
// Chrome is a legitimate, if lossy, way to record). Scratch/dedicated roots have
|
|
1829
|
+
// no Local State + Default/Preferences pair and stay silent.
|
|
1830
|
+
if (existsSync(join(dir, "Local State")) && existsSync(join(dir, "Default", "Preferences"))) {
|
|
1831
|
+
process.stderr.write(`${c.yellow("warning:")} this opens your real Chrome Default profile in place — the recording browser can write to it; ` +
|
|
1832
|
+
`prefer --profile-directory '<name>' (records an ephemeral copy, original untouched) or --source mac-screen\n`);
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
// --- --profile-directory: copy a named Chrome profile into a scratch root ----
|
|
1836
|
+
// Playwright's launchPersistentContext ignores --profile-directory (verified: the
|
|
1837
|
+
// switch is stripped and Default is always loaded), so selecting a named profile
|
|
1838
|
+
// means making it the Default of the root we open. We COPY <root>/<name> into a
|
|
1839
|
+
// temp scratch root's Default/ (+ the root's 'Local State') and launch against
|
|
1840
|
+
// that. The user's real profile is never opened or written. LOUD by design — this
|
|
1841
|
+
// whole track exists because silent profile substitution is the enemy.
|
|
1842
|
+
const PROFILE_COPY_PREFIX = "clipy-profile-";
|
|
1843
|
+
// Bulk cache dirs — identity lives in Cookies / Login Data / Local Storage /
|
|
1844
|
+
// Preferences, so we skip these to keep the copy small.
|
|
1845
|
+
const PROFILE_SKIP_TOP = new Set(["Cache", "Code Cache", "GPUCache"]);
|
|
1846
|
+
const SW_CACHE_FRAGMENT = join("Service Worker", "CacheStorage");
|
|
1847
|
+
/** Bytes we'll actually copy (identity, minus the skipped cache dirs). */
|
|
1848
|
+
function profileCopyableSize(profileDir) {
|
|
1849
|
+
let total = 0;
|
|
1850
|
+
const walk = (p, top) => {
|
|
1851
|
+
let entries;
|
|
1852
|
+
try {
|
|
1853
|
+
entries = readdirSync(p, { withFileTypes: true });
|
|
1854
|
+
}
|
|
1855
|
+
catch {
|
|
1856
|
+
return;
|
|
1857
|
+
}
|
|
1858
|
+
for (const e of entries) {
|
|
1859
|
+
if (top && (e.name.startsWith("Singleton") || PROFILE_SKIP_TOP.has(e.name)))
|
|
1860
|
+
continue;
|
|
1861
|
+
const full = join(p, e.name);
|
|
1862
|
+
if (full.includes(SW_CACHE_FRAGMENT))
|
|
1863
|
+
continue;
|
|
1864
|
+
try {
|
|
1865
|
+
if (e.isDirectory())
|
|
1866
|
+
walk(full, false);
|
|
1867
|
+
else
|
|
1868
|
+
total += statSync(full).size;
|
|
1869
|
+
}
|
|
1870
|
+
catch {
|
|
1871
|
+
// unreadable — skip
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
};
|
|
1875
|
+
walk(profileDir, true);
|
|
1876
|
+
return total;
|
|
1877
|
+
}
|
|
1878
|
+
/** Copy <userDataDir>/<profileName> into a fresh 0700 scratch root's Default/
|
|
1879
|
+
* (plus the root's 'Local State'), skipping Singleton-locks and cache dirs.
|
|
1880
|
+
* Prints the loud disclosure and a running-Chrome warning. Best-effort per
|
|
1881
|
+
* top-level entry, so a locked file loses only that entry. Returns the scratch
|
|
1882
|
+
* root to launch against. */
|
|
1883
|
+
function copyProfileToScratchRoot(userDataDir, profileName, log) {
|
|
1884
|
+
const srcProfile = join(userDataDir, profileName);
|
|
1885
|
+
if (existsSync(join(userDataDir, "SingletonLock")) || existsSync(join(userDataDir, "SingletonSocket"))) {
|
|
1886
|
+
log(c.yellow("warning: Chrome appears to be running — in-use databases may copy inconsistently; quit Chrome for a guaranteed-clean copy"));
|
|
1887
|
+
}
|
|
1888
|
+
const size = profileCopyableSize(srcProfile);
|
|
1889
|
+
// LOUD, always — the user must know their profile is being copied (never silent).
|
|
1890
|
+
log(`${c.dim("→")} copying profile '${profileName}' (${fmtBytes(size)}) into a temporary recording root — ` +
|
|
1891
|
+
`your real profile is never modified; the copy carries your logged-in identity and is deleted after upload`);
|
|
1892
|
+
// FALSE-IDENTITY GUARD (macOS): Chrome encrypts its cookies with a Keychain key
|
|
1893
|
+
// scoped to "Chrome Safe Storage", but the recorder runs Playwright's Chromium,
|
|
1894
|
+
// which reads "Chromium Safe Storage" — so a copied real-Chrome profile can open
|
|
1895
|
+
// LOOKING like the user (bookmarks, prefs, localStorage) while being silently
|
|
1896
|
+
// signed out. That's the exact class --profile-directory exists to prevent, so it
|
|
1897
|
+
// is a loud warning, never a docs footnote.
|
|
1898
|
+
if (process.platform === "darwin") {
|
|
1899
|
+
log(c.yellow("warning: On macOS, cookie-based logins in a real Chrome profile may not decrypt under the recorder's Chromium " +
|
|
1900
|
+
"(Chrome and Chromium use different Keychain keys) — localStorage/Preferences sessions survive. " +
|
|
1901
|
+
"If the recording lands logged out, that's why: record your real browser with --source mac-screen, " +
|
|
1902
|
+
"or drive your own browser and attach evidence with --observed/--verdict."));
|
|
1903
|
+
}
|
|
1904
|
+
const scratchRoot = join(tmpdir(), `${PROFILE_COPY_PREFIX}${randomUUID()}`);
|
|
1905
|
+
mkdirSync(scratchRoot, { recursive: true });
|
|
1906
|
+
try {
|
|
1907
|
+
chmodSync(scratchRoot, 0o700);
|
|
1908
|
+
}
|
|
1909
|
+
catch {
|
|
1910
|
+
// best-effort on platforms without POSIX modes
|
|
1911
|
+
}
|
|
1912
|
+
const destDefault = join(scratchRoot, "Default");
|
|
1913
|
+
mkdirSync(destDefault, { recursive: true });
|
|
1914
|
+
const skipped = [];
|
|
1915
|
+
for (const entry of readdirSync(srcProfile, { withFileTypes: true })) {
|
|
1916
|
+
const name = entry.name;
|
|
1917
|
+
if (name.startsWith("Singleton") || PROFILE_SKIP_TOP.has(name))
|
|
1918
|
+
continue;
|
|
1919
|
+
try {
|
|
1920
|
+
cpSync(join(srcProfile, name), join(destDefault, name), {
|
|
1921
|
+
recursive: true,
|
|
1922
|
+
// Skip the bulk CacheStorage nested under Service Worker.
|
|
1923
|
+
filter: (s) => !s.includes(SW_CACHE_FRAGMENT),
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
catch {
|
|
1927
|
+
skipped.push(name); // locked/unreadable — best-effort
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
// 'Local State' lives at the root and carries the os_crypt key Linux uses to
|
|
1931
|
+
// decrypt Cookies/Login Data (harmless elsewhere — macOS keys off the Keychain).
|
|
1932
|
+
try {
|
|
1933
|
+
if (existsSync(join(userDataDir, "Local State"))) {
|
|
1934
|
+
cpSync(join(userDataDir, "Local State"), join(scratchRoot, "Local State"));
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
catch {
|
|
1938
|
+
// best-effort
|
|
1939
|
+
}
|
|
1940
|
+
if (skipped.length) {
|
|
1941
|
+
log(c.yellow(`note: skipped ${skipped.length} locked/unreadable profile entr${skipped.length === 1 ? "y" : "ies"} (${skipped.join(", ")})`));
|
|
1942
|
+
}
|
|
1943
|
+
return scratchRoot;
|
|
1944
|
+
}
|
|
1945
|
+
/** Remove stranded profile copies (a SIGKILL between copy and cleanup can leave
|
|
1946
|
+
* one). Swept at the start of every record/session start. Best-effort. */
|
|
1947
|
+
function sweepStaleProfileCopies() {
|
|
1948
|
+
const now = Date.now();
|
|
1949
|
+
let entries;
|
|
1950
|
+
try {
|
|
1951
|
+
entries = readdirSync(tmpdir(), { withFileTypes: true });
|
|
1952
|
+
}
|
|
1953
|
+
catch {
|
|
1954
|
+
return;
|
|
1955
|
+
}
|
|
1956
|
+
for (const e of entries) {
|
|
1957
|
+
if (!e.isDirectory() || !e.name.startsWith(PROFILE_COPY_PREFIX))
|
|
1958
|
+
continue;
|
|
1959
|
+
const full = join(tmpdir(), e.name);
|
|
1960
|
+
try {
|
|
1961
|
+
if (now - statSync(full).mtimeMs > 24 * 3600 * 1000)
|
|
1962
|
+
rmSync(full, { recursive: true, force: true });
|
|
1963
|
+
}
|
|
1964
|
+
catch {
|
|
1965
|
+
// best-effort
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1782
1968
|
}
|
|
1783
1969
|
/** Launch a recording context. With userDataDir: a PERSISTENT context bound to
|
|
1784
1970
|
* that dir (launchPersistentContext — it IS the context, there's no separate
|
|
@@ -1820,8 +2006,9 @@ async function cmdRecord(ctx, opts) {
|
|
|
1820
2006
|
}
|
|
1821
2007
|
validateAuthCapture(opts.auth, target.href); // usage errors (exit 2) before auth/browser
|
|
1822
2008
|
if (opts.userDataDir)
|
|
1823
|
-
validateUserDataDir(opts.userDataDir);
|
|
2009
|
+
validateUserDataDir(opts.userDataDir, opts.profileDirectory);
|
|
1824
2010
|
requireKey(ctx); // fail fast before we spin up a browser
|
|
2011
|
+
sweepStaleProfileCopies(); // clear any profile copy a prior SIGKILL stranded
|
|
1825
2012
|
const chromium = await loadChromium();
|
|
1826
2013
|
const tmpDir = join(tmpdir(), `clipy-record-${randomUUID()}`);
|
|
1827
2014
|
mkdirSync(tmpDir, { recursive: true });
|
|
@@ -1829,6 +2016,18 @@ async function cmdRecord(ctx, opts) {
|
|
|
1829
2016
|
if (!opts.json)
|
|
1830
2017
|
process.stderr.write(`${m}\n`);
|
|
1831
2018
|
};
|
|
2019
|
+
// --profile-directory ⇒ copy the named profile into a scratch root's Default and
|
|
2020
|
+
// launch against THAT (Playwright can't select a named profile in-place). The
|
|
2021
|
+
// copy is disclosed loudly and cleaned up in the finally below. Always writes
|
|
2022
|
+
// the disclosure to stderr, even under --json (no silent profile substitution).
|
|
2023
|
+
let profileScratchRoot;
|
|
2024
|
+
const launchUserDataDir = (() => {
|
|
2025
|
+
if (opts.userDataDir && opts.profileDirectory) {
|
|
2026
|
+
profileScratchRoot = copyProfileToScratchRoot(opts.userDataDir, opts.profileDirectory, (m) => process.stderr.write(`${m}\n`));
|
|
2027
|
+
return profileScratchRoot;
|
|
2028
|
+
}
|
|
2029
|
+
return opts.userDataDir;
|
|
2030
|
+
})();
|
|
1832
2031
|
// Multi-viewport mode records every size sequentially into ONE video; the
|
|
1833
2032
|
// frame is sized to the largest viewport and smaller passes letterbox
|
|
1834
2033
|
// inside it. Each pass emits an auto note so the transcript chapters the
|
|
@@ -1861,7 +2060,7 @@ async function cmdRecord(ctx, opts) {
|
|
|
1861
2060
|
// browser sandbox isn't a trust boundary here. --user-data-dir ⇒ a persistent
|
|
1862
2061
|
// context (its own browser); else an ephemeral browser + context.
|
|
1863
2062
|
const { context, browser } = await launchRecordingContext(chromium, {
|
|
1864
|
-
userDataDir:
|
|
2063
|
+
userDataDir: launchUserDataDir,
|
|
1865
2064
|
viewport: frame,
|
|
1866
2065
|
recordVideoDir: tmpDir,
|
|
1867
2066
|
args: ["--no-sandbox", "--disable-dev-shm-usage"],
|
|
@@ -1954,6 +2153,14 @@ async function cmdRecord(ctx, opts) {
|
|
|
1954
2153
|
catch {
|
|
1955
2154
|
// best-effort temp cleanup
|
|
1956
2155
|
}
|
|
2156
|
+
if (profileScratchRoot) {
|
|
2157
|
+
try {
|
|
2158
|
+
rmSync(profileScratchRoot, { recursive: true, force: true });
|
|
2159
|
+
}
|
|
2160
|
+
catch {
|
|
2161
|
+
// best-effort — the 24h sweep will catch a stranded copy
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
1957
2164
|
}
|
|
1958
2165
|
if (opts.wait && uploaded.publicId) {
|
|
1959
2166
|
log(`${c.dim("waiting for transcript…")}`);
|
|
@@ -2050,6 +2257,38 @@ function cleanupSessionFiles(state, file) {
|
|
|
2050
2257
|
}
|
|
2051
2258
|
}
|
|
2052
2259
|
}
|
|
2260
|
+
/** Annotation for a mark Clipy itself evaluated against its own live page. */
|
|
2261
|
+
function verifiedMarkAnnotation(passed, expected, observed) {
|
|
2262
|
+
return passed
|
|
2263
|
+
? `[assert ✓ verified-by-clipy; ${observed}]`
|
|
2264
|
+
: `[ASSERT ✗ verified-by-clipy; expected ${expected}; observed ${observed}]`;
|
|
2265
|
+
}
|
|
2266
|
+
/** Annotation for a mark the DRIVER attested — Clipy records the claim and the
|
|
2267
|
+
* agent's observed values, and never presents it as its own verification. */
|
|
2268
|
+
function attestedMarkAnnotation(verdict, observed) {
|
|
2269
|
+
return `[ASSERT ${verdict === "pass" ? "✓" : "✗"} driver-attested; observed=${observed}]`;
|
|
2270
|
+
}
|
|
2271
|
+
/** The leading [verification] note. The two provenances are SEPARATE segments and
|
|
2272
|
+
* are never pooled: clipy-verified (what Clipy checked against its own page) vs
|
|
2273
|
+
* driver-attested (what the agent reported). With only clipy-verified marks the
|
|
2274
|
+
* rendering stays byte-identical to the pre-0.8.3 single-segment form, so existing
|
|
2275
|
+
* consumers don't churn. Returns [] when nothing was asserted. */
|
|
2276
|
+
function verificationNote(t) {
|
|
2277
|
+
const clipyN = t.clipyPassed + t.clipyFailed + t.clipyUnverified;
|
|
2278
|
+
const driverN = t.driverPassed + t.driverFailed;
|
|
2279
|
+
if (clipyN === 0 && driverN === 0)
|
|
2280
|
+
return [];
|
|
2281
|
+
const clipyBody = `${t.clipyPassed} passed, ${t.clipyFailed} failed` +
|
|
2282
|
+
(t.clipyUnverified > 0 ? `, ${t.clipyUnverified} unverified` : "");
|
|
2283
|
+
if (driverN === 0) {
|
|
2284
|
+
return [{ startMs: 0, text: `[verification] ${clipyN} assertion(s): ${clipyBody}` }];
|
|
2285
|
+
}
|
|
2286
|
+
const segments = [];
|
|
2287
|
+
if (clipyN > 0)
|
|
2288
|
+
segments.push(`${clipyN} clipy-verified: ${clipyBody}`);
|
|
2289
|
+
segments.push(`${driverN} driver-attested: ${t.driverPassed} passed, ${t.driverFailed} failed`);
|
|
2290
|
+
return [{ startMs: 0, text: `[verification] ${segments.join(" · ")}` }];
|
|
2291
|
+
}
|
|
2053
2292
|
/** Compile a URL glob to a RegExp: `**` → `.*`, a lone `*` → `[^/]*`, every
|
|
2054
2293
|
* other regex metachar escaped. A glob with NO `*` is treated as a bare
|
|
2055
2294
|
* substring match (the common "is this path in the URL" case). */
|
|
@@ -2307,9 +2546,10 @@ async function cmdSessionStart(ctx, opts) {
|
|
|
2307
2546
|
}
|
|
2308
2547
|
validateAuthCapture(opts.auth, target.href); // usage errors (exit 2) before auth/daemonizing
|
|
2309
2548
|
if (opts.userDataDir)
|
|
2310
|
-
validateUserDataDir(opts.userDataDir);
|
|
2549
|
+
validateUserDataDir(opts.userDataDir, opts.profileDirectory);
|
|
2311
2550
|
const key = requireKey(ctx);
|
|
2312
2551
|
await loadChromium(); // fail fast with install instructions before daemonizing
|
|
2552
|
+
sweepStaleProfileCopies();
|
|
2313
2553
|
const file = sessionFilePath(process.cwd());
|
|
2314
2554
|
const existing = readSessionState(file);
|
|
2315
2555
|
if (existing && sessionIsActive(existing)) {
|
|
@@ -2318,6 +2558,14 @@ async function cmdSessionStart(ctx, opts) {
|
|
|
2318
2558
|
}
|
|
2319
2559
|
if (existing)
|
|
2320
2560
|
cleanupSessionFiles(existing, file); // stale (daemon died) — clear
|
|
2561
|
+
// --profile-directory ⇒ copy the named profile into a scratch root HERE, in the
|
|
2562
|
+
// parent, so the user sees the loud disclosure (the daemon's stdout goes to a
|
|
2563
|
+
// log). The daemon launches against the scratch root and removes it at stop/abort;
|
|
2564
|
+
// profileScratchRoot flags it. Disclosure always to stderr, even under --json.
|
|
2565
|
+
let profileScratchRoot;
|
|
2566
|
+
const launchUserDataDir = opts.userDataDir && opts.profileDirectory
|
|
2567
|
+
? (profileScratchRoot = copyProfileToScratchRoot(opts.userDataDir, opts.profileDirectory, (m) => process.stderr.write(`${m}\n`)))
|
|
2568
|
+
: opts.userDataDir;
|
|
2321
2569
|
const maxSec = Math.min(Math.max(1, opts.maxSec), SESSION_HARD_CAP_SEC);
|
|
2322
2570
|
const id = randomUUID();
|
|
2323
2571
|
const dir = sessionDir();
|
|
@@ -2338,7 +2586,8 @@ async function cmdSessionStart(ctx, opts) {
|
|
|
2338
2586
|
initScriptPath: opts.auth.initScriptPath,
|
|
2339
2587
|
cookieSpecs: opts.auth.cookieSpecs.length ? opts.auth.cookieSpecs : undefined,
|
|
2340
2588
|
localStorageSpecs: opts.auth.localStorageSpecs.length ? opts.auth.localStorageSpecs : undefined,
|
|
2341
|
-
userDataDir:
|
|
2589
|
+
userDataDir: launchUserDataDir,
|
|
2590
|
+
profileScratchRoot,
|
|
2342
2591
|
state: "starting",
|
|
2343
2592
|
marksPath: join(dir, `marks-${id}.jsonl`),
|
|
2344
2593
|
controlPath: join(dir, `control-${id}.json`),
|
|
@@ -2427,29 +2676,42 @@ function printMarkResult(res, json) {
|
|
|
2427
2676
|
async function cmdMark(text, json, opts) {
|
|
2428
2677
|
const { file, state } = requireSession();
|
|
2429
2678
|
const hasAssert = !!opts.assert;
|
|
2679
|
+
const attest = opts.attest;
|
|
2430
2680
|
const backdated = opts.atSec != null || opts.agoSec != null;
|
|
2431
2681
|
if (state.kind === "mac") {
|
|
2432
|
-
// The Mac app records the real screen — there is no page to probe,
|
|
2433
|
-
//
|
|
2434
|
-
//
|
|
2682
|
+
// The Mac app records the real screen — there is no Clipy-owned page to probe,
|
|
2683
|
+
// so Clipy-EVALUATED assertions can't run here. Driver-attested marks CAN: the
|
|
2684
|
+
// agent brings its own observation and Clipy holds the ledger.
|
|
2435
2685
|
if (hasAssert) {
|
|
2436
|
-
die("assertions need a
|
|
2686
|
+
die("Clipy-evaluated assertions need a Clipy-owned page — use --observed/--verdict to attach evidence you collected yourself", 2);
|
|
2437
2687
|
}
|
|
2438
2688
|
if (backdated) {
|
|
2439
2689
|
die("--at/--ago need a web session — the Mac bridge stamps each mark on its own clock", 2);
|
|
2440
2690
|
}
|
|
2441
|
-
|
|
2691
|
+
// Driver-attested: annotate here (nothing to evaluate) and keep a CLI-side
|
|
2692
|
+
// tally in the session file — there's no daemon to compute one, so
|
|
2693
|
+
// `session stop` emits the [verification] summary as a final bridge mark.
|
|
2694
|
+
const macText = attest ? `${text.trim()} ${attestedMarkAnnotation(attest.verdict, attest.observed)}` : text;
|
|
2695
|
+
const result = await bridgeRequest(bridgeInfoFromSession(state), "mark", { text: macText }).catch((e) => {
|
|
2442
2696
|
if (e instanceof BridgeUnavailableError) {
|
|
2443
2697
|
cleanupSessionFiles(state, file);
|
|
2444
2698
|
die("the Clipy app is no longer running — session cleared. Start a new one.");
|
|
2445
2699
|
}
|
|
2446
2700
|
die(e.message);
|
|
2447
2701
|
});
|
|
2702
|
+
if (attest) {
|
|
2703
|
+
if (attest.verdict === "pass")
|
|
2704
|
+
state.attestedPassed = (state.attestedPassed ?? 0) + 1;
|
|
2705
|
+
else
|
|
2706
|
+
state.attestedFailed = (state.attestedFailed ?? 0) + 1;
|
|
2707
|
+
writeSessionState(file, state);
|
|
2708
|
+
}
|
|
2448
2709
|
if (json) {
|
|
2449
|
-
printJson(result);
|
|
2710
|
+
printJson({ ...result, text: macText, ...(attest ? { assert: { passed: attest.verdict === "pass", observed: attest.observed, attested: true } } : {}) });
|
|
2450
2711
|
return;
|
|
2451
2712
|
}
|
|
2452
|
-
|
|
2713
|
+
const glyph = attest && attest.verdict === "fail" ? c.red("✗") : c.green("✓");
|
|
2714
|
+
process.stdout.write(`${glyph} mark @ ${Number(result.atSeconds ?? 0).toFixed(1)}s — ${macText}\n`);
|
|
2453
2715
|
return;
|
|
2454
2716
|
}
|
|
2455
2717
|
if (!pidAlive(state.pid)) {
|
|
@@ -2481,14 +2743,23 @@ async function cmdMark(text, json, opts) {
|
|
|
2481
2743
|
text: cleanText,
|
|
2482
2744
|
...(atMs != null ? { atMs } : {}),
|
|
2483
2745
|
...(hasAssert ? { assert: opts.assert } : {}),
|
|
2746
|
+
...(attest ? { attest } : {}),
|
|
2484
2747
|
}, CONTROL_TIMEOUT_MS);
|
|
2485
2748
|
}
|
|
2486
2749
|
catch (e) {
|
|
2487
2750
|
const reason = String(e.message).slice(0, 120);
|
|
2488
2751
|
// NEVER drop a mark. If the daemon didn't answer, record the narration to
|
|
2489
|
-
// the file regardless.
|
|
2490
|
-
//
|
|
2491
|
-
|
|
2752
|
+
// the file regardless. A driver-attested mark needs no evaluation, so the
|
|
2753
|
+
// client annotates it here and it still counts in the driver segment.
|
|
2754
|
+
if (attest) {
|
|
2755
|
+
const annotated = `${cleanText} ${attestedMarkAnnotation(attest.verdict, attest.observed)}`;
|
|
2756
|
+
appendFileSync(state.marksPath, `${JSON.stringify({ id: markId, tMs: localTMs, text: annotated, attested: true, verdict: attest.verdict })}\n`, { mode: 0o600 });
|
|
2757
|
+
printMarkResult({ tMs: localTMs, text: annotated, assert: { passed: attest.verdict === "pass", observed: attest.observed, attested: true } }, json);
|
|
2758
|
+
return;
|
|
2759
|
+
}
|
|
2760
|
+
// For an ASSERTED mark we couldn't verify the claim, so tag it honestly
|
|
2761
|
+
// ⚠ UNVERIFIED (never a silent pass) — the daemon counts {unverified:true}
|
|
2762
|
+
// file marks into the clipy segment's third bucket.
|
|
2492
2763
|
if (hasAssert) {
|
|
2493
2764
|
const annotated = `${cleanText} [ASSERT ⚠ could not evaluate — ${reason}]`;
|
|
2494
2765
|
appendFileSync(state.marksPath, `${JSON.stringify({ id: markId, tMs: localTMs, text: annotated, unverified: true })}\n`, { mode: 0o600 });
|
|
@@ -2513,7 +2784,14 @@ async function cmdMark(text, json, opts) {
|
|
|
2513
2784
|
printMarkResult(res, json);
|
|
2514
2785
|
return;
|
|
2515
2786
|
}
|
|
2516
|
-
// No control endpoint (session started by a pre-0.6 CLI):
|
|
2787
|
+
// No control endpoint (session started by a pre-0.6 CLI): Clipy can't evaluate
|
|
2788
|
+
// anything, but a driver-attested mark needs no evaluation — annotate + record it.
|
|
2789
|
+
if (attest) {
|
|
2790
|
+
const annotated = `${cleanText} ${attestedMarkAnnotation(attest.verdict, attest.observed)}`;
|
|
2791
|
+
appendFileSync(state.marksPath, `${JSON.stringify({ id: markId, tMs: localTMs, text: annotated, attested: true, verdict: attest.verdict })}\n`, { mode: 0o600 });
|
|
2792
|
+
printMarkResult({ tMs: localTMs, text: annotated, assert: { passed: attest.verdict === "pass", observed: attest.observed, attested: true } }, json);
|
|
2793
|
+
return;
|
|
2794
|
+
}
|
|
2517
2795
|
if (hasAssert) {
|
|
2518
2796
|
die("this session has no control endpoint (started by an older clipy) — stop it and run `clipy session start` again to use assertion marks");
|
|
2519
2797
|
}
|
|
@@ -2580,6 +2858,20 @@ async function cmdSessionStop(json) {
|
|
|
2580
2858
|
if (state.kind === "mac") {
|
|
2581
2859
|
if (!json)
|
|
2582
2860
|
process.stderr.write(`${c.dim("stopping + uploading…")}\n`);
|
|
2861
|
+
// No daemon on the mac path to merge a tally, so emit the [verification]
|
|
2862
|
+
// summary ourselves as a final bridge mark (stamped at stop) BEFORE stopping.
|
|
2863
|
+
const macTally = verificationNote({
|
|
2864
|
+
clipyPassed: 0,
|
|
2865
|
+
clipyFailed: 0,
|
|
2866
|
+
clipyUnverified: 0,
|
|
2867
|
+
driverPassed: state.attestedPassed ?? 0,
|
|
2868
|
+
driverFailed: state.attestedFailed ?? 0,
|
|
2869
|
+
});
|
|
2870
|
+
if (macTally.length) {
|
|
2871
|
+
await bridgeRequest(bridgeInfoFromSession(state), "mark", { text: macTally[0].text }).catch(() => {
|
|
2872
|
+
// best-effort: never block the stop on the summary mark
|
|
2873
|
+
});
|
|
2874
|
+
}
|
|
2583
2875
|
const result = await bridgeRequest(bridgeInfoFromSession(state), "stop").catch((e) => {
|
|
2584
2876
|
cleanupSessionFiles(state, file);
|
|
2585
2877
|
die(e.message);
|
|
@@ -3037,16 +3329,23 @@ async function runSessionDaemon(file) {
|
|
|
3037
3329
|
let assertOut;
|
|
3038
3330
|
let assertOutcome;
|
|
3039
3331
|
let aborted = false;
|
|
3040
|
-
if (m.
|
|
3332
|
+
if (m.attest && typeof m.attest === "object") {
|
|
3333
|
+
// DRIVER-ATTESTED: the agent brought its own observation. Clipy evaluates
|
|
3334
|
+
// nothing here — it records the claim + the agent's observed values, labeled
|
|
3335
|
+
// so it can never be read as a Clipy verification.
|
|
3336
|
+
const passed = m.attest.verdict === "pass";
|
|
3337
|
+
annotated = `${text} ${attestedMarkAnnotation(m.attest.verdict, m.attest.observed)}`;
|
|
3338
|
+
assertOut = { passed, observed: m.attest.observed, attested: true };
|
|
3339
|
+
assertOutcome = { kind: "driver", passed, expected: "", observed: m.attest.observed };
|
|
3340
|
+
}
|
|
3341
|
+
else if (m.assert && typeof m.assert === "object") {
|
|
3041
3342
|
// evaluateAssertion throws if the page is unresponsive — the HTTP path
|
|
3042
3343
|
// turns that into a 5xx (the CLI then records a ⚠ UNVERIFIED file mark),
|
|
3043
3344
|
// and the in-page path rejects to the driver.
|
|
3044
3345
|
const ev = await evaluateAssertion(page, m.assert);
|
|
3045
|
-
annotated = ev.passed
|
|
3046
|
-
? `${text} [assert ✓ ${ev.observed}]`
|
|
3047
|
-
: `${text} [ASSERT ✗ expected ${ev.expected}; observed ${ev.observed}]`;
|
|
3346
|
+
annotated = `${text} ${verifiedMarkAnnotation(ev.passed, ev.expected, ev.observed)}`;
|
|
3048
3347
|
assertOut = { passed: ev.passed, observed: ev.observed };
|
|
3049
|
-
assertOutcome = { passed: ev.passed, expected: ev.expected, observed: ev.observed };
|
|
3348
|
+
assertOutcome = { kind: "clipy", passed: ev.passed, expected: ev.expected, observed: ev.observed };
|
|
3050
3349
|
if (!ev.passed && m.assert.failMode === "abort")
|
|
3051
3350
|
aborted = true;
|
|
3052
3351
|
// Backdated assertion divergence: a --at/--ago mark is stamped in the past
|
|
@@ -3145,6 +3444,7 @@ async function runSessionDaemon(file) {
|
|
|
3145
3444
|
text: typeof body.text === "string" ? body.text : "",
|
|
3146
3445
|
atMs: typeof body.atMs === "number" ? body.atMs : undefined,
|
|
3147
3446
|
assert: body.assert,
|
|
3447
|
+
attest: body.attest,
|
|
3148
3448
|
id: typeof body.id === "string" ? body.id : undefined,
|
|
3149
3449
|
});
|
|
3150
3450
|
/** POST /chapter → a === CHAPTER === mark at the live clock. Carries its
|
|
@@ -3329,7 +3629,11 @@ async function runSessionDaemon(file) {
|
|
|
3329
3629
|
const fileMarks = [];
|
|
3330
3630
|
const unverifiedClaimById = new Map(); // id → claim time (ms)
|
|
3331
3631
|
const abandonedIds = new Set(); // any id the client wrote to the file
|
|
3332
|
-
let assertUnverified = 0; // K
|
|
3632
|
+
let assertUnverified = 0; // K (clipy-verified marks we couldn't evaluate)
|
|
3633
|
+
// Driver-attested marks the client wrote to the file (control endpoint down):
|
|
3634
|
+
// they're already annotated client-side (nothing to evaluate) and still count.
|
|
3635
|
+
let driverPassed = 0;
|
|
3636
|
+
let driverFailed = 0;
|
|
3333
3637
|
try {
|
|
3334
3638
|
for (const line of readFileSync(state.marksPath, "utf8").split("\n")) {
|
|
3335
3639
|
if (!line.trim())
|
|
@@ -3339,6 +3643,12 @@ async function runSessionDaemon(file) {
|
|
|
3339
3643
|
continue;
|
|
3340
3644
|
const startMs = Math.max(0, Math.round(m.tMs));
|
|
3341
3645
|
fileMarks.push({ startMs, text: m.text.trim() }); // the mark of record, verbatim
|
|
3646
|
+
if (m.attested) {
|
|
3647
|
+
if (m.verdict === "pass")
|
|
3648
|
+
driverPassed++;
|
|
3649
|
+
else
|
|
3650
|
+
driverFailed++;
|
|
3651
|
+
}
|
|
3342
3652
|
if (m.id) {
|
|
3343
3653
|
abandonedIds.add(m.id);
|
|
3344
3654
|
if (m.unverified) {
|
|
@@ -3382,24 +3692,31 @@ async function runSessionDaemon(file) {
|
|
|
3382
3692
|
}
|
|
3383
3693
|
resolvedDaemon.push({ startMs: dm.startMs, text: dm.text });
|
|
3384
3694
|
if (dm.assertOutcome) {
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3695
|
+
const bump = dm.assertOutcome.passed ? 1 : 0;
|
|
3696
|
+
if (dm.assertOutcome.kind === "driver") {
|
|
3697
|
+
driverPassed += bump;
|
|
3698
|
+
driverFailed += 1 - bump;
|
|
3699
|
+
}
|
|
3700
|
+
else {
|
|
3701
|
+
assertPassed += bump;
|
|
3702
|
+
assertFailed += 1 - bump;
|
|
3703
|
+
}
|
|
3389
3704
|
}
|
|
3390
3705
|
}
|
|
3391
3706
|
let notes = [...fileMarks, ...resolvedDaemon, ...autoMarks].sort((a, b) => a.startMs - b.startMs);
|
|
3392
|
-
// If any ORIGINAL assertion was attempted
|
|
3393
|
-
//
|
|
3394
|
-
//
|
|
3395
|
-
//
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3707
|
+
// If any ORIGINAL assertion was attempted, prepend a 0ms verification summary so
|
|
3708
|
+
// it LEADS the transcript (a stable sort keeps it ahead of other 0ms marks). The
|
|
3709
|
+
// two provenances are reported as SEPARATE segments and never pooled. When only
|
|
3710
|
+
// clipy-verified marks exist the legacy single-segment rendering is byte-identical
|
|
3711
|
+
// (no churn for existing consumers). Late checks count toward neither.
|
|
3712
|
+
notes.unshift(...verificationNote({
|
|
3713
|
+
clipyPassed: assertPassed,
|
|
3714
|
+
clipyFailed: assertFailed,
|
|
3715
|
+
clipyUnverified: assertUnverified,
|
|
3716
|
+
driverPassed,
|
|
3717
|
+
driverFailed,
|
|
3718
|
+
}));
|
|
3719
|
+
notes.sort((a, b) => a.startMs - b.startMs);
|
|
3403
3720
|
// Server limit: cap the merged set at 200 marks (the verification note sorts
|
|
3404
3721
|
// to 0ms so it always survives the slice).
|
|
3405
3722
|
if (notes.length > 200) {
|
|
@@ -3450,6 +3767,16 @@ async function runSessionDaemon(file) {
|
|
|
3450
3767
|
await ctxToClose.close().catch(() => { });
|
|
3451
3768
|
if (browser)
|
|
3452
3769
|
await browser.close().catch(() => { });
|
|
3770
|
+
// Remove the copied-profile scratch root (a SIGKILL strands it → the 24h
|
|
3771
|
+
// sweep at the next record/session start catches that).
|
|
3772
|
+
if (state.profileScratchRoot) {
|
|
3773
|
+
try {
|
|
3774
|
+
rmSync(state.profileScratchRoot, { recursive: true, force: true });
|
|
3775
|
+
}
|
|
3776
|
+
catch {
|
|
3777
|
+
// best-effort
|
|
3778
|
+
}
|
|
3779
|
+
}
|
|
3453
3780
|
}
|
|
3454
3781
|
}
|
|
3455
3782
|
// ---------------------------------------------------------------------------
|
|
@@ -3541,7 +3868,7 @@ async function cmdAgents(ctx, sub, targetRaw, json) {
|
|
|
3541
3868
|
// command's shape without trial-and-error. Bump GUIDE_SCHEMA_VERSION when the
|
|
3542
3869
|
// contract changes.
|
|
3543
3870
|
// ---------------------------------------------------------------------------
|
|
3544
|
-
const GUIDE_SCHEMA_VERSION =
|
|
3871
|
+
const GUIDE_SCHEMA_VERSION = 9;
|
|
3545
3872
|
function cmdGuide(json) {
|
|
3546
3873
|
if (!json) {
|
|
3547
3874
|
process.stdout.write(HELP);
|
|
@@ -3592,9 +3919,9 @@ function cmdGuide(json) {
|
|
|
3592
3919
|
cmdDoc("download", "clipy download <id> [-o path]", "Download the MP4"),
|
|
3593
3920
|
cmdDoc("open", "clipy open <id>", "Open the share page in a browser"),
|
|
3594
3921
|
cmdDoc("wait", "clipy wait <id> [--for transcript|summary|both] [--timeout sec]", "Block until artifacts are ready"),
|
|
3595
|
-
cmdDoc("record", "clipy record --url <url> [--for sec] [--viewports list] [--title t] [--type kind] [--note '12: text']… [--storage-state f] [--cookie 'n=v']… [--local-storage 'k=v']… [--init-script f] [--wait] [--json]", "Headless one-shot capture of a web app; notes become the transcript. Notes are absolute ('12: text') or pass-scoped ('pass2: text' / 'pass2@5: text', anchored to a --viewports pass's real start; a malformed pass note is rejected). --type declares the recording kind (bug_report|feature_request|product_demo|walkthrough_tutorial|feedback_review|discussion_talk|other, plus aliases bug/feature/demo/walkthrough/feedback/discussion) so the AI summary reads it correctly. Auth (web capture only, applied before the first navigation so a logged-in SPA's route guard sees it): --storage-state <playwright storageState JSON path>, --cookie 'name=value[; Domain=d; Path=p; Secure; HttpOnly; SameSite=Lax]' (repeatable), --local-storage 'key=value' (repeatable, target origin only), --init-script <js file run before every page load>, --user-data-dir <dir> (launch a persistent Chromium
|
|
3596
|
-
cmdDoc("session", "clipy session <start|run|stop|abort|status> [--url <url>] [--max sec] [--type kind] [--source web|mac-screen] [--window w] [--display d] [--expose-cdp] [--storage-state f] [--cookie 'n=v']… [--local-storage 'k=v']… [--init-script f] [--json]", "Background recording session; auto-stops + uploads at --max (default 600s, cap 1800s). --type sets the recording kind (see record). --window/--display (with --source mac-screen) record one window/display. --expose-cdp (web sessions) opens a CDP endpoint (cdpUrl/cdpHttpUrl in the state file + session start/status output) so your own tools can drive the page while it records; OFF by default (any local process could attach), and CLIPY_DISABLE_CDP=1 forces it off. `session run [start flags] -- <command…>` starts a session, runs the command with inherited stdio (env CLIPY_SESSION=1, plus CLIPY_CDP_URL when --expose-cdp), then GUARANTEES cleanup: exit 0 uploads, any non-zero exit or signal discards (session abort) and propagates the child's code — the crash-safe wrapper so a dead driver never records dead air. Accepts the same auth flags as record (--storage-state/--user-data-dir/--cookie/--local-storage/--init-script; web only, rejected on --source mac-screen). `session run` exports CLIPY_SESSION_FILE to the child so mark/chapter resolve the session from any cwd. --json is supported on start/stop/status (start returns cdpUrl/cdpHttpUrl)", ["run", "--url", "--max", "--type", "--source", "--window", "--display", "--expose-cdp", "--storage-state", "--user-data-dir", "--cookie", "--local-storage", "--init-script", "--json"]),
|
|
3597
|
-
cmdDoc("mark", "clipy mark \"<text>\" [--assert-selector <css> [--assert-text <substr>]] [--assert-url <glob>] [--fail-mode warn|abort] [--at <sec>|--ago <sec>] [--json]", "Drop a live-timestamped note into the active session.
|
|
3922
|
+
cmdDoc("record", "clipy record --url <url> [--for sec] [--viewports list] [--title t] [--type kind] [--note '12: text']… [--storage-state f] [--cookie 'n=v']… [--local-storage 'k=v']… [--init-script f] [--wait] [--json]", "Headless one-shot capture of a web app; notes become the transcript. Notes are absolute ('12: text') or pass-scoped ('pass2: text' / 'pass2@5: text', anchored to a --viewports pass's real start; a malformed pass note is rejected). --type declares the recording kind (bug_report|feature_request|product_demo|walkthrough_tutorial|feedback_review|discussion_talk|other, plus aliases bug/feature/demo/walkthrough/feedback/discussion) so the AI summary reads it correctly. Auth (web capture only, applied before the first navigation so a logged-in SPA's route guard sees it): --storage-state <playwright storageState JSON path>, --cookie 'name=value[; Domain=d; Path=p; Secure; HttpOnly; SameSite=Lax]' (repeatable), --local-storage 'key=value' (repeatable, target origin only), --init-script <js file run before every page load>, --user-data-dir <dir> (launch from a persistent Chromium user-data ROOT with its whole logged-in identity; web only, mutually exclusive with --storage-state; refused if <dir> is a profile subdir — pass the root — or, in direct mode, a live-locked root via SingletonLock/Socket), --profile-directory <name> (with --user-data-dir: pick a NAMED profile like 'Profile 12' from chrome://version; Playwright can't select a profile in place, so Clipy COPIES it into a temp recording root and launches the copy — loudly disclosed, the real profile is never opened or written, and the copy is deleted after upload; no need to quit Chrome, though it warns if Chrome is running since in-use DBs may copy inconsistently). Auth boundary: --storage-state only seeds what the file contains; for cross-origin auth produce it with `npx playwright open --save-storage=auth.json <login-host>`, or use --user-data-dir + --profile-directory to record your real profile, or --source mac-screen --window Chrome. With --source mac-screen: records the real screen via the Clipy Mac app (--type not yet applied on mac; auth flags rejected — the screen is already logged in); --window '<title|app|id>' or --display <id> target one window/display (ids from clipy sources). --json prints {id, shareUrl, contextUrl, sizeBytes}", ["--for", "--viewports", "--title", "--description", "--type", "--note", "--storage-state", "--cookie", "--local-storage", "--init-script", "--user-data-dir", "--profile-directory", "--width", "--height", "--wait", "--source", "--window", "--display", "--json"]),
|
|
3923
|
+
cmdDoc("session", "clipy session <start|run|stop|abort|status> [--url <url>] [--max sec] [--type kind] [--source web|mac-screen] [--window w] [--display d] [--expose-cdp] [--storage-state f] [--cookie 'n=v']… [--local-storage 'k=v']… [--init-script f] [--json]", "Background recording session; auto-stops + uploads at --max (default 600s, cap 1800s). --type sets the recording kind (see record). --window/--display (with --source mac-screen) record one window/display. --expose-cdp (web sessions) opens a CDP endpoint (cdpUrl/cdpHttpUrl in the state file + session start/status output) so your own tools can drive the page while it records; OFF by default (any local process could attach), and CLIPY_DISABLE_CDP=1 forces it off. `session run [start flags] -- <command…>` starts a session, runs the command with inherited stdio (env CLIPY_SESSION=1, plus CLIPY_CDP_URL when --expose-cdp), then GUARANTEES cleanup: exit 0 uploads, any non-zero exit or signal discards (session abort) and propagates the child's code — the crash-safe wrapper so a dead driver never records dead air. Accepts the same auth flags as record (--storage-state/--user-data-dir/--profile-directory/--cookie/--local-storage/--init-script; web only, rejected on --source mac-screen). `session run` exports CLIPY_SESSION_FILE to the child so mark/chapter resolve the session from any cwd. --json is supported on start/stop/status (start returns cdpUrl/cdpHttpUrl)", ["run", "--url", "--max", "--type", "--source", "--window", "--display", "--expose-cdp", "--storage-state", "--user-data-dir", "--profile-directory", "--cookie", "--local-storage", "--init-script", "--json"]),
|
|
3924
|
+
cmdDoc("mark", "clipy mark \"<text>\" [--observed \"<values>\" --verdict pass|fail] [--assert-selector <css> [--assert-text <substr>]] [--assert-url <glob>] [--fail-mode warn|abort] [--at <sec>|--ago <sec>] [--json]", "Drop a live-timestamped note into the active session. A mark carries at most ONE evidence provenance, and the two are labeled + tallied separately so they can never be pooled. DRIVER-ATTESTED (--observed '<values>' --verdict pass|fail, both required together): you drove the browser and report what YOU observed — renders '<text> [ASSERT ✓ driver-attested; observed=<values>]' (or ✗) and works in EVERY session type including --source mac-screen. Honesty rule: driver-attested means Clipy vouches the agent SAID it, not that Clipy verified it — put real observed values there. Combining --observed/--verdict with --assert-* is a usage error. CLIPY-VERIFIED assertion marks (Clipy-owned page only) make the note evidence Clipy itself checked: --assert-selector checks a CSS selector matches (its trimmed textContent is recorded as 'observed'); --assert-text requires that element's text to contain a substring (needs --assert-selector); --assert-url matches the page URL against a glob (** = any, * = any non-slash, no * = substring). The daemon evaluates against its live page and annotates the mark: pass ⇒ '<text> [assert ✓ verified-by-clipy; <observed>]', fail ⇒ '<text> [ASSERT ✗ verified-by-clipy; expected …; observed …]' — a false claim cannot read as fact. --fail-mode warn (default) records the ✗; --fail-mode abort DISCARDS the whole session on a failed assertion (no upload) and the CLI exits non-zero. If any assertion was attempted, a leading 0ms [verification] note is prepended, reporting the provenances as SEPARATE segments: '[verification] N clipy-verified: P passed, F failed, K unverified · M driver-attested: P passed, F failed' (a segment is omitted when empty; with only clipy-verified marks the legacy 'N assertion(s): …' rendering is byte-identical). --at <sec> stamps at an absolute recording time; --ago <sec> stamps N seconds before now (mutually exclusive). Assertions/backdating need a web session (rejected on --source mac-screen). Up to 200 marks per recording.", ["--observed", "--verdict", "--assert-selector", "--assert-text", "--assert-url", "--fail-mode", "--at", "--ago", "--json"]),
|
|
3598
3925
|
cmdDoc("chapter", "clipy chapter \"<label>\" [--json]", "Mark a BEFORE/AFTER section boundary in the active recording (stored as '=== CHAPTER: <label> ==='). The PR-review shape: demo the base branch, run `clipy chapter \"AFTER — fix applied\"`, swap branches + restart the dev server, demo the fix — one video carrying both states. Works on web + --source mac-screen sessions.", ["--json"]),
|
|
3599
3926
|
cmdDoc("doctor", "clipy doctor [--json]", "One-shot health check: API key + whoami round-trip, Mac agent bridge (exists/parses/pid/appVersion>=" + MIN_BRIDGE_APP_VERSION + "), Playwright resolvability (and the resolved path/node_modules dir), and install mode (npx/global/local) — each a pass/warn/fail with a fix hint; exits non-zero if any check fails", ["--json"]),
|
|
3600
3927
|
cmdDoc("playwright-path", "clipy playwright-path [--json]", "Print the node_modules directory of the Playwright this CLI resolves, so your own --expose-cdp driver scripts can load the same copy: NODE_PATH=$(clipy playwright-path) node driver.js. Exits 1 (empty stdout) if Playwright is unresolvable. --json prints {path, nodeModulesDir, source}", ["--json"]),
|
|
@@ -3610,6 +3937,7 @@ function cmdGuide(json) {
|
|
|
3610
3937
|
"Headless captures have no audio: --note flags and session marks become the transcript, labeled agent-narration.",
|
|
3611
3938
|
"--note is absolute ('12: text') or pass-scoped ('pass2: text' / 'pass2@5: text'); pass-scoped notes anchor to the real start of a --viewports pass, so they don't drift when load time shifts the pass boundaries. A malformed pass note (e.g. 'pass2 text' with no colon) is a usage error, not silently demoted.",
|
|
3612
3939
|
"--type declares what a recording IS (bug_report/feature_request/product_demo/walkthrough_tutorial/feedback_review/discussion_talk/other, plus short aliases) so the AI summary doesn't misread a demo as a bug report. Applied on web today; --source mac-screen support is pending a Clipy app update.",
|
|
3940
|
+
"Clipy is a RECORDER, not a driver. When you drive the browser yourself (the usual agent case), the primary path is: record the real app (--source mac-screen --window '<app>', or your own driven browser) and attach evidence with driver-attested marks — `clipy mark \"<claim>\" --observed \"<values you read>\" --verdict pass|fail` — plus `clipy chapter` for before/after. Clipy holds the ledger; it does not drive. The owned-browser auth flags (--storage-state/--user-data-dir/--profile-directory/--cookie/--local-storage/--init-script) are the AGENTLESS/CI fallback for when nothing is driving and Clipy needs its own logged-in context. Provenance is never pooled: driver-attested marks render '[ASSERT ✓ driver-attested; observed=…]' and clipy-evaluated ones '[assert ✓ verified-by-clipy; …]', and the [verification] note counts them in separate segments. The honesty rule: driver-attested means Clipy vouches the agent SAID it, not that Clipy verified it.",
|
|
3613
3941
|
"Assertion marks are the differentiator: assert what you claim. `clipy mark \"X\" --assert-selector '.status' --assert-text Active` records X only alongside the live-page truth — the daemon runs the check against its Playwright page and annotates the mark ✓/✗ with what it actually observed, so a false claim cannot pass as fact in the transcript. --fail-mode abort turns a failed assertion into a discarded session (nothing uploaded, non-zero exit). Assertions need a web session and the daemon's control endpoint (started by clipy 0.6+); they are rejected on --source mac-screen.",
|
|
3614
3942
|
"A mark is NEVER dropped, and a late verdict never rewrites it. If the daemon can't be reached to evaluate an assertion (its event loop briefly starved during a dev-server recompile), `clipy mark` records the narration anyway tagged '[ASSERT ⚠ could not evaluate — <reason>]', prints a loud ⚠, and exits 0 — an unverified claim is flagged, never promoted to a ✓. The tally's third bucket counts these: '[verification] N assertion(s): P passed, F failed, K unverified' (the ', K unverified' clause is omitted when K=0). That ⚠ is the MARK OF RECORD: if the daemon was only slow and evaluates the same claim later, that verdict judged a LATER page state, so it does NOT overwrite the ⚠ — it's recorded as a separate '[late check of \"…\" — evaluated Ns after the claim: …]' note at its own time and counts toward none of P/F/K. Plain non-asserted marks the daemon later processes are just deduped (exactly once).",
|
|
3615
3943
|
"clipy chapter \"<label>\" splits one recording into BEFORE/AFTER sections for PR-review-style demos: record the base branch, `clipy chapter \"AFTER — fix applied\"`, swap branches + restart, record the fix. One video carries both states.",
|
|
@@ -3618,6 +3946,7 @@ function cmdGuide(json) {
|
|
|
3618
3946
|
"session --expose-cdp (web, opt-in) publishes a CDP endpoint (cdpHttpUrl) in `session start`/`session status` output and the 0600 session state file; connect with playwright.connectOverCDP() to drive the recorded page. Off by default (any local process could attach); CLIPY_DISABLE_CDP=1 forces it off.",
|
|
3619
3947
|
"Driving an --expose-cdp session: connect with playwright.connectOverCDP(cdpHttpUrl); the recorded page is browser.contexts()[0].pages()[0] (a fresh context/page you open is NOT captured); page.viewportSize() is null over a CDP attach; resize with a CDP session's Emulation.setDeviceMetricsOverride, not setViewportSize. Your own driver script resolves Playwright from its own cwd — run it as NODE_PATH=$(clipy playwright-path) node driver.js if require('playwright') can't find it.",
|
|
3620
3948
|
"Auth for headless web capture (record + session start): --storage-state <playwright storageState JSON> is passed straight to Playwright's newContext; --cookie / --local-storage / --init-script are applied to the context BEFORE the first navigation, so a logged-in SPA's route guard sees the state on first paint (seeding it after navigating loses that race). --cookie without a Domain is url-scoped to the target; with a Domain it is domain-scoped. --local-storage pairs are origin-guarded to the target. All four are web-only and are rejected on --source mac-screen, which records the real, already-signed-in screen. The storage-state file may hold live credentials; the CLI never prints its contents and the session state file that carries these specs is chmod 0600.",
|
|
3949
|
+
"Recording a real Chrome profile: --user-data-dir is the user-data ROOT (the dir with 'Local State'), NOT a profile subdir — pointing it at a 'Default'/'Profile N' dir is refused (Chromium would mint a blank logged-out Default inside your real profile), with a hint to pass the parent + --profile-directory. --profile-directory '<name>' selects a named profile: Playwright's launchPersistentContext IGNORES an in-place --profile-directory switch (verified: it's stripped and Default always loads), so Clipy COPIES <root>/<name> into a temp 0700 scratch root's Default/ (+ the root's 'Local State'; skipping Singleton-locks and Cache/Code Cache/GPUCache/Service Worker CacheStorage), launches the copy, and deletes it after upload. The copy is disclosed loudly on stderr (never silent — that's the whole point), the real profile is never opened or written, a running Chrome only draws a warning (in-use DBs may copy inconsistently), and a stranded copy from a SIGKILL is swept after 24h at the next record/session start.",
|
|
3621
3950
|
"clipy record gates its capture clock on the first non-blank frame (up to a 10s cap, then starts anyway) so notes aren't anchored to a still-compiling t=0.",
|
|
3622
3951
|
"Run `clipy doctor` first when record/session or --source mac-screen fails — it names the exact missing piece (key, bridge socket/handshake/version, Playwright, install mode).",
|
|
3623
3952
|
"Public recordings have an unauthenticated context document at https://clipy.online/video/<id>.md.",
|
|
@@ -3722,11 +4051,14 @@ async function main() {
|
|
|
3722
4051
|
"assert-text": { type: "string" },
|
|
3723
4052
|
"assert-url": { type: "string" },
|
|
3724
4053
|
"fail-mode": { type: "string" },
|
|
4054
|
+
observed: { type: "string" },
|
|
4055
|
+
verdict: { type: "string" },
|
|
3725
4056
|
at: { type: "string" },
|
|
3726
4057
|
ago: { type: "string" },
|
|
3727
4058
|
"expose-cdp": { type: "boolean", default: false },
|
|
3728
4059
|
"storage-state": { type: "string" },
|
|
3729
4060
|
"user-data-dir": { type: "string" },
|
|
4061
|
+
"profile-directory": { type: "string" },
|
|
3730
4062
|
"init-script": { type: "string" },
|
|
3731
4063
|
cookie: { type: "string", multiple: true },
|
|
3732
4064
|
"local-storage": { type: "string", multiple: true },
|
|
@@ -3767,6 +4099,7 @@ async function main() {
|
|
|
3767
4099
|
// without an explicit cwd — reads the same files the parent validated.
|
|
3768
4100
|
const authFlagsPresent = Boolean(values["storage-state"] ||
|
|
3769
4101
|
values["user-data-dir"] ||
|
|
4102
|
+
values["profile-directory"] ||
|
|
3770
4103
|
values["init-script"] ||
|
|
3771
4104
|
values.cookie?.length ||
|
|
3772
4105
|
values["local-storage"]?.length);
|
|
@@ -3787,6 +4120,17 @@ async function main() {
|
|
|
3787
4120
|
}
|
|
3788
4121
|
return resolve(String(values["user-data-dir"]));
|
|
3789
4122
|
};
|
|
4123
|
+
// --profile-directory names a profile subdir inside --user-data-dir; only
|
|
4124
|
+
// meaningful WITH it (Clipy copies that subdir into a scratch root's Default).
|
|
4125
|
+
const profileDirectory = () => {
|
|
4126
|
+
const pd = values["profile-directory"]?.trim();
|
|
4127
|
+
if (!pd)
|
|
4128
|
+
return undefined;
|
|
4129
|
+
if (!values["user-data-dir"]) {
|
|
4130
|
+
die("--profile-directory names a profile inside --user-data-dir — pass --user-data-dir <chrome user-data root> too", 2);
|
|
4131
|
+
}
|
|
4132
|
+
return pd;
|
|
4133
|
+
};
|
|
3790
4134
|
const macAuthGuard = "auth state (--storage-state/--user-data-dir/--cookie/--local-storage/--init-script) applies to headless web capture — --source mac-screen records the real, already-logged-in screen";
|
|
3791
4135
|
switch (command) {
|
|
3792
4136
|
case "login":
|
|
@@ -3977,6 +4321,7 @@ async function main() {
|
|
|
3977
4321
|
json,
|
|
3978
4322
|
auth: authCapture(),
|
|
3979
4323
|
userDataDir: userDataDir(),
|
|
4324
|
+
profileDirectory: profileDirectory(),
|
|
3980
4325
|
});
|
|
3981
4326
|
return;
|
|
3982
4327
|
}
|
|
@@ -4018,6 +4363,7 @@ async function main() {
|
|
|
4018
4363
|
exposeCdp: Boolean(values["expose-cdp"]),
|
|
4019
4364
|
auth: authCapture(),
|
|
4020
4365
|
userDataDir: userDataDir(),
|
|
4366
|
+
profileDirectory: profileDirectory(),
|
|
4021
4367
|
};
|
|
4022
4368
|
};
|
|
4023
4369
|
if (sub === "start") {
|
|
@@ -4047,7 +4393,7 @@ async function main() {
|
|
|
4047
4393
|
case "mark": {
|
|
4048
4394
|
const text = rest.join(" ").trim();
|
|
4049
4395
|
if (!text) {
|
|
4050
|
-
die('usage: clipy mark "<what just happened>" [--assert-selector <css> [--assert-text <substr>]] [--assert-url <glob>] [--fail-mode warn|abort] [--at <sec>|--ago <sec>]', 2);
|
|
4396
|
+
die('usage: clipy mark "<what just happened>" [--observed "<values>" --verdict pass|fail] [--assert-selector <css> [--assert-text <substr>]] [--assert-url <glob>] [--fail-mode warn|abort] [--at <sec>|--ago <sec>]', 2);
|
|
4051
4397
|
}
|
|
4052
4398
|
const selector = values["assert-selector"]?.trim() || undefined;
|
|
4053
4399
|
const expectText = values["assert-text"]; // exact, not trimmed
|
|
@@ -4060,6 +4406,22 @@ async function main() {
|
|
|
4060
4406
|
die("--fail-mode must be warn or abort", 2);
|
|
4061
4407
|
}
|
|
4062
4408
|
const hasAssert = Boolean(selector || (expectText != null && expectText !== "") || urlGlob);
|
|
4409
|
+
// Driver-attested provenance: --observed + --verdict travel together, and a
|
|
4410
|
+
// mark carries exactly ONE provenance (Clipy verified it, or the agent did).
|
|
4411
|
+
const observed = values.observed;
|
|
4412
|
+
const verdictRaw = values.verdict?.trim().toLowerCase();
|
|
4413
|
+
if ((observed == null) !== (verdictRaw == null)) {
|
|
4414
|
+
die("--observed and --verdict go together — pass both (the observed values you collected, and your pass/fail verdict)", 2);
|
|
4415
|
+
}
|
|
4416
|
+
if (verdictRaw != null && verdictRaw !== "pass" && verdictRaw !== "fail") {
|
|
4417
|
+
die("--verdict must be pass or fail", 2);
|
|
4418
|
+
}
|
|
4419
|
+
const attest = observed != null && verdictRaw != null
|
|
4420
|
+
? { observed, verdict: verdictRaw }
|
|
4421
|
+
: undefined;
|
|
4422
|
+
if (attest && hasAssert) {
|
|
4423
|
+
die("--observed/--verdict (driver-attested) and --assert-* (Clipy-verified) are different provenances — use one per mark", 2);
|
|
4424
|
+
}
|
|
4063
4425
|
if (failModeRaw && !hasAssert) {
|
|
4064
4426
|
die("--fail-mode only applies with an assertion (--assert-selector / --assert-text / --assert-url)", 2);
|
|
4065
4427
|
}
|
|
@@ -4073,6 +4435,7 @@ async function main() {
|
|
|
4073
4435
|
assert: hasAssert
|
|
4074
4436
|
? { selector, expectText, urlGlob, failMode: failModeRaw || "warn" }
|
|
4075
4437
|
: undefined,
|
|
4438
|
+
attest,
|
|
4076
4439
|
});
|
|
4077
4440
|
return;
|
|
4078
4441
|
}
|
package/dist/skill.js
CHANGED
|
@@ -15,7 +15,7 @@ description: Read and create Clipy screen recordings. Use when the user shares a
|
|
|
15
15
|
|
|
16
16
|
# Clipy — recordings you can read AND make
|
|
17
17
|
|
|
18
|
-
Written for @clipy/cli + @clipy/mcp 0.8.
|
|
18
|
+
Written for @clipy/cli + @clipy/mcp 0.8.3 (the two versions move in lockstep). If
|
|
19
19
|
\`clipy --version\` reports older, upgrade first: \`npm i -g @clipy/cli@latest\`.
|
|
20
20
|
|
|
21
21
|
Clipy (clipy.online) is the screen recorder built to be agent-readable. Every
|
|
@@ -81,14 +81,30 @@ Notes are absolute (\`"12: text"\`) or pass-scoped (\`"pass2: text"\`,
|
|
|
81
81
|
\`"pass2@5: text"\`). Pass-scoped notes anchor to a --viewports pass's REAL start,
|
|
82
82
|
so they stay aligned when load time shifts the pass boundaries.
|
|
83
83
|
|
|
84
|
-
## Recording a logged-in app
|
|
84
|
+
## Recording a logged-in app
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
86
|
+
**Preferred when YOU are driving (the usual agent case):** don't hand Clipy the
|
|
87
|
+
credentials at all. Drive the REAL, already-logged-in browser with your own tooling
|
|
88
|
+
and let Clipy record the screen:
|
|
89
|
+
|
|
90
|
+
clipy session start --source mac-screen --window "Chrome" --title "PR-1234 verification"
|
|
91
|
+
# …drive the real Chrome with your own tooling, attaching evidence as you go:
|
|
92
|
+
clipy mark "redemptions tab active" --observed "tab=Redemptions, rows=14" --verdict pass
|
|
93
|
+
clipy chapter "AFTER — fix applied"
|
|
94
|
+
clipy session stop
|
|
95
|
+
|
|
96
|
+
No auth to reproduce, no credentials in flags, and the recording shows the real app.
|
|
97
|
+
Clipy is the camera + the ledger; you are the driver.
|
|
98
|
+
|
|
99
|
+
### Fallback: hand Clipy its own browser (agentless / CI)
|
|
100
|
+
|
|
101
|
+
When nothing is driving — a one-shot \`clipy record\` in CI, or a headless session
|
|
102
|
+
you're not steering — Clipy needs its own logged-in context. The headless browser
|
|
103
|
+
starts signed out, so seed the session BEFORE the first navigation — otherwise the
|
|
104
|
+
app's route guard runs before your credentials exist and redirects to /login (seeding
|
|
105
|
+
localStorage AFTER visiting a guarded route loses that race). \`--storage-state\` and
|
|
106
|
+
\`--init-script\` apply BEFORE any page script structurally, which is what avoids the
|
|
107
|
+
trap. These flags are web-only (rejected on --source mac-screen):
|
|
92
108
|
|
|
93
109
|
# reuse a saved Playwright login (cookies + per-origin localStorage)
|
|
94
110
|
clipy record --url https://app.example.com/dashboard --for 20 --storage-state ./auth.json
|
|
@@ -103,11 +119,17 @@ work on both \`record\` and \`session start\` (web only; rejected on --source ma
|
|
|
103
119
|
repeatable; without a Domain it's url-scoped to the target.
|
|
104
120
|
- \`--local-storage "key=value"\` — repeatable; origin-guarded to the target.
|
|
105
121
|
- \`--init-script <file>\` — a JS file run before every page's own scripts.
|
|
106
|
-
- \`--user-data-dir <dir>\` — launch a PERSISTENT Chromium profile from
|
|
107
|
-
(its whole logged-in identity, not just injected storage).
|
|
108
|
-
exclusive with --storage-state; --cookie/--local-storage
|
|
109
|
-
compose.
|
|
110
|
-
|
|
122
|
+
- \`--user-data-dir <dir>\` — launch a PERSISTENT Chromium profile from the
|
|
123
|
+
user-data ROOT \`dir\` (its whole logged-in identity, not just injected storage).
|
|
124
|
+
Web only; mutually exclusive with --storage-state; --cookie/--local-storage/
|
|
125
|
+
--init-script still compose. Pass the ROOT, not a profile subdir (Clipy refuses
|
|
126
|
+
a profile dir and tells you the parent + --profile-directory to use).
|
|
127
|
+
- \`--profile-directory "<name>"\` — with --user-data-dir, pick a NAMED profile
|
|
128
|
+
(e.g. "Profile 12", from chrome://version → "Profile Path"). Clipy COPIES that
|
|
129
|
+
profile into a temporary recording root and launches it there (loudly — it
|
|
130
|
+
prints what it's copying); your real profile is never opened or modified, and
|
|
131
|
+
the copy is deleted after upload. This is how you record your actual logged-in
|
|
132
|
+
Chrome identity.
|
|
111
133
|
|
|
112
134
|
### The auth boundary (read this if a login won't stick)
|
|
113
135
|
|
|
@@ -118,8 +140,18 @@ Three reliable ways to record a real logged-in app:
|
|
|
118
140
|
1. Produce the state file with a REAL interactive login (it captures cross-domain
|
|
119
141
|
cookies): \`npx playwright open --save-storage=auth.json https://<login-host>\`,
|
|
120
142
|
sign in, close — then \`--storage-state auth.json\`.
|
|
121
|
-
2.
|
|
122
|
-
|
|
143
|
+
2. Your real Chrome profile via copy:
|
|
144
|
+
\`--user-data-dir "$HOME/Library/Application Support/Google/Chrome" --profile-directory "Profile 12"\`
|
|
145
|
+
(name from chrome://version). Clipy copies that profile to a temp root and
|
|
146
|
+
records the copy — no manual export, no quitting Chrome required (quit it for a
|
|
147
|
+
guaranteed-clean copy of in-use databases; Clipy warns if it's running).
|
|
148
|
+
⚠ ON macOS THIS CAN OPEN SILENTLY SIGNED OUT: Chrome encrypts cookies with a
|
|
149
|
+
Keychain key scoped to "Chrome Safe Storage", but the recorder runs Playwright's
|
|
150
|
+
CHROMIUM, which reads "Chromium Safe Storage". The copy can look like the user
|
|
151
|
+
(bookmarks, prefs, localStorage intact) while every cookie login is gone.
|
|
152
|
+
localStorage/Preferences sessions survive; cookie sessions may not. Clipy prints
|
|
153
|
+
this warning before recording. If the recording lands logged out, THAT is why —
|
|
154
|
+
fall back to option 3, or to the agent-driven path at the top of this section.
|
|
123
155
|
3. \`--source mac-screen --window "Chrome"\` — record your REAL logged-in Chrome
|
|
124
156
|
window (Mac app), no headless auth to reproduce at all.
|
|
125
157
|
|
|
@@ -149,12 +181,33 @@ Headless captures are silent, so your notes/marks BECOME the transcript (honestl
|
|
|
149
181
|
labeled as agent narration, never passed off as speech). Narrate every meaningful
|
|
150
182
|
step.
|
|
151
183
|
|
|
152
|
-
### Assert what you claim (
|
|
184
|
+
### Assert what you claim (two provenances, never pooled)
|
|
153
185
|
|
|
154
186
|
A plain mark is an unverified claim — you can write \`clipy mark "the Redemptions
|
|
155
187
|
tab is active"\` whether it's true or not, and the transcript reads as fact either
|
|
156
|
-
way. Make marks EVIDENCE
|
|
157
|
-
|
|
188
|
+
way. Make marks EVIDENCE. There are TWO ways, and Clipy labels which one produced
|
|
189
|
+
each mark so they can never be confused:
|
|
190
|
+
|
|
191
|
+
**A. Driver-attested — you brought the browser (the usual agent path).** You are
|
|
192
|
+
driving a real browser with your own tooling; Clipy is the camera + the ledger.
|
|
193
|
+
Attach the values YOU observed and your verdict:
|
|
194
|
+
|
|
195
|
+
clipy mark "redemptions tab active" --observed "tab=Redemptions, rows=14" --verdict pass
|
|
196
|
+
clipy mark "totals still stale" --observed "total=\$0.00 (expected \$412.50)" --verdict fail
|
|
197
|
+
|
|
198
|
+
Renders as \`… [ASSERT ✓ driver-attested; observed=<your values>]\` (or ✗). Both
|
|
199
|
+
flags are required together, and a mark carries exactly ONE provenance — combining
|
|
200
|
+
them with --assert-* is a usage error. Works in EVERY session type, including
|
|
201
|
+
\`--source mac-screen\`.
|
|
202
|
+
|
|
203
|
+
**THE HONESTY RULE — internalize this:**
|
|
204
|
+
driver-attested means Clipy vouches the agent SAID it, not that Clipy verified it.
|
|
205
|
+
Put real observed values in --observed (the actual text/number/URL you read), never a
|
|
206
|
+
restatement of the claim — the whole value of the ledger is that a reviewer can check
|
|
207
|
+
your attestation against the video.
|
|
208
|
+
|
|
209
|
+
**B. Clipy-verified — Clipy owns the page (headless web sessions only).** When the
|
|
210
|
+
recording IS a Clipy-owned Playwright page, Clipy can check the claim itself:
|
|
158
211
|
|
|
159
212
|
clipy mark "opened redemptions" --assert-url "**/redemptions"
|
|
160
213
|
clipy mark "status is Active" --assert-selector ".status-badge" --assert-text "Active"
|
|
@@ -166,13 +219,17 @@ against its live page:
|
|
|
166
219
|
- \`--assert-url <glob>\` — the page URL must match (\`**\` = anything, \`*\` = any
|
|
167
220
|
non-slash segment, no \`*\` = substring). Combine freely; all checks must pass.
|
|
168
221
|
|
|
169
|
-
A pass annotates the mark \`… [assert ✓ <observed>]\`; a fail
|
|
170
|
-
\`… [ASSERT ✗ expected …; observed …]\` — a wrong claim is
|
|
171
|
-
assertion, it can never read as fact. \`--fail-mode warn\`
|
|
172
|
-
and keeps going; \`--fail-mode abort\` DISCARDS the whole
|
|
173
|
-
non-zero exit) so you never ship a clip that asserted its
|
|
174
|
-
|
|
175
|
-
|
|
222
|
+
A pass annotates the mark \`… [assert ✓ verified-by-clipy; <observed>]\`; a fail
|
|
223
|
+
\`… [ASSERT ✗ verified-by-clipy; expected …; observed …]\` — a wrong claim is
|
|
224
|
+
preserved AS a failed assertion, it can never read as fact. \`--fail-mode warn\`
|
|
225
|
+
(default) records the ✗ and keeps going; \`--fail-mode abort\` DISCARDS the whole
|
|
226
|
+
session (nothing uploaded, non-zero exit) so you never ship a clip that asserted its
|
|
227
|
+
way into a broken state.
|
|
228
|
+
|
|
229
|
+
The leading \`[verification]\` note reports the two provenances as SEPARATE segments
|
|
230
|
+
and never pools them:
|
|
231
|
+
\`[verification] N clipy-verified: P passed, F failed[, K unverified] · M driver-attested: P passed, F failed\`
|
|
232
|
+
(a segment is omitted when it's empty).
|
|
176
233
|
|
|
177
234
|
A mark is NEVER dropped: if the recording daemon can't be reached to evaluate an
|
|
178
235
|
assertion (e.g. its event loop is briefly starved during a dev-server recompile),
|
|
@@ -182,9 +239,11 @@ unverified (the K bucket), never passed off as a ✓. That ⚠ is the MARK OF RE
|
|
|
182
239
|
if the daemon was only slow and evaluates the same claim a moment later, that late
|
|
183
240
|
verdict does NOT overwrite the ⚠ (it judged a later page state) — it's recorded as a
|
|
184
241
|
separate \`[late check of "…" — evaluated Ns after the claim: …]\` note at its own
|
|
185
|
-
time, and it counts toward neither passed/failed/unverified.
|
|
186
|
-
|
|
187
|
-
|
|
242
|
+
time, and it counts toward neither passed/failed/unverified. Clipy-VERIFIED
|
|
243
|
+
assertions need a Clipy-owned page, so \`--assert-*\` is rejected on
|
|
244
|
+
\`--source mac-screen\` — use \`--observed/--verdict\` there (and anywhere you drive
|
|
245
|
+
the browser yourself). Prefer attaching evidence to the specific claims a reviewer
|
|
246
|
+
cares about over narrating them bare.
|
|
188
247
|
|
|
189
248
|
### Before/after in one recording (clipy chapter)
|
|
190
249
|
|
|
@@ -251,7 +310,10 @@ evaluated daemon-side, annotated ✓/✗ identically:
|
|
|
251
310
|
|
|
252
311
|
It returns the annotated result (\`{ tMs, text, assert }\`); \`assertText\` without
|
|
253
312
|
\`assertSelector\` REJECTS so your driver sees the misuse, and \`failMode: "abort"\`
|
|
254
|
-
discards the session just like the CLI flag.
|
|
313
|
+
discards the session just like the CLI flag. \`__clipyMark\` deliberately has NO
|
|
314
|
+
observed/verdict option: it runs inside a Clipy-owned page, where clipy-verified is
|
|
315
|
+
strictly better than an attestation. Use \`--observed/--verdict\` for browsers Clipy
|
|
316
|
+
doesn't own.
|
|
255
317
|
|
|
256
318
|
(While CDP is exposed the page's own scripts can call these too — same trust model as
|
|
257
319
|
--expose-cdp itself.) \`clipy playwright-path\` prints the node_modules dir to resolve
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clipy/cli",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"description": "Command-line interface for Clipy — list, search, and read your screen recordings' transcripts, AI summaries, and key moments from the terminal.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|