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(backends): emit inline-table dicts inside mixed TOML arrays

cyh80906172bd17
diff --git a/tests/test_codex_config.py b/tests/test_codex_config.py
index 743c9fec5..5edb658ce 100644
--- a/tests/test_codex_config.py
+++ b/tests/test_codex_config.py
@@ -152,6 +152,24 @@ def test_read_codex_api_key_missing_returns_none(tmp_path: Path) -> None:
assert codex_config.read_codex_api_key(home=tmp_path) is None
+def test_round_trip_mixed_array_with_inline_tables() -> None:
+ """``contributors = ["foo", { name = "bar" }]`` and similar mixed
+ arrays must keep the dict element as a TOML inline table — falling
+ through to ``json.dumps`` previously converted it into a quoted
+ JSON string, silently corrupting valid user-owned config."""
+ data = {
+ "contributors": ["foo", {"name": "bar", "role": "maintainer"}],
+ "plugins": [{"name": "first"}, {"name": "second", "enabled": True}, "raw-string"],
+ }
+ assert _round_trip(data) == data
+
+
+def test_round_trip_nested_inline_table() -> None:
+ """Inline tables can nest other inline tables."""
+ data = {"settings": ["a", {"nested": {"x": 1, "y": "two"}}]}
+ assert _round_trip(data) == data
+
+
def test_apply_api_key_pins_credentials_store_to_file(tmp_path: Path) -> None:
"""Codex's default ``cli_auth_credentials_store`` is ``auto`` (keyring-
preferred). When the UI writes an API key, the live process must
diff --git a/vibe/codex_config.py b/vibe/codex_config.py
index cca4dc164..fe2c9c1ad 100644
--- a/vibe/codex_config.py
+++ b/vibe/codex_config.py
@@ -123,6 +123,22 @@ def _is_table_array(value: Any) -> bool:
return isinstance(value, list) and bool(value) and all(isinstance(item, dict) for item in value)
+def _dump_toml_inline_table(data: Dict[str, Any]) -> str:
+ """Emit a dict as a TOML inline table: ``{ key = value, key2 = value2 }``.
+
+ Used for dict elements that appear inside arrays — TOML calls these
+ "inline tables" and they must stay single-line. Without this path,
+ ``_dump_toml_value`` would fall through to ``json.dumps`` and write
+ something like ``"{\\"name\\": \\"bar\\"}"`` — a quoted JSON string,
+ not a table — silently corrupting valid configs such as
+ ``contributors = ["foo", { name = "bar" }]``.
+ """
+ if not data:
+ return "{}"
+ parts = [f"{_format_toml_key(k)} = {_dump_toml_value(v)}" for k, v in data.items()]
+ return "{ " + ", ".join(parts) + " }"
+
+
def _dump_toml_value(value: Any) -> str:
"""Serialize a single scalar value back to TOML. Tables handled separately."""
if isinstance(value, bool):
@@ -144,6 +160,12 @@ def _dump_toml_value(value: Any) -> str:
return value.isoformat()
if isinstance(value, _dt.time):
return value.isoformat()
+ if isinstance(value, dict):
+ # Pure dict-only lists are routed through ``[[a.b]]`` array-of-
+ # tables emission in ``_dump_toml_table``, so reaching this branch
+ # means we're inside a mixed array (or an explicit inline-table
+ # value) — both of which TOML requires to stay single-line.
+ return _dump_toml_inline_table(value)
if isinstance(value, list):
return "[" + ", ".join(_dump_toml_value(item) for item in value) + "]"
# Fallback: serialize as JSON-ish string (best-effort for unexpected types).