Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions extensions/context-pivot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ export default function contextPivot(pi: ExtensionAPI) {
});
};

pi.on("session_start", () => {
setVisibleForContext();
pi.on("session_start", (_event, ctx) => {
setVisibleForContext(ctx);
});

pi.on("agent_start", (_event, ctx) => {
Expand Down
21 changes: 17 additions & 4 deletions tests/extensions/context-pivot/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import contextPivot, {
MIN_CONTEXT_PIVOT_TOKENS,
} from "../../../extensions/context-pivot/index.ts";

test("context_pivot is visible only when the next run starts above its threshold", () => {
test("context_pivot visibility follows session and run context usage", () => {
let active = ["read", "third_party_tool"];
const handlers = new Map<
string,
Expand All @@ -36,9 +36,20 @@ test("context_pivot is visible only when the next run starts above its threshold
registerCommand() {},
} as unknown as ExtensionAPI;
contextPivot(pi);
for (const handler of handlers.get("session_start") ?? []) {
handler({}, {} as ExtensionContext);
}
const emitSessionStart = (tokens: number | null) => {
const ctx = {
getContextUsage: () => ({
tokens,
contextWindow: 200_000,
percent: tokens === null ? null : (tokens / 200_000) * 100,
}),
} as unknown as ExtensionContext;
for (const handler of handlers.get("session_start") ?? []) {
handler({}, ctx);
}
};

emitSessionStart(null);
assert.deepEqual(active, ["read", "third_party_tool"]);

const emitAgentStart = (tokens: number | null) => {
Expand All @@ -56,6 +67,8 @@ test("context_pivot is visible only when the next run starts above its threshold

emitAgentStart(29_999);
assert.deepEqual(active, ["read", "third_party_tool"]);
emitSessionStart(30_000);
assert.deepEqual(active, ["read", "third_party_tool", "context_pivot"]);
emitAgentStart(30_000);
assert.deepEqual(active, ["read", "third_party_tool", "context_pivot"]);
emitAgentStart(2_000);
Expand Down
Loading