Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions .opencode/opencode.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -407,19 +407,26 @@
"npm": "@opencode/ai/providers/mistral",
"name": "Mistral API (drewrypope)"
// Credential: the enrolled server credential (integration
// "mistral", Bitwarden mistral.api-key); MISTRAL_API_KEY is also
// materialized into the server unit's environment (home/common).
// "mistral", Bitwarden mistral.api-key) — the only source.
// MISTRAL_API_KEY is deliberately NOT materialized into the
// server environment: vibe-direct's env-first resolution would
// spend this API-budget key (see home/common, opencode#1653).
// "models": maintained by sync-models in the runtime overlay (~/.local/state/opencode/opencode-runtime.jsonc) — see code#4544.
},
"vibe-direct": {
"npm": "@opencode/ai/providers/vibe",
"name": "Mistral Vibe Direct (native wire clone)",
// 2026-11-04 (opencode#1653, PR #1661): native in-fork emulation of
// the mistral-vibe binary — same Mistral wire, Vibe's presets and
// the attribution stamp (metadata.call_source "vibe_code", the
// metering key for the Vibe quota marts). No vibe subprocess.
// Credential: MISTRAL_API_KEY in the server unit's environment
// (vibe-auth resolution: config -> env -> ~/.vibe/.env -> keyring).
// the attribution stamp (metadata.call_source "vibe_code"; billing
// follows the KEY, not the stamp — see the credential note).
// No vibe subprocess.
// Credential: vibe-auth resolution mirrors the binary (config ->
// env -> ~/.vibe/.env -> keyring) and the server env must NOT
// carry MISTRAL_API_KEY: that key is the API-budget key and
// Mistral meters per key, so with the env slot empty vibe-direct
// falls through to the keyring "ai.mistral.vibe" sign-in key —
// the Vibe plan key.
// Models are declared HERE: models.dev has no vibe entry, so
// sync-models cannot maintain this catalog. The entries are the
// preset ids + names from Vibe's own catalog (opencode#1653).
Expand Down Expand Up @@ -1793,13 +1800,14 @@
},
// mistral-plan (2026-11-04, Drew): the Mistral pair as ONE
// provider route — vibe-direct attempted first on every dispatch
// (the Vibe-attributed leg: metadata.call_source "vibe_code"),
// the plain Mistral API provider the reserve; the API leg serves
// only when vibe-direct fails or is demoted. Both legs resolve
// the same Bitwarden mistral.api-key credential (the vibe leg via
// MISTRAL_API_KEY in the server environment, the API leg via the
// enrolled "mistral" integration credential). Change the leg
// order HERE, in this providers list, and nowhere else.
// (the Vibe plan leg), the plain Mistral API provider the
// reserve; the API leg serves only when vibe-direct fails or is
// demoted. The legs use DIFFERENT keys by design (corrected
// 2026-11-06): Mistral meters per key — vibe-direct's keyring
// sign-in key bills the Vibe plan budget; the API leg's enrolled
// "mistral" integration credential bills the account API budget.
// Change the leg order HERE, in this providers list, and
// nowhere else.
"mistral-plan": {
"providers": ["vibe-direct", "mistral"],
"selection": "ordered"
Expand Down
41 changes: 26 additions & 15 deletions home/common/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1130,27 +1130,38 @@ in
};
};

# MISTRAL_API_KEY for the opencode server (opencode#1653): the value
# lives in Bitwarden (mistral.api-key), mirrored into sops and decrypted
# to /run/secrets/agent-auth/mistral-api-key (nixos/agent-auth). It must
# DEEPSEEK_API_KEY for the opencode server: the value lives in
# Bitwarden (deepseek.api-key), mirrored into sops and decrypted to
# /run/secrets/agent-auth/deepseek-api-key (nixos/agent-auth). It must
# never enter the Nix store, so an ExecStartPre materializes a
# systemd EnvironmentFile at every server start — the same pattern as
# openclaw-facade-auth-materialize in home/openclaw — and the unit reads
# it via EnvironmentFile. The vibe provider resolves the key from the
# server process env; the mistral provider's enrolled credential
# (integration "mistral") remains its primary source.
# The same materializer also writes DEEPSEEK_API_KEY (Bitwarden
# deepseek.api-key, via agent-auth/deepseek-api-key) into the same
# EnvironmentFile: it keys the deepseek provider's official-API leg
# (deepseek/deepseek-flash, "1017") in the deepseek-flash-plan route
# (Drew, direct order, 2026-11-05).
# systemd EnvironmentFile at every server start — the same pattern
# as openclaw-facade-auth-materialize in home/openclaw — and the
# unit reads it via EnvironmentFile. It keys the deepseek provider's
# official-API leg (deepseek/deepseek-flash, "1017") in the
# deepseek-flash-plan route (Drew, direct order, 2026-11-05).
#
# MISTRAL_API_KEY is deliberately NOT materialized here (removed
# 2026-11-06, root cause on opencode#1653). Mistral meters per KEY,
# not by call metadata: the Bitwarden mistral.api-key value is the
# account API key, billed to the API budget, while Vibe-plan usage
# is billed only when the Vibe sign-in key is used (OS keyring
# service "ai.mistral.vibe", from `vibe --setup`). vibe-direct
# resolves its credential exactly like the vibe binary — env
# MISTRAL_API_KEY first — so materializing the API key here
# silently rerouted all vibe-direct traffic onto the API budget:
# it burned the pool 16% -> 100% on 2026-11-05 and then walled the
# mistral-plan route. With no MISTRAL_API_KEY in the server env,
# vibe-direct falls through to the keyring plan key. The mistral
# provider is unaffected: its enrolled credential (integration
# "mistral") is its source — verified live 2026-11-06 (the leg
# returns the API-budget 402, not an auth error, with the env var
# absent).
systemd.user.services.opencode.Service = {
ExecStartPre = toString (
pkgs.writeShellScript "opencode-mistral-key-materialize" ''
pkgs.writeShellScript "opencode-env-key-materialize" ''
set -eu
umask 077
mkdir -p "$HOME/.local/state/opencode"
printf 'MISTRAL_API_KEY=%s\n' "$(cat /run/secrets/agent-auth/mistral-api-key)" > "$HOME/.local/state/opencode/mistral-api-key.env"
printf 'DEEPSEEK_API_KEY=%s\n' "$(cat /run/secrets/agent-auth/deepseek-api-key)" >> "$HOME/.local/state/opencode/mistral-api-key.env"
''
);
Expand Down