@foliox/transparent-compact-pi 0.8.6 → 0.8.7

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
@@ -2,7 +2,24 @@
2
2
 
3
3
  ## Unreleased — initial release preparation
4
4
 
5
- - Scope recovery guidance to specific earlier details lost to compaction in the
5
+ - Advertise recovery positively as retrieving history hidden by compaction, with
6
+ explicit provenance and contradiction triggers in the lookup description, skill,
7
+ and post-compaction reminders. Distinguish historical observations from current
8
+ source contents; allow cheap rereads/recomputations and avoid blanket fact
9
+ re-verification. Re-orientation leads with ordinary input restoration and makes
10
+ lookup conditional on a hidden historical need, rather than reusing the tool
11
+ advertisement. Shorten fallback descriptions by referring to lookup's scope
12
+ rather than repeating it. Keep recovery scope, fallback, and filesystem boundaries.
13
+
14
+ - Make compaction tool signatures leaner: short outcome labels, relative project
15
+ paths, write sizes and edit counts instead of payload previews, and a single
16
+ ellipsis for abbreviated arguments. Keep bash previews at 160 characters and
17
+ preserve complete file-tool paths. Bound user bash-execution stubs too. Raw
18
+ history, retained outputs, and user/assistant prose are unchanged.
19
+ - Mark all size-trimmed spans, including partial removals and shortened user
20
+ messages; no longer label originally empty spans as trimmed.
21
+
22
+ - Scope recovery guidance to specific earlier details hidden by compaction in the
6
23
  current conversation, not startup, project discovery, or missing requirements.
7
24
  Filesystem restrictions apply only to that recovery workflow, not user-requested
8
25
  session audits, debugging, or cross-session analysis. Remove the misleading
@@ -29,10 +46,11 @@
29
46
  raw session history; previously saved spans are not rewritten. Managed
30
47
  re-orientation messages continue to be regenerated instead.
31
48
  - Tool signatures record per-call `ok`, `error`, or `unknown` outcomes from
32
- matched tool-result metadata, always marking output as removed. Missing or
49
+ matched tool-result metadata; the header explains that outputs are removed. Missing or
33
50
  ambiguous outcomes are never inferred, including unlabelled older spans.
34
- - Read-file entries distinguish retained startup reads from removed content; a closing evidence rule
35
- requires lookup or re-reading before relying on removed outputs or document rules.
51
+ - Read-file entries distinguish retained startup reads from removed content; a closing
52
+ evidence rule directs historical evidence/provenance questions to lookup and
53
+ current-state questions to the source.
36
54
  - The instruction envelope now has recovery explanations before all compacted
37
55
  spans, one evidence-boundary warning after them, and numbered
38
56
  recovery reminders plus brief recovery recap after the retained tail.
package/README.md CHANGED
@@ -65,6 +65,13 @@ After another compaction, only the current checklist is presented: older generat
65
65
  checklists are excluded from compacted spans and the retained tail. This is
66
66
  instruction delivery, not a guarantee of model compliance.
67
67
 
68
+ Compaction hides earlier details from the model's view; recorded history remains
69
+ retrievable. Recovery guidance explicitly names uncertain provenance (where a
70
+ finding came from or why a conclusion was reached) and contradictions between
71
+ earlier notes and new evidence. Prefer lookup for historical observations or to
72
+ avoid repeating costly research; inspect project files for current contents.
73
+ Cheap local rereads and recomputations remain reasonable.
74
+
68
75
  ### Automatic startup-read retention
69
76
 
70
77
  Successful text reads between the first and second user prompts are retained when
package/docs/DESIGN.md CHANGED
@@ -20,8 +20,20 @@ extension builds a checkpoint without changing that boundary or calling a model:
20
20
 
21
21
  Checkpoints label tool outcomes as `ok`, `error`, or `unknown` and remind the
22
22
  agent to recover missing evidence when needed. These labels describe tool
23
- results, not a guarantee that tests passed. There is no required-document reread
24
- checklist: retained reads remain available as evidence.
23
+ results, not a guarantee that tests passed. Output removal is explained once in
24
+ the checkpoint header rather than repeated beside every outcome. There is no
25
+ required-document reread checklist: retained reads remain available as evidence.
26
+
27
+ File-tool signatures keep complete identifying paths, made relative to the session
28
+ working directory where possible. Shell commands abbreviate that directory to
29
+ `.` at path boundaries, without changing raw arguments. This is display notation,
30
+ not a replayable command. Read/modified file lists use the same relative paths.
31
+ Write bodies become `content=<N chars>`; edit arrays become `edits=K` (individual
32
+ `oldText`/`newText` arguments become character counts). Other argument previews,
33
+ including bash commands, retain a 160-character JSON-encoded prefix with a single
34
+ ellipsis when abbreviated. Multi-line command prefixes are not reduced to their
35
+ first line. These changes affect only checkpoint signatures, never conversation
36
+ prose, retained read outputs, or raw session evidence.
25
37
 
