mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 10:45:22 +00:00
feat: unify context compaction
This commit is contained in:
@@ -45,7 +45,7 @@ Accepted false values: `0`, `false`, `no`, `off` (case-insensitive).
|
||||
|
||||
## How it works
|
||||
|
||||
The footer reads context usage from the last assistant message's token counts (free — comes with every LLM response). Subscription usage is fetched from each provider's dedicated quota API using your existing auth tokens from `~/.pi/agent/auth.json` or environment variables.
|
||||
The footer reads effective context usage from the read-only `pi-compaction` service so its gauge matches provider projection and compaction decisions. Before the first projection snapshot exists it safely falls back to the last assistant message's token counts. Subscription usage is fetched from each provider's dedicated quota API using your existing auth tokens from `~/.pi/agent/auth.json` or environment variables.
|
||||
|
||||
Usage is fetched:
|
||||
|
||||
|
||||
@@ -893,6 +893,16 @@ export default function (pi: ExtensionAPI) {
|
||||
const contextWindow = model?.contextWindow ?? 0;
|
||||
if (contextWindow === 0) return { percentage: 0, used: 0, total: 0 };
|
||||
|
||||
const effective = (globalThis as any)[Symbol.for("my-pi.pi-compaction.service.v1")]
|
||||
?.getMetrics(ctx.sessionManager.getSessionId());
|
||||
if (effective) {
|
||||
return {
|
||||
percentage: effective.percent,
|
||||
used: effective.effectiveTokens,
|
||||
total: effective.contextWindow || contextWindow,
|
||||
};
|
||||
}
|
||||
|
||||
const entries = ctx.sessionManager.getEntries();
|
||||
const leafId = ctx.sessionManager.getLeafId();
|
||||
const context = buildSessionContext(entries, leafId);
|
||||
|
||||
Reference in New Issue
Block a user