@sema-agent/core
Version:
Stateless, task-oriented AI agent core
226 lines (225 loc) • 11.9 kB
TypeScript
/**
* The one reading of a caller's {@link TaskSpec}. A spec is the caller's own object: a literal, a class instance, a bag with
* accessors, a Proxy. The run takes it through here once, at its entrance, and every reader after that — the session lock, the
* config doors, prepare, the leg, the backstop terminal — reads the snapshot this returns, never the caller's object again.
*
* Each member is read once, by name, through an ordinary property lookup (an inherited, non-enumerable, accessor-backed or
* Proxy-answered member included — the presence law the retired-key door states, `retired-keys.ts`), and a defined value lands
* as an own enumerable data member of a new plain frozen object: the snapshot reads exactly like an object literal spec, so any
* later copy (a spread included) keeps every member, and a getter's value is the one value the whole run sees. Values are taken
* by reference (a member's own contents — the tool roster's entries, a policy, a signal — are their own readers' to snapshot).
*
* Three refusals, each by name and recorded on the read (thrown where the run's prepare refuses, so a failed read ends the run
* as any prepare refusal does): a member whose lookup throws (`config.spec_member_unreadable`); a retired key the lookup answers
* (`config.spec_retired_key`, the retired-key door judged over the values just read); an own key (enumerable or not, string or
* symbol) that is neither a member nor a retired name — the engine's one name judgment, on the spec as given; an inherited key is
* no own key, so it is neither read as a stray nor refused — (`config.spec_unknown_key` — a key the engine never reads is refused,
* not carried silently).
*
* The one re-read the engine keeps is the tool roster's identity check (`refuseLateRosterChanges`, against the caller's own
* object): it compares objects, it does not take a value.
*/
import type { TaskSpec } from "./task-spec.js";
/** The two non-placeholder values of the member table's column — the member lives and dies with `sessionId`, so a run that is
* handed a new session of its own carries neither kind:
* - {@link SESSION}: the session's address and the run's demand on it (the session to continue, the requirement that it exists);
* - {@link ENTRY}: an operation a run performs on ENTERING that session — branch it at an entry, converge its files to a history
* boundary (and how), open on what is parked for it. The leg that enters performs it once; a later leg in the session an earlier
* leg of the same call entered carries none of them. */
declare const SESSION: "session";
declare const ENTRY: "entry";
/** Every {@link TaskSpec} member, by name — the type's own key set, fenced both ways (a member added to `TaskSpec` and not
* listed here, or a name here that `TaskSpec` does not declare, is a compile error). The value is a column: `0` for an
* ordinary member, {@link SESSION} or {@link ENTRY} for one that is bound to the spec's session. */
declare const SPEC_MEMBER_TABLE: {
taskId: 0;
objective: 0;
wake: "entry";
principal: 0;
isolationScope: 0;
actor: 0;
runOrigin: 0;
interactionPosture: 0;
approvalReach: 0;
interactiveQuestionFallback: 0;
images: 0;
userAttachments: 0;
sessionId: "session";
project: 0;
workspace: 0;
requireExistingSession: "session";
oneShot: 0;
clientContext: 0;
resumeAt: "entry";
resumeAtMode: "entry";
model: 0;
modelRole: 0;
roles: 0;
advisorModel: 0;
thinking: 0;
fastMode: 0;
systemPrompt: 0;
promptRole: 0;
promptForm: 0;
promptBinding: 0;
promptLocale: 0;
appendSystemPrompt: 0;
outputStyle: 0;
memory: 0;
suggestNextPrompts: 0;
fileHistory: 0;
projectMemory: 0;
instructionFamily: 0;
restoreFiles: "entry";
acceptPartialRestore: "entry";
unplacedHistoryRecordedUnder: "entry";
rewindFilesTo: "entry";
tools: 0;
allowTools: 0;
excludeTools: 0;
excludeAllTools: 0;
deferTools: 0;
toolMaterializeStrategy: 0;
alwaysLoadTools: 0;
restoreGatedTools: 0;
deferSelfResolve: 0;
promptLean: 0;
agents: 0;
toolPolicy: 0;
basePolicyForResumeEdit: 0;
onAsk: 0;
onQuestion: 0;
lspManager: 0;
lspDiagnostics: 0;
mods: 0;
peerPresence: 0;
durableApproval: 0;
resourceSuspend: 0;
preemptSignal: 0;
resilience: 0;
finalVerification: 0;
maxSuspends: 0;
checkpointStore: 0;
handsReadOnly: 0;
ownHandsReadOnly: 0;
runLedger: 0;
managerApproves: 0;
team: 0;
memoryPersistenceCapable: 0;
additionalDirectories: 0;
additionalReadDirectories: 0;
readDenyPatterns: 0;
readDenyBuiltinExclude: 0;
writeProtectedAdditions: 0;
agentConfigDirs: 0;
agentHomeDirs: 0;
complianceAdditionalDenies: 0;
readFace: 0;
writeFace: 0;
enablePlanMode: 0;
planFile: 0;
interactiveTools: 0;
enableFork: 0;
shellGate: 0;
permissionMode: 0;
classifyAllShell: 0;
blockReadsOutsideRoots: 0;
mcp: 0;
a2a: 0;
skills: 0;
userInvokedSkills: 0;
allowedTools: 0;
skillListingBudgetFraction: 0;
skillListingMaxDescChars: 0;
backgroundScope: 0;
sandbox: 0;
envFacts: 0;
limits: 0;
configOverrides: 0;
forwardSubagentEvents: 0;
retainSubagentSessions: 0;
retainBackgroundProcesses: 0;
outputSchema: 0;
outputRetries: 0;
tracer: 0;
toolResultThresholdChars: 0;
compaction: 0;
attachments: 0;
enableBlockedReport: 0;
selfOrchestration: 0;
getApiKeyAndHeaders: 0;
signal: 0;
language: 0;
};
/** Every {@link TaskSpec} member, by name. */
export declare const TASK_SPEC_MEMBERS: readonly string[];
/** The members the table marks as bound to the spec's session (either kind) — a name here is a member that means something only
* beside `sessionId` (`requireExistingSession` without one is refused, `resumeAt` / `resumeAtMode` branch the session it names,
* `restoreFiles` needs the `resumeAt` it restores to, `rewindFilesTo` / `acceptPartialRestore` / `unplacedHistoryRecordedUnder` address its file-history boundaries). */
export type SessionBoundSpecMember = {
[K in keyof typeof SPEC_MEMBER_TABLE]: (typeof SPEC_MEMBER_TABLE)[K] extends typeof SESSION | typeof ENTRY ? K : never;
}[keyof typeof SPEC_MEMBER_TABLE];
/** The session-bound members, in table order. */
export declare const SESSION_BOUND_SPEC_MEMBERS: readonly SessionBoundSpecMember[];
/** The session-bound members of the {@link ENTRY} kind — the operations a run performs on entering its session — in table order. A
* composition that never enters its caller's session ({@link enteringMembersOf}) refuses a spec that carries one. */
export declare const SESSION_ENTRY_SPEC_MEMBERS: readonly SessionBoundSpecMember[];
/**
* The spec for a run that gets a session of its own: the caller's spec without every session-bound member, by the table (never
* by a name written at the call site), so a member added to the column is dropped here too. A shallow copy — every other member
* rides by the same reference.
*/
export declare function withoutSessionBinding(spec: TaskSpec): Omit<TaskSpec, SessionBoundSpecMember>;
/**
* The {@link ENTRY} members the spec carries, in table order: those whose ordinary property lookup answers a defined value (the
* presence law the run's own read of its spec keeps, {@link readCallerSpec} — an inherited or accessor-backed member counts, a member
* present with no value does not) other than `false`, which a flag member answers when it asks for nothing (a run that is handed
* `restoreFiles: false` restores no file). A composition whose legs never enter the caller's session reads this at its door: what the
* spec asks of the session's entry is not something any of its legs would perform. A lookup that throws is the lookup's own throw.
*/
export declare function enteringMembersOf(spec: Partial<TaskSpec>): readonly SessionBoundSpecMember[];
/**
* THE one judgment of a leg that continues work already done in a session: it requires that session to still exist
* (`requireExistingSession`), whatever the caller wrote. A session gone in between is a refusal (`resume.session_not_found`) before
* the leg reaches the model — never a leg that runs cold on a newly created empty session and a composition that reports it done.
* Two kinds of leg are instances of it and call it, and no leg states the demand itself: a later leg of a composition
* ({@link withOpeningObjective} with `continues`: the session the leg before it reported) and a resumed repair loop's first attempt
* (the session its spec names, whose transcript holds the task it sends no second time). `session` empty or absent is no session to
* continue (the absence of one, as `sessionId: ""` reads everywhere): the leg carries no such demand. A shallow copy.
*/
export declare function continuingSession(spec: TaskSpec, session: string | undefined): TaskSpec;
/**
* The spec of a leg a composition opens on an objective of its own, from the caller's spec. A leg opens on exactly one input (the
* door refuses `wake` beside an objective), and the objective is this one's.
* - Without `continues`: the leg that ENTERS the caller's session (a resumed repair loop's first attempt) — every member of the column
* stays but `wake`.
* - With `continues`: a LATER leg, in the session an earlier leg of the same call entered (a fix leg, a later repair attempt, a later
* goal iteration) — the leg runs in `continues`, and every {@link ENTRY} member is dropped, by the table: the earlier leg performed
* those on entering, and carried into a later leg each would be performed again (a rewind written back over the earlier legs' files,
* a branch that drops their turns). It continues the session the leg before it left, so it requires it ({@link continuingSession}).
* A member added to the column is read here as its kind says. A shallow copy, as {@link withoutSessionBinding}.
*/
export declare function withOpeningObjective(spec: Omit<TaskSpec, "objective">, objective: string, continues?: string): TaskSpec;
/** What one read of a caller's spec answered: the snapshot every reader reads, the caller's own object (for the roster's identity
* check only), and the refusal the read met (thrown at prepare's door), if any. */
export interface CallerSpecRead<S extends Partial<TaskSpec> = TaskSpec> {
readonly spec: S;
readonly caller: S;
readonly refusal: (Error & {
code: string;
}) | undefined;
}
/**
* Read the caller's spec once (see the module note). Never throws for a spec that is an object: a refusal is recorded on the read
* and thrown at prepare's door; a spec that is no object at all is a `TypeError`, as any member read of it would be. `takeSeat`: the
* Runner's entrance takes the per-model auth seat in this same step (`swappable-deps.ts` `takeSeat`), so the snapshot holds the
* seat it took; a snapshot handed back in answers its own read, its seat as taken then.
*/
export declare function readCallerSpec<S extends Partial<TaskSpec>>(spec: S, takeSeat?: (seat: TaskSpec["getApiKeyAndHeaders"]) => TaskSpec["getApiKeyAndHeaders"]): CallerSpecRead<S>;
/**
* The run's spec with `members` laid over it, as the SAME read: the new snapshot answers {@link readCallerSpec} with the read of
* `snapshot` — its caller's object and its refusal — so a member the engine fills in at the run's entry (a saved team's recipe seats)
* is read like every member the caller wrote, and nothing the read recorded is lost. `snapshot` is a snapshot this module minted.
*/
export declare function rereadWith<S extends Partial<TaskSpec>>(snapshot: S, members: Partial<TaskSpec>): S;
export {};