pi-condense 2.6.0 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/PRUNING.md +32 -3
- package/README.md +12 -1
- package/index.ts +288 -109
- package/package.json +1 -1
- package/src/budget.test.ts +49 -2
- package/src/budget.ts +22 -8
- package/src/commands.test.ts +138 -4
- package/src/commands.ts +32 -11
- package/src/context-metrics.test.ts +335 -0
- package/src/context-metrics.ts +152 -0
- package/src/reload-rearm.integration.test.ts +647 -0
- package/src/summarizer-wiring.test.ts +2 -0
- package/src/types.ts +48 -6
package/src/types.ts
CHANGED
|
@@ -87,6 +87,13 @@ export const CUSTOM_TYPE_CHAIN = "context-prune-chain";
|
|
|
87
87
|
*/
|
|
88
88
|
export const CUSTOM_TYPE_DIAGNOSTIC = "context-prune-diagnostic";
|
|
89
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Per-flush-attempt observability record. Written once per non-concurrent
|
|
92
|
+
* flushPending invocation, regardless of outcome (including "empty" and
|
|
93
|
+
* "error"). Append-only log: never in LLM context, never reconstructed.
|
|
94
|
+
*/
|
|
95
|
+
export const CUSTOM_TYPE_FLUSH_METRICS = "context-prune-flush-metrics";
|
|
96
|
+
|
|
90
97
|
export type DiagnosticKind = "unresolved-range" | "range-id-mismatch" | "orphan-sweep";
|
|
91
98
|
|
|
92
99
|
export interface DiagnosticEntryData {
|
|
@@ -232,7 +239,8 @@ export const SUMMARIZER_MAX_TIMEOUT_PRESETS: { value: string; label: string }[]
|
|
|
232
239
|
/**
|
|
233
240
|
* Cycling presets for the `autoBudgetThreshold` setting (stored as strings;
|
|
234
241
|
* the settings UI cycles string values). "0" is the disabled sentinel → null.
|
|
235
|
-
* Other values are 0–1 fractions of the context window (e.g. "0.8" = flush at
|
|
242
|
+
* Other values are 0–1 fractions of the context window (e.g. "0.8" = flush at
|
|
243
|
+
* 80% of the window, or at MAX_BUDGET_WINDOW tokens, whichever comes first).
|
|
236
244
|
*/
|
|
237
245
|
export const AUTO_BUDGET_PRESETS: { value: string; label: string }[] = [
|
|
238
246
|
{ value: "0", label: "Off (default)" },
|
|
@@ -380,10 +388,14 @@ export interface ContextPruneConfig {
|
|
|
380
388
|
/**
|
|
381
389
|
* Token-budget auto-flush trigger. A fraction in (0, 1] (a 0–1 share of the
|
|
382
390
|
* context window, NOT a 0–100 percentage; e.g. 0.8 = flush at 80% of the
|
|
383
|
-
* window). When set, a flush of all
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
391
|
+
* window, capped at 300k tokens - see below). When set, a flush of all
|
|
392
|
+
* pending batches is forced at the end of
|
|
393
|
+
* any tool-using turn once context usage reaches `threshold * contextWindow`
|
|
394
|
+
* tokens OR 300,000 tokens (MAX_BUDGET_WINDOW in src/budget.ts), whichever
|
|
395
|
+
* comes first — regardless of `pruneOn`. The ceiling keeps the setting
|
|
396
|
+
* reachable on huge-window models, where 0.9 of 1M would mean 900k tokens; it
|
|
397
|
+
* never binds on a model advertising 300k or less. An ADDITIONAL trigger on
|
|
398
|
+
* top of `pruneOn`, not a replacement.
|
|
387
399
|
*
|
|
388
400
|
* null (default) = disabled, preserving pre-feature behavior. Out-of-range
|
|
389
401
|
* values (<= 0 or > 1) normalize to null.
|
|
@@ -395,7 +407,11 @@ export interface ContextPruneConfig {
|
|
|
395
407
|
spillPreviewBytes: number;
|
|
396
408
|
/**
|
|
397
409
|
* Per-turn usage-fraction increase (0–1) that forces a flush, independent of
|
|
398
|
-
* autoBudgetThreshold.
|
|
410
|
+
* autoBudgetThreshold. The fraction is measured against the effective window
|
|
411
|
+
* `min(contextWindow, MAX_BUDGET_WINDOW)` (300_000), so the required growth is
|
|
412
|
+
* `delta * min(contextWindow, MAX_BUDGET_WINDOW)` tokens - e.g. 0.1 means +30k
|
|
413
|
+
* tokens in one turn on any model at or above 300k, and +20k on a 200k model.
|
|
414
|
+
* null (default) = disabled. Out-of-range (<= 0 or > 1) normalizes to null.
|
|
399
415
|
*/
|
|
400
416
|
budgetTurnDelta: number | null;
|
|
401
417
|
}
|
|
@@ -672,6 +688,30 @@ export interface SummaryMessageDetails {
|
|
|
672
688
|
timestamp: number;
|
|
673
689
|
}
|
|
674
690
|
|
|
691
|
+
/** Snapshot of what the pruner cannot (yet) reclaim. All token values are Math.round(JSON-chars / 4). */
|
|
692
|
+
export interface ContextMetricsSnapshot {
|
|
693
|
+
/** Est. tokens of thinking blocks retained in the trailing open segment. */
|
|
694
|
+
openCycleThinkingTokens: number;
|
|
695
|
+
/** max(largest closed chain, open segment) chars / total branch chars, 0-100. */
|
|
696
|
+
largestChainSharePct: number;
|
|
697
|
+
/** Est. tokens of summarization-eligible unsummarized toolResults after the frontier. */
|
|
698
|
+
frontierGapTokens: number;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
export type FlushTrigger = "budget" | "delta" | "message-end" | "manual" | "rearmed";
|
|
702
|
+
|
|
703
|
+
/** Payload of CUSTOM_TYPE_FLUSH_METRICS. */
|
|
704
|
+
export interface FlushMetricsEntry {
|
|
705
|
+
ts: number;
|
|
706
|
+
trigger: FlushTrigger;
|
|
707
|
+
/** Batches after rescan+trim, before processing. */
|
|
708
|
+
capturedBatches: number;
|
|
709
|
+
processedBatches: number;
|
|
710
|
+
outcome: "summarized" | "skipped-oversized" | "skipped-deduped" | "skipped-trivial" | "empty" | "error";
|
|
711
|
+
/** Computed at flush ENTRY (pre-flush pressure). */
|
|
712
|
+
metrics: ContextMetricsSnapshot;
|
|
713
|
+
}
|
|
714
|
+
|
|
675
715
|
// ── Summarizer stats ────────────────────────────────────────────────────────
|
|
676
716
|
|
|
677
717
|
/**
|
|
@@ -794,6 +834,8 @@ export interface FlushOptions {
|
|
|
794
834
|
* the frontier. All pending batches are restored so the next flush can retry.
|
|
795
835
|
*/
|
|
796
836
|
signal?: AbortSignal;
|
|
837
|
+
/** Which trigger initiated this flush. Defaults to "manual" when absent. */
|
|
838
|
+
trigger?: FlushTrigger;
|
|
797
839
|
/**
|
|
798
840
|
* The final text-only assistant message that triggered an agent-message flush.
|
|
799
841
|
* pi emits `message_end` to extensions before persisting it to the session, so it
|