Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions apps/cli/src/cli-socket-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { platform, tmpdir } from "node:os";
import { homedir, platform } from "node:os";
import { join } from "node:path";

// One socket / named pipe per host. On macOS tmpdir is per-user; on Linux /tmp
// is global but the socket file's owner-only mode 0600 keeps it isolated.
// One socket / named pipe per host. Stays under the user's home — not
// os.tmpdir() — because $TMPDIR differs between the two processes that talk
// to each other: the app is launched by Finder/Dock (no $TMPDIR, so
// os.tmpdir() falls back to /tmp) while the CLI runs in a terminal ($TMPDIR
// set to /var/folders/.../T). Anchoring on homedir() gives both the same
// path and keeps the socket owner-only (dir mode 0700) for isolation.
//
// Kept separate from cli-channels so the renderer can import the channel
// registry and envelope types without pulling in node:os / node:path.
export const SOCKET_DIR = join(homedir(), ".diffusion-studio");
export const SOCKET_PATH =
platform() === "win32"
? "\\\\.\\pipe\\diffusion-studio"
: join(tmpdir(), "diffusion-studio.sock");
: join(SOCKET_DIR, "diffusion-studio.sock");
5 changes: 3 additions & 2 deletions apps/desktop/src/cli-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { existsSync, unlinkSync } from "node:fs";
import { existsSync, mkdirSync, unlinkSync } from "node:fs";
import { createServer } from "node:net";
import type { Server, Socket } from "node:net";
import { app, BrowserWindow } from "electron";
import { CLI_WIRE, SOCKET_PATH } from "@diffusionstudio/cli/protocol";
import { CLI_WIRE, SOCKET_DIR, SOCKET_PATH } from "@diffusionstudio/cli/protocol";
import type { CliHandshake, CliHandshakeReply } from "@diffusionstudio/cli/protocol";
import { mainBridge } from "./main-manager";
import { MAIN_CHANNELS } from "./main-channels";
Expand Down Expand Up @@ -102,6 +102,7 @@ async function deliverHandshake(handshake: CliHandshake, sock: Socket): Promise<

export function startCliServer() {
cleanupStaleSocket();
if (process.platform !== "win32") mkdirSync(SOCKET_DIR, { recursive: true, mode: 0o700 });
bindWindowLifecycle();

cliServer = createServer({ allowHalfOpen: true }, (sock: Socket) => {
Expand Down