lithe-cli 0.1.3__tar.gz → 0.1.5__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.3 → lithe_cli-0.1.5}/PKG-INFO +2 -2
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli/__init__.py +1 -1
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli/agent.py +18 -6
- lithe_cli-0.1.5/lithe_cli/cli_parser.py +186 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli/config.py +10 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli/main.py +3 -233
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli/ttui.py +45 -400
- lithe_cli-0.1.5/lithe_cli/ttui_render.py +122 -0
- lithe_cli-0.1.5/lithe_cli/ttui_widgets.py +287 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli/workbench.py +4 -1
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli.egg-info/PKG-INFO +2 -2
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli.egg-info/SOURCES.txt +3 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli.egg-info/requires.txt +1 -1
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/pyproject.toml +1 -1
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/tests/test_cli.py +58 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/tests/test_cli_budget_steer.py +14 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/tests/test_cli_subagents.py +21 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/tests/test_ttui.py +56 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/tests/test_tui_v2.py +13 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/LICENSE +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/README.md +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli/__main__.py +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli/clipboard.py +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli/commands.py +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli/profiles.py +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli/prompts.py +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli/py.typed +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli/sessions.py +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli/setup.py +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli/tui.py +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli/ui.py +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli.egg-info/dependency_links.txt +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli.egg-info/entry_points.txt +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/lithe_cli.egg-info/top_level.txt +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/setup.cfg +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/tests/test_cli_clipboard.py +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/tests/test_cli_guard.py +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/tests/test_cli_sessions.py +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/tests/test_profiles.py +0 -0
- {lithe_cli-0.1.3 → lithe_cli-0.1.5}/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.5
|
|
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.3
|
|
43
43
|
Requires-Dist: prompt-toolkit>=3.0.38
|
|
44
44
|
Requires-Dist: textual>=1.0
|
|
45
45
|
Provides-Extra: dev
|
|
@@ -75,10 +75,14 @@ SYSTEM_PROMPT_BASE = (
|
|
|
75
75
|
)
|
|
76
76
|
|
|
77
77
|
|
|
78
|
-
def todo_store_path(cfg: Config) -> Path:
|
|
78
|
+
def todo_store_path(cfg: Config, conversation_id: int | None = None) -> Path:
|
|
79
|
+
"""Path for one conversation's task list (None is the non-session scope)."""
|
|
79
80
|
workspace = str(cfg.workspace_dir.expanduser().resolve())
|
|
81
|
+
scope_data = {"user_id": str(cfg.user_id), "workspace": workspace}
|
|
82
|
+
if conversation_id is not None:
|
|
83
|
+
scope_data["conversation_id"] = conversation_id
|
|
80
84
|
scope = json.dumps(
|
|
81
|
-
|
|
85
|
+
scope_data,
|
|
82
86
|
ensure_ascii=False,
|
|
83
87
|
sort_keys=True,
|
|
84
88
|
separators=(",", ":"),
|
|
@@ -126,6 +130,8 @@ def build_llm(cfg: Config) -> LLMConfig:
|
|
|
126
130
|
"api_key": cfg.api_key or "unused",
|
|
127
131
|
"timeout": cfg.timeout,
|
|
128
132
|
"attempts": cfg.attempts,
|
|
133
|
+
"sleep_429": cfg.sleep_429,
|
|
134
|
+
"sleep_err": cfg.sleep_err,
|
|
129
135
|
"stream": cfg.stream,
|
|
130
136
|
"context_window": cfg.context_window,
|
|
131
137
|
"reasoning_effort": cfg.reasoning_effort,
|
|
@@ -159,7 +165,11 @@ def build_llm(cfg: Config) -> LLMConfig:
|
|
|
159
165
|
return LLMConfig(**overrides)
|
|
160
166
|
|
|
161
167
|
|
|
162
|
-
def build_registry(
|
|
168
|
+
def build_registry(
|
|
169
|
+
cfg: Config,
|
|
170
|
+
approver: Callable[[str], Awaitable[bool]] | None = None,
|
|
171
|
+
conversation_id: int | None = None,
|
|
172
|
+
) -> ToolRegistry:
|
|
163
173
|
"""Register the CLI's tool set against the configured workspace.
|
|
164
174
|
|
|
165
175
|
``approver`` is the human-confirmation channel for destructive
|
|
@@ -173,7 +183,7 @@ def build_registry(cfg: Config, approver: Callable[[str], Awaitable[bool]] | Non
|
|
|
173
183
|
|
|
174
184
|
register_file_tools(reg, workspace_for)
|
|
175
185
|
register_apply_patch_tool(reg, workspace_for)
|
|
176
|
-
todo_store = JsonTodoStore(todo_store_path(cfg))
|
|
186
|
+
todo_store = JsonTodoStore(todo_store_path(cfg, conversation_id))
|
|
177
187
|
register_todo_tools(reg, lambda ctx: todo_store)
|
|
178
188
|
if cfg.download:
|
|
179
189
|
register_download_tools(reg, workspace_for)
|
|
@@ -517,7 +527,7 @@ async def execute(
|
|
|
517
527
|
the steering channel: a queue of user texts the kernel drains at step
|
|
518
528
|
boundaries and injects as user messages (see AgentRuntime.run).
|
|
519
529
|
"""
|
|
520
|
-
reg = build_registry(cfg, approver)
|
|
530
|
+
reg = build_registry(cfg, approver, conversation_id=conversation_id)
|
|
521
531
|
host = build_host(cfg, reg)
|
|
522
532
|
if cfg.subagents:
|
|
523
533
|
register_subagents(cfg, host, reg, on_event=on_event)
|
|
@@ -560,7 +570,9 @@ async def execute(
|
|
|
560
570
|
|
|
561
571
|
async def undo(cfg: Config, run_id: str, quiet: bool = False) -> int:
|
|
562
572
|
"""Revert a run's mutations; returns how many actions were reverted."""
|
|
563
|
-
|
|
573
|
+
run = JsonlRunStore(cfg.store_dir).get_run(run_id, cfg.user_id)
|
|
574
|
+
conversation_id = run.conversation_id if run is not None else None
|
|
575
|
+
reg = build_registry(cfg, conversation_id=conversation_id)
|
|
564
576
|
host = build_host(cfg, reg)
|
|
565
577
|
report = await undo_run(host, run_id, cfg.user_id)
|
|
566
578
|
if not quiet:
|
|
@@ -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"))
|