@sema-agent/core
Version:
Stateless, task-oriented AI agent core
65 lines (64 loc) • 4 kB
TypeScript
/**
* Opening a session's files for an OUT-OF-RUN verb — `Runner.rewindFiles` and `Runner.readSessionChanges` — written once, in one
* order, so the two verbs cannot disagree about which session's files they reach or in which order they say no:
*
* ① hands — the verb's env is a filesystem (a minted or static env, not the no-I/O stub);
* ② the target is an entry of THIS session's own log ({@link entryInOwnLog});
* ③ the session's row, read once for its history address (`fileHistoryScopeOf`) and its fork lineage;
* ④ the session's root ({@link sessionRootOf}: its own tree when it works in one);
* ⑤ a fork that works in a tree of its own ({@link forkHasOwnTree});
* ⑥ the history coordinates on that root ({@link resolveFileHistoryCoordinates}).
*
* A verb skips what it does not read: no target ⇒ no ②; no working tree ⇒ no ① ④; no history ⇒ no ③ ⑤ ⑥. Three steps answer a fact
* the verb reads its own way (the rewind throws its refusal, the read answers a word): ① no hands, ② a target outside the log, ⑤ a
* fork with a tree of its own. Two throw as they always did, whichever verb asks: ③ a row that cannot be read (the verb's own refusal,
* `rewind.restore_failed`, transient — no address, nothing to read or restore from), ④ a checkout that cannot be resolved (the
* checkout's own code, the verb's sentence first); ⑤ throws `workspace.checkout_unavailable` for a fork whose record cannot be read.
* The fork carry and everything after the coordinates are the verb's own (a read carries nothing).
*/
import type { ExecutionEnv, Session, SessionMetadata } from "../../internal/harness-types.js";
import type { SessionStore } from "../session.js";
/** What a verb asks {@link openSessionFiles} to open. */
export interface SessionFilesOpenInput {
readonly session: Session;
readonly sessionId: string;
/** ① ④ — the verb reads or writes the working tree: its hands (`undefined` = the verb's env is no filesystem — none was mounted, or
* the factory did not answer its purpose: ① answers `no_hands`), each the env and the root a leg of the session is handed (the base
* checkout); and the sentence a checkout that cannot be resolved is refused with (what the verb did not do). Absent ⇒ no ① ④. */
readonly tree?: {
readonly hands: {
readonly env: ExecutionEnv;
readonly baseRoot: string;
} | undefined;
readonly refusedAs: string;
readonly sessions: Pick<SessionStore, "acquire">;
};
/** ② — the entry the verb names. Absent ⇒ no ②. */
readonly target?: string;
/** ③ ⑤ ⑥ — the verb reads the session's history: the refusal a row that cannot be read is thrown as. Absent ⇒ no ③ ⑤ ⑥. */
readonly history?: {
readonly unaddressed: () => Error;
};
}
/** The session's history as ③ ⑥ read it: its row's lineage, its own scope, and the scope and root its history is keyed at
* (`historyRoot` is `""` where the verb did not open the tree, as {@link resolveFileHistoryCoordinates} answers a leg with no root). */
export interface OpenedSessionHistory {
readonly row: Pick<SessionMetadata, "incarnation" | "forkedFrom" | "forkedFromIncarnation">;
readonly ownScope: string;
readonly historyScope: string;
readonly historyRoot: string;
}
/** What {@link openSessionFiles} answers: the three facts a verb reads its own way, or what it opened. */
export type SessionFilesOpened = {
readonly kind: "no_hands";
} | {
readonly kind: "target_outside_log";
} | {
readonly kind: "fork_with_own_tree";
} | {
readonly kind: "opened";
readonly sessionRoot: string | undefined;
readonly history: OpenedSessionHistory | undefined;
};
/** Open a session's files for an out-of-run verb, in the module's one order (see the header). */
export declare function openSessionFiles(input: SessionFilesOpenInput): Promise<SessionFilesOpened>;