Liking cljdoc? Tell your friends :D

com.blockether.vis.internal.context.engine

Pure helpers for the model-facing context snapshot.

The mutable session state lives outside this namespace; these functions advance the turn/iteration cursor and compute utilization metadata.

Pure helpers for the model-facing context snapshot.

The mutable session state lives outside this namespace; these functions advance
the turn/iteration cursor and compute utilization metadata.
raw docstring

advance-iterclj

(advance-iter ctx _form-results-vec)

Advance the cursor so the next iter starts at "iter" (current+1), "next_form" 1. Prior tool outputs are carried by append-only message history, not by mutable context state. CTX is STRING-KEYED end to end — it is bound into Python as the context dict and nippy-persisted, and both surfaces are strings-only.

Advance the cursor so the next iter starts at "iter" (current+1),
"next_form" 1. Prior tool outputs are carried by append-only message
history, not by mutable context state. CTX is STRING-KEYED end to end —
it is bound into Python as the `context` dict and nippy-persisted, and
both surfaces are strings-only.
sourceraw docstring

block->envelopeclj

(block->envelope block position cursor)
(block->envelope block _position cursor head-tag-resolver)

Project one loop-side block {:code :error :stdout} plus its 1-based position and the engine cursor into the canonical form envelope (one block = one form):

{:scope :tag :src :duration-ms :error :stdout :activity}

:stdout is the single successful output surface: channels paint it and the model reads it back. :error may coexist when the block printed before it failed. Duration, tool-call identity, timeout, Activity metadata and engine-recorded :vis/fold-count are copied when present.

Project one loop-side block `{:code :error :stdout}` plus its 1-based position
and the engine cursor into the canonical form envelope (one block = one form):

  {:scope :tag :src :duration-ms :error :stdout :activity}

`:stdout` is the single successful output surface: channels paint it and the
model reads it back. `:error` may coexist when the block printed before it
failed. Duration, tool-call identity, timeout, Activity metadata and engine-recorded
`:vis/fold-count` are copied when present.
sourceraw docstring

blocks->formsclj

(blocks->forms blocks cursor)
(blocks->forms blocks {:keys [turn iter]} head-tag-resolver)

Map a loop-side blocks vec into a vec of engine envelopes. :cursor is {:turn :iter} of THIS iter; each block gets a 1-based form position by its index in the vec.

3-arity passes head-tag-resolver (see classify-form-tag) through to every block->envelope call so extension-declared mutation tools (db/commit!, any symbol with inline :tag on its vis/symbol entry) classify correctly without the engine hard-coding their symbol set.

Map a loop-side blocks vec into a vec of engine envelopes. `:cursor`
is `{:turn :iter}` of THIS iter; each block gets a 1-based form
position by its index in the vec.

3-arity passes `head-tag-resolver` (see `classify-form-tag`) through
to every `block->envelope` call so extension-declared mutation tools
(`db/commit!`, any symbol with inline `:tag` on its
`vis/symbol` entry) classify correctly without the engine
hard-coding their symbol set.
sourceraw docstring

classify-form-tagclj

(classify-form-tag src)
(classify-form-tag src head-tag-resolver)

Classify a form-source string as :observation or :mutation.

1-arity: pure, engine-only. Returns :mutation when the head is a member of core-mutation-heads; everything else is :observation. Use this from contexts that have no access to the extension registry (tests, pure tools).

2-arity: takes head-tag-resolver, an optional fn (fn [^Symbol head]) -> :mutation | :observation | nil. The resolver wins when it returns a non-nil tag; on nil the engine falls back to core-mutation-heads. The integration layer in loop.clj builds the resolver from extension/op-tag so every extension-declared tool (db/commit!, anything new an extension ships) classifies correctly without the engine hard- coding its symbol.

Classify a form-source string as `:observation` or `:mutation`.

1-arity: pure, engine-only. Returns `:mutation` when the head is a
member of `core-mutation-heads`; everything else is `:observation`.
Use this from contexts that have no access to the extension
registry (tests, pure tools).

2-arity: takes `head-tag-resolver`, an optional fn
`(fn [^Symbol head]) -> :mutation | :observation | nil`. The
resolver wins when it returns a non-nil tag; on nil the engine
falls back to `core-mutation-heads`. The integration layer in
`loop.clj` builds the resolver from `extension/op-tag` so every
extension-declared tool (`db/commit!`, anything new an
extension ships) classifies correctly without the engine hard-
coding its symbol.
sourceraw docstring

