pindrop 0.1.3 → 0.1.5
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/cli.mjs +222 -26
- package/lib/auth.mjs +200 -6
- package/lib/client.mjs +64 -6
- package/lib/skill.mjs +16 -0
- package/package.json +1 -1
package/cli.mjs
CHANGED
|
@@ -3,20 +3,22 @@ import { mkdirSync, realpathSync, writeFileSync } from "node:fs";
|
|
|
3
3
|
import { dirname, join, resolve } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import {
|
|
6
|
+
completePairing,
|
|
6
7
|
getLinkedProject,
|
|
7
8
|
getSavedProfile,
|
|
8
9
|
loginWithBrowser,
|
|
10
|
+
loginWithPairing,
|
|
9
11
|
openInBrowser,
|
|
10
12
|
resolveMcpUrl,
|
|
11
13
|
revokeAndLogout,
|
|
12
14
|
saveApiKeyProfile,
|
|
13
15
|
saveLinkedProject,
|
|
14
16
|
} from "./lib/auth.mjs";
|
|
15
|
-
import { CliError, callPinDropTool } from "./lib/client.mjs";
|
|
17
|
+
import { CliError, callPinDropTool, callSandboxApi } from "./lib/client.mjs";
|
|
16
18
|
import { inferProjectHint, inferSiteUrl } from "./lib/project.mjs";
|
|
17
19
|
import { installSkillFiles } from "./lib/skill.mjs";
|
|
18
20
|
|
|
19
|
-
const VERSION = "0.1.
|
|
21
|
+
const VERSION = "0.1.5";
|
|
20
22
|
|
|
21
23
|
function parseArgv(argv) {
|
|
22
24
|
const positionals = [];
|
|
@@ -30,6 +32,9 @@ function parseArgv(argv) {
|
|
|
30
32
|
"full",
|
|
31
33
|
"resolved",
|
|
32
34
|
"open",
|
|
35
|
+
"watch",
|
|
36
|
+
"w",
|
|
37
|
+
"once",
|
|
33
38
|
"no-browser",
|
|
34
39
|
"no-login",
|
|
35
40
|
"force",
|
|
@@ -128,6 +133,10 @@ function announceBrowserAuth(url) {
|
|
|
128
133
|
process.stderr.write(`If it didn't open, visit:\n${url}\n`);
|
|
129
134
|
}
|
|
130
135
|
|
|
136
|
+
function announcePairingWait() {
|
|
137
|
+
process.stderr.write(`Approve PinDrop in your open browser tab…\n`);
|
|
138
|
+
}
|
|
139
|
+
|
|
131
140
|
function parsePinNumber(raw) {
|
|
132
141
|
const cleaned = String(raw || "").replace(/^#/, "");
|
|
133
142
|
const n = Number(cleaned);
|
|
@@ -206,10 +215,10 @@ Usage:
|
|
|
206
215
|
pindrop status Show connected account, plan, and limits
|
|
207
216
|
|
|
208
217
|
pindrop projects List active PinDrop projects
|
|
209
|
-
pindrop create [url] [--
|
|
218
|
+
pindrop create [url] [--open] Create (or reuse) a review link for a live URL
|
|
210
219
|
pindrop open [n] [--project <id>] Open the review link (or pin #n) in your browser
|
|
211
|
-
pindrop pins [--project <id>] [--resolved] [--full] [--json]
|
|
212
|
-
List pins for this repo
|
|
220
|
+
pindrop pins [--watch] [--once] [--project <id>] [--resolved] [--full] [--json]
|
|
221
|
+
List (or live-watch) pins for this repo
|
|
213
222
|
pindrop pin <n> [--screenshot [path]] [--project <id>] [--json]
|
|
214
223
|
Read full context (and optionally save screenshot)
|
|
215
224
|
pindrop comment <n> --body <text> Reply on a pin
|
|
@@ -221,8 +230,10 @@ Usage:
|
|
|
221
230
|
pindrop delete <n> Soft-delete a pin
|
|
222
231
|
pindrop drop --path <p> --x <n> --y <n> --vw <n> --comment <text>
|
|
223
232
|
Drop a new pin from measured coordinates
|
|
224
|
-
pindrop sandbox
|
|
225
|
-
|
|
233
|
+
pindrop sandbox pins <id> <code> List open pins on a /try sandbox (no signup)
|
|
234
|
+
pindrop sandbox resolve <id> <code> <n> --new-text <text>
|
|
235
|
+
Resolve a /try sandbox pin live (no signup)
|
|
236
|
+
pindrop sandbox claim <id> <code> Claim a /try sandbox into your PinDrop account
|
|
226
237
|
pindrop billing [--action trial|upgrade|manage] [--plan pro|studio]
|
|
227
238
|
Get a secure browser checkout/billing link
|
|
228
239
|
pindrop skill install [--global|--local] [--agent <id>] [--force]
|
|
@@ -253,6 +264,7 @@ export async function runCli(argv = process.argv.slice(2)) {
|
|
|
253
264
|
const autoLogin = !flags["no-login"];
|
|
254
265
|
const openBrowser = !flags["no-browser"];
|
|
255
266
|
const asJson = Boolean(flags.json);
|
|
267
|
+
const pairId = flagStr(flags, "pair");
|
|
256
268
|
|
|
257
269
|
switch (cmd) {
|
|
258
270
|
case "login": {
|
|
@@ -263,6 +275,18 @@ export async function runCli(argv = process.argv.slice(2)) {
|
|
|
263
275
|
else process.stdout.write(`Saved API key for ${mcpUrl}\n`);
|
|
264
276
|
return 0;
|
|
265
277
|
}
|
|
278
|
+
if (pairId) {
|
|
279
|
+
const paired = await loginWithPairing({
|
|
280
|
+
mcpUrl,
|
|
281
|
+
pairId,
|
|
282
|
+
onWaiting: announcePairingWait,
|
|
283
|
+
});
|
|
284
|
+
if (paired?.token) {
|
|
285
|
+
if (asJson) printJson({ ok: true, mode: "paired", mcpUrl });
|
|
286
|
+
else process.stdout.write(`Connected to PinDrop (${mcpUrl})\n`);
|
|
287
|
+
return 0;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
266
290
|
await loginWithBrowser({
|
|
267
291
|
mcpUrl,
|
|
268
292
|
openBrowser,
|
|
@@ -317,11 +341,21 @@ export async function runCli(argv = process.argv.slice(2)) {
|
|
|
317
341
|
});
|
|
318
342
|
|
|
319
343
|
if (!targetUrl) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
344
|
+
let paired = null;
|
|
345
|
+
if (pairId) {
|
|
346
|
+
paired = await loginWithPairing({
|
|
347
|
+
mcpUrl,
|
|
348
|
+
pairId,
|
|
349
|
+
onWaiting: announcePairingWait,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
if (!paired?.token) {
|
|
353
|
+
await loginWithBrowser({
|
|
354
|
+
mcpUrl,
|
|
355
|
+
openBrowser,
|
|
356
|
+
onAuthorizeUrl: announceBrowserAuth,
|
|
357
|
+
});
|
|
358
|
+
}
|
|
325
359
|
if (asJson) {
|
|
326
360
|
printJson({ ok: true, connected: true, skills: skillResults, project: null });
|
|
327
361
|
} else {
|
|
@@ -343,6 +377,9 @@ export async function runCli(argv = process.argv.slice(2)) {
|
|
|
343
377
|
args: { targetUrl, ...(title ? { title } : {}) },
|
|
344
378
|
autoLogin,
|
|
345
379
|
openBrowser,
|
|
380
|
+
pairId,
|
|
381
|
+
targetUrl,
|
|
382
|
+
onPairingWaiting: announcePairingWait,
|
|
346
383
|
onAuthorizeUrl: announceBrowserAuth,
|
|
347
384
|
});
|
|
348
385
|
const p = res.structured || {};
|
|
@@ -352,11 +389,26 @@ export async function runCli(argv = process.argv.slice(2)) {
|
|
|
352
389
|
shareUrl: p.shareUrl,
|
|
353
390
|
targetUrl: p.targetUrl || targetUrl,
|
|
354
391
|
});
|
|
392
|
+
if (pairId && p.shareUrl) {
|
|
393
|
+
await completePairing({
|
|
394
|
+
mcpUrl,
|
|
395
|
+
pairId,
|
|
396
|
+
cliSecret: res.cliSecret,
|
|
397
|
+
token: res.authToken,
|
|
398
|
+
projectId: p.projectId,
|
|
399
|
+
shareUrl: p.shareUrl,
|
|
400
|
+
targetUrl: p.targetUrl || targetUrl,
|
|
401
|
+
projectTitle: p.title || title,
|
|
402
|
+
});
|
|
403
|
+
}
|
|
355
404
|
}
|
|
405
|
+
const shouldOpen = Boolean((flags.open || p.isFirstProject) && openBrowser && p.shareUrl);
|
|
406
|
+
if (shouldOpen) openInBrowser(p.shareUrl);
|
|
356
407
|
if (asJson) {
|
|
357
408
|
printJson({
|
|
358
409
|
ok: true,
|
|
359
410
|
inferredFrom,
|
|
411
|
+
opened: shouldOpen,
|
|
360
412
|
skills: skillResults,
|
|
361
413
|
project: res.structured,
|
|
362
414
|
});
|
|
@@ -366,6 +418,7 @@ export async function runCli(argv = process.argv.slice(2)) {
|
|
|
366
418
|
}
|
|
367
419
|
process.stdout.write(`Review link: ${p.shareUrl || res.text}\n`);
|
|
368
420
|
if (p.projectId) process.stdout.write(`Project ID: ${p.projectId}\n`);
|
|
421
|
+
if (shouldOpen) process.stderr.write(`Opened review link in your browser.\n`);
|
|
369
422
|
for (const r of skillResults) {
|
|
370
423
|
if (r.status === "installed") {
|
|
371
424
|
process.stdout.write(`Installed skill: ${r.path}\n`);
|
|
@@ -426,6 +479,9 @@ export async function runCli(argv = process.argv.slice(2)) {
|
|
|
426
479
|
args: { targetUrl, ...(title ? { title } : {}) },
|
|
427
480
|
autoLogin,
|
|
428
481
|
openBrowser,
|
|
482
|
+
pairId,
|
|
483
|
+
targetUrl,
|
|
484
|
+
onPairingWaiting: announcePairingWait,
|
|
429
485
|
onAuthorizeUrl: announceBrowserAuth,
|
|
430
486
|
});
|
|
431
487
|
const p = res.structured || {};
|
|
@@ -435,15 +491,34 @@ export async function runCli(argv = process.argv.slice(2)) {
|
|
|
435
491
|
shareUrl: p.shareUrl,
|
|
436
492
|
targetUrl: p.targetUrl || targetUrl,
|
|
437
493
|
});
|
|
494
|
+
if (pairId && p.shareUrl) {
|
|
495
|
+
await completePairing({
|
|
496
|
+
mcpUrl,
|
|
497
|
+
pairId,
|
|
498
|
+
cliSecret: res.cliSecret,
|
|
499
|
+
token: res.authToken,
|
|
500
|
+
projectId: p.projectId,
|
|
501
|
+
shareUrl: p.shareUrl,
|
|
502
|
+
targetUrl: p.targetUrl || targetUrl,
|
|
503
|
+
projectTitle: p.title || title,
|
|
504
|
+
});
|
|
505
|
+
}
|
|
438
506
|
}
|
|
507
|
+
const shouldOpen = Boolean((flags.open || p.isFirstProject) && openBrowser && p.shareUrl);
|
|
508
|
+
if (shouldOpen) openInBrowser(p.shareUrl);
|
|
439
509
|
if (asJson) {
|
|
440
|
-
printJson({
|
|
510
|
+
printJson({
|
|
511
|
+
...(res.structured || {}),
|
|
512
|
+
...(inferredFrom ? { inferredFrom } : {}),
|
|
513
|
+
...(shouldOpen ? { opened: true } : {}),
|
|
514
|
+
});
|
|
441
515
|
} else {
|
|
442
516
|
if (inferredFrom) {
|
|
443
517
|
process.stderr.write(`Detected site URL ${targetUrl} from ${inferredFrom}\n`);
|
|
444
518
|
}
|
|
445
519
|
process.stdout.write(`Review link: ${p.shareUrl || res.text}\n`);
|
|
446
520
|
if (p.projectId) process.stdout.write(`Project ID: ${p.projectId}\n`);
|
|
521
|
+
if (shouldOpen) process.stderr.write(`Opened review link in your browser.\n`);
|
|
447
522
|
if (p.wasReused) process.stdout.write(`Reused existing project for ${p.targetUrl || targetUrl}\n`);
|
|
448
523
|
writeProjectNextSteps(p.projectId);
|
|
449
524
|
}
|
|
@@ -500,6 +575,73 @@ export async function runCli(argv = process.argv.slice(2)) {
|
|
|
500
575
|
...(flagStr(flags, "path") ? { path: flagStr(flags, "path") } : {}),
|
|
501
576
|
...(flagStr(flags, "priority") ? { priority: flagStr(flags, "priority") } : {}),
|
|
502
577
|
};
|
|
578
|
+
if (flags.watch || flags.w) {
|
|
579
|
+
const intervalSec = Math.max(1, flagNum(flags, "interval") ?? 3);
|
|
580
|
+
const once = Boolean(flags.once);
|
|
581
|
+
const seen = new Map();
|
|
582
|
+
let stopped = false;
|
|
583
|
+
const stop = () => {
|
|
584
|
+
stopped = true;
|
|
585
|
+
};
|
|
586
|
+
process.on("SIGINT", stop);
|
|
587
|
+
process.on("SIGTERM", stop);
|
|
588
|
+
process.stderr.write(
|
|
589
|
+
`Watching ${projectId || hint || "PinDrop"} for pins (every ${intervalSec}s; Ctrl+C to stop)…\n`,
|
|
590
|
+
);
|
|
591
|
+
try {
|
|
592
|
+
while (!stopped) {
|
|
593
|
+
const res = await callPinDropTool({
|
|
594
|
+
mcpUrl,
|
|
595
|
+
toolName,
|
|
596
|
+
args,
|
|
597
|
+
autoLogin,
|
|
598
|
+
openBrowser,
|
|
599
|
+
onAuthorizeUrl: announceBrowserAuth,
|
|
600
|
+
});
|
|
601
|
+
const s = res.structured || {};
|
|
602
|
+
if (s.scope === "unmatched" && Array.isArray(s.candidates) && s.candidates.length > 0) {
|
|
603
|
+
process.stderr.write("No project matched this folder. Pass --project <id>:\n");
|
|
604
|
+
for (const c of s.candidates) {
|
|
605
|
+
process.stderr.write(` ${c.id} · ${c.title || c.targetUrl} (${c.targetUrl})\n`);
|
|
606
|
+
}
|
|
607
|
+
return 3;
|
|
608
|
+
}
|
|
609
|
+
const pins = Array.isArray(s.pins) ? s.pins : [];
|
|
610
|
+
const changed = [];
|
|
611
|
+
for (const pin of pins) {
|
|
612
|
+
const key = String(pin.pinNumber ?? pin.number ?? pin.id ?? "");
|
|
613
|
+
const fp = JSON.stringify([
|
|
614
|
+
pin.status,
|
|
615
|
+
pin.comment,
|
|
616
|
+
Array.isArray(pin.thread) ? pin.thread.length : 0,
|
|
617
|
+
]);
|
|
618
|
+
if (seen.get(key) !== fp) {
|
|
619
|
+
seen.set(key, fp);
|
|
620
|
+
changed.push(pin);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
if (changed.length > 0) {
|
|
624
|
+
if (asJson) {
|
|
625
|
+
for (const pin of changed) {
|
|
626
|
+
process.stdout.write(JSON.stringify(pin) + "\n");
|
|
627
|
+
}
|
|
628
|
+
} else {
|
|
629
|
+
for (const pin of changed) {
|
|
630
|
+
process.stdout.write(formatPinCompact(pin) + "\n");
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
if (once) return 0;
|
|
634
|
+
}
|
|
635
|
+
if (stopped) break;
|
|
636
|
+
await new Promise((r) => setTimeout(r, intervalSec * 1000));
|
|
637
|
+
}
|
|
638
|
+
} finally {
|
|
639
|
+
process.off("SIGINT", stop);
|
|
640
|
+
process.off("SIGTERM", stop);
|
|
641
|
+
}
|
|
642
|
+
return 0;
|
|
643
|
+
}
|
|
644
|
+
|
|
503
645
|
const res = await callPinDropTool({
|
|
504
646
|
mcpUrl,
|
|
505
647
|
toolName,
|
|
@@ -735,20 +877,74 @@ export async function runCli(argv = process.argv.slice(2)) {
|
|
|
735
877
|
|
|
736
878
|
case "sandbox": {
|
|
737
879
|
const sub = positionals[1];
|
|
738
|
-
if (sub
|
|
739
|
-
|
|
880
|
+
if (sub === "pins") {
|
|
881
|
+
const projectId = positionals[2] || flagStr(flags, "project", "p");
|
|
882
|
+
const claimCode = positionals[3] || flagStr(flags, "claim-code", "code");
|
|
883
|
+
if (!projectId || !claimCode) {
|
|
884
|
+
throw new CliError("Usage: pindrop sandbox pins <projectId> <claimCode> [--json]", 1);
|
|
885
|
+
}
|
|
886
|
+
const data = await callSandboxApi({
|
|
887
|
+
mcpUrl,
|
|
888
|
+
method: "GET",
|
|
889
|
+
path: `/api/v1/sandbox/pins?project=${encodeURIComponent(projectId)}`,
|
|
890
|
+
claimCode,
|
|
891
|
+
});
|
|
892
|
+
if (asJson) {
|
|
893
|
+
printJson(data);
|
|
894
|
+
} else {
|
|
895
|
+
const pins = Array.isArray(data?.pins) ? data.pins : [];
|
|
896
|
+
if (pins.length === 0) process.stdout.write("No open pins.\n");
|
|
897
|
+
else for (const pin of pins) process.stdout.write(formatPinCompact(pin) + "\n");
|
|
898
|
+
}
|
|
899
|
+
return 0;
|
|
740
900
|
}
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
901
|
+
if (sub === "resolve") {
|
|
902
|
+
const projectId = positionals[2] || flagStr(flags, "project", "p");
|
|
903
|
+
const claimCode = positionals[3] || flagStr(flags, "claim-code", "code");
|
|
904
|
+
const pinNumber = parsePinNumber(positionals[4]);
|
|
905
|
+
const newText = flagStr(flags, "new-text", "newText");
|
|
906
|
+
const comment = flagStr(flags, "comment", "c", "m");
|
|
907
|
+
const authorName = flagStr(flags, "author") || process.env.PINDROP_AGENT_NAME;
|
|
908
|
+
if (!projectId || !claimCode) {
|
|
909
|
+
throw new CliError(
|
|
910
|
+
'Usage: pindrop sandbox resolve <projectId> <claimCode> <pinNumber> --new-text "<text>"',
|
|
911
|
+
1,
|
|
912
|
+
);
|
|
913
|
+
}
|
|
914
|
+
const data = await callSandboxApi({
|
|
915
|
+
mcpUrl,
|
|
916
|
+
method: "POST",
|
|
917
|
+
path: "/api/v1/sandbox/resolve",
|
|
918
|
+
claimCode,
|
|
919
|
+
body: {
|
|
920
|
+
projectId,
|
|
921
|
+
pinNumber,
|
|
922
|
+
...(newText ? { newText } : {}),
|
|
923
|
+
...(comment ? { comment } : {}),
|
|
924
|
+
...(authorName ? { authorName } : {}),
|
|
925
|
+
},
|
|
926
|
+
});
|
|
927
|
+
if (asJson) printJson(data);
|
|
928
|
+
else process.stdout.write(`${data?.pinShareUrl || `Resolved sandbox pin #${pinNumber}.`}\n`);
|
|
929
|
+
return 0;
|
|
930
|
+
}
|
|
931
|
+
if (sub === "claim" && positionals[2] && positionals[3]) {
|
|
932
|
+
const res = await callPinDropTool({
|
|
933
|
+
mcpUrl,
|
|
934
|
+
toolName: "pindrop_claim_sandbox",
|
|
935
|
+
args: { projectId: positionals[2], claimCode: positionals[3] },
|
|
936
|
+
autoLogin,
|
|
937
|
+
openBrowser,
|
|
938
|
+
onAuthorizeUrl: announceBrowserAuth,
|
|
939
|
+
});
|
|
940
|
+
if (asJson) printJson(res.structured ?? { text: res.text });
|
|
941
|
+
else process.stdout.write((res.text || `Claimed sandbox ${positionals[2]}`) + "\n");
|
|
942
|
+
return 0;
|
|
943
|
+
}
|
|
944
|
+
throw new CliError(
|
|
945
|
+
"Usage: pindrop sandbox <pins|resolve|claim> <projectId> <claimCode> [pinNumber]",
|
|
946
|
+
1,
|
|
947
|
+
);
|
|
752
948
|
}
|
|
753
949
|
|
|
754
950
|
case "billing": {
|
package/lib/auth.mjs
CHANGED
|
@@ -11,13 +11,48 @@ import {
|
|
|
11
11
|
} from "node:fs";
|
|
12
12
|
import { createServer } from "node:http";
|
|
13
13
|
import { homedir, platform } from "node:os";
|
|
14
|
-
import { dirname, join, resolve } from "node:path";
|
|
14
|
+
import { dirname, join, resolve, basename } from "node:path";
|
|
15
15
|
|
|
16
16
|
export const DEFAULT_MCP_URL = "https://mcp.pindrop.page";
|
|
17
17
|
const EXPIRY_BUFFER_MS = 60_000;
|
|
18
18
|
const LOGIN_TIMEOUT_MS = 180_000;
|
|
19
|
+
const PAIR_POLL_INTERVAL_MS = 1_000;
|
|
19
20
|
const FETCH_RETRY_DELAY_MS = 400;
|
|
20
21
|
|
|
22
|
+
export function detectAgentName(env = process.env) {
|
|
23
|
+
if (env.CLAUDECODE || env.CLAUDE_CODE_ENTRYPOINT || env.CLAUDE_CODE_SSE_PORT) {
|
|
24
|
+
return "Claude Code";
|
|
25
|
+
}
|
|
26
|
+
if (env.CODEX_SANDBOX || env.CODEX_THREAD_ID || env.CODEX_CI || env.OPENAI_CODEX) {
|
|
27
|
+
return "Codex";
|
|
28
|
+
}
|
|
29
|
+
if (env.CURSOR_AGENT || env.CURSOR_TRACE_ID || env.TERM_PROGRAM === "cursor") {
|
|
30
|
+
return "Cursor";
|
|
31
|
+
}
|
|
32
|
+
if (env.ANTIGRAVITY_AGENT || env.AGY_SESSION_ID) {
|
|
33
|
+
return "Antigravity";
|
|
34
|
+
}
|
|
35
|
+
if (env.GEMINI_CLI) {
|
|
36
|
+
return "Gemini CLI";
|
|
37
|
+
}
|
|
38
|
+
if (env.GROK_BUILD) {
|
|
39
|
+
return "Grok";
|
|
40
|
+
}
|
|
41
|
+
if (env.VSCODE_PID || env.TERM_PROGRAM === "vscode") {
|
|
42
|
+
return "VS Code";
|
|
43
|
+
}
|
|
44
|
+
return "PinDrop CLI";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function detectMachineLabel(cwd = process.cwd()) {
|
|
48
|
+
const folder = basename(resolve(cwd));
|
|
49
|
+
return folder && folder !== "/" ? folder : undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function pairBaseUrl(mcpUrl) {
|
|
53
|
+
return resolveMcpUrl(mcpUrl).replace(/\/mcp$/, "");
|
|
54
|
+
}
|
|
55
|
+
|
|
21
56
|
export async function fetchWithRetry(url, init, fetchImpl = fetch) {
|
|
22
57
|
let lastErr;
|
|
23
58
|
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
@@ -570,43 +605,202 @@ export async function revokeAndLogout(mcpUrl, fetchImpl = fetch) {
|
|
|
570
605
|
return clearProfile(mcpUrl);
|
|
571
606
|
}
|
|
572
607
|
|
|
608
|
+
export async function loginWithPairing({
|
|
609
|
+
mcpUrl,
|
|
610
|
+
pairId,
|
|
611
|
+
agentName = detectAgentName(),
|
|
612
|
+
machineLabel = detectMachineLabel(),
|
|
613
|
+
targetUrl,
|
|
614
|
+
timeoutMs = LOGIN_TIMEOUT_MS,
|
|
615
|
+
pollIntervalMs = PAIR_POLL_INTERVAL_MS,
|
|
616
|
+
onWaiting,
|
|
617
|
+
fetchImpl = fetch,
|
|
618
|
+
}) {
|
|
619
|
+
if (!pairId || typeof pairId !== "string") return null;
|
|
620
|
+
const cleanedPairId = pairId.trim();
|
|
621
|
+
if (!/^pair_[a-f0-9]{16}$/.test(cleanedPairId)) return null;
|
|
622
|
+
|
|
623
|
+
const base = pairBaseUrl(mcpUrl);
|
|
624
|
+
const cliSecret = randomBytes(16).toString("hex");
|
|
625
|
+
|
|
626
|
+
let connectResp;
|
|
627
|
+
try {
|
|
628
|
+
connectResp = await fetchWithRetry(
|
|
629
|
+
`${base}/api/v1/pair/connect`,
|
|
630
|
+
{
|
|
631
|
+
method: "POST",
|
|
632
|
+
headers: {
|
|
633
|
+
"Content-Type": "application/json",
|
|
634
|
+
Accept: "application/json",
|
|
635
|
+
},
|
|
636
|
+
body: JSON.stringify({
|
|
637
|
+
pairId: cleanedPairId,
|
|
638
|
+
cliSecret,
|
|
639
|
+
agentName,
|
|
640
|
+
...(machineLabel ? { machineLabel } : {}),
|
|
641
|
+
...(targetUrl ? { targetUrl } : {}),
|
|
642
|
+
}),
|
|
643
|
+
},
|
|
644
|
+
fetchImpl,
|
|
645
|
+
);
|
|
646
|
+
} catch {
|
|
647
|
+
return null;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
const connectData = await connectResp.json().catch(() => ({}));
|
|
651
|
+
if (!connectResp.ok || !connectData.ok) {
|
|
652
|
+
return null;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
onWaiting?.({ pairId: cleanedPairId, agentName, machineLabel });
|
|
656
|
+
|
|
657
|
+
const deadline = Date.now() + timeoutMs;
|
|
658
|
+
while (Date.now() < deadline) {
|
|
659
|
+
await new Promise((r) => setTimeout(r, pollIntervalMs));
|
|
660
|
+
let pollResp;
|
|
661
|
+
try {
|
|
662
|
+
pollResp = await fetchImpl(`${base}/api/v1/pair/poll`, {
|
|
663
|
+
method: "POST",
|
|
664
|
+
headers: {
|
|
665
|
+
"Content-Type": "application/json",
|
|
666
|
+
Accept: "application/json",
|
|
667
|
+
},
|
|
668
|
+
body: JSON.stringify({
|
|
669
|
+
pairId: cleanedPairId,
|
|
670
|
+
cliSecret,
|
|
671
|
+
}),
|
|
672
|
+
});
|
|
673
|
+
} catch {
|
|
674
|
+
continue;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
const pollData = await pollResp.json().catch(() => ({}));
|
|
678
|
+
if (pollData.status === "approved" && typeof pollData.token === "string") {
|
|
679
|
+
const profile = saveApiKeyProfile(mcpUrl, pollData.token);
|
|
680
|
+
return {
|
|
681
|
+
profile,
|
|
682
|
+
token: pollData.token,
|
|
683
|
+
cliSecret,
|
|
684
|
+
ownerEmail: pollData.ownerEmail ?? null,
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
if (pollData.status === "denied") {
|
|
688
|
+
throw new Error("Connection was canceled in your browser tab.");
|
|
689
|
+
}
|
|
690
|
+
if (
|
|
691
|
+
pollData.status === "expired" ||
|
|
692
|
+
pollData.status === "not_found" ||
|
|
693
|
+
pollData.status === "unauthorized" ||
|
|
694
|
+
pollData.status === "already_claimed"
|
|
695
|
+
) {
|
|
696
|
+
return null;
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
return null;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
export async function completePairing({
|
|
704
|
+
mcpUrl,
|
|
705
|
+
pairId,
|
|
706
|
+
cliSecret,
|
|
707
|
+
token,
|
|
708
|
+
agentName = detectAgentName(),
|
|
709
|
+
projectId,
|
|
710
|
+
shareUrl,
|
|
711
|
+
targetUrl,
|
|
712
|
+
projectTitle,
|
|
713
|
+
fetchImpl = fetch,
|
|
714
|
+
}) {
|
|
715
|
+
if (!pairId || !projectId || !shareUrl) return false;
|
|
716
|
+
const cleanedPairId = String(pairId).trim();
|
|
717
|
+
if (!/^pair_[a-f0-9]{16}$/.test(cleanedPairId)) return false;
|
|
718
|
+
|
|
719
|
+
const base = pairBaseUrl(mcpUrl);
|
|
720
|
+
const headers = {
|
|
721
|
+
"Content-Type": "application/json",
|
|
722
|
+
Accept: "application/json",
|
|
723
|
+
};
|
|
724
|
+
if (token) {
|
|
725
|
+
headers.Authorization = `Bearer ${token}`;
|
|
726
|
+
}
|
|
727
|
+
try {
|
|
728
|
+
const resp = await fetchImpl(`${base}/api/v1/pair/complete`, {
|
|
729
|
+
method: "POST",
|
|
730
|
+
headers,
|
|
731
|
+
body: JSON.stringify({
|
|
732
|
+
pairId: cleanedPairId,
|
|
733
|
+
...(cliSecret ? { cliSecret } : {}),
|
|
734
|
+
agentName,
|
|
735
|
+
projectId,
|
|
736
|
+
shareUrl,
|
|
737
|
+
...(targetUrl ? { targetUrl } : {}),
|
|
738
|
+
...(projectTitle ? { projectTitle } : {}),
|
|
739
|
+
}),
|
|
740
|
+
});
|
|
741
|
+
return resp.ok;
|
|
742
|
+
} catch {
|
|
743
|
+
return false;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
|
|
573
747
|
export async function resolveBearerToken({
|
|
574
748
|
mcpUrl,
|
|
575
749
|
autoLogin = false,
|
|
576
750
|
openBrowser = true,
|
|
751
|
+
pairId,
|
|
752
|
+
targetUrl,
|
|
753
|
+
onPairingWaiting,
|
|
577
754
|
onAuthorizeUrl,
|
|
578
755
|
fetchImpl = fetch,
|
|
579
756
|
}) {
|
|
580
757
|
const envKey = process.env.PINDROP_API_KEY?.trim();
|
|
581
758
|
if (envKey) {
|
|
582
|
-
return { token: envKey, source: "env", profile: null };
|
|
759
|
+
return { token: envKey, source: "env", profile: null, cliSecret: null };
|
|
583
760
|
}
|
|
584
761
|
|
|
585
762
|
const saved = getSavedProfile(mcpUrl);
|
|
586
763
|
if (saved?.type === "api_key" && saved.apiKey) {
|
|
587
|
-
return { token: saved.apiKey, source: "api_key", profile: saved };
|
|
764
|
+
return { token: saved.apiKey, source: "api_key", profile: saved, cliSecret: null };
|
|
588
765
|
}
|
|
589
766
|
|
|
590
767
|
if (saved?.type === "oauth" && saved.accessToken) {
|
|
591
768
|
const expired =
|
|
592
769
|
typeof saved.expiresAt === "number" && Date.now() + EXPIRY_BUFFER_MS >= saved.expiresAt;
|
|
593
770
|
if (!expired) {
|
|
594
|
-
return { token: saved.accessToken, source: "oauth", profile: saved };
|
|
771
|
+
return { token: saved.accessToken, source: "oauth", profile: saved, cliSecret: null };
|
|
595
772
|
}
|
|
596
773
|
const refreshed = await refreshSavedToken(mcpUrl, saved, fetchImpl);
|
|
597
774
|
if (refreshed?.accessToken) {
|
|
598
|
-
return { token: refreshed.accessToken, source: "oauth", profile: refreshed };
|
|
775
|
+
return { token: refreshed.accessToken, source: "oauth", profile: refreshed, cliSecret: null };
|
|
599
776
|
}
|
|
600
777
|
}
|
|
601
778
|
|
|
602
779
|
if (autoLogin) {
|
|
780
|
+
if (pairId) {
|
|
781
|
+
const paired = await loginWithPairing({
|
|
782
|
+
mcpUrl,
|
|
783
|
+
pairId,
|
|
784
|
+
targetUrl,
|
|
785
|
+
onWaiting: onPairingWaiting,
|
|
786
|
+
fetchImpl,
|
|
787
|
+
});
|
|
788
|
+
if (paired?.token) {
|
|
789
|
+
return {
|
|
790
|
+
token: paired.token,
|
|
791
|
+
source: "paired",
|
|
792
|
+
profile: paired.profile,
|
|
793
|
+
cliSecret: paired.cliSecret,
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
}
|
|
603
797
|
const loggedIn = await loginWithBrowser({
|
|
604
798
|
mcpUrl,
|
|
605
799
|
openBrowser,
|
|
606
800
|
onAuthorizeUrl,
|
|
607
801
|
fetchImpl,
|
|
608
802
|
});
|
|
609
|
-
return { token: loggedIn.accessToken, source: "oauth", profile: loggedIn };
|
|
803
|
+
return { token: loggedIn.accessToken, source: "oauth", profile: loggedIn, cliSecret: null };
|
|
610
804
|
}
|
|
611
805
|
|
|
612
806
|
return null;
|
package/lib/client.mjs
CHANGED
|
@@ -20,7 +20,7 @@ async function postMcp(mcpUrl, token, toolName, args, fetchImpl = fetch) {
|
|
|
20
20
|
"Content-Type": "application/json",
|
|
21
21
|
Accept: "application/json, text/event-stream",
|
|
22
22
|
Authorization: `Bearer ${token}`,
|
|
23
|
-
"User-Agent": "pindrop-cli/0.1.
|
|
23
|
+
"User-Agent": "pindrop-cli/0.1.5",
|
|
24
24
|
},
|
|
25
25
|
body: JSON.stringify({
|
|
26
26
|
jsonrpc: "2.0",
|
|
@@ -56,13 +56,19 @@ export async function callPinDropTool({
|
|
|
56
56
|
args = {},
|
|
57
57
|
autoLogin = false,
|
|
58
58
|
openBrowser = true,
|
|
59
|
+
pairId,
|
|
60
|
+
targetUrl,
|
|
61
|
+
onPairingWaiting,
|
|
59
62
|
onAuthorizeUrl,
|
|
60
63
|
fetchImpl = fetch,
|
|
61
64
|
}) {
|
|
62
|
-
|
|
65
|
+
let auth = await resolveBearerToken({
|
|
63
66
|
mcpUrl,
|
|
64
67
|
autoLogin,
|
|
65
68
|
openBrowser,
|
|
69
|
+
pairId,
|
|
70
|
+
targetUrl,
|
|
71
|
+
onPairingWaiting,
|
|
66
72
|
onAuthorizeUrl,
|
|
67
73
|
fetchImpl,
|
|
68
74
|
});
|
|
@@ -73,12 +79,14 @@ export async function callPinDropTool({
|
|
|
73
79
|
);
|
|
74
80
|
}
|
|
75
81
|
|
|
76
|
-
let
|
|
82
|
+
let activeToken = auth.token;
|
|
83
|
+
let res = await postMcp(mcpUrl, activeToken, toolName, args, fetchImpl);
|
|
77
84
|
|
|
78
85
|
if (res.status === 401 && auth.source === "oauth" && auth.profile) {
|
|
79
86
|
const refreshed = await refreshSavedToken(mcpUrl, auth.profile, fetchImpl);
|
|
80
87
|
if (refreshed?.accessToken) {
|
|
81
|
-
|
|
88
|
+
activeToken = refreshed.accessToken;
|
|
89
|
+
res = await postMcp(mcpUrl, activeToken, toolName, args, fetchImpl);
|
|
82
90
|
}
|
|
83
91
|
}
|
|
84
92
|
|
|
@@ -88,11 +96,16 @@ export async function callPinDropTool({
|
|
|
88
96
|
mcpUrl,
|
|
89
97
|
autoLogin: true,
|
|
90
98
|
openBrowser,
|
|
99
|
+
pairId,
|
|
100
|
+
targetUrl,
|
|
101
|
+
onPairingWaiting,
|
|
91
102
|
onAuthorizeUrl,
|
|
92
103
|
fetchImpl,
|
|
93
104
|
});
|
|
94
|
-
if (fresh?.token && fresh.token !==
|
|
95
|
-
|
|
105
|
+
if (fresh?.token && fresh.token !== activeToken) {
|
|
106
|
+
auth = fresh;
|
|
107
|
+
activeToken = fresh.token;
|
|
108
|
+
res = await postMcp(mcpUrl, activeToken, toolName, args, fetchImpl);
|
|
96
109
|
}
|
|
97
110
|
}
|
|
98
111
|
}
|
|
@@ -137,5 +150,50 @@ export async function callPinDropTool({
|
|
|
137
150
|
structured: result.structuredContent ?? null,
|
|
138
151
|
text: textBlocks.join("\n").trim(),
|
|
139
152
|
content: Array.isArray(result.content) ? result.content : [],
|
|
153
|
+
authToken: activeToken,
|
|
154
|
+
cliSecret: auth.cliSecret ?? null,
|
|
140
155
|
};
|
|
141
156
|
}
|
|
157
|
+
|
|
158
|
+
export async function callSandboxApi({
|
|
159
|
+
mcpUrl,
|
|
160
|
+
method,
|
|
161
|
+
path,
|
|
162
|
+
claimCode,
|
|
163
|
+
body,
|
|
164
|
+
fetchImpl = fetch,
|
|
165
|
+
}) {
|
|
166
|
+
const base = mcpUrl.replace(/\/mcp$/, "").replace(/\/+$/, "");
|
|
167
|
+
const response = await fetchWithRetry(
|
|
168
|
+
`${base}${path}`,
|
|
169
|
+
{
|
|
170
|
+
method,
|
|
171
|
+
headers: {
|
|
172
|
+
Accept: "application/json",
|
|
173
|
+
Authorization: `Sandbox ${claimCode}`,
|
|
174
|
+
"User-Agent": "pindrop-cli/0.1.5",
|
|
175
|
+
...(body !== undefined ? { "Content-Type": "application/json" } : {}),
|
|
176
|
+
},
|
|
177
|
+
...(body !== undefined ? { body: JSON.stringify(body) } : {}),
|
|
178
|
+
},
|
|
179
|
+
fetchImpl,
|
|
180
|
+
);
|
|
181
|
+
const text = await response.text();
|
|
182
|
+
let payload = null;
|
|
183
|
+
try {
|
|
184
|
+
payload = JSON.parse(text);
|
|
185
|
+
} catch {
|
|
186
|
+
payload = null;
|
|
187
|
+
}
|
|
188
|
+
if (!response.ok) {
|
|
189
|
+
const msg =
|
|
190
|
+
payload?.error?.message ||
|
|
191
|
+
payload?.error ||
|
|
192
|
+
`PinDrop sandbox request failed (${response.status}).`;
|
|
193
|
+
throw new CliError(
|
|
194
|
+
String(msg),
|
|
195
|
+
response.status === 401 ? 2 : response.status === 404 ? 3 : 1,
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
return payload;
|
|
199
|
+
}
|
package/lib/skill.mjs
CHANGED
|
@@ -30,6 +30,8 @@ export function resolveSkillTargets({
|
|
|
30
30
|
const claudeDir = join(home, ".claude");
|
|
31
31
|
const agentsDir = join(home, ".agents");
|
|
32
32
|
const codexDir = join(home, ".codex");
|
|
33
|
+
const cursorDir = join(home, ".cursor");
|
|
34
|
+
const geminiDir = join(home, ".gemini");
|
|
33
35
|
|
|
34
36
|
if (agent === "claude-code" || agent === "claude") {
|
|
35
37
|
targets.push({ label: "Claude Code", path: join(claudeDir, "skills", "pindrop", "SKILL.md") });
|
|
@@ -39,6 +41,14 @@ export function resolveSkillTargets({
|
|
|
39
41
|
targets.push({ label: "Codex", path: join(codexDir, "skills", "pindrop", "SKILL.md") });
|
|
40
42
|
return targets;
|
|
41
43
|
}
|
|
44
|
+
if (agent === "cursor") {
|
|
45
|
+
targets.push({ label: "Cursor", path: join(cursorDir, "skills", "pindrop", "SKILL.md") });
|
|
46
|
+
return targets;
|
|
47
|
+
}
|
|
48
|
+
if (agent === "gemini") {
|
|
49
|
+
targets.push({ label: "Gemini CLI", path: join(geminiDir, "skills", "pindrop", "SKILL.md") });
|
|
50
|
+
return targets;
|
|
51
|
+
}
|
|
42
52
|
if (agent === "agents") {
|
|
43
53
|
targets.push({ label: "Shared agents", path: join(agentsDir, "skills", "pindrop", "SKILL.md") });
|
|
44
54
|
return targets;
|
|
@@ -51,6 +61,12 @@ export function resolveSkillTargets({
|
|
|
51
61
|
if (existsSync(codexDir)) {
|
|
52
62
|
targets.push({ label: "Codex", path: join(codexDir, "skills", "pindrop", "SKILL.md") });
|
|
53
63
|
}
|
|
64
|
+
if (existsSync(cursorDir)) {
|
|
65
|
+
targets.push({ label: "Cursor", path: join(cursorDir, "skills", "pindrop", "SKILL.md") });
|
|
66
|
+
}
|
|
67
|
+
if (existsSync(geminiDir)) {
|
|
68
|
+
targets.push({ label: "Gemini CLI", path: join(geminiDir, "skills", "pindrop", "SKILL.md") });
|
|
69
|
+
}
|
|
54
70
|
targets.push({ label: "Shared agents", path: join(agentsDir, "skills", "pindrop", "SKILL.md") });
|
|
55
71
|
return targets;
|
|
56
72
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pindrop",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Zero-dependency CLI for PinDrop visual client feedback pins. Browser OAuth login, instant project creation, pin context & screenshots, and agent skill setup.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|