@clipy/cli 0.4.1 → 0.5.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
@@ -65,10 +65,18 @@ One-shot capture of a running app (notes become the transcript, see below):
65
65
  clipy record --url http://localhost:3000 --for 20 --wait \\
66
66
  --title "Export button demo" --note "0: homepage" --note "8: export works"
67
67
 
68
+ Declare what you recorded with \`--type\` (demo|bug|walkthrough|feature|feedback|
69
+ discussion|other) — it keeps the AI summary from misreading a demo as a bug report.
70
+
68
71
  Multi screen-size demo (one video, a transcript chapter per pass):
69
72
 
70
73
  clipy record --url http://localhost:3000/settings \\
71
- --viewports mobile,tablet,desktop --title "Settings overflow fix"
74
+ --viewports mobile,tablet,desktop --title "Settings overflow fix" \\
75
+ --note "pass1: mobile" --note "pass2@3: tablet after scroll"
76
+
77
+ Notes are absolute (\`"12: text"\`) or pass-scoped (\`"pass2: text"\`,
78
+ \`"pass2@5: text"\`). Pass-scoped notes anchor to a --viewports pass's REAL start,
79
+ so they stay aligned when load time shifts the pass boundaries.
72
80
 
73
81
  ## Session mode — you drive the app, Clipy records
74
82
 
@@ -84,6 +92,14 @@ auto-stops and uploads at \`--max\` (default 600s, cap 1800s), so a forgotten
84
92
  session can't run away. One session per directory. Up to 200 marks per recording
85
93
  (further marks are refused, not silently dropped).
86
94
 
95
+ If you intend to drive the browser yourself, pass \`--expose-cdp\` to
96
+ \`session start\`: it opens a CDP endpoint (\`cdpHttpUrl\` in \`session start\` /
97
+ \`session status --json\` and the session state file). Connect your own tooling
98
+ (\`playwright.connectOverCDP(cdpHttpUrl)\`) and drive the EXISTING context/page —
99
+ navigation, clicks, viewport — to have your actions captured while it records.
100
+ It's OFF by default (while open, any local process can attach to that browser),
101
+ and \`CLIPY_DISABLE_CDP=1\` forces it off.
102
+
87
103
  Headless captures are silent, so your notes/marks BECOME the transcript (honestly
88
104
  labeled as agent narration, never passed off as speech). Narrate every meaningful
89
105
  step.
@@ -129,6 +145,16 @@ time.
129
145
  (\`clipy.online/video/<id>\`, the human page) AND the \`.md\` context URL
130
146
  (\`clipy.online/video/<id>.md\`, for their agents).
131
147
 
148
+ ## When record / session / --source mac-screen fails
149
+
150
+ Run \`clipy doctor\` (\`--json\` for parsing). It one-shot-checks the API key, the
151
+ Mac agent bridge (running? version new enough?), whether Playwright is loadable
152
+ from here, and how the CLI is installed — each a PASS/WARN/FAIL with a fix hint.
153
+ It names the exact missing piece instead of leaving you to guess. Under \`npx\`,
154
+ a globally-installed Playwright is NOT visible; \`clipy doctor\` says so and gives
155
+ the right fix (\`npm i -g @clipy/cli playwright\`, or run from a project that has
156
+ Playwright installed).
157
+
132
158
  ## Keeping the CLI current
133
159
 
134
160
  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.5.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,7 @@
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
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "^22.0.0",