euron-code 1.8.5__tar.gz → 1.8.7__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 (170) hide show
  1. {euron_code-1.8.5 → euron_code-1.8.7}/CHANGELOG.md +21 -0
  2. {euron_code-1.8.5 → euron_code-1.8.7}/PKG-INFO +4 -2
  3. {euron_code-1.8.5 → euron_code-1.8.7}/README.md +3 -1
  4. {euron_code-1.8.5 → euron_code-1.8.7}/pyproject.toml +1 -1
  5. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/__init__.py +1 -1
  6. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/agent.py +72 -11
  7. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/permissions.py +42 -0
  8. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/repl.py +20 -14
  9. euron_code-1.8.7/tests/test_v186_bypass_and_waits.py +223 -0
  10. euron_code-1.8.7/tests/test_v187_sleep_wake.py +57 -0
  11. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v3_live_repl.py +4 -2
  12. {euron_code-1.8.5 → euron_code-1.8.7}/.gitignore +0 -0
  13. {euron_code-1.8.5 → euron_code-1.8.7}/LICENSE +0 -0
  14. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/__main__.py +0 -0
  15. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/activity.py +0 -0
  16. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/api.py +0 -0
  17. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/attachments.py +0 -0
  18. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/auth.py +0 -0
  19. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/autoupdate.py +0 -0
  20. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/builtin_skills/build-from-reference/SKILL.md +0 -0
  21. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/builtin_skills/explain-codebase/SKILL.md +0 -0
  22. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/builtin_skills/review/SKILL.md +0 -0
  23. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/builtin_skills/test-writer/SKILL.md +0 -0
  24. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/cache.py +0 -0
  25. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/checkpoints.py +0 -0
  26. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/cli.py +0 -0
  27. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/codeindex.py +0 -0
  28. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/config.py +0 -0
  29. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/context.py +0 -0
  30. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/contextforge/LICENSE +0 -0
  31. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/contextforge/__init__.py +0 -0
  32. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/contextforge/text.py +0 -0
  33. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/contextforge/toolout.py +0 -0
  34. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/credentials.py +0 -0
  35. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/ctxstats.py +0 -0
  36. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/doctor.py +0 -0
  37. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/documents.py +0 -0
  38. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/dotnet.py +0 -0
  39. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/error_hints.py +0 -0
  40. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/errorlog.py +0 -0
  41. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/failures.py +0 -0
  42. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/friendly.py +0 -0
  43. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/frontmatter.py +0 -0
  44. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/hooks.py +0 -0
  45. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/keys.py +0 -0
  46. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/knowledge.py +0 -0
  47. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/licensing.py +0 -0
  48. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/llm/__init__.py +0 -0
  49. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/llm/anthropic.py +0 -0
  50. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/llm/base.py +0 -0
  51. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/llm/openai_compat.py +0 -0
  52. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/llm/setup.py +0 -0
  53. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/logo.py +0 -0
  54. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/markdown_view.py +0 -0
  55. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/memory.py +0 -0
  56. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/migration.py +0 -0
  57. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/modes.py +0 -0
  58. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/mvc5.py +0 -0
  59. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/osscache.py +0 -0
  60. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/ossgithub.py +0 -0
  61. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/pasteinput.py +0 -0
  62. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/pathfix.py +0 -0
  63. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/progress.py +0 -0
  64. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/project_setup.py +0 -0
  65. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/prompts.py +0 -0
  66. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/repomap.py +0 -0
  67. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/rules.py +0 -0
  68. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/security_scan.py +0 -0
  69. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/sessions.py +0 -0
  70. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/skills.py +0 -0
  71. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/taskstate.py +0 -0
  72. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/textsafe.py +0 -0
  73. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tls.py +0 -0
  74. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/__init__.py +0 -0
  75. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/background.py +0 -0
  76. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/base.py +0 -0
  77. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/db.py +0 -0
  78. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/document.py +0 -0
  79. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/erie.py +0 -0
  80. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/fs.py +0 -0
  81. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/ignore.py +0 -0
  82. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/normalize.py +0 -0
  83. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/oss.py +0 -0
  84. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/pathfind.py +0 -0
  85. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/port.py +0 -0
  86. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/reuse.py +0 -0
  87. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/search.py +0 -0
  88. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/shell.py +0 -0
  89. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/skill.py +0 -0
  90. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/symbols.py +0 -0
  91. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/task.py +0 -0
  92. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/todo.py +0 -0
  93. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/web.py +0 -0
  94. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/tools/websearch.py +0 -0
  95. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/transcript.py +0 -0
  96. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/trust.py +0 -0
  97. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/ui.py +0 -0
  98. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/update_check.py +0 -0
  99. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/usage_view.py +0 -0
  100. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/version_info.py +0 -0
  101. {euron_code-1.8.5 → euron_code-1.8.7}/src/euron_code/webforms.py +0 -0
  102. {euron_code-1.8.5 → euron_code-1.8.7}/tests/conftest.py +0 -0
  103. {euron_code-1.8.5 → euron_code-1.8.7}/tests/fake_providers.py +0 -0
  104. {euron_code-1.8.5 → euron_code-1.8.7}/tests/helpers.py +0 -0
  105. {euron_code-1.8.5 → euron_code-1.8.7}/tests/measure_floor.py +0 -0
  106. {euron_code-1.8.5 → euron_code-1.8.7}/tests/mock_gateway.py +0 -0
  107. {euron_code-1.8.5 → euron_code-1.8.7}/tests/serve_helper.py +0 -0
  108. {euron_code-1.8.5 → euron_code-1.8.7}/tests/sim_long_session.py +0 -0
  109. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_agent_mock.py +0 -0
  110. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_api_shell.py +0 -0
  111. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_bench.py +0 -0
  112. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_bench_harness.py +0 -0
  113. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_cli_e2e.py +0 -0
  114. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_context_memory_sessions.py +0 -0
  115. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_dashboard_fixes.py +0 -0
  116. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_dashboard_fixes_102.py +0 -0
  117. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_db.py +0 -0
  118. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_erie.py +0 -0
  119. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_knowledge_security.py +0 -0
  120. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_markdown_view.py +0 -0
  121. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_oss_local.py +0 -0
  122. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_permissions.py +0 -0
  123. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_powershell_exit_codes.py +0 -0
  124. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_qa_attach_secrets.py +0 -0
  125. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_qa_long_task.py +0 -0
  126. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_qa_print_output.py +0 -0
  127. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_qa_reuse_unrelated.py +0 -0
  128. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_qa_yolo_outside.py +0 -0
  129. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_render_ghost.py +0 -0
  130. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_repl.py +0 -0
  131. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_reuse_honesty.py +0 -0
  132. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_search.py +0 -0
  133. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_textsafe.py +0 -0
  134. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_tools_fs.py +0 -0
  135. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_transcript_ui.py +0 -0
  136. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_update_check.py +0 -0
  137. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v111_user_reports.py +0 -0
  138. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v113_fix_path.py +0 -0
  139. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v11_byo.py +0 -0
  140. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v11_speed.py +0 -0
  141. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v11_tool_fixes.py +0 -0
  142. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v130_cut_writes.py +0 -0
  143. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v130_reliability.py +0 -0
  144. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v140_parity.py +0 -0
  145. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v152_migration.py +0 -0
  146. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v153_user_errors.py +0 -0
  147. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v155_user_errors.py +0 -0
  148. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v156_autoupdate.py +0 -0
  149. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v156_paste_and_edits.py +0 -0
  150. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v157_zero_errors.py +0 -0
  151. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v15_hosted_models.py +0 -0
  152. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v15_reuse_off_subagent_hooks.py +0 -0
  153. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v160_stop_scope_atomic.py +0 -0
  154. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v161_residual_errors.py +0 -0
  155. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v170_v2.py +0 -0
  156. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v180_rescue_research_permissions.py +0 -0
  157. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v181_silent_failures_verified.py +0 -0
  158. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v182_zero_errors.py +0 -0
  159. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v184_selfupdate_pep668.py +0 -0
  160. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v2_rules_skills_hooks.py +0 -0
  161. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v2_tokens_shortcuts.py +0 -0
  162. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v2_usage_headers.py +0 -0
  163. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v31_security.py +0 -0
  164. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v3_accounts_value_setup.py +0 -0
  165. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v3_activity.py +0 -0
  166. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v3_attachments.py +0 -0
  167. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v3_context.py +0 -0
  168. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v3_single_login.py +0 -0
  169. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v4.py +0 -0
  170. {euron_code-1.8.5 → euron_code-1.8.7}/tests/test_v5.py +0 -0
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.8.7 (2026-11-19)
4
+
5
+ - **A laptop that slept with a request open no longer ends the turn.** After waking, the first network error used
6
+ to stop the turn with "The Euron model has not answered for 27m 11s (1 tries)", because the sleep counted as
7
+ waiting. A request that was open for 5 minutes or more now restarts the retry clock, the line says "This computer
8
+ was asleep or offline for a while; reconnecting." and Euron Code reconnects and continues the turn.
9
+ - **"Busy" waits name the right cause.** When your account already has a request running (another Euron Code window,
10
+ or a sub-agent), the wait line says so instead of "your previous request is still finishing".
11
+
12
+ ## 1.8.6 (2026-11-17)
13
+
14
+ - **`--dangerously-skip-permissions` stays on for the whole session, sub-agents included.** Shift+Tab, `/plan` off
15
+ and accepting a plan used to switch a bypass session back to "default" (or "accept edits"), and from then on
16
+ every edit asked, the sub-agents' edits too. Now Shift+Tab switches between bypass and plan only, leaving plan
17
+ mode goes back to bypass, and "(a)" after a plan means "go without asking". `/permissions mode default` still
18
+ turns bypass off when you want that. Paths outside the project and destructive commands still ask, as before.
19
+ - **Long waits for the model say what is happening.** The live line shows how long the current request has waited,
20
+ which try it is and the time in all ("waiting for the model 3m 12s, try 2, 5m 40s in all"), and after 2 and 5
21
+ minutes a line says the model is slow, that Esc stops and that your message is kept for /retry. Retries of one
22
+ request now stop after 10 minutes in all (before, waiting in a long queue could go on for much longer).
23
+
3
24
  ## 1.8.5 (2026-11-16)
