@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.tcss CHANGED
@@ -5,10 +5,32 @@
5
5
  width: 1fr;
6
6
  }
7
7
 
8
+ /* IT SCROLLS, because a Vertical does not (batch 59). Textual's Vertical
9
+ is `overflow: hidden hidden`, so the sidebar silently dropped whatever
10
+ did not fit. Measured at the 24-row floor with a todo list and a
11
+ research run both live: `max_scroll_y` was 11 -- eleven rows the
12
+ container had already computed and clipped anyway -- #todo-panel lost
13
+ three rows and #research-progress was ENTIRELY off screen, its header
14
+ drawn on the last visible row with its whole body gone.
15
+
16
+ `overflow-y` on the CONTAINER, not a swap to VerticalScroll. That class
17
+ is `can_focus=True` and binds up/down/home/end/pageup/pagedown, which
18
+ would add a tab stop and take the arrows batch 55 gave the suggestion
19
+ panel. The trade, named rather than discovered later: this scrolls by
20
+ wheel and not by keyboard. EP3's sibling rule (a consent surface must
21
+ not be mouse-only) does not reach here -- no decision is made in the
22
+ sidebar, and every figure in it is also said in the transcript.
23
+
24
+ `scrollbar-size-vertical: 1` because the budget is tiny. Measured: 19
25
+ usable columns when everything fits, 18 while the bar is up, against 17
26
+ at textual's default 2. The width is CONDITIONAL either way -- widgets
27
+ reflow by a column when the bar appears. */
8
28
  #sidebar {
9
29
  width: 22;
10
30
  border-left: solid $panel;
11
31
  padding: 1;
32
+ overflow-y: auto;
33
+ scrollbar-size-vertical: 1;
12
34
  }
13
35
 
14
36
  #transcript {
@@ -17,9 +39,60 @@
17
39
  padding: 0 1;
18
40
  }
19
41
 
42
+ /* Batch 55, the slash-command suggestions. Directly above the prompt
43
+ because it is the last child in #main's flow and #prompt is docked out
44
+ of that flow -- so it opens UPWARDS with no layer and no offset.
45
+
46
+ `height: auto` with a `max-height` again, and the cap is arithmetic:
47
+ SUGGEST_MAX_ROWS is 8, plus two border rows is 10, which at the 24-row
48
+ floor leaves the transcript nine rows while the panel is up. The widget
49
+ budgets itself to those 8 rows, so the cap is a backstop rather than a
50
+ clip -- if it ever clips, the budget is wrong.
51
+
52
+ No `overflow-y`. A panel that scrolled would be a second thing to
53
+ navigate inside a thing being navigated. */
54
+ #slash-suggest {
55
+ height: auto;
56
+ max-height: 10;
57
+ border: solid $primary;
58
+ padding: 0 1;
59
+ /* The count, `4 of 26 - /help for all`. Muted for #prompt's reason:
60
+ it is a hint about the list, not a heading over it. */
61
+ border-title-color: $text-muted;
62
+ /* Batch 62's key hints, on the bottom border. STATED, and measured
63
+ rather than assumed: an unstyled subtitle renders in $primary --
64
+ the border's own green -- so without this the hint would be
65
+ brighter than the count above it on the same box, and the less
66
+ important of the two labels would be the louder one. No
67
+ `border-subtitle-align`: textual already defaults a subtitle to
68
+ the right, which is the corner #prompt's meter uses one box
69
+ down, so titles sit left and status sits right throughout. */
70
+ border-subtitle-color: $text-muted;
71
+ }
72
+
73
+ /* Batch 54. `height: auto` with a `max-height` -- batch 49's shape, for
74
+ batch 49's reason. A definite height would reserve four rows whether or
75
+ not anything is typed, and this box's whole point is that it is one row
76
+ until it isn't; auto also means the transcript gets those rows back the
77
+ moment a turn is submitted. The cap is what stops a pasted essay from
78
+ eating the transcript: 6 is the border plus four text rows, so a fully
79
+ extended prompt still leaves 18 of the 24-row floor above it, and past
80
+ four rows the box scrolls instead of growing.
81
+
82
+ `padding: 0 1` is stated rather than inherited. TextArea's own default
83
+ is `0 1` and the Input this replaced was `0 2`; naming it is what keeps
84
+ the typed text's left edge where a reader already has it. */
20
85
  #prompt {
21
86
  dock: bottom;
22
87
  border: solid $primary;