26
38
  All newly compacted custom messages follow the same stub policy, regardless of
27
39
  extension, display setting, or content format. Long type names are abbreviated
@@ -73,7 +85,10 @@ original branch, not from its summary prose.
73
85
  Retained startup reads count as fixed budget overhead and are never trimmed.
74
86
  Like an inherited base, they can exceed the budget by themselves; in that case
75
87
  the extension warns and preserves them. The conversation-line budget still has
76
- a 500-character minimum. Originals remain recoverable from the session.
88
+ a 500-character minimum. Every span changed by the cap carries `trimmed="true"`
89
+ and a recovery note, including partial line removal and shortened user messages.
90
+ An originally empty span is not marked as trimmed. Originals remain recoverable
91
+ from the session.
77
92
 
78
93
 
79
94
  ### Session-backed lookup
@@ -114,12 +129,27 @@ by provider.
114
129
 
115
130
  ### Recover historical details
116
131
 
117
- Recovery is for a specific detail previously present on this conversation's active
118
- branch and now missing because of compaction. The visible conversation or checkpoint
119
- must establish relevant earlier history; the agent should not call recovery tools
120
- to discover whether that history exists. Session startup, project discovery, missing
121
- requirements, and information never supplied are not recovery triggers: inspect
122
- project files or ask the user instead.
132
+ Compaction hides earlier details from the model's current view; the recorded history,
133
+ including tool outputs and reasoning, remains in the session. Recovery can retrieve
134
+ specific outputs, trace where an earlier finding came from or why a conclusion was
135
+ reached, and check historical evidence when earlier notes conflict with new evidence.
136
+ These triggers are advertised in the tool description and conditionally explained
137
+ in post-compaction reminders, not just in the skill body. Reminders lead with
138
+ restoring task-relevant inputs, current-file reads, and cheap recomputation;
139
+ compaction alone is not a lookup trigger. Advertising and re-orientation use
140
+ separate wording. The skill description also names provenance and contradictions.
141
+ This is guidance, not a guarantee of model compliance.
142
+
143
+ Re-read project files for their current contents. Prefer lookup for what was
144
+ observed earlier or to avoid repeating slow external research or expensive
145
+ computations; cheap local rereads (including downloaded sources) and recomputations
146
+ remain reasonable. Current external facts may require fresh research. Retrieval
147
+ establishes what was recorded, not whether an earlier conclusion was correct.
148
+
149
+ Use recovery for history established by this conversation or its checkpoint, not
150
+ project discovery, requirements never supplied, other sessions, or abandoned branches.
151
+ For unfamiliar project details or missing requirements, inspect project files or
152
+ ask the user instead.
123
153
 
124
154
  For this recovery workflow, use the recovery tools rather than reading raw session
125
155
  files through filesystem tools. This restriction does not apply to user-requested
@@ -176,7 +206,12 @@ The recovery reminders identify retained startup reads and the uncompacted tail
176
206
  as available evidence. They ask for recovery only when task-relevant inputs are
177
207
  missing, not for rediscovery of reading requirements or blanket document rereads.
178
208
  They also distinguish restoring inputs from repeating completed writes, call for
179
- inspecting Git state, and require verification before relying on removed evidence.
209
+ inspecting Git state, and ask the agent to resolve task-relevant uncertainty or
210
+ contradictions using supporting output or current-state verification before treating
211
+ a claim as established. Retained prose can guide continuation without re-verifying
212
+ every fact; unresolved claims should be labelled unverified, and retrieved reasoning
213
+ remains a historical hypothesis. Historical outputs do not establish current file
214
+ or build/test state.
180
215
  There is no blanket edit-target reread. It is a saved
181
216
  custom message tagged with the current compaction entry ID, not a temporary nudge:
182
217
  subsequent responses and user turns retain it in history before the work that
@@ -419,22 +419,49 @@ function branchToTranscript(entries: SessionEntry[]): { lines: string[]; index:
419
419
  // Mechanical summary (what replaces the model summary in the session)
420
420
  // ============================================================================
421
421
 
422
- function toolCallSignature(name: string, args: Record<string, unknown> | undefined): string {
422
+ // Display-only shortening: never change raw arguments or resolve symlinks.
423
+ function checkpointPath(value: string, cwd: string): string {
424
+ const prefix = cwd.endsWith(path.sep) ? cwd : cwd + path.sep;
425
+ if (value === cwd) return ".";
426
+ return value.startsWith(prefix) ? value.slice(prefix.length) : value;
427
+ }
428
+
429
+ function checkpointCommand(command: string, cwd: string): string {
430
+ const escaped = cwd.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
431
+ // Match complete path prefixes, not sibling directories or URL fragments.
432
+ return command.replace(new RegExp(`(^|[\\s"'=<>|;&(])${escaped}(?=$|[/\\s"'<>|;&)])`, "g"), "$1.");
433
+ }
434
+
435
+ function argumentSnippet(value: unknown): string {
436
+ let s: string;
437
+ try {
438
+ s = JSON.stringify(value) ?? String(value);
439
+ } catch {
440
+ s = String(value);
441
+ }
442
+ return s.length > cfg.argSnippetChars ? `${s.slice(0, cfg.argSnippetChars)}…` : s;
443
+ }
444
+
445
+ function toolCallSignature(name: string, args: Record<string, unknown> | undefined, cwd: string): string {
423
446
  const parts: string[] = [];
424
447
  for (const [k, v] of Object.entries(args ?? {})) {
425
448
  let s: string;
426
- try {
427
- s = JSON.stringify(v) ?? String(v);
428
- } catch {
429
- s = String(v);
430
- }
431
- if (s.length > cfg.argSnippetChars) s = `${s.slice(0, cfg.argSnippetChars)}…[+${s.length - cfg.argSnippetChars} chars]`;
449
+ if (["read", "write", "edit"].includes(name) && k === "path" && typeof v === "string")
450
+ s = JSON.stringify(checkpointPath(v, cwd)); // Keep the whole identifying path.
451
+ else if (name === "write" && k === "content" && typeof v === "string")
452
+ s = `<${v.length} chars>`;
453
+ else if (name === "edit" && k === "edits" && Array.isArray(v))
454
+ s = String(v.length);
455
+ else if (name === "edit" && (k === "oldText" || k === "newText") && typeof v === "string")
456
+ s = `<${v.length} chars>`;
457
+ else
458
+ s = argumentSnippet(name === "bash" && k === "command" && typeof v === "string" ? checkpointCommand(v, cwd) : v);
432
459
  parts.push(`${k}=${s}`);
433
460
  }
434
461
  return `${name}(${parts.join(", ")})`;
435
462
  }
436
463
 
437
- function summarizeMessages(messages: AgentMessage[]): string[] {
464
+ function summarizeMessages(messages: AgentMessage[], cwd: string): string[] {
438
465
  // Pair calls with later results in Pi's selected messages only. Never infer
439
466
  // outcomes from result text, assistant claims, or another branch/the kept tail.
440
467
  const outcomes = new Map<object, "ok" | "error">();
@@ -470,7 +497,7 @@ function summarizeMessages(messages: AgentMessage[]): string[] {
470
497
  for (const block of m.content ?? []) {
471
498
  if (block.type === "text") prose += (prose ? "\n" : "") + String(block.text ?? "");
472
499
  else if (block.type === "toolCall")
473
- calls.push(`${toolCallSignature(String(block.name), block.arguments)} [${outcomes.get(block) ?? "unknown"}; output removed]`);
500
+ calls.push(`${toolCallSignature(String(block.name), block.arguments, cwd)} [${outcomes.get(block) ?? "unknown"}]`);
474
501
  // thinking blocks: removed by design (kept in the session)
475
502
  }
476
503
  if (prose.trim()) lines.push(`[Assistant]: ${prose.trim()}`);
@@ -481,13 +508,13 @@ function summarizeMessages(messages: AgentMessage[]): string[] {
481
508
  // removed by design (kept in the session)
482
509
  break;
483
510
  case "bashExecution":
484
- lines.push(`[BashExecution]: $ ${String(m.command ?? "")} (output removed — use context_lookup)`);
511
+ lines.push(`[BashExecution]: ${toolCallSignature("bash", { command: String(m.command ?? "") }, cwd)} [output removed]`);
485
512
  break;
486
513
  case "custom":
487
514
  // Our instruction envelope is regenerated, not conversation prose.
488
515
  // Keep originals in raw history, but never carry old checklists into spans.
489
516
  if (m.customType !== REORIENT_MESSAGE)
490
- lines.push(`[Custom message]: ${toolCallSignature("custom", { type: m.customType })} [content removed — use context_lookup]`);
517
+ lines.push(`[Custom message]: ${toolCallSignature("custom", { type: m.customType }, cwd)} [content removed — use context_lookup]`);
491
518
  break;
492
519
  case "branchSummary":
493
520
  case "compactionSummary":
@@ -611,7 +638,7 @@ function renderStartupReads(state: StartupReads, entries: SessionEntry[], firstK
611
638
  const retained = state.reads.filter((r) => !tail.has(r.entryId));
612
639
  if (retained.length === 0) return "";
613
640
  return ["### Retained startup reads",
614
- "Original read outputs, preserved verbatim. Offsets and truncation notices are part of the original reads. These are not new filesystem reads. Tool stubs marked 'output removed' refer to the conversation spans, not these retained copies.",
641
+ "Original read outputs, preserved verbatim. Offsets and truncation notices are part of the original reads. These are not new filesystem reads. Tool-call status labels refer to the conversation spans, where outputs are removed, not these retained copies.",
615
642
  ...retained.map((r) => `<retained-read entry=${JSON.stringify(r.entryId)} path=${JSON.stringify(r.path)} offset=${r.offset ?? 1}${r.limit === undefined ? "" : ` limit=${r.limit}`}>
616
643
  ${r.text.join("\n")}
617
644
  </retained-read>`),
@@ -721,21 +748,25 @@ function capSpans(spans: string[][], budget: number): string[][] {
721
748
  return spans.map((_, span) => items.filter((it) => it.span === span).map((it) => it.line));
722
749
  }
723
750
 
724
- const REORIENT_BLOCK = `**Post-compaction re-orientation.** Retained startup reads and the uncompacted tail remain available as evidence. Recover only missing information needed for the current task.
725
- 1. Re-acquire information needed for the current task that is no longer in context. This means restoring inputs, not repeating completed work: do not redo writes, edits, or other state-changing actions merely because their results were dropped. If needed, recover those results with \`context_lookup\`, or verify current state.
726
- 2. If this is a Git repository, run \`git status\` and review uncommitted work. Re-verify build/test state if you are about to rely on it.
727
- 3. **Treat knowledge from removed evidence as unverified.** Thinking and tool outputs were removed from the compacted spans, except for the separately retained startup reads. The uncompacted tail is unchanged. Anything you know only from removed material — or from earlier assistant prose describing it — is a note, not evidence. Before you state it as fact or base a decision on it, re-read the source or ask \`context_lookup\`. If you cannot verify it, say explicitly that it is unverified.`;
751
+ const RECOVERY_HISTORY_NOTE = "Compaction hides earlier details from your current view. The original conversation history, including recorded tool outputs and your reasoning, is preserved in the session and can be retrieved.";
752
+ const RECOVERY_TRIGGERS = "Ask `context_lookup` where an earlier finding came from, what a command actually printed, or why you reached a conclusion, especially when earlier notes conflict with new evidence.";
753
+ const RECOVERY_SOURCE_GUIDANCE = "Re-read project files for their current contents. Prefer lookup for what was observed earlier or to avoid repeating slow external research or expensive computations; cheap local rereads and recomputations remain reasonable.";
754
+ const RECOVERY_SCOPE_RULE = "Use the recovery tools for history established by this conversation or its checkpoint, not project discovery, requirements never supplied, other sessions, or abandoned branches.";
755
+ const RECOVERY_FILESYSTEM_RULE = "For recovery of details hidden by compaction, do not read or grep raw session JSONL files through filesystem tools; use the recovery tools instead.";
728
756
 
729
- const CHECKPOINT_EXPLANATION = "**Compacted conversation follows.** The earlier part of this conversation has been compacted into the checkpoint below. This is not the full transcript: assistant thinking and tool outputs have been removed from the compacted spans, but are preserved in the session and can be recovered.";
757
+ const REORIENT_BLOCK = `**Post-compaction re-orientation.** ${RECOVERY_HISTORY_NOTE} Retained startup reads and the uncompacted tail remain available as evidence. Recover only hidden information needed for the current task.
758
+ 1. **Restore only information needed to continue.** Re-read project files when you need their current contents; cheap local rereads and recomputations are reasonable. If you need an earlier observation, the source of a finding, or the reason for a conclusion that compaction hid, use \`context_lookup\`. This can avoid repeating slow or unreliable research. Restore inputs, not completed actions: do not redo writes, edits, or other state-changing actions merely because their results are hidden.
759
+ 2. If this is a Git repository, run \`git status\` and review uncommitted work. Re-verify build/test state if you are about to rely on it.
760
+ 3. **Distinguish earlier claims from supporting evidence.** Retained assistant prose records what was said, not independent verification. If a task-relevant claim has uncertain provenance or conflicts with new evidence, check its supporting output (using \`context_lookup\` if hidden) or the current source before treating it as established; label unresolved claims unverified. Retrieved reasoning remains a historical hypothesis, and historical outputs do not establish current file or build/test state.`;
730
761
 
731
- const RECOVERY_FILESYSTEM_RULE = "For recovery of details lost from the context in this session due to compaction, do not read or grep raw session JSONL files through filesystem tools; use the recovery tools instead.";
762
+ const CHECKPOINT_EXPLANATION = `**Compacted conversation follows.** The earlier part of this conversation has been compacted into the checkpoint below. This is not the full transcript. ${RECOVERY_HISTORY_NOTE}`;
732
763
 
733
- const RECOVERY_INSTRUCTIONS = `**Recovering dropped details.** Information removed from your active context is preserved in this conversation's history, including earlier thinking and tool outputs. Recover only specific details previously present on this conversation's active branch and now missing because of compaction, not information never supplied. Prefer \`context_lookup\` for this recovery with a specific question: a subagent searches the transcript in its own context and returns relevant findings. If its findings are incomplete, use the bounded fallback tools \`context_list_entries\`, \`context_grep\`, and \`context_show_entry\`; follow their pagination instructions for more detail. ${RECOVERY_FILESYSTEM_RULE}`;
764
+ const RECOVERY_INSTRUCTIONS = `**Recovering hidden details.** Prefer \`context_lookup\` with a specific historical question: a subagent searches this conversation's full raw active branch in its own context and returns relevant findings. ${RECOVERY_SCOPE_RULE} If its findings are incomplete, use the bounded fallback tools \`context_list_entries\`, \`context_grep\`, and \`context_show_entry\`; follow their pagination instructions for more detail. ${RECOVERY_FILESYSTEM_RULE}`;
734
765
 
735
- const EVIDENCE_BOUNDARY_RULE = "**Evidence boundary:** Tool signatures and file lists do not contain command output, file contents, or rules from read documents; if a claim depends on that removed evidence, use `context_lookup` or re-read the source before relying on it.";
766
+ const EVIDENCE_BOUNDARY_RULE = "**Evidence boundary:** Tool signatures and file lists do not contain command output, file contents, or rules from read documents; use `context_lookup` when you need that historical evidence or its provenance, and inspect the source when you need current state.";
736
767
 
737
768
  const REORIENT_MESSAGE = "transparent-compact:reorient";
738
- const RECOVERY_RECAP = `**Recovery recap.** When needed evidence from earlier in this conversation is missing because of compaction, re-read its source or ask \`context_lookup\` a specific question about that removed history. Missing requirements or unfamiliar project details are not evidence of forgotten history: inspect project files or ask the user instead. If its findings are incomplete, use \`context_list_entries\`, \`context_grep\`, or \`context_show_entry\`, following pagination instructions. ${RECOVERY_FILESYSTEM_RULE} Keep these evidence/recovery rules in force as work continues.`;
769
+ const RECOVERY_RECAP = `**Recovery recap.** ${RECOVERY_SCOPE_RULE} For unfamiliar project details or missing requirements, inspect project files or ask the user instead. If lookup findings are incomplete, use \`context_list_entries\`, \`context_grep\`, or \`context_show_entry\`, following pagination instructions. ${RECOVERY_FILESYSTEM_RULE} Keep these evidence/recovery rules in force as work continues.`;
739
770
 
740
771
  function latestVerbatimCompaction(entries: SessionEntry[]) {
741
772
  for (let i = entries.length - 1; i >= 0; i--) {
@@ -835,10 +866,14 @@ async function buildMechanicalSummary(opts: {
835
866
  if (base) blocks.push(`${baseOpen}\n${base.summary.replace(/\n+$/, "")}\n${BASE_CLOSE}`);
836
867
  capped.forEach((lines, i) => {
837
868
  const s = allSpans[i];
869
+ const trimmed = lines.length !== s.lines.length || lines.some((line, j) => line !== s.lines[j]);
838
870
  const open = spanOpen(i + 1, s.at, s.reason, coversOf(s));
839
- blocks.push(
840
- lines.length > 0 ? `${open}\n${lines.join("\n")}\n${SPAN_CLOSE}` : `${open.slice(0, -1)}${SPAN_TRIMMED_ATTR}>\n${SPAN_TRIMMED_NOTE}\n${SPAN_CLOSE}`,
841
- );
871
+ blocks.push([
872
+ trimmed ? `${open.slice(0, -1)}${SPAN_TRIMMED_ATTR}>` : open,
873
+ ...(trimmed ? [SPAN_TRIMMED_NOTE] : []),
874
+ ...lines,
875
+ SPAN_CLOSE,
876
+ ].join("\n"));
842
877
  });
843
878
 
844
879
  const compactionCount = opts.branchEntries.filter((e) => e.type === "compaction").length + 1;
@@ -850,7 +885,7 @@ async function buildMechanicalSummary(opts: {
850
885
  opts.notify(MIXED_CONTEXT_WARNING);
851
886
  }
852
887
  parts.push(`- Latest: ${opts.now} (trigger: ${opts.reason}, ~${opts.tokensBefore.toLocaleString()} tokens before compaction)`);
853
- parts.push("- In the compacted spans, user and assistant prose is kept verbatim, subject to budget trimming; tool calls are kept as one-line signatures (arguments truncated). Assistant thinking and tool outputs are removed. Retained prose is a record of what was said, not verification of its claims.");
888
+ parts.push("- In the compacted spans, user and assistant prose is kept verbatim, subject to budget trimming; tool calls are kept as one-line signatures. Paths under the session working directory are shown relative to it (as `.` in shell commands). Write contents and edit payloads are replaced by sizes/counts; other argument snippets keep up to 160 characters followed by an ellipsis when abbreviated. Assistant thinking and tool outputs are removed. Retained prose is a record of what was said, not verification of its claims.");
854
889
  parts.push("- Tool status: ok = result not flagged as an error; error = result flagged as an error; unknown = no safely matched result/status. Output content is removed in all cases. ok does not prove a command or tests passed. Calls without a status in older spans have unknown outcomes.");
855
890
  parts.push("- Newly compacted custom messages are kept only as type stubs (long types abbreviated); their content is removed and remains recoverable in the session through context_lookup. Previously saved spans are unchanged.");
856
891
  parts.push(
@@ -871,9 +906,9 @@ async function buildMechanicalSummary(opts: {
871
906
  const hasFileLists = opts.readFiles.length > 0 || opts.modifiedFiles.length > 0;
872
907
  if (hasFileLists) parts.push("");
873
908
  if (opts.readFiles.length > 0)
874
- parts.push(`<read-files note="read before compaction; unless marked retained, content removed — re-read or use context_lookup">\n${opts.readFiles.map((file) => `${file} (${retainedPaths.has(path.resolve(opts.cwd, file)) ? "startup read output retained in checkpoint or tail; may be partial" : "content removed"})`).join("\n")}\n</read-files>`);
909
+ parts.push(`<read-files note="read before compaction; unless marked retained, content removed — re-read or use context_lookup">\n${opts.readFiles.map((file) => `${checkpointPath(file, opts.cwd)} (${retainedPaths.has(path.resolve(opts.cwd, file)) ? "startup read output retained in checkpoint or tail; may be partial" : "content removed"})`).join("\n")}\n</read-files>`);
875
910
  if (opts.modifiedFiles.length > 0)
876
- parts.push(`<modified-files note="modified before compaction; current contents NOT in context">\n${opts.modifiedFiles.join("\n")}\n</modified-files>`);
911
+ parts.push(`<modified-files note="modified before compaction; current contents NOT in context">\n${opts.modifiedFiles.map((file) => checkpointPath(file, opts.cwd)).join("\n")}\n</modified-files>`);
877
912
  parts.push("");
878
913
  parts.push(EVIDENCE_BOUNDARY_RULE);
879
914
  parts.push("");
@@ -1347,7 +1382,7 @@ function consecutiveLookups(ctx: { sessionManager: { getBranch: () => SessionEnt
1347
1382
  }
1348
1383
 
1349
1384
  function registerDirectTools(pi: ExtensionAPI): void {
1350
- const pre = "Fallback after context_lookup, when its findings are incomplete: recover specific earlier details lost to compaction on this conversation's active branch, not project discovery or information never supplied. Cannot search other sessions or abandoned branches. ";
1385
+ const pre = "Fallback after context_lookup, when its findings are incomplete; same scope as context_lookup. ";
1351
1386
  const run = (ctx: { sessionManager: { getBranch: () => SessionEntry[] } }, f: (t: Transcript[]) => string) => {
1352
1387
  try {
1353
1388
  const transcript = sessionTranscript(ctx);
@@ -1371,7 +1406,7 @@ function registerDirectTools(pi: ExtensionAPI): void {
1371
1406
  name: "context_grep",
1372
1407
  label: "Context: grep",
1373
1408
  description: pre + "Regex-search the full raw session branch, including compacted thinking and tool outputs, with surrounding lines and authoritative entry attribution. pattern is a JS regex (case-insensitive). Up to 12000 payload characters per page, plus cursor notes. Follow all reported continuation parameters (offset, charOffset, throughEntry) for remaining matches or oversized lines. Historical thinking is not verified fact.",
1374
- promptSnippet: "Fallback: search this conversation's evidence lost through compaction",
1409
+ promptSnippet: "Fallback: search this conversation's evidence hidden by compaction",
1375
1410
  parameters: Type.Object(GREP_FIELDS),
1376
1411
  async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
1377
1412
  return run(ctx, (t) => grepTranscript(t, params));
@@ -1553,7 +1588,7 @@ export default function (pi: ExtensionAPI) {
1553
1588
  const msgTs = (m: AgentMessage): unknown => (m as unknown as { timestamp?: unknown }).timestamp;
1554
1589
  const spanFrom = toIso(msgTs(allMessages[0]));
1555
1590
  const spanTo = toIso(msgTs(allMessages[allMessages.length - 1]));
1556
- const spanLines = summarizeMessages(allMessages);
1591
+ const spanLines = summarizeMessages(allMessages, ctx.cwd);
1557
1592
 
1558
1593
  // 3) Freeze startup references after the second user prompt, then carry
1559
1594
  // their original outputs forward outside the trimmable conversation spans.
@@ -1612,11 +1647,10 @@ export default function (pi: ExtensionAPI) {
1612
1647
  label: "Context lookup",
1613
1648
  executionMode: "sequential",
1614
1649
  description:
1615
- "Recover a specific detail previously present earlier on this conversation's active branch but now missing because of compaction, including thinking, tool outputs, error text, file contents, or earlier decisions. Use only when the visible conversation or compaction checkpoint establishes relevant earlier history; do not call this tool to discover whether such history exists. Not for session startup, new-project orientation, missing requirements, or information never supplied: inspect project files or ask the user instead. Spawns a subagent that searches this conversation's full raw active branch (across all compactions) in its OWN context and returns relevant findings. Does not search abandoned branches or other sessions. For this recovery workflow, prefer this tool first; if findings are incomplete, use the bounded context_list_entries, context_grep, and context_show_entry fallback tools. Follow their pagination instructions. " +
1616
- RECOVERY_FILESYSTEM_RULE + "",
1617
- promptSnippet: "Recover specific earlier conversation details lost through compaction",
1650
+ `Retrieve earlier outputs, findings, decisions, and reasoning hidden by compaction. ${RECOVERY_TRIGGERS} A subagent searches this conversation's full raw active branch in its own context and returns relevant findings. ${RECOVERY_SOURCE_GUIDANCE} ${RECOVERY_SCOPE_RULE} If findings are incomplete, use context_list_entries, context_grep, or context_show_entry, following pagination instructions. ${RECOVERY_FILESYSTEM_RULE}`,
1651
+ promptSnippet: "Retrieve earlier outputs, findings, decisions, and reasoning hidden by compaction, including the provenance of earlier conclusions",
1618
1652
  parameters: Type.Object({
1619
- question: Type.String({ description: "The specific detail from earlier in this conversation that compaction removed (exact error text, previously read file, decision, command output…)." }),
1653
+ question: Type.String({ description: "A specific question about earlier in this conversation: an output, source of a finding, reason for a decision, or evidence behind notes that conflict with new observations." }),
1620
1654
  }),
1621
1655
  async execute(toolCallId, params, signal, _onUpdate, ctx) {
1622
1656
  if (cfg.lookupMaxCalls > 0 && consecutiveLookups(ctx, toolCallId) >= cfg.lookupMaxCalls) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foliox/transparent-compact-pi",
3
- "version": "0.8.6",
3
+ "version": "0.8.7",
4
4
  "description": "Deterministic, verbatim-preserving compaction for Pi, with session-backed subagent context recovery.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -1,22 +1,21 @@
1
1
  ---
2
2
  name: context-retrieval
3
- description: Use context_lookup when compaction has removed a specific detail from earlier in this same conversation and that detail is needed again. Not for session startup, project discovery, missing requirements, or auditing session files.
3
+ description: Use context_lookup to recover earlier conversation details hidden by compaction, trace where an earlier finding came from, or investigate contradictions between earlier notes and new evidence.
4
4
  ---
5
5
 
6
6
  # Session context recovery
7
7
 
8
8
  ## Applicability
9
9
 
10
- Use this skill only to recover a specific detail previously present on this
11
- conversation's active branch and now missing because of compaction. The visible
12
- conversation or compaction checkpoint must establish relevant earlier history;
13
- do not call recovery tools to discover whether such history exists. Missing
14
- requirements or an unfamiliar project do not imply forgotten context: inspect
15
- project files or ask the user instead.
10
+ Compaction hides earlier details from your current view. The original conversation
11
+ history, including recorded tool outputs and your reasoning, is preserved in the
12
+ session and can be retrieved. Retained startup reads and the uncompacted tail
13
+ remain available as evidence; recover only hidden information needed for the task.
16
14
 
17
- Retained startup reads and the uncompacted tail remain available as evidence.
18
- Do not recover information that is still visible, or information never supplied.
19
- These tools cannot search other sessions or abandoned branches.
15
+ Use the recovery tools for history established by this conversation or its checkpoint,
16
+ not project discovery, requirements never supplied, other sessions, or abandoned branches.
17
+ For unfamiliar project details or missing requirements, inspect project files or
18
+ ask the user instead.
20
19
 
21
20
  User-requested session audits, debugging, and cross-session analysis are separate
22
21
  tasks, not this recovery workflow. Its filesystem restrictions do not apply to
@@ -26,7 +25,7 @@ This skill pairs with the `@foliox/transparent-compact-pi` extension, which prov
26
25
 
27
26
  - **Verbatim compaction** — a deterministic checkpoint retains user messages, assistant prose, and compact tool-call signatures. Thinking and most tool outputs are removed from the active model context, not from the raw session history. Selected startup read outputs remain verbatim in the checkpoint or uncompacted tail. Earlier spans are re-rendered flat, with recovery guidance before them and an evidence-boundary warning after them. Persistent task-relevant recovery reminders and a recap follow the retained tail; later compactions replace the old generated reminders rather than duplicating them. An inherited opaque base is kept when needed.
28
27
  - **`context_lookup`** — the preferred first step for this recovery workflow: a subagent searches the full raw session branch in its **own** context and returns relevant findings. At lookup time, the extension mechanically renders the branch into entry-anchored text with an authoritative entry/section index, in memory.
29
- - **Bounded fallback tools** — if those findings are incomplete, use `context_list_entries`, `context_grep`, and `context_show_entry` for direct evidence recovery. Their results enter this conversation. For recovery of details lost to compaction, these are the permitted fallback, not filesystem access to session files.
28
+ - **Bounded fallback tools** — if those findings are incomplete, use `context_list_entries`, `context_grep`, and `context_show_entry` for direct evidence recovery. Their results enter this conversation. For recovery of details hidden by compaction, these are the permitted fallback, not filesystem access to session files.
30
29
 
31
30
  Pi normally saves sessions under `~/.pi/agent/sessions/`; custom session locations also work. In-memory sessions retain history only while the process lives and cannot be resumed after exit.
32
31
 
@@ -34,8 +33,21 @@ If `context_lookup` is not in your tool list, say that subagent recovery is unav
34
33
 
35
34
  ## When to use
36
35
 
37
- - After a compaction, you need an exact error message, a full tool output, previously read file content, full tool-call arguments, an earlier instruction or decision, or reasoning that was dropped → call `context_lookup` with a **specific** question.
38
- - A compaction checkpoint contains a claim whose supporting tool output was removed → re-read the current source or ask `context_lookup` for that historical evidence before relying on the claim. If you cannot verify it, explicitly label it unverified.
36
+ - You need an earlier output, exact error, previously read content, full tool-call arguments, instruction, decision, or reasoning hidden by compaction.
37
+ - You are unsure where an earlier finding came from, what a command actually printed, or why you reached a conclusion.
38
+ - Earlier notes conflict with new evidence and you need to check the historical evidence behind them.
39
+
40
+ Ask `context_lookup` a **specific historical question** to recover hidden supporting
41
+ evidence. This can avoid repeating slow or unreliable research. For example:
42
+ "Where did our earlier Holi 2026 date come from: a
43
+ published source or our own computation? Include the observed output and ENTRY id."
44
+
45
+ ### Lookup or inspect the source?
46
+
47
+ - Re-read project files when you need their current contents.
48
+ - Prefer lookup when you need what was observed earlier, or when recovering earlier external research or expensive computations would avoid repeating slow or unreliable work.
49
+ - Cheap local rereads (including downloaded sources) and recomputations remain reasonable; needing a current external fact may require fresh research.
50
+ - Retained prose can guide continuation without re-verifying every fact. When uncertainty or a contradiction matters to the current task, check the supporting output or verify current state; label unresolved claims unverified. Retrieval establishes what was recorded, not whether an earlier conclusion was correct.
39
51
 
40
52
  ## How to ask
41
53
 
@@ -79,7 +91,7 @@ intended context parameters.
79
91
 
80
92
  ## Rules
81
93
 
82
- 1. **For recovery of details lost to compaction, do not read or grep raw session JSONL files through filesystem tools.** Prefer `context_lookup`; when its findings are incomplete, use the bounded fallback tools above. Raw filesystem recovery would refill the compacted context. This restriction does not apply to user-requested session audits, debugging, or cross-session analysis.
94
+ 1. **For recovery of details hidden by compaction, do not read or grep raw session JSONL files through filesystem tools.** Prefer `context_lookup`; when its findings are incomplete, use the bounded fallback tools above. Raw filesystem recovery would refill the compacted context. This restriction does not apply to user-requested session audits, debugging, or cross-session analysis.
83
95
  2. Ask narrowly scoped questions using exact error strings, file paths, function names, or the command whose output you need. Recover tightly related details together; use separate queries for independent facts. Ask the subagent for evidence, not for a solution to the broader task.
84
96
  3. Findings cite ENTRY ids and the logical transcript name. Retain these citations when relying on recovered facts. The renderer preserves full thinking, text, tool-call arguments, and tool results, although individual search results have output limits.
85
97
  4. Distinguish **user instructions**, **observed tool output**, and **reasoning at the time**. A recovered `[thinking]` block is a historical hypothesis, not verified fact. Earlier assistant prose is not independently observed evidence either.