@clipy/cli 0.13.1 → 0.14.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,43 @@
1
+ function retryDelayMs(response) {
2
+ const seconds = Number(response.headers.get('retry-after'));
3
+ return Number.isFinite(seconds) && seconds > 0 ? seconds * 1_000 : 3_000;
4
+ }
5
+ async function fetchBeforeDeadline(fetchContext, remainingMs) {
6
+ if (remainingMs <= 0)
7
+ return null;
8
+ const controller = new AbortController();
9
+ const timer = setTimeout(() => controller.abort(), remainingMs);
10
+ try {
11
+ return await fetchContext(controller.signal);
12
+ }
13
+ catch (error) {
14
+ if (controller.signal.aborted)
15
+ return null;
16
+ throw error;
17
+ }
18
+ finally {
19
+ clearTimeout(timer);
20
+ }
21
+ }
22
+ export async function waitForAgentContext(fetchContext, options) {
23
+ const startedAt = options.now();
24
+ const initial = await fetchBeforeDeadline(fetchContext, options.timeoutMs);
25
+ if (!initial)
26
+ throw new Error('Agent context request exceeded the wait timeout');
27
+ let response = initial;
28
+ while (response.headers.get('x-clipy-agent-readiness') === 'preparing') {
29
+ const remainingMs = options.timeoutMs - (options.now() - startedAt);
30
+ if (remainingMs <= 0)
31
+ return { response, timedOut: true };
32
+ await options.sleep(Math.min(retryDelayMs(response), remainingMs));
33
+ if (options.now() - startedAt >= options.timeoutMs) {
34
+ return { response, timedOut: true };
35
+ }
36
+ const next = await fetchBeforeDeadline(fetchContext, options.timeoutMs - (options.now() - startedAt));
37
+ if (!next)
38
+ return { response, timedOut: true };
39
+ await response.body?.cancel().catch(() => { });
40
+ response = next;
41
+ }
42
+ return { response, timedOut: false };
43
+ }
package/dist/index.js CHANGED
@@ -34,6 +34,7 @@ import { cmdContextRead } from "./context/readCmd.js";
34
34
  import { errorEnvelope } from "./context/errors.js";
35
35
  import { supportsWebp } from "./context/ffmpeg.js";
36
36
  import { renderProofFrames } from "./proofFrames.js";
37
+ import { waitForAgentContext } from "./agentReadiness.js";
37
38
  import { BridgeUnavailableError, bridgeRequest, inspectBridge, listSources, readBridgeInfo, resolveCaptureSource, windowLabel, probeSocketOpenable, probeBridgeHandshake, bridgeInfoFromFile, bridgeAppOutdated, MIN_BRIDGE_APP_VERSION, describeWindow, describeDisplay, } from "./macBridge.js";
38
39
  // Exit quietly when stdout/stderr close early (e.g. `clipy list | head`).
