refactor(pi): share session manager runtime registry

This commit is contained in:
Peter Steinberger
2026-02-15 17:39:10 +00:00
parent c6b3736fe7
commit 9084c4e345
4 changed files with 60 additions and 55 deletions

View File

@@ -1,4 +1,5 @@
import type { EffectiveContextPruningSettings } from "./settings.js";
import { createSessionManagerRuntimeRegistry } from "../session-manager-runtime-registry.js";
export type ContextPruningRuntimeValue = {
settings: EffectiveContextPruningSettings;
@@ -7,34 +8,10 @@ export type ContextPruningRuntimeValue = {
lastCacheTouchAt?: number | null;
};
// Session-scoped runtime registry keyed by object identity.
// Important: this relies on Pi passing the same SessionManager object instance into
// ExtensionContext (ctx.sessionManager) that we used when calling setContextPruningRuntime.
const REGISTRY = new WeakMap<object, ContextPruningRuntimeValue>();
const registry = createSessionManagerRuntimeRegistry<ContextPruningRuntimeValue>();
export function setContextPruningRuntime(
sessionManager: unknown,
value: ContextPruningRuntimeValue | null,
): void {
if (!sessionManager || typeof sessionManager !== "object") {
return;
}
export const setContextPruningRuntime = registry.set;
const key = sessionManager;
if (value === null) {
REGISTRY.delete(key);
return;
}
REGISTRY.set(key, value);
}
export function getContextPruningRuntime(
sessionManager: unknown,
): ContextPruningRuntimeValue | null {
if (!sessionManager || typeof sessionManager !== "object") {
return null;
}
return REGISTRY.get(sessionManager) ?? null;
}
export const getContextPruningRuntime = registry.get;