@yahyahammad/venastine 0.1.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/.env.example +14 -0
- package/LICENSE +201 -0
- package/NOTICE +14 -0
- package/PRIVACY.md +66 -0
- package/README.md +878 -0
- package/SECURITY.md +88 -0
- package/THIRD_PARTY_NOTICES.md +100 -0
- package/agents/builtin/compactor.md +75 -0
- package/agents/builtin/explore.md +77 -0
- package/agents/builtin/grill-me.md +27 -0
- package/agents/builtin/initializer.md +94 -0
- package/agents/builtin/pipeline-reviewer.md +100 -0
- package/agents/builtin/plan.md +88 -0
- package/agents/builtin/review.md +74 -0
- package/agents/manager.py +195 -0
- package/agents/subagent_tool.py +215 -0
- package/agents/tui_commands.py +136 -0
- package/bin/venastine.mjs +382 -0
- package/config.py +1198 -0
- package/core/__init__.py +0 -0
- package/core/approval.py +115 -0
- package/core/client.py +1548 -0
- package/core/compaction.py +959 -0
- package/core/config_loader.py +1563 -0
- package/core/events.py +61 -0
- package/core/interaction.py +328 -0
- package/core/loop.py +1353 -0
- package/core/memory.py +370 -0
- package/core/model_windows.py +175 -0
- package/core/pipeline_models.py +176 -0
- package/core/reasoning/__init__.py +0 -0
- package/core/reasoning/authorization.py +130 -0
- package/core/reasoning/base.py +219 -0
- package/core/reasoning/confidence_scoring.py +468 -0
- package/core/reasoning/events.py +149 -0
- package/core/reasoning/json_retry.py +219 -0
- package/core/reasoning/orchestrator.py +1382 -0
- package/core/reasoning/output_writer.py +286 -0
- package/core/reasoning/payload_validation.py +398 -0
- package/core/reasoning/pipeline_storage.py +361 -0
- package/core/reasoning/review.py +615 -0
- package/core/reasoning/scholar.py +434 -0
- package/core/reasoning/source_corpus.py +327 -0
- package/core/reasoning/source_scoring.py +855 -0
- package/core/replay.py +167 -0
- package/core/session.py +153 -0
- package/core/workspace_trust.py +207 -0
- package/credentials.py +180 -0
- package/database.py +252 -0
- package/env_secrets.py +77 -0
- package/json_store.py +123 -0
- package/logging_setup.py +185 -0
- package/main.py +1959 -0
- package/mcp_client/__init__.py +15 -0
- package/mcp_client/client.py +499 -0
- package/mcp_client/config.py +379 -0
- package/mcp_client/registration.py +182 -0
- package/memories/manager.py +132 -0
- package/memories/tui_commands.py +232 -0
- package/package.json +73 -0
- package/project_init/config_files.py +278 -0
- package/project_init/doc_sets.py +330 -0
- package/project_init/generator.py +564 -0
- package/project_init/manifest.py +406 -0
- package/project_init/tui_commands.py +144 -0
- package/prompts/__init__.py +0 -0
- package/prompts/annotate.md +14 -0
- package/prompts/assumption_audit.md +27 -0
- package/prompts/claim_extraction.md +34 -0
- package/prompts/completeness.md +18 -0
- package/prompts/confidence_tiers.md +23 -0
- package/prompts/critic_pass.md +24 -0
- package/prompts/final_synthesis.md +13 -0
- package/prompts/initial_generation.md +14 -0
- package/prompts/preliminary_plan.md +23 -0
- package/prompts/revalidate.md +25 -0
- package/prompts/revise.md +15 -0
- package/prompts/source_grounding.md +66 -0
- package/prompts/system_prompts.py +262 -0
- package/prompts/universal_system_prompt +7 -0
- package/prompts/untrusted_content +1 -0
- package/providers.json.example +92 -0
- package/pyproject.toml +100 -0
- package/requirements.txt +72 -0
- package/safety/__init__.py +0 -0
- package/safety/policy_enforcement.py +682 -0
- package/security/__init__.py +0 -0
- package/security/capability.py +177 -0
- package/security/permissions.py +190 -0
- package/security/posture.py +302 -0
- package/security/protected_paths.py +309 -0
- package/security/sandbox.py +985 -0
- package/skills/builtin/crypto/cryptography-verification.md +66 -0
- package/skills/builtin/math/formal-specification.md +67 -0
- package/skills/builtin/math/numerical-methods.md +66 -0
- package/skills/builtin/math/proof-writing.md +61 -0
- package/skills/builtin/research/experiment-design.md +62 -0
- package/skills/builtin/research/literature-review.md +65 -0
- package/skills/builtin/research/reproducibility.md +55 -0
- package/skills/builtin/research/source-evaluation.md +70 -0
- package/skills/builtin/research/statistical-inference.md +63 -0
- package/skills/builtin/research/technical-writing.md +59 -0
- package/skills/builtin/security/cybersecurity-research.md +63 -0
- package/skills/builtin/software/code-review.md +61 -0
- package/skills/builtin/software/debugging.md +61 -0
- package/skills/builtin/software/test-design.md +67 -0
- package/skills/manager.py +138 -0
- package/skills/tui_commands.py +111 -0
- package/storage.py +1005 -0
- package/tools/base.py +305 -0
- package/tools/builtin/__init__.py +0 -0
- package/tools/builtin/_math_common.py +377 -0
- package/tools/builtin/_net_common.py +61 -0
- package/tools/builtin/arxiv.py +223 -0
- package/tools/builtin/ask_user.py +213 -0
- package/tools/builtin/discrete_math.py +134 -0
- package/tools/builtin/fetch_url.py +153 -0
- package/tools/builtin/file_ops.py +412 -0
- package/tools/builtin/geometry.py +148 -0
- package/tools/builtin/get_time.py +20 -0
- package/tools/builtin/linear_algebra.py +155 -0
- package/tools/builtin/load_skill.py +66 -0
- package/tools/builtin/logic.py +96 -0
- package/tools/builtin/pin.py +193 -0
- package/tools/builtin/probability_stats.py +228 -0
- package/tools/builtin/project_docs.py +405 -0
- package/tools/builtin/remember.py +158 -0
- package/tools/builtin/shell.py +461 -0
- package/tools/builtin/symbolic_math.py +119 -0
- package/tools/builtin/todo.py +147 -0
- package/tools/builtin/web_search.py +151 -0
- package/tools/context.py +136 -0
- package/tools/isolation.py +314 -0
- package/tools/registry.py +897 -0
- package/tui/app.py +3423 -0
- package/tui/app.tcss +458 -0
- package/tui/commands.py +61 -0
- package/tui/diffs.py +265 -0
- package/tui/preferences.py +182 -0
- package/tui/ravens.py +146 -0
- package/tui/screens.py +943 -0
- package/tui/themes.py +366 -0
- package/tui/widgets.py +1239 -0
package/tui/screens.py
ADDED
|
@@ -0,0 +1,943 @@
|
|
|
1
|
+
"""
|
|
2
|
+
tui/screens.py
|
|
3
|
+
|
|
4
|
+
ROADMAP_v2 §16 modal screens: the permission prompt (AC2) and the thread
|
|
5
|
+
picker (§16 AC1), plus §25's research grant picker.
|
|
6
|
+
|
|
7
|
+
The permission modal is the load-bearing one. §13 built `permission_channel`
|
|
8
|
+
as a plain stdlib queue.Queue precisely so this hand-off works: the worker
|
|
9
|
+
thread running _run() blocks on channel.get() while the UI thread shows the
|
|
10
|
+
modal, and the user's answer unblocks it. Nothing here is async-aware --
|
|
11
|
+
the blocking side is a thread, not a coroutine.
|
|
12
|
+
|
|
13
|
+
EVERY RENDERABLE BUILT FROM A NON-LITERAL IS WRAPPED IN `Text(...)`
|
|
14
|
+
(batch 42, RA1). Textual renders a `str` through `Text.from_markup`, so
|
|
15
|
+
a square bracket in a tool argument, a claim, a thread preview or an
|
|
16
|
+
`ask_user` option is CONSOLE MARKUP here -- and these screens exist to
|
|
17
|
+
show a person exactly what a model asked for. Two live failures:
|
|
18
|
+
|
|
19
|
+
* `sed -i "s/[/]//" f.txt` in a permission payload
|
|
20
|
+
raised MarkupError inside compose(). The screen was pushed and
|
|
21
|
+
never rendered, so its dismissal callback never fired and the
|
|
22
|
+
worker parked on Queue.get() for ATTENDED_APPROVAL_TIMEOUT_S --
|
|
23
|
+
600s, presenting as a hang. ARCHITECTURE.md records that every
|
|
24
|
+
DISMISSAL path must produce a boolean; this is the case that rule
|
|
25
|
+
misses, because a screen that cannot render never reaches one.
|
|
26
|
+
|
|
27
|
+
* `ReviewScreen`'s title read `[{severity}]`, and `[high]` is a tag.
|
|
28
|
+
The severity was silently absent from every review modal since
|
|
29
|
+
§20 -- an unconditional defect, needing no adversary at all.
|
|
30
|
+
|
|
31
|
+
`markup=False` IS NOT THE FIX, and looks like it is. On the pinned
|
|
32
|
+
textual 1.0.0 `Static.__init__` stores the flag and assigns
|
|
33
|
+
`self._content` directly; the `visual` property then calls
|
|
34
|
+
`render_str()` -> `Text.from_markup` unconditionally and never reads
|
|
35
|
+
it. Only the `renderable` SETTER honours it, and no constructor goes
|
|
36
|
+
through the setter -- so `Static(x, markup=False)` still raises,
|
|
37
|
+
measured. `render_str` returns a `Text` unaltered, which is why
|
|
38
|
+
wrapping works and is the only thing here that does.
|
|
39
|
+
|
|
40
|
+
A literal written in THIS file is left alone: it is ours and it is
|
|
41
|
+
reviewed. The rule is mechanical, so it holds for the next screen
|
|
42
|
+
somebody adds -- test_tui.py walks this file's AST and asserts it.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
import json
|
|
46
|
+
|
|
47
|
+
from rich.text import Text
|
|
48
|
+
from textual.app import ComposeResult
|
|
49
|
+
from textual.containers import Horizontal, Vertical, VerticalScroll
|
|
50
|
+
from textual.screen import ModalScreen
|
|
51
|
+
from textual.widgets import (
|
|
52
|
+
Button, Input, Label, ListItem, ListView, SelectionList, Static,
|
|
53
|
+
)
|
|
54
|
+
from textual.widgets.selection_list import Selection
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class ScrollBox(VerticalScroll):
|
|
58
|
+
"""A bounded block of text whose overflow can actually be reached
|
|
59
|
+
(§46, EP3).
|
|
60
|
+
|
|
61
|
+
Two things were wrong with `Static` + `max-height` + `overflow-y`,
|
|
62
|
+
and only the first is the one that looks wrong:
|
|
63
|
+
|
|
64
|
+
* `Static.can_focus` is False on the pinned textual 1.0.0, so the
|
|
65
|
+
scrollbar such a rule produces can only be moved by a mouse.
|
|
66
|
+
* A `Static` NEVER reports content taller than its own box --
|
|
67
|
+
`virtual_size` follows the clamped box, not the text -- so
|
|
68
|
+
`max_scroll_y` was 0 and the hidden rows were not scrolled past,
|
|
69
|
+
they were GONE. Measured: nine lines of payload in a seven-row
|
|
70
|
+
block, `max_scroll_y == 0`, End does nothing. Making the Static
|
|
71
|
+
focusable would have fixed the visible half of that and left the
|
|
72
|
+
truncation exactly where it was.
|
|
73
|
+
|
|
74
|
+
So the bound belongs on a real scroll container and the text on an
|
|
75
|
+
auto-height child inside it.
|
|
76
|
+
|
|
77
|
+
THE BOUND IS `height: auto` WITH A `max-height`, NOT A DEFINITE
|
|
78
|
+
`height` (batch 49, amending EP3). §46 read the zero it measured as
|
|
79
|
+
"a scrollable container asked for `height: auto` resolves to ZERO"
|
|
80
|
+
and prescribed a definite height. The zero was EP1's `1fr` ROW.
|
|
81
|
+
Measured again with the row `auto`, all three spellings differ and
|
|
82
|
+
only one is right:
|
|
83
|
+
|
|
84
|
+
25 lines of payload, grid row `auto`
|
|
85
|
+
height: auto box=25, no scroll, BUTTONS OUTSIDE
|
|
86
|
+
height: 9 box=9, 16 scrollable, BUTTONS OUT
|
|
87
|
+
height: auto; max-height: 9 box=9, 16 scrollable, buttons in
|
|
88
|
+
the same three inside a `1fr` row box=0, all three
|
|
89
|
+
|
|
90
|
+
A definite height bounds what this box DRAWS and not what its parent
|
|
91
|
+
RESERVES, so the row kept growing with the payload and pushed the
|
|
92
|
+
Allow/Deny row past the dialog's own `max-height`, where it was
|
|
93
|
+
clipped away entirely. `auto` with a `max-height` reports the bound
|
|
94
|
+
upward, so the dialog stays inside itself -- and it still shrinks for
|
|
95
|
+
a short payload, which a definite height never did.
|
|
96
|
+
|
|
97
|
+
Bindings are `ScrollableContainer`'s minus the horizontal ones:
|
|
98
|
+
there is nothing to scroll sideways, because the text wraps.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class PermissionScreen(ModalScreen[bool]):
|
|
103
|
+
"""Approve or deny one tool call. Dismisses with the decision.
|
|
104
|
+
|
|
105
|
+
The payload is shown FULL and UNREDACTED: the user must see the exact
|
|
106
|
+
path/command/URL they are being asked to authorise, and truncation or
|
|
107
|
+
redaction here would make the consent uninformed (the param_digest
|
|
108
|
+
truncation is for the transcript only). Logs redact via
|
|
109
|
+
logging_setup._RedactingFormatter and safety/policy_enforcement's
|
|
110
|
+
check_output_policy, so the full value never reaches disk unguarded —
|
|
111
|
+
do not add redaction here to "match" the transcript.
|
|
112
|
+
|
|
113
|
+
Full and unredacted, and NOT INTERPRETED: the payload goes
|
|
114
|
+
through `Text(...)` so a bracket in a command stays a bracket.
|
|
115
|
+
Showing the exact value is this screen's whole purpose, and
|
|
116
|
+
markup parsing is a way of showing something else -- see the
|
|
117
|
+
module docstring.
|
|
118
|
+
|
|
119
|
+
THE RATIONALE IS NOT EVIDENCE (§42, RA6). It is the agent's own
|
|
120
|
+
sentence about its own call, so it is unverifiable by
|
|
121
|
+
construction: an agent that has been steered writes a reassuring
|
|
122
|
+
one, and that is the case this screen exists for. It is labelled
|
|
123
|
+
as a claim and placed BELOW the notice, which the harness
|
|
124
|
+
computed, so nobody reads the harness as vouching for it. What it
|
|
125
|
+
is actually for is longitudinal -- a thread's worth of stated
|
|
126
|
+
reasons, archived beside the calls, is a drift signal no single
|
|
127
|
+
prompt can be.
|
|
128
|
+
|
|
129
|
+
THE SUBJECT OF THE QUESTION IS PINNED, OUTSIDE THE SCROLL (§46,
|
|
130
|
+
EP1). RA6 ordered three things -- the harness's notice, the agent's
|
|
131
|
+
claim, the payload -- and the command is none of them: it is what
|
|
132
|
+
all three are ABOUT. Ranked among them it came last, inside the
|
|
133
|
+
payload, which is how a user came to report that the command was
|
|
134
|
+
visible in the transcript and nowhere on the modal asking about it.
|
|
135
|
+
The payload keeps RA6's order intact below; the headline is lifted
|
|
136
|
+
out of the ranking, not moved up it.
|
|
137
|
+
|
|
138
|
+
What the investigation actually found is worse than the ordering,
|
|
139
|
+
and it is recorded here because the obvious reading of the report
|
|
140
|
+
was wrong. `#permission-params` sat in a `1fr` grid row inside a
|
|
141
|
+
`height: auto` dialog, and a fractional row in an auto-height
|
|
142
|
+
container resolves to ZERO. Measured against HEAD in a worktree:
|
|
143
|
+
`region.height == 0`, `virtual_size.height == 0`, nine lines of
|
|
144
|
+
content. The notice, the agent's stated reason and the payload were
|
|
145
|
+
not clipped and scrollable -- they were absent, from every
|
|
146
|
+
permission modal this app has ever shown, for every tool. The
|
|
147
|
+
command was merely the part somebody noticed was missing.
|
|
148
|
+
|
|
149
|
+
Nothing caught it because every assertion about this screen reads
|
|
150
|
+
`.visual._renderable.plain`, the string the widget was built from,
|
|
151
|
+
which a widget of zero height still reports in full. §46's tests
|
|
152
|
+
assert on the rendered REGION for that reason.
|
|
153
|
+
|
|
154
|
+
The headline is DISPLAY ONLY and is also inside `params`, which is
|
|
155
|
+
still rendered whole below it. That duplication is deliberate for
|
|
156
|
+
the reason the rationale's is: this screen shows the payload
|
|
157
|
+
entire, and the pinned copy is a placement, not a substitution. A
|
|
158
|
+
reader comparing the two is doing something useful.
|
|
159
|
+
"""
|
|
160
|
+
|
|
161
|
+
BINDINGS = [("escape", "deny", "Deny")]
|
|
162
|
+
|
|
163
|
+
def __init__(self, tool_name: str, params: dict, notice: str = None,
|
|
164
|
+
rationale: str = None, headline: str = None):
|
|
165
|
+
super().__init__()
|
|
166
|
+
self._tool_name = tool_name
|
|
167
|
+
self._params = params
|
|
168
|
+
# §46 (EP2). What this call is asking to DO -- for `shell`, the
|
|
169
|
+
# command. Resolved by the registry from whichever param the
|
|
170
|
+
# tool declared and passed in already a string, for the reason
|
|
171
|
+
# the rationale is: this module imports nothing from the rest
|
|
172
|
+
# of the project. None for every tool that declares no
|
|
173
|
+
# headline, and the pinned block simply does not render.
|
|
174
|
+
self._headline = headline
|
|
175
|
+
# §42 (RA6). The agent's OWN account of why it wants this call,
|
|
176
|
+
# resolved by the registry from whichever param the tool
|
|
177
|
+
# declared. Passed in rather than looked up: this module
|
|
178
|
+
# imports nothing from the rest of the project and that is
|
|
179
|
+
# worth more than saving a parameter.
|
|
180
|
+
self._rationale = rationale
|
|
181
|
+
# Supplied by the tool via ToolSpec.approval_notice, not composed
|
|
182
|
+
# here: what approving authorises is the TOOL's knowledge.
|
|
183
|
+
# spawn_subagent uses it to list the tools the subagent could then
|
|
184
|
+
# run unprompted, which the params alone never say.
|
|
185
|
+
# DISPLAYED FULL above — see class docstring for why this stays
|
|
186
|
+
# unredacted while the transcript's `▸` digest and the log do not.
|
|
187
|
+
self._notice = notice
|
|
188
|
+
|
|
189
|
+
def compose(self) -> ComposeResult:
|
|
190
|
+
try:
|
|
191
|
+
rendered = json.dumps(self._params, indent=2, default=str)
|
|
192
|
+
except (TypeError, ValueError):
|
|
193
|
+
rendered = repr(self._params)
|
|
194
|
+
# HARNESS FACT, THEN AGENT CLAIM, THEN EVIDENCE (§42, RA6).
|
|
195
|
+
# The notice is computed -- `classify_command` decided it --
|
|
196
|
+
# so it is read before any reassurance the model wrote. The
|
|
197
|
+
# payload stays last and stays whole; the rationale appears in
|
|
198
|
+
# it as well, and that duplication is the honest cost of
|
|
199
|
+
# surfacing the field without breaking the rule above that
|
|
200
|
+
# this screen shows the payload entire.
|
|
201
|
+
reason = self._rationale or "(none given)"
|
|
202
|
+
rendered = (f"Agent's stated reason (its own words, unverified):\n"
|
|
203
|
+
f" {reason}\n\n{rendered}")
|
|
204
|
+
if self._notice:
|
|
205
|
+
rendered = f"{self._notice}\n\n{rendered}"
|
|
206
|
+
widgets = [Label(Text(f"Allow {self._tool_name}?"),
|
|
207
|
+
id="permission-title")]
|
|
208
|
+
if self._headline:
|
|
209
|
+
# `Text(...)` is not optional here (batch 42, RA1). This is
|
|
210
|
+
# the most attacker-influenced string on the screen -- a
|
|
211
|
+
# model-authored command shown so a person can vet it --
|
|
212
|
+
# and `Static` renders a `str` through `Text.from_markup`,
|
|
213
|
+
# so `sed -i "s/[/]//" f.txt` would raise MarkupError
|
|
214
|
+
# inside compose(), leaving the screen pushed, unrendered
|
|
215
|
+
# and its dismissal callback never fired. test_tui.py walks
|
|
216
|
+
# this file's AST and asserts the wrapping.
|
|
217
|
+
widgets.append(ScrollBox(
|
|
218
|
+
Static(Text(self._headline), id="permission-command"),
|
|
219
|
+
id="permission-command-box"))
|
|
220
|
+
# The id stays on the STATIC and the scroll container is a
|
|
221
|
+
# `-box` sibling, rather than the other way round: a stylesheet
|
|
222
|
+
# wants the bound and the overflow, which belong to the
|
|
223
|
+
# container, while every assertion in test_rationale.py and
|
|
224
|
+
# test_tui.py asks what text was DRAWN, which only the Static
|
|
225
|
+
# can answer. Moving the id outward would make
|
|
226
|
+
# `query_one("#permission-params")` return a container with no
|
|
227
|
+
# `visual` -- and reading that attribute is how batch 42's
|
|
228
|
+
# markup bug was caught.
|
|
229
|
+
widgets.append(ScrollBox(
|
|
230
|
+
Static(Text(rendered), id="permission-params"),
|
|
231
|
+
id="permission-params-box"))
|
|
232
|
+
# ONE bar, centred, holding both answers (batch 49). Two
|
|
233
|
+
# Buttons in a two-column Grid sat at the LEFT of their columns,
|
|
234
|
+
# so a 16-wide Deny left ~22 dead columns beside it while Allow
|
|
235
|
+
# was flush against the padding -- the dialog was centred and its
|
|
236
|
+
# contents were not. A Horizontal with `align: center middle`
|
|
237
|
+
# centres the pair as a unit and keeps both answers the same
|
|
238
|
+
# size, which the alternative (each button filling its half) does
|
|
239
|
+
# not: it would make the permissive answer a target half the
|
|
240
|
+
# width of the modal.
|
|
241
|
+
widgets.append(Horizontal(
|
|
242
|
+
Button("Allow", variant="success", id="allow"),
|
|
243
|
+
Button("Deny", variant="error", id="deny"),
|
|
244
|
+
id="permission-buttons"))
|
|
245
|
+
# A Vertical, not a Grid (batch 49). Every child spanned both
|
|
246
|
+
# columns, so the second column only ever held the Deny button --
|
|
247
|
+
# and the `with-headline` class existed solely to carry a ROW
|
|
248
|
+
# COUNT to the stylesheet, because a Grid's `grid-size` is static
|
|
249
|
+
# and this screen composes three children or four. A Vertical
|
|
250
|
+
# does not care how many there are, so the template it guarded
|
|
251
|
+
# against getting wrong is gone rather than documented.
|
|
252
|
+
yield Vertical(*widgets, id="permission-dialog")
|
|
253
|
+
|
|
254
|
+
def on_mount(self) -> None:
|
|
255
|
+
# ENTER DECLINES (batch 49). Focus lands on the first focusable
|
|
256
|
+
# widget otherwise, which is whichever ScrollBox composed first --
|
|
257
|
+
# so Enter did nothing here, and on ConfirmScreen, whose body is a
|
|
258
|
+
# plain Static, it said YES. The convenient action must not be the
|
|
259
|
+
# permissive one; that is already the recorded reason
|
|
260
|
+
# GrantPickerScreen ships every option unticked, and it applies
|
|
261
|
+
# with more force to a key a person presses without looking.
|
|
262
|
+
self.query_one("#deny", Button).focus()
|
|
263
|
+
|
|
264
|
+
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
265
|
+
self.dismiss(event.button.id == "allow")
|
|
266
|
+
|
|
267
|
+
def action_deny(self) -> None:
|
|
268
|
+
# Escape answers with the SAME value the No button produces.
|
|
269
|
+
# Since §23 a dismissal carrying None would be safe anyway --
|
|
270
|
+
# interaction.decode supplies APPROVAL's declining default -- so
|
|
271
|
+
# this is explicitness rather than hang-prevention: one screen
|
|
272
|
+
# should not have two ways to say no.
|
|
273
|
+
self.dismiss(False)
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
class GrantPickerScreen(ModalScreen[object]):
|
|
277
|
+
"""Pick which approval-gated tools a research run may use (§25 R1).
|
|
278
|
+
|
|
279
|
+
Dismisses with a set of names, or None to cancel the run entirely --
|
|
280
|
+
the two are different answers. An empty SET means "run with no grants"
|
|
281
|
+
(a legitimate choice: the pipeline just keeps hiding gated tools),
|
|
282
|
+
while None means "I did not mean to start this at all".
|
|
283
|
+
|
|
284
|
+
Per-tool rather than one prompt for the whole set, and each row shows
|
|
285
|
+
what the tool says it does, because the harness cannot tell a
|
|
286
|
+
read-only tool from one that writes or sends -- MCP exposes no such
|
|
287
|
+
metadata. The description and the individual choice are the entire
|
|
288
|
+
substance of informed consent here.
|
|
289
|
+
"""
|
|
290
|
+
|
|
291
|
+
BINDINGS = [("escape", "cancel", "Cancel")]
|
|
292
|
+
|
|
293
|
+
def __init__(self, offered: list):
|
|
294
|
+
super().__init__()
|
|
295
|
+
self._offered = list(offered)
|
|
296
|
+
|
|
297
|
+
def compose(self) -> ComposeResult:
|
|
298
|
+
# Every option starts UNSELECTED. A pre-ticked list would make the
|
|
299
|
+
# convenient action the permissive one, and this prompt exists
|
|
300
|
+
# precisely because nobody will be watching afterwards.
|
|
301
|
+
options = [
|
|
302
|
+
Selection(Text(f"{name} — {description}" if description
|
|
303
|
+
else name),
|
|
304
|
+
name, False)
|
|
305
|
+
for name, description in self._offered
|
|
306
|
+
]
|
|
307
|
+
yield Vertical(
|
|
308
|
+
Label("Authorise for this run only", id="grant-title"),
|
|
309
|
+
Static(
|
|
310
|
+
"These tools need approval, and nothing can give it during "
|
|
311
|
+
"an unattended run.\nSpace toggles, Enter confirms, Escape "
|
|
312
|
+
"cancels the run. Nothing is saved.",
|
|
313
|
+
id="grant-help"),
|
|
314
|
+
SelectionList(*options, id="grant-list"),
|
|
315
|
+
# A bar with one button in it. NO focus call here and none on
|
|
316
|
+
# ProjectKindScreen: neither screen HAS a declining button --
|
|
317
|
+
# escape is the decline on both -- so there is nothing to
|
|
318
|
+
# focus that would make Enter safe, and focusing the
|
|
319
|
+
# affirmative one for consistency would be the exact
|
|
320
|
+
# inversion PermissionScreen.on_mount exists to prevent.
|
|
321
|
+
Horizontal(
|
|
322
|
+
Button("Run with selected", variant="success",
|
|
323
|
+
id="grant-ok"),
|
|
324
|
+
id="grant-buttons"),
|
|
325
|
+
id="grant-dialog",
|
|
326
|
+
)
|
|
327
|
+
|
|
328
|
+
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
329
|
+
self.dismiss(set(self.query_one("#grant-list", SelectionList).selected))
|
|
330
|
+
|
|
331
|
+
def action_cancel(self) -> None:
|
|
332
|
+
self.dismiss(None)
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
class SubagentSignoffScreen(ModalScreen[object]):
|
|
336
|
+
"""Pick which of a subagent's gated tools it may use unprompted
|
|
337
|
+
(ROADMAP_v2 §23 AC1b).
|
|
338
|
+
|
|
339
|
+
Modelled on GrantPickerScreen, and dismissing with the same THREE
|
|
340
|
+
answers for the same reason: a set of names grants those, an EMPTY set
|
|
341
|
+
spawns the agent with nothing granted, and None refuses the spawn
|
|
342
|
+
outright. Those are three different intentions and a bool cannot hold
|
|
343
|
+
them -- which is precisely why §18 shipped this all-or-nothing (S1)
|
|
344
|
+
on a boolean channel, and why it could only be built once §23 gave the
|
|
345
|
+
channel a typed answer.
|
|
346
|
+
|
|
347
|
+
Every option starts UNSELECTED. A pre-ticked list makes the convenient
|
|
348
|
+
action the permissive one, and the point of this prompt is that
|
|
349
|
+
approving a spawn used to authorise the child's ENTIRE gated set.
|
|
350
|
+
"""
|
|
351
|
+
|
|
352
|
+
BINDINGS = [("escape", "refuse", "Refuse")]
|
|
353
|
+
|
|
354
|
+
def __init__(self, agent: str, candidates: list):
|
|
355
|
+
super().__init__()
|
|
356
|
+
self._agent = agent
|
|
357
|
+
self._candidates = list(candidates)
|
|
358
|
+
|
|
359
|
+
def compose(self) -> ComposeResult:
|
|
360
|
+
if not self._candidates:
|
|
361
|
+
yield Vertical(
|
|
362
|
+
Label(Text(f"Run {self._agent}?"),
|
|
363
|
+
id="permission-title"),
|
|
364
|
+
Static(Text(f"{self._agent} needs no approval-gated "
|
|
365
|
+
f"tools."),
|
|
366
|
+
id="permission-params"),
|
|
367
|
+
Horizontal(
|
|
368
|
+
Button("Run", variant="success", id="signoff-none"),
|
|
369
|
+
Button("Refuse", variant="error", id="signoff-refuse"),
|
|
370
|
+
id="permission-buttons"),
|
|
371
|
+
id="permission-dialog",
|
|
372
|
+
)
|
|
373
|
+
return
|
|
374
|
+
options = [Selection(Text(name), name, False)
|
|
375
|
+
for name in self._candidates]
|
|
376
|
+
yield Vertical(
|
|
377
|
+
Label(Text(f"What may {self._agent} use without asking again?"),
|
|
378
|
+
id="grant-title"),
|
|
379
|
+
Static(
|
|
380
|
+
"Space toggles, then choose. Anything left unticked still "
|
|
381
|
+
"prompts you if the subagent tries it.\nRunning with none "
|
|
382
|
+
"selected is fine. Escape refuses the spawn entirely.",
|
|
383
|
+
id="grant-help"),
|
|
384
|
+
SelectionList(*options, id="signoff-list"),
|
|
385
|
+
Horizontal(
|
|
386
|
+
Button("Run with selected", variant="success",
|
|
387
|
+
id="signoff-ok"),
|
|
388
|
+
Button("Refuse the spawn", variant="error",
|
|
389
|
+
id="signoff-refuse"),
|
|
390
|
+
id="grant-buttons"),
|
|
391
|
+
id="grant-dialog",
|
|
392
|
+
)
|
|
393
|
+
|
|
394
|
+
def on_mount(self) -> None:
|
|
395
|
+
# The refusal, on both branches -- see PermissionScreen.on_mount.
|
|
396
|
+
self.query_one("#signoff-refuse", Button).focus()
|
|
397
|
+
|
|
398
|
+
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
399
|
+
if event.button.id == "signoff-refuse":
|
|
400
|
+
self.dismiss(None)
|
|
401
|
+
elif event.button.id == "signoff-none":
|
|
402
|
+
self.dismiss(set())
|
|
403
|
+
else:
|
|
404
|
+
self.dismiss(
|
|
405
|
+
set(self.query_one("#signoff-list", SelectionList).selected))
|
|
406
|
+
|
|
407
|
+
def action_refuse(self) -> None:
|
|
408
|
+
# Escape REFUSES rather than running with nothing granted. The two
|
|
409
|
+
# are different answers, and the one a user reaches for when they
|
|
410
|
+
# did not mean to start this is the refusal.
|
|
411
|
+
self.dismiss(None)
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
class QuestionScreen(ModalScreen[object]):
|
|
415
|
+
"""Ask the user the model's question (§23 slice 2, AC2).
|
|
416
|
+
|
|
417
|
+
Dismisses with a dict, or None. THREE answers, and the middle one is
|
|
418
|
+
the one to lose -- the same distinction SubagentSignoffScreen draws:
|
|
419
|
+
|
|
420
|
+
None nobody answered. Escape, and the app's
|
|
421
|
+
shutdown release.
|
|
422
|
+
{"defer": True} "let's talk about it instead". A REAL
|
|
423
|
+
answer: the user engaged and declined to
|
|
424
|
+
pick, which tells the model something that
|
|
425
|
+
closing the modal does not.
|
|
426
|
+
{"options": [...], what they chose, what they typed, or both.
|
|
427
|
+
"text": "..."}
|
|
428
|
+
|
|
429
|
+
Four affordances, all four from the spec. Options are a SelectionList
|
|
430
|
+
when several may be chosen and Buttons when only one may -- a
|
|
431
|
+
single-select SelectionList would let a user tick three and then be
|
|
432
|
+
told only one counted, which is a worse lie than not offering it.
|
|
433
|
+
|
|
434
|
+
UNSELECTED and EMPTY to start, like every other picker here. The
|
|
435
|
+
convenient action must not be the one that answers on the user's
|
|
436
|
+
behalf, and this modal exists precisely because the model does not
|
|
437
|
+
know the answer.
|
|
438
|
+
|
|
439
|
+
The screen does NOT validate. Whether a returned option was actually
|
|
440
|
+
offered is core.interaction.decode's job, which is why it takes the
|
|
441
|
+
request -- ProjectKindScreen made the same move for the same reason.
|
|
442
|
+
"""
|
|
443
|
+
|
|
444
|
+
BINDINGS = [("escape", "dismiss_unanswered", "No answer")]
|
|
445
|
+
|
|
446
|
+
def __init__(self, question: str, options=(), multi_select: bool = False,
|
|
447
|
+
allow_text: bool = True):
|
|
448
|
+
super().__init__()
|
|
449
|
+
self._question = question
|
|
450
|
+
self._options = list(options)
|
|
451
|
+
self._multi = bool(multi_select)
|
|
452
|
+
self._allow_text = bool(allow_text)
|
|
453
|
+
|
|
454
|
+
def compose(self) -> ComposeResult:
|
|
455
|
+
# The question is the MODEL's, so its length is the one thing
|
|
456
|
+
# this screen does not choose -- bounded and scrollable for the
|
|
457
|
+
# same reason the payload block is.
|
|
458
|
+
widgets = [Label("The assistant has a question", id="question-title"),
|
|
459
|
+
ScrollBox(Static(Text(self._question), id="question-body"),
|
|
460
|
+
id="question-body-box")]
|
|
461
|
+
|
|
462
|
+
if self._options and self._multi:
|
|
463
|
+
widgets.append(Static(
|
|
464
|
+
"Space toggles; several may be chosen.", id="question-help"))
|
|
465
|
+
widgets.append(SelectionList(
|
|
466
|
+
*[Selection(Text(o), o, False) for o in self._options],
|
|
467
|
+
id="question-list"))
|
|
468
|
+
widgets.append(
|
|
469
|
+
Button("Answer", variant="success", id="question-ok"))
|
|
470
|
+
elif self._options:
|
|
471
|
+
# Bounded and scrollable, like the multi-select branch's
|
|
472
|
+
# SelectionList beside it (batch 49). Unbounded, four options
|
|
473
|
+
# of two lines each cost 16 of the dialog's 18 rows and took
|
|
474
|
+
# the Answer button and Discuss instead off the bottom with
|
|
475
|
+
# them. The Buttons are also FIXED WIDTH in the stylesheet:
|
|
476
|
+
# at `width: auto` an option wider than the dialog was
|
|
477
|
+
# CLIPPED, and the same label at `width: 100%` wraps to two
|
|
478
|
+
# centred lines instead.
|
|
479
|
+
widgets.append(ScrollBox(
|
|
480
|
+
*[Button(option, variant="primary",
|
|
481
|
+
id=f"question-opt-{index}")
|
|
482
|
+
for index, option in enumerate(self._options)],
|
|
483
|
+
id="question-options"))
|
|
484
|
+
|
|
485
|
+
if self._allow_text:
|
|
486
|
+
widgets.append(Input(
|
|
487
|
+
placeholder="…or write your own answer",
|
|
488
|
+
id="question-text"))
|
|
489
|
+
if not (self._options and self._multi):
|
|
490
|
+
# A submit button for the typed answer. The multi-select
|
|
491
|
+
# branch already has one, and the single-select branch's
|
|
492
|
+
# option Buttons read the Input too -- but an open question
|
|
493
|
+
# with no options at all would otherwise have no way to
|
|
494
|
+
# submit anything.
|
|
495
|
+
widgets.append(
|
|
496
|
+
Button("Answer", variant="success", id="question-ok"))
|
|
497
|
+
|
|
498
|
+
# Always last, always available: the spec's escape is an answer the
|
|
499
|
+
# user can give on purpose, not only a thing that happens when they
|
|
500
|
+
# close the window. In the bar rather than beside it, so it cannot
|
|
501
|
+
# be the child that falls off the bottom -- which is exactly what
|
|
502
|
+
# it was.
|
|
503
|
+
trailing = [w for w in widgets if getattr(w, "id", "") == "question-ok"]
|
|
504
|
+
for widget in trailing:
|
|
505
|
+
widgets.remove(widget)
|
|
506
|
+
widgets.append(Horizontal(
|
|
507
|
+
*trailing,
|
|
508
|
+
Button("Discuss instead", variant="default", id="question-defer"),
|
|
509
|
+
id="question-buttons"))
|
|
510
|
+
yield Vertical(*widgets, id="question-dialog")
|
|
511
|
+
|
|
512
|
+
def on_mount(self) -> None:
|
|
513
|
+
# The first OPTION, which is where focus landed before the options
|
|
514
|
+
# gained a ScrollBox around them -- a scroll container is focusable
|
|
515
|
+
# and would otherwise take it. NOT the declining button: this
|
|
516
|
+
# screen authorises nothing, so there is no permissive answer for
|
|
517
|
+
# Enter to give, and the whole point of it is that the model does
|
|
518
|
+
# not know which option is right.
|
|
519
|
+
for candidate in ("#question-opt-0", "#question-list",
|
|
520
|
+
"#question-text", "#question-defer"):
|
|
521
|
+
found = self.query(candidate)
|
|
522
|
+
if found:
|
|
523
|
+
found.first().focus()
|
|
524
|
+
return
|
|
525
|
+
|
|
526
|
+
def _typed(self) -> str:
|
|
527
|
+
if not self._allow_text:
|
|
528
|
+
return ""
|
|
529
|
+
# Read on EVERY path, like ReviewScreen's note: a user who ticks an
|
|
530
|
+
# option and qualifies it in the box has given one answer, and
|
|
531
|
+
# dropping half of it because they pressed the wrong button first
|
|
532
|
+
# would be silent.
|
|
533
|
+
try:
|
|
534
|
+
return self.query_one("#question-text", Input).value.strip()
|
|
535
|
+
except Exception: # noqa: BLE001 -- absent when allow_text is False
|
|
536
|
+
return ""
|
|
537
|
+
|
|
538
|
+
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
539
|
+
button_id = event.button.id or ""
|
|
540
|
+
if button_id == "question-defer":
|
|
541
|
+
self.dismiss({"defer": True})
|
|
542
|
+
return
|
|
543
|
+
|
|
544
|
+
chosen = []
|
|
545
|
+
if button_id.startswith("question-opt-"):
|
|
546
|
+
index = int(button_id.rsplit("-", 1)[1])
|
|
547
|
+
chosen = [self._options[index]]
|
|
548
|
+
self._answer(chosen)
|
|
549
|
+
|
|
550
|
+
def on_input_submitted(self, event: Input.Submitted) -> None:
|
|
551
|
+
# Enter in the text box answers (batch 49). Textual posts this and
|
|
552
|
+
# nothing handled it, so the one affordance whose entire purpose
|
|
553
|
+
# is being typed into had no way to send what was typed -- and the
|
|
554
|
+
# Answer button it needed instead was the child clipped off the
|
|
555
|
+
# bottom. Through `_answer`, not a second dismissal: one shape of
|
|
556
|
+
# answer, one place that builds it.
|
|
557
|
+
self._answer([])
|
|
558
|
+
|
|
559
|
+
def _answer(self, chosen: list) -> None:
|
|
560
|
+
if self._options and self._multi:
|
|
561
|
+
chosen = list(
|
|
562
|
+
self.query_one("#question-list", SelectionList).selected)
|
|
563
|
+
self.dismiss({"options": chosen, "text": self._typed()})
|
|
564
|
+
|
|
565
|
+
def action_dismiss_unanswered(self) -> None:
|
|
566
|
+
# None, NOT a deferral. Escape means "I am not dealing with this";
|
|
567
|
+
# "Discuss instead" means "I want to talk about it". The tool says
|
|
568
|
+
# different things to the model about each, so collapsing them here
|
|
569
|
+
# would make the button pointless.
|
|
570
|
+
self.dismiss(None)
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
class ReviewScreen(ModalScreen[object]):
|
|
574
|
+
"""Decide one proposed correction to a finished research run (§20 V4).
|
|
575
|
+
|
|
576
|
+
Dismisses with a (decision, notes) tuple. Every dismissal path carries
|
|
577
|
+
one -- escape, the buttons, and the app's shutdown release -- because
|
|
578
|
+
the /research worker is blocked on a queue that must receive AN
|
|
579
|
+
answer. What the answer is matters less than that it arrives:
|
|
580
|
+
interaction.decode turns anything unusable (None, a bare False from
|
|
581
|
+
shutdown, malformed junk) into REVIEW's declining default, so a new
|
|
582
|
+
path added later fails safe -- an edit is never applied because
|
|
583
|
+
nobody answered.
|
|
584
|
+
|
|
585
|
+
Four outcomes, not two. Reject and refine are different answers: "this
|
|
586
|
+
is wrong" ends the finding, while "you missed something" sends it back
|
|
587
|
+
with a note. And "reject the rest" is the escape a long review needs,
|
|
588
|
+
safe by construction because it only ever declines -- the affordance
|
|
589
|
+
that must NOT exist is the one that accepts in bulk.
|
|
590
|
+
"""
|
|
591
|
+
|
|
592
|
+
BINDINGS = [("escape", "reject", "Reject")]
|
|
593
|
+
|
|
594
|
+
def __init__(self, finding: dict, round_index: int = 0,
|
|
595
|
+
max_rounds: int = 0):
|
|
596
|
+
super().__init__()
|
|
597
|
+
self._finding = finding
|
|
598
|
+
self._round = round_index
|
|
599
|
+
self._max_rounds = max_rounds
|
|
600
|
+
|
|
601
|
+
def compose(self) -> ComposeResult:
|
|
602
|
+
kind = self._finding.get("kind", "?")
|
|
603
|
+
target = self._finding.get("claim_id") or "the report"
|
|
604
|
+
severity = self._finding.get("severity", "unknown")
|
|
605
|
+
body = (
|
|
606
|
+
f"Why: {self._finding.get('reason', '(no reason given)')}\n\n"
|
|
607
|
+
f"Proposed: {self._finding.get('proposed')}"
|
|
608
|
+
)
|
|
609
|
+
if self._round:
|
|
610
|
+
body = (f"(refinement {self._round} of {self._max_rounds})\n\n"
|
|
611
|
+
f"{body}")
|
|
612
|
+
yield Vertical(
|
|
613
|
+
# `[{severity}]` is a MARKUP TAG to Rich, so this title
|
|
614
|
+
# rendered WITHOUT its severity on every review modal from
|
|
615
|
+
# §20 until batch 42 -- `[high]` parsed as an unknown
|
|
616
|
+
# style over a zero-width span. The brackets are wanted
|
|
617
|
+
# here; the parsing never was.
|
|
618
|
+
Label(Text(f"{kind} correction to {target} [{severity}]"),
|
|
619
|
+
id="review-title"),
|
|
620
|
+
ScrollBox(Static(Text(body), id="review-body"),
|
|
621
|
+
id="review-body-box"),
|
|
622
|
+
Input(placeholder="Note for the reviewer (used by Refine)",
|
|
623
|
+
id="review-note"),
|
|
624
|
+
# FOUR buttons in ONE row (batch 49). Stacked they cost 12 of
|
|
625
|
+
# the 18 rows a dialog has on an 80x24 terminal, so the body
|
|
626
|
+
# and the note pushed three of the four decisions off the
|
|
627
|
+
# bottom -- Refine, Reject and Reject the rest, which is to
|
|
628
|
+
# say every answer except Accept. Measured at 65 columns of
|
|
629
|
+
# buttons in 70, so they fit the floor as a row.
|
|
630
|
+
Horizontal(
|
|
631
|
+
Button("Accept", variant="success", id="review-accept"),
|
|
632
|
+
Button("Refine", variant="primary", id="review-refine"),
|
|
633
|
+
Button("Reject", variant="error", id="review-reject"),
|
|
634
|
+
Button("Reject the rest", variant="error",
|
|
635
|
+
id="review-reject-all"),
|
|
636
|
+
id="review-buttons"),
|
|
637
|
+
id="review-dialog",
|
|
638
|
+
)
|
|
639
|
+
|
|
640
|
+
def on_mount(self) -> None:
|
|
641
|
+
# The declining answer, like every other consent surface here --
|
|
642
|
+
# see PermissionScreen.on_mount. `reject` and not `reject_all`:
|
|
643
|
+
# both decline, and only one of them declines everything else too.
|
|
644
|
+
self.query_one("#review-reject", Button).focus()
|
|
645
|
+
|
|
646
|
+
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
647
|
+
decisions = {
|
|
648
|
+
"review-accept": "accept",
|
|
649
|
+
"review-refine": "refine",
|
|
650
|
+
"review-reject": "reject",
|
|
651
|
+
"review-reject-all": "reject_all",
|
|
652
|
+
}
|
|
653
|
+
note = self.query_one("#review-note", Input).value.strip()
|
|
654
|
+
self.dismiss((decisions[event.button.id], note))
|
|
655
|
+
|
|
656
|
+
def action_reject(self) -> None:
|
|
657
|
+
# Escape declines rather than dismissing with no value, for the
|
|
658
|
+
# same reason PermissionScreen's escape denies.
|
|
659
|
+
self.dismiss(("reject", ""))
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
class ClaimsScreen(ModalScreen[None]):
|
|
663
|
+
"""Every claim a research run produced, with the metadata that decided
|
|
664
|
+
its tier (ROADMAP_v2 §26).
|
|
665
|
+
|
|
666
|
+
The report a run ends with is a synthesis. What it was synthesised
|
|
667
|
+
FROM -- which assertions were extracted, which were grounded and by
|
|
668
|
+
how many sources, which carried unexamined assumptions, which were
|
|
669
|
+
revised and how often, and what arithmetic produced each tier -- all
|
|
670
|
+
exists on every Claim and reaches /output/<run_id>/, and none of it was
|
|
671
|
+
reachable from either shell. So a run could be read only as prose,
|
|
672
|
+
with the confidence machinery that is the point of the pipeline
|
|
673
|
+
visible nowhere.
|
|
674
|
+
|
|
675
|
+
A MODAL rather than transcript rows: a dozen claims at this detail is
|
|
676
|
+
longer than the report, and dumping it inline would push the answer
|
|
677
|
+
off screen at the moment it arrives. Scrollable, escape closes.
|
|
678
|
+
|
|
679
|
+
Takes plain DICTS, not Claim objects, and that is deliberate -- the
|
|
680
|
+
three sources are `vars(c)` for a finished in-session run,
|
|
681
|
+
pipeline_storage.load_pipeline_run() for an earlier one (which already
|
|
682
|
+
returns the dicts vars(c) wrote), and the partial picture assembled
|
|
683
|
+
from PipelineEvents while a run is still going. One shape here means
|
|
684
|
+
no branch inside the renderer, and it is the shape §5 already
|
|
685
|
+
persists.
|
|
686
|
+
"""
|
|
687
|
+
|
|
688
|
+
BINDINGS = [("escape", "close", "Close")]
|
|
689
|
+
|
|
690
|
+
def __init__(self, claims: list, title: str = "Claims",
|
|
691
|
+
partial: bool = False):
|
|
692
|
+
super().__init__()
|
|
693
|
+
self._claims = list(claims or [])
|
|
694
|
+
self._title = title
|
|
695
|
+
self._partial = partial
|
|
696
|
+
|
|
697
|
+
def compose(self) -> ComposeResult:
|
|
698
|
+
header = f"{self._title} ({len(self._claims)})"
|
|
699
|
+
if self._partial:
|
|
700
|
+
# Say so, rather than showing thin rows and letting the reader
|
|
701
|
+
# conclude the pipeline recorded nothing: mid-run, only id,
|
|
702
|
+
# text and tier have been broadcast as events.
|
|
703
|
+
header += " — run in progress, metadata incomplete"
|
|
704
|
+
yield Vertical(
|
|
705
|
+
Label(Text(header), id="claims-title"),
|
|
706
|
+
# A ScrollBox, not a `max-height` Static (batch 49). EP3's
|
|
707
|
+
# second rule was right about this one: a Static's
|
|
708
|
+
# virtual_size follows its clamped box, so a run with more
|
|
709
|
+
# claims than fit had the remainder GONE rather than below
|
|
710
|
+
# the fold, on the one screen whose entire purpose is showing
|
|
711
|
+
# all of them.
|
|
712
|
+
ScrollBox(Static(Text(_render_claims(self._claims)),
|
|
713
|
+
id="claims-body"),
|
|
714
|
+
id="claims-body-box"),
|
|
715
|
+
id="claims-dialog",
|
|
716
|
+
)
|
|
717
|
+
|
|
718
|
+
def action_close(self) -> None:
|
|
719
|
+
self.dismiss(None)
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
# Tier order for the claims view: worst first. A reader opening this is
|
|
723
|
+
# looking for what NOT to trust, and burying the unverified claims under
|
|
724
|
+
# the confident ones makes them the hardest thing to find.
|
|
725
|
+
_TIER_ORDER = ("UNVERIFIED", "UNVERIFIED_COVERAGE", "LOW", "MEDIUM", "HIGH")
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
def _render_claims(claims: list) -> str:
|
|
729
|
+
if not claims:
|
|
730
|
+
return "No claims recorded for this run."
|
|
731
|
+
|
|
732
|
+
def _rank(claim):
|
|
733
|
+
tier = claim.get("confidence_tier")
|
|
734
|
+
return _TIER_ORDER.index(tier) if tier in _TIER_ORDER else len(_TIER_ORDER)
|
|
735
|
+
|
|
736
|
+
out = []
|
|
737
|
+
for claim in sorted(claims, key=_rank):
|
|
738
|
+
tier = claim.get("confidence_tier") or "—"
|
|
739
|
+
head = f"{tier:<20} {claim.get('id', '?')} {claim.get('type') or ''}"
|
|
740
|
+
if claim.get("retry_count"):
|
|
741
|
+
head += f" revised x{claim['retry_count']}"
|
|
742
|
+
out.append(head.rstrip())
|
|
743
|
+
# final_text is what the claim carries into the report; text is
|
|
744
|
+
# what Pass 2 extracted. Showing final_text when they differ means
|
|
745
|
+
# the view matches the report rather than the draft behind it.
|
|
746
|
+
out.append(f" {claim.get('final_text') or claim.get('text') or ''}")
|
|
747
|
+
if claim.get("entities"):
|
|
748
|
+
out.append(f" entities: {', '.join(map(str, claim['entities']))}")
|
|
749
|
+
if claim.get("grounding_status") or claim.get("grounding_sources"):
|
|
750
|
+
sources = len(claim.get("grounding_sources") or ())
|
|
751
|
+
out.append(f" grounding: {claim.get('grounding_status') or 'none'}"
|
|
752
|
+
f" ({sources} source{'s' if sources != 1 else ''})")
|
|
753
|
+
for field, label in (("fallacies", "fallacies"),
|
|
754
|
+
("contradictions", "contradictions"),
|
|
755
|
+
("assumption_flags", "assumptions")):
|
|
756
|
+
if claim.get(field):
|
|
757
|
+
out.append(f" {label}: {'; '.join(map(str, claim[field]))}")
|
|
758
|
+
if claim.get("score_breakdown"):
|
|
759
|
+
out.append(" score: " + ", ".join(
|
|
760
|
+
f"{k}={v}" for k, v in claim["score_breakdown"].items()))
|
|
761
|
+
if claim.get("annotation"):
|
|
762
|
+
out.append(f" {claim['annotation']}")
|
|
763
|
+
out.append("")
|
|
764
|
+
return "\n".join(out).rstrip()
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
def _thread_row(thread: dict) -> str:
|
|
768
|
+
"""One picker row: timestamp, first message, id (§27).
|
|
769
|
+
|
|
770
|
+
`created_at` and `id` are INDEXED deliberately, not .get: a row
|
|
771
|
+
without either has nothing honest to render -- storage.list_threads()
|
|
772
|
+
always supplies both, and the id is the row's whole payload on
|
|
773
|
+
selection. Only `preview` is optional (.get): §27 added it, so
|
|
774
|
+
hand-built test rows predate it, and a missing preview degrades to an
|
|
775
|
+
id-only row rather than a KeyError in a test-only construction.
|
|
776
|
+
"""
|
|
777
|
+
created = thread["created_at"]
|
|
778
|
+
stamp = (f"{created:%Y-%m-%d %H:%M}"
|
|
779
|
+
if hasattr(created, "strftime") else str(created))
|
|
780
|
+
preview = (thread.get("preview") or "").strip()
|
|
781
|
+
return f"{stamp} {preview} ({thread['id']})" if preview \
|
|
782
|
+
else f"{stamp} {thread['id']}"
|
|
783
|
+
|
|
784
|
+
|
|
785
|
+
class ConfirmScreen(ModalScreen[bool]):
|
|
786
|
+
"""A titled yes/no over a block of text (ROADMAP_v2 §24).
|
|
787
|
+
|
|
788
|
+
PermissionScreen is the wrong shape here even though it also returns a
|
|
789
|
+
bool: it titles itself "Allow <tool>?" and renders params as JSON,
|
|
790
|
+
because it exists to gate ONE tool call. /init's question is about a
|
|
791
|
+
set of files, and the substance is the diff -- so the body is text the
|
|
792
|
+
caller composed and the title says what is being decided.
|
|
793
|
+
|
|
794
|
+
Escape declines rather than dismissing with no value. Fifth place that
|
|
795
|
+
invariant applies, and here the unsafe failure is a worker parked on a
|
|
796
|
+
queue nobody will answer.
|
|
797
|
+
"""
|
|
798
|
+
|
|
799
|
+
BINDINGS = [("escape", "decline", "No")]
|
|
800
|
+
|
|
801
|
+
def __init__(self, title: str, body: str, confirm_label: str = "Yes"):
|
|
802
|
+
super().__init__()
|
|
803
|
+
self._title = title
|
|
804
|
+
self._body = body
|
|
805
|
+
self._confirm_label = confirm_label
|
|
806
|
+
|
|
807
|
+
def compose(self) -> ComposeResult:
|
|
808
|
+
yield Vertical(
|
|
809
|
+
Label(Text(self._title), id="permission-title"),
|
|
810
|
+
# The body is a DIFF (/init's file list), so it is the one
|
|
811
|
+
# here most able to outgrow the dialog -- 30 files measured at
|
|
812
|
+
# 36 rows of content in a 16-row box, which took both buttons
|
|
813
|
+
# off the bottom with it. Bounded and scrollable like the
|
|
814
|
+
# payload block, for the same reason.
|
|
815
|
+
ScrollBox(Static(Text(self._body), id="permission-params"),
|
|
816
|
+
id="permission-params-box"),
|
|
817
|
+
Horizontal(
|
|
818
|
+
Button(self._confirm_label, variant="success", id="allow"),
|
|
819
|
+
Button("No", variant="error", id="deny"),
|
|
820
|
+
id="permission-buttons"),
|
|
821
|
+
id="permission-dialog",
|
|
822
|
+
)
|
|
823
|
+
|
|
824
|
+
def on_mount(self) -> None:
|
|
825
|
+
# See PermissionScreen.on_mount. This screen is where Enter
|
|
826
|
+
# actually said yes: its body was a plain Static, so the
|
|
827
|
+
# affirmative button was the first focusable widget on it.
|
|
828
|
+
self.query_one("#deny", Button).focus()
|
|
829
|
+
|
|
830
|
+
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
831
|
+
self.dismiss(event.button.id == "allow")
|
|
832
|
+
|
|
833
|
+
def action_decline(self) -> None:
|
|
834
|
+
self.dismiss(False)
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
class ProjectKindScreen(ModalScreen[object]):
|
|
838
|
+
"""Which document set /init scaffolds (§24, I13).
|
|
839
|
+
|
|
840
|
+
Dismisses with "software", "research", or None to cancel -- three
|
|
841
|
+
answers, not a bool, because cancelling is not the same as picking the
|
|
842
|
+
other one.
|
|
843
|
+
|
|
844
|
+
An established project arrives here with a PROPOSAL and the reason for
|
|
845
|
+
it, so the user is confirming a finding. A blank folder arrives with
|
|
846
|
+
neither: there is nothing to infer from, and a proposal would be a
|
|
847
|
+
guess wearing a finding's clothes.
|
|
848
|
+
"""
|
|
849
|
+
|
|
850
|
+
BINDINGS = [("escape", "cancel", "Cancel")]
|
|
851
|
+
|
|
852
|
+
def __init__(self, proposal=None, reason: str = "", blank: bool = False):
|
|
853
|
+
super().__init__()
|
|
854
|
+
self._proposal = proposal
|
|
855
|
+
self._reason = reason
|
|
856
|
+
self._blank = blank
|
|
857
|
+
|
|
858
|
+
def compose(self) -> ComposeResult:
|
|
859
|
+
if self._blank:
|
|
860
|
+
explanation = ("This folder is empty, so there is nothing to go "
|
|
861
|
+
"on. Which kind of project is this?")
|
|
862
|
+
elif self._proposal:
|
|
863
|
+
explanation = (f"This looks like a {self._proposal} project — "
|
|
864
|
+
f"{self._reason}. Change it if that is wrong.")
|
|
865
|
+
else:
|
|
866
|
+
explanation = "Which kind of project is this?"
|
|
867
|
+
yield Vertical(
|
|
868
|
+
Label("Set up documentation for which kind of project?",
|
|
869
|
+
id="permission-title"),
|
|
870
|
+
ScrollBox(Static(
|
|
871
|
+
Text(
|
|
872
|
+
f"{explanation}\n\n"
|
|
873
|
+
"software — ARCHITECTURE, ROADMAP, DEVLOG, "
|
|
874
|
+
"TECHNICAL_DEBT, DOCUMENTATION_STANDARDS, "
|
|
875
|
+
"TEST_WRITING, BREAKING_CHANGES\n"
|
|
876
|
+
"research — RESEARCH_QUESTIONS, METHODOLOGY, "
|
|
877
|
+
"SOURCES, FINDINGS, LIMITATIONS, EXPERIMENT_LOG, "
|
|
878
|
+
"OPEN_QUESTIONS, DOCUMENTATION_STANDARDS"),
|
|
879
|
+
id="permission-params"),
|
|
880
|
+
id="permission-params-box"),
|
|
881
|
+
Horizontal(
|
|
882
|
+
Button("Software", variant="success", id="kind-software"),
|
|
883
|
+
Button("Research", variant="primary", id="kind-research"),
|
|
884
|
+
id="permission-buttons"),
|
|
885
|
+
id="permission-dialog",
|
|
886
|
+
)
|
|
887
|
+
|
|
888
|
+
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
889
|
+
self.dismiss("research" if event.button.id == "kind-research"
|
|
890
|
+
else "software")
|
|
891
|
+
|
|
892
|
+
def action_cancel(self) -> None:
|
|
893
|
+
self.dismiss(None)
|
|
894
|
+
|
|
895
|
+
|
|
896
|
+
class ThreadPickerScreen(ModalScreen[object]):
|
|
897
|
+
"""Pick a thread to resume. Dismisses with a UUID, or None to cancel.
|
|
898
|
+
|
|
899
|
+
Reads storage.list_threads(), which since §27 returns CONVERSATIONS only
|
|
900
|
+
-- a research run creates ~15 threads of machinery and every automatic
|
|
901
|
+
compaction one more, and all of them used to be offered here as things
|
|
902
|
+
to resume.
|
|
903
|
+
|
|
904
|
+
A row leads with the thread's first user message (§27), because a list
|
|
905
|
+
of uuids and timestamps was still unusable once it was short: filtering
|
|
906
|
+
made the picker correct, and the preview is what makes it answerable.
|
|
907
|
+
The id stays, since it is what --thread and /resume take.
|
|
908
|
+
|
|
909
|
+
`note` carries one line shown under the title when the list is not the
|
|
910
|
+
whole story (#30/#32): the picker caps at PICKER_LIMIT rows, and a cap
|
|
911
|
+
that does not say so reads as "this is everything" (M14's rule). Older
|
|
912
|
+
conversations remain reachable by id via /resume.
|
|
913
|
+
"""
|
|
914
|
+
|
|
915
|
+
BINDINGS = [("escape", "cancel", "Cancel")]
|
|
916
|
+
|
|
917
|
+
def __init__(self, threads: list[dict], note: str = ""):
|
|
918
|
+
super().__init__()
|
|
919
|
+
self._threads = threads
|
|
920
|
+
self._note = note
|
|
921
|
+
|
|
922
|
+
def compose(self) -> ComposeResult:
|
|
923
|
+
items = [ListItem(Label(Text(_thread_row(t))))
|
|
924
|
+
for t in self._threads]
|
|
925
|
+
children = [Label("Resume which thread?", id="thread-title")]
|
|
926
|
+
if self._note:
|
|
927
|
+
children.append(Static(Text(self._note),
|
|
928
|
+
id="thread-note"))
|
|
929
|
+
if items:
|
|
930
|
+
children.append(ListView(*items, id="thread-list"))
|
|
931
|
+
else:
|
|
932
|
+
children.append(Static("No saved threads yet.", id="thread-empty"))
|
|
933
|
+
yield Vertical(*children, id="thread-dialog")
|
|
934
|
+
|
|
935
|
+
def on_list_view_selected(self, event: ListView.Selected) -> None:
|
|
936
|
+
index = event.list_view.index
|
|
937
|
+
if index is not None and 0 <= index < len(self._threads):
|
|
938
|
+
self.dismiss(self._threads[index]["id"])
|
|
939
|
+
else:
|
|
940
|
+
self.dismiss(None)
|
|
941
|
+
|
|
942
|
+
def action_cancel(self) -> None:
|
|
943
|
+
self.dismiss(None)
|