Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

docs(evals): attach dsh to local SuperGrok OAuth

Cursor Agent67311f4ba7e8
diff --git a/graff-evals/README.md b/graff-evals/README.md
index dff41d67..351ad011 100644
--- a/graff-evals/README.md
+++ b/graff-evals/README.md
@@ -92,9 +92,15 @@ grok-build's heap or a 4-tool catalog (ADR 0024). First keep:
Add a harness by adding an entry; add a model by passing `--model`.
Same-model grok-4.6 series: `graff-dev`, `grok`, `opencode` (needs xAI
-auth), `dsh-grok` (needs `dsh` + an xAI key dsh will accept). Mixed-model
-native defaults — `opencode-zen`, `dsh-deepseek` — are a **different
-comparison**; do not read them as grok-4.6 list-price points.
+auth), `dsh-grok` (needs `dsh` + an xAI key dsh will accept; 0.1.1-rc.2
+catalog has no grok-4.6 — use `dsh-xai` / grok-4.5 for a live dsh point).
+Mixed-model native defaults — `opencode-zen`, `dsh-deepseek` — are a
+**different comparison**; do not read them as grok-4.6 list-price points.
+
+`dsh` does not read graff/grok OAuth files. On this machine the SuperGrok
+seat is attached locally (`python3 graff-evals/attach-dsh-xai-oauth.py
+--install`); see [dsh-local-oauth.md](dsh-local-oauth.md). No token is
+in git. `dsh-deepseek` still needs a DeepSeek key (none here).
## Tasks
diff --git a/graff-evals/attach-dsh-xai-oauth.py b/graff-evals/attach-dsh-xai-oauth.py
new file mode 100755
index 00000000..d53947d3
--- /dev/null
+++ b/graff-evals/attach-dsh-xai-oauth.py
@@ -0,0 +1,308 @@
+#!/usr/bin/env python3
+"""Attach the machine's SuperGrok OAuth seat to dsh. No secrets in git.
+
+dsh 0.1.1-rc.2 does not read ~/.xai/credentials/graff-oauth.json. Its xAI
+route is pi-ai catalog + apiKeyEnv: XAI_API_KEY (see dsh-xai.yml /
+dsh-grok.yml). This copies the already-logged-in graff/grok token into
+dsh's local store and optionally prints `export XAI_API_KEY=...` for the
+current shell. Tokens are never printed except via --export-env.
+
+Sources (first hit):
+ ~/.xai/credentials/graff-oauth.json graff login xai
+ ~/.grok/auth.json grok CLI (same public client)
+
+Writes (0600 under 0700 $DSH_HOME):
+ $DSH_HOME/.credentials.yaml
+ refs.XAI_API_KEY so --patch layers resolve
+ records.llm-pi-ai/xai pi-ai SuperGrok grant (refreshable)
+
+dsh-deepseek still needs DEEPSEEK_API_KEY. This script does not invent one.
+"""
+from __future__ import annotations
+
+import argparse
+import json
+import os
+import stat
+import sys
+import time
+import urllib.parse
+import urllib.request
+from pathlib import Path
+
+XAI_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828"
+XAI_TOKEN_URL = "https://auth.x.ai/oauth2/token"
+REFRESH_MARGIN_S = 300
+PI_REFRESH_SKEW_MS = 5 * 60 * 1000
+
+
+def _home() -> Path:
+ return Path(os.environ.get("HOME") or Path.home())
+
+
+def _dsh_home() -> Path:
+ raw = os.environ.get("DSH_HOME")
+ return Path(raw) if raw else _home() / ".dsh"
+
+
+def _yaml_sq(s: str) -> str:
+ return "'" + s.replace("'", "''") + "'"
+
+
+def _read_graff_oauth() -> dict | None:
+ path = _home() / ".xai" / "credentials" / "graff-oauth.json"
+ if not path.is_file():
+ return None
+ data = json.loads(path.read_text())
+ access = data.get("access_token")
+ if not isinstance(access, str) or not access:
+ return None
+ exp = data.get("expires_at")
+ expires_at = int(exp) if isinstance(exp, (int, float)) else 0
+ refresh = data.get("refresh_token") if isinstance(data.get("refresh_token"), str) else ""
+ return {
+ "access": access,
+ "refresh": refresh,
+ "expires_at": expires_at,
+ "path": path,
+ "source": "graff-oauth",
+ }
+
+
+def _read_grok_auth() -> dict | None:
+ path = _home() / ".grok" / "auth.json"
+ if not path.is_file():
+ return None
+ data = json.loads(path.read_text())
+ for key, entry in data.items():
+ if not isinstance(entry, dict):
+ continue
+ if not str(key).startswith("https://auth.x.ai::"):
+ continue
+ access = entry.get("key")
+ if not isinstance(access, str) or not access:
+ continue
+ refresh = entry.get("refresh_token") if isinstance(entry.get("refresh_token"), str) else ""
+ expires_at = 0
+ raw_exp = entry.get("expires_at")
+ if isinstance(raw_exp, str) and raw_exp:
+ try:
+ from datetime import datetime, timezone
+
+ expires_at = int(datetime.fromisoformat(raw_exp.replace("Z", "+00:00")).timestamp())
+ except ValueError:
+ expires_at = 0
+ return {
+ "access": access,
+ "refresh": refresh,
+ "expires_at": expires_at,
+ "path": path,
+ "source": "grok-auth",
+ }
+ return None
+
+
+def _refresh(cred: dict) -> dict:
+ refresh = cred.get("refresh") or ""
+ if not refresh:
+ return cred
+ body = urllib.parse.urlencode(
+ {
+ "client_id": XAI_CLIENT_ID,
+ "grant_type": "refresh_token",
+ "refresh_token": refresh,
+ }
+ ).encode()
+ req = urllib.request.Request(
+ XAI_TOKEN_URL,
+ data=body,
+ method="POST",
+ headers={
+ "Accept": "application/json",
+ "Content-Type": "application/x-www-form-urlencoded",
+ "User-Agent": "grok-cli/1.0",
+ },
+ )
+ try:
+ with urllib.request.urlopen(req, timeout=20) as resp:
+ parsed = json.loads(resp.read().decode())
+ except Exception as exc:
+ print(f"warn: xAI refresh failed ({type(exc).__name__}); using stored token", file=sys.stderr)
+ return cred
+ access = parsed.get("access_token")
+ if not isinstance(access, str) or not access:
+ print("warn: xAI refresh returned no access_token; using stored token", file=sys.stderr)
+ return cred
+ new_refresh = parsed.get("refresh_token") if isinstance(parsed.get("refresh_token"), str) else refresh
+ expires_in = parsed.get("expires_in")
+ if not isinstance(expires_in, (int, float)) or expires_in <= 0:
+ expires_in = 3600
+ cred = dict(cred)
+ cred["access"] = access
+ cred["refresh"] = new_refresh
+ cred["expires_at"] = int(time.time()) + int(expires_in)
+ if cred.get("source") == "graff-oauth":
+ path = cred["path"]
+ existing = json.loads(path.read_text()) if path.is_file() else {}
+ existing["access_token"] = access
+ existing["refresh_token"] = new_refresh
+ existing["expires_at"] = cred["expires_at"]
+ path.write_text(json.dumps(existing))
+ os.chmod(path, 0o600)
+ return cred
+
+
+def _maybe_refresh(cred: dict) -> dict:
+ exp = cred.get("expires_at") or 0
+ if exp and int(time.time()) >= exp - REFRESH_MARGIN_S:
+ return _refresh(cred)
+ return cred
+
+
+def _write_credentials(cred: dict, dsh_home: Path) -> Path:
+ dsh_home.mkdir(mode=0o700, exist_ok=True)
+ try:
+ os.chmod(dsh_home, 0o700)
+ except OSError:
+ pass
+ dest = dsh_home / ".credentials.yaml"
+ expires_ms = 0
+ if cred.get("expires_at"):
+ expires_ms = int(cred["expires_at"]) * 1000 - PI_REFRESH_SKEW_MS
+ lines = [
+ "version: 1",
+ "",
+ "refs:",
+ f" XAI_API_KEY: {_yaml_sq(cred['access'])}",
+ "",
+ "records:",
+ " llm-pi-ai/xai:",
+ " kind: grant",
+ " payload:",
+ " type: oauth",
+ f" access: {_yaml_sq(cred['access'])}",
+ f" refresh: {_yaml_sq(cred.get('refresh') or '')}",
+ f" expires: {expires_ms}",
+ "",
+ ]
+ dest.write_text("\n".join(lines) if lines[-1] == "" else "\n".join(lines) + "\n")
+ os.chmod(dest, 0o600)
+ return dest
+
+
+def _install_wrapper() -> Path:
+ wrapper = _home() / ".local" / "bin" / "dsh"
+ node = os.environ.get("NVM_BIN") or str(
+ Path.home() / ".nvm" / "versions" / "node" / "v22.22.2" / "bin"
+ )
+ node_bin = str(Path(node) / "node") if not node.endswith("node") else node
+ if not Path(node_bin).is_file():
+ # fall back to PATH node
+ import shutil
+
+ found = shutil.which("node")
+ node_bin = found or node_bin
+ dsh_js = _home() / ".local" / "node_modules" / "@deepseek-ai" / "dsh" / "lib" / "bin.js"
+ hook = _home() / ".local" / "bin" / "dsh-xai-from-graff-oauth"
+ wrapper.parent.mkdir(parents=True, exist_ok=True)
+ wrapper.write_text(
+ "#!/bin/sh\n"
+ f'export PATH="{Path(node_bin).parent}:$PATH"\n'
+ "# SuperGrok OAuth → XAI_API_KEY (machine-local; same seat as graff/grok)\n"
+ f'if [ -x "{hook}" ]; then\n'
+ f' eval "$("{hook}" --export-env 2>/dev/null)"\n'
+ "fi\n"
+ f'exec "{node_bin}" "{dsh_js}" "$@"\n'
+ )
+ os.chmod(wrapper, os.stat(wrapper).st_mode | stat.S_IXUSR)
+ return wrapper
+
+
+def _install_bashrc() -> None:
+ bashrc = _home() / ".bashrc"
+ marker = "# dsh SuperGrok OAuth (graff-evals/attach-dsh-xai-oauth.py)"
+ block = (
+ f"{marker}\n"
+ 'if [ -x "$HOME/.local/bin/dsh-xai-from-graff-oauth" ]; then\n'
+ ' eval "$("$HOME/.local/bin/dsh-xai-from-graff-oauth" --export-env 2>/dev/null)"\n'
+ "fi\n"
+ )
+ text = bashrc.read_text() if bashrc.is_file() else ""
+ if marker in text:
+ return
+ with bashrc.open("a") as f:
+ f.write("\n" + block)
+
+
+def _install_self() -> Path:
+ dest = _home() / ".local" / "bin" / "dsh-xai-from-graff-oauth"
+ dest.parent.mkdir(parents=True, exist_ok=True)
+ dest.write_text(Path(__file__).read_text())
+ os.chmod(dest, 0o755)
+ return dest
+
+
+def _status(cred: dict, dest: Path | None) -> None:
+ exp = cred.get("expires_at") or 0
+ left = (exp - int(time.time())) if exp else None
+ print(
+ f"ok: source={cred['source']} token_len={len(cred['access'])}"
+ + (f" expires_in_s={left}" if left is not None else ""),
+ file=sys.stderr,
+ )
+ if dest:
+ print(f"ok: wrote {dest} (refs.XAI_API_KEY + llm-pi-ai/xai grant)", file=sys.stderr)
+
+
+def main() -> int:
+ parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
+ parser.add_argument(
+ "--export-env",
+ action="store_true",
+ help="print `export XAI_API_KEY=...` for eval/source (the only path that emits the token)",
+ )
+ parser.add_argument(
+ "--install",
+ action="store_true",
+ help="install ~/.local/bin wrappers and a bashrc hook",
+ )
+ parser.add_argument(
+ "--status",
+ action="store_true",
+ help="print whether a local seat is attached (no token)",
+ )
+ args = parser.parse_args()
+
+ cred = _read_graff_oauth() or _read_grok_auth()
+ if cred is None:
+ print(
+ "error: no SuperGrok OAuth at ~/.xai/credentials/graff-oauth.json"
+ " or ~/.grok/auth.json — run `graff login xai` first",
+ file=sys.stderr,
+ )
+ return 2
+ cred = _maybe_refresh(cred)
+
+ if args.status:
+ _status(cred, None)
+ dest = _dsh_home() / ".credentials.yaml"
+ print(f"credentials_yaml={'yes' if dest.is_file() else 'no'}", file=sys.stderr)
+ print(f"process_XAI_API_KEY={'yes' if os.environ.get('XAI_API_KEY') else 'no'}", file=sys.stderr)
+ return 0
+
+ dest = _write_credentials(cred, _dsh_home())
+ if args.install:
+ self = _install_self()
+ wrap = _install_wrapper()
+ _install_bashrc()
+ print(f"ok: installed {self} and {wrap}", file=sys.stderr)
+ if not args.export_env:
+ _status(cred, dest)
+ return 0
+ # --export-env is the only stdout that carries the token; callers eval it.
+ sys.stdout.write("export XAI_API_KEY=" + _yaml_sq(cred["access"]) + "\n")
+ return 0
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())
diff --git a/graff-evals/dsh-grok.yml b/graff-evals/dsh-grok.yml
index 402979c3..1a3a482f 100644
--- a/graff-evals/dsh-grok.yml
+++ b/graff-evals/dsh-grok.yml
@@ -9,3 +9,6 @@
providers:
xai:
apiKeyEnv: XAI_API_KEY
+ headers:
+ # routing flag (not a secret); SuperGrok OAuth tokens need it
+ X-XAI-Token-Auth: xai-grok-cli
diff --git a/graff-evals/dsh-local-oauth.md b/graff-evals/dsh-local-oauth.md
new file mode 100644
index 00000000..8d73efd1
--- /dev/null
+++ b/graff-evals/dsh-local-oauth.md
@@ -0,0 +1,57 @@
+# dsh + local SuperGrok OAuth
+
+Sibling note for the eval-frontier live A/B (`dsh` / `dsh-xai` / `dsh-grok`).
+Machine config only — no secret is in this repo.
+
+## What dsh is
+
+[deepseek-ai/deepseek-harness](https://github.com/deepseek-ai/deepseek-harness)
+(`dsh` 0.1.1-rc.2 here). Official clone on this box: `/tmp/deepseek-harness`
+(not vendored). CLI is `~/.local/bin/dsh` → `@deepseek-ai/dsh`.
+
+It has **no SuperGrok login of its own**. Auth is:
+
+| route | credential |
+|---|---|
+| `dsh-xai` / `dsh-grok` | `XAI_API_KEY` (pi-ai xAI catalog) |
+| `dsh-deepseek` | `DEEPSEEK_API_KEY` — **not present**; do not invent one |
+| `dsh` (luna) | `OPENAI_API_KEY` — not this hook |
+
+pi-ai *can* store an xAI OAuth grant (`llm-pi-ai/xai`, same public client as
+`graff login xai`), but the harness patches name `apiKeyEnv: XAI_API_KEY`,
+so a missing env var is `MISSING_CREDENTIAL` even if a grant exists.
+
+## What was attached (this machine)
+
+Same seat graff and grok already use:
+
+- `~/.xai/credentials/graff-oauth.json`
+- `~/.grok/auth.json`
+
+```sh
+python3 graff-evals/attach-dsh-xai-oauth.py --install
+# or: eval "$(python3 graff-evals/attach-dsh-xai-oauth.py --export-env)"
+python3 graff-evals/attach-dsh-xai-oauth.py --status
+```
+
+That writes `$DSH_HOME/.credentials.yaml` (`0600`): `refs.XAI_API_KEY` plus a
+`llm-pi-ai/xai` grant. The `dsh` wrapper and `~/.bashrc` export `XAI_API_KEY`
+from the graff file so `run.py` inherits it. Refresh uses `auth.x.ai` and
+the same public client id; near-expiry updates the graff file in place.
+
+SuperGrok access tokens also need the **non-secret** routing header
+`X-XAI-Token-Auth: xai-grok-cli` (graff sends this for `.login` tokens;
+a bare Bearer is for a metered `XAI_API_KEY`). `dsh-xai.yml` and
+`dsh-grok.yml` set that header.
+
+## Live A/B
+
+Include **`dsh-xai`** (grok-4.5 — nearest id in dsh's pi-ai catalog).
+`dsh-grok` (grok-4.6) is `UNKNOWN_MODEL` on 0.1.1-rc.2. `dsh-deepseek`
+stays blocked until a DeepSeek key exists.
+
+```sh
+dsh --help
+dsh --profile headless --patch graff-evals/dsh-xai.yml "Reply with exactly: pong"
+./run.py --harness dsh-xai --task exact-reply
+```
diff --git a/graff-evals/dsh-xai.yml b/graff-evals/dsh-xai.yml
new file mode 100644
index 00000000..e42f56b8
--- /dev/null
+++ b/graff-evals/dsh-xai.yml
@@ -0,0 +1,16 @@
+# Nearest xAI model in dsh's vendored pi-ai catalog (0.1.1-rc.2).
+# That catalog has grok-4.5 / grok-4.3 / grok-build-0.1 — not grok-4.6.
+# Mixed-model point: do not read as the grok-4.6 same-model series.
+# XAI_API_KEY is attached locally from SuperGrok OAuth (see dsh-local-oauth.md).
+# X-XAI-Token-Auth is a routing flag, not a secret — graff sends it for login tokens.
+- id: agent-default-model
+ config:
+ provider: xai
+ model: grok-4.5
+- id: llm-pi-ai
+ config:
+ providers:
+ xai:
+ apiKeyEnv: XAI_API_KEY
+ headers:
+ X-XAI-Token-Auth: xai-grok-cli
diff --git a/graff-evals/harnesses.json b/graff-evals/harnesses.json
index 7bbebd08..952073b2 100644
--- a/graff-evals/harnesses.json
+++ b/graff-evals/harnesses.json
@@ -173,6 +173,15 @@
"capabilities": [],
"env": {"DSH_PERMISSION_MODE": "danger-full-access"},
"default_model": "grok-4.6",
- "note": "deepseek-ai/deepseek-harness same-model attempt: patch layer pins xai/grok-4.6. Needs `dsh` on PATH and an xAI credential dsh will accept. Native default is dsh-deepseek (different model)."
+ "note": "Same-model attempt. dsh 0.1.1-rc.2 pi-ai catalog has no grok-4.6 (only grok-4.5 / 4.3 / grok-build-0.1). Expect UNKNOWN_MODEL. Use dsh-xai for a live dsh point."
+ },
+ "dsh-xai": {
+ "cmd": ["dsh", "--profile", "headless", "--patch", "{repo}/graff-evals/dsh-xai.yml", "{prompt}"],
+ "answer": "stdout",
+ "usage": null,
+ "capabilities": [],
+ "env": {"DSH_PERMISSION_MODE": "danger-full-access"},
+ "default_model": "grok-4.5",
+ "note": "deepseek-harness on grok-4.5 (nearest xAI id in its catalog). NOT grok-4.6. Mixed-model chart only. Needs Node >=22.15 (zstd). SuperGrok OAuth → XAI_API_KEY via attach-dsh-xai-oauth.py (local; see dsh-local-oauth.md). No usage footer."
}
}