@vibelord/lanes 1.7.6 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +13 -9
  2. package/package.json +1 -1
  3. package/payload/lanes/README.md +2 -2
  4. package/payload/lanes/VERSION +1 -1
  5. package/payload/lanes/bin/lanes +26 -4
  6. package/payload/lanes/bin/lanes-site-serve +4 -8
  7. package/payload/lanes/bin-rs/BINARIES.json +17 -2
  8. package/payload/lanes/bin-rs/THIRD-PARTY-NOTICES +18953 -0
  9. package/payload/lanes/bin-rs/x86_64-unknown-linux-musl/lanes-hook +0 -0
  10. package/payload/lanes/bin-rs/x86_64-unknown-linux-musl/lanes-terminal +0 -0
  11. package/payload/lanes/client/lanes-launch +4 -2
  12. package/payload/lanes/container/lane-mcp +1 -1
  13. package/payload/lanes/container/lane_core.py +4 -3
  14. package/payload/lanes/docs/ARCHITECTURE.md +38 -9
  15. package/payload/lanes/docs/RUNBOOK.md +123 -53
  16. package/payload/lanes/docs/USERGUIDE.md +68 -9
  17. package/payload/lanes/install/lanes-host.service.in +25 -0
  18. package/payload/lanes/install/services.py +243 -0
  19. package/payload/lanes/libexec/agent_state.py +3 -1
  20. package/payload/lanes/libexec/attach.py +139 -21
  21. package/payload/lanes/libexec/cutover.py +24 -4
  22. package/payload/lanes/libexec/doctor_lanes2.py +3 -3
  23. package/payload/lanes/libexec/native.sh +2 -2
  24. package/payload/lanes/libexec/native_bin.py +595 -109
  25. package/payload/lanes/libexec/shadow.py +51 -3
  26. package/payload/lanes/libexec/sidebar.py +208 -35
  27. package/payload/lanes/libexec/sidebar_status.py +190 -80
  28. package/payload/lanes/libexec/update.py +12 -3
  29. package/payload/lanes/site/protocol.py +24 -9
  30. package/payload/lanes/site/relay.py +292 -0
  31. package/payload/lanes/site/server.py +31 -3
  32. package/payload/lanes/web/README.md +6 -6
  33. package/payload/lanes/web/directory.js +10 -8
  34. package/payload/lanes/web/generated/README.md +85 -21
  35. package/payload/lanes/web/generated/lanes2_protocol.d.mts +4190 -188
  36. package/payload/lanes/web/generated/lanes2_protocol.mjs +14218 -351
  37. package/payload/lanes/web/inbox.js +8 -6
  38. package/payload/manifest.json +22 -5
@@ -15,13 +15,24 @@ however many devices view a board; `atomic_write_if_changed` skips a write whose
15
15
  `board_view`, the function that builds the board files below, so both sources paint the same frame.
16
16
  Its write decision is compared()-style (BEY-6933): a document whose only news is `fleet.at` or `throttle.at`
17
17
  (statusd's sample times: every FLEET_INTERVAL, every pulse) is the previous document, byte for byte, so it is never
18
- rewritten for that alone. `directory_revision` (also the source's `observed_at_unix_ms` and cursor) is the Unix ms at
19
- which the content first appeared, so it moves exactly when the content does, and it only grows on this host: a
20
- restarted statusd starts from the document already on disk (`prior_directory`), so neither a restart nor a clock
21
- step back lowers it, and a restart over unchanged content writes nothing. Liveness is the health line's `status_at`
22
- (DM-LANES-HEALTH), never this file's mtime. The rows are ONE page of at most PAGE_ROWS (500); above that the page
23
- is `incomplete` and names no `next_page` (no continuation is published: an open item for the Rust projector, B9),
24
- while the compatibility body still carries every lane.
18
+ rewritten for that alone. Revisions follow final contract decision FC-I-9's one clock rule, max(now_ms, last + 1):
19
+ the host source revision R (also `directory_revision`, the source's `observed_at_unix_ms` and its cursor
20
+ `lanes_host.<R>`) advances only when the directory's rows change (every row, the page and beyond it); a change
21
+ confined to the compatibility body is rewritten with the same revisions. A row's `source.revision` is the R at which
22
+ its content last changed. A restarted statusd starts from the document already on disk (`prior_directory`): neither
23
+ a restart nor a clock step back lowers a revision, and a restart over unchanged content writes nothing. Liveness is
24
+ the health line's `status_at` (DM-LANES-HEALTH), never this file's mtime. The rows are ONE page of at most PAGE_ROWS
25
+ (500); above that the page is `incomplete` and names no `next_page` (live paging is the authenticated directory's,
26
+ FC-I-12), while the compatibility body still carries every lane.
27
+
28
+ This module is the parity oracle of the Rust writer `lanes-runtime` `projections::twin` (FC-I-11): for the same
29
+ registry, status payload, clock and prior file both produce the same bytes, which the committed golden
30
+ `crates/lanes-runtime/src/projections/testdata/directory_twin.golden.json` pins. Each row follows the conformance
31
+ catalog (`lanes/tests/conformance/catalog.json`, FC-I-10): the catalog's activity rules over (holder state, agent
32
+ status, owner wait, agent activity), the `style_tokens` rule, every catalog action with its reason code, and
33
+ `last_activity_unix_ms` = stable_since > since > the last output. A row carries `agent_status` when an agent is
34
+ published and `holder_state` whenever the lane has a holder row (FC-I-5). The twin's principal is `host:directory`
35
+ (FC-X3).
25
36
  - `<board>`: the 1.7.2 per-board projection (DM-LANES-SIDEBAR-STATUS), kept as the compatibility stage for a sidebar of
26
37
  an older tree. Its bytes and its write interval are unchanged (architecture D5), including the rewrite its
27
38
  `fleet.at` causes.
@@ -47,7 +58,8 @@ DIRECTORY = '@directory'
47
58
  RENDERED = ('state', 'activity', 'stale', 'agent', 'viewers', 'docs', 'inbox', 'role', 'address')
48
59
  EXTRAS = ('fleet', 'throttle', 'web_origin')
49
60
  SAMPLED = ('fleet', 'throttle') # objects whose `at` is a sample time: news only beside a fact (statusd.compared)
50
- PRESENTATION_REVISION = 3 # lanes/tokens/tokens.v1.json theme.revision (palette v3); a test pins the two together
61
+ PRESENTATION_REVISION = 3 # lanes/tokens/tokens.v1.json theme.revision (FC-I-9); a test pins the two together
62
+ PRINCIPAL = 'host:directory' # the twin's principal (FC-X3)
51
63
  PAGE_ROWS = 500 # the contract's rows bound (lanes-protocol PAGE_MAX_ITEMS); this file is one page
52
64
  LABEL_BYTES = 256
53
65
  TOKEN_BYTES = 128
@@ -60,10 +72,11 @@ SECTION_ORDER = ('needs_you', 'working', 'done_unseen', 'remaining', 'unregister
60
72
  ATTENTION_ORDER = ('approval', 'actionable_error', 'input') # sidebar NEEDS_RANK: needs_approval, errored, needs_input
61
73
  INF = float('inf')
62
74
  PRIOR_BYTES = 64 << 20 # the most of a previous process's directory a restart reads (prior_directory)
63
- # The attach action's reason when the lane cannot be shown (statusd's words: `absent` = no such session in a running
64
- # container, `missing` = the container is down, `dead` = the pane's process ended).
65
- UNHEALTHY = {'absent': 'no such session right now', 'missing': 'its container is not running',
66
- 'dead': 'the pane has exited'}
75
+ # The attach action's reason code when the lane cannot be shown (catalog reasons; statusd's words are their `words`:
76
+ # `absent` = no such session in a running container, `missing` = the container is down, `dead` = the pane exited).
77
+ UNHEALTHY = {'absent': 'session_absent', 'missing': 'container_down', 'dead': 'pane_exited'}
78
+ # The catalog's ongoing activities (`expires_when_stale`): stale when the row is not fresh.
79
+ ONGOING = ('working', 'delegating', 'waiting_build', 'waiting_capacity', 'waiting_person')
67
80
  # statusd's process: name -> (comparison key, published text, revision) of the last directory it published. A restart
68
81
  # starts empty and its first cycle seeds it from the document on disk (prior_directory), so an unchanged directory is
69
82
  # not rewritten and the revision never falls; `projections(memo=...)` gives a caller (a test) its own.
@@ -159,43 +172,104 @@ def millis(value):
159
172
  return max(0, min(int(value * 1000), (1 << 63) - 1))
160
173
 
161
174
 
162
- def directory_row(lane_id, workspaces, entry, row, authority, unregistered):
163
- """One LaneDirectoryRow (TI §3, IC §5.1) from the registry `entry` and the status `row` of a lane the boards
164
- `workspaces` list (the first one minted it). The section is the DEFAULT one: viewed-Done and pins are principal
165
- preferences each client applies (the Python sidebar keeps its device and profile marks). The revision is 0 until
166
- `stamp` fills it."""
167
- row = row if isinstance(row, dict) else {}
168
- agent = row.get('agent') if isinstance(row.get('agent'), dict) else {}
169
- status = agent.get('status') if agent.get('status') in tokens.AGENT_GLYPHS else None
170
- state = row.get('state') if row.get('state') in tokens.GLYPHS else 'unknown'
171
- stale = row.get('stale') is True or state == 'unknown'
172
- attention = ATTENTION.get(status, 'none')
173
- if stale:
174
- activity = 'stale'
175
- elif state == 'missing':
175
+ def activity_of(state, status, waiting_on, agent_activity, fresh):
176
+ """The catalog's activity (lanes/tests/conformance/catalog.json `activity_rules`, FC-I-10): the first rule over
177
+ (holder state, agent status, owner wait, agent activity), then `stale` for an ongoing activity whose row is not
178
+ fresh (`expires_when_stale`)."""
179
+ if state == 'missing':
176
180
  activity = 'disconnected'
177
- elif state in ('absent', 'dead'):
181
+ elif state in ('dead', 'absent'):
178
182
  activity = 'stopped'
179
- elif attention != 'none':
183
+ elif state == 'unknown':
184
+ activity = 'stale'
185
+ elif status in ('needs_approval', 'errored', 'needs_input'):
180
186
  activity = 'waiting_person'
187
+ elif status == 'working' and waiting_on == 'build':
188
+ activity = 'waiting_build'
189
+ elif status == 'working' and waiting_on == 'capacity':
190
+ activity = 'waiting_capacity'
181
191
  elif status == 'working':
182
- activity = 'delegating' if agent.get('activity') == 'delegating' else 'working'
183
- elif status == 'done' or state != 'active':
192
+ activity = 'delegating' if agent_activity == 'delegating' else 'working'
193
+ elif status in ('done', 'idle'):
184
194
  activity = 'finished'
185
195
  else:
186
- activity = 'working'
196
+ activity = 'stopped'
197
+ return 'stale' if not fresh and activity in ONGOING else activity
198
+
199
+
200
+ def style_token(activity, status, state):
201
+ """The catalog's `style_tokens` rule (FC-I-10): `ink-dim` when the activity is stale; otherwise the agent glyph's
202
+ tone when an agent is published; otherwise the holder state's stream tone (lanes/tokens/tokens.v1.json)."""
203
+ if activity == 'stale':
204
+ return 'ink-dim'
205
+ return (tokens.AGENT_GLYPHS[status] if status else tokens.GLYPHS[state])[2]
206
+
207
+
208
+ def unavailable(name, availability, reason):
209
+ return {'action': name, 'availability': availability, 'reason': reason}
210
+
211
+
212
+ def actions(registered, closable, zmx, state):
213
+ """Every catalog action in catalog order with its availability and reason code, for the host-scoped view (no
214
+ principal preferences, read-write): pin and hide need a registered lane, then an owner profile; close takes a
215
+ closable unregistered session, a registered lane unregisters first; rename always opens; a zmx lane takes no
216
+ message; only a closable unregistered session registers; attach is unhealthy for an absent session, a down
217
+ container or an exited pane. `busy` is kit-local and never on the wire."""
218
+ out = []
219
+ for name in ('pin', 'hide'):
220
+ out.append(unavailable(name, 'unconfigured', 'no_owner_profile') if registered
221
+ else unavailable(name, 'unsupported', 'not_registered'))
222
+ if not registered and closable:
223
+ out.append({'action': 'close', 'availability': 'available'})
224
+ else:
225
+ out.append(unavailable('close', 'unsupported', 'registered_unregister_first' if registered else 'not_closable'))
226
+ out.append({'action': 'rename', 'availability': 'available'})
227
+ out.append(unavailable('message', 'unsupported', 'not_messageable') if zmx
228
+ else {'action': 'message', 'availability': 'available'})
229
+ if registered:
230
+ out.append(unavailable('register', 'unsupported', 'already_registered'))
231
+ elif closable:
232
+ out.append({'action': 'register', 'availability': 'available'})
233
+ else:
234
+ out.append(unavailable('register', 'unsupported', 'not_promotable'))
235
+ out.append(unavailable('attach', 'unhealthy', UNHEALTHY[state]) if state in UNHEALTHY
236
+ else {'action': 'attach', 'availability': 'available'})
237
+ return out
238
+
239
+
240
+ def directory_row(lane_id, workspaces, entry, row, authority, unregistered, zmx=False, waiting_on=None):
241
+ """One LaneDirectoryRow (TI §3, IC §5.1) from the registry `entry` and the status `row` of a lane the boards
242
+ `workspaces` list (the first one minted it), under the conformance catalog's one presentation rule (FC-I-10). The
243
+ section is the DEFAULT one: viewed-Done and pins are principal preferences each client applies (the Python sidebar
244
+ keeps its device and profile marks). `holder_state` is present whenever the lane has a holder row (`unknown`
245
+ included) and `agent_status` when an agent is published (FC-I-5). `waiting_on` is the owner wait class (`build`,
246
+ `capacity`; FC-X15): statusd has no wait source, so the twin passes None, and the catalog rule is the same one the
247
+ Rust bridge applies to the waits it is handed. The revision is 0 until `stamp` fills it."""
248
+ has_row = isinstance(row, dict)
249
+ row = row if has_row else {}
250
+ agent = row.get('agent') if isinstance(row.get('agent'), dict) else {}
251
+ status = agent.get('status') if agent.get('status') in tokens.AGENT_GLYPHS else None
252
+ state = row.get('state') if row.get('state') in tokens.GLYPHS else 'unknown'
253
+ stale = row.get('stale') is True or state == 'unknown'
254
+ attention = ATTENTION.get(status, 'none')
255
+ activity = activity_of(state, status, waiting_on, agent.get('activity'), not stale)
187
256
  section = 'unregistered' if unregistered else SECTION[AS.SECTION.get(status)]
188
- attach = {'action': 'attach', 'availability': 'available'}
189
- if state in UNHEALTHY:
190
- attach = {'action': 'attach', 'availability': 'unhealthy', 'reason': UNHEALTHY[state]}
191
- return {'v': 1, 'lane': {'authority': authority, 'workspace_id': workspaces[0], 'lane_id': lane_id},
257
+ # FC-I-10's order stamp: a published agent's stable_since, else its since, else unknown (0); the holder's last
258
+ # output only for a lane with no published agent, so a client orders by this stamp exactly as order_key does.
259
+ stamp_at = entered_at(agent) if status else row.get('activity')
260
+ made = {'v': 1, 'lane': {'authority': authority, 'workspace_id': workspaces[0], 'lane_id': lane_id},
192
261
  'memberships': [{'workspace_id': workspace} for workspace in workspaces],
193
262
  'label': label(entry.get('name') or lane_id), 'activity': activity, 'attention': attention,
194
263
  'section': section,
195
- 'last_activity_unix_ms': millis(row['activity'] if 'activity' in row else agent.get('since')),
196
- 'style_token': (tokens.AGENT_GLYPHS[status] if status else tokens.GLYPHS[state])[2],
264
+ 'last_activity_unix_ms': 0 if stamp_at is None else millis(stamp_at),
265
+ 'style_token': style_token(activity, status, state),
197
266
  'source': {'owner': 'lanes_host', 'revision': 0, 'freshness': 'stale' if stale else 'fresh'},
198
- 'actions': [attach]}
267
+ 'actions': actions(not unregistered, unregistered, zmx, state)}
268
+ if status:
269
+ made['agent_status'] = status
270
+ if has_row:
271
+ made['holder_state'] = state
272
+ return made
199
273
 
200
274
 
201
275
  def entered_at(agent):
@@ -227,44 +301,51 @@ def order_key(row, entered):
227
301
  return (SECTION_ORDER.index(section),) + rank + (identity,)
228
302
 
229
303
 
230
- def directory(registry, payload, authority, runtime):
304
+ def directory(registry, payload, authority, runtime, everything=None):
231
305
  """The LaneDirectoryProjection v1 of this host, revision fields 0: every lane any board lists (registered, zmx, then
232
306
  unregistered sessions) once, its identity (authority, the board that lists it first, lane id) and every board that
233
- lists it as a membership, in the default order; the counts over all of them."""
307
+ lists it as a membership, in the default order; the counts over all of them. It is `incomplete` exactly when the
308
+ rows exceed the page (FC-I-11: a stale row marks that row, never the directory). `everything`, a list, receives
309
+ every row in order, the page and beyond it (publish_directory's revision key)."""
234
310
  rows = payload.get('lanes') if isinstance(payload.get('lanes'), dict) else {}
235
311
  unregistered = payload.get('unregistered') if isinstance(payload.get('unregistered'), dict) else {}
236
312
  zmx = payload.get('zmx') if isinstance(payload.get('zmx'), dict) else {}
237
- found, order = {}, [] # lane id -> [boards, registry entry, unregistered?]
313
+ found, order = {}, [] # lane id -> [boards, registry entry, unregistered?, a zmx holder?]
238
314
  for name, board in boards(registry):
239
- for entries, ghost in ((board.get('lanes') or [], False), (listed(zmx.get(name, [])), False),
240
- (listed(unregistered.get(name, [])), True)):
315
+ for entries, ghost, kind in ((listed(board.get('lanes')), False, 'registry'),
316
+ (listed(zmx.get(name, [])), False, 'zmx'),
317
+ (listed(unregistered.get(name, [])), True, 'session')):
241
318
  for entry in entries:
242
319
  lane_id = token(entry.get('id', '')) if isinstance(entry, dict) else ''
243
320
  if not lane_id:
244
321
  continue
245
322
  if lane_id not in found:
246
- found[lane_id] = [[], entry, ghost]
323
+ holder_zmx = kind == 'zmx' or (kind == 'registry' and entry.get('holder') == 'zmx')
324
+ found[lane_id] = [[], entry, ghost, holder_zmx]
247
325
  order.append(lane_id)
248
326
  if name not in found[lane_id][0]:
249
327
  found[lane_id][0].append(name)
250
328
  built = []
251
329
  for lane_id in order:
252
- workspaces, entry, ghost = found[lane_id]
330
+ workspaces, entry, ghost, holder_zmx = found[lane_id]
253
331
  row = rows.get(lane_id)
254
332
  agent = row.get('agent') if isinstance(row, dict) and isinstance(row.get('agent'), dict) else {}
255
- made = directory_row(lane_id, workspaces, entry, row, authority, ghost)
256
- built.append((order_key(made, entered_at(agent)), made))
333
+ status = agent.get('status') if agent.get('status') in tokens.AGENT_GLYPHS else None
334
+ made = directory_row(lane_id, workspaces, entry, row, authority, ghost, holder_zmx)
335
+ built.append((order_key(made, entered_at(agent) if status else None), made))
257
336
  built.sort(key=lambda pair: pair[0])
258
337
  counts = {'total': len(built), 'needs_you': 0, 'working': 0, 'done_unseen': 0}
259
338
  for _key, row in built:
260
339
  if row['section'] in counts:
261
340
  counts[row['section']] += 1
262
- complete = len(built) <= PAGE_ROWS and all(row['source']['freshness'] == 'fresh' for _key, row in built)
263
- return {'v': 1, 'scope': {'principal_id': 'lanes-host', 'authorization_epoch': 0, 'runtime_instance_id': runtime},
341
+ if everything is not None:
342
+ everything.extend(row for _key, row in built)
343
+ complete = len(built) <= PAGE_ROWS
344
+ return {'v': 1, 'scope': {'principal_id': PRINCIPAL, 'authorization_epoch': 0, 'runtime_instance_id': runtime},
264
345
  'directory_revision': 0, 'schema_revision': 1, 'presentation_revision': PRESENTATION_REVISION,
265
346
  'filter': {'workspace_ids': [], 'project_ids': []},
266
- 'sources': [{'owner': 'lanes_host', 'runtime_instance_id': runtime, 'cursor': 'statusd.0', 'revision': 0,
267
- 'freshness': 'fresh', 'observed_at_unix_ms': 0}],
347
+ 'sources': [{'owner': 'lanes_host', 'runtime_instance_id': runtime, 'cursor': 'lanes_host.0',
348
+ 'revision': 0, 'freshness': 'fresh', 'observed_at_unix_ms': 0}],
268
349
  'completeness': 'complete' if complete else 'incomplete', 'counts': counts,
269
350
  'rows': [row for _key, row in built[:PAGE_ROWS]]}
270
351
 
@@ -274,8 +355,9 @@ def rendered(row):
274
355
  return {field: row[field] for field in RENDERED if field in row} if isinstance(row, dict) else row
275
356
 
276
357
 
277
- def document(registry, payload, host):
278
- """The shared directory document, every revision field 0: `directory`, then the compatibility body."""
358
+ def document(registry, payload, host, everything=None):
359
+ """The shared directory document, every revision field 0: `directory`, then the compatibility body. `everything`
360
+ receives every directory row (see `directory`)."""
279
361
  rows = payload.get('lanes') if isinstance(payload.get('lanes'), dict) else {}
280
362
  unregistered = payload.get('unregistered') if isinstance(payload.get('unregistered'), dict) else {}
281
363
  zmx = payload.get('zmx') if isinstance(payload.get('zmx'), dict) else {}
@@ -291,27 +373,41 @@ def document(registry, payload, host):
291
373
  if key in owned or facts:
292
374
  lanes[key] = facts
293
375
  host = token(host, AUTHORITY_BYTES - len('host:')) or 'local'
294
- out = {'v': 1, 'directory': directory(registry, payload, 'host:' + host, 'lanes-host:' + host),
376
+ out = {'v': 1, 'directory': directory(registry, payload, 'host:' + host, 'lanes-host:' + host, everything),
295
377
  'lanes': lanes, 'unregistered': ghosts_of, 'zmx': zmx_of}
296
378
  out.update({key: payload[key] for key in EXTRAS if key in payload})
297
379
  return out
298
380
 
299
381
 
300
- def stamp(doc, revision):
301
- """Fill `doc`'s revision fields with `revision` (the Unix ms its content first appeared) -> doc."""
382
+ def identity_text(row):
383
+ """A row's authority-qualified identity, spelled `authority/workspace/lane`."""
384
+ lane = row['lane']
385
+ return '/'.join((lane['authority'], lane['workspace_id'], lane['lane_id']))
386
+
387
+
388
+ def row_key(row):
389
+ """A row's content without its revision (FC-I-9: a row's revision is the R at which this last changed)."""
390
+ zeroed = dict(row, source=dict(row['source'], revision=0))
391
+ return json.dumps(zeroed, sort_keys=True, separators=(',', ':'))
392
+
393
+
394
+ def stamp(doc, revision, rows=None):
395
+ """Fill `doc`'s revision fields -> doc: the directory, its source and cursor (`lanes_host.<R>`) with `revision`
396
+ (R), and each row with its own revision from `rows` ({identity text: (row key, revision)}), else `revision`."""
302
397
  projection = doc['directory']
303
398
  projection['directory_revision'] = revision
304
399
  for source in projection['sources']:
305
- source.update(revision=revision, cursor=f'statusd.{revision}', observed_at_unix_ms=revision)
400
+ source.update(revision=revision, cursor=f'lanes_host.{revision}', observed_at_unix_ms=revision)
306
401
  for row in projection['rows']:
307
- row['source']['revision'] = revision
402
+ row['source']['revision'] = rows[identity_text(row)][1] if rows else revision
308
403
  return doc
309
404
 
310
405
 
311
406
  def prior_directory(path):
312
- """(comparison key or None, text, revision) of the directory document a previous statusd process left at `path`,
313
- or None (no file, more than PRIOR_BYTES, not JSON, or no revision in 0..2^63-1). The key is `compared` of the
314
- document with its revision fields 0, as publish_directory keys a new one; None when it is not this format."""
407
+ """The memo entry of the directory document a previous statusd process left at `path`, or None (no file, more
408
+ than PRIOR_BYTES, not JSON, or no revision in 0..2^63-1): {'dkey', 'ckey', 'text', 'revision', 'rows'}, keyed as
409
+ publish_directory keys a new one (the rows and the whole document with their revisions 0) and the rows' own
410
+ revisions. The keys are None and the rows empty when it is not this format: the revision still seeds."""
315
411
  try:
316
412
  with open(path, 'rb') as handle:
317
413
  data = handle.read(PRIOR_BYTES + 1)
@@ -328,32 +424,46 @@ def prior_directory(path):
328
424
  if isinstance(revision, bool) or not isinstance(revision, int) or not 0 <= revision < 1 << 63:
329
425
  return None
330
426
  try:
331
- key = json.dumps(compared(stamp(doc, 0)), sort_keys=True, separators=(',', ':'))
332
- except (KeyError, TypeError, AttributeError):
333
- key = None
334
- return key, text, revision
427
+ rows = {identity_text(row): (row_key(row), row['source']['revision']) for row in doc['directory']['rows']}
428
+ if any(isinstance(at, bool) or not isinstance(at, int) for _key, at in rows.values()):
429
+ raise TypeError('a row revision is not an integer')
430
+ dkey = json.dumps([json.loads(key) for key, _at in rows.values()], sort_keys=True, separators=(',', ':'))
431
+ ckey = json.dumps(compared(stamp(doc, 0)), sort_keys=True, separators=(',', ':'))
432
+ except (KeyError, TypeError, AttributeError, ValueError):
433
+ rows, dkey, ckey = {}, None, None
434
+ return {'dkey': dkey, 'ckey': ckey, 'text': text, 'revision': revision, 'rows': rows}
335
435
 
336
436
 
337
437
  def publish_directory(registry, payload, memo, now=None, host=None, prior=None):
338
- """The text of the shared directory document. When its content (everything but the sample times, `compared`, and
339
- the revision) is what `memo` last published, the SAME text again, so statusd's byte compare writes nothing;
340
- otherwise a new revision: the Unix ms now, and always above the last one. A `memo` that has published nothing yet
341
- (a statusd process's first cycle) starts from `prior`, the path of the document already on disk (prior_directory,
342
- read once): an unchanged content keeps its text and revision, and a new one is stamped above it, so a restart never
343
- lowers the revision, even after a clock step back."""
344
- doc = document(registry, payload, os.uname().nodename if host is None else host)
345
- key = json.dumps(compared(doc), sort_keys=True, separators=(',', ':'))
438
+ """The text of the shared directory document under FC-I-9's revision rules. When its rows (every row, beyond the
439
+ page too) and its content (everything but the sample times, `compared`, and the revisions) are what `memo` last
440
+ published, the SAME text again, so statusd's byte compare writes nothing. When only the compatibility body changed, the new text with the same revisions. When a row
441
+ changed (any row, beyond the page too), a new revision R = max(now_ms, last + 1); each row keeps the revision at
442
+ which its content last changed. A `memo` that has published nothing yet (a statusd process's first cycle) starts
443
+ from `prior`, the path of the document already on disk (prior_directory, read once), so a restart never lowers a
444
+ revision, even after a clock step back."""
445
+ everything = []
446
+ doc = document(registry, payload, os.uname().nodename if host is None else host, everything)
447
+ ckey = json.dumps(compared(doc), sort_keys=True, separators=(',', ':'))
448
+ dkey = json.dumps(everything, sort_keys=True, separators=(',', ':'))
346
449
  last = memo.get(DIRECTORY)
347
450
  if last is None and prior is not None:
348
451
  last = prior_directory(prior)
349
- if last and last[0] == key:
452
+ if last and last['dkey'] == dkey and last['ckey'] == ckey:
350
453
  memo[DIRECTORY] = last
351
- return last[1]
352
- revision = millis(time.time() if now is None else now)
353
- if last:
354
- revision = max(revision, last[2] + 1)
355
- text = json.dumps(stamp(doc, revision), sort_keys=True, separators=(',', ':')) + '\n'
356
- memo[DIRECTORY] = (key, text, revision)
454
+ return last['text']
455
+ if last and last['dkey'] == dkey:
456
+ revision = last['revision']
457
+ else:
458
+ revision = max(millis(time.time() if now is None else now), (last['revision'] if last else 0) + 1)
459
+ known = last['rows'] if last else {}
460
+ rows = {}
461
+ for row in everything:
462
+ key = row_key(row)
463
+ old = known.get(identity_text(row))
464
+ rows[identity_text(row)] = (key, old[1] if old and old[0] == key else revision)
465
+ text = json.dumps(stamp(doc, revision, rows), sort_keys=True, separators=(',', ':')) + '\n'
466
+ memo[DIRECTORY] = {'dkey': dkey, 'ckey': ckey, 'text': text, 'revision': revision, 'rows': rows}
357
467
  return text
358
468
 
359
469
 
@@ -21,8 +21,10 @@ installed. Its steps run in this order, each whatever the ones before it returne
21
21
  ran the same check before its commit, so this is the second; a binary whose size or sha256 differs from the list, an
22
22
  unlisted one, or a list that is not well formed fails it, and any flags/native.* file the tree does not admit is
23
23
  removed) · lanes sync · systemctl --user restart lanes-statusd.service (skipped with a warning while
24
- flags/native.statusd exists: that flag gives observation to the host coordinator, AR 9.4, so its Python twin is not
25
- started again; `lanes rs apply` never writes it in Round 1, host_composed) ·
24
+ flags/native.statusd exists: `lanes rs apply` writes it only once the observation and delivery cutover records are
25
+ active for the lanes host, AR 9.4, so its Python twin is not started again) · systemctl --user try-restart
26
+ lanes-host.service while flags/native.host or native.host.shadow exists (FC-R1: the lanes host restarts onto the new
27
+ tree) ·
26
28
  systemctl --user try-restart <unit> for each optional service in TRY_RESTART (restarted only when it runs), and
27
29
  right after lanes-docsd's, `sh install/enable-docs.sh` of the tree (the docs page's pinned Mermaid, plan W10 W8:
28
30
  DOCS_STEP; skipped for a tree that has no such script) ·
@@ -134,6 +136,7 @@ REFUSED = 3 # `lock`'s exit status when another run holds the ru
134
136
  # native_bin.prune_flags); after the commit this step checks the tree again.
135
137
  BIN_RS_STEP = 'verify bin-rs'
136
138
  STATUSD_UNIT = 'lanes-statusd.service'
139
+ HOST_UNIT = 'lanes-host.service' # the Lanes 2.0 host (FC-R1), rendered while HOST is shadow or on
137
140
  DOCS_UNIT = 'lanes-docsd.service'
138
141
  DOCS_STEP = 'enable-docs'
139
142
  DOCS_SCRIPT = 'install/enable-docs.sh'
@@ -449,9 +452,15 @@ def post_commit(tree, state, log, steps=(), before=None, started=None, out=None,
449
452
  str(tree), '--state', str(state), '--prune-flags'])
450
453
  step('sync', [lanes, 'sync'])
451
454
  if os.path.lexists(Path(state) / 'flags' / native_bin.flag_file('statusd', 'on')):
452
- skip('restart lanes-statusd', 'flags/native.statusd: observation belongs to the host coordinator')
455
+ skip('restart lanes-statusd', 'flags/native.statusd: observation belongs to the lanes host')
453
456
  else:
454
457
  step('restart lanes-statusd', [systemctl, '--user', 'restart', STATUSD_UNIT])
458
+ # Lanes 2.0 (final contract decision FC-R1; AR 9.5 as amended): while HOST is shadow or on, the lanes host
459
+ # restarts onto the tree just installed (try-restart: only when it runs). Its new process takes the host
460
+ # lock first.
461
+ if any(os.path.lexists(Path(state) / 'flags' / native_bin.flag_file(native_bin.HOST, mode))
462
+ for mode in ('on', 'shadow')):
463
+ step('try-restart lanes-host', [systemctl, '--user', 'try-restart', HOST_UNIT])
455
464
  for unit in TRY_RESTART:
456
465
  step('try-restart ' + unit[:-len('.service')], [systemctl, '--user', 'try-restart', unit])
457
466
  if unit == DOCS_UNIT and (Path(tree) / DOCS_SCRIPT).is_file():
@@ -9,9 +9,12 @@ Framing: newline-delimited UTF-8 JSON, one object per line, at most FRAME_MAX by
9
9
  reply {"id": N, "ok": {...}} | {"id": N, "err": {"code": "<code>", "human": "<text>"}}
10
10
  The first request of a connection is `hello`; every other op before it is refused `hello_required`.
11
11
 
12
- Ops in v1 (this module is their one definition). They are plan row H1's interim ops (the W16-H seam): transport,
13
- framing, hello and versioning are AR §3.32's; AR's fs.*, exec.run, msg.deliver/msg.status, holder.* and the streams
14
- arrive additively with the owner runtime (W17/W20).
12
+ Ops in v1 (this module is their one definition). They are plan row H1's interim ops (the W16-H seam) and the relay
13
+ ops of FC-X31: transport, framing, hello and versioning are AR §3.32's; AR's fs.*, holder.* and the streams arrive
14
+ additively. msg.deliver, msg.status and exec.run are served by site/relay.py's rules: the first two are relayed to the
15
+ guest's own lanes host once it owns `delivery` (`owner_unclaimed` before, `owner_unavailable` while its lanesd.sock is
16
+ absent); exec.run, exec and tmux_write are refused `owned_elsewhere` once the lanes host owns their domain (lifecycle
17
+ for exec.run and exec, delivery for tmux_write).
15
18
  hello{client, proto} -> {lanes_site, proto, guest_id, boot_id, versions, capabilities, ops, epochs}