39
40
  for (const stream of [process.stdout, process.stderr]) {
@@ -151,12 +152,17 @@ function requireKey(ctx) {
151
152
  return ctx.apiKey;
152
153
  die(`no API key. Run ${c.bold("clipy login")} to approve this device in your browser, or set CLIPY_API_KEY.`);
153
154
  }
154
- async function api(ctx, path, accept = "application/json") {
155
+ async function api(ctx, path, accept = "application/json", deadlineSignal) {
155
156
  const key = requireKey(ctx);
156
157
  const controller = new AbortController();
158
+ const abortForDeadline = () => controller.abort();
159
+ if (deadlineSignal?.aborted)
160
+ controller.abort();
161
+ else
162
+ deadlineSignal?.addEventListener("abort", abortForDeadline, { once: true });
157
163
  const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
158
164
  try {
159
- return await fetch(`${ctx.apiUrl}${path}`, {
165
+ const response = await fetch(`${ctx.apiUrl}${path}`, {
160
166
  headers: {
161
167
  Authorization: `Bearer ${key}`,
162
168
  Accept: accept,
@@ -164,15 +170,24 @@ async function api(ctx, path, accept = "application/json") {
164
170
  },
165
171
  signal: controller.signal,
166
172
  });
173
+ const body = await response.arrayBuffer();
174
+ return new Response(body.byteLength > 0 ? body : null, {
175
+ status: response.status,
176
+ statusText: response.statusText,
177
+ headers: response.headers,
178
+ });
167
179
  }
168
180
  catch (e) {
169
181
  if (e.name === "AbortError") {
182
+ if (deadlineSignal?.aborted)
183
+ throw e;
170
184
  die(`request timed out after ${FETCH_TIMEOUT_MS / 1000}s (${path})`);
171
185
  }
172
186
  throw e;
173
187
  }
174
188
  finally {
175
189
  clearTimeout(timer);
190
+ deadlineSignal?.removeEventListener("abort", abortForDeadline);
176
191
  }
177
192
  }
178
193
  async function apiJson(ctx, path) {
@@ -808,7 +823,15 @@ async function cmdMoments(ctx, id, json) {
808
823
  async function cmdContext(ctx, id) {
809
824
  const publicId = normalizeId(id, ctx);
810
825
  const pid = encodeURIComponent(publicId);
811
- const res = await api(ctx, `/api/agent-context/${pid}`, "text/markdown, text/plain, application/json");
826
+ const waited = await waitForAgentContext((signal) => api(ctx, `/api/agent-context/${pid}`, "text/markdown, text/plain, application/json", signal), {
827
+ timeoutMs: 60_000,
828
+ now: Date.now,
829
+ sleep: (milliseconds) => new Promise((resolve) => setTimeout(resolve, milliseconds)),
830
+ });
831
+ const res = waited.response;
832
+ if (waited.timedOut) {
833
+ process.stderr.write(`${c.yellow("!")} recording is still preparing; returning the latest available context\n`);
834
+ }
812
835
  const text = await res.text();
813
836
  if (!res.ok) {
814
837
  let msg = `Clipy API error ${res.status}`;
@@ -1485,8 +1508,11 @@ async function ingestPostChunk(ctx, recordingId, uploadToken, partNumber, bytes,
1485
1508
  for (let attempt = 1; attempt <= 4; attempt++) {
1486
1509
  // Copy the window into a standalone ArrayBuffer: it satisfies BlobPart
1487
1510
  // under strict lib settings (a subarray's .buffer is ArrayBufferLike) and
1488
- // makes the snapshot independent of the reused read buffer.
1489
- const part = bytes.slice().buffer;
1511
+ // makes the snapshot independent of the reused read buffer. Not
1512
+ // bytes.slice(): on a Node Buffer that is a view, so its .buffer is the
1513
+ // whole 4 MiB read buffer, and every part would carry stale bytes and
1514
+ // uninitialized memory past bytes.length.
1515
+ const part = new Uint8Array(bytes).buffer;
1490
1516
  const form = new FormData();
1491
1517
  form.append("recordingId", recordingId);
1492
1518
  form.append("uploadToken", uploadToken);
package/dist/skill.js CHANGED
@@ -15,12 +15,13 @@ description: Read and create Clipy screen recordings, turn screenshots or tool-n
15
15
 
16
16
  # Clipy — recordings you can read AND make
17
17
 
18
- Written for @clipy/cli + @clipy/mcp 0.13.1 (the two versions move in lockstep). If
18
+ Written for @clipy/cli + @clipy/mcp 0.14.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
22
- recording has a share link, an AI transcript + summary, key moments, and a
23
- machine-readable context document. With the CLI you can also CREATE proof:
22
+ recording has a share link, an AI transcript + summary, a normalized interaction
23
+ timeline, key moments, and a machine-readable context document. With the CLI you
24
+ can also CREATE proof:
24
25
  combine screenshots from whatever tool you already use, upload a tool-native
25
26
  WebM/MP4, capture a running web app headlessly, or capture the real Mac screen
26
27
  through the running Clipy app, then hand back a watchable link.
@@ -59,6 +60,16 @@ try to watch the video or scrape the watch page: fetch the twin
59
60
  5. For bug reports / feedback: enumerate the extracted issues as a numbered list
60
61
  (with timestamps) before implementing anything.
61
62
 
63
+ The interaction timeline distinguishes captured facts from derived gestures.
64
+ Pointer dwell is not evidence of attention or intent. Coordinates belong to the
65
+ capture viewport and may not align with cropped, zoomed, or composed playback
66
+ frames. Typed values and exact key counts are excluded. A missing source is a
67
+ capture gap, and \`preparing\` means evidence is pending, not that no action happened.
68
+ Public documents contain compact non-pointer events. Owners can use MCP
69
+ \`get_interactions\` for detailed evidence with \`fromMs\`, \`toMs\`, \`types\`, and
70
+ \`limit\` (1–250, default 100); follow \`pagination.nextCursor\` as \`cursor\` with
71
+ unchanged filters. Event kind \`dwell\` means stationary pointer activity.
72
+
62
73
  ## Search everything the user remembers
63
74
 
64
75
  When the user refers to something they recorded, watched, imported, showed, or
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@clipy/cli",
3
- "version": "0.13.1",
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.14.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": {
@@ -43,9 +43,9 @@
43
43
  "test:setup": "npm run build && node scripts/setup.test.mjs",
44
44
  "test:memory": "npm run build && node scripts/memory-search.test.mjs",
45
45
  "test:session": "npm run build && node scripts/auth-guard.test.mjs && node scripts/session-control.test.mjs",
46
- "test": "npm run test:auth && npm run test:session && node scripts/setup.test.mjs && node scripts/transcript-replace.test.mjs && node scripts/proof-frames.test.mjs && node scripts/memory-search.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",
46
+ "test": "npm run test:auth && npm run test:session && node scripts/setup.test.mjs && node scripts/transcript-replace.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",
47
47
  "prebuild": "node scripts/sync-context-core.mjs",
48
- "test:context": "npm run build && 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"
48
+ "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"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/node": "^22.0.0",