vit 0.1.0 → 0.1.3

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.
@@ -0,0 +1,477 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 sol pbc
3
+
4
+ import { DEFAULT_EXPLORE_URL } from '../lib/constants.js';
5
+ import { readProjectConfig } from '../lib/vit-dir.js';
6
+ import { brand } from '../lib/brand.js';
7
+ import { jsonOk, jsonError } from '../lib/json-output.js';
8
+
9
+ function timeAgo(isoString) {
10
+ const seconds = Math.floor((Date.now() - new Date(isoString).getTime()) / 1000);
11
+ if (seconds < 60) return `${seconds}s ago`;
12
+ const minutes = Math.floor(seconds / 60);
13
+ if (minutes < 60) return `${minutes}m ago`;
14
+ const hours = Math.floor(minutes / 60);
15
+ if (hours < 24) return `${hours}h ago`;
16
+ const days = Math.floor(hours / 24);
17
+ if (days < 30) return `${days}d ago`;
18
+ const months = Math.floor(days / 30);
19
+ if (months < 12) return `${months}mo ago`;
20
+ const years = Math.floor(days / 365);
21
+ return `${years}y ago`;
22
+ }
23
+
24
+ function resolveUrl(opts) {
25
+ return opts.exploreUrl || process.env.VIT_EXPLORE_URL || DEFAULT_EXPLORE_URL;
26
+ }
27
+
28
+ function unavailableMessage(baseUrl) {
29
+ try {
30
+ return `${new URL(baseUrl).host} is unavailable. try 'vit scan' for network-wide discovery or 'vit skim' for your followed accounts.`;
31
+ } catch {
32
+ return `${baseUrl} is unavailable. try 'vit scan' for network-wide discovery or 'vit skim' for your followed accounts.`;
33
+ }
34
+ }
35
+
36
+ function mergeExploreOpts(opts, command) {
37
+ return {
38
+ ...(command?.parent?.opts?.() || {}),
39
+ ...(command?.opts?.() || opts || {}),
40
+ };
41
+ }
42
+
43
+ async function fetchAndShowStats(opts) {
44
+ const baseUrl = resolveUrl(opts);
45
+ try {
46
+ const url = new URL('/api/stats', baseUrl);
47
+ const res = await fetch(url);
48
+ if (!res.ok) throw new Error(`explore API returned ${res.status}`);
49
+ const data = await res.json();
50
+
51
+ if (opts.json) {
52
+ jsonOk(data);
53
+ return;
54
+ }
55
+
56
+ console.log(`${brand} explore stats`);
57
+ console.log(` caps: ${data.total_caps} skills: ${data.total_skills}`);
58
+ console.log(` vouches: ${data.total_vouches} beacons: ${data.total_beacons}`);
59
+ console.log(` active dids: ${data.active_dids} skill publishers: ${data.skill_publishers}`);
60
+ } catch (err) {
61
+ const msg = err instanceof Error ? err.message : String(err);
62
+ const finalMsg = msg.startsWith('explore API returned ')
63
+ ? msg
64
+ : unavailableMessage(baseUrl);
65
+ if (opts.json) {
66
+ jsonError(finalMsg);
67
+ return;
68
+ }
69
+ console.error(finalMsg);
70
+ process.exitCode = 1;
71
+ }
72
+ }
73
+
74
+ export default function register(program) {
75
+ const explore = program
76
+ .command('explore')
77
+ .description('Query the explore index for caps, skills, beacons, vouches, and stats')
78
+ .option('--json', 'Output as JSON')
79
+ .option('--explore-url <url>', 'Explore API base URL')
80
+ .action(async (opts) => {
81
+ await fetchAndShowStats(opts);
82
+ });
83
+
84
+ explore
85
+ .command('cap')
86
+ .argument('<ref>', 'Cap ref to look up')
87
+ .description('Show details for a single cap')
88
+ .option('--beacon <beacon>', 'Scope lookup to a beacon')
89
+ .option('--json', 'Output as JSON')
90
+ .option('--explore-url <url>', 'Explore API base URL')
91
+ .action(async (ref, opts, command) => {
92
+ opts = mergeExploreOpts(opts, command);
93
+ const baseUrl = resolveUrl(opts);
94
+
95
+ try {
96
+ const url = new URL('/api/cap', baseUrl);
97
+ url.searchParams.set('ref', ref);
98
+ if (opts.beacon) url.searchParams.set('beacon', opts.beacon);
99
+
100
+ const res = await fetch(url);
101
+ if (!res.ok) throw new Error(`explore API returned ${res.status}`);
102
+ const data = await res.json();
103
+
104
+ if (!data.cap) {
105
+ const msg = `no cap found with ref '${ref}'`;
106
+ if (opts.json) {
107
+ jsonError(msg);
108
+ return;
109
+ }
110
+ console.error(msg);
111
+ process.exitCode = 1;
112
+ return;
113
+ }
114
+
115
+ if (opts.json) {
116
+ jsonOk(data);
117
+ return;
118
+ }
119
+
120
+ const record = JSON.parse(data.cap.record_json);
121
+ console.log(`${brand} explore cap`);
122
+ console.log(` ${data.cap.title} [${record.kind}]`);
123
+ console.log(` ${data.cap.description}`);
124
+ console.log();
125
+ console.log(` beacon: ${data.cap.beacon}`);
126
+ console.log(` author: @${data.cap.handle}`);
127
+ console.log(` ref: ${data.cap.ref}`);
128
+ console.log(` posted: ${timeAgo(data.cap.created_at)}`);
129
+ if (record.text) {
130
+ console.log();
131
+ console.log(` ${record.text}`);
132
+ }
133
+ console.log();
134
+ console.log(` vouches: ${data.cap.vouch_count}`);
135
+ console.log();
136
+ console.log(` vit vet ${data.cap.ref} - inspect before adopting`);
137
+ console.log(` vit remix ${data.cap.ref} - remix this cap`);
138
+ } catch (err) {
139
+ const msg = err instanceof Error ? err.message : String(err);
140
+ const finalMsg = msg.startsWith('explore API returned ')
141
+ ? msg
142
+ : unavailableMessage(baseUrl);
143
+ if (opts.json) {
144
+ jsonError(finalMsg);
145
+ return;
146
+ }
147
+ console.error(finalMsg);
148
+ process.exitCode = 1;
149
+ }
150
+ });
151
+
152
+ explore
153
+ .command('skill')
154
+ .argument('<name>', 'Skill name to look up')
155
+ .description('Show details for a single skill')
156
+ .option('--json', 'Output as JSON')
157
+ .option('--explore-url <url>', 'Explore API base URL')
158
+ .action(async (name, opts, command) => {
159
+ opts = mergeExploreOpts(opts, command);
160
+ const baseUrl = resolveUrl(opts);
161
+
162
+ try {
163
+ const url = new URL('/api/skill', baseUrl);
164
+ url.searchParams.set('name', name);
165
+
166
+ const res = await fetch(url);
167
+ if (!res.ok) throw new Error(`explore API returned ${res.status}`);
168
+ const data = await res.json();
169
+
170
+ if (!data.skill) {
171
+ const msg = `no skill found with name '${name}'`;
172
+ if (opts.json) {
173
+ jsonError(msg);
174
+ return;
175
+ }
176
+ console.error(msg);
177
+ process.exitCode = 1;
178
+ return;
179
+ }
180
+
181
+ if (opts.json) {
182
+ jsonOk(data);
183
+ return;
184
+ }
185
+
186
+ const record = JSON.parse(data.skill.record_json);
187
+ console.log(`${brand} explore skill`);
188
+ console.log(` /${data.skill.name} v${data.skill.version}`);
189
+ console.log(` ${data.skill.description}`);
190
+ console.log();
191
+ console.log(` author: @${data.skill.handle}`);
192
+ if (record.license) console.log(` license: ${record.license}`);
193
+ if (data.skill.tags) console.log(` tags: ${data.skill.tags}`);
194
+ console.log(` vouches: ${data.skill.vouch_count}`);
195
+ console.log();
196
+ console.log(` vit learn skill-${data.skill.name} - install this skill`);
197
+ } catch (err) {
198
+ const msg = err instanceof Error ? err.message : String(err);
199
+ const finalMsg = msg.startsWith('explore API returned ')
200
+ ? msg
201
+ : unavailableMessage(baseUrl);
202
+ if (opts.json) {
203
+ jsonError(finalMsg);
204
+ return;
205
+ }
206
+ console.error(finalMsg);
207
+ process.exitCode = 1;
208
+ }
209
+ });
210
+
211
+ explore
212
+ .command('caps')
213
+ .description('List recent caps from the explore index')
214
+ .option('--beacon <beacon>', 'Filter by beacon')
215
+ .option('--limit <n>', 'Limit number of caps')
216
+ .option('--cursor <id>', 'Pagination cursor')
217
+ .option('--json', 'Output as JSON')
218
+ .option('--explore-url <url>', 'Explore API base URL')
219
+ .action(async (opts, command) => {
220
+ opts = mergeExploreOpts(opts, command);
221
+ const baseUrl = resolveUrl(opts);
222
+
223
+ try {
224
+ let beacon = opts.beacon;
225
+ if (beacon === '.') {
226
+ const config = readProjectConfig();
227
+ const beacons = [config.beacon, config.secondaryBeacon].filter(Boolean);
228
+ if (beacons.length === 0) {
229
+ const msg = "no beacon set — run 'vit init' first";
230
+ if (opts.json) {
231
+ jsonError(msg);
232
+ return;
233
+ }
234
+ console.error(msg);
235
+ process.exitCode = 1;
236
+ return;
237
+ }
238
+ beacon = beacons.join(',');
239
+ }
240
+
241
+ const url = new URL('/api/caps', baseUrl);
242
+ if (beacon) url.searchParams.set('beacon', beacon);
243
+ if (opts.limit) url.searchParams.set('limit', opts.limit);
244
+ if (opts.cursor) url.searchParams.set('cursor', opts.cursor);
245
+
246
+ const res = await fetch(url);
247
+ if (!res.ok) throw new Error(`explore API returned ${res.status}`);
248
+ const data = await res.json();
249
+
250
+ if (opts.json) {
251
+ jsonOk({ caps: data.caps, cursor: data.cursor });
252
+ return;
253
+ }
254
+
255
+ console.log(`${brand} explore caps`);
256
+ if (!data.caps?.length) {
257
+ console.log('no caps found.');
258
+ return;
259
+ }
260
+
261
+ for (const cap of data.caps) {
262
+ console.log(` ${cap.title} (${cap.ref})`);
263
+ console.log(` @${cap.handle} ${cap.beacon}`);
264
+ console.log(` ${cap.description}`);
265
+ }
266
+ if (data.cursor) {
267
+ console.log(`\nnext: --cursor ${data.cursor}`);
268
+ }
269
+ } catch (err) {
270
+ const msg = err instanceof Error ? err.message : String(err);
271
+ const finalMsg = msg.startsWith('explore API returned ')
272
+ ? msg
273
+ : unavailableMessage(baseUrl);
274
+ if (opts.json) {
275
+ jsonError(finalMsg);
276
+ return;
277
+ }
278
+ console.error(finalMsg);
279
+ process.exitCode = 1;
280
+ }
281
+ });
282
+
283
+ explore
284
+ .command('skills')
285
+ .description('List published skills from the explore index')
286
+ .option('--tag <tag>', 'Filter by tag')
287
+ .option('--limit <n>', 'Limit number of skills')
288
+ .option('--cursor <id>', 'Pagination cursor')
289
+ .option('--json', 'Output as JSON')
290
+ .option('--explore-url <url>', 'Explore API base URL')
291
+ .action(async (opts, command) => {
292
+ opts = mergeExploreOpts(opts, command);
293
+ const baseUrl = resolveUrl(opts);
294
+
295
+ try {
296
+ const url = new URL('/api/skills', baseUrl);
297
+ if (opts.tag) url.searchParams.set('tag', opts.tag);
298
+ if (opts.limit) url.searchParams.set('limit', opts.limit);
299
+ if (opts.cursor) url.searchParams.set('cursor', opts.cursor);
300
+
301
+ const res = await fetch(url);
302
+ if (!res.ok) throw new Error(`explore API returned ${res.status}`);
303
+ const data = await res.json();
304
+
305
+ if (opts.json) {
306
+ jsonOk({ skills: data.skills, cursor: data.cursor });
307
+ return;
308
+ }
309
+
310
+ console.log(`${brand} explore skills`);
311
+ if (!data.skills?.length) {
312
+ console.log('no skills found.');
313
+ return;
314
+ }
315
+
316
+ for (const skill of data.skills) {
317
+ console.log(` ${skill.name} v${skill.version} (${skill.ref})`);
318
+ console.log(` @${skill.handle} ${skill.description}`);
319
+ }
320
+ if (data.cursor) {
321
+ console.log(`\nnext: --cursor ${data.cursor}`);
322
+ }
323
+ } catch (err) {
324
+ const msg = err instanceof Error ? err.message : String(err);
325
+ const finalMsg = msg.startsWith('explore API returned ')
326
+ ? msg
327
+ : unavailableMessage(baseUrl);
328
+ if (opts.json) {
329
+ jsonError(finalMsg);
330
+ return;
331
+ }
332
+ console.error(finalMsg);
333
+ process.exitCode = 1;
334
+ }
335
+ });
336
+
337
+ explore
338
+ .command('beacons')
339
+ .description('List active beacons from the explore index')
340
+ .option('--json', 'Output as JSON')
341
+ .option('--explore-url <url>', 'Explore API base URL')
342
+ .action(async (opts, command) => {
343
+ opts = mergeExploreOpts(opts, command);
344
+ const baseUrl = resolveUrl(opts);
345
+
346
+ try {
347
+ const url = new URL('/api/beacons', baseUrl);
348
+ const res = await fetch(url);
349
+ if (!res.ok) throw new Error(`explore API returned ${res.status}`);
350
+ const data = await res.json();
351
+
352
+ if (opts.json) {
353
+ jsonOk({ beacons: data.beacons });
354
+ return;
355
+ }
356
+
357
+ console.log(`${brand} explore beacons`);
358
+ if (!data.beacons?.length) {
359
+ console.log('no beacons found.');
360
+ return;
361
+ }
362
+
363
+ for (const beacon of data.beacons) {
364
+ console.log(` ${beacon.name}`);
365
+ console.log(` caps: ${beacon.cap_count} vouches: ${beacon.vouch_count} last active: ${beacon.last_activity}`);
366
+ }
367
+ } catch (err) {
368
+ const msg = err instanceof Error ? err.message : String(err);
369
+ const finalMsg = msg.startsWith('explore API returned ')
370
+ ? msg
371
+ : unavailableMessage(baseUrl);
372
+ if (opts.json) {
373
+ jsonError(finalMsg);
374
+ return;
375
+ }
376
+ console.error(finalMsg);
377
+ process.exitCode = 1;
378
+ }
379
+ });
380
+
381
+ explore
382
+ .command('vouches')
383
+ .description('List vouches for a cap from the explore index')
384
+ .option('--cap <uri>', 'Cap URI')
385
+ .option('--ref <ref>', 'Cap ref')
386
+ .option('--beacon <beacon>', 'Filter ref lookup by beacon')
387
+ .option('--json', 'Output as JSON')
388
+ .option('--explore-url <url>', 'Explore API base URL')
389
+ .action(async (opts, command) => {
390
+ opts = mergeExploreOpts(opts, command);
391
+ const baseUrl = resolveUrl(opts);
392
+
393
+ try {
394
+ if ((!opts.cap && !opts.ref) || (opts.cap && opts.ref)) {
395
+ const msg = 'provide --cap <uri> or --ref <ref>';
396
+ if (opts.json) {
397
+ jsonError(msg);
398
+ return;
399
+ }
400
+ console.error(msg);
401
+ process.exitCode = 1;
402
+ return;
403
+ }
404
+
405
+ let capUri = opts.cap;
406
+ if (opts.ref) {
407
+ const capsUrl = new URL('/api/caps', baseUrl);
408
+ if (opts.beacon) capsUrl.searchParams.set('beacon', opts.beacon);
409
+
410
+ const capsRes = await fetch(capsUrl);
411
+ if (!capsRes.ok) throw new Error(`explore API returned ${capsRes.status}`);
412
+ const capsData = await capsRes.json();
413
+ const match = capsData.caps?.find((cap) => cap.ref === opts.ref);
414
+
415
+ if (!match) {
416
+ const msg = `no cap found with ref '${opts.ref}'`;
417
+ if (opts.json) {
418
+ jsonError(msg);
419
+ return;
420
+ }
421
+ console.error(msg);
422
+ process.exitCode = 1;
423
+ return;
424
+ }
425
+
426
+ capUri = match.uri;
427
+ }
428
+
429
+ const url = new URL('/api/vouches', baseUrl);
430
+ url.searchParams.set('cap_uri', capUri);
431
+
432
+ const res = await fetch(url);
433
+ if (!res.ok) throw new Error(`explore API returned ${res.status}`);
434
+ const data = await res.json();
435
+
436
+ if (opts.json) {
437
+ jsonOk({ vouches: data.vouches, cap_uri: capUri });
438
+ return;
439
+ }
440
+
441
+ console.log(`${brand} explore vouches`);
442
+ if (!data.vouches?.length) {
443
+ console.log('no vouches found for this cap.');
444
+ return;
445
+ }
446
+
447
+ for (const vouch of data.vouches) {
448
+ const who = vouch.handle ? `@${vouch.handle}` : (vouch.did || 'unknown');
449
+ const createdAt = vouch.created_at || vouch.createdAt || 'unknown';
450
+ const ref = vouch.ref || vouch.cap_ref || vouch.cap_uri || '';
451
+ console.log(` ${who} ${createdAt}`);
452
+ if (ref) console.log(` ${ref}`);
453
+ }
454
+ } catch (err) {
455
+ const msg = err instanceof Error ? err.message : String(err);
456
+ const finalMsg = msg.startsWith('explore API returned ')
457
+ ? msg
458
+ : unavailableMessage(baseUrl);
459
+ if (opts.json) {
460
+ jsonError(finalMsg);
461
+ return;
462
+ }
463
+ console.error(finalMsg);
464
+ process.exitCode = 1;
465
+ }
466
+ });
467
+
468
+ explore
469
+ .command('stats', { isDefault: true })
470
+ .description('Show network-wide stats from the explore index')
471
+ .option('--json', 'Output as JSON')
472
+ .option('--explore-url <url>', 'Explore API base URL')
473
+ .action(async (opts, command) => {
474
+ opts = mergeExploreOpts(opts, command);
475
+ await fetchAndShowStats(opts);
476
+ });
477
+ }
@@ -1,19 +1,17 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
1
+ // SPDX-License-Identifier: MIT
2
2
  // Copyright (c) 2026 sol pbc
