@vibelord/lanes 1.7.3 → 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 +252 -30
  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
@@ -96,6 +96,7 @@ import visibility # noqa: E402
96
96
  import agent_state as AS # noqa: E402
97
97
  import session_actions as A # noqa: E402
98
98
  import registrations as R # noqa: E402
99
+ import sidebar_status as SS # noqa: E402
99
100
  import tokens # noqa: E402
100
101
  import users # noqa: E402
101
102
 
@@ -405,6 +406,21 @@ FLEET_FULL, FLEET_SHORT = 27, 18
405
406
  # every 10 s (a 12 s cycle at its slowest) and the pulse `throttle.at` at least every 60 s, which statusd flags past
406
407
  # 60 s; a status.json that stopped changing (statusd frozen) still turns the block stale here.
407
408
  FLEET_STALE_S, PULSE_STALE_S = 60, 90
409
+ # 1.7.4: a sidebar on a projection (the 1.7.2 board file or the C7 directory) stats the canonical status.json once
410
+ # every CANON_REFRESH_TICKS reloads (about 15 s) and, when its mtime moved, re-reads the fleet block's two objects
411
+ # from it, so facts a site hook adopts there AFTER the projection was written reach a quiet board too. The C7 tick
412
+ # budget (one status stat per tick) holds: the other ticks stat nothing for it.
413
+ CANON_REFRESH_TICKS = 15
414
+ # Lanes 2.0 C7: the shared directory projection (sidebar_status: sidebar-status/@directory.json) is never rewritten
415
+ # for a new sample time alone. On that source the fleet block's own-clock floor starts at the newer of the object's
416
+ # `at` and the health line's `status_at` (DM-LANES-HEALTH, which poll_health reads anyway: when statusd last wrote
417
+ # status.json, which it does in every cycle that published a payload, so also the directory, and at least every
418
+ # HEARTBEAT 15 s; a statusd whose cycles publish nothing keeps writing the line's `at` but not `status_at`). The list's
419
+ # ages, the block's `429 +N` window and its `reset` countdowns are repainted by the clock instead of riding the
420
+ # rewrites: compared at most once per CLOCK_REFRESH_S, repainted only when one of them changed. 10 s is the interval
421
+ # they rode until now (statusd's FLEET_INTERVAL, the per-board file's `fleet.at`). Both are the compatibility stage's
422
+ # coalescing, with the 1 s select tick; the directory document names no refresh interval.
423
+ CLOCK_REFRESH_S = 10
408
424
  BAR_CELLS = 10
409
425
  # The pulse's pools, in row order, and the row's word: the vendor (W12, spec 2026-10-15 §6: Kimi Code's pool is
410
426
  # `kimi`, its vendor Moonshot AI; W13: Throttle's native `muse-code` pool, vendor Meta, and `zai`, vendor Z.ai). No grok
@@ -497,16 +513,38 @@ def compact_gib(value):
497
513
  return (f'{gib:.1f}' if gib < 9.95 else f'{gib:.0f}').removesuffix('.0') + 'G'
498
514
 
499
515
 
