UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

43 lines • 1.73 kB
const THINKING_LEVELS = new Set(["off", "minimal", "low", "medium", "high", "xhigh", "max"]); function isThinkingLevel(value) { return typeof value === "string" && THINKING_LEVELS.has(value); } export function modelThinkingKey(model) { return `${model.provider}/${model.id}`; } /** * The last level each model ran at on this branch, keyed `provider/id`. Entries written before * senpi#3819 carry no model and are skipped: attributing them by position would misfile the level a * switch writes just before its `model_change`. */ export function deriveSessionModelThinkingLevels(path) { const levels = {}; for (const entry of path) { if (entry.type !== "thinking_level_change") continue; // Session files are parsed without validation, so every field is checked here. if (typeof entry.provider !== "string" || typeof entry.modelId !== "string") continue; if (!isThinkingLevel(entry.thinkingLevel)) continue; levels[modelThinkingKey({ provider: entry.provider, id: entry.modelId })] = entry.thinkingLevel; } return levels; } /** Re-derives only when the branch leaf moved, so repeated `get_state` reads stay O(1). */ export class SessionThinkingMemory { constructor(source) { this.source = source; } levels() { const leafId = this.source.getLeafId(); if (this.cached?.leafId !== leafId) { this.cached = { leafId, levels: deriveSessionModelThinkingLevels(this.source.getBranch()) }; } return { ...this.cached.levels }; } levelFor(model) { return this.levels()[modelThinkingKey(model)]; } } //# sourceMappingURL=session-thinking-memory.js.map