pi-smart-compact 10.2.0 → 10.3.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/dist/rtk.js CHANGED
@@ -198,7 +198,7 @@ class SecretScrubber {
198
198
  }
199
199
 
200
200
  // src/constants.ts
201
- var VERSION = "10.2.0";
201
+ var VERSION = "10.3.0";
202
202
  var OPTIONAL_COMPONENTS = {
203
203
  mnemopi: { name: "@oh-my-pi/pi-mnemopi", version: "18.3.1", enables: "Mnemopi memory store" },
204
204
  bun: { name: "bun", version: "1.4.2", enables: "Mnemopi worker runtime when no Bun 1.3.14+ is on PATH" },
@@ -370,11 +370,17 @@ stay on disk and manual `/smart-compact trim` still works.
370
370
  | Key | TUI label | Default | Effect |
371
371
  | --- | --- | --- | --- |
372
372
  | `contextHygieneEnabled` | `Automatic cleanup` | `true` | Batched, recoverable trimming. Needs 16,384 characters of net savings and eight assistant turns since the last trim, rewind or compaction. Works with `autoTrigger: false`. |
373
- | `contextPressureOnly` | `Cleanup timing` | `true` | Automatic cleanup and agent trim/rewind/anchor requests require the early pressure gate. `false` opts into the legacy economic/cold-cache timing below. Human commands bypass pressure, never safety checks. |
373
+ | `contextPressureOnly` | `Cleanup timing` | `true` | Automatic cleanup and autonomous agent trim/anchor requests require the early pressure gate. Human commands and one host-confirmed anchor can bypass timing, never safety checks. Checkpoint/rewind research round trips are independent of pressure. `false` opts into the legacy early/economic timing below; no switch is needed for a user-confirmed anchor. |
374
374
  | `artifactOffloadEnabled` | `Offload huge outputs` | `false` | Saves eligible read-only text results of 16,384+ characters before the model sees them. Independent of pressure gates. |
375
375
  | `visualArchiveEnabled` | `Image snapshots` | `false` | Experimental image snapshots beside the verified text. Adds image tokens; needs a vision model with a validated cost rule and the optional `@resvg/resvg-js` component (not installed with the extension; `Readiness & details` shows the install command). Without it, output falls back to text. |
376
376
  | `pinPaths` | `Always-kept files` | `[]` | Paths every summary must keep |
377
377
 
378
+ User-guided early anchors use Pi's native confirmation, not a new setting or
379
+ model-settable override. The confirmation is scoped to one anchor/cleanup;
380
+ `contextHygieneEnabled: false` disables periodic cleanup, not explicit confirmed
381
+ work. Tool/navigation permissions, prepared work and signed-thinking guards
382
+ still apply. See [user-guided anchors](./guide.md#user-guided-early-anchors).
383
+
378
384
  ### Fixed hygiene limits
379
385
 
380
386
  These limits are not configurable. Behavior and examples are in the guide's
@@ -398,8 +404,10 @@ These limits are not configurable. Behavior and examples are in the guide's
398
404
  Default: only `pressure` can trigger automatic cleanup. The shared early gate is
399
405
  `prepareContextPercent`, or the adaptive lead when null. A 400k policy window
400
406
  with the default 80% apply gate cleans from 288k and compacts from 320k.
401
- Unknown usage does not authorize cleanup. First-delivery offload and metadata
402
- checkpoints do not rewrite cached history and remain independent of pressure.
407
+ Unknown usage does not authorize automatic cleanup. First-delivery offload and
408
+ metadata checkpoints do not rewrite cached history. Explicit research rewind
409
+ is also independent of pressure: it returns to a valid checkpoint with a report,
410
+ subject to the same branch, permission, preparation and safety checks.
403
411
 
404
412
  The following economics apply **only with `contextPressureOnly: false`**.
405
413
  Let `X` be the estimated tokens a batch removes (net of its markers) and `T`
@@ -415,13 +423,17 @@ At a completed turn boundary a ready batch commits with cause:
415
423
  - `pressure` when usage reached the early pressure gate;
416
424
  - `break-even` when `N* ≤ 24`;
417
425
  - `cold` otherwise, after waiting. The batch is held (`smart_context`
418
- `status` reports it as `deferredTrim`). The first request after the cache
419
- expired (5 minutes after the last response, 1 hour when the last response
420
- that wrote cache reported 1h retention) sends the trimmed messages, later
421
- requests keep them, and the edits commit at the next completed, uncontested
422
- turn.
423
-
424
- An unknown price only allows `pressure` and `cold`. Manual and permitted agent trims
426
+ `status` reports it as `deferredTrim`). The first request beyond the estimated
427
+ cache horizon sends the trimmed messages; later requests keep them, and the
428
+ edits commit at the next completed, uncontested turn. The horizon comes from
429
+ Pi's model `promptCache` metadata (seconds), not a universal five-minute TTL.
430
+ Since the chosen retention tier is not recorded, the longest advertised tier
431
+ is used; an observed 1h write can extend it. Short tail writes never shorten
432
+ an older 1h prefix. A different model or context epoch cannot supply the clock.
433
+ Missing/invalid lifetime metadata disables `cold` timing and its warming veto,
434
+ not manual cleanup or pressure-based cleanup.
435
+
436
+ An unknown price only allows `pressure` and `cold` (the latter still needs lifetime metadata). Manual and permitted agent trims
425
437
  commit at the next boundary (causes `manual`, `agent`).
426
438
 
427
439
  A Pi cache-warming refresh counts as a response for this expiry. While a
@@ -454,7 +466,7 @@ Settings → **Agent tools & navigation**.
454
466
  | `contextPivotEnabled` | `Return to an anchor` | `true` | Returning to an anchor on a new branch with a required carryover. |
455
467
  | `contextAnchorCacheEnabled` | `Anchor prompt cache` | `true` | Anthropic models: keeps a prompt-cache marker on the newest anchor. |
456
468
  | `contextAnchorStatusEnabled` | `Anchor status` | `true` | Shows the newest anchor on this branch in Pi's footer; display only. |
457
- | `contextGuidanceEnabled` | `Navigation guide` | `true` | Lets you or the agent open the navigation guide on request; it is never added to a request otherwise. Also enables context attention: one short note to the model when context usage enters the cleanup band and again at the compaction band, naming only the context tools available right now (anchor; checkpoint/rewind and trim when history edits are possible). Re-armed once pressure clears. |
469
+ | `contextGuidanceEnabled` | `Navigation guide` | `true` | Lets you or the agent open the navigation guide on request; the full guide is never injected automatically. Also enables one short context-attention note per pressure band. Prompt-start advice uses current usage and permissions, not a parked `nextTurn` note. It names reachable tools, shares cleanup's preparation gate, and distinguishes automatic strategies and staging from applying. Checkpoint metadata can remain available when trim/rewind is blocked. Navigation off does not disable history guidance. Re-armed when pressure clears, compaction occurs or the session/model changes. |
458
470
 
459
471
  Group permissions apply in both `lazy` and `eager` modes: `compaction` follows
460
472
  `agentToolAccess`, `memory` needs `contextGraphEnabled` or a non-local
@@ -367,13 +367,16 @@ policy starts from the same history. Policies:
367
367
  pressure fires later in replay than live.
368
368
  - `timed-<N>`: the current rule with `N` in place of the break-even limit;
369
369
  pressure commits, `N* ≤ N` commits (`break-even`), otherwise the batch is held
370
- and applied at the first request after the previous request's cache lifetime
371
- (`cold`). Planning, cooldown and protected prefixes use the extension's own
370
+ and applied at the first request beyond the model's estimated cache horizon
371
+ (`cold`). The longest advertised `promptCache` tier is used when the chosen
372
+ retention is unknown; observed 1h writes can extend it. Missing lifetime
373
+ metadata never permits a cold trim. Planning, cooldown and protected prefixes use the extension's own
372
374
  `planContextTrim`/`trimEntries`/`trimTokens`.
373
375
 
374
376
  Cost model per request: the projected context is estimated per message; the
375
377
  cached prefix is the longest run of identical projected messages shared with
376
- the previous request (0 after the cache lifetime or a model switch);
378
+ the previous request (0 after the estimated cache horizon, a model switch,
379
+ or when cache lifetime metadata is unknown);
377
380
  `uncached = prompt − cached`; a rebuild is `uncached ≥ max(--rebuild-min,
378
381
  0.5 × prompt)`; price = `cacheRead × cached + (cacheWrite, else input) ×
379
382
  uncached` at catalog rates. System prompt, tool definitions and output are
package/docs/guide.md CHANGED
@@ -222,10 +222,11 @@ boundary under pressure. The other two causes below require the explicit
222
222
  - `pressure`: context usage reached the early pressure gate.
223
223
  - `break-even`: the model's catalog prices say the trim pays back its prompt
224
224
  cache rewrite within 24 further requests.
225
- - `cold`: otherwise the batch is held back until the cache has expired (5
226
- minutes after the last response, 1 hour when the last response that wrote
227
- cache reported 1h retention). A refresh from Pi's cache warming keeps the
228
- entry alive, so the batch also waits one lifetime past the latest refresh.
225
+ - `cold`: otherwise the batch waits beyond the model's estimated cache horizon.
226
+ Pi's `promptCache` metadata supplies the lifetime, not a universal five-minute
227
+ default. When the chosen retention is unknown, the longest advertised tier
228
+ is used; reported 1h writes can extend it. Missing lifetime metadata prevents
229
+ time-based cleanup. A refresh from Pi's cache warming extends this wait too.
229
230
  The first request after that already sends the trimmed context, every later
230
231
  request keeps sending it, and the edits commit at the next completed turn
231
232
  that nothing else claims.
@@ -388,36 +389,44 @@ size, an `artifact-<hash>` ID and short first/last excerpts.
388
389
 
389
390
  ## Checkpoint and rewind
390
391
 
391
- Use this for bounded research: set a checkpoint, explore, then replace the
392
- exploration with a short report.
392
+ Use this for a bounded read-only investigation, not periodic cleanup:
393
+ checkpoint → explore → rewind with findings → continue the original task.
394
+ For a purely read-only detour, the delivered context becomes the unchanged
395
+ checkpoint prefix plus one report. Finish the rewind before implementation
396
+ or your final answer; do not wait for context pressure.
393
397
 
394
398
  Example inputs (one JSON object per call; explore between checkpoint and rewind):
395
399
 
396
400
  ```jsonl
397
401
  {"action":"checkpoint","label":"Investigate auth expiry"}
398
- {"action":"rewind","report":"Expiry must use <=. Keep async API. Failed approach: local-time parsing. Next: patch and test."}
399
- {"action":"plan"}
400
- {"action":"trim"}
402
+ {"action":"rewind","report":"src/auth.ts:12: expiry must use <=. Keep async API. Failed approach: local-time parsing. Next: patch and test."}
401
403
  ```
402
404
 
403
- - Check `status` for actual usage and gates. Checkpoints are permitted below
404
- pressure; agent rewind/trim/anchor requests are not, by default. Human
405
- commands can request early work. Unsafe edits before retained signed
406
- Anthropic thinking are refused, even when thinking bytes themselves would
407
- stay unchanged.
405
+ - `checkpoint` and `rewind` do **not** require context pressure or an available
406
+ usage reading. Autonomous agent trim/anchor requests and automatic cleanup
407
+ still do by default; an early user-requested anchor requires host confirmation.
408
+ Research return is a separate operation, not a cleanup trigger.
409
+ - Check `status` when blocked. Tool permissions, prepared/running compaction,
410
+ a pending pivot and signed-thinking safety checks still apply. Keep/report
411
+ findings if blocked; do not loop, silently replace the checkpoint, or claim
412
+ the rewind completed.
408
413
  - `checkpoint`, `rewind` and `trim` return **queued**. Pi commits them at the
409
414
  end of the current tool batch.
410
- - One checkpoint is active at a time; a new one replaces it. It survives reload.
415
+ - One checkpoint is active at a time and survives reload. A second checkpoint
416
+ is rejected; finish the active one before starting another investigation.
411
417
  - New user instructions, a compaction, branch changes or edits to the context
412
418
  before the checkpoint invalidate rewind. It does not silently drop new
413
419
  requirements.
414
420
  - Rewind removes successful read-only tool exchanges as complete call/result
415
- pairs. Errors, instruction reads, incomplete exchanges, images, shell
421
+ pairs, including supported graph queries, diagnostics and web research.
422
+ It removes intermediate assistant prose, the rewind call itself and this
423
+ extension's pressure hints created during the detour, leaving one handoff.
424
+ Unrelated extension messages stay. Errors, instruction reads, incomplete exchanges, images, shell
416
425
  commands, writes and unknown tools stay.
417
426
  - **Files, processes, Git state and external effects are never rolled back.**
418
427
  - The report (maximum 8,000 characters) is written by the agent and is not
419
- verified. It should include findings, constraints, failed attempts and the
420
- next step. More than 512 eligible messages requires a normal compaction.
428
+ verified. It should include findings with evidence paths/identifiers,
429
+ constraints, failed attempts and the next step. More than 512 eligible messages requires a normal compaction.
421
430
  - `plan` previews how many outputs a trim would remove and the characters
422
431
  saved, without queuing anything.
423
432
 
@@ -432,6 +441,33 @@ anchor prefixes stay protected. It is not a full compaction; the response says
432
441
  whether cleanup was queued, blocked or unnecessary. A human may mark a milestone
433
442
  earlier. Append-only anchors do not discard an already prepared summary.
434
443
 
444
+ ### User-guided early anchors
445
+
446
+ With `contextPressureOnly: true`, you can ask the agent to mark a milestone
447
+ before the pressure gate (including when usage is unknown). The agent prepares
448
+ an anchor name and summary; Pi shows them in a native confirmation dialog.
449
+ Approval authorizes **that anchor and one safe cleanup only**. It changes no
450
+ settings, grants no future permission and needs no extra summarizer request.
451
+ The model cannot authorize itself with a `userConfirmed` argument.
452
+
453
+ - Rejecting/cancelling the dialog leaves the anchor and cleanup unrequested.
454
+ Non-interactive hosts cannot grant this exception; RPC supports the dialog.
455
+ - Session/branch changes, new history/input, revoked navigation/tool access and
456
+ cancellation invalidate pending approval. Cleanup rechecks the originating
457
+ successful tool batch and all safety/preparation gates at commit.
458
+ - User-confirmed cleanup skips automatic pressure, minimum-batch and cooldown
459
+ timing, not eligibility: recent turns, previous anchor/checkpoint prefixes,
460
+ instructions and signed-thinking dependencies stay protected. It works with
461
+ automatic cleanup disabled. An anchor can be saved even when no safe cleanup
462
+ is possible; the response says why instead of claiming context shrank.
463
+ - Autonomous anchor/trim and automatic cleanup keep their pressure policy.
464
+ `contextPressureOnly: false` remains the existing early/economic opt-in;
465
+ no global switch needs changing for a user-confirmed request.
466
+ - Full compaction remains a separate operation with its existing permission
467
+ and verification rules. An anchor does not replace the whole conversation.
468
+
469
+ ### Manual navigation panel
470
+
435
471
  Home → **History & recovery** → **Session navigation**, or `/smart-compact context`:
436
472
 
437
473
  | Row | What it does |
@@ -459,8 +495,9 @@ Settings → **Agent tools & navigation** has the switches: **Session
459
495
  navigation** (off hides the panel and the agent tool; recorded anchors and the
460
496
  other switches are kept), **Search other sessions**, **Return to an anchor**,
461
497
  **Anchor prompt cache** (Anthropic models: keeps a prompt-cache marker on the
462
- newest anchor, so the context before it is read from cache while later turns
463
- change), **Anchor status** (footer, display only) and **Navigation guide**.
498
+ newest anchor so an unchanged prefix can be reused while later turns change;
499
+ hits still depend on provider caching and expiry), **Anchor status** (footer,
500
+ display only) and **Navigation guide**.
464
501
 
