@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
102 lines • 5.37 kB
TypeScript
/**
* Provider-scoped compaction ownership for the `anthropic-subscription` main lane.
*
* That lane keeps one resident SDK session per senpi session. By default senpi
* owns its compaction (speculative, idle, restoration, degradation recovery): an
* accepted compaction invalidates the resident binding and the next turn
* cold-seeds the compacted branch (`tainted_compaction` always flattens), while
* the SDK's native auto-compact is pinned off so exactly one side compacts.
*
* `compactionOwner: "sdk"` opts out: the Claude Agent SDK runs its own native
* auto-compaction over the resident transcript and senpi stands down for the
* lane (no auto-compaction triggers, no context reduction). The stand-down lifts
* with the `resumeMode: "off"` escape hatch, where senpi flattens its own
* history into every request. Every other provider is untouched.
*
* The owner is read per call, from the same settings snapshot the query options
* use for the next turn, so a mid-session change can never leave the two sides
* disagreeing about who compacts.
*
* This module also owns the shape of the mirrored `compact_boundary` ledger
* entry, so the SDK's native compactions stay visible in senpi history.
*/
import type { AgentMessage } from "@earendil-works/pi-agent-core";
import type { SessionEntry } from "../../../session-manager.ts";
import type { CompactionReason } from "../../types.ts";
import type { AnthropicSubscriptionProviderSettings } from "../anthropic-subscription/settings.ts";
/** Custom session entry type carrying a mirrored SDK compaction boundary. */
export declare const ANTHROPIC_SUBSCRIPTION_COMPACT_ENTRY_TYPE = "claude-sdk-oauth-compact";
/** Assistant-message diagnostic the lane uses to transport a received boundary. */
export declare const ANTHROPIC_SUBSCRIPTION_COMPACT_BOUNDARY_DIAGNOSTIC = "claude_sdk_oauth_compact_boundary";
/**
* Reason reported when senpi declines to compact an SDK-native lane. The
* `external-owner` rejection cause carries the machine-readable policy while
* this string is what the user and the compaction log see.
*/
export declare const SDK_NATIVE_LANE_REJECTION_REASON = "the Claude Agent SDK owns compaction for this session";
declare const COMPACT_BOUNDARY_SCHEMA = "senpi.claude-sdk-oauth.compact-boundary.v1";
export interface LaneModel {
provider?: string;
}
export interface SdkNativeLaneInput {
model: LaneModel | undefined;
/** Resolved `claudeSdkOauthProvider.resumeMode`; `undefined` means the "auto" default. */
resumeMode?: string;
/** Resolved `anthropicSubscriptionProvider.compactionOwner`; `undefined` means the "senpi" default. */
compactionOwner?: string;
}
export interface LaneContext {
cwd: string;
model: LaneModel | undefined;
/**
* Optional resolved-settings getter (present on the real ExtensionContext).
* Used to read a configured `compaction.model` override. When an override is
* set the lane hands summarization to a senpi-owned model, so the SDK-native
* stand-down no longer applies even with a resident SDK session.
*/
getCompactionSettings?: () => {
model?: string;
};
/** Branch reader (present on the real ExtensionContext) used to find a failed cold-seed turn. */
sessionManager?: {
getBranch(): readonly SessionEntry[];
};
}
export interface CompactionLanePolicy {
/** True when the SDK owns this lane's context and senpi compaction must stand down. */
disablesSenpiCompaction(context: LaneContext): boolean;
/** Manual requests are explicitly owned by senpi for recovery, even on SDK lanes. */
ownsCompaction(context: LaneContext, reason: CompactionReason): boolean;
/**
* True when the active lane replays its transcript into a resident SDK session that
* only accepts appended messages. Per-turn history rewrites (no-LLM context reduction)
* would diverge it and force a full cold re-send every turn, so they must not run;
* compaction (one summary, one cold-seed) is the reduction path there.
*/
hasAppendOnlyTranscript(context: LaneContext): boolean;
}
export interface CompactBoundaryEntry {
schema: typeof COMPACT_BOUNDARY_SCHEMA;
sdkSessionId: string;
uuid: string;
compactMetadata: Record<string, unknown>;
}
/**
* Pure lane predicate. Kept separate from {@link createCompactionLanePolicy} so
* callers that already know the resolved resume mode never touch disk.
*/
export declare function isSdkNativeCompactionLane(input: SdkNativeLaneInput): boolean;
/**
* Per-extension-instance lane policy. Settings are only read when the active
* model actually belongs to the lane, so other providers never pay for the
* lookup; the loader itself is cached by settings-file revision.
*/
export declare function createCompactionLanePolicy(options?: {
loadProviderSettings?: (cwd: string) => AnthropicSubscriptionProviderSettings;
}): CompactionLanePolicy;
/** Parse an SDK `compact_boundary` system message into the senpi ledger payload. */
export declare function parseCompactBoundaryMessage(value: unknown): CompactBoundaryEntry | undefined;
/** Collect every compaction boundary the lane attached to a finalized message. */
export declare function collectCompactBoundaryEntries(message: AgentMessage): CompactBoundaryEntry[];
export {};
//# sourceMappingURL=lane-policy.d.ts.map