16
19
  (`epochs` {workspace: N} is {} until an owner lanesd fences a workspace)
17
20
  boards.list{} -> {boards: [{id, title, container, lanes, stale}]}
@@ -29,9 +32,14 @@ arrive additively with the owner runtime (W17/W20).
29
32
  [intent]}; by template id only (EXEC_TEMPLATES: the pulse and lane-peerd re-arms),
30
33
  never an argv; the guest decides whether it is due (`skipped` with `detail`) and
31
34
  refuses `busy` while its own health is critical
35
+ exec.run{template_id, args{container}, [intent_id], [epoch]} -> as exec (AR's spelling of it; FC-X31)
36
+ msg.deliver{operation_id, to, text, [reply_to], [timing]} -> {operation_id, receipt}: relayed as request{inbox_compose}
37
+ msg.status{operation_id, target{workspace_id, lane_id}, expected_owner_epoch} -> {operation_id, receipt}: relayed as
38
+ command{query_operation}
32
39
  A mutating op (tmux_write, exec) takes an optional `intent` (INTENT: the caller's id of this one attempt, echoed in
33
40
  the reply, never reused) and an optional `epoch` (an integer >= 0). v1 enforces neither; the codes an owner fence will
34
- answer with (RESERVED_ERRORS) are reserved now so that turning the fence on stays additive within v1 (AR §3.32).
41
+ answer with (RESERVED_ERRORS) are reserved now so that turning the fence on stays additive within v1 (AR §3.32). The
42
+ relay's refusals (owner_unclaimed, owner_unavailable, owned_elsewhere, relay_refused) are sent since FC-X31.
35
43
 
36
44
  Check order (normative, every adapter): a request's shape, then its verb allowlist and its text bound, and only then
37
45
  the recipient (socket, lane, container) in the guest's registry. A probe aimed at an unregistered target therefore
@@ -61,7 +69,8 @@ WRITE_DEADLINE_S = 16.0
61
69
  TMUX_TIMEOUT = 5 # = lane_core.TMUX_TIMEOUT
62
70
  ENTER_DELAY = 0.5 # = lane_core.ENTER_DELAY: the Enter is a second client (DEF-1803)
63
71
 
64
- OPS = ('hello', 'boards.list', 'boards.lanes', 'tmux_read', 'tmux_write', 'exec')
72
+ OPS = ('hello', 'boards.list', 'boards.lanes', 'tmux_read', 'tmux_write', 'exec', 'exec.run', 'msg.deliver',
73
+ 'msg.status')
65
74
  CAPABILITIES = ('boards', 'tmux_read', 'tmux_write', 'exec')
66
75
  # template id -> the seconds its one bounded spawn may take (= statusd PULSE_REARM_TIMEOUT / PEERD_REARM_TIMEOUT: each
67
76
  # is one `docker exec -d`). Plan row H1 bounds exec to these two; a new template is a new op version's business.
@@ -89,13 +98,19 @@ ERRORS = (
89
98
  'tmux_failed', # tmux did not take the keys (outcome in `human`)
90
99
  'template_unknown', # exec of a template id not in EXEC_TEMPLATES
91
100
  'argv_refused', # exec carrying anything but a template id and its container (a free-form argv)
92
- 'adapter_unavailable', # the forced command cannot start the adapter its flag names (rs-site before lanesd, W20)
101
+ 'adapter_unavailable', # retired (FC-X31: the forced command always serves the Python server); sent by no server
102
+ 'owner_unclaimed', # msg.deliver/msg.status while no lanes host owns `delivery` on the guest (site/relay.py)
103
+ 'owner_unavailable', # the guest's lanes host owns the domain, but its lanesd.sock is absent or does not answer
104
+ 'owned_elsewhere', # a local effect (tmux_write, exec, exec.run) in a domain the guest's lanes host owns
105
+ 'relay_refused', # the guest's lanes host refused a relayed request: a refusal receipt outside the
106
+ # owner_unavailable class, or a boundary refusal of the relayed frame (code in `human`)
93
107
  'internal', # the server failed; `human` says how, never with a secret
94
108
  )
95
109
  # Reserved in v1, sent by no v1 server: the owner fence of AR §3.32 (W17 on: every mutating op carries the workspace
96
- # epoch and an intent id) and the relay's refusals. A v1 client treats each as a refusal of that request.
97
- RESERVED_ERRORS = ('epoch_required', 'intent_required', 'stale_epoch', 'owner_unclaimed', 'owner_unavailable',
98
- 'store_unavailable')
110
+ # epoch and an intent id). The relay's refusals left this list for ERRORS with FC-X31 (site/relay.py sends them). A v1
111
+ # client treats each as a refusal of that request.
112
+ RESERVED_ERRORS = ('epoch_required', 'intent_required', 'stale_epoch', 'store_unavailable')
113
+ RELAY_ERRORS = ('owner_unclaimed', 'owner_unavailable', 'owned_elsewhere', 'relay_refused') # site/relay.py's
99
114
  IDENT = re.compile(r'[A-Za-z0-9_][A-Za-z0-9_.-]*\Z') # = lanes_lib.IDENT
100
115
  TMUX_SESSION = re.compile(r'[A-Za-z0-9_][A-Za-z0-9_. -]*\Z') # = lanes_lib.TMUX_SESSION
101
116
  ALIAS = re.compile(r'[A-Za-z0-9_][A-Za-z0-9_.-]{0,62}\Z') # an ssh alias in `guest:<alias>`