euron-code 1.8.8__tar.gz → 1.8.9__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 (172) hide show
  1. {euron_code-1.8.8 → euron_code-1.8.9}/CHANGELOG.md +13 -0
  2. {euron_code-1.8.8 → euron_code-1.8.9}/PKG-INFO +1 -1
  3. {euron_code-1.8.8 → euron_code-1.8.9}/pyproject.toml +1 -1
  4. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/__init__.py +1 -1
  5. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/fs.py +78 -3
  6. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_tools_fs.py +9 -6
  7. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v160_stop_scope_atomic.py +15 -4
  8. euron_code-1.8.9/tests/test_v189_edit_partial.py +138 -0
  9. {euron_code-1.8.8 → euron_code-1.8.9}/.gitignore +0 -0
  10. {euron_code-1.8.8 → euron_code-1.8.9}/LICENSE +0 -0
  11. {euron_code-1.8.8 → euron_code-1.8.9}/README.md +0 -0
  12. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/__main__.py +0 -0
  13. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/activity.py +0 -0
  14. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/agent.py +0 -0
  15. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/api.py +0 -0
  16. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/attachments.py +0 -0
  17. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/auth.py +0 -0
  18. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/autoupdate.py +0 -0
  19. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/builtin_skills/build-from-reference/SKILL.md +0 -0
  20. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/builtin_skills/explain-codebase/SKILL.md +0 -0
  21. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/builtin_skills/review/SKILL.md +0 -0
  22. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/builtin_skills/test-writer/SKILL.md +0 -0
  23. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/cache.py +0 -0
  24. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/checkpoints.py +0 -0
  25. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/cli.py +0 -0
  26. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/codeindex.py +0 -0
  27. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/config.py +0 -0
  28. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/context.py +0 -0
  29. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/contextforge/LICENSE +0 -0
  30. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/contextforge/__init__.py +0 -0
  31. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/contextforge/text.py +0 -0
  32. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/contextforge/toolout.py +0 -0
  33. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/credentials.py +0 -0
  34. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/ctxstats.py +0 -0
  35. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/doctor.py +0 -0
  36. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/documents.py +0 -0
  37. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/dotnet.py +0 -0
  38. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/error_hints.py +0 -0
  39. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/errorlog.py +0 -0
  40. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/failures.py +0 -0
  41. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/friendly.py +0 -0
  42. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/frontmatter.py +0 -0
  43. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/hooks.py +0 -0
  44. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/keys.py +0 -0
  45. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/knowledge.py +0 -0
  46. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/licensing.py +0 -0
  47. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/llm/__init__.py +0 -0
  48. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/llm/anthropic.py +0 -0
  49. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/llm/base.py +0 -0
  50. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/llm/openai_compat.py +0 -0
  51. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/llm/setup.py +0 -0
  52. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/logo.py +0 -0
  53. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/markdown_view.py +0 -0
  54. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/memory.py +0 -0
  55. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/migration.py +0 -0
  56. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/modes.py +0 -0
  57. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/mvc5.py +0 -0
  58. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/osscache.py +0 -0
  59. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/ossgithub.py +0 -0
  60. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/pasteinput.py +0 -0
  61. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/pathfix.py +0 -0
  62. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/permissions.py +0 -0
  63. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/progress.py +0 -0
  64. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/project_setup.py +0 -0
  65. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/prompts.py +0 -0
  66. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/repl.py +0 -0
  67. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/repomap.py +0 -0
  68. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/rules.py +0 -0
  69. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/security_scan.py +0 -0
  70. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/sessions.py +0 -0
  71. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/skills.py +0 -0
  72. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/taskstate.py +0 -0
  73. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/textsafe.py +0 -0
  74. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tls.py +0 -0
  75. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/__init__.py +0 -0
  76. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/background.py +0 -0
  77. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/base.py +0 -0
  78. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/db.py +0 -0
  79. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/document.py +0 -0
  80. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/erie.py +0 -0
  81. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/ignore.py +0 -0
  82. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/normalize.py +0 -0
  83. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/oss.py +0 -0
  84. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/pathfind.py +0 -0
  85. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/port.py +0 -0
  86. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/reuse.py +0 -0
  87. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/search.py +0 -0
  88. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/shell.py +0 -0
  89. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/skill.py +0 -0
  90. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/symbols.py +0 -0
  91. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/task.py +0 -0
  92. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/todo.py +0 -0
  93. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/web.py +0 -0
  94. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/tools/websearch.py +0 -0
  95. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/transcript.py +0 -0
  96. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/trust.py +0 -0
  97. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/ui.py +0 -0
  98. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/update_check.py +0 -0
  99. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/usage_view.py +0 -0
  100. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/version_info.py +0 -0
  101. {euron_code-1.8.8 → euron_code-1.8.9}/src/euron_code/webforms.py +0 -0
  102. {euron_code-1.8.8 → euron_code-1.8.9}/tests/conftest.py +0 -0
  103. {euron_code-1.8.8 → euron_code-1.8.9}/tests/fake_providers.py +0 -0
  104. {euron_code-1.8.8 → euron_code-1.8.9}/tests/helpers.py +0 -0
  105. {euron_code-1.8.8 → euron_code-1.8.9}/tests/measure_floor.py +0 -0
  106. {euron_code-1.8.8 → euron_code-1.8.9}/tests/mock_gateway.py +0 -0
  107. {euron_code-1.8.8 → euron_code-1.8.9}/tests/serve_helper.py +0 -0
  108. {euron_code-1.8.8 → euron_code-1.8.9}/tests/sim_long_session.py +0 -0
  109. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_agent_mock.py +0 -0
  110. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_api_shell.py +0 -0
  111. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_bench.py +0 -0
  112. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_bench_harness.py +0 -0
  113. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_cli_e2e.py +0 -0
  114. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_context_memory_sessions.py +0 -0
  115. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_dashboard_fixes.py +0 -0
  116. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_dashboard_fixes_102.py +0 -0
  117. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_db.py +0 -0
  118. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_erie.py +0 -0
  119. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_knowledge_security.py +0 -0
  120. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_markdown_view.py +0 -0
  121. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_oss_local.py +0 -0
  122. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_permissions.py +0 -0
  123. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_powershell_exit_codes.py +0 -0
  124. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_qa_attach_secrets.py +0 -0
  125. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_qa_long_task.py +0 -0
  126. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_qa_print_output.py +0 -0
  127. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_qa_reuse_unrelated.py +0 -0
  128. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_qa_yolo_outside.py +0 -0
  129. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_render_ghost.py +0 -0
  130. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_repl.py +0 -0
  131. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_reuse_honesty.py +0 -0
  132. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_search.py +0 -0
  133. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_textsafe.py +0 -0
  134. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_transcript_ui.py +0 -0
  135. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_update_check.py +0 -0
  136. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v111_user_reports.py +0 -0
  137. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v113_fix_path.py +0 -0
  138. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v11_byo.py +0 -0
  139. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v11_speed.py +0 -0
  140. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v11_tool_fixes.py +0 -0
  141. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v130_cut_writes.py +0 -0
  142. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v130_reliability.py +0 -0
  143. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v140_parity.py +0 -0
  144. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v152_migration.py +0 -0
  145. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v153_user_errors.py +0 -0
  146. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v155_user_errors.py +0 -0
  147. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v156_autoupdate.py +0 -0
  148. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v156_paste_and_edits.py +0 -0
  149. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v157_zero_errors.py +0 -0
  150. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v15_hosted_models.py +0 -0
  151. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v15_reuse_off_subagent_hooks.py +0 -0
  152. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v161_residual_errors.py +0 -0
  153. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v170_v2.py +0 -0
  154. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v180_rescue_research_permissions.py +0 -0
  155. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v181_silent_failures_verified.py +0 -0
  156. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v182_zero_errors.py +0 -0
  157. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v184_selfupdate_pep668.py +0 -0
  158. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v186_bypass_and_waits.py +0 -0
  159. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v187_sleep_wake.py +0 -0
  160. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v188_typed_cli_commands.py +0 -0
  161. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v2_rules_skills_hooks.py +0 -0
  162. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v2_tokens_shortcuts.py +0 -0
  163. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v2_usage_headers.py +0 -0
  164. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v31_security.py +0 -0
  165. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v3_accounts_value_setup.py +0 -0
  166. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v3_activity.py +0 -0
  167. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v3_attachments.py +0 -0
  168. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v3_context.py +0 -0
  169. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v3_live_repl.py +0 -0
  170. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v3_single_login.py +0 -0
  171. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v4.py +0 -0
  172. {euron_code-1.8.8 → euron_code-1.8.9}/tests/test_v5.py +0 -0
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.8.9 (2026-11-20)
4
+
5
+ - **One wrong edit no longer throws away the good ones.** When Euron Code changes several places in one file at once
6
+ and one of them does not match the file, the others are now applied and only the missing one is reported, with the
7
+ file's real text to copy. Before, nothing was applied and the whole batch had to be sent again (in the last days one
8
+ batch of 21 changes was lost to a single wrong line). If no change matches at all, the file stays as it was.
9
+ - **A change that is already in the file is not an error, and is never added twice.** A change sent again (after a
10
+ summary of a long conversation, or a step that was partly done) used to fail with "old_string was not found"; an
11
+ added line sent again could appear twice. Both are now recognised and skipped, also in files with Windows line ends.
12
+ - On a benchmark built from the shapes of these failures (no user code), the same edits needed about 10% fewer steps
13
+ and over a third less text sent, and a model that re-sends only the change it fixed now ends with the right file
14
+ every time (before: about 1 in 4).
15
+
3
16
  ## 1.8.8 (2026-11-20)