88
+ height: auto;
89
+ max-height: 6;
90
+ padding: 0 1;
91
+ /* The placeholder, which a TextArea has no other way to carry. Muted
92
+ is already this sheet's vocabulary for a hint (#usage-line,
93
+ #todo-panel, #research-progress), so it reads as one rather than
94
+ as a heading. */
95
+ border-title-color: $text-muted;
23
96
  }
24
97
 
25
98
  #raven {
@@ -38,6 +111,16 @@
38
111
  padding: 1 0 0 0;
39
112
  }
40
113
 
114
+ /* Batch 59's agent stack. Auto height and hidden until there is an active
115
+ agent or a running spawn, so it costs no rows in the ordinary case --
116
+ the same shape #posture-badge and #usage-line already use. No colours
117
+ here: the panel renders through Rich styles resolved per draw
118
+ (role_styles), which is what makes /theme reach it. */
119
+ #agent-panel {
120
+ height: auto;
121
+ padding-top: 1;
122
+ }
123
+
41
124
  #effort-raven {
42
125
  height: 2;
43
126
  color: $secondary;
@@ -52,13 +135,24 @@
52
135
  color: $text-muted;
53
136
  }
54
137
 
55
- /* §22 live research view. Auto height so it takes no sidebar space
56
- until a run starts, and scrolls rather than pushing the ravens off
57
- screen on a long retry loop. */
138
+ /* §22 live research view. Auto height so it takes no sidebar space until
139
+ a run starts.
140
+
141
+ THE CAP AND THE OVERFLOW ARE GONE (batch 59), and they were EP3's trap
142
+ a second time. `Static` + `max-height` + `overflow-y: auto` reads as
143
+ "clip it and let them scroll" and does neither: a Static's
144
+ `virtual_size` follows its clamped box rather than its text, so
145
+ `max_scroll_y` was 0 and the rows past the bound were not below the
146
+ fold, they were gone. Measured here at one lost row with twenty passes
147
+ and twelve claims; measured in tui/screens.py at nine lines in a
148
+ seven-row block, which is the ScrollBox that fixed it there.
149
+
150
+ The fix is the same shape: the bound belongs on a real scroll
151
+ container, and #sidebar is now one. What still bounds this panel is
152
+ ResearchProgress.ROWS -- a window over the passes, which is the half of
153
+ that comment that was always true. */
58
154
  #research-progress {
59
155
  height: auto;
60
- max-height: 20;
61
- overflow-y: auto;
62
156
  padding-top: 1;
63
157
  color: $text-muted;
64
158
  }
