Compare commits

..

2 Commits

Author SHA1 Message Date
dark
6e694224ef 1、补充提交 2026-06-02 16:58:23 +08:00
dark
6dfb79dcd2 1、修复 chat_history.txt不存在的问题 2026-06-02 16:57:55 +08:00
2 changed files with 26 additions and 2 deletions

View File

@ -6,6 +6,8 @@ import time
import json
import shlex
import builtins
import os
import sys
from dataclasses import asdict
from pathlib import Path
from typing import Any, Callable
@ -557,8 +559,16 @@ def _build_prompt_input(input_func: InputFunc) -> InputFunc:
"checkpoint",
"exit",
]
history = None
try:
history_path = Path("runtime") / "chat_history.txt"
history_path.parent.mkdir(parents=True, exist_ok=True)
history = FileHistory(str(history_path))
except OSError:
history = None
session = PromptSession(
history=FileHistory(str(Path("runtime") / "chat_history.txt")),
history=history,
completer=WordCompleter(commands, ignore_case=True, sentence=True),
)
return session.prompt

View File

@ -1,8 +1,11 @@
import builtins
from pathlib import Path
import pytest
from pam_deploy_graph.agent import PamDeployAgent
from pam_deploy_graph.fake_runner import FakeActionRunner
from pam_deploy_graph.interactive import InteractiveCliSession
from pam_deploy_graph.interactive import InteractiveCliSession, _build_prompt_input
PARAMS = {
@ -130,3 +133,14 @@ def test_chat_can_hot_load_mcp_config(tmp_path: Path):
assert session.agent.mcp_runner is not None
assert session.agent.router.mcp_runner is not None
assert any("MCP 配置已加载" in item for item in output)
def test_prompt_history_creates_runtime_dir(tmp_path: Path, monkeypatch):
pytest.importorskip("prompt_toolkit")
monkeypatch.chdir(tmp_path)
prompt = _build_prompt_input(builtins.input)
assert callable(prompt)
assert (tmp_path / "runtime").is_dir()