UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

34 lines (33 loc) • 1.89 kB
import { DEFAULT_GATE_AWAIT_TIMEOUT_MS, gateWaitFailureOf, withGateTimeout } from "../gate-bounded-await.js"; import { readStationAnswer } from "../shell-read-silence.js"; import { attest } from "../tool-policy.js"; import { READ_BLOCK_REMEDY } from "../../tools/fs/file-read-check.js"; export function readBlockOf(leg) { return leg.spec.blockReadsOutsideRoots === true || leg.resume?.seed.readBlock === true; } export function readBlockLeg(readBlock) { return readBlock ? { outsideReadRemedy: READ_BLOCK_REMEDY, grantsReadRootMidRun: false, personDirectories: "set_aside" } : { outsideReadRemedy: undefined, grantsReadRootMidRun: true, personDirectories: "honored" }; } export function readBoundaryRefusalOver(seat) { return async (creq, args, csignal) => { const { judge } = seat; if (judge === undefined) return undefined; const signal = csignal ?? seat.signal; const judged = judge.judge(creq, args, seat.cwd(), signal, { toolCallId: creq.toolCallId }); if (judged === null) return undefined; let answer; try { answer = await withGateTimeout(judged, DEFAULT_GATE_AWAIT_TIMEOUT_MS, signal, "readBoundaryAhead"); } catch (err) { answer = judge.unanswered(creq, gateWaitFailureOf(err) === "timeout" ? "the read station timed out" : "the read station could not answer"); } const reading = readStationAnswer(answer, { toolName: creq.toolName, toolCallId: creq.toolCallId }); if (reading.kind !== "refuse") return undefined; const { sentence, details } = reading.verdict; return attest({ action: "deny", message: sentence ?? `tool "${creq.toolName}" reads what the session's read boundary refuses` }, creq, { stationRefusal: { layer: "read_boundary", ...(details !== undefined ? { details } : {}) } }); }; }