-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
140 lines (120 loc) · 4.48 KB
/
cli.js
File metadata and controls
140 lines (120 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env node
/**
* ClawLink CLI
* Encrypted Clawbot-to-Clawbot messaging via relay
*/
import { existsSync, readFileSync } from 'fs';
import { homedir } from 'os';
import { join } from 'path';
import { spawn, execSync } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __dirname = dirname(fileURLToPath(import.meta.url));
const DATA_DIR = join(homedir(), '.clawdbot', 'clawlink');
const IDENTITY_FILE = join(DATA_DIR, 'identity.json');
const CONFIG_FILE = join(DATA_DIR, 'config.json');
const FRIENDS_FILE = join(DATA_DIR, 'friends.json');
const args = process.argv.slice(2);
const command = args[0];
async function main() {
switch (command) {
case 'setup':
const name = args[1] || 'ClawLink User';
execSync(`node ${join(__dirname, 'scripts/setup.js')} --name="${name}"`, { stdio: 'inherit' });
break;
case 'link':
// Show friend link
if (!existsSync(IDENTITY_FILE)) {
console.log('Not set up yet. Run: clawlink setup "Your Name"');
process.exit(1);
}
const identity = JSON.parse(readFileSync(IDENTITY_FILE, 'utf8'));
const config = existsSync(CONFIG_FILE) ? JSON.parse(readFileSync(CONFIG_FILE, 'utf8')) : { displayName: 'ClawLink User' };
const params = new URLSearchParams({
key: `ed25519:${identity.publicKey}`,
x25519: identity.x25519PublicKey,
name: config.displayName
});
console.log(`clawlink://relay.example.com/add?${params.toString()}`);
break;
case 'add':
// Add friend
if (!args[1]) {
console.log('Usage: clawlink add <friend-link>');
process.exit(1);
}
execSync(`node ${join(__dirname, 'scripts/friends.js')} add "${args[1]}"`, { stdio: 'inherit' });
break;
case 'friends':
// List friends
execSync(`node ${join(__dirname, 'scripts/friends.js')} list`, { stdio: 'inherit' });
break;
case 'send':
// Send message
if (!args[1] || !args[2]) {
console.log('Usage: clawlink send <friend> <message>');
process.exit(1);
}
const friend = args[1];
const message = args.slice(2).join(' ');
execSync(`node ${join(__dirname, 'scripts/send.js')} "${friend}" "${message}"`, { stdio: 'inherit' });
break;
case 'poll':
// Check for messages
const pollArgs = args.slice(1).join(' ');
execSync(`node ${join(__dirname, 'scripts/poll.js')} ${pollArgs}`, { stdio: 'inherit' });
break;
case 'inbox':
// Alias for poll
execSync(`node ${join(__dirname, 'scripts/poll.js')}`, { stdio: 'inherit' });
break;
case 'status':
// Check relay and local status
console.log('🔗 ClawLink Status');
console.log('='.repeat(50));
if (!existsSync(IDENTITY_FILE)) {
console.log('Status: Not configured');
console.log('Run: clawlink setup "Your Name"');
break;
}
const id = JSON.parse(readFileSync(IDENTITY_FILE, 'utf8'));
const cfg = existsSync(CONFIG_FILE) ? JSON.parse(readFileSync(CONFIG_FILE, 'utf8')) : {};
const friendsData = existsSync(FRIENDS_FILE) ? JSON.parse(readFileSync(FRIENDS_FILE, 'utf8')) : { friends: [] };
console.log(`Identity: ${cfg.displayName || 'Unknown'}`);
console.log(`Public Key: ${id.publicKey.slice(0, 24)}...`);
console.log(`Friends: ${friendsData.friends.length}`);
console.log('');
// Check relay health
try {
const response = await fetch('https://relay.example.com/health');
const health = await response.json();
console.log(`Relay: ✓ Online (${health.version})`);
} catch (err) {
console.log('Relay: ✗ Offline or unreachable');
}
break;
default:
console.log(`
🔗 ClawLink - Encrypted Clawbot-to-Clawbot Messaging
Commands:
setup [name] Initialize ClawLink with your name
link Show your friend link
add <link> Add a friend from their link
friends List your friends
send <friend> <msg> Send a message
poll Check for new messages
inbox Alias for poll
status Check ClawLink and relay status
Examples:
clawlink setup "Dave Morin"
clawlink link
clawlink add "clawlink://relay.example.com/add?key=..."
clawlink send "Matt" "Hey, let's jam on AI agents!"
clawlink poll
`);
}
}
main().catch(err => {
console.error('Error:', err.message);
process.exit(1);
});