@foliox/transparent-compact-pi 0.13.2 → 0.13.3
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/README.md +4 -4
- package/extensions/index.ts +4 -5
- package/extensions/lib/turn-context.ts +30 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Context compaction and pruning for [Pi](https://pi.dev/) that keeps conversation text verbatim instead of replacing it with a model-generated summary or truncation. It removes thinking and most tool output from the active context, while keeping user messages, assistant text, algorithmically compacted tool-call stubs and explicitly selected reads.
|
|
4
4
|
|
|
5
|
-
When the agent needs a detail that is no longer in context, it can use retrieval tools to search the recorded session history with a subagent. Compaction itself does not make a model call.
|
|
5
|
+
When the agent needs a detail that is no longer in context, it can use retrieval tools to search the recorded session history with a subagent (no extra extension required). Compaction itself does not make a model call.
|
|
6
6
|
|
|
7
7
|
The user can also [selectively manipulate which turns to hold in the current context](#filter-turns) in higher or lower fidelity, and [specify file reads to be retained in the context in full](#retain-reads), (e.g. a spec or plan).
|
|
8
8
|
|
|
9
9
|
This extension is aimed at addressing two main issues that other compaction techniques face, which are especially exacerbated in agents running on lightweight and local LLMs:
|
|
10
10
|
- Model summaries such as Pi's default method can lead to degradation and confabulation of details that can cause confident blunders.
|
|
11
|
-
-
|
|
11
|
+
- Mechanical compression (i.e. no model call) + retrieval systems like `pi-vcc` can be effective when the agent knows what to look for, but omitting session structure from the retained context can make the actual use of retrieval less reliable.
|
|
12
12
|
|
|
13
|
-
`transparent-compact` is also a retrieval
|
|
13
|
+
`transparent-compact` is also a mechanical compression + retrieval system, but its design keeps manipulation of conversation text to a minimum and maximises the agent's awareness of its own compacted state, with the aim of avoiding confabulation and encouraging accurate retrieval of historical details. [This study](https://arxiv.org/abs/2610.20116) found that a minimal approach outperformed more complex techniques with lightweight models and was at least as effective with frontier models.
|
|
14
14
|
|
|
15
15
|
The verbatim compaction system plays particularly nicely with manual pruning of the context. This allows you to decide which parts of the session remain important to the current work, without having to commit to a particular branching point with /tree or decide at the time of the prompt with something like claude's /btw.
|
|
16
16
|
|
|
@@ -29,7 +29,7 @@ pi install git:github.com/felixwoolford/transparent-compact-pi
|
|
|
29
29
|
pi install /absolute/path/to/transparent-compact
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
Once loaded, the extension uses verbatim compaction by default. Pi's automatic compaction continues to work, using the extension's configured method; to compact manually, enter:
|
|
32
|
+
Once loaded, the extension uses verbatim mechanical compaction by default. Pi's automatic compaction triggering continues to work, using the extension's configured method; to compact manually, enter:
|
|
33
33
|
|
|
34
34
|
```text
|
|
35
35
|
/compact
|
package/extensions/index.ts
CHANGED
|
@@ -50,7 +50,7 @@ import type { FilterTurn, TurnSpan, ReadPosition } from "./lib/turn-filter.js";
|
|
|
50
50
|
import { readPath as fileEvidenceKey, readCatalog, readRetentionState, selectedReads, renderRetainedReads, retainedReadOutputs, retainReadSpans, READ_RETENTION_ENTRY } from "./lib/read-retention.js";
|
|
51
51
|
import type { ReadOutput, ReadRetention } from "./lib/read-retention.js";
|
|
52
52
|
import { pickRetainedReads } from "./lib/read-retention-ui.js";
|
|
53
|
-
import { FIDELITY_EXPLANATION, fidelityMessages, fidelitySpans, locateSlots, expandCheckpoint,
|
|
53
|
+
import { CHECKPOINT_EXPLANATION, RECOVERY_HISTORY_NOTE, FIDELITY_EXPLANATION, fidelityMessages, fidelitySpans, locateSlots, expandCheckpoint, frameCheckpoint,
|
|
54
54
|
messageTokens, previewMessages, checkCheckpointBudget, checkContextBudget, isExpandedCheckpoint, checkpointContextMessages, retainedTailMessages, estimateContext } from "./lib/turn-context.js";
|
|
55
55
|
import type { ContextEstimate, NoticeTokens, TurnFidelities, TurnSelection, TurnSlot } from "./lib/turn-context.js";
|
|
56
56
|
|
|
@@ -779,7 +779,6 @@ function checkpointEvidence(entries: SessionEntry[], firstKeptEntryId: string, c
|
|
|
779
779
|
};
|
|
780
780
|
}
|
|
781
781
|
|
|
782
|
-
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.";
|
|
783
782
|
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.";
|
|
784
783
|
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.";
|
|
785
784
|
|
|
@@ -789,7 +788,6 @@ const REORIENT_BLOCK = `**Post-compaction re-orientation.** ${RECOVERY_HISTORY_N
|
|
|
789
788
|
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.`;
|
|
790
789
|
|
|
791
790
|
const REVISION_NOTE_PREFIX = "- Checkpoint context revised: ";
|
|
792
|
-
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}`;
|
|
793
791
|
|
|
794
792
|
const RECOVERY_INSTRUCTIONS = `**Recovering hidden details.** Use \`context_lookup\` with a specific historical question: a subagent searches this conversation's full session history and returns relevant findings.`;
|
|
795
793
|
|
|
@@ -1570,7 +1568,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
1570
1568
|
pi.on("context_with_system", (event, ctx) => {
|
|
1571
1569
|
const entries = ctx.sessionManager.getBranch();
|
|
1572
1570
|
try {
|
|
1573
|
-
const
|
|
1571
|
+
const projected = projectReorientation(projectCheckpoint(event.messages, entries), entries);
|
|
1572
|
+
const messages = latestVerbatimCompaction(entries) ? frameCheckpoint(projected) : projected;
|
|
1574
1573
|
if (Object.keys(turnFidelities(entries)).length) checkContextBudget(messages, ctx);
|
|
1575
1574
|
if (messages.length !== event.messages.length || messages.some((m, i) => m !== event.messages[i])) return { messages };
|
|
1576
1575
|
} catch (error) {
|
|
@@ -1687,7 +1686,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1687
1686
|
const reminder: AgentMessage = { ...reorientationMessage(entries, compaction.id, pruned.size > 0,
|
|
1688
1687
|
revisionId ?? compaction.id, Object.keys(modes).length > 0), role: "custom", timestamp: 0 };
|
|
1689
1688
|
const messages = checkpointContextMessages(summary, placements, modes, entries, compaction.firstKeptEntryId);
|
|
1690
|
-
return { ...estimateContext([system, ...messages, reminder], ctx), tailTokens,
|
|
1689
|
+
return { ...estimateContext([system, ...frameCheckpoint(messages), reminder], ctx), tailTokens,
|
|
1691
1690
|
noticeTokens: contextNoticeTokens(messages, reminder), shortening };
|
|
1692
1691
|
};
|
|
1693
1692
|
const saved = latestFilterRevision(entries)?.data ?? { summary: compaction.summary,
|
|
@@ -13,6 +13,9 @@ export interface TurnSlot { turnId: string; mode: Fidelity; offset: number; mark
|
|
|
13
13
|
export const MODE_LABELS: Record<TurnMode, string> = { pruned: "PRUNED", prose: "PROSE", tools: "PROSE+TOOLS", full: "FULL" };
|
|
14
14
|
export const MODE_SYMBOLS: Record<TurnMode, string> = { pruned: "X", prose: " ", tools: "○", full: "■" };
|
|
15
15
|
export const FIDELITY_EXPLANATION = "Selected PROSE+TOOLS/FULL turns are inserted as original context messages at their labelled positions, replacing their compacted copies. PROSE+TOOLS replaces recorded thinking blocks with [Thinking omitted]; FULL retains all recorded thinking. They are not shortened by the prose cap. Provider/model compatibility transformations still apply. Historical content and thinking are not verification of current facts.";
|
|
16
|
+
export 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.";
|
|
17
|
+
export 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}`;
|
|
18
|
+
export const CHECKPOINT_MESSAGE = "transparent-compact:checkpoint";
|
|
16
19
|
/** Raw user boundaries define whole turns, independent of context edits. */
|
|
17
20
|
export function turnOwners(entries: SessionEntry[]): Map<string, string | null> {
|
|
18
21
|
let owner: string | null = null;
|
|
@@ -140,6 +143,32 @@ export function expandCheckpoint(message: Extract<AgentMessage, { role: "compact
|
|
|
140
143
|
return output;
|
|
141
144
|
}
|
|
142
145
|
|
|
146
|
+
/** Frame TC's active checkpoint for the model only. Pi converts custom
|
|
147
|
+
* messages to user messages without adding its compaction summary wrapper.
|
|
148
|
+
* A full-fidelity checkpoint may straddle native turns; frame it once.
|
|
149
|
+
*/
|
|
150
|
+
export function frameCheckpoint(messages: AgentMessage[]): AgentMessage[] {
|
|
151
|
+
const first = messages.findIndex((m) => m.role === "compactionSummary");
|
|
152
|
+
if (first < 0) return messages;
|
|
153
|
+
const last = messages.findLastIndex((m) => m.role === "compactionSummary");
|
|
154
|
+
return messages.map((message, i) => {
|
|
155
|
+
if (message.role !== "compactionSummary") return message;
|
|
156
|
+
let content = message.summary;
|
|
157
|
+
if (i === first) {
|
|
158
|
+
// Move only the generated second line, never a matching quote in the body.
|
|
159
|
+
const start = content.indexOf("\n") + 1;
|
|
160
|
+
const intro = `${CHECKPOINT_EXPLANATION}\n`;
|
|
161
|
+
if (start > 0 && content.startsWith(intro, start)) {
|
|
162
|
+
content = `${CHECKPOINT_EXPLANATION}\n\n<compacted-checkpoint>\n${content.slice(0, start)}${content.slice(start + intro.length)}`;
|
|
163
|
+
} else {
|
|
164
|
+
content = `<compacted-checkpoint>\n${content}`;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (i === last) content += "\n</compacted-checkpoint>";
|
|
168
|
+
return { role: "custom", customType: CHECKPOINT_MESSAGE, content, display: false, timestamp: message.timestamp };
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
143
172
|
export interface NoticeTokens { pruning: number; revision: number; fidelity: number }
|
|
144
173
|
export interface ContextEstimate {
|
|
145
174
|
tokens: number;
|
|
@@ -190,7 +219,7 @@ export function checkpointContextMessages(summary: string, slots: TurnSlot[], fi
|
|
|
190
219
|
|
|
191
220
|
export function checkCheckpointBudget(summary: string, slots: TurnSlot[], fidelity: TurnFidelities,
|
|
192
221
|
entries: SessionEntry[], boundary: string, ctx: ExtensionContext): void {
|
|
193
|
-
if (Object.keys(fidelity).length) checkContextBudget(checkpointContextMessages(summary, slots, fidelity, entries, boundary), ctx, true);
|
|
222
|
+
if (Object.keys(fidelity).length) checkContextBudget(frameCheckpoint(checkpointContextMessages(summary, slots, fidelity, entries, boundary)), ctx, true);
|
|
194
223
|
}
|
|
195
224
|
|
|
196
225
|
/** UI-only, complete text/arguments/output preview; image bytes are identified,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foliox/transparent-compact-pi",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.3",
|
|
4
4
|
"description": "Model-free, deterministic, and self-aware compaction; with session-backed subagent context recovery, and optional context pruning and fidelity controls.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|