@rethinkingstudio/clawpilot 1.1.17 → 2.0.0-beta.1

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.
Files changed (43) hide show
  1. package/dist/commands/install.js +17 -18
  2. package/dist/commands/install.js.map +1 -1
  3. package/dist/commands/openclaw-cli.js +23 -3
  4. package/dist/commands/openclaw-cli.js.map +1 -1
  5. package/dist/commands/pair.js +8 -1
  6. package/dist/commands/pair.js.map +1 -1
  7. package/dist/commands/status.js +3 -0
  8. package/dist/commands/status.js.map +1 -1
  9. package/dist/i18n/index.js +6 -0
  10. package/dist/i18n/index.js.map +1 -1
  11. package/dist/index.js +1 -1
  12. package/dist/index.js.map +1 -1
  13. package/dist/platform/service-manager.d.ts +6 -0
  14. package/dist/platform/service-manager.js +384 -42
  15. package/dist/platform/service-manager.js.map +1 -1
  16. package/package.json +8 -1
  17. package/src/commands/assistant-send.ts +0 -91
  18. package/src/commands/install.ts +0 -128
  19. package/src/commands/local-handlers.ts +0 -533
  20. package/src/commands/openclaw-cli.ts +0 -329
  21. package/src/commands/pair.ts +0 -120
  22. package/src/commands/provider-config.ts +0 -275
  23. package/src/commands/provider-handlers.ts +0 -184
  24. package/src/commands/provider-registry.ts +0 -138
  25. package/src/commands/run.ts +0 -34
  26. package/src/commands/send.ts +0 -42
  27. package/src/commands/session-key.ts +0 -77
  28. package/src/commands/set-token.ts +0 -45
  29. package/src/commands/status.ts +0 -154
  30. package/src/commands/upload.ts +0 -141
  31. package/src/config/config.ts +0 -137
  32. package/src/generated/build-config.ts +0 -1
  33. package/src/i18n/index.ts +0 -179
  34. package/src/index.ts +0 -166
  35. package/src/media/assistant-attachments.ts +0 -205
  36. package/src/media/oss-uploader.ts +0 -306
  37. package/src/platform/service-manager.ts +0 -570
  38. package/src/relay/gateway-client.ts +0 -359
  39. package/src/relay/reconnect.ts +0 -37
  40. package/src/relay/relay-manager.ts +0 -328
  41. package/test-chat.mjs +0 -64
  42. package/test-direct.mjs +0 -171
  43. package/tsconfig.json +0 -16
@@ -1,570 +0,0 @@
1
- import { existsSync, mkdirSync, openSync, readFileSync, unlinkSync, writeFileSync } from "fs";
2
- import { execSync, spawn } from "child_process";
3
- import { homedir } from "os";
4
- import { join } from "path";
5
-
6
- export type ServicePlatform = "macos" | "linux" | "windows" | "unsupported";
7
-
8
- export interface ServiceStatus {
9
- platform: ServicePlatform;
10
- installed: boolean;
11
- running: boolean;
12
- serviceName: string;
13
- manager: string;
14
- servicePath?: string;
15
- logPath: string;
16
- startHint?: string;
17
- }
18
-
19
- const MAC_LABEL = "com.rethinkingstudio.clawpilot";
20
- const MAC_LABEL_OLD = "com.rethinkingstudio.clawai";
21
- const MAC_PLIST_DIR = join(homedir(), "Library", "LaunchAgents");
22
- const MAC_PLIST_PATH = join(MAC_PLIST_DIR, `${MAC_LABEL}.plist`);
23
- const MAC_PLIST_PATH_OLD = join(MAC_PLIST_DIR, `${MAC_LABEL_OLD}.plist`);
24
-
25
- const LINUX_SERVICE_NAME = "clawpilot.service";
26
- const LINUX_SYSTEMD_USER_DIR = join(homedir(), ".config", "systemd", "user");
27
- const LINUX_SERVICE_PATH = join(LINUX_SYSTEMD_USER_DIR, LINUX_SERVICE_NAME);
28
-
29
- const LOG_DIR = join(homedir(), ".clawai");
30
- const LOG_PATH = join(LOG_DIR, "clawpilot.log");
31
- const ERROR_LOG_PATH = join(LOG_DIR, "clawpilot-error.log");
32
- const LINUX_NOHUP_PID_PATH = join(LOG_DIR, "clawpilot.pid");
33
- const LINUX_NOHUP_START_SCRIPT_PATH = join(LOG_DIR, "clawpilot-start.sh");
34
- const WINDOWS_PID_PATH = join(LOG_DIR, "clawpilot-windows.pid");
35
-
36
- function detectPlatform(): ServicePlatform {
37
- if (process.platform === "darwin") return "macos";
38
- if (process.platform === "linux") return "linux";
39
- if (process.platform === "win32") return "windows";
40
- return "unsupported";
41
- }
42
-
43
- function shellEscape(arg: string): string {
44
- return `'${arg.replace(/'/g, `'\\''`)}'`;
45
- }
46
-
47
- function run(command: string, stdio: "pipe" | "inherit" = "pipe"): void {
48
- execSync(command, { stdio });
49
- }
50
-
51
- function commandExists(command: string): boolean {
52
- try {
53
- run(`command -v ${command}`, "pipe");
54
- return true;
55
- } catch {
56
- return false;
57
- }
58
- }
59
-
60
- function getProgramArgs(): string[] {
61
- const nodeBin = process.execPath;
62
- const scriptPath = process.argv[1];
63
- return nodeBin === scriptPath ? [scriptPath, "run"] : [nodeBin, scriptPath, "run"];
64
- }
65
-
66
- function ensureLogDir(): void {
67
- mkdirSync(LOG_DIR, { recursive: true });
68
- }
69
-
70
- function canUseSystemdUser(): boolean {
71
- if (!commandExists("systemctl")) return false;
72
- try {
73
- run("systemctl --user show-environment", "pipe");
74
- return true;
75
- } catch {
76
- return false;
77
- }
78
- }
79
-
80
- function isPidRunning(pid: number): boolean {
81
- try {
82
- process.kill(pid, 0);
83
- return true;
84
- } catch {
85
- return false;
86
- }
87
- }
88
-
89
- function readNohupPid(): number | null {
90
- return readPidFile(LINUX_NOHUP_PID_PATH);
91
- }
92
-
93
- function readWindowsPid(): number | null {
94
- return readPidFile(WINDOWS_PID_PATH);
95
- }
96
-
97
- function readPidFile(path: string): number | null {
98
- if (!existsSync(path)) return null;
99
- try {
100
- const raw = readFileSync(path, "utf-8").trim();
101
- const pid = Number(raw);
102
- return Number.isInteger(pid) && pid > 0 ? pid : null;
103
- } catch {
104
- return null;
105
- }
106
- }
107
-
108
- function removeNohupPidFile(): void {
109
- removePidFile(LINUX_NOHUP_PID_PATH);
110
- }
111
-
112
- function removeWindowsPidFile(): void {
113
- removePidFile(WINDOWS_PID_PATH);
114
- }
115
-
116
- function removePidFile(path: string): void {
117
- if (existsSync(path)) {
118
- unlinkSync(path);
119
- }
120
- }
121
-
122
- function getNohupStartCommand(): string {
123
- return `bash ${shellEscape(LINUX_NOHUP_START_SCRIPT_PATH)}`;
124
- }
125
-
126
- function writeLinuxNohupStartScript(): void {
127
- const args = getProgramArgs().map(shellEscape).join(" ");
128
- const script = `#!/usr/bin/env bash
129
- set -euo pipefail
130
-
131
- mkdir -p ${shellEscape(LOG_DIR)}
132
- if [ -f ${shellEscape(LINUX_NOHUP_PID_PATH)} ]; then
133
- pid="$(cat ${shellEscape(LINUX_NOHUP_PID_PATH)} 2>/dev/null || true)"
134
- if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
135
- echo "clawpilot is already running (pid=$pid)"
136
- exit 0
137
- fi
138
- fi
139
-
140
- nohup ${args} >> ${shellEscape(LOG_PATH)} 2>> ${shellEscape(ERROR_LOG_PATH)} < /dev/null &
141
- echo $! > ${shellEscape(LINUX_NOHUP_PID_PATH)}
142
- echo "clawpilot started in nohup mode (pid=$(cat ${shellEscape(LINUX_NOHUP_PID_PATH)}))"
143
- `;
144
- writeFileSync(LINUX_NOHUP_START_SCRIPT_PATH, script, { encoding: "utf-8", mode: 0o755 });
145
- }
146
-
147
- function installMacService(): boolean {
148
- const argsXml = getProgramArgs().map((arg) => ` <string>${arg}</string>`).join("\n");
149
- const plistContent = `<?xml version="1.0" encoding="UTF-8"?>
150
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
151
- "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
152
- <plist version="1.0">
153
- <dict>
154
- <key>Label</key>
155
- <string>${MAC_LABEL}</string>
156
- <key>ProgramArguments</key>
157
- <array>
158
- ${argsXml}
159
- </array>
160
- <key>RunAtLoad</key>
161
- <true/>
162
- <key>KeepAlive</key>
163
- <true/>
164
- <key>StandardOutPath</key>
165
- <string>${LOG_PATH}</string>
166
- <key>StandardErrorPath</key>
167
- <string>${ERROR_LOG_PATH}</string>
168
- </dict>
169
- </plist>`;
170
-
171
- mkdirSync(MAC_PLIST_DIR, { recursive: true });
172
- ensureLogDir();
173
-
174
- try {
175
- run(`launchctl unload -w "${MAC_PLIST_PATH}"`);
176
- } catch {
177
- // Ignore if not loaded.
178
- }
179
-
180
- writeFileSync(MAC_PLIST_PATH, plistContent, "utf-8");
181
-
182
- try {
183
- run(`launchctl load -w "${MAC_PLIST_PATH}"`, "inherit");
184
- return true;
185
- } catch {
186
- return false;
187
- }
188
- }
189
-
190
- function installLinuxServiceSystemd(): boolean {
191
- mkdirSync(LINUX_SYSTEMD_USER_DIR, { recursive: true });
192
- ensureLogDir();
193
-
194
- const args = getProgramArgs().map(shellEscape).join(" ");
195
- const serviceContent = `[Unit]
196
- Description=ClawPilot relay client
197
- After=network-online.target
198
- Wants=network-online.target
199
-
200
- [Service]
201
- Type=simple
202
- ExecStart=${args}
203
- Restart=always
204
- RestartSec=5
205
- WorkingDirectory=${shellEscape(process.cwd())}
206
- StandardOutput=append:${LOG_PATH}
207
- StandardError=append:${ERROR_LOG_PATH}
208
-
209
- [Install]
210
- WantedBy=default.target
211
- `;
212
-
213
- writeFileSync(LINUX_SERVICE_PATH, serviceContent, "utf-8");
214
- run("systemctl --user daemon-reload", "inherit");
215
- run(`systemctl --user enable --now ${LINUX_SERVICE_NAME}`, "inherit");
216
- return true;
217
- }
218
-
219
- function installLinuxServiceNohup(): boolean {
220
- ensureLogDir();
221
- writeLinuxNohupStartScript();
222
- run(`sh -lc ${shellEscape(getNohupStartCommand())}`, "inherit");
223
- const pid = readNohupPid();
224
- return pid != null && isPidRunning(pid);
225
- }
226
-
227
- function installLinuxService(): boolean {
228
- try {
229
- if (installLinuxServiceNohup()) {
230
- return true;
231
- }
232
- } catch {
233
- // Fall back to systemd below.
234
- }
235
-
236
- if (canUseSystemdUser()) {
237
- try {
238
- return installLinuxServiceSystemd();
239
- } catch {
240
- // Give up below.
241
- }
242
- }
243
-
244
- return false;
245
- }
246
-
247
- function installWindowsService(): boolean {
248
- ensureLogDir();
249
-
250
- const pid = readWindowsPid();
251
- if (pid != null && isPidRunning(pid)) {
252
- return true;
253
- }
254
- if (pid != null) {
255
- removeWindowsPidFile();
256
- }
257
-
258
- const args = getProgramArgs();
259
- const stdoutFd = openSync(LOG_PATH, "a");
260
- const stderrFd = openSync(ERROR_LOG_PATH, "a");
261
- const child = spawn(args[0], args.slice(1), {
262
- detached: true,
263
- stdio: ["ignore", stdoutFd, stderrFd],
264
- windowsHide: true,
265
- });
266
-
267
- child.unref();
268
- writeFileSync(WINDOWS_PID_PATH, `${child.pid}`, "utf-8");
269
- return isPidRunning(child.pid ?? -1);
270
- }
271
-
272
- function uninstallMacArtifacts(): boolean {
273
- let changed = false;
274
- try {
275
- run(`launchctl unload -w "${MAC_PLIST_PATH}"`);
276
- changed = true;
277
- } catch {
278
- // ignore
279
- }
280
- if (existsSync(MAC_PLIST_PATH)) {
281
- unlinkSync(MAC_PLIST_PATH);
282
- changed = true;
283
- }
284
- try {
285
- run(`launchctl unload -w "${MAC_PLIST_PATH_OLD}"`);
286
- changed = true;
287
- } catch {
288
- // ignore
289
- }
290
- if (existsSync(MAC_PLIST_PATH_OLD)) {
291
- unlinkSync(MAC_PLIST_PATH_OLD);
292
- changed = true;
293
- }
294
- return changed;
295
- }
296
-
297
- function uninstallLinuxArtifacts(removeFile: boolean): boolean {
298
- let changed = false;
299
-
300
- if (canUseSystemdUser()) {
301
- try {
302
- run(`systemctl --user stop ${LINUX_SERVICE_NAME}`);
303
- changed = true;
304
- } catch {
305
- // ignore
306
- }
307
- try {
308
- run(`systemctl --user disable ${LINUX_SERVICE_NAME}`);
309
- changed = true;
310
- } catch {
311
- // ignore
312
- }
313
- try {
314
- run("systemctl --user daemon-reload");
315
- } catch {
316
- // ignore
317
- }
318
- }
319
-
320
- const nohupPid = readNohupPid();
321
- if (nohupPid != null) {
322
- try {
323
- process.kill(nohupPid, "SIGTERM");
324
- changed = true;
325
- } catch {
326
- // ignore
327
- }
328
- removeNohupPidFile();
329
- changed = true;
330
- }
331
-
332
- if (removeFile && existsSync(LINUX_SERVICE_PATH)) {
333
- unlinkSync(LINUX_SERVICE_PATH);
334
- changed = true;
335
- }
336
- if (removeFile && existsSync(LINUX_NOHUP_START_SCRIPT_PATH)) {
337
- unlinkSync(LINUX_NOHUP_START_SCRIPT_PATH);
338
- changed = true;
339
- }
340
-
341
- return changed;
342
- }
343
-
344
- function restartMacService(): boolean {
345
- return installMacService();
346
- }
347
-
348
- function restartLinuxService(): boolean {
349
- if (canUseSystemdUser() && existsSync(LINUX_SERVICE_PATH)) {
350
- try {
351
- run("systemctl --user daemon-reload", "inherit");
352
- run(`systemctl --user restart ${LINUX_SERVICE_NAME}`, "inherit");
353
- return true;
354
- } catch {
355
- // Fall back to nohup restart below.
356
- }
357
- }
358
-
359
- uninstallLinuxArtifacts(false);
360
- try {
361
- return installLinuxServiceNohup();
362
- } catch {
363
- return false;
364
- }
365
- }
366
-
367
- function restartWindowsService(): boolean {
368
- uninstallWindowsArtifacts(false);
369
- try {
370
- return installWindowsService();
371
- } catch {
372
- return false;
373
- }
374
- }
375
-
376
- function uninstallWindowsArtifacts(removeFile: boolean): boolean {
377
- let changed = false;
378
- const pid = readWindowsPid();
379
- if (pid != null) {
380
- try {
381
- process.kill(pid, "SIGTERM");
382
- changed = true;
383
- } catch {
384
- // ignore
385
- }
386
- removeWindowsPidFile();
387
- changed = true;
388
- }
389
-
390
- if (removeFile && existsSync(WINDOWS_PID_PATH)) {
391
- unlinkSync(WINDOWS_PID_PATH);
392
- changed = true;
393
- }
394
-
395
- return changed;
396
- }
397
-
398
- export function getServicePlatform(): ServicePlatform {
399
- return detectPlatform();
400
- }
401
-
402
- export function installService(): boolean {
403
- switch (detectPlatform()) {
404
- case "macos":
405
- return installMacService();
406
- case "linux":
407
- return installLinuxService();
408
- case "windows":
409
- return installWindowsService();
410
- default:
411
- return false;
412
- }
413
- }
414
-
415
- export function restartService(): boolean {
416
- switch (detectPlatform()) {
417
- case "macos":
418
- return restartMacService();
419
- case "linux":
420
- return restartLinuxService();
421
- case "windows":
422
- return restartWindowsService();
423
- default:
424
- return false;
425
- }
426
- }
427
-
428
- export function stopService(): boolean {
429
- switch (detectPlatform()) {
430
- case "macos":
431
- return uninstallMacArtifacts();
432
- case "linux":
433
- return uninstallLinuxArtifacts(false);
434
- case "windows":
435
- return uninstallWindowsArtifacts(false);
436
- default:
437
- return false;
438
- }
439
- }
440
-
441
- export function uninstallService(): boolean {
442
- switch (detectPlatform()) {
443
- case "macos":
444
- return uninstallMacArtifacts();
445
- case "linux":
446
- return uninstallLinuxArtifacts(true);
447
- case "windows":
448
- return uninstallWindowsArtifacts(true);
449
- default:
450
- return false;
451
- }
452
- }
453
-
454
- export function getServiceStatus(): ServiceStatus {
455
- const platform = detectPlatform();
456
-
457
- if (platform === "macos") {
458
- let running = false;
459
- try {
460
- run(`launchctl list ${MAC_LABEL}`);
461
- running = true;
462
- } catch {
463
- running = false;
464
- }
465
- return {
466
- platform,
467
- installed: existsSync(MAC_PLIST_PATH),
468
- running,
469
- serviceName: MAC_LABEL,
470
- manager: "launchd",
471
- servicePath: MAC_PLIST_PATH,
472
- logPath: LOG_PATH,
473
- startHint: `launchctl start ${MAC_LABEL}`,
474
- };
475
- }
476
-
477
- if (platform === "linux") {
478
- const pid = readNohupPid();
479
- const hasNohupArtifacts = pid != null || existsSync(LINUX_NOHUP_START_SCRIPT_PATH);
480
- const running = pid != null && isPidRunning(pid);
481
- if (!running && pid != null) {
482
- removeNohupPidFile();
483
- }
484
-
485
- if (running || (hasNohupArtifacts && !canUseSystemdUser())) {
486
- return {
487
- platform,
488
- installed: hasNohupArtifacts,
489
- running,
490
- serviceName: "clawpilot (nohup)",
491
- manager: "nohup",
492
- servicePath: existsSync(LINUX_NOHUP_START_SCRIPT_PATH) ? LINUX_NOHUP_START_SCRIPT_PATH : undefined,
493
- logPath: LOG_PATH,
494
- startHint: getNohupStartCommand(),
495
- };
496
- }
497
-
498
- const hasSystemdServiceFile = existsSync(LINUX_SERVICE_PATH);
499
- if (hasSystemdServiceFile) {
500
- let systemdRunning = false;
501
- if (canUseSystemdUser()) {
502
- try {
503
- run(`systemctl --user is-active --quiet ${LINUX_SERVICE_NAME}`);
504
- systemdRunning = true;
505
- } catch {
506
- systemdRunning = false;
507
- }
508
- }
509
- return {
510
- platform,
511
- installed: true,
512
- running: systemdRunning,
513
- serviceName: LINUX_SERVICE_NAME,
514
- manager: "systemd",
515
- servicePath: LINUX_SERVICE_PATH,
516
- logPath: LOG_PATH,
517
- startHint: `systemctl --user start ${LINUX_SERVICE_NAME}`,
518
- };
519
- }
520
-
521
- return {
522
- platform,
523
- installed: hasNohupArtifacts,
524
- running,
525
- serviceName: "clawpilot (nohup)",
526
- manager: "nohup",
527
- servicePath: existsSync(LINUX_NOHUP_START_SCRIPT_PATH) ? LINUX_NOHUP_START_SCRIPT_PATH : undefined,
528
- logPath: LOG_PATH,
529
- startHint: getNohupStartCommand(),
530
- };
531
- }
532
-
533
- if (platform === "windows") {
534
- const pid = readWindowsPid();
535
- const running = pid != null && isPidRunning(pid);
536
- if (!running && pid != null) {
537
- removeWindowsPidFile();
538
- }
539
-
540
- return {
541
- platform,
542
- installed: pid != null,
543
- running,
544
- serviceName: "clawpilot (detached)",
545
- manager: "windows-detached",
546
- servicePath: existsSync(WINDOWS_PID_PATH) ? WINDOWS_PID_PATH : undefined,
547
- logPath: LOG_PATH,
548
- startHint: "clawpilot install",
549
- };
550
- }
551
-
552
- return {
553
- platform,
554
- installed: false,
555
- running: false,
556
- serviceName: "",
557
- manager: "unsupported",
558
- logPath: LOG_PATH,
559
- };
560
- }
561
-
562
- export const servicePaths = {
563
- logPath: LOG_PATH,
564
- errorLogPath: ERROR_LOG_PATH,
565
- macPlistPath: MAC_PLIST_PATH,
566
- linuxServicePath: LINUX_SERVICE_PATH,
567
- linuxNohupPidPath: LINUX_NOHUP_PID_PATH,
568
- linuxNohupStartScriptPath: LINUX_NOHUP_START_SCRIPT_PATH,
569
- windowsPidPath: WINDOWS_PID_PATH,
570
- };