vit 0.1.0 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -661
- package/README.md +56 -78
- package/bin/vit.js +1 -1
- package/package.json +6 -2
- package/src/cli.js +11 -1
- package/src/cmd/adopt.js +1 -1
- package/src/cmd/beacon.js +1 -1
- package/src/cmd/config.js +1 -1
- package/src/cmd/doctor.js +150 -16
- package/src/cmd/explore.js +477 -0
- package/src/cmd/firehose.js +20 -9
- package/src/cmd/follow.js +59 -10
- package/src/cmd/hack.js +83 -0
- package/src/cmd/init.js +95 -13
- package/src/cmd/learn.js +244 -0
- package/src/cmd/link.js +75 -0
- package/src/cmd/login.js +95 -13
- package/src/cmd/remix.js +82 -37
- package/src/cmd/scan.js +207 -0
- package/src/cmd/setup.js +1 -1
- package/src/cmd/ship.js +564 -149
- package/src/cmd/skim.js +106 -36
- package/src/cmd/vet.js +565 -97
- package/src/cmd/vouch.js +231 -88
- package/src/lib/agent.js +11 -1
- package/src/lib/beacon.js +1 -1
- package/src/lib/brand.js +1 -1
- package/src/lib/cap-ref.js +1 -1
- package/src/lib/compat.js +1 -1
- package/src/lib/config.js +11 -2
- package/src/lib/constants.js +4 -1
- package/src/lib/json-output.js +13 -0
- package/src/lib/oauth.js +49 -6
- package/src/lib/paths.js +1 -1
- package/src/lib/pds.js +79 -0
- package/src/lib/sandbox.js +1 -1
- package/src/lib/skill-ref.js +37 -0
- package/src/lib/trust-gate.js +39 -0
- package/src/lib/vit-dir.js +9 -1
package/src/cmd/hack.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
import { execFileSync } from 'node:child_process';
|
|
5
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
6
|
+
import { join, resolve } from 'node:path';
|
|
7
|
+
import { which } from '../lib/compat.js';
|
|
8
|
+
import { mark, name } from '../lib/brand.js';
|
|
9
|
+
|
|
10
|
+
export default function register(program) {
|
|
11
|
+
program
|
|
12
|
+
.command('hack')
|
|
13
|
+
.description('Fork and install vit from source')
|
|
14
|
+
.option('--from <repo>', 'Clone an existing fork instead of creating a new one (e.g. user/vit)')
|
|
15
|
+
.action(async (opts) => {
|
|
16
|
+
try {
|
|
17
|
+
const ghPath = which('gh');
|
|
18
|
+
if (!opts.from && !ghPath) {
|
|
19
|
+
console.error(`${name} hack requires gh (GitHub CLI). Install it from https://cli.github.com`);
|
|
20
|
+
process.exitCode = 1;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const gitPath = which('git');
|
|
25
|
+
if (opts.from && !gitPath) {
|
|
26
|
+
console.error('missing required tool: git');
|
|
27
|
+
process.exitCode = 1;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const repo = opts.from || 'solpbc/vit';
|
|
32
|
+
const dirName = repo.split('/').pop();
|
|
33
|
+
const dirPath = resolve(process.cwd(), dirName);
|
|
34
|
+
const cloned = !existsSync(dirPath);
|
|
35
|
+
|
|
36
|
+
if (!cloned) {
|
|
37
|
+
console.log(`${mark} ${dirName}/ already exists, skipping clone`);
|
|
38
|
+
} else if (opts.from) {
|
|
39
|
+
execFileSync('git', ['clone', 'https://github.com/' + opts.from + '.git', dirName], { stdio: 'inherit' });
|
|
40
|
+
} else {
|
|
41
|
+
execFileSync('gh', ['repo', 'fork', 'solpbc/vit', '--clone'], { stdio: 'inherit' });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
process.chdir(dirName);
|
|
45
|
+
|
|
46
|
+
const bunPath = which('bun');
|
|
47
|
+
if (!bunPath) {
|
|
48
|
+
console.error('missing required tool: bun');
|
|
49
|
+
process.exitCode = 1;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
execFileSync('bun', ['install'], { stdio: 'inherit' });
|
|
54
|
+
execFileSync('node', [join(process.cwd(), 'bin', 'vit.js'), 'link'], { stdio: 'inherit' });
|
|
55
|
+
|
|
56
|
+
if (!opts.from) {
|
|
57
|
+
const remote = execFileSync(
|
|
58
|
+
'gh',
|
|
59
|
+
['repo', 'view', '--json', 'nameWithOwner', '-q', '.nameWithOwner'],
|
|
60
|
+
{ encoding: 'utf-8' }
|
|
61
|
+
).trim();
|
|
62
|
+
const hackPath = join(process.cwd(), 'hack');
|
|
63
|
+
if (existsSync(hackPath)) {
|
|
64
|
+
const current = readFileSync(hackPath, 'utf-8');
|
|
65
|
+
writeFileSync(hackPath, current.replace('SELF="solpbc/vit"', `SELF="${remote}"`));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (opts.from && cloned) {
|
|
70
|
+
try {
|
|
71
|
+
execFileSync('git', ['remote', 'add', 'upstream', 'https://github.com/solpbc/vit.git'], { stdio: 'inherit' });
|
|
72
|
+
} catch {}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
console.log('');
|
|
76
|
+
console.log(`${mark} ${name} installed from source`);
|
|
77
|
+
console.log(`run: cd ${dirName}`);
|
|
78
|
+
} catch (err) {
|
|
79
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
80
|
+
process.exitCode = 1;
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
package/src/cmd/init.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
2
|
// Copyright (c) 2026 sol pbc
|
|
3
3
|
|
|
4
4
|
import { existsSync, writeFileSync } from 'node:fs';
|
|
@@ -8,17 +8,24 @@ import { toBeacon } from '../lib/beacon.js';
|
|
|
8
8
|
import { vitDir, readProjectConfig, writeProjectConfig } from '../lib/vit-dir.js';
|
|
9
9
|
import { requireAgent } from '../lib/agent.js';
|
|
10
10
|
import { mark, name, DOT_VIT_README } from '../lib/brand.js';
|
|
11
|
+
import { jsonOk, jsonError } from '../lib/json-output.js';
|
|
11
12
|
|
|
12
13
|
export default function register(program) {
|
|
13
14
|
program
|
|
14
15
|
.command('init')
|
|
15
16
|
.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
17
|
.option('--beacon <url>', 'Git URL (or "." to read from git remote upstream/origin) to derive the beacon URI')
|
|
18
|
+
.option('--secondary <url>', 'Secondary beacon URL for upstream cap discovery')
|
|
19
|
+
.option('--json', 'Output as JSON')
|
|
17
20
|
.option('-v, --verbose', 'Show step-by-step details')
|
|
18
21
|
.action(async (opts) => {
|
|
19
22
|
try {
|
|
20
23
|
const gate = requireAgent();
|
|
21
24
|
if (!gate.ok) {
|
|
25
|
+
if (opts.json) {
|
|
26
|
+
jsonError('agent required', 'run vit init from a coding agent');
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
22
29
|
console.error(`${name} init should be run by a coding agent (e.g. claude code, gemini cli).`);
|
|
23
30
|
console.error(`open your agent and ask it to run '${name} init' for you.`);
|
|
24
31
|
process.exitCode = 1;
|
|
@@ -26,13 +33,23 @@ export default function register(program) {
|
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
const { verbose } = opts;
|
|
36
|
+
const vlog = opts.json ? (...a) => console.error(...a) : console.log;
|
|
29
37
|
const dir = vitDir();
|
|
30
|
-
if (verbose)
|
|
38
|
+
if (verbose) vlog(`[verbose] .vit dir: ${dir}`);
|
|
31
39
|
|
|
32
|
-
if (!opts.beacon) {
|
|
40
|
+
if (!opts.beacon && !opts.secondary) {
|
|
33
41
|
const config = readProjectConfig();
|
|
34
42
|
if (config.beacon) {
|
|
43
|
+
if (opts.json) {
|
|
44
|
+
const out = { beacon: config.beacon };
|
|
45
|
+
if (config.secondaryBeacon) out.secondaryBeacon = config.secondaryBeacon;
|
|
46
|
+
jsonOk(out);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
35
49
|
console.log(`${mark} beacon: ${config.beacon}`);
|
|
50
|
+
if (config.secondaryBeacon) {
|
|
51
|
+
console.log(`${mark} secondary beacon: ${config.secondaryBeacon}`);
|
|
52
|
+
}
|
|
36
53
|
console.log(`hint: to change the beacon, run: ${name} init --beacon <git-url>`);
|
|
37
54
|
return;
|
|
38
55
|
}
|
|
@@ -45,10 +62,19 @@ export default function register(program) {
|
|
|
45
62
|
});
|
|
46
63
|
isGitRepo = true;
|
|
47
64
|
} catch {}
|
|
48
|
-
if (verbose)
|
|
65
|
+
if (verbose) vlog(`[verbose] in git repo: ${isGitRepo ? 'yes' : 'no'}`);
|
|
49
66
|
|
|
50
67
|
const hasVitDir = existsSync(dir);
|
|
51
68
|
if (!isGitRepo) {
|
|
69
|
+
let remotes = [];
|
|
70
|
+
if (opts.json) {
|
|
71
|
+
jsonOk({
|
|
72
|
+
status: hasVitDir ? 'no beacon' : 'not initialized',
|
|
73
|
+
git: false,
|
|
74
|
+
remotes,
|
|
75
|
+
});
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
52
78
|
console.log(hasVitDir ? 'status: no beacon' : 'status: not initialized');
|
|
53
79
|
console.log('git: false');
|
|
54
80
|
if (hasVitDir) {
|
|
@@ -74,7 +100,7 @@ export default function register(program) {
|
|
|
74
100
|
} catch {
|
|
75
101
|
remoteNames = [];
|
|
76
102
|
}
|
|
77
|
-
if (verbose)
|
|
103
|
+
if (verbose) vlog(`[verbose] remotes detected: ${remoteNames.length > 0 ? remoteNames.join(', ') : 'none'}`);
|
|
78
104
|
|
|
79
105
|
const remotes = [];
|
|
80
106
|
for (const name of remoteNames) {
|
|
@@ -87,7 +113,16 @@ export default function register(program) {
|
|
|
87
113
|
} catch {}
|
|
88
114
|
}
|
|
89
115
|
if (verbose && remotes.length > 0) {
|
|
90
|
-
|
|
116
|
+
vlog(`[verbose] remote urls: ${remotes.map(r => `${r.name}=${r.url}`).join(' ')}`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (opts.json) {
|
|
120
|
+
jsonOk({
|
|
121
|
+
status: hasVitDir ? 'no beacon' : 'not initialized',
|
|
122
|
+
git: true,
|
|
123
|
+
remotes: remotes.map(r => ({ name: r.name, url: r.url })),
|
|
124
|
+
});
|
|
125
|
+
return;
|
|
91
126
|
}
|
|
92
127
|
|
|
93
128
|
const remotesDisplay = remotes.length > 0
|
|
@@ -108,9 +143,33 @@ export default function register(program) {
|
|
|
108
143
|
return;
|
|
109
144
|
}
|
|
110
145
|
|
|
146
|
+
if (opts.secondary && !opts.beacon) {
|
|
147
|
+
const config = readProjectConfig();
|
|
148
|
+
if (!config.beacon) {
|
|
149
|
+
if (opts.json) {
|
|
150
|
+
jsonError("no primary beacon set — run 'vit init --beacon <url>' first");
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
console.error("no primary beacon set — run 'vit init --beacon <url>' first");
|
|
154
|
+
process.exitCode = 1;
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const secondary = 'vit:' + toBeacon(opts.secondary);
|
|
159
|
+
const merged = { ...config, secondaryBeacon: secondary };
|
|
160
|
+
writeProjectConfig(merged);
|
|
161
|
+
if (opts.json) {
|
|
162
|
+
jsonOk({ beacon: merged.beacon, secondaryBeacon: merged.secondaryBeacon });
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
console.log(`${mark} beacon: ${merged.beacon}`);
|
|
166
|
+
console.log(`${mark} secondary beacon: ${merged.secondaryBeacon}`);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
111
170
|
let gitUrl = opts.beacon;
|
|
112
171
|
if (gitUrl === '.') {
|
|
113
|
-
if (verbose)
|
|
172
|
+
if (verbose) vlog('[verbose] resolving --beacon . via remote.upstream.url then remote.origin.url');
|
|
114
173
|
let usedRemote = '';
|
|
115
174
|
try {
|
|
116
175
|
gitUrl = execSync('git config --get remote.upstream.url', {
|
|
@@ -135,25 +194,48 @@ export default function register(program) {
|
|
|
135
194
|
}
|
|
136
195
|
|
|
137
196
|
if (!gitUrl) {
|
|
197
|
+
if (opts.json) {
|
|
198
|
+
jsonError('no git remote found', 'set a remote or provide a git URL directly');
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
138
201
|
console.error('No git remote found. Set a remote or provide a git URL directly.');
|
|
139
202
|
process.exitCode = 1;
|
|
140
203
|
return;
|
|
141
204
|
}
|
|
142
|
-
if (verbose)
|
|
205
|
+
if (verbose) vlog(`[verbose] Read git remote ${usedRemote}: ${gitUrl}`);
|
|
143
206
|
}
|
|
144
207
|
|
|
145
208
|
const beacon = 'vit:' + toBeacon(gitUrl);
|
|
146
|
-
if (verbose)
|
|
147
|
-
|
|
148
|
-
|
|
209
|
+
if (verbose) vlog(`[verbose] Computed beacon: ${beacon}`);
|
|
210
|
+
const existing = readProjectConfig();
|
|
211
|
+
const merged = { ...existing, beacon };
|
|
212
|
+
if (opts.secondary) {
|
|
213
|
+
merged.secondaryBeacon = 'vit:' + toBeacon(opts.secondary);
|
|
214
|
+
}
|
|
215
|
+
writeProjectConfig(merged);
|
|
216
|
+
if (verbose) vlog(`[verbose] Wrote config.json`);
|
|
149
217
|
const readmePath = join(vitDir(), 'README.md');
|
|
150
218
|
if (!existsSync(readmePath)) {
|
|
151
219
|
writeFileSync(readmePath, DOT_VIT_README);
|
|
152
|
-
if (verbose)
|
|
220
|
+
if (verbose) vlog(`[verbose] Wrote .vit/README.md`);
|
|
221
|
+
}
|
|
222
|
+
if (opts.json) {
|
|
223
|
+
const out = { beacon: merged.beacon };
|
|
224
|
+
if (merged.secondaryBeacon) out.secondaryBeacon = merged.secondaryBeacon;
|
|
225
|
+
jsonOk(out);
|
|
226
|
+
return;
|
|
153
227
|
}
|
|
154
228
|
console.log(`${mark} beacon: ${beacon}`);
|
|
229
|
+
if (merged.secondaryBeacon) {
|
|
230
|
+
console.log(`${mark} secondary beacon: ${merged.secondaryBeacon}`);
|
|
231
|
+
}
|
|
155
232
|
} catch (err) {
|
|
156
|
-
|
|
233
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
234
|
+
if (opts.json) {
|
|
235
|
+
jsonError(msg);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
console.error(msg);
|
|
157
239
|
process.exitCode = 1;
|
|
158
240
|
}
|
|
159
241
|
});
|
package/src/cmd/learn.js
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Copyright (c) 2026 sol pbc
|
|
3
|
+
|
|
4
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { join, dirname } from 'node:path';
|
|
6
|
+
import { homedir } from 'node:os';
|
|
7
|
+
import { requireDid } from '../lib/config.js';
|
|
8
|
+
import { SKILL_COLLECTION } from '../lib/constants.js';
|
|
9
|
+
import { restoreAgent } from '../lib/oauth.js';
|
|
10
|
+
import { readFollowing, readLog, appendLog } from '../lib/vit-dir.js';
|
|
11
|
+
import { requireAgent, detectCodingAgent } from '../lib/agent.js';
|
|
12
|
+
import { shouldBypassVet } from '../lib/trust-gate.js';
|
|
13
|
+
import { isSkillRef, nameFromSkillRef, isValidSkillRef } from '../lib/skill-ref.js';
|
|
14
|
+
import { mark, name } from '../lib/brand.js';
|
|
15
|
+
import { resolvePds, listRecordsFromPds, batchQuery } from '../lib/pds.js';
|
|
16
|
+
import { loadConfig } from '../lib/config.js';
|
|
17
|
+
import { jsonOk, jsonError } from '../lib/json-output.js';
|
|
18
|
+
|
|
19
|
+
export default function register(program) {
|
|
20
|
+
program
|
|
21
|
+
.command('learn')
|
|
22
|
+
.argument('<ref>', 'Skill reference (e.g. skill-agent-test-patterns)')
|
|
23
|
+
.description('Install a skill from the network into your skill directory')
|
|
24
|
+
.option('--did <did>', 'DID to use')
|
|
25
|
+
.option('--user', 'Install to user-wide ~/.claude/skills/ (requires vet)')
|
|
26
|
+
.option('--json', 'Output as JSON')
|
|
27
|
+
.option('-v, --verbose', 'Show step-by-step details')
|
|
28
|
+
.action(async (ref, opts) => {
|
|
29
|
+
try {
|
|
30
|
+
const gate = requireAgent();
|
|
31
|
+
if (!gate.ok) {
|
|
32
|
+
if (opts.json) {
|
|
33
|
+
jsonError('agent required', 'run vit learn from a coding agent');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
console.error(`${name} learn should be run by a coding agent (e.g. claude code, gemini cli).`);
|
|
37
|
+
console.error(`open your agent and ask it to run '${name} learn' for you.`);
|
|
38
|
+
process.exitCode = 1;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const { verbose } = opts;
|
|
43
|
+
const vlog = opts.json ? (...a) => console.error(...a) : console.log;
|
|
44
|
+
|
|
45
|
+
if (!isSkillRef(ref)) {
|
|
46
|
+
if (opts.json) {
|
|
47
|
+
jsonError('invalid skill ref', 'expected format: skill-{name}');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
console.error(`invalid skill ref. expected format: skill-{name} (e.g. skill-agent-test-patterns)`);
|
|
51
|
+
process.exitCode = 1;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!isValidSkillRef(ref)) {
|
|
56
|
+
if (opts.json) {
|
|
57
|
+
jsonError('invalid skill ref', 'lowercase letters, numbers, hyphens only');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
console.error('invalid skill ref. name must be lowercase letters, numbers, hyphens only.');
|
|
61
|
+
console.error('no leading hyphen, no consecutive hyphens, max 64 chars.');
|
|
62
|
+
process.exitCode = 1;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const skillName = nameFromSkillRef(ref);
|
|
67
|
+
if (verbose) vlog(`[verbose] skill name: ${skillName}`);
|
|
68
|
+
|
|
69
|
+
// Trust gate
|
|
70
|
+
const isUserInstall = !!opts.user;
|
|
71
|
+
const trusted = readLog('trusted.jsonl');
|
|
72
|
+
const trustedEntry = trusted.find(e => e.ref === ref);
|
|
73
|
+
|
|
74
|
+
if (isUserInstall && !trustedEntry) {
|
|
75
|
+
// --user ALWAYS requires vet
|
|
76
|
+
if (opts.json) {
|
|
77
|
+
jsonError(`skill '${ref}' is not yet vetted`, 'user-wide install requires vetting');
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
console.error(`skill '${ref}' is not yet vetted. user-wide install requires vetting.`);
|
|
81
|
+
console.error(`ask the user to vet it first:`);
|
|
82
|
+
console.error('');
|
|
83
|
+
console.error(` vit vet ${ref}`);
|
|
84
|
+
console.error('');
|
|
85
|
+
console.error('after reviewing, they can trust it with:');
|
|
86
|
+
console.error('');
|
|
87
|
+
console.error(` vit vet ${ref} --trust`);
|
|
88
|
+
process.exitCode = 1;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (!isUserInstall && !trustedEntry) {
|
|
93
|
+
// Project-level: requires vet UNLESS dangerous-accept
|
|
94
|
+
const trustGate = shouldBypassVet();
|
|
95
|
+
if (!trustGate.bypass) {
|
|
96
|
+
if (opts.json) {
|
|
97
|
+
jsonError(`skill '${ref}' is not yet vetted`, `run 'vit vet ${ref}' first`);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
console.error(`skill '${ref}' is not yet vetted.`);
|
|
101
|
+
console.error(`ask the user to vet it first:`);
|
|
102
|
+
console.error('');
|
|
103
|
+
console.error(` vit vet ${ref}`);
|
|
104
|
+
console.error('');
|
|
105
|
+
console.error('after reviewing, they can trust it with:');
|
|
106
|
+
console.error('');
|
|
107
|
+
console.error(` vit vet ${ref} --trust`);
|
|
108
|
+
if (detectCodingAgent()) {
|
|
109
|
+
console.error('');
|
|
110
|
+
console.error('or, to trust all items without review:');
|
|
111
|
+
console.error('');
|
|
112
|
+
console.error(' vit vet --dangerous-accept --confirm');
|
|
113
|
+
}
|
|
114
|
+
process.exitCode = 1;
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (verbose) vlog(`[verbose] vet gate bypassed: ${trustGate.reason}`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (opts.json && !(opts.did || loadConfig().did)) {
|
|
121
|
+
jsonError('no DID configured', "run 'vit login <handle>' first");
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const did = requireDid(opts);
|
|
125
|
+
if (!did) return;
|
|
126
|
+
if (verbose) vlog(`[verbose] DID: ${did}`);
|
|
127
|
+
|
|
128
|
+
const { agent } = await restoreAgent(did);
|
|
129
|
+
if (verbose) vlog('[verbose] session restored');
|
|
130
|
+
|
|
131
|
+
// Build DID list from following + self
|
|
132
|
+
const following = readFollowing();
|
|
133
|
+
const dids = following.map(e => e.did);
|
|
134
|
+
dids.push(did);
|
|
135
|
+
|
|
136
|
+
// Fetch skills from each DID, find matching ref
|
|
137
|
+
const allRecords = await batchQuery(dids, async (repoDid) => {
|
|
138
|
+
const pds = await resolvePds(repoDid);
|
|
139
|
+
if (verbose) vlog(`[verbose] ${repoDid}: resolved PDS ${pds}`);
|
|
140
|
+
return (await listRecordsFromPds(pds, repoDid, SKILL_COLLECTION, 50)).records;
|
|
141
|
+
}, { verbose });
|
|
142
|
+
|
|
143
|
+
let match = null;
|
|
144
|
+
for (const records of allRecords) {
|
|
145
|
+
for (const rec of records) {
|
|
146
|
+
const recName = rec.value.name;
|
|
147
|
+
if (recName === skillName) {
|
|
148
|
+
if (!match || (rec.value.createdAt || '') > (match.value.createdAt || '')) {
|
|
149
|
+
match = rec;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (!match) {
|
|
156
|
+
if (opts.json) {
|
|
157
|
+
jsonError(`no skill found with ref '${ref}'`);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
console.error(`no skill found with ref '${ref}' from followed accounts.`);
|
|
161
|
+
process.exitCode = 1;
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const record = match.value;
|
|
166
|
+
if (verbose) vlog(`[verbose] found skill: ${record.name} from ${match.uri}`);
|
|
167
|
+
|
|
168
|
+
// Determine install path
|
|
169
|
+
let installDir;
|
|
170
|
+
if (isUserInstall) {
|
|
171
|
+
installDir = join(homedir(), '.claude', 'skills', skillName);
|
|
172
|
+
} else {
|
|
173
|
+
installDir = join(process.cwd(), '.claude', 'skills', skillName);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
mkdirSync(installDir, { recursive: true });
|
|
177
|
+
|
|
178
|
+
// Write SKILL.md from text field — verbatim, no reconstruction
|
|
179
|
+
writeFileSync(join(installDir, 'SKILL.md'), record.text);
|
|
180
|
+
if (verbose) vlog(`[verbose] wrote SKILL.md to ${installDir}`);
|
|
181
|
+
|
|
182
|
+
// Download and write resource blobs
|
|
183
|
+
if (record.resources && record.resources.length > 0) {
|
|
184
|
+
const authorDid = match.uri.split('/')[2];
|
|
185
|
+
const pds = await resolvePds(authorDid);
|
|
186
|
+
|
|
187
|
+
for (const resource of record.resources) {
|
|
188
|
+
const resourcePath = join(installDir, resource.path);
|
|
189
|
+
mkdirSync(dirname(resourcePath), { recursive: true });
|
|
190
|
+
|
|
191
|
+
try {
|
|
192
|
+
// Download blob from PDS
|
|
193
|
+
const blobCid = resource.blob?.ref?.$link || resource.blob?.cid;
|
|
194
|
+
if (blobCid) {
|
|
195
|
+
const blobUrl = new URL('/xrpc/com.atproto.sync.getBlob', pds);
|
|
196
|
+
blobUrl.searchParams.set('did', authorDid);
|
|
197
|
+
blobUrl.searchParams.set('cid', blobCid);
|
|
198
|
+
const blobRes = await fetch(blobUrl);
|
|
199
|
+
if (!blobRes.ok) throw new Error(`blob fetch failed: ${blobRes.status}`);
|
|
200
|
+
const blobData = Buffer.from(await blobRes.arrayBuffer());
|
|
201
|
+
writeFileSync(resourcePath, blobData);
|
|
202
|
+
if (verbose) vlog(`[verbose] wrote resource: ${resource.path}`);
|
|
203
|
+
}
|
|
204
|
+
} catch (err) {
|
|
205
|
+
console.error(`warning: failed to download resource ${resource.path}: ${err.message}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Log to learned.jsonl
|
|
211
|
+
try {
|
|
212
|
+
appendLog('learned.jsonl', {
|
|
213
|
+
ref,
|
|
214
|
+
name: skillName,
|
|
215
|
+
uri: match.uri,
|
|
216
|
+
cid: match.cid,
|
|
217
|
+
installedTo: installDir,
|
|
218
|
+
scope: isUserInstall ? 'user' : 'project',
|
|
219
|
+
learnedAt: new Date().toISOString(),
|
|
220
|
+
version: record.version || null,
|
|
221
|
+
});
|
|
222
|
+
} catch (logErr) {
|
|
223
|
+
console.error('warning: failed to write learned.jsonl:', logErr.message);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const scope = isUserInstall ? 'user' : 'project';
|
|
227
|
+
if (opts.json) {
|
|
228
|
+
jsonOk({ ref, name: skillName, installedTo: installDir, scope, version: record.version || null });
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
console.log(`${mark} learned: ${ref} (${scope})`);
|
|
232
|
+
console.log(`installed to: ${installDir}`);
|
|
233
|
+
if (record.version) console.log(`version: ${record.version}`);
|
|
234
|
+
} catch (err) {
|
|
235
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
236
|
+
if (opts.json) {
|
|
237
|
+
jsonError(msg);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
console.error(msg);
|
|
241
|
+
process.exitCode = 1;
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}
|
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
|
+
}
|