@clipy/cli 0.3.0 → 0.3.1
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/index.js +168 -6
- package/dist/macBridge.js +121 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ import { Readable, Transform } from "node:stream";
|
|
|
22
22
|
import { pipeline } from "node:stream/promises";
|
|
23
23
|
import { createRequire } from "node:module";
|
|
24
24
|
import { CLIPY_SKILL_MD } from "./skill.js";
|
|
25
|
+
import { BridgeUnavailableError, bridgeRequest, readBridgeInfo, } from "./macBridge.js";
|
|
25
26
|
// Exit quietly when stdout/stderr close early (e.g. `clipy list | head`).
|
|
26
27
|
for (const stream of [process.stdout, process.stderr]) {
|
|
27
28
|
stream.on("error", (e) => {
|
|
@@ -295,6 +296,8 @@ ${c.bold("RECORD")} ${c.dim("(needs an API key with the \"ingest\" permission)")
|
|
|
295
296
|
--wait Block until the transcript is ready before printing
|
|
296
297
|
|
|
297
298
|
${c.bold("SESSION")} ${c.dim("(agent works, Clipy records — one active session per directory)")}
|
|
299
|
+
${c.dim("--source mac-screen on record/session records the REAL screen via the")}
|
|
300
|
+
${c.dim("running Clipy Mac app (consent-gated, indicator always visible).")}
|
|
298
301
|
session start --url <app> [--max <sec>] [--title <t>]
|
|
299
302
|
Start recording in a background daemon and
|
|
300
303
|
return immediately (auto-stops + uploads at
|
|
@@ -1107,7 +1110,88 @@ function cleanupSessionFiles(state, file) {
|
|
|
1107
1110
|
}
|
|
1108
1111
|
}
|
|
1109
1112
|
}
|
|
1113
|
+
// --- Mac bridge flows (--source mac-screen): the desktop app records -------
|
|
1114
|
+
/** One-shot real-screen recording through the running Clipy app. */
|
|
1115
|
+
async function cmdRecordMac(opts) {
|
|
1116
|
+
const info = readBridgeInfo();
|
|
1117
|
+
const log = (m) => {
|
|
1118
|
+
if (!opts.json)
|
|
1119
|
+
process.stderr.write(`${m}\n`);
|
|
1120
|
+
};
|
|
1121
|
+
log(`${c.dim(`asking the Clipy app (v${info.appVersion}) to record the screen…`)}`);
|
|
1122
|
+
await bridgeRequest(info, "start", {
|
|
1123
|
+
// The recording is stopped by us after forSec; maxSec is the safety net
|
|
1124
|
+
// in case this CLI process dies mid-wait.
|
|
1125
|
+
maxSec: Math.min(opts.forSec + 60, 1800),
|
|
1126
|
+
title: opts.name,
|
|
1127
|
+
description: opts.description,
|
|
1128
|
+
notes: opts.notes.map((n) => ({ startMs: n.startMs, text: n.text })),
|
|
1129
|
+
});
|
|
1130
|
+
log(`${c.dim(`recording for ${opts.forSec}s…`)}`);
|
|
1131
|
+
await new Promise((r) => setTimeout(r, opts.forSec * 1000));
|
|
1132
|
+
log(`${c.dim("stopping + uploading…")}`);
|
|
1133
|
+
const result = await bridgeRequest(info, "stop");
|
|
1134
|
+
return {
|
|
1135
|
+
publicId: String(result.publicId ?? ""),
|
|
1136
|
+
shareUrl: String(result.shareUrl ?? ""),
|
|
1137
|
+
};
|
|
1138
|
+
}
|
|
1139
|
+
function macSessionState(info, maxSec) {
|
|
1140
|
+
const dir = sessionDir();
|
|
1141
|
+
return {
|
|
1142
|
+
version: 1,
|
|
1143
|
+
kind: "mac",
|
|
1144
|
+
bridge: { socketPath: info.socketPath, token: info.token, pid: info.pid },
|
|
1145
|
+
pid: info.pid,
|
|
1146
|
+
cwd: process.cwd(),
|
|
1147
|
+
url: "mac-screen",
|
|
1148
|
+
maxSec,
|
|
1149
|
+
width: 0,
|
|
1150
|
+
height: 0,
|
|
1151
|
+
state: "recording",
|
|
1152
|
+
recordStartEpochMs: Date.now(),
|
|
1153
|
+
marksPath: join(dir, "unused"),
|
|
1154
|
+
controlPath: join(dir, "unused"),
|
|
1155
|
+
logPath: join(dir, "unused"),
|
|
1156
|
+
tmpDir: join(dir, "unused"),
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
function bridgeInfoFromSession(state) {
|
|
1160
|
+
if (!state.bridge) {
|
|
1161
|
+
die("session file is missing bridge info — abort it with `clipy session abort` and restart");
|
|
1162
|
+
}
|
|
1163
|
+
return {
|
|
1164
|
+
socketPath: state.bridge.socketPath,
|
|
1165
|
+
token: state.bridge.token,
|
|
1166
|
+
pid: state.bridge.pid,
|
|
1167
|
+
appVersion: "",
|
|
1168
|
+
protocolVersion: 1,
|
|
1169
|
+
};
|
|
1170
|
+
}
|
|
1110
1171
|
async function cmdSessionStart(ctx, opts) {
|
|
1172
|
+
if (opts.source === "mac-screen") {
|
|
1173
|
+
const file = sessionFilePath(process.cwd());
|
|
1174
|
+
const existing = readSessionState(file);
|
|
1175
|
+
if (existing && existing.kind !== "mac" && sessionIsActive(existing)) {
|
|
1176
|
+
die("a web recording session is already active here — finish or abort it first");
|
|
1177
|
+
}
|
|
1178
|
+
const info = readBridgeInfo();
|
|
1179
|
+
const maxSec = Math.min(Math.max(1, opts.maxSec), SESSION_HARD_CAP_SEC);
|
|
1180
|
+
await bridgeRequest(info, "start", {
|
|
1181
|
+
maxSec,
|
|
1182
|
+
title: opts.name,
|
|
1183
|
+
description: opts.description,
|
|
1184
|
+
});
|
|
1185
|
+
writeSessionState(file, macSessionState(info, maxSec));
|
|
1186
|
+
if (opts.json) {
|
|
1187
|
+
printJson({ state: "recording", source: "mac-screen", maxSec });
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
process.stdout.write(`${c.green("✓")} the Clipy app is recording your screen (max ${maxSec}s)\n`);
|
|
1191
|
+
process.stdout.write(`${c.dim("while it runs:")} clipy mark "what just happened"\n` +
|
|
1192
|
+
`${c.dim("when finished:")} clipy session stop ${c.dim("· discard:")} clipy session abort\n`);
|
|
1193
|
+
return;
|
|
1194
|
+
}
|
|
1111
1195
|
let target;
|
|
1112
1196
|
try {
|
|
1113
1197
|
target = new URL(opts.url);
|
|
@@ -1196,8 +1280,23 @@ function requireSession() {
|
|
|
1196
1280
|
}
|
|
1197
1281
|
return { file, state };
|
|
1198
1282
|
}
|
|
1199
|
-
function cmdMark(text, json) {
|
|
1283
|
+
async function cmdMark(text, json) {
|
|
1200
1284
|
const { file, state } = requireSession();
|
|
1285
|
+
if (state.kind === "mac") {
|
|
1286
|
+
const result = await bridgeRequest(bridgeInfoFromSession(state), "mark", { text }).catch((e) => {
|
|
1287
|
+
if (e instanceof BridgeUnavailableError) {
|
|
1288
|
+
cleanupSessionFiles(state, file);
|
|
1289
|
+
die("the Clipy app is no longer running — session cleared. Start a new one.");
|
|
1290
|
+
}
|
|
1291
|
+
die(e.message);
|
|
1292
|
+
});
|
|
1293
|
+
if (json) {
|
|
1294
|
+
printJson(result);
|
|
1295
|
+
return;
|
|
1296
|
+
}
|
|
1297
|
+
process.stdout.write(`${c.green("✓")} mark @ ${Number(result.atSeconds ?? 0).toFixed(1)}s — ${text.trim()}\n`);
|
|
1298
|
+
return;
|
|
1299
|
+
}
|
|
1201
1300
|
if (!pidAlive(state.pid)) {
|
|
1202
1301
|
cleanupSessionFiles(state, file);
|
|
1203
1302
|
die("the session daemon is no longer running (crashed?) — session cleared. Start a new one.");
|
|
@@ -1216,6 +1315,23 @@ function cmdMark(text, json) {
|
|
|
1216
1315
|
}
|
|
1217
1316
|
async function cmdSessionStop(json) {
|
|
1218
1317
|
const { file, state } = requireSession();
|
|
1318
|
+
if (state.kind === "mac") {
|
|
1319
|
+
if (!json)
|
|
1320
|
+
process.stderr.write(`${c.dim("stopping + uploading…")}\n`);
|
|
1321
|
+
const result = await bridgeRequest(bridgeInfoFromSession(state), "stop").catch((e) => {
|
|
1322
|
+
cleanupSessionFiles(state, file);
|
|
1323
|
+
die(e.message);
|
|
1324
|
+
});
|
|
1325
|
+
cleanupSessionFiles(state, file);
|
|
1326
|
+
const publicId = String(result.publicId ?? "");
|
|
1327
|
+
reportSessionResult({
|
|
1328
|
+
publicId,
|
|
1329
|
+
shareUrl: String(result.shareUrl ?? ""),
|
|
1330
|
+
contextUrl: `https://clipy.online/api/agent-context/${publicId}`,
|
|
1331
|
+
sizeBytes: 0,
|
|
1332
|
+
}, json);
|
|
1333
|
+
return;
|
|
1334
|
+
}
|
|
1219
1335
|
if (!pidAlive(state.pid)) {
|
|
1220
1336
|
// Daemon already gone: it may have finished (auto-stop at max duration)
|
|
1221
1337
|
// or crashed. Report whatever terminal state it left behind.
|
|
@@ -1276,6 +1392,15 @@ function reportSessionResult(result, json) {
|
|
|
1276
1392
|
}
|
|
1277
1393
|
async function cmdSessionAbort(json) {
|
|
1278
1394
|
const { file, state } = requireSession();
|
|
1395
|
+
if (state.kind === "mac") {
|
|
1396
|
+
await bridgeRequest(bridgeInfoFromSession(state), "abort").catch(() => { });
|
|
1397
|
+
cleanupSessionFiles(state, file);
|
|
1398
|
+
if (json)
|
|
1399
|
+
printJson({ state: "aborted" });
|
|
1400
|
+
else
|
|
1401
|
+
process.stdout.write(`${c.green("✓")} session aborted — nothing was uploaded\n`);
|
|
1402
|
+
return;
|
|
1403
|
+
}
|
|
1279
1404
|
if (!pidAlive(state.pid)) {
|
|
1280
1405
|
cleanupSessionFiles(state, file);
|
|
1281
1406
|
if (!json)
|
|
@@ -1715,6 +1840,7 @@ async function main() {
|
|
|
1715
1840
|
viewports: { type: "string" },
|
|
1716
1841
|
max: { type: "string" },
|
|
1717
1842
|
replace: { type: "string" },
|
|
1843
|
+
source: { type: "string" },
|
|
1718
1844
|
width: { type: "string" },
|
|
1719
1845
|
height: { type: "string" },
|
|
1720
1846
|
wait: { type: "boolean", default: false },
|
|
@@ -1833,9 +1959,40 @@ async function main() {
|
|
|
1833
1959
|
cmdGuide(json);
|
|
1834
1960
|
return;
|
|
1835
1961
|
case "record": {
|
|
1962
|
+
const source = String(values.source ?? "web");
|
|
1963
|
+
if (source !== "web" && source !== "mac-screen") {
|
|
1964
|
+
die("--source must be web (headless browser) or mac-screen (the Clipy Mac app)", 2);
|
|
1965
|
+
}
|
|
1966
|
+
if (source === "mac-screen") {
|
|
1967
|
+
const noteFlags = values.note ?? [];
|
|
1968
|
+
try {
|
|
1969
|
+
const result = await cmdRecordMac({
|
|
1970
|
+
forSec: num(values.for, 15),
|
|
1971
|
+
name: (values.title ?? values.name)?.trim() ||
|
|
1972
|
+
undefined,
|
|
1973
|
+
description: values.description?.trim() || undefined,
|
|
1974
|
+
notes: noteFlags.map(parseNoteFlag),
|
|
1975
|
+
json,
|
|
1976
|
+
});
|
|
1977
|
+
if (values.wait && result.publicId) {
|
|
1978
|
+
await waitForArtifacts(ctx, result.publicId).catch(() => { });
|
|
1979
|
+
}
|
|
1980
|
+
if (json) {
|
|
1981
|
+
printJson({ id: result.publicId, shareUrl: result.shareUrl });
|
|
1982
|
+
}
|
|
1983
|
+
else {
|
|
1984
|
+
process.stdout.write(`${c.green("✓")} recorded — ${c.bold(result.shareUrl)}\n`);
|
|
1985
|
+
process.stdout.write(`${c.dim("next:")} clipy context ${result.publicId} · clipy wait ${result.publicId}\n`);
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
catch (e) {
|
|
1989
|
+
die(e.message);
|
|
1990
|
+
}
|
|
1991
|
+
return;
|
|
1992
|
+
}
|
|
1836
1993
|
const url = values.url?.trim() || rest[0];
|
|
1837
1994
|
if (!url) {
|
|
1838
|
-
die("usage: clipy record --url <http(s) url> [--for <sec>] [--name <title>] [--viewports <list>] [--wait]", 2);
|
|
1995
|
+
die("usage: clipy record --url <http(s) url> [--for <sec>] [--name <title>] [--viewports <list>] [--source web|mac-screen] [--wait]", 2);
|
|
1839
1996
|
}
|
|
1840
1997
|
const noteFlags = values.note ?? [];
|
|
1841
1998
|
await cmdRecord(ctx, {
|
|
@@ -1856,12 +2013,16 @@ async function main() {
|
|
|
1856
2013
|
case "session": {
|
|
1857
2014
|
const sub = rest[0];
|
|
1858
2015
|
if (sub === "start") {
|
|
2016
|
+
const source = String(values.source ?? "web");
|
|
2017
|
+
if (source !== "web" && source !== "mac-screen") {
|
|
2018
|
+
die("--source must be web (headless browser) or mac-screen (the Clipy Mac app)", 2);
|
|
2019
|
+
}
|
|
1859
2020
|
const url = values.url?.trim() || rest[1];
|
|
1860
|
-
if (!url) {
|
|
1861
|
-
die("usage: clipy session start --url <http(s) url> [--max <sec>] [--
|
|
2021
|
+
if (!url && source === "web") {
|
|
2022
|
+
die("usage: clipy session start --url <http(s) url> [--max <sec>] [--source web|mac-screen]", 2);
|
|
1862
2023
|
}
|
|
1863
2024
|
await cmdSessionStart(ctx, {
|
|
1864
|
-
url,
|
|
2025
|
+
url: url || "mac-screen",
|
|
1865
2026
|
name: (values.title ?? values.name)?.trim() ||
|
|
1866
2027
|
undefined,
|
|
1867
2028
|
description: values.description?.trim() || undefined,
|
|
@@ -1869,6 +2030,7 @@ async function main() {
|
|
|
1869
2030
|
width: num(values.width, 1280),
|
|
1870
2031
|
height: num(values.height, 720),
|
|
1871
2032
|
json,
|
|
2033
|
+
source,
|
|
1872
2034
|
});
|
|
1873
2035
|
return;
|
|
1874
2036
|
}
|
|
@@ -1891,7 +2053,7 @@ async function main() {
|
|
|
1891
2053
|
const text = rest.join(" ").trim();
|
|
1892
2054
|
if (!text)
|
|
1893
2055
|
die('usage: clipy mark "<what just happened>"', 2);
|
|
1894
|
-
cmdMark(text, json);
|
|
2056
|
+
await cmdMark(text, json);
|
|
1895
2057
|
return;
|
|
1896
2058
|
}
|
|
1897
2059
|
case "__session-daemon": {
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mac bridge client — drives real screen recordings through the running
|
|
3
|
+
* Clipy desktop app over its Unix-socket agent bridge (agent_bridge.rs).
|
|
4
|
+
*
|
|
5
|
+
* Discovery: ~/Library/Application Support/Clipy/agent-bridge.json, written
|
|
6
|
+
* by the app on launch: {socketPath, token, pid, appVersion, protocolVersion}.
|
|
7
|
+
* The file and socket are 0600, and every request carries the per-launch
|
|
8
|
+
* token. Protocol: one JSON request line per connection, one JSON response
|
|
9
|
+
* line back.
|
|
10
|
+
*/
|
|
11
|
+
import { readFileSync } from "node:fs";
|
|
12
|
+
import { homedir } from "node:os";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { createConnection } from "node:net";
|
|
15
|
+
export class BridgeUnavailableError extends Error {
|
|
16
|
+
}
|
|
17
|
+
const REQUEST_TIMEOUT_MS = 15_000;
|
|
18
|
+
/** stop waits for the streaming upload to hand back the share link. */
|
|
19
|
+
const STOP_TIMEOUT_MS = 200_000;
|
|
20
|
+
export function bridgeFilePath() {
|
|
21
|
+
if (process.env.CLIPY_BRIDGE_FILE?.trim())
|
|
22
|
+
return process.env.CLIPY_BRIDGE_FILE;
|
|
23
|
+
return join(homedir(), "Library", "Application Support", "Clipy", "agent-bridge.json");
|
|
24
|
+
}
|
|
25
|
+
function pidAlive(pid) {
|
|
26
|
+
try {
|
|
27
|
+
process.kill(pid, 0);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Reads + validates the discovery file; throws BridgeUnavailableError with a
|
|
35
|
+
* friendly one-liner when the app isn't installed or running. */
|
|
36
|
+
export function readBridgeInfo() {
|
|
37
|
+
if (process.platform !== "darwin" && !process.env.CLIPY_BRIDGE_FILE) {
|
|
38
|
+
throw new BridgeUnavailableError("--source mac-screen records through the Clipy Mac app, which only runs on macOS.");
|
|
39
|
+
}
|
|
40
|
+
let raw;
|
|
41
|
+
try {
|
|
42
|
+
raw = readFileSync(bridgeFilePath(), "utf8");
|
|
43
|
+
}
|
|
44
|
+
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");
|
|
46
|
+
}
|
|
47
|
+
let info;
|
|
48
|
+
try {
|
|
49
|
+
info = JSON.parse(raw);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
throw new BridgeUnavailableError("agent bridge file is corrupt — restart the Clipy app");
|
|
53
|
+
}
|
|
54
|
+
if (!info.socketPath || !info.token || typeof info.pid !== "number") {
|
|
55
|
+
throw new BridgeUnavailableError("agent bridge file is incomplete — restart the Clipy app");
|
|
56
|
+
}
|
|
57
|
+
if (!pidAlive(info.pid)) {
|
|
58
|
+
throw new BridgeUnavailableError("the Clipy app is not running (stale agent bridge). Open Clipy and try again.");
|
|
59
|
+
}
|
|
60
|
+
return info;
|
|
61
|
+
}
|
|
62
|
+
/** One request line in, one response line out. */
|
|
63
|
+
export function bridgeRequest(info, cmd, args = {}) {
|
|
64
|
+
const timeoutMs = cmd === "stop" ? STOP_TIMEOUT_MS : REQUEST_TIMEOUT_MS;
|
|
65
|
+
return new Promise((resolvePromise, reject) => {
|
|
66
|
+
const socket = createConnection({ path: info.socketPath });
|
|
67
|
+
let buffer = "";
|
|
68
|
+
let settled = false;
|
|
69
|
+
const timer = setTimeout(() => {
|
|
70
|
+
if (!settled) {
|
|
71
|
+
settled = true;
|
|
72
|
+
socket.destroy();
|
|
73
|
+
reject(new Error(cmd === "stop"
|
|
74
|
+
? "the Clipy app did not finish the upload in time — check the app; the recording may still complete in the background"
|
|
75
|
+
: `the Clipy app did not answer (${cmd}) — is it responding?`));
|
|
76
|
+
}
|
|
77
|
+
}, timeoutMs);
|
|
78
|
+
socket.on("error", (e) => {
|
|
79
|
+
if (settled)
|
|
80
|
+
return;
|
|
81
|
+
settled = true;
|
|
82
|
+
clearTimeout(timer);
|
|
83
|
+
reject(e.code === "ENOENT" || e.code === "ECONNREFUSED"
|
|
84
|
+
? new BridgeUnavailableError("the Clipy app is not running (agent bridge socket unavailable). Open Clipy and try again.")
|
|
85
|
+
: e);
|
|
86
|
+
});
|
|
87
|
+
socket.on("connect", () => {
|
|
88
|
+
socket.write(`${JSON.stringify({ token: info.token, cmd, ...args })}\n`);
|
|
89
|
+
});
|
|
90
|
+
socket.on("data", (chunk) => {
|
|
91
|
+
buffer += chunk.toString("utf8");
|
|
92
|
+
const newline = buffer.indexOf("\n");
|
|
93
|
+
if (newline === -1)
|
|
94
|
+
return;
|
|
95
|
+
if (settled)
|
|
96
|
+
return;
|
|
97
|
+
settled = true;
|
|
98
|
+
clearTimeout(timer);
|
|
99
|
+
socket.end();
|
|
100
|
+
try {
|
|
101
|
+
const parsed = JSON.parse(buffer.slice(0, newline));
|
|
102
|
+
if (parsed.ok) {
|
|
103
|
+
resolvePromise(parsed.data ?? {});
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
reject(new Error(parsed.error?.message ?? "bridge error"));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
reject(new Error("unparseable response from the Clipy app bridge"));
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
socket.on("close", () => {
|
|
114
|
+
if (!settled) {
|
|
115
|
+
settled = true;
|
|
116
|
+
clearTimeout(timer);
|
|
117
|
+
reject(new Error("the Clipy app closed the bridge connection unexpectedly"));
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clipy/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
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",
|