pi-context-guard-jev 0.3.1 → 0.3.2

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/docs/TESTING.md CHANGED
@@ -22,7 +22,7 @@ These need Node ≥ 22.18, which runs the `.ts` files directly. There is no netw
22
22
  | `render.test.ts` | Labels, verbatim chunks with omission lines, `read` offsets, file lists, full removal |
23
23
  | `cache-pin.test.ts` | Question pin: API-key and OAuth payloads, trailing system messages, TTL selection and `ttl-conflict`, string content, tool-result-only messages, over-budget restore. Anchors: question > read > write priority, read anchor inside a batch of tool_result blocks, breakpoint budget (identity and tools breakpoints dropped, then write, then read; the question survives a foreign breakpoint), not found / last message / already marked, normalized tool ids, TTL order, `markedToolResults` |
24
24
  | `stats.test.ts` | Savings from the projection (images by pixels), run records (checkpoints counted), lifetime total and `compacted`, status texts (`🛡 0 · Σ−79k`) and colours, cost format |
25
- | `images.test.ts` | Old images: age rule, keep-turns 0/1/3, stub text and sizes, user images / already removed / foreign-edited results skipped |
25
+ | `images.test.ts` | Old images: age rule, keep-turns 0/1/3, stub text and sizes, user images / already removed / foreign-edited results skipped, results the same pass already omits or distills keep that edit (no orphaned tool result) |
26
26
  | `size.test.ts` | Image sizes from PNG/JPEG/GIF/WebP headers, image tokens by pixels (not base64 length), thinking and tool-call sizes, `contextChars` with screenshots |
27
27
  | `recall.test.ts` | Original output, pattern (length cap, 4,000-char match window, catastrophic-regex timeout), offset/limit, line and byte caps, oversized lines |
28
28
  | `config.test.ts` | Defaults, validation and ranges (incl. `historyExchanges` 0–10 integer and the `midRun*` settings), `provider/id` parsing, load/save round trip |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-context-guard-jev",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Pi extension that removes tool output the agent no longer needs from its context. The Jev classifier keeps the needed lines verbatim; stale small outputs, unrelated old exchanges and old screenshots become one-line notes. Everything can be recalled.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/process.ts CHANGED
@@ -146,9 +146,17 @@ export async function processItems(
146
146
 
147
147
  export const emptyOutcome = (): ProcessOutcome => ({ edits: [], records: [], savedChars: 0, requests: 0, inputTokens: 0, costUsd: 0, ms: 0, timedOut: false });
148
148
 
149
- /** Add the removal of old images (no Jev request; images.ts) to `outcome`. */
149
+ /**
150
+ * Add the removal of old images (no Jev request; images.ts) to `outcome`. Results the outcome already
151
+ * edits are skipped: Pi applies a session's context_edits in order and the last one for an entry wins, so
152
+ * an image stub after an exchange omission (`replacement: null`) would bring the tool result back without
153
+ * its omitted tool call (Anthropic: 400 "unexpected `tool_use_id` found in `tool_result` blocks"), and one
154
+ * after a distillation would undo it. Skipped images stay eligible for a later pass.
155
+ */
150
156
  export function addImages(outcome: ProcessOutcome, items: readonly ImageItem[]): void {
157
+ const edited = new Set(outcome.edits.map((e) => e.targetId));
151
158
  for (const item of items) {
159
+ if (edited.has(item.entryId)) continue;
152
160
  outcome.edits.push({ type: "context_edit", targetId: item.entryId, replacement: { content: item.replacement } });
153
161
  outcome.records.push({
154
162
  kind: "image",