lightcone-cli 0.5.0rc5__tar.gz → 0.5.1__tar.gz

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 (125) hide show
  1. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/.gitignore +4 -0
  2. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/PKG-INFO +5 -4
  3. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/README.md +1 -3
  4. lightcone_cli-0.5.1/hatch_build.py +23 -0
  5. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/pyproject.toml +13 -7
  6. lightcone_cli-0.5.1/src/lightcone/app/__init__.py +120 -0
  7. lightcone_cli-0.5.1/src/lightcone/app/__main__.py +3 -0
  8. lightcone_cli-0.5.1/src/lightcone/app/files.py +194 -0
  9. lightcone_cli-0.5.1/src/lightcone/app/routes.py +128 -0
  10. lightcone_cli-0.5.1/src/lightcone/app/static/03e9641d6f9e9223.woff2 +0 -0
  11. lightcone_cli-0.5.1/src/lightcone/app/static/0462f03bdf9d9e26.woff2 +0 -0
  12. lightcone_cli-0.5.1/src/lightcone/app/static/0750571032beef1a.woff +0 -0
  13. lightcone_cli-0.5.1/src/lightcone/app/static/07ef19e7b06429d4.ttf +0 -0
  14. lightcone_cli-0.5.1/src/lightcone/app/static/10d95fd3a2a3c8c5.woff2 +0 -0
  15. lightcone_cli-0.5.1/src/lightcone/app/static/1608a09b4aff30c2.woff +0 -0
  16. lightcone_cli-0.5.1/src/lightcone/app/static/3b1e59b3ba055bda.woff2 +0 -0
  17. lightcone_cli-0.5.1/src/lightcone/app/static/47373d1e512354bb.ttf +0 -0
  18. lightcone_cli-0.5.1/src/lightcone/app/static/4aafdb685c2bf1c9.ttf +0 -0
  19. lightcone_cli-0.5.1/src/lightcone/app/static/5295ba483ad9f51a.woff +0 -0
  20. lightcone_cli-0.5.1/src/lightcone/app/static/55fac25845c12663.woff2 +0 -0
  21. lightcone_cli-0.5.1/src/lightcone/app/static/572d331f69425f62.woff2 +0 -0
  22. lightcone_cli-0.5.1/src/lightcone/app/static/577270225ea69a74.woff +0 -0
  23. lightcone_cli-0.5.1/src/lightcone/app/static/5916a24fa3ab2b17.woff2 +0 -0
  24. lightcone_cli-0.5.1/src/lightcone/app/static/6258592bdc9387b6.woff +0 -0
  25. lightcone_cli-0.5.1/src/lightcone/app/static/6f2bb1dff24614a5.woff2 +0 -0
  26. lightcone_cli-0.5.1/src/lightcone/app/static/70d8b0a530ab8484.ttf +0 -0
  27. lightcone_cli-0.5.1/src/lightcone/app/static/740484788f643b19.woff +0 -0
  28. lightcone_cli-0.5.1/src/lightcone/app/static/7a996c9da2ec18e6.woff +0 -0
  29. lightcone_cli-0.5.1/src/lightcone/app/static/7c1871215eef4da8.woff +0 -0
  30. lightcone_cli-0.5.1/src/lightcone/app/static/7c9bc82b17fa2586.woff +0 -0
  31. lightcone_cli-0.5.1/src/lightcone/app/static/7f51fe034014000e.woff +0 -0
  32. lightcone_cli-0.5.1/src/lightcone/app/static/8916142bec8821e7.woff2 +0 -0
  33. lightcone_cli-0.5.1/src/lightcone/app/static/8c5b5494b63adb73.woff2 +0 -0
  34. lightcone_cli-0.5.1/src/lightcone/app/static/9024d815ba48fa55.woff +0 -0
  35. lightcone_cli-0.5.1/src/lightcone/app/static/939bc64440a13865.ttf +0 -0
  36. lightcone_cli-0.5.1/src/lightcone/app/static/94e1e8dc5ff5d517.ttf +0 -0
  37. lightcone_cli-0.5.1/src/lightcone/app/static/9acaf01c6476f53a.woff +0 -0
  38. lightcone_cli-0.5.1/src/lightcone/app/static/9f256b8593ce632e.woff +0 -0
  39. lightcone_cli-0.5.1/src/lightcone/app/static/a144ef5840bbd063.ttf +0 -0
  40. lightcone_cli-0.5.1/src/lightcone/app/static/a79f1c3119cd700d.woff2 +0 -0
  41. lightcone_cli-0.5.1/src/lightcone/app/static/a8709e36220dee77.woff2 +0 -0
  42. lightcone_cli-0.5.1/src/lightcone/app/static/a879cf8383e22737.ttf +0 -0
  43. lightcone_cli-0.5.1/src/lightcone/app/static/b18f59e1d1359581.ttf +0 -0
  44. lightcone_cli-0.5.1/src/lightcone/app/static/b4230e7e83f57db8.woff2 +0 -0
  45. lightcone_cli-0.5.1/src/lightcone/app/static/b4c20c84d8259773.ttf +0 -0
  46. lightcone_cli-0.5.1/src/lightcone/app/static/b67709187bb0654a.woff +0 -0
  47. lightcone_cli-0.5.1/src/lightcone/app/static/b74a1a8b2c5d73c2.ttf +0 -0
  48. lightcone_cli-0.5.1/src/lightcone/app/static/b7f8fe9b5f78a977.ttf +0 -0
  49. lightcone_cli-0.5.1/src/lightcone/app/static/ba21ed5f8468b2b7.woff2 +0 -0
  50. lightcone_cli-0.5.1/src/lightcone/app/static/bf59d231c34de257.woff +0 -0
  51. lightcone_cli-0.5.1/src/lightcone/app/static/bundle.js +7446 -0
  52. lightcone_cli-0.5.1/src/lightcone/app/static/c3fb5ac22fd413f2.woff2 +0 -0
  53. lightcone_cli-0.5.1/src/lightcone/app/static/cce5b8ecea35407a.ttf +0 -0
  54. lightcone_cli-0.5.1/src/lightcone/app/static/cfe392c431bfee31.js +2 -0
  55. lightcone_cli-0.5.1/src/lightcone/app/static/d181c4650dd0c0fe.woff +0 -0
  56. lightcone_cli-0.5.1/src/lightcone/app/static/d3c882a649b3f4fa.woff2 +0 -0
  57. lightcone_cli-0.5.1/src/lightcone/app/static/d42a5579b0283025.woff2 +0 -0
  58. lightcone_cli-0.5.1/src/lightcone/app/static/d4d7ba480428fe6e.ttf +0 -0
  59. lightcone_cli-0.5.1/src/lightcone/app/static/d6b476ecd3949434.ttf +0 -0
  60. lightcone_cli-0.5.1/src/lightcone/app/static/d97aaf4a1ebf38b0.ttf +0 -0
  61. lightcone_cli-0.5.1/src/lightcone/app/static/dad44a7fc678e2ca.woff +0 -0
  62. lightcone_cli-0.5.1/src/lightcone/app/static/e1e279cbdd2feecd.woff +0 -0
  63. lightcone_cli-0.5.1/src/lightcone/app/static/e3f82f9d2724733a.woff +0 -0
  64. lightcone_cli-0.5.1/src/lightcone/app/static/eae34984b3dc1874.woff2 +0 -0
  65. lightcone_cli-0.5.1/src/lightcone/app/static/eb2a35646018d68d.js +8 -0
  66. lightcone_cli-0.5.1/src/lightcone/app/static/ec17d132645b2c86.woff2 +0 -0
  67. lightcone_cli-0.5.1/src/lightcone/app/static/ed38e79f5799ceca.ttf +0 -0
  68. lightcone_cli-0.5.1/src/lightcone/app/static/f1035d8d5d945108.woff +0 -0
  69. lightcone_cli-0.5.1/src/lightcone/app/static/f28c23acad0b6d75.woff2 +0 -0
  70. lightcone_cli-0.5.1/src/lightcone/app/static/fabc004aab10cb40.ttf +0 -0
  71. lightcone_cli-0.5.1/src/lightcone/app/static/favicon.svg +1 -0
  72. lightcone_cli-0.5.1/src/lightcone/app/static/fbccdabe0ae624b8.ttf +0 -0
  73. lightcone_cli-0.5.1/src/lightcone/app/static/fe9cbbe1a0f37727.ttf +0 -0
  74. lightcone_cli-0.5.1/src/lightcone/app/templates/index.html +30 -0
  75. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/cli/commands.py +37 -0
  76. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/cli/compute.py +20 -13
  77. lightcone_cli-0.5.1/src/lightcone/engine/__init__.py +3 -0
  78. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/assets.py +9 -1
  79. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/compute/__init__.py +46 -57
  80. lightcone_cli-0.5.1/src/lightcone/engine/compute/catalog.py +165 -0
  81. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/compute/local.py +38 -47
  82. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/compute/local_runtime.py +26 -4
  83. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/compute/model.py +75 -49
  84. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/compute/runtime.py +11 -6
  85. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/compute/slurm.py +71 -110
  86. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/compute/slurm_bootstrap.py +5 -11
  87. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/crate.py +8 -9
  88. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/image.py +2 -2
  89. lightcone_cli-0.5.1/src/lightcone/engine/serve.py +164 -0
  90. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/templates/files/pyproject.toml.tmpl +1 -1
  91. lightcone_cli-0.5.0rc5/src/lightcone/engine/__init__.py +0 -9
  92. lightcone_cli-0.5.0rc5/src/lightcone/engine/compute/catalog.py +0 -183
  93. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/LICENSE +0 -0
  94. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/_sandbox_exec.py +0 -0
  95. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/cli/__init__.py +0 -0
  96. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/compute/output.py +0 -0
  97. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/container.py +0 -0
  98. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/dataset.py +0 -0
  99. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/execution_resources.py +0 -0
  100. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/identity.py +0 -0
  101. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/materialize.py +0 -0
  102. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/plan.py +0 -0
  103. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/project.py +0 -0
  104. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/run.py +0 -0
  105. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/sandbox/__init__.py +0 -0
  106. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/sandbox/boundary.py +0 -0
  107. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/sandbox/denial.py +0 -0
  108. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/sandbox/landlock.py +0 -0
  109. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/sandbox/model.py +0 -0
  110. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/sandbox/oci.py +0 -0
  111. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/sandbox/policy.py +0 -0
  112. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/sandbox/profiles/base.sbpl +0 -0
  113. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/sandbox/profiles/network.sbpl +0 -0
  114. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/sandbox/profiles/platform-defaults.sbpl +0 -0
  115. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/sandbox/seatbelt.py +0 -0
  116. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/templates/__init__.py +0 -0
  117. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/templates/files/data-README.md.tmpl +0 -0
  118. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/templates/files/datalad-config.tmpl +0 -0
  119. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/templates/files/gitattributes.tmpl +0 -0
  120. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/templates/files/gitignore.tmpl +0 -0
  121. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/templates/files/index.md.tmpl +0 -0
  122. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/templates/files/myst.yml.tmpl +0 -0
  123. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/templates/files/results-README.md.tmpl +0 -0
  124. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/units.py +0 -0
  125. {lightcone_cli-0.5.0rc5 → lightcone_cli-0.5.1}/src/lightcone/engine/worker.py +0 -0
