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(opencode): handle inline closing brace updates

cyhaa3206595eee
diff --git a/tests/test_ui_api.py b/tests/test_ui_api.py
index f3db4666d..7fcedc060 100644
--- a/tests/test_ui_api.py
+++ b/tests/test_ui_api.py
@@ -308,6 +308,32 @@ def test_setup_opencode_permission_preserves_comments_when_updating_existing_per
}
+def test_setup_opencode_permission_handles_multiline_object_with_inline_closing_brace(monkeypatch, tmp_path):
+ config_path = tmp_path / ".config" / "opencode" / "opencode.json"
+ config_path.parent.mkdir(parents=True, exist_ok=True)
+ config_path.write_text(
+ """{
+ "model": "openai/gpt-5"}""",
+ encoding="utf-8",
+ )
+
+ monkeypatch.setattr(api.Path, "home", lambda: tmp_path)
+
+ result = api.setup_opencode_permission()
+ updated_text = config_path.read_text(encoding="utf-8")
+
+ assert result["ok"] is True
+ assert result["config_path"] == str(config_path)
+ assert updated_text == """{
+ "model": "openai/gpt-5",
+ "permission": "allow"
+}"""
+ assert parse_jsonc_object(updated_text) == {
+ "model": "openai/gpt-5",
+ "permission": "allow",
+ }
+
+
def test_setup_opencode_permission_skips_comment_only_file_and_uses_next_valid_path(monkeypatch, tmp_path):
xdg_path = tmp_path / ".config" / "opencode" / "opencode.json"
legacy_path = tmp_path / ".opencode" / "opencode.json"
diff --git a/vibe/opencode_config.py b/vibe/opencode_config.py
index 997b4f1cf..5e31057c8 100644
--- a/vibe/opencode_config.py
+++ b/vibe/opencode_config.py
@@ -327,6 +327,7 @@ def set_jsonc_top_level_string_property(source: str, key: str, value: str) -> st
child_indent = first_property_indent or (root_indent + " ")
property_text = f'{json.dumps(key)}: {serialized_value}'
has_multiline_layout = "\n" in source[root_start:root_end]
+ closing_brace_on_own_line = source[closing_line_start:root_end].strip() == ""
if not properties:
if has_multiline_layout:
@@ -353,11 +354,19 @@ def set_jsonc_top_level_string_property(source: str, key: str, value: str) -> st
if insertion_point > last_property.value_end:
insertion_point += 1
- if has_multiline_layout:
+ if has_multiline_layout and closing_brace_on_own_line:
suffix = "," if trailing_comma else ""
insertion = f"{child_indent}{property_text}{suffix}{newline}"
return updated_source[:insertion_point] + insertion + updated_source[insertion_point:]
+ if has_multiline_layout:
+ insertion_point = root_end
+ if not trailing_comma:
+ insertion_point += 1
+ suffix = "," if trailing_comma else ""
+ insertion = f"{newline}{child_indent}{property_text}{suffix}{newline}{root_indent}"
+ return updated_source[:insertion_point] + insertion + updated_source[insertion_point:]
+
def load_first_opencode_user_config(
*,