@sema-agent/core
Version:
Stateless, task-oriented AI agent core
96 lines (95 loc) • 4.79 kB
JavaScript
import { describeRejectedValue } from "../../core/tool-search-setting.js";
export function skipsRootsContainment(face) {
return face === "open";
}
export const FACE_CLAMP_CAUSES = Object.freeze(["read_only_mount", "read_block"]);
const FACE_DIALECT = {
read: {
key: "readFace",
specSeat: "TaskSpec.readFace",
depsSeat: "readFace (deployment seat)",
depsOwnKey: "RunnerDeps.readFace",
noun: "open read face",
invalidCode: "config.read_face_invalid",
readOnlyConflictCode: "config.read_face_readonly_conflict",
orgEscalationCode: "config.read_face_org_task_escalation",
readOnlyWhy: `that mount's containment is load-bearing (its read-only shell face is confined by it) and is never openable.`,
clampWhy: `the mount's containment is load-bearing and never openable`,
},
write: {
key: "writeFace",
specSeat: "TaskSpec.writeFace",
depsSeat: "writeFace (deployment seat)",
depsOwnKey: "RunnerDeps.writeFace",
noun: "open write face",
invalidCode: "config.write_face_invalid",
readOnlyConflictCode: "config.write_face_readonly_conflict",
orgEscalationCode: "config.write_face_org_task_escalation",
readOnlyWhy: `that mount carries no write faces at all (the hand band's write half does not mount on it), so an open write face declares a posture for tools this call does not have.`,
clampWhy: `that mount carries no write faces for it to widen`,
},
};
export function containmentFaceSeatName(kind, layer) {
const d = FACE_DIALECT[kind];
return layer === "spec" ? d.specSeat : d.depsSeat;
}
export function assertContainmentFaceValue(v, kind, layer) {
if (v === undefined)
return undefined;
if (v === "open" || v === "roots")
return v;
const d = FACE_DIALECT[kind];
const e = new Error(`${containmentFaceSeatName(kind, layer)}: invalid ${d.key} value ${describeRejectedValue(v)} — expected "open" or "roots" (bad values refuse loudly; nothing falls back to a default).`);
e.code = d.invalidCode;
throw e;
}
export function resolveContainmentFace(i) {
const d = FACE_DIALECT[i.kind];
const spec = assertContainmentFaceValue(i.specFace, i.kind, "spec");
const deps = assertContainmentFaceValue(i.depsFace, i.kind, "deps");
const cause = i.readOnlyMount ? "read_only_mount" : i.kind === "read" && i.readBlock === true ? "read_block" : undefined;
if (cause !== undefined) {
if (spec === "open") {
if (cause === "read_only_mount") {
const e = new Error(`${d.key}: "open" contradicts the read-only (verifier) mount — ${d.readOnlyWhy} Drop the ${d.key} declaration or the readOnly mount.`);
e.code = d.readOnlyConflictCode;
throw e;
}
const e = new Error(`${d.key}: "open" contradicts blockReadsOutsideRoots — an open read face would read where this task refuses to read. Drop the ${d.key} declaration or blockReadsOutsideRoots.`);
e.code = "config.read_face_read_block_conflict";
throw e;
}
if (deps === "open" && spec === undefined)
i.onDeploymentClamp?.(cause);
return "roots";
}
if (i.orgGoverned) {
if (spec === "open") {
const e = new Error(`${d.specSeat}: "open" is refused under organization governance — the task layer may only tighten (set ${d.depsOwnKey}: "open" if the DEPLOYMENT declares the ${d.noun}).`);
e.code = d.orgEscalationCode;
throw e;
}
if (spec === "roots")
return "roots";
return deps ?? "roots";
}
if (spec !== undefined)
return spec;
if (deps !== undefined)
return deps;
if (i.modeFace !== undefined)
return i.modeFace;
if (!i.fullShellReachable)
return "roots";
return "roots";
}
export function deploymentFaceClampNotice(kind, cause) {
const d = FACE_DIALECT[kind];
const message = cause === "read_only_mount"
? `${d.depsSeat}: the deployment-wide "open" declaration is not in force on this read-only (verifier) mount — clamped to "roots" (stricter-wins: ${d.clampWhy}). Other mounts still honor "open".`
: `${d.depsSeat}: the deployment-wide "open" declaration is not in force on this leg, which refuses reads outside its directories (blockReadsOutsideRoots) — clamped to "roots" (stricter-wins). Other legs still honor "open".`;
const detail = { seat: d.depsSeat, declared: "open", inForce: "roots", cause };
return kind === "read"
? { code: "config.read_face_deployment_clamped", message, detail }
: { code: "config.write_face_deployment_clamped", message, detail };
}