vit 0.6.1 → 0.6.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/package.json +1 -1
- package/skills/vit/SKILL.md +5 -1
- package/src/cli.js +9 -0
- package/src/cmd/adopt.js +3 -3
- package/src/cmd/beacon.js +15 -9
- package/src/cmd/doctor.js +19 -8
- package/src/cmd/explore.js +11 -2
- package/src/cmd/init.js +35 -10
- package/src/cmd/remix.js +2 -1
- package/src/cmd/scan.js +6 -4
- package/src/cmd/ship.js +4 -9
- package/src/cmd/skim.js +2 -1
- package/src/cmd/vet.js +2 -1
- package/src/cmd/vouch.js +5 -2
- package/src/lib/beacon.js +23 -1
- package/src/lib/constants.js +1 -0
- package/src/lib/vit-dir.js +25 -2
package/package.json
CHANGED
package/skills/vit/SKILL.md
CHANGED
|
@@ -28,6 +28,10 @@ Dependency chain: `login → init → follow → skim/ship`.
|
|
|
28
28
|
|
|
29
29
|
Handoffs:
|
|
30
30
|
- If no DID is configured, tell the user to run `vit login <handle>`.
|
|
31
|
+
- If `vit login <handle>` says “Already logged in” but a session has been
|
|
32
|
+
revoked or later fails server authentication, tell the user to rerun
|
|
33
|
+
`vit login <handle> --force`. The ordinary login check only sees local
|
|
34
|
+
session material and can false-green a revoked token.
|
|
31
35
|
- If the user wants to review a cap, tell them to run `vit vet <ref>` in their terminal.
|
|
32
36
|
|
|
33
37
|
## 4. Commands the Agent Runs
|
|
@@ -166,7 +170,7 @@ When the user says "ship it", "vit ship", or asks you to publish a cap for work
|
|
|
166
170
|
## 5. Commands the Agent Must NOT Run
|
|
167
171
|
|
|
168
172
|
These commands require human interaction. Tell the user exactly what to run:
|
|
169
|
-
- `vit login <handle>` - Tell user: "Run `vit login <handle>` in your terminal to authenticate via browser OAuth."
|
|
173
|
+
- `vit login <handle>` - Tell user: "Run `vit login <handle>` in your terminal to authenticate via browser OAuth." If it falsely reports an existing login after revocation or a server-auth failure, add `--force` to restart authentication.
|
|
170
174
|
- `vit adopt <beacon>` - Tell user: "Run `vit adopt <beacon>` in your terminal to fork and clone a project."
|
|
171
175
|
- `vit vet <ref>` - Human review command. Tell the user to run it in their terminal.
|
|
172
176
|
**Exception: sandboxed sub-agent vetting.** If you are a dedicated sub-agent
|
package/src/cli.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { Command } from 'commander';
|
|
5
5
|
import { readFileSync } from 'node:fs';
|
|
6
6
|
import { brand } from './lib/brand.js';
|
|
7
|
+
import { USING_VIT_REMINDER } from './lib/constants.js';
|
|
7
8
|
import registerAdopt from './cmd/adopt.js';
|
|
8
9
|
import registerBeacon from './cmd/beacon.js';
|
|
9
10
|
import registerConfig from './cmd/config.js';
|
|
@@ -52,4 +53,12 @@ registerHack(program);
|
|
|
52
53
|
registerLink(program);
|
|
53
54
|
registerInbox(program);
|
|
54
55
|
|
|
56
|
+
program.addHelpText('after', USING_VIT_REMINDER);
|
|
57
|
+
program.configureOutput({
|
|
58
|
+
outputError(str, write) {
|
|
59
|
+
write(str);
|
|
60
|
+
write(`${USING_VIT_REMINDER}\n`);
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
55
64
|
export { program };
|
package/src/cmd/adopt.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { existsSync } from 'node:fs';
|
|
5
5
|
import { resolve } from 'node:path';
|
|
6
6
|
import { execFileSync } from 'node:child_process';
|
|
7
|
-
import { parseGitUrl,
|
|
7
|
+
import { parseGitUrl, normalizeBeacon, beaconToHttps } from '../lib/beacon.js';
|
|
8
8
|
import { requireNotAgent } from '../lib/agent.js';
|
|
9
9
|
import { which } from '../lib/compat.js';
|
|
10
10
|
import { mark, name } from '../lib/brand.js';
|
|
@@ -30,9 +30,9 @@ export default function register(program) {
|
|
|
30
30
|
|
|
31
31
|
// resolve beacon
|
|
32
32
|
if (verbose) console.log(`[verbose] resolving beacon: ${beacon}`);
|
|
33
|
-
const
|
|
33
|
+
const beaconUri = normalizeBeacon(beacon, 'vit adopt <beacon>');
|
|
34
|
+
const httpsUrl = beaconToHttps(beaconUri);
|
|
34
35
|
const parsed = parseGitUrl(httpsUrl);
|
|
35
|
-
const beaconUri = 'vit:' + toBeacon(httpsUrl);
|
|
36
36
|
if (verbose) console.log(`[verbose] beacon: ${beaconUri}`);
|
|
37
37
|
if (verbose) console.log(`[verbose] https: ${httpsUrl}`);
|
|
38
38
|
|
package/src/cmd/beacon.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
import git from 'isomorphic-git';
|
|
5
5
|
import http from 'isomorphic-git/http/node';
|
|
6
6
|
import { memfs } from 'memfs';
|
|
7
|
-
import { beaconToHttps } from '../lib/beacon.js';
|
|
7
|
+
import { beaconToHttps, normalizeBeacon, tryNormalizeBeacon } from '../lib/beacon.js';
|
|
8
8
|
import { mark } from '../lib/brand.js';
|
|
9
|
-
import {
|
|
9
|
+
import { formatError } from '../lib/error-format.js';
|
|
10
10
|
|
|
11
11
|
async function readTreeFile(fs, dir, treeOid, pathParts) {
|
|
12
12
|
for (let i = 0; i < pathParts.length; i++) {
|
|
@@ -31,7 +31,8 @@ export default function register(program) {
|
|
|
31
31
|
.action(async (target, opts) => {
|
|
32
32
|
try {
|
|
33
33
|
const { verbose } = opts;
|
|
34
|
-
const
|
|
34
|
+
const canonicalTarget = normalizeBeacon(target, 'vit beacon <target>');
|
|
35
|
+
const url = beaconToHttps(canonicalTarget);
|
|
35
36
|
if (verbose) console.log(`[verbose] Resolved URL: ${url}`);
|
|
36
37
|
const { fs } = memfs();
|
|
37
38
|
const dir = '/';
|
|
@@ -43,20 +44,25 @@ export default function register(program) {
|
|
|
43
44
|
if (verbose) console.log(`[verbose] HEAD resolved: ${head}`);
|
|
44
45
|
const commit = await git.readObject({ fs, dir, oid: head, format: 'parsed' });
|
|
45
46
|
const content = await readTreeFile(fs, dir, commit.object.tree, ['.vit', 'config.json']);
|
|
46
|
-
|
|
47
|
+
const configPresent = content !== null;
|
|
48
|
+
if (verbose) console.log(`[verbose] Read .vit/config.json: ${configPresent ? 'found' : 'not found'}`);
|
|
47
49
|
|
|
48
50
|
let beacon;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
if (configPresent) {
|
|
52
|
+
try {
|
|
53
|
+
beacon = tryNormalizeBeacon(JSON.parse(content).beacon);
|
|
54
|
+
} catch {
|
|
55
|
+
beacon = null;
|
|
56
|
+
}
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
if (beacon) {
|
|
56
60
|
console.log(`${mark} beacon: lit ${beacon}`);
|
|
57
|
-
} else {
|
|
61
|
+
} else if (!configPresent) {
|
|
58
62
|
console.log(`${mark} beacon: unlit — this repo hasn't initialized vit yet.`);
|
|
59
63
|
console.log("the maintainer can light the beacon by running 'vit init' inside the repo.");
|
|
64
|
+
} else {
|
|
65
|
+
console.log(`${mark} beacon: invalid — remote .vit/config.json does not contain a valid project identity`);
|
|
60
66
|
}
|
|
61
67
|
} catch (err) {
|
|
62
68
|
console.error(formatError(err, { verbose: opts.verbose }));
|
package/src/cmd/doctor.js
CHANGED
|
@@ -65,6 +65,7 @@ export default function register(program) {
|
|
|
65
65
|
let vitPath = which(name);
|
|
66
66
|
let installPath = vitPath || null;
|
|
67
67
|
let beacon = null;
|
|
68
|
+
let beaconError = null;
|
|
68
69
|
let skillInstalled = false;
|
|
69
70
|
let projectSkills = [];
|
|
70
71
|
let userSkills = [];
|
|
@@ -93,12 +94,19 @@ export default function register(program) {
|
|
|
93
94
|
}
|
|
94
95
|
}
|
|
95
96
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
97
|
+
try {
|
|
98
|
+
const projConfig = readProjectConfig();
|
|
99
|
+
beacon = projConfig.beacon || null;
|
|
100
|
+
if (projConfig.beacon) {
|
|
101
|
+
if (!opts.json) console.log(`${mark} beacon: ${projConfig.beacon}`);
|
|
102
|
+
} else {
|
|
103
|
+
if (!opts.json) console.log(`${mark} beacon: not set (run vit init)`);
|
|
104
|
+
}
|
|
105
|
+
} catch (err) {
|
|
106
|
+
beaconError = errorMessage(err);
|
|
107
|
+
if (!opts.json) {
|
|
108
|
+
console.log(`${mark} beacon: invalid project identity in .vit/config.json (run vit init --beacon <canonical-git-url>)`);
|
|
109
|
+
}
|
|
102
110
|
}
|
|
103
111
|
|
|
104
112
|
const skillResult = ensureSkill();
|
|
@@ -184,7 +192,7 @@ export default function register(program) {
|
|
|
184
192
|
}
|
|
185
193
|
|
|
186
194
|
if (opts.json) {
|
|
187
|
-
|
|
195
|
+
const result = {
|
|
188
196
|
install: { type: installType, path: installPath },
|
|
189
197
|
beacon,
|
|
190
198
|
skill: skillInstalled,
|
|
@@ -192,8 +200,11 @@ export default function register(program) {
|
|
|
192
200
|
projectSkills,
|
|
193
201
|
userSkills,
|
|
194
202
|
bluesky: { ok: blueskyOk, did: effectiveDid || null, pds, source: identitySource, authType },
|
|
195
|
-
}
|
|
203
|
+
};
|
|
204
|
+
if (beaconError) result.beaconError = beaconError;
|
|
205
|
+
jsonOk(result);
|
|
196
206
|
}
|
|
207
|
+
if (beaconError) process.exitCode = 1;
|
|
197
208
|
} catch (err) {
|
|
198
209
|
if (opts.json) {
|
|
199
210
|
jsonError(err);
|
package/src/cmd/explore.js
CHANGED
|
@@ -6,6 +6,7 @@ import { readProjectConfig } from '../lib/vit-dir.js';
|
|
|
6
6
|
import { brand } from '../lib/brand.js';
|
|
7
7
|
import { jsonOk, jsonError } from '../lib/json-output.js';
|
|
8
8
|
import { errorMessage, formatError } from '../lib/error-format.js';
|
|
9
|
+
import { normalizeBeacon } from '../lib/beacon.js';
|
|
9
10
|
|
|
10
11
|
function timeAgo(isoString) {
|
|
11
12
|
const seconds = Math.floor((Date.now() - new Date(isoString).getTime()) / 1000);
|
|
@@ -104,9 +105,12 @@ export default function register(program) {
|
|
|
104
105
|
const baseUrl = resolveUrl(opts);
|
|
105
106
|
|
|
106
107
|
try {
|
|
108
|
+
const beacon = opts.beacon
|
|
109
|
+
? normalizeBeacon(opts.beacon, '--beacon')
|
|
110
|
+
: null;
|
|
107
111
|
const url = new URL('/api/cap', baseUrl);
|
|
108
112
|
url.searchParams.set('ref', ref);
|
|
109
|
-
if (
|
|
113
|
+
if (beacon) url.searchParams.set('beacon', beacon);
|
|
110
114
|
|
|
111
115
|
const data = await fetchExploreJson(url);
|
|
112
116
|
|
|
@@ -236,6 +240,8 @@ export default function register(program) {
|
|
|
236
240
|
return;
|
|
237
241
|
}
|
|
238
242
|
beacon = beacons.join(',');
|
|
243
|
+
} else if (beacon) {
|
|
244
|
+
beacon = normalizeBeacon(beacon, '--beacon');
|
|
239
245
|
}
|
|
240
246
|
|
|
241
247
|
const url = new URL('/api/caps', baseUrl);
|
|
@@ -389,10 +395,13 @@ export default function register(program) {
|
|
|
389
395
|
return;
|
|
390
396
|
}
|
|
391
397
|
|
|
398
|
+
const beacon = opts.beacon
|
|
399
|
+
? normalizeBeacon(opts.beacon, '--beacon')
|
|
400
|
+
: null;
|
|
392
401
|
let capUri = opts.cap;
|
|
393
402
|
if (opts.ref) {
|
|
394
403
|
const capsUrl = new URL('/api/caps', baseUrl);
|
|
395
|
-
if (
|
|
404
|
+
if (beacon) capsUrl.searchParams.set('beacon', beacon);
|
|
396
405
|
|
|
397
406
|
const capsData = await fetchExploreJson(capsUrl);
|
|
398
407
|
const match = capsData.caps?.find((cap) => cap.ref === opts.ref);
|
package/src/cmd/init.js
CHANGED
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
import { existsSync, writeFileSync } from 'node:fs';
|
|
5
5
|
import { execSync } from 'node:child_process';
|
|
6
6
|
import { join } from 'node:path';
|
|
7
|
-
import {
|
|
8
|
-
import { vitDir, readProjectConfig, writeProjectConfig } from '../lib/vit-dir.js';
|
|
7
|
+
import { normalizeBeacon, tryNormalizeBeacon } from '../lib/beacon.js';
|
|
8
|
+
import { vitDir, readProjectConfig, readRawProjectConfig, 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
11
|
import { jsonOk, jsonError } from '../lib/json-output.js';
|
|
12
12
|
import { errorMessage, formatError } from '../lib/error-format.js';
|
|
13
13
|
|
|
14
|
+
const BEACON_REPAIR_HINT = 'run vit init --beacon <canonical-git-url> to repair it';
|
|
15
|
+
|
|
14
16
|
export default function register(program) {
|
|
15
17
|
program
|
|
16
18
|
.command('init')
|
|
@@ -39,7 +41,13 @@ export default function register(program) {
|
|
|
39
41
|
if (verbose) vlog(`[verbose] .vit dir: ${dir}`);
|
|
40
42
|
|
|
41
43
|
if (!opts.beacon && !opts.secondary) {
|
|
42
|
-
|
|
44
|
+
let config;
|
|
45
|
+
try {
|
|
46
|
+
config = readProjectConfig();
|
|
47
|
+
} catch (err) {
|
|
48
|
+
err.hint = BEACON_REPAIR_HINT;
|
|
49
|
+
throw err;
|
|
50
|
+
}
|
|
43
51
|
if (config.beacon) {
|
|
44
52
|
if (opts.json) {
|
|
45
53
|
const out = { beacon: config.beacon };
|
|
@@ -149,7 +157,7 @@ export default function register(program) {
|
|
|
149
157
|
}
|
|
150
158
|
|
|
151
159
|
if (opts.secondary && !opts.beacon) {
|
|
152
|
-
const config =
|
|
160
|
+
const config = readRawProjectConfig();
|
|
153
161
|
if (!config.beacon) {
|
|
154
162
|
if (opts.json) {
|
|
155
163
|
jsonError("no primary beacon set — run 'vit init --beacon <url>' first");
|
|
@@ -160,8 +168,15 @@ export default function register(program) {
|
|
|
160
168
|
return;
|
|
161
169
|
}
|
|
162
170
|
|
|
163
|
-
|
|
164
|
-
|
|
171
|
+
let primary;
|
|
172
|
+
try {
|
|
173
|
+
primary = normalizeBeacon(config.beacon, '.vit/config.json "beacon"');
|
|
174
|
+
} catch (err) {
|
|
175
|
+
err.hint = BEACON_REPAIR_HINT;
|
|
176
|
+
throw err;
|
|
177
|
+
}
|
|
178
|
+
const secondary = normalizeBeacon(opts.secondary, '--secondary');
|
|
179
|
+
const merged = { ...config, beacon: primary, secondaryBeacon: secondary };
|
|
165
180
|
writeProjectConfig(merged);
|
|
166
181
|
if (opts.json) {
|
|
167
182
|
jsonOk({ beacon: merged.beacon, secondaryBeacon: merged.secondaryBeacon });
|
|
@@ -210,12 +225,22 @@ export default function register(program) {
|
|
|
210
225
|
if (verbose) vlog(`[verbose] Read git remote ${usedRemote}: ${gitUrl}`);
|
|
211
226
|
}
|
|
212
227
|
|
|
213
|
-
const beacon = '
|
|
228
|
+
const beacon = normalizeBeacon(gitUrl, '--beacon');
|
|
214
229
|
if (verbose) vlog(`[verbose] Computed beacon: ${beacon}`);
|
|
215
|
-
const existing =
|
|
230
|
+
const existing = readRawProjectConfig();
|
|
216
231
|
const merged = { ...existing, beacon };
|
|
217
232
|
if (opts.secondary) {
|
|
218
|
-
merged.secondaryBeacon =
|
|
233
|
+
merged.secondaryBeacon = normalizeBeacon(opts.secondary, '--secondary');
|
|
234
|
+
} else if (Object.hasOwn(existing, 'secondaryBeacon')) {
|
|
235
|
+
// Tolerant normalization is deliberate on this repair path: an invalid secondary
|
|
236
|
+
// must be dropped with a warning, not block repair of the primary beacon.
|
|
237
|
+
const secondary = tryNormalizeBeacon(existing.secondaryBeacon);
|
|
238
|
+
if (secondary) {
|
|
239
|
+
merged.secondaryBeacon = secondary;
|
|
240
|
+
} else {
|
|
241
|
+
delete merged.secondaryBeacon;
|
|
242
|
+
console.warn('warning: dropping invalid .vit/config.json "secondaryBeacon" while repairing beacon');
|
|
243
|
+
}
|
|
219
244
|
}
|
|
220
245
|
writeProjectConfig(merged);
|
|
221
246
|
if (verbose) vlog(`[verbose] Wrote config.json`);
|
|
@@ -239,7 +264,7 @@ export default function register(program) {
|
|
|
239
264
|
jsonError(err);
|
|
240
265
|
return;
|
|
241
266
|
}
|
|
242
|
-
console.error(formatError(err, { verbose: opts.verbose }));
|
|
267
|
+
console.error(formatError(err, { hint: err?.hint, verbose: opts.verbose }));
|
|
243
268
|
process.exitCode = 1;
|
|
244
269
|
}
|
|
245
270
|
});
|
package/src/cmd/remix.js
CHANGED
|
@@ -13,6 +13,7 @@ import { resolvePds, listRecordsFromPds, batchQuery } from '../lib/pds.js';
|
|
|
13
13
|
import { loadConfig } from '../lib/config.js';
|
|
14
14
|
import { jsonOk, jsonError } from '../lib/json-output.js';
|
|
15
15
|
import { formatError } from '../lib/error-format.js';
|
|
16
|
+
import { tryNormalizeBeacon } from '../lib/beacon.js';
|
|
16
17
|
|
|
17
18
|
export default function register(program) {
|
|
18
19
|
program
|
|
@@ -114,7 +115,7 @@ export default function register(program) {
|
|
|
114
115
|
let match = null;
|
|
115
116
|
for (const records of allRecords) {
|
|
116
117
|
for (const rec of records) {
|
|
117
|
-
if (!beaconSet.has(rec.value.beacon)) continue;
|
|
118
|
+
if (!beaconSet.has(tryNormalizeBeacon(rec.value.beacon))) continue;
|
|
118
119
|
const recRef = resolveRef(rec.value, rec.cid);
|
|
119
120
|
if (recRef === ref) {
|
|
120
121
|
if (!match || (rec.value.createdAt || '') > (match.value.createdAt || '')) {
|
package/src/cmd/scan.js
CHANGED
|
@@ -8,6 +8,7 @@ import { brand } from '../lib/brand.js';
|
|
|
8
8
|
import { jsonOk, jsonError } from '../lib/json-output.js';
|
|
9
9
|
import { readBeaconSet } from '../lib/vit-dir.js';
|
|
10
10
|
import { formatError } from '../lib/error-format.js';
|
|
11
|
+
import { normalizeBeacon, tryNormalizeBeacon } from '../lib/beacon.js';
|
|
11
12
|
|
|
12
13
|
export default function register(program) {
|
|
13
14
|
program
|
|
@@ -53,7 +54,7 @@ export default function register(program) {
|
|
|
53
54
|
return;
|
|
54
55
|
}
|
|
55
56
|
} else {
|
|
56
|
-
beaconSet = new Set([opts.beacon]);
|
|
57
|
+
beaconSet = new Set([normalizeBeacon(opts.beacon, '--beacon')]);
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
|
|
@@ -111,7 +112,8 @@ export default function register(program) {
|
|
|
111
112
|
if (!isCapEvent && !isSkillEvent) return;
|
|
112
113
|
|
|
113
114
|
// Apply filters
|
|
114
|
-
|
|
115
|
+
const recordBeacon = isCapEvent ? tryNormalizeBeacon(record.beacon) : null;
|
|
116
|
+
if (isCapEvent && beaconSet && !beaconSet.has(recordBeacon)) return;
|
|
115
117
|
if (isSkillEvent && opts.tag) {
|
|
116
118
|
const tags = record.tags || [];
|
|
117
119
|
if (!tags.some(t => t.toLowerCase() === opts.tag.toLowerCase())) return;
|
|
@@ -125,7 +127,7 @@ export default function register(program) {
|
|
|
125
127
|
if (isCapEvent) {
|
|
126
128
|
const title = record.title || '';
|
|
127
129
|
const refPart = ref ? ` (${ref})` : '';
|
|
128
|
-
vlog(` ${didShort}: [cap] ${title}${refPart} [${
|
|
130
|
+
vlog(` ${didShort}: [cap] ${title}${refPart} [${recordBeacon || 'no beacon'}]`);
|
|
129
131
|
} else {
|
|
130
132
|
const skillName = record.name || '';
|
|
131
133
|
const tags = record.tags ? ` [${record.tags.join(', ')}]` : '';
|
|
@@ -139,7 +141,7 @@ export default function register(program) {
|
|
|
139
141
|
const entry = publishers.get(did);
|
|
140
142
|
if (isCapEvent) {
|
|
141
143
|
entry.capCount++;
|
|
142
|
-
if (
|
|
144
|
+
if (recordBeacon) entry.beacons.add(recordBeacon);
|
|
143
145
|
} else {
|
|
144
146
|
entry.skillCount++;
|
|
145
147
|
if (record.tags) {
|
package/src/cmd/ship.js
CHANGED
|
@@ -14,7 +14,7 @@ import { isValidSkillName, skillRefFromName } from '../lib/skill-ref.js';
|
|
|
14
14
|
import { name } from '../lib/brand.js';
|
|
15
15
|
import { resolvePds, listRecordsFromPds, batchQuery } from '../lib/pds.js';
|
|
16
16
|
import { jsonOk, jsonError } from '../lib/json-output.js';
|
|
17
|
-
import {
|
|
17
|
+
import { normalizeBeacon } from '../lib/beacon.js';
|
|
18
18
|
import { hashTo3Words } from '../lib/cap-ref.js';
|
|
19
19
|
import { formatError } from '../lib/error-format.js';
|
|
20
20
|
import { publishCap } from '../lib/cap.js';
|
|
@@ -49,11 +49,6 @@ function generateRef(title, existingRefs) {
|
|
|
49
49
|
return null;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
function normalizeBeacon(input) {
|
|
53
|
-
if (input.startsWith('vit:')) return input;
|
|
54
|
-
return 'vit:' + toBeacon(input);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
52
|
function parseFrontmatter(text) {
|
|
58
53
|
const match = text.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?/);
|
|
59
54
|
if (!match) return { frontmatter: {}, body: text };
|
|
@@ -381,13 +376,13 @@ export async function shipCap(opts) {
|
|
|
381
376
|
// Request caps: --beacon flag or project config (in that order)
|
|
382
377
|
if (opts.beacon) {
|
|
383
378
|
try {
|
|
384
|
-
beacon = normalizeBeacon(opts.beacon);
|
|
379
|
+
beacon = normalizeBeacon(opts.beacon, '--beacon');
|
|
385
380
|
} catch (err) {
|
|
386
381
|
if (opts.json) {
|
|
387
|
-
jsonError(
|
|
382
|
+
jsonError(err);
|
|
388
383
|
return;
|
|
389
384
|
}
|
|
390
|
-
console.error(
|
|
385
|
+
console.error(formatError(err, { verbose }));
|
|
391
386
|
process.exitCode = 1;
|
|
392
387
|
return;
|
|
393
388
|
}
|
package/src/cmd/skim.js
CHANGED
|
@@ -12,6 +12,7 @@ import { name } from '../lib/brand.js';
|
|
|
12
12
|
import { resolvePds, listRecordsFromPds, batchQuery } from '../lib/pds.js';
|
|
13
13
|
import { jsonError } from '../lib/json-output.js';
|
|
14
14
|
import { formatError } from '../lib/error-format.js';
|
|
15
|
+
import { tryNormalizeBeacon } from '../lib/beacon.js';
|
|
15
16
|
|
|
16
17
|
export default function register(program) {
|
|
17
18
|
program
|
|
@@ -95,7 +96,7 @@ export default function register(program) {
|
|
|
95
96
|
// Fetch caps (filtered by beacon)
|
|
96
97
|
if (wantCaps && beaconSet.size > 0) {
|
|
97
98
|
const res = await listRecordsFromPds(pds, repoDid, CAP_COLLECTION, 50);
|
|
98
|
-
let caps = res.records.filter(r => beaconSet.has(r.value.beacon));
|
|
99
|
+
let caps = res.records.filter(r => beaconSet.has(tryNormalizeBeacon(r.value.beacon)));
|
|
99
100
|
if (opts.kind) {
|
|
100
101
|
caps = caps.filter(r => r.value.kind === opts.kind);
|
|
101
102
|
}
|
package/src/cmd/vet.js
CHANGED
|
@@ -18,6 +18,7 @@ import { loadConfig } from '../lib/config.js';
|
|
|
18
18
|
import { jsonOk, jsonError } from '../lib/json-output.js';
|
|
19
19
|
import { sandboxArgs } from '../lib/sandbox.js';
|
|
20
20
|
import { formatError } from '../lib/error-format.js';
|
|
21
|
+
import { tryNormalizeBeacon } from '../lib/beacon.js';
|
|
21
22
|
|
|
22
23
|
const execFileAsync = promisify(execFile);
|
|
23
24
|
|
|
@@ -290,7 +291,7 @@ export default function register(program) {
|
|
|
290
291
|
let match = null;
|
|
291
292
|
for (const records of allRecords) {
|
|
292
293
|
for (const rec of records) {
|
|
293
|
-
if (!beaconSet.has(rec.value.beacon)) continue;
|
|
294
|
+
if (!beaconSet.has(tryNormalizeBeacon(rec.value.beacon))) continue;
|
|
294
295
|
const recRef = resolveRef(rec.value, rec.cid);
|
|
295
296
|
if (recRef === ref) {
|
|
296
297
|
if (!match || (rec.value.createdAt || '') > (match.value.createdAt || '')) {
|
package/src/cmd/vouch.js
CHANGED
|
@@ -13,6 +13,7 @@ import { resolvePds, listRecordsFromPds, batchQuery } from '../lib/pds.js';
|
|
|
13
13
|
import { loadConfig } from '../lib/config.js';
|
|
14
14
|
import { jsonOk, jsonError } from '../lib/json-output.js';
|
|
15
15
|
import { formatError } from '../lib/error-format.js';
|
|
16
|
+
import { tryNormalizeBeacon } from '../lib/beacon.js';
|
|
16
17
|
|
|
17
18
|
export default function register(program) {
|
|
18
19
|
program
|
|
@@ -229,7 +230,7 @@ export default function register(program) {
|
|
|
229
230
|
let match = null;
|
|
230
231
|
for (const records of allRecords) {
|
|
231
232
|
for (const rec of records) {
|
|
232
|
-
if (!isWant && !beaconSet.has(rec.value.beacon)) continue;
|
|
233
|
+
if (!isWant && !beaconSet.has(tryNormalizeBeacon(rec.value.beacon))) continue;
|
|
233
234
|
const recRef = resolveRef(rec.value, rec.cid);
|
|
234
235
|
if (recRef === ref) {
|
|
235
236
|
if (!match || (rec.value.createdAt || '') > (match.value.createdAt || '')) {
|
|
@@ -254,7 +255,9 @@ export default function register(program) {
|
|
|
254
255
|
}
|
|
255
256
|
|
|
256
257
|
const now = new Date().toISOString();
|
|
257
|
-
const projBeacon = beaconSet.size > 0
|
|
258
|
+
const projBeacon = beaconSet.size > 0
|
|
259
|
+
? [...beaconSet][0]
|
|
260
|
+
: tryNormalizeBeacon(match.value.beacon);
|
|
258
261
|
const vouchRecord = {
|
|
259
262
|
$type: VOUCH_COLLECTION,
|
|
260
263
|
subject: {
|
package/src/lib/beacon.js
CHANGED
|
@@ -81,11 +81,33 @@ export function parseGitUrl(input) {
|
|
|
81
81
|
return { host, org, repo };
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
function toBeacon(input) {
|
|
85
85
|
const { host, org, repo } = parseGitUrl(input);
|
|
86
86
|
return org ? `${host}/${org}/${repo}` : `${host}//${repo}`;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
export const BEACON_ACCEPTED_FORMS = 'vit:host/owner/repo or a git URL (a scheme URL such as https://host/owner/repo, ssh://git@host/owner/repo, or git://host/owner/repo; SCP-style git@host:owner/repo; or host/owner/repo)';
|
|
90
|
+
|
|
91
|
+
export function normalizeBeacon(input, source) {
|
|
92
|
+
try {
|
|
93
|
+
const trimmed = typeof input === 'string' ? input.trim() : input;
|
|
94
|
+
const gitUrl = typeof trimmed === 'string' && trimmed.startsWith('vit:')
|
|
95
|
+
? trimmed.slice(4)
|
|
96
|
+
: trimmed;
|
|
97
|
+
return `vit:${toBeacon(gitUrl)}`;
|
|
98
|
+
} catch {
|
|
99
|
+
throw new Error(`Invalid beacon from ${source}: expected ${BEACON_ACCEPTED_FORMS}.`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function tryNormalizeBeacon(input) {
|
|
104
|
+
try {
|
|
105
|
+
return normalizeBeacon(input, 'untrusted value');
|
|
106
|
+
} catch {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
89
111
|
export function beaconToHttps(input) {
|
|
90
112
|
if (typeof input === 'string' && input.startsWith('vit:')) {
|
|
91
113
|
const path = input.slice(4);
|
package/src/lib/constants.js
CHANGED
|
@@ -6,3 +6,4 @@ export const VOUCH_COLLECTION = 'org.v-it.vouch';
|
|
|
6
6
|
export const SKILL_COLLECTION = 'org.v-it.skill';
|
|
7
7
|
export const DEFAULT_JETSTREAM_URL = 'wss://jetstream2.us-east.bsky.network/subscribe';
|
|
8
8
|
export const DEFAULT_EXPLORE_URL = 'https://explore.v-it.org';
|
|
9
|
+
export const USING_VIT_REMINDER = 'Load the using-vit skill before using this CLI.';
|
package/src/lib/vit-dir.js
CHANGED
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
|
|
4
4
|
import { existsSync, mkdirSync, readFileSync, writeFileSync, appendFileSync } from 'node:fs';
|
|
5
5
|
import { join } from 'node:path';
|
|
6
|
+
import { normalizeBeacon } from './beacon.js';
|
|
6
7
|
import { errorMessage } from './error-format.js';
|
|
7
8
|
|
|
8
9
|
export function vitDir(dir) {
|
|
9
10
|
return join(dir || process.cwd(), '.vit');
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
// Exported only so vit init can replace corrupt beacon fields while preserving
|
|
14
|
+
// unrelated config. Other command paths must use readProjectConfig.
|
|
15
|
+
export function readRawProjectConfig(dir) {
|
|
13
16
|
const p = join(vitDir(dir), 'config.json');
|
|
14
17
|
if (!existsSync(p)) return {};
|
|
15
18
|
try {
|
|
@@ -20,6 +23,25 @@ export function readProjectConfig(dir) {
|
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
25
|
|
|
26
|
+
function normalizeProjectConfig(config) {
|
|
27
|
+
const normalized = { ...config };
|
|
28
|
+
if (Object.hasOwn(normalized, 'beacon')) {
|
|
29
|
+
normalized.beacon = normalizeBeacon(normalized.beacon, '.vit/config.json "beacon"');
|
|
30
|
+
}
|
|
31
|
+
if (Object.hasOwn(normalized, 'secondaryBeacon')) {
|
|
32
|
+
normalized.secondaryBeacon = normalizeBeacon(
|
|
33
|
+
normalized.secondaryBeacon,
|
|
34
|
+
'.vit/config.json "secondaryBeacon"',
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
return normalized;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function readProjectConfig(dir) {
|
|
41
|
+
const config = readRawProjectConfig(dir);
|
|
42
|
+
return normalizeProjectConfig(config);
|
|
43
|
+
}
|
|
44
|
+
|
|
23
45
|
export function readBeaconSet(dir) {
|
|
24
46
|
const config = readProjectConfig(dir);
|
|
25
47
|
const set = new Set();
|
|
@@ -30,8 +52,9 @@ export function readBeaconSet(dir) {
|
|
|
30
52
|
|
|
31
53
|
export function writeProjectConfig(obj, baseDir) {
|
|
32
54
|
const dir = baseDir ? join(baseDir, '.vit') : vitDir();
|
|
55
|
+
const normalized = normalizeProjectConfig(obj);
|
|
33
56
|
mkdirSync(dir, { recursive: true });
|
|
34
|
-
writeFileSync(join(dir, 'config.json'), JSON.stringify(
|
|
57
|
+
writeFileSync(join(dir, 'config.json'), JSON.stringify(normalized, null, 2) + '\n');
|
|
35
58
|
}
|
|
36
59
|
|
|
37
60
|
export function appendLog(filename, record, dir) {
|