vit 0.3.0 → 0.4.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.
package/src/cmd/learn.js CHANGED
@@ -2,32 +2,244 @@
2
2
  // Copyright (c) 2026 sol pbc
3
3
 
4
4
  import { spawnSync } from 'node:child_process';
5
- import { mkdirSync, writeFileSync, mkdtempSync, rmSync } from 'node:fs';
5
+ import { existsSync, mkdirSync, writeFileSync, mkdtempSync, rmSync } from 'node:fs';
6
6
  import { join, dirname } from 'node:path';
7
7
  import { homedir, tmpdir } from 'node:os';
8
8
  import { requireDid } from '../lib/config.js';
9
9
  import { SKILL_COLLECTION } from '../lib/constants.js';
10
10
  import { restoreAgent } from '../lib/oauth.js';
11
- import { readFollowing, readLog, appendLog } from '../lib/vit-dir.js';
11
+ import { readFollowing, readLog, appendLog, vitDir } from '../lib/vit-dir.js';
12
12
  import { requireAgent, detectCodingAgent } from '../lib/agent.js';
13
13
  import { shouldBypassVet } from '../lib/trust-gate.js';
14
- import { isSkillRef, nameFromSkillRef, isValidSkillRef } from '../lib/skill-ref.js';
14
+ import { isSkillRef, nameFromSkillRef, isValidSkillRef, isValidSkillName } from '../lib/skill-ref.js';
15
15
  import { mark, name } from '../lib/brand.js';
16
- import { resolvePds, listRecordsFromPds, batchQuery } from '../lib/pds.js';
16
+ import { resolvePds, resolveHandle, listRecordsFromPds, batchQuery } from '../lib/pds.js';
17
17
  import { loadConfig } from '../lib/config.js';
18
18
  import { jsonOk, jsonError } from '../lib/json-output.js';
