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/vouch.js CHANGED
@@ -1,77 +1,209 @@
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, 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, readProjectConfig, readFollowing, readLog } from '../lib/vit-dir.js';
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>', 'Three-word cap reference (e.g. fast-cache-invalidation)')
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')
17
21
  .option('--did <did>', 'DID to use')
22
+ .option('--json', 'Output as JSON')
18
23
  .option('-v, --verbose', 'Show step-by-step details')
19
24
  .action(async (ref, opts) => {
20
25
  try {
21
26
  const { verbose } = opts;
27
+ const vlog = opts.json ? (...a) => console.error(...a) : console.log;
28
+ const isSkill = isSkillRef(ref);
22
29
 
23
- if (!REF_PATTERN.test(ref)) {
24
- console.error('invalid ref. expected three lowercase words with dashes (e.g. fast-cache-invalidation)');
25
- process.exitCode = 1;
26
- return;
30
+ // Validate ref format
31
+ if (isSkill) {
32
+ if (!isValidSkillRef(ref)) {
33
+ if (opts.json) {
34
+ jsonError('invalid skill ref', 'expected format: skill-{name}');
35
+ return;
36
+ }
37
+ console.error('invalid skill ref. expected format: skill-{name} (lowercase letters, numbers, hyphens)');
38
+ process.exitCode = 1;
39
+ return;
40
+ }
41
+ } else {
42
+ if (!REF_PATTERN.test(ref)) {
43
+ if (opts.json) {
44
+ jsonError('invalid ref', 'expected three lowercase words with dashes');
45
+ return;
46
+ }
47
+ console.error('invalid ref. expected three lowercase words with dashes (e.g. fast-cache-invalidation)');
48
+ process.exitCode = 1;
49
+ return;
50
+ }
27
51
  }
28
52
 
53
+ if (opts.json && !(opts.did || loadConfig().did)) {
54
+ jsonError('no DID configured', "run 'vit login <handle>' first");
55
+ return;
56
+ }
29
57
  const did = requireDid(opts);
30
58
  if (!did) return;
31
- if (verbose) console.log(`[verbose] DID: ${did}`);
59
+ if (verbose) vlog(`[verbose] DID: ${did}`);
32
60
 
33
- const projectConfig = readProjectConfig();
34
- const beacon = projectConfig.beacon;
35
- if (!beacon) {
36
- console.error(`no beacon set. run '${name} init' in a project directory first.`);
37
- process.exitCode = 1;
38
- return;
39
- }
40
- if (verbose) console.log(`[verbose] beacon: ${beacon}`);
41
-
42
- const trusted = readLog('trusted.jsonl');
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;
53
- return;
54
- }
55
- if (verbose) console.log(`[verbose] trusted entry found, uri: ${trustedEntry.uri}`);
61
+ if (isSkill) {
62
+ // Skill vouch — no beacon required, check trusted first
63
+ const trusted = readLog('trusted.jsonl');
64
+ const trustedEntry = trusted.find(e => e.ref === ref);
65
+ if (!trustedEntry) {
66
+ if (opts.json) {
67
+ jsonError(`skill '${ref}' is not yet vetted`, `run 'vit vet ${ref}' first`);
68
+ return;
69
+ }
70
+ console.error(`skill '${ref}' is not yet vetted. vet it first:`);
71
+ console.error('');
72
+ console.error(` vit vet ${ref}`);
73
+ console.error('');
74
+ console.error('after reviewing, trust it with:');
75
+ console.error('');
76
+ console.error(` vit vet ${ref} --trust`);
77
+ process.exitCode = 1;
78
+ return;
79
+ }
80
+ if (verbose) vlog(`[verbose] trusted entry found, uri: ${trustedEntry.uri}`);
81
+
82
+ const skillName = nameFromSkillRef(ref);
56
83
 
57
- const { agent } = await restoreAgent(did);
58
- if (verbose) console.log('[verbose] session restored');
84
+ const { agent } = await restoreAgent(did);
85
+ if (verbose) vlog('[verbose] session restored');
59
86
 
60
- const following = readFollowing();
61
- const dids = following.map(e => e.did);
62
- dids.push(did);
63
- if (verbose) console.log(`[verbose] querying ${dids.length} accounts`);
87
+ const following = readFollowing();
88
+ const dids = following.map(e => e.did);
89
+ dids.push(did);
90
+
91
+ const allRecords = await batchQuery(dids, async (repoDid) => {
92
+ const pds = await resolvePds(repoDid);
93
+ if (verbose) vlog(`[verbose] ${repoDid}: resolved PDS ${pds}`);
94
+ return (await listRecordsFromPds(pds, repoDid, SKILL_COLLECTION, 50)).records;
95
+ }, { verbose });
96
+
97
+ let match = null;
98
+ for (const records of allRecords) {
99
+ for (const rec of records) {
100
+ if (rec.value.name === skillName) {
101
+ if (!match || (rec.value.createdAt || '') > (match.value.createdAt || '')) {
102
+ match = rec;
103
+ }
104
+ }
105
+ }
106
+ }
107
+
108
+ if (!match) {
109
+ if (opts.json) {
110
+ jsonError(`no skill found with ref '${ref}'`);
111
+ return;
112
+ }
113
+ console.error(`no skill found with ref '${ref}' from followed accounts.`);
114
+ process.exitCode = 1;
115
+ return;
116
+ }
117
+
118
+ const now = new Date().toISOString();
119
+ const vouchRecord = {
120
+ $type: VOUCH_COLLECTION,
121
+ subject: {
122
+ uri: match.uri,
123
+ cid: match.cid,
124
+ },
125
+ createdAt: now,
126
+ ref,
127
+ // No beacon for skill vouches
128
+ };
129
+ if (verbose) vlog(`[verbose] creating vouch for ${match.uri}`);
130
+ const rkey = TID.nextStr();
131
+ const res = await agent.com.atproto.repo.putRecord({
132
+ repo: did,
133
+ collection: VOUCH_COLLECTION,
134
+ rkey,
135
+ record: vouchRecord,
136
+ validate: true,
137
+ });
64
138
 
65
- let match = null;
66
- for (const repoDid of dids) {
67
139
  try {
68
- const res = await agent.com.atproto.repo.listRecords({
69
- repo: repoDid,
70
- collection: CAP_COLLECTION,
71
- limit: 50,
140
+ appendLog('vouched.jsonl', {
141
+ ref,
142
+ uri: match.uri,
143
+ cid: match.cid,
144
+ vouchUri: res.data.uri,
145
+ ts: now,
72
146
  });
73
- for (const rec of res.data.records) {
74
- if (rec.value.beacon !== beacon) continue;
147
+ } catch (logErr) {
148
+ console.error('warning: failed to write vouched.jsonl:', logErr.message);
149
+ }
150
+ if (verbose) vlog('[verbose] logged to vouched.jsonl');
151
+
152
+ if (opts.json) {
153
+ jsonOk({ ref, uri: match.uri, vouchUri: res.data.uri });
154
+ return;
155
+ }
156
+ console.log(`${mark} vouched: ${ref} (${match.uri})`);
157
+ } else {
158
+ // Cap vouch — requires beacon (check beacon before trusted, matching original behavior)
159
+ const beaconSet = readBeaconSet();
160
+ if (beaconSet.size === 0) {
161
+ if (opts.json) {
162
+ jsonError('no beacon set', "run 'vit init' first");
163
+ return;
164
+ }
165
+ console.error(`no beacon set. run '${name} init' in a project directory first.`);
166
+ process.exitCode = 1;
167
+ return;
168
+ }
169
+ if (verbose) vlog(`[verbose] beacons: ${[...beaconSet].join(', ')}`);
170
+
171
+ const trusted = readLog('trusted.jsonl');
172
+ const trustedEntry = trusted.find(e => e.ref === ref);
173
+ if (!trustedEntry) {
174
+ if (opts.json) {
175
+ jsonError(`cap '${ref}' is not yet vetted`, `run 'vit vet ${ref}' first`);
176
+ return;
177
+ }
178
+ console.error(`cap '${ref}' is not yet vetted. vet it first:`);
179
+ console.error('');
180
+ console.error(` vit vet ${ref}`);
181
+ console.error('');
182
+ console.error('after reviewing, trust it with:');
183
+ console.error('');
184
+ console.error(` vit vet ${ref} --trust`);
185
+ process.exitCode = 1;
186
+ return;
187
+ }
188
+ if (verbose) vlog(`[verbose] trusted entry found, uri: ${trustedEntry.uri}`);
189
+
190
+ const { agent } = await restoreAgent(did);
191
+ if (verbose) vlog('[verbose] session restored');
192
+
193
+ const following = readFollowing();
194
+ const dids = following.map(e => e.did);
195
+ dids.push(did);
196
+
197
+ const allRecords = await batchQuery(dids, async (repoDid) => {
198
+ const pds = await resolvePds(repoDid);
199
+ if (verbose) vlog(`[verbose] ${repoDid}: resolved PDS ${pds}`);
200
+ return (await listRecordsFromPds(pds, repoDid, CAP_COLLECTION, 50)).records;
201
+ }, { verbose });
202
+
203
+ let match = null;
204
+ for (const records of allRecords) {
205
+ for (const rec of records) {
206
+ if (!beaconSet.has(rec.value.beacon)) continue;
75
207
  const recRef = resolveRef(rec.value, rec.cid);
76
208
  if (recRef === ref) {
77
209
  if (!match || (rec.value.createdAt || '') > (match.value.createdAt || '')) {
@@ -79,55 +211,66 @@ export default function register(program) {
79
211
  }
80
212
  }
81
213
  }
82
- } catch (err) {
83
- if (verbose) console.log(`[verbose] ${repoDid}: error fetching caps: ${err.message}`);
84
214
  }
85
- }
86
215
 
87
- if (!match) {
88
- console.error(`no cap found with ref '${ref}' for this beacon.`);
89
- process.exitCode = 1;
90
- return;
91
- }
216
+ if (!match) {
217
+ if (opts.json) {
218
+ jsonError(`no cap found with ref '${ref}' for this beacon`);
219
+ return;
220
+ }
221
+ console.error(`no cap found with ref '${ref}' for this beacon.`);
222
+ process.exitCode = 1;
223
+ return;
224
+ }
92
225
 
93
- const now = new Date().toISOString();
94
- const vouchRecord = {
95
- $type: VOUCH_COLLECTION,
96
- subject: {
97
- uri: match.uri,
98
- cid: match.cid,
99
- },
100
- createdAt: now,
101
- ref,
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', {
226
+ const now = new Date().toISOString();
227
+ const vouchRecord = {
228
+ $type: VOUCH_COLLECTION,
229
+ subject: {
230
+ uri: match.uri,
231
+ cid: match.cid,
232
+ },
233
+ createdAt: now,
116
234
  ref,
117
- uri: match.uri,
118
- cid: match.cid,
119
- vouchUri: res.data.uri,
120
235
  beacon,
121
- ts: now,
236
+ };
237
+ if (verbose) vlog(`[verbose] creating vouch for ${match.uri}`);
238
+ const rkey = TID.nextStr();
239
+ const res = await agent.com.atproto.repo.putRecord({
240
+ repo: did,
241
+ collection: VOUCH_COLLECTION,
242
+ rkey,
243
+ record: vouchRecord,
244
+ validate: true,
122
245
  });
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
246
 
128
- console.log(`${mark} vouched: ${ref} (${match.uri})`);
247
+ try {
248
+ appendLog('vouched.jsonl', {
249
+ ref,
250
+ uri: match.uri,
251
+ cid: match.cid,
252
+ vouchUri: res.data.uri,
253
+ beacon,
254
+ ts: now,
255
+ });
256
+ } catch (logErr) {
257
+ console.error('warning: failed to write vouched.jsonl:', logErr.message);
258
+ }
259
+ if (verbose) vlog('[verbose] logged to vouched.jsonl');
260
+
261
+ if (opts.json) {
262
+ jsonOk({ ref, uri: match.uri, vouchUri: res.data.uri });
263
+ return;
264
+ }
265
+ console.log(`${mark} vouched: ${ref} (${match.uri})`);
266
+ }
129
267
  } catch (err) {
130
- console.error(err instanceof Error ? err.message : String(err));
268
+ const msg = err instanceof Error ? err.message : String(err);
269
+ if (opts.json) {
270
+ jsonError(msg);
271
+ return;
272
+ }
273
+ console.error(msg);
131
274
  process.exitCode = 1;
132
275
  }
133
276
  });
package/src/lib/agent.js CHANGED
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
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
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
1
+ // SPDX-License-Identifier: MIT
2
2
  // Copyright (c) 2026 sol pbc
3
3
 
4
4
  export function parseGitUrl(input) {
package/src/lib/brand.js CHANGED
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
1
+ // SPDX-License-Identifier: MIT
2
2
  // Copyright (c) 2026 sol pbc
3
3
 
4
4
  const VIT_MARK = 'v\u0307'; // v̇
@@ -1,4 +1,4 @@
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 { sha256 } from '@noble/hashes/sha256';
package/src/lib/compat.js CHANGED
@@ -1,4 +1,4 @@
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 { execFileSync } from 'node:child_process';
package/src/lib/config.js CHANGED
@@ -1,7 +1,8 @@
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 { 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
- const did = opts?.did || loadConfig().did;
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;
@@ -1,5 +1,8 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
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: AGPL-3.0-only
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 tokenSet = data[did]?.tokenSet;
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
@@ -1,4 +1,4 @@
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 envPaths from 'env-paths';
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
+ }
@@ -1,4 +1,4 @@
1
- // SPDX-License-Identifier: AGPL-3.0-only
1
+ // SPDX-License-Identifier: MIT
2
2
  // Copyright (c) 2026 sol pbc
3
3
 
4
4
  const AGENTS = new Set(['claude', 'codex', 'gemini']);