compress-scopesclj

(compress-scopes scopes universe & [whole-turns])

Compress a seq/set of concrete tN/iN scopes into a compact, model-legible token vector, RELATIVE to universe (every tN/iN currently on the wire):

  • a turn whose EVERY universe iteration is present → "tN/*"
  • a run of consecutive such FULL turns → "tA-tB/*"
  • full turns covering the WHOLE universe → ["t*"]
  • a partially-present turn stays explicit, its iteration numbers themselves run-compressed: "tN/iM" (singleton) or "tN/iA-iC" (run). Optional whole-turns names turns covered as a whole, including turns with no iteration on the wire; each renders as a FULL turn. Tokens are ordered by (turn, iter). Scopes/universe entries that don't parse are ignored. Pure — same inputs → same output.
Compress a seq/set of concrete `tN/iN` scopes into a compact, model-legible
token vector, RELATIVE to `universe` (every `tN/iN` currently on the wire):
  - a turn whose EVERY universe iteration is present  → `"tN/*"`
  - a run of consecutive such FULL turns              → `"tA-tB/*"`
  - full turns covering the WHOLE universe            → `["t*"]`
  - a partially-present turn stays explicit, its iteration numbers themselves
    run-compressed: `"tN/iM"` (singleton) or `"tN/iA-iC"` (run).
Optional `whole-turns` names turns covered as a whole, including turns with
no iteration on the wire; each renders as a FULL turn.
Tokens are ordered by (turn, iter). Scopes/universe entries that don't parse
are ignored. Pure — same inputs → same output.
sourceraw docstring

DEFAULT_PROMPT_BUDGET_TOKENSclj

Soft per-call operating budget surfaced to the model as session_utilization.auto_compress_above for a model without an entry in MODEL_PROMPT_BUDGET_TOKENS. It keeps routine work below a 200k-token handled-context allowance while the provider-reported input limit remains the hard ceiling. Compared against provider-reported input tokens (no local tokenizer) — see utilization.

Soft per-call operating budget surfaced to the model as
`session_utilization.auto_compress_above` for a model without an entry in
`MODEL_PROMPT_BUDGET_TOKENS`. It keeps routine work below a 200k-token
handled-context allowance while the provider-reported input limit remains the
hard ceiling. Compared against provider-reported input tokens (no local
tokenizer) — see `utilization`.
sourceraw docstring

empty-ctxclj

(empty-ctx)
(empty-ctx session-id)

A minimal CTX scaffold with all model-facing keys filled by empty / default values. Useful as the starting point for scenario replays.

Includes the engine-ephemeral key "engine_warnings" so the rest of the system can swap! it without nil-puncturing. Stripped at persistence boundaries via strip-ephemeral.

CTX is STRING-KEYED end to end: it is bound into Python as the context dict (strings-only boundary) and nippy-persisted (strings-only DB), so there is no keyword->string projection anywhere between.

A minimal CTX scaffold with all model-facing keys filled by empty /
default values. Useful as the starting point for scenario replays.

Includes the engine-ephemeral key `"engine_warnings"` so the rest of
the system can swap! it without nil-puncturing. Stripped at
persistence boundaries via `strip-ephemeral`.

CTX is STRING-KEYED end to end: it is bound into Python as the `context`
dict (strings-only boundary) and nippy-persisted (strings-only DB), so
there is no keyword->string projection anywhere between.
sourceraw docstring

enter-turnclj

(enter-turn ctx turn-pos)

Idempotent turn-start sync. Sets :session/turn to turn-pos, resets :session/scope to {:turn turn-pos :iter 1 :next-form 1}, clears :engine/blockers, and drops the prior turn's ephemeral provider telemetry. Safe to call repeatedly with the same turn-pos (no-op semantically); safe to call when ctx was loaded fresh from DB at turn-pos > 1.

THIS is what the integration layer (vis loop) calls at the start of every turn. Single chokepoint for engine turn-state advance — no advance-turn alias, no auto-incrementing variant. The integration layer always knows the target turn-pos (DB tracks session_turn_soul.position), so the engine takes it as an explicit arg.

