/** * SessionInspector — read-only / introspection-oriented operations on a session. * * Owns the five methods previously scattered across `AgentService` that all * compute a "summary view" of one session: * - `compact` (manual user-triggered compaction) * - `btwQuery` (one-shot LLM answer with transcript as background) * - `report` (Markdown / JSON `/context` summary) * - `agentConfig` (resolved thinking + model + workspace for the Web UI) * - `contextUsage` (rough token budget vs estimated transcript) * * The shared helper `computeStats` keeps the three callsites that need * `getWindowStats` / `getCompactionStats` / `estimateTokenUsage` in lockstep. */ import type { AgentMessage } from '@earendil-works/pi-agent-core'; import type { ThinkingLevel } from '@earendil-works/pi-agent-core'; import type { Config } from '../../config/schema.js'; import type { BtwQueryOptions } from '../../chat-commands/index.js'; import { type SessionConfigStore } from '../../session/index.js'; import type { SessionStore } from '../../session/store.js'; import type { CompactionResult } from '../memory/compaction.js'; import type { ModelManager } from '../models/index.js'; import type { AgentInstanceGateway } from '../agent-instance-gateway.js'; import type { ReasoningLevel, VerboseLevel } from '../transcript/thinking-types.js'; import type { SessionHydrator } from './session-hydrator.js'; export interface SessionInspectorOptions { sessionStore: SessionStore; sessionConfigStore: SessionConfigStore; modelManager: ModelManager; agentManager: AgentInstanceGateway; sessionHydrator: SessionHydrator; /** Effective config snapshot accessor (honours runtime overrides). */ getConfig: () => Config | undefined; /** * Nominal context window the session is budgeted against. Derived from the * effective session model metadata, defaulting to 128k. */ getContextWindow: (sessionKey: string) => number; } export interface SessionContextUsage { estimatedTokens: number; contextWindow: number; usagePercent: number | null; } export interface SessionAgentConfigView { thinkingLevel: ThinkingLevel; model: string; reasoningLevel: ReasoningLevel; activityDetail: { default: ReasoningLevel; override: ReasoningLevel | null; effective: ReasoningLevel; source: 'session' | 'default'; }; verboseLevel: VerboseLevel; effectiveWorkspacePath: string; workingDirectoryLocked: boolean; workspaceSource: 'project' | 'session_override' | 'agent_default_root' | 'agent_workspace'; } export declare class SessionInspector { private readonly opts; constructor(opts: SessionInspectorOptions); private ensureEffectiveSessionModel; private contextWindowForSession; /** * Manual compaction triggered by a user / API. Always forces a compaction * pass (`force: true` by default) and evicts the in-memory agent so the * next turn reloads from the compacted transcript. */ compact(sessionKey: string, options?: { instructions?: string; force?: boolean; }): Promise; /** One-shot LLM answer for `/btw`: transcript as background, not persisted. */ btwQuery(sessionKey: string, question: string, options?: BtwQueryOptions): Promise<{ text: string; error?: string; }>; /** Cheap stats used by both the report and other callers. */ stats(sessionKey: string, messages: AgentMessage[]): { windowStats: ReturnType; compactionStats: ReturnType; tokenEstimate: ReturnType; }; /** Rough context usage for TUI footer (estimated tokens vs nominal budget). */ contextUsage(sessionKey: string): Promise; /** Markdown or JSON summary for `/context`. */ report(sessionKey: string, mode: 'list' | 'detail' | 'json'): Promise; /** Resolved thinking / model / workspace for the Web UI. */ agentConfig(sessionKey: string): Promise; }