euron-code 0.9.0__tar.gz → 1.0.1__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-0.9.0 → euron_code-1.0.1}/CHANGELOG.md +31 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/PKG-INFO +1 -1
- {euron_code-0.9.0 → euron_code-1.0.1}/pyproject.toml +1 -1
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/__init__.py +1 -1
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/agent.py +31 -5
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/api.py +40 -1
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/repl.py +5 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/tools/background.py +22 -2
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/tools/fs.py +179 -8
- euron_code-1.0.1/src/euron_code/tools/normalize.py +122 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/tools/oss.py +12 -3
- euron_code-1.0.1/src/euron_code/tools/pathfind.py +95 -0
- euron_code-1.0.1/src/euron_code/update_check.py +92 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/conftest.py +1 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/mock_gateway.py +36 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_agent_mock.py +20 -0
- euron_code-1.0.1/tests/test_dashboard_fixes.py +170 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_tools_fs.py +151 -143
- euron_code-1.0.1/tests/test_update_check.py +61 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/.gitignore +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/LICENSE +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/README.md +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/__main__.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/activity.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/attachments.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/auth.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/builtin_skills/build-from-reference/SKILL.md +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/builtin_skills/explain-codebase/SKILL.md +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/builtin_skills/review/SKILL.md +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/builtin_skills/test-writer/SKILL.md +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/cache.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/checkpoints.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/cli.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/config.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/context.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/contextforge/LICENSE +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/contextforge/__init__.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/contextforge/text.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/contextforge/toolout.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/credentials.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/doctor.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/documents.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/error_hints.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/errorlog.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/frontmatter.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/hooks.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/keys.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/knowledge.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/licensing.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/logo.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/markdown_view.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/memory.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/osscache.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/ossgithub.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/permissions.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/project_setup.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/prompts.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/repomap.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/rules.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/security_scan.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/sessions.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/skills.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/textsafe.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/tools/__init__.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/tools/base.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/tools/db.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/tools/document.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/tools/erie.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/tools/ignore.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/tools/reuse.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/tools/search.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/tools/shell.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/tools/skill.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/tools/symbols.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/tools/task.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/tools/todo.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/tools/web.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/transcript.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/trust.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/ui.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/src/euron_code/usage_view.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/helpers.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/serve_helper.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_api_shell.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_bench.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_cli_e2e.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_context_memory_sessions.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_db.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_erie.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_knowledge_security.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_markdown_view.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_oss_local.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_permissions.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_powershell_exit_codes.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_qa_attach_secrets.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_qa_long_task.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_qa_print_output.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_qa_reuse_unrelated.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_qa_yolo_outside.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_repl.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_reuse_honesty.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_search.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_textsafe.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_transcript_ui.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_v2_rules_skills_hooks.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_v2_tokens_shortcuts.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_v2_usage_headers.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_v31_security.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_v3_accounts_value_setup.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_v3_activity.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_v3_attachments.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_v3_context.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_v3_live_repl.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_v3_single_login.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_v4.py +0 -0
- {euron_code-0.9.0 → euron_code-1.0.1}/tests/test_v5.py +0 -0
|
@@ -1,5 +1,36 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.0.1 (2026-11-06)
|
|
4
|
+
|
|
5
|
+
- Euron Code tells you when a newer version is out, with the command to upgrade
|
|
6
|
+
(`pip install -U euron-code`). It checks PyPI at most once a day, in the background of start-up, with a
|
|
7
|
+
two-second limit, and says nothing when you are offline or up to date. Turn it off with
|
|
8
|
+
`EURON_NO_UPDATE_CHECK=1`.
|
|
9
|
+
|
|
10
|
+
## 1.0.0 (2026-11-06)
|
|
11
|
+
|
|
12
|
+
Fixes for every failure recorded on the Euron Code error dashboard since launch.
|
|
13
|
+
|
|
14
|
+
- A dropped connection no longer loses your turn. When the connection breaks part-way through an
|
|
15
|
+
answer (seen as "WinError 10054 ... forcibly closed by the remote host"), Euron Code asks again by
|
|
16
|
+
itself, up to three times, because nothing had been applied yet. If the answer had already finished
|
|
17
|
+
when the connection dropped, it is kept instead of thrown away.
|
|
18
|
+
- Edits that differ only in whitespace now apply. When the exact text is not found, Euron Code matches
|
|
19
|
+
it ignoring line numbers copied from read_file, trailing spaces, or indentation, and re-indents the
|
|
20
|
+
new code to the file's style (2 to 4 spaces, tabs). It only does this when there is exactly one
|
|
21
|
+
match, and the result says how it matched.
|
|
22
|
+
- Tool calls with the parameter names other tools use (file_path, old_str, query, ...), lists sent as
|
|
23
|
+
text, or numbers sent as strings are repaired before they run, instead of failing with "Missing
|
|
24
|
+
required parameter".
|
|
25
|
+
- A path that does not exist is resolved when it can mean only one file (app/page.tsx is
|
|
26
|
+
src/app/page.tsx; css/style.css is style.css in a GitHub repo), and otherwise the error lists the
|
|
27
|
+
closest real paths.
|
|
28
|
+
- stop_process accepts "1", "P1", the process number or part of the command.
|
|
29
|
+
- write_file on a file you had not read shows its current content right away, so the next call works.
|
|
30
|
+
- A new terminal on the same computer is no longer told Euron Code "is running in another terminal".
|
|
31
|
+
Euron Code sends an anonymous id for this computer (a random value kept in ~/.euron/device-id); a
|
|
32
|
+
different computer still has to take over.
|
|
33
|
+
|
|
3
34
|
## 0.9.0 (2026-11-06)
|
|
4
35
|
|
|
5
36
|
Every build starts from code that already exists, and the report says what was really reused.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: euron-code
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.1
|
|
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 = "0.
|
|
7
|
+
version = "1.0.1"
|
|
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"
|
|
@@ -35,6 +35,7 @@ BUSY_BACKOFF = [5, 10, 20, 40, 40] # spec §4: 5, 10, 20, 40 s, max 5 tries
|
|
|
35
35
|
RATE_LIMIT_FALLBACK = 20
|
|
36
36
|
MAX_RATE_LIMIT_RETRIES = 5
|
|
37
37
|
NETWORK_BACKOFF = [2, 4, 8]
|
|
38
|
+
MIDSTREAM_BACKOFF = [1, 3, 6] # automatic retries after a stream dropped part-way
|
|
38
39
|
DENIED = "denied"
|
|
39
40
|
EFFORTS = ("low", "medium", "high")
|
|
40
41
|
OUTPUT_FLOOR = 1024 # never ask for fewer output tokens than this
|
|
@@ -623,9 +624,20 @@ class Agent:
|
|
|
623
624
|
net = 0
|
|
624
625
|
compacted = False
|
|
625
626
|
took_over = False
|
|
627
|
+
dropped = 0
|
|
626
628
|
while True:
|
|
627
629
|
try:
|
|
628
630
|
return call()
|
|
631
|
+
except MidStreamError as e:
|
|
632
|
+
# A dropped connection must not cost the user their turn: nothing was applied
|
|
633
|
+
# (no tool ran), so ask again, after a short pause.
|
|
634
|
+
if not e.retryable or dropped >= len(MIDSTREAM_BACKOFF):
|
|
635
|
+
raise
|
|
636
|
+
wait = MIDSTREAM_BACKOFF[dropped]
|
|
637
|
+
dropped += 1
|
|
638
|
+
self.ui.warn("The connection dropped part-way through the answer. Nothing was applied; "
|
|
639
|
+
f"asking again automatically ({dropped}/{len(MIDSTREAM_BACKOFF)}).")
|
|
640
|
+
self._wait(wait, "Reconnecting to Euron Code.")
|
|
629
641
|
except api.SessionInUseError:
|
|
630
642
|
ask = self.on_session_in_use
|
|
631
643
|
if took_over or ask is None or not ask():
|
|
@@ -747,11 +759,20 @@ class Agent:
|
|
|
747
759
|
raise
|
|
748
760
|
except EuronError as e:
|
|
749
761
|
if shown and not isinstance(e, (api.NotEntitledError, api.AuthError, api.QuotaExceededError)):
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
762
|
+
dropped = isinstance(e, NetworkError) or str(e.code or "").startswith("upstream_")
|
|
763
|
+
if dropped and r.finish_reason and r.finish_reason != "length":
|
|
764
|
+
# The model had already finished; only the connection's last bytes were
|
|
765
|
+
# lost (seen in production as WinError 10054 right after the answer). Keep it.
|
|
766
|
+
pass
|
|
767
|
+
else:
|
|
768
|
+
self.ui.end_response()
|
|
769
|
+
err = MidStreamError(
|
|
770
|
+
f"The response stopped part-way ({e.message}). Nothing more was applied. "
|
|
771
|
+
"Send your message again to retry.", status=e.status, code=e.code)
|
|
772
|
+
err.retryable = dropped
|
|
773
|
+
raise err from None
|
|
774
|
+
else:
|
|
775
|
+
raise
|
|
755
776
|
self.ui.end_response()
|
|
756
777
|
r.tool_calls = []
|
|
757
778
|
for idx in sorted(calls):
|
|
@@ -1227,6 +1248,11 @@ class Agent:
|
|
|
1227
1248
|
hint = (" The output limit cut the call off; write smaller pieces (for example several edits)."
|
|
1228
1249
|
if truncated else "")
|
|
1229
1250
|
return f"Error: invalid JSON arguments for {name}: {e}.{hint}", None
|
|
1251
|
+
from euron_code.tools.normalize import normalize_args
|
|
1252
|
+
try:
|
|
1253
|
+
args = normalize_args(args, getattr(tool, "parameters", None))
|
|
1254
|
+
except Exception: # repairing is best effort; the tool still validates
|
|
1255
|
+
pass
|
|
1230
1256
|
try:
|
|
1231
1257
|
summary = tool.describe(args, self.ctx)
|
|
1232
1258
|
except Exception:
|
|
@@ -146,7 +146,13 @@ class NetworkError(EuronError):
|
|
|
146
146
|
|
|
147
147
|
|
|
148
148
|
class MidStreamError(EuronError):
|
|
149
|
-
"""The stream failed after output was already shown.
|
|
149
|
+
"""The stream failed after output was already shown.
|
|
150
|
+
|
|
151
|
+
`retryable`: the connection dropped (or the server cut the stream) before the model
|
|
152
|
+
finished and before any tool ran, so the agent repeats the request by itself.
|
|
153
|
+
"""
|
|
154
|
+
|
|
155
|
+
retryable = False
|
|
150
156
|
|
|
151
157
|
|
|
152
158
|
class Interrupted(Exception):
|
|
@@ -244,6 +250,36 @@ def new_task_id() -> str:
|
|
|
244
250
|
return uuid.uuid4().hex
|
|
245
251
|
|
|
246
252
|
|
|
253
|
+
_DEVICE_ID: Optional[str] = None
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def device_id() -> Optional[str]:
|
|
257
|
+
"""An anonymous, stable id for this computer + OS user (a random UUID kept in ~/.euron/device-id).
|
|
258
|
+
|
|
259
|
+
Sent as X-Euron-Device so a new terminal on the SAME computer takes over the one-login lock without
|
|
260
|
+
"running in another terminal" (the gateway still refuses another computer). Never derived from
|
|
261
|
+
hardware or personal data; deleting the file just makes a new one.
|
|
262
|
+
"""
|
|
263
|
+
global _DEVICE_ID
|
|
264
|
+
if _DEVICE_ID is not None:
|
|
265
|
+
return _DEVICE_ID or None
|
|
266
|
+
value = ""
|
|
267
|
+
try:
|
|
268
|
+
path = config.euron_home() / "device-id"
|
|
269
|
+
try:
|
|
270
|
+
value = path.read_text(encoding="utf-8").strip()
|
|
271
|
+
except OSError:
|
|
272
|
+
value = ""
|
|
273
|
+
if not _ID_RE.match(value or ""):
|
|
274
|
+
value = uuid.uuid4().hex
|
|
275
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
276
|
+
path.write_text(value + "\n", encoding="utf-8")
|
|
277
|
+
except OSError:
|
|
278
|
+
value = value if _ID_RE.match(value or "") else ""
|
|
279
|
+
_DEVICE_ID = value
|
|
280
|
+
return value or None
|
|
281
|
+
|
|
282
|
+
|
|
247
283
|
def user_agent() -> str:
|
|
248
284
|
return f"euron-code/{__version__} ({platform.system()}; Python {platform.python_version()})"
|
|
249
285
|
|
|
@@ -292,6 +328,9 @@ class Client:
|
|
|
292
328
|
h["X-Euron-Session"] = str(self.session_id)
|
|
293
329
|
if valid_id(self.task_id):
|
|
294
330
|
h["X-Euron-Task"] = str(self.task_id)
|
|
331
|
+
dev = device_id()
|
|
332
|
+
if dev:
|
|
333
|
+
h["X-Euron-Device"] = dev
|
|
295
334
|
if self.takeover_once:
|
|
296
335
|
h["X-Euron-Takeover"] = "1"
|
|
297
336
|
return h
|
|
@@ -793,6 +793,11 @@ class Repl:
|
|
|
793
793
|
self.ui.plain(" " + row)
|
|
794
794
|
self.ui.plain("")
|
|
795
795
|
self.ui.info(f"[bold]Euron Code[/bold] {__version__} [dim]{escape(str(self.agent.root))}[/dim]")
|
|
796
|
+
if getattr(self.ui, "interactive", False):
|
|
797
|
+
from euron_code import update_check
|
|
798
|
+
upgrade = update_check.notice()
|
|
799
|
+
if upgrade:
|
|
800
|
+
self.ui.warn(upgrade)
|
|
796
801
|
if self.me:
|
|
797
802
|
access = self.me.get("access") or {}
|
|
798
803
|
q = self.me.get("quota") or {}
|
|
@@ -24,7 +24,7 @@ import threading
|
|
|
24
24
|
import time
|
|
25
25
|
from dataclasses import dataclass, field
|
|
26
26
|
from pathlib import Path
|
|
27
|
-
from typing import Dict, List, Optional
|
|
27
|
+
from typing import Any, Dict, List, Optional
|
|
28
28
|
from urllib.parse import urlparse
|
|
29
29
|
|
|
30
30
|
from euron_code.permissions import Request
|
|
@@ -109,11 +109,31 @@ class ProcessManager:
|
|
|
109
109
|
bp.dropped += cut
|
|
110
110
|
|
|
111
111
|
def get(self, pid: str) -> BgProcess:
|
|
112
|
-
bp = self.
|
|
112
|
+
bp = self.resolve(pid)
|
|
113
113
|
if bp is None:
|
|
114
114
|
raise ToolError(f"No background process {pid!r}. Running: {', '.join(self.procs) or 'none'}.")
|
|
115
115
|
return bp
|
|
116
116
|
|
|
117
|
+
def resolve(self, pid: Any) -> Optional[BgProcess]:
|
|
118
|
+
"""Find a process by its id ("p1"), and also by what models send instead: "1", "P1",
|
|
119
|
+
the OS process id, or a unique part of the command line."""
|
|
120
|
+
key = str(pid if pid is not None else "").strip().strip("'\"`")
|
|
121
|
+
if not key:
|
|
122
|
+
return None
|
|
123
|
+
if key in self.procs:
|
|
124
|
+
return self.procs[key]
|
|
125
|
+
low = key.lower()
|
|
126
|
+
if low in self.procs:
|
|
127
|
+
return self.procs[low]
|
|
128
|
+
if low.isdigit():
|
|
129
|
+
if "p" + low in self.procs:
|
|
130
|
+
return self.procs["p" + low]
|
|
131
|
+
for bp in self.procs.values():
|
|
132
|
+
if str(getattr(bp.proc, "pid", "")) == low:
|
|
133
|
+
return bp
|
|
134
|
+
hits = [bp for bp in self.procs.values() if low in str(getattr(bp, "command", "")).lower()]
|
|
135
|
+
return hits[0] if len(hits) == 1 else None
|
|
136
|
+
|
|
117
137
|
def stop(self, pid: str) -> BgProcess:
|
|
118
138
|
from euron_code.tools.shell import _kill_tree
|
|
119
139
|
bp = self.get(pid)
|
|
@@ -161,8 +161,141 @@ def _near_miss_hint(text: str, old: str) -> str:
|
|
|
161
161
|
return " Re-read the file; it may have changed."
|
|
162
162
|
|
|
163
163
|
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
_GUTTER = re.compile(r"^[ \t]*\d+(?:\t|[ \t]*[|:\u2502][ \t]?)")
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def _strip_gutter(s: str) -> Optional[str]:
|
|
168
|
+
"""old_string copied from read_file output WITH its line numbers (" 12\tcode"): drop them.
|
|
169
|
+
Only when every non-blank line has one, so real code that starts with digits is left alone."""
|
|
170
|
+
lines = s.split("\n")
|
|
171
|
+
body = [ln for ln in lines if ln.strip()]
|
|
172
|
+
if not body or not all(_GUTTER.match(ln) for ln in body):
|
|
173
|
+
return None
|
|
174
|
+
return "\n".join(_GUTTER.sub("", ln, count=1) for ln in lines)
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def _indent(line: str) -> str:
|
|
178
|
+
return line[: len(line) - len(line.lstrip(" \t"))]
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _windows(file_lines: List[str], old_lines: List[str], key) -> List[int]:
|
|
182
|
+
want = [key(x) for x in old_lines]
|
|
183
|
+
n = len(want)
|
|
184
|
+
have = [key(x) for x in file_lines]
|
|
185
|
+
return [i for i in range(len(have) - n + 1) if have[i:i + n] == want]
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def _indent_map(old_lines: List[str], file_lines: List[str]):
|
|
189
|
+
"""Learn how old_string's indentation maps onto the file's from the matched line pairs."""
|
|
190
|
+
pairs = {}
|
|
191
|
+
for o, f in zip(old_lines, file_lines):
|
|
192
|
+
if o.strip():
|
|
193
|
+
pairs.setdefault(_indent(o), _indent(f))
|
|
194
|
+
ratio = 1.0
|
|
195
|
+
keys = sorted(pairs, key=len)
|
|
196
|
+
for k1 in keys:
|
|
197
|
+
for k2 in keys:
|
|
198
|
+
if len(k2) > len(k1):
|
|
199
|
+
ratio = (len(pairs[k2]) - len(pairs[k1])) / (len(k2) - len(k1))
|
|
200
|
+
break
|
|
201
|
+
if ratio != 1.0:
|
|
202
|
+
break
|
|
203
|
+
ch = "\t" if any("\t" in v for v in pairs.values()) else " "
|
|
204
|
+
return pairs, max(ratio, 0.0), ch
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def _reindent(new_lines: List[str], pairs, ratio: float, ch: str) -> List[str]:
|
|
208
|
+
"""Give each new line the file's indentation: the same mapping as old_string's lines where the
|
|
209
|
+
indent is known, otherwise the nearest known level plus the extra depth scaled (2 -> 4 spaces)."""
|
|
210
|
+
if all(k == v for k, v in pairs.items()):
|
|
211
|
+
return new_lines
|
|
212
|
+
out = []
|
|
213
|
+
for ln in new_lines:
|
|
214
|
+
if not ln.strip():
|
|
215
|
+
out.append("")
|
|
216
|
+
continue
|
|
217
|
+
ni = _indent(ln)
|
|
218
|
+
if ni in pairs:
|
|
219
|
+
out.append(pairs[ni] + ln[len(ni):])
|
|
220
|
+
continue
|
|
221
|
+
base = max((k for k in pairs if ni.startswith(k)), key=len, default="")
|
|
222
|
+
extra = len(ni) - len(base)
|
|
223
|
+
if ch == "\t":
|
|
224
|
+
unit = next((len(k2) - len(k1) for k1 in pairs for k2 in pairs if len(k2) > len(k1)), 4) or 4
|
|
225
|
+
add = "\t" * max(1, round(extra / unit)) if extra else ""
|
|
226
|
+
else:
|
|
227
|
+
add = " " * int(round(extra * ratio))
|
|
228
|
+
out.append(pairs.get(base, base) + add + ln[len(ni):])
|
|
229
|
+
return out
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def _fuzzy_replace(text: str, old: str, new: str, replace_all: bool) -> Optional[Tuple[str, int, str]]:
|
|
233
|
+
"""Line-based match that tolerates trailing whitespace, then indentation differences.
|
|
234
|
+
|
|
235
|
+
Returns (new_text, count, how) or None. A tolerant match is used only when it is unique
|
|
236
|
+
(or replace_all is set); the replacement is re-indented to the file's indentation.
|
|
237
|
+
"""
|
|
238
|
+
crlf = "\r\n" in text
|
|
239
|
+
nl = "\r\n" if crlf else "\n"
|
|
240
|
+
file_lines = text.replace("\r\n", "\n").split("\n")
|
|
241
|
+
old_lines = old.replace("\r\n", "\n").split("\n")
|
|
242
|
+
new_lines = new.replace("\r\n", "\n").split("\n")
|
|
243
|
+
while len(old_lines) > 1 and not old_lines[-1].strip(): # a trailing newline in old_string
|
|
244
|
+
old_lines.pop()
|
|
245
|
+
if len(new_lines) > 1 and not new_lines[-1].strip():
|
|
246
|
+
new_lines.pop()
|
|
247
|
+
while len(old_lines) > 1 and not old_lines[0].strip():
|
|
248
|
+
old_lines.pop(0)
|
|
249
|
+
if len(new_lines) > 1 and not new_lines[0].strip():
|
|
250
|
+
new_lines.pop(0)
|
|
251
|
+
if not any(x.strip() for x in old_lines):
|
|
252
|
+
return None
|
|
253
|
+
for how, key in (("ignoring trailing whitespace", lambda x: x.rstrip()),
|
|
254
|
+
("ignoring indentation", lambda x: x.strip())):
|
|
255
|
+
hits = _windows(file_lines, old_lines, key)
|
|
256
|
+
if not hits:
|
|
257
|
+
continue
|
|
258
|
+
if len(hits) > 1 and not replace_all:
|
|
259
|
+
where = ", ".join(str(h + 1) for h in hits[:6])
|
|
260
|
+
raise ToolError(f"old_string matches {len(hits)} places ({how}; lines {where}). Add more "
|
|
261
|
+
"surrounding lines to make it unique, or set replace_all to true.")
|
|
262
|
+
chosen: List[int] = [] # non-overlapping, applied bottom-up so indexes stay valid
|
|
263
|
+
for h in hits:
|
|
264
|
+
if not chosen or h >= chosen[-1] + len(old_lines):
|
|
265
|
+
chosen.append(h)
|
|
266
|
+
for h in reversed(chosen):
|
|
267
|
+
seg = file_lines[h:h + len(old_lines)]
|
|
268
|
+
repl = (_reindent(new_lines, *_indent_map(old_lines, seg))
|
|
269
|
+
if how == "ignoring indentation" else new_lines)
|
|
270
|
+
file_lines[h:h + len(old_lines)] = repl
|
|
271
|
+
return nl.join(file_lines), len(chosen), how
|
|
272
|
+
return None
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def _project_files(ctx: ToolContext) -> List[str]:
|
|
276
|
+
from euron_code.tools import pathfind
|
|
277
|
+
return pathfind.list_files(ctx.root)
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def _find_in_project(ctx: ToolContext, wanted: str) -> Optional[Path]:
|
|
281
|
+
"""The only project file a missing relative path can mean (app/page.tsx -> src/app/page.tsx)."""
|
|
282
|
+
from euron_code.tools import pathfind
|
|
283
|
+
if not isinstance(wanted, str) or os.path.isabs(os.path.expanduser(wanted.strip())):
|
|
284
|
+
return None
|
|
285
|
+
real = pathfind.resolve_unique(_project_files(ctx), wanted)
|
|
286
|
+
return (ctx.root / real) if real else None
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
def _project_hint(ctx: ToolContext, wanted: str) -> str:
|
|
290
|
+
from euron_code.tools import pathfind
|
|
291
|
+
try:
|
|
292
|
+
return pathfind.hint(_project_files(ctx), wanted)
|
|
293
|
+
except OSError:
|
|
294
|
+
return ""
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def apply_edit_ex(text: str, old: str, new: str, replace_all: bool = False) -> Tuple[str, int, str]:
|
|
298
|
+
"""apply_edit plus how the match was found ("" = exact)."""
|
|
166
299
|
if old == "":
|
|
167
300
|
raise ToolError("old_string is empty. To create or overwrite a file use write_file.")
|
|
168
301
|
if old == new:
|
|
@@ -174,13 +307,33 @@ def apply_edit(text: str, old: str, new: str, replace_all: bool = False) -> Tupl
|
|
|
174
307
|
old_a, new_a = old, new
|
|
175
308
|
count = text.count(old_a)
|
|
176
309
|
if count == 0:
|
|
310
|
+
# 1. line numbers copied from read_file
|
|
311
|
+
g_old = _strip_gutter(old)
|
|
312
|
+
if g_old is not None and g_old != old and g_old.strip():
|
|
313
|
+
g_new = _strip_gutter(new)
|
|
314
|
+
try:
|
|
315
|
+
out, n, how = apply_edit_ex(text, g_old, g_new if g_new is not None else new, replace_all)
|
|
316
|
+
return out, n, "without the copied line numbers" + (", " + how if how else "")
|
|
317
|
+
except ToolError:
|
|
318
|
+
pass
|
|
319
|
+
# 2./3. whitespace-tolerant, unique match
|
|
320
|
+
fz = _fuzzy_replace(text, old, new, replace_all)
|
|
321
|
+
if fz is not None:
|
|
322
|
+
return fz
|
|
177
323
|
raise ToolError("old_string was not found in the file." + _near_miss_hint(text, old))
|
|
178
324
|
if count > 1 and not replace_all:
|
|
179
325
|
raise ToolError(
|
|
180
326
|
f"old_string matches {count} places. Add more surrounding lines to make it unique, "
|
|
181
327
|
"or set replace_all to true to change every occurrence."
|
|
182
328
|
)
|
|
183
|
-
return text.replace(old_a, new_a), count
|
|
329
|
+
return text.replace(old_a, new_a), count, ""
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def apply_edit(text: str, old: str, new: str, replace_all: bool = False) -> Tuple[str, int]:
|
|
333
|
+
"""Replace old with new: exact first, then (unique) tolerant of copied line numbers,
|
|
334
|
+
trailing whitespace and indentation. Returns (new_text, count)."""
|
|
335
|
+
out, n, _ = apply_edit_ex(text, old, new, replace_all)
|
|
336
|
+
return out, n
|
|
184
337
|
|
|
185
338
|
|
|
186
339
|
# ---------------------------------------------------------------- read_file
|
|
@@ -212,6 +365,13 @@ class ReadFile(Tool):
|
|
|
212
365
|
|
|
213
366
|
def run(self, args, ctx):
|
|
214
367
|
path = ctx.resolve(require(args, "path"))
|
|
368
|
+
moved = ""
|
|
369
|
+
if not path.exists():
|
|
370
|
+
real = _find_in_project(ctx, args["path"])
|
|
371
|
+
if real is None:
|
|
372
|
+
raise ToolError(f"File not found: {ctx.rel(path)}." + _project_hint(ctx, args["path"]))
|
|
373
|
+
moved = f"(no {ctx.rel(path)}; this is {ctx.rel(real)}, the only file it can mean)\n"
|
|
374
|
+
path = real
|
|
215
375
|
offset = max(1, opt_int(args, "offset", 1) or 1)
|
|
216
376
|
limit = max(1, min(opt_int(args, "limit", DEFAULT_READ_LIMIT) or DEFAULT_READ_LIMIT, 2000))
|
|
217
377
|
rng = (offset, limit)
|
|
@@ -264,7 +424,7 @@ class ReadFile(Tool):
|
|
|
264
424
|
if offset > 1 or end < total:
|
|
265
425
|
body += (f"\n\n(Showing lines {offset}-{end} of {total}. Use offset={end + 1} to read more"
|
|
266
426
|
+ (", or grep for what you need" if end < total else "") + ".)")
|
|
267
|
-
body = ctx.cut(body, "read a smaller range")
|
|
427
|
+
body = moved + ctx.cut(body, "read a smaller range")
|
|
268
428
|
# a read that reached the end of the file covers any later range too
|
|
269
429
|
cover = (offset, TO_END if end >= total else len(chunk))
|
|
270
430
|
ctx.tracker.mark_read(path, cover, ctx.turn, len(body), ctx.call_id)
|
|
@@ -303,7 +463,13 @@ class WriteFile(Tool):
|
|
|
303
463
|
if path.is_dir():
|
|
304
464
|
raise ToolError(f"{path} is a directory.")
|
|
305
465
|
if not ctx.tracker.was_read(path):
|
|
306
|
-
|
|
466
|
+
# Show the current content now (and count it as read), so the next write_file call
|
|
467
|
+
# can go through without a separate read_file round trip.
|
|
468
|
+
cur = load_text(path).text
|
|
469
|
+
ctx.tracker.mark_read(path, (1, TO_END), ctx.turn, len(cur), ctx.call_id)
|
|
470
|
+
raise ToolError(f"{ctx.rel(path)} already exists and you had not read it. Its current content is "
|
|
471
|
+
"below; if you still want to replace it, call write_file again (or use edit_file "
|
|
472
|
+
"for a smaller change).\n" + ctx.cut(cur, "file shortened"))
|
|
307
473
|
if not ctx.tracker.unchanged_since_read(path):
|
|
308
474
|
raise ToolError(f"{ctx.rel(path)} changed since you last read it. Read it again first.")
|
|
309
475
|
tf = load_text(path)
|
|
@@ -366,12 +532,15 @@ class EditFile(Tool):
|
|
|
366
532
|
tf = load_text(path)
|
|
367
533
|
text = tf.text
|
|
368
534
|
total = 0
|
|
535
|
+
self._notes = []
|
|
369
536
|
for i, e in enumerate(self.edits(args), start=1):
|
|
370
537
|
if not isinstance(e, dict):
|
|
371
538
|
raise ToolError(f"edit {i} must be an object.")
|
|
372
539
|
try:
|
|
373
|
-
text, n =
|
|
374
|
-
|
|
540
|
+
text, n, how = apply_edit_ex(text, e.get("old_string", ""), e.get("new_string", ""),
|
|
541
|
+
bool(e.get("replace_all")))
|
|
542
|
+
if how:
|
|
543
|
+
self._notes.append(how)
|
|
375
544
|
except ToolError as err:
|
|
376
545
|
prefix = f"Edit {i} failed: " if self.name == "multi_edit" else ""
|
|
377
546
|
raise ToolError(prefix + str(err) + (" No edits were applied." if self.name == "multi_edit" else ""))
|
|
@@ -391,7 +560,9 @@ class EditFile(Tool):
|
|
|
391
560
|
removed = sum(1 for ln in diff.splitlines() if ln.startswith("-") and not ln.startswith("---"))
|
|
392
561
|
check = syntax_check(path)
|
|
393
562
|
return ToolResult(
|
|
394
|
-
f"Edited {ctx.rel(path)}: {total} replacement(s), +{added} -{removed} lines
|
|
563
|
+
f"Edited {ctx.rel(path)}: {total} replacement(s), +{added} -{removed} lines"
|
|
564
|
+
+ (f" (matched {'; '.join(sorted(set(self._notes)))}; check the diff)" if getattr(self, "_notes", None) else "")
|
|
565
|
+
+ ".\n"
|
|
395
566
|
+ truncate(diff, 3000, "diff shortened") + (f"\n{check}" if check else ""),
|
|
396
567
|
preview=f"+{added} -{removed} lines" + (f" ({check})" if check and "error" in check else ""),
|
|
397
568
|
)
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""Repair the small slips models make in tool arguments, before the tool runs.
|
|
2
|
+
|
|
3
|
+
Seen in production error reports (Euron Code dashboard, Nov 2026):
|
|
4
|
+
- `Missing required parameter` on edit_file / write_file / multi_edit / oss_grep: the model
|
|
5
|
+
used another common name for the parameter (file_path, old_str, query, ...).
|
|
6
|
+
- `todos must be a list`: the list arrived as a JSON string.
|
|
7
|
+
- integers / booleans sent as strings ("50", "true").
|
|
8
|
+
|
|
9
|
+
Only the tool's own schema is trusted: an alias is used only when the canonical parameter is
|
|
10
|
+
missing, and only for parameters the tool really has. Nothing is guessed beyond that.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import json
|
|
16
|
+
from typing import Any, Dict, List, Optional
|
|
17
|
+
|
|
18
|
+
# canonical name -> other names models use for it
|
|
19
|
+
ALIASES: Dict[str, List[str]] = {
|
|
20
|
+
"path": ["file_path", "filepath", "file", "filename", "file_name", "target_file", "target", "dir",
|
|
21
|
+
"directory", "folder", "relative_path", "absolute_path"],
|
|
22
|
+
"old_string": ["old_str", "oldString", "old", "old_text", "search", "find", "original", "before",
|
|
23
|
+
"search_string", "from"],
|
|
24
|
+
"new_string": ["new_str", "newString", "new", "new_text", "replace", "replacement", "after",
|
|
25
|
+
"replace_string", "to"],
|
|
26
|
+
"content": ["contents", "text", "file_content", "file_text", "data", "code", "body"],
|
|
27
|
+
"pattern": ["query", "regex", "search", "q", "grep", "expression", "term"],
|
|
28
|
+
"command": ["cmd", "shell_command", "script", "bash"],
|
|
29
|
+
"id": ["process_id", "pid", "proc_id", "process", "name", "job_id"],
|
|
30
|
+
"todos": ["items", "tasks", "todo", "list", "todo_list"],
|
|
31
|
+
"repo": ["repository", "repo_name", "full_name"],
|
|
32
|
+
"edits": ["changes", "replacements", "patches"],
|
|
33
|
+
"replace_all": ["replaceAll", "all", "global"],
|
|
34
|
+
"offset": ["start_line", "start", "line", "from_line"],
|
|
35
|
+
"limit": ["lines", "count", "max_lines", "num_lines"],
|
|
36
|
+
"url": ["link", "href", "uri"],
|
|
37
|
+
"prompt": ["task", "instructions", "description"],
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
_TRUE = {"true", "yes", "1", "on"}
|
|
41
|
+
_FALSE = {"false", "no", "0", "off", ""}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _props(schema: Optional[Dict[str, Any]]) -> Dict[str, Any]:
|
|
45
|
+
if not isinstance(schema, dict):
|
|
46
|
+
return {}
|
|
47
|
+
p = schema.get("properties")
|
|
48
|
+
return p if isinstance(p, dict) else {}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _coerce(value: Any, spec: Any) -> Any:
|
|
52
|
+
if not isinstance(spec, dict):
|
|
53
|
+
return value
|
|
54
|
+
typ = spec.get("type")
|
|
55
|
+
if typ in ("array", "object") and isinstance(value, str):
|
|
56
|
+
s = value.strip()
|
|
57
|
+
if s[:1] in ("[", "{"):
|
|
58
|
+
try:
|
|
59
|
+
parsed = json.loads(s)
|
|
60
|
+
except ValueError:
|
|
61
|
+
return value
|
|
62
|
+
if (typ == "array" and isinstance(parsed, list)) or (typ == "object" and isinstance(parsed, dict)):
|
|
63
|
+
value = parsed
|
|
64
|
+
if typ == "array" and isinstance(value, dict) and isinstance(spec.get("items"), dict) \
|
|
65
|
+
and spec["items"].get("type") == "object":
|
|
66
|
+
value = [value] # a single item sent without its list
|
|
67
|
+
if typ == "array" and isinstance(value, list) and isinstance(spec.get("items"), dict):
|
|
68
|
+
value = [_normalize_obj(v, spec["items"]) if isinstance(v, dict) else _coerce(v, spec["items"])
|
|
69
|
+
for v in value]
|
|
70
|
+
elif typ == "object" and isinstance(value, dict):
|
|
71
|
+
value = _normalize_obj(value, spec)
|
|
72
|
+
elif typ == "integer" and isinstance(value, str):
|
|
73
|
+
s = value.strip()
|
|
74
|
+
if s.lstrip("-").isdigit():
|
|
75
|
+
value = int(s)
|
|
76
|
+
elif typ == "integer" and isinstance(value, float) and value.is_integer():
|
|
77
|
+
value = int(value)
|
|
78
|
+
elif typ == "boolean" and isinstance(value, str) and value.strip().lower() in _TRUE | _FALSE:
|
|
79
|
+
value = value.strip().lower() in _TRUE
|
|
80
|
+
elif typ == "string" and isinstance(value, (int, float)) and not isinstance(value, bool):
|
|
81
|
+
value = str(value)
|
|
82
|
+
return value
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _normalize_obj(args: Dict[str, Any], schema: Dict[str, Any]) -> Dict[str, Any]:
|
|
86
|
+
props = _props(schema)
|
|
87
|
+
if not props:
|
|
88
|
+
return args
|
|
89
|
+
out = dict(args)
|
|
90
|
+
for canon in props:
|
|
91
|
+
if canon in out and out[canon] is not None:
|
|
92
|
+
continue
|
|
93
|
+
for alias in ALIASES.get(canon, []):
|
|
94
|
+
if alias in out and alias not in props and out[alias] is not None:
|
|
95
|
+
out[canon] = out.pop(alias)
|
|
96
|
+
break
|
|
97
|
+
for k, spec in props.items():
|
|
98
|
+
if k in out and out[k] is not None:
|
|
99
|
+
out[k] = _coerce(out[k], spec)
|
|
100
|
+
return out
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def normalize_args(args: Dict[str, Any], schema: Optional[Dict[str, Any]]) -> Dict[str, Any]:
|
|
104
|
+
"""Return `args` with aliases mapped to the schema's names and values coerced to its types.
|
|
105
|
+
|
|
106
|
+
Also unwraps `{"arguments": {...}}` / `{"input": {...}}` / `{"params": {...}}` when the tool has
|
|
107
|
+
no such parameter and that is the only key.
|
|
108
|
+
"""
|
|
109
|
+
if not isinstance(args, dict):
|
|
110
|
+
return args
|
|
111
|
+
props = _props(schema)
|
|
112
|
+
if len(args) == 1:
|
|
113
|
+
(k, v), = args.items()
|
|
114
|
+
if k in ("arguments", "input", "params", "parameters", "args") and k not in props:
|
|
115
|
+
if isinstance(v, str):
|
|
116
|
+
try:
|
|
117
|
+
v = json.loads(v)
|
|
118
|
+
except ValueError:
|
|
119
|
+
pass
|
|
120
|
+
if isinstance(v, dict):
|
|
121
|
+
args = v
|
|
122
|
+
return _normalize_obj(args, schema or {})
|
|
@@ -423,16 +423,25 @@ class OssRead(Tool):
|
|
|
423
423
|
p = osscache.resolve_in(c, path)
|
|
424
424
|
except osscache.CacheError as e:
|
|
425
425
|
raise ToolError(e.message)
|
|
426
|
+
moved = ""
|
|
426
427
|
if not p.is_file():
|
|
427
|
-
|
|
428
|
-
|
|
428
|
+
from euron_code.tools import pathfind
|
|
429
|
+
files = pathfind.list_files(c.src)
|
|
430
|
+
real = pathfind.resolve_unique(files, path)
|
|
431
|
+
if real is None:
|
|
432
|
+
raise ToolError(f"{path} is not in {c.repo} (or was skipped as binary / vendored)."
|
|
433
|
+
+ pathfind.hint(files, path) + " Use oss_tree to see the layout.")
|
|
434
|
+
moved = f"(no {path} in {c.repo}; this is {real}, the only file it can mean)\n"
|
|
435
|
+
path = real
|
|
436
|
+
p = osscache.resolve_in(c, path)
|
|
429
437
|
lines = p.read_text(encoding="utf-8", errors="replace").split("\n")
|
|
430
438
|
e = min(end, len(lines))
|
|
431
439
|
url = f"{c.url}/blob/{c.sha}/{path.strip('/')}"
|
|
432
440
|
head = (f"{c.repo} :: {path} lines {start}-{e} of {len(lines)} [{c.license}] {url}\n"
|
|
433
441
|
f"[{licensing.usage_note(c.license)}]\n")
|
|
434
442
|
body = "\n".join(f"{i:>6}\t{ln}" for i, ln in enumerate(lines[start - 1:e], start))
|
|
435
|
-
return ToolResult(ctx.cut(head + body),
|
|
443
|
+
return ToolResult(ctx.cut(moved + head + body),
|
|
444
|
+
preview=f"{max(0, e - start + 1)} lines [{c.license}] (local)")
|
|
436
445
|
try:
|
|
437
446
|
d = _client(ctx).oss_read(repo, path, start, end, ref=args.get("ref"))
|
|
438
447
|
except api.EuronError as e:
|