Files
claude-code-conduit/server/actions.mjs
mikael-lovqvists-claude-agent 4b064f1bf8 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>
2026-03-07 20:38:04 +00:00

71 lines
1.8 KiB
JavaScript

// Action registry — defines all available actions, their parameters, and policies.
// policy: "auto-accept" | "auto-deny" | "queue"
import { resolve_path, exec } from "./helpers.mjs";
export const actions = {
"list-actions": {
description: "List all available actions and their definitions",
params: [],
policy: "auto-accept",
handler: () => {
return Object.entries(actions).map(([name, def]) => ({
action: name,
description: def.description,
params: def.params,
policy: def.policy,
}));
},
},
"edit-file": {
description: "Open a file in the editor",
params: [{ name: "filename", required: true, type: "path" }],
policy: "auto-accept",
handler: ({ filename }) => {
const resolved = resolve_path(filename);
exec('subl3', [resolved]);
return { opened: resolved };
},
},
/*
"open-directory": {
description: "Open a directory in the file manager",
params: [{ name: "path", required: true, type: "path" }],
policy: 'queue',
handler: ({ path }) => {
const resolved = resolve_path(path);
// exec( ... );
return { opened: resolved };
},
},
*/
"open-browser": {
description: "Open a URL in the web browser",
params: [{ name: "url", required: true, type: "string" }],
policy: "queue",
handler: ({ url }) => {
const parsed = new URL(url);
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
throw new Error(`Disallowed protocol: ${parsed.protocol}`);
}
exec('xdg-open', [parsed.href]);
return { opened: parsed.href };
},
},
"open-terminal": {
description: "Open a terminal in a given directory",
params: [{ name: "path", required: false, type: "path" }],
policy: 'queue',
handler: ({ path }) => {
const resolved = resolve_path(path ?? 'workspace');
exec('konsole', ['--workdir', resolved, '-e', 'bash']);
return { opened: resolved };
},
},
};