An image counted as half a million tokens: the context estimate measured its base64 as text, so a 1-3 MB screenshot read as "context at 150-280%" the moment view_image added it, and the session compacted after every image. An image now counts by its dimensions (28 px patches, at most 16k tokens, a flat 1600 when unreadable) everywhere the CLI estimates -- the meter, pruning, /context and the no-usage fallback of all five dialects. Images over 1600 px or 500 KB are shrunk to 1600 px when ImageMagick is there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
12 files changed
+196
-18
No files matched your search
@@ -16,7 +16,7 @@ import { fill, promptText } from "../prompt/assemble.ts"
|
||||
import { resolveCall } from "../tool/names.ts"
|
||||
import { contextWindow } from "../provider/discover.ts"
|
||||
import { summaryTurns, type Store } from "./store.ts"
|
||||
import { estimateTokens } from "../provider/tokens.ts"
|
||||
import { estimateTokens, estimateValue } from "../provider/tokens.ts"
|
||||
import { duration } from "../duration.ts"
|
||||
|
||||
export interface EngineOptions {
|
||||
@@ -244,7 +244,7 @@ export class Engine {
|
||||
* last reply's output but will not be in the next request. */
|
||||
contextUsed(): number | undefined {
|
||||
if (!this.usage) return undefined
|
||||
return this.usage.input + this.usage.output - this.droppedThinking() + estimateTokens(JSON.stringify(this.messages.slice(this.usageAt)))
|
||||
return this.usage.input + this.usage.output - this.droppedThinking() + estimateValue(this.messages.slice(this.usageAt))
|
||||
}
|
||||
|
||||
private droppedThinking(): number {
|
||||
@@ -262,7 +262,7 @@ export class Engine {
|
||||
let saved = 0
|
||||
for (let i = this.messages.length - 1; i >= 0; i--) {
|
||||
const m = this.messages[i]!
|
||||
const size = estimateTokens(JSON.stringify(m))
|
||||
const size = estimateValue(m)
|
||||
if (recent < protect) {
|
||||
recent += size
|
||||
continue
|
||||
|
||||
Reference in new issue
Block a user