@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
94 lines • 4.59 kB
TypeScript
import { type CursorCliErrorClassification, type CursorCliErrorInput } from "./errors.ts";
import type { CursorCliOauthResumeMode } from "./settings.ts";
export declare const CURSOR_CLI_CONTEXT_RECAP_MAX_BYTES: number;
export declare const CURSOR_CLI_CONTEXT_RECAP_BEGIN = "===== senpi context recap =====";
export declare const CURSOR_CLI_CONTEXT_RECAP_END = "===== end senpi context recap =====";
export type CursorCliSessionRecord = {
readonly accountName: string;
readonly chatId: string;
readonly lastModel: string;
readonly lastUsedAt: number;
};
export type CursorCliRecapExchange = {
readonly role: "user" | "assistant";
readonly text: string;
};
export type CursorCliSessionTurnContext = {
readonly senpiSessionId: string;
readonly accountName: string;
};
export type CursorCliSessionTurnInput = {
readonly prompt: string;
readonly model: string | undefined;
readonly recentExchanges?: readonly CursorCliRecapExchange[];
};
export type CursorCliSessionPolicy = {
readonly resumeMode?: CursorCliOauthResumeMode;
readonly contextRecapOnModelSwitch?: boolean;
readonly maxRecapBytes?: number;
readonly promptCeilingBytes?: number;
};
export type CursorCliTurnPlan = {
/** Chat id passed as `--resume`, or undefined for a fresh chat. */
readonly resumeChatId: string | undefined;
/** Final spawn prompt: the recap block prepended unless it had to be dropped for the ceiling. */
readonly prompt: string;
readonly contextRecap: string | undefined;
readonly modelSwitch: boolean;
readonly recapDroppedForCeiling: boolean;
};
export type CursorCliSessionAttempt = {
readonly prompt: string;
readonly resumeChatId: string | undefined;
};
export type CursorCliSessionInitObservation = {
readonly chatId: string;
readonly model: string;
};
export type CursorCliSessionRestartReason = "resume_failed" | "context_overflow";
export type CursorCliSessionRestartNotice = {
readonly type: "cursor_chat_restarted";
readonly message: string;
readonly previousChatId: string;
readonly reason: CursorCliSessionRestartReason;
};
export type CursorCliSessionRunOptions<TEvent> = {
readonly senpiSessionId: string;
readonly accountName: string;
readonly runAttempt: (attempt: CursorCliSessionAttempt) => AsyncIterable<TEvent> | Promise<AsyncIterable<TEvent>>;
readonly now?: () => number;
readonly classify?: (input: CursorCliErrorInput) => CursorCliErrorClassification;
readonly errorFromEvent?: (event: TEvent) => CursorCliErrorInput | undefined;
readonly initFromEvent?: (event: TEvent) => CursorCliSessionInitObservation | undefined;
readonly isVisibleAssistantDelta?: (event: TEvent) => boolean;
} & CursorCliSessionPolicy;
export type CursorCliSessionRouterDeps = {
readonly now?: () => number;
};
/**
* Builds the one-turn context recap from senpi's own last exchanges, wrapped in
* explicit delimiters and hard-capped at `maxRecapBytes` (delimiters included).
* The newest exchanges are kept; older ones are dropped first.
*/
export declare function buildCursorCliContextRecap(model: string | undefined, exchanges: readonly CursorCliRecapExchange[] | undefined, maxRecapBytes?: number): string | undefined;
/**
* Sticky per-senpi-session chat routing for the Cursor CLI lane. This lane
* spawns once per turn, so routing state is just the last observed
* `system/init` per senpi session - no resident CLI process exists to manage.
* The turn decision itself is pure; records change only when an init event is
* observed, so cancelled or failed turns leave prior routing intact.
*/
export declare class CursorCliSessionRouter {
private readonly records;
private readonly nowFn;
constructor(deps?: CursorCliSessionRouterDeps);
getRecord(senpiSessionId: string): Readonly<CursorCliSessionRecord> | undefined;
clear(senpiSessionId: string): void;
planTurn(context: CursorCliSessionTurnContext, input: CursorCliSessionTurnInput, policy?: CursorCliSessionPolicy): CursorCliTurnPlan;
/** Records the chat id and effective model reported by `system/init`. */
observeInit(context: CursorCliSessionTurnContext, init: CursorCliSessionInitObservation, at?: number): void;
runTurn<TEvent>(options: CursorCliSessionRunOptions<TEvent>, input: CursorCliSessionTurnInput): AsyncGenerator<TEvent | CursorCliSessionRestartNotice>;
}
/** Shared router instance; one record per senpi session, in-process. */
export declare const cursorCliSessionRouter: CursorCliSessionRouter;
//# sourceMappingURL=session-router.d.ts.map