dint-cli 0.1.1__tar.gz → 0.1.3__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.
- {dint_cli-0.1.1/src/dint_cli.egg-info → dint_cli-0.1.3}/PKG-INFO +2 -2
- {dint_cli-0.1.1 → dint_cli-0.1.3}/README.md +1 -1
- {dint_cli-0.1.1 → dint_cli-0.1.3}/pyproject.toml +1 -1
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint/__init__.py +1 -1
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint/cli.py +145 -17
- {dint_cli-0.1.1 → dint_cli-0.1.3/src/dint_cli.egg-info}/PKG-INFO +2 -2
- dint_cli-0.1.3/tests/test_cli.py +213 -0
- dint_cli-0.1.1/tests/test_cli.py +0 -118
- {dint_cli-0.1.1 → dint_cli-0.1.3}/LICENSE +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/setup.cfg +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint/__main__.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint/engines/__init__.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint/engines/base.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint/engines/claude.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint/engines/codex.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint/engines/copilot.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint/engines/grok.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint/envfile.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint/jobs.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint/logbook/__init__.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint/logbook/mcp.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint/logbook/rest.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint/proc.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint/router.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint/runtime.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint/status.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint/types.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint_cli.egg-info/SOURCES.txt +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint_cli.egg-info/dependency_links.txt +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint_cli.egg-info/entry_points.txt +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint_cli.egg-info/requires.txt +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/src/dint_cli.egg-info/top_level.txt +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/tests/test_engines.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/tests/test_envfile.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/tests/test_jobs.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/tests/test_logbook.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/tests/test_router.py +0 -0
- {dint_cli-0.1.1 → dint_cli-0.1.3}/tests/test_runtime.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dint-cli
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: One local chat API over Claude, Codex, Grok, and Copilot. Codicent Logbook is the ledger.
|
|
5
5
|
Author-email: Johan Isaksson <johan@izaxon.com>
|
|
6
6
|
License: MIT License
|
|
@@ -97,7 +97,7 @@ dint list <chat_id>
|
|
|
97
97
|
dint show <chat_id>
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
-
Bare `dint`
|
|
100
|
+
Bare `dint` opens a chat in this folder (starts logbook + serve). Inside: `/engine`, `/job`, `/chats`, `/new`, `/help`. `DINT_ENGINE` picks the default CLI. Logbook and `dint serve` keep running in the background.
|
|
101
101
|
|
|
102
102
|
Python:
|
|
103
103
|
|
|
@@ -52,7 +52,7 @@ dint list <chat_id>
|
|
|
52
52
|
dint show <chat_id>
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
Bare `dint`
|
|
55
|
+
Bare `dint` opens a chat in this folder (starts logbook + serve). Inside: `/engine`, `/job`, `/chats`, `/new`, `/help`. `DINT_ENGINE` picks the default CLI. Logbook and `dint serve` keep running in the background.
|
|
56
56
|
|
|
57
57
|
Python:
|
|
58
58
|
|
|
@@ -9,7 +9,7 @@ import sys
|
|
|
9
9
|
from dint import __version__
|
|
10
10
|
from dint.envfile import load_dotenv
|
|
11
11
|
from dint.router import ENGINES, Router
|
|
12
|
-
from dint.runtime import ensure_runtime, pick_engine, serve_running
|
|
12
|
+
from dint.runtime import ensure_runtime, jobs_url, logbook_url, pick_engine, serve_running
|
|
13
13
|
|
|
14
14
|
COMMANDS = {
|
|
15
15
|
"start",
|
|
@@ -35,9 +35,16 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
35
35
|
|
|
36
36
|
p = argparse.ArgumentParser(
|
|
37
37
|
prog="dint",
|
|
38
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
38
39
|
description=(
|
|
39
40
|
"Chat router over Claude, Codex, Grok, and Copilot. "
|
|
40
|
-
"
|
|
41
|
+
"No command opens a chat in this folder (starts logbook + serve)."
|
|
42
|
+
),
|
|
43
|
+
epilog=(
|
|
44
|
+
"examples:\n"
|
|
45
|
+
" dint chat REPL (/help inside)\n"
|
|
46
|
+
" dint grok \"Summarize this\" one-shot\n"
|
|
47
|
+
" dint job grok \"Summarize this\" enqueue a #job"
|
|
41
48
|
),
|
|
42
49
|
)
|
|
43
50
|
p.add_argument("--version", action="version", version=f"dint {__version__}")
|
|
@@ -174,11 +181,12 @@ def run_chat(engine: str | None, prompt: str | None) -> int:
|
|
|
174
181
|
print("dint: pass a prompt, or run in a terminal", file=sys.stderr)
|
|
175
182
|
return 2
|
|
176
183
|
router = Router()
|
|
184
|
+
had = any(_cwd_key(str(c.get("cwd") or "")) == _cwd_key(cwd) for c in router.list_chats())
|
|
177
185
|
engine, chat_id = _resume_or_start(router, engine, cwd)
|
|
178
|
-
print(f"{engine} {cwd} {chat_id}", file=sys.stderr)
|
|
179
186
|
if prompt:
|
|
187
|
+
print(f"{engine} {cwd} {chat_id}", file=sys.stderr)
|
|
180
188
|
return _send(router, chat_id, prompt)
|
|
181
|
-
return _repl(router, engine, cwd, chat_id)
|
|
189
|
+
return _repl(router, engine, cwd, chat_id, fresh=not had)
|
|
182
190
|
|
|
183
191
|
|
|
184
192
|
def _resume_or_start(router: Router, engine: str | None, cwd: str) -> tuple[str, str]:
|
|
@@ -204,31 +212,151 @@ def _resume_or_start(router: Router, engine: str | None, cwd: str) -> tuple[str,
|
|
|
204
212
|
return engine, router.start_chat(engine, cwd)
|
|
205
213
|
|
|
206
214
|
|
|
207
|
-
def _repl(router: Router, engine: str, cwd: str, chat_id: str) -> int:
|
|
208
|
-
|
|
215
|
+
def _repl(router: Router, engine: str, cwd: str, chat_id: str, *, fresh: bool) -> int:
|
|
216
|
+
_print_banner(engine, cwd, chat_id, fresh=fresh)
|
|
209
217
|
while True:
|
|
210
218
|
try:
|
|
211
|
-
line = input()
|
|
219
|
+
line = input(f"{engine}> ")
|
|
212
220
|
except (EOFError, KeyboardInterrupt):
|
|
213
221
|
print(file=sys.stderr)
|
|
214
222
|
return 0
|
|
215
223
|
text = line.strip()
|
|
216
224
|
if not text:
|
|
217
225
|
continue
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
code = _send(router, chat_id,
|
|
226
|
+
send_text = text
|
|
227
|
+
if text.startswith("//"):
|
|
228
|
+
send_text = text[1:]
|
|
229
|
+
elif text.startswith("/"):
|
|
230
|
+
action, engine, chat_id = _slash(router, engine, cwd, chat_id, text)
|
|
231
|
+
if action == "quit":
|
|
232
|
+
return 0
|
|
233
|
+
if action != "send":
|
|
234
|
+
continue
|
|
235
|
+
code = _send(router, chat_id, send_text, quiet_done=True)
|
|
228
236
|
if code != 0:
|
|
229
237
|
return code
|
|
230
238
|
|
|
231
239
|
|
|
240
|
+
def _print_banner(engine: str, cwd: str, chat_id: str, *, fresh: bool) -> None:
|
|
241
|
+
print(f"{engine} {cwd} chat {chat_id}", file=sys.stderr)
|
|
242
|
+
print(f"logbook {logbook_url()} serve {jobs_url()}", file=sys.stderr)
|
|
243
|
+
if fresh:
|
|
244
|
+
print(
|
|
245
|
+
f'no chats here yet — type a prompt, or: dint job {engine} "Summarize this repo"',
|
|
246
|
+
file=sys.stderr,
|
|
247
|
+
)
|
|
248
|
+
print("/engine /job /chats /new /help quit: Ctrl-C or /quit", file=sys.stderr)
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def _print_help(engine: str) -> None:
|
|
252
|
+
print(
|
|
253
|
+
"slash:\n"
|
|
254
|
+
" /engine CLIs on PATH\n"
|
|
255
|
+
" /engine claude switch engine (new or resume in this folder)\n"
|
|
256
|
+
" /job [engine] text enqueue a #job (dint serve runs it)\n"
|
|
257
|
+
" /chats chats in this folder\n"
|
|
258
|
+
" /status logbook + engines\n"
|
|
259
|
+
" /new new chat, same engine\n"
|
|
260
|
+
" /help /quit\n"
|
|
261
|
+
" /login (and other unknown /lines) go to the engine\n"
|
|
262
|
+
" //help send /help to the engine\n"
|
|
263
|
+
"same from another shell:\n"
|
|
264
|
+
f' dint job {engine} "Summarize this repo"\n'
|
|
265
|
+
" dint chats\n"
|
|
266
|
+
" dint status",
|
|
267
|
+
file=sys.stderr,
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def _slash(
|
|
272
|
+
router: Router, engine: str, cwd: str, chat_id: str, text: str
|
|
273
|
+
) -> tuple[str, str, str]:
|
|
274
|
+
parts = text.split()
|
|
275
|
+
cmd = parts[0].lower()
|
|
276
|
+
args = parts[1:]
|
|
277
|
+
if cmd in {"/quit", "/exit", "/q"}:
|
|
278
|
+
return "quit", engine, chat_id
|
|
279
|
+
if cmd == "/help":
|
|
280
|
+
_print_help(engine)
|
|
281
|
+
return "ok", engine, chat_id
|
|
282
|
+
if cmd == "/new":
|
|
283
|
+
chat_id = router.start_chat(engine, cwd)
|
|
284
|
+
print(f"{engine} {cwd} chat {chat_id}", file=sys.stderr)
|
|
285
|
+
return "ok", engine, chat_id
|
|
286
|
+
if cmd == "/engine":
|
|
287
|
+
if not args:
|
|
288
|
+
_print_engines(engine)
|
|
289
|
+
return "ok", engine, chat_id
|
|
290
|
+
name = args[0].lower()
|
|
291
|
+
if name not in ENGINES:
|
|
292
|
+
print(f"unknown engine: {name} ({', '.join(sorted(ENGINES))})", file=sys.stderr)
|
|
293
|
+
return "ok", engine, chat_id
|
|
294
|
+
if shutil.which(name) is None:
|
|
295
|
+
print(f"{name} is not on PATH", file=sys.stderr)
|
|
296
|
+
return "ok", engine, chat_id
|
|
297
|
+
engine, chat_id = _resume_or_start(router, name, cwd)
|
|
298
|
+
print(f"{engine} {cwd} chat {chat_id}", file=sys.stderr)
|
|
299
|
+
return "ok", engine, chat_id
|
|
300
|
+
if cmd == "/chats":
|
|
301
|
+
_print_chats(router, cwd, chat_id)
|
|
302
|
+
return "ok", engine, chat_id
|
|
303
|
+
if cmd == "/status":
|
|
304
|
+
from dint.status import run_status
|
|
305
|
+
|
|
306
|
+
run_status()
|
|
307
|
+
return "ok", engine, chat_id
|
|
308
|
+
if cmd == "/job":
|
|
309
|
+
_slash_job(router, engine, cwd, args)
|
|
310
|
+
return "ok", engine, chat_id
|
|
311
|
+
return "send", engine, chat_id
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
def _slash_job(router: Router, engine: str, cwd: str, args: list[str]) -> None:
|
|
315
|
+
from dint.jobs import post_job, wait_for_job_chat
|
|
316
|
+
|
|
317
|
+
if not args:
|
|
318
|
+
print(f'/job [engine] prompt e.g. /job {engine} Summarize this repo', file=sys.stderr)
|
|
319
|
+
return
|
|
320
|
+
job_engine = engine
|
|
321
|
+
prompt_parts = args
|
|
322
|
+
if args[0].lower() in ENGINES:
|
|
323
|
+
job_engine = args[0].lower()
|
|
324
|
+
prompt_parts = args[1:]
|
|
325
|
+
prompt = " ".join(prompt_parts).strip()
|
|
326
|
+
if not prompt:
|
|
327
|
+
print("/job: prompt required", file=sys.stderr)
|
|
328
|
+
return
|
|
329
|
+
job_id = post_job(router, job_engine, prompt, cwd)
|
|
330
|
+
print(f"job\t{job_id}", file=sys.stderr)
|
|
331
|
+
new_chat = wait_for_job_chat(router, job_id)
|
|
332
|
+
if new_chat:
|
|
333
|
+
print(f"chat\t{new_chat} dint list {new_chat}", file=sys.stderr)
|
|
334
|
+
else:
|
|
335
|
+
print("waiting for dint serve... try: /chats", file=sys.stderr)
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
def _print_engines(current: str) -> None:
|
|
339
|
+
for name in sorted(ENGINES):
|
|
340
|
+
path = shutil.which(name)
|
|
341
|
+
mark = "*" if name == current else " "
|
|
342
|
+
print(f"{mark} {name:8} {path or 'NOT ON PATH'}", file=sys.stderr)
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
def _print_chats(router: Router, cwd: str, current: str) -> None:
|
|
346
|
+
key = _cwd_key(cwd)
|
|
347
|
+
rows = [c for c in router.list_chats() if _cwd_key(str(c.get("cwd") or "")) == key]
|
|
348
|
+
if not rows:
|
|
349
|
+
print("no chats in this folder dint chats", file=sys.stderr)
|
|
350
|
+
return
|
|
351
|
+
for c in rows:
|
|
352
|
+
mark = "*" if c.get("chatId") == current else " "
|
|
353
|
+
preview = (c.get("preview") or "").replace("\n", " ")[:50]
|
|
354
|
+
print(
|
|
355
|
+
f"{mark} {c.get('ts')}\t{c.get('chatId')}\t{c.get('engine')}\t{preview}",
|
|
356
|
+
file=sys.stderr,
|
|
357
|
+
)
|
|
358
|
+
|
|
359
|
+
|
|
232
360
|
def _send(router: Router, chat_id: str, prompt: str, *, quiet_done: bool = False) -> int:
|
|
233
361
|
printer = EventPrinter(quiet_done=quiet_done)
|
|
234
362
|
try:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dint-cli
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: One local chat API over Claude, Codex, Grok, and Copilot. Codicent Logbook is the ledger.
|
|
5
5
|
Author-email: Johan Isaksson <johan@izaxon.com>
|
|
6
6
|
License: MIT License
|
|
@@ -97,7 +97,7 @@ dint list <chat_id>
|
|
|
97
97
|
dint show <chat_id>
|
|
98
98
|
```
|
|
99
99
|
|
|
100
|
-
Bare `dint`
|
|
100
|
+
Bare `dint` opens a chat in this folder (starts logbook + serve). Inside: `/engine`, `/job`, `/chats`, `/new`, `/help`. `DINT_ENGINE` picks the default CLI. Logbook and `dint serve` keep running in the background.
|
|
101
101
|
|
|
102
102
|
Python:
|
|
103
103
|
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
from dint.cli import EventPrinter, _job_cwd_prompt, main
|
|
7
|
+
from dint.logbook import ChatLog
|
|
8
|
+
from dint.router import Router
|
|
9
|
+
from dint.types import Event
|
|
10
|
+
from test_logbook import MemoryLogbook
|
|
11
|
+
from test_router import FakeEngine
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_cli_start_and_list(monkeypatch, capsys) -> None:
|
|
15
|
+
engine = FakeEngine(
|
|
16
|
+
"claude",
|
|
17
|
+
[[Event(type="session", session_id="ses-cli"), Event(type="text", text="ok"), Event(type="done")]],
|
|
18
|
+
)
|
|
19
|
+
router = Router(
|
|
20
|
+
store=ChatLog(MemoryLogbook(), project="dint"),
|
|
21
|
+
engines={"claude": engine, "codex": FakeEngine("codex", []), "grok": FakeEngine("grok", [])},
|
|
22
|
+
)
|
|
23
|
+
monkeypatch.setattr("dint.cli.ensure_runtime", lambda **k: None)
|
|
24
|
+
monkeypatch.setattr("dint.cli.Router", lambda: router)
|
|
25
|
+
|
|
26
|
+
assert main(["start", "claude", "."]) == 0
|
|
27
|
+
chat_id = capsys.readouterr().out.strip()
|
|
28
|
+
assert len(chat_id) == 12
|
|
29
|
+
assert main(["send", chat_id, "hello"]) == 0
|
|
30
|
+
capsys.readouterr()
|
|
31
|
+
assert main(["list", chat_id]) == 0
|
|
32
|
+
out = capsys.readouterr().out
|
|
33
|
+
assert "hello" in out and "ok" in out
|
|
34
|
+
assert main(["show", chat_id]) == 0
|
|
35
|
+
assert "ses-cli" in capsys.readouterr().out
|
|
36
|
+
assert main(["chats"]) == 0
|
|
37
|
+
chats_out = capsys.readouterr().out
|
|
38
|
+
assert chat_id in chats_out
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_job_cwd_prompt(tmp_path) -> None:
|
|
42
|
+
cwd, prompt = _job_cwd_prompt(["hello", "world"])
|
|
43
|
+
assert prompt == "hello world"
|
|
44
|
+
cwd, prompt = _job_cwd_prompt([str(tmp_path), "do", "work"])
|
|
45
|
+
assert cwd == os.path.abspath(str(tmp_path))
|
|
46
|
+
assert prompt == "do work"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_dint_prompt_starts_chat(monkeypatch, capsys) -> None:
|
|
50
|
+
engine = FakeEngine(
|
|
51
|
+
"grok",
|
|
52
|
+
[[Event(type="text", text="pong"), Event(type="done", session_id="s1")]],
|
|
53
|
+
)
|
|
54
|
+
router = Router(
|
|
55
|
+
store=ChatLog(MemoryLogbook(), project="dint"),
|
|
56
|
+
engines={"grok": engine, "claude": FakeEngine("claude", []), "codex": FakeEngine("codex", [])},
|
|
57
|
+
)
|
|
58
|
+
monkeypatch.setattr("dint.cli.ensure_runtime", lambda **k: None)
|
|
59
|
+
monkeypatch.setattr("dint.cli.pick_engine", lambda: "grok")
|
|
60
|
+
monkeypatch.setattr("dint.cli.shutil.which", lambda name: f"/bin/{name}")
|
|
61
|
+
monkeypatch.setattr("dint.cli.Router", lambda: router)
|
|
62
|
+
assert main(["hello there"]) == 0
|
|
63
|
+
out = capsys.readouterr()
|
|
64
|
+
assert "pong" in out.out
|
|
65
|
+
chats = router.list_chats()
|
|
66
|
+
assert len(chats) == 1
|
|
67
|
+
assert chats[0]["engine"] == "grok"
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_dint_engine_prompt(monkeypatch, capsys) -> None:
|
|
71
|
+
engine = FakeEngine(
|
|
72
|
+
"claude",
|
|
73
|
+
[[Event(type="text", text="ok"), Event(type="done")]],
|
|
74
|
+
)
|
|
75
|
+
router = Router(
|
|
76
|
+
store=ChatLog(MemoryLogbook(), project="dint"),
|
|
77
|
+
engines={"claude": engine, "grok": FakeEngine("grok", [])},
|
|
78
|
+
)
|
|
79
|
+
monkeypatch.setattr("dint.cli.ensure_runtime", lambda **k: None)
|
|
80
|
+
monkeypatch.setattr("dint.cli.shutil.which", lambda name: f"/bin/{name}")
|
|
81
|
+
monkeypatch.setattr("dint.cli.Router", lambda: router)
|
|
82
|
+
assert main(["claude", "hi"]) == 0
|
|
83
|
+
assert "ok" in capsys.readouterr().out
|
|
84
|
+
assert router.list_chats()[0]["engine"] == "claude"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def test_dint_resumes_same_cwd(monkeypatch, capsys, tmp_path) -> None:
|
|
88
|
+
engine = FakeEngine(
|
|
89
|
+
"grok",
|
|
90
|
+
[
|
|
91
|
+
[Event(type="text", text="one"), Event(type="done")],
|
|
92
|
+
[Event(type="text", text="two"), Event(type="done")],
|
|
93
|
+
],
|
|
94
|
+
)
|
|
95
|
+
router = Router(
|
|
96
|
+
store=ChatLog(MemoryLogbook(), project="dint"),
|
|
97
|
+
engines={"grok": engine},
|
|
98
|
+
)
|
|
99
|
+
monkeypatch.chdir(tmp_path)
|
|
100
|
+
monkeypatch.setattr("dint.cli.ensure_runtime", lambda **k: None)
|
|
101
|
+
monkeypatch.setattr("dint.cli.pick_engine", lambda: "grok")
|
|
102
|
+
monkeypatch.setattr("dint.cli.shutil.which", lambda name: f"/bin/{name}")
|
|
103
|
+
monkeypatch.setattr("dint.cli.Router", lambda: router)
|
|
104
|
+
assert main(["first"]) == 0
|
|
105
|
+
chat_id = router.list_chats()[0]["chatId"]
|
|
106
|
+
assert main(["second"]) == 0
|
|
107
|
+
assert router.list_chats()[0]["chatId"] == chat_id
|
|
108
|
+
turns = router.list_turns(chat_id)
|
|
109
|
+
assert [t.get("text") for t in turns if t.get("role") == "user"] == ["first", "second"]
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def test_repl_help_engine_quit(monkeypatch, capsys, tmp_path) -> None:
|
|
113
|
+
monkeypatch.chdir(tmp_path)
|
|
114
|
+
monkeypatch.setattr("dint.cli.ensure_runtime", lambda **k: None)
|
|
115
|
+
monkeypatch.setattr("dint.cli.pick_engine", lambda: "grok")
|
|
116
|
+
monkeypatch.setattr("dint.cli.shutil.which", lambda name: f"/bin/{name}" if name != "codex" else None)
|
|
117
|
+
monkeypatch.setattr("dint.cli.logbook_url", lambda: "http://127.0.0.1:5101")
|
|
118
|
+
monkeypatch.setattr("dint.cli.jobs_url", lambda: "http://127.0.0.1:8787")
|
|
119
|
+
monkeypatch.setattr(sys.stdin, "isatty", lambda: True)
|
|
120
|
+
router = Router(
|
|
121
|
+
store=ChatLog(MemoryLogbook(), project="dint"),
|
|
122
|
+
engines={"grok": FakeEngine("grok", []), "claude": FakeEngine("claude", [])},
|
|
123
|
+
)
|
|
124
|
+
monkeypatch.setattr("dint.cli.Router", lambda: router)
|
|
125
|
+
lines = iter(["/help", "/engine", "/quit"])
|
|
126
|
+
monkeypatch.setattr("builtins.input", lambda prompt="": next(lines))
|
|
127
|
+
assert main([]) == 0
|
|
128
|
+
err = capsys.readouterr().err
|
|
129
|
+
assert "/job" in err and "dint job" in err
|
|
130
|
+
assert "* grok" in err
|
|
131
|
+
assert "NOT ON PATH" in err
|
|
132
|
+
assert "no chats here yet" in err
|
|
133
|
+
assert "grok " in err or "chat " in err
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def test_repl_engine_switch(monkeypatch, capsys, tmp_path) -> None:
|
|
137
|
+
monkeypatch.chdir(tmp_path)
|
|
138
|
+
monkeypatch.setattr("dint.cli.ensure_runtime", lambda **k: None)
|
|
139
|
+
monkeypatch.setattr("dint.cli.pick_engine", lambda: "grok")
|
|
140
|
+
monkeypatch.setattr("dint.cli.shutil.which", lambda name: f"/bin/{name}")
|
|
141
|
+
monkeypatch.setattr("dint.cli.logbook_url", lambda: "http://127.0.0.1:5100")
|
|
142
|
+
monkeypatch.setattr("dint.cli.jobs_url", lambda: "http://127.0.0.1:8787")
|
|
143
|
+
monkeypatch.setattr(sys.stdin, "isatty", lambda: True)
|
|
144
|
+
router = Router(
|
|
145
|
+
store=ChatLog(MemoryLogbook(), project="dint"),
|
|
146
|
+
engines={"grok": FakeEngine("grok", []), "claude": FakeEngine("claude", [])},
|
|
147
|
+
)
|
|
148
|
+
monkeypatch.setattr("dint.cli.Router", lambda: router)
|
|
149
|
+
lines = iter(["/engine claude", "/quit"])
|
|
150
|
+
monkeypatch.setattr("builtins.input", lambda prompt="": next(lines))
|
|
151
|
+
assert main([]) == 0
|
|
152
|
+
engines = {c["engine"] for c in router.list_chats()}
|
|
153
|
+
assert "claude" in engines
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def test_repl_job(monkeypatch, capsys, tmp_path) -> None:
|
|
157
|
+
monkeypatch.chdir(tmp_path)
|
|
158
|
+
monkeypatch.setattr("dint.cli.ensure_runtime", lambda **k: None)
|
|
159
|
+
monkeypatch.setattr("dint.cli.pick_engine", lambda: "grok")
|
|
160
|
+
monkeypatch.setattr("dint.cli.shutil.which", lambda name: f"/bin/{name}")
|
|
161
|
+
monkeypatch.setattr("dint.cli.logbook_url", lambda: "http://127.0.0.1:5100")
|
|
162
|
+
monkeypatch.setattr("dint.cli.jobs_url", lambda: "http://127.0.0.1:8787")
|
|
163
|
+
monkeypatch.setattr(sys.stdin, "isatty", lambda: True)
|
|
164
|
+
router = Router(
|
|
165
|
+
store=ChatLog(MemoryLogbook(), project="dint"),
|
|
166
|
+
engines={"grok": FakeEngine("grok", [])},
|
|
167
|
+
)
|
|
168
|
+
monkeypatch.setattr("dint.cli.Router", lambda: router)
|
|
169
|
+
monkeypatch.setattr("dint.jobs.post_job", lambda router, engine, prompt, cwd: "job-1")
|
|
170
|
+
monkeypatch.setattr("dint.jobs.wait_for_job_chat", lambda router, job_id, timeout=20: "chatjob")
|
|
171
|
+
lines = iter(["/job Summarize this repo", "/quit"])
|
|
172
|
+
monkeypatch.setattr("builtins.input", lambda prompt="": next(lines))
|
|
173
|
+
assert main([]) == 0
|
|
174
|
+
err = capsys.readouterr().err
|
|
175
|
+
assert "job-1" in err and "chatjob" in err
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def test_repl_unknown_slash_goes_to_engine(monkeypatch, capsys, tmp_path) -> None:
|
|
179
|
+
monkeypatch.chdir(tmp_path)
|
|
180
|
+
monkeypatch.setattr("dint.cli.ensure_runtime", lambda **k: None)
|
|
181
|
+
monkeypatch.setattr("dint.cli.pick_engine", lambda: "claude")
|
|
182
|
+
monkeypatch.setattr("dint.cli.shutil.which", lambda name: f"/bin/{name}")
|
|
183
|
+
monkeypatch.setattr("dint.cli.logbook_url", lambda: "http://127.0.0.1:5100")
|
|
184
|
+
monkeypatch.setattr("dint.cli.jobs_url", lambda: "http://127.0.0.1:8787")
|
|
185
|
+
monkeypatch.setattr(sys.stdin, "isatty", lambda: True)
|
|
186
|
+
claude = FakeEngine(
|
|
187
|
+
"claude",
|
|
188
|
+
[
|
|
189
|
+
[Event(type="text", text="login please"), Event(type="done")],
|
|
190
|
+
[Event(type="text", text="engine help"), Event(type="done")],
|
|
191
|
+
],
|
|
192
|
+
)
|
|
193
|
+
router = Router(
|
|
194
|
+
store=ChatLog(MemoryLogbook(), project="dint"),
|
|
195
|
+
engines={"claude": claude},
|
|
196
|
+
)
|
|
197
|
+
monkeypatch.setattr("dint.cli.Router", lambda: router)
|
|
198
|
+
lines = iter(["/login", "//help", "/quit"])
|
|
199
|
+
monkeypatch.setattr("builtins.input", lambda prompt="": next(lines))
|
|
200
|
+
assert main([]) == 0
|
|
201
|
+
assert [c["prompt"] for c in claude.calls] == ["/login", "/help"]
|
|
202
|
+
out = capsys.readouterr().out
|
|
203
|
+
assert "login please" in out and "engine help" in out
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def test_cli_streams_tokens_inline(capsys) -> None:
|
|
207
|
+
printer = EventPrinter()
|
|
208
|
+
printer.emit(Event(type="text", text="He"))
|
|
209
|
+
printer.emit(Event(type="text", text="j"))
|
|
210
|
+
printer.emit(Event(type="done", session_id="g1"))
|
|
211
|
+
out = capsys.readouterr().out
|
|
212
|
+
assert out.startswith("Hej\n")
|
|
213
|
+
assert "[done] session=g1" in out
|
dint_cli-0.1.1/tests/test_cli.py
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import os
|
|
4
|
-
|
|
5
|
-
from dint.cli import EventPrinter, _job_cwd_prompt, main
|
|
6
|
-
from dint.logbook import ChatLog
|
|
7
|
-
from dint.router import Router
|
|
8
|
-
from dint.types import Event
|
|
9
|
-
from test_logbook import MemoryLogbook
|
|
10
|
-
from test_router import FakeEngine
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def test_cli_start_and_list(monkeypatch, capsys) -> None:
|
|
14
|
-
engine = FakeEngine(
|
|
15
|
-
"claude",
|
|
16
|
-
[[Event(type="session", session_id="ses-cli"), Event(type="text", text="ok"), Event(type="done")]],
|
|
17
|
-
)
|
|
18
|
-
router = Router(
|
|
19
|
-
store=ChatLog(MemoryLogbook(), project="dint"),
|
|
20
|
-
engines={"claude": engine, "codex": FakeEngine("codex", []), "grok": FakeEngine("grok", [])},
|
|
21
|
-
)
|
|
22
|
-
monkeypatch.setattr("dint.cli.ensure_runtime", lambda **k: None)
|
|
23
|
-
monkeypatch.setattr("dint.cli.Router", lambda: router)
|
|
24
|
-
|
|
25
|
-
assert main(["start", "claude", "."]) == 0
|
|
26
|
-
chat_id = capsys.readouterr().out.strip()
|
|
27
|
-
assert len(chat_id) == 12
|
|
28
|
-
assert main(["send", chat_id, "hello"]) == 0
|
|
29
|
-
capsys.readouterr()
|
|
30
|
-
assert main(["list", chat_id]) == 0
|
|
31
|
-
out = capsys.readouterr().out
|
|
32
|
-
assert "hello" in out and "ok" in out
|
|
33
|
-
assert main(["show", chat_id]) == 0
|
|
34
|
-
assert "ses-cli" in capsys.readouterr().out
|
|
35
|
-
assert main(["chats"]) == 0
|
|
36
|
-
chats_out = capsys.readouterr().out
|
|
37
|
-
assert chat_id in chats_out
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def test_job_cwd_prompt(tmp_path) -> None:
|
|
41
|
-
cwd, prompt = _job_cwd_prompt(["hello", "world"])
|
|
42
|
-
assert prompt == "hello world"
|
|
43
|
-
cwd, prompt = _job_cwd_prompt([str(tmp_path), "do", "work"])
|
|
44
|
-
assert cwd == os.path.abspath(str(tmp_path))
|
|
45
|
-
assert prompt == "do work"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def test_dint_prompt_starts_chat(monkeypatch, capsys) -> None:
|
|
49
|
-
engine = FakeEngine(
|
|
50
|
-
"grok",
|
|
51
|
-
[[Event(type="text", text="pong"), Event(type="done", session_id="s1")]],
|
|
52
|
-
)
|
|
53
|
-
router = Router(
|
|
54
|
-
store=ChatLog(MemoryLogbook(), project="dint"),
|
|
55
|
-
engines={"grok": engine, "claude": FakeEngine("claude", []), "codex": FakeEngine("codex", [])},
|
|
56
|
-
)
|
|
57
|
-
monkeypatch.setattr("dint.cli.ensure_runtime", lambda **k: None)
|
|
58
|
-
monkeypatch.setattr("dint.cli.pick_engine", lambda: "grok")
|
|
59
|
-
monkeypatch.setattr("dint.cli.shutil.which", lambda name: f"/bin/{name}")
|
|
60
|
-
monkeypatch.setattr("dint.cli.Router", lambda: router)
|
|
61
|
-
assert main(["hello there"]) == 0
|
|
62
|
-
out = capsys.readouterr()
|
|
63
|
-
assert "pong" in out.out
|
|
64
|
-
chats = router.list_chats()
|
|
65
|
-
assert len(chats) == 1
|
|
66
|
-
assert chats[0]["engine"] == "grok"
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
def test_dint_engine_prompt(monkeypatch, capsys) -> None:
|
|
70
|
-
engine = FakeEngine(
|
|
71
|
-
"claude",
|
|
72
|
-
[[Event(type="text", text="ok"), Event(type="done")]],
|
|
73
|
-
)
|
|
74
|
-
router = Router(
|
|
75
|
-
store=ChatLog(MemoryLogbook(), project="dint"),
|
|
76
|
-
engines={"claude": engine, "grok": FakeEngine("grok", [])},
|
|
77
|
-
)
|
|
78
|
-
monkeypatch.setattr("dint.cli.ensure_runtime", lambda **k: None)
|
|
79
|
-
monkeypatch.setattr("dint.cli.shutil.which", lambda name: f"/bin/{name}")
|
|
80
|
-
monkeypatch.setattr("dint.cli.Router", lambda: router)
|
|
81
|
-
assert main(["claude", "hi"]) == 0
|
|
82
|
-
assert "ok" in capsys.readouterr().out
|
|
83
|
-
assert router.list_chats()[0]["engine"] == "claude"
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
def test_dint_resumes_same_cwd(monkeypatch, capsys, tmp_path) -> None:
|
|
87
|
-
engine = FakeEngine(
|
|
88
|
-
"grok",
|
|
89
|
-
[
|
|
90
|
-
[Event(type="text", text="one"), Event(type="done")],
|
|
91
|
-
[Event(type="text", text="two"), Event(type="done")],
|
|
92
|
-
],
|
|
93
|
-
)
|
|
94
|
-
router = Router(
|
|
95
|
-
store=ChatLog(MemoryLogbook(), project="dint"),
|
|
96
|
-
engines={"grok": engine},
|
|
97
|
-
)
|
|
98
|
-
monkeypatch.chdir(tmp_path)
|
|
99
|
-
monkeypatch.setattr("dint.cli.ensure_runtime", lambda **k: None)
|
|
100
|
-
monkeypatch.setattr("dint.cli.pick_engine", lambda: "grok")
|
|
101
|
-
monkeypatch.setattr("dint.cli.shutil.which", lambda name: f"/bin/{name}")
|
|
102
|
-
monkeypatch.setattr("dint.cli.Router", lambda: router)
|
|
103
|
-
assert main(["first"]) == 0
|
|
104
|
-
chat_id = router.list_chats()[0]["chatId"]
|
|
105
|
-
assert main(["second"]) == 0
|
|
106
|
-
assert router.list_chats()[0]["chatId"] == chat_id
|
|
107
|
-
turns = router.list_turns(chat_id)
|
|
108
|
-
assert [t.get("text") for t in turns if t.get("role") == "user"] == ["first", "second"]
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
def test_cli_streams_tokens_inline(capsys) -> None:
|
|
112
|
-
printer = EventPrinter()
|
|
113
|
-
printer.emit(Event(type="text", text="He"))
|
|
114
|
-
printer.emit(Event(type="text", text="j"))
|
|
115
|
-
printer.emit(Event(type="done", session_id="g1"))
|
|
116
|
-
out = capsys.readouterr().out
|
|
117
|
-
assert out.startswith("Hej\n")
|
|
118
|
-
assert "[done] session=g1" in out
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|