@sema-agent/core
Version:
Stateless, task-oriented AI agent core
61 lines (60 loc) • 3.13 kB
JavaScript
export const MANAGER_LAUNCH_ITEMS = Object.freeze([
"background_delegation",
"report_tool",
"read_hands",
"worker_transcript",
"worker_write_approval",
"task_list",
]);
const REFUSING = new Set(["background_delegation", "report_tool"]);
const NARROWED = {
background_delegation: "it cannot dispatch workers that report back, so it cannot direct anyone",
report_tool: "it has no report tool, so nothing it concludes reaches the person with the engine's ledger beside it",
read_hands: "it cannot read the work itself; it can only send workers to look",
worker_transcript: "it cannot read a worker's record; it sees only what each worker says",
worker_write_approval: "a worker's writes will be refused: nobody on this run can approve them",
task_list: "the plan cannot be kept as a shared task list",
};
const ITEM_WORDS = {
background_delegation: "dispatching workers that report back",
report_tool: "the report tool",
read_hands: "reading the work",
worker_transcript: "reading a worker's record",
worker_write_approval: "an approval route for the workers' writes",
task_list: "a shared task list",
};
export function managerLaunchNarrowedNotice(c, ids) {
return { code: "task.manager_launch_narrowed", message: managerLaunchCheckSentence(c), detail: { ...ids, launch: c } };
}
export function managerLaunchCheck(facts) {
const items = MANAGER_LAUNCH_ITEMS.map((item) => {
const v = facts[item];
const state = v === true ? "ok" : v === false ? "missing" : "unknown";
return Object.freeze({ item, state, ...(state === "missing" ? { means: NARROWED[item] } : {}) });
});
const missing = items.filter((i) => i.state === "missing");
const verdict = missing.some((i) => REFUSING.has(i.item)) ? "refused" : missing.length > 0 ? "narrowed" : "ready";
return Object.freeze({ verdict, items: Object.freeze(items) });
}
export function managerLaunchFactsOf(r) {
const has = (...names) => names.every((n) => r.names.has(n));
return {
background_delegation: r.backgroundAgents === undefined ? undefined : r.backgroundAgents && r.completionLane,
report_tool: has("SendUserMessage"),
read_hands: has("Read", "Grep", "Glob"),
worker_transcript: has("AgentTranscript"),
worker_write_approval: r.approver ? true : !r.parkStore && r.oneShot ? false : undefined,
task_list: has("TaskCreate", "TaskList"),
};
}
export function managerLaunchCheckSentence(c) {
const missing = c.items.filter((i) => i.state === "missing");
const unknown = c.items.filter((i) => i.state === "unknown").map((i) => ITEM_WORDS[i.item]);
const said = missing.map((i) => i.means).join("; ");
const unread = unknown.length > 0 ? ` Not read here: ${unknown.join(", ")}.` : "";
if (c.verdict === "ready")
return `The launch check found everything this run needs.${unread}`;
if (c.verdict === "refused")
return `This run declares a member ledger but cannot do that job — ${said}.${unread}`;
return `This run starts narrowed — ${said}.${unread}`;
}