@astrosheep/pi-context 0.4.0 → 0.4.1
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 +1 -1
- package/package.json +1 -1
- package/src/index.ts +13 -7
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ The extension composes Pi's public `session_before_compact` / `session_compact`
|
|
|
20
20
|
|
|
21
21
|
- **`new_context` tool** — the model requests a fresh context window. The extension waits for the current tool turn to end, compacts with a short deterministic reset message (old conversation is excluded from the new provider context but stays in the session), then sends exactly one hidden continuation turn.
|
|
22
22
|
- **`<context_window>` hint** — persisted as a visible custom message at session start and after each window reset (Codex-style: written once into history instead of re-injected per request). It carries the agent name, first/current/previous window IDs, and the 5 most recently updated notes. Within a window the note list goes stale, exactly like Codex's steady-state world-state diffing.
|
|
23
|
-
- **Low-budget guidance** — while remaining context is at or below 16,000 tokens, a `<context_window_guidance>` reminder is
|
|
23
|
+
- **Low-budget guidance** — while remaining context is at or below 16,000 tokens, a `<context_window_guidance>` reminder is appended after the request messages on every call (transient single-shot would vanish from the next request; Codex's persisted reminder stays visible, so continuous low-budget injection is the effective parity). The text is static and appended (not prepended), so the provider's prefix cache survives: crossing the threshold adds one stable suffix segment instead of rewriting the prefix. The exact remaining figure is one `get_context_remaining` call away. Note: Pi's built-in auto-compaction fires when remaining context falls below `reserveTokens` (default 16,384), so raise the reminder threshold above your `reserveTokens` or the reminder never precedes compaction.
|
|
24
24
|
- **Runtime toggle** — `/pi-context off` disables hint injection, guidance, and reset-style compaction (Pi's default compaction, including `keepRecentTokens`, applies again). `/pi-context on` re-enables; a bare `/pi-context` reports the current state.
|
|
25
25
|
- **History tools** — the model searches pre-reset conversation with case-sensitive literal substring search, exactly like Codex's `history.*` namespace.
|
|
26
26
|
- **Notes tools** — persistent, session-scoped virtual files that survive window resets.
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -235,9 +235,13 @@ export function contextWindowHint(ctx: ExtensionContext): string {
|
|
|
235
235
|
return `${CONTEXT_WINDOW_OPEN_TAG}\n${lines.join("\n")}\n${CONTEXT_WINDOW_CLOSE_TAG}`;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
/**
|
|
239
|
-
|
|
240
|
-
|
|
238
|
+
/**
|
|
239
|
+
* Codex-equivalent low-budget reminder. Static by design: this text is injected on
|
|
240
|
+
* every request while below the threshold, so a varying token count would invalidate
|
|
241
|
+
* the provider's prefix cache on each call. The exact figure is one tool call away.
|
|
242
|
+
*/
|
|
243
|
+
function tokenBudgetGuidance(): string {
|
|
244
|
+
return `${GUIDANCE_OPEN_TAG}\nContext budget is at or below ${REMINDER_THRESHOLD_TOKENS} tokens remaining. Persist durable state with notes_write_file, then call new_context before the window closes. get_context_remaining reports the exact figure.\n${GUIDANCE_CLOSE_TAG}`;
|
|
241
245
|
}
|
|
242
246
|
|
|
243
247
|
function lineRange(text: string, startValue: unknown, stopValue: unknown) {
|
|
@@ -414,18 +418,20 @@ export default function piContext(pi: ExtensionAPI) {
|
|
|
414
418
|
|
|
415
419
|
pi.on("context", (event, ctx) => {
|
|
416
420
|
if (!enabled) return undefined;
|
|
417
|
-
// Transient
|
|
418
|
-
//
|
|
421
|
+
// Transient while below the threshold: Codex's reminder persists in history and
|
|
422
|
+
// stays visible, so continuous low-budget visibility is the effective parity.
|
|
423
|
+
// Appended (not prepended) with static text: the cached prefix stays untouched,
|
|
424
|
+
// crossing the threshold only adds one stable suffix segment.
|
|
419
425
|
const usage = ctx.getContextUsage();
|
|
420
426
|
if (!usage || usage.tokens === null) return undefined;
|
|
421
427
|
const remaining = Math.max(0, usage.contextWindow - usage.tokens);
|
|
422
428
|
if (remaining > REMINDER_THRESHOLD_TOKENS) return undefined;
|
|
423
429
|
const guidance = {
|
|
424
430
|
role: "user" as const,
|
|
425
|
-
content: [{ type: "text" as const, text: tokenBudgetGuidance(
|
|
431
|
+
content: [{ type: "text" as const, text: tokenBudgetGuidance() }],
|
|
426
432
|
timestamp: Date.now(),
|
|
427
433
|
};
|
|
428
|
-
return { messages: [
|
|
434
|
+
return { messages: [...event.messages, guidance] };
|
|
429
435
|
});
|
|
430
436
|
|
|
431
437
|
pi.registerTool(defineTool({
|