twisk 0.1.0b0__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 (41) hide show
  1. twisk-0.1.0b0/LICENSE +199 -0
  2. twisk-0.1.0b0/PKG-INFO +360 -0
  3. twisk-0.1.0b0/README.md +328 -0
  4. twisk-0.1.0b0/pyproject.toml +76 -0
  5. twisk-0.1.0b0/pyproject.toml.orig +71 -0
  6. twisk-0.1.0b0/src/twisk/__init__.py +3 -0
  7. twisk-0.1.0b0/src/twisk/backend/__init__.py +39 -0
  8. twisk-0.1.0b0/src/twisk/backend/base.py +284 -0
  9. twisk-0.1.0b0/src/twisk/backend/fake.py +629 -0
  10. twisk-0.1.0b0/src/twisk/backend/skypilot.py +729 -0
  11. twisk-0.1.0b0/src/twisk/cli.py +306 -0
  12. twisk-0.1.0b0/src/twisk/sandbox.py +471 -0
  13. twisk-0.1.0b0/src/twisk/settings.py +99 -0
  14. twisk-0.1.0b0/src/twisk/specs/__init__.py +26 -0
  15. twisk-0.1.0b0/src/twisk/specs/models.py +691 -0
  16. twisk-0.1.0b0/src/twisk/specs/store.py +193 -0
  17. twisk-0.1.0b0/src/twisk/templates/__init__.py +20 -0
  18. twisk-0.1.0b0/src/twisk/templates/builtin/cluster.yaml +57 -0
  19. twisk-0.1.0b0/src/twisk/templates/builtin/job.yaml +68 -0
  20. twisk-0.1.0b0/src/twisk/templates/builtin/pool.yaml +51 -0
  21. twisk-0.1.0b0/src/twisk/templates/builtin/service.yaml +73 -0
  22. twisk-0.1.0b0/src/twisk/templates/builtin/volume.yaml +40 -0
  23. twisk-0.1.0b0/src/twisk/templates/engine.py +351 -0
  24. twisk-0.1.0b0/src/twisk/templates/model.py +188 -0
  25. twisk-0.1.0b0/src/twisk/templates/registry.py +141 -0
  26. twisk-0.1.0b0/src/twisk/tui/__init__.py +0 -0
  27. twisk-0.1.0b0/src/twisk/tui/app.py +113 -0
  28. twisk-0.1.0b0/src/twisk/tui/format.py +63 -0
  29. twisk-0.1.0b0/src/twisk/tui/screens/__init__.py +0 -0
  30. twisk-0.1.0b0/src/twisk/tui/screens/detail.py +64 -0
  31. twisk-0.1.0b0/src/twisk/tui/screens/dialogs.py +200 -0
  32. twisk-0.1.0b0/src/twisk/tui/screens/editor.py +204 -0
  33. twisk-0.1.0b0/src/twisk/tui/screens/form.py +251 -0
  34. twisk-0.1.0b0/src/twisk/tui/screens/help.py +78 -0
  35. twisk-0.1.0b0/src/twisk/tui/screens/logs.py +129 -0
  36. twisk-0.1.0b0/src/twisk/tui/screens/main.py +1126 -0
  37. twisk-0.1.0b0/src/twisk/tui/twisk.tcss +255 -0
  38. twisk-0.1.0b0/src/twisk/tui/views.py +698 -0
  39. twisk-0.1.0b0/src/twisk/tui/widgets/__init__.py +0 -0
  40. twisk-0.1.0b0/src/twisk/tui/widgets/header.py +106 -0
  41. twisk-0.1.0b0/src/twisk/tui/widgets/vim.py +801 -0
