@sharedots/cli 0.0.0-stage → 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.
package/LICENSE ADDED
@@ -0,0 +1,195 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of discussing and
55
+ improving the Work, but excluding communication that is conspicuously
56
+ marked or otherwise designated in writing by the copyright owner as
57
+ "Not a Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and subsequently
61
+ incorporated within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by combination of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You
79
+ institute patent litigation against any entity (including a cross-claim
80
+ or counterclaim in a lawsuit) alleging that the Work or any
81
+ Contribution incorporated within the Work constitutes direct or
82
+ contributory patent infringement, then any patent licenses granted
83
+ to You under this License for that Work shall terminate as of the
84
+ date such litigation is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the
87
+ Work or Derivative Works thereof in any medium, with or without
88
+ modifications, and in Source or Object form, provided that You
89
+ meet the following conditions:
90
+
91
+ (a) You must give any other recipients of the Work or Derivative
92
+ Works a copy of this License; and
93
+
94
+ (b) You must cause any modified files to carry prominent notices
95
+ stating that You changed the files; and
96
+
97
+ (c) You must retain, in the Source form of any Derivative Works
98
+ that You distribute, all copyright, patent, trademark, and
99
+ attribution notices from the Source form of the Work,
100
+ excluding those notices that do not pertain to any part of
101
+ the Derivative Works; and
102
+
103
+ (d) If the Work includes a "NOTICE" text file as part of its
104
+ distribution, You must include a readable copy of the
105
+ attribution notices contained within such NOTICE file, in
106
+ at least one of the following places: within a NOTICE text
107
+ file distributed as part of the Derivative Works; within
108
+ the Source form or documentation, if provided along with the
109
+ Derivative Works; or, within a display generated by the
110
+ Derivative Works, if and wherever such third-party notices
111
+ normally appear. The contents of the NOTICE file are for
112
+ informational purposes only and do not modify the License.
113
+ You may add Your own attribution notices within Derivative
114
+ Works that You distribute, alongside or as an addendum to
115
+ the NOTICE text from the Work, provided that such additional
116
+ attribution notices cannot be construed as modifying the License.
117
+
118
+ You may add Your own license statement for Your modifications and
119
+ may provide additional grant of rights to use, modify, and distribute
120
+ Your modifications, or for such Derivative Works as a whole, under
121
+ terms of Your choice, provided Your use, reproduction, and
122
+ distribution of the Work otherwise complies with the conditions
123
+ stated in this License.
124
+
125
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
126
+ any Contribution intentionally submitted for inclusion in the Work
127
+ by You to the Licensor shall be under the terms and conditions of
128
+ this License, without any additional terms or conditions.
129
+ Notwithstanding the above, nothing herein shall supersede or modify
130
+ the terms of any separate license agreement you may have executed
131
+ with Licensor regarding such Contributions.
132
+
133
+ 6. Trademarks. This License does not grant permission to use the trade
134
+ names, trademarks, service marks, or product names of the Licensor,
135
+ except as required for reasonable and customary use in describing the
136
+ origin of the Work and reproducing the content of the NOTICE file.
137
+
138
+ 7. Disclaimer of Warranty. Unless required by applicable law or
139
+ agreed to in writing, Licensor provides the Work (and each
140
+ Contributor provides its Contributions) on an "AS IS" BASIS,
141
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
142
+ implied, including, without limitation, any warranties or conditions
143
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
144
+ PARTICULAR PURPOSE. You are solely responsible for determining the
145
+ appropriateness of using or redistributing the Work and assume any
146
+ risks associated with Your exercise of permissions under this License.
147
+
148
+ 8. Limitation of Liability. In no event and under no legal theory,
149
+ whether in tort (including negligence), contract, or otherwise,
150
+ unless required by applicable law (such as deliberate and grossly
151
+ negligent acts) or agreed to in writing, shall any Contributor be
152
+ liable to You for damages, including any direct, indirect, special,
153
+ incidental, or exemplary damages of any character arising as a
154
+ result of this License or out of the use or inability to use the
155
+ Work (including but not limited to damages for loss of goodwill,
156
+ work stoppage, computer failure or malfunction, or all other
157
+ commercial damages or losses), even if such Contributor has been
158
+ advised of the possibility of such damages.
159
+
160
+ 9. Accepting Warranty or Additional Liability. While redistributing
161
+ the Work or Derivative Works thereof, You may choose to offer,
162
+ and charge a fee for, acceptance of support, warranty, indemnity,
163
+ or other liability obligations and/or rights consistent with this
164
+ License. However, in accepting such obligations, You may act only
165
+ on Your own behalf and on Your sole responsibility, not on behalf
166
+ of any other Contributor, and only if You agree to indemnify,
167
+ defend, and hold each Contributor harmless for any liability
168
+ incurred by, or claims asserted against, such Contributor by reason
169
+ of your accepting any such warranty or additional liability.
170
+
171
+ END OF TERMS AND CONDITIONS
172
+
173
+ APPENDIX: How to apply the Apache License to your work.
174
+
175
+ To apply the Apache License to your work, attach the following
176
+ boilerplate notice, with the fields enclosed by brackets "[]"
177
+ replaced with your own identifying information. (Don't include
178
+ the brackets!) The text should be enclosed in the appropriate
179
+ comment syntax for the file format. Please also include a
180
+ "NOTICE" file as part of your distribution, as well as a pointer
181
+ to your git repository or project page for further information.
182
+
183
+ Copyright 2026 Sharedots Contributors
184
+
185
+ Licensed under the Apache License, Version 2.0 (the "License");
186
+ you may not use this file except in compliance with the License.
187
+ You may obtain a copy of the License at
188
+
189
+ http://www.apache.org/licenses/LICENSE-2.0
190
+
191
+ Unless required by applicable law or agreed to in writing, software
192
+ distributed under the License is distributed on an "AS IS" BASIS,
193
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
194
+ See the License for the specific language governing permissions and
195
+ limitations under the License.
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ export declare function parseFlags(argv: string[]): {
3
+ positional: string[];
4
+ flags: Record<string, string | boolean>;
5
+ };
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAkFA,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG;IAAE,UAAU,EAAE,MAAM,EAAE,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAA;CAAE,CAwB5G"}
package/dist/index.js ADDED
@@ -0,0 +1,364 @@
1
+ #!/usr/bin/env node
2
+ import { spawn, spawnSync } from "node:child_process";
3
+ import { closeSync, existsSync, mkdirSync, openSync, readFileSync, rmSync, writeFileSync, } from "node:fs";
4
+ import { homedir } from "node:os";
5
+ import { dirname, join, resolve } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+ import { Sharedots } from "sharedots";
8
+ const __dirname = dirname(fileURLToPath(import.meta.url));
9
+ function getHomeDir() {
10
+ const dir = process.env.SHAREDOTS_HOME
11
+ ? resolve(process.env.SHAREDOTS_HOME)
12
+ : join(homedir(), ".sharedots");
13
+ mkdirSync(dir, { recursive: true });
14
+ return dir;
15
+ }
16
+ function configPath() {
17
+ return join(getHomeDir(), "worker-config.json");
18
+ }
19
+ function pidPath() {
20
+ return join(getHomeDir(), "worker.pid");
21
+ }
22
+ function logPath() {
23
+ return join(getHomeDir(), "worker.log");
24
+ }
25
+ function readConfig() {
26
+ const p = configPath();
27
+ if (!existsSync(p))
28
+ return null;
29
+ return JSON.parse(readFileSync(p, "utf8"));
30
+ }
31
+ function writeConfig(cfg) {
32
+ writeFileSync(configPath(), `${JSON.stringify(cfg, null, 2)}\n`, "utf8");
33
+ }
34
+ function resolveDaemonBinary() {
35
+ if (process.env.SHAREDOTS_DAEMON_BIN && existsSync(process.env.SHAREDOTS_DAEMON_BIN)) {
36
+ return process.env.SHAREDOTS_DAEMON_BIN;
37
+ }
38
+ const exe = process.platform === "win32" ? "sharedots-daemon.exe" : "sharedots-daemon";
39
+ const repoRoot = resolve(__dirname, "../../..");
40
+ const candidates = [
41
+ join(repoRoot, "target", "release", exe),
42
+ join(repoRoot, "target", "debug", exe),
43
+ join(process.cwd(), "target", "release", exe),
44
+ join(process.cwd(), "target", "debug", exe),
45
+ ];
46
+ for (const c of candidates) {
47
+ if (existsSync(c))
48
+ return c;
49
+ }
50
+ return exe; // fallback to PATH
51
+ }
52
+ function isProcessRunning(pid) {
53
+ try {
54
+ process.kill(pid, 0);
55
+ return true;
56
+ }
57
+ catch {
58
+ return false;
59
+ }
60
+ }
61
+ export function parseFlags(argv) {
62
+ const positional = [];
63
+ const flags = {};
64
+ for (let i = 0; i < argv.length; i++) {
65
+ const arg = argv[i];
66
+ if (arg.startsWith("--")) {
67
+ const key = arg.slice(2);
68
+ const eq = key.indexOf("=");
69
+ if (eq !== -1) {
70
+ flags[key.slice(0, eq)] = key.slice(eq + 1);
71
+ }
72
+ else {
73
+ const next = argv[i + 1];
74
+ if (next && !next.startsWith("--")) {
75
+ flags[key] = next;
76
+ i++;
77
+ }
78
+ else {
79
+ flags[key] = true;
80
+ }
81
+ }
82
+ }
83
+ else {
84
+ positional.push(arg);
85
+ }
86
+ }
87
+ return { positional, flags };
88
+ }
89
+ function printHelp() {
90
+ console.log(`Sharedots CLI v0.1.0 — Universal Distributed Compute Network
91
+
92
+ Usage:
93
+ sharedots tui [--coordinator URL]
94
+ sharedots room create [--name NAME] [--coordinator URL]
95
+ sharedots worker join <ROOM_ID> --token <SECRET> [--coordinator URL]
96
+ sharedots worker start [--cpu-limit N] [--memory-limit MB] [--gpu] [--foreground]
97
+ sharedots worker status
98
+ sharedots worker stop
99
+ sharedots worker leave
100
+ sharedots worker logs [--lines N]
101
+ sharedots job submit <job.json> [--coordinator URL] [--room ROOM_ID] [--token SECRET]
102
+ sharedots bench [--size N] [--partitions P] [--coordinator URL] [--room ROOM_ID] [--token SECRET]
103
+ `);
104
+ }
105
+ async function main() {
106
+ const { positional, flags } = parseFlags(process.argv.slice(2));
107
+ const [group, sub, ...rest] = positional;
108
+ if (!group || flags.help || group === "help") {
109
+ printHelp();
110
+ return;
111
+ }
112
+ const defaultCoord = (typeof flags.coordinator === "string" ? flags.coordinator : undefined) ??
113
+ process.env.SHAREDOTS_COORDINATOR ??
114
+ "http://localhost:4000";
115
+ if (group === "tui") {
116
+ try {
117
+ const tui = await import("@sharedots/tui");
118
+ if (typeof tui.runTui === "function") {
119
+ await tui.runTui({
120
+ initialCoordinator: defaultCoord,
121
+ });
122
+ return;
123
+ }
124
+ }
125
+ catch {
126
+ // Fallback to relative path lookup
127
+ const repoRoot = resolve(__dirname, "../../..");
128
+ const candidates = [
129
+ join(repoRoot, "apps", "tui", "dist", "index.js"),
130
+ join(process.cwd(), "apps", "tui", "dist", "index.js"),
131
+ ];
132
+ for (const cand of candidates) {
133
+ if (existsSync(cand)) {
134
+ const mod = await import(`file://${cand.replace(/\\/g, "/")}`);
135
+ if (typeof mod.runTui === "function") {
136
+ await mod.runTui({ initialCoordinator: defaultCoord });
137
+ return;
138
+ }
139
+ }
140
+ }
141
+ console.error("Failed to load @sharedots/tui. Please build apps/tui first.");
142
+ process.exit(1);
143
+ }
144
+ return;
145
+ }
146
+ if (group === "room" && sub === "create") {
147
+ const client = new Sharedots({ coordinator: defaultCoord });
148
+ const name = typeof flags.name === "string" ? flags.name : undefined;
149
+ const room = await client.createRoom(name);
150
+ if (flags.json) {
151
+ console.log(JSON.stringify(room, null, 2));
152
+ }
153
+ else {
154
+ console.log(`Room created successfully`);
155
+ console.log(` ROOM_ID: ${room.roomId}`);
156
+ console.log(` ROOM_SECRET: ${room.secret}`);
157
+ console.log(` COORDINATOR: ${defaultCoord}`);
158
+ console.log(`\nJoin a worker with:`);
159
+ console.log(` sharedots worker join ${room.roomId} --coordinator ${defaultCoord} --token ${room.secret}`);
160
+ }
161
+ return;
162
+ }
163
+ if (group === "worker") {
164
+ if (sub === "join") {
165
+ const roomId = rest[0];
166
+ const token = (typeof flags.token === "string" ? flags.token : undefined) ?? process.env.SHAREDOTS_TOKEN;
167
+ if (!roomId || !token) {
168
+ console.error("Usage: sharedots worker join <ROOM_ID> --token <SECRET> [--coordinator URL]");
169
+ process.exit(1);
170
+ }
171
+ writeConfig({
172
+ coordinator: defaultCoord,
173
+ roomId,
174
+ token,
175
+ joinedAt: new Date().toISOString(),
176
+ });
177
+ console.log(`Saved worker configuration for room ${roomId} (${defaultCoord})`);
178
+ console.log(`Start the background daemon with: sharedots worker start`);
179
+ return;
180
+ }
181
+ if (sub === "start") {
182
+ const cfg = readConfig();
183
+ const roomId = (typeof flags.room === "string" ? flags.room : undefined) ?? cfg?.roomId;
184
+ const token = (typeof flags.token === "string" ? flags.token : undefined) ?? cfg?.token;
185
+ const coordinator = (typeof flags.coordinator === "string" ? flags.coordinator : undefined) ??
186
+ cfg?.coordinator ??
187
+ defaultCoord;
188
+ if (!roomId || !token) {
189
+ console.error("Worker is not joined to a room. Run `sharedots worker join <ROOM_ID> --token <SECRET>` first.");
190
+ process.exit(1);
191
+ }
192
+ const bin = resolveDaemonBinary();
193
+ const home = getHomeDir();
194
+ const args = [
195
+ "--coordinator",
196
+ coordinator,
197
+ "--room-id",
198
+ roomId,
199
+ "--token",
200
+ token,
201
+ "--state-dir",
202
+ join(home, "state"),
203
+ "--work-dir",
204
+ join(home, "work"),
205
+ ];
206
+ if (typeof flags["cpu-limit"] === "string") {
207
+ args.push("--cpu-limit", flags["cpu-limit"]);
208
+ }
209
+ if (typeof flags["memory-limit"] === "string") {
210
+ args.push("--memory-limit", flags["memory-limit"]);
211
+ }
212
+ if (flags.gpu === true) {
213
+ args.push("--gpu");
214
+ }
215
+ if (flags.foreground === true) {
216
+ const child = spawn(bin, args, { stdio: "inherit" });
217
+ child.on("exit", (code) => process.exit(code ?? 0));
218
+ return;
219
+ }
220
+ const logFd = openSync(logPath(), "a");
221
+ const child = spawn(bin, args, {
222
+ detached: true,
223
+ stdio: ["ignore", logFd, logFd],
224
+ });
225
+ child.unref();
226
+ closeSync(logFd);
227
+ if (child.pid) {
228
+ writeFileSync(pidPath(), String(child.pid), "utf8");
229
+ console.log(`Started sharedots-daemon (PID ${child.pid}) for room ${roomId}`);
230
+ console.log(`Logs: ${logPath()}`);
231
+ }
232
+ else {
233
+ console.error(`Failed to start daemon binary: ${bin}`);
234
+ process.exit(1);
235
+ }
236
+ return;
237
+ }
238
+ if (sub === "status") {
239
+ const cfg = readConfig();
240
+ const pidFile = pidPath();
241
+ const pid = existsSync(pidFile) ? Number.parseInt(readFileSync(pidFile, "utf8").trim(), 10) : null;
242
+ const running = pid !== null && Number.isFinite(pid) && isProcessRunning(pid);
243
+ const widFile = join(getHomeDir(), "state", "worker_id");
244
+ const workerId = existsSync(widFile) ? readFileSync(widFile, "utf8").trim() : null;
245
+ console.log(`Worker Status: ${running ? "running" : "stopped"}`);
246
+ if (pid)
247
+ console.log(` PID: ${pid}`);
248
+ if (workerId)
249
+ console.log(` Worker ID: ${workerId}`);
250
+ if (cfg) {
251
+ console.log(` Room ID: ${cfg.roomId}`);
252
+ console.log(` Coordinator: ${cfg.coordinator}`);
253
+ }
254
+ return;
255
+ }
256
+ if (sub === "stop") {
257
+ const pidFile = pidPath();
258
+ if (!existsSync(pidFile)) {
259
+ console.log("Worker daemon is not running.");
260
+ return;
261
+ }
262
+ const pid = Number.parseInt(readFileSync(pidFile, "utf8").trim(), 10);
263
+ if (Number.isFinite(pid) && isProcessRunning(pid)) {
264
+ try {
265
+ process.kill(pid, "SIGTERM");
266
+ }
267
+ catch {
268
+ // ignore
269
+ }
270
+ console.log(`Stopped worker daemon (PID ${pid})`);
271
+ }
272
+ else {
273
+ console.log("Worker daemon was already stopped.");
274
+ }
275
+ rmSync(pidFile, { force: true });
276
+ return;
277
+ }
278
+ if (sub === "leave") {
279
+ const pidFile = pidPath();
280
+ if (existsSync(pidFile)) {
281
+ const pid = Number.parseInt(readFileSync(pidFile, "utf8").trim(), 10);
282
+ if (Number.isFinite(pid) && isProcessRunning(pid)) {
283
+ try {
284
+ process.kill(pid, "SIGTERM");
285
+ }
286
+ catch {
287
+ // ignore
288
+ }
289
+ }
290
+ rmSync(pidFile, { force: true });
291
+ }
292
+ rmSync(configPath(), { force: true });
293
+ console.log("Worker left room and cleared local room configuration.");
294
+ return;
295
+ }
296
+ if (sub === "logs") {
297
+ const p = logPath();
298
+ if (!existsSync(p)) {
299
+ console.log("No worker logs found yet.");
300
+ return;
301
+ }
302
+ const lines = readFileSync(p, "utf8").split(/\r?\n/);
303
+ const count = typeof flags.lines === "string" ? Number.parseInt(flags.lines, 10) : 50;
304
+ console.log(lines.slice(-count).join("\n"));
305
+ return;
306
+ }
307
+ }
308
+ if (group === "job" && sub === "submit") {
309
+ const jobFile = rest[0];
310
+ if (!jobFile || !existsSync(resolve(jobFile))) {
311
+ console.error("Usage: sharedots job submit <job.json> [--coordinator URL] [--room ROOM_ID] [--token SECRET]");
312
+ process.exit(1);
313
+ }
314
+ const cfg = readConfig();
315
+ const coordinator = (typeof flags.coordinator === "string" ? flags.coordinator : undefined) ??
316
+ cfg?.coordinator ??
317
+ defaultCoord;
318
+ const roomId = (typeof flags.room === "string" ? flags.room : undefined) ??
319
+ process.env.SHAREDOTS_ROOM_ID ??
320
+ cfg?.roomId;
321
+ const token = (typeof flags.token === "string" ? flags.token : undefined) ??
322
+ process.env.SHAREDOTS_TOKEN ??
323
+ cfg?.token;
324
+ if (!roomId || !token) {
325
+ console.error("Missing --room and --token (or join a room first).");
326
+ process.exit(1);
327
+ }
328
+ const spec = JSON.parse(readFileSync(resolve(jobFile), "utf8"));
329
+ const client = new Sharedots({ coordinator, token });
330
+ const room = await client.connect(roomId);
331
+ const job = await room.submit(spec);
332
+ console.log(`Submitted job ${job.jobId} to room ${roomId}`);
333
+ job.on("progress", (p) => {
334
+ console.log(` progress: ${p.percent}% (${p.completedTasks ?? 0}/${p.totalTasks ?? 0})`);
335
+ });
336
+ const result = await job.result();
337
+ console.log(JSON.stringify(result, null, 2));
338
+ return;
339
+ }
340
+ if (group === "bench") {
341
+ const repoRoot = resolve(__dirname, "../../..");
342
+ const benchScript = join(repoRoot, "scripts", "bench", "run-matrix-bench.mjs");
343
+ if (!existsSync(benchScript)) {
344
+ console.error(`Benchmark script not found at ${benchScript}`);
345
+ process.exit(1);
346
+ }
347
+ const res = spawnSync(process.execPath, [benchScript, ...process.argv.slice(3)], {
348
+ stdio: "inherit",
349
+ });
350
+ process.exit(res.status ?? 0);
351
+ }
352
+ console.error(`Unknown command: ${positional.join(" ")}`);
353
+ printHelp();
354
+ process.exit(1);
355
+ }
356
+ const isMain = process.argv[1] &&
357
+ resolve(process.argv[1]).toLowerCase() === resolve(fileURLToPath(import.meta.url)).toLowerCase();
358
+ if (isMain) {
359
+ main().catch((err) => {
360
+ console.error(err instanceof Error ? err.message : String(err));
361
+ process.exit(1);
362
+ });
363
+ }
364
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAA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IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,26 @@
1
1
  {
2
2
  "name": "@sharedots/cli",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "bin": {
8
+ "sharedots": "./dist/index.js"
9
+ },
10
+ "dependencies": {
11
+ "@sharedots/protocol": "0.1.0",
12
+ "@sharedots/tui": "0.1.0",
13
+ "sharedots": "0.1.0"
14
+ },
15
+ "devDependencies": {
16
+ "@types/node": "^22.10.0",
17
+ "typescript": "^5.7.2",
18
+ "vitest": "^2.1.8"
19
+ },
20
+ "scripts": {
21
+ "build": "tsc -p tsconfig.json",
22
+ "typecheck": "tsc -p tsconfig.json --noEmit",
23
+ "test": "vitest run",
24
+ "clean": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\""
25
+ }
6
26
  }
