egzoscore 0.2.0__py3-none-any.whl

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 (62) hide show
  1. egzos/__init__.py +11 -0
  2. egzos/_ids.py +29 -0
  3. egzos/_signals.py +39 -0
  4. egzos/_term.py +33 -0
  5. egzos/_types.py +1023 -0
  6. egzos/api/__init__.py +150 -0
  7. egzos/api/app.py +1574 -0
  8. egzos/api/blobs.py +92 -0
  9. egzos/api/throttle.py +190 -0
  10. egzos/auth.py +176 -0
  11. egzos/authz/__init__.py +5 -0
  12. egzos/authz/presence.py +778 -0
  13. egzos/authz/values.py +32 -0
  14. egzos/backends/__init__.py +8 -0
  15. egzos/backends/base.py +91 -0
  16. egzos/backends/postgres.py +490 -0
  17. egzos/backends/sqlite.py +524 -0
  18. egzos/binding.py +309 -0
  19. egzos/cli/__init__.py +1092 -0
  20. egzos/cli/__main__.py +11 -0
  21. egzos/confirm.py +455 -0
  22. egzos/container.py +222 -0
  23. egzos/identity.py +1104 -0
  24. egzos/ledger.py +167 -0
  25. egzos/mcp/__init__.py +3 -0
  26. egzos/mcp/http.py +90 -0
  27. egzos/mcp/server.py +287 -0
  28. egzos/model.py +242 -0
  29. egzos/py.typed +0 -0
  30. egzos/resolver.py +115 -0
  31. egzos/store/__init__.py +10 -0
  32. egzos/store/autotitle.py +31 -0
  33. egzos/store/blobs.py +120 -0
  34. egzos/store/find.py +120 -0
  35. egzos/store/items.py +233 -0
  36. egzos/store/nodes.py +193 -0
  37. egzos/store/objects.py +143 -0
  38. egzos/store/uploads.py +369 -0
  39. egzos/trust.py +675 -0
  40. egzos/web/__init__.py +88 -0
  41. egzos/web/app.py +965 -0
  42. egzos/web/static/htmx.LICENSE +13 -0
  43. egzos/web/static/htmx.min.js +1 -0
  44. egzos/web/static/lifeboat.css +140 -0
  45. egzos/web/static/lifeboat.js +12 -0
  46. egzos/web/strings.py +133 -0
  47. egzos/web/templates/_manifest_row.html +3 -0
  48. egzos/web/templates/_shell.html +29 -0
  49. egzos/web/templates/_window.html +7 -0
  50. egzos/web/templates/base.html +24 -0
  51. egzos/web/templates/error.html +10 -0
  52. egzos/web/templates/home.html +39 -0
  53. egzos/web/templates/item.html +91 -0
  54. egzos/web/templates/notfound.html +6 -0
  55. egzos/web/templates/pending.html +107 -0
  56. egzos/web/tokens.css +294 -0
  57. egzoscore-0.2.0.dist-info/METADATA +135 -0
  58. egzoscore-0.2.0.dist-info/RECORD +62 -0
  59. egzoscore-0.2.0.dist-info/WHEEL +4 -0
  60. egzoscore-0.2.0.dist-info/entry_points.txt +2 -0
  61. egzoscore-0.2.0.dist-info/licenses/LICENSE +65 -0
  62. egzoscore-0.2.0.dist-info/licenses/NOTICE +6 -0
