alpiecode 10.10.2__tar.gz → 10.10.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 (147) hide show
  1. {alpiecode-10.10.2 → alpiecode-10.10.4}/PKG-INFO +1 -1
  2. {alpiecode-10.10.2 → alpiecode-10.10.4}/pyproject.toml +1 -1
  3. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/alpiecode.egg-info/PKG-INFO +1 -1
  4. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/alpiecode.egg-info/SOURCES.txt +2 -0
  5. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/__init__.py +1 -1
  6. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/backends/local_backend.py +78 -22
  7. alpiecode-10.10.4/src/codeagent/convergence.py +32 -0
  8. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/executor.py +20 -5
  9. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/local_model.py +48 -29
  10. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/media.py +9 -1
  11. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/orchestrator.py +168 -24
  12. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/prompt.py +7 -0
  13. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/slash.py +3 -0
  14. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/system1.py +10 -2
  15. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/tools.py +18 -2
  16. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_deloop_and_sessions.py +74 -0
  17. alpiecode-10.10.4/test/test_report_convergence.py +158 -0
  18. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_truncation_resilience.py +60 -0
  19. {alpiecode-10.10.2 → alpiecode-10.10.4}/README.md +0 -0
  20. {alpiecode-10.10.2 → alpiecode-10.10.4}/setup.cfg +0 -0
  21. {alpiecode-10.10.2 → alpiecode-10.10.4}/setup.py +0 -0
  22. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/alpiecode/__init__.py +0 -0
  23. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/alpiecode.egg-info/dependency_links.txt +0 -0
  24. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/alpiecode.egg-info/entry_points.txt +0 -0
  25. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/alpiecode.egg-info/requires.txt +0 -0
  26. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/alpiecode.egg-info/top_level.txt +0 -0
  27. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/__main__.py +0 -0
  28. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/agent.py +0 -0
  29. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/assessment.py +0 -0
  30. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/backends/__init__.py +0 -0
  31. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/backends/base.py +0 -0
  32. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/backends/openai_backend.py +0 -0
  33. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/blueprints.py +0 -0
  34. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/cache.py +0 -0
  35. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/chat_tags.py +0 -0
  36. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/cli.py +0 -0
  37. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/client.py +0 -0
  38. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/compaction.py +0 -0
  39. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/config.py +0 -0
  40. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/context.py +0 -0
  41. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/diff_preview.py +0 -0
  42. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/discovery.py +0 -0
  43. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/doctor.py +0 -0
  44. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/dream_rsi.py +0 -0
  45. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/git_ops.py +0 -0
  46. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/github.py +0 -0
  47. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/guardian.py +0 -0
  48. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/guardrails.py +0 -0
  49. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/ipython_ext.py +0 -0
  50. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/memory.py +0 -0
  51. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/metrics.py +0 -0
  52. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/onboarding.py +0 -0
  53. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/paths.py +0 -0
  54. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/progress.py +0 -0
  55. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/project_template.py +0 -0
  56. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/rephraser.py +0 -0
  57. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/server.py +0 -0
  58. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/session.py +0 -0
  59. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/accessibility-audit/SKILL.md +0 -0
  60. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/accessibility-testing/SKILL.md +0 -0
  61. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/accessibility-ui-components/SKILL.md +0 -0
  62. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/agentic-workflows/SKILL.md +0 -0
  63. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/api-design/SKILL.md +0 -0
  64. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/architecture-design/SKILL.md +0 -0
  65. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/backend-engineering/SKILL.md +0 -0
  66. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/browser-automation/SKILL.md +0 -0
  67. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/cli-development/SKILL.md +0 -0
  68. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/cloud-infrastructure/SKILL.md +0 -0
  69. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/code-generation/SKILL.md +0 -0
  70. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/code-review/SKILL.md +0 -0
  71. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/codebase-onboarding/SKILL.md +0 -0
  72. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/cost-optimization/SKILL.md +0 -0
  73. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/data-analysis/SKILL.md +0 -0
  74. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/data-engineering/SKILL.md +0 -0
  75. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/database-engineering/SKILL.md +0 -0
  76. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/dependency-management/SKILL.md +0 -0
  77. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/dependency-security/SKILL.md +0 -0
  78. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/dependency-upgrades/SKILL.md +0 -0
  79. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/devops-ci-cd/SKILL.md +0 -0
  80. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/docker-containers/SKILL.md +0 -0
  81. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/documentation/SKILL.md +0 -0
  82. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/documentation-site/SKILL.md +0 -0
  83. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/e2e-testing/SKILL.md +0 -0
  84. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/error-handling-resilience/SKILL.md +0 -0
  85. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/feature-development/SKILL.md +0 -0
  86. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/frontend-engineering/SKILL.md +0 -0
  87. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/git-workflow/SKILL.md +0 -0
  88. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/incident-response/SKILL.md +0 -0
  89. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/legacy-code-modernization/SKILL.md +0 -0
  90. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/llm-application-engineering/SKILL.md +0 -0
  91. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/localization-i18n/SKILL.md +0 -0
  92. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/mcp-server-development/SKILL.md +0 -0
  93. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/migration-engineering/SKILL.md +0 -0
  94. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/mobile-development/SKILL.md +0 -0
  95. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/model-evaluation/SKILL.md +0 -0
  96. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/nodejs-services/SKILL.md +0 -0
  97. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/observability/SKILL.md +0 -0
  98. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/performance-optimization/SKILL.md +0 -0
  99. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/privacy-data-protection/SKILL.md +0 -0
  100. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/prompt-engineering/SKILL.md +0 -0
  101. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/python-engineering/SKILL.md +0 -0
  102. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/rag-retrieval/SKILL.md +0 -0
  103. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/react-engineering/SKILL.md +0 -0
  104. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/release-management/SKILL.md +0 -0
  105. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/requirements-analysis/SKILL.md +0 -0
  106. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/responsive-design/SKILL.md +0 -0
  107. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/safe-refactoring/SKILL.md +0 -0
  108. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/secure-coding/SKILL.md +0 -0
  109. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/systematic-debugging/SKILL.md +0 -0
  110. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/technical-planning/SKILL.md +0 -0
  111. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/technical-research/SKILL.md +0 -0
  112. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/technical-writing/SKILL.md +0 -0
  113. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/test-engineering/SKILL.md +0 -0
  114. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/tool-integration/SKILL.md +0 -0
  115. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/typescript-engineering/SKILL.md +0 -0
  116. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/visual-regression-testing/SKILL.md +0 -0
  117. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/web-performance/SKILL.md +0 -0
  118. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/web-security-testing/SKILL.md +0 -0
  119. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills/workflow-automation/SKILL.md +0 -0
  120. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/skills.py +0 -0
  121. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/subagent.py +0 -0
  122. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/updater.py +0 -0
  123. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/verifier.py +0 -0
  124. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/vscode_installer.py +0 -0
  125. {alpiecode-10.10.2 → alpiecode-10.10.4}/src/codeagent/walkthrough.py +0 -0
  126. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_adaptive_resilience.py +0 -0
  127. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_chat_tags_and_offline_multimodal.py +0 -0
  128. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_cli_ui.py +0 -0
  129. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_context_and_trajectory.py +0 -0
  130. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_dream_rsi.py +0 -0
  131. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_frontier_architecture.py +0 -0
  132. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_gpu_detection.py +0 -0
  133. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_lifecycle_and_portfolio.py +0 -0
  134. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_local_model_download.py +0 -0
  135. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_memory_optimization.py +0 -0
  136. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_non_thinking_and_local_stream.py +0 -0
  137. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_onboarding.py +0 -0
  138. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_project_templates.py +0 -0
  139. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_security_config.py +0 -0
  140. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_skills_engine.py +0 -0
  141. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_slash_and_diff.py +0 -0
  142. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_subagents.py +0 -0
  143. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_task_assessment.py +0 -0
  144. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_token_economy_and_256k.py +0 -0
  145. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_verifier.py +0 -0
  146. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_walkthrough.py +0 -0
  147. {alpiecode-10.10.2 → alpiecode-10.10.4}/test/test_web_resilience_and_guardrails.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: alpiecode
3
- Version: 10.10.2
3
+ Version: 10.10.4
4
4
  Summary: AlpieCode
5
5
  Requires-Python: >=3.9
6
6
  Requires-Dist: huggingface_hub>=0.20.0
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "alpiecode"
7
- version = "10.10.2"
7
+ version = "10.10.4"
8
8
  description = "AlpieCode"
9
9
  requires-python = ">=3.9"
10
10
  dependencies = [
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: alpiecode
3
- Version: 10.10.2
3
+ Version: 10.10.4
4
4
  Summary: AlpieCode
5
5
  Requires-Python: >=3.9
6
6
  Requires-Dist: huggingface_hub>=0.20.0
@@ -20,6 +20,7 @@ src/codeagent/client.py
20
20
  src/codeagent/compaction.py
21
21
  src/codeagent/config.py
22
22
  src/codeagent/context.py
23
+ src/codeagent/convergence.py
23
24
  src/codeagent/diff_preview.py
24
25
  src/codeagent/discovery.py
25
26
  src/codeagent/doctor.py
@@ -131,6 +132,7 @@ test/test_memory_optimization.py
131
132
  test/test_non_thinking_and_local_stream.py
132
133
  test/test_onboarding.py
133
134
  test/test_project_templates.py
135
+ test/test_report_convergence.py
134
136
  test/test_security_config.py
135
137
  test/test_skills_engine.py
136
138
  test/test_slash_and_diff.py
@@ -17,7 +17,7 @@ Supports:
17
17
  from pathlib import Path
18
18
  from typing import Optional, Any, Dict
19
19
 
20
- __version__ = "10.10.2"
20
+ __version__ = "10.10.4"
21
21
 
22
22
  def run(task: str, workdir: str = ".", reasoning_level: str = "thinking", **kwargs):
23
23
  """Run an autonomous coding task programmatically."""
@@ -94,12 +94,33 @@ class LocalBackend:
94
94
 
95
95
  clean = {"role": role}
96
96
 
97
- # Ensure content is always a string
97
+ # Check if vision projector is present in cache
98
+ from ..local_model import get_model_cache_dir
99
+ has_vision = bool(list(Path(get_model_cache_dir()).glob("*mmproj*.gguf")))
100
+
101
+ # Ensure content is always valid string or multimodal list
98
102
  content = msg.get("content")
99
103
  if content is None:
100
104
  content = ""
105
+ elif role == "user" and isinstance(content, list) and has_vision and any(isinstance(p, dict) and p.get("type") == "image_url" for p in content):
106
+ # Vision projector is active — preserve native multimodal image blocks for Qwen25VLChatHandler / llama-cpp
107
+ multimodal_content = []
108
+ for part in content:
109
+ if isinstance(part, dict):
110
+ if part.get("type") == "text":
111
+ t = str(part.get("text", ""))
112
+ if len(t) > 12000:
113
+ t = t[:11000] + f"\n... [content truncated: {len(t)} chars total for local context headroom]"
114
+ multimodal_content.append({"type": "text", "text": t})
115
+ elif part.get("type") == "image_url":
116
+ multimodal_content.append(part)
117
+ elif isinstance(part, str):
118
+ multimodal_content.append({"type": "text", "text": part})
119
+ clean["content"] = multimodal_content
120
+ sanitized.append(clean)
121
+ continue
101
122
  elif isinstance(content, list):
102
- # Multimodal content (image_url + text blocks) — extract text parts & run offline visual analysis
123
+ # Multimodal content on pure text model — extract text parts & run offline visual analysis
103
124
  text_parts = []
104
125
  img_idx = 1
105
126
  for part in content:
@@ -184,22 +205,40 @@ class LocalBackend:
184
205
  if not m.get("content") and m.get("role") != "system":
185
206
  continue
186
207
  if coalesced and coalesced[-1]["role"] == m["role"] and m["role"] != "system":
187
- prev_c = coalesced[-1]["content"].rstrip()
188
- new_c = m["content"].lstrip()
189
- if new_c:
190
- coalesced[-1]["content"] = f"{prev_c}\n\n{new_c}".strip()
208
+ prev_c = coalesced[-1]["content"]
209
+ new_c = m["content"]
210
+ if isinstance(prev_c, str) and isinstance(new_c, str):
211
+ coalesced[-1]["content"] = f"{prev_c.rstrip()}\n\n{new_c.lstrip()}".strip()
212
+ elif isinstance(prev_c, list) and isinstance(new_c, str):
213
+ coalesced[-1]["content"] = prev_c + [{"type": "text", "text": new_c}]
214
+ elif isinstance(prev_c, str) and isinstance(new_c, list):
215
+ coalesced[-1]["content"] = [{"type": "text", "text": prev_c}] + new_c
216
+ elif isinstance(prev_c, list) and isinstance(new_c, list):
217
+ coalesced[-1]["content"] = prev_c + new_c
191
218
  else:
192
219
  coalesced.append(m)
193
220
 
194
221
  if coalesced and coalesced[-1].get("role") == "user":
195
- c_text = coalesced[-1].get("content", "")
196
- if any(k in c_text for k in ("[Tool Result", "[Workspace State", "Files created so far", "[CRITICAL STYLING DIRECTIVE")):
197
- prompt_hint = (
198
- "\n\n[Next Action: Output your next <tool_call> (e.g. write_file, edit_file, or bash) immediately. "
199
- "Do NOT output conversational text. When all files are created and verified, call complete_task or output: DONE: <summary>.]"
222
+ c_val = coalesced[-1].get("content")
223
+ prompt_hint = (
224
+ "\n\n[Next Action: Output your next <tool_call> (e.g. write_file, edit_file, or bash) immediately. "
225
+ "Do NOT output conversational text. When all files are created and verified, call complete_task or output: DONE: <summary>.]"
226
+ )
227
+ if isinstance(c_val, str):
228
+ if any(k in c_val for k in ("[Tool Result", "[Workspace State", "Files created so far", "[CRITICAL STYLING DIRECTIVE")):
229
+ if "[Next Action:" not in c_val:
230
+ coalesced[-1]["content"] += prompt_hint
231
+ elif isinstance(c_val, list):
232
+ has_directive = any(
233
+ isinstance(p, dict) and any(k in str(p.get("text", "")) for k in ("[Tool Result", "[Workspace State", "Files created so far", "[CRITICAL STYLING DIRECTIVE"))
234
+ for p in c_val
200
235
  )
201
- if "[Next Action:" not in c_text:
202
- coalesced[-1]["content"] += prompt_hint
236
+ if has_directive:
237
+ for p in reversed(c_val):
238
+ if isinstance(p, dict) and p.get("type") == "text":
239
+ if "[Next Action:" not in p.get("text", ""):
240
+ p["text"] = p.get("text", "") + prompt_hint
241
+ break
203
242
 
204
243
  return coalesced
205
244
 
@@ -217,12 +256,29 @@ class LocalBackend:
217
256
  return messages, min(max_tokens, max(256, max_context - 64))
218
257
 
219
258
  def _estimate_msg_tokens(m: dict) -> int:
220
- t_chars = len(str(m.get("content") or ""))
259
+ content = m.get("content")
260
+ tokens = 0
261
+ if isinstance(content, str):
262
+ if "data:image/" in content:
263
+ import re as _re
264
+ clean_t = _re.sub(r"data:image/[^;]+;base64,[A-Za-z0-9+/=]+", "", content)
265
+ tokens += max(1, len(clean_t) // 4) + 450
266
+ else:
267
+ tokens += max(1, len(content) // 4)
268
+ elif isinstance(content, list):
269
+ for part in content:
270
+ if isinstance(part, dict):
271
+ if part.get("type") == "text":
272
+ tokens += max(1, len(str(part.get("text", ""))) // 4)
273
+ elif part.get("type") == "image_url":
274
+ tokens += 450
275
+ elif isinstance(part, str):
276
+ tokens += max(1, len(part) // 4)
221
277
  for tc in m.get("tool_calls") or []:
222
278
  if isinstance(tc, dict):
223
279
  fn = tc.get("function", {})
224
- t_chars += len(str(fn.get("arguments", ""))) + len(str(fn.get("name", "")))
225
- return max(1, t_chars // 4) + 6
280
+ tokens += max(1, (len(str(fn.get("arguments", ""))) + len(str(fn.get("name", "")))) // 4)
281
+ return max(1, tokens) + 6
226
282
 
227
283
  # Allocate generation headroom
228
284
  max_gen_budget = max(256, min(max_tokens, max_context // 2))
@@ -336,8 +392,8 @@ class LocalBackend:
336
392
  import time
337
393
  start_time = time.time()
338
394
  temp = temperature if temperature is not None else getattr(self._cfg, "temperature", 0.2)
339
- raw_m = max_tokens if max_tokens is not None else getattr(self._cfg, "max_tokens", 2048)
340
- m_tokens = min(raw_m, 4096)
395
+ raw_m = max_tokens if max_tokens is not None else getattr(self._cfg, "max_tokens", 4096)
396
+ m_tokens = min(raw_m, 8192)
341
397
 
342
398
  model = self._ensure_model()
343
399
  sanitized_msgs = self._sanitize_messages_for_gguf(messages)
@@ -657,8 +713,8 @@ class LocalBackend:
657
713
  sanitized[-1]["content"] = u_text + "\n\n[Direct Mode: Output code and tool calls directly without <think> tags. Do not deliberate.]"
658
714
 
659
715
  n_ctx = getattr(self._cfg, "n_ctx", 8192) or 8192
660
- raw_m = max_tokens if max_tokens is not None else getattr(self._cfg, "max_tokens", 2048)
661
- m_tokens = min(raw_m, 4096)
716
+ raw_m = max_tokens if max_tokens is not None else getattr(self._cfg, "max_tokens", 4096)
717
+ m_tokens = min(raw_m, 8192)
662
718
  sanitized, safe_max_tokens = self._enforce_context_headroom(sanitized, max_context=n_ctx, max_tokens=m_tokens)
663
719
  payload = {
664
720
  "model": "local",
@@ -1120,8 +1176,8 @@ class iOSBackend(BasePlatformBackend):
1120
1176
  bridge_url = self._get_bridge_url()
1121
1177
  sanitized = self._sanitize_messages_for_gguf(messages)
1122
1178
  n_ctx = getattr(self._cfg, "n_ctx", 4096) or 4096
1123
- raw_m = max_tokens if max_tokens is not None else getattr(self._cfg, "max_tokens", 2048)
1124
- m_tokens = min(raw_m, 4096)
1179
+ raw_m = max_tokens if max_tokens is not None else getattr(self._cfg, "max_tokens", 4096)
1180
+ m_tokens = min(raw_m, 8192)
1125
1181
  sanitized, safe_max_tokens = self._enforce_context_headroom(sanitized, max_context=n_ctx, max_tokens=m_tokens)
1126
1182
  payload = {
1127
1183
  "model": "local",
@@ -0,0 +1,32 @@
1
+ """Task-local limits for retries that do not change the observed outcome."""
2
+
3
+ import hashlib
4
+ import json
5
+ from typing import Any, Dict, Optional
6
+
7
+
8
+ class ConvergenceGuard:
9
+ def __init__(self) -> None:
10
+ self._failures: Dict[str, tuple] = {}
11
+ self._writes: Dict[str, str] = {}
12
+
13
+ def observe(self, name: str, args: Dict[str, Any], output: str,
14
+ failed: bool) -> Optional[str]:
15
+ target = str(args.get("path") or args.get("file") or args.get("filepath")
16
+ or args.get("filename") or args.get("command") or "")
17
+ key = json.dumps([name, target])
18
+ if failed:
19
+ # Ignore changing generated content: the same rejection is no progress.
20
+ previous, count = self._failures.get(key, (None, 0))
21
+ count = count + 1 if previous == output else 1
22
+ self._failures[key] = (output, count)
23
+ if count >= 2:
24
+ return f"Stopped after the same {name} error twice for {target or 'this action'}: {output[:500]}"
25
+ else:
26
+ self._failures.pop(key, None)
27
+ if name == "write_file" and not args.get("append"):
28
+ signature = hashlib.sha256(json.dumps(args, sort_keys=True).encode()).hexdigest()
29
+ if self._writes.get(key) == signature:
30
+ return f"Repeated identical write_file for {target}; preserve the existing file and summarize the result."
31
+ self._writes[key] = signature
32
+ return None
@@ -263,6 +263,21 @@ def suggest_similar_file(workdir: Path, target_path: str) -> Optional[str]:
263
263
  return None
264
264
 
265
265
 
266
+ def _normalize_tool_arguments(raw: Any) -> dict:
267
+ """Safely normalize tool arguments into a dictionary, handling strings or dicts."""
268
+ if isinstance(raw, dict):
269
+ return dict(raw)
270
+ if isinstance(raw, str):
271
+ try:
272
+ import json as _json
273
+ d = _json.loads(raw)
274
+ if isinstance(d, dict):
275
+ return d
276
+ except Exception:
277
+ pass
278
+ return {}
279
+
280
+
266
281
  class ToolExecutor:
267
282
  """Executes tool calls for a workspace."""
268
283
 
@@ -330,7 +345,7 @@ class ToolExecutor:
330
345
  if on_tool_start:
331
346
  on_tool_start(tc.name, tc.arguments)
332
347
  t0 = time.monotonic()
333
- safe_args = tc.arguments if isinstance(tc.arguments, dict) else {}
348
+ safe_args = _normalize_tool_arguments(tc.arguments)
334
349
  fn = self.dispatch.get(tc.name)
335
350
  if fn:
336
351
  future = pool.submit(fn, safe_args)
@@ -361,7 +376,7 @@ class ToolExecutor:
361
376
  if on_tool_start:
362
377
  on_tool_start(tc.name, tc.arguments)
363
378
  t0 = time.monotonic()
364
- safe_args = tc.arguments if isinstance(tc.arguments, dict) else {}
379
+ safe_args = _normalize_tool_arguments(tc.arguments)
365
380
  fn = self.dispatch.get(tc.name)
366
381
  res_str = str(fn(safe_args)) if fn else f"error: Unknown tool '{tc.name}'"
367
382
  elapsed = (time.monotonic() - t0) * 1000
@@ -374,7 +389,7 @@ class ToolExecutor:
374
389
  # Stage 2: Mutating tools (parallel write_file if distinct paths, otherwise sequential)
375
390
  all_writes = all(tc.name == "write_file" for tc in mut_calls)
376
391
  paths = [
377
- tc.arguments.get("path") if isinstance(tc.arguments, dict) else None
392
+ _normalize_tool_arguments(tc.arguments).get("path")
378
393
  for tc in mut_calls
379
394
  ]
380
395
  can_parallel_write = (
@@ -391,7 +406,7 @@ class ToolExecutor:
391
406
  if on_tool_start:
392
407
  on_tool_start(tc.name, tc.arguments)
393
408
  t0 = time.monotonic()
394
- safe_args = tc.arguments if isinstance(tc.arguments, dict) else {}
409
+ safe_args = _normalize_tool_arguments(tc.arguments)
395
410
  fn = self.dispatch.get(tc.name)
396
411
  if fn:
397
412
  future = pool.submit(fn, safe_args)
@@ -423,7 +438,7 @@ class ToolExecutor:
423
438
  if on_tool_start:
424
439
  on_tool_start(tc.name, tc.arguments)
425
440
  t0 = time.monotonic()
426
- safe_args = tc.arguments if isinstance(tc.arguments, dict) else {}
441
+ safe_args = _normalize_tool_arguments(tc.arguments)
427
442
  fn = self.dispatch.get(tc.name)
428
443
  if fn:
429
444
  try:
@@ -716,6 +716,22 @@ class LocalModel:
716
716
  content = m.get("content", "")
717
717
  if isinstance(content, str) and directive_tag not in content:
718
718
  msgs.append({**m, "content": f"{content}\n\n{directive_tag}"})
719
+ elif isinstance(content, list):
720
+ new_content = []
721
+ appended = False
722
+ for p in content:
723
+ if isinstance(p, dict) and p.get("type") == "text" and not appended:
724
+ t = p.get("text", "")
725
+ if directive_tag not in t:
726
+ new_content.append({"type": "text", "text": f"{t}\n\n{directive_tag}"})
727
+ appended = True
728
+ else:
729
+ new_content.append(p)
730
+ else:
731
+ new_content.append(p)
732
+ if not appended:
733
+ new_content.append({"type": "text", "text": directive_tag})
734
+ msgs.append({**m, "content": new_content})
719
735
  else:
720
736
  msgs.append(m)
721
737
  else:
@@ -726,46 +742,49 @@ class LocalModel:
726
742
  # Context headroom safety guard: dynamically clamp max_tokens so prompt + max_tokens <= n_ctx
727
743
  n_ctx_limit = getattr(self, "n_ctx", 32768)
728
744
  try:
729
- total_chars = 0
730
- for m in msgs:
731
- total_chars += len(str(m.get("content") or ""))
732
- for tc in m.get("tool_calls") or []:
733
- if isinstance(tc, dict):
734
- fn = tc.get("function", {})
735
- total_chars += len(str(fn.get("arguments", ""))) + len(str(fn.get("name", "")))
736
- if tools:
737
- import json
738
- total_chars += len(json.dumps(tools))
739
- # Accurate token estimate: 1 token ≈ 3.2 chars + template overhead
740
- est_prompt_tokens = int(total_chars / 3.2) + 120
745
+ def _calc_est_tokens(messages_list: List[Dict[str, Any]]) -> int:
746
+ toks = 0
747
+ for m in messages_list:
748
+ c = m.get("content")
749
+ if isinstance(c, str):
750
+ if "data:image/" in c:
751
+ import re as _re
752
+ c_clean = _re.sub(r"data:image/[^;]+;base64,[A-Za-z0-9+/=]+", "", c)
753
+ toks += max(1, int(len(c_clean) / 3.2)) + 450
754
+ else:
755
+ toks += max(1, int(len(c) / 3.2))
756
+ elif isinstance(c, list):
757
+ for part in c:
758
+ if isinstance(part, dict):
759
+ if part.get("type") == "text":
760
+ toks += max(1, int(len(str(part.get("text", ""))) / 3.2))
761
+ elif part.get("type") == "image_url":
762
+ toks += 450 # Visual patch tokens for vision encoder
763
+ elif isinstance(part, str):
764
+ toks += max(1, int(len(part) / 3.2))
765
+ for tc in m.get("tool_calls") or []:
766
+ if isinstance(tc, dict):
767
+ fn = tc.get("function", {})
768
+ toks += max(1, int((len(str(fn.get("arguments", ""))) + len(str(fn.get("name", "")))) / 3.2))
769
+ return toks
770
+
771
+ tools_tokens = int(len(json.dumps(tools)) / 3.2) if tools else 0
772
+ est_prompt_tokens = _calc_est_tokens(msgs) + tools_tokens + 120
741
773
  available_tokens = n_ctx_limit - est_prompt_tokens - 32
742
774
  if available_tokens < 1024:
743
775
  from .compaction import compact_text_tool_calls, compact_tool_calls
744
776
  for m in msgs:
745
777
  if m.get("tool_calls"):
746
778
  m["tool_calls"] = compact_tool_calls(m["tool_calls"])
747
- if m.get("content") and "<tool_call>" in str(m["content"]):
748
- m["content"] = compact_text_tool_calls(str(m["content"]))
749
- total_chars = sum(len(str(m.get("content") or "")) for m in msgs)
750
- for m in msgs:
751
- for tc in m.get("tool_calls") or []:
752
- if isinstance(tc, dict):
753
- fn = tc.get("function", {})
754
- total_chars += len(str(fn.get("arguments", ""))) + len(str(fn.get("name", "")))
755
- if tools:
756
- import json
757
- total_chars += len(json.dumps(tools))
758
- est_prompt_tokens = int(total_chars / 3.2) + 120
779
+ if m.get("content") and isinstance(m["content"], str) and "<tool_call>" in m["content"]:
780
+ m["content"] = compact_text_tool_calls(m["content"])
781
+ est_prompt_tokens = _calc_est_tokens(msgs) + tools_tokens + 120
759
782
  available_tokens = n_ctx_limit - est_prompt_tokens - 32
760
783
 
761
784
  if available_tokens < 1024 and len(msgs) > 2:
762
785
  from .compaction import compact_messages
763
786
  msgs = compact_messages(msgs, keep_recent=2)
764
- total_chars = sum(len(str(m.get("content") or "")) for m in msgs)
765
- if tools:
766
- import json
767
- total_chars += len(json.dumps(tools))
768
- est_prompt_tokens = int(total_chars / 3.2) + 120
787
+ est_prompt_tokens = _calc_est_tokens(msgs) + tools_tokens + 120
769
788
  available_tokens = n_ctx_limit - est_prompt_tokens - 32
770
789
 
771
790
  safe_cap = max(256, available_tokens)
@@ -466,7 +466,12 @@ def build_media_content(
466
466
  try:
467
467
  frames = extract_frames(str(vid_file), max_frames=frames_per_vid)
468
468
  if frames:
469
- header = f"--- Video {idx}/{num_vids}: {vid_file.name} ({len(frames)} keyframes) ---"
469
+ header = (
470
+ f"--- Video {idx}/{num_vids}: {vid_file.name} ({len(frames)} keyframes) ---\n"
471
+ "Coverage: sampled still frames only; no audio or transcript was extracted. "
472
+ "Do not claim to have watched the entire video or heard the review. "
473
+ "Separate visible observations from unknown spoken claims."
474
+ )
470
475
  content.append({"type": "text", "text": header})
471
476
  for i, (mime, raw_bytes) in enumerate(frames):
472
477
  b64 = base64.b64encode(raw_bytes).decode("utf-8")
@@ -490,6 +495,9 @@ def build_media_content(
490
495
  console.print(f" ✅ Downloaded: {Path(downloaded).name}", style="green")
491
496
  console.print(f"🎬 Extracting frames...", style="cyan")
492
497
  frames = extract_frames(downloaded)
498
+ content.append({"type": "text", "text":
499
+ "Video coverage: sampled still frames only; no audio or transcript was extracted. "
500
+ "Do not claim full-video or spoken-review analysis."})
493
501
  for mime, raw_bytes in frames:
494
502
  b64 = base64.b64encode(raw_bytes).decode("utf-8")
495
503
  content.append({