/** * Issue #456: model and effort changes within a Claude or Pi session. * Both harnesses have native mid-session mechanisms (verified: Claude * 2.1.319 `set_model` / `apply_flag_settings {effortLevel}` control * requests; Pi 1.4 RPC `set_model` / `set_thinking_level`), and this * module is the pure owner of their wire shapes, of the validation the * spawn flags already apply, and of Pi's model resolution against the * catalog the running session reports (`get_available_models`), mirroring * Pi 1.4.0's own `resolveCliModel`. Execution sequences the writes and * settles the receipt; nothing here touches a process. */ import type { HarnessDescriptor, SessionInputContract, SessionInputKind } from "../knowledge/descriptor.js"; /** The request id prefix hcn stamps on its settings commands, so their * responses cannot be confused with anything user-visible. The effort * half of one op carries `:e`, Pi's catalog read `:c` and its state * readback `:s`. */ export declare const SETTINGS_ID_PREFIX = "hcn-settings:"; export declare const settingsModelId: (token: string) => string; export declare const settingsEffortId: (token: string) => string; export declare const settingsCatalogId: (token: string) => string; export declare const settingsStateId: (token: string) => string; /** Which native command of one settings op a settings answer names. */ export type SettingsPart = "model" | "effort" | "catalog" | "state"; export declare const parseSettingsId: (id: unknown) => { readonly token: string; readonly part: SettingsPart; } | null; /** Session input kinds with a native mid-session settings mechanism. */ export declare const supportsSessionSettings: (kind: SessionInputKind) => boolean; export type SessionSettingsRejection = "invalid-model" | "invalid-effort" | "unsupported"; /** One settings op, validated the way the spawn flags validate. Pi's * model stays the caller's selector here: it resolves against the * session's own catalog (see resolvePiSessionModel) only after the * native `get_available_models` round trip, which validation cannot * make. */ export interface ValidatedSessionSettings { /** The model id as the harness knows it (Claude aliases resolved; * Pi: the syntactically valid selector, resolved later). */ readonly model?: { readonly id: string; }; /** The effort word, from the harness's own ladder. */ readonly effort?: string; } /** Validate a settings op exactly as the spawn flags do. Claude's model * resolves aliases here; Pi's model passes only the spawn flag's * selector check (blank, flag-shaped or shell-carrying strings refuse) * and resolves semantically against the native catalog afterwards. The * effort ladder is the resulting model's: the op's own model, else the * session's CURRENT model (the last one a settings op applied, tracked * by the runner, else the spawn model). Invalid values reject without a * native write. */ export declare const validateSessionSettings: (h: HarnessDescriptor, input: SessionInputContract, request: { readonly model?: string; readonly effort?: string; }, session?: { readonly model?: string; readonly provider?: string; }) => { readonly ok: true; readonly value: ValidatedSessionSettings; } | { readonly ok: false; readonly reason: SessionSettingsRejection; }; /** One entry of Pi's `get_available_models` response - the fields the * resolver reads, not the full Model object. `name` is the display name * pi's fuzzy matching also considers. */ export interface PiModelEntry { readonly provider: string; readonly id: string; readonly name?: string; } /** The {provider, modelId} pair Pi's `set_model` takes. */ export interface PiModelRef { readonly provider: string; readonly modelId: string; } export type PiModelResolution = { readonly status: "resolved"; readonly ref: PiModelRef; /** A `:` selector's parsed thinking level, the way * pi's `--model` parses it (see resolvePiSessionModel). */ readonly thinkingLevel?: string; } | { readonly status: "invalid"; }; /** Resolve one Pi model selector against the session's own catalog, a * faithful port of pi 1.4.0's `resolveCliModel` (the spawn flag's * resolver) as a pure function over the `get_available_models` entries: * the same reference precedence (`selectReference`), the same fuzzy * matching, the same `:` suffix parse, minus the pieces * that need credentials or pi's custom-model fallback (a settings op * that cannot resolve rejects `invalid-model` instead): * * - The session's `--provider` constrains the pool the way the spawn * flag does, and a provider absent from the catalog (or an unknown * `--provider`) refuses; the catalog IS the available set, so pi's * `hasConfiguredAuth` tiebreak reads true for every candidate: a * named candidate always wins a cross-provider tie, exactly as it * does at spawn over an authenticated catalog (the selector * `moonshotai/kimi-k2.6` with both OpenRouter's gateway id * `moonshotai/kimi-k2.6` and Moonshot's own `kimi-k2.6` available * resolves to Moonshot). * - An ambiguous or unmatched selector refuses; pi's fallback to a * custom model id is not part of this surface. */ export declare const resolvePiSessionModel: (catalog: readonly PiModelEntry[], request: { readonly text: string; readonly provider?: string; }) => PiModelResolution; /** The catalog of a Pi `get_available_models` response: entries with a * string provider and id, others dropped. The optional display `name` * rides along when present - pi's fuzzy matching considers it. */ export declare const piCatalogOf: (parsed: Record) => readonly PiModelEntry[]; /** What a Pi `get_state` answer says hcn's receipt reports: the * effective model (provider/id) and thinking level. */ export interface PiStateAnswer { readonly model?: PiModelRef; readonly thinkingLevel?: string; } export declare const piStateOf: (parsed: Record) => PiStateAnswer; /** The native command(s) one validated half of a settings op becomes. * Claude writes control requests; pi writes rpc commands. Each carries * the request id its answer will name, so the runner can correlate. */ export declare const encodeSessionSettingsModel: (input: SessionInputContract, requestId: string, model: { readonly id: string; readonly pi?: PiModelRef; }) => string; /** Effort is not cleared by a model change: this writes exactly the word * the op named (claude `effortLevel`, pi's thinking level). */ export declare const encodeSessionSettingsEffort: (input: SessionInputContract, requestId: string, effort: string) => string; /** Pi only: the catalog read that precedes a model write, so the model * resolves against the session's own providers exactly the way the * spawn flags resolve it. */ export declare const encodeSessionSettingsCatalog: (input: SessionInputContract, requestId: string) => string; /** Pi only: the state readback that follows the writes, so the receipt * reports the effective model and thinking level, not the requested * ones (pi clamps both silently). */ export declare const encodeSessionSettingsState: (input: SessionInputContract, requestId: string) => string; /** What one parsed native answer to a settings command says. `model` is * the native confirmation where the harness returns one (claude's * `response.model`, pi's `data.id`), else undefined. */ export interface SessionSettingsAnswer { readonly ok: boolean; readonly model?: string; } /** The answer inside a claude `control_response` to a settings control * request, or null when the record carries no usable answer shape. The * caller has already matched the response's request_id to the settings * prefix. */ export declare const claudeSettingsAnswerOf: (parsed: Record) => SessionSettingsAnswer | null; /** The answer inside a pi rpc response to a settings command, or null * when the record is not one: the command must be the one the id's part * names. The caller has already matched the id to the settings prefix. */ export declare const piSettingsAnswerOf: (parsed: Record, part: SettingsPart) => SessionSettingsAnswer | null; //# sourceMappingURL=session-settings.d.ts.map