@caupulican/pi-adaptative 0.80.75 → 0.80.76

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 CHANGED
@@ -1,3 +1,18 @@
1
+ ## [0.80.76] - 2026-06-28
2
+
3
+ ### Added
4
+
5
+ - Proactive per-turn cost guard (opt-in): set `costGuard.maxTurnUsd` to estimate the dollar cost of each
6
+ turn before it is submitted and, when it exceeds the ceiling, surface a warning or (with
7
+ `costGuard.action: "downgrade"`) automatically step reasoning effort down once to curb a runaway
8
+ billing spike. Disabled by default.
9
+
10
+ ### Changed
11
+
12
+ - Background reflection now uses a static system prompt with the variable memory/turn content moved to the
13
+ user message, so repeated reflection passes reuse the provider prompt-cache prefix instead of re-billing
14
+ it — and added guidance to avoid persisting transient/environment-specific noise as memory.
15
+
1
16
  ## [0.80.75] - 2026-06-28
2
17
 
3
18
  ### Changed
@@ -13,10 +13,11 @@
13
13
  * Modes use this class and add their own I/O layer on top.
14
14
  */
15
15
  import type { Agent, AgentEvent, AgentMessage, AgentState, AgentTool, ThinkingLevel } from "@caupulican/pi-agent-core";
16
- import type { ImageContent, Message, Model, StopReason, TextContent, Usage } from "@caupulican/pi-ai";
16
+ import type { CacheRetention, ImageContent, Message, Model, StopReason, TextContent, Usage } from "@caupulican/pi-ai";
17
17
  import { type BashResult } from "./bash-executor.ts";
18
18
  import { type CompactionResult } from "./compaction/index.ts";
19
19
  import { type ContextGcReport } from "./context-gc.ts";
20
+ import { type CostGuardDecision } from "./cost-guard.ts";
20
21
  import { type ContextUsage, type ExtensionCommandContextActions, type ExtensionContext, type ExtensionErrorListener, ExtensionRunner, type ExtensionUIContext, type InputSource, type ReplacedSessionContext, type SessionStartEvent, type ShutdownHandler, type ToolDefinition, type ToolInfo } from "./extensions/index.ts";
21
22
  import { type ChannelProvider, GatewayRegistry, type JobSchedulerProvider } from "./gateways/channel-provider.ts";
22
23
  import { type DemandSignals, type ReflectionResult } from "./learning/reflection-engine.ts";
@@ -225,6 +226,12 @@ export interface IsolatedCompletionOptions {
225
226
  maxTokens?: number;
226
227
  /** Abort signal. */
227
228
  signal?: AbortSignal;
229
+ /**
230
+ * Prompt-cache retention for this isolated call. Defaults to `"none"` (no caching — preserves full
231
+ * isolation). Callers whose `systemPrompt` is STATIC across calls (e.g. reflection, #33) can pass
232
+ * `"short"`/`"long"` so the provider reuses the cached prefix and bills only the variable tail.
233
+ */
234
+ cacheRetention?: CacheRetention;
228
235
  }
229
236
  /** Result of an isolated completion: the text, the usage spent, and the stop reason. */
230
237
  export interface IsolatedCompletionResult {
@@ -281,6 +288,10 @@ export declare class AgentSession {
281
288
  private readonly _gatewayRegistry;
282
289
  /** Cache for getSpawnedUsage(), keyed by session entry count (Bug #22 — avoid O(N) per render frame). */
283
290
  private _spawnedUsageCache?;
291
+ /** Latest proactive cost-guard decision (#34), for the host UI to surface. Undefined when disabled. */
292
+ private _lastCostGuardDecision?;
293
+ /** One-shot latch so the cost guard downgrades reasoning once per over-threshold episode, not every call. */
294
+ private _costGuardDowngraded;
284
295
  /** Set on dispose so in-flight background reflection bails instead of writing to a dead session (Bug #21). */
285
296
  private _disposed;
286
297
  /** Aborts in-flight background reflection completions on dispose (Bug #21). */
@@ -328,6 +339,16 @@ export declare class AgentSession {
328
339
  * happens here instead of in wrappers.
329
340
  */
330
341
  private _installAgentContextTransform;
342
+ /**
343
+ * Proactive per-turn cost guard (#34): estimate the USD cost of the about-to-be-submitted turn and,
344
+ * when it exceeds the user's ceiling, record a warning decision (for the host UI to surface) and —
345
+ * if configured to `downgrade` — step reasoning effort down ONCE per over-threshold episode to curb a
346
+ * runaway billing spike. Disabled by default (`maxTurnUsd<=0`), so it never alters behavior unless the
347
+ * user opts in. Best-effort: never throws into the turn.
348
+ */
349
+ private _applyCostGuard;
350
+ /** Latest cost-guard decision (for the host footer/UI to surface a warning). Undefined if disabled. */
351
+ getLastCostGuardDecision(): CostGuardDecision | undefined;
331
352
  private _installAgentTurnRefresh;
332
353
  private _createAgentContextSnapshot;
333
354
  private _contextGcStorageDir;