3
3
 
4
4
  import { loadConfig } from '../lib/config.js';
5
- import { CAP_COLLECTION } from '../lib/constants.js';
5
+ import { CAP_COLLECTION, DEFAULT_JETSTREAM_URL } from '../lib/constants.js';
6
6
  import { resolveRef } from '../lib/cap-ref.js';
7
7
  import { brand } from '../lib/brand.js';
8
8
 
9
- const JETSTREAM_URL = 'wss://jetstream2.us-east.bsky.network/subscribe';
10
-
11
9
  let ws = null;
12
10
  let shuttingDown = false;
13
11
  let backoff = 1000;
14
12
 
15
- function buildUrl(collection, did, cursor) {
16
- const url = new URL(JETSTREAM_URL);
13
+ function buildUrl(baseUrl, collection, did, cursor) {
14
+ const url = new URL(baseUrl);
17
15
  url.searchParams.set('wantedCollections', collection);
18
16
  if (did) url.searchParams.set('wantedDids', did);
19
17
  if (cursor) url.searchParams.set('cursor', cursor);
@@ -59,7 +57,7 @@ function formatEvent(event) {
59
57
  }
60
58
 
61
59
  function connect(opts, cursor) {
62
- const url = buildUrl(opts.collection, opts.did, cursor);
60
+ const url = buildUrl(opts.jetstreamUrl, opts.collection, opts.did, cursor);
63
61
  let lastCursor = cursor;
64
62
 
65
63
  ws = new WebSocket(url);
@@ -113,16 +111,29 @@ export default function register(program) {
113
111
  .description('Listen to Jetstream for cap events')
114
112
  .option('-v, --verbose', 'Show full JSON for each event')
115
113
  .option('--did <did>', 'Filter by DID (reads saved DID from config if not provided)')
114
+ .option('--global', 'Show cap events from all DIDs across the network')
116
115
  .option('--collection <nsid>', 'Collection NSID to filter', CAP_COLLECTION)
116
+ .option('--jetstream <url>', 'Jetstream WebSocket URL (default: VIT_JETSTREAM_URL env or built-in)')
117
117
  .action(async (opts) => {
118
118
  try {
119
- if (!opts.did) {
119
+ if (opts.global && opts.did) {
120
+ console.error('error: --global and --did are mutually exclusive');
121
+ process.exitCode = 1;
122
+ return;
123
+ }
124
+
125
+ if (opts.global) {
126
+ opts.did = undefined;
127
+ } else if (!opts.did) {
120
128
  const config = loadConfig();
121
129
  if (config.did) {
122
130
  opts.did = config.did;
123
131
  }
124
132
  }
125
133
 
134
+ const jetstreamUrl = opts.jetstream || process.env.VIT_JETSTREAM_URL || DEFAULT_JETSTREAM_URL;
135
+ opts.jetstreamUrl = jetstreamUrl;
136
+
126
137
  for (const sig of ['SIGINT', 'SIGTERM']) {
127
138
  process.on(sig, () => {
128
139
  shuttingDown = true;
@@ -132,7 +143,7 @@ export default function register(program) {
132
143
  });
133
144
  }
134
145
 
135
- const url = buildUrl(opts.collection, opts.did, null);
146
+ const url = buildUrl(jetstreamUrl, opts.collection, opts.did, null);
136
147
  console.log(`${brand} firehose`);
137
148
  console.log(` Collection: ${opts.collection}`);
138
149
  if (opts.did) console.log(` DID filter: ${opts.did}`);
package/src/cmd/follow.js CHANGED
@@ -1,10 +1,11 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
1
+ // SPDX-License-Identifier: MIT
2
2
  // Copyright (c) 2026 sol pbc
3
3
 
4
- import { requireDid } from '../lib/config.js';
4
+ import { requireDid, loadConfig } from '../lib/config.js';
5
5
  import { restoreAgent } from '../lib/oauth.js';
6
6
  import { readFollowing, writeFollowing } from '../lib/vit-dir.js';
7
7
  import { mark } from '../lib/brand.js';
8
+ import { jsonOk, jsonError } from '../lib/json-output.js';
8
9
 
9
10
  export default function register(program) {
10
11
  program
@@ -12,35 +13,54 @@ export default function register(program) {
12
13
  .argument('<handle>', 'Handle to follow (e.g. alice.bsky.social)')
13
14
  .description('Add an account to this project\'s following list')
14
15
  .option('-v, --verbose', 'Show step-by-step details')
16
+ .option('--json', 'Output as JSON')
15
17
  .option('--did <did>', 'DID to use for handle resolution')
16
18
  .action(async (handle, opts) => {
17
19
  try {
18
20
  const { verbose } = opts;
21
+ const vlog = opts.json ? (...a) => console.error(...a) : console.log;
19
22
  handle = handle.replace(/^@/, '');
20
23
 
24
+ if (opts.json && !(opts.did || loadConfig().did)) {
25
+ jsonError('no DID configured', "run 'vit login <handle>' first");
26
+ return;
27
+ }
21
28
  const did = requireDid(opts);
22
29
  if (!did) return;
23
- if (verbose) console.log(`[verbose] DID: ${did}`);
30
+ if (verbose) vlog(`[verbose] DID: ${did}`);
24
31
 
25
32
  const list = readFollowing();
26
33
  if (list.some(e => e.handle === handle)) {
34
+ if (opts.json) {
35
+ jsonError(`already following ${handle}`);
36
+ return;
37
+ }
27
38
  console.error(`already following ${handle}`);
28
39
  process.exitCode = 1;
29
40
  return;
30
41
  }
31
42
 
32
43
  const { agent } = await restoreAgent(did);
33
- if (verbose) console.log('[verbose] session restored');
44
+ if (verbose) vlog('[verbose] session restored');
34
45
 
35
46
  const resolved = await agent.resolveHandle({ handle });
36
47
  const targetDid = resolved.data.did;
37
- if (verbose) console.log(`[verbose] resolved ${handle} to ${targetDid}`);
48
+ if (verbose) vlog(`[verbose] resolved ${handle} to ${targetDid}`);
38
49
 
39
50
  list.push({ handle, did: targetDid, followedAt: new Date().toISOString() });
40
51
  writeFollowing(list);
52
+ if (opts.json) {
53
+ jsonOk({ handle, did: targetDid, followedAt: list[list.length - 1].followedAt });
54
+ return;
55
+ }
41
56
  console.log(`${mark} following ${handle} (${targetDid})`);
42
57
  } catch (err) {
43
- console.error(err instanceof Error ? err.message : String(err));
58
+ const msg = err instanceof Error ? err.message : String(err);
59
+ if (opts.json) {
60
+ jsonError(msg);
61
+ return;
62
+ }
63
+ console.error(msg);
44
64
  process.exitCode = 1;
45
65
  }
46
66
  });
@@ -50,24 +70,39 @@ export default function register(program) {
50
70
  .argument('<handle>', 'Handle to unfollow (e.g. alice.bsky.social)')
51
71
  .description('Remove an account from this project\'s following list')
52
72
  .option('-v, --verbose', 'Show step-by-step details')
73
+ .option('--json', 'Output as JSON')
53
74
  .action(async (handle, opts) => {
54
75
  try {
55
76
  const { verbose } = opts;
77
+ const vlog = opts.json ? (...a) => console.error(...a) : console.log;
56
78
  handle = handle.replace(/^@/, '');
57
79
 
58
80
  const list = readFollowing();
59
81
  const filtered = list.filter(e => e.handle !== handle);
60
82
  if (filtered.length === list.length) {
83
+ if (opts.json) {
84
+ jsonError(`not following ${handle}`);
85
+ return;
86
+ }
61
87
  console.error(`not following ${handle}`);
62
88
  process.exitCode = 1;
63
89
  return;
64
90
  }
65
91
 
66
92
  writeFollowing(filtered);
67
- if (verbose) console.log(`[verbose] removed ${handle} from following list`);
93
+ if (verbose) vlog(`[verbose] removed ${handle} from following list`);
94
+ if (opts.json) {
95
+ jsonOk({ handle });
96
+ return;
97
+ }
68
98
  console.log(`${mark} unfollowed ${handle}`);
69
99
  } catch (err) {
70
- console.error(err instanceof Error ? err.message : String(err));
100
+ const msg = err instanceof Error ? err.message : String(err);
101
+ if (opts.json) {
102
+ jsonError(msg);
103
+ return;
104
+ }
105
+ console.error(msg);
71
106
  process.exitCode = 1;
72
107
  }
73
108
  });
@@ -76,18 +111,32 @@ export default function register(program) {
76
111
  .command('following')
77
112
  .description('List accounts in this project\'s following list')
78
113
  .option('-v, --verbose', 'Show step-by-step details')
79
- .action(async (_opts) => {
114
+ .option('--json', 'Output as JSON')
115
+ .action(async (opts) => {
80
116
  try {
81
117
  const list = readFollowing();
82
118
  if (list.length === 0) {
119
+ if (opts.json) {
120
+ jsonOk({ following: [] });
121
+ return;
122
+ }
83
123
  console.log('no followings');
84
124
  return;
85
125
  }
126
+ if (opts.json) {
127
+ jsonOk({ following: list });
128
+ return;
129
+ }
86
130
  for (const e of list) {
87
131
  console.log(`${e.handle} (${e.did})`);
88
132
  }
89
133
  } catch (err) {
90
- console.error(err instanceof Error ? err.message : String(err));
134
+ const msg = err instanceof Error ? err.message : String(err);
135
+ if (opts.json) {
136
+ jsonError(msg);
137
+ return;
138
+ }
139
+ console.error(msg);
91
140
  process.exitCode = 1;
92
141
  }
93
142
  });