Rename .js to .mjs, extract helpers module
Move resolvePath and exec out of index.mjs into server/helpers.mjs so actions can import them directly rather than receiving them as arguments. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
63
server/actions.mjs
Normal file
63
server/actions.mjs
Normal file
@@ -0,0 +1,63 @@
|
||||
// Action registry — defines all available actions, their parameters, and policies.
|
||||
// policy: "auto-accept" | "auto-deny" | "queue"
|
||||
|
||||
import { resolvePath, exec } from "./helpers.mjs";
|
||||
|
||||
export const actions = {
|
||||
"list-actions": {
|
||||
description: "List all available actions and their definitions",
|
||||
params: [],
|
||||
policy: "auto-accept",
|
||||
handler: async () => {
|
||||
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: async ({ filename }) => {
|
||||
const resolved = resolvePath(filename);
|
||||
await exec("xdg-open", [resolved]);
|
||||
return { opened: resolved };
|
||||
},
|
||||
},
|
||||
|
||||
"open-directory": {
|
||||
description: "Open a directory in the file manager",
|
||||
params: [{ name: "path", required: true, type: "path" }],
|
||||
policy: "auto-accept",
|
||||
handler: async ({ path }) => {
|
||||
const resolved = resolvePath(path);
|
||||
await exec("xdg-open", [resolved]);
|
||||
return { opened: resolved };
|
||||
},
|
||||
},
|
||||
|
||||
"open-browser": {
|
||||
description: "Open a URL in the web browser",
|
||||
params: [{ name: "url", required: true, type: "string" }],
|
||||
policy: "queue",
|
||||
handler: async ({ url }) => {
|
||||
await exec("xdg-open", [url]);
|
||||
return { opened: url };
|
||||
},
|
||||
},
|
||||
|
||||
"open-terminal": {
|
||||
description: "Open a terminal in a given directory",
|
||||
params: [{ name: "path", required: false, type: "path" }],
|
||||
policy: "queue",
|
||||
handler: async ({ path }) => {
|
||||
const resolved = path ? resolvePath(path) : process.env.HOME;
|
||||
await exec("xdg-open", [resolved]);
|
||||
return { opened: resolved };
|
||||
},
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user