19
+ import { errorMessage, formatError } from '../lib/error-format.js';
20
+
21
+ async function installSkill({ match, skillName, isGlobal, opts, ref }) {
22
+ const { verbose } = opts;
23
+ const vlog = opts.json ? (...a) => console.error(...a) : console.log;
24
+ const record = match.value;
25
+
26
+ const tempDir = mkdtempSync(join(tmpdir(), 'vit-learn-'));
27
+ try {
28
+ writeFileSync(join(tempDir, 'SKILL.md'), record.text);
29
+ if (verbose) vlog('[verbose] wrote SKILL.md to temp dir');
30
+
31
+ if (record.resources && record.resources.length > 0) {
32
+ const authorDid = match.uri.split('/')[2];
33
+ const pds = await resolvePds(authorDid);
34
+
35
+ for (const resource of record.resources) {
36
+ const resourcePath = join(tempDir, resource.path);
37
+ mkdirSync(dirname(resourcePath), { recursive: true });
38
+
39
+ try {
40
+ const blobCid = resource.blob?.ref?.$link || resource.blob?.cid;
41
+ if (blobCid) {
42
+ const blobUrl = new URL('/xrpc/com.atproto.sync.getBlob', pds);
43
+ blobUrl.searchParams.set('did', authorDid);
44
+ blobUrl.searchParams.set('cid', blobCid);
45
+ const blobRes = await fetch(blobUrl);
46
+ if (!blobRes.ok) throw new Error(`blob fetch failed: ${blobRes.status}`);
47
+ const blobData = Buffer.from(await blobRes.arrayBuffer());
48
+ writeFileSync(resourcePath, blobData);
49
+ if (verbose) vlog(`[verbose] wrote resource: ${resource.path}`);
50
+ }
51
+ } catch (err) {
52
+ console.error(`warning: failed to download resource ${resource.path}: ${err.message}`);
53
+ }
54
+ }
55
+ }
56
+
57
+ const addArgs = ['skills', 'add', tempDir, '-a', 'claude-code', '-y'];
58
+ if (isGlobal) addArgs.push('-g');
59
+ const addResult = spawnSync('npx', addArgs, {
60
+ encoding: 'utf-8',
61
+ stdio: ['pipe', 'pipe', 'pipe'],
62
+ });
63
+ if (addResult.status !== 0) {
64
+ const errText = (addResult.stderr || addResult.stdout || '').trim();
65
+ throw new Error(`skill install failed: ${errText || 'unknown error'}`);
66
+ }
67
+ if (verbose) vlog('[verbose] installed via npx skills add');
68
+ } finally {
69
+ try {
70
+ rmSync(tempDir, { recursive: true, force: true });
71
+ } catch (err) {
72
+ console.warn(`warning: failed to remove temporary directory ${tempDir}: ${errorMessage(err)}`);
73
+ }
74
+ }
75
+
76
+ const installDir = isGlobal
77
+ ? join(homedir(), '.claude', 'skills', skillName)
78
+ : join(process.cwd(), '.claude', 'skills', skillName);
79
+
80
+ if (existsSync(vitDir())) {
81
+ try {
82
+ appendLog('learned.jsonl', {
83
+ ref,
84
+ name: skillName,
85
+ uri: match.uri,
86
+ cid: match.cid,
87
+ installedTo: installDir,
88
+ scope: isGlobal ? 'user' : 'project',
89
+ learnedAt: new Date().toISOString(),
90
+ version: record.version || null,
91
+ });
92
+ } catch (logErr) {
93
+ console.error('warning: failed to write learned.jsonl:', logErr.message);
94
+ }
95
+ }
96
+
97
+ const scope = isGlobal ? 'user' : 'project';
98
+ if (opts.json) {
99
+ jsonOk({ ref, name: skillName, installedTo: installDir, scope, version: record.version || null });
100
+ return;
101
+ }
102
+ console.log(`${mark} learned: ${ref} (${scope})`);
103
+ console.log(`installed to: ${installDir}`);
104
+ if (record.version) console.log(`version: ${record.version}`);
105
+ }
106
+
107
+ async function learnFromHandle(ref, opts) {
108
+ const { verbose } = opts;
109
+ const vlog = opts.json ? (...a) => console.error(...a) : console.log;
110
+
111
+ let raw = ref.slice(1);
112
+ let projectLocal = false;
113
+ if (raw.endsWith('.')) {
114
+ projectLocal = true;
115
+ raw = raw.slice(0, -1);
116
+ }
117
+
118
+ const slashIdx = raw.indexOf('/');
119
+ if (slashIdx === -1 || slashIdx === 0 || slashIdx === raw.length - 1) {
120
+ if (opts.json) {
121
+ jsonError('invalid ref', 'expected format: @handle/skill-name');
122
+ return;
123
+ }
124
+ console.error('invalid ref. expected format: @handle/skill-name');
125
+ process.exitCode = 1;
126
+ return;
127
+ }
128
+
129
+ const handle = raw.slice(0, slashIdx);
130
+ const skillName = raw.slice(slashIdx + 1);
131
+
132
+ if (!handle.includes('.')) {
133
+ if (opts.json) {
134
+ jsonError('invalid handle', 'handle must be a domain name (e.g. alice.bsky.social)');
135
+ return;
136
+ }
137
+ console.error('invalid handle. must be a domain name (e.g. alice.bsky.social)');
138
+ process.exitCode = 1;
139
+ return;
140
+ }
141
+
142
+ if (!isValidSkillName(skillName)) {
143
+ if (opts.json) {
144
+ jsonError('invalid skill name', 'lowercase letters, numbers, hyphens only');
145
+ return;
146
+ }
147
+ console.error('invalid skill name. lowercase letters, numbers, hyphens only.');
148
+ console.error('no leading hyphen, no consecutive hyphens, max 64 chars.');
149
+ process.exitCode = 1;
150
+ return;
151
+ }
152
+
153
+ if (verbose) vlog(`[verbose] handle: ${handle}, skill: ${skillName}`);
154
+
155
+ const did = await resolveHandle(handle);
156
+ if (verbose) vlog(`[verbose] resolved DID: ${did}`);
157
+
158
+ const pds = await resolvePds(did);
159
+ if (verbose) vlog(`[verbose] resolved PDS: ${pds}`);
160
+
161
+ const { records } = await listRecordsFromPds(pds, did, SKILL_COLLECTION, 50);
162
+
163
+ let match = null;
164
+ for (const rec of records) {
165
+ if (rec.value.name === skillName) {
166
+ if (!match || (rec.value.createdAt || '') > (match.value.createdAt || '')) {
167
+ match = rec;
168
+ }
169
+ }
170
+ }
171
+
172
+ if (!match) {
173
+ const msg = `no skill '${skillName}' found from @${handle}`;
174
+ if (opts.json) {
175
+ jsonError(msg);
176
+ return;
177
+ }
178
+ console.error(msg);
179
+ process.exitCode = 1;
180
+ return;
181
+ }
182
+
183
+ if (verbose) vlog(`[verbose] found skill: ${match.value.name} from ${match.uri}`);
184
+
185
+ if (opts.dryRun) {
186
+ const record = match.value;
187
+ if (opts.json) {
188
+ jsonOk({
189
+ name: record.name,
190
+ author: handle,
191
+ did,
192
+ description: record.description || null,
193
+ version: record.version || null,
194
+ tags: record.tags || [],
195
+ resources: (record.resources || []).map(r => r.path),
196
+ text: record.text,
197
+ });
198
+ return;
199
+ }
200
+ console.log(`name: ${record.name}`);
201
+ console.log(`author: @${handle} (${did})`);
202
+ if (record.description) console.log(`description: ${record.description}`);
203
+ if (record.version) console.log(`version: ${record.version}`);
204
+ if (record.tags?.length) console.log(`tags: ${record.tags.join(', ')}`);
205
+ if (record.resources?.length) console.log(`resources: ${record.resources.map(r => r.path).join(', ')}`);
206
+ console.log('');
207
+ console.log('--- SKILL.md ---');
208
+ console.log(record.text);
209
+ return;
210
+ }
211
+
212
+ const isGlobal = !(projectLocal || opts.project);
213
+ await installSkill({ match, skillName, isGlobal, opts, ref });
214
+ }
19
215
 
