UNPKG

@code-yeongyu/senpi

Version:

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

103 lines • 4.89 kB
import type { Options, SDKUserMessage, SdkQuery, SdkQueryHandle } from "./sdk-boundary.ts"; import { type SessionRegistryReapHandle } from "./session-reaper.ts"; import { type AnthropicSubscriptionSessionState } from "./session-registry-state.ts"; export declare const SESSION_REGISTRY_IDLE_TTL_MS: number; export declare const SESSION_REGISTRY_MAX_ENTRIES = 32; export interface SessionInputController extends AsyncIterable<SDKUserMessage> { push(message: SDKUserMessage): void; close(): void; } export type SessionRegistryBoundary = { now: () => number; queryFactory: SdkQuery; scheduleReap: (callback: () => void, delayMs: number) => SessionRegistryReapHandle; }; export declare function overrideSessionRegistryBoundary(override: Partial<SessionRegistryBoundary>): void; export declare function resetSessionRegistryBoundary(): void; export type { SessionRegistryReapHandle }; export type SessionBranchInfo = { oldLeafId: string; newLeafId: string; }; export interface AnthropicSubscriptionSessionEntry { senpiSessionId: string; sdkSessionId: string; sdkSessionIdConfirmed: boolean; generation: number; accountName: string; modelId: string; toolsetHash: string; systemPromptHash: string; query: SdkQueryHandle; inputController: SessionInputController; pumpTask: Promise<void> | null; state: AnthropicSubscriptionSessionState; activeTurn: unknown | null; syncedPrefixHash: string | null; sentCount: number; assistantUuidByIndex: Map<number, string>; branchInfo: SessionBranchInfo | null; taintedReason: string | null; /** Wave C seam: a divergence boundary recorded for the next continuity decision. */ pendingForkReason: string | null; /** senpi#1975: first diverged field path the commit boundary named for the pending fork, when it named one. */ pendingForkDivergedPath: string | null; lastUsedAt: number; /** Digest of the access token the resident subprocess was spawned with. */ credentialDigest?: string; /** senpi#6411: the live `setModel` chain (`done` never rejects) and the model it selects, until it settles. */ pendingModelSwitch?: { done: Promise<void>; modelId: string; }; } export interface CreateSessionRegistryEntryInput { senpiSessionId: string; accountName: string; modelId: string; toolsetHash: string; systemPromptHash: string; options: Options; resume?: { sdkSessionId: string; atUuid?: string; }; } export declare class SessionRegistryResourceLimitError extends Error { readonly code = "session_registry_capacity"; constructor(); } export declare function createSessionUuid(now?: number): `${string}-${string}-${string}-${string}-${string}`; export declare class AnthropicSubscriptionSessionRegistry { private readonly entries; /** * Monotonic per-registry generation counter. Numbers are never reused for * a session id, so stale async work gated on `isCurrentGeneration` cannot be * mistaken for current after a close/reopen cycle. A per-id map of last-used * numbers would grow once per distinct session id for process lifetime; * this counter provides the same (stronger, process-wide) uniqueness with no * residue at all. */ private generationCounter; private readonly reaper; get size(): number; get(senpiSessionId: string): AnthropicSubscriptionSessionEntry | undefined; getOrCreate(input: CreateSessionRegistryEntryInput): AnthropicSubscriptionSessionEntry; touch(entry: AnthropicSubscriptionSessionEntry): void; closeSession(senpiSessionId: string, reason: string): void; isCurrentGeneration(senpiSessionId: string, generation: number): boolean; evictExpired(): void; private recordUse; private ensureCapacity; } export declare const sessionRegistry: AnthropicSubscriptionSessionRegistry; export declare function getOrCreateSession(input: CreateSessionRegistryEntryInput): AnthropicSubscriptionSessionEntry; export declare function getSession(senpiSessionId: string): AnthropicSubscriptionSessionEntry | undefined; export declare function closeSession(senpiSessionId: string, reason: string): void; export declare function isIdleExpired(entry: Pick<AnthropicSubscriptionSessionEntry, "lastUsedAt">): boolean; export declare function markTainted(senpiSessionId: string, reason: string): void; export declare function switchSessionModel(senpiSessionId: string, modelId: string, sdkModel?: string): boolean; export declare function recordPendingFork(senpiSessionId: string, reason: string, divergedPath?: string): void; export declare function recordBranchInfo(senpiSessionId: string, info: SessionBranchInfo): void; export declare function isCurrentGeneration(senpiSessionId: string, generation: number): boolean; //# sourceMappingURL=session-registry.d.ts.map