@sema-agent/core
Version:
Stateless, task-oriented AI agent core
84 lines (83 loc) • 3.87 kB
JavaScript
import { describeRejectedValue } from "../../core/tool-search-setting.js";
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");
if (i.readOnlyMount) {
if (spec === "open") {
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;
}
if (deps === "open" && spec === undefined)
i.onDeploymentClamp?.();
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) {
const d = FACE_DIALECT[kind];
const message = `${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".`;
const detail = { seat: d.depsSeat, declared: "open", inForce: "roots", cause: "read_only_mount" };
return kind === "read"
? { code: "config.read_face_deployment_clamped", message, detail }
: { code: "config.write_face_deployment_clamped", message, detail };
}