lithe-cli 0.1.4__tar.gz → 0.1.6__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.
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/PKG-INFO +2 -2
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli/__init__.py +1 -1
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli/agent.py +18 -4
- lithe_cli-0.1.6/lithe_cli/cli_parser.py +186 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli/config.py +10 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli/main.py +3 -233
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli/ttui.py +2 -115
- lithe_cli-0.1.6/lithe_cli/ttui_render.py +122 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli/tui.py +7 -4
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli/workbench.py +2 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli.egg-info/PKG-INFO +2 -2
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli.egg-info/SOURCES.txt +2 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli.egg-info/requires.txt +1 -1
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/pyproject.toml +1 -1
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/tests/test_cli_budget_steer.py +14 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/tests/test_cli_subagents.py +32 -6
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/tests/test_tui_v2.py +13 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/LICENSE +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/README.md +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli/__main__.py +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli/clipboard.py +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli/commands.py +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli/profiles.py +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli/prompts.py +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli/py.typed +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli/sessions.py +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli/setup.py +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli/ttui_widgets.py +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli/ui.py +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli.egg-info/dependency_links.txt +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli.egg-info/entry_points.txt +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/lithe_cli.egg-info/top_level.txt +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/setup.cfg +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/tests/test_cli.py +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/tests/test_cli_clipboard.py +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/tests/test_cli_guard.py +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/tests/test_cli_sessions.py +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/tests/test_profiles.py +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/tests/test_ttui.py +0 -0
- {lithe_cli-0.1.4 → lithe_cli-0.1.6}/tests/test_workbench.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lithe-cli
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.6
|
|
4
4
|
Summary: Command-line interface for the lithe agent kernel: chat, one-shot runs, undo, and run inspection.
|
|
5
5
|
License: MIT License
|
|
6
6
|
|
|
@@ -39,7 +39,7 @@ Classifier: Typing :: Typed
|
|
|
39
39
|
Requires-Python: >=3.10
|
|
40
40
|
Description-Content-Type: text/markdown
|
|
41
41
|
License-File: LICENSE
|
|
42
|
-
Requires-Dist: lithe>=0.1.
|
|
42
|
+
Requires-Dist: lithe>=0.1.4
|
|
43
43
|
Requires-Dist: prompt-toolkit>=3.0.38
|
|
44
44
|
Requires-Dist: textual>=1.0
|
|
45
45
|
Provides-Extra: dev
|
|
@@ -130,6 +130,8 @@ def build_llm(cfg: Config) -> LLMConfig:
|
|
|
130
130
|
"api_key": cfg.api_key or "unused",
|
|
131
131
|
"timeout": cfg.timeout,
|
|
132
132
|
"attempts": cfg.attempts,
|
|
133
|
+
"sleep_429": cfg.sleep_429,
|
|
134
|
+
"sleep_err": cfg.sleep_err,
|
|
133
135
|
"stream": cfg.stream,
|
|
134
136
|
"context_window": cfg.context_window,
|
|
135
137
|
"reasoning_effort": cfg.reasoning_effort,
|
|
@@ -340,15 +342,27 @@ def tool_names(cfg: Config) -> list[str]:
|
|
|
340
342
|
return names
|
|
341
343
|
|
|
342
344
|
|
|
345
|
+
def _agent_label(ev: dict) -> str:
|
|
346
|
+
"""Display label for a delegation event: the roster display name, plus
|
|
347
|
+
the delegation instance's short suffix when present. Same-agent parallel
|
|
348
|
+
delegations (each its own instance, kernel >= 0.1.4) would otherwise be
|
|
349
|
+
indistinguishable in the live feed."""
|
|
350
|
+
who = str(ev.get("display") or ev.get("agent") or "?")
|
|
351
|
+
inst = str(ev.get("instance") or "")
|
|
352
|
+
if inst:
|
|
353
|
+
who = f"{who}·{inst.rsplit(':', 1)[-1][:4]}"
|
|
354
|
+
return who
|
|
355
|
+
|
|
356
|
+
|
|
343
357
|
def _render_subagent_progress(ev: dict) -> None:
|
|
344
|
-
"""Render one live subagent heartbeat: ``[
|
|
358
|
+
"""Render one live subagent heartbeat: ``[检索员·a3f2] ⚒ read_file · …``.
|
|
345
359
|
|
|
346
360
|
The kernel's progress hook caps text (300) and dumps ``tool_call`` args
|
|
347
361
|
to a capped JSON string, so parse them back for the label. ``step``
|
|
348
362
|
events are skipped — per-step chatter from every parallel worker is
|
|
349
363
|
noise, the tool lines carry the substance.
|
|
350
364
|
"""
|
|
351
|
-
who =
|
|
365
|
+
who = _agent_label(ev)
|
|
352
366
|
tag = ui.s(f"[{who}]", MAGENTA)
|
|
353
367
|
inner = ev.get("event") or {}
|
|
354
368
|
t = inner.get("type")
|
|
@@ -447,12 +461,12 @@ def render_event(
|
|
|
447
461
|
elif t == "subagent_start":
|
|
448
462
|
# Emitted in ToolResult.ui after the delegation finished: the
|
|
449
463
|
# per-agent record of what it was tasked with.
|
|
450
|
-
who =
|
|
464
|
+
who = _agent_label(ev)
|
|
451
465
|
task = str(ev.get("task") or "").replace("\n", " ").strip()
|
|
452
466
|
line = f"{who}:{truncate(task, max(8, ui.width - 14))}" if task else who
|
|
453
467
|
print(f" {ui.s('▸', MAGENTA)} {ui.s(line, MAGENTA)}")
|
|
454
468
|
elif t == "subagent_end":
|
|
455
|
-
who =
|
|
469
|
+
who = _agent_label(ev)
|
|
456
470
|
status = str(ev.get("status") or "")
|
|
457
471
|
zh = SUBAGENT_STATUS.get(status, status or "?")
|
|
458
472
|
color = (GREEN if status == "done"
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"""Argument parser construction for the :mod:`lithe_cli` command line."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
|
|
7
|
+
from lithe import __version__ as lithe_version
|
|
8
|
+
|
|
9
|
+
from . import __version__
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
13
|
+
p = argparse.ArgumentParser(
|
|
14
|
+
prog="lithe",
|
|
15
|
+
description="Command-line interface for the lithe agent kernel.",
|
|
16
|
+
)
|
|
17
|
+
p.add_argument(
|
|
18
|
+
"--version",
|
|
19
|
+
action="version",
|
|
20
|
+
version=f"lithe-cli {__version__} (lithe {lithe_version})",
|
|
21
|
+
)
|
|
22
|
+
sub = p.add_subparsers(dest="command")
|
|
23
|
+
|
|
24
|
+
def common(sp: argparse.ArgumentParser) -> None:
|
|
25
|
+
sp.add_argument("--api-key", help="endpoint API key (env LITHE_API_KEY)")
|
|
26
|
+
sp.add_argument("--base-url", help="endpoint base URL (env LITHE_BASE_URL)")
|
|
27
|
+
sp.add_argument("--model", help="model name (env LITHE_MODEL)")
|
|
28
|
+
sp.add_argument(
|
|
29
|
+
"--profile",
|
|
30
|
+
help="endpoint profile name (env LITHE_PROFILE; default: active "
|
|
31
|
+
"profile from lithe config --list)",
|
|
32
|
+
)
|
|
33
|
+
sp.add_argument("--workspace", help="agent workspace dir (default: cwd)")
|
|
34
|
+
sp.add_argument("--store", help="run store dir (default: ~/.lithe/runs)")
|
|
35
|
+
sp.add_argument("--user", help="user id for the store (default: cli)")
|
|
36
|
+
sp.add_argument("--download", action="store_true",
|
|
37
|
+
help="grant the agent download_file (network fetch)")
|
|
38
|
+
sp.add_argument(
|
|
39
|
+
"--code", action="store_true",
|
|
40
|
+
help="grant run_code/run_file (sandboxed Python; "
|
|
41
|
+
"bwrap when available, passthrough otherwise)",
|
|
42
|
+
)
|
|
43
|
+
sp.add_argument(
|
|
44
|
+
"--shell", action="store_true",
|
|
45
|
+
help="grant run_command (native shell with current-user host access)",
|
|
46
|
+
)
|
|
47
|
+
sp.add_argument(
|
|
48
|
+
"--skills", metavar="DIR",
|
|
49
|
+
help="markdown skill dir (default: $LITHE_HOME/skills "
|
|
50
|
+
'when it exists; "" disables)',
|
|
51
|
+
)
|
|
52
|
+
sp.add_argument("--mcp", metavar="SPEC",
|
|
53
|
+
help="MCP servers as JSON array/object or @file (env LITHE_MCP)")
|
|
54
|
+
sp.add_argument("--vision", action="store_true",
|
|
55
|
+
help="grant image_info/analyze_image (vision on the main endpoint)")
|
|
56
|
+
sp.add_argument(
|
|
57
|
+
"--document", action="store_true",
|
|
58
|
+
help="grant document_info/analyze_document "
|
|
59
|
+
"(PDF/OOXML reading on the main endpoint)",
|
|
60
|
+
)
|
|
61
|
+
sp.add_argument(
|
|
62
|
+
"--subagents", action=argparse.BooleanOptionalAction, default=True,
|
|
63
|
+
help="grant delegate/delegate_parallel on the default roster "
|
|
64
|
+
"(researcher/coder/operator). Default: on — the roster only "
|
|
65
|
+
"reuses already-enabled tools; multiplies token spend "
|
|
66
|
+
"(--no-subagents disables)",
|
|
67
|
+
)
|
|
68
|
+
sp.add_argument(
|
|
69
|
+
"--document-format", metavar="DIALECT", default=None,
|
|
70
|
+
choices=["inline-file", "files-api", "none"],
|
|
71
|
+
help="document block dialect for analyze_document: "
|
|
72
|
+
"inline-file = OpenRouter family (incl. self-built same-format "
|
|
73
|
+
"routers), files-api = strict OpenAI two-step upload "
|
|
74
|
+
"(default: profile field document_format, else provider preset)",
|
|
75
|
+
)
|
|
76
|
+
color = sp.add_mutually_exclusive_group()
|
|
77
|
+
color.add_argument("--color", action="store_true", help="force colored output")
|
|
78
|
+
color.add_argument("--no-color", action="store_true", help="disable colored output")
|
|
79
|
+
sp.add_argument("--verbose", "-v", action="store_true",
|
|
80
|
+
help="show usage/reasoning events")
|
|
81
|
+
|
|
82
|
+
def runtime(sp: argparse.ArgumentParser) -> None:
|
|
83
|
+
common(sp)
|
|
84
|
+
sp.add_argument("--stream", action="store_true", help="stream tokens as they generate")
|
|
85
|
+
sp.add_argument(
|
|
86
|
+
"--no-setup", action="store_true",
|
|
87
|
+
help="skip the first-run endpoint wizard (fail hard "
|
|
88
|
+
"when unconfigured instead of prompting)",
|
|
89
|
+
)
|
|
90
|
+
sp.add_argument("--max-steps", type=int, default=35,
|
|
91
|
+
help="tool-loop step budget (default: 35)")
|
|
92
|
+
sp.add_argument("--context-window", type=int, default=None,
|
|
93
|
+
help="model context window, for fullness gauges")
|
|
94
|
+
sp.add_argument("--timeout", type=float, default=180.0,
|
|
95
|
+
help="per-call timeout in seconds")
|
|
96
|
+
sp.add_argument("--attempts", type=int, default=2,
|
|
97
|
+
help="per-call retry attempts")
|
|
98
|
+
sp.add_argument(
|
|
99
|
+
"--sleep-429", dest="sleep_429", type=float, default=2.0,
|
|
100
|
+
help="base backoff seconds between 429 retries, jittered and "
|
|
101
|
+
"scaled by attempt (default: 2.0; 0 retries immediately)",
|
|
102
|
+
)
|
|
103
|
+
sp.add_argument(
|
|
104
|
+
"--sleep-err", dest="sleep_err", type=float, default=1.0,
|
|
105
|
+
help="base backoff seconds between other retryable failures "
|
|
106
|
+
"(5xx / network), jittered (default: 1.0; 0 retries immediately)",
|
|
107
|
+
)
|
|
108
|
+
sp.add_argument("--temperature", type=float, default=None,
|
|
109
|
+
help="sampling temperature (default: profile field, else endpoint default)")
|
|
110
|
+
sp.add_argument(
|
|
111
|
+
"--max-output-tokens", dest="max_tokens", type=int, default=None,
|
|
112
|
+
help="per-call output token cap (default: profile max_tokens, "
|
|
113
|
+
"else endpoint default); NOT the run budget --max-tokens",
|
|
114
|
+
)
|
|
115
|
+
sp.add_argument(
|
|
116
|
+
"--max-cost", type=float, default=None,
|
|
117
|
+
help="run cost budget in USD: the run ends with status "
|
|
118
|
+
"budget_exceeded once cumulative cost crosses it (needs a "
|
|
119
|
+
"pricing table on endpoints that report no usage cost)",
|
|
120
|
+
)
|
|
121
|
+
sp.add_argument(
|
|
122
|
+
"--max-tokens", dest="max_total_tokens", type=int, default=None,
|
|
123
|
+
help="run total-token budget: ends with budget_exceeded once "
|
|
124
|
+
"cumulative tokens cross it",
|
|
125
|
+
)
|
|
126
|
+
sp.add_argument(
|
|
127
|
+
"--reasoning-effort", metavar="LEVEL", default=None,
|
|
128
|
+
help="reasoning intensity (off/minimal/low/medium/high, model "
|
|
129
|
+
"dependent; profile field reasoning_effort; in-session /reasoning)",
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
run_p = sub.add_parser("run", help="run one task")
|
|
133
|
+
runtime(run_p)
|
|
134
|
+
run_p.add_argument("task", help="the task for the agent")
|
|
135
|
+
|
|
136
|
+
chat_p = sub.add_parser("chat", help="interactive session")
|
|
137
|
+
runtime(chat_p)
|
|
138
|
+
chat_p.add_argument("-c", "--continue", dest="cont", action="store_true",
|
|
139
|
+
help="resume the most recent conversation")
|
|
140
|
+
chat_p.add_argument("--resume", metavar="ID|标题",
|
|
141
|
+
help="resume a specific conversation (id or unique title prefix)")
|
|
142
|
+
chat_p.add_argument("--title", help="title for a new conversation")
|
|
143
|
+
|
|
144
|
+
sessions_p = sub.add_parser("sessions", help="list conversations")
|
|
145
|
+
common(sessions_p)
|
|
146
|
+
sessions_p.add_argument("--limit", type=int, default=30)
|
|
147
|
+
sessions_p.add_argument("--rename", nargs=2, metavar=("ID", "TITLE"))
|
|
148
|
+
sessions_p.add_argument("--delete", metavar="ID")
|
|
149
|
+
sessions_p.add_argument(
|
|
150
|
+
"--export", metavar="ID|标题",
|
|
151
|
+
help="print a conversation as plain text (pipe it: lithe sessions "
|
|
152
|
+
"--export 12 | pbcopy)",
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
models_p = sub.add_parser("models", help="list the endpoint's models (GET /models)")
|
|
156
|
+
common(models_p)
|
|
157
|
+
models_p.add_argument("--cached", action="store_true",
|
|
158
|
+
help="show only the cached list, no network")
|
|
159
|
+
|
|
160
|
+
tools_p = sub.add_parser("tools", help="list registered tools")
|
|
161
|
+
common(tools_p)
|
|
162
|
+
|
|
163
|
+
runs_p = sub.add_parser("runs", help="list stored runs")
|
|
164
|
+
common(runs_p)
|
|
165
|
+
runs_p.add_argument("--limit", type=int, default=30)
|
|
166
|
+
|
|
167
|
+
log_p = sub.add_parser("log", help="show a run's messages and actions")
|
|
168
|
+
common(log_p)
|
|
169
|
+
log_p.add_argument("run_id")
|
|
170
|
+
|
|
171
|
+
undo_p = sub.add_parser("undo", help="revert a run's mutations")
|
|
172
|
+
common(undo_p)
|
|
173
|
+
undo_p.add_argument("run_id")
|
|
174
|
+
|
|
175
|
+
sub.add_parser("doctor", help="show configuration and capability status")
|
|
176
|
+
|
|
177
|
+
config_p = sub.add_parser("config", help="interactive endpoint setup (first-run wizard)")
|
|
178
|
+
config_p.add_argument("--show", action="store_true",
|
|
179
|
+
help="print the active profile's config (key masked) and exit")
|
|
180
|
+
config_p.add_argument("--list", action="store_true",
|
|
181
|
+
help="list saved profiles and exit")
|
|
182
|
+
config_p.add_argument("--use", metavar="NAME", help="switch the active profile")
|
|
183
|
+
config_p.add_argument("--model", metavar="NAME",
|
|
184
|
+
help="set the active profile's default model")
|
|
185
|
+
|
|
186
|
+
return p
|
|
@@ -106,6 +106,14 @@ class Config:
|
|
|
106
106
|
context_window: int | None = None
|
|
107
107
|
timeout: float = 180.0
|
|
108
108
|
attempts: int = 2
|
|
109
|
+
# Retry backoff bases (LLMConfig.sleep_429 / sleep_err): an immediate
|
|
110
|
+
# duplicate request — the sleeps' 0.0 default — loses to the same
|
|
111
|
+
# rate-limit that just refused the first one, burning the retry budget
|
|
112
|
+
# of a transiently throttled gateway in milliseconds. Nonzero defaults
|
|
113
|
+
# give the one automatic retry a real chance; a Retry-After header (when
|
|
114
|
+
# the gateway sends one) always wins over the base.
|
|
115
|
+
sleep_429: float = 2.0
|
|
116
|
+
sleep_err: float = 1.0
|
|
109
117
|
download: bool = False
|
|
110
118
|
verbose: bool = False
|
|
111
119
|
code: bool = False
|
|
@@ -348,6 +356,8 @@ def load_config(args: Any) -> Config:
|
|
|
348
356
|
context_window=g("context_window", None) or saved.get("context_window"),
|
|
349
357
|
timeout=g("timeout", 180.0),
|
|
350
358
|
attempts=g("attempts", 2),
|
|
359
|
+
sleep_429=g("sleep_429", 2.0),
|
|
360
|
+
sleep_err=g("sleep_err", 1.0),
|
|
351
361
|
download=g("download", False),
|
|
352
362
|
verbose=g("verbose", False),
|
|
353
363
|
code=g("code", False),
|
|
@@ -25,7 +25,6 @@ ID|标题 picks one, and inside the TUI F3/F4 switch session/model live.
|
|
|
25
25
|
|
|
26
26
|
from __future__ import annotations
|
|
27
27
|
|
|
28
|
-
import argparse
|
|
29
28
|
import asyncio
|
|
30
29
|
import sys
|
|
31
30
|
from typing import Any
|
|
@@ -35,6 +34,7 @@ from lithe.bundles import JsonlRunStore
|
|
|
35
34
|
|
|
36
35
|
from . import __version__
|
|
37
36
|
from . import prompts
|
|
37
|
+
from .cli_parser import build_parser
|
|
38
38
|
from .agent import build_registry, execute, render_event, sandbox_backend, undo
|
|
39
39
|
from .config import config_file, load_config, require_endpoint
|
|
40
40
|
from .prompts import open_history
|
|
@@ -42,238 +42,6 @@ from .tui import screen_supported
|
|
|
42
42
|
from .ui import BOLD, CYAN, GREEN, RED, YELLOW, configure, truncate, ui
|
|
43
43
|
|
|
44
44
|
|
|
45
|
-
def build_parser() -> argparse.ArgumentParser:
|
|
46
|
-
p = argparse.ArgumentParser(
|
|
47
|
-
prog="lithe",
|
|
48
|
-
description="Command-line interface for the lithe agent kernel.",
|
|
49
|
-
)
|
|
50
|
-
p.add_argument(
|
|
51
|
-
"--version",
|
|
52
|
-
action="version",
|
|
53
|
-
version=f"lithe-cli {__version__} (lithe {lithe_version})",
|
|
54
|
-
)
|
|
55
|
-
sub = p.add_subparsers(dest="command")
|
|
56
|
-
|
|
57
|
-
def common(sp: argparse.ArgumentParser) -> None:
|
|
58
|
-
sp.add_argument("--api-key", help="endpoint API key (env LITHE_API_KEY)")
|
|
59
|
-
sp.add_argument("--base-url", help="endpoint base URL (env LITHE_BASE_URL)")
|
|
60
|
-
sp.add_argument("--model", help="model name (env LITHE_MODEL)")
|
|
61
|
-
sp.add_argument(
|
|
62
|
-
"--profile",
|
|
63
|
-
help="endpoint profile name (env LITHE_PROFILE; default: active "
|
|
64
|
-
"profile from lithe config --list)",
|
|
65
|
-
)
|
|
66
|
-
sp.add_argument("--workspace", help="agent workspace dir (default: cwd)")
|
|
67
|
-
sp.add_argument("--store", help="run store dir (default: ~/.lithe/runs)")
|
|
68
|
-
sp.add_argument("--user", help="user id for the store (default: cli)")
|
|
69
|
-
sp.add_argument(
|
|
70
|
-
"--download",
|
|
71
|
-
action="store_true",
|
|
72
|
-
help="grant the agent download_file (network fetch)",
|
|
73
|
-
)
|
|
74
|
-
sp.add_argument(
|
|
75
|
-
"--code",
|
|
76
|
-
action="store_true",
|
|
77
|
-
help="grant run_code/run_file (sandboxed Python; "
|
|
78
|
-
"bwrap when available, passthrough otherwise)",
|
|
79
|
-
)
|
|
80
|
-
sp.add_argument(
|
|
81
|
-
"--shell",
|
|
82
|
-
action="store_true",
|
|
83
|
-
help="grant run_command (native shell with current-user host access)",
|
|
84
|
-
)
|
|
85
|
-
sp.add_argument(
|
|
86
|
-
"--skills",
|
|
87
|
-
metavar="DIR",
|
|
88
|
-
help="markdown skill dir (default: $LITHE_HOME/skills "
|
|
89
|
-
'when it exists; "" disables)',
|
|
90
|
-
)
|
|
91
|
-
sp.add_argument(
|
|
92
|
-
"--mcp",
|
|
93
|
-
metavar="SPEC",
|
|
94
|
-
help="MCP servers as JSON array/object or @file (env LITHE_MCP)",
|
|
95
|
-
)
|
|
96
|
-
sp.add_argument(
|
|
97
|
-
"--vision",
|
|
98
|
-
action="store_true",
|
|
99
|
-
help="grant image_info/analyze_image (vision on the main endpoint)",
|
|
100
|
-
)
|
|
101
|
-
sp.add_argument(
|
|
102
|
-
"--document",
|
|
103
|
-
action="store_true",
|
|
104
|
-
help="grant document_info/analyze_document "
|
|
105
|
-
"(PDF/OOXML reading on the main endpoint)",
|
|
106
|
-
)
|
|
107
|
-
sp.add_argument(
|
|
108
|
-
"--subagents",
|
|
109
|
-
action=argparse.BooleanOptionalAction,
|
|
110
|
-
default=True,
|
|
111
|
-
help="grant delegate/delegate_parallel on the default roster "
|
|
112
|
-
"(researcher/coder/operator). Default: on — the roster only "
|
|
113
|
-
"reuses already-enabled tools; multiplies token spend "
|
|
114
|
-
"(--no-subagents disables)",
|
|
115
|
-
)
|
|
116
|
-
sp.add_argument(
|
|
117
|
-
"--document-format",
|
|
118
|
-
metavar="DIALECT",
|
|
119
|
-
default=None,
|
|
120
|
-
choices=["inline-file", "files-api", "none"],
|
|
121
|
-
help="document block dialect for analyze_document: "
|
|
122
|
-
"inline-file = OpenRouter family (incl. self-built same-format "
|
|
123
|
-
"routers), files-api = strict OpenAI two-step upload "
|
|
124
|
-
"(default: profile field document_format, else provider preset)",
|
|
125
|
-
)
|
|
126
|
-
color = sp.add_mutually_exclusive_group()
|
|
127
|
-
color.add_argument("--color", action="store_true", help="force colored output")
|
|
128
|
-
color.add_argument(
|
|
129
|
-
"--no-color", action="store_true", help="disable colored output"
|
|
130
|
-
)
|
|
131
|
-
sp.add_argument(
|
|
132
|
-
"--verbose", "-v", action="store_true", help="show usage/reasoning events"
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
def runtime(sp: argparse.ArgumentParser) -> None:
|
|
136
|
-
common(sp)
|
|
137
|
-
sp.add_argument(
|
|
138
|
-
"--stream", action="store_true", help="stream tokens as they generate"
|
|
139
|
-
)
|
|
140
|
-
sp.add_argument(
|
|
141
|
-
"--no-setup",
|
|
142
|
-
action="store_true",
|
|
143
|
-
help="skip the first-run endpoint wizard (fail hard "
|
|
144
|
-
"when unconfigured instead of prompting)",
|
|
145
|
-
)
|
|
146
|
-
sp.add_argument(
|
|
147
|
-
"--max-steps",
|
|
148
|
-
type=int,
|
|
149
|
-
default=35,
|
|
150
|
-
help="tool-loop step budget (default: 35)",
|
|
151
|
-
)
|
|
152
|
-
sp.add_argument(
|
|
153
|
-
"--context-window",
|
|
154
|
-
type=int,
|
|
155
|
-
default=None,
|
|
156
|
-
help="model context window, for fullness gauges",
|
|
157
|
-
)
|
|
158
|
-
sp.add_argument(
|
|
159
|
-
"--timeout", type=float, default=180.0, help="per-call timeout in seconds"
|
|
160
|
-
)
|
|
161
|
-
sp.add_argument(
|
|
162
|
-
"--attempts", type=int, default=2, help="per-call retry attempts"
|
|
163
|
-
)
|
|
164
|
-
sp.add_argument(
|
|
165
|
-
"--temperature",
|
|
166
|
-
type=float,
|
|
167
|
-
default=None,
|
|
168
|
-
help="sampling temperature (default: profile field, else endpoint default)",
|
|
169
|
-
)
|
|
170
|
-
sp.add_argument(
|
|
171
|
-
"--max-output-tokens",
|
|
172
|
-
dest="max_tokens",
|
|
173
|
-
type=int,
|
|
174
|
-
default=None,
|
|
175
|
-
help="per-call output token cap (default: profile max_tokens, "
|
|
176
|
-
"else endpoint default); NOT the run budget --max-tokens",
|
|
177
|
-
)
|
|
178
|
-
sp.add_argument(
|
|
179
|
-
"--max-cost",
|
|
180
|
-
type=float,
|
|
181
|
-
default=None,
|
|
182
|
-
help="run cost budget in USD: the run ends with status "
|
|
183
|
-
"budget_exceeded once cumulative cost crosses it (needs a "
|
|
184
|
-
"pricing table on endpoints that report no usage cost)",
|
|
185
|
-
)
|
|
186
|
-
sp.add_argument(
|
|
187
|
-
"--max-tokens",
|
|
188
|
-
dest="max_total_tokens",
|
|
189
|
-
type=int,
|
|
190
|
-
default=None,
|
|
191
|
-
help="run total-token budget: ends with budget_exceeded once "
|
|
192
|
-
"cumulative tokens cross it",
|
|
193
|
-
)
|
|
194
|
-
sp.add_argument(
|
|
195
|
-
"--reasoning-effort",
|
|
196
|
-
metavar="LEVEL",
|
|
197
|
-
default=None,
|
|
198
|
-
help="reasoning intensity (off/minimal/low/medium/high, model "
|
|
199
|
-
"dependent; profile field reasoning_effort; in-session /reasoning)",
|
|
200
|
-
)
|
|
201
|
-
|
|
202
|
-
run_p = sub.add_parser("run", help="run one task")
|
|
203
|
-
runtime(run_p)
|
|
204
|
-
run_p.add_argument("task", help="the task for the agent")
|
|
205
|
-
|
|
206
|
-
chat_p = sub.add_parser("chat", help="interactive session")
|
|
207
|
-
runtime(chat_p)
|
|
208
|
-
chat_p.add_argument(
|
|
209
|
-
"-c",
|
|
210
|
-
"--continue",
|
|
211
|
-
dest="cont",
|
|
212
|
-
action="store_true",
|
|
213
|
-
help="resume the most recent conversation",
|
|
214
|
-
)
|
|
215
|
-
chat_p.add_argument(
|
|
216
|
-
"--resume",
|
|
217
|
-
metavar="ID|标题",
|
|
218
|
-
help="resume a specific conversation (id or unique title prefix)",
|
|
219
|
-
)
|
|
220
|
-
chat_p.add_argument("--title", help="title for a new conversation")
|
|
221
|
-
|
|
222
|
-
sessions_p = sub.add_parser("sessions", help="list conversations")
|
|
223
|
-
common(sessions_p)
|
|
224
|
-
sessions_p.add_argument("--limit", type=int, default=30)
|
|
225
|
-
sessions_p.add_argument("--rename", nargs=2, metavar=("ID", "TITLE"))
|
|
226
|
-
sessions_p.add_argument("--delete", metavar="ID")
|
|
227
|
-
sessions_p.add_argument(
|
|
228
|
-
"--export", metavar="ID|标题",
|
|
229
|
-
help="print a conversation as plain text (pipe it: lithe sessions "
|
|
230
|
-
"--export 12 | pbcopy)",
|
|
231
|
-
)
|
|
232
|
-
|
|
233
|
-
models_p = sub.add_parser(
|
|
234
|
-
"models", help="list the endpoint's models (GET /models)"
|
|
235
|
-
)
|
|
236
|
-
common(models_p)
|
|
237
|
-
models_p.add_argument(
|
|
238
|
-
"--cached", action="store_true", help="show only the cached list, no network"
|
|
239
|
-
)
|
|
240
|
-
|
|
241
|
-
tools_p = sub.add_parser("tools", help="list registered tools")
|
|
242
|
-
common(tools_p)
|
|
243
|
-
|
|
244
|
-
runs_p = sub.add_parser("runs", help="list stored runs")
|
|
245
|
-
common(runs_p)
|
|
246
|
-
runs_p.add_argument("--limit", type=int, default=30)
|
|
247
|
-
|
|
248
|
-
log_p = sub.add_parser("log", help="show a run's messages and actions")
|
|
249
|
-
common(log_p)
|
|
250
|
-
log_p.add_argument("run_id")
|
|
251
|
-
|
|
252
|
-
undo_p = sub.add_parser("undo", help="revert a run's mutations")
|
|
253
|
-
common(undo_p)
|
|
254
|
-
undo_p.add_argument("run_id")
|
|
255
|
-
|
|
256
|
-
sub.add_parser("doctor", help="show configuration and capability status")
|
|
257
|
-
|
|
258
|
-
config_p = sub.add_parser(
|
|
259
|
-
"config", help="interactive endpoint setup (first-run wizard)"
|
|
260
|
-
)
|
|
261
|
-
config_p.add_argument(
|
|
262
|
-
"--show",
|
|
263
|
-
action="store_true",
|
|
264
|
-
help="print the active profile's config (key masked) and exit",
|
|
265
|
-
)
|
|
266
|
-
config_p.add_argument(
|
|
267
|
-
"--list", action="store_true", help="list saved profiles and exit"
|
|
268
|
-
)
|
|
269
|
-
config_p.add_argument("--use", metavar="NAME", help="switch the active profile")
|
|
270
|
-
config_p.add_argument(
|
|
271
|
-
"--model", metavar="NAME", help="set the active profile's default model"
|
|
272
|
-
)
|
|
273
|
-
|
|
274
|
-
return p
|
|
275
|
-
|
|
276
|
-
|
|
277
45
|
def _cmd_tools(cfg: Any) -> int:
|
|
278
46
|
reg = build_registry(cfg)
|
|
279
47
|
rows = []
|
|
@@ -327,6 +95,8 @@ def _cmd_log(cfg: Any, run_id: str) -> int:
|
|
|
327
95
|
+ (f" 耗时={duration}" if duration else "")
|
|
328
96
|
)
|
|
329
97
|
print(f"task: {run.task}")
|
|
98
|
+
if run.error:
|
|
99
|
+
print(ui.s(f"error: {run.error[:500]}", RED))
|
|
330
100
|
if run.final:
|
|
331
101
|
print(f"final: {run.final[:500]}")
|
|
332
102
|
print(ui.section("messages"))
|
|
@@ -42,129 +42,16 @@ from .tui import (
|
|
|
42
42
|
feed_text,
|
|
43
43
|
transcript_feed_lines,
|
|
44
44
|
)
|
|
45
|
-
from .ui import fmt_duration
|
|
45
|
+
from .ui import fmt_duration as fmt_duration # noqa: F401 — legacy re-export
|
|
46
46
|
from . import ttui_widgets as _widgets
|
|
47
47
|
from .ttui_widgets import (
|
|
48
48
|
ConfirmModal, ConversationPane, HistoryInput, PickerModal, WbEvent,
|
|
49
49
|
completion_suggestions, selected_text,
|
|
50
50
|
)
|
|
51
|
+
from .ttui_render import footer_text, header_text, sidebar_markup
|
|
51
52
|
|
|
52
53
|
_MAX_FEED = 400 # mounted conversation lines before trimming the oldest
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
# -- pure text builders (shared with tests) -----------------------------------
|
|
56
|
-
|
|
57
|
-
def header_text(state: TuiState, version: str) -> str:
|
|
58
|
-
who = f"{state.profile} · {state.model}" if state.profile else state.model
|
|
59
|
-
if state.session_id is not None:
|
|
60
|
-
who = f"▣ #{state.session_id} {state.session_title or '无标题'} │ {who}"
|
|
61
|
-
return f" lithe {version} · {who} · {state.workspace}"
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
def sidebar_markup(state: TuiState) -> str:
|
|
65
|
-
out: list[str] = []
|
|
66
|
-
out.append("[dim]◆ 会话[/]")
|
|
67
|
-
if state.session_id is None:
|
|
68
|
-
out.append("[dim](单次运行,无会话)[/]")
|
|
69
|
-
else:
|
|
70
|
-
dot = "[yellow]●[/]" if state.session_id in state.busy_sessions else "·"
|
|
71
|
-
out.append(f"#{state.session_id} {state.session_title or '无标题'} {dot}")
|
|
72
|
-
shown = 0
|
|
73
|
-
for row in state.sessions:
|
|
74
|
-
if shown >= 3:
|
|
75
|
-
break
|
|
76
|
-
if row.get("id") == state.session_id:
|
|
77
|
-
continue
|
|
78
|
-
shown += 1
|
|
79
|
-
mark = "[yellow]●[/]" if row["id"] in state.busy_sessions else (
|
|
80
|
-
"[green]✓[/]" if row.get("last_status") == "done" else "·")
|
|
81
|
-
out.append(f"[dim] #{row['id']} {row.get('title') or ''} "
|
|
82
|
-
f"{mark} {row.get('n_runs', 0)}轮[/]")
|
|
83
|
-
out.append("[dim]F3 切换 · /new 新建[/]")
|
|
84
|
-
out.append("[dim]◆ 模型[/]")
|
|
85
|
-
label = f"{state.profile} · {state.model}" if state.profile else state.model
|
|
86
|
-
out.append(f"[cyan]{label}[/]")
|
|
87
|
-
if state.reasoning_effort:
|
|
88
|
-
out.append(f"[dim]推理 {state.reasoning_effort} · F6 切换[/]")
|
|
89
|
-
if state.context_window:
|
|
90
|
-
out.append(f"[dim]窗口 {state.context_window:,} · F4 切换[/]")
|
|
91
|
-
else:
|
|
92
|
-
out.append("[dim]F4 或 /model 切换[/]")
|
|
93
|
-
out.append("[dim]◆ 运行[/]")
|
|
94
|
-
if state.running:
|
|
95
|
-
status_color = "yellow"
|
|
96
|
-
elif state.status in ("就绪",) or "完成" in state.status or "取消" in state.status:
|
|
97
|
-
status_color = "green"
|
|
98
|
-
else:
|
|
99
|
-
status_color = "red"
|
|
100
|
-
out.append(f"[{status_color}]● {state.status}[/]")
|
|
101
|
-
out.append(f"[dim]步骤 {state.step}/{state.max_steps}[/]")
|
|
102
|
-
live = state.elapsed()
|
|
103
|
-
if state.running:
|
|
104
|
-
if live is not None:
|
|
105
|
-
out.append(f"[yellow]已进行 {fmt_duration(live)}[/]")
|
|
106
|
-
elif state.last_turn_duration is not None:
|
|
107
|
-
out.append(f"[dim]本轮耗时 {fmt_duration(state.last_turn_duration)}[/]")
|
|
108
|
-
out.append("[dim]◆ 工具[/]")
|
|
109
|
-
if not state.tools:
|
|
110
|
-
out.append("[dim]暂无调用[/]")
|
|
111
|
-
for tool in state.tools[-4:]:
|
|
112
|
-
mark = {"running": "…", "done": "✓", "failed": "✗"}.get(tool["status"], "·")
|
|
113
|
-
tcolor = "green" if tool["status"] == "done" else (
|
|
114
|
-
"red" if tool["status"] == "failed" else "cyan")
|
|
115
|
-
suffix = f" {tool['elapsed']:.1f}s" if tool.get("elapsed") is not None else ""
|
|
116
|
-
out.append(f"[{tcolor}]{mark} {tool['name']}{suffix}[/]")
|
|
117
|
-
done = sum(todo.get("status") == "completed" for todo in state.todos)
|
|
118
|
-
out.append(f"[dim]◆ 待办 {done}/{len(state.todos)}[/]")
|
|
119
|
-
if not state.todos:
|
|
120
|
-
out.append("[dim]暂无任务清单[/]")
|
|
121
|
-
marks = {"pending": "[ ]", "in_progress": "[~]",
|
|
122
|
-
"completed": "[x]", "cancelled": "[-]"}
|
|
123
|
-
tcolors = {"pending": "dim", "in_progress": "yellow",
|
|
124
|
-
"completed": "green", "cancelled": "dim"}
|
|
125
|
-
for todo in state.todos[-5:]:
|
|
126
|
-
status = todo.get("status")
|
|
127
|
-
out.append(f"[{tcolors.get(status, 'dim')}]"
|
|
128
|
-
f"{marks.get(status, '[ ]')} {todo.get('content', '')}[/]")
|
|
129
|
-
input_tokens = state.input_tokens + state._turn_input_tokens
|
|
130
|
-
output_tokens = state.output_tokens + state._turn_output_tokens
|
|
131
|
-
cached_tokens = state.cached_tokens + state._turn_cached_tokens
|
|
132
|
-
tokens = state.tokens + state._turn_tokens
|
|
133
|
-
cost = state.cost + state._turn_cost
|
|
134
|
-
turn_cost = (state._turn_cost if state.running or not state._done_seen
|
|
135
|
-
else state.last_turn_cost)
|
|
136
|
-
context = "—"
|
|
137
|
-
if state.context_tokens is not None:
|
|
138
|
-
context = f"{state.context_tokens:,}"
|
|
139
|
-
if state.context_window:
|
|
140
|
-
context += f" / {state.context_window:,}"
|
|
141
|
-
if state.context_percent is not None:
|
|
142
|
-
context += f" ({state.context_percent}%)"
|
|
143
|
-
out.append("[dim]◆ 会话用量[/]")
|
|
144
|
-
out.append(f"输入 {input_tokens:,}")
|
|
145
|
-
out.append(f"输出 {output_tokens:,}")
|
|
146
|
-
out.append(f"缓存输入 {cached_tokens:,}")
|
|
147
|
-
out.append(f"合计 {tokens:,}")
|
|
148
|
-
out.append(f"本轮费用 ${turn_cost:.4f}")
|
|
149
|
-
out.append(f"累计费用 ${cost:.4f}")
|
|
150
|
-
if state.max_cost is not None:
|
|
151
|
-
out.append(f"[dim]成本预算 ${cost:.4f} / ${state.max_cost:.2f}[/]")
|
|
152
|
-
if state.max_total_tokens is not None:
|
|
153
|
-
out.append(f"[dim]token 预算 {tokens:,} / {state.max_total_tokens:,}[/]")
|
|
154
|
-
out.append(f"上下文 {context}")
|
|
155
|
-
return "\n".join(out)
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
def footer_text(state: TuiState) -> str:
|
|
159
|
-
if state.running:
|
|
160
|
-
live = state.elapsed()
|
|
161
|
-
timer = f" · {fmt_duration(live)}" if live is not None else ""
|
|
162
|
-
return (f" ● {state.status}{timer} · Ctrl+C 取消 · F3 会话"
|
|
163
|
-
f" · F4 模型 · F6 推理 ")
|
|
164
|
-
return (f" ● {state.status} · Enter 发送 · F2 侧栏 · F3 会话 · F4 模型"
|
|
165
|
-
f" · F5 设置 · F6 推理 · /help ")
|
|
166
|
-
|
|
167
|
-
|
|
168
55
|
# -- the app ----------------------------------------------------------------------
|
|
169
56
|
|
|
170
57
|
class LitheApp(App):
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""Pure text builders for the Textual interface.
|
|
2
|
+
|
|
3
|
+
Keeping display formatting separate from the application/event loop makes
|
|
4
|
+
the sidebar and chrome easy to test without mounting a Textual app. The
|
|
5
|
+
historical imports from :mod:`lithe_cli.ttui` remain available there.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from .tui import TuiState
|
|
11
|
+
from .ui import fmt_duration
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def header_text(state: TuiState, version: str) -> str:
|
|
15
|
+
who = f"{state.profile} · {state.model}" if state.profile else state.model
|
|
16
|
+
if state.session_id is not None:
|
|
17
|
+
who = f"▣ #{state.session_id} {state.session_title or '无标题'} │ {who}"
|
|
18
|
+
return f" lithe {version} · {who} · {state.workspace}"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def sidebar_markup(state: TuiState) -> str:
|
|
22
|
+
out: list[str] = []
|
|
23
|
+
out.append("[dim]◆ 会话[/]")
|
|
24
|
+
if state.session_id is None:
|
|
25
|
+
out.append("[dim](单次运行,无会话)[/]")
|
|
26
|
+
else:
|
|
27
|
+
dot = "[yellow]●[/]" if state.session_id in state.busy_sessions else "·"
|
|
28
|
+
out.append(f"#{state.session_id} {state.session_title or '无标题'} {dot}")
|
|
29
|
+
shown = 0
|
|
30
|
+
for row in state.sessions:
|
|
31
|
+
if shown >= 3:
|
|
32
|
+
break
|
|
33
|
+
if row.get("id") == state.session_id:
|
|
34
|
+
continue
|
|
35
|
+
shown += 1
|
|
36
|
+
mark = "[yellow]●[/]" if row["id"] in state.busy_sessions else (
|
|
37
|
+
"[green]✓[/]" if row.get("last_status") == "done" else "·")
|
|
38
|
+
out.append(f"[dim] #{row['id']} {row.get('title') or ''} "
|
|
39
|
+
f"{mark} {row.get('n_runs', 0)}轮[/]")
|
|
40
|
+
out.append("[dim]F3 切换 · /new 新建[/]")
|
|
41
|
+
out.append("[dim]◆ 模型[/]")
|
|
42
|
+
label = f"{state.profile} · {state.model}" if state.profile else state.model
|
|
43
|
+
out.append(f"[cyan]{label}[/]")
|
|
44
|
+
if state.reasoning_effort:
|
|
45
|
+
out.append(f"[dim]推理 {state.reasoning_effort} · F6 切换[/]")
|
|
46
|
+
if state.context_window:
|
|
47
|
+
out.append(f"[dim]窗口 {state.context_window:,} · F4 切换[/]")
|
|
48
|
+
else:
|
|
49
|
+
out.append("[dim]F4 或 /model 切换[/]")
|
|
50
|
+
out.append("[dim]◆ 运行[/]")
|
|
51
|
+
if state.running:
|
|
52
|
+
status_color = "yellow"
|
|
53
|
+
elif state.status in ("就绪",) or "完成" in state.status or "取消" in state.status:
|
|
54
|
+
status_color = "green"
|
|
55
|
+
else:
|
|
56
|
+
status_color = "red"
|
|
57
|
+
out.append(f"[{status_color}]● {state.status}[/]")
|
|
58
|
+
out.append(f"[dim]步骤 {state.step}/{state.max_steps}[/]")
|
|
59
|
+
live = state.elapsed()
|
|
60
|
+
if state.running:
|
|
61
|
+
if live is not None:
|
|
62
|
+
out.append(f"[yellow]已进行 {fmt_duration(live)}[/]")
|
|
63
|
+
elif state.last_turn_duration is not None:
|
|
64
|
+
out.append(f"[dim]本轮耗时 {fmt_duration(state.last_turn_duration)}[/]")
|
|
65
|
+
out.append("[dim]◆ 工具[/]")
|
|
66
|
+
if not state.tools:
|
|
67
|
+
out.append("[dim]暂无调用[/]")
|
|
68
|
+
for tool in state.tools[-4:]:
|
|
69
|
+
mark = {"running": "…", "done": "✓", "failed": "✗"}.get(tool["status"], "·")
|
|
70
|
+
tcolor = "green" if tool["status"] == "done" else (
|
|
71
|
+
"red" if tool["status"] == "failed" else "cyan")
|
|
72
|
+
suffix = f" {tool['elapsed']:.1f}s" if tool.get("elapsed") is not None else ""
|
|
73
|
+
out.append(f"[{tcolor}]{mark} {tool['name']}{suffix}[/]")
|
|
74
|
+
done = sum(todo.get("status") == "completed" for todo in state.todos)
|
|
75
|
+
out.append(f"[dim]◆ 待办 {done}/{len(state.todos)}[/]")
|
|
76
|
+
if not state.todos:
|
|
77
|
+
out.append("[dim]暂无任务清单[/]")
|
|
78
|
+
marks = {"pending": "[ ]", "in_progress": "[~]",
|
|
79
|
+
"completed": "[x]", "cancelled": "[-]"}
|
|
80
|
+
tcolors = {"pending": "dim", "in_progress": "yellow",
|
|
81
|
+
"completed": "green", "cancelled": "dim"}
|
|
82
|
+
for todo in state.todos[-5:]:
|
|
83
|
+
status = todo.get("status")
|
|
84
|
+
out.append(f"[{tcolors.get(status, 'dim')}]"
|
|
85
|
+
f"{marks.get(status, '[ ]')} {todo.get('content', '')}[/]")
|
|
86
|
+
input_tokens = state.input_tokens + state._turn_input_tokens
|
|
87
|
+
output_tokens = state.output_tokens + state._turn_output_tokens
|
|
88
|
+
cached_tokens = state.cached_tokens + state._turn_cached_tokens
|
|
89
|
+
tokens = state.tokens + state._turn_tokens
|
|
90
|
+
cost = state.cost + state._turn_cost
|
|
91
|
+
turn_cost = (state._turn_cost if state.running or not state._done_seen
|
|
92
|
+
else state.last_turn_cost)
|
|
93
|
+
context = "—"
|
|
94
|
+
if state.context_tokens is not None:
|
|
95
|
+
context = f"{state.context_tokens:,}"
|
|
96
|
+
if state.context_window:
|
|
97
|
+
context += f" / {state.context_window:,}"
|
|
98
|
+
if state.context_percent is not None:
|
|
99
|
+
context += f" ({state.context_percent}%)"
|
|
100
|
+
out.append("[dim]◆ 会话用量[/]")
|
|
101
|
+
out.append(f"输入 {input_tokens:,}")
|
|
102
|
+
out.append(f"输出 {output_tokens:,}")
|
|
103
|
+
out.append(f"缓存输入 {cached_tokens:,}")
|
|
104
|
+
out.append(f"合计 {tokens:,}")
|
|
105
|
+
out.append(f"本轮费用 ${turn_cost:.4f}")
|
|
106
|
+
out.append(f"累计费用 ${cost:.4f}")
|
|
107
|
+
if state.max_cost is not None:
|
|
108
|
+
out.append(f"[dim]成本预算 ${cost:.4f} / ${state.max_cost:.2f}[/]")
|
|
109
|
+
if state.max_total_tokens is not None:
|
|
110
|
+
out.append(f"[dim]token 预算 {tokens:,} / {state.max_total_tokens:,}[/]")
|
|
111
|
+
out.append(f"上下文 {context}")
|
|
112
|
+
return "\n".join(out)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def footer_text(state: TuiState) -> str:
|
|
116
|
+
if state.running:
|
|
117
|
+
live = state.elapsed()
|
|
118
|
+
timer = f" · {fmt_duration(live)}" if live is not None else ""
|
|
119
|
+
return (f" ● {state.status}{timer} · Ctrl+C 取消 · F3 会话"
|
|
120
|
+
f" · F4 模型 · F6 推理 ")
|
|
121
|
+
return (f" ● {state.status} · Enter 发送 · F2 侧栏 · F3 会话 · F4 模型"
|
|
122
|
+
f" · F5 设置 · F6 推理 · /help ")
|
|
@@ -26,6 +26,7 @@ import os
|
|
|
26
26
|
import sys
|
|
27
27
|
import time
|
|
28
28
|
|
|
29
|
+
from .agent import _agent_label
|
|
29
30
|
from .ui import SUBAGENT_STATUS, fmt_duration, tool_call_label, truncate
|
|
30
31
|
|
|
31
32
|
_STATUS_DONE = "done"
|
|
@@ -246,12 +247,14 @@ class TuiState:
|
|
|
246
247
|
self.say("user", str(ev.get("text") or ""))
|
|
247
248
|
elif kind == "subagent_start":
|
|
248
249
|
# Per-delegation record (ToolResult.ui): which worker got what
|
|
249
|
-
# task — the group's feed line, labeled with the display name
|
|
250
|
-
|
|
250
|
+
# task — the group's feed line, labeled with the display name
|
|
251
|
+
# (plus the instance suffix that keeps same-agent parallel
|
|
252
|
+
# delegations distinguishable).
|
|
253
|
+
who = _agent_label(ev)
|
|
251
254
|
task = str(ev.get("task") or "").replace("\n", " ").strip()
|
|
252
255
|
self.say("tool", f"▸ {who}:{task[:120]}" if task else f"▸ {who}")
|
|
253
256
|
elif kind == "subagent_end":
|
|
254
|
-
who =
|
|
257
|
+
who = _agent_label(ev)
|
|
255
258
|
status = str(ev.get("status") or "")
|
|
256
259
|
bits = [SUBAGENT_STATUS.get(status, status or "?")]
|
|
257
260
|
if ev.get("steps") is not None:
|
|
@@ -265,7 +268,7 @@ class TuiState:
|
|
|
265
268
|
# Live heartbeat (kernel on_subagent_event, wired in
|
|
266
269
|
# register_subagents): each worker's tool calls and outputs,
|
|
267
270
|
# prefixed so parallel workers stay distinguishable.
|
|
268
|
-
who =
|
|
271
|
+
who = _agent_label(ev)
|
|
269
272
|
inner = ev.get("event") or {}
|
|
270
273
|
t = inner.get("type")
|
|
271
274
|
if t == "tool_call":
|
|
@@ -49,6 +49,8 @@ _SETTING_DEFS: list[tuple[str, str, str, str]] = [
|
|
|
49
49
|
("max-steps", "max_steps", "工具循环步数上限", "int"),
|
|
50
50
|
("timeout", "timeout", "单次模型调用超时(秒)", "float"),
|
|
51
51
|
("attempts", "attempts", "模型调用重试次数", "int"),
|
|
52
|
+
("sleep-429", "sleep_429", "429 重试退避基数(秒)", "float"),
|
|
53
|
+
("sleep-err", "sleep_err", "网络/5xx 重试退避基数(秒)", "float"),
|
|
52
54
|
("temperature", "temperature", "采样温度(off = 端点默认)", "float"),
|
|
53
55
|
("max-output-tokens", "max_tokens", "单次调用输出上限(off = 端点默认)", "int"),
|
|
54
56
|
("max-cost", "max_cost", "单轮成本预算 $(off = 不限)", "float"),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lithe-cli
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.6
|
|
4
4
|
Summary: Command-line interface for the lithe agent kernel: chat, one-shot runs, undo, and run inspection.
|
|
5
5
|
License: MIT License
|
|
6
6
|
|
|
@@ -39,7 +39,7 @@ Classifier: Typing :: Typed
|
|
|
39
39
|
Requires-Python: >=3.10
|
|
40
40
|
Description-Content-Type: text/markdown
|
|
41
41
|
License-File: LICENSE
|
|
42
|
-
Requires-Dist: lithe>=0.1.
|
|
42
|
+
Requires-Dist: lithe>=0.1.4
|
|
43
43
|
Requires-Dist: prompt-toolkit>=3.0.38
|
|
44
44
|
Requires-Dist: textual>=1.0
|
|
45
45
|
Provides-Extra: dev
|
|
@@ -4,6 +4,7 @@ pyproject.toml
|
|
|
4
4
|
lithe_cli/__init__.py
|
|
5
5
|
lithe_cli/__main__.py
|
|
6
6
|
lithe_cli/agent.py
|
|
7
|
+
lithe_cli/cli_parser.py
|
|
7
8
|
lithe_cli/clipboard.py
|
|
8
9
|
lithe_cli/commands.py
|
|
9
10
|
lithe_cli/config.py
|
|
@@ -14,6 +15,7 @@ lithe_cli/py.typed
|
|
|
14
15
|
lithe_cli/sessions.py
|
|
15
16
|
lithe_cli/setup.py
|
|
16
17
|
lithe_cli/ttui.py
|
|
18
|
+
lithe_cli/ttui_render.py
|
|
17
19
|
lithe_cli/ttui_widgets.py
|
|
18
20
|
lithe_cli/tui.py
|
|
19
21
|
lithe_cli/ui.py
|
|
@@ -9,7 +9,7 @@ description = "Command-line interface for the lithe agent kernel: chat, one-shot
|
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { file = "LICENSE" }
|
|
11
11
|
requires-python = ">=3.10"
|
|
12
|
-
dependencies = ["lithe>=0.1.
|
|
12
|
+
dependencies = ["lithe>=0.1.4", "prompt-toolkit>=3.0.38", "textual>=1.0"]
|
|
13
13
|
keywords = ["agent", "llm", "react", "cli", "tool-calling"]
|
|
14
14
|
classifiers = [
|
|
15
15
|
"Development Status :: 4 - Beta",
|
|
@@ -98,6 +98,20 @@ def test_preset_extra_body_merges_under_profile_fields(tmp_path):
|
|
|
98
98
|
assert llm.extra_body.get("route") == "fallback"
|
|
99
99
|
|
|
100
100
|
|
|
101
|
+
def test_retry_backoff_reaches_llm_config(tmp_path):
|
|
102
|
+
"""重试必须带退避基数:立即原样重发只会再撞同一个限流——一次瞬时
|
|
103
|
+
上游错误就能连杀委派与编排者的下一次调用(会话 #54 的失败形状)。
|
|
104
|
+
默认非零,且 profile 字段可覆盖。"""
|
|
105
|
+
cfg = make_config(tmp_path, [])
|
|
106
|
+
assert cfg.sleep_429 == 2.0 and cfg.sleep_err == 1.0
|
|
107
|
+
llm = build_llm(cfg)
|
|
108
|
+
assert llm.attempts == 2
|
|
109
|
+
assert llm.sleep_429 == 2.0 and llm.sleep_err == 1.0
|
|
110
|
+
cfg.sleep_429, cfg.sleep_err = 5.0, 0.0
|
|
111
|
+
llm = build_llm(cfg)
|
|
112
|
+
assert llm.sleep_429 == 5.0 and llm.sleep_err == 0.0
|
|
113
|
+
|
|
114
|
+
|
|
101
115
|
def test_set_budget_and_sampling_knobs(tmp_path):
|
|
102
116
|
cfg = make_config(tmp_path, [])
|
|
103
117
|
wb = Workbench(cfg)
|
|
@@ -9,6 +9,7 @@ from __future__ import annotations
|
|
|
9
9
|
|
|
10
10
|
import asyncio
|
|
11
11
|
import json
|
|
12
|
+
import re
|
|
12
13
|
|
|
13
14
|
from lithe_cli.agent import (
|
|
14
15
|
build_host,
|
|
@@ -62,6 +63,27 @@ def test_delegation_enabled_by_default_with_opt_out(tmp_path):
|
|
|
62
63
|
assert "delegate" not in build_system_prompt(off)
|
|
63
64
|
|
|
64
65
|
|
|
66
|
+
def test_parser_split_preserves_all_runtime_options():
|
|
67
|
+
from lithe_cli.cli_parser import build_parser as parser_builder
|
|
68
|
+
from lithe_cli.main import build_parser
|
|
69
|
+
|
|
70
|
+
args = build_parser().parse_args([
|
|
71
|
+
"run", "--no-subagents", "--no-setup", "--stream",
|
|
72
|
+
"--max-steps", "7", "--context-window", "8192", "--timeout", "12",
|
|
73
|
+
"--attempts", "4", "--temperature", "0.2", "--max-output-tokens", "99",
|
|
74
|
+
"--max-cost", "1.5", "--max-tokens", "200", "--reasoning-effort", "low",
|
|
75
|
+
"--sleep-429", "3.5", "--sleep-err", "0.5",
|
|
76
|
+
"task",
|
|
77
|
+
])
|
|
78
|
+
assert args.subagents is False
|
|
79
|
+
assert args.no_setup and args.stream
|
|
80
|
+
assert (args.max_steps, args.context_window, args.timeout, args.attempts) == (7, 8192, 12, 4)
|
|
81
|
+
assert (args.temperature, args.max_tokens) == (0.2, 99)
|
|
82
|
+
assert (args.max_cost, args.max_total_tokens, args.reasoning_effort) == (1.5, 200, "low")
|
|
83
|
+
assert (args.sleep_429, args.sleep_err) == (3.5, 0.5)
|
|
84
|
+
assert parser_builder().parse_args(["tools"]).command == "tools"
|
|
85
|
+
|
|
86
|
+
|
|
65
87
|
def test_delegation_runs_and_records_child_messages(tmp_path, capsys):
|
|
66
88
|
cfg = make_config(tmp_path, DELEGATE_SCRIPT)
|
|
67
89
|
cfg.subagents = True
|
|
@@ -74,10 +96,12 @@ def test_delegation_runs_and_records_child_messages(tmp_path, capsys):
|
|
|
74
96
|
assert done["status"] == "done"
|
|
75
97
|
out = capsys.readouterr().out
|
|
76
98
|
assert "子代理已确认" in out
|
|
77
|
-
# the child's messages are recorded under the run, tagged
|
|
99
|
+
# the child's messages are recorded under the run, tagged with the
|
|
100
|
+
# delegation instance ("<agent>:<hex8>", kernel >= 0.1.4)
|
|
78
101
|
rows = host.store.messages_for_run(rid, cfg.user_id)
|
|
79
|
-
tagged = [r for r in rows
|
|
80
|
-
|
|
102
|
+
tagged = [r for r in rows
|
|
103
|
+
if str(r.get("subagent") or "").startswith("researcher:")]
|
|
104
|
+
assert tagged, "researcher's turns must be recorded with its instance tag"
|
|
81
105
|
assert any("a.md" in (r.get("content") or "") for r in tagged)
|
|
82
106
|
|
|
83
107
|
|
|
@@ -151,11 +175,13 @@ def test_delegation_renders_live_progress_and_records(tmp_path, capsys):
|
|
|
151
175
|
# the parallel call line names the roster and the task count
|
|
152
176
|
assert "researcher(1 项)" in out
|
|
153
177
|
# live heartbeat: the worker's answer, labeled with its display name
|
|
154
|
-
|
|
178
|
+
# plus the delegation-instance suffix (kernel >= 0.1.4) that keeps
|
|
179
|
+
# same-agent parallel delegations distinguishable
|
|
180
|
+
assert re.search(r"\[检索员·[0-9a-f]{4}\]", out)
|
|
155
181
|
assert "a.md 的内容是待办清单" in out
|
|
156
182
|
# per-agent start/end records follow the delegation's tool_result
|
|
157
|
-
assert "▸
|
|
158
|
-
assert "▪
|
|
183
|
+
assert re.search(r"▸ 检索员·[0-9a-f]{4}:找一下 a\.md 里写了什么", out)
|
|
184
|
+
assert re.search(r"▪ 检索员·[0-9a-f]{4} · 完成", out)
|
|
159
185
|
# the footer carries the delegation footprint
|
|
160
186
|
assert "delegations 1" in out
|
|
161
187
|
|
|
@@ -101,6 +101,19 @@ def test_header_shows_profile_and_session():
|
|
|
101
101
|
assert "zhipu · glm-4.6" in text and "#12" in text and "重构计划" in text
|
|
102
102
|
|
|
103
103
|
|
|
104
|
+
def test_render_builders_keep_the_legacy_ttui_import_path():
|
|
105
|
+
from lithe_cli.ttui import footer_text as legacy_footer
|
|
106
|
+
from lithe_cli.ttui import header_text as legacy_header
|
|
107
|
+
from lithe_cli.ttui import sidebar_markup as legacy_sidebar
|
|
108
|
+
from lithe_cli.ttui_render import footer_text, header_text, sidebar_markup
|
|
109
|
+
|
|
110
|
+
state = TuiState("m", "/ws", 5)
|
|
111
|
+
assert legacy_header is header_text
|
|
112
|
+
assert legacy_sidebar is sidebar_markup
|
|
113
|
+
assert legacy_footer is footer_text
|
|
114
|
+
assert legacy_header(state, "1") == header_text(state, "1")
|
|
115
|
+
|
|
116
|
+
|
|
104
117
|
def test_sidebar_marks_running_and_failed_tools():
|
|
105
118
|
state = TuiState("m", "/ws", 5)
|
|
106
119
|
state.on_event({"type": "run_start"})
|
|
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
|