diff --git a/home/dot_config/opencode/opencode.jsonc.tmpl b/home/dot_config/opencode/opencode.jsonc.tmpl index 0e28199..b65577d 100644 --- a/home/dot_config/opencode/opencode.jsonc.tmpl +++ b/home/dot_config/opencode/opencode.jsonc.tmpl @@ -6,6 +6,9 @@ "@franlol/opencode-md-table-formatter@0.0.3", // "file:///home/xevion/projects/opencode-anthropic-websearch/dist/index.js" ], + "keybinds": { + "model_cycle_favorite": "ctrl+f" + }, "lsp": { "jdtls": { "disabled": true diff --git a/home/dot_local/state/opencode/modify_model.json b/home/dot_local/state/opencode/modify_model.json new file mode 100755 index 0000000..4a3efcb --- /dev/null +++ b/home/dot_local/state/opencode/modify_model.json @@ -0,0 +1,68 @@ +#!/bin/bash +# Ensure Anthropic 4.5 models are in OpenCode favorites + +SCRIPT=$(mktemp) +trap "rm -f $SCRIPT" EXIT + +cat > "$SCRIPT" <<'TYPESCRIPT' +import stableHash from "stable-hash@latest"; + +interface ModelRef { + providerID: string; + modelID: string; +} + +interface ModelState { + recent?: ModelRef[]; + favorite?: ModelRef[]; + variant?: Record; +} + +const REQUIRED_FAVORITES: ModelRef[] = [ + { providerID: "anthropic", modelID: "claude-haiku-4-5" }, + { providerID: "anthropic", modelID: "claude-opus-4-5" }, + { providerID: "anthropic", modelID: "claude-sonnet-4-5" }, +]; + +const originalText = await Bun.stdin.text(); +const hasTrailingNewline = originalText.endsWith('\n'); +const originalState: ModelState = originalText.trim() ? JSON.parse(originalText) : {}; +const originalHash = stableHash(originalState); + +const modifiedState: ModelState = JSON.parse(JSON.stringify(originalState)); + +if (!Array.isArray(modifiedState.favorite)) { + modifiedState.favorite = []; +} + +for (const required of REQUIRED_FAVORITES) { + const exists = modifiedState.favorite.some( + (fav) => fav.providerID === required.providerID && fav.modelID === required.modelID + ); + if (!exists) { + modifiedState.favorite.push(required); + } +} + +const modifiedHash = stableHash(modifiedState); + +// Only output changes if data actually changed +if (originalHash === modifiedHash) { + process.stdout.write(originalText); +} else { + // Preserve original formatting style (check for newlines in actual JSON, not trailing ones) + const isPrettified = originalText.trim().includes('\n'); + const output = isPrettified + ? JSON.stringify(modifiedState, null, 2) + : JSON.stringify(modifiedState); + + // Preserve trailing newline behavior + if (hasTrailingNewline) { + console.log(output); + } else { + process.stdout.write(output); + } +} +TYPESCRIPT + +exec bun "$SCRIPT"