@vibelord/lanes 1.7.2 → 1.7.4

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.
Files changed (50) hide show
  1. package/README.md +9 -0
  2. package/package.json +1 -1
  3. package/payload/lanes/VERSION +1 -1
  4. package/payload/lanes/bin/lanes +97 -17
  5. package/payload/lanes/bin/lanes-site-serve +15 -0
  6. package/payload/lanes/bin-rs/BINARIES.json +5 -0
  7. package/payload/lanes/container/lane-mcp +105 -5
  8. package/payload/lanes/container/lane_core.py +110 -0
  9. package/payload/lanes/container/throttle-pulse +159 -14
  10. package/payload/lanes/docs/ARCHITECTURE.md +108 -11
  11. package/payload/lanes/docs/DESIGN.md +10 -8
  12. package/payload/lanes/docs/INSTALL.md +1 -1
  13. package/payload/lanes/docs/RUNBOOK.md +297 -5
  14. package/payload/lanes/docs/USERGUIDE.md +11 -6
  15. package/payload/lanes/install/host-install.sh +14 -3
  16. package/payload/lanes/libexec/adopt.py +325 -0
  17. package/payload/lanes/libexec/cutover.py +656 -0
  18. package/payload/lanes/libexec/docsd.py +12 -8
  19. package/payload/lanes/libexec/doctor_lanes2.py +213 -0
  20. package/payload/lanes/libexec/economy_poll.py +87 -2
  21. package/payload/lanes/libexec/lanes_lib.py +465 -2
  22. package/payload/lanes/libexec/native.sh +38 -0
  23. package/payload/lanes/libexec/native_bin.py +668 -0
  24. package/payload/lanes/libexec/shadow.py +1311 -0
  25. package/payload/lanes/libexec/sidebar.py +269 -28
  26. package/payload/lanes/libexec/sidebar_status.py +373 -25
  27. package/payload/lanes/libexec/statusd.py +67 -3
  28. package/payload/lanes/libexec/tokens.py +99 -131
  29. package/payload/lanes/libexec/tokens.sh +1 -1
  30. package/payload/lanes/libexec/update.py +48 -5
  31. package/payload/lanes/libexec/users.py +282 -0
  32. package/payload/lanes/site/README.md +9 -0
  33. package/payload/lanes/site/conformance.py +280 -0
  34. package/payload/lanes/site/protocol.py +368 -0
  35. package/payload/lanes/site/server.py +314 -0
  36. package/payload/lanes/tokens/README.md +156 -0
  37. package/payload/lanes/tokens/generate.py +930 -0
  38. package/payload/lanes/tokens/generated/parity.v1.tsv +489 -0
  39. package/payload/lanes/tokens/generated/tokens.resolved.json +835 -0
  40. package/payload/lanes/tokens/tokens.v1.json +763 -0
  41. package/payload/lanes/tokens/tokens.v1.schema.json +143 -0
  42. package/payload/lanes/web/README.md +132 -4
  43. package/payload/lanes/web/directory.css +95 -0
  44. package/payload/lanes/web/directory.js +951 -0
  45. package/payload/lanes/web/generated/README.md +107 -0
  46. package/payload/lanes/web/generated/lanes2_protocol.d.mts +1162 -0
  47. package/payload/lanes/web/generated/lanes2_protocol.mjs +2333 -0
  48. package/payload/lanes/web/mobile.js +17 -21
  49. package/payload/lanes/web/tokens.css +137 -0
  50. package/payload/manifest.json +7 -4
