@vibelord/lanes 1.6.1 → 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.
@@ -15,7 +15,10 @@ a `holder: tmux` lane through its exact socket and session; any other id is a zm
15
15
  (a second tmux client half a second later: an agent's prompt takes text+Enter in one
16
16
  burst as a paste)
17
17
  zmx: the bytes as given, never an Enter of its own (use $'\\r')
18
- lane capture <id> [--lines N] [--vt] print scrollback (plain text, or VT with --vt)
18
+ <id> may be an address (W15): @<board>.<lane>, @<board> (its coordinator), @fleet (the
19
+ fleet admin, which takes text from a coordinator only when this runs in a lane)
20
+ lane capture <id> [--lines N] [--vt] print scrollback (plain text, or VT with --vt); <id> may be an address
21
+ lane address [--json] this lane's address, role, its board's coordinator and the site's fleet admin
19
22
  lane ls [--json] [--all] zmx lanes with holder metadata; --all adds the registry's tmux lanes with `alive`
20
23
  (the default listing stays zmx-only: Throttle Studio reads every row of it as zmx)
21
24
  lane status <id> JSON: alive/running?, the hook agent (`lane-signal`), meta; exit 1 when not running
@@ -29,6 +32,20 @@ a `holder: tmux` lane through its exact socket and session; any other id is a zm
29
32
  once) and prints {id, …, picked_up_by, expected_within_s} as JSON; the host's lanes-docsd
30
33
  takes it within ~5 s and writes <id>.receipt.json beside it (kind from the extension when
31
34
  --kind is left out; the file must be under /home/coder, at most 32 MiB)
35
+ lane message <address> [--ttl S] [--queue] <text...>
36
+ one message from the lane this runs in to a lane of this container (W15 L4, BEY-6842,
37
+ lane_core.message, what lanes_message does): prints the answer as JSON — `delivered_by`
38
+ codex_queue, throttle_turn, typed or (with --queue) queued, with `expected_within_s`, or
39
+ unknown (an adapter whose answer was lost: held, never sent again by Lanes);
40
+ from a Claude agent to a Claude session: refused use_send_message (its own SendMessage)
41
+ lane inbox [--json] this lane's inbox (~/.lz/state/inbox/<lane>/): each message's id, sender, time, how it
42
+ was delivered and its text until acknowledged (every message not yet settled, and the
43
+ newest 512 settled ones)
44
+ lane inbox ack <id> this lane has the message: its text leaves the inbox, its receipt stays
45
+ lane inbox retry <id> --duplicate-risk [--lane <id>]
46
+ a person hands a held message (receipt unknown) of this lane's inbox, or of --lane's,
47
+ back to the inbox (queued: lanes-statusd types it when the lane is next idle); it may
48
+ have arrived already, so it may arrive twice — --duplicate-risk says you accept that
32
49
  lane mcp install [--agent claude|codex|kimi|grok|grok-cli|muse|zcode|all] [--write]
33
50
  add the Lanes MCP server (~/.lz/bin/lane-mcp) to ~/.claude.json (mcpServers.lanes) and
34
51
  ~/.codex/config.toml ([mcp_servers.lanes], with env_vars passing LANE_ID, LANE_WS, TMUX
@@ -312,12 +329,17 @@ def cmd_send(args):
312
329
  if not enter:
313
330
  args = list(args)
314
331
  args.remove('--no-enter')
315
- name = lane_id(args[0] if args else '')
332
+ name = target('send', args[0] if args else '')
316
333
  text = ' '.join(args[1:])
334
+ route(name)
317
335
  held = tmux_lane('send', name)
318
336
  if held:
319
337
  _, socket, session = held
320
- results = C.send_keys(socket, session, text, enter, run=tmux_run)
338
+ try: # W15 part 2: the lane's one native-input authority, held across the text and its Enter
339
+ with C.dispatch_lock(ROOT, name):
340
+ results = C.send_keys(socket, session, text, enter, run=tmux_run)
341
+ except C.DispatchBusy as error:
342
+ sys.exit(f'lane send: {error} — nothing was typed')
321
343
  sys.stderr.write(''.join(result.stderr for result in results))
322
344
  if len(results) == 2 and results[1].returncode:
323
345
  sys.stderr.write('lane send: the text was typed; Enter was not pressed\n')
@@ -332,10 +354,41 @@ def last_lines(text, lines):
332
354
  return C.last_lines(text, lines) or '\n'
333
355
 
334
356
 
357
+ def target(verb, text):
358
+ """The lane id `text` names (W15 L2): an `@` address resolved through lane_core.resolve_address (`@<board>.<lane>`,
359
+ `@<board>` for its coordinator, `@fleet` for the fleet admin; a refusal exits with its sentence), anything else the
360
+ id as given (lane_id checks it)."""
361
+ if not (text or '').startswith('@'):
362
+ return lane_id(text)
363
+ try:
364
+ return lane_id(C.resolve_address(ROOT, text)[0])
365
+ except C.NewerVersion:
366
+ sys.exit(f'lane {verb}: the registry is newer than this `lane` — on the host run: lanes install-container <container>')
367
+ except C.LaneError as error:
368
+ sys.exit(f'lane {verb}: {error} ({error.code})')
369
+
370
+
371
+ def route(name):
372
+ """W15 L2b in a lane: text for the fleet admin's lane only from a coordinator (lane_core.routing_check). Run
373
+ outside a lane (a person's shell, Throttle Studio's `docker exec`) nothing is checked: the rule routes agents."""
374
+ try:
375
+ export = C.registry_export(ROOT)
376
+ except C.NewerVersion:
377
+ return
378
+ _address, admin = C.fleet_admin_of(export)
379
+ if admin is None or name != admin:
380
+ return
381
+ sender = C.whoami(ROOT, os.environ)['lane']
382
+ if sender and C.routing_check(sender, name, export):
383
+ facts = C.addressing(ROOT, sender, export['lanes'].get(sender), export=export)
384
+ sys.exit(f'lane send: {name} is the fleet admin: it takes text from coordinators (use_coordinator) — send it '
385
+ f'to your board\'s coordinator{" @" + facts["coordinator"] if facts["coordinator"] else ""}')
386
+
387
+
335
388
  def cmd_capture(args):
336
389
  lines = int(option(args, '--lines', '0') or 0)
337
390
  flags = ['--vt'] if '--vt' in args else []
338
- name = lane_id(next((a for a in args if not a.startswith('--')), ''))
391
+ name = target('capture', next((a for a in args if not a.startswith('--')), ''))
339
392
  held = tmux_lane('capture', name)
340
393
  if held:
341
394
  _, socket, session = held
@@ -624,8 +677,135 @@ def cmd_publish(args):
624
677
  f"{out['receipt']}\n")
625
678
 
626
679
 
