@vibelord/lanes 1.6.0 → 1.7.0
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 +571 -4
- package/payload/lanes/client/ghostty/lanes-themed-window +12 -2
- package/payload/lanes/client/lanes-launch +21 -4
- package/payload/lanes/client/lanes-window +8 -0
- package/payload/lanes/container/lane +185 -5
- package/payload/lanes/container/lane-mcp +319 -55
- package/payload/lanes/container/lane-peerd +704 -0
- package/payload/lanes/container/lane_core.py +2091 -12
- package/payload/lanes/docs/AGENTS-lanes.md +50 -0
- package/payload/lanes/docs/ARCHITECTURE.md +274 -33
- package/payload/lanes/docs/DESIGN.md +7 -3
- package/payload/lanes/docs/INSTALL.md +5 -3
- package/payload/lanes/docs/RUNBOOK.md +288 -13
- package/payload/lanes/docs/USERGUIDE.md +218 -29
- package/payload/lanes/install.sh +5 -0
- package/payload/lanes/libexec/agent_state.py +338 -15
- package/payload/lanes/libexec/attach.py +154 -14
- package/payload/lanes/libexec/lanes_lib.py +429 -8
- package/payload/lanes/libexec/sidebar.py +464 -43
- package/payload/lanes/libexec/statusd.py +764 -34
- package/payload/lanes/libexec/tokens.py +14 -0
- package/payload/lanes/systemd/lanes-statusd.service +1 -1
- package/payload/manifest.json +4 -3
package/payload/lanes/bin/lanes
CHANGED
|
@@ -54,6 +54,43 @@
|
|
|
54
54
|
register undoes it); refused while tmux cannot check it. A record no workspace lists
|
|
55
55
|
any more is removed from registered-sessions.json. A lane declared in a repository's
|
|
56
56
|
terminals.json is refused with the file to edit
|
|
57
|
+
lanes address list [<board>] every lane's registered address (<board>.<slug>: its id with `--` turned into `.`, or
|
|
58
|
+
its board manifest's `addresses` override), its role (coordinator / fleet-admin) and
|
|
59
|
+
whether its Claude session name is that address (yes / no / - for no Claude session);
|
|
60
|
+
then the fleet admin and the boards without a coordinator
|
|
61
|
+
lanes address set <lane-id> <board>.<alias>
|
|
62
|
+
give a repository lane another address: `addresses[<terminal name>]` in its
|
|
63
|
+
workspaces.<board>.json (alias: a-z 0-9 . _ -, no `--`, which Claude refuses as a
|
|
64
|
+
name; a leading @ is dropped; its derived address again removes the override), only
|
|
65
|
+
that member rewritten, a .bak-<UTC> copy on the manifest's first write, then synced.
|
|
66
|
+
Refused, nothing written, while another lane answers to the address; a sync that
|
|
67
|
+
refuses the result puts the manifest back
|
|
68
|
+
lanes address set-coordinator <board> <lane-id>
|
|
69
|
+
make one of the board's declared lanes its coordinator (`coordinator` in its manifest:
|
|
70
|
+
`@<board>` reaches it, it alone may message the fleet admin), then sync
|
|
71
|
+
lanes names sync [--board B] [--write]
|
|
72
|
+
Claude lanes whose session name is not their address. Dry run by default: what it would
|
|
73
|
+
type and the lanes it leaves for later (working, waiting for an approval, delegating,
|
|
74
|
+
output in the last 20 s, not observed). --write types `/rename <address>` and Enter
|
|
75
|
+
into each of the others, after reading its session file again (only Claude's own
|
|
76
|
+
`idle`, one session in the lane, a name that differs). Exit 1 when tmux did not take
|
|
77
|
+
one; statusd retries the busy ones while site.conf's LANES_NAMES_AUTO is not 0
|
|
78
|
+
lanes migrate addresses [--write] [--board B]
|
|
79
|
+
the fleet's move to registered addresses, idempotent: `coordinator` in every board
|
|
80
|
+
manifest that has none (the lane whose slug is the board id, else the first declared;
|
|
81
|
+
each choice printed, `lanes address set-coordinator` changes it) and, without --board,
|
|
82
|
+
LANES_FLEET_ADMIN=@fleet-management.fleet-management appended to site.conf when unset;
|
|
83
|
+
collisions among addresses are reported. Dry run by default (the diffs). --write
|
|
84
|
+
copies every file it changes to ~/.local/state/lanes/migrations/<UTC stamp>/ with a
|
|
85
|
+
receipt.json, writes, validates the site again (a board error or a collision that was
|
|
86
|
+
not there before puts every file back, exit 1) and syncs. Exit 0 when nothing is left
|
|
87
|
+
to change
|
|
88
|
+
lanes message [--from <login>] [--ttl S] <lane-id|@address> <text...>
|
|
89
|
+
a person's message to a lane of any container (W15 L4, BEY-6842; the sidebar's `m`):
|
|
90
|
+
sender host:<login> (this account's name without --from), the text in one envelope
|
|
91
|
+
written into the lane's inbox (~/.lz/state/inbox/<lane>/ through the home volume),
|
|
92
|
+
typed at once when the lane is idle at its prompt, else queued — lanes-statusd types
|
|
93
|
+
it when the lane is next idle with no terminal attached; ttl 24 h by default
|
|
57
94
|
lanes workspaces print the board ids (what the client installer reads)
|
|
58
95
|
lanes workspaces add <id> --container <name> --repo <path> [--title T] [--session S] [--write]
|
|
59
96
|
add a board to the site catalog (catalog.json + a new workspaces.<id>.json whose one
|
|
@@ -214,7 +251,9 @@
|
|
|
214
251
|
(site.conf LANES_THROTTLE_CONTAINER, else the registry's Throttle Monitor container)
|
|
215
252
|
its loop is started, once: `docker exec -d -u 1000 -e HOME=/home/coder <name> tmux -L
|
|
216
253
|
lanes-pulse new -d -s pulse ~/.lz/bin/throttle-pulse --loop` (nothing when that
|
|
217
|
-
session already runs; exit 1 when docker refused the start)
|
|
254
|
+
session already runs; exit 1 when docker refused the start). lane-peerd (W15 L6) ships
|
|
255
|
+
to every container; lanes-statusd starts its loop there (`tmux -L lanes-peers`,
|
|
256
|
+
site.conf LANES_PEERS=0 never)
|
|
218
257
|
lanes throttle adopt-token <container>
|
|
219
258
|
the operator's opt-in to the pulse's burn and money lines: copy env.ANTHROPIC_API_KEY
|
|
220
259
|
of the container's own ~/.claude/settings.json — the LOCAL Throttle client bearer, it
|
|
@@ -303,6 +342,9 @@
|
|
|
303
342
|
the lanes per create-recipe class (idempotent / attach-only / null / external /
|
|
304
343
|
retired-path), lane identity, numeric session names, crowded `default` sockets and
|
|
305
344
|
orphan tmux socket files (report only; in a container `lane gc --sockets` removes them),
|
|
345
|
+
the lane addresses (⚠ boards without a coordinator, ✗ two lanes on one address, ⚠ the
|
|
346
|
+
fleet admin unset or naming no lane, ⚠ `addresses` keys naming no terminal, and per
|
|
347
|
+
container how many Claude lanes' session names are their addresses),
|
|
306
348
|
any record left in the retired legacy-sessions/ directory, the devices without an owner
|
|
307
349
|
(each keeps its look to itself: `lanes device claim`), and the browser/phone half:
|
|
308
350
|
lanes-web / lanes-mobile units (⚠ not enabled, ✗ enabled but not running), the login-token
|
|
@@ -391,6 +433,9 @@
|
|
|
391
433
|
Without --yes or off a terminal: the plan, exit 2
|
|
392
434
|
"""
|
|
393
435
|
import contextlib
|
|
436
|
+
import copy
|
|
437
|
+
import difflib
|
|
438
|
+
import hashlib
|
|
394
439
|
import json
|
|
395
440
|
import math
|
|
396
441
|
import os
|
|
@@ -422,6 +467,8 @@ PROC = Path(os.environ.get('LANES_PROC_ROOT') or '/proc') # injectable for the
|
|
|
422
467
|
# runs `lanes attach|ensure|rebuild` decides them for the view sessions it creates. A device's recorded LOOK_KEYS still
|
|
423
468
|
# win over them (sidebar.resolve_modes / resolve_dim_notify).
|
|
424
469
|
LOOK_ENV = ('LANES_COLOR', 'LANES_THEME', 'LANES_GLYPHS', 'LANES_DIM', 'LANES_NOTIFY')
|
|
470
|
+
# `lanes attach` hands only these to its display supervisor (libexec/attach.py BACKLOG_ENV/STALL_ENV), never to a session.
|
|
471
|
+
DISPLAY_ENV = ('LANES_DISPLAY_BACKLOG_BYTES', 'LANES_DISPLAY_STALL_S')
|
|
425
472
|
|
|
426
473
|
|
|
427
474
|
def clean_env(extra=None):
|
|
@@ -1169,9 +1216,14 @@ def cmd_attach(args):
|
|
|
1169
1216
|
'COLORTERM': os.environ.get('COLORTERM', 'truecolor')})
|
|
1170
1217
|
if L.run_bounded(['infocmp', env['TERM']], 5)[0] != 0: # unknown here — or no answer: the safe default
|
|
1171
1218
|
env['TERM'] = 'xterm-256color'
|
|
1219
|
+
for key in DISPLAY_ENV: # the operator's display limits, validated by the supervisor; nothing else passes
|
|
1220
|
+
if os.environ.get(key):
|
|
1221
|
+
env[key] = os.environ[key]
|
|
1172
1222
|
# Own the terminal backlog as well as SSH's transport. A slow Zellij 0.45.1
|
|
1173
1223
|
# client can stay alive after its server has dropped it (Exit is behind the
|
|
1174
1224
|
# queued frames); keepalives alone cannot make lanes-launch reconnect it.
|
|
1225
|
+
# The supervisor keeps reading it, sheds what a slow terminal cannot take
|
|
1226
|
+
# and repaints; only a terminal that takes nothing ends the display.
|
|
1175
1227
|
os.execve(sys.executable, [sys.executable, str(L.REPO / 'libexec/attach.py'),
|
|
1176
1228
|
*ZELLIJ_BASE, 'attach', device], env)
|
|
1177
1229
|
|
|
@@ -1222,7 +1274,9 @@ def hook_env(home):
|
|
|
1222
1274
|
|
|
1223
1275
|
INSTALL_CONTAINER_USAGE = 'usage: lanes install-container <name> [--no-mcp]'
|
|
1224
1276
|
# lane_core.py first: `lane` imports it, so no moment has a new `lane` beside an old (or no) lane_core.py.
|
|
1225
|
-
|
|
1277
|
+
# W15 L6 (BEY-6843): lane-peerd ships to every container too; lanes-statusd starts its loop (statusd.rearm_peerd).
|
|
1278
|
+
CONTRACT_FILES = ('lane_core.py', 'lane-mcp', 'lane', 'lane-run', 'lane-signal', 'lane-edit', 'throttle-pulse',
|
|
1279
|
+
'lane-peerd')
|
|
1226
1280
|
# The Throttle pulse (W11): installed everywhere, its loop started only in the daemon's container. As uid 1000 with
|
|
1227
1281
|
# the container home as HOME, whatever user the image defaults to: it writes ~/.lz/state/throttle.json, which
|
|
1228
1282
|
# lanes-statusd reads, and reads ~/.lz/throttle-token, which only the container's own user may read (0600).
|
|
@@ -1306,6 +1360,30 @@ def install_mcp_entries(home):
|
|
|
1306
1360
|
return code
|
|
1307
1361
|
|
|
1308
1362
|
|
|
1363
|
+
def codex_hook_step(container, home):
|
|
1364
|
+
"""W15 L3 (Linear BEY-6841): the gated Codex step `lanes install-container` prints for a container whose home
|
|
1365
|
+
has a real ~/.codex (read before the install writes Codex's MCP entry, which creates it) -> [line]. The Codex
|
|
1366
|
+
hooks record each Codex lane's thread id (lane-signal's `session`), which makes the lane addressable by `codex
|
|
1367
|
+
queue --thread`; they are the operator's opt-in (`lanes hooks install --agent codex`, a dry run until --write;
|
|
1368
|
+
Codex asks a person to trust them). Until then lane-mcp matches a thread through Codex's own app-server
|
|
1369
|
+
(lane_core.codex_handles). Nothing is read through a link: a linked ~/.codex is no Codex home here, a linked
|
|
1370
|
+
hooks.json no install. [] without ~/.codex."""
|
|
1371
|
+
codex = Path(home) / '.codex'
|
|
1372
|
+
try:
|
|
1373
|
+
if not stat.S_ISDIR(os.lstat(codex).st_mode):
|
|
1374
|
+
return []
|
|
1375
|
+
except OSError:
|
|
1376
|
+
return []
|
|
1377
|
+
hooks = lane_core().read_regular(codex / 'hooks.json', 1 << 20)
|
|
1378
|
+
if hooks is not None and b'lane-signal' in hooks:
|
|
1379
|
+
return ['Codex hooks: lane-signal installed — each Codex lane\'s thread id reaches lanes_status `handle` at '
|
|
1380
|
+
'its next turn']
|
|
1381
|
+
return [f'Codex lanes: lanes hooks install --agent codex --container {container} (a dry run; add --write) records '
|
|
1382
|
+
'each Codex lane\'s thread id at its next turn, so a lane message reaches it by `codex queue --thread`; '
|
|
1383
|
+
'Codex asks a person to trust new hooks before it runs them. Until then lane-mcp matches each Codex lane '
|
|
1384
|
+
'to its thread through Codex\'s app-server (handle `via: app-server`)']
|
|
1385
|
+
|
|
1386
|
+
|
|
1309
1387
|
def cmd_install_container(args):
|
|
1310
1388
|
names = [word for word in args if word != '--no-mcp']
|
|
1311
1389
|
if len(names) != 1 or names[0].startswith('-'):
|
|
@@ -1317,6 +1395,7 @@ def cmd_install_container(args):
|
|
|
1317
1395
|
raise L.LanesError(f'{container}: home volume not found')
|
|
1318
1396
|
home = Path(info['home'])
|
|
1319
1397
|
root = home / '.lz'
|
|
1398
|
+
codex_step = codex_hook_step(container, home) # W15 L3: before the MCP entry creates ~/.codex
|
|
1320
1399
|
# Every directory is a real one and every file lands by rename (DEF-1798): nothing is written through a link.
|
|
1321
1400
|
for sub in ('bin', 's', 'meta', 'state', 'hooks'):
|
|
1322
1401
|
container_dir(home, '.lz', sub)
|
|
@@ -1346,11 +1425,13 @@ def cmd_install_container(args):
|
|
|
1346
1425
|
if link.is_symlink() or link.exists():
|
|
1347
1426
|
link.unlink()
|
|
1348
1427
|
link.symlink_to(root)
|
|
1349
|
-
print(f"installed {root}/bin/{{lane,lane_core.py,lane-run,lane-signal,lane-edit,throttle-pulse"
|
|
1428
|
+
print(f"installed {root}/bin/{{lane,lane_core.py,lane-run,lane-signal,lane-edit,throttle-pulse,lane-peerd"
|
|
1350
1429
|
f"{'' if no_mcp else ',lane-mcp'},zmx-*}}, "
|
|
1351
1430
|
f'{root}/VERSION, {root}/vimrc, {root}/hooks/' + (f' and {root}/env.sh' if env_file.exists() else '')
|
|
1352
1431
|
+ f'; host link {link} -> {root}')
|
|
1353
1432
|
pulse = start_pulse(container)
|
|
1433
|
+
for line in codex_step:
|
|
1434
|
+
print(line)
|
|
1354
1435
|
if no_mcp:
|
|
1355
1436
|
print('--no-mcp: lane-mcp and the agents\' MCP entries left out (anything an earlier install wrote is kept)')
|
|
1356
1437
|
return pulse
|
|
@@ -5389,6 +5470,12 @@ def cmd_doctor(_args):
|
|
|
5389
5470
|
print(f' {line}')
|
|
5390
5471
|
for warning in warnings + socket_report(containers, SD.live_by_container):
|
|
5391
5472
|
print(f'⚠ {warning}')
|
|
5473
|
+
# W15 L2/L2b/L2c: coordinators, unique addresses, the fleet admin, Claude names = addresses per container.
|
|
5474
|
+
for mark, text in address_doctor(registry, L.read_json(L.STATE / 'status.json') or {}):
|
|
5475
|
+
if mark in ('⚠', ''):
|
|
5476
|
+
print(f'{mark or " "} {text}')
|
|
5477
|
+
else:
|
|
5478
|
+
check(mark == '✓', text)
|
|
5392
5479
|
# Plan Task 19 retired the pre-persistence Docker-shell tracker. A record still in its directory is inert (never
|
|
5393
5480
|
# observed, never closable from the sidebar): name it, so the operator ends that shell by hand and removes it.
|
|
5394
5481
|
legacy = sorted(p.stem for p in (L.STATE / 'legacy-sessions').glob('*.json'))
|
|
@@ -5545,6 +5632,485 @@ def cmd_rename(args):
|
|
|
5545
5632
|
return 0
|
|
5546
5633
|
|
|
5547
5634
|
|
|
5635
|
+
# ------------------------------------------------------------------ addresses (W15 L2, L2b, L2c, L2d)
|
|
5636
|
+
# A lane's registered address is `<board>.<slug>` (lanes_lib.address_of) or its board manifest's `addresses` override;
|
|
5637
|
+
# a board's coordinator is its manifest's `coordinator`; the fleet admin is site.conf's LANES_FLEET_ADMIN. The verbs
|
|
5638
|
+
# below are their writers, editing a manifest the way `lanes rename` edits `displayNames` (atomic, a `.bak-<UTC>` copy
|
|
5639
|
+
# on the first write) but byte-preserving (lane_core.set_member: only the member that changes is rewritten), then
|
|
5640
|
+
# syncing; a sync that refuses the result gets the manifest back.
|
|
5641
|
+
|
|
5642
|
+
ADDRESS_USAGE = ('usage: lanes address list [<board>] | lanes address set <lane-id> <board>.<alias> | '
|
|
5643
|
+
'lanes address set-coordinator <board> <lane-id>')
|
|
5644
|
+
NAMES_USAGE = 'usage: lanes names sync [--board B] [--write]'
|
|
5645
|
+
MIGRATE_USAGE = 'usage: lanes migrate addresses [--write] [--board B]'
|
|
5646
|
+
MIGRATIONS = 'migrations' # under the state directory: one <UTC stamp>/ per `lanes migrate addresses --write`
|
|
5647
|
+
|
|
5648
|
+
|
|
5649
|
+
def flag_args(args, usage, flags=('--write',), values=('--board',)):
|
|
5650
|
+
"""(set of the `flags` given, {value flag: its value}) of `args`; LanesError(usage) for anything else."""
|
|
5651
|
+
given, found, rest = set(), {}, list(args)
|
|
5652
|
+
while rest:
|
|
5653
|
+
word = rest.pop(0)
|
|
5654
|
+
if word in flags:
|
|
5655
|
+
given.add(word)
|
|
5656
|
+
elif word in values and rest:
|
|
5657
|
+
found[word] = rest.pop(0)
|
|
5658
|
+
else:
|
|
5659
|
+
raise L.LanesError(usage)
|
|
5660
|
+
return given, found
|
|
5661
|
+
|
|
5662
|
+
|
|
5663
|
+
def board_of(registry, board_id):
|
|
5664
|
+
board = next((w for w in registry['workspaces'] if w['id'] == board_id), None)
|
|
5665
|
+
if board is None:
|
|
5666
|
+
raise L.LanesError(f'Unknown workspace: {board_id}')
|
|
5667
|
+
return board
|
|
5668
|
+
|
|
5669
|
+
|
|
5670
|
+
def declared_lane(registry, lane_id, what):
|
|
5671
|
+
"""(board, lane) of a lane a repository declares (its terminal is in the board manifest's reach); LanesError for
|
|
5672
|
+
an unknown id and for an adopted session, an SSH pane or a tool, which have no terminal name."""
|
|
5673
|
+
for board in registry['workspaces']:
|
|
5674
|
+
for lane in board['lanes']:
|
|
5675
|
+
if lane['id'] == lane_id:
|
|
5676
|
+
if lane.get('registered_session') or not lane.get('registry_name') or not lane.get('repo'):
|
|
5677
|
+
raise L.LanesError(f'{lane_id} is no repository lane: {what} names a terminal of a '
|
|
5678
|
+
"repository's terminals.json (an adopted session keeps its derived address; "
|
|
5679
|
+
'promote it with P to name it)')
|
|
5680
|
+
return board, lane
|
|
5681
|
+
raise L.LanesError(f'Unknown lane: {lane_id}')
|
|
5682
|
+
|
|
5683
|
+
|
|
5684
|
+
def manifest_member(text, path, key, value):
|
|
5685
|
+
"""`text` (a board manifest) with the member `key` of the object at `path` set to `value` (None: removed) — every
|
|
5686
|
+
other byte kept (lane_core.set_member / remove_member, the in-container terminals.json editor)."""
|
|
5687
|
+
C = L.lane_core()
|
|
5688
|
+
try:
|
|
5689
|
+
return C.set_member(text, path, key, value) if value is not None else C.remove_member(text, path, key)
|
|
5690
|
+
except C.LaneError as error:
|
|
5691
|
+
raise L.LanesError(f'the manifest cannot be edited: {error}') from error
|
|
5692
|
+
|
|
5693
|
+
|
|
5694
|
+
def manifest_addresses(text, name, address):
|
|
5695
|
+
"""`text` with `addresses[name]` = `address` (None: the override removed)."""
|
|
5696
|
+
current = json.loads(text).get('addresses')
|
|
5697
|
+
if address is None:
|
|
5698
|
+
return manifest_member(text, ['addresses'], name, None) if isinstance(current, dict) and name in current else text
|
|
5699
|
+
if isinstance(current, dict):
|
|
5700
|
+
return manifest_member(text, ['addresses'], name, address)
|
|
5701
|
+
return manifest_member(text, [], 'addresses', {name: address})
|
|
5702
|
+
|
|
5703
|
+
|
|
5704
|
+
def edit_manifest(path, change):
|
|
5705
|
+
"""Read, change and write one board manifest under registry_lock -> its text before (None when `change` changed
|
|
5706
|
+
nothing). Written atomically with its own mode; the first write keeps `<manifest>.bak-<UTC>` beside it
|
|
5707
|
+
(session_actions.rename_registered's idiom)."""
|
|
5708
|
+
path = Path(path)
|
|
5709
|
+
with L.registry_lock():
|
|
5710
|
+
before = path.read_text()
|
|
5711
|
+
after = change(before)
|
|
5712
|
+
if after == before:
|
|
5713
|
+
return None
|
|
5714
|
+
json.loads(after) # the editor keeps JSON valid; a slip here must never reach the file
|
|
5715
|
+
if not any(path.parent.glob(path.name + '.bak-*')):
|
|
5716
|
+
L.atomic_write(path.parent / (path.name + '.bak-' + time.strftime('%Y%m%dT%H%M%SZ', time.gmtime())),
|
|
5717
|
+
before, mode=0o644)
|
|
5718
|
+
L.atomic_write(path, after, mode=stat.S_IMODE(path.stat().st_mode))
|
|
5719
|
+
return before
|
|
5720
|
+
|
|
5721
|
+
|
|
5722
|
+
def publish_manifest(path, before, board_id, what):
|
|
5723
|
+
"""`lanes sync` after a manifest edit. A sync that refuses the site (two lanes on one address) or reports an error
|
|
5724
|
+
on this board puts `before` back and syncs again, so the boards show what they showed: LanesError naming why."""
|
|
5725
|
+
try:
|
|
5726
|
+
failed, refused = sync_registry()
|
|
5727
|
+
problem = next((e for w in failed if w['id'] == board_id for e in w['errors']), None)
|
|
5728
|
+
except L.LanesError as error:
|
|
5729
|
+
problem = str(error)
|
|
5730
|
+
if problem:
|
|
5731
|
+
L.atomic_write(path, before, mode=stat.S_IMODE(Path(path).stat().st_mode))
|
|
5732
|
+
try:
|
|
5733
|
+
sync_registry()
|
|
5734
|
+
except L.LanesError:
|
|
5735
|
+
pass
|
|
5736
|
+
raise L.LanesError(f'{what} refused by lanes sync, the manifest is back as it was: {problem}')
|
|
5737
|
+
if refused:
|
|
5738
|
+
raise L.ProjectionRefused(what, refused)
|
|
5739
|
+
|
|
5740
|
+
|
|
5741
|
+
def address_list(board_id=None):
|
|
5742
|
+
registry = L.load_registry()
|
|
5743
|
+
boards = [board_of(registry, board_id)] if board_id else registry['workspaces']
|
|
5744
|
+
rows = (L.read_json(L.STATE / 'status.json') or {}).get('lanes') or {}
|
|
5745
|
+
facts = L.lane_addresses(registry)
|
|
5746
|
+
table = [('LANE', 'ADDRESS', 'ROLE', 'NAME MATCH')]
|
|
5747
|
+
for board in boards:
|
|
5748
|
+
for lane in board['lanes']:
|
|
5749
|
+
address, role = facts[lane['id']]
|
|
5750
|
+
agent = (rows.get(lane['id']) or {}).get('agent') or {}
|
|
5751
|
+
match = agent.get('name_match') if isinstance(agent, dict) else None
|
|
5752
|
+
table.append((lane['id'], address, role or '-', 'yes' if match is True else 'no' if match is False else '-'))
|
|
5753
|
+
widths = [max(len(row[i]) for row in table) for i in range(3)]
|
|
5754
|
+
for row in table:
|
|
5755
|
+
print(' '.join(cell.ljust(widths[i]) for i, cell in enumerate(row[:3])) + ' ' + row[3])
|
|
5756
|
+
fleet = registry.get('fleet_admin')
|
|
5757
|
+
print(f'fleet admin: @{fleet}' if fleet else 'fleet admin: unset (LANES_FLEET_ADMIN in ~/.config/lanes/site.conf; '
|
|
5758
|
+
'lanes migrate addresses)')
|
|
5759
|
+
without = [board['id'] for board in boards if board.get('lanes') and not board.get('coordinator')
|
|
5760
|
+
and not board.get('attach_only')]
|
|
5761
|
+
if without:
|
|
5762
|
+
print('boards without a coordinator: ' + ', '.join(without) + ' (lanes address set-coordinator <board> <lane-id>)')
|
|
5763
|
+
return 0
|
|
5764
|
+
|
|
5765
|
+
|
|
5766
|
+
def address_set(lane_id, value):
|
|
5767
|
+
registry = L.load_registry()
|
|
5768
|
+
board, lane = declared_lane(registry, lane_id, 'an address override')
|
|
5769
|
+
address = L.check_address(board['id'], L.parse_address(value))
|
|
5770
|
+
name = lane['registry_name']
|
|
5771
|
+
target = None if address == L.address_of(lane_id, board=board['id']) else address
|
|
5772
|
+
trial = copy.deepcopy(registry) # the registry as it would be: refused while another lane answers to it
|
|
5773
|
+
overrides = dict(board_of(trial, board['id']).get('address_overrides') or {})
|
|
5774
|
+
overrides.pop(name, None)
|
|
5775
|
+
if target:
|
|
5776
|
+
overrides[name] = target
|
|
5777
|
+
board_of(trial, board['id'])['address_overrides'] = overrides
|
|
5778
|
+
clash = next((c for c in L.apply_addresses(trial, strict=False) if lane_id in c[1:]), None)
|
|
5779
|
+
if clash:
|
|
5780
|
+
other = clash[1] if clash[2] == lane_id else clash[2]
|
|
5781
|
+
raise L.LanesError(f'{address} is the address of {other}: nothing written')
|
|
5782
|
+
path = L.manifest_path(board['id'])
|
|
5783
|
+
before = edit_manifest(path, lambda text: manifest_addresses(text, name, target))
|
|
5784
|
+
if before is None:
|
|
5785
|
+
print(f'{lane_id}: address {address} already (nothing written)')
|
|
5786
|
+
return 0
|
|
5787
|
+
publish_manifest(path, before, board['id'], 'Address')
|
|
5788
|
+
print(f'{lane_id} ({name!r}): address {address}' + ('' if target else ' (its derived address: override removed)'))
|
|
5789
|
+
return 0
|
|
5790
|
+
|
|
5791
|
+
|
|
5792
|
+
def address_set_coordinator(board_id, lane_id):
|
|
5793
|
+
registry = L.load_registry()
|
|
5794
|
+
board = board_of(registry, board_id)
|
|
5795
|
+
owner, lane = declared_lane(registry, lane_id, 'a coordinator')
|
|
5796
|
+
if owner['id'] != board_id:
|
|
5797
|
+
raise L.LanesError(f'{lane_id} is a lane of {owner["id"]}, not of {board_id}')
|
|
5798
|
+
path = L.manifest_path(board_id)
|
|
5799
|
+
before = edit_manifest(path, lambda text: manifest_member(text, [], 'coordinator', lane['registry_name']))
|
|
5800
|
+
if before is None:
|
|
5801
|
+
print(f'{board_id}: coordinator {lane_id} already (nothing written)')
|
|
5802
|
+
return 0
|
|
5803
|
+
publish_manifest(path, before, board_id, 'Coordinator')
|
|
5804
|
+
print(f"{board_id}: coordinator {lane_id} ({lane['registry_name']!r}, @{lane.get('address') or L.address_of(lane_id)})"
|
|
5805
|
+
+ (f' — was {board["coordinator"]}' if board.get('coordinator') else ''))
|
|
5806
|
+
return 0
|
|
5807
|
+
|
|
5808
|
+
|
|
5809
|
+
def cmd_address(args):
|
|
5810
|
+
if args[:1] == ['list'] and len(args) <= 2:
|
|
5811
|
+
return address_list(args[1] if len(args) == 2 else None)
|
|
5812
|
+
if args[:1] == ['set'] and len(args) == 3:
|
|
5813
|
+
return address_set(args[1], args[2])
|
|
5814
|
+
if args[:1] == ['set-coordinator'] and len(args) == 3:
|
|
5815
|
+
return address_set_coordinator(args[1], args[2])
|
|
5816
|
+
raise L.LanesError(ADDRESS_USAGE)
|
|
5817
|
+
|
|
5818
|
+
|
|
5819
|
+
MESSAGE_USAGE = 'usage: lanes message [--from <login>] [--ttl S] [--] <lane-id|@address> <text...>'
|
|
5820
|
+
|
|
5821
|
+
|
|
5822
|
+
def cmd_message(args):
|
|
5823
|
+
"""lanes message [--from <login>] [--ttl S] <lane-id|@address> <text...> (W15 L4): a person's message to a lane of
|
|
5824
|
+
any container on this site, sender `host:<login>` (the login given, else this account's name) — written into the
|
|
5825
|
+
lane's inbox through its container's home volume, then typed at once when the lane is idle at its prompt, else left
|
|
5826
|
+
`queued` for lanes-statusd, which types it when the lane is next idle with no terminal attached. The sidebar's `m`
|
|
5827
|
+
runs this verb. Exit 0 once the message is in the inbox, typed or not; a refusal is exit 1 (main's LanesError)."""
|
|
5828
|
+
import pwd as _pwd
|
|
5829
|
+
import statusd as SD
|
|
5830
|
+
C = L.lane_core()
|
|
5831
|
+
rest, login, ttl = list(args), None, C.MESSAGE_TTL_S
|
|
5832
|
+
while rest and rest[0].startswith('--'):
|
|
5833
|
+
word = rest.pop(0)
|
|
5834
|
+
if word == '--':
|
|
5835
|
+
break
|
|
5836
|
+
if word == '--from' and rest:
|
|
5837
|
+
login = rest.pop(0)
|
|
5838
|
+
elif word == '--ttl' and rest and rest[0].isdigit():
|
|
5839
|
+
ttl = int(rest.pop(0))
|
|
5840
|
+
else:
|
|
5841
|
+
raise L.LanesError(MESSAGE_USAGE)
|
|
5842
|
+
if len(rest) < 2:
|
|
5843
|
+
raise L.LanesError(MESSAGE_USAGE)
|
|
5844
|
+
if not C.MESSAGE_TTL_MIN <= ttl <= C.MESSAGE_TTL_MAX:
|
|
5845
|
+
raise L.LanesError(f'--ttl is {C.MESSAGE_TTL_MIN} to {C.MESSAGE_TTL_MAX} seconds')
|
|
5846
|
+
to, text = rest[0], ' '.join(rest[1:])
|
|
5847
|
+
sender = 'host:' + (login or _pwd.getpwuid(os.getuid()).pw_name)
|
|
5848
|
+
if not C.HOST_SENDER.fullmatch(sender):
|
|
5849
|
+
raise L.LanesError(f'--from {login!r}: one login of letters, digits and . _ @ + -')
|
|
5850
|
+
try:
|
|
5851
|
+
C.check_message(text)
|
|
5852
|
+
except C.LaneError as error:
|
|
5853
|
+
raise L.LanesError(f'{error} ({error.code})') from None
|
|
5854
|
+
registry = L.load_registry()
|
|
5855
|
+
payload = L.read_json(L.STATE / 'status.json', {}) or {}
|
|
5856
|
+
lane_id = SD.resolve_lane(registry, payload, to)
|
|
5857
|
+
place = SD.lane_places(registry, payload)[lane_id]
|
|
5858
|
+
address = (L.lane_addresses(registry).get(lane_id) or (L.address_of(lane_id), None))[0]
|
|
5859
|
+
info = (L.read_json(L.STATE / 'containers.json', {}) or {}).get(place.get('container') or '') or {}
|
|
5860
|
+
row = (payload.get('lanes') or {}).get(lane_id)
|
|
5861
|
+
message_id, outcome, detail = SD.host_message(place, row, info, lane_id, address, sender, text, ttl)
|
|
5862
|
+
if outcome in ('typed', 'typed-no-enter'):
|
|
5863
|
+
print(f'message {message_id} to @{address}: {outcome} ({detail})' if outcome != 'typed'
|
|
5864
|
+
else f'message {message_id} to @{address}: typed')
|
|
5865
|
+
else:
|
|
5866
|
+
print(f'message {message_id} to @{address}: queued — lanes-statusd types it when the lane is next idle '
|
|
5867
|
+
f'({detail})')
|
|
5868
|
+
return 0
|
|
5869
|
+
|
|
5870
|
+
|
|
5871
|
+
def cmd_names(args):
|
|
5872
|
+
"""lanes names sync [--board B] [--write] (W15 L2c): a Claude lane's session name is its address."""
|
|
5873
|
+
if args[:1] != ['sync']:
|
|
5874
|
+
raise L.LanesError(NAMES_USAGE)
|
|
5875
|
+
given, values = flag_args(args[1:], NAMES_USAGE)
|
|
5876
|
+
registry = L.load_registry()
|
|
5877
|
+
board = values.get('--board')
|
|
5878
|
+
if board:
|
|
5879
|
+
board_of(registry, board)
|
|
5880
|
+
status = L.read_json(L.STATE / 'status.json') or {}
|
|
5881
|
+
todo, deferred, matched = L.names_plan(registry, status, board)
|
|
5882
|
+
containers = L.read_json(L.STATE / 'containers.json') or {}
|
|
5883
|
+
write, counts = '--write' in given, {}
|
|
5884
|
+
for _board, lane, row in todo:
|
|
5885
|
+
address = row.get('address') or lane.get('address') or L.address_of(lane['id'])
|
|
5886
|
+
current = (((row.get('agent') or {}).get('messaging')) or {}).get('name')
|
|
5887
|
+
if not write:
|
|
5888
|
+
print(f"would rename {lane['id']} {current!r} -> {address}")
|
|
5889
|
+
counts['to rename'] = counts.get('to rename', 0) + 1
|
|
5890
|
+
continue
|
|
5891
|
+
outcome, detail = L.rename_claude(lane, address, containers.get(lane['container']) or {})
|
|
5892
|
+
print(f"{outcome:<12} {lane['id']}: {detail}")
|
|
5893
|
+
counts[outcome] = counts.get(outcome, 0) + 1
|
|
5894
|
+
for _board, lane, why in deferred:
|
|
5895
|
+
print(f"deferred {lane['id']}: {why}")
|
|
5896
|
+
counts['deferred'] = counts.get('deferred', 0) + len(deferred)
|
|
5897
|
+
print(', '.join(f'{n} {what}' for what, n in counts.items()) + f', {matched} already match'
|
|
5898
|
+
+ ('' if write else ' — dry run: --write types /rename <address> + Enter into each lane to rename'))
|
|
5899
|
+
return 1 if counts.get('failed') else 0
|
|
5900
|
+
|
|
5901
|
+
|
|
5902
|
+
def site_check():
|
|
5903
|
+
"""`lanes sync`'s validation without publishing: the registry built from the site as it is now (two lanes on one
|
|
5904
|
+
address left in place, `strict=False`) -> (registry, None), or (None, why) when the site cannot be built at all."""
|
|
5905
|
+
try:
|
|
5906
|
+
return L.build_registry(L.read_json(L.STATE / 'registry.json'), strict=False), None
|
|
5907
|
+
except (L.LanesError, OSError, ValueError, KeyError) as error:
|
|
5908
|
+
return None, str(error)
|
|
5909
|
+
|
|
5910
|
+
|
|
5911
|
+
def site_findings(registry):
|
|
5912
|
+
"""(board errors, address clashes) of a `site_check` registry, as sets a before/after comparison can subtract."""
|
|
5913
|
+
errors = {(board['id'], error) for board in registry['workspaces'] for error in board['errors']}
|
|
5914
|
+
clashes = {tuple(clash) for clash in L.apply_addresses(copy.deepcopy(registry), strict=False)}
|
|
5915
|
+
return errors, clashes
|
|
5916
|
+
|
|
5917
|
+
|
|
5918
|
+
def findings_line(errors, clashes):
|
|
5919
|
+
return (f'{len(errors)} board error{"s" if len(errors) != 1 else ""}, {len(clashes)} address '
|
|
5920
|
+
f'clash{"es" if len(clashes) != 1 else ""}')
|
|
5921
|
+
|
|
5922
|
+
|
|
5923
|
+
def migration_plan(registry, board_id):
|
|
5924
|
+
"""[(path, text before, text after, what)] of `lanes migrate addresses`, printing each decision."""
|
|
5925
|
+
changes = []
|
|
5926
|
+
for board in registry['workspaces']:
|
|
5927
|
+
if board.get('attach_only') or (board_id and board['id'] != board_id):
|
|
5928
|
+
continue
|
|
5929
|
+
path = L.manifest_path(board['id'])
|
|
5930
|
+
text = path.read_text()
|
|
5931
|
+
current = json.loads(text).get('coordinator')
|
|
5932
|
+
if current is not None:
|
|
5933
|
+
print(f" {board['id']}: coordinator {current!r} kept")
|
|
5934
|
+
continue
|
|
5935
|
+
if board['errors']:
|
|
5936
|
+
print(f" {board['id']}: has errors ({board['errors'][0]}): no coordinator written — fix it, run again")
|
|
5937
|
+
continue
|
|
5938
|
+
declared = [lane for lane in board['lanes'] if lane.get('registry_name') and not lane.get('registered_session')]
|
|
5939
|
+
if not declared:
|
|
5940
|
+
print(f" {board['id']}: no declared lane: no coordinator")
|
|
5941
|
+
continue
|
|
5942
|
+
pick = next((lane for lane in declared if lane['id'] == f"{board['id']}--{board['id']}"), None)
|
|
5943
|
+
rule = 'its slug is the board id' if pick else 'the first declared lane'
|
|
5944
|
+
pick = pick or declared[0]
|
|
5945
|
+
changes.append((path, text, manifest_member(text, [], 'coordinator', pick['registry_name']),
|
|
5946
|
+
f"{board['id']}: coordinator {pick['registry_name']!r}"))
|
|
5947
|
+
print(f" {board['id']}: coordinator {pick['registry_name']!r} = {pick['id']} (@{pick.get('address')}; rule: "
|
|
5948
|
+
f"{rule}) — another: lanes address set-coordinator {board['id']} <lane-id>")
|
|
5949
|
+
if board_id:
|
|
5950
|
+
print(f' site.conf: not considered with --board ({L.FLEET_ADMIN_KEY})')
|
|
5951
|
+
return changes
|
|
5952
|
+
conf = Path.home() / L.SITE_CONF
|
|
5953
|
+
current = L.site_conf().get(L.FLEET_ADMIN_KEY)
|
|
5954
|
+
if current:
|
|
5955
|
+
print(f' site.conf: {L.FLEET_ADMIN_KEY}={current} kept')
|
|
5956
|
+
elif not conf.is_file():
|
|
5957
|
+
print(f'⚠ site.conf: no {conf}: {L.FLEET_ADMIN_KEY} not written (add it by hand)')
|
|
5958
|
+
else:
|
|
5959
|
+
text = conf.read_text()
|
|
5960
|
+
line = f'{L.FLEET_ADMIN_KEY}=@{L.DEFAULT_FLEET_ADMIN}\n'
|
|
5961
|
+
changes.append((conf, text, text + ('\n' if text and not text.endswith('\n') else '') + line,
|
|
5962
|
+
f'site.conf: {line.strip()}'))
|
|
5963
|
+
known = any(lane.get('address') == L.DEFAULT_FLEET_ADMIN for board in registry['workspaces']
|
|
5964
|
+
for lane in board['lanes'])
|
|
5965
|
+
print(f' site.conf: {line.strip()}' + ('' if known else ' (no lane answers to that address yet)'))
|
|
5966
|
+
return changes
|
|
5967
|
+
|
|
5968
|
+
|
|
5969
|
+
def cmd_migrate(args):
|
|
5970
|
+
"""lanes migrate addresses [--write] [--board B] (W15 L2d)."""
|
|
5971
|
+
if args[:1] != ['addresses']:
|
|
5972
|
+
raise L.LanesError(MIGRATE_USAGE)
|
|
5973
|
+
given, values = flag_args(args[1:], MIGRATE_USAGE)
|
|
5974
|
+
board_id = values.get('--board')
|
|
5975
|
+
before, why = site_check()
|
|
5976
|
+
if before is None:
|
|
5977
|
+
print(f'✗ site validation before: {why} — nothing written; lanes sync says the same')
|
|
5978
|
+
return 1
|
|
5979
|
+
if board_id:
|
|
5980
|
+
board_of(before, board_id)
|
|
5981
|
+
errors, clashes = site_findings(before)
|
|
5982
|
+
print(f'site validation before: {findings_line(errors, clashes)}')
|
|
5983
|
+
for address, first, second in sorted(clashes):
|
|
5984
|
+
print(f' ✗ {address}: {first} and {second} (lanes address set <lane-id> <board>.<alias>)')
|
|
5985
|
+
changes = migration_plan(before, board_id)
|
|
5986
|
+
if not changes:
|
|
5987
|
+
print('nothing to change')
|
|
5988
|
+
return 0
|
|
5989
|
+
for path, old, new, _what in changes:
|
|
5990
|
+
sys.stdout.writelines(difflib.unified_diff(old.splitlines(True), new.splitlines(True), str(path), str(path), n=1))
|
|
5991
|
+
if '--write' not in given:
|
|
5992
|
+
print(f'dry run: --write applies it (copies under {L.STATE / MIGRATIONS}/<UTC stamp>/)')
|
|
5993
|
+
return 0
|
|
5994
|
+
stamp = time.strftime('%Y%m%dT%H%M%SZ', time.gmtime())
|
|
5995
|
+
backup, n = L.STATE / MIGRATIONS / stamp, 2
|
|
5996
|
+
while backup.exists():
|
|
5997
|
+
backup, n = L.STATE / MIGRATIONS / f'{stamp}-{n}', n + 1
|
|
5998
|
+
files = []
|
|
5999
|
+
with L.registry_lock():
|
|
6000
|
+
for path, old, _new, _what in changes:
|
|
6001
|
+
if path.read_text() != old:
|
|
6002
|
+
raise L.LanesError(f'{path} changed while the migration was planned: nothing written; run it again')
|
|
6003
|
+
backup.mkdir(parents=True, mode=0o700)
|
|
6004
|
+
for index, (path, old, new, what) in enumerate(changes):
|
|
6005
|
+
copy_name = f'{index:02d}-{path.name}'
|
|
6006
|
+
L.atomic_write(backup / copy_name, old, mode=0o600)
|
|
6007
|
+
files.append({'path': str(path), 'backup': copy_name, 'change': what,
|
|
6008
|
+
'sha256_before': hashlib.sha256(old.encode()).hexdigest(),
|
|
6009
|
+
'sha256_after': hashlib.sha256(new.encode()).hexdigest()})
|
|
6010
|
+
L.atomic_write(backup / 'receipt.json', json.dumps(
|
|
6011
|
+
{'v': 1, 'verb': 'lanes migrate addresses', 'at': time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()),
|
|
6012
|
+
'board': board_id, 'files': files}, indent=1) + '\n', mode=0o600)
|
|
6013
|
+
for path, _old, new, _what in changes:
|
|
6014
|
+
L.atomic_write(path, new, mode=stat.S_IMODE(path.stat().st_mode))
|
|
6015
|
+
print(f'backups: {backup} ({len(changes)} file{"s" if len(changes) != 1 else ""}, receipt.json)')
|
|
6016
|
+
after, why = site_check()
|
|
6017
|
+
if after is not None:
|
|
6018
|
+
errors_after, clashes_after = site_findings(after)
|
|
6019
|
+
why = '; '.join([f'{w}: {e}' for w, e in sorted(errors_after - errors)]
|
|
6020
|
+
+ [f'{a}: {x} and {y}' for a, x, y in sorted(clashes_after - clashes)])
|
|
6021
|
+
if why: # worse than before (or no site at all): every file goes back
|
|
6022
|
+
with L.registry_lock():
|
|
6023
|
+
for path, old, _new, _what in changes:
|
|
6024
|
+
L.atomic_write(path, old, mode=stat.S_IMODE(path.stat().st_mode))
|
|
6025
|
+
print(f'✗ site validation after: {why} — every file is back as it was (copies in {backup})')
|
|
6026
|
+
return 1
|
|
6027
|
+
print(f'site validation after: {findings_line(errors_after, clashes_after)}')
|
|
6028
|
+
try:
|
|
6029
|
+
_failed, refused = sync_registry()
|
|
6030
|
+
except L.LanesError as error: # a clash that was there before: written, and the operator's to resolve
|
|
6031
|
+
print(f'✗ written, but lanes sync refuses the site until this is resolved: {error}')
|
|
6032
|
+
return 1
|
|
6033
|
+
if refused:
|
|
6034
|
+
raise L.ProjectionRefused('Migration', refused)
|
|
6035
|
+
return 0
|
|
6036
|
+
|
|
6037
|
+
|
|
6038
|
+
def address_doctor(registry, status):
|
|
6039
|
+
"""`lanes doctor`'s address lines (W15 L2, L2b, L2c) -> [(mark, text)]: boards without a coordinator (⚠), two
|
|
6040
|
+
lanes on one address (✗; ✓ when none), the fleet admin (⚠ unset or naming no lane), override keys that name no
|
|
6041
|
+
terminal (⚠) and, per container, how many Claude lanes answer to their address (information). Reads registry.json
|
|
6042
|
+
and status.json only."""
|
|
6043
|
+
trial = copy.deepcopy(registry)
|
|
6044
|
+
clashes = L.apply_addresses(trial, strict=False)
|
|
6045
|
+
boards = [board for board in trial.get('workspaces') or [] if board.get('lanes') and not board.get('attach_only')]
|
|
6046
|
+
lines = []
|
|
6047
|
+
without = [board['id'] for board in boards if not board.get('coordinator')]
|
|
6048
|
+
lines.append(('⚠', f'{len(without)} of {len(boards)} boards without a coordinator: {", ".join(without[:6])}'
|
|
6049
|
+
f'{" …" if len(without) > 6 else ""} — lanes migrate addresses --write, or lanes address '
|
|
6050
|
+
'set-coordinator <board> <lane-id>') if without else
|
|
6051
|
+
('', f'coordinators: every board has one ({len(boards)})'))
|
|
6052
|
+
lines.append(('✗', 'lane addresses unique — ' + '; '.join(f'{a}: {x} and {y}' for a, x, y in clashes[:3])
|
|
6053
|
+
+ ' (lanes sync refuses the site until one has another address)') if clashes else
|
|
6054
|
+
('✓', 'lane addresses unique'))
|
|
6055
|
+
fleet = trial.get('fleet_admin')
|
|
6056
|
+
owner = next((lane['id'] for board in trial.get('workspaces') or [] for lane in board.get('lanes') or []
|
|
6057
|
+
if fleet and lane.get('address') == fleet), None)
|
|
6058
|
+
if not fleet:
|
|
6059
|
+
lines.append(('⚠', f'fleet admin unset — {L.FLEET_ADMIN_KEY}=@<address> in ~/.config/lanes/site.conf (lanes '
|
|
6060
|
+
f'migrate addresses --write sets @{L.DEFAULT_FLEET_ADMIN})'))
|
|
6061
|
+
elif not owner:
|
|
6062
|
+
lines.append(('⚠', f'fleet admin @{fleet} is the address of no lane'))
|
|
6063
|
+
else:
|
|
6064
|
+
lines.append(('', f'fleet admin: @{fleet} ({owner})'))
|
|
6065
|
+
for board in boards:
|
|
6066
|
+
names = {lane.get('registry_name') for lane in board['lanes']}
|
|
6067
|
+
orphans = sorted(set(board.get('address_overrides') or {}) - names)
|
|
6068
|
+
if orphans:
|
|
6069
|
+
lines.append(('⚠', f"{board['id']}: addresses for no terminal: {', '.join(map(repr, orphans[:4]))} — "
|
|
6070
|
+
'remove them from the manifest or set them again'))
|
|
6071
|
+
rows, counts = (status or {}).get('lanes') or {}, {}
|
|
6072
|
+
for board in trial.get('workspaces') or []:
|
|
6073
|
+
for lane in board.get('lanes') or []:
|
|
6074
|
+
agent = (rows.get(lane['id']) or {}).get('agent')
|
|
6075
|
+
if isinstance(agent, dict) and agent.get('harness') == 'claude':
|
|
6076
|
+
tally = counts.setdefault(lane.get('container') or '?', [0, 0])
|
|
6077
|
+
tally[0] += agent.get('name_match') is True
|
|
6078
|
+
tally[1] += 1
|
|
6079
|
+
if counts:
|
|
6080
|
+
lines.append(('', 'Claude names = addresses: ' + ' · '.join(f'{c} {m}/{n}' for c, (m, n) in sorted(counts.items()))
|
|
6081
|
+
+ ('' if all(m == n for m, n in counts.values()) else
|
|
6082
|
+
' (lanes names sync --write; statusd renames the busy ones as they go idle while '
|
|
6083
|
+
f'{L.NAMES_AUTO_KEY} is on)')))
|
|
6084
|
+
codex = codex_addressable(trial, rows)
|
|
6085
|
+
if codex:
|
|
6086
|
+
short = sorted(name for name, (found, total) in codex.items() if found < total)
|
|
6087
|
+
counted = ' · '.join(f'{c} {m} of {n}' for c, (m, n) in sorted(codex.items()))
|
|
6088
|
+
lines.append(('', 'codex lanes addressable: ' + counted
|
|
6089
|
+
+ (f' — counted by the thread id the Codex hooks record (lanes hooks install --agent codex '
|
|
6090
|
+
f'--container {short[0]} --write{" and the others" if len(short) > 1 else ""}); until then '
|
|
6091
|
+
"lane-mcp in the container matches each by its cwd through Codex's app-server (lanes_status "
|
|
6092
|
+
'`handle.via`)' if short else '')))
|
|
6093
|
+
return lines
|
|
6094
|
+
|
|
6095
|
+
|
|
6096
|
+
def codex_addressable(registry, rows):
|
|
6097
|
+
"""{container: [addressable, live]} over the registry's Codex lanes (W15 L3): `live` counts the lanes whose agent
|
|
6098
|
+
is Codex (status.json; a `shell` word is a Codex that ended), `addressable` those with a thread id the Codex hooks
|
|
6099
|
+
recorded (agent.session_id, lane_core.THREAD_RE). The container-side fallback (lane_core.codex_handles) is not
|
|
6100
|
+
the host's to count."""
|
|
6101
|
+
core, counts = lane_core(), {}
|
|
6102
|
+
for board in registry.get('workspaces') or []:
|
|
6103
|
+
for lane in board.get('lanes') or []:
|
|
6104
|
+
agent = (rows.get(lane['id']) or {}).get('agent')
|
|
6105
|
+
if not isinstance(agent, dict) or agent.get('harness') != 'codex' or agent.get('status') in (None, 'shell'):
|
|
6106
|
+
continue
|
|
6107
|
+
tally = counts.setdefault(lane.get('container') or '?', [0, 0])
|
|
6108
|
+
thread = agent.get('session_id')
|
|
6109
|
+
tally[0] += isinstance(thread, str) and bool(core.THREAD_RE.fullmatch(thread))
|
|
6110
|
+
tally[1] += 1
|
|
6111
|
+
return counts
|
|
6112
|
+
|
|
6113
|
+
|
|
5548
6114
|
# ------------------------------------------------------------------ preview
|
|
5549
6115
|
# Ctrl-Alt-m (zellij/config.kdl, spec §5.4) opens a floating pane running `lanes preview --focused`: the markdown file
|
|
5550
6116
|
# the focused lane printed last, rendered by glow (else `less -R`). Read-only: two zellij listings, one guarded tmux
|
|
@@ -6154,7 +6720,8 @@ COMMANDS = {'rebuilt': cmd_rebuilt, 'hello': cmd_hello, 'client-config': cmd_cli
|
|
|
6154
6720
|
'sidebar-key': cmd_sidebar_key, 'studio-host': cmd_studio_host,
|
|
6155
6721
|
'keys': cmd_keys, 'invite': cmd_invite, 'enrol': cmd_enrol, 'offboard': cmd_offboard,
|
|
6156
6722
|
'token': cmd_token, 'onboard': cmd_onboard, 'user': cmd_user, 'lane': cmd_lane, 'here': cmd_here,
|
|
6157
|
-
'version': cmd_version, 'update': cmd_update, 'docs': cmd_docs
|
|
6723
|
+
'version': cmd_version, 'update': cmd_update, 'docs': cmd_docs,
|
|
6724
|
+
'address': cmd_address, 'names': cmd_names, 'migrate': cmd_migrate, 'message': cmd_message}
|
|
6158
6725
|
|
|
6159
6726
|
if __name__ == '__main__':
|
|
6160
6727
|
if len(sys.argv) < 2 or sys.argv[1] not in COMMANDS:
|