euron-code 0.6.0__tar.gz → 0.7.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-0.6.0 → euron_code-0.7.0}/CHANGELOG.md +13 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/PKG-INFO +1 -1
- {euron_code-0.6.0 → euron_code-0.7.0}/pyproject.toml +1 -1
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/__init__.py +1 -1
- euron_code-0.7.0/src/euron_code/markdown_view.py +331 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/ui.py +40 -35
- euron_code-0.7.0/tests/test_markdown_view.py +94 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/.gitignore +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/LICENSE +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/README.md +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/__main__.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/activity.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/agent.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/api.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/attachments.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/auth.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/builtin_skills/build-from-reference/SKILL.md +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/builtin_skills/explain-codebase/SKILL.md +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/builtin_skills/review/SKILL.md +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/builtin_skills/test-writer/SKILL.md +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/cache.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/checkpoints.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/cli.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/config.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/context.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/contextforge/LICENSE +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/contextforge/__init__.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/contextforge/text.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/contextforge/toolout.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/credentials.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/doctor.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/documents.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/error_hints.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/errorlog.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/frontmatter.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/hooks.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/keys.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/licensing.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/memory.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/osscache.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/ossgithub.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/permissions.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/project_setup.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/prompts.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/repl.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/repomap.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/rules.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/sessions.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/skills.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/textsafe.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/tools/__init__.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/tools/background.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/tools/base.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/tools/db.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/tools/document.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/tools/erie.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/tools/fs.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/tools/ignore.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/tools/oss.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/tools/reuse.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/tools/search.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/tools/shell.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/tools/skill.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/tools/symbols.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/tools/task.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/tools/todo.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/tools/web.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/transcript.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/trust.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/usage_view.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/conftest.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/helpers.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/mock_gateway.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/serve_helper.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_agent_mock.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_api_shell.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_bench.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_cli_e2e.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_context_memory_sessions.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_db.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_erie.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_oss_local.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_permissions.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_powershell_exit_codes.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_qa_attach_secrets.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_qa_long_task.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_qa_print_output.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_qa_reuse_unrelated.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_qa_yolo_outside.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_repl.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_search.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_textsafe.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_tools_fs.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_transcript_ui.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_v2_rules_skills_hooks.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_v2_tokens_shortcuts.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_v2_usage_headers.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_v31_security.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_v3_accounts_value_setup.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_v3_activity.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_v3_attachments.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_v3_context.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_v3_live_repl.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_v3_single_login.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_v4.py +0 -0
- {euron_code-0.6.0 → euron_code-0.7.0}/tests/test_v5.py +0 -0
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.7.0 (2026-11-06)
|
|
4
|
+
|
|
5
|
+
Answers are formatted, not raw Markdown.
|
|
6
|
+
|
|
7
|
+
- Tables are drawn as boxed grids that fit the terminal: columns sized to their content, long cells
|
|
8
|
+
wrapped, `:---:` alignment honoured, header in bold. Too narrow for a grid, each row is shown as
|
|
9
|
+
`header: value` lines.
|
|
10
|
+
- **Bold**, *italic*, `code`, ~~strike~~ and links show as styles instead of their markers.
|
|
11
|
+
- Headings, bullet and numbered lists (nested, wrapped under their text), task lists, block quotes and
|
|
12
|
+
horizontal rules are laid out for the terminal.
|
|
13
|
+
- Fenced code is syntax-highlighted and keeps its indentation.
|
|
14
|
+
- Works with `NO_COLOR` and ASCII terminals (`+-|` borders). `euron -p` output is unchanged.
|
|
15
|
+
|
|
3
16
|
## 0.6.0 (2026-11-06)
|
|
4
17
|
|
|
5
18
|
A new look for the interactive session.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: euron-code
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.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>
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "euron-code"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.7.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,331 @@
|
|
|
1
|
+
"""Markdown in the answer, rendered for the terminal as it streams.
|
|
2
|
+
|
|
3
|
+
The model answers in Markdown. Printed raw, a table was a wall of pipes and dashes and every
|
|
4
|
+
`**bold**` kept its asterisks. This turns it into terminal output, one line at a time:
|
|
5
|
+
|
|
6
|
+
| Approach | Tokens | ┌──────────────┬───────────────┐
|
|
7
|
+
|---|---| → │ Approach │ Tokens │
|
|
8
|
+
| **From scratch** | ~9k | ├──────────────┼───────────────┤
|
|
9
|
+
│ From scratch │ ~9,000-12,000 │
|
|
10
|
+
└──────────────┴───────────────┘
|
|
11
|
+
|
|
12
|
+
Handled: tables (column widths fitted to the terminal, cells wrapped, alignment from the `:---:`
|
|
13
|
+
row), headings, bullet and numbered lists (nested), block quotes, horizontal rules, fenced code
|
|
14
|
+
(syntax-highlighted, never re-wrapped mid-word), and inline **bold**, *italic*, `code`,
|
|
15
|
+
~~strike~~ and [links](url).
|
|
16
|
+
|
|
17
|
+
Streaming: a line is rendered as soon as it is complete. Table rows are held until the table
|
|
18
|
+
ends (a column width depends on every row), and finish() prints whatever is still held.
|
|
19
|
+
|
|
20
|
+
Pure functions of (text, width, glyphs) that return rich `Text`, so tests can compare plain
|
|
21
|
+
strings, and NO_COLOR or a pipe drops the styles while the layout still reads.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
import io
|
|
27
|
+
import re
|
|
28
|
+
from typing import List, Optional, Tuple
|
|
29
|
+
|
|
30
|
+
from rich.cells import cell_len
|
|
31
|
+
from rich.console import Console
|
|
32
|
+
from rich.text import Text
|
|
33
|
+
|
|
34
|
+
from .transcript import ACCENT, ASCII, UNICODE, Glyphs, _clean, wrap_cells
|
|
35
|
+
|
|
36
|
+
CODE_STYLE = "#e5c07b" # inline `code`: warm, readable on dark and light terminals
|
|
37
|
+
LINK_STYLE = f"underline {ACCENT}"
|
|
38
|
+
|
|
39
|
+
# A Console only for measuring and wrapping Text; it never prints.
|
|
40
|
+
_MEASURE = Console(file=io.StringIO(), width=1000, color_system=None, highlight=False, emoji=False)
|
|
41
|
+
|
|
42
|
+
_FENCE = re.compile(r"^(\s*)(```+|~~~+)\s*([\w+#.-]*)")
|
|
43
|
+
_HEADING = re.compile(r"^\s{0,3}(#{1,6})\s+(.*?)\s*#*\s*$")
|
|
44
|
+
_LIST = re.compile(r"^(\s*)([-*+]|\d{1,3}[.)])\s+(.*)$")
|
|
45
|
+
_TASK = re.compile(r"^\[([ xX])\]\s+(.*)$")
|
|
46
|
+
_QUOTE = re.compile(r"^\s{0,3}>\s?(.*)$")
|
|
47
|
+
_HR = re.compile(r"^\s{0,3}([-*_])(\s*\1){2,}\s*$")
|
|
48
|
+
_TABLE_SEP = re.compile(r"^\s*\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$")
|
|
49
|
+
|
|
50
|
+
# Inline spans, tried left to right; code first so nothing inside it is touched.
|
|
51
|
+
_INLINE = re.compile(
|
|
52
|
+
r"(?P<code>`+)(?P<code_body>.+?)(?P=code)"
|
|
53
|
+
r"|\*\*(?P<b1>(?=\S).+?(?<=\S))\*\*"
|
|
54
|
+
r"|__(?P<b2>(?=\S).+?(?<=\S))__"
|
|
55
|
+
r"|~~(?P<s>(?=\S).+?(?<=\S))~~"
|
|
56
|
+
r"|\[(?P<lt>[^\]]+)\]\((?P<lu>[^)\s]+)\)"
|
|
57
|
+
r"|(?<![\w*])\*(?P<i1>(?=[^\s*]).+?(?<=[^\s*]))\*(?![\w*])"
|
|
58
|
+
r"|(?<![\w_])_(?P<i2>(?=[^\s_]).+?(?<=[^\s_]))_(?![\w_])"
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def inline(text: str, style: str = "") -> Text:
|
|
63
|
+
"""`text` with Markdown inline markup turned into styles (markers removed)."""
|
|
64
|
+
out = Text(style=style)
|
|
65
|
+
pos = 0
|
|
66
|
+
text = _clean(text)
|
|
67
|
+
for m in _INLINE.finditer(text):
|
|
68
|
+
if m.start() > pos:
|
|
69
|
+
out.append(_unescape(text[pos:m.start()]))
|
|
70
|
+
if m.group("code"):
|
|
71
|
+
out.append(m.group("code_body").strip() if m.group("code_body").strip() else m.group("code_body"),
|
|
72
|
+
style=CODE_STYLE)
|
|
73
|
+
elif m.group("b1") or m.group("b2"):
|
|
74
|
+
out.append_text(inline(m.group("b1") or m.group("b2"), "bold"))
|
|
75
|
+
elif m.group("s"):
|
|
76
|
+
out.append_text(inline(m.group("s"), "strike"))
|
|
77
|
+
elif m.group("lt"):
|
|
78
|
+
label, url = m.group("lt"), m.group("lu")
|
|
79
|
+
out.append_text(inline(label, LINK_STYLE))
|
|
80
|
+
if url != label and not url.startswith("#"):
|
|
81
|
+
out.append(f" ({url})", style="dim")
|
|
82
|
+
else:
|
|
83
|
+
out.append_text(inline(m.group("i1") or m.group("i2"), "italic"))
|
|
84
|
+
pos = m.end()
|
|
85
|
+
if pos < len(text):
|
|
86
|
+
out.append(_unescape(text[pos:]))
|
|
87
|
+
return out
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _unescape(s: str) -> str:
|
|
91
|
+
return re.sub(r"\\([\\`*_{}\[\]()#+\-.!|~>])", r"\1", s)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def wrap(text: Text, width: int) -> List[Text]:
|
|
95
|
+
"""Word-wrap styled text to `width` cells; a word longer than the width is split."""
|
|
96
|
+
width = max(4, width)
|
|
97
|
+
if not text.plain:
|
|
98
|
+
return [Text("")]
|
|
99
|
+
lines = text.wrap(_MEASURE, width, overflow="fold", no_wrap=False)
|
|
100
|
+
out = []
|
|
101
|
+
for ln in lines:
|
|
102
|
+
ln.rstrip()
|
|
103
|
+
out.append(ln)
|
|
104
|
+
return out or [Text("")]
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _hang(first: str, rest: str, body: Text, width: int, prefix_style: str = "") -> List[Text]:
|
|
108
|
+
rows = wrap(body, width - cell_len(first))
|
|
109
|
+
out = []
|
|
110
|
+
for i, row in enumerate(rows):
|
|
111
|
+
t = Text(first if i == 0 else rest, style=prefix_style)
|
|
112
|
+
t.append_text(row)
|
|
113
|
+
out.append(t)
|
|
114
|
+
return out
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
# ---------------------------------------------------------------- tables
|
|
118
|
+
|
|
119
|
+
def split_row(line: str) -> List[str]:
|
|
120
|
+
"""Cells of a `| a | b |` row. A pipe inside `code` or escaped as \\| does not split."""
|
|
121
|
+
s = line.strip()
|
|
122
|
+
if s.startswith("|"):
|
|
123
|
+
s = s[1:]
|
|
124
|
+
if s.endswith("|") and not s.endswith("\\|"):
|
|
125
|
+
s = s[:-1]
|
|
126
|
+
cells, cur, in_code = [], [], False
|
|
127
|
+
i = 0
|
|
128
|
+
while i < len(s):
|
|
129
|
+
ch = s[i]
|
|
130
|
+
if ch == "\\" and i + 1 < len(s) and s[i + 1] == "|":
|
|
131
|
+
cur.append("|")
|
|
132
|
+
i += 2
|
|
133
|
+
continue
|
|
134
|
+
if ch == "`":
|
|
135
|
+
in_code = not in_code
|
|
136
|
+
if ch == "|" and not in_code:
|
|
137
|
+
cells.append("".join(cur).strip())
|
|
138
|
+
cur = []
|
|
139
|
+
else:
|
|
140
|
+
cur.append(ch)
|
|
141
|
+
i += 1
|
|
142
|
+
cells.append("".join(cur).strip())
|
|
143
|
+
return cells
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def _aligns(sep: str, n: int) -> List[str]:
|
|
147
|
+
out = []
|
|
148
|
+
for c in split_row(sep)[:n]:
|
|
149
|
+
c = c.strip()
|
|
150
|
+
out.append("center" if c.startswith(":") and c.endswith(":") else "right" if c.endswith(":") else "left")
|
|
151
|
+
return out + ["left"] * (n - len(out))
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _box(g: Glyphs) -> dict:
|
|
155
|
+
if g is ASCII:
|
|
156
|
+
return dict(h="-", v="|", tl="+", tm="+", tr="+", ml="+", mm="+", mr="+", bl="+", bm="+", br="+")
|
|
157
|
+
return dict(h="─", v="│", tl="┌", tm="┬", tr="┐", ml="├", mm="┼", mr="┤", bl="└", bm="┴", br="┘")
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def render_table(lines: List[str], width: int, g: Glyphs = UNICODE) -> List[Text]:
|
|
161
|
+
"""A Markdown table as a box-drawn table that fits `width` cells."""
|
|
162
|
+
header = split_row(lines[0])
|
|
163
|
+
has_sep = len(lines) > 1 and bool(_TABLE_SEP.match(lines[1]))
|
|
164
|
+
body_lines = lines[2:] if has_sep else lines[1:]
|
|
165
|
+
n = max([len(header)] + [len(split_row(b)) for b in body_lines])
|
|
166
|
+
aligns = _aligns(lines[1], n) if has_sep else ["left"] * n
|
|
167
|
+
rows = [header] + [split_row(b) for b in body_lines]
|
|
168
|
+
rows = [r + [""] * (n - len(r)) for r in rows]
|
|
169
|
+
cells = [[inline(c, "bold" if ri == 0 else "") for c in r] for ri, r in enumerate(rows)]
|
|
170
|
+
|
|
171
|
+
natural = [max(max((cell_len(x.plain) for x in col), default=0), 1) for col in zip(*cells)]
|
|
172
|
+
budget = width - (3 * n + 1) # "│ " + " │ " between + " │"
|
|
173
|
+
widths = natural[:]
|
|
174
|
+
if budget < n * 3:
|
|
175
|
+
# Far too narrow for a grid: one "header: value" block per row instead.
|
|
176
|
+
return _stacked(cells, width, g)
|
|
177
|
+
while sum(widths) > budget:
|
|
178
|
+
i = max(range(n), key=lambda k: widths[k])
|
|
179
|
+
widths[i] -= 1
|
|
180
|
+
if widths[i] < 3:
|
|
181
|
+
return _stacked(cells, width, g)
|
|
182
|
+
|
|
183
|
+
b = _box(g)
|
|
184
|
+
border = "dim"
|
|
185
|
+
|
|
186
|
+
def rule(left: str, mid: str, right: str) -> Text:
|
|
187
|
+
return Text(left + mid.join(b["h"] * (w + 2) for w in widths) + right, style=border)
|
|
188
|
+
|
|
189
|
+
out = [rule(b["tl"], b["tm"], b["tr"])]
|
|
190
|
+
for ri, row in enumerate(cells):
|
|
191
|
+
wrapped = [wrap(c, widths[ci]) for ci, c in enumerate(row)]
|
|
192
|
+
height = max(len(w) for w in wrapped)
|
|
193
|
+
for k in range(height):
|
|
194
|
+
t = Text(b["v"], style=border)
|
|
195
|
+
for ci in range(n):
|
|
196
|
+
part = wrapped[ci][k] if k < len(wrapped[ci]) else Text("")
|
|
197
|
+
space = widths[ci] - cell_len(part.plain)
|
|
198
|
+
al = aligns[ci] if ri > 0 else "left"
|
|
199
|
+
lpad = space if al == "right" else space // 2 if al == "center" else 0
|
|
200
|
+
t.append(" " + " " * lpad)
|
|
201
|
+
t.append_text(part)
|
|
202
|
+
t.append(" " * (space - lpad) + " ")
|
|
203
|
+
t.append(b["v"], style=border)
|
|
204
|
+
out.append(t)
|
|
205
|
+
if ri == 0:
|
|
206
|
+
out.append(rule(b["ml"], b["mm"], b["mr"]))
|
|
207
|
+
out.append(rule(b["bl"], b["bm"], b["br"]))
|
|
208
|
+
return out
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def _stacked(cells: List[List[Text]], width: int, g: Glyphs) -> List[Text]:
|
|
212
|
+
header, body = cells[0], cells[1:]
|
|
213
|
+
out: List[Text] = []
|
|
214
|
+
for r in body:
|
|
215
|
+
for h, c in zip(header, r):
|
|
216
|
+
label = Text(h.plain + ": ", style="bold")
|
|
217
|
+
out.extend(_hang("", " ", label + c, width))
|
|
218
|
+
out.append(Text(""))
|
|
219
|
+
return out[:-1] if out else out
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
# ---------------------------------------------------------------- the stream
|
|
223
|
+
|
|
224
|
+
class MarkdownStream:
|
|
225
|
+
"""Feed answer lines one at a time; get back the terminal rows to print for each."""
|
|
226
|
+
|
|
227
|
+
def __init__(self, width: int, g: Glyphs = UNICODE, color: bool = True):
|
|
228
|
+
self.width = width
|
|
229
|
+
self.g = g
|
|
230
|
+
self.color = color
|
|
231
|
+
self._code: Optional[Tuple[str, str]] = None # (fence, language) while inside a code block
|
|
232
|
+
self._table: List[str] = []
|
|
233
|
+
|
|
234
|
+
# -- public
|
|
235
|
+
def feed(self, line: str) -> List[Text]:
|
|
236
|
+
line = line.rstrip("\r\n")
|
|
237
|
+
out: List[Text] = []
|
|
238
|
+
if self._code is not None:
|
|
239
|
+
return self._code_line(line)
|
|
240
|
+
if self._table:
|
|
241
|
+
if "|" in line and line.strip():
|
|
242
|
+
self._table.append(line)
|
|
243
|
+
return []
|
|
244
|
+
out.extend(self._end_table())
|
|
245
|
+
m = _FENCE.match(line)
|
|
246
|
+
if m:
|
|
247
|
+
self._code = (m.group(2)[0] * 3, m.group(3).lower())
|
|
248
|
+
label = m.group(3) or "code"
|
|
249
|
+
return out + [Text(label, style="dim")]
|
|
250
|
+
if line.strip().startswith("|") or (line.count("|") >= 2 and line.strip()):
|
|
251
|
+
self._table = [line]
|
|
252
|
+
return out
|
|
253
|
+
return out + self._block(line)
|
|
254
|
+
|
|
255
|
+
def finish(self) -> List[Text]:
|
|
256
|
+
out: List[Text] = []
|
|
257
|
+
if self._table:
|
|
258
|
+
out.extend(self._end_table())
|
|
259
|
+
self._code = None
|
|
260
|
+
return out
|
|
261
|
+
|
|
262
|
+
# -- blocks
|
|
263
|
+
def _end_table(self) -> List[Text]:
|
|
264
|
+
rows, self._table = self._table, []
|
|
265
|
+
is_table = len(rows) >= 2 and bool(_TABLE_SEP.match(rows[1]))
|
|
266
|
+
if not is_table:
|
|
267
|
+
out: List[Text] = []
|
|
268
|
+
for r in rows:
|
|
269
|
+
out.extend(self._block(r))
|
|
270
|
+
return out
|
|
271
|
+
return render_table(rows, self.width, self.g)
|
|
272
|
+
|
|
273
|
+
def _code_line(self, line: str) -> List[Text]:
|
|
274
|
+
fence, lang = self._code # type: ignore[misc]
|
|
275
|
+
if line.strip().startswith(fence):
|
|
276
|
+
self._code = None
|
|
277
|
+
return []
|
|
278
|
+
body = _clean(line)
|
|
279
|
+
styled = self._highlight(body, lang)
|
|
280
|
+
rows = []
|
|
281
|
+
avail = max(8, self.width - 2)
|
|
282
|
+
# Code is cut by cells, never re-flowed: indentation must survive.
|
|
283
|
+
if cell_len(body) <= avail:
|
|
284
|
+
t = Text(" ")
|
|
285
|
+
t.append_text(styled)
|
|
286
|
+
return [t]
|
|
287
|
+
for chunk in wrap_cells(body, avail):
|
|
288
|
+
rows.append(Text(" " + chunk, style=CODE_STYLE))
|
|
289
|
+
return rows
|
|
290
|
+
|
|
291
|
+
def _highlight(self, line: str, lang: str) -> Text:
|
|
292
|
+
if not self.color or not lang or lang in ("text", "plain", "console", "output"):
|
|
293
|
+
return Text(line, style=CODE_STYLE if not lang else "")
|
|
294
|
+
try:
|
|
295
|
+
from rich.syntax import Syntax
|
|
296
|
+
|
|
297
|
+
t = Syntax(line, lang, theme="monokai", background_color="default").highlight(line)
|
|
298
|
+
t.rstrip()
|
|
299
|
+
return t
|
|
300
|
+
except Exception:
|
|
301
|
+
return Text(line, style=CODE_STYLE)
|
|
302
|
+
|
|
303
|
+
def _block(self, line: str) -> List[Text]:
|
|
304
|
+
if not line.strip():
|
|
305
|
+
return [Text("")]
|
|
306
|
+
if _HR.match(line):
|
|
307
|
+
return [Text(self.g.rule * min(self.width, 48), style="dim")]
|
|
308
|
+
m = _HEADING.match(line)
|
|
309
|
+
if m:
|
|
310
|
+
level = len(m.group(1))
|
|
311
|
+
style = f"bold {ACCENT}" if level <= 2 else "bold"
|
|
312
|
+
return wrap(inline(m.group(2), style), self.width)
|
|
313
|
+
m = _QUOTE.match(line)
|
|
314
|
+
if m:
|
|
315
|
+
bar = "│ " if self.g is UNICODE else "| "
|
|
316
|
+
return _hang(bar, bar, inline(m.group(1), "italic"), self.width, prefix_style="dim")
|
|
317
|
+
m = _LIST.match(line)
|
|
318
|
+
if m:
|
|
319
|
+
indent = " " * min(len(m.group(1).replace("\t", " ")) // 2, 6)
|
|
320
|
+
marker = m.group(2)
|
|
321
|
+
text = m.group(3)
|
|
322
|
+
t = _TASK.match(text)
|
|
323
|
+
if t:
|
|
324
|
+
marker = ("☑" if t.group(1).lower() == "x" else "☐") if self.g is UNICODE else (
|
|
325
|
+
"[x]" if t.group(1).lower() == "x" else "[ ]")
|
|
326
|
+
text = t.group(2)
|
|
327
|
+
elif marker in "-*+":
|
|
328
|
+
marker = "•" if self.g is UNICODE else "-"
|
|
329
|
+
first = f"{indent}{marker} "
|
|
330
|
+
return _hang(first, " " * cell_len(first), inline(text), self.width, prefix_style=ACCENT)
|
|
331
|
+
return wrap(inline(line.strip()), self.width)
|
|
@@ -17,12 +17,14 @@ import threading
|
|
|
17
17
|
import time
|
|
18
18
|
from typing import Any, Dict, List, Optional
|
|
19
19
|
|
|
20
|
+
from rich.cells import cell_len
|
|
20
21
|
from rich.console import Console
|
|
21
22
|
from rich.markup import escape
|
|
22
23
|
from rich.text import Text
|
|
23
24
|
|
|
24
25
|
from euron_code import transcript
|
|
25
26
|
from euron_code.activity import Activity, supports_unicode
|
|
27
|
+
from euron_code.markdown_view import MarkdownStream
|
|
26
28
|
|
|
27
29
|
|
|
28
30
|
class _ActivityRenderable:
|
|
@@ -64,6 +66,7 @@ class UI:
|
|
|
64
66
|
self._content_started = False
|
|
65
67
|
self._reasoning_printed = False
|
|
66
68
|
self._buf = "" # streamed text not yet printed (no newline yet)
|
|
69
|
+
self._md: Optional[MarkdownStream] = None # Markdown state of the answer being printed
|
|
67
70
|
self._rbuf = ""
|
|
68
71
|
self._prose_first = True # the next answer line is the first of this answer (gets the bullet)
|
|
69
72
|
self._at_line_start = True # direct streaming: the cursor is at the start of a line
|
|
@@ -196,6 +199,9 @@ class UI:
|
|
|
196
199
|
if self._buf:
|
|
197
200
|
self._print_prose(self._buf)
|
|
198
201
|
self._buf = ""
|
|
202
|
+
if self._md is not None:
|
|
203
|
+
self._print_rows(self._md.finish())
|
|
204
|
+
self._md = None
|
|
199
205
|
|
|
200
206
|
# ---------------------------------------------------------- transcript output
|
|
201
207
|
@property
|
|
@@ -212,39 +218,41 @@ class UI:
|
|
|
212
218
|
self.console.print(t, soft_wrap=True)
|
|
213
219
|
|
|
214
220
|
def _print_prose(self, line: str) -> None:
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
+
"""One complete line of the answer, rendered as Markdown (tables, bold, lists, code)."""
|
|
222
|
+
if self._md is None:
|
|
223
|
+
if self._prose_first and not line.strip():
|
|
224
|
+
return # blank lines before an answer: the block gets one blank line of its own
|
|
225
|
+
avail = self.width - cell_len(self.g.bullet) - 1
|
|
226
|
+
self._md = MarkdownStream(avail, self.g, color=not transcript.no_color())
|
|
227
|
+
self._print_rows(self._md.feed(line))
|
|
228
|
+
|
|
229
|
+
def _print_rows(self, rows: List[Text]) -> None:
|
|
230
|
+
"""Rendered rows under the answer bullet: the first row gets the bullet, the rest the indent."""
|
|
231
|
+
pad = " " * (cell_len(self.g.bullet) + 1)
|
|
232
|
+
for row in rows:
|
|
233
|
+
if self._prose_first:
|
|
234
|
+
if not row.plain.strip():
|
|
235
|
+
continue
|
|
236
|
+
lead = [Text("")] if not self._spaced else []
|
|
237
|
+
self._spaced = False
|
|
238
|
+
first = Text(self.g.bullet + " ")
|
|
239
|
+
first.append_text(row)
|
|
240
|
+
self._lines(lead + [first])
|
|
241
|
+
self._prose_first = False
|
|
242
|
+
else:
|
|
243
|
+
line = Text(pad) if row.plain else Text("")
|
|
244
|
+
line.append_text(row)
|
|
245
|
+
self._lines([line])
|
|
221
246
|
|
|
222
247
|
def _emit_prose(self, text: str) -> None:
|
|
223
|
-
"""Stream answer text
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
self._buf = buf
|
|
232
|
-
return
|
|
233
|
-
pad = " " * (len(self.g.bullet) + 1)
|
|
234
|
-
out = []
|
|
235
|
-
for piece in text.splitlines(keepends=True):
|
|
236
|
-
if self._prose_first and self._at_line_start and not piece.strip():
|
|
237
|
-
continue
|
|
238
|
-
if self._at_line_start and piece.strip("\r\n"):
|
|
239
|
-
if self._prose_first:
|
|
240
|
-
out.append(("" if self._spaced else "\n") + self.g.bullet + " ")
|
|
241
|
-
self._spaced = False
|
|
242
|
-
else:
|
|
243
|
-
out.append(pad)
|
|
244
|
-
self._prose_first = False
|
|
245
|
-
out.append(piece)
|
|
246
|
-
self._at_line_start = piece.endswith("\n")
|
|
247
|
-
self.console.print(Text("".join(out)), end="")
|
|
248
|
+
"""Stream answer text a whole line at a time, so each line can be rendered as Markdown
|
|
249
|
+
(a table row, a list item, a code line) before it reaches the terminal."""
|
|
250
|
+
with self._out_lock:
|
|
251
|
+
buf = self._buf + text
|
|
252
|
+
while "\n" in buf:
|
|
253
|
+
done, buf = buf.split("\n", 1)
|
|
254
|
+
self._print_prose(done)
|
|
255
|
+
self._buf = buf
|
|
248
256
|
|
|
249
257
|
@property
|
|
250
258
|
def expand_how(self) -> str:
|
|
@@ -302,10 +310,7 @@ class UI:
|
|
|
302
310
|
|
|
303
311
|
def end_response(self) -> None:
|
|
304
312
|
self._close_reasoning()
|
|
305
|
-
|
|
306
|
-
self._flush()
|
|
307
|
-
elif self._content_started and not self._at_line_start:
|
|
308
|
-
self.console.print()
|
|
313
|
+
self._flush()
|
|
309
314
|
self._content_started = False
|
|
310
315
|
self._at_line_start = True
|
|
311
316
|
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""Answers are Markdown: the terminal shows them formatted, not as raw pipes and asterisks."""
|
|
2
|
+
|
|
3
|
+
from euron_code.markdown_view import ASCII, UNICODE, MarkdownStream, inline, render_table, split_row
|
|
4
|
+
|
|
5
|
+
TABLE = [
|
|
6
|
+
"| Approach | Lines | Tokens (approx) |",
|
|
7
|
+
"|---|---:|---|",
|
|
8
|
+
"| **From scratch** (no reference) | ~1200-1500 | ~9,000-12,000 |",
|
|
9
|
+
"| **Saved** | ~200-500 lines | ~2,000-4,000 tokens |",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def render(md: str, width: int = 80, g=UNICODE):
|
|
14
|
+
s = MarkdownStream(width, g, color=False)
|
|
15
|
+
rows = []
|
|
16
|
+
for line in md.split("\n"):
|
|
17
|
+
rows += s.feed(line)
|
|
18
|
+
rows += s.finish()
|
|
19
|
+
return [r.plain.rstrip() for r in rows]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_table_is_box_drawn_and_markers_are_gone():
|
|
23
|
+
out = render("\n".join(TABLE))
|
|
24
|
+
assert out[0].startswith("┌") and out[-1].startswith("└")
|
|
25
|
+
assert any("│ From scratch (no reference) │" in r for r in out)
|
|
26
|
+
assert not any("**" in r or "|---" in r for r in out)
|
|
27
|
+
# every row of the grid has the same width
|
|
28
|
+
assert len({len(r) for r in out}) == 1
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_right_aligned_column():
|
|
32
|
+
out = render("\n".join(TABLE))
|
|
33
|
+
row = next(r for r in out if "From scratch" in r)
|
|
34
|
+
cell = row.split("│")[2]
|
|
35
|
+
assert cell.endswith("~1200-1500 ")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_table_fits_a_narrow_terminal():
|
|
39
|
+
out = render("\n".join(TABLE), width=40)
|
|
40
|
+
assert all(len(r) <= 40 for r in out)
|
|
41
|
+
assert any("From" in r for r in out)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_ascii_table():
|
|
45
|
+
out = render("\n".join(TABLE), g=ASCII)
|
|
46
|
+
assert out[0].startswith("+-") and "|" in out[1]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_pipes_in_prose_and_code_are_not_a_table():
|
|
50
|
+
out = render("run `a | b` then pipe it | grep x")
|
|
51
|
+
assert out == ["run a | b then pipe it | grep x"]
|
|
52
|
+
out = render("```sh\nls | wc -l\n```")
|
|
53
|
+
assert "ls | wc -l" in out[1]
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def test_inline_styles():
|
|
57
|
+
t = inline("a **bold** b *it* c `code` [docs](https://x.y)")
|
|
58
|
+
assert t.plain == "a bold b it c code docs (https://x.y)"
|
|
59
|
+
styles = {t.plain[s.start:s.end]: str(s.style) for s in t.spans}
|
|
60
|
+
assert "bold" in styles["bold"] and "italic" in styles["it"]
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_snake_case_and_math_stay_literal():
|
|
64
|
+
assert inline("use my_var_name and 2*3*4").plain == "use my_var_name and 2*3*4"
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_lists_headings_quotes_rules():
|
|
68
|
+
out = render("## Plan\n- one\n - two\n1. first\n> quoted\n---\n- [x] done")
|
|
69
|
+
assert out[0] == "Plan"
|
|
70
|
+
assert out[1] == "• one" and out[2] == " • two"
|
|
71
|
+
assert out[3] == "1. first"
|
|
72
|
+
assert out[4] == "│ quoted"
|
|
73
|
+
assert set(out[5]) == {"─"}
|
|
74
|
+
assert out[6] == "☑ done"
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def test_list_item_wraps_under_its_text():
|
|
78
|
+
out = render("- " + "word " * 30, width=40)
|
|
79
|
+
assert out[0].startswith("• ") and all(r.startswith(" ") for r in out[1:])
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_code_block_keeps_indentation():
|
|
83
|
+
out = render("```python\ndef f():\n return 1\n```")
|
|
84
|
+
assert out == ["python", " def f():", " return 1"]
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def test_split_row_respects_code_and_escapes():
|
|
88
|
+
assert split_row("| `a|b` | c \\| d |") == ["`a|b`", "c | d"]
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def test_render_table_header_bold():
|
|
92
|
+
rows = render_table(TABLE, 80)
|
|
93
|
+
header = rows[1]
|
|
94
|
+
assert any("bold" in str(s.style) for s in header.spans)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/builtin_skills/build-from-reference/SKILL.md
RENAMED
|
File without changes
|
{euron_code-0.6.0 → euron_code-0.7.0}/src/euron_code/builtin_skills/explain-codebase/SKILL.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|