code-puppy 0.0.379__py3-none-any.whl → 0.0.380__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.
@@ -3,8 +3,11 @@
3
3
  import asyncio
4
4
  import json
5
5
  import math
6
+ import pathlib
6
7
  import signal
7
8
  import threading
9
+ import time
10
+ import traceback
8
11
  import uuid
9
12
  from abc import ABC, abstractmethod
10
13
  from typing import (
@@ -37,6 +40,7 @@ from pydantic_ai.durable_exec.dbos import DBOSAgent
37
40
  from pydantic_ai.messages import (
38
41
  ModelMessage,
39
42
  ModelRequest,
43
+ ModelResponse,
40
44
  TextPart,
41
45
  ThinkingPart,
42
46
  ToolCallPart,
@@ -88,6 +92,49 @@ _delayed_compaction_requested = False
88
92
  _reload_count = 0
89
93
 
90
94
 
95
+ def _log_error_to_file(exc: Exception) -> Optional[str]:
96
+ """Log detailed error information to ~/.code_puppy/error_logs/log_{timestamp}.txt.
97
+
98
+ Args:
99
+ exc: The exception to log.
100
+
101
+ Returns:
102
+ The path to the log file if successful, None otherwise.
103
+ """
104
+ try:
105
+ error_logs_dir = pathlib.Path.home() / ".code_puppy" / "error_logs"
106
+ error_logs_dir.mkdir(parents=True, exist_ok=True)
107
+
108
+ timestamp = time.strftime("%Y%m%d_%H%M%S")
109
+ log_file = error_logs_dir / f"log_{timestamp}.txt"
110
+
111
+ with open(log_file, "w", encoding="utf-8") as f:
112
+ f.write(f"Timestamp: {time.strftime('%Y-%m-%d %H:%M:%S')}\n")
113
+ f.write(f"Exception Type: {type(exc).__name__}\n")
114
+ f.write(f"Exception Message: {str(exc)}\n")
115
+ f.write(f"Exception Args: {exc.args}\n")
116
+ f.write("\n--- Full Traceback ---\n")
117
+ f.write(traceback.format_exc())
118
+ f.write("\n--- Exception Chain ---\n")
119
+ # Walk the exception chain for chained exceptions
120
+ current = exc
121
+ chain_depth = 0
122
+ while current is not None and chain_depth < 10:
123
+ f.write(
124
+ f"\n[Cause {chain_depth}] {type(current).__name__}: {current}\n"
125
+ )
126
+ f.write("".join(traceback.format_tb(current.__traceback__)))
127
+ current = (
128
+ current.__cause__ if current.__cause__ else current.__context__
129
+ )
130
+ chain_depth += 1
131
+
132
+ return str(log_file)
133
+ except Exception:
134
+ # Don't let logging errors break the main flow
135
+ return None
136
+
137
+
91
138
  class BaseAgent(ABC):
92
139
  """Base class for all agent configurations."""
93
140
 
@@ -264,6 +311,33 @@ class BaseAgent(ABC):
264
311
  cleaned.append(message)
265
312
  return cleaned
266
313
 
314
+ def ensure_history_ends_with_request(
315
+ self, messages: List[ModelMessage]
316
+ ) -> List[ModelMessage]:
317
+ """Ensure message history ends with a ModelRequest.
318
+
319
+ pydantic_ai requires that processed message history ends with a ModelRequest.
320
+ This can fail when swapping models mid-conversation if the history ends with
321
+ a ModelResponse from the previous model.
322
+
323
+ This method trims trailing ModelResponse messages to ensure compatibility.
324
+
325
+ Args:
326
+ messages: List of messages to validate/fix.
327
+
328
+ Returns:
329
+ List of messages guaranteed to end with ModelRequest, or empty list
330
+ if no ModelRequest is found.
331
+ """
332
+ if not messages:
333
+ return messages
334
+
335
+ # Trim trailing ModelResponse messages
336
+ while messages and isinstance(messages[-1], ModelResponse):
337
+ messages = messages[:-1]
338
+
339
+ return messages
340
+
267
341
  # Message history processing methods (moved from state_management.py and message_history_processor.py)
268
342
  def _stringify_part(self, part: Any) -> str:
269
343
  """Create a stable string representation for a message part.
@@ -372,10 +446,10 @@ class BaseAgent(ABC):
372
446
 
373
447
  def estimate_token_count(self, text: str) -> int:
374
448
  """
375
- Simple token estimation using len(message) / 3.
449
+ Simple token estimation using len(message) / 2.5.
376
450
  This replaces tiktoken with a much simpler approach.
377
451
  """
378
- return max(1, math.floor((len(text) / 3)))
452
+ return max(1, math.floor((len(text) / 2.5)))
379
453
 
380
454
  def estimate_tokens_for_message(self, message: ModelMessage) -> int:
381
455
  """
code_puppy/callbacks.py CHANGED
@@ -27,6 +27,7 @@ PhaseType = Literal[
27
27
  "get_model_system_prompt",
28
28
  "agent_run_start",
29
29
  "agent_run_end",
30
+ "register_mcp_catalog_servers",
30
31
  ]
31
32
  CallbackFunc = Callable[..., Any]
32
33
 
@@ -54,6 +55,7 @@ _callbacks: Dict[PhaseType, List[CallbackFunc]] = {
54
55
  "get_model_system_prompt": [],
55
56
  "agent_run_start": [],
56
57
  "agent_run_end": [],
58
+ "register_mcp_catalog_servers": [],
57
59
  }
58
60
 
59
61
  logger = logging.getLogger(__name__)
@@ -517,3 +519,15 @@ async def on_agent_run_end(
517
519
  response_text,
518
520
  metadata,
519
521
  )
522
+
523
+
524
+ def on_register_mcp_catalog_servers() -> List[Any]:
525
+ """Trigger callbacks to register additional MCP catalog servers.
526
+
527
+ Plugins can register callbacks that return List[MCPServerTemplate] to add
528
+ servers to the MCP catalog/marketplace.
529
+
530
+ Returns:
531
+ List of results from all registered callbacks (each should be a list of MCPServerTemplate).
532
+ """
533
+ return _trigger_callbacks_sync("register_mcp_catalog_servers")
code_puppy/config.py CHANGED
@@ -144,6 +144,19 @@ def set_universal_constructor_enabled(enabled: bool) -> None:
144
144
  set_value("enable_universal_constructor", "true" if enabled else "false")
145
145
 
146
146
 
147
+ def get_enable_streaming() -> bool:
148
+ """
149
+ Get the enable_streaming configuration value.
150
+ Controls whether streaming (SSE) is used for model responses.
151
+ Returns True if streaming is enabled, False otherwise.
152
+ Defaults to True.
153
+ """
154
+ val = get_value("enable_streaming")
155
+ if val is None:
156
+ return True # Default to True for better UX
157
+ return str(val).lower() in ("1", "true", "yes", "on")
158
+
159
+
147
160
  DEFAULT_SECTION = "puppy"
148
161
  REQUIRED_KEYS = ["puppy_name", "owner_name"]
149
162
 
@@ -289,6 +302,8 @@ def get_config_keys():
289
302
  default_keys.append("enable_pack_agents")
290
303
  # Add universal constructor control key
291
304
  default_keys.append("enable_universal_constructor")
305
+ # Add streaming control key
306
+ default_keys.append("enable_streaming")
292
307
  # Add cancel agent key configuration
293
308
  default_keys.append("cancel_agent_key")
294
309
  # Add banner color keys
@@ -1025,7 +1025,20 @@ class MCPServerCatalog:
1025
1025
  """Catalog for searching and managing pre-configured MCP servers."""
1026
1026
 
1027
1027
  def __init__(self):
1028
- self.servers = MCP_SERVER_REGISTRY
1028
+ # Start with built-in servers
1029
+ self.servers = list(MCP_SERVER_REGISTRY)
1030
+
1031
+ # Let plugins add their own catalog entries
1032
+ try:
1033
+ from code_puppy.callbacks import on_register_mcp_catalog_servers
1034
+
1035
+ plugin_results = on_register_mcp_catalog_servers()
1036
+ for result in plugin_results:
1037
+ if isinstance(result, list):
1038
+ self.servers.extend(result)
1039
+ except Exception:
1040
+ pass # Don't break catalog if plugins fail
1041
+
1029
1042
  self._build_index()
1030
1043
 
1031
1044
  def _build_index(self):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: code-puppy
3
- Version: 0.0.379
3
+ Version: 0.0.380
4
4
  Summary: Code generation agent
5
5
  Project-URL: repository, https://github.com/mpfaffenberger/code_puppy
6
6
  Project-URL: HomePage, https://github.com/mpfaffenberger/code_puppy
@@ -1,10 +1,10 @@
1
1
  code_puppy/__init__.py,sha256=xMPewo9RNHb3yfFNIk5WCbv2cvSPtJOCgK2-GqLbNnU,373
2
2
  code_puppy/__main__.py,sha256=pDVssJOWP8A83iFkxMLY9YteHYat0EyWDQqMkKHpWp4,203
3
- code_puppy/callbacks.py,sha256=A7aqykjNVB2HorewzerCEb3YYnqeDIdQG_2wNTt1paE,16745
3
+ code_puppy/callbacks.py,sha256=Gy9i__GMMeFxJns0HggRfSkl5Pcnwzg_fyczOWKPu8s,17256
4
4
  code_puppy/chatgpt_codex_client.py,sha256=upMuAfOhMB7SEpVw4CU4GjgaeZ8X65ri3yNM-dnlmYA,12308
5
5
  code_puppy/claude_cache_client.py,sha256=GtwYrxcTe0pE-JGtl1ysR2qskfeE73_x4w7q_u-kR1k,24026
6
6
  code_puppy/cli_runner.py,sha256=w5CLKgQYYaT7My3Cga2StXYol-u6DBxNzzUuhhsfhsA,34952
7
- code_puppy/config.py,sha256=eAyVqiu8SwzJQpaJu80rlJvd8XXY51DqafMsP5lBRI4,55827
7
+ code_puppy/config.py,sha256=mdup26I0W599y297WuYm2vPRPCtm7Qbwf_DfN90k2A4,56325
8
8
  code_puppy/error_logging.py,sha256=a80OILCUtJhexI6a9GM-r5LqIdjvSRzggfgPp2jv1X0,3297
9
9
  code_puppy/gemini_code_assist.py,sha256=KGS7sO5OLc83nDF3xxS-QiU6vxW9vcm6hmzilu79Ef8,13867
10
10
  code_puppy/gemini_model.py,sha256=UHb5vFC9zrEdFJ-yCN3vNCdp0UxP156BL_fwbnEhaw8,27988
@@ -45,7 +45,7 @@ code_puppy/agents/agent_qa_kitten.py,sha256=qvry-1u_CiXi8eRueHTax4OtqsS_mQrtXHsb
45
45
  code_puppy/agents/agent_security_auditor.py,sha256=SpiYNA0XAsIwBj7S2_EQPRslRUmF_-b89pIJyW7DYtY,12022
46
46
  code_puppy/agents/agent_terminal_qa.py,sha256=U-iyP7OBWdAmchW_oUU8k6asH2aignTMmgqqYDyf-ms,10343
47
47
  code_puppy/agents/agent_typescript_reviewer.py,sha256=vsnpp98xg6cIoFAEJrRTUM_i4wLEWGm5nJxs6fhHobM,10275
48
- code_puppy/agents/base_agent.py,sha256=gZvACpqH8L2Wp2xjn_v5D4Azlt6yvGnQO6UApN8HCEo,76272
48
+ code_puppy/agents/base_agent.py,sha256=oc59XiPb7xfuLo70vduxGtjAWGWZd6ZzsV_rsNcsmB4,78924
49
49
  code_puppy/agents/event_stream_handler.py,sha256=JttLZJpNADE5HXiXY-GZ6tpwaBeFRODcy34KiquPOvU,14952
50
50
  code_puppy/agents/json_agent.py,sha256=FtbZxO8mo563kvXgpgRM4b-c9VA3G3cty7r-O0nBZQk,5690
51
51
  code_puppy/agents/prompt_reviewer.py,sha256=JJrJ0m5q0Puxl8vFsyhAbY9ftU9n6c6UxEVdNct1E-Q,5558
@@ -130,7 +130,7 @@ code_puppy/mcp_/manager.py,sha256=_2ZRTLS8Sf3SMgEpAHl-wXBDYVqg2l-j9uI9EkfCNaE,31
130
130
  code_puppy/mcp_/mcp_logs.py,sha256=o4pSHwELWIjEjqhfaMMEGrBvb159-VIgUp21E707BPo,6264
131
131
  code_puppy/mcp_/registry.py,sha256=U_t12WQ-En-KGyZoiTYdqlhp9NkDTWafu8g5InvF2NM,15774
132
132
  code_puppy/mcp_/retry_manager.py,sha256=evVxbtrsHNyo8UoI7zpO-NVDegibn82RLlgN8VKewA8,10665
133
- code_puppy/mcp_/server_registry_catalog.py,sha256=fr_wsr99BphnaDiPLcN60t4Mp62lbt8rYNOpghKnqEA,39429
133
+ code_puppy/mcp_/server_registry_catalog.py,sha256=HhWXMsU4xq3zxpzKhV5DvFh7i7Ho30kPkm4XIY6V0tE,39898
134
134
  code_puppy/mcp_/status_tracker.py,sha256=uekxrzkzIWrv3OfSVgblaPuoGFcAh_dBYwCcaHZ_CrM,12183
135
135
  code_puppy/mcp_/system_tools.py,sha256=7_oR8k0c8YjtCcYF9g7A946oAGuKOf_i-92aJH7VmlQ,7331
136
136
  code_puppy/mcp_/examples/retry_example.py,sha256=Qi5K6cNmhc5-zncZa0F_dkJUEdZ6OIgt1xfG5PUxt3Q,7234
@@ -225,10 +225,10 @@ code_puppy/tools/browser/chromium_terminal_manager.py,sha256=w1thQ_ACb6oV45L93TS
225
225
  code_puppy/tools/browser/terminal_command_tools.py,sha256=9byOZku-dwvTtCl532xt7Lumed_jTn0sLvUe_X75XCQ,19068
226
226
  code_puppy/tools/browser/terminal_screenshot_tools.py,sha256=J_21YO_495NvYgNFu9KQP6VYg2K_f8CtSdZuF94Yhnw,18448
227
227
  code_puppy/tools/browser/terminal_tools.py,sha256=F5LjVH3udSCFHmqC3O1UJLoLozZFZsEdX42jOmkqkW0,17853
228
- code_puppy-0.0.379.data/data/code_puppy/models.json,sha256=SC7N2lV1Q8ikXlalRNqABkNvuuL_8fIIk638739-gGY,3319
229
- code_puppy-0.0.379.data/data/code_puppy/models_dev_api.json,sha256=wHjkj-IM_fx1oHki6-GqtOoCrRMR0ScK0f-Iz0UEcy8,548187
230
- code_puppy-0.0.379.dist-info/METADATA,sha256=ldoaFKnfpIocHpmV_ZBTVEjfW0l7YWxIX7qRXJt1rQM,27604
231
- code_puppy-0.0.379.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
232
- code_puppy-0.0.379.dist-info/entry_points.txt,sha256=Tp4eQC99WY3HOKd3sdvb22vZODRq0XkZVNpXOag_KdI,91
233
- code_puppy-0.0.379.dist-info/licenses/LICENSE,sha256=31u8x0SPgdOq3izJX41kgFazWsM43zPEF9eskzqbJMY,1075
234
- code_puppy-0.0.379.dist-info/RECORD,,
228
+ code_puppy-0.0.380.data/data/code_puppy/models.json,sha256=SC7N2lV1Q8ikXlalRNqABkNvuuL_8fIIk638739-gGY,3319
229
+ code_puppy-0.0.380.data/data/code_puppy/models_dev_api.json,sha256=wHjkj-IM_fx1oHki6-GqtOoCrRMR0ScK0f-Iz0UEcy8,548187
230
+ code_puppy-0.0.380.dist-info/METADATA,sha256=wly6VwqY5mH1VCOrdDaw_9n6b0gblNQ9rVc3DN4YyWw,27604
231
+ code_puppy-0.0.380.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
232
+ code_puppy-0.0.380.dist-info/entry_points.txt,sha256=Tp4eQC99WY3HOKd3sdvb22vZODRq0XkZVNpXOag_KdI,91
233
+ code_puppy-0.0.380.dist-info/licenses/LICENSE,sha256=31u8x0SPgdOq3izJX41kgFazWsM43zPEF9eskzqbJMY,1075
234
+ code_puppy-0.0.380.dist-info/RECORD,,