Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ miniagent/
└── cli.py # 命令行入口
```

四文件核心 **531 行**;全部官方包 Python **5,056 行**(含旧版兼容代码)。行数包含注释和空行,不含第三方依赖。运行 `python scripts/source_stats.py` 可复核。[统计脚本](scripts/source_stats.py)
四文件核心 **531 行**;全部官方包 Python **5,079 行**(含旧版兼容代码)。行数包含注释和空行,不含第三方依赖。运行 `python scripts/source_stats.py` 可复核。[统计脚本](scripts/source_stats.py)

## 文档与贡献

Expand Down
2 changes: 1 addition & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ miniagent/
└── cli.py # CLI entry point
```

The core totals **531 lines**; all first-party package Python totals **5,056 lines**, including legacy compatibility code. Counts include comments and blank lines and exclude third-party dependencies. Run `python scripts/source_stats.py` to verify. [Counting script](scripts/source_stats.py)
The core totals **531 lines**; all first-party package Python totals **5,079 lines**, including legacy compatibility code. Counts include comments and blank lines and exclude third-party dependencies. Run `python scripts/source_stats.py` to verify. [Counting script](scripts/source_stats.py)

## Docs and contributing

Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [Unreleased]

- [改进] CLI 终端欢迎界面显示模型、权限和会话摘要,帮助列出命令用途,单次任务与工具执行结果更易辨认;复用 Rich,不改变模型、工具、权限和会话语义。
- [文档] 重写中英文 README,突出小核心、常用能力及使用/学习/定制三种用途;恢复 Windows 案例,加入已有终端回放与来源说明,按主线校正源码行数和公开能力,不改变运行时。

- [修复] Gemini 凭据别名统一解析并以规范账户保存,兼容读取旧复合账户;/models 与 /connect 共用密钥误填保护;显式 MINIAGENT_HOME 不再提前解析系统用户目录。
Expand Down
29 changes: 26 additions & 3 deletions miniagent/cli_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

from rich.console import Console
from rich.markdown import Markdown
from rich.panel import Panel
from rich.prompt import Prompt
from rich.table import Table
from rich.text import Text

from .config import load_config
Expand Down Expand Up @@ -94,7 +96,7 @@ def start(event):
def end(event):
elapsed = time.monotonic() - starts.pop(event["call_id"], time.monotonic())
symbol = "failed" if event["error"] else "done"
console.print(Text(f" {symbol} {event['name']} · {elapsed:.2f}s"))
console.print(Text(f" {symbol} {event['name']} · {elapsed:.2f}s", style="red" if event["error"] else "green"))
ctx.on("tool.start", start)
ctx.on("tool.end", end)
ctx.on("llm.request", lambda event: chunks.clear())
Expand All @@ -110,6 +112,8 @@ def stream(token):
chunks.append(token)
console.print(Text(token), end="", highlight=False)
async def ask(query):
if console.is_terminal and args.prompt is not None:
console.print(Panel(Text(query), title="You", border_style="bright_black"))
answer = await app.arun(query, stream=stream if streaming else None)
if not chunks:
console.print(Markdown(answer) if console.is_terminal else Text(answer))
Expand All @@ -136,7 +140,16 @@ def install(ctx):
app.apply_skill(app.skill)
try:
async with app:
console.print(Text(f"MiniAgent · {model} · {app.policy.workspace}\nSession: {app.session.path}", style="dim"))
if console.is_terminal:
welcome = Text("MiniAgent", style="bold green")
welcome.append(" / Python harness + agent\n", style="dim")
welcome.append(f"{model} · {args.policy}\n", style="cyan")
welcome.append(f"Workspace: {app.policy.workspace.name} · Session: {app.session.path.stem[:8]}", style="dim")
if args.prompt is None:
welcome.append("\n/help commands · /connect models · /q exit", style="dim")
console.print(Panel(welcome, border_style="green", padding=(1, 2)))
else:
console.print(Text(f"MiniAgent · {model} · {app.policy.workspace}\nSession: {app.session.path}", style="dim"))
if args.prompt is not None:
await ask(args.prompt)
return 0
Expand All @@ -150,7 +163,17 @@ def install(ctx):
if text in {"/q", "/quit", "/exit"}:
break
if text == "/help":
console.print(Text("/connect · /models · /model [provider:model] · /plugins · /skills [name|path|off]\n/session [new|resolve ID verified-result] · /stream · /help · /q"))
commands = Table(box=None, padding=(0, 2), show_header=False)
for command, purpose in (
("/connect", "Connect a provider"), ("/models", "Choose a model"),
("/model [provider:model]", "Show or switch model; starts a new session"),
("/plugins", "List active plugins"), ("/skills [name|path|off]", "List or switch Skills"),
("/session [new]", "Inspect or start a session"),
("/session resolve ID verified-result", "Record a verified result before resuming"),
("/stream", "Toggle streaming"), ("/q", "Exit"),
):
commands.add_row(Text(command, style="cyan"), Text(purpose))
console.print(commands)
elif text == "/plugins":
console.print(Text(", ".join(app.active)))
elif text.startswith("/skills"):
Expand Down
22 changes: 22 additions & 0 deletions tests/test_cli_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,28 @@ def test_stream_does_not_duplicate_final_answer(tmp_path):
assert output.getvalue().count("literal text") == 1


def test_terminal_welcome_and_help_keep_paths_private(tmp_path, monkeypatch):
import sys
monkeypatch.setattr(sys, "stdin", io.StringIO("/help\n/q\n"))
output = io.StringIO()
console = Console(file=output, force_terminal=True, width=100, no_color=True)
assert asyncio.run(cli_run(options(tmp_path, prompt=None), console=console, backend=Backend())) == 0
text = output.getvalue()
assert "Python harness + agent" in text and "readonly" in text
assert "Choose a model" in text and "verified result" in text
assert str(tmp_path) not in text


def test_terminal_one_shot_shows_literal_prompt_once(tmp_path):
output = io.StringIO()
console = Console(file=output, force_terminal=True, width=100, no_color=True)
prompt = "[red]show this literally[/red]"
assert asyncio.run(cli_run(options(tmp_path, prompt=prompt), console=console, backend=Backend())) == 0
text = output.getvalue()
assert text.count(prompt) == 1
assert text.count("literal text") == 1


def test_repl_session_resume_and_commands(tmp_path, monkeypatch):
import sys
monkeypatch.setattr(sys, "stdin", io.StringIO("/help\n/plugins\n/skills reviewer\nfirst\n/session\n/q\n"))
Expand Down
Loading