dev-bubble 0.2.0__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 (54) hide show
  1. dev_bubble-0.2.0/.claude/CLAUDE.md +166 -0
  2. dev_bubble-0.2.0/.github/workflows/ci.yml +78 -0
  3. dev_bubble-0.2.0/.gitignore +10 -0
  4. dev_bubble-0.2.0/LICENSE +190 -0
  5. dev_bubble-0.2.0/PKG-INFO +187 -0
  6. dev_bubble-0.2.0/README.md +155 -0
  7. dev_bubble-0.2.0/bubble/__init__.py +3 -0
  8. dev_bubble-0.2.0/bubble/automation.py +359 -0
  9. dev_bubble-0.2.0/bubble/clean.py +186 -0
  10. dev_bubble-0.2.0/bubble/cli.py +1715 -0
  11. dev_bubble-0.2.0/bubble/config.py +87 -0
  12. dev_bubble-0.2.0/bubble/git_store.py +92 -0
  13. dev_bubble-0.2.0/bubble/hooks/__init__.py +51 -0
  14. dev_bubble-0.2.0/bubble/hooks/lean.py +125 -0
  15. dev_bubble-0.2.0/bubble/images/__init__.py +0 -0
  16. dev_bubble-0.2.0/bubble/images/builder.py +129 -0
  17. dev_bubble-0.2.0/bubble/images/scripts/base.sh +117 -0
  18. dev_bubble-0.2.0/bubble/images/scripts/lean-toolchain.sh +14 -0
  19. dev_bubble-0.2.0/bubble/images/scripts/lean.sh +199 -0
  20. dev_bubble-0.2.0/bubble/lifecycle.py +56 -0
  21. dev_bubble-0.2.0/bubble/naming.py +39 -0
  22. dev_bubble-0.2.0/bubble/network.py +141 -0
  23. dev_bubble-0.2.0/bubble/relay.py +409 -0
  24. dev_bubble-0.2.0/bubble/repo_registry.py +94 -0
  25. dev_bubble-0.2.0/bubble/runtime/__init__.py +0 -0
  26. dev_bubble-0.2.0/bubble/runtime/base.py +84 -0
  27. dev_bubble-0.2.0/bubble/runtime/colima.py +37 -0
  28. dev_bubble-0.2.0/bubble/runtime/incus.py +168 -0
  29. dev_bubble-0.2.0/bubble/target.py +280 -0
  30. dev_bubble-0.2.0/bubble/vscode.py +91 -0
  31. dev_bubble-0.2.0/claude-skill/SKILL.md +111 -0
  32. dev_bubble-0.2.0/config/com.bubble.git-update.plist +26 -0
  33. dev_bubble-0.2.0/config/com.bubble.image-refresh.plist +33 -0
  34. dev_bubble-0.2.0/config/com.bubble.relay-daemon.plist +26 -0
  35. dev_bubble-0.2.0/dev_bubble.egg-info/PKG-INFO +187 -0
  36. dev_bubble-0.2.0/dev_bubble.egg-info/SOURCES.txt +52 -0
  37. dev_bubble-0.2.0/dev_bubble.egg-info/dependency_links.txt +1 -0
  38. dev_bubble-0.2.0/dev_bubble.egg-info/entry_points.txt +2 -0
  39. dev_bubble-0.2.0/dev_bubble.egg-info/requires.txt +9 -0
  40. dev_bubble-0.2.0/dev_bubble.egg-info/top_level.txt +1 -0
  41. dev_bubble-0.2.0/pyproject.toml +57 -0
  42. dev_bubble-0.2.0/setup.cfg +4 -0
  43. dev_bubble-0.2.0/tests/conftest.py +186 -0
  44. dev_bubble-0.2.0/tests/test_config.py +51 -0
  45. dev_bubble-0.2.0/tests/test_git_store.py +22 -0
  46. dev_bubble-0.2.0/tests/test_hooks.py +174 -0
  47. dev_bubble-0.2.0/tests/test_integration.py +310 -0
  48. dev_bubble-0.2.0/tests/test_lifecycle.py +49 -0
  49. dev_bubble-0.2.0/tests/test_naming.py +50 -0
  50. dev_bubble-0.2.0/tests/test_network.py +96 -0
  51. dev_bubble-0.2.0/tests/test_relay.py +502 -0
  52. dev_bubble-0.2.0/tests/test_repo_registry.py +96 -0
  53. dev_bubble-0.2.0/tests/test_target.py +433 -0
  54. dev_bubble-0.2.0/tests/test_vscode.py +78 -0
@@ -0,0 +1,166 @@
1
+ # bubble Architecture Guide
2
+
3
+ This file helps Claude Code sessions understand the bubble codebase.
4
+
5
+ ## What This Project Is
6
+
7
+ `bubble` provides containerized development environments via Incus containers. The primary interface is URL-based: `bubble <github-url>` creates (or re-attaches to) an isolated container with VSCode Remote SSH. Language-specific hooks (currently Lean 4) auto-detect the project type and select the right image.
8
+
9
+ ## Package Structure
10
+
11
+ ```
12
+ bubble/
13
+ ├── cli.py # Click CLI with BubbleGroup (routes unknown args to `open` command)
14
+ ├── config.py # TOML config at ~/.bubble/config.toml
15
+ ├── target.py # Target parsing: GitHub URLs, local paths, bare PR numbers
16
+ ├── repo_registry.py # Learned short name → owner/repo mappings (~/.bubble/repos.json)
17
+ ├── naming.py # Container name generation: <repo>-<source>-<id>
18
+ ├── git_store.py # Shared bare repo management at ~/.bubble/git/
19
+ ├── clean.py # Container cleanness checking (safe to discard?)
20
+ ├── lifecycle.py # Registry tracking for active bubbles
21
+ ├── network.py # Network allowlisting via iptables inside containers
22
+ ├── vscode.py # SSH config generation + `code --remote` launching
23
+ ├── automation.py # Periodic jobs: launchd (macOS), systemd (Linux)
24
+ ├── relay.py # Bubble-in-bubble relay daemon (Unix socket, validation, rate limiting)
25
+ ├── hooks/
26
+ │ ├── __init__.py # Hook ABC, discover_hooks(), select_hook()
27
+ │ └── lean.py # LeanHook: detects lean-toolchain, uses lean image
28
+ ├── runtime/
29
+ │ ├── base.py # Abstract ContainerRuntime interface
30
+ │ ├── incus.py # IncusRuntime: shells out to `incus` CLI
31
+ │ └── colima.py # macOS: ensure Colima VM is running with correct resources
32
+ ├── images/
33
+ │ ├── builder.py # Image build via IMAGES registry dict (recursive parent building)
34
+ │ └── scripts/
35
+ │ ├── base.sh # Ubuntu 24.04 + git + ssh + build-essential (user: "user")
36
+ │ ├── lean.sh # elan + VS Code Lean extension (derives from base, no toolchains)
37
+ │ └── lean-toolchain.sh # Installs one specific Lean toolchain (for versioned images)
38
+ ```
39
+
40
+ ## Key Design Decisions
41
+
42
+ ### URL-First Interface
43
+ The primary command is `bubble <target>`. A custom `BubbleGroup(click.Group)` routes any unknown first argument to the implicit `open` command. Targets are parsed by `target.py` into a `Target(owner, repo, kind, ref, local_path)` dataclass. Supported target forms:
44
+ - GitHub URLs: `https://github.com/owner/repo/pull/123`
45
+ - Shorthand: `owner/repo`, `mathlib4/pull/123`, `mathlib4`
46
+ - Local paths: `.`, `./path`, `/absolute/path` (extracts owner/repo from git remote)
47
+ - Bare PR numbers: `123` (uses current directory's repo)
48
+ - `--path` flag for disambiguation: `bubble --path mydir`
49
+
50
+ Short names are resolved via `RepoRegistry`, which learns mappings automatically on first use. Local paths use the local `.git` as the `--reference` source for fast cloning, and support unpushed branches by fetching refs from the mounted local repo.
51
+
52
+ ### Language Hooks
53
+ The `hooks/` package provides a pluggable system for language-specific behavior. Each `Hook` subclass implements `detect()` (check bare repo for language markers), `image_name()`, `post_clone()`, `vscode_extensions()`, and `network_domains()`. Hook detection runs against the host bare repo via `git show <ref>:<file>` — no container needed.
54
+
55
+ ### Runtime Abstraction
56
+ `ContainerRuntime` (base.py) is an abstract interface. `IncusRuntime` is the only implementation today. Docker/Podman support is a stretch goal — the abstraction exists to make that possible without refactoring.
57
+
58
+ ### Git Object Sharing
59
+ The core performance optimization. Host maintains bare mirror repos (`git clone --bare`). Containers clone with `git clone --reference /shared/git/repo.git url` — git alternates share immutable objects. Each container has fully independent refs/branches/working tree. `update_all_repos()` discovers repos from the `~/.bubble/git/*.git` directory listing.
60
+
61
+ ### Image Registry
62
+ Images are defined in `builder.py`'s `IMAGES` dict with script and parent references. Building is recursive — if a parent image is missing, it's built first. Static images: `base` (from Ubuntu 24.04) and `lean` (from base, elan + VS Code extension only, no toolchains).
63
+
64
+ ### Lazy Lean Toolchain Images
65
+ The `lean` image has only elan (no toolchains pre-installed). When `LeanHook` detects a project, it reads `lean-toolchain` and parses the version. For stable/RC versions (v4.X.Y, v4.X.Y-rcK), it requests image `lean-v4.X.Y`. If that image exists, it's used directly. If not, the plain `lean` image is used (elan downloads the toolchain on demand) and a background build of the versioned image is triggered for next time. Dynamic images are built via `build_lean_toolchain_image()` in `builder.py`. Nightlies and custom toolchains always use the plain `lean` image.
66
+
67
+ ### Colima on macOS
68
+ Incus requires Linux. On macOS, Colima runs a lightweight Linux VM with Apple's Virtualization.Framework (`--vm-type vz`). The `ensure_colima()` function starts it if needed.
69
+
70
+ ### SSH via ProxyCommand
71
+ Each container runs sshd. Rather than port forwarding (which doesn't work well through Colima on macOS), we use `ProxyCommand incus exec <name> -- su - user -c "nc localhost 22"`. SSH config entries are auto-generated in `~/.ssh/config.d/bubble`.
72
+
73
+ ### Container Naming
74
+ Names are `<repo>-<source>-<id>` (e.g., `mathlib4-pr-12345`). Numeric suffix for collisions. The `open` command checks for existing containers by generated name and registry lookup before creating new ones.
75
+
76
+ ### Container Lifecycle
77
+ ```
78
+ created → running ⇄ paused → destroyed
79
+ ```
80
+
81
+ ### Network Allowlisting
82
+ Uses iptables rules inside containers (not Incus ACLs) for portability across Colima/native setups. IPv6 is blocked entirely. DNS restricted to container resolver only. No outbound SSH. Base allowlist comes from config.toml; hooks contribute additional domains (e.g., Lean adds `releases.lean-lang.org`).
83
+
84
+ ### Security Model
85
+ The `user` account has no sudo and a locked password. Network allowlisting is applied on container creation. SSH keys are injected via `incus file push` (not shell interpolation). All user-supplied values in shell commands are quoted with `shlex.quote()`. Each container mounts only its specific bare repo, not the entire git store.
86
+
87
+ ## How to Add a New Language Hook
88
+
89
+ 1. Create `bubble/hooks/<language>.py` with a class extending `Hook`
90
+ 2. Implement `detect()` to check for language markers in the bare repo
91
+ 3. Implement `image_name()` to return the image to use
92
+ 4. Add image script in `images/scripts/<name>.sh` and entry in `builder.py`'s `IMAGES` dict
93
+ 5. Register the hook in `hooks/__init__.py`'s `discover_hooks()`
94
+
95
+ ## How to Add a New Command
96
+
97
+ 1. Add a `@main.command()` function in `cli.py`
98
+ 2. Load config with `load_config()`, get runtime with `get_runtime(config)`
99
+ 3. Use `runtime.exec()`, `runtime.launch()`, etc. for container operations
100
+
101
+ ## Data Locations
102
+
103
+ - `~/.bubble/config.toml` — user settings
104
+ - `~/.bubble/git/` — bare repo mirrors
105
+ - `~/.bubble/repos.json` — learned repo short name mappings
106
+ - `~/.bubble/registry.json` — bubble state tracking
107
+ - `~/.bubble/relay.sock` — relay daemon Unix socket (when enabled)
108
+ - `~/.bubble/relay-tokens.json` — relay auth tokens per container
109
+ - `~/.bubble/relay.log` — relay request log
110
+ - `~/.bubble/vscode-commit` — VS Code commit hash baked into current base image
111
+ - `~/.ssh/config.d/bubble` — auto-managed SSH config
112
+
113
+ ## Automation
114
+
115
+ Automation is installed automatically on first bubble creation. On macOS, launchd jobs:
116
+ - `com.bubble.git-update` — hourly git store refresh
117
+ - `com.bubble.image-refresh` — weekly base image rebuild
118
+ - `com.bubble.relay-daemon` — persistent relay daemon (installed via `bubble relay enable`)
119
+
120
+ On Linux, equivalent systemd user timers/services are installed.
121
+
122
+ ## Bubble-in-Bubble Relay
123
+
124
+ The relay allows running `bubble` from inside a container. Architecture:
125
+
126
+ ```
127
+ Container Host
128
+ ──────── ────
129
+ /usr/local/bin/bubble (stub) bubble relay daemon
130
+ → /bubble/relay.sock (Incus proxy) ← ~/.bubble/relay.sock
131
+ sends {"target": "..."} validates, rate-limits, logs
132
+ reads {"status": "ok", ...} calls bubble open
133
+ ```
134
+
135
+ - Opt-in via `bubble relay enable` (installs daemon, sets config)
136
+ - Security: known repos only (`~/.bubble/git/` must exist), no local paths, rate limited (3/min, 10/10min, 20/hr per container), all requests logged
137
+ - Container identifies itself via `/bubble/container-id` file
138
+ - Relay daemon runs as launchd (macOS) or systemd (Linux) service
139
+ - Code: `bubble/relay.py` (daemon + validation), `bubble/images/scripts/base.sh` (stub + client)
140
+
141
+ ## Testing Bubbles
142
+
143
+ **Never run `bubble` with `--no-interactive` on the user's behalf.** When the user wants to test bubble, tell them the command and let them run it themselves. The user wants to see the live output in their terminal and interact with the result (VS Code window, SSH session). Running it non-interactively from a tool call hides the output and wastes time.
144
+
145
+ ## VS Code Integration Notes
146
+
147
+ ### Workspace Trust
148
+ The workspace trust dialog is a **local VS Code client** decision, not controlled by remote server settings. We pass `--disable-workspace-trust` when launching VS Code in `open_vscode()`. Writing to `.vscode-server/data/Machine/settings.json` or `User/settings.json` inside the container does NOT suppress the trust prompt.
149
+
150
+ ### Clearing Trust State for Testing
151
+ VS Code stores trusted workspace URIs in a SQLite database. To clear bubble-related trust entries:
152
+ ```python
153
+ import json, sqlite3
154
+ db = "/Users/kim/Library/Application Support/Code/User/globalStorage/state.vscdb"
155
+ conn = sqlite3.connect(db)
156
+ cur = conn.cursor()
157
+ cur.execute("SELECT value FROM ItemTable WHERE key = 'content.trust.model.key'")
158
+ data = json.loads(cur.fetchone()[0])
159
+ data["uriTrustInfo"] = [e for e in data["uriTrustInfo"] if "bubble-" not in e["uri"].get("authority", "")]
160
+ cur.execute("UPDATE ItemTable SET value = ? WHERE key = 'content.trust.model.key'", [json.dumps(data)])
161
+ conn.commit()
162
+ ```
163
+ VS Code must be restarted after modifying this database.
164
+
165
+ ### Pre-baked VS Code Server
166
+ The base image pre-installs the VS Code Server binary matching the host's `code --version` commit hash. On each `bubble open`, if the hash has changed (VS Code updated), a background `bubble images build base` is triggered. The current bubble proceeds immediately; the next one gets the pre-baked server.
@@ -0,0 +1,78 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main, master]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ lint:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: actions/setup-python@v5
17
+ with:
18
+ python-version: "3.12"
19
+ - run: pip install ruff
20
+ - run: ruff check bubble/ tests/
21
+ - run: ruff format --check bubble/ tests/
22
+
23
+ test:
24
+ runs-on: ubuntu-latest
25
+ strategy:
26
+ matrix:
27
+ python-version: ["3.10", "3.12"]
28
+ steps:
29
+ - uses: actions/checkout@v4
30
+ - uses: actions/setup-python@v5
31
+ with:
32
+ python-version: ${{ matrix.python-version }}
33
+ - run: pip install -e ".[dev]"
34
+ - run: pytest -v -m "not integration"
35
+
36
+ integration:
37
+ runs-on: ubuntu-latest
38
+ steps:
39
+ - uses: actions/checkout@v4
40
+ - uses: actions/setup-python@v5
41
+ with:
42
+ python-version: "3.12"
43
+
44
+ - name: Install Incus
45
+ run: |
46
+ sudo mkdir -p /etc/apt/keyrings/
47
+ curl -fsSL https://pkgs.zabbly.com/key.asc | sudo tee /etc/apt/keyrings/zabbly.asc > /dev/null
48
+ sudo sh -c 'cat <<EOF > /etc/apt/sources.list.d/zabbly-incus-stable.sources
49
+ Enabled: yes
50
+ Types: deb
51
+ URIs: https://pkgs.zabbly.com/incus/stable
52
+ Suites: $(. /etc/os-release && echo ${VERSION_CODENAME})
53
+ Components: main
54
+ Architectures: $(dpkg --print-architecture)
55
+ Signed-By: /etc/apt/keyrings/zabbly.asc
56
+ EOF'
57
+ sudo apt-get update
58
+ sudo apt-get install -y incus
59
+
60
+ - name: Initialize Incus
61
+ run: |
62
+ sudo incus admin init --minimal
63
+ # Allow non-root access (CI-only, ephemeral VM)
64
+ sudo chmod 666 /var/lib/incus/unix.socket
65
+ # Ensure IP forwarding and NAT for container internet access
66
+ sudo sysctl -w net.ipv4.ip_forward=1
67
+ sudo iptables -t nat -A POSTROUTING -s 10.0.0.0/8 -o eth0 -j MASQUERADE
68
+ sudo iptables -A FORWARD -i incusbr0 -j ACCEPT
69
+ sudo iptables -A FORWARD -o incusbr0 -m state --state RELATED,ESTABLISHED -j ACCEPT
70
+
71
+ - name: Install bubble
72
+ run: pip install -e ".[dev]"
73
+
74
+ - name: Build base image
75
+ run: bubble images build base
76
+
77
+ - name: Run integration tests
78
+ run: pytest -v -m integration
@@ -0,0 +1,10 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ dist/
5
+ build/
6
+ .eggs/
7
+ *.egg
8
+ .venv/
9
+ .env
10
+ uv.lock
@@ -0,0 +1,190 @@
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
+ Copyright 2025 Kim Morrison
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
@@ -0,0 +1,187 @@
1
+ Metadata-Version: 2.4
2
+ Name: dev-bubble
3
+ Version: 0.2.0
4
+ Summary: Containerized development environments powered by Incus
5
+ Author-email: Kim Morrison <kim@tqft.net>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/kim-em/bubble
8
+ Project-URL: Repository, https://github.com/kim-em/bubble
9
+ Project-URL: Issues, https://github.com/kim-em/bubble/issues
10
+ Keywords: containers,development,incus,lean,vscode
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: MacOS
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: click>=8.0
26
+ Requires-Dist: tomli>=2.0; python_version < "3.11"
27
+ Requires-Dist: tomli-w>=1.0
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest; extra == "dev"
30
+ Requires-Dist: ruff; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ # bubble
34
+
35
+ Containerized development environments for the Lean language, powered by [Incus](https://linuxcontainers.org/incus/).
36
+
37
+ ## Quick Start
38
+
39
+ ```bash
40
+ # Install (use pipx or uv to avoid PEP 668 issues with system Python)
41
+ pipx install dev-bubble # or: uv tool install dev-bubble
42
+ # For development: uv pip install -e '.[dev]'
43
+
44
+ # Open a bubble for a GitHub PR — just paste the URL, and you get a containerized VSCode window!
45
+ bubble https://github.com/leanprover-community/mathlib4/pull/35219
46
+
47
+ # Shorter forms work too
48
+ bubble leanprover-community/mathlib4/pull/35219
49
+ bubble mathlib4/pull/35219 # after first use, short names are learned
50
+
51
+ # Branch or commit
52
+ bubble leanprover-community/mathlib4/tree/some-branch
53
+ bubble leanprover-community/mathlib4/commit/abc123
54
+
55
+ # Default branch
56
+ bubble leanprover-community/mathlib4
57
+
58
+ # From a local git repo — opens the current branch in a bubble
59
+ bubble .
60
+ bubble ./path/to/repo
61
+
62
+ # PR number shorthand (when in a cloned repo)
63
+ bubble 123 # opens PR #123 for the current repo
64
+
65
+ # List your bubbles
66
+ bubble list
67
+
68
+ # SSH instead of VSCode
69
+ bubble https://github.com/leanprover/lean4 --ssh
70
+
71
+ # Just create, don't open anything
72
+ bubble leanprover/lean4 --no-interactive
73
+
74
+ # Pause a bubble
75
+ bubble pause mathlib4-pr-35219
76
+
77
+ # Destroy permanently
78
+ bubble destroy mathlib4-pr-35219
79
+ ```
80
+
81
+ ## How It Works
82
+
83
+ Each "bubble" is a lightweight Linux container (via Incus) with:
84
+ - Your project cloned and ready to work on
85
+ - SSH server for VSCode Remote connection
86
+ - Network restricted to allowed domains only
87
+ - Language-specific tooling when detected (e.g. Lean 4 via elan)
88
+
89
+ **URL-first interface**: The primary command is `bubble <target>`. Targets can be full GitHub URLs, partial URLs, org/repo paths, or learned short names. If a bubble already exists for that target, it re-attaches instead of creating a new one.
90
+
91
+ **Shared git objects**: A bare mirror of each repo is maintained on the host. Containers clone via `git --reference`, sharing the immutable object store. This means creating a new bubble for a mathlib PR downloads only the few new commits, not the entire 1.5GB repo.
92
+
93
+ **Language hooks**: bubble automatically detects the project's language and selects the right image. For Lean 4 projects (detected via `lean-toolchain`), the container includes elan, pre-installed VS Code extensions, and auto-downloads the mathlib cache when needed.
94
+
95
+ **Network allowlisting**: Containers can only reach allowed domains (GitHub by default, plus language-specific domains like `releases.lean-lang.org` for Lean). IPv6 is blocked, DNS is restricted to the container resolver, and outbound SSH is blocked. Configurable in `~/.bubble/config.toml`.
96
+
97
+ ## Requirements
98
+
99
+ - **macOS**: Homebrew, then `brew install colima incus`
100
+ - **Linux**: Incus installed natively ([install guide](https://linuxcontainers.org/incus/docs/main/installing/))
101
+ - **VSCode** with [Remote - SSH](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh) extension
102
+
103
+ ## Commands
104
+
105
+ | Command | Description |
106
+ |---------|-------------|
107
+ | `bubble <target>` | Open (or create) a bubble for a GitHub URL/repo |
108
+ | `bubble list` | List all bubbles |
109
+ | `bubble pause <name>` | Freeze a bubble |
110
+ | `bubble destroy <name>` | Delete a bubble permanently |
111
+ | `bubble cleanup` | Destroy all clean bubbles (no unsaved work) |
112
+ | `bubble images list\|build` | Manage base images |
113
+ | `bubble git update` | Refresh shared git mirrors |
114
+ | `bubble network apply\|remove <name>` | Manage network restrictions |
115
+ | `bubble automation install\|remove\|status` | Manage periodic jobs |
116
+ | `bubble relay enable\|disable\|status` | Manage bubble-in-bubble relay |
117
+ | `bubble doctor` | Diagnose and fix common issues |
118
+
119
+ ## Images
120
+
121
+ Images are built automatically on first use.
122
+
123
+ | Image | Contents |
124
+ |-------|----------|
125
+ | `base` | Ubuntu 24.04, git, openssh-server, build-essential, pre-baked VS Code Server |
126
+ | `lean` | base + elan, leantar, VS Code Lean 4 extension, auto-cache extension |
127
+ | `lean-v4.X.Y` | lean + specific toolchain pre-installed (built lazily on demand) |
128
+
129
+ `base` and `lean` are static images you can rebuild with `bubble images build <name>`. Versioned `lean-v4.X.Y` images are built automatically in the background when a project uses a stable/RC toolchain not yet cached — the current bubble proceeds immediately with elan downloading the toolchain on demand, and the next bubble for that version starts instantly.
130
+
131
+ For mathlib or mathlib-dependent projects, a VS Code terminal automatically runs `lake exe cache get` when the workspace opens.
132
+
133
+ ## Configuration
134
+
135
+ Config lives at `~/.bubble/config.toml`. Created automatically on first use.
136
+
137
+ Set `BUBBLE_HOME` to override the data directory (default: `~/.bubble`):
138
+ ```bash
139
+ export BUBBLE_HOME=/data/bubble
140
+ ```
141
+
142
+ ```toml
143
+ [runtime]
144
+ backend = "incus"
145
+ colima_cpu = 24 # macOS: CPUs for the Colima VM
146
+ colima_memory = 16 # macOS: GB of RAM
147
+ colima_vm_type = "vz" # macOS: Apple Virtualization.Framework
148
+
149
+ [network]
150
+ allowlist = [
151
+ "github.com",
152
+ "raw.githubusercontent.com",
153
+ "release-assets.githubusercontent.com",
154
+ "objects.githubusercontent.com",
155
+ "codeload.githubusercontent.com",
156
+ ]
157
+ ```
158
+
159
+ ## Bubble-in-Bubble
160
+
161
+ You can run `bubble` from inside a container to open another bubble on the host. This is useful when reviewing a related PR while working on a feature branch.
162
+
163
+ ```bash
164
+ # On the host: enable the relay (one-time setup)
165
+ bubble relay enable
166
+
167
+ # Inside a container: open another bubble
168
+ bubble leanprover/lean4/pull/456
169
+ bubble mathlib4
170
+ ```
171
+
172
+ The relay only allows opening repos already cloned in `~/.bubble/git/` — it cannot trigger cloning of new repos. Local paths are rejected. Existing bubbles need to be recreated after enabling the relay to get the relay socket.
173
+
174
+ ## Security
175
+
176
+ - **No sudo**: The `user` account has no sudo access and a locked password
177
+ - **Network allowlisting**: iptables rules restrict outbound connections to allowed domains only
178
+ - **IPv6 blocked**: All IPv6 traffic is dropped
179
+ - **DNS restricted**: DNS queries only go to the container's configured resolver
180
+ - **No outbound SSH**: Containers cannot SSH out (VSCode uses `incus exec` ProxyCommand)
181
+ - **SSH key-only auth**: Password authentication is disabled
182
+ - **Shell injection hardening**: All user-supplied values are quoted with `shlex.quote()`
183
+ - **Per-repo git mount**: Each container only sees its own bare repo, not the entire git store
184
+
185
+ ## License
186
+
187
+ Apache 2.0 — see [LICENSE](LICENSE).