4
25
 
5
26
  - **The input box no longer jumps down and leaves copies of itself behind.** In Windows Terminal, VS Code and other
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: euron-code
3
- Version: 1.8.5
3
+ Version: 1.8.7
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>
@@ -337,7 +337,9 @@ how full the context is, what is left today and this week, and how long the sess
337
337
  | plan | Shift+Tab twice, `/plan` | read-only; it proposes a plan, you decide when it may act |
338
338
  | bypass | `euron --dangerously-skip-permissions` (or `--permission-mode bypassPermissions`, `--yolo`) | nothing asks. Only in a throwaway folder or container. Paths outside the project still ask |
339
339
 
340
- Shift+Tab cycles default -> acceptEdits -> plan, and reaches bypass only if you started with it.
340
+ Shift+Tab cycles default -> acceptEdits -> plan. In a session started with bypass it switches between bypass and
341
+ plan only, and leaving plan mode (Shift+Tab, `/plan`, accepting a plan with `a`) goes back to bypass, sub-agents
342
+ included. `/permissions mode default` turns bypass off when you want edits to ask again.
341
343
  `--add-dir ../shared` lets it also work in another folder.
342
344
 
343
345
  ## Your code and your account
@@ -270,7 +270,9 @@ how full the context is, what is left today and this week, and how long the sess
270
270
  | plan | Shift+Tab twice, `/plan` | read-only; it proposes a plan, you decide when it may act |
