@yahyahammad/venastine 0.3.13 → 0.3.15
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.
- package/README.md +12 -12
- package/config.py +3 -1
- package/core/client.py +21 -2
- package/core/compaction.py +11 -5
- package/core/config_loader.py +1 -1
- package/core/interaction.py +1 -1
- package/core/loop.py +104 -4
- package/core/memory.py +4 -1
- package/core/pipeline_models.py +10 -10
- package/core/reasoning/json_retry.py +15 -0
- package/core/reasoning/orchestrator.py +14 -5
- package/core/reasoning/review.py +1 -1
- package/core/reasoning/source_scoring.py +1 -1
- package/logging_setup.py +1 -1
- package/main.py +39 -12
- package/mcp_client/client.py +1 -1
- package/memories/manager.py +1 -1
- package/package.json +1 -1
- package/project_init/config_files.py +4 -4
- package/pyproject.toml +1 -1
- package/security/posture.py +14 -13
- package/security/sandbox.py +1 -1
- package/storage.py +42 -5
- package/tools/builtin/file_ops.py +1 -1
- package/tools/builtin/shell.py +5 -5
- package/tools/builtin/shell_sessions.py +1 -1
- package/tui/app.py +15 -6
- package/tui/themes.py +129 -8
- package/tui/widgets.py +1 -1
package/tui/themes.py
CHANGED
|
@@ -29,8 +29,11 @@ here sets it: these fourteen are RGB palettes, which is the whole
|
|
|
29
29
|
premise of the contrast floors they are held to.
|
|
30
30
|
"""
|
|
31
31
|
|
|
32
|
+
import colorsys
|
|
32
33
|
import logging
|
|
33
34
|
|
|
35
|
+
from rich.color import Color as RichColor
|
|
36
|
+
from rich.color import ColorSystem
|
|
34
37
|
from textual.color import Color
|
|
35
38
|
from textual.theme import Theme
|
|
36
39
|
|
|
@@ -332,7 +335,102 @@ def _tint(colour: str, background: str,
|
|
|
332
335
|
return Color.parse(colour).blend(Color.parse(background), factor).hex
|
|
333
336
|
|
|
334
337
|
|
|
335
|
-
|
|
338
|
+
# Batch 257. How many colours the terminal can show, by the names Rich's
|
|
339
|
+
# `Console.color_system` reports them under. A blended band is designed
|
|
340
|
+
# in truecolour, and Rich ROUNDS every colour to the nearest one the
|
|
341
|
+
# terminal has. On 256 colours that sent dark-plain's added-line band
|
|
342
|
+
# (#1E2F27) to #000000 -- the page's own colour, so the band vanished --
|
|
343
|
+
# while the removed-line band (#35201F) landed on #5f0000 and stayed.
|
|
344
|
+
# Measured on the owner's WSL install, which runs with
|
|
345
|
+
# TERM=xterm-256color and no COLORTERM, so Rich picks 256 there.
|
|
346
|
+
TRUECOLOUR = "truecolor"
|
|
347
|
+
EIGHT_BIT = "256"
|
|
348
|
+
SIXTEEN = frozenset({"standard", "windows"})
|
|
349
|
+
|
|
350
|
+
#: The six hues the xterm cube can draw at a band's depth, in the order
|
|
351
|
+
#: of the hue circle from red. A channel is 1 where that hue has it.
|
|
352
|
+
_CUBE_HUES = ((1, 0, 0), (1, 1, 0), (0, 1, 0), (0, 1, 1), (0, 0, 1),
|
|
353
|
+
(1, 0, 1))
|
|
354
|
+
|
|
355
|
+
#: The same six as the terminal's own colour names, for a sixteen-colour
|
|
356
|
+
#: terminal: the colours git, diff and patch use there.
|
|
357
|
+
_ANSI_HUES = ("red", "yellow", "green", "cyan", "blue", "magenta")
|
|
358
|
+
|
|
359
|
+
#: The cube levels a 256-colour band takes, as (channel absent, channel
|
|
360
|
+
#: present). The cube's levels are 0, 95, 135, 175, 215 and 255.
|
|
361
|
+
#: On a dark page the band is the hue at the cube's first step out of
|
|
362
|
+
#: black (#005f00, #5f0000). On a light page it is the hue two steps in
|
|
363
|
+
#: from white (#afd7af, #d7afaf); one step in (#d7ffd7, #ffd7d7) stands
|
|
364
|
+
#: off light-plain's page at 1.06:1 and 1.13:1, under X7's 1.15 floor.
|
|
365
|
+
_CUBE_DARK = (0, 1)
|
|
366
|
+
_CUBE_LIGHT = (3, 4)
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
def _hue_sector(colour: str) -> int:
|
|
370
|
+
"""Which of the six cube hues `colour` is nearest, as an index into
|
|
371
|
+
`_CUBE_HUES`. Rounding the hue to a sixth of the circle is all the
|
|
372
|
+
resolution a band at one cube step has."""
|
|
373
|
+
red, green, blue = Color.parse(colour).rgb
|
|
374
|
+
hue, _sat, _val = colorsys.rgb_to_hsv(red / 255, green / 255, blue / 255)
|
|
375
|
+
return round(hue * 6) % 6
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
def _cube_band(colour: str, dark: bool) -> int:
|
|
379
|
+
"""`colour`'s hue as a band on the xterm cube, as a colour number.
|
|
380
|
+
|
|
381
|
+
Placed on the cube rather than blended and left to Rich to round,
|
|
382
|
+
because the rounding is what lost the band: the cube is fixed, so
|
|
383
|
+
a band chosen on it is the band the terminal paints. Still derived
|
|
384
|
+
from the theme's own hue (#116), only at the cube's resolution."""
|
|
385
|
+
absent, present = _CUBE_DARK if dark else _CUBE_LIGHT
|
|
386
|
+
red, green, blue = (present if channel else absent
|
|
387
|
+
for channel in _CUBE_HUES[_hue_sector(colour)])
|
|
388
|
+
return 16 + 36 * red + 6 * green + blue
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
def _as_256(colour: str) -> int:
|
|
392
|
+
"""The colour number Rich paints `colour` as on a 256-colour
|
|
393
|
+
terminal: its own downgrade, so the comparison below is against the
|
|
394
|
+
page the reader actually sees."""
|
|
395
|
+
return RichColor.parse(colour).downgrade(ColorSystem.EIGHT_BIT).number
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
def _diff_styles(palette: dict[str, str], dark: bool,
|
|
399
|
+
depth: str | None) -> tuple[str, str]:
|
|
400
|
+
"""The added and removed rows' styles at the terminal's colour depth.
|
|
401
|
+
|
|
402
|
+
Truecolour, and a depth Rich could not name, keep X7's blended band.
|
|
403
|
+
256 colours put the band on the cube (`_cube_band`). Sixteen colours
|
|
404
|
+
have no band to give, so the row takes the hue as its TEXT colour,
|
|
405
|
+
the ANSI themes' rule. An ANSI theme keeps that rule at every depth:
|
|
406
|
+
its colours are the terminal's own, with no RGB to measure.
|
|
407
|
+
|
|
408
|
+
A 256-colour band that would land on the page's own colour, or on
|
|
409
|
+
the other band, falls back to the sixteen-colour form. No shipped
|
|
410
|
+
theme reaches it (tests/test_themes.py holds that); a theme from
|
|
411
|
+
ctrl+p's list might.
|
|
412
|
+
"""
|
|
413
|
+
success, error = palette["success"], palette["error"]
|
|
414
|
+
page, text = palette["background"], palette["foreground"]
|
|
415
|
+
measured = all(c.startswith("#") for c in (success, error, page))
|
|
416
|
+
if not measured:
|
|
417
|
+
add, delete = _tint(success, page), _tint(error, page)
|
|
418
|
+
return (f"{text} on {add}" if add else success,
|
|
419
|
+
f"{text} on {delete}" if delete else error)
|
|
420
|
+
as_text = (_ANSI_HUES[_hue_sector(success)],
|
|
421
|
+
_ANSI_HUES[_hue_sector(error)])
|
|
422
|
+
if depth in SIXTEEN:
|
|
423
|
+
return as_text
|
|
424
|
+
if depth == EIGHT_BIT:
|
|
425
|
+
add, delete = _cube_band(success, dark), _cube_band(error, dark)
|
|
426
|
+
if add == delete or _as_256(page) in (add, delete):
|
|
427
|
+
return as_text
|
|
428
|
+
return f"{text} on color({add})", f"{text} on color({delete})"
|
|
429
|
+
return (f"{text} on {_tint(success, page)}",
|
|
430
|
+
f"{text} on {_tint(error, page)}")
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
def role_styles(theme: Theme, depth: str | None = TRUECOLOUR) -> dict[str, str]:
|
|
336
434
|
"""Rich style strings keyed by transcript role, for one theme.
|
|
337
435
|
|
|
338
436
|
Roles are what a line MEANS, not where it came from: `pass` covers a
|
|
@@ -344,10 +442,16 @@ def role_styles(theme: Theme) -> dict[str, str]:
|
|
|
344
442
|
leave a slot at None or fill it with textual's `ansi_*` names,
|
|
345
443
|
and one of them took the whole app down at mount. `_palette`
|
|
346
444
|
fills and translates; nothing below can see the difference.
|
|
445
|
+
|
|
446
|
+
`depth` is the terminal's colour depth as Rich names it, and only
|
|
447
|
+
the two diff rows read it (batch 257): they are the one place this
|
|
448
|
+
table sets a background, and a background is what Rich's rounding
|
|
449
|
+
can merge into the page. Every other role is a foreground, which
|
|
450
|
+
rounding moves but cannot hide. The default is truecolour, which is
|
|
451
|
+
what every caller but `styles_for` means.
|
|
347
452
|
"""
|
|
348
453
|
palette = _palette(theme)
|
|
349
|
-
|
|
350
|
-
delete = _tint(palette["error"], palette["background"])
|
|
454
|
+
diff_add, diff_del = _diff_styles(palette, theme.dark, depth)
|
|
351
455
|
return {
|
|
352
456
|
# Who is speaking. The hues, because these distinguish identity.
|
|
353
457
|
"user": f"bold {palette['primary']}",
|
|
@@ -443,10 +547,12 @@ def role_styles(theme: Theme) -> dict[str, str]:
|
|
|
443
547
|
# was the alternative, and DIFF_TINT's comment above turns that
|
|
444
548
|
# down for every theme that CAN be measured; picking it for the
|
|
445
549
|
# one that cannot would be backwards.
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
550
|
+
#
|
|
551
|
+
# And unless the terminal cannot show the blend. `_diff_styles`
|
|
552
|
+
# puts the band on the xterm cube at 256 colours and falls back
|
|
553
|
+
# to the foreground form at sixteen (batch 257).
|
|
554
|
+
"diff_add": diff_add,
|
|
555
|
+
"diff_del": diff_del,
|
|
450
556
|
# Unchanged context recedes: it is there to place the change,
|
|
451
557
|
# not to be read. `secondary` rather than a dimmed foreground
|
|
452
558
|
# for X1's reason -- `dim` is an attribute no floor can
|
|
@@ -509,6 +615,21 @@ def role_styles(theme: Theme) -> dict[str, str]:
|
|
|
509
615
|
_UNSTYLABLE: set[str] = set()
|
|
510
616
|
|
|
511
617
|
|
|
618
|
+
def colour_depth(app) -> str | None:
|
|
619
|
+
"""How many colours `app`'s terminal shows, as Rich names it.
|
|
620
|
+
|
|
621
|
+
Read off Textual's own console, because that console is what renders
|
|
622
|
+
the screen: Rich decides the depth there from COLORTERM and TERM
|
|
623
|
+
(TEXTUAL_COLOR_SYSTEM overrides it), and downgrades every colour to
|
|
624
|
+
it on the way out. None when it cannot be read, which `role_styles`
|
|
625
|
+
treats as truecolour -- what this module did before it asked.
|
|
626
|
+
"""
|
|
627
|
+
try:
|
|
628
|
+
return app.console.color_system
|
|
629
|
+
except Exception: # noqa: BLE001 -- no console yet; keep the blend
|
|
630
|
+
return None
|
|
631
|
+
|
|
632
|
+
|
|
512
633
|
def styles_for(app) -> dict[str, str]:
|
|
513
634
|
"""The active theme's role styles, or unstyled when there is no app.
|
|
514
635
|
|
|
@@ -550,7 +671,7 @@ def styles_for(app) -> dict[str, str]:
|
|
|
550
671
|
if theme is None:
|
|
551
672
|
return {}
|
|
552
673
|
try:
|
|
553
|
-
return role_styles(theme)
|
|
674
|
+
return role_styles(theme, colour_depth(app))
|
|
554
675
|
except Exception: # noqa: BLE001 -- a theme this build cannot resolve
|
|
555
676
|
name = getattr(theme, "name", "?")
|
|
556
677
|
if name not in _UNSTYLABLE:
|
package/tui/widgets.py
CHANGED
|
@@ -430,7 +430,7 @@ class PostureBadge(Static):
|
|
|
430
430
|
§40 (UN3). The startup banner scrolls away; a posture does not. The
|
|
431
431
|
case this exists for is not the researcher who just typed a flag --
|
|
432
432
|
it is the user who set `ALLOW_INSECURE_SANDBOX_FALLBACK` months ago
|
|
433
|
-
and forgot, or who inherited a config.
|
|
433
|
+
and forgot, or who inherited a config.yaml from somewhere. Neither of
|
|
434
434
|
them reads app.log.
|
|
435
435
|
|
|
436
436
|
Hidden when the posture is the shipped one, GoalBanner-style, so it
|