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.
package/src/cmd/skim.js CHANGED
@@ -1,22 +1,26 @@
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 { requireDid } from '../lib/config.js';
5
- import { CAP_COLLECTION } from '../lib/constants.js';
5
+ import { CAP_COLLECTION, SKILL_COLLECTION } from '../lib/constants.js';
6
6
  import { restoreAgent } from '../lib/oauth.js';
7
- import { readProjectConfig, readFollowing } from '../lib/vit-dir.js';
7
+ import { readBeaconSet, readFollowing } from '../lib/vit-dir.js';
8
8
  import { requireAgent } from '../lib/agent.js';
9
9
  import { resolveRef } from '../lib/cap-ref.js';
10
+ import { skillRefFromName } from '../lib/skill-ref.js';
10
11
  import { name } from '../lib/brand.js';
12
+ import { resolvePds, listRecordsFromPds, batchQuery } from '../lib/pds.js';
11
13
 
12
14
  export default function register(program) {
13
15
  program
14
16
  .command('skim')
15
- .description('Read caps from followed accounts, filtered by beacon')
17
+ .description('Read caps and skills from followed accounts')
16
18
  .option('--did <did>', 'DID to use')
17
- .option('--handle <handle>', 'Show caps from a specific handle only')
18
- .option('--limit <n>', 'Max caps to display', '25')
19
+ .option('--handle <handle>', 'Show items from a specific handle only')
20
+ .option('--limit <n>', 'Max items to display', '25')
19
21
  .option('--json', 'Output as JSON array')
22
+ .option('--caps', 'Show only caps')
23
+ .option('--skills', 'Show only skills')
20
24
  .option('-v, --verbose', 'Show step-by-step details')
21
25
  .action(async (opts) => {
22
26
  try {
@@ -33,51 +37,94 @@ export default function register(program) {
33
37
  if (!did) return;
34
38
  if (verbose) console.log(`[verbose] DID: ${did}`);
35
39
 
36
- const projectConfig = readProjectConfig();
37
- const beacon = projectConfig.beacon;
38
- if (!beacon) {
40
+ const beaconSet = readBeaconSet();
41
+
42
+ const wantCaps = !opts.skills;
43
+ const wantSkills = !opts.caps;
44
+ const skillsOnly = opts.skills && !opts.caps;
45
+
46
+ // Beacon required unless --skills only mode
47
+ if (beaconSet.size === 0 && !skillsOnly) {
39
48
  console.error(`no beacon set. run '${name} init' in a project directory first.`);
40
49
  process.exitCode = 1;
41
50
  return;
42
51
  }
43
- if (verbose) console.log(`[verbose] beacon: ${beacon}`);
52
+
53
+ if (verbose && beaconSet.size > 0) console.log(`[verbose] beacons: ${[...beaconSet].join(', ')}`);
44
54
 
45
55
  const { agent } = await restoreAgent(did);
46
56
  if (verbose) console.log('[verbose] session restored');
47
57
 
48
- // build list of DIDs to query
58
+ // build list of DIDs to query and DID→handle map
59
+ const handleMap = new Map();
49
60
  let dids;
50
61
  if (opts.handle) {
51
62
  const handle = opts.handle.replace(/^@/, '');
52
63
  const resolved = await agent.resolveHandle({ handle });
53
64
  dids = [resolved.data.did];
65
+ handleMap.set(resolved.data.did, handle);
54
66
  if (verbose) console.log(`[verbose] resolved ${handle} to ${resolved.data.did}`);
55
67
  } else {
56
68
  const following = readFollowing();
69
+ for (const e of following) handleMap.set(e.did, e.handle);
57
70
  dids = following.map(e => e.did);
58
71
  dids.push(did);
59
- if (verbose) console.log(`[verbose] querying ${dids.length} accounts (${dids.length - 1} follows + self)`);
60
72
  }
61
73
 
62
- // fetch caps from each DID
63
- const allCaps = [];
64
- for (const repoDid of dids) {
74
+ // resolve own handle if not already known
75
+ if (!handleMap.has(did)) {
65
76
  try {
66
- const res = await agent.com.atproto.repo.listRecords({
67
- repo: repoDid,
68
- collection: CAP_COLLECTION,
69
- limit: 50,
70
- });
71
- const caps = res.data.records.filter(r => r.value.beacon === beacon);
72
- if (verbose) console.log(`[verbose] ${repoDid}: ${res.data.records.length} caps, ${caps.length} matching beacon`);
73
- allCaps.push(...caps);
74
- } catch (err) {
75
- if (verbose) console.log(`[verbose] ${repoDid}: error fetching caps: ${err.message}`);
77
+ const desc = await agent.com.atproto.repo.describeRepo({ repo: did });
78
+ handleMap.set(did, desc.data.handle);
79
+ } catch {
80
+ if (verbose) console.log(`[verbose] could not resolve handle for ${did}`);
81
+ }
82
+ }
83
+
84
+ // fetch from each DID
85
+ const allItems = [];
86
+
87
+ const batchResults = await batchQuery(dids, async (repoDid) => {
88
+ const pds = await resolvePds(repoDid);
89
+ if (verbose) console.log(`[verbose] ${repoDid}: resolved PDS ${pds}`);
90
+ const items = [];
91
+
92
+ // Fetch caps (filtered by beacon)
93
+ if (wantCaps && beaconSet.size > 0) {
94
+ const res = await listRecordsFromPds(pds, repoDid, CAP_COLLECTION, 50);
95
+ const caps = res.records.filter(r => beaconSet.has(r.value.beacon));
96
+ if (verbose) console.log(`[verbose] ${repoDid}: ${res.records.length} caps, ${caps.length} matching beacon`);
97
+ for (const cap of caps) {
98
+ cap._handle = handleMap.get(repoDid) || repoDid;
99
+ cap._type = 'cap';
100
+ }
101
+ items.push(...caps);
102
+ }
103
+
104
+ // Fetch skills (unfiltered — skills are universal)
105
+ if (wantSkills) {
106
+ try {
107
+ const res = await listRecordsFromPds(pds, repoDid, SKILL_COLLECTION, 50);
108
+ if (verbose) console.log(`[verbose] ${repoDid}: ${res.records.length} skills`);
109
+ for (const skill of res.records) {
110
+ skill._handle = handleMap.get(repoDid) || repoDid;
111
+ skill._type = 'skill';
112
+ }
113
+ items.push(...res.records);
114
+ } catch (err) {
115
+ if (verbose) console.log(`[verbose] ${repoDid}: error fetching skills: ${err.message}`);
116
+ }
76
117
  }
118
+
119
+ return items;
120
+ }, { verbose });
121
+
122
+ for (const items of batchResults) {
123
+ allItems.push(...items);
77
124
  }
78
125
 
79
126
  // sort by createdAt descending
80
- allCaps.sort((a, b) => {
127
+ allItems.sort((a, b) => {
81
128
  const ta = a.value.createdAt || '';
82
129
  const tb = b.value.createdAt || '';
83
130
  return tb.localeCompare(ta);
@@ -85,25 +132,48 @@ export default function register(program) {
85
132
 
86
133
  // apply limit
87
134
  const limit = parseInt(opts.limit, 10);
88
- const capped = allCaps.slice(0, limit);
135
+ const capped = allItems.slice(0, limit);
89
136
 
90
137
  if (opts.json) {
91
138
  console.log(JSON.stringify(capped, null, 2));
92
139
  } else {
93
140
  if (capped.length === 0) {
94
- console.log('no caps found for this beacon.');
141
+ if (skillsOnly) {
142
+ console.log('no skills found.');
143
+ } else if (opts.caps) {
144
+ console.log('no caps found for this beacon.');
145
+ } else {
146
+ console.log('no caps or skills found.');
147
+ }
95
148
  }
96
149
  for (const rec of capped) {
97
- const ref = resolveRef(rec.value, rec.cid);
98
- const title = rec.value.title || '';
99
- const description = rec.value.description || '';
100
- console.log(`ref: ${ref}`);
101
- if (title) console.log(`title: ${title}`);
102
- if (description) console.log(`description: ${description}`);
103
- console.log();
150
+ if (rec._type === 'skill') {
151
+ const skillRef = skillRefFromName(rec.value.name);
152
+ const skillName = rec.value.name || '';
153
+ const description = rec.value.description || '';
154
+ const version = rec.value.version;
155
+ const tags = rec.value.tags;
156
+ console.log(`ref: ${skillRef}`);
157
+ console.log(`by: @${rec._handle}`);
158
+ console.log(`type: skill${version ? ' v' + version : ''}`);
159
+ if (skillName) console.log(`title: ${skillName}`);
160
+ if (description) console.log(`description: ${description}`);
161
+ if (tags && tags.length > 0) console.log(`tags: ${tags.join(', ')}`);
162
+ console.log();
163
+ } else {
164
+ const ref = resolveRef(rec.value, rec.cid);
165
+ const title = rec.value.title || '';
166
+ const description = rec.value.description || '';
167
+ console.log(`ref: ${ref}`);
168
+ console.log(`by: @${rec._handle}`);
169
+ console.log(`type: cap`);
170
+ if (title) console.log(`title: ${title}`);
171
+ if (description) console.log(`description: ${description}`);
172
+ console.log();
173
+ }
104
174
  }
105
175
  console.log('---');
106
- console.log(`hint: tell your user to run '${name} vet <ref>' in another terminal for any cap they want to review.`);
176
+ console.log(`hint: tell your user to run '${name} vet <ref>' in another terminal for any item they want to review.`);
107
177
  }
108
178
  } catch (err) {
109
179
  console.error(err instanceof Error ? err.message : String(err));