@sema-agent/core
Version:
Stateless, task-oriented AI agent core
91 lines (90 loc) • 5.73 kB
TypeScript
import type { SessionStore } from "../session.js";
import type { RunnerDeps, TaskSpec } from "../types.js";
import type { RosterSpec } from "./caller-roster.js";
import type { PrepareResume, RunInternals, ToolFaceSnapshot } from "./contracts.js";
/**
* The SINGLE effective-delegation derivation for a leg, minted once per prepare
* and read by EVERY consumer face; two facets, one source:
*
* - `isDelegatedChild` — the raw delegation fact, forks included. Trusted internals first; on a
* resume leg where the caller supplied NO delegation fact, the checkpoint's persisted axis
* ({@link import("../checkpoint-store.js").CheckpointState.isDelegatedChild}) stands in — else a
* deps-only `resume(token, outcome, config)` of a parked delegation read `false` at every station:
* persona flip (subagent consent/notes pack dropped), ask refusal texts on the parent-thread arm
* ("wait for the user" in a transcript no user turn ever lands in), and a lifecycle-observer gate
* that never opened. Consumed by the ask source mint (a fork's refusal posture is the child's) and
* the `hookIdentity` mint.
* - `isNonForkChild` — the fact minus forks, for the authority/context faces: the memory injection's
* `isSubagent` and the prompt runtime fact `isSubagent` (the `SUBAGENT_CONSENT_NOTICE` gate). A FORK
* is excluded on both, deliberately:
* a fork IS the parent continuing, so it inherits the parent's authority — and, on the
* memory face, the parent's own project context; trimming a fork's CLAUDE.md would hand the
* continuation LESS context than the run it continues. (The memory face must not use
* `parentTaskId !== undefined` alone, which {@link RunInternals.isDelegatedChild}'s own docstring
* forbids — a directly-started workflow's children have no nameable parent.)
*
* `insideFork` is NOT persisted (the checkpoint's documented honest absence), so on a deps-only resume
* a FORK child reads as a plain delegated child on the non-fork facet — the honest residue is written
* on the checkpoint field's own list, not papered over with a new persistence axis.
*/
export declare function effectiveDelegationFacts(internals: Pick<RunInternals, "isDelegatedChild" | "insideFork"> | undefined, seedIsDelegatedChild: boolean | undefined): {
isDelegatedChild: boolean;
isNonForkChild: boolean;
};
export interface TaskStartDoorsInput {
/** borrowed-readonly — the leg's spec as the Runner read it (`readCallerSpec`), or a caller's own spec when prepare runs outside a Runner. */
request: TaskSpec;
/** borrowed-readonly — the deployment's seats; the doors rebind the role map once and hand the rebound deps back. */
deps: RunnerDeps;
/** borrowed-readonly — the session store the leg would acquire from; only its declarations are read (the retention door). */
sessions: SessionStore;
/** borrowed-readonly — the resume leg, when the leg is one. */
resume?: PrepareResume | undefined;
/** borrowed-readonly — the trusted internals the leg is started with. */
internals?: RunInternals | undefined;
/** borrowed-readonly — the seat the interaction-posture refusal is also disclosed on (`phase: "config"`); absent ⇒ the refusal is only thrown. */
refusalSink?: RunnerDeps["onError"] | undefined;
}
/** Everything the doors read, judged and resolved — the bindings `prepareTask` goes on with. */
export declare function taskStartDoors(input: TaskStartDoorsInput): {
callerRoster: {
spec: import("./caller-roster.js").CallerRosterSpec;
roster: import("./caller-roster.js").CallerRosterSnapshot;
refusal: import("../task-spec-members.js").CallerSpecRead["refusal"];
};
mountsCallerTool: (tool: import("../tool-spec.js").ToolSpec) => boolean;
permissionModeSeat: "auto" | "default" | "plan" | "acceptEdits" | "bypassPermissions" | "dontAsk" | undefined;
doors: import("./prepare-config-doors.js").PrepareConfigDoorsResult;
spec: RosterSpec;
deps: RunnerDeps;
checkpointStore: import("../checkpoint-store.js").CheckpointStore | undefined;
checkpointSeat: import("../checkpoint-seat.js").CheckpointSeat | undefined;
outputStyleSeat: import("../output-style.js").OutputStyleSeat | undefined;
languageDeclared: string | undefined;
allowedTools: readonly import("../allow-entry.js").AllowListEntry[] | undefined;
userAttachmentsSeat: readonly import("../user-attachment.js").ScreenedUserAttachment[] | undefined;
safety: import("./prepare-safety-scan.js").PrepareSafetyScanResult;
ownToolLists: {
readonly toolName: string;
readonly definition?: string;
readonly lists: string;
} | undefined;
delegation: {
isDelegatedChild: boolean;
isNonForkChild: boolean;
};
approvalParkNotResumable: import("../park-resumability.js").ApprovalParkNotResumable | undefined;
notResumableSays: import("../park-resumability.js").ApprovalParkNotResumable | undefined;
toolLegs: ("delegated" | "teammate" | "goal" | "observer" | "structured")[];
toolCeiling: readonly import("../tool-face.js").ToolSelectorLayer[] | readonly {
readonly allow?: readonly string[];
readonly deny: readonly string[];
}[] | undefined;
toolListsJudged: string | undefined;
toolFaceSnapshot: ToolFaceSnapshot;
toolCeilingRead: import("../tool-face.js").ToolSelectorLayer[] | undefined;
fileHistoryRequest: import("./file-history-request.js").FileHistoryRequest;
retiredNames: import("../tool-name-aliases.js").RetiredNameView;
};
/** What {@link taskStartDoors} hands back. */
export type TaskStartDoors = ReturnType<typeof taskStartDoors>;