vit 0.0.1 → 0.1.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 +661 -21
- package/README.md +116 -2
- package/bin/vit.js +7 -0
- package/package.json +25 -18
- package/src/cli.js +42 -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 +59 -0
- package/src/cmd/firehose.js +148 -0
- package/src/cmd/follow.js +94 -0
- package/src/cmd/init.js +160 -0
- package/src/cmd/login.js +185 -0
- package/src/cmd/remix.js +136 -0
- package/src/cmd/setup.js +76 -0
- package/src/cmd/ship.js +195 -0
- package/src/cmd/skim.js +113 -0
- package/src/cmd/vet.js +141 -0
- package/src/cmd/vouch.js +134 -0
- package/src/lib/agent.js +27 -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 +39 -0
- package/src/lib/constants.js +5 -0
- package/src/lib/oauth.js +106 -0
- package/src/lib/paths.js +10 -0
- package/src/lib/sandbox.js +37 -0
- package/src/lib/vit-dir.js +61 -0
- package/.npmignore +0 -37
package/src/cmd/ship.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
import { TID } from '@atproto/common-web';
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
import { CAP_COLLECTION } from '../lib/constants.js';
|
|
7
|
+
import { requireAgent } from '../lib/agent.js';
|
|
8
|
+
import { requireDid } from '../lib/config.js';
|
|
9
|
+
import { restoreAgent } from '../lib/oauth.js';
|
|
10
|
+
import { appendLog, readProjectConfig, readLog, readFollowing } from '../lib/vit-dir.js';
|
|
11
|
+
import { REF_PATTERN, resolveRef } from '../lib/cap-ref.js';
|
|
12
|
+
import { name } from '../lib/brand.js';
|
|
13
|
+
|
|
14
|
+
export default function register(program) {
|
|
15
|
+
program
|
|
16
|
+
.command('ship')
|
|
17
|
+
.description('Publish a cap to your feed')
|
|
18
|
+
.option('-v, --verbose', 'Show step-by-step details')
|
|
19
|
+
.option('--did <did>', 'DID to use (reads saved DID from config if not provided)')
|
|
20
|
+
.requiredOption('--title <title>', 'Short title for the cap')
|
|
21
|
+
.requiredOption('--description <description>', 'Description of the cap')
|
|
22
|
+
.requiredOption('--ref <ref>', 'Three lowercase words with dashes (e.g. fast-cache-invalidation)')
|
|
23
|
+
.option('--recap <ref>', 'Ref of the cap this derives from (quote-post semantics)')
|
|
24
|
+
.action(async (opts) => {
|
|
25
|
+
try {
|
|
26
|
+
const gate = requireAgent();
|
|
27
|
+
if (!gate.ok) {
|
|
28
|
+
console.error(`${name} ship should be run by a coding agent (e.g. claude code, gemini cli).`);
|
|
29
|
+
console.error(`open your agent and ask it to run '${name} ship' for you.`);
|
|
30
|
+
process.exitCode = 1;
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const { verbose } = opts;
|
|
35
|
+
const did = requireDid(opts);
|
|
36
|
+
if (!did) return;
|
|
37
|
+
if (verbose) console.log(`[verbose] DID: ${did}`);
|
|
38
|
+
|
|
39
|
+
let text;
|
|
40
|
+
try {
|
|
41
|
+
text = readFileSync('/dev/stdin', 'utf-8').trim();
|
|
42
|
+
} catch {
|
|
43
|
+
text = '';
|
|
44
|
+
}
|
|
45
|
+
if (!text) {
|
|
46
|
+
console.error('error: cap body is required via stdin (pipe or heredoc)');
|
|
47
|
+
process.exitCode = 1;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!REF_PATTERN.test(opts.ref)) {
|
|
52
|
+
console.error('error: --ref must be exactly three lowercase words separated by dashes (e.g. fast-cache-invalidation)');
|
|
53
|
+
process.exitCode = 1;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let recapUri = null;
|
|
58
|
+
if (opts.recap) {
|
|
59
|
+
if (!REF_PATTERN.test(opts.recap)) {
|
|
60
|
+
console.error('error: --recap must be exactly three lowercase words separated by dashes (e.g. fast-cache-invalidation)');
|
|
61
|
+
process.exitCode = 1;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const caps = readLog('caps.jsonl');
|
|
66
|
+
const localMatch = caps.find(e => e.ref === opts.recap);
|
|
67
|
+
if (localMatch) {
|
|
68
|
+
recapUri = localMatch.uri;
|
|
69
|
+
if (verbose) console.log(`[verbose] recap resolved locally: ${recapUri}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const now = new Date().toISOString();
|
|
74
|
+
|
|
75
|
+
const { agent, session } = await restoreAgent(did);
|
|
76
|
+
if (verbose) console.log(`[verbose] Session restored, PDS: ${session.serverMetadata?.issuer}`);
|
|
77
|
+
|
|
78
|
+
if (opts.recap && !recapUri) {
|
|
79
|
+
const following = readFollowing();
|
|
80
|
+
const dids = following.map(e => e.did);
|
|
81
|
+
dids.push(did);
|
|
82
|
+
if (verbose) console.log(`[verbose] recap: querying ${dids.length} accounts`);
|
|
83
|
+
|
|
84
|
+
let match = null;
|
|
85
|
+
for (const repoDid of dids) {
|
|
86
|
+
try {
|
|
87
|
+
const res = await agent.com.atproto.repo.listRecords({
|
|
88
|
+
repo: repoDid,
|
|
89
|
+
collection: CAP_COLLECTION,
|
|
90
|
+
limit: 50,
|
|
91
|
+
});
|
|
92
|
+
for (const rec of res.data.records) {
|
|
93
|
+
const recRef = resolveRef(rec.value, rec.cid);
|
|
94
|
+
if (recRef === opts.recap) {
|
|
95
|
+
if (!match || (rec.value.createdAt || '') > (match.value.createdAt || '')) {
|
|
96
|
+
match = rec;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
} catch (err) {
|
|
101
|
+
if (verbose) console.log(`[verbose] ${repoDid}: error fetching caps: ${err.message}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (match) {
|
|
106
|
+
recapUri = match.uri;
|
|
107
|
+
if (verbose) console.log(`[verbose] recap resolved remotely: ${recapUri}`);
|
|
108
|
+
} else {
|
|
109
|
+
console.error(`error: could not find cap with ref '${opts.recap}' to recap`);
|
|
110
|
+
process.exitCode = 1;
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const record = {
|
|
116
|
+
$type: CAP_COLLECTION,
|
|
117
|
+
text,
|
|
118
|
+
title: opts.title,
|
|
119
|
+
description: opts.description,
|
|
120
|
+
ref: opts.ref,
|
|
121
|
+
createdAt: now,
|
|
122
|
+
};
|
|
123
|
+
const projectConfig = readProjectConfig();
|
|
124
|
+
if (projectConfig.beacon) record.beacon = projectConfig.beacon;
|
|
125
|
+
if (opts.recap) record.recap = { uri: recapUri, ref: opts.recap };
|
|
126
|
+
if (verbose && projectConfig.beacon) console.log(`[verbose] Beacon: ${projectConfig.beacon}`);
|
|
127
|
+
const rkey = TID.nextStr();
|
|
128
|
+
if (verbose) console.log(`[verbose] Record built, rkey: ${rkey}`);
|
|
129
|
+
const putArgs = {
|
|
130
|
+
repo: did,
|
|
131
|
+
collection: CAP_COLLECTION,
|
|
132
|
+
rkey,
|
|
133
|
+
record,
|
|
134
|
+
validate: false,
|
|
135
|
+
};
|
|
136
|
+
if (verbose) console.log(`[verbose] putRecord ${putArgs.collection} rkey=${rkey}`);
|
|
137
|
+
const putRes = await agent.com.atproto.repo.putRecord(putArgs);
|
|
138
|
+
try {
|
|
139
|
+
appendLog('caps.jsonl', {
|
|
140
|
+
ts: now,
|
|
141
|
+
did,
|
|
142
|
+
rkey,
|
|
143
|
+
ref: opts.ref,
|
|
144
|
+
collection: CAP_COLLECTION,
|
|
145
|
+
pds: session.serverMetadata?.issuer,
|
|
146
|
+
uri: putRes.data.uri,
|
|
147
|
+
cid: putRes.data.cid,
|
|
148
|
+
});
|
|
149
|
+
} catch (logErr) {
|
|
150
|
+
console.error('warning: failed to write caps.jsonl:', logErr.message);
|
|
151
|
+
}
|
|
152
|
+
if (verbose) console.log(`[verbose] Log written to caps.jsonl`);
|
|
153
|
+
console.log(
|
|
154
|
+
JSON.stringify({
|
|
155
|
+
ts: now,
|
|
156
|
+
pds: session.serverMetadata?.issuer,
|
|
157
|
+
xrpc: 'com.atproto.repo.putRecord',
|
|
158
|
+
request: putArgs,
|
|
159
|
+
response: putRes.data,
|
|
160
|
+
}),
|
|
161
|
+
);
|
|
162
|
+
} catch (err) {
|
|
163
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
164
|
+
process.exitCode = 1;
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
.addHelpText('after', `
|
|
168
|
+
Authoring guidance (for coding agents):
|
|
169
|
+
|
|
170
|
+
Fields:
|
|
171
|
+
--title Short name for the cap (2-5 words)
|
|
172
|
+
--description One sentence explaining what this cap does
|
|
173
|
+
--ref Three lowercase words with dashes (your-ref-name)
|
|
174
|
+
--recap <ref> Optional. Ref of the cap this derives from (links back to original)
|
|
175
|
+
body (stdin) Full cap content, piped or via heredoc
|
|
176
|
+
|
|
177
|
+
What makes a good cap:
|
|
178
|
+
- Title is a concise noun phrase: "Fast LRU Cache", "JWT Auth Middleware"
|
|
179
|
+
- Description explains the value: "Thread-safe LRU cache with O(1) eviction"
|
|
180
|
+
- Body contains the complete, self-contained capability text
|
|
181
|
+
- Ref is a memorable three-word slug for discovery
|
|
182
|
+
|
|
183
|
+
When to use --recap:
|
|
184
|
+
Use --recap when this cap is derived from another cap (e.g. after vit remix).
|
|
185
|
+
It creates a link back to the original, like a quote-post.
|
|
186
|
+
|
|
187
|
+
Example:
|
|
188
|
+
vit ship --title "Fast LRU Cache" \\
|
|
189
|
+
--description "Thread-safe LRU cache with O(1) eviction" \\
|
|
190
|
+
--ref "fast-lru-cache" \\
|
|
191
|
+
--recap "original-cache-ref" \\
|
|
192
|
+
<<'EOF'
|
|
193
|
+
... full cap body text ...
|
|
194
|
+
EOF`);
|
|
195
|
+
}
|
package/src/cmd/skim.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
import { requireDid } from '../lib/config.js';
|
|
5
|
+
import { CAP_COLLECTION } from '../lib/constants.js';
|
|
6
|
+
import { restoreAgent } from '../lib/oauth.js';
|
|
7
|
+
import { readProjectConfig, readFollowing } from '../lib/vit-dir.js';
|
|
8
|
+
import { requireAgent } from '../lib/agent.js';
|
|
9
|
+
import { resolveRef } from '../lib/cap-ref.js';
|
|
10
|
+
import { name } from '../lib/brand.js';
|
|
11
|
+
|
|
12
|
+
export default function register(program) {
|
|
13
|
+
program
|
|
14
|
+
.command('skim')
|
|
15
|
+
.description('Read caps from followed accounts, filtered by beacon')
|
|
16
|
+
.option('--did <did>', 'DID to use')
|
|
17
|
+
.option('--handle <handle>', 'Show caps from a specific handle only')
|
|
18
|
+
.option('--limit <n>', 'Max caps to display', '25')
|
|
19
|
+
.option('--json', 'Output as JSON array')
|
|
20
|
+
.option('-v, --verbose', 'Show step-by-step details')
|
|
21
|
+
.action(async (opts) => {
|
|
22
|
+
try {
|
|
23
|
+
const gate = requireAgent();
|
|
24
|
+
if (!gate.ok) {
|
|
25
|
+
console.error(`${name} skim should be run by a coding agent (e.g. claude code, gemini cli).`);
|
|
26
|
+
console.error(`open your agent and ask it to run '${name} skim' for you.`);
|
|
27
|
+
process.exitCode = 1;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const { verbose } = opts;
|
|
32
|
+
const did = requireDid(opts);
|
|
33
|
+
if (!did) return;
|
|
34
|
+
if (verbose) console.log(`[verbose] DID: ${did}`);
|
|
35
|
+
|
|
36
|
+
const projectConfig = readProjectConfig();
|
|
37
|
+
const beacon = projectConfig.beacon;
|
|
38
|
+
if (!beacon) {
|
|
39
|
+
console.error(`no beacon set. run '${name} init' in a project directory first.`);
|
|
40
|
+
process.exitCode = 1;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (verbose) console.log(`[verbose] beacon: ${beacon}`);
|
|
44
|
+
|
|
45
|
+
const { agent } = await restoreAgent(did);
|
|
46
|
+
if (verbose) console.log('[verbose] session restored');
|
|
47
|
+
|
|
48
|
+
// build list of DIDs to query
|
|
49
|
+
let dids;
|
|
50
|
+
if (opts.handle) {
|
|
51
|
+
const handle = opts.handle.replace(/^@/, '');
|
|
52
|
+
const resolved = await agent.resolveHandle({ handle });
|
|
53
|
+
dids = [resolved.data.did];
|
|
54
|
+
if (verbose) console.log(`[verbose] resolved ${handle} to ${resolved.data.did}`);
|
|
55
|
+
} else {
|
|
56
|
+
const following = readFollowing();
|
|
57
|
+
dids = following.map(e => e.did);
|
|
58
|
+
dids.push(did);
|
|
59
|
+
if (verbose) console.log(`[verbose] querying ${dids.length} accounts (${dids.length - 1} follows + self)`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// fetch caps from each DID
|
|
63
|
+
const allCaps = [];
|
|
64
|
+
for (const repoDid of dids) {
|
|
65
|
+
try {
|
|
66
|
+
const res = await agent.com.atproto.repo.listRecords({
|
|
67
|
+
repo: repoDid,
|
|
68
|
+
collection: CAP_COLLECTION,
|
|
69
|
+
limit: 50,
|
|
70
|
+
});
|
|
71
|
+
const caps = res.data.records.filter(r => r.value.beacon === beacon);
|
|
72
|
+
if (verbose) console.log(`[verbose] ${repoDid}: ${res.data.records.length} caps, ${caps.length} matching beacon`);
|
|
73
|
+
allCaps.push(...caps);
|
|
74
|
+
} catch (err) {
|
|
75
|
+
if (verbose) console.log(`[verbose] ${repoDid}: error fetching caps: ${err.message}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// sort by createdAt descending
|
|
80
|
+
allCaps.sort((a, b) => {
|
|
81
|
+
const ta = a.value.createdAt || '';
|
|
82
|
+
const tb = b.value.createdAt || '';
|
|
83
|
+
return tb.localeCompare(ta);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// apply limit
|
|
87
|
+
const limit = parseInt(opts.limit, 10);
|
|
88
|
+
const capped = allCaps.slice(0, limit);
|
|
89
|
+
|
|
90
|
+
if (opts.json) {
|
|
91
|
+
console.log(JSON.stringify(capped, null, 2));
|
|
92
|
+
} else {
|
|
93
|
+
if (capped.length === 0) {
|
|
94
|
+
console.log('no caps found for this beacon.');
|
|
95
|
+
}
|
|
96
|
+
for (const rec of capped) {
|
|
97
|
+
const ref = resolveRef(rec.value, rec.cid);
|
|
98
|
+
const title = rec.value.title || '';
|
|
99
|
+
const description = rec.value.description || '';
|
|
100
|
+
console.log(`ref: ${ref}`);
|
|
101
|
+
if (title) console.log(`title: ${title}`);
|
|
102
|
+
if (description) console.log(`description: ${description}`);
|
|
103
|
+
console.log();
|
|
104
|
+
}
|
|
105
|
+
console.log('---');
|
|
106
|
+
console.log(`hint: tell your user to run '${name} vet <ref>' in another terminal for any cap they want to review.`);
|
|
107
|
+
}
|
|
108
|
+
} catch (err) {
|
|
109
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
110
|
+
process.exitCode = 1;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
package/src/cmd/vet.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
import { requireDid } from '../lib/config.js';
|
|
5
|
+
import { CAP_COLLECTION } from '../lib/constants.js';
|
|
6
|
+
import { restoreAgent } from '../lib/oauth.js';
|
|
7
|
+
import { appendLog, readProjectConfig, readFollowing } from '../lib/vit-dir.js';
|
|
8
|
+
import { requireNotAgent } from '../lib/agent.js';
|
|
9
|
+
import { resolveRef, REF_PATTERN } from '../lib/cap-ref.js';
|
|
10
|
+
import { mark, brand, name } from '../lib/brand.js';
|
|
11
|
+
|
|
12
|
+
export default function register(program) {
|
|
13
|
+
program
|
|
14
|
+
.command('vet')
|
|
15
|
+
.argument('<ref>', 'Three-word cap reference (e.g. fast-cache-invalidation)')
|
|
16
|
+
.description('Review a cap before trusting it')
|
|
17
|
+
.option('--did <did>', 'DID to use')
|
|
18
|
+
.option('--trust', 'Mark the cap as locally trusted')
|
|
19
|
+
.option('-v, --verbose', 'Show step-by-step details')
|
|
20
|
+
.action(async (ref, opts) => {
|
|
21
|
+
try {
|
|
22
|
+
const gate = requireNotAgent();
|
|
23
|
+
if (!gate.ok) {
|
|
24
|
+
console.error(`${name} vet must be run by a human. run it in your own terminal.`);
|
|
25
|
+
console.error('');
|
|
26
|
+
console.error('cap vetting requires human review for safety.');
|
|
27
|
+
console.error('ask your user to run this command in their terminal:');
|
|
28
|
+
console.error('');
|
|
29
|
+
console.error(` vit vet ${ref}`);
|
|
30
|
+
console.error('');
|
|
31
|
+
console.error('after reviewing, they can trust it with:');
|
|
32
|
+
console.error('');
|
|
33
|
+
console.error(` vit vet ${ref} --trust`);
|
|
34
|
+
console.error('');
|
|
35
|
+
console.error('once trusted, ask your user to confirm and you can proceed.');
|
|
36
|
+
process.exitCode = 1;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const { verbose } = opts;
|
|
41
|
+
|
|
42
|
+
if (!REF_PATTERN.test(ref)) {
|
|
43
|
+
console.error('invalid ref. expected three lowercase words with dashes (e.g. fast-cache-invalidation)');
|
|
44
|
+
process.exitCode = 1;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const did = requireDid(opts);
|
|
49
|
+
if (!did) return;
|
|
50
|
+
if (verbose) console.log(`[verbose] DID: ${did}`);
|
|
51
|
+
|
|
52
|
+
const projectConfig = readProjectConfig();
|
|
53
|
+
const beacon = projectConfig.beacon;
|
|
54
|
+
if (!beacon) {
|
|
55
|
+
console.error(`no beacon set. run '${name} init' in a project directory first.`);
|
|
56
|
+
process.exitCode = 1;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (verbose) console.log(`[verbose] beacon: ${beacon}`);
|
|
60
|
+
|
|
61
|
+
const { agent } = await restoreAgent(did);
|
|
62
|
+
if (verbose) console.log('[verbose] session restored');
|
|
63
|
+
|
|
64
|
+
// build DID list from following + self
|
|
65
|
+
const following = readFollowing();
|
|
66
|
+
const dids = following.map(e => e.did);
|
|
67
|
+
dids.push(did);
|
|
68
|
+
if (verbose) console.log(`[verbose] querying ${dids.length} accounts`);
|
|
69
|
+
|
|
70
|
+
// fetch caps from each DID, find matching ref
|
|
71
|
+
let match = null;
|
|
72
|
+
for (const repoDid of dids) {
|
|
73
|
+
try {
|
|
74
|
+
const res = await agent.com.atproto.repo.listRecords({
|
|
75
|
+
repo: repoDid,
|
|
76
|
+
collection: CAP_COLLECTION,
|
|
77
|
+
limit: 50,
|
|
78
|
+
});
|
|
79
|
+
for (const rec of res.data.records) {
|
|
80
|
+
if (rec.value.beacon !== beacon) continue;
|
|
81
|
+
const recRef = resolveRef(rec.value, rec.cid);
|
|
82
|
+
if (recRef === ref) {
|
|
83
|
+
if (!match || (rec.value.createdAt || '') > (match.value.createdAt || '')) {
|
|
84
|
+
match = rec;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
} catch (err) {
|
|
89
|
+
if (verbose) console.log(`[verbose] ${repoDid}: error fetching caps: ${err.message}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!match) {
|
|
94
|
+
console.error(`no cap found with ref '${ref}' for this beacon.`);
|
|
95
|
+
process.exitCode = 1;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const record = match.value;
|
|
100
|
+
|
|
101
|
+
if (opts.trust) {
|
|
102
|
+
appendLog('trusted.jsonl', {
|
|
103
|
+
ref,
|
|
104
|
+
uri: match.uri,
|
|
105
|
+
trustedAt: new Date().toISOString(),
|
|
106
|
+
});
|
|
107
|
+
console.log(`${mark} trusted: ${ref}`);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const author = match.uri.split('/')[2];
|
|
112
|
+
const title = record.title || '';
|
|
113
|
+
const description = record.description || '';
|
|
114
|
+
const text = record.text || '';
|
|
115
|
+
|
|
116
|
+
console.log(`=== ${brand} cap review ===`);
|
|
117
|
+
console.log('Review this cap carefully before trusting it.');
|
|
118
|
+
console.log('');
|
|
119
|
+
console.log(` Ref: ${ref}`);
|
|
120
|
+
if (title) console.log(` Title: ${title}`);
|
|
121
|
+
console.log(` Author: ${author}`);
|
|
122
|
+
if (description) {
|
|
123
|
+
console.log('');
|
|
124
|
+
console.log(` ${description}`);
|
|
125
|
+
}
|
|
126
|
+
if (text) {
|
|
127
|
+
console.log('');
|
|
128
|
+
console.log('--- Text ---');
|
|
129
|
+
console.log(text);
|
|
130
|
+
console.log('---');
|
|
131
|
+
}
|
|
132
|
+
console.log('');
|
|
133
|
+
console.log('To trust this cap, run:');
|
|
134
|
+
console.log('');
|
|
135
|
+
console.log(` vit vet ${ref} --trust`);
|
|
136
|
+
} catch (err) {
|
|
137
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
138
|
+
process.exitCode = 1;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
package/src/cmd/vouch.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
import { requireDid } from '../lib/config.js';
|
|
5
|
+
import { CAP_COLLECTION, VOUCH_COLLECTION } from '../lib/constants.js';
|
|
6
|
+
import { TID } from '@atproto/common-web';
|
|
7
|
+
import { restoreAgent } from '../lib/oauth.js';
|
|
8
|
+
import { appendLog, readProjectConfig, readFollowing, readLog } from '../lib/vit-dir.js';
|
|
9
|
+
import { resolveRef, REF_PATTERN } from '../lib/cap-ref.js';
|
|
10
|
+
import { mark, name } from '../lib/brand.js';
|
|
11
|
+
|
|
12
|
+
export default function register(program) {
|
|
13
|
+
program
|
|
14
|
+
.command('vouch')
|
|
15
|
+
.argument('<ref>', 'Three-word cap reference (e.g. fast-cache-invalidation)')
|
|
16
|
+
.description('Publicly endorse a vetted cap')
|
|
17
|
+
.option('--did <did>', 'DID to use')
|
|
18
|
+
.option('-v, --verbose', 'Show step-by-step details')
|
|
19
|
+
.action(async (ref, opts) => {
|
|
20
|
+
try {
|
|
21
|
+
const { verbose } = opts;
|
|
22
|
+
|
|
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;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const did = requireDid(opts);
|
|
30
|
+
if (!did) return;
|
|
31
|
+
if (verbose) console.log(`[verbose] DID: ${did}`);
|
|
32
|
+
|
|
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}`);
|
|
56
|
+
|
|
57
|
+
const { agent } = await restoreAgent(did);
|
|
58
|
+
if (verbose) console.log('[verbose] session restored');
|
|
59
|
+
|
|
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`);
|
|
64
|
+
|
|
65
|
+
let match = null;
|
|
66
|
+
for (const repoDid of dids) {
|
|
67
|
+
try {
|
|
68
|
+
const res = await agent.com.atproto.repo.listRecords({
|
|
69
|
+
repo: repoDid,
|
|
70
|
+
collection: CAP_COLLECTION,
|
|
71
|
+
limit: 50,
|
|
72
|
+
});
|
|
73
|
+
for (const rec of res.data.records) {
|
|
74
|
+
if (rec.value.beacon !== beacon) continue;
|
|
75
|
+
const recRef = resolveRef(rec.value, rec.cid);
|
|
76
|
+
if (recRef === ref) {
|
|
77
|
+
if (!match || (rec.value.createdAt || '') > (match.value.createdAt || '')) {
|
|
78
|
+
match = rec;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} catch (err) {
|
|
83
|
+
if (verbose) console.log(`[verbose] ${repoDid}: error fetching caps: ${err.message}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!match) {
|
|
88
|
+
console.error(`no cap found with ref '${ref}' for this beacon.`);
|
|
89
|
+
process.exitCode = 1;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
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', {
|
|
116
|
+
ref,
|
|
117
|
+
uri: match.uri,
|
|
118
|
+
cid: match.cid,
|
|
119
|
+
vouchUri: res.data.uri,
|
|
120
|
+
beacon,
|
|
121
|
+
ts: now,
|
|
122
|
+
});
|
|
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
|
+
|
|
128
|
+
console.log(`${mark} vouched: ${ref} (${match.uri})`);
|
|
129
|
+
} catch (err) {
|
|
130
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
131
|
+
process.exitCode = 1;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
package/src/lib/agent.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
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
|
+
}
|