@sharedots/cli 0.1.2 → 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/src/parser.ts DELETED
@@ -1,77 +0,0 @@
1
- const BOOLEAN_FLAGS = new Set([
2
- "help",
3
- "h",
4
- "yes",
5
- "y",
6
- "cluster",
7
- "contributor",
8
- "foreground",
9
- "gpu",
10
- "json",
11
- ]);
12
-
13
- export function parseFlags(argv: string[]): { positional: string[]; flags: Record<string, string | boolean> } {
14
- const positional: string[] = [];
15
- const flags: Record<string, string | boolean> = {};
16
- let endOfFlags = false;
17
-
18
- for (let i = 0; i < argv.length; i++) {
19
- const arg = argv[i]!;
20
-
21
- if (endOfFlags) {
22
- positional.push(arg);
23
- continue;
24
- }
25
-
26
- if (arg === "--") {
27
- endOfFlags = true;
28
- continue;
29
- }
30
-
31
- if (arg.startsWith("--")) {
32
- const rest = arg.slice(2);
33
- const eq = rest.indexOf("=");
34
- if (eq !== -1) {
35
- const key = rest.slice(0, eq);
36
- const rawVal = rest.slice(eq + 1);
37
- if (rawVal === "true") {
38
- flags[key] = true;
39
- } else if (rawVal === "false") {
40
- flags[key] = false;
41
- } else {
42
- flags[key] = rawVal;
43
- }
44
- } else {
45
- const key = rest;
46
- if (BOOLEAN_FLAGS.has(key)) {
47
- flags[key] = true;
48
- } else {
49
- const next = argv[i + 1];
50
- if (next !== undefined && !next.startsWith("-")) {
51
- flags[key] = next;
52
- i++;
53
- } else {
54
- flags[key] = true;
55
- }
56
- }
57
- }
58
- } else if (arg.startsWith("-") && arg.length >= 2) {
59
- const key = arg.slice(1);
60
- if (BOOLEAN_FLAGS.has(key)) {
61
- flags[key] = true;
62
- } else {
63
- const next = argv[i + 1];
64
- if (next !== undefined && !next.startsWith("-")) {
65
- flags[key] = next;
66
- i++;
67
- } else {
68
- flags[key] = true;
69
- }
70
- }
71
- } else {
72
- positional.push(arg);
73
- }
74
- }
75
- return { positional, flags };
76
- }
77
-
package/src/up-wizard.ts DELETED
@@ -1,339 +0,0 @@
1
- import { execSync } from "node:child_process";
2
- import os from "node:os";
3
- import readline from "node:readline";
4
- import { decodeInviteCode } from "@sharedots/protocol";
5
- import { readConfig, startDaemonProcess, writeConfig } from "./daemon-runner.js";
6
-
7
- export interface SystemSpecs {
8
- cpuCores: number;
9
- cpuModel: string;
10
- totalMemoryBytes: number;
11
- totalMemoryGb: number;
12
- gpuDetected: boolean;
13
- gpuName?: string;
14
- osName: string;
15
- }
16
-
17
- export function probeSystemSpecs(): SystemSpecs {
18
- const cpus = os.cpus();
19
- const cpuCores = cpus.length;
20
- const cpuModel = cpus[0]?.model || "Generic CPU";
21
- const totalMemoryBytes = os.totalmem();
22
- const totalMemoryGb = Math.round((totalMemoryBytes / (1024 ** 3)) * 10) / 10;
23
- const osName = `${os.type()} ${os.release()} (${os.arch()})`;
24
-
25
- let gpuDetected = false;
26
- let gpuName: string | undefined;
27
-
28
- // Check for nvidia-smi
29
- try {
30
- const smi = execSync("nvidia-smi --query-gpu=name --format=csv,noheader", {
31
- encoding: "utf8",
32
- stdio: ["pipe", "pipe", "ignore"],
33
- timeout: 1500,
34
- }).trim();
35
- if (smi) {
36
- gpuDetected = true;
37
- gpuName = smi.split("\n")[0]?.trim();
38
- }
39
- } catch {
40
- // No nvidia-smi, check Windows WMIC or PowerShell if win32
41
- if (process.platform === "win32") {
42
- try {
43
- const winGpu = execSync(
44
- 'powershell -NoProfile -Command "(Get-CimInstance Win32_VideoController | Select-Object -ExpandProperty Name)[0]"',
45
- { encoding: "utf8", stdio: ["pipe", "pipe", "ignore"], timeout: 1500 },
46
- ).trim();
47
- if (winGpu && !winGpu.toLowerCase().includes("basic display") && !winGpu.toLowerCase().includes("remote")) {
48
- gpuDetected = true;
49
- gpuName = winGpu;
50
- }
51
- } catch {
52
- // ignore
53
- }
54
- }
55
- }
56
-
57
- return {
58
- cpuCores,
59
- cpuModel,
60
- totalMemoryBytes,
61
- totalMemoryGb,
62
- gpuDetected,
63
- gpuName,
64
- osName,
65
- };
66
- }
67
-
68
- export async function detectCoordinator(customUrls: string[] = []): Promise<string | null> {
69
- const candidateUrls = [
70
- ...customUrls,
71
- "https://sharedots.onrender.com",
72
- "http://127.0.0.1:4000",
73
- "http://localhost:4000",
74
- ];
75
-
76
- // Try checking tailscale peers if tailscale is installed
77
- try {
78
- const tsOut = execSync("tailscale status --json", {
79
- encoding: "utf8",
80
- stdio: ["pipe", "pipe", "ignore"],
81
- timeout: 1000,
82
- });
83
- const parsed = JSON.parse(tsOut) as { Peer?: Record<string, { TailscaleIPs?: string[] }> };
84
- if (parsed.Peer) {
85
- for (const peer of Object.values(parsed.Peer)) {
86
- if (peer.TailscaleIPs && peer.TailscaleIPs[0]) {
87
- candidateUrls.push(`http://${peer.TailscaleIPs[0]}:4000`);
88
- }
89
- }
90
- }
91
- } catch {
92
- // Tailscale not running or not installed
93
- }
94
-
95
- for (const url of candidateUrls) {
96
- try {
97
- const res = await fetch(`${url.replace(/\/+$/, "")}/api/overview`, {
98
- signal: AbortSignal.timeout(1000),
99
- });
100
- if (res.ok) {
101
- return url.replace(/\/+$/, "");
102
- }
103
- } catch {
104
- // transient unreachable
105
- }
106
- }
107
-
108
- return null;
109
- }
110
-
111
- export interface UpWizardOptions {
112
- cluster?: boolean;
113
- contributor?: boolean;
114
- joinCode?: string;
115
- coordinator?: string;
116
- yes?: boolean;
117
- foreground?: boolean;
118
- }
119
-
120
- function promptUser(query: string): Promise<string> {
121
- const rl = readline.createInterface({
122
- input: process.stdin,
123
- output: process.stdout,
124
- });
125
- return new Promise((res) => {
126
- rl.question(query, (ans) => {
127
- rl.close();
128
- res(ans.trim());
129
- });
130
- });
131
- }
132
-
133
- export async function runUpWizard(options: UpWizardOptions = {}): Promise<void> {
134
- console.log(`\n\x1b[1m\x1b[36m⚡ SHAREDOTS ZERO-CONFIG AUTO-DISCOVERY & LAUNCH WIZARD\x1b[0m\n`);
135
-
136
- const specs = probeSystemSpecs();
137
- console.log(`\x1b[32m✔ Host Hardware Detected:\x1b[0m`);
138
- console.log(` • CPU: ${specs.cpuCores} cores (${specs.cpuModel})`);
139
- console.log(` • Memory: ${specs.totalMemoryGb} GB`);
140
- console.log(` • GPU: ${specs.gpuDetected ? (specs.gpuName ?? "Yes") : "None / Integrated"}`);
141
- console.log(` • OS: ${specs.osName}\n`);
142
-
143
- // Direct join code provided
144
- if (options.joinCode) {
145
- const decoded = decodeInviteCode(options.joinCode);
146
- if (!decoded) {
147
- console.error("\x1b[31m✖ Error: Invalid invite code provided.\x1b[0m");
148
- process.exit(1);
149
- }
150
- console.log(`Configuring worker for room ${decoded.roomId} (${decoded.coordinatorUrl})...`);
151
- writeConfig({
152
- coordinator: decoded.coordinatorUrl,
153
- roomId: decoded.roomId,
154
- token: decoded.token,
155
- joinedAt: new Date().toISOString(),
156
- });
157
- const started = startDaemonProcess({
158
- coordinator: decoded.coordinatorUrl,
159
- roomId: decoded.roomId,
160
- token: decoded.token,
161
- foreground: options.foreground,
162
- });
163
- if (started.pid) {
164
- console.log(`\x1b[32m✔ Daemon running in background (PID ${started.pid}).\x1b[0m`);
165
- console.log(`Run 'sharedots worker status' or 'sharedots tui' to monitor.\n`);
166
- }
167
- return;
168
- }
169
-
170
- // Explicit cluster flag
171
- if (options.cluster) {
172
- console.log(`Starting new local Sharedots cluster...`);
173
- console.log(`Run 'pnpm coordinator:start' or launch coordinator on port 4000.\n`);
174
- return;
175
- }
176
-
177
- // Explicit contributor mode flag
178
- if (options.contributor) {
179
- console.log(`Configuring auto-tuned contributor node...`);
180
- const existing = readConfig();
181
- const coord = options.coordinator ?? existing?.coordinator ?? "https://sharedots.onrender.com";
182
- const room = existing?.roomId ?? "public-pool";
183
- const token = existing?.token ?? "sec_public";
184
-
185
- writeConfig({ coordinator: coord, roomId: room, token, joinedAt: new Date().toISOString() });
186
- const started = startDaemonProcess({
187
- coordinator: coord,
188
- roomId: room,
189
- token,
190
- cpuLimit: 75,
191
- foreground: options.foreground,
192
- });
193
- console.log(`\x1b[32m✔ Contributor node running (PID ${started.pid}). Contributing up to 75% CPU.\x1b[0m\n`);
194
- return;
195
- }
196
-
197
- // Probe for active coordinators
198
- process.stdout.write("Scanning local network and Tailscale mesh for active coordinators... ");
199
- const detectedCoord = await detectCoordinator(options.coordinator ? [options.coordinator] : []);
200
- if (detectedCoord) {
201
- console.log(`\x1b[32mFound!\x1b[0m`);
202
- console.log(`\x1b[1m\x1b[35m● Active coordinator discovered at: ${detectedCoord}\x1b[0m\n`);
203
-
204
- let joinNow = options.yes;
205
- if (!joinNow && process.stdin.isTTY) {
206
- const ans = await promptUser(`Join active coordinator at ${detectedCoord}? [Y/n]: `);
207
- joinNow = ans === "" || ans.toLowerCase().startsWith("y");
208
- }
209
-
210
- if (joinNow) {
211
- // Fetch or probe active rooms
212
- let roomId = "mesh-default";
213
- let token = "sec_auto";
214
- try {
215
- const roomsRes = await fetch(`${detectedCoord}/api/rooms`, {
216
- signal: AbortSignal.timeout(2000),
217
- });
218
- if (roomsRes.ok) {
219
- const body = (await roomsRes.json()) as { rooms?: Array<{ roomId: string }> };
220
- if (body.rooms && body.rooms.length > 0 && body.rooms[0]) {
221
- roomId = body.rooms[0].roomId;
222
- }
223
- }
224
- } catch {
225
- // ignore
226
- }
227
-
228
- writeConfig({
229
- coordinator: detectedCoord,
230
- roomId,
231
- token,
232
- joinedAt: new Date().toISOString(),
233
- });
234
- const started = startDaemonProcess({
235
- coordinator: detectedCoord,
236
- roomId,
237
- token,
238
- foreground: options.foreground,
239
- });
240
- console.log(`\x1b[32m✔ Connected to cluster at ${detectedCoord} (room: ${roomId}).\x1b[0m`);
241
- if (started.pid) {
242
- console.log(`Worker daemon started (PID ${started.pid}). Run 'sharedots tui' to view dashboard.\n`);
243
- }
244
- return;
245
- }
246
- } else {
247
- console.log(`None detected.`);
248
- }
249
-
250
- // Interactive selection if TTY
251
- if (process.stdin.isTTY) {
252
- console.log(`How do you want to run Sharedots?`);
253
- console.log(` [1] Join existing mesh (paste invite code or enter URL)`);
254
- console.log(` [2] Start new cluster (Coordinator + local Worker)`);
255
- console.log(` [3] Contributor mode (Worker only, auto-tuned to 75% CPU)`);
256
-
257
- const choice = await promptUser(`Select option [1-3] (default 1): `);
258
-
259
- if (choice === "2") {
260
- console.log(`Starting new local Sharedots cluster...`);
261
- // Start cluster
262
- console.log(`Run 'pnpm coordinator:start' or launch coordinator on port 4000.`);
263
- return;
264
- }
265
-
266
- if (choice === "3") {
267
- console.log(`Configuring auto-tuned contributor node...`);
268
- const existing = readConfig();
269
- const coord = existing?.coordinator ?? detectedCoord ?? "https://sharedots.onrender.com";
270
- const room = existing?.roomId ?? "public-pool";
271
- const token = existing?.token ?? "sec_public";
272
-
273
- writeConfig({ coordinator: coord, roomId: room, token, joinedAt: new Date().toISOString() });
274
- const started = startDaemonProcess({
275
- coordinator: coord,
276
- roomId: room,
277
- token,
278
- cpuLimit: 75,
279
- foreground: options.foreground,
280
- });
281
- console.log(`\x1b[32m✔ Contributor node running (PID ${started.pid}). Contributing up to 75% CPU.\x1b[0m\n`);
282
- return;
283
- }
284
-
285
- // Default option 1: join
286
- const rawInput = await promptUser(`Paste Unified Invite Code ('sd_join_...') or Coordinator URL: `);
287
- if (!rawInput) {
288
- console.log("No input received. Exiting.");
289
- return;
290
- }
291
- const decoded = decodeInviteCode(rawInput);
292
- if (decoded) {
293
- writeConfig({
294
- coordinator: decoded.coordinatorUrl,
295
- roomId: decoded.roomId,
296
- token: decoded.token,
297
- joinedAt: new Date().toISOString(),
298
- });
299
- const started = startDaemonProcess({
300
- coordinator: decoded.coordinatorUrl,
301
- roomId: decoded.roomId,
302
- token: decoded.token,
303
- foreground: options.foreground,
304
- });
305
- console.log(`\x1b[32m✔ Worker successfully configured and launched (PID ${started.pid}).\x1b[0m\n`);
306
- return;
307
- }
308
-
309
- console.log(`Connecting to ${rawInput}...`);
310
- writeConfig({
311
- coordinator: rawInput,
312
- roomId: "default-room",
313
- token: "sec_default",
314
- joinedAt: new Date().toISOString(),
315
- });
316
- startDaemonProcess({
317
- coordinator: rawInput,
318
- roomId: "default-room",
319
- token: "sec_default",
320
- foreground: options.foreground,
321
- });
322
- console.log(`\x1b[32m✔ Worker started.\x1b[0m\n`);
323
- } else {
324
- // Non-interactive fallback
325
- const existing = readConfig();
326
- const coord = existing?.coordinator ?? detectedCoord ?? "https://sharedots.onrender.com";
327
- const room = existing?.roomId ?? "mesh-default";
328
- const token = existing?.token ?? "sec_auto";
329
-
330
- writeConfig({ coordinator: coord, roomId: room, token, joinedAt: new Date().toISOString() });
331
- const started = startDaemonProcess({
332
- coordinator: coord,
333
- roomId: room,
334
- token,
335
- foreground: options.foreground,
336
- });
337
- console.log(`\x1b[32m✔ Sharedots started for room ${room} on ${coord} (PID ${started.pid}).\x1b[0m\n`);
338
- }
339
- }
package/tsconfig.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- "rootDir": "./src",
6
- "paths": {
7
- "@sharedots/tui": ["../../apps/tui/dist/index.d.ts"]
8
- }
9
- },
10
- "include": ["src/**/*.ts"],
11
- "exclude": ["src/**/*.test.ts"]
12
- }