Skip to content

Commit 5bb0fe4

Browse files
committed
fix: restore full context percentage limits
Refs #522
1 parent 6fd4a54 commit 5bb0fe4

5 files changed

Lines changed: 33 additions & 62 deletions

File tree

lib/hooks.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
stripHallucinationsFromString,
1414
stripStaleMetadata,
1515
syncCompressionBlocks,
16-
computeInputBudget,
1716
} from "./messages"
1817
import { renderSystemPrompt, type PromptStore } from "./prompts"
1918
import { buildProtectedToolsExtension } from "./prompts/extensions/system"
@@ -54,17 +53,11 @@ export function createSystemPromptHandler(
5453
prompts: PromptStore,
5554
) {
5655
return async (
57-
input: {
58-
sessionID?: string
59-
model: { limit: { context: number; input?: number; output?: number } }
60-
},
56+
input: { sessionID?: string; model: { limit: { context: number } } },
6157
output: { system: string[] },
6258
) => {
6359
if (input.model?.limit?.context) {
64-
const inputBudget = computeInputBudget(input.model.limit)
65-
if (inputBudget !== undefined) {
66-
state.modelContextLimit = inputBudget
67-
}
60+
state.modelContextLimit = input.model.limit.context
6861
logger.debug("Cached model context limit", { limit: state.modelContextLimit })
6962
}
7063

lib/messages/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
export { prune } from "./prune"
22
export { syncCompressionBlocks } from "./sync"
33
export { injectCompressNudges } from "./inject/inject"
4-
export { computeInputBudget } from "./inject/utils"
54
export { injectMessageIds } from "./inject/inject"
65
export { injectExtendedSubAgentResults } from "./inject/subagent-results"
76
export { stripStaleMetadata } from "./reasoning-strip"

lib/messages/inject/utils.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,6 @@ export interface LastNonIgnoredMessage {
3434
index: number
3535
}
3636

37-
interface ModelLimit {
38-
context: number
39-
input?: number
40-
output?: number
41-
}
42-
43-
export function computeInputBudget(limit: ModelLimit): number | undefined {
44-
if (!limit.context) {
45-
return undefined
46-
}
47-
48-
return limit.input ?? Math.max(0, limit.context - (limit.output ?? 0))
49-
}
50-
5137
export function getNudgeFrequency(config: PluginConfig): number {
5238
return Math.max(1, Math.floor(config.compress.nudgeFrequency || 1))
5339
}

tests/hooks-permission.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
createChatMessageTransformHandler,
66
createCommandExecuteHandler,
77
createEventHandler,
8+
createSystemPromptHandler,
89
createTextCompleteHandler,
910
} from "../lib/hooks"
1011
import { Logger } from "../lib/logger"
@@ -86,6 +87,36 @@ function buildMessage(id: string, role: "user" | "assistant", text: string): Wit
8687
}
8788
}
8889

90+
test("system prompt handler caches full model context for percentage thresholds", async () => {
91+
const state = createSessionState()
92+
const handler = createSystemPromptHandler(
93+
state,
94+
new Logger(false),
95+
buildConfig("deny"),
96+
{
97+
reload() {},
98+
getRuntimePrompts() {
99+
return {} as any
100+
},
101+
} as any,
102+
)
103+
104+
await handler(
105+
{
106+
sessionID: "session-1",
107+
model: {
108+
limit: {
109+
context: 200000,
110+
output: 131072,
111+
},
112+
},
113+
} as any,
114+
{ system: ["base system"] },
115+
)
116+
117+
assert.equal(state.modelContextLimit, 200000)
118+
})
119+
89120
test("chat message transform strips hallucinated tags even when compress is denied", async () => {
90121
const state = createSessionState()
91122
const logger = new Logger(false)

tests/input-budget.test.ts

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)