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.
@@ -0,0 +1,97 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright (c) 2026 sol pbc
3
+
4
+ export function parseGitUrl(input) {
5
+ if (typeof input !== 'string' || input.trim() === '') {
6
+ throw new Error('Invalid git URL: ' + String(input));
7
+ }
8
+
9
+ const raw = input.trim();
10
+ const normalizedError = () => new Error('Invalid git URL: ' + raw);
11
+
12
+ let host = '';
13
+ let path = '';
14
+
15
+ if (raw.includes('@') && !raw.includes('://')) {
16
+ const atIndex = raw.lastIndexOf('@');
17
+ const hostAndPath = raw.slice(atIndex + 1);
18
+ const colonIndex = hostAndPath.indexOf(':');
19
+ if (colonIndex === -1) {
20
+ throw normalizedError();
21
+ }
22
+ host = hostAndPath.slice(0, colonIndex);
23
+ path = hostAndPath.slice(colonIndex + 1);
24
+ if (!host || !path) {
25
+ throw normalizedError();
26
+ }
27
+ } else if (raw.includes('://')) {
28
+ let url;
29
+ try {
30
+ url = new URL(raw);
31
+ } catch {
32
+ throw normalizedError();
33
+ }
34
+ host = url.hostname;
35
+ path = url.pathname;
36
+ if (!host) {
37
+ throw normalizedError();
38
+ }
39
+ } else {
40
+ const slashIndex = raw.indexOf('/');
41
+ if (slashIndex !== -1) {
42
+ const maybeHost = raw.slice(0, slashIndex);
43
+ if (maybeHost.includes('.')) {
44
+ host = maybeHost;
45
+ path = raw.slice(slashIndex + 1);
46
+ if (!host) {
47
+ throw normalizedError();
48
+ }
49
+ } else {
50
+ throw normalizedError();
51
+ }
52
+ } else {
53
+ throw normalizedError();
54
+ }
55
+ }
56
+
57
+ const cleanedPath = path.replace(/^\/+|\/+$/g, '').replace(/\.git$/, '');
58
+ const segments = cleanedPath.split('/').filter(Boolean);
59
+
60
+ if (segments.length === 0 || segments.length >= 3) {
61
+ throw normalizedError();
62
+ }
63
+
64
+ let org = '';
65
+ let repo = '';
66
+ if (segments.length === 1) {
67
+ repo = segments[0];
68
+ } else {
69
+ org = segments[0];
70
+ repo = segments[1];
71
+ }
72
+
73
+ host = host.toLowerCase();
74
+ org = org.toLowerCase();
75
+ repo = repo.toLowerCase();
76
+
77
+ if (!repo) {
78
+ throw normalizedError();
79
+ }
80
+
81
+ return { host, org, repo };
82
+ }
83
+
84
+ export function toBeacon(input) {
85
+ const { host, org, repo } = parseGitUrl(input);
86
+ return org ? `${host}/${org}/${repo}` : `${host}//${repo}`;
87
+ }
88
+
89
+ export function beaconToHttps(input) {
90
+ if (typeof input === 'string' && input.startsWith('vit:')) {
91
+ const path = input.slice(4);
92
+ if (!path) throw new Error('Invalid beacon URI: ' + input);
93
+ return 'https://' + path.replace(/\/\//, '/');
94
+ }
95
+ const { host, org, repo } = parseGitUrl(input);
96
+ return org ? `https://${host}/${org}/${repo}` : `https://${host}/${repo}`;
97
+ }
@@ -0,0 +1,20 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright (c) 2026 sol pbc
3
+
4
+ const VIT_MARK = 'v\u0307'; // v̇
5
+ const VIT_BRAND = `${VIT_MARK}it`; // v̇it
6
+
7
+ const canCombine = process.stdout.isTTY && !process.env.TERM?.startsWith('dumb');
8
+ const brand = canCombine ? VIT_BRAND : 'vit';
9
+ const mark = canCombine ? VIT_MARK : 'v';
10
+ const prefix = canCombine ? `[${VIT_MARK}]` : '[v]';
11
+ const name = 'vit';
12
+
13
+ const DOT_VIT_README = `# .${VIT_BRAND}
14
+
15
+ this project participates in the social open source network. capabilities flow through people and agents you trust — not through gatekeepers or centralized platforms. the future of open source is social.
16
+
17
+ learn more at [v-it.org](https://v-it.org)
18
+ `;
19
+
20
+ export { VIT_MARK, VIT_BRAND, brand, mark, prefix, name, DOT_VIT_README };
@@ -0,0 +1,23 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright (c) 2026 sol pbc
3
+
4
+ import { sha256 } from '@noble/hashes/sha256';
5
+ import { wordlist } from '@scure/bip39/wordlists/english.js';
6
+
7
+ export const REF_PATTERN = /^[a-z]+-[a-z]+-[a-z]+$/;
8
+
9
+ export function hashTo3Words(input) {
10
+ const hash = sha256(new TextEncoder().encode(input));
11
+ // Take first 33 bits -> 3 x 11-bit indices into BIP39 wordlist (2048 words)
12
+ const i0 = (hash[0] << 3) | (hash[1] >> 5);
13
+ const i1 = ((hash[1] & 0x1f) << 6) | (hash[2] >> 2);
14
+ const i2 = ((hash[2] & 0x03) << 9) | (hash[3] << 1) | (hash[4] >> 7);
15
+ return `${wordlist[i0]}-${wordlist[i1]}-${wordlist[i2]}`;
16
+ }
17
+
18
+ export function resolveRef(record, cid) {
19
+ if (record?.ref && REF_PATTERN.test(record.ref)) {
20
+ return record.ref;
21
+ }
22
+ return hashTo3Words(cid);
23
+ }
@@ -0,0 +1,20 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright (c) 2026 sol pbc
3
+
4
+ import { execFileSync } from 'node:child_process';
5
+
6
+ /**
7
+ * Find the full path of an executable (cross-runtime replacement for Bun.which).
8
+ * Returns the path string or null if not found.
9
+ */
10
+ export function which(cmd) {
11
+ try {
12
+ const bin = process.platform === 'win32' ? 'where' : 'which';
13
+ return execFileSync(bin, [cmd], {
14
+ encoding: 'utf-8',
15
+ stdio: ['pipe', 'pipe', 'pipe'],
16
+ }).trim().split('\n')[0];
17
+ } catch {
18
+ return null;
19
+ }
20
+ }
@@ -0,0 +1,39 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright (c) 2026 sol pbc
3
+
4
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
5
+ import { configDir, configPath } from './paths.js';
6
+
7
+ const vitJsonPath = configPath('vit.json');
8
+
9
+ export function loadConfig() {
10
+ if (!existsSync(vitJsonPath)) return {};
11
+ try {
12
+ return JSON.parse(readFileSync(vitJsonPath, 'utf-8'));
13
+ } catch {
14
+ return {};
15
+ }
16
+ }
17
+
18
+ export function saveConfig(obj) {
19
+ const now = Math.floor(Date.now() / 1000);
20
+ if (!obj.created_at) obj.created_at = now;
21
+ obj.updated_at = now;
22
+ mkdirSync(configDir, { recursive: true });
23
+ writeFileSync(vitJsonPath, JSON.stringify(obj, null, 2) + '\n');
24
+ }
25
+
26
+ export function requireDid(opts) {
27
+ const did = opts?.did || loadConfig().did;
28
+ if (!did) {
29
+ console.error("no DID configured. run 'vit login <handle>' first or pass --did.");
30
+ process.exitCode = 1;
31
+ }
32
+ return did;
33
+ }
34
+
35
+ export function getScalars(obj) {
36
+ return Object.entries(obj).filter(
37
+ ([, v]) => typeof v !== 'object' || v === null
38
+ );
39
+ }
@@ -0,0 +1,5 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright (c) 2026 sol pbc
3
+
4
+ export const CAP_COLLECTION = 'org.v-it.cap';
5
+ export const VOUCH_COLLECTION = 'org.v-it.vouch';
@@ -0,0 +1,106 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright (c) 2026 sol pbc
3
+
4
+ import { Agent } from '@atproto/api';
5
+ import { NodeOAuthClient } from '@atproto/oauth-client-node';
6
+ import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
7
+ import { configDir, configPath } from './paths.js';
8
+
9
+ const requestLock = async (_name, fn) => await fn();
10
+
11
+ const noopStore = {
12
+ set: async () => {},
13
+ get: async () => undefined,
14
+ del: async () => {},
15
+ };
16
+
17
+ const clientMetadata = {
18
+ client_id: 'https://v-it.org/client-metadata.json',
19
+ client_name: 'vit CLI',
20
+ application_type: 'native',
21
+ grant_types: ['authorization_code', 'refresh_token'],
22
+ response_types: ['code'],
23
+ scope: 'atproto transition:generic',
24
+ token_endpoint_auth_method: 'none',
25
+ dpop_bound_access_tokens: true,
26
+ client_uri: 'https://v-it.org',
27
+ };
28
+
29
+ export function createStore() {
30
+ const map = new Map();
31
+
32
+ return {
33
+ set: async (key, value) => {
34
+ map.set(key, value);
35
+ },
36
+ get: async (key) => map.get(key),
37
+ del: async (key) => {
38
+ map.delete(key);
39
+ },
40
+ };
41
+ }
42
+
43
+ export function createSessionStore() {
44
+ const sessionFile = configPath('session.json');
45
+ let data = {};
46
+ try {
47
+ data = JSON.parse(readFileSync(sessionFile, 'utf-8'));
48
+ } catch {}
49
+ return {
50
+ set: async (key, value) => {
51
+ data[key] = value;
52
+ mkdirSync(configDir, { recursive: true });
53
+ writeFileSync(sessionFile, JSON.stringify(data, null, 2) + '\n');
54
+ },
55
+ get: async (key) => data[key],
56
+ del: async (key) => {
57
+ delete data[key];
58
+ mkdirSync(configDir, { recursive: true });
59
+ writeFileSync(sessionFile, JSON.stringify(data, null, 2) + '\n');
60
+ },
61
+ };
62
+ }
63
+
64
+ export function checkSession(did) {
65
+ try {
66
+ const raw = readFileSync(configPath('session.json'), 'utf-8');
67
+ const data = JSON.parse(raw);
68
+ const tokenSet = data[did]?.tokenSet;
69
+ if (!tokenSet) return null;
70
+ // Session is valid if access token is fresh OR a refresh token exists
71
+ // (the library will auto-refresh expired access tokens on restore)
72
+ const accessValid = tokenSet.expires_at && new Date(tokenSet.expires_at) > new Date();
73
+ if (accessValid || tokenSet.refresh_token) return did;
74
+ return null;
75
+ } catch {
76
+ return null;
77
+ }
78
+ }
79
+
80
+ export function createOAuthClient({ stateStore, sessionStore, redirectUri }) {
81
+ return new NodeOAuthClient({
82
+ requestLock,
83
+ clientMetadata: {
84
+ ...clientMetadata,
85
+ redirect_uris: [redirectUri],
86
+ },
87
+ stateStore,
88
+ sessionStore,
89
+ });
90
+ }
91
+
92
+ export async function restoreAgent(did) {
93
+ const sessionStore = createSessionStore();
94
+ const client = new NodeOAuthClient({
95
+ handleResolver: { resolve() { throw new Error('handle resolution not needed for restore'); } },
96
+ requestLock,
97
+ clientMetadata: {
98
+ ...clientMetadata,
99
+ redirect_uris: ['http://127.0.0.1'],
100
+ },
101
+ stateStore: noopStore,
102
+ sessionStore,
103
+ });
104
+ const session = await client.restore(did);
105
+ return { agent: new Agent(session), session };
106
+ }
@@ -0,0 +1,10 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
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);
@@ -0,0 +1,37 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
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,61 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
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 writeProjectConfig(obj, baseDir) {
22
+ const dir = baseDir ? join(baseDir, '.vit') : vitDir();
23
+ mkdirSync(dir, { recursive: true });
24
+ writeFileSync(join(dir, 'config.json'), JSON.stringify(obj, null, 2) + '\n');
25
+ }
26
+
27
+ export function appendLog(filename, record) {
28
+ const dir = vitDir();
29
+ mkdirSync(dir, { recursive: true });
30
+ appendFileSync(join(dir, filename), JSON.stringify(record) + '\n');
31
+ }
32
+
33
+ export function readLog(filename) {
34
+ const p = join(vitDir(), filename);
35
+ if (!existsSync(p)) return [];
36
+ try {
37
+ return readFileSync(p, 'utf-8')
38
+ .split('\n')
39
+ .filter(line => line.trim())
40
+ .map(line => { try { return JSON.parse(line); } catch { return null; } })
41
+ .filter(Boolean);
42
+ } catch {
43
+ return [];
44
+ }
45
+ }
46
+
47
+ export function readFollowing() {
48
+ const p = join(vitDir(), 'following.json');
49
+ if (!existsSync(p)) return [];
50
+ try {
51
+ return JSON.parse(readFileSync(p, 'utf-8'));
52
+ } catch {
53
+ return [];
54
+ }
55
+ }
56
+
57
+ export function writeFollowing(list) {
58
+ const dir = vitDir();
59
+ mkdirSync(dir, { recursive: true });
60
+ writeFileSync(join(dir, 'following.json'), JSON.stringify(list, null, 2) + '\n');
61
+ }
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