@yahyahammad/venastine 0.1.0 → 0.2.0

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/tui/app.py CHANGED
@@ -32,14 +32,16 @@ import json
32
32
  import logging
33
33
  import os
34
34
  import queue
35
+ from time import monotonic
35
36
  from pathlib import Path
36
37
  from uuid import UUID
37
38
 
38
39
  from textual.app import App, ComposeResult
40
+ from textual.binding import Binding
39
41
  from textual.containers import Horizontal, Vertical
40
42
  from textual.css.query import NoMatches
41
43
  from textual.message import Message
42
- from textual.widgets import Footer, Header, Input
44
+ from textual.widgets import Footer, Header
43
45
  from textual.worker import Worker, WorkerState
44
46
 
45
47
  import config
@@ -51,6 +53,7 @@ from memories.tui_commands import register_memory_commands
51
53
  from project_init.tui_commands import register_init_commands
52
54
  from skills.tui_commands import register_skill_commands
53
55
  from core import config_loader
56
+ from core.agent_activity import AgentActivity
54
57
  from core.approval import RunAuthorization
55
58
  from core.client import api_initialization, effort_levels_for_model
56
59
  from core.loop import (
@@ -69,7 +72,7 @@ from safety.policy_enforcement import (
69
72
 
70
73
  from tools.builtin import file_ops
71
74
  from tools.registry import registry as tool_registry
72
- from tui import diffs, preferences, ravens, themes
75
+ from tui import diffs, history, meters, preferences, ravens, themes
73
76
  from tui.commands import SlashCommand, registry as commands
74
77
  from tui.screens import (
75
78
  ClaimsScreen, ConfirmScreen, GrantPickerScreen, PermissionScreen,
@@ -78,8 +81,10 @@ from tui.screens import (
78
81
  )
79
82
  from security import posture
80
83
  from tui.widgets import (
81
- CONVERSATION_ROLES, EffortRaven, GoalBanner, PostureBadge, RavenPanel,
82
- ResearchProgress, ThinkingIndicator, TodoPanel, Transcript, UsageLine,
84
+ AgentPanel, ANIMATION_INTERVAL,
85
+ CONVERSATION_ROLES, EffortRaven, GoalBanner, PostureBadge, PromptInput,
86
+ RavenPanel, ResearchProgress, SlashSuggest, ThinkingIndicator, TodoPanel,
87
+ Transcript, UsageLine,
83
88
  )
84
89
 
85
90
  logger = logging.getLogger(__name__)
@@ -98,6 +103,13 @@ DIFFED_TOOLS = ("write", "edit")
98
103
  #: without line numbers.
99
104
  DIFF_SNAPSHOT_MAX_BYTES = 512_000
100
105
 
106
+ #: How long a first ctrl+c stays armed (batch 57). Short enough that
107
+ #: "twice in quick succession" is the only way through it, and it is also
108
+ #: how long the footer says so -- the label reverts on this timer, so the
109
+ #: window is something the screen shows rather than something the user has
110
+ #: to guess at.
111
+ QUIT_CONFIRM_S = 2.0
112
+
101
113
 
102
114
  class LoopEventMessage(Message):
103
115
  """One LoopEvent, forwarded from the worker thread to the UI thread.
@@ -278,6 +290,59 @@ class OneShotFinished(Message):
278
290
  super().__init__()
279
291
 
280
292
 
293
+ class AgentStackChanged(Message):
294
+ """The set of running agent-shaped runs changed (batch 59).
295
+
296
+ Carries the WHOLE stack rather than a delta. The sink runs on the
297
+ worker thread and the handler on the UI thread, so a message per
298
+ push/pop would have the panel reassembling an order it did not
299
+ observe; a snapshot cannot disagree with itself.
300
+ """
301
+
302
+ def __init__(self, stack) -> None:
303
+ super().__init__()
304
+ self.stack = list(stack)
305
+
306
+
307
+ class TuiActivity(AgentActivity):
308
+ """core/agent_activity.py's sink, wired to the sidebar.
309
+
310
+ CALLED ON THE WORKER THREAD -- spawn_subagent opens its span inside
311
+ registry.dispatch(), which is inside the loop generator this app
312
+ drains in run_worker(thread=True). So this touches no widget and
313
+ posts instead, exactly as _consume does; post_message is the
314
+ thread-safe half of the API and `self._stack` below is read and
315
+ written only here, under the worker's own serialisation.
316
+
317
+ The stack is kept HERE rather than on the app because the enter/exit
318
+ pairing is this object's business: the app holds what it was last
319
+ told to draw, which is a different question and one the UI thread
320
+ owns.
321
+ """
322
+
323
+ def __init__(self, app) -> None:
324
+ self._app = app
325
+ self._stack: list = []
326
+
327
+ def enter(self, span) -> None:
328
+ self._stack.append((span.name, span.depth))
329
+ self._post()
330
+
331
+ def exit(self, span) -> None:
332
+ # Remove the LAST matching entry, not the first: two spans can
333
+ # legitimately share a name and a depth across one turn (a goal
334
+ # turn spawning `explore` twice), and popping the wrong one would
335
+ # leave the panel one row off for the rest of the run.
336
+ entry = (span.name, span.depth)
337
+ for i in range(len(self._stack) - 1, -1, -1):
338
+ if self._stack[i] == entry:
339
+ del self._stack[i]
340
+ break
341
+ self._post()
342
+
343
+ def _post(self) -> None:
344
+ self._app.post_message(AgentStackChanged(self._stack))
345
+
281
346
  class VenastineApp(App):
282
347
  """Chat + research shell."""
283
348
 
@@ -285,15 +350,53 @@ class VenastineApp(App):
285
350
  TITLE = "Venastine Research Harness"
286
351
 
287
352
  BINDINGS = [
288
- ("ctrl+c", "quit", "Quit"),
353
+ # Batch 57. TWO bindings on one key, and `check_action` decides
354
+ # which is live -- textual's dynamic-actions path, and the only
355
+ # way to relabel a footer entry, since a Binding's description is
356
+ # fixed at class definition. The armed one is listed FIRST so it
357
+ # claims the slot the moment it is enabled (`active_bindings` is a
358
+ # dict keyed by KEY, first writer wins).
359
+ #
360
+ # `priority=True` on both, and it is what makes ctrl+c work at
361
+ # all: `Input` and `TextArea` bind ctrl+c to `copy`, the prompt
362
+ # holds focus almost always, and an ordinary app binding loses to
363
+ # the focused widget -- measured, `("ctrl+c", "quit")` fired under
364
+ # NEITHER text box. It also loses under a modal, which blocks
365
+ # non-priority app bindings outright. The cost of the flag is that
366
+ # it takes the copy away too, which is why `_copy_selection` gives
367
+ # it back; see `action_arm_quit`.
368
+ Binding("ctrl+c", "confirm_quit", "Press again to quit",
369
+ priority=True),
370
+ Binding("ctrl+c", "arm_quit", "Quit", priority=True),
289
371
  ("ctrl+t", "pick_thread", "Threads"),
290
- # §26. ctrl+l, NOT ctrl+k: Textual's Input binds ctrl+k to
291
- # delete_right_all and the input holds focus almost always, so a
372
+ # §26. ctrl+l, NOT ctrl+k: the prompt binds ctrl+k to a
373
+ # delete-to-end-of-line and it holds focus almost always, so a
292
374
  # ctrl+k binding here would be shadowed -- pressing it would
293
- # silently delete the rest of the typed line instead. ctrl+l is
294
- # bound by neither Input, App nor Footer on the pinned textual
375
+ # silently delete the rest of the typed line instead. Still true
376
+ # after batch 54 swapped Input for TextArea: BOTH bind ctrl+k,
377
+ # and neither binds ctrl+l, which App and Footer also leave free
295
378
  # (D22: verified against the installed version, not assumed).
296
379
  ("ctrl+l", "show_claims", "Claims"),
380
+ # Batch 63. ctrl+UP/DOWN, and the pair was chosen by
381
+ # elimination rather than by taste. ctrl+p is textual's
382
+ # COMMAND_PALETTE_BINDING, bound priority=True, and the
383
+ # palette is enabled on purpose here -- `watch_theme` exists
384
+ # because it sets App.theme directly. Relocating it to
385
+ # ctrl+shift+p would delete it on Windows: that chord is
386
+ # indistinguishable from ctrl+p without the kitty protocol,
387
+ # which textual turns on in its LINUX drivers alone.
388
+ #
389
+ # The plain arrows were the other candidate and are already
390
+ # spoken for twice -- cursor movement in a box batch 54 made
391
+ # multi-line, and the suggestion panel's highlight since 55.
392
+ # A third meaning gated on the cursor being at line 1 is the
393
+ # shell convention and would have been the third.
394
+ #
395
+ # Free, measured off `screen.active_bindings` with the prompt
396
+ # focused, which is App, Screen and TextArea's forty-odd
397
+ # editing keys in one list rather than a docs page.
398
+ ("ctrl+up", "recall_previous", "Previous"),
399
+ ("ctrl+down", "recall_next", "Next"),
297
400
  ]
298
401
 
299
402
  # Set by exit(); consulted by the blocking ask paths (review §19-20
@@ -305,6 +408,27 @@ class VenastineApp(App):
305
408
  # instead of raising.
306
409
  _shutting_down = False
307
410
 
411
+ # Batch 57's quit gesture. CLASS attributes for `_shutting_down`'s
412
+ # reason, and read by `check_action`, which textual calls while the
413
+ # footer is composing -- before anything of ours has run.
414
+ _quit_armed = False
415
+ _quit_timer = None
416
+
417
+ # Batch 61. CLASS-level defaults, so an app built with __new__ and
418
+ # no __init__ -- four tests do exactly that, to exercise one method
419
+ # against a handful of injected attributes -- can assign `_busy`
420
+ # without an AttributeError. Transcript._styles' rule applied to
421
+ # state instead of to styling: a bare object degrades to doing
422
+ # nothing, because there is no screen to paint and no clock worth
423
+ # keeping.
424
+ _busy_state = False
425
+ _meter = None
426
+ _meter_timer = None
427
+ _meter_last = None
428
+ _last_turn_elapsed = None
429
+ _turn_output_tokens = None
430
+ _history = None
431
+
308
432
  def __init__(self, provider_name: str = DEFAULT_PROVIDER,
309
433
  model: str = None, settings: dict | None = None,
310
434
  cli_pinned: bool = False):
@@ -394,7 +518,35 @@ class VenastineApp(App):
394
518
  self._todo_position = tui_settings.get("todo_position", "side")
395
519
 
396
520
  self._memory: ConversationMemory | None = None
521
+ # The transcript, held rather than re-queried. See the `_transcript`
522
+ # property and on_mount; None until mounted, which is the state
523
+ # every test that builds this app without a pilot is in.
524
+ self._transcript_widget: "Transcript | None" = None
397
525
  self._permission_channel: queue.Queue | None = None
526
+ # Batch 61. BEFORE the `_busy` assignment below, which is a
527
+ # property setter now and drives this object.
528
+ self._meter = meters.TurnMeter()
529
+ self._meter_timer = None
530
+ self._meter_last = None
531
+ #: The last finished turn's active seconds, stashed by the
532
+ #: setter for the exit handler that writes the line. The
533
+ #: setter owns the CLOCK; saying so in the transcript stays
534
+ #: at the exits, because `_busy` is also cleared on paths
535
+ #: where no turn ever ran.
536
+ self._last_turn_elapsed = None
537
+ #: The finished turn's OUTPUT tokens, off the terminal
538
+ #: response. None where the provider reports no usage, which
539
+ #: is sixteen of the nineteen configured ones -- and None is
540
+ #: why the completion line can decline to claim a count
541
+ #: instead of printing a zero.
542
+ self._turn_output_tokens = None
543
+ # Batch 63. The prompts submitted this session. Session-scoped
544
+ # and in memory: it records what the PERSON typed rather than
545
+ # what a thread holds, so it survives /new and /resume -- a
546
+ # misfire bad enough to start a new thread is exactly when the
547
+ # text is wanted back.
548
+ self._history = history.PromptHistory()
549
+ self._busy_state = False
398
550
  self._busy = False
399
551
  # §18 session-scoped active agent (/agent switch). None = default
400
552
  # harness. Applies to subsequent turns until switched or cleared.
@@ -428,6 +580,12 @@ class VenastineApp(App):
428
580
  # that clear it; a per-turn map that outlives its turn is a
429
581
  # leak on an app that stays open for hours.
430
582
  self._file_calls: dict = {}
583
+ # Batch 59. The sidebar's view of who is running. `_agent_stack` is
584
+ # what the panel was last told to draw and is touched ONLY on the
585
+ # UI thread, in on_agent_stack_changed; the sink that feeds it
586
+ # keeps its own copy on the worker side. One writer each.
587
+ self._agent_stack: list = []
588
+ self._activity = TuiActivity(self)
431
589
 
432
590
  # -- layout --------------------------------------------------------------
433
591
 
@@ -453,7 +611,16 @@ class VenastineApp(App):
453
611
  id="thinking-indicator")
454
612
  if self._todo_position == "bottom":
455
613
  yield TodoPanel(id="todo-panel")
456
- yield Input(placeholder="Message, or /help", id="prompt")
614
+ # Batch 55. LAST before the prompt, and that is the whole
615
+ # placement: #prompt is dock: bottom, so the last widget in
616
+ # the flow lands directly above it and the panel opens
617
+ # upwards without a layer, an offset or a screen. Hidden
618
+ # until a slash is typed, ThinkingIndicator-style.
619
+ yield SlashSuggest(id="slash-suggest")
620
+ # Batch 54. Wraps and grows to four rows as it is typed,
621
+ # then collapses on submit -- see PromptInput for why this
622
+ # is a TextArea and what `priority=True` buys on enter.
623
+ yield PromptInput(placeholder="Message, or /help", id="prompt")
457
624
  with Vertical(id="sidebar"):
458
625
  yield RavenPanel(animations=self._animations, id="raven")
459
626
  yield EffortRaven(id="effort-raven")
@@ -462,6 +629,12 @@ class VenastineApp(App):
462
629
  # transcript where it would scroll away.
463
630
  yield PostureBadge(posture.current().unsafe_reasons(),
464
631
  id="posture-badge")
632
+ # Batch 59. Under the posture badge, which §40 put above
633
+ # the ravens' siblings and wants kept in view; above the
634
+ # usage line, so "who is working" sits with the ravens
635
+ # rather than among the figures. Hidden until there is an
636
+ # agent or a spawn, PostureBadge-style.
637
+ yield AgentPanel(id="agent-panel")
465
638
  # #4: billed-since-resume and current context size, one
466
639
  # line. Hidden until a turn produces figures.
467
640
  yield UsageLine(id="usage-line")
@@ -471,6 +644,12 @@ class VenastineApp(App):
471
644
  yield Footer()
472
645
 
473
646
  def on_mount(self) -> None:
647
+ # HELD BEFORE THE LOG HANDLER IS ATTACHED, because the handler is
648
+ # the fastest way to need it: the first routed WARNING can arrive
649
+ # from any thread at any moment, including one where a modal is
650
+ # on top. See the `_transcript` property for why holding it is
651
+ # what makes that survivable.
652
+ self._transcript_widget = self.query_one("#transcript", Transcript)
474
653
  # Attached before anything else can log. Removed in on_unmount --
475
654
  # the handler holds a reference to this app, so leaving it on the
476
655
  # root logger would keep a dead app alive and, in the test suite,
@@ -489,7 +668,20 @@ class VenastineApp(App):
489
668
  self.query_one("#effort-raven", EffortRaven).effort = self.effort
490
669
  self.refresh_goal_banner()
491
670
  self.refresh_todo_panel()
671
+ self.refresh_agent_panel()
492
672
  self.refresh_status()
673
+ # Batch 61. HERE and not in __init__: "up" means the shell
674
+ # has been on screen, not that an object was constructed.
675
+ self._meter.begin_session(monotonic())
676
+ if self._animations:
677
+ # RavenPanel's cadence, spelled once and imported. Created
678
+ # PAUSED (ThinkingIndicator's shape) and resumed only while
679
+ # a turn runs -- `tui.animations: false` therefore costs
680
+ # exactly the two silences a token delta cannot cover: a
681
+ # long tool call, and pre-first-token latency.
682
+ self._meter_timer = self.set_interval(
683
+ ANIMATION_INTERVAL, self._refresh_meter, pause=True)
684
+ self._refresh_meter()
493
685
  self._write_session_banner()
494
686
  # #138. Beside the status line it qualifies, before anything the
495
687
  # user might type. write_error, matching /model: an unknown
@@ -497,7 +689,13 @@ class VenastineApp(App):
497
689
  for warning in self._startup_warnings:
498
690
  self._transcript.write_error(warning)
499
691
  self._transcript.write_system("Type /help for commands.")
500
- self.query_one("#prompt", Input).focus()
692
+ prompt = self.query_one("#prompt", PromptInput)
693
+ # Batch 55. Handed over once, here, rather than looked up per
694
+ # keystroke: app.py stays the thing that introduces two widgets to
695
+ # each other, and a PromptInput built bare (which the suite does)
696
+ # keeps `suggest = None` and behaves exactly as it did in batch 54.
697
+ prompt.suggest = self.query_one("#slash-suggest", SlashSuggest)
698
+ prompt.focus()
501
699
  if self.effort and self._effort_named:
502
700
  # A persisted effort level was trusted as-is and sent on every
503
701
  # turn, unlike the sibling tui.theme three lines up which gets
@@ -663,6 +861,135 @@ class VenastineApp(App):
663
861
  f"| theme {self._theme_name}"
664
862
  )
665
863
 
864
+ # -- the turn meter (batch 61) ------------------------------------------
865
+
866
+ @property
867
+ def _busy(self) -> bool:
868
+ return self._busy_state
869
+
870
+ @_busy.setter
871
+ def _busy(self, value) -> None:
872
+ """The one funnel a turn clock can hang off.
873
+
874
+ A PROPERTY rather than a rename, and the arithmetic is the
875
+ argument: `_busy` is written at eleven sites with four distinct
876
+ turn exits (on_turn_finished, on_one_shot_finished,
877
+ on_research_finished, and _cmd_compact's worker `finally` via
878
+ call_from_thread), and read by 89 references across 11 test
879
+ files. A clock started at one of those and stopped at another
880
+ WILL leak -- that is the defect batch 60 removed from
881
+ core/loop.py, one layer up. Batch 54 made the same trade for
882
+ the same reason: a one-line property is cheaper than sixty
883
+ edits made to land a rendering change.
884
+
885
+ Guarded like Transcript._styles: this runs during __init__ and
886
+ in bare-built apps across the suite, where there is no screen
887
+ to query and no timer to move.
888
+ """
889
+ value = bool(value)
890
+ was = self._busy_state
891
+ self._busy_state = value
892
+ if self._meter is None:
893
+ # A bare-built app (see the class defaults above): the flag
894
+ # is the whole contract there.
895
+ return
896
+ if value == was:
897
+ # Idempotent. `_busy = True` is assigned twice on at least
898
+ # one path, and the second must not restart the clock.
899
+ return
900
+ now = monotonic()
901
+ if value:
902
+ self._meter.start(now)
903
+ else:
904
+ self._last_turn_elapsed = self._meter.stop(now)
905
+ self._sync_meter_timer()
906
+ self._refresh_meter()
907
+
908
+ def _sync_meter_timer(self) -> None:
909
+ """Tick only while a turn is running (ThinkingIndicator's rule).
910
+
911
+ A 0.4s tick against an idle shell is exactly the redraw loop
912
+ RavenPanel.pause_animation exists to avoid. The price, named
913
+ rather than discovered: uptime is refreshed at every turn
914
+ boundary and on every loop event, so a session left idle shows
915
+ the uptime it had when the last turn ended until the next one
916
+ starts."""
917
+ if self._meter_timer is None:
918
+ return
919
+ if self._busy_state:
920
+ self._meter_timer.resume()
921
+ else:
922
+ self._meter_timer.pause()
923
+
924
+ def _refresh_meter(self) -> None:
925
+ """Paint the live figures onto the prompt's bottom border.
926
+
927
+ THE BORDER SUBTITLE, which costs zero rows -- and #prompt's
928
+ border TITLE is already taken by the TextArea placeholder,
929
+ which a TextArea has no other way to carry. RichLog cannot
930
+ rewrite a drawn row, so the live half could never have lived
931
+ in the transcript; this is the nearest surface to the input
932
+ box that redraws.
933
+
934
+ EVENT-DRIVEN FIRST, timed second. on_loop_event_message calls
935
+ this once per token delta, and those keep arriving while the
936
+ commit cap withholds a table -- it is the renderer that is
937
+ holding, not the stream -- so the figures stay live through
938
+ the silence whether or not the timer is running. The
939
+ change-guard is what makes that nearly free (UsageLine's
940
+ shape): a repaint happens only when the rendered string is
941
+ actually different.
942
+
943
+ The modal pause is read off the SCREEN STACK rather than
944
+ hooked into the four push_screen sites, so every modal counts
945
+ including ones added after this batch. Measured: textual's
946
+ on_screen_suspend does not reach the App, but the stack depth
947
+ moves 1 -> 2 -> 1 reliably.
948
+ """
949
+ if self._meter is None:
950
+ return
951
+ now = monotonic()
952
+ try:
953
+ blocked = len(self.screen_stack) > 1
954
+ except Exception: # noqa: BLE001 -- no screen yet; nothing is blocking
955
+ blocked = False
956
+ self._meter.set_blocked(blocked, now)
957
+ text = self._meter.subtitle(now)
958
+ if text == self._meter_last:
959
+ return
960
+ self._meter_last = text
961
+ try:
962
+ self.query_one('#prompt', PromptInput).border_subtitle = text or ''
963
+ except Exception: # noqa: BLE001 -- unmounted; nothing to paint
964
+ pass
965
+
966
+ def _write_turn_time(self) -> None:
967
+ """Say the turn is over, under the answer it belongs to.
968
+
969
+ `system` -- the harness talking about itself -- which is
970
+ already in META_ROLES, so /copy conversation keeps excluding
971
+ it. A new role would have to be classified in both role sets,
972
+ and tests/test_themes.py holds both halves against
973
+ MESSAGE_ROLES.
974
+
975
+ The exact token count is the provider's own, and where a
976
+ provider reports none NO TOKEN CLAIM IS MADE -- a zero would
977
+ say the model wrote nothing on sixteen of the nineteen
978
+ configured providers (D21: OpenAI-compatible streaming reports
979
+ no usage unless stream_options is sent, which Mistral rejects
980
+ outright)."""
981
+ if self._meter is None:
982
+ return
983
+ elapsed = self._last_turn_elapsed
984
+ self._last_turn_elapsed = None
985
+ if elapsed is None:
986
+ # `_busy` was cleared without a turn having run.
987
+ return
988
+ self._transcript.write_role(
989
+ 'system',
990
+ self._meter.completion(elapsed, self._turn_output_tokens))
991
+ self._turn_output_tokens = None
992
+
666
993
  def refresh_status(self) -> None:
667
994
  """Keep the header showing which provider/model turns will use.
668
995
 
@@ -839,6 +1166,38 @@ class VenastineApp(App):
839
1166
 
840
1167
  @property
841
1168
  def _transcript(self) -> Transcript:
1169
+ """The transcript widget, HELD rather than queried per access.
1170
+
1171
+ `query_one` on the app searches the ACTIVE screen, so any pushed
1172
+ modal shadows `#transcript` and this raised `NoMatches` (§27).
1173
+ That was survivable only where a caller remembered to catch it,
1174
+ and the callers who cannot are exactly the ones that fire while a
1175
+ modal is up: `on_log_record_message` for any routed WARNING+, the
1176
+ startup workers' report handlers, and `_timed_out_ask`, whose
1177
+ whole occasion IS an open modal. An exception out of a Textual
1178
+ message handler takes the app down, so a diagnostic could kill the
1179
+ session it was diagnosing -- which is the failure
1180
+ TranscriptLogHandler.emit's own docstring refuses one hop earlier.
1181
+
1182
+ Measured on all three: a `logging.warning` under a `ConfirmScreen`,
1183
+ an `EffortLevelsReady` carrying a probe failure, and a timeout
1184
+ narration for a screen already dismissed. Each killed the app.
1185
+
1186
+ Nothing ever remounts this widget -- there is no `mount()` or
1187
+ `remove()` for it anywhere in the app -- so the reference cannot go
1188
+ stale, and `/new` clears it through `reset()` rather than replacing
1189
+ it. The query remains as the fallback for an app that was
1190
+ constructed but never mounted, which is what most of the suite
1191
+ does, so those tests behave exactly as they did.
1192
+
1193
+ The consequence worth naming: a line written while a modal is up
1194
+ now LANDS, in the real transcript, and is there when the modal
1195
+ closes. The `except NoMatches` guards that used to stand in for
1196
+ this dropped it instead -- and for a routed warning, dropping it
1197
+ defeats the handler that exists because the TUI detached stderr.
1198
+ """
1199
+ if self._transcript_widget is not None:
1200
+ return self._transcript_widget
842
1201
  return self.query_one("#transcript", Transcript)
843
1202
 
844
1203
  @property
@@ -859,10 +1218,14 @@ class VenastineApp(App):
859
1218
  the same moment and a flipped tui.show_thinking cannot leave one
860
1219
  of them running.
861
1220
 
862
- Best-effort, #104's rule: a modal on top means query_one searches
863
- the ACTIVE screen and finds neither widget (§27), and an
864
- undrawable indicator must not be the reason an event handler
865
- dies mid-turn.
1221
+ Best-effort, #104's rule, and it is now about the INDICATOR
1222
+ alone: `_transcript` is held from on_mount and no longer cares
1223
+ which screen is active, but `_thinking_indicator` is still a
1224
+ query, so a modal on top still hides it (§27). An undrawable
1225
+ indicator must not be the reason an event handler dies mid-turn.
1226
+ The transcript half therefore runs where it used to be skipped,
1227
+ which is the right way round -- a thinking span left open under a
1228
+ modal was closed only by whatever wrote next.
866
1229
  """
867
1230
  try:
868
1231
  self._transcript.end_thinking()
@@ -872,10 +1235,57 @@ class VenastineApp(App):
872
1235
 
873
1236
  # -- input ---------------------------------------------------------------
874
1237
 
875
- def on_input_submitted(self, event: Input.Submitted) -> None:
1238
+ def _change_suggestions(self, panel, apply) -> None:
1239
+ """Change the slash panel, and keep the transcript where it was.
1240
+
1241
+ The re-pin is the part that is not obvious. Measured: a panel
1242
+ opening under the transcript takes rows from it and textual does
1243
+ NOT re-pin the scroll -- `scroll_y` stayed at 41 while
1244
+ `max_scroll_y` grew 41 -> 53, so the newest twelve lines of the
1245
+ conversation scrolled silently out of view and came back only when
1246
+ the panel closed. Whether the reader was at the bottom is knowable
1247
+ only BEFORE the relayout, which is why it is captured here and
1248
+ restored after, and why a reader who had deliberately scrolled up
1249
+ is left where they were.
1250
+
1251
+ Batch 56 is why this is a helper rather than a handler body: the
1252
+ panel's window slides, so ARROW KEYS resize it too -- measured, a
1253
+ seven-to-eight-row step unpins the transcript exactly as opening
1254
+ it does, and that one would repeat on most keypresses.
1255
+ """
1256
+ if panel is None:
1257
+ return
1258
+ try:
1259
+ transcript = self._transcript
1260
+ pinned = transcript.scroll_offset.y >= transcript.max_scroll_y
1261
+ except NoMatches: # never mounted (see #104)
1262
+ transcript, pinned = None, False
1263
+ apply()
1264
+ if pinned:
1265
+ self.call_after_refresh(transcript.scroll_end, animate=False)
1266
+
1267
+ def on_prompt_input_suggestions_changed(
1268
+ self, event: PromptInput.SuggestionsChanged) -> None:
1269
+ """The typed line changed, so the offered commands did.
1270
+
1271
+ The panel comes off the event rather than out of a query: the
1272
+ prompt was handed it at mount, and #104's rule would otherwise
1273
+ make this raise the moment a modal is on top (a slash command that
1274
+ pushes a screen clears `.value`, which posts one of these).
1275
+ """
1276
+ panel = event.prompt.suggest
1277
+ self._change_suggestions(panel, lambda: panel.offer(event.matches))
1278
+
1279
+ def on_prompt_input_suggestions_moved(
1280
+ self, event: PromptInput.SuggestionsMoved) -> None:
1281
+ """An arrow key, moving the highlight and possibly the window."""
1282
+ panel = event.prompt.suggest
1283
+ self._change_suggestions(panel, lambda: panel.move(event.delta))
1284
+
1285
+ def on_prompt_input_submitted(self, event: PromptInput.Submitted) -> None:
876
1286
  text = event.value.strip()
877
1287
  if not text:
878
- event.input.value = ""
1288
+ event.prompt.value = ""
879
1289
  return
880
1290
  # Clear AFTER the busy check, not before. /research holds _busy
881
1291
  # for a whole ten-pass pipeline, so a follow-up typed during one
@@ -883,7 +1293,21 @@ class VenastineApp(App):
883
1293
  if not text.startswith("/") and self._busy:
884
1294
  self._transcript.write_error("Still working — wait for this turn to finish.")
885
1295
  return
886
- event.input.value = ""
1296
+ event.prompt.value = ""
1297
+ # Batch 63. AFTER the busy refusal above, which returns without
1298
+ # clearing -- a message that was never sent is not something to
1299
+ # recall. Before the dispatch, so a command that fails is still
1300
+ # there to be corrected, which is most of why this exists.
1301
+ was_empty = not self._history
1302
+ self._history.remember(text)
1303
+ if was_empty:
1304
+ # The Footer recomposes off the screen's bindings signal and
1305
+ # nothing else here raises it, so without this the two
1306
+ # entries stay grey for the session while the keys work --
1307
+ # `action_arm_quit` carries the same comment for the same
1308
+ # reason. Guarded on the transition because that is the only
1309
+ # time the answer changes: a history never empties.
1310
+ self.refresh_bindings()
887
1311
  if text.startswith("/"):
888
1312
  if not commands.dispatch(self, text):
889
1313
  name = text[1:].split(" ")[0]
@@ -978,6 +1402,12 @@ class VenastineApp(App):
978
1402
  config_loader.spend_cap(),
979
1403
  effort=self.effort,
980
1404
  response_channel=self.response_channel(),
1405
+ # Batch 59. Rides beside the response channel because it is the
1406
+ # same kind of thing: an out-of-band object handed down to a
1407
+ # run that happens inside a tool call, where a LoopEvent cannot
1408
+ # reach. This is the route by which a spawn -- and a spawn
1409
+ # inside that spawn -- becomes a row in the sidebar.
1410
+ activity=self._activity,
981
1411
  )
982
1412
  self.run_worker(
983
1413
  lambda: self._consume(generator),
@@ -1070,6 +1500,10 @@ class VenastineApp(App):
1070
1500
  provider_name=provider,
1071
1501
  effort=self.effort,
1072
1502
  authorization=authorization,
1503
+ # continue_conversation drains its own loop, so this
1504
+ # channel is the ONLY way a subagent spawned inside a
1505
+ # /grill-me turn is visible at all.
1506
+ activity=self._activity,
1073
1507
  )
1074
1508
  text = response.text
1075
1509
  notices = list(getattr(response, "notices", ()) or ())
@@ -1107,6 +1541,7 @@ class VenastineApp(App):
1107
1541
 
1108
1542
  def on_one_shot_finished(self, message: OneShotFinished) -> None:
1109
1543
  self._busy = False
1544
+ self._write_turn_time()
1110
1545
  self._raven.resume_animation()
1111
1546
  self._raven.state = ravens.IDLE
1112
1547
  if message.error is not None:
@@ -1167,6 +1602,33 @@ class VenastineApp(App):
1167
1602
  self._memory.billed_tokens, self._memory.last_input_tokens,
1168
1603
  ceiling, overridden)
1169
1604
 
1605
+ def on_agent_stack_changed(self, message: AgentStackChanged) -> None:
1606
+ """The sink spoke. Runs on the UI thread."""
1607
+ self._agent_stack = message.stack
1608
+ self.refresh_agent_panel()
1609
+
1610
+ def refresh_agent_panel(self) -> None:
1611
+ """Redraw the panel from the two facts that make it up: the
1612
+ session's active agent (an /agent switch) and the spans open right
1613
+ now. ONE function, called from both writers -- the sink's handler
1614
+ above and /agent -- so the panel cannot be shown a stack without
1615
+ its root, or a root without its stack.
1616
+
1617
+ `query`, not `query_one`: the sink posts from a worker thread, so
1618
+ an exit landing while the app is being torn down would raise
1619
+ NoMatches out of a message handler on a DOM that no longer has the
1620
+ widget. Measured -- a turn whose spans close as the app closes,
1621
+ which is exactly what an interrupted run looks like. The same
1622
+ shape as removing the log handler in on_unmount: a message can
1623
+ outlive the thing it is about.
1624
+ """
1625
+ panel = self.query("#agent-panel").first(AgentPanel) \
1626
+ if self.query("#agent-panel") else None
1627
+ if panel is None:
1628
+ return
1629
+ name = self.active_agent.name if self.active_agent else None
1630
+ panel.show(name, self._agent_stack)
1631
+
1170
1632
  def restyle_sidebar(self) -> None:
1171
1633
  """Re-render the Rich-styled sidebar widgets after a /theme
1172
1634
  (#183).
@@ -1182,12 +1644,23 @@ class VenastineApp(App):
1182
1644
  self.refresh_goal_banner()
1183
1645
  self.refresh_todo_panel()
1184
1646
  self.query_one("#research-progress", ResearchProgress).restyle()
1647
+ # Batch 59. A Rich-styled sidebar widget like the two above it, so
1648
+ # it needs the same poke -- tcss reaches the panel's box and not
1649
+ # the styles inside its Text.
1650
+ self.query_one("#agent-panel", AgentPanel).restyle()
1185
1651
 
1186
1652
  def on_loop_event_message(self, message: LoopEventMessage) -> None:
1187
1653
  event = message.event
1188
1654
  transcript = self._transcript
1189
1655
 
1190
1656
  self.refresh_usage_line()
1657
+ # Batch 61. Counted whether or not the renderer draws it: the
1658
+ # commit cap withholds a table from its header row with no
1659
+ # HOLD_LIMIT to bound it, and a figure that stopped there
1660
+ # would go still during the one silence it exists to cover.
1661
+ if event.token_delta:
1662
+ self._meter.add_output_chars(len(event.token_delta))
1663
+ self._refresh_meter()
1191
1664
 
1192
1665
  if event.thinking_delta:
1193
1666
  # §38. Same mascot handling as a token delta -- reasoning is
@@ -1234,7 +1707,15 @@ class VenastineApp(App):
1234
1707
  # whenever the model emits that key first.
1235
1708
  digest = tool_registry.call_digest(name, params)
1236
1709
  detail = f" {digest}" if digest else ""
1237
- transcript.write_role("tool", f"▸ {name}{detail}")
1710
+ # Batch 65 (TECHNICAL_DEBT 16). The digest caps a value
1711
+ # at sixty characters, which is shorter than most real
1712
+ # URLs, so the untruncated values ride alongside for a
1713
+ # cut-off span to resolve against. Redacted at the
1714
+ # producer, and a value the redactor rewrote is not
1715
+ # among them -- see `redacted_values`.
1716
+ transcript.write_role(
1717
+ "tool", f"▸ {name}{detail}",
1718
+ tool_registry.call_links(name, params))
1238
1719
 
1239
1720
  if event.tool_result:
1240
1721
  result = event.tool_result["result"]
@@ -1282,6 +1763,14 @@ class VenastineApp(App):
1282
1763
 
1283
1764
  if event.final_response is not None:
1284
1765
  self._end_thinking()
1766
+ # Batch 61's third instrument. NOT turn_billed_tokens (a
1767
+ # spend meter, which counts the prompt again every step)
1768
+ # and NOT turn_new_tokens (a size meter, which adds the
1769
+ # input deltas a tool-using turn brings in). Dividing
1770
+ # either by a duration yields a number that looks like
1771
+ # tok/s and is not.
1772
+ self._turn_output_tokens = getattr(
1773
+ event.final_response, 'turn_output_tokens', None)
1285
1774
  transcript.flush_stream()
1286
1775
  if event.stop_reason and event.stop_reason != "complete":
1287
1776
  transcript.write_system(f"[stopped early: {event.stop_reason}]")
@@ -1392,6 +1881,138 @@ class VenastineApp(App):
1392
1881
  "system",
1393
1882
  f" {path}: the change is entirely inside redacted content")
1394
1883
 
1884
+ # -- quitting (batch 57) -------------------------------------------------
1885
+ #
1886
+ # ctrl+c used to mean four different things depending on what had
1887
+ # focus: it copied in the prompt (and did NOTHING there without a
1888
+ # selection), quit outright one `tab` away, and did nothing at all
1889
+ # under a modal, which blocks non-priority app bindings. README
1890
+ # promised it quit. It now means one thing everywhere, and that one
1891
+ # thing takes two presses, so selecting a typed prompt and copying it
1892
+ # cannot end the session by accident.
1893
+
1894
+ def check_action(self, action: str, parameters) -> bool | None:
1895
+ """Which of the two ctrl+c bindings is live.
1896
+
1897
+ `False`, never `None`, and that is not a style choice.
1898
+ `Screen.active_bindings` skips a binding only on `is False`; a
1899
+ `None` leaves it in the map marked disabled, and the map is keyed
1900
+ by KEY -- so the first ctrl+c binding keeps the slot regardless.
1901
+ Under `None` the DISPATCH is still correct (`_check_bindings`
1902
+ walks past a refused action to the next binding for the same key)
1903
+ and the FOOTER shows the wrong label permanently. Measured, and it
1904
+ is why the footer test asserts on the drawn row rather than on the
1905
+ binding object, where the bug is invisible.
1906
+ """
1907
+ if action == "confirm_quit":
1908
+ return self._quit_armed
1909
+ if action == "arm_quit":
1910
+ return not self._quit_armed
1911
+ if action in ("recall_previous", "recall_next"):
1912
+ # Batch 63, and this is the SAME distinction used the other
1913
+ # way round. ctrl+c needs False because a refused binding
1914
+ # must give up its slot to the other one on that key. These
1915
+ # want None: `active_bindings` KEEPS a None-refused binding,
1916
+ # marked disabled, so the footer greys the entry rather than
1917
+ # dropping it and reflowing -- while `_check_bindings` still
1918
+ # declines the press, so the key is inert on a fresh
1919
+ # session. One return value buys both halves.
1920
+ return True if self._history else None
1921
+ return True
1922
+
1923
+ def action_recall_previous(self) -> None:
1924
+ """ctrl+up: the prompt before this one."""
1925
+ self._recall(-1)
1926
+
1927
+ def action_recall_next(self) -> None:
1928
+ """ctrl+down: the prompt after this one, or the draft back."""
1929
+ self._recall(1)
1930
+
1931
+ def _recall(self, direction: int) -> None:
1932
+ """Put a remembered prompt in the box, cursor at the end.
1933
+
1934
+ The box's CURRENT text is handed to the history, and that is
1935
+ what lets an edit survive: a `current` that is not what the
1936
+ history last served means the user has typed, so the move starts
1937
+ a fresh browse with the edit saved as the draft rather than
1938
+ walking past it. See `tui/history.py` for why that beats hooking
1939
+ the keystroke.
1940
+
1941
+ Assignment goes through `.value`, so batch 55's `_api_edit` path
1942
+ closes the suggestion panel on the way -- which is right:
1943
+ recalling `/research --attended` should not open a completion
1944
+ list over it. And `load_text` leaves the cursor at the START of
1945
+ the document, so the next keystroke would land in FRONT of the
1946
+ recalled text; `_complete()` fixes the same thing the same way.
1947
+
1948
+ No `_busy` gate. The box stays editable during a turn on
1949
+ purpose, and recall is part of that.
1950
+ """
1951
+ if self._history is None:
1952
+ return
1953
+ try:
1954
+ prompt = self.query_one("#prompt", PromptInput)
1955
+ except NoMatches: # a modal is on top (#104)
1956
+ return
1957
+ move = (self._history.previous if direction < 0
1958
+ else self._history.following)
1959
+ text = move(prompt.value)
1960
+ if text is None:
1961
+ # Nothing to go to: an empty history, or a browse already at
1962
+ # the oldest entry. The box is left exactly as it was.
1963
+ return
1964
+ prompt.value = text
1965
+ prompt.move_cursor(prompt.document.end)
1966
+
1967
+ def _copy_selection(self) -> bool:
1968
+ """Copy the focused widget's selection; True if there was one.
1969
+
1970
+ This is what `priority=True` takes away and has to hand back. Both
1971
+ `Input` and `TextArea` bind ctrl+c to `copy`, and a priority app
1972
+ binding pre-empts them completely -- measured, the clipboard
1973
+ stayed empty. So the app performs the copy itself, and the rule
1974
+ the whole gesture rests on is: **ctrl+c copies when there is
1975
+ something to copy, and starts a quit when there is not.** A press
1976
+ that copies never arms and never quits, armed or not -- so no
1977
+ sequence of copies can end the session.
1978
+ """
1979
+ selection = getattr(self.focused, "selected_text", "")
1980
+ if not selection:
1981
+ return False
1982
+ self.copy_to_clipboard(selection)
1983
+ return True
1984
+
1985
+ def action_arm_quit(self) -> None:
1986
+ """First ctrl+c: say what a second one does, and mean it for
1987
+ `QUIT_CONFIRM_S`."""
1988
+ if self._copy_selection():
1989
+ return
1990
+ self._quit_armed = True
1991
+ self._quit_timer = self.set_timer(QUIT_CONFIRM_S, self._disarm_quit)
1992
+ # Without this the state changes and the footer does not: the
1993
+ # Footer recomposes off the screen's bindings signal, which
1994
+ # nothing else here raises.
1995
+ self.refresh_bindings()
1996
+
1997
+ def action_confirm_quit(self) -> None:
1998
+ """Second ctrl+c, inside the window."""
1999
+ if self._copy_selection():
2000
+ return
2001
+ if self._quit_timer is not None:
2002
+ self._quit_timer.stop()
2003
+ self._quit_timer = None
2004
+ self.exit()
2005
+
2006
+ def _disarm_quit(self) -> None:
2007
+ """The window closed with one press in it. The label goes back."""
2008
+ # A quit that came from somewhere else (/quit, ctrl+q) can leave
2009
+ # this timer pending; refreshing bindings without a screen raises.
2010
+ if self._shutting_down:
2011
+ return
2012
+ self._quit_armed = False
2013
+ self._quit_timer = None
2014
+ self.refresh_bindings()
2015
+
1395
2016
  def _release_permission_channel(self) -> None:
1396
2017
  """Unblock a worker parked on permission_channel.get(), denying.
1397
2018
 
@@ -1424,10 +2045,12 @@ class VenastineApp(App):
1424
2045
  # next event (#105's fix), so this is a bounded goodbye, and
1425
2046
  # the line tells the user what became of the run.
1426
2047
  #
1427
- # Best-effort twice over (#104's rule): quitting from under a
1428
- # modal means query_one finds no #transcript at all -- it
1429
- # searches the ACTIVE screen (§27) -- and an unrenderable
1430
- # goodbye must not block the goodbye.
2048
+ # Best-effort (#104's rule), though the case it was written
2049
+ # for is gone: `_transcript` is held from on_mount, so
2050
+ # quitting from under a modal now WRITES this line rather
2051
+ # than skipping it. The guard stays for an app that never
2052
+ # mounted, and because an unrenderable goodbye must not block
2053
+ # the goodbye.
1431
2054
  try:
1432
2055
  self._transcript.write_system(
1433
2056
  "[quitting — the active work is abandoned at its next "
@@ -1572,15 +2195,49 @@ class VenastineApp(App):
1572
2195
  """
1573
2196
  channel: queue.Queue = queue.Queue()
1574
2197
  self._permission_channel = channel
2198
+ # Batch 61. The turn clock stops while a human is being waited
2199
+ # on -- this is their time, not the harness's, and counting it
2200
+ # would make a 30-second decision read as a slow model and
2201
+ # collapse the throughput figure to nothing. The tick reads the
2202
+ # screen stack for the general case; this call is what makes
2203
+ # the pause exact when `tui.animations: false` leaves no tick
2204
+ # to notice the transition. set_blocked is idempotent, so the
2205
+ # two routes are one piece of state.
2206
+ #
2207
+ # DIRECT, never call_from_thread: this runs on a worker, and
2208
+ # a quitting app has no message pump left to marshal into --
2209
+ # measured, that parks the worker forever and breaks the
2210
+ # shutdown release this method exists to keep working
2211
+ # (test_quitting_during_an_attended_research_prompt_releases_
2212
+ # the_worker). The meter touches no widget, so there is
2213
+ # nothing to marshal.
2214
+ self._meter.set_blocked(True, monotonic())
1575
2215
  self.call_from_thread(
1576
2216
  self.push_screen, screen, lambda answer: channel.put(answer))
1577
2217
  try:
1578
2218
  return channel.get(timeout=config.ATTENDED_APPROVAL_TIMEOUT_S)
1579
2219
  except queue.Empty:
1580
- self.call_from_thread(on_timeout, screen)
2220
+ # NARRATION IS BEST-EFFORT; THE ANSWER IS NOT. This method's
2221
+ # contract is to return the dismissal value raw, and None here
2222
+ # is what interaction.decode turns into the kind's declining
2223
+ # default. A failure while merely SAYING so must not replace
2224
+ # that with an exception, which would travel out through
2225
+ # `_ask_blocking` and be logged by interaction.ask as
2226
+ # "response channel raised" -- naming this call as the cause
2227
+ # of a refusal it did not cause, and masking whatever actually
2228
+ # broke. Observed: a crash inside on_log_record_message killed
2229
+ # the app, the next call_from_thread failed because of it, and
2230
+ # the interaction.py line was the one that surfaced.
2231
+ try:
2232
+ self.call_from_thread(on_timeout, screen)
2233
+ except Exception: # noqa: BLE001 -- the answer stands regardless
2234
+ logger.exception(
2235
+ "Could not narrate the timeout for this request; it is "
2236
+ "still declined.")
1581
2237
  return None
1582
2238
  finally:
1583
2239
  self._permission_channel = None
2240
+ self._meter.set_blocked(False, monotonic())
1584
2241
 
1585
2242
  def ask_choice_blocking(self, payload: dict):
1586
2243
  """Pick one of a set of offered options. Blocks; returns whatever
@@ -1761,6 +2418,9 @@ class VenastineApp(App):
1761
2418
  # record now (Transcript.last_answer), so there is no second buffer
1762
2419
  # to keep in step and no flush site that has to remember to.
1763
2420
  self._transcript.flush_stream()
2421
+ # Batch 61. AFTER the flush, so the line lands under the
2422
+ # answer rather than inside it.
2423
+ self._write_turn_time()
1764
2424
  self._raven.resume_animation()
1765
2425
  self._raven.state = ravens.IDLE
1766
2426
  if message.error is not None:
@@ -1800,8 +2460,14 @@ class VenastineApp(App):
1800
2460
  elif event.kind == "tool_call":
1801
2461
  # §26, the thing §22 P2 made invisible. Indented under its
1802
2462
  # pass, so a run reads as a tree rather than a flat log.
2463
+ # pipeline_tool, not tool: it renders identically (the widget
2464
+ # aliases the style) and copies identically (still
2465
+ # CONVERSATION), but must not open the turn's label the way a
2466
+ # chat tool call now can -- the run's label belongs to the
2467
+ # report (§43 RM1).
1803
2468
  detail = f" {event.text}" if event.text else ""
1804
- self._transcript.write_role("tool", f" ▸ {event.tool}{detail}")
2469
+ self._transcript.write_role(
2470
+ "pipeline_tool", f" ▸ {event.tool}{detail}")
1805
2471
  panel.tool_called(event.pass_id)
1806
2472
  elif event.kind == "tool_result":
1807
2473
  # Only failures. A line per successful call doubles the volume
@@ -1836,6 +2502,7 @@ class VenastineApp(App):
1836
2502
 
1837
2503
  def on_research_finished(self, message: ResearchFinished) -> None:
1838
2504
  self._busy = False
2505
+ self._write_turn_time()
1839
2506
  self._raven.state = ravens.IDLE
1840
2507
  if getattr(message, "abandoned", False):
1841
2508
  # #105. A deliberate quit is not a pipeline failure: say what
@@ -2000,7 +2667,7 @@ class VenastineApp(App):
2000
2667
  f"open and usable — only its history could not be "
2001
2668
  f"drawn.")
2002
2669
  return
2003
- for role, text in entries:
2670
+ for role, text, links in entries:
2004
2671
  if role == "user":
2005
2672
  self._transcript.write_user(text)
2006
2673
  elif role == "assistant":
@@ -2020,7 +2687,7 @@ class VenastineApp(App):
2020
2687
  if self._show_thinking:
2021
2688
  self._transcript.write_role(role, text)
2022
2689
  else:
2023
- self._transcript.write_role(role, text)
2690
+ self._transcript.write_role(role, text, links)
2024
2691
  if entries:
2025
2692
  noun = "entry" if len(entries) == 1 else "entries"
2026
2693
  self._transcript.write_system(
@@ -2093,7 +2760,12 @@ def _cmd_help(app: VenastineApp, args: str) -> None:
2093
2760
  app._transcript.write_system("Commands:")
2094
2761
  for command in commands.all():
2095
2762
  usage = f" {command.usage}" if command.usage else ""
2096
- app._transcript.write_system(f" /{command.name}{usage} — {command.summary}")
2763
+ # `all()` is canonical, so an alias has exactly one place to be
2764
+ # named: on the row of the command it belongs to (batch 57).
2765
+ also = (f" (also {', '.join('/' + a for a in command.aliases)})"
2766
+ if command.aliases else "")
2767
+ app._transcript.write_system(
2768
+ f" /{command.name}{usage} — {command.summary}{also}")
2097
2769
  # §26. Worth saying plainly: the pinned textual has no text selection,
2098
2770
  # so someone trying to select with the mouse gets nothing and has no
2099
2771
  # way to know why. Most terminals let shift+drag bypass the app's
@@ -2961,7 +3633,11 @@ def _cmd_compact(app: VenastineApp, args: str) -> None:
2961
3633
  from core import compaction
2962
3634
  try:
2963
3635
  outcome = compaction.compact(
2964
- memory, app.model, app.provider_name, overrides=overrides)
3636
+ memory, app.model, app.provider_name, overrides=overrides,
3637
+ # Batch 59. A manual /compact runs the compactor agent in
3638
+ # its own worker with nothing above it, so its span is the
3639
+ # root of the stack rather than one level down.
3640
+ activity=getattr(app, "_activity", None), depth=0)
2965
3641
  except Exception as e: # noqa: BLE001 — same containment as the loop's
2966
3642
  app.call_from_thread(
2967
3643
  app._transcript.write_error, f"Compaction failed: {e}")
@@ -3397,7 +4073,8 @@ def register_builtin_commands() -> None:
3397
4073
  SlashCommand("resume", "resume a thread by id, even an old one",
3398
4074
  _cmd_resume, "<thread-id>"),
3399
4075
  SlashCommand("new", "start a new thread", _cmd_new),
3400
- SlashCommand("quit", "exit", _cmd_quit),
4076
+ SlashCommand("quit", "exit the harness", _cmd_quit,
4077
+ aliases=("exit", "bye")),
3401
4078
  ):
3402
4079
  commands.register(command)
3403
4080