twisk-0.1.0b0/LICENSE ADDED
@@ -0,0 +1,199 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. Please also get an OpenPGP
185
+ key ID and put it in the key field.
186
+
187
+ Copyright [yyyy] [name of copyright owner]
188
+
189
+ Licensed under the Apache License, Version 2.0 (the "License");
190
+ you may not use this file except in compliance with the License.
191
+ You may obtain a copy of the License at
192
+
193
+ http://www.apache.org/licenses/LICENSE-2.0
194
+
195
+ Unless required by applicable law or agreed to in writing, software
196
+ distributed under the License is distributed on an "AS IS" BASIS,
197
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
198
+ See the License for the specific language governing permissions and
199
+ limitations under the License.
twisk-0.1.0b0/PKG-INFO ADDED
@@ -0,0 +1,360 @@
1
+ Metadata-Version: 2.4
2
+ Name: twisk
3
+ Version: 0.1.0b0
4
+ Summary: A k9s-style terminal UI for SkyPilot: clusters, managed jobs, services and volumes without hand-written YAML
5
+ Keywords: skypilot,tui,k9s,ml,gpu,kubernetes,cloud
6
+ Author: Reda Oulbacha
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Environment :: Console :: Curses
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: System :: Clustering
19
+ Classifier: Topic :: System :: Systems Administration
20
+ Requires-Dist: textual>=8,<9
21
+ Requires-Dist: rich>=13
22
+ Requires-Dist: pydantic>=2,<3
23
+ Requires-Dist: pyyaml>=6,<7
24
+ Requires-Dist: jinja2>=3.1,<4
25
+ Requires-Dist: typer>=0.12
26
+ Requires-Dist: skypilot>=0.14.2,<0.15
27
+ Requires-Python: >=3.10, <3.14
28
+ Project-URL: Homepage, https://github.com/roulbac/twisk
29
+ Project-URL: Repository, https://github.com/roulbac/twisk
30
+ Project-URL: Issues, https://github.com/roulbac/twisk/issues
31
+ Description-Content-Type: text/markdown
32
+
33
+ # twisk
34
+
35
+ **A k9s-style terminal UI for [SkyPilot](https://github.com/skypilot-org/skypilot).** *(twisk = TUI + sky)*
36
+ Browse and drive clusters, managed jobs, services and volumes from one keyboard-driven screen, and create them
37
+ through forms instead of hand-writing YAML.
38
+
39
+ ![twisk demo: creating a cluster from a form, following its launch, then GPU usage and the spec library](https://raw.githubusercontent.com/roulbac/twisk/main/docs/assets/twisk-demo.gif)
40
+
41
+ <sub>Recorded with `twisk --demo` (an in-memory simulation). Regenerate with `scripts/capture_screenshots.py`.</sub>
42
+
43
+ ## Why
44
+
45
+ SkyPilot is configured with task YAML. That's powerful, but for day-to-day work you end up keeping a folder of
46
+ half-remembered YAML files and a terminal full of `sky status`, `sky logs`, `sky jobs queue`… twisk keeps the power
47
+ and removes the bookkeeping:
48
+
49
+ - **Forms, not YAML.** Press `c` anywhere to create a cluster, managed job, service or volume. Each form validates as
50
+ you type and shows the exact SkyPilot YAML it generates in a live preview pane.
51
+ - **Forms you define.** Every form is a template in `~/.twisk/templates` — a list of fields plus a Jinja2 template
52
+ that turns them into SkyPilot YAML. Write your team's "GPU dev box" or "nightly eval" form once; everyone gets a
53
+ form with just the knobs that matter and your defaults baked in. See [Form templates](#form-templates).
54
+ - **A spec library you never have to manage, but can.** Everything you create is saved as plain SkyPilot YAML under
55
+ `~/.twisk/specs/<kind>/<name>.yaml`. Press `e` to re-open the form, `E` to edit the YAML in twisk's built-in vim
56
+ editor, `R` to relaunch from it. Fields the form doesn't know about (e.g. `file_mounts`,
57
+ `instance_type`, `config:`) are preserved across form edits. The files work with the plain CLI too:
58
+ `sky launch -c dev ~/.twisk/specs/clusters/dev.yaml`.
59
+ - **Everything in one place, live.** Clusters, cluster job queues, managed jobs, services and their replicas, job
60
+ pools and their workers, volumes, storage buckets, GPU usage, in-flight API requests, enabled infra and
61
+ workspaces — auto-refreshing, filterable, sortable.
62
+ - **GPU-hours and idle time, not dollars.** Every cluster shows its GPU count, GPU-hours so far and how long it has
63
+ been idle (busy while jobs run; otherwise idle since its last job ended, the same notion SkyPilot's autostop uses).
64
+ GPU clusters idle for an hour or more are flagged red, and the title bar counts GPUs up vs. GPUs sitting idle.
65
+ `:usage` lists GPU-hours per cluster — including torn-down ones — over 1d/7d/30d/all. No prices are shown:
66
+ Kubernetes has none unless an admin configures them. (Interactive SSH sessions aren't visible to twisk, so a
67
+ cluster someone is using only over SSH reads as idle.)
68
+ - **Mine vs. everyone, and workspaces.** `U` toggles between your resources and every user's (default: yours, so
69
+ `ctrl-d` isn't one key from a teammate's cluster). `:ws` lists workspaces; `enter` switches the one new launches go
70
+ to (via a SkyPilot project-config overlay — your `~/.sky/config.yaml` is never edited).
71
+ - **Knows SkyPilot's sharp edges.** e.g. Kubernetes clusters can only auto-*down*, never stop; a service's port has
72
+ to be both `service.ports` and an opened resource port. twisk checks these as you type — in the built-in forms,
73
+ your own templates and the YAML editor alike — so launches don't fail late.
74
+ - **Logs and shells one key away.** `l` streams logs (cluster jobs, managed jobs, controllers, load balancers,
75
+ replicas, API requests); `s` drops you into an SSH shell on a cluster; `x` runs a command with `sky exec`.
76
+ - **Safe by default.** Destructive actions are on `ctrl-d` and always confirm. twisk never auto-starts a local API
77
+ server behind your back; it tells you when the server is unreachable instead.
78
+
79
+ ## Screenshots
80
+
81
+ | | |
82
+ |---|---|
83
+ | ![Clusters with GPU count, GPU-hours and idle time](https://raw.githubusercontent.com/roulbac/twisk/main/docs/assets/clusters.png) | ![Create form with live YAML preview](https://raw.githubusercontent.com/roulbac/twisk/main/docs/assets/create-form.png) |
84
+ | **Clusters.** GPUs, GPU-hours and idle time per cluster; idle GPU clusters in red, "9 GPUs up · 8 idle ≥1h" in the title. | **Forms, not YAML.** Fill fields, see the exact SkyPilot YAML on the right; `ctrl-s` saves and launches. |
85
+ | ![Launch output streaming](https://raw.githubusercontent.com/roulbac/twisk/main/docs/assets/launch-logs.png) | ![GPU usage over the last 30 days](https://raw.githubusercontent.com/roulbac/twisk/main/docs/assets/usage.png) |
86
+ | **Launch logs.** SkyPilot's output streams in, then the job's own output. `esc` detaches; the launch keeps going. | **GPU usage.** GPU-hours per cluster, including torn-down ones, over 1d / 7d / 30d / all. |
87
+ | ![Spec library](https://raw.githubusercontent.com/roulbac/twisk/main/docs/assets/specs.png) | ![Built-in YAML editor](https://raw.githubusercontent.com/roulbac/twisk/main/docs/assets/yaml-editor.png) |
88
+ | **Spec library.** Everything you create, as plain SkyPilot YAML in `~/.twisk/specs`. | **Escape hatch.** `E` (or `ctrl-e` in a form) opens the YAML in a built-in vim editor; it's validated on `:w`. |
89
+ | ![Form templates](https://raw.githubusercontent.com/roulbac/twisk/main/docs/assets/templates.png) | ![A form generated from a custom template](https://raw.githubusercontent.com/roulbac/twisk/main/docs/assets/custom-form.png) |
90
+ | **Form templates.** Built-in forms and your own, side by side (`:templates`). | **Your own forms.** A team template: five fields, the rest of the YAML baked in. |
91
+
92
+ ## Install & run
93
+
94
+ twisk is on [PyPI](https://pypi.org/project/twisk/). Install it as a command-line tool with
95
+ [uv](https://docs.astral.sh/uv/getting-started/installation/):
96
+
97
+ ```bash
98
+ uv tool install twisk==0.1.0b0
99
+ twisk --demo # try it against an in-memory simulation, no server needed
100
+ twisk # TUI against your SkyPilot API server
101
+ ```
102
+
103
+ 0.1.0b0 is a beta (a pre-release), so name the version or allow pre-releases — `uv tool install twisk` alone only
104
+ picks stable releases. uv picks a supported Python (3.10–3.13) by itself. Other ways to get it:
105
+
106
+ ```bash
107
+ uv tool install --prerelease allow twisk # latest, including betas
108
+ uvx --from twisk==0.1.0b0 twisk --demo # run once without installing
109
+ uv tool upgrade --prerelease allow twisk # update
110
+ uv tool install git+https://github.com/roulbac/twisk # straight from main
111
+ pipx install twisk==0.1.0b0 # or with pipx / pip
112
+ uv tool uninstall twisk
113
+ ```
114
+
115
+ From a checkout (for development), use `uv sync` and prefix commands with `uv run` (`uv run twisk --demo`).
116
+
117
+ twisk talks to a [SkyPilot API server](https://docs.skypilot.co/en/latest/reference/api-server/api-server.html).
118
+ The endpoint is resolved in this order: `--endpoint URL`, `$SKYPILOT_API_SERVER_ENDPOINT`, `endpoint:` in
119
+ `~/.twisk/config.yaml`, `api_server.endpoint` in `~/.sky/config.yaml` (what `sky api login` writes), then
120
+ `http://127.0.0.1:46580`.
121
+
122
+ ## Try it: the k3s sandbox
123
+
124
+ `twisk sandbox` gives you a disposable SkyPilot setup on your laptop: a single-node k3s cluster and a SkyPilot API
125
+ server wired to it, both in Docker. Nothing touches your real clouds.
126
+
127
+ ```bash
128
+ twisk sandbox up # ~3–5 min the first time (pulls k3s, SkyPilot and the SkyPilot pod image)
129
+ twisk # the sandbox is now twisk's default endpoint
130
+ twisk sandbox status
131
+ twisk sandbox start # after a reboot / Docker restart
132
+ twisk sandbox down # removes everything
133
+ ```
134
+
135
+ Requirements: Docker with ~4 CPUs / 8 GB available. In the sandbox use `infra: k8s` (or leave infra empty), keep
136
+ requests small (1 CPU / 1–2 GB), and note that Kubernetes clusters can be torn down but not stopped.
137
+
138
+ | | |
139
+ |---|---|
140
+ | API server | `http://127.0.0.1:46580` (also usable with the plain `sky` CLI via `SKYPILOT_API_SERVER_ENDPOINT`) |
141
+ | kubeconfig | `~/.twisk/sandbox/kubeconfig` (`kubectl --kubeconfig ~/.twisk/sandbox/kubeconfig get pods`) |
142
+ | server logs | `twisk sandbox logs` |
143
+ | service endpoints | SkyServe load balancers listen on `http://localhost:30001`–`30020` (published from the sandbox) |
144
+ | pod images | `twisk sandbox preload [IMAGE…]` side-loads images from your host's Docker into k3s |
145
+ | workspaces | `default` and `experiments`, to try workspace switching (`:ws`) |
146
+
147
+ What `sandbox up` does: starts `rancher/k3s` (API on `127.0.0.1:16443`), starts `berkeleyskypilot/skypilot:0.14.2`
148
+ with `sky api start --deploy` in the k3s container's network namespace, gives the server the k3s kubeconfig plus a
149
+ small config (managed-jobs/serve controllers run inside the API server; pods use `imagePullPolicy: IfNotPresent`),
150
+ pre-loads SkyPilot's pod image into k3s from your host's Docker cache (so recreating the sandbox doesn't re-download
151
+ it), runs `sky check kubernetes`, and points twisk at it. It detects cgroup-v1 hosts and nested-container hosts that
152
+ forbid lowering `oom_score_adj` and adjusts k3s accordingly.
153
+
154
+ The sandbox is one k3s node with whatever CPUs Docker gives it. If a launch sits in INIT or fails with
155
+ "Failed to acquire resources", the node is full: tear down clusters/services you no longer need (`ctrl-d`).
156
+
157
+ Behind a TLS-intercepting corporate proxy, pass a CA bundle that includes your proxy's CA:
158
+ `twisk sandbox up --ca-bundle /path/to/ca-bundle.crt`. It is trusted by k3s (image pulls), the API server (catalog
159
+ downloads) and every SkyPilot pod (pip/uv/curl during runtime setup).
160
+
161
+ ## Keys
162
+
163
+ | Global | |
164
+ |---|---|
165
+ | `:` | command mode: `:clusters` `:jobs` `:services` `:pools` `:volumes` `:storage` `:usage` `:specs` `:requests` `:infra` `:ws` `:templates` `:q` (aliases: `cl`, `mj`, `svc`, `pl`, `vol`, `st`, `gpu`, `sp`, `req`, `tpl`, …) |
166
+ | `1`–`9`, `0` | jump to a view: clusters, jobs, services, pools, volumes, storage, usage, specs, requests, infra |
167
+ | `j` `k` · `g` `G` | move down / up · to top / bottom (arrows work too) |
168
+ | `U` | scope: only my resources ⇄ every user's |
169
+ | `/` | filter rows, `esc` clears |
170
+ | `<` `>` | sort by previous/next column (again to reverse) |
171
+ | `ctrl-r` | refresh now (on clusters: ask the clouds for fresh status) |
172
+ | `esc` / `q` | back (q quits at the top level) · `?` help · `ctrl-c` quit |
173
+
174
+ | Clusters | | Managed jobs | |
175
+ |---|---|---|---|
176
+ | `c` | create (form) | `c` | submit (form) |
177
+ | `enter` | job queue on the cluster | `l` / `enter` | job logs |
178
+ | `l` | logs of the latest job | `L` | controller logs |
179
+ | `s` | SSH shell | `ctrl-d` | cancel |
180
+ | `x` | `sky exec` a command | `R` | resubmit from spec |
181
+ | `p` / `u` | stop / start | | |
182
+ | `a` | autostop / autodown | **Services** | |
183
+ | `ctrl-d` | tear down | `enter` | replicas (`l` logs, `ctrl-d` terminate) |
184
+ | `d` / `y` | describe / YAML | `l` / `L` | load balancer / controller logs |
185
+ | `e` / `E` | edit spec in form / as YAML | `e` / `R` | edit, rolling update |
186
+ | `R` | relaunch from spec | `ctrl-d` | tear down |
187
+ | `i` | import the server's YAML into the library | | |
188
+
189
+ | Spec library (`8`) | | Requests (`9`) | |
190
+ |---|---|---|---|
191
+ | `enter` | launch / apply | `enter` | follow logs |
192
+ | `e` / `E` | edit in form / as YAML | `ctrl-d` | cancel |
193
+ | `D` | duplicate | | |
194
+ | `ctrl-d` | delete the file | **Forms** | |
195
+ | `o` | show (and copy) the path | `ctrl-s` | save spec + launch/apply |
196
+ | | | `ctrl-o` / `ctrl-e` | save only / continue in the vim editor |
197
+ | | | `c` (any view) | new resource; asks which form if a kind has several templates |
198
+
199
+ | Pools (`4`) | | GPU usage (`7`) | |
200
+ |---|---|---|---|
201
+ | `c` | create (form) | `t` | cycle window: 1d / 7d / 30d / all |
202
+ | `enter` | workers (`l` worker logs) | `d` | describe |
203
+ | `l` | controller logs | **Storage (`6`)** | |
204
+ | `ctrl-d` | tear down | `ctrl-d` | delete bucket (and its objects) |
205
+ | `e` / `R` | edit / re-apply (rolling) | **Workspaces (`:ws`)** | |
206
+ | | | `enter` | switch the active workspace |
207
+
208
+ | Volumes (`5`) | | Form templates (`:templates`) | |
209
+ |---|---|---|---|
210
+ | `c` | create (form) | `enter` | new resource from the template |
211
+ | `ctrl-d` | delete (and its data) | `c` | new template from a working example |
212
+ | `d` / `y` | describe / YAML | `E` | edit in the vim editor (a built-in saves your copy) |
213
+ | `e` / `E` | edit in form / as YAML | `D` | duplicate |
214
+ | `R` | re-apply | `ctrl-d` | delete yours (a built-in it replaced comes back) |
215
+ | `i` | import the server's YAML | `o` | show (and copy) the path |
216
+
217
+ Managed jobs have a **Run in pool** field: set it to submit the job to a pool's warm workers instead of
218
+ provisioning a cluster (`sky jobs launch --pool`). Since the pool isn't part of SkyPilot's task YAML, the spec file
219
+ records it in a `# twisk: pool=<name>` header comment.
220
+
221
+ Log views: `f` toggle follow, `w` toggle wrap, `s` save to `~/.twisk/logs/`, `esc` detach (the work keeps running).
222
+
223
+ ## Editing YAML (the escape hatch)
224
+
225
+ The forms cover the common fields. For anything else — `file_mounts`, `config:` overrides, a custom
226
+ `instance_type`, an extra `service` option — edit the YAML directly, without leaving twisk:
227
+
228
+ - **An existing resource or spec:** select it and press `E` (works in clusters, jobs, services, pools, volumes and
229
+ the spec library). Resources created outside twisk are seeded from the YAML the server recorded.
230
+ - **A resource you're about to create:** fill what you can in the form, then `ctrl-e` to continue in the editor.
231
+ Nothing is written until `:w`, so `:q!` leaves no trace.
232
+
233
+ The editor is a vim inside the TUI (normal / insert / visual modes; no vim binary needed):
234
+
235
+ | | |
236
+ |---|---|
237
+ | `:w` · `:wq` (`ZZ`) · `:q` · `:q!` (`ZQ`) | save · save & close · close (refuses with unsaved changes) · discard |
238
+ | `:apply` or `ctrl-s` | save, then launch the cluster / submit the job / roll out the service / apply the volume or pool |
239
+ | `i a I A o O`, `esc` | insert modes (`o`/`O` keep YAML indentation, one level deeper after `key:`), back to normal |
240
+ | `h j k l w b e 0 ^ $ gg G`, `ctrl-d/u` | motions, with counts (`3j`, `2w`, `5G`) |
241
+ | `d c y > <` + motion, `dd yy cc >> <<` | operators on a motion or on lines |
242
+ | `x X D C s S J r p P ~` | the usual single-key edits |
243
+ | `v`, `V` | visual / visual-line selection, then an operator |
244
+ | `u`, `ctrl-r` | undo / redo (one step per change) |
245
+ | `/pattern`, `n`, `N` · `:42` | search (regex) · go to line |
246
+
247
+ The status line shows the mode, unsaved changes (`[+]`) and whether the YAML is valid as you type; invalid YAML is
248
+ never written. Prefer your own editor? Set `editor: nvim` (or `editor: $EDITOR`) in `~/.twisk/config.yaml` and `E`
249
+ will suspend twisk and open it instead.
250
+
251
+ ## Form templates
252
+
253
+ Every create/edit form in twisk is generated from a **template**: a YAML file that lists the form's fields and a
254
+ [Jinja2](https://jinja.palletsprojects.com/templates/) template that turns the field values into SkyPilot YAML.
255
+ twisk ships one per kind (`cluster`, `job`, `service`, `pool`, `volume`); yours live in `~/.twisk/templates/`.
256
+
257
+ ```yaml
258
+ # ~/.twisk/templates/gpu-box.yaml
259
+ kind: cluster # cluster | job | service | pool | volume
260
+ title: GPU dev box
261
+ description: One node on our Kubernetes cluster, with our base image
262
+ fields:
263
+ - {key: name, label: Cluster name, required: true} # every template needs `name`
264
+ - key: gpu
265
+ label: GPU
266
+ type: select
267
+ options: [L4, A100, H100]
268
+ default: L4
269
+ - {key: gpus, label: GPUs, type: int, default: 1, min: 1, max: 8}
270
+ - {key: team, label: Team, pattern: "[a-z]+", help: lowercase team name}
271
+ - {key: env, label: Environment, type: kv, help: "KEY=value, one per line"}
272
+ template: |
273
+ name: {{ name }}
274
+ resources:
275
+ infra: k8s
276
+ accelerators: {{ gpu }}:{{ gpus }}
277
+ cpus: {{ gpus * 8 }}+
278
+ memory: {{ gpus * 64 }}+
279
+ image_id: docker:ghcr.io/acme/base:latest
280
+ autostop: {idle_minutes: 120, down: true}
281
+ envs: {{ env | yaml }}
282
+ {% if team %}
283
+ config:
284
+ kubernetes:
285
+ pod_config: {metadata: {labels: {team: {{ team | yaml }}}}}
286
+ {% endif %}
287
+ ```
288
+
289
+ With that file in place, `c` in the clusters view asks which form to use; pick *GPU dev box* and you get exactly
290
+ those five fields, with the rendered YAML live next to them.
291
+
292
+ **Fields**
293
+
294
+ | | |
295
+ |---|---|
296
+ | `key` | variable name in the template (letters, digits, `_`) |
297
+ | `type` | `text` · `area` (multi-line) · `int` · `float` · `bool` · `select` · `list` (comma-separated → list) · `kv` (`KEY=value` lines → mapping) |
298
+ | `label`, `section`, `help`, `placeholder` | how it shows in the form (fields are grouped by `section`) |
299
+ | `default`, `required` | starting value; required fields can't be left empty |
300
+ | `options` | for `select`: `[a, b]` or `[{label: …, value: …}]` (a value of `""` means "leave it out") |
301
+ | `min`, `max`, `pattern` | validation for numbers / text (`pattern` is a full-match regex; `help` is shown as the error) |
302
+ | `suggest` | completions: a list, or `infra` · `accelerators` · `volumes` · `pools` (live from your server) |
303
+ | `path` | where the field lives in the YAML (`resources.cpus`, alternatives as `a|b`). Lets twisk fill the form from YAML it didn't render (e.g. a cluster created with `sky launch`) and attach SkyPilot validation errors to the right field. `twisk.pool` stores a job's pool. |
304
+
305
+ **Templates**
306
+
307
+ - Field values are variables; empty optional fields are `none`. `{{ x | yaml }}` renders any value as YAML (strings
308
+ get quoted, `kv` fields become mappings), and keys whose value comes out null or empty are dropped — so optional
309
+ fields rarely need `{% if %}`.
310
+ - The output is validated like any spec: SkyPilot rules (`cpus: 4+`, `A100:8`, Kubernetes can't stop clusters, …) are
311
+ checked as you type, and unknown SkyPilot keys (`file_mounts`, `config`, …) pass straight through.
312
+ - Templates run in Jinja2's sandbox.
313
+
314
+ **Managing them**
315
+
316
+ - `:templates` in the TUI lists every template and whether it's built-in, yours, or yours overriding a built-in.
317
+ `enter` creates a resource from it, `c` starts a new template from a working example, `E` edits one in the vim
318
+ editor (it's validated on `:w`; editing a built-in saves your copy), `D` duplicates, `ctrl-d` deletes yours.
319
+ - A file named after a kind (`~/.twisk/templates/cluster.yaml`) **replaces that built-in form**.
320
+ `twisk templates init` copies all the built-ins there as a starting point.
321
+ - `twisk templates list` / `validate` / `path` from the shell.
322
+
323
+ **Editing later.** Specs remember which template and values made them, so `e` reopens the same form filled in.
324
+ Changes you made in the YAML editor in the meantime are kept: twisk does a three-way merge between the file, what
325
+ the form rendered last time, and what it renders now — anything the form doesn't produce survives, and anything you
326
+ change in the form wins.
327
+
328
+ ## Layout
329
+
330
+ ```
331
+ src/twisk/
332
+ specs/ typed specs ⇄ SkyPilot YAML, and the on-disk spec library
333
+ backend/ Backend protocol; skypilot.py (SDK, API-server mode) and fake.py (demo/tests)
334
+ templates/ form templates: model, engine (render/validate/merge), registry, builtin/*.yaml
335
+ tui/ Textual app: views.py (resource tables), screens/ (form, vim editor, …), widgets/
336
+ sandbox.py k3s + SkyPilot API server sandbox
337
+ cli.py `twisk`, `twisk sandbox …`, `twisk specs …`, `twisk templates …`
338
+ tests/ unit + Textual pilot tests (fake backend); `-m sandbox` for live checks
339
+ scripts/ capture_screenshots.py — regenerates docs/assets (README screenshots + GIF)
340
+ ```
341
+
342
+ ## Development
343
+
344
+ ```bash
345
+ uv sync
346
+ uv run pytest # unit + TUI tests (fake backend, ~1.5 min)
347
+ uv run pytest -m sandbox # live checks against a running `twisk sandbox`
348
+ ```
349
+
350
+ ### Screenshots and the demo GIF
351
+
352
+ `scripts/capture_screenshots.py` drives the real TUI against the demo backend, exports Textual screenshots and
353
+ renders them with Playwright + Pillow into `docs/assets/`. Rerun it after UI changes and look at the GIF before
354
+ committing:
355
+
356
+ ```bash
357
+ uv sync --group docs
358
+ uv run playwright install chromium # once
359
+ uv run python scripts/capture_screenshots.py
360
+ ```