465
502
  Legacy `context` tool anchors recorded in earlier sessions stay readable in
466
503
  browse and search.
@@ -647,30 +684,33 @@ out rather than estimated. Discarded preparations are only in
647
684
 
648
685
  For each assistant response in the current session, Pi Continuity records the
649
686
  prompt usage the provider reported for Pi's own request: uncached input, cache
650
- reads and cache writes. Nothing is estimated; responses without reported
651
- usage, or with zero prompt tokens (aborted or failed requests), are skipped.
687
+ reads and cache writes. Those token counts are measured; rebuild detection and
688
+ cause labels are estimates. Responses without reported usage, or with zero
689
+ prompt tokens (aborted or failed requests), are skipped.
652
690
 
653
- A request counts as a cache rebuild when it is not the session's first and
654
- its uncached tokens (input + cache writes) are at least 16,384 and at least
655
- half of its prompt tokens. Each rebuild gets one cause, checked in this order:
691
+ A request counts as an estimated rebuild when it is not the current route's
692
+ first and its uncached tokens (input + cache writes) are at least 16,384 and at
693
+ least half of its prompt tokens. Timing labels are checked in this order; they
694
+ are not provider-confirmed root causes:
656
695
 
657
696
  - **continuity**: a Continuity edit reached the branch since the previous
