@foliox/transparent-compact-pi 0.8.7 → 0.8.8
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 +11 -0
- package/README.md +8 -0
- package/docs/DESIGN.md +42 -2
- package/extensions/index.ts +123 -8
- package/package.json +1 -1
- package/skills/context-retrieval/SKILL.md +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased — initial release preparation
|
|
4
4
|
|
|
5
|
+
- Replace misleading file-list content-absence claims with compact retained-evidence
|
|
6
|
+
labels, recomputed from Pi's projected tail at each checkpoint. Distinguish full,
|
|
7
|
+
partial, and uncertain reads; visible write payloads; and subsequent tracked
|
|
8
|
+
changes. Preserve startup-read labels and give modified paths a narrowly factual
|
|
9
|
+
negative label when no retained read/write evidence is established. Read-list
|
|
10
|
+
headers state the negative default once instead of repeating it per path. No
|
|
11
|
+
extra filesystem reads, model calls, or source-content duplication.
|
|
12
|
+
- Add a narrow safeguard before whole-file `write` replacement: reread unless
|
|
13
|
+
current contents are already visible, and do not reconstruct unchanged sections
|
|
14
|
+
from memory. Small exact-match edits do not require a blanket reread.
|
|
15
|
+
|
|
5
16
|
- Advertise recovery positively as retrieving history hidden by compaction, with
|
|
6
17
|
explicit provenance and contradiction triggers in the lookup description, skill,
|
|
7
18
|
and post-compaction reminders. Distinguish historical observations from current
|
package/README.md
CHANGED
|
@@ -72,6 +72,14 @@ earlier notes and new evidence. Prefer lookup for historical observations or to
|
|
|
72
72
|
avoid repeating costly research; inspect project files for current contents.
|
|
73
73
|
Cheap local rereads and recomputations remain reasonable.
|
|
74
74
|
|
|
75
|
+
File lists now distinguish source output retained in the recent tail, partial
|
|
76
|
+
reads, and reads followed by tracked changes. Modified paths without retained
|
|
77
|
+
read/write evidence are marked `no read-tool output in tail`; these annotations
|
|
78
|
+
are checkpoint-time evidence, not guarantees of current filesystem state.
|
|
79
|
+
Before replacing an existing file with `write`, the agent is told to reread it
|
|
80
|
+
unless current contents are already visible, rather than reconstruct unchanged
|
|
81
|
+
sections from memory. Small exact-match edits have no blanket reread requirement.
|
|
82
|
+
|
|
75
83
|
### Automatic startup-read retention
|
|
76
84
|
|
|
77
85
|
Successful text reads between the first and second user prompts are retained when
|
package/docs/DESIGN.md
CHANGED
|
@@ -16,7 +16,7 @@ extension builds a checkpoint without changing that boundary or calling a model:
|
|
|
16
16
|
| Custom messages | Short type stubs marked `content removed`; bodies remain in the raw session. Managed re-orientation messages are regenerated instead. |
|
|
17
17
|
| Recent conversation | Pi keeps its normal verbatim tail. |
|
|
18
18
|
| Earlier compacted spans | Re-rendered chronologically, without repeated model summarization. |
|
|
19
|
-
| Read/modified file lists |
|
|
19
|
+
| Read/modified file lists | Cumulative operation lists with checkpoint-relative retained-evidence annotations. |
|
|
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
|
|
@@ -40,6 +40,42 @@ extension, display setting, or content format. Long type names are abbreviated
|
|
|
40
40
|
like tool-call arguments. This applies even with the cap disabled. Previously
|
|
41
41
|
saved spans are not rewritten; older custom-message bodies may remain in them.
|
|
42
42
|
|
|
43
|
+
### File-list evidence annotations
|
|
44
|
+
|
|
45
|
+
The lists record reads and modifications in compacted history, not an exhaustive
|
|
46
|
+
inventory of current file contents. At every checkpoint, the extension checks
|
|
47
|
+
Pi's model-context projection from `firstKeptEntryId` onward. The turn prefix is
|
|
48
|
+
being compacted and is not treated as retained evidence. Context omissions and
|
|
49
|
+
replacements are respected; replacement read text has unknown completeness.
|
|
50
|
+
No filesystem reads or model calls are made for annotation.
|
|
51
|
+
|
|
52
|
+
Successful, unambiguously paired `read` results receive `(full read in tail)`,
|
|
53
|
+
`(partial read in tail)`, or `(read output in tail)` when completeness is uncertain.
|
|
54
|
+
For Pi's read contract, offset/limit alone does not imply partialness: an offset of
|
|
55
|
+
1 with a limit beyond EOF can still be complete. Truncation metadata and continuation
|
|
56
|
+
notices are checked. Separate partial pages are not combined into a full-file claim.
|
|
57
|
+
A later partial read does not hide an earlier complete snapshot with no intervening
|
|
58
|
+
tracked modification.
|
|
59
|
+
|
|
60
|
+
Successful writes with a visible full payload receive `(write content in tail)`.
|
|
61
|
+
Recorded subsequent edits/writes invalidate earlier snapshots and produce labels
|
|
62
|
+
such as `(read in tail, then edited)`. Mutation metadata can invalidate a snapshot
|
|
63
|
+
even when the mutation's message was omitted, but cannot restore omitted source
|
|
64
|
+
contents. Nested calls can invalidate snapshots, not supply visible file contents.
|
|
65
|
+
Same-path sibling operations may run concurrently, so ambiguous read/write versus
|
|
66
|
+
mutation ordering receives `(read in tail; order uncertain)` or the write equivalent
|
|
67
|
+
instead of treating result order as proof of freshness.
|
|
68
|
+
|
|
69
|
+
Modified paths without retained read/write evidence receive `(no read-tool output
|
|
70
|
+
in tail)`, unless a selected startup read is retained separately. Startup reads
|
|
71
|
+
keep their existing positive annotation. Unmodified paths without established
|
|
72
|
+
retained evidence remain unannotated; the read-list header states the default once:
|
|
73
|
+
"unless annotated, no retained read-tool output identified". A bare path does not
|
|
74
|
+
establish that document contents are still visible. The shared explanation states that labels
|
|
75
|
+
apply as of this checkpoint, not to live filesystem state; shell reads/changes and
|
|
76
|
+
external modifications are not inferred. File contents are never duplicated into
|
|
77
|
+
these lists, and annotations are recomputed rather than persisted as file metadata.
|
|
78
|
+
|
|
43
79
|
### Retained startup reads
|
|
44
80
|
|
|
45
81
|
On the first verbatim compaction, the extension scans successful text-only `read`
|
|
@@ -212,7 +248,11 @@ a claim as established. Retained prose can guide continuation without re-verifyi
|
|
|
212
248
|
every fact; unresolved claims should be labelled unverified, and retrieved reasoning
|
|
213
249
|
remains a historical hypothesis. Historical outputs do not establish current file
|
|
214
250
|
or build/test state.
|
|
215
|
-
There is no blanket edit-target reread.
|
|
251
|
+
There is no blanket edit-target reread. Before replacing an existing file with
|
|
252
|
+
`write`, the guidance requires rereading unless current contents are already in
|
|
253
|
+
view, and forbids reconstructing unchanged sections from memory. Small exact-match
|
|
254
|
+
edits and newly created files do not acquire a blanket reread requirement.
|
|
255
|
+
It is a saved
|
|
216
256
|
custom message tagged with the current compaction entry ID, not a temporary nudge:
|
|
217
257
|
subsequent responses and user turns retain it in history before the work that
|
|
218
258
|
followed it. `before_agent_start` adds it on normal starts/resume when missing;
|
package/extensions/index.ts
CHANGED
|
@@ -25,11 +25,13 @@
|
|
|
25
25
|
|
|
26
26
|
import * as fs from "node:fs";
|
|
27
27
|
import * as path from "node:path";
|
|
28
|
+
import { homedir } from "node:os";
|
|
29
|
+
import { fileURLToPath } from "node:url";
|
|
28
30
|
import { Type } from "typebox";
|
|
29
31
|
import { contentText, normalizeContext, uuidv7 } from "@earendil-works/pi-ai";
|
|
30
32
|
import type { Message as AiMessage, Model, Tool as AiTool } from "@earendil-works/pi-ai";
|
|
31
33
|
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
32
|
-
import { SessionManager } from "@earendil-works/pi-coding-agent";
|
|
34
|
+
import { buildSessionProjection, SessionManager } from "@earendil-works/pi-coding-agent";
|
|
33
35
|
import type { ExtensionAPI, ExtensionContext, ModelRegistry, SessionEntry } from "@earendil-works/pi-coding-agent";
|
|
34
36
|
|
|
35
37
|
// ============================================================================
|
|
@@ -645,6 +647,108 @@ ${r.text.join("\n")}
|
|
|
645
647
|
].join("\n\n");
|
|
646
648
|
}
|
|
647
649
|
|
|
650
|
+
// File annotations describe evidence, not a guarantee of filesystem freshness.
|
|
651
|
+
// Use Pi's projection for visibility, but recorded mutations can invalidate a
|
|
652
|
+
// snapshot even when the mutation's message was subsequently omitted.
|
|
653
|
+
interface FileEvidence {
|
|
654
|
+
kind: "read" | "write";
|
|
655
|
+
completeness?: "full" | "partial" | "unknown";
|
|
656
|
+
changed?: "edit" | "write";
|
|
657
|
+
orderUncertain?: boolean;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
function fileEvidenceKey(file: string, cwd: string): string {
|
|
661
|
+
// Lexical normalization only: no stat/realpath, and no symlink-equivalence claim.
|
|
662
|
+
let normalized = file.replace(/[\u00A0\u2000-\u200A\u202F\u205F\u3000]/g, " ").replace(/^@/, "");
|
|
663
|
+
if (normalized === "~") normalized = homedir();
|
|
664
|
+
else if (normalized.startsWith("~/") || (process.platform === "win32" && normalized.startsWith("~\\"))) normalized = path.join(homedir(), normalized.slice(2));
|
|
665
|
+
if (normalized.startsWith("file://")) {
|
|
666
|
+
try { normalized = fileURLToPath(normalized); } catch { /* Unknown path syntax: keep it literal. */ }
|
|
667
|
+
}
|
|
668
|
+
return path.resolve(cwd, normalized);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
function readCompleteness(args: Record<string, any>, message: Record<string, any>, replaced: boolean): "full" | "partial" | "unknown" {
|
|
672
|
+
const blocks = message.content;
|
|
673
|
+
if (replaced || !Array.isArray(blocks) || blocks.length !== 1 || blocks[0].type !== "text" || typeof blocks[0].text !== "string") return "unknown";
|
|
674
|
+
const text = blocks[0].text;
|
|
675
|
+
if (/^Read image file \[/.test(text)) return "unknown";
|
|
676
|
+
const truncation = message.details?.truncation;
|
|
677
|
+
if (truncation?.firstLineExceedsLimit) return "unknown"; // Only a warning, not file contents.
|
|
678
|
+
// Pi's read tool supplies these notices for both default and explicit limits.
|
|
679
|
+
if (truncation?.truncated === true || /\[(?:Showing lines [^\n]*Use offset=\d+ to continue\.|\d+ more lines in file\. Use offset=\d+ to continue\.)\]\s*$/.test(text)) return "partial";
|
|
680
|
+
const offset = args.offset ?? 1;
|
|
681
|
+
if (!Number.isInteger(offset) || offset < 1 || (args.limit != null && (!Number.isInteger(args.limit) || args.limit < 1))) return "unknown";
|
|
682
|
+
if (offset > 1) return "partial";
|
|
683
|
+
// A limit is not proof of partialness: without a continuation notice Pi reached EOF.
|
|
684
|
+
// Unknown argument schemas are not assumed to have Pi's read semantics.
|
|
685
|
+
return Object.keys(args).every((key) => ["path", "offset", "limit"].includes(key)) ? "full" : "unknown";
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
function retainedFileEvidence(entries: SessionEntry[], firstKeptEntryId: string | undefined, cwd: string): Map<string, FileEvidence> {
|
|
689
|
+
const evidence = new Map<string, FileEvidence>();
|
|
690
|
+
const cut = entries.findIndex((entry) => entry.id === firstKeptEntryId);
|
|
691
|
+
if (cut < 0) return evidence;
|
|
692
|
+
const visible = new Map(buildSessionProjection(entries).entries.map((entry) => [entry.sourceEntry.id, entry.messages]));
|
|
693
|
+
const pending = new Map<string, { name: string; args: Record<string, any>; visible: boolean; orderUncertain: boolean } | null>();
|
|
694
|
+
const changed = (name: "edit" | "write", args: Record<string, any>) => {
|
|
695
|
+
if (typeof args.path !== "string") return;
|
|
696
|
+
const previous = evidence.get(fileEvidenceKey(args.path, cwd));
|
|
697
|
+
if (previous) previous.changed = name;
|
|
698
|
+
};
|
|
699
|
+
for (const entry of entries.slice(cut)) {
|
|
700
|
+
if (entry.type !== "message") continue;
|
|
701
|
+
const raw = entry.message as unknown as Record<string, any>;
|
|
702
|
+
const projected = visible.get(entry.id)?.find((message) => message.role === raw.role) as Record<string, any> | undefined;
|
|
703
|
+
if (raw.role === "assistant") {
|
|
704
|
+
const blocks = Array.isArray(raw.content) ? raw.content : [];
|
|
705
|
+
for (const block of blocks) {
|
|
706
|
+
if (block.type !== "toolCall" || typeof block.id !== "string") continue;
|
|
707
|
+
// Sibling calls may execute concurrently; result order is not read/write order.
|
|
708
|
+
const orderUncertain = typeof block.arguments?.path === "string" && blocks.some((other: any) =>
|
|
709
|
+
other !== block && other.type === "toolCall" && ["write", "edit"].includes(other.name) &&
|
|
710
|
+
typeof other.arguments?.path === "string" &&
|
|
711
|
+
fileEvidenceKey(other.arguments.path, cwd) === fileEvidenceKey(block.arguments.path, cwd));
|
|
712
|
+
const shown = projected?.content?.filter?.((b: any) => b.type === "toolCall" && b.id === block.id);
|
|
713
|
+
const sameCall = shown?.length === 1 && shown[0].name === block.name &&
|
|
714
|
+
JSON.stringify(shown[0].arguments) === JSON.stringify(block.arguments);
|
|
715
|
+
pending.set(block.id, pending.has(block.id) ? null : { name: block.name, args: block.arguments ?? {}, visible: sameCall, orderUncertain });
|
|
716
|
+
}
|
|
717
|
+
} else if (raw.role === "toolResult") {
|
|
718
|
+
const call = pending.get(raw.toolCallId);
|
|
719
|
+
pending.delete(raw.toolCallId);
|
|
720
|
+
if (call && call.name === raw.toolName && typeof call.args.path === "string" && raw.isError === false) {
|
|
721
|
+
const key = fileEvidenceKey(call.args.path, cwd);
|
|
722
|
+
if (call.name === "write" || call.name === "edit") changed(call.name, call.args);
|
|
723
|
+
if (call.visible && projected && call.name === "read") {
|
|
724
|
+
const completeness = readCompleteness(call.args, projected, projected.content !== raw.content);
|
|
725
|
+
const previous = evidence.get(key);
|
|
726
|
+
// A later partial read does not hide an earlier complete snapshot.
|
|
727
|
+
if (!previous || previous.changed || previous.orderUncertain || (previous.kind === "read" && previous.completeness !== "full"))
|
|
728
|
+
evidence.set(key, { kind: "read", completeness, orderUncertain: call.orderUncertain });
|
|
729
|
+
} else if (call.visible && call.name === "write" && typeof call.args.content === "string") {
|
|
730
|
+
evidence.set(key, { kind: "write", orderUncertain: call.orderUncertain });
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
// Nested calls have metadata but no model-visible read outputs or write payloads.
|
|
734
|
+
for (const nested of raw.nestedCalls?.calls ?? []) {
|
|
735
|
+
if (nested.status === "ok" && (nested.name === "edit" || nested.name === "write")) changed(nested.name, nested.arguments ?? {});
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
return evidence;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
function fileEvidenceLabel(evidence: FileEvidence | undefined): string | undefined {
|
|
743
|
+
if (!evidence) return;
|
|
744
|
+
if (evidence.orderUncertain) return `${evidence.kind} in tail; order uncertain`;
|
|
745
|
+
if (evidence.changed) return `${evidence.kind} in tail, then ${evidence.changed === "edit" ? "edited" : "written"}`;
|
|
746
|
+
if (evidence.kind === "write") return "write content in tail";
|
|
747
|
+
return evidence.completeness === "unknown" ? "read output in tail" : `${evidence.completeness} read in tail`;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
const FILE_LIST_EXPLANATION = "File lists record earlier operations. Read/write annotations describe retained evidence as of this checkpoint, not live filesystem state; unannotated paths do not establish content visibility.";
|
|
751
|
+
|
|
648
752
|
const SECTION_HEADER = "### Compacted conversation (oldest first)";
|
|
649
753
|
const SPAN_CLOSE = "</compacted-span>";
|
|
650
754
|
const SPAN_TRIMMED_NOTE = "(trimmed for size — use context_lookup)";
|
|
@@ -755,7 +859,7 @@ const RECOVERY_SCOPE_RULE = "Use the recovery tools for history established by t
|
|
|
755
859
|
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.";
|
|
756
860
|
|
|
757
861
|
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.
|
|
862
|
+
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. **Before using \`write\` to replace an existing file, re-read it unless its current contents are already visible in context. Do not reconstruct unchanged sections from memory.**
|
|
759
863
|
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
864
|
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.`;
|
|
761
865
|
|
|
@@ -902,13 +1006,24 @@ async function buildMechanicalSummary(opts: {
|
|
|
902
1006
|
// verbatim boundary line. That closing line is the LAST line of the
|
|
903
1007
|
// checkpoint; everything after it is pi's retained verbatim tail.
|
|
904
1008
|
if (retainedReads) parts.push("", retainedReads);
|
|
905
|
-
const retainedPaths = new Set(opts.startupReads.reads.map((r) =>
|
|
1009
|
+
const retainedPaths = new Set(opts.startupReads.reads.map((r) => fileEvidenceKey(r.path, opts.cwd)));
|
|
906
1010
|
const hasFileLists = opts.readFiles.length > 0 || opts.modifiedFiles.length > 0;
|
|
907
|
-
if (hasFileLists)
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
1011
|
+
if (hasFileLists) {
|
|
1012
|
+
const evidence = retainedFileEvidence(opts.branchEntries, opts.firstKeptEntryId, opts.cwd);
|
|
1013
|
+
const knownTail = opts.branchEntries.some((entry) => entry.id === opts.firstKeptEntryId);
|
|
1014
|
+
const fileLine = (file: string, modified: boolean): string => {
|
|
1015
|
+
const key = fileEvidenceKey(file, opts.cwd);
|
|
1016
|
+
const label = fileEvidenceLabel(evidence.get(key)) ?? (retainedPaths.has(key)
|
|
1017
|
+
? "startup read output retained in checkpoint or tail; may be partial"
|
|
1018
|
+
: modified && knownTail ? "no read-tool output in tail" : undefined);
|
|
1019
|
+
return `${checkpointPath(file, opts.cwd)}${label ? ` (${label})` : ""}`;
|
|
1020
|
+
};
|
|
1021
|
+
parts.push("", FILE_LIST_EXPLANATION);
|
|
1022
|
+
if (opts.readFiles.length > 0)
|
|
1023
|
+
parts.push(`<read-files note="reads in compacted history; unless annotated, no retained read-tool output identified">\n${opts.readFiles.map((file) => fileLine(file, false)).join("\n")}\n</read-files>`);
|
|
1024
|
+
if (opts.modifiedFiles.length > 0)
|
|
1025
|
+
parts.push(`<modified-files note="modified in compacted history">\n${opts.modifiedFiles.map((file) => fileLine(file, true)).join("\n")}\n</modified-files>`);
|
|
1026
|
+
}
|
|
912
1027
|
parts.push("");
|
|
913
1028
|
parts.push(EVIDENCE_BOUNDARY_RULE);
|
|
914
1029
|
parts.push("");
|
package/package.json
CHANGED
|
@@ -95,7 +95,7 @@ intended context parameters.
|
|
|
95
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.
|
|
96
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.
|
|
97
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.
|
|
98
|
-
5. Historical tool output proves what was observed then, not what is true now. Review uncommitted work and re-verify current build/test state when needed
|
|
98
|
+
5. Historical tool output proves what was observed then, not what is true now. Review uncommitted work and re-verify current build/test state when needed. **Before using `write` to replace an existing file, re-read it unless its current contents are already visible in context. Do not reconstruct unchanged sections from memory.** This is not a blanket reread requirement for small exact-match `edit`s. File-list annotations describe retained evidence as of the checkpoint, not live filesystem state; a read or write payload may already be visible in the tail.
|
|
99
99
|
6. Lookups can return incomplete findings or fail. State what remains missing; do not invent details or treat a partial answer as exhaustive.
|
|
100
100
|
|
|
101
101
|
## Independent exports
|