@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
32 lines • 1.95 kB
TypeScript
import type { ContentBlockParam } from "@anthropic-ai/sdk/resources/messages.js";
export interface DedupeResult {
blocks: ContentBlockParam[];
collapsedDirectives: number;
}
/**
* Total UTF-8 byte size of the serialized prompt's text blocks. Uses
* `Buffer.byteLength` rather than `String.length`, which counts UTF-16 code
* units and understates every multibyte payload (Korean, emoji, CJK) that the
* lane actually pays for on the wire.
*/
export declare function serializedPayloadBytes(blocks: readonly ContentBlockParam[]): number;
/**
* Collapse repeated `<ultrawork-mode>...</ultrawork-mode>` directive spans in a serialized
* prompt. Without this, every flatten/bootstrap re-send bills ~17KB per duplicate (issue #494's
* 875KB prompt was 73% such duplicates).
*
* Invariants (load-bearing):
* - Spans match WITHIN a single text block; a lone open tag in one block and a close tag in
* another never form a span.
* - Inside the replayed history (before `CONVERSATION_HISTORY_CLOSER`), a directive identical to the
* directive just before it becomes a placeholder; a directive whose text differs is kept in full,
* so the newest wording is always present and an A, B, A sequence keeps all three. Each decision
* depends only on earlier blocks, so a rebuilt prompt stays a byte prefix of the next one and
* reads its history from the prompt cache (senpi#2982). Keeping the last copy instead rewrote an
* earlier block every time a new directive arrived.
* - After the closer (the current turn), nothing is collapsed: the active directive stays in full.
* - Other block fields (`cache_control`) are preserved, and the input array is never mutated, so
* continuity hashes (derived from `context.messages` in `session-sync.ts`) are unaffected.
*/
export declare function dedupeUltraworkBlocks(blocks: readonly ContentBlockParam[]): DedupeResult;
//# sourceMappingURL=prompt-directive-dedupe.d.ts.map