Idempotent turn-start sync. Sets `:session/turn` to `turn-pos`, resets
`:session/scope` to `{:turn turn-pos :iter 1 :next-form 1}`, clears
`:engine/blockers`, and drops the prior turn's ephemeral provider telemetry.
Safe to call repeatedly with the same `turn-pos` (no-op semantically); safe to
call when ctx was loaded fresh from DB at turn-pos > 1.

THIS is what the integration layer (vis loop) calls at the start of every turn.
Single chokepoint for engine turn-state advance — no `advance-turn` alias, no
auto-incrementing variant. The integration layer always knows the target
turn-pos (DB tracks `session_turn_soul.position`), so the engine takes it as an
explicit arg.
sourceraw docstring

expand-throughclj

(expand-through summaries universe & [turns])

Resolve every fold SELECTOR on each summary against universe (the caller's own live iteration scopes) into a concrete "scopes" set, so ONE intent expands consistently wherever summaries are read (apply-summaries: the trailer, prior turns included; folds-view: the ledger). Selector keys (all optional, their results UNIONED): "scopes" explicit ids — a tN/iN is kept verbatim; a bare tN EXPANDS to every iteration of that turn present in universe. "through" tN/iN cursor → every universe scope AT OR BEFORE it (start→cursor). "from"/"to" inclusive window — either bound optional (open start / end). "since" tN/iN cursor → every universe scope AT OR AFTER it (cursor→newest). "ranges" the windows AFTER the first (intent-ranges) — each resolved on its own and UNIONED, so one fold may carry disjoint spans. A range cursor may also be a bare tN — a WHOLE-TURN boundary: through/to tN cover all of turn N (its last iteration), from/since tN its first. The range keys are dropped after resolution and the union lands in "scopes".

EXPLICIT whole-turn intent is recorded as "turns" (a set of turn numbers): a bare tN token, or a RANGE selector whose resolved window covers every universe iteration of that turn. An ENUMERATED tN/iN list never yields whole-turn intent — even when it happens to name every iteration — so a fine-grained fold can never silently erase a turn's request and answer (apply-summaries collapses turn boundaries off turns, not scope cover). Optional turns names persisted turns, including turns with no indexed iterations. A range selects an iteration-less turn only when it spans that entire turn; an iteration cursor inside the turn is not evidence of whole-turn coverage.

Intents with none of these keys pass through untouched. Pure — same inputs → same output.

Resolve every fold SELECTOR on each summary against `universe` (the caller's
own live iteration scopes) into a concrete `"scopes"` set, so ONE intent
expands consistently wherever summaries are read (apply-summaries: the
trailer, prior turns included; folds-view: the ledger).
Selector keys (all optional, their results UNIONED):
  `"scopes"`  explicit ids — a `tN/iN` is kept verbatim; a bare `tN` EXPANDS
              to every iteration of that turn present in `universe`.
  `"through"` `tN/iN` cursor → every universe scope AT OR BEFORE it (start→cursor).
  `"from"`/`"to"` inclusive window — either bound optional (open start / end).
  `"since"`  `tN/iN` cursor → every universe scope AT OR AFTER it (cursor→newest).
  `"ranges"` the windows AFTER the first (`intent-ranges`) — each resolved on
             its own and UNIONED, so one fold may carry disjoint spans.
  A range cursor may also be a bare `tN` — a WHOLE-TURN boundary: `through`/`to tN`
  cover all of turn N (its last iteration), `from`/`since tN` its first.
The range keys are dropped after resolution and the union lands in `"scopes"`.

EXPLICIT whole-turn intent is recorded as `"turns"` (a set of turn numbers):
a bare `tN` token, or a RANGE selector whose resolved window covers every
universe iteration of that turn. An ENUMERATED `tN/iN` list never yields
whole-turn intent — even when it happens to name every iteration — so a
fine-grained fold can never silently erase a turn's request and answer
(`apply-summaries` collapses turn boundaries off `turns`, not scope cover).
Optional `turns` names persisted turns, including turns with no indexed iterations.
A range selects an iteration-less turn only when it spans that entire turn;
an iteration cursor inside the turn is not evidence of whole-turn coverage.

Intents with none of these keys pass through untouched. Pure — same inputs →
same output.
sourceraw docstring

finalize-turnclj

(finalize-turn ctx _form-scope _args)

Finalize a turn: the loop ships :answer to the channel and the engine returns ctx unchanged so the turn can settle.

Finalize a turn: the loop ships `:answer` to the channel and the engine
returns ctx unchanged so the turn can settle.
sourceraw docstring

fold-keyclj

(fold-key k)

Parse fold_session's KEY — the first of the verb's two arguments (a key and an optional gist), and the only shape the verb accepts — into one selector intent plus the label its ack card shows. Tokens are comma- or space-separated and .. and - are the same range separator: "t2" a whole turn "t2/i5" one iteration (a tN/iM/fK form id folds its iteration) "t2/i1-i56" an inclusive window; the right side may drop the shared turn "t1/i3-t4" a window across turns (a bare tN bound covers all of turn N) "-t2/i56" open start: every settled step at or before the cursor "t2/i5-" open end: every settled step at or after it Several keys union ("t1, t2/i1-i3"), RANGES INCLUDED: one window sits FLAT on the intent, every window after it under "ranges" (intent-ranges reads both). The parsed intent is what expand-through resolves; its string keys are a RECORDED shape (they persist in the ctx nippy blob), never something a caller passes in. Returns {:intent … :label …}, {:error <model-facing refusal>} for an unparseable token or an argument that is not a key string, or nil when the key named nothing at all. Pure.

Parse `fold_session`'s KEY — the first of the verb's two arguments (a key and
an optional gist), and the only shape the verb accepts — into one selector
intent plus the label its ack card shows. Tokens are comma- or space-separated
and `..` and `-` are the same range separator:
  `"t2"`         a whole turn
  `"t2/i5"`      one iteration (a `tN/iM/fK` form id folds its iteration)
  `"t2/i1-i56"`  an inclusive window; the right side may drop the shared turn
  `"t1/i3-t4"`   a window across turns (a bare `tN` bound covers all of turn N)
  `"-t2/i56"`    open start: every settled step at or before the cursor
  `"t2/i5-"`     open end: every settled step at or after it
Several keys union (`"t1, t2/i1-i3"`), RANGES INCLUDED: one window sits FLAT
on the intent, every window after it under `"ranges"` (`intent-ranges` reads
both). The parsed intent is what `expand-through` resolves;
its string keys are a RECORDED shape (they persist in the ctx nippy blob),
never something a caller passes in.
Returns `{:intent … :label …}`, `{:error <model-facing refusal>}` for an
unparseable token or an argument that is not a key string, or
nil when the key named nothing at all. Pure.
sourceraw docstring

fold-key-grammarclj

The fold KEY grammar in ONE line, said verbatim by every refusal so the caller reads the whole vocabulary at the moment it typed something else.

The fold KEY grammar in ONE line, said verbatim by every refusal so the
caller reads the whole vocabulary at the moment it typed something else.
sourceraw docstring

folds-viewclj

(folds-view summaries universe weights util)
(folds-view summaries universe weights util turn-weights)

Diagnostic fold budget derived from recorded fold_session intents. Returns a now summary when a live iteration universe is available and {} before the next send stamps one. The value summarizes collapsed and live scopes and estimated token savings without repeating any fold gist. It is not included in the model-facing utilization projection; the gists remain in the transcript breadcrumbs. Token prices are best-effort. Pure.

Diagnostic fold budget derived from recorded `fold_session` intents.
Returns a `now` summary when a live iteration universe is available and `{}`
before the next send stamps one. The value summarizes collapsed and live
scopes and estimated token savings without repeating any fold gist. It is
not included in the model-facing utilization projection; the gists remain
in the transcript breadcrumbs. Token prices are best-effort. Pure.
sourceraw docstring

form-head-nameclj

(form-head-name src)

Return the head call NAME (a string) of src — a Python source string — or nil when src is not a name(...) call form. Leading comments and blank lines are skipped. Reading the head name (rather than scanning the raw source) avoids false positives — a "db_commit(x)" inside a string can't match. Used by classify-form-tag.

Return the head call NAME (a string) of `src` — a Python source string —
or nil when `src` is not a `name(...)` call form. Leading comments and
blank lines are skipped. Reading the head name (rather than scanning the
raw source) avoids false positives — a `"db_commit(x)"` inside a string can't
match. Used by `classify-form-tag`.
sourceraw docstring

gc-passclj

(gc-pass ctx)

Passthrough. Tasks/facts/archive are gone — there is nothing to GC. Kept so the turn-lifecycle chokepoint (enter-turn) and any external callers stay valid.

Passthrough. Tasks/facts/archive are gone — there is nothing to GC.
Kept so the turn-lifecycle chokepoint (`enter-turn`) and any external
callers stay valid.
sourceraw docstring

intent-rangesclj

(intent-ranges s)

Every RANGE selector one fold intent/summary carries, as a vector of range maps ("through" / "since" / "from"+"to"). A key may name SEVERAL windows ("t1/i61-i98, t3/i111-i135"): ONE window sits FLAT on the intent itself, several travel under "ranges", and both spellings read the same here — this is the ONLY place that knows how ranges are carried, so expand-through (resolution), the fold verb (freezing an unbounded window) and apply-summaries (stale-cursor check) all ask it instead of reaching for the raw keys. Pure.

Every RANGE selector one fold intent/summary carries, as a vector of range
maps (`"through"` / `"since"` / `"from"`+`"to"`). A key may name
SEVERAL windows (`"t1/i61-i98, t3/i111-i135"`): ONE window sits FLAT on the
intent itself, several travel under `"ranges"`, and both spellings read the
same here — this is the ONLY place that knows how ranges are carried, so
`expand-through` (resolution), the fold verb (freezing an unbounded window)
and `apply-summaries` (stale-cursor check) all ask it instead of reaching for
the raw keys. Pure.
sourceraw docstring

model-facing-keysclj

EXACT set of session_* keys the model is meant to see. Security access is included as an environment-derived value; engine bookkeeping remains hidden.

EXACT set of `session_*` keys the model is meant to see. Security access is
included as an environment-derived value; engine bookkeeping remains hidden.
sourceraw docstring

MODEL_PROMPT_BUDGET_TOKENSclj

Operating budgets for model families whose routed windows reach far past the default, as [name-pattern tokens] pairs; the first match wins. Patterns accept provider spellings such as anthropic/claude-opus-4.5, anthropic.claude-opus-4-5-20251101-v1:0 and azure/gpt-5.5. The routed input window still caps every budget — see loop.router/context-fold-budget.

Operating budgets for model families whose routed windows reach far past the
default, as `[name-pattern tokens]` pairs; the first match wins. Patterns accept
provider spellings such as `anthropic/claude-opus-4.5`,
`anthropic.claude-opus-4-5-20251101-v1:0` and `azure/gpt-5.5`. The routed input
window still caps every budget — see `loop.router/context-fold-budget`.
sourceraw docstring

over-budget-hintclj

(over-budget-hint util current-turn since-turn)

Stateful compaction guidance for session_utilization.

Pressure starts at 75% of auto_compress_above, escalates at 90%, and becomes mandatory above the operating ceiling. Once armed it remains visible while pressure remains; an ignored warning must never silently expire. The hint names fold_session, the safe settled boundary, and the evidence to preserve. Pure.

Stateful compaction guidance for `session_utilization`.

Pressure starts at 75% of `auto_compress_above`, escalates at 90%, and becomes
mandatory above the operating ceiling. Once armed it remains visible while
pressure remains; an ignored warning must never silently expire. The hint names
`fold_session`, the safe settled boundary, and the evidence to preserve. Pure.
sourceraw docstring

pretty-scopesclj

(pretty-scopes scopes universe & [whole-turns])

Render a seq of concrete tN/iN scopes as ONE beautiful, model-legible anchor string using the SAME grammar the fold ledger speaks (compress-scopes + join-scopes): same-turn iter-runs merge (t3/i3-i4,i7-i8), whole turns collapse to tN/* / tA-tB/* / t*. universe (the live wire scopes, or nil) drives the whole-turn collapse; nil/empty keeps every turn explicit. whole-turns names turns folded as a whole, which render as tN/* runs even without an iteration on the wire. nil for an empty/unparseable seq. Pure. Shared by the ledger AND the transcript fold breadcrumb so a collapsed region reads identically wherever it surfaces — one anchor vocabulary, not two.

Render a seq of concrete `tN/iN` scopes as ONE beautiful, model-legible anchor
string using the SAME grammar the fold ledger speaks (`compress-scopes` +
`join-scopes`): same-turn iter-runs merge (`t3/i3-i4,i7-i8`), whole turns
collapse to `tN/*` / `tA-tB/*` / `t*`. `universe` (the live wire scopes, or
nil) drives the whole-turn collapse; nil/empty keeps every turn explicit.
`whole-turns` names turns folded as a whole, which render as `tN/*` runs even
without an iteration on the wire. nil for an empty/unparseable seq. Pure.
Shared by the ledger AND the transcript fold breadcrumb so a collapsed region
reads identically wherever it surfaces — one anchor vocabulary, not two.
sourceraw docstring

prompt-budget-tokensclj

(prompt-budget-tokens model)

Operating budget for the model named model before any input-window cap: its family budget from MODEL_PROMPT_BUDGET_TOKENS, else DEFAULT_PROMPT_BUDGET_TOKENS.

Operating budget for the model named `model` before any input-window cap:
its family budget from `MODEL_PROMPT_BUDGET_TOKENS`, else
`DEFAULT_PROMPT_BUDGET_TOKENS`.
sourceraw docstring

prompt-cache-status-keyclj

Engine-only slot for Svar's latest provider prompt-cache status. Kept for request diagnostics, not projected into model-facing utilization.

Engine-only slot for Svar's latest provider prompt-cache status. Kept for
request diagnostics, not projected into model-facing utilization.
sourceraw docstring

scope-keyclj

(scope-key scope)

Ordered key for a scope so ranges can compare scopes: "t1/i2" or "t1/i2/f3" → [1 2] (the form index is dropped — ranges cover WHOLE iterations). nil when the scope can't be parsed, so callers skip it rather than mis-order it. Lives here (below apply-summaries in loop) so BOTH the wire (apply-summaries) and the render-time ledger (folds-view) resolve fold selectors through the SAME function.

Ordered key for a scope so ranges can compare scopes: `"t1/i2"` or
`"t1/i2/f3"` → `[1 2]` (the form index is dropped — ranges cover WHOLE
iterations). nil when the scope can't be parsed, so callers skip it rather
than mis-order it. Lives here (below `apply-summaries` in loop) so BOTH the
wire (`apply-summaries`) and the render-time ledger (`folds-view`) resolve fold
selectors through the SAME function.
sourceraw docstring

served-routeclj

(served-route ctx)

Pure: {"provider" .. "model" ..} for THIS turn, or nil.

A stamp left by an EARLIER turn is ignored rather than pruned: the human may have picked another model in between, and a turn's first request is sent before anything has served it — until then the session pick is the only truth.

Pure: `{"provider" .. "model" ..}` for THIS turn, or nil.

A stamp left by an EARLIER turn is ignored rather than pruned: the human may
have picked another model in between, and a turn's first request is sent before
anything has served it — until then the session pick is the only truth.
sourceraw docstring

served-route-keyclj

ctx key holding the provider/model pair that ACTUALLY answered the last request of the CURRENT turn. engine_* is engine bookkeeping: session-view never ships it, enrich-ctx folds it into the model-facing session_routing.

ctx key holding the provider/model pair that ACTUALLY answered the last
request of the CURRENT turn. `engine_*` is engine bookkeeping: `session-view`
never ships it, `enrich-ctx` folds it into the model-facing `session_routing`.
sourceraw docstring

session-viewclj

(session-view ctx)
(session-view ctx _warnings)

The single projection from engine-internal ctx to the model-facing session_* view. Both rendered context and the sandbox session bag use it. Only the latest provider-measured input, soft budget, hard limit and an armed hint enter session_utilization. Internal telemetry and fold statistics stay in engine state and request health. The second arity ignores legacy warnings. Pure; STRING keys in and out.

The single projection from engine-internal ctx to the model-facing
`session_*` view. Both rendered context and the sandbox `session` bag use it.
Only the latest provider-measured input, soft budget, hard limit and an armed
hint enter `session_utilization`. Internal telemetry and fold statistics stay
in engine state and request health. The second arity ignores legacy `warnings`.
Pure; STRING keys in and out.
sourceraw docstring

stamp-served-routeclj

(stamp-served-route ctx provider model)

Pure: record provider/model as the pair that answered a request during the ctx's current turn. A half-named route (either side blank) leaves ctx untouched — it would be worse than the pin it replaces.

Pure: record `provider`/`model` as the pair that answered a request during the
ctx's current turn. A half-named route (either side blank) leaves ctx
untouched — it would be worse than the pin it replaces.
sourceraw docstring

strip-ephemeralclj

(strip-ephemeral ctx)

Remove transient context keys before Nippy-snapshotting: engine bookkeeping must never become durable session state.

Remove transient context keys before Nippy-snapshotting: engine bookkeeping
must never become durable session state.
sourceraw docstring

supersede-summariesclj

(supersede-summaries summaries)

Collapse 'summary of summary': drop any summary whose scope set is fully COVERED by another's — a proper subset, or an equal set recorded earlier — so re-folding a region with a broader/newer gist REPLACES the finer breadcrumb instead of stacking a second line. Coverage is never lost: every scope of a dropped summary is present in the one that supersedes it (the superset wins; for equal sets the later/newer wins), and the dropped summary's explicit whole-turn intent ("turns") is MERGED into a surviving coverer so a fold-of-fold can never resurrect an already-folded turn's request and answer. Whole turns also count as coverage, so their gists can be superseded without dropping unrelated turns. Order-stable. Expects resolved scopes. Pure.

Collapse 'summary of summary': drop any summary whose scope set is fully
COVERED by another's — a proper subset, or an equal set recorded earlier — so
re-folding a region with a broader/newer gist REPLACES the finer breadcrumb
instead of stacking a second line. Coverage is never lost: every scope of a
dropped summary is present in the one that supersedes it (the superset wins;
for equal sets the later/newer wins), and the dropped summary's explicit
whole-turn intent (`"turns"`) is MERGED into a surviving coverer so a
fold-of-fold can never resurrect an already-folded turn's request and answer.
Whole turns also count as coverage, so their gists can be superseded without
dropping unrelated turns. Order-stable. Expects resolved scopes.
Pure.
sourceraw docstring

turn-keyclj

(turn-key scope)

Turn number of a bare WHOLE-TURN scope "tN" (no /iN); nil otherwise, so expand-through only whole-turn-expands an id that is JUST a turn — a plain "t1/i2" stays a single iteration.

Turn number of a bare WHOLE-TURN scope `"tN"` (no `/iN`); nil otherwise, so
`expand-through` only whole-turn-expands an id that is JUST a turn — a plain
`"t1/i2"` stays a single iteration.
sourceraw docstring

utilizationclj

(utilization request-tokens window-tokens turn-tokens fold-cap)

Internal utilization from the most recent provider request. The measured last_request_tokens counts input (prompt, context and tool history), not output tokens or cumulative turn input. On overflow it can be the rejected request’s reported input, not a live estimate for the next one. turn_total_tokens is cumulative billing input; saturation and headroom_tokens compare against the hard provider limit. auto_compress_above is the soft operating budget.

session-view projects only the three decision-making fields, exposing the latest measured input as latest_measured_input_tokens for the model. Other fields remain internal for request health and diagnostics. Returns nil until a request is measured (req <= 0).

Internal utilization from the most recent provider request. The measured
`last_request_tokens` counts input (prompt, context and tool history), not
output tokens or cumulative turn input. On overflow it can be the rejected
request’s reported input, not a live estimate for the next one. `turn_total_tokens` is cumulative
billing input; `saturation` and `headroom_tokens` compare against the hard
provider limit. `auto_compress_above` is the soft operating budget.

`session-view` projects only the three decision-making fields, exposing the
latest measured input as `latest_measured_input_tokens` for the model. Other
fields remain internal for request health and diagnostics.
Returns nil until a request is measured (req <= 0).
sourceraw docstring

with-prompt-cache-statusclj

(with-prompt-cache-status util status)

Pure: attach Svar's already-computed prompt-cache status to a utilization map. Vis deliberately performs no cache arithmetic, freshness policy, route grouping, or persistence here. A missing status leaves the map untouched.

Pure: attach Svar's already-computed prompt-cache status to a utilization map.
Vis deliberately performs no cache arithmetic, freshness policy, route grouping,
or persistence here. A missing status leaves the map untouched.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close