1
- import atexit
2
1
import logging
3
- import readline
4
2
from typing import cast
5
3
6
4
from dotenv import load_dotenv
7
5
8
6
from .config import config_path , load_config , set_config_value
9
- from .dirs import get_readline_history_file
10
7
from .llm import init_llm
11
8
from .models import (
12
9
PROVIDERS ,
13
10
Provider ,
14
11
get_recommended_model ,
15
12
set_default_model ,
16
13
)
17
- from .tabcomplete import register_tabcomplete
14
+ from .readline import load_readline_history , register_tabcomplete
18
15
from .tools import init_tools
19
16
from .util import console
20
17
@@ -74,7 +71,7 @@ def init(model: str | None, interactive: bool, tool_allowlist: list[str] | None)
74
71
set_default_model (model )
75
72
76
73
if interactive :
77
- _load_readline_history ()
74
+ load_readline_history ()
78
75
79
76
# for some reason it bugs out shell tests in CI
80
77
register_tabcomplete ()
@@ -89,36 +86,6 @@ def init_logging(verbose):
89
86
logging .getLogger ("httpx" ).setLevel (logging .WARNING )
90
87
91
88
92
- # default history if none found
93
- # NOTE: there are also good examples in the integration tests
94
- history_examples = [
95
- "What is love?" ,
96
- "Have you heard about an open-source app called ActivityWatch?" ,
97
- "Explain 'Attention is All You Need' in the style of Andrej Karpathy." ,
98
- "Explain how public-key cryptography works as if I'm five." ,
99
- "Write a Python script that prints the first 100 prime numbers." ,
100
- "Find all TODOs in the current git project" ,
101
- ]
102
-
103
-
104
- def _load_readline_history () -> None : # pragma: no cover
105
- logger .debug ("Loading history" )
106
- # enabled by default in CPython, make it explicit
107
- readline .set_auto_history (True )
108
- # had some bugs where it grew to gigs, which should be fixed, but still good precaution
109
- readline .set_history_length (100 )
110
- history_file = get_readline_history_file ()
111
- try :
112
- readline .read_history_file (history_file )
113
- except FileNotFoundError :
114
- for line in history_examples :
115
- readline .add_history (line )
116
- except Exception :
117
- logger .exception ("Failed to load history file" )
118
-
119
- atexit .register (readline .write_history_file , history_file )
120
-
121
-
122
89
def _prompt_api_key () -> tuple [str , str , str ]: # pragma: no cover
123
90
api_key = input ("Your OpenAI, Anthropic, or OpenRouter API key: " ).strip ()
124
91
if api_key .startswith ("sk-ant-" ):
0 commit comments