20
216
  export default function register(program) {
21
217
  program
22
218
  .command('learn')
23
- .argument('<ref>', 'Skill reference (e.g. skill-agent-test-patterns)')
24
- .description('Install a skill from the network into your skill directory')
25
- .option('--did <did>', 'DID to use')
26
- .option('--user', 'Install to user-wide ~/.claude/skills/ (requires vet)')
219
+ .argument('<ref>', 'Skill reference: @handle/name or skill-{name}')
220
+ .description('Install a skill from the network')
221
+ .option('--did <did>', 'DID to use (skill-{name} path only)')
222
+ .option('--user', 'Install to user-wide ~/.claude/skills/ (skill-{name} path, requires vet)')
223
+ .option('--project', 'Install to project .claude/skills/ (@handle/ path)')
224
+ .option('--dry-run', 'Show skill contents without installing')
27
225
  .option('--json', 'Output as JSON')
28
226
  .option('-v, --verbose', 'Show step-by-step details')
227
+ .addHelpText('after', `
228
+ Examples:
229
+ vit learn @solpbc.org/using-vit Install from publisher (user-wide)
230
+ vit learn @solpbc.org/using-vit. Install from publisher (project-local)
231
+ vit learn @solpbc.org/using-vit --project Same as trailing dot
232
+ vit learn @solpbc.org/using-vit --dry-run Inspect without installing
233
+ vit learn skill-agent-test-patterns Install from followed accounts (project-local)
234
+ vit learn skill-agent-test-patterns --user Install from followed (user-wide, requires vet)
235
+ `)
29
236
  .action(async (ref, opts) => {
30
237
  try {
238
+ if (ref.startsWith('@')) {
239
+ await learnFromHandle(ref, opts);
240
+ return;
241
+ }
242
+
31
243
  const gate = requireAgent();
32
244
  if (!gate.ok) {
33
245
  if (opts.json) {
@@ -170,92 +382,38 @@ export default function register(program) {
170
382
  const record = match.value;
171
383
  if (verbose) vlog(`[verbose] found skill: ${record.name} from ${match.uri}`);
172
384
 
173
- // Install via skills CLI
174
- const tempDir = mkdtempSync(join(tmpdir(), 'vit-learn-'));
175
- try {
176
- writeFileSync(join(tempDir, 'SKILL.md'), record.text);
177
- if (verbose) vlog('[verbose] wrote SKILL.md to temp dir');
178
-
179
- // Download resource blobs to temp dir
180
- if (record.resources && record.resources.length > 0) {
181
- const authorDid = match.uri.split('/')[2];
182
- const pds = await resolvePds(authorDid);
183
-
184
- for (const resource of record.resources) {
185
- const resourcePath = join(tempDir, resource.path);
186
- mkdirSync(dirname(resourcePath), { recursive: true });
187
-
188
- try {
189
- // Download blob from PDS
190
- const blobCid = resource.blob?.ref?.$link || resource.blob?.cid;
191
- if (blobCid) {
192
- const blobUrl = new URL('/xrpc/com.atproto.sync.getBlob', pds);
193
- blobUrl.searchParams.set('did', authorDid);
194
- blobUrl.searchParams.set('cid', blobCid);
195
- const blobRes = await fetch(blobUrl);
196
- if (!blobRes.ok) throw new Error(`blob fetch failed: ${blobRes.status}`);
197
- const blobData = Buffer.from(await blobRes.arrayBuffer());
198
- writeFileSync(resourcePath, blobData);
199
- if (verbose) vlog(`[verbose] wrote resource: ${resource.path}`);
200
- }
201
- } catch (err) {
202
- console.error(`warning: failed to download resource ${resource.path}: ${err.message}`);
203
- }
204
- }
205
- }
206
-
207
- // Delegate to skills CLI
208
- const addArgs = ['skills', 'add', tempDir, '-a', 'claude-code', '-y'];
209
- if (isUserInstall) addArgs.push('-g');
210
- const addResult = spawnSync('npx', addArgs, {
211
- encoding: 'utf-8',
212
- stdio: ['pipe', 'pipe', 'pipe'],
213
- });
214
- if (addResult.status !== 0) {
215
- const errText = (addResult.stderr || addResult.stdout || '').trim();
216
- throw new Error(`skill install failed: ${errText || 'unknown error'}`);
385
+ if (opts.dryRun) {
386
+ if (opts.json) {
387
+ jsonOk({
388
+ name: record.name,
389
+ author: match.uri.split('/')[2],
390
+ description: record.description || null,
391
+ version: record.version || null,
392
+ tags: record.tags || [],
393
+ resources: (record.resources || []).map(r => r.path),
394
+ text: record.text,
395
+ });
396
+ return;
217
397
  }
218
- if (verbose) vlog('[verbose] installed via npx skills add');
219
- } finally {
220
- try { rmSync(tempDir, { recursive: true, force: true }); } catch {}
221
- }
222
-
223
- // Determine install path for logging
224
- const installDir = isUserInstall
225
- ? join(homedir(), '.claude', 'skills', skillName)
226
- : join(process.cwd(), '.claude', 'skills', skillName);
227
-
228
- // Log to learned.jsonl
229
- try {
230
- appendLog('learned.jsonl', {
231
- ref,
232
- name: skillName,
233
- uri: match.uri,
234
- cid: match.cid,
235
- installedTo: installDir,
236
- scope: isUserInstall ? 'user' : 'project',
237
- learnedAt: new Date().toISOString(),
238
- version: record.version || null,
239
- });
240
- } catch (logErr) {
241
- console.error('warning: failed to write learned.jsonl:', logErr.message);
242
- }
243
-
244
- const scope = isUserInstall ? 'user' : 'project';
245
- if (opts.json) {
246
- jsonOk({ ref, name: skillName, installedTo: installDir, scope, version: record.version || null });
398
+ console.log(`name: ${record.name}`);
399
+ console.log(`author: ${match.uri.split('/')[2]}`);
400
+ if (record.description) console.log(`description: ${record.description}`);
401
+ if (record.version) console.log(`version: ${record.version}`);
402
+ if (record.tags?.length) console.log(`tags: ${record.tags.join(', ')}`);
403
+ if (record.resources?.length) console.log(`resources: ${record.resources.map(r => r.path).join(', ')}`);
404
+ console.log('');
405
+ console.log('--- SKILL.md ---');
406
+ console.log(record.text);
247
407
  return;
248
408
  }
249
- console.log(`${mark} learned: ${ref} (${scope})`);
250
- console.log(`installed to: ${installDir}`);
251
- if (record.version) console.log(`version: ${record.version}`);
409
+
410
+ await installSkill({ match, skillName, isGlobal: !!opts.user, opts, ref });
252
411
  } catch (err) {
253
- const msg = err instanceof Error ? err.message : String(err);
254
412
  if (opts.json) {
255
- jsonError(msg);
413
+ jsonError(err);
256
414
  return;
257
415
  }
258
- console.error(msg);
416
+ console.error(formatError(err, { verbose: opts.verbose }));
259
417
  process.exitCode = 1;
260
418
  }
261
419
  });
package/src/cmd/link.js CHANGED
@@ -4,6 +4,7 @@
4
4
  import { existsSync, mkdirSync, symlinkSync, unlinkSync, readlinkSync, writeFileSync } from 'node:fs';
5
5
  import { join, resolve } from 'node:path';
6
6
  import { mark, name } from '../lib/brand.js';
7
+ import { formatError } from '../lib/error-format.js';
7
8
 
8
9
  export default function register(program) {
9
10
  program
@@ -68,7 +69,7 @@ export default function register(program) {
68
69
  console.log(`${mark} PATH: ok`);
69
70
  }
70
71
  } catch (err) {
71
- console.error(err instanceof Error ? err.message : String(err));
72
+ console.error(formatError(err, { verbose: false }));
72
73
  process.exitCode = 1;
73
74
  }
74
75
  });
package/src/cmd/login.js CHANGED
@@ -11,6 +11,14 @@ import { loadConfig, saveConfig } from '../lib/config.js';
11
11
  import { createOAuthClient, createSessionStore, createStore, checkSession } from '../lib/oauth.js';
12
12
  import { configDir, configPath } from '../lib/paths.js';
13
13
  import { vitDir } from '../lib/vit-dir.js';
14
+ import { errorMessage, formatError } from '../lib/error-format.js';
15
+
16
+ export const LOGIN_COMMON_ISSUES_FOOTER = `Common issues:
17
+ - make sure the handle is correct and resolves on Bluesky
18
+ - open the printed URL in your browser, approve vit, and wait for the callback to finish
19
+ - if you're on a remote machine, rerun with 'vit login <handle> --remote' and paste the full callback URL
20
+ - if you used an app password, create a fresh Bluesky app password and try again
21
+ - check your DNS, firewall, or VPN settings if vit cannot reach Bluesky`;
14
22
 
15
23
  function ensureGitignore(dir, entry) {
16
24
  const gitignorePath = join(dir, '.gitignore');
@@ -21,6 +29,42 @@ function ensureGitignore(dir, entry) {
21
29
  }
22
30
  }
23
31
 
32
+ export function cancelLogin({
33
+ server,
34
+ rl,
35
+ timer,
36
+ clearTimer = clearTimeout,
37
+ stderr = console.error,
38
+ exit = process.exit,
39
+ footer = LOGIN_COMMON_ISSUES_FOOTER,
40
+ }) {
41
+ try {
42
+ if (server?.listening) server.close();
43
+ } catch {
44
+ // Ignore cleanup failures during cancellation.
45
+ }
46
+ try {
47
+ rl?.close();
48
+ } catch {
49
+ // Ignore cleanup failures during cancellation.
50
+ }
51
+ try {
52
+ if (timer) clearTimer(timer);
53
+ } catch {
54
+ // Ignore cleanup failures during cancellation.
55
+ }
56
+ stderr('\nLogin cancelled.');
57
+ stderr(footer);
58
+ exit(130);
59
+ }
60
+
61
+ export function printLoginFailure(err, { verbose = false, includeFooter = false } = {}) {
62
+ console.error(formatError(err, { verbose }));
63
+ if (includeFooter) {
64
+ console.error(LOGIN_COMMON_ISSUES_FOOTER);
65
+ }
66
+ }
67
+
24
68
  export default function register(program) {
25
69
  program
26
70
  .command('login')
@@ -60,7 +104,9 @@ export default function register(program) {
60
104
  return;
61
105
  }
62
106
  }
63
- } catch {}
107
+ } catch (err) {
108
+ console.warn(`warning: failed to read ${localPath}: ${errorMessage(err)}`);
109
+ }
64
110
  }
65
111
  } else {
66
112
  const existing = loadConfig();
@@ -91,7 +137,13 @@ export default function register(program) {
91
137
  } else {
92
138
  const sessionFile = configPath('session.json');
93
139
  let data = {};
94
- try { data = JSON.parse(readFileSync(sessionFile, 'utf-8')); } catch {}
140
+ if (existsSync(sessionFile)) {
141
+ try {
142
+ data = JSON.parse(readFileSync(sessionFile, 'utf-8'));
143
+ } catch (err) {
144
+ console.warn(`warning: failed to read ${sessionFile}: ${errorMessage(err)}`);
145
+ }
146
+ }
95
147
  data[did] = { type: 'app-password', service: 'https://bsky.social', session };
96
148
  mkdirSync(configDir, { recursive: true });
97
149
  writeFileSync(sessionFile, JSON.stringify(data, null, 2) + '\n');
@@ -102,7 +154,7 @@ export default function register(program) {
102
154
 
103
155
  console.log(`Logged in as ${did}`);
104
156
  } catch (err) {
105
- console.error(err instanceof Error ? err.message : String(err));
157
+ printLoginFailure(err, { verbose: opts.verbose, includeFooter: true });
106
158
  process.exitCode = 1;
107
159
  }
108
160
  return;
@@ -111,6 +163,8 @@ export default function register(program) {
111
163
  let server;
112
164
  let timeout;
113
165
  let rl;
166
+ let loginStage = 'preflight';
167
+ let onSigint = () => {};
114
168
 
115
169
  try {
116
170
  let resolveCallback;
@@ -139,6 +193,12 @@ export default function register(program) {
139
193
  res.end('Not found');
140
194
  });
141
195
 
196
+ onSigint = () => {
197
+ process.off('SIGINT', onSigint);
198
+ cancelLogin({ server, rl, timer: timeout });
199
+ };
200
+ process.once('SIGINT', onSigint);
201
+
142
202
  await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
143
203
  const port = server.address().port;
144
204
 
@@ -156,6 +216,7 @@ export default function register(program) {
156
216
  const sessionStore = createSessionStore();
157
217
  const client = createOAuthClient({ stateStore, sessionStore, redirectUri });
158
218
 
219
+ loginStage = 'authorize';
159
220
  const authUrl = await client.authorize(handle, {
160
221
  scope: 'atproto transition:generic',
161
222
  });
@@ -182,6 +243,7 @@ export default function register(program) {
182
243
  console.log(`Open this URL in your browser:\n ${authUrl.toString()}\n`);
183
244
  }
184
245
 
246
+ loginStage = 'callback';
185
247
  if (isRemote) {
186
248
  rl = createInterface({ input: process.stdin, output: process.stdout });
187
249
  rl.question('Paste the callback URL from your browser: ', (line) => {
@@ -229,6 +291,7 @@ export default function register(program) {
229
291
  }
230
292
 
231
293
  console.log('Exchanging token...');
294
+ loginStage = 'token';
232
295
  const { session } = await client.callback(params);
233
296
 
234
297
  if (verbose) {
@@ -247,9 +310,13 @@ export default function register(program) {
247
310
  }
248
311
  console.log(`Logged in as ${session.did}`);
249
312
  } catch (err) {
250
- console.error(err instanceof Error ? err.message : String(err));
313
+ printLoginFailure(err, {
314
+ verbose: opts.verbose,
315
+ includeFooter: loginStage !== 'preflight',
316
+ });
251
317
  process.exitCode = 1;
252
318
  } finally {
319
+ process.removeListener('SIGINT', onSigint);
253
320
  if (timeout) {
254
321
  clearTimeout(timeout);
255
322
  }
package/src/cmd/remix.js CHANGED
@@ -12,6 +12,7 @@ import { brand, name } from '../lib/brand.js';
12
12
  import { resolvePds, listRecordsFromPds, batchQuery } from '../lib/pds.js';
13
13
  import { loadConfig } from '../lib/config.js';
14
14
  import { jsonOk, jsonError } from '../lib/json-output.js';
15
+ import { formatError } from '../lib/error-format.js';
15
16
 
16
17
  export default function register(program) {
17
18
  program
@@ -173,12 +174,11 @@ export default function register(program) {
173
174
  console.log('');
174
175
  console.log(text);
175
176
  } catch (err) {
176
- const msg = err instanceof Error ? err.message : String(err);
177
177
  if (opts.json) {
178
- jsonError(msg);
178
+ jsonError(err);
179
179
  return;
180
180
  }
181
- console.error(msg);
181
+ console.error(formatError(err, { verbose: opts.verbose }));
182
182
  process.exitCode = 1;
183
183
  }
184
184
  });
package/src/cmd/scan.js CHANGED
@@ -7,6 +7,7 @@ import { resolveHandleFromDid } from '../lib/pds.js';
7
7
  import { brand } from '../lib/brand.js';
8
8
  import { jsonOk, jsonError } from '../lib/json-output.js';
9
9
  import { readBeaconSet } from '../lib/vit-dir.js';
10
+ import { formatError } from '../lib/error-format.js';
10
11
 
11
12
  export default function register(program) {
12
13
  program
@@ -91,7 +92,12 @@ export default function register(program) {
91
92
 
92
93
  ws.onmessage = (event) => {
93
94
  let msg;
94
- try { msg = JSON.parse(event.data); } catch { return; }
95
+ try {
96
+ msg = JSON.parse(event.data);
97
+ } catch {
98
+ console.warn('warning: failed to parse Jetstream event as JSON; skipping');
99
+ return;
100
+ }
95
101
 
96
102
  if (msg.kind !== 'commit' || msg.commit?.operation !== 'create') return;
97
103
 
@@ -197,12 +203,11 @@ export default function register(program) {
197
203
  console.log(` ${parts.join(' ')}`);
198
204
  }
199
205
  } catch (err) {
200
- const msg = err instanceof Error ? err.message : String(err);
201
206
  if (opts.json) {
202
- jsonError(msg);
207
+ jsonError(err);
203
208
  return;
204
209
  }
205
- console.error(msg);
210
+ console.error(formatError(err, { verbose: opts.verbose }));
206
211
  process.exitCode = 1;
207
212
  }
208
213
  });
package/src/cmd/ship.js CHANGED
@@ -16,6 +16,7 @@ import { resolvePds, listRecordsFromPds, batchQuery } from '../lib/pds.js';
16
16
  import { jsonOk, jsonError } from '../lib/json-output.js';
17
17
  import { toBeacon } from '../lib/beacon.js';
18
18
  import { hashTo3Words } from '../lib/cap-ref.js';
19
+ import { formatError } from '../lib/error-format.js';
19
20
 
20
21
  const STOP_WORDS = new Set([
21
22
  'a', 'an', 'the', 'and', 'or', 'but', 'in', 'on', 'at', 'to', 'for',
@@ -664,12 +665,11 @@ export default function register(program) {
664
665
  await shipCap(opts);
665
666
  }
666
667
  } catch (err) {
667
- const msg = err instanceof Error ? err.message : String(err);
668
668
  if (opts.json) {
669
- jsonError(msg);
669
+ jsonError(err);
670
670
  return;
671
671
  }
672
- console.error(msg);
672
+ console.error(formatError(err, { verbose: opts.verbose }));
673
673
  process.exitCode = 1;
674
674
  }
675
675
  })
package/src/cmd/skim.js CHANGED
@@ -10,6 +10,8 @@ import { resolveRef } from '../lib/cap-ref.js';
10
10
  import { skillRefFromName } from '../lib/skill-ref.js';
11
11
  import { name } from '../lib/brand.js';
12
12
  import { resolvePds, listRecordsFromPds, batchQuery } from '../lib/pds.js';
13
+ import { jsonError } from '../lib/json-output.js';
14
+ import { formatError } from '../lib/error-format.js';
13
15
 
14
16
  export default function register(program) {
15
17
  program
@@ -208,7 +210,11 @@ export default function register(program) {
208
210
  }
209
211
  }
210
212
  } catch (err) {
211
- console.error(err instanceof Error ? err.message : String(err));
213
+ if (opts.json) {
214
+ jsonError(err);
215
+ return;
216
+ }
217
+ console.error(formatError(err, { verbose: opts.verbose }));
212
218
  process.exitCode = 1;
213
219
  }
214
220
  });
package/src/cmd/vet.js CHANGED
@@ -17,6 +17,7 @@ import { resolvePds, listRecordsFromPds, batchQuery } from '../lib/pds.js';
17
17
  import { loadConfig } from '../lib/config.js';
18
18
  import { jsonOk, jsonError } from '../lib/json-output.js';
19
19
  import { sandboxArgs } from '../lib/sandbox.js';
20
+ import { formatError } from '../lib/error-format.js';
20
21
 
21
22
  const execFileAsync = promisify(execFile);
22
23
 
@@ -629,12 +630,11 @@ export default function register(program) {
629
630
  console.log(` vit vet ${ref} --trust`);
630
631
  }
631
632
  } catch (err) {
632
- const msg = err instanceof Error ? err.message : String(err);
633
633
  if (opts.json) {
634
- jsonError(msg);
634
+ jsonError(err);
635
635
  return;
636
636
  }
637
- console.error(msg);
637
+ console.error(formatError(err, { verbose: opts.verbose }));
638
638
  process.exitCode = 1;
639
639
  }
640
640
  });