4
17
 
5
18
  - **Typing a terminal command at the Euron Code prompt now does what you meant.** Many people typed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: euron-code
3
- Version: 1.8.8
3
+ Version: 1.8.9
4
4
  Summary: Euron Code: an agentic coding assistant in your terminal for Euron Plus and Super 30 students.
5
5
  Project-URL: Homepage, https://euron.one/code-agent
6
6
  Author-email: Euron <contact@euron.one>
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "euron-code"
7
- version = "1.8.8"
7
+ version = "1.8.9"
8
8
  description = "Euron Code: an agentic coding assistant in your terminal for Euron Plus and Super 30 students."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -1,3 +1,3 @@
1
1
  """Euron Code: an agentic coding assistant for the terminal."""
2
2
 
3
- __version__ = "1.8.8"
3
+ __version__ = "1.8.9"
@@ -515,6 +515,37 @@ def _project_hint(ctx: ToolContext, wanted: str) -> str:
515
515
  return ""
516
516
 
517
517
 
518
+
519
+ #: 1.8.9: new_string must have at least this many non-blank characters to count as "already in the file"
520
+ ALREADY_MIN_CHARS = 20
521
+
522
+
523
+ def _already_applied(text: str, old: str, new: str, count: int) -> str:
524
+ """The edit is already in the file (prod 17-20 Nov: edits retried after a partial step, a summary or a rewind
525
+ failed with "old_string was not found", or an insertion was applied twice). Returns the note, or "".
526
+ - old_string is gone and new_string is there (and new_string is not just a piece of old_string): nothing to do.
527
+ - an insertion (new_string contains old_string) where every occurrence of old_string already sits inside an
528
+ occurrence of new_string: applying it again would add a second copy."""
529
+ core = new.strip()
530
+ if len("".join(core.split())) < ALREADY_MIN_CHARS or not old.strip() or new == old:
531
+ return ""
532
+ if count == 0:
533
+ if new in text and old.strip() not in core:
534
+ return "no change needed: the file already has new_string (this edit was applied before)"
535
+ return ""
536
+ if old in new and new in text:
537
+ off = new.index(old)
538
+ free, at = 0, text.find(old)
539
+ while at >= 0:
540
+ start = at - off
541
+ if not (start >= 0 and text.startswith(new, start)):
542
+ free += 1
543
+ at = text.find(old, at + max(1, len(old)))
544
+ if free == 0:
545
+ return "no change needed: the file already has new_string (applying it again would add a second copy)"
546
+ return ""
547
+
548
+
518
549
  def apply_edit_ex(text: str, old: str, new: str, replace_all: bool = False) -> Tuple[str, int, str]:
519
550
  """apply_edit plus how the match was found ("" = exact)."""
520
551
  if old == "":
@@ -532,6 +563,11 @@ def apply_edit_ex(text: str, old: str, new: str, replace_all: bool = False) -> T
532
563
  if count == 0 and old_a != old:
533
564
  old_a, new_a = old, new
534
565
  count = text.count(old_a)
566
+ done = _already_applied(text, old_a, new_a, count)
567
+ if not done and crlf and count == 0 and "\r\n" not in new: # a CRLF file, LF edit text
568
+ done = _already_applied(text, _adapt_newlines(old, True), _adapt_newlines(new, True), 0)
569
+ if done:
570
+ return text, 0, done
535
571
  if count == 0:
536
572
  # 1. line numbers copied from read_file
537
573
  g_old = _strip_gutter(old)
@@ -1068,6 +1104,9 @@ class EditFile(Tool):
1068
1104
  text = tf.text
1069
1105
  total = 0
1070
1106
  self._notes = []
1107
+ self._skipped = [] # multi_edit (1.8.9): edits that did not match, with why; the others are applied
1108
+ self._n_edits = len(edits)
1109
+ partial_ok = self.name == "multi_edit" and len(edits) > 1 and not strict
1071
1110
 
1072
1111
  def refuse(why: str):
