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:
@@ -9,7 +9,7 @@ export const actions = {
|
|||||||
description: "List all available actions and their definitions",
|
description: "List all available actions and their definitions",
|
||||||
params: [],
|
params: [],
|
||||||
policy: "auto-accept",
|
policy: "auto-accept",
|
||||||
handler: async () => {
|
handler: () => {
|
||||||
return Object.entries(actions).map(([name, def]) => ({
|
return Object.entries(actions).map(([name, def]) => ({
|
||||||
action: name,
|
action: name,
|
||||||
description: def.description,
|
description: def.description,
|
||||||
@@ -23,9 +23,9 @@ export const actions = {
|
|||||||
description: "Open a file in the editor",
|
description: "Open a file in the editor",
|
||||||
params: [{ name: "filename", required: true, type: "path" }],
|
params: [{ name: "filename", required: true, type: "path" }],
|
||||||
policy: "auto-accept",
|
policy: "auto-accept",
|
||||||
handler: async ({ filename }) => {
|
handler: ({ filename }) => {
|
||||||
const resolved = resolve_path(filename);
|
const resolved = resolve_path(filename);
|
||||||
await exec('subl3', [resolved]);
|
exec('subl3', [resolved]);
|
||||||
return { opened: resolved };
|
return { opened: resolved };
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -35,9 +35,9 @@ export const actions = {
|
|||||||
description: "Open a directory in the file manager",
|
description: "Open a directory in the file manager",
|
||||||
params: [{ name: "path", required: true, type: "path" }],
|
params: [{ name: "path", required: true, type: "path" }],
|
||||||
policy: 'queue',
|
policy: 'queue',
|
||||||
handler: async ({ path }) => {
|
handler: ({ path }) => {
|
||||||
const resolved = resolve_path(path);
|
const resolved = resolve_path(path);
|
||||||
// await exec( ... );
|
// exec( ... );
|
||||||
return { opened: resolved };
|
return { opened: resolved };
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -47,12 +47,12 @@ export const actions = {
|
|||||||
description: "Open a URL in the web browser",
|
description: "Open a URL in the web browser",
|
||||||
params: [{ name: "url", required: true, type: "string" }],
|
params: [{ name: "url", required: true, type: "string" }],
|
||||||
policy: "queue",
|
policy: "queue",
|
||||||
handler: async ({ url }) => {
|
handler: ({ url }) => {
|
||||||
const parsed = new URL(url);
|
const parsed = new URL(url);
|
||||||
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
||||||
throw new Error(`Disallowed protocol: ${parsed.protocol}`);
|
throw new Error(`Disallowed protocol: ${parsed.protocol}`);
|
||||||
}
|
}
|
||||||
await exec('xdg-open', [parsed.href]);
|
exec('xdg-open', [parsed.href]);
|
||||||
return { opened: parsed.href };
|
return { opened: parsed.href };
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -61,9 +61,9 @@ export const actions = {
|
|||||||
description: "Open a terminal in a given directory",
|
description: "Open a terminal in a given directory",
|
||||||
params: [{ name: "path", required: false, type: "path" }],
|
params: [{ name: "path", required: false, type: "path" }],
|
||||||
policy: 'queue',
|
policy: 'queue',
|
||||||
handler: async ({ path }) => {
|
handler: ({ path }) => {
|
||||||
const resolved = resolve_path(path ?? 'workspace');
|
const resolved = resolve_path(path ?? 'workspace');
|
||||||
await exec('konsole', ['--workdir', resolved, '-e', 'bash']);
|
exec('konsole', ['--workdir', resolved, '-e', 'bash']);
|
||||||
return { opened: resolved };
|
return { opened: resolved };
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { spawnSync } from "child_process";
|
import { spawn } from "child_process";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
const CONTAINER_PATH = "/home/devilholk/Projekt/claude-docker/";
|
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}`);
|
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 = []) {
|
export function exec(bin, args = []) {
|
||||||
return new Promise((resolve, reject) => {
|
spawn(bin, args, { stdio: 'ignore', detached: true }).unref();
|
||||||
const result = spawnSync(bin, args, { stdio: "inherit" });
|
|
||||||
if (result.error) {
|
|
||||||
reject(result.error);
|
|
||||||
} else {
|
|
||||||
resolve(result.status);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user