From a9bf1c050544bbf8e7975e15f1cdcf1dbde23ce0 Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Thu, 5 Mar 2026 22:03:24 -0500 Subject: [PATCH] refactor: replace Bun.hash with Hash.fast using xxhash3-xxh64 --- packages/opencode/src/acp/agent.ts | 3 ++- packages/opencode/src/provider/provider.ts | 7 ++++--- packages/opencode/src/util/hash.ts | 7 +++++++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 packages/opencode/src/util/hash.ts diff --git a/packages/opencode/src/acp/agent.ts b/packages/opencode/src/acp/agent.ts index 8b338f1b5..d518dd12a 100644 --- a/packages/opencode/src/acp/agent.ts +++ b/packages/opencode/src/acp/agent.ts @@ -31,6 +31,7 @@ import { import { Log } from "../util/log" import { pathToFileURL } from "bun" import { Filesystem } from "../util/filesystem" +import { Hash } from "../util/hash" import { ACPSessionManager } from "./session" import type { ACPConfig } from "./types" import { Provider } from "../provider/provider" @@ -281,7 +282,7 @@ export namespace ACP { const output = this.bashOutput(part) const content: ToolCallContent[] = [] if (output) { - const hash = String(Bun.hash(output)) + const hash = Hash.fast(output) if (part.tool === "bash") { if (this.bashSnapshots.get(part.callID) === hash) { await this.connection diff --git a/packages/opencode/src/provider/provider.ts b/packages/opencode/src/provider/provider.ts index 817038365..b4836ae04 100644 --- a/packages/opencode/src/provider/provider.ts +++ b/packages/opencode/src/provider/provider.ts @@ -6,9 +6,10 @@ import { mapValues, mergeDeep, omit, pickBy, sortBy } from "remeda" import { NoSuchModelError, type Provider as SDK } from "ai" import { Log } from "../util/log" import { BunProc } from "../bun" +import { Hash } from "../util/hash" import { Plugin } from "../plugin" -import { ModelsDev } from "./models" import { NamedError } from "@opencode-ai/util/error" +import { ModelsDev } from "./models" import { Auth } from "../auth" import { Env } from "../env" import { Instance } from "../project/instance" @@ -795,7 +796,7 @@ export namespace Provider { const modelLoaders: { [providerID: string]: CustomModelLoader } = {} - const sdk = new Map() + const sdk = new Map() log.info("init") @@ -1085,7 +1086,7 @@ export namespace Provider { ...model.headers, } - const key = Bun.hash.xxHash32(JSON.stringify({ providerID: model.providerID, npm: model.api.npm, options })) + const key = Hash.fast(JSON.stringify({ providerID: model.providerID, npm: model.api.npm, options })) const existing = s.sdk.get(key) if (existing) return existing diff --git a/packages/opencode/src/util/hash.ts b/packages/opencode/src/util/hash.ts new file mode 100644 index 000000000..648148f93 --- /dev/null +++ b/packages/opencode/src/util/hash.ts @@ -0,0 +1,7 @@ +import { createHash } from "crypto" + +export namespace Hash { + export function fast(input: string | Buffer): string { + return createHash("xxhash3-xxh64").update(input).digest("hex") + } +}