@yahyahammad/venastine 0.2.0 → 0.3.8
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/.env.example +19 -14
- package/CONFIG_ARCHITECTURE.md +2002 -0
- package/NOTICE +1 -1
- package/README.md +233 -94
- package/agents/builtin/build.md +73 -0
- package/agents/builtin/general.md +80 -0
- package/agents/builtin/plan.md +23 -5
- package/agents/builtin/test.md +65 -0
- package/agents/builtin/writer.md +67 -0
- package/agents/manager.py +261 -195
- package/agents/subagent_tool.py +277 -43
- package/agents/tui_commands.py +7 -12
- package/bin/venastine.mjs +528 -382
- package/bin/venastine.py +71 -0
- package/cli_commands.py +835 -0
- package/config.py +95 -1198
- package/config.yaml +1090 -0
- package/config_edit.py +1301 -0
- package/config_schema.py +966 -0
- package/config_update.py +749 -0
- package/core/agent_activity.py +158 -20
- package/core/ansi.py +452 -0
- package/core/approval.py +27 -5
- package/core/call_view.py +364 -0
- package/core/cancel.py +121 -0
- package/core/chatgpt_auth.py +747 -0
- package/core/claims_view.py +107 -0
- package/core/client.py +1238 -82
- package/core/commands.py +454 -0
- package/core/compaction.py +830 -66
- package/core/config_loader.py +516 -97
- package/core/connect.py +686 -0
- package/core/events.py +68 -6
- package/core/file_mentions.py +280 -0
- package/core/interaction.py +87 -4
- package/core/line_pattern.py +128 -0
- package/core/loop.py +1516 -440
- package/core/memory.py +120 -8
- package/core/pipeline_models.py +23 -9
- package/core/provider_errors.py +234 -0
- package/core/reasoning/confidence_scoring.py +70 -54
- package/core/reasoning/json_retry.py +19 -1
- package/core/reasoning/orchestrator.py +232 -53
- package/core/reasoning/output_writer.py +90 -31
- package/core/reasoning/payload_validation.py +133 -7
- package/core/reasoning/pipeline_storage.py +427 -361
- package/core/reasoning/review.py +659 -615
- package/core/reasoning/scholar.py +38 -14
- package/core/reasoning/source_corpus.py +110 -4
- package/core/replay.py +158 -26
- package/core/session.py +36 -12
- package/core/session_view.py +259 -0
- package/core/session_wake.py +259 -0
- package/core/shell_sessions.py +1553 -0
- package/core/workspace_trust.py +1 -1
- package/credentials.py +308 -180
- package/database.py +82 -1
- package/{PRIVACY.md → docs/PRIVACY.md} +19 -7
- package/docs/SECURITY.md +108 -0
- package/docs/THIRD_PARTY_NOTICES.md +148 -0
- package/env_secrets.py +118 -77
- package/json_store.py +236 -16
- package/logging_setup.py +121 -11
- package/main.py +1671 -199
- package/mcp_client/client.py +257 -23
- package/mcp_client/config.py +484 -379
- package/mcp_client/registration.py +163 -2
- package/memories/manager.py +15 -0
- package/memories/tui_commands.py +7 -12
- package/package.json +234 -4
- package/project_init/config_files.py +4 -0
- package/project_init/generator.py +201 -37
- package/project_init/manifest.py +418 -406
- package/project_init/tui_commands.py +7 -4
- package/prompts/revalidate.md +1 -1
- package/prompts/revise.md +17 -15
- package/prompts/system_prompts.py +64 -10
- package/providers.json.example +94 -92
- package/pyproject.toml +51 -2
- package/requirements.txt +252 -29
- package/safety/policy_enforcement.py +353 -17
- package/security/askpass.py +419 -0
- package/security/capability.py +37 -7
- package/security/confine.py +484 -0
- package/security/hosted.py +182 -0
- package/security/permissions.py +54 -7
- package/security/posture.py +124 -12
- package/security/protected_paths.py +198 -6
- package/security/sandbox.py +3262 -139
- package/security/secrets.py +855 -0
- package/skills/tui_commands.py +3 -4
- package/storage.py +368 -35
- package/tools/base.py +465 -305
- package/tools/builtin/_math_common.py +306 -16
- package/tools/builtin/_net_common.py +267 -61
- package/tools/builtin/arxiv.py +681 -223
- package/tools/builtin/ask_user.py +231 -213
- package/tools/builtin/discrete_math.py +35 -4
- package/tools/builtin/fetch_url.py +239 -21
- package/tools/builtin/file_ops.py +341 -33
- package/tools/builtin/geometry.py +184 -148
- package/tools/builtin/get_time.py +2 -2
- package/tools/builtin/linear_algebra.py +66 -23
- package/tools/builtin/load_skill.py +10 -0
- package/tools/builtin/logic.py +171 -12
- package/tools/builtin/pin.py +46 -12
- package/tools/builtin/probability_stats.py +224 -228
- package/tools/builtin/project_docs.py +80 -21
- package/tools/builtin/remember.py +21 -4
- package/tools/builtin/shell.py +586 -67
- package/tools/builtin/shell_sessions.py +613 -0
- package/tools/builtin/symbolic_math.py +80 -10
- package/tools/builtin/todo.py +5 -3
- package/tools/builtin/web_search.py +329 -151
- package/tools/context.py +23 -0
- package/tools/isolation.py +387 -314
- package/tools/registry.py +347 -30
- package/tui/app.py +4645 -438
- package/tui/app.tcss +185 -2
- package/tui/commands.py +10 -154
- package/tui/diffs.py +286 -265
- package/tui/hosted_driver.py +102 -0
- package/tui/markdown.py +60 -10
- package/tui/meters.py +103 -7
- package/tui/screens.py +346 -92
- package/tui/themes.py +59 -19
- package/tui/widgets.py +1575 -111
- package/SECURITY.md +0 -88
- package/THIRD_PARTY_NOTICES.md +0 -100
package/tui/app.tcss
CHANGED
|
@@ -33,12 +33,69 @@
|
|
|
33
33
|
scrollbar-size-vertical: 1;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/* Section 47. The switcher holding the live transcript and the read-only
|
|
37
|
+
view. Both children stay mounted; only `current` changes -- which is what
|
|
38
|
+
lets a running turn keep writing to the live pane while a stored thread is
|
|
39
|
+
on screen, with nothing to buffer and nothing to flush on the way back. */
|
|
40
|
+
#pane {
|
|
41
|
+
height: 1fr;
|
|
42
|
+
}
|
|
43
|
+
|
|
36
44
|
#transcript {
|
|
37
45
|
height: 1fr;
|
|
38
46
|
border: solid $panel;
|
|
39
47
|
padding: 0 1;
|
|
40
48
|
}
|
|
41
49
|
|
|
50
|
+
/* The accent border is the whole affordance: at a glance this is not the
|
|
51
|
+
conversation you are having. The prompt is disabled underneath it, so the
|
|
52
|
+
read-only rule is visible rather than merely true. */
|
|
53
|
+
#thread-view {
|
|
54
|
+
height: 1fr;
|
|
55
|
+
border: solid $accent;
|
|
56
|
+
padding: 0 1;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/* The lineage trail. `height: auto` and hidden until the viewer opens, so
|
|
60
|
+
the live conversation costs no row for a trail it does not need -- the
|
|
61
|
+
GoalBanner rule, which every conditional row in #main follows. */
|
|
62
|
+
/* ROADMAP_v3 §49 (SS14). THE SAME BOX as #transcript and #thread-view --
|
|
63
|
+
`border: solid` and `padding: 0 1` -- and that is load-bearing rather
|
|
64
|
+
than tidy: a hidden pane measures 0 and borrows the on-screen pane's
|
|
65
|
+
width (Transcript._region_width), so four panes that are not the same
|
|
66
|
+
box would each write at another one's width. The accent border is
|
|
67
|
+
#thread-view's affordance, for #thread-view's reason: at a glance this
|
|
68
|
+
is not the conversation you are having. */
|
|
69
|
+
#session-view {
|
|
70
|
+
height: 1fr;
|
|
71
|
+
border: solid $accent;
|
|
72
|
+
padding: 0 1;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/* ROADMAP_v3 §55 (TR10). One tool call: the whole command and what it
|
|
76
|
+
printed. The FOURTH pane, and the same box for the paragraph above --
|
|
77
|
+
`test_the_panes_measure_the_same_width_when_shown` holds that, and a
|
|
78
|
+
different gutter here would silently rewrap every row the live
|
|
79
|
+
transcript wrote while this one was up. Accent border, same reason:
|
|
80
|
+
this is not the conversation you are having. */
|
|
81
|
+
#call-view {
|
|
82
|
+
height: 1fr;
|
|
83
|
+
border: solid $accent;
|
|
84
|
+
padding: 0 1;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
#thread-crumb {
|
|
88
|
+
height: auto;
|
|
89
|
+
padding: 0 1;
|
|
90
|
+
/* One line, elided rather than wrapped: a trail that reflowed
|
|
91
|
+
would take a second row from the transcript below it. The
|
|
92
|
+
ellipsis is the point -- the segment you are standing on is
|
|
93
|
+
the last one, so the cut belongs at the far end. Moved off
|
|
94
|
+
the Rich Text for `#agent-panel`'s reason. */
|
|
95
|
+
text-wrap: nowrap;
|
|
96
|
+
text-overflow: ellipsis;
|
|
97
|
+
}
|
|
98
|
+
|
|
42
99
|
/* Batch 55, the slash-command suggestions. Directly above the prompt
|
|
43
100
|
because it is the last child in #main's flow and #prompt is docked out
|
|
44
101
|
of that flow -- so it opens UPWARDS with no layer and no offset.
|
|
@@ -68,6 +125,14 @@
|
|
|
68
125
|
the right, which is the corner #prompt's meter uses one box
|
|
69
126
|
down, so titles sit left and status sits right throughout. */
|
|
70
127
|
border-subtitle-color: $text-muted;
|
|
128
|
+
/* `render()` pads every row to the panel width itself, and the
|
|
129
|
+
pin on that arithmetic is a test that no drawn row is wider
|
|
130
|
+
than the panel. This is the net under it, moved off the Rich
|
|
131
|
+
Text for `#agent-panel`'s reason: a row that ever does
|
|
132
|
+
overrun clips visibly instead of reflowing into a height the
|
|
133
|
+
budget did not count. */
|
|
134
|
+
text-wrap: nowrap;
|
|
135
|
+
text-overflow: clip;
|
|
71
136
|
}
|
|
72
137
|
|
|
73
138
|
/* Batch 54. `height: auto` with a `max-height` -- batch 49's shape, for
|
|
@@ -88,7 +153,8 @@
|
|
|
88
153
|
height: auto;
|
|
89
154
|
max-height: 6;
|
|
90
155
|
padding: 0 1;
|
|
91
|
-
/* The placeholder,
|
|
156
|
+
/* The placeholder, carried by the border title rather than TextArea's
|
|
157
|
+
native in-box one (assigning both drew it twice). Muted
|
|
92
158
|
is already this sheet's vocabulary for a hint (#usage-line,
|
|
93
159
|
#todo-panel, #research-progress), so it reads as one rather than
|
|
94
160
|
as a heading. */
|
|
@@ -119,6 +185,27 @@
|
|
|
119
185
|
#agent-panel {
|
|
120
186
|
height: auto;
|
|
121
187
|
padding-top: 1;
|
|
188
|
+
/* The rows are sized by the widget (AgentPanel.WIDTH lays out
|
|
189
|
+
against 18) and must not be re-wrapped underneath it: a
|
|
190
|
+
miscalculation should clip where it can be seen rather than
|
|
191
|
+
reflow where it cannot. This used to be `no_wrap` /
|
|
192
|
+
`overflow` on the Rich Text itself, which stopped meaning
|
|
193
|
+
anything when the textual pin moved -- a Content carries
|
|
194
|
+
neither flag and the conversion drops both. See
|
|
195
|
+
`widgets.as_content`. */
|
|
196
|
+
text-wrap: nowrap;
|
|
197
|
+
text-overflow: clip;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/* ROADMAP_v3 §49 (SS14). The same box as #agent-panel above, because it is
|
|
201
|
+
the same kind of widget in the same twenty columns: rows sized by the
|
|
202
|
+
widget (SessionPanel.WIDTH, which is AgentPanel.WIDTH) and clipped rather
|
|
203
|
+
than reflowed, for that block's reason. */
|
|
204
|
+
#session-panel {
|
|
205
|
+
height: auto;
|
|
206
|
+
padding-top: 1;
|
|
207
|
+
text-wrap: nowrap;
|
|
208
|
+
text-overflow: clip;
|
|
122
209
|
}
|
|
123
210
|
|
|
124
211
|
#effort-raven {
|
|
@@ -165,12 +252,23 @@ PermissionScreen {
|
|
|
165
252
|
screen had both a type selector and an id block for its dialog, and
|
|
166
253
|
five of nine never got the first -- they measured at x=0, y=0, pinned
|
|
167
254
|
to the top-left corner of an 80x24 terminal. The viewport test in
|
|
168
|
-
tests/test_tui.py pushes
|
|
255
|
+
tests/test_tui.py pushes every modal the app defines; until batch 179
|
|
256
|
+
it pushed only the ones its table listed, and SecretScreen, which came
|
|
257
|
+
later and missed both the row and this rule, opened every masked
|
|
258
|
+
prompt in the corner. */
|
|
169
259
|
|
|
170
260
|
GrantPickerScreen {
|
|
171
261
|
align: center middle;
|
|
172
262
|
}
|
|
173
263
|
|
|
264
|
+
SecretScreen {
|
|
265
|
+
align: center middle;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
NoticeScreen {
|
|
269
|
+
align: center middle;
|
|
270
|
+
}
|
|
271
|
+
|
|
174
272
|
SubagentSignoffScreen {
|
|
175
273
|
align: center middle;
|
|
176
274
|
}
|
|
@@ -230,6 +328,25 @@ ReviewScreen {
|
|
|
230
328
|
margin-bottom: 1;
|
|
231
329
|
}
|
|
232
330
|
|
|
331
|
+
/* Section 47. Which run raised the question, when it was not the
|
|
332
|
+
conversation itself. Muted and unbold: it qualifies the title rather
|
|
333
|
+
than competing with it, and it sits directly under it because RA6
|
|
334
|
+
reads a harness fact before anything the agent wrote.
|
|
335
|
+
|
|
336
|
+
It eats the title's margin, so the pair reads as one heading rather
|
|
337
|
+
than as two blocks -- which is what the margin exists to separate.
|
|
338
|
+
|
|
339
|
+
ONE ID ACROSS THE THREE MODALS that can be asked from inside a run
|
|
340
|
+
(batch 75: the sign-off and the model's own question joined the
|
|
341
|
+
permission prompt). Ids are per-screen, so one rule styles all three
|
|
342
|
+
and there is nothing to keep in step -- the same reason
|
|
343
|
+
`screens.asker_label` is one function. */
|
|
344
|
+
#permission-asker {
|
|
345
|
+
color: $text-muted;
|
|
346
|
+
margin-top: -1;
|
|
347
|
+
margin-bottom: 1;
|
|
348
|
+
}
|
|
349
|
+
|
|
233
350
|
/* The pinned subject of the question (§46, EP1), and the split
|
|
234
351
|
favours it deliberately: the payload below repeats the notice, the
|
|
235
352
|
reason and the command itself, so rows spent here buy the one thing
|
|
@@ -402,6 +519,72 @@ ClaimsScreen {
|
|
|
402
519
|
margin-bottom: 1;
|
|
403
520
|
}
|
|
404
521
|
|
|
522
|
+
/* Section 47's run picker, the keyboard route to what the sidebar
|
|
523
|
+
offers on a click. Narrower than the thread picker because its rows
|
|
524
|
+
are agent names and an indent rather than a uuid plus a preview,
|
|
525
|
+
and it takes the accent border the read-only pane takes: both say
|
|
526
|
+
the same thing, that what you are about to look at is not the
|
|
527
|
+
conversation you are having. */
|
|
528
|
+
#agent-picker-dialog {
|
|
529
|
+
width: 48;
|
|
530
|
+
height: auto;
|
|
531
|
+
max-height: 20;
|
|
532
|
+
padding: 1 2;
|
|
533
|
+
border: thick $accent;
|
|
534
|
+
background: $surface;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
#agent-picker-title {
|
|
538
|
+
text-style: bold;
|
|
539
|
+
padding-bottom: 1;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
#agent-picker-list {
|
|
543
|
+
height: auto;
|
|
544
|
+
max-height: 14;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/* Finished runs read muted. They open like any other row, so this is
|
|
548
|
+
de-emphasis rather than a warning -- and a muted hue rather than the
|
|
549
|
+
`dim` attribute, which is the transcript's vocabulary (test_themes
|
|
550
|
+
pins it to the system role) while this list is a modal, where
|
|
551
|
+
UNVERIFIED_COVERAGE already set the precedent that quiet names a
|
|
552
|
+
different state rather than a broken one. */
|
|
553
|
+
#agent-picker-list .finished {
|
|
554
|
+
color: $text-muted;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
AgentPickerScreen {
|
|
558
|
+
align: center middle;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/* ROADMAP_v3 §49 (SS2): the kill picker. Wider than the run picker
|
|
562
|
+
because its rows carry a command as well as a name, and a command cut
|
|
563
|
+
at 48 columns is exactly the "which one is this?" the picker exists to
|
|
564
|
+
answer. */
|
|
565
|
+
#session-kill-dialog {
|
|
566
|
+
width: 72;
|
|
567
|
+
height: auto;
|
|
568
|
+
max-height: 20;
|
|
569
|
+
padding: 1 2;
|
|
570
|
+
border: thick $accent;
|
|
571
|
+
background: $surface;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
#session-kill-title {
|
|
575
|
+
text-style: bold;
|
|
576
|
+
padding-bottom: 1;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
#session-kill-list {
|
|
580
|
+
height: auto;
|
|
581
|
+
max-height: 14;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
SessionKillScreen {
|
|
585
|
+
align: center middle;
|
|
586
|
+
}
|
|
587
|
+
|
|
405
588
|
#thread-dialog {
|
|
406
589
|
width: 70;
|
|
407
590
|
height: auto;
|
package/tui/commands.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""
|
|
2
2
|
tui/commands.py
|
|
3
3
|
|
|
4
|
-
ROADMAP_v2 §16 slash-command registry.
|
|
4
|
+
ROADMAP_v2 §16 slash-command registry -- the TUI's.
|
|
5
5
|
|
|
6
6
|
The registry is §16's; the commands registered into it are not all §16's.
|
|
7
7
|
D7 assigns `/skill <name>` to §19, and §18/§21 add their own -- each
|
|
@@ -9,162 +9,18 @@ registers here rather than editing a match statement in the app, which is
|
|
|
9
9
|
the same mechanism-vs-policy split tools/registry.py already uses for
|
|
10
10
|
tools.
|
|
11
11
|
|
|
12
|
+
Since ROADMAP_v3 §89 (#8) the MECHANISM lives in `core/commands.py`, beside
|
|
13
|
+
the catalog both shells bind to, because the CLI binds to it too and must
|
|
14
|
+
not import from `tui/` to do so. This module is the TUI's registry
|
|
15
|
+
instance: it takes only what the catalog declares for the TUI, built with
|
|
16
|
+
`bind()`.
|
|
17
|
+
|
|
12
18
|
A handler takes (app, argument_string) and returns None. It runs on the UI
|
|
13
19
|
thread, so anything slow belongs in a worker.
|
|
14
20
|
"""
|
|
15
21
|
|
|
16
|
-
from
|
|
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
|
|
22
|
+
from core.commands import TUI, CommandRegistry, SlashCommand, bind
|
|
168
23
|
|
|
24
|
+
__all__ = ["CommandRegistry", "SlashCommand", "bind", "registry"]
|
|
169
25
|
|
|
170
|
-
registry = CommandRegistry()
|
|
26
|
+
registry = CommandRegistry(TUI)
|