@sema-agent/core
Version:
Stateless, task-oriented AI agent core
50 lines (49 loc) • 4.16 kB
TypeScript
/**
* The run loop's COMPACTION SEAMS, verbatim from three private methods of `Runner`: the Seam C
* cost-optimization options every `maybeCompact` call site spreads, the pre/postCompact hook-option wrapper and
* the consecutive-reuse counter fold. Layer-1 machinery under a name of its own (the S1 reading: a module the lanes stand
* on is not a lane) — the turn-boundary lane, the recovery lane and the terminal adoption's end-of-task pass reach DOWN
* for these three where the driver used to hand each lane the methods as delegates on its Input. Every function reads
* the Runner's deps LIVE through {@link RunnerDepsSeat}: `runner.deps.x` here is exactly `this.deps.x` in the method it
* came from, on the tick it is read.
*/
import type { HookInvocationIdentity } from "../hooks.js";
import type { MaybeCompactOptions } from "../auto-compaction.js";
import { type LegModBus } from "../mods/stations.js";
import type { Prepared, RunnerDepsSeat } from "./contracts.js";
/**
* The cost-optimization compaction options threaded into BOTH `maybeCompact` call
* sites (within-task turn boundary + `finish()`). All three fields come from `RunnerDeps` (a trusted
* FUNCTION seam — never `TaskSpec`, which is serializable/durable-resumable/untrusted-caller). The
* Runner OWNS the consecutive-reuse counter (`prepared.compactionReuseRef`) so the
* `maxConsecutiveProviderReuse` drift guard spans the whole task across both sites: it FEEDS the current
* count in as `consecutiveProviderReuse`, and {@link recordCompactionReuse} updates it from the result.
* The provider half is absent when no provider is wired (byte-identical to the prior behavior at every
* call site); the #1036 `onCommitted` effect sink rides unconditionally, which is why the
* function itself always returns an object.
*/
export declare function seamCCompactionOptions(runner: RunnerDepsSeat, prepared: Prepared): Pick<MaybeCompactOptions, "summaryProvider" | "onCompaction" | "maxConsecutiveProviderReuse" | "consecutiveProviderReuse" | "onCommitted">;
/** The Seam C PROVIDER half — the deployment's summary provider, its observer and its drift guard, fed the caller's
* consecutive-reuse count (a run's counter; `0` for a pass outside a run, which has no earlier reuse to count). Still
* provider-gated: with no provider wired the four keys stay ABSENT, so every caller spreads exactly what it spread
* before. */
export declare function summaryProviderOptions(runner: RunnerDepsSeat, consecutive: number): Pick<MaybeCompactOptions, "summaryProvider" | "onCompaction" | "maxConsecutiveProviderReuse" | "consecutiveProviderReuse">;
/** The pre/postCompact stations threaded into maybeCompact: `classic.PreCompact` and `classic.PostCompact` raised on the
* leg's bus (a station is wired only when a handler hangs on its event). Their failure and abort columns are the
* bus's — a handler that throws or runs past its budget is skipped and reported, so a failed gate is "no block, no
* instructions" and the compaction that was already deemed necessary proceeds. A `block` answered under a "forced"
* trigger is reported as ignored (maybeCompact enforces the ignore — blocking a compaction the provider/trim layer
* already demanded would kill the run). `signal` is the pass's abort (absent ⇒ each handler's own budget is the
* whole bound). */
export declare function compactionHookOptions(runner: RunnerDepsSeat, prepared: {
readonly modBus: LegModBus;
readonly hookIdentity: HookInvocationIdentity | undefined;
readonly sessionId: string;
}, trigger: "auto" | "manual" | "forced", signal: AbortSignal | undefined): Pick<MaybeCompactOptions, "trigger" | "preCompact" | "postCompact">;
/** Fold a finished compaction's `reused` flag into the run-scoped consecutive-reuse
* counter: a reused (provider) summary increments it, a real (LLM) summary resets it to 0. A no-op
* compaction (`compacted:false`) leaves the counter untouched. No-op when no provider is wired. */
export declare function recordCompactionReuse(runner: RunnerDepsSeat, prepared: Prepared, comp: {
compacted: boolean;
reused?: boolean;
}): void;