vit 0.0.1 → 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 +1 -1
- package/README.md +94 -2
- package/bin/vit.js +7 -0
- package/package.json +29 -18
- package/src/cli.js +52 -0
- package/src/cmd/adopt.js +92 -0
- package/src/cmd/beacon.js +62 -0
- package/src/cmd/config.js +63 -0
- package/src/cmd/doctor.js +193 -0
- package/src/cmd/explore.js +477 -0
- package/src/cmd/firehose.js +159 -0
- package/src/cmd/follow.js +143 -0
- package/src/cmd/hack.js +83 -0
- package/src/cmd/init.js +242 -0
- package/src/cmd/learn.js +244 -0
- package/src/cmd/link.js +75 -0
- package/src/cmd/login.js +267 -0
- package/src/cmd/remix.js +181 -0
- package/src/cmd/scan.js +207 -0
- package/src/cmd/setup.js +76 -0
- package/src/cmd/ship.js +610 -0
- package/src/cmd/skim.js +183 -0
- package/src/cmd/vet.js +609 -0
- package/src/cmd/vouch.js +277 -0
- package/src/lib/agent.js +37 -0
- package/src/lib/beacon.js +97 -0
- package/src/lib/brand.js +20 -0
- package/src/lib/cap-ref.js +23 -0
- package/src/lib/compat.js +20 -0
- package/src/lib/config.js +48 -0
- package/src/lib/constants.js +8 -0
- package/src/lib/json-output.js +13 -0
- package/src/lib/oauth.js +149 -0
- package/src/lib/paths.js +10 -0
- package/src/lib/pds.js +79 -0
- package/src/lib/sandbox.js +37 -0
- package/src/lib/skill-ref.js +37 -0
- package/src/lib/trust-gate.js +39 -0
- package/src/lib/vit-dir.js +69 -0
- package/.npmignore +0 -37
package/src/cmd/vouch.js
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
import { requireDid } from '../lib/config.js';
|
|
5
|
+
import { CAP_COLLECTION, SKILL_COLLECTION, VOUCH_COLLECTION } from '../lib/constants.js';
|
|
6
|
+
import { TID } from '@atproto/common-web';
|
|
7
|
+
import { restoreAgent } from '../lib/oauth.js';
|
|
8
|
+
import { appendLog, readBeaconSet, readFollowing, readLog } from '../lib/vit-dir.js';
|
|
9
|
+
import { resolveRef, REF_PATTERN } from '../lib/cap-ref.js';
|
|
10
|
+
import { isSkillRef, isValidSkillRef, nameFromSkillRef } from '../lib/skill-ref.js';
|
|
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';
|
|
15
|
+
|
|
16
|
+
export default function register(program) {
|
|
17
|
+
program
|
|
18
|
+
.command('vouch')
|
|
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')
|
|
21
|
+
.option('--did <did>', 'DID to use')
|
|
22
|
+
.option('--json', 'Output as JSON')
|
|
23
|
+
.option('-v, --verbose', 'Show step-by-step details')
|
|
24
|
+
.action(async (ref, opts) => {
|
|
25
|
+
try {
|
|
26
|
+
const { verbose } = opts;
|
|
27
|
+
const vlog = opts.json ? (...a) => console.error(...a) : console.log;
|
|
28
|
+
const isSkill = isSkillRef(ref);
|
|
29
|
+
|
|
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
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (opts.json && !(opts.did || loadConfig().did)) {
|
|
54
|
+
jsonError('no DID configured', "run 'vit login <handle>' first");
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const did = requireDid(opts);
|
|
58
|
+
if (!did) return;
|
|
59
|
+
if (verbose) vlog(`[verbose] DID: ${did}`);
|
|
60
|
+
|
|
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);
|
|
83
|
+
|
|
84
|
+
const { agent } = await restoreAgent(did);
|
|
85
|
+
if (verbose) vlog('[verbose] session restored');
|
|
86
|
+
|
|
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
|
+
});
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
appendLog('vouched.jsonl', {
|
|
141
|
+
ref,
|
|
142
|
+
uri: match.uri,
|
|
143
|
+
cid: match.cid,
|
|
144
|
+
vouchUri: res.data.uri,
|
|
145
|
+
ts: now,
|
|
146
|
+
});
|
|
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;
|
|
207
|
+
const recRef = resolveRef(rec.value, rec.cid);
|
|
208
|
+
if (recRef === ref) {
|
|
209
|
+
if (!match || (rec.value.createdAt || '') > (match.value.createdAt || '')) {
|
|
210
|
+
match = rec;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
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
|
+
}
|
|
225
|
+
|
|
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,
|
|
234
|
+
ref,
|
|
235
|
+
beacon,
|
|
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,
|
|
245
|
+
});
|
|
246
|
+
|
|
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
|
+
}
|
|
267
|
+
} catch (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);
|
|
274
|
+
process.exitCode = 1;
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
}
|
package/src/lib/agent.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
const CODING_AGENTS = {
|
|
5
|
+
CLAUDECODE: 'claude code',
|
|
6
|
+
GEMINI_CLI: 'gemini cli',
|
|
7
|
+
CODEX_CI: 'codex',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function detectCodingAgent() {
|
|
11
|
+
for (const [envVar, name] of Object.entries(CODING_AGENTS)) {
|
|
12
|
+
if (process.env[envVar] === '1') return { name, envVar };
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function requireAgent() {
|
|
18
|
+
const agent = detectCodingAgent();
|
|
19
|
+
if (agent) return { ok: true, ...agent };
|
|
20
|
+
return { ok: false };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function requireNotAgent() {
|
|
24
|
+
const agent = detectCodingAgent();
|
|
25
|
+
if (!agent) return { ok: true };
|
|
26
|
+
return { ok: false, ...agent };
|
|
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
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
export function parseGitUrl(input) {
|
|
5
|
+
if (typeof input !== 'string' || input.trim() === '') {
|
|
6
|
+
throw new Error('Invalid git URL: ' + String(input));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const raw = input.trim();
|
|
10
|
+
const normalizedError = () => new Error('Invalid git URL: ' + raw);
|
|
11
|
+
|
|
12
|
+
let host = '';
|
|
13
|
+
let path = '';
|
|
14
|
+
|
|
15
|
+
if (raw.includes('@') && !raw.includes('://')) {
|
|
16
|
+
const atIndex = raw.lastIndexOf('@');
|
|
17
|
+
const hostAndPath = raw.slice(atIndex + 1);
|
|
18
|
+
const colonIndex = hostAndPath.indexOf(':');
|
|
19
|
+
if (colonIndex === -1) {
|
|
20
|
+
throw normalizedError();
|
|
21
|
+
}
|
|
22
|
+
host = hostAndPath.slice(0, colonIndex);
|
|
23
|
+
path = hostAndPath.slice(colonIndex + 1);
|
|
24
|
+
if (!host || !path) {
|
|
25
|
+
throw normalizedError();
|
|
26
|
+
}
|
|
27
|
+
} else if (raw.includes('://')) {
|
|
28
|
+
let url;
|
|
29
|
+
try {
|
|
30
|
+
url = new URL(raw);
|
|
31
|
+
} catch {
|
|
32
|
+
throw normalizedError();
|
|
33
|
+
}
|
|
34
|
+
host = url.hostname;
|
|
35
|
+
path = url.pathname;
|
|
36
|
+
if (!host) {
|
|
37
|
+
throw normalizedError();
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
const slashIndex = raw.indexOf('/');
|
|
41
|
+
if (slashIndex !== -1) {
|
|
42
|
+
const maybeHost = raw.slice(0, slashIndex);
|
|
43
|
+
if (maybeHost.includes('.')) {
|
|
44
|
+
host = maybeHost;
|
|
45
|
+
path = raw.slice(slashIndex + 1);
|
|
46
|
+
if (!host) {
|
|
47
|
+
throw normalizedError();
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
throw normalizedError();
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
throw normalizedError();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const cleanedPath = path.replace(/^\/+|\/+$/g, '').replace(/\.git$/, '');
|
|
58
|
+
const segments = cleanedPath.split('/').filter(Boolean);
|
|
59
|
+
|
|
60
|
+
if (segments.length === 0 || segments.length >= 3) {
|
|
61
|
+
throw normalizedError();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let org = '';
|
|
65
|
+
let repo = '';
|
|
66
|
+
if (segments.length === 1) {
|
|
67
|
+
repo = segments[0];
|
|
68
|
+
} else {
|
|
69
|
+
org = segments[0];
|
|
70
|
+
repo = segments[1];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
host = host.toLowerCase();
|
|
74
|
+
org = org.toLowerCase();
|
|
75
|
+
repo = repo.toLowerCase();
|
|
76
|
+
|
|
77
|
+
if (!repo) {
|
|
78
|
+
throw normalizedError();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return { host, org, repo };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function toBeacon(input) {
|
|
85
|
+
const { host, org, repo } = parseGitUrl(input);
|
|
86
|
+
return org ? `${host}/${org}/${repo}` : `${host}//${repo}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export function beaconToHttps(input) {
|
|
90
|
+
if (typeof input === 'string' && input.startsWith('vit:')) {
|
|
91
|
+
const path = input.slice(4);
|
|
92
|
+
if (!path) throw new Error('Invalid beacon URI: ' + input);
|
|
93
|
+
return 'https://' + path.replace(/\/\//, '/');
|
|
94
|
+
}
|
|
95
|
+
const { host, org, repo } = parseGitUrl(input);
|
|
96
|
+
return org ? `https://${host}/${org}/${repo}` : `https://${host}/${repo}`;
|
|
97
|
+
}
|
package/src/lib/brand.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
const VIT_MARK = 'v\u0307'; // v̇
|
|
5
|
+
const VIT_BRAND = `${VIT_MARK}it`; // v̇it
|
|
6
|
+
|
|
7
|
+
const canCombine = process.stdout.isTTY && !process.env.TERM?.startsWith('dumb');
|
|
8
|
+
const brand = canCombine ? VIT_BRAND : 'vit';
|
|
9
|
+
const mark = canCombine ? VIT_MARK : 'v';
|
|
10
|
+
const prefix = canCombine ? `[${VIT_MARK}]` : '[v]';
|
|
11
|
+
const name = 'vit';
|
|
12
|
+
|
|
13
|
+
const DOT_VIT_README = `# .${VIT_BRAND}
|
|
14
|
+
|
|
15
|
+
this project participates in the social open source network. capabilities flow through people and agents you trust — not through gatekeepers or centralized platforms. the future of open source is social.
|
|
16
|
+
|
|
17
|
+
learn more at [v-it.org](https://v-it.org)
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
export { VIT_MARK, VIT_BRAND, brand, mark, prefix, name, DOT_VIT_README };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
5
|
+
import { wordlist } from '@scure/bip39/wordlists/english.js';
|
|
6
|
+
|
|
7
|
+
export const REF_PATTERN = /^[a-z]+-[a-z]+-[a-z]+$/;
|
|
8
|
+
|
|
9
|
+
export function hashTo3Words(input) {
|
|
10
|
+
const hash = sha256(new TextEncoder().encode(input));
|
|
11
|
+
// Take first 33 bits -> 3 x 11-bit indices into BIP39 wordlist (2048 words)
|
|
12
|
+
const i0 = (hash[0] << 3) | (hash[1] >> 5);
|
|
13
|
+
const i1 = ((hash[1] & 0x1f) << 6) | (hash[2] >> 2);
|
|
14
|
+
const i2 = ((hash[2] & 0x03) << 9) | (hash[3] << 1) | (hash[4] >> 7);
|
|
15
|
+
return `${wordlist[i0]}-${wordlist[i1]}-${wordlist[i2]}`;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function resolveRef(record, cid) {
|
|
19
|
+
if (record?.ref && REF_PATTERN.test(record.ref)) {
|
|
20
|
+
return record.ref;
|
|
21
|
+
}
|
|
22
|
+
return hashTo3Words(cid);
|
|
23
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
import { execFileSync } from 'node:child_process';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Find the full path of an executable (cross-runtime replacement for Bun.which).
|
|
8
|
+
* Returns the path string or null if not found.
|
|
9
|
+
*/
|
|
10
|
+
export function which(cmd) {
|
|
11
|
+
try {
|
|
12
|
+
const bin = process.platform === 'win32' ? 'where' : 'which';
|
|
13
|
+
return execFileSync(bin, [cmd], {
|
|
14
|
+
encoding: 'utf-8',
|
|
15
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
16
|
+
}).trim().split('\n')[0];
|
|
17
|
+
} catch {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { configDir, configPath } from './paths.js';
|
|
7
|
+
|
|
8
|
+
const vitJsonPath = configPath('vit.json');
|
|
9
|
+
|
|
10
|
+
export function loadConfig() {
|
|
11
|
+
if (!existsSync(vitJsonPath)) return {};
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(readFileSync(vitJsonPath, 'utf-8'));
|
|
14
|
+
} catch {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function saveConfig(obj) {
|
|
20
|
+
const now = Math.floor(Date.now() / 1000);
|
|
21
|
+
if (!obj.created_at) obj.created_at = now;
|
|
22
|
+
obj.updated_at = now;
|
|
23
|
+
mkdirSync(configDir, { recursive: true });
|
|
24
|
+
writeFileSync(vitJsonPath, JSON.stringify(obj, null, 2) + '\n');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function requireDid(opts) {
|
|
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;
|
|
37
|
+
if (!did) {
|
|
38
|
+
console.error("no DID configured. run 'vit login <handle>' first or pass --did.");
|
|
39
|
+
process.exitCode = 1;
|
|
40
|
+
}
|
|
41
|
+
return did;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function getScalars(obj) {
|
|
45
|
+
return Object.entries(obj).filter(
|
|
46
|
+
([, v]) => typeof v !== 'object' || v === null
|
|
47
|
+
);
|
|
48
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
export const CAP_COLLECTION = 'org.v-it.cap';
|
|
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
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
import { Agent, AtpAgent } from '@atproto/api';
|
|
5
|
+
import { NodeOAuthClient } from '@atproto/oauth-client-node';
|
|
6
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { configDir, configPath } from './paths.js';
|
|
9
|
+
|
|
10
|
+
const requestLock = async (_name, fn) => await fn();
|
|
11
|
+
|
|
12
|
+
const noopStore = {
|
|
13
|
+
set: async () => {},
|
|
14
|
+
get: async () => undefined,
|
|
15
|
+
del: async () => {},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const clientMetadata = {
|
|
19
|
+
client_id: 'https://v-it.org/client-metadata.json',
|
|
20
|
+
client_name: 'vit CLI',
|
|
21
|
+
application_type: 'native',
|
|
22
|
+
grant_types: ['authorization_code', 'refresh_token'],
|
|
23
|
+
response_types: ['code'],
|
|
24
|
+
scope: 'atproto transition:generic',
|
|
25
|
+
token_endpoint_auth_method: 'none',
|
|
26
|
+
dpop_bound_access_tokens: true,
|
|
27
|
+
client_uri: 'https://v-it.org',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export function createStore() {
|
|
31
|
+
const map = new Map();
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
set: async (key, value) => {
|
|
35
|
+
map.set(key, value);
|
|
36
|
+
},
|
|
37
|
+
get: async (key) => map.get(key),
|
|
38
|
+
del: async (key) => {
|
|
39
|
+
map.delete(key);
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function createSessionStore() {
|
|
45
|
+
const sessionFile = configPath('session.json');
|
|
46
|
+
let data = {};
|
|
47
|
+
try {
|
|
48
|
+
data = JSON.parse(readFileSync(sessionFile, 'utf-8'));
|
|
49
|
+
} catch {}
|
|
50
|
+
return {
|
|
51
|
+
set: async (key, value) => {
|
|
52
|
+
data[key] = value;
|
|
53
|
+
mkdirSync(configDir, { recursive: true });
|
|
54
|
+
writeFileSync(sessionFile, JSON.stringify(data, null, 2) + '\n');
|
|
55
|
+
},
|
|
56
|
+
get: async (key) => data[key],
|
|
57
|
+
del: async (key) => {
|
|
58
|
+
delete data[key];
|
|
59
|
+
mkdirSync(configDir, { recursive: true });
|
|
60
|
+
writeFileSync(sessionFile, JSON.stringify(data, null, 2) + '\n');
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
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
|
+
|
|
77
|
+
try {
|
|
78
|
+
const raw = readFileSync(configPath('session.json'), 'utf-8');
|
|
79
|
+
const data = JSON.parse(raw);
|
|
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;
|
|
88
|
+
if (!tokenSet) return null;
|
|
89
|
+
const accessValid = tokenSet.expires_at && new Date(tokenSet.expires_at) > new Date();
|
|
90
|
+
if (accessValid || tokenSet.refresh_token) return did;
|
|
91
|
+
return null;
|
|
92
|
+
} catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function createOAuthClient({ stateStore, sessionStore, redirectUri }) {
|
|
98
|
+
return new NodeOAuthClient({
|
|
99
|
+
requestLock,
|
|
100
|
+
clientMetadata: {
|
|
101
|
+
...clientMetadata,
|
|
102
|
+
redirect_uris: [redirectUri],
|
|
103
|
+
},
|
|
104
|
+
stateStore,
|
|
105
|
+
sessionStore,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
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
|
|
136
|
+
const sessionStore = createSessionStore();
|
|
137
|
+
const client = new NodeOAuthClient({
|
|
138
|
+
handleResolver: { resolve() { throw new Error('handle resolution not needed for restore'); } },
|
|
139
|
+
requestLock,
|
|
140
|
+
clientMetadata: {
|
|
141
|
+
...clientMetadata,
|
|
142
|
+
redirect_uris: ['http://127.0.0.1'],
|
|
143
|
+
},
|
|
144
|
+
stateStore: noopStore,
|
|
145
|
+
sessionStore,
|
|
146
|
+
});
|
|
147
|
+
const session = await client.restore(did);
|
|
148
|
+
return { agent: new Agent(session), session };
|
|
149
|
+
}
|