500
- def aged(doc, now, floor):
516
+ def aged(doc, now, floor, alive=None):
501
517
  """Whether a `fleet` / `throttle` object is a frozen picture: its publisher says so (`stale: true`), or its own `at`
502
518
  is more than `floor` seconds behind `now` (OUR clock, DEF-1528). False for {} (nothing known, nothing claimed) and
503
- without a numeric `at`."""
519
+ without a numeric `at`. `alive` (C7: the health line's `status_at` on the shared directory, which keeps an
520
+ unchanged object's `at`) moves the floor's start up to it: the publisher published a payload then and would have
521
+ marked a frozen sample `stale`."""
504
522
  if not doc:
505
523
  return False
506
524
  at = number(doc.get('at'))
525
+ if at is not None and number(alive) is not None:
526
+ at = max(at, alive)
507
527
  return doc.get('stale') is True or (at is not None and now - at > floor)
508
528
 
509
529
 
530
+ def lane_age(observed, now):
531
+ """The age column of a lane's status row (spec §4.2): since its agent's `since` while it has one, else since its
532
+ last output (`activity`), in age3's three cells."""
533
+ agent = observed.get('agent') if isinstance(observed.get('agent'), dict) else {}
534
+ since = agent.get('since') if agent.get('status') in AGENT_GLYPHS else observed.get('activity')
535
+ return age3(int(now - since) if isinstance(since, (int, float)) and since > 0 else None)
536
+
537
+
538
+ def phone_age(observed, now):
539
+ """The age the phone's Row B paints (render_mobile, spec §4.10): since the agent's `since` for an agent status other
540
+ than `shell`, else since the last output (`activity`), as a shell says its state word and its output age; age3's
541
+ text without its padding."""
542
+ agent = observed.get('agent') if isinstance(observed.get('agent'), dict) else {}
543
+ status = agent.get('status') if agent.get('status') in AGENT_GLYPHS else None
544
+ since = agent.get('since') if status and status != 'shell' else observed.get('activity')
545
+ return age3(now - since if isinstance(since, (int, float)) and since > 0 else None).strip()
546
+
547
+
510
548
  def finite(value):
511
549
  """number(value) when it is also finite (a NaN or an infinity in published JSON is no fact), else None."""
512
550
  value = number(value)
@@ -995,6 +1033,17 @@ class Sidebar:
995
1033
  # the first VERSION_RECHECK_S of a process), `restored` when __init__ took a predecessor's .sidebar.state, whose
996
1034
  # cursor lane `restore_id` the first reload puts the cursor on.
997
1035
  swappable, restored, restore_id = False, False, None
1036
+ # Lanes 2.0 C7: the status source (status_source): `directory` (the shared directory projection), `board` (1.7.2's
1037
+ # per-board file, the compatibility stage) or `status` (status.json). On `directory`: the last document read, the
1038
+ # board view derived from it (directory_view), every lane id it lists (the seen marks' bound) and the age column
1039
+ # as last painted (clock_sig) with the time it was last compared (clock_at).
1040
+ source = 'status'
1041
+ directory_doc, directory_last, known_lanes = None, None, None
1042
+ clock_sig, clock_at = None, 0.0
1043
+ # What the last fleet_block laid out that time changes without a rewrite (fleet_clock): whether its Throttle row
1044
+ # carries `429 +N`, and the pools whose provider rows carry a `reset` countdown.
1045
+ block_timed = (False, ())
1046
+ health = {}
998
1047
  profile_marks, last_open, profile_retry_at = {}, None, 0.0
999
1048
  # W9 U6: whether clients/<device>.update-ready existed at the last look (poll_update), when to look next, and until
1000
1049
  # when a rebuild `r` started counts as on its way (monotonic seconds)
@@ -1037,10 +1086,9 @@ class Sidebar:
1037
1086
  self.command_path = L.sidebar_key_path(self.view_dir, workspace)
1038
1087
  self.focused, self.focus_reported, self.legend_until, self.legend_shown = False, False, 0.0, False
1039
1088
  self.registry_path = os.path.join(STATE, 'registry.json')
1040
- self.status_path = os.path.join(STATE, 'status.json')
1089
+ self.directory_path = os.path.join(STATE, 'sidebar-status', SS.DIRECTORY + '.json')
1041
1090
  self.projection_path = os.path.join(STATE, 'sidebar-status', workspace + '.json')
1042
- if os.path.isfile(self.projection_path):
1043
- self.status_path = self.projection_path
1091
+ self.status_path, self.source = self.status_source(first=True)
1044
1092
  self.economy_path = os.path.join(STATE, 'economy.json') # the opt-in poller's projection (Task 11)
1045
1093
  self.health_path = os.path.join(STATE, 'health')
1046
1094
  self.health, self.health_stamp, self.banner = {}, None, ''
@@ -1081,7 +1129,8 @@ class Sidebar:
1081
1129
  self.seen = L.clean_seen(read_json(self.seen_path))
1082
1130
  self.merge_seen(profile)
1083
1131
  # registry, status, targets, device look, economy, sidebar.cmd, profile (0 and never stat()ed when ownerless)
1084
- self.stamp = (0, 0, 0, 0, 0, 0, 0)
1132
+ self.stamp = (0, 0, 0, 0, 0, 0, 0, 0)
1133
+ self.canon_countdown, self.canon_mtime = 0, 0 # 1.7.4: canonical_stamp's pacing and its last stat
1085
1134
  self.size = (0, 0)
1086
1135
  self.dirty = True
1087
1136
  self.message = ''
@@ -1113,15 +1162,92 @@ class Sidebar:
1113
1162
  return ''
1114
1163
 
1115
1164
  # ---------------------------------------------------------------- data
1165
+ def status_source(self, first=False):
1166
+ """(path, kind) of the status this sidebar reads (Lanes 2.0 C7): the shared directory projection every sidebar
1167
+ of the host reads (`directory`, sidebar-status/@directory.json), else this board's 1.7.2 projection (`board`, the
1168
+ compatibility stage of a statusd that publishes no directory), else status.json (`status`). __init__ (`first`)
1169
+ tries all three. recheck_version's 30 s check costs ONE stat, the directory's: without one a sidebar stays on
1170
+ its board file while reload()'s per-tick mtime still finds it (a stamp of 0: it vanished, status.json), and on
1171
+ status.json, which only a directory takes over (a statusd of this tree publishes one; a 1.7.2 statusd under a
1172
+ newer sidebar is an upgrade window). Only a directory that vanished (a rollback) looks for the board file
1173
+ again, a second stat on that one check."""
1174
+ if os.path.isfile(self.directory_path):
1175
+ return self.directory_path, 'directory'
1176
+ if not first and self.source == 'board' and self.stamp[1]:
1177
+ return self.projection_path, 'board'
1178
+ if (first or self.source == 'directory') and os.path.isfile(self.projection_path):
1179
+ return self.projection_path, 'board'
1180
+ return os.path.join(STATE, 'status.json'), 'status'
1181
+
1182
+ def directory_view(self):
1183
+ """This board's status document from the shared directory last read (sidebar_status.board_view, the function
1184
+ statusd builds the 1.7.2 board file with: the same rows, the same frame), under the registry this sidebar read.
1185
+ Keeps every lane id the directory lists, on every board, as the seen marks' bound (seen_known)."""
1186
+ doc = self.directory_doc if isinstance(self.directory_doc, dict) else {}
1187
+ lanes = doc.get('lanes') if isinstance(doc.get('lanes'), dict) else {}
1188
+ projection = doc.get('directory') if isinstance(doc.get('directory'), dict) else {}
1189
+ rows = projection.get('rows') if isinstance(projection.get('rows'), list) else []
1190
+ known = set(lanes)
1191
+ for row in rows:
1192
+ lane = row.get('lane') if isinstance(row, dict) else None
1193
+ if isinstance(lane, dict) and isinstance(lane.get('lane_id'), str):
1194
+ known.add(lane['lane_id'])
1195
+ self.known_lanes = known
1196
+ board = next((w for w in self.workspaces if isinstance(w, dict) and w.get('id') == self.workspace), None)
1197
+ return SS.board_view(board or {'id': self.workspace}, lanes, doc.get('unregistered'), doc.get('zmx'), doc)
1198
+
1199
+ def take_directory(self, doc):
1200
+ """Keep the shared directory document `doc` (read_json's value; anything but an object is {}) and its view."""
1201
+ self.directory_doc = doc if isinstance(doc, dict) else {}
1202
+ self.directory_last = self.directory_view()
1203
+
1204
+ def directory_quiet(self, stamp, force):
1205
+ """reload()'s first step on the shared directory (C7). When the document is all that moved, it is read here:
1206
+ a view of THIS board that is the one shown but for the sample times (sidebar_status.compared: `fleet.at` and
1207
+ `throttle.at`, which every rewrite carries as they are at that moment, so another board's news brings new
1208
+ ones) is taken with its lane ids and its fleet facts (take_fleet: the newer sample times for the staleness
1209
+ floor and the `429 +N` samples), and reload() stops (-> True: no reload of the rest, no frame; poll_fleet and
1210
+ poll_clock repaint if those facts change what the block shows). A changed view is kept for reload() to apply
1211
+ without a second read (-> False). None (nothing read) on any other source, a forced reload, a first read, or
1212
+ when the registry, a target, the device file, economy.json, the sidebar command or the profile moved too."""
1213
+ if (force or self.source != 'directory' or self.directory_last is None or stamp[1] == self.stamp[1]
1214
+ or stamp[0] != self.stamp[0] or stamp[2:] != self.stamp[2:]):
1215
+ return None
1216
+ shown = self.directory_last
1217
+ self.take_directory(read_json(self.status_path))
1218
+ if SS.compared(self.directory_last) != SS.compared(shown):
1219
+ return False
1220
+ self.take_fleet(self.directory_last)
1221
+ self.stamp = stamp
1222
+ return True
1223
+
1224
+ def seen_known(self):
1225
+ """The lane ids a seen mark may name (lanes_lib.record_seen's bound). On the shared directory: every lane it
1226
+ lists, on every board, and what this view holds. Every tab of the device writes the same
1227
+ clients/<device>.seen.json, so a bound of one board's view would drop the marks of every other board's lanes
1228
+ from it. Elsewhere: the status this sidebar read."""
1229
+ if self.source == 'directory' and self.known_lanes is not None:
1230
+ return self.known_lanes | set(self.status)
1231
+ return self.status
1232
+
1116
1233
  def reload(self, force=False):
1117
1234
  self.recheck_version()
1118
1235
  if not force and self.swap_due(): # run()'s tick only: a forced reload is an action's, never cut short
1119
1236
  self.self_swap()
1120
1237
  stamp = (mtime(self.registry_path), mtime(self.status_path),
1121
1238
  sum(mtime(self.slot_file(slot, 'target')) for slot in SLOTS[:self.viewports]),
1122
- mtime(self.look_path), mtime(self.economy_path), mtime(self.command_path), self.profile_stamp())
1239
+ mtime(self.look_path), mtime(self.economy_path), mtime(self.command_path), self.profile_stamp(),
1240
+ self.canonical_stamp())
1123
1241
  if stamp == self.stamp and not force:
1124
1242
  return
1243
+ canon = stamp[7] != self.stamp[7] # 1.7.4: status.json's mtime moved since its last paced stat (0 off a projection)
1244
+ quiet = self.directory_quiet(stamp, force) # C7: None (not on the directory), True (nothing to paint), False
1245
+ if quiet:
1246
+ if canon and self.refresh_canonical_fleet():
1247
+ self.stamp, self.dirty = stamp, True
1248
+ else:
1249
+ self.stamp = self.stamp[:7] + (stamp[7],)
1250
+ return
1125
1251
  if force:
1126
1252
  self.row_cache.clear() # `r` and every forced reload repaint every row from scratch (spec §4.11)
1127
1253
  # The cursor follows the LANE, not the index (spec §4.5, §10): a lane that changes section moves rows above
@@ -1142,10 +1268,19 @@ class Sidebar:
1142
1268
  self.errors = workspace.get('errors', [])
1143
1269
  self.attach_only = bool(workspace.get('attach_only'))
1144
1270
  break
1145
- if stamp[1] != self.stamp[1] or force:
1146
- status = read_json(self.status_path) or {}
1147
- if self.status_path == self.projection_path:
1148
- status = self.with_canonical_fleet(status) # 1.7.3: the fleet block reads the canonical facts
1271
+ status = None
1272
+ if self.source != 'directory':
1273
+ if stamp[1] != self.stamp[1] or force:
1274
+ status = read_json(self.status_path) or {}
1275
+ if self.status_path == self.projection_path:
1276
+ status = self.with_canonical_fleet(status) # 1.7.3: preserve the board fallback during upgrades
1277
+ elif stamp[1] != self.stamp[1] or force:
1278
+ if quiet is None: # directory_quiet read nothing; when it returned False it took this document
1279
+ self.take_directory(read_json(self.status_path))
1280
+ status = self.directory_last
1281
+ elif stamp[0] != self.stamp[0]:
1282
+ status = self.directory_last = self.directory_view() # the registry moved: the same document, re-viewed
1283
+ if status is not None:
1149
1284
  self.status = status.get('lanes', {})