680
+ def cmd_address(args):
681
+ """`lane address [--json]` (W15 L2/L2b): the lane this runs in ($LANE_ID, else the tmux pane) with its address,
682
+ role, its board's coordinator and the site's fleet admin (lane_core.addressing, what lanes_whoami answers). Lines
683
+ for a person, or one JSON object with --json (addresses without their `@`). Outside a lane: one stderr line, exit 1."""
684
+ if args not in ([], ['--json']):
685
+ sys.exit('usage: lane address [--json]')
686
+ try:
687
+ found = C.whoami(ROOT, os.environ)
688
+ if not found['lane']:
689
+ sys.exit(f"lane address: {found.get('why') or 'not inside a lane'}")
690
+ observed = C.container_status(ROOT)['lanes'].get(found['lane'])
691
+ facts = C.addressing(ROOT, found['lane'], found.get('entry'), found.get('session'), observed)
692
+ except C.NewerVersion:
693
+ sys.exit('lane address: the registry is newer than this `lane` — on the host run: lanes install-container <container>')
694
+ if args:
695
+ print(json.dumps({'lane': found['lane'], **facts}, ensure_ascii=False, indent=1))
696
+ return
697
+ shown = lambda value: '@' + value if value else '-' # noqa: E731
698
+ handle = facts['handle'] or {}
699
+ print(f"lane {found['lane']}\naddress {shown(facts['address'])}\nrole {facts['role'] or '-'}\n"
700
+ f"coordinator {shown(facts['coordinator'])}\nfleet admin {shown(facts['fleet_admin'])}\n"
701
+ f"handle {handle.get('kind') or '-'} {handle.get('name') or ''} ({handle.get('transport') or '-'})\n"
702
+ f"name match {'-' if facts['name_match'] is None else str(facts['name_match']).lower()}")
703
+
704
+
705
+ MESSAGE_USAGE = 'usage: lane message <address> [--ttl S] [--queue] <text...>'
706
+ INBOX_USAGE = 'usage: lane inbox [--json] | lane inbox ack <id> | lane inbox retry <id> --duplicate-risk [--lane <id>]'
707
+
708
+
709
+ def own_lane(verb):
710
+ """The lane this process runs in (lane_core.whoami: $LANE_ID, else the tmux pane); outside one: exit 1."""
711
+ try:
712
+ found = C.whoami(ROOT, os.environ)
713
+ except C.NewerVersion:
714
+ sys.exit(f'lane {verb}: the registry is newer than this `lane` — on the host run: lanes install-container <container>')
715
+ if not found['lane']:
716
+ sys.exit(f"lane {verb}: {found.get('why') or 'not inside a lane'}")
717
+ return found['lane']
718
+
719
+
720
+ def cmd_message(args):
721
+ """`lane message` (W15 L4): lane_core.message from the lane this runs in, the sender's harness from the process
722
+ tree (lane_core.parent_harness: a Claude agent's Bash tool runs this under `claude`). Prints the answer as JSON on
723
+ stdout and one line for a person on stderr; a refusal is one stderr line naming its code, exit 1 (the
724
+ use_send_message refusal names the `to` the sender's SendMessage takes)."""
725
+ rest, ttl, queue = list(args), C.MESSAGE_TTL_S, False
726
+ while rest and rest[0].startswith('--') and rest[0] != '--':
727
+ word = rest.pop(0)
728
+ if word == '--queue':
729
+ queue = True
730
+ elif word == '--ttl' and rest and rest[0].isdigit():
731
+ ttl = int(rest.pop(0))
732
+ else:
733
+ sys.exit(MESSAGE_USAGE)
734
+ if rest[:1] == ['--']:
735
+ rest.pop(0)
736
+ if len(rest) < 2:
737
+ sys.exit(MESSAGE_USAGE)
738
+ to, text = rest[0], ' '.join(rest[1:]) # options come before the address: a later `--queue` is text
739
+ lane = own_lane('message')
740
+ try:
741
+ out = C.message(ROOT, Path(os.environ.get('HOME') or Path.home()), lane, to, text, ttl_s=ttl, queue=queue,
742
+ harness=C.parent_harness(PROC, os.getppid()), environ=os.environ, proc=PROC)
743
+ except C.LaneError as error:
744
+ extra = getattr(error, 'extra', None) or {}
745
+ hint = f" — use your own SendMessage to {extra['to']}" if error.code == 'use_send_message' else ''
746
+ sys.exit(f'lane message: {error} ({error.code}){hint}')
747
+ print(json.dumps(out, ensure_ascii=False, indent=1))
748
+ sys.stderr.write(f"lane message: {out['bytes']} bytes to @{out['to']} ({out['lane']}): {out['delivered_by']} — "
749
+ f"{out['picked_up_by']}\n")
750
+ if out['delivered_by'] == 'unknown': # W15 part 2: never send it again yourself
751
+ sys.stderr.write(f"lane message: {out['not_confirmed']} — do not send it again; `lane inbox retry {out['id']} "
752
+ f"--duplicate-risk --lane {out['lane']}` is a person's call\n")
753
+
754
+
755
+ def cmd_inbox(args):
756
+ """`lane inbox [--json]` lists this lane's inbox (oldest first: id, sender, time, delivered_by, the text until it
757
+ is acknowledged); `lane inbox ack <id>` acknowledges one (lane_core.message_ack); `lane inbox retry <id>
758
+ --duplicate-risk [--lane <id>]` hands a held (`unknown`) message back to its inbox (lane_core.message_retry)."""
759
+ lane = None
760
+ if args[:1] == ['retry']:
761
+ rest, risk, lane = list(args[1:]), False, None
762
+ while '--duplicate-risk' in rest:
763
+ rest.remove('--duplicate-risk')
764
+ risk = True
765
+ if '--lane' in rest:
766
+ at = rest.index('--lane')
767
+ if at + 1 >= len(rest):
768
+ sys.exit(INBOX_USAGE)
769
+ lane = lane_id(rest[at + 1])
770
+ del rest[at:at + 2]
771
+ if len(rest) != 1 or rest[0].startswith('-'):
772
+ sys.exit(INBOX_USAGE)
773
+ try:
774
+ out = C.message_retry(ROOT, lane or own_lane('inbox'), rest[0], duplicate_risk=risk)
775
+ except C.LaneError as error:
776
+ sys.exit(f'lane inbox: {error} ({error.code})')
777
+ print(json.dumps(out, ensure_ascii=False, indent=1))
778
+ return
779
+ if args[:1] == ['ack'] and len(args) == 2:
780
+ lane = own_lane('inbox')
781
+ try:
782
+ out = C.message_ack(ROOT, lane, args[1])
783
+ except C.LaneError as error:
784
+ sys.exit(f'lane inbox: {error} ({error.code})')
785
+ print(json.dumps(out, ensure_ascii=False, indent=1))
786
+ return
787
+ if args not in ([], ['--json']):
788
+ sys.exit(INBOX_USAGE)
789
+ lane = own_lane('inbox')
790
+ rows = []
791
+ for entry in C.inbox_entries(ROOT, lane):
792
+ record, receipt = entry.get('record') or {}, entry.get('receipt') or {}
793
+ rows.append({'id': entry['id'], 'from': record.get('from'), 'at': record.get('at'),
794
+ 'delivered_by': receipt.get('delivered_by'), 'acked': record.get('acked'),
795
+ 'text': record.get('text')})
796
+ if args:
797
+ print(json.dumps({'lane': lane, 'messages': rows}, ensure_ascii=False, indent=1))
798
+ return
799
+ if not rows:
800
+ print(f'{lane}: no messages')
801
+ for row in rows:
802
+ said = row['text'] if row['text'] is not None else ('(acknowledged)' if row['acked'] else '(no text)')
803
+ print(f"{row['id']} {row['at'] or '-'} @{row['from'] or '-'} {row['delivered_by'] or 'on its way'} {said}")
804
+
805
+
627
806
  COMMANDS = {'new': cmd_new, 'open': cmd_open, 'attach': cmd_attach, 'send': cmd_send, 'capture': cmd_capture, 'ls': cmd_ls,
628
- 'status': cmd_status, 'kill': cmd_kill, 'gc': cmd_gc, 'mcp': cmd_mcp, 'publish': cmd_publish}
807
+ 'status': cmd_status, 'kill': cmd_kill, 'gc': cmd_gc, 'mcp': cmd_mcp, 'publish': cmd_publish,
808
+ 'address': cmd_address, 'message': cmd_message, 'inbox': cmd_inbox}
629
809
 
630
810
  if __name__ == '__main__':
631
811
  if len(sys.argv) < 2 or sys.argv[1] not in COMMANDS: