patchpal 0.22.3__tar.gz → 0.22.4__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.
Files changed (67) hide show
  1. {patchpal-0.22.3/patchpal.egg-info → patchpal-0.22.4}/PKG-INFO +1 -1
  2. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/__init__.py +1 -1
  3. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/agent/function_calling.py +2 -4
  4. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/context.py +18 -17
  5. {patchpal-0.22.3 → patchpal-0.22.4/patchpal.egg-info}/PKG-INFO +1 -1
  6. {patchpal-0.22.3 → patchpal-0.22.4}/LICENSE +0 -0
  7. {patchpal-0.22.3 → patchpal-0.22.4}/MANIFEST.in +0 -0
  8. {patchpal-0.22.3 → patchpal-0.22.4}/README.md +0 -0
  9. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/agent/__init__.py +0 -0
  10. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/agent/react.py +0 -0
  11. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/cli/__init__.py +0 -0
  12. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/cli/autopilot.py +0 -0
  13. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/cli/interactive.py +0 -0
  14. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/cli/mcp.py +0 -0
  15. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/cli/sandbox.py +0 -0
  16. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/cli/streaming.py +0 -0
  17. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/config.py +0 -0
  18. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/permissions.py +0 -0
  19. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/prompts/react_prompt.md +0 -0
  20. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/prompts/system_prompt.md +0 -0
  21. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/skills.py +0 -0
  22. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/tools/__init__.py +0 -0
  23. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/tools/audit.py +0 -0
  24. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/tools/code_analysis.py +0 -0
  25. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/tools/common.py +0 -0
  26. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/tools/definitions.py +0 -0
  27. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/tools/file_reading.py +0 -0
  28. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/tools/file_writing.py +0 -0
  29. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/tools/find_tool.py +0 -0
  30. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/tools/grep_tool.py +0 -0
  31. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/tools/image_handler.py +0 -0
  32. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/tools/mcp.py +0 -0
  33. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/tools/repo_map.py +0 -0
  34. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/tools/shell_tools.py +0 -0
  35. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/tools/todo_tools.py +0 -0
  36. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/tools/tool_schema.py +0 -0
  37. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/tools/user_interaction.py +0 -0
  38. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal/tools/web_tools.py +0 -0
  39. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal.egg-info/SOURCES.txt +0 -0
  40. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal.egg-info/dependency_links.txt +0 -0
  41. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal.egg-info/entry_points.txt +0 -0
  42. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal.egg-info/requires.txt +0 -0
  43. {patchpal-0.22.3 → patchpal-0.22.4}/patchpal.egg-info/top_level.txt +0 -0
  44. {patchpal-0.22.3 → patchpal-0.22.4}/pyproject.toml +0 -0
  45. {patchpal-0.22.3 → patchpal-0.22.4}/setup.cfg +0 -0
  46. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_agent.py +0 -0
  47. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_cli.py +0 -0
  48. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_config_dynamic.py +0 -0
  49. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_context.py +0 -0
  50. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_custom_tools.py +0 -0
  51. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_enabled_tools.py +0 -0
  52. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_find_tool.py +0 -0
  53. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_guardrails.py +0 -0
  54. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_image_blocking.py +0 -0
  55. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_maximum_security.py +0 -0
  56. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_mcp_config.py +0 -0
  57. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_memory.py +0 -0
  58. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_operational_safety.py +0 -0
  59. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_optional_tools.py +0 -0
  60. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_permissions.py +0 -0
  61. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_react.py +0 -0
  62. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_reasoning_content.py +0 -0
  63. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_repo_map.py +0 -0
  64. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_simplified_prompt.py +0 -0
  65. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_skills.py +0 -0
  66. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_streaming.py +0 -0
  67. {patchpal-0.22.3 → patchpal-0.22.4}/tests/test_tools.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: patchpal
3
- Version: 0.22.3
3
+ Version: 0.22.4
4
4
  Summary: An agentic coding and automation assistant, supporting both local and cloud LLMs
5
5
  Author: PatchPal Contributors
6
6
  License-Expression: Apache-2.0
@@ -1,6 +1,6 @@
1
1
  """PatchPal - An open-source Claude Code clone implemented purely in Python."""
2
2
 
3
- __version__ = "0.22.3"
3
+ __version__ = "0.22.4"
4
4
 
5
5
  from patchpal.agent import create_agent, create_react_agent
6
6
  from patchpal.cli.autopilot import autopilot_loop
@@ -957,10 +957,8 @@ It's currently empty (just the template). The file is automatically loaded at se
957
957
 
958
958
  # Check for compaction BEFORE starting work
959
959
  # This ensures we never compact mid-execution and lose tool results
960
- # Use last_prompt_tokens from previous API call for accurate check (includes cache operations)
961
- if self.enable_auto_compact and self.context_manager.needs_compaction(
962
- self.messages, actual_prompt_tokens=self.last_prompt_tokens
963
- ):
960
+ # Always estimates current messages to avoid staleness issues (no actual_prompt_tokens)
961
+ if self.enable_auto_compact and self.context_manager.needs_compaction(self.messages):
964
962
  self._perform_auto_compaction()
965
963
 
966
964
  # Agent loop with interrupt handling
@@ -321,30 +321,31 @@ Be comprehensive but concise. The goal is to continue work seamlessly without lo
321
321
  ) -> bool:
322
322
  """Check if context window needs compaction.
323
323
 
324
- Supports both reactive (preferred) and proactive (fallback) approaches:
325
- - Reactive: Use actual_prompt_tokens from latest API response
326
- - Proactive: Estimate tokens if actual_prompt_tokens not available
327
-
328
- The reactive approach is preferred as it uses actual token counts from the LLM,
329
- avoiding the need for tiktoken or other estimation methods.
324
+ ALWAYS estimates current messages to avoid staleness issues when predicting
325
+ whether the NEXT API call will overflow. Using actual_prompt_tokens from a
326
+ previous call can cause false negatives when large messages are added between
327
+ the last API call and the compaction check.
328
+
329
+ Example of staleness bug (fixed):
330
+ - Previous API call: 120K tokens (60% usage)
331
+ - User pastes huge changelog: +90K tokens
332
+ - Total: 210K tokens (exceeds 200K limit)
333
+ - Bug: If we used actual_prompt_tokens=120K, we'd think we're at 60%
334
+ - Fix: Always re-estimate to see the 210K total
335
+
336
+ The actual_prompt_tokens parameter is kept for API compatibility but ignored
337
+ for compaction decisions. Use get_usage_stats() for display purposes where
338
+ actual tokens are appropriate (staleness OK for showing recent stats).
330
339
 
331
340
  Args:
332
341
  messages: Current message history
333
- actual_prompt_tokens: Optional actual prompt token count from latest API response
342
+ actual_prompt_tokens: IGNORED - kept for API compatibility only
334
343
 
335
344
  Returns:
336
345
  True if compaction is needed
337
346
  """
338
- # Reactive approach (preferred): use actual token counts from API response
339
- if actual_prompt_tokens is not None:
340
- # Add output reserve to account for response tokens
341
- total_tokens = actual_prompt_tokens + self.output_reserve
342
- usage_ratio = total_tokens / self.context_limit
343
- return usage_ratio >= self.COMPACT_THRESHOLD
344
-
345
- # Proactive approach (fallback): estimate tokens when API data not available
346
- # This uses character-based estimation (3 chars per token) which works
347
- # reliably without requiring tiktoken or network access
347
+ # ALWAYS estimate current messages - never use stale actual_prompt_tokens
348
+ # This ensures we detect large message additions that happen between API calls
348
349
  # Note: Dynamic date/time message adds ~30 tokens on each LLM call
349
350
  system_tokens = self.estimator.estimate_tokens(self.system_prompt)
350
351
  datetime_tokens = 30 # Approximate size of dynamic date/time message
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: patchpal
3
- Version: 0.22.3
3
+ Version: 0.22.4
4
4
  Summary: An agentic coding and automation assistant, supporting both local and cloud LLMs
5
5
  Author: PatchPal Contributors
6
6
  License-Expression: Apache-2.0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes