code-puppy 0.0.322__py3-none-any.whl → 0.0.324__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.
@@ -4,6 +4,7 @@ import asyncio
4
4
  import json
5
5
  import math
6
6
  import signal
7
+ import sys
7
8
  import threading
8
9
  import uuid
9
10
  from abc import ABC, abstractmethod
@@ -1910,29 +1911,72 @@ class BaseAgent(ABC):
1910
1911
  # When using keyboard-based cancel, SIGINT should be a no-op
1911
1912
  # (just show a hint to user about the configured cancel key)
1912
1913
  from code_puppy.keymap import get_cancel_agent_display_name
1914
+ import sys
1913
1915
 
1914
1916
  cancel_key = get_cancel_agent_display_name()
1915
- emit_info(f"Use {cancel_key} to cancel the agent task.")
1917
+ if sys.platform == "win32":
1918
+ # On Windows, we use keyboard listener, so SIGINT might still fire
1919
+ # but we handle cancellation via the key listener
1920
+ pass # Silent on Windows - the key listener handles it
1921
+ else:
1922
+ emit_info(f"Use {cancel_key} to cancel the agent task.")
1916
1923
 
1917
1924
  original_handler = None
1918
1925
  key_listener_stop_event = None
1919
1926
  _key_listener_thread = None
1927
+ _windows_ctrl_handler = None # Store reference to prevent garbage collection
1920
1928
 
1921
1929
  try:
1922
- if cancel_agent_uses_signal():
1923
- # Use SIGINT-based cancellation (default Ctrl+C behavior)
1930
+ if sys.platform == "win32":
1931
+ # Windows: Use SetConsoleCtrlHandler for reliable Ctrl+C handling
1932
+ import ctypes
1933
+
1934
+ # Define the handler function type
1935
+ HANDLER_ROUTINE = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.c_ulong)
1936
+
1937
+ def windows_ctrl_handler(ctrl_type):
1938
+ """Handle Windows console control events."""
1939
+ CTRL_C_EVENT = 0
1940
+ CTRL_BREAK_EVENT = 1
1941
+
1942
+ if ctrl_type in (CTRL_C_EVENT, CTRL_BREAK_EVENT):
1943
+ # Check if we're awaiting user input
1944
+ if is_awaiting_user_input():
1945
+ return False # Let default handler run
1946
+
1947
+ # Schedule agent cancellation
1948
+ schedule_agent_cancel()
1949
+ return True # We handled it, don't terminate
1950
+
1951
+ return False # Let other handlers process it
1952
+
1953
+ # Create the callback - must keep reference alive!
1954
+ _windows_ctrl_handler = HANDLER_ROUTINE(windows_ctrl_handler)
1955
+
1956
+ # Register the handler
1957
+ kernel32 = ctypes.windll.kernel32
1958
+ if not kernel32.SetConsoleCtrlHandler(_windows_ctrl_handler, True):
1959
+ emit_warning("Failed to set Windows Ctrl+C handler")
1960
+
1961
+ # Also spawn keyboard listener for Ctrl+X (shell cancel) and other keys
1962
+ key_listener_stop_event = threading.Event()
1963
+ _key_listener_thread = self._spawn_ctrl_x_key_listener(
1964
+ key_listener_stop_event,
1965
+ on_escape=lambda: None, # Ctrl+X handled by command_runner
1966
+ on_cancel_agent=None, # Ctrl+C handled by SetConsoleCtrlHandler above
1967
+ )
1968
+ elif cancel_agent_uses_signal():
1969
+ # Unix with Ctrl+C: Use SIGINT-based cancellation
1924
1970
  original_handler = signal.signal(
1925
1971
  signal.SIGINT, keyboard_interrupt_handler
1926
1972
  )
1927
1973
  else:
1928
- # Use keyboard listener for agent cancellation
1929
- # Set a graceful SIGINT handler that shows a hint
1974
+ # Unix with different cancel key: Use keyboard listener
1930
1975
  original_handler = signal.signal(signal.SIGINT, graceful_sigint_handler)
1931
- # Spawn keyboard listener with the cancel agent callback
1932
1976
  key_listener_stop_event = threading.Event()
