onechat-cli 0.1.1__py3-none-any.whl
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.
- onechat/__init__.py +46 -0
- onechat/benchmark.py +253 -0
- onechat/cli.py +252 -0
- onechat/cli_doctor.py +272 -0
- onechat/cli_repl.py +116 -0
- onechat/config.py +311 -0
- onechat/contracts.py +142 -0
- onechat/defaults.yaml +47 -0
- onechat/executors/__init__.py +19 -0
- onechat/executors/api.py +254 -0
- onechat/executors/cli.py +211 -0
- onechat/executors/parser_cc.py +129 -0
- onechat/executors/parser_formats.py +81 -0
- onechat/executors/parser_tool_streams.py +218 -0
- onechat/executors/parsers.py +52 -0
- onechat/executors/process.py +228 -0
- onechat/gitstate.py +91 -0
- onechat/handoff.py +176 -0
- onechat/profiles/agy.yaml +11 -0
- onechat/profiles/autoclaw.yaml +12 -0
- onechat/profiles/claude.yaml +11 -0
- onechat/profiles/codex.yaml +14 -0
- onechat/profiles/gemini.yaml +11 -0
- onechat/profiles/opencode.yaml +11 -0
- onechat/profiles/qoder.yaml +12 -0
- onechat/profiles/qwen.yaml +11 -0
- onechat/profiles/workbuddy.yaml +13 -0
- onechat/profiles/zcode.yaml +12 -0
- onechat/quota.py +287 -0
- onechat/redact.py +58 -0
- onechat/router.py +299 -0
- onechat/router_helpers.py +288 -0
- onechat/scoring.py +241 -0
- onechat/sdk.py +210 -0
- onechat/selector.py +294 -0
- onechat/store.py +298 -0
- onechat_cli-0.1.1.dist-info/METADATA +201 -0
- onechat_cli-0.1.1.dist-info/RECORD +40 -0
- onechat_cli-0.1.1.dist-info/WHEEL +4 -0
- onechat_cli-0.1.1.dist-info/entry_points.txt +3 -0
onechat/store.py
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
"""SQLite WAL store (Plan 02 §7): sessions, turns, native sessions, usage, cooldowns.
|
|
2
|
+
|
|
3
|
+
One connection + threading.Lock; every public method is one transaction. Errors persisted
|
|
4
|
+
through append_turn are redacted (never store secret-shaped text).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import sqlite3
|
|
10
|
+
import threading
|
|
11
|
+
import time
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
from .redact import make_redactor, redact
|
|
16
|
+
|
|
17
|
+
ROUTER_SCHEMA_VERSION = 3
|
|
18
|
+
|
|
19
|
+
_SCHEMA = """
|
|
20
|
+
CREATE TABLE IF NOT EXISTS schema_versions(component TEXT PRIMARY KEY, version INT NOT NULL);
|
|
21
|
+
CREATE TABLE IF NOT EXISTS sessions(id TEXT PRIMARY KEY, title TEXT, workdir TEXT, created_at REAL,
|
|
22
|
+
pinned_executor TEXT, tier INT, summary TEXT, summary_upto INT DEFAULT 0,
|
|
23
|
+
lock_owner TEXT, lock_until REAL);
|
|
24
|
+
CREATE TABLE IF NOT EXISTS turns(id INTEGER PRIMARY KEY, session_id TEXT REFERENCES sessions(id),
|
|
25
|
+
idx INT, role TEXT, text TEXT, executor_id TEXT, stop TEXT, created_at REAL,
|
|
26
|
+
subagent_role TEXT, UNIQUE(session_id, idx));
|
|
27
|
+
CREATE TABLE IF NOT EXISTS native_sessions(session_id TEXT, executor_id TEXT, native_id TEXT,
|
|
28
|
+
last_turn_idx INT, PRIMARY KEY(session_id, executor_id));
|
|
29
|
+
CREATE TABLE IF NOT EXISTS usage(id INTEGER PRIMARY KEY, ts REAL, executor_id TEXT, session_id TEXT,
|
|
30
|
+
run_id TEXT, input_tokens INT, output_tokens INT, cost_usd REAL, stop TEXT);
|
|
31
|
+
CREATE TABLE IF NOT EXISTS cooldowns(executor_id TEXT PRIMARY KEY, until_ts REAL, strikes INT,
|
|
32
|
+
reason TEXT);
|
|
33
|
+
CREATE TABLE IF NOT EXISTS executor_overrides(executor_id TEXT PRIMARY KEY, status TEXT NOT NULL,
|
|
34
|
+
enabled_override INT, priority_override INT, latency_s REAL, checked_at REAL NOT NULL,
|
|
35
|
+
detail TEXT);
|
|
36
|
+
CREATE INDEX IF NOT EXISTS idx_usage_exec_ts ON usage(executor_id, ts);
|
|
37
|
+
CREATE INDEX IF NOT EXISTS idx_usage_run_ts ON usage(run_id, ts);
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class Store:
|
|
42
|
+
"""All router persistence. Methods never raise for missing rows; they return None/[]."""
|
|
43
|
+
|
|
44
|
+
def __init__(self, path: Path | str, api_key_envs: list[str] | None = None) -> None:
|
|
45
|
+
self._redact = make_redactor(list(api_key_envs)) if api_key_envs else redact
|
|
46
|
+
self._conn = sqlite3.connect(str(path), check_same_thread=False)
|
|
47
|
+
self._conn.row_factory = sqlite3.Row
|
|
48
|
+
self._lock = threading.Lock()
|
|
49
|
+
with self._lock, self._conn:
|
|
50
|
+
self._conn.execute("PRAGMA busy_timeout=5000") # BEFORE WAL (T09)
|
|
51
|
+
self._conn.execute("PRAGMA journal_mode=WAL")
|
|
52
|
+
self._conn.execute("PRAGMA foreign_keys=ON")
|
|
53
|
+
self._conn.executescript(_SCHEMA)
|
|
54
|
+
self._migrate()
|
|
55
|
+
|
|
56
|
+
def _migrate(self) -> None:
|
|
57
|
+
"""Bump the recorded router schema version forward (T09: v1 -> v2, v3 subagent_role)."""
|
|
58
|
+
cols = {row["name"] for row in self._conn.execute("PRAGMA table_info(turns)").fetchall()}
|
|
59
|
+
if "subagent_role" not in cols:
|
|
60
|
+
self._conn.execute("ALTER TABLE turns ADD COLUMN subagent_role TEXT")
|
|
61
|
+
self._conn.execute(
|
|
62
|
+
"INSERT INTO schema_versions(component, version) VALUES('router', ?) "
|
|
63
|
+
"ON CONFLICT(component) DO UPDATE SET version=excluded.version "
|
|
64
|
+
"WHERE excluded.version > schema_versions.version",
|
|
65
|
+
(ROUTER_SCHEMA_VERSION,),
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
def _query(self, sql: str, params: tuple | list = ()) -> list[dict[str, Any]]:
|
|
69
|
+
with self._lock:
|
|
70
|
+
return [dict(r) for r in self._conn.execute(sql, params).fetchall()]
|
|
71
|
+
|
|
72
|
+
def _query_row(self, sql: str, params: tuple | list = ()) -> dict[str, Any] | None:
|
|
73
|
+
with self._lock:
|
|
74
|
+
r = self._conn.execute(sql, params).fetchone()
|
|
75
|
+
return dict(r) if r else None
|
|
76
|
+
|
|
77
|
+
def _exec(self, sql: str, params: tuple | list = ()) -> None:
|
|
78
|
+
with self._lock, self._conn:
|
|
79
|
+
self._conn.execute(sql, params)
|
|
80
|
+
|
|
81
|
+
@property
|
|
82
|
+
def conn(self) -> sqlite3.Connection:
|
|
83
|
+
return self._conn
|
|
84
|
+
|
|
85
|
+
def close(self) -> None:
|
|
86
|
+
with self._lock:
|
|
87
|
+
self._conn.close()
|
|
88
|
+
|
|
89
|
+
# -- sessions ------------------------------------------------------------
|
|
90
|
+
def create_session(self, sid: str, title: str, workdir: str) -> None:
|
|
91
|
+
self._exec(
|
|
92
|
+
"INSERT INTO sessions(id, title, workdir, created_at) VALUES(?,?,?,?)",
|
|
93
|
+
(sid, title, workdir, time.time()),
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
def get_session(self, sid: str) -> dict[str, Any] | None:
|
|
97
|
+
return self._query_row("SELECT * FROM sessions WHERE id=?", (sid,))
|
|
98
|
+
|
|
99
|
+
def list_sessions(self) -> list[dict[str, Any]]:
|
|
100
|
+
return self._query("SELECT * FROM sessions ORDER BY created_at DESC")
|
|
101
|
+
|
|
102
|
+
def pin(self, sid: str, executor_id: str | None, tier: int | None) -> None:
|
|
103
|
+
self._exec(
|
|
104
|
+
"UPDATE sessions SET pinned_executor=?, tier=? WHERE id=?", (executor_id, tier, sid)
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
def set_lease(self, sid: str, owner: str | None, until: float | None) -> None:
|
|
108
|
+
self._exec("UPDATE sessions SET lock_owner=?, lock_until=? WHERE id=?", (owner, until, sid))
|
|
109
|
+
|
|
110
|
+
def acquire_lease(self, sid: str, owner: str, until_ts: float, now_ts: float) -> bool:
|
|
111
|
+
"""Single-row CAS (T09): free, expired, or already-ours -> claimed; else False."""
|
|
112
|
+
with self._lock, self._conn:
|
|
113
|
+
c = self._conn.execute(
|
|
114
|
+
"UPDATE sessions SET lock_owner=?, lock_until=? WHERE id=? "
|
|
115
|
+
"AND (lock_owner IS NULL OR lock_until <= ? OR lock_owner = ?)",
|
|
116
|
+
(owner, until_ts, sid, now_ts, owner),
|
|
117
|
+
)
|
|
118
|
+
return c.rowcount == 1
|
|
119
|
+
|
|
120
|
+
def release_lease(self, sid: str, owner: str) -> None:
|
|
121
|
+
"""Owner-checked release: another owner's lease is never touched (T09)."""
|
|
122
|
+
sql = "UPDATE sessions SET lock_owner=NULL, lock_until=NULL WHERE id=? AND lock_owner=?"
|
|
123
|
+
self._exec(sql, (sid, owner))
|
|
124
|
+
|
|
125
|
+
def set_summary(self, sid: str, summary: str, upto: int) -> None:
|
|
126
|
+
self._exec(
|
|
127
|
+
"UPDATE sessions SET summary=?, summary_upto=? WHERE id=?",
|
|
128
|
+
(self._redact(summary), upto, sid),
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
# -- turns ---------------------------------------------------------------
|
|
132
|
+
def append_turn(
|
|
133
|
+
self,
|
|
134
|
+
sid: str,
|
|
135
|
+
idx: int,
|
|
136
|
+
role: str,
|
|
137
|
+
text: str,
|
|
138
|
+
executor_id: str,
|
|
139
|
+
stop: str,
|
|
140
|
+
subagent_role: str | None = None,
|
|
141
|
+
) -> None:
|
|
142
|
+
self._exec(
|
|
143
|
+
"INSERT INTO turns(session_id, idx, role, text, executor_id, stop, created_at, "
|
|
144
|
+
"subagent_role) VALUES(?,?,?,?,?,?,?,?)",
|
|
145
|
+
(sid, idx, role, self._redact(text), executor_id, stop, time.time(), subagent_role),
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
def turns(self, sid: str, since_idx: int = 0) -> list[dict[str, Any]]:
|
|
149
|
+
return self._query(
|
|
150
|
+
"SELECT * FROM turns WHERE session_id=? AND idx>=? ORDER BY idx", (sid, since_idx)
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
def next_turn_idx(self, sid: str) -> int:
|
|
154
|
+
"""MAX(idx)+1 across all stored turns — gap/order tolerant (T09)."""
|
|
155
|
+
with self._lock:
|
|
156
|
+
row = self._conn.execute(
|
|
157
|
+
"SELECT COALESCE(MAX(idx) + 1, 0) FROM turns WHERE session_id=?", (sid,)
|
|
158
|
+
).fetchone()
|
|
159
|
+
return int(row[0])
|
|
160
|
+
|
|
161
|
+
# -- native sessions -----------------------------------------------------
|
|
162
|
+
def set_native(self, sid: str, executor_id: str, native_id: str, last_turn_idx: int) -> None:
|
|
163
|
+
self._exec(
|
|
164
|
+
"INSERT INTO native_sessions(session_id, executor_id, native_id, last_turn_idx) "
|
|
165
|
+
"VALUES(?,?,?,?) ON CONFLICT(session_id, executor_id) "
|
|
166
|
+
"DO UPDATE SET native_id=excluded.native_id, last_turn_idx=excluded.last_turn_idx",
|
|
167
|
+
(sid, executor_id, native_id, last_turn_idx),
|
|
168
|
+
)
|
|
169
|
+
|
|
170
|
+
def get_native(self, sid: str, executor_id: str) -> dict[str, Any] | None:
|
|
171
|
+
return self._query_row(
|
|
172
|
+
"SELECT * FROM native_sessions WHERE session_id=? AND executor_id=?",
|
|
173
|
+
(sid, executor_id),
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
# -- usage ---------------------------------------------------------------
|
|
177
|
+
def record_usage(
|
|
178
|
+
self,
|
|
179
|
+
ts: float,
|
|
180
|
+
executor_id: str,
|
|
181
|
+
session_id: str,
|
|
182
|
+
run_id: str | None,
|
|
183
|
+
input_tokens: int,
|
|
184
|
+
output_tokens: int,
|
|
185
|
+
cost_usd: float | None,
|
|
186
|
+
stop: str,
|
|
187
|
+
) -> None:
|
|
188
|
+
self._exec(
|
|
189
|
+
"INSERT INTO usage(ts, executor_id, session_id, run_id, input_tokens, "
|
|
190
|
+
"output_tokens, cost_usd, stop) VALUES(?,?,?,?,?,?,?,?)",
|
|
191
|
+
(ts, executor_id, session_id, run_id, input_tokens, output_tokens, cost_usd, stop),
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
def usage_count(self, executor_id: str, since_ts: float) -> int:
|
|
195
|
+
with self._lock:
|
|
196
|
+
row = self._conn.execute(
|
|
197
|
+
"SELECT COUNT(*) FROM usage WHERE executor_id=? AND ts>=?", (executor_id, since_ts)
|
|
198
|
+
).fetchone()
|
|
199
|
+
return int(row[0])
|
|
200
|
+
|
|
201
|
+
def spend(self, since_ts: float, run_id: str | None = None) -> float:
|
|
202
|
+
sql = "SELECT COALESCE(SUM(cost_usd),0) FROM usage WHERE ts>=?"
|
|
203
|
+
params: list[Any] = [since_ts] if run_id is None else [since_ts, run_id]
|
|
204
|
+
if run_id is not None:
|
|
205
|
+
sql += " AND run_id=?"
|
|
206
|
+
with self._lock:
|
|
207
|
+
row = self._conn.execute(sql, params).fetchone()
|
|
208
|
+
return float(row[0])
|
|
209
|
+
|
|
210
|
+
def oldest_usage_ts(self, executor_id: str, since_ts: float) -> float | None:
|
|
211
|
+
return self.nth_oldest_usage_ts(executor_id, since_ts, offset=0)
|
|
212
|
+
|
|
213
|
+
def nth_oldest_usage_ts(
|
|
214
|
+
self, executor_id: str, since_ts: float, offset: int = 0
|
|
215
|
+
) -> float | None:
|
|
216
|
+
with self._lock:
|
|
217
|
+
row = self._conn.execute(
|
|
218
|
+
"SELECT ts FROM usage WHERE executor_id=? AND ts>=? "
|
|
219
|
+
"ORDER BY ts ASC LIMIT 1 OFFSET ?",
|
|
220
|
+
(executor_id, since_ts, max(0, offset)),
|
|
221
|
+
).fetchone()
|
|
222
|
+
return float(row[0]) if row and row[0] is not None else None
|
|
223
|
+
|
|
224
|
+
def delete_session(self, sid: str) -> None:
|
|
225
|
+
with self._lock, self._conn:
|
|
226
|
+
self._conn.execute("DELETE FROM turns WHERE session_id=?", (sid,))
|
|
227
|
+
self._conn.execute("DELETE FROM native_sessions WHERE session_id=?", (sid,))
|
|
228
|
+
self._conn.execute("DELETE FROM sessions WHERE id=?", (sid,))
|
|
229
|
+
|
|
230
|
+
# -- cooldowns -----------------------------------------------------------
|
|
231
|
+
def set_cooldown(self, executor_id: str, until_ts: float, strikes: int, reason: str) -> None:
|
|
232
|
+
self._exec(
|
|
233
|
+
"INSERT INTO cooldowns(executor_id, until_ts, strikes, reason) VALUES(?,?,?,?) "
|
|
234
|
+
"ON CONFLICT(executor_id) DO UPDATE SET "
|
|
235
|
+
"until_ts=excluded.until_ts, strikes=excluded.strikes, reason=excluded.reason",
|
|
236
|
+
(executor_id, until_ts, strikes, reason),
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
def get_cooldown(self, executor_id: str) -> dict[str, Any] | None:
|
|
240
|
+
return self._query_row("SELECT * FROM cooldowns WHERE executor_id=?", (executor_id,))
|
|
241
|
+
|
|
242
|
+
def clear_cooldown(self, executor_id: str | None = None) -> None:
|
|
243
|
+
p = (executor_id,) if executor_id else ()
|
|
244
|
+
self._exec("DELETE FROM cooldowns WHERE executor_id=?" if p else "DELETE FROM cooldowns", p)
|
|
245
|
+
|
|
246
|
+
def all_cooldowns(self, now_ts: float | None = None) -> list[dict[str, Any]]:
|
|
247
|
+
"""Active cooldowns (until_ts > now) — []-safe when now_ts is None (T09)."""
|
|
248
|
+
if now_ts is None:
|
|
249
|
+
return self._query("SELECT * FROM cooldowns ORDER BY executor_id")
|
|
250
|
+
return self._query(
|
|
251
|
+
"SELECT * FROM cooldowns WHERE until_ts > ? ORDER BY until_ts", (now_ts,)
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
def recent_stops(self, executor_id: str, since_ts: float) -> list[str]:
|
|
255
|
+
"""Stops recorded for an executor since a timestamp, oldest first (T09/T10 K1)."""
|
|
256
|
+
return [
|
|
257
|
+
str(r["stop"] or "")
|
|
258
|
+
for r in self._query(
|
|
259
|
+
"SELECT stop FROM usage WHERE executor_id=? AND ts>=? ORDER BY ts",
|
|
260
|
+
(executor_id, since_ts),
|
|
261
|
+
)
|
|
262
|
+
]
|
|
263
|
+
|
|
264
|
+
# -- executor overrides (benchmark watchdog) ------------------------------
|
|
265
|
+
def set_executor_override(
|
|
266
|
+
self,
|
|
267
|
+
executor_id: str,
|
|
268
|
+
status: str,
|
|
269
|
+
enabled_override: int | None = None,
|
|
270
|
+
priority_override: int | None = None,
|
|
271
|
+
latency_s: float | None = None,
|
|
272
|
+
detail: str | None = None,
|
|
273
|
+
) -> None:
|
|
274
|
+
sql = (
|
|
275
|
+
"INSERT INTO executor_overrides("
|
|
276
|
+
"executor_id, status, enabled_override, priority_override, "
|
|
277
|
+
"latency_s, checked_at, detail) VALUES(?,?,?,?,?,?,?) ON CONFLICT(executor_id) "
|
|
278
|
+
"DO UPDATE SET status=excluded.status, enabled_override=excluded.enabled_override, "
|
|
279
|
+
"priority_override=excluded.priority_override, latency_s=excluded.latency_s, "
|
|
280
|
+
"checked_at=excluded.checked_at, detail=excluded.detail"
|
|
281
|
+
)
|
|
282
|
+
clean = self._redact(detail) if detail else None
|
|
283
|
+
vals = (
|
|
284
|
+
executor_id,
|
|
285
|
+
status,
|
|
286
|
+
enabled_override,
|
|
287
|
+
priority_override,
|
|
288
|
+
latency_s,
|
|
289
|
+
time.time(),
|
|
290
|
+
clean,
|
|
291
|
+
)
|
|
292
|
+
self._exec(sql, vals)
|
|
293
|
+
|
|
294
|
+
def get_executor_overrides(self) -> dict[str, dict[str, Any]]:
|
|
295
|
+
return {str(r["executor_id"]): r for r in self._query("SELECT * FROM executor_overrides")}
|
|
296
|
+
|
|
297
|
+
def clear_executor_override(self, executor_id: str) -> None:
|
|
298
|
+
self._exec("DELETE FROM executor_overrides WHERE executor_id=?", (executor_id,))
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: onechat-cli
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: One chat session surviving AI backend switches (CLI agents + OpenAI-compatible APIs)
|
|
5
|
+
Keywords: ai,cli,llm,router,claude-code,codex,gemini,agents
|
|
6
|
+
Author: Abolfazl Moeini
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
15
|
+
Requires-Dist: pydantic>=2.8
|
|
16
|
+
Requires-Dist: typer>=0.12
|
|
17
|
+
Requires-Dist: pyyaml>=6
|
|
18
|
+
Requires-Dist: openai==3.42.1
|
|
19
|
+
Requires-Python: >=3.12
|
|
20
|
+
Project-URL: Homepage, https://github.com/abolfazl-moeini/onechat
|
|
21
|
+
Project-URL: Repository, https://github.com/abolfazl-moeini/onechat
|
|
22
|
+
Project-URL: Issues, https://github.com/abolfazl-moeini/onechat/issues
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# onechat
|
|
26
|
+
|
|
27
|
+
[](https://github.com/abolfazl-moeini/onechat/actions/workflows/ci.yml)
|
|
28
|
+
[](https://pypi.org/project/onechat-cli/)
|
|
29
|
+
[](https://www.python.org/downloads/)
|
|
30
|
+
[](https://github.com/abolfazl-moeini/onechat/blob/main/LICENSE)
|
|
31
|
+
|
|
32
|
+
**The Problem:** You are deep into a coding or debugging session with Claude Code, Codex, or Gemini CLI—then you hit a rate limit, quota wall, or timeout. Switching tools means starting a fresh terminal and re-explaining your entire context from scratch.
|
|
33
|
+
|
|
34
|
+
**The Solution:** `onechat` gives you **one persistent chat session that survives AI backend switches**. It automatically detects quota/auth/timeout failures, places the failing backend on cooldown, generates a compact handoff brief (plus current git state), and continues the exact same conversation on the next available CLI agent or OpenAI-compatible API.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Supported Backends
|
|
39
|
+
|
|
40
|
+
| Backend | Kind | Profile / Parser | Notes |
|
|
41
|
+
|---|---|---|---|
|
|
42
|
+
| **Claude Code** (`claude`) | CLI | `claude` | Native JSONL stream + session resume |
|
|
43
|
+
| **OpenAI Codex** (`codex`) | CLI | `codex` | Native JSONL stream + session resume |
|
|
44
|
+
| **Google Gemini CLI** (`gemini`) | CLI | `gemini` | Stream JSON + session resume |
|
|
45
|
+
| **OpenCode** (`opencode`) | CLI | `opencode` | Multi-provider CLI + model routing |
|
|
46
|
+
| **Qwen Code** (`qwen`) | CLI | `qwen` | Stream JSON + session resume |
|
|
47
|
+
| **OpenAI-compatible APIs** | API | `kind: api` | Groq, OpenRouter, DeepSeek, Cerebras, local vLLM/Ollama |
|
|
48
|
+
| **Additional CLI profiles** | CLI | `agy`, `autoclaw`, `workbuddy`, `qoder`, `zcode` | Built-in YAML profiles + custom `~/.onechat/profiles/*.yaml` |
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## How It Works
|
|
53
|
+
|
|
54
|
+
```mermaid
|
|
55
|
+
flowchart LR
|
|
56
|
+
U["User / SDK / CLI (`onechat chat` or `onechat run`)"] --> R["Router"]
|
|
57
|
+
R --> S["Selector (Tier, Capabilities, Skills, Cost)"]
|
|
58
|
+
S --> Q["Quota & Cooldown Book (SQLite WAL)"]
|
|
59
|
+
Q -->|Available| E1["Primary Executor (CLI / API)"]
|
|
60
|
+
E1 -->|Quota / Timeout / Error| H["Handoff Brief + Git State"]
|
|
61
|
+
H --> E2["Fallback Executor (Next Backend)"]
|
|
62
|
+
E1 -->|Done| DB[("~/.onechat/onechat.db")]
|
|
63
|
+
E2 -->|Done| DB
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
- **Same backend next turn?** Uses native session resume (`--resume`) for zero extra token overhead.
|
|
67
|
+
- **Switched to a different backend?** Injects a bounded `<asf-handoff>` summary + recent turns + current git status/diff so the new model picks up seamlessly.
|
|
68
|
+
- **Zero secrets stored:** API keys are read strictly from environment variables (`os.environ` or `~/.onechat/env`) and automatically redacted from logs, errors, and SQLite.
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Installation
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# Install globally as a CLI tool (recommended)
|
|
76
|
+
uv tool install onechat-cli
|
|
77
|
+
|
|
78
|
+
# Or with pip
|
|
79
|
+
pip install onechat-cli
|
|
80
|
+
|
|
81
|
+
# Or run one-off without installing
|
|
82
|
+
uvx --from onechat-cli onechat doctor
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Quick Start
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# 1. Check installed CLI binaries, API key env vars, and SQLite DB
|
|
91
|
+
onechat doctor
|
|
92
|
+
|
|
93
|
+
# 2. Start an interactive multi-backend chat REPL
|
|
94
|
+
onechat chat
|
|
95
|
+
|
|
96
|
+
# 3. Run a single turn in a persistent session
|
|
97
|
+
onechat run "Find why tests/test_auth.py is flaky" --session my-debug
|
|
98
|
+
|
|
99
|
+
# 4. Inspect executor pool, cooldowns, and session history
|
|
100
|
+
onechat executors list
|
|
101
|
+
onechat sessions list
|
|
102
|
+
onechat sessions export my-debug --format md
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Inside `onechat chat`:
|
|
106
|
+
- `/use <executor>` — switch backend mid-conversation without losing context
|
|
107
|
+
- `/tier low|medium|high` — override reasoning/cost tier
|
|
108
|
+
- `/status` — inspect active session, executor, and cooldowns
|
|
109
|
+
- `/exit` — quit
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Configuration (`~/.onechat/config.yaml`)
|
|
114
|
+
|
|
115
|
+
`onechat` works out of the box with defaults, and deep-merges `~/.onechat/config.yaml` (or `$ONECHAT_CONFIG`).
|
|
116
|
+
|
|
117
|
+
```yaml
|
|
118
|
+
db_path: ~/.onechat/onechat.db
|
|
119
|
+
|
|
120
|
+
# Optional: define your prioritized executor pool (free -> subscription -> paid)
|
|
121
|
+
executors:
|
|
122
|
+
- id: codex-main
|
|
123
|
+
kind: cli
|
|
124
|
+
profile: codex
|
|
125
|
+
tier: 3
|
|
126
|
+
cost: subscription
|
|
127
|
+
capabilities: [chat, code]
|
|
128
|
+
|
|
129
|
+
- id: claude-main
|
|
130
|
+
kind: cli
|
|
131
|
+
profile: claude
|
|
132
|
+
tier: 3
|
|
133
|
+
cost: subscription
|
|
134
|
+
capabilities: [chat, code]
|
|
135
|
+
|
|
136
|
+
- id: gemini-cli
|
|
137
|
+
kind: cli
|
|
138
|
+
profile: gemini
|
|
139
|
+
tier: 2
|
|
140
|
+
cost: free
|
|
141
|
+
capabilities: [chat, code]
|
|
142
|
+
|
|
143
|
+
- id: groq-fast
|
|
144
|
+
kind: api
|
|
145
|
+
base_url: https://api.groq.com/openai/v1
|
|
146
|
+
model: llama-3.3-70b-versatile
|
|
147
|
+
api_key_env: GROQ_API_KEY
|
|
148
|
+
tier: 2
|
|
149
|
+
cost: free
|
|
150
|
+
capabilities: [chat]
|
|
151
|
+
|
|
152
|
+
- id: openrouter-fallback
|
|
153
|
+
kind: api
|
|
154
|
+
base_url: https://openrouter.ai/api/v1
|
|
155
|
+
model: qwen/qwen3-coder:free
|
|
156
|
+
api_key_env: OPENROUTER_API_KEY
|
|
157
|
+
tier: 3
|
|
158
|
+
cost: free
|
|
159
|
+
capabilities: [chat, code]
|
|
160
|
+
|
|
161
|
+
tier_policy:
|
|
162
|
+
cost_order: [free, subscription, paid]
|
|
163
|
+
allow_paid: false
|
|
164
|
+
|
|
165
|
+
cooldown:
|
|
166
|
+
quota_cooldown_s: 7200
|
|
167
|
+
timeout_cooldown_s: 7200
|
|
168
|
+
error_cooldown_s: 14400
|
|
169
|
+
auth_cooldown_s: 86400
|
|
170
|
+
share_profile_cooldown: true
|
|
171
|
+
|
|
172
|
+
handoff:
|
|
173
|
+
recent_turns: 6
|
|
174
|
+
turn_max_chars: 4000
|
|
175
|
+
brief_max_chars: 24000
|
|
176
|
+
compact_threshold_chars: 30000
|
|
177
|
+
|
|
178
|
+
roles:
|
|
179
|
+
builder: codex
|
|
180
|
+
reviewer: claude
|
|
181
|
+
auditor: codex
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Python SDK
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
from onechat import OneChatClient
|
|
190
|
+
|
|
191
|
+
client = OneChatClient()
|
|
192
|
+
session = client.session(workdir=".")
|
|
193
|
+
|
|
194
|
+
# Turn 1: runs on the best available executor
|
|
195
|
+
reply1 = session.ask_sync("Summarize the architecture of src/")
|
|
196
|
+
print(f"[{reply1.executor_id}] {reply1.text}")
|
|
197
|
+
|
|
198
|
+
# Turn 2: force a switch or let failover handle quota automatically
|
|
199
|
+
reply2 = session.ask_sync("Now write unit tests for the config loader", executor="claude-main")
|
|
200
|
+
print(f"[{reply2.executor_id}] {reply2.text}")
|
|
201
|
+
```
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
onechat/__init__.py,sha256=BtXNjq8GMsQWchE4rVQ91bkRC49WQSsJScgY-_E52JQ,905
|
|
2
|
+
onechat/benchmark.py,sha256=LJuH4DpD9nQADMsmqWmhOrCZSjLRQLFlsRkFnsKQ3lc,8723
|
|
3
|
+
onechat/cli.py,sha256=OQiWjR69NGJCrDynLkyLD4QWcojnXqqNn7sgzjgCot8,8798
|
|
4
|
+
onechat/cli_doctor.py,sha256=VRW1Ej_NVe_-syhfTQ0CV0bK9KZHoO-RVHJtpQoF5Ms,9545
|
|
5
|
+
onechat/cli_repl.py,sha256=L28CZHxQHvGuFzWNo9iQxvT2l7oiW7t8hZYmXbmpxO4,3812
|
|
6
|
+
onechat/config.py,sha256=M0b4F2XVBmW6933reVynhv1L25gJjqgwG1QGDhr71PU,11132
|
|
7
|
+
onechat/contracts.py,sha256=toVd2_a54q_qDdoEPo7GC2s_1istvjezdDt7L23fP1M,3779
|
|
8
|
+
onechat/defaults.yaml,sha256=WM6e2iw1tnuJemEILiliEK6Qyh_mb803xrOuwIYWWn0,983
|
|
9
|
+
onechat/executors/__init__.py,sha256=dzONbzlmKNQOBPg3B84ItlUcNIurfQO4Ju3pZzWd0i0,711
|
|
10
|
+
onechat/executors/api.py,sha256=twBswiJCTZVnLG284gMEMJ7q-7ynEmqRZpFXFWtufgc,10431
|
|
11
|
+
onechat/executors/cli.py,sha256=4H91hahL41KDowAlQYiIR0cymN6fzGSKlOtmta5NqwE,8125
|
|
12
|
+
onechat/executors/parser_cc.py,sha256=KmH1h9i430ZG9frG1akDDRXeqj4dVqgkBZEw_1vEuBk,4839
|
|
13
|
+
onechat/executors/parser_formats.py,sha256=NtmOYpP96XMYSABILBpBwlKiNxZUJbWpN4Vcyw-qi1U,2417
|
|
14
|
+
onechat/executors/parser_tool_streams.py,sha256=vU5sY2yeZr97DnoKSZydDij1SsH_2NkXAKWXNgP4lgU,8733
|
|
15
|
+
onechat/executors/parsers.py,sha256=GBhEqbxaRsrR7-VeBemtj8CUbtebnfMllukOHuTY-9o,1886
|
|
16
|
+
onechat/executors/process.py,sha256=P4qssIK9CCjJO441DgNzyd8hvLShtTbMGp8kh3LPO3s,8124
|
|
17
|
+
onechat/gitstate.py,sha256=GN-yMhWQRviZanzMQBO6WBcmBW0R3zujcpR1ve5HJTM,2981
|
|
18
|
+
onechat/handoff.py,sha256=4LwcW2xvCKysvRzzHHtoas2m8ztYFB-tvcwzzZwJ0cc,6248
|
|
19
|
+
onechat/profiles/agy.yaml,sha256=GpBQo65RQhPJfeugd1sRjByi7HB8_XPqdjZq96PZovE,674
|
|
20
|
+
onechat/profiles/autoclaw.yaml,sha256=nqGKPUziVQHPewAMfjKiZcPNOHX7CJP5ll5pG5ElntA,692
|
|
21
|
+
onechat/profiles/claude.yaml,sha256=oqZROfy3EDF6WnW1mJEWH1hRbUe-gssVsikL_hpUD2I,741
|
|
22
|
+
onechat/profiles/codex.yaml,sha256=WOSardJc1gMqKcaS0Fe9tRVh6EdjLt9DDLQDW8ug8EY,845
|
|
23
|
+
onechat/profiles/gemini.yaml,sha256=oYegaz2sMyAVeK68FjqrOV0u6g_APFZeTZ-V9PxKlRw,645
|
|
24
|
+
onechat/profiles/opencode.yaml,sha256=hWvZV14hZ8vLX1mdHwkYsphoC30xetmsJbDU0kFAkts,654
|
|
25
|
+
onechat/profiles/qoder.yaml,sha256=RqEwnMfjanD80oieFb4AkblhAlQJX5UyRApXOv1tiH4,632
|
|
26
|
+
onechat/profiles/qwen.yaml,sha256=SKykvgiQl1RxYrlbX0rxqJ15LyKed-0x6uNL8hPO3EY,612
|
|
27
|
+
onechat/profiles/workbuddy.yaml,sha256=ZvkAcQmUP946I2ahgZl1fO2S8RvCAku3ydUI0bPe6Ls,892
|
|
28
|
+
onechat/profiles/zcode.yaml,sha256=OAiTjUncU48IUH13YkhtLR3WLLtKNJx6I1Hiq0mzFNo,677
|
|
29
|
+
onechat/quota.py,sha256=uTHBitkJjlkMWhB0Y-zMMzzTRbBQSjDwk59a1sk7Ld0,10851
|
|
30
|
+
onechat/redact.py,sha256=aXyH7n-fUg9QEF9VonwlxvGKwzGiGA1Ks8tIpm0qDFo,2223
|
|
31
|
+
onechat/router.py,sha256=zdiFSLti_zcBz5wejcv8FQJHA20_ZnKUWpeTBE42u9g,11998
|
|
32
|
+
onechat/router_helpers.py,sha256=w_uu3K9oKxcjAPIkWwMZq0kJ4P0vKObUmhybHjRrHiM,10084
|
|
33
|
+
onechat/scoring.py,sha256=_4B6W4PixY7TYf0PGtFXxPf27zoKavs7NM2oFLdWoGk,7622
|
|
34
|
+
onechat/sdk.py,sha256=AB_IpQ91p2Dlrt_UGT4xGisMjxuAPoTao6hywdV3pQ4,7596
|
|
35
|
+
onechat/selector.py,sha256=Bf04Dz1UVkukTsQXyVkWKvZbxgOtXxHFoU0QIUkA3hI,9860
|
|
36
|
+
onechat/store.py,sha256=JhGPGsQyQiSEMAob5ogNNoXRKa1mnb_ucoU82h8DU3w,13171
|
|
37
|
+
onechat_cli-0.1.1.dist-info/WHEEL,sha256=4OL6Foqnnp3xRY5wMkjgc25_i5YJC6dKsC6LPcjqEoU,80
|
|
38
|
+
onechat_cli-0.1.1.dist-info/entry_points.txt,sha256=gGaVQCgF3MApi4p8HAqdap8uer7VdHYv0wjUsZvh6xQ,45
|
|
39
|
+
onechat_cli-0.1.1.dist-info/METADATA,sha256=nUasxA9fqOcpykAE3goDTbuy1GQr48aflo_SlxcgACM,6659
|
|
40
|
+
onechat_cli-0.1.1.dist-info/RECORD,,
|