pi-context 2.0.0-beta.0 → 2.1.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Pi Context: Agentic Context Management for Pi
2
2
 
3
- An Agentic Context Management tool that helps AI agents proactively manage checkpoints, timeline inspection, and rewind-based context cleanup.
3
+ An Agentic Context Management tool that helps AI agents keep long conversations focused by maintaining a clean working set: checkpoint useful anchors, inspect the active history structure, and compact noisy completed paths into state summaries.
4
4
 
5
5
  Inspired by kimi-cli d-mail, it brings lossless time travel to Pi's session tree.
6
6
 
@@ -13,9 +13,9 @@ Earlier versions used more Git-like names such as `context_tag`, `context_log`,
13
13
  Current versions intentionally use conversation-native names instead:
14
14
  - `context_checkpoint`
15
15
  - `context_timeline`
16
- - `context_rewind`
16
+ - `context_compact`
17
17
 
18
- These tools manage **conversation history**, not repository state. They should not be treated as Git commands or as replacements for real `git tag`, `git log`, or `git checkout`.
18
+ These tools manage **conversation history**, not repository state. They should not be treated as Git commands or as replacements for real `git tag`, `git log`, or `git checkout`. Context navigation does not modify or roll back files, running processes, browser state, tickets, databases, or remote services.
19
19
 
20
20
  ## Installation
21
21
 
