vit 0.0.1 → 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.
@@ -0,0 +1,10 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 sol pbc
3
+
4
+ import envPaths from 'env-paths';
5
+ import { join } from 'node:path';
6
+
7
+ const paths = envPaths('vit', { suffix: '' });
8
+
9
+ export const configDir = paths.config;
10
+ export const configPath = (filename) => join(paths.config, filename);
package/src/lib/pds.js ADDED
@@ -0,0 +1,79 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 sol pbc
3
+
4
+ const PLC_DIRECTORY = 'https://plc.directory';
5
+ const pdsCache = new Map();
6
+
7
+ async function fetchDidDocument(did) {
8
+ let url;
9
+ if (did.startsWith('did:web:')) {
10
+ const rest = did.slice('did:web:'.length);
11
+ const parts = rest.split(':');
12
+ const domain = decodeURIComponent(parts[0]);
13
+ if (parts.length === 1) {
14
+ url = `https://${domain}/.well-known/did.json`;
15
+ } else {
16
+ url = `https://${domain}/${parts.slice(1).map(decodeURIComponent).join('/')}/did.json`;
17
+ }
18
+ } else {
19
+ url = `${PLC_DIRECTORY}/${did}`;
20
+ }
21
+
22
+ const res = await fetch(url);
23
+ if (!res.ok) throw new Error(`failed to resolve DID document for ${did}: ${res.status} ${res.statusText}`);
24
+ return res.json();
25
+ }
26
+
27
+ export async function resolvePds(did) {
28
+ if (pdsCache.has(did)) return pdsCache.get(did);
29
+ const doc = await fetchDidDocument(did);
30
+ const pds = doc.service?.find(s => s.type === 'AtprotoPersonalDataServer');
31
+ if (!pds?.serviceEndpoint) throw new Error(`no PDS found in DID document for ${did}`);
32
+ pdsCache.set(did, pds.serviceEndpoint);
33
+ return pds.serviceEndpoint;
34
+ }
35
+
36
+ export async function listRecordsFromPds(pdsUrl, repo, collection, limit) {
37
+ const records = [];
38
+ let cursor;
39
+ do {
40
+ const url = new URL('/xrpc/com.atproto.repo.listRecords', pdsUrl);
41
+ url.searchParams.set('repo', repo);
42
+ url.searchParams.set('collection', collection);
43
+ if (limit) url.searchParams.set('limit', String(limit));
44
+ if (cursor) url.searchParams.set('cursor', cursor);
45
+ const res = await fetch(url);
46
+ if (!res.ok) throw new Error(`listRecords failed for ${repo}: ${res.status} ${res.statusText}`);
47
+ const data = await res.json();
48
+ records.push(...data.records);
49
+ cursor = data.cursor;
50
+ } while (cursor);
51
+ return { records };
52
+ }
53
+
54
+ export async function resolveHandleFromDid(did) {
55
+ try {
56
+ const doc = await fetchDidDocument(did);
57
+ const aka = doc.alsoKnownAs?.find(a => a.startsWith('at://'));
58
+ return aka ? aka.replace('at://', '') : did;
59
+ } catch {
60
+ return did;
61
+ }
62
+ }
63
+
64
+ export async function batchQuery(items, fn, { batchSize = 10, verbose = false } = {}) {
65
+ if (verbose) console.log(`[verbose] querying ${items.length} accounts in batches of ${batchSize}`);
66
+ const results = [];
67
+ for (let i = 0; i < items.length; i += batchSize) {
68
+ const chunk = items.slice(i, i + batchSize);
69
+ const settled = await Promise.allSettled(chunk.map(fn));
70
+ for (let j = 0; j < settled.length; j++) {
71
+ if (settled[j].status === 'fulfilled' && settled[j].value !== undefined) {
72
+ results.push(settled[j].value);
73
+ } else if (settled[j].status === 'rejected' && verbose) {
74
+ console.log(`[verbose] ${chunk[j]}: error: ${settled[j].reason?.message || settled[j].reason}`);
75
+ }
76
+ }
77
+ }
78
+ return results;
79
+ }
@@ -0,0 +1,37 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 sol pbc
3
+
4
+ const AGENTS = new Set(['claude', 'codex', 'gemini']);
5
+
6
+ export function sandboxArgs(agent, { prompt, systemPrompt, model } = {}) {
7
+ if (!AGENTS.has(agent)) {
8
+ throw new Error(`Unknown agent: ${agent}. Must be one of: ${[...AGENTS].join(', ')}`);
9
+ }
10
+ if (!prompt) {
11
+ throw new Error('prompt is required');
12
+ }
13
+
14
+ if (agent === 'claude') {
15
+ const args = ['-p', '--tools', '', '--output-format', 'json'];
16
+ if (systemPrompt) args.push('--system-prompt', systemPrompt);
17
+ args.push('--model', model || 'haiku');
18
+ args.push(prompt);
19
+ return { cmd: 'claude', args, env: { CLAUDECODE: '' } };
20
+ }
21
+
22
+ // codex and gemini lack a separate system prompt flag,
23
+ // so we prepend instructions to the prompt
24
+ const combined = systemPrompt ? `${systemPrompt}\n\n${prompt}` : prompt;
25
+
26
+ if (agent === 'codex') {
27
+ const args = ['exec', '-s', 'read-only'];
28
+ if (model) args.push('-m', model);
29
+ args.push(combined);
30
+ return { cmd: 'codex', args, env: {} };
31
+ }
32
+
33
+ // gemini
34
+ const args = ['-p', combined, '-s', '-e', 'none', '--output-format', 'json'];
35
+ if (model) args.push('-m', model);
36
+ return { cmd: 'gemini', args, env: {} };
37
+ }
@@ -0,0 +1,37 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 sol pbc
3
+
4
+ // Skill ref format: skill-{name}
5
+ // Name: lowercase letters, numbers, hyphens. No leading hyphen, no consecutive hyphens. Max 64 chars.
6
+
7
+ export const SKILL_NAME_PATTERN = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
8
+ export const SKILL_REF_PATTERN = /^skill-[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
9
+ export const SKILL_NAME_MAX = 64;
10
+
11
+ export function isValidSkillName(name) {
12
+ if (!name || typeof name !== 'string') return false;
13
+ if (name.length > SKILL_NAME_MAX) return false;
14
+ return SKILL_NAME_PATTERN.test(name);
15
+ }
16
+
17
+ export function isSkillRef(ref) {
18
+ if (!ref || typeof ref !== 'string') return false;
19
+ return ref.startsWith('skill-');
20
+ }
21
+
22
+ export function skillRefFromName(name) {
23
+ return `skill-${name}`;
24
+ }
25
+
26
+ export function nameFromSkillRef(ref) {
27
+ if (!isSkillRef(ref)) return null;
28
+ return ref.slice(6);
29
+ }
30
+
31
+ export function isValidSkillRef(ref) {
32
+ if (!ref || typeof ref !== 'string') return false;
33
+ // skill- prefix + valid name, total ref max 71 chars (6 + 64 + 1 for the hyphen in prefix)
34
+ if (!SKILL_REF_PATTERN.test(ref)) return false;
35
+ const name = nameFromSkillRef(ref);
36
+ return name.length <= SKILL_NAME_MAX;
37
+ }
@@ -0,0 +1,39 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 sol pbc
3
+
4
+ import { existsSync, readFileSync } from 'node:fs';
5
+ import { join } from 'node:path';
6
+ import { vitDir } from './vit-dir.js';
7
+
8
+ const ACCEPT_FILE = 'dangerous-accept';
9
+
10
+ /**
11
+ * Check if dangerous-accept flag is active.
12
+ * Returns { accepted: true } or { accepted: false }.
13
+ * No TTL — once set, it's permanent until deleted.
14
+ */
15
+ export function checkDangerousAccept() {
16
+ const p = join(vitDir(), ACCEPT_FILE);
17
+ if (!existsSync(p)) return { accepted: false };
18
+ try {
19
+ JSON.parse(readFileSync(p, 'utf-8'));
20
+ return { accepted: true };
21
+ } catch {
22
+ return { accepted: false };
23
+ }
24
+ }
25
+
26
+ /**
27
+ * Check if the vet gate should be bypassed.
28
+ * Returns { bypass: true, reason } or { bypass: false }.
29
+ *
30
+ * Bypass condition: dangerous-accept flag is active.
31
+ * Caller checks trusted.jsonl before calling this.
32
+ */
33
+ export function shouldBypassVet() {
34
+ const accept = checkDangerousAccept();
35
+ if (accept.accepted) {
36
+ return { bypass: true, reason: 'dangerous-accept' };
37
+ }
38
+ return { bypass: false };
39
+ }
@@ -0,0 +1,69 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026 sol pbc
3
+
4
+ import { existsSync, mkdirSync, readFileSync, writeFileSync, appendFileSync } from 'node:fs';
5
+ import { join } from 'node:path';
6
+
7
+ export function vitDir() {
8
+ return join(process.cwd(), '.vit');
9
+ }
10
+
11
+ export function readProjectConfig() {
12
+ const p = join(vitDir(), 'config.json');
13
+ if (!existsSync(p)) return {};
14
+ try {
15
+ return JSON.parse(readFileSync(p, 'utf-8'));
16
+ } catch {
17
+ return {};
18
+ }
19
+ }
20
+
21
+ export function readBeaconSet() {
22
+ const config = readProjectConfig();
23
+ const set = new Set();
24
+ if (config.beacon) set.add(config.beacon);
25
+ if (config.secondaryBeacon) set.add(config.secondaryBeacon);
26
+ return set;
27
+ }
28
+
29
+ export function writeProjectConfig(obj, baseDir) {
30
+ const dir = baseDir ? join(baseDir, '.vit') : vitDir();
31
+ mkdirSync(dir, { recursive: true });
32
+ writeFileSync(join(dir, 'config.json'), JSON.stringify(obj, null, 2) + '\n');
33
+ }
34
+
35
+ export function appendLog(filename, record) {
36
+ const dir = vitDir();
37
+ mkdirSync(dir, { recursive: true });
38
+ appendFileSync(join(dir, filename), JSON.stringify(record) + '\n');
39
+ }
40
+
41
+ export function readLog(filename) {
42
+ const p = join(vitDir(), filename);
43
+ if (!existsSync(p)) return [];
44
+ try {
45
+ return readFileSync(p, 'utf-8')
46
+ .split('\n')
47
+ .filter(line => line.trim())
48
+ .map(line => { try { return JSON.parse(line); } catch { return null; } })
49
+ .filter(Boolean);
50
+ } catch {
51
+ return [];
52
+ }
53
+ }
54
+
55
+ export function readFollowing() {
56
+ const p = join(vitDir(), 'following.json');
57
+ if (!existsSync(p)) return [];
58
+ try {
59
+ return JSON.parse(readFileSync(p, 'utf-8'));
60
+ } catch {
61
+ return [];
62
+ }
63
+ }
64
+
65
+ export function writeFollowing(list) {
66
+ const dir = vitDir();
67
+ mkdirSync(dir, { recursive: true });
68
+ writeFileSync(join(dir, 'following.json'), JSON.stringify(list, null, 2) + '\n');
69
+ }
package/.npmignore DELETED
@@ -1,37 +0,0 @@
1
- # Logs
2
- logs
3
- *.log
4
- npm-debug.log*
5
-
6
- # Runtime data
7
- pids
8
- *.pid
9
- *.seed
10
-
11
- # Directory for instrumented libs generated by jscoverage/JSCover
12
- lib-cov
13
-
14
- # Coverage directory used by tools like istanbul
15
- coverage
16
-
17
- # nyc test coverage
18
- .nyc_output
19
-
20
- # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21
- .grunt
22
-
23
- # node-waf configuration
24
- .lock-wscript
25
-
26
- # Compiled binary addons (http://nodejs.org/api/addons.html)
27
- build/Release
28
-
29
- # Dependency directories
30
- node_modules
31
- jspm_packages
32
-
33
- # Optional npm cache directory
34
- .npm
35
-
36
- # Optional REPL history
37
- .node_repl_history