658
697
  request (an output trim or checkpoint rewind, a navigation pivot, or a Pi
659
698
  Continuity compaction). Edits that were queued but not committed do not
660
699
  count.
661
- - **idle-expiry**: the gap since the previous request, or since Pi's latest
662
- cache-warming refresh after it, exceeded the cache lifetime, 5 minutes, or
663
- 1 hour while the cached prefix was written with 1-hour retention (only
664
- Anthropic reports that split).
665
- - **foreign**: neither. Something else changed the prompt prefix, for
666
- example another extension, a model or tool change, Pi's built-in
667
- compaction, or eviction by the provider.
700
+ - **possible idle-expiry**: the gap since the previous request or cache-warming
701
+ refresh exceeded the model's longest advertised cache lifetime, extended by
702
+ any observed 1h writes. Unknown lifetime metadata never implies expiry.
703
+ - **foreign / cause unknown**: neither. The ledger did not observe a Continuity
704
+ edit or a known expiry horizon; this does not prove another extension changed
705
+ the prompt. Tool changes, Pi's built-in compaction or provider eviction are
706
+ possible explanations, not assigned causes. A model switch starts a new
707
+ timing baseline rather than borrowing the old model's clock.
668
708
 
669
709
  Home › Readiness & details lists the request count, the share of prompt
670
710
  tokens read from cache, rebuilds by cause with their uncached tokens, and the
671
711
  cost Pi priced from that usage when the model has catalog prices. The third
672
- foreign rebuild in a session shows one notice with the count and uncached
673
- tokens. The ledger is session-local: it resets on a new or switched session,
712
+ unassigned rebuild records one diagnostic with the count and uncached tokens;
713
+ it does not duplicate Pi's cache-miss notification. The ledger is session-local: it resets on a new or switched session,
674
714
  is not persisted, and covers only Pi's own requests; Pi Continuity's summary
675
715
  calls are in `/smart-compact metrics` instead.
676
716
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-smart-compact",
3
- "version": "10.2.0",
3
+ "version": "10.3.0",
4
4
  "description": "Pi Continuity — context hygiene and session continuity for Pi Coding Agent: recoverable cleanup, checkpoints, memory and verified compaction.",
5
5
  "type": "module",
6
6
  "packageManager": "bun@1.4.2",