@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
34 lines • 1.27 kB
JavaScript
import { parentPort } from "node:worker_threads";
import "../../windows-power-throttling-startup.js";
import { isBunBinary } from "../../config.js";
import { createLooplessRuntimeFactory } from "./runtime-factory-loopless.js";
if (isBunBinary) {
const { registerBunRuntimeModules } = await import("../../bun/runtime-modules.js");
registerBunRuntimeModules();
}
const port = parentPort;
if (!port)
throw new Error("Loopless worker requires a parent port");
const send = (message) => port.postMessage(message);
let runtime;
async function handle(message) {
switch (message.type) {
case "start": {
if (runtime)
throw new Error("Loopless worker already started");
runtime = await createLooplessRuntimeFactory(message.configuration)({ cwd: message.cwd });
send({ type: "ready", tools: [...runtime.definitions.keys()] });
return;
}
case "close":
await runtime?.dispose();
process.exit(0);
}
}
port.on("message", (message) => {
void handle(message).catch((cause) => {
send({ type: "failure", error: cause instanceof Error ? cause.message : String(cause) });
process.exit(1);
});
});
//# sourceMappingURL=loopless-worker.js.map