@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/README.md +44 -5
- package/dist/index.js +697 -28
- package/dist/macBridge.js +187 -7
- package/dist/skill.js +27 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -22,9 +22,11 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
22
22
|
import { Readable, Transform } from "node:stream";
|
|
23
23
|
import { pipeline } from "node:stream/promises";
|
|
24
24
|
import { createRequire } from "node:module";
|
|
25
|
+
import { pathToFileURL } from "node:url";
|
|
26
|
+
import { createServer } from "node:net";
|
|
25
27
|
import { CLIPY_SKILL_MD } from "./skill.js";
|
|
26
28
|
import { browserLogin, shouldUseManualLogin } from "./browserLogin.js";
|
|
27
|
-
import { BridgeUnavailableError, bridgeRequest, listSources, readBridgeInfo, resolveCaptureSource, windowLabel, } from "./macBridge.js";
|
|
29
|
+
import { BridgeUnavailableError, bridgeRequest, inspectBridge, listSources, readBridgeInfo, resolveCaptureSource, windowLabel, probeSocketOpenable, probeBridgeHandshake, bridgeInfoFromFile, bridgeAppOutdated, MIN_BRIDGE_APP_VERSION, } from "./macBridge.js";
|
|
28
30
|
// Exit quietly when stdout/stderr close early (e.g. `clipy list | head`).
|
|
29
31
|
for (const stream of [process.stdout, process.stderr]) {
|
|
30
32
|
stream.on("error", (e) => {
|
|
@@ -295,8 +297,13 @@ ${c.bold("RECORD")} ${c.dim("(needs an API key with the \"ingest\" permission)")
|
|
|
295
297
|
--viewports <l> Record several sizes into ONE video, e.g.
|
|
296
298
|
mobile,tablet,desktop or 390x844,1440x900 (chapters marked)
|
|
297
299
|
--title/--description Recording metadata
|
|
298
|
-
--
|
|
299
|
-
|
|
300
|
+
--type <kind> What this recording IS, so the AI summary reads it right:
|
|
301
|
+
bug|feature|demo|walkthrough|feedback|discussion|other
|
|
302
|
+
(aliases of bug_report/feature_request/product_demo/…)
|
|
303
|
+
--note "12: text" Timestamped narration note (repeatable). "12: text" is
|
|
304
|
+
absolute; "pass2: text" / "pass2@5: text" anchor to the
|
|
305
|
+
actual start of a --viewports pass. Silent captures → the
|
|
306
|
+
notes become the transcript
|
|
300
307
|
--width/--height Viewport + video size (default 1280×720)
|
|
301
308
|
--wait Block until the transcript is ready before printing
|
|
302
309
|
|
|
@@ -307,10 +314,14 @@ ${c.bold("SESSION")} ${c.dim("(agent works, Clipy records — one active session
|
|
|
307
314
|
sources List capturable displays + windows (ids for --window/--display)
|
|
308
315
|
--window "<title|app|id>" Record just that window (e.g. --window Chrome)
|
|
309
316
|
--display <id> Record a specific display
|
|
310
|
-
session start --url <app> [--max <sec>] [--title <t>]
|
|
317
|
+
session start --url <app> [--max <sec>] [--title <t>] [--type <kind>] [--expose-cdp]
|
|
311
318
|
Start recording in a background daemon and
|
|
312
319
|
return immediately (auto-stops + uploads at
|
|
313
|
-
--max, default ${SESSION_DEFAULT_MAX_SEC}s, cap ${SESSION_HARD_CAP_SEC}s)
|
|
320
|
+
--max, default ${SESSION_DEFAULT_MAX_SEC}s, cap ${SESSION_HARD_CAP_SEC}s). --type sets
|
|
321
|
+
the recording kind (see record). --expose-cdp
|
|
322
|
+
opens a CDP endpoint so your tools can drive the
|
|
323
|
+
page as it records (off by default; any local
|
|
324
|
+
process could attach — CLIPY_DISABLE_CDP=1 forces off)
|
|
314
325
|
mark "<what just happened>" Drop a live timestamped note; marks become
|
|
315
326
|
the recording's transcript chapters
|
|
316
327
|
session stop Finish: close browser, upload, print link
|
|
@@ -322,6 +333,8 @@ ${c.bold("AGENTS")}
|
|
|
322
333
|
Install the bundled Clipy skill for a coding
|
|
323
334
|
agent (teaches it to read + make recordings)
|
|
324
335
|
agents status | uninstall <t> Show / remove installed skills
|
|
336
|
+
doctor [--json] Health check: API key, Mac agent bridge,
|
|
337
|
+
Playwright, and install mode — with fix hints
|
|
325
338
|
guide --json Machine-readable manifest: every command,
|
|
326
339
|
flag, env var, and exit code
|
|
327
340
|
transcript <id> --replace <file> Replace a transcript with agent-authored
|
|
@@ -731,6 +744,284 @@ function cmdMcp() {
|
|
|
731
744
|
child.on("exit", (code) => process.exit(code ?? 0));
|
|
732
745
|
child.on("error", (e) => die(`failed to launch @clipy/mcp via npx: ${e.message}`));
|
|
733
746
|
}
|
|
747
|
+
/** Non-dying key probe for doctor — reuses the whoami round-trip endpoint but
|
|
748
|
+
* returns structured results (die() would exit before other checks run) and
|
|
749
|
+
* distinguishes offline from rejected so we can degrade gracefully. */
|
|
750
|
+
async function probeApiKey(ctx) {
|
|
751
|
+
if (!ctx.apiKey)
|
|
752
|
+
return { ok: false, offline: false, status: 0, message: "no key" };
|
|
753
|
+
const controller = new AbortController();
|
|
754
|
+
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
755
|
+
try {
|
|
756
|
+
const res = await fetch(`${ctx.apiUrl}/api/v1/recordings?limit=1`, {
|
|
757
|
+
headers: {
|
|
758
|
+
Authorization: `Bearer ${ctx.apiKey}`,
|
|
759
|
+
Accept: "application/json",
|
|
760
|
+
"User-Agent": `clipy-cli/${VERSION}`,
|
|
761
|
+
},
|
|
762
|
+
signal: controller.signal,
|
|
763
|
+
});
|
|
764
|
+
if (res.ok)
|
|
765
|
+
return { ok: true, offline: false, status: res.status, message: "ok" };
|
|
766
|
+
let message = `HTTP ${res.status}`;
|
|
767
|
+
try {
|
|
768
|
+
const body = (await res.json());
|
|
769
|
+
if (typeof body.error === "string")
|
|
770
|
+
message = body.error;
|
|
771
|
+
}
|
|
772
|
+
catch {
|
|
773
|
+
// keep the HTTP status message
|
|
774
|
+
}
|
|
775
|
+
return { ok: false, offline: false, status: res.status, message };
|
|
776
|
+
}
|
|
777
|
+
catch (e) {
|
|
778
|
+
const message = e.name === "AbortError" ? "request timed out" : e.message;
|
|
779
|
+
return { ok: false, offline: true, status: 0, message };
|
|
780
|
+
}
|
|
781
|
+
finally {
|
|
782
|
+
clearTimeout(timer);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
async function doctorAuthCheck(ctx) {
|
|
786
|
+
if (!ctx.apiKey) {
|
|
787
|
+
return {
|
|
788
|
+
name: "auth",
|
|
789
|
+
status: "fail",
|
|
790
|
+
detail: "no API key configured",
|
|
791
|
+
hint: "run `clipy login` (or set CLIPY_API_KEY)",
|
|
792
|
+
data: { hasKey: false },
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
const source = process.env.CLIPY_API_KEY === ctx.apiKey
|
|
796
|
+
? "env CLIPY_API_KEY"
|
|
797
|
+
: readConfig().apiKey === ctx.apiKey
|
|
798
|
+
? configPath()
|
|
799
|
+
: "--key flag";
|
|
800
|
+
const masked = `${ctx.apiKey.slice(0, 18)}…`;
|
|
801
|
+
const probe = await probeApiKey(ctx);
|
|
802
|
+
const data = { hasKey: true, keySource: source, apiUrl: ctx.apiUrl };
|
|
803
|
+
if (probe.ok) {
|
|
804
|
+
return { name: "auth", status: "pass", detail: `key ${masked} valid (${source}) against ${ctx.apiUrl}`, data };
|
|
805
|
+
}
|
|
806
|
+
if (probe.offline) {
|
|
807
|
+
return {
|
|
808
|
+
name: "auth",
|
|
809
|
+
status: "warn",
|
|
810
|
+
detail: `key ${masked} present (${source}) but ${ctx.apiUrl} is unreachable: ${probe.message}`,
|
|
811
|
+
hint: "check your connection — the key could not be verified",
|
|
812
|
+
data: { ...data, offline: true },
|
|
813
|
+
};
|
|
814
|
+
}
|
|
815
|
+
const hint = probe.status === 401
|
|
816
|
+
? "the key is invalid or revoked — run `clipy login`"
|
|
817
|
+
: probe.status === 403
|
|
818
|
+
? `the key lacks a required scope — mint one at ${ctx.apiUrl}/settings/api-keys`
|
|
819
|
+
: "check the key and --api-url";
|
|
820
|
+
return {
|
|
821
|
+
name: "auth",
|
|
822
|
+
status: "fail",
|
|
823
|
+
detail: `key ${masked} (${source}) rejected by ${ctx.apiUrl}: ${probe.message}`,
|
|
824
|
+
hint,
|
|
825
|
+
data: { ...data, status: probe.status },
|
|
826
|
+
};
|
|
827
|
+
}
|
|
828
|
+
function fmtAge(ms) {
|
|
829
|
+
const sec = Math.max(0, Math.round(ms / 1000));
|
|
830
|
+
if (sec < 90)
|
|
831
|
+
return `${sec}s`;
|
|
832
|
+
if (sec < 5400)
|
|
833
|
+
return `${Math.round(sec / 60)}m`;
|
|
834
|
+
return `${Math.round(sec / 3600)}h`;
|
|
835
|
+
}
|
|
836
|
+
/** The bridge produces several PASS/FAIL lines: the discovery FILE (validity +
|
|
837
|
+
* version), its MTIME freshness, the SOCKET's openability, and a live
|
|
838
|
+
* HANDSHAKE that confirms the running app answers and its version matches the
|
|
839
|
+
* file (catching the "stale artifact from an app that predates the bridge"
|
|
840
|
+
* case a pid check alone misses). */
|
|
841
|
+
async function doctorBridgeChecks() {
|
|
842
|
+
const b = inspectBridge();
|
|
843
|
+
const fileData = {
|
|
844
|
+
path: b.path,
|
|
845
|
+
exists: b.exists,
|
|
846
|
+
appVersion: b.appVersion,
|
|
847
|
+
pid: b.pid,
|
|
848
|
+
pidAlive: b.pidAlive,
|
|
849
|
+
minAppVersion: MIN_BRIDGE_APP_VERSION,
|
|
850
|
+
mtimeMs: b.mtimeMs,
|
|
851
|
+
};
|
|
852
|
+
if (!b.applicable) {
|
|
853
|
+
return [{ name: "bridge", status: "skip", detail: `n/a — ${b.detail}`, data: fileData }];
|
|
854
|
+
}
|
|
855
|
+
if (!b.exists) {
|
|
856
|
+
return [
|
|
857
|
+
{
|
|
858
|
+
name: "bridge",
|
|
859
|
+
status: "warn",
|
|
860
|
+
detail: `${b.detail} (${b.path})`,
|
|
861
|
+
hint: "only needed for --source mac-screen; open the Clipy app, or install/update it at https://clipy.online/download",
|
|
862
|
+
data: fileData,
|
|
863
|
+
},
|
|
864
|
+
];
|
|
865
|
+
}
|
|
866
|
+
const out = [];
|
|
867
|
+
// 1) discovery file validity + version
|
|
868
|
+
if (b.healthy) {
|
|
869
|
+
out.push({ name: "bridge", status: "pass", detail: `${b.detail} at ${b.path}`, data: fileData });
|
|
870
|
+
}
|
|
871
|
+
else {
|
|
872
|
+
const predate = (b.pidAlive === false && bridgeAppOutdated(b.appVersion)) || b.versionOk === false;
|
|
873
|
+
const hint = predate
|
|
874
|
+
? `your installed Clipy app likely predates the agent bridge (needs v${MIN_BRIDGE_APP_VERSION}+) — update via https://clipy.online/download`
|
|
875
|
+
: b.pidAlive === false
|
|
876
|
+
? "open the Clipy app (its previous process quit)"
|
|
877
|
+
: "restart the Clipy app";
|
|
878
|
+
out.push({ name: "bridge", status: "fail", detail: `${b.detail} (${b.path})`, hint, data: fileData });
|
|
879
|
+
}
|
|
880
|
+
// 2) mtime freshness (the app rewrites the file every launch on 0.1.41+)
|
|
881
|
+
if (b.mtimeMs != null) {
|
|
882
|
+
const age = fmtAge(Date.now() - b.mtimeMs);
|
|
883
|
+
const staleShaped = b.pidAlive === false;
|
|
884
|
+
out.push({
|
|
885
|
+
name: "bridge mtime",
|
|
886
|
+
status: staleShaped ? "warn" : "info",
|
|
887
|
+
detail: staleShaped
|
|
888
|
+
? `discovery file last written ${age} ago but its pid is dead — stale artifact`
|
|
889
|
+
: `discovery file written ${age} ago`,
|
|
890
|
+
...(staleShaped
|
|
891
|
+
? { hint: `a fresh Clipy launch should rewrite it; if it doesn't, the app predates the bridge (needs v${MIN_BRIDGE_APP_VERSION}+)` }
|
|
892
|
+
: {}),
|
|
893
|
+
data: { mtimeMs: b.mtimeMs },
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
// 3) + 4) socket openability + live handshake (only when the file is complete)
|
|
897
|
+
if (b.complete && b.socketPath) {
|
|
898
|
+
const openable = await probeSocketOpenable(b.socketPath);
|
|
899
|
+
out.push({
|
|
900
|
+
name: "bridge socket",
|
|
901
|
+
status: openable ? "pass" : "fail",
|
|
902
|
+
detail: openable ? `socket openable at ${b.socketPath}` : `socket not answering at ${b.socketPath}`,
|
|
903
|
+
...(openable ? {} : { hint: "stale bridge artifact — restart the Clipy app" }),
|
|
904
|
+
data: { socketPath: b.socketPath, openable },
|
|
905
|
+
});
|
|
906
|
+
if (openable) {
|
|
907
|
+
const info = bridgeInfoFromFile();
|
|
908
|
+
if (info) {
|
|
909
|
+
const hs = await probeBridgeHandshake(info);
|
|
910
|
+
if (hs.ok) {
|
|
911
|
+
const match = !hs.appVersion || !b.appVersion || hs.appVersion === b.appVersion;
|
|
912
|
+
out.push({
|
|
913
|
+
name: "bridge handshake",
|
|
914
|
+
status: match ? "pass" : "fail",
|
|
915
|
+
detail: match
|
|
916
|
+
? `app answered "status" (v${hs.appVersion ?? "?"})`
|
|
917
|
+
: `discovery file says v${b.appVersion} but the running app reports v${hs.appVersion} — stale bridge artifact`,
|
|
918
|
+
...(match ? {} : { hint: "restart the Clipy app so it rewrites the discovery file" }),
|
|
919
|
+
data: { fileAppVersion: b.appVersion, liveAppVersion: hs.appVersion ?? null },
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
else {
|
|
923
|
+
out.push({
|
|
924
|
+
name: "bridge handshake",
|
|
925
|
+
status: "fail",
|
|
926
|
+
detail: `no answer to a "status" handshake: ${hs.error}`,
|
|
927
|
+
hint: bridgeAppOutdated(b.appVersion)
|
|
928
|
+
? `your installed Clipy app likely predates the agent bridge (needs v${MIN_BRIDGE_APP_VERSION}+) — update via https://clipy.online/download`
|
|
929
|
+
: "stale bridge artifact — restart the Clipy app",
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
return out;
|
|
936
|
+
}
|
|
937
|
+
async function doctorPlaywrightCheck() {
|
|
938
|
+
const res = await resolvePlaywright();
|
|
939
|
+
if (res.ok) {
|
|
940
|
+
return { name: "playwright", status: "pass", detail: `resolved via ${res.source}`, data: { source: res.source } };
|
|
941
|
+
}
|
|
942
|
+
const { mode } = detectInstallMode();
|
|
943
|
+
return {
|
|
944
|
+
name: "playwright",
|
|
945
|
+
status: "fail",
|
|
946
|
+
detail: `${res.error} — record/session cannot launch a browser`,
|
|
947
|
+
hint: playwrightInstallHint(mode),
|
|
948
|
+
data: { installMode: mode },
|
|
949
|
+
};
|
|
950
|
+
}
|
|
951
|
+
function doctorInstallCheck() {
|
|
952
|
+
const { mode, argv1 } = detectInstallMode();
|
|
953
|
+
const label = {
|
|
954
|
+
npx: "npx cache (isolated)",
|
|
955
|
+
global: "global install",
|
|
956
|
+
local: "project-local install",
|
|
957
|
+
unknown: "unknown (running from source?)",
|
|
958
|
+
};
|
|
959
|
+
const hint = mode === "npx"
|
|
960
|
+
? "for repeated use, `npm i -g @clipy/cli` — a global install can load a global Playwright; the npx cache can't"
|
|
961
|
+
: undefined;
|
|
962
|
+
return {
|
|
963
|
+
name: "install",
|
|
964
|
+
status: "info",
|
|
965
|
+
detail: `${label[mode]} — ${argv1 || "?"}`,
|
|
966
|
+
hint,
|
|
967
|
+
data: { mode, argv1 },
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
function doctorGlyph(status) {
|
|
971
|
+
switch (status) {
|
|
972
|
+
case "pass":
|
|
973
|
+
return c.green("PASS");
|
|
974
|
+
case "warn":
|
|
975
|
+
return c.yellow("WARN");
|
|
976
|
+
case "fail":
|
|
977
|
+
return c.red("FAIL");
|
|
978
|
+
case "skip":
|
|
979
|
+
return c.dim("SKIP");
|
|
980
|
+
default:
|
|
981
|
+
return c.dim("INFO");
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
async function cmdDoctor(ctx, json) {
|
|
985
|
+
const checks = [
|
|
986
|
+
await doctorAuthCheck(ctx),
|
|
987
|
+
...(await doctorBridgeChecks()),
|
|
988
|
+
await doctorPlaywrightCheck(),
|
|
989
|
+
doctorInstallCheck(),
|
|
990
|
+
];
|
|
991
|
+
const failed = checks.filter((chk) => chk.status === "fail").length;
|
|
992
|
+
if (json) {
|
|
993
|
+
printJson({
|
|
994
|
+
version: VERSION,
|
|
995
|
+
apiUrl: ctx.apiUrl,
|
|
996
|
+
ok: failed === 0,
|
|
997
|
+
checks: checks.map((chk) => ({
|
|
998
|
+
name: chk.name,
|
|
999
|
+
status: chk.status,
|
|
1000
|
+
detail: chk.detail,
|
|
1001
|
+
...(chk.hint ? { hint: chk.hint } : {}),
|
|
1002
|
+
...(chk.data ? { data: chk.data } : {}),
|
|
1003
|
+
})),
|
|
1004
|
+
});
|
|
1005
|
+
if (failed > 0)
|
|
1006
|
+
process.exitCode = 1;
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
process.stdout.write(`${c.bold("clipy doctor")} ${c.dim(`— v${VERSION} · ${ctx.apiUrl}`)}\n\n`);
|
|
1010
|
+
for (const chk of checks) {
|
|
1011
|
+
// Pad to the longest check name ("bridge handshake") so details align.
|
|
1012
|
+
process.stdout.write(`${doctorGlyph(chk.status)} ${chk.name.padEnd(16)} ${chk.detail}\n`);
|
|
1013
|
+
if (chk.hint)
|
|
1014
|
+
process.stdout.write(` ${c.dim(`↳ ${chk.hint}`)}\n`);
|
|
1015
|
+
}
|
|
1016
|
+
process.stdout.write("\n");
|
|
1017
|
+
if (failed === 0) {
|
|
1018
|
+
process.stdout.write(`${c.green("✓")} no failures\n`);
|
|
1019
|
+
}
|
|
1020
|
+
else {
|
|
1021
|
+
process.stdout.write(`${c.red(`✗ ${failed} check${failed === 1 ? "" : "s"} failed`)} — see the hints above.\n`);
|
|
1022
|
+
process.exitCode = 1;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
734
1025
|
// ---------------------------------------------------------------------------
|
|
735
1026
|
// record — the ONE write command. Drives a headless browser (Playwright),
|
|
736
1027
|
// captures the page to WebM, and streams it through Clipy's raw-upload
|
|
@@ -844,23 +1135,106 @@ async function ingestPostChunk(ctx, recordingId, uploadToken, partNumber, bytes)
|
|
|
844
1135
|
throw new Error(`chunk ${partNumber} failed (HTTP ${res.status})${text ? `: ${text}` : ""}`);
|
|
845
1136
|
}
|
|
846
1137
|
}
|
|
847
|
-
|
|
1138
|
+
/** Pull `chromium` out of a dynamically-imported Playwright module. A bare
|
|
1139
|
+
* `import('playwright')` (via the package `exports` map) exposes it as a named
|
|
1140
|
+
* export, but importing the raw index.js by file URL (the cwd-local path
|
|
1141
|
+
* below) hits CJS→ESM interop where it only lands on `.default`. Check both. */
|
|
1142
|
+
function chromiumFrom(mod) {
|
|
1143
|
+
const m = mod;
|
|
1144
|
+
return m.chromium ?? m.default?.chromium;
|
|
1145
|
+
}
|
|
1146
|
+
async function resolvePlaywright() {
|
|
1147
|
+
// 1) Resolve relative to the CLI itself — a normal dependency, or a global
|
|
1148
|
+
// Playwright sitting beside a global `@clipy/cli` in the same node_modules.
|
|
848
1149
|
for (const mod of ["playwright", "playwright-core"]) {
|
|
849
1150
|
try {
|
|
850
|
-
const
|
|
851
|
-
if (
|
|
852
|
-
return
|
|
1151
|
+
const chromium = chromiumFrom(await import(mod));
|
|
1152
|
+
if (chromium)
|
|
1153
|
+
return { ok: true, chromium, source: `import('${mod}')` };
|
|
853
1154
|
}
|
|
854
1155
|
catch {
|
|
855
|
-
// try the next
|
|
1156
|
+
// try the next strategy
|
|
856
1157
|
}
|
|
857
1158
|
}
|
|
858
|
-
|
|
1159
|
+
// 2) Resolve relative to the user's project (cwd). Under `npx @clipy/cli` the
|
|
1160
|
+
// package lives in an isolated cache that a bare ESM import cannot resolve
|
|
1161
|
+
// a global/project Playwright from, but a require rooted at cwd can.
|
|
1162
|
+
for (const mod of ["playwright", "playwright-core"]) {
|
|
1163
|
+
try {
|
|
1164
|
+
const requireFromCwd = createRequire(join(process.cwd(), "package.json"));
|
|
1165
|
+
const resolved = requireFromCwd.resolve(mod);
|
|
1166
|
+
const chromium = chromiumFrom(await import(pathToFileURL(resolved).href));
|
|
1167
|
+
if (chromium)
|
|
1168
|
+
return { ok: true, chromium, source: `${mod} at ${dirname(resolved)}` };
|
|
1169
|
+
}
|
|
1170
|
+
catch {
|
|
1171
|
+
// fall through to the miss
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
return {
|
|
1175
|
+
ok: false,
|
|
1176
|
+
source: null,
|
|
1177
|
+
error: "Playwright is not installed where this CLI can load it (tried a bundled import and a cwd-local resolve)",
|
|
1178
|
+
};
|
|
1179
|
+
}
|
|
1180
|
+
/** Classify how this CLI was invoked so install hints match the user's setup.
|
|
1181
|
+
* npx runs from an isolated `_npx` cache; a global bin lives outside cwd; a
|
|
1182
|
+
* project-local install sits under cwd/node_modules. */
|
|
1183
|
+
function detectInstallMode() {
|
|
1184
|
+
const argv1 = process.argv[1] ? resolve(process.argv[1]) : "";
|
|
1185
|
+
const norm = argv1.replace(/\\/g, "/");
|
|
1186
|
+
const cwd = resolve(process.cwd()).replace(/\\/g, "/");
|
|
1187
|
+
let mode = "unknown";
|
|
1188
|
+
if (/\/_npx\//.test(norm))
|
|
1189
|
+
mode = "npx";
|
|
1190
|
+
else if (norm.startsWith(`${cwd}/`) && /\/node_modules\//.test(norm))
|
|
1191
|
+
mode = "local";
|
|
1192
|
+
else if (/\/node_modules\//.test(norm))
|
|
1193
|
+
mode = "global";
|
|
1194
|
+
return { mode, argv1 };
|
|
1195
|
+
}
|
|
1196
|
+
/** One-line install hint keyed to the install mode (the `doctor` ↳ line). For
|
|
1197
|
+
* npx we LEAD with the cwd-local install — the only guaranteed-working fix,
|
|
1198
|
+
* since the resolver's cwd-local strategy loads it and the npx cache can't see
|
|
1199
|
+
* a global one. */
|
|
1200
|
+
function playwrightInstallHint(mode) {
|
|
1201
|
+
if (mode === "npx") {
|
|
1202
|
+
return "in your project dir: npm i playwright && npx playwright install chromium (then re-run) — or install globally: npm i -g @clipy/cli playwright && clipy …";
|
|
1203
|
+
}
|
|
1204
|
+
if (mode === "local")
|
|
1205
|
+
return "npm i -D playwright && npx playwright install chromium";
|
|
1206
|
+
return "npm install -g playwright && npx playwright install chromium";
|
|
1207
|
+
}
|
|
1208
|
+
/** The full, multi-line message record/daemon die() with when Playwright is
|
|
1209
|
+
* missing — the npx branch is the important fix: `npm i -g playwright` cannot
|
|
1210
|
+
* help a package running from the npx cache (ESM there can't see globals), so
|
|
1211
|
+
* we lead with the cwd-local install, which the resolver DOES load. */
|
|
1212
|
+
function playwrightMissingMessage(mode) {
|
|
1213
|
+
const head = "clipy record needs Playwright (a headless browser), but it isn't installed where this CLI can load it.";
|
|
1214
|
+
if (mode === "npx") {
|
|
1215
|
+
return (`${head}\n` +
|
|
1216
|
+
`You're running via npx, whose isolated cache can't load a globally-installed Playwright. The reliable fix is a project-local install — run this in your project directory (the one you'll run clipy from):\n` +
|
|
1217
|
+
` ${c.bold("npm i playwright && npx playwright install chromium")}\n` +
|
|
1218
|
+
`then re-run your command. Alternatively, install everything globally and run the global clipy (not npx):\n` +
|
|
1219
|
+
` ${c.bold("npm i -g @clipy/cli playwright && npx playwright install chromium && clipy record …")}`);
|
|
1220
|
+
}
|
|
1221
|
+
if (mode === "local") {
|
|
1222
|
+
return (`${head}\n` +
|
|
1223
|
+
` ${c.bold("npm i -D playwright && npx playwright install chromium")}\n` +
|
|
1224
|
+
`Then re-run your command.`);
|
|
1225
|
+
}
|
|
1226
|
+
return (`${head}\n` +
|
|
859
1227
|
` ${c.bold("npm install -g playwright")}\n` +
|
|
860
1228
|
` ${c.bold("npx playwright install chromium")}\n` +
|
|
861
1229
|
`Then re-run your command. (Playwright is kept out of the base CLI so the ` +
|
|
862
1230
|
`read-only commands stay a small, dependency-free install.)`);
|
|
863
1231
|
}
|
|
1232
|
+
async function loadChromium() {
|
|
1233
|
+
const res = await resolvePlaywright();
|
|
1234
|
+
if (res.ok)
|
|
1235
|
+
return res.chromium;
|
|
1236
|
+
die(playwrightMissingMessage(detectInstallMode().mode));
|
|
1237
|
+
}
|
|
864
1238
|
/** Named viewport presets for `--viewports` (agent demos across screen sizes). */
|
|
865
1239
|
const VIEWPORT_ALIASES = {
|
|
866
1240
|
mobile: { width: 390, height: 844 },
|
|
@@ -887,13 +1261,55 @@ function parseViewports(spec) {
|
|
|
887
1261
|
die("--viewports supports at most 8 sizes per recording", 2);
|
|
888
1262
|
return out;
|
|
889
1263
|
}
|
|
890
|
-
/**
|
|
891
|
-
*
|
|
1264
|
+
/**
|
|
1265
|
+
* Parses a `--note` flag value. Strict grammar — three shapes:
|
|
1266
|
+
* "12: text" / "12.5s: text" → absolute note at 12s
|
|
1267
|
+
* "pass2: text" → note at the real start of viewport pass 2
|
|
1268
|
+
* "pass2@5: text" / "pass2@5s: t" → 5s into pass 2's real start
|
|
1269
|
+
* A value with no recognized prefix is a bare note at 0s. A value that LOOKS
|
|
1270
|
+
* like a pass directive but is malformed (e.g. "pass2 text" with no colon, or
|
|
1271
|
+
* "pass0:") is REJECTED, not silently demoted to an absolute-0 note — a wrong
|
|
1272
|
+
* timestamp that pairs a note with the wrong pass is worse than a hard error.
|
|
1273
|
+
*/
|
|
892
1274
|
function parseNoteFlag(value) {
|
|
893
|
-
const
|
|
1275
|
+
const v = value.trim();
|
|
1276
|
+
const passMatch = v.match(/^pass\s*(\d+)\s*(?:@\s*(\d+(?:\.\d+)?)\s*s?)?\s*:\s*(.+)$/i);
|
|
1277
|
+
if (passMatch) {
|
|
1278
|
+
const pass = parseInt(passMatch[1], 10);
|
|
1279
|
+
if (pass < 1) {
|
|
1280
|
+
die(`invalid --note "${value}": pass number must be an integer ≥ 1 (e.g. "pass2: text")`, 2);
|
|
1281
|
+
}
|
|
1282
|
+
return {
|
|
1283
|
+
pass,
|
|
1284
|
+
passOffsetMs: passMatch[2] ? Math.round(parseFloat(passMatch[2]) * 1000) : 0,
|
|
1285
|
+
text: passMatch[3].trim(),
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
// Attempted-but-malformed pass directive ("pass2 text", "pass2@: x", "pass0:").
|
|
1289
|
+
if (/^pass\s*\d/i.test(v)) {
|
|
1290
|
+
die(`invalid --note "${value}": pass-scoped notes are "passN: text" or "passN@<seconds>: text" ` +
|
|
1291
|
+
`(integer pass ≥ 1, optional @seconds), e.g. "pass2: mobile" or "pass2@5: after scroll"`, 2);
|
|
1292
|
+
}
|
|
1293
|
+
const m = v.match(/^(\d+(?:\.\d+)?)\s*s?\s*:\s*(.+)$/);
|
|
894
1294
|
if (m)
|
|
895
1295
|
return { startMs: Math.round(parseFloat(m[1]) * 1000), text: m[2].trim() };
|
|
896
|
-
return { startMs: 0, text:
|
|
1296
|
+
return { startMs: 0, text: v };
|
|
1297
|
+
}
|
|
1298
|
+
/** Highest pass index referenced by any pass-scoped note (0 = none). */
|
|
1299
|
+
function maxPassRef(parsed) {
|
|
1300
|
+
return parsed.reduce((m, n) => (n.pass != null && n.pass > m ? n.pass : m), 0);
|
|
1301
|
+
}
|
|
1302
|
+
/** Anchor parsed notes to absolute ms using the recorded pass start offsets
|
|
1303
|
+
* (index 0 = pass 1). Pass-scoped notes land at their pass's real start (+offset);
|
|
1304
|
+
* absolute notes pass through. An out-of-range pass clamps to the last pass. */
|
|
1305
|
+
function resolveNarrationNotes(parsed, passStartsMs) {
|
|
1306
|
+
return parsed.map((n) => {
|
|
1307
|
+
if (n.pass != null) {
|
|
1308
|
+
const base = passStartsMs[n.pass - 1] ?? passStartsMs[passStartsMs.length - 1] ?? 0;
|
|
1309
|
+
return { startMs: Math.max(0, Math.round(base + (n.passOffsetMs ?? 0))), text: n.text };
|
|
1310
|
+
}
|
|
1311
|
+
return { startMs: Math.max(0, Math.round(n.startMs ?? 0)), text: n.text };
|
|
1312
|
+
});
|
|
897
1313
|
}
|
|
898
1314
|
/** WebM/Matroska files start with the EBML magic. Refuse to upload anything
|
|
899
1315
|
* else — a crashed Chromium can leave a zero-byte or garbage file behind. */
|
|
@@ -914,6 +1330,51 @@ function validateWebmFile(videoPath) {
|
|
|
914
1330
|
}
|
|
915
1331
|
return size;
|
|
916
1332
|
}
|
|
1333
|
+
// --- Recording kind (--type) -----------------------------------------------
|
|
1334
|
+
// Declares what a recording IS, so the AI summary doesn't misread a demo as a
|
|
1335
|
+
// bug report. Sent as `recordingKind` on raw-upload/complete. The literals +
|
|
1336
|
+
// aliases mirror the server contract exactly (server also normalizes and
|
|
1337
|
+
// ignores unknowns); the CLI validates locally so agents get instant feedback.
|
|
1338
|
+
const RECORDING_KINDS = [
|
|
1339
|
+
"bug_report",
|
|
1340
|
+
"feature_request",
|
|
1341
|
+
"product_demo",
|
|
1342
|
+
"walkthrough_tutorial",
|
|
1343
|
+
"feedback_review",
|
|
1344
|
+
"discussion_talk",
|
|
1345
|
+
"other",
|
|
1346
|
+
];
|
|
1347
|
+
const RECORDING_KIND_ALIASES = {
|
|
1348
|
+
bug: "bug_report",
|
|
1349
|
+
feature: "feature_request",
|
|
1350
|
+
demo: "product_demo",
|
|
1351
|
+
product: "product_demo",
|
|
1352
|
+
walkthrough: "walkthrough_tutorial",
|
|
1353
|
+
tutorial: "walkthrough_tutorial",
|
|
1354
|
+
guide: "walkthrough_tutorial",
|
|
1355
|
+
feedback: "feedback_review",
|
|
1356
|
+
review: "feedback_review",
|
|
1357
|
+
discussion: "discussion_talk",
|
|
1358
|
+
talk: "discussion_talk",
|
|
1359
|
+
meeting: "discussion_talk",
|
|
1360
|
+
};
|
|
1361
|
+
/** Normalize a --type value (case/space/hyphen-insensitive) to a canonical
|
|
1362
|
+
* recordingKind literal, or null if unrecognized. */
|
|
1363
|
+
function normalizeRecordingKind(input) {
|
|
1364
|
+
const norm = input.trim().toLowerCase().replace(/[\s-]+/g, "_");
|
|
1365
|
+
if (RECORDING_KINDS.includes(norm))
|
|
1366
|
+
return norm;
|
|
1367
|
+
return RECORDING_KIND_ALIASES[norm] ?? null;
|
|
1368
|
+
}
|
|
1369
|
+
/** Validate a --type value; die() with the accepted list on a miss. */
|
|
1370
|
+
function requireRecordingKind(input) {
|
|
1371
|
+
const kind = normalizeRecordingKind(input);
|
|
1372
|
+
if (!kind) {
|
|
1373
|
+
die(`--type "${input}" is not a recording kind. Accepted: ${RECORDING_KINDS.join(", ")} ` +
|
|
1374
|
+
`(aliases: bug, feature, demo/product, walkthrough/tutorial/guide, feedback/review, discussion/talk/meeting)`, 2);
|
|
1375
|
+
}
|
|
1376
|
+
return kind;
|
|
1377
|
+
}
|
|
917
1378
|
/**
|
|
918
1379
|
* Streams a captured WebM through Clipy's raw-upload pipeline
|
|
919
1380
|
* (initiate → chunks → finalize → complete). Shared by `clipy record` and
|
|
@@ -979,6 +1440,7 @@ async function uploadWebmToClipy(ctx, opts) {
|
|
|
979
1440
|
description: opts.description,
|
|
980
1441
|
sourcePlatform: "web",
|
|
981
1442
|
sourceVersion: `cli/${VERSION}`,
|
|
1443
|
+
...(opts.recordingKind ? { recordingKind: opts.recordingKind } : {}),
|
|
982
1444
|
...(opts.narration && (opts.narration.text || opts.narration.notes?.length)
|
|
983
1445
|
? { narration: opts.narration }
|
|
984
1446
|
: {}),
|
|
@@ -1002,6 +1464,52 @@ async function uploadWebmToClipy(ctx, opts) {
|
|
|
1002
1464
|
sizeBytes,
|
|
1003
1465
|
};
|
|
1004
1466
|
}
|
|
1467
|
+
/**
|
|
1468
|
+
* Blank-frame heuristic. We can't decode pixels without a dependency, so JPEG
|
|
1469
|
+
* size per megapixel is our stddev/complexity proxy: a uniform "still
|
|
1470
|
+
* compiling" screen compresses to a tiny JPEG, real UI to a much larger one.
|
|
1471
|
+
* Calibrated at quality 30 on a 1280×720 viewport — solid colours, a bare
|
|
1472
|
+
* "Compiling…" line, and a lone spinner all land ~6.7–7.0 KB/MP; a real page
|
|
1473
|
+
* with a header, nav, text and a table is ~22 KB/MP. 12 KB/MP sits well clear
|
|
1474
|
+
* of both, biased to treat splash/compile screens as blank.
|
|
1475
|
+
*/
|
|
1476
|
+
function isBlankFrame(jpeg, width, height) {
|
|
1477
|
+
const px = Math.max(1, width * height);
|
|
1478
|
+
const bytesPerMegapixel = (jpeg.length / px) * 1_000_000;
|
|
1479
|
+
return bytesPerMegapixel < 12_000;
|
|
1480
|
+
}
|
|
1481
|
+
/**
|
|
1482
|
+
* Poll cheap JPEG screenshots until the frame has real content (not the blank
|
|
1483
|
+
* t=0 a still-compiling dev server shows) or a 10s cap, so the capture clock —
|
|
1484
|
+
* and every note anchored to it — starts on the first meaningful frame, not on
|
|
1485
|
+
* a blank one. Returns the ms spent waiting; logs when it waited meaningfully.
|
|
1486
|
+
*/
|
|
1487
|
+
async function waitForFirstPaint(page, size, log) {
|
|
1488
|
+
const CAP_MS = 10_000;
|
|
1489
|
+
const POLL_MS = 250;
|
|
1490
|
+
const start = Date.now();
|
|
1491
|
+
for (;;) {
|
|
1492
|
+
let blank = true;
|
|
1493
|
+
try {
|
|
1494
|
+
const buf = await page.screenshot({ type: "jpeg", quality: 30 });
|
|
1495
|
+
blank = isBlankFrame(buf, size.width, size.height);
|
|
1496
|
+
}
|
|
1497
|
+
catch {
|
|
1498
|
+
blank = true; // screenshot failed (page not ready yet) — keep waiting
|
|
1499
|
+
}
|
|
1500
|
+
if (!blank)
|
|
1501
|
+
break;
|
|
1502
|
+
if (Date.now() - start >= CAP_MS) {
|
|
1503
|
+
log(c.yellow(`no meaningful paint after ${Math.round(CAP_MS / 1000)}s — starting the clock anyway (a blank app shell is fine)`));
|
|
1504
|
+
break;
|
|
1505
|
+
}
|
|
1506
|
+
await page.waitForTimeout(POLL_MS);
|
|
1507
|
+
}
|
|
1508
|
+
const waited = Date.now() - start;
|
|
1509
|
+
if (waited >= POLL_MS * 2)
|
|
1510
|
+
log(c.dim(`waited ${(waited / 1000).toFixed(1)}s for first meaningful paint`));
|
|
1511
|
+
return waited;
|
|
1512
|
+
}
|
|
1005
1513
|
async function cmdRecord(ctx, opts) {
|
|
1006
1514
|
// Validate the target URL up front — a headless browser will happily hang on
|
|
1007
1515
|
// a typo'd or non-http(s) URL otherwise.
|
|
@@ -1034,8 +1542,18 @@ async function cmdRecord(ctx, opts) {
|
|
|
1034
1542
|
width: Math.max(...passes.map((v) => v.width)),
|
|
1035
1543
|
height: Math.max(...passes.map((v) => v.height)),
|
|
1036
1544
|
};
|
|
1545
|
+
// A pass-scoped note ("pass3: …") that names a pass we won't record is almost
|
|
1546
|
+
// always a mistake — fail fast before spinning up the browser.
|
|
1547
|
+
const maxRef = maxPassRef(opts.notes);
|
|
1548
|
+
if (maxRef > passes.length) {
|
|
1549
|
+
die(`--note "pass${maxRef}: …" refers to pass ${maxRef}, but this recording has ${passes.length} pass${passes.length === 1 ? "" : "es"}` +
|
|
1550
|
+
`${opts.viewports ? "" : " (pass-scoped notes are for --viewports; use an absolute timestamp otherwise)"}`, 2);
|
|
1551
|
+
}
|
|
1037
1552
|
let uploaded;
|
|
1038
1553
|
const autoNotes = [];
|
|
1554
|
+
// The real start of each pass, measured from the capture clock (index 0 =
|
|
1555
|
+
// pass 1). Pass-scoped notes anchor to these actual times, not fixed guesses.
|
|
1556
|
+
const passStartsMs = [];
|
|
1039
1557
|
try {
|
|
1040
1558
|
// --- Capture -----------------------------------------------------------
|
|
1041
1559
|
let videoPath;
|
|
@@ -1053,14 +1571,12 @@ async function cmdRecord(ctx, opts) {
|
|
|
1053
1571
|
recordVideo: { dir: tmpDir, size: frame },
|
|
1054
1572
|
});
|
|
1055
1573
|
const page = await context.newPage();
|
|
1056
|
-
|
|
1574
|
+
// captureStart is set AFTER the first meaningful paint (below), so notes
|
|
1575
|
+
// and pass marks aren't anchored to the blank t=0 a compiling app shows.
|
|
1576
|
+
let captureStart = 0;
|
|
1057
1577
|
for (const [i, vp] of passes.entries()) {
|
|
1058
1578
|
if (opts.viewports) {
|
|
1059
1579
|
await page.setViewportSize({ width: vp.width, height: vp.height }).catch(() => { });
|
|
1060
|
-
autoNotes.push({
|
|
1061
|
-
startMs: Date.now() - captureStart,
|
|
1062
|
-
text: `[auto] Viewport pass ${i + 1}/${passes.length}: ${vp.label}`,
|
|
1063
|
-
});
|
|
1064
1580
|
log(`${c.dim(`viewport ${vp.label}…`)}`);
|
|
1065
1581
|
}
|
|
1066
1582
|
log(`${c.dim(`opening ${target.href}…`)}`);
|
|
@@ -1072,6 +1588,21 @@ async function cmdRecord(ctx, opts) {
|
|
|
1072
1588
|
// asked to capture whatever is on screen for --for seconds.
|
|
1073
1589
|
log(c.yellow(`page load timed out; recording current state anyway`));
|
|
1074
1590
|
}
|
|
1591
|
+
// Gate the capture clock on first meaningful paint (once, on pass 1).
|
|
1592
|
+
if (i === 0) {
|
|
1593
|
+
await waitForFirstPaint(page, frame, log);
|
|
1594
|
+
captureStart = Date.now();
|
|
1595
|
+
}
|
|
1596
|
+
const passStart = Date.now() - captureStart;
|
|
1597
|
+
passStartsMs[i] = passStart;
|
|
1598
|
+
if (opts.viewports) {
|
|
1599
|
+
autoNotes.push({
|
|
1600
|
+
startMs: passStart,
|
|
1601
|
+
// "pass N/M start" is a deterministic, machine-parseable tag so
|
|
1602
|
+
// downstream key-moment alignment knows exactly where each pass began.
|
|
1603
|
+
text: `[auto] Viewport pass ${i + 1}/${passes.length} start: ${vp.label}`,
|
|
1604
|
+
});
|
|
1605
|
+
}
|
|
1075
1606
|
log(`${c.dim(`recording for ${opts.forSec}s…`)}`);
|
|
1076
1607
|
if (opts.viewports) {
|
|
1077
1608
|
// Slow scroll through the page so each size shows real layout, not
|
|
@@ -1099,11 +1630,12 @@ async function cmdRecord(ctx, opts) {
|
|
|
1099
1630
|
await browser.close().catch(() => { });
|
|
1100
1631
|
}
|
|
1101
1632
|
// --- Upload ------------------------------------------------------------
|
|
1102
|
-
const notes = [...autoNotes, ...opts.notes].sort((a, b) => a.startMs - b.startMs);
|
|
1633
|
+
const notes = [...autoNotes, ...resolveNarrationNotes(opts.notes, passStartsMs)].sort((a, b) => a.startMs - b.startMs);
|
|
1103
1634
|
uploaded = await uploadWebmToClipy(ctx, {
|
|
1104
1635
|
videoPath,
|
|
1105
1636
|
name: opts.name,
|
|
1106
1637
|
description: opts.description,
|
|
1638
|
+
recordingKind: opts.recordingKind,
|
|
1107
1639
|
narration: notes.length ? { notes } : undefined,
|
|
1108
1640
|
log,
|
|
1109
1641
|
});
|
|
@@ -1168,7 +1700,16 @@ function readSessionState(file) {
|
|
|
1168
1700
|
function writeSessionState(file, state) {
|
|
1169
1701
|
mkdirSync(dirname(file), { recursive: true });
|
|
1170
1702
|
const tmp = `${file}.${process.pid}.tmp`;
|
|
1703
|
+
// 0600: the state file can hold a CDP endpoint that grants full control of
|
|
1704
|
+
// the recording browser — keep it owner-only. mode on writeFileSync is
|
|
1705
|
+
// umask-masked, so chmod explicitly to guarantee it.
|
|
1171
1706
|
writeFileSync(tmp, `${JSON.stringify(state, null, 2)}\n`, { mode: 0o600 });
|
|
1707
|
+
try {
|
|
1708
|
+
chmodSync(tmp, 0o600);
|
|
1709
|
+
}
|
|
1710
|
+
catch {
|
|
1711
|
+
// best-effort on platforms without POSIX modes
|
|
1712
|
+
}
|
|
1172
1713
|
renameSync(tmp, file);
|
|
1173
1714
|
}
|
|
1174
1715
|
function pidAlive(pid) {
|
|
@@ -1210,6 +1751,12 @@ async function resolveBridgeTarget(info, opts) {
|
|
|
1210
1751
|
}
|
|
1211
1752
|
/** One-shot real-screen recording through the running Clipy app. */
|
|
1212
1753
|
async function cmdRecordMac(opts) {
|
|
1754
|
+
// A real-screen capture is one continuous take — there are no viewport passes
|
|
1755
|
+
// to anchor pass-scoped notes against.
|
|
1756
|
+
const macMaxRef = maxPassRef(opts.notes);
|
|
1757
|
+
if (macMaxRef > 1) {
|
|
1758
|
+
die(`--note "pass${macMaxRef}: …" needs --viewports (multiple passes). --source mac-screen is one continuous capture — use an absolute timestamp, e.g. --note "12: text".`, 2);
|
|
1759
|
+
}
|
|
1213
1760
|
const info = readBridgeInfo();
|
|
1214
1761
|
const log = (m) => {
|
|
1215
1762
|
if (!opts.json)
|
|
@@ -1217,13 +1764,23 @@ async function cmdRecordMac(opts) {
|
|
|
1217
1764
|
};
|
|
1218
1765
|
const target = await resolveBridgeTarget(info, opts);
|
|
1219
1766
|
log(`${c.dim(`asking the Clipy app (v${info.appVersion}) to record ${target?.label ?? "the screen"}…`)}`);
|
|
1767
|
+
// --type on the mac path: the current Clipy app doesn't forward recordingKind
|
|
1768
|
+
// from the bridge to its raw-upload/complete call (its AgentCompleteExtras has
|
|
1769
|
+
// no such field — desktop follow-up). We still send it (serde ignores unknown
|
|
1770
|
+
// start-args, so it's forward-compatible) but tell the user it isn't applied
|
|
1771
|
+
// yet, rather than silently dropping their intent.
|
|
1772
|
+
if (opts.recordingKind) {
|
|
1773
|
+
log(c.yellow(`note: --type is not applied to --source mac-screen recordings yet (needs a Clipy app update)`));
|
|
1774
|
+
}
|
|
1775
|
+
const notes = resolveNarrationNotes(opts.notes, [0]);
|
|
1220
1776
|
await bridgeRequest(info, "start", {
|
|
1221
1777
|
// The recording is stopped by us after forSec; maxSec is the safety net
|
|
1222
1778
|
// in case this CLI process dies mid-wait.
|
|
1223
1779
|
maxSec: Math.min(opts.forSec + 60, 1800),
|
|
1224
1780
|
title: opts.name,
|
|
1225
1781
|
description: opts.description,
|
|
1226
|
-
|
|
1782
|
+
...(opts.recordingKind ? { recordingKind: opts.recordingKind } : {}),
|
|
1783
|
+
notes: notes.map((n) => ({ startMs: n.startMs, text: n.text })),
|
|
1227
1784
|
...(target ? { source: target.source } : {}),
|
|
1228
1785
|
});
|
|
1229
1786
|
log(`${c.dim(`recording for ${opts.forSec}s…`)}`);
|
|
@@ -1277,10 +1834,16 @@ async function cmdSessionStart(ctx, opts) {
|
|
|
1277
1834
|
const info = readBridgeInfo();
|
|
1278
1835
|
const maxSec = Math.min(Math.max(1, opts.maxSec), SESSION_HARD_CAP_SEC);
|
|
1279
1836
|
const target = await resolveBridgeTarget(info, opts);
|
|
1837
|
+
// See cmdRecordMac: --type isn't applied on the mac path yet (desktop gap);
|
|
1838
|
+
// send it forward-compat but tell the user.
|
|
1839
|
+
if (opts.recordingKind && !opts.json) {
|
|
1840
|
+
process.stderr.write(`${c.yellow("note: --type is not applied to --source mac-screen recordings yet (needs a Clipy app update)")}\n`);
|
|
1841
|
+
}
|
|
1280
1842
|
await bridgeRequest(info, "start", {
|
|
1281
1843
|
maxSec,
|
|
1282
1844
|
title: opts.name,
|
|
1283
1845
|
description: opts.description,
|
|
1846
|
+
...(opts.recordingKind ? { recordingKind: opts.recordingKind } : {}),
|
|
1284
1847
|
...(target ? { source: target.source } : {}),
|
|
1285
1848
|
});
|
|
1286
1849
|
writeSessionState(file, macSessionState(info, maxSec));
|
|
@@ -1324,9 +1887,11 @@ async function cmdSessionStart(ctx, opts) {
|
|
|
1324
1887
|
url: target.href,
|
|
1325
1888
|
name: opts.name,
|
|
1326
1889
|
description: opts.description,
|
|
1890
|
+
recordingKind: opts.recordingKind,
|
|
1327
1891
|
maxSec,
|
|
1328
1892
|
width: opts.width,
|
|
1329
1893
|
height: opts.height,
|
|
1894
|
+
exposeCdp: opts.exposeCdp,
|
|
1330
1895
|
state: "starting",
|
|
1331
1896
|
marksPath: join(dir, `marks-${id}.jsonl`),
|
|
1332
1897
|
controlPath: join(dir, `control-${id}.json`),
|
|
@@ -1365,11 +1930,29 @@ async function cmdSessionStart(ctx, opts) {
|
|
|
1365
1930
|
}
|
|
1366
1931
|
await new Promise((r) => setTimeout(r, 300));
|
|
1367
1932
|
}
|
|
1933
|
+
const started = readSessionState(file);
|
|
1368
1934
|
if (opts.json) {
|
|
1369
|
-
printJson({
|
|
1935
|
+
printJson({
|
|
1936
|
+
state: "recording",
|
|
1937
|
+
url: target.href,
|
|
1938
|
+
maxSec,
|
|
1939
|
+
sessionFile: file,
|
|
1940
|
+
cdpUrl: started?.cdpUrl ?? null,
|
|
1941
|
+
cdpHttpUrl: started?.cdpHttpUrl ?? null,
|
|
1942
|
+
});
|
|
1370
1943
|
return;
|
|
1371
1944
|
}
|
|
1372
1945
|
process.stdout.write(`${c.green("✓")} recording ${c.bold(target.href)} (max ${maxSec}s)\n`);
|
|
1946
|
+
if (started?.cdpHttpUrl) {
|
|
1947
|
+
process.stdout.write(`${c.yellow("⚠ CDP exposed:")} any local process can attach to and control this browser while the session runs.\n` +
|
|
1948
|
+
`${c.dim(`drive the browser: connect your tools to ${started.cdpHttpUrl}`)}\n`);
|
|
1949
|
+
}
|
|
1950
|
+
else if (opts.exposeCdp) {
|
|
1951
|
+
// Asked for it, but it isn't up — either env-disabled or discovery failed.
|
|
1952
|
+
process.stdout.write(`${c.dim(process.env.CLIPY_DISABLE_CDP === "1"
|
|
1953
|
+
? "CDP not exposed (CLIPY_DISABLE_CDP=1 overrides --expose-cdp)"
|
|
1954
|
+
: "CDP requested but the endpoint could not be established — see the daemon log")}\n`);
|
|
1955
|
+
}
|
|
1373
1956
|
process.stdout.write(`${c.dim("while it runs:")} clipy mark "what just happened"\n` +
|
|
1374
1957
|
`${c.dim("when finished:")} clipy session stop ${c.dim("· discard:")} clipy session abort\n`);
|
|
1375
1958
|
}
|
|
@@ -1584,11 +2167,52 @@ async function cmdSessionStatus(json) {
|
|
|
1584
2167
|
elapsedSec: elapsed,
|
|
1585
2168
|
maxSec: state.maxSec,
|
|
1586
2169
|
pid: state.pid,
|
|
2170
|
+
cdpUrl: state.cdpUrl ?? null,
|
|
2171
|
+
cdpHttpUrl: state.cdpHttpUrl ?? null,
|
|
1587
2172
|
});
|
|
1588
2173
|
return;
|
|
1589
2174
|
}
|
|
1590
2175
|
process.stdout.write(`${c.bold(state.state)}${alive ? "" : c.red(" (daemon dead)")} — ${state.url}` +
|
|
1591
2176
|
`${elapsed != null ? ` — ${elapsed}s elapsed (max ${state.maxSec}s)` : ""}\n`);
|
|
2177
|
+
if (state.cdpHttpUrl && state.state === "recording" && alive) {
|
|
2178
|
+
process.stdout.write(`${c.dim(`drive the browser: connect your tools to ${state.cdpHttpUrl}`)}\n`);
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
/** Reserve a free localhost TCP port for Chromium's CDP endpoint. Binding to
|
|
2182
|
+
* :0 then closing hands us a concrete port to pass to --remote-debugging-port,
|
|
2183
|
+
* which we can then poll — passing 0 directly leaves the chosen port only in
|
|
2184
|
+
* Chromium's DevToolsActivePort file, which Playwright's temp profile hides. */
|
|
2185
|
+
function pickFreePort() {
|
|
2186
|
+
return new Promise((resolve, reject) => {
|
|
2187
|
+
const srv = createServer();
|
|
2188
|
+
srv.on("error", reject);
|
|
2189
|
+
srv.listen(0, "127.0.0.1", () => {
|
|
2190
|
+
const addr = srv.address();
|
|
2191
|
+
const port = typeof addr === "object" && addr ? addr.port : 0;
|
|
2192
|
+
srv.close(() => (port ? resolve(port) : reject(new Error("no port"))));
|
|
2193
|
+
});
|
|
2194
|
+
});
|
|
2195
|
+
}
|
|
2196
|
+
/** After Chromium is up with --remote-debugging-port, its HTTP endpoint exposes
|
|
2197
|
+
* the browser-level ws URL at /json/version. Poll until it answers (or 10s). */
|
|
2198
|
+
async function discoverCdpWsUrl(port) {
|
|
2199
|
+
const deadline = Date.now() + 10_000;
|
|
2200
|
+
for (;;) {
|
|
2201
|
+
try {
|
|
2202
|
+
const res = await fetch(`http://127.0.0.1:${port}/json/version`);
|
|
2203
|
+
if (res.ok) {
|
|
2204
|
+
const body = (await res.json());
|
|
2205
|
+
if (body.webSocketDebuggerUrl)
|
|
2206
|
+
return body.webSocketDebuggerUrl;
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
catch {
|
|
2210
|
+
// endpoint not up yet
|
|
2211
|
+
}
|
|
2212
|
+
if (Date.now() >= deadline)
|
|
2213
|
+
return null;
|
|
2214
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
2215
|
+
}
|
|
1592
2216
|
}
|
|
1593
2217
|
async function runSessionDaemon(file) {
|
|
1594
2218
|
const state = readSessionState(file);
|
|
@@ -1617,15 +2241,42 @@ async function runSessionDaemon(file) {
|
|
|
1617
2241
|
try {
|
|
1618
2242
|
const chromium = await loadChromium();
|
|
1619
2243
|
log(`launching chromium for ${state.url}`);
|
|
2244
|
+
// CDP is OPT-IN (--expose-cdp) and the env kill switch wins over the flag:
|
|
2245
|
+
// no debugging port is opened unless the user asked AND CLIPY_DISABLE_CDP
|
|
2246
|
+
// isn't set. When enabled, Playwright still controls the browser over its
|
|
2247
|
+
// own pipe; the extra --remote-debugging-port opens a parallel TCP endpoint
|
|
2248
|
+
// an agent can attach to.
|
|
2249
|
+
const wantCdp = !!state.exposeCdp && process.env.CLIPY_DISABLE_CDP !== "1";
|
|
2250
|
+
if (state.exposeCdp && !wantCdp)
|
|
2251
|
+
log("CDP disabled by CLIPY_DISABLE_CDP=1 — not opening a debugging port");
|
|
2252
|
+
const cdpPort = wantCdp ? await pickFreePort().catch(() => 0) : 0;
|
|
1620
2253
|
browser = await chromium.launch({
|
|
1621
2254
|
headless: true,
|
|
1622
|
-
args: [
|
|
2255
|
+
args: [
|
|
2256
|
+
"--no-sandbox",
|
|
2257
|
+
"--disable-dev-shm-usage",
|
|
2258
|
+
...(cdpPort ? [`--remote-debugging-port=${cdpPort}`] : []),
|
|
2259
|
+
],
|
|
1623
2260
|
});
|
|
1624
2261
|
const context = await browser.newContext({
|
|
1625
2262
|
viewport: { width: state.width, height: state.height },
|
|
1626
2263
|
recordVideo: { dir: state.tmpDir, size: { width: state.width, height: state.height } },
|
|
1627
2264
|
});
|
|
1628
2265
|
const page = await context.newPage();
|
|
2266
|
+
// Best-effort: publish the CDP URL so `session start`/`status` can hand it
|
|
2267
|
+
// to the agent. The recording works fine even if discovery fails.
|
|
2268
|
+
let cdpUrl;
|
|
2269
|
+
let cdpHttpUrl;
|
|
2270
|
+
if (cdpPort) {
|
|
2271
|
+
cdpUrl = (await discoverCdpWsUrl(cdpPort)) ?? undefined;
|
|
2272
|
+
if (cdpUrl) {
|
|
2273
|
+
cdpHttpUrl = `http://127.0.0.1:${cdpPort}`;
|
|
2274
|
+
log(`CDP endpoint ready at ${cdpHttpUrl} (${cdpUrl})`);
|
|
2275
|
+
}
|
|
2276
|
+
else {
|
|
2277
|
+
log(`CDP endpoint not reachable on port ${cdpPort} — browser drive unavailable`);
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
1629
2280
|
// Auto-marks: instrumentation ground truth alongside the agent's intent
|
|
1630
2281
|
// marks. Type-tagged with [auto] so the transcript distinguishes them.
|
|
1631
2282
|
page.on("framenavigated", ((frame) => {
|
|
@@ -1648,7 +2299,7 @@ async function runSessionDaemon(file) {
|
|
|
1648
2299
|
}
|
|
1649
2300
|
}));
|
|
1650
2301
|
recordStart = Date.now();
|
|
1651
|
-
save({ state: "recording", recordStartEpochMs: recordStart });
|
|
2302
|
+
save({ state: "recording", recordStartEpochMs: recordStart, cdpUrl, cdpHttpUrl });
|
|
1652
2303
|
try {
|
|
1653
2304
|
await page.goto(state.url, { waitUntil: "load", timeout: 30_000 });
|
|
1654
2305
|
}
|
|
@@ -1727,6 +2378,7 @@ async function runSessionDaemon(file) {
|
|
|
1727
2378
|
videoPath,
|
|
1728
2379
|
name: state.name,
|
|
1729
2380
|
description: state.description,
|
|
2381
|
+
recordingKind: state.recordingKind,
|
|
1730
2382
|
narration: notes.length ? { notes } : undefined,
|
|
1731
2383
|
log: (m) => log(m.replace(/\x1b\[[0-9;]*m/g, "")),
|
|
1732
2384
|
}).catch((e) => {
|
|
@@ -1849,7 +2501,7 @@ async function cmdAgents(ctx, sub, targetRaw, json) {
|
|
|
1849
2501
|
// command's shape without trial-and-error. Bump GUIDE_SCHEMA_VERSION when the
|
|
1850
2502
|
// contract changes.
|
|
1851
2503
|
// ---------------------------------------------------------------------------
|
|
1852
|
-
const GUIDE_SCHEMA_VERSION =
|
|
2504
|
+
const GUIDE_SCHEMA_VERSION = 3;
|
|
1853
2505
|
function cmdGuide(json) {
|
|
1854
2506
|
if (!json) {
|
|
1855
2507
|
process.stdout.write(HELP);
|
|
@@ -1876,6 +2528,7 @@ function cmdGuide(json) {
|
|
|
1876
2528
|
env: [
|
|
1877
2529
|
{ name: "CLIPY_API_KEY", description: "API key (clipy_sk_live_…) from clipy.online/settings/api-keys; write commands need the 'ingest' scope" },
|
|
1878
2530
|
{ name: "CLIPY_API_URL", description: "API base URL override (default https://clipy.online)" },
|
|
2531
|
+
{ name: "CLIPY_DISABLE_CDP", description: "set to 1 to force session --expose-cdp off (a hard kill switch that wins over the flag)" },
|
|
1879
2532
|
{ name: "NO_COLOR", description: "disable ANSI color" },
|
|
1880
2533
|
],
|
|
1881
2534
|
exitCodes: [
|
|
@@ -1898,9 +2551,10 @@ function cmdGuide(json) {
|
|
|
1898
2551
|
cmdDoc("download", "clipy download <id> [-o path]", "Download the MP4"),
|
|
1899
2552
|
cmdDoc("open", "clipy open <id>", "Open the share page in a browser"),
|
|
1900
2553
|
cmdDoc("wait", "clipy wait <id> [--for transcript|summary|both] [--timeout sec]", "Block until artifacts are ready"),
|
|
1901
|
-
cmdDoc("record", "clipy record --url <url> [--for sec] [--viewports list] [--title t] [--note '12: text']… [--wait] [--json]", "Headless one-shot capture of a web app; notes become the transcript. With --source mac-screen: records the real screen via the Clipy Mac app; --window '<title|app|id>' or --display <id> target one window/display (ids from clipy sources)", ["--for", "--viewports", "--title", "--description", "--note", "--width", "--height", "--wait", "--source", "--window", "--display"]),
|
|
1902
|
-
cmdDoc("session", "clipy session <start|stop|abort|status> [--url <url>] [--max sec] [--source web|mac-screen] [--window w] [--display d]", "Background recording session; auto-stops + uploads at --max (default 600s, cap 1800s). --window/--display (with --source mac-screen) record one window/display"),
|
|
2554
|
+
cmdDoc("record", "clipy record --url <url> [--for sec] [--viewports list] [--title t] [--type kind] [--note '12: text']… [--wait] [--json]", "Headless one-shot capture of a web app; notes become the transcript. Notes are absolute ('12: text') or pass-scoped ('pass2: text' / 'pass2@5: text', anchored to a --viewports pass's real start; a malformed pass note is rejected). --type declares the recording kind (bug_report|feature_request|product_demo|walkthrough_tutorial|feedback_review|discussion_talk|other, plus aliases bug/feature/demo/walkthrough/feedback/discussion) so the AI summary reads it correctly. With --source mac-screen: records the real screen via the Clipy Mac app (--type not yet applied on mac); --window '<title|app|id>' or --display <id> target one window/display (ids from clipy sources)", ["--for", "--viewports", "--title", "--description", "--type", "--note", "--width", "--height", "--wait", "--source", "--window", "--display"]),
|
|
2555
|
+
cmdDoc("session", "clipy session <start|stop|abort|status> [--url <url>] [--max sec] [--type kind] [--source web|mac-screen] [--window w] [--display d] [--expose-cdp]", "Background recording session; auto-stops + uploads at --max (default 600s, cap 1800s). --type sets the recording kind (see record). --window/--display (with --source mac-screen) record one window/display. --expose-cdp (web sessions) opens a CDP endpoint (cdpUrl/cdpHttpUrl in the state file + session start/status output) so your own tools can drive the page while it records; OFF by default (any local process could attach), and CLIPY_DISABLE_CDP=1 forces it off", ["--url", "--max", "--type", "--source", "--window", "--display", "--expose-cdp"]),
|
|
1903
2556
|
cmdDoc("mark", "clipy mark \"<text>\"", "Drop a live-timestamped note into the active session"),
|
|
2557
|
+
cmdDoc("doctor", "clipy doctor [--json]", "One-shot health check: API key + whoami round-trip, Mac agent bridge (exists/parses/pid/appVersion>=" + MIN_BRIDGE_APP_VERSION + "), Playwright resolvability (and where it resolved from), and install mode (npx/global/local) — each a pass/warn/fail with a fix hint; exits non-zero if any check fails"),
|
|
1904
2558
|
cmdDoc("sources", "clipy sources [--json]", "List displays + windows the Clipy Mac app can capture — ids feed --window/--display"),
|
|
1905
2559
|
cmdDoc("agents", "clipy agents <status|install|uninstall> <claude|codex|cursor>", "Install the bundled Clipy skill for a coding agent; install triggers a browser login first when no key is configured (interactive terminals only)"),
|
|
1906
2560
|
cmdDoc("guide", "clipy guide --json", "This manifest"),
|
|
@@ -1911,6 +2565,11 @@ function cmdGuide(json) {
|
|
|
1911
2565
|
"login opens a browser to approve this device (loopback redirect to 127.0.0.1); use --key/--paste or a piped key on headless boxes.",
|
|
1912
2566
|
"record/session/mark/transcript --replace are the only write commands; they need a key with the 'ingest' permission.",
|
|
1913
2567
|
"Headless captures have no audio: --note flags and session marks become the transcript, labeled agent-narration.",
|
|
2568
|
+
"--note is absolute ('12: text') or pass-scoped ('pass2: text' / 'pass2@5: text'); pass-scoped notes anchor to the real start of a --viewports pass, so they don't drift when load time shifts the pass boundaries. A malformed pass note (e.g. 'pass2 text' with no colon) is a usage error, not silently demoted.",
|
|
2569
|
+
"--type declares what a recording IS (bug_report/feature_request/product_demo/walkthrough_tutorial/feedback_review/discussion_talk/other, plus short aliases) so the AI summary doesn't misread a demo as a bug report. Applied on web today; --source mac-screen support is pending a Clipy app update.",
|
|
2570
|
+
"session --expose-cdp (web, opt-in) publishes a CDP endpoint (cdpHttpUrl) in `session start`/`session status` output and the 0600 session state file; connect with playwright.connectOverCDP() to drive the recorded page. Off by default (any local process could attach); CLIPY_DISABLE_CDP=1 forces it off.",
|
|
2571
|
+
"clipy record gates its capture clock on the first non-blank frame (up to a 10s cap, then starts anyway) so notes aren't anchored to a still-compiling t=0.",
|
|
2572
|
+
"Run `clipy doctor` first when record/session or --source mac-screen fails — it names the exact missing piece (key, bridge socket/handshake/version, Playwright, install mode).",
|
|
1914
2573
|
"Public recordings have an unauthenticated context document at https://clipy.online/video/<id>.md.",
|
|
1915
2574
|
],
|
|
1916
2575
|
});
|
|
@@ -1993,6 +2652,8 @@ async function main() {
|
|
|
1993
2652
|
source: { type: "string" },
|
|
1994
2653
|
window: { type: "string" },
|
|
1995
2654
|
display: { type: "string" },
|
|
2655
|
+
type: { type: "string" },
|
|
2656
|
+
"expose-cdp": { type: "boolean", default: false },
|
|
1996
2657
|
width: { type: "string" },
|
|
1997
2658
|
height: { type: "string" },
|
|
1998
2659
|
wait: { type: "boolean", default: false },
|
|
@@ -2108,6 +2769,9 @@ async function main() {
|
|
|
2108
2769
|
case "mcp":
|
|
2109
2770
|
cmdMcp();
|
|
2110
2771
|
return;
|
|
2772
|
+
case "doctor":
|
|
2773
|
+
await cmdDoctor(ctx, json);
|
|
2774
|
+
return;
|
|
2111
2775
|
case "agents":
|
|
2112
2776
|
await cmdAgents(ctx, rest[0], rest[1], json);
|
|
2113
2777
|
return;
|
|
@@ -2148,6 +2812,7 @@ async function main() {
|
|
|
2148
2812
|
if (values.window && values.display) {
|
|
2149
2813
|
die("--window and --display are mutually exclusive — pick one capture source", 2);
|
|
2150
2814
|
}
|
|
2815
|
+
const recordingKind = values.type ? requireRecordingKind(String(values.type)) : undefined;
|
|
2151
2816
|
if (source === "mac-screen") {
|
|
2152
2817
|
const noteFlags = values.note ?? [];
|
|
2153
2818
|
const forSec = num(values.for, 15);
|
|
@@ -2162,6 +2827,7 @@ async function main() {
|
|
|
2162
2827
|
name: (values.title ?? values.name)?.trim() ||
|
|
2163
2828
|
undefined,
|
|
2164
2829
|
description: values.description?.trim() || undefined,
|
|
2830
|
+
recordingKind,
|
|
2165
2831
|
window: values.window?.trim() || undefined,
|
|
2166
2832
|
display: values.display?.trim() || undefined,
|
|
2167
2833
|
notes: noteFlags.map(parseNoteFlag),
|
|
@@ -2194,6 +2860,7 @@ async function main() {
|
|
|
2194
2860
|
name: (values.title ?? values.name)?.trim() ||
|
|
2195
2861
|
undefined,
|
|
2196
2862
|
description: values.description?.trim() || undefined,
|
|
2863
|
+
recordingKind,
|
|
2197
2864
|
notes: noteFlags.map(parseNoteFlag),
|
|
2198
2865
|
viewports: values.viewports ? parseViewports(String(values.viewports)) : null,
|
|
2199
2866
|
width: num(values.width, 1280),
|
|
@@ -2227,11 +2894,13 @@ async function main() {
|
|
|
2227
2894
|
name: (values.title ?? values.name)?.trim() ||
|
|
2228
2895
|
undefined,
|
|
2229
2896
|
description: values.description?.trim() || undefined,
|
|
2897
|
+
recordingKind: values.type ? requireRecordingKind(String(values.type)) : undefined,
|
|
2230
2898
|
maxSec: num(values.max, SESSION_DEFAULT_MAX_SEC),
|
|
2231
2899
|
width: num(values.width, 1280),
|
|
2232
2900
|
height: num(values.height, 720),
|
|
2233
2901
|
json,
|
|
2234
2902
|
source,
|
|
2903
|
+
exposeCdp: Boolean(values["expose-cdp"]),
|
|
2235
2904
|
});
|
|
2236
2905
|
return;
|
|
2237
2906
|
}
|