@@ -0,0 +1,19 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { parseFlags } from "./index.js";
3
+
4
+ describe("@sharedots/cli argument parser", () => {
5
+ it("parses positional commands and flag values cleanly", () => {
6
+ const parsed = parseFlags([
7
+ "worker",
8
+ "start",
9
+ "--cpu-limit",
10
+ "50",
11
+ "--memory-limit=4096",
12
+ "--gpu",
13
+ ]);
14
+ expect(parsed.positional).toEqual(["worker", "start"]);
15
+ expect(parsed.flags["cpu-limit"]).toBe("50");
16
+ expect(parsed.flags["memory-limit"]).toBe("4096");
17
+ expect(parsed.flags.gpu).toBe(true);
18
+ });
19
+ });
package/src/index.ts ADDED
@@ -0,0 +1,415 @@
1
+ #!/usr/bin/env node
2
+ import { spawn, spawnSync } from "node:child_process";
3
+ import {
4
+ closeSync,
5
+ existsSync,
6
+ mkdirSync,
7
+ openSync,
8
+ readFileSync,
9
+ realpathSync,
10
+ rmSync,
11
+ writeFileSync,
12
+ } from "node:fs";
13
+ import { homedir } from "node:os";
14
+ import { dirname, join, resolve } from "node:path";
15
+ import { fileURLToPath } from "node:url";
16
+ import { Sharedots } from "sharedots";
17
+
18
+ const __dirname = dirname(fileURLToPath(import.meta.url));
19
+
20
+ interface LocalWorkerConfig {
21
+ coordinator: string;
22
+ roomId: string;
23
+ token: string;
24
+ joinedAt: string;
25
+ }
26
+
27
+ function getHomeDir(): string {
28
+ const dir = process.env.SHAREDOTS_HOME
29
+ ? resolve(process.env.SHAREDOTS_HOME)
30
+ : join(homedir(), ".sharedots");
31
+ mkdirSync(dir, { recursive: true });
32
+ return dir;
33
+ }
34
+
35
+ function configPath(): string {
36
+ return join(getHomeDir(), "worker-config.json");
37
+ }
38
+
39
+ function pidPath(): string {
40
+ return join(getHomeDir(), "worker.pid");
41
+ }
42
+
43
+ function logPath(): string {
44
+ return join(getHomeDir(), "worker.log");
45
+ }
46
+
47
+ function readConfig(): LocalWorkerConfig | null {
48
+ const p = configPath();
49
+ if (!existsSync(p)) return null;
50
+ return JSON.parse(readFileSync(p, "utf8")) as LocalWorkerConfig;
51
+ }
52
+
53
+ function writeConfig(cfg: LocalWorkerConfig): void {
54
+ writeFileSync(configPath(), `${JSON.stringify(cfg, null, 2)}\n`, "utf8");
55
+ }
56
+
57
+ function resolveDaemonBinary(): string {
58
+ if (process.env.SHAREDOTS_DAEMON_BIN && existsSync(process.env.SHAREDOTS_DAEMON_BIN)) {
59
+ return process.env.SHAREDOTS_DAEMON_BIN;
60
+ }
61
+ const exe = process.platform === "win32" ? "sharedots-daemon.exe" : "sharedots-daemon";
62
+ const repoRoot = resolve(__dirname, "../../..");
63
+ const candidates = [
64
+ join(repoRoot, "target", "release", exe),
65
+ join(repoRoot, "target", "debug", exe),
66
+ join(process.cwd(), "target", "release", exe),
67
+ join(process.cwd(), "target", "debug", exe),
68
+ ];
69
+ for (const c of candidates) {
70
+ if (existsSync(c)) return c;
71
+ }
72
+ return exe; // fallback to PATH
73
+ }
74
+
75
+ function isProcessRunning(pid: number): boolean {
76
+ try {
77
+ process.kill(pid, 0);
78
+ return true;
79
+ } catch {
80
+ return false;
81
+ }
82
+ }
83
+
84
+ export function parseFlags(argv: string[]): { positional: string[]; flags: Record<string, string | boolean> } {
85
+ const positional: string[] = [];
86
+ const flags: Record<string, string | boolean> = {};
87
+ for (let i = 0; i < argv.length; i++) {
88
+ const arg = argv[i]!;
89
+ if (arg.startsWith("--")) {
90
+ const key = arg.slice(2);
91
+ const eq = key.indexOf("=");
92
+ if (eq !== -1) {
93
+ flags[key.slice(0, eq)] = key.slice(eq + 1);
94
+ } else {
95
+ const next = argv[i + 1];
96
+ if (next && !next.startsWith("--")) {
97
+ flags[key] = next;
98
+ i++;
99
+ } else {
100
+ flags[key] = true;
101
+ }
102
+ }
103
+ } else {
104
+ positional.push(arg);
105
+ }
106
+ }
107
+ return { positional, flags };
108
+ }
109
+
110
+ function printHelp(): void {
111
+ console.log(`Sharedots CLI v0.1.0 — Universal Distributed Compute Network
112
+
113
+ Usage:
114
+ sharedots tui [--coordinator URL]
115
+ sharedots room create [--name NAME] [--coordinator URL]
116
+ sharedots worker join <ROOM_ID> --token <SECRET> [--coordinator URL]
117
+ sharedots worker start [--cpu-limit N] [--memory-limit MB] [--gpu] [--foreground]
118
+ sharedots worker status
119
+ sharedots worker stop
120
+ sharedots worker leave
121
+ sharedots worker logs [--lines N]
122
+ sharedots job submit <job.json> [--coordinator URL] [--room ROOM_ID] [--token SECRET]
123
+ sharedots bench [--size N] [--partitions P] [--coordinator URL] [--room ROOM_ID] [--token SECRET]
124
+ `);
125
+ }
126
+
127
+ async function main(): Promise<void> {
128
+ const { positional, flags } = parseFlags(process.argv.slice(2));
129
+ const [group, sub, ...rest] = positional;
130
+
131
+ if (!group || flags.help || group === "help") {
132
+ printHelp();
133
+ return;
134
+ }
135
+
136
+ const defaultCoord =
137
+ (typeof flags.coordinator === "string" ? flags.coordinator : undefined) ??
138
+ process.env.SHAREDOTS_COORDINATOR ??
139
+ "http://localhost:4000";
140
+
141
+ if (group === "tui") {
142
+ try {
143
+ const tui = await import("@sharedots/tui");
144
+ if (typeof tui.runTui === "function") {
145
+ await tui.runTui({
146
+ initialCoordinator: defaultCoord,
147
+ });
148
+ return;
149
+ }
150
+ } catch {
151
+ // Fallback to relative path lookup
152
+ const repoRoot = resolve(__dirname, "../../..");
153
+ const candidates = [
154
+ join(repoRoot, "apps", "tui", "dist", "index.js"),
155
+ join(process.cwd(), "apps", "tui", "dist", "index.js"),
156
+ ];
157
+ for (const cand of candidates) {
158
+ if (existsSync(cand)) {
159
+ const mod = await import(`file://${cand.replace(/\\/g, "/")}`);
160
+ if (typeof mod.runTui === "function") {
161
+ await mod.runTui({ initialCoordinator: defaultCoord });
162
+ return;
163
+ }
164
+ }
165
+ }
166
+ console.error("Failed to load @sharedots/tui. Please build apps/tui first.");
167
+ process.exit(1);
168
+ }
169
+ return;
170
+ }
171
+
172
+ if (group === "room" && sub === "create") {
173
+ const client = new Sharedots({ coordinator: defaultCoord });
174
+ const name = typeof flags.name === "string" ? flags.name : undefined;
175
+ const room = await client.createRoom(name);
176
+ if (flags.json) {
177
+ console.log(JSON.stringify(room, null, 2));
178
+ } else {
179
+ console.log(`Room created successfully`);
180
+ console.log(` ROOM_ID: ${room.roomId}`);
181
+ console.log(` ROOM_SECRET: ${room.secret}`);
182
+ console.log(` COORDINATOR: ${defaultCoord}`);
183
+ console.log(`\nJoin a worker with:`);
184
+ console.log(` sharedots worker join ${room.roomId} --coordinator ${defaultCoord} --token ${room.secret}`);
185
+ }
186
+ return;
187
+ }
188
+
189
+ if (group === "worker") {
190
+ if (sub === "join") {
191
+ const roomId = rest[0];
192
+ const token =
193
+ (typeof flags.token === "string" ? flags.token : undefined) ?? process.env.SHAREDOTS_TOKEN;
194
+ if (!roomId || !token) {
195
+ console.error("Usage: sharedots worker join <ROOM_ID> --token <SECRET> [--coordinator URL]");
196
+ process.exit(1);
197
+ }
198
+ writeConfig({
199
+ coordinator: defaultCoord,
200
+ roomId,
201
+ token,
202
+ joinedAt: new Date().toISOString(),
203
+ });
204
+ console.log(`Saved worker configuration for room ${roomId} (${defaultCoord})`);
205
+ console.log(`Start the background daemon with: sharedots worker start`);
206
+ return;
207
+ }
208
+
209
+ if (sub === "start") {
210
+ const cfg = readConfig();
211
+ const roomId = (typeof flags.room === "string" ? flags.room : undefined) ?? cfg?.roomId;
212
+ const token = (typeof flags.token === "string" ? flags.token : undefined) ?? cfg?.token;
213
+ const coordinator =
214
+ (typeof flags.coordinator === "string" ? flags.coordinator : undefined) ??
215
+ cfg?.coordinator ??
216
+ defaultCoord;
217
+
218
+ if (!roomId || !token) {
219
+ console.error("Worker is not joined to a room. Run `sharedots worker join <ROOM_ID> --token <SECRET>` first.");
220
+ process.exit(1);
221
+ }
222
+
223
+ const bin = resolveDaemonBinary();
224
+ const home = getHomeDir();
225
+ const args = [
226
+ "--coordinator",
227
+ coordinator,
228
+ "--room-id",
229
+ roomId,
230
+ "--token",
231
+ token,
232
+ "--state-dir",
233
+ join(home, "state"),
234
+ "--work-dir",
235
+ join(home, "work"),
236
+ ];
237
+ if (typeof flags["cpu-limit"] === "string") {
238
+ args.push("--cpu-limit", flags["cpu-limit"]);
239
+ }
240
+ if (typeof flags["memory-limit"] === "string") {
241
+ args.push("--memory-limit", flags["memory-limit"]);
242
+ }
243
+ if (flags.gpu === true) {
244
+ args.push("--gpu");
245
+ }
246
+
247
+ if (flags.foreground === true) {
248
+ const child = spawn(bin, args, { stdio: "inherit" });
249
+ child.on("exit", (code) => process.exit(code ?? 0));
250
+ return;
251
+ }
252
+
253
+ const logFd = openSync(logPath(), "a");
254
+ const child = spawn(bin, args, {
255
+ detached: true,
256
+ stdio: ["ignore", logFd, logFd],
257
+ });
258
+ child.unref();
259
+ closeSync(logFd);
260
+
261
+ if (child.pid) {
262
+ writeFileSync(pidPath(), String(child.pid), "utf8");
263
+ console.log(`Started sharedots-daemon (PID ${child.pid}) for room ${roomId}`);
264
+ console.log(`Logs: ${logPath()}`);
265
+ } else {
266
+ console.error(`Failed to start daemon binary: ${bin}`);
267
+ process.exit(1);
268
+ }
269
+ return;
270
+ }
271
+
272
+ if (sub === "status") {
273
+ const cfg = readConfig();
274
+ const pidFile = pidPath();
275
+ const pid = existsSync(pidFile) ? Number.parseInt(readFileSync(pidFile, "utf8").trim(), 10) : null;
276
+ const running = pid !== null && Number.isFinite(pid) && isProcessRunning(pid);
277
+ const widFile = join(getHomeDir(), "state", "worker_id");
278
+ const workerId = existsSync(widFile) ? readFileSync(widFile, "utf8").trim() : null;
279
+
280
+ console.log(`Worker Status: ${running ? "running" : "stopped"}`);
281
+ if (pid) console.log(` PID: ${pid}`);
282
+ if (workerId) console.log(` Worker ID: ${workerId}`);
283
+ if (cfg) {
284
+ console.log(` Room ID: ${cfg.roomId}`);
285
+ console.log(` Coordinator: ${cfg.coordinator}`);
286
+ }
287
+ return;
288
+ }
289
+
290
+ if (sub === "stop") {
291
+ const pidFile = pidPath();
292
+ if (!existsSync(pidFile)) {
293
+ console.log("Worker daemon is not running.");
294
+ return;
295
+ }
296
+ const pid = Number.parseInt(readFileSync(pidFile, "utf8").trim(), 10);
297
+ if (Number.isFinite(pid) && isProcessRunning(pid)) {
298
+ try {
299
+ process.kill(pid, "SIGTERM");
300
+ } catch {
301
+ // ignore
302
+ }
303
+ console.log(`Stopped worker daemon (PID ${pid})`);
304
+ } else {
305
+ console.log("Worker daemon was already stopped.");
306
+ }
307
+ rmSync(pidFile, { force: true });
308
+ return;
309
+ }
310
+
311
+ if (sub === "leave") {
312
+ const pidFile = pidPath();
313
+ if (existsSync(pidFile)) {
314
+ const pid = Number.parseInt(readFileSync(pidFile, "utf8").trim(), 10);
315
+ if (Number.isFinite(pid) && isProcessRunning(pid)) {
316
+ try {
317
+ process.kill(pid, "SIGTERM");
318
+ } catch {
319
+ // ignore
320
+ }
321
+ }
322
+ rmSync(pidFile, { force: true });
323
+ }
324
+ rmSync(configPath(), { force: true });
325
+ console.log("Worker left room and cleared local room configuration.");
326
+ return;
327
+ }
328
+
329
+ if (sub === "logs") {
330
+ const p = logPath();
331
+ if (!existsSync(p)) {
332
+ console.log("No worker logs found yet.");
333
+ return;
334
+ }
335
+ const lines = readFileSync(p, "utf8").split(/\r?\n/);
336
+ const count = typeof flags.lines === "string" ? Number.parseInt(flags.lines, 10) : 50;
337
+ console.log(lines.slice(-count).join("\n"));
338
+ return;
339
+ }
340
+ }
341
+
342
+ if (group === "job" && sub === "submit") {
343
+ const jobFile = rest[0];
344
+ if (!jobFile || !existsSync(resolve(jobFile))) {
345
+ console.error("Usage: sharedots job submit <job.json> [--coordinator URL] [--room ROOM_ID] [--token SECRET]");
346
+ process.exit(1);
347
+ }
348
+ const cfg = readConfig();
349
+ const coordinator =
350
+ (typeof flags.coordinator === "string" ? flags.coordinator : undefined) ??
351
+ cfg?.coordinator ??
352
+ defaultCoord;
353
+ const roomId =
354
+ (typeof flags.room === "string" ? flags.room : undefined) ??
355
+ process.env.SHAREDOTS_ROOM_ID ??
356
+ cfg?.roomId;
357
+ const token =
358
+ (typeof flags.token === "string" ? flags.token : undefined) ??
359
+ process.env.SHAREDOTS_TOKEN ??
360
+ cfg?.token;
361
+
362
+ if (!roomId || !token) {
363
+ console.error("Missing --room and --token (or join a room first).");
364
+ process.exit(1);
365
+ }
366
+
367
+ const spec = JSON.parse(readFileSync(resolve(jobFile), "utf8"));
368
+ const client = new Sharedots({ coordinator, token });
369
+ const room = await client.connect(roomId);
370
+ const job = await room.submit(spec);
371
+ console.log(`Submitted job ${job.jobId} to room ${roomId}`);
372
+ job.on("progress", (p) => {
373
+ console.log(` progress: ${p.percent}% (${p.completedTasks ?? 0}/${p.totalTasks ?? 0})`);
374
+ });
375
+ const result = await job.result();
376
+ console.log(JSON.stringify(result, null, 2));
377
+ return;
378
+ }
379
+
380
+ if (group === "bench") {
381
+ const repoRoot = resolve(__dirname, "../../..");
382
+ const benchScript = join(repoRoot, "scripts", "bench", "run-matrix-bench.mjs");
383
+ if (!existsSync(benchScript)) {
384
+ console.error(`Benchmark script not found at ${benchScript}`);
385
+ process.exit(1);
386
+ }
387
+ const res = spawnSync(process.execPath, [benchScript, ...process.argv.slice(3)], {
388
+ stdio: "inherit",
389
+ });
390
+ process.exit(res.status ?? 0);
391
+ }
392
+
393
+ console.error(`Unknown command: ${positional.join(" ")}`);
394
+ printHelp();
395
+ process.exit(1);
396
+ }
397
+
398
+ const checkIsMain = () => {
399
+ if (!process.argv[1]) return false;
400
+ const target = resolve(fileURLToPath(import.meta.url)).toLowerCase();
401
+ if (resolve(process.argv[1]).toLowerCase() === target) return true;
402
+ try {
403
+ if (realpathSync(process.argv[1]).toLowerCase() === target) return true;
404
+ } catch {}
405
+ return false;
406
+ };
407
+
408
+ const isMain = checkIsMain();
409
+
410
+ if (isMain) {
411
+ main().catch((err) => {
412
+ console.error(err instanceof Error ? err.message : String(err));
413
+ process.exit(1);
414
+ });
415
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,12 @@
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
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.