pi-context 1.1.4 → 2.0.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.
@@ -0,0 +1,75 @@
1
+ # Development and Troubleshooting
2
+
3
+ Use this reference for long-running:
4
+ - implementation
5
+ - debugging
6
+ - troubleshooting
7
+ - refactoring
8
+ - migration
9
+ - review or audit work
10
+
11
+ These tasks often stay cleaner when treated as stages with anchors, instead of one uninterrupted thread. If multiple alternative approaches, failed branches, or route comparisons become central, also read `retry-branch-and-pivot.md`.
12
+
13
+ ## Working pattern
14
+
15
+ 1. Create a checkpoint before starting serious work.
16
+ 2. Add checkpoints before risky edits, new approaches, or major phase changes.
17
+ 3. Review the timeline when you need to understand the current shape of the work.
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
+
20
+ ## Typical checkpoint moments
21
+
22
+ Checkpoint:
23
+ - before starting implementation
24
+ - before a risky refactor
25
+ - before trying an alternative fix
26
+ - after a milestone like "root cause confirmed" or "first pass implemented"
27
+ - before switching to a side task
28
+
29
+ Example checkpoint names:
30
+ - `parser-fix-start`
31
+ - `cache-refactor-attempt-2`
32
+ - `migration-plan-ready`
33
+ - `incident-root-cause-confirmed`
34
+
35
+ ## Timeline review moments
36
+
37
+ Run `context_timeline` when:
38
+ - multiple attempts now exist
39
+ - the task moved from diagnosis to implementation
40
+ - you are about to abandon one approach and restart from another anchor
41
+ - you are unsure which checkpoint best represents the clean continuation point
42
+
43
+ ## Compact patterns
44
+
45
+ ### After a failed attempt
46
+
47
+ Use compact when an attempt clearly failed and you have a crisp summary of why.
48
+
49
+ ```javascript
50
+ context_compact({
51
+ target: "memory-leak-fix-start",
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
+ backupCheckpoint: "memory-leak-weakref-raw-history"
54
+ });
55
+ ```
56
+
57
+ ### After a completed phase
58
+
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
+
61
+ ```javascript
62
+ context_compact({
63
+ target: "parser-fix-start",
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
+ backupCheckpoint: "parser-fix-debug-history"
66
+ });
67
+ ```
68
+
69
+ ## Warning signs
70
+
71
+ Switch into stronger context-management behavior when:
72
+ - you are accumulating many partial theories
73
+ - the thread contains multiple fix attempts
74
+ - you keep revisiting earlier reasoning
75
+ - the next step is clear but the path behind it is getting noisy
@@ -0,0 +1,81 @@
1
+ # Planning and Execution
2
+
3
+ Use this reference when the work is organized around an explicit execution frame, such as:
4
+ - a formal implementation or migration plan
5
+ - a roadmap with multiple milestones
6
+ - a lightweight todo list or checklist
7
+ - staged execution that will be revisited, updated, or reordered across many turns
8
+
9
+ The defining feature here is not just that the work has phases. It is that execution repeatedly returns to an explicit plan, roadmap, or todo baseline.
10
+
11
+ ## Two common variants
12
+
13
+ ### Formal plan
14
+ Examples:
15
+ - a plan produced by a planning step or planning agent
16
+ - a migration plan with several services or phases
17
+ - a rollout plan with checkpoints and validation steps
18
+
19
+ ### Lightweight todo / checklist
20
+ Examples:
21
+ - a short task list for a refactor
22
+ - a checklist for a release or audit
23
+ - a small execution outline that will be worked through item by item
24
+
25
+ Both variants use the same context-management rhythm.
26
+
27
+ ## Working pattern
28
+
29
+ 1. Create or confirm the plan / todo list.
30
+ 2. Create a checkpoint for the clean plan-ready state.
31
+ 3. Execute one subtask or phase.
32
+ 4. If that subtask becomes noisy, let it get noisy locally.
33
+ 5. Once the subtask produces a stable takeaway and another subtask or phase remains, compact to the anchor that gives the next subtask the cleanest sufficient working set, often the plan-ready or phase-start anchor.
34
+ 6. Continue with the next subtask from that focused working set.
35
+ 7. If the plan changes materially, checkpoint the updated plan state again.
36
+ 8. If the last subtask completes the user's whole request, give the final answer without an automatic compact; decide on cleanup at the next user message if the conversation continues.
37
+
38
+ ## Useful anchors
39
+
40
+ Example checkpoint names:
41
+ - `auth-migration-plan-ready`
42
+ - `release-rollout-plan-ready`
43
+ - `parser-refactor-todo-baseline`
44
+ - `cleanup-phase-2-start`
45
+ - `vendor-audit-milestone-1`
46
+
47
+ ## When to review timeline
48
+
49
+ Run `context_timeline` when:
50
+ - several subtasks have already been executed
51
+ - the plan has changed more than once
52
+ - multiple branches now exist under the same plan
53
+ - you are unsure whether the next subtask needs the overall plan, the current phase context, or only a summary
54
+
55
+ ## When to compact
56
+
57
+ Compact when:
58
+ - a subtask is complete, another subtask remains, and its raw execution path is no longer worth keeping active
59
+ - a phase finished and the next phase should start from a cleaner state
60
+ - the plan remains valid but the current execution segment has become noisy
61
+ - a later user message starts a new task after the plan-driven task completed noisily
62
+
63
+ Do not compact just because a todo list exists. Compact when a specific execution segment has already served its purpose and can be compacted for an actual continuation. If the segment changed files, launched/stopped processes, or updated external systems, record those side effects in the summary; context navigation does not revert them.
64
+
65
+ ## Replan
66
+
67
+ If the plan itself changes materially:
68
+ 1. finish or abandon the current noisy segment
69
+ 2. summarize the change in direction
70
+ 3. checkpoint the new plan-ready state
71
+ 4. continue from the updated plan anchor
72
+
73
+ If the plan change is driven by failed branches or strategy shifts, also read `retry-branch-and-pivot.md`.
74
+
75
+ ## Common mistakes
76
+
77
+ Avoid:
78
+ - keeping every finished subtask's raw reasoning active instead of preserving only the reusable state
79
+ - choosing an anchor that drops the current plan state without preserving it in the summary
80
+ - failing to checkpoint the updated plan after a major replan
81
+ - confusing repeated-item work with plan-driven work when the subtasks are actually different in nature
@@ -0,0 +1,69 @@
1
+ # Repeated Items and Batch Work
2
+
3
+ Use this reference when the work involves many similar items handled over many turns, such as:
4
+ - repeated cases
5
+ - repeated tickets
6
+ - repeated reviews
7
+ - repeated checks
8
+ - repeated fix attempts on similar inputs
9
+
10
+ Use this reference when the items are similar enough that the same method should be reused across them. If the subtasks are heterogeneous and anchored to a roadmap or todo baseline, use `planning-and-execution.md` instead.
11
+
12
+ ## Working pattern
13
+
14
+ 1. Create a checkpoint at the start of the overall repeated-item task.
15
+ 2. If item 1 teaches you a reusable approach, checkpoint again after that approach becomes clear.
16
+ 3. Work item by item.
17
+ 4. Compact after each completed item or completed mini-phase when another item remains and the raw path is no longer worth carrying forward.
18
+ 5. Use timeline occasionally to verify that the history still has a clean structure.
19
+
20
+ For repeated-item work, the default between-item move is not "keep carrying the last item's raw reasoning". Once an item is done, its takeaway is stable, and another item remains, compact to the repeated-work anchor or other baseline that preserves the reusable method without item-specific noise. If the last item completes the whole user request, deliver the final answer and wait for the next user message before deciding whether to compact.
21
+
22
+ ## Useful anchors
23
+
24
+ Example checkpoint names:
25
+ - `vendor-review-start`
26
+ - `vendor-review-method-clear`
27
+ - `ticket-triage-batch-start`
28
+ - `ticket-triage-pattern-1-confirmed`
29
+
30
+ ## When to review timeline
31
+
32
+ Run `context_timeline` when:
33
+ - several items have already been processed
34
+ - item-level work has created multiple branches or compactions
35
+ - you want to confirm that the overall pattern still looks clean
36
+ - you are about to choose which anchor repeated work should keep returning to
37
+
38
+ ## When to compact
39
+
40
+ Compact after:
41
+ - a representative item produced a reusable method and the batch will continue
42
+ - a single item is complete, another item remains, and the raw path should be compacted
43
+ - an item-specific dead end is understood and should not remain active in full
44
+ - a new user message arrives after the batch completed, and the batch's raw path is stale baggage for the new task
45
+
46
+ ## Example rhythm
47
+
48
+ ```javascript
49
+ context_checkpoint({ name: "vendor-review-start" });
50
+
51
+ // ... work through first representative item ...
52
+
53
+ context_checkpoint({ name: "vendor-review-method-clear" });
54
+
55
+ // ... process another item ...
56
+
57
+ context_compact({
58
+ target: "vendor-review-method-clear",
59
+ summary: "Current task: continue the vendor review batch. State: one more vendor review is complete; item-specific reasoning no longer needs to stay raw. Reusable method remains the active baseline. Next step: process the next vendor using the same method.",
60
+ backupCheckpoint: "vendor-review-item-7-history"
61
+ });
62
+ ```
63
+
64
+ ## Warning signs
65
+
66
+ Use stronger checkpoint/timeline/compact discipline when:
67
+ - each item creates lots of local reasoning
68
+ - you are starting to confuse one item's path with another's
69
+ - the repeated work is stretching across many turns
@@ -0,0 +1,71 @@
1
+ # Retry, Branch, and Pivot
2
+
3
+ Use this reference when multiple approaches are being tried and abandoned cleanly, such as:
4
+ - trying A / B / C approaches
5
+ - failed branches that should not pollute the main line
6
+ - compare-and-choose work
7
+ - strategy pivots or goal shifts
8
+ - restarting from a focused working set after a dead end
9
+
10
+ This is a **cross-cutting pattern reference**. Read it alongside a primary reference such as search/research, development/troubleshooting, or planning/execution when branch behavior becomes central.
11
+
12
+ ## Working pattern
13
+
14
+ 1. Checkpoint before opening a risky branch or alternative path.
15
+ 2. Explore or implement that branch.
16
+ 3. If anchor choice becomes unclear, inspect timeline.
17
+ 4. Once the branch produces a stable lesson, decision, or dead-end, compact to the anchor that removes branch noise while preserving the state needed for the next attempt.
18
+ 5. Continue with the next branch or the chosen direction from that focused state.
19
+
20
+ ## When to review timeline
21
+
22
+ Run `context_timeline` when:
23
+ - multiple branches now exist
24
+ - you are unsure which branch actually stayed useful
25
+ - you need to choose which pre-branch or older anchor gives the next attempt the best working set
26
+ - the next direction is clear but the old branch still clutters active context
27
+
28
+ ## When to compact
29
+
30
+ Compact when:
31
+ - a branch clearly failed
32
+ - a comparison is complete and one option won
33
+ - the direction changed enough that the old path is now baggage
34
+ - the next attempt should start from a focused state rather than the raw failed branch
35
+
36
+ ## Strategy pivot
37
+
38
+ Use this pattern when the old direction no longer makes sense even though the task is still continuing.
39
+
40
+ Examples:
41
+ - the original approach is no longer viable
42
+ - the user's priority changed
43
+ - the scope narrowed or widened enough that old execution noise is now baggage
44
+
45
+ In these cases:
46
+ - summarize what still matters
47
+ - compact to the anchor that removes the stale branch while preserving current task state
48
+ - continue under the new direction
49
+
50
+ ## Example rhythm
51
+
52
+ ```javascript
53
+ context_checkpoint({ name: "oauth-fix-start" });
54
+
55
+ // ... try cookie-based approach ...
56
+
57
+ context_compact({
58
+ target: "oauth-fix-start",
59
+ summary: "Current task: continue the OAuth fix with a new approach. State: cookie-based approach is not viable because the callback flow loses session continuity. Decision: switch to signed state tokens. Next step: implement the signed-state approach.",
60
+ backupCheckpoint: "oauth-cookie-approach-history"
61
+ });
62
+ context_checkpoint({ name: "oauth-signed-state-start" });
63
+ ```
64
+
65
+ ## Common mistakes
66
+
67
+ Avoid:
68
+ - opening alternative branches without a clean checkpoint first
69
+ - dragging failed branches forward after their lesson is already clear
70
+ - compacting to a point that still includes the branch you meant to abandon
71
+ - treating every branch as equally worth preserving
@@ -0,0 +1,103 @@
1
+ # Search, Research, and Reading
2
+
3
+ Use this reference when the work is mainly driven by large amounts of input material, such as:
4
+ - searching
5
+ - research
6
+ - web search
7
+ - browser-driven information gathering
8
+ - reading many files, logs, docs, webpages, or web results
9
+ - review-heavy reading
10
+ - comparison-heavy reading
11
+ - audit or inspection across many sources
12
+
13
+ This reference is for **input-heavy work where the process is much larger than the final conclusion**. It is especially relevant for web search and browser/page reading, where the information density is often low and the raw trail becomes stale quickly. If the main anchor is an explicit plan or todo list, use `planning-and-execution.md` instead.
14
+
15
+ ## Working pattern
16
+
17
+ 1. Create a checkpoint before a large search or reading loop.
18
+ 2. Search, browse, read, inspect, and follow leads normally.
19
+ 3. If you lose orientation, review the timeline.
20
+ 4. Once the investigation yields a stable finding and there is another step to take, compact to the anchor that gives the next step a focused working set.
21
+ 5. Continue with the conclusion, recommendation, or next action instead of carrying the entire raw exploration forward. If the finding is the final answer to the user's current request, answer first and wait; compact on the next user message if it starts new work.
22
+
23
+ Do not stop at "I already made a checkpoint" if the investigation phase is complete and the conversation is continuing. The cleanup move for completed research is usually a compact to the anchor that preserves only the raw context the next step still needs.
24
+
25
+ **Important:** “another step” includes the next phase of the same request. If you searched to find the right data source, previous task record, API shape, rule id, or query pattern, then the next execution step (running the real query/export, implementing, validating, etc.) is an immediate continuation. Compact before that execution step, not only before a future user message.
26
+
27
+ ## When to checkpoint
28
+
29
+ Checkpoint:
30
+ - before the first big search pass
31
+ - before opening a browser-heavy or webpage-heavy reading pass
32
+ - before diving into a new evidence branch
33
+ - after a stable intermediate conclusion
34
+ - before changing investigation direction
35
+
36
+ Example checkpoint names:
37
+ - `incident-search-start`
38
+ - `vendor-review-evidence-branch`
39
+ - `api-timeout-investigation-midpoint`
40
+
41
+ ## When to review timeline
42
+
43
+ Run `context_timeline` when:
44
+ - you have followed several leads
45
+ - you are no longer sure what the main anchor is
46
+ - the investigation has already produced multiple checkpoints
47
+ - you are deciding which path should be compacted
48
+
49
+ ## When to compact
50
+
51
+ Compact after the investigation produces one of these and there is a continuation that benefits from cleanup:
52
+ - a stable root cause
53
+ - a stable comparison result
54
+ - a dead-end conclusion
55
+ - a shortlist of viable next actions
56
+ - a located data source, old conversation, schema, rule id, query/API pattern, or other fact that unlocks execution
57
+
58
+ If you already have one of these, the investigation phase is usually complete enough to compact. If the next step is to use the finding in another tool call, compact first. If there is no continuation yet because you are about to give the final answer, wait until the next user message before deciding.
59
+
60
+ Do not compact in the middle of a still-open search loop just because the thread feels busy.
61
+
62
+ ## Message quality for research compactions
63
+
64
+ Research compactions are especially sensitive to summary quality. The raw exploration may contain details that become important later, but returning to the backup branch is a context switch. Preserve the state needed to use the finding, not the whole journey.
65
+
66
+ Include:
67
+ - **Current task/state:** what the research unlocked and how it will be used next
68
+ - **Finding:** what is now known
69
+ - **Source anchors:** key files, URLs, docs, sessions, commands, queries, or records used to reach the finding
70
+ - **Evidence:** important numbers, errors, examples, IDs, or constraints that support the finding
71
+ - **Rejected leads:** only expensive dead ends that future-you should not repeat
72
+ - **Open questions:** what is still uncertain
73
+ - **Next step:** what to do immediately after compact
74
+ - **Backup pointer:** if `backupCheckpoint` is set, when to return to it
75
+
76
+ Do not compress research to only “found the answer”. That forces future-you to either trust an unsupported conclusion or switch back to the backup for basic details.
77
+
78
+ ## Typical rhythm
79
+
80
+ ```javascript
81
+ context_checkpoint({ name: "timeout-investigation-start" });
82
+
83
+ // ... search logs, read code, compare docs, inspect outputs ...
84
+
85
+ // Stable finding found and the next action is execution/validation, so compact before continuing.
86
+ context_timeline();
87
+
88
+ context_compact({
89
+ target: "timeout-investigation-start",
90
+ backupCheckpoint: "timeout-investigation-raw-history",
91
+ summary: "Current task: plan mitigation for API timeouts. State: DB connection pool exhaustion is the likely root cause. Evidence: logs show pool wait timeouts during peak traffic; config has pool size 10; no network errors found in the checked logs. Rejected lead: API gateway timeout was downstream of DB waits, not the origin. Backup: timeout-investigation-raw-history if exact log lines are needed. Next step: propose mitigation and validation steps."
92
+ });
93
+ ```
94
+
95
+ ## Good compact outcomes
96
+
97
+ After compacting, you should be able to continue with:
98
+ - the finding
99
+ - the recommendation
100
+ - the next verification step
101
+ - the next narrower investigation
102
+
103
+ You should not still need the whole raw trail in active context unless the investigation is still ongoing.
@@ -0,0 +1,72 @@
1
+ # Task Switching and Cleanup
2
+
3
+ Use this reference when the main problem is not the task domain itself, but a change in thread state, such as:
4
+ - the user inserts a temporary side task
5
+ - the user starts a new task after a completed noisy task
6
+ - you need to pause one line of work and resume it later
7
+ - several active fronts now exist
8
+ - the thread is already messy and needs cleanup before continuing
9
+ - a finished noisy phase should be summarized and left behind before new work starts
10
+
11
+ This reference is for **pause/resume, cleanup, and clean continuation**. It is not for repeated similar items or plan-driven execution.
12
+
13
+ ## Three common variants
14
+
15
+ ### Interruption / task switch
16
+ Use when you are actively switching away from one line of work and intend to come back.
17
+
18
+ ### Completed-task handoff
19
+ Use when a previous task is complete, the user has now said something new, and the previous task's raw path is noisy enough that it should not be carried into the new work.
20
+
21
+ ### Cleanup and continue
22
+ Use when the thread is already stale or messy and you want to compress it now, even though context management is being adopted late.
23
+
24
+ ## Working pattern
25
+
26
+ 1. Inspect timeline if anchor choice is unclear.
27
+ 2. Before switching away or compacting a noisy path, preserve or choose the anchor that will give the resumed/new task a clean working set.
28
+ 3. If needed, create a backup checkpoint for the current noisy branch.
29
+ 4. If the user has just started a new task after a completed noisy task, compact before doing the new task so the completed task becomes a compact summary rather than active baggage.
30
+ 5. Handle the side task or cleanup move.
31
+ 6. Compact away the stale path when the handoff summary is clear.
32
+ 7. Resume from the paused anchor or continue from the compacted state.
33
+
34
+ ## Useful anchors
35
+
36
+ Example checkpoint names:
37
+ - `primary-task-paused`
38
+ - `migration-mainline-paused`
39
+ - `release-investigation-paused`
40
+ - `cleanup-pre-noise-anchor`
41
+
42
+ ## When to review timeline
43
+
44
+ Run `context_timeline` when:
45
+ - multiple interruptions happened
46
+ - the pause lasted many turns
47
+ - several side-task branches now exist
48
+ - you are unsure which anchor gives the resumed/new task the right working set
49
+ - the thread is already messy and you need to find the right pre-noise checkpoint
50
+
51
+ ## When to compact
52
+
53
+ Compact when:
54
+ - the interruption created lots of noise
55
+ - the side task is done and should not stay active in full
56
+ - the user begins a new task after a completed noisy task and the previous raw path is no longer useful in full
57
+ - a stale path is making current reasoning worse
58
+ - the useful state is now much smaller than the accumulated process
59
+ - you can express the handoff clearly in a summary
60
+
61
+ Do not compact at the instant you finish a user-visible task if there is no known continuation. In that moment, deliver the answer and wait. If the next user message starts a new task, that is the right time to compact the completed task before proceeding. If the completed task changed files, browser state, tickets, or remote services, include those side effects in the handoff summary because the context move does not undo them. If the interruption was tiny and clean, a compact may be unnecessary. A checkpoint before switching away is still the key move.
62
+
63
+ ## Common mistakes
64
+
65
+ Avoid:
66
+ - switching away without a pause checkpoint
67
+ - compacting immediately after a final answer just because the task completed
68
+ - starting a new, unrelated user task while still carrying the previous task's full raw path
69
+ - returning to the main line while still carrying the side task's full raw path
70
+ - trying to clean up without first checking timeline when anchor choice is unclear
71
+ - resetting past still-valid near-term context without carrying it in the summary
72
+ - forgetting that files and external systems remain in their latest state after context navigation
package/src/context.ts CHANGED
@@ -2,8 +2,8 @@ import {
2
2
  type ExtensionAPI,
3
3
  type SessionManager,
4
4
  DynamicBorder,
5
- } from "@mariozechner/pi-coding-agent";
6
- import { Container, Text, Spacer } from "@mariozechner/pi-tui";
5
+ } from "@earendil-works/pi-coding-agent";
6
+ import { Container, Text, Spacer } from "@earendil-works/pi-tui";
7
7
  import { formatTokens } from "./utils.js";
8
8
 
9
9
  export default function (pi: ExtensionAPI) {
@@ -61,8 +61,9 @@ export default function (pi: ExtensionAPI) {
61
61
  const toolDefTokensRaw = estimateTokens(JSON.stringify(activeToolDefs));
62
62
  const totalActual = usage.tokens;
63
63
  const limit = usage.contextWindow;
64
+ const usagePercent = usage.percent;
64
65
 
65
- if (totalActual == null || limit == null || usage.percent == null) {
66
+ if (totalActual == null || limit == null || usagePercent == null) {
66
67
  ctx.ui.notify("Context usage info not available.", "warning");
67
68
  return;
68
69
  }
@@ -123,7 +124,7 @@ export default function (pi: ExtensionAPI) {
123
124
  gridLines.push(rowStr.trimEnd());
124
125
  }
125
126
 
126
- const totalUsageTitle = `${theme.fg("text", theme.bold("Total Usage".padEnd(16)))} ${theme.fg("text", theme.bold(formatTokens(totalActual).padStart(7)))} ${theme.fg("text", theme.bold(`(${usage.percent.toFixed(1).padStart(5)}%)`))}`;
127
+ const totalUsageTitle = `${theme.fg("text", theme.bold("Total Usage".padEnd(16)))} ${theme.fg("text", theme.bold(formatTokens(totalActual).padStart(7)))} ${theme.fg("text", theme.bold(`(${usagePercent.toFixed(1).padStart(5)}%)`))}`;
127
128
 
128
129
  const catDetailLines = categories.map(cat => {
129
130
  const labelStr = cat.label.padEnd(14);