euron-code 1.5.5__tar.gz → 1.5.6__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 (152) hide show
  1. {euron_code-1.5.5 → euron_code-1.5.6}/CHANGELOG.md +23 -0
  2. {euron_code-1.5.5 → euron_code-1.5.6}/PKG-INFO +1 -1
  3. {euron_code-1.5.5 → euron_code-1.5.6}/pyproject.toml +1 -1
  4. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/__init__.py +1 -1
  5. euron_code-1.5.6/src/euron_code/autoupdate.py +334 -0
  6. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/cli.py +76 -5
  7. euron_code-1.5.6/src/euron_code/pasteinput.py +208 -0
  8. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/prompts.py +2 -1
  9. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/repl.py +48 -2
  10. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/background.py +12 -4
  11. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/fs.py +24 -2
  12. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/ignore.py +75 -75
  13. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/shell.py +11 -2
  14. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/update_check.py +2 -2
  15. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_permissions.py +91 -91
  16. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_repl.py +10 -1
  17. euron_code-1.5.6/tests/test_v156_autoupdate.py +173 -0
  18. euron_code-1.5.6/tests/test_v156_paste_and_edits.py +249 -0
  19. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v3_live_repl.py +5 -1
  20. {euron_code-1.5.5 → euron_code-1.5.6}/.gitignore +0 -0
  21. {euron_code-1.5.5 → euron_code-1.5.6}/LICENSE +0 -0
  22. {euron_code-1.5.5 → euron_code-1.5.6}/README.md +0 -0
  23. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/__main__.py +0 -0
  24. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/activity.py +0 -0
  25. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/agent.py +0 -0
  26. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/api.py +0 -0
  27. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/attachments.py +0 -0
  28. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/auth.py +0 -0
  29. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/builtin_skills/build-from-reference/SKILL.md +0 -0
  30. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/builtin_skills/explain-codebase/SKILL.md +0 -0
  31. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/builtin_skills/review/SKILL.md +0 -0
  32. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/builtin_skills/test-writer/SKILL.md +0 -0
  33. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/cache.py +0 -0
  34. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/checkpoints.py +0 -0
  35. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/config.py +0 -0
  36. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/context.py +0 -0
  37. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/contextforge/LICENSE +0 -0
  38. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/contextforge/__init__.py +0 -0
  39. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/contextforge/text.py +0 -0
  40. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/contextforge/toolout.py +0 -0
  41. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/credentials.py +0 -0
  42. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/doctor.py +0 -0
  43. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/documents.py +0 -0
  44. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/dotnet.py +0 -0
  45. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/error_hints.py +0 -0
  46. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/errorlog.py +0 -0
  47. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/friendly.py +0 -0
  48. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/frontmatter.py +0 -0
  49. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/hooks.py +0 -0
  50. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/keys.py +0 -0
  51. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/knowledge.py +0 -0
  52. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/licensing.py +0 -0
  53. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/llm/__init__.py +0 -0
  54. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/llm/anthropic.py +0 -0
  55. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/llm/base.py +0 -0
  56. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/llm/openai_compat.py +0 -0
  57. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/llm/setup.py +0 -0
  58. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/logo.py +0 -0
  59. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/markdown_view.py +0 -0
  60. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/memory.py +0 -0
  61. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/migration.py +0 -0
  62. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/mvc5.py +0 -0
  63. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/osscache.py +0 -0
  64. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/ossgithub.py +0 -0
  65. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/pathfix.py +0 -0
  66. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/permissions.py +0 -0
  67. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/progress.py +0 -0
  68. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/project_setup.py +0 -0
  69. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/repomap.py +0 -0
  70. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/rules.py +0 -0
  71. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/security_scan.py +0 -0
  72. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/sessions.py +0 -0
  73. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/skills.py +0 -0
  74. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/textsafe.py +0 -0
  75. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/__init__.py +0 -0
  76. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/base.py +0 -0
  77. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/db.py +0 -0
  78. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/document.py +0 -0
  79. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/erie.py +0 -0
  80. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/normalize.py +0 -0
  81. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/oss.py +0 -0
  82. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/pathfind.py +0 -0
  83. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/port.py +0 -0
  84. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/reuse.py +0 -0
  85. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/search.py +0 -0
  86. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/skill.py +0 -0
  87. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/symbols.py +0 -0
  88. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/task.py +0 -0
  89. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/todo.py +0 -0
  90. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/tools/web.py +0 -0
  91. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/transcript.py +0 -0
  92. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/trust.py +0 -0
  93. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/ui.py +0 -0
  94. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/usage_view.py +0 -0
  95. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/version_info.py +0 -0
  96. {euron_code-1.5.5 → euron_code-1.5.6}/src/euron_code/webforms.py +0 -0
  97. {euron_code-1.5.5 → euron_code-1.5.6}/tests/conftest.py +0 -0
  98. {euron_code-1.5.5 → euron_code-1.5.6}/tests/fake_providers.py +0 -0
  99. {euron_code-1.5.5 → euron_code-1.5.6}/tests/helpers.py +0 -0
  100. {euron_code-1.5.5 → euron_code-1.5.6}/tests/measure_floor.py +0 -0
  101. {euron_code-1.5.5 → euron_code-1.5.6}/tests/mock_gateway.py +0 -0
  102. {euron_code-1.5.5 → euron_code-1.5.6}/tests/serve_helper.py +0 -0
  103. {euron_code-1.5.5 → euron_code-1.5.6}/tests/sim_long_session.py +0 -0
  104. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_agent_mock.py +0 -0
  105. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_api_shell.py +0 -0
  106. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_bench.py +0 -0
  107. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_bench_harness.py +0 -0
  108. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_cli_e2e.py +0 -0
  109. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_context_memory_sessions.py +0 -0
  110. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_dashboard_fixes.py +0 -0
  111. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_dashboard_fixes_102.py +0 -0
  112. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_db.py +0 -0
  113. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_erie.py +0 -0
  114. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_knowledge_security.py +0 -0
  115. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_markdown_view.py +0 -0
  116. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_oss_local.py +0 -0
  117. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_powershell_exit_codes.py +0 -0
  118. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_qa_attach_secrets.py +0 -0
  119. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_qa_long_task.py +0 -0
  120. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_qa_print_output.py +0 -0
  121. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_qa_reuse_unrelated.py +0 -0
  122. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_qa_yolo_outside.py +0 -0
  123. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_reuse_honesty.py +0 -0
  124. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_search.py +0 -0
  125. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_textsafe.py +0 -0
  126. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_tools_fs.py +0 -0
  127. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_transcript_ui.py +0 -0
  128. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_update_check.py +0 -0
  129. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v111_user_reports.py +0 -0
  130. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v113_fix_path.py +0 -0
  131. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v11_byo.py +0 -0
  132. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v11_speed.py +0 -0
  133. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v11_tool_fixes.py +0 -0
  134. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v130_cut_writes.py +0 -0
  135. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v130_reliability.py +0 -0
  136. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v140_parity.py +0 -0
  137. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v152_migration.py +0 -0
  138. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v153_user_errors.py +0 -0
  139. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v155_user_errors.py +0 -0
  140. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v15_hosted_models.py +0 -0
  141. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v15_reuse_off_subagent_hooks.py +0 -0
  142. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v2_rules_skills_hooks.py +0 -0
  143. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v2_tokens_shortcuts.py +0 -0
  144. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v2_usage_headers.py +0 -0
  145. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v31_security.py +0 -0
  146. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v3_accounts_value_setup.py +0 -0
  147. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v3_activity.py +0 -0
  148. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v3_attachments.py +0 -0
  149. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v3_context.py +0 -0
  150. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v3_single_login.py +0 -0
  151. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v4.py +0 -0
  152. {euron_code-1.5.5 → euron_code-1.5.6}/tests/test_v5.py +0 -0
