euron-code 1.1.2__tar.gz → 1.2.0__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.
- {euron_code-1.1.2 → euron_code-1.2.0}/CHANGELOG.md +24 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/PKG-INFO +18 -3
- {euron_code-1.1.2 → euron_code-1.2.0}/README.md +17 -2
- {euron_code-1.1.2 → euron_code-1.2.0}/pyproject.toml +1 -1
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/__init__.py +1 -1
- euron_code-1.2.0/src/euron_code/__main__.py +7 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/agent.py +75 -29
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/cli.py +25 -3
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/doctor.py +17 -0
- euron_code-1.2.0/src/euron_code/pathfix.py +246 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/prompts.py +16 -3
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/mock_gateway.py +6 -1
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_agent_mock.py +39 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_update_check.py +2 -2
- euron_code-1.2.0/tests/test_v113_fix_path.py +205 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_v11_speed.py +4 -3
- euron_code-1.1.2/src/euron_code/__main__.py +0 -4
- {euron_code-1.1.2 → euron_code-1.2.0}/.gitignore +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/LICENSE +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/activity.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/api.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/attachments.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/auth.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/builtin_skills/build-from-reference/SKILL.md +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/builtin_skills/explain-codebase/SKILL.md +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/builtin_skills/review/SKILL.md +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/builtin_skills/test-writer/SKILL.md +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/cache.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/checkpoints.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/config.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/context.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/contextforge/LICENSE +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/contextforge/__init__.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/contextforge/text.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/contextforge/toolout.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/credentials.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/documents.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/error_hints.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/errorlog.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/frontmatter.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/hooks.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/keys.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/knowledge.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/licensing.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/llm/__init__.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/llm/anthropic.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/llm/base.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/llm/openai_compat.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/llm/setup.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/logo.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/markdown_view.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/memory.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/osscache.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/ossgithub.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/permissions.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/project_setup.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/repl.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/repomap.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/rules.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/security_scan.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/sessions.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/skills.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/textsafe.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/tools/__init__.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/tools/background.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/tools/base.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/tools/db.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/tools/document.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/tools/erie.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/tools/fs.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/tools/ignore.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/tools/normalize.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/tools/oss.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/tools/pathfind.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/tools/reuse.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/tools/search.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/tools/shell.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/tools/skill.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/tools/symbols.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/tools/task.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/tools/todo.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/tools/web.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/transcript.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/trust.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/ui.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/update_check.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/usage_view.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/src/euron_code/version_info.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/conftest.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/fake_providers.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/helpers.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/measure_floor.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/serve_helper.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/sim_long_session.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_api_shell.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_bench.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_cli_e2e.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_context_memory_sessions.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_dashboard_fixes.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_dashboard_fixes_102.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_db.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_erie.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_knowledge_security.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_markdown_view.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_oss_local.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_permissions.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_powershell_exit_codes.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_qa_attach_secrets.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_qa_long_task.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_qa_print_output.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_qa_reuse_unrelated.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_qa_yolo_outside.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_repl.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_reuse_honesty.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_search.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_textsafe.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_tools_fs.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_transcript_ui.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_v111_user_reports.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_v11_byo.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_v11_tool_fixes.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_v2_rules_skills_hooks.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_v2_tokens_shortcuts.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_v2_usage_headers.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_v31_security.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_v3_accounts_value_setup.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_v3_activity.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_v3_attachments.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_v3_context.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_v3_live_repl.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_v3_single_login.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_v4.py +0 -0
- {euron_code-1.1.2 → euron_code-1.2.0}/tests/test_v5.py +0 -0
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.2.0 (2026-11-09)
|
|
4
|
+
|
|
5
|
+
Faster steps on the Euron model: more of every request reuses the prompt the model has already read.
|
|
6
|
+
|
|
7
|
+
- Conversation summaries are asked at the end of the conversation the model already has, with the same
|
|
8
|
+
instructions and tools, so the model reuses what it has already read instead of reading a re-written
|
|
9
|
+
copy of the conversation from scratch. If the model answers with a tool call instead, the old
|
|
10
|
+
summary request is used.
|
|
11
|
+
- The wrap-up step at the time / step budget keeps the tool list (with tool calls switched off), so it
|
|
12
|
+
reuses it too.
|
|
13
|
+
- The system prompt is ordered from most to least stable: the project knowledge block (code map, recent
|
|
14
|
+
work) now comes last, so a new session in the same project starts faster.
|
|
15
|
+
- After an edit, Euron Code runs the tests closest to the change first and the full suite once at the end.
|
|
16
|
+
|
|
17
|
+
## 1.1.3 (2026-11-08)
|
|
18
|
+
|
|
19
|
+
- "'euron' is not recognized" (Windows) or "euron: command not found" right after `pip install euron-code`:
|
|
20
|
+
pip put the `euron` command in a Scripts folder that is not on your PATH. New `python -m euron_code fix-path`
|
|
21
|
+
finds that folder and adds it to your user PATH (Windows; no admin, the system PATH is not touched, safe to
|
|
22
|
+
run twice) or prints the line to add to your shell profile (macOS, Linux). Open a new terminal afterwards.
|
|
23
|
+
- `python -m euron_code` (or `py -m euron_code` on Windows) does everything `euron` does, e.g.
|
|
24
|
+
`python -m euron_code login`, and says once how to fix PATH when `euron` is not on it.
|
|
25
|
+
- `euron doctor` has a PATH check.
|
|
26
|
+
|
|
3
27
|
## 1.1.2 (2026-11-07)
|
|
4
28
|
|
|
5
29
|
- A connection that drops in the middle of an answer ("The response stopped part-way ... WinError 10054") now
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: euron-code
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0
|
|
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>
|
|
@@ -89,6 +89,21 @@ One idea. One prompt. Endless possibilities.
|
|
|
89
89
|
pip install euron-code
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
+
Or let one command install it and put `euron` on your PATH:
|
|
93
|
+
|
|
94
|
+
```powershell
|
|
95
|
+
# Windows PowerShell
|
|
96
|
+
irm https://euron.one/code-agent/install.ps1 | iex
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# macOS / Linux
|
|
101
|
+
curl -fsSL https://euron.one/code-agent/install.sh | sh
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
If the terminal then says `'euron' is not recognized` or `euron: command not found`, run
|
|
105
|
+
`python -m euron_code fix-path` and open a new terminal (see Troubleshooting).
|
|
106
|
+
|
|
92
107
|
**2. Run it in your project folder:**
|
|
93
108
|
|
|
94
109
|
```bash
|
|
@@ -717,7 +732,7 @@ in the editor straight away. Tips:
|
|
|
717
732
|
- On Windows the integrated terminal is PowerShell by default; Euron Code runs commands with
|
|
718
733
|
PowerShell too. To use Git Bash instead: `euron config set shell bash`.
|
|
719
734
|
- If `euron` is not found after `pip install`, the Python `Scripts` folder is not on your PATH.
|
|
720
|
-
|
|
735
|
+
Run `python -m euron_code fix-path` once, then restart VS Code. `python -m euron_code` works meanwhile.
|
|
721
736
|
- Keep your edits saved before asking Euron Code to change the same file.
|
|
722
737
|
|
|
723
738
|
## Troubleshooting
|
|
@@ -741,7 +756,7 @@ number; inside a session use `/version` or `/status`.
|
|
|
741
756
|
| `Cannot reach Euron Code ... WinError 10054` (connection forcibly closed) | your network reset the connection (often a broken IPv6 route, a VPN, a proxy or an antivirus web shield). 1.1.1 and later retry and switch to IPv4 by themselves; you can force it with `EURON_IPV4=1`. If it still fails, allow euron.one in the VPN/antivirus and run `euron doctor` |
|
|
742
757
|
| `pip install -U euron-code` did not change the version | pip updated a different Python. `euron version` prints the exact upgrade command for the Python that runs `euron` |
|
|
743
758
|
| `Client_Requirement_Document.docx looks like a binary file` | fixed in 1.1.1: Word, Excel, PowerPoint and PDF files are read as text |
|
|
744
|
-
| `euron: command not found` |
|
|
759
|
+
| `'euron' is not recognized as the name of a cmdlet` (Windows) or `euron: command not found` | pip put the `euron` command in a Scripts folder that is not on your PATH. Run `python -m euron_code fix-path` (on Windows `py -m euron_code fix-path` works too), then close and reopen the terminal. Right away, `python -m euron_code login` and `python -m euron_code` do everything `euron` does |
|
|
745
760
|
| garbled colours on old Windows consoles | use Windows Terminal or VS Code's terminal |
|
|
746
761
|
|
|
747
762
|
`euron doctor` checks Python, the connection, your login and plan, ripgrep (faster search; optional)
|
|
@@ -23,6 +23,21 @@ One idea. One prompt. Endless possibilities.
|
|
|
23
23
|
pip install euron-code
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
Or let one command install it and put `euron` on your PATH:
|
|
27
|
+
|
|
28
|
+
```powershell
|
|
29
|
+
# Windows PowerShell
|
|
30
|
+
irm https://euron.one/code-agent/install.ps1 | iex
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# macOS / Linux
|
|
35
|
+
curl -fsSL https://euron.one/code-agent/install.sh | sh
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
If the terminal then says `'euron' is not recognized` or `euron: command not found`, run
|
|
39
|
+
`python -m euron_code fix-path` and open a new terminal (see Troubleshooting).
|
|
40
|
+
|
|
26
41
|
**2. Run it in your project folder:**
|
|
27
42
|
|
|
28
43
|
```bash
|
|
@@ -651,7 +666,7 @@ in the editor straight away. Tips:
|
|
|
651
666
|
- On Windows the integrated terminal is PowerShell by default; Euron Code runs commands with
|
|
652
667
|
PowerShell too. To use Git Bash instead: `euron config set shell bash`.
|
|
653
668
|
- If `euron` is not found after `pip install`, the Python `Scripts` folder is not on your PATH.
|
|
654
|
-
|
|
669
|
+
Run `python -m euron_code fix-path` once, then restart VS Code. `python -m euron_code` works meanwhile.
|
|
655
670
|
- Keep your edits saved before asking Euron Code to change the same file.
|
|
656
671
|
|
|
657
672
|
## Troubleshooting
|
|
@@ -675,7 +690,7 @@ number; inside a session use `/version` or `/status`.
|
|
|
675
690
|
| `Cannot reach Euron Code ... WinError 10054` (connection forcibly closed) | your network reset the connection (often a broken IPv6 route, a VPN, a proxy or an antivirus web shield). 1.1.1 and later retry and switch to IPv4 by themselves; you can force it with `EURON_IPV4=1`. If it still fails, allow euron.one in the VPN/antivirus and run `euron doctor` |
|
|
676
691
|
| `pip install -U euron-code` did not change the version | pip updated a different Python. `euron version` prints the exact upgrade command for the Python that runs `euron` |
|
|
677
692
|
| `Client_Requirement_Document.docx looks like a binary file` | fixed in 1.1.1: Word, Excel, PowerPoint and PDF files are read as text |
|
|
678
|
-
| `euron: command not found` |
|
|
693
|
+
| `'euron' is not recognized as the name of a cmdlet` (Windows) or `euron: command not found` | pip put the `euron` command in a Scripts folder that is not on your PATH. Run `python -m euron_code fix-path` (on Windows `py -m euron_code fix-path` works too), then close and reopen the terminal. Right away, `python -m euron_code login` and `python -m euron_code` do everything `euron` does |
|
|
679
694
|
| garbled colours on old Windows consoles | use Windows Terminal or VS Code's terminal |
|
|
680
695
|
|
|
681
696
|
`euron doctor` checks Python, the connection, your login and plan, ripgrep (faster search; optional)
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "euron-code"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.2.0"
|
|
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"
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""`python -m euron_code ...` does everything `euron ...` does. It works even when pip put the `euron` command in
|
|
2
|
+
a folder that is not on PATH ("'euron' is not recognized"); `python -m euron_code fix-path` then fixes PATH."""
|
|
3
|
+
|
|
4
|
+
from euron_code.cli import main
|
|
5
|
+
|
|
6
|
+
if __name__ == "__main__":
|
|
7
|
+
raise SystemExit(main(via_module=True))
|
|
@@ -185,6 +185,7 @@ class Agent:
|
|
|
185
185
|
self.window = int(settings.get("contextWindow") or 32768)
|
|
186
186
|
self.max_output = int(settings.get("maxOutputTokens") or 8192)
|
|
187
187
|
self._effort_once: Optional[str] = None # one request at a different effort (retries)
|
|
188
|
+
self._tool_choice_once: Optional[str] = None # "none" for the wrap-up step (keeps the tool list)
|
|
188
189
|
self._turn_effort: Optional[str] = None # "low" for a simple follow-up like "thanks"
|
|
189
190
|
if is_subagent and subagent_mode == "write":
|
|
190
191
|
self.tools = default_tools(settings, subagents=False)
|
|
@@ -326,11 +327,9 @@ class Agent:
|
|
|
326
327
|
cut = know[:SMALL_KNOWLEDGE_CHARS]
|
|
327
328
|
know = cut[:cut.rfind("\n") if "\n" in cut else len(cut)] + (
|
|
328
329
|
"\n[... more in .euron/knowledge/codemap.md and journal.md; read them when you need it ...]")
|
|
329
|
-
if know:
|
|
330
|
-
mem = (mem + "\n\n" + know) if mem else know
|
|
331
330
|
self.system_parts = {"memory": mem, "rules": rules_text, "skills": skills_text, "knowledge": know}
|
|
332
331
|
return prompts.build_system_prompt(self.root, self.shell_kind, mem, rules_text=rules_text,
|
|
333
|
-
skills_text=skills_text,
|
|
332
|
+
skills_text=skills_text, knowledge_text=know,
|
|
334
333
|
extra_dirs=getattr(self.permissions, "extra_roots", ()),
|
|
335
334
|
test_command=getattr(self, "test_command", None))
|
|
336
335
|
|
|
@@ -695,7 +694,12 @@ class Agent:
|
|
|
695
694
|
self._effort_once = "low"
|
|
696
695
|
saved = self.tool_schemas
|
|
697
696
|
try:
|
|
698
|
-
self.
|
|
697
|
+
if self.uses_euron:
|
|
698
|
+
# same tool list, tool_choice "none": the request keeps the cached prompt prefix (the tool
|
|
699
|
+
# list is rendered first), instead of a cold prefill of the whole conversation
|
|
700
|
+
self._tool_choice_once = "none"
|
|
701
|
+
else:
|
|
702
|
+
self.tool_schemas = []
|
|
699
703
|
resp = self._request()
|
|
700
704
|
except (Interrupted, KeyboardInterrupt):
|
|
701
705
|
self.ui.end_response()
|
|
@@ -705,6 +709,9 @@ class Agent:
|
|
|
705
709
|
return TurnResult(last_text, "error", turns, error=e)
|
|
706
710
|
finally:
|
|
707
711
|
self.tool_schemas = saved
|
|
712
|
+
self._tool_choice_once = None
|
|
713
|
+
if resp.tool_calls: # a wrap-up answers in words; a tool call here is not run
|
|
714
|
+
resp.content = resp.content or "(no summary)"
|
|
708
715
|
self._append({"role": "assistant", "content": resp.content or "(no summary)"})
|
|
709
716
|
if not self.is_subagent:
|
|
710
717
|
self._footer()
|
|
@@ -765,7 +772,7 @@ class Agent:
|
|
|
765
772
|
"model": self.model,
|
|
766
773
|
"messages": self.messages,
|
|
767
774
|
"tools": self.tool_schemas,
|
|
768
|
-
"tool_choice": "auto",
|
|
775
|
+
"tool_choice": getattr(self, "_tool_choice_once", None) or "auto",
|
|
769
776
|
"max_tokens": max_tokens,
|
|
770
777
|
"reasoning_effort": self._next_effort(),
|
|
771
778
|
}
|
|
@@ -1875,6 +1882,9 @@ class Agent:
|
|
|
1875
1882
|
room = self.conversation_room()
|
|
1876
1883
|
target = self.floor_tokens() + int(AFTER_SUMMARY_MAX * room)
|
|
1877
1884
|
before = self.context_usage()
|
|
1885
|
+
# the conversation as the model last saw it, before stage 1 edits old tool outputs in place:
|
|
1886
|
+
# a summary asked at its end reuses the GPU prefix cache (stage 1 replaces messages by index)
|
|
1887
|
+
sent = list(self.messages)
|
|
1878
1888
|
# stage 1: drop bulky old tool outputs
|
|
1879
1889
|
if not manual:
|
|
1880
1890
|
cf_saved, cf_ids = context.condense_history(self.messages, protect_steps=1)
|
|
@@ -1904,37 +1914,37 @@ class Agent:
|
|
|
1904
1914
|
return False
|
|
1905
1915
|
old = self.messages[1:cut]
|
|
1906
1916
|
recent = self.messages[cut:]
|
|
1907
|
-
transcript = context.render_transcript(old)
|
|
1908
|
-
max_in_chars = int((self.window - 3000) * context.CHARS_PER_TOKEN * 0.8)
|
|
1909
|
-
if len(transcript) > max_in_chars:
|
|
1910
|
-
transcript = transcript[-max_in_chars:]
|
|
1911
|
-
ask = "Summarise this conversation so far.\n\n<transcript>\n" + transcript + "\n</transcript>"
|
|
1912
|
-
if instructions:
|
|
1913
|
-
ask += f"\n\nExtra instructions from the user for the summary: {instructions}"
|
|
1914
1917
|
# no thinking for a summary (the gateway turns it off for "none"), and a summary that is budgeted to
|
|
1915
1918
|
# fit: summary + kept tail + notes stay under AFTER_SUMMARY_MAX of the room
|
|
1916
1919
|
summary_cap = max(300, min(SUMMARY_MAX_TOKENS, int(0.15 * room)))
|
|
1917
|
-
|
|
1918
|
-
|
|
1920
|
+
payloads = [p for p in (self._cached_summary_payload(sent, cut, summary_cap, instructions),
|
|
1921
|
+
self._transcript_summary_payload(old, summary_cap, instructions)) if p]
|
|
1919
1922
|
self.ui.begin_response()
|
|
1920
1923
|
self._phase("compacting the conversation")
|
|
1921
1924
|
self.ui.waiting("Compacting conversation...")
|
|
1922
|
-
try:
|
|
1923
|
-
data = self._with_retries(lambda: self.llm.chat(payload), allow_compact=False)
|
|
1924
|
-
except EuronError as e:
|
|
1925
|
-
self.ui.end_response()
|
|
1926
|
-
self.ui.warn(f"Could not summarise the conversation ({e.message}); dropped old tool outputs instead.")
|
|
1927
|
-
context.elide_old_tool_outputs(self.messages, keep_last=2, min_chars=300)
|
|
1928
|
-
self._persist_compaction()
|
|
1929
|
-
self._summary_step, self._after_summary = self.steps, self.context_usage() # do not retry at once
|
|
1930
|
-
return False
|
|
1931
|
-
self.ui.end_response()
|
|
1932
|
-
self.tokens.record(data.get("usage"), 0, euron=self.uses_euron)
|
|
1933
1925
|
summary = ""
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1926
|
+
for i, payload in enumerate(payloads):
|
|
1927
|
+
last = i == len(payloads) - 1
|
|
1928
|
+
try:
|
|
1929
|
+
data = self._with_retries(lambda: self.llm.chat(payload), allow_compact=False)
|
|
1930
|
+
except EuronError as e:
|
|
1931
|
+
if not last and not isinstance(e, (api.AuthError, api.NotEntitledError, api.QuotaExceededError)):
|
|
1932
|
+
continue # the prefix-cached form failed (too long, refused): the transcript form next
|
|
1933
|
+
self.ui.end_response()
|
|
1934
|
+
self.ui.warn(f"Could not summarise the conversation ({e.message}); dropped old tool outputs instead.")
|
|
1935
|
+
context.elide_old_tool_outputs(self.messages, keep_last=2, min_chars=300)
|
|
1936
|
+
self._persist_compaction()
|
|
1937
|
+
self._summary_step, self._after_summary = self.steps, self.context_usage() # do not retry at once
|
|
1938
|
+
return False
|
|
1939
|
+
self.tokens.record(data.get("usage"), 0, euron=self.uses_euron)
|
|
1940
|
+
try:
|
|
1941
|
+
summary = (data["choices"][0]["message"].get("content") or "").strip()
|
|
1942
|
+
except (KeyError, IndexError, TypeError):
|
|
1943
|
+
summary = ""
|
|
1944
|
+
if summary and "<tool_call>" not in summary and not _has_tool_calls(data):
|
|
1945
|
+
break
|
|
1946
|
+
summary = "" # it tried to keep working instead of summarising: ask the transcript way
|
|
1947
|
+
self.ui.end_response()
|
|
1938
1948
|
if not summary:
|
|
1939
1949
|
self.ui.warn("The summary came back empty; keeping the conversation as it was.")
|
|
1940
1950
|
return False
|
|
@@ -1989,6 +1999,35 @@ class Agent:
|
|
|
1989
1999
|
self.ui.dim(f"Compacted: {before} -> {after} tokens (estimated).")
|
|
1990
2000
|
return True
|
|
1991
2001
|
|
|
2002
|
+
def _cached_summary_payload(self, sent: List[Dict[str, Any]], cut: int, cap: int,
|
|
2003
|
+
instructions: Optional[str]) -> Optional[Dict[str, Any]]:
|
|
2004
|
+
"""The summary asked at the end of the conversation the model last saw, with the same tools: the
|
|
2005
|
+
request shares its whole prefix with the previous step, so the GPU prefix cache serves it (the
|
|
2006
|
+
gateway keeps earlier steps rendered the same when a user message is added). Euron model only:
|
|
2007
|
+
another provider is billed per input token either way and may not cache this."""
|
|
2008
|
+
if not self.uses_euron or cut <= 1 or cut > len(sent) or not self.tool_schemas:
|
|
2009
|
+
return None
|
|
2010
|
+
ask = prompts.COMPACT_ASK
|
|
2011
|
+
if instructions:
|
|
2012
|
+
ask += f"\n\nExtra instructions from the user for the summary: {instructions}"
|
|
2013
|
+
msgs = sent[:cut] + [{"role": "user", "content": ask}]
|
|
2014
|
+
if context.estimate_tokens(msgs, self.tool_schemas) + cap > int(self.window * 0.9):
|
|
2015
|
+
return None
|
|
2016
|
+
return {"model": self.model, "max_tokens": cap, "reasoning_effort": "none", "messages": msgs,
|
|
2017
|
+
"tools": self.tool_schemas, "tool_choice": "none"}
|
|
2018
|
+
|
|
2019
|
+
def _transcript_summary_payload(self, old: List[Dict[str, Any]], cap: int,
|
|
2020
|
+
instructions: Optional[str]) -> Dict[str, Any]:
|
|
2021
|
+
transcript = context.render_transcript(old)
|
|
2022
|
+
max_in_chars = int((self.window - 3000) * context.CHARS_PER_TOKEN * 0.8)
|
|
2023
|
+
if len(transcript) > max_in_chars:
|
|
2024
|
+
transcript = transcript[-max_in_chars:]
|
|
2025
|
+
ask = "Summarise this conversation so far.\n\n<transcript>\n" + transcript + "\n</transcript>"
|
|
2026
|
+
if instructions:
|
|
2027
|
+
ask += f"\n\nExtra instructions from the user for the summary: {instructions}"
|
|
2028
|
+
return {"model": self.model, "max_tokens": cap, "reasoning_effort": "none",
|
|
2029
|
+
"messages": [{"role": "system", "content": prompts.COMPACT}, {"role": "user", "content": ask}]}
|
|
2030
|
+
|
|
1992
2031
|
def _persist_compaction(self) -> None:
|
|
1993
2032
|
self.tokens.reset_anchor() # earlier messages changed: the server count no longer applies
|
|
1994
2033
|
if self.session is not None:
|
|
@@ -2302,6 +2341,13 @@ def _friendly_os_error(tool: str, e: BaseException) -> str:
|
|
|
2302
2341
|
return f"Error: {tool} failed: {type(e).__name__}: {e}"
|
|
2303
2342
|
|
|
2304
2343
|
|
|
2344
|
+
def _has_tool_calls(data: Dict[str, Any]) -> bool:
|
|
2345
|
+
try:
|
|
2346
|
+
return bool(data["choices"][0]["message"].get("tool_calls"))
|
|
2347
|
+
except (KeyError, IndexError, TypeError, AttributeError):
|
|
2348
|
+
return False
|
|
2349
|
+
|
|
2350
|
+
|
|
2305
2351
|
def _cut_kind(resp: "Response") -> Optional[str]:
|
|
2306
2352
|
"""What an answer stopped by the output limit was doing: tool | text | reasoning."""
|
|
2307
2353
|
if resp.tool_calls:
|
|
@@ -18,7 +18,8 @@ from euron_code import __version__, api, auth, config, credentials, llm, session
|
|
|
18
18
|
from euron_code.ui import UI, QuietUI
|
|
19
19
|
|
|
20
20
|
EXIT_OK, EXIT_ERROR, EXIT_USAGE, EXIT_NO_PLUS, EXIT_AUTH, EXIT_QUOTA, EXIT_MAX_TURNS, EXIT_INT = 0, 1, 2, 3, 4, 5, 6, 130
|
|
21
|
-
SUBCOMMANDS = ("login", "logout", "whoami", "usage", "users", "doctor", "config", "init", "trust", "cache", "models", "version"
|
|
21
|
+
SUBCOMMANDS = ("login", "logout", "whoami", "usage", "users", "doctor", "config", "init", "trust", "cache", "models", "version",
|
|
22
|
+
"fix-path")
|
|
22
23
|
STARTED = __import__("time").monotonic() # session uptime counts from here
|
|
23
24
|
|
|
24
25
|
|
|
@@ -52,7 +53,8 @@ def main_parser() -> argparse.ArgumentParser:
|
|
|
52
53
|
p = argparse.ArgumentParser(
|
|
53
54
|
prog="euron",
|
|
54
55
|
description="Euron Code: an AI coding agent in your terminal (Euron Plus and Super 30).",
|
|
55
|
-
epilog="Commands: euron login [--force] | logout | whoami | version | usage | init | doctor |
|
|
56
|
+
epilog="Commands: euron login [--force] | logout | whoami | version | usage | init | doctor | fix-path | "
|
|
57
|
+
"config get|set|unset|list | "
|
|
56
58
|
"cache list|size|clear | models list|add|remove|use. "
|
|
57
59
|
"Run `euron` with no arguments for an interactive session.",
|
|
58
60
|
)
|
|
@@ -120,9 +122,26 @@ def sub_parser(cmd: str) -> argparse.ArgumentParser:
|
|
|
120
122
|
return p
|
|
121
123
|
|
|
122
124
|
|
|
123
|
-
def
|
|
125
|
+
def _path_hint(argv: List[str]) -> None:
|
|
126
|
+
"""Run as `python -m euron_code` because `euron` is not found? Say once per run how to fix that for good."""
|
|
127
|
+
if argv[:1] == ["fix-path"] or "--output-format" in argv:
|
|
128
|
+
return
|
|
129
|
+
try:
|
|
130
|
+
if not sys.stderr.isatty():
|
|
131
|
+
return
|
|
132
|
+
from euron_code import pathfix
|
|
133
|
+
tip = pathfix.hint()
|
|
134
|
+
if tip:
|
|
135
|
+
print(tip, file=sys.stderr)
|
|
136
|
+
except Exception:
|
|
137
|
+
pass
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def main(argv: Optional[List[str]] = None, via_module: bool = False) -> int:
|
|
124
141
|
_fix_windows_console()
|
|
125
142
|
argv = list(sys.argv[1:] if argv is None else argv)
|
|
143
|
+
if via_module:
|
|
144
|
+
_path_hint(argv)
|
|
126
145
|
try:
|
|
127
146
|
if argv and argv[0] in ("version", "-v"): # `euron version`: version, Python, newer release on PyPI
|
|
128
147
|
from euron_code import version_info
|
|
@@ -213,6 +232,9 @@ def run_subcommand(cmd: str, args) -> int:
|
|
|
213
232
|
if cmd == "doctor":
|
|
214
233
|
from euron_code.doctor import doctor
|
|
215
234
|
return doctor(ui)
|
|
235
|
+
if cmd == "fix-path":
|
|
236
|
+
from euron_code import pathfix
|
|
237
|
+
return pathfix.fix_path(out=print)
|
|
216
238
|
if cmd == "config":
|
|
217
239
|
return run_config(ui, args)
|
|
218
240
|
if cmd == "cache":
|
|
@@ -17,6 +17,22 @@ from euron_code.tools.shell import detect_shell
|
|
|
17
17
|
OK, WARN, FAIL = "ok", "warn", "fail"
|
|
18
18
|
|
|
19
19
|
|
|
20
|
+
def path_check() -> Tuple[str, str, str]:
|
|
21
|
+
"""Is the folder with the `euron` command on PATH? ("'euron' is not recognized" after pip install)"""
|
|
22
|
+
try:
|
|
23
|
+
from euron_code import pathfix
|
|
24
|
+
d, here, later = pathfix.status()
|
|
25
|
+
except Exception as e:
|
|
26
|
+
return ("PATH", WARN, f"could not check: {type(e).__name__}")
|
|
27
|
+
if not d:
|
|
28
|
+
return ("PATH", WARN, "the euron command was not found for this Python; `python -m euron_code` works")
|
|
29
|
+
if here:
|
|
30
|
+
return ("PATH", OK, d)
|
|
31
|
+
if later:
|
|
32
|
+
return ("PATH", WARN, f"{d} is on your PATH for new terminals; open a new terminal")
|
|
33
|
+
return ("PATH", WARN, f"{d} is not on PATH, so `euron` is not found. Fix: python -m euron_code fix-path")
|
|
34
|
+
|
|
35
|
+
|
|
20
36
|
def run_checks() -> List[Tuple[str, str, str]]:
|
|
21
37
|
checks: List[Tuple[str, str, str]] = []
|
|
22
38
|
v = sys.version_info
|
|
@@ -24,6 +40,7 @@ def run_checks() -> List[Tuple[str, str, str]]:
|
|
|
24
40
|
f"{platform.python_version()} ({sys.executable})"))
|
|
25
41
|
checks.append(("euron-code", OK, __version__))
|
|
26
42
|
checks.append(("Platform", OK, f"{platform.system()} {platform.release()} {platform.machine()}"))
|
|
43
|
+
checks.append(path_check())
|
|
27
44
|
url = config.base_url()
|
|
28
45
|
if os.environ.get("EURON_CODE_API"): # a developer override; the default is not shown
|
|
29
46
|
checks.append(("API base URL", OK, f"{url} (EURON_CODE_API)"))
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"""`euron fix-path` / `python -m euron_code fix-path`: put the folder that holds the `euron` command on PATH.
|
|
2
|
+
|
|
3
|
+
The most common install problem (support tickets, 2026-11): `pip install euron-code` succeeds, then PowerShell
|
|
4
|
+
says "The term 'euron' is not recognized". pip put `euron.exe` in a Scripts folder that is not on PATH, either
|
|
5
|
+
`%APPDATA%\\Python\\Python3XX\\Scripts` (a user install) or the Microsoft Store Python's
|
|
6
|
+
`...\\LocalCache\\local-packages\\Python3XX\\Scripts`. `python -m euron_code` always works; this module finds that
|
|
7
|
+
folder and adds it to the *user* PATH (never the system PATH, never needs admin). On macOS and Linux it prints
|
|
8
|
+
the line to add to the shell profile instead of editing it.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
import sysconfig
|
|
16
|
+
from typing import Iterable, List, Optional, Tuple
|
|
17
|
+
|
|
18
|
+
COMMAND = "euron"
|
|
19
|
+
DIST = "euron-code"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _norm(p: str) -> str:
|
|
23
|
+
p = os.path.expandvars(os.path.expanduser((p or "").strip().strip('"')))
|
|
24
|
+
return os.path.normcase(os.path.normpath(p)) if p else ""
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _exe_names() -> Tuple[str, ...]:
|
|
28
|
+
return (COMMAND + ".exe", COMMAND) if os.name == "nt" else (COMMAND,)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _has_command(folder: str) -> bool:
|
|
32
|
+
return bool(folder) and any(os.path.isfile(os.path.join(folder, n)) for n in _exe_names())
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _user_scheme() -> str:
|
|
36
|
+
try:
|
|
37
|
+
return sysconfig.get_preferred_scheme("user") # type: ignore[attr-defined] # 3.10+
|
|
38
|
+
except Exception:
|
|
39
|
+
return f"{os.name}_user"
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def candidate_dirs() -> List[str]:
|
|
43
|
+
"""Where pip may have put the `euron` command for the Python that is running, most likely first."""
|
|
44
|
+
out: List[str] = []
|
|
45
|
+
|
|
46
|
+
def add(p: Optional[str]) -> None:
|
|
47
|
+
if p and _norm(p) not in {_norm(x) for x in out}:
|
|
48
|
+
out.append(os.path.normpath(p))
|
|
49
|
+
|
|
50
|
+
for scheme in (None, _user_scheme(), f"{os.name}_user"):
|
|
51
|
+
try:
|
|
52
|
+
add(sysconfig.get_path("scripts") if scheme is None else sysconfig.get_path("scripts", scheme))
|
|
53
|
+
except Exception:
|
|
54
|
+
pass
|
|
55
|
+
try: # what pip recorded at install time, wherever that was
|
|
56
|
+
from importlib import metadata
|
|
57
|
+
for f in metadata.distribution(DIST).files or []:
|
|
58
|
+
if os.path.basename(str(f)).lower() in {n.lower() for n in _exe_names()}:
|
|
59
|
+
add(os.path.dirname(os.path.abspath(str(f.locate()))))
|
|
60
|
+
except Exception:
|
|
61
|
+
pass
|
|
62
|
+
return out
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def scripts_dir() -> Optional[str]:
|
|
66
|
+
"""The folder that actually holds the `euron` command, or None when none of the candidates has it."""
|
|
67
|
+
for d in candidate_dirs():
|
|
68
|
+
if _has_command(d):
|
|
69
|
+
return d
|
|
70
|
+
return None
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _split(path_value: str, sep: str = os.pathsep) -> List[str]:
|
|
74
|
+
return [p for p in (path_value or "").split(sep) if p.strip()]
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _contains(entries: Iterable[str], folder: str) -> bool:
|
|
78
|
+
want = _norm(folder)
|
|
79
|
+
return any(_norm(e) == want for e in entries)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def in_process_path(folder: str) -> bool:
|
|
83
|
+
return _contains(_split(os.environ.get("PATH", "")), folder)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# ---------------------------------------------------------------- Windows registry (user PATH)
|
|
87
|
+
|
|
88
|
+
ENV_KEY = "Environment"
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _winreg():
|
|
92
|
+
import winreg # only on Windows; tests pass a fake
|
|
93
|
+
return winreg
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def read_user_path(winreg=None) -> Tuple[str, Optional[int]]:
|
|
97
|
+
"""The user PATH from HKCU\\Environment as (value, registry type); ("", None) when there is none."""
|
|
98
|
+
winreg = winreg or _winreg()
|
|
99
|
+
try:
|
|
100
|
+
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, ENV_KEY, 0, winreg.KEY_READ) as k:
|
|
101
|
+
value, kind = winreg.QueryValueEx(k, "Path")
|
|
102
|
+
return str(value or ""), kind
|
|
103
|
+
except FileNotFoundError:
|
|
104
|
+
return "", None
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def in_user_path(folder: str, winreg=None) -> bool:
|
|
108
|
+
try:
|
|
109
|
+
return _contains(_split(read_user_path(winreg)[0], ";"), folder)
|
|
110
|
+
except Exception:
|
|
111
|
+
return False
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
SYSTEM_ENV_KEY = r"SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def in_system_path(folder: str, winreg=None) -> bool:
|
|
118
|
+
"""Read-only check of the machine PATH (an all-users Python install puts Scripts there)."""
|
|
119
|
+
try:
|
|
120
|
+
winreg = winreg or _winreg()
|
|
121
|
+
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, SYSTEM_ENV_KEY, 0, winreg.KEY_READ) as k:
|
|
122
|
+
return _contains(_split(str(winreg.QueryValueEx(k, "Path")[0] or ""), ";"), folder)
|
|
123
|
+
except Exception:
|
|
124
|
+
return False
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def add_to_user_path(folder: str, winreg=None) -> bool:
|
|
128
|
+
"""Append `folder` to the user PATH in HKCU\\Environment. Returns False when it was already there.
|
|
129
|
+
|
|
130
|
+
Reads and writes the registry directly: `setx PATH` cuts the value at 1024 characters and mixes the system
|
|
131
|
+
PATH into the user one. The existing value type is kept (REG_EXPAND_SZ keeps %VARIABLES% working).
|
|
132
|
+
"""
|
|
133
|
+
winreg = winreg or _winreg()
|
|
134
|
+
current, kind = read_user_path(winreg)
|
|
135
|
+
entries = _split(current, ";") # the registry value is ";"-separated, whatever os.pathsep says
|
|
136
|
+
if _contains(entries, folder):
|
|
137
|
+
return False
|
|
138
|
+
new_value = ";".join(entries + [folder])
|
|
139
|
+
with winreg.CreateKeyEx(winreg.HKEY_CURRENT_USER, ENV_KEY, 0, winreg.KEY_SET_VALUE) as k:
|
|
140
|
+
winreg.SetValueEx(k, "Path", 0, kind if kind is not None else winreg.REG_EXPAND_SZ, new_value)
|
|
141
|
+
return True
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def broadcast_environment_change() -> None:
|
|
145
|
+
"""Tell Explorer (and terminals started from it) that the environment changed, as the Settings app does."""
|
|
146
|
+
try:
|
|
147
|
+
import ctypes
|
|
148
|
+
from ctypes import wintypes
|
|
149
|
+
result = wintypes.DWORD()
|
|
150
|
+
ctypes.windll.user32.SendMessageTimeoutW(0xFFFF, 0x001A, 0, "Environment", 0x0002, 5000,
|
|
151
|
+
ctypes.byref(result))
|
|
152
|
+
except Exception:
|
|
153
|
+
pass
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
# ---------------------------------------------------------------- what to tell the user
|
|
157
|
+
|
|
158
|
+
def _python_cmd() -> str:
|
|
159
|
+
"""The other usual name of Python: the Windows launcher `py`, or `python3` on macOS and Linux."""
|
|
160
|
+
return "py" if os.name == "nt" else "python3"
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def _is_windows() -> bool:
|
|
164
|
+
return os.name == "nt"
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _in_venv() -> bool:
|
|
168
|
+
return getattr(sys, "base_prefix", sys.prefix) != sys.prefix
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def shell_profile() -> Tuple[str, str]:
|
|
172
|
+
"""(profile file, line format) for the user's shell on macOS / Linux."""
|
|
173
|
+
shell = os.path.basename(os.environ.get("SHELL", ""))
|
|
174
|
+
if shell == "fish":
|
|
175
|
+
return "~/.config/fish/config.fish", "fish_add_path {dir}"
|
|
176
|
+
if shell == "zsh":
|
|
177
|
+
return "~/.zshrc", 'export PATH="{dir}:$PATH"'
|
|
178
|
+
if shell == "bash" and sys.platform == "darwin":
|
|
179
|
+
return "~/.bash_profile", 'export PATH="{dir}:$PATH"'
|
|
180
|
+
return ("~/.bashrc" if shell == "bash" else "~/.profile"), 'export PATH="{dir}:$PATH"'
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def status() -> Tuple[Optional[str], bool, bool]:
|
|
184
|
+
"""(scripts dir or None, on PATH in this terminal, on PATH for new terminals)."""
|
|
185
|
+
d = scripts_dir()
|
|
186
|
+
if not d:
|
|
187
|
+
return None, False, False
|
|
188
|
+
here = in_process_path(d)
|
|
189
|
+
later = here or (os.name == "nt" and (in_user_path(d) or in_system_path(d)))
|
|
190
|
+
return d, here, later
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def hint() -> Optional[str]:
|
|
194
|
+
"""One line for `python -m euron_code` when the `euron` command is not on PATH yet, else None."""
|
|
195
|
+
try:
|
|
196
|
+
d, here, later = status()
|
|
197
|
+
except Exception:
|
|
198
|
+
return None
|
|
199
|
+
if not d or here:
|
|
200
|
+
return None
|
|
201
|
+
if later:
|
|
202
|
+
return "Tip: the euron command is set up; open a new terminal to use it."
|
|
203
|
+
return (f"Tip: the euron command is not on your PATH yet. Run `python -m euron_code fix-path` once "
|
|
204
|
+
f"(or `{_python_cmd()} -m euron_code fix-path`) so `euron` works in every terminal.")
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def fix_path(out=print) -> int:
|
|
208
|
+
"""The `fix-path` command. Idempotent: running it twice changes nothing the second time."""
|
|
209
|
+
d = scripts_dir()
|
|
210
|
+
if not d:
|
|
211
|
+
out("Could not find the folder that holds the euron command for this Python "
|
|
212
|
+
f"({sys.executable}).")
|
|
213
|
+
out(f"Reinstall it with: {_python_cmd()} -m pip install --upgrade euron-code")
|
|
214
|
+
out("Until then, `python -m euron_code` works everywhere `euron` does, e.g. `python -m euron_code login`.")
|
|
215
|
+
return 1
|
|
216
|
+
out(f"The euron command is in: {d}")
|
|
217
|
+
if _in_venv():
|
|
218
|
+
out("This Python is a virtual environment: activate it and `euron` is on PATH there. "
|
|
219
|
+
"Nothing was changed.")
|
|
220
|
+
return 0
|
|
221
|
+
if _is_windows():
|
|
222
|
+
try:
|
|
223
|
+
added = False if in_system_path(d) else add_to_user_path(d)
|
|
224
|
+
except Exception as e:
|
|
225
|
+
out(f"Could not update your PATH: {type(e).__name__}: {e}")
|
|
226
|
+
out("Add the folder above yourself: Start > 'Edit environment variables for your account' > Path > "
|
|
227
|
+
"New. Or keep using `python -m euron_code`.")
|
|
228
|
+
return 1
|
|
229
|
+
if not in_process_path(d):
|
|
230
|
+
os.environ["PATH"] = os.environ.get("PATH", "").rstrip(os.pathsep) + os.pathsep + d
|
|
231
|
+
if added:
|
|
232
|
+
broadcast_environment_change()
|
|
233
|
+
out("Added it to your user PATH (no admin needed; the system PATH was not touched).")
|
|
234
|
+
else:
|
|
235
|
+
out("It is already on your PATH. Nothing to change.")
|
|
236
|
+
out("Close this terminal (and VS Code, if you use its terminal), open a new one, then run: euron login")
|
|
237
|
+
return 0
|
|
238
|
+
if in_process_path(d):
|
|
239
|
+
out("It is already on your PATH. Nothing to change. Run: euron login")
|
|
240
|
+
return 0
|
|
241
|
+
profile, fmt = shell_profile()
|
|
242
|
+
line = fmt.format(dir=d)
|
|
243
|
+
out(f"Add this line to {profile}, then open a new terminal:")
|
|
244
|
+
out(f" {line}")
|
|
245
|
+
out(f"For example: echo '{line}' >> {profile}")
|
|
246
|
+
return 0
|