1073
1112
  ctx.tracker.mark_read(path, (1, TO_END), ctx.turn, len(tf.text), ctx.call_id)
@@ -1089,13 +1128,46 @@ class EditFile(Tool):
1089
1128
  if strict and "Its current content is below" not in str(err):
1090
1129
  refuse(f"{ctx.rel(path)} {'was not read in this session (read_file a file before editing it)' if not ctx.tracker.was_read(path) else 'changed since you read it'}"
1091
1130
  f" and edit {i} did not match: {str(err).split(chr(10))[0]}")
1131
+ if partial_ok:
1132
+ # prod 17-20 Nov: 226 "Edit N failed, so none of the M edits were applied" from 20 people; the
1133
+ # retry re-sent every edit and often failed again (up to 21 edits lost for one bad one). The
1134
+ # edits that match are applied; the ones that do not are reported with the text to copy.
1135
+ self._skipped.append((i, e, str(err)))
1136
+ continue
1092
1137
  prefix = (f"Edit {i} failed, so none of the {len(edits)} edits were applied "
1093
1138
  "(the file is unchanged): ") if self.name == "multi_edit" else ""
1094
1139
  raise ToolError(prefix + str(err) + _current_text_for_retry(ctx, path, tf, str(err),
1095
1140
  str(e.get("old_string") or "")))
1096
1141
  total += n
1142
+ if self._skipped and len(self._skipped) == len(edits):
1143
+ i, e, err = self._skipped[0]
1144
+ self._skipped = []
1145
+ raise ToolError(f"None of the {len(edits)} edits matched (the file is unchanged). Edit {i}: " + err
1146
+ + _current_text_for_retry(ctx, path, TextFile(text, tf.bom), err,
1147
+ str(e.get("old_string") or "")))
1097
1148
  return path, tf, text, total
1098
1149
 