@@ -1,5 +1,28 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.5.6 (2026-11-11)
4
+
5
+ Fixes from this week's usage review.
6
+
7
+ - Euron Code now keeps itself up to date. When a newer release is out (checked at most every 6 hours), `euron`
8
+ installs it into the same Python it runs from (venv, pipx, user or system install) and starts your command
9
+ again on it, so you carry on without doing anything. When Euron's servers ask for a newer version mid-session,
10
+ it updates and continues the conversation. If the update cannot run (offline, no permission) you stay on your
11
+ version with one line saying how to update. Turn it off with `euron config set autoUpdate false` or
12
+ `EURON_NO_AUTO_UPDATE=1`.
13
+
14
+ - Pasting several lines (a spec, a list, a SQL `CREATE TABLE`) sends them as ONE message. Before, the Windows
15
+ console (cmd, PowerShell) and Git Bash sent every line as its own task. Works in the normal prompt and the
16
+ simple one (Git Bash, IDE consoles), on Windows, macOS and Linux. Lines you type one by one stay separate
17
+ messages.
18
+ - Output never stops on a character your terminal cannot show (an ASCII-only locale now writes UTF-8), and
19
+ Python scripts Euron Code runs for you print UTF-8 too.
20
+ - A failed command's hint no longer breaks if Euron Code is updated while a session runs ("No module named
21
+ 'euron_code.error_hints'").
22
+ - Edits: when the text to replace is not in the file, a small file comes back with the error, so the next try
23
+ uses the real text instead of another read. The agent is told more firmly to read a file before editing it
24
+ and never to type the text to replace from memory.
25
+
3
26
  ## 1.5.5 (2026-11-11)
