@vibelord/lanes 1.7.3 → 1.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/package.json +1 -1
- package/payload/lanes/VERSION +1 -1
- package/payload/lanes/bin/lanes +128 -24
- package/payload/lanes/bin/lanes-site-serve +15 -0
- package/payload/lanes/bin-rs/BINARIES.json +5 -0
- package/payload/lanes/container/lane-mcp +108 -5
- package/payload/lanes/container/lane_core.py +116 -0
- package/payload/lanes/container/throttle-pulse +159 -14
- package/payload/lanes/docs/ARCHITECTURE.md +132 -13
- package/payload/lanes/docs/DESIGN.md +10 -8
- package/payload/lanes/docs/INSTALL.md +1 -1
- package/payload/lanes/docs/RUNBOOK.md +436 -8
- package/payload/lanes/docs/USERGUIDE.md +82 -9
- package/payload/lanes/install/host-install.sh +35 -4
- package/payload/lanes/libexec/adopt.py +364 -0
- package/payload/lanes/libexec/attach.py +35 -5
- package/payload/lanes/libexec/cutover.py +656 -0
- package/payload/lanes/libexec/docsd.py +12 -8
- package/payload/lanes/libexec/doctor_lanes2.py +284 -0
- package/payload/lanes/libexec/economy_poll.py +87 -2
- package/payload/lanes/libexec/gc_unregistered.py +407 -0
- package/payload/lanes/libexec/lanes_lib.py +474 -2
- package/payload/lanes/libexec/native.sh +38 -0
- package/payload/lanes/libexec/native_bin.py +670 -0
- package/payload/lanes/libexec/session_actions.py +85 -7
- package/payload/lanes/libexec/shadow.py +1311 -0
- package/payload/lanes/libexec/sidebar.py +252 -30
- package/payload/lanes/libexec/sidebar_status.py +373 -25
- package/payload/lanes/libexec/statusd.py +67 -3
- package/payload/lanes/libexec/tokens.py +99 -131
- package/payload/lanes/libexec/tokens.sh +1 -1
- package/payload/lanes/libexec/update.py +78 -8
- package/payload/lanes/libexec/users.py +282 -0
- package/payload/lanes/site/README.md +9 -0
- package/payload/lanes/site/conformance.py +280 -0
- package/payload/lanes/site/protocol.py +368 -0
- package/payload/lanes/site/server.py +314 -0
- package/payload/lanes/systemd/lanes-gc.service +1 -1
- package/payload/lanes/systemd/lanes-gc.timer +14 -3
- package/payload/lanes/tokens/README.md +156 -0
- package/payload/lanes/tokens/generate.py +930 -0
- package/payload/lanes/tokens/generated/parity.v1.tsv +489 -0
- package/payload/lanes/tokens/generated/tokens.resolved.json +835 -0
- package/payload/lanes/tokens/tokens.v1.json +763 -0
- package/payload/lanes/tokens/tokens.v1.schema.json +143 -0
- package/payload/lanes/web/Caddyfile +11 -0
- package/payload/lanes/web/README.md +253 -4
- package/payload/lanes/web/directory.css +95 -0
- package/payload/lanes/web/directory.js +951 -0
- package/payload/lanes/web/generated/README.md +107 -0
- package/payload/lanes/web/generated/lanes2_protocol.d.mts +1162 -0
- package/payload/lanes/web/generated/lanes2_protocol.mjs +2333 -0
- package/payload/lanes/web/inbox.js +1140 -0
- package/payload/lanes/web/mobile.js +35 -45
- package/payload/lanes/web/tokens.css +137 -0
- package/payload/manifest.json +7 -4
|
@@ -1790,7 +1790,10 @@ Paths, receipts and the log: [RUNBOOK](RUNBOOK.md#messages-inboxes-receipts-and-
|
|
|
1790
1790
|
not counted; `shell` stays 0 in practice: a lane whose harness ended into its shell is published under that
|
|
1791
1791
|
harness's name with the status `shell`); lanes per create-recipe class (`idempotent`, `attach-only`, `null`, `external`, `retired-path`), how many
|
|
1792
1792
|
create with their identity, where the `lane` contract is installed, zmx-held lanes, the preview renderer, the live
|
|
1793
|
-
view sessions,
|
|
1793
|
+
view sessions, the unregistered sweep (`gc unregistered: off (LANES_GC_UNREGISTERED unset)`, or `on, idle ≥ 6h,
|
|
1794
|
+
last sweep … : ended N`, `(by hand)` after the time unless the timer ran it; `⚠` for an idle floor it refuses, or a
|
|
1795
|
+
`LANES_GC_` line with a comment, quote or space after its value, named —
|
|
1796
|
+
[Daily cleanup of unregistered terminals](#daily-cleanup-of-unregistered-terminals)), and the pressure summary.
|
|
1794
1797
|
- Addresses ([Addresses, coordinators and the fleet admin](#addresses-coordinators-and-the-fleet-admin)): `⚠ 2 of 14
|
|
1795
1798
|
boards without a coordinator: …` (fix: `lanes migrate addresses --write` or `lanes address set-coordinator`),
|
|
1796
1799
|
`✓ lane addresses unique` (`✗` naming the two lanes of each clash: `lanes sync` refuses the site until one has
|
|
@@ -2450,11 +2453,16 @@ systemctl --user enable --now lanes-notify.service
|
|
|
2450
2453
|
|
|
2451
2454
|
## 9. Appearance
|
|
2452
2455
|
|
|
2453
|
-
One token
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2456
|
+
One token source, `tokens/tokens.v1.json`, defines every colour and glyph ([`tokens/README.md`](../tokens/README.md)).
|
|
2457
|
+
Edit it, never a generated file. `python3 tokens/generate.py --write` regenerates everything derived from it: the
|
|
2458
|
+
resolved table `libexec/tokens.py` reads, the browser's `web/tokens.css`, the Rust and Swift tokens (in a repository
|
|
2459
|
+
checkout only), and the marked blocks in `zellij/config.kdl` (the `lanes-dark` / `lanes-light` themes and the web
|
|
2460
|
+
client palette), `web/mobile.css`, `web/mobile.js`, `libexec/tokens.sh` (the viewer's status screens),
|
|
2461
|
+
`docs/DESIGN.md` and the optional Ghostty palette files. `python3 tokens/generate.py --check` fails on drift (in an
|
|
2462
|
+
installed tree it compares the files inside `lanes/` only); `python3 libexec/tokens.py --check` covers the marked
|
|
2463
|
+
blocks and the generated files inside `lanes/`. `tokens.py` is the reader: `--kdl`, `--css`, `--sh`, `--md`, `--js`,
|
|
2464
|
+
`--ghostty-dark` and `--ghostty-light` print one block, and its own `--write` only re-splices the marked blocks from the
|
|
2465
|
+
generated table, so a source edit needs `generate.py --write`.
|
|
2458
2466
|
|
|
2459
2467
|
| Switch | Values | Default |
|
|
2460
2468
|
| --- | --- | --- |
|
|
@@ -2558,7 +2566,7 @@ All units run in `lanes.slice` and are rendered by the server installer from `la
|
|
|
2558
2566
|
| `lanes-statusd.service` | Always on | Server install | Observes every lane; writes `status.json` and `health`; hot-sync; types only `/rename <address>` into an idle Claude lane whose session name is not its address, with no terminal attached (at most two a pass, each lane at most once per 120 s; `LANES_NAMES_AUTO=0` in site.conf turns it off) |
|
|
2559
2567
|
| `lanes-sync.timer` / `.service` | Every 2 min | Server install | `lanes sync` |
|
|
2560
2568
|
| `lanes-ensure.timer` / `.service` | Every 1 min | Server install | `lanes ensure`: recreate missing device view sessions; rebuild a view an update left once no client is attached |
|
|
2561
|
-
| `lanes-gc.timer` / `.service` | Daily | Server install | `lanes gc`: truncate zmx logs over 5 MB, drop stale dynamic resolve files, prune old npm-staged trees — each folder keeps its 3 newest and every older tree `current`, `current.previous`, a view layout, a running daemon's run record or a process of this account uses; none when `/proc` cannot be read ([INSTALL](INSTALL.md#6-updates-optional-operations-and-removal)) |
|
|
2569
|
+
| `lanes-gc.timer` / `.service` | Daily at midnight, host time (+0–5 min; a midnight the host missed runs once at the next boot) | Server install | `lanes gc`: truncate zmx logs over 5 MB, drop stale dynamic resolve files, prune old npm-staged trees — each folder keeps its 3 newest and every older tree `current`, `current.previous`, a view layout, a running daemon's run record or a process of this account uses; none when `/proc` cannot be read ([INSTALL](INSTALL.md#6-updates-optional-operations-and-removal)); then, only with `LANES_GC_UNREGISTERED=1` in site.conf, end the unregistered sessions in which nothing runs ([Daily cleanup of unregistered terminals](#daily-cleanup-of-unregistered-terminals)) |
|
|
2562
2570
|
| `lanes-update.timer` / `.service` | 15 min after boot, then every 30 min (+0–5 min) | Server install (the full one: `--update-only` enables nothing — `systemctl --user enable --now lanes-update.timer` on a server set up before 1.2.0) | `lanes update --timer`: install the newest npm release when it is newer ([Update](#update)); a checkout server is left alone; stopped after 1 h |
|
|
2563
2571
|
| `lanes-enrold.service` | Always on | Server install (enabled and restarted by every one) | Enrolment service on `127.0.0.1:8184`, reached as `https://<host>:8443/enrol/*`: invite redemption, enrolment requests, `/enrol/pending` approvals ([RUNBOOK](RUNBOOK.md#enrolment-service-lanes-enrold-w8-a3)) |
|
|
2564
2572
|
| `lanes-docsd.service` | Always on | Server install (enabled and restarted by every one) | Docs service on `127.0.0.1:8185`, reached as `https://<host>:8443/lanes-docs/`: login-bound documents, sandboxed artifacts and uploads with receipts; refuses every request until `lanes enrol mode request` is pinned ([RUNBOOK](RUNBOOK.md#docs-service-lanes-docsd-w10-w3)) |
|
|
@@ -2635,7 +2643,8 @@ Clients also get `lanes-helper.service` and `lanes-upload.path`/`.service` (Linu
|
|
|
2635
2643
|
| Health | `lanes pressure` | Memory / io / cpu pressure, swap, per-container memory and `/tmp`; plain files only; exit 1 unless ok |
|
|
2636
2644
|
| Health | `lanes invariant save\|check` | Snapshot / verify every live pane's pid and window size |
|
|
2637
2645
|
| Health | `lanes sockets [check\|repair]` | tmux servers whose socket file was deleted; `repair` sends tmux's SIGUSR1, nothing restarts |
|
|
2638
|
-
| Housekeeping | `lanes gc` | What the daily timer runs |
|
|
2646
|
+
| Housekeeping | `lanes gc` | What the daily timer runs (at midnight) |
|
|
2647
|
+
| Housekeeping | `lanes gc --unregistered [--write] [--board B]` | One line per unregistered session: `reap: <why>` only on evidence that nothing runs in it, `keep: <why>` for every other one; `--write` ends the reap lines' sessions ([Daily cleanup of unregistered terminals](#daily-cleanup-of-unregistered-terminals)) |
|
|
2639
2648
|
| Housekeeping | `lanes tmp scan\|plan\|apply\|reap\|caches [container…] [--approve] [--home]` | What fills the containers' RAM-backed `/tmp`, and removing the dead part ([RUNBOOK](RUNBOOK.md#free-the-ram-lanes-tmp)) |
|
|
2640
2649
|
| Housekeeping | `lanes guard [--dry-run] [container…]` | One OOM-guard pass by hand |
|
|
2641
2650
|
| Throttle | `lanes economy --once [--dry-run] [--status-file F --sessions-file F]` | One economy poll (section 8) |
|
|
@@ -2666,6 +2675,7 @@ Server (`~/.local/state/lanes/`, `$LANES_STATE`):
|
|
|
2666
2675
|
| --- | --- |
|
|
2667
2676
|
| `registry.json`, `registry.synced`, `resolve/`, `resolve.dynamic/` | The published registry, the last sync time, per-lane targets |
|
|
2668
2677
|
| `status.json`, `health` | statusd's snapshot and the one-line health record |
|
|
2678
|
+
| `gc-unregistered.json` | The last write run of the unregistered sweep (`lanes gc` with the policy on, or `lanes gc --unregistered --write`): when, by the timer or by hand, the idle floor, and how many sessions it ended, could not end and kept; `lanes doctor` shows it |
|
|
2669
2679
|
| `run/<name>.tree` | The tree each long-running process started from — `statusd`, `enrold`, `docsd`, `economy`, `notify`, `studio_host` (the enable step its enrolment timer runs) and `sidebar` (the most recently started one): one resolved path, rewritten at every start, so a record that differs from where `~/.local/share/lanes/current` points is a process still running an older version |
|
|
2670
2680
|
| `containers.json`, `containers/` | Container init pids and home volumes |
|
|
2671
2681
|
| `devices/<device>.json` | Each known device: layout, viewports, base device, owner, look (colour, theme, glyphs, dim; `device_only` lists the keys `--device-only` kept for this device alone), desktop notifications on/off and the quick-edit editor |
|
|
@@ -2678,7 +2688,7 @@ Server (`~/.local/state/lanes/`, `$LANES_STATE`):
|
|
|
2678
2688
|
| `upload-requests/<device>/` | Upload hand-off between sidebar and helper |
|
|
2679
2689
|
| `economy.json`, `economy.cursor.json` | The opt-in economy projection and its log cursor |
|
|
2680
2690
|
| `notify.enrol-seen.json` | The enrolment requests the opt-in push notifier already announced (0600, pruned to the requests on disk); deleting it announces the ones still pending once more |
|
|
2681
|
-
| `flags/` | `coexist`, `readonly`, `tmpreap.armed`, `sockets-lost` |
|
|
2691
|
+
| `flags/` | `coexist`, `readonly`, `tmpreap.armed`, `sockets-lost`; Lanes 2.0's `native.<component>` (`on`) and `native.<component>.shadow` (`shadow`): empty files `lanes rs apply` writes from `site.conf`'s `LANES_RS_<COMPONENT>` for a verified native binary only, removed otherwise (RUNBOOK, "Lanes 2.0 native binaries and flags") |
|
|
2682
2692
|
| `cursor-sync-backups/` | Backups taken by `cursor-sync --write` |
|
|
2683
2693
|
| `migrations/<UTC stamp>/` | One directory per `lanes migrate addresses --write` (0700): a copy of each file it changed as it was (`<NN>-<file name>`, 0600) and `receipt.json` (`{v, verb, at, board, files: [{path, backup, change, sha256_before, sha256_after}]}`) |
|
|
2684
2694
|
| `invariant.json` | `lanes invariant save` |
|
|
@@ -2722,6 +2732,69 @@ Client: `~/.config/lanes/` (`device`, `install-options`, `ghostty.conf`, `client
|
|
|
2722
2732
|
`~/.local/state/lanes-client/` (`launch-<target>.log`, `helper.alive`, `helper-service.log`, `checked` — the time of a
|
|
2723
2733
|
window's last update question — and `checking/` while one asks), `~/.local/share/lanes/client/`.
|
|
2724
2734
|
|
|
2735
|
+
### Daily cleanup of unregistered terminals
|
|
2736
|
+
|
|
2737
|
+
Ending a lane is a person's call: `x` in the sidebar, one session at a time. A site whose operator wants the
|
|
2738
|
+
unregistered terminals in which nothing runs gone without asking each time can say so once, in the server's
|
|
2739
|
+
`~/.config/lanes/site.conf`:
|
|
2740
|
+
|
|
2741
|
+
```sh
|
|
2742
|
+
# The daily lanes gc (midnight) ends the unregistered sessions in which nothing runs.
|
|
2743
|
+
LANES_GC_UNREGISTERED=1
|
|
2744
|
+
# Optional: how long a session must have shown no output, in seconds (default 21600 = 6 h, at least 3600).
|
|
2745
|
+
LANES_GC_IDLE_S=21600
|
|
2746
|
+
```
|
|
2747
|
+
|
|
2748
|
+
Each setting is `KEY=VALUE` alone on its line, with comments on lines of their own: a `LANES_GC_` line with anything
|
|
2749
|
+
after its value (a comment, quotes, a space) is refused rather than read as unset — the sweep then ends nothing, and
|
|
2750
|
+
`lanes doctor` names the line with a `⚠`.
|
|
2751
|
+
|
|
2752
|
+
Only **unregistered** sessions are ever considered: the tmux sessions a board lists under **Unregistered** —
|
|
2753
|
+
unregistered, including a lane a person unregistered while it ran (`u`, `lanes unregister`). A registered lane is
|
|
2754
|
+
never ended, however idle. A session is ended only on **positive evidence that nothing runs in it**:
|
|
2755
|
+
|
|
2756
|
+
- its agent's status is `shell` (the harness ended into its shell), or it has no agent and its pane runs a bare shell
|
|
2757
|
+
(`bash`, `zsh`, `sh`, …), or its pane is dead; and
|
|
2758
|
+
- just before it is ended, a look at every pane of every window of the session finds each one dead, or a bare shell
|
|
2759
|
+
with no process under it; and
|
|
2760
|
+
- it showed no output for at least `LANES_GC_IDLE_S`, no terminal is attached to it, no Studio browser views it,
|
|
2761
|
+
statusd observed it within the last 30 s, and this server reaches its container itself.
|
|
2762
|
+
|
|
2763
|
+
Every other session is kept: an agent that is errored, done, waiting for you (`needs_input`, `needs_approval`),
|
|
2764
|
+
working, or idle at its prompt (every harness prompt stays until a person opens the lane), or a status the sweep does
|
|
2765
|
+
not know; a pane that runs anything but a bare shell (`keep: runs vim`, or `keep: runs claude` for a Claude in another
|
|
2766
|
+
window); a session statusd could not observe (no evidence is never "idle"); a container behind a guest (that guest's
|
|
2767
|
+
own Lanes sweeps it). A session is ended the way the sidebar's `x` ends it, in an unattended mode: the exact session
|
|
2768
|
+
(its tmux id and creation time, checked inside tmux), never while a Studio browser views it, and never a view's own
|
|
2769
|
+
session. An attach statusd has published keeps the session, and the kill itself refuses while a client is attached:
|
|
2770
|
+
tmux checks that inside the same command as the kill, so someone who attaches a second before keeps it too.
|
|
2771
|
+
|
|
2772
|
+
**Look first.** `lanes gc --unregistered` is the dry run, with or without the switch: one line per session, the
|
|
2773
|
+
decision and why, and nothing ended (it also looks at the panes of each session it would end, read-only, so it says
|
|
2774
|
+
what a write would do).
|
|
2775
|
+
|
|
2776
|
+
```text
|
|
2777
|
+
gc unregistered: off (LANES_GC_UNREGISTERED unset), idle ≥ 6h — dry run: --write ends each reap
|
|
2778
|
+
keep: attached — work--x-scratch-3f2a91c0d4 (work lanes-shells-work/scratch)
|
|
2779
|
+
keep: agent needs_input — work--x-review-8b7e6d5c4a (work lanes-shells-work/review)
|
|
2780
|
+
keep: runs vim — work--x-notes-2c3d4e5f6a (work lanes-shells-work/notes)
|
|
2781
|
+
keep: active 12m ago — work--x-build-1a2b3c4d5e (work lanes-shells-work/build)
|
|
2782
|
+
reap: idle 7h, no agent, no client — work--x-old-9f8e7d6c5b (work lanes-shells-work/old)
|
|
2783
|
+
gc unregistered: 1 to end, 4 kept — lanes gc --unregistered --write ends them
|
|
2784
|
+
```
|
|
2785
|
+
|
|
2786
|
+
`--board B` looks at one board's sessions. `lanes gc --unregistered --write` ends the `reap` lines' sessions now, by
|
|
2787
|
+
hand. Each is judged again just before closing. A new client, grouped viewer or
|
|
2788
|
+
new output on any window keeps the session even before the status display catches
|
|
2789
|
+
up; cleanup never closes a viewer to make a session eligible. With the switch
|
|
2790
|
+
on, the midnight `lanes gc` does the same after its other housekeeping; its lines are in
|
|
2791
|
+
`journalctl --user -u lanes-gc.service`, and `lanes doctor` names the last run:
|
|
2792
|
+
`gc unregistered: on, idle ≥ 6h, last sweep 2026-11-02 00:03 UTC: ended 1` (with `(by hand)` after the time when a
|
|
2793
|
+
person ran it rather than the timer). Turn it off by removing the line or setting `LANES_GC_UNREGISTERED=0`.
|
|
2794
|
+
[inferred, not measured: on a host whose timer was the earlier boot-relative one, the update that moves it to midnight
|
|
2795
|
+
may run one `lanes gc` at once, because systemd counts a missed calendar run from the timer's last trigger; that sweep
|
|
2796
|
+
ends only what a midnight one would.]
|
|
2797
|
+
|
|
2725
2798
|
### NEVER
|
|
2726
2799
|
|
|
2727
2800
|
From the [RUNBOOK](RUNBOOK.md#never):
|
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
# pre-commit preflight (prerequisites, the user manager, Docker, an installed release: an update restarts what the
|
|
7
7
|
# full install enabled and enables nothing, so with no `current` it is refused), the pinned binaries
|
|
8
8
|
# (sha256), terminfo, the catalog: a failure here leaves the installed release running exactly as it was;
|
|
9
|
-
# commit
|
|
9
|
+
# commit Lanes 2.0's native binaries of this tree against its bin-rs/BINARIES.json (libexec/native_bin.py
|
|
10
|
+
# verify-tree: a binary unlisted, not executable or with other bytes is refused, exit 3, and nothing
|
|
11
|
+
# changes), every flags/native.* file this tree does not admit removed, then install/services.py
|
|
12
|
+
# --install: every unit, then current.previous, then the flip of `current` (W9 U1);
|
|
10
13
|
# post-commit libexec/update.py post-commit, from the tree just installed: daemon-reload, `lanes sync`, restart
|
|
11
14
|
# lanes-statusd, try-restart each optional service (right after lanes-docsd's, install/enable-docs.sh:
|
|
12
15
|
# the docs page's pinned Mermaid, a warning when it is skipped or refused, W10 W8), `lanes
|
|
@@ -92,8 +95,9 @@ phase() {
|
|
|
92
95
|
phase=$1
|
|
93
96
|
}
|
|
94
97
|
# --update-only, before the commit: whatever ends the run is recorded (`set -e`, an `exit`, a signal). refused: the
|
|
95
|
-
# preflight (no installed release among its checks), or
|
|
96
|
-
#
|
|
98
|
+
# preflight (no installed release among its checks), or in the commit phase native_bin.py verify-tree's refusal (exit
|
|
99
|
+
# 3: a native binary that does not verify) or install/services.py's (exit 3: another install holds its lock, a link
|
|
100
|
+
# that is no symlink);
|
|
97
101
|
# failed: anything else — unless the flip happened before services.py failed (its command link), which is installed
|
|
98
102
|
# but not restarted: partial. After the commit the post-commit records its own outcome.
|
|
99
103
|
update_ended() {
|
|
@@ -168,7 +172,27 @@ check_docs_age
|
|
|
168
172
|
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
|
|
169
173
|
if [ "$start" = 1 ]; then
|
|
170
174
|
systemctl --user show-environment >/dev/null
|
|
171
|
-
|
|
175
|
+
# An update of an aggregator — a host whose boards all run behind guests (lanes-site/1, docs/RUNBOOK.md
|
|
176
|
+
# "Federation") — needs no docker daemon of its own: when `docker info` is refused and `lanes sync` recorded no
|
|
177
|
+
# local container with a home volume, the update goes on with a warning. A full install, and an update of a host
|
|
178
|
+
# with local containers, still refuse: install-container and the pulse need docker there.
|
|
179
|
+
if ! python3 -c 'import subprocess; subprocess.run(["docker", "info", "--format", "{{.ServerVersion}}"], check=True, timeout=15)'; then
|
|
180
|
+
[ "$update_only" = 1 ] || exit 1
|
|
181
|
+
python3 - "$state/containers.json" <<'PY' || exit 1
|
|
182
|
+
import json, sys
|
|
183
|
+
try:
|
|
184
|
+
recorded = json.load(open(sys.argv[1]))
|
|
185
|
+
except (OSError, ValueError):
|
|
186
|
+
sys.exit(1)
|
|
187
|
+
# A failed inspect has no home either: absence of an answer is not evidence
|
|
188
|
+
# that this host needs no Docker. Malformed records also fail closed (BEY-7140).
|
|
189
|
+
local = sorted(name for name, info in recorded.items()
|
|
190
|
+
if not isinstance(info, dict) or info.get('error') or info.get('home')) \
|
|
191
|
+
if isinstance(recorded, dict) else None
|
|
192
|
+
sys.exit(0 if local == [] else 1)
|
|
193
|
+
PY
|
|
194
|
+
printf 'WARN docker info was refused; no local container is recorded (an aggregator): the update goes on without it\n' >&3
|
|
195
|
+
fi
|
|
172
196
|
fi
|
|
173
197
|
if [ "$check" = 1 ]; then
|
|
174
198
|
echo 'Server prerequisites: ready'
|
|
@@ -218,6 +242,13 @@ if [ ! -e "$catalog" ] && [ ! -d "$repo/workspaces" ] && [ -z "${LANES_WORKSPACE
|
|
|
218
242
|
printf '{"version":1,"workspaces":[]}\n' > "$catalog"
|
|
219
243
|
fi
|
|
220
244
|
phase commit
|
|
245
|
+
# Lanes 2.0 native binaries (lanes2 Round 1 H2; AR 9.3, D9), right before the flip: this tree's bin-rs/ against its
|
|
246
|
+
# BINARIES.json (a full install too). A binary that is unlisted, not executable or has other bytes than its digest is
|
|
247
|
+
# refused (exit 3: an update records `refused`, and the installed release keeps running exactly as it was), so
|
|
248
|
+
# `current` never names a tree whose binaries nobody verified. Then every flags/native.* file this tree does not admit
|
|
249
|
+
# is removed (a component whose binary it no longer ships returns to Python), so after the flip each shell reader that
|
|
250
|
+
# finds a flag runs a binary that was checked. A tree without binaries passes and prunes only those flags.
|
|
251
|
+
python3 "$repo/libexec/native_bin.py" verify-tree "$repo" --state "$state" --prune-flags
|
|
221
252
|
# --install: the server installer is the one caller that makes its own tree the installed release (`current`);
|
|
222
253
|
# the enable steps re-render the release `current` names (install/services.py, DEF-1835).
|
|
223
254
|
python3 "$repo/install/services.py" --install
|
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""adopt.py — installed adoption of the Lanes 2.0 store (lanes2 Round 2 S12; Rust runtime specification §17.1, the
|
|
3
|
+
adoption half; P32; BEY-6988). Python 3 stdlib.
|
|
4
|
+
|
|
5
|
+
python3 libexec/adopt.py adopt [--state DIR] [--tree DIR] [--json] adopt every domain; exit 0 every domain adopted,
|
|
6
|
+
3 a domain refused, 4 an I/O failure, 2 usage
|
|
7
|
+
(1 is never ours: Python's own crash status)
|
|
8
|
+
python3 libexec/adopt.py status [--state DIR] [--json] what is adopted, verified on disk; exit 0 every
|
|
9
|
+
domain verified, 3 otherwise (or none adopted)
|
|
10
|
+
python3 libexec/adopt.py doctor [--state DIR] `lanes doctor`'s lines (doctor_lines)
|
|
11
|
+
|
|
12
|
+
WHAT ADOPTION IS. An existing 1.x install gains the Lanes 2.0 state layout without a manual step: `lanes update`'s
|
|
13
|
+
post-commit runs `adopt` from the tree it just installed (update.py ADOPT_STEP), on every update, idempotently. For
|
|
14
|
+
every state domain of DOMAINS it makes sure the domain's cutover record exists (DM-LANES2-CUTOVER-RECORD,
|
|
15
|
+
`$LANES_STATE/cutover/<domain>.json`, written through cutover.py's compare-and-swap writer): a domain without one gets
|
|
16
|
+
exactly the record the Rust fence would create on its first open (`DomainFence::open`): phase `shadow`, epoch 1, owner
|
|
17
|
+
`lanes-py`, no previous owner, schema 1, nothing fenced. A domain that already has a record keeps it untouched, whatever
|
|
18
|
+
its phase or owner (a cutover in progress, a domain a Rust owner took): adoption never moves ownership. It creates the
|
|
19
|
+
store's directory `$LANES_STATE/store/` (0700) and never the store itself: the host coordinator's store owner creates
|
|
20
|
+
`coordination.sqlite` and migrates it on its first open (lane B3; a second migrator would be a second schema
|
|
21
|
+
authority). Last, it writes the adoption record `$LANES_STATE/lanes2/adoption.json` (`lanes2.adoption/1`, 0600):
|
|
22
|
+
|
|
23
|
+
{"v": 1, "kind": "lanes2.adoption/1", "adopted_at": "<UTC>", "release": "<tree VERSION>",
|
|
24
|
+
"store": "<state>/store/coordination.sqlite", "domains": [<every domain verified>],
|
|
25
|
+
"refused": [{"domain": D, "code": C}]}
|
|
26
|
+
|
|
27
|
+
`domains` lists a domain only after its record was read back from disk and parsed (verify_domain): a domain whose
|
|
28
|
+
write failed or was skipped is never reported adopted, and `refused` names it with its code (`record_malformed`,
|
|
29
|
+
`record_unreadable`, `journal_conflict`, `record_missing`, ...).
|
|
30
|
+
|
|
31
|
+
WHAT IT NEVER DOES. No flag: `$LANES_STATE/flags/native.*` and site.conf's `LANES_RS_*` keys are lane H2's and stay as
|
|
32
|
+
they are (every component off); no unit, no daemon, no import of legacy data (a domain's records are imported by its
|
|
33
|
+
cutover fence, RT 17.1, never by adoption); no Rust binary is run. With the records owned by `lanes-py`, a Rust host
|
|
34
|
+
that recovers (crates/lanes-runtime/src/recovery) comes up fenced, read-only, until a domain's cutover activates it.
|
|
35
|
+
|
|
36
|
+
DOCTOR. doctor_lines(state) -> [(mark, text)] in `lanes doctor`'s protocol: nothing before the first adoption; then one
|
|
37
|
+
information line for the store and the flags, and one line per domain of DOMAINS: ✓ adopted (phase, owner, epoch and
|
|
38
|
+
where its 1.x owner keeps it), ⚠ a fence in progress or interrupted (a phase between quiesced and epoch_committed), ⚠
|
|
39
|
+
not adopted yet (a refusal's code, or a domain a newer release added), ✗ listed as adopted but its record is missing
|
|
40
|
+
or unreadable.
|
|
41
|
+
"""
|
|
42
|
+
import argparse
|
|
43
|
+
import json
|
|
44
|
+
import os
|
|
45
|
+
import stat
|
|
46
|
+
import sys
|
|
47
|
+
import time
|
|
48
|
+
from pathlib import Path
|
|
49
|
+
|
|
50
|
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
51
|
+
import cutover # noqa: E402 (H3's record format and writer: the one journal of record)
|
|
52
|
+
|
|
53
|
+
KIND = 'lanes2.adoption/1'
|
|
54
|
+
LEGACY_OWNER = cutover.LEGACY_OWNER # 'lanes-py'
|
|
55
|
+
LEGACY_SCHEMA = 1 # the schema epoch the Python owner reads
|
|
56
|
+
ADOPTION = Path('lanes2') / 'adoption.json' # under $LANES_STATE
|
|
57
|
+
STORE_DIR = Path('store') # under $LANES_STATE (AR 4.4)
|
|
58
|
+
STORE_FILE = 'coordination.sqlite'
|
|
59
|
+
# Exit 1 is what Python itself returns for an uncaught exception (an import or syntax failure in a broken tree), so
|
|
60
|
+
# the adopter never uses it: update.py keeps 3 and 4 as warnings and a crash (1) as a failure (WARN_RC).
|
|
61
|
+
EXIT_USAGE, EXIT_REFUSED, EXIT_IO = 2, 3, 4
|
|
62
|
+
ADOPTION_MAX = 64 * 1024
|
|
63
|
+
# The Lanes 2.0 state domains (RT 6.2 "the store includes ..." and the Round-2 slices), each with what it holds and
|
|
64
|
+
# where its 1.x owner keeps it. Order is doctor order.
|
|
65
|
+
DOMAINS = (
|
|
66
|
+
('owner-epochs', 'workspace owner epochs', 'none in 1.x: one host owns its workspaces'),
|
|
67
|
+
('bindings', 'native-generation bindings', 'registry.json and resolve/ (lanes sync)'),
|
|
68
|
+
('receipts', 'command receipts', 'none in 1.x'),
|
|
69
|
+
('attention', 'prompt and answer state', 'status.json and the containers\' .sent markers (statusd)'),
|
|
70
|
+
('effects', 'external effects', 'the containers\' .sent markers'),
|
|
71
|
+
('inbox-outbox', 'inbox and outbox records', 'the containers\' ~/.lz/state/inbox'),
|
|
72
|
+
('projects', 'project and work claims', 'none in 1.x'),
|
|
73
|
+
('schedules', 'schedule occurrences', 'none in 1.x'),
|
|
74
|
+
('connectors', 'connector cursors', 'none in 1.x'),
|
|
75
|
+
('projections', 'projection checkpoints', 'sidebar-status/ and status.json (statusd)'),
|
|
76
|
+
('preferences', 'presentation preferences', 'users/<login>.json'),
|
|
77
|
+
('builds', 'build references', 'none in 1.x: buildctl owns the jobs'),
|
|
78
|
+
('notify', 'notification groups', 'notify.enrol-seen.json (lanes-notify)'),
|
|
79
|
+
('drafts', 'retained drafts', 'none in 1.x'),
|
|
80
|
+
)
|
|
81
|
+
DOMAIN_NAMES = tuple(name for name, _, _ in DOMAINS)
|
|
82
|
+
FENCED_PHASES = frozenset({'quiesced', 'drained', 'cut_verified', 'epoch_committed'})
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def default_state():
|
|
86
|
+
return Path(os.environ.get('LANES_STATE') or Path.home() / '.local/state/lanes')
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def utc(at=None):
|
|
90
|
+
return time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(at))
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def tree_release(tree):
|
|
94
|
+
"""The VERSION of `tree`, or '' when it has none."""
|
|
95
|
+
try:
|
|
96
|
+
return (Path(tree) / 'VERSION').read_text().strip()[:64]
|
|
97
|
+
except (OSError, UnicodeDecodeError):
|
|
98
|
+
return ''
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def initial_record(domain):
|
|
102
|
+
"""The record DomainFence::open creates for a domain the legacy owner holds (cutover/fence.rs `open`)."""
|
|
103
|
+
return {'v': 1, 'kind': cutover.KIND, 'domain': domain, 'phase': 'shadow', 'epoch': 1, 'owner': LEGACY_OWNER,
|
|
104
|
+
'previous': None, 'schema': LEGACY_SCHEMA, 'fenced_through': None}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def ensure_record(state, domain):
|
|
108
|
+
"""The domain's record after making sure one exists: an existing one untouched, else the initial one written by
|
|
109
|
+
compare-and-swap from 'no record' (a writer that got there first wins and its record is kept). Raises
|
|
110
|
+
cutover.Refused for an unreadable or malformed record, OSError for an I/O failure."""
|
|
111
|
+
current = cutover.read_record(state, domain)
|
|
112
|
+
if current is not None:
|
|
113
|
+
return current
|
|
114
|
+
try:
|
|
115
|
+
return cutover.write_record(state, initial_record(domain), None)
|
|
116
|
+
except cutover.Refused as refused:
|
|
117
|
+
if refused.code != 'journal_conflict':
|
|
118
|
+
raise
|
|
119
|
+
return cutover.read_record(state, domain)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def verify_domain(state, domain):
|
|
123
|
+
"""(record, None) when the domain's record is on disk and canonical, else (None, code)."""
|
|
124
|
+
try:
|
|
125
|
+
record = cutover.read_record(state, domain)
|
|
126
|
+
except cutover.Refused as refused:
|
|
127
|
+
return None, refused.code
|
|
128
|
+
except OSError:
|
|
129
|
+
return None, 'record_unreadable'
|
|
130
|
+
if record is None:
|
|
131
|
+
return None, 'record_missing'
|
|
132
|
+
return record, None
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _private_dir(path):
|
|
136
|
+
path = Path(path)
|
|
137
|
+
path.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
138
|
+
if not stat.S_ISDIR(os.lstat(path).st_mode):
|
|
139
|
+
raise OSError(f'{path} is not a directory')
|
|
140
|
+
return path
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _atomic_write(path, text):
|
|
144
|
+
path = Path(path)
|
|
145
|
+
temp = path.with_name(f'.{path.name}.{os.getpid()}.tmp')
|
|
146
|
+
fd = os.open(temp, os.O_WRONLY | os.O_CREAT | os.O_TRUNC | os.O_NOFOLLOW, 0o600)
|
|
147
|
+
try:
|
|
148
|
+
with os.fdopen(fd, 'w') as handle:
|
|
149
|
+
handle.write(text)
|
|
150
|
+
handle.flush()
|
|
151
|
+
os.fsync(handle.fileno())
|
|
152
|
+
os.replace(temp, path)
|
|
153
|
+
except BaseException:
|
|
154
|
+
try:
|
|
155
|
+
os.unlink(temp)
|
|
156
|
+
except OSError:
|
|
157
|
+
pass
|
|
158
|
+
raise
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def store_path(state):
|
|
162
|
+
return Path(state) / STORE_DIR / STORE_FILE
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def adopt(state, tree=None, now=None):
|
|
166
|
+
"""Adopt every domain of DOMAINS into `state` -> the adoption record written. Every domain is attempted; a domain
|
|
167
|
+
is listed in `domains` only once verify_domain read its record back, else it is in `refused`. Raises OSError when
|
|
168
|
+
the store directory or the adoption record cannot be written."""
|
|
169
|
+
state = Path(state)
|
|
170
|
+
_private_dir(state / STORE_DIR)
|
|
171
|
+
adopted, refused = [], []
|
|
172
|
+
for domain in DOMAIN_NAMES:
|
|
173
|
+
try:
|
|
174
|
+
ensure_record(state, domain)
|
|
175
|
+
except cutover.Refused as error:
|
|
176
|
+
refused.append({'domain': domain, 'code': error.code})
|
|
177
|
+
continue
|
|
178
|
+
except OSError as error:
|
|
179
|
+
refused.append({'domain': domain, 'code': f'io:{error.strerror or type(error).__name__}'})
|
|
180
|
+
continue
|
|
181
|
+
record, code = verify_domain(state, domain)
|
|
182
|
+
if record is None:
|
|
183
|
+
refused.append({'domain': domain, 'code': code})
|
|
184
|
+
else:
|
|
185
|
+
adopted.append(domain)
|
|
186
|
+
document = {'v': 1, 'kind': KIND, 'adopted_at': utc(now), 'release': tree_release(tree) if tree else '',
|
|
187
|
+
'store': str(store_path(state)), 'domains': adopted, 'refused': refused}
|
|
188
|
+
_private_dir(state / ADOPTION.parent)
|
|
189
|
+
_atomic_write(state / ADOPTION, json.dumps(document, indent=1) + '\n')
|
|
190
|
+
return document
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _refusal_entry(entry):
|
|
194
|
+
return (isinstance(entry, dict) and set(entry) == {'domain', 'code'}
|
|
195
|
+
and all(isinstance(entry[key], str) for key in ('domain', 'code')))
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def read_adoption(state):
|
|
199
|
+
"""The adoption record, None when there is none, or raises ValueError when it is not one: every field the doctor
|
|
200
|
+
and status read is checked for its type here (kind; domains a list of strings; refused a list of {domain, code}
|
|
201
|
+
strings; adopted_at, release and store strings), so a damaged record is one ✗ line, never a crash."""
|
|
202
|
+
path = Path(state) / ADOPTION
|
|
203
|
+
try:
|
|
204
|
+
with path.open('rb') as handle:
|
|
205
|
+
raw = handle.read(ADOPTION_MAX + 1)
|
|
206
|
+
except FileNotFoundError:
|
|
207
|
+
return None
|
|
208
|
+
if len(raw) > ADOPTION_MAX:
|
|
209
|
+
raise ValueError(f'longer than {ADOPTION_MAX} bytes')
|
|
210
|
+
try:
|
|
211
|
+
document = json.loads(raw)
|
|
212
|
+
except RecursionError as error:
|
|
213
|
+
raise ValueError('adoption record is nested too deeply') from error
|
|
214
|
+
if (not isinstance(document, dict) or type(document.get('v')) is not int or document['v'] != 1
|
|
215
|
+
or document.get('kind') != KIND):
|
|
216
|
+
raise ValueError(f'not a {KIND} record')
|
|
217
|
+
# BEY-7110: validate every consumed field before doctor/status use it.
|
|
218
|
+
# Unknown domains remain valid for readers of an older v1 release.
|
|
219
|
+
for field in ('adopted_at', 'release', 'store'):
|
|
220
|
+
value = document.get(field)
|
|
221
|
+
if not isinstance(value, str) or '\x00' in value or (field != 'release' and not value):
|
|
222
|
+
raise ValueError(f'invalid {field}')
|
|
223
|
+
# JSON permits escaped lone surrogates; paths and diagnostic output do not.
|
|
224
|
+
# Refuse inside this reader's ValueError boundary before either consumes it.
|
|
225
|
+
value.encode('utf-8')
|
|
226
|
+
domains = document.get('domains')
|
|
227
|
+
if (not isinstance(domains, list)
|
|
228
|
+
or not all(isinstance(name, str) and cutover.DOMAIN_RE.fullmatch(name) for name in domains)
|
|
229
|
+
or len(domains) != len(set(domains))):
|
|
230
|
+
raise ValueError('invalid domains')
|
|
231
|
+
refused = document.get('refused')
|
|
232
|
+
if not isinstance(refused, list):
|
|
233
|
+
raise ValueError('invalid refused')
|
|
234
|
+
seen = set(domains)
|
|
235
|
+
for entry in refused:
|
|
236
|
+
if not _refusal_entry(entry):
|
|
237
|
+
raise ValueError('invalid refusal')
|
|
238
|
+
domain, code = entry.get('domain'), entry.get('code')
|
|
239
|
+
if (not isinstance(domain, str) or not cutover.DOMAIN_RE.fullmatch(domain) or domain in seen
|
|
240
|
+
or not isinstance(code, str) or not code or '\x00' in code):
|
|
241
|
+
raise ValueError('invalid refusal')
|
|
242
|
+
code.encode('utf-8')
|
|
243
|
+
seen.add(domain)
|
|
244
|
+
return document
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def status(state):
|
|
248
|
+
"""{adopted: bool, record, domains: [{domain, listed, record, code}]}: every domain of DOMAINS checked on disk.
|
|
249
|
+
`adopted` is True only when every domain is listed and its record verifies."""
|
|
250
|
+
document = read_adoption(state)
|
|
251
|
+
listed = set(document['domains']) if document else set()
|
|
252
|
+
rows = []
|
|
253
|
+
for domain in DOMAIN_NAMES:
|
|
254
|
+
record, code = verify_domain(state, domain)
|
|
255
|
+
rows.append({'domain': domain, 'listed': domain in listed, 'record': record, 'code': code})
|
|
256
|
+
adopted = document is not None and all(row['listed'] and row['record'] is not None for row in rows)
|
|
257
|
+
return {'adopted': adopted, 'record': document, 'domains': rows}
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def _store_text(state, document):
|
|
261
|
+
path = Path(document.get('store') or store_path(state))
|
|
262
|
+
try:
|
|
263
|
+
size = path.stat().st_size
|
|
264
|
+
except OSError:
|
|
265
|
+
return f'store {path}: not created yet (the host coordinator creates and migrates it on its first open)'
|
|
266
|
+
return f'store {path}: present, {size} B'
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def _flags_text(state):
|
|
270
|
+
try:
|
|
271
|
+
names = sorted(name for name in os.listdir(Path(state) / 'flags') if name.startswith('native.'))
|
|
272
|
+
except OSError:
|
|
273
|
+
names = []
|
|
274
|
+
return 'flags: every LANES_RS_* off' if not names else 'flags: ' + ', '.join(names)
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def doctor_lines(state=None):
|
|
278
|
+
"""`lanes doctor`'s Lanes 2.0 adoption lines -> [(mark, text)], mark ✓ | ✗ | ⚠ | '' (information). Nothing before
|
|
279
|
+
the first adoption (`lanes update` adopts)."""
|
|
280
|
+
state = default_state() if state is None else Path(state)
|
|
281
|
+
try:
|
|
282
|
+
document = read_adoption(state)
|
|
283
|
+
except (OSError, ValueError) as error:
|
|
284
|
+
return [('✗', f'lanes2 adoption: {state / ADOPTION} unreadable ({error}) — lanes update adopts again')]
|
|
285
|
+
if document is None:
|
|
286
|
+
return []
|
|
287
|
+
release = document.get('release') or '?'
|
|
288
|
+
lines = [('', f"lanes2: adopted {document.get('adopted_at') or '?'} by {release}; {_store_text(state, document)}; "
|
|
289
|
+
f'{_flags_text(state)}')]
|
|
290
|
+
listed = set(document['domains'])
|
|
291
|
+
refused = {entry['domain']: entry['code'] for entry in document.get('refused') or ()}
|
|
292
|
+
for domain, what, legacy in DOMAINS:
|
|
293
|
+
record, code = verify_domain(state, domain)
|
|
294
|
+
if domain not in listed:
|
|
295
|
+
why = refused.get(domain) or 'added by a newer release'
|
|
296
|
+
lines.append(('⚠', f'lanes2 {domain} ({what}): not adopted ({why}) — lanes update adopts it'))
|
|
297
|
+
elif record is None:
|
|
298
|
+
lines.append(('✗', f'lanes2 {domain} ({what}): listed as adopted but its cutover record is {code} — '
|
|
299
|
+
'lanes update adopts it again'))
|
|
300
|
+
elif record['phase'] in FENCED_PHASES:
|
|
301
|
+
lines.append(('⚠', f"lanes2 {domain} ({what}): fenced in {record['phase']} (owner {record['owner']}, "
|
|
302
|
+
f"epoch {record['epoch']}) — a cutover is in progress or was interrupted: "
|
|
303
|
+
f'python3 libexec/cutover.py status {domain}'))
|
|
304
|
+
else:
|
|
305
|
+
keeper = f'; 1.x: {legacy}' if record['owner'] == LEGACY_OWNER else ''
|
|
306
|
+
lines.append(('✓', f"lanes2 {domain} ({what}): adopted — {record['phase']}, owner {record['owner']}, "
|
|
307
|
+
f"epoch {record['epoch']}{keeper}"))
|
|
308
|
+
return lines
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def parser():
|
|
312
|
+
top = argparse.ArgumentParser(prog='adopt.py', description='installed adoption of the Lanes 2.0 store (S12)')
|
|
313
|
+
commands = top.add_subparsers(dest='command', required=True)
|
|
314
|
+
for name in ('adopt', 'status', 'doctor'):
|
|
315
|
+
command = commands.add_parser(name)
|
|
316
|
+
command.add_argument('--state', default=None)
|
|
317
|
+
if name == 'adopt':
|
|
318
|
+
command.add_argument('--tree', default=None)
|
|
319
|
+
if name != 'doctor':
|
|
320
|
+
command.add_argument('--json', action='store_true')
|
|
321
|
+
return top
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def main(argv=None, out=None):
|
|
325
|
+
out = sys.stdout if out is None else out
|
|
326
|
+
try:
|
|
327
|
+
args = parser().parse_args(argv)
|
|
328
|
+
except SystemExit as exit_:
|
|
329
|
+
return EXIT_USAGE if exit_.code else 0
|
|
330
|
+
state = Path(args.state) if args.state else default_state()
|
|
331
|
+
if args.command == 'doctor':
|
|
332
|
+
for mark, text in doctor_lines(state):
|
|
333
|
+
print(f'{mark or " "} {text}', file=out)
|
|
334
|
+
return 0
|
|
335
|
+
if args.command == 'adopt':
|
|
336
|
+
tree = Path(args.tree) if args.tree else Path(__file__).resolve().parent.parent
|
|
337
|
+
try:
|
|
338
|
+
document = adopt(state, tree)
|
|
339
|
+
except OSError as error:
|
|
340
|
+
print(f'adopt: {error.strerror or error}', file=out)
|
|
341
|
+
return EXIT_IO
|
|
342
|
+
if args.json:
|
|
343
|
+
print(json.dumps(document), file=out)
|
|
344
|
+
else:
|
|
345
|
+
print(f"adopt: {len(document['domains'])} of {len(DOMAIN_NAMES)} domains adopted"
|
|
346
|
+
+ ''.join(f"; {entry['domain']} refused ({entry['code']})" for entry in document['refused']),
|
|
347
|
+
file=out)
|
|
348
|
+
return 0 if not document['refused'] else EXIT_REFUSED
|
|
349
|
+
try:
|
|
350
|
+
report = status(state)
|
|
351
|
+
except (OSError, ValueError) as error:
|
|
352
|
+
print(f'adopt: {state / ADOPTION} unreadable ({error})', file=out)
|
|
353
|
+
return EXIT_REFUSED
|
|
354
|
+
if args.json:
|
|
355
|
+
print(json.dumps(report), file=out)
|
|
356
|
+
else:
|
|
357
|
+
for row in report['domains']:
|
|
358
|
+
word = 'adopted' if row['listed'] and row['record'] else (row['code'] or 'not listed')
|
|
359
|
+
print(f"{row['domain']}: {word}", file=out)
|
|
360
|
+
return 0 if report['adopted'] else EXIT_REFUSED
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
if __name__ == '__main__':
|
|
364
|
+
sys.exit(main())
|
|
@@ -69,6 +69,38 @@ def settings(environ):
|
|
|
69
69
|
return limit, age, refused
|
|
70
70
|
|
|
71
71
|
|
|
72
|
+
|
|
73
|
+
def align_pending(pending):
|
|
74
|
+
"""Start retained presentation at ESC within the first CHUNK bytes (BEY-7148).
|
|
75
|
+
|
|
76
|
+
A PTY read boundary can split an escape sequence. Search the bounded
|
|
77
|
+
queued byte stream across chunks, as the Rust relay does for its ring.
|
|
78
|
+
Without an escape in that window, leave plain output unchanged.
|
|
79
|
+
"""
|
|
80
|
+
scanned = 0
|
|
81
|
+
discard = None
|
|
82
|
+
for chunk in pending:
|
|
83
|
+
window = min(len(chunk), CHUNK - scanned)
|
|
84
|
+
at = chunk.find(b'\x1b', 0, window)
|
|
85
|
+
if at >= 0:
|
|
86
|
+
discard = scanned + at
|
|
87
|
+
break
|
|
88
|
+
scanned += window
|
|
89
|
+
if scanned == CHUNK:
|
|
90
|
+
break
|
|
91
|
+
if discard is None:
|
|
92
|
+
return 0
|
|
93
|
+
left = discard
|
|
94
|
+
while left:
|
|
95
|
+
chunk = pending.popleft()
|
|
96
|
+
if len(chunk) > left:
|
|
97
|
+
pending.appendleft(chunk[left:])
|
|
98
|
+
left = 0
|
|
99
|
+
else:
|
|
100
|
+
left -= len(chunk)
|
|
101
|
+
return discard
|
|
102
|
+
|
|
103
|
+
|
|
72
104
|
def relay(command, output_limit=OUTPUT_LIMIT, output_age=OUTPUT_AGE):
|
|
73
105
|
if not command:
|
|
74
106
|
raise ValueError('No display command supplied')
|
|
@@ -119,11 +151,9 @@ def relay(command, output_limit=OUTPUT_LIMIT, output_age=OUTPUT_AGE):
|
|
|
119
151
|
if not dropped: # a limit below two reads: nothing stale to drop, nothing cut
|
|
120
152
|
return
|
|
121
153
|
# Start what is kept at its first escape sequence, not inside one (or inside a UTF-8 character).
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
pending_size -= at
|
|
126
|
-
dropped += at
|
|
154
|
+
aligned = align_pending(pending)
|
|
155
|
+
pending_size -= aligned
|
|
156
|
+
dropped += aligned
|
|
127
157
|
pending.appendleft(CUT)
|
|
128
158
|
pending_size += len(CUT)
|
|
129
159
|
shed_bytes += dropped
|