1933
1977
  _key_listener_thread = self._spawn_ctrl_x_key_listener(
1934
1978
  key_listener_stop_event,
1935
- on_escape=lambda: None, # Ctrl+X handled by command_runner
1979
+ on_escape=lambda: None,
1936
1980
  on_cancel_agent=schedule_agent_cancel,
1937
1981
  )
1938
1982
 
@@ -1957,8 +2001,17 @@ class BaseAgent(ABC):
1957
2001
  # Stop keyboard listener if it was started
1958
2002
  if key_listener_stop_event is not None:
1959
2003
  key_listener_stop_event.set()
1960
- # Restore original signal handler
1961
- if (
1962
- original_handler is not None
1963
- ): # Explicit None check - SIG_DFL can be 0/falsy!
2004
+
2005
+ # Unregister Windows Ctrl handler
2006
+ if sys.platform == "win32" and _windows_ctrl_handler is not None:
2007
+ try:
2008
+ import ctypes
2009
+
2010
+ kernel32 = ctypes.windll.kernel32
2011
+ kernel32.SetConsoleCtrlHandler(_windows_ctrl_handler, False)
2012
+ except Exception:
2013
+ pass # Best effort cleanup
2014
+
2015
+ # Restore original signal handler (Unix)
2016
+ if original_handler is not None:
1964
2017
  signal.signal(signal.SIGINT, original_handler)
code_puppy/cli_runner.py CHANGED
@@ -790,5 +790,6 @@ def main_entry():
790
790
  DBOS.destroy()
791
791
  return 0
792
792
  finally:
793
- # Reset terminal on Unix-like systems (not Windows)
793
+ # Reset terminal on all platforms for clean state
794
+ reset_windows_terminal_full() # Safe no-op on non-Windows
794
795
  reset_unix_terminal()
code_puppy/keymap.py CHANGED
@@ -86,9 +86,15 @@ def cancel_agent_uses_signal() -> bool:
86
86
  """Check if the cancel agent key uses SIGINT (Ctrl+C).
87
87
 
88
88
  Returns:
89
- True if the cancel key is ctrl+c (uses SIGINT handler),
90
- False if it uses keyboard listener approach.
89
+ True if the cancel key is ctrl+c AND we're not on Windows
90
+ (uses SIGINT handler), False if it uses keyboard listener approach.
91
91
  """
92
+ import sys
93
+
94
+ # On Windows, always use keyboard listener - SIGINT is unreliable
95
+ if sys.platform == "win32":
96
+ return False
97
+
92
98
  return get_cancel_agent_key() == "ctrl+c"
93
99
 
94
100
 
code_puppy/models.json CHANGED
@@ -9,9 +9,9 @@
9
9
  "context_length": 200000,
10
10
  "supported_settings": ["temperature", "seed"]
11
11
  },
