eva-cli 3.0.0__py3-none-any.whl
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.
- eva/__init__.py +3 -0
- eva/budget.py +31 -0
- eva/cache/__init__.py +17 -0
- eva/cache/cache.py +40 -0
- eva/cache.py +19 -0
- eva/chat_session.py +5 -0
- eva/cli/__init__.py +3 -0
- eva/cli/app.py +851 -0
- eva/cli.py +5 -0
- eva/config/__init__.py +33 -0
- eva/config/config.py +129 -0
- eva/config.py +35 -0
- eva/context/__init__.py +19 -0
- eva/context/finder.py +5 -0
- eva/context/gitignore.py +5 -0
- eva/context/io.py +5 -0
- eva/context/tokenizer.py +5 -0
- eva/context/tree.py +5 -0
- eva/diagnostics.py +9 -0
- eva/git_ops.py +15 -0
- eva/indexing/__init__.py +18 -0
- eva/indexing/finder.py +42 -0
- eva/indexing/io.py +35 -0
- eva/indexing/repo_index.py +240 -0
- eva/indexing/tokenizer.py +37 -0
- eva/indexing/tree.py +60 -0
- eva/plugins/__init__.py +3 -0
- eva/prompts/__init__.py +36 -0
- eva/providers/__init__.py +150 -0
- eva/providers/gemini_provider.py +72 -0
- eva/providers/groq_provider.py +37 -0
- eva/providers/llamacpp_provider.py +69 -0
- eva/providers/ollama_provider.py +70 -0
- eva/providers/openai_compat.py +57 -0
- eva/providers/opencode_zen_provider.py +53 -0
- eva/providers/openrouter_provider.py +55 -0
- eva/replay/__init__.py +11 -0
- eva/replay/player.py +91 -0
- eva/replay/recorder.py +67 -0
- eva/router/__init__.py +25 -0
- eva/router/gemini_provider.py +5 -0
- eva/router/groq_provider.py +5 -0
- eva/router/openai_compat.py +5 -0
- eva/router/opencode_zen_provider.py +5 -0
- eva/router/openrouter_provider.py +5 -0
- eva/security/__init__.py +32 -0
- eva/security/audit.py +126 -0
- eva/security/redaction.py +80 -0
- eva/security/sandbox.py +55 -0
- eva/security/work_safety.py +85 -0
- eva/shell/__init__.py +3 -0
- eva/shell/runner.py +6 -0
- eva/telemetry/__init__.py +10 -0
- eva/telemetry/diagnostics.py +43 -0
- eva/telemetry/metrics.py +68 -0
- eva/ui/formatter.py +46 -0
- eva/ui/streaming.py +21 -0
- eva/work_safety.py +21 -0
- eva/workflows/__init__.py +39 -0
- eva/workflows/budget.py +139 -0
- eva/workflows/builtins/dependency_audit.yaml +12 -0
- eva/workflows/builtins/repo_health.yaml +16 -0
- eva/workflows/builtins/security_scan.yaml +12 -0
- eva/workflows/chat_session.py +54 -0
- eva/workflows/engine.py +267 -0
- eva/workspace/__init__.py +39 -0
- eva/workspace/git_ops.py +202 -0
- eva/workspace/gitignore.py +47 -0
- eva/workspace/session.py +184 -0
- eva_cli-3.0.0.dist-info/METADATA +344 -0
- eva_cli-3.0.0.dist-info/RECORD +74 -0
- eva_cli-3.0.0.dist-info/WHEEL +4 -0
- eva_cli-3.0.0.dist-info/entry_points.txt +2 -0
- eva_cli-3.0.0.dist-info/licenses/LICENSE +21 -0
eva/telemetry/metrics.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import logging
|
|
3
|
+
from datetime import datetime, timezone
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
|
|
9
|
+
from eva.config import AppConfig, get_config_dir
|
|
10
|
+
|
|
11
|
+
logger = logging.getLogger(__name__)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def get_telemetry_dir() -> Path:
|
|
15
|
+
d = get_config_dir() / "telemetry"
|
|
16
|
+
d.mkdir(parents=True, exist_ok=True)
|
|
17
|
+
return d
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def record_provider_metric(
|
|
21
|
+
provider_name: str,
|
|
22
|
+
latency_s: float,
|
|
23
|
+
success: bool,
|
|
24
|
+
error_type: str | None = None,
|
|
25
|
+
config: AppConfig | None = None,
|
|
26
|
+
telemetry_dir: Path | None = None,
|
|
27
|
+
):
|
|
28
|
+
"""Record anonymized provider performance telemetry (latency, success rate, error type).
|
|
29
|
+
|
|
30
|
+
Never records prompt text, file contents, or commands.
|
|
31
|
+
Off by default — requires config.general.telemetry_enabled = True.
|
|
32
|
+
"""
|
|
33
|
+
if not config or not config.general.telemetry_enabled:
|
|
34
|
+
return # Opt-in check: Off by default
|
|
35
|
+
|
|
36
|
+
record = {
|
|
37
|
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
|
38
|
+
"event_type": "provider_call",
|
|
39
|
+
"provider": provider_name,
|
|
40
|
+
"latency_s": round(latency_s, 4),
|
|
41
|
+
"success": success,
|
|
42
|
+
"error_type": error_type,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
target_dir = telemetry_dir or get_telemetry_dir()
|
|
46
|
+
target_dir.mkdir(parents=True, exist_ok=True)
|
|
47
|
+
metrics_file = target_dir / "metrics.jsonl"
|
|
48
|
+
|
|
49
|
+
with open(metrics_file, "a", encoding="utf-8") as f:
|
|
50
|
+
f.write(json.dumps(record) + "\n")
|
|
51
|
+
|
|
52
|
+
# Optional self-hosted export endpoint
|
|
53
|
+
endpoint = config.general.telemetry_export_endpoint
|
|
54
|
+
if endpoint and endpoint.strip():
|
|
55
|
+
_export_metric(endpoint.strip(), record)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _export_metric(endpoint: str, record: dict[str, Any]):
|
|
59
|
+
"""Export single metric record to self-hosted telemetry endpoint."""
|
|
60
|
+
try:
|
|
61
|
+
httpx.post(
|
|
62
|
+
endpoint,
|
|
63
|
+
json={"metrics": [record]},
|
|
64
|
+
timeout=3.0,
|
|
65
|
+
headers={"User-Agent": "Eva-Telemetry/1.0"},
|
|
66
|
+
)
|
|
67
|
+
except httpx.HTTPError as exc:
|
|
68
|
+
logger.debug("Telemetry export POST to %s failed: %s", endpoint, exc)
|
eva/ui/formatter.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from rich.console import Console
|
|
2
|
+
from rich.markdown import Markdown
|
|
3
|
+
from rich.markup import escape
|
|
4
|
+
from rich.panel import Panel
|
|
5
|
+
from rich.theme import Theme
|
|
6
|
+
|
|
7
|
+
eva_theme = Theme(
|
|
8
|
+
{
|
|
9
|
+
"info": "cyan",
|
|
10
|
+
"warning": "yellow",
|
|
11
|
+
"error": "bold red",
|
|
12
|
+
"success": "green",
|
|
13
|
+
}
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
console = Console(theme=eva_theme)
|
|
17
|
+
err_console = Console(theme=eva_theme, stderr=True)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def print_error(msg: str):
|
|
21
|
+
err_console.print(f"[error]✖ {escape(msg)}[/error]")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def print_success(msg: str):
|
|
25
|
+
err_console.print(f"[success]✔ {escape(msg)}[/success]")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def print_info(msg: str):
|
|
29
|
+
err_console.print(f"[info]ℹ {escape(msg)}[/info]")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def print_warning(msg: str):
|
|
33
|
+
err_console.print(f"[warning]⚠ {escape(msg)}[/warning]")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def print_markdown(content: str, title: str | None = None):
|
|
37
|
+
md = Markdown(content)
|
|
38
|
+
if title:
|
|
39
|
+
console.print(Panel(md, title=f"[info]{title}[/info]", border_style="cyan"))
|
|
40
|
+
else:
|
|
41
|
+
console.print(md)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def is_ai_error(result: str) -> bool:
|
|
45
|
+
stripped = result.strip()
|
|
46
|
+
return stripped.startswith(("[Eva Error]", "Error:")) or "\n[Eva Error]" in result
|
eva/ui/streaming.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from collections.abc import Iterator
|
|
2
|
+
|
|
3
|
+
from rich.live import Live
|
|
4
|
+
from rich.spinner import Spinner
|
|
5
|
+
|
|
6
|
+
from eva.ui.formatter import err_console
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def stream_response(stream: Iterator[str]) -> str:
|
|
10
|
+
"""Consume a streaming LLM response, showing progress on stderr."""
|
|
11
|
+
full_text = ""
|
|
12
|
+
got_first_chunk = False
|
|
13
|
+
|
|
14
|
+
with Live(Spinner("dots", text="Thinking..."), console=err_console, refresh_per_second=10, transient=True) as live:
|
|
15
|
+
for chunk in stream:
|
|
16
|
+
full_text += chunk
|
|
17
|
+
if not got_first_chunk:
|
|
18
|
+
got_first_chunk = True
|
|
19
|
+
live.update(Spinner("dots", text=f"Receiving... ({len(full_text)} chars)"))
|
|
20
|
+
|
|
21
|
+
return full_text
|
eva/work_safety.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Compatibility re-exports for work_safety."""
|
|
2
|
+
|
|
3
|
+
from eva.security.work_safety import (
|
|
4
|
+
CommandExtractionError,
|
|
5
|
+
ParsedCommand,
|
|
6
|
+
UnsafeCommandError,
|
|
7
|
+
append_command_audit,
|
|
8
|
+
extract_single_command,
|
|
9
|
+
get_command_audit_log,
|
|
10
|
+
parse_safe_command,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"CommandExtractionError",
|
|
15
|
+
"ParsedCommand",
|
|
16
|
+
"UnsafeCommandError",
|
|
17
|
+
"append_command_audit",
|
|
18
|
+
"extract_single_command",
|
|
19
|
+
"get_command_audit_log",
|
|
20
|
+
"parse_safe_command",
|
|
21
|
+
]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from eva.workflows.budget import (
|
|
2
|
+
Budget,
|
|
3
|
+
UsageStats,
|
|
4
|
+
check_and_increment,
|
|
5
|
+
get_budget_file,
|
|
6
|
+
get_budget_lock_file,
|
|
7
|
+
get_live_budget,
|
|
8
|
+
normalize_usage_stats,
|
|
9
|
+
remaining_budget,
|
|
10
|
+
reset_provider_usage,
|
|
11
|
+
save_budget,
|
|
12
|
+
)
|
|
13
|
+
from eva.workflows.chat_session import run_chat_session
|
|
14
|
+
from eva.workflows.engine import (
|
|
15
|
+
Workflow,
|
|
16
|
+
WorkflowStep,
|
|
17
|
+
list_workflows,
|
|
18
|
+
load_workflow,
|
|
19
|
+
run_workflow,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"Budget",
|
|
24
|
+
"UsageStats",
|
|
25
|
+
"Workflow",
|
|
26
|
+
"WorkflowStep",
|
|
27
|
+
"check_and_increment",
|
|
28
|
+
"get_budget_file",
|
|
29
|
+
"get_budget_lock_file",
|
|
30
|
+
"get_live_budget",
|
|
31
|
+
"list_workflows",
|
|
32
|
+
"load_workflow",
|
|
33
|
+
"normalize_usage_stats",
|
|
34
|
+
"remaining_budget",
|
|
35
|
+
"reset_provider_usage",
|
|
36
|
+
"run_chat_session",
|
|
37
|
+
"run_workflow",
|
|
38
|
+
"save_budget",
|
|
39
|
+
]
|
eva/workflows/budget.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from contextlib import contextmanager
|
|
3
|
+
from datetime import datetime, timezone
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from pydantic import BaseModel, Field
|
|
7
|
+
|
|
8
|
+
from eva.config import get_config_dir
|
|
9
|
+
|
|
10
|
+
__all__ = ["get_config_dir"]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class UsageStats(BaseModel):
|
|
14
|
+
requests_today: int = 0
|
|
15
|
+
requests_this_minute: int = 0
|
|
16
|
+
last_request_time: float = 0.0
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Budget(BaseModel):
|
|
20
|
+
usage_by_provider: dict[str, UsageStats] = Field(default_factory=dict)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_budget_file() -> Path:
|
|
24
|
+
return get_config_dir() / "usage.json"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def get_budget_lock_file() -> Path:
|
|
28
|
+
return get_config_dir() / "usage.lock"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@contextmanager
|
|
32
|
+
def _locked_budget_file():
|
|
33
|
+
lock_file = get_budget_lock_file()
|
|
34
|
+
lock_file.parent.mkdir(parents=True, exist_ok=True)
|
|
35
|
+
try:
|
|
36
|
+
import fcntl
|
|
37
|
+
except ImportError:
|
|
38
|
+
yield
|
|
39
|
+
return
|
|
40
|
+
|
|
41
|
+
with open(lock_file, "a+") as lock:
|
|
42
|
+
try:
|
|
43
|
+
fcntl.flock(lock.fileno(), fcntl.LOCK_EX)
|
|
44
|
+
yield
|
|
45
|
+
finally:
|
|
46
|
+
fcntl.flock(lock.fileno(), fcntl.LOCK_UN)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _load_budget_unlocked() -> Budget:
|
|
50
|
+
budget_file = get_budget_file()
|
|
51
|
+
if not budget_file.exists():
|
|
52
|
+
return Budget()
|
|
53
|
+
|
|
54
|
+
with open(budget_file, "r") as f:
|
|
55
|
+
data = json.load(f)
|
|
56
|
+
return Budget(**data)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def load_budget() -> Budget:
|
|
60
|
+
with _locked_budget_file():
|
|
61
|
+
return _load_budget_unlocked()
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _save_budget_unlocked(budget: Budget):
|
|
65
|
+
budget_file = get_budget_file()
|
|
66
|
+
budget_file.parent.mkdir(parents=True, exist_ok=True)
|
|
67
|
+
with open(budget_file, "w") as f:
|
|
68
|
+
json.dump(budget.model_dump(), f, indent=2)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def save_budget(budget: Budget):
|
|
72
|
+
with _locked_budget_file():
|
|
73
|
+
_save_budget_unlocked(budget)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def normalize_usage_stats(stats: UsageStats, now: datetime | None = None) -> UsageStats:
|
|
77
|
+
now = now or datetime.now(timezone.utc)
|
|
78
|
+
current_timestamp = now.timestamp()
|
|
79
|
+
|
|
80
|
+
if stats.last_request_time <= 0:
|
|
81
|
+
stats.requests_this_minute = 0
|
|
82
|
+
return stats
|
|
83
|
+
|
|
84
|
+
last_time = datetime.fromtimestamp(stats.last_request_time, tz=timezone.utc)
|
|
85
|
+
|
|
86
|
+
if last_time.date() < now.date():
|
|
87
|
+
stats.requests_today = 0
|
|
88
|
+
|
|
89
|
+
if (current_timestamp - stats.last_request_time) >= 60.0:
|
|
90
|
+
stats.requests_this_minute = 0
|
|
91
|
+
|
|
92
|
+
return stats
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def get_live_budget() -> Budget:
|
|
96
|
+
with _locked_budget_file():
|
|
97
|
+
budget = _load_budget_unlocked()
|
|
98
|
+
for stats in budget.usage_by_provider.values():
|
|
99
|
+
normalize_usage_stats(stats)
|
|
100
|
+
_save_budget_unlocked(budget)
|
|
101
|
+
return budget
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def check_and_increment(provider: str, max_rpm: int, max_rpd: int) -> bool:
|
|
105
|
+
with _locked_budget_file():
|
|
106
|
+
budget = _load_budget_unlocked()
|
|
107
|
+
|
|
108
|
+
if provider not in budget.usage_by_provider:
|
|
109
|
+
budget.usage_by_provider[provider] = UsageStats()
|
|
110
|
+
|
|
111
|
+
stats = budget.usage_by_provider[provider]
|
|
112
|
+
normalize_usage_stats(stats)
|
|
113
|
+
|
|
114
|
+
if stats.requests_today >= max_rpd:
|
|
115
|
+
return False
|
|
116
|
+
|
|
117
|
+
if stats.requests_this_minute >= max_rpm:
|
|
118
|
+
return False
|
|
119
|
+
|
|
120
|
+
now = datetime.now(timezone.utc)
|
|
121
|
+
stats.requests_today += 1
|
|
122
|
+
stats.requests_this_minute += 1
|
|
123
|
+
stats.last_request_time = now.timestamp()
|
|
124
|
+
|
|
125
|
+
_save_budget_unlocked(budget)
|
|
126
|
+
return True
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def reset_provider_usage(provider: str):
|
|
130
|
+
with _locked_budget_file():
|
|
131
|
+
budget = _load_budget_unlocked()
|
|
132
|
+
budget.usage_by_provider[provider] = UsageStats()
|
|
133
|
+
_save_budget_unlocked(budget)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def remaining_budget(provider: str, max_rpm: int, max_rpd: int) -> tuple[int, int]:
|
|
137
|
+
budget = get_live_budget()
|
|
138
|
+
stats = budget.usage_by_provider.get(provider, UsageStats())
|
|
139
|
+
return max(max_rpd - stats.requests_today, 0), max(max_rpm - stats.requests_this_minute, 0)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
name: dependency_audit
|
|
2
|
+
description: "Dependency audit: inspect installed Python package list and check for issues."
|
|
3
|
+
version: "1.0"
|
|
4
|
+
steps:
|
|
5
|
+
- name: List Installed Packages
|
|
6
|
+
description: "Check currently installed Python dependencies."
|
|
7
|
+
command: "python -m pip list"
|
|
8
|
+
risk_level: "low"
|
|
9
|
+
- name: Dependency Consistency Check
|
|
10
|
+
description: "Check for broken dependencies or missing packages."
|
|
11
|
+
command: "python -m pip check"
|
|
12
|
+
risk_level: "low"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: repo_health
|
|
2
|
+
description: "Repository health check: git status, recent commit log, branch state, and configuration audit."
|
|
3
|
+
version: "1.0"
|
|
4
|
+
steps:
|
|
5
|
+
- name: Working Tree Status
|
|
6
|
+
description: "Check for uncommitted, unstaged, or untracked changes."
|
|
7
|
+
command: "git status --short"
|
|
8
|
+
risk_level: "low"
|
|
9
|
+
- name: Recent Commit Activity
|
|
10
|
+
description: "Review recent commit log."
|
|
11
|
+
command: "git log -n 5 --oneline"
|
|
12
|
+
risk_level: "low"
|
|
13
|
+
- name: Remote Configuration
|
|
14
|
+
description: "Inspect configured git remotes."
|
|
15
|
+
command: "git remote -v"
|
|
16
|
+
risk_level: "low"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
name: security_scan
|
|
2
|
+
description: "Security scan: check git status and scan tracked files for risky key/secret patterns."
|
|
3
|
+
version: "1.0"
|
|
4
|
+
steps:
|
|
5
|
+
- name: Check Git Tracked Files
|
|
6
|
+
description: "Ensure no temporary or secret files are untracked in git root."
|
|
7
|
+
command: "git status --porcelain"
|
|
8
|
+
risk_level: "low"
|
|
9
|
+
- name: Scan Config Key Patterns
|
|
10
|
+
description: "Scan for hardcoded secret variables."
|
|
11
|
+
command: "grep -rn 'API_KEY' --exclude-dir='.git' --exclude-dir='.venv' --exclude='*.jsonl' . || true"
|
|
12
|
+
risk_level: "low"
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
from eva.config import get_config_dir
|
|
5
|
+
from eva.indexing.tokenizer import trim_context
|
|
6
|
+
from eva.prompts import CHAT_SYSTEM_PROMPT
|
|
7
|
+
from eva.providers import dispatch
|
|
8
|
+
from eva.ui.formatter import is_ai_error, print_error, print_info, print_markdown
|
|
9
|
+
from eva.ui.streaming import stream_response
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def run_chat_session(
|
|
13
|
+
config,
|
|
14
|
+
provider: str | None = None,
|
|
15
|
+
session: str | None = None,
|
|
16
|
+
resume: bool = False,
|
|
17
|
+
) -> None:
|
|
18
|
+
print_info("Starting Eva Chat. Type 'exit' or 'quit' to stop.")
|
|
19
|
+
|
|
20
|
+
context_history = ""
|
|
21
|
+
session_path: Path | None = None
|
|
22
|
+
if session:
|
|
23
|
+
safe_name = re.sub(r"[^A-Za-z0-9_.-]+", "_", session).strip("._") or "session"
|
|
24
|
+
session_path = get_config_dir() / "sessions" / f"{safe_name}.md"
|
|
25
|
+
session_path.parent.mkdir(parents=True, exist_ok=True)
|
|
26
|
+
if resume and session_path.exists():
|
|
27
|
+
context_history = session_path.read_text(encoding="utf-8", errors="replace")
|
|
28
|
+
print_info(f"Resumed chat session: {session_path}")
|
|
29
|
+
|
|
30
|
+
while True:
|
|
31
|
+
try:
|
|
32
|
+
query = input("\n> ")
|
|
33
|
+
if query.lower() in ("exit", "quit"):
|
|
34
|
+
break
|
|
35
|
+
if not query.strip():
|
|
36
|
+
continue
|
|
37
|
+
|
|
38
|
+
trimmed_history = trim_context(context_history, max_tokens=6000, keep="tail") if context_history else ""
|
|
39
|
+
stream = dispatch(CHAT_SYSTEM_PROMPT, query, trimmed_history, config, pinned_provider=provider)
|
|
40
|
+
result = stream_response(stream)
|
|
41
|
+
|
|
42
|
+
if is_ai_error(result):
|
|
43
|
+
print_error(result.strip())
|
|
44
|
+
continue
|
|
45
|
+
|
|
46
|
+
print_markdown(result)
|
|
47
|
+
|
|
48
|
+
# Simple rolling context (just appending for now)
|
|
49
|
+
context_history += f"\nUser: {query}\nEva: {result}\n"
|
|
50
|
+
if session_path:
|
|
51
|
+
session_path.write_text(context_history, encoding="utf-8")
|
|
52
|
+
|
|
53
|
+
except (KeyboardInterrupt, EOFError):
|
|
54
|
+
break
|