pi-plus 0.1.5 → 0.1.6
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 +8 -8
- package/package.json +3 -2
- package/src/index.ts +11 -18
- package/src/indicator.ts +0 -33
package/README.md
CHANGED
|
@@ -4,10 +4,10 @@ Claude Code-exact context usage detection for [pi](https://github.com/earendil-w
|
|
|
4
4
|
|
|
5
5
|
This extension measures pi's context usage with the **same arithmetic as Claude Code** —
|
|
6
6
|
usage-based prefix counting plus rough tail estimation, CC's context-window resolution,
|
|
7
|
-
and CC's warning thresholds. It
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
and CC's warning thresholds. It replaces pi's built-in footer so its context field
|
|
8
|
+
shows the plugin's CC-exact usage measured against the auto-compact threshold.
|
|
9
|
+
Optionally, it can also take over auto-compaction and fire `ctx.compact()` at CC's
|
|
10
|
+
auto-compact threshold.
|
|
11
11
|
|
|
12
12
|
## What it replicates (from Claude Code's source)
|
|
13
13
|
|
|
@@ -20,7 +20,6 @@ plugin's CC-exact usage. Optionally, it can also take over auto-compaction and f
|
|
|
20
20
|
| Context measurement: last API usage (input+cacheWrite+cacheRead+output) + chars/4 tail estimate; images/PDFs flat 2000 | `utils/tokens.ts`, `services/tokenEstimation.ts` | `src/usage.ts` |
|
|
21
21
|
| Statusline percentage excludes output tokens; raw window denominator | `utils/context.ts` | `src/percentages.ts` |
|
|
22
22
|
| Warning/error/blocking thresholds (20k/20k/3k buffers) | `services/compact/autoCompact.ts` | `src/percentages.ts` |
|
|
23
|
-
| Indicator text: dim `N% until auto-compact`, `Context low (N% remaining) · Run /compact to compact & continue` | `components/TokenWarning.tsx` | `src/indicator.ts` |
|
|
24
23
|
| Footer replication: cwd/branch line, token stats, model right side, extension-status line | `modes/interactive/components/footer.ts` | `src/footer-render.ts` |
|
|
25
24
|
|
|
26
25
|
This plugin supports **no Claude Code environment variables**
|
|
@@ -96,7 +95,7 @@ auto-compact and CC's autocompact use). The trigger is edge-triggered: it
|
|
|
96
95
|
fires once per crossing and re-arms after post-compact usage drops below the
|
|
97
96
|
threshold. Manual `/compact` keeps working.
|
|
98
97
|
|
|
99
|
-
Set `PI_PLUS_NO_AUTO_COMPACT=1` to disable the plugin's trigger (
|
|
98
|
+
Set `PI_PLUS_NO_AUTO_COMPACT=1` to disable the plugin's trigger (footer field only).
|
|
100
99
|
|
|
101
100
|
## Configuration
|
|
102
101
|
|
|
@@ -155,8 +154,9 @@ Set `PI_PLUS_NO_LOG=1` to disable it.
|
|
|
155
154
|
|
|
156
155
|
- With `customFooter` off (or replaced by another extension), pi's built-in
|
|
157
156
|
footer keeps showing its own `percent%` (raw-window denominator — a much
|
|
158
|
-
larger number for models like `kimi-for-coding` whose registry window is 1M)
|
|
159
|
-
|
|
157
|
+
larger number for models like `kimi-for-coding` whose registry window is 1M);
|
|
158
|
+
the plugin then has no on-screen display, only the log and the auto-compact
|
|
159
|
+
trigger.
|
|
160
160
|
- pi core owns the compaction cut point (keeps last ~20k tokens) — only the trigger
|
|
161
161
|
threshold is CC-exact.
|
|
162
162
|
- Exactness is guaranteed for Anthropic-style usage fields; other providers may map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-plus",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Claude Code-exact context usage detection for pi (extension)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"pi": {
|
|
@@ -44,7 +44,8 @@
|
|
|
44
44
|
],
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"@earendil-works/pi-ai": "*",
|
|
47
|
-
"@earendil-works/pi-coding-agent": "*"
|
|
47
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
48
|
+
"@earendil-works/pi-tui": "*"
|
|
48
49
|
},
|
|
49
50
|
"dependencies": {
|
|
50
51
|
"@juanibiapina/pi-extension-settings": "^0.10.0"
|
package/src/index.ts
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A pi extension that measures context usage with the same arithmetic as
|
|
5
5
|
* Claude Code (usage-based prefix count + rough tail estimation, CC's context
|
|
6
|
-
* window resolution and warning thresholds) and
|
|
7
|
-
*
|
|
6
|
+
* window resolution and warning thresholds) and shows it in the footer's
|
|
7
|
+
* context field via a custom footer. When pi's built-in auto-compaction is
|
|
8
8
|
* disabled, the plugin takes over and calls ctx.compact() at CC's
|
|
9
9
|
* auto-compact threshold (effective window − 13,000 tokens).
|
|
10
10
|
*
|
|
@@ -18,11 +18,9 @@ import { initialTriggerState, shouldFireAutoCompact, type AutoCompactTriggerStat
|
|
|
18
18
|
import { computePluginContextUsage } from "./context-usage.ts";
|
|
19
19
|
import { installFooter } from "./footer.ts";
|
|
20
20
|
import { isAutoCompactEnabled } from "./percentages.ts";
|
|
21
|
-
import { renderTokenWarning } from "./indicator.ts";
|
|
22
21
|
import { appendUsageLog } from "./logger.ts";
|
|
23
22
|
import { loadPiPlusSettings } from "./settings.ts";
|
|
24
23
|
|
|
25
|
-
const STATUS_KEY = "cc-context";
|
|
26
24
|
|
|
27
25
|
export default function (pi: ExtensionAPI) {
|
|
28
26
|
// Register our settings so they appear in the /extension-settings UI
|
|
@@ -95,12 +93,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
95
93
|
// re-arms automatically once post-compact usage drops below the threshold.
|
|
96
94
|
let compactTrigger: AutoCompactTriggerState = initialTriggerState();
|
|
97
95
|
|
|
98
|
-
function
|
|
96
|
+
function logUsageCheck(ctx: ExtensionContext): void {
|
|
99
97
|
const model = ctx.model;
|
|
100
|
-
if (!model)
|
|
101
|
-
if (ctx.hasUI) ctx.ui.setStatus(STATUS_KEY, undefined);
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
98
|
+
if (!model) return;
|
|
104
99
|
const settings = loadPiPlusSettings();
|
|
105
100
|
const computed = computePluginContextUsage(ctx, settings);
|
|
106
101
|
if (!computed) return;
|
|
@@ -116,8 +111,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
116
111
|
aboveAutoCompact: state.isAboveAutoCompactThreshold,
|
|
117
112
|
atBlockingLimit: state.isAtBlockingLimit,
|
|
118
113
|
});
|
|
119
|
-
if (!ctx.hasUI) return;
|
|
120
|
-
ctx.ui.setStatus(STATUS_KEY, renderTokenWarning(state, computed.autoCompactEnabled, ctx.ui.theme));
|
|
121
114
|
}
|
|
122
115
|
|
|
123
116
|
/**
|
|
@@ -163,17 +156,17 @@ export default function (pi: ExtensionAPI) {
|
|
|
163
156
|
pi.on("session_start", (_event, ctx) => {
|
|
164
157
|
compactTrigger = initialTriggerState();
|
|
165
158
|
installFooter(ctx);
|
|
166
|
-
|
|
159
|
+
logUsageCheck(ctx);
|
|
167
160
|
maybeAutoCompact(ctx);
|
|
168
161
|
});
|
|
169
|
-
pi.on("turn_end", (_event, ctx) =>
|
|
170
|
-
pi.on("agent_settled", (_event, ctx) =>
|
|
162
|
+
pi.on("turn_end", (_event, ctx) => logUsageCheck(ctx));
|
|
163
|
+
pi.on("agent_settled", (_event, ctx) => logUsageCheck(ctx));
|
|
171
164
|
// Check token overflow on every tool task finish.
|
|
172
165
|
pi.on("tool_execution_end", (_event, ctx) => {
|
|
173
|
-
|
|
166
|
+
logUsageCheck(ctx);
|
|
174
167
|
maybeAutoCompact(ctx);
|
|
175
168
|
});
|
|
176
|
-
pi.on("message_end", (_event, ctx) =>
|
|
177
|
-
pi.on("model_select", (_event, ctx) =>
|
|
178
|
-
pi.on("session_compact", (_event, ctx) =>
|
|
169
|
+
pi.on("message_end", (_event, ctx) => logUsageCheck(ctx));
|
|
170
|
+
pi.on("model_select", (_event, ctx) => logUsageCheck(ctx));
|
|
171
|
+
pi.on("session_compact", (_event, ctx) => logUsageCheck(ctx));
|
|
179
172
|
}
|
package/src/indicator.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Port of Claude Code's TokenWarning indicator (src/components/TokenWarning.tsx),
|
|
3
|
-
* adapted for a permanent footer status line.
|
|
4
|
-
*
|
|
5
|
-
* Rendering rules (auto-compact reactive/collapse modes omitted — ant-only):
|
|
6
|
-
* - below the warning threshold: dim "N% until auto-compact" (CC renders nothing
|
|
7
|
-
* here, but a status line should always show the current usage)
|
|
8
|
-
* - auto-compact on: dim "N% until auto-compact"
|
|
9
|
-
* - auto-compact off: "Context low (N% remaining) · Run /compact to compact & continue",
|
|
10
|
-
* warning color, or error color once past the error threshold / blocking limit
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import type { TokenWarningState } from "./percentages.ts";
|
|
14
|
-
|
|
15
|
-
/** Structural subset of pi's Theme — avoids a hard pi-tui dependency. */
|
|
16
|
-
export interface ThemeLike {
|
|
17
|
-
fg(color: string, text: string): string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function renderTokenWarning(
|
|
21
|
-
state: TokenWarningState,
|
|
22
|
-
autoCompactEnabled: boolean,
|
|
23
|
-
theme: ThemeLike,
|
|
24
|
-
): string | undefined {
|
|
25
|
-
if (autoCompactEnabled) {
|
|
26
|
-
return theme.fg("dim", `${state.percentLeft}% until auto-compact`);
|
|
27
|
-
}
|
|
28
|
-
if (!state.isAboveWarningThreshold) {
|
|
29
|
-
return theme.fg("dim", `${state.percentLeft}% remaining`);
|
|
30
|
-
}
|
|
31
|
-
const color = state.isAboveErrorThreshold || state.isAtBlockingLimit ? "error" : "warning";
|
|
32
|
-
return theme.fg(color, `Context low (${state.percentLeft}% remaining) · Run /compact to compact & continue`);
|
|
33
|
-
}
|