271
271
  | bypass | `euron --dangerously-skip-permissions` (or `--permission-mode bypassPermissions`, `--yolo`) | nothing asks. Only in a throwaway folder or container. Paths outside the project still ask |
272
272
 
273
- Shift+Tab cycles default -> acceptEdits -> plan, and reaches bypass only if you started with it.
273
+ Shift+Tab cycles default -> acceptEdits -> plan. In a session started with bypass it switches between bypass and
274
+ plan only, and leaving plan mode (Shift+Tab, `/plan`, accepting a plan with `a`) goes back to bypass, sub-agents
275
+ included. `/permissions mode default` turns bypass off when you want edits to ask again.
274
276
  `--add-dir ../shared` lets it also work in another folder.
275
277
 
276
278
  ## Your code and your account
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "euron-code"
7
- version = "1.8.5"
7
+ version = "1.8.7"
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.5"
3
+ __version__ = "1.8.7"
@@ -20,7 +20,7 @@ from pathlib import Path
20
20
  from typing import Any, Callable, Dict, List, Optional, Tuple
21
21
 
22
22
  from euron_code import api, context, failures, licensing, memory, modes, progress, prompts, rules, skills, taskstate
23
- from euron_code.activity import Activity, phase_from_comment, tool_label
23
+ from euron_code.activity import Activity, fmt_elapsed, phase_from_comment, tool_label
24
24
  from euron_code.api import (BusyError, ContextTooLongError, EuronError, Interrupted, MidStreamError,
25
25
  NetworkError, RateLimitedError)
26
26
  from euron_code.checkpoints import Checkpoints
@@ -41,6 +41,17 @@ MIDSTREAM_BACKOFF = [1, 2, 4, 8, 15, 30] # automatic retries after a stream dro
41
41
  # turn, up to about 10 minutes, instead of failing the request or a sub-agent's task (1.5.7)
42
42
  QUEUE_BACKOFF = [2, 5, 10, 15, 20, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30]
43
43
  QUEUE_CODES = {"user_queue_full", "queue_timeout", "queue_full", "no_capacity"}
44
+ #: 1.8.6: the retries of one request stop after this much wall-clock time, waits AND the requests themselves
45
+ #: (ticket: ~14 minutes of "waiting for the model"; each queued try also waits up to 90 s at the gateway, so the
46
+ #: queue back-off alone could run ~45 minutes, not the "about 10" it promised)
47
+ RETRY_WALL_S = 600.0
48
+ #: 1.8.7: one request that stayed open this long ended because the computer slept (or the network was off), not
49
+ #: because the model did not answer: the gateway cuts a silent upstream at 120 s and a queue wait at 90 s. Prod
50
+ #: 2026-11-18: "The Euron model has not answered for 27m 11s (1 tries)" right after a laptop woke up (the same
51
+ #: second the DNS lookup failed), and the turn stopped. Such a call restarts the wall clock and reconnects.
52
+ SUSPENDED_CALL_S = 300.0
53
+ #: a visible line while one request has waited this long for its first token (seconds)
54
+ STILL_WAITING_AT = (120.0, 300.0)
44
55
  SUBAGENT_RESUMES = 2 # a sub-agent stopped by a busy server or a dropped connection continues this many times
45
56
  MAX_TOOLS_PER_REQUEST = 128 # servers refuse more tool definitions than this in one request
46
57
  #: tools that are never dropped when the list has to be cut to MAX_TOOLS_PER_REQUEST
@@ -1419,7 +1430,31 @@ class Agent:
1419
1430
  dropped = 0
1420
1431
  who = self.model_label
1421
1432
  from euron_code import llm as _llm
1433
+ t0 = time.monotonic()
1434
+ call_t0 = t0
1435
+ tries = 0
1436
+
1437
+ def over_wall(offline: bool = False) -> bool:
1438
+ nonlocal t0, slept
1439
+ if not slept and time.monotonic() - call_t0 >= SUSPENDED_CALL_S:
1440
+ # this one call was open for minutes (a long stream, or the computer slept or went offline):
1441
+ # the time went to that call, not to retries; start counting again
1442
+ slept = True
1443
+ t0 = time.monotonic()
1444
+ if offline:
1445
+ self.ui.dim("This computer was asleep or offline for a while; reconnecting.")
1446
+ return time.monotonic() - t0 >= RETRY_WALL_S
1447
+
1448
+ def gave_up(e: EuronError) -> EuronError:
1449
+ return EuronError(
1450
+ f"The {who} has not answered for {fmt_elapsed(time.monotonic() - t0)} ({tries} tries). Your message "
1451
+ "is kept: send /retry to try again" + (", or switch model with /model." if self.uses_euron else "."),
1452
+ status=e.status, code=e.code)
1453
+ slept = False
1422
1454
  while True:
1455
+ tries += 1
1456
+ self._retry_info = (tries, t0)
1457
+ call_t0 = time.monotonic()
1423
1458
  try:
1424
1459
  return call()
1425
1460
  except _llm.ProviderError:
@@ -1429,6 +1464,8 @@ class Agent:
1429
1464
  # (no tool ran), so ask again, after a short pause.
1430
1465
  if not e.retryable or dropped >= len(MIDSTREAM_BACKOFF):
1431
1466
  raise
1467
+ if over_wall():
1468
+ raise gave_up(e) from None
1432
1469
  wait = MIDSTREAM_BACKOFF[dropped]
1433
1470
  dropped += 1
1434
1471
  # one short status line, no error: the answer is asked for again from the same point
@@ -1455,6 +1492,8 @@ class Agent:
1455
1492
  self._wait(min(float(wait), 120.0), "Rate limit reached (requests per minute)." if self.uses_euron
1456
1493
  else f"{who}: rate limit reached.")
1457
1494
  except BusyError as e:
1495
+ if over_wall():
1496
+ raise gave_up(e) from None
1458
1497
  if str(e.code or "") in QUEUE_CODES:
1459
1498
  # the queue is full or long: wait our turn (a sub-agent's task must not fail on this)
1460
1499
  if queued >= len(QUEUE_BACKOFF):
@@ -1468,7 +1507,7 @@ class Agent:
1468
1507
  if e.retry_after is not None:
1469
1508
  wait = max(wait, min(float(e.retry_after), 60.0))
1470
1509
  queued += 1
1471
- why = {"user_queue_full": "your previous request is still finishing",
1510
+ why = {"user_queue_full": "another request of yours is still running, in another window or a sub-agent",
1472
1511
  "queue_timeout": "the queue is long", "queue_full": "the queue is full",
1473
1512
  "no_capacity": "all servers are in use"}[str(e.code)]
1474
1513
  self._wait(wait, f"The {who} is busy ({why}); waiting for a turn." if self.uses_euron
@@ -1490,7 +1529,7 @@ class Agent:
1490
1529
  wait = max(wait, min(float(e.retry_after), 60.0))
1491
1530
  busy += 1
1492
1531
  why = {"no_capacity": "all servers are in use", "queue_timeout": "the queue is long",
1493
- "user_queue_full": "your previous request is still finishing",
1532
+ "user_queue_full": "another request of yours is still running, in another window or a sub-agent",
1494
1533
  "queue_full": "the queue is full"}.get(str(e.code or ""), "the servers are busy")
1495
1534
  label = f"The {who} is busy ({why})" if self.uses_euron else f"{who} is busy or unreachable"
1496
1535
  self._wait(wait, f"{label}; waiting and trying again (try {busy} of {len(BUSY_BACKOFF)}).")
@@ -1509,9 +1548,11 @@ class Agent:
1509
1548
  self.compact(force=True)
1510
1549
  # each try leaves more room: 65%, 50%, 35%, 30% of the window
1511
1550
  self.fit_to_window(target=max(0.3, FIT_TARGET - 0.15 * compacted))
1512
- except NetworkError:
1551
+ except NetworkError as e:
1513
1552
  if net >= len(NETWORK_BACKOFF):
1514
1553
  raise
1554
+ if over_wall(offline=True):
1555
+ raise gave_up(e) from None
1515
1556
  wait = NETWORK_BACKOFF[net]
1516
1557
  net += 1
1517
1558
  self._wait(wait, "Connection lost, reconnecting.")
@@ -1610,6 +1651,10 @@ class Agent:
1610
1651
 
1611
1652
  def _wait(self, seconds: float, message: str) -> None:
1612
1653
  self.ui.end_response()
1654
+ info = getattr(self, "_retry_info", None)
1655
+ if info is not None and time.monotonic() - info[1] >= 60:
1656
+ # 1.8.6: a long wait says how long it has been, not only the next countdown
1657
+ message = message.rstrip(".") + f" ({fmt_elapsed(time.monotonic() - info[1])} so far)."
1613
1658
  self._phase(f"{message.rstrip('.')} - retrying in {seconds:.0f}s")
1614
1659
  try:
1615
1660
  self.ui.countdown(seconds, message, self.cancel)
@@ -1711,22 +1756,38 @@ class Agent:
1711
1756
  shown = False
1712
1757
  self.ui.begin_response()
1713
1758
  started = time.monotonic()
1759
+ wait_state: Dict[str, Any] = {"base": None, "notes": 0}
1714
1760
 
1715
1761
  def on_wait(comment: Optional[str] = None) -> None:
1716
1762
  if shown:
1717
1763
  return
1718
1764
  phase = phase_from_comment(comment)
1719
1765
  if phase:
1720
- self._phase(phase)
1721
- self.ui.waiting(phase[0].upper() + phase[1:] + " (Esc to cancel)")
1722
- return
1766
+ wait_state["base"] = phase
1723
1767
  waited = time.monotonic() - started
1724
- if waited > 3:
1725
- act = self.activity
1726
- if act is not None and not act.phase.startswith("waiting"):
1727
- act.set_phase("waiting for the model")
1768
+ if not phase and waited <= 3:
1769
+ return
1770
+ # 1.8.6: the live line says how long this request has waited and which try it is
1771
+ # ("waiting for the model 3m 12s, try 2, 5m 40s in all"), not a bare "waiting for the model"
1772
+ tries, t0 = getattr(self, "_retry_info", None) or (1, started)
1773
+ extra = f", try {tries}, {fmt_elapsed(time.monotonic() - t0)} in all" if tries > 1 else ""
1774
+ clock = f" {fmt_elapsed(waited)}" if waited > 3 else ""
1775
+ self._phase(f"{wait_state['base'] or 'waiting for the model'}{clock}{extra}")
1776
+ if phase:
1777
+ self.ui.waiting(phase[0].upper() + phase[1:] + " (Esc to cancel)")
1778
+ else:
1728
1779
  self.ui.waiting(f"Waiting for the {self.model_label}... {waited:.0f}s (queued; Esc to cancel)"
1729
1780
  if self.uses_euron else f"Waiting for {self.model_label}... {waited:.0f}s (Esc to cancel)")
1781
+ n = wait_state["notes"]
1782
+ if n < len(STILL_WAITING_AT) and waited >= STILL_WAITING_AT[n]:
1783
+ wait_state["notes"] = n + 1
1784
+ who = "the " + self.model_label if self.uses_euron else self.model_label
1785
+ note = (f"Still waiting for {who} ({fmt_elapsed(waited)}{extra}): it is slow to answer right now. "
1786
+ "Esc stops; your message is kept and /retry continues it.")
1787
+ try:
1788
+ (self.ui.dim if not self.is_subagent else self.ui.warn)(note)
1789
+ except Exception:
1790
+ pass
1730
1791
 
1731
1792
  interactive = getattr(self.ui, "interactive", False) and not self.is_subagent
1732
1793
  # the live prompt reads the keyboard itself; a second reader would steal keys
@@ -41,6 +41,9 @@ def normalize_mode(mode: Optional[str]) -> str:
41
41
  return m if m in MODES else "default"
42
42
 
43
43
  CYCLE = ("default", "acceptEdits", "plan") # Shift+Tab order
44
+ #: Shift+Tab order in a session started with --dangerously-skip-permissions (1.8.6): bypass <-> plan, so the key
45
+ #: never drops bypass by accident (1.8.5: one press went bypass -> default and every edit asked again)
46
+ BYPASS_CYCLE = ("yolo", "plan")
44
47
 
45
48
  SENSITIVE_PATTERNS = [
46
49
  ".env", ".env.*", "*.pem", "*.key", "id_rsa*", "id_ed25519*", "*.p12", "*.pfx",
@@ -414,9 +417,48 @@ class Permissions:
414
417
  self.deny = list(deny or [])
415
418
  self.session_allow: List[str] = []
416
419
  self.mode = normalize_mode(mode)
420
+ #: started with --dangerously-skip-permissions (or --permission-mode bypassPermissions): set once, for the
421
+ #: whole session. Leaving plan mode (/plan, an accepted plan, Shift+Tab) goes back to bypass, never to
422
+ #: "default" (1.8.6, ticket: every sub-agent edit asked although the session was started in bypass mode).
423
+ self.bypass_session = self.mode == "yolo"
424
+ self._before_plan: Optional[str] = None
417
425
  #: the user's choice: hard asks are asked every time, never remembered (/permissions ask-every-time)
418
426
  self.ask_every_time = bool(ask_every_time)
419
427
 
428
+ # ---------------------------------------------------------- mode changes
429
+ def resting_mode(self) -> str:
430
+ """The mode to return to when plan mode ends without a better answer."""
431
+ return "yolo" if self.bypass_session else "default"
432
+
433
+ def enter_plan(self) -> None:
434
+ if self.mode != "plan":
435
+ self._before_plan = self.mode
436
+ self.mode = "plan"
437
+
438
+ def leave_plan(self, to: Optional[str] = None) -> str:
439
+ """End plan mode: `to` when given, else the mode before plan mode (bypass in a bypass session)."""
440
+ before = self._before_plan
441
+ self._before_plan = None
442
+ if to is None:
443
+ to = before if before and before != "plan" else self.resting_mode()
444
+ self.mode = normalize_mode(to)
445
+ return self.mode
446
+
447
+ def cycle(self) -> str:
448
+ """Shift+Tab: default -> acceptEdits -> plan -> default; in a bypass session bypass <-> plan."""
449
+ if self.bypass_session:
450
+ if self.mode == "plan":
451
+ return self.leave_plan("yolo")
452
+ self.enter_plan()
453
+ return self.mode
454
+ if self.mode == "acceptEdits":
455
+ self.enter_plan()
456
+ return self.mode
457
+ if self.mode == "plan":
458
+ return self.leave_plan("default")
459
+ self.mode = "acceptEdits" if self.mode == "default" else "default"
460
+ return self.mode
461
+
420
462
  def inside(self, path: Path) -> bool:
421
463
  return is_inside(path, self.root) or any(is_inside(path, r) for r in self.extra_roots)
422
464
 
@@ -16,7 +16,6 @@ from rich.markup import escape
16
16
 
17
17
  from euron_code import __version__, api, auth, config, hooks, llm, memory, prompts, repomap, rules, sessions, skills
18
18
  from euron_code.agent import Agent, TurnResult
19
- from euron_code.permissions import CYCLE
20
19
  from euron_code.tools.ignore import ALWAYS_SKIP_DIRS
21
20
  from euron_code.usage_view import (MODE_LABELS, estimate_value, fmt_int, money, reference_label, fmt_uptime, local_when, render_account, render_usage,
22
21
  short, status_line, weekly_limit)
@@ -92,7 +91,7 @@ SHORTCUTS = [
92
91
  ("drag a file", "drop files or images into the terminal to attach them"),
93
92
  ("Ctrl+V", "paste an image from the clipboard (needs Pillow)"),
94
93
  ("# note", "save a note to memory (EURON.md)"),
95
- ("Shift+Tab", "cycle mode: default -> acceptEdits -> plan (-> bypass, if started with it)"),
94
+ ("Shift+Tab", "cycle mode: default -> acceptEdits -> plan (bypass <-> plan, if started with bypass)"),
96
95
  ("Esc Esc", "rewind the last turn (on an empty prompt); clears the line otherwise"),
97
96
  ("Esc / Ctrl-C", "interrupt the running task (queued messages come back to the input line)"),
98
97
  ("typing while busy", "/usage /cost /context /status /model /todos /permissions /help run at once; "
@@ -203,7 +202,7 @@ class Repl:
203
202
  self.session = session
204
203
  self.me_base_tokens = 0
205
204
  self.started = started if started is not None else time.monotonic()
206
- self.bypass_allowed = agent.permissions.mode == "yolo" # Shift+Tab reaches bypass only then
205
+ self.bypass_allowed = agent.permissions.bypass_session # bypass can be (re)entered only then
207
206
  self._prompt = None
208
207
  self._prefill = ""
209
208
  # live mode (prompt_toolkit): one worker thread runs turns and other jobs in order
@@ -279,10 +278,7 @@ class Repl:
279
278
  return estimate_value(t.session_prompt, t.session_completion, t.session_cached, (self.me or {}).get("value"))
280
279
 
281
280
  def cycle_mode(self) -> str:
282
- order = CYCLE + (("yolo",) if self.bypass_allowed else ())
283
- p = self.agent.permissions
284
- p.mode = order[(order.index(p.mode) + 1) % len(order)] if p.mode in order else "default"
285
- return p.mode
281
+ return self.agent.permissions.cycle()
286
282
 
287
283
  def command_table(self) -> Dict[str, str]:
288
284
  table = dict(SLASH_COMMANDS)
@@ -1000,11 +996,14 @@ class Repl:
1000
996
  return None
1001
997
 
1002
998
  def _after_plan(self) -> Optional[int]:
1003
- ans = self.ui.ask_text("Plan mode: (a) accept edits and go, (y) go and ask before each change, "
999
+ p = self.agent.permissions
1000
+ go = "(a) go without asking (bypass)" if p.bypass_session else "(a) accept edits and go"
1001
+ ans = self.ui.ask_text(f"Plan mode: {go}, (y) go and ask before each change, "
1004
1002
  "Enter to keep planning: ").strip().lower()
1005
1003
  if ans in ("a", "y"):
1006
- self.agent.permissions.mode = "acceptEdits" if ans == "a" else "default"
1007
- self.ui.dim(f"Left plan mode (now {self.agent.permissions.mode}).")
1004
+ # (a) in a session started with --dangerously-skip-permissions goes back to bypass (1.8.6)
1005
+ p.leave_plan(("yolo" if p.bypass_session else "acceptEdits") if ans == "a" else "default")
1006
+ self.ui.dim(f"Left plan mode (now {MODE_LABELS.get(p.mode, p.mode)}).")
1008
1007
  return self.turn("The plan is approved. Carry it out now, step by step, and verify the result.")
1009
1008
  return None
1010
1009
 
@@ -1171,9 +1170,13 @@ class Repl:
1171
1170
  return self._trust()
1172
1171
  if cmd == "/plan":
1173
1172
  p = self.agent.permissions
1174
- p.mode = "default" if p.mode == "plan" else "plan"
1175
- self.ui.info(f"Permission mode: {p.mode}" + (" (read-only; the model will propose a plan)"
1176
- if p.mode == "plan" else ""))
1173
+ if p.mode == "plan":
1174
+ p.leave_plan() # back to the mode before plan mode (bypass, if the session started with it)
1175
+ else:
1176
+ p.enter_plan()
1177
+ self._status_cache = (0.0, "")
1178
+ self.ui.info(f"Permission mode: {MODE_LABELS.get(p.mode, p.mode)}"
1179
+ + (" (read-only; the model will propose a plan)" if p.mode == "plan" else ""))
1177
1180
  return None
1178
1181
  if cmd == "/permissions":
1179
1182
  return self._permissions(arg)
@@ -1901,7 +1904,10 @@ class Repl:
1901
1904
  self.ui.warn("Bypass mode can only be used when Euron Code was started with "
1902
1905
  "--dangerously-skip-permissions (or --permission-mode bypassPermissions).")
1903
1906
  return None
1904
- p.mode = want
1907
+ if want == "plan":
1908
+ p.enter_plan()
1909
+ else:
1910
+ p.mode = want
1905
1911
  self._status_cache = (0.0, "")
1906
1912
  when = " (applies from the next tool call)" if self._running else ""
1907
1913
  self.ui.info(f"Permission mode: {MODE_LABELS.get(p.mode, p.mode)}{when}")
@@ -0,0 +1,223 @@
1
+ """1.8.6: a session started with --dangerously-skip-permissions stays in bypass (sub-agents included) after Shift+Tab,
2
+ /plan and an accepted plan; long model waits say how long and which try; one request's retries have a wall clock.
3
+
4
+ Ticket (tabish): "with --dangerously-skip-permissions, sub-agent edits still ask", plus ~14 minutes of
5
+ "waiting for the model" with no feedback. 1.8.5 root cause: Shift+Tab from bypass went to "default" (one press),
6
+ /plan off went to "default", and accepting a plan set "acceptEdits"/"default". Sub-agents share the session's
7
+ Permissions object, so from then on every edit (the sub-agents' too) asked.
8
+ """
9
+
10
+ import time
11
+
12
+ import pytest
13
+
14
+ from euron_code import agent as agent_mod
15
+ from euron_code import api
16
+ from euron_code.activity import Activity
17
+ from euron_code.permissions import Permissions, Request
18
+ from helpers import RecordingUI
19
+ from test_v11_speed import Scripted, _agent
20
+ from test_v2_tokens_shortcuts import AnsweringUI, BUGGY, calc, make_repl # noqa: F401 (calc is a fixture)
21
+
22
+
23
+ def _edit(root, name="a.py"):
24
+ return Request(tool="write_file", category="Edit", paths=[root / name])
25
+
26
+
27
+ # ---------------------------------------------------------------- the mode transitions
28
+
29
+ def test_bypass_session_flag_is_set_by_the_launch_mode(project):
30
+ assert Permissions(project, mode="yolo").bypass_session
31
+ assert Permissions(project, mode="bypassPermissions").bypass_session
32
+ assert not Permissions(project).bypass_session
33
+ assert not Permissions(project, mode="acceptEdits").bypass_session
34
+
35
+
36
+ def test_shift_tab_in_a_bypass_session_toggles_bypass_and_plan_only(project):
37
+ p = Permissions(project, mode="yolo")
38
+ seen = [p.cycle() for _ in range(5)]
39
+ assert seen == ["plan", "yolo", "plan", "yolo", "plan"]
40
+ assert "default" not in seen and "acceptEdits" not in seen
41
+ p.cycle()
42
+ assert p.check(_edit(project)) == "allow"
43
+
44
+
45
+ def test_shift_tab_without_bypass_is_unchanged(project):
46
+ p = Permissions(project)
47
+ assert [p.cycle() for _ in range(4)] == ["acceptEdits", "plan", "default", "acceptEdits"]
48
+ p.mode = "yolo" # never reachable here without the launch flag, but must not stick
49
+ assert p.cycle() == "default"
50
+
51
+
52
+ def test_leaving_plan_returns_to_the_mode_before_it(project):
53
+ p = Permissions(project, mode="yolo")
54
+ p.enter_plan()
55
+ assert p.mode == "plan" and p.check(_edit(project)) == "ask"
56
+ assert p.leave_plan() == "yolo"
57
+ p = Permissions(project, mode="acceptEdits")
58
+ p.enter_plan()
59
+ assert p.leave_plan() == "acceptEdits"
60
+ p = Permissions(project, mode="yolo")
61
+ p.mode = "plan" # plan set directly (old code paths): the bypass session still comes back to bypass
62
+ assert p.leave_plan() == "yolo"
63
+
64
+
65
+ def test_slash_plan_off_returns_to_bypass(project, logged_in, mock_url):
66
+ r, a, ui = make_repl(project, logged_in, mock_url, mode="yolo")
67
+ r.slash("/plan")
68
+ assert a.permissions.mode == "plan"
69
+ r.slash("/plan")
70
+ assert a.permissions.mode == "yolo", "1.8.5 went to 'default' here and every edit asked again"
71
+ assert r.cycle_mode() == "plan" and r.cycle_mode() == "yolo"
72
+
73
+
74
+ def test_permissions_mode_command_still_allows_an_explicit_default(project, logged_in, mock_url):
75
+ r, a, ui = make_repl(project, logged_in, mock_url, mode="yolo")
76
+ r.slash("/permissions mode default")
77
+ assert a.permissions.mode == "default" # the user's explicit choice is honoured
78
+ r.slash("/permissions mode bypassPermissions")
79
+ assert a.permissions.mode == "yolo" # and bypass can be re-entered: the session started with it
80
+
81
+
82
+ def test_accepted_plan_in_a_bypass_session_runs_without_asking(calc, logged_in, mock_url):
83
+ ui = AnsweringUI(["a"], answers=[])
84
+ r, a, _ = make_repl(calc, logged_in, mock_url, ui=ui, mode="yolo")
85
+ a.permissions.enter_plan()
86
+ r.turn("fix the add bug")
87
+ assert a.permissions.mode == "yolo" # (a) after the plan goes back to bypass, not acceptEdits / default
88
+ assert "return a + b" in (calc / "calc.py").read_text()
89
+ assert ui.asked == [], f"bypass session asked: {ui.asked}"
90
+
91
+
92
+ def test_accepted_plan_with_y_asks_before_each_change(calc, logged_in, mock_url):
93
+ ui = AnsweringUI(["y"], answers=["y"] * 5)
94
+ r, a, _ = make_repl(calc, logged_in, mock_url, ui=ui, mode="yolo")
95
+ a.permissions.enter_plan()
96
+ r.turn("fix the add bug")
97
+ assert a.permissions.mode == "default" # "(y) go and ask before each change" is an explicit choice
98
+
99
+
100
+ # ---------------------------------------------------------------- sub-agents honour bypass
101
+
102
+ def _write_subagent_steps():
103
+ return [
104
+ [("task", {"description": "docker", "mode": "write", "paths": ["Dockerfile"], "prompt": "write a Dockerfile"})],
105
+ [("write_file", {"path": "Dockerfile", "content": "FROM python:3.12\n"})],
106
+ "sub done",
107
+ "written",
108
+ ]
109
+
110
+
111
+ @pytest.mark.parametrize("transition", ["none", "shift_tab_twice", "plan_on_off", "after_plan"])
112
+ def test_write_subagent_edits_never_ask_in_a_bypass_session(project, transition):
113
+ llm = Scripted(_write_subagent_steps())
114
+ a = _agent(project, llm) # Permissions(root, mode="yolo"), as --dangerously-skip-permissions builds it
115
+ ui = a.ui
116
+ p = a.permissions
117
+ assert p.bypass_session
118
+ if transition == "shift_tab_twice":
119
+ p.cycle()
120
+ p.cycle()
121
+ elif transition == "plan_on_off":
122
+ p.enter_plan()
123
+ p.leave_plan()
124
+ elif transition == "after_plan":
125
+ p.enter_plan()
126
+ p.leave_plan("yolo")
127
+ res = a.run_turn("add a Dockerfile with a sub-agent")
128
+ assert res.stop_reason == "end_turn"
129
+ assert (project / "Dockerfile").read_text() == "FROM python:3.12\n"
130
+ assert ui.asked == [], f"a sub-agent edit asked in bypass mode: {ui.asked}"
131
+ assert p.mode == "yolo"
132
+
133
+
134
+ def test_write_subagent_edit_asks_once_bypass_was_dropped_by_hand(project):
135
+ """The control: with bypass really off, the sub-agent's edit asks through the main prompt (so the test above
136
+ would catch a regression)."""
137
+ llm = Scripted(_write_subagent_steps())
138
+ a = _agent(project, llm)
139
+ a.ui.answers = ["y"]
140
+ a.permissions.mode = "default"
141
+ a.run_turn("add a Dockerfile with a sub-agent")
142
+ assert any("sub-agent" in q for q in a.ui.asked)
143
+
144
+
145
+ # ---------------------------------------------------------------- long waits are visible
146
+
147
+ class _SlowFirstToken(Scripted):
148
+ """Waits (with keep-alive ticks, like the gateway's `: keep-alive` comments) before the first token."""
149
+
150
+ def __init__(self, steps, wait_s):
151
+ super().__init__(steps)
152
+ self.wait_s = wait_s
153
+
154
+ def stream_chat(self, payload, cancel=None, on_wait=None):
155
+ end = time.monotonic() + self.wait_s
156
+ while time.monotonic() < end:
157
+ if on_wait:
158
+ on_wait("keep-alive")
159
+ time.sleep(0.02)
160
+ yield from super().stream_chat(payload, cancel, on_wait)
161
+
162
+
163
+ class _Activity(Activity):
164
+ """The real live line, recording every phase it was given."""
165
+
166
+ def __init__(self):
167
+ super().__init__(ascii=True)
168
+ self.phases = []
169
+
170
+ def set_phase(self, text):
171
+ super().set_phase(text)
172
+ self.phases.append(text)
173
+
174
+
175
+ def test_waiting_phase_shows_elapsed_time_and_a_note_after_a_long_wait(project, monkeypatch):
176
+ monkeypatch.setattr(agent_mod, "STILL_WAITING_AT", (0.3, 99.0))
177
+ llm = _SlowFirstToken(["hello"], wait_s=4.0)
178
+ a = _agent(project, llm)
179
+ act = _Activity()
180
+ a.ui.activity = act
181
+ res = a.run_turn("hi")
182
+ assert res.stop_reason == "end_turn"
183
+ waits = [ph for ph in act.phases if ph.startswith("waiting for the model")]
184
+ assert waits and any(ph.endswith("s") and ph.split()[-1][0].isdigit() for ph in waits), waits[-3:]
185
+ assert "Still waiting for" in a.ui.text and "/retry" in a.ui.text
186
+
187
+
188
+ def test_retry_try_count_is_in_the_waiting_phase(project, monkeypatch):
189
+ calls = {"n": 0}
190
+ llm = _SlowFirstToken(["hello"], wait_s=3.3)
191
+ real = llm.stream_chat
192
+
193
+ def flaky(payload, cancel=None, on_wait=None):
194
+ calls["n"] += 1
195
+ if calls["n"] == 1:
196
+ raise api.BusyError("busy", status=503, code="upstream_timeout")
197
+ return real(payload, cancel, on_wait)
198
+
199
+ llm.stream_chat = flaky
200
+ a = _agent(project, llm)
201
+ act = _Activity()
202
+ a.ui.activity = act
203
+ a.run_turn("hi")
204
+ assert any(", try 2, " in ph and "in all" in ph for ph in act.phases), act.phases[-5:]
205
+
206
+
207
+ def test_retries_of_one_request_stop_at_the_wall_clock(project, monkeypatch):
208
+ monkeypatch.setattr(agent_mod, "RETRY_WALL_S", 0.5)
209
+ monkeypatch.setattr(agent_mod, "QUEUE_BACKOFF", [0.2] * 50)
210
+ llm = Scripted([])
211
+
212
+ def always_queued(payload, cancel=None, on_wait=None):
213
+ time.sleep(0.15)
214
+ raise api.BusyError("queue", status=503, code="queue_timeout")
215
+ yield # pragma: no cover
216
+
217
+ llm.stream_chat = always_queued
218
+ a = _agent(project, llm)
219
+ t0 = time.monotonic()
220
+ res = a.run_turn("hi")
221
+ took = time.monotonic() - t0
222
+ assert res.error is not None and "/retry" in res.error.message and "tries" in res.error.message
223
+ assert took < 5, f"kept retrying for {took:.1f}s"