UNPKG

@code-yeongyu/senpi

Version:

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

47 lines • 2.08 kB
import { DEFAULT_LIMITS } from "./limits.js"; import { createLocalInfoOps } from "./info/local-info.js"; import { createLocalFileOps } from "./files/local-files.js"; import { gated } from "./policy/gate.js"; import { defaultKillTree, runExec } from "./process/exec.js"; import { HandleRegistry } from "./process/handles.js"; import { ScopeRegistry } from "./process/scopes.js"; /** The local implementation of every op, one instance per host runtime. No concurrency cap anywhere. */ export function createLocalMachineOps(options) { const limits = options.limits ?? DEFAULT_LIMITS; const killTree = options.killProcessTree ?? defaultKillTree; const scopes = options.stateDir === undefined ? undefined : new ScopeRegistry(options.stateDir, killTree); const handles = new HandleRegistry(options.holder, scopes, limits); let lastOpAtMs; const touch = (fn) => { return (...args) => { lastOpAtMs = Date.now(); return fn(...args); }; }; const localFiles = createLocalFileOps({ resolveFd: options.resolveFd }); const files = { read: touch(localFiles.read), write: touch(localFiles.write), edit: touch(localFiles.edit), glob: touch(localFiles.glob), grep: touch(localFiles.grep), stat: touch(localFiles.stat), list: touch(localFiles.list), }; const processOps = { exec: touch((req, ctx) => gated("process.exec", req, ctx, () => runExec(req, ctx, { scopes, killTree }))), spawn: touch((req, ctx) => gated("process.spawn", req, ctx, () => handles.spawn(req, ctx.principal.id, ctx.limits))), handle: (id) => handles.get(id), list: (principal) => handles.list(principal), sweep: touch(async (tokens) => { await scopes?.sweep(tokens); }), }; const info = createLocalInfoOps({ stateDir: options.stateDir, handle: (id) => handles.get(id), lastOpAtMs: () => lastOpAtMs, }); return { files, process: processOps, info, limits }; } //# sourceMappingURL=local.js.map