@@ -448,11 +542,15 @@ QuestionScreen {
448
542
 
449
543
  /* §23 slice 2's checklist. `height: auto` so an empty list costs no rows in
450
544
  whichever slot tui.todo_position put it in -- the widget hides itself, and
451
- this is what makes the unused slots free. */
545
+ this is what makes the unused slots free.
546
+
547
+ No `max-height`, no `overflow-y`: see #research-progress for why that
548
+ pairing on a Static clips rather than scrolls (batch 59, EP3's trap).
549
+ TodoPanel.ROWS is the bound. This panel also sits in the `top` and
550
+ `bottom` slots inside #main, where nothing scrolls at all -- one more
551
+ reason its own height must be honest rather than clamped. */
452
552
  #todo-panel {
453
553
  height: auto;
454
- max-height: 14;
455
- overflow-y: auto;
456
554
  padding: 0 1;
457
555
  color: $text-muted;
458
556
  }
package/tui/commands.py CHANGED
@@ -1,61 +1,170 @@
1
- """
2
- tui/commands.py
3
-
4
- ROADMAP_v2 §16 slash-command registry.
5
-
6
- The registry is §16's; the commands registered into it are not all §16's.
7
- D7 assigns `/skill <name>` to §19, and §18/§21 add their own -- each
8
- registers here rather than editing a match statement in the app, which is
9
- the same mechanism-vs-policy split tools/registry.py already uses for
10
- tools.
11
-
12
- A handler takes (app, argument_string) and returns None. It runs on the UI
13
- thread, so anything slow belongs in a worker.
14
- """
15
-
16
- from dataclasses import dataclass
17
- from typing import Callable, Optional
18
-
19
-
20
- @dataclass
21
- class SlashCommand:
22
- name: str # without the leading slash
23
- summary: str # one line, shown by /help
24
- handler: Callable # (app, args: str) -> None
25
- usage: Optional[str] = None # shown by /help when the shape is not obvious
26
-
27
-
28
- class CommandRegistry:
29
- def __init__(self) -> None:
30
- self._commands: dict[str, SlashCommand] = {}
31
-
32
- def register(self, command: SlashCommand) -> None:
33
- self._commands[command.name] = command
34
-
35
- def get(self, name: str) -> Optional[SlashCommand]:
36
- return self._commands.get(name)
37
-
38
- def names(self) -> list[str]:
39
- return sorted(self._commands)
40
-
41
- def all(self) -> list[SlashCommand]:
42
- return [self._commands[n] for n in self.names()]
43
-
44
- def dispatch(self, app, raw: str) -> bool:
45
- """Run the command in `raw` (a line starting with '/').
46
-
47
- Returns True if a command handled the line, False if the name is
48
- unknown -- the caller decides what to do about it. Unknown names are
49
- NOT sent to the model: a mistyped slash command should say so, not
50
- silently become a chat turn that burns a request.
51
- """
52
- stripped = raw[1:].strip()
53
- name, _, args = stripped.partition(" ")
54
- command = self.get(name.lower())
55
- if command is None:
56
- return False
57
- command.handler(app, args.strip())
58
- return True
59
-
60
-
61
- registry = CommandRegistry()
1
+ """
2
+ tui/commands.py
3
+
4
+ ROADMAP_v2 §16 slash-command registry.
5
+
6
+ The registry is §16's; the commands registered into it are not all §16's.
7
+ D7 assigns `/skill <name>` to §19, and §18/§21 add their own -- each
8
+ registers here rather than editing a match statement in the app, which is
9
+ the same mechanism-vs-policy split tools/registry.py already uses for
10
+ tools.
11
+
12
+ A handler takes (app, argument_string) and returns None. It runs on the UI
13
+ thread, so anything slow belongs in a worker.
14
+ """
15
+
16
+ from dataclasses import dataclass
17
+ from typing import Callable, Optional
18
+
19
+
20
+ @dataclass
21
+ class SlashCommand:
22
+ name: str # without the leading slash
23
+ summary: str # one line, shown by /help
24
+ handler: Callable # (app, args: str) -> None
25
+ usage: Optional[str] = None # shown by /help when the shape is not obvious
26
+ # Other names the same command answers to (batch 57). A FIELD rather
27
+ # than two more registrations, and the difference is what the LISTS
28
+ # say: `all()` and `names()` stay canonical, so `/help` prints one row
29
+ # per command and a bare slash still offers the menu it always did.
30
+ # Registering `/exit` and `/bye` outright would have sorted `bye`
31
+ # second in that menu, ahead of `/claims`, for a name nobody browses
32
+ # for -- and moved every window position batch 56 measured.
33
+ aliases: tuple[str, ...] = ()
34
+
35
+
36
+ class CommandRegistry:
37
+ def __init__(self) -> None:
38
+ self._commands: dict[str, SlashCommand] = {}
39
+ # alias -> canonical name. A second index rather than a scan, and
40
+ # it is what makes an alias collision detectable at REGISTRATION
41
+ # instead of at the keystroke that silently reached the wrong
42
+ # handler.
43
+ self._aliases: dict[str, str] = {}
44
+
45
+ def register(self, command: SlashCommand) -> None:
46
+ """Register by name; re-registering the same name overwrites.
47
+
48
+ Idempotent on purpose -- `register_builtin_commands()` runs on
49
+ import AND is called again by tests, so a second pass must not
50
+ duplicate or raise.
51
+
52
+ An alias that would shadow something REFUSES, both ways round: a
53
+ name already taken by a command, and a command name already taken
54
+ by somebody's alias. Both resolve silently otherwise -- `get()`
55
+ prefers real names, so the alias would simply stop working and
56
+ nothing would say why.
57
+ """
58
+ for alias in command.aliases:
59
+ if alias in self._commands:
60
+ raise ValueError(
61
+ f"/{alias} is already a command; it cannot also be an "
62
+ f"alias of /{command.name}")
63
+ owner = self._aliases.get(alias)
64
+ if owner is not None and owner != command.name:
65
+ raise ValueError(
66
+ f"/{alias} is already an alias of /{owner}; it cannot "
67
+ f"also be an alias of /{command.name}")
68
+ owner = self._aliases.get(command.name)
69
+ if owner is not None and owner != command.name:
70
+ raise ValueError(
71
+ f"/{command.name} is already an alias of /{owner}")
72
+ old = self._commands.get(command.name)
73
+ if old is not None:
74
+ for alias in old.aliases:
75
+ if alias not in command.aliases \
76
+ and self._aliases.get(alias) == command.name:
77
+ del self._aliases[alias]
78
+ self._commands[command.name] = command
79
+ for alias in command.aliases:
80
+ self._aliases[alias] = command.name
81
+
82
+ def get(self, name: str) -> Optional[SlashCommand]:
83
+ """The command called `name`, by its own name or by an alias.
84
+
85
+ Names win over aliases, which is also the collision `register`
86
+ refuses -- so the precedence can never actually be exercised.
87
+ """
88
+ command = self._commands.get(name)
89
+ if command is not None:
90
+ return command
91
+ canonical = self._aliases.get(name)
92
+ return self._commands.get(canonical) if canonical else None
93
+
94
+ def names(self) -> list[str]:
95
+ return sorted(self._commands)
96
+
97
+ def all(self) -> list[SlashCommand]:
98
+ return [self._commands[n] for n in self.names()]
99
+
100
+ def matching(self, text: str) -> list[SlashCommand]:
101
+ """Commands whose name starts with the token in `text`.
102
+
103
+ The suggestion panel's source, and it reads `all()` so the panel and
104
+ `/help` cannot disagree about what exists -- register a command
105
+ anywhere and both change, which is the whole reason the matching
106
+ lives here rather than in the widget.
107
+
108
+ Empty unless `text` is a BARE slash token: leading whitespace
109
+ allowed (`dispatch` tolerates it, so `" /help"` runs and had
110
+ better offer), a leading `/`, and NO whitespace after that.
111
+
112
+ `lstrip`, not `strip`, and the difference is a bug this had: a
113
+ TRAILING space survives `strip()`, so `"/copy "` read as `"/copy"`
114
+ and the panel stayed open over a line that had already moved on to
115
+ its arguments. Once a space is typed there is nothing left to
116
+ complete, whichever end of the token it is on.
117
+
118
+ Lowercased for the same reason `dispatch` lowercases: `/HELP` runs,
119
+ so `/HEL` had better offer it.
120
+
121
+ ALIASES join the list once a prefix is typed, and never on a bare
122
+ slash (batch 57). The bare slash is the MENU -- it is what someone
123
+ who does not know the commands presses, and a menu lists each
124
+ thing once, under its own name. `/ex` is not browsing: it is a
125
+ guess, and the answer to a guess is whether it works. So
126
+ `matching("/") == all()` still holds exactly, and typing toward an
127
+ alias surfaces it.
128
+ """
129
+ token = text.lstrip()
130
+ if not token.startswith("/") or any(c.isspace() for c in token):
131
+ return []
132
+ prefix = token[1:].lower()
133
+ matches = [c for c in self.all() if c.name.startswith(prefix)]
134
+ if not prefix:
135
+ return matches
136
+ matches.extend(self._alias_row(a) for a in self._aliases
137
+ if a.startswith(prefix))
138
+ return sorted(matches, key=lambda command: command.name)
139
+
140
+ def _alias_row(self, alias: str) -> SlashCommand:
141
+ """One offer for `alias`, carrying the canonical command's handler.
142
+
143
+ A real `SlashCommand` rather than a flag on the canonical one, so
144
+ the panel needs to know nothing about aliases: it draws the name
145
+ it is given and completes the name it drew, which has to be the
146
+ alias the user was typing rather than the name they were not.
147
+ """
148
+ command = self._commands[self._aliases[alias]]
149
+ return SlashCommand(
150
+ alias, f"{command.summary} (alias of /{command.name})",
151
+ command.handler, command.usage)
152
+
153
+ def dispatch(self, app, raw: str) -> bool:
154
+ """Run the command in `raw` (a line starting with '/').
155
+
156
+ Returns True if a command handled the line, False if the name is
157
+ unknown -- the caller decides what to do about it. Unknown names are
158
+ NOT sent to the model: a mistyped slash command should say so, not
159
+ silently become a chat turn that burns a request.
160
+ """
161
+ stripped = raw[1:].strip()
162
+ name, _, args = stripped.partition(" ")
163
+ command = self.get(name.lower())
164
+ if command is None:
165
+ return False
166
+ command.handler(app, args.strip())
167
+ return True
168
+
169
+
170
+ registry = CommandRegistry()
package/tui/history.py ADDED
@@ -0,0 +1,128 @@
1
+ """
2
+ tui/history.py
3
+
4
+ Batch 63. What you already sent, so a misfire does not cost the typing.
5
+
6
+ PURE, like `tui/markdown.py`, `tui/diffs.py` and `tui/meters.py` beside it:
7
+ no I/O, no `core/` import, no widget, no clock. `tui/app.py` owns the keys
8
+ and the box; this owns the arithmetic, so every test here is a function
9
+ call rather than a pilot pressing keys at a live TextArea.
10
+ """
11
+
12
+ # A hundred prompts is more than a sitting produces and costs nothing to
13
+ # hold; the cap exists so a very long session cannot grow this without
14
+ # bound, not because anyone will reach it.
15
+ HISTORY_LIMIT = 100
16
+
17
+
18
+ class PromptHistory:
19
+ """The prompts submitted this session, and where a browse has got to.
20
+
21
+ Session-scoped and in memory: it survives `/new` and `/resume` because
22
+ it records what the PERSON typed, not what a thread holds, and a
23
+ misfire bad enough to start a new thread is exactly when the text is
24
+ wanted back. Nothing here is persisted.
25
+
26
+ **Both movers take the box's current text, and that one parameter is
27
+ the whole design.** The history remembers what it last handed out, so
28
+ a `current` that differs from it means the user has typed since --
29
+ which ends the browse and starts a new one with `current` saved as the
30
+ draft. Recall a prompt, edit it, press previous again: the edit is not
31
+ discarded, it becomes the thing `following()` hands back.
32
+
33
+ The alternative was to hook `PromptInput.on_text_area_changed`, where
34
+ batch 55's `_api_edit` flag already separates assignment from typing.
35
+ It is the wrong seam: that message is POSTED, so the app would be
36
+ holding a flag across an async hop, and the panel's own
37
+ `SuggestionsChanged` fires on both halves of the split anyway. Asking
38
+ the box what it holds, at the only two moments it matters, needs
39
+ neither.
40
+
41
+ `previous()` STOPS at the oldest entry rather than wrapping. A
42
+ suggestion panel wraps because its list is a menu; this is a walk
43
+ backwards through time, and arriving at the start of it by pressing a
44
+ key twelve times should not deposit you at the end.
45
+ """
46
+
47
+ def __init__(self) -> None:
48
+ self._entries: list[str] = [] # oldest first
49
+ # The index being shown, or None when the box holds a live draft.
50
+ self._cursor = None
51
+ self._draft = ""
52
+ # The exact string last handed out. `None` while not browsing.
53
+ self._served = None
54
+
55
+ def __len__(self) -> int:
56
+ """How many prompts are recallable. `check_action` reads this."""
57
+ return len(self._entries)
58
+
59
+ @property
60
+ def browsing(self) -> bool:
61
+ """True while a recalled entry is being shown. For tests."""
62
+ return self._cursor is not None
63
+
64
+ def remember(self, text: str) -> None:
65
+ """Record a submitted prompt and end any browse in progress.
66
+
67
+ Slash commands included: a mistyped `/research --attended --grant`
68
+ is the worst retyping in the shell, and `on_prompt_input_submitted`
69
+ is one funnel for both kinds.
70
+
71
+ A CONSECUTIVE repeat is not appended twice -- sending the same
72
+ thing twice is one thing to walk back past, not two. A repeat with
73
+ something else between them is kept, because the order is the
74
+ record of what happened.
75
+ """
76
+ if not text:
77
+ return
78
+ if not self._entries or self._entries[-1] != text:
79
+ self._entries.append(text)
80
+ del self._entries[:-HISTORY_LIMIT]
81
+ self._forget_browse()
82
+
83
+ def previous(self, current: str):
84
+ """The next older prompt, or None when there is nowhere to go.
85
+
86
+ None means the caller writes nothing -- an empty history, or a
87
+ browse already at the oldest entry. The browse state is left
88
+ alone in both cases, so a press at the oldest is inert rather
89
+ than a reset.
90
+ """
91
+ if not self._entries:
92
+ return None
93
+ if not self._is_browsing(current):
94
+ self._draft = current
95
+ self._cursor = len(self._entries)
96
+ if self._cursor == 0:
97
+ return None
98
+ self._cursor -= 1
99
+ self._served = self._entries[self._cursor]
100
+ return self._served
101
+
102
+ def following(self, current: str):
103
+ """The next newer prompt, or the draft once past the newest.
104
+
105
+ None when no browse is in progress, which is what makes the key
106
+ inert on a box the user is typing into fresh: there is nothing
107
+ newer than what they are already looking at.
108
+ """
109
+ if not self._is_browsing(current):
110
+ return None
111
+ self._cursor += 1
112
+ if self._cursor < len(self._entries):
113
+ self._served = self._entries[self._cursor]
114
+ return self._served
115
+ draft = self._draft
116
+ self._forget_browse()
117
+ return draft
118
+
119
+ # -- internals ----------------------------------------------------------
120
+
121
+ def _is_browsing(self, current: str) -> bool:
122
+ """Whether `current` is still the string this last handed out."""
123
+ return self._cursor is not None and current == self._served
124
+
125
+ def _forget_browse(self) -> None:
126
+ self._cursor = None
127
+ self._draft = ""
128
+ self._served = None