4
27
 
5
28
  Fixes for errors people met this week.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: euron-code
3
- Version: 1.5.5
3
+ Version: 1.5.6
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.5.5"
7
+ version = "1.5.6"
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.5.5"
3
+ __version__ = "1.5.6"
@@ -0,0 +1,334 @@
1
+ """Euron Code keeps itself up to date (1.5.6).
2
+
3
+ In the 4-11 Nov 2026 audit 72% of tasks ran on versions older than 1.5, so fixes did not reach most people. From
4
+ 1.5.6, every start checks PyPI (cached for CHECK_EVERY_S) and, when a newer release exists, upgrades the same
5
+ installation that is running (the Python in sys.executable: a venv, a pipx venv, the user site or the system
6
+ site) and starts the same command again, so the session simply continues on the new version. The server's
7
+ `client_update_required` answer triggers the same upgrade straight away.
8
+
9
+ Never blocks: no network, a read-only install or a failing pip leaves the current version running with one line
10
+ saying how to update. Off with EURON_NO_AUTO_UPDATE=1 (or `euron config set autoUpdate false`), and never in a
11
+ source checkout / editable install, where pip would replace the developer's code.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ import os
18
+ import site
19
+ import subprocess
20
+ import sys
21
+ from pathlib import Path
22
+ from typing import Callable, List, Optional
23
+
24
+ from euron_code import __version__, update_check
25
+
26
+ ENV_DONE = "EURON_AUTO_UPDATED" # set on the relaunched process: never update twice in a row
27
+ ENV_OFF = "EURON_NO_AUTO_UPDATE"
28
+ PIP_TIMEOUT_S = 240
29
+ NO_UPDATE_COMMANDS = {"version", "fix-path", "config", "doctor", "logout", "cache"}
30
+
31
+ _relaunch: Optional[List[str]] = None # argv to start again with, after an upgrade during the run
32
+
33
+
34
+ def disabled(env=None) -> Optional[str]:
35
+ """Why auto-update is off here, or None."""
36
+ env = os.environ if env is None else env
37
+ if env.get(ENV_OFF) or env.get("EURON_NO_UPDATE_CHECK"):
38
+ return "turned off"
39
+ if env.get(ENV_DONE):
40
+ return "just updated"
41
+ try:
42
+ from euron_code import config
43
+ if str(config.load_user_settings().get("autoUpdate", True)).lower() in ("false", "0", "off", "no"):
44
+ return "turned off"
45
+ except Exception:
46
+ pass
47
+ if is_dev_install():
48
+ return "source install"
49
+ return None
50
+
51
+
52
+ def is_dev_install() -> bool:
53
+ """Running from a git checkout or an editable install (pip -e): never pip over it."""
54
+ pkg = Path(__file__).resolve().parent
55
+ if (pkg.parent.parent / ".git").exists() or (pkg.parent.parent / "pyproject.toml").exists():
56
+ return True
57
+ try:
58
+ from importlib import metadata
59
+ dist = metadata.distribution("euron-code")
60
+ direct = dist.read_text("direct_url.json")
61
+ if direct and json.loads(direct).get("dir_info", {}).get("editable"):
62
+ return True
63
+ except Exception:
64
+ return False
65
+ return False
66
+
67
+
68
+ def install_kind() -> str:
69
+ """How the running copy was installed: pipx, venv, user or system."""
70
+ prefix = str(Path(sys.prefix).resolve()).replace("\\", "/").lower()
71
+ if "/pipx/venvs/" in prefix:
72
+ return "pipx"
73
+ if sys.prefix != getattr(sys, "base_prefix", sys.prefix):
74
+ return "venv"
75
+ try:
76
+ user_site = str(Path(site.getusersitepackages()).resolve()).lower()
77
+ here = str(Path(__file__).resolve()).lower()
78
+ if here.startswith(user_site):
79
+ return "user"
80
+ except Exception:
81
+ pass
82
+ return "system"
83
+
84
+
85
+ def pip_command(version: str, kind: Optional[str] = None) -> List[str]:
86
+ kind = kind or install_kind()
87
+ cmd = [sys.executable, "-m", "pip", "install", "--upgrade", "--disable-pip-version-check", "--no-input",
88
+ "--quiet", f"euron-code=={version}"]
89
+ if kind == "user":
90
+ cmd.insert(4, "--user")
91
+ return cmd
92
+
93
+
94
+ def _run(cmd: List[str]) -> subprocess.CompletedProcess:
95
+ env = dict(os.environ, PIP_DISABLE_PIP_VERSION_CHECK="1", PYTHONIOENCODING="utf-8")
96
+ return subprocess.run(cmd, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
97
+ timeout=PIP_TIMEOUT_S, env=env)
98
+
99
+
100
+ def upgrade(version: str, say: Callable[[str], None], run=None) -> bool:
101
+ """Install `version` into the running Python. True when it worked."""
102
+ run = run or _run
103
+ from euron_code import version_info
104
+ kind = install_kind()
105
+ out = ""
106
+ if use_swap():
107
+ # Windows: the running euron.exe launcher is locked, and pip, failing to replace it, left the package
108
+ # half uninstalled (seen while testing 1.5.6). Stage the new version and swap only the package.
109
+ ok, out = swap_install(version, run)
110
+ if ok:
111
+ return True
112
+ else:
113
+ tries = [pip_command(version, kind)]
114
+ if kind == "system":
115
+ tries.append(pip_command(version, "user")) # no write access to the system site: the user site
116
+ if kind == "pipx":
117
+ import shutil
118
+ pipx = shutil.which("pipx")
119
+ if pipx:
120
+ tries.insert(0, [pipx, "install", "--force", f"euron-code=={version}"])
121
+ for cmd in tries:
122
+ try:
123
+ r = run(cmd)
124
+ except (OSError, subprocess.SubprocessError) as e:
125
+ out = str(e)
126
+ continue
127
+ out = _text(r.stdout)
128
+ if r.returncode == 0:
129
+ return True
130
+ if not _importable():
131
+ # pip stopped half-way: put the version that was running back, so `euron` still starts next time
132
+ try:
133
+ run(pip_command(__version__, kind) + ["--force-reinstall", "--no-deps"])
134
+ except Exception:
135
+ pass
136
+ why = _reason(out)
137
+ say(f"Could not update Euron Code automatically ({why}); still on {__version__}. "
138
+ f"Update with: {version_info.upgrade_command()}")
139
+ return False
140
+
141
+
142
+ def use_swap() -> bool:
143
+ return os.name == "nt"
144
+
145
+
146
+ def _text(b) -> str:
147
+ return b.decode("utf-8", "replace") if isinstance(b, bytes) else str(b or "")
148
+
149
+
150
+ def _site_dir() -> Path:
151
+ return Path(__file__).resolve().parent.parent
152
+
153
+
154
+ TRASH_PREFIX = ".euron_code-replaced-"
155
+
156
+
157
+ def swap_install(version: str, run=None) -> tuple:
158
+ """Download `version` into a staging folder, then swap the euron_code package and its dist-info in place
159
+ (directories can be renamed while Python runs; the euron.exe launcher, the same for every version, stays),
160
+ then make sure its dependencies are installed. Returns (ok, pip output)."""
161
+ import shutil
162
+ import tempfile
163
+ run = run or _run
164
+ site_dir = _site_dir()
165
+ pkg = site_dir / "euron_code"
166
+ try:
167
+ stage = Path(tempfile.mkdtemp(prefix="euron-update-"))
168
+ except OSError as e:
169
+ return False, str(e)
170
+ try:
171
+ try:
172
+ r = run([sys.executable, "-m", "pip", "install", "--no-deps", "--no-input", "--quiet",
173
+ "--disable-pip-version-check", "--target", str(stage), f"euron-code=={version}"])
174
+ except (OSError, subprocess.SubprocessError) as e:
175
+ return False, str(e)
176
+ if r.returncode != 0:
177
+ return False, _text(r.stdout)
178
+ new_pkg = stage / "euron_code"
179
+ infos = list(stage.glob("euron_code-*.dist-info"))
180
+ if not new_pkg.is_dir() or not infos:
181
+ return False, "pip failed: the downloaded package is incomplete"
182
+ trash = site_dir / f"{TRASH_PREFIX}{os.getpid()}"
183
+ try:
184
+ trash.mkdir(exist_ok=True)
185
+ os.replace(pkg, trash / "euron_code")
186
+ except OSError as e:
187
+ return False, f"permission: {e}"
188
+ try:
189
+ shutil.move(str(new_pkg), str(pkg))
190
+ except OSError as e:
191
+ try:
192
+ if pkg.exists():
193
+ shutil.rmtree(pkg, ignore_errors=True)
194
+ os.replace(trash / "euron_code", pkg) # put the running version back
195
+ except OSError:
196
+ pass
197
+ return False, f"permission: {e}"
198
+ for old in site_dir.glob("euron_code-*.dist-info"):
199
+ try:
200
+ os.replace(old, trash / old.name)
201
+ except OSError:
202
+ pass
203
+ try:
204
+ shutil.move(str(infos[0]), str(site_dir / infos[0].name))
205
+ except OSError:
206
+ pass
207
+ deps = _requirements(site_dir / infos[0].name / "METADATA")
208
+ if deps:
209
+ try:
210
+ run([sys.executable, "-m", "pip", "install", "--no-input", "--quiet", "--disable-pip-version-check",
211
+ *(["--user"] if install_kind() == "user" else []), *deps])
212
+ except Exception:
213
+ pass # the old dependencies usually still fit; the next start tries again
214
+ return True, ""
215
+ finally:
216
+ shutil.rmtree(stage, ignore_errors=True)
217
+
218
+
219
+ def _requirements(metadata: Path) -> List[str]:
220
+ """Requires-Dist lines without an extra marker."""
221
+ out = []
222
+ try:
223
+ for line in metadata.read_text(encoding="utf-8", errors="replace").splitlines():
224
+ if line.startswith("Requires-Dist:") and "extra ==" not in line:
225
+ out.append(line.split(":", 1)[1].split(";")[0].strip())
226
+ except OSError:
227
+ pass
228
+ return [d for d in out if d]
229
+
230
+
231
+ def cleanup_replaced() -> None:
232
+ """Delete the package folders an earlier update swapped out (free once that process ended)."""
233
+ import shutil
234
+ try:
235
+ for d in _site_dir().glob(TRASH_PREFIX + "*"):
236
+ if d.name != f"{TRASH_PREFIX}{os.getpid()}":
237
+ shutil.rmtree(d, ignore_errors=True)
238
+ except OSError:
239
+ pass
240
+
241
+
242
+ def _importable() -> bool:
243
+ try:
244
+ r = subprocess.run([sys.executable, "-c", "import euron_code.cli"], stdin=subprocess.DEVNULL,
245
+ stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=60)
246
+ return r.returncode == 0
247
+ except Exception:
248
+ return True # cannot tell: do not touch the install
249
+
250
+
251
+ def _reason(out: str) -> str:
252
+ low = out.lower()
253
+ if "permission" in low or "access is denied" in low or "errno 13" in low:
254
+ return "no permission to change this Python"
255
+ if "connection" in low or "temporary failure" in low or "getaddrinfo" in low or "timed out" in low \
256
+ or "no matching distribution" in low:
257
+ return "no connection to PyPI"
258
+ if "externally-managed" in low:
259
+ return "this Python is managed by the system"
260
+ return "pip failed"
261
+
262
+
263
+ def relaunch_argv(argv: List[str]) -> List[str]:
264
+ return [sys.executable, "-m", "euron_code", *argv]
265
+
266
+
267
+ def relaunch(argv: List[str], version: str) -> int:
268
+ """Start the same command again on the new version and return its exit code (POSIX: replace this process)."""
269
+ env = dict(os.environ)
270
+ env[ENV_DONE] = version
271
+ env["EURON_RELAUNCHED"] = "1"
272
+ cmd = relaunch_argv(argv)
273
+ sys.stdout.flush()
274
+ sys.stderr.flush()
275
+ if os.name != "nt":
276
+ try:
277
+ os.execve(sys.executable, cmd, env)
278
+ except OSError:
279
+ pass
280
+ # Windows: a process cannot replace itself; the new one shares this console and we wait for it
281
+ try:
282
+ return subprocess.call(cmd, env=env)
283
+ except KeyboardInterrupt:
284
+ return 130
285
+
286
+
287
+ def newer_version(fresh: bool = False) -> Optional[str]:
288
+ try:
289
+ latest = update_check.latest_version(fresh=fresh)
290
+ except Exception:
291
+ return None
292
+ return latest if latest and update_check.is_newer(latest) else None
293
+
294
+
295
+ def at_start(argv: List[str], say: Callable[[str], None]) -> Optional[int]:
296
+ """Called before a run starts. Returns the exit code of the relaunched newer version, or None to go on."""
297
+ if argv and argv[0] in NO_UPDATE_COMMANDS:
298
+ return None
299
+ try:
300
+ cleanup_replaced()
301
+ except Exception:
302
+ pass
303
+ if disabled():
304
+ return None
305
+ latest = newer_version()
306
+ if not latest:
307
+ return None
308
+ say(f"Updating Euron Code {__version__} -> {latest} ...")
309
+ if not upgrade(latest, say):
310
+ return None
311
+ say(f"Euron Code {latest} installed; continuing on it.")
312
+ return relaunch(argv, latest)
313
+
314
+
315
+ def on_update_required(argv: List[str], say: Callable[[str], None]) -> bool:
316
+ """The server refused this version (client_update_required). Upgrade now; True when a relaunch is queued
317
+ (the caller ends the run; main() then starts `argv` on the new version)."""
318
+ global _relaunch
319
+ if os.environ.get(ENV_OFF):
320
+ return False
321
+ latest = newer_version(fresh=True)
322
+ if not latest or os.environ.get(ENV_DONE) == latest:
323
+ return False
324
+ say(f"This version is too old for Euron Code's servers. Updating {__version__} -> {latest} ...")
325
+ if not upgrade(latest, say):
326
+ return False
327
+ _relaunch = list(argv)
328
+ os.environ[ENV_DONE] = latest
329
+ say(f"Euron Code {latest} installed; restarting it to continue.")
330
+ return True
331
+
332
+
333
+ def pending_relaunch() -> Optional[List[str]]:
334
+ return _relaunch
@@ -24,13 +24,16 @@ STARTED = __import__("time").monotonic() # session uptime counts from here
24
24
 
25
25
 
26
26
  def _fix_windows_console() -> None:
27
- """Make sure UTF-8 output does not crash on legacy Windows code pages."""
27
+ """Make sure output never crashes on a character the console's code page lacks (legacy Windows code pages,
28
+ an ASCII-only locale: prod "'ascii' codec can't encode character" while an answer streamed)."""
28
29
  for stream in (sys.stdout, sys.stderr):
29
30
  try:
30
31
  if stream and hasattr(stream, "reconfigure") and (stream.encoding or "").lower() not in ("utf-8", "utf8"):
31
- if not stream.isatty():
32
+ enc = (stream.encoding or "").lower().replace("_", "-")
33
+ if not stream.isatty() or enc in ("ascii", "us-ascii", "ansi-x3.4-1968", "646", ""):
32
34
  # redirected to a file or pipe: write UTF-8. With the legacy code page, Hindi and emoji
33
- # answers came out as "???" (QA 2026-11-05: `euron -p ... > out.txt` lost every character)
35
+ # answers came out as "???" (QA 2026-11-05: `euron -p ... > out.txt` lost every character).
36
+ # An ASCII-only locale (LANG=C, a bare container) on a terminal: terminals speak UTF-8.
34
37
  stream.reconfigure(encoding="utf-8", errors="replace")
35
38
  else:
36
39
  stream.reconfigure(errors="replace")
@@ -143,7 +146,7 @@ def _path_hint(argv: List[str]) -> None:
143
146
  def main(argv: Optional[List[str]] = None, via_module: bool = False) -> int:
144
147
  _fix_windows_console()
145
148
  argv = list(sys.argv[1:] if argv is None else argv)
146
- if via_module:
149
+ if via_module and not os.environ.get("EURON_RELAUNCHED"):
147
150
  _path_hint(argv)
148
151
  try:
149
152
  if argv and argv[0] in ("version", "-v"): # `euron version`: version, Python, newer release on PyPI
@@ -153,7 +156,17 @@ def main(argv: Optional[List[str]] = None, via_module: bool = False) -> int:
153
156
  if argv and argv[0] in SUBCOMMANDS:
154
157
  return run_subcommand(argv[0], sub_parser(argv[0]).parse_args(argv[1:]))
155
158
  args = main_parser().parse_args(argv)
156
- return run_main(args)
159
+ global CURRENT_ARGS
160
+ CURRENT_ARGS = args
161
+ from euron_code import autoupdate
162
+ newer = autoupdate.at_start(argv, _say_stderr) # 1.5.6: a newer release installs itself and runs instead
163
+ if newer is not None:
164
+ return newer
165
+ code = run_main(args)
166
+ again = autoupdate.pending_relaunch() # the server asked for a newer version during the run
167
+ if again is not None:
168
+ return autoupdate.relaunch(again, os.environ.get(autoupdate.ENV_DONE, ""))
169
+ return code
157
170
  except KeyboardInterrupt:
158
171
  print("\nInterrupted.", file=sys.stderr)
159
172
  return EXIT_INT
@@ -186,9 +199,67 @@ def _need_client(ui) -> api.Client:
186
199
  return api.Client(api_key=cred.api_key, base_url=url)
187
200
 
188
201
 
202
+ CURRENT_ARGS: Optional[argparse.Namespace] = None # the options of this run (a relaunch after an update keeps them)
203
+
204
+
205
+ def _say_stderr(msg: str) -> None:
206
+ try:
207
+ print(msg, file=sys.stderr, flush=True)
208
+ except Exception:
209
+ pass
210
+
211
+
212
+ def relaunch_args(prompt: Optional[str] = None, cont: bool = True) -> List[str]:
213
+ """The options of this run, to start it again on a new version (the conversation continues with -c)."""
214
+ a = CURRENT_ARGS
215
+ out: List[str] = []
216
+ if a is not None:
217
+ if a.print_mode:
218
+ out.append("-p")
219
+ if a.output_format != "text":
220
+ out += ["--output-format", a.output_format]
221
+ if a.model:
222
+ out += ["--model", a.model]
223
+ if a.yolo:
224
+ out.append("--yolo")
225
+ if a.permission_mode:
226
+ out += ["--permission-mode", a.permission_mode]
227
+ if a.max_turns:
228
+ out += ["--max-turns", str(a.max_turns)]
229
+ for flag in ("no_budget", "no_reuse", "takeover", "yes", "verbose"):
230
+ if getattr(a, flag, False):
231
+ out.append("--" + flag.replace("_", "-"))
232
+ for d in a.add_dir or []:
233
+ out += ["--add-dir", d]
234
+ if a.allowed_tools:
235
+ out += ["--allowed-tools", a.allowed_tools]
236
+ if a.resume is not None and not cont:
237
+ out += ["--resume", a.resume] if a.resume else ["--resume"]
238
+ if prompt is None:
239
+ prompt = a.prompt
240
+ if cont and "-p" not in out:
241
+ out.append("-c")
242
+ if prompt:
243
+ out.append(prompt)
244
+ return out
245
+
246
+
247
+ def _update_required(e: api.EuronError) -> bool:
248
+ """The server refused this version: install the new one; the run ends and main() starts it again."""
249
+ if e.code != "client_update_required":
250
+ return False
251
+ from euron_code import autoupdate
252
+ try:
253
+ return autoupdate.on_update_required(relaunch_args(cont=False), _say_stderr)
254
+ except Exception:
255
+ return False
256
+
257
+
189
258
  def _report(ui, e: api.EuronError) -> int:
190
259
  from euron_code import errorlog
191
260
  errorlog.report_euron_error(e)
261
+ if _update_required(e):
262
+ return EXIT_ERROR
192
263
  if isinstance(e, api.NotEntitledError):
193
264
  ui.exact(api.NO_PLUS_BYO_MESSAGE)
194
265
  return EXIT_NO_PLUS