@caupulican/pi-adaptative 0.80.75 → 0.80.77

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/core/agent-session.d.ts +38 -1
  3. package/dist/core/agent-session.d.ts.map +1 -1
  4. package/dist/core/agent-session.js +83 -3
  5. package/dist/core/agent-session.js.map +1 -1
  6. package/dist/core/cost-guard.d.ts +55 -0
  7. package/dist/core/cost-guard.d.ts.map +1 -0
  8. package/dist/core/cost-guard.js +50 -0
  9. package/dist/core/cost-guard.js.map +1 -0
  10. package/dist/core/learning/reflection-engine.d.ts +7 -0
  11. package/dist/core/learning/reflection-engine.d.ts.map +1 -1
  12. package/dist/core/learning/reflection-engine.js +22 -13
  13. package/dist/core/learning/reflection-engine.js.map +1 -1
  14. package/dist/core/learning/skill-curator.d.ts +71 -0
  15. package/dist/core/learning/skill-curator.d.ts.map +1 -0
  16. package/dist/core/learning/skill-curator.js +179 -0
  17. package/dist/core/learning/skill-curator.js.map +1 -0
  18. package/dist/core/settings-manager.d.ts +10 -0
  19. package/dist/core/settings-manager.d.ts.map +1 -1
  20. package/dist/core/settings-manager.js +7 -0
  21. package/dist/core/settings-manager.js.map +1 -1
  22. package/dist/core/slash-commands.d.ts.map +1 -1
  23. package/dist/core/slash-commands.js +1 -0
  24. package/dist/core/slash-commands.js.map +1 -1
  25. package/dist/modes/interactive/interactive-mode.d.ts +7 -0
  26. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  27. package/dist/modes/interactive/interactive-mode.js +38 -0
  28. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  29. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  30. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  31. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  32. package/examples/extensions/sandbox/package-lock.json +2 -2
  33. package/examples/extensions/sandbox/package.json +1 -1
  34. package/examples/extensions/with-deps/package-lock.json +2 -2
  35. package/examples/extensions/with-deps/package.json +1 -1
  36. package/npm-shrinkwrap.json +12 -12
  37. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,3 +1,28 @@
1
+ ## [0.80.77] - 2026-06-28
2
+
3
+ ### Added
4
+
5
+ - Skill curator (`/curate`): reflection-promoted skills are now usage-tracked and can be reviewed instead
6
+ of accumulating forever. `/curate` lists stale/unused promoted skills proposed for (restorable)
7
+ archival and overlapping pairs proposed for consolidation; `/curate archive <name>` and
8
+ `/curate restore <name>` apply them. Propose-only — nothing is archived or merged automatically, and
9
+ hand-authored skills are never touched.
10
+
11
+ ## [0.80.76] - 2026-06-28
12
+
13
+ ### Added
14
+
15
+ - Proactive per-turn cost guard (opt-in): set `costGuard.maxTurnUsd` to estimate the dollar cost of each
16
+ turn before it is submitted and, when it exceeds the ceiling, surface a warning or (with
17
+ `costGuard.action: "downgrade"`) automatically step reasoning effort down once to curb a runaway
18
+ billing spike. Disabled by default.
19
+
20
+ ### Changed
21
+
22
+ - Background reflection now uses a static system prompt with the variable memory/turn content moved to the
23
+ user message, so repeated reflection passes reuse the provider prompt-cache prefix instead of re-billing
24
+ it — and added guidance to avoid persisting transient/environment-specific noise as memory.
25
+
1
26
  ## [0.80.75] - 2026-06-28
2
27
 
3
28
  ### Changed
@@ -13,13 +13,15 @@
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";
24
+ import { type CurationProposals } from "./learning/skill-curator.ts";
23
25
  import type { MemoryProvider } from "./memory/memory-provider.ts";
24
26
  import { type CustomMessage } from "./messages.ts";
25
27
  import type { ModelRegistry } from "./model-registry.ts";
@@ -225,6 +227,12 @@ export interface IsolatedCompletionOptions {
225
227
  maxTokens?: number;
226
228
  /** Abort signal. */
227
229
  signal?: AbortSignal;
230
+ /**
231
+ * Prompt-cache retention for this isolated call. Defaults to `"none"` (no caching — preserves full
232
+ * isolation). Callers whose `systemPrompt` is STATIC across calls (e.g. reflection, #33) can pass
233
+ * `"short"`/`"long"` so the provider reuses the cached prefix and bills only the variable tail.
234
+ */
235
+ cacheRetention?: CacheRetention;
228
236
  }
229
237
  /** Result of an isolated completion: the text, the usage spent, and the stop reason. */
230
238
  export interface IsolatedCompletionResult {
@@ -281,6 +289,12 @@ export declare class AgentSession {
281
289
  private readonly _gatewayRegistry;
282
290
  /** Cache for getSpawnedUsage(), keyed by session entry count (Bug #22 — avoid O(N) per render frame). */
283
291
  private _spawnedUsageCache?;
292
+ /** Latest proactive cost-guard decision (#34), for the host UI to surface. Undefined when disabled. */
293
+ private _lastCostGuardDecision?;
294
+ /** One-shot latch so the cost guard downgrades reasoning once per over-threshold episode, not every call. */
295
+ private _costGuardDowngraded;
296
+ /** Lazily-built skill curator (#32) over `<agentDir>/skills`. */
297
+ private _skillCuratorInstance?;
284
298
  /** Set on dispose so in-flight background reflection bails instead of writing to a dead session (Bug #21). */
285
299
  private _disposed;
286
300
  /** Aborts in-flight background reflection completions on dispose (Bug #21). */
@@ -328,6 +342,29 @@ export declare class AgentSession {
328
342
  * happens here instead of in wrappers.
329
343
  */
330
344
  private _installAgentContextTransform;
345
+ /**
346
+ * Proactive per-turn cost guard (#34): estimate the USD cost of the about-to-be-submitted turn and,
347
+ * when it exceeds the user's ceiling, record a warning decision (for the host UI to surface) and —
348
+ * if configured to `downgrade` — step reasoning effort down ONCE per over-threshold episode to curb a
349
+ * runaway billing spike. Disabled by default (`maxTurnUsd<=0`), so it never alters behavior unless the
350
+ * user opts in. Best-effort: never throws into the turn.
351
+ */
352
+ private _applyCostGuard;
353
+ /** Latest cost-guard decision (for the host footer/UI to surface a warning). Undefined if disabled. */
354
+ getLastCostGuardDecision(): CostGuardDecision | undefined;
355
+ private get _skillCurator();
356
+ /**
357
+ * Skill curator (#32): PROPOSE (never auto-apply) archival of stale reflection-promoted skills and
358
+ * consolidation of overlapping ones. The host surfaces these (e.g. a `/curate` command) for approval.
359
+ */
360
+ proposeSkillCuration(options?: {
361
+ staleDays?: number;
362
+ overlapThreshold?: number;
363
+ }): CurationProposals;
364
+ /** Archive a promoted skill into `skills/.archive/` (restorable, non-destructive). Returns true if moved. */
365
+ archivePromotedSkill(name: string): boolean;
366
+ /** Restore a previously-archived promoted skill. Returns true if moved back. */
367
+ restorePromotedSkill(name: string): boolean;
331
368
  private _installAgentTurnRefresh;
332
369
  private _createAgentContextSnapshot;
333
370
  private _contextGcStorageDir;