@clipy/cli 0.17.0 → 0.18.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.
@@ -0,0 +1,279 @@
1
+ /**
2
+ * `clipy recheck` command: argument handling, Chrome for Clipy, upload and
3
+ * output around the pure pieces in recheck.ts. index.ts only parses flags and
4
+ * hands over the helpers it owns (Playwright loading and the proof upload).
5
+ */
6
+ import { mkdirSync, mkdtempSync } from "node:fs";
7
+ import { homedir, tmpdir } from "node:os";
8
+ import { join, resolve } from "node:path";
9
+ import { DEFAULT_CDP_PORT, newBackgroundPage, startChrome, } from "./chromeForClipy.js";
10
+ import { failure, request, recordingPath } from "./library.js";
11
+ import { buildRecheckPlan, createPageDriver, fmtClock, frameCaption, limitationsFor, readOriginalRun, RecheckInputError, RECHECK_MAX_STEPS, RECHECK_REPORT_VERSION, renderMarkdown, routeOf, runRecheck, summarize, writeReportFiles, } from "./recheck.js";
12
+ const USAGE = "usage: clipy recheck <id|url> --url <start-url> [--out <dir>] [--plan] [--no-upload] [--settle-ms N] [--nav-timeout-ms N] [--max-steps N] [--fail-on-divergence] [--allow-destructive] [--port N] [--json]";
13
+ function stamp() {
14
+ return new Date().toISOString().replace(/[:.]/g, "-");
15
+ }
16
+ export async function cmdRecheck(deps, id, opts) {
17
+ const usage = (message) => failure(deps, "usage_error", message, "Fix the arguments; `clipy guide --json` lists every command's flags.", 2);
18
+ if (!id)
19
+ usage(USAGE);
20
+ if (!Number.isInteger(opts.maxSteps) || opts.maxSteps < 1 || opts.maxSteps > RECHECK_MAX_STEPS) {
21
+ usage(`--max-steps must be an integer from 1 to ${RECHECK_MAX_STEPS}`);
22
+ }
23
+ if (!Number.isFinite(opts.settleMs) || opts.settleMs < 0 || opts.settleMs > 30_000)
24
+ usage("--settle-ms must be 0-30000");
25
+ if (!Number.isFinite(opts.navigationTimeoutMs) || opts.navigationTimeoutMs < 0 || opts.navigationTimeoutMs > 60_000) {
26
+ usage("--nav-timeout-ms must be 0-60000");
27
+ }
28
+ if (opts.port !== undefined && (!Number.isInteger(opts.port) || opts.port < 1 || opts.port > 65535)) {
29
+ usage("--port must be an integer from 1 to 65535");
30
+ }
31
+ let startUrl = null;
32
+ if (opts.startUrl) {
33
+ try {
34
+ const u = new URL(opts.startUrl);
35
+ if (u.protocol !== "http:" && u.protocol !== "https:")
36
+ throw new Error("scheme");
37
+ startUrl = u.href;
38
+ }
39
+ catch {
40
+ usage("--url must be an http(s) URL");
41
+ }
42
+ }
43
+ else if (!opts.planOnly) {
44
+ usage(`--url <start-url> is required (the page the workflow starts on)\n${USAGE}`);
45
+ }
46
+ const log = (m) => {
47
+ if (!deps.json)
48
+ process.stderr.write(`${deps.color.dim(m)}\n`);
49
+ };
50
+ const { pid } = recordingPath(deps, id);
51
+ let original;
52
+ try {
53
+ original = await readOriginalRun((path) => request(deps, "GET", path), pid);
54
+ }
55
+ catch (error) {
56
+ if (error instanceof RecheckInputError)
57
+ failure(deps, error.code, error.message, error.remediation);
58
+ throw error;
59
+ }
60
+ const planOpts = { allowIrreversible: opts.allowDestructive };
61
+ const plan = buildRecheckPlan(original, opts.maxSteps, planOpts);
62
+ const contextUrl = original.webUrl ? `${original.webUrl}.arec` : null;
63
+ if (opts.planOnly) {
64
+ const result = {
65
+ ok: true,
66
+ type: "clipy.recheck_plan",
67
+ version: RECHECK_REPORT_VERSION,
68
+ original: {
69
+ id: original.id,
70
+ name: original.name,
71
+ webUrl: original.webUrl,
72
+ contextUrl,
73
+ expectedResult: original.expectedResult,
74
+ timelineStatus: original.timelineStatus,
75
+ urlPrivacy: original.urlPrivacy,
76
+ eventsRead: original.events.length,
77
+ eventsTruncated: original.eventsTruncated,
78
+ },
79
+ steps: plan.steps,
80
+ truncatedSteps: plan.truncatedSteps,
81
+ limitations: limitationsFor(original, planOpts),
82
+ warnings: [],
83
+ };
84
+ if (deps.json)
85
+ return deps.printJson(result);
86
+ process.stdout.write(`${deps.color.bold(`Re-check plan for ${original.name || original.id}`)} (${plan.steps.length} steps)\n`);
87
+ for (const step of plan.steps) {
88
+ const what = step.kind === "click"
89
+ ? `click ${step.role ?? "control"}${step.label ? ` "${step.label}"` : ""}`
90
+ : step.kind === "start" || step.kind === "navigate"
91
+ ? `${step.kind} ${step.route}`
92
+ : `${step.kind}${step.direction ? ` ${step.direction}` : ""}`;
93
+ process.stdout.write(`${deps.color.cyan(String(step.index).padStart(2))} ${fmtClock(step.tMs)} ${what}` +
94
+ (step.unmappable ? deps.color.yellow(` (could not map: ${step.unmappable})`) : "") +
95
+ "\n");
96
+ }
97
+ if (original.expectedResult)
98
+ process.stdout.write(`\nExpected result: ${original.expectedResult}\n`);
99
+ return;
100
+ }
101
+ // The default folder is private (mkdtemp is 0700): the frames are
102
+ // screenshots of a signed-in app, and /tmp is shared on Linux. The id comes
103
+ // from the server, so it is reduced to a safe name before it touches a path.
104
+ let outDir;
105
+ if (opts.outDir) {
106
+ outDir = resolve(opts.outDir);
107
+ }
108
+ else {
109
+ const safeId = original.id.replace(/[^A-Za-z0-9_-]/g, "").slice(0, 40) || "recording";
110
+ outDir = mkdtempSync(join(tmpdir(), `clipy-recheck-${safeId}-${stamp()}-`));
111
+ }
112
+ const framesDir = join(outDir, "frames");
113
+ mkdirSync(framesDir, { recursive: true, mode: 0o700 });
114
+ const chromium = await deps.loadChromium();
115
+ const started = await startChrome(homedir(), process.env, process.platform, opts.port ?? DEFAULT_CDP_PORT);
116
+ if (!started.ok) {
117
+ failure(deps, "chrome_unavailable", `Chrome for Clipy is not available: ${started.error}`, "Run `clipy chrome status --json` and `clipy chrome start`; sign in to the app there once if the workflow needs a login, then re-run.");
118
+ }
119
+ log(`Chrome for Clipy ready on port ${started.state.port}`);
120
+ let browser = null;
121
+ let page = null;
122
+ // Tabs the replayed site opened (target=_blank, window.open): closed with
123
+ // the re-check's own window so nothing is left behind in Chrome for Clipy.
124
+ const popups = [];
125
+ let run;
126
+ let runError = null;
127
+ const aborter = new AbortController();
128
+ let cleaned = null;
129
+ const cleanup = () => {
130
+ cleaned ??= (async () => {
131
+ for (const p of [...popups, page])
132
+ await p?.close().catch(() => { });
133
+ // Disconnects; Chrome for Clipy keeps running.
134
+ await browser?.close().catch(() => { });
135
+ })();
136
+ return cleaned;
137
+ };
138
+ // Ctrl-C would otherwise end the process with the window still open on the
139
+ // replayed site: stop taking steps, close it, then exit as interrupted.
140
+ const onSignal = (signal) => {
141
+ aborter.abort();
142
+ void cleanup().finally(() => process.exit(signal === "SIGINT" ? 130 : 143));
143
+ };
144
+ process.once("SIGINT", onSignal);
145
+ process.once("SIGTERM", onSignal);
146
+ try {
147
+ browser = await chromium.connectOverCDP(`http://127.0.0.1:${started.state.port}`);
148
+ const context = browser.contexts()[0];
149
+ if (!context)
150
+ throw new Error("Chrome for Clipy has no browser context to attach to");
151
+ // Its own background window: the re-check never takes over a tab the user
152
+ // or another agent is using, and never brings Chrome to the front.
153
+ page = await newBackgroundPage(browser, context, true);
154
+ page.on?.("popup", (p) => {
155
+ popups.push(p);
156
+ });
157
+ const driver = createPageDriver(page, { settleMs: opts.settleMs });
158
+ run = await runRecheck(plan, driver, {
159
+ startUrl: startUrl,
160
+ framesDir,
161
+ navigationTimeoutMs: opts.navigationTimeoutMs,
162
+ urlPrivacy: original.urlPrivacy,
163
+ allowIrreversible: opts.allowDestructive,
164
+ signal: aborter.signal,
165
+ log,
166
+ });
167
+ }
168
+ catch (error) {
169
+ runError = error;
170
+ }
171
+ finally {
172
+ process.off("SIGINT", onSignal);
173
+ process.off("SIGTERM", onSignal);
174
+ // Here, before any failure(): failure() exits the process, so a finally
175
+ // around it would never run and the window would stay open.
176
+ await cleanup();
177
+ }
178
+ // Interrupted: the signal handler closes the window and owns the exit.
179
+ if (aborter.signal.aborted)
180
+ return;
181
+ if (runError || !run) {
182
+ if (runError instanceof RecheckInputError)
183
+ failure(deps, runError.code, runError.message, runError.remediation);
184
+ failure(deps, "chrome_unavailable", `the re-check could not drive Chrome for Clipy: ${runError?.message ?? "no result"}`, "Run `clipy chrome status --json`; if Chrome for Clipy is running, re-run once.");
185
+ }
186
+ const summary = summarize(run.steps);
187
+ const report = {
188
+ ok: true,
189
+ type: "clipy.recheck_report",
190
+ version: RECHECK_REPORT_VERSION,
191
+ original: {
192
+ id: original.id,
193
+ name: original.name,
194
+ webUrl: original.webUrl,
195
+ contextUrl,
196
+ sourcePlatform: original.sourcePlatform,
197
+ expectedResult: original.expectedResult,
198
+ timelineStatus: original.timelineStatus,
199
+ urlPrivacy: original.urlPrivacy,
200
+ eventsRead: original.events.length,
201
+ eventsTruncated: original.eventsTruncated,
202
+ },
203
+ start: { route: startUrl ? routeOf(startUrl) : null, originMapping: run.originMapping },
204
+ run: {
205
+ browser: "chrome-for-clipy",
206
+ startedAt: run.startedAt,
207
+ finishedAt: run.finishedAt,
208
+ framesDir,
209
+ truncatedSteps: plan.truncatedSteps,
210
+ },
211
+ recording: null,
212
+ summary,
213
+ steps: run.steps,
214
+ limitations: limitationsFor(original, planOpts),
215
+ warnings: [],
216
+ };
217
+ // Written before the upload, so a failed upload never costs the report.
218
+ writeReportFiles(outDir, report);
219
+ if (opts.upload) {
220
+ const frames = run.steps
221
+ .filter((s) => s.observed.frame)
222
+ .map((s) => ({ path: s.observed.frame, caption: frameCaption(s, run.steps.length) }));
223
+ if (frames.length === 0) {
224
+ report.warnings.push({
225
+ code: "recheck_upload_failed",
226
+ error: "no step frame was captured, so there is nothing to upload",
227
+ remediation: "Read the report; the per-step results do not depend on the frames.",
228
+ });
229
+ }
230
+ else {
231
+ try {
232
+ const uploaded = await deps.uploadFrames(frames, {
233
+ name: `Re-check: ${original.name || original.id}`,
234
+ description: `Re-check of ${original.webUrl ?? original.id} on ${report.start.route ?? "the start URL"}: ` +
235
+ `${summary.matched} matched, ${summary.controlNotFound} control not found, ${summary.differentScreen} different screen, ` +
236
+ `${summary.error} error, ${summary.unmapped} could not map.`,
237
+ log,
238
+ });
239
+ report.recording = uploaded;
240
+ }
241
+ catch (error) {
242
+ // The upload became a recording whose completion was not confirmed:
243
+ // uploading the frames again would make a duplicate.
244
+ const stranded = error.publicId;
245
+ if (stranded) {
246
+ report.recording = {
247
+ id: stranded,
248
+ shareUrl: `${deps.apiUrl}/video/${stranded}`,
249
+ contextUrl: `${deps.apiUrl}/video/${stranded}.arec`,
250
+ };
251
+ report.warnings.push({
252
+ code: "upload_unconfirmed",
253
+ error: `the step frames were uploaded as ${stranded}, but the server did not confirm its completion: ${error.message}`,
254
+ remediation: `Do not upload again; the recording exists. Check it with: clipy show ${stranded}`,
255
+ });
256
+ }
257
+ else {
258
+ report.warnings.push({
259
+ code: "recheck_upload_failed",
260
+ error: `the step frames could not be uploaded: ${error.message}`,
261
+ remediation: `The report and frames are saved in ${outDir}. Upload them with \`clipy proof --frame\` if a share link is needed; do not re-run the whole re-check for it.`,
262
+ });
263
+ }
264
+ }
265
+ }
266
+ writeReportFiles(outDir, report);
267
+ }
268
+ if (deps.json) {
269
+ deps.printJson({ ...report, files: { json: join(outDir, "report.json"), markdown: join(outDir, "report.md") } });
270
+ }
271
+ else {
272
+ process.stdout.write(renderMarkdown(report));
273
+ process.stdout.write(`${deps.color.dim(`report: ${join(outDir, "report.json")}`)}\n`);
274
+ }
275
+ // exitCode, not exit(): a large report written to a pipe must be flushed
276
+ // before the process ends (pipe writes are asynchronous on macOS).
277
+ if (opts.failOnDivergence && summary.verdict !== "matches")
278
+ process.exitCode = 4;
279
+ }
package/dist/skill.js CHANGED
@@ -10,12 +10,12 @@
10
10
  */
