UNPKG

@code-yeongyu/senpi

Version:

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

76 lines • 5.15 kB
import type { ResumeModeSource } from "./settings.ts"; /** * Per-turn continuity observability for the claude-sdk-oauth lane. * * Emission semantics: a decision is STAGED per attempt at its final outcome * point and EMITTED only when the auth-lane retain/discard wrapper retains that * attempt (auth-attempt.ts). A discarded attempt emits nothing, so every * completed turn yields exactly one observation; a turn where every attempt * fails yields one terminal `failed` observation instead. `failed` is not a * re-send: the next attempt still resumes from the retry checkpoint. */ export type ContinuityKind = "bootstrap" | "delta" | "reattach" | "fork" | "flatten" | "disabled" | "failed"; /** Fixed vocabulary — arbitrary error text never reaches an observation. */ export type ContinuityReason = "prefix_matched" | "registry_miss" | "idle_ttl" | "capacity" | "model_selected" | "thinking_level_selected" | "bound_account_token_expiring" | "account_changed" | "credential_refreshed" | "model_changed" | "toolset_changed" | "system_prompt_changed" | "assistant_stream_diverged" | "sent_stream_diverged" | "options_changed" | "history_rolled_back" | "assistant_rewritten" | "transcript_missing" | "cross_root_unsupported" | "branch_diverged" | "branch_boundary_unavailable" | "branch_resume" | "tainted_compaction" | "tainted_fork" | "tainted_abort" | "tainted_assistant_provenance_unverified" | "resume_initialization_failed" | "resume_initialization_aborted" | "resume_mode_off" | "query_failed" | "turn_attribution_failed" | "session_unconfirmed" | "abort_timeout" | "extensions_removed" | "session_shutdown" | "timeout_retry" | "other"; export type ContinuityObservation = { kind: ContinuityKind; reason: ContinuityReason; deltaMessages?: number; payloadBytes?: number; collapsedDirectives?: number; /** Where a `disabled`/`resume_mode_off` setting came from, so the notice can name it. */ settingSource?: ResumeModeSource; /** * Short digest of the serving account, never its name: lets a quota cascade be attributed * to seats without reading credentials (oh-my-openagent#10304). */ seat?: string; /** The attempt runs on a different seat than the lineage's last one: its prompt cache is cold. */ seatChanged?: boolean; /** senpi#1975: first diverged field path behind an assistant_rewritten decision. Paths only, never values. */ divergedPath?: string; }; export type ContinuityObservabilityBoundary = { emit: (observation: ContinuityObservation) => void; log: (event: string, data: Record<string, unknown>) => void; }; export declare function overrideContinuityObservabilityBoundary(override: Partial<ContinuityObservabilityBoundary>): void; export declare function resetContinuityObservabilityBoundary(): void; /** Writes one structured session.log line through the active boundary (never conversation content). */ export declare function logContinuityEvent(event: string, data: Record<string, unknown>): void; /** Maps a fixed vocabulary member through, and anything else to a bucketed cause. */ export declare function sanitizeReason(value: unknown): ContinuityReason; /** Buckets arbitrary close/pump failures into the fixed close-cause vocabulary. */ export declare function sanitizeCloseCause(value: unknown): ContinuityReason; /** * Classifies the failure that ended a turn after every auth attempt failed. * Anything reaching here came out of the SDK query path, so an Error is a query * failure unless it matches a more specific bucket; the raw text never escapes. */ export declare function sanitizeTerminalFailure(value: unknown): ContinuityReason; export declare function recordPendingCloseCause(senpiSessionId: string, reason: unknown): void; /** Read the pending close cause WITHOUT consuming it (consumed at emit time). */ export declare function peekPendingCloseCause(senpiSessionId: string): ContinuityReason | undefined; export declare function consumePendingCloseCause(senpiSessionId: string): ContinuityReason | undefined; /** * Maps the continuity decision families onto the observation vocabulary: * incremental→delta, resume→fork, cold-seed→flatten. */ export declare function observeSessionSyncDecision(input: { kind: "incremental" | "resume" | "cold-seed"; reason?: string; deltaMessages: number; firstTurn: boolean; senpiSessionId: string; payloadBytes?: number; collapsedDirectives?: number; divergedPath?: string; }): ContinuityObservation; export type StagedContinuityDecision = { observation: ContinuityObservation; emit: () => void; }; /** Stages an attempt's decision; `emit` fires only when the attempt is retained. */ export declare function stageContinuityDecision(observation: ContinuityObservation, sessionId: string, onDecision?: (observation: ContinuityObservation) => void, beforeEmit?: () => void): StagedContinuityDecision; export declare function emitContinuityObservation(observation: ContinuityObservation, sessionId: string | undefined, onDecision?: (observation: ContinuityObservation) => void): void; //# sourceMappingURL=session-observability.d.ts.map