@vibelord/lanes 1.7.3 → 1.7.5
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/README.md +9 -0
- package/package.json +1 -1
- package/payload/lanes/VERSION +1 -1
- package/payload/lanes/bin/lanes +128 -24
- package/payload/lanes/bin/lanes-site-serve +15 -0
- package/payload/lanes/bin-rs/BINARIES.json +5 -0
- package/payload/lanes/container/lane-mcp +108 -5
- package/payload/lanes/container/lane_core.py +116 -0
- package/payload/lanes/container/throttle-pulse +159 -14
- package/payload/lanes/docs/ARCHITECTURE.md +132 -13
- package/payload/lanes/docs/DESIGN.md +10 -8
- package/payload/lanes/docs/INSTALL.md +1 -1
- package/payload/lanes/docs/RUNBOOK.md +436 -8
- package/payload/lanes/docs/USERGUIDE.md +82 -9
- package/payload/lanes/install/host-install.sh +35 -4
- package/payload/lanes/libexec/adopt.py +364 -0
- package/payload/lanes/libexec/attach.py +35 -5
- package/payload/lanes/libexec/cutover.py +656 -0
- package/payload/lanes/libexec/docsd.py +12 -8
- package/payload/lanes/libexec/doctor_lanes2.py +284 -0
- package/payload/lanes/libexec/economy_poll.py +87 -2
- package/payload/lanes/libexec/gc_unregistered.py +407 -0
- package/payload/lanes/libexec/lanes_lib.py +474 -2
- package/payload/lanes/libexec/native.sh +38 -0
- package/payload/lanes/libexec/native_bin.py +670 -0
- package/payload/lanes/libexec/session_actions.py +85 -7
- package/payload/lanes/libexec/shadow.py +1311 -0
- package/payload/lanes/libexec/sidebar.py +252 -30
- package/payload/lanes/libexec/sidebar_status.py +373 -25
- package/payload/lanes/libexec/statusd.py +67 -3
- package/payload/lanes/libexec/tokens.py +99 -131
- package/payload/lanes/libexec/tokens.sh +1 -1
- package/payload/lanes/libexec/update.py +78 -8
- package/payload/lanes/libexec/users.py +282 -0
- package/payload/lanes/site/README.md +9 -0
- package/payload/lanes/site/conformance.py +280 -0
- package/payload/lanes/site/protocol.py +368 -0
- package/payload/lanes/site/server.py +314 -0
- package/payload/lanes/systemd/lanes-gc.service +1 -1
- package/payload/lanes/systemd/lanes-gc.timer +14 -3
- package/payload/lanes/tokens/README.md +156 -0
- package/payload/lanes/tokens/generate.py +930 -0
- package/payload/lanes/tokens/generated/parity.v1.tsv +489 -0
- package/payload/lanes/tokens/generated/tokens.resolved.json +835 -0
- package/payload/lanes/tokens/tokens.v1.json +763 -0
- package/payload/lanes/tokens/tokens.v1.schema.json +143 -0
- package/payload/lanes/web/Caddyfile +11 -0
- package/payload/lanes/web/README.md +253 -4
- package/payload/lanes/web/directory.css +95 -0
- package/payload/lanes/web/directory.js +951 -0
- package/payload/lanes/web/generated/README.md +107 -0
- package/payload/lanes/web/generated/lanes2_protocol.d.mts +1162 -0
- package/payload/lanes/web/generated/lanes2_protocol.mjs +2333 -0
- package/payload/lanes/web/inbox.js +1140 -0
- package/payload/lanes/web/mobile.js +35 -45
- package/payload/lanes/web/tokens.css +137 -0
- package/payload/manifest.json +7 -4
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""lanes-site/1 reference server — what a guest runs behind the aggregator's forced-command key.
|
|
3
|
+
|
|
4
|
+
Python 3 stdlib only. One process per ssh connection, serving newline JSON on stdin/stdout (site/protocol.py; Lanes2
|
|
5
|
+
architecture §3.32, DM-LANES-SITE-ADAPTER). The authorized_keys line on the guest is AR §3.32's
|
|
6
|
+
|
|
7
|
+
command="<home>/.local/share/lanes/current/bin/lanes-site-serve",restrict ssh-ed25519 AAAA… lanes-site@<aggregator>
|
|
8
|
+
|
|
9
|
+
`restrict` gives no pty, no forwarding and no agent; the forced command (bin/lanes-site-serve, POSIX sh) ignores
|
|
10
|
+
whatever the client asked to run and execs this file unless `$LANES_STATE/flags/rs-site` names the native adapter.
|
|
11
|
+
|
|
12
|
+
It answers from the guest's own Lanes state (`$LANES_STATE`: registry.json, containers.json — the files its own
|
|
13
|
+
`lanes sync` and statusd write) and holds no store: it reads them again for every request, so a sync between two
|
|
14
|
+
requests is seen. The one write (`tmux_write`) types into the active pane of a lane registered to this guest, under the
|
|
15
|
+
recipient's dispatch lock (lanes_lib.dispatch_lock, the inode every writer in the container takes); `exec` spawns by
|
|
16
|
+
template id only, and only when the guest itself finds it due (the checks its own statusd makes: never while its health
|
|
17
|
+
is critical, nothing that is not installed, nothing that is running). Every request is checked in protocol.py's
|
|
18
|
+
normative order: its shape, its verb allowlist and text bound, and only then its recipient. Requests are served in
|
|
19
|
+
order, one at a time: every op is bounded (tmux TMUX_TIMEOUT, the lock DISPATCH_WAIT_S, each template its
|
|
20
|
+
EXEC_TEMPLATES seconds), so the longest wait a later request sees is one tmux_write (about 16 s); the reader thread
|
|
21
|
+
and worker pool of AR §3.32 come with its slow ops (containers.resolve). stderr is never part of the protocol;
|
|
22
|
+
nothing here logs a typed text."""
|
|
23
|
+
import os
|
|
24
|
+
import platform
|
|
25
|
+
import socket
|
|
26
|
+
import sys
|
|
27
|
+
import time
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
|
|
30
|
+
HERE = Path(__file__).resolve().parent
|
|
31
|
+
TREE = HERE.parent
|
|
32
|
+
sys.path.insert(0, str(HERE))
|
|
33
|
+
sys.path.insert(1, str(TREE / 'libexec'))
|
|
34
|
+
import protocol as P # noqa: E402
|
|
35
|
+
|
|
36
|
+
BOOT_ID = '/proc/sys/kernel/random/boot_id'
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _version():
|
|
40
|
+
try:
|
|
41
|
+
return (TREE / 'VERSION').read_text().strip()[:32]
|
|
42
|
+
except OSError:
|
|
43
|
+
return 'unknown'
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _boot_id():
|
|
47
|
+
try:
|
|
48
|
+
return Path(BOOT_ID).read_text().strip()[:64]
|
|
49
|
+
except OSError:
|
|
50
|
+
return ''
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _guest_id():
|
|
54
|
+
"""LANES_SITE_GUEST_ID when it is an identifier, else this host's name cut to one."""
|
|
55
|
+
named = os.environ.get('LANES_SITE_GUEST_ID', '')
|
|
56
|
+
if P.IDENT.match(named):
|
|
57
|
+
return named
|
|
58
|
+
host = ''.join(c if c.isalnum() or c in '._-' else '-' for c in socket.gethostname()).strip('-.') or 'guest'
|
|
59
|
+
return host[:63]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class Server:
|
|
63
|
+
"""The ops of lanes-site/1 over a lanes_lib module `lib`. Every effect goes through an injectable seam so the
|
|
64
|
+
conformance kit and the unit tests drive it without tmux or docker: `tmux(info, socket, args, timeout) -> (outcome,
|
|
65
|
+
text)` (lanes_lib.tmux_probe), `lock(info, lane_id)` a context manager yielding None while held, else why not
|
|
66
|
+
(lanes_lib.dispatch_lock), `runner(argv, timeout) -> (rc, out, err)` (lanes_lib.run_bounded), `pause(seconds)`."""
|
|
67
|
+
|
|
68
|
+
def __init__(self, lib, tmux=None, lock=None, runner=None, pause=None, guest_id=None, boot_id=None):
|
|
69
|
+
self.L = lib
|
|
70
|
+
self.tmux = tmux or lib.tmux_probe
|
|
71
|
+
self.lock = lock or lib.dispatch_lock
|
|
72
|
+
self.runner = runner or lib.run_bounded
|
|
73
|
+
self.pause = pause or time.sleep
|
|
74
|
+
self.guest_id = guest_id or _guest_id()
|
|
75
|
+
self.boot_id = _boot_id() if boot_id is None else boot_id
|
|
76
|
+
self.greeted = False
|
|
77
|
+
|
|
78
|
+
# ------------------------------------------------------------------ the guest's own state, read per request
|
|
79
|
+
|
|
80
|
+
def registry(self):
|
|
81
|
+
registry = self.L.read_json(self.L.STATE / 'registry.json')
|
|
82
|
+
if not isinstance(registry, dict) or not isinstance(registry.get('workspaces'), list):
|
|
83
|
+
raise P.ProtocolError('registry_unavailable', 'this guest has no registry yet (lanes sync)')
|
|
84
|
+
try:
|
|
85
|
+
newer = int(registry.get('version', 1)) > 1
|
|
86
|
+
except (TypeError, ValueError):
|
|
87
|
+
newer = True
|
|
88
|
+
if newer:
|
|
89
|
+
raise P.ProtocolError('registry_unavailable', 'registry.json was written by a newer Lanes on this guest')
|
|
90
|
+
return registry
|
|
91
|
+
|
|
92
|
+
def containers(self):
|
|
93
|
+
found = self.L.read_json(self.L.STATE / 'containers.json')
|
|
94
|
+
return found if isinstance(found, dict) else {}
|
|
95
|
+
|
|
96
|
+
def registered_lanes(self, registry):
|
|
97
|
+
"""{lane id: lane} of every registered tmux lane whose container, socket and session are well formed."""
|
|
98
|
+
lanes = {}
|
|
99
|
+
for workspace in registry['workspaces']:
|
|
100
|
+
for lane in (workspace.get('lanes') if isinstance(workspace, dict) else None) or []:
|
|
101
|
+
if not isinstance(lane, dict) or lane.get('holder') != 'tmux':
|
|
102
|
+
continue
|
|
103
|
+
tmux = lane.get('tmux') if isinstance(lane.get('tmux'), dict) else {}
|
|
104
|
+
if (P.IDENT.match(str(lane.get('id') or '')) and P.IDENT.match(str(lane.get('container') or ''))
|
|
105
|
+
and P.IDENT.match(str(tmux.get('socket') or ''))
|
|
106
|
+
and P.TMUX_SESSION.match(str(tmux.get('session') or ''))):
|
|
107
|
+
lanes[lane['id']] = lane
|
|
108
|
+
return lanes
|
|
109
|
+
|
|
110
|
+
def registered_containers(self, registry):
|
|
111
|
+
names = {lane['container'] for lane in self.registered_lanes(registry).values()}
|
|
112
|
+
for tool in registry.get('tools') or []:
|
|
113
|
+
if isinstance(tool, dict) and P.IDENT.match(str(tool.get('container') or '')):
|
|
114
|
+
names.add(tool['container'])
|
|
115
|
+
return names
|
|
116
|
+
|
|
117
|
+
def local_info(self, container):
|
|
118
|
+
"""The guest's containers.json entry of a container whose init runs HERE: a pid, and no transport but local
|
|
119
|
+
(a guest never relays a write onwards). ProtocolError container_unavailable otherwise."""
|
|
120
|
+
info = self.containers().get(container)
|
|
121
|
+
if not isinstance(info, dict) or not info.get('pid') or info.get('transport', 'local') != 'local':
|
|
122
|
+
raise P.ProtocolError('container_unavailable', f'{container} has no running init on this guest')
|
|
123
|
+
return info
|
|
124
|
+
|
|
125
|
+
# ------------------------------------------------------------------ ops
|
|
126
|
+
|
|
127
|
+
def op_hello(self, message, args):
|
|
128
|
+
asked = message.get('lanes_site', args.get('proto', P.PROTO))
|
|
129
|
+
if asked != P.PROTO or args.get('proto', P.PROTO) != P.PROTO:
|
|
130
|
+
raise P.ProtocolError('version_unsupported', f'this guest serves lanes-site/{P.PROTO} only')
|
|
131
|
+
self.greeted = True
|
|
132
|
+
return {'lanes_site': P.PROTO, 'proto': P.PROTO, 'guest_id': self.guest_id, 'boot_id': self.boot_id,
|
|
133
|
+
'versions': {'lanes': _version(), 'lanes_site': P.PROTO, 'python': platform.python_version()},
|
|
134
|
+
'capabilities': list(P.CAPABILITIES), 'ops': list(P.OPS),
|
|
135
|
+
'epochs': {}} # no owner lanesd fences a workspace on this guest yet (AR §3.32, W17)
|
|
136
|
+
|
|
137
|
+
def op_boards_list(self, _message, _args):
|
|
138
|
+
boards = []
|
|
139
|
+
for workspace in self.registry()['workspaces']:
|
|
140
|
+
if not isinstance(workspace, dict) or not P.IDENT.match(str(workspace.get('id') or '')):
|
|
141
|
+
continue
|
|
142
|
+
boards.append({'id': workspace['id'], 'title': str(workspace.get('title') or workspace['id']),
|
|
143
|
+
'container': str(workspace.get('container') or ''),
|
|
144
|
+
'lanes': len(workspace.get('lanes') or []), 'stale': bool(workspace.get('stale'))})
|
|
145
|
+
return {'boards': boards}
|
|
146
|
+
|
|
147
|
+
def op_boards_lanes(self, _message, args):
|
|
148
|
+
board = args.get('board')
|
|
149
|
+
if not isinstance(board, str) or not P.IDENT.match(board):
|
|
150
|
+
raise P.ProtocolError('args_invalid', 'boards.lanes needs {board}')
|
|
151
|
+
for workspace in self.registry()['workspaces']:
|
|
152
|
+
if isinstance(workspace, dict) and workspace.get('id') == board:
|
|
153
|
+
lanes = []
|
|
154
|
+
for lane in workspace.get('lanes') or []:
|
|
155
|
+
if not isinstance(lane, dict):
|
|
156
|
+
continue
|
|
157
|
+
tmux = lane.get('tmux') if isinstance(lane.get('tmux'), dict) else None
|
|
158
|
+
lanes.append({'id': str(lane.get('id') or ''), 'name': str(lane.get('name') or ''),
|
|
159
|
+
'holder': str(lane.get('holder') or ''), 'container': str(lane.get('container') or ''),
|
|
160
|
+
'address': lane.get('address'), 'role': lane.get('role'),
|
|
161
|
+
'tmux': {'socket': str(tmux.get('socket') or ''),
|
|
162
|
+
'session': str(tmux.get('session') or '')} if tmux else None})
|
|
163
|
+
return {'board': board, 'lanes': lanes}
|
|
164
|
+
raise P.ProtocolError('board_unknown', f'this guest has no board {board}')
|
|
165
|
+
|
|
166
|
+
def op_tmux_read(self, _message, args):
|
|
167
|
+
container, sock = args.get('container'), args.get('socket')
|
|
168
|
+
if not isinstance(container, str) or not P.IDENT.match(container) or not isinstance(sock, str) \
|
|
169
|
+
or not P.IDENT.match(sock):
|
|
170
|
+
raise P.ProtocolError('args_invalid', 'tmux_read needs {container, socket, args}')
|
|
171
|
+
words = P.check_tmux_read(args.get('args'))
|
|
172
|
+
used = {(lane['container'], lane['tmux']['socket']) for lane in self.registered_lanes(self.registry()).values()}
|
|
173
|
+
if (container, sock) not in used:
|
|
174
|
+
raise P.ProtocolError('socket_unregistered', f'no registered lane of {container} uses tmux socket {sock}')
|
|
175
|
+
outcome, text = self.tmux(self.local_info(container), sock, words, P.TMUX_TIMEOUT)
|
|
176
|
+
# A byte budget, not a character count: the reply always fits one frame; a screen keeps its newest lines.
|
|
177
|
+
text, truncated = P.fit_text(text if isinstance(text, str) else '', tail=words[0] == 'capture-pane')
|
|
178
|
+
return {'outcome': outcome, 'text': text, 'truncated': truncated}
|
|
179
|
+
|
|
180
|
+
def op_tmux_write(self, _message, args):
|
|
181
|
+
lane_id, enter = args.get('lane'), args.get('enter', False)
|
|
182
|
+
if not isinstance(lane_id, str) or not P.IDENT.match(lane_id) or not isinstance(enter, bool):
|
|
183
|
+
raise P.ProtocolError('args_invalid', 'tmux_write needs {lane, text, enter: bool}')
|
|
184
|
+
intent, _epoch = P.check_intent(args)
|
|
185
|
+
text = P.check_text(args.get('text')) # before the lane: a bound is checked whoever the recipient is
|
|
186
|
+
lane = self.registered_lanes(self.registry()).get(lane_id)
|
|
187
|
+
if lane is None:
|
|
188
|
+
raise P.ProtocolError('lane_unregistered', f'{lane_id} is not a registered tmux lane of this guest')
|
|
189
|
+
info = self.local_info(lane['container'])
|
|
190
|
+
sock, target = lane['tmux']['socket'], f"={lane['tmux']['session']}:"
|
|
191
|
+
with self.lock(info, lane_id) as busy:
|
|
192
|
+
if busy:
|
|
193
|
+
raise P.ProtocolError('busy', busy)
|
|
194
|
+
outcome, detail = self.tmux(info, sock, ['send-keys', '-t', target, '-l', '--', P.tmux_literal(text)],
|
|
195
|
+
P.TMUX_TIMEOUT)
|
|
196
|
+
if outcome != 'ok':
|
|
197
|
+
raise P.ProtocolError('tmux_failed', f'tmux did not take it ({outcome}{": " + detail if detail else ""})')
|
|
198
|
+
entered = False
|
|
199
|
+
if enter:
|
|
200
|
+
self.pause(P.ENTER_DELAY)
|
|
201
|
+
entered = self.tmux(info, sock, ['send-keys', '-t', target, 'Enter'], P.TMUX_TIMEOUT)[0] == 'ok'
|
|
202
|
+
return dict({'lane': lane_id, 'typed': True, 'enter': entered}, **({'intent': intent} if intent else {}))
|
|
203
|
+
|
|
204
|
+
def template_plan(self, template, container, now=None):
|
|
205
|
+
"""('spawn', argv) when the template is due in `container` by this guest's own reading — the checks its
|
|
206
|
+
statusd's rearm_pulse / rearm_peerd make, so the aggregator is never a second actor that spawns what the guest
|
|
207
|
+
would not — else (outcome, why) with outcome 'off' (site.conf LANES_PEERS=0) or 'skipped'. The argv is fixed:
|
|
208
|
+
nothing of it comes from the wire but the checked container name."""
|
|
209
|
+
import statusd as SD # libexec; imported only here: the server's other ops need none of it
|
|
210
|
+
now = time.time() if now is None else now
|
|
211
|
+
pid = self.local_info(container)['pid']
|
|
212
|
+
if template == 'pulse.rearm':
|
|
213
|
+
daemon = SD.daemon_container(self.registry(), SD.site_settings())
|
|
214
|
+
if container != daemon:
|
|
215
|
+
return 'skipped', f'{container} is not the Throttle daemon container of this guest ({daemon or "none"})'
|
|
216
|
+
if not SD.pulse_installed(pid):
|
|
217
|
+
return 'skipped', f'~/.lz/bin/{SD.PULSE_PROGRAM} is not installed in {container}'
|
|
218
|
+
mtime = self.pulse_mtime(SD, pid)
|
|
219
|
+
if mtime is not None and now - mtime <= SD.PULSE_REARM_S:
|
|
220
|
+
return 'skipped', f'its pulse file is {int(now - mtime)} s old: running'
|
|
221
|
+
return 'spawn', SD.pulse_rearm_argv(container)
|
|
222
|
+
policy = SD.peerd_policy(SD.site_settings()) # peerd.rearm
|
|
223
|
+
if policy is None:
|
|
224
|
+
return 'off', 'site.conf LANES_PEERS=0'
|
|
225
|
+
installed, mtime = SD.peerd_look(pid)
|
|
226
|
+
if not installed:
|
|
227
|
+
return 'skipped', f'~/.lz/bin/{SD.PEERD_PROGRAM} is not installed in {container}'
|
|
228
|
+
if mtime is not None and now - mtime <= SD.PEERD_REARM_S:
|
|
229
|
+
return 'skipped', f'its peers.json is {int(now - mtime)} s old: running'
|
|
230
|
+
return 'spawn', SD.peerd_rearm_argv(container, policy)
|
|
231
|
+
|
|
232
|
+
def pulse_mtime(self, SD, pid):
|
|
233
|
+
"""The pulse file's mtime in the container whose init is `pid` (statusd throttle_snapshot's walk: every
|
|
234
|
+
directory opened without following a link), None when it cannot be seen."""
|
|
235
|
+
try:
|
|
236
|
+
fd = self.L.open_real_dir(Path(self.L.proc_root()) / str(pid) / 'root', SD.PULSE_DIR)
|
|
237
|
+
except (OSError, self.L.LanesError):
|
|
238
|
+
return None
|
|
239
|
+
try:
|
|
240
|
+
return os.stat(SD.PULSE_FILE, dir_fd=fd, follow_symlinks=False).st_mtime
|
|
241
|
+
except OSError:
|
|
242
|
+
return None
|
|
243
|
+
finally:
|
|
244
|
+
os.close(fd)
|
|
245
|
+
|
|
246
|
+
def op_exec(self, _message, args):
|
|
247
|
+
template, container = P.check_exec(args)
|
|
248
|
+
intent, _epoch = P.check_intent(args)
|
|
249
|
+
if container not in self.registered_containers(self.registry()):
|
|
250
|
+
raise P.ProtocolError('container_unknown', f'this guest registers no container {container}')
|
|
251
|
+
if self.L.read_health().get('level') == 'critical': # never spawn on a critical host (statusd's rule)
|
|
252
|
+
raise P.ProtocolError('busy', 'this guest is critical (its $LANES_STATE/health): no spawn now')
|
|
253
|
+
reply = {'template': template, 'container': container, 'rc': None, 'out': '', 'err': '', 'detail': ''}
|
|
254
|
+
if intent:
|
|
255
|
+
reply['intent'] = intent
|
|
256
|
+
outcome, plan = self.template_plan(template, container)
|
|
257
|
+
if outcome != 'spawn':
|
|
258
|
+
return dict(reply, outcome=outcome, detail=plan)
|
|
259
|
+
rc, out, err = self.runner(plan, P.EXEC_TEMPLATES[template])
|
|
260
|
+
return dict(reply, rc=rc, outcome='timeout' if rc is None else ('ok' if rc == 0 else 'failed'),
|
|
261
|
+
out=(out or '')[-P.TAIL_MAX:], err=(err or '')[-P.TAIL_MAX:])
|
|
262
|
+
|
|
263
|
+
OPS = {'hello': op_hello, 'boards.list': op_boards_list, 'boards.lanes': op_boards_lanes,
|
|
264
|
+
'tmux_read': op_tmux_read, 'tmux_write': op_tmux_write, 'exec': op_exec}
|
|
265
|
+
|
|
266
|
+
def handle(self, message):
|
|
267
|
+
"""One request -> its reply (never raises)."""
|
|
268
|
+
request_id = message.get('id')
|
|
269
|
+
if not isinstance(request_id, int) or isinstance(request_id, bool):
|
|
270
|
+
request_id = None
|
|
271
|
+
op, args = message.get('op'), message.get('args', {})
|
|
272
|
+
try:
|
|
273
|
+
if op not in self.OPS:
|
|
274
|
+
raise P.ProtocolError('op_unknown', f'lanes-site/{P.PROTO} ops: {", ".join(P.OPS)}')
|
|
275
|
+
if not isinstance(args, dict):
|
|
276
|
+
raise P.ProtocolError('args_invalid', 'args is an object')
|
|
277
|
+
if op != 'hello' and not self.greeted:
|
|
278
|
+
raise P.ProtocolError('hello_required', 'the first request of a connection is hello')
|
|
279
|
+
return P.reply_ok(request_id, self.OPS[op](self, message, args))
|
|
280
|
+
except P.ProtocolError as error:
|
|
281
|
+
return P.reply_err(request_id, error.code, error.human)
|
|
282
|
+
except Exception as error: # a bug or an OS failure answers as one, and the connection stays usable
|
|
283
|
+
return P.reply_err(request_id, 'internal', f'{type(error).__name__}: {error}')
|
|
284
|
+
|
|
285
|
+
def serve(self, in_fd=0, out_fd=1):
|
|
286
|
+
"""Answer frames from in_fd on out_fd until end of file -> 0."""
|
|
287
|
+
reader = P.FrameReader(in_fd)
|
|
288
|
+
while True:
|
|
289
|
+
try:
|
|
290
|
+
message = reader.read()
|
|
291
|
+
except P.ProtocolError as error:
|
|
292
|
+
P.write_frame(out_fd, P.reply_err(None, error.code, error.human))
|
|
293
|
+
continue
|
|
294
|
+
if message is None:
|
|
295
|
+
return 0
|
|
296
|
+
try:
|
|
297
|
+
P.write_frame(out_fd, self.handle(message))
|
|
298
|
+
except P.ProtocolError as error: # a reply over FRAME_MAX: said so instead
|
|
299
|
+
P.write_frame(out_fd, P.reply_err(message.get('id'), error.code, error.human))
|
|
300
|
+
except BrokenPipeError:
|
|
301
|
+
return 0
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def main():
|
|
305
|
+
import lanes_lib as L
|
|
306
|
+
# The protocol keeps its own copy of stdout (os.dup: not inherited by any spawn); fd 1 then points at stderr, so
|
|
307
|
+
# a stray print anywhere in the libraries lands on stderr instead of inside a frame.
|
|
308
|
+
protocol_out = os.dup(1)
|
|
309
|
+
os.dup2(2, 1)
|
|
310
|
+
return Server(L).serve(0, protocol_out)
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
if __name__ == '__main__':
|
|
314
|
+
sys.exit(main())
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
[Unit]
|
|
2
|
-
Description=lanes housekeeping (zmx logs never rotate; stale dynamic resolve files; old staged trees)
|
|
2
|
+
Description=lanes housekeeping (zmx logs never rotate; stale dynamic resolve files; old staged trees; unregistered sessions in which nothing runs, where site.conf opts in)
|
|
3
3
|
|
|
4
4
|
[Service]
|
|
5
5
|
Type=oneshot
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
[Unit]
|
|
2
|
-
Description=lanes housekeeping daily
|
|
2
|
+
Description=lanes housekeeping daily at midnight
|
|
3
3
|
|
|
4
4
|
[Timer]
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
# Midnight in the host's time zone (+0-5 min), enabled by every full server install with the other timers. The unit
|
|
6
|
+
# file is re-rendered by every install and update (install/services.py; an update's post-commit runs daemon-reload and,
|
|
7
|
+
# when this file's text changed, `systemctl --user try-restart lanes-gc.timer`), so a host whose timer was the earlier
|
|
8
|
+
# boot-relative one (OnBootSec=10min, OnUnitActiveSec=1d) takes this calendar at its next update. [inferred, not
|
|
9
|
+
# measured: systemd counts a Persistent= calendar timer from its last trigger, which on such a host lies before the
|
|
10
|
+
# last midnight, so the update that moves the schedule may run one `lanes gc` at once; its sweep ends only what a
|
|
11
|
+
# midnight one would.]
|
|
12
|
+
# Persistent= runs a midnight the host missed (off or suspended) once at the next boot, so no OnBootSec= is needed.
|
|
13
|
+
# `lanes gc` also ends the unregistered sessions in which nothing runs, only where site.conf sets LANES_GC_UNREGISTERED=1
|
|
14
|
+
# (RUNBOOK "Daily cleanup of unregistered terminals").
|
|
15
|
+
OnCalendar=*-*-* 00:00:00
|
|
16
|
+
Persistent=true
|
|
17
|
+
RandomizedDelaySec=300
|
|
7
18
|
|
|
8
19
|
[Install]
|
|
9
20
|
WantedBy=timers.target
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# Lanes semantic design tokens
|
|
2
|
+
|
|
3
|
+
`tokens.v1.json` (schema `tokens.v1.schema.json`, `lanes.tokens/1`) is the one versioned semantic token source required
|
|
4
|
+
by IC §5.1 and witness A26, and the only file a person edits. `generate.py` (fan-out lane F1) checks it and derives
|
|
5
|
+
every client projection from it, so the same theme id/revision paints alike in the terminal, the browser, the Apple
|
|
6
|
+
apps and the Python sidebar.
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
python3 lanes/tokens/generate.py --write # regenerate every projection and every tokens.py marker block
|
|
10
|
+
python3 lanes/tokens/generate.py --check # exit 1, with a diff, when anything committed differs
|
|
11
|
+
python3 lanes/libexec/tokens.py --check # the eight marker surfaces, plus the generated files inside lanes/
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The Rust and Swift outputs exist only in a repository checkout (a `Cargo.toml` beside `lanes/`). In an installed or
|
|
15
|
+
payload tree (`npm/lanes` ships this directory) `generate.py` compares and writes the files inside `lanes/` only, says
|
|
16
|
+
which outputs it skipped, and never creates anything outside the tree. Every output is replaced atomically (a sibling
|
|
17
|
+
temporary file and a rename), so a sidebar or notify starting meanwhile reads the old resolved table or the new one,
|
|
18
|
+
never a truncated file; `tokens.py` names the file and `generate.py --write` in a one-line import error when the table
|
|
19
|
+
is missing or unreadable.
|
|
20
|
+
|
|
21
|
+
## The source
|
|
22
|
+
|
|
23
|
+
- **Theme.** The theme id `lanes` and revision `3` are shared by every client. The variants are `dark` and `light`.
|
|
24
|
+
Shared with the principal (DM-LANES2-PRESENTATION, IC §5.1): the theme id/revision and the appearance defaults
|
|
25
|
+
(light/dark/auto, colour tier, glyph mode). Device-local, never broadcast: a device appearance override (light/dark/
|
|
26
|
+
auto, colour tier, glyph mode), the colour-capability fallback, accessibility and density.
|
|
27
|
+
- **Revisions.** `theme.revisions` maps each revision to the sha256 of its styling content. The digest covers the
|
|
28
|
+
whole document except `schema`, `source`, `description`, `theme` and each tier's `description`, as JSON with sorted
|
|
29
|
+
keys, separators `(',', ':')` and UTF-8 text. Numbers have one canonical form, the one every JSON encoder prints
|
|
30
|
+
alike: an integral value is written as an integer (`3`, never `3.0`; Python prints `3.0` where JavaScript and Swift
|
|
31
|
+
print `3`), a non-integral one in its shortest round-trip form (`4.5`). `generate.py` refuses an integral float, and
|
|
32
|
+
the generator suite recomputes the digest with a JavaScript/Swift-style encoder. The current revision's digest must
|
|
33
|
+
match the content, so a styling edit without a new revision fails, even when the source and the generated table
|
|
34
|
+
change together. Revision 3 is revision 2 (palette v2 of cockpit v3 P1 with the 256-colour set) plus the semantic
|
|
35
|
+
states, the text hierarchy and the contrast rules: no role, tier, glyph or label value changed, so a client at
|
|
36
|
+
revision 2 paints every role alike. Its digest was re-recorded once before publication, when review added the
|
|
37
|
+
tertiary-text contrast pairs and wrote the integral minima as integers. Revision 1 (palette v1) predates this table
|
|
38
|
+
and has no recorded digest.
|
|
39
|
+
- **Roles.** All 19 roles, the 9 painted roles, and the background mapping (`selected` uses `accent-wash`).
|
|
40
|
+
- **The five colour tiers.**
|
|
41
|
+
- `truecolor`: hex per role and variant.
|
|
42
|
+
- `256`: one xterm index per painted role and variant.
|
|
43
|
+
- `16`: the user's own palette as SGR codes, with the dim roles and their dim SGR (`90`, or `2` under `LANES_DIM=2`).
|
|
44
|
+
- `palette16`: Lanes' own 16-slot palette for the surfaces that define one (the Zellij web client's xterm.js,
|
|
45
|
+
and Ghostty).
|
|
46
|
+
- `none`: attributes only; `accent` is bold.
|
|
47
|
+
- **Glyphs and labels.** Unicode and ASCII twins with their tones for the agent, stream, mark and economy glyphs,
|
|
48
|
+
plus the phone's agent labels.
|
|
49
|
+
- **Text hierarchy.** `primary` ink and `secondary` ink-dim carry essential text (4.5:1); `tertiary` ink-faint is
|
|
50
|
+
non-essential text only — hints, ages, rules — held to 3:1 on every surface it sits on.
|
|
51
|
+
- **Semantic states.** The meanings IC §5.1 and the terminal UX spec name — identity, selection, focus, approval,
|
|
52
|
+
attention, working, done, error, stale, disabled — each with the painted role it takes and the **cues that carry it
|
|
53
|
+
with colour removed** (the `none` tier, `NO_COLOR`, a colour-blind reader): a glyph (its ASCII twin keeps it in ASCII
|
|
54
|
+
mode), a label, or text (the lane name, the unavailable reason, the focus legend). States whose glyph cues share a
|
|
55
|
+
table (one row slot) must differ in both glyph modes; approval and error share `tone-urgent` and differ by `◆`/`!`
|
|
56
|
+
against `✗`/`X`.
|
|
57
|
+
- **Contrast rules.** Per variant, every foreground reference on every background reference of a rule keeps at least
|
|
58
|
+
`min`:1 (WCAG relative luminance). References are `truecolor:<role>`, `256:<painted role>` (the fixed RGB of the
|
|
59
|
+
xterm index) or `palette16:<slot>`. Text roles keep 4.5:1 on every surface they sit on in truecolor, 4.2:1 in 256
|
|
60
|
+
(the cube's six levels allow no more), `ink-faint` (the tertiary level) 3:1 on surface, surface-raised and the
|
|
61
|
+
selected band in both tiers (accent-wash in truecolor, the 256 `selected` index), every defined slot 4.5:1. `test_lanes2_token_generator.py` holds each rule to a floor it may raise, never lower.
|
|
62
|
+
- **Projections.** The mappings `tokens.py`'s renderers use beyond the role tables: `css_aliases` (the legacy
|
|
63
|
+
`--lanes-<alias>` names), `zellij_slots` (the `--zj-<slot>` theme slots), `docs_roles` (the roles the docs page CSS
|
|
64
|
+
carries) and `sh_names` (the viewer's `LZ_*` shell variables).
|
|
65
|
+
|
|
66
|
+
## What the generator writes
|
|
67
|
+
|
|
68
|
+
| Output | Who reads it | What it carries |
|
|
69
|
+
| --- | --- | --- |
|
|
70
|
+
| `generated/tokens.resolved.json` (`lanes.tokens.resolved/1`) | `lanes/libexec/tokens.py`, its only input | the tables in the shapes `tokens.py` exposes, every SGR escape per tier, variant and painted role, the dim escapes |
|
|
71
|
+
| `generated/parity.v1.tsv` (`lanes.tokens.parity/1`) | the Python, Rust and Swift suites | one styling fact per line (below) |
|
|
72
|
+
| `lanes/web/tokens.css` | no page yet: the browser directory (lane F3) still carries its own copy of the roles in `lanes/web/directory.css`, compared with the source by its node suite; loading this file instead is open | `--lanes-<role>` per variant, `--lanes-ansi-<n>`, `--lanes-theme-id`/`-revision`, `--lanes-text-<level>`, `--lanes-state-<state>`. Every selector sits in `:where()`, so it has zero specificity and a surface stylesheet that sets the same property (the phone's `html.lanes-mobile` block in `mobile.css`) always wins. The variant follows the page's appearance authority: light under `data-zj-theme="light"` (the phone shell's attribute, the principal's appearance), dark under any other value; with no such attribute, the system appearance — except on the phone shell (`html.lanes-mobile`), which `mobile.css` paints dark until the attribute is set. No attribute of its own |
|
|
73
|
+
| `crates/lanes-terminal/src/tokens/generated.rs` | `lanes_terminal::tokens`, for the Rust sidebar (lane C2); no caller yet | enums for variants, tiers, roles, painted roles, glyph tables, text levels and states; every hex; the complete SGR per tier/variant/role; xterm indexes; the 16-colour codes; the sixteen slots; glyph twins; labels; cues |
|
|
74
|
+
| `apps/throttle-ios/Sources/LanesKit/Tokens/LanesTokens.swift` | LanesKit (`LanesTokens`); no caller yet: the Apple directory (lane F4) reads its own projection, `Sources/LanesDirectoryKit/SemanticTokens.generated.swift`, written by `apps/throttle-ios/scripts/semantic_tokens_swift.py` from the same source; one Swift projection is open | the theme, every role's hex and RGBA per variant, the shadow, the sixteen slots, glyph twins, labels, the text hierarchy, states and cues; Foundation-free |
|
|
75
|
+
|
|
76
|
+
The Swift file is placed per the DM-LANES2-TOKENS Day-0 provision (a `Tokens/` directory inside an existing
|
|
77
|
+
`apps/throttle-ios/Sources/<target>/` target; ThrottleKit is the package, not a directory). The throttle-swift lane's
|
|
78
|
+
agreement on file ownership in `apps/throttle-ios` is pending (fan-out plan §7); the file adds no target and touches no
|
|
79
|
+
other Swift file.
|
|
80
|
+
|
|
81
|
+
`tokens.py` keeps rendering the older surfaces from the resolved table, between their markers and byte for byte as
|
|
82
|
+
before F1: the Zellij KDL theme and web client palette (`zellij/config.kdl`), the phone CSS and JS (`web/mobile.css`,
|
|
83
|
+
`web/mobile.js`), the viewer's shell sets (`libexec/tokens.sh`), `docs/DESIGN.md`, the Ghostty palettes and the docs
|
|
84
|
+
page CSS. `generate.py --write` regenerates them after its own outputs.
|
|
85
|
+
|
|
86
|
+
## The parity fixture
|
|
87
|
+
|
|
88
|
+
`parity.v1.tsv` is the A26 comparison. Each line is one fact, tab-separated: `theme`, `role`, `painted`,
|
|
89
|
+
`background`, `vivid`, `text`, `hex`, `rgba` (integers 0–255), `shadow` (x, y, blur, RGBA), `sgr` (tier `truecolor`,
|
|
90
|
+
`256`, `16`, `16-dim2` or `none`; ESC written `\e`, an empty escape `-`), `xterm256`, `ansi16`, `palette16`,
|
|
91
|
+
`palette16-role`, `glyph`, `label`, `semantic`, `cue` and `contrast` (a rule per variant and pair). Each client derives
|
|
92
|
+
the lines of the kinds it carries from its own compiled values and must equal the fixture's:
|
|
93
|
+
|
|
94
|
+
| Client | Suite | Tiers it paints |
|
|
95
|
+
| --- | --- | --- |
|
|
96
|
+
| Python sidebar (`tokens.py`) | `lanes/tests/unit/test_lanes2_token_generator.py`, `test_lanes2_tokens.py` | truecolor, 256, 16, none, palette16 |
|
|
97
|
+
| Browser (`tokens.css`) | `test_lanes2_token_generator.py` | truecolor, palette16 |
|
|
98
|
+
| Zellij KDL theme | `test_lanes2_token_generator.py` (theme names, web client slots, every colour a value of its variant) | truecolor, palette16 (dark) |
|
|
99
|
+
| Rust terminal | `crates/lanes-terminal/src/tokens/tests.rs` (CI `unit_tests` lane) | truecolor, 256, 16, none, palette16 |
|
|
100
|
+
| Swift (LanesKit) | `apps/throttle-ios/Tests/LanesKitTests/Tokens/LanesTokensParityTests.swift` (CI `throttlekit`) | truecolor, palette16 |
|
|
101
|
+
|
|
102
|
+
Each suite also holds its own values to the fixture's contrast rules and the semantic states to their no-colour cues,
|
|
103
|
+
and each detector has a sabotage leg. `test_lanes2_token_generator.py` pins the Rust and Swift suites' registration:
|
|
104
|
+
that they read the fixture and carry every kind of their tiers, and (`RUST_LEGS`, `SWIFT_LEGS`) that every test of
|
|
105
|
+
each suite is a registered detector with an existing sabotage test or a registered leg, so no detector loses its leg
|
|
106
|
+
or goes missing silently. It also composes `tokens.css` with the phone's `mobile.css` for every system appearance x
|
|
107
|
+
`data-zj-theme` combination and both load orders, and requires every role, slot and `color-scheme` to paint the
|
|
108
|
+
phone's variant.
|
|
109
|
+
`lanes/tests/unit/test_lanes2_tokens.py` pins what `tokens.py` exposes to the source, and
|
|
110
|
+
`lanes/tests/conformance/prove_detectors.sh` edits the committed source and the generated table without a new revision
|
|
111
|
+
and requires the digest detector to fail.
|
|
112
|
+
|
|
113
|
+
## Why the values are what they are
|
|
114
|
+
|
|
115
|
+
The reasons recorded beside the tables in `tokens.py` before F1, carried here with the values they explain:
|
|
116
|
+
|
|
117
|
+
- **Palette v2** (cockpit v3 P1, 2026-10-06): vivid, high-contrast roles in both variants. v1 had darkened the light
|
|
118
|
+
tones until they passed (amber `#8a5a00` read olive-brown). Surfaces are v1's but for the dark accent-wash, the
|
|
119
|
+
cursor row.
|
|
120
|
+
- **16 colours**: the user's own palette resolves the roles; selection is achromatic (bold) there and dim is bright
|
|
121
|
+
black (`LANES_DIM=2` opts into SGR 2).
|
|
122
|
+
- **`selected`** is the cursor row (cockpit v3 P2): a background role taking the accent-wash the Zellij themes'
|
|
123
|
+
`*_selected` components and the phone's current row already use, with ink on it. It has no CSS variable of its own:
|
|
124
|
+
the phone needs none, and a copy per variant would cost bytes of `mobile.css`'s capped allowance.
|
|
125
|
+
- **Vivid tiers**: truecolor and 256 are the modes whose colours Lanes defines; the sidebar spends the palette there,
|
|
126
|
+
and `view.sh` (`LZ_VIVID`) the warning tone on its lead. 16 and none keep v1's bytes.
|
|
127
|
+
- **The 256-colour set**: one xterm index per painted role, always from 16–255 (fixed RGB; 0–15 are the user's
|
|
128
|
+
palette). Each is the nearest entry in its token's hue family — greys for the inks — that keeps every text role at
|
|
129
|
+
4.2:1 or more on surface, surface-raised and the 256 `selected` band; `selected` is the nearest entry to the wash.
|
|
130
|
+
Light accent and done share 22 (`#005f00`): the nearest passing entry, 23, is a teal. `test_tokens.Xterm256`
|
|
131
|
+
re-derives every index.
|
|
132
|
+
- **Palette16** is the lane-identity palette of the two places that define a palette: Zellij's `web_client { theme {} }`
|
|
133
|
+
(the phone's xterm.js; dark only) and the optional Ghostty file. A Zellij theme's legacy `black…white` keys are not one
|
|
134
|
+
of them (DEF-1413). Slots 1–4 are the four tones and 7/15 the ink pair; v2 re-saturates the rest. Every slot keeps
|
|
135
|
+
4.5:1.
|
|
136
|
+
- **Glyph positions** disambiguate shared twins: agent glyphs in column 2, the column-3 marks, stream glyphs in column 33,
|
|
137
|
+
the economy tail in column 34. In column 3, pinned `▲`/`^` (cockpit v3 R5; the lane leads its section and never falls
|
|
138
|
+
below `⋮ N more`) is the lowest mark; the leader `★`/`*` (the coordinator in the attention tone, the fleet admin in the
|
|
139
|
+
urgent tone; one glyph in two tones, W15 L2b/L2c) ranks above pinned and below pending `…`/`~` (cockpit v3 S8; a
|
|
140
|
+
registration on its way), the viewports `²`/`³` and the viewing mark `›`/`=`; the inbox `✉`/`&` (a message waiting for
|
|
141
|
+
the lane's agent, W15 L4) ranks below the leader and above the messaging-name mismatch `≠`/`/`. Every seven-bit twin
|
|
142
|
+
in column 3 is unique there.
|
|
143
|
+
- **Tone-less punctuation** (spec §3 completeness): every ` · ` and every quote the sidebar draws is a lookup, so
|
|
144
|
+
`LANES_GLYPHS=ascii` yields a seven-bit frame. `sep` shares `-` with `rule` and `dash` on purpose: none carries state.
|
|
145
|
+
The focus legend's arrow is `→`/`->` (cockpit v3 S4).
|
|
146
|
+
- **The fleet block** (W11): column 2 says what the row is about — Throttle `⚙`/`@`, a provider pool `◆`/`*`, the host
|
|
147
|
+
`▣`/`[` — in the row's worst tone, then a provider's ten-cell availability bar: usable `▰`/`=`, cooling `▱`/`~`, benched
|
|
148
|
+
`▪`/`:`, dead `·`/`.`. The twins are unique among the block's marks and against every other mark its rows draw. `#` is
|
|
149
|
+
the docs twin alone (`▤`, plan W10 W7).
|
|
150
|
+
|
|
151
|
+
## Changing a value
|
|
152
|
+
|
|
153
|
+
Edit `tokens.v1.json`, record the new styling digest under a new `theme.revisions` entry and set `theme.revision` to
|
|
154
|
+
it (`generate.py --check` prints the digest it expects), run `generate.py --write`, and commit the source with every
|
|
155
|
+
generated file in one commit. A meaning change bumps the revision so clients re-render rather than mix revisions; a
|
|
156
|
+
client holding an unknown revision falls back to the last one it validated (DM-LANES2-TOKENS).
|