pindrop 0.0.0-stage → 0.1.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 +47 -2
- package/cli.mjs +753 -0
- package/lib/auth.mjs +520 -0
- package/lib/client.mjs +141 -0
- package/lib/project.mjs +148 -0
- package/lib/skill.mjs +87 -0
- package/package.json +34 -4
- package/skill/SKILL.md +55 -0
package/cli.mjs
ADDED
|
@@ -0,0 +1,753 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { mkdirSync, realpathSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join, resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import {
|
|
6
|
+
getSavedProfile,
|
|
7
|
+
loginWithBrowser,
|
|
8
|
+
resolveMcpUrl,
|
|
9
|
+
revokeAndLogout,
|
|
10
|
+
saveApiKeyProfile,
|
|
11
|
+
} from "./lib/auth.mjs";
|
|
12
|
+
import { CliError, callPinDropTool } from "./lib/client.mjs";
|
|
13
|
+
import { inferProjectHint, inferSiteUrl } from "./lib/project.mjs";
|
|
14
|
+
import { installSkillFiles } from "./lib/skill.mjs";
|
|
15
|
+
|
|
16
|
+
const VERSION = "0.1.0";
|
|
17
|
+
|
|
18
|
+
function parseArgv(argv) {
|
|
19
|
+
const positionals = [];
|
|
20
|
+
const flags = {};
|
|
21
|
+
const booleanFlags = new Set([
|
|
22
|
+
"help",
|
|
23
|
+
"h",
|
|
24
|
+
"version",
|
|
25
|
+
"v",
|
|
26
|
+
"json",
|
|
27
|
+
"full",
|
|
28
|
+
"resolved",
|
|
29
|
+
"open",
|
|
30
|
+
"no-browser",
|
|
31
|
+
"no-login",
|
|
32
|
+
"force",
|
|
33
|
+
"global",
|
|
34
|
+
"g",
|
|
35
|
+
"local",
|
|
36
|
+
"reopen",
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
40
|
+
const arg = argv[i];
|
|
41
|
+
if (arg === "--") {
|
|
42
|
+
positionals.push(...argv.slice(i + 1));
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
if (arg.startsWith("--")) {
|
|
46
|
+
const eq = arg.indexOf("=");
|
|
47
|
+
if (eq !== -1) {
|
|
48
|
+
flags[arg.slice(2, eq)] = arg.slice(eq + 1);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const key = arg.slice(2);
|
|
52
|
+
if (booleanFlags.has(key)) {
|
|
53
|
+
flags[key] = true;
|
|
54
|
+
} else if (key === "screenshot") {
|
|
55
|
+
const next = argv[i + 1];
|
|
56
|
+
if (next && !next.startsWith("-")) {
|
|
57
|
+
flags[key] = next;
|
|
58
|
+
i += 1;
|
|
59
|
+
} else {
|
|
60
|
+
flags[key] = true;
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
const next = argv[i + 1];
|
|
64
|
+
if (next === undefined) {
|
|
65
|
+
throw new CliError(`Missing value for --${key}`, 1);
|
|
66
|
+
}
|
|
67
|
+
flags[key] = next;
|
|
68
|
+
i += 1;
|
|
69
|
+
}
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (arg.startsWith("-") && arg.length === 2) {
|
|
73
|
+
const key = arg.slice(1);
|
|
74
|
+
if (booleanFlags.has(key)) {
|
|
75
|
+
flags[key] = true;
|
|
76
|
+
} else {
|
|
77
|
+
const next = argv[i + 1];
|
|
78
|
+
if (next === undefined) {
|
|
79
|
+
throw new CliError(`Missing value for -${key}`, 1);
|
|
80
|
+
}
|
|
81
|
+
flags[key] = next;
|
|
82
|
+
i += 1;
|
|
83
|
+
}
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
positionals.push(arg);
|
|
87
|
+
}
|
|
88
|
+
return { positionals, flags };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function flagStr(flags, ...names) {
|
|
92
|
+
for (const name of names) {
|
|
93
|
+
const v = flags[name];
|
|
94
|
+
if (typeof v === "string" && v.trim().length > 0) return v.trim();
|
|
95
|
+
}
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function flagInt(flags, ...names) {
|
|
100
|
+
const raw = flagStr(flags, ...names);
|
|
101
|
+
if (raw === undefined) return undefined;
|
|
102
|
+
const num = Number(raw);
|
|
103
|
+
if (!Number.isInteger(num)) {
|
|
104
|
+
throw new CliError(`Expected an integer for --${names[0]}, got "${raw}".`, 1);
|
|
105
|
+
}
|
|
106
|
+
return num;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function flagNum(flags, ...names) {
|
|
110
|
+
const raw = flagStr(flags, ...names);
|
|
111
|
+
if (raw === undefined) return undefined;
|
|
112
|
+
const num = Number(raw);
|
|
113
|
+
if (!Number.isFinite(num)) {
|
|
114
|
+
throw new CliError(`Expected a number for --${names[0]}, got "${raw}".`, 1);
|
|
115
|
+
}
|
|
116
|
+
return num;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function printJson(data) {
|
|
120
|
+
process.stdout.write(JSON.stringify(data, null, 2) + "\n");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function announceBrowserAuth(url) {
|
|
124
|
+
process.stderr.write(`Opening PinDrop in your browser to connect…\n`);
|
|
125
|
+
process.stderr.write(`If it didn't open, visit:\n${url}\n`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function parsePinNumber(raw) {
|
|
129
|
+
const cleaned = String(raw || "").replace(/^#/, "");
|
|
130
|
+
const n = Number(cleaned);
|
|
131
|
+
if (!Number.isInteger(n) || n < 1) {
|
|
132
|
+
throw new CliError(`Pin number must be a positive integer, got "${raw}".`, 1);
|
|
133
|
+
}
|
|
134
|
+
return n;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function resolveProjectIdForPin({ mcpUrl, flags, autoLogin }) {
|
|
138
|
+
const explicit = flagStr(flags, "project", "p", "project-id");
|
|
139
|
+
if (explicit) return explicit;
|
|
140
|
+
const hint = flagStr(flags, "hint") || inferProjectHint();
|
|
141
|
+
const res = await callPinDropTool({
|
|
142
|
+
mcpUrl,
|
|
143
|
+
toolName: "pindrop_list_open_pins",
|
|
144
|
+
args: { projectHint: hint, limit: 1 },
|
|
145
|
+
autoLogin,
|
|
146
|
+
openBrowser: !flags["no-browser"],
|
|
147
|
+
onAuthorizeUrl: announceBrowserAuth,
|
|
148
|
+
});
|
|
149
|
+
const s = res.structured;
|
|
150
|
+
if (s?.project?.id) return s.project.id;
|
|
151
|
+
if (Array.isArray(s?.candidates) && s.candidates.length === 1 && s.candidates[0]?.id) {
|
|
152
|
+
return s.candidates[0].id;
|
|
153
|
+
}
|
|
154
|
+
if (Array.isArray(s?.candidates) && s.candidates.length > 0) {
|
|
155
|
+
const list = s.candidates.map((c) => ` ${c.id} ${c.title || c.targetUrl}`).join("\n");
|
|
156
|
+
throw new CliError(
|
|
157
|
+
`Could not match this repo uniquely. Pass --project <id>:\n${list}`,
|
|
158
|
+
3,
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
throw new CliError(
|
|
162
|
+
"Could not match this directory to a PinDrop project. Pass --project <shareId> or run `pindrop projects`.",
|
|
163
|
+
3,
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function formatPinCompact(pin) {
|
|
168
|
+
const num = pin.pinNumber ?? pin.number ?? "?";
|
|
169
|
+
const path = pin.page?.path || pin.path || "/";
|
|
170
|
+
const comment = (pin.comment || "").replace(/\s+/g, " ").trim();
|
|
171
|
+
const vp = pin.placement?.viewportWidth
|
|
172
|
+
? `${pin.placement.viewportWidth}x${pin.placement.viewportHeight || "?"}`
|
|
173
|
+
: null;
|
|
174
|
+
const status = pin.status || "open";
|
|
175
|
+
const parts = [`#${num}`, path, JSON.stringify(comment)];
|
|
176
|
+
if (vp) parts.push(vp);
|
|
177
|
+
parts.push(status);
|
|
178
|
+
return parts.join(" · ");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function printHelp() {
|
|
182
|
+
process.stdout.write(`pindrop v${VERSION} — visual client feedback pins for your coding agent
|
|
183
|
+
|
|
184
|
+
Usage:
|
|
185
|
+
pindrop init [url] Sign in, install skill, and create project
|
|
186
|
+
pindrop login [--api-key pdp_...] Connect via browser OAuth (or save API key)
|
|
187
|
+
pindrop logout Disconnect saved PinDrop credentials
|
|
188
|
+
pindrop status Show connected account, plan, and limits
|
|
189
|
+
|
|
190
|
+
pindrop projects List active PinDrop projects
|
|
191
|
+
pindrop create [url] [--title <name>] Create (or reuse) a review link for a live URL
|
|
192
|
+
pindrop pins [--project <id>] [--resolved] [--full] [--json]
|
|
193
|
+
List pins for this repo (auto-matched by git remote)
|
|
194
|
+
pindrop pin <n> [--screenshot [path]] [--project <id>] [--json]
|
|
195
|
+
Read full context (and optionally save screenshot)
|
|
196
|
+
pindrop comment <n> --body <text> Reply on a pin
|
|
197
|
+
pindrop edit <n> --body <text> Edit a pin's original text
|
|
198
|
+
pindrop mark <n> <open|in_progress|resolved> [--comment <text>]
|
|
199
|
+
Update a pin's status
|
|
200
|
+
pindrop resolve <n> [--comment <text>] [--new-text <text>]
|
|
201
|
+
Close a pin (use --new-text on /try sandboxes)
|
|
202
|
+
pindrop delete <n> Soft-delete a pin
|
|
203
|
+
pindrop drop --path <p> --x <n> --y <n> --vw <n> --comment <text>
|
|
204
|
+
Drop a new pin from measured coordinates
|
|
205
|
+
pindrop sandbox claim <projectId> <claimCode>
|
|
206
|
+
Claim a pindrop.page/try demo sandbox
|
|
207
|
+
pindrop billing [--action trial|upgrade|manage] [--plan pro|studio]
|
|
208
|
+
Get a secure browser checkout/billing link
|
|
209
|
+
pindrop skill install [--global|--local] [--agent <id>] [--force]
|
|
210
|
+
Install the PinDrop agent SKILL.md
|
|
211
|
+
|
|
212
|
+
Global flags:
|
|
213
|
+
--url <mcpUrl> Override PinDrop MCP endpoint (default: https://mcp.pindrop.page)
|
|
214
|
+
--json Emit raw structured JSON
|
|
215
|
+
--no-browser Print the sign-in URL without opening a browser
|
|
216
|
+
--no-login Fail with exit code 2 instead of launching browser login
|
|
217
|
+
-h, --help Show this help
|
|
218
|
+
`);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export async function runCli(argv = process.argv.slice(2)) {
|
|
222
|
+
const { positionals, flags } = parseArgv(argv);
|
|
223
|
+
if (flags.version || flags.v) {
|
|
224
|
+
process.stdout.write(`pindrop ${VERSION}\n`);
|
|
225
|
+
return 0;
|
|
226
|
+
}
|
|
227
|
+
const cmd = positionals[0];
|
|
228
|
+
if (!cmd || flags.help || flags.h || cmd === "help") {
|
|
229
|
+
printHelp();
|
|
230
|
+
return 0;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const mcpUrl = resolveMcpUrl(flagStr(flags, "url"));
|
|
234
|
+
const autoLogin = !flags["no-login"];
|
|
235
|
+
const openBrowser = !flags["no-browser"];
|
|
236
|
+
const asJson = Boolean(flags.json);
|
|
237
|
+
|
|
238
|
+
switch (cmd) {
|
|
239
|
+
case "login": {
|
|
240
|
+
const apiKey = flagStr(flags, "api-key", "k");
|
|
241
|
+
if (apiKey) {
|
|
242
|
+
saveApiKeyProfile(mcpUrl, apiKey);
|
|
243
|
+
if (asJson) printJson({ ok: true, mode: "api_key", mcpUrl });
|
|
244
|
+
else process.stdout.write(`Saved API key for ${mcpUrl}\n`);
|
|
245
|
+
return 0;
|
|
246
|
+
}
|
|
247
|
+
await loginWithBrowser({
|
|
248
|
+
mcpUrl,
|
|
249
|
+
openBrowser,
|
|
250
|
+
onAuthorizeUrl: announceBrowserAuth,
|
|
251
|
+
});
|
|
252
|
+
if (asJson) printJson({ ok: true, mode: "oauth", mcpUrl });
|
|
253
|
+
else process.stdout.write(`Connected to PinDrop (${mcpUrl})\n`);
|
|
254
|
+
return 0;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
case "logout": {
|
|
258
|
+
const removed = await revokeAndLogout(mcpUrl);
|
|
259
|
+
if (asJson) printJson({ ok: true, removed, mcpUrl });
|
|
260
|
+
else process.stdout.write(removed ? `Disconnected from ${mcpUrl}\n` : `Not signed in to ${mcpUrl}\n`);
|
|
261
|
+
return 0;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
case "whoami":
|
|
265
|
+
case "status": {
|
|
266
|
+
const res = await callPinDropTool({
|
|
267
|
+
mcpUrl,
|
|
268
|
+
toolName: "pindrop_account_status",
|
|
269
|
+
args: {},
|
|
270
|
+
autoLogin: false,
|
|
271
|
+
});
|
|
272
|
+
const saved = getSavedProfile(mcpUrl);
|
|
273
|
+
const authMode = process.env.PINDROP_API_KEY
|
|
274
|
+
? "env"
|
|
275
|
+
: saved?.type || "oauth";
|
|
276
|
+
if (asJson) {
|
|
277
|
+
printJson({ authMode, mcpUrl, ...(res.structured || {}) });
|
|
278
|
+
} else {
|
|
279
|
+
process.stdout.write((res.text || JSON.stringify(res.structured)) + "\n");
|
|
280
|
+
}
|
|
281
|
+
return 0;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
case "init": {
|
|
285
|
+
let targetUrl = positionals[1] || flagStr(flags, "site");
|
|
286
|
+
let inferredFrom = null;
|
|
287
|
+
if (!targetUrl) {
|
|
288
|
+
const inferred = inferSiteUrl();
|
|
289
|
+
if (inferred) {
|
|
290
|
+
targetUrl = inferred.url;
|
|
291
|
+
inferredFrom = inferred.source;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
const skillResults = installSkillFiles({
|
|
295
|
+
scope: flags.local ? "local" : "global",
|
|
296
|
+
agent: flagStr(flags, "agent", "a"),
|
|
297
|
+
force: Boolean(flags.force),
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
if (!targetUrl) {
|
|
301
|
+
await loginWithBrowser({
|
|
302
|
+
mcpUrl,
|
|
303
|
+
openBrowser,
|
|
304
|
+
onAuthorizeUrl: announceBrowserAuth,
|
|
305
|
+
});
|
|
306
|
+
if (asJson) {
|
|
307
|
+
printJson({ ok: true, connected: true, skills: skillResults, project: null });
|
|
308
|
+
} else {
|
|
309
|
+
process.stdout.write("Connected to PinDrop.\n");
|
|
310
|
+
for (const r of skillResults) {
|
|
311
|
+
process.stdout.write(`Skill (${r.label}): ${r.status} -> ${r.path}\n`);
|
|
312
|
+
}
|
|
313
|
+
process.stdout.write(
|
|
314
|
+
"No live site URL detected in this folder. Run `pindrop create https://your-site.com` to get your client review link.\n",
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
return 0;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const title = flagStr(flags, "title", "name");
|
|
321
|
+
const res = await callPinDropTool({
|
|
322
|
+
mcpUrl,
|
|
323
|
+
toolName: "pindrop_create_project",
|
|
324
|
+
args: { targetUrl, ...(title ? { title } : {}) },
|
|
325
|
+
autoLogin,
|
|
326
|
+
openBrowser,
|
|
327
|
+
onAuthorizeUrl: announceBrowserAuth,
|
|
328
|
+
});
|
|
329
|
+
if (asJson) {
|
|
330
|
+
printJson({
|
|
331
|
+
ok: true,
|
|
332
|
+
inferredFrom,
|
|
333
|
+
skills: skillResults,
|
|
334
|
+
project: res.structured,
|
|
335
|
+
});
|
|
336
|
+
} else {
|
|
337
|
+
const p = res.structured || {};
|
|
338
|
+
if (inferredFrom) {
|
|
339
|
+
process.stderr.write(`Detected site URL ${targetUrl} from ${inferredFrom}\n`);
|
|
340
|
+
}
|
|
341
|
+
process.stdout.write(`Review link: ${p.shareUrl || res.text}\n`);
|
|
342
|
+
if (p.projectId) process.stdout.write(`Project ID: ${p.projectId}\n`);
|
|
343
|
+
for (const r of skillResults) {
|
|
344
|
+
if (r.status === "installed") {
|
|
345
|
+
process.stdout.write(`Installed skill: ${r.path}\n`);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return 0;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
case "projects": {
|
|
353
|
+
const res = await callPinDropTool({
|
|
354
|
+
mcpUrl,
|
|
355
|
+
toolName: "pindrop_list_projects",
|
|
356
|
+
args: {},
|
|
357
|
+
autoLogin,
|
|
358
|
+
openBrowser,
|
|
359
|
+
onAuthorizeUrl: announceBrowserAuth,
|
|
360
|
+
});
|
|
361
|
+
if (asJson) {
|
|
362
|
+
printJson(res.structured ?? { text: res.text });
|
|
363
|
+
return 0;
|
|
364
|
+
}
|
|
365
|
+
const projects = res.structured?.projects || [];
|
|
366
|
+
if (projects.length === 0) {
|
|
367
|
+
process.stdout.write("No active PinDrop projects yet. Run `pindrop create <url>`.\n");
|
|
368
|
+
return 0;
|
|
369
|
+
}
|
|
370
|
+
for (const p of projects) {
|
|
371
|
+
const open = typeof p.openPinCount === "number" ? `${p.openPinCount} open` : "";
|
|
372
|
+
process.stdout.write(
|
|
373
|
+
`${p.id} · ${p.title || p.targetUrl} · ${p.targetUrl}${open ? ` · ${open}` : ""}\n`,
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
return 0;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
case "create": {
|
|
380
|
+
let targetUrl = positionals[1] || flagStr(flags, "site");
|
|
381
|
+
let inferredFrom = null;
|
|
382
|
+
if (!targetUrl) {
|
|
383
|
+
const inferred = inferSiteUrl();
|
|
384
|
+
if (inferred) {
|
|
385
|
+
targetUrl = inferred.url;
|
|
386
|
+
inferredFrom = inferred.source;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (!targetUrl) {
|
|
390
|
+
throw new CliError(
|
|
391
|
+
"No live URL detected in this folder. Pass one explicitly: `pindrop create https://your-site.com`",
|
|
392
|
+
1,
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
const title = flagStr(flags, "title", "name");
|
|
396
|
+
const res = await callPinDropTool({
|
|
397
|
+
mcpUrl,
|
|
398
|
+
toolName: "pindrop_create_project",
|
|
399
|
+
args: { targetUrl, ...(title ? { title } : {}) },
|
|
400
|
+
autoLogin,
|
|
401
|
+
openBrowser,
|
|
402
|
+
onAuthorizeUrl: announceBrowserAuth,
|
|
403
|
+
});
|
|
404
|
+
if (asJson) {
|
|
405
|
+
printJson({ ...(res.structured || {}), ...(inferredFrom ? { inferredFrom } : {}) });
|
|
406
|
+
} else {
|
|
407
|
+
const p = res.structured || {};
|
|
408
|
+
if (inferredFrom) {
|
|
409
|
+
process.stderr.write(`Detected site URL ${targetUrl} from ${inferredFrom}\n`);
|
|
410
|
+
}
|
|
411
|
+
process.stdout.write(`Review link: ${p.shareUrl || res.text}\n`);
|
|
412
|
+
if (p.projectId) process.stdout.write(`Project ID: ${p.projectId}\n`);
|
|
413
|
+
if (p.wasReused) process.stdout.write(`Reused existing project for ${p.targetUrl || targetUrl}\n`);
|
|
414
|
+
}
|
|
415
|
+
return 0;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
case "pins": {
|
|
419
|
+
const projectId = flagStr(flags, "project", "p", "project-id");
|
|
420
|
+
const hint = projectId ? undefined : flagStr(flags, "hint") || inferProjectHint();
|
|
421
|
+
const limit = flagInt(flags, "limit", "n");
|
|
422
|
+
const toolName = flags.resolved ? "pindrop_list_resolved_pins" : "pindrop_list_open_pins";
|
|
423
|
+
const args = {
|
|
424
|
+
...(projectId ? { projectId } : {}),
|
|
425
|
+
...(hint ? { projectHint: hint } : {}),
|
|
426
|
+
...(limit ? { limit } : {}),
|
|
427
|
+
...(flagStr(flags, "status") ? { status: flagStr(flags, "status") } : {}),
|
|
428
|
+
...(flagStr(flags, "path") ? { path: flagStr(flags, "path") } : {}),
|
|
429
|
+
...(flagStr(flags, "priority") ? { priority: flagStr(flags, "priority") } : {}),
|
|
430
|
+
};
|
|
431
|
+
const res = await callPinDropTool({
|
|
432
|
+
mcpUrl,
|
|
433
|
+
toolName,
|
|
434
|
+
args,
|
|
435
|
+
autoLogin,
|
|
436
|
+
openBrowser,
|
|
437
|
+
onAuthorizeUrl: announceBrowserAuth,
|
|
438
|
+
});
|
|
439
|
+
if (asJson) {
|
|
440
|
+
printJson(res.structured ?? { text: res.text });
|
|
441
|
+
return 0;
|
|
442
|
+
}
|
|
443
|
+
if (flags.full) {
|
|
444
|
+
process.stdout.write((res.text || JSON.stringify(res.structured, null, 2)) + "\n");
|
|
445
|
+
return 0;
|
|
446
|
+
}
|
|
447
|
+
const s = res.structured || {};
|
|
448
|
+
const pins = Array.isArray(s.pins) ? s.pins : [];
|
|
449
|
+
if (s.scope === "unmatched" && Array.isArray(s.candidates) && s.candidates.length > 0) {
|
|
450
|
+
process.stdout.write("No project matched this folder. Pass --project <id>:\n");
|
|
451
|
+
for (const c of s.candidates) {
|
|
452
|
+
process.stdout.write(` ${c.id} · ${c.title || c.targetUrl} (${c.targetUrl})\n`);
|
|
453
|
+
}
|
|
454
|
+
return 3;
|
|
455
|
+
}
|
|
456
|
+
if (pins.length === 0) {
|
|
457
|
+
process.stdout.write(flags.resolved ? "No resolved pins.\n" : "No open pins.\n");
|
|
458
|
+
return 0;
|
|
459
|
+
}
|
|
460
|
+
for (const pin of pins) {
|
|
461
|
+
process.stdout.write(formatPinCompact(pin) + "\n");
|
|
462
|
+
}
|
|
463
|
+
return 0;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
case "pin": {
|
|
467
|
+
const pinId = flagStr(flags, "id", "pin-id");
|
|
468
|
+
const wantScreenshot = Boolean(flags.screenshot);
|
|
469
|
+
let args;
|
|
470
|
+
if (pinId) {
|
|
471
|
+
args = { pinId, ...(wantScreenshot ? { inlineBase64: true } : {}) };
|
|
472
|
+
} else {
|
|
473
|
+
if (!positionals[1]) {
|
|
474
|
+
throw new CliError("Usage: pindrop pin <number> [--project <id>] [--screenshot [path]]", 1);
|
|
475
|
+
}
|
|
476
|
+
const pinNumber = parsePinNumber(positionals[1]);
|
|
477
|
+
const projectId = await resolveProjectIdForPin({ mcpUrl, flags, autoLogin });
|
|
478
|
+
args = { projectId, pinNumber, ...(wantScreenshot ? { inlineBase64: true } : {}) };
|
|
479
|
+
}
|
|
480
|
+
const res = await callPinDropTool({
|
|
481
|
+
mcpUrl,
|
|
482
|
+
toolName: "pindrop_get_pin_context",
|
|
483
|
+
args,
|
|
484
|
+
autoLogin,
|
|
485
|
+
openBrowser,
|
|
486
|
+
onAuthorizeUrl: announceBrowserAuth,
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
let savedScreenshotPath = null;
|
|
490
|
+
if (wantScreenshot) {
|
|
491
|
+
const inlineBase64 = res.structured?.assets?.screenshotInlineBase64;
|
|
492
|
+
const suggested = res.structured?.assets?.screenshotSuggestedFilename || "pin-screenshot.png";
|
|
493
|
+
const imageBlock = res.content.find((c) => c && c.type === "image" && c.data);
|
|
494
|
+
const b64 = inlineBase64 || imageBlock?.data;
|
|
495
|
+
if (b64) {
|
|
496
|
+
const outPath =
|
|
497
|
+
typeof flags.screenshot === "string"
|
|
498
|
+
? resolve(flags.screenshot)
|
|
499
|
+
: resolve(join(".pindrop-screenshots", suggested));
|
|
500
|
+
mkdirSync(dirname(outPath), { recursive: true });
|
|
501
|
+
writeFileSync(outPath, Buffer.from(b64, "base64"));
|
|
502
|
+
savedScreenshotPath = outPath;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
if (asJson) {
|
|
507
|
+
const out = { ...(res.structured || {}) };
|
|
508
|
+
if (savedScreenshotPath) out.savedScreenshotPath = savedScreenshotPath;
|
|
509
|
+
if (out.assets?.screenshotInlineBase64) {
|
|
510
|
+
out.assets = { ...out.assets, screenshotInlineBase64: "[saved]" };
|
|
511
|
+
}
|
|
512
|
+
printJson(out);
|
|
513
|
+
} else {
|
|
514
|
+
process.stdout.write((res.text || JSON.stringify(res.structured, null, 2)) + "\n");
|
|
515
|
+
if (savedScreenshotPath) {
|
|
516
|
+
process.stdout.write(`Screenshot saved: ${savedScreenshotPath}\n`);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return 0;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
case "comment": {
|
|
523
|
+
const pinNumber = parsePinNumber(positionals[1]);
|
|
524
|
+
const body = flagStr(flags, "body", "b", "comment", "m") || positionals.slice(2).join(" ").trim();
|
|
525
|
+
if (!body) throw new CliError("Usage: pindrop comment <number> --body <text>", 1);
|
|
526
|
+
const projectId = await resolveProjectIdForPin({ mcpUrl, flags, autoLogin });
|
|
527
|
+
const authorName = flagStr(flags, "author") || process.env.PINDROP_AGENT_NAME;
|
|
528
|
+
const res = await callPinDropTool({
|
|
529
|
+
mcpUrl,
|
|
530
|
+
toolName: "pindrop_add_pin_comment",
|
|
531
|
+
args: { projectId, pinNumber, body, ...(authorName ? { authorName } : {}) },
|
|
532
|
+
autoLogin,
|
|
533
|
+
openBrowser,
|
|
534
|
+
onAuthorizeUrl: announceBrowserAuth,
|
|
535
|
+
});
|
|
536
|
+
if (asJson) printJson(res.structured ?? { text: res.text });
|
|
537
|
+
else process.stdout.write((res.structured?.pinShareUrl || res.text || "Comment added.") + "\n");
|
|
538
|
+
return 0;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
case "edit": {
|
|
542
|
+
const pinNumber = parsePinNumber(positionals[1]);
|
|
543
|
+
const body = flagStr(flags, "body", "b", "comment", "m") || positionals.slice(2).join(" ").trim();
|
|
544
|
+
if (!body) throw new CliError("Usage: pindrop edit <number> --body <text>", 1);
|
|
545
|
+
const projectId = await resolveProjectIdForPin({ mcpUrl, flags, autoLogin });
|
|
546
|
+
const res = await callPinDropTool({
|
|
547
|
+
mcpUrl,
|
|
548
|
+
toolName: "pindrop_edit_pin",
|
|
549
|
+
args: { projectId, pinNumber, body },
|
|
550
|
+
autoLogin,
|
|
551
|
+
openBrowser,
|
|
552
|
+
onAuthorizeUrl: announceBrowserAuth,
|
|
553
|
+
});
|
|
554
|
+
if (asJson) printJson(res.structured ?? { text: res.text });
|
|
555
|
+
else process.stdout.write((res.text || `Updated pin #${pinNumber}.`) + "\n");
|
|
556
|
+
return 0;
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
case "mark": {
|
|
560
|
+
const pinNumber = parsePinNumber(positionals[1]);
|
|
561
|
+
const status = positionals[2] || flagStr(flags, "status");
|
|
562
|
+
if (!status || !["open", "in_progress", "resolved"].includes(status)) {
|
|
563
|
+
throw new CliError("Usage: pindrop mark <number> <open|in_progress|resolved> [--comment <text>]", 1);
|
|
564
|
+
}
|
|
565
|
+
const projectId = await resolveProjectIdForPin({ mcpUrl, flags, autoLogin });
|
|
566
|
+
const comment = flagStr(flags, "comment", "c", "m");
|
|
567
|
+
const authorName = flagStr(flags, "author") || process.env.PINDROP_AGENT_NAME;
|
|
568
|
+
const res = await callPinDropTool({
|
|
569
|
+
mcpUrl,
|
|
570
|
+
toolName: "pindrop_set_pin_status",
|
|
571
|
+
args: {
|
|
572
|
+
projectId,
|
|
573
|
+
pinNumber,
|
|
574
|
+
status,
|
|
575
|
+
...(comment ? { comment } : {}),
|
|
576
|
+
...(authorName ? { authorName } : {}),
|
|
577
|
+
},
|
|
578
|
+
autoLogin,
|
|
579
|
+
openBrowser,
|
|
580
|
+
onAuthorizeUrl: announceBrowserAuth,
|
|
581
|
+
});
|
|
582
|
+
if (asJson) printJson(res.structured ?? { text: res.text });
|
|
583
|
+
else process.stdout.write((res.structured?.pinShareUrl || res.text || `Pin #${pinNumber} -> ${status}`) + "\n");
|
|
584
|
+
return 0;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
case "resolve": {
|
|
588
|
+
const pinNumber = parsePinNumber(positionals[1]);
|
|
589
|
+
const projectId = await resolveProjectIdForPin({ mcpUrl, flags, autoLogin });
|
|
590
|
+
const comment = flagStr(flags, "comment", "c", "m") || positionals.slice(2).join(" ").trim() || undefined;
|
|
591
|
+
const newText = flagStr(flags, "new-text", "newText");
|
|
592
|
+
const authorName = flagStr(flags, "author") || process.env.PINDROP_AGENT_NAME;
|
|
593
|
+
const res = await callPinDropTool({
|
|
594
|
+
mcpUrl,
|
|
595
|
+
toolName: "pindrop_resolve_pin",
|
|
596
|
+
args: {
|
|
597
|
+
projectId,
|
|
598
|
+
pinNumber,
|
|
599
|
+
resolved: !flags.reopen,
|
|
600
|
+
...(comment ? { comment } : {}),
|
|
601
|
+
...(newText ? { newText } : {}),
|
|
602
|
+
...(authorName ? { authorName } : {}),
|
|
603
|
+
},
|
|
604
|
+
autoLogin,
|
|
605
|
+
openBrowser,
|
|
606
|
+
onAuthorizeUrl: announceBrowserAuth,
|
|
607
|
+
});
|
|
608
|
+
if (asJson) printJson(res.structured ?? { text: res.text });
|
|
609
|
+
else process.stdout.write((res.structured?.pinShareUrl || res.text || `Resolved pin #${pinNumber}.`) + "\n");
|
|
610
|
+
return 0;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
case "delete": {
|
|
614
|
+
const pinNumber = parsePinNumber(positionals[1]);
|
|
615
|
+
const projectId = await resolveProjectIdForPin({ mcpUrl, flags, autoLogin });
|
|
616
|
+
const res = await callPinDropTool({
|
|
617
|
+
mcpUrl,
|
|
618
|
+
toolName: "pindrop_delete_pin",
|
|
619
|
+
args: { projectId, pinNumber },
|
|
620
|
+
autoLogin,
|
|
621
|
+
openBrowser,
|
|
622
|
+
onAuthorizeUrl: announceBrowserAuth,
|
|
623
|
+
});
|
|
624
|
+
if (asJson) printJson(res.structured ?? { text: res.text });
|
|
625
|
+
else process.stdout.write((res.text || `Deleted pin #${pinNumber}.`) + "\n");
|
|
626
|
+
return 0;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
case "drop": {
|
|
630
|
+
const projectId = await resolveProjectIdForPin({ mcpUrl, flags, autoLogin });
|
|
631
|
+
const path = flagStr(flags, "path") || "/";
|
|
632
|
+
const x = flagNum(flags, "x");
|
|
633
|
+
const y = flagNum(flags, "y");
|
|
634
|
+
const viewportWidth = flagNum(flags, "vw", "viewport-width");
|
|
635
|
+
const viewportHeight = flagNum(flags, "vh", "viewport-height");
|
|
636
|
+
const comment = flagStr(flags, "comment", "c", "m", "body");
|
|
637
|
+
if (x === undefined || y === undefined || viewportWidth === undefined || !comment) {
|
|
638
|
+
throw new CliError(
|
|
639
|
+
"Usage: pindrop drop --path <path> --x <n> --y <n> --vw <n> --comment <text> [--vh <n>] [--project <id>]",
|
|
640
|
+
1,
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
const res = await callPinDropTool({
|
|
644
|
+
mcpUrl,
|
|
645
|
+
toolName: "pindrop_create_pin",
|
|
646
|
+
args: {
|
|
647
|
+
projectId,
|
|
648
|
+
path,
|
|
649
|
+
x,
|
|
650
|
+
y,
|
|
651
|
+
viewportWidth,
|
|
652
|
+
...(viewportHeight !== undefined ? { viewportHeight } : {}),
|
|
653
|
+
comment,
|
|
654
|
+
},
|
|
655
|
+
autoLogin,
|
|
656
|
+
openBrowser,
|
|
657
|
+
onAuthorizeUrl: announceBrowserAuth,
|
|
658
|
+
});
|
|
659
|
+
if (asJson) printJson(res.structured ?? { text: res.text });
|
|
660
|
+
else process.stdout.write((res.structured?.pinShareUrl || res.text) + "\n");
|
|
661
|
+
return 0;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
case "sandbox": {
|
|
665
|
+
const sub = positionals[1];
|
|
666
|
+
if (sub !== "claim" || !positionals[2] || !positionals[3]) {
|
|
667
|
+
throw new CliError("Usage: pindrop sandbox claim <projectId> <claimCode>", 1);
|
|
668
|
+
}
|
|
669
|
+
const res = await callPinDropTool({
|
|
670
|
+
mcpUrl,
|
|
671
|
+
toolName: "pindrop_claim_sandbox",
|
|
672
|
+
args: { projectId: positionals[2], claimCode: positionals[3] },
|
|
673
|
+
autoLogin,
|
|
674
|
+
openBrowser,
|
|
675
|
+
onAuthorizeUrl: announceBrowserAuth,
|
|
676
|
+
});
|
|
677
|
+
if (asJson) printJson(res.structured ?? { text: res.text });
|
|
678
|
+
else process.stdout.write((res.text || `Claimed sandbox ${positionals[2]}`) + "\n");
|
|
679
|
+
return 0;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
case "billing": {
|
|
683
|
+
const action = flagStr(flags, "action") || "upgrade";
|
|
684
|
+
const plan = flagStr(flags, "plan");
|
|
685
|
+
const interval = flagStr(flags, "interval");
|
|
686
|
+
const res = await callPinDropTool({
|
|
687
|
+
mcpUrl,
|
|
688
|
+
toolName: "pindrop_get_billing_link",
|
|
689
|
+
args: {
|
|
690
|
+
action,
|
|
691
|
+
...(plan ? { plan } : {}),
|
|
692
|
+
...(interval ? { interval } : {}),
|
|
693
|
+
},
|
|
694
|
+
autoLogin,
|
|
695
|
+
openBrowser,
|
|
696
|
+
onAuthorizeUrl: announceBrowserAuth,
|
|
697
|
+
});
|
|
698
|
+
if (asJson) printJson(res.structured ?? { text: res.text });
|
|
699
|
+
else process.stdout.write((res.structured?.url || res.text) + "\n");
|
|
700
|
+
return 0;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
case "skill": {
|
|
704
|
+
const sub = positionals[1] || "install";
|
|
705
|
+
if (sub !== "install") {
|
|
706
|
+
throw new CliError("Usage: pindrop skill install [--global|--local] [--agent <id>] [--force]", 1);
|
|
707
|
+
}
|
|
708
|
+
const results = installSkillFiles({
|
|
709
|
+
scope: flags.local ? "local" : "global",
|
|
710
|
+
agent: flagStr(flags, "agent", "a"),
|
|
711
|
+
force: Boolean(flags.force),
|
|
712
|
+
});
|
|
713
|
+
if (asJson) {
|
|
714
|
+
printJson({ ok: true, results });
|
|
715
|
+
} else {
|
|
716
|
+
for (const r of results) {
|
|
717
|
+
process.stdout.write(`${r.label}: ${r.status} -> ${r.path}\n`);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
return 0;
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
default:
|
|
724
|
+
throw new CliError(`Unknown command: ${cmd}. Run \`pindrop --help\` for usage.`, 1);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
function isDirectExecution() {
|
|
729
|
+
if (!process.argv[1]) return false;
|
|
730
|
+
try {
|
|
731
|
+
return realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
|
|
732
|
+
} catch {
|
|
733
|
+
return resolve(process.argv[1]) === resolve(fileURLToPath(import.meta.url));
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
if (isDirectExecution()) {
|
|
738
|
+
runCli()
|
|
739
|
+
.then((code) => {
|
|
740
|
+
process.exitCode = code ?? 0;
|
|
741
|
+
})
|
|
742
|
+
.catch((err) => {
|
|
743
|
+
if (err instanceof CliError) {
|
|
744
|
+
process.stderr.write(`${err.message}\n`);
|
|
745
|
+
process.exitCode = err.exitCode;
|
|
746
|
+
} else {
|
|
747
|
+
const cause = err?.cause?.message || err?.cause?.code;
|
|
748
|
+
const msg = err?.message || String(err);
|
|
749
|
+
process.stderr.write(`${cause && !msg.includes(cause) ? `${msg} (${cause})` : msg}\n`);
|
|
750
|
+
process.exitCode = 1;
|
|
751
|
+
}
|
|
752
|
+
});
|
|
753
|
+
}
|