11
11
  export const CLIPY_SKILL_MD = `---
12
12
  name: clipy
13
- description: Read and create Clipy screen recordings, turn screenshots or tool-native video into proof, and turn any video into agent-readable context. Use when the user shares a clipy.online/video/<id> URL (watch, summarize, or act on a recording, bug report, or walkthrough), shares a YouTube URL, a Loom share link, or a local video file as context/reference for a task ("implement what this video shows", "give me the context of this video" — import it with clipy context import), OR asks you to verify your own work and share proof through Clipy.
13
+ description: Read and create Clipy screen recordings, turn screenshots or tool-native video into proof, and turn any video into agent-readable context. Use when the user shares a clipy.online/video/<id> URL (watch, summarize, or act on a recording, bug report, or walkthrough), shares a YouTube URL, a Loom share link, or a local video file as context/reference for a task ("implement what this video shows", "give me the context of this video" — import it with clipy context import), OR asks you to verify your own work and share proof through Clipy, OR asks whether a recorded workflow still works on today's UI (re-check it with clipy recheck).
14
14
  ---
15
15
 
16
16
  # Clipy — recordings you can read AND make
17
17
 
18
- Written for @clipy/cli + @clipy/mcp 0.17.0 (the two versions move in lockstep). If
18
+ Written for @clipy/cli + @clipy/mcp 0.18.0 (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
@@ -27,7 +27,8 @@ WebM/MP4, capture a running web app headlessly, or capture the real Mac screen
27
27
  through the running Clipy app, then hand back a watchable link.
28
28
 
29
29
  Commands below use \`clipy\`. If it is not on PATH, prefix with \`npx @clipy/cli\`
30
- (identical). Exit codes: \`0\` ok · \`1\` error · \`2\` usage · \`3\` artifact not ready.
30
+ (identical). Exit codes: \`0\` ok · \`1\` error · \`2\` usage · \`3\` artifact not ready ·
31
+ \`4\` \`clipy recheck --fail-on-divergence\` did not match (diverged or incomplete).
31
32
 
32
33
  The canonical live operating contract is \`https://clipy.online/agents.md\`. Fetch
33
34
  it when network access is available. It explains which surface to choose, auth and
@@ -422,6 +423,51 @@ data, or unrelated windows. After upload, read the returned result, then run
422
423
  \`clipy context <id>\` and confirm the narration matches the frames/video before
423
424
  sharing both URLs.
424
425
 
426
+ ## Re-check a recorded workflow against today's UI
427
+
428
+ When the user asks "does this recorded flow still work?", "re-check this
429
+ recording", or an agent is about to replay recorded steps, re-check it first.
430
+ Recorded workflows fail silently when the app changes; this tells a broken flow
431
+ from a redesign before anyone clicks the wrong control.
432
+
433
+ clipy recheck <id|url> --plan --json # the steps, no browser
434
+ clipy recheck <id|url> --url <start-url> --json # replay and report
435
+
436
+ It reads the recording's interaction timeline (clicks with element labels,
437
+ navigations, scrolls, typing), key moments and transcript, drives Chrome for
438
+ Clipy (its own background window, signed in once with \`clipy chrome start\`)
439
+ from \`--url\`, captures a frame per step and uploads them as a proof
440
+ recording (\`--no-upload\` keeps it local). \`--url\` may be another host than
441
+ the original (staging, localhost); recorded paths are then checked on that host, and nothing is clicked on any other host (a redirect back to production is a different screen).
442
+
443
+ Each step comes back as one of:
444
+
445
+ - \`matched\`: the page was on the recorded route and the labelled control was
446
+ found and clicked.
447
+ - \`replayed\`: a scroll, replayed by direction (the distance is not recorded).
448
+ - \`control_not_found\`: no visible control has the recorded label;
449
+ \`observed.nearbyControls\` names what is there now (often the rename).
450
+ - \`different_screen\`: the page is on another route, or the control is covered
451
+ (a dialog, a banner). Nothing is clicked.
452
+ - \`error\`: the step threw; the reason says what.
453
+ - \`unmapped\` ("could not map step"): typing (values are never captured),
454
+ unlabelled or right clicks, drags, a label shared by several controls with
455
+ no position to choose, or a control that reads as irreversible (delete, pay,
456
+ send, submit and similar). Never report an unmapped step as passing.
457
+
458
+ The replay clicks for real in a signed-in browser, so it never clicks an
459
+ irreversible-looking control on its own. Pass \`--allow-destructive\` only when
460
+ the user asked for those steps to be replayed and the site is one where that is
461
+ safe (a test account, staging). Run \`--plan\` first to see which steps those are.
462
+
463
+ Read \`summary.verdict\` (\`matches\` | \`diverged\` | \`incomplete\`) and
464
+ \`summary.firstDivergence\`. When \`original.expectedResult\` is set, the user
465
+ wrote down what should have happened: compare it with the last step's frame
466
+ yourself, the re-check does not judge it. Return the re-check's \`shareUrl\`
467
+ and \`contextUrl\`, the first diverging step, and its reason. Recordings with
468
+ no click or navigation data (a plain web-recorder take) fail with
469
+ \`no_interactions\`; there is nothing to replay.
470
+
425
471
  ## Making a recording — headless web app
426
472
 
427
473
  One-shot capture of a running app (notes become the transcript, see below):
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@clipy/cli",
3
- "version": "0.17.0",
4
- "description": "Command-line interface for Clipy \u2014 list, search, and read your screen recordings' transcripts, AI summaries, and key moments from the terminal.",
3
+ "version": "0.18.0",
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",
7
7
  "publishConfig": {
@@ -30,10 +30,10 @@
30
30
  "homepage": "https://clipy.online",
31
31
  "repository": {
32
32
  "type": "git",
33
- "url": "git+https://github.com/manovagyanik1/clipy-cli.git"
33
+ "url": "git+https://github.com/clipy-recorder/clipy-cli.git"
34
34
  },
35
35
  "bugs": {
36
- "url": "https://github.com/manovagyanik1/clipy-cli/issues"
36
+ "url": "https://github.com/clipy-recorder/clipy-cli/issues"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "tsc",
@@ -41,12 +41,13 @@
41
41
  "start": "node dist/index.js",
42
42
  "test:auth": "npm run build && node scripts/mock-auth-server.test.mjs && node scripts/doctor.test.mjs && node scripts/open-url.test.mjs",
43
43
  "test:proof": "npm run build && node scripts/proof-frames.test.mjs",
44
+ "test:recheck": "npm run build && node scripts/recheck.test.mjs",
44
45
  "test:setup": "npm run build && node scripts/setup.test.mjs && node scripts/chrome-for-clipy.test.mjs && node scripts/extension-abort.test.mjs && node scripts/capture-title.test.mjs && node scripts/cdp-client.test.mjs",
45
46
  "test:memory": "npm run build && node scripts/memory-search.test.mjs",
46
47
  "test:library": "npm run build && node scripts/library-commands.test.mjs",
47
48
  "test:chrome-capture": "npm run build && node scripts/chrome-capture.test.mjs",
48
49
  "test:session": "npm run build && node scripts/auth-guard.test.mjs && node scripts/session-control.test.mjs && node scripts/cdp-diagnostics.test.mjs && node scripts/linux-screen.test.mjs",
49
- "test": "npm run test:auth && npm run test:session && node scripts/setup.test.mjs && node scripts/chrome-for-clipy.test.mjs && node scripts/extension-abort.test.mjs && node scripts/capture-title.test.mjs && node scripts/cdp-client.test.mjs && node scripts/transcript-replace.test.mjs && node scripts/library-commands.test.mjs && node scripts/proof-frames.test.mjs && node scripts/memory-search.test.mjs && node scripts/agent-readiness.test.mjs && node scripts/context-sync.test.mjs && node scripts/context-frames.test.mjs && node scripts/context-youtube-transcript.test.mjs && node scripts/context-youtube-url-lang.test.mjs && node scripts/context-loom-url.test.mjs && node scripts/context-loom-import.test.mjs && node scripts/context-retry.test.mjs && node scripts/context-json-envelope.test.mjs && node scripts/context-ytdlp-update.test.mjs",
50
+ "test": "npm run test:auth && npm run test:session && node scripts/setup.test.mjs && node scripts/chrome-for-clipy.test.mjs && node scripts/extension-abort.test.mjs && node scripts/capture-title.test.mjs && node scripts/cdp-client.test.mjs && node scripts/transcript-replace.test.mjs && node scripts/library-commands.test.mjs && node scripts/proof-frames.test.mjs && node scripts/recheck.test.mjs && node scripts/memory-search.test.mjs && node scripts/agent-readiness.test.mjs && node scripts/context-sync.test.mjs && node scripts/context-frames.test.mjs && node scripts/context-youtube-transcript.test.mjs && node scripts/context-youtube-url-lang.test.mjs && node scripts/context-loom-url.test.mjs && node scripts/context-loom-import.test.mjs && node scripts/context-retry.test.mjs && node scripts/context-json-envelope.test.mjs && node scripts/context-ytdlp-update.test.mjs",
50
51
  "prebuild": "node scripts/sync-context-core.mjs",
51
52
  "test:context": "npm run build && node scripts/agent-readiness.test.mjs && node scripts/context-sync.test.mjs && node scripts/context-frames.test.mjs && node scripts/context-youtube-transcript.test.mjs && node scripts/context-youtube-url-lang.test.mjs && node scripts/context-loom-url.test.mjs && node scripts/context-loom-import.test.mjs && node scripts/context-retry.test.mjs && node scripts/context-json-envelope.test.mjs && node scripts/context-ytdlp-update.test.mjs"
52
53
  },