@@ -220,3 +220,7 @@ uv.lock
220
220
 
221
221
  # macOS
222
222
  .DS_Store
223
+
224
+ # The app's front end: dependencies, and the build that `uv build` packages
225
+ ui/node_modules/
226
+ src/lightcone/app/static/
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: lightcone-cli
3
- Version: 0.5.0rc5
3
+ Version: 0.5.1
4
4
  Summary: Lightcone Research's agentic execution layer
5
5
  Project-URL: Repository, https://github.com/LightconeResearch/lightcone-cli
6
6
  Author: Lightcone Research
@@ -24,6 +24,9 @@ Requires-Dist: click>=8.0
24
24
  Requires-Dist: cryptography>=44
25
25
  Requires-Dist: distributed>=2026.7
26
26
  Requires-Dist: git-annex>=10.2026
27
+ Requires-Dist: jupyter-live-content<0.2,>=0.1.2
28
+ Requires-Dist: jupyter-server>=2.21
29
+ Requires-Dist: jupyterlab-server>=2.28
27
30
  Requires-Dist: psutil>=6
28
31
  Requires-Dist: pydantic<3,>=2.9
29
32
  Requires-Dist: pyyaml>=6
@@ -54,7 +57,7 @@ uv tool install lightcone-cli
54
57
  ```
55
58
 
56
59
  Create an ASTRA project and launch the built-in local compute offer; no compute
57
- configuration is needed. [Configure resource offers](docs/user/cluster.md) for
60
+ configuration is needed. [Configure resource offers](https://docs.lightconeresearch.org) for
58
61
  larger local allocations or Slurm:
59
62
 
60
63
  ```bash
