@vibelord/lanes 1.6.1 → 1.7.1

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.
@@ -8,6 +8,8 @@ Fully usable from the keyboard (touch/mouse is a bonus):
8
8
  2 / 3 open the lane under the cursor in the 2nd / 3rd viewport (wide view sessions) · x / × close (y, then Enter)
9
9
  u unregister a session added with a (z within 10 s undoes it; a declared lane says which file to edit)
10
10
  d shows the cursor lane's docs link in the footer (plan W10 W7) · i folds / unfolds the fleet block (W11)
11
+ @ shows the cursor lane's handle in the footer and every address in the body until the next key (W15 L2)
12
+ m asks for one line in the footer and sends it to the cursor lane as a message (`lanes message`, W15 L4, BEY-6842)
11
13
  ? shows every key in the body until the next key · Tab / Shift-Tab open the next / previous lane that needs you
12
14
  The keyboard goes back to the lane after every action (cockpit v3 S3): the sidebar and the lane share one keyboard, so
13
15
  an action that ends — a close, a rename, a register, a cancel, Esc, r, closing the key sheet, a click that opened
@@ -63,8 +65,13 @@ Truthful under load: a lane statusd could not observe keeps its last glyph, dimm
63
65
  when the host is under pressure or statusd has fallen behind (age of $STATE/health, measured with our own clock).
64
66
  Never frozen by an action (cockpit v3 S9): a close, `P`'s write and a new shell run on one worker thread (Worker); the
65
67
  row they act on carries the dim `pending` mark and takes no key until run()'s tick takes the answer (finish_actions).
68
+ Addresses (W15 L2/L2b/L2c): status.json's `address`, `role` and `agent.name_match` give the cursor row's handle
69
+ `@<address>` after the name (`look.handles`: cursor · all · off), the leader glyph ★ of the workspace's coordinator and
70
+ of the fleet admin and the ≠ of an agent whose messaging name is not its address in column 3, and `@`'s footer and
71
+ sheet; a row without those keys is today's row, byte for byte.
66
72
  Run via libexec/sidebar (a loop), so it never leaves its pane empty.
67
73
  """
74
+ import codecs
68
75
  import json
69
76
  import os
70
77
  import queue
@@ -183,7 +190,7 @@ STATE_FRESH_S = 60.0 # a .sidebar.state older than this (by its own `
183
190
  # The one prompt (cockpit v3 S6): `self.prompt = {verb, entry, stage, value, armed}`. A `name` stage is a text field
184
191
  # (` › Rename: value█`); a `confirm` stage is ` › <word> ‘name’ — y⏎ confirm · Esc cancel`. The verb is what the phone
185
192
  # title announces (DM-LANES-SIDEBAR-TITLE); the word is what the footer says it does — `P` registers the session.
186
- PROMPT_FIELDS = {'rename': 'Rename', 'promote': 'Register as'}
193
+ PROMPT_FIELDS = {'rename': 'Rename', 'promote': 'Register as', 'message': 'Message'}
187
194
  PROMPT_WORDS = {'close': 'close', 'promote': 'register', 'hide': 'hide'}
188
195
  # The owner's profile (cockpit v3 R3, LNS-76): users/<login>.json (libexec/users.py) of the person this device belongs
189
196
  # to. Opening a lane writes its mark there through users.update, which holds the profile's lock; the CLI waits up to
@@ -227,6 +234,81 @@ def osc8(url, text):
227
234
  return f'\033]8;;{url}\033\\{text}\033]8;;\033\\' if url else text
228
235
 
229
236
 
237
+ # Addresses, handles and roles (W15 L2/L2b/L2c, plan 2026-10-25-lanes-messaging-bus). statusd publishes per lane row a
238
+ # top-level `address` (`<board>.<slug>` or an alias, L.IDENT) and `role` (`coordinator`, `fleet-admin` or null), and in
239
+ # `agent{}` `name_match` (the agent's messaging name IS the address: true / false / null = not known) and `messaging`
240
+ # ({socket_present, name} or null) — status.json, which the sidebar already reads: no stat, read or fork of its own.
241
+ # The handle is the address with `@`: one ink-dim tone after the name on the cursor row (`look.handles` = `cursor`, the
242
+ # default), on every lane row (`all`) or nowhere (`off`). The name is truncated first; the handle is drawn whole or
243
+ # not at all, and never leaves the name fewer than HANDLE_NAME_MIN cells (its `…` included; a shorter name keeps its
244
+ # own width), so a 36-column row holds a handle of at most 15 cells beside a long name — the footer (`@`) and the `@`
245
+ # sheet show every handle whole. A row without an address (a statusd before W15) is today's row, byte for byte.
246
+ HANDLES_MODES = ('cursor', 'all', 'off')
247
+ HANDLE_NAME_MIN = 8
248
+ ADDRESS_MAX = 128 # characters of an address the sidebar prints (a longer one is no address)
249
+ MESSAGING_NAME_MAX = 128 # characters of a messaging name kept for the footer and the sheet (each clips further)
250
+ # statusd's `role` -> the column-3 mark that draws it: the leader glyph ★ in the attention tone (the board's
251
+ # coordinator) or the urgent tone (the fleet admin). Column 3's precedence, highest first: pending, the viewport marks,
252
+ # the viewing mark, the role glyph, `name_mismatch` ≠ (agent.name_match false), `pinned` ▲ — the phone's mark column
253
+ # (its column 2) the same without the viewports. The agent glyph (column 2) is never displaced.
254
+ ROLE_MARKS = {'coordinator': 'coordinator', 'fleet-admin': 'fleet_admin'}
255
+ # The `@` sheet (key_sheet's pattern: in place of the body until the next key, which it consumes): at most this many
256
+ # lines, each at most cols − 1 cells — first `@<board> → @<coordinator>` and `@fleet → @<fleet admin>` when status.json
257
+ # names them, then one line per lane on screen, `@<address> <kind>:<name>` (` ≠ ` between them when the agent's
258
+ # messaging name is not the address); `⋮ N more` when the lanes do not fit.
259
+ ADDRESS_SHEET_LINES = 18
260
+
261
+
262
+ def lane_address(row):
263
+ """A status.json lane row's `address` as the sidebar prints it, without the `@`: '' when absent, not a string, or
264
+ not one L.IDENT address of at most ADDRESS_MAX characters (published data: nothing else may reach the frame)."""
265
+ address = row.get('address') if isinstance(row, dict) else None
266
+ if not isinstance(address, str):
267
+ return ''
268
+ address = address.removeprefix('@')
269
+ return address if len(address) <= ADDRESS_MAX and L.IDENT.match(address) else ''
270
+
271
+
272
+ def lane_role(row):
273
+ """The column-3 mark key of a row's `role` (ROLE_MARKS), or None: no role, or a word this reader does not know."""
274
+ role = row.get('role') if isinstance(row, dict) else None
275
+ return ROLE_MARKS.get(role) if isinstance(role, str) else None
276
+
277
+
278
+ def name_mismatch(row):
279
+ """True only when statusd says the agent's messaging name is NOT the lane's address (`agent.name_match` false);
280
+ null or absent (not known, another harness, an older statusd) is no mismatch."""
281
+ agent = row.get('agent') if isinstance(row, dict) else None
282
+ return isinstance(agent, dict) and agent.get('name_match') is False
283
+
284
+
285
+ def inbox_waiting(row):
286
+ """True while statusd says messages wait in the lane's inbox (`inbox.pending`, a positive int; W15 L4)."""
287
+ inbox = row.get('inbox') if isinstance(row, dict) else None
288
+ n = inbox.get('pending') if isinstance(inbox, dict) else None
289
+ return isinstance(n, int) and not isinstance(n, bool) and n > 0
290
+
291
+
292
+ def messaging_of(row):
293
+ """(kind, name) the footer and the `@` sheet say for a row: the agent's harness (`claude`, `codex`, …) and its
294
+ messaging name (`agent.messaging.name`), each printable and bounded, '' when not known."""
295
+ agent = row.get('agent') if isinstance(row, dict) else None
296
+ agent = agent if isinstance(agent, dict) else {}
297
+ messaging = agent.get('messaging') if isinstance(agent.get('messaging'), dict) else {}
298
+ kind, name = agent.get('harness'), messaging.get('name')
299
+ return (short_name(kind, 32) if isinstance(kind, str) else '',
300
+ short_name(name, MESSAGING_NAME_MAX) if isinstance(name, str) else '')
301
+
302
+
303
+ def resolve_handles(env, meta):
304
+ """`look.handles` (W15 L2): the device file's `handles` (on a device with an owner, layered_look's meta: that file's
305
+ keys), then LANES_HANDLES, then `cursor`. Pure; a value outside HANDLES_MODES is skipped, layer by layer, so a
306
+ hand-edited file never kills a pane."""
307
+ meta = meta if isinstance(meta, dict) else {}
308
+ return next((value for value in (meta.get('handles'), env.get('LANES_HANDLES')) if value in HANDLES_MODES),
309
+ HANDLES_MODES[0])
310
+
311
+
230
312
  def shown_version(path):
231
313
  """A tree's release as the sidebar paints it (cockpit v3 V2, LNS-84): lanes_lib.tree_version's first line, control
232
314
  characters dropped (a VERSION file never writes an escape into the terminal), at most 32 characters; '' when there
@@ -471,6 +553,9 @@ MOBILE_AGENT_LABELS = tokens.MOBILE_AGENT_LABELS
471
553
  # The phone header's words after each glyph count (spec §4.10): ` ◆1 need approval · ◇2 need you · ▸6 working`.
472
554
  # Keyed by HEADER_COUNTS, the statuses the desktop header counts.
473
555
  MOBILE_COUNT_WORDS = {'needs_approval': 'need approval', 'needs_input': 'need you', 'working': 'working', 'done': 'done'}
556
+ # W15 L1: statusd's additive `agent.activity` -> the phone's word for it, in place of the status label (a delegating
557
+ # lane's status is `working`, so its glyph, section and header count stay Working's).
558
+ MOBILE_ACTIVITY_LABELS = {'delegating': 'Delegating'}
474
559
  # The phone sidebar spells the same six words (plus `helper`) in full. The keys are GLYPHS's keys and the
475
560
  # vocabulary gate pins that: this map kept `idle` for a whole release after DEF-823 removed it from GLYPHS,
476
561
  # because the gate read GLYPHS alone and the map was a literal buried inside `render_mobile` (DEF-983).
@@ -660,25 +745,54 @@ BOX_ROWS = 1 # the upload strip (spec §4.6(d)); it was a four-row box
660
745
  # dynamic version row (cockpit v3 V2, LNS-84: ` lanes <current> · view <tree>`, key_sheet) — exactly the 19-row body
661
746
  # of a 24-row pane with the strip row; R5's `p h` / `H o` (LNS-78) took the two rows S10 left, and V2's row the line
662
747
  # `u z` now share. Plan W10 W7's `d` (the cursor lane's docs link) joins the strip's own keys, `+ U d`, for the same reason,
663
- # and W11's `i` (fold the fleet block) the reload and the sheet, `r i ?`.
748
+ # W11's `i` (fold the fleet block) the reload and the sheet, `r i ?`, W15 L2's `@` (the addresses) the find, `/ @`, and
749
+ # W15 L4's `m` (a message to the cursor lane) the rename, `R m`.
664
750
  # test_sidebar.DocumentedKeys holds the sheet, the table and handle() to the same keys.
665
751
  KEY_SHEET = (('↑ ↓ j k', 'Up Dn j k', 'move'), ('⏎ → Space', 'Enter Spc', 'open the cursor lane'),
666
752
  ('J K', 'J K', 'open next / prev lane'), ('Tab S-Tab', 'Tab S-Tab', 'next / prev needing you'),
667
- ('2 3', '2 3', 'show in viewport 2 / 3'), ('/', '/', 'find a lane'),
753
+ ('2 3', '2 3', 'show in viewport 2 / 3'), ('/ @', '/ @', 'find / addresses'),
668
754
  ('Esc', 'Esc', 'cancel, back to lane'), ('g G', 'g G', 'first / last'),
669
755
  ('+ U d', '+ U d', 'shell / upload / docs'), ('a', 'a', 'add to a workspace'),
670
756
  ('x', 'x', 'close (y, then Enter)'), ('u z', 'u z', 'unregister / undo 10 s'),
671
- ('R', 'R', 'rename'), ('P', 'P', 'register a session'), ('p h', 'p h', 'pin / hide lane'),
757
+ ('R m', 'R m', 'rename / message'), ('P', 'P', 'register a session'), ('p h', 'p h', 'pin / hide lane'),
672
758
  ('H o', 'H o', 'hide tab / hidden lanes'), ('r i ?', 'r i ?', 'reload / fleet / keys'),
673
759
  ('Ctrl-Alt-l', 'Ctrl-Alt-l', 'focus the sidebar'))
674
760
  PASTE_START, PASTE_END = '\033[200~', '\033[201~'
675
761
  # A paste typed into a footer field (Sidebar.pasted): a run of line breaks / tabs is one space, never an Enter.
676
762
  PASTE_BREAKS = re.compile(r'[\t\n\v\f\r]+')
763
+ # Input a read cut (BEY-6842; Sidebar.handle_input). run() reads at most 4096 bytes per wake, and a writer that hands
764
+ # its bytes over in pieces (Zellij under backpressure) can end a read anywhere: inside a paste marker, a mouse report
765
+ # or a multi-byte character. ESC_WAIT_S is how long a lone Esc or another unfinished sequence that ends a read waits for
766
+ # more input before it is the key it says it is — an escape delay on run()'s one select tick (tick_timeout,
767
+ # expire_carry): a bare Esc typed alone acts after this. CARRY_MAX is the longest unfinished sequence held for the next
768
+ # read (an SGR mouse report is under 20 characters).
769
+ ESC_WAIT_S = 0.05
770
+ CARRY_MAX = 32
771
+ UTF8 = codecs.getincrementaldecoder('utf-8') # take_reports: a character cut by a read waits for its rest
677
772
  # W9 U6 (LNS-94): how often the sidebar looks for clients/<device>.update-ready — one stat per UPDATE_POLL seconds,
678
773
  # never one per tick (spec §8's tick budget counts reload/poll_health/poll_upload; this look is outside the tick).
679
774
  UPDATE_POLL = 30
680
775
 
681
776
 
777
+ def marker_cut(text):
778
+ """Whether `text` is a bracketed-paste marker (`ESC [ 2 0 0 ~` / `ESC [ 2 0 1 ~`) cut short, two characters or more:
779
+ what a read that ends inside one leaves (handle_input holds it for the next read, which completes it)."""
780
+ return 1 < len(text) < len(PASTE_START) and (PASTE_START.startswith(text) or PASTE_END.startswith(text))
781
+
782
+
783
+ def unfinished_at(data):
784
+ """Where the escape sequence a read cut off starts — a lone Esc, an SS3 introducer (`ESC O`) or a CSI with no final
785
+ byte yet (a cut paste marker, a cut mouse report) — or len(data) when the read ends on a whole key. Only the last
786
+ CARRY_MAX characters are looked at: a longer run with no final byte is no key, and is taken as it comes."""
787
+ i = data.rfind('\033', max(0, len(data) - CARRY_MAX))
788
+ if i < 0:
789
+ return len(data)
790
+ rest = data[i + 1:]
791
+ if rest in ('', 'O') or (rest[:1] == '[' and not any('@' <= c <= '~' for c in rest[1:])):
792
+ return i
793
+ return len(data)
794
+
795
+
682
796
  def key_length(data, i):
683
797
  """How many characters of `data` from `i` make ONE key: a plain character, a bare Esc, an SS3 key (`\\033OA`), an
684
798
  SGR mouse report (`\\033[<b;x;yM`/`m`) or any other CSI up to its final byte (`\\033[A`, `\\033[5~`). Esc followed
@@ -785,6 +899,25 @@ def promote_job(promote, spawn, workspace, entry, registry_path, name):
785
899
  return (new_id if isinstance(new_id, str) else None), sync
786
900
 
787
901
 
902
+ MESSAGE_TIMEOUT_S = 30 # `lanes message` on the worker: resolve, write the inbox, type when idle (two tmux clients)
903
+
904
+
905
+ def message_job(run, lane_id, text, login, state):
906
+ """`m`'s send, on the worker (W15 L4): `lanes message [--from <login>] <lane id> <text>` -> its answer line (what the
907
+ footer says: typed, or queued until the lane is next idle). A refusal raises LanesError with the verb's own words.
908
+ The verb reads the state directory this sidebar reads (LANES_STATE = `state`)."""
909
+ argv = [LANES_BIN, 'message'] + (['--from', login] if login else []) + ['--', lane_id, text]
910
+ try:
911
+ done = run(argv, capture_output=True, text=True, timeout=MESSAGE_TIMEOUT_S, stdin=subprocess.DEVNULL,
912
+ env=dict(os.environ, LANES_STATE=str(state)))
913
+ except subprocess.TimeoutExpired:
914
+ raise L.LanesError(f'lanes message did not answer within {MESSAGE_TIMEOUT_S} s') from None
915
+ said = ((done.stdout if done.returncode == 0 else done.stderr) or '').strip().splitlines()
916
+ if done.returncode:
917
+ raise L.LanesError(said[-1].removeprefix('lanes: ') if said else f'lanes message exited {done.returncode}')
918
+ return said[-1] if said else 'sent'
919
+
920
+
788
921
  class Sidebar:
789
922
  # Class-level defaults for the registration state, so a Sidebar built without `__init__` (the
790
923
  # alignment gate constructs one with `__new__` and sets only the fields its rule needs) reads the
@@ -814,11 +947,22 @@ class Sidebar:
814
947
  vivid = False # color in VIVID (apply_look): the modes whose colours Lanes defines (cockpit v3 P2)
815
948
  dim, notify = '90', True # the 16-colour dim's SGR and OSC 9 on/off (apply_look, resolve_dim_notify; P4)
816
949
  theme_pending, theme_deadline, osc_buffer = False, 0.0, ''
950
+ # Input across reads (BEY-6842, handle_input): a paste half read (`paste_buffer`, None = none), whether it — or the
951
+ # paste the carry opens — is dropped at its end (drop_pending), the escape sequence the last read cut (`key_carry`)
952
+ # and, for a lone Esc or another sequence that may be a whole key, the time.monotonic() at which run()'s tick takes
953
+ # it as that key (`carry_due`, 0.0 = a cut paste marker: only the next read decides); whether the last read ended
954
+ # in a lone Esc taken as the Esc key (`esc_taken`); whether this sidebar reads run()'s terminal (`on_tty`: only there
955
+ # can the rest of a cut sequence still be on its way — without one a lone Esc acts at once, as it always did); the
956
+ # UTF-8 decoder.
957
+ paste_buffer, paste_dropped, key_carry, carry_due = None, False, '', 0.0
958
+ esc_taken, on_tty, utf8 = False, False, None
817
959
  last_visible = () # the list visible() last returned: the one `self.cursor` indexes
818
960
  economy = {} # read-only default; reload() assigns the loaded economy.json (load_economy)
819
961
  economy_tiers = '' # this workspace's tier mix from economy.json, `F2 S1` (reload)
820
962
  more_row = 0 # the 1-based screen row of `⋮ N more` (render), 0 = the list fits
821
963
  showing_keys = False # `?` replaces the body with the key sheet until the next key (spec §4.7)
964
+ sheet = 'keys' # which sheet showing_keys shows: `keys` (`?`) or `addresses` (`@`, W15 L2)
965
+ handles = 'cursor' # look.handles (apply_look, resolve_handles): `cursor`, `all` or `off` (W15 L2)
822
966
  fleet = {} # other workspaces' title -> {needs_approval: n, needs_input: n} (reload)
823
967
  board_titles = {} # workspace id -> title, from the registry (reload)
824
968
  strip_row = False # render(): the strip row (economy or fleet attention) is drawn this frame
@@ -935,7 +1079,9 @@ class Sidebar:
935
1079
  self.message = ''
936
1080
  self.box, self.box_top = False, 10 ** 6
937
1081
  self.entry_top, self.entry_height = 2, 1
938
- self.armed, self.paste_buffer = False, None
1082
+ self.armed, self.paste_buffer, self.paste_dropped = False, None, False
1083
+ self.key_carry, self.carry_due, self.esc_taken = '', 0.0, False
1084
+ self.on_tty, self.utf8 = False, UTF8('replace')
939
1085
  self.upload = None # {'id', 'spool', 'names', 'at'} while a request is in flight
940
1086
  self.upload_note, self.upload_note_at = '', 0
941
1087
  # Which lanes (cockpit v3 V2): this tree's version once; the installed one now and every 30 s (recheck_version).
@@ -1079,13 +1225,13 @@ class Sidebar:
1079
1225
  # ------------------------------------------------------------- the self-swap (cockpit v3 U5)
1080
1226
  def idle(self):
1081
1227
  """Nothing would be lost by replacing this process now: no prompt, no filter being typed, no armed strip, no
1082
- Add to workspace picker or key sheet, no paste half read, no action on the worker (a close mid-kill), no
1083
- promotion held (S8), no undo offer (S7), no upload in flight, no profile mark waiting for its retry (R3), and no
1084
- rebuild `r` started (W9 U6, rebuild_view): that rebuild ends this process with its view, so swapping first
1085
- would only repaint once for nothing."""
1228
+ Add to workspace picker or key sheet, no paste or escape sequence half read (BEY-6842), no action on the worker
1229
+ (a close mid-kill), no promotion held (S8), no undo offer (S7), no upload in flight, no profile mark waiting for
1230
+ its retry (R3), and no rebuild `r` started (W9 U6, rebuild_view): that rebuild ends this process with its view,
1231
+ so swapping first would only repaint once for nothing."""
1086
1232
  return not (self.prompt or self.filtering or self.armed or self.registration or self.showing_keys
1087
- or self.paste_buffer is not None or self.actions or self.pending_rows or self.undo or self.upload
1088
- or self.profile_marks or self.last_open or time.monotonic() < self.rebuild_until)
1233
+ or self.paste_buffer is not None or self.key_carry or self.actions or self.pending_rows or self.undo
1234
+ or self.upload or self.profile_marks or self.last_open or time.monotonic() < self.rebuild_until)
1089
1235
 
1090
1236
  def swap_due(self):
1091
1237
  """reload()'s tick: the installed version differs from this tree's, a re-exec would run it (`swappable`), and
@@ -1231,9 +1377,10 @@ class Sidebar:
1231
1377
  devices included."""
1232
1378
  color, theme, glyphs = resolve_modes(os.environ, meta)
1233
1379
  dim, notify = resolve_dim_notify(os.environ, meta)
1234
- changed = (color, glyphs, dim) != (self.color, self.glyph_mode, self.dim)
1380
+ handles = resolve_handles(os.environ, meta) # W15 L2: where the rows draw the lane's handle
1381
+ changed = (color, glyphs, dim, handles) != (self.color, self.glyph_mode, self.dim, self.handles)
1235
1382
  self.color, self.glyph_mode, self.vivid = color, glyphs, color in VIVID
1236
- self.dim, self.notify = dim, notify == '1'
1383
+ self.dim, self.notify, self.handles = dim, notify == '1', handles
1237
1384
  if theme != 'auto':
1238
1385
  changed = changed or theme != self.variant
1239
1386
  self.variant, self.theme_pending = theme, False
@@ -1415,6 +1562,7 @@ class Sidebar:
1415
1562
  if not key:
1416
1563
  return
1417
1564
  self.begin_action()
1565
+ self.drop_pending() # BEY-6842: a paste on its way to what the chord cancels never lands in the filter / strip
1418
1566
  if self.prompt:
1419
1567
  self.cancel_prompt()
1420
1568
  if self.registration:
@@ -2037,6 +2185,9 @@ class Sidebar:
2037
2185
  def row(self, entry, index, target, others, cols, now, section_tone=None):
2038
2186
  """One lane row (spec §4.2): columns 1-35 written, column 36 never (the caller's `\\033[K` clears it).
2039
2187
  cursor 1 · agent 2 · mark 3 · name 4-27 · space · age 29-31 · space · stream 33 · tail 34 · × 35.
2188
+ W15 L2: the lane's handle (`@<address>`) shares columns 4-27 with the name, after it and its viewer dots, on the
2189
+ cursor row (`look.handles` cursor) or every row (`all`); column 3 carries the role glyph ★ and the ≠ of a
2190
+ messaging name that is not the address, below pending, the viewports and the viewing mark (ROLE_MARKS).
2040
2191
  Cached per lane by everything that can change its bytes (spec §4.11); `row_hits`/`row_misses` count it."""
2041
2192
  observed = self.status.get(entry['id']) or {}
2042
2193
  agent = observed.get('agent') if isinstance(observed.get('agent'), dict) else {}
@@ -2056,7 +2207,14 @@ class Sidebar:
2056
2207
  mark = self.glyphs['marks'][name]
2057
2208
  if mark == ' ' and is_viewing and not is_cursor:
2058
2209
  mark = self.glyphs['marks']['viewing']
2059
- # The owner's pin (cockpit v3 R5): column 3's lowest mark — pending, the viewports and the viewing mark win.
2210
+ # W15 L2b/L2c/L4: the lane's role (the leader glyph), then messages waiting in its inbox (✉), then a messaging
2211
+ # name that is not its address — below the viewing mark, above the pin.
2212
+ leader, inbox, mismatch = lane_role(observed), inbox_waiting(observed), name_mismatch(observed)
2213
+ for flag, name in ((leader, leader), (inbox, 'inbox'), (mismatch, 'name_mismatch')):
2214
+ if mark == ' ' and flag:
2215
+ mark, mark_role = self.glyphs['marks'][name], MARKS[name][2]
2216
+ # The owner's pin (cockpit v3 R5): column 3's lowest mark — pending, the viewports, the viewing mark and the
2217
+ # W15 marks win.
2060
2218
  pinned = entry['id'] in self.lane_pins
2061
2219
  if mark == ' ' and pinned:
2062
2220
  mark, mark_role = self.glyphs['marks']['pinned'], MARKS['pinned'][2]
@@ -2068,9 +2226,12 @@ class Sidebar:
2068
2226
  can_register = closable and R.eligible(entry)
2069
2227
  # Plan W10 W7: the cursor row's name is one OSC 8 link to its lane's documents while it has any.
2070
2228
  link = self.lane_docs_link(entry['id']) if is_cursor else ''
2229
+ # W15 L2: the handle this row may draw (fitted to the name below): the cursor row's, or every row's.
2230
+ address = lane_address(observed) if self.handles == 'all' or (self.handles == 'cursor' and is_cursor) else ''
2231
+ handle = '@' + address if address else ''
2071
2232
  key = (entry.get('name'), entry.get('color'), entry.get('icon'), closable, can_register, key_state, stale,
2072
2233
  viewers, status, age, tail, tail_role, is_cursor, is_viewing, mark, mark_role, cols, section_tone, hidden,
2073
- link)
2234
+ link, handle, leader, inbox, mismatch)
2074
2235
  cached = self.row_cache.get(entry['id'])
2075
2236
  if cached and cached[0] == key:
2076
2237
  self.row_hits += 1
@@ -2085,13 +2246,20 @@ class Sidebar:
2085
2246
  name_width -= 3
2086
2247
  name_width = max(1, name_width)
2087
2248
  name = entry.get('name', entry['id'])
2088
- clipped, used = clip(name, name_width)
2249
+ # W15 L2: the handle takes the end of the name's cells and one blank before it. The name is truncated first;
2250
+ # the handle is dropped, never cut, when the name would keep fewer than HANDLE_NAME_MIN cells (fewer than its
2251
+ # own width, for a shorter name).
2252
+ handle_width = cell_width(handle) + 1 if handle else 0
2253
+ if handle and name_width - handle_width < min(cell_width(name), HANDLE_NAME_MIN):
2254
+ handle, handle_width = '', 0
2255
+ room = name_width - handle_width
2256
+ clipped, used = clip(name, room)
2089
2257
  if len(clipped) < len(name): # truncated: one cell less for the name, then `…` (no second width walk)
2090
- while clipped and used > name_width - 1:
2258
+ while clipped and used > room - 1:
2091
2259
  used -= cell_width(clipped[-1])
2092
2260
  clipped = clipped[:-1]
2093
2261
  clipped, used = clipped + g['marks']['truncation'], used + 1
2094
- pad = ' ' * max(0, name_width - used)
2262
+ pad = ' ' * max(0, room - used)
2095
2263
  cursor = f'{tone["accent"]}{g["marks"]["cursor"]}{reset}' if is_cursor else ' '
2096
2264
  agent_cell = ' '
2097
2265
  if status:
@@ -2108,6 +2276,8 @@ class Sidebar:
2108
2276
  name_cell = osc8(link, f'{lead}{clipped}{reset}' if lead else clipped)
2109
2277
  if viewers:
2110
2278
  name_cell += f'{tone["ink-dim"]}{viewers}{reset}'
2279
+ if handle: # W15 L2: one ink-dim tone, outside the docs link
2280
+ name_cell += f' {tone["ink-dim"]}{handle}{reset}'
2111
2281
  # The `+` register control (README "Daily use") has no column in spec §4.2: it takes the spacer cell 28
2112
2282
  # (= cols − 8), inside its click box `cols − 8 ≤ x < cols − 4`, so the age keeps its place. It and the `×`
2113
2283
  # are POSITIONED (CHA): a name whose terminal width disagrees with `cell_width` cannot push either control
@@ -2430,6 +2600,8 @@ class Sidebar:
2430
2600
  self.closed(action, ok, value)
2431
2601
  elif action['verb'] == 'promote':
2432
2602
  self.promoted(action, ok, value)
2603
+ elif action['verb'] == 'message':
2604
+ self.messaged(action, ok, value)
2433
2605
  else:
2434
2606
  self.shell_created(action, ok, value)
2435
2607
  if answers:
@@ -2531,10 +2703,20 @@ class Sidebar:
2531
2703
 
2532
2704
  def cancel_prompt(self):
2533
2705
  """End the prompt unanswered: the footer says ` Cancelled` (an Esc, any other key at a confirmation, an emptied
2534
- name, a sidebar-key chord)."""
2706
+ name, a sidebar-key chord). What was on its way to it never lands in what is open next (drop_pending)."""
2535
2707
  self.close_prompt()
2708
+ self.drop_pending()
2536
2709
  self.message = 'Cancelled'
2537
2710
 
2711
+ def drop_pending(self):
2712
+ """A prompt cancelled or the keyboard gone back (hand_off) between reads (BEY-6842): a paste half read, and one
2713
+ the held carry turns out to open, are read to their end marker and dropped (take_input, handle_input), never
2714
+ typed into what is open next — a message composer opened later included; a carry that opens no paste is
2715
+ discarded, never a key. Inside a read there is nothing to mark: handle_input holds no carry while it takes the
2716
+ read, and decides on the one this read cut after its keys (a hand-off marks it the lane's)."""
2717
+ if self.paste_buffer is not None or self.key_carry:
2718
+ self.paste_dropped = True
2719
+
2538
2720
  def request_close(self, entry):
2539
2721
  """`x` or a click on `×`: ask first (spec §4.6(a)); handle() arms on `y`, closes on the Enter after it and cancels
2540
2722
  on anything else (cockpit v3 S3). A lane that cannot be closed asks nothing and keeps the keyboard: the `y` typed
@@ -2671,6 +2853,37 @@ class Sidebar:
2671
2853
  self.dirty = True
2672
2854
  self.release_focus()
2673
2855
 
2856
+ def start_message(self, entry):
2857
+ """`m` (W15 L4): a one-line message to the lane under the cursor — the `message` prompt's field, empty (` ›
2858
+ Message: █`). Enter sends it (commit_message); an empty line sends nothing."""
2859
+ self.begin_action()
2860
+ if not entry or entry.get('divider') or entry.get('action') or not entry.get('id') \
2861
+ or entry.get('holder') == 'zmx' or self.still_pending(entry):
2862
+ self.message, self.dirty = 'no lane to message here', True
2863
+ return
2864
+ self.open_prompt('message', entry, 'name', '')
2865
+
2866
+ def commit_message(self):
2867
+ """Enter on the message field: `lanes message` from this device's owner (`host:<login>`) to the lane, on the
2868
+ worker (message_job) — typed when the lane is idle, else queued in its inbox and typed when it is next idle.
2869
+ The footer says which once the verb answers; the keyboard goes back to the lane now."""
2870
+ prompt = self.close_prompt()
2871
+ entry, text = prompt.get('entry'), prompt.get('value', '').strip()
2872
+ if not entry or not text:
2873
+ self.message = 'Cancelled'
2874
+ self.release_focus()
2875
+ return
2876
+ key = f"{entry['id']}--message-{time.monotonic_ns()}"
2877
+ self.start_action(key, {'verb': 'message', 'entry': entry}, message_job, subprocess.run, entry['id'], text,
2878
+ self.login, STATE)
2879
+ g = self.glyphs['marks']
2880
+ self.message = f'Sending to {g["quote-open"]}{entry.get("name", entry["id"])}{g["quote-close"]}'
2881
+ self.release_focus()
2882
+
2883
+ def messaged(self, action, ok, value):
2884
+ """`m`'s answer: the verb's own line (` message … typed` / ` … queued …`), or why it refused."""
2885
+ self.message = (value if isinstance(value, str) and value else 'sent') if ok else failure_text(value)
2886
+
2674
2887
  def start_promote(self, entry):
2675
2888
  """Begin promotion of an unregistered session: the `promote` prompt's name stage, prefilled with the session's
2676
2889
  name (Enter accepts it), then its confirmation — `y` arms, Enter registers (cockpit v3 S3). A refusal asks
@@ -3067,6 +3280,90 @@ class Sidebar:
3067
3280
  self._message_link = url if self.web_origin else ''
3068
3281
  self.release_focus()
3069
3282
 
3283
+ def show_addresses(self, entry):
3284
+ """`@` (W15 L2): the cursor lane's handle in the footer — a message like `d`'s (MESSAGE_S, or until the next
3285
+ action; no link: an address is no URL) — and every address in place of the body until the next key, which
3286
+ closes the sheet and is consumed, as `?`'s (address_sheet). The keyboard stays here until that key."""
3287
+ self.begin_action()
3288
+ self.message = self.address_text(entry)
3289
+ self.sheet, self.showing_keys, self.dirty = 'addresses', True, True
3290
+
3291
+ def messaging_text(self, row, between, colon):
3292
+ """What follows a lane's address in the footer (`between` ` · `, `colon` `: `) and on the `@` sheet (two blanks,
3293
+ `:`): the agent's harness and its messaging name — `claude: <name>`, the harness alone while the name is not
3294
+ known, '' for a lane without an agent. ` ≠ ` (the `name_mismatch` mark) replaces `between` when statusd says the
3295
+ name is not the address (name ≠ address)."""
3296
+ kind, name = messaging_of(row)
3297
+ said = f'{kind}{colon}{name}' if kind and name else kind or name
3298
+ if not said:
3299
+ return ''
3300
+ return (f' {self.glyphs["marks"]["name_mismatch"]} ' if name_mismatch(row) else between) + said
3301
+
3302
+ def address_text(self, entry):
3303
+ """`@`'s footer message for `entry`: `@<address> · <kind>: <messaging name>` (` ≠ ` for a name that is not the
3304
+ address), ` no address for ‘name’` on a lane statusd published none for (a statusd before W15), ` no address
3305
+ here` on a divider or an action row."""
3306
+ g = self.glyphs['marks']
3307
+ lane_id = (entry or {}).get('id')
3308
+ if not lane_id or entry.get('divider') or entry.get('action'):
3309
+ return 'no address here'
3310
+ row = self.status.get(lane_id) or {}
3311
+ address = lane_address(row)
3312
+ if not address:
3313
+ return f'no address for {g["quote-open"]}{entry.get("name", lane_id)}{g["quote-close"]}'
3314
+ return '@' + address + self.messaging_text(row, f' {g["sep"]} ', ': ')
3315
+
3316
+ def leaders(self):
3317
+ """((address, role mark) of this workspace's coordinator, (address, role mark) of the fleet admin), each ('',
3318
+ None) while status.json names none: the coordinator is the registry lane of this workspace whose row says
3319
+ `role: coordinator` — else the one that says `fleet-admin` (the fleet admin's own board) — and the fleet admin
3320
+ any row of status.json that says `fleet-admin`. Reads the status.json already loaded (no I/O)."""
3321
+ coordinator = fleet = ('', None)
3322
+ for entry in self.entries:
3323
+ row = self.status.get(entry.get('id')) or {}
3324
+ role, address = lane_role(row), lane_address(row)
3325
+ if address and role and (role == 'coordinator' or not coordinator[0]):
3326
+ coordinator = (address, role)
3327
+ if role == 'coordinator':
3328
+ break
3329
+ for row in self.status.values():
3330
+ if lane_role(row) == 'fleet_admin' and lane_address(row):
3331
+ fleet = (lane_address(row), 'fleet_admin')
3332
+ break
3333
+ return coordinator, fleet
3334
+
3335
+ def address_sheet(self, cols, body, entries):
3336
+ """`body` lines: the `@` sheet (W15 L2, key_sheet's pattern) — first ` @<workspace> → @<coordinator>` and
3337
+ ` @fleet → @<fleet admin>` while status.json names them (the address in its leader glyph's tone), then one line
3338
+ per lane of `entries` (the list on screen, in its order) with an address, ` @<address> <kind>:<name>`, the
3339
+ harness and name ink-dim (` ≠ ` for a name that is not the address); at most ADDRESS_SHEET_LINES lines, the last
3340
+ ` ⋮ N more` when the lanes do not fit; each at most cols − 1 cells; padded with blank lines, cut to the body.
3341
+ ` no addresses published` while no lane has one (a statusd before W15)."""
3342
+ tone, g = self.tone, self.glyphs['marks']
3343
+ dim, reset, width = tone['ink-dim'], tone['reset'], max(0, cols - 1)
3344
+ lines = []
3345
+ for word, (address, role) in zip((self.workspace, 'fleet'), self.leaders()):
3346
+ if address:
3347
+ head, used = clip(f' @{word} {g["arrow"]} ', width)
3348
+ rest, _ = clip('@' + address, width - used)
3349
+ lines.append(f'{dim}{head}{reset}{tone[MARKS[role][2]]}{rest}{reset}')
3350
+ lanes = []
3351
+ for entry in entries:
3352
+ row = {} if entry.get('divider') or entry.get('action') else self.status.get(entry.get('id')) or {}
3353
+ address = lane_address(row)
3354
+ if address:
3355
+ text, used = clip(' @' + address, width)
3356
+ said, _ = clip(self.messaging_text(row, ' ', ':'), width - used)
3357
+ lanes.append(f'{text}{dim}{said}{reset}' if said else text)
3358
+ if not lanes and not lines:
3359
+ lines.append(f'{dim}{clip(" no addresses published", width)[0]}{reset}')
3360
+ room = max(1, min(ADDRESS_SHEET_LINES, body) - len(lines))
3361
+ if len(lanes) > room:
3362
+ hidden = len(lanes) - (room - 1)
3363
+ more, _ = clip(f' {g["more"]} {hidden} more', width)
3364
+ lanes = lanes[:room - 1] + [f'{dim}{more}{reset}']
3365
+ return (lines + lanes + [''] * body)[:body]
3366
+
3070
3367
  def toggle_hidden(self):
3071
3368
  """`o`: show the lanes the owner hid (faint, in their places; `h` there shows one for good) or hide them again.
3072
3369
  The footer says how many; then the keyboard goes back to the lane."""
@@ -3366,9 +3663,14 @@ class Sidebar:
3366
3663
  not end it first (prompt_sequence ends it before a click opens a lane) — is closed without a word of its own,
3367
3664
  so the action that moved the keyboard says what it says (` view not running yet`). Left open, its field or
3368
3665
  question stayed in the footer while the keys went to the lane, and the next key typed on the sidebar answered
3369
- it. release_focus() never gets here with one open (an open question keeps the keyboard)."""
3666
+ it. release_focus() never gets here with one open (an open question keeps the keyboard). Nothing half read
3667
+ outlives it either (BEY-6842): drop_pending() marks a paste on its way, and the decoder forgets a cut character —
3668
+ the rest of it was typed for the lane."""
3370
3669
  if self.prompt:
3371
3670
  self.close_prompt()
3671
+ self.drop_pending()
3672
+ if self.utf8 is not None:
3673
+ self.utf8.reset()
3372
3674
  self.focus_lane(slot)
3373
3675
  self.handed_off = True
3374
3676
  self.focused, self.legend_until = False, 0.0
@@ -3588,10 +3890,13 @@ class Sidebar:
3588
3890
  lines.append(f'{dim} {key}{reset}{action}')
3589
3891
  return (lines + [''] * body)[:body]
3590
3892
 
3591
- @staticmethod
3592
- def tick_timeout():
3593
- """run()'s select() timeout: 1 s, always. An upload no longer shortens it — its strip repaints on progress."""
3594
- return 1.0
3893
+ def tick_timeout(self, now=None):
3894
+ """run()'s select() timeout: 1 s — or until a sequence a read cut is due (expire_carry, BEY-6842: the escape
3895
+ delay rides this one select, never a timer of its own). An upload no longer shortens it — its strip repaints
3896
+ on progress."""
3897
+ if not self.carry_due:
3898
+ return 1.0
3899
+ return max(0.0, min(1.0, self.carry_due - (time.monotonic() if now is None else now)))
3595
3900
 
3596
3901
  # ------------------------------------------------------------ rendering
3597
3902
  def place_body(self, entries, body):
@@ -3696,7 +4001,8 @@ class Sidebar:
3696
4001
  g = marks
3697
4002
  sep, q0, q1 = f' {g["sep"]} ', g['quote-open'], g['quote-close']
3698
4003
  if self.showing_keys: # spec §4.7: `?` replaces the body with the key sheet until any key
3699
- out.extend(f'{line}\033[K\r\n' for line in self.key_sheet(cols, body))
4004
+ sheet = self.address_sheet(cols, body, entries) if self.sheet == 'addresses' else self.key_sheet(cols, body)
4005
+ out.extend(f'{line}\033[K\r\n' for line in sheet) # W15 L2: `@`'s sheet the same way
3700
4006
  sections = self.sections_at(entries, rows) if rows else {}
3701
4007
  for row in range(0 if self.showing_keys else body):
3702
4008
  index = rows[row] if row < len(rows) else len(entries)
@@ -3828,6 +4134,12 @@ class Sidebar:
3828
4134
  closable = bool(entry.get('closable')) and not pending
3829
4135
  can_register = closable and R.eligible(entry)
3830
4136
  mark = f'{tone["accent"]}{marks["viewing"]}{reset}' if entry['id'] == target else ' '
4137
+ # W15 L2b/L2c/L4: the role's leader glyph, then ✉ (messages waiting), then the ≠ of a messaging name
4138
+ # that is not the address — the desktop's column-3 order (row()), between the viewing mark and the pin.
4139
+ for key in (lane_role(observed), 'inbox' if inbox_waiting(observed) else None,
4140
+ 'name_mismatch' if name_mismatch(observed) else None):
4141
+ if mark == ' ' and key:
4142
+ mark = f'{tone[MARKS[key][2]]}{marks[key]}{reset}'
3831
4143
  if mark == ' ' and entry['id'] in self.lane_pins: # the owner's pin, below viewing (R5)
3832
4144
  mark = f'{tone[MARKS["pinned"][2]]}{marks["pinned"]}{reset}'
3833
4145
  if pending:
@@ -3852,9 +4164,10 @@ class Sidebar:
3852
4164
  if entry.get('divider'):
3853
4165
  line(); line()
3854
4166
  continue
3855
- # Row B: what the agent needs and since when, and which harness; a shell says its state word and its
3856
- # output age. Row C: the agent's task, blank for shells. Agent text is pane-title data: control
3857
- # characters are dropped so a title can never inject a sequence into the frame.
4167
+ # Row B: what the agent needs and since when, and which harness — `Delegating` in place of `Working`
4168
+ # while its turn is over but its background subagents or jobs still run (W15 L1, statusd's additive
4169
+ # `agent.activity`, MOBILE_ACTIVITY_LABELS); a shell says its state word and its output age. Row C: the agent's task, blank for shells. Agent text is
4170
+ # pane-title data: control characters are dropped so a title can never inject a sequence into the frame.
3858
4171
  task = ''
3859
4172
  if entry.get('action'):
3860
4173
  detail = {'new-shell': 'Create a persistent shell', 'register-workspace': 'Add this session',
@@ -3863,7 +4176,8 @@ class Sidebar:
3863
4176
  since = agent.get('since')
3864
4177
  age = age3(now - since if isinstance(since, (int, float)) and since > 0 else None).strip()
3865
4178
  harness = OSC_UNSAFE.sub('', str(agent.get('harness') or ''))
3866
- detail = sep.join(part for part in (MOBILE_AGENT_LABELS[status], age, harness) if part)
4179
+ label = MOBILE_ACTIVITY_LABELS.get(agent.get('activity')) if status == 'working' else None
4180
+ detail = sep.join(part for part in (label or MOBILE_AGENT_LABELS[status], age, harness) if part)
3867
4181
  task = OSC_UNSAFE.sub('', str(agent.get('name') or ''))
3868
4182
  else:
3869
4183
  activity = observed.get('activity')
@@ -3894,34 +4208,131 @@ class Sidebar:
3894
4208
  """What in a raw read is no input -> the rest (keys, mouse reports, a paste). An OSC 11 answer (`\\033]11;rgb:…`
3895
4209
  ST/BEL, possibly split across reads) is a theme, never an Esc: it is taken out before anything reads the keys,
3896
4210
  so it cannot cancel a filter or a prompt (spec §2.4, Review Focus 6). A focus report is noted and taken out
3897
- (note_focus, cockpit v3 S4)."""
3898
- if isinstance(data, bytes): # the raw read, as run() gets it from the pty
3899
- data = data.decode('utf-8', 'replace')
4211
+ (note_focus, cockpit v3 S4). The raw read (bytes, as run() gets it from the pty) is decoded by this sidebar's
4212
+ incremental decoder (BEY-6842): a multi-byte character the read cut waits there for the rest of its bytes,
4213
+ never two `�` typed into a field; a byte that cannot continue it makes it one `�`, as the old per-read decode
4214
+ did. hand_off() empties the decoder: what the read held after the keyboard went back was the lane's."""
4215
+ if isinstance(data, bytes):
4216
+ if self.utf8 is None:
4217
+ self.utf8 = UTF8('replace')
4218
+ data = self.utf8.decode(data)
3900
4219
  return self.note_focus(self.strip_osc(data))
3901
4220
 
3902
4221
  def handle_input(self, data):
3903
- """The input of one read, its reports already taken out (take_reports)."""
4222
+ """The input of one read, its reports already taken out (take_reports).
4223
+
4224
+ A read can end inside an escape sequence (BEY-6842, the `m` composer's review): run() reads at most 4096 bytes
4225
+ per wake and a writer that hands its bytes over in pieces can cut a read anywhere, so `ESC [ 2 0` may end one
4226
+ read and `0 ~ first line ⏎ …` start the next. Read as keys, that rest typed `0~first line` into ` › Message: `
4227
+ and its line break sent it, without an Enter of the person's. The sequence a read cut (unfinished_at) is held
4228
+ in `key_carry` instead and the next read is appended to it, so a marker cut anywhere is a marker again and its
4229
+ paste stays field data (pasted(): line breaks as one space); only an Enter typed outside a paste submits.
4230
+ * A cut paste marker (marker_cut: `ESC [` … `ESC [ 2 0 1`) is always held: no sidebar key is one. The next
4231
+ read decides. When the two make the marker, or still a longer cut of it, they are one read. When they do
4232
+ not, the next byte ended the sequence, and the carry is taken first as the keys it is — an unterminated
4233
+ sequence, consumed as one always was (a name field keeps its text) — then the read on its own. A carry that
4234
+ never completes waits for the next read only; no timer acts on it, and it is at most five characters.
4235
+ * A lone Esc or another unfinished sequence (an SS3 introducer, a cut mouse report) may be a whole key too.
4236
+ On run()'s terminal (`on_tty`) it is held ESC_WAIT_S: a read before then is appended to it whatever it
4237
+ starts with (the bytes came together); else run()'s select tick, shortened to that moment
4238
+ (tick_timeout), takes it as the key it is (expire_carry) — a bare Esc typed alone cancels after
4239
+ ESC_WAIT_S. Without a terminal it is that key at once, as it always was. So an opening marker cut after
4240
+ its Esc whose rest is more than ESC_WAIT_S late is an Esc: the prompt is cancelled and nothing is sent;
4241
+ and when the next read then turns out to finish the marker (`esc_taken`), that paste is dropped like the
4242
+ lane's, never keys.
4243
+ Neither outlives the keyboard. When an action of this read hands it back, the rest of the read was typed for
4244
+ the lane (cockpit v3 S3) and a paste in that rest, or one a carry cut there opens, is read to its end marker in
4245
+ the reads that follow and dropped (take_input), never acted on as keys. When the keyboard goes back or a prompt
4246
+ is cancelled between reads (drop_pending), a paste half read or one the carry opens is dropped the same way,
4247
+ and a carry that opens none is discarded, never a key. A character cut by the read waits in take_reports'
4248
+ decoder the same way, and hand_off() empties it."""
3904
4249
  self.handed_off = False # cockpit v3 S3: set when an action of THIS read gives the keyboard back
3905
- # Bracketed paste (a drop, or a real paste) can span several reads: buffered until its end marker. It is taken at
3906
- # its place in the read (S3 review): the keys before it act first — `P`, Backspace, then the paste fills the
3907
- # emptied name — and pasted() routes it by what is open then. Once an action hands the keyboard back, the rest
3908
- # of the read, a paste included, was typed for the lane.
4250
+ carry, due, self.key_carry, self.carry_due = self.key_carry, self.carry_due, '', 0.0
4251
+ if self.esc_taken and not carry and self.paste_buffer is None:
4252
+ joined = '\033' + data
4253
+ if marker_cut(joined) or joined.startswith(PASTE_START):
4254
+ carry, self.paste_dropped = '\033', True # a paste cut after its Esc, taken as the Esc key
4255
+ self.esc_taken = False
4256
+ if carry:
4257
+ joined = carry + data
4258
+ if self.paste_dropped and self.paste_buffer is None: # the carry of a field the keyboard left
4259
+ if marker_cut(joined):
4260
+ self.key_carry = joined
4261
+ return
4262
+ if joined.startswith(PASTE_START):
4263
+ data = joined # its paste: read to its end and dropped
4264
+ else:
4265
+ self.paste_dropped = False # it opened none: discarded, never a key
4266
+ elif due or marker_cut(joined) or joined.startswith((PASTE_START, PASTE_END)):
4267
+ data = joined
4268
+ else:
4269
+ # The next byte ended it: the keys it is, as its own read would have taken them, then this read on its
4270
+ # own — a hand-off they make leaves this read's cut character in the decoder (it is not the lane's).
4271
+ held = self.utf8.getstate() if self.utf8 is not None else None
4272
+ self.take_input(carry)
4273
+ self.handed_off = False
4274
+ if held is not None:
4275
+ self.utf8.setstate(held)
4276
+ cut = unfinished_at(data)
4277
+ tail, due = data[cut:], 0.0
4278
+ if tail:
4279
+ if self.on_tty and not marker_cut(tail):
4280
+ due = time.monotonic() + ESC_WAIT_S # its rest may be on its way: run()'s tick decides
4281
+ if due or marker_cut(tail):
4282
+ data = data[:cut]
4283
+ else:
4284
+ self.esc_taken, tail = tail == '\033', ''
4285
+ self.take_input(data)
4286
+ if tail:
4287
+ self.key_carry, self.carry_due = tail, due
4288
+ if self.handed_off:
4289
+ self.paste_dropped = True # the lane's: never a key here, and a paste it opens is dropped
4290
+
4291
+ def take_input(self, data):
4292
+ """The keys and pastes of one read, its cut tail held back (handle_input). Bracketed paste (a drop, or a real
4293
+ paste) can span several reads: buffered until its end marker. It is taken at its place in the read (S3
4294
+ review): the keys before it act first — `P`, Backspace, then the paste fills the emptied name — and pasted()
4295
+ routes it by what is open then. Once an action hands the keyboard back, the rest of the read, a paste
4296
+ included, was typed for the lane; a paste that rest opens and does not end is read to its end marker in the
4297
+ next reads and dropped (`paste_dropped`, BEY-6842), as is one open when drop_pending() ran."""
3909
4298
  while data and not self.handed_off:
3910
4299
  if self.paste_buffer is not None:
3911
4300
  self.paste_buffer += data
3912
4301
  if PASTE_END not in self.paste_buffer:
3913
4302
  return
3914
4303
  pasted, _, data = self.paste_buffer.partition(PASTE_END)
3915
- self.paste_buffer = None
3916
- self.pasted(pasted)
4304
+ dropped, self.paste_buffer, self.paste_dropped = self.paste_dropped, None, False
4305
+ if not dropped:
4306
+ self.pasted(pasted)
3917
4307
  self.dirty = True
3918
4308
  continue
3919
4309
  keys, start, data = data.partition(PASTE_START)
3920
4310
  self.handle_keys(keys)
3921
- if not start or self.handed_off:
4311
+ if self.handed_off:
4312
+ rest = start + data
4313
+ if rest.rfind(PASTE_START) > rest.rfind(PASTE_END):
4314
+ self.paste_buffer, self.paste_dropped = '', True
4315
+ return
4316
+ if not start:
3922
4317
  return
3923
4318
  self.paste_buffer = ''
3924
4319
 
4320
+ def expire_carry(self, now=None):
4321
+ """run()'s tick when its select timed out: a lone Esc or another sequence held since a read ended in it
4322
+ (handle_input) that no read completed within ESC_WAIT_S is the key it is, now — taken as its own read would
4323
+ have taken it (a bare Esc cancels and gives the keyboard back). One a cancelled field or a returned keyboard
4324
+ left (drop_pending) is discarded instead, never a key. -> True when one was taken (a repaint)."""
4325
+ if not self.carry_due or (time.monotonic() if now is None else now) < self.carry_due:
4326
+ return False
4327
+ carry, self.key_carry, self.carry_due = self.key_carry, '', 0.0
4328
+ if self.paste_dropped and self.paste_buffer is None:
4329
+ self.paste_dropped = False
4330
+ else:
4331
+ self.handed_off = False
4332
+ self.take_input(carry)
4333
+ self.esc_taken = carry == '\033'
4334
+ return True
4335
+
3925
4336
  def note_focus(self, data):
3926
4337
  """Take the focus reports out of a read (cockpit v3 S4) and note where the keyboard is -> the read without them.
3927
4338
  A report is never a key: left in, `ESC [ I` would cancel a confirmation, close the key sheet or hand the
@@ -4076,6 +4487,8 @@ class Sidebar:
4076
4487
  prompt = self.prompt
4077
4488
  if ch in '\r\n' and prompt['verb'] == 'rename':
4078
4489
  self.commit_rename()
4490
+ elif ch in '\r\n' and prompt['verb'] == 'message':
4491
+ self.commit_message()
4079
4492
  elif ch in '\r\n':
4080
4493
  self.accept_promote_name()
4081
4494
  elif ch in '\x7f\x08':
@@ -4137,6 +4550,8 @@ class Sidebar:
4137
4550
  elif ch == 'R' and entries:
4138
4551
  entry = entries[min(self.cursor, len(entries) - 1)]
4139
4552
  self.start_rename(entry)
4553
+ elif ch == 'm': # W15 L4: one line to the cursor lane, as a message
4554
+ self.start_message(entries[min(self.cursor, len(entries) - 1)] if entries else None)
4140
4555
  elif ch == 'p' and entries: # cockpit v3 R5: pins and hidden lanes, the owner's profile
4141
4556
  self.pin_lane(entries[min(self.cursor, len(entries) - 1)])
4142
4557
  elif ch == 'h' and entries:
@@ -4149,6 +4564,8 @@ class Sidebar:
4149
4564
  self.toggle_fleet()
4150
4565
  elif ch == 'd': # plan W10 W7: the cursor lane's docs link in the footer
4151
4566
  self.show_docs_link(entries[min(self.cursor, len(entries) - 1)] if entries else None)
4567
+ elif ch == '@': # W15 L2: the cursor lane's handle in the footer, every address in the body
4568
+ self.show_addresses(entries[min(self.cursor, len(entries) - 1)] if entries else None)
4152
4569
  elif ch == 'P' and entries:
4153
4570
  entry = entries[min(self.cursor, len(entries) - 1)]
4154
4571
  self.start_promote(entry)
@@ -4161,7 +4578,7 @@ class Sidebar:
4161
4578
  self.release_focus()
4162
4579
  elif ch == '?':
4163
4580
  self.begin_action()
4164
- self.showing_keys = True
4581
+ self.sheet, self.showing_keys = 'keys', True
4165
4582
  self.dirty = True
4166
4583
  i += 1
4167
4584
 
@@ -4186,7 +4603,8 @@ class Sidebar:
4186
4603
  the keys. A read clears no footer message (cockpit v3 S6): it lasts MESSAGE_S (expire_message, on run()'s
4187
4604
  tick) or until the next action begins (begin_action). Until S6 the next read that proved the focus cleared it
4188
4605
  (S4 review, DEF-1815), so a cursor move wiped the reason a close failed (DEF-1822); before S4 every read did,
4189
- and Zellij's `ESC [ O` after each hand_off() wiped ` Closed sh` as soon as it was painted."""
4606
+ and Zellij's `ESC [ O` after each hand_off() wiped ` Closed sh` as soon as it was painted. run() hands the read
4607
+ over raw (bytes): take_reports decodes it, keeping a character the read cut for the next (BEY-6842)."""
4190
4608
  data = self.take_reports(data)
4191
4609
  self.poll_command()
4192
4610
  self.handle_input(data)
@@ -4196,6 +4614,7 @@ class Sidebar:
4196
4614
  saved = termios.tcgetattr(fd)
4197
4615
  try:
4198
4616
  tty.setraw(fd)
4617
+ self.on_tty = True # a read cut inside an escape sequence may get its rest (BEY-6842)
4199
4618
  sys.stdout.write(self.start_bytes())
4200
4619
  self.reload(force=True)
4201
4620
  self.start_cursor()
@@ -4239,7 +4658,9 @@ class Sidebar:
4239
4658
  if not data:
4240
4659
  time.sleep(1) # pty closed: let the wrapper loop decide
4241
4660
  return
4242
- self.on_read(data.decode('utf-8', 'replace'))
4661
+ self.on_read(data)
4662
+ elif self.expire_carry(): # no read came: a held lone Esc is the Esc key (BEY-6842)
4663
+ self.dirty = True
4243
4664
  finally:
4244
4665
  sys.stdout.write(self.stop_bytes())
4245
4666
  sys.stdout.flush()