code-puppy 0.0.331__tar.gz → 0.0.333__tar.gz
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.
- {code_puppy-0.0.331 → code_puppy-0.0.333}/PKG-INFO +1 -1
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/agents/base_agent.py +30 -72
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/cli_runner.py +65 -9
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/keymap.py +8 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/claude_code_oauth/register_callbacks.py +0 -15
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/claude_code_oauth/utils.py +0 -202
- code_puppy-0.0.333/code_puppy/terminal_utils.py +291 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/tools/command_runner.py +4 -89
- code_puppy-0.0.333/code_puppy/uvx_detection.py +242 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/pyproject.toml +1 -1
- code_puppy-0.0.331/code_puppy/terminal_utils.py +0 -130
- {code_puppy-0.0.331 → code_puppy-0.0.333}/.gitignore +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/LICENSE +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/README.md +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/__init__.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/__main__.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/agents/__init__.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/agents/agent_c_reviewer.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/agents/agent_code_puppy.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/agents/agent_code_reviewer.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/agents/agent_cpp_reviewer.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/agents/agent_creator_agent.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/agents/agent_golang_reviewer.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/agents/agent_javascript_reviewer.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/agents/agent_manager.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/agents/agent_planning.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/agents/agent_python_programmer.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/agents/agent_python_reviewer.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/agents/agent_qa_expert.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/agents/agent_qa_kitten.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/agents/agent_security_auditor.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/agents/agent_typescript_reviewer.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/agents/json_agent.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/agents/prompt_reviewer.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/callbacks.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/chatgpt_codex_client.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/claude_cache_client.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/__init__.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/add_model_menu.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/attachments.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/autosave_menu.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/colors_menu.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/command_handler.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/command_registry.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/config_commands.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/core_commands.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/diff_menu.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/file_path_completion.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/load_context_completion.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/__init__.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/add_command.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/base.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/catalog_server_installer.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/custom_server_form.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/custom_server_installer.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/edit_command.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/handler.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/help_command.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/install_command.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/install_menu.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/list_command.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/logs_command.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/remove_command.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/restart_command.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/search_command.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/start_all_command.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/start_command.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/status_command.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/stop_all_command.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/stop_command.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/test_command.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/utils.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp/wizard_utils.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/mcp_completion.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/model_picker_completion.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/model_settings_menu.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/motd.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/pin_command_completion.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/prompt_toolkit_completion.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/session_commands.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/command_line/utils.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/config.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/error_logging.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/gemini_code_assist.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/http_utils.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/main.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/mcp_/__init__.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/mcp_/async_lifecycle.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/mcp_/blocking_startup.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/mcp_/captured_stdio_server.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/mcp_/circuit_breaker.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/mcp_/config_wizard.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/mcp_/dashboard.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/mcp_/error_isolation.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/mcp_/examples/retry_example.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/mcp_/health_monitor.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/mcp_/managed_server.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/mcp_/manager.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/mcp_/mcp_logs.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/mcp_/registry.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/mcp_/retry_manager.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/mcp_/server_registry_catalog.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/mcp_/status_tracker.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/mcp_/system_tools.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/messaging/__init__.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/messaging/bus.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/messaging/commands.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/messaging/markdown_patches.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/messaging/message_queue.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/messaging/messages.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/messaging/queue_console.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/messaging/renderers.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/messaging/rich_renderer.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/messaging/spinner/__init__.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/messaging/spinner/console_spinner.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/messaging/spinner/spinner_base.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/model_factory.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/model_utils.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/models.json +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/models_dev_api.json +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/models_dev_parser.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/__init__.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/chatgpt_oauth/__init__.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/chatgpt_oauth/config.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/chatgpt_oauth/oauth_flow.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/chatgpt_oauth/register_callbacks.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/chatgpt_oauth/test_plugin.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/chatgpt_oauth/utils.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/claude_code_oauth/README.md +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/claude_code_oauth/SETUP.md +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/claude_code_oauth/__init__.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/claude_code_oauth/config.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/claude_code_oauth/test_plugin.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/customizable_commands/__init__.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/customizable_commands/register_callbacks.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/example_custom_command/README.md +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/example_custom_command/register_callbacks.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/file_permission_handler/__init__.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/file_permission_handler/register_callbacks.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/oauth_puppy_html.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/shell_safety/__init__.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/shell_safety/agent_shell_safety.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/shell_safety/command_cache.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/shell_safety/register_callbacks.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/prompts/codex_system_prompt.md +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/pydantic_patches.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/reopenable_async_client.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/round_robin_model.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/session_storage.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/status_display.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/summarization_agent.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/tools/__init__.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/tools/agent_tools.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/tools/browser/__init__.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/tools/browser/browser_control.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/tools/browser/browser_interactions.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/tools/browser/browser_locators.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/tools/browser/browser_navigation.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/tools/browser/browser_screenshot.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/tools/browser/browser_scripts.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/tools/browser/browser_workflows.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/tools/browser/camoufox_manager.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/tools/browser/vqa_agent.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/tools/common.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/tools/file_modifications.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/tools/file_operations.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/tools/tools_content.py +0 -0
- {code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/version_checker.py +0 -0
|
@@ -75,8 +75,6 @@ from code_puppy.model_factory import ModelFactory, make_model_settings
|
|
|
75
75
|
from code_puppy.summarization_agent import run_summarization_sync
|
|
76
76
|
from code_puppy.tools.agent_tools import _active_subagent_tasks
|
|
77
77
|
from code_puppy.tools.command_runner import (
|
|
78
|
-
_add_windows_ctrl_handler,
|
|
79
|
-
_remove_windows_ctrl_handler,
|
|
80
78
|
is_awaiting_user_input,
|
|
81
79
|
)
|
|
82
80
|
|
|
@@ -1384,15 +1382,14 @@ class BaseAgent(ABC):
|
|
|
1384
1382
|
def _print_thinking_banner() -> None:
|
|
1385
1383
|
"""Print the THINKING banner with spinner pause and line clear."""
|
|
1386
1384
|
nonlocal did_stream_anything
|
|
1387
|
-
import sys
|
|
1388
1385
|
import time
|
|
1389
1386
|
|
|
1390
1387
|
from code_puppy.config import get_banner_color
|
|
1391
1388
|
|
|
1392
1389
|
pause_all_spinners()
|
|
1393
1390
|
time.sleep(0.1) # Delay to let spinner fully clear
|
|
1394
|
-
|
|
1395
|
-
|
|
1391
|
+
# Clear line and print newline before banner
|
|
1392
|
+
console.print(" " * 50, end="\r")
|
|
1396
1393
|
console.print() # Newline before banner
|
|
1397
1394
|
# Bold banner with configurable color and lightning bolt
|
|
1398
1395
|
thinking_color = get_banner_color("thinking")
|
|
@@ -1402,21 +1399,19 @@ class BaseAgent(ABC):
|
|
|
1402
1399
|
),
|
|
1403
1400
|
end="",
|
|
1404
1401
|
)
|
|
1405
|
-
sys.stdout.flush()
|
|
1406
1402
|
did_stream_anything = True
|
|
1407
1403
|
|
|
1408
1404
|
def _print_response_banner() -> None:
|
|
1409
1405
|
"""Print the AGENT RESPONSE banner with spinner pause and line clear."""
|
|
1410
1406
|
nonlocal did_stream_anything
|
|
1411
|
-
import sys
|
|
1412
1407
|
import time
|
|
1413
1408
|
|
|
1414
1409
|
from code_puppy.config import get_banner_color
|
|
1415
1410
|
|
|
1416
1411
|
pause_all_spinners()
|
|
1417
1412
|
time.sleep(0.1) # Delay to let spinner fully clear
|
|
1418
|
-
|
|
1419
|
-
|
|
1413
|
+
# Clear line and print newline before banner
|
|
1414
|
+
console.print(" " * 50, end="\r")
|
|
1420
1415
|
console.print() # Newline before banner
|
|
1421
1416
|
response_color = get_banner_color("agent_response")
|
|
1422
1417
|
console.print(
|
|
@@ -1424,7 +1419,6 @@ class BaseAgent(ABC):
|
|
|
1424
1419
|
f"[bold white on {response_color}] AGENT RESPONSE [/bold white on {response_color}]"
|
|
1425
1420
|
)
|
|
1426
1421
|
)
|
|
1427
|
-
sys.stdout.flush()
|
|
1428
1422
|
did_stream_anything = True
|
|
1429
1423
|
|
|
1430
1424
|
async for event in events:
|
|
@@ -1448,8 +1442,8 @@ class BaseAgent(ABC):
|
|
|
1448
1442
|
# Buffer initial content if present
|
|
1449
1443
|
if part.content and part.content.strip():
|
|
1450
1444
|
text_buffer[event.index].append(part.content)
|
|
1451
|
-
#
|
|
1452
|
-
token_count[event.index] +=
|
|
1445
|
+
# Count chunks (each part counts as 1)
|
|
1446
|
+
token_count[event.index] += 1
|
|
1453
1447
|
elif isinstance(part, ToolCallPart):
|
|
1454
1448
|
streaming_parts.add(event.index)
|
|
1455
1449
|
tool_parts.add(event.index)
|
|
@@ -1467,24 +1461,20 @@ class BaseAgent(ABC):
|
|
|
1467
1461
|
if delta.content_delta:
|
|
1468
1462
|
# For text parts, show token counter then render at end
|
|
1469
1463
|
if event.index in text_parts:
|
|
1470
|
-
import sys
|
|
1471
|
-
|
|
1472
1464
|
# Print banner on first content
|
|
1473
1465
|
if event.index not in banner_printed:
|
|
1474
1466
|
_print_response_banner()
|
|
1475
1467
|
banner_printed.add(event.index)
|
|
1476
1468
|
# Accumulate text for final markdown render
|
|
1477
1469
|
text_buffer[event.index].append(delta.content_delta)
|
|
1478
|
-
#
|
|
1479
|
-
token_count[event.index] +=
|
|
1480
|
-
|
|
1481
|
-
)
|
|
1482
|
-
# Update token counter in place (single line)
|
|
1470
|
+
# Count chunks received
|
|
1471
|
+
token_count[event.index] += 1
|
|
1472
|
+
# Update chunk counter in place (single line)
|
|
1483
1473
|
count = token_count[event.index]
|
|
1484
|
-
|
|
1485
|
-
f"
|
|
1474
|
+
console.print(
|
|
1475
|
+
f" ⏳ Receiving... {count} chunks ",
|
|
1476
|
+
end="\r",
|
|
1486
1477
|
)
|
|
1487
|
-
sys.stdout.flush()
|
|
1488
1478
|
else:
|
|
1489
1479
|
# For thinking parts, stream immediately (dim)
|
|
1490
1480
|
if event.index not in banner_printed:
|
|
@@ -1493,34 +1483,30 @@ class BaseAgent(ABC):
|
|
|
1493
1483
|
escaped = escape(delta.content_delta)
|
|
1494
1484
|
console.print(f"[dim]{escaped}[/dim]", end="")
|
|
1495
1485
|
elif isinstance(delta, ToolCallPartDelta):
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
# For tool calls, show token counter (use string repr for estimation)
|
|
1499
|
-
token_count[event.index] += len(str(delta)) // 3
|
|
1486
|
+
# For tool calls, count chunks received
|
|
1487
|
+
token_count[event.index] += 1
|
|
1500
1488
|
# Get tool name if available
|
|
1501
1489
|
tool_name = getattr(delta, "tool_name_delta", "")
|
|
1502
1490
|
count = token_count[event.index]
|
|
1503
1491
|
# Display with tool wrench icon and tool name
|
|
1504
1492
|
if tool_name:
|
|
1505
|
-
|
|
1506
|
-
f"
|
|
1493
|
+
console.print(
|
|
1494
|
+
f" 🔧 Calling {tool_name}... {count} chunks ",
|
|
1495
|
+
end="\r",
|
|
1507
1496
|
)
|
|
1508
1497
|
else:
|
|
1509
|
-
|
|
1510
|
-
f"
|
|
1498
|
+
console.print(
|
|
1499
|
+
f" 🔧 Calling tool... {count} chunks ",
|
|
1500
|
+
end="\r",
|
|
1511
1501
|
)
|
|
1512
|
-
sys.stdout.flush()
|
|
1513
1502
|
|
|
1514
1503
|
# PartEndEvent - finish the streaming with a newline
|
|
1515
1504
|
elif isinstance(event, PartEndEvent):
|
|
1516
1505
|
if event.index in streaming_parts:
|
|
1517
|
-
import sys
|
|
1518
|
-
|
|
1519
1506
|
# For text parts, clear counter line and render markdown
|
|
1520
1507
|
if event.index in text_parts:
|
|
1521
|
-
# Clear the
|
|
1522
|
-
|
|
1523
|
-
sys.stdout.flush()
|
|
1508
|
+
# Clear the chunk counter line by printing spaces and returning
|
|
1509
|
+
console.print(" " * 50, end="\r")
|
|
1524
1510
|
# Render the final markdown nicely
|
|
1525
1511
|
if event.index in text_buffer:
|
|
1526
1512
|
try:
|
|
@@ -1530,11 +1516,10 @@ class BaseAgent(ABC):
|
|
|
1530
1516
|
except Exception:
|
|
1531
1517
|
pass
|
|
1532
1518
|
del text_buffer[event.index]
|
|
1533
|
-
# For tool parts, clear the
|
|
1519
|
+
# For tool parts, clear the chunk counter line
|
|
1534
1520
|
elif event.index in tool_parts:
|
|
1535
|
-
# Clear the
|
|
1536
|
-
|
|
1537
|
-
sys.stdout.flush()
|
|
1521
|
+
# Clear the chunk counter line by printing spaces and returning
|
|
1522
|
+
console.print(" " * 50, end="\r")
|
|
1538
1523
|
# For thinking parts, just print newline
|
|
1539
1524
|
elif event.index in banner_printed:
|
|
1540
1525
|
console.print() # Final newline after streaming
|
|
@@ -1953,7 +1938,12 @@ class BaseAgent(ABC):
|
|
|
1953
1938
|
def graceful_sigint_handler(_sig, _frame):
|
|
1954
1939
|
# When using keyboard-based cancel, SIGINT should be a no-op
|
|
1955
1940
|
# (just show a hint to user about the configured cancel key)
|
|
1941
|
+
# Also reset terminal to prevent bricking on Windows+uvx
|
|
1956
1942
|
from code_puppy.keymap import get_cancel_agent_display_name
|
|
1943
|
+
from code_puppy.terminal_utils import reset_windows_terminal_full
|
|
1944
|
+
|
|
1945
|
+
# Reset terminal state first to prevent bricking
|
|
1946
|
+
reset_windows_terminal_full()
|
|
1957
1947
|
|
|
1958
1948
|
cancel_key = get_cancel_agent_display_name()
|
|
1959
1949
|
emit_info(f"Use {cancel_key} to cancel the agent task.")
|
|
@@ -1961,12 +1951,6 @@ class BaseAgent(ABC):
|
|
|
1961
1951
|
original_handler = None
|
|
1962
1952
|
key_listener_stop_event = None
|
|
1963
1953
|
_key_listener_thread = None
|
|
1964
|
-
windows_ctrl_handler = None
|
|
1965
|
-
|
|
1966
|
-
# Check if we're on Windows
|
|
1967
|
-
import sys
|
|
1968
|
-
|
|
1969
|
-
is_windows = sys.platform.startswith("win")
|
|
1970
1954
|
|
|
1971
1955
|
try:
|
|
1972
1956
|
if cancel_agent_uses_signal():
|
|
@@ -1974,27 +1958,10 @@ class BaseAgent(ABC):
|
|
|
1974
1958
|
original_handler = signal.signal(
|
|
1975
1959
|
signal.SIGINT, keyboard_interrupt_handler
|
|
1976
1960
|
)
|
|
1977
|
-
# On Windows, also use SetConsoleCtrlHandler for reliable Ctrl+C with uvx
|
|
1978
|
-
if is_windows:
|
|
1979
|
-
windows_ctrl_handler = _add_windows_ctrl_handler(
|
|
1980
|
-
schedule_agent_cancel
|
|
1981
|
-
)
|
|
1982
1961
|
else:
|
|
1983
1962
|
# Use keyboard listener for agent cancellation
|
|
1984
1963
|
# Set a graceful SIGINT handler that shows a hint
|
|
1985
1964
|
original_handler = signal.signal(signal.SIGINT, graceful_sigint_handler)
|
|
1986
|
-
# On Windows, SetConsoleCtrlHandler should also show the hint
|
|
1987
|
-
if is_windows:
|
|
1988
|
-
|
|
1989
|
-
def graceful_ctrl_handler():
|
|
1990
|
-
from code_puppy.keymap import get_cancel_agent_display_name
|
|
1991
|
-
|
|
1992
|
-
cancel_key = get_cancel_agent_display_name()
|
|
1993
|
-
emit_info(f"Use {cancel_key} to cancel the agent task.")
|
|
1994
|
-
|
|
1995
|
-
windows_ctrl_handler = _add_windows_ctrl_handler(
|
|
1996
|
-
graceful_ctrl_handler
|
|
1997
|
-
)
|
|
1998
1965
|
# Spawn keyboard listener with the cancel agent callback
|
|
1999
1966
|
key_listener_stop_event = threading.Event()
|
|
2000
1967
|
_key_listener_thread = self._spawn_ctrl_x_key_listener(
|
|
@@ -2024,17 +1991,8 @@ class BaseAgent(ABC):
|
|
|
2024
1991
|
# Stop keyboard listener if it was started
|
|
2025
1992
|
if key_listener_stop_event is not None:
|
|
2026
1993
|
key_listener_stop_event.set()
|
|
2027
|
-
# Remove Windows console handler
|
|
2028
|
-
if windows_ctrl_handler is not None:
|
|
2029
|
-
_remove_windows_ctrl_handler(windows_ctrl_handler)
|
|
2030
1994
|
# Restore original signal handler
|
|
2031
1995
|
if (
|
|
2032
1996
|
original_handler is not None
|
|
2033
1997
|
): # Explicit None check - SIG_DFL can be 0/falsy!
|
|
2034
1998
|
signal.signal(signal.SIGINT, original_handler)
|
|
2035
|
-
# Windows-specific: Reset terminal after Ctrl+C to prevent corruption
|
|
2036
|
-
# This fixes the issue where Enter key shows as 'm' after interrupting with uvx
|
|
2037
|
-
if is_windows:
|
|
2038
|
-
from code_puppy.terminal_utils import reset_windows_terminal_full
|
|
2039
|
-
|
|
2040
|
-
reset_windows_terminal_full()
|
|
@@ -171,6 +171,45 @@ async def main():
|
|
|
171
171
|
emit_error(str(e))
|
|
172
172
|
sys.exit(1)
|
|
173
173
|
|
|
174
|
+
# Show uvx detection notice if we're on Windows + uvx
|
|
175
|
+
# Also disable Ctrl+C at the console level to prevent terminal bricking
|
|
176
|
+
try:
|
|
177
|
+
from code_puppy.uvx_detection import should_use_alternate_cancel_key
|
|
178
|
+
|
|
179
|
+
if should_use_alternate_cancel_key():
|
|
180
|
+
from code_puppy.terminal_utils import (
|
|
181
|
+
disable_windows_ctrl_c,
|
|
182
|
+
set_keep_ctrl_c_disabled,
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
# Disable Ctrl+C at the console input level
|
|
186
|
+
# This prevents Ctrl+C from being processed as a signal at all
|
|
187
|
+
disable_windows_ctrl_c()
|
|
188
|
+
|
|
189
|
+
# Set flag to keep it disabled (prompt_toolkit may re-enable it)
|
|
190
|
+
set_keep_ctrl_c_disabled(True)
|
|
191
|
+
|
|
192
|
+
# Use print directly - emit_system_message can get cleared by ANSI codes
|
|
193
|
+
print(
|
|
194
|
+
"🔧 Detected uvx launch on Windows - using Ctrl+K for cancellation "
|
|
195
|
+
"(Ctrl+C is disabled to prevent terminal issues)"
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
# Also install a SIGINT handler as backup
|
|
199
|
+
import signal
|
|
200
|
+
|
|
201
|
+
from code_puppy.terminal_utils import reset_windows_terminal_full
|
|
202
|
+
|
|
203
|
+
def _uvx_protective_sigint_handler(_sig, _frame):
|
|
204
|
+
"""Protective SIGINT handler for Windows+uvx."""
|
|
205
|
+
reset_windows_terminal_full()
|
|
206
|
+
# Re-disable Ctrl+C in case something re-enabled it
|
|
207
|
+
disable_windows_ctrl_c()
|
|
208
|
+
|
|
209
|
+
signal.signal(signal.SIGINT, _uvx_protective_sigint_handler)
|
|
210
|
+
except ImportError:
|
|
211
|
+
pass # uvx_detection module not available, ignore
|
|
212
|
+
|
|
174
213
|
# Load API keys from puppy.cfg into environment variables
|
|
175
214
|
from code_puppy.config import load_api_keys_to_environment
|
|
176
215
|
|
|
@@ -421,10 +460,6 @@ async def interactive_mode(message_renderer, initial_command: str = None) -> Non
|
|
|
421
460
|
current_agent_task = None
|
|
422
461
|
|
|
423
462
|
while True:
|
|
424
|
-
# Windows-specific: Aggressively reset terminal at the start of every loop
|
|
425
|
-
# This fixes terminal corruption after Ctrl+C, especially when running via uvx
|
|
426
|
-
reset_windows_terminal_full()
|
|
427
|
-
|
|
428
463
|
from code_puppy.agents.agent_manager import get_current_agent
|
|
429
464
|
from code_puppy.messaging import emit_info
|
|
430
465
|
|
|
@@ -444,6 +479,15 @@ async def interactive_mode(message_renderer, initial_command: str = None) -> Non
|
|
|
444
479
|
task = await get_input_with_combined_completion(
|
|
445
480
|
get_prompt_with_active_model(), history_file=COMMAND_HISTORY_FILE
|
|
446
481
|
)
|
|
482
|
+
|
|
483
|
+
# Windows+uvx: Re-disable Ctrl+C after prompt_toolkit
|
|
484
|
+
# (prompt_toolkit restores console mode which re-enables Ctrl+C)
|
|
485
|
+
try:
|
|
486
|
+
from code_puppy.terminal_utils import ensure_ctrl_c_disabled
|
|
487
|
+
|
|
488
|
+
ensure_ctrl_c_disabled()
|
|
489
|
+
except ImportError:
|
|
490
|
+
pass
|
|
447
491
|
except ImportError:
|
|
448
492
|
# Fall back to basic input if prompt_toolkit is not available
|
|
449
493
|
task = input(">>> ")
|
|
@@ -608,8 +652,14 @@ async def interactive_mode(message_renderer, initial_command: str = None) -> Non
|
|
|
608
652
|
# Check if the task was cancelled (but don't show message if we just killed processes)
|
|
609
653
|
if result is None:
|
|
610
654
|
# Windows-specific: Reset terminal state after cancellation
|
|
611
|
-
|
|
612
|
-
|
|
655
|
+
reset_windows_terminal_ansi()
|
|
656
|
+
# Re-disable Ctrl+C if needed (uvx mode)
|
|
657
|
+
try:
|
|
658
|
+
from code_puppy.terminal_utils import ensure_ctrl_c_disabled
|
|
659
|
+
|
|
660
|
+
ensure_ctrl_c_disabled()
|
|
661
|
+
except ImportError:
|
|
662
|
+
pass
|
|
613
663
|
continue
|
|
614
664
|
# Get the structured response
|
|
615
665
|
agent_response = result.output
|
|
@@ -650,6 +700,15 @@ async def interactive_mode(message_renderer, initial_command: str = None) -> Non
|
|
|
650
700
|
|
|
651
701
|
auto_save_session_if_enabled()
|
|
652
702
|
|
|
703
|
+
# Re-disable Ctrl+C if needed (uvx mode) - must be done after
|
|
704
|
+
# each iteration as various operations may restore console mode
|
|
705
|
+
try:
|
|
706
|
+
from code_puppy.terminal_utils import ensure_ctrl_c_disabled
|
|
707
|
+
|
|
708
|
+
ensure_ctrl_c_disabled()
|
|
709
|
+
except ImportError:
|
|
710
|
+
pass
|
|
711
|
+
|
|
653
712
|
|
|
654
713
|
def prettier_code_blocks():
|
|
655
714
|
"""Configure Rich to use prettier code block rendering."""
|
|
@@ -711,9 +770,6 @@ async def run_prompt_with_attachments(
|
|
|
711
770
|
attachments = [attachment.content for attachment in processed_prompt.attachments]
|
|
712
771
|
link_attachments = [link.url_part for link in processed_prompt.link_attachments]
|
|
713
772
|
|
|
714
|
-
# Trigger invoke_agent callbacks (e.g., Claude Code OAuth token refresh)
|
|
715
|
-
await callbacks.on_invoke_agent()
|
|
716
|
-
|
|
717
773
|
# IMPORTANT: Set the shared console on the agent so that streaming output
|
|
718
774
|
# uses the same console as the spinner. This prevents Live display conflicts
|
|
719
775
|
# that cause line duplication during markdown streaming.
|
|
@@ -55,11 +55,19 @@ class KeymapError(Exception):
|
|
|
55
55
|
def get_cancel_agent_key() -> str:
|
|
56
56
|
"""Get the configured cancel agent key from config.
|
|
57
57
|
|
|
58
|
+
On Windows when launched via uvx, this automatically returns "ctrl+k"
|
|
59
|
+
to work around uvx capturing Ctrl+C before it reaches Python.
|
|
60
|
+
|
|
58
61
|
Returns:
|
|
59
62
|
The key name (e.g., "ctrl+c", "ctrl+k") from config,
|
|
60
63
|
or the default if not configured.
|
|
61
64
|
"""
|
|
62
65
|
from code_puppy.config import get_value
|
|
66
|
+
from code_puppy.uvx_detection import should_use_alternate_cancel_key
|
|
67
|
+
|
|
68
|
+
# On Windows + uvx, force ctrl+k to bypass uvx's SIGINT capture
|
|
69
|
+
if should_use_alternate_cancel_key():
|
|
70
|
+
return "ctrl+k"
|
|
63
71
|
|
|
64
72
|
key = get_value("cancel_agent_key")
|
|
65
73
|
if key is None or key.strip() == "":
|
{code_puppy-0.0.331 → code_puppy-0.0.333}/code_puppy/plugins/claude_code_oauth/register_callbacks.py
RENAMED
|
@@ -25,7 +25,6 @@ from .utils import (
|
|
|
25
25
|
fetch_claude_code_models,
|
|
26
26
|
load_claude_models_filtered,
|
|
27
27
|
load_stored_tokens,
|
|
28
|
-
maybe_refresh_token,
|
|
29
28
|
prepare_oauth_context,
|
|
30
29
|
remove_claude_code_models,
|
|
31
30
|
save_tokens,
|
|
@@ -303,19 +302,5 @@ def _handle_custom_command(command: str, name: str) -> Optional[bool]:
|
|
|
303
302
|
return None
|
|
304
303
|
|
|
305
304
|
|
|
306
|
-
def _on_invoke_agent(*args, **kwargs) -> None:
|
|
307
|
-
"""Called before each agent invocation.
|
|
308
|
-
|
|
309
|
-
Checks if 30 minutes have passed since last token refresh and
|
|
310
|
-
refreshes the Claude Code OAuth token if needed.
|
|
311
|
-
"""
|
|
312
|
-
try:
|
|
313
|
-
if maybe_refresh_token():
|
|
314
|
-
logger.debug("Token refresh check completed")
|
|
315
|
-
except Exception as exc: # pragma: no cover - defensive
|
|
316
|
-
logger.warning("Token refresh check failed: %s", exc)
|
|
317
|
-
|
|
318
|
-
|
|
319
305
|
register_callback("custom_command_help", _custom_help)
|
|
320
306
|
register_callback("custom_command", _handle_custom_command)
|
|
321
|
-
register_callback("invoke_agent", _on_invoke_agent)
|
|
@@ -23,10 +23,6 @@ from .config import (
|
|
|
23
23
|
|
|
24
24
|
logger = logging.getLogger(__name__)
|
|
25
25
|
|
|
26
|
-
# Token refresh tracking
|
|
27
|
-
_last_refresh_time: float = 0.0
|
|
28
|
-
REFRESH_INTERVAL_SECONDS: float = 30 * 60 # 30 minutes
|
|
29
|
-
|
|
30
26
|
|
|
31
27
|
@dataclass
|
|
32
28
|
class OAuthContext:
|
|
@@ -401,201 +397,3 @@ def remove_claude_code_models() -> int:
|
|
|
401
397
|
except Exception as exc: # pragma: no cover - defensive logging
|
|
402
398
|
logger.error("Error removing Claude Code models: %s", exc)
|
|
403
399
|
return 0
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
def _update_model_tokens(new_access_token: str) -> bool:
|
|
407
|
-
"""Update all Claude Code models with the new access token.
|
|
408
|
-
|
|
409
|
-
Args:
|
|
410
|
-
new_access_token: The new access token to set
|
|
411
|
-
|
|
412
|
-
Returns:
|
|
413
|
-
True if successful, False otherwise
|
|
414
|
-
"""
|
|
415
|
-
try:
|
|
416
|
-
claude_models = load_claude_models()
|
|
417
|
-
if not claude_models:
|
|
418
|
-
logger.debug("No models to update")
|
|
419
|
-
return True
|
|
420
|
-
|
|
421
|
-
updated = 0
|
|
422
|
-
for _model_name, config in claude_models.items():
|
|
423
|
-
if config.get("oauth_source") == "claude-code-plugin":
|
|
424
|
-
if (
|
|
425
|
-
"custom_endpoint" in config
|
|
426
|
-
and "api_key" in config["custom_endpoint"]
|
|
427
|
-
):
|
|
428
|
-
config["custom_endpoint"]["api_key"] = new_access_token
|
|
429
|
-
updated += 1
|
|
430
|
-
|
|
431
|
-
if updated > 0:
|
|
432
|
-
if save_claude_models(claude_models):
|
|
433
|
-
logger.info("Updated %s model configurations with new token", updated)
|
|
434
|
-
return True
|
|
435
|
-
else:
|
|
436
|
-
logger.error("Failed to save updated model configurations")
|
|
437
|
-
return False
|
|
438
|
-
|
|
439
|
-
return True
|
|
440
|
-
|
|
441
|
-
except Exception as exc: # pragma: no cover - defensive logging
|
|
442
|
-
logger.error("Error updating model tokens: %s", exc)
|
|
443
|
-
return False
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
def refresh_access_token() -> Optional[str]:
|
|
447
|
-
"""Refresh the access token using the refresh token.
|
|
448
|
-
|
|
449
|
-
Returns:
|
|
450
|
-
New access token if successful, None otherwise
|
|
451
|
-
"""
|
|
452
|
-
try:
|
|
453
|
-
tokens = load_stored_tokens()
|
|
454
|
-
if not tokens:
|
|
455
|
-
logger.debug("No stored tokens found for refresh")
|
|
456
|
-
return None
|
|
457
|
-
|
|
458
|
-
if "refresh_token" not in tokens:
|
|
459
|
-
logger.debug("No refresh token available")
|
|
460
|
-
return None
|
|
461
|
-
|
|
462
|
-
refresh_token = tokens["refresh_token"]
|
|
463
|
-
|
|
464
|
-
# Prepare refresh request
|
|
465
|
-
payload = {
|
|
466
|
-
"grant_type": "refresh_token",
|
|
467
|
-
"client_id": CLAUDE_CODE_OAUTH_CONFIG["client_id"],
|
|
468
|
-
"refresh_token": refresh_token,
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
headers = {
|
|
472
|
-
"Content-Type": "application/json",
|
|
473
|
-
"Accept": "application/json",
|
|
474
|
-
"anthropic-beta": "oauth-2025-04-20",
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
logger.info("Refreshing Claude Code access token...")
|
|
478
|
-
response = requests.post(
|
|
479
|
-
CLAUDE_CODE_OAUTH_CONFIG["token_url"],
|
|
480
|
-
json=payload,
|
|
481
|
-
headers=headers,
|
|
482
|
-
timeout=30,
|
|
483
|
-
)
|
|
484
|
-
|
|
485
|
-
if response.status_code == 200:
|
|
486
|
-
token_data = response.json()
|
|
487
|
-
|
|
488
|
-
# Update tokens with new access token and expiry
|
|
489
|
-
new_access_token = token_data.get("access_token")
|
|
490
|
-
if not new_access_token:
|
|
491
|
-
logger.error("No access_token in refresh response")
|
|
492
|
-
return None
|
|
493
|
-
|
|
494
|
-
# Update stored tokens
|
|
495
|
-
tokens["access_token"] = new_access_token
|
|
496
|
-
|
|
497
|
-
# Update expiry if provided
|
|
498
|
-
if "expires_in" in token_data:
|
|
499
|
-
tokens["expires_at"] = time.time() + token_data["expires_in"]
|
|
500
|
-
|
|
501
|
-
# Update refresh token if a new one was provided
|
|
502
|
-
if "refresh_token" in token_data:
|
|
503
|
-
tokens["refresh_token"] = token_data["refresh_token"]
|
|
504
|
-
|
|
505
|
-
# Save updated tokens
|
|
506
|
-
if save_tokens(tokens):
|
|
507
|
-
logger.info("Claude Code access token refreshed successfully")
|
|
508
|
-
|
|
509
|
-
# Update model configurations with new token
|
|
510
|
-
_update_model_tokens(new_access_token)
|
|
511
|
-
|
|
512
|
-
return new_access_token
|
|
513
|
-
else:
|
|
514
|
-
logger.error("Failed to save refreshed tokens")
|
|
515
|
-
return None
|
|
516
|
-
else:
|
|
517
|
-
logger.warning(
|
|
518
|
-
"Token refresh failed: %s - %s",
|
|
519
|
-
response.status_code,
|
|
520
|
-
response.text,
|
|
521
|
-
)
|
|
522
|
-
return None
|
|
523
|
-
|
|
524
|
-
except Exception as exc: # pragma: no cover - defensive logging
|
|
525
|
-
logger.error("Error refreshing access token: %s", exc)
|
|
526
|
-
return None
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
def _is_using_claude_code_model() -> bool:
|
|
530
|
-
"""Check if the current agent is using a Claude Code OAuth model.
|
|
531
|
-
|
|
532
|
-
Returns:
|
|
533
|
-
True if currently using a claude-code-* model, False otherwise
|
|
534
|
-
"""
|
|
535
|
-
try:
|
|
536
|
-
from code_puppy.agents import get_current_agent
|
|
537
|
-
from code_puppy.model_utils import is_claude_code_model
|
|
538
|
-
|
|
539
|
-
agent = get_current_agent()
|
|
540
|
-
if agent is None:
|
|
541
|
-
return False
|
|
542
|
-
|
|
543
|
-
model_name = agent.get_model_name()
|
|
544
|
-
if not model_name:
|
|
545
|
-
return False
|
|
546
|
-
|
|
547
|
-
return is_claude_code_model(model_name)
|
|
548
|
-
except Exception as exc:
|
|
549
|
-
logger.debug("Could not determine current model: %s", exc)
|
|
550
|
-
return False
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
def maybe_refresh_token() -> bool:
|
|
554
|
-
"""Refresh the token if 30 minutes have passed since last refresh.
|
|
555
|
-
|
|
556
|
-
This function is designed to be called on every prompt, but will only
|
|
557
|
-
actually refresh the token if:
|
|
558
|
-
1. The current model is a Claude Code OAuth model (starts with 'claude-code-')
|
|
559
|
-
2. REFRESH_INTERVAL_SECONDS (30 min) has passed since last refresh
|
|
560
|
-
|
|
561
|
-
Returns:
|
|
562
|
-
True if refresh was attempted (regardless of success), False if skipped
|
|
563
|
-
"""
|
|
564
|
-
global _last_refresh_time
|
|
565
|
-
|
|
566
|
-
# Only refresh if we're actually using a Claude Code model
|
|
567
|
-
if not _is_using_claude_code_model():
|
|
568
|
-
return False
|
|
569
|
-
|
|
570
|
-
# Check if we have tokens at all
|
|
571
|
-
tokens = load_stored_tokens()
|
|
572
|
-
if not tokens or "refresh_token" not in tokens:
|
|
573
|
-
return False
|
|
574
|
-
|
|
575
|
-
current_time = time.time()
|
|
576
|
-
time_since_last = current_time - _last_refresh_time
|
|
577
|
-
|
|
578
|
-
if time_since_last < REFRESH_INTERVAL_SECONDS:
|
|
579
|
-
logger.debug(
|
|
580
|
-
"Skipping token refresh, %.1f minutes until next refresh",
|
|
581
|
-
(REFRESH_INTERVAL_SECONDS - time_since_last) / 60,
|
|
582
|
-
)
|
|
583
|
-
return False
|
|
584
|
-
|
|
585
|
-
logger.info(
|
|
586
|
-
"Token refresh interval reached (%.1f min since last refresh)",
|
|
587
|
-
time_since_last / 60,
|
|
588
|
-
)
|
|
589
|
-
|
|
590
|
-
# Attempt refresh
|
|
591
|
-
result = refresh_access_token()
|
|
592
|
-
if result:
|
|
593
|
-
_last_refresh_time = current_time
|
|
594
|
-
logger.info("Token refresh successful, next refresh in 30 minutes")
|
|
595
|
-
else:
|
|
596
|
-
# Even on failure, update the timestamp to avoid hammering the API
|
|
597
|
-
# We'll retry on the next 30-min interval
|
|
598
|
-
_last_refresh_time = current_time
|
|
599
|
-
logger.warning("Token refresh failed, will retry in 30 minutes")
|
|
600
|
-
|
|
601
|
-
return True
|