/** * PSYCHE-MEMORY block budgeting for spawn prompts (T12519 · E-TOKEN-ECONOMY). * * `buildRetrievalBundle` returns up to ~400 cold-pass user-profile traits plus * the ten most recent learnings, patterns and decisions. It does not consider * the task being spawned. Rendering all of it made the PSYCHE-MEMORY block * about 51 % of a tier-1 prompt (measured 2026-09-27: ~3,844 of 7,497 tokens). * Most of that was operation receipts ("Cleo tasks update operation * succeeded") and dispatch traces. * * This module turns a bundle into a bounded block: * * 1. **Exclude noise.** Drop entries that only record an operation succeeding, * and serialized dispatch traces. See {@link isOperationReceiptText} for why * this is a text match rather than a field match. * 2. **Rank by relevance to the spawned task.** First by overlap with the * task's id, epic, labels and files. Then by stored quality score. Then by * citation count. * 3. **Cap at a token budget** ({@link PSYCHE_MEMORY_TOKEN_BUDGET}) using the * repo's `estimateTokens` (chars / 4). Entries are admitted whole or not at * all, never cut mid-entry. The omitted count is surfaced as a single * `cleo memory find` pointer line. * * @module orchestration/psyche-memory-budget * @task T12519 * @epic T12484 */ import type { RetrievalBundle, Task } from '@cleocode/contracts'; /** Default token budget for the whole `## PSYCHE-MEMORY` block (T12519). */ export declare const PSYCHE_MEMORY_TOKEN_BUDGET = 800; /** * Whether memory text only records that an operation succeeded, or is a * serialized dispatch trace. Such text carries no knowledge a spawned agent * can act on. * * @param text - Entry text (trait value, pattern, insight, title, …). * @returns `true` when the entry is noise and must not be injected. */ export declare function isOperationReceiptText(text: string): boolean; /** Task facts used to rank memory entries by relevance. */ export interface PsycheRelevanceContext { /** Id of the task being spawned. */ taskId: string; /** Parent (epic) id of the spawned task, when it has one. */ epicId?: string | null; /** Task labels. */ labels?: readonly string[]; /** Files the task declares. */ files?: readonly string[]; } /** * Derive a {@link PsycheRelevanceContext} from a task record. * * @param task - The task being spawned. * @returns The relevance context for ranking memory entries. */ export declare function relevanceContextFromTask(task: Task): PsycheRelevanceContext; /** Inputs for {@link buildBudgetedPsycheMemoryBlock}. */ export interface BudgetedPsycheMemoryInput { /** Retrieval bundle from `buildRetrievalBundle`. */ bundle: RetrievalBundle; /** Relevance facts of the spawned task. */ relevance: PsycheRelevanceContext; /** Pre-rendered, already-bounded Tier-2 attention digest lines (T11374). */ attentionDigestLines?: readonly string[]; /** Token budget for the whole block. Defaults to {@link PSYCHE_MEMORY_TOKEN_BUDGET}. */ tokenBudget?: number; } /** Result of {@link buildBudgetedPsycheMemoryBlock}. */ export interface BudgetedPsycheMemoryResult { /** The rendered `## PSYCHE-MEMORY` markdown section. */ block: string; /** Estimated tokens of `block` (chars / 4). */ tokens: number; /** Entries rendered. */ shown: number; /** Relevant (non-noise) entries omitted because the budget ran out. */ omitted: number; /** Entries dropped as operation receipts / dispatch traces. */ excludedNoise: number; } /** * Render the `## PSYCHE-MEMORY` block under a token budget. * * The header, the attention digest (already bounded by its own renderer) and * the sigil card are fixed. Every other entry competes for the remaining * budget in rank order: pinned first, then overlap score, then quality, then * citations, then bundle (recency) order. An entry that does not fit is skipped * whole, and a smaller one further down may still fit. Admitted entries render * grouped under their usual section headings, in rank order within each * section. * * @param input - Bundle, relevance context, attention lines and budget. * @returns The rendered block plus accounting. * * @example * ```ts * const { block } = buildBudgetedPsycheMemoryBlock({ * bundle, * relevance: relevanceContextFromTask(task), * }); * ``` */ export declare function buildBudgetedPsycheMemoryBlock(input: BudgetedPsycheMemoryInput): BudgetedPsycheMemoryResult; //# sourceMappingURL=psyche-memory-budget.d.ts.map