fix(filesystem): avoid duplicate pifs chat output

This commit is contained in:
BukeLy 2026-05-26 14:48:53 +08:00
parent 3625a592f2
commit 3d62293a1e
2 changed files with 38 additions and 5 deletions

View file

@ -140,7 +140,9 @@ def _run_ask(argv: list[str], *, workspace_default: str | None) -> int:
raise ValueError("ask requires a question")
filesystem = _filesystem_from_workspace(args.workspace)
print(run_pifs_agent(filesystem, question, **_agent_kwargs(args)))
answer = run_pifs_agent(filesystem, question, **_agent_kwargs(args))
if args.stream_mode == "off":
print(answer)
return 0
@ -164,7 +166,9 @@ def _run_chat(argv: list[str], *, workspace_default: str | None) -> int:
continue
if question.lower() in EXIT_COMMANDS:
break
print(run_pifs_agent(filesystem, question, **_agent_kwargs(args)))
answer = run_pifs_agent(filesystem, question, **_agent_kwargs(args))
if args.stream_mode == "off":
print(answer)
return 0

View file

@ -58,7 +58,7 @@ def test_cli_ask_invokes_agent_with_question(monkeypatch, capsys, tmp_path):
"--model",
"test-model",
"--stream-mode",
"tools",
"off",
"--max-turns",
"7",
"--max-seconds",
@ -80,7 +80,7 @@ def test_cli_ask_invokes_agent_with_question(monkeypatch, capsys, tmp_path):
assert question == "What is inside?"
assert kwargs == {
"model": "test-model",
"stream_mode": "tools",
"stream_mode": "off",
"max_turns": 7,
"max_seconds": 3.5,
"reasoning_effort": "low",
@ -140,7 +140,7 @@ def test_cli_chat_runs_one_question_and_exits(monkeypatch, capsys, tmp_path):
status = cli.main(["chat", "--workspace", str(workspace), "--model", "test-model"])
assert status == 0
assert capsys.readouterr().out == "answer:Summarize the workspace\n"
assert capsys.readouterr().out == ""
assert len(agent_calls) == 1
filesystem, question, kwargs = agent_calls[0]
assert filesystem.workspace == workspace
@ -149,6 +149,35 @@ def test_cli_chat_runs_one_question_and_exits(monkeypatch, capsys, tmp_path):
assert kwargs["stream_mode"] == "all"
def test_cli_ask_does_not_reprint_streamed_agent_output(monkeypatch, capsys, tmp_path):
from pageindex.filesystem import cli
workspace = tmp_path / "workspace"
def fake_run_pifs_agent(filesystem, question, **kwargs):
print("streamed answer")
return "returned answer"
monkeypatch.setattr(cli, "PageIndexFileSystem", FakeFileSystem)
monkeypatch.setattr(cli, "run_pifs_agent", fake_run_pifs_agent)
status = cli.main(
[
"ask",
"--workspace",
str(workspace),
"--stream-mode",
"all",
"What",
"is",
"inside?",
]
)
assert status == 0
assert capsys.readouterr().out == "streamed answer\n"
def test_cli_chat_stream_mode_can_be_overridden(monkeypatch, tmp_path):
from pageindex.filesystem import cli