vit 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -661
- package/README.md +55 -78
- package/bin/vit.js +1 -1
- package/package.json +10 -3
- package/skills/vit/COMMANDS.md +270 -0
- package/skills/vit/SKILL.md +203 -0
- package/src/cli.js +13 -3
- package/src/cmd/adopt.js +1 -1
- package/src/cmd/beacon.js +3 -2
- package/src/cmd/config.js +7 -2
- package/src/cmd/doctor.js +143 -20
- package/src/cmd/explore.js +483 -0
- package/src/cmd/firehose.js +20 -9
- package/src/cmd/follow.js +63 -11
- package/src/cmd/hack.js +83 -0
- package/src/cmd/inbox.js +131 -0
- package/src/cmd/init.js +95 -13
- package/src/cmd/learn.js +262 -0
- package/src/cmd/link.js +75 -0
- package/src/cmd/login.js +95 -13
- package/src/cmd/remix.js +86 -37
- package/src/cmd/scan.js +209 -0
- package/src/cmd/ship.js +665 -149
- package/src/cmd/skim.js +140 -38
- package/src/cmd/vet.js +597 -97
- package/src/cmd/vouch.js +269 -89
- package/src/lib/agent.js +11 -1
- package/src/lib/beacon.js +1 -1
- package/src/lib/brand.js +1 -1
- package/src/lib/cap-ref.js +1 -1
- package/src/lib/compat.js +1 -1
- package/src/lib/config.js +11 -2
- package/src/lib/constants.js +4 -1
- package/src/lib/json-output.js +13 -0
- package/src/lib/oauth.js +49 -6
- package/src/lib/paths.js +1 -1
- package/src/lib/pds.js +79 -0
- package/src/lib/sandbox.js +1 -1
- package/src/lib/skill-ref.js +37 -0
- package/src/lib/trust-gate.js +39 -0
- package/src/lib/vit-dir.js +9 -1
- package/src/postinstall.js +26 -0
- package/src/cmd/setup.js +0 -76
package/src/cmd/learn.js
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import { mkdirSync, writeFileSync, mkdtempSync, rmSync } from 'node:fs';
|
|
6
|
+
import { join, dirname } from 'node:path';
|
|
7
|
+
import { homedir, tmpdir } from 'node:os';
|
|
8
|
+
import { requireDid } from '../lib/config.js';
|
|
9
|
+
import { SKILL_COLLECTION } from '../lib/constants.js';
|
|
10
|
+
import { restoreAgent } from '../lib/oauth.js';
|
|
11
|
+
import { readFollowing, readLog, appendLog } from '../lib/vit-dir.js';
|
|
12
|
+
import { requireAgent, detectCodingAgent } from '../lib/agent.js';
|
|
13
|
+
import { shouldBypassVet } from '../lib/trust-gate.js';
|
|
14
|
+
import { isSkillRef, nameFromSkillRef, isValidSkillRef } from '../lib/skill-ref.js';
|
|
15
|
+
import { mark, name } from '../lib/brand.js';
|
|
16
|
+
import { resolvePds, listRecordsFromPds, batchQuery } from '../lib/pds.js';
|
|
17
|
+
import { loadConfig } from '../lib/config.js';
|
|
18
|
+
import { jsonOk, jsonError } from '../lib/json-output.js';
|
|
19
|
+
|
|
20
|
+
export default function register(program) {
|
|
21
|
+
program
|
|
22
|
+
.command('learn')
|
|
23
|
+
.argument('<ref>', 'Skill reference (e.g. skill-agent-test-patterns)')
|
|
24
|
+
.description('Install a skill from the network into your skill directory')
|
|
25
|
+
.option('--did <did>', 'DID to use')
|
|
26
|
+
.option('--user', 'Install to user-wide ~/.claude/skills/ (requires vet)')
|
|
27
|
+
.option('--json', 'Output as JSON')
|
|
28
|
+
.option('-v, --verbose', 'Show step-by-step details')
|
|
29
|
+
.action(async (ref, opts) => {
|
|
30
|
+
try {
|
|
31
|
+
const gate = requireAgent();
|
|
32
|
+
if (!gate.ok) {
|
|
33
|
+
if (opts.json) {
|
|
34
|
+
jsonError('agent required', 'run vit learn from a coding agent');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
console.error(`${name} learn should be run by a coding agent (e.g. claude code, gemini cli).`);
|
|
38
|
+
console.error(`open your agent and ask it to run '${name} learn' for you.`);
|
|
39
|
+
process.exitCode = 1;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const { verbose } = opts;
|
|
44
|
+
const vlog = opts.json ? (...a) => console.error(...a) : console.log;
|
|
45
|
+
|
|
46
|
+
if (!isSkillRef(ref)) {
|
|
47
|
+
if (opts.json) {
|
|
48
|
+
jsonError('invalid skill ref', 'expected format: skill-{name}');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
console.error(`invalid skill ref. expected format: skill-{name} (e.g. skill-agent-test-patterns)`);
|
|
52
|
+
process.exitCode = 1;
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!isValidSkillRef(ref)) {
|
|
57
|
+
if (opts.json) {
|
|
58
|
+
jsonError('invalid skill ref', 'lowercase letters, numbers, hyphens only');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
console.error('invalid skill ref. name must be lowercase letters, numbers, hyphens only.');
|
|
62
|
+
console.error('no leading hyphen, no consecutive hyphens, max 64 chars.');
|
|
63
|
+
process.exitCode = 1;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const skillName = nameFromSkillRef(ref);
|
|
68
|
+
if (verbose) vlog(`[verbose] skill name: ${skillName}`);
|
|
69
|
+
|
|
70
|
+
// Trust gate
|
|
71
|
+
const isUserInstall = !!opts.user;
|
|
72
|
+
const trusted = readLog('trusted.jsonl');
|
|
73
|
+
const trustedEntry = trusted.find(e => e.ref === ref);
|
|
74
|
+
|
|
75
|
+
if (isUserInstall && !trustedEntry) {
|
|
76
|
+
// --user ALWAYS requires vet
|
|
77
|
+
if (opts.json) {
|
|
78
|
+
jsonError(`skill '${ref}' is not yet vetted`, 'user-wide install requires vetting');
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
console.error(`skill '${ref}' is not yet vetted. user-wide install requires vetting.`);
|
|
82
|
+
console.error(`tell your operator to vet it first:`);
|
|
83
|
+
console.error('');
|
|
84
|
+
console.error(` vit vet ${ref}`);
|
|
85
|
+
console.error('');
|
|
86
|
+
console.error('after reviewing, they can trust it with:');
|
|
87
|
+
console.error('');
|
|
88
|
+
console.error(` vit vet ${ref} --trust`);
|
|
89
|
+
process.exitCode = 1;
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!isUserInstall && !trustedEntry) {
|
|
94
|
+
// Project-level: requires vet UNLESS dangerous-accept
|
|
95
|
+
const trustGate = shouldBypassVet();
|
|
96
|
+
if (!trustGate.bypass) {
|
|
97
|
+
if (opts.json) {
|
|
98
|
+
jsonError(`skill '${ref}' is not yet vetted`, `run 'vit vet ${ref}' first`);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
console.error(`skill '${ref}' is not yet vetted.`);
|
|
102
|
+
console.error(`tell your operator to vet it first:`);
|
|
103
|
+
console.error('');
|
|
104
|
+
console.error(` vit vet ${ref}`);
|
|
105
|
+
console.error('');
|
|
106
|
+
console.error('after reviewing, they can trust it with:');
|
|
107
|
+
console.error('');
|
|
108
|
+
console.error(` vit vet ${ref} --trust`);
|
|
109
|
+
if (detectCodingAgent()) {
|
|
110
|
+
console.error('');
|
|
111
|
+
console.error('or, to trust all items without review:');
|
|
112
|
+
console.error('');
|
|
113
|
+
console.error(' vit vet --dangerous-accept --confirm');
|
|
114
|
+
}
|
|
115
|
+
process.exitCode = 1;
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (verbose) vlog(`[verbose] vet gate bypassed: ${trustGate.reason}`);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (opts.json && !(opts.did || loadConfig().did)) {
|
|
122
|
+
jsonError('no DID configured', "run 'vit login <handle>' first");
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const did = requireDid(opts);
|
|
126
|
+
if (!did) return;
|
|
127
|
+
if (verbose) vlog(`[verbose] DID: ${did}`);
|
|
128
|
+
|
|
129
|
+
const { agent } = await restoreAgent(did);
|
|
130
|
+
if (verbose) vlog('[verbose] session restored');
|
|
131
|
+
|
|
132
|
+
// Build DID list from following + self
|
|
133
|
+
const following = readFollowing();
|
|
134
|
+
const dids = following.map(e => e.did);
|
|
135
|
+
dids.push(did);
|
|
136
|
+
|
|
137
|
+
// Fetch skills from each DID, find matching ref
|
|
138
|
+
const allRecords = await batchQuery(dids, async (repoDid) => {
|
|
139
|
+
const pds = await resolvePds(repoDid);
|
|
140
|
+
if (verbose) vlog(`[verbose] ${repoDid}: resolved PDS ${pds}`);
|
|
141
|
+
return (await listRecordsFromPds(pds, repoDid, SKILL_COLLECTION, 50)).records;
|
|
142
|
+
}, { verbose });
|
|
143
|
+
|
|
144
|
+
let match = null;
|
|
145
|
+
for (const records of allRecords) {
|
|
146
|
+
for (const rec of records) {
|
|
147
|
+
const recName = rec.value.name;
|
|
148
|
+
if (recName === skillName) {
|
|
149
|
+
if (!match || (rec.value.createdAt || '') > (match.value.createdAt || '')) {
|
|
150
|
+
match = rec;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (!match) {
|
|
157
|
+
if (opts.json) {
|
|
158
|
+
jsonError(`no skill found with ref '${ref}'`);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
console.error(`no skill found with ref '${ref}' from followed accounts.`);
|
|
162
|
+
console.error('');
|
|
163
|
+
console.error('hint: skills appear from accounts you follow and your own.');
|
|
164
|
+
console.error(` vit following check who you're following`);
|
|
165
|
+
console.error(` vit explore skills browse skills network-wide`);
|
|
166
|
+
process.exitCode = 1;
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const record = match.value;
|
|
171
|
+
if (verbose) vlog(`[verbose] found skill: ${record.name} from ${match.uri}`);
|
|
172
|
+
|
|
173
|
+
// Install via skills CLI
|
|
174
|
+
const tempDir = mkdtempSync(join(tmpdir(), 'vit-learn-'));
|
|
175
|
+
try {
|
|
176
|
+
writeFileSync(join(tempDir, 'SKILL.md'), record.text);
|
|
177
|
+
if (verbose) vlog('[verbose] wrote SKILL.md to temp dir');
|
|
178
|
+
|
|
179
|
+
// Download resource blobs to temp dir
|
|
180
|
+
if (record.resources && record.resources.length > 0) {
|
|
181
|
+
const authorDid = match.uri.split('/')[2];
|
|
182
|
+
const pds = await resolvePds(authorDid);
|
|
183
|
+
|
|
184
|
+
for (const resource of record.resources) {
|
|
185
|
+
const resourcePath = join(tempDir, resource.path);
|
|
186
|
+
mkdirSync(dirname(resourcePath), { recursive: true });
|
|
187
|
+
|
|
188
|
+
try {
|
|
189
|
+
// Download blob from PDS
|
|
190
|
+
const blobCid = resource.blob?.ref?.$link || resource.blob?.cid;
|
|
191
|
+
if (blobCid) {
|
|
192
|
+
const blobUrl = new URL('/xrpc/com.atproto.sync.getBlob', pds);
|
|
193
|
+
blobUrl.searchParams.set('did', authorDid);
|
|
194
|
+
blobUrl.searchParams.set('cid', blobCid);
|
|
195
|
+
const blobRes = await fetch(blobUrl);
|
|
196
|
+
if (!blobRes.ok) throw new Error(`blob fetch failed: ${blobRes.status}`);
|
|
197
|
+
const blobData = Buffer.from(await blobRes.arrayBuffer());
|
|
198
|
+
writeFileSync(resourcePath, blobData);
|
|
199
|
+
if (verbose) vlog(`[verbose] wrote resource: ${resource.path}`);
|
|
200
|
+
}
|
|
201
|
+
} catch (err) {
|
|
202
|
+
console.error(`warning: failed to download resource ${resource.path}: ${err.message}`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Delegate to skills CLI
|
|
208
|
+
const addArgs = ['skills', 'add', tempDir, '-a', 'claude-code', '-y'];
|
|
209
|
+
if (isUserInstall) addArgs.push('-g');
|
|
210
|
+
const addResult = spawnSync('npx', addArgs, {
|
|
211
|
+
encoding: 'utf-8',
|
|
212
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
213
|
+
});
|
|
214
|
+
if (addResult.status !== 0) {
|
|
215
|
+
const errText = (addResult.stderr || addResult.stdout || '').trim();
|
|
216
|
+
throw new Error(`skill install failed: ${errText || 'unknown error'}`);
|
|
217
|
+
}
|
|
218
|
+
if (verbose) vlog('[verbose] installed via npx skills add');
|
|
219
|
+
} finally {
|
|
220
|
+
try { rmSync(tempDir, { recursive: true, force: true }); } catch {}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Determine install path for logging
|
|
224
|
+
const installDir = isUserInstall
|
|
225
|
+
? join(homedir(), '.claude', 'skills', skillName)
|
|
226
|
+
: join(process.cwd(), '.claude', 'skills', skillName);
|
|
227
|
+
|
|
228
|
+
// Log to learned.jsonl
|
|
229
|
+
try {
|
|
230
|
+
appendLog('learned.jsonl', {
|
|
231
|
+
ref,
|
|
232
|
+
name: skillName,
|
|
233
|
+
uri: match.uri,
|
|
234
|
+
cid: match.cid,
|
|
235
|
+
installedTo: installDir,
|
|
236
|
+
scope: isUserInstall ? 'user' : 'project',
|
|
237
|
+
learnedAt: new Date().toISOString(),
|
|
238
|
+
version: record.version || null,
|
|
239
|
+
});
|
|
240
|
+
} catch (logErr) {
|
|
241
|
+
console.error('warning: failed to write learned.jsonl:', logErr.message);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const scope = isUserInstall ? 'user' : 'project';
|
|
245
|
+
if (opts.json) {
|
|
246
|
+
jsonOk({ ref, name: skillName, installedTo: installDir, scope, version: record.version || null });
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
console.log(`${mark} learned: ${ref} (${scope})`);
|
|
250
|
+
console.log(`installed to: ${installDir}`);
|
|
251
|
+
if (record.version) console.log(`version: ${record.version}`);
|
|
252
|
+
} catch (err) {
|
|
253
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
254
|
+
if (opts.json) {
|
|
255
|
+
jsonError(msg);
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
console.error(msg);
|
|
259
|
+
process.exitCode = 1;
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
}
|
package/src/cmd/link.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
import { existsSync, mkdirSync, symlinkSync, unlinkSync, readlinkSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { join, resolve } from 'node:path';
|
|
6
|
+
import { mark, name } from '../lib/brand.js';
|
|
7
|
+
|
|
8
|
+
export default function register(program) {
|
|
9
|
+
program
|
|
10
|
+
.command('link')
|
|
11
|
+
.description('Link vit binary into ~/.local/bin (or create .cmd shim on Windows)')
|
|
12
|
+
.action(async () => {
|
|
13
|
+
try {
|
|
14
|
+
const vitBin = resolve(import.meta.dirname, '..', '..', 'bin', 'vit.js');
|
|
15
|
+
if (!existsSync(vitBin)) {
|
|
16
|
+
console.error(`${name} link could not find ${vitBin}`);
|
|
17
|
+
process.exitCode = 1;
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let binDir;
|
|
22
|
+
if (process.platform === 'win32') {
|
|
23
|
+
const home = process.env.USERPROFILE || process.env.HOME;
|
|
24
|
+
binDir = join(home, '.local', 'bin');
|
|
25
|
+
mkdirSync(binDir, { recursive: true });
|
|
26
|
+
const target = join(binDir, 'vit.cmd');
|
|
27
|
+
writeFileSync(target, `@node "${vitBin}" %*\n`);
|
|
28
|
+
console.log(`${mark} link: ${target} -> ${vitBin}`);
|
|
29
|
+
} else {
|
|
30
|
+
binDir = join(process.env.HOME, '.local', 'bin');
|
|
31
|
+
mkdirSync(binDir, { recursive: true });
|
|
32
|
+
const target = join(binDir, 'vit');
|
|
33
|
+
if (existsSync(target)) {
|
|
34
|
+
try {
|
|
35
|
+
const current = readlinkSync(target);
|
|
36
|
+
if (current === vitBin) {
|
|
37
|
+
console.log(`${mark} link: already linked`);
|
|
38
|
+
} else {
|
|
39
|
+
unlinkSync(target);
|
|
40
|
+
symlinkSync(vitBin, target);
|
|
41
|
+
console.log(`${mark} link: ${target} -> ${vitBin}`);
|
|
42
|
+
}
|
|
43
|
+
} catch {
|
|
44
|
+
unlinkSync(target);
|
|
45
|
+
symlinkSync(vitBin, target);
|
|
46
|
+
console.log(`${mark} link: ${target} -> ${vitBin}`);
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
symlinkSync(vitBin, target);
|
|
50
|
+
console.log(`${mark} link: ${target} -> ${vitBin}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const pathDirs = (process.env.PATH || '').split(process.platform === 'win32' ? ';' : ':');
|
|
55
|
+
if (!pathDirs.includes(binDir)) {
|
|
56
|
+
const shell = (process.env.SHELL || '').split('/').pop();
|
|
57
|
+
let instruction = '[Environment]::SetEnvironmentVariable("PATH", "$env:USERPROFILE\\.local\\bin;" + $env:PATH, "User")';
|
|
58
|
+
if (shell === 'fish') {
|
|
59
|
+
instruction = 'set -Ua fish_user_paths ~/.local/bin';
|
|
60
|
+
} else if (shell === 'zsh') {
|
|
61
|
+
instruction = 'echo \'export PATH="$HOME/.local/bin:$PATH"\' >> ~/.zshrc';
|
|
62
|
+
} else if (shell === 'bash') {
|
|
63
|
+
instruction = 'echo \'export PATH="$HOME/.local/bin:$PATH"\' >> ~/.bashrc';
|
|
64
|
+
}
|
|
65
|
+
console.log(`${mark} note: add ~/.local/bin to your PATH:`);
|
|
66
|
+
console.log(instruction);
|
|
67
|
+
} else {
|
|
68
|
+
console.log(`${mark} PATH: ok`);
|
|
69
|
+
}
|
|
70
|
+
} catch (err) {
|
|
71
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
72
|
+
process.exitCode = 1;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
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,73 +36,103 @@ 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`, `tell your operator to run 'vit vet ${ref} --trust'`);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
console.error(`cap '${ref}' is not trusted. tell your operator 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.`);
|
|
132
|
+
console.error('');
|
|
133
|
+
console.error('hint: caps only appear from accounts you follow and your own.');
|
|
134
|
+
console.error(` vit following check who you're following`);
|
|
135
|
+
console.error(` vit explore cap ${ref} search the network-wide index`);
|
|
97
136
|
process.exitCode = 1;
|
|
98
137
|
return;
|
|
99
138
|
}
|
|
@@ -104,6 +143,11 @@ export default function register(program) {
|
|
|
104
143
|
const description = record.description || '';
|
|
105
144
|
const text = record.text || '';
|
|
106
145
|
|
|
146
|
+
if (opts.json) {
|
|
147
|
+
jsonOk({ ref, author, title, description, text });
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
107
151
|
console.log(`# ${brand} remix: ${title}`);
|
|
108
152
|
console.log('');
|
|
109
153
|
console.log(`ref: ${ref}`);
|
|
@@ -129,7 +173,12 @@ export default function register(program) {
|
|
|
129
173
|
console.log('');
|
|
130
174
|
console.log(text);
|
|
131
175
|
} catch (err) {
|
|
132
|
-
|
|
176
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
177
|
+
if (opts.json) {
|
|
178
|
+
jsonError(msg);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
console.error(msg);
|
|
133
182
|
process.exitCode = 1;
|
|
134
183
|
}
|
|
135
184
|
});
|