package/README.md CHANGED
@@ -125,6 +125,15 @@ options of the last install (remembered in `~/.config/lanes/install-options`; a
125
125
  The package version equals `lanes/VERSION`; bump both together. `prepack` builds `payload/` from `git ls-files lanes`
126
126
  (tests excluded) and refuses uncommitted `lanes/` changes.
127
127
 
128
+ Lanes 2.0 native binaries (none yet): with `LANES_RS_ARTIFACTS=<dir>` — the fetched result of one buildctl job built
129
+ from the same commit, `<dir>/x86_64-unknown-linux-musl/lanes-<name>` plus `<dir>/THIRD-PARTY-NOTICES` — the build ships
130
+ each binary under `payload/lanes/bin-rs/` and lists `{name, target, sha256, size, commit}` in the staged
131
+ `bin-rs/BINARIES.json` and in `manifest.binaries`, all inside the payload digest. Each binary's `--version` must print
132
+ exactly one line `<name> <version> (commit <40-hex>)` naming itself and `HEAD`, with nothing after the hash; a dirty or
133
+ local build (`<HEAD>-dirty`, `<HEAD>+local`), a second commit, another commit or none is refused before anything is
134
+ written. Without the variable the list is empty and the build is today's. `--out DIR` (tests only; refused under
135
+ npm's pack and publish lifecycles) builds somewhere other than `payload/`.
136
+
128
137
  ```sh
129
138
  cd npm/lanes && npm test
130
139
  scripts/publish.sh --dry-run # then without --dry-run
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibelord/lanes",
3
- "version": "1.7.2",
3
+ "version": "1.7.4",
4
4
  "description": "Installer for Lanes: shared agent terminals over SSH with Zellij views, registry sync, uploads and a phone interface.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1 +1 @@
1
- 1.7.2
1
+ 1.7.4
@@ -338,6 +338,10 @@
338
338
  lanes studio-host re-key [--yes] [--dry-run]
339
339
  after the owner revoked this machine: stop the Host, remove the machine key and its
340
340
  dead enrolment, publish a NEW public key for the next deploy. Nothing without --yes
341
+ lanes rs install --from PATH --sha256 HEX | uninstall NAME | verify [--tree] | status | apply
342
+ Lanes 2.0 native binaries and site.conf's LANES_RS_<COMPONENT> flags
343
+ (libexec/native_bin.py; every flag off): place or remove a locally built binary
344
+ (sha256-verified), check binaries against their digests, show or apply the flags
341
345
  lanes doctor full health check (every external call is bounded; includes the pressure summary), with
342
346
  the lanes per create-recipe class (idempotent / attach-only / null / external /
343
347
  retired-path), lane identity, numeric session names, crowded `default` sockets and
@@ -2665,17 +2669,23 @@ def active_workspace(registry, device):
2665
2669
  raise L.LanesError(f"the active tab '{title}' is not a board; name one: lanes upload <workspace>")
2666
2670
 
2667
2671
 
2668
- def type_into_lane(registry, device, workspace, text):
2669
- """Type text into the lane shown in the device's first viewport (user-initiated input, like typing)."""
2672
+ def paste_into_lane(registry, device, workspace, text):
2673
+ """Type text into the lane shown in the device's first viewport (user-initiated input, like typing) through its
2674
+ container's transport (lanes_lib.lane_write, H1) -> (lane name, None, None) when typed, else (None, outcome, why):
2675
+ why starts `not typed:` (or says it is not known), outcome `no_transport` when the container has no write
2676
+ transport."""
2670
2677
  target = L.STATE / 'views' / device / f"{workspace['id']}.main.target"
2671
2678
  lane_id = (target.read_text().split('\n')[0] if target.exists() else '') or \
2672
2679
  (L.STATE / 'defaults' / workspace['id']).read_text().split('\n')[0]
2673
2680
  _ws, lane = L.find_lane(registry, lane_id)
2674
- info = (L.read_json(L.STATE / 'containers.json') or {}).get(lane['container'], {})
2675
- if lane['holder'] == 'tmux':
2676
- ok = L.tmux_query(info, lane['tmux']['socket'], ['send-keys', '-t', f"={lane['tmux']['session']}:", '-l', '--', text])
2677
- return lane['name'] if ok is not None else None
2678
- return None
2681
+ info = (L.read_json(L.STATE / 'containers.json') or {}).get(lane.get('container') or '', {})
2682
+ outcome, why = L.lane_write(lane, info, text)
2683
+ return (lane['name'], None, None) if outcome == 'typed' else (None, outcome, why)
2684
+
2685
+
2686
+ def type_into_lane(registry, device, workspace, text):
2687
+ """paste_into_lane's lane name, or None when nothing was typed."""
2688
+ return paste_into_lane(registry, device, workspace, text)[0]
2679
2689
 
2680
2690
 
2681
2691
  def paste_target(spool, request, fallback):
@@ -2751,13 +2761,16 @@ def cmd_upload(args):
2751
2761
  raise L.LanesError('nothing was uploaded (empty archive)')
2752
2762
  for path in landed:
2753
2763
  print(path)
2764
+ typed = True
2754
2765
  if '--paste' in args and paste_device:
2755
2766
  # The result files (.done / .err) stay in the base spool, where the asking sidebar looks for them.
2756
- shown = type_into_lane(registry, device_name(view_device), workspace, ' '.join(shlex.quote(p) for p in landed) + ' ')
2757
- print(f'# typed into lane: {shown}' if shown else '# could not type into the lane (not a tmux lane?)', file=sys.stderr)
2767
+ shown, outcome, why = paste_into_lane(registry, device_name(view_device), workspace,
2768
+ ' '.join(shlex.quote(p) for p in landed) + ' ')
2769
+ typed = outcome is None # paste_into_lane: (name, None, None) once typed
2770
+ print(f'# typed into lane: {shown}' if typed else f'# {why}', file=sys.stderr)
2758
2771
  if spool:
2759
2772
  L.atomic_write(spool / f'{request}.done', '\n'.join(landed) + '\n')
2760
- return 0
2773
+ return 0 if typed else 1 # the files landed either way; a paste that typed nothing is never an exit 0 (BEY-6899)
2761
2774
 
2762
2775
 
2763
2776
  DOCS_USAGE = 'usage: lanes docs push <id>'
@@ -3955,6 +3968,10 @@ def cmd_studio_host(args):
3955
3968
  return libexec_module('studio_host').main(args) # verbs, refusals and exit codes are studio_host's
3956
3969
 
3957
3970
 
3971
+ def cmd_rs(args):
3972
+ return libexec_module('native_bin').main(args) # verbs, refusals and exit codes are native_bin's
3973
+
3974
+
3958
3975
  def cmd_keys(args):
3959
3976
  # verbs, refusals and exit codes are keys.py's; a verb that names an owner (adopt --login, owner) ends by folding
3960
3977
  # the views of the devices it named into that person's profile (cockpit v3 R2), and a dropped fold is its exit 1
@@ -5128,6 +5145,40 @@ def fleet_doctor(status, registry, home=None, now=None):
5128
5145
  dashboard_line(home)]
5129
5146
 
5130
5147
 
5148
+ def projection_doctor(status, state=None, now=None):
5149
+ """`lanes doctor`'s 1.7.4 line about the sidebar projections -> [(mark, text)] or []: the files under
5150
+ `sidebar-status/` (the 1.7.2 board files, the C7 directory) that carry no `throttle`/`fleet` or an older sample
5151
+ than status.json — the shape that hid the operator's mini dashboard on 1.7.3 (a site hook adopts a guest's pulse
5152
+ into status.json after the projection was written). Sidebars since 1.7.4 refresh the block from status.json
5153
+ themselves (sidebar.CANON_REFRESH_S), so the line is information, never a ✗. Read-only."""
5154
+ state = L.STATE if state is None else Path(state)
5155
+ status = status if isinstance(status, dict) else {}
5156
+ folder = state / 'sidebar-status'
5157
+ try:
5158
+ names = sorted(entry.name for entry in folder.iterdir() if entry.name.endswith('.json'))
5159
+ except OSError:
5160
+ return []
5161
+ behind = []
5162
+ for name in names:
5163
+ doc = L.read_json(folder / name)
5164
+ if not isinstance(doc, dict):
5165
+ continue
5166
+ for key in ('throttle', 'fleet'):
5167
+ theirs, ours = status.get(key), doc.get(key)
5168
+ if not isinstance(theirs, dict):
5169
+ continue
5170
+ if not isinstance(ours, dict) or (number(theirs.get('at')) or 0) > (number(ours.get('at')) or 0):
5171
+ behind.append(f'{name} ({key})')
5172
+ break
5173
+ if not names:
5174
+ return []
5175
+ if not behind:
5176
+ return [('', f'sidebar projections: {len(names)} carry the fleet block facts status.json has')]
5177
+ shown = ', '.join(behind[:3]) + (f' and {len(behind) - 3} more' if len(behind) > 3 else '')
5178
+ return [('⚠', f'sidebar projections behind status.json: {shown} — a site hook adopts the pulse after the '
5179
+ 'projection; sidebars read the block from status.json every ≤15 s since 1.7.4')]
5180
+
5181
+
5131
5182
  # ------------------------------------------------------------------ doctor: the harness mix (W12)
5132
5183
  # `agent.harness` is an observed fact since W12 (spec
5133
5184
  # docs/superpowers/specs/2026-10-15-lanes-harness-observers-design.md §2): statusd reads it from the pane's process
@@ -5411,13 +5462,16 @@ def release_doctor(table, home=None):
5411
5462
  """`lanes doctor`'s release lines -> [(mark, text)], mark ✓ | ✗ | ⚠ | '' (information) (W9 V3, LNS-85): `current`
5412
5463
  and its VERSION, the run records against the processes in `table` (`ps -eo pid=,comm=,args=`; None when ps did
5413
5464
  not answer), the device layouts, the units, then the updates (W9 U3: libexec/update.py doctor_line, with the unit
5414
- folders it looks for lanes-update.timer's enable link in; no line without an installed release). Read-only: files
5415
- and the one process table doctor already swept."""
5465
+ folders it looks for lanes-update.timer's enable link in; no line without an installed release), then the Lanes 2.0
5466
+ adoption (libexec/adopt.py doctor_lines: nothing before the first adoption, then one line per state domain).
5467
+ Read-only: files and the one process table doctor already swept."""
5416
5468
  report = version_report(home=home)
5417
5469
  reference = report['current'] or os.path.realpath(report['tree'])
5418
5470
  updates = libexec_module('update').doctor_line(L.STATE, home, units=unit_dirs(home))
5471
+ adopted = libexec_module('adopt').doctor_lines(L.STATE) # Lanes 2.0 adoption, one line per domain (lanes2 S12)
5419
5472
  return [current_doctor(report, home), *records_doctor(report, table, reference, home),
5420
- layouts_doctor(reference, home), units_doctor(reference, home), *([updates] if updates else [])]
5473
+ layouts_doctor(reference, home), units_doctor(reference, home), *([updates] if updates else []),
5474
+ *adopted]
5421
5475
 
5422
5476
 
5423
5477
  def cmd_doctor(_args):
@@ -5435,8 +5489,14 @@ def cmd_doctor(_args):
5435
5489
  errors = [(w['id'], e) for w in registry['workspaces'] for e in w['errors']]
5436
5490
  check(not errors, 'registry clean', '; '.join(f'{w}: {e}' for w, e in errors))
5437
5491
  hook = site_hook_old()
5438
- if hook:
5439
- print(f'⚠ {hook} (Linear BEY-6912)')
5492
+ if hook: # H1: a warning until the O-3 installed witness (W20), never by release count (RUNBOOK "Federation")
5493
+ if L.site_conf().get('LANES_SITE_HOOK') == 'refuse':
5494
+ check(False, f'{hook} (Linear BEY-6912)', 'refused: site.conf LANES_SITE_HOOK=refuse')
5495
+ else:
5496
+ print(f'⚠ {hook} (Linear BEY-6912) — becomes a refusal after the O-3 installed witness (W20); '
5497
+ 'site.conf LANES_SITE_HOOK=refuse refuses it now')
5498
+ for ok, label, detail in L.transport_report(registry, L.read_json(L.STATE / 'containers.json') or {}):
5499
+ check(ok, label, detail) # H1: no write transport, tmux_probe-only containers, the guests a board names
5440
5500
  # Stale registry check: any terminals.json newer than the last sync? A lane's `source` is the container's
5441
5501
  # spelling; doctor runs on the host, so it stats the file under the container's home volume.
5442
5502
  sys.path.insert(0, str(L.REPO / 'libexec'))
@@ -5561,6 +5621,8 @@ def cmd_doctor(_args):
5561
5621
  print(f'{mark or " "} {text}')
5562
5622
  else:
5563
5623
  check(mark == '✓', text)
5624
+ for mark, text in projection_doctor(status): # 1.7.4: the projections the sidebars read
5625
+ print(f'{mark or " "} {text}')
5564
5626
  # The release that runs (W9 V3): `current`, the run records against the one process-table sweep above, the
5565
5627
  # device layouts, the units.
5566
5628
  for mark, text in release_doctor(table if rc == 0 else None):
@@ -5568,6 +5630,13 @@ def cmd_doctor(_args):
5568
5630
  print(f'{mark or " "} {text}')
5569
5631
  else:
5570
5632
  check(mark == '✓', text)
5633
+ # Lanes 2.0 runtime signals (RT 16.3, lanes2 R2-DOCTOR): the snapshot a Lanes 2.0 host exports; nothing until one does.
5634
+ import doctor_lanes2
5635
+ for mark, text in doctor_lanes2.doctor_lines(L.STATE):
5636
+ if mark in ('⚠', ''):
5637
+ print(f'{mark or " "} {text}')
5638
+ else:
5639
+ check(mark == '✓', text)
5571
5640
  print('PRESSURE')
5572
5641
  health = L.compute_health()
5573
5642
  print('\n'.join(pressure_lines(health, L.read_json(L.STATE / 'containers.json') or {})))
@@ -5887,6 +5956,11 @@ def cmd_names(args):
5887
5956
  for _board, lane, row in todo:
5888
5957
  address = row.get('address') or lane.get('address') or L.address_of(lane['id'])
5889
5958
  current = (((row.get('agent') or {}).get('messaging')) or {}).get('name')
5959
+ refusal = None if write else L.names_refusal(lane, containers.get(lane['container']) or {})
5960
+ if refusal: # H1, BEY-6899: what --write could never type from here is said, and exit 1
5961
+ print(f"{'failed':<12} {lane['id']}: {refusal}")
5962
+ counts['failed'] = counts.get('failed', 0) + 1
5963
+ continue
5890
5964
  if not write:
5891
5965
  print(f"would rename {lane['id']} {current!r} -> {address}")
5892
5966
  counts['to rename'] = counts.get('to rename', 0) + 1
@@ -5894,9 +5968,15 @@ def cmd_names(args):
5894
5968
  outcome, detail = L.rename_claude(lane, address, containers.get(lane['container']) or {})
5895
5969
  print(f"{outcome:<12} {lane['id']}: {detail}")
5896
5970
  counts[outcome] = counts.get(outcome, 0) + 1
5971
+ counts['deferred'] = counts.get('deferred', 0) # always counted, as before (0 deferred is said)
5897
5972
  for _board, lane, why in deferred:
5973
+ refusal = L.names_refusal(lane, containers.get(lane.get('container')) or {})
5974
+ if refusal: # H1, BEY-6899: said, and exit 1
5975
+ print(f"{'failed':<12} {lane['id']}: {refusal}")
5976
+ counts['failed'] = counts.get('failed', 0) + 1
5977
+ continue
5898
5978
  print(f"deferred {lane['id']}: {why}")
5899
- counts['deferred'] = counts.get('deferred', 0) + len(deferred)
5979
+ counts['deferred'] = counts.get('deferred', 0) + 1
5900
5980
  print(', '.join(f'{n} {what}' for what, n in counts.items()) + f', {matched} already match'
5901
5981
  + ('' if write else ' — dry run: --write types /rename <address> + Enter into each lane to rename'))
5902
5982
  return 1 if counts.get('failed') else 0
@@ -6748,7 +6828,7 @@ COMMANDS = {'rebuilt': cmd_rebuilt, 'hello': cmd_hello, 'client-config': cmd_cli
6748
6828
  'guard': cmd_guard, 'rename': cmd_rename, 'register': cmd_register, 'unregister': cmd_unregister,
6749
6829
  'hooks': cmd_hooks, 'economy': cmd_economy, 'throttle': cmd_throttle,
6750
6830
  'preview': cmd_preview, 'edit': cmd_edit, 'device': cmd_device, 'next': cmd_next, 'prev': cmd_prev,
6751
- 'sidebar-key': cmd_sidebar_key, 'studio-host': cmd_studio_host,
6831
+ 'sidebar-key': cmd_sidebar_key, 'studio-host': cmd_studio_host, 'rs': cmd_rs,
6752
6832
  'keys': cmd_keys, 'invite': cmd_invite, 'enrol': cmd_enrol, 'offboard': cmd_offboard,
6753
6833
  'token': cmd_token, 'onboard': cmd_onboard, 'user': cmd_user, 'lane': cmd_lane, 'here': cmd_here,
6754
6834
  'version': cmd_version, 'update': cmd_update, 'docs': cmd_docs,
@@ -0,0 +1,15 @@
1
+ #!/bin/sh
2
+ # lanes-site/1 on a guest: the forced command of the aggregator's site key (Lanes2 architecture §3.32, plan row H1,
3
+ # DM-LANES-SITE-ADAPTER). Its authorized_keys line:
4
+ # command="<home>/.local/share/lanes/current/bin/lanes-site-serve",restrict ssh-ed25519 AAAA... lanes-site@<aggregator>
5
+ # SSH_ORIGINAL_COMMAND is ignored: this key reaches the protocol and nothing else. stdin/stdout are the protocol.
6
+ # $LANES_STATE/flags/rs-site names the native adapter (`lanesd site-serve`, W20); no lanesd is installed before W20,
7
+ # so the flag refuses with one typed frame (adapter_unavailable) instead of serving something else. Otherwise the
8
+ # Python reference server, without site-packages or PYTHON* environment (-S -E), writing no bytecode (-B).
9
+ here=$(dirname -- "$0")
10
+ state=${LANES_STATE:-$HOME/.local/state/lanes}
11
+ if [ -e "$state/flags/rs-site" ]; then
12
+ printf '%s\n' '{"id":null,"err":{"code":"adapter_unavailable","human":"flags/rs-site names lanesd site-serve, which is not installed on this guest (W20): remove the flag to serve the Python adapter"}}'
13
+ exit 69
14
+ fi
15
+ exec python3 -S -E -B "$here/../site/server.py"
@@ -0,0 +1,5 @@
1
+ {
2
+ "schema": "lanes.bin-rs/1",
3
+ "commit": "780a5871e019c91660568ebe4a9e46eea763d31f",
4
+ "binaries": []
5
+ }
@@ -56,6 +56,11 @@ terminal); `lanes sync` publishes the change (lanes-statusd starts one within ~1
56
56
  (lane_core.dispatch_lock, W15 part 2); an adapter whose answer was lost is `unknown`:
57
57
  held, never sent again by Lanes (a person: `lane inbox retry <id> --duplicate-risk`)
58
58
  lanes_message_ack <id> this agent's own lane has a message: its text leaves the inbox, the receipt stays
59
+ Project tools (Lanes 2.0 Round 2, R2-S10; listed only while ~/.lz/flags/projects exists, the container's
60
+ LANES_PROJECTS=on, so the frozen listing above keeps its bytes): lanes_work_list, lanes_work_claim,
61
+ lanes_work_release and lanes_checkpoint build the request the host's project store takes (lane_core.project_request)
62
+ and, until a transport carries it there (integration gate I1), answer `projects_unavailable` with that request:
63
+ nothing is claimed, released or recorded.
59
64
  Human-only by omission (no tool exists): ending or closing a lane, interrupting it (C-c or any key that is not
60
65
  printable text), opening or attaching one, uploads (a person's file into a lane: the Docs page or the desktop drop;
61
66
  an agent's own file goes the other way, lanes_publish), the host's sync/gc/ensure, renaming a tmux session, and any
@@ -161,8 +166,11 @@ TARGET_ARG = {'type': 'string', 'pattern': TARGET_PATTERN, 'maxLength': 129,
161
166
  '"@bw-tools.lanes-zellij" (a lane), "@bw-tools" (that board\'s coordinator) or "@fleet" '
162
167
  '(the fleet admin).'}
163
168
  MESSAGE_ID_PATTERN = '^[a-z0-9]{10,20}$' # lane_core.PUBLISH_ID: a message id (W15 L4)
169
+ PROJECT_ID_PATTERN = '^[A-Za-z0-9_][A-Za-z0-9_.:-]*$' # lane_core.PROJECT_ID_RE: a project-domain id (R2-S10)
170
+ WORK_CURSOR_PATTERN = '^[0-9]{10}:[0-9]{20}:[A-Za-z0-9_][A-Za-z0-9_.:-]*$' # lane_core.WORK_CURSOR_RE
164
171
  PATTERNS = {ID_PATTERN: C.LANE_RE, TARGET_PATTERN: C.TARGET_RE,
165
- MESSAGE_ID_PATTERN: C.PUBLISH_ID} # what validate() holds each `pattern` to
172
+ MESSAGE_ID_PATTERN: C.PUBLISH_ID, PROJECT_ID_PATTERN: C.PROJECT_ID_RE,
173
+ WORK_CURSOR_PATTERN: C.WORK_CURSOR_RE} # what validate() holds each `pattern` to
166
174
  READ_ONLY = {'readOnlyHint': True, 'destructiveHint': False, 'idempotentHint': True, 'openWorldHint': False}
167
175
 
168
176
 
@@ -355,6 +363,65 @@ TOOLS = (
355
363
  TOOL_BY_NAME = {tool['name']: tool for tool in TOOLS}
356
364
  WRITE_TOOLS = frozenset(tool['name'] for tool in TOOLS if not tool['annotations']['readOnlyHint'])
357
365
 
366
+ # Lanes 2.0 Round 2, R2-S10 (W28-D): the project tools, appended after the thirteen only while the container holds
367
+ # the projects switch (lane_core.projects_enabled), so the frozen listing keeps its bytes until that flag flips
368
+ # (lanes2 architecture section 7.2). Each answers one JSON object, a refusal included.
369
+ PROJECT_ARG = {'type': 'string', 'pattern': PROJECT_ID_PATTERN, 'maxLength': 128,
370
+ 'description': 'The project id, as lanes_work_list answers it.'}
371
+ ITEM_ARG = {'type': 'string', 'pattern': PROJECT_ID_PATTERN, 'maxLength': 128,
372
+ 'description': 'The work item id, as lanes_work_list answers it.'}
373
+ COUNTER_ARG = {'type': 'integer', 'minimum': 1, 'maximum': C.PROJECT_COUNTER_MAX}
374
+ PROJECTS_NOTE = ('Until the host\'s project store is active this answers projects_unavailable with the request it '
375
+ 'would send: nothing is claimed, released or recorded.')
376
+ PROJECT_TOOLS = (
377
+ _tool('lanes_work_list', 'List ready project work',
378
+ 'The ready work of a project for the responsibility this agent\'s lane holds: every eligible item in '
379
+ 'ready order (priority, then age), one page at a time, each with its id, revision, work type, objective '
380
+ 'and how many items depend on it, and how many items are not ready, by reason. Readiness is not capacity. '
381
+ + PROJECTS_NOTE,
382
+ {'project': PROJECT_ARG,
383
+ 'after': {'type': 'string', 'pattern': WORK_CURSOR_PATTERN, 'maxLength': 160,
384
+ 'description': 'Where the next page starts: the `next` a previous answer gave.'},
385
+ 'limit': {'type': 'integer', 'minimum': 1, 'maximum': C.WORK_LIMIT_MAX,
386
+ 'default': C.WORK_LIMIT_DEFAULT,
387
+ 'description': f'Items per page, 1–{C.WORK_LIMIT_MAX} (default {C.WORK_LIMIT_DEFAULT}).'}},
388
+ required=('project',)),
389
+ _tool('lanes_work_claim', 'Claim project work',
390
+ 'Claim one ready work item for the responsibility this agent\'s lane holds, at the item revision '
391
+ 'lanes_work_list answered: one claimant wins and every other is refused; the answer is the claim\'s epoch, '
392
+ 'which every later change of the claim presents. ' + PROJECTS_NOTE,
393
+ {'project': PROJECT_ARG, 'item': ITEM_ARG,
394
+ 'revision': dict(COUNTER_ARG, description='The item revision you read (lanes_work_list `revision`).'),
395
+ 'lease_s': {'type': 'integer', 'minimum': C.LEASE_MIN_S, 'maximum': C.LEASE_MAX_S,
396
+ 'default': C.LEASE_DEFAULT_S,
397
+ 'description': f'The ownership lease in seconds, {C.LEASE_MIN_S}–{C.LEASE_MAX_S} '
398
+ f'(default {C.LEASE_DEFAULT_S}); renewing it is not progress.'}},
399
+ required=('project', 'item', 'revision'), hints=_writes(False, False)),
400
+ _tool('lanes_work_release', 'Release a claim',
401
+ 'Give up a claim this agent\'s responsibility holds, at its epoch and the item revision you read: the item '
402
+ 'reopens for others. A stale epoch releases nothing. ' + PROJECTS_NOTE,
403
+ {'project': PROJECT_ARG, 'item': ITEM_ARG,
404
+ 'epoch': dict(COUNTER_ARG, description='The claim epoch lanes_work_claim answered.'),
405
+ 'revision': dict(COUNTER_ARG, description='The item revision you read.')},
406
+ required=('project', 'item', 'epoch', 'revision'), hints=_writes(False, False)),
407
+ _tool('lanes_checkpoint', 'Record a checkpoint',
408
+ 'Record a checkpoint for the responsibility this agent\'s lane holds: the host takes its live claims and '
409
+ 'the current mandate revision from its own records, with your one-line note and next useful action, so a '
410
+ 'replacement session reconciles it before acting. A checkpoint never authorizes replaying a call. '
411
+ + PROJECTS_NOTE,
412
+ {'project': PROJECT_ARG,
413
+ 'checkpoint': {'type': 'string', 'pattern': PROJECT_ID_PATTERN, 'maxLength': 128,
414
+ 'description': 'A new checkpoint id of your choosing, e.g. "cp-2026-11-01-a".'},
415
+ 'note': {'type': 'string', 'maxLength': C.PROJECT_TEXT_MAX,
416
+ 'description': 'What holds now, in a sentence or two.'},
417
+ 'next_action': {'type': 'string', 'maxLength': C.PROJECT_TEXT_MAX,
418
+ 'description': 'The next useful action.'}},
419
+ required=('project', 'checkpoint'), hints=_writes(False, False)),
420
+ )
421
+ PROJECT_TOOL_BY_NAME = {tool['name']: tool for tool in PROJECT_TOOLS}
422
+ PROJECT_OPS = {'lanes_work_list': 'work_list', 'lanes_work_claim': 'work_claim',
423
+ 'lanes_work_release': 'work_release', 'lanes_checkpoint': 'checkpoint'}
424
+
358
425
 
359
426
  class RpcError(Exception):
360
427
  def __init__(self, code, message):
@@ -463,6 +530,9 @@ HUMAN = {
463
530
  'retried: `~/.lz/bin/lane inbox` shows each message\'s receipt.',
464
531
  'duplicate_risk': 'The message may have arrived already: a person who accepts that it may arrive twice runs '
465
532
  '`~/.lz/bin/lane inbox retry <id> --duplicate-risk`, or the recipient acknowledges it.',
533
+ # R2-S10: the project tools.
534
+ 'projects_unavailable': 'Coordinate with lanes_message meanwhile; a person turns projects on once the host runs the '
535
+ 'Lanes 2.0 project store (LANES_PROJECTS).',
466
536
  'refused': 'A person takes it from here.',
467
537
  }
468
538
 
@@ -545,6 +615,10 @@ def validate(schema, arguments):
545
615
  if spec['pattern'] == ID_PATTERN else
546
616
  f'"{key}" is not a message id (10–20 lower-case letters and digits)'
547
617
  if spec['pattern'] == MESSAGE_ID_PATTERN else
618
+ f'"{key}" is not a project id (letters, digits, _ . : -; at most {spec["maxLength"]})'
619
+ if spec['pattern'] == PROJECT_ID_PATTERN else
620
+ f'"{key}" is not a cursor lanes_work_list answered'
621
+ if spec['pattern'] == WORK_CURSOR_PATTERN else
548
622
  f'"{key}" is neither a lane id nor an address (an optional @, then letters, digits, '
549
623
  f'_ . -; at most {spec["maxLength"]})')
550
624
  elif len(value) < spec.get('minLength', 0):
@@ -697,7 +771,7 @@ class Server:
697
771
  if self.protocol is None:
698
772
  raise RpcError(NOT_INITIALIZED, 'Server not initialized: send initialize first')
699
773
  if method == 'tools/list':
700
- return {'tools': json.loads(json.dumps(TOOLS))}
774
+ return {'tools': json.loads(json.dumps(self.listed()))}
701
775
  if method == 'tools/call':
702
776
  return self.call(params)
703
777
  raise RpcError(METHOD_NOT_FOUND, f'Method not found: {method}')
@@ -713,12 +787,18 @@ class Server:
713
787
  'serverInfo': {'name': 'lanes', 'version': self.version}, 'instructions': INSTRUCTIONS}
714
788
 
715
789
  # ---------------------------------------------------------------------------------------------- tools
790
+ def listed(self):
791
+ """The tools this server lists: the frozen thirteen, then the project tools while the container holds the
792
+ projects switch (R2-S10)."""
793
+ return TOOLS + PROJECT_TOOLS if C.projects_enabled(self.root) else TOOLS
794
+
716
795
  def call(self, params):
717
796
  name, arguments = params.get('name'), params.get('arguments')
718
- if not isinstance(name, str) or name not in TOOL_BY_NAME:
797
+ table = {tool['name']: tool for tool in self.listed()}
798
+ if not isinstance(name, str) or name not in table:
719
799
  raise RpcError(INVALID_PARAMS, f'Unknown tool: {name!r} (tools/list names them)')
720
800
  started, lane, code = time.monotonic(), None, None
721
- writes = name in WRITE_TOOLS
801
+ writes = name in WRITE_TOOLS or name in PROJECT_TOOL_BY_NAME # a project tool always answers JSON
722
802
  self._peers = None # W15 L6: virtual_peers read afresh for each call (Server.peers)
723
803
  try:
724
804
  if arguments is None:
@@ -726,7 +806,7 @@ class Server:
726
806
  if not isinstance(arguments, dict):
727
807
  raise ToolError('arguments must be an object')
728
808
  lane = arguments.get('lane') if C.TARGET_RE.fullmatch(str(arguments.get('lane') or '')) else None
729
- problems = validate(TOOL_BY_NAME[name]['inputSchema'], arguments)
809
+ problems = validate(table[name]['inputSchema'], arguments)
730
810
  if problems:
731
811
  raise ToolError('; '.join(problems))
732
812
  payload, error = getattr(self, 'tool_' + name[len('lanes_'):])(arguments), False
@@ -1435,6 +1515,26 @@ class Server:
1435
1515
  out = C.message_ack(self.root, lane, arguments['id'])
1436
1516
  return {**out, 'picked_up_by': STATUS_PICKUP, 'expected_within_s': STATUS_LATENCY_S}
1437
1517
 
1518
+ # ------------------------------------------------------------------------------------------ project tools
1519
+ def project(self, name, arguments):
1520
+ """R2-S10: one project tool from this agent's own lane. The request is built and validated
1521
+ (lane_core.project_request) and, while no transport reaches the host's project store, answered
1522
+ `projects_unavailable` with it: nothing is claimed, released or recorded."""
1523
+ lane = self.own_lane(name)
1524
+ raise C.project_unavailable(C.project_request(PROJECT_OPS[name], lane, arguments))
1525
+
1526
+ def tool_work_list(self, arguments):
1527
+ return self.project('lanes_work_list', arguments)
1528
+
1529
+ def tool_work_claim(self, arguments):
1530
+ return self.project('lanes_work_claim', arguments)
1531
+
1532
+ def tool_work_release(self, arguments):
1533
+ return self.project('lanes_work_release', arguments)
1534
+
1535
+ def tool_checkpoint(self, arguments):
1536
+ return self.project('lanes_checkpoint', arguments)
1537
+
1438
1538
 
1439
1539
  def main(argv):
1440
1540
  if argv:
@@ -3829,3 +3829,113 @@ def _unlink_at(dir_fd, name):
3829
3829
  os.unlink(name, dir_fd=dir_fd)
3830
3830
  except OSError:
3831
3831
  pass
3832
+
3833
+
3834
+ # ------------------------------------------------------------------------------------------------ project tools
3835
+ # Lanes 2.0 Round 2, lane R2-S10 (W28-D; CW sections 5 and 6.3). The agent's half of the project, claim and
3836
+ # checkpoint store that lives in the host runtime (crates/lanes-runtime/src/project, built and NOT activated): the
3837
+ # request a project tool would send, built and validated here, and the refusal every tool answers until the host
3838
+ # serves it. The project tools are listed only while the container holds the projects switch (PROJECTS_FLAG, the
3839
+ # container's LANES_PROJECTS=on; no installer writes it yet), so the frozen wire v1 listing keeps its bytes; and
3840
+ # even then no transport carries the request to the host before integration gate I1, so the answer is
3841
+ # `projects_unavailable` with the request it would have sent — never a simulated claim. The request's bytes are
3842
+ # the ones lanes-runtime's `project::requests` decodes: both sides are held to the shared fixture
3843
+ # crates/lanes-runtime/src/project/testdata/agent-requests.json.
3844
+ PROJECTS_FLAG = ('flags', 'projects') # ~/.lz/flags/projects: a regular file, no link
3845
+ PROJECT_REQUEST = 'lanes.project-request.v1'
3846
+ PROJECT_ID_RE = re.compile(r'[A-Za-z0-9_][A-Za-z0-9_.:-]{0,127}') # lanes-core's project-domain id grammar
3847
+ WORK_CURSOR_RE = re.compile(r'[0-9]{10}:[0-9]{20}:[A-Za-z0-9_][A-Za-z0-9_.:-]{0,127}') # the ready view's cursor
3848
+ PROJECT_COUNTER_MAX = (1 << 53) - 1 # lanes-core COUNTER_MAX: revisions and epochs
3849
+ WORK_LIMIT_MAX, WORK_LIMIT_DEFAULT = 100, 20 # one page of the ready view (the host's max 500)
3850
+ LEASE_MIN_S, LEASE_MAX_S, LEASE_DEFAULT_S = 60, 7 * 24 * 3600, 1800 # lanes-runtime LEASE_MAX_MS is 7 days
3851
+ PROJECT_TEXT_MAX = 2048 # lanes-runtime TEXT_MAX (bytes, UTF-8)
3852
+ # Every key a request may carry, in its one order (lanes-runtime's AgentRequest field order).
3853
+ PROJECT_KEYS = ('schema', 'op', 'lane', 'project', 'item', 'revision', 'epoch', 'lease_s', 'after', 'limit',
3854
+ 'checkpoint', 'note', 'next_action')
3855
+ PROJECT_OPS = { # op -> (required arguments, optional arguments)
3856
+ 'work_list': (('project',), ('after', 'limit')),
3857
+ 'work_claim': (('project', 'item', 'revision'), ('lease_s',)),
3858
+ 'work_release': (('project', 'item', 'epoch', 'revision'), ()),
3859
+ 'checkpoint': (('project', 'checkpoint'), ('note', 'next_action')),
3860
+ }
3861
+ PROJECTS_PICKUP = 'lanes-runtime project store' # who would take the request (named in the refusal)
3862
+
3863
+
3864
+ def projects_enabled(root):
3865
+ """Whether the container holds the projects switch: ~/.lz/flags/projects as a regular file reached without a
3866
+ symbolic link (a link planted in the volume is never followed)."""
3867
+ path = Path(root).joinpath(*PROJECTS_FLAG)
3868
+ try:
3869
+ no_links(root, path)
3870
+ return stat.S_ISREG(os.lstat(str(path)).st_mode)
3871
+ except (OSError, LaneError):
3872
+ return False
3873
+
3874
+
3875
+ def _project_value(key, value):
3876
+ """One argument checked against its rule -> the value the request carries, else a LaneError."""
3877
+ def bad(why):
3878
+ return _refusal(f'"{key}" {why}', 'invalid_arguments', argument=key)
3879
+ if key in ('project', 'item', 'checkpoint'):
3880
+ if not isinstance(value, str) or not PROJECT_ID_RE.fullmatch(value):
3881
+ raise bad('is not a project id (letters, digits, _ . : -; at most 128, not starting with . : -)')
3882
+ return value
3883
+ if key == 'after':
3884
+ if not isinstance(value, str) or not WORK_CURSOR_RE.fullmatch(value):
3885
+ raise bad('is not a cursor lanes_work_list answered')
3886
+ return value
3887
+ if key in ('revision', 'epoch'):
3888
+ if isinstance(value, bool) or not isinstance(value, int) or not 1 <= value <= PROJECT_COUNTER_MAX:
3889
+ raise bad(f'must be an integer between 1 and {PROJECT_COUNTER_MAX}')
3890
+ return value
3891
+ if key == 'lease_s':
3892
+ if isinstance(value, bool) or not isinstance(value, int) or not LEASE_MIN_S <= value <= LEASE_MAX_S:
3893
+ raise bad(f'must be an integer between {LEASE_MIN_S} and {LEASE_MAX_S}')
3894
+ return value
3895
+ if key == 'limit':
3896
+ if isinstance(value, bool) or not isinstance(value, int) or not 1 <= value <= WORK_LIMIT_MAX:
3897
+ raise bad(f'must be an integer between 1 and {WORK_LIMIT_MAX}')
3898
+ return value
3899
+ if key in ('note', 'next_action'):
3900
+ if not isinstance(value, str) or len(value.encode('utf-8', 'surrogatepass')) > PROJECT_TEXT_MAX:
3901
+ raise bad(f'must be text of at most {PROJECT_TEXT_MAX} bytes')
3902
+ if any(unicodedata.category(ch) == 'Cc' and ch != '\n' for ch in value):
3903
+ raise bad('holds a control character')
3904
+ return value
3905
+ raise bad('is not an argument of a project request')
3906
+
3907
+
3908
+ def project_request(op, lane, arguments):
3909
+ """The canonical request of project tool `op` from the agent in `lane` -> a dict in PROJECT_KEYS order:
3910
+ {schema, op, lane, …the op's arguments that are present}, the defaults (`limit`, `lease_s`) filled in. Refused
3911
+ (LaneError `invalid_arguments`) for an unknown op, a missing or unknown argument, or a value outside its rule."""
3912
+ if op not in PROJECT_OPS:
3913
+ raise _refusal(f'{op!r} is not a project request', 'invalid_arguments')
3914
+ if not isinstance(lane, str) or not LANE_RE.fullmatch(lane):
3915
+ raise _refusal(f'{lane!r} is not a lane id', 'invalid_arguments', argument='lane')
3916
+ required, optional = PROJECT_OPS[op]
3917
+ unknown = sorted(set(arguments) - set(required) - set(optional))
3918
+ if unknown:
3919
+ raise _refusal(f'"{unknown[0]}" is not an argument of {op}', 'invalid_arguments', argument=unknown[0])
3920
+ for key in required:
3921
+ if key not in arguments:
3922
+ raise _refusal(f'missing required argument "{key}"', 'invalid_arguments', argument=key)
3923
+ values = dict(arguments)
3924
+ if op == 'work_list':
3925
+ values.setdefault('limit', WORK_LIMIT_DEFAULT)
3926
+ if op == 'work_claim':
3927
+ values.setdefault('lease_s', LEASE_DEFAULT_S)
3928
+ request = {'schema': PROJECT_REQUEST, 'op': op, 'lane': lane}
3929
+ for key in PROJECT_KEYS[3:]:
3930
+ if key in values:
3931
+ request[key] = _project_value(key, values[key])
3932
+ return request
3933
+
3934
+
3935
+ def project_unavailable(request):
3936
+ """The refusal every project tool answers while the host's project store is not reachable from this container
3937
+ (LANES_PROJECTS off on the host, or no agent transport before integration gate I1): nothing was sent and nothing
3938
+ changed; the answer carries the request that would have been sent."""
3939
+ return _refusal(f'{request["op"]}: the host\'s project store is not active, so nothing was claimed, released or '
3940
+ f'recorded (the request was not sent)', 'projects_unavailable', request=request,
3941
+ owner=PROJECTS_PICKUP)