1150
1285
  self.unregistered = (status.get('unregistered') or {}).get(self.workspace, [])
1151
1286
  self.zmx = (status.get('zmx') or {}).get(self.workspace, [])
@@ -1168,7 +1303,7 @@ class Sidebar:
1168
1303
  self.login, self.profile_path = owner
1169
1304
  self.profile_marks, self.last_open = {}, None # unwritten marks were for the previous profile
1170
1305
  self.seen = L.clean_seen(read_json(self.seen_path)) # this device's own; the new profile's below
1171
- stamp = stamp[:6] + (self.profile_stamp(),)
1306
+ stamp = stamp[:6] + (self.profile_stamp(),) + stamp[7:]
1172
1307
  profile = True
1173
1308
  before = self.profile_look
1174
1309
  if profile:
@@ -1200,6 +1335,8 @@ class Sidebar:
1200
1335
  merged[key] = max(value, merged.get(key, value))
1201
1336
  self.seen = merged # a fresh dict, never the class default mutated in place
1202
1337
  command = stamp[5] != self.stamp[5] # never `or force`: `r` must not replay the last chord
1338
+ if self.source != 'status' and (canon or status is not None or force):
1339
+ self.refresh_canonical_fleet() # 1.7.4: the block's facts never lag the canonical file by a cycle
1203
1340
  self.stamp = stamp
1204
1341
  self.dirty = True
1205
1342
  # A promoted session whose lane the registry now lists: the cursor on its row goes to the lane (cockpit v3 S8).
@@ -1220,10 +1357,10 @@ class Sidebar:
1220
1357
  if now < self.version_at + VERSION_RECHECK_S:
1221
1358
  return False
1222
1359
  self.version_at = now
1223
- status_path = (self.projection_path if os.path.isfile(self.projection_path)
1224
- else os.path.join(STATE, 'status.json'))
1360
+ status_path, source = self.status_source()
1225
1361
  if status_path != self.status_path:
1226
- self.status_path = status_path
1362
+ self.status_path, self.source = status_path, source
1363
+ self.directory_doc = self.directory_last = self.known_lanes = None
1227
1364
  self.stamp = self.stamp[:1] + (0,) + self.stamp[2:]
1228
1365
  url = site_dashboard() # W11: the dashboard link follows site.conf within 30 s
1229
1366
  if url != self.fleet_url:
@@ -1648,9 +1785,9 @@ class Sidebar:
1648
1785
  its next tick. A profile write that does not get the lock within PROFILE_LOCK_S is retried by run()'s tick."""
1649
1786
  since = self.agent_of(lane_id).get('since')
1650
1787
  if not self.profile_path:
1651
- self.seen = L.record_seen(self.seen_path, lane_id, since, self.status, self.seen)
1788
+ self.seen = L.record_seen(self.seen_path, lane_id, since, self.seen_known(), self.seen)
1652
1789
  return
1653
- mine = L.record_seen(self.seen_path, lane_id, since, self.status)
1790
+ mine = L.record_seen(self.seen_path, lane_id, since, self.seen_known())
1654
1791
  seen = dict(self.seen)
1655
1792
  for lane, at in mine.items():
1656
1793
  seen[lane] = max(at, seen.get(lane, at))
@@ -1844,6 +1981,31 @@ class Sidebar:
1844
1981
  status[key] = theirs
1845
1982
  return status
1846
1983
 
1984
+ def canonical_stamp(self):
1985
+ """reload()'s eighth stamp element: status.json's mtime, stat()ed once every CANON_REFRESH_TICKS calls and
1986
+ held between them, while this sidebar reads a projection (board or directory); 0 on status.json itself, whose
1987
+ facts come with the file. The first call stats (a new sidebar learns the facts at once)."""
1988
+ if self.source == 'status':
1989
+ return 0
1990
+ if self.canon_countdown <= 0:
1991
+ self.canon_mtime, self.canon_countdown = mtime(os.path.join(STATE, 'status.json')), CANON_REFRESH_TICKS
1992
+ else:
1993
+ self.canon_countdown -= 1
1994
+ return self.canon_mtime
1995
+
1996
+ def refresh_canonical_fleet(self):
1997
+ """1.7.4: the fleet block's two objects from status.json when it holds one the sidebar lacks or a newer
1998
+ sample than the one held (with_canonical_fleet's rule, applied to the facts in hand rather than to a
1999
+ projection just read) -> True when either changed. The operator's mini dashboard stayed hidden on 1.7.3 on a
2000
+ quiet board: its projection, rewritten only on change, never changed after the site hook had adopted the
2001
+ guest's pulse into status.json, so the 1.7.3 fallback (projection-change driven) never ran again."""
2002
+ held = {'fleet': self.fleet_facts or None, 'throttle': self.throttle_facts or None}
2003
+ merged = self.with_canonical_fleet(dict(held))
2004
+ if all(merged.get(key) is held.get(key) for key in ('fleet', 'throttle')):
2005
+ return False
2006
+ self.take_fleet({key: value for key, value in merged.items() if isinstance(value, dict)})
2007
+ return True
2008
+
1847
2009
  def take_fleet(self, status):
