@yahyahammad/venastine 0.3.16 → 0.3.18
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/CONFIG_ARCHITECTURE.md +14 -8
- package/README.md +5 -5
- package/cli_commands.py +82 -1
- package/core/client.py +130 -11
- package/core/commands.py +7 -3
- package/core/loop.py +21 -1
- package/core/memory.py +13 -0
- package/core/reasoning/json_retry.py +148 -31
- package/core/reasoning/orchestrator.py +49 -3
- package/core/shell_sessions.py +67 -6
- package/core/usage_view.py +119 -0
- package/docs/THIRD_PARTY_NOTICES.md +1 -1
- package/logging_setup.py +35 -2
- package/main.py +184 -21
- package/package.json +1 -1
- package/pyproject.toml +1 -1
- package/safety/policy_enforcement.py +79 -9
- package/security/sandbox.py +11 -2
- package/tools/builtin/arxiv.py +8 -2
- package/tools/builtin/fetch_url.py +8 -1
- package/tools/builtin/file_ops.py +74 -8
- package/tools/builtin/project_docs.py +10 -4
- package/tools/builtin/shell.py +2 -1
- package/tools/builtin/shell_sessions.py +6 -3
- package/tools/builtin/web_search.py +5 -1
- package/tools/isolation.py +9 -6
- package/tui/app.py +240 -12
- package/tui/meters.py +124 -40
- package/tui/widgets.py +8 -7
package/tui/app.py
CHANGED
|
@@ -187,6 +187,14 @@ DIFF_SNAPSHOT_MAX_BYTES = 512_000
|
|
|
187
187
|
#: to guess at.
|
|
188
188
|
QUIT_CONFIRM_S = 2.0
|
|
189
189
|
|
|
190
|
+
#: Where the turn worker's post-turn session wait is (ROADMAP_v3 §49, SS2
|
|
191
|
+
#: as amended in batch 265): between replies, where a message the user
|
|
192
|
+
#: sends is taken and gets a turn of its own, or inside a wake turn, where
|
|
193
|
+
#: it is refused as it is during any turn. None (`_wait_phase`'s default)
|
|
194
|
+
#: means the worker is not waiting at all.
|
|
195
|
+
_WAIT_IDLE = "idle"
|
|
196
|
+
_WAIT_WAKE = "wake"
|
|
197
|
+
|
|
190
198
|
|
|
191
199
|
class LoopEventMessage(Message):
|
|
192
200
|
"""One LoopEvent, forwarded from the worker thread to the UI thread.
|
|
@@ -346,6 +354,22 @@ class SessionNote(Message):
|
|
|
346
354
|
super().__init__()
|
|
347
355
|
|
|
348
356
|
|
|
357
|
+
class SessionWait(Message):
|
|
358
|
+
"""The turn worker began (or stopped) waiting on its background
|
|
359
|
+
sessions (ROADMAP_v3 §97, UF1).
|
|
360
|
+
|
|
361
|
+
Posted by `_wait_for_sessions` for the meter, which runs on the UI
|
|
362
|
+
thread: the seconds between wake turns are the shell waiting, not the
|
|
363
|
+
model writing, so the completion line's rate leaves them out. FIFO from
|
|
364
|
+
the one worker, like SessionNote, so a wake turn's events always land
|
|
365
|
+
after the `False` that resumes the clock for them.
|
|
366
|
+
"""
|
|
367
|
+
|
|
368
|
+
def __init__(self, waiting: bool) -> None:
|
|
369
|
+
self.waiting = waiting
|
|
370
|
+
super().__init__()
|
|
371
|
+
|
|
372
|
+
|
|
349
373
|
class ConnectCodeReady(Message):
|
|
350
374
|
"""`/connect huggingface` has a device code to show (ROADMAP_v3 §79, HD5).
|
|
351
375
|
|
|
@@ -869,6 +893,20 @@ class VenastineApp(App):
|
|
|
869
893
|
# setter runs on bare-built apps across the suite.
|
|
870
894
|
_pending_restart = None
|
|
871
895
|
|
|
896
|
+
# Batch 265 (SS2 as amended). The post-turn session wait's phase
|
|
897
|
+
# (`_WAIT_IDLE`, `_WAIT_WAKE`, or None when the worker is not waiting)
|
|
898
|
+
# and the message the user sent while it was idle, which the wait hands
|
|
899
|
+
# to a turn of its own once the worker is free. Both change under
|
|
900
|
+
# `_wait_lock`, because the UI thread takes a message on the strength
|
|
901
|
+
# of the phase and the worker starts a wake on the strength of the
|
|
902
|
+
# message, and those two decisions must not cross. CLASS attributes for
|
|
903
|
+
# `_shutting_down`'s reason -- bare-built apps run the wait loop and the
|
|
904
|
+
# submit handler across the suite -- with a class-wide lock that
|
|
905
|
+
# __init__ replaces with the instance's own.
|
|
906
|
+
_wait_phase = None
|
|
907
|
+
_handed_message = None
|
|
908
|
+
_wait_lock = threading.Lock()
|
|
909
|
+
|
|
872
910
|
# §79 (HD5). The stop signal of the one sign-in that may be waiting for
|
|
873
911
|
# approval, or None. A CLASS attribute for `_shutting_down`'s reason:
|
|
874
912
|
# `on_unmount` and `exit()` stop it, and both run on bare-built apps
|
|
@@ -887,6 +925,7 @@ class VenastineApp(App):
|
|
|
887
925
|
_meter_timer = None
|
|
888
926
|
_meter_last = None
|
|
889
927
|
_last_turn_elapsed = None
|
|
928
|
+
_last_turn_generating = None
|
|
890
929
|
_turn_output_tokens = None
|
|
891
930
|
_history = None
|
|
892
931
|
# ROADMAP_v3 §61 (CN9). The live turn's CancelToken, or None between
|
|
@@ -1104,6 +1143,9 @@ class VenastineApp(App):
|
|
|
1104
1143
|
# Per-thread state: `reset()`'s list, beside `_spawn_threads`.
|
|
1105
1144
|
self._session_calls: dict = {}
|
|
1106
1145
|
self._permission_channel: queue.Queue | None = None
|
|
1146
|
+
# Batch 265: this app's own, rather than the class-wide default
|
|
1147
|
+
# bare-built apps share.
|
|
1148
|
+
self._wait_lock = threading.Lock()
|
|
1107
1149
|
# Batch 61. BEFORE the `_busy` assignment below, which is a
|
|
1108
1150
|
# property setter now and drives this object.
|
|
1109
1151
|
self._meter = meters.TurnMeter()
|
|
@@ -1115,6 +1157,10 @@ class VenastineApp(App):
|
|
|
1115
1157
|
#: at the exits, because `_busy` is also cleared on paths
|
|
1116
1158
|
#: where no turn ever ran.
|
|
1117
1159
|
self._last_turn_elapsed = None
|
|
1160
|
+
#: The same turn's seconds with no tool running and no session
|
|
1161
|
+
#: wait: the completion line's rate divides by this, `took` by
|
|
1162
|
+
#: the one above (ROADMAP_v3 §97, UF1).
|
|
1163
|
+
self._last_turn_generating = None
|
|
1118
1164
|
#: The finished turn's OUTPUT tokens, off the terminal
|
|
1119
1165
|
#: response. None where the provider reports no usage, which
|
|
1120
1166
|
#: is twelve of the fifteen configured ones -- and None is
|
|
@@ -1645,7 +1691,13 @@ class VenastineApp(App):
|
|
|
1645
1691
|
now = monotonic()
|
|
1646
1692
|
if value:
|
|
1647
1693
|
self._meter.start(now)
|
|
1694
|
+
# §97 (UF1). Summed per terminal response since this batch, so
|
|
1695
|
+
# it starts at the turn: a count left by a turn whose line was
|
|
1696
|
+
# never written must not join the next one's.
|
|
1697
|
+
self._turn_output_tokens = None
|
|
1648
1698
|
else:
|
|
1699
|
+
# Read BEFORE stop, which closes the turn and zeroes it.
|
|
1700
|
+
self._last_turn_generating = self._meter.generating(now)
|
|
1649
1701
|
self._last_turn_elapsed = self._meter.stop(now)
|
|
1650
1702
|
self._sync_meter_timer()
|
|
1651
1703
|
self._refresh_meter()
|
|
@@ -1664,9 +1716,18 @@ class VenastineApp(App):
|
|
|
1664
1716
|
"""
|
|
1665
1717
|
return getattr(self._memory, "thread_id", None)
|
|
1666
1718
|
|
|
1667
|
-
def refuse_if_occupied(self, action: str
|
|
1719
|
+
def refuse_if_occupied(self, action: str, *, by_sessions: bool = True
|
|
1720
|
+
) -> bool:
|
|
1668
1721
|
"""Whether `action` must be refused right now, saying why.
|
|
1669
1722
|
|
|
1723
|
+
`by_sessions=False` is a plain MESSAGE's question since batch 265
|
|
1724
|
+
(SS2 as amended, the owner's choice): live sessions do not hold a
|
|
1725
|
+
message back, only a running turn does. A message sent while the
|
|
1726
|
+
wait is between replies never reaches this -- `_hand_to_wait`
|
|
1727
|
+
takes it first -- so what this still refuses for one is a turn
|
|
1728
|
+
actually running, a wake turn included, with the words any turn
|
|
1729
|
+
gets.
|
|
1730
|
+
|
|
1670
1731
|
SS2 gives the shell a SECOND way to be occupied. Before this, one
|
|
1671
1732
|
condition (`_busy`) was checked at eight sites with the same three
|
|
1672
1733
|
lines copied between them; live background sessions add a
|
|
@@ -1688,8 +1749,12 @@ class VenastineApp(App):
|
|
|
1688
1749
|
are typed into it.
|
|
1689
1750
|
"""
|
|
1690
1751
|
thread_id = self._session_thread
|
|
1691
|
-
if thread_id is not None
|
|
1692
|
-
|
|
1752
|
+
if by_sessions and thread_id is not None \
|
|
1753
|
+
and shell_sessions.sessions.blocks(thread_id):
|
|
1754
|
+
# `waited_on`, not `live_for` (batch 265): an interactive
|
|
1755
|
+
# shell does not hold the shell (SS25), so it is not one of
|
|
1756
|
+
# the sessions this sentence asks the user to wait for.
|
|
1757
|
+
live = shell_sessions.sessions.waited_on(thread_id)
|
|
1693
1758
|
plural = "" if live == 1 else "s"
|
|
1694
1759
|
self._transcript.write_error(
|
|
1695
1760
|
f"{live} background session{plural} still running — "
|
|
@@ -1701,6 +1766,46 @@ class VenastineApp(App):
|
|
|
1701
1766
|
return True
|
|
1702
1767
|
return False
|
|
1703
1768
|
|
|
1769
|
+
def _hand_to_wait(self, text: str) -> bool:
|
|
1770
|
+
"""Take a message sent while the session wait is between replies
|
|
1771
|
+
(ROADMAP_v3 §49, SS2 as amended in batch 265). Whether it was taken.
|
|
1772
|
+
|
|
1773
|
+
TAKEN means it will run: the worker sees it, leaves the wait with
|
|
1774
|
+
the sessions still running, and `on_turn_finished` starts its turn
|
|
1775
|
+
-- a turn of its own, with its own clock, escape and held results,
|
|
1776
|
+
because that is what the owner asked for and because it IS a user
|
|
1777
|
+
turn. The results that land meanwhile wake after it (`put_back`,
|
|
1778
|
+
and the wait its own turn ends in).
|
|
1779
|
+
|
|
1780
|
+
NOT taken while a wake turn runs, or once one message is already
|
|
1781
|
+
waiting: the owner's choice is that a send then is refused as it
|
|
1782
|
+
is during any turn, and the caller asks the funnel for the words.
|
|
1783
|
+
|
|
1784
|
+
UNDER `_wait_lock`, beside the worker's own read of it: the phase
|
|
1785
|
+
is what this decides on, and the worker decides to start a wake on
|
|
1786
|
+
the strength of what this writes. The nudge is outside the lock.
|
|
1787
|
+
The order, wherever both are held, is `_wait_lock` and then the
|
|
1788
|
+
manager's (the worker's `put_back`); `wait_for_wake` reads
|
|
1789
|
+
`_handed_message` under the manager's alone, with no lock of ours.
|
|
1790
|
+
"""
|
|
1791
|
+
with self._wait_lock:
|
|
1792
|
+
if self._wait_phase != _WAIT_IDLE or \
|
|
1793
|
+
self._handed_message is not None:
|
|
1794
|
+
return False
|
|
1795
|
+
self._handed_message = text
|
|
1796
|
+
shell_sessions.sessions.nudge()
|
|
1797
|
+
return True
|
|
1798
|
+
|
|
1799
|
+
def _message_is_waiting(self) -> bool:
|
|
1800
|
+
"""`wait_for_wake`'s stop: a plain attribute read, because it is
|
|
1801
|
+
called under the manager's lock."""
|
|
1802
|
+
return self._handed_message is not None
|
|
1803
|
+
|
|
1804
|
+
def _take_handed_message(self):
|
|
1805
|
+
with self._wait_lock:
|
|
1806
|
+
text, self._handed_message = self._handed_message, None
|
|
1807
|
+
return text
|
|
1808
|
+
|
|
1704
1809
|
def _sync_meter_timer(self) -> None:
|
|
1705
1810
|
"""Tick only while a turn is running (ThinkingIndicator's rule).
|
|
1706
1811
|
|
|
@@ -1781,9 +1886,12 @@ class VenastineApp(App):
|
|
|
1781
1886
|
if elapsed is None:
|
|
1782
1887
|
# `_busy` was cleared without a turn having run.
|
|
1783
1888
|
return
|
|
1889
|
+
generating = self._last_turn_generating
|
|
1890
|
+
self._last_turn_generating = None
|
|
1784
1891
|
self._transcript.write_role(
|
|
1785
1892
|
'system',
|
|
1786
|
-
self._meter.completion(elapsed, self._turn_output_tokens
|
|
1893
|
+
self._meter.completion(elapsed, self._turn_output_tokens,
|
|
1894
|
+
generating))
|
|
1787
1895
|
self._turn_output_tokens = None
|
|
1788
1896
|
|
|
1789
1897
|
def refresh_status(self) -> None:
|
|
@@ -3082,8 +3190,17 @@ class VenastineApp(App):
|
|
|
3082
3190
|
# Clear AFTER the busy check, not before. /research holds _busy
|
|
3083
3191
|
# for a whole ten-pass pipeline, so a follow-up typed during one
|
|
3084
3192
|
# was wiped and had to be retyped from memory.
|
|
3085
|
-
|
|
3086
|
-
|
|
3193
|
+
#
|
|
3194
|
+
# BATCH 265 (SS2 as amended, the owner's choice). A message sent
|
|
3195
|
+
# while the turn's background sessions run is no longer held back
|
|
3196
|
+
# by them: between replies the wait takes it and it gets a turn of
|
|
3197
|
+
# its own, and during a reply it is refused as during any turn.
|
|
3198
|
+
# Taken FIRST, because `_busy` is true through the whole wait and
|
|
3199
|
+
# the funnel would otherwise refuse it for that.
|
|
3200
|
+
handed = (not text.startswith("/")
|
|
3201
|
+
and self._hand_to_wait(text))
|
|
3202
|
+
if not text.startswith("/") and not handed and \
|
|
3203
|
+
self.refuse_if_occupied("send a message", by_sessions=False):
|
|
3087
3204
|
return
|
|
3088
3205
|
event.prompt.value = ""
|
|
3089
3206
|
# Batch 63. AFTER the busy refusal above, which returns without
|
|
@@ -3100,6 +3217,11 @@ class VenastineApp(App):
|
|
|
3100
3217
|
# reason. Guarded on the transition because that is the only
|
|
3101
3218
|
# time the answer changes: a history never empties.
|
|
3102
3219
|
self.refresh_bindings()
|
|
3220
|
+
if handed:
|
|
3221
|
+
# The worker leaves the wait and `on_turn_finished` runs it,
|
|
3222
|
+
# so nothing is drawn here: its `you ›` line is the turn's
|
|
3223
|
+
# own, written when the turn starts and not before.
|
|
3224
|
+
return
|
|
3103
3225
|
if text.startswith("/"):
|
|
3104
3226
|
name = text[1:].split(" ")[0]
|
|
3105
3227
|
# CONTAINED HERE, not inside CommandRegistry.dispatch, and the
|
|
@@ -3315,8 +3437,11 @@ class VenastineApp(App):
|
|
|
3315
3437
|
|
|
3316
3438
|
The wait is INSIDE the worker and before `TurnFinished`, which is
|
|
3317
3439
|
what keeps `_busy` true across it. That is not a side effect but
|
|
3318
|
-
the mechanism: SS2
|
|
3319
|
-
`_busy` already
|
|
3440
|
+
the mechanism: SS2 holds the commands that would change what the
|
|
3441
|
+
wait is waiting for, and `_busy` already refuses them everywhere
|
|
3442
|
+
`refuse_if_occupied` asks. A plain message is the exception since
|
|
3443
|
+
batch 265 (SS2 as amended): `_hand_to_wait` takes it between
|
|
3444
|
+
replies, and it gets a turn of its own once this frame returns.
|
|
3320
3445
|
"""
|
|
3321
3446
|
error = None
|
|
3322
3447
|
try:
|
|
@@ -3347,12 +3472,38 @@ class VenastineApp(App):
|
|
|
3347
3472
|
event like any other, and the loop keeps going until nothing is
|
|
3348
3473
|
live and nothing is pending, so the results of what the user
|
|
3349
3474
|
stopped are still delivered rather than dropped on the floor.
|
|
3475
|
+
|
|
3476
|
+
A MESSAGE DOES (batch 265, SS2 as amended). One sent between replies
|
|
3477
|
+
is taken by `_hand_to_wait`, and the loop leaves with the sessions
|
|
3478
|
+
still running so `on_turn_finished` can give it a turn of its own;
|
|
3479
|
+
that turn ends in this loop again, which is where what landed in
|
|
3480
|
+
the meantime wakes. The phase says which side of a reply the loop
|
|
3481
|
+
is on, and it is set under `_wait_lock` because the UI thread takes
|
|
3482
|
+
a message on the strength of it.
|
|
3350
3483
|
"""
|
|
3484
|
+
with self._wait_lock:
|
|
3485
|
+
self._wait_phase = _WAIT_IDLE
|
|
3486
|
+
try:
|
|
3487
|
+
self._wait_until_done(thread_id, wake)
|
|
3488
|
+
finally:
|
|
3489
|
+
with self._wait_lock:
|
|
3490
|
+
self._wait_phase = None
|
|
3491
|
+
|
|
3492
|
+
def _wait_until_done(self, thread_id, wake) -> None:
|
|
3493
|
+
"""`_wait_for_sessions`'s loop, with its phase already set."""
|
|
3351
3494
|
from core.session_wake import build_wake
|
|
3352
3495
|
|
|
3353
3496
|
sessions = shell_sessions.sessions
|
|
3497
|
+
# ROADMAP_v3 §97 (UF1). Whether the meter has been told this stretch
|
|
3498
|
+
# is a wait, so it is told once per stretch rather than per second.
|
|
3499
|
+
waiting = False
|
|
3354
3500
|
while True:
|
|
3355
|
-
|
|
3501
|
+
# `waited_on`, not `live_for` (batch 265): an interactive shell
|
|
3502
|
+
# is not waited on (SS25), and `wait_for_wake` already answers
|
|
3503
|
+
# None at once for one -- so counting it here spun this loop
|
|
3504
|
+
# for as long as the shell stayed open.
|
|
3505
|
+
if not sessions.waited_on(thread_id) and \
|
|
3506
|
+
not sessions.pending(thread_id):
|
|
3356
3507
|
return
|
|
3357
3508
|
# BATCH 145. The SAME rule as `sessions.closing`
|
|
3358
3509
|
# below, one step earlier in the same teardown: the flag means
|
|
@@ -3409,7 +3560,18 @@ class VenastineApp(App):
|
|
|
3409
3560
|
"and their results will arrive with your next "
|
|
3410
3561
|
"message —"))
|
|
3411
3562
|
return
|
|
3412
|
-
|
|
3563
|
+
if self._message_is_waiting():
|
|
3564
|
+
# Batch 265. The user's message is next, and this loop is
|
|
3565
|
+
# not where it runs: `on_turn_finished` gives it a turn.
|
|
3566
|
+
# The meter may be left paused (§97 UF1), as on every
|
|
3567
|
+
# return below: TurnFinished stops it, and the message's
|
|
3568
|
+
# turn starts a fresh one.
|
|
3569
|
+
return
|
|
3570
|
+
if not waiting:
|
|
3571
|
+
self.post_message(SessionWait(True))
|
|
3572
|
+
waiting = True
|
|
3573
|
+
batch = sessions.wait_for_wake(
|
|
3574
|
+
thread_id, timeout=1.0, stop=self._message_is_waiting)
|
|
3413
3575
|
if batch is None:
|
|
3414
3576
|
if sessions.suspended(thread_id):
|
|
3415
3577
|
# SS2's consecutive-wake limit. The block lifts here,
|
|
@@ -3423,7 +3585,19 @@ class VenastineApp(App):
|
|
|
3423
3585
|
"message —"))
|
|
3424
3586
|
return
|
|
3425
3587
|
continue
|
|
3588
|
+
with self._wait_lock:
|
|
3589
|
+
if self._handed_message is not None:
|
|
3590
|
+
# Batch 265. The message and this batch reached the
|
|
3591
|
+
# shell together, and the owner's rule is that the
|
|
3592
|
+
# message goes first: the batch goes back, and wakes
|
|
3593
|
+
# after the turn the message gets.
|
|
3594
|
+
sessions.put_back(thread_id, batch)
|
|
3595
|
+
return
|
|
3596
|
+
self._wait_phase = _WAIT_WAKE
|
|
3426
3597
|
text, record = build_wake(batch)
|
|
3598
|
+
# §97 (UF1). The wake turn is the model writing again.
|
|
3599
|
+
self.post_message(SessionWait(False))
|
|
3600
|
+
waiting = False
|
|
3427
3601
|
# ITS FIRST LINE, matching core/replay.py's rule for the same
|
|
3428
3602
|
# row: the rest is program output the model was given, which
|
|
3429
3603
|
# can run to thousands of lines and would bury the
|
|
@@ -3434,10 +3608,19 @@ class VenastineApp(App):
|
|
|
3434
3608
|
"wake", text.split("\n", 1)[0].strip()))
|
|
3435
3609
|
for event in wake(text, record):
|
|
3436
3610
|
self.post_message(LoopEventMessage(event))
|
|
3611
|
+
with self._wait_lock:
|
|
3612
|
+
self._wait_phase = _WAIT_IDLE
|
|
3437
3613
|
|
|
3438
3614
|
def on_session_note(self, message: SessionNote) -> None:
|
|
3439
3615
|
self._transcript.write_role(message.role, message.text)
|
|
3440
3616
|
|
|
3617
|
+
def on_session_wait(self, message: SessionWait) -> None:
|
|
3618
|
+
"""ROADMAP_v3 §97 (UF1): pause or resume the rate's clock."""
|
|
3619
|
+
if self._meter is None:
|
|
3620
|
+
return
|
|
3621
|
+
self._meter.set_waiting(message.waiting, monotonic())
|
|
3622
|
+
self._refresh_meter()
|
|
3623
|
+
|
|
3441
3624
|
def _deliver_held(self, thread_id) -> None:
|
|
3442
3625
|
"""Results held for the user's next message (§49, SS2/SS19): past
|
|
3443
3626
|
the consecutive-wake limit, or from a kill the user made between
|
|
@@ -4056,8 +4239,17 @@ class VenastineApp(App):
|
|
|
4056
4239
|
# input deltas a tool-using turn brings in). Dividing
|
|
4057
4240
|
# either by a duration yields a number that looks like
|
|
4058
4241
|
# tok/s and is not.
|
|
4059
|
-
|
|
4242
|
+
#
|
|
4243
|
+
# SUMMED, since ROADMAP_v3 §97 (UF1): a turn held open for its
|
|
4244
|
+
# background sessions ends with one line, after every wake
|
|
4245
|
+
# turn, and each wake turn is a run of its own with its own
|
|
4246
|
+
# terminal response. Assigning kept only the LAST wake turn's
|
|
4247
|
+
# count, divided by a time that covered them all.
|
|
4248
|
+
reported = getattr(
|
|
4060
4249
|
event.final_response, 'turn_output_tokens', None)
|
|
4250
|
+
if reported is not None:
|
|
4251
|
+
self._turn_output_tokens = (
|
|
4252
|
+
(self._turn_output_tokens or 0) + reported)
|
|
4061
4253
|
transcript.flush_stream()
|
|
4062
4254
|
if event.stop_reason and event.stop_reason != "complete":
|
|
4063
4255
|
transcript.write_system(f"[stopped early: {event.stop_reason}]")
|
|
@@ -4411,7 +4603,16 @@ class VenastineApp(App):
|
|
|
4411
4603
|
for worker in self.workers)
|
|
4412
4604
|
|
|
4413
4605
|
def _fire_pending_restart(self) -> None:
|
|
4414
|
-
"""The queued restart, once the turn that blocked it has ended.
|
|
4606
|
+
"""The queued restart, once the turn that blocked it has ended.
|
|
4607
|
+
|
|
4608
|
+
BATCH 265. Not while a turn runs: a message sent during the session
|
|
4609
|
+
wait starts its turn in `on_turn_finished`, the same pass that
|
|
4610
|
+
scheduled this, so by the time it fires another turn may already
|
|
4611
|
+
be running. Left queued, it fires when that turn ends -- the
|
|
4612
|
+
`_busy` setter schedules it again.
|
|
4613
|
+
"""
|
|
4614
|
+
if self._busy_state:
|
|
4615
|
+
return
|
|
4415
4616
|
key, self._pending_restart = self._pending_restart, None
|
|
4416
4617
|
if key is None or self._shutting_down:
|
|
4417
4618
|
return
|
|
@@ -5083,6 +5284,16 @@ class VenastineApp(App):
|
|
|
5083
5284
|
self._raven.state = ravens.IDLE
|
|
5084
5285
|
if message.error is not None:
|
|
5085
5286
|
self._write_failure(message.error)
|
|
5287
|
+
# Batch 265 (SS2 as amended). A message the user sent while this
|
|
5288
|
+
# turn waited on its sessions gets its turn NOW, as the last thing
|
|
5289
|
+
# here: the line under the answer above is the finished turn's, and
|
|
5290
|
+
# on the UI thread nothing else can run between this and the turn
|
|
5291
|
+
# starting. After a failure too -- the box was cleared when it was
|
|
5292
|
+
# taken, so dropping it here would lose what the user wrote. Not on
|
|
5293
|
+
# the way out, where nothing will answer it.
|
|
5294
|
+
handed = self._take_handed_message()
|
|
5295
|
+
if handed is not None and not self._shutting_down:
|
|
5296
|
+
self.run_agent_turn(handed)
|
|
5086
5297
|
|
|
5087
5298
|
def _write_failure(self, error, label: str = "error") -> None:
|
|
5088
5299
|
"""A turn, a one-shot or a research run that failed, on one line.
|
|
@@ -6240,6 +6451,22 @@ def _cmd_network(app: VenastineApp, args: str) -> None:
|
|
|
6240
6451
|
app.refresh_network_line(force=True)
|
|
6241
6452
|
|
|
6242
6453
|
|
|
6454
|
+
def _cmd_usage(app: VenastineApp, args: str) -> None:
|
|
6455
|
+
"""ROADMAP_v3 §97 (UF4): this thread's provider-reported counts.
|
|
6456
|
+
|
|
6457
|
+
The lines are `core.usage_view.report_lines`'s, which the CLI prints
|
|
6458
|
+
too, over the tally `ConversationMemory.record_usage` keeps beside
|
|
6459
|
+
`billed` -- so this and the usage line cover one span. `_memory`, not
|
|
6460
|
+
`memory`: a thread with no turn yet has nothing to count, and the
|
|
6461
|
+
public property would write a thread row to say so.
|
|
6462
|
+
"""
|
|
6463
|
+
from core.usage_view import report_lines
|
|
6464
|
+
|
|
6465
|
+
memory = app._memory
|
|
6466
|
+
for line in report_lines(getattr(memory, "usage", None)):
|
|
6467
|
+
app._transcript.write_system(line)
|
|
6468
|
+
|
|
6469
|
+
|
|
6243
6470
|
def _cmd_trigger(app: VenastineApp, args: str) -> None:
|
|
6244
6471
|
"""Override the working-set compaction ceiling for this session.
|
|
6245
6472
|
|
|
@@ -8415,6 +8642,7 @@ def register_builtin_commands() -> None:
|
|
|
8415
8642
|
bind("window", _cmd_window),
|
|
8416
8643
|
bind("trigger", _cmd_trigger),
|
|
8417
8644
|
bind("network", _cmd_network),
|
|
8645
|
+
bind("usage", _cmd_usage),
|
|
8418
8646
|
bind("classifier", _cmd_classifier),
|
|
8419
8647
|
bind("config", _cmd_config, complete=_config_rows),
|
|
8420
8648
|
bind("secrets", _cmd_secrets),
|