Switch exec to fire-and-forget spawn, drop awaits

spawnSync was blocking the event loop until the subprocess exited, so
opening a browser would freeze the server until it closed. Replace with
spawn + unref (detached, stdio ignored) and remove the now-pointless
awaits and async keywords from action handlers.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 20:38:04 +00:00
parent 0568026e7c
commit 4b064f1bf8
2 changed files with 12 additions and 19 deletions

View File

@@ -9,7 +9,7 @@ export const actions = {
description: "List all available actions and their definitions",
params: [],
policy: "auto-accept",
handler: async () => {
handler: () => {
return Object.entries(actions).map(([name, def]) => ({
action: name,
description: def.description,
@@ -23,9 +23,9 @@ export const actions = {
description: "Open a file in the editor",
params: [{ name: "filename", required: true, type: "path" }],
policy: "auto-accept",
handler: async ({ filename }) => {
handler: ({ filename }) => {
const resolved = resolve_path(filename);
await exec('subl3', [resolved]);
exec('subl3', [resolved]);
return { opened: resolved };
},
},
@@ -35,9 +35,9 @@ export const actions = {
description: "Open a directory in the file manager",
params: [{ name: "path", required: true, type: "path" }],
policy: 'queue',
handler: async ({ path }) => {
handler: ({ path }) => {
const resolved = resolve_path(path);
// await exec( ... );
// exec( ... );
return { opened: resolved };
},
},
@@ -47,12 +47,12 @@ export const actions = {
description: "Open a URL in the web browser",
params: [{ name: "url", required: true, type: "string" }],
policy: "queue",
handler: async ({ url }) => {
handler: ({ url }) => {
const parsed = new URL(url);
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
throw new Error(`Disallowed protocol: ${parsed.protocol}`);
}
await exec('xdg-open', [parsed.href]);
exec('xdg-open', [parsed.href]);
return { opened: parsed.href };
},
},
@@ -61,9 +61,9 @@ export const actions = {
description: "Open a terminal in a given directory",
params: [{ name: "path", required: false, type: "path" }],
policy: 'queue',
handler: async ({ path }) => {
handler: ({ path }) => {
const resolved = resolve_path(path ?? 'workspace');
await exec('konsole', ['--workdir', resolved, '-e', 'bash']);
exec('konsole', ['--workdir', resolved, '-e', 'bash']);
return { opened: resolved };
},
},

View File

@@ -1,4 +1,4 @@
import { spawnSync } from "child_process";
import { spawn } from "child_process";
import path from "path";
const CONTAINER_PATH = "/home/devilholk/Projekt/claude-docker/";
@@ -24,14 +24,7 @@ export function resolve_path(user_path) {
throw new Error(`Path is outside all known volumes: ${user_path}`);
}
// Execute a binary with an argument list — no shell interpolation.
// Launch a binary with an argument list — no shell interpolation, fire and forget.
export function exec(bin, args = []) {
return new Promise((resolve, reject) => {
const result = spawnSync(bin, args, { stdio: "inherit" });
if (result.error) {
reject(result.error);
} else {
resolve(result.status);
}
});
spawn(bin, args, { stdio: 'ignore', detached: true }).unref();
}