@@ -43,13 +43,13 @@ Open a visual dashboard to inspect context-window usage and token distribution (
43
43
 
44
44
  ### For Agents
45
45
 
46
- This extension adds the `context-management` skill, which includes three core tools:
46
+ This extension adds the `context-management` skill, which guides agents to keep the active conversation as the smallest sufficient working set for the next step. It includes three core tools:
47
47
 
48
- 1. **🔖 Structure (`context_checkpoint`)**
49
- Create named checkpoints to organize conversation history.
48
+ 1. **🔖 Anchor (`context_checkpoint`)**
49
+ Label a meaningful conversation node with a unique semantic checkpoint name, such as `parser-fix-start` or `timeout-investigation-search`.
50
50
 
51
- 2. **📊 Monitor (`context_timeline`)**
52
- Visualize conversation history, inspect token usage, and see where you are in the task tree.
51
+ 2. **📊 Inspect (`context_timeline`)**
52
+ View the active path as a structural map of checkpoints, summaries/compactions, branch points, user turns, and current position. Use it when orientation or compact target selection depends on history shape.
53
53
 
54
- 3. **⏪ Compress (`context_rewind`)**
55
- Return to an earlier checkpoint or anchor with a carryover summary so completed noisy work can be compacted into a cleaner continuation.
54
+ 3. **⏪ Compact (`context_compact`)**
55
+ Create a summarized continuation branch from an earlier checkpoint, history node, or `root`. The summary should restore the useful state after the target: current task, decisions, external side effects such as changed files or remote updates, validation state, source anchors, and the explicit next step.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-context",
3
- "version": "2.0.0-beta.0",
3
+ "version": "2.1.0",
4
4
  "description": "Agentic Context Management for Pi",
5
5
  "files": [
6
6
  "src",
@@ -15,18 +15,19 @@
15
15
  "pi-package",
16
16
  "context-management",
17
17
  "context-optimization",
18
+ "context-compact",
18
19
  "time-travel",
19
20
  "checkpoint",
20
21
  "pi-skill"
21
22
  ],
22
23
  "type": "module",
23
- "author": "",
24
+ "author": "ttttmr",
24
25
  "license": "MIT",
25
26
  "devDependencies": {
26
- "@earendil-works/pi-ai": "^0.75.4",
27
- "@earendil-works/pi-coding-agent": "^0.75.4",
28
- "@earendil-works/pi-tui": "^0.75.4",
29
- "typescript": "^5.7.2"
27
+ "@earendil-works/pi-ai": "^0.80.6",
28
+ "@earendil-works/pi-coding-agent": "^0.80.6",
29
+ "@earendil-works/pi-tui": "^0.80.6",
30
+ "typescript": "^5.9.3"
30
31
  },
31
32
  "pi": {
32
33
  "extensions": [
@@ -1,274 +1,205 @@
1
1
  ---
2
2
  name: context-management
3
- description: Read this skill for work that is likely to stretch across many turns or get messy if handled in one uninterrupted thread. Especially use it when the request sounds like first go search or read a lot, first look through logs/files/pages/results and come back with the real conclusion, this will probably take several rounds, there may be several approaches to try, first make a plan or todo list and then work through it, there will be many similar cases to handle, the user may interrupt with side tasks, or the thread is already getting messy and should be cleaned up before continuing. It teaches a working mode built around frequent checkpoints, periodic timeline review, and targeted rewinds as the task evolves. Usually skip it for one-shot reads, bounded summaries, direct rewrites, or deterministic scripts.
3
+ description: "Use this skill for multi-turn, phased, or noisy work: research/reading, debugging, plan-then-execute, retries/pivots, background or asynchronous work, handoffs, user decisions, task switching, repeated items, or repeated progress checks. It keeps the conversation as a clean working set with checkpoints, timeline review, and compaction at continuation boundaries. Always use when resuming after context compaction or when a long phase reaches a decision, handoff, validation, or task-switch boundary. Usually skip simple one-shot tasks."
4
4
  ---
5
5
 
6
6
  # Context Management
7
7
 
8
- Use this skill to adopt an explicit conversation-management working mode.
8
+ Use this skill to keep the active conversation as a useful **working set** for the next step. Keep raw only the context that still needs direct reasoning; carry the rest as compact task state when that is more efficient.
9
9
 
10
- This mode is for tasks where the work may still be valid, but the thread carrying it is likely to become long, noisy, multi-phase, or hard to keep clean. The goal is to keep the work navigable: checkpoint early, review timeline when needed, and compact completed noisy phases back to clean anchors.
10
+ Core rhythm:
11
+
12
+ - **checkpoint before mess**
13
+ - **review timeline when structure affects the next decision**
14
+ - **compact when a state summary is a better working set than the raw trail**
15
+
16
+ Use only these tools:
11
17
 
12
- Use only the current tool names:
13
18
  - `context_checkpoint`
14
19
  - `context_timeline`
15
- - `context_rewind`
20
+ - `context_compact`
21
+
22
+ ## Working-set model
23
+
24
+ Before choosing a tool, ask:
16
25
 
17
- ## When to use this skill
26
+ - What am I trying to do next?
27
+ - What facts, constraints, or artifacts must stay raw for that next action?
28
+ - What important data has a reliable external source I can re-check instead of carrying raw?
29
+ - What history is useful only as a conclusion, pointer, or state update?
30
+ - What history is process noise or stale baggage?
18
31
 
19
- Read this skill when the task is likely to outgrow one clean thread and would benefit from explicit history management.
32
+ Classify context into:
20
33
 
21
- It should feel like a good fit when the user is effectively asking for one of these patterns:
34
+ - **Raw context:** user intent, constraints, code/log/error details, evidence, or plan text you expect to inspect directly soon.
35
+ - **State summary:** decisions, findings, lessons, changed files, validation status, source pointers, rejected leads, and next steps that can replace raw process.
36
+ - **Discardable process:** repetitive searches, verbose logs, abandoned hypotheses, false starts, and unrelated turns whose useful value is already captured or gone.
22
37
 
23
- ### “First go look through a lot of stuff, then come back with the real conclusion.”
24
- Examples:
25
- - searching or researching first
26
- - web search or browser-driven information gathering
27
- - reading many files, logs, docs, webpages, or web results
28
- - review / comparison / audit-heavy reading across many sources
38
+ If the active context is already small, coherent, and directly useful for the next step, do not manage it just to be tidy.
29
39
 
30
- ### “This will probably take several rounds or several phases.”
31
- Examples:
40
+ ## When to use
41
+
42
+ Use this mode when the work may outgrow one clean thread:
43
+
44
+ - search, research, browser work, or reading many files/logs/pages/results
32
45
  - investigate -> decide -> execute -> validate
33
46
  - plan -> implement -> verify
34
- - collect -> compare -> conclude
35
- - any task that will keep changing shape as it progresses
36
-
37
- ### “We may need to try more than one route.”
38
- Examples:
39
- - A / B / C approaches
40
- - dead ends and retries
41
- - compare and choose
42
- - pivoting after a failed direction
43
-
44
- ### “Start from a plan or todo list, then work through it.”
45
- Examples:
46
- - a formal implementation or migration plan
47
- - a roadmap with milestones
48
- - a lightweight todo list or checklist
49
- - staged execution that will be revisited across many turns
50
-
51
- ### “There will be many similar cases, tickets, or items.”
52
- Examples:
53
- - repeated cases
54
- - repeated tickets
55
- - repeated checks
56
- - repeated reviews
57
- - repeated fix attempts on similar inputs
58
-
59
- ### “I may interrupt you, or this thread is already getting messy.”
60
- Examples:
61
- - the user may insert side tasks
62
- - you need to pause one line of work and resume it later
63
- - the thread is already long, stale, or cluttered
64
- - finished noisy phases should be cleaned up before continuing
65
-
66
- ### “This is code-facing work and may turn noisy while I debug or implement it.”
67
- Examples:
68
- - implementation
69
- - debugging
70
- - troubleshooting
71
- - refactoring
72
- - migration
73
- - code-facing review or fix work
74
-
75
- If one of these patterns clearly applies, take the first structural action now—usually a checkpoint—instead of only describing the intended workflow.
76
-
77
- If multiple approaches, failed branches, compare work, or pivots become central, also read `references/retry-branch-and-pivot.md` in addition to the main scenario reference.
78
-
79
- ## When to skip it
80
-
81
- Usually skip this skill for:
82
- - one-shot reads
83
- - bounded summaries
84
- - direct rewrites with little exploration
85
- - simple fact lookup or concept explanation
86
- - deterministic scripts or fixed-rule automation
87
- - short tasks that can stay clean in one thread
88
-
89
- ## Operating rhythm
90
-
91
- 1. Before entering a noisy phase, create a checkpoint.
92
- 2. If you feel disoriented or anchor choice is unclear, run `context_timeline`.
93
- 3. Add more checkpoints at milestones, phase boundaries, risky branches, and interruptions.
94
- 4. Do not rewind just because the skill triggered.
95
- 5. Once a noisy phase is complete and summarizable, rewind to the best earlier clean anchor.
96
- 6. Continue from the compacted state instead of dragging the full messy path forward.
97
-
98
- The key habit is: **checkpoint is the default move; rewind is the selective cleanup move.** Checkpointing alone is not the end state. Checkpoints create anchors so that completed noisy phases can later be compacted cleanly.
47
+ - background or asynchronous work, handoffs, user decisions, or delayed results
48
+ - multiple approaches, retries, failed branches, comparisons, or pivots
49
+ - repeated similar cases, tickets, reviews, or batch items
50
+ - a main task that may be interrupted by side tasks
51
+ - repeated progress/status checks that indicate active state is hard to track
52
+ - scattered threads that need cleanup before continuing
53
+ - debugging, troubleshooting, refactoring, migration, or code-facing work that may get noisy
99
54
 
100
- ## Tool policy
55
+ If one of these clearly applies, take a structural action now, usually a checkpoint. Do not merely describe the workflow. If the user has not provided enough task details, still checkpoint the workflow shape before asking clarifying questions.
101
56
 
102
- ### `context_checkpoint`
103
- This is the default tool in this mode.
57
+ Usually skip this skill for one-shot reads, bounded summaries, direct rewrites, simple lookups, deterministic scripts, short tasks that can stay clean, or moments where the active context is already a good working set.
104
58
 
105
- Use it:
106
- - before noisy work
107
- - before a new phase
108
- - after a meaningful milestone
109
- - before a risky attempt
110
- - before switching to another subtask
59
+ ## Start-of-turn check
111
60
 
112
- Use semantic names so the timeline stays readable.
61
+ At the start of each new user message, classify it:
113
62
 
114
- Recommended patterns:
115
- - `<task>-start`
116
- - `<task>-<phase>`
117
- - `<task>-<attempt>`
118
- - `<task>-<milestone>`
63
+ - **Same task / next phase:** continue; if the previous phase is complete and noisy, compact before the next phase.
64
+ - **Correction or follow-up:** usually answer from recent context; do not compact yet.
65
+ - **New task or direction shift:** if the previous task left a complete noisy segment, inspect timeline when anchors are unclear, then compact to a continuation anchor that gives the new task a clean working set.
119
66
 
120
- Examples:
121
- - `auth-oauth-start`
122
- - `timeout-analysis-search`
123
- - `db-migration-plan`
124
- - `parser-fix-attempt-2`
125
- - `vendor-review-milestone-1`
67
+ Think of the tools as a phase pipeline: checkpoint marks anchors, work happens, timeline shows structure, and compact creates a new branch from the chosen continuation anchor with a summary of what happened after it. The target is a working-set choice, not an age choice.
126
68
 
127
- Avoid generic names like `start`, `checkpoint-1`, `phase-1`, or `retry`.
69
+ ## Main loop
128
70
 
129
- ### `context_timeline`
130
- Use this tool to regain orientation.
131
-
132
- Use it:
133
- - when you feel lost or drifted
134
- - when several checkpoints or branches now exist
135
- - before choosing a rewind target
136
- - at major phase transitions if you need a quick map
137
- - when the thread feels cluttered and you want a structural view before acting
138
-
139
- When you inspect timeline, ask:
140
- - Where is the nearest clean anchor?
141
- - Has the current segment grown too long without a clean checkpoint?
142
- - Am I carrying a failed or stale branch forward?
143
- - Is there already a better checkpoint to rewind to?
144
-
145
- ### `context_rewind`
146
- Use this tool to compact a path that should no longer stay active in full.
147
-
148
- Use it:
149
- - after a noisy investigation has produced a stable finding
150
- - after a failed attempt has produced a clear lesson
151
- - after a completed phase where the next step is clear
152
- - after a representative item or branch has already taught you what you need
153
- - when the current path is dragging too much stale or low-value context forward
154
-
155
- A successful use of this mode often ends with `context_rewind`, not just more checkpointing.
156
-
157
- ## Rewind protocol
158
-
159
- ### When to rewind
160
- Rewind when the current phase is ready to be compacted.
161
-
162
- Good reasons to rewind:
163
- - a phase produced a stable finding or conclusion
164
- - a failed path produced a clear dead-end lesson
165
- - a milestone was reached and you want a cleaner continuation
166
- - a representative item or branch has already taught you the reusable lesson
167
- - the thread is carrying more stale intermediate process than active value
168
-
169
- A phase is usually rewind-ready when you now have one of these:
170
- - a root cause or research conclusion
171
- - a clear failure reason for abandoning a branch
172
- - a completed implementation or troubleshooting phase
173
- - a reusable method learned from a representative item
174
- - a finished repeated-item segment whose raw path no longer needs to stay live
175
-
176
- Do **not** rewind yet when:
177
- - you are still in the middle of active exploration
178
- - the result is still unstable or incomplete
179
- - you only feel mild clutter and a checkpoint would be enough
180
- - you have not yet decided which earlier anchor you want to continue from
181
-
182
- When in doubt: checkpoint first, review timeline if needed, and rewind later once the phase boundary is clearer.
183
-
184
- ### Choose the target and backup
185
- Choose the **best earlier clean anchor**, not just any earlier checkpoint.
186
-
187
- Usually prefer:
188
- - the start of the noisy phase you are compacting
189
- - the nearest clean phase-start before the current failed or completed path
190
- - the repeated-work anchor for repeated-item workflows
191
- - the last stable pre-branch checkpoint when abandoning an approach
71
+ 1. Before noisy work, create a semantic checkpoint as the first context-management action. If the first job is orientation over existing history, run `context_timeline` before adding a new checkpoint.
72
+ 2. When the task shape is clear, read one matching scenario reference only if it will change tool timing, anchor choice, or summary content. Skip reference loading for obvious short applications where this main skill body is enough.
73
+ 3. Add checkpoints at meaningful milestones: phase boundaries, risky attempts, reusable batch methods, and interruptions.
74
+ 4. Use `context_timeline` when the active path structure affects the next decision or compact target.
75
+ 5. At continuation boundaries, run the compact gate before starting another phase. If the whole requested task is complete and only the final response remains, answer and wait.
76
+ 6. After a successful compact, continue from the injected summary instead of dragging the full raw path forward.
192
77
 
193
- Avoid:
194
- - rewinding too far back when a nearer clean anchor exists
195
- - rewinding to a checkpoint that still includes the noise you want to leave behind
196
- - defaulting to `root` unless the whole active path should be reset
197
-
198
- If you are unsure which anchor is best, run `context_timeline` first.
199
-
200
- Use `backupCheckpoint` when:
201
- - the raw path may still be useful later
202
- - you are compacting a long investigation
203
- - you are abandoning a branch but may need its details again
204
- - you want a safe recovery point before a major rewind
205
-
206
- A backup checkpoint preserves the raw path you are compacting. If the summary later proves insufficient, return to that backup instead of redoing the whole investigation.
207
-
208
- If the raw path is low value and unlikely to matter again, a backup is optional.
209
-
210
- ### Write the message
211
- A rewind message is the baton pass to future-you. It is not a throwaway comment.
212
-
213
- At minimum, include:
214
- - the main result, lesson, or failure summary
215
- - why you are rewinding now
216
- - important changes, especially changed files if disk state changed
217
- - the next step after the rewind
218
-
219
- Useful shapes:
220
- - `[result] + [reason for rewind] + [next step]`
221
- - `[result] + [reason for rewind] + [important decision or change] + [next step]`
222
- - `[result] + [reason for rewind] + [important changes / changed files] + [next step]`
223
-
224
- Good examples:
225
- - `Found DB connection pool exhaustion as the likely root cause. Reason: investigation phase is complete and ready to compact. Next step: report findings and propose mitigation.`
226
- - `Parser fix is implemented and the debugging phase is complete. Reason: compacting implementation history before focused validation. Important changes: modified src/parser.ts and test/parser.test.ts. Next step: run targeted validation and summarize remaining edge cases.`
227
- - `WeakRef approach failed because objects were collected too early and cache hit rate collapsed. Reason: abandoning this attempt and returning to a clean anchor. Next step: try object pooling instead.`
228
-
229
- Avoid vague messages like:
230
- - `Done`
231
- - `Switching context`
232
- - `Investigated`
233
- - `Going back`
234
-
235
- Before using `context_rewind`, quickly check:
236
- - Is there already a stable result, lesson, or failure summary?
237
- - Do I know why this is the right moment to rewind?
238
- - If disk state changed, did I record the important changes or changed files?
239
- - Is the next step explicit?
240
- - Would future-me understand what changed just from this message?
241
-
242
- If not, keep working a bit longer or checkpoint first.
243
-
244
- ### After rewind
245
- When `context_rewind` succeeds:
246
- 1. Read the injected summary carefully.
247
- 2. Treat it as the new active state.
248
- 3. Execute the next step from that summary.
249
- 4. Do not keep reasoning from the full old path unless you intentionally return to a backup checkpoint.
78
+ ## Continuation boundaries
250
79
 
251
- ## Common mistakes
80
+ A continuation boundary is a point where the current phase has produced a stable result and the next action will use that result to start a different phase. It is not necessarily the end of the user's whole task.
252
81
 
253
- Avoid:
254
- - checkpointing constantly without phase meaning
255
- - rewinding blindly without checking timeline when anchor choice is unclear
256
- - carrying completed noisy phases forward instead of compacting them
257
- - writing vague rewind messages that future-you cannot act on
82
+ Examples: investigation -> decision/plan/implementation, implementation -> validation, failed validation -> next approach, delayed result -> routing/action, user decision -> execution, rejected branch -> replacement direction, side request -> pause/summarize mainline before switching.
83
+
84
+ Do not ask only "is the whole task done?" Ask "will the next action start a new phase using the stable result of this phase?" If yes, this is often a compaction boundary.
85
+
86
+ Handoffs are not final answers: if a response transfers control to the user, another actor/process, later validation, or a queued phase, compact when the prior phase was noisy and the next action needs only stable state.
258
87
 
259
88
  ## Read the right reference
260
89
 
261
- Read **one primary reference** based on the task shape:
262
- - search / research / reading-heavy work, especially web search, browser operation, or low-density webpage reading -> `references/search-research-and-reading.md`
90
+ Read **one primary reference** only when the scenario pattern will affect tool timing, anchor choice, or summary content:
91
+
92
+ - search / research / reading-heavy work -> `references/search-research-and-reading.md`
263
93
  - development / debugging / troubleshooting / refactoring / migration -> `references/development-and-troubleshooting.md`
264
94
  - planning / staged execution / todo-driven work -> `references/planning-and-execution.md`
265
95
  - repeated similar items / batch work -> `references/repeated-items-and-batch-work.md`
266
- - task switching / pause-resume / cleanup-and-continue work -> `references/task-switching-and-cleanup.md`
96
+ - task switching / pause-resume / interruptions / cleanup-and-continue -> `references/task-switching-and-cleanup.md`
97
+ - interleaved async work / overlapping fronts / background results / user decisions -> `references/interleaved-async-work.md`
98
+
99
+ Also read `references/retry-branch-and-pivot.md` when multiple approaches, failed branches, comparisons, retries, or pivots become central.
100
+
101
+ ## Tool policy
102
+
103
+ ### `context_checkpoint`
104
+
105
+ Use before noisy work, a new phase, a risky attempt, switching subtasks, or after a meaningful milestone. Use semantic names such as `<task>-start`, `<task>-<phase>`, `<task>-<attempt>`, or `<task>-<milestone>`. Avoid generic names like `start`, `checkpoint-1`, or `retry`.
106
+
107
+ ### `context_timeline`
108
+
109
+ Use it as the structural view of the active path:
110
+
111
+ - when the current path shape affects the next decision
112
+ - when several checkpoints, branches, or task switches exist
113
+ - before choosing a non-obvious compact target
114
+ - when the thread feels cluttered and you need to distinguish useful context from baggage
115
+
116
+ When reading the timeline, ask which raw messages are still needed for the immediate next action, which paths are now baggage, and which anchor gives the smallest sufficient working set after summary injection.
117
+
118
+ ### `context_compact`
119
+
120
+ Use it to replace raw history with a state summary when the next phase would benefit from a smaller working set.
267
121
 
268
- Then read the cross-cutting retry reference when needed:
269
- - multiple approaches, failed branches, compare, retry, or pivot behavior -> `references/retry-branch-and-pivot.md`
122
+ Typical compact boundaries: investigation -> execution, diagnosis -> fix, implementation -> validation, failed attempt -> next attempt, representative item -> remaining batch, completed noisy task -> new user task.
270
123
 
271
- Keep the mode simple:
272
- - checkpoint before mess
273
- - review timeline when orientation matters
274
- - rewind when a phase is ready to be compacted
124
+ Strong signals to consider compaction:
125
+
126
+ - repeated progress/status checks
127
+ - inability to summarize current state, next action, and open risks in one short paragraph
128
+ - rejected, abandoned, or superseded branches
129
+ - stable result after many tool calls or long output
130
+ - returned background/asynchronous/delegated result
131
+ - material plan or approach change
132
+ - side question arriving while stale process history is active
133
+
134
+ Do not compact while exploration is still active, when the result is unstable, just because the skill triggered, or just because the user-visible task ended.
135
+
136
+ ## Compact gate
137
+
138
+ Before calling `context_compact`, require all three:
139
+
140
+ 1. The segment being left behind is noisy, stale, failed, low-value in raw form, or actively reducing focus.
141
+ 2. You can restore the useful task state in a clear summary.
142
+ 3. There is an immediate continuation that benefits from cleaner context.
143
+
144
+ If the compact is prompted by a new user message, a direction shift, or several possible checkpoint targets, run `context_timeline` first and choose the target from visible structure rather than memory.
145
+
146
+ If the whole task is done and only the final answer remains, wait. Compact later only if the next user message makes it useful.
147
+
148
+ Checkpoint-only failure mode: a checkpoint is useful because it gives you a clean anchor to compact back to later. After any checkpointed phase produces a stable result, ask what the phase settled, whether the next step is different, and whether a summary can replace the raw trail. If yes, compact; do not keep accumulating raw history just because the overall task is still active.
149
+
150
+ ## Choosing target and backup
151
+
152
+ Choose the continuation anchor by designing the next working set:
153
+
154
+ 1. Name the immediate next action.
155
+ 2. Decide what must remain raw: active user intent, current constraints, still-open evidence/code context, an approved plan being executed, or details you expect to inspect directly next.
156
+ 3. Decide what can become state summary or disappear: completed searches, verbose logs, failed attempts, stale branches, earlier unrelated tasks, externally recoverable data, and clear process details.
157
+ 4. Pick the anchor that leaves the new branch with the **smallest sufficient context** after summary injection.
158
+ 5. If an older anchor plus a stronger summary is cleaner than a recent anchor plus stale context, prefer the older anchor. When completed fronts fill the middle of the thread, it can be correct to compact to a much older anchor or even `root` if the summary restores the active front and source pointers.
159
+
160
+ Avoid targets that are too late, too early with a weak summary, or semantically wrong. If there are several checkpoints, a task switch, or uncertainty about the best working set, run `context_timeline` first.
161
+
162
+ Use `backupCheckpoint` when raw history may still matter later. A backup is a recovery safety net, not a substitute for the summary.
163
+
164
+ ## Compact summary contract
165
+
166
+ The summary is not a transcript recap. It is the state needed to resume work from the chosen anchor; older or cleaner anchors require stronger summaries.
167
+
168
+ Context tools change conversation state, not the outside world. Files, processes, browser state, tickets, databases, remote services, and other side effects stay current. If you compact to an anchor before those changes, the summary must bridge the gap between old conversation context and current external state.
169
+
170
+ A compact summary must restore:
171
+
172
+ 1. **Task state:** current task, user intent, constraints, decisions, assumptions, and known result/progress/failure.
173
+ 2. **External state:** changed files, created/deleted artifacts, running/stopped processes, browser actions, tickets/records, deployments, remote changes.
174
+ 3. **Verification state:** commands already run, validation status, notable outputs, and remaining risks or open questions.
175
+ 4. **Navigation state:** source anchors/evidence when needed, rejected leads worth avoiding, backup checkpoint guidance, and explicit next step.
176
+
177
+ If important data has a reliable external source, preserve the pointer and retrieval method rather than copying the raw data. Examples: file path and line/query, database table/query, task/job id, log path, URL, record id, branch/commit, or command to inspect status. Include raw values only when they are small, unstable, hard to retrieve, or needed for immediate reasoning.
178
+
179
+ For long-running work, shape the summary as a state capsule: goal, stable result, decisions, rejected paths, current artifacts/source pointers, active work, pending input, risks/open questions, and next action. Include why compacting is appropriate only when it helps future orientation. Avoid vague summaries like `Done`, `Investigated`, `Switching context`, or `Going back`.
180
+
181
+ Before compacting, quickly check: stable state? real continuation? smallest sufficient working set? summary restores state after the anchor? externally recoverable data represented by pointers? external side effects and validation captured? explicit next step?
182
+
183
+ ## After compact
184
+
185
+ 1. Read the injected summary carefully and treat it as the new active state.
186
+ 2. Verify it contains enough state for the next action.
187
+ 3. Remember that disk and external systems were not rolled back; inspect current files/tools/services when state matters.
188
+ 4. If a missing detail is cheap to reconstruct from disk, tools, or source anchors, retrieve it directly.
189
+ 5. Return to the backup checkpoint only when the missing raw context cannot be reconstructed cheaply.
190
+
191
+ ## Common mistakes
192
+
193
+ Avoid:
194
+
195
+ - checkpointing constantly without phase meaning
196
+ - checkpointing early but never compacting after a stable phase result
197
+ - compacting blindly without timeline when anchor choice is unclear
198
+ - preserving too much raw history because older anchors or `root` feel risky
199
+ - using an old anchor or `root` with a weak summary
200
+ - compacting immediately after a final deliverable when no next user intent is known
201
+ - carrying completed noisy phases into a new task
202
+ - treating handoff or decision prompts as final answers when a continuation is expected
203
+ - writing summaries that recap history but fail to restore current task state
204
+ - assuming compact or branch navigation reverts files, processes, browser state, or remote services
205
+ - omitting decisions, constraints, external side effects, changed files, validation status, or next step
@@ -15,7 +15,7 @@ These tasks often stay cleaner when treated as stages with anchors, instead of o
15
15
  1. Create a checkpoint before starting serious work.
16
16
  2. Add checkpoints before risky edits, new approaches, or major phase changes.
17
17
  3. Review the timeline when you need to understand the current shape of the work.
18
- 4. Rewind after a stable implementation milestone, a failed approach, or a completed troubleshooting phase.
18
+ 4. Compact after a stable implementation milestone, a failed approach, or a completed troubleshooting phase when there is another phase, attempt, validation step, or task switch that benefits from cleanup. If files, processes, or external systems changed, include those side effects in the summary because context navigation does not roll them back. If the completed phase is also the final user-visible deliverable, answer first and wait.
19
19
 
20
20
  ## Typical checkpoint moments
21
21
 
@@ -40,28 +40,28 @@ Run `context_timeline` when:
40
40
  - you are about to abandon one approach and restart from another anchor
41
41
  - you are unsure which checkpoint best represents the clean continuation point
42
42
 
43
- ## Rewind patterns
43
+ ## Compact patterns
44
44
 
45
45
  ### After a failed attempt
46
46
 
47
- Use rewind when an attempt clearly failed and you have a crisp summary of why.
47
+ Use compact when an attempt clearly failed and you have a crisp summary of why.
48
48
 
49
49
  ```javascript
50
- context_rewind({
50
+ context_compact({
51
51
  target: "memory-leak-fix-start",
52
- message: "WeakRef approach failed because objects were collected too early and cache hit rate collapsed. Reason: abandoning this attempt and returning to a clean anchor. Next step: try object pooling instead.",
52
+ summary: "Current task: continue the memory leak fix. State: WeakRef approach failed because objects were collected too early and cache hit rate collapsed. Decision: abandon WeakRef and try object pooling. Next step: implement the object-pooling approach.",
53
53
  backupCheckpoint: "memory-leak-weakref-raw-history"
54
54
  });
55
55
  ```
56
56
 
57
57
  ### After a completed phase
58
58
 
59
- Use rewind when a phase is done and you want to continue from a cleaner thread.
59
+ Use compact when a phase is done and the next phase would work better from a focused state summary than from the raw implementation/debugging trail. Do not use this as a reflexive final step after delivering the finished work; use it before validation, the next phase, the next attempt, or the next user task.
60
60
 
61
61
  ```javascript
62
- context_rewind({
62
+ context_compact({
63
63
  target: "parser-fix-start",
64
- message: "Parser fix is implemented and the debugging phase is complete. Reason: compacting implementation history before focused validation. Next step: run targeted validation and summarize remaining edge cases.",
64
+ summary: "Current task: validate the parser fix. State: implementation is done and the debugging trail can be summarized. External state: parser implementation and related tests were changed on disk; context navigation did not revert them. Validation not yet run after final edit. Next step: run targeted validation and summarize remaining edge cases.",
65
65
  backupCheckpoint: "parser-fix-debug-history"
66
66
  });
67
67
  ```