1150
+ def _skipped_report(self, ctx, path: Path, text: str, applied: int) -> str:
1151
+ """multi_edit: what was NOT applied, each with its reason and the current text to copy for the retry."""
1152
+ skipped = getattr(self, "_skipped", None) or []
1153
+ if not skipped:
1154
+ return ""
1155
+ nums = ", ".join(str(i) for i, _, _ in skipped)
1156
+ out = [f"\nPARTLY APPLIED: {applied} edit(s) are in the file; edit(s) {nums} were NOT applied (they did not "
1157
+ "match). Send ONLY the missing edit(s) again with old_string copied from the text below; do not "
1158
+ "re-send the applied ones."]
1159
+ tf_now = TextFile(text, False)
1160
+ shown_whole = False
1161
+ for i, e, err in skipped:
1162
+ out.append(f"Edit {i}: " + (err if "matches" in err.split(chr(10))[0] else err.split(chr(10))[0]))
1163
+ if shown_whole:
1164
+ continue
1165
+ extra = _current_text_for_retry(ctx, path, tf_now, err, str(e.get("old_string") or ""))
1166
+ if extra:
1167
+ out.append(extra.lstrip("\n"))
1168
+ shown_whole = extra.startswith("\nThe file as it is now")
1169
+ return "\n".join(out)
1170
+
1099
1171
  def preview(self, args, ctx):
1100
1172
  path, tf, text, _ = self._compute(args, ctx)
1101
1173
  return make_diff(tf.text, text, ctx.rel(path))
@@ -1123,8 +1195,10 @@ class EditFile(Tool):
1123
1195
  + (f" (matched {'; '.join(sorted(set(notes)))}; check the diff)" if notes else "")
1124
1196
  + ".\n"
1125
1197
  + truncate(diff, 3000 if notes else 1500, "diff shortened") + (f"\n{check}" if check else "")
1126
- + (("\n" + dup) if dup else ""),
1127
- preview=f"+{added} -{removed} lines" + (f" ({check})" if check and "error" in check else ""),
1198
+ + (("\n" + dup) if dup else "")
1199
+ + self._skipped_report(ctx, path, text, getattr(self, "_n_edits", 0) - len(getattr(self, "_skipped", None) or [])),
1200
+ preview=f"+{added} -{removed} lines" + (f" ({check})" if check and "error" in check else "")
1201
+ + (f", {len(self._skipped)} edit(s) not applied" if getattr(self, "_skipped", None) else ""),
1128
1202
  )
1129
1203
 
1130
1204
 
@@ -1186,7 +1260,8 @@ def _edit_aliases(e: Any) -> Any:
1186
1260
 
1187
1261
  class MultiEdit(EditFile):
1188
1262
  name = "multi_edit"
