@sema-agent/core
Version:
Stateless, task-oriented AI agent core
376 lines (375 loc) • 29.2 kB
TypeScript
import type { AssistantMessage } from "../../internal/llm.js";
import type { HumanReviewGateRow } from "../task-result.js";
import type { NestedUsage, PausedCause, TaskResult, TerminalCause } from "../types.js";
import type { TerminalBlockedDetail } from "../terminal-cause.js";
import type { HaltConsumption, LoopTerminalReason } from "../../internal/harness.js";
import type { PostureSeatsSource } from "./contracts.js";
import { type RewindOutcome } from "./rewind-outcome.js";
/** Per-task usage/cost accumulator (filled across the run loop, surfaced as `TaskResult.stats`). */
export interface Stats {
turns: number;
tokens: number;
/** Total tool calls executed (one per `tool_start`). Spread into `TaskResult.stats`. */
toolCalls: number;
/** Prompt tokens that MISSED the cache (Anthropic-protocol `input_tokens` shape). */
promptTokens: number;
cachedTokens: number;
cacheWriteTokens: number;
cacheWriteTokensLong: number;
outputTokens: number;
cacheHitRate?: number;
/** The cache account's marks, exclusions and per-lane operands (`./cache-hit-account.ts`; the public faces are documented on
* `TaskResult.stats`). `cacheLanes` is run-loop internal, stripped at assembly. */
cacheReadUnreported?: true;
cacheWriteUnreported?: true;
cacheHitRateExcludes?: import("./cache-hit-account.js").CacheHitExclusion[];
cacheLanes?: import("./cache-hit-account.js").CacheLanes;
/** Cache-INCLUSIVE prompt total (`promptTokens + cachedTokens + cacheWriteTokens`; the one-hour writes are a part of the last) — the
* billing/window/hit-rate denominator. Required (not derived) so a new accumulation site that forgets
* it fails the type check instead of silently reporting a total short by its own leg. */
totalInputTokens: number;
costMicroUsd: number;
/** Wall time of this leg's main-loop model calls, summed (`bookMainCall`; the `brain.call` rows' `latencyMs`); a leg's run starts it at 0. */
apiDurationMs?: number;
/** Main-loop calls served at fast speed (`TaskResult.stats.fastSpeedCalls`); absent while none was. */
fastSpeedCalls?: number;
/** Present (`true`) when at least one model round of this leg reported NO usage frame (the brain's
* own `usageMissing` mark on the assistant message: an aborted / errored / usage-less provider reply). The
* numeric fields stay required and stay what was COUNTED — with this key present they are a LOWER BOUND,
* not a measurement ("0 is unknown, not free"). Absent ⇔ every round reported usage. */
usageMissing?: true;
nested?: NestedUsage;
/** Post-task memory-consolidation usage; set after the result is assembled. Kept out of
* the budget gate (`overBudget` reads `costMicroUsd`/`tokens`, never this). */
memory?: {
tokens: number;
costMicroUsd: number;
applied: number;
};
/** Human-review burden. Wall-clock approval-gate wait + count, bucketed by
* `gate.kind`, accumulated across resume legs. Set by the run loop from the per-task human-review
* accumulator (synchronous `resolveAsk` timing + durable resume latency). **NOT an LLM cost** — never
* folded into `costMicroUsd`/`costBreakdown`/the budget gate (same budget-excluded treatment as `memory`).
* Flows straight through to `TaskResult.stats.humanReview` via the public-stats spread (`TaskResult.stats.humanReview`
* says when it is present). */
humanReview?: {
count: number;
totalWaitMs: number;
gates: HumanReviewGateRow[];
};
/** TB telemetry B2: engine-mechanism engagement counters. Set by the run loop
* only when ≥1 engaged; flows straight through to `TaskResult.stats.mechanisms` via the
* public-stats spread. */
mechanisms?: {
finalVerifyInjections?: number;
attachmentsInjected?: number;
repetitionCuts?: number;
repetitionSpared?: number;
repetitionEvents?: Array<{
turn: number;
action: "cut" | "spared";
rule: "char-run" | "unit-loop";
period: number;
reps: number;
segment: string;
}>;
};
/** Within-task compaction LLM cost (micro-USD), accumulated by
* `recordCompactionUsage` as a SEPARATE running total because that cost IS folded into `costMicroUsd`
* (so it can't be re-derived from `costMicroUsd` alone). The {@link costBreakdown.compactionMicroUsd}
* source. Run-loop internal — not a public `TaskResult.stats` field. */
compactionMicroUsd?: number;
/** The permission classifier's, a mod's and the advisor tool's model-call cost (micro-USD), accumulated by `recordSideCallUsage`. Folded
* into `costMicroUsd` like compaction, but it STAYS inside {@link costBreakdown.llmRootMicroUsd} (an "of which" line,
* not a partition member). Absent until a call is booked. Run-loop internal — the public figure is
* `costBreakdown.sideCallMicroUsd`. */
sideCallMicroUsd?: number;
/**
* A thin FINANCE TAXONOMY of the LLM-derived costs the engine actually
* prices, decomposing the task's spend into report categories (no new persisted structure — derived from
* the cost sources that already exist). CORE = LLM-token-derived ONLY; the SERVICE adds the infra axes it
* owns (tool-call / sandbox-walltime / egress — it has the k8s cost data) and composes them with this.
* Each category is ≥ 0 and the parts reconcile to the independently-summed LLM total
* (`llmRoot + nestedSubagent + compaction` — `memory` is a separate, budget-excluded line, see its doc).
* Filled in assembleResult for `llmRoot`/`nestedSubagent`/`compaction`; the `memoryConsolidation` line is
* permanently 0 since B19 retired the runner-integrated consolidation pass (field kept — it is
* public stats contract; an engine-plane re-mount would fill it again).
*/
costBreakdown?: {
/** Root-agent LLM cost (micro-USD): `costMicroUsd` MINUS the sub-categories already folded into it
* (compaction). NOT minus nested — nested subagent cost is tracked separately and is NEVER folded into
* `costMicroUsd` (it lands only in `stats.nested`), so subtracting it would under-report the root. */
llmRootMicroUsd: number;
/** Delegated sub-agent (nested) LLM cost (micro-USD) = `stats.nested?.costMicroUsd ?? 0`. */
nestedSubagentMicroUsd: number;
/** Within-task compaction LLM cost (micro-USD) = the running `compactionMicroUsd` accumulator (the
* category Framing-4 missed). This IS part of `costMicroUsd`, so it is subtracted from `llmRoot`. */
compactionMicroUsd: number;
/** Side model-call LLM cost (micro-USD) — the permission classifier's and mods' calls — present once one is booked.
* An "of which" line: it is part of `costMicroUsd` AND of `llmRootMicroUsd` (not subtracted from root), so the
* partition `llmRoot + compaction === costMicroUsd` keeps holding. */
sideCallMicroUsd?: number;
};
}
/** The two cumulative budget ceilings a task can trip. Tokens outrank cost when both are
* over at the same boundary. */
export type BudgetAxis = "tokens" | "cost";
/**
* The terminal-state flags the run loop hands {@link assembleResult} — the typed contract between the
* loop and result assembly (exported so it's grep-able and tests can construct it).
*/
export interface ResultFlags {
threw: unknown;
/** The run's ENGINE-minted identity (`Prepared.runId`), echoed verbatim on
* `TaskResult.runId`. Pure pass-through on every terminal: assembly neither mints nor derives it
* (a caller reaching assembly at all has completed prepare, so the value exists), and a
* hand-constructed flags bag without one simply produces a result without one. */
runId?: string;
/** The EFFECTIVE (resolved) model id that served the task — echoed on `TaskResult.model`. */
model?: string;
/** Some spend was accounted while the serving model had NO configured price table
* (no `RunnerDeps.pricing` entry, no `Model.cost`). The numeric total is then a fabricated
* undercount — `stats.costMicroUsd`/`costBreakdown` are OMITTED from the public result instead of
* reporting a 0 indistinguishable from "declared free". The internal accumulator (budget gate's
* coordinate) is untouched. */
unpricedSpend?: boolean;
/** Prepare-time rewind disclosures to echo on `TaskResult.rewindNotes`.
* Pure pass-through — assembly neither adds nor filters (a rewind that FAILED never reaches here; it
* throws at prepare and lands in the `threw` slot as a terminal errorCode). */
rewindNotes?: TaskResult["rewindNotes"];
/** The leg's record of what its rewind did ({@link RewindOutcome}): read once at the return ({@link withRewindOutcome}). Absent on a
* leg that asked for no rewind. */
rewindOutcome?: RewindOutcome;
/** The run's OWN edited-file ledger, echoed on `TaskResult.editedFiles`. Pure pass-through on
* EVERY terminal — what this run's hands changed is a fact about the leg that ran, whatever
* terminal it reached (a failed/aborted run that edited files is exactly the case a "restore the
* code this message changed" affordance is for). Undefined ⇒ the key is omitted. */
editedFiles?: TaskResult["editedFiles"];
/** The run's final turn was halted by a person's BARE rejection of a tool call (the parent-thread
* control-flow boundary) — echoed on `TaskResult.haltedOnUserRejection`. Pure pass-through on
* every terminal: the fact is about the leg that ran, whatever terminal it reached (on the normal
* path the terminal is `completed`, and this is what tells that completion apart from a natural
* one — the model did not finish; the person stopped it and the run awaits their direction). */
haltedOnUserRejection?: boolean;
/** the harness's STATEMENT of what the run's halt did (see `HaltConsumption`):
* the loop's report that the halt's (or an extension's) cut settled the final turn, and/or the boundary consult that
* stopped the loop for the halt's request. This is the ONLY input to `TaskResult.haltedByUser` / `turnAbortedBy`
* (halt-attribution.ts) and to slot 9.7 — the assembly never infers causation from the
* final's shape or from the verb's acceptance. A halt that was accepted but consumed nothing (the run
* ended for its own reason first) leaves this empty: the original terminal stands and the seat is
* NOT signed (the settle lane mints `task.halt_unconsumed` for it). */
haltConsumption?: HaltConsumption;
answerEntryIds?: readonly string[];
intake?: TaskResult["intake"];
/** What the leg's display showed of those messages when a handler changed it or the caller's stop cut it short (`MessageDisplay.displayedOf`):
* `result` is then that text (same projection); `by` names who changed it, `inPart` says the display ended with text of the model's unshown. */
displayed?: {
readonly text: string;
readonly by: readonly string[];
readonly inPart?: true;
};
/** Call ids of answered-but-never-collected questions, echoed on
* `TaskResult.strandedHumanAnswers`. Pure pass-through; empty/absent ⇒ the field is omitted. The
* optional `onError` alert is NOT the disclosure — this mandatory result face is. */
strandedHumanAnswers?: TaskResult["strandedHumanAnswers"];
/** The run's remote-workspace lifecycle failures, echoed on `TaskResult.remoteEnvFailures`.
* Pure pass-through (assembly neither adds nor filters) and INDEPENDENT of the status/errorCode chain:
* a refused `suspendVM` still ends the task exactly the way it did before — this only stops the eleven
* distinct codes from arriving as one anonymous `limits.max_turns_exceeded`. Empty/absent ⇒ the field is omitted. */
remoteEnvFailures?: TaskResult["remoteEnvFailures"];
/** The asks the run refused because nobody could answer them, echoed on `TaskResult.refusedAsks`; empty/absent ⇒ omitted. */
refusedAsks?: TaskResult["refusedAsks"];
/** The run's refusal records as a result of this kind carries them (`final`: not paused) — echoed on `TaskResult.refusedToolCalls`
* and `TaskResult.verdictRefused` (the verdict ledger's `recordsOf`: a paused result carries no verdict record, and the calls that
* record would count are then counted as the ordinary refusals they are); and whether the leg's last verdict end was a refusal
* (an output-retry cap that tripped on refusals says so, not that the model produced no valid output). */
refusalRecords?: (final: boolean) => {
readonly refusedToolCalls?: TaskResult["refusedToolCalls"];
readonly verdictRefused?: TaskResult["verdictRefused"];
};
verdictLastEndRefused?: boolean;
/** The leg's postures ({@link resultPostureSeats}): the prepared leg, read by the one assembly of its posture seats. INDEPENDENT of
* the status/errorCode chain — the posture is a fact about the leg that ran, whatever terminal it reached. */
posture?: PostureSeatsSource;
/** The byte floor's latch as the leg ends ({@link TaskResult.readDenyFloor}): the rows of its unkept judgment (any table it compiled, at prepare or after), else `false`. Pass-through, every terminal (the posture law). */
readDenyFloorUnkept?: import("../../tools/fs/read-floor.js").ReadFloorRows | false;
/** The memory-visibility observation, echoed on
* `TaskResult.effectiveMemoryScopes`. Pure pass-through on every terminal, same law as the
* read-posture seats above: present iff prepare completed (the memory-less states are their own
* values — absence means only "prepare never ran to completion"). */
effectiveMemoryScopes?: TaskResult["effectiveMemoryScopes"];
/** The leg's frozen placement fixed point, echoed on `TaskResult.placementRoot`. Pure pass-through on every terminal (the
* same law as the observation seats above); absent ⇒ the key is omitted. */
placementRoot?: TaskResult["placementRoot"];
/** The leg's effective reasoning resolution, echoed on `TaskResult.effectiveReasoning`.
* Pure pass-through on every terminal (same law as the read-posture seats): the SAME object the
* `reasoning.resolved` trace frame carried (runtask resolves once per leg — two faces, one mint);
* absent when thinking was off/unset for the leg, so the key is omitted. */
effectiveReasoning?: TaskResult["effectiveReasoning"];
/** The leg's fast-mode reading at its end, echoed on `TaskResult.fastMode`; absent ⇒ the key is omitted. */
fastMode?: TaskResult["fastMode"];
/** The run's compaction record (see `TaskResult.compaction`); assembly omits the key when absent. */
compaction?: TaskResult["compaction"];
/** ruled 2026-08-04 — the usage-governance wait hint carried by the platform terminal the run adopted
* (`undefined` for every other cause: an expiring environment has no return time to give, and a store
* failure is not a window). Passed as data rather than read back off `threw` so the seat has a typed
* producer. The assembler still gates it on the SETTLED errorCode, so a hint that arrived alongside a
* higher-ranked terminal is dropped instead of being filed under a code that does not name it —
* see `TaskResult.retryAfterMs` for the in-presence condition this preserves. */
retryAfterMs?: number;
abortedForTimeout: boolean;
abortedForTurns: boolean;
/** audit A-1: the abort signal fired DURING the run (user interrupt / timeout / max-turns / budget),
* captured before the run loop's unconditional release-abort. Since the loop now exits CLEANLY on an
* abort (no synthetic stopReason:"aborted" assistant is appended), `final` is the last REAL assistant
* message — this flag is what keeps an interrupted run from being mistaken for a completed one. */
abortedLive?: boolean;
/** The leg's ONE evaluation of {@link answerSettled} (a clean `"stop"` final with no queued continuation
* lost): a live abort that found this true landed on the run's tail, not on work — slot 9 stands down
* and the run takes the completed floor. Absent/false = the abort's ordinary reading. */
answerSettled?: boolean;
/** The task axis the run ended past, evaluated once at the settle ({@link import("./clock-and-limits.js").limitCrossedOf}) and echoed on `TaskResult.limitCrossed` only when the terminal is `completed` (a run that owed another request fails or parks on its axis, and says it there). */
limitCrossed?: TaskResult["limitCrossed"];
budgetHit?: "exceeded" | "precall";
/** The spend account's refusal that ended the run's loop: on a ceiling (`budgetHit: "precall"`, which node held it and its
* figures) or on a closed account (`spend.account_closed`). */
spendStop?: import("../spend-account.js").SpendStop;
/** Which budget ceiling the hit belongs to. Set together with {@link budgetHit} at every
* site that records one; it picks the terminal code (`limits.max_tokens_exceeded` vs
* `limits.max_cost_exceeded`), so a hit without an axis would be an unattributable terminal. */
budgetAxis?: BudgetAxis;
blockedReason?: string;
blockedDetail?: TerminalBlockedDetail;
/** The leg's write-boundary latch as the result reads it (`Prepared.writeRefusal`): `conflict` — a session write lost the
* optimistic lock (slots 6 / 11); `holder.superseded` — a session write was refused for the run's grant (slot 0). */
writeRefusal?: "conflict" | "holder.superseded";
/** The request-build guard threw the irreducible-core terminal this run (the trim's core or the git frame's) — the loop
* folded it into a text-only failure message, so the typed code rides this flag. */
coreOverBudget?: boolean;
outputInvalid?: boolean;
/** The word the loop's last exit named (`Prepared.loopTerminalRef`), read through `loopExitFailureOf`; absent = the loop never exited. */
loopTerminal?: LoopTerminalReason;
/** A re-suspend was refused because the task already suspended `maxSuspends` times
* (a resume/restart loop). It aborted the run (no `threw`) but must read as `failed`/`suspend.loop`,
* NOT `suspended` — slotted ABOVE `suspendRef` and the aborted branches (this suspend never minted a
* checkpoint, so `suspendRef` is unset anyway; the ordering makes the intent explicit). */
suspendLoop?: boolean;
/** The run's ONE committed durable pause (the holder's `pausedRef.current.cause`): the run stopped at a
* gate — an approval or content ask, a resource slice, a platform pause, a plan or dry-run review —
* and a checkpoint is durably committed. It used an abort to stop the loop (`final.stopReason ===
* "aborted"`) but set no `threw`/timeout/turns, so it is slotted ABOVE the `!final`/aborted arms (a
* clean pause, not a failure) and BELOW the real budget/threw failures (a limit that coincided still
* owns the ending). WHICH terminal status it reads (`suspended` / `needs_review`) is the pause's own
* `gate.kind` registry row, not a second flag: the two same-shaped refs that used to split the approval
* family from the review family — and the slot order between them that only ever mattered if both were
* somehow set — are gone with the commit-side routing that fed them. */
paused?: PausedCause;
}
/**
* WHY the run ended — the ONE terminal arbitration ({@link TerminalCause}). First match wins, in the
* slot order documented on {@link assembleResult} (a public contract: do not reorder). Every plane
* field a result shows (`status`, `errorCode`, `errorMessage`, `blockedReason`, the checkpoint seats)
* is projected from the value this returns by {@link terminalProjection}, so a terminal that carries a
* token cannot be reported under a status that does not, and a review pause cannot be reported as an
* approval pause: the pairing is the cause's shape, not the arbitration's discipline.
*
* `apiFailure` rides beside the cause rather than inside it on purpose: it is the message's own
* provider-failure disclosure, filled only when a provider failure IS the terminal (the same
* in-presence rule the usage-window wait hint states for itself), and it is not part of the cause's
* public projection.
*/
/**
* Has the run's ANSWER settled — is `final` the model's own clean end of its work? A run whose last turn
* ended `stopReason:"stop"` has said everything it was going to say; whatever ran after that turn (the
* final boundary's compaction, a stop hook, the teardown) is the run's tail, not its work. A hard stop
* that lands in that tail — `TaskStream.interrupt()`, the task's `signal`, the walltime or turns limit —
* cuts nothing the person or the caller wanted, so the run is NOT cancellable there: it ends `completed`
* with the answer as `result` (slot 9 yields to the completed floor), no interruption marker is written
* for it, and the end-of-task hook seats keep their full deadline. One predicate, read by every site that
* used to decide the question for itself; there is no second spelling.
*
* What does NOT count as settled — each is "the model was still working" and stays cancellable:
* - `stopReason:"length"` — the output was truncated; the auto-continue chain owns what follows;
* - `stopReason:"toolUse"` — a batch was in flight (the orphan reconcile owns the abort);
* - `stopReason:"aborted"` / `"error"` — the turn itself was cut or failed;
* - a `partialFinalized` `"stop"` — a mid-stream loss promoted to a final; the loop's bounded
* continue nudge owns it, so the stop the caller sees is a salvage, not the model's own end;
* - no `final` at all;
* - `continuationCut` — the run was cut with a continuation still owed: a steer / follow-up the person
* had already queued was still pending (queued, or drained at the final boundary and never served —
* the harness's agent_end account, which also mints `task.user_steer_undrained` /
* `task.user_followup_undrained`), or the loop itself had decided to run another turn (a drained
* frame, a nudge, a Stop hook's push-back) and it was never sent — the abort caught it before the dispatch, or
* the spend account refused its request unsent (`Prepared.workCutRef.continuation`, its two writers) — in both, a
* stop landing between the decision and the next stream returns the PREVIOUS clean answer as
* `final` (the loop exits at its pre-dispatch guard, or the leg puts it back), so `final` alone cannot tell, and a
* thinking-only "stop" the loop was about to nudge into a visible answer is an empty result, not
* an answer; or the abort was already in force when the last turn ENDED
* (`Prepared.workCutRef.abortedBeforeTurnEnd`) — a brain that ignored its signal and delivered a
* full "stop" through the abort still answered a run somebody had stopped mid-work.
* Three axes, one law: the `abortedLive` flag alone decides that a stop landed; this decides whether it
* landed on work or on the tail. Evaluated ONCE per leg (the terminal-adoption lane, where both facts
* are in hand) and handed on as a value — {@link ResultFlags.answerSettled} — so the arbitration, the
* marker gate, the hook-seat grace, the teardown attribution and the notice read the same verdict.
* (A budget ceiling crossed by the last turn's own spend reads the same verdict at its own slot, above
* slot 9: an answered turn owes no further request, so the ceiling is a fact on `stats`, not a failure.)
*/
export declare function answerSettled(final: AssistantMessage | undefined, continuationCut?: boolean): boolean;
export declare function terminalCauseOf(final: AssistantMessage | undefined, stats: Pick<Stats, "humanReview">, flags: ResultFlags): {
terminal: TerminalCause;
apiFailure: TaskResult["apiFailure"];
};
/**
* Build the final {@link TaskResult} from the run's terminal state. **The errorCode priority chain is a
* public contract** (callers `switch` on these strings) — first match wins, in this exact order
* (red-line #3, do not reorder):
* 0. `writeRefusal` `"holder.superseded"` → `"holder.superseded"` (a session write refused for the run's grant; the leg stopped),
* EXCEPT under a committed durable pause (8.5 wins: the row was laid down while the grant held)
* 1. `outputInvalid` → `"output.invalid"`
* 2. degenerate → `"output.degenerate"` + `salvagedOutput` (wins over budget/timeout)
* 3. `budgetHit` → `"limits.max_tokens_exceeded"` | `"limits.max_cost_exceeded"` (by `budgetAxis`;
* the pre-call estimate rejection and the after-spend crossing share the code — the distinction
* lives in `errorMessage`, not in a second code), EXCEPT when `answerSettled` (the answering turn's own spend crossed it → 12)
* 3.5 `suspendLoop` → `"suspend.loop"` (the re-suspend cap; deterministic root
* cause, above `threw` because it owns the abort)
* 4. `threw` + walltime → `"limits.max_walltime_exceeded"`
* 5. `threw` + turns → `"limits.max_turns_exceeded"`
* 6. `threw` + conflict→ `"conflict"`
* 7. `threw` (other) → `errorCodeOf(threw)`
* 8. `blockedReason` → status `"blocked"` (no errorCode)
* 8.5 `paused` → status by the pause's registry row (`suspended` for an approval / resource
* slice / platform pause, `needs_review` + `"review.pending"` for a plan or dry-run review) +
* checkpointToken/gate (a deliberate durable pause beats the abort it used, but
* yields to a real budget/threw failure above)
* 9. `abortedLive` | stopReason aborted → `"limits.max_walltime_exceeded"` | `"limits.max_turns_exceeded"` | undefined
* (audit A-1: hoisted ABOVE no-final — the loop exits cleanly on abort, so `final` may be a
* normal message or absent; a plain user interrupt carries NO errorCode — switch on `status`),
* EXCEPT when the aborted `final` is an ending cut's OWN artifact (`cutOwnsAbortedFinal`: the
* loop reported the halt's, or an extension's `$.turn.abort`, cut settled the final turn — never shape inference),
* and EXCEPT when the answer had already settled (`answerSettled`: a clean `"stop"` final, not
* partial) — a stop landing on the run's tail cuts no work, so the run falls through to 12
* (`completed`, the answer as `result`, no `limits.*` code for the axis; three axes, one law)
* 9.7 halt CONSUMED (`haltConsumed(flags.haltConsumption)`) + (no `final` | the halt's own aborted
* `final`) → status `"completed"` (a bare user halt — the verb working, not a defect; below the
* aborts on purpose, a real abort/limit that also fired owns the terminal and the halt rides as
* the pass-through seat; an accepted-but-unconsumed halt never reaches this slot); an extension's
* `$.turn.abort` that ended the final turn reaches it the same way (`endingCutConsumed`, `turnAbortedBy`)
* 9.8 the spend account closed (`flags.spendStop.reason === "closed"`) → `"spend.account_closed"` (status `"failed"`)
* 10. no `final` → status `"failed"`
* 11. stopReason error → brain `[code]` prefix (or `"conflict"` from the storage-layer flag)
* 11.5 the loop exited on a spent recovery budget (`loopTerminal`, read through `loopExitFailureOf`) →
* `"model.malformed_tool_use_exhausted"` | `"model.truncated_output_exhausted"` (status `"failed"`)
* 12. else → `"completed"`
*/
export declare function assembleResult(leg: {
readonly taskId: string;
readonly sessionId: string;
}, final: AssistantMessage | undefined, stats: Stats, flags: ResultFlags): TaskResult;
/**
* THE assembly of a leg's posture seats on its result — read by the result's two mints, this module's `assembleResult` and the stream
* layer's failure backstop (a leg that throws past its result assembly, once its identity wiring published the leg), so the seats ride either: the read and write faces, the deny
* additions and the declared places (the follow-on legs fold them) and the three postures a parked row keeps for its resume (the read
* block, the sandbox requirement, the external-content fold). Pure pass-through of the leg's own resolution; the declared places and the
* sandbox requirement are copied here, the deny additions are the defensive copy prepare already made. No leg ⇒ no seats.
*/
export declare function resultPostureSeats(p: PostureSeatsSource | undefined): Partial<Pick<TaskResult, "effectiveReadFace" | "effectiveWriteFace" | "effectiveReadDenyPatterns" | "effectiveAgentConfigDirs" | "effectiveAgentHomeDirs" | "effectiveBlockReadsOutsideRoots" | "effectiveSandbox" | "effectiveExternalContentTarget">>;