alpiecode 10.10.1__tar.gz → 10.10.3__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 (145) hide show
  1. {alpiecode-10.10.1 → alpiecode-10.10.3}/PKG-INFO +1 -1
  2. {alpiecode-10.10.1 → alpiecode-10.10.3}/pyproject.toml +1 -1
  3. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/alpiecode.egg-info/PKG-INFO +1 -1
  4. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/__init__.py +1 -1
  5. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/backends/local_backend.py +78 -22
  6. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/cli.py +2 -2
  7. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/config.py +1 -1
  8. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/executor.py +20 -5
  9. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/local_model.py +48 -29
  10. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/orchestrator.py +4 -9
  11. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/server.py +1 -1
  12. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/slash.py +4 -1
  13. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_truncation_resilience.py +60 -0
  14. {alpiecode-10.10.1 → alpiecode-10.10.3}/README.md +0 -0
  15. {alpiecode-10.10.1 → alpiecode-10.10.3}/setup.cfg +0 -0
  16. {alpiecode-10.10.1 → alpiecode-10.10.3}/setup.py +0 -0
  17. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/alpiecode/__init__.py +0 -0
  18. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/alpiecode.egg-info/SOURCES.txt +0 -0
  19. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/alpiecode.egg-info/dependency_links.txt +0 -0
  20. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/alpiecode.egg-info/entry_points.txt +0 -0
  21. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/alpiecode.egg-info/requires.txt +0 -0
  22. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/alpiecode.egg-info/top_level.txt +0 -0
  23. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/__main__.py +0 -0
  24. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/agent.py +0 -0
  25. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/assessment.py +0 -0
  26. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/backends/__init__.py +0 -0
  27. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/backends/base.py +0 -0
  28. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/backends/openai_backend.py +0 -0
  29. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/blueprints.py +0 -0
  30. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/cache.py +0 -0
  31. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/chat_tags.py +0 -0
  32. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/client.py +0 -0
  33. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/compaction.py +0 -0
  34. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/context.py +0 -0
  35. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/diff_preview.py +0 -0
  36. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/discovery.py +0 -0
  37. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/doctor.py +0 -0
  38. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/dream_rsi.py +0 -0
  39. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/git_ops.py +0 -0
  40. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/github.py +0 -0
  41. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/guardian.py +0 -0
  42. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/guardrails.py +0 -0
  43. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/ipython_ext.py +0 -0
  44. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/media.py +0 -0
  45. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/memory.py +0 -0
  46. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/metrics.py +0 -0
  47. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/onboarding.py +0 -0
  48. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/paths.py +0 -0
  49. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/progress.py +0 -0
  50. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/project_template.py +0 -0
  51. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/prompt.py +0 -0
  52. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/rephraser.py +0 -0
  53. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/session.py +0 -0
  54. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/accessibility-audit/SKILL.md +0 -0
  55. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/accessibility-testing/SKILL.md +0 -0
  56. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/accessibility-ui-components/SKILL.md +0 -0
  57. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/agentic-workflows/SKILL.md +0 -0
  58. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/api-design/SKILL.md +0 -0
  59. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/architecture-design/SKILL.md +0 -0
  60. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/backend-engineering/SKILL.md +0 -0
  61. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/browser-automation/SKILL.md +0 -0
  62. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/cli-development/SKILL.md +0 -0
  63. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/cloud-infrastructure/SKILL.md +0 -0
  64. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/code-generation/SKILL.md +0 -0
  65. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/code-review/SKILL.md +0 -0
  66. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/codebase-onboarding/SKILL.md +0 -0
  67. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/cost-optimization/SKILL.md +0 -0
  68. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/data-analysis/SKILL.md +0 -0
  69. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/data-engineering/SKILL.md +0 -0
  70. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/database-engineering/SKILL.md +0 -0
  71. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/dependency-management/SKILL.md +0 -0
  72. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/dependency-security/SKILL.md +0 -0
  73. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/dependency-upgrades/SKILL.md +0 -0
  74. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/devops-ci-cd/SKILL.md +0 -0
  75. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/docker-containers/SKILL.md +0 -0
  76. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/documentation/SKILL.md +0 -0
  77. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/documentation-site/SKILL.md +0 -0
  78. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/e2e-testing/SKILL.md +0 -0
  79. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/error-handling-resilience/SKILL.md +0 -0
  80. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/feature-development/SKILL.md +0 -0
  81. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/frontend-engineering/SKILL.md +0 -0
  82. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/git-workflow/SKILL.md +0 -0
  83. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/incident-response/SKILL.md +0 -0
  84. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/legacy-code-modernization/SKILL.md +0 -0
  85. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/llm-application-engineering/SKILL.md +0 -0
  86. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/localization-i18n/SKILL.md +0 -0
  87. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/mcp-server-development/SKILL.md +0 -0
  88. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/migration-engineering/SKILL.md +0 -0
  89. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/mobile-development/SKILL.md +0 -0
  90. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/model-evaluation/SKILL.md +0 -0
  91. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/nodejs-services/SKILL.md +0 -0
  92. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/observability/SKILL.md +0 -0
  93. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/performance-optimization/SKILL.md +0 -0
  94. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/privacy-data-protection/SKILL.md +0 -0
  95. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/prompt-engineering/SKILL.md +0 -0
  96. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/python-engineering/SKILL.md +0 -0
  97. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/rag-retrieval/SKILL.md +0 -0
  98. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/react-engineering/SKILL.md +0 -0
  99. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/release-management/SKILL.md +0 -0
  100. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/requirements-analysis/SKILL.md +0 -0
  101. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/responsive-design/SKILL.md +0 -0
  102. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/safe-refactoring/SKILL.md +0 -0
  103. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/secure-coding/SKILL.md +0 -0
  104. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/systematic-debugging/SKILL.md +0 -0
  105. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/technical-planning/SKILL.md +0 -0
  106. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/technical-research/SKILL.md +0 -0
  107. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/technical-writing/SKILL.md +0 -0
  108. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/test-engineering/SKILL.md +0 -0
  109. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/tool-integration/SKILL.md +0 -0
  110. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/typescript-engineering/SKILL.md +0 -0
  111. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/visual-regression-testing/SKILL.md +0 -0
  112. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/web-performance/SKILL.md +0 -0
  113. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/web-security-testing/SKILL.md +0 -0
  114. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills/workflow-automation/SKILL.md +0 -0
  115. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/skills.py +0 -0
  116. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/subagent.py +0 -0
  117. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/system1.py +0 -0
  118. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/tools.py +0 -0
  119. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/updater.py +0 -0
  120. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/verifier.py +0 -0
  121. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/vscode_installer.py +0 -0
  122. {alpiecode-10.10.1 → alpiecode-10.10.3}/src/codeagent/walkthrough.py +0 -0
  123. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_adaptive_resilience.py +0 -0
  124. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_chat_tags_and_offline_multimodal.py +0 -0
  125. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_cli_ui.py +0 -0
  126. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_context_and_trajectory.py +0 -0
  127. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_deloop_and_sessions.py +0 -0
  128. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_dream_rsi.py +0 -0
  129. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_frontier_architecture.py +0 -0
  130. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_gpu_detection.py +0 -0
  131. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_lifecycle_and_portfolio.py +0 -0
  132. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_local_model_download.py +0 -0
  133. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_memory_optimization.py +0 -0
  134. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_non_thinking_and_local_stream.py +0 -0
  135. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_onboarding.py +0 -0
  136. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_project_templates.py +0 -0
  137. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_security_config.py +0 -0
  138. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_skills_engine.py +0 -0
  139. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_slash_and_diff.py +0 -0
  140. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_subagents.py +0 -0
  141. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_task_assessment.py +0 -0
  142. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_token_economy_and_256k.py +0 -0
  143. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_verifier.py +0 -0
  144. {alpiecode-10.10.1 → alpiecode-10.10.3}/test/test_walkthrough.py +0 -0
  145. {alpiecode-10.10.1 → alpiecode-10.10.3}/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.1
3
+ Version: 10.10.3
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.1"
7
+ version = "10.10.3"
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.1
3
+ Version: 10.10.3
4
4
  Summary: AlpieCode
5
5
  Requires-Python: >=3.9
6
6
  Requires-Dist: huggingface_hub>=0.20.0
@@ -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.1"
20
+ __version__ = "10.10.3"
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",
@@ -153,9 +153,9 @@ def main():
153
153
  common.add_argument("--github", default=None, help="GitHub repository (e.g. owner/repo or URL) for open-source analysis")
154
154
  common.add_argument("--max-turns", type=int, default=None, help="Override max turns")
155
155
  common.add_argument("--endpoint", "--base-url", dest="endpoint", default=None, help="VLM API endpoint base URL")
156
- common.add_argument("--model", dest="model", default=None, help="Model name (e.g. alpie_seed, alpie_9b)")
156
+ common.add_argument("--model", dest="model", default=None, help="Model name (e.g. alpie_seed)")
157
157
  common.add_argument("--api-key", dest="api_key", default=None, help="API key for endpoint authentication")
158
- common.add_argument("--preset", dest="preset", choices=["default", "alpie_seed", "alpie_9b"], default=None, help="Endpoint preset profile")
158
+ common.add_argument("--preset", dest="preset", choices=["default", "alpie_seed"], default=None, help="Endpoint preset profile")
159
159
  common.add_argument("--thinking", "--reasoning", dest="thinking", action="store_true", help="Enable VLM reasoning mode")
160
160
  common.add_argument("--no-thinking", "--non-thinking", dest="no_thinking", action="store_true", help="Disable VLM reasoning mode")
161
161
  common.add_argument("--force-thinking", dest="force_thinking", action="store_true", help="Force VLM reasoning on all turns, disabling dynamic gating")
@@ -89,7 +89,7 @@ KNOWN_PRESETS = {
89
89
  },
90
90
  "alpie_9b": {
91
91
  "base_url": _INTERNAL_9B_URL,
92
- "model": "alpie_9b",
92
+ "model": "alpie_seed",
93
93
  "api_key": "not-needed",
94
94
  },
95
95
  }
@@ -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)
@@ -889,8 +889,8 @@ class AgentOrchestrator:
889
889
  if extracted_tcs and not resp.tool_calls:
890
890
  resp.tool_calls = extracted_tcs
891
891
 
892
- # Truncation cleanup: If any tool call was truncated, condense its arguments before saving to context
893
- # to prevent massive truncated strings (15k+ chars) from exhausting the context window on subsequent turns
892
+ # Truncation cleanup: If any tool call was truncated, ensure arguments retain clean dict structure
893
+ # with path and parsed content preserved so tools (e.g. write_file partial save) can execute cleanly.
894
894
  for tc in resp.tool_calls or []:
895
895
  import json as _json
896
896
  tc_args = tc.arguments if isinstance(tc.arguments, dict) else {}
@@ -899,13 +899,8 @@ class AgentOrchestrator:
899
899
  tc_args = _json.loads(tc.arguments)
900
900
  except Exception:
901
901
  tc_args = {}
902
- if tc_args.get("_was_truncated") and tc.name in ("write_file", "edit_file", "append_file"):
903
- p = tc_args.get("path") or tc_args.get("file") or "file"
904
- condensed = {"path": p, "content": f"... [content truncated at token limit and preserved on disk] ...", "_was_truncated": True}
905
- tc.arguments = _json.dumps(condensed)
906
- if resp.content and "<tool_call>" in resp.content:
907
- from .compaction import compact_text_tool_calls
908
- resp.content = compact_text_tool_calls(resp.content)
902
+ if isinstance(tc_args, dict) and tc_args:
903
+ tc.arguments = tc_args # Always guarantee dict type, never serialized JSON string
909
904
 
910
905
  session.context.add_assistant_response(resp)
911
906
 
@@ -78,7 +78,7 @@ if HAS_FASTAPI:
78
78
  "status": "online",
79
79
  "mode": "offline" if is_offline else "online",
80
80
  "backend": backend_name,
81
- "model": getattr(getattr(app.state, "cfg", None), "model", "alpie_9b"),
81
+ "model": getattr(getattr(app.state, "cfg", None), "model", "alpie_seed"),
82
82
  "available": is_avail,
83
83
  "uptime_seconds": round(uptime, 2),
84
84
  "version": "0.9.2",
@@ -70,7 +70,7 @@ def handle_slash_command(
70
70
  " [bold green]/url <youtube_url>[/bold green] - Attach a YouTube video URL for multimodal analysis\n"
71
71
  " [bold green]/github <repo>[/bold green] - Set target GitHub repo for clone & analysis\n"
72
72
  " [bold green]/cd <path>[/bold green] - Switch active working directory on the fly\n"
73
- " [bold green]/model <name>[/bold green] - Switch model (e.g. alpie_seed, alpie_9b)\n"
73
+ " [bold green]/model <name>[/bold green] - Switch model (e.g. alpie_seed)\n"
74
74
  " [bold green]/offline[/bold green] - Switch to local offline GGUF inference\n"
75
75
  " [bold green]/online[/bold green] - Switch to cloud VLM API endpoint\n"
76
76
  " [bold green]/diff[/bold green] - View unified colored diff of changes made\n"
@@ -351,6 +351,8 @@ def handle_slash_command(
351
351
  from .agent import resolve_backend
352
352
  cfg.base_url = "offline"
353
353
  os.environ["ALPIECODE_BASE_URL"] = "offline"
354
+ if getattr(cfg, "n_ctx", 0) > 32768:
355
+ cfg.n_ctx = 16384
354
356
  orchestrator.backend = resolve_backend(cfg)
355
357
  console.print("[bold yellow]🧠 Switched to OFFLINE mode (Local GGUF model on device).[/bold yellow]" if has_rich else "Switched to OFFLINE mode (Local GGUF).")
356
358
  return True
@@ -363,6 +365,7 @@ def handle_slash_command(
363
365
  cfg.base_url = KNOWN_PRESETS.get("alpie_seed", {}).get("base_url", "https://api.169pi.com/v1")
364
366
  if "ALPIECODE_BASE_URL" in os.environ:
365
367
  del os.environ["ALPIECODE_BASE_URL"]
368
+ cfg.n_ctx = 262144
366
369
  orchestrator.backend = resolve_backend(cfg)
367
370
  console.print("[bold green]🌐 Switched to ONLINE mode (Cloud VLM API).[/bold green]" if has_rich else "Switched to ONLINE mode.")
368
371
  return True
@@ -145,3 +145,63 @@ def test_gpu_context_window_auto_scaling(monkeypatch):
145
145
  # Should auto-scale to 16,384 tokens on 6GB GPU
146
146
  assert cfg.n_ctx == 16384
147
147
  assert cfg.max_tokens == 8192
148
+
149
+
150
+ def test_executor_normalizes_string_arguments_without_error():
151
+ """ToolExecutor handles JSON-string serialized arguments cleanly without 'path parameter is required' error."""
152
+ from codeagent.executor import ToolExecutor, ToolCall
153
+ with tempfile.TemporaryDirectory() as td:
154
+ workdir = Path(td)
155
+ executor = ToolExecutor(workdir)
156
+
157
+ # Call with arguments as a JSON string (simulating serialized payload)
158
+ serialized_args = json.dumps({"path": "output.txt", "content": "Hello from string args"})
159
+ tc = ToolCall(id="call_test_1", name="write_file", arguments=serialized_args)
160
+
161
+ results = executor.execute_tool_calls([tc])
162
+ assert len(results) == 1
163
+ assert "Successfully wrote" in results[0].content or "error:" not in results[0].content
164
+ assert (workdir / "output.txt").read_text() == "Hello from string args"
165
+
166
+
167
+ def test_local_backend_preserves_multimodal_when_vision_active():
168
+ """LocalBackend._sanitize_messages_for_gguf preserves image_url blocks when mmproj is cached."""
169
+ from codeagent.backends.local_backend import LocalBackend
170
+
171
+ test_messages = [
172
+ {"role": "system", "content": "You are Alpie."},
173
+ {
174
+ "role": "user",
175
+ "content": [
176
+ {"type": "text", "text": "Analyze this frame"},
177
+ {"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,/9j/4AAQSkZJRg=="}},
178
+ ],
179
+ },
180
+ ]
181
+
182
+ with patch("codeagent.backends.local_backend.Path.glob", return_value=[Path("/mock/alpie-vl-mmproj-f16.gguf")]):
183
+ sanitized = LocalBackend._sanitize_messages_for_gguf(test_messages)
184
+ user_msg = next(m for m in sanitized if m["role"] == "user")
185
+ assert isinstance(user_msg["content"], list), "Multimodal user turn must remain a list for Qwen25VLChatHandler"
186
+ assert any(p.get("type") == "image_url" for p in user_msg["content"])
187
+
188
+
189
+ def test_multimodal_token_estimation_not_skewed_by_base64():
190
+ """Base64 images must NOT be counted as millions of text characters in headroom calculation."""
191
+ from codeagent.backends.local_backend import LocalBackend
192
+
193
+ # Simulated 18 base64 images (~1MB payload)
194
+ fake_b64 = "A" * 80000 # 80KB base64
195
+ msg = {
196
+ "role": "user",
197
+ "content": [
198
+ {"type": "text", "text": "Compare these cars"}
199
+ ] + [
200
+ {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{fake_b64}"}}
201
+ for _ in range(18)
202
+ ],
203
+ }
204
+
205
+ compacted, safe_max = LocalBackend._enforce_context_headroom([msg], max_context=16384, max_tokens=4096)
206
+ # With 18 images at ~450 tokens each (8100 tokens), safe_max should be substantial, NOT clamped to 256!
207
+ assert safe_max >= 2048, f"safe_max_tokens should be >= 2048, got {safe_max}"
File without changes
File without changes
File without changes