1189
- description = 'Several exact-string edits to ONE file, in order, all or nothing.'
1263
+ description = ("Several exact-string edits to ONE file, in order. Edits that match are applied; any that do "
1264
+ "not are reported back with the current text, so re-send only those.")
1190
1265
  parameters = {
1191
1266
  "type": "object",
1192
1267
  "properties": {
@@ -112,16 +112,19 @@ def test_edit_preserves_crlf_and_bom(project):
112
112
  assert p.read_bytes() == b"\xef\xbb\xbfuno\r\ndos\r\n"
113
113
 
114
114
 
115
- def test_multi_edit_is_atomic(project):
115
+ def test_multi_edit_applies_what_matches(project):
116
+ # 1.8.9: no longer all-or-nothing; the edit that did not match is reported, the file keeps the others
116
117
  p = project / "m.py"
117
118
  p.write_text("a = 1\nb = 2\n")
118
119
  ctx = make_ctx(project)
119
120
  ReadFile().run({"path": "m.py"}, ctx)
120
- with pytest.raises(ToolError, match="Edit 2 failed"):
121
- MultiEdit().run({"path": "m.py", "edits": [
122
- {"old_string": "a = 1", "new_string": "a = 10"},
123
- {"old_string": "zzz", "new_string": "y"}]}, ctx)
124
- assert p.read_text() == "a = 1\nb = 2\n"
121
+ res = MultiEdit().run({"path": "m.py", "edits": [
122
+ {"old_string": "a = 1", "new_string": "a = 10"},
123
+ {"old_string": "zzz", "new_string": "y"}]}, ctx)
124
+ assert "edit(s) 2 were NOT applied" in res.content
125
+ assert p.read_text() == "a = 10\nb = 2\n"
126
+ p.write_text("a = 1\nb = 2\n")
127
+ ReadFile().run({"path": "m.py"}, ctx)
125
128
  MultiEdit().run({"path": "m.py", "edits": [
126
129
  {"old_string": "a = 1", "new_string": "a = 10"},
127
130
  {"old_string": "a = 10\nb = 2", "new_string": "a = 10\nb = 20"}]}, ctx)
@@ -149,15 +149,26 @@ def test_one_failed_edit_undoes_the_other_edits_of_the_same_step(project):
149
149
  assert any("undone too" in c for c in tool_msgs)
150
150
 
151
151
 
152
- def test_multi_edit_failure_says_on_its_first_line_that_nothing_was_applied(project):
152
+ def test_multi_edit_applies_the_matching_edits_and_reports_the_rest(project):
153
+ # 1.8.9: was all-or-nothing ("none of the 2 edits were applied"); prod showed whole batches re-sent and lost
154
+ (project / "m.py").write_text("a = 1\nb = 2\n", encoding="utf-8")
155
+ ctx = make_ctx(project)
156
+ ctx.tracker.mark_read(project / "m.py", (1, 10 ** 9))
157
+ res = MultiEdit().run({"path": "m.py", "edits": [{"old_string": "a = 1", "new_string": "a = 9"},
158
+ {"old_string": "zzz", "new_string": "q"}]}, ctx)
159
+ assert not res.is_error
160
+ assert "PARTLY APPLIED" in res.content and "edit(s) 2 were NOT applied" in res.content
161
+ assert (project / "m.py").read_text(encoding="utf-8") == "a = 9\nb = 2\n"
162
+
163
+
164
+ def test_multi_edit_where_nothing_matches_is_an_error_and_changes_nothing(project):
153
165
  (project / "m.py").write_text("a = 1\nb = 2\n", encoding="utf-8")
154
166
  ctx = make_ctx(project)
155
167
  ctx.tracker.mark_read(project / "m.py", (1, 10 ** 9))
156
168
  with pytest.raises(ToolError) as ei:
157
- MultiEdit().run({"path": "m.py", "edits": [{"old_string": "a = 1", "new_string": "a = 9"},
169
+ MultiEdit().run({"path": "m.py", "edits": [{"old_string": "yyy", "new_string": "a = 9"},
158
170
  {"old_string": "zzz", "new_string": "q"}]}, ctx)
159
- first = str(ei.value).splitlines()[0]
160
- assert "none of the 2 edits were applied" in first
171
+ assert "None of the 2 edits matched" in str(ei.value).splitlines()[0]
161
172
  assert (project / "m.py").read_text(encoding="utf-8") == "a = 1\nb = 2\n"
162
173
 
163
174
 
@@ -0,0 +1,138 @@
1
+ """1.8.9: multi_edit applies the edits that match and reports the rest; an edit already in the file is a no-op.
2
+
3
+ Prod 17-20 Nov: 226 "Edit N failed, so none of the M edits were applied" (20 people) and ~250 "old_string was not
4
+ found" (18 people). Retries re-sent whole batches (up to 21 edits) and weak models often re-sent only the fixed edit,
5
+ losing the others; edits re-sent after a partial step failed because they were already applied.
6
+ Benchmark: bench/edit_shapes.py (synthetic files, prod failure shapes, no user code).
7
+ """
8
+
9
+ import pytest
10
+
11
+ from euron_code.tools.base import ToolError
12
+ from euron_code.tools.fs import EditFile, MultiEdit, apply_edit_ex
13
+ from helpers import make_ctx
14
+
15
+ SRC = ("def a():\n x = 1\n return x\n\n"
16
+ "def b():\n y = 2\n return y\n\n"
17
+ "def c():\n z = 3\n return z\n")
18
+
19
+
20
+ def _ctx(project, text=SRC, name="m.py", crlf=False):
21
+ f = project / name
22
+ f.write_bytes((text.replace("\n", "\r\n") if crlf else text).encode("utf-8"))
23
+ ctx = make_ctx(project)
24
+ ctx.tracker.mark_read(f, (1, 10 ** 9))
25
+ return f, ctx
26
+
27
+
28
+ # ---------------------------------------------------------------- partial apply
29
+
30
+ def test_good_edits_apply_and_the_bad_one_is_reported_with_the_text_to_copy(project):
31
+ f, ctx = _ctx(project)
32
+ res = MultiEdit().run({"path": "m.py", "edits": [
33
+ {"old_string": " x = 1", "new_string": " x = 10"},
34
+ {"old_string": " y = 99", "new_string": " y = 20"}, # stale
35
+ {"old_string": " z = 3", "new_string": " z = 30"}]}, ctx)
36
+ assert not res.is_error
37
+ body = f.read_text(encoding="utf-8")
38
+ assert "x = 10" in body and "z = 30" in body and "y = 2\n" in body
39
+ assert "PARTLY APPLIED: 2 edit(s) are in the file; edit(s) 2 were NOT applied" in res.content
40
+ assert "y = 2" in res.content.split("PARTLY APPLIED", 1)[1] # the real line, to copy for the retry
41
+ assert "not applied" in (res.preview or "")
42
+
43
+
44
+ def test_ambiguous_edit_is_reported_with_each_place(project):
45
+ f, ctx = _ctx(project)
46
+ res = MultiEdit().run({"path": "m.py", "edits": [
47
+ {"old_string": " x = 1", "new_string": " x = 10"},
48
+ {"old_string": " return", "new_string": " return "}]}, ctx)
49
+ report = res.content.split("PARTLY APPLIED", 1)[1]
50
+ assert "matches 3 places" in report and "lines" in report
51
+ assert "x = 10" in f.read_text(encoding="utf-8")
52
+
53
+
54
+ def test_dependent_edit_after_a_failed_one_is_also_reported(project):
55
+ f, ctx = _ctx(project)
56
+ res = MultiEdit().run({"path": "m.py", "edits": [
57
+ {"old_string": " x = 999", "new_string": " x = 5"},
58
+ {"old_string": " x = 5\n return x", "new_string": " x = 5\n return x + 1"},
59
+ {"old_string": " z = 3", "new_string": " z = 30"}]}, ctx)
60
+ assert "edit(s) 1, 2 were NOT applied" in res.content
61
+ assert f.read_text(encoding="utf-8").count("x = 1") == 1
62
+
63
+
64
+ def test_nothing_matching_stays_an_error_and_the_file_is_untouched(project):
65
+ f, ctx = _ctx(project)
66
+ with pytest.raises(ToolError) as ei:
67
+ MultiEdit().run({"path": "m.py", "edits": [{"old_string": "nope", "new_string": "a"},
68
+ {"old_string": "nada", "new_string": "b"}]}, ctx)
69
+ assert str(ei.value).startswith("None of the 2 edits matched")
70
+ assert f.read_text(encoding="utf-8") == SRC
71
+
72
+
73
+ def test_a_file_not_read_in_this_session_keeps_the_strict_refusal(project):
74
+ f = project / "m.py"
75
+ f.write_text(SRC, encoding="utf-8")
76
+ ctx = make_ctx(project) # never read
77
+ with pytest.raises(ToolError) as ei:
78
+ MultiEdit().run({"path": "m.py", "edits": [{"old_string": " x = 1", "new_string": " x = 10"},
79
+ {"old_string": "nope", "new_string": "b"}]}, ctx)
80
+ assert "was not read in this session" in str(ei.value)
81
+ assert f.read_text(encoding="utf-8") == SRC
82
+
83
+
84
+ def test_single_edit_multi_edit_keeps_the_old_error(project):
85
+ f, ctx = _ctx(project)
86
+ with pytest.raises(ToolError) as ei:
87
+ MultiEdit().run({"path": "m.py", "edits": [{"old_string": "nope", "new_string": "a"}]}, ctx)
88
+ assert "none of the 1 edits were applied" in str(ei.value)
89
+
90
+
91
+ # ---------------------------------------------------------------- already applied
92
+
93
+ def test_an_edit_already_in_the_file_is_a_no_op(project):
94
+ f, ctx = _ctx(project)
95
+ args = {"path": "m.py", "old_string": "def b():\n y = 2", "new_string": "def b():\n y = 2000 # the new value"}
96
+ EditFile().run(dict(args), ctx)
97
+ ctx.tracker.mark_read(f, (1, 10 ** 9))
98
+ res = EditFile().run(dict(args), ctx) # re-sent after a summary / partial step
99
+ assert not res.is_error and "already" in res.content
100
+ assert f.read_text(encoding="utf-8").count("y = 2000") == 1
101
+
102
+
103
+ def test_already_applied_on_a_crlf_file(project):
104
+ f, ctx = _ctx(project, crlf=True)
105
+ edit = {"old_string": "def c():\n z = 3", "new_string": "def c():\n z = 3000 # crlf case here"}
106
+ MultiEdit().run({"path": "m.py", "edits": [dict(edit), {"old_string": " x = 1", "new_string": " x = 9"}]}, ctx)
107
+ ctx.tracker.mark_read(f, (1, 10 ** 9))
108
+ res = MultiEdit().run({"path": "m.py", "edits": [dict(edit), {"old_string": " x = 9", "new_string": " x = 8"}]}, ctx)
109
+ assert "PARTLY" not in res.content
110
+ text = f.read_bytes().decode("utf-8")
111
+ assert text.count("z = 3000") == 1 and "x = 8" in text and "\r\n" in text
112
+
113
+
114
+ def test_an_insertion_is_not_added_twice(project):
115
+ text = "import os\n\ndef main():\n pass\n"
116
+ ins = {"old_string": "import os\n", "new_string": "import os\nimport sys # needed for argv\n"}
117
+ assert apply_edit_ex(text, ins["old_string"], ins["new_string"])[0].count("import sys") == 1
118
+ once = apply_edit_ex(text, ins["old_string"], ins["new_string"])[0]
119
+ again, n, how = apply_edit_ex(once, ins["old_string"], ins["new_string"])
120
+ assert again == once and n == 0 and "second copy" in how
121
+
122
+
123
+ def test_short_or_unrelated_text_is_not_taken_as_already_applied(project):
124
+ text = "a = 1\nb = 2\nresult = compute(a, b) # done\n"
125
+ # old_string missing and new_string short: still the normal error
126
+ with pytest.raises(ToolError):
127
+ apply_edit_ex(text, "c = 3", "b = 2")
128
+ # an insertion where old_string also appears OUTSIDE new_string is applied normally
129
+ t2 = "x = 1\nx = 1\ny = 2 # a long enough line\n"
130
+ out, n, _ = apply_edit_ex(t2, "x = 1\ny", "x = 1\nz = 0 # a long enough line\ny", replace_all=False)
131
+ assert n == 1
132
+
133
+
134
+ def test_replace_all_on_an_insertion_still_runs_when_some_places_lack_it():
135
+ text = "log()\nfoo()\nlog()\n"
136
+ out, n, how = apply_edit_ex("log()\ntrace() # traced call here\nfoo()\nlog()\n", "log()\n",
137
+ "log()\ntrace() # traced call here\n", replace_all=True)
138
+ assert n == 2 and how == ""
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes