chore(codex): route Codex to OpenCode Go without clobbering ChatGPT auth
The ChatGPT desktop app owns and rewrites ~/.codex/config.toml, so symlinking that file into the repo leaked the app's own config (model, [desktop], [plugins], [mcp_servers]) into git and got clobbered on launch. - Stop symlinking ~/.codex/config.toml; keep it app-owned and merge the repo fragment home/.codex/config.toml into it on every activation (home.activation.codexOpenCodeGo + home/bin/codex-opencode-go-sync). - Replace requires_openai_auth with a command-backed token (~/.local/bin/opencode-go-token reads the key from the opencode store), so ~/.codex/auth.json stays in ChatGPT mode and ChatGPT sign-in coexists with Go. - Add the Codex 0.160+ profile file home/.codex/luna.config.toml (gpt-6-luna). - Declare the chatgpt + codex casks; document the decision in AGENTS.md. Verified: default deepseek-v4.1-flash and --profile luna both return over the Go Responses API while auth.json remains in chatgpt mode.
This commit is contained in:
1 parent
1f13c6eb1a
commit
6e0bc81e85
8 files changed
+152
No files matched your search
Executable
+66
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Reconcile the OpenCode Go fragment into Codex's live config.
|
||||
|
||||
Codex (the ChatGPT desktop app and the CLI) both read ~/.codex/config.toml, and
|
||||
the ChatGPT app owns and rewrites that file. So home-manager must not symlink it.
|
||||
Instead this script merges the repo fragment (argv[1]) into the live file
|
||||
(argv[2]) on every activation:
|
||||
|
||||
* only the keys the fragment defines are forced (fragment wins),
|
||||
* the whole model_providers.opencode-go table is replaced, so stale keys such
|
||||
as a previous `requires_openai_auth = true` are dropped,
|
||||
* everything the app wrote itself ([desktop], [plugins], [mcp_servers],
|
||||
[marketplaces], ...) is preserved.
|
||||
|
||||
Run with a Python that has tomlkit (home.activation.codexOpenCodeGo does).
|
||||
"""
|
||||
|
||||
import copy
|
||||
import os
|
||||
import sys
|
||||
|
||||
import tomlkit
|
||||
|
||||
|
||||
def _table(doc, key):
|
||||
if key not in doc:
|
||||
doc[key] = tomlkit.table()
|
||||
return doc[key]
|
||||
|
||||
|
||||
def main() -> int:
|
||||
fragment_path, live_path = sys.argv[1], sys.argv[2]
|
||||
|
||||
with open(fragment_path) as fh:
|
||||
fragment = tomlkit.parse(fh.read())
|
||||
|
||||
if os.path.exists(live_path):
|
||||
with open(live_path) as fh:
|
||||
live = tomlkit.parse(fh.read())
|
||||
else:
|
||||
live = tomlkit.document()
|
||||
|
||||
# Root keys the fragment owns.
|
||||
for key in ("model", "model_provider"):
|
||||
if key in fragment:
|
||||
live[key] = fragment[key]
|
||||
|
||||
# Replace the fragment provider tables wholesale (drops stale keys).
|
||||
incoming = fragment.get("model_providers") or {}
|
||||
target = _table(live, "model_providers")
|
||||
for name, table in incoming.items():
|
||||
target[name] = copy.deepcopy(table)
|
||||
|
||||
# Codex 0.160+ rejects the legacy [profiles.*] table; profiles now live in
|
||||
# $CODEX_HOME/<name>.config.toml. Drop one if an older config left it behind.
|
||||
if "profiles" in live:
|
||||
del live["profiles"]
|
||||
|
||||
with open(live_path, "w") as fh:
|
||||
fh.write(tomlkit.dumps(live))
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
# Print the OpenCode Go API key on stdout.
|
||||
#
|
||||
# Codex uses this as its command-backed provider auth
|
||||
# ([model_providers.opencode-go.auth].command). That keeps ~/.codex/auth.json
|
||||
# untouched in ChatGPT mode, so the ChatGPT desktop app and the OpenCode Go
|
||||
# subscription coexist in the same Codex install. The key is never committed; it
|
||||
# is read live from the opencode auth store (the same source oc2 and Hermes use).
|
||||
set -eu
|
||||
|
||||
auth="${XDG_DATA_HOME:-$HOME/.local/share}/opencode/auth.json"
|
||||
py="$(command -v python3 || true)"
|
||||
if [ -z "$py" ]; then
|
||||
py=/usr/bin/python3
|
||||
fi
|
||||
|
||||
exec "$py" -c 'import json, sys; print(json.load(open(sys.argv[1]))["opencode-go"]["key"])' "$auth"
|
||||
Reference in new issue
Block a user