diff --git a/packages/codemode/src/token.ts b/packages/codemode/src/token.ts deleted file mode 100644 index 1e06bec1e4..0000000000 --- a/packages/codemode/src/token.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** - * Token estimation for budgeting model-facing text. Copied from - * `@opencode-ai/core/util/token` (chars / 4) so this package stays - * dependency-free; keep the two in sync if the heuristic ever changes. - */ -export * as Token from "./token.js" - -const CHARS_PER_TOKEN = 4 - -export const estimate = (input: string) => Math.max(0, Math.round(input.length / CHARS_PER_TOKEN)) diff --git a/packages/codemode/src/tool-runtime.ts b/packages/codemode/src/tool-runtime.ts index 9d0c1ea4bd..0135a2ae8f 100644 --- a/packages/codemode/src/tool-runtime.ts +++ b/packages/codemode/src/tool-runtime.ts @@ -10,9 +10,10 @@ import { outputTypeScript, type Definition, } from "./tool.js" -import { estimate } from "./token.js" import { SandboxDate, SandboxMap, SandboxPromise, SandboxRegExp, SandboxSet } from "./values.js" +const estimateTokens = (input: string) => Math.max(0, Math.round(input.length / 4)) + export type HostTool = (...args: Array) => Effect.Effect export type HostTools = { @@ -438,7 +439,7 @@ export const discoveryPlan = ( picked: new Set(), queue: [...group].sort( (left, right) => - estimate(catalogLine(left)) - estimate(catalogLine(right)) || left.path.localeCompare(right.path), + estimateTokens(catalogLine(left)) - estimateTokens(catalogLine(right)) || left.path.localeCompare(right.path), ), })) let used = 0 @@ -447,7 +448,7 @@ export const discoveryPlan = ( const stillActive: typeof active = [] for (const selection of active) { const tool = selection.queue[0]! - const cost = estimate(catalogLine(tool)) + const cost = estimateTokens(catalogLine(tool)) if (used + cost > maxInlineCatalogTokens) continue selection.queue.shift() selection.picked.add(tool)