@vibelord/lanes 1.9.5 → 1.9.7
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 +3 -0
- package/payload/lanes/bin-rs/BINARIES.json +1 -1
- package/payload/lanes/libexec/agent_state.py +462 -59
- package/payload/lanes/libexec/lanes_lib.py +3 -2
- package/payload/lanes/libexec/site_hooks.py +239 -31
- package/payload/lanes/libexec/statusd.py +54 -13
- package/payload/manifest.json +3 -3
package/package.json
CHANGED
package/payload/lanes/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.9.
|
|
1
|
+
1.9.7
|
package/payload/lanes/bin/lanes
CHANGED
|
@@ -5764,6 +5764,9 @@ def cmd_doctor(_args):
|
|
|
5764
5764
|
print(f'{mark or " "} {text}')
|
|
5765
5765
|
else:
|
|
5766
5766
|
check(mark == '✓', text)
|
|
5767
|
+
# FLE-413 (27 Nov 2026): the site hooks this host loads and each one the loader refused; nothing without one.
|
|
5768
|
+
for mark, text in site_hooks.doctor_lines():
|
|
5769
|
+
check(mark == '✓', text)
|
|
5767
5770
|
# Lanes 2.0 runtime signals (RT 16.3, lanes2 R2-DOCTOR): the snapshot a Lanes 2.0 host exports; nothing until one does.
|
|
5768
5771
|
import doctor_lanes2
|
|
5769
5772
|
for mark, text in doctor_lanes2.doctor_lines(L.STATE):
|
|
@@ -66,16 +66,83 @@ import heapq
|
|
|
66
66
|
import importlib.util
|
|
67
67
|
import json
|
|
68
68
|
import os
|
|
69
|
+
import re
|
|
69
70
|
import stat
|
|
70
71
|
import sys
|
|
71
72
|
import time
|
|
72
73
|
import zlib
|
|
73
74
|
from pathlib import Path
|
|
74
75
|
|
|
76
|
+
# BEY-8970: the forms each harness writes are recorded once, with the version each was read from and how
|
|
77
|
+
# (lanes/tests/unit/fixtures/harness-forms/forms.json: Claude Code 2.1.332, Codex 0.169.1). These words, their Rust
|
|
78
|
+
# twins (crates/lanes-runtime/src/observers) and lane_core's own read are each pinned to that record by a test.
|
|
75
79
|
SPINNER = set('⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏⠁⠂⠄⡀⢀⠠⠐⠈')
|
|
76
80
|
ACTION = '[ ! ] Action Required'
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
ACTIONS = (ACTION, '[ . ] Action Required') # Codex alternates the two every second while an approval waits
|
|
82
|
+
LISTENING = '● ' # Codex puts it before everything while its microphone listens
|
|
83
|
+
ACTION_DRAWN = 'actionrequired' # the mark's words (`Action Required`) in ASCII lower case, as they are
|
|
84
|
+
# looked for outside the mark: in what is DRAWN of the title, spaces aside
|
|
85
|
+
UNKNOWN_MARK_RE = re.compile(r'\[[^\]]{0,3}\]') # a bracketed mark first, of a kind the observer does not know
|
|
86
|
+
# Characters that draw nothing, dropped before that check. Spelled out, not taken from a Unicode table, so the Rust
|
|
87
|
+
# twin (which has no general category) drops exactly the same: white space, the C0 and C1 controls, and these
|
|
88
|
+
# format characters.
|
|
89
|
+
# The characters that draw nothing in a pane title: every code point of the Unicode general categories Cf, Cc, Cs,
|
|
90
|
+
# Zs, Zl and Zp, frozen as ranges (Unicode 15.0.0) so that this observer, its Rust twin and lane_core's own read
|
|
91
|
+
# agree whatever Unicode their runtime carries. The record: tests/unit/fixtures/harness-forms/forms.json `unseen`,
|
|
92
|
+
# to which each of the three is pinned by a test.
|
|
93
|
+
TITLE_UNSEEN_RANGES = (
|
|
94
|
+
(0x0000, 0x0020), (0x007F, 0x00A0), (0x00AD, 0x00AD), (0x0600, 0x0605), (0x061C, 0x061C), (0x06DD, 0x06DD),
|
|
95
|
+
(0x070F, 0x070F), (0x0890, 0x0891), (0x08E2, 0x08E2), (0x1680, 0x1680), (0x180E, 0x180E), (0x2000, 0x200F),
|
|
96
|
+
(0x2028, 0x202F), (0x205F, 0x2064), (0x2066, 0x206F), (0x3000, 0x3000), (0xD800, 0xDFFF), (0xFEFF, 0xFEFF),
|
|
97
|
+
(0xFFF9, 0xFFFB), (0x110BD, 0x110BD), (0x110CD, 0x110CD), (0x13430, 0x1343F), (0x1BCA0, 0x1BCA3),
|
|
98
|
+
(0x1D173, 0x1D17A), (0xE0001, 0xE0001), (0xE0020, 0xE007F),
|
|
99
|
+
)
|
|
100
|
+
BRAILLE_FIRST, BRAILLE_LAST = 0x2800, 0x28FF # the block Codex's spinner glyphs are in (SPINNER: the 18 it writes)
|
|
101
|
+
CODEX_SEPARATOR = ' | '
|
|
102
|
+
CODEX_PROJECT_MAX, CODEX_PROJECT_KEPT, CODEX_PROJECT_CUT = 24, 21, '...'
|
|
103
|
+
SHELL_TITLES = {'', 'bash', 'sh', 'zsh', 'fish'} # tmux's default title, the machine's name, is the row's `host`
|
|
104
|
+
HOSTNAME_FILE = ('etc', 'hostname') # in a container's root: the name tmux gives a pane nobody titled
|
|
105
|
+
HOSTNAME_MAX = 256
|
|
106
|
+
# What a Claude Code session file's `status` is published as. `waiting` is published by its reason
|
|
107
|
+
# (CLAUDE_WAITING, CLAUDE_WAITING_PUBLISHES); a word that is not here is no form the observer knows (UNKNOWN).
|
|
108
|
+
STATUS_FROM_CLAUDE = {'busy': 'working', 'idle': 'needs_input', 'shell': 'shell'} # `waiting`: CLAUDE_WAITING below
|
|
109
|
+
# The reasons Claude Code writes beside `waiting`, each with its class; any other reason, or none, is `unlisted`.
|
|
110
|
+
CLAUDE_WAITING = {'permission prompt': 'permission', 'sandbox request': 'permission', 'worker request': 'permission',
|
|
111
|
+
'goal proposal': 'permission', 'input needed': 'question', 'dialog open': 'menu'}
|
|
112
|
+
# THE INTERIM ROW: what each class is published as. A question and an open menu are published needs_approval until,
|
|
113
|
+
# per container, BEY-8963 is installed there and no lane-mcp process older than that install is alive; then they
|
|
114
|
+
# become needs_input by changing this one row (its Rust twin with it).
|
|
115
|
+
CLAUDE_WAITING_PUBLISHES = {'permission': 'needs_approval', 'question': 'needs_approval', 'menu': 'needs_approval',
|
|
116
|
+
'unlisted': 'needs_approval',
|
|
117
|
+
# A form the observer does not know, of a harness it observes (UNKNOWN below), with no
|
|
118
|
+
# hook sidecar standing: its own class in the same row.
|
|
119
|
+
'unknown': 'needs_approval'}
|
|
120
|
+
WAITING_EVENT = 'waiting' # the `event` of a waiting read whose file names no reason
|
|
121
|
+
UNKNOWN_EVENT = 'a form the observer does not know' # the `event` of the unknown class: why the row stands
|
|
122
|
+
SIDECAR_OVER_WAITING = ('needs_approval', 'errored') # a hook sidecar's words a waiting read does not outrank
|
|
123
|
+
EVENT_MAX = 120 # characters of the harness's own reason an agent{} carries as `event`
|
|
124
|
+
|
|
125
|
+
# A Codex batch run (BEY-8970; MEASURED 26 Nov 2026 on a live pane: `codex exec` under the title nobody set). It has no
|
|
126
|
+
# screen of its own and writes no title, so the title on its pane is not its and nobody waits there. It is known by
|
|
127
|
+
# the process's own arguments: the first one that is not one of Codex's global options is one of CODEX_BATCH_WORDS.
|
|
128
|
+
# The tables are `codex --help` of codex-cli 0.169.1 and are pinned to the forms record (forms.json, codex.batch).
|
|
129
|
+
# `-i/--image` takes one or more values and is in neither table: what follows it is not read.
|
|
130
|
+
BATCH_EVENT = 'a batch run' # the `event` of a batch run's row: why it says working
|
|
131
|
+
CODEX_BATCH_WORDS = ('exec', 'e')
|
|
132
|
+
CODEX_OPTIONS_WITH_A_VALUE = ('-c', '--config', '--enable', '--disable', '--remote', '--remote-auth-token-env', '-m',
|
|
133
|
+
'--model', '--local-provider', '-p', '--profile', '-s', '--sandbox', '-C', '--cd',
|
|
134
|
+
'--add-dir', '-a', '--ask-for-approval')
|
|
135
|
+
CODEX_OPTIONS_WITHOUT = ('--strict-config', '--oss', '--approve-for-me', '--dangerously-bypass-approvals-and-sandbox',
|
|
136
|
+
'--dangerously-bypass-hook-trust', '--worktree', '--search', '--no-alt-screen', '--no-daemon')
|
|
137
|
+
ARGV_MAX = 65536 # bytes of a process's /proc/<pid>/cmdline read for `process_argv`
|
|
138
|
+
SESSION_FILE_MAX = 64 * 1024 # bytes of one Claude session file read (the Rust twin's bound): a
|
|
139
|
+
# longer file is not Claude's and is that one pane's unreadable file
|
|
140
|
+
SESSION_DEPTH_MAX = 64 # levels of lists and objects in one session file, the document itself
|
|
141
|
+
# the first: under what both parsers go to (this one about 10,000,
|
|
142
|
+
# the Rust twin's 128), so both refuse the same files
|
|
143
|
+
BESIDE_UNKNOWN = 'beside unknown' # the kind of a hook sidecar's verdict published beside an own read
|
|
144
|
+
# that is the unknown class: the delegating rule does not apply
|
|
145
|
+
DELETED = ' (deleted)' # what /proc appends to the path of a removed directory or file
|
|
79
146
|
STATUSES = ('working', 'needs_input', 'needs_approval', 'done', 'errored', 'shell', 'idle')
|
|
80
147
|
SHELL_COMMANDS = {'bash', 'sh', 'dash', 'zsh', 'fish', 'ksh', 'tcsh', 'csh'}
|
|
81
148
|
# The attention section each status belongs to (None = the workspace's other lanes) and how urgent a section is: the
|
|
@@ -164,6 +231,9 @@ CONTAINER_HOME = '/home/coder'
|
|
|
164
231
|
# `claude_sessions` skips it, so a Codex lane is never published as Claude from Lanes' own entry.
|
|
165
232
|
VIRTUAL_PEERS = CONTAINER_HOME + '/.lz/state/peers/'
|
|
166
233
|
GROK_UNKNOWN = 'unknown' # the Grok observer's word for a pane it sees but cannot join (leader mode): no agent{}
|
|
234
|
+
UNKNOWN = GROK_UNKNOWN # BEY-8970, the same word inside every observer: its harness is there, in a form it does
|
|
235
|
+
# not know. Never published as it is, and nothing below may guess a word for it: merge
|
|
236
|
+
# publishes the unknown class's row (CLAUDE_WAITING_PUBLISHES) unless a hook sidecar stands.
|
|
167
237
|
_DIR_FLAGS = os.O_RDONLY | os.O_DIRECTORY | getattr(os, 'O_CLOEXEC', 0)
|
|
168
238
|
_FILE_FLAGS = os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK | getattr(os, 'O_CLOEXEC', 0)
|
|
169
239
|
|
|
@@ -263,7 +333,7 @@ def _exe(proc_root, pid):
|
|
|
263
333
|
exe = os.readlink(Path(proc_root, str(pid), 'exe'))
|
|
264
334
|
except OSError:
|
|
265
335
|
return None
|
|
266
|
-
return exe[:-len(
|
|
336
|
+
return exe[:-len(DELETED)] if exe.endswith(DELETED) else exe
|
|
267
337
|
|
|
268
338
|
|
|
269
339
|
def _named(proc_root, pid, comm):
|
|
@@ -402,27 +472,124 @@ def _same_process(proc_root, pid, proc_start):
|
|
|
402
472
|
return lane_core().same_process(proc_root, pid, proc_start)
|
|
403
473
|
|
|
404
474
|
|
|
405
|
-
def
|
|
475
|
+
def container_host(root):
|
|
476
|
+
"""The host name of the container whose root is `root` (its /etc/hostname, one line), or None when it cannot be
|
|
477
|
+
read: the title tmux gives a pane nobody titled (MEASURED, tmux 3.4). statusd sets it on every pane row as `host`
|
|
478
|
+
(BEY-8970), so the shell-title list holds no machine's name."""
|
|
479
|
+
try:
|
|
480
|
+
with open(Path(root).joinpath(*HOSTNAME_FILE), 'rb') as handle:
|
|
481
|
+
name = handle.read(HOSTNAME_MAX + 1)
|
|
482
|
+
except OSError:
|
|
483
|
+
return None
|
|
484
|
+
try:
|
|
485
|
+
name = name.decode('utf-8').strip()
|
|
486
|
+
except UnicodeDecodeError:
|
|
487
|
+
return None
|
|
488
|
+
return name if name and len(name) <= HOSTNAME_MAX and '\n' not in name else None
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
def _title_unseen(char):
|
|
492
|
+
"""Whether `char` draws nothing in a title (TITLE_UNSEEN_RANGES)."""
|
|
493
|
+
code = ord(char)
|
|
494
|
+
return any(low <= code <= high for low, high in TITLE_UNSEEN_RANGES)
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
def _braille(char):
|
|
498
|
+
"""Whether `char` is a glyph of the braille block."""
|
|
499
|
+
return BRAILLE_FIRST <= ord(char) <= BRAILLE_LAST
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
def _ascii_lower(text):
|
|
503
|
+
"""`text` with A to Z in lower case and every other character as it is (no Unicode case folding: the Rust twin
|
|
504
|
+
folds the same 26 letters)."""
|
|
505
|
+
return ''.join(chr(ord(char) + 32) if 'A' <= char <= 'Z' else char for char in text)
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
def _title_words(text):
|
|
509
|
+
"""`text` split at every character that draws nothing (_title_unseen), empty words left out."""
|
|
510
|
+
words, word = [], []
|
|
511
|
+
for char in text:
|
|
512
|
+
if _title_unseen(char):
|
|
513
|
+
if word:
|
|
514
|
+
words.append(''.join(word))
|
|
515
|
+
word = []
|
|
516
|
+
else:
|
|
517
|
+
word.append(char)
|
|
518
|
+
return words + ([''.join(word)] if word else [])
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
def codex_projects(cwd):
|
|
522
|
+
"""The words Codex may show as its project for a process that runs in `cwd`: each directory name on that path,
|
|
523
|
+
whole, and as Codex cuts one longer than CODEX_PROJECT_MAX (MEASURED on 73 live panes, 26 Nov 2026). Empty when the
|
|
524
|
+
path was not read."""
|
|
525
|
+
if not isinstance(cwd, str) or not cwd.startswith('/'):
|
|
526
|
+
return frozenset()
|
|
527
|
+
if cwd.endswith(DELETED):
|
|
528
|
+
cwd = cwd[:-len(DELETED)] # a removed directory (a worktree removed under a sitting agent), as `_exe` does
|
|
529
|
+
names = [name for name in cwd.split('/') if name]
|
|
530
|
+
return frozenset(names) | frozenset(name[:CODEX_PROJECT_KEPT] + CODEX_PROJECT_CUT for name in names
|
|
531
|
+
if len(name) > CODEX_PROJECT_MAX)
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
def parse_codex_title(title, harness=None, cwd=None, host=None):
|
|
406
535
|
"""A Codex pane title -> {'harness','status','name'}, or None for a shell / non-agent title. `harness` is the pane's
|
|
407
536
|
OBSERVED harness (`harness_walk`): a pane running another harness (claude, kimi, grok, grok-cli) is never Codex's.
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
537
|
+
|
|
538
|
+
On a pane that runs Codex (BEY-8970) the title is read as one of the forms Codex writes, and a title in no such
|
|
539
|
+
form answers status UNKNOWN (merge then publishes the unknown class's row: never idle, never no agent): either
|
|
540
|
+
frame of the approval mark
|
|
541
|
+
ANYWHERE in the title -> needs_approval; a spinner first, or as a word of its own anywhere -> working; idle only
|
|
542
|
+
when the title's last ` | ` item (or its one word: a session not yet named) is a project of the process
|
|
543
|
+
(`codex_projects(cwd)`, `cwd` the directory statusd read for the harness pid). The mark's words outside the mark,
|
|
544
|
+
a first item that begins with another bracketed mark, a shell's title and `host` (tmux's default title, the
|
|
545
|
+
pane's host name) are no form Codex writes.
|
|
546
|
+
|
|
547
|
+
On a pane running something else (`unknown`) only the mark and a braille spinner are Codex's; on a bare shell
|
|
548
|
+
(`shell`, a title tmux kept after Codex exited) and where the harness could not be observed (None) also its idle
|
|
549
|
+
`<task> | <dir>`. The pre-W12 catch-all, "any title of two or more words is Codex idle", is gone (DEF-1970)."""
|
|
412
550
|
if harness not in (None, 'codex', 'unknown', 'shell'):
|
|
413
551
|
return None
|
|
552
|
+
found = _codex_title(title, harness, cwd, host)
|
|
553
|
+
if found is None and harness == 'codex':
|
|
554
|
+
return {'harness': 'codex', 'status': UNKNOWN, 'name': ''}
|
|
555
|
+
return found
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
def _codex_title(title, harness, cwd, host):
|
|
559
|
+
host = host if isinstance(host, str) and host else None # a name that was read, or none
|
|
414
560
|
t = (title or '').strip()
|
|
561
|
+
mark = next((action for action in ACTIONS if action in t), None)
|
|
562
|
+
if mark:
|
|
563
|
+
rest = [p.strip() for p in t.split(mark, 1)[1].split('|') if p.strip()]
|
|
564
|
+
return {'harness': 'codex', 'status': 'needs_approval', 'name': rest[0] if rest else ''}
|
|
565
|
+
if ACTION_DRAWN in _ascii_lower(''.join(each for each in t if not _title_unseen(each))):
|
|
566
|
+
return None # the mark's words outside the mark, whatever draws nothing between or inside them
|
|
415
567
|
head = t.split('|')[0]
|
|
416
|
-
if t in SHELL_TITLES or (': ' in head and head.startswith(('coder@', 'root@'))):
|
|
568
|
+
if t in SHELL_TITLES or (host and t == host) or (': ' in head and head.startswith(('coder@', 'root@'))):
|
|
417
569
|
return None
|
|
418
|
-
if t.startswith(
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
570
|
+
if t.startswith(LISTENING):
|
|
571
|
+
t = t[len(LISTENING):].strip()
|
|
572
|
+
head = t.split('|')[0]
|
|
573
|
+
drawn = ''.join(each for each in t if not _title_unseen(each)) # what a person sees of it, spaces aside
|
|
574
|
+
if UNKNOWN_MARK_RE.match(drawn):
|
|
575
|
+
return None
|
|
576
|
+
alone = [word for word in _title_words(t) if len(word) == 1 and _braille(word)] # a braille glyph as a word
|
|
577
|
+
if (drawn[:1] and _braille(drawn[0]) and drawn[0] not in SPINNER) or any(word not in SPINNER for word in alone):
|
|
578
|
+
return None # a braille glyph that is none of the spinner's: no form Codex writes
|
|
579
|
+
if drawn[:1] and drawn[0] in SPINNER:
|
|
580
|
+
return {'harness': 'codex', 'status': 'working', 'name': t[t.index(drawn[0]) + 1:].split('|')[0].strip()}
|
|
581
|
+
if alone:
|
|
582
|
+
return {'harness': 'codex', 'status': 'working', 'name': ''}
|
|
423
583
|
if t.startswith('✳'):
|
|
424
584
|
return None # Claude's static title: presence only; the session file carries the state
|
|
425
|
-
if harness == 'codex'
|
|
585
|
+
if harness == 'codex':
|
|
586
|
+
items = [item.strip() for item in t.split(CODEX_SEPARATOR)]
|
|
587
|
+
if len(items) == 1 and not host:
|
|
588
|
+
return None # one word, and the host's name was not read: it may be the title nobody set
|
|
589
|
+
if all(items) and items[-1] in codex_projects(cwd):
|
|
590
|
+
return {'harness': 'codex', 'status': 'idle', 'name': items[0] if len(items) > 1 else ''}
|
|
591
|
+
return None
|
|
592
|
+
if harness != 'unknown' and '|' in t:
|
|
426
593
|
return {'harness': 'codex', 'status': 'idle', 'name': head.strip()}
|
|
427
594
|
return None
|
|
428
595
|
|
|
@@ -459,13 +626,67 @@ def ancestry(proc_root, pid, depth=ANCESTRY_DEPTH):
|
|
|
459
626
|
return tuple(chain)
|
|
460
627
|
|
|
461
628
|
|
|
462
|
-
def
|
|
629
|
+
def _nests_deeper(value, limit):
|
|
630
|
+
"""Whether `value` (parsed JSON) holds lists and objects more than `limit` levels deep, itself the first. No
|
|
631
|
+
recursion: a deep value must not be what ends the walk."""
|
|
632
|
+
stack = [(value, 1)]
|
|
633
|
+
while stack:
|
|
634
|
+
item, level = stack.pop()
|
|
635
|
+
if isinstance(item, (dict, list)):
|
|
636
|
+
if level > limit:
|
|
637
|
+
return True
|
|
638
|
+
stack.extend((child, level + 1) for child in (item.values() if isinstance(item, dict) else item))
|
|
639
|
+
return False
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
def _read_session_file(path):
|
|
643
|
+
"""(document, there) for the session file at `path`. A dict and True when it can be read whole. (None, True) when
|
|
644
|
+
a file is there and cannot: it is no regular file (opened without following a link and without blocking, so a
|
|
645
|
+
FIFO, a directory or a link at the name can never hang or redirect the read of a whole container), it is over
|
|
646
|
+
SESSION_FILE_MAX bytes, not UTF-8, not JSON, no object, or nested deeper than SESSION_DEPTH_MAX levels. (None,
|
|
647
|
+
False) when no file is there (it went between the listing and the read)."""
|
|
648
|
+
try:
|
|
649
|
+
fd = os.open(str(path), os.O_RDONLY | os.O_NONBLOCK | getattr(os, 'O_NOFOLLOW', 0) | getattr(os, 'O_CLOEXEC', 0))
|
|
650
|
+
except FileNotFoundError:
|
|
651
|
+
return None, False
|
|
652
|
+
except OSError:
|
|
653
|
+
return None, True
|
|
654
|
+
try:
|
|
655
|
+
if not stat.S_ISREG(os.fstat(fd).st_mode):
|
|
656
|
+
return None, True
|
|
657
|
+
raw = b''
|
|
658
|
+
while len(raw) <= SESSION_FILE_MAX:
|
|
659
|
+
chunk = os.read(fd, SESSION_FILE_MAX + 1 - len(raw))
|
|
660
|
+
if not chunk:
|
|
661
|
+
break
|
|
662
|
+
raw += chunk
|
|
663
|
+
if len(raw) > SESSION_FILE_MAX:
|
|
664
|
+
return None, True # not Claude's: this ONE pane's unreadable file
|
|
665
|
+
d = json.loads(raw.decode('utf-8'))
|
|
666
|
+
except (OSError, ValueError, RecursionError):
|
|
667
|
+
return None, True # RecursionError: a file nested deeper than the parser goes; it costs only its own pane
|
|
668
|
+
finally:
|
|
669
|
+
os.close(fd)
|
|
670
|
+
if not isinstance(d, dict) or _nests_deeper(d, SESSION_DEPTH_MAX):
|
|
671
|
+
return None, True
|
|
672
|
+
return d, True
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
def _pane_of(proc_root, pid, panes):
|
|
676
|
+
"""The bound key of the ONE pane of `panes` whose root process is `pid` or one of its ancestors, or None (no
|
|
677
|
+
pane's, or more than one's): the pane a process runs in, read from the process tree and from nothing it wrote."""
|
|
678
|
+
line = ancestry(proc_root, pid)
|
|
679
|
+
owners = [bound_key(socket, key) for socket, index in panes.items() for key, root in index.items() if root in line]
|
|
680
|
+
return owners[0] if len(owners) == 1 else None
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
def claude_files(sessions_dir, proc_root, panes=None, unreadable=None):
|
|
463
684
|
"""The live Claude session files of one container -> [(key, pid, document)], unordered. Live: `pid` (the file name)
|
|
464
685
|
exists in `proc_root` — the container's /proc as the host sees it (/proc/<container-pid>/root/proc), so liveness
|
|
465
686
|
is checked in the container's pid namespace — and, when the file carries `procStart`, still is the process that
|
|
466
687
|
wrote it (`_same_process`: a recycled pid is skipped; no `procStart` -> existence only). `document` is the parsed
|
|
467
|
-
file; its `tmux` must be a non-empty string. A malformed file
|
|
468
|
-
else their agent. Only `<pid>.json` is ever opened (the `<pid>.<hash>.key` beside it never is, DEF-1802).
|
|
688
|
+
file; its `tmux` must be a non-empty string. A malformed file, one over SESSION_FILE_MAX bytes and one nested
|
|
689
|
+
deeper than SESSION_DEPTH_MAX levels are skipped, never raised: one bad file costs nobody else their agent. Only `<pid>.json` is ever opened (the `<pid>.<hash>.key` beside it never is, DEF-1802).
|
|
469
690
|
|
|
470
691
|
`panes` binds every file to its tmux server (BEY-6838): {socket: {pane key: the pane's root pid}}, the panes of the
|
|
471
692
|
container's servers as their own `list-panes` rows name them. A file then counts only for the socket whose pane of
|
|
@@ -473,21 +694,33 @@ def claude_files(sessions_dir, proc_root, panes=None):
|
|
|
473
694
|
skipped when no socket's pane qualifies (a process outside every listed pane: another server's, one reparented to
|
|
474
695
|
init, or one whose file names a pane it does not run in) or when more than one does. Without `panes` the key is the
|
|
475
696
|
`tmux` string itself, socket-blind: right only where the container runs one tmux server (the pure readers' unit
|
|
476
|
-
fixtures); statusd and `lanes_lib.rename_claude` always bind.
|
|
697
|
+
fixtures); statusd and `lanes_lib.rename_claude` always bind.
|
|
698
|
+
|
|
699
|
+
`unreadable`, when a list and `panes` is given, receives (bound key, pid) for every live pid whose file is there
|
|
700
|
+
and cannot be read whole (`_read_session_file`), whose process is Claude Code (`_harness_of`) and runs in
|
|
701
|
+
exactly one listed pane (`_pane_of`).
|
|
702
|
+
Such a file is never among the returned ones."""
|
|
477
703
|
out = []
|
|
478
704
|
try:
|
|
479
705
|
names = os.listdir(sessions_dir)
|
|
480
706
|
except OSError:
|
|
481
707
|
return out
|
|
482
|
-
for fn in names:
|
|
708
|
+
for fn in sorted(names): # a stated order: two files of one pane in one second are judged alike everywhere
|
|
483
709
|
stem = fn[:-5] if fn.endswith('.json') else ''
|
|
484
710
|
if not stem.isdigit() or not os.path.exists(os.path.join(proc_root, stem)):
|
|
485
711
|
continue
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
712
|
+
d, there = _read_session_file(Path(sessions_dir, fn))
|
|
713
|
+
if d is None:
|
|
714
|
+
# A live pid's file that cannot be read whole says nothing, not even its pane. Where the panes are
|
|
715
|
+
# known, the process tree names the pane, and the caller is told: that pane's newest file is unreadable.
|
|
716
|
+
# Only for a pid that IS Claude Code: a readable file of a recycled pid is refused by its `procStart`,
|
|
717
|
+
# and an unreadable one cannot be, so the process itself must say what it is.
|
|
718
|
+
key = None
|
|
719
|
+
if there and panes is not None and unreadable is not None \
|
|
720
|
+
and _harness_of(proc_root, stem, _comm(proc_root, stem)) == 'claude':
|
|
721
|
+
key = _pane_of(proc_root, stem, panes)
|
|
722
|
+
if key is not None:
|
|
723
|
+
unreadable.append((key, int(stem)))
|
|
491
724
|
continue
|
|
492
725
|
if str(d.get('messagingSocketPath') or '').startswith(VIRTUAL_PEERS):
|
|
493
726
|
continue # lane-peerd's virtual peer (W15 L6): the lane's agent is not Claude
|
|
@@ -507,6 +740,55 @@ def claude_files(sessions_dir, proc_root, panes=None):
|
|
|
507
740
|
return out
|
|
508
741
|
|
|
509
742
|
|
|
743
|
+
def process_argv(proc_root, pid):
|
|
744
|
+
"""The arguments of process `pid` as a list of str, or None: a cmdline that cannot be read, is empty (a process
|
|
745
|
+
that has gone), is over ARGV_MAX bytes or is not UTF-8. One bounded read; nothing is started."""
|
|
746
|
+
try:
|
|
747
|
+
with open(Path(proc_root, str(pid), 'cmdline'), 'rb') as handle:
|
|
748
|
+
raw = handle.read(ARGV_MAX + 1)
|
|
749
|
+
except OSError:
|
|
750
|
+
return None
|
|
751
|
+
if not raw or len(raw) > ARGV_MAX:
|
|
752
|
+
return None
|
|
753
|
+
try:
|
|
754
|
+
text = raw.decode('utf-8')
|
|
755
|
+
except UnicodeDecodeError:
|
|
756
|
+
return None
|
|
757
|
+
return (text[:-1] if text.endswith('\0') else text).split('\0')
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
def codex_batch(argv):
|
|
761
|
+
"""True when a Codex process's own arguments `argv` (the executable first) say a batch run: the first argument that
|
|
762
|
+
is not one of Codex's global options is one of CODEX_BATCH_WORDS. An option of CODEX_OPTIONS_WITH_A_VALUE skips
|
|
763
|
+
its value (`--name=value` is one argument); an option neither table holds ends the read: False, never a guess.
|
|
764
|
+
Anything but a list of str is False."""
|
|
765
|
+
if not isinstance(argv, (list, tuple)) or not all(isinstance(word, str) for word in argv):
|
|
766
|
+
return False
|
|
767
|
+
rest = iter(argv[1:])
|
|
768
|
+
for word in rest:
|
|
769
|
+
if word in CODEX_OPTIONS_WITHOUT:
|
|
770
|
+
continue
|
|
771
|
+
if word in CODEX_OPTIONS_WITH_A_VALUE:
|
|
772
|
+
if next(rest, None) is None:
|
|
773
|
+
return False
|
|
774
|
+
continue
|
|
775
|
+
if word.startswith('--') and '=' in word and word.partition('=')[0] in CODEX_OPTIONS_WITH_A_VALUE:
|
|
776
|
+
continue
|
|
777
|
+
return word in CODEX_BATCH_WORDS
|
|
778
|
+
return False
|
|
779
|
+
|
|
780
|
+
|
|
781
|
+
def _tie_rank(entry):
|
|
782
|
+
"""Where a session-file entry stands among the files of one pane and one second: a waiting read 2, a file in no
|
|
783
|
+
known form 1, the rest 0."""
|
|
784
|
+
return 2 if waiting_read(entry) else 1 if entry.get('status') == UNKNOWN else 0
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
def waiting_read(entry):
|
|
788
|
+
"""Whether a Claude session-file entry is a WAITING read (the file said `waiting`): it carries an `event`."""
|
|
789
|
+
return isinstance(entry, dict) and entry.get('source') == 'claude-session-file' and 'event' in entry
|
|
790
|
+
|
|
791
|
+
|
|
510
792
|
def claude_sessions(sessions_dir, proc_root, work=None, panes=None):
|
|
511
793
|
"""pane key -> agent dict, live pids only (`claude_files`, which `panes` binds to the tmux server each process runs
|
|
512
794
|
in: the key is then `bound_key(socket, pane key)`, BEY-6838). Several files can name one pane (a resumed session
|
|
@@ -516,25 +798,51 @@ def claude_sessions(sessions_dir, proc_root, work=None, panes=None):
|
|
|
516
798
|
`work`, when a dict, also receives {pane key: (cwd, status)} of each winning file — its `cwd` (None unless a
|
|
517
799
|
string) and Claude's own word (`idle`, `waiting`, ...) — for `delegation_check` (W15 L1); the published entry does
|
|
518
800
|
not carry them."""
|
|
519
|
-
out = {}
|
|
520
|
-
|
|
801
|
+
out, unreadable = {}, []
|
|
802
|
+
files = claude_files(sessions_dir, proc_root, panes, unreadable)
|
|
803
|
+
# A pane whose live process has a file that cannot be read whole: no stamp can be read from it, so it counts as
|
|
804
|
+
# the pane's newest file, and the pane is in no known form whatever an older live file of it says.
|
|
805
|
+
closed = {}
|
|
806
|
+
for key, pid in unreadable:
|
|
807
|
+
closed[key] = {'harness': 'claude', 'status': UNKNOWN, 'name': '', 'session_id': '', 'pid': pid,
|
|
808
|
+
'source': 'claude-session-file'}
|
|
809
|
+
if work is not None:
|
|
810
|
+
work[key] = (None, None)
|
|
811
|
+
for key, pid, d in files:
|
|
812
|
+
if key in closed:
|
|
813
|
+
continue
|
|
521
814
|
try:
|
|
522
815
|
since = int((d.get('statusUpdatedAt') or 0) // 1000)
|
|
523
816
|
except (TypeError, ValueError):
|
|
524
817
|
continue
|
|
525
|
-
|
|
526
|
-
if
|
|
527
|
-
|
|
818
|
+
word, reason = d.get('status'), d.get('waitingFor')
|
|
819
|
+
if word == 'waiting':
|
|
820
|
+
reason = reason if isinstance(reason, str) else ''
|
|
821
|
+
status = CLAUDE_WAITING_PUBLISHES[CLAUDE_WAITING.get(_ascii_lower(reason.strip()), 'unlisted')]
|
|
822
|
+
elif 'waitingFor' in d or not isinstance(word, str) or word not in STATUS_FROM_CLAUDE:
|
|
823
|
+
status = UNKNOWN # a status Claude Code does not write, or a waiting reason beside another status
|
|
824
|
+
else:
|
|
825
|
+
status = STATUS_FROM_CLAUDE[word]
|
|
528
826
|
entry = {'harness': 'claude', 'status': status, 'name': str(d.get('name') or ''),
|
|
529
827
|
'session_id': str(d.get('sessionId') or ''), 'pid': pid,
|
|
530
828
|
'since': since, 'source': 'claude-session-file'}
|
|
829
|
+
if word == 'waiting':
|
|
830
|
+
# The harness's own reason, as read (a question, a menu, …); WAITING_EVENT when it names none. An `event`
|
|
831
|
+
# is what marks a session-file entry as a WAITING read (waiting_read): no other entry of this file has one.
|
|
832
|
+
entry['event'] = reason.strip()[:EVENT_MAX] or WAITING_EVENT
|
|
531
833
|
if since < 0:
|
|
532
834
|
del entry['since'] # FC-I-6: an instant is an unsigned count; a negative one is no instant
|
|
533
|
-
|
|
835
|
+
held = out.get(key)
|
|
836
|
+
newer = held is None or entry.get('since', -1) > held.get('since', -1)
|
|
837
|
+
# The same second (files are read in name order): a waiting read first, then a file in no known form, then
|
|
838
|
+
# the rest; among equals the later file wins.
|
|
839
|
+
tie = held is not None and entry.get('since', -1) == held.get('since', -1) and _tie_rank(entry) >= _tie_rank(held)
|
|
840
|
+
if newer or tie:
|
|
534
841
|
out[key] = entry
|
|
535
842
|
if work is not None:
|
|
536
843
|
cwd = d.get('cwd')
|
|
537
844
|
work[key] = (cwd if isinstance(cwd, str) else None, d.get('status'))
|
|
845
|
+
out.update(closed)
|
|
538
846
|
return out
|
|
539
847
|
|
|
540
848
|
|
|
@@ -1155,11 +1463,16 @@ BELL_LESS = ('muse', 'zcode')
|
|
|
1155
1463
|
|
|
1156
1464
|
def merge(pane_row, claude_by_pane, sidecar, kimi_by_pane=None, grok_by_pane=None, muse_by_pane=None, delegating=None,
|
|
1157
1465
|
key=None):
|
|
1158
|
-
"""
|
|
1466
|
+
"""The pane's published verdict. The order of the sources is `_verdict`'s (BEY-8970): an observer's own
|
|
1467
|
+
`needs_approval` > a waiting read with another word (unless the hook sidecar says SIDECAR_OVER_WAITING) > the hook
|
|
1468
|
+
sidecar (event-driven, every harness) > the unknown class's row > the observers' own verdict. The observers' own
|
|
1469
|
+
order (`_own`): Claude session file > Kimi session file > Muse session
|
|
1159
1470
|
file (`muse_sessions`, W13) > Grok observer (`grok_sessions`: its session file, else the title with its blink
|
|
1160
1471
|
memory) > the Grok title (`grok_title`, a pane observed as `grok` nothing above claimed) > the Muse title
|
|
1161
|
-
(`muse_title`, a pane observed as `muse`) > Codex
|
|
1162
|
-
|
|
1472
|
+
(`muse_title`, a pane observed as `muse`) > a Codex batch run (`harness_batch`, statusd's row key: working from
|
|
1473
|
+
its process, whatever the title says) > Codex title > the observed harness itself > the bell (never for a
|
|
1474
|
+
BELL_LESS harness). A pane observed as Claude Code with no usable session file, a session file in no known form
|
|
1475
|
+
and a Codex title in no known form are the unknown class (`_unknown_row`): never idle, never no agent.
|
|
1163
1476
|
Any Codex title — idle, spinner or Action Required, bell or not — over a bare-shell pane whose shell has no
|
|
1164
1477
|
child process (`pane_has_child is False`, statusd's row key) publishes `shell`: the harness ended and tmux kept
|
|
1165
1478
|
its last title, so no ghost idle/done/working/needs_approval. Unknown liveness leaves the title in charge.
|
|
@@ -1170,60 +1483,153 @@ def merge(pane_row, claude_by_pane, sidecar, kimi_by_pane=None, grok_by_pane=Non
|
|
|
1170
1483
|
the window bell set is `done` — a turn ended and the harness rang — except a question still asked of the person
|
|
1171
1484
|
(`event: interaction.request`); the Grok observer's verdicts carry its own bell rule (only a completed turn or an
|
|
1172
1485
|
idle title is `done`) and are taken as they come. The Grok observer's GROK_UNKNOWN (leader mode: its Grok Build runs a session it
|
|
1173
|
-
cannot join to the pane) publishes no agent{}: nothing below may guess one. Last rung: a pane whose observed harness
|
|
1486
|
+
cannot join to the pane) publishes no agent{} where no sidecar stands: nothing below may guess one. Last rung: a pane whose observed harness
|
|
1174
1487
|
nothing above claimed is that harness, `idle`, `done` with the bell (`source: process`, `pid` the harness pid statusd
|
|
1175
1488
|
found). Returns None when nothing says an agent is here — the sidebar then draws a plain shell.
|
|
1176
1489
|
|
|
1177
1490
|
W15 L1, after all of that (so after the sidecar too): a Claude verdict in DELEGATING_FROM whose session is
|
|
1178
1491
|
delegating — `delegating(pane key)`, statusd's `delegation_check`, asked only then — is published `working` with
|
|
1179
1492
|
the additive `activity: 'delegating'`; every other key is the verdict's own. A `needs_approval` or `errored` verdict
|
|
1180
|
-
is never in DELEGATING_FROM: a permission prompt or a failed turn is real whatever runs in the background.
|
|
1493
|
+
is never in DELEGATING_FROM: a permission prompt or a failed turn is real whatever runs in the background. A
|
|
1494
|
+
waiting read and the unknown class's row are never turned into `working`, whatever their word.
|
|
1181
1495
|
|
|
1182
1496
|
`key` is what every index and `delegating` are looked up by: the pane's `pane_key` by default; statusd passes
|
|
1183
1497
|
`bound_key(socket, pane_key)`, its indexes being keyed by tmux server too (BEY-6838: two servers of one container
|
|
1184
1498
|
may hold the same local key, and a socket-blind lookup gave one pane's agent to the other's row)."""
|
|
1499
|
+
return merge_classed(pane_row, claude_by_pane, sidecar, kimi_by_pane, grok_by_pane, muse_by_pane, delegating,
|
|
1500
|
+
key)[0]
|
|
1501
|
+
|
|
1502
|
+
|
|
1503
|
+
def merge_classed(pane_row, claude_by_pane, sidecar, kimi_by_pane=None, grok_by_pane=None, muse_by_pane=None,
|
|
1504
|
+
delegating=None, key=None):
|
|
1505
|
+
"""`merge`'s verdict with its kind: (verdict or None, kind). kind UNKNOWN: the verdict is the unknown class's row
|
|
1506
|
+
(statusd holds it back a cycle by this, never by the row's text); 'waiting': a waiting read of the harness's own
|
|
1507
|
+
state; BESIDE_UNKNOWN: a hook sidecar's verdict beside an own read that is the unknown class; 'none': an observer
|
|
1508
|
+
that says no agent may be published here; None otherwise."""
|
|
1185
1509
|
observed = pane_row.get('harness')
|
|
1186
1510
|
key = pane_key(pane_row) if key is None else key
|
|
1187
|
-
verdict = _verdict(pane_row, claude_by_pane, sidecar, kimi_by_pane or {}, grok_by_pane or {},
|
|
1188
|
-
|
|
1511
|
+
verdict, kind = _verdict(pane_row, claude_by_pane, sidecar, kimi_by_pane or {}, grok_by_pane or {},
|
|
1512
|
+
muse_by_pane or {}, observed, key)
|
|
1189
1513
|
if verdict is not None and observed in AGENT_HARNESSES:
|
|
1190
1514
|
verdict['harness'] = observed
|
|
1191
|
-
|
|
1515
|
+
# A waiting read and the unknown class are never turned into `working` by the delegating rule, and where the own
|
|
1516
|
+
# read is the unknown class the rule applies to nothing that is published for the pane (`kind`).
|
|
1517
|
+
if (verdict is not None and kind is None and delegating is not None and verdict.get('harness') == 'claude'
|
|
1192
1518
|
and verdict.get('status') in DELEGATING_FROM and delegating(key)):
|
|
1193
1519
|
verdict.update(status='working', activity='delegating')
|
|
1194
|
-
return verdict
|
|
1520
|
+
return verdict, kind
|
|
1195
1521
|
|
|
1196
1522
|
|
|
1197
1523
|
def _verdict(pane_row, claude_by_pane, sidecar, kimi_by_pane, grok_by_pane, muse_by_pane, observed, key):
|
|
1198
|
-
|
|
1199
|
-
|
|
1524
|
+
"""(verdict or None, kind) for one pane. `kind`: 'waiting' for a waiting read of the harness's own state,
|
|
1525
|
+
UNKNOWN for the unknown class's row, BESIDE_UNKNOWN for a sidecar published beside one, None otherwise. The
|
|
1526
|
+
order (BEY-8970):
|
|
1527
|
+
|
|
1528
|
+
1. An observer's own `needs_approval` (the Claude session file, the Codex title, the Kimi, Muse and Grok
|
|
1529
|
+
observers) is published above every hook sidecar, as that observer's WHOLE verdict.
|
|
1530
|
+
2. A waiting read with another word (the Claude session file said `waiting`) is published above a hook sidecar
|
|
1531
|
+
that says anything but SIDECAR_OVER_WAITING.
|
|
1532
|
+
3. A hook sidecar with a known word: its whole verdict.
|
|
1533
|
+
4. The unknown class (a harness observed in a form no observer knows): its row in CLAUDE_WAITING_PUBLISHES,
|
|
1534
|
+
with UNKNOWN_EVENT. Never idle, never no agent.
|
|
1535
|
+
5. The observers' own verdict otherwise.
|
|
1536
|
+
|
|
1537
|
+
Nothing is kept between cycles for this: the own read rules for exactly as long as it says what it says. The
|
|
1538
|
+
ended-harness rule stays inside the own read (a marked title over a childless shell is `shell`, never an approval)."""
|
|
1539
|
+
side = dict(sidecar, source=sidecar.get('source') or 'hook') if sidecar and sidecar.get('status') in STATUSES \
|
|
1540
|
+
else None
|
|
1541
|
+
own, kind = _own(pane_row, claude_by_pane, kimi_by_pane, grok_by_pane, muse_by_pane, observed, key)
|
|
1542
|
+
if own is not None and kind != UNKNOWN:
|
|
1543
|
+
if own.get('status') == 'needs_approval':
|
|
1544
|
+
return own, 'waiting'
|
|
1545
|
+
if kind == 'waiting' and not (side and side['status'] in SIDECAR_OVER_WAITING):
|
|
1546
|
+
return own, kind
|
|
1547
|
+
if side:
|
|
1548
|
+
return side, (BESIDE_UNKNOWN if kind == UNKNOWN else None)
|
|
1549
|
+
return own, kind
|
|
1550
|
+
|
|
1551
|
+
|
|
1552
|
+
def _unknown_row(observed, source, since, known=None, pid=0):
|
|
1553
|
+
"""The unknown class's verdict for a pane whose observed harness is `observed`: an agent of that harness with the
|
|
1554
|
+
interim row's word, its `event` saying why the row stands. `known`: what the own read does know of the agent (a
|
|
1555
|
+
Claude entry's name, session and pid)."""
|
|
1556
|
+
row = dict(known or {}, harness=observed, status=CLAUDE_WAITING_PUBLISHES[UNKNOWN], source=source,
|
|
1557
|
+
event=UNKNOWN_EVENT)
|
|
1558
|
+
row.setdefault('name', '')
|
|
1559
|
+
if 'since' not in row and since is not None:
|
|
1560
|
+
row['since'] = since
|
|
1561
|
+
if 'pid' not in row and pid > 0:
|
|
1562
|
+
row['pid'] = pid # the harness the pane runs, as the process rung these rows replace carried it
|
|
1563
|
+
return row
|
|
1564
|
+
|
|
1565
|
+
|
|
1566
|
+
def _harness_pid(pane_row):
|
|
1567
|
+
"""The harness pid statusd found for the pane, 0 when it names none."""
|
|
1568
|
+
try:
|
|
1569
|
+
return int(pane_row.get('harness_pid') or 0)
|
|
1570
|
+
except (TypeError, ValueError):
|
|
1571
|
+
return 0
|
|
1572
|
+
|
|
1573
|
+
|
|
1574
|
+
def _codex_marked(pane_row, observed):
|
|
1575
|
+
"""Whether the pane's title holds Codex's approval mark."""
|
|
1576
|
+
title = parse_codex_title(pane_row.get('pane_title'), observed, pane_row.get('harness_cwd'), pane_row.get('host'))
|
|
1577
|
+
return bool(title) and title['status'] == 'needs_approval'
|
|
1578
|
+
|
|
1579
|
+
|
|
1580
|
+
def _own(pane_row, claude_by_pane, kimi_by_pane, grok_by_pane, muse_by_pane, observed, key):
|
|
1581
|
+
"""(verdict or None, kind) from the observers below the hook sidecar, in their order. kind 'waiting': the Claude
|
|
1582
|
+
session file said `waiting`; UNKNOWN: the unknown class's row; 'none': an observer that says no agent may be
|
|
1583
|
+
published or guessed here (the Grok observer's cannot-join word)."""
|
|
1584
|
+
try:
|
|
1585
|
+
activity = int(pane_row.get('window_activity') or 0)
|
|
1586
|
+
except ValueError:
|
|
1587
|
+
activity = 0
|
|
1200
1588
|
if key in claude_by_pane:
|
|
1201
|
-
|
|
1589
|
+
found = claude_by_pane[key]
|
|
1590
|
+
if found.get('status') == UNKNOWN: # seen, in no form the observer knows
|
|
1591
|
+
known = {name: found[name] for name in ('name', 'session_id', 'pid', 'since') if name in found}
|
|
1592
|
+
return _unknown_row('claude', 'claude-session-file', activity, known, _harness_pid(pane_row)), UNKNOWN
|
|
1593
|
+
return dict(found), ('waiting' if waiting_read(found) else None)
|
|
1594
|
+
if observed == 'claude':
|
|
1595
|
+
# A pane that runs Claude Code and no usable session file of it (unreadable, malformed, another pane's): the
|
|
1596
|
+
# same class. Its process says nothing of whether it waits.
|
|
1597
|
+
return _unknown_row('claude', 'claude-session-file', activity, pid=_harness_pid(pane_row)), UNKNOWN
|
|
1202
1598
|
bell = pane_row.get('window_bell_flag') == '1' and observed not in BELL_LESS
|
|
1203
1599
|
# The Kimi observer leaves the bell to merge; the Grok observer applies it itself (harness_grok: only a completed
|
|
1204
1600
|
# turn or an idle title is `done` — a cancelled or interrupted turn stays needs_input, spec §4); Muse rings none.
|
|
1205
1601
|
for index, rings in ((kimi_by_pane, True), (muse_by_pane, False), (grok_by_pane, False)):
|
|
1206
1602
|
found = index.get(key)
|
|
1207
1603
|
if isinstance(found, dict) and found.get('status') == GROK_UNKNOWN:
|
|
1208
|
-
return None # seen, not joinable (Grok's leader mode): no guess below
|
|
1604
|
+
return None, 'none' # seen, not joinable (Grok's leader mode): no guess below
|
|
1209
1605
|
if isinstance(found, dict) and found.get('status') in STATUSES:
|
|
1210
1606
|
found = dict(found)
|
|
1211
1607
|
if rings and found['status'] == 'needs_input' and bell and found.get('event') != 'interaction.request':
|
|
1212
1608
|
found['status'] = 'done'
|
|
1213
|
-
return found
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1609
|
+
return found, None
|
|
1610
|
+
if observed == 'codex' and pane_row.get('harness_batch') is True and not _codex_marked(pane_row, observed):
|
|
1611
|
+
# A Codex batch run (statusd read it from the process's own arguments, `codex_batch`): it writes no title, so
|
|
1612
|
+
# the title on its pane is not its, and nobody waits at it. The approval mark alone stands above this row.
|
|
1613
|
+
found = {'harness': 'codex', 'status': 'working', 'name': '', 'source': 'process', 'since': activity,
|
|
1614
|
+
'event': BATCH_EVENT}
|
|
1615
|
+
harness_pid = _harness_pid(pane_row)
|
|
1616
|
+
if harness_pid > 0:
|
|
1617
|
+
found['pid'] = harness_pid
|
|
1618
|
+
return found, None
|
|
1218
1619
|
if observed == 'grok':
|
|
1219
1620
|
found = grok_title(pane_row, bell, activity)
|
|
1220
1621
|
if found:
|
|
1221
|
-
return found
|
|
1622
|
+
return found, None
|
|
1222
1623
|
if observed == 'muse':
|
|
1223
1624
|
found = muse_title(pane_row, activity)
|
|
1224
1625
|
if found:
|
|
1225
|
-
return found
|
|
1226
|
-
title = parse_codex_title(pane_row.get('pane_title'), observed)
|
|
1626
|
+
return found, None
|
|
1627
|
+
title = parse_codex_title(pane_row.get('pane_title'), observed, pane_row.get('harness_cwd'), pane_row.get('host'))
|
|
1628
|
+
if title and title['status'] == UNKNOWN:
|
|
1629
|
+
# A pane that runs Codex, its title in no form the observer knows: the unknown class, no guess below.
|
|
1630
|
+
return _unknown_row('codex', 'title', activity, pid=_harness_pid(pane_row)), UNKNOWN
|
|
1631
|
+
if title and title['status'] == 'idle' and observed != 'codex' and not _harness_ended(pane_row):
|
|
1632
|
+
title = None # Codex's idle form is read only where Codex is observed: elsewhere a bar in a title is no evidence
|
|
1227
1633
|
if title:
|
|
1228
1634
|
if _harness_ended(pane_row):
|
|
1229
1635
|
title['status'] = 'shell' # stale title on a childless shell: the harness ended, no ghost of any kind
|
|
@@ -1231,18 +1637,15 @@ def _verdict(pane_row, claude_by_pane, sidecar, kimi_by_pane, grok_by_pane, muse
|
|
|
1231
1637
|
title['status'] = 'done'
|
|
1232
1638
|
title['source'] = 'title'
|
|
1233
1639
|
title['since'] = activity
|
|
1234
|
-
return title
|
|
1640
|
+
return title, None
|
|
1235
1641
|
if observed in AGENT_HARNESSES:
|
|
1236
1642
|
found = {'harness': observed, 'status': 'done' if bell else 'idle', 'name': '', 'source': 'process',
|
|
1237
1643
|
'since': activity}
|
|
1238
|
-
|
|
1239
|
-
harness_pid = int(pane_row.get('harness_pid') or 0)
|
|
1240
|
-
except (TypeError, ValueError):
|
|
1241
|
-
harness_pid = 0
|
|
1644
|
+
harness_pid = _harness_pid(pane_row)
|
|
1242
1645
|
if harness_pid > 0:
|
|
1243
1646
|
found['pid'] = harness_pid
|
|
1244
|
-
return found
|
|
1245
|
-
return None
|
|
1647
|
+
return found, None
|
|
1648
|
+
return None, None
|
|
1246
1649
|
|
|
1247
1650
|
|
|
1248
1651
|
def _stamp(value):
|
|
@@ -1022,9 +1022,10 @@ PANE_FORMAT = '\t'.join('#{' + f + '}' for f in PANE_FIELDS)
|
|
|
1022
1022
|
|
|
1023
1023
|
def pane_rows(text):
|
|
1024
1024
|
"""The rows of a `list-panes -F PANE_FORMAT` answer as dicts (a tab inside the title stays in the title); a line
|
|
1025
|
-
with fewer columns than PANE_FIELDS is not one of ours and is skipped.
|
|
1025
|
+
with fewer columns than PANE_FIELDS is not one of ours and is skipped. A row ends at tmux's own newline only: a
|
|
1026
|
+
title may hold U+2028 or U+0085 (MEASURED, tmux 3.4), which splitlines() would take for a row's end (BEY-8970)."""
|
|
1026
1027
|
rows = []
|
|
1027
|
-
for line in (text or '').
|
|
1028
|
+
for line in (text or '').split('\n'):
|
|
1028
1029
|
values = line.split('\t', len(PANE_FIELDS) - 1)
|
|
1029
1030
|
if len(values) == len(PANE_FIELDS):
|
|
1030
1031
|
rows.append(dict(zip(PANE_FIELDS, values)))
|
|
@@ -1,59 +1,267 @@
|
|
|
1
|
-
"""External site-hook loader (FLE-388, BEY-6912 durable federation).
|
|
2
|
-
|
|
3
|
-
A host declares `LANES_SITE_HOOK=<dir>` in site.conf (or the env). Each `.py`
|
|
4
|
-
module in that dir may define any of install_library / install_status /
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"""External site-hook loader (FLE-388, BEY-6912 durable federation; hardened FLE-413, 27 Nov 2026).
|
|
2
|
+
|
|
3
|
+
A host declares `LANES_SITE_HOOK=<absolute dir>` in `$HOME/.config/lanes/site.conf` (or the env). Each `.py`
|
|
4
|
+
module in that dir may define any of install_library / install_status / install_cli / install_docs /
|
|
5
|
+
install_actions. At each entrypoint the matching one is called, so a host's federation hook lives OUTSIDE the
|
|
6
|
+
package tree and survives every update. No declaration (or `=refuse`) -> a no-op. Values are read from site.conf,
|
|
7
|
+
never executed.
|
|
8
|
+
|
|
9
|
+
The hooks run inside every host process that imports `lanes_lib`, so the loader takes only what the host account
|
|
10
|
+
controls (FLE-413):
|
|
11
|
+
|
|
12
|
+
* The declared path is absolute, and without HOME no site.conf is read: nothing resolves against the working
|
|
13
|
+
directory.
|
|
14
|
+
* site.conf is read first only to learn whether it declares a hook (a regular file, O_NOFOLLOW | O_NONBLOCK, at
|
|
15
|
+
most MAX_BYTES; a value there is never executed). A declaration loads code, so then site.conf's directories and
|
|
16
|
+
the hook directory are checked component by component with lstat (no symlink; owner root or this account; not
|
|
17
|
+
writable by group or others, except a root-owned sticky directory above, such as /tmp), and the last is opened
|
|
18
|
+
O_NOFOLLOW and compared by device and inode.
|
|
19
|
+
* site.conf and each hook are opened O_NOFOLLOW | O_NONBLOCK, checked with fstat on that fd (a regular file, owned
|
|
20
|
+
by root or this account, not writable by group or others, at most MAX_BYTES) and read from that fd, so a FIFO
|
|
21
|
+
never blocks and the bytes executed are the bytes checked.
|
|
22
|
+
* A hidden file and a file whose stem is not a module name are refused. A stem that names a Lanes module (any
|
|
23
|
+
module of this package's libexec) is refused, and every hook is loaded as `lanes_site_hook_<stem>`, never under
|
|
24
|
+
its bare stem, so no hook can become another module.
|
|
25
|
+
|
|
26
|
+
A refused directory loads nothing; a refused file is skipped and the others load. `doctor_lines()` reports what
|
|
27
|
+
was loaded and what was refused, and `lanes doctor` prints it; the loader itself writes nothing to stderr, so a
|
|
28
|
+
program's output never depends on it. A host with no site.conf and no LANES_SITE_HOOK opens nothing (one lstat).
|
|
9
29
|
"""
|
|
10
|
-
import
|
|
30
|
+
import errno
|
|
11
31
|
import os
|
|
32
|
+
import stat
|
|
12
33
|
import sys
|
|
34
|
+
import types
|
|
13
35
|
from pathlib import Path
|
|
14
36
|
|
|
15
37
|
_STAGES = ('library', 'status', 'cli', 'docs', 'actions')
|
|
38
|
+
MAX_BYTES = 1 << 20 # a site.conf or hook larger than this is refused
|
|
39
|
+
MODULE_PREFIX = 'lanes_site_hook_'
|
|
16
40
|
_modules = None
|
|
41
|
+
_report = None # {'dir': str | None, 'loaded': [stem], 'refused': [(name, why)], 'error': str | None}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class Refused(Exception):
|
|
45
|
+
"""A path the loader does not take; the message says why, without the file's content."""
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _owners():
|
|
49
|
+
"""The accounts whose files the loader takes: root and the account this process runs as."""
|
|
50
|
+
return {0, os.geteuid()}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _check(st, what, owners, sticky_ok=False):
|
|
54
|
+
if st.st_uid not in owners:
|
|
55
|
+
raise Refused(f'{what} is owned by uid {st.st_uid}, not by root or this account')
|
|
56
|
+
if st.st_mode & 0o022:
|
|
57
|
+
if sticky_ok and st.st_uid == 0 and stat.S_ISDIR(st.st_mode) and st.st_mode & stat.S_ISVTX:
|
|
58
|
+
return
|
|
59
|
+
raise Refused(f'{what} is writable by group or others ({oct(st.st_mode & 0o777)})')
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _open_dir(path, owners):
|
|
63
|
+
"""A directory fd for the absolute `path`. Every component is checked with lstat first (no open, so nothing
|
|
64
|
+
outside the path is read): not a symlink, a directory, owned by root or this account and not writable by group or
|
|
65
|
+
others, except a root-owned sticky directory above the last. Then the last is opened with O_NOFOLLOW and must be the
|
|
66
|
+
directory that was checked. No account but root and this one can change a component in between, because no
|
|
67
|
+
component is writable by another (a sticky root directory lets nobody else rename what this account owns)."""
|
|
68
|
+
if not isinstance(path, str) or not path.startswith('/'):
|
|
69
|
+
raise Refused('the path is not absolute')
|
|
70
|
+
parts = [part for part in path.split('/') if part]
|
|
71
|
+
if any(part in ('.', '..') for part in parts):
|
|
72
|
+
raise Refused('the path holds . or ..')
|
|
73
|
+
current, st = '/', os.lstat('/')
|
|
74
|
+
_check(st, '/', owners, sticky_ok=bool(parts))
|
|
75
|
+
for index, part in enumerate(parts):
|
|
76
|
+
current = os.path.join(current, part)
|
|
77
|
+
st = os.lstat(current)
|
|
78
|
+
if stat.S_ISLNK(st.st_mode):
|
|
79
|
+
raise Refused(f'{part} is a symlink')
|
|
80
|
+
if not stat.S_ISDIR(st.st_mode):
|
|
81
|
+
raise Refused(f'{part} is not a directory')
|
|
82
|
+
_check(st, part, owners, sticky_ok=index < len(parts) - 1)
|
|
83
|
+
try:
|
|
84
|
+
fd = os.open(path, os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW | os.O_CLOEXEC)
|
|
85
|
+
except OSError as error:
|
|
86
|
+
if error.errno in (errno.ELOOP, errno.ENOTDIR):
|
|
87
|
+
raise Refused(f'{parts[-1] if parts else "/"} changed while it was checked') from None
|
|
88
|
+
raise
|
|
89
|
+
opened = os.fstat(fd)
|
|
90
|
+
if (opened.st_dev, opened.st_ino) != (st.st_dev, st.st_ino):
|
|
91
|
+
os.close(fd)
|
|
92
|
+
raise Refused(f'{parts[-1] if parts else "/"} changed while it was checked')
|
|
93
|
+
return fd
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
_FILE_FLAGS = os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK | os.O_CLOEXEC
|
|
97
|
+
|
|
17
98
|
|
|
99
|
+
def _read(dir_fd, name, owners):
|
|
100
|
+
"""The bytes of regular file `name` in `dir_fd`, read from the fd that was checked (`_read_fd`)."""
|
|
101
|
+
try:
|
|
102
|
+
fd = os.open(name, _FILE_FLAGS, dir_fd=dir_fd)
|
|
103
|
+
except OSError as error:
|
|
104
|
+
if error.errno == errno.ELOOP:
|
|
105
|
+
raise Refused(f'{name} is a symlink') from None
|
|
106
|
+
raise
|
|
107
|
+
return _read_fd(fd, name, owners)
|
|
18
108
|
|
|
19
|
-
|
|
109
|
+
|
|
110
|
+
def _read_fd(fd, name, owners):
|
|
111
|
+
"""The bytes of the open fd `fd` (closed here): a regular file by fstat, at most MAX_BYTES, and, unless `owners` is
|
|
112
|
+
None, owned by one of `owners` and not writable by group or others."""
|
|
113
|
+
try:
|
|
114
|
+
st = os.fstat(fd)
|
|
115
|
+
if not stat.S_ISREG(st.st_mode):
|
|
116
|
+
raise Refused(f'{name} is not a regular file')
|
|
117
|
+
if owners is not None:
|
|
118
|
+
_check(st, name, owners)
|
|
119
|
+
if st.st_size > MAX_BYTES:
|
|
120
|
+
raise Refused(f'{name} is larger than {MAX_BYTES} bytes')
|
|
121
|
+
chunks, total = [], 0
|
|
122
|
+
while True:
|
|
123
|
+
chunk = os.read(fd, 65536)
|
|
124
|
+
if not chunk:
|
|
125
|
+
break
|
|
126
|
+
total += len(chunk)
|
|
127
|
+
if total > MAX_BYTES:
|
|
128
|
+
raise Refused(f'{name} is larger than {MAX_BYTES} bytes')
|
|
129
|
+
chunks.append(chunk)
|
|
130
|
+
return b''.join(chunks)
|
|
131
|
+
finally:
|
|
132
|
+
os.close(fd)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _declared(data):
|
|
136
|
+
val = None
|
|
137
|
+
for line in data.decode('utf-8', 'replace').splitlines():
|
|
138
|
+
s = line.strip()
|
|
139
|
+
if s.startswith('LANES_SITE_HOOK='):
|
|
140
|
+
val = s.split('=', 1)[1].strip()
|
|
141
|
+
return val
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _hook_dir(owners):
|
|
145
|
+
"""The declared hook directory (an absolute path), or None when none is declared. Refused raises.
|
|
146
|
+
|
|
147
|
+
site.conf is read once only to learn whether it declares a hook: opened O_NOFOLLOW | O_NONBLOCK, a regular file of
|
|
148
|
+
at most MAX_BYTES (a value there is never executed). Only a declaration loads code, so only then must site.conf and
|
|
149
|
+
its directories be the host account's: it is read again through `_open_dir` and `_read`, and the checked bytes
|
|
150
|
+
decide. A site.conf that declares no hook is never judged by its owner."""
|
|
20
151
|
val = os.environ.get('LANES_SITE_HOOK')
|
|
21
152
|
if val is None:
|
|
22
|
-
|
|
153
|
+
home = os.environ.get('HOME', '')
|
|
154
|
+
if not home.startswith('/'):
|
|
155
|
+
return None # no HOME: never a site.conf relative to the working directory
|
|
156
|
+
directory = os.path.join(home, '.config', 'lanes')
|
|
23
157
|
try:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
158
|
+
os.lstat(os.path.join(directory, 'site.conf'))
|
|
159
|
+
except (FileNotFoundError, NotADirectoryError):
|
|
160
|
+
return None # none declared: nothing is opened (a host without hooks reads nothing more)
|
|
161
|
+
try:
|
|
162
|
+
fd = os.open(os.path.join(directory, 'site.conf'), _FILE_FLAGS)
|
|
163
|
+
except OSError as error:
|
|
164
|
+
if error.errno == errno.ELOOP:
|
|
165
|
+
raise Refused('site.conf is a symlink') from None
|
|
29
166
|
return None
|
|
167
|
+
try:
|
|
168
|
+
val = _declared(_read_fd(fd, 'site.conf', None))
|
|
169
|
+
except Refused as refused:
|
|
170
|
+
raise Refused(f'site.conf: {refused}') from None
|
|
171
|
+
if not val or val == 'refuse':
|
|
172
|
+
return None
|
|
173
|
+
try:
|
|
174
|
+
fd = _open_dir(directory, owners)
|
|
175
|
+
try:
|
|
176
|
+
val = _declared(_read(fd, 'site.conf', owners))
|
|
177
|
+
finally:
|
|
178
|
+
os.close(fd)
|
|
179
|
+
except Refused as refused:
|
|
180
|
+
raise Refused(f'site.conf declares a hook directory, but {refused}') from None
|
|
30
181
|
if not val or val == 'refuse':
|
|
31
182
|
return None
|
|
32
|
-
|
|
33
|
-
|
|
183
|
+
if not val.startswith('/'):
|
|
184
|
+
raise Refused('LANES_SITE_HOOK is not an absolute path')
|
|
185
|
+
return val
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def _reserved():
|
|
189
|
+
"""Stems a hook may not take: every module of this package's libexec, and the loader's own name."""
|
|
190
|
+
here = Path(__file__).resolve().parent
|
|
191
|
+
return {p.stem for p in here.glob('*.py')} | {'lanes', 'site_hooks'}
|
|
34
192
|
|
|
35
193
|
|
|
36
194
|
def _load():
|
|
37
|
-
global _modules
|
|
195
|
+
global _modules, _report
|
|
38
196
|
if _modules is not None:
|
|
39
197
|
return _modules
|
|
40
198
|
_modules = []
|
|
41
|
-
|
|
42
|
-
|
|
199
|
+
_report = {'dir': None, 'loaded': [], 'refused': [], 'error': None}
|
|
200
|
+
owners = _owners()
|
|
201
|
+
try:
|
|
202
|
+
path = _hook_dir(owners)
|
|
203
|
+
if path is None:
|
|
204
|
+
return _modules
|
|
205
|
+
_report['dir'] = path
|
|
206
|
+
dir_fd = _open_dir(path, owners)
|
|
207
|
+
except Refused as refused:
|
|
208
|
+
_report['error'] = str(refused)
|
|
43
209
|
return _modules
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
210
|
+
except OSError as error:
|
|
211
|
+
_report['error'] = f'the hook directory cannot be opened ({error.strerror})'
|
|
212
|
+
return _modules
|
|
213
|
+
try:
|
|
214
|
+
reserved = _reserved()
|
|
215
|
+
for name in sorted(os.listdir(dir_fd)):
|
|
216
|
+
if not name.endswith('.py') or name.startswith('_'):
|
|
217
|
+
continue
|
|
218
|
+
stem = name[:-3]
|
|
219
|
+
try:
|
|
220
|
+
if name.startswith('.'):
|
|
221
|
+
raise Refused('a hidden file')
|
|
222
|
+
if not stem.isidentifier():
|
|
223
|
+
raise Refused('not a module name')
|
|
224
|
+
if stem in reserved:
|
|
225
|
+
raise Refused('it names a Lanes module')
|
|
226
|
+
source = _read(dir_fd, name, owners)
|
|
227
|
+
except Refused as refused:
|
|
228
|
+
_report['refused'].append((name, str(refused)))
|
|
229
|
+
continue
|
|
230
|
+
except OSError as error:
|
|
231
|
+
_report['refused'].append((name, error.strerror))
|
|
232
|
+
continue
|
|
233
|
+
module_name = MODULE_PREFIX + stem
|
|
234
|
+
module = types.ModuleType(module_name)
|
|
235
|
+
module.__file__ = os.path.join(path, name)
|
|
236
|
+
code = compile(source, module.__file__, 'exec')
|
|
237
|
+
sys.modules[module_name] = module
|
|
238
|
+
try:
|
|
239
|
+
exec(code, module.__dict__)
|
|
240
|
+
except BaseException:
|
|
241
|
+
sys.modules.pop(module_name, None)
|
|
242
|
+
raise
|
|
243
|
+
_modules.append(module)
|
|
244
|
+
_report['loaded'].append(stem)
|
|
245
|
+
finally:
|
|
246
|
+
os.close(dir_fd)
|
|
54
247
|
return _modules
|
|
55
248
|
|
|
56
249
|
|
|
250
|
+
def doctor_lines():
|
|
251
|
+
"""(mark, text) lines for `lanes doctor`: the loaded hooks (✓) and each refusal (✗). None declared -> []."""
|
|
252
|
+
_load()
|
|
253
|
+
report = _report or {}
|
|
254
|
+
lines = []
|
|
255
|
+
if report.get('error'):
|
|
256
|
+
lines.append(('✗', f'site hooks: refused, so none is loaded: {report["error"]}'))
|
|
257
|
+
elif report.get('dir'):
|
|
258
|
+
names = ', '.join(report['loaded']) or 'none'
|
|
259
|
+
lines.append(('✓', f'site hooks loaded from {report["dir"]}: {names}'))
|
|
260
|
+
for name, why in report.get('refused', []):
|
|
261
|
+
lines.append(('✗', f'site hook {name} refused: {why}'))
|
|
262
|
+
return lines
|
|
263
|
+
|
|
264
|
+
|
|
57
265
|
def apply(stage, *args):
|
|
58
266
|
"""Call install_<stage>(*args) on every declared site-hook module that defines it."""
|
|
59
267
|
if stage not in _STAGES:
|
|
@@ -345,13 +345,33 @@ def lane_entry(pane, now, activity=None, viewing=(), agent=None):
|
|
|
345
345
|
return entry
|
|
346
346
|
|
|
347
347
|
|
|
348
|
-
|
|
348
|
+
# BEY-8970: the unknown class (`agent_state.merge_classed`'s kind UNKNOWN; never the row's text) is published only
|
|
349
|
+
# when the lane was in the class in one of the TWO cycles before. MEASURED 26 Nov 2026: a starting Claude Code 2.1.332
|
|
350
|
+
# has no usable session file for about 0.9 s (three starts), and a starting Codex 0.169.1 sits under the title nobody
|
|
351
|
+
# set until it writes its first; one cycle of the class is a starting or redrawing harness, and each entry into the
|
|
352
|
+
# approval word raises a notice. Two cycles, not one: a form that alternates with another word (or with no agent)
|
|
353
|
+
# cycle by cycle is then published at its second sighting, and not never. `this`: the lane ids whose verdict was the
|
|
354
|
+
# class in the cycle being observed; `last` and `before`: those of the two cycles before. `observe` moves them on
|
|
355
|
+
# when it starts.
|
|
356
|
+
UNKNOWN_HOLD = {'before': frozenset(), 'last': frozenset(), 'this': set()}
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
def settled(previous, lane_id, now, raw, kind=None):
|
|
349
360
|
"""What a live lane publishes as its agent{} this cycle: `merge`'s verdict `raw` debounced against the agent{} the
|
|
350
361
|
PREVIOUS payload published for the same lane id (`agent_state.settle`, cockpit v3 S1). `previous` is the last
|
|
351
362
|
published payload — `new_context()` seeds it from status.json, so a restarted daemon keeps every lane's
|
|
352
|
-
`stable_since`. Called at both merge sites in `observe`: declared lanes and undeclared sessions alike.
|
|
363
|
+
`stable_since`. Called at both merge sites in `observe`: declared lanes and undeclared sessions alike.
|
|
364
|
+
|
|
365
|
+
`kind` is the verdict's kind (`agent_state.merge_classed`). The unknown class in a cycle neither of whose two
|
|
366
|
+
predecessors saw it (UNKNOWN_HOLD) publishes what the lane published before, unchanged, whatever word that is, or
|
|
367
|
+
no agent for a lane that had none: the row keeps its last word for that one cycle."""
|
|
353
368
|
old = ((previous.get('lanes') or {}).get(lane_id) or {}) if isinstance(previous, dict) else {}
|
|
354
|
-
|
|
369
|
+
before = old.get('agent') if isinstance(old, dict) else None
|
|
370
|
+
if kind == AS.UNKNOWN:
|
|
371
|
+
UNKNOWN_HOLD['this'].add(lane_id)
|
|
372
|
+
if lane_id not in UNKNOWN_HOLD['last'] and lane_id not in UNKNOWN_HOLD['before']:
|
|
373
|
+
return before if isinstance(before, dict) and before.get('status') in AS.STATUSES else None
|
|
374
|
+
return AS.settle(before, raw, now)
|
|
355
375
|
|
|
356
376
|
|
|
357
377
|
# W12 (spec §2): the harness each pane runs, read from the container's /proc and kept per pane pid between cycles —
|
|
@@ -501,8 +521,11 @@ def agent_signals(containers, sessions_by_server, now=None):
|
|
|
501
521
|
panes = [(socket, pane) for (owner, socket), sessions in sessions_by_server.items() if owner == container
|
|
502
522
|
for pane in sessions.values() if str(pane.get('pane_pid') or '').isdigit()]
|
|
503
523
|
index = {}
|
|
524
|
+
host = AS.container_host(root) # BEY-8970: the title tmux gives a pane nobody titled in this container
|
|
504
525
|
for socket, pane in panes:
|
|
505
526
|
index.setdefault(socket, {})[AS.pane_key(pane)] = int(pane['pane_pid'])
|
|
527
|
+
if host:
|
|
528
|
+
pane['host'] = host
|
|
506
529
|
work = {}
|
|
507
530
|
try:
|
|
508
531
|
claude = AS.claude_sessions(root / L.CONTAINER_HOME.lstrip('/') / '.claude' / 'sessions', root / 'proc',
|
|
@@ -526,6 +549,15 @@ def agent_signals(containers, sessions_by_server, now=None):
|
|
|
526
549
|
pane['harness'] = harness
|
|
527
550
|
if harness_pid:
|
|
528
551
|
pane['harness_pid'] = harness_pid
|
|
552
|
+
if harness == 'codex' and harness_pid:
|
|
553
|
+
# BEY-8970: the directory Codex runs in; its title's last item is that path's project name.
|
|
554
|
+
try:
|
|
555
|
+
pane['harness_cwd'] = os.readlink(root / 'proc' / str(harness_pid) / 'cwd')
|
|
556
|
+
except OSError:
|
|
557
|
+
pass
|
|
558
|
+
# BEY-8970: a batch run (`codex exec`) is known by the process's own arguments; it writes no title.
|
|
559
|
+
if AS.codex_batch(AS.process_argv(root / 'proc', harness_pid)):
|
|
560
|
+
pane['harness_batch'] = True
|
|
529
561
|
key = AS.bound_key(socket, AS.pane_key(pane))
|
|
530
562
|
if harness == 'kimi' and harness_pid:
|
|
531
563
|
observers['kimi'][key] = harness_pid
|
|
@@ -588,12 +620,19 @@ def delegating_check(container, root, claude, work, now):
|
|
|
588
620
|
return guarded
|
|
589
621
|
|
|
590
622
|
|
|
623
|
+
def merged_classed(pane, signals, sidecar, socket):
|
|
624
|
+
"""`agent_state.merge_classed` of one pane of tmux server `socket` over its container's `agent_signals` and its
|
|
625
|
+
lane's hook sidecar, looked up by `agent_state.bound_key(socket, pane key)` (BEY-6838): (verdict, kind)."""
|
|
626
|
+
return AS.merge_classed(pane, signals.get('claude', {}), sidecar, signals.get('kimi', {}), signals.get('grok', {}),
|
|
627
|
+
signals.get('muse', {}), delegating=signals.get('delegating'),
|
|
628
|
+
key=AS.bound_key(socket, AS.pane_key(pane)))
|
|
629
|
+
|
|
630
|
+
|
|
591
631
|
def merged(pane, signals, sidecar, socket):
|
|
592
|
-
"""
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
key=AS.bound_key(socket, AS.pane_key(pane)))
|
|
632
|
+
"""The verdict of `merged_classed`, without its kind. statusd itself no longer calls it (`observe` needs the kind
|
|
633
|
+
for the hold); it stays as the seam the harness tests read one pane's verdict through (test_agent_state_harness,
|
|
634
|
+
test_harness_muse)."""
|
|
635
|
+
return merged_classed(pane, signals, sidecar, socket)[0]
|
|
597
636
|
|
|
598
637
|
|
|
599
638
|
SIDECAR_MAX_AGE = 3600 # a hook sidecar whose last event is older than this loses to the live signals
|
|
@@ -757,6 +796,7 @@ def observe(registry, containers, live, previous=None, report=None):
|
|
|
757
796
|
previous = previous or {}
|
|
758
797
|
messaging = report.get('messaging') if isinstance(report, dict) else None
|
|
759
798
|
now = time.time()
|
|
799
|
+
UNKNOWN_HOLD.update(before=UNKNOWN_HOLD['last'], last=frozenset(UNKNOWN_HOLD['this']), this=set())
|
|
760
800
|
lanes, servers, unregistered = {}, {}, {}
|
|
761
801
|
wanted, owners, counts = {}, {}, {}
|
|
762
802
|
for workspace in registry['workspaces']:
|
|
@@ -886,8 +926,9 @@ def observe(registry, containers, live, previous=None, report=None):
|
|
|
886
926
|
entry['note'] = 'session name outside the lane declaration grammar'
|
|
887
927
|
found = lane_entry(pane, now, activities.get(name), viewers.get(name, []),
|
|
888
928
|
settled(previous, entry['id'], now,
|
|
889
|
-
|
|
890
|
-
|
|
929
|
+
*merged_classed(pane, signals.get(container, {}),
|
|
930
|
+
sidecars.get(container, {}).get(entry['id']),
|
|
931
|
+
socket)))
|
|
891
932
|
if messaging is not None:
|
|
892
933
|
messaging[entry['id']] = messaging_of(signals, container, socket, pane)
|
|
893
934
|
except Exception as error:
|
|
@@ -909,9 +950,9 @@ def observe(registry, containers, live, previous=None, report=None):
|
|
|
909
950
|
try:
|
|
910
951
|
lanes[lane['id']] = lane_entry(pane, now, activities.get(session), viewers.get(session, []),
|
|
911
952
|
settled(previous, lane['id'], now,
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
953
|
+
*merged_classed(pane, signals.get(container, {}),
|
|
954
|
+
sidecars.get(container, {}).get(lane['id']),
|
|
955
|
+
socket)))
|
|
915
956
|
if messaging is not None:
|
|
916
957
|
messaging[lane['id']] = messaging_of(signals, container, socket, pane)
|
|
917
958
|
except Exception as error: # a torn row: the session is there, its details are not readable
|
package/payload/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibelord/lanes",
|
|
3
|
-
"version": "1.9.
|
|
4
|
-
"commit": "
|
|
5
|
-
"digest": "sha256:
|
|
3
|
+
"version": "1.9.7",
|
|
4
|
+
"commit": "d35621513d447b393f04013c74735b2a2c010b8e",
|
|
5
|
+
"digest": "sha256:e026906f4c0e60c1acbdd1c3f34f70c5c7f208b7373d272f93086c43c2877f8d",
|
|
6
6
|
"executables": [
|
|
7
7
|
"bin/lanes",
|
|
8
8
|
"bin/lanes-site-serve",
|