@@ -74,8 +77,6 @@ lc compute down "$CLUSTER"
74
77
  ASTRA specs are plain, structured YAML — they work well hand-written or
75
78
  drafted with any AI coding assistant.
76
79
 
77
- → [Full getting-started guide](https://docs.lightconeresearch.org/user/getting-started/)
78
-
79
80
  ## Capabilities
80
81
 
81
82
  - **Multiverse analysis** — declare methodological decisions with multiple defensible options; `lc` materializes your analysis across every universe you define
@@ -21,7 +21,7 @@ uv tool install lightcone-cli
21
21
  ```
22
22
 
23
23
  Create an ASTRA project and launch the built-in local compute offer; no compute
24
- configuration is needed. [Configure resource offers](docs/user/cluster.md) for
24
+ configuration is needed. [Configure resource offers](https://docs.lightconeresearch.org) for
25
25
  larger local allocations or Slurm:
26
26
 
27
27
  ```bash
@@ -41,8 +41,6 @@ lc compute down "$CLUSTER"
41
41
  ASTRA specs are plain, structured YAML — they work well hand-written or
42
42
  drafted with any AI coding assistant.
43
43
 
44
- → [Full getting-started guide](https://docs.lightconeresearch.org/user/getting-started/)
45
-
46
44
  ## Capabilities
47
45
 
48
46
  - **Multiverse analysis** — declare methodological decisions with multiple defensible options; `lc` materializes your analysis across every universe you define
@@ -0,0 +1,23 @@
1
+ """Build checkout assets; consume bundled assets when installing the sdist."""
2
+
3
+ import subprocess
4
+ from pathlib import Path
5
+ from typing import Any
6
+
7
+ from hatchling.builders.hooks.plugin.interface import BuildHookInterface
8
+
9
+
10
+ class FrontendBuildHook(BuildHookInterface[Any]):
11
+ def initialize(self, version: str, build_data: dict[str, Any]) -> None:
12
+ if version == "editable":
13
+ return
14
+ root = Path(self.root)
15
+ ui = root / "ui"
16
+ if ui.is_dir():
17
+ # An unconditional build includes styles, assets, dependency locks,
18
+ # and compiler/bundler configuration, even after a git checkout.
19
+ subprocess.run(["npm", "ci"], cwd=ui, check=True)
20
+ subprocess.run(["npm", "run", "build"], cwd=ui, check=True)
21
+ for name in ("bundle.js", "favicon.svg"):
22
+ if not (root / "src/lightcone/app/static" / name).is_file():
23
+ raise RuntimeError(f"Missing frontend asset: {name}")
@@ -34,12 +34,17 @@ dependencies = [
34
34
  "psutil>=6",
35
35
  "pydantic>=2.9,<3",
36
36
  "pyyaml>=6",
37
+ "jupyter-server>=2.21",
38
+ "jupyterlab-server>=2.28",
39
+ "jupyter-live-content>=0.1.2,<0.2",
37
40
  ]
38
41
 
39
42
  [dependency-groups]
40
43
  dev = [
41
44
  "pytest>=8.0",
42
45
  "pytest-cov",
46
+ "hatchling",
47
+ "playwright>=1.58",
43
48
  "ruff",
44
49
  "mypy",
45
50
  "datalad",
@@ -47,12 +52,6 @@ dev = [
47
52
  "types-pyyaml>=6.0.12.20260906",
48
53
  "types-psutil>=7.2.2.20260906",
49
54
  ]
50
- docs = [
51
- "zensical>=0.0.33",
52
- # squidfunk's mike fork — required by zensical's versioning provider.
53
- # Not on PyPI; install from git.
54
- "mike @ git+https://github.com/squidfunk/mike.git ; python_version >= '3.10'",
55
- ]
56
55
 
57
56
 
58
57
  [project.urls]
@@ -80,9 +79,16 @@ source = "vcs"
80
79
 
81
80
  [tool.hatch.build.targets.wheel]
82
81
  packages = ["src/lightcone"]
82
+ # The app's front end, built from ui/ and gitignored.
83
+ artifacts = ["src/lightcone/app/static"]
83
84
 
84
85
  [tool.hatch.build.targets.sdist]
85
- include = ["src/lightcone"]
86
+ include = ["src/lightcone", "hatch_build.py"]
87
+ artifacts = ["src/lightcone/app/static"]
88
+
89
+ # Checkout distributions rebuild all frontend inputs. Prebuilt sdists need
90
+ # no Node, and editable installs leave the optional frontend build explicit.
91
+ [tool.hatch.build.hooks.custom]
86
92
 
87
93
  [tool.ruff]
88
94
  target-version = "py311"
@@ -0,0 +1,120 @@
1
+ """The Lightcone app: one page over one project's ``astra.yaml``.
2
+
3
+ Inspired from JupyterLab's ``examples/app`` (BSD-3-Clause, Copyright (c)
4
+ Jupyter Development Team): a ``LabServerApp`` serving one page, with its
5
+ token, its page config and Jupyter's Contents API. The page reads the
6
+ project through that API and resolves the spec itself; the app's own routes
7
+ (see ``routes``) answer what that API cannot: an output's recorded run, read
8
+ by lc's manifest reader; every output's state, from the engine's own
9
+ classification; and the cited papers in astra's cache, outside the project.
10
+ It serves no settings or themes: the page has no JupyterLab interface to
11
+ configure. The one other extension it loads is
12
+ jupyter-live-content, whose WebSocket tells the page when a file it read
13
+ changed on disk.
14
+
15
+ The token reads and nothing more. The page only reads, so the server keeps
16
+ two of Jupyter's services, the Contents API and ``/files/``, and Jupyter's
17
+ authorizer refuses every write; there are no kernels, sessions or terminals
18
+ for the token to run code with, and no config to write. Three writes Jupyter
19
+ makes outside its authorizer are switched off as well: the login form's
20
+ password change, the notebook trust store, and corrupt-notebook recovery.
21
+
22
+ Run as ``python -m lightcone.app``; ``lc view`` is what starts it.
23
+ """
24
+
25
+ from __future__ import annotations
26
+
27
+ import hashlib
28
+ import os
29
+ import secrets
30
+ from pathlib import Path
31
+ from typing import Any
32
+
33
+ from jupyter_server.auth.authorizer import Authorizer
34
+ from jupyter_server.auth.identity import PasswordIdentityProvider, User
35
+ from jupyter_server.base.handlers import JupyterHandler
36
+ from jupyter_server.serverapp import ServerApp
37
+ from jupyterlab_server import LabServerApp
38
+ from traitlets import Bool, default
39
+
40
+ from lightcone.app import routes
41
+ from lightcone.app.files import ProjectContents
42
+ from lightcone.engine.serve import BUNDLE
43
+
44
+ _HERE = Path(__file__).parent
45
+
46
+
47
+ def _jupyter_server_extension_points() -> list[dict[str, Any]]:
48
+ return [{"module": __name__, "app": LightconeApp}]
49
+
50
+
51
+ class ReadOnly(Authorizer):
52
+ """Let the token read and nothing else."""
53
+
54
+ def is_authorized(
55
+ self, handler: JupyterHandler, user: User, action: str, resource: str
56
+ ) -> bool:
57
+ """Allow ``read``; refuse ``write`` and ``execute`` with a 403."""
58
+ return action == "read"
59
+
60
+
61
+ class TokenLogin(PasswordIdentityProvider):
62
+ """Jupyter's token login, without the form's offer to set a password."""
63
+
64
+ # Accepting one writes a Jupyter config file and lets that password in
65
+ # beside the token. Not configurable, so no config can turn it back on.
66
+ allow_password_change = Bool(False)
67
+
68
+ @default("token")
69
+ def _token_default(self) -> str:
70
+ # JUPYTER_NO_CONFIG does not suppress JUPYTER_TOKEN[_FILE].
71
+ self.token_generated = True
72
+ return secrets.token_hex(32)
73
+
74
+
75
+ class LightconeServer(ServerApp):
76
+ """Jupyter's server with only what the page reads through."""
77
+
78
+ # jupyter_server's documented way to expose a subset of its services; its
79
+ # own tuple's inferred type is what mypy objects to.
80
+ default_services = ("contents", "files") # type: ignore[assignment]
81
+
82
+ @default("cookie_secret")
83
+ def _default_cookie_secret(self) -> bytes:
84
+ # A different user can claim a stopped server's port and receive the
85
+ # old page's cookies. Those cookies must never authenticate a new run.
86
+ return os.urandom(32)
87
+
88
+
89
+ class LightconeApp(LabServerApp):
90
+ """Serve the Lightcone front end and nothing else."""
91
+
92
+ serverapp_class = LightconeServer
93
+ name = "lightcone"
94
+ app_name = "Lightcone"
95
+ # The page's `?v=`. Jupyter serves static/ as immutable by path, so this
96
+ # is all that makes a browser fetch a rebuilt bundle: its bytes, not the
97
+ # package version, which a development build does not move.
98
+ app_version = hashlib.sha256(BUNDLE.read_bytes() if BUNDLE.is_file() else b"").hexdigest()[:16]
99
+ default_url = "/lightcone"
100
+ app_url = "/lightcone"
101
+ serverapp_config = {
102
+ "jpserver_extensions": {"jupyter_live_content": True},
103
+ # jupyter_server still serves a handler that declares no auth rule to
104
+ # anyone; refused instead, every route needs the token, ours included.
105
+ "allow_unauthenticated_access": False,
106
+ "authorizer_class": ReadOnly,
107
+ "identity_provider_class": TokenLogin,
108
+ "contents_manager_class": ProjectContents,
109
+ }
110
+ static_dir = str(BUNDLE.parent)
111
+ templates_dir = str(_HERE / "templates")
112
+ # The page loads no lab extension, so none is advertised to it.
113
+ labextensions_path: list[str] = []
114
+
115
+ def initialize_handlers(self) -> None:
116
+ """Add the app's routes to the page's own."""
117
+ super().initialize_handlers()
118
+ # Ahead of the catch-all jupyterlab_server ends its own list with
119
+ # (`/lightcone/.*`), which would answer for them with the page.
120
+ self.handlers[:0] = routes.HANDLERS
@@ -0,0 +1,3 @@
1
+ from lightcone.app import LightconeApp
2
+
3
+ LightconeApp.launch_instance() # type: ignore[no-untyped-call]
@@ -0,0 +1,194 @@
1
+ """Confined reads for the viewer, including symlinks in shared projects."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import stat
7
+ from collections.abc import Iterator
8
+ from contextlib import ExitStack, contextmanager
9
+ from datetime import UTC, datetime
10
+ from pathlib import Path
11
+ from typing import IO, Any
12
+
13
+ from jupyter_server.base.handlers import AuthenticatedFileHandler
14
+ from jupyter_server.services.contents.largefilemanager import AsyncLargeFileManager
15
+ from nbformat.sign import NotebookNotary
16
+ from tornado import web
17
+ from traitlets import Bool, default
18
+
19
+ from lightcone.engine import assets
20
+
21
+
22
+ def resolved_path(root: Path, path: Path, *, hidden: bool = False) -> Path:
23
+ """Allow project-local links, including annex objects, but no escaping links."""
24
+ root = root.resolve()
25
+ try:
26
+ relative = path.relative_to(root)
27
+ resolved = path.resolve(strict=True)
28
+ target = resolved.relative_to(root)
29
+ if not hidden:
30
+ if any(part.startswith(".") for part in relative.parts):
31
+ raise ValueError("hidden path")
32
+ # Locked git-annex artifacts point into this private object store.
33
+ parts = (
34
+ target.parts[3:]
35
+ if target.parts[:3] == (".git", "annex", "objects")
36
+ else target.parts
37
+ )
38
+ if any(part.startswith(".") for part in parts):
39
+ raise ValueError("hidden target")
40
+ return resolved
41
+ except (ValueError, OSError, RuntimeError) as error:
42
+ raise web.HTTPError(404, "File is outside the readable project") from error
43
+
44
+
45
+ @contextmanager
46
+ def open_fd(
47
+ root: Path, path: Path, *, directory: bool = False, hidden: bool = False
48
+ ) -> Iterator[int]:
49
+ """Open beneath root without following links swapped in after resolution.
50
+
51
+ Directory descriptors anchor every step. O_NONBLOCK and fstat reject
52
+ special files without hanging on a FIFO planted by another project writer.
53
+ """
54
+ root = root.resolve()
55
+ path = resolved_path(root, path, hidden=hidden)
56
+ try:
57
+ with ExitStack() as stack:
58
+ flags = os.O_RDONLY | os.O_NOFOLLOW | os.O_DIRECTORY
59
+ parent = os.open(root, flags)
60
+ stack.callback(os.close, parent)
61
+ parts = path.relative_to(root).parts
62
+ for part in parts[:-1]:
63
+ parent = os.open(part, flags, dir_fd=parent)
64
+ stack.callback(os.close, parent)
65
+ flags = os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK
66
+ if directory:
67
+ flags |= os.O_DIRECTORY
68
+ fd = os.open(parts[-1] if parts else ".", flags, dir_fd=parent)
69
+ stack.callback(os.close, fd)
70
+ mode = os.fstat(fd).st_mode
71
+ if not (stat.S_ISDIR(mode) if directory else stat.S_ISREG(mode)):
72
+ raise web.HTTPError(404, "Not a regular file")
73
+ yield fd
74
+ except OSError as error:
75
+ raise web.HTTPError(404, "File is unavailable") from error
76
+
77
+
78
+ class ProjectFileHandler(AuthenticatedFileHandler):
79
+ """Jupyter's authentication and HTTP ranges over a confined, open file."""
80
+
81
+ def validate_absolute_path(self, root: str, absolute_path: str) -> str:
82
+ # The opener checks containment and hidden paths, allowing annex links.
83
+ # Keep the requested alias for MIME detection and subsequent reads:
84
+ # its resolved target may legitimately live under .git/annex/objects.
85
+ with open_fd(Path(root), Path(absolute_path)) as fd:
86
+ self._stat_result = os.fstat(fd)
87
+ return absolute_path
88
+
89
+ # Tornado's classmethod reads by path. This instance needs the serving root
90
+ # as well; compute_etag is disabled by Jupyter, so no class-level caller runs.
91
+ def get_content( # type: ignore[override]
92
+ self, abspath: str, start: int | None = None, end: int | None = None
93
+ ) -> Iterator[bytes]:
94
+ with (
95
+ open_fd(Path(self.root), Path(abspath)) as fd,
96
+ os.fdopen(fd, "rb", closefd=False) as file,
97
+ ):
98
+ file.seek(start or 0)
99
+ remaining = None if end is None else end - (start or 0)
100
+ while remaining is None or remaining > 0:
101
+ chunk = file.read(65_536 if remaining is None else min(65_536, remaining))
102
+ if not chunk:
103
+ break
104
+ if remaining is not None:
105
+ remaining -= len(chunk)
106
+ yield chunk
107
+
108
+
109
+ class ProjectContents(AsyncLargeFileManager):
110
+ """Confined project reads, without hashing or persistent notebook trust."""
111
+
112
+ # Notebook reads otherwise recover a corrupt file by renaming its atomic
113
+ # intermediate into place, a write that bypasses Jupyter's authorizer.
114
+ use_atomic_writing = Bool(False)
115
+
116
+ @default("files_handler_class")
117
+ def _files_handler_class_default(self) -> type[ProjectFileHandler]:
118
+ return ProjectFileHandler
119
+
120
+ def _get_os_path(self, path: str) -> str:
121
+ os_path: str = super()._get_os_path(path) # type: ignore[no-untyped-call]
122
+ resolved_path(Path(self.root_dir), Path(os_path))
123
+ return os_path
124
+
125
+ def _base_model(self, path: str) -> dict[str, Any]:
126
+ model: dict[str, Any] = super()._base_model(path) # type: ignore[no-untyped-call]
127
+ os_path = Path(self._get_os_path(path))
128
+ with open_fd(Path(self.root_dir), os_path, directory=os_path.is_dir()) as fd:
129
+ info = os.fstat(fd)
130
+ # lstat describes the symlink itself. Previews and cache tokens must
131
+ # instead describe the bytes that will be served through that link.
132
+ model.update(size=info.st_size, writable=False)
133
+ for field, timestamp in (("last_modified", info.st_mtime), ("created", info.st_ctime)):
134
+ try:
135
+ model[field] = datetime.fromtimestamp(timestamp, UTC)
136
+ except (ValueError, OverflowError, OSError):
137
+ model[field] = datetime.fromtimestamp(0, UTC)
138
+ return model
139
+
140
+ @contextmanager
141
+ def open(self, os_path: str, mode: str = "r", **kwargs: Any) -> Iterator[IO[Any]]:
142
+ with open_fd(Path(self.root_dir), Path(os_path)) as fd:
143
+ with open(fd, mode, closefd=False, **kwargs) as file:
144
+ yield file
145
+
146
+ async def get(
147
+ self,
148
+ path: str,
149
+ content: bool = True,
150
+ type: str | None = None,
151
+ format: str | None = None,
152
+ require_hash: bool = False,
153
+ ) -> dict[str, Any]:
154
+ # Live-content asks for a hash even for metadata-only reads. The page
155
+ # never uses it, and Jupyter would read the entire artifact to produce it.
156
+ model: dict[str, Any] = await super().get( # type: ignore[no-untyped-call]
157
+ path, content, type, format, require_hash=False
158
+ )
159
+ if model["type"] != "directory":
160
+ root = Path(self.root_dir)
161
+ target = resolved_path(root, root / model["path"])
162
+ model["watchPaths"] = [
163
+ target.relative_to(root).as_posix(),
164
+ assets.manifest_path(Path(model["path"])).as_posix(),
165
+ ]
166
+ return model
167
+
168
+ async def _dir_model(self, path: str, content: bool = True) -> dict[str, Any]:
169
+ model: dict[str, Any] = await super()._dir_model( # type: ignore[no-untyped-call]
170
+ path, content=False
171
+ )
172
+ if content:
173
+ with open_fd(Path(self.root_dir), Path(self._get_os_path(path)), directory=True) as fd:
174
+ names = os.listdir(fd)
175
+ children = []
176
+ for name in names:
177
+ if not self.should_list(name): # type: ignore[no-untyped-call]
178
+ continue
179
+ try:
180
+ children.append(await self.get(f"{path}/{name}".strip("/"), content=False))
181
+ except (web.HTTPError, OSError):
182
+ # A hidden, escaping, absent or unreadable child must not
183
+ # prevent the rest of the directory from being listed.
184
+ continue
185
+ model.update(content=children, format="json")
186
+ return model
187
+
188
+ @default("notary")
189
+ def _notary_default(self) -> NotebookNotary:
190
+ # Reading a notebook checks its signature, which by default creates
191
+ # Jupyter's signature database and secret in the user's data directory.
192
+ return NotebookNotary( # type: ignore[no-untyped-call]
193
+ parent=self, db_file=":memory:", secret=os.urandom(32)
194
+ )
@@ -0,0 +1,128 @@
1
+ """The app's own routes: what the page needs and the Contents API cannot give.
2
+
3
+ An output's recorded run, read by lc's own manifest reader, so the page
4
+ never parses lc's format and the server never has to open dotfiles to it;
5
+ every output's state, classified by the engine exactly as ``lc status``
6
+ does, so the page holds no copy of that rule; and the cited papers in
7
+ astra's paper cache, which lies outside the
8
+ project (``astra paper add`` fills it, and quotes are verified against it).
9
+ The paper routes are adapted from jupyterlab-lightcone's ``routes.py``
10
+ (BSD-3-Clause, Lightcone Research), without its fetch route: nothing here
11
+ writes the cache. Every route needs the token, like the rest of the server.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import asyncio
17
+ import os
18
+ from pathlib import Path
19
+ from typing import Any
20
+
21
+ from astra.papers.cache import CachedPaper, PaperCache
22
+ from jupyter_core.utils import ensure_async
23
+ from jupyter_server.base.handlers import APIHandler
24
+ from jupyter_server.utils import url_path_join
25
+ from tornado import web
26
+
27
+ from lightcone.app.files import ProjectFileHandler, open_fd
28
+ from lightcone.engine import assets, materialize
29
+ from lightcone.engine.project import ProjectError, current_project
30
+
31
+ _PAPERS = PaperCache().cache_dir
32
+
33
+
34
+ def _cached() -> dict[str, CachedPaper]:
35
+ """Every cached paper by DOI as the SDK normalizes it, unversioned first."""
36
+ papers: dict[str, CachedPaper] = {}
37
+ for paper in PaperCache().list_papers():
38
+ doi = paper.metadata.doi.strip().lower()
39
+ if doi not in papers or paper.metadata.version is None:
40
+ papers[doi] = paper
41
+ return papers
42
+
43
+
44
+ class PapersHandler(APIHandler):
45
+ """Title, authors and PDF of the cited DOIs the cache holds."""
46
+
47
+ @web.authenticated
48
+ async def get(self) -> None:
49
+ """Answer the repeated ``doi`` arguments from one scan of the cache."""
50
+ cached = await asyncio.to_thread(_cached)
51
+ papers: dict[str, dict[str, str]] = {}
52
+ for doi in self.get_arguments("doi"):
53
+ if (paper := cached.get(doi)) is None:
54
+ continue
55
+ pdf = paper.pdf_path.relative_to(_PAPERS).as_posix()
56
+ metadata = {
57
+ "title": paper.metadata.title,
58
+ "authors": ", ".join(paper.metadata.authors or []),
59
+ "pdfUrl": url_path_join(self.base_url, "lightcone/papers", pdf),
60
+ }
61
+ papers[doi] = {key: value for key, value in metadata.items() if value}
62
+ self.set_header("Cache-Control", "private, no-store")
63
+ self.finish({"papers": papers})
64
+
65
+
66
+ class RunHandler(APIHandler):
67
+ """The run lc recorded for one output, or ``null`` when there is none."""
68
+
69
+ @web.authenticated
70
+ async def get(self) -> None:
71
+ """Read the manifest beside the output the ``path`` argument names."""
72
+ # Whether the path is a file in the project is the contents manager's
73
+ # to say, as it does for /files/: outside the root, hidden, absent or
74
+ # a directory is refused before anything is read.
75
+ cm: Any = self.contents_manager # its methods are untyped
76
+ path = self.get_query_argument("path")
77
+ if not cm.allow_hidden and await ensure_async(cm.is_hidden(path)):
78
+ raise web.HTTPError(404)
79
+ model = await ensure_async(cm.get(path, type="file", content=False))
80
+ # The sidecar is hidden, but uses the same confined opener as artifacts.
81
+ root = Path(cm.root_dir).resolve()
82
+ sidecar = assets.manifest_path(root / model["path"])
83
+ try:
84
+ with open_fd(root, sidecar, hidden=True) as fd:
85
+ with os.fdopen(fd, "r", closefd=False) as file:
86
+ manifest = assets.loads(file.read())
87
+ except (web.HTTPError, UnicodeDecodeError):
88
+ manifest = None
89
+ run: dict[str, Any] | None = None
90
+ if manifest is not None:
91
+ run = {
92
+ "finishedAt": manifest.finished_at,
93
+ "gitRevision": manifest.git_sha,
94
+ "recipe": manifest.recipe,
95
+ "environment": manifest.env_version,
96
+ "cliVersion": manifest.lc_version,
97
+ "inputVersions": manifest.input_versions,
98
+ }
99
+ self.set_header("Cache-Control", "private, no-store")
100
+ self.finish({"run": run})
101
+
102
+
103
+ class StatusHandler(APIHandler):
104
+ """What state every output is in: the engine's answer, as `lc status` gives it."""
105
+
106
+ @web.authenticated
107
+ async def get(self) -> None:
108
+ """Classify every output; a project the engine cannot read is a 422."""
109
+ root = Path(self.contents_manager.root_dir)
110
+ try:
111
+ # Classification hashes the declared inputs, so it runs off the loop.
112
+ report = await asyncio.to_thread(materialize.status, current_project(root))
113
+ except ProjectError as error:
114
+ raise web.HTTPError(422, str(error)) from error
115
+ outputs = {o.output: {"state": o.status, "detail": o.why} for o in report.outputs}
116
+ self.set_header("Cache-Control", "private, no-store")
117
+ # The warnings qualify the verdicts — an unfetched input reads as
118
+ # "changed" without the line saying it is merely not in this clone.
119
+ self.finish({"outputs": outputs, "warnings": report.warnings})
120
+
121
+
122
+ HANDLERS = [
123
+ ("/lightcone/api/papers", PapersHandler),
124
+ ("/lightcone/api/run", RunHandler),
125
+ ("/lightcone/api/status", StatusHandler),
126
+ # Jupyter's own file handler: ranges for pdf.js, 304s on reopening.
127
+ ("/lightcone/papers/(.*)", ProjectFileHandler, {"path": str(_PAPERS)}),
128
+ ]