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/LICENSE +21 -661
- package/README.md +56 -78
- package/bin/vit.js +1 -1
- package/package.json +6 -2
- package/src/cli.js +11 -1
- package/src/cmd/adopt.js +1 -1
- package/src/cmd/beacon.js +1 -1
- package/src/cmd/config.js +1 -1
- package/src/cmd/doctor.js +150 -16
- package/src/cmd/explore.js +477 -0
- package/src/cmd/firehose.js +20 -9
- package/src/cmd/follow.js +59 -10
- package/src/cmd/hack.js +83 -0
- package/src/cmd/init.js +95 -13
- package/src/cmd/learn.js +244 -0
- package/src/cmd/link.js +75 -0
- package/src/cmd/login.js +95 -13
- package/src/cmd/remix.js +82 -37
- package/src/cmd/scan.js +207 -0
- package/src/cmd/setup.js +1 -1
- package/src/cmd/ship.js +564 -149
- package/src/cmd/skim.js +106 -36
- package/src/cmd/vet.js +565 -97
- package/src/cmd/vouch.js +231 -88
- 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/cmd/login.js
CHANGED
|
@@ -1,38 +1,113 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Copyright (c) 2026 sol pbc
|
|
3
3
|
|
|
4
4
|
import { createServer } from 'node:http';
|
|
5
5
|
import { spawn } from 'node:child_process';
|
|
6
6
|
import { createInterface } from 'node:readline';
|
|
7
|
+
import { AtpAgent } from '@atproto/api';
|
|
8
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import { join } from 'node:path';
|
|
7
10
|
import { loadConfig, saveConfig } from '../lib/config.js';
|
|
8
11
|
import { createOAuthClient, createSessionStore, createStore, checkSession } from '../lib/oauth.js';
|
|
12
|
+
import { configDir, configPath } from '../lib/paths.js';
|
|
13
|
+
import { vitDir } from '../lib/vit-dir.js';
|
|
14
|
+
|
|
15
|
+
function ensureGitignore(dir, entry) {
|
|
16
|
+
const gitignorePath = join(dir, '.gitignore');
|
|
17
|
+
let content = '';
|
|
18
|
+
try { content = readFileSync(gitignorePath, 'utf-8'); } catch {}
|
|
19
|
+
if (!content.split('\n').includes(entry)) {
|
|
20
|
+
writeFileSync(gitignorePath, content + (content.endsWith('\n') ? '' : '\n') + entry + '\n');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
9
23
|
|
|
10
24
|
export default function register(program) {
|
|
11
25
|
program
|
|
12
26
|
.command('login')
|
|
13
|
-
.description('Log in to Bluesky
|
|
27
|
+
.description('Log in to Bluesky')
|
|
14
28
|
.argument('<handle>', 'Bluesky handle (e.g. alice.bsky.social)')
|
|
15
29
|
.option('-v, --verbose', 'Show discovery details')
|
|
16
30
|
.option('--force', 'Force re-login, skip session validation')
|
|
17
31
|
.option('--remote', 'Skip browser launch; prompt to paste callback URL (auto-detected over SSH)')
|
|
18
32
|
.option('--browser <command>', 'Browser command to use (e.g. firefox)')
|
|
33
|
+
.option('--app-password <password>', 'Authenticate with an app password (skips browser OAuth)')
|
|
34
|
+
.option('--local', 'Store session in project .vit/ instead of global config')
|
|
19
35
|
.action(async (handle, opts) => {
|
|
20
|
-
const { verbose, force, remote, browser } = opts;
|
|
36
|
+
const { verbose, force, remote, browser, appPassword, local: localLogin } = opts;
|
|
21
37
|
const isRemote = remote || !!(process.env.SSH_CONNECTION || process.env.SSH_TTY || process.env.SSH_CLIENT);
|
|
22
38
|
handle = handle.replace(/^@/, '');
|
|
23
39
|
|
|
40
|
+
if (localLogin) {
|
|
41
|
+
const dir = vitDir();
|
|
42
|
+
if (!existsSync(dir)) {
|
|
43
|
+
console.error("no .vit directory found. run 'vit init' first.");
|
|
44
|
+
process.exitCode = 1;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
24
49
|
if (!force) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
50
|
+
if (localLogin) {
|
|
51
|
+
const localPath = join(vitDir(), 'login.json');
|
|
52
|
+
if (existsSync(localPath)) {
|
|
53
|
+
try {
|
|
54
|
+
const local = JSON.parse(readFileSync(localPath, 'utf-8'));
|
|
55
|
+
if (local.did) {
|
|
56
|
+
console.log('Checking local session...');
|
|
57
|
+
const validDid = checkSession(local.did);
|
|
58
|
+
if (validDid) {
|
|
59
|
+
console.log(`Already logged in locally as ${validDid}`);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
} catch {}
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
const existing = loadConfig();
|
|
67
|
+
if (existing.did) {
|
|
68
|
+
console.log('Checking session...');
|
|
69
|
+
const validDid = checkSession(existing.did);
|
|
70
|
+
if (validDid) {
|
|
71
|
+
console.log(`Already logged in as ${validDid}`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
32
74
|
}
|
|
33
75
|
}
|
|
34
76
|
}
|
|
35
77
|
|
|
78
|
+
if (appPassword) {
|
|
79
|
+
try {
|
|
80
|
+
const agent = new AtpAgent({ service: 'https://bsky.social' });
|
|
81
|
+
if (verbose) console.log('[verbose] Authenticating with app password...');
|
|
82
|
+
const res = await agent.login({ identifier: handle, password: appPassword });
|
|
83
|
+
const { did, handle: resolvedHandle, accessJwt, refreshJwt } = res.data;
|
|
84
|
+
const session = { accessJwt, refreshJwt, handle: resolvedHandle, did, active: true };
|
|
85
|
+
|
|
86
|
+
if (localLogin) {
|
|
87
|
+
const loginData = { did, handle: resolvedHandle, type: 'app-password', service: 'https://bsky.social', session };
|
|
88
|
+
const dir = vitDir();
|
|
89
|
+
writeFileSync(join(dir, 'login.json'), JSON.stringify(loginData, null, 2) + '\n');
|
|
90
|
+
ensureGitignore(dir, 'login.json');
|
|
91
|
+
} else {
|
|
92
|
+
const sessionFile = configPath('session.json');
|
|
93
|
+
let data = {};
|
|
94
|
+
try { data = JSON.parse(readFileSync(sessionFile, 'utf-8')); } catch {}
|
|
95
|
+
data[did] = { type: 'app-password', service: 'https://bsky.social', session };
|
|
96
|
+
mkdirSync(configDir, { recursive: true });
|
|
97
|
+
writeFileSync(sessionFile, JSON.stringify(data, null, 2) + '\n');
|
|
98
|
+
const config = loadConfig();
|
|
99
|
+
config.did = did;
|
|
100
|
+
saveConfig(config);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
console.log(`Logged in as ${did}`);
|
|
104
|
+
} catch (err) {
|
|
105
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
106
|
+
process.exitCode = 1;
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
36
111
|
let server;
|
|
37
112
|
let timeout;
|
|
38
113
|
let rl;
|
|
@@ -160,9 +235,16 @@ export default function register(program) {
|
|
|
160
235
|
console.log(`[verbose] Token exchange result for DID: ${session.did}`);
|
|
161
236
|
}
|
|
162
237
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
238
|
+
if (localLogin) {
|
|
239
|
+
const loginData = { did: session.did, handle, type: 'oauth' };
|
|
240
|
+
const dir = vitDir();
|
|
241
|
+
writeFileSync(join(dir, 'login.json'), JSON.stringify(loginData, null, 2) + '\n');
|
|
242
|
+
ensureGitignore(dir, 'login.json');
|
|
243
|
+
} else {
|
|
244
|
+
const config = loadConfig();
|
|
245
|
+
config.did = session.did;
|
|
246
|
+
saveConfig(config);
|
|
247
|
+
}
|
|
166
248
|
console.log(`Logged in as ${session.did}`);
|
|
167
249
|
} catch (err) {
|
|
168
250
|
console.error(err instanceof Error ? err.message : String(err));
|
package/src/cmd/remix.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
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
5
|
import { CAP_COLLECTION } from '../lib/constants.js';
|
|
6
6
|
import { restoreAgent } from '../lib/oauth.js';
|
|
7
|
-
import {
|
|
8
|
-
import { requireAgent } from '../lib/agent.js';
|
|
7
|
+
import { readBeaconSet, readFollowing, readLog } from '../lib/vit-dir.js';
|
|
8
|
+
import { requireAgent, detectCodingAgent } from '../lib/agent.js';
|
|
9
|
+
import { shouldBypassVet } from '../lib/trust-gate.js';
|
|
9
10
|
import { resolveRef, REF_PATTERN } from '../lib/cap-ref.js';
|
|
10
11
|
import { brand, 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
|
|
@@ -15,11 +19,16 @@ export default function register(program) {
|
|
|
15
19
|
.argument('<ref>', 'Three-word cap reference (e.g. fast-cache-invalidation)')
|
|
16
20
|
.description('Derive a vetted cap into the local codebase')
|
|
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 gate = requireAgent();
|
|
22
27
|
if (!gate.ok) {
|
|
28
|
+
if (opts.json) {
|
|
29
|
+
jsonError('agent required', 'run vit remix from a coding agent');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
23
32
|
console.error(`${name} remix should be run by a coding agent (e.g. claude code, gemini cli).`);
|
|
24
33
|
console.error(`open your agent and ask it to run '${name} remix' for you.`);
|
|
25
34
|
process.exitCode = 1;
|
|
@@ -27,72 +36,98 @@ export default function register(program) {
|
|
|
27
36
|
}
|
|
28
37
|
|
|
29
38
|
const { verbose } = opts;
|
|
39
|
+
const vlog = opts.json ? (...a) => console.error(...a) : console.log;
|
|
30
40
|
|
|
31
41
|
if (!REF_PATTERN.test(ref)) {
|
|
42
|
+
if (opts.json) {
|
|
43
|
+
jsonError('invalid ref', 'expected three lowercase words with dashes');
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
32
46
|
console.error('invalid ref. expected three lowercase words with dashes (e.g. fast-cache-invalidation)');
|
|
33
47
|
process.exitCode = 1;
|
|
34
48
|
return;
|
|
35
49
|
}
|
|
36
50
|
|
|
51
|
+
if (opts.json && !(opts.did || loadConfig().did)) {
|
|
52
|
+
jsonError('no DID configured', "run 'vit login <handle>' first");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
37
55
|
const did = requireDid(opts);
|
|
38
56
|
if (!did) return;
|
|
39
|
-
if (verbose)
|
|
57
|
+
if (verbose) vlog(`[verbose] DID: ${did}`);
|
|
40
58
|
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
59
|
+
const beaconSet = readBeaconSet();
|
|
60
|
+
if (beaconSet.size === 0) {
|
|
61
|
+
if (opts.json) {
|
|
62
|
+
jsonError('no beacon set', "run 'vit init' first");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
44
65
|
console.error(`no beacon set. run '${name} init' in a project directory first.`);
|
|
45
66
|
process.exitCode = 1;
|
|
46
67
|
return;
|
|
47
68
|
}
|
|
48
|
-
if (verbose)
|
|
69
|
+
if (verbose) vlog(`[verbose] beacons: ${[...beaconSet].join(', ')}`);
|
|
49
70
|
|
|
50
71
|
const trusted = readLog('trusted.jsonl');
|
|
51
72
|
const trustedEntry = trusted.find(e => e.ref === ref);
|
|
52
73
|
if (!trustedEntry) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
74
|
+
const trustGate = shouldBypassVet();
|
|
75
|
+
if (!trustGate.bypass) {
|
|
76
|
+
if (opts.json) {
|
|
77
|
+
jsonError(`cap '${ref}' is not trusted`, `ask user to run 'vit vet ${ref} --trust'`);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
console.error(`cap '${ref}' is not trusted. ask the user to vet it first:`);
|
|
81
|
+
console.error('');
|
|
82
|
+
console.error(` vit vet ${ref}`);
|
|
83
|
+
console.error('');
|
|
84
|
+
console.error('after reviewing, they can trust it with:');
|
|
85
|
+
console.error('');
|
|
86
|
+
console.error(` vit vet ${ref} --trust`);
|
|
87
|
+
if (detectCodingAgent()) {
|
|
88
|
+
console.error('');
|
|
89
|
+
console.error('or, to trust all items without review:');
|
|
90
|
+
console.error('');
|
|
91
|
+
console.error(' vit vet --dangerous-accept --confirm');
|
|
92
|
+
}
|
|
93
|
+
process.exitCode = 1;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (verbose) vlog(`[verbose] vet gate bypassed: ${trustGate.reason}`);
|
|
62
97
|
}
|
|
63
|
-
if (verbose)
|
|
98
|
+
if (verbose && trustedEntry) vlog(`[verbose] trusted entry found, uri: ${trustedEntry.uri}`);
|
|
64
99
|
|
|
65
100
|
const { agent } = await restoreAgent(did);
|
|
66
|
-
if (verbose)
|
|
101
|
+
if (verbose) vlog('[verbose] session restored');
|
|
67
102
|
|
|
68
103
|
const following = readFollowing();
|
|
69
104
|
const dids = following.map(e => e.did);
|
|
70
105
|
dids.push(did);
|
|
71
|
-
|
|
106
|
+
|
|
107
|
+
const allRecords = await batchQuery(dids, async (repoDid) => {
|
|
108
|
+
const pds = await resolvePds(repoDid);
|
|
109
|
+
if (verbose) vlog(`[verbose] ${repoDid}: resolved PDS ${pds}`);
|
|
110
|
+
return (await listRecordsFromPds(pds, repoDid, CAP_COLLECTION, 50)).records;
|
|
111
|
+
}, { verbose });
|
|
72
112
|
|
|
73
113
|
let match = null;
|
|
74
|
-
for (const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
for (const rec of res.data.records) {
|
|
82
|
-
if (rec.value.beacon !== beacon) continue;
|
|
83
|
-
const recRef = resolveRef(rec.value, rec.cid);
|
|
84
|
-
if (recRef === ref) {
|
|
85
|
-
if (!match || (rec.value.createdAt || '') > (match.value.createdAt || '')) {
|
|
86
|
-
match = rec;
|
|
87
|
-
}
|
|
114
|
+
for (const records of allRecords) {
|
|
115
|
+
for (const rec of records) {
|
|
116
|
+
if (!beaconSet.has(rec.value.beacon)) continue;
|
|
117
|
+
const recRef = resolveRef(rec.value, rec.cid);
|
|
118
|
+
if (recRef === ref) {
|
|
119
|
+
if (!match || (rec.value.createdAt || '') > (match.value.createdAt || '')) {
|
|
120
|
+
match = rec;
|
|
88
121
|
}
|
|
89
122
|
}
|
|
90
|
-
} catch (err) {
|
|
91
|
-
if (verbose) console.log(`[verbose] ${repoDid}: error fetching caps: ${err.message}`);
|
|
92
123
|
}
|
|
93
124
|
}
|
|
94
125
|
|
|
95
126
|
if (!match) {
|
|
127
|
+
if (opts.json) {
|
|
128
|
+
jsonError(`no cap found with ref '${ref}' for this beacon`);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
96
131
|
console.error(`no cap found with ref '${ref}' for this beacon.`);
|
|
97
132
|
process.exitCode = 1;
|
|
98
133
|
return;
|
|
@@ -104,6 +139,11 @@ export default function register(program) {
|
|
|
104
139
|
const description = record.description || '';
|
|
105
140
|
const text = record.text || '';
|
|
106
141
|
|
|
142
|
+
if (opts.json) {
|
|
143
|
+
jsonOk({ ref, author, title, description, text });
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
107
147
|
console.log(`# ${brand} remix: ${title}`);
|
|
108
148
|
console.log('');
|
|
109
149
|
console.log(`ref: ${ref}`);
|
|
@@ -129,7 +169,12 @@ export default function register(program) {
|
|
|
129
169
|
console.log('');
|
|
130
170
|
console.log(text);
|
|
131
171
|
} catch (err) {
|
|
132
|
-
|
|
172
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
173
|
+
if (opts.json) {
|
|
174
|
+
jsonError(msg);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
console.error(msg);
|
|
133
178
|
process.exitCode = 1;
|
|
134
179
|
}
|
|
135
180
|
});
|
package/src/cmd/scan.js
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
import { CAP_COLLECTION, SKILL_COLLECTION, DEFAULT_JETSTREAM_URL } from '../lib/constants.js';
|
|
5
|
+
import { resolveRef } from '../lib/cap-ref.js';
|
|
6
|
+
import { resolveHandleFromDid } from '../lib/pds.js';
|
|
7
|
+
import { brand } from '../lib/brand.js';
|
|
8
|
+
import { jsonOk, jsonError } from '../lib/json-output.js';
|
|
9
|
+
import { readBeaconSet } from '../lib/vit-dir.js';
|
|
10
|
+
|
|
11
|
+
export default function register(program) {
|
|
12
|
+
program
|
|
13
|
+
.command('scan')
|
|
14
|
+
.description('Discover cap and skill publishers across the network via Jetstream replay')
|
|
15
|
+
.option('--days <n>', 'Number of days to replay', '7')
|
|
16
|
+
.option('--beacon <beacon>', 'Filter by beacon (caps only)')
|
|
17
|
+
.option('--skills', 'Show only skill publishers')
|
|
18
|
+
.option('--caps', 'Show only cap publishers')
|
|
19
|
+
.option('--tag <tag>', 'Filter skills by tag')
|
|
20
|
+
.option('-v, --verbose', 'Show each event as it arrives')
|
|
21
|
+
.option('--json', 'Output as JSON')
|
|
22
|
+
.option('--jetstream <url>', 'Jetstream WebSocket URL (default: VIT_JETSTREAM_URL env or built-in)')
|
|
23
|
+
.action(async (opts) => {
|
|
24
|
+
try {
|
|
25
|
+
const vlog = opts.json ? (...a) => console.error(...a) : console.log;
|
|
26
|
+
const days = parseInt(opts.days, 10);
|
|
27
|
+
if (isNaN(days) || days < 1) {
|
|
28
|
+
if (opts.json) {
|
|
29
|
+
jsonError('--days must be a positive integer');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
console.error('error: --days must be a positive integer');
|
|
33
|
+
process.exitCode = 1;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const jetstreamUrl = opts.jetstream || process.env.VIT_JETSTREAM_URL || DEFAULT_JETSTREAM_URL;
|
|
38
|
+
|
|
39
|
+
const wantCaps = !opts.skills;
|
|
40
|
+
const wantSkills = !opts.caps;
|
|
41
|
+
let beaconSet = null;
|
|
42
|
+
if (opts.beacon) {
|
|
43
|
+
if (opts.beacon === '.') {
|
|
44
|
+
beaconSet = readBeaconSet();
|
|
45
|
+
if (beaconSet.size === 0) {
|
|
46
|
+
if (opts.json) {
|
|
47
|
+
jsonError("no beacon set — run 'vit init' first");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
console.error("no beacon set — run 'vit init' first");
|
|
51
|
+
process.exitCode = 1;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
beaconSet = new Set([opts.beacon]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const cursor = (Date.now() - days * 86400000) * 1000;
|
|
60
|
+
const timeout = Math.max(120000, Math.min(600000, days * 60000));
|
|
61
|
+
|
|
62
|
+
// Build wanted collections
|
|
63
|
+
const collections = [];
|
|
64
|
+
if (wantCaps) collections.push(CAP_COLLECTION);
|
|
65
|
+
if (wantSkills) collections.push(SKILL_COLLECTION);
|
|
66
|
+
|
|
67
|
+
const url = new URL(jetstreamUrl);
|
|
68
|
+
for (const col of collections) {
|
|
69
|
+
url.searchParams.append('wantedCollections', col);
|
|
70
|
+
}
|
|
71
|
+
url.searchParams.set('cursor', String(cursor));
|
|
72
|
+
|
|
73
|
+
const scanType = wantCaps && wantSkills ? 'cap + skill' : wantSkills ? 'skill' : 'cap';
|
|
74
|
+
if (!opts.json) {
|
|
75
|
+
console.log(`${brand} scan`);
|
|
76
|
+
console.log(` Replaying ${days} day${days === 1 ? '' : 's'} of ${scanType} events...`);
|
|
77
|
+
if (beaconSet) console.log(` Beacon filter: ${[...beaconSet].join(', ')}`);
|
|
78
|
+
if (opts.tag) console.log(` Tag filter: ${opts.tag}`);
|
|
79
|
+
console.log(` Timeout: ${Math.round(timeout / 1000)}s`);
|
|
80
|
+
console.log('');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const publishers = new Map();
|
|
84
|
+
|
|
85
|
+
await new Promise((resolve, reject) => {
|
|
86
|
+
const ws = new WebSocket(url.toString());
|
|
87
|
+
const timer = setTimeout(() => {
|
|
88
|
+
ws.close();
|
|
89
|
+
resolve();
|
|
90
|
+
}, timeout);
|
|
91
|
+
|
|
92
|
+
ws.onmessage = (event) => {
|
|
93
|
+
let msg;
|
|
94
|
+
try { msg = JSON.parse(event.data); } catch { return; }
|
|
95
|
+
|
|
96
|
+
if (msg.kind !== 'commit' || msg.commit?.operation !== 'create') return;
|
|
97
|
+
|
|
98
|
+
const record = msg.commit?.record;
|
|
99
|
+
if (!record) return;
|
|
100
|
+
|
|
101
|
+
const collection = msg.commit?.collection;
|
|
102
|
+
const isCapEvent = collection === CAP_COLLECTION;
|
|
103
|
+
const isSkillEvent = collection === SKILL_COLLECTION;
|
|
104
|
+
|
|
105
|
+
if (!isCapEvent && !isSkillEvent) return;
|
|
106
|
+
|
|
107
|
+
// Apply filters
|
|
108
|
+
if (isCapEvent && beaconSet && !beaconSet.has(record.beacon)) return;
|
|
109
|
+
if (isSkillEvent && opts.tag) {
|
|
110
|
+
const tags = record.tags || [];
|
|
111
|
+
if (!tags.some(t => t.toLowerCase() === opts.tag.toLowerCase())) return;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const did = msg.did;
|
|
115
|
+
const ref = isCapEvent && msg.commit?.cid ? resolveRef(record, msg.commit.cid) : null;
|
|
116
|
+
|
|
117
|
+
if (opts.verbose) {
|
|
118
|
+
const didShort = did.slice(-12);
|
|
119
|
+
if (isCapEvent) {
|
|
120
|
+
const title = record.title || '';
|
|
121
|
+
const refPart = ref ? ` (${ref})` : '';
|
|
122
|
+
vlog(` ${didShort}: [cap] ${title}${refPart} [${record.beacon || 'no beacon'}]`);
|
|
123
|
+
} else {
|
|
124
|
+
const skillName = record.name || '';
|
|
125
|
+
const tags = record.tags ? ` [${record.tags.join(', ')}]` : '';
|
|
126
|
+
vlog(` ${didShort}: [skill] ${skillName}${tags}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (!publishers.has(did)) {
|
|
131
|
+
publishers.set(did, { capCount: 0, skillCount: 0, beacons: new Set(), tags: new Set(), lastActive: '' });
|
|
132
|
+
}
|
|
133
|
+
const entry = publishers.get(did);
|
|
134
|
+
if (isCapEvent) {
|
|
135
|
+
entry.capCount++;
|
|
136
|
+
if (record.beacon) entry.beacons.add(record.beacon);
|
|
137
|
+
} else {
|
|
138
|
+
entry.skillCount++;
|
|
139
|
+
if (record.tags) {
|
|
140
|
+
for (const t of record.tags) entry.tags.add(t);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (record.createdAt && record.createdAt > entry.lastActive) {
|
|
144
|
+
entry.lastActive = record.createdAt;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
ws.onerror = (err) => {
|
|
149
|
+
clearTimeout(timer);
|
|
150
|
+
reject(new Error(`WebSocket error: ${err?.message ?? 'unknown'}`));
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
ws.onclose = () => {
|
|
154
|
+
clearTimeout(timer);
|
|
155
|
+
resolve();
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
if (publishers.size === 0) {
|
|
160
|
+
if (opts.json) {
|
|
161
|
+
jsonOk({ publishers: [] });
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
console.log(`no ${scanType} publishers found in this time window.`);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const entries = [];
|
|
169
|
+
for (const [did, stats] of publishers) {
|
|
170
|
+
const handle = await resolveHandleFromDid(did);
|
|
171
|
+
entries.push({ handle, did, ...stats, beacons: [...stats.beacons], tags: [...stats.tags] });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const totalCount = (e) => e.capCount + e.skillCount;
|
|
175
|
+
entries.sort((a, b) => totalCount(b) - totalCount(a));
|
|
176
|
+
|
|
177
|
+
if (opts.json) {
|
|
178
|
+
jsonOk({ publishers: entries });
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
console.log(`found ${entries.length} publisher${entries.length === 1 ? '' : 's'}:\n`);
|
|
182
|
+
for (const e of entries) {
|
|
183
|
+
console.log(` @${e.handle}`);
|
|
184
|
+
const parts = [];
|
|
185
|
+
if (wantCaps && e.capCount > 0) {
|
|
186
|
+
const beaconStr = e.beacons.length > 0 ? e.beacons.join(', ') : '(none)';
|
|
187
|
+
parts.push(`caps: ${e.capCount} beacons: ${beaconStr}`);
|
|
188
|
+
}
|
|
189
|
+
if (wantSkills && e.skillCount > 0) {
|
|
190
|
+
const tagStr = e.tags.length > 0 ? e.tags.join(', ') : '(none)';
|
|
191
|
+
parts.push(`skills: ${e.skillCount} tags: ${tagStr}`);
|
|
192
|
+
}
|
|
193
|
+
const lastActive = e.lastActive ? e.lastActive.split('T')[0] : 'unknown';
|
|
194
|
+
parts.push(`last active: ${lastActive}`);
|
|
195
|
+
console.log(` ${parts.join(' ')}`);
|
|
196
|
+
}
|
|
197
|
+
} catch (err) {
|
|
198
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
199
|
+
if (opts.json) {
|
|
200
|
+
jsonError(msg);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
console.error(msg);
|
|
204
|
+
process.exitCode = 1;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
package/src/cmd/setup.js
CHANGED