1848
2010
  """reload()'s status.json read: its `fleet` and `throttle` objects (fleet_doc) and, once per new pulse sample
1849
2011
  (`throttle.at` moved), the pools' summed `upstream_429_total` for `429 +N` (surge). Fresh values only."""
@@ -1866,16 +2028,29 @@ class Sidebar:
1866
2028
  keep = max((i for i, (when, _total) in enumerate(samples) if when <= start), default=0)
1867
2029
  self.surge_samples = samples[keep:][-SURGE_SAMPLES:]
1868
2030
 
1869
- def surge(self):
2031
+ def surge(self, now=None):
1870
2032
  """`429 +N`'s N: the summed upstream_429_total's growth from the newest sample at or before SURGE_S seconds
1871
- before the latest one (the oldest this sidebar has, while it has seen less than that) to the latest."""
2033
+ before the latest one (the oldest this sidebar has, while it has seen less than that) to the latest. On the
2034
+ shared directory (C7), which is never rewritten for a pulse sample alone, the window ends at `now` (our clock)
2035
+ when that is later: an unchanged total is still the latest, so the growth ages out without a new sample, as on
2036
+ the board file, where every pulse adds one."""
1872
2037
  samples = self.surge_samples
1873
- return samples[-1][1] - samples[0][1] if len(samples) > 1 else 0
2038
+ if len(samples) < 2:
2039
+ return 0
2040
+ end = samples[-1][0]
2041
+ if self.source == 'directory' and number(now) is not None:
2042
+ end = max(end, now)
2043
+ base = max((i for i, (when, _total) in enumerate(samples) if when <= end - SURGE_S), default=0)
2044
+ return samples[-1][1] - samples[base][1]
1874
2045
 
1875
2046
  def fleet_aged(self, now):
1876
2047
  """(fleet stale, throttle stale): the publisher's flag, or the object's own `at` past FLEET_STALE_S /
1877
- PULSE_STALE_S by our clock (aged)."""
1878
- return aged(self.fleet_facts, now, FLEET_STALE_S), aged(self.throttle_facts, now, PULSE_STALE_S)
2048
+ PULSE_STALE_S by our clock (aged). On the shared directory the floor starts no earlier than the health line's
2049
+ `status_at` (CLOCK_REFRESH_S above): never its `at`, which statusd writes even in a cycle that published
2050
+ nothing, so a statusd whose payload keeps failing still turns the block stale (DEF-1528)."""
2051
+ alive = number((self.health or {}).get('status_at')) if self.source == 'directory' else None
2052
+ return (aged(self.fleet_facts, now, FLEET_STALE_S, alive),
2053
+ aged(self.throttle_facts, now, PULSE_STALE_S, alive))
1879
2054
 
1880
2055
  def poll_fleet(self):
1881
2056
  """Repaint when either object crosses into (or out of) stale. Polled every tick like poll_economy(): a statusd
@@ -1884,6 +2059,50 @@ class Sidebar:
1884
2059
  if frozen != self.fleet_frozen:
1885
2060
  self.fleet_frozen, self.dirty = frozen, True
1886
2061
 
2062
+ def clock_signature(self, entries, now):
2063
+ """What time alone changes on screen at `now`: the age of each lane row of `entries` (dividers and actions
2064
+ skipped) by the rule of the surface painted (lane_age on the desktop, phone_age on the phone, none on a phone
2065
+ too short for Row B), and the fleet block's timed texts (fleet_clock)."""
2066
+ status, age = self.status, phone_age if self.mobile else lane_age
2067
+ out = []
2068
+ if not (self.mobile and self.entry_height == 1):
2069
+ for entry in entries:
2070
+ if isinstance(entry, dict) and not entry.get('divider') and not entry.get('action'):
2071
+ row = status.get(entry.get('id'))
2072
+ out.append(age(row if isinstance(row, dict) else {}, now))
2073
+ return tuple(out), self.fleet_clock(now)
2074
+
2075
+ def fleet_clock(self, now):
2076
+ """The fleet block's texts that time changes without a rewrite, at `now`, as the last fleet_block laid the block
2077
+ out (block_timed): the Throttle row's `429 +N` (surge) and each shown provider row's `reset` countdown (and
2078
+ whether it is still ahead). () when the last frame had no unfolded block (the fold's line shows neither)."""
2079
+ surged, pools = self.block_timed
2080
+ if not (surged or pools):
2081
+ return ()
2082
+ found = self.throttle_facts.get('pools')
2083
+ found = found if isinstance(found, dict) else {}
2084
+ out = [self.surge(now) if surged else None]
2085
+ for key in pools:
2086
+ pool = found.get(key) if isinstance(found.get(key), dict) else {}
2087
+ reset = finite(pool.get('soonest_reset'))
2088
+ out.append(age3(reset - now).strip() if reset is not None and reset > now else None)
2089
+ return tuple(out)
2090
+
2091
+ def poll_clock(self, now=None, wall=None):
2092
+ """The texts time changes on the shared directory (C7), which is never rewritten for time alone: once per
2093
+ CLOCK_REFRESH_S (monotonic `now`), compare what the screen would show at `wall` (clock_signature: the list's
2094
+ ages, the fleet block's `429 +N` and `reset` countdowns) with what the last frame painted and repaint only
2095
+ when one changed. The board file and status.json are rewritten at least every 10 and 15 s and keep riding
2096
+ that. In-memory only: no I/O."""
2097
+ if self.source != 'directory':
2098
+ return
2099
+ now = time.monotonic() if now is None else now
2100
+ if now < self.clock_at + CLOCK_REFRESH_S:
2101
+ return
2102
+ self.clock_at = now
2103
+ if self.clock_signature(self.last_visible, time.time() if wall is None else wall) != self.clock_sig:
2104
+ self.dirty = True
2105
+
1887
2106
  def fleet_money(self):
1888
2107
  """(text, role) of ONE pool's overflow money — `$8.5k/16k 53%` — or None (no token: every overflow figure is
1889
2108
  null). The pools' daily budgets are separate, non-fungible money, so the figure is never a sum: it is the pool
@@ -1935,7 +2154,7 @@ class Sidebar:
1935
2154
  spills = [finite(pool.get('spill_fraction')) for pool in pools.values() if isinstance(pool, dict)]
1936
2155
  spill = max((value for value in spills if value is not None), default=None)
1937
2156
  spill = [[(f'spill {percent(spill)}%', 'ink-dim')]] if spill is not None and percent(spill) > 0 else []
1938
- surge = self.surge()
2157
+ surge = self.surge(now)
1939
2158
  surge = [[(f'429 +{int(surge)}', 'ink-dim')]] if surge > 0 else []
1940
2159
  money = self.fleet_money()
1941
2160
  if money:
@@ -2106,7 +2325,7 @@ class Sidebar:
2106
2325
  the whole sheet still fits a 24-row pane). Folded (`i`): one line. FLEET_FULL rows or more: the rule, Throttle,
2107
2326
  Anthropic, OpenAI, Moonshot (Kimi), the host, its containers; fewer: Throttle, the worse provider, the host.
2108
2327
  Each row at most cols − 1 cells (column 36 never written)."""
2109
- self.block_says_money = False
2328
+ self.block_says_money, self.block_timed = False, (False, ())
2110
2329
  if self.showing_keys or rows < FLEET_SHORT or not (self.fleet_facts or self.throttle_facts):
2111
2330
  return []
2112
2331
  stale, width = any(self.fleet_aged(now)), max(1, cols - 1)
@@ -2119,11 +2338,14 @@ class Sidebar:
2119
2338
  # spill): a 36-column row that dropped `spill 76%` does not show the strip's facts, so the strip keeps them
2120
2339
  throttle_row, whole = self.fleet_layout('fleet-throttle', throttle, width, stale)
2121
2340
  self.block_says_money = whole and self.throttle_shows_money()
2341
+ surged = bool(self.throttle_facts) and self.throttle_facts.get('up') is not False # throttle_spec's `429 +N`
2122
2342
  if rows < FLEET_FULL:
2123
2343
  key, word = self.worse_provider()
2344
+ self.block_timed = (surged, (key,))
2124
2345
  return [throttle_row,
2125
2346
  self.fleet_row('fleet-provider', self.provider_spec(key, word, now), width, stale),
2126
2347
  self.fleet_row('fleet-host', host, width, stale, link)]
2348
+ self.block_timed = (surged, tuple(key for key, _word in PROVIDERS))
2127
2349
  return [self.fleet_rule(cols), throttle_row] + [
2128
2350
  self.fleet_row('fleet-provider', self.provider_spec(key, word, now), width, stale) for key, word in PROVIDERS
2129
2351
  ] + [self.fleet_row('fleet-host', host, width, stale, link),
@@ -2245,8 +2467,7 @@ class Sidebar:
2245
2467
  state = observed.get('state', 'helper' if entry.get('holder') == 'exec' else 'unknown')
2246
2468
  key_state = state if state in GLYPHS else 'unknown'
2247
2469
  stale = bool(observed.get('stale'))
2248
- since = agent.get('since') if status else observed.get('activity')
2249
- age = age3(int(now - since) if isinstance(since, (int, float)) and since > 0 else None)
2470
+ age = lane_age(observed, now)
2250
2471
  is_cursor, is_viewing = index == self.cursor, entry['id'] == target
2251
2472
  # Column 3: a row `P` is registering says so first (cockpit v3 S8, the dim `pending` mark), then the viewports.
2252
2473
  pending = bool(entry.get('pending'))
@@ -4019,6 +4240,7 @@ class Sidebar:
4019
4240
  # not, and the strip keeps its place), else fleet attention.
4020
4241
  self.box = rows >= 14 and not self.registration and not self.attach_only
4021
4242
  block = self.fleet_block(cols, rows, now)
4243
+ self.clock_sig = self.clock_signature(entries, now) # C7: what time changes in this frame (poll_clock)
4022
4244
  economy_line = (self.economy_strip(cols - 2, now)[0] if self.economy and rows >= 18
4023
4245
  and not (block and self.block_says_money) else '')
4024
4246
  self.strip_row = rows >= 18 and (bool(economy_line) or bool(self.fleet))
@@ -4150,6 +4372,7 @@ class Sidebar:
4150
4372
  line(counts or f' {len(self.shown_lanes())} lanes', tone['ink-dim'] if self.banner or not counts else tone['bold'])
4151
4373
  line()
4152
4374
  now, sep = time.time(), f' {marks["sep"]} ' # every ` · ` is the sep mark: the ASCII frame stays seven-bit
4375
+ self.clock_sig = self.clock_signature(entries, now) # C7: what time changes in this frame (poll_clock)
4153
4376
  for index in range(self.top, self.top + body):
4154
4377
  if index >= len(entries):
4155
4378
  for _ in range(self.entry_height):
@@ -4222,15 +4445,13 @@ class Sidebar:
4222
4445
  detail = {'new-shell': 'Create a persistent shell', 'register-workspace': 'Add this session',
4223
4446
  'cancel-registration': 'Keep unregistered'}.get(entry['action'], '')
4224
4447
  elif status and status != 'shell':
4225
- since = agent.get('since')
4226
- age = age3(now - since if isinstance(since, (int, float)) and since > 0 else None).strip()
4448
+ age = phone_age(observed, now)
4227
4449
  harness = OSC_UNSAFE.sub('', str(agent.get('harness') or ''))
4228
4450
  label = MOBILE_ACTIVITY_LABELS.get(agent.get('activity')) if status == 'working' else None
4229
4451
  detail = sep.join(part for part in (label or MOBILE_AGENT_LABELS[status], age, harness) if part)
4230
4452
  task = OSC_UNSAFE.sub('', str(agent.get('name') or ''))
4231
4453
  else:
4232
- activity = observed.get('activity')
4233
- age = age3(now - activity if isinstance(activity, (int, float)) and activity > 0 else None).strip()
4454
+ age = phone_age(observed, now)
4234
4455
  detail = sep.join(part for part in (MOBILE_LABELS.get(lane_state, lane_state), age) if part)
4235
4456
  if stale:
4236
4457
  detail += sep + 'status delayed'
@@ -4702,6 +4923,7 @@ class Sidebar:
4702
4923
  self.poll_update()
4703
4924
  self.poll_economy()
4704
4925
  self.poll_fleet() # W11: the fleet block's facts turning stale (no I/O)
4926
+ self.poll_clock() # C7: the age column on the shared directory (no I/O)
4705
4927
  # An upload in flight no longer forces a frame: poll_upload() dirties on progress and on the end.
4706
4928
  if self.armed or (self.upload_note and time.time() - self.upload_note_at < 9):
4707
4929
  self.dirty = True