12
- "synthetic-MiniMax-M2": {
12
+ "synthetic-MiniMax-M2.1": {
13
13
  "type": "custom_openai",
14
- "name": "hf:MiniMaxAI/MiniMax-M2",
14
+ "name": "hf:MiniMaxAI/MiniMax-M2.1",
15
15
  "custom_endpoint": {
16
16
  "url": "https://api.synthetic.new/openai/v1/",
17
17
  "api_key": "$SYN_API_KEY"
@@ -192,6 +192,11 @@ def kill_all_running_shell_processes() -> int:
192
192
  """Kill all currently tracked running shell processes and stop reader threads.
193
193
 
194
194
  Returns the number of processes signaled.
195
+
196
+ Implementation notes:
197
+ - Atomically snapshot and clear the registry to prevent race conditions
198
+ - Deduplicate by PID to ensure each process is killed at most once
199
+ - Let exceptions from _kill_process_group propagate (tests expect this)
195
200
  """
196
201
  global _READER_STOP_EVENT
197
202
 
@@ -199,30 +204,52 @@ def kill_all_running_shell_processes() -> int:
199
204
  if _READER_STOP_EVENT:
200
205
  _READER_STOP_EVENT.set()
201
206
 
202
- procs: list[subprocess.Popen]
207
+ # Atomically take snapshot and clear registry
208
+ # This prevents other threads from seeing/processing the same processes
203
209
  with _RUNNING_PROCESSES_LOCK:
204
- procs = list(_RUNNING_PROCESSES)
205
- count = 0
206
- for p in procs:
210
+ procs_snapshot = list(_RUNNING_PROCESSES)
211
+ _RUNNING_PROCESSES.clear()
212
+
213
+ # Deduplicate by pid to ensure at-most-one kill per process
214
+ seen_pids: set = set()
215
+ killed_count = 0
216
+
217
+ for proc in procs_snapshot:
218
+ if proc is None:
219
+ continue
220
+
221
+ pid = getattr(proc, "pid", None)
222
+ key = pid if pid is not None else id(proc)
223
+
224
+ if key in seen_pids:
225
+ continue
226
+ seen_pids.add(key)
227
+
228
+ # Close pipes first to unblock readline()
207
229
  try:
208
- # Close pipes first to unblock readline()
209
- try:
210
- if p.stdout and not p.stdout.closed:
211
- p.stdout.close()
212
- if p.stderr and not p.stderr.closed:
213
- p.stderr.close()
214
- if p.stdin and not p.stdin.closed:
215
- p.stdin.close()
216
- except (OSError, ValueError):
217
- pass
230
+ if proc.stdout and not proc.stdout.closed:
231
+ proc.stdout.close()
232
+ if proc.stderr and not proc.stderr.closed:
233
+ proc.stderr.close()
234
+ if proc.stdin and not proc.stdin.closed:
235
+ proc.stdin.close()
236
+ except (OSError, ValueError):
237
+ pass
238
+
239
+ # Only attempt to kill processes that are still running
240
+ if proc.poll() is None:
241
+ # Let exceptions bubble up (tests expect this behavior)
242
+ _kill_process_group(proc)
243
+ killed_count += 1
244
+
245
+ # Track user-killed PIDs
246
+ if pid is not None:
247
+ try:
248
+ _USER_KILLED_PROCESSES.add(pid)
249
+ except Exception:
250
+ pass # Non-fatal bookkeeping
218
251
 
219
- if p.poll() is None:
220
- _kill_process_group(p)
221
- count += 1
222
- _USER_KILLED_PROCESSES.add(p.pid)
223
- finally:
224
- _unregister_process(p)
225
- return count
252
+ return killed_count
226
253
 
227
254
 
228
255
  def get_running_shell_process_count() -> int:
@@ -9,9 +9,9 @@
9
9
  "context_length": 200000,
10
10
  "supported_settings": ["temperature", "seed"]
11
11
  },
12
- "synthetic-MiniMax-M2": {
12
+ "synthetic-MiniMax-M2.1": {
13
13
  "type": "custom_openai",
14
- "name": "hf:MiniMaxAI/MiniMax-M2",
14
+ "name": "hf:MiniMaxAI/MiniMax-M2.1",
15
15
  "custom_endpoint": {
16
16
  "url": "https://api.synthetic.new/openai/v1/",
17
17
  "api_key": "$SYN_API_KEY"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: code-puppy
3
- Version: 0.0.322
3
+ Version: 0.0.324
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
@@ -3,16 +3,16 @@ code_puppy/__main__.py,sha256=pDVssJOWP8A83iFkxMLY9YteHYat0EyWDQqMkKHpWp4,203
3
3
  code_puppy/callbacks.py,sha256=hqTV--dNxG5vwWWm3MrEjmb8MZuHFFdmHePl23NXPHk,8621
4
4
  code_puppy/chatgpt_codex_client.py,sha256=Om0ANB_kpHubhCwNzF9ENf8RvKBqs0IYzBLl_SNw0Vk,9833
5
5
  code_puppy/claude_cache_client.py,sha256=hZr_YtXZSQvBoJFtRbbecKucYqJgoMopqUmm0IxFYGY,6071
6
- code_puppy/cli_runner.py,sha256=qAP5cocyUoRVJwvOmlhNsDcoh6h-AXEakDomWxNYlfs,29581
6
+ code_puppy/cli_runner.py,sha256=UIM04pqMb3qkVKG0lKtHQuVSrevsQhEqDC__wAdjqy8,29646
7
7
  code_puppy/config.py,sha256=qqeJrQP7gqADqeYqVzfksP7NYGROLrBQCuYic5PuQfY,52295
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/http_utils.py,sha256=w5mWYIGIWJZJvgvMahXs9BmdidoJvGn4CASDRY88a8o,13414
11
- code_puppy/keymap.py,sha256=Uzvq7HB-6inTjKox-90JWzuijztRdWqhJpfTDZVy5no,3235
11
+ code_puppy/keymap.py,sha256=kbC6S_s57rXcONdE2e1xdj2XNRJ4nHJI32RxbI83DC4,3400
12
12
  code_puppy/main.py,sha256=82r3vZy_XcyEsenLn82BnUusaoyL3Bpm_Th_jKgqecE,273
13
13
  code_puppy/model_factory.py,sha256=H_a5nX462Q-dhX3g3ZY7dmBCIAUOd1aOSZa4HMxF1o4,34191
14
14
  code_puppy/model_utils.py,sha256=NU8W8NW5F7QS_PXHaLeh55Air1koUV7IVYFP7Rz3XpY,3615
15
- code_puppy/models.json,sha256=mTpmJH0UJlmX8M2KVPbxMWb99de3IxKXCWO-B23b6xo,3101
15
+ code_puppy/models.json,sha256=IPABdOrDw2OZJxa0XGBWSWmBRerV6_pIEmKVLRtUbAk,3105
16
16
  code_puppy/models_dev_api.json,sha256=wHjkj-IM_fx1oHki6-GqtOoCrRMR0ScK0f-Iz0UEcy8,548187
17
17
  code_puppy/models_dev_parser.py,sha256=8ndmWrsSyKbXXpRZPXc0w6TfWMuCcgaHiMifmlaBaPc,20611
18
18
  code_puppy/pydantic_patches.py,sha256=YecAEeCOjSIwIBu2O5vEw72atMSL37cXGrbEuukI07o,4582
@@ -39,7 +39,7 @@ code_puppy/agents/agent_qa_expert.py,sha256=5Ikb4U3SZQknUEfwlHZiyZXKqnffnOTQagr_
39
39
  code_puppy/agents/agent_qa_kitten.py,sha256=5PeFFSwCFlTUvP6h5bGntx0xv5NmRwBiw0HnMqY8nLI,9107
40
40
  code_puppy/agents/agent_security_auditor.py,sha256=SpiYNA0XAsIwBj7S2_EQPRslRUmF_-b89pIJyW7DYtY,12022
41
41
  code_puppy/agents/agent_typescript_reviewer.py,sha256=vsnpp98xg6cIoFAEJrRTUM_i4wLEWGm5nJxs6fhHobM,10275
42
- code_puppy/agents/base_agent.py,sha256=N_efw0Fbz-X5ufkKymj2sUnrpYhZwj397Mnita0X33s,80818
42
+ code_puppy/agents/base_agent.py,sha256=TP_iXzoKzqg160EwFVCQmaXfbDF-WX_XH4dyxsypwYc,83200
43
43
  code_puppy/agents/json_agent.py,sha256=lhopDJDoiSGHvD8A6t50hi9ZBoNRKgUywfxd0Po_Dzc,4886
44
44
  code_puppy/agents/prompt_reviewer.py,sha256=JJrJ0m5q0Puxl8vFsyhAbY9ftU9n6c6UxEVdNct1E-Q,5558
45
45
  code_puppy/command_line/__init__.py,sha256=y7WeRemfYppk8KVbCGeAIiTuiOszIURCDjOMZv_YRmU,45
@@ -144,7 +144,7 @@ code_puppy/plugins/shell_safety/register_callbacks.py,sha256=W3v664RR48Fdbbbltf_
144
144
  code_puppy/prompts/codex_system_prompt.md,sha256=hEFTCziroLqZmqNle5kG34A8kvTteOWezCiVrAEKhE0,24400
145
145
  code_puppy/tools/__init__.py,sha256=BVTZ85jLHgDANwOnUSOz3UDlp8VQDq4DoGF23BRlyWw,6032
146
146
  code_puppy/tools/agent_tools.py,sha256=snBI6FlFtR03CbYKXwu53R48c_fRSuDIwcNdVUruLcA,21020
147
- code_puppy/tools/command_runner.py,sha256=WLesijwbXEsnyuIJvWZHbVVyoUAPQcTWJbz31pXPSi0,44325
147
+ code_puppy/tools/command_runner.py,sha256=Sz2AI9CCE3fUcFv-86p1BB5tBkt_UbrPNi57Tfk031E,45281
148
148
  code_puppy/tools/common.py,sha256=IboS6sbwN4a3FzHdfsZJtEFiyDUCszevI6LpH14ydEk,40561
149
149
  code_puppy/tools/file_modifications.py,sha256=vz9n7R0AGDSdLUArZr_55yJLkyI30M8zreAppxIx02M,29380
150
150
  code_puppy/tools/file_operations.py,sha256=CqhpuBnOFOcQCIYXOujskxq2VMLWYJhibYrH0YcPSfA,35692
@@ -159,10 +159,10 @@ code_puppy/tools/browser/browser_scripts.py,sha256=sNb8eLEyzhasy5hV4B9OjM8yIVMLV
159
159
  code_puppy/tools/browser/browser_workflows.py,sha256=nitW42vCf0ieTX1gLabozTugNQ8phtoFzZbiAhw1V90,6491
160
160
  code_puppy/tools/browser/camoufox_manager.py,sha256=RZjGOEftE5sI_tsercUyXFSZI2wpStXf-q0PdYh2G3I,8680
161
161
  code_puppy/tools/browser/vqa_agent.py,sha256=DBn9HKloILqJSTSdNZzH_PYWT0B2h9VwmY6akFQI_uU,2913
162
- code_puppy-0.0.322.data/data/code_puppy/models.json,sha256=mTpmJH0UJlmX8M2KVPbxMWb99de3IxKXCWO-B23b6xo,3101
163
- code_puppy-0.0.322.data/data/code_puppy/models_dev_api.json,sha256=wHjkj-IM_fx1oHki6-GqtOoCrRMR0ScK0f-Iz0UEcy8,548187
164
- code_puppy-0.0.322.dist-info/METADATA,sha256=-tIjZhIMRQz1VNQkZzb8aVEsOavOA8hdGdHHY4adgM8,28030
165
- code_puppy-0.0.322.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
166
- code_puppy-0.0.322.dist-info/entry_points.txt,sha256=Tp4eQC99WY3HOKd3sdvb22vZODRq0XkZVNpXOag_KdI,91
167
- code_puppy-0.0.322.dist-info/licenses/LICENSE,sha256=31u8x0SPgdOq3izJX41kgFazWsM43zPEF9eskzqbJMY,1075
168
- code_puppy-0.0.322.dist-info/RECORD,,
162
+ code_puppy-0.0.324.data/data/code_puppy/models.json,sha256=IPABdOrDw2OZJxa0XGBWSWmBRerV6_pIEmKVLRtUbAk,3105
163
+ code_puppy-0.0.324.data/data/code_puppy/models_dev_api.json,sha256=wHjkj-IM_fx1oHki6-GqtOoCrRMR0ScK0f-Iz0UEcy8,548187
164
+ code_puppy-0.0.324.dist-info/METADATA,sha256=-ExYXf8pscVAS3uSfNB0PPXgk87LyuPVcaW16HLNQEY,28030
165
+ code_puppy-0.0.324.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
166
+ code_puppy-0.0.324.dist-info/entry_points.txt,sha256=Tp4eQC99WY3HOKd3sdvb22vZODRq0XkZVNpXOag_KdI,91
167
+ code_puppy-0.0.324.dist-info/licenses/LICENSE,sha256=31u8x0SPgdOq3izJX41kgFazWsM43zPEF9eskzqbJMY,1075
168
+ code_puppy-0.0.324.dist-info/RECORD,,