@vibelord/lanes 1.7.0 → 1.7.2
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/bin/lanes +32 -1
- package/payload/lanes/docs/ARCHITECTURE.md +32 -0
- package/payload/lanes/docs/RUNBOOK.md +15 -0
- package/payload/lanes/libexec/connection.py +123 -23
- package/payload/lanes/libexec/sidebar.py +88 -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.2
|
package/payload/lanes/bin/lanes
CHANGED
|
@@ -5434,6 +5434,9 @@ def cmd_doctor(_args):
|
|
|
5434
5434
|
if registry:
|
|
5435
5435
|
errors = [(w['id'], e) for w in registry['workspaces'] for e in w['errors']]
|
|
5436
5436
|
check(not errors, 'registry clean', '; '.join(f'{w}: {e}' for w, e in errors))
|
|
5437
|
+
hook = site_hook_old()
|
|
5438
|
+
if hook:
|
|
5439
|
+
print(f'⚠ {hook} (Linear BEY-6912)')
|
|
5437
5440
|
# Stale registry check: any terminals.json newer than the last sync? A lane's `source` is the container's
|
|
5438
5441
|
# spelling; doctor runs on the host, so it stats the file under the container's home volume.
|
|
5439
5442
|
sys.path.insert(0, str(L.REPO / 'libexec'))
|
|
@@ -5899,11 +5902,39 @@ def cmd_names(args):
|
|
|
5899
5902
|
return 1 if counts.get('failed') else 0
|
|
5900
5903
|
|
|
5901
5904
|
|
|
5905
|
+
def site_hook_old():
|
|
5906
|
+
"""A site hook that replaced `lanes_lib.build_registry` with a callable written for a Lanes before 1.7.0 (no
|
|
5907
|
+
`strict`; rd-control's federation hook, Linear BEY-6912) -> one line saying so, else None. Read from the callable's
|
|
5908
|
+
signature only: a `**kwargs` wrapper that forwards to the real function counts as current."""
|
|
5909
|
+
import inspect
|
|
5910
|
+
try:
|
|
5911
|
+
params = inspect.signature(L.build_registry).parameters
|
|
5912
|
+
except (TypeError, ValueError):
|
|
5913
|
+
return None
|
|
5914
|
+
if 'strict' in params or any(p.kind is inspect.Parameter.VAR_KEYWORD for p in params.values()):
|
|
5915
|
+
return None
|
|
5916
|
+
who = getattr(L.build_registry, '__qualname__', None) or 'something'
|
|
5917
|
+
return (f'{who} replaces lanes_lib.build_registry without `strict` (a site hook written for a Lanes before 1.7.0): '
|
|
5918
|
+
'two lanes on one address refuse instead of being listed')
|
|
5919
|
+
|
|
5920
|
+
|
|
5921
|
+
def build_site_registry(previous, strict=True):
|
|
5922
|
+
"""`L.build_registry(previous, strict=…)`, or the older call when a site hook replaced it (site_hook_old): then a
|
|
5923
|
+
`strict=False` caller is told on stderr once, and a duplicate address raises as it did before 1.7.0 — the verb
|
|
5924
|
+
still runs instead of dying on a TypeError (BEY-6912)."""
|
|
5925
|
+
why = site_hook_old()
|
|
5926
|
+
if why is None:
|
|
5927
|
+
return L.build_registry(previous, strict=strict)
|
|
5928
|
+
if not strict:
|
|
5929
|
+
print(f'lanes: {why} (Linear BEY-6912)', file=sys.stderr)
|
|
5930
|
+
return L.build_registry(previous)
|
|
5931
|
+
|
|
5932
|
+
|
|
5902
5933
|
def site_check():
|
|
5903
5934
|
"""`lanes sync`'s validation without publishing: the registry built from the site as it is now (two lanes on one
|
|
5904
5935
|
address left in place, `strict=False`) -> (registry, None), or (None, why) when the site cannot be built at all."""
|
|
5905
5936
|
try:
|
|
5906
|
-
return
|
|
5937
|
+
return build_site_registry(L.read_json(L.STATE / 'registry.json'), strict=False), None
|
|
5907
5938
|
except (L.LanesError, OSError, ValueError, KeyError) as error:
|
|
5908
5939
|
return None, str(error)
|
|
5909
5940
|
|
|
@@ -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:
|
|
@@ -2956,6 +2964,13 @@ LANES_MEASURE_CODEX=1 python3 -c 'import sys; sys.path.insert(0, "lanes/tests/un
|
|
|
2956
2964
|
|
|
2957
2965
|
then run the unit suite in a managed job; a Codex that renamed a method or a field reds the contract's live leg.
|
|
2958
2966
|
|
|
2967
|
+
**A site hook written before 1.7.0 (BEY-6912).** A site that replaces `lanes_lib.build_registry` (rd-control's
|
|
2968
|
+
federation hook does, to fold the guests' lanes in) with a callable that has no `strict` parameter would have made
|
|
2969
|
+
`lanes migrate addresses` and `lanes doctor` die on a `TypeError`. Since 1.7.1 `site_check` reads the callable's
|
|
2970
|
+
signature: without `strict` (and without `**kwargs`) it makes the older call and says so once on stderr — two lanes
|
|
2971
|
+
on one address then refuse, as before 1.7.0, instead of being listed — and `lanes doctor` prints the same as a `⚠`.
|
|
2972
|
+
The hook's fix is to forward keyword arguments (`def build_registry(previous=None, **kw)`), after which nothing is said.
|
|
2973
|
+
|
|
2959
2974
|
## Safety rules baked into the code (do not remove)
|
|
2960
2975
|
|
|
2961
2976
|
- tmux is always called with `-N` (`attach-session`, `new-session` and `start-server` on a missing socket start
|
|
@@ -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, ''
|
|
@@ -1175,6 +1183,7 @@ class Sidebar:
|
|
|
1175
1183
|
# hidden board has no tab to watch from.
|
|
1176
1184
|
first = users.arrange(self.workspaces, {'workspaces': self.profile_workspaces})
|
|
1177
1185
|
self.mobile_owner = self.mobile and bool(first) and first[0].get('id') == self.workspace
|
|
1186
|
+
self.visibility_owner = bool(first) and first[0].get('id') == self.workspace
|
|
1178
1187
|
if stamp[4] != self.stamp[4] or force:
|
|
1179
1188
|
# The seventh stat() of a tick at one viewport (spec §8): re-read only when the poller replaced the file.
|
|
1180
1189
|
# A missing file (no poller: the default) is {} — no economy tail on any row, the strip row yields.
|
|
@@ -1204,9 +1213,16 @@ class Sidebar:
|
|
|
1204
1213
|
installed tree's VERSION (one open, no stat; a checkout, whose current tree is its own, reads nothing) -> True
|
|
1205
1214
|
when it changed (one repaint: the footer's version note and the `?` row). Every other tick costs a clock read."""
|
|
1206
1215
|
now = time.monotonic() if now is None else now
|
|
1207
|
-
|
|
1216
|
+
# BEY-6972: subtraction can round an exact computed deadline back below
|
|
1217
|
+
# the interval when the addition crosses a float exponent boundary.
|
|
1218
|
+
if now < self.version_at + VERSION_RECHECK_S:
|
|
1208
1219
|
return False
|
|
1209
1220
|
self.version_at = now
|
|
1221
|
+
status_path = (self.projection_path if os.path.isfile(self.projection_path)
|
|
1222
|
+
else os.path.join(STATE, 'status.json'))
|
|
1223
|
+
if status_path != self.status_path:
|
|
1224
|
+
self.status_path = status_path
|
|
1225
|
+
self.stamp = self.stamp[:1] + (0,) + self.stamp[2:]
|
|
1210
1226
|
url = site_dashboard() # W11: the dashboard link follows site.conf within 30 s
|
|
1211
1227
|
if url != self.fleet_url:
|
|
1212
1228
|
self.fleet_url, self.dirty = url, True
|
|
@@ -1231,7 +1247,8 @@ class Sidebar:
|
|
|
1231
1247
|
so swapping first would only repaint once for nothing."""
|
|
1232
1248
|
return not (self.prompt or self.filtering or self.armed or self.registration or self.showing_keys
|
|
1233
1249
|
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
|
|
1250
|
+
or self.upload or self.profile_marks or self.last_open or time.monotonic() < self.rebuild_until
|
|
1251
|
+
or (self.visibility_thread is not None and self.visibility_thread.is_alive()))
|
|
1235
1252
|
|
|
1236
1253
|
def swap_due(self):
|
|
1237
1254
|
"""reload()'s tick: the installed version differs from this tree's, a re-exec would run it (`swappable`), and
|
|
@@ -1448,30 +1465,43 @@ class Sidebar:
|
|
|
1448
1465
|
return data
|
|
1449
1466
|
|
|
1450
1467
|
def poll_mobile_view(self):
|
|
1451
|
-
"""One sidebar observes
|
|
1468
|
+
"""One sidebar observes this device's clients and tabs, at most once a second.
|
|
1452
1469
|
|
|
1453
1470
|
Safari bypasses `lanes attach`, which normally sets clients/<device>.ready. Hidden mobile tabs have a
|
|
1454
1471
|
plausible placeholder size, so they also need a per-workspace first-display gate before attaching tmux.
|
|
1455
1472
|
"""
|
|
1456
|
-
if not self.
|
|
1473
|
+
if not self.visibility_owner or time.monotonic() < self.next_mobile_poll:
|
|
1474
|
+
return
|
|
1475
|
+
if self.visibility_thread is not None and self.visibility_thread.is_alive():
|
|
1457
1476
|
return
|
|
1458
1477
|
self.next_mobile_poll = time.monotonic() + 1
|
|
1478
|
+
if self.mobile:
|
|
1479
|
+
self.observe_visibility()
|
|
1480
|
+
else:
|
|
1481
|
+
# A slow Zellij CLI must not hold the desktop's keyboard loop. There is
|
|
1482
|
+
# only one bounded observation in flight, even on a stalled frontend.
|
|
1483
|
+
self.visibility_thread = threading.Thread(target=self.observe_visibility, daemon=True)
|
|
1484
|
+
self.visibility_thread.start()
|
|
1485
|
+
|
|
1486
|
+
def observe_visibility(self):
|
|
1459
1487
|
command = [os.environ.get('LANES_ZELLIJ') or 'zellij', '-s', self.device, 'action']
|
|
1460
1488
|
ready = os.path.join(STATE, 'clients', self.device + '.ready')
|
|
1461
1489
|
if not os.path.exists(ready):
|
|
1462
1490
|
rc, out, _err = L.run_bounded(command + ['list-clients'], 2)
|
|
1463
1491
|
if rc != 0 or not any(re.match(r'^\s*\d+\s', line) for line in out.splitlines()):
|
|
1492
|
+
if rc == 0:
|
|
1493
|
+
L.atomic_write(Path(self.view_dir) / 'visibility.json', json.dumps(visibility.snapshot([], {}, self.mobile)))
|
|
1464
1494
|
return
|
|
1465
1495
|
L.atomic_write(Path(ready), f'{time.time()}\n')
|
|
1466
1496
|
rc, out, _err = L.run_bounded(command + ['list-tabs', '-j'], 2)
|
|
1467
1497
|
if rc != 0:
|
|
1468
1498
|
return
|
|
1469
1499
|
try:
|
|
1470
|
-
|
|
1471
|
-
except (ValueError, KeyError,
|
|
1500
|
+
observed = visibility.snapshot(json.loads(out), self.mobile_titles, self.mobile)
|
|
1501
|
+
except (ValueError, KeyError, TypeError):
|
|
1472
1502
|
return
|
|
1473
|
-
|
|
1474
|
-
|
|
1503
|
+
L.atomic_write(Path(self.view_dir) / 'visibility.json', json.dumps(observed))
|
|
1504
|
+
for workspace in observed['viewports']:
|
|
1475
1505
|
shown = Path(self.view_dir) / f'{workspace}.main.shown'
|
|
1476
1506
|
if not shown.exists():
|
|
1477
1507
|
L.atomic_write(shown, f'{time.time()}\n')
|
|
@@ -4605,6 +4635,7 @@ class Sidebar:
|
|
|
4605
4635
|
(S4 review, DEF-1815), so a cursor move wiped the reason a close failed (DEF-1822); before S4 every read did,
|
|
4606
4636
|
and Zellij's `ESC [ O` after each hand_off() wiped ` Closed sh` as soon as it was painted. run() hands the read
|
|
4607
4637
|
over raw (bytes): take_reports decodes it, keeping a character the read cut for the next (BEY-6842)."""
|
|
4638
|
+
self.visibility_awake_until = time.monotonic() + visibility.TTL
|
|
4608
4639
|
data = self.take_reports(data)
|
|
4609
4640
|
self.poll_command()
|
|
4610
4641
|
self.handle_input(data)
|
|
@@ -4619,45 +4650,62 @@ class Sidebar:
|
|
|
4619
4650
|
self.reload(force=True)
|
|
4620
4651
|
self.start_cursor()
|
|
4621
4652
|
last_size = None
|
|
4653
|
+
was_visible = True
|
|
4622
4654
|
while True:
|
|
4623
|
-
|
|
4655
|
+
# The elected observer remains cheap and awake even when its own tab is hidden.
|
|
4656
|
+
if self.visibility_owner:
|
|
4657
|
+
self.reload()
|
|
4624
4658
|
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
|
-
|
|
4659
|
+
shown = (time.monotonic() < self.visibility_awake_until
|
|
4660
|
+
or visibility.visible(STATE, self.device, self.workspace, 'sidebars'))
|
|
4661
|
+
if not shown:
|
|
4662
|
+
if time.monotonic() >= self.hidden_reload_at:
|
|
4663
|
+
self.hidden_reload_at = time.monotonic() + visibility.TTL
|
|
4664
|
+
self.reload() # profile/registry changes can elect a new observer
|
|
4665
|
+
self.finish_actions()
|
|
4666
|
+
self.poll_profile()
|
|
4667
|
+
was_visible = False
|
|
4668
|
+
else:
|
|
4669
|
+
self.reload(force=not was_visible)
|
|
4670
|
+
was_visible = True
|
|
4671
|
+
# The worker's answers (cockpit v3 S9): a drain, never a wait — taken after reload(), so an answer is
|
|
4672
|
+
# applied to the listing it changes, and before expire_pending(), which holds a `P` whose write is out.
|
|
4673
|
+
if self.finish_actions():
|
|
4674
|
+
self.dirty = True
|
|
4675
|
+
try:
|
|
4676
|
+
size = tuple(os.get_terminal_size(sys.stdout.fileno()))
|
|
4677
|
+
except OSError:
|
|
4678
|
+
size = None
|
|
4679
|
+
if size != last_size:
|
|
4680
|
+
last_size, self.dirty = size, True
|
|
4681
|
+
self.poll_upload()
|
|
4682
|
+
self.poll_health()
|
|
4683
|
+
self.poll_update()
|
|
4684
|
+
self.poll_economy()
|
|
4685
|
+
self.poll_fleet() # W11: the fleet block's facts turning stale (no I/O)
|
|
4686
|
+
# An upload in flight no longer forces a frame: poll_upload() dirties on progress and on the end.
|
|
4687
|
+
if self.armed or (self.upload_note and time.time() - self.upload_note_at < 9):
|
|
4688
|
+
self.dirty = True
|
|
4689
|
+
if self.legend_stale(): # the no-report focus legend ran out (cockpit v3 S4)
|
|
4690
|
+
self.dirty = True
|
|
4691
|
+
if self.expire_message(): # the last message is MESSAGE_S old (cockpit v3 S6)
|
|
4692
|
+
self.dirty = True
|
|
4693
|
+
if self.expire_undo(): # the undo offer is UNDO_S old (cockpit v3 S7)
|
|
4694
|
+
self.dirty = True
|
|
4695
|
+
if self.expire_pending(): # a `P` the registry has not listed PENDING_S on (cockpit v3 S8)
|
|
4696
|
+
self.dirty = True
|
|
4697
|
+
self.expire_theme() # the OSC 11 grace ran out: resolve and publish, frame or not (DEF-1775)
|
|
4698
|
+
self.poll_profile() # a mark the owner's busy profile dropped, every PROFILE_RETRY_S (R3)
|
|
4699
|
+
if self.dirty:
|
|
4700
|
+
self.render()
|
|
4701
|
+
ready, _, _ = select.select([fd], [], [], self.tick_timeout() if shown else 1)
|
|
4656
4702
|
if ready:
|
|
4657
4703
|
data = os.read(fd, 4096)
|
|
4658
4704
|
if not data:
|
|
4659
4705
|
time.sleep(1) # pty closed: let the wrapper loop decide
|
|
4660
4706
|
return
|
|
4707
|
+
if not shown:
|
|
4708
|
+
self.reload(force=True)
|
|
4661
4709
|
self.on_read(data)
|
|
4662
4710
|
elif self.expire_carry(): # no read came: a held lone Esc is the Esc key (BEY-6842)
|
|
4663
4711
|
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.2",
|
|
4
|
+
"commit": "bfb56879994ea10a12e8e95083b4f12203d1d853",
|
|
5
|
+
"digest": "sha256:ce6c071a7269d10c2fda091e46c4aed47cfca96f27b8f698bb69138706679c82",
|
|
6
6
|
"executables": [
|
|
7
7
|
"bin/lanes",
|
|
8
8
|
"client/ghostty/lanes-themed-window",
|