egzos/web/__init__.py ADDED
@@ -0,0 +1,88 @@
1
+ # Copyright 2026 Ali Sasanian
2
+ # SPDX-License-Identifier: LicenseRef-PolyForm-Strict-1.0.0
3
+ """
4
+ The lifeboat (`egzoscore web`), built to spec/design/lifeboat.md §0: server-rendered, in-process with
5
+ the container, FastAPI + Jinja + htmx, no JS toolchain, tokens as CSS variables only. The app is
6
+ `egzos.web.app`; this module launches it on loopback.
7
+
8
+ The URL opened at launch carries a per-launch key, and the key works ONCE: the first browser to
9
+ open it is handed to this launch's own host, `<random>.localhost`, and gets the session there (an
10
+ HttpOnly, host-only cookie, a different value); the key is dead, so a copy read later from the
11
+ launcher's argv or a terminal opens nothing. The session lives on the random host because a
12
+ browser does not isolate cookies by port: a cookie for 127.0.0.1 would reach every other server
13
+ on 127.0.0.1 the owner's browser visits. The label is minted in this process and never printed.
14
+ `*.localhost` resolves to loopback in Chromium and Firefox (RFC 6761); the launch output says what
15
+ to do when the browser does not (`LOCALHOST_HINT`). The keyed URL is printed only when no
16
+ browser was opened AND stdout is a terminal: an agent's shell tool is not a terminal. To reopen
17
+ the lifeboat after closing the browser, restart `egzoscore web`.
18
+ `tokens.css` lives in this package: spec/design/tokens.css as of v0.12 (Docket v2). It stays there, not
19
+ re-vendored to v0.13 (direction A′), until the lifeboat and tap-page specs are revised for A′.
20
+ """
21
+
22
+ from __future__ import annotations
23
+
24
+ import secrets
25
+ import threading
26
+ import time
27
+ import webbrowser
28
+
29
+ from egzos._signals import sigterm_as_sigint
30
+ from egzos.authz.presence import is_terminal
31
+ from egzos.container import Container
32
+
33
+ DEFAULT_PORT = 7425
34
+ # a1r minor on #127: the key is spent once the launch host hands off, so a browser that cannot
35
+ # resolve the session host must be told what to do instead of being left on a dead page.
36
+ LOCALHOST_HINT = (
37
+ "The session moves to a private *.localhost address. If that page does not load, this "
38
+ "browser does not resolve *.localhost: stop egzoscore web, run `egzoscore web --no-open`, and open "
39
+ "the printed link in Chromium or Firefox."
40
+ )
41
+
42
+
43
+ def _launch(url: str, open_browser: bool, opener=None, terminal=None) -> bool:
44
+ """Open the browser on the keyed URL; print the key only to a person at a terminal."""
45
+ if open_browser and (opener or webbrowser.open)(url):
46
+ print("Opened in your browser.", flush=True)
47
+ print(LOCALHOST_HINT, flush=True)
48
+ return True
49
+ if terminal if terminal is not None else is_terminal():
50
+ print(f"Open this in your browser (it carries this session's key):\n {url}", flush=True)
51
+ print(LOCALHOST_HINT, flush=True)
52
+ else:
53
+ print(
54
+ "No browser was opened and this is not a terminal, so the session key is not printed. "
55
+ "Run `egzoscore web` from a terminal on this machine.",
56
+ flush=True,
57
+ )
58
+ return False
59
+
60
+
61
+ def lifeboat_for(container: Container, port: int):
62
+ """The lifeboat, its app and its launch URL. The launch URL is on 127.0.0.1 and carries only
63
+ the single-use key; the session host's random label never leaves this process except in the
64
+ redirect that hands the redeemed launch to it."""
65
+ from egzos.web.app import Lifeboat, create_app
66
+
67
+ label = secrets.token_hex(10)
68
+ boat = Lifeboat(container, host=f"{label}.localhost:{port}", launch_host=f"127.0.0.1:{port}")
69
+ return boat, create_app(boat, f"http://{boat.host}"), f"http://127.0.0.1:{port}/?k={boat.key}"
70
+
71
+
72
+ def serve_web(container: Container, port: int = DEFAULT_PORT, open_browser: bool = True) -> None:
73
+ import uvicorn
74
+
75
+ token = container.require_token()
76
+ if token.principal != "interactive":
77
+ raise PermissionError("the lifeboat is the owner's; a client principal cannot open it")
78
+ host = "127.0.0.1"
79
+ _boat, app, url = lifeboat_for(container, port)
80
+ print(f"egzoscore web on http://{host}:{port} — loopback only. Ctrl-C to stop.", flush=True)
81
+
82
+ def launch_when_up() -> None:
83
+ time.sleep(0.5)
84
+ _launch(url, open_browser)
85
+
86
+ threading.Thread(target=launch_when_up, daemon=True).start()
87
+ with sigterm_as_sigint(): # a SIGTERM stop closes the container as Ctrl-C does
88
+ uvicorn.run(app, host=host, port=port, log_level="warning", access_log=False)