@vibelord/lanes 1.7.1 → 1.7.3
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/package.json +1 -1
- package/payload/lanes/VERSION +1 -1
- package/payload/lanes/docs/ARCHITECTURE.md +32 -0
- package/payload/lanes/docs/RUNBOOK.md +8 -0
- package/payload/lanes/libexec/connection.py +123 -23
- package/payload/lanes/libexec/sidebar.py +107 -40
- package/payload/lanes/libexec/sidebar_status.py +31 -0
- package/payload/lanes/libexec/statusd.py +8 -0
- package/payload/lanes/libexec/view.sh +11 -1
- package/payload/lanes/libexec/visibility.py +44 -0
- package/payload/manifest.json +3 -3
package/package.json
CHANGED
package/payload/lanes/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.7.
|
|
1
|
+
1.7.3
|
|
@@ -33,6 +33,12 @@ for operations, the [runbook](RUNBOOK.md).
|
|
|
33
33
|
4. The status daemon observes tmux sessions and publishes status/health snapshots. Failed or timed-out
|
|
34
34
|
probes mean unknown; they do not prove a missing session. A bad terminal registry retains the last good board.
|
|
35
35
|
|
|
36
|
+
Sidebars use change-only `sidebar-status/<board>.json` projections (v1), published once per board by
|
|
37
|
+
`statusd.cycle`. Each contains that board's complete rows, unregistered/zmx listings, shared fleet facts,
|
|
38
|
+
cross-board attention statuses and fleet-admin address. Global heartbeat and other boards' process metadata
|
|
39
|
+
do not rewrite it. `status.json` remains canonical; a sidebar without a projection uses it and checks for
|
|
40
|
+
a projection on its existing 30 s version tick. Health freshness still comes from the separate health file.
|
|
41
|
+
|
|
36
42
|
Each workspace container that has the lane contract (`~/.lz/bin/lane`) also gets its own slice of the
|
|
37
43
|
observation as `~/.lz/status.json` (LNS-32, `statusd.write_container_status`), because nothing in a container
|
|
38
44
|
can read the host's `status.json`: `{v: 1, at, lanes{<id>: {state, agent?, attached?, viewers?, activity?, size?,
|
|
@@ -423,6 +429,32 @@ in `views/<device>/<ws>.<slot>.sidebar.state` and exits 75, and the wrapper re-e
|
|
|
423
429
|
directory at once. `view.sh` traps `USR2` and re-executes itself at its child's next natural exit, so an attached lane
|
|
424
430
|
is never cut.
|
|
425
431
|
|
|
432
|
+
## View visibility and terminal backpressure
|
|
433
|
+
|
|
434
|
+
The first board in each device owner's arranged workspace list observes Zellij tabs at most once per second.
|
|
435
|
+
Desktop observations run outside the keyboard loop, with one bounded request in flight. Its disposable
|
|
436
|
+
`views/<device>/visibility.json` (v1) records the union of all clients' focused tabs, with separate sidebar and
|
|
437
|
+
viewport sets: a mobile picker exposes only its sidebar. Observations expire after five seconds; missing,
|
|
438
|
+
malformed or stale observations keep viewers active. Visibility is an optimization, never lane authority.
|
|
439
|
+
An unknown focused tab name or schema publishes no new observation, so a renamed tab recovers when the previous
|
|
440
|
+
hint expires. A sidebar waits for its in-flight visibility query before a routine version self-swap.
|
|
441
|
+
|
|
442
|
+
A hidden sidebar skips rendering and health/status polling, except for the elected observer and a five-second
|
|
443
|
+
registry/profile refresh that can elect its successor. Keyboard input wakes it immediately. A viewport waits
|
|
444
|
+
silently in one process until ready, large enough and visible. Hiding it ends only its attach client (internal
|
|
445
|
+
exit 79); showing it reconnects the saved target. A lane switch while hidden restarts the silent waiter.
|
|
446
|
+
Native lane servers, agents and mappings remain owned by their
|
|
447
|
+
existing holders. Before first attach, the legacy ready and mobile first-display gates still apply.
|
|
448
|
+
|
|
449
|
+
`connection.py` multiplexes keyboard and display independently with nonblocking partial writes. The output
|
|
450
|
+
queue holds at most 1 MiB and the input queue at most one 4 KiB read. A full output queue pauses PTY reads while
|
|
451
|
+
keyboard forwarding continues; it never discards part of an ANSI stream. Cancellation remains responsive when
|
|
452
|
+
the display stops consuming bytes. Pre-connection mouse/keyboard input is discarded until the child answers.
|
|
453
|
+
Raw-mode changes use `TCSANOW`, so starting a waiter never waits for queued display output to drain. The
|
|
454
|
+
connecting spinner advances at most once every 150 ms even when stdout is continuously writable.
|
|
455
|
+
Regression coverage is in `test_connection.py`, `test_lanes_latency.py` and the existing sidebar budget gates
|
|
456
|
+
(BEY-6931, BEY-6932, BEY-6933).
|
|
457
|
+
|
|
426
458
|
## Views and panes
|
|
427
459
|
|
|
428
460
|
`lanes attach DEVICE` creates or reattaches the device's Zellij view. Layouts have one tab per workspace,
|
|
@@ -630,6 +630,14 @@ lanes studio-host re-key --yes after the owner revoked the Host: a new mac
|
|
|
630
630
|
|
|
631
631
|
## When the host is overloaded
|
|
632
632
|
|
|
633
|
+
The relay keeps keyboard forwarding independent of a blocked display, and current views idle while their tabs
|
|
634
|
+
have no viewer (BEY-6931/6932). A hidden tab reconnecting to its saved target is normal; the native agent keeps
|
|
635
|
+
running. `views/<device>/visibility.json` is only a five-second observer hint: uncertainty keeps viewers active.
|
|
636
|
+
For a sidebar that refreshes too often, inspect `sidebar-status/<board>.json`; `statusd` updates it only when
|
|
637
|
+
that board's rows, shared fleet facts or cross-board attention change (BEY-6933). Older deployments fall back
|
|
638
|
+
to `status.json`. These bounds reduce frontend load; exhausted workspace memory or scratch storage still needs
|
|
639
|
+
the Fleet owner's resource and retention fix. Do not restart agents or delete tmux sockets to treat latency.
|
|
640
|
+
|
|
633
641
|
2026-09-19: ceobox thrashed (load 400+ on 64 cores, swap full, memory pressure 68 %); `coder-dev-work` sat at 207 of
|
|
634
642
|
its 208 GiB, 95 GiB of that in its RAM-backed `/tmp`. **No lane was lost** — every pane kept its pid — but the
|
|
635
643
|
harness timed out on its own questions, reported "gone", and the client window closed itself. The rule since then:
|
|
@@ -11,14 +11,61 @@ import sys
|
|
|
11
11
|
import termios
|
|
12
12
|
import time
|
|
13
13
|
import tty
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
import visibility
|
|
14
17
|
|
|
15
18
|
RESET = b'\x1b[?1000l\x1b[?1002l\x1b[?1003l\x1b[?1005l\x1b[?1006l\x1b[?1015l\x1b[?1016l\x1b[?2004l\x1b[<u\x1b[0m'
|
|
19
|
+
OUTPUT_LIMIT = 1024 * 1024
|
|
20
|
+
HIDDEN = 79
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def view_visible():
|
|
24
|
+
state = os.environ.get('LANES_STATE', str(Path.home() / '.local/state/lanes'))
|
|
25
|
+
device, workspace = os.environ.get('LANES_DEVICE'), os.environ.get('LANES_WS')
|
|
26
|
+
return not (device and workspace) or visibility.visible(state, device, workspace)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def await_visible(device, workspace, slot='main', mobile=False):
|
|
30
|
+
"""One silent sleeper per viewport, including before its first real client."""
|
|
31
|
+
state = Path(os.environ.get('LANES_STATE', str(Path.home() / '.local/state/lanes')))
|
|
32
|
+
ready = state / 'clients' / (device + '.ready')
|
|
33
|
+
shown = state / 'views' / device / f'{workspace}.{slot}.shown'
|
|
34
|
+
saved = termios.tcgetattr(0)
|
|
35
|
+
handlers = {sig: signal.getsignal(sig) for sig in (signal.SIGTERM, signal.SIGHUP)}
|
|
36
|
+
def stop(sig, _frame):
|
|
37
|
+
raise SystemExit(128 + sig)
|
|
38
|
+
for sig in handlers:
|
|
39
|
+
signal.signal(sig, stop)
|
|
40
|
+
try:
|
|
41
|
+
tty.setraw(0, when=termios.TCSANOW)
|
|
42
|
+
while True:
|
|
43
|
+
try:
|
|
44
|
+
cols, rows = os.get_terminal_size(0)
|
|
45
|
+
except OSError:
|
|
46
|
+
cols, rows = 0, 0
|
|
47
|
+
if (ready.exists() and (not mobile or shown.exists())
|
|
48
|
+
and cols >= (20 if mobile else 40) and rows >= (4 if mobile else 8)
|
|
49
|
+
and visibility.visible(state, device, workspace)):
|
|
50
|
+
drain()
|
|
51
|
+
return
|
|
52
|
+
if select.select([0], [], [], 1)[0] and not os.read(0, 4096):
|
|
53
|
+
return
|
|
54
|
+
finally:
|
|
55
|
+
for sig, handler in handlers.items():
|
|
56
|
+
signal.signal(sig, handler)
|
|
57
|
+
drain()
|
|
58
|
+
termios.tcsetattr(0, termios.TCSANOW, saved)
|
|
16
59
|
|
|
17
60
|
|
|
18
61
|
def screen(title, frame):
|
|
62
|
+
os.write(1, screen_bytes(title, frame))
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def screen_bytes(title, frame):
|
|
19
66
|
title = ''.join(c for c in title if c.isprintable())[:100]
|
|
20
67
|
spinner = '|/-\\'[frame % 4]
|
|
21
|
-
|
|
68
|
+
return b'\x1b[H\x1b[2J\x1b[?25l' + f'\n {spinner} Syncing {title}…\n\n Connecting to the workspace\n'.encode()
|
|
22
69
|
|
|
23
70
|
|
|
24
71
|
def drain():
|
|
@@ -33,7 +80,7 @@ def wait_screen(title, seconds, preserve_screen=False):
|
|
|
33
80
|
for sig in handlers:
|
|
34
81
|
signal.signal(sig, stop)
|
|
35
82
|
try:
|
|
36
|
-
tty.setraw(0)
|
|
83
|
+
tty.setraw(0, when=termios.TCSANOW)
|
|
37
84
|
os.write(1, RESET)
|
|
38
85
|
drain()
|
|
39
86
|
end, frame = time.monotonic() + seconds, 0
|
|
@@ -59,7 +106,9 @@ def connect(title, command):
|
|
|
59
106
|
error_fd = os.dup(2)
|
|
60
107
|
child = None
|
|
61
108
|
stopping = False
|
|
109
|
+
hidden = False
|
|
62
110
|
master = None
|
|
111
|
+
output_flags = fcntl.fcntl(1, fcntl.F_GETFL)
|
|
63
112
|
|
|
64
113
|
def stop(_sig, _frame):
|
|
65
114
|
nonlocal stopping
|
|
@@ -77,10 +126,8 @@ def connect(title, command):
|
|
|
77
126
|
|
|
78
127
|
old_handlers = {sig: signal.getsignal(sig) for sig in (signal.SIGTERM, signal.SIGHUP, signal.SIGWINCH)}
|
|
79
128
|
try:
|
|
80
|
-
tty.setraw(0)
|
|
129
|
+
tty.setraw(0, when=termios.TCSANOW)
|
|
81
130
|
drain()
|
|
82
|
-
os.write(1, RESET)
|
|
83
|
-
screen(title, 0)
|
|
84
131
|
child, master = pty.fork()
|
|
85
132
|
if child == 0:
|
|
86
133
|
os.dup2(error_fd, 2) # diagnostics belong in the view's error file
|
|
@@ -96,9 +143,30 @@ def connect(title, command):
|
|
|
96
143
|
signal.signal(signal.SIGTERM, stop)
|
|
97
144
|
signal.signal(signal.SIGHUP, stop)
|
|
98
145
|
signal.signal(signal.SIGWINCH, resize)
|
|
146
|
+
os.set_blocking(master, False)
|
|
147
|
+
os.set_blocking(1, False)
|
|
148
|
+
outgoing = bytearray(RESET + screen_bytes(title, 0))
|
|
149
|
+
incoming = bytearray()
|
|
150
|
+
ended = False
|
|
99
151
|
connected, frame = False, 0
|
|
152
|
+
next_visibility = 0
|
|
153
|
+
next_frame = time.monotonic() + .15
|
|
100
154
|
while not stopping:
|
|
101
|
-
|
|
155
|
+
if time.monotonic() >= next_visibility:
|
|
156
|
+
next_visibility = time.monotonic() + 1
|
|
157
|
+
if not view_visible():
|
|
158
|
+
hidden = True
|
|
159
|
+
stop(None, None)
|
|
160
|
+
break
|
|
161
|
+
if ended and not outgoing:
|
|
162
|
+
break
|
|
163
|
+
# Output backpressure must never hold the keyboard. Bound both directions,
|
|
164
|
+
# retain partial writes and pause PTY reads instead of dropping ANSI bytes.
|
|
165
|
+
readers = ([] if incoming or ended else [0])
|
|
166
|
+
if not ended and len(outgoing) < OUTPUT_LIMIT:
|
|
167
|
+
readers.append(master)
|
|
168
|
+
writers = ([master] if incoming and not ended else []) + ([1] if outgoing else [])
|
|
169
|
+
ready, writable, _ = select.select(readers, writers, [], .15)
|
|
102
170
|
# Consume old mouse/keyboard input BEFORE accepting the first output.
|
|
103
171
|
if 0 in ready:
|
|
104
172
|
data = os.read(0, 4096)
|
|
@@ -106,38 +174,59 @@ def connect(title, command):
|
|
|
106
174
|
stop(None, None)
|
|
107
175
|
break
|
|
108
176
|
if connected:
|
|
109
|
-
|
|
177
|
+
incoming.extend(data)
|
|
178
|
+
if incoming and not ended:
|
|
179
|
+
try:
|
|
180
|
+
del incoming[:os.write(master, incoming)]
|
|
181
|
+
except BlockingIOError:
|
|
182
|
+
pass
|
|
183
|
+
except OSError as error:
|
|
184
|
+
if error.errno != errno.EIO:
|
|
185
|
+
raise
|
|
186
|
+
ended = True
|
|
110
187
|
if master in ready:
|
|
111
188
|
try:
|
|
112
|
-
data = os.read(master, 65536)
|
|
189
|
+
data = os.read(master, min(65536, OUTPUT_LIMIT - len(outgoing)))
|
|
190
|
+
except BlockingIOError:
|
|
191
|
+
data = None
|
|
113
192
|
except OSError as error:
|
|
114
193
|
if error.errno != errno.EIO:
|
|
115
194
|
raise
|
|
195
|
+
data = b''
|
|
196
|
+
if data == b'':
|
|
197
|
+
ended = True
|
|
198
|
+
elif data is not None:
|
|
199
|
+
if not connected:
|
|
200
|
+
drain()
|
|
201
|
+
outgoing = bytearray(RESET + b'\x1b[?25h\x1b[H\x1b[2J')
|
|
202
|
+
connected = True
|
|
203
|
+
outgoing.extend(data)
|
|
204
|
+
if outgoing and 1 in writable:
|
|
205
|
+
try:
|
|
206
|
+
del outgoing[:os.write(1, outgoing)]
|
|
207
|
+
except BlockingIOError:
|
|
208
|
+
pass
|
|
209
|
+
except OSError:
|
|
210
|
+
stop(None, None)
|
|
116
211
|
break
|
|
117
|
-
|
|
118
|
-
break
|
|
119
|
-
if not connected:
|
|
120
|
-
drain()
|
|
121
|
-
os.write(1, RESET + b'\x1b[?25h\x1b[H\x1b[2J')
|
|
122
|
-
connected = True
|
|
123
|
-
os.write(1, data)
|
|
124
|
-
if not connected:
|
|
212
|
+
if not connected and not outgoing and not ended and time.monotonic() >= next_frame:
|
|
125
213
|
frame += 1
|
|
126
|
-
|
|
214
|
+
outgoing.extend(screen_bytes(title, frame))
|
|
215
|
+
next_frame = time.monotonic() + .15
|
|
127
216
|
if stopping:
|
|
128
217
|
# This kills only the attach client group, never the persistent lane.
|
|
129
218
|
deadline = time.monotonic() + 2
|
|
130
219
|
while time.monotonic() < deadline:
|
|
131
220
|
pid, status = os.waitpid(child, os.WNOHANG)
|
|
132
221
|
if pid:
|
|
133
|
-
return -signal.SIGTERM
|
|
222
|
+
return HIDDEN if hidden else -signal.SIGTERM
|
|
134
223
|
time.sleep(.05)
|
|
135
224
|
try:
|
|
136
225
|
os.killpg(child, signal.SIGKILL)
|
|
137
226
|
except ProcessLookupError:
|
|
138
227
|
pass
|
|
139
228
|
_, status = os.waitpid(child, 0)
|
|
140
|
-
return -signal.SIGTERM if stopping else os.waitstatus_to_exitcode(status)
|
|
229
|
+
return (HIDDEN if hidden else -signal.SIGTERM) if stopping else os.waitstatus_to_exitcode(status)
|
|
141
230
|
finally:
|
|
142
231
|
for sig, handler in old_handlers.items():
|
|
143
232
|
signal.signal(sig, handler)
|
|
@@ -145,9 +234,14 @@ def connect(title, command):
|
|
|
145
234
|
os.close(master)
|
|
146
235
|
if error_fd >= 0:
|
|
147
236
|
os.close(error_fd)
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
237
|
+
try:
|
|
238
|
+
drain()
|
|
239
|
+
termios.tcsetattr(0, termios.TCSANOW, saved)
|
|
240
|
+
os.write(1, RESET + b'\x1b[?25h')
|
|
241
|
+
except (BlockingIOError, termios.error, BrokenPipeError):
|
|
242
|
+
pass # a blocked or closed display must not block cancellation
|
|
243
|
+
finally:
|
|
244
|
+
fcntl.fcntl(1, fcntl.F_SETFL, output_flags)
|
|
151
245
|
|
|
152
246
|
|
|
153
247
|
def main():
|
|
@@ -156,9 +250,15 @@ def main():
|
|
|
156
250
|
parser.add_argument('--wait', type=float)
|
|
157
251
|
parser.add_argument('--preserve-screen', action='store_true')
|
|
158
252
|
parser.add_argument('--retry', action='store_true')
|
|
253
|
+
parser.add_argument('--await-visible', nargs=2, metavar=('DEVICE', 'WORKSPACE'))
|
|
254
|
+
parser.add_argument('--slot', default='main')
|
|
255
|
+
parser.add_argument('--mobile', action='store_true')
|
|
159
256
|
parser.add_argument('command', nargs=argparse.REMAINDER)
|
|
160
257
|
args = parser.parse_args()
|
|
161
258
|
command = args.command[1:] if args.command[:1] == ['--'] else args.command
|
|
259
|
+
if args.await_visible:
|
|
260
|
+
await_visible(*args.await_visible, slot=args.slot, mobile=args.mobile)
|
|
261
|
+
return 0
|
|
162
262
|
if args.wait is not None:
|
|
163
263
|
wait_screen(args.title, args.wait, args.preserve_screen)
|
|
164
264
|
return 0
|
|
@@ -168,7 +268,7 @@ def main():
|
|
|
168
268
|
while True:
|
|
169
269
|
started = time.monotonic()
|
|
170
270
|
code = connect(args.title, command)
|
|
171
|
-
if not args.retry or code < 0:
|
|
271
|
+
if not args.retry or code < 0 or code == HIDDEN:
|
|
172
272
|
return max(0, code) if code < 0 else code
|
|
173
273
|
delay = 1 if time.monotonic() - started >= 30 else min(delay * 2, 15)
|
|
174
274
|
wait_screen(args.title, delay)
|
|
@@ -92,6 +92,7 @@ import unicodedata
|
|
|
92
92
|
|
|
93
93
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
94
94
|
import lanes_lib as L # noqa: E402
|
|
95
|
+
import visibility # noqa: E402
|
|
95
96
|
import agent_state as AS # noqa: E402
|
|
96
97
|
import session_actions as A # noqa: E402
|
|
97
98
|
import registrations as R # noqa: E402
|
|
@@ -1020,6 +1021,10 @@ class Sidebar:
|
|
|
1020
1021
|
meta = meta if isinstance(meta, dict) else {}
|
|
1021
1022
|
self.mobile = bool(meta.get('mobile'))
|
|
1022
1023
|
self.mobile_owner, self.mobile_titles, self.next_mobile_poll = False, {}, 0
|
|
1024
|
+
self.visibility_owner = False
|
|
1025
|
+
self.visibility_awake_until = 0
|
|
1026
|
+
self.visibility_thread = None
|
|
1027
|
+
self.hidden_reload_at = 0
|
|
1023
1028
|
try:
|
|
1024
1029
|
self.viewports = max(1, min(len(SLOTS), int(viewports)))
|
|
1025
1030
|
except ValueError:
|
|
@@ -1033,6 +1038,9 @@ class Sidebar:
|
|
|
1033
1038
|
self.focused, self.focus_reported, self.legend_until, self.legend_shown = False, False, 0.0, False
|
|
1034
1039
|
self.registry_path = os.path.join(STATE, 'registry.json')
|
|
1035
1040
|
self.status_path = os.path.join(STATE, 'status.json')
|
|
1041
|
+
self.projection_path = os.path.join(STATE, 'sidebar-status', workspace + '.json')
|
|
1042
|
+
if os.path.isfile(self.projection_path):
|
|
1043
|
+
self.status_path = self.projection_path
|
|
1036
1044
|
self.economy_path = os.path.join(STATE, 'economy.json') # the opt-in poller's projection (Task 11)
|
|
1037
1045
|
self.health_path = os.path.join(STATE, 'health')
|
|
1038
1046
|
self.health, self.health_stamp, self.banner = {}, None, ''
|
|
@@ -1136,6 +1144,8 @@ class Sidebar:
|
|
|
1136
1144
|
break
|
|
1137
1145
|
if stamp[1] != self.stamp[1] or force:
|
|
1138
1146
|
status = read_json(self.status_path) or {}
|
|
1147
|
+
if self.status_path == self.projection_path:
|
|
1148
|
+
status = self.with_canonical_fleet(status) # 1.7.3: the fleet block reads the canonical facts
|
|
1139
1149
|
self.status = status.get('lanes', {})
|
|
1140
1150
|
self.unregistered = (status.get('unregistered') or {}).get(self.workspace, [])
|
|
1141
1151
|
self.zmx = (status.get('zmx') or {}).get(self.workspace, [])
|
|
@@ -1175,6 +1185,7 @@ class Sidebar:
|
|
|
1175
1185
|
# hidden board has no tab to watch from.
|
|
1176
1186
|
first = users.arrange(self.workspaces, {'workspaces': self.profile_workspaces})
|
|
1177
1187
|
self.mobile_owner = self.mobile and bool(first) and first[0].get('id') == self.workspace
|
|
1188
|
+
self.visibility_owner = bool(first) and first[0].get('id') == self.workspace
|
|
1178
1189
|
if stamp[4] != self.stamp[4] or force:
|
|
1179
1190
|
# The seventh stat() of a tick at one viewport (spec §8): re-read only when the poller replaced the file.
|
|
1180
1191
|
# A missing file (no poller: the default) is {} — no economy tail on any row, the strip row yields.
|
|
@@ -1204,9 +1215,16 @@ class Sidebar:
|
|
|
1204
1215
|
installed tree's VERSION (one open, no stat; a checkout, whose current tree is its own, reads nothing) -> True
|
|
1205
1216
|
when it changed (one repaint: the footer's version note and the `?` row). Every other tick costs a clock read."""
|
|
1206
1217
|
now = time.monotonic() if now is None else now
|
|
1207
|
-
|
|
1218
|
+
# BEY-6972: subtraction can round an exact computed deadline back below
|
|
1219
|
+
# the interval when the addition crosses a float exponent boundary.
|
|
1220
|
+
if now < self.version_at + VERSION_RECHECK_S:
|
|
1208
1221
|
return False
|
|
1209
1222
|
self.version_at = now
|
|
1223
|
+
status_path = (self.projection_path if os.path.isfile(self.projection_path)
|
|
1224
|
+
else os.path.join(STATE, 'status.json'))
|
|
1225
|
+
if status_path != self.status_path:
|
|
1226
|
+
self.status_path = status_path
|
|
1227
|
+
self.stamp = self.stamp[:1] + (0,) + self.stamp[2:]
|
|
1210
1228
|
url = site_dashboard() # W11: the dashboard link follows site.conf within 30 s
|
|
1211
1229
|
if url != self.fleet_url:
|
|
1212
1230
|
self.fleet_url, self.dirty = url, True
|
|
@@ -1231,7 +1249,8 @@ class Sidebar:
|
|
|
1231
1249
|
so swapping first would only repaint once for nothing."""
|
|
1232
1250
|
return not (self.prompt or self.filtering or self.armed or self.registration or self.showing_keys
|
|
1233
1251
|
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
|
|
1252
|
+
or self.upload or self.profile_marks or self.last_open or time.monotonic() < self.rebuild_until
|
|
1253
|
+
or (self.visibility_thread is not None and self.visibility_thread.is_alive()))
|
|
1235
1254
|
|
|
1236
1255
|
def swap_due(self):
|
|
1237
1256
|
"""reload()'s tick: the installed version differs from this tree's, a re-exec would run it (`swappable`), and
|
|
@@ -1448,30 +1467,43 @@ class Sidebar:
|
|
|
1448
1467
|
return data
|
|
1449
1468
|
|
|
1450
1469
|
def poll_mobile_view(self):
|
|
1451
|
-
"""One sidebar observes
|
|
1470
|
+
"""One sidebar observes this device's clients and tabs, at most once a second.
|
|
1452
1471
|
|
|
1453
1472
|
Safari bypasses `lanes attach`, which normally sets clients/<device>.ready. Hidden mobile tabs have a
|
|
1454
1473
|
plausible placeholder size, so they also need a per-workspace first-display gate before attaching tmux.
|
|
1455
1474
|
"""
|
|
1456
|
-
if not self.
|
|
1475
|
+
if not self.visibility_owner or time.monotonic() < self.next_mobile_poll:
|
|
1476
|
+
return
|
|
1477
|
+
if self.visibility_thread is not None and self.visibility_thread.is_alive():
|
|
1457
1478
|
return
|
|
1458
1479
|
self.next_mobile_poll = time.monotonic() + 1
|
|
1480
|
+
if self.mobile:
|
|
1481
|
+
self.observe_visibility()
|
|
1482
|
+
else:
|
|
1483
|
+
# A slow Zellij CLI must not hold the desktop's keyboard loop. There is
|
|
1484
|
+
# only one bounded observation in flight, even on a stalled frontend.
|
|
1485
|
+
self.visibility_thread = threading.Thread(target=self.observe_visibility, daemon=True)
|
|
1486
|
+
self.visibility_thread.start()
|
|
1487
|
+
|
|
1488
|
+
def observe_visibility(self):
|
|
1459
1489
|
command = [os.environ.get('LANES_ZELLIJ') or 'zellij', '-s', self.device, 'action']
|
|
1460
1490
|
ready = os.path.join(STATE, 'clients', self.device + '.ready')
|
|
1461
1491
|
if not os.path.exists(ready):
|
|
1462
1492
|
rc, out, _err = L.run_bounded(command + ['list-clients'], 2)
|
|
1463
1493
|
if rc != 0 or not any(re.match(r'^\s*\d+\s', line) for line in out.splitlines()):
|
|
1494
|
+
if rc == 0:
|
|
1495
|
+
L.atomic_write(Path(self.view_dir) / 'visibility.json', json.dumps(visibility.snapshot([], {}, self.mobile)))
|
|
1464
1496
|
return
|
|
1465
1497
|
L.atomic_write(Path(ready), f'{time.time()}\n')
|
|
1466
1498
|
rc, out, _err = L.run_bounded(command + ['list-tabs', '-j'], 2)
|
|
1467
1499
|
if rc != 0:
|
|
1468
1500
|
return
|
|
1469
1501
|
try:
|
|
1470
|
-
|
|
1471
|
-
except (ValueError, KeyError,
|
|
1502
|
+
observed = visibility.snapshot(json.loads(out), self.mobile_titles, self.mobile)
|
|
1503
|
+
except (ValueError, KeyError, TypeError):
|
|
1472
1504
|
return
|
|
1473
|
-
|
|
1474
|
-
|
|
1505
|
+
L.atomic_write(Path(self.view_dir) / 'visibility.json', json.dumps(observed))
|
|
1506
|
+
for workspace in observed['viewports']:
|
|
1475
1507
|
shown = Path(self.view_dir) / f'{workspace}.main.shown'
|
|
1476
1508
|
if not shown.exists():
|
|
1477
1509
|
L.atomic_write(shown, f'{time.time()}\n')
|
|
@@ -1795,6 +1827,23 @@ class Sidebar:
|
|
|
1795
1827
|
return lead_painted + sep_painted.join(painted), lead + sep_plain.join(plain)
|
|
1796
1828
|
|
|
1797
1829
|
# ---------------------------------------------------------- the fleet block (W11, spec 2026-10-11 §3)
|
|
1830
|
+
def with_canonical_fleet(self, status):
|
|
1831
|
+
"""The per-board projection (1.7.2, `sidebar-status/<board>.json`) is written inside statusd's cycle BEFORE a
|
|
1832
|
+
site hook adopts a federated guest's pulse into status.json (rd-control, 2026-10-29: the fleet block vanished
|
|
1833
|
+
with 1.7.2 — the projection carried no `throttle`, status.json did). The block's two objects therefore come
|
|
1834
|
+
from the canonical status.json whenever the projection lacks one or carries an older sample (`at`): one extra
|
|
1835
|
+
read of status.json per projection change, never per idle tick. A missing status.json changes nothing."""
|
|
1836
|
+
if not isinstance(status, dict):
|
|
1837
|
+
return status
|
|
1838
|
+
canonical = read_json(os.path.join(STATE, 'status.json')) or {}
|
|
1839
|
+
for key in ('fleet', 'throttle'):
|
|
1840
|
+
theirs, ours = canonical.get(key), status.get(key)
|
|
1841
|
+
if not isinstance(theirs, dict):
|
|
1842
|
+
continue
|
|
1843
|
+
if not isinstance(ours, dict) or (finite(theirs.get('at')) or 0) > (finite(ours.get('at')) or 0):
|
|
1844
|
+
status[key] = theirs
|
|
1845
|
+
return status
|
|
1846
|
+
|
|
1798
1847
|
def take_fleet(self, status):
|
|
1799
1848
|
"""reload()'s status.json read: its `fleet` and `throttle` objects (fleet_doc) and, once per new pulse sample
|
|
1800
1849
|
(`throttle.at` moved), the pools' summed `upstream_429_total` for `429 +N` (surge). Fresh values only."""
|
|
@@ -4605,6 +4654,7 @@ class Sidebar:
|
|
|
4605
4654
|
(S4 review, DEF-1815), so a cursor move wiped the reason a close failed (DEF-1822); before S4 every read did,
|
|
4606
4655
|
and Zellij's `ESC [ O` after each hand_off() wiped ` Closed sh` as soon as it was painted. run() hands the read
|
|
4607
4656
|
over raw (bytes): take_reports decodes it, keeping a character the read cut for the next (BEY-6842)."""
|
|
4657
|
+
self.visibility_awake_until = time.monotonic() + visibility.TTL
|
|
4608
4658
|
data = self.take_reports(data)
|
|
4609
4659
|
self.poll_command()
|
|
4610
4660
|
self.handle_input(data)
|
|
@@ -4619,45 +4669,62 @@ class Sidebar:
|
|
|
4619
4669
|
self.reload(force=True)
|
|
4620
4670
|
self.start_cursor()
|
|
4621
4671
|
last_size = None
|
|
4672
|
+
was_visible = True
|
|
4622
4673
|
while True:
|
|
4623
|
-
|
|
4674
|
+
# The elected observer remains cheap and awake even when its own tab is hidden.
|
|
4675
|
+
if self.visibility_owner:
|
|
4676
|
+
self.reload()
|
|
4624
4677
|
self.poll_mobile_view()
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
if
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
self.
|
|
4649
|
-
|
|
4650
|
-
self.
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4678
|
+
shown = (time.monotonic() < self.visibility_awake_until
|
|
4679
|
+
or visibility.visible(STATE, self.device, self.workspace, 'sidebars'))
|
|
4680
|
+
if not shown:
|
|
4681
|
+
if time.monotonic() >= self.hidden_reload_at:
|
|
4682
|
+
self.hidden_reload_at = time.monotonic() + visibility.TTL
|
|
4683
|
+
self.reload() # profile/registry changes can elect a new observer
|
|
4684
|
+
self.finish_actions()
|
|
4685
|
+
self.poll_profile()
|
|
4686
|
+
was_visible = False
|
|
4687
|
+
else:
|
|
4688
|
+
self.reload(force=not was_visible)
|
|
4689
|
+
was_visible = True
|
|
4690
|
+
# The worker's answers (cockpit v3 S9): a drain, never a wait — taken after reload(), so an answer is
|
|
4691
|
+
# applied to the listing it changes, and before expire_pending(), which holds a `P` whose write is out.
|
|
4692
|
+
if self.finish_actions():
|
|
4693
|
+
self.dirty = True
|
|
4694
|
+
try:
|
|
4695
|
+
size = tuple(os.get_terminal_size(sys.stdout.fileno()))
|
|
4696
|
+
except OSError:
|
|
4697
|
+
size = None
|
|
4698
|
+
if size != last_size:
|
|
4699
|
+
last_size, self.dirty = size, True
|
|
4700
|
+
self.poll_upload()
|
|
4701
|
+
self.poll_health()
|
|
4702
|
+
self.poll_update()
|
|
4703
|
+
self.poll_economy()
|
|
4704
|
+
self.poll_fleet() # W11: the fleet block's facts turning stale (no I/O)
|
|
4705
|
+
# An upload in flight no longer forces a frame: poll_upload() dirties on progress and on the end.
|
|
4706
|
+
if self.armed or (self.upload_note and time.time() - self.upload_note_at < 9):
|
|
4707
|
+
self.dirty = True
|
|
4708
|
+
if self.legend_stale(): # the no-report focus legend ran out (cockpit v3 S4)
|
|
4709
|
+
self.dirty = True
|
|
4710
|
+
if self.expire_message(): # the last message is MESSAGE_S old (cockpit v3 S6)
|
|
4711
|
+
self.dirty = True
|
|
4712
|
+
if self.expire_undo(): # the undo offer is UNDO_S old (cockpit v3 S7)
|
|
4713
|
+
self.dirty = True
|
|
4714
|
+
if self.expire_pending(): # a `P` the registry has not listed PENDING_S on (cockpit v3 S8)
|
|
4715
|
+
self.dirty = True
|
|
4716
|
+
self.expire_theme() # the OSC 11 grace ran out: resolve and publish, frame or not (DEF-1775)
|
|
4717
|
+
self.poll_profile() # a mark the owner's busy profile dropped, every PROFILE_RETRY_S (R3)
|
|
4718
|
+
if self.dirty:
|
|
4719
|
+
self.render()
|
|
4720
|
+
ready, _, _ = select.select([fd], [], [], self.tick_timeout() if shown else 1)
|
|
4656
4721
|
if ready:
|
|
4657
4722
|
data = os.read(fd, 4096)
|
|
4658
4723
|
if not data:
|
|
4659
4724
|
time.sleep(1) # pty closed: let the wrapper loop decide
|
|
4660
4725
|
return
|
|
4726
|
+
if not shown:
|
|
4727
|
+
self.reload(force=True)
|
|
4661
4728
|
self.on_read(data)
|
|
4662
4729
|
elif self.expire_carry(): # no read came: a held lone Esc is the Esc key (BEY-6842)
|
|
4663
4730
|
self.dirty = True
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""Small, change-only sidebar projections of the canonical host status."""
|
|
2
|
+
import json
|
|
3
|
+
import re
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def projections(registry, payload):
|
|
7
|
+
rows = payload.get('lanes') or {}
|
|
8
|
+
shared = {}
|
|
9
|
+
for key, row in rows.items():
|
|
10
|
+
summary = {}
|
|
11
|
+
if not isinstance(row, dict):
|
|
12
|
+
continue
|
|
13
|
+
agent = row.get('agent') or {}
|
|
14
|
+
if isinstance(agent, dict) and agent.get('status') in ('needs_input', 'needs_approval'):
|
|
15
|
+
summary['agent'] = {'status': agent['status']}
|
|
16
|
+
if row.get('role') in ('fleet-admin', 'fleet_admin'):
|
|
17
|
+
summary.update({field: row[field] for field in ('role', 'address') if field in row})
|
|
18
|
+
if summary:
|
|
19
|
+
shared[key] = summary
|
|
20
|
+
for board in (registry or {}).get('workspaces') or []:
|
|
21
|
+
name = board.get('id', '')
|
|
22
|
+
if not re.fullmatch(r'[A-Za-z0-9_.-]+', name) or name in ('.', '..'):
|
|
23
|
+
continue
|
|
24
|
+
ghosts = (payload.get('unregistered') or {}).get(name, [])
|
|
25
|
+
zmx = (payload.get('zmx') or {}).get(name, [])
|
|
26
|
+
ids = {entry.get('id') for entry in list(board.get('lanes') or []) + ghosts + zmx}
|
|
27
|
+
own = {key: row for key, row in rows.items() if key in ids or key.startswith(name + '--')}
|
|
28
|
+
result = {'v': 1, 'lanes': dict(shared, **own),
|
|
29
|
+
'unregistered': {name: ghosts}, 'zmx': {name: zmx}}
|
|
30
|
+
result.update({key: payload[key] for key in ('fleet', 'throttle', 'web_origin') if key in payload})
|
|
31
|
+
yield name, json.dumps(result, sort_keys=True) + '\n'
|
|
@@ -2269,6 +2269,14 @@ def cycle(ctx, reconcile=True):
|
|
|
2269
2269
|
if payload is not None:
|
|
2270
2270
|
payload = with_fleet(ctx, payload, health, sample, due, started)
|
|
2271
2271
|
ctx['payload'] = payload
|
|
2272
|
+
try:
|
|
2273
|
+
# Derived files omit global heartbeat and unrelated boards' process metadata.
|
|
2274
|
+
# One publisher, independent of the number of devices viewing a board.
|
|
2275
|
+
from sidebar_status import projections
|
|
2276
|
+
for board, text in projections(ctx.get('registry'), payload):
|
|
2277
|
+
L.atomic_write_if_changed(L.STATE / 'sidebar-status' / (board + '.json'), text)
|
|
2278
|
+
except Exception as error:
|
|
2279
|
+
log('sidebar status', error)
|
|
2272
2280
|
# Rewrite only on change (plus a heartbeat) so sidebars do not repaint for nothing. `health` changes every
|
|
2273
2281
|
# cycle and is therefore not part of the comparison; nor is the fleet's sample time (`compared`).
|
|
2274
2282
|
if (ctx['published'] is None or compared(payload) != compared(ctx['published'])
|
|
@@ -26,7 +26,7 @@ mkdir -p "$dir"
|
|
|
26
26
|
target_file=$dir/$ws.$slot.target
|
|
27
27
|
err_file=$dir/$ws.$slot.err
|
|
28
28
|
echo $$ > "$dir/$ws.$slot.pid"
|
|
29
|
-
export LANES_STATE="$state" LANES_WS="$ws"
|
|
29
|
+
export LANES_STATE="$state" LANES_WS="$ws" LANES_DEVICE="$device"
|
|
30
30
|
|
|
31
31
|
child=
|
|
32
32
|
switching=0
|
|
@@ -138,6 +138,15 @@ health_hint() {
|
|
|
138
138
|
|
|
139
139
|
delay=1
|
|
140
140
|
while :; do
|
|
141
|
+
switching=0
|
|
142
|
+
# Stay in one silent process while hidden or unattached. The visibility observer
|
|
143
|
+
# is shared by this device's sidebars; no CLI polling or repaint loop per pane.
|
|
144
|
+
if [ "$mobile" = 1 ]; then
|
|
145
|
+
run python3 "$repo/libexec/connection.py" --await-visible "$device" "$ws" --slot "$slot" --mobile || :
|
|
146
|
+
else
|
|
147
|
+
run python3 "$repo/libexec/connection.py" --await-visible "$device" "$ws" --slot "$slot" || :
|
|
148
|
+
fi
|
|
149
|
+
if [ "$switching" = 1 ]; then delay=1; continue; fi
|
|
141
150
|
# A background-created zellij session has no real size yet: idle until a client has attached once.
|
|
142
151
|
while [ ! -e "$state/clients/$device.ready" ] || { [ "$mobile" = 1 ] && [ ! -e "$dir/$ws.$slot.shown" ]; }; do
|
|
143
152
|
status_screen "$ws" 'waiting for the first client…' ''
|
|
@@ -184,6 +193,7 @@ while :; do
|
|
|
184
193
|
exec) run python3 "$repo/libexec/connection.py" --title "${title:-$lane}" -- "$repo/holders/exec.sh" "$f2" "$f3" "$f4" || : ;;
|
|
185
194
|
*) rc=64 ;;
|
|
186
195
|
esac
|
|
196
|
+
if [ "$rc" = 79 ]; then delay=1; continue; fi
|
|
187
197
|
if [ "$switching" = 1 ]; then delay=1; continue; fi
|
|
188
198
|
|
|
189
199
|
# The holder's client has just left its own last word on the screen (tmux: "[terminated]", "[lost server]"), which
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Disposable, device-wide tab observations; uncertainty always keeps a viewer alive."""
|
|
2
|
+
import json
|
|
3
|
+
import time
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
TTL = 5
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def snapshot(tabs, titles, mobile, now=None):
|
|
10
|
+
"""Union all clients' tabs. A mobile picker contains no native viewport."""
|
|
11
|
+
if not isinstance(tabs, list) or any(not isinstance(tab, dict) or not isinstance(tab.get('name'), str)
|
|
12
|
+
or not isinstance(tab.get('active'), bool) for tab in tabs):
|
|
13
|
+
raise ValueError('invalid tab observation')
|
|
14
|
+
sidebars, viewports = set(), set()
|
|
15
|
+
for tab in tabs:
|
|
16
|
+
if not (tab.get('active') is True or tab.get('other_focused_clients')):
|
|
17
|
+
continue
|
|
18
|
+
title = tab['name']
|
|
19
|
+
picker = mobile and title.endswith(' ☰')
|
|
20
|
+
workspace = titles.get(title[:-2] if picker else title)
|
|
21
|
+
if not workspace:
|
|
22
|
+
# A renamed/new tab is uncertainty, not proof all known boards are hidden.
|
|
23
|
+
# Keep the last observation only until its short TTL expires.
|
|
24
|
+
raise ValueError('focused tab has no workspace identity')
|
|
25
|
+
if workspace:
|
|
26
|
+
if not mobile or picker:
|
|
27
|
+
sidebars.add(workspace)
|
|
28
|
+
if not picker:
|
|
29
|
+
viewports.add(workspace)
|
|
30
|
+
return {'v': 1, 'at': time.time() if now is None else now,
|
|
31
|
+
'sidebars': sorted(sidebars), 'viewports': sorted(viewports)}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def visible(state, device, workspace, kind='viewports', now=None):
|
|
35
|
+
try:
|
|
36
|
+
value = json.loads((Path(state) / 'views' / device / 'visibility.json').read_text())
|
|
37
|
+
age = (time.time() if now is None else now) - value['at']
|
|
38
|
+
if value.get('v') != 1 or not 0 <= age <= TTL or not isinstance(value[kind], list):
|
|
39
|
+
return True
|
|
40
|
+
if any(not isinstance(item, str) for item in value[kind]):
|
|
41
|
+
return True
|
|
42
|
+
return workspace in value[kind]
|
|
43
|
+
except (OSError, ValueError, KeyError, TypeError, AttributeError):
|
|
44
|
+
return True
|
package/payload/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibelord/lanes",
|
|
3
|
-
"version": "1.7.
|
|
4
|
-
"commit": "
|
|
5
|
-
"digest": "sha256:
|
|
3
|
+
"version": "1.7.3",
|
|
4
|
+
"commit": "34aa7b11da0788bac2b780e0f5906c178e6a085c",
|
|
5
|
+
"digest": "sha256:e49343f97567090ba8290b98443345239cc8a04993e87cc72361c72acf31d8a4",
|
|
6
6
|
"executables": [
|
|
7
7
|
"bin/lanes",
|
|
8
8
|
"client/ghostty/lanes-themed-window",
|