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
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
import { requireDid } from '../lib/config.js';
|
|
5
|
+
import { restoreAgent } from '../lib/oauth.js';
|
|
6
|
+
import { readFollowing, writeFollowing } from '../lib/vit-dir.js';
|
|
7
|
+
import { mark } from '../lib/brand.js';
|
|
8
|
+
|
|
9
|
+
export default function register(program) {
|
|
10
|
+
program
|
|
11
|
+
.command('follow')
|
|
12
|
+
.argument('<handle>', 'Handle to follow (e.g. alice.bsky.social)')
|
|
13
|
+
.description('Add an account to this project\'s following list')
|
|
14
|
+
.option('-v, --verbose', 'Show step-by-step details')
|
|
15
|
+
.option('--did <did>', 'DID to use for handle resolution')
|
|
16
|
+
.action(async (handle, opts) => {
|
|
17
|
+
try {
|
|
18
|
+
const { verbose } = opts;
|
|
19
|
+
handle = handle.replace(/^@/, '');
|
|
20
|
+
|
|
21
|
+
const did = requireDid(opts);
|
|
22
|
+
if (!did) return;
|
|
23
|
+
if (verbose) console.log(`[verbose] DID: ${did}`);
|
|
24
|
+
|
|
25
|
+
const list = readFollowing();
|
|
26
|
+
if (list.some(e => e.handle === handle)) {
|
|
27
|
+
console.error(`already following ${handle}`);
|
|
28
|
+
process.exitCode = 1;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const { agent } = await restoreAgent(did);
|
|
33
|
+
if (verbose) console.log('[verbose] session restored');
|
|
34
|
+
|
|
35
|
+
const resolved = await agent.resolveHandle({ handle });
|
|
36
|
+
const targetDid = resolved.data.did;
|
|
37
|
+
if (verbose) console.log(`[verbose] resolved ${handle} to ${targetDid}`);
|
|
38
|
+
|
|
39
|
+
list.push({ handle, did: targetDid, followedAt: new Date().toISOString() });
|
|
40
|
+
writeFollowing(list);
|
|
41
|
+
console.log(`${mark} following ${handle} (${targetDid})`);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
44
|
+
process.exitCode = 1;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
program
|
|
49
|
+
.command('unfollow')
|
|
50
|
+
.argument('<handle>', 'Handle to unfollow (e.g. alice.bsky.social)')
|
|
51
|
+
.description('Remove an account from this project\'s following list')
|
|
52
|
+
.option('-v, --verbose', 'Show step-by-step details')
|
|
53
|
+
.action(async (handle, opts) => {
|
|
54
|
+
try {
|
|
55
|
+
const { verbose } = opts;
|
|
56
|
+
handle = handle.replace(/^@/, '');
|
|
57
|
+
|
|
58
|
+
const list = readFollowing();
|
|
59
|
+
const filtered = list.filter(e => e.handle !== handle);
|
|
60
|
+
if (filtered.length === list.length) {
|
|
61
|
+
console.error(`not following ${handle}`);
|
|
62
|
+
process.exitCode = 1;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
writeFollowing(filtered);
|
|
67
|
+
if (verbose) console.log(`[verbose] removed ${handle} from following list`);
|
|
68
|
+
console.log(`${mark} unfollowed ${handle}`);
|
|
69
|
+
} catch (err) {
|
|
70
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
71
|
+
process.exitCode = 1;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
program
|
|
76
|
+
.command('following')
|
|
77
|
+
.description('List accounts in this project\'s following list')
|
|
78
|
+
.option('-v, --verbose', 'Show step-by-step details')
|
|
79
|
+
.action(async (_opts) => {
|
|
80
|
+
try {
|
|
81
|
+
const list = readFollowing();
|
|
82
|
+
if (list.length === 0) {
|
|
83
|
+
console.log('no followings');
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
for (const e of list) {
|
|
87
|
+
console.log(`${e.handle} (${e.did})`);
|
|
88
|
+
}
|
|
89
|
+
} catch (err) {
|
|
90
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
91
|
+
process.exitCode = 1;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
package/src/cmd/init.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
import { existsSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { execSync } from 'node:child_process';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { toBeacon } from '../lib/beacon.js';
|
|
8
|
+
import { vitDir, readProjectConfig, writeProjectConfig } from '../lib/vit-dir.js';
|
|
9
|
+
import { requireAgent } from '../lib/agent.js';
|
|
10
|
+
import { mark, name, DOT_VIT_README } from '../lib/brand.js';
|
|
11
|
+
|
|
12
|
+
export default function register(program) {
|
|
13
|
+
program
|
|
14
|
+
.command('init')
|
|
15
|
+
.description('Initialize .vit directory and set project beacon. Use the most official upstream or well-known git URL so all contributors converge on the same beacon.')
|
|
16
|
+
.option('--beacon <url>', 'Git URL (or "." to read from git remote upstream/origin) to derive the beacon URI')
|
|
17
|
+
.option('-v, --verbose', 'Show step-by-step details')
|
|
18
|
+
.action(async (opts) => {
|
|
19
|
+
try {
|
|
20
|
+
const gate = requireAgent();
|
|
21
|
+
if (!gate.ok) {
|
|
22
|
+
console.error(`${name} init should be run by a coding agent (e.g. claude code, gemini cli).`);
|
|
23
|
+
console.error(`open your agent and ask it to run '${name} init' for you.`);
|
|
24
|
+
process.exitCode = 1;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const { verbose } = opts;
|
|
29
|
+
const dir = vitDir();
|
|
30
|
+
if (verbose) console.log(`[verbose] .vit dir: ${dir}`);
|
|
31
|
+
|
|
32
|
+
if (!opts.beacon) {
|
|
33
|
+
const config = readProjectConfig();
|
|
34
|
+
if (config.beacon) {
|
|
35
|
+
console.log(`${mark} beacon: ${config.beacon}`);
|
|
36
|
+
console.log(`hint: to change the beacon, run: ${name} init --beacon <git-url>`);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let isGitRepo = false;
|
|
41
|
+
try {
|
|
42
|
+
execSync('git rev-parse --is-inside-work-tree', {
|
|
43
|
+
encoding: 'utf-8',
|
|
44
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
45
|
+
});
|
|
46
|
+
isGitRepo = true;
|
|
47
|
+
} catch {}
|
|
48
|
+
if (verbose) console.log(`[verbose] in git repo: ${isGitRepo ? 'yes' : 'no'}`);
|
|
49
|
+
|
|
50
|
+
const hasVitDir = existsSync(dir);
|
|
51
|
+
if (!isGitRepo) {
|
|
52
|
+
console.log(hasVitDir ? 'status: no beacon' : 'status: not initialized');
|
|
53
|
+
console.log('git: false');
|
|
54
|
+
if (hasVitDir) {
|
|
55
|
+
console.log(`hint: run: ${name} init --beacon <canonical-git-url>`);
|
|
56
|
+
} else {
|
|
57
|
+
console.log(`hint: run ${name} init from inside a git repository.`);
|
|
58
|
+
}
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
console.log(hasVitDir ? 'status: no beacon' : 'status: not initialized');
|
|
63
|
+
console.log('git: true');
|
|
64
|
+
|
|
65
|
+
let remoteNames = [];
|
|
66
|
+
try {
|
|
67
|
+
remoteNames = execSync('git remote', {
|
|
68
|
+
encoding: 'utf-8',
|
|
69
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
70
|
+
})
|
|
71
|
+
.trim()
|
|
72
|
+
.split('\n')
|
|
73
|
+
.filter(Boolean);
|
|
74
|
+
} catch {
|
|
75
|
+
remoteNames = [];
|
|
76
|
+
}
|
|
77
|
+
if (verbose) console.log(`[verbose] remotes detected: ${remoteNames.length > 0 ? remoteNames.join(', ') : 'none'}`);
|
|
78
|
+
|
|
79
|
+
const remotes = [];
|
|
80
|
+
for (const name of remoteNames) {
|
|
81
|
+
try {
|
|
82
|
+
const url = execSync(`git config --get remote.${name}.url`, {
|
|
83
|
+
encoding: 'utf-8',
|
|
84
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
85
|
+
}).trim();
|
|
86
|
+
if (url) remotes.push({ name, url });
|
|
87
|
+
} catch {}
|
|
88
|
+
}
|
|
89
|
+
if (verbose && remotes.length > 0) {
|
|
90
|
+
console.log(`[verbose] remote urls: ${remotes.map(r => `${r.name}=${r.url}`).join(' ')}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const remotesDisplay = remotes.length > 0
|
|
94
|
+
? remotes.map(remote => `${remote.name}=${remote.url}`).join(' ')
|
|
95
|
+
: 'none';
|
|
96
|
+
console.log(`remotes: ${remotesDisplay}`);
|
|
97
|
+
|
|
98
|
+
const upstream = remotes.find(remote => remote.name === 'upstream');
|
|
99
|
+
const origin = remotes.find(remote => remote.name === 'origin');
|
|
100
|
+
if (upstream) {
|
|
101
|
+
console.log('hint: detected upstream remote. upstream points to the canonical repo.');
|
|
102
|
+
console.log(`hint: run: ${name} init --beacon ${upstream.url}`);
|
|
103
|
+
} else if (origin) {
|
|
104
|
+
console.log(`hint: run: ${name} init --beacon ${origin.url}`);
|
|
105
|
+
} else {
|
|
106
|
+
console.log(`hint: no git remotes found. run: ${name} init --beacon <canonical-git-url>`);
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let gitUrl = opts.beacon;
|
|
112
|
+
if (gitUrl === '.') {
|
|
113
|
+
if (verbose) console.log('[verbose] resolving --beacon . via remote.upstream.url then remote.origin.url');
|
|
114
|
+
let usedRemote = '';
|
|
115
|
+
try {
|
|
116
|
+
gitUrl = execSync('git config --get remote.upstream.url', {
|
|
117
|
+
encoding: 'utf-8',
|
|
118
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
119
|
+
}).trim();
|
|
120
|
+
if (gitUrl) usedRemote = 'upstream';
|
|
121
|
+
} catch {
|
|
122
|
+
gitUrl = '';
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (!gitUrl) {
|
|
126
|
+
try {
|
|
127
|
+
gitUrl = execSync('git config --get remote.origin.url', {
|
|
128
|
+
encoding: 'utf-8',
|
|
129
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
130
|
+
}).trim();
|
|
131
|
+
if (gitUrl) usedRemote = 'origin';
|
|
132
|
+
} catch {
|
|
133
|
+
gitUrl = '';
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (!gitUrl) {
|
|
138
|
+
console.error('No git remote found. Set a remote or provide a git URL directly.');
|
|
139
|
+
process.exitCode = 1;
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (verbose) console.log(`[verbose] Read git remote ${usedRemote}: ${gitUrl}`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const beacon = 'vit:' + toBeacon(gitUrl);
|
|
146
|
+
if (verbose) console.log(`[verbose] Computed beacon: ${beacon}`);
|
|
147
|
+
writeProjectConfig({ beacon });
|
|
148
|
+
if (verbose) console.log(`[verbose] Wrote config.json`);
|
|
149
|
+
const readmePath = join(vitDir(), 'README.md');
|
|
150
|
+
if (!existsSync(readmePath)) {
|
|
151
|
+
writeFileSync(readmePath, DOT_VIT_README);
|
|
152
|
+
if (verbose) console.log(`[verbose] Wrote .vit/README.md`);
|
|
153
|
+
}
|
|
154
|
+
console.log(`${mark} beacon: ${beacon}`);
|
|
155
|
+
} catch (err) {
|
|
156
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
157
|
+
process.exitCode = 1;
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
package/src/cmd/login.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
import { createServer } from 'node:http';
|
|
5
|
+
import { spawn } from 'node:child_process';
|
|
6
|
+
import { createInterface } from 'node:readline';
|
|
7
|
+
import { loadConfig, saveConfig } from '../lib/config.js';
|
|
8
|
+
import { createOAuthClient, createSessionStore, createStore, checkSession } from '../lib/oauth.js';
|
|
9
|
+
|
|
10
|
+
export default function register(program) {
|
|
11
|
+
program
|
|
12
|
+
.command('login')
|
|
13
|
+
.description('Log in to Bluesky via browser-based OAuth')
|
|
14
|
+
.argument('<handle>', 'Bluesky handle (e.g. alice.bsky.social)')
|
|
15
|
+
.option('-v, --verbose', 'Show discovery details')
|
|
16
|
+
.option('--force', 'Force re-login, skip session validation')
|
|
17
|
+
.option('--remote', 'Skip browser launch; prompt to paste callback URL (auto-detected over SSH)')
|
|
18
|
+
.option('--browser <command>', 'Browser command to use (e.g. firefox)')
|
|
19
|
+
.action(async (handle, opts) => {
|
|
20
|
+
const { verbose, force, remote, browser } = opts;
|
|
21
|
+
const isRemote = remote || !!(process.env.SSH_CONNECTION || process.env.SSH_TTY || process.env.SSH_CLIENT);
|
|
22
|
+
handle = handle.replace(/^@/, '');
|
|
23
|
+
|
|
24
|
+
if (!force) {
|
|
25
|
+
const existing = loadConfig();
|
|
26
|
+
if (existing.did) {
|
|
27
|
+
console.log('Checking session...');
|
|
28
|
+
const validDid = checkSession(existing.did);
|
|
29
|
+
if (validDid) {
|
|
30
|
+
console.log(`Already logged in as ${validDid}`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let server;
|
|
37
|
+
let timeout;
|
|
38
|
+
let rl;
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
let resolveCallback;
|
|
42
|
+
let callbackResolved = false;
|
|
43
|
+
const callbackPromise = new Promise((resolve) => {
|
|
44
|
+
resolveCallback = resolve;
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
server = createServer((req, res) => {
|
|
48
|
+
const url = new URL(req.url, `http://127.0.0.1`);
|
|
49
|
+
|
|
50
|
+
if (req.method === 'GET' && url.pathname === '/callback') {
|
|
51
|
+
const params = new URLSearchParams(url.searchParams);
|
|
52
|
+
|
|
53
|
+
if (!callbackResolved) {
|
|
54
|
+
callbackResolved = true;
|
|
55
|
+
resolveCallback(params);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
res.writeHead(200, { 'content-type': 'text/html; charset=utf-8' });
|
|
59
|
+
res.end('<!doctype html><html><body><h2>Authorization complete, you can close this tab.</h2></body></html>');
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
res.writeHead(404);
|
|
64
|
+
res.end('Not found');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
|
|
68
|
+
const port = server.address().port;
|
|
69
|
+
|
|
70
|
+
if (verbose) {
|
|
71
|
+
console.log(`[verbose] Server started on port ${port}`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const redirectUri = `http://127.0.0.1:${port}/callback`;
|
|
75
|
+
|
|
76
|
+
if (verbose) {
|
|
77
|
+
console.log(`[verbose] Redirect URI: ${redirectUri}`);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const stateStore = createStore();
|
|
81
|
+
const sessionStore = createSessionStore();
|
|
82
|
+
const client = createOAuthClient({ stateStore, sessionStore, redirectUri });
|
|
83
|
+
|
|
84
|
+
const authUrl = await client.authorize(handle, {
|
|
85
|
+
scope: 'atproto transition:generic',
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
if (verbose) {
|
|
89
|
+
console.log(`[verbose] Authorization URL: ${authUrl.toString()}`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (isRemote) {
|
|
93
|
+
console.log("You're on a remote system. Open this URL in your local browser:");
|
|
94
|
+
console.log(` ${authUrl.toString()}\n`);
|
|
95
|
+
} else {
|
|
96
|
+
const platform = process.platform;
|
|
97
|
+
const cmd = browser || (platform === 'darwin' ? 'open' : platform === 'win32' ? 'cmd' : 'xdg-open');
|
|
98
|
+
const browserArgs = !browser && platform === 'win32' ? ['/c', 'start', authUrl.toString()] : [authUrl.toString()];
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
const child = spawn(cmd, browserArgs, { stdio: 'ignore', detached: true });
|
|
102
|
+
child.unref();
|
|
103
|
+
} catch {
|
|
104
|
+
// Ignore browser-open failures and rely on printed URL.
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
console.log(`Open this URL in your browser:\n ${authUrl.toString()}\n`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (isRemote) {
|
|
111
|
+
rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
112
|
+
rl.question('Paste the callback URL from your browser: ', (line) => {
|
|
113
|
+
try {
|
|
114
|
+
const url = new URL(line.trim());
|
|
115
|
+
const params = new URLSearchParams(url.searchParams);
|
|
116
|
+
if (!callbackResolved) {
|
|
117
|
+
callbackResolved = true;
|
|
118
|
+
resolveCallback(params);
|
|
119
|
+
}
|
|
120
|
+
} catch {
|
|
121
|
+
console.error('Invalid URL. Please paste the full callback URL.');
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const timeoutMs = 5 * 60 * 1000;
|
|
127
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
128
|
+
timeout = setTimeout(() => {
|
|
129
|
+
reject(new Error('Timed out waiting for callback.'));
|
|
130
|
+
}, timeoutMs);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const params = await Promise.race([callbackPromise, timeoutPromise]);
|
|
134
|
+
|
|
135
|
+
clearTimeout(timeout);
|
|
136
|
+
timeout = undefined;
|
|
137
|
+
server.closeAllConnections?.();
|
|
138
|
+
server.close();
|
|
139
|
+
if (rl) {
|
|
140
|
+
rl.close();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (verbose) {
|
|
144
|
+
console.log(`[verbose] Callback received with params: ${params.toString()}`);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const oauthError = params.get('error');
|
|
148
|
+
if (oauthError) {
|
|
149
|
+
const description = params.get('error_description');
|
|
150
|
+
if (description) {
|
|
151
|
+
throw new Error(`OAuth error: ${oauthError} (${description})`);
|
|
152
|
+
}
|
|
153
|
+
throw new Error(`OAuth error: ${oauthError}`);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
console.log('Exchanging token...');
|
|
157
|
+
const { session } = await client.callback(params);
|
|
158
|
+
|
|
159
|
+
if (verbose) {
|
|
160
|
+
console.log(`[verbose] Token exchange result for DID: ${session.did}`);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const config = loadConfig();
|
|
164
|
+
config.did = session.did;
|
|
165
|
+
saveConfig(config);
|
|
166
|
+
console.log(`Logged in as ${session.did}`);
|
|
167
|
+
} catch (err) {
|
|
168
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
169
|
+
process.exitCode = 1;
|
|
170
|
+
} finally {
|
|
171
|
+
if (timeout) {
|
|
172
|
+
clearTimeout(timeout);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (rl) {
|
|
176
|
+
rl.close();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (server?.listening) {
|
|
180
|
+
server.closeAllConnections?.();
|
|
181
|
+
server.close();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
}
|
package/src/cmd/remix.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
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, readLog } from '../lib/vit-dir.js';
|
|
8
|
+
import { requireAgent } from '../lib/agent.js';
|
|
9
|
+
import { resolveRef, REF_PATTERN } from '../lib/cap-ref.js';
|
|
10
|
+
import { brand, name } from '../lib/brand.js';
|
|
11
|
+
|
|
12
|
+
export default function register(program) {
|
|
13
|
+
program
|
|
14
|
+
.command('remix')
|
|
15
|
+
.argument('<ref>', 'Three-word cap reference (e.g. fast-cache-invalidation)')
|
|
16
|
+
.description('Derive a vetted cap into the local codebase')
|
|
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 gate = requireAgent();
|
|
22
|
+
if (!gate.ok) {
|
|
23
|
+
console.error(`${name} remix should be run by a coding agent (e.g. claude code, gemini cli).`);
|
|
24
|
+
console.error(`open your agent and ask it to run '${name} remix' for you.`);
|
|
25
|
+
process.exitCode = 1;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const { verbose } = opts;
|
|
30
|
+
|
|
31
|
+
if (!REF_PATTERN.test(ref)) {
|
|
32
|
+
console.error('invalid ref. expected three lowercase words with dashes (e.g. fast-cache-invalidation)');
|
|
33
|
+
process.exitCode = 1;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const did = requireDid(opts);
|
|
38
|
+
if (!did) return;
|
|
39
|
+
if (verbose) console.log(`[verbose] DID: ${did}`);
|
|
40
|
+
|
|
41
|
+
const projectConfig = readProjectConfig();
|
|
42
|
+
const beacon = projectConfig.beacon;
|
|
43
|
+
if (!beacon) {
|
|
44
|
+
console.error(`no beacon set. run '${name} init' in a project directory first.`);
|
|
45
|
+
process.exitCode = 1;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (verbose) console.log(`[verbose] beacon: ${beacon}`);
|
|
49
|
+
|
|
50
|
+
const trusted = readLog('trusted.jsonl');
|
|
51
|
+
const trustedEntry = trusted.find(e => e.ref === ref);
|
|
52
|
+
if (!trustedEntry) {
|
|
53
|
+
console.error(`cap '${ref}' is not trusted. ask the user to vet it first:`);
|
|
54
|
+
console.error('');
|
|
55
|
+
console.error(` vit vet ${ref}`);
|
|
56
|
+
console.error('');
|
|
57
|
+
console.error('after reviewing, they can trust it with:');
|
|
58
|
+
console.error('');
|
|
59
|
+
console.error(` vit vet ${ref} --trust`);
|
|
60
|
+
process.exitCode = 1;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (verbose) console.log(`[verbose] trusted entry found, uri: ${trustedEntry.uri}`);
|
|
64
|
+
|
|
65
|
+
const { agent } = await restoreAgent(did);
|
|
66
|
+
if (verbose) console.log('[verbose] session restored');
|
|
67
|
+
|
|
68
|
+
const following = readFollowing();
|
|
69
|
+
const dids = following.map(e => e.did);
|
|
70
|
+
dids.push(did);
|
|
71
|
+
if (verbose) console.log(`[verbose] querying ${dids.length} accounts`);
|
|
72
|
+
|
|
73
|
+
let match = null;
|
|
74
|
+
for (const repoDid of dids) {
|
|
75
|
+
try {
|
|
76
|
+
const res = await agent.com.atproto.repo.listRecords({
|
|
77
|
+
repo: repoDid,
|
|
78
|
+
collection: CAP_COLLECTION,
|
|
79
|
+
limit: 50,
|
|
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
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
} catch (err) {
|
|
91
|
+
if (verbose) console.log(`[verbose] ${repoDid}: error fetching caps: ${err.message}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!match) {
|
|
96
|
+
console.error(`no cap found with ref '${ref}' for this beacon.`);
|
|
97
|
+
process.exitCode = 1;
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const record = match.value;
|
|
102
|
+
const author = match.uri.split('/')[2];
|
|
103
|
+
const title = record.title || ref;
|
|
104
|
+
const description = record.description || '';
|
|
105
|
+
const text = record.text || '';
|
|
106
|
+
|
|
107
|
+
console.log(`# ${brand} remix: ${title}`);
|
|
108
|
+
console.log('');
|
|
109
|
+
console.log(`ref: ${ref}`);
|
|
110
|
+
console.log(`author: ${author}`);
|
|
111
|
+
if (description) console.log(`description: ${description}`);
|
|
112
|
+
console.log('');
|
|
113
|
+
console.log('---');
|
|
114
|
+
console.log('');
|
|
115
|
+
console.log('you are remixing a vetted cap into the current codebase.');
|
|
116
|
+
console.log('create a thorough implementation plan that:');
|
|
117
|
+
console.log('');
|
|
118
|
+
console.log('1. adapts the cap to this repo\'s architecture, conventions, and existing code');
|
|
119
|
+
console.log('2. follows local guidelines (CLAUDE.md, project conventions, coding standards)');
|
|
120
|
+
console.log('3. identifies all files to create or modify');
|
|
121
|
+
console.log('4. specifies tests to add or update');
|
|
122
|
+
console.log('5. notes any dependencies or migrations needed');
|
|
123
|
+
console.log('');
|
|
124
|
+
console.log('do not apply the cap blindly. produce a well-researched plan first.');
|
|
125
|
+
console.log('');
|
|
126
|
+
console.log('---');
|
|
127
|
+
console.log('');
|
|
128
|
+
console.log('## cap content');
|
|
129
|
+
console.log('');
|
|
130
|
+
console.log(text);
|
|
131
|
+
} catch (err) {
|
|
132
|
+
console.error(err.message);
|
|
133
|
+
process.exitCode = 1;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
package/src/cmd/setup.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// SPDX-License-Identifier: AGPL-3.0-only
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import { loadConfig, saveConfig } from '../lib/config.js';
|
|
6
|
+
import { requireNotAgent } from '../lib/agent.js';
|
|
7
|
+
import { which } from '../lib/compat.js';
|
|
8
|
+
import { mark, brand, name } from '../lib/brand.js';
|
|
9
|
+
|
|
10
|
+
export default function register(program) {
|
|
11
|
+
program
|
|
12
|
+
.command('setup')
|
|
13
|
+
.description('Initialize user-level vit setup')
|
|
14
|
+
.action(async () => {
|
|
15
|
+
try {
|
|
16
|
+
const gate = requireNotAgent();
|
|
17
|
+
if (!gate.ok) {
|
|
18
|
+
console.error(`${name} setup must be run by a human. run it in your own terminal.`);
|
|
19
|
+
process.exitCode = 1;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const gitPath = which('git');
|
|
24
|
+
console.log(`${mark} git: ${gitPath ? 'found' : 'not found'}`);
|
|
25
|
+
if (!gitPath) {
|
|
26
|
+
console.error('missing required tool: git');
|
|
27
|
+
process.exitCode = 1;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// skill installation
|
|
32
|
+
const npxPath = which('npx');
|
|
33
|
+
if (npxPath) {
|
|
34
|
+
try {
|
|
35
|
+
const result = spawnSync(
|
|
36
|
+
'npx', ['skills', 'add', 'https://github.com/solpbc/vit/tree/main/skills/vit', '-a', 'claude-code', '-y'],
|
|
37
|
+
{
|
|
38
|
+
encoding: 'utf-8',
|
|
39
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
40
|
+
}
|
|
41
|
+
);
|
|
42
|
+
if (result.status === 0) {
|
|
43
|
+
console.log(`${mark} skill: installed (using-vit)`);
|
|
44
|
+
} else {
|
|
45
|
+
const errText = (result.stderr || '').trim();
|
|
46
|
+
console.log(`${mark} skill: failed (${errText || 'unknown error'})`);
|
|
47
|
+
}
|
|
48
|
+
} catch {
|
|
49
|
+
console.log(`${mark} skill: failed (could not run npx skills)`);
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
console.log(`${mark} skill: skipped (npx not found)`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const config = loadConfig();
|
|
56
|
+
if (config.did) {
|
|
57
|
+
console.log(`${mark} login: ${config.did}`);
|
|
58
|
+
} else {
|
|
59
|
+
console.log(`${mark} login: not logged in`);
|
|
60
|
+
console.log(`next: run '${name} login <handle>' to authenticate with Bluesky`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!config.setup_at) {
|
|
64
|
+
config.setup_at = Math.floor(Date.now() / 1000);
|
|
65
|
+
saveConfig(config);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (config.did) {
|
|
69
|
+
console.log(`${brand} setup complete`);
|
|
70
|
+
}
|
|
71
|
+
} catch (err) {
|
|
72
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
73
|
+
process.exitCode = 1;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|