Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix: smart detection of OpenCode config path

yh ccfa971c882c3
diff --git a/ui/src/context/ApiContext.tsx b/ui/src/context/ApiContext.tsx
index 7daabc55f..29759d115 100644
--- a/ui/src/context/ApiContext.tsx
+++ b/ui/src/context/ApiContext.tsx
@@ -12,7 +12,7 @@ export type ApiContextType = {
slackManifest: () => Promise<{ ok: boolean; manifest?: string; manifest_compact?: string; error?: string }>;
doctor: () => Promise<any>;
opencodeOptions: (cwd: string) => Promise<any>;
- opencodeSetupPermission: () => Promise<{ ok: boolean; message: string; config_paths: string[] }>;
+ opencodeSetupPermission: () => Promise<{ ok: boolean; message: string; config_path: string }>;
getLogs: (lines?: number) => Promise<{ logs: LogEntry[]; total: number }>;
getVersion: () => Promise<VersionInfo>;
doUpgrade: () => Promise<UpgradeResult>;
diff --git a/vibe/api.py b/vibe/api.py
index 950f433ca..82b3e4075 100644
--- a/vibe/api.py
+++ b/vibe/api.py
@@ -435,48 +435,65 @@ def do_upgrade(auto_restart: bool = True) -> dict:
def setup_opencode_permission() -> dict:
- """Set OpenCode permission to 'allow' in config files.
+ """Set OpenCode permission to 'allow' in config file.
- Updates both ~/.config/opencode/opencode.json and ~/.opencode/opencode.json
- since OpenCode supports multiple config locations.
+ Detection priority:
+ 1. ~/.opencode/opencode.json - if exists, update it
+ 2. ~/.config/opencode/opencode.json - if exists, update it
+ 3. Create new file at ~/.config/opencode/opencode.json (XDG standard)
Returns:
- {"ok": bool, "message": str, "config_paths": list[str]}
+ {"ok": bool, "message": str, "config_path": str}
"""
from pathlib import Path
- paths_to_update = [
- Path.home() / ".config" / "opencode" / "opencode.json",
- Path.home() / ".opencode" / "opencode.json",
- ]
- updated = []
+ opencode_path = Path.home() / ".opencode" / "opencode.json"
+ xdg_path = Path.home() / ".config" / "opencode" / "opencode.json"
- for config_path in paths_to_update:
- try:
- config_path.parent.mkdir(parents=True, exist_ok=True)
-
- config = {}
- if config_path.exists():
- content = config_path.read_text(encoding="utf-8").strip()
- if content:
- parsed = json.loads(content)
- if isinstance(parsed, dict):
- config = parsed
-
- if config.get("permission") != "allow":
- config["permission"] = "allow"
- config_path.write_text(
- json.dumps(config, indent=2) + "\n", encoding="utf-8"
- )
+ # Determine which path to use
+ if opencode_path.exists():
+ config_path = opencode_path
+ elif xdg_path.exists():
+ config_path = xdg_path
+ else:
+ config_path = xdg_path # Default to XDG standard
+
+ try:
+ config_path.parent.mkdir(parents=True, exist_ok=True)
+
+ config = {}
+ if config_path.exists():
+ content = config_path.read_text(encoding="utf-8").strip()
+ if content:
+ config = json.loads(content)
+ if not isinstance(config, dict):
+ return {
+ "ok": False,
+ "message": "Config is not a JSON object",
+ "config_path": str(config_path),
+ }
+
+ if config.get("permission") == "allow":
+ return {
+ "ok": True,
+ "message": "Permission already set",
+ "config_path": str(config_path),
+ }
- updated.append(str(config_path))
- except Exception as e:
- logger.warning(f"Failed to update {config_path}: {e}")
+ config["permission"] = "allow"
+ config_path.write_text(json.dumps(config, indent=2) + "\n", encoding="utf-8")
- if updated:
return {
"ok": True,
- "message": f"Permission set in {len(updated)} config(s)",
- "config_paths": updated,
+ "message": "Permission set to 'allow'",
+ "config_path": str(config_path),
}
- return {"ok": False, "message": "Failed to update any config", "config_paths": []}
+ except json.JSONDecodeError as e:
+ return {
+ "ok": False,
+ "message": f"Invalid JSON: {e}",
+ "config_path": str(config_path),
+ }
+ except Exception as e:
+ logger.error(f"Failed to setup OpenCode permission: {e}")
+ return {"ok": False, "message": str(e), "config_path": str(config_path)}