/** * The claude-code harness's model broker: the family gateway routes * `harnessModel` / `memberModel` / `setMemberModel` here, and the broker * answers the family's fixed resolution order — the session-level override * (the composer's picker), the delegation's recorded model, the plugin-config * `model` key (the settings card), the scoped settings.json's own `model`, * and last the CLI's built-in default, which names nothing. * * The override map is IN-MEMORY by design (it deliberately does not survive a * host restart) and SHARED: index.ts hands the same map to the provider's and * the live driver's model resolvers, so a composer switch reaches the next * round through every drive. With the live driver on, switching to a * DIFFERENT model retires the member's resident runtime so the next round * respawns onto the new model — the CLI session itself resumes on disk, so * the conversation carries over. A switch while a round is in flight is * refused: retiring a runtime mid-round would kill the run. * * `lastObserved` (the cli-builtin layer's display hint): the delegation * record's `observedModel` answers when the live-settle channel reported * one; the member's own CLI transcript (`transcriptModel`, a bounded read of * the projects tree) is the history backstop for rounds that predate that * channel — read-only, TTL-cached, never a write into `delegations.jsonl`. * * @module @khorsheed/dsh-local-agent-claude-code/model-broker — internal, unit-tested directly. */ import type { LocalAgentRegistry, MemberConfigurationAdapter } from '@khorsheed/dsh-local-agent'; import type { LocalAgentModelBroker, LocalAgentModelInfo, LocalAgentModelDirectory, LocalAgentMemberBinding } from '@khorsheed/dsh-local-agent/types'; import type { LiveDriverSwitch } from './live-switch.ts'; /** * The scoped settings.json `model` key across live-spawn scratch writes. The * live driver writes a member's effective model into the file before a * resident spawn (a `--resume` respawn restores the session's stored model * over the `--model` flag), and this memory keeps the person's own configured * value straight across those writes: what the file held before our first * write is the `cli-config` layer, and a spawn with NO effective model * restores that value instead of leaking the previous member's model into * the next runtime. In-memory on purpose: a restart re-reads the file as it * stands. Writes serialize on an internal queue so concurrent member spawns * cannot lose each other's read-modify-write. */ export declare class ClaudeScopedModelMemory { /** The value we last scratched in and believe the file still holds. */ private written; /** What the file held before our first write; null = it named no model. */ private previous; private queue; /** * Bring the scoped settings.json's `model` key to the effective model a * spawn is about to bind — writing it, or restoring the person's value when * the spawn binds none and the file still holds our earlier scratch. * @param homeDir - the scoped home the spawn runs against. * @param model - the spawn's effective model, or undefined for none. */ provision(homeDir: string, model: string | undefined): Promise; /** * The person's configured model — the `cli-config` layer. A file value we * did not write reports as read; our own scratch value reports what the * file held before we wrote it. * @param homeDir - the scoped home to read. * @returns the person's configured model, or undefined when none. */ cliDefault(homeDir: string): Promise; private provisionLocked; } /** Everything the broker reads that it does not own. */ export interface ClaudeModelBrokerDeps { /** The registry face for the in-flight check and the delegation record. */ readonly localAgent: Pick & Partial>; readonly configurationContext?: (binding: LocalAgentMemberBinding) => { home: string; directory: (refresh?: boolean) => LocalAgentModelDirectory | Promise; }; /** The settings layer: the curated list's first entry, else the plugin-config model, read per call. */ readonly settingsModel: (scope?: string) => string | undefined; /** The scope's curated model list, read per call (empty = the fallback chain decides the vocabulary too). */ readonly modelList?: (scope?: string) => readonly string[]; /** The scoped settings.json's own model, minus live-spawn scratch writes. */ readonly cliDefault: (childSessionId?: string) => Promise; readonly directory?: (childSessionId?: string, refresh?: boolean) => LocalAgentModelDirectory | Promise; readonly followDirectory?: (childSessionId: string | undefined, signal: AbortSignal) => AsyncIterable; /** Model identifiers the settings card saved before (the card's memory). */ readonly recentModels: () => readonly string[]; /** Whether the live driver is on for the member's rounds. */ readonly live: () => boolean; /** The session-level override map, shared with the round model resolvers. */ readonly overrides: Map; /** The live-driver switch, for the hosting generation's retire on a switch. */ readonly liveSwitch: Pick; /** * The transcript backstop for `lastObserved`: read the model the member's * own CLI transcript names (its recorded cliSessionId), or — absent, the * settings card's memberless read — the newest transcript in the scoped * home's projects tree. Read-only history; never throws. */ readonly transcriptModel: (cliSessionId?: string, childSessionId?: string) => Promise; } /** How long one transcript read-back answer is reused (repeated card opens). */ export declare const OBSERVED_MODEL_CACHE_TTL_MS = 60000; export declare class ClaudeModelBroker implements LocalAgentModelBroker { private readonly deps; constructor(deps: ClaudeModelBrokerDeps); configurationAdapter(binding: LocalAgentMemberBinding): MemberConfigurationAdapter; modelDirectory(childSessionId?: string, refresh?: boolean): Promise; followModelDirectory(childSessionId: string | undefined, signal: AbortSignal): AsyncIterable; /** * The `lastObserved` cache: childSessionId (empty key = the memberless * harness read) → the answer and when it was read. A miss is cached too — * a member with no transcript yet should not pay a rescan per card open. */ private readonly observedCache; /** * The last model the member (or the harness) was observed running. The * live-settle channel is primary — a record whose latest round reported * `observedModel` answers without touching disk; the CLI's own transcripts * are the history backstop for every round that predates it. */ private lastObserved; /** * Read the model surface in the family's fixed order. Without a member the * override and delegation layers stay absent — the settings card's "what * would a round run with" read. */ modelInfo(childSessionId?: string, delegationModel?: string): Promise; /** * Set or clear a member's session-level override. Throws while a round is * in flight for the member; a same-model set is a no-op; a real change * retires the member's resident runtime when its bound model is no longer * what the next round would spawn with (the CLI session resumes on the * respawn, so the conversation carries over). */ setMemberModel(childSessionId: string, model: string | undefined): Promise; } //# sourceMappingURL=model-broker.d.ts.map