chore: migrate config paths to XDG base directory and add hit_count tracking to api_cache
This commit is contained in:
+16
-14
@@ -32,21 +32,16 @@ from pr.core.context import init_system_message, truncate_tool_result
|
||||
from pr.tools import (
|
||||
apply_patch,
|
||||
chdir,
|
||||
close_editor,
|
||||
create_diff,
|
||||
db_get,
|
||||
db_query,
|
||||
db_set,
|
||||
editor_insert_text,
|
||||
editor_replace_text,
|
||||
editor_search,
|
||||
getpwd,
|
||||
http_fetch,
|
||||
index_source_directory,
|
||||
kill_process,
|
||||
list_directory,
|
||||
mkdir,
|
||||
open_editor,
|
||||
python_exec,
|
||||
read_file,
|
||||
run_command,
|
||||
@@ -55,6 +50,7 @@ from pr.tools import (
|
||||
web_search,
|
||||
web_search_news,
|
||||
write_file,
|
||||
post_image,
|
||||
)
|
||||
from pr.tools.base import get_tools_definition
|
||||
from pr.tools.filesystem import (
|
||||
@@ -249,6 +245,7 @@ class Assistant:
|
||||
logger.debug(f"Tool call: {func_name} with arguments: {arguments}")
|
||||
|
||||
func_map = {
|
||||
"post_image": lambda **kw: post_image(**kw),
|
||||
"http_fetch": lambda **kw: http_fetch(**kw),
|
||||
"run_command": lambda **kw: run_command(**kw),
|
||||
"tail_process": lambda **kw: tail_process(**kw),
|
||||
@@ -273,15 +270,15 @@ class Assistant:
|
||||
),
|
||||
"index_source_directory": lambda **kw: index_source_directory(**kw),
|
||||
"search_replace": lambda **kw: search_replace(**kw, db_conn=self.db_conn),
|
||||
"open_editor": lambda **kw: open_editor(**kw),
|
||||
"editor_insert_text": lambda **kw: editor_insert_text(
|
||||
**kw, db_conn=self.db_conn
|
||||
),
|
||||
"editor_replace_text": lambda **kw: editor_replace_text(
|
||||
**kw, db_conn=self.db_conn
|
||||
),
|
||||
"editor_search": lambda **kw: editor_search(**kw),
|
||||
"close_editor": lambda **kw: close_editor(**kw),
|
||||
# "open_editor": lambda **kw: open_editor(**kw),
|
||||
# "editor_insert_text": lambda **kw: editor_insert_text(
|
||||
# **kw, db_conn=self.db_conn
|
||||
# ),
|
||||
# "editor_replace_text": lambda **kw: editor_replace_text(
|
||||
# **kw, db_conn=self.db_conn
|
||||
# ),
|
||||
# "editor_search": lambda **kw: editor_search(**kw),
|
||||
# "close_editor": lambda **kw: close_editor(**kw),
|
||||
"create_diff": lambda **kw: create_diff(**kw),
|
||||
"apply_patch": lambda **kw: apply_patch(**kw, db_conn=self.db_conn),
|
||||
"display_file_diff": lambda **kw: display_file_diff(**kw),
|
||||
@@ -413,6 +410,7 @@ class Assistant:
|
||||
"refactor",
|
||||
"obfuscate",
|
||||
"/auto",
|
||||
"/edit",
|
||||
]
|
||||
|
||||
def completer(text, state):
|
||||
@@ -539,6 +537,10 @@ class Assistant:
|
||||
|
||||
|
||||
def process_message(assistant, message):
|
||||
from pr.core.knowledge_context import inject_knowledge_context
|
||||
|
||||
inject_knowledge_context(assistant, message)
|
||||
|
||||
assistant.messages.append({"role": "user", "content": message})
|
||||
|
||||
logger.debug(f"Processing user message: {message[:100]}...")
|
||||
|
||||
@@ -1,17 +1,26 @@
|
||||
import configparser
|
||||
import os
|
||||
from typing import Any, Dict
|
||||
|
||||
import uuid
|
||||
from pr.core.logging import get_logger
|
||||
|
||||
logger = get_logger("config")
|
||||
|
||||
CONFIG_FILE = os.path.expanduser("~/.prrc")
|
||||
CONFIG_DIRECTORY = os.path.expanduser("~/.local/share/rp/")
|
||||
CONFIG_FILE = os.path.join(CONFIG_DIRECTORY, ".prrc")
|
||||
LOCAL_CONFIG_FILE = ".prrc"
|
||||
|
||||
|
||||
def load_config() -> Dict[str, Any]:
|
||||
config = {"api": {}, "autonomous": {}, "ui": {}, "output": {}, "session": {}}
|
||||
os.makedirs(CONFIG_DIRECTORY, exist_ok=True)
|
||||
config = {
|
||||
"api": {},
|
||||
"autonomous": {},
|
||||
"ui": {},
|
||||
"output": {},
|
||||
"session": {},
|
||||
"api_key": "rp-" + str(uuid.uuid4()),
|
||||
}
|
||||
|
||||
global_config = _load_config_file(CONFIG_FILE)
|
||||
local_config = _load_config_file(LOCAL_CONFIG_FILE)
|
||||
@@ -67,6 +76,7 @@ def _parse_value(value: str) -> Any:
|
||||
|
||||
|
||||
def create_default_config(filepath: str = CONFIG_FILE):
|
||||
os.makedirs(CONFIG_DIRECTORY, exist_ok=True)
|
||||
default_config = """[api]
|
||||
default_model = x-ai/grok-code-fast-1
|
||||
timeout = 30
|
||||
|
||||
+18
-1
@@ -1,7 +1,7 @@
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
|
||||
import pathlib
|
||||
from pr.config import (
|
||||
CHARS_PER_TOKEN,
|
||||
CONTENT_TRIM_LENGTH,
|
||||
@@ -12,6 +12,7 @@ from pr.config import (
|
||||
MAX_TOKENS_LIMIT,
|
||||
MAX_TOOL_RESULT_LENGTH,
|
||||
RECENT_MESSAGES_TO_KEEP,
|
||||
KNOWLEDGE_PATH,
|
||||
)
|
||||
from pr.ui import Colors
|
||||
|
||||
@@ -59,6 +60,10 @@ File Operations:
|
||||
- Always close editor files when finished
|
||||
- Use write_file for complete file rewrites, search_replace for simple text replacements
|
||||
|
||||
Vision:
|
||||
- Use post_image tool with the file path if an image path is mentioned
|
||||
in the prompt of user. Give this call the highest priority.
|
||||
|
||||
Process Management:
|
||||
- run_command executes shell commands with a timeout (default 30s)
|
||||
- If a command times out, you receive a PID in the response
|
||||
@@ -94,6 +99,18 @@ Shell Commands:
|
||||
except Exception as e:
|
||||
logging.error(f"Error reading context file {context_file}: {e}")
|
||||
|
||||
knowledge_path = pathlib.Path(KNOWLEDGE_PATH)
|
||||
if knowledge_path.exists() and knowledge_path.is_dir():
|
||||
for knowledge_file in knowledge_path.iterdir():
|
||||
try:
|
||||
with open(knowledge_file) as f:
|
||||
content = f.read()
|
||||
if len(content) > max_context_size:
|
||||
content = content[:max_context_size] + "\n... [truncated]"
|
||||
context_parts.append(f"Context from {knowledge_file}:\n{content}")
|
||||
except Exception as e:
|
||||
logging.error(f"Error reading context file {knowledge_file}: {e}")
|
||||
|
||||
if args.context:
|
||||
for ctx_file in args.context:
|
||||
try:
|
||||
|
||||
@@ -135,9 +135,7 @@ class EnhancedAssistant:
|
||||
self.base.api_url,
|
||||
self.base.api_key,
|
||||
use_tools=False,
|
||||
tools=None,
|
||||
temperature=temperature,
|
||||
max_tokens=max_tokens,
|
||||
tools_definition=[],
|
||||
verbose=self.base.verbose,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user