@yefengr/remote-pi 0.7.3 → 0.7.5
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/README.md +81 -586
- package/dist/actions/handlers.d.ts +1 -1
- package/dist/actions/handlers.js +2 -1
- package/dist/actions/handlers.js.map +1 -1
- package/dist/bin/supervisord.js +4 -5
- package/dist/bin/supervisord.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +2 -2
- package/dist/daemon/cli-links.d.ts +30 -0
- package/dist/daemon/cli-links.js +134 -0
- package/dist/daemon/cli-links.js.map +1 -0
- package/dist/daemon/commands.d.ts +27 -0
- package/dist/daemon/commands.js +295 -0
- package/dist/daemon/commands.js.map +1 -0
- package/dist/daemon/control_protocol.d.ts +53 -31
- package/dist/daemon/control_protocol.js +8 -31
- package/dist/daemon/control_protocol.js.map +1 -1
- package/dist/daemon/cron_log.d.ts +2 -23
- package/dist/daemon/cron_log.js +10 -25
- package/dist/daemon/cron_log.js.map +1 -1
- package/dist/daemon/cron_registry.d.ts +3 -40
- package/dist/daemon/cron_registry.js +58 -103
- package/dist/daemon/cron_registry.js.map +1 -1
- package/dist/daemon/install-runtime.d.ts +10 -0
- package/dist/daemon/install-runtime.js +81 -0
- package/dist/daemon/install-runtime.js.map +1 -0
- package/dist/daemon/install.d.ts +3 -63
- package/dist/daemon/install.js +5 -289
- package/dist/daemon/install.js.map +1 -1
- package/dist/daemon/preflight.d.ts +51 -0
- package/dist/daemon/preflight.js +136 -0
- package/dist/daemon/preflight.js.map +1 -0
- package/dist/daemon/registry.d.ts +33 -45
- package/dist/daemon/registry.js +171 -117
- package/dist/daemon/registry.js.map +1 -1
- package/dist/daemon/rpc_child.d.ts +92 -146
- package/dist/daemon/rpc_child.js +336 -263
- package/dist/daemon/rpc_child.js.map +1 -1
- package/dist/daemon/status.d.ts +45 -0
- package/dist/daemon/status.js +87 -0
- package/dist/daemon/status.js.map +1 -0
- package/dist/daemon/supervisor-ipc.d.ts +2 -0
- package/dist/daemon/supervisor-ipc.js +20 -0
- package/dist/daemon/supervisor-ipc.js.map +1 -0
- package/dist/daemon/supervisor.d.ts +48 -71
- package/dist/daemon/supervisor.js +430 -420
- package/dist/daemon/supervisor.js.map +1 -1
- package/dist/extension_ui_bridge.d.ts +4 -3
- package/dist/extension_ui_bridge.js +10 -0
- package/dist/extension_ui_bridge.js.map +1 -1
- package/dist/index.d.ts +25 -217
- package/dist/index.js +527 -5504
- package/dist/index.js.map +1 -1
- package/dist/pairing/crypto.d.ts +8 -1
- package/dist/pairing/crypto.js +56 -6
- package/dist/pairing/crypto.js.map +1 -1
- package/dist/pairing/owner_storage.d.ts +42 -0
- package/dist/pairing/owner_storage.js +207 -0
- package/dist/pairing/owner_storage.js.map +1 -0
- package/dist/pairing/qr.d.ts +3 -42
- package/dist/pairing/qr.js +9 -59
- package/dist/pairing/qr.js.map +1 -1
- package/dist/pairing/storage.d.ts +3 -45
- package/dist/pairing/storage.js +10 -223
- package/dist/pairing/storage.js.map +1 -1
- package/dist/protocol/types.d.ts +1 -1
- package/dist/protocol/v2/schemas.d.ts +1 -1
- package/dist/protocol/v2/schemas.js +1 -1
- package/dist/protocol/v2/schemas.js.map +1 -1
- package/dist/runtime/owner_router.d.ts +16 -0
- package/dist/runtime/owner_router.js +37 -0
- package/dist/runtime/owner_router.js.map +1 -0
- package/dist/session/ipc.d.ts +1 -22
- package/dist/session/ipc.js +4 -11
- package/dist/session/ipc.js.map +1 -1
- package/dist/session/local_config.d.ts +4 -47
- package/dist/session/local_config.js +19 -101
- package/dist/session/local_config.js.map +1 -1
- package/dist/timeline/v2_service.d.ts +6 -0
- package/dist/timeline/v2_service.js +20 -2
- package/dist/timeline/v2_service.js.map +1 -1
- package/dist/transport/peer_channel.d.ts +25 -39
- package/dist/transport/peer_channel.js +74 -131
- package/dist/transport/peer_channel.js.map +1 -1
- package/dist/transport/relay_client.d.ts +26 -70
- package/dist/transport/relay_client.js +37 -106
- package/dist/transport/relay_client.js.map +1 -1
- package/docs/daemon.md +91 -207
- package/package.json +21 -17
- package/dist/daemon/id.d.ts +0 -24
- package/dist/daemon/id.js +0 -36
- package/dist/daemon/id.js.map +0 -1
- package/dist/mcp/mesh_result.d.ts +0 -10
- package/dist/mcp/mesh_result.js +0 -42
- package/dist/mcp/mesh_result.js.map +0 -1
- package/dist/mcp/mesh_server.d.ts +0 -16
- package/dist/mcp/mesh_server.js +0 -327
- package/dist/mcp/mesh_server.js.map +0 -1
- package/dist/mesh/canonical.d.ts +0 -30
- package/dist/mesh/canonical.js +0 -61
- package/dist/mesh/canonical.js.map +0 -1
- package/dist/mesh/client.d.ts +0 -18
- package/dist/mesh/client.js +0 -125
- package/dist/mesh/client.js.map +0 -1
- package/dist/mesh/encoding.d.ts +0 -38
- package/dist/mesh/encoding.js +0 -216
- package/dist/mesh/encoding.js.map +0 -1
- package/dist/mesh/self_revoke.d.ts +0 -73
- package/dist/mesh/self_revoke.js +0 -401
- package/dist/mesh/self_revoke.js.map +0 -1
- package/dist/mesh/siblings.d.ts +0 -49
- package/dist/mesh/siblings.js +0 -159
- package/dist/mesh/siblings.js.map +0 -1
- package/dist/mesh/types.d.ts +0 -34
- package/dist/mesh/types.js +0 -11
- package/dist/mesh/types.js.map +0 -1
- package/dist/mesh/verify.d.ts +0 -17
- package/dist/mesh/verify.js +0 -86
- package/dist/mesh/verify.js.map +0 -1
- package/dist/rooms.d.ts +0 -29
- package/dist/rooms.js +0 -57
- package/dist/rooms.js.map +0 -1
- package/dist/session/bridge.d.ts +0 -37
- package/dist/session/bridge.js +0 -130
- package/dist/session/bridge.js.map +0 -1
- package/dist/session/broker.d.ts +0 -189
- package/dist/session/broker.js +0 -507
- package/dist/session/broker.js.map +0 -1
- package/dist/session/broker_remote.d.ts +0 -74
- package/dist/session/broker_remote.js +0 -583
- package/dist/session/broker_remote.js.map +0 -1
- package/dist/session/cwd_lock.d.ts +0 -33
- package/dist/session/cwd_lock.js +0 -126
- package/dist/session/cwd_lock.js.map +0 -1
- package/dist/session/envelope.d.ts +0 -33
- package/dist/session/envelope.js +0 -117
- package/dist/session/envelope.js.map +0 -1
- package/dist/session/global_config.d.ts +0 -33
- package/dist/session/global_config.js +0 -73
- package/dist/session/global_config.js.map +0 -1
- package/dist/session/leader_election.d.ts +0 -32
- package/dist/session/leader_election.js +0 -106
- package/dist/session/leader_election.js.map +0 -1
- package/dist/session/mesh_node.d.ts +0 -116
- package/dist/session/mesh_node.js +0 -573
- package/dist/session/mesh_node.js.map +0 -1
- package/dist/session/peer.d.ts +0 -139
- package/dist/session/peer.js +0 -451
- package/dist/session/peer.js.map +0 -1
- package/dist/session/peer_inventory.d.ts +0 -13
- package/dist/session/peer_inventory.js +0 -48
- package/dist/session/peer_inventory.js.map +0 -1
- package/dist/session/peer_limits.d.ts +0 -9
- package/dist/session/peer_limits.js +0 -21
- package/dist/session/peer_limits.js.map +0 -1
- package/dist/session/setup_wizard.d.ts +0 -39
- package/dist/session/setup_wizard.js +0 -63
- package/dist/session/setup_wizard.js.map +0 -1
- package/dist/session/tools.d.ts +0 -24
- package/dist/session/tools.js +0 -252
- package/dist/session/tools.js.map +0 -1
- package/dist/session/wizard.d.ts +0 -13
- package/dist/session/wizard.js +0 -20
- package/dist/session/wizard.js.map +0 -1
- package/dist/transport/pi_forward_client.d.ts +0 -29
- package/dist/transport/pi_forward_client.js +0 -62
- package/dist/transport/pi_forward_client.js.map +0 -1
- package/dist/ui/footer.d.ts +0 -32
- package/dist/ui/footer.js +0 -34
- package/dist/ui/footer.js.map +0 -1
- package/skills/agent-network/SKILL.md +0 -310
|
@@ -114,7 +114,7 @@ type ThinkingSetMsg = Extract<ClientMessage, {
|
|
|
114
114
|
type ListModelsMsg = Extract<ClientMessage, {
|
|
115
115
|
type: "list_models";
|
|
116
116
|
}>;
|
|
117
|
-
export declare function handleSessionCompact(ctx: ActionCtx | null, sender: ActionReplySender, msg: SessionCompactMsg): void;
|
|
117
|
+
export declare function handleSessionCompact(ctx: ActionCtx | null, sender: ActionReplySender, msg: SessionCompactMsg, onSettled?: () => void): void;
|
|
118
118
|
export declare function handleSessionNew(ctx: ActionCtx | null, sender: ActionReplySender, msg: SessionNewMsg, onReplaced?: (freshCtx: ActionCtx) => void): Promise<boolean>;
|
|
119
119
|
export declare function handleThinkingSet(pi: ActionPi, sender: ActionReplySender, msg: ThinkingSetMsg): void;
|
|
120
120
|
export declare function handleModelSet(pi: ActionPi, ctx: ActionCtx | null, reg: ActionModelRegistry, sender: ActionReplySender, msg: ModelSetMsg, onPersist?: (provider: string, modelId: string) => void): Promise<void>;
|
package/dist/actions/handlers.js
CHANGED
|
@@ -65,7 +65,7 @@ async function runAsync(sender, msg, action, body) {
|
|
|
65
65
|
return false;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
export function handleSessionCompact(ctx, sender, msg) {
|
|
68
|
+
export function handleSessionCompact(ctx, sender, msg, onSettled) {
|
|
69
69
|
runSync(sender, msg, "session_compact", () => {
|
|
70
70
|
if (!ctx?.compact)
|
|
71
71
|
throw new Error("compact unavailable (no active session ctx)");
|
|
@@ -75,6 +75,7 @@ export function handleSessionCompact(ctx, sender, msg) {
|
|
|
75
75
|
// compaction prompt (best-effort: the model writes the summary).
|
|
76
76
|
ctx.compact({
|
|
77
77
|
customInstructions: "Always write the compaction summary in English, even if the conversation is in another language.",
|
|
78
|
+
...(onSettled ? { onComplete: onSettled, onError: onSettled } : {}),
|
|
78
79
|
});
|
|
79
80
|
});
|
|
80
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/actions/handlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AA2FH;wDACwD;AACxD,MAAM,UAAU,aAAa,CAAC,KAAiB;IAC7C,OAAO;QACL,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,QAAQ,EAAE,KAAK,CA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AAO,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;SACpD,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
package/dist/bin/supervisord.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*
|
|
11
11
|
* Once running, it:
|
|
12
12
|
* - Reads `~/.pi/remote/daemons.json`
|
|
13
|
-
* - Spawns `pi --mode rpc
|
|
13
|
+
* - Spawns configured `pi --mode rpc` children per entry
|
|
14
14
|
* - Listens on `~/.pi/remote/supervisor.sock` for CLI control requests
|
|
15
15
|
* - Restarts crashed children with exponential backoff
|
|
16
16
|
*
|
|
@@ -55,15 +55,14 @@ async function main() {
|
|
|
55
55
|
"This binary takes no arguments. Run `pi-supervisord --help`.\n");
|
|
56
56
|
process.exit(2);
|
|
57
57
|
}
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
// build; the extension is the sibling `dist/index.js`.
|
|
58
|
+
// Retained only for Supervisor constructor compatibility. Pi discovers the
|
|
59
|
+
// configured extension itself; the child process never receives `-e`.
|
|
61
60
|
const here = fileURLToPath(import.meta.url);
|
|
62
61
|
const distRoot = dirname(dirname(here)); // dist/bin → dist
|
|
63
62
|
const extensionPath = join(distRoot, "index.js");
|
|
64
63
|
const supervisor = new Supervisor({ extensionPath });
|
|
65
64
|
await supervisor.start();
|
|
66
|
-
process.stderr.write(
|
|
65
|
+
process.stderr.write("[pi-supervisord] up — UDS: ~/.pi/remote/supervisor.sock\n");
|
|
67
66
|
const shutdown = async (signal) => {
|
|
68
67
|
process.stderr.write(`[pi-supervisord] received ${signal}, shutting down\n`);
|
|
69
68
|
await supervisor.stop();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supervisord.js","sourceRoot":"","sources":["../../src/bin/supervisord.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,aAAa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,EAAE,CAAC;IACzB,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,2DAA2D,CAC5D,CAAC;IAEF,MAAM,QAAQ,GAAG,KAAK,EAAE,MAAc,EAAE,EAAE;QACxC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA6B,MAAM,mBAAmB,CAAC,CAAC;QAC7E,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC;QACxB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC;IACF,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,KAAK,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;IACtD,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;AACtD,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,yEAAyE;IACzE,0EAA0E;IAC1E,sEAAsE;IACtE,IAAI,GAAG,YAAY,6BAA6B,EAAE,CAAC;QACjD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC;QAC1D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,2BAA2B,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACjE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/config.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export declare function isWebSocketScheme(url: string): boolean;
|
|
|
39
39
|
/**
|
|
40
40
|
* Converts an http(s):// URL to the corresponding ws(s):// form. Used by
|
|
41
41
|
* the transport layer right before opening the WebSocket — config storage
|
|
42
|
-
* and the
|
|
42
|
+
* and the Relay client both stay on http(s)://.
|
|
43
43
|
*
|
|
44
44
|
* https://host → wss://host
|
|
45
45
|
* http://host → ws://host
|
package/dist/config.js
CHANGED
|
@@ -8,7 +8,7 @@ const CONFIG_FILE = path.join(CONFIG_DIR, "config.json");
|
|
|
8
8
|
* to ws(s):// happens at the transport layer (see `toWebSocketUrl`). The
|
|
9
9
|
* community relay's reverse proxy maps `:443 → :3000` (the WS port), so the
|
|
10
10
|
* URL has no explicit port and the WebSocket upgrade rides on the same TLS
|
|
11
|
-
* connection as the HTTPS
|
|
11
|
+
* connection as the HTTPS endpoint used by the Relay client.
|
|
12
12
|
*/
|
|
13
13
|
const kLegacyDefaultRelayUrl = "https://relay-rp1.jacobmoura.work";
|
|
14
14
|
export const kDefaultRelayUrl = "https://relay-pi.yefengr.cn";
|
|
@@ -87,7 +87,7 @@ export function isWebSocketScheme(url) {
|
|
|
87
87
|
/**
|
|
88
88
|
* Converts an http(s):// URL to the corresponding ws(s):// form. Used by
|
|
89
89
|
* the transport layer right before opening the WebSocket — config storage
|
|
90
|
-
* and the
|
|
90
|
+
* and the Relay client both stay on http(s)://.
|
|
91
91
|
*
|
|
92
92
|
* https://host → wss://host
|
|
93
93
|
* http://host → ws://host
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface LinkBinariesResult {
|
|
2
|
+
binDir: string;
|
|
3
|
+
links: Array<{
|
|
4
|
+
name: string;
|
|
5
|
+
path: string;
|
|
6
|
+
target: string;
|
|
7
|
+
}>;
|
|
8
|
+
onPath: boolean;
|
|
9
|
+
log: string[];
|
|
10
|
+
}
|
|
11
|
+
export declare function userLocalBinDir(home?: string): string;
|
|
12
|
+
export declare function isOnPath(dir: string, envPath?: string): boolean;
|
|
13
|
+
export declare function linkCliBinaries(home?: string, paths?: {
|
|
14
|
+
remotePi?: string;
|
|
15
|
+
supervisord?: string;
|
|
16
|
+
}, opts?: {
|
|
17
|
+
node?: string;
|
|
18
|
+
mutatePath?: boolean;
|
|
19
|
+
}): LinkBinariesResult;
|
|
20
|
+
export declare function buildCmdShim(node: string, target: string): string;
|
|
21
|
+
export interface UnlinkBinariesResult {
|
|
22
|
+
binDir: string;
|
|
23
|
+
removed: Array<{
|
|
24
|
+
name: string;
|
|
25
|
+
path: string;
|
|
26
|
+
existed: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
log: string[];
|
|
29
|
+
}
|
|
30
|
+
export declare function unlinkCliBinaries(home?: string): UnlinkBinariesResult;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { delimiter, join } from "node:path";
|
|
2
|
+
import { chmodSync, existsSync, lstatSync, mkdirSync, readlinkSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import { homedir, platform } from "node:os";
|
|
5
|
+
import { findNodeBinary, findRemotePiScript, findSupervisorScript } from "./install.js";
|
|
6
|
+
export function userLocalBinDir(home = homedir()) {
|
|
7
|
+
return join(home, ".local", "bin");
|
|
8
|
+
}
|
|
9
|
+
export function isOnPath(dir, envPath = process.env["PATH"] ?? "") {
|
|
10
|
+
const target = dir.replace(/\/+$/, "");
|
|
11
|
+
return envPath.split(delimiter).some((entry) => entry.replace(/\/+$/, "") === target);
|
|
12
|
+
}
|
|
13
|
+
export function linkCliBinaries(home = homedir(), paths = {}, opts = {}) {
|
|
14
|
+
const binDir = userLocalBinDir(home);
|
|
15
|
+
if (platform() === "win32")
|
|
16
|
+
return linkCliBinariesWindows(binDir, paths, opts);
|
|
17
|
+
const log = [];
|
|
18
|
+
mkdirSync(binDir, { recursive: true });
|
|
19
|
+
log.push(`ensured ${binDir}`);
|
|
20
|
+
const remotePi = paths.remotePi ?? findRemotePiScript();
|
|
21
|
+
const supervisord = paths.supervisord ?? findSupervisorScript();
|
|
22
|
+
assertScriptsExist(remotePi, supervisord);
|
|
23
|
+
try {
|
|
24
|
+
chmodSync(remotePi, 0o755);
|
|
25
|
+
}
|
|
26
|
+
catch { /* best-effort */ }
|
|
27
|
+
try {
|
|
28
|
+
chmodSync(supervisord, 0o755);
|
|
29
|
+
}
|
|
30
|
+
catch { /* best-effort */ }
|
|
31
|
+
const links = [
|
|
32
|
+
{ name: "remote-pi", path: join(binDir, "remote-pi"), target: remotePi },
|
|
33
|
+
{ name: "pi-supervisord", path: join(binDir, "pi-supervisord"), target: supervisord },
|
|
34
|
+
];
|
|
35
|
+
for (const link of links)
|
|
36
|
+
replaceSymlink(link.path, link.target, log);
|
|
37
|
+
const onPath = isOnPath(binDir);
|
|
38
|
+
if (!onPath)
|
|
39
|
+
log.push(`WARNING: ${binDir} is not on $PATH. Add this line to your shell rc: export PATH="$HOME/.local/bin:$PATH"`);
|
|
40
|
+
return { binDir, links, onPath, log };
|
|
41
|
+
}
|
|
42
|
+
function assertScriptsExist(remotePi, supervisord) {
|
|
43
|
+
if (!existsSync(remotePi))
|
|
44
|
+
throw new Error(`remote-pi script not found at ${remotePi}. Run \`pnpm build\` (dev) or reinstall the extension.`);
|
|
45
|
+
if (!existsSync(supervisord))
|
|
46
|
+
throw new Error(`supervisor script not found at ${supervisord}. Run \`pnpm build\` (dev) or reinstall the extension.`);
|
|
47
|
+
}
|
|
48
|
+
function linkCliBinariesWindows(binDir, paths, opts) {
|
|
49
|
+
const log = [];
|
|
50
|
+
mkdirSync(binDir, { recursive: true });
|
|
51
|
+
log.push(`ensured ${binDir}`);
|
|
52
|
+
const node = opts.node ?? findNodeBinary();
|
|
53
|
+
const remotePi = paths.remotePi ?? findRemotePiScript();
|
|
54
|
+
const supervisord = paths.supervisord ?? findSupervisorScript();
|
|
55
|
+
assertScriptsExist(remotePi, supervisord);
|
|
56
|
+
const links = [
|
|
57
|
+
{ name: "remote-pi.cmd", path: join(binDir, "remote-pi.cmd"), target: remotePi },
|
|
58
|
+
{ name: "pi-supervisord.cmd", path: join(binDir, "pi-supervisord.cmd"), target: supervisord },
|
|
59
|
+
];
|
|
60
|
+
for (const link of links) {
|
|
61
|
+
writeFileSync(link.path, buildCmdShim(node, link.target));
|
|
62
|
+
log.push(`wrote ${link.path}`);
|
|
63
|
+
}
|
|
64
|
+
const onPath = isOnPath(binDir);
|
|
65
|
+
if (!onPath && opts.mutatePath !== false) {
|
|
66
|
+
try {
|
|
67
|
+
addUserPath(binDir);
|
|
68
|
+
log.push(`added ${binDir} to your user PATH — open a NEW terminal for \`remote-pi\` to resolve.`);
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
log.push(`WARNING: ${binDir} is not on PATH and auto-add failed (${String(error)}). Add it manually: setx PATH "%PATH%;${binDir}"`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return { binDir, links, onPath, log };
|
|
75
|
+
}
|
|
76
|
+
export function buildCmdShim(node, target) {
|
|
77
|
+
return `@echo off\r\n"${node}" "${target}" %*\r\n`;
|
|
78
|
+
}
|
|
79
|
+
function addUserPath(dir) {
|
|
80
|
+
const literal = `'${dir.replace(/'/g, "''")}'`;
|
|
81
|
+
execFileSync("powershell", [
|
|
82
|
+
"-NoProfile", "-NonInteractive", "-Command",
|
|
83
|
+
`$d = ${literal}; ` +
|
|
84
|
+
"$p = [Environment]::GetEnvironmentVariable('Path','User'); " +
|
|
85
|
+
"if (-not $p) { $p = '' }; " +
|
|
86
|
+
"$parts = $p.Split(';') | Where-Object { $_ -ne '' }; " +
|
|
87
|
+
"if ($parts -notcontains $d) { [Environment]::SetEnvironmentVariable('Path', (($parts + $d) -join ';'), 'User') }",
|
|
88
|
+
], { stdio: ["ignore", "pipe", "pipe"] });
|
|
89
|
+
}
|
|
90
|
+
export function unlinkCliBinaries(home = homedir()) {
|
|
91
|
+
const binDir = userLocalBinDir(home);
|
|
92
|
+
const log = [];
|
|
93
|
+
const names = platform() === "win32" ? ["remote-pi.cmd", "pi-supervisord.cmd"] : ["remote-pi", "pi-supervisord"];
|
|
94
|
+
const removed = [];
|
|
95
|
+
for (const name of names) {
|
|
96
|
+
const path = join(binDir, name);
|
|
97
|
+
let existed = false;
|
|
98
|
+
try {
|
|
99
|
+
lstatSync(path);
|
|
100
|
+
existed = true;
|
|
101
|
+
}
|
|
102
|
+
catch { /* absent */ }
|
|
103
|
+
if (existed) {
|
|
104
|
+
try {
|
|
105
|
+
unlinkSync(path);
|
|
106
|
+
log.push(`removed ${path}`);
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
log.push(`failed to remove ${path}: ${String(error)}`);
|
|
110
|
+
existed = false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
removed.push({ name, path, existed });
|
|
114
|
+
}
|
|
115
|
+
return { binDir, removed, log };
|
|
116
|
+
}
|
|
117
|
+
function replaceSymlink(linkPath, target, log) {
|
|
118
|
+
let existing = null;
|
|
119
|
+
try {
|
|
120
|
+
existing = readlinkSync(linkPath);
|
|
121
|
+
}
|
|
122
|
+
catch { /* not a symlink */ }
|
|
123
|
+
if (existing === target) {
|
|
124
|
+
log.push(`symlink ${linkPath} → ${target} (unchanged)`);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
unlinkSync(linkPath);
|
|
129
|
+
}
|
|
130
|
+
catch { /* absent */ }
|
|
131
|
+
symlinkSync(target, linkPath);
|
|
132
|
+
log.push(`symlink ${linkPath} → ${target}`);
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=cli-links.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-links.js","sourceRoot":"","sources":["../../src/daemon/cli-links.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC5H,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC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ed25519Keypair } from "../pairing/crypto.js";
|
|
3
|
+
type CommandStartContext = Pick<ExtensionContext, "ui" | "cwd">;
|
|
4
|
+
export interface RemoteCommandDependencies {
|
|
5
|
+
start(ctx: CommandStartContext): Promise<void>;
|
|
6
|
+
stop(): void;
|
|
7
|
+
state(): "idle" | "started";
|
|
8
|
+
relayStatus(): string;
|
|
9
|
+
relayUrl(): string | null;
|
|
10
|
+
endpointIdentity(): Readonly<{
|
|
11
|
+
endpointId: string;
|
|
12
|
+
runtimeInstanceId: string;
|
|
13
|
+
}>;
|
|
14
|
+
activeOwnerCount(): number;
|
|
15
|
+
isOwnerActive(ownerId: string): boolean;
|
|
16
|
+
detachOwner(ownerId: string): void;
|
|
17
|
+
updateEndpoint(): Promise<void>;
|
|
18
|
+
displayName(cwd?: string): string;
|
|
19
|
+
keypair(): Ed25519Keypair | null;
|
|
20
|
+
hasRelay(): boolean;
|
|
21
|
+
piApi(): ExtensionAPI | null;
|
|
22
|
+
setCommandContext(ctx: ExtensionCommandContext): void;
|
|
23
|
+
}
|
|
24
|
+
export declare function persistModelDefault(provider: string, modelId: string): void;
|
|
25
|
+
export declare function registerCommands(pi: ExtensionAPI, deps: RemoteCommandDependencies): void;
|
|
26
|
+
export declare function runDirectCli(deps: RemoteCommandDependencies, directRun: boolean): void;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { canonicalizeEd25519PublicKey } from "../pairing/crypto.js";
|
|
5
|
+
import { buildQRUri, clampPairTtlMs, qrSession, renderQRAscii, TOKEN_TTL_MS } from "../pairing/qr.js";
|
|
6
|
+
import { listPeers, removePeer } from "../pairing/storage.js";
|
|
7
|
+
import { isValidRelayUrl, isWebSocketScheme, resolveRelayUrl, saveConfig } from "../config.js";
|
|
8
|
+
import { addDaemon, findDaemonByCwd, listDaemons, removeDaemon } from "./registry.js";
|
|
9
|
+
import { callSupervisor, supervisorOnline, SupervisorOfflineError } from "./client.js";
|
|
10
|
+
import { installService, uninstallService, linkCliBinaries, unlinkCliBinaries, LAUNCHD_LABEL, SYSTEMD_UNIT, } from "./install.js";
|
|
11
|
+
function notify(ctx, text, kind = "info") {
|
|
12
|
+
try {
|
|
13
|
+
ctx.ui.notify(text, kind);
|
|
14
|
+
}
|
|
15
|
+
catch { /* headless/stale context */ }
|
|
16
|
+
}
|
|
17
|
+
async function pair(ctx, args, deps) {
|
|
18
|
+
if (deps.state() === "idle")
|
|
19
|
+
await deps.start(ctx);
|
|
20
|
+
const keypair = deps.keypair();
|
|
21
|
+
if (!deps.hasRelay() || !keypair) {
|
|
22
|
+
notify(ctx, "[remote-pi] Pair requires a Relay connection.", "warning");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const ttl = /--ttl\s+(\d+)/.exec(args);
|
|
26
|
+
const ttlMs = ttl ? clampPairTtlMs(Number(ttl[1]) * 1_000) : TOKEN_TTL_MS;
|
|
27
|
+
const issued = qrSession.issueToken(ttlMs);
|
|
28
|
+
const identity = deps.endpointIdentity();
|
|
29
|
+
const uri = buildQRUri(issued.token, keypair.publicKey, deps.displayName(ctx.cwd), identity.endpointId, identity.runtimeInstanceId);
|
|
30
|
+
try {
|
|
31
|
+
deps.piApi()?.sendMessage({
|
|
32
|
+
customType: "remote-pi:pair-code",
|
|
33
|
+
content: `Scan to pair:\n\n${renderQRAscii(uri)}\n\n${uri}`,
|
|
34
|
+
details: { uri, token: issued.token, expiresAt: issued.expiresAt, endpointId: identity.endpointId, name: deps.displayName(ctx.cwd) },
|
|
35
|
+
display: true,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch { /* headless pairing still has a status message */ }
|
|
39
|
+
notify(ctx, `[remote-pi] QR ready until ${new Date(issued.expiresAt).toLocaleTimeString()}.`);
|
|
40
|
+
}
|
|
41
|
+
async function listDevices(ctx, deps) {
|
|
42
|
+
const peers = await listPeers();
|
|
43
|
+
if (!peers.length) {
|
|
44
|
+
notify(ctx, "[remote-pi] No paired devices.");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
notify(ctx, `[remote-pi] Paired devices:\n${peers.map((peer) => `• ${peer.remote_epk.slice(0, 8)} — ${peer.name}${deps.isOwnerActive(peer.remote_epk) ? " 🟢 online" : ""}`).join("\n")}`);
|
|
48
|
+
}
|
|
49
|
+
async function revoke(args, ctx, deps) {
|
|
50
|
+
const shortId = args.trim();
|
|
51
|
+
if (!shortId) {
|
|
52
|
+
notify(ctx, "[remote-pi] Usage: /remote-pi revoke <shortid>", "warning");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const matches = (await listPeers()).filter((peer) => peer.remote_epk.startsWith(shortId));
|
|
56
|
+
if (matches.length !== 1) {
|
|
57
|
+
notify(ctx, matches.length ? "[remote-pi] Ambiguous owner id." : "[remote-pi] No matching paired device.", "warning");
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const peer = matches[0];
|
|
61
|
+
await removePeer(peer.remote_epk);
|
|
62
|
+
try {
|
|
63
|
+
deps.detachOwner(canonicalizeEd25519PublicKey(peer.remote_epk, "Owner public key"));
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
deps.detachOwner(peer.remote_epk);
|
|
67
|
+
}
|
|
68
|
+
await deps.updateEndpoint();
|
|
69
|
+
notify(ctx, `[remote-pi] Revoked: ${peer.name}`);
|
|
70
|
+
}
|
|
71
|
+
function status(ctx, deps) {
|
|
72
|
+
const url = deps.relayUrl() ?? resolveRelayUrl().url;
|
|
73
|
+
const identity = deps.endpointIdentity();
|
|
74
|
+
const detail = deps.state() === "idle"
|
|
75
|
+
? "off"
|
|
76
|
+
: `${deps.relayStatus()}, endpoint=${identity.endpointId}, runtime=${identity.runtimeInstanceId}, owners=${deps.activeOwnerCount()}`;
|
|
77
|
+
notify(ctx, `[remote-pi] Relay ${detail} (${url})`);
|
|
78
|
+
}
|
|
79
|
+
function setRelay(value, ctx) {
|
|
80
|
+
const url = value.trim();
|
|
81
|
+
if (isWebSocketScheme(url)) {
|
|
82
|
+
notify(ctx, "[remote-pi] Use http:// or https://; it is converted internally.", "warning");
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (!isValidRelayUrl(url)) {
|
|
86
|
+
notify(ctx, "[remote-pi] Invalid Relay URL.", "warning");
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
saveConfig({ relay: url });
|
|
90
|
+
notify(ctx, `[remote-pi] Relay set to ${url}.`);
|
|
91
|
+
}
|
|
92
|
+
export function persistModelDefault(provider, modelId) {
|
|
93
|
+
try {
|
|
94
|
+
const path = join(process.cwd(), ".pi", "settings.json");
|
|
95
|
+
let config = {};
|
|
96
|
+
try {
|
|
97
|
+
config = JSON.parse(readFileSync(path, "utf8"));
|
|
98
|
+
}
|
|
99
|
+
catch { /* fresh file */ }
|
|
100
|
+
config.defaultProvider = provider;
|
|
101
|
+
config.defaultModel = modelId;
|
|
102
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
103
|
+
writeFileSync(path, JSON.stringify(config, null, 2));
|
|
104
|
+
}
|
|
105
|
+
catch { /* a live model switch must not fail because persistence failed */ }
|
|
106
|
+
}
|
|
107
|
+
function daemonLines(daemons) {
|
|
108
|
+
return daemons.map((daemon) => `${daemon.id.slice(0, 8)} ${daemon.name} ${daemon.health} ${daemon.relay}`).join("\n") || "(none)";
|
|
109
|
+
}
|
|
110
|
+
async function daemonList(ctx) {
|
|
111
|
+
if (await supervisorOnline()) {
|
|
112
|
+
const data = await callSupervisor({ op: "list" });
|
|
113
|
+
notify(ctx, `[remote-pi] Daemons:\n${daemonLines(data.daemons)}`);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const entries = listDaemons();
|
|
117
|
+
notify(ctx, `[remote-pi] Daemons (supervisor offline):\n${entries.map((entry) => `${entry.id.slice(0, 8)} ${entry.name} ${entry.desired_state}`).join("\n") || "(none)"}`);
|
|
118
|
+
}
|
|
119
|
+
async function daemonControl(op, id, ctx) {
|
|
120
|
+
const data = await callSupervisor(id ? { op, id } : { op: `${op}_all` });
|
|
121
|
+
notify(ctx, `[remote-pi] ${op}: ${JSON.stringify(data)}`);
|
|
122
|
+
}
|
|
123
|
+
async function daemonCreate(arg, ctx) {
|
|
124
|
+
const cwd = arg.trim() || process.cwd();
|
|
125
|
+
const entry = addDaemon(cwd);
|
|
126
|
+
try {
|
|
127
|
+
await callSupervisor({ op: "start", id: entry.id });
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
if (!(error instanceof SupervisorOfflineError))
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
notify(ctx, `[remote-pi] Registered daemon ${entry.id} for ${entry.cwd}.`);
|
|
134
|
+
}
|
|
135
|
+
async function daemonRemove(arg, ctx) {
|
|
136
|
+
const id = arg.trim();
|
|
137
|
+
if (!id) {
|
|
138
|
+
notify(ctx, "[remote-pi] Usage: remove <daemon-id>", "warning");
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const removed = await supervisorOnline() ? await callSupervisor({ op: "unregister", id }) : removeDaemon(id);
|
|
142
|
+
notify(ctx, removed.removed ? "[remote-pi] Daemon removed." : "[remote-pi] No daemon matched.", removed.removed ? "info" : "warning");
|
|
143
|
+
}
|
|
144
|
+
async function daemonRemoveCwd(cwd, ctx) {
|
|
145
|
+
const target = cwd.trim() || process.cwd();
|
|
146
|
+
const removed = await supervisorOnline()
|
|
147
|
+
? await callSupervisor({ op: "unregister_cwd", cwd: target })
|
|
148
|
+
: (() => { const entry = findDaemonByCwd(target); return entry ? removeDaemon(entry.id) : { removed: false }; })();
|
|
149
|
+
notify(ctx, removed.removed ? "[remote-pi] Daemon removed." : "[remote-pi] No daemon matched.", removed.removed ? "info" : "warning");
|
|
150
|
+
}
|
|
151
|
+
function install(ctx) {
|
|
152
|
+
try {
|
|
153
|
+
installService();
|
|
154
|
+
linkCliBinaries();
|
|
155
|
+
notify(ctx, "[remote-pi] Supervisor service installed.");
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
notify(ctx, `[remote-pi] install failed: ${String(error)}`, "error");
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function uninstall(ctx) {
|
|
162
|
+
try {
|
|
163
|
+
uninstallService();
|
|
164
|
+
unlinkCliBinaries();
|
|
165
|
+
notify(ctx, "[remote-pi] Supervisor service removed.");
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
notify(ctx, `[remote-pi] uninstall failed: ${String(error)}`, "error");
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
async function command(args, ctx, deps) {
|
|
172
|
+
deps.setCommandContext(ctx);
|
|
173
|
+
const [verb, ...rest] = args.trim().split(/\s+/);
|
|
174
|
+
const value = rest.join(" ");
|
|
175
|
+
try {
|
|
176
|
+
switch (verb || "start") {
|
|
177
|
+
case "start":
|
|
178
|
+
await deps.start(ctx);
|
|
179
|
+
return;
|
|
180
|
+
case "stop":
|
|
181
|
+
deps.stop();
|
|
182
|
+
notify(ctx, "[remote-pi] Stopped.");
|
|
183
|
+
return;
|
|
184
|
+
case "status":
|
|
185
|
+
status(ctx, deps);
|
|
186
|
+
return;
|
|
187
|
+
case "pair":
|
|
188
|
+
await pair(ctx, value, deps);
|
|
189
|
+
return;
|
|
190
|
+
case "devices":
|
|
191
|
+
await listDevices(ctx, deps);
|
|
192
|
+
return;
|
|
193
|
+
case "revoke":
|
|
194
|
+
await revoke(value, ctx, deps);
|
|
195
|
+
return;
|
|
196
|
+
case "set-relay":
|
|
197
|
+
setRelay(value, ctx);
|
|
198
|
+
return;
|
|
199
|
+
case "config":
|
|
200
|
+
notify(ctx, `[remote-pi] ${resolveRelayUrl().url}`);
|
|
201
|
+
return;
|
|
202
|
+
case "daemons":
|
|
203
|
+
await daemonList(ctx);
|
|
204
|
+
return;
|
|
205
|
+
case "create":
|
|
206
|
+
await daemonCreate(value, ctx);
|
|
207
|
+
return;
|
|
208
|
+
case "remove":
|
|
209
|
+
await daemonRemove(value, ctx);
|
|
210
|
+
return;
|
|
211
|
+
case "remove-cwd":
|
|
212
|
+
await daemonRemoveCwd(value, ctx);
|
|
213
|
+
return;
|
|
214
|
+
case "install":
|
|
215
|
+
install(ctx);
|
|
216
|
+
return;
|
|
217
|
+
case "uninstall":
|
|
218
|
+
uninstall(ctx);
|
|
219
|
+
return;
|
|
220
|
+
case "daemon": {
|
|
221
|
+
const [operation, id] = value.split(/\s+/, 2);
|
|
222
|
+
if (operation === "start" || operation === "stop" || operation === "restart")
|
|
223
|
+
await daemonControl(operation, id, ctx);
|
|
224
|
+
else if (operation === "status")
|
|
225
|
+
await daemonList(ctx);
|
|
226
|
+
else
|
|
227
|
+
notify(ctx, "[remote-pi] Usage: daemon <start|stop|restart|status> [id]", "warning");
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
default:
|
|
231
|
+
await deps.start(ctx);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
notify(ctx, `[remote-pi] ${verb} failed: ${String(error)}`, "error");
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
export function registerCommands(pi, deps) {
|
|
240
|
+
const handler = (args, ctx) => command(args, ctx, deps);
|
|
241
|
+
pi.registerCommand("remote-pi", { description: "Connect this Pi endpoint to Remote Pi", handler });
|
|
242
|
+
pi.registerCommand("remote-pi start", { description: "Connect this endpoint to Relay", handler: async (_, ctx) => handler("start", ctx) });
|
|
243
|
+
pi.registerCommand("remote-pi stop", { description: "Disconnect this endpoint", handler: async (_, ctx) => handler("stop", ctx) });
|
|
244
|
+
pi.registerCommand("remote-pi pair", { description: "Show an endpoint pairing QR", handler: async (args, ctx) => handler(`pair ${args}`, ctx) });
|
|
245
|
+
pi.registerCommand("remote-pi devices", { description: "List locally paired Owners", handler: async (_, ctx) => handler("devices", ctx) });
|
|
246
|
+
pi.registerCommand("remote-pi revoke", { description: "Revoke a locally paired Owner", handler: async (args, ctx) => handler(`revoke ${args}`, ctx) });
|
|
247
|
+
pi.registerCommand("remote-pi remove-cwd", { description: "Unregister the daemon for a cwd", handler: async (args, ctx) => handler(`remove-cwd ${args}`, ctx) });
|
|
248
|
+
pi.registerCommand("remote-pi set-relay", { description: "Set Relay URL", handler: async (args, ctx) => handler(`set-relay ${args}`, ctx) });
|
|
249
|
+
}
|
|
250
|
+
function directCliContext() {
|
|
251
|
+
return { ui: { notify: (message) => console.log(message) } };
|
|
252
|
+
}
|
|
253
|
+
export function runDirectCli(deps, directRun) {
|
|
254
|
+
if (!directRun)
|
|
255
|
+
return;
|
|
256
|
+
const [, , commandName, ...args] = process.argv;
|
|
257
|
+
const ctx = directCliContext();
|
|
258
|
+
if (commandName === "devices" || commandName === "list")
|
|
259
|
+
void listDevices(ctx, deps);
|
|
260
|
+
else if (commandName === "revoke")
|
|
261
|
+
void revoke(args[0] ?? "", ctx, deps);
|
|
262
|
+
else if (commandName === "set-relay")
|
|
263
|
+
setRelay(args[0] ?? "", ctx);
|
|
264
|
+
else if (commandName === "daemons")
|
|
265
|
+
void daemonList(ctx);
|
|
266
|
+
else if (commandName === "daemon" && ["start", "stop", "restart"].includes(args[0] ?? ""))
|
|
267
|
+
void daemonControl(args[0], args[1], ctx);
|
|
268
|
+
else if (commandName === "create")
|
|
269
|
+
void daemonCreate(args.join(" "), ctx);
|
|
270
|
+
else if (commandName === "remove")
|
|
271
|
+
void daemonRemove(args[0] ?? "", ctx);
|
|
272
|
+
else if (commandName === "remove-cwd")
|
|
273
|
+
void daemonRemoveCwd(args.join(" "), ctx);
|
|
274
|
+
else if (commandName === "install")
|
|
275
|
+
install(ctx);
|
|
276
|
+
else if (commandName === "uninstall")
|
|
277
|
+
uninstall(ctx);
|
|
278
|
+
else if (commandName === "restart-supervisor")
|
|
279
|
+
restartSupervisor();
|
|
280
|
+
else
|
|
281
|
+
console.log("Usage: remote-pi <devices|revoke|set-relay|daemons|daemon|create|remove|remove-cwd|install|uninstall>");
|
|
282
|
+
}
|
|
283
|
+
function restartSupervisor() {
|
|
284
|
+
const uid = process.getuid?.() ?? 0;
|
|
285
|
+
const step = process.platform === "darwin"
|
|
286
|
+
? ["launchctl", ["kickstart", "-k", `gui/${uid}/${LAUNCHD_LABEL}`]]
|
|
287
|
+
: process.platform === "linux"
|
|
288
|
+
? ["systemctl", ["--user", "restart", SYSTEMD_UNIT]]
|
|
289
|
+
: null;
|
|
290
|
+
if (!step)
|
|
291
|
+
process.exitCode = 1;
|
|
292
|
+
else
|
|
293
|
+
spawnSync(step[0], step[1], { stdio: "inherit" });
|
|
294
|
+
}
|
|
295
|
+
//# sourceMappingURL=commands.js.map
|