From 3d3276e9c498f3f4f0a1fabb033e33d99d05c156 Mon Sep 17 00:00:00 2001 From: jmug Date: Fri, 20 Nov 2026 12:56:06 -0800 Subject: [PATCH] [opencode] Set up config for v2 with WandB inference. --- home-modules/opencode-config.nix | 104 ++++++++++++++++++++++++++----- 1 file changed, 87 insertions(+), 17 deletions(-) diff --git a/home-modules/opencode-config.nix b/home-modules/opencode-config.nix index 32cf53f..fc71d0f 100644 --- a/home-modules/opencode-config.nix +++ b/home-modules/opencode-config.nix @@ -1,19 +1,89 @@ -{ ... } : { - home.file.".config/opencode/opencode.jsonc" = { - text = '' - { - "$schema": "https://opencode.ai/config.json", - "permission": { - "edit": "ask", - "webfetch": "ask", - "bash": { - "git status": "allow", - "git diff": "allow", - "ls": "allow", - "pwd": "allow" - } - } - } - ''; +{ ... }: +let + # W&B Inference (CoreWeave), OpenAI-compatible. + # The API key is NOT in this repo. Put it on each machine with: + # mkdir -p ~/.keys && install -m 600 /dev/stdin ~/.keys/wandb + # (paste the key, then Ctrl-D) + # NOTE: opencode refuses to start if a {file:...} reference is missing. + wandbTokenFile = "~/.keys/wandb"; + + # Model IDs from https://docs.coreweave.com/inference/models (Nov 2026). + # Prices are $/1M tokens, input/output. + wandbModels = { + # Quality. + "zai-org/GLM-5.3" = { name = "GLM 5.3"; context = 1048576; }; # $0.75/$3.00 + "moonshotai/Kimi-K2.7-Code" = { name = "Kimi K2.7 Code"; context = 262144; }; # $0.60/$3.00 + "deepseek-ai/DeepSeek-V4-Pro-0813" = { name = "DeepSeek V4 Pro"; context = 1048576; }; # $1.31/$3.96 + # Balanced. + "deepseek-ai/DeepSeek-V4.1-Flash-1017" = { name = "DeepSeek V4.1 Flash 1017"; context = 1048576; }; # $0.30/$1.20 + "MiniMaxAI/MiniMax-M3" = { name = "MiniMax M3"; context = 262144; }; # $0.23/$0.96 + # Speed. + "zai-org/GLM-5.3-Flash" = { name = "GLM 5.3 Flash"; context = 1048576; }; # $0.12/$0.38 + "nvidia/NVIDIA-Nemotron-3.5-Lightning-30B-A3B" = { name = "Nemotron 3.5 Lightning"; context = 262144; }; # $0.07/$0.20 }; + + fastModel = "wandb/zai-org/GLM-5.3-Flash"; + + rule = action: resource: effect: { inherit action resource effect; }; + + # Last matching rule wins; unmatched checks default to "ask". + # `opencode --auto` (alias: oca) turns every "ask" into "allow", but "deny" + # is still enforced, so the deny list below is the guardrail for auto mode. + permissions = [ + # Normal (non-auto) mode: prompt for edits and fetches. + (rule "edit" "*" "ask") + (rule "webfetch" "*" "ask") + (rule "shell" "git status *" "allow") + (rule "shell" "git diff *" "allow") + (rule "shell" "git log *" "allow") + (rule "shell" "ls *" "allow") + (rule "shell" "pwd" "allow") + + # Hard denies, in every mode. + (rule "shell" "sudo *" "deny") + (rule "shell" "git push *--force*" "deny") + (rule "shell" "git push * -f" "deny") + (rule "shell" "git push * -f *" "deny") + (rule "shell" "git push -f *" "deny") + (rule "shell" "git reset --hard *" "deny") + (rule "shell" "git clean *" "deny") + (rule "shell" "rm -rf /*" "deny") + (rule "shell" "rm -rf ~*" "deny") + ] ++ builtins.concatMap (dir: [ + (rule "read" dir "deny") + (rule "edit" dir "deny") + ]) [ "~/.keys/*" "~/.ssh/*" "~/.aws/*" "~/.config/sops/*" ]; + + opencodeConfig = { + "$schema" = "https://opencode.ai/config.json"; + + model = "wandb/zai-org/GLM-5.3"; + # Cheap background calls. + agents = { + title.model = fastModel; + summary.model = fastModel; + }; + + providers.wandb = { + name = "W&B Inference"; + package = "@opencode/ai/providers/openai-compatible"; + settings = { + baseURL = "https://api.inference.wandb.ai/v1"; + apiKey = "{file:${wandbTokenFile}}"; + }; + # "/" to bill against. Required when the account is in + # several teams; the default entity (coreweave1) rejects this key. + headers."OpenAI-Project" = "cw-wb/at"; + models = builtins.mapAttrs (_: m: { + inherit (m) name; + limit = { inherit (m) context; output = 32768; }; + }) wandbModels; + }; + + inherit permissions; + }; +in { + home.file.".config/opencode/opencode.jsonc".text = builtins.toJSON opencodeConfig; + + programs.zsh.shellAliases.oca = "opencode --auto"; }