import type { MemoryPromptPreparation } from "../memory-backend/types.js"; import type { AgentSession } from "../session/agent-session.js"; import { type BankScope, type HindsightBankSet } from "./bank.js"; import type { HindsightClientApi } from "./client.js"; import type { HindsightConfig } from "./config.js"; import { type HindsightMessage } from "./content.js"; import { type RetainInput } from "./outbox.js"; /** `notice` source of Hindsight recall/retain failures; print mode writes these to stderr. */ export declare const HINDSIGHT_NOTICE_SOURCE = "Hindsight"; interface RecallOutcome { context: string | null; ok: boolean; } /** * What a subagent alias reads from its parent state: the routing it copies and the * snippets the developer prompt shows. A subagent worker holds a remote implementation * whose client and bank set are main's live ones. */ export interface HindsightSessionStateApi { readonly client: HindsightClientApi; readonly bankId: string; readonly retainTags?: string[]; readonly recallTags?: string[]; readonly recallTagsMatch?: "any" | "all" | "any_strict" | "all_strict"; readonly config: HindsightConfig; readonly banksSet: HindsightBankSet; readonly lastRecallSnippet?: string; readonly mentalModelsSnippet?: string; } export interface HindsightSessionStateOptions { agentDir?: string; /** Session id used for retain-queue metadata. */ sessionId: string; client: HindsightClientApi; bankId: string; /** Tags on project-scoped retains (transcripts and tool writes) — non-empty in per-project-tagged mode. Global tool writes omit them. */ retainTags?: string[]; /** Tag filter applied to every recall/reflect — non-empty in per-project-tagged mode. */ recallTags?: string[]; recallTagsMatch?: "any" | "all" | "any_strict" | "all_strict"; config: HindsightConfig; session: AgentSession; banksSet: HindsightBankSet; lastRetainedTurn?: number; hasRecalledForFirstTurn?: boolean; /** * When set, this entry is a subagent alias that reuses the parent's bank, * scope, config, client, and banksSet. Aliases skip auto-recall and * auto-retain — those run on the parent only — but the recall/retain/reflect * tools resolve via the alias so they persist to the same bank as the parent. */ aliasOf?: HindsightSessionStateApi; } /** * Debounced delivery of tool-initiated `retain` calls owned by one Hindsight * session state. Items are persisted in the {@link HindsightOutbox} before * `enqueue` resolves; flushes deliver every pending event for this destination, * including ones earlier processes left behind. * * Auto-retain (`HindsightSessionState.retainSession`) is intentionally not * routed through this queue — it submits a full transcript as one large item * and already runs `async: true` server-side. */ export declare class HindsightRetainQueue { #private; constructor(state: HindsightSessionState, agentDir: string); /** Resolves once every item is durable; rejects, queueing nothing, when it cannot be. */ enqueue(toolCallId: string, items: RetainInput[]): Promise; flush(): Promise; dispose(): void; } /** Per-session Hindsight runtime state owned by its AgentSession. */ export declare class HindsightSessionState implements HindsightSessionStateApi { #private; /** Session id used for retain-queue metadata. */ sessionId: string; client: HindsightClientApi; bankId: string; /** Tags on project-scoped retains (transcripts and tool writes) — non-empty in per-project-tagged mode. Global tool writes omit them. */ retainTags?: string[]; /** Tag filter applied to every recall/reflect — non-empty in per-project-tagged mode. */ recallTags?: string[]; recallTagsMatch?: "any" | "all" | "any_strict" | "all_strict"; config: HindsightConfig; session: AgentSession; banksSet: HindsightBankSet; lastRetainedTurn: number; hasRecalledForFirstTurn: boolean; lastRecallSnippet?: string; /** Cached `` block injected into developer instructions. */ mentalModelsSnippet?: string; /** When the current bootstrap/boundary load settled; gates the first-turn race. */ mentalModelsLoadedAt?: number; /** * In-flight bootstrap or transcript-boundary load. `beforeAgentStartPrompt` * awaits it on the first turn so a timely snapshot lands before generation, * even though startup and transcript transitions remain non-blocking. */ mentalModelsLoadPromise?: Promise; unsubscribe?: () => void; /** Alias states delegate persistence config to a primary parent state. */ aliasOf?: HindsightSessionStateApi; readonly retainQueue: HindsightRetainQueue; constructor(options: HindsightSessionStateOptions); setSessionId(sessionId: string): void; resetConversationTracking(): void; /** * Whether `scope: "global"` is enabled (`hindsight.globalScope`, off by default) and has a destination every * project recalls: untagged memories in the shared bank. `per-project` scoping recalls only the project's own bank, * so a global write there would never surface. Reads this state's config, which a subagent alias copies from its * parent, so tool exposure and enforcement agree even after the live settings change. */ isGlobalRetainAvailable(): boolean; /** Throws, naming the reason, unless {@link isGlobalRetainAvailable}. */ assertGlobalRetainAvailable(): void; /** Queues a tool-initiated retain; `scope: "global"` retains it untagged (see {@link assertGlobalRetainAvailable}). */ enqueueRetain(toolCallId: string, items: RetainInput[]): Promise; flushRetainQueue(): Promise; recallForContext(query: string, signal?: AbortSignal): Promise; retainSession(messages: HindsightMessage[]): Promise; maybeRetainOnAgentEnd(): Promise; forceRetainCurrentSession(): Promise; beforeAgentStartPrompt(promptText: string, signal?: AbortSignal): Promise; recallForCompaction(messages: HindsightMessage[], signal?: AbortSignal): Promise; runMentalModelLoad(scope: BankScope): Promise; /** * Starts a bounded reload for a new transcript without blocking the session * transition. A result that misses the first-turn deadline is discarded so * the previous snapshot stays frozen for the whole transcript. */ beginMentalModelsTranscriptReload(): void; reloadMentalModels(): Promise; attachSessionListeners(): void; dispose(): void; } export {};