@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
52 lines • 2.55 kB
JavaScript
/**
* The ops the engine serves for the relay host (senpi#6752), each with the relay host's own decoder and run step. The
* relay host keeps policy.get/set, agent.restart, machine.preflight/update/update_status, service.restart and
* doctor.report; an op not listed here is refused malformed, as the relay host refuses an op it does not offer.
*/
import * as core from "./core-ops.js";
import * as args from "./op-args.js";
import * as term from "./terminal-args.js";
const decoded = (decode, a) => {
try {
return { d: decode(a) };
}
catch (error) {
if (error instanceof args.ArgsError)
return { problem: error.message };
throw error;
}
};
const entry = (decode, run, handleArg) => ({
...(handleArg === undefined ? {} : { handleArg }),
decode: (a) => {
const r = decoded(decode, a);
return "problem" in r ? r.problem : undefined;
},
run: (a, call) => {
const r = decoded(decode, a);
return "problem" in r
? Promise.resolve({ state: "refused", error: { code: "malformed", message: r.problem } })
: run(r.d, call);
},
});
const SERVED = {
"fs.read": entry(args.readArgs, core.runRead),
"fs.read_range": entry(args.readRangeArgs, core.runRead),
"fs.write": entry(args.writeArgs, core.runWrite),
"fs.write_range": entry(args.writeRangeArgs, core.runWrite),
"fs.edit": entry(args.editArgs, core.runEdit),
"fs.glob": entry(args.globArgs, core.runGlob),
"fs.grep": entry(args.grepArgs, core.runGrep),
"fs.stat": entry(args.statArgs, core.runStat),
"fs.list": entry(args.listArgs, core.runList),
shell: entry(args.shellArgs, core.runShell),
"process.info": entry(args.processInfoArgs, (d, call) => core.runProcessInfo(d, call, call.pidOf), "handleId"),
"mesh.message": entry(args.meshMessageArgs, core.runMeshMessage),
exec_command: entry(term.execCommandArgs, (d, call) => call.terminal.execCommand(d, call)),
write_stdin: entry(term.writeStdinArgs, (d, call) => call.terminal.writeStdin(d, call), "handle_id"),
wait_for_command: entry(term.waitForCommandArgs, (d, call) => call.terminal.waitForCommand(d, call), "handle_id"),
kill_terminal: entry(term.killTerminalArgs, (d, call) => call.terminal.killTerminal(d), "handle_id"),
};
/** The served op's entry (own keys only: an op named like an Object prototype key has none). */
export const servedOp = (name) => Object.hasOwn(SERVED, name) ? SERVED[name] : undefined;
//# sourceMappingURL=op-registry.js.map