pindrop 0.1.4 → 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 CHANGED
@@ -3,9 +3,11 @@ 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,
@@ -16,7 +18,7 @@ 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.4";
21
+ const VERSION = "0.1.5";
20
22
 
21
23
  function parseArgv(argv) {
22
24
  const positionals = [];
@@ -131,6 +133,10 @@ function announceBrowserAuth(url) {
131
133
  process.stderr.write(`If it didn't open, visit:\n${url}\n`);
132
134
  }
133
135
 
136
+ function announcePairingWait() {
137
+ process.stderr.write(`Approve PinDrop in your open browser tab…\n`);
138
+ }
139
+
134
140
  function parsePinNumber(raw) {
135
141
  const cleaned = String(raw || "").replace(/^#/, "");
136
142
  const n = Number(cleaned);
@@ -258,6 +264,7 @@ export async function runCli(argv = process.argv.slice(2)) {
258
264
  const autoLogin = !flags["no-login"];
259
265
  const openBrowser = !flags["no-browser"];
260
266
  const asJson = Boolean(flags.json);
267
+ const pairId = flagStr(flags, "pair");
261
268
 
262
269
  switch (cmd) {
263
270
  case "login": {
@@ -268,6 +275,18 @@ export async function runCli(argv = process.argv.slice(2)) {
268
275
  else process.stdout.write(`Saved API key for ${mcpUrl}\n`);
269
276
  return 0;
270
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
+ }
271
290
  await loginWithBrowser({
272
291
  mcpUrl,
273
292
  openBrowser,
@@ -322,11 +341,21 @@ export async function runCli(argv = process.argv.slice(2)) {
322
341
  });
323
342
 
324
343
  if (!targetUrl) {
325
- await loginWithBrowser({
326
- mcpUrl,
327
- openBrowser,
328
- onAuthorizeUrl: announceBrowserAuth,
329
- });
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
+ }
330
359
  if (asJson) {
331
360
  printJson({ ok: true, connected: true, skills: skillResults, project: null });
332
361
  } else {
@@ -348,6 +377,9 @@ export async function runCli(argv = process.argv.slice(2)) {
348
377
  args: { targetUrl, ...(title ? { title } : {}) },
349
378
  autoLogin,
350
379
  openBrowser,
380
+ pairId,
381
+ targetUrl,
382
+ onPairingWaiting: announcePairingWait,
351
383
  onAuthorizeUrl: announceBrowserAuth,
352
384
  });
353
385
  const p = res.structured || {};
@@ -357,6 +389,18 @@ export async function runCli(argv = process.argv.slice(2)) {
357
389
  shareUrl: p.shareUrl,
358
390
  targetUrl: p.targetUrl || targetUrl,
359
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
+ }
360
404
  }
361
405
  const shouldOpen = Boolean((flags.open || p.isFirstProject) && openBrowser && p.shareUrl);
362
406
  if (shouldOpen) openInBrowser(p.shareUrl);
@@ -435,6 +479,9 @@ export async function runCli(argv = process.argv.slice(2)) {
435
479
  args: { targetUrl, ...(title ? { title } : {}) },
436
480
  autoLogin,
437
481
  openBrowser,
482
+ pairId,
483
+ targetUrl,
484
+ onPairingWaiting: announcePairingWait,
438
485
  onAuthorizeUrl: announceBrowserAuth,
439
486
  });
440
487
  const p = res.structured || {};
@@ -444,6 +491,18 @@ export async function runCli(argv = process.argv.slice(2)) {
444
491
  shareUrl: p.shareUrl,
445
492
  targetUrl: p.targetUrl || targetUrl,
446
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
+ }
447
506
  }
448
507
  const shouldOpen = Boolean((flags.open || p.isFirstProject) && openBrowser && p.shareUrl);
449
508
  if (shouldOpen) openInBrowser(p.shareUrl);
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.4",
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
- const auth = await resolveBearerToken({
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 res = await postMcp(mcpUrl, auth.token, toolName, args, fetchImpl);
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
- res = await postMcp(mcpUrl, refreshed.accessToken, toolName, args, fetchImpl);
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 !== auth.token) {
95
- res = await postMcp(mcpUrl, fresh.token, toolName, args, fetchImpl);
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,6 +150,8 @@ 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
  }
142
157
 
@@ -156,7 +171,7 @@ export async function callSandboxApi({
156
171
  headers: {
157
172
  Accept: "application/json",
158
173
  Authorization: `Sandbox ${claimCode}`,
159
- "User-Agent": "pindrop-cli/0.1.4",
174
+ "User-Agent": "pindrop-cli/0.1.5",
160
175
  ...(body !== undefined ? { "Content-Type": "application/json" } : {}),
161
176
  },
162
177
  ...(body !== undefined ? { body: JSON.stringify(body) } : {}),
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.4",
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": {