vit 0.1.0 → 0.2.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/LICENSE +21 -661
- package/README.md +55 -78
- package/bin/vit.js +1 -1
- package/package.json +10 -3
- package/skills/vit/COMMANDS.md +270 -0
- package/skills/vit/SKILL.md +203 -0
- package/src/cli.js +13 -3
- package/src/cmd/adopt.js +1 -1
- package/src/cmd/beacon.js +3 -2
- package/src/cmd/config.js +7 -2
- package/src/cmd/doctor.js +143 -20
- package/src/cmd/explore.js +483 -0
- package/src/cmd/firehose.js +20 -9
- package/src/cmd/follow.js +63 -11
- package/src/cmd/hack.js +83 -0
- package/src/cmd/inbox.js +131 -0
- package/src/cmd/init.js +95 -13
- package/src/cmd/learn.js +262 -0
- package/src/cmd/link.js +75 -0
- package/src/cmd/login.js +95 -13
- package/src/cmd/remix.js +86 -37
- package/src/cmd/scan.js +209 -0
- package/src/cmd/ship.js +665 -149
- package/src/cmd/skim.js +140 -38
- package/src/cmd/vet.js +597 -97
- package/src/cmd/vouch.js +269 -89
- package/src/lib/agent.js +11 -1
- package/src/lib/beacon.js +1 -1
- package/src/lib/brand.js +1 -1
- package/src/lib/cap-ref.js +1 -1
- package/src/lib/compat.js +1 -1
- package/src/lib/config.js +11 -2
- package/src/lib/constants.js +4 -1
- package/src/lib/json-output.js +13 -0
- package/src/lib/oauth.js +49 -6
- package/src/lib/paths.js +1 -1
- package/src/lib/pds.js +79 -0
- package/src/lib/sandbox.js +1 -1
- package/src/lib/skill-ref.js +37 -0
- package/src/lib/trust-gate.js +39 -0
- package/src/lib/vit-dir.js +9 -1
- package/src/postinstall.js +26 -0
- package/src/cmd/setup.js +0 -76
package/src/cmd/vouch.js
CHANGED
|
@@ -1,77 +1,234 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
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, VOUCH_COLLECTION } from '../lib/constants.js';
|
|
5
|
+
import { CAP_COLLECTION, SKILL_COLLECTION, VOUCH_COLLECTION } from '../lib/constants.js';
|
|
6
6
|
import { TID } from '@atproto/common-web';
|
|
7
7
|
import { restoreAgent } from '../lib/oauth.js';
|
|
8
|
-
import { appendLog,
|
|
8
|
+
import { appendLog, readBeaconSet, readFollowing, readLog } from '../lib/vit-dir.js';
|
|
9
9
|
import { resolveRef, REF_PATTERN } from '../lib/cap-ref.js';
|
|
10
|
+
import { isSkillRef, isValidSkillRef, nameFromSkillRef } from '../lib/skill-ref.js';
|
|
10
11
|
import { mark, name } from '../lib/brand.js';
|
|
12
|
+
import { resolvePds, listRecordsFromPds, batchQuery } from '../lib/pds.js';
|
|
13
|
+
import { loadConfig } from '../lib/config.js';
|
|
14
|
+
import { jsonOk, jsonError } from '../lib/json-output.js';
|
|
11
15
|
|
|
12
16
|
export default function register(program) {
|
|
13
17
|
program
|
|
14
18
|
.command('vouch')
|
|
15
|
-
.argument('<ref>', '
|
|
16
|
-
.description('Publicly endorse a vetted cap')
|
|
19
|
+
.argument('<ref>', 'Cap or skill reference (e.g. fast-cache-invalidation or skill-agent-test-patterns)')
|
|
20
|
+
.description('Publicly endorse a vetted cap or skill, or signal demand with --kind want')
|
|
17
21
|
.option('--did <did>', 'DID to use')
|
|
22
|
+
.option('--kind <kind>', 'Vouch intent: endorse (default, quality signal) or want (demand signal)')
|
|
23
|
+
.option('--json', 'Output as JSON')
|
|
18
24
|
.option('-v, --verbose', 'Show step-by-step details')
|
|
19
25
|
.action(async (ref, opts) => {
|
|
20
26
|
try {
|
|
21
27
|
const { verbose } = opts;
|
|
28
|
+
const vlog = opts.json ? (...a) => console.error(...a) : console.log;
|
|
29
|
+
const isSkill = isSkillRef(ref);
|
|
22
30
|
|
|
23
|
-
if
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
// Validate --kind if provided
|
|
32
|
+
if (opts.kind) {
|
|
33
|
+
const validVouchKinds = ['endorse', 'want'];
|
|
34
|
+
if (!validVouchKinds.includes(opts.kind)) {
|
|
35
|
+
if (opts.json) {
|
|
36
|
+
jsonError(`--kind must be one of: ${validVouchKinds.join(', ')}`);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
console.error(`error: --kind must be one of: ${validVouchKinds.join(', ')}`);
|
|
40
|
+
process.exitCode = 1;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
27
43
|
}
|
|
28
44
|
|
|
29
|
-
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
// Validate ref format
|
|
46
|
+
if (isSkill) {
|
|
47
|
+
if (!isValidSkillRef(ref)) {
|
|
48
|
+
if (opts.json) {
|
|
49
|
+
jsonError('invalid skill ref', 'expected format: skill-{name}');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
console.error('invalid skill ref. expected format: skill-{name} (lowercase letters, numbers, hyphens)');
|
|
53
|
+
process.exitCode = 1;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
if (!REF_PATTERN.test(ref)) {
|
|
58
|
+
if (opts.json) {
|
|
59
|
+
jsonError('invalid ref', 'expected three lowercase words with dashes');
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
console.error('invalid ref. expected three lowercase words with dashes (e.g. fast-cache-invalidation)');
|
|
63
|
+
process.exitCode = 1;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
39
66
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const trustedEntry = trusted.find(e => e.ref === ref);
|
|
44
|
-
if (!trustedEntry) {
|
|
45
|
-
console.error(`cap '${ref}' is not yet vetted. vet it first:`);
|
|
46
|
-
console.error('');
|
|
47
|
-
console.error(` vit vet ${ref}`);
|
|
48
|
-
console.error('');
|
|
49
|
-
console.error('after reviewing, trust it with:');
|
|
50
|
-
console.error('');
|
|
51
|
-
console.error(` vit vet ${ref} --trust`);
|
|
52
|
-
process.exitCode = 1;
|
|
67
|
+
|
|
68
|
+
if (opts.json && !(opts.did || loadConfig().did)) {
|
|
69
|
+
jsonError('no DID configured', "run 'vit login <handle>' first");
|
|
53
70
|
return;
|
|
54
71
|
}
|
|
55
|
-
|
|
72
|
+
const did = requireDid(opts);
|
|
73
|
+
if (!did) return;
|
|
74
|
+
if (verbose) vlog(`[verbose] DID: ${did}`);
|
|
56
75
|
|
|
57
|
-
|
|
58
|
-
|
|
76
|
+
if (isSkill) {
|
|
77
|
+
// Skill vouch — no beacon required, check trusted first
|
|
78
|
+
const trusted = readLog('trusted.jsonl');
|
|
79
|
+
const trustedEntry = trusted.find(e => e.ref === ref);
|
|
80
|
+
if (!trustedEntry) {
|
|
81
|
+
if (opts.json) {
|
|
82
|
+
jsonError(`skill '${ref}' is not yet vetted`, `run 'vit vet ${ref}' first`);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
console.error(`skill '${ref}' is not yet vetted. vet it first:`);
|
|
86
|
+
console.error('');
|
|
87
|
+
console.error(` vit vet ${ref}`);
|
|
88
|
+
console.error('');
|
|
89
|
+
console.error('after reviewing, trust it with:');
|
|
90
|
+
console.error('');
|
|
91
|
+
console.error(` vit vet ${ref} --trust`);
|
|
92
|
+
process.exitCode = 1;
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (verbose) vlog(`[verbose] trusted entry found, uri: ${trustedEntry.uri}`);
|
|
59
96
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
97
|
+
const skillName = nameFromSkillRef(ref);
|
|
98
|
+
|
|
99
|
+
const { agent } = await restoreAgent(did);
|
|
100
|
+
if (verbose) vlog('[verbose] session restored');
|
|
101
|
+
|
|
102
|
+
const following = readFollowing();
|
|
103
|
+
const dids = following.map(e => e.did);
|
|
104
|
+
dids.push(did);
|
|
105
|
+
|
|
106
|
+
const allRecords = await batchQuery(dids, async (repoDid) => {
|
|
107
|
+
const pds = await resolvePds(repoDid);
|
|
108
|
+
if (verbose) vlog(`[verbose] ${repoDid}: resolved PDS ${pds}`);
|
|
109
|
+
return (await listRecordsFromPds(pds, repoDid, SKILL_COLLECTION, 50)).records;
|
|
110
|
+
}, { verbose });
|
|
111
|
+
|
|
112
|
+
let match = null;
|
|
113
|
+
for (const records of allRecords) {
|
|
114
|
+
for (const rec of records) {
|
|
115
|
+
if (rec.value.name === skillName) {
|
|
116
|
+
if (!match || (rec.value.createdAt || '') > (match.value.createdAt || '')) {
|
|
117
|
+
match = rec;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (!match) {
|
|
124
|
+
if (opts.json) {
|
|
125
|
+
jsonError(`no skill found with ref '${ref}'`);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
console.error(`no skill found with ref '${ref}' from followed accounts.`);
|
|
129
|
+
console.error('');
|
|
130
|
+
console.error('hint: skills appear from accounts you follow and your own.');
|
|
131
|
+
console.error(` vit following check who you're following`);
|
|
132
|
+
console.error(` vit explore skills browse skills network-wide`);
|
|
133
|
+
process.exitCode = 1;
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const now = new Date().toISOString();
|
|
138
|
+
const vouchRecord = {
|
|
139
|
+
$type: VOUCH_COLLECTION,
|
|
140
|
+
subject: {
|
|
141
|
+
uri: match.uri,
|
|
142
|
+
cid: match.cid,
|
|
143
|
+
},
|
|
144
|
+
createdAt: now,
|
|
145
|
+
ref,
|
|
146
|
+
// No beacon for skill vouches
|
|
147
|
+
};
|
|
148
|
+
if (verbose) vlog(`[verbose] creating vouch for ${match.uri}`);
|
|
149
|
+
const rkey = TID.nextStr();
|
|
150
|
+
const res = await agent.com.atproto.repo.putRecord({
|
|
151
|
+
repo: did,
|
|
152
|
+
collection: VOUCH_COLLECTION,
|
|
153
|
+
rkey,
|
|
154
|
+
record: vouchRecord,
|
|
155
|
+
validate: true,
|
|
156
|
+
});
|
|
64
157
|
|
|
65
|
-
let match = null;
|
|
66
|
-
for (const repoDid of dids) {
|
|
67
158
|
try {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
159
|
+
appendLog('vouched.jsonl', {
|
|
160
|
+
ref,
|
|
161
|
+
uri: match.uri,
|
|
162
|
+
cid: match.cid,
|
|
163
|
+
vouchUri: res.data.uri,
|
|
164
|
+
ts: now,
|
|
72
165
|
});
|
|
73
|
-
|
|
74
|
-
|
|
166
|
+
} catch (logErr) {
|
|
167
|
+
console.error('warning: failed to write vouched.jsonl:', logErr.message);
|
|
168
|
+
}
|
|
169
|
+
if (verbose) vlog('[verbose] logged to vouched.jsonl');
|
|
170
|
+
|
|
171
|
+
if (opts.json) {
|
|
172
|
+
jsonOk({ ref, uri: match.uri, vouchUri: res.data.uri });
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
console.log(`${mark} vouched: ${ref} (${match.uri})`);
|
|
176
|
+
} else {
|
|
177
|
+
const vouchKind = opts.kind || 'endorse';
|
|
178
|
+
const isWant = vouchKind === 'want';
|
|
179
|
+
|
|
180
|
+
// Cap vouch — beacon required unless want-vouching (demand signal)
|
|
181
|
+
const beaconSet = readBeaconSet();
|
|
182
|
+
|
|
183
|
+
if (!isWant) {
|
|
184
|
+
if (beaconSet.size === 0) {
|
|
185
|
+
if (opts.json) {
|
|
186
|
+
jsonError('no beacon set', "run 'vit init' first");
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
console.error(`no beacon set. run '${name} init' in a project directory first.`);
|
|
190
|
+
process.exitCode = 1;
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (verbose) vlog(`[verbose] beacons: ${[...beaconSet].join(', ')}`);
|
|
194
|
+
|
|
195
|
+
const trusted = readLog('trusted.jsonl');
|
|
196
|
+
const trustedEntry = trusted.find(e => e.ref === ref);
|
|
197
|
+
if (!trustedEntry) {
|
|
198
|
+
if (opts.json) {
|
|
199
|
+
jsonError(`cap '${ref}' is not yet vetted`, `run 'vit vet ${ref}' first`);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
console.error(`cap '${ref}' is not yet vetted. vet it first:`);
|
|
203
|
+
console.error('');
|
|
204
|
+
console.error(` vit vet ${ref}`);
|
|
205
|
+
console.error('');
|
|
206
|
+
console.error('after reviewing, trust it with:');
|
|
207
|
+
console.error('');
|
|
208
|
+
console.error(` vit vet ${ref} --trust`);
|
|
209
|
+
process.exitCode = 1;
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (verbose) vlog(`[verbose] trusted entry found, uri: ${trustedEntry.uri}`);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const { agent } = await restoreAgent(did);
|
|
216
|
+
if (verbose) vlog('[verbose] session restored');
|
|
217
|
+
|
|
218
|
+
const following = readFollowing();
|
|
219
|
+
const dids = following.map(e => e.did);
|
|
220
|
+
dids.push(did);
|
|
221
|
+
|
|
222
|
+
const allRecords = await batchQuery(dids, async (repoDid) => {
|
|
223
|
+
const pds = await resolvePds(repoDid);
|
|
224
|
+
if (verbose) vlog(`[verbose] ${repoDid}: resolved PDS ${pds}`);
|
|
225
|
+
return (await listRecordsFromPds(pds, repoDid, CAP_COLLECTION, 50)).records;
|
|
226
|
+
}, { verbose });
|
|
227
|
+
|
|
228
|
+
let match = null;
|
|
229
|
+
for (const records of allRecords) {
|
|
230
|
+
for (const rec of records) {
|
|
231
|
+
if (!isWant && !beaconSet.has(rec.value.beacon)) continue;
|
|
75
232
|
const recRef = resolveRef(rec.value, rec.cid);
|
|
76
233
|
if (recRef === ref) {
|
|
77
234
|
if (!match || (rec.value.createdAt || '') > (match.value.createdAt || '')) {
|
|
@@ -79,55 +236,78 @@ export default function register(program) {
|
|
|
79
236
|
}
|
|
80
237
|
}
|
|
81
238
|
}
|
|
82
|
-
} catch (err) {
|
|
83
|
-
if (verbose) console.log(`[verbose] ${repoDid}: error fetching caps: ${err.message}`);
|
|
84
239
|
}
|
|
85
|
-
}
|
|
86
240
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
241
|
+
if (!match) {
|
|
242
|
+
if (opts.json) {
|
|
243
|
+
jsonError(`no cap found with ref '${ref}'${!isWant ? ' for this beacon' : ''}`);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
console.error(`no cap found with ref '${ref}'${!isWant ? ' for this beacon' : ''}.`);
|
|
247
|
+
console.error('');
|
|
248
|
+
console.error('hint: caps only appear from accounts you follow and your own.');
|
|
249
|
+
console.error(` vit following check who you're following`);
|
|
250
|
+
console.error(` vit explore cap ${ref} search the network-wide index`);
|
|
251
|
+
process.exitCode = 1;
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
92
254
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
beacon,
|
|
103
|
-
};
|
|
104
|
-
if (verbose) console.log(`[verbose] creating vouch for ${match.uri}`);
|
|
105
|
-
const rkey = TID.nextStr();
|
|
106
|
-
const res = await agent.com.atproto.repo.putRecord({
|
|
107
|
-
repo: did,
|
|
108
|
-
collection: VOUCH_COLLECTION,
|
|
109
|
-
rkey,
|
|
110
|
-
record: vouchRecord,
|
|
111
|
-
validate: false,
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
try {
|
|
115
|
-
appendLog('vouched.jsonl', {
|
|
255
|
+
const now = new Date().toISOString();
|
|
256
|
+
const projBeacon = beaconSet.size > 0 ? [...beaconSet][0] : (match.value.beacon || null);
|
|
257
|
+
const vouchRecord = {
|
|
258
|
+
$type: VOUCH_COLLECTION,
|
|
259
|
+
subject: {
|
|
260
|
+
uri: match.uri,
|
|
261
|
+
cid: match.cid,
|
|
262
|
+
},
|
|
263
|
+
createdAt: now,
|
|
116
264
|
ref,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
265
|
+
kind: vouchKind,
|
|
266
|
+
};
|
|
267
|
+
if (projBeacon) vouchRecord.beacon = projBeacon;
|
|
268
|
+
if (verbose) vlog(`[verbose] creating vouch (${vouchKind}) for ${match.uri}`);
|
|
269
|
+
const rkey = TID.nextStr();
|
|
270
|
+
const res = await agent.com.atproto.repo.putRecord({
|
|
271
|
+
repo: did,
|
|
272
|
+
collection: VOUCH_COLLECTION,
|
|
273
|
+
rkey,
|
|
274
|
+
record: vouchRecord,
|
|
275
|
+
validate: false,
|
|
122
276
|
});
|
|
123
|
-
} catch (logErr) {
|
|
124
|
-
console.error('warning: failed to write vouched.jsonl:', logErr.message);
|
|
125
|
-
}
|
|
126
|
-
if (verbose) console.log('[verbose] logged to vouched.jsonl');
|
|
127
277
|
|
|
128
|
-
|
|
278
|
+
try {
|
|
279
|
+
appendLog('vouched.jsonl', {
|
|
280
|
+
ref,
|
|
281
|
+
uri: match.uri,
|
|
282
|
+
cid: match.cid,
|
|
283
|
+
vouchUri: res.data.uri,
|
|
284
|
+
kind: vouchKind,
|
|
285
|
+
beacon: projBeacon,
|
|
286
|
+
ts: now,
|
|
287
|
+
});
|
|
288
|
+
} catch (logErr) {
|
|
289
|
+
console.error('warning: failed to write vouched.jsonl:', logErr.message);
|
|
290
|
+
}
|
|
291
|
+
if (verbose) vlog('[verbose] logged to vouched.jsonl');
|
|
292
|
+
|
|
293
|
+
if (opts.json) {
|
|
294
|
+
jsonOk({ ref, uri: match.uri, vouchUri: res.data.uri, kind: vouchKind });
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (isWant) {
|
|
298
|
+
console.log(`${mark} vouched (want): ${ref}`);
|
|
299
|
+
console.log(` demand signal recorded. vouch count visible in vit explore vouches.`);
|
|
300
|
+
} else {
|
|
301
|
+
console.log(`${mark} vouched: ${ref} (${match.uri})`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
129
304
|
} catch (err) {
|
|
130
|
-
|
|
305
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
306
|
+
if (opts.json) {
|
|
307
|
+
jsonError(msg);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
console.error(msg);
|
|
131
311
|
process.exitCode = 1;
|
|
132
312
|
}
|
|
133
313
|
});
|
package/src/lib/agent.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Copyright (c) 2026 sol pbc
|
|
3
3
|
|
|
4
4
|
const CODING_AGENTS = {
|
|
@@ -25,3 +25,13 @@ export function requireNotAgent() {
|
|
|
25
25
|
if (!agent) return { ok: true };
|
|
26
26
|
return { ok: false, ...agent };
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
const SANDBOX_NAMES = {
|
|
30
|
+
'claude code': 'claude',
|
|
31
|
+
'gemini cli': 'gemini',
|
|
32
|
+
'codex': 'codex',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export function toSandboxName(agentName) {
|
|
36
|
+
return SANDBOX_NAMES[agentName] || null;
|
|
37
|
+
}
|
package/src/lib/beacon.js
CHANGED
package/src/lib/brand.js
CHANGED
package/src/lib/cap-ref.js
CHANGED
package/src/lib/compat.js
CHANGED
package/src/lib/config.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Copyright (c) 2026 sol pbc
|
|
3
3
|
|
|
4
4
|
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
5
|
+
import { join } from 'node:path';
|
|
5
6
|
import { configDir, configPath } from './paths.js';
|
|
6
7
|
|
|
7
8
|
const vitJsonPath = configPath('vit.json');
|
|
@@ -24,7 +25,15 @@ export function saveConfig(obj) {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export function requireDid(opts) {
|
|
27
|
-
|
|
28
|
+
if (opts?.did) return opts.did;
|
|
29
|
+
try {
|
|
30
|
+
const localLogin = join(process.cwd(), '.vit', 'login.json');
|
|
31
|
+
if (existsSync(localLogin)) {
|
|
32
|
+
const local = JSON.parse(readFileSync(localLogin, 'utf-8'));
|
|
33
|
+
if (local.did) return local.did;
|
|
34
|
+
}
|
|
35
|
+
} catch {}
|
|
36
|
+
const did = loadConfig().did;
|
|
28
37
|
if (!did) {
|
|
29
38
|
console.error("no DID configured. run 'vit login <handle>' first or pass --did.");
|
|
30
39
|
process.exitCode = 1;
|
package/src/lib/constants.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Copyright (c) 2026 sol pbc
|
|
3
3
|
|
|
4
4
|
export const CAP_COLLECTION = 'org.v-it.cap';
|
|
5
5
|
export const VOUCH_COLLECTION = 'org.v-it.vouch';
|
|
6
|
+
export const SKILL_COLLECTION = 'org.v-it.skill';
|
|
7
|
+
export const DEFAULT_JETSTREAM_URL = 'wss://jetstream2.us-east.bsky.network/subscribe';
|
|
8
|
+
export const DEFAULT_EXPLORE_URL = 'https://explore.v-it.org';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
export function jsonOk(data) {
|
|
5
|
+
console.log(JSON.stringify({ ok: true, ...data }, null, 2));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function jsonError(error, hint) {
|
|
9
|
+
const obj = { ok: false, error };
|
|
10
|
+
if (hint) obj.hint = hint;
|
|
11
|
+
console.log(JSON.stringify(obj, null, 2));
|
|
12
|
+
process.exitCode = 1;
|
|
13
|
+
}
|
package/src/lib/oauth.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Copyright (c) 2026 sol pbc
|
|
3
3
|
|
|
4
|
-
import { Agent } from '@atproto/api';
|
|
4
|
+
import { Agent, AtpAgent } from '@atproto/api';
|
|
5
5
|
import { NodeOAuthClient } from '@atproto/oauth-client-node';
|
|
6
|
-
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
6
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
7
|
+
import { join } from 'node:path';
|
|
7
8
|
import { configDir, configPath } from './paths.js';
|
|
8
9
|
|
|
9
10
|
const requestLock = async (_name, fn) => await fn();
|
|
@@ -62,13 +63,29 @@ export function createSessionStore() {
|
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
export function checkSession(did) {
|
|
66
|
+
// Check project-local app-password session
|
|
67
|
+
try {
|
|
68
|
+
const localPath = join(process.cwd(), '.vit', 'login.json');
|
|
69
|
+
if (existsSync(localPath)) {
|
|
70
|
+
const local = JSON.parse(readFileSync(localPath, 'utf-8'));
|
|
71
|
+
if (local.did === did && local.type === 'app-password' && local.session?.accessJwt) {
|
|
72
|
+
return did;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
} catch {}
|
|
76
|
+
|
|
65
77
|
try {
|
|
66
78
|
const raw = readFileSync(configPath('session.json'), 'utf-8');
|
|
67
79
|
const data = JSON.parse(raw);
|
|
68
|
-
const
|
|
80
|
+
const entry = data[did];
|
|
81
|
+
if (!entry) return null;
|
|
82
|
+
// App-password session in global store
|
|
83
|
+
if (entry.type === 'app-password') {
|
|
84
|
+
return entry.session?.accessJwt ? did : null;
|
|
85
|
+
}
|
|
86
|
+
// OAuth session
|
|
87
|
+
const tokenSet = entry?.tokenSet;
|
|
69
88
|
if (!tokenSet) return null;
|
|
70
|
-
// Session is valid if access token is fresh OR a refresh token exists
|
|
71
|
-
// (the library will auto-refresh expired access tokens on restore)
|
|
72
89
|
const accessValid = tokenSet.expires_at && new Date(tokenSet.expires_at) > new Date();
|
|
73
90
|
if (accessValid || tokenSet.refresh_token) return did;
|
|
74
91
|
return null;
|
|
@@ -90,6 +107,32 @@ export function createOAuthClient({ stateStore, sessionStore, redirectUri }) {
|
|
|
90
107
|
}
|
|
91
108
|
|
|
92
109
|
export async function restoreAgent(did) {
|
|
110
|
+
// Check project-local app-password session
|
|
111
|
+
try {
|
|
112
|
+
const localPath = join(process.cwd(), '.vit', 'login.json');
|
|
113
|
+
if (existsSync(localPath)) {
|
|
114
|
+
const local = JSON.parse(readFileSync(localPath, 'utf-8'));
|
|
115
|
+
if (local.did === did && local.type === 'app-password' && local.session) {
|
|
116
|
+
const agent = new AtpAgent({ service: local.service || 'https://bsky.social' });
|
|
117
|
+
await agent.resumeSession(local.session);
|
|
118
|
+
return { agent, session: { did: local.did, handle: local.handle } };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
} catch {}
|
|
122
|
+
|
|
123
|
+
// Check global app-password session
|
|
124
|
+
try {
|
|
125
|
+
const raw = readFileSync(configPath('session.json'), 'utf-8');
|
|
126
|
+
const data = JSON.parse(raw);
|
|
127
|
+
const entry = data[did];
|
|
128
|
+
if (entry?.type === 'app-password' && entry.session) {
|
|
129
|
+
const agent = new AtpAgent({ service: entry.service || 'https://bsky.social' });
|
|
130
|
+
await agent.resumeSession(entry.session);
|
|
131
|
+
return { agent, session: { did, handle: entry.session.handle } };
|
|
132
|
+
}
|
|
133
|
+
} catch {}
|
|
134
|
+
|
|
135
|
+
// Existing OAuth restore path
|
|
93
136
|
const sessionStore = createSessionStore();
|
|
94
137
|
const client = new NodeOAuthClient({
|
|
95
138
|
handleResolver: { resolve() { throw new Error('handle resolution not needed for restore'); } },
|
package/src/lib/paths.js
CHANGED
package/src/lib/pds.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
const PLC_DIRECTORY = 'https://plc.directory';
|
|
5
|
+
const pdsCache = new Map();
|
|
6
|
+
|
|
7
|
+
async function fetchDidDocument(did) {
|
|
8
|
+
let url;
|
|
9
|
+
if (did.startsWith('did:web:')) {
|
|
10
|
+
const rest = did.slice('did:web:'.length);
|
|
11
|
+
const parts = rest.split(':');
|
|
12
|
+
const domain = decodeURIComponent(parts[0]);
|
|
13
|
+
if (parts.length === 1) {
|
|
14
|
+
url = `https://${domain}/.well-known/did.json`;
|
|
15
|
+
} else {
|
|
16
|
+
url = `https://${domain}/${parts.slice(1).map(decodeURIComponent).join('/')}/did.json`;
|
|
17
|
+
}
|
|
18
|
+
} else {
|
|
19
|
+
url = `${PLC_DIRECTORY}/${did}`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const res = await fetch(url);
|
|
23
|
+
if (!res.ok) throw new Error(`failed to resolve DID document for ${did}: ${res.status} ${res.statusText}`);
|
|
24
|
+
return res.json();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function resolvePds(did) {
|
|
28
|
+
if (pdsCache.has(did)) return pdsCache.get(did);
|
|
29
|
+
const doc = await fetchDidDocument(did);
|
|
30
|
+
const pds = doc.service?.find(s => s.type === 'AtprotoPersonalDataServer');
|
|
31
|
+
if (!pds?.serviceEndpoint) throw new Error(`no PDS found in DID document for ${did}`);
|
|
32
|
+
pdsCache.set(did, pds.serviceEndpoint);
|
|
33
|
+
return pds.serviceEndpoint;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export async function listRecordsFromPds(pdsUrl, repo, collection, limit) {
|
|
37
|
+
const records = [];
|
|
38
|
+
let cursor;
|
|
39
|
+
do {
|
|
40
|
+
const url = new URL('/xrpc/com.atproto.repo.listRecords', pdsUrl);
|
|
41
|
+
url.searchParams.set('repo', repo);
|
|
42
|
+
url.searchParams.set('collection', collection);
|
|
43
|
+
if (limit) url.searchParams.set('limit', String(limit));
|
|
44
|
+
if (cursor) url.searchParams.set('cursor', cursor);
|
|
45
|
+
const res = await fetch(url);
|
|
46
|
+
if (!res.ok) throw new Error(`listRecords failed for ${repo}: ${res.status} ${res.statusText}`);
|
|
47
|
+
const data = await res.json();
|
|
48
|
+
records.push(...data.records);
|
|
49
|
+
cursor = data.cursor;
|
|
50
|
+
} while (cursor);
|
|
51
|
+
return { records };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function resolveHandleFromDid(did) {
|
|
55
|
+
try {
|
|
56
|
+
const doc = await fetchDidDocument(did);
|
|
57
|
+
const aka = doc.alsoKnownAs?.find(a => a.startsWith('at://'));
|
|
58
|
+
return aka ? aka.replace('at://', '') : did;
|
|
59
|
+
} catch {
|
|
60
|
+
return did;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function batchQuery(items, fn, { batchSize = 10, verbose = false } = {}) {
|
|
65
|
+
if (verbose) console.log(`[verbose] querying ${items.length} accounts in batches of ${batchSize}`);
|
|
66
|
+
const results = [];
|
|
67
|
+
for (let i = 0; i < items.length; i += batchSize) {
|
|
68
|
+
const chunk = items.slice(i, i + batchSize);
|
|
69
|
+
const settled = await Promise.allSettled(chunk.map(fn));
|
|
70
|
+
for (let j = 0; j < settled.length; j++) {
|
|
71
|
+
if (settled[j].status === 'fulfilled' && settled[j].value !== undefined) {
|
|
72
|
+
results.push(settled[j].value);
|
|
73
|
+
} else if (settled[j].status === 'rejected' && verbose) {
|
|
74
|
+
console.log(`[verbose] ${chunk[j]}: error: ${settled[j].reason?.message || settled[j].reason}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return results;
|
|
79
|
+
}
|