rivonasi 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,35 @@
1
+ Metadata-Version: 2.4
2
+ Name: rivonasi
3
+ Version: 0.2.0
4
+ Summary: Claude Code-style terminal coding & automation agent with 112+ MCP servers and multi-key rotation
5
+ Author: Biplop Devkota
6
+ Requires-Python: >=3.11
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: textual>=1.0.0
9
+ Requires-Dist: httpx>=0.27.0
10
+ Requires-Dist: httpx2>=2.10.0
11
+ Requires-Dist: rich>=13.0.0
12
+ Requires-Dist: mcp>=2.0.0
13
+ Requires-Dist: python-dotenv>=1.0.0
14
+
15
+ # Rivonasi
16
+
17
+ Terminal coding & automation agent by **Biplop Devkota** (`@devkotabiplop10`).
18
+
19
+ ## Install via pip (PyPI / Wheel — No Git Needed)
20
+
21
+ ```bash
22
+ pip install rivonasi
23
+ ```
24
+
25
+ Or install directly from the built wheel file:
26
+
27
+ ```bash
28
+ pip install rivonasi-0.2.0-py3-none-any.whl
29
+ ```
30
+
31
+ Then run anywhere:
32
+
33
+ ```bash
34
+ rivonasi
35
+ ```
@@ -0,0 +1,21 @@
1
+ # Rivonasi
2
+
3
+ Terminal coding & automation agent by **Biplop Devkota** (`@devkotabiplop10`).
4
+
5
+ ## Install via pip (PyPI / Wheel — No Git Needed)
6
+
7
+ ```bash
8
+ pip install rivonasi
9
+ ```
10
+
11
+ Or install directly from the built wheel file:
12
+
13
+ ```bash
14
+ pip install rivonasi-0.2.0-py3-none-any.whl
15
+ ```
16
+
17
+ Then run anywhere:
18
+
19
+ ```bash
20
+ rivonasi
21
+ ```
@@ -0,0 +1,26 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "rivonasi"
7
+ version = "0.2.0"
8
+ description = "Claude Code-style terminal coding & automation agent with 112+ MCP servers and multi-key rotation"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ authors = [{ name = "Biplop Devkota" }]
12
+ dependencies = [
13
+ "textual>=1.0.0",
14
+ "httpx>=0.27.0",
15
+ "httpx2>=2.10.0",
16
+ "rich>=13.0.0",
17
+ "mcp>=2.0.0",
18
+ "python-dotenv>=1.0.0",
19
+ ]
20
+
21
+ [project.scripts]
22
+ rivonasi = "rivonasi.cli:main"
23
+ rivonasi-mcp = "rivonasi.mcp_server:main"
24
+
25
+ [tool.setuptools.packages.find]
26
+ include = ["rivonasi*"]
@@ -0,0 +1,3 @@
1
+ """Rivonasi — OpenCode-style Terminal Agent & Antigravity MCP Server."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,100 @@
1
+ from __future__ import annotations
2
+
3
+ import shutil
4
+ import subprocess
5
+ from pathlib import Path
6
+
7
+ from mcp.server.mcpserver import MCPServer
8
+
9
+ mcp = MCPServer("antigravity")
10
+
11
+
12
+ def _find_agy() -> str | None:
13
+ agy = shutil.which("agy")
14
+ if agy:
15
+ return agy
16
+ fallback = Path.home() / ".gemini" / "bin" / "agy.exe"
17
+ return str(fallback) if fallback.is_file() else None
18
+
19
+
20
+ @mcp.tool()
21
+ def agy_ask(prompt: str, working_dir: str | None = None) -> str:
22
+ """Run a prompt or task using the Antigravity CLI (agy -p)."""
23
+ agy = _find_agy()
24
+ if not agy:
25
+ return "Antigravity CLI (agy.exe) not found on this machine."
26
+ cwd = working_dir or str(Path.cwd())
27
+ proc = subprocess.run(
28
+ [agy, "-p", prompt],
29
+ cwd=cwd,
30
+ capture_output=True,
31
+ text=True,
32
+ timeout=120,
33
+ )
34
+ out = (proc.stdout or "") + (f"\n[stderr]\n{proc.stderr}" if proc.stderr else "")
35
+ return out.strip() or f"(exit {proc.returncode})"
36
+
37
+
38
+ @mcp.tool()
39
+ def agy_list_skills() -> str:
40
+ """List installed global and built-in Antigravity skills."""
41
+ roots = [
42
+ ("global", Path.home() / ".gemini" / "config" / "skills"),
43
+ ("builtin", Path.home() / ".gemini" / "antigravity" / "builtin" / "skills"),
44
+ ]
45
+ lines: list[str] = []
46
+ for label, root in roots:
47
+ if root.is_dir():
48
+ names = sorted(p.name for p in root.iterdir() if p.is_dir() and (p / "SKILL.md").is_file())
49
+ lines.append(f"[{label}] ({len(names)}): {', '.join(names)}")
50
+ return "\n".join(lines) if lines else "No Antigravity skills found."
51
+
52
+
53
+ @mcp.tool()
54
+ def agy_read_skill(name: str) -> str:
55
+ """Read the SKILL.md instructions for an Antigravity skill by name."""
56
+ candidates = [
57
+ Path.home() / ".gemini" / "config" / "skills" / name / "SKILL.md",
58
+ Path.home() / ".gemini" / "antigravity" / "builtin" / "skills" / name / "SKILL.md",
59
+ ]
60
+ for c in candidates:
61
+ if c.is_file():
62
+ return c.read_text(encoding="utf-8", errors="replace")[:12000]
63
+ return f"Skill '{name}' not found."
64
+
65
+
66
+ @mcp.tool()
67
+ def agy_plugins() -> str:
68
+ """List installed Antigravity plugins."""
69
+ agy = _find_agy()
70
+ if not agy:
71
+ return "Antigravity CLI not found."
72
+ proc = subprocess.run([agy, "plugin", "list"], capture_output=True, text=True, timeout=20)
73
+ return (proc.stdout or proc.stderr or "").strip()
74
+
75
+
76
+ @mcp.tool()
77
+ def agy_conversations() -> str:
78
+ """List saved Antigravity conversations."""
79
+ agy = _find_agy()
80
+ if not agy:
81
+ return "Antigravity CLI not found."
82
+ proc = subprocess.run([agy, "conversations", "list"], capture_output=True, text=True, timeout=20)
83
+ return (proc.stdout or proc.stderr or "").strip()
84
+
85
+
86
+ @mcp.tool()
87
+ def agy_read_rules() -> str:
88
+ """Read Antigravity global GEMINI.md rules."""
89
+ p = Path.home() / ".gemini" / "config" / "GEMINI.md"
90
+ if not p.is_file():
91
+ return "Global GEMINI.md not found."
92
+ return p.read_text(encoding="utf-8", errors="replace")
93
+
94
+
95
+ def main() -> None:
96
+ mcp.run(transport="stdio")
97
+
98
+
99
+ if __name__ == "__main__":
100
+ main()
@@ -0,0 +1,28 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ from pathlib import Path
5
+
6
+ from rivonasi.antigravity_mcp import main as agy_mcp_main
7
+ from rivonasi.mcp_server import main as mcp_main
8
+ from rivonasi.tui import RivonasiApp
9
+
10
+
11
+ def main() -> None:
12
+ parser = argparse.ArgumentParser(prog="rivonasi", description="Rivonasi Terminal Agent & MCP")
13
+ parser.add_argument("--mcp", action="store_true", help="Run Rivonasi as an Antigravity stdio MCP server")
14
+ parser.add_argument("--agy-mcp", action="store_true", help="Run Antigravity bridge as a stdio MCP server")
15
+ parser.add_argument("--cwd", type=str, default=None, help="Working directory for the agent")
16
+ args = parser.parse_args()
17
+
18
+ if args.mcp:
19
+ mcp_main()
20
+ elif args.agy_mcp:
21
+ agy_mcp_main()
22
+ else:
23
+ cwd = Path(args.cwd).resolve() if args.cwd else Path.cwd()
24
+ RivonasiApp(cwd=cwd).run()
25
+
26
+
27
+ if __name__ == "__main__":
28
+ main()
@@ -0,0 +1,224 @@
1
+ from __future__ import annotations
2
+
3
+ import asyncio
4
+ import json
5
+ import time
6
+ from typing import Any, AsyncIterator, Callable
7
+ import httpx
8
+
9
+ from .config import Settings
10
+
11
+ RATE_LIMIT_STATUS_CODES = {402, 403, 429}
12
+
13
+
14
+ def _is_limit_error(status_code: int, body_text: str) -> bool:
15
+ if status_code in RATE_LIMIT_STATUS_CODES:
16
+ return True
17
+ low = body_text.lower()
18
+ return any(tok in low for tok in ("rate limit", "rate_limit", "quota", "limit reached", "too many requests"))
19
+
20
+
21
+ class CoarenaClient:
22
+ def __init__(
23
+ self,
24
+ settings: Settings,
25
+ on_key_switch: Callable[[int, int, int], None] | None = None,
26
+ on_retry_wait: Callable[[str], None] | None = None,
27
+ ) -> None:
28
+ self.base_url = settings.coarena_base_url
29
+ self.secondary_model = settings.secondary_model
30
+ self.keys: list[str] = list(settings.coarena_api_keys) or ([settings.coarena_api_key] if settings.coarena_api_key else [])
31
+ self.active_index: int = 0
32
+ self.cooldowns: dict[int, float] = {}
33
+ self.on_key_switch = on_key_switch
34
+ self.on_retry_wait = on_retry_wait
35
+
36
+ @property
37
+ def api_key(self) -> str:
38
+ if not self.keys:
39
+ return ""
40
+ return self.keys[self.active_index % len(self.keys)]
41
+
42
+ def _headers(self) -> dict[str, str]:
43
+ return {
44
+ "Authorization": f"Bearer {self.api_key}",
45
+ "Content-Type": "application/json",
46
+ }
47
+
48
+ def switch_to(self, index_0based: int) -> bool:
49
+ if not self.keys or not (0 <= index_0based < len(self.keys)):
50
+ return False
51
+ self.active_index = index_0based
52
+ return True
53
+
54
+ def _rotate_key(self, cooldown_sec: float = 60.0) -> bool:
55
+ """Mark current key as rate-limited and switch to the next key (wrapping back to old keys)."""
56
+ if len(self.keys) <= 1:
57
+ return False
58
+ old_idx = self.active_index
59
+ self.cooldowns[old_idx] = time.time() + cooldown_sec
60
+ now = time.time()
61
+
62
+ for offset in range(1, len(self.keys) + 1):
63
+ cand = (old_idx + offset) % len(self.keys)
64
+ if self.cooldowns.get(cand, 0.0) <= now:
65
+ self.active_index = cand
66
+ if self.on_key_switch:
67
+ self.on_key_switch(old_idx, cand, len(self.keys))
68
+ return True
69
+
70
+ cand = (old_idx + 1) % len(self.keys)
71
+ self.active_index = cand
72
+ if self.on_key_switch:
73
+ self.on_key_switch(old_idx, cand, len(self.keys))
74
+ return True
75
+
76
+ async def list_models(self) -> list[dict[str, Any]]:
77
+ async with httpx.AsyncClient(timeout=20.0) as client:
78
+ resp = await client.get(f"{self.base_url}/models", headers=self._headers())
79
+ resp.raise_for_status()
80
+ return resp.json().get("data", [])
81
+
82
+ async def chat_completion(
83
+ self,
84
+ messages: list[dict[str, Any]],
85
+ model: str,
86
+ tools: list[dict[str, Any]] | None = None,
87
+ temperature: float = 0.2,
88
+ ) -> dict[str, Any]:
89
+ models_to_try = [model]
90
+ if self.secondary_model and self.secondary_model != model:
91
+ models_to_try.append(self.secondary_model)
92
+
93
+ last_err_msg = "Request failed"
94
+ async with httpx.AsyncClient(timeout=120.0) as client:
95
+ for try_model in models_to_try:
96
+ payload: dict[str, Any] = {
97
+ "model": try_model,
98
+ "messages": messages,
99
+ "temperature": temperature,
100
+ }
101
+ if tools:
102
+ payload["tools"] = tools
103
+ payload["tool_choice"] = "auto"
104
+
105
+ key_attempts = max(1, len(self.keys))
106
+ for cycle in range(3):
107
+ for _ in range(key_attempts):
108
+ resp = await client.post(
109
+ f"{self.base_url}/chat/completions",
110
+ headers=self._headers(),
111
+ json=payload,
112
+ )
113
+ if resp.status_code < 400:
114
+ return resp.json()
115
+
116
+ last_err_msg = f"HTTP {resp.status_code}"
117
+ if _is_limit_error(resp.status_code, resp.text):
118
+ if self._rotate_key():
119
+ continue
120
+ break
121
+ raise RuntimeError(f"API error ({resp.status_code}): {resp.text[:240]}")
122
+
123
+ # All keys hit 429 in this cycle: wait briefly and retry
124
+ if cycle < 2:
125
+ wait_s = 3 * (cycle + 1)
126
+ if self.on_retry_wait:
127
+ self.on_retry_wait(f"Rate limit reached - retrying in {wait_s}s...")
128
+ await asyncio.sleep(wait_s)
129
+
130
+ raise RuntimeError(f"Rate limit reached ({last_err_msg}). Add more keys with /setup or /key-add, or try again shortly.")
131
+
132
+ async def stream_chat(
133
+ self,
134
+ messages: list[dict[str, Any]],
135
+ model: str,
136
+ tools: list[dict[str, Any]] | None = None,
137
+ temperature: float = 0.2,
138
+ ) -> AsyncIterator[dict[str, Any]]:
139
+ payload: dict[str, Any] = {
140
+ "model": model,
141
+ "messages": messages,
142
+ "temperature": temperature,
143
+ "stream": True,
144
+ }
145
+ if tools:
146
+ payload["tools"] = tools
147
+ payload["tool_choice"] = "auto"
148
+
149
+ async with httpx.AsyncClient(timeout=120.0) as client:
150
+ async with client.stream(
151
+ "POST",
152
+ f"{self.base_url}/chat/completions",
153
+ headers=self._headers(),
154
+ json=payload,
155
+ ) as resp:
156
+ resp.raise_for_status()
157
+ async for line in resp.aiter_lines():
158
+ if not line or not line.startswith("data:"):
159
+ continue
160
+ data_str = line[5:].strip()
161
+ if data_str == "[DONE]":
162
+ break
163
+ try:
164
+ yield json.loads(data_str)
165
+ except json.JSONDecodeError:
166
+ continue
167
+
168
+ async def send_feedback(
169
+ self,
170
+ response_id: str,
171
+ rating: int,
172
+ comment: str | None = None,
173
+ ) -> dict[str, Any]:
174
+ payload: dict[str, Any] = {
175
+ "response_id": response_id,
176
+ "rating": rating,
177
+ }
178
+ if comment:
179
+ payload["comment"] = comment
180
+ async with httpx.AsyncClient(timeout=20.0) as client:
181
+ resp = await client.post(
182
+ f"{self.base_url}/feedback",
183
+ headers=self._headers(),
184
+ json=payload,
185
+ )
186
+ resp.raise_for_status()
187
+ return resp.json() if resp.content else {"status": "ok"}
188
+
189
+
190
+ class HiggsfieldClient:
191
+ BASE_URL = "https://platform.higgsfield.ai"
192
+
193
+ def __init__(self, settings: Settings) -> None:
194
+ self.hf_key = settings.hf_key
195
+ self.headers = {
196
+ "Authorization": f"Key {self.hf_key}",
197
+ "Content-Type": "application/json",
198
+ }
199
+
200
+ async def request(
201
+ self,
202
+ method: str,
203
+ url_or_path: str,
204
+ body: dict[str, Any] | None = None,
205
+ ) -> dict[str, Any]:
206
+ if not self.hf_key:
207
+ return {"error": "HF_KEY is not configured."}
208
+ url = (
209
+ url_or_path
210
+ if url_or_path.startswith("http://") or url_or_path.startswith("https://")
211
+ else f"{self.BASE_URL}/{url_or_path.lstrip('/')}"
212
+ )
213
+ async with httpx.AsyncClient(timeout=60.0) as client:
214
+ resp = await client.request(
215
+ method=method.upper(),
216
+ url=url,
217
+ headers=self.headers,
218
+ json=body,
219
+ )
220
+ try:
221
+ data = resp.json()
222
+ except Exception:
223
+ data = {"text": resp.text}
224
+ return {"status_code": resp.status_code, "data": data}