dint-cli 0.1.1__tar.gz → 0.1.2__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.
Files changed (37) hide show
  1. {dint_cli-0.1.1/src/dint_cli.egg-info → dint_cli-0.1.2}/PKG-INFO +2 -2
  2. {dint_cli-0.1.1 → dint_cli-0.1.2}/README.md +1 -1
  3. {dint_cli-0.1.1 → dint_cli-0.1.2}/pyproject.toml +1 -1
  4. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint/__init__.py +1 -1
  5. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint/cli.py +137 -14
  6. {dint_cli-0.1.1 → dint_cli-0.1.2/src/dint_cli.egg-info}/PKG-INFO +2 -2
  7. {dint_cli-0.1.1 → dint_cli-0.1.2}/tests/test_cli.py +67 -0
  8. {dint_cli-0.1.1 → dint_cli-0.1.2}/LICENSE +0 -0
  9. {dint_cli-0.1.1 → dint_cli-0.1.2}/setup.cfg +0 -0
  10. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint/__main__.py +0 -0
  11. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint/engines/__init__.py +0 -0
  12. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint/engines/base.py +0 -0
  13. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint/engines/claude.py +0 -0
  14. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint/engines/codex.py +0 -0
  15. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint/engines/copilot.py +0 -0
  16. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint/engines/grok.py +0 -0
  17. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint/envfile.py +0 -0
  18. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint/jobs.py +0 -0
  19. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint/logbook/__init__.py +0 -0
  20. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint/logbook/mcp.py +0 -0
  21. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint/logbook/rest.py +0 -0
  22. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint/proc.py +0 -0
  23. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint/router.py +0 -0
  24. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint/runtime.py +0 -0
  25. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint/status.py +0 -0
  26. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint/types.py +0 -0
  27. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint_cli.egg-info/SOURCES.txt +0 -0
  28. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint_cli.egg-info/dependency_links.txt +0 -0
  29. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint_cli.egg-info/entry_points.txt +0 -0
  30. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint_cli.egg-info/requires.txt +0 -0
  31. {dint_cli-0.1.1 → dint_cli-0.1.2}/src/dint_cli.egg-info/top_level.txt +0 -0
  32. {dint_cli-0.1.1 → dint_cli-0.1.2}/tests/test_engines.py +0 -0
  33. {dint_cli-0.1.1 → dint_cli-0.1.2}/tests/test_envfile.py +0 -0
  34. {dint_cli-0.1.1 → dint_cli-0.1.2}/tests/test_jobs.py +0 -0
  35. {dint_cli-0.1.1 → dint_cli-0.1.2}/tests/test_logbook.py +0 -0
  36. {dint_cli-0.1.1 → dint_cli-0.1.2}/tests/test_router.py +0 -0
  37. {dint_cli-0.1.1 → dint_cli-0.1.2}/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.1
3
+ Version: 0.1.2
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` resumes the latest chat for this folder, or starts one with the first engine CLI on PATH (`DINT_ENGINE` to pick). `/new` starts a fresh chat; `/quit` exits. Logbook and `dint serve` keep running in the background.
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` resumes the latest chat for this folder, or starts one with the first engine CLI on PATH (`DINT_ENGINE` to pick). `/new` starts a fresh chat; `/quit` exits. Logbook and `dint serve` keep running in the background.
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
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dint-cli"
3
- version = "0.1.1"
3
+ version = "0.1.2"
4
4
  description = "One local chat API over Claude, Codex, Grok, and Copilot. Codicent Logbook is the ledger."
5
5
  readme = "README.md"
6
6
  license = { file = "LICENSE" }
@@ -4,4 +4,4 @@ from dint.router import Router
4
4
  from dint.types import Chat, Event
5
5
 
6
6
  __all__ = ["Chat", "Event", "Router"]
7
- __version__ = "0.1.1"
7
+ __version__ = "0.1.2"
@@ -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
- "Run `dint` or `dint grok` in a folder to start logbook + serve and chat."
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,146 @@ 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
- print("message, /new, /quit", file=sys.stderr)
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
- if text in {"/quit", "/exit", "/q"}:
219
- return 0
220
- if text == "/new":
221
- chat_id = router.start_chat(engine, cwd)
222
- print(f"{engine} {cwd} {chat_id}", file=sys.stderr)
223
- continue
224
226
  if text.startswith("/"):
225
- print("commands: /new /quit", file=sys.stderr)
227
+ action, engine, chat_id = _slash(router, engine, cwd, chat_id, text)
228
+ if action == "quit":
229
+ return 0
226
230
  continue
227
231
  code = _send(router, chat_id, text, quiet_done=True)
228
232
  if code != 0:
229
233
  return code
230
234
 
231
235
 
236
+ def _print_banner(engine: str, cwd: str, chat_id: str, *, fresh: bool) -> None:
237
+ print(f"{engine} {cwd} chat {chat_id}", file=sys.stderr)
238
+ print(f"logbook {logbook_url()} serve {jobs_url()}", file=sys.stderr)
239
+ if fresh:
240
+ print(
241
+ f'no chats here yet — type a prompt, or: dint job {engine} "Summarize this repo"',
242
+ file=sys.stderr,
243
+ )
244
+ print("/engine /job /chats /new /help quit: Ctrl-C or /quit", file=sys.stderr)
245
+
246
+
247
+ def _print_help(engine: str) -> None:
248
+ print(
249
+ "slash:\n"
250
+ " /engine CLIs on PATH\n"
251
+ " /engine claude switch engine (new or resume in this folder)\n"
252
+ " /job [engine] text enqueue a #job (dint serve runs it)\n"
253
+ " /chats chats in this folder\n"
254
+ " /status logbook + engines\n"
255
+ " /new new chat, same engine\n"
256
+ " /help /quit\n"
257
+ "same from another shell:\n"
258
+ f' dint job {engine} "Summarize this repo"\n'
259
+ " dint chats\n"
260
+ " dint status",
261
+ file=sys.stderr,
262
+ )
263
+
264
+
265
+ def _slash(
266
+ router: Router, engine: str, cwd: str, chat_id: str, text: str
267
+ ) -> tuple[str, str, str]:
268
+ parts = text.split()
269
+ cmd = parts[0].lower()
270
+ args = parts[1:]
271
+ if cmd in {"/quit", "/exit", "/q"}:
272
+ return "quit", engine, chat_id
273
+ if cmd == "/help":
274
+ _print_help(engine)
275
+ return "ok", engine, chat_id
276
+ if cmd == "/new":
277
+ chat_id = router.start_chat(engine, cwd)
278
+ print(f"{engine} {cwd} chat {chat_id}", file=sys.stderr)
279
+ return "ok", engine, chat_id
280
+ if cmd == "/engine":
281
+ if not args:
282
+ _print_engines(engine)
283
+ return "ok", engine, chat_id
284
+ name = args[0].lower()
285
+ if name not in ENGINES:
286
+ print(f"unknown engine: {name} ({', '.join(sorted(ENGINES))})", file=sys.stderr)
287
+ return "ok", engine, chat_id
288
+ if shutil.which(name) is None:
289
+ print(f"{name} is not on PATH", file=sys.stderr)
290
+ return "ok", engine, chat_id
291
+ engine, chat_id = _resume_or_start(router, name, cwd)
292
+ print(f"{engine} {cwd} chat {chat_id}", file=sys.stderr)
293
+ return "ok", engine, chat_id
294
+ if cmd == "/chats":
295
+ _print_chats(router, cwd, chat_id)
296
+ return "ok", engine, chat_id
297
+ if cmd == "/status":
298
+ from dint.status import run_status
299
+
300
+ run_status()
301
+ return "ok", engine, chat_id
302
+ if cmd == "/job":
303
+ _slash_job(router, engine, cwd, args)
304
+ return "ok", engine, chat_id
305
+ print("commands: /engine /job /chats /status /new /help /quit", file=sys.stderr)
306
+ return "ok", engine, chat_id
307
+
308
+
309
+ def _slash_job(router: Router, engine: str, cwd: str, args: list[str]) -> None:
310
+ from dint.jobs import post_job, wait_for_job_chat
311
+
312
+ if not args:
313
+ print(f'/job [engine] prompt e.g. /job {engine} Summarize this repo', file=sys.stderr)
314
+ return
315
+ job_engine = engine
316
+ prompt_parts = args
317
+ if args[0].lower() in ENGINES:
318
+ job_engine = args[0].lower()
319
+ prompt_parts = args[1:]
320
+ prompt = " ".join(prompt_parts).strip()
321
+ if not prompt:
322
+ print("/job: prompt required", file=sys.stderr)
323
+ return
324
+ job_id = post_job(router, job_engine, prompt, cwd)
325
+ print(f"job\t{job_id}", file=sys.stderr)
326
+ new_chat = wait_for_job_chat(router, job_id)
327
+ if new_chat:
328
+ print(f"chat\t{new_chat} dint list {new_chat}", file=sys.stderr)
329
+ else:
330
+ print("waiting for dint serve... try: /chats", file=sys.stderr)
331
+
332
+
333
+ def _print_engines(current: str) -> None:
334
+ for name in sorted(ENGINES):
335
+ path = shutil.which(name)
336
+ mark = "*" if name == current else " "
337
+ print(f"{mark} {name:8} {path or 'NOT ON PATH'}", file=sys.stderr)
338
+
339
+
340
+ def _print_chats(router: Router, cwd: str, current: str) -> None:
341
+ key = _cwd_key(cwd)
342
+ rows = [c for c in router.list_chats() if _cwd_key(str(c.get("cwd") or "")) == key]
343
+ if not rows:
344
+ print("no chats in this folder dint chats", file=sys.stderr)
345
+ return
346
+ for c in rows:
347
+ mark = "*" if c.get("chatId") == current else " "
348
+ preview = (c.get("preview") or "").replace("\n", " ")[:50]
349
+ print(
350
+ f"{mark} {c.get('ts')}\t{c.get('chatId')}\t{c.get('engine')}\t{preview}",
351
+ file=sys.stderr,
352
+ )
353
+
354
+
232
355
  def _send(router: Router, chat_id: str, prompt: str, *, quiet_done: bool = False) -> int:
233
356
  printer = EventPrinter(quiet_done=quiet_done)
234
357
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dint-cli
3
- Version: 0.1.1
3
+ Version: 0.1.2
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` resumes the latest chat for this folder, or starts one with the first engine CLI on PATH (`DINT_ENGINE` to pick). `/new` starts a fresh chat; `/quit` exits. Logbook and `dint serve` keep running in the background.
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
 
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import os
4
+ import sys
4
5
 
5
6
  from dint.cli import EventPrinter, _job_cwd_prompt, main
6
7
  from dint.logbook import ChatLog
@@ -108,6 +109,72 @@ def test_dint_resumes_same_cwd(monkeypatch, capsys, tmp_path) -> None:
108
109
  assert [t.get("text") for t in turns if t.get("role") == "user"] == ["first", "second"]
109
110
 
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
+
111
178
  def test_cli_streams_tokens_inline(capsys) -> None:
112
179
  printer = EventPrinter()
113
180
  printer.emit(Event(type="text", text="He"))
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