UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

47 lines • 1.93 kB
/** * Tool-path limits over the machine's own defaults. The tools keep their own truncation (truncate.ts, the output * accumulator), so the operation layer reads files whole and streams exec output uncaptured. */ function toolPathLimits(machineLimits) { return { ...machineLimits, readMaxBytes: Number.POSITIVE_INFINITY, execStdoutMaxBytes: 0, execStderrMaxBytes: 0, execTimeoutDefaultMs: Number.POSITIVE_INFINITY, }; } const NEVER_ABORTED = new AbortController().signal; /** Binds the tool path to the MachineOps `resolveOps` returns, read on every use. */ export function bindToolMachine(resolveOps, policy) { const context = (signal, pathLock) => ({ scope: { id: "local-session" }, principal: { kind: "local-session", id: "local-session" }, signal: signal ?? NEVER_ABORTED, limits: toolPathLimits(resolveOps().limits), // The tools run the extension filesystem policy themselves (with their own error text) and the gate below // already ran once for the call, so sub-operations carry no hooks. policy: {}, ...(pathLock !== undefined ? { pathLock } : {}), }); return { get ops() { return resolveOps(); }, begin(op, args, signal) { const beforeOp = policy?.beforeOp; if (beforeOp === undefined) return undefined; return beforeOp(op, args, { ...context(signal), policy: policy ?? {} }).then((decision) => { if (!decision.allow) throw new Error(decision.reason); }); }, context, }; } /** A ToolMachine over a host-supplied MachineOps (a remote device, a sandbox): the tools' only effect channel. */ export function createToolMachine(options) { return bindToolMachine(() => options.ops, options.policy); } //# sourceMappingURL=tool-machine.js.map