@clipy/cli 0.4.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/macBridge.js CHANGED
@@ -8,7 +8,7 @@
8
8
  * token. Protocol: one JSON request line per connection, one JSON response
9
9
  * line back.
10
10
  */
11
- import { readFileSync } from "node:fs";
11
+ import { readFileSync, statSync } from "node:fs";
12
12
  import { homedir } from "node:os";
13
13
  import { join } from "node:path";
14
14
  import { createConnection } from "node:net";
@@ -17,11 +17,39 @@ export class BridgeUnavailableError extends Error {
17
17
  const REQUEST_TIMEOUT_MS = 15_000;
18
18
  /** stop waits for the streaming upload to hand back the share link. */
19
19
  const STOP_TIMEOUT_MS = 200_000;
20
+ /** The oldest Clipy Mac app version that ships the agent bridge this CLI drives.
21
+ * Older builds either don't write the discovery file at all or wrote it to a
22
+ * path the CLI never read (the pre-0.1.41 bundle-id location), so `--source
23
+ * mac-screen` silently found nothing. Surfaced by `clipy doctor` and in the
24
+ * stale/missing-bridge errors below. */
25
+ export const MIN_BRIDGE_APP_VERSION = "0.1.41";
26
+ const UPDATE_HINT = "your installed Clipy app may predate the agent bridge — update via https://clipy.online/download";
20
27
  export function bridgeFilePath() {
21
28
  if (process.env.CLIPY_BRIDGE_FILE?.trim())
22
29
  return process.env.CLIPY_BRIDGE_FILE;
23
30
  return join(homedir(), "Library", "Application Support", "Clipy", "agent-bridge.json");
24
31
  }
32
+ /** Numeric-dotted version compare: a<b → -1, a==b → 0, a>b → 1. Missing/short
33
+ * parts count as 0 (so "0.1" == "0.1.0"). */
34
+ export function compareVersions(a, b) {
35
+ const pa = a.split(".").map((x) => parseInt(x, 10) || 0);
36
+ const pb = b.split(".").map((x) => parseInt(x, 10) || 0);
37
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
38
+ const d = (pa[i] ?? 0) - (pb[i] ?? 0);
39
+ if (d !== 0)
40
+ return d < 0 ? -1 : 1;
41
+ }
42
+ return 0;
43
+ }
44
+ /** True only when a well-formed appVersion is present AND older than the minimum.
45
+ * A missing/garbled version returns false — we can't prove it's old, so callers
46
+ * fall back to the softer "may predate the bridge" hint instead. */
47
+ export function bridgeAppOutdated(appVersion) {
48
+ const v = appVersion?.trim();
49
+ if (!v || !/^\d+(\.\d+)*$/.test(v))
50
+ return false;
51
+ return compareVersions(v, MIN_BRIDGE_APP_VERSION) < 0;
52
+ }
25
53
  function pidAlive(pid) {
26
54
  try {
27
55
  process.kill(pid, 0);
@@ -32,33 +60,185 @@ function pidAlive(pid) {
32
60
  }
33
61
  }
34
62
  /** Reads + validates the discovery file; throws BridgeUnavailableError with a
35
- * friendly one-liner when the app isn't installed or running. */
63
+ * diagnostic one-liner (file path, pid + liveness, appVersion, and an update
64
+ * hint when the app looks too old) so an agent hitting a dead end can see what
65
+ * was actually found and self-correct. */
36
66
  export function readBridgeInfo() {
67
+ const path = bridgeFilePath();
37
68
  if (process.platform !== "darwin" && !process.env.CLIPY_BRIDGE_FILE) {
38
69
  throw new BridgeUnavailableError("--source mac-screen records through the Clipy Mac app, which only runs on macOS.");
39
70
  }
40
71
  let raw;
41
72
  try {
42
- raw = readFileSync(bridgeFilePath(), "utf8");
73
+ raw = readFileSync(path, "utf8");
43
74
  }
44
75
  catch {
45
- throw new BridgeUnavailableError("the Clipy app is not running (no agent bridge found). Open Clipy, or install it from https://clipy.online/download");
76
+ throw new BridgeUnavailableError(`the Clipy app is not running: no agent bridge file at ${path}. ` +
77
+ `Open Clipy (or install it from https://clipy.online/download). ` +
78
+ `If Clipy IS running, ${UPDATE_HINT}.`);
46
79
  }
47
80
  let info;
48
81
  try {
49
82
  info = JSON.parse(raw);
50
83
  }
51
84
  catch {
52
- throw new BridgeUnavailableError("agent bridge file is corrupt — restart the Clipy app");
85
+ throw new BridgeUnavailableError(`agent bridge file at ${path} is corrupt (unparseable JSON) — restart the Clipy app`);
53
86
  }
54
87
  if (!info.socketPath || !info.token || typeof info.pid !== "number") {
55
- throw new BridgeUnavailableError("agent bridge file is incomplete — restart the Clipy app");
88
+ const seen = info.appVersion ? ` (file reports appVersion ${info.appVersion})` : "";
89
+ throw new BridgeUnavailableError(`agent bridge file at ${path} is incomplete — missing socketPath/token/pid${seen}. ` +
90
+ `Restart the Clipy app.`);
56
91
  }
57
92
  if (!pidAlive(info.pid)) {
58
- throw new BridgeUnavailableError("the Clipy app is not running (stale agent bridge). Open Clipy and try again.");
93
+ // A dead pid whose file also reports a pre-bridge version is the classic
94
+ // "app predates the agent bridge" shape: an older Clipy is running under a
95
+ // different pid and can't rewrite this file (it has no bridge code), so a
96
+ // fresh launch never clears the stale artifact. Say so, don't just say
97
+ // "restart".
98
+ if (bridgeAppOutdated(info.appVersion)) {
99
+ throw new BridgeUnavailableError(`stale agent bridge at ${path} (pid ${info.pid} is dead, file appVersion ${info.appVersion}). ` +
100
+ `Your installed Clipy app likely predates the agent bridge (needs ${MIN_BRIDGE_APP_VERSION}+) — ` +
101
+ `update via https://clipy.online/download.`);
102
+ }
103
+ throw new BridgeUnavailableError(`stale agent bridge at ${path}: pid ${info.pid} is not running (dead)` +
104
+ `${info.appVersion ? `, appVersion ${info.appVersion}` : ""} — the Clipy app has quit. ` +
105
+ `Open Clipy and try again.`);
59
106
  }
60
107
  return info;
61
108
  }
109
+ /** Full BridgeInfo (INCLUDING the token) straight from the discovery file,
110
+ * skipping the liveness/version gating readBridgeInfo does — for the doctor
111
+ * handshake, which wants to attempt a `status` call even against a possibly
112
+ * stale file. Returns null when absent/incomplete. The token this carries must
113
+ * never be logged or placed in doctor's printed output. */
114
+ export function bridgeInfoFromFile() {
115
+ try {
116
+ const info = JSON.parse(readFileSync(bridgeFilePath(), "utf8"));
117
+ if (!info.socketPath || !info.token || typeof info.pid !== "number")
118
+ return null;
119
+ return {
120
+ socketPath: info.socketPath,
121
+ token: info.token,
122
+ pid: info.pid,
123
+ appVersion: typeof info.appVersion === "string" ? info.appVersion : "",
124
+ protocolVersion: typeof info.protocolVersion === "number" ? info.protocolVersion : 1,
125
+ };
126
+ }
127
+ catch {
128
+ return null;
129
+ }
130
+ }
131
+ /** Can we open the bridge's Unix socket at all? (Openable but unanswered is a
132
+ * distinct failure from a missing socket — doctor reports them separately.) */
133
+ export function probeSocketOpenable(socketPath) {
134
+ return new Promise((resolvePromise) => {
135
+ const socket = createConnection({ path: socketPath });
136
+ let done = false;
137
+ const finish = (openable) => {
138
+ if (done)
139
+ return;
140
+ done = true;
141
+ socket.destroy();
142
+ resolvePromise(openable);
143
+ };
144
+ const timer = setTimeout(() => finish(false), 2_000);
145
+ socket.on("connect", () => {
146
+ clearTimeout(timer);
147
+ finish(true);
148
+ });
149
+ socket.on("error", () => {
150
+ clearTimeout(timer);
151
+ finish(false);
152
+ });
153
+ });
154
+ }
155
+ /** Live handshake: ask the running app for its status (which echoes appVersion)
156
+ * so doctor can confirm the socket answers AND catch a discovery file that
157
+ * points at a different app version than the one actually replying. */
158
+ export async function probeBridgeHandshake(info) {
159
+ try {
160
+ const data = await bridgeRequest(info, "status");
161
+ const appVersion = typeof data.appVersion === "string" ? data.appVersion : undefined;
162
+ return { ok: true, appVersion };
163
+ }
164
+ catch (e) {
165
+ return { ok: false, error: e.message };
166
+ }
167
+ }
168
+ export function inspectBridge() {
169
+ const path = bridgeFilePath();
170
+ const applicable = process.platform === "darwin" || !!process.env.CLIPY_BRIDGE_FILE?.trim();
171
+ const base = {
172
+ path,
173
+ applicable,
174
+ exists: false,
175
+ parses: false,
176
+ complete: false,
177
+ pid: null,
178
+ pidAlive: null,
179
+ appVersion: null,
180
+ versionOk: null,
181
+ socketPath: null,
182
+ mtimeMs: null,
183
+ healthy: false,
184
+ detail: "",
185
+ };
186
+ if (!applicable) {
187
+ return {
188
+ ...base,
189
+ detail: "not macOS — the agent bridge is only used for --source mac-screen on macOS",
190
+ };
191
+ }
192
+ let raw;
193
+ try {
194
+ raw = readFileSync(path, "utf8");
195
+ }
196
+ catch {
197
+ return {
198
+ ...base,
199
+ detail: "no bridge file (the Clipy app is not running, or it predates the agent bridge)",
200
+ };
201
+ }
202
+ let mtimeMs = null;
203
+ try {
204
+ mtimeMs = statSync(path).mtimeMs;
205
+ }
206
+ catch {
207
+ // mtime is best-effort context, not a gate
208
+ }
209
+ const rep = { ...base, exists: true, mtimeMs };
210
+ let info;
211
+ try {
212
+ info = JSON.parse(raw);
213
+ }
214
+ catch {
215
+ return { ...rep, detail: "bridge file is corrupt (unparseable JSON)" };
216
+ }
217
+ rep.parses = true;
218
+ rep.appVersion = typeof info.appVersion === "string" ? info.appVersion : null;
219
+ rep.socketPath = typeof info.socketPath === "string" ? info.socketPath : null;
220
+ rep.pid = typeof info.pid === "number" ? info.pid : null;
221
+ rep.complete = !!info.socketPath && !!info.token && typeof info.pid === "number";
222
+ if (!rep.complete) {
223
+ return { ...rep, detail: "bridge file is incomplete (missing socketPath/token/pid)" };
224
+ }
225
+ rep.pidAlive = pidAlive(info.pid);
226
+ rep.versionOk = rep.appVersion ? !bridgeAppOutdated(rep.appVersion) : null;
227
+ if (!rep.pidAlive) {
228
+ return { ...rep, detail: `pid ${rep.pid} is not running (the Clipy app has quit)` };
229
+ }
230
+ if (bridgeAppOutdated(rep.appVersion)) {
231
+ return {
232
+ ...rep,
233
+ detail: `Clipy app v${rep.appVersion} is older than the required v${MIN_BRIDGE_APP_VERSION} — ${UPDATE_HINT}`,
234
+ };
235
+ }
236
+ return {
237
+ ...rep,
238
+ healthy: true,
239
+ detail: `Clipy app v${rep.appVersion ?? "?"} running (pid ${rep.pid})`,
240
+ };
241
+ }
62
242
  /** Enumerate capturable displays + windows from the running app. */
63
243
  export async function listSources(info) {
64
244
  const data = await bridgeRequest(info, "sources");
package/dist/skill.js CHANGED
@@ -15,6 +15,9 @@ 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.0 (the two versions move in lockstep). If
19
+ \`clipy --version\` reports older, upgrade first: \`npm i -g @clipy/cli@latest\`.
20
+
18
21
  Clipy (clipy.online) is the screen recorder built to be agent-readable. Every
19
22
  recording has a share link, an AI transcript + summary, key moments, and a
20
23
  machine-readable context document. With the CLI you can also CREATE recordings:
@@ -65,10 +68,41 @@ One-shot capture of a running app (notes become the transcript, see below):
65
68
  clipy record --url http://localhost:3000 --for 20 --wait \\
66
69
  --title "Export button demo" --note "0: homepage" --note "8: export works"
67
70
 
71
+ Declare what you recorded with \`--type\` (demo|bug|walkthrough|feature|feedback|
72
+ discussion|other) — it keeps the AI summary from misreading a demo as a bug report.
73
+
68
74
  Multi screen-size demo (one video, a transcript chapter per pass):
69
75
 
70
76
  clipy record --url http://localhost:3000/settings \\
71
- --viewports mobile,tablet,desktop --title "Settings overflow fix"
77
+ --viewports mobile,tablet,desktop --title "Settings overflow fix" \\
78
+ --note "pass1: mobile" --note "pass2@3: tablet after scroll"
79
+
80
+ Notes are absolute (\`"12: text"\`) or pass-scoped (\`"pass2: text"\`,
81
+ \`"pass2@5: text"\`). Pass-scoped notes anchor to a --viewports pass's REAL start,
82
+ so they stay aligned when load time shifts the pass boundaries.
83
+
84
+ ## Recording a logged-in app (headless web capture)
85
+
86
+ The headless browser starts signed out. To record a page behind auth, seed the
87
+ session BEFORE the first navigation — otherwise the app's route guard runs before
88
+ your credentials exist and redirects to /login (seeding localStorage AFTER visiting
89
+ a guarded route loses that race). \`--storage-state\` and \`--init-script\` apply
90
+ BEFORE any page script structurally, which is what avoids the trap. All four flags
91
+ work on both \`record\` and \`session start\` (web only; rejected on --source mac-screen):
92
+
93
+ # reuse a saved Playwright login (cookies + per-origin localStorage)
94
+ clipy record --url https://app.example.com/dashboard --for 20 --storage-state ./auth.json
95
+
96
+ # or seed a token / cookie directly
97
+ clipy session start --url https://app.example.com/dashboard \\
98
+ --local-storage "authToken=eyJ…" --cookie "sid=abc; Domain=app.example.com; Secure"
99
+
100
+ - \`--storage-state <file>\` — a Playwright storageState JSON (log in once, save
101
+ \`context.storageState({ path })\`); passed straight to newContext. Never printed.
102
+ - \`--cookie "name=value[; Domain=d; Path=p; Secure; HttpOnly; SameSite=Lax]"\` —
103
+ repeatable; without a Domain it's url-scoped to the target.
104
+ - \`--local-storage "key=value"\` — repeatable; origin-guarded to the target.
105
+ - \`--init-script <file>\` — a JS file run before every page's own scripts.
72
106
 
73
107
  ## Session mode — you drive the app, Clipy records
74
108
 
@@ -84,10 +118,88 @@ auto-stops and uploads at \`--max\` (default 600s, cap 1800s), so a forgotten
84
118
  session can't run away. One session per directory. Up to 200 marks per recording
85
119
  (further marks are refused, not silently dropped).
86
120
 
121
+ If you intend to drive the browser yourself, pass \`--expose-cdp\` to
122
+ \`session start\`: it opens a CDP endpoint (\`cdpHttpUrl\` in \`session start\` /
123
+ \`session status --json\` and the session state file). Connect your own tooling
124
+ (\`playwright.connectOverCDP(cdpHttpUrl)\`) and drive the EXISTING context/page —
125
+ navigation, clicks, viewport — to have your actions captured while it records.
126
+ It's OFF by default (while open, any local process can attach to that browser),
127
+ and \`CLIPY_DISABLE_CDP=1\` forces it off.
128
+
87
129
  Headless captures are silent, so your notes/marks BECOME the transcript (honestly
88
130
  labeled as agent narration, never passed off as speech). Narrate every meaningful
89
131
  step.
90
132
 
133
+ ### Assert what you claim (assertion marks)
134
+
135
+ A plain mark is an unverified claim — you can write \`clipy mark "the Redemptions
136
+ tab is active"\` whether it's true or not, and the transcript reads as fact either
137
+ way. Make marks EVIDENCE by attaching an assertion the recording daemon checks
138
+ against its live page:
139
+
140
+ clipy mark "opened redemptions" --assert-url "**/redemptions"
141
+ clipy mark "status is Active" --assert-selector ".status-badge" --assert-text "Active"
142
+
143
+ - \`--assert-selector <css>\` — the element must match (its trimmed text is recorded
144
+ as the observed value).
145
+ - \`--assert-text <substr>\` — that element's text must contain the substring (needs
146
+ --assert-selector).
147
+ - \`--assert-url <glob>\` — the page URL must match (\`**\` = anything, \`*\` = any
148
+ non-slash segment, no \`*\` = substring). Combine freely; all checks must pass.
149
+
150
+ A pass annotates the mark \`… [assert ✓ <observed>]\`; a fail annotates it
151
+ \`… [ASSERT ✗ expected …; observed …]\` — a wrong claim is preserved AS a failed
152
+ assertion, it can never read as fact. \`--fail-mode warn\` (default) records the ✗
153
+ and keeps going; \`--fail-mode abort\` DISCARDS the whole session (nothing uploaded,
154
+ non-zero exit) so you never ship a clip that asserted its way into a broken state.
155
+ If any assertions ran, a leading \`[verification] N assertion(s): P passed, F failed\`
156
+ note opens the transcript. Assertions need a WEB session (rejected on --source
157
+ mac-screen — there's no page to probe). Prefer asserting the specific claims a
158
+ reviewer cares about over narrating them unverified.
159
+
160
+ ### Before/after in one recording (clipy chapter)
161
+
162
+ \`clipy chapter "<label>"\` marks a section boundary, so one video carries a BEFORE
163
+ and an AFTER — the PR-review shape:
164
+
165
+ clipy session start --url http://localhost:3000/settings --title "Overflow fix"
166
+ clipy mark "sidebar overflows" --assert-selector ".sidebar.is-overflowing"
167
+ clipy chapter "AFTER — fix applied"
168
+ # (git switch fix-branch, restart the dev server, reload)
169
+ clipy mark "sidebar wraps" --assert-selector ".sidebar:not(.is-overflowing)"
170
+ clipy session stop
171
+
172
+ ### Crash-safe wrapping (clipy session run)
173
+
174
+ If your driver script crashes, a plain \`session start\` keeps recording dead air to
175
+ \`--max\` and uploads it. \`session run\` guarantees cleanup:
176
+
177
+ clipy session run --url http://localhost:3000 --expose-cdp -- node driver.js
178
+
179
+ It starts the session, runs everything after \`--\` with inherited stdio, then: exit
180
+ 0 → \`session stop\` (upload); any non-zero exit or signal → \`session abort\` (discard)
181
+ with the child's exit code propagated. The command runs with \`CLIPY_SESSION=1\` set
182
+ (and \`CLIPY_CDP_URL=<cdpHttpUrl>\` when --expose-cdp). All session-start flags apply
183
+ before the \`--\`.
184
+
185
+ ### Mark timing (backdating + in-page marks)
186
+
187
+ Each \`clipy mark\` is a process spawn (~100-300ms), so a mark can land slightly after
188
+ the state it describes. Backdate onto the recording clock:
189
+
190
+ clipy mark "toast appeared" --ago 2 # 2s before now
191
+ clipy mark "page loaded" --at 4 # absolute 4s on the recording clock
192
+
193
+ When you drive over --expose-cdp, emit marks IN-PAGE with zero spawn latency by
194
+ calling the bindings the daemon exposes:
195
+
196
+ await page.evaluate(() => window.__clipyMark("clicked Export"));
197
+ await page.evaluate(() => window.__clipyChapter("AFTER — fix applied"));
198
+
199
+ (While CDP is exposed the page's own scripts can call these too — same trust model as
200
+ --expose-cdp itself.) \`clipy playwright-path\` prints the node_modules dir to resolve
201
+ Playwright for your driver: \`NODE_PATH=$(clipy playwright-path) node driver.js\`.
202
+
91
203
  ## Record the real Mac screen — a window or a display
92
204
 
93
205
  Add \`--source mac-screen\` to \`record\` or \`session start\` to capture the REAL
@@ -129,6 +241,16 @@ time.
129
241
  (\`clipy.online/video/<id>\`, the human page) AND the \`.md\` context URL
130
242
  (\`clipy.online/video/<id>.md\`, for their agents).
131
243
 
244
+ ## When record / session / --source mac-screen fails
245
+
246
+ Run \`clipy doctor\` (\`--json\` for parsing). It one-shot-checks the API key, the
247
+ Mac agent bridge (running? version new enough?), whether Playwright is loadable
248
+ from here, and how the CLI is installed — each a PASS/WARN/FAIL with a fix hint.
249
+ It names the exact missing piece instead of leaving you to guess. Under \`npx\`,
250
+ a globally-installed Playwright is NOT visible; \`clipy doctor\` says so and gives
251
+ the right fix (\`npm i -g @clipy/cli playwright\`, or run from a project that has
252
+ Playwright installed).
253
+
132
254
  ## Keeping the CLI current
133
255
 
134
256
  If \`clipy\` misbehaves or a flag is missing, check the version:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clipy/cli",
3
- "version": "0.4.1",
3
+ "version": "0.8.0",
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",
@@ -38,7 +38,9 @@
38
38
  "build": "tsc",
39
39
  "prepublishOnly": "npm run build",
40
40
  "start": "node dist/index.js",
41
- "test:auth": "npm run build && node scripts/mock-auth-server.test.mjs"
41
+ "test:auth": "npm run build && node scripts/mock-auth-server.test.mjs && node scripts/doctor.test.mjs",
42
+ "test:session": "npm run build && node scripts/auth-guard.test.mjs && node scripts/session-control.test.mjs",
43
+ "test": "npm run test:auth && npm run test:session"
42
44
  },
43
45
  "devDependencies": {
44
46
  "@types/node": "^22.0.0",