mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-30 05:02:58 +00:00
* M1: terminals survive daemon restarts: stop reasons, detached terminal worker, kill cleanup
restart_server_request.killTerminals / shutdown_server_request.keepTerminals and server_info.features.terminalsSurviveRestart; CLI daemon restart --kill-terminals and daemon stop --keep-terminals (capability-gated). The terminal worker runs detached over an owner-only, secret-authenticated socket and is adopted on daemon start. One kill cleanup contract (the reaper) by birth time, used by the daemon, the supervisor and stopDaemonInstance. Settings offers Restart and close terminals.
* M1: fix review findings: reaper session/table retry, short-command creation order, remote kill-restart cleanup report, stop test port
* M1: fix review findings: reaper-owned cleanup record, session member identity by terminal id, unreadable cleanup records, Settings restart error rendered in the card
* M2: worker protocol versions and draining, worker runs from its own copy, desktop upgrades keep terminals, out-of-date daemon notice, docs/terminal-worker.md
- Daemon classifies live workers by protocol: adopts current, drains one version old, shuts
down older, leaves a newer one running and answers list/create with
terminal_worker_incompatible (daemon status prints it). Never more than two workers.
- esbuild worker bundle (build:lib); a built daemon copies bundle, shell integration and
node-pty into $PASEO_HOME/terminal-worker/<version>-<hash>/ and launches from it; copies no
record names are pruned.
- Desktop app_update/version_mismatch stop with keep terminals on macOS/Linux; Windows and a
daemon without the capability close them.
- Out-of-date daemon sidebar notice with Update button, worded by terminalsSurviveRestart.
- PASEO-13: unreadable worker records fail status and kill-restart retry.
- PASEO-14: a session member without a terminal id is unknown, not unrelated.
- Smoke test 46 with A/B installation fixtures and per-fixture CLI shims (PASEO-9 fold).
* M2: track in-flight worker requests without leaving an unhandled rejection
detach({ afterPendingRequests }) tracked each request with request.finally(), which rejects
with the request; a fire-and-forget send that timed out surfaced as an unhandled rejection
(worker-terminal-manager.test.ts). Track settlement only.
* M2: CI round 1 fixes: worker terminal manager in the MCP key test, status cleanup field, shared socket dir
- mcp-server.test.ts (new upstream test) built the worker manager with the old fork API;
it now starts a real detached worker in a throwaway home.
- daemon-session.test.ts expected status without terminalCleanupUnconfirmed (added in M1).
- paseo-daemon.test.ts: a home under the scratch temp dir is too long for a unix socket, so
the worker listens in the per-user paseo-<uid> directory, which outlives workers by design;
the test now requires it to be empty instead of absent.
* M2: run Windows PowerShell by its install path for process identity
server-tests (windows-latest): bootstrap-provider-availability.test.ts starts a daemon with a
PATH that holds only git, and the terminal worker failed to start: 'cannot read its own process
identity: spawn powershell.exe ENOENT'. Process inspection (managed-processes.ts inspect and the
terminal worker's process table) now runs %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe.
* M2: lifecycle e2e plain stop uses the shutdown RPC on Windows
CI round 2, server-integration (windows-latest): 'stop and stop --force never signal processes
a stale or earlier-boot record names' called stopDaemonInstance without a shutdown channel,
which Windows refuses ('has no graceful shutdown channel'). Plain stops in the file now pass
one, as the CLI does.
* M2: native notice outlet, Windows desktop-update wording, worker cap counts unconfirmed cleanups, create recovers after a drain
* M2: phone sidebar mounts the callout slot (iOS notice verified), worker record reads retry transient errors
* M2: native notice preconditions use explicit working directories, one block per terminal
* M1: compact sidebar shows only native callouts on every platform; PTY round trips in the MCP key test get a 5 s window
* ci: pin Playwright browser jobs to ubuntu-24.04
The pinned Playwright (1.58) has no ubuntu-26.04 build, and forks whose
ubuntu-latest already resolves to 26.04 fail at browser install. Job names
are unchanged, so required-check contexts still match.
* ci: use ubuntu-latest for Playwright jobs, same as upstream
Reverts the ubuntu-24.04 pin; upstream main's Playwright shards pass on ubuntu-latest.
* fix(server): keep terminal worker record IO off the daemon event loop
* fix(server): restore terminal creation after worker failure
A disconnected terminal worker remained the current manager indefinitely, leaving dead sessions listed and every later create bound to a closed socket. Confirm process death before retiring the member and use the existing single launch path for replacement. Reconnect live workers and replay their screens while preserving terminal identity.
* test(server): verify orphan cleanup during worker recovery
Recovery reaps orphaned programs before a later daemon stop. The previous fixed-delay assertion raced that cleanup and failed when it completed promptly. Verify orphan removal, same-daemon replacement creation and cleanup on normal or forced stop instead.
* test(server): isolate Windows dependency fixture setup
Build the local package registry in setup so its npm packing processes do not consume the installation journey deadline. Install the platform package used by Windows runtime fixtures directly, avoiding an unused wrapper postinstall probe without a timeout.
* test(server): wait for pending watchers before disposal
Observation admission starts before asynchronous path setup reaches watcher subscription. Disposing at the admission counter races setup and never exercises late watcher cleanup. Wait for the subscriptions to be pending before disposing.
---------
Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
561 lines
19 KiB
TypeScript
561 lines
19 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import path from "node:path";
|
|
import { app, ipcMain, powerMonitor } from "electron";
|
|
import log from "electron-log/main";
|
|
import {
|
|
resolvePaseoHome,
|
|
startDaemonInstance,
|
|
DaemonInstanceError,
|
|
stopDaemonInstance,
|
|
readDaemonInstance,
|
|
isSameDaemonInstance,
|
|
readLocalCredentialForTarget,
|
|
type DaemonInstance,
|
|
} from "@getpaseo/server/daemon-control";
|
|
import {
|
|
copyAttachmentFileToManagedStorage,
|
|
deleteManagedAttachmentFile,
|
|
garbageCollectManagedAttachmentFiles,
|
|
readManagedFileBase64,
|
|
writeAttachmentBase64,
|
|
writeAttachmentBytes,
|
|
} from "../features/attachments.js";
|
|
import {
|
|
checkForAppUpdate,
|
|
downloadAndInstallUpdate,
|
|
type AppUpdateCheckIntent,
|
|
type AppReleaseChannel,
|
|
} from "../features/auto-updater.js";
|
|
import {
|
|
getBundledCliShimPath,
|
|
getCliInstallStatus,
|
|
installCli,
|
|
} from "../integrations/cli-install/index.js";
|
|
import {
|
|
openLocalTransportSession,
|
|
sendLocalTransportMessage,
|
|
closeLocalTransportSession,
|
|
} from "./local-transport.js";
|
|
import { createNodeEntrypointInvocation, resolveDaemonRunnerEntrypoint } from "./runtime-paths.js";
|
|
import {
|
|
ExternalCliCommandError,
|
|
runExternalCliJsonCommand,
|
|
runExternalCliTextCommand,
|
|
} from "./cli/external.js";
|
|
import {
|
|
createDesktopSettingsCommandHandlers,
|
|
type DesktopCommandHandler,
|
|
} from "../settings/desktop-settings-commands.js";
|
|
import type { DesktopSettings } from "../settings/desktop-settings.js";
|
|
import { getDesktopSettingsStore } from "../settings/desktop-settings-electron.js";
|
|
import { isRunningUnderARM64Translation } from "../system/arm64-translation.js";
|
|
import { describeSandbox } from "../diagnostics/sandbox.js";
|
|
import { getDesktopAppLogs } from "../diagnostics/app-logs.js";
|
|
import { getDesktopUpdaterDiagnostics } from "../diagnostics/updater.js";
|
|
import {
|
|
deleteLegacySkillSelection,
|
|
readLegacySkillSelection,
|
|
} from "../integrations/legacy-skill-selection.js";
|
|
import { tailFile } from "../diagnostics/tail-file.js";
|
|
|
|
const DAEMON_LOG_FILENAME = "daemon.log";
|
|
let ownedLaunch: { home: string; instance: DaemonInstance } | null = null;
|
|
|
|
type DesktopDaemonState = "starting" | "running" | "stopped" | "errored";
|
|
const DESKTOP_DAEMON_STOP_REASON_VALUES = [
|
|
"manual_ipc",
|
|
"settings",
|
|
"host_remove",
|
|
"quit",
|
|
"app_update",
|
|
"version_mismatch",
|
|
"restart",
|
|
] as const;
|
|
export type DesktopDaemonStopReason = (typeof DESKTOP_DAEMON_STOP_REASON_VALUES)[number];
|
|
|
|
const DESKTOP_DAEMON_STOP_REASONS = new Set<string>(DESKTOP_DAEMON_STOP_REASON_VALUES);
|
|
const DEFAULT_DESKTOP_DAEMON_STOP_REASON: DesktopDaemonStopReason = "manual_ipc";
|
|
|
|
export interface DesktopDaemonStatus {
|
|
serverId: string;
|
|
status: DesktopDaemonState;
|
|
listen: string | null;
|
|
hostname: string | null;
|
|
pid: number | null;
|
|
home: string;
|
|
version: string | null;
|
|
desktopManaged: boolean;
|
|
ownedByDesktop: boolean;
|
|
startedAt: string | null;
|
|
error: string | null;
|
|
}
|
|
|
|
interface DesktopDaemonLogs {
|
|
logPath: string;
|
|
contents: string;
|
|
}
|
|
|
|
function parseReleaseChannel(
|
|
args: Record<string, unknown> | undefined,
|
|
): AppReleaseChannel | undefined {
|
|
if (args?.releaseChannel === "beta") {
|
|
return "beta";
|
|
}
|
|
if (args?.releaseChannel === "stable") {
|
|
return "stable";
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
function parseAppUpdateCheckIntent(
|
|
args: Record<string, unknown> | undefined,
|
|
): AppUpdateCheckIntent {
|
|
return args?.intent === "manual" ? "manual" : "automatic";
|
|
}
|
|
|
|
function parseDesktopDaemonStopReason(
|
|
args: Record<string, unknown> | undefined,
|
|
): DesktopDaemonStopReason {
|
|
const reason = args?.reason;
|
|
if (typeof reason === "string" && DESKTOP_DAEMON_STOP_REASONS.has(reason)) {
|
|
return reason as DesktopDaemonStopReason;
|
|
}
|
|
return DEFAULT_DESKTOP_DAEMON_STOP_REASON;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Utilities
|
|
// ---------------------------------------------------------------------------
|
|
|
|
function getPaseoHome(): string {
|
|
return resolvePaseoHome(process.env);
|
|
}
|
|
|
|
function logFilePath(): string {
|
|
return path.join(getPaseoHome(), DAEMON_LOG_FILENAME);
|
|
}
|
|
|
|
export function isDesktopManagedDaemonRunningSync(): boolean {
|
|
if (!ownedLaunch) return false;
|
|
try {
|
|
const lock = JSON.parse(readFileSync(path.join(ownedLaunch.home, "paseo.pid"), "utf8"));
|
|
return isSameDaemonInstance(lock, ownedLaunch.instance) && isProcessRunning(lock.pid);
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export async function stopDesktopDaemonViaCli(
|
|
reason: DesktopDaemonStopReason = DEFAULT_DESKTOP_DAEMON_STOP_REASON,
|
|
): Promise<void> {
|
|
await stopDesktopDaemon(reason);
|
|
}
|
|
|
|
function isProcessRunning(pid: number): boolean {
|
|
try {
|
|
process.kill(pid, 0);
|
|
return true;
|
|
} catch (err) {
|
|
if (typeof err === "object" && err !== null && "code" in err && err.code === "EPERM") {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function logDesktopDaemonLifecycle(message: string, details?: Record<string, unknown>): void {
|
|
log.info("[desktop daemon]", message, {
|
|
pid: process.pid,
|
|
...details,
|
|
});
|
|
}
|
|
|
|
function statusFromDaemonProbe(
|
|
payload: Record<string, unknown>,
|
|
home: string,
|
|
): DesktopDaemonStatus {
|
|
const local = typeof payload.localDaemon === "string" ? payload.localDaemon : "stopped";
|
|
const processAlive = local === "running" || local === "not_ready";
|
|
let status: DesktopDaemonState = "stopped";
|
|
if (local === "not_ready") status = "starting";
|
|
if (local === "running") status = "running";
|
|
return {
|
|
serverId: typeof payload.serverId === "string" ? payload.serverId : "",
|
|
status,
|
|
listen: typeof payload.listen === "string" ? payload.listen : null,
|
|
hostname:
|
|
status === "running" && typeof payload.hostname === "string" ? payload.hostname : null,
|
|
pid: processAlive && typeof payload.pid === "number" ? payload.pid : null,
|
|
home,
|
|
version: typeof payload.daemonVersion === "string" ? payload.daemonVersion : null,
|
|
desktopManaged: payload.desktopManaged === true,
|
|
startedAt: typeof payload.startedAt === "string" ? payload.startedAt : null,
|
|
ownedByDesktop: Boolean(
|
|
ownedLaunch &&
|
|
ownedLaunch.home === home &&
|
|
payload.pid === ownedLaunch.instance.pid &&
|
|
payload.startedAt === ownedLaunch.instance.startedAt,
|
|
),
|
|
error: null,
|
|
};
|
|
}
|
|
|
|
function resolveDesktopAppVersion(): string {
|
|
if (app.isPackaged) {
|
|
return app.getVersion();
|
|
}
|
|
|
|
try {
|
|
const packageJsonPath = path.join(__dirname, "..", "..", "package.json");
|
|
const pkg = JSON.parse(readFileSync(packageJsonPath, "utf-8")) as {
|
|
version?: unknown;
|
|
};
|
|
if (typeof pkg.version === "string" && pkg.version.trim().length > 0) {
|
|
return pkg.version.trim();
|
|
}
|
|
} catch {
|
|
// Fall back to Electron's default version if the package metadata is unavailable.
|
|
}
|
|
|
|
return app.getVersion();
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Daemon lifecycle
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export async function resolveDesktopDaemonStatus(): Promise<DesktopDaemonStatus> {
|
|
const home = getPaseoHome();
|
|
|
|
try {
|
|
// The app polls this while no local daemon runs. Answer that case in-process,
|
|
// since launching the CLI once per poll keeps spawning processes while idle.
|
|
if (!(await readDaemonInstance(home))) {
|
|
return statusFromDaemonProbe({ localDaemon: "stopped" }, home);
|
|
}
|
|
|
|
const payload = (await runExternalCliJsonCommand([
|
|
"daemon",
|
|
"status",
|
|
"--home",
|
|
home,
|
|
"--json",
|
|
])) as Record<string, unknown>;
|
|
return statusFromDaemonProbe(payload, home);
|
|
} catch (error) {
|
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
logDesktopDaemonLifecycle("resolveStatus failed", { error: errorMessage });
|
|
return {
|
|
serverId: "",
|
|
status: "errored",
|
|
listen: null,
|
|
hostname: null,
|
|
pid: null,
|
|
home,
|
|
version: null,
|
|
desktopManaged: false,
|
|
ownedByDesktop: false,
|
|
startedAt: null,
|
|
error: errorMessage,
|
|
};
|
|
}
|
|
}
|
|
|
|
function normalizeVersion(version: string | null): string | null {
|
|
const trimmed = version?.trim();
|
|
if (!trimmed) return null;
|
|
return trimmed.replace(/^v/i, "");
|
|
}
|
|
|
|
function shouldRestartForVersion(current: DesktopDaemonStatus): boolean {
|
|
if (!current.ownedByDesktop) return false;
|
|
const appVersion = normalizeVersion(resolveDesktopAppVersion());
|
|
const daemonVersion = normalizeVersion(current.version);
|
|
return Boolean(appVersion && daemonVersion && appVersion !== daemonVersion);
|
|
}
|
|
|
|
function assertBuiltInDaemonManagementEnabled(settings: DesktopSettings): void {
|
|
if (!settings.daemon.manageBuiltInDaemon) {
|
|
throw new Error("Built-in daemon management is disabled.");
|
|
}
|
|
}
|
|
|
|
async function startDaemon(): Promise<DesktopDaemonStatus> {
|
|
assertBuiltInDaemonManagementEnabled(await getDesktopSettingsStore().get());
|
|
|
|
const current = await resolveDesktopDaemonStatus();
|
|
logDesktopDaemonLifecycle("initial status check before start", {
|
|
status: current.status,
|
|
pid: current.pid,
|
|
listen: current.listen,
|
|
serverId: current.serverId || null,
|
|
error: current.error,
|
|
desktopManaged: current.desktopManaged,
|
|
});
|
|
if (current.status === "running" || current.status === "starting") {
|
|
if (shouldRestartForVersion(current)) {
|
|
logDesktopDaemonLifecycle("daemon version mismatch, restarting", {
|
|
appVersion: normalizeVersion(resolveDesktopAppVersion()),
|
|
daemonVersion: normalizeVersion(current.version),
|
|
});
|
|
await stopDesktopDaemon("version_mismatch");
|
|
} else {
|
|
return current;
|
|
}
|
|
}
|
|
|
|
const home = getPaseoHome();
|
|
const invocation = createNodeEntrypointInvocation({
|
|
entrypoint: resolveDaemonRunnerEntrypoint(),
|
|
argvMode: "node-script",
|
|
args: [],
|
|
baseEnv: process.env,
|
|
});
|
|
try {
|
|
await startDaemonInstance({
|
|
home,
|
|
timeoutMs: 30_000,
|
|
...invocation,
|
|
env: { ...invocation.env, PASEO_CLI: getBundledCliShimPath() },
|
|
mode: "managed",
|
|
desktopManaged: true,
|
|
onAcquired: (instance) => {
|
|
ownedLaunch = { home, instance };
|
|
},
|
|
});
|
|
} catch (error) {
|
|
if (!(error instanceof DaemonInstanceError && error.code === "DAEMON_NOT_READY")) throw error;
|
|
}
|
|
return resolveDesktopDaemonStatus();
|
|
}
|
|
|
|
export async function stopDesktopDaemon(
|
|
reason: DesktopDaemonStopReason = DEFAULT_DESKTOP_DAEMON_STOP_REASON,
|
|
confirmedInstance?: { pid: number; startedAt: string },
|
|
): Promise<DesktopDaemonStatus> {
|
|
const home = getPaseoHome();
|
|
const instance = await readDaemonInstance(home);
|
|
const owned = Boolean(
|
|
instance &&
|
|
ownedLaunch &&
|
|
ownedLaunch.home === home &&
|
|
isSameDaemonInstance(instance, ownedLaunch.instance),
|
|
);
|
|
const explicit =
|
|
reason === "manual_ipc" &&
|
|
confirmedInstance &&
|
|
instance &&
|
|
instance.pid === confirmedInstance.pid &&
|
|
instance.startedAt === confirmedInstance.startedAt;
|
|
if (confirmedInstance && !explicit)
|
|
throw new Error(
|
|
"Daemon changed since confirmation; inspect its current home and PID before stopping it.",
|
|
);
|
|
if (!instance || (!owned && !explicit)) return resolveDesktopDaemonStatus();
|
|
const keepTerminals = keepsTerminalsOnStop(reason, process.platform);
|
|
logDesktopDaemonLifecycle("stopping captured supervisor", {
|
|
reason,
|
|
pid: instance.pid,
|
|
owned,
|
|
keepTerminals,
|
|
});
|
|
await stopCapturedDaemon({ home, instance, reason, keepTerminals });
|
|
if (owned) ownedLaunch = null;
|
|
return resolveDesktopDaemonStatus();
|
|
}
|
|
|
|
export interface StopCapturedDaemonInput {
|
|
home: string;
|
|
instance: DaemonInstance;
|
|
reason: DesktopDaemonStopReason;
|
|
keepTerminals: boolean;
|
|
stopInstance?: typeof stopDaemonInstance;
|
|
runCliJson?: typeof runExternalCliJsonCommand;
|
|
log?: typeof logDesktopDaemonLifecycle;
|
|
}
|
|
|
|
/** Stops the supervisor desktop captured, keeping its terminals when asked and supported. */
|
|
export async function stopCapturedDaemon(input: StopCapturedDaemonInput): Promise<void> {
|
|
const stopInstance = input.stopInstance ?? stopDaemonInstance;
|
|
const runCliJson = input.runCliJson ?? runExternalCliJsonCommand;
|
|
const logLifecycle = input.log ?? logDesktopDaemonLifecycle;
|
|
const stop = (keep: boolean) =>
|
|
stopInstance(input.home, {
|
|
instance: input.instance,
|
|
timeoutMs: 15_000,
|
|
keepTerminals: keep,
|
|
requestShutdown: async (ready) => {
|
|
await runCliJson([
|
|
"daemon",
|
|
"stop",
|
|
"--host",
|
|
ready.listen,
|
|
...(keep ? ["--keep-terminals"] : []),
|
|
"--json",
|
|
]);
|
|
},
|
|
});
|
|
try {
|
|
await stop(input.keepTerminals);
|
|
} catch (error) {
|
|
// The CLI refuses a keep stop before sending anything when the daemon predates the feature;
|
|
// that daemon closes terminals on every stop, as every upgrade did before.
|
|
if (
|
|
!input.keepTerminals ||
|
|
!(error instanceof ExternalCliCommandError) ||
|
|
error.code !== "TERMINALS_KEEP_UNSUPPORTED"
|
|
) {
|
|
throw error;
|
|
}
|
|
const version = typeof error.error?.version === "string" ? error.error.version : "unknown";
|
|
logLifecycle(`daemon v${version} cannot keep terminals; stopping it and closing them`, {
|
|
reason: input.reason,
|
|
pid: input.instance.pid,
|
|
});
|
|
await stop(false);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Whether a desktop stop keeps the daemon's terminals running for the daemon that replaces it.
|
|
* Only when one comes straight back (an app update, a version-mismatch restart), and never on
|
|
* Windows: a surviving terminal worker runs Paseo.exe and would lock the install folder the
|
|
* update replaces. Quit, Settings, host removal and manual stops close terminals.
|
|
*/
|
|
export function keepsTerminalsOnStop(
|
|
reason: DesktopDaemonStopReason,
|
|
platform: NodeJS.Platform,
|
|
): boolean {
|
|
if (platform === "win32") return false;
|
|
return reason === "app_update" || reason === "version_mismatch";
|
|
}
|
|
|
|
async function restartDaemon(): Promise<DesktopDaemonStatus> {
|
|
await runExternalCliJsonCommand(["daemon", "restart", "--home", getPaseoHome(), "--json"]);
|
|
return resolveDesktopDaemonStatus();
|
|
}
|
|
|
|
function getDaemonLogs(): DesktopDaemonLogs {
|
|
const logPath = logFilePath();
|
|
return {
|
|
logPath,
|
|
contents: tailFile(logPath, 100),
|
|
};
|
|
}
|
|
|
|
async function getCliDaemonStatus(): Promise<string> {
|
|
return await runExternalCliTextCommand(["daemon", "status", "--home", getPaseoHome()]);
|
|
}
|
|
|
|
async function getLocalDaemonVersion(): Promise<{ version: string | null; error: string | null }> {
|
|
const status = await resolveDesktopDaemonStatus();
|
|
if (status.status !== "running") {
|
|
return { version: null, error: "Daemon is not running." };
|
|
}
|
|
return {
|
|
version: status.version,
|
|
error: status.version ? null : "Running daemon did not report a version.",
|
|
};
|
|
}
|
|
|
|
async function resolveRequestedReleaseChannel(
|
|
args: Record<string, unknown> | undefined,
|
|
): Promise<AppReleaseChannel> {
|
|
return parseReleaseChannel(args) ?? (await getDesktopSettingsStore().get()).releaseChannel;
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// IPC registration
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export function createDaemonCommandHandlers(): Record<string, DesktopCommandHandler> {
|
|
return {
|
|
...createDesktopSettingsCommandHandlers({ settingsStore: getDesktopSettingsStore() }),
|
|
desktop_get_runtime_info: () => ({
|
|
appVersion: resolveDesktopAppVersion(),
|
|
runningUnderARM64Translation: isRunningUnderARM64Translation(),
|
|
}),
|
|
desktop_daemon_status: () => resolveDesktopDaemonStatus(),
|
|
desktop_local_credential: async (args) => {
|
|
const instance = await readDaemonInstance(getPaseoHome());
|
|
if (!instance?.desktopManaged || typeof args?.listen !== "string") return null;
|
|
return readLocalCredentialForTarget(getPaseoHome(), args.listen);
|
|
},
|
|
start_desktop_daemon: () => startDaemon(),
|
|
stop_desktop_daemon: (args) =>
|
|
stopDesktopDaemon(
|
|
parseDesktopDaemonStopReason(args),
|
|
typeof args?.pid === "number" && typeof args.startedAt === "string"
|
|
? { pid: args.pid, startedAt: args.startedAt }
|
|
: undefined,
|
|
),
|
|
restart_desktop_daemon: () => restartDaemon(),
|
|
desktop_daemon_logs: () => getDaemonLogs(),
|
|
desktop_sandbox_diagnostics: () =>
|
|
describeSandbox({
|
|
disabled: app.commandLine.hasSwitch("no-sandbox"),
|
|
launcherReason: process.env.PASEO_DESKTOP_SANDBOX_REASON,
|
|
}),
|
|
desktop_app_logs: () => getDesktopAppLogs(),
|
|
desktop_update_diagnostics: () => getDesktopUpdaterDiagnostics(),
|
|
desktop_get_system_idle_time: () => powerMonitor.getSystemIdleTime() * 1000,
|
|
cli_daemon_status: () => getCliDaemonStatus(),
|
|
write_attachment_base64: (args) => writeAttachmentBase64(args ?? {}),
|
|
write_attachment_bytes: (args) => writeAttachmentBytes(args ?? {}),
|
|
copy_attachment_file: (args) => copyAttachmentFileToManagedStorage(args ?? {}),
|
|
read_file_base64: (args) => readManagedFileBase64(args ?? {}),
|
|
delete_attachment_file: (args) => deleteManagedAttachmentFile(args ?? {}),
|
|
garbage_collect_attachment_files: (args) => garbageCollectManagedAttachmentFiles(args ?? {}),
|
|
open_local_daemon_transport: async (args) => await openLocalTransportSession(args),
|
|
send_local_daemon_transport_message: async (args) => {
|
|
await sendLocalTransportMessage(
|
|
args as { sessionId: string; text?: string; binaryBase64?: string },
|
|
);
|
|
},
|
|
close_local_daemon_transport: (args) => {
|
|
const sessionId =
|
|
typeof args === "object" && args !== null && "sessionId" in args
|
|
? (args as { sessionId: string }).sessionId
|
|
: "";
|
|
if (sessionId) closeLocalTransportSession(sessionId);
|
|
},
|
|
check_app_update: async (args) => {
|
|
const currentVersion = resolveDesktopAppVersion();
|
|
return checkForAppUpdate({
|
|
currentVersion,
|
|
releaseChannel: await resolveRequestedReleaseChannel(args),
|
|
intent: parseAppUpdateCheckIntent(args),
|
|
});
|
|
},
|
|
install_app_update: async (args) => {
|
|
const currentVersion = resolveDesktopAppVersion();
|
|
return downloadAndInstallUpdate(
|
|
{ currentVersion, releaseChannel: await resolveRequestedReleaseChannel(args) },
|
|
async () => {
|
|
await stopDesktopDaemon("app_update");
|
|
},
|
|
);
|
|
},
|
|
get_local_daemon_version: () => getLocalDaemonVersion(),
|
|
install_cli: () => installCli(),
|
|
get_cli_install_status: () => getCliInstallStatus(),
|
|
read_legacy_skill_selection: () => readLegacySkillSelection(),
|
|
delete_legacy_skill_selection: () => deleteLegacySkillSelection(),
|
|
};
|
|
}
|
|
|
|
export function registerDaemonManager(): void {
|
|
const handlers = createDaemonCommandHandlers();
|
|
|
|
ipcMain.handle(
|
|
"paseo:invoke",
|
|
async (_event, command: string, args?: Record<string, unknown>) => {
|
|
const handler = handlers[command];
|
|
if (!handler) {
|
|
throw new Error(`Unknown desktop command: ${command}`);
|
|
}
|
|
return await handler(args);
|
|
},
|
|
);
|
|
}
|