google-colab-cli 0.5.11__tar.gz → 0.7.2__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.
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/AGENTS.md +20 -5
- google_colab_cli-0.7.2/CHANGELOG.md +80 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/PKG-INFO +9 -5
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/README.md +6 -3
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/cloudbuild.yaml +29 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/docs/01_session_management.md +22 -9
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/docs/04_automation_and_utility.md +52 -28
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/docs/05_run_command.md +2 -0
- google_colab_cli-0.7.2/docs/06_ssh_access.md +137 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/integration/README.md +1 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/integration/repro_keep_alive_scope/test.sh +16 -10
- google_colab_cli-0.7.2/integration/repro_ssh/test.sh +189 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/pyproject.toml +12 -2
- google_colab_cli-0.5.11/COLAB_SKILL.md → google_colab_cli-0.7.2/skills/colab-operator/SKILL.md +10 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/auth.py +41 -4
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/cli.py +3 -1
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/client.py +82 -51
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/commands/automation.py +8 -3
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/commands/execution.py +55 -5
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/commands/run.py +91 -29
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/commands/session.py +94 -34
- google_colab_cli-0.7.2/src/colab_cli/commands/ssh.py +711 -0
- google_colab_cli-0.7.2/src/colab_cli/commands/usage.py +37 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/commands/utility.py +2 -2
- google_colab_cli-0.7.2/src/colab_cli/consumption.py +56 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/repl.py +11 -10
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/runtime.py +22 -10
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/state.py +1 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/utils.py +20 -1
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_auth.py +27 -4
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_cli.py +94 -6
- google_colab_cli-0.7.2/tests/test_client.py +345 -0
- google_colab_cli-0.7.2/tests/test_consumption.py +53 -0
- google_colab_cli-0.7.2/tests/test_consumption_client.py +73 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_exec.py +94 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_readme.py +2 -2
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_run.py +160 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_runtime.py +28 -25
- google_colab_cli-0.7.2/tests/test_ssh.py +444 -0
- google_colab_cli-0.7.2/tests/test_ssh_autocreate.py +332 -0
- google_colab_cli-0.7.2/tests/test_ssh_lifecycle.py +284 -0
- google_colab_cli-0.7.2/tests/test_ssh_wire_contract.py +391 -0
- google_colab_cli-0.7.2/tests/test_ssh_workdir.py +75 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_utils.py +30 -1
- google_colab_cli-0.7.2/uv.lock +1186 -0
- google_colab_cli-0.5.11/tests/test_client.py +0 -198
- google_colab_cli-0.5.11/uv.lock +0 -1044
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/.githooks/pre-commit +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/.gitignore +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/.pre-commit-config.yaml +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/.python-version +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/CONTRIBUTING.md +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/LICENSE +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/docs/02_execution_and_interactive.md +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/docs/03_file_management.md +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/docs/3042ab12-2026-05-07.png +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/docs/demo.webm +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/docs/demos.md +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/examples/finetune_run.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/integration/repro_bundled_oauth/test.sh +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/integration/repro_keep_alive/test.sh +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/integration/repro_piped_console/test.sh +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/integration/repro_plot_redirection/test.sh +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/integration/repro_run_command/test.sh +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/integration/repro_variable_persistence/test.sh +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/auto_update.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/commands/__init__.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/commands/files.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/common.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/console.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/contents.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/converter.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/history.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/src/colab_cli/oauth_config.json +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/conftest.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_auth_adc.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_automation.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_cli_log.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_console.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_contents.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_history.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_ipynb_exec.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_keep_alive.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_log_export.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_pay.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_repl.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_resolution_logic.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_state.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_streaming.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_update.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_url.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_version.py +0 -0
- {google_colab_cli-0.5.11 → google_colab_cli-0.7.2}/tests/test_whoami.py +0 -0
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
- **Common**: `common.py` centralizes shared `State` (lazy-loading) and session resolution.
|
|
6
6
|
- **Client**: `ColabClient` handles API interactions (assignment, unassignment).
|
|
7
7
|
- **Auth**: `auth.py` exposes a single `get_credentials(config_path, provider)` facade that dispatches on the `AuthProvider` enum. Two providers are supported, selected via the global `--auth=oauth2|adc` flag (default `oauth2`):
|
|
8
|
-
- `oauth2`: public `google-auth-oauthlib` `InstalledAppFlow`, token cached at `~/.config/colab-cli/token.json`.
|
|
9
|
-
- `adc`: Google Application Default Credentials via `google.auth.default()`. The CLI passes `scopes=PUBLIC_SCOPES` (which includes `colaboratory`) and re-applies via `creds.with_scopes()` for credential types that support it. **User credentials minted by `gcloud auth application-default login` ignore the `scopes=` kwarg AND raise `NotImplementedError` on `with_scopes`**: ADC users must explicitly re-authenticate with `gcloud auth application-default login --scopes=openid,https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/colaboratory`. `userinfo.email` is required by the session backend at `colab.research.google.com` (assign/unassign/sessions return 401 without it); `colaboratory` is
|
|
8
|
+
- `oauth2`: public `google-auth-oauthlib` `InstalledAppFlow`, token cached at `~/.config/colab-cli/token.json`. Reads the client OAuth config from `-c/--client-oauth-config` (default `~/.colab-cli-oauth-config.json`), falling back to the **bundled** `src/colab_cli/oauth_config.json` resource (re-added in PR #41 / `9f44fe2`, 2026-05-29 — the earlier "removed in `20eb88e`" note was stale/incorrect; the file exists and `auth.py:_get_google_auth_credentials` loads it via `importlib.resources`). As of 2026-06-11 the flow is a **remote copy-paste flow**, not a localhost server: `_run_remote_flow` sets `redirect_uri=https://sdk.cloud.google.com/applicationdefaultauthcode.html` + `token_usage=remote`, prints the URL, and reads the pasted code via `input()`. NEVER revert to OOB (`urn:ietf:wg:oauth:2.0:oob`) — Google blocked it in 2022 ("OOB flow has been blocked"); the `sdk.cloud.google.com` redirect is registered only to the bundled cloud-SDK client (`764086051850-...`), so any other client id gets `redirect_uri_mismatch`. Server-side acceptance/rejection of these variants is verifiable GET-only by building the authorization URL and inspecting whether Google reaches sign-in vs. an OAuth error page (no resources allocated).
|
|
9
|
+
- `adc`: Google Application Default Credentials via `google.auth.default()`. The CLI passes `scopes=PUBLIC_SCOPES` (which includes `colaboratory`) and re-applies via `creds.with_scopes()` for credential types that support it. **User credentials minted by `gcloud auth application-default login` ignore the `scopes=` kwarg AND raise `NotImplementedError` on `with_scopes`**: ADC users must explicitly re-authenticate with `gcloud auth application-default login --scopes=openid,https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/userinfo.email,https://www.googleapis.com/auth/colaboratory`. `userinfo.email` is required by the session backend at `colab.research.google.com` (assign/unassign/sessions/keep-alive return 401 without it); `colaboratory` is retained for forward compatibility and other Colab features (keep-alive no longer uses `colab.pa.googleapis.com` — see the Keep-alive note below); `openid` and `cloud-platform` are mandated by `gcloud` itself, which rejects scope lists that omit `cloud-platform` with `Invalid value for [--scopes]`. Service-account / GCE / GKE / impersonated creds get the right scopes transparently via `with_scopes`.
|
|
10
10
|
- **Backend Hosts**: Two distinct backends with different requirements:
|
|
11
|
-
- `colab.research.google.com` (session backend / `tun/m/...`): accepts the `userinfo.email` scope.
|
|
12
|
-
- `colab.
|
|
11
|
+
- `colab.research.google.com` (session backend / `tun/m/...`): accepts the `userinfo.email` scope. Handles assign, unassign, the contents API, **and keep-alive** (see below).
|
|
12
|
+
- **Keep-alive (2026-06-15, issue #14)**: keep-alive is a **Tunnel Frontend (TFE) HTTP ping** — `GET https://colab.research.google.com/tun/m/<endpoint>/keep-alive/` with header `X-Colab-Tunnel: Google`, authenticated by the user's own Gaia bearer token (same host/credential as `assign`). TFE records `LastActiveTime` before forwarding, refreshing the idle timer. The VM usually doesn't answer on this path, so the request commonly **read-times-out even on success** — `client.keep_alive_assignment` therefore catches `requests.exceptions.ReadTimeout` and treats it as success, while genuine HTTP errors (e.g. 404 for a deleted assignment) propagate. This mirrors the official `colab-vscode` extension's `sendKeepAlive` (`src/colab/client.ts`). **DO NOT revert to the `colab.pa.googleapis.com` `RuntimeService/KeepAliveAssignment` RPC**: that RPC requires the caller to be a `serviceusage` consumer of Colab's internal project `1014160490159`, which no ordinary user account is, so it returned HTTP 403 `USER_PROJECT_DENIED` for every external user (issue #14) and silently idle-pruned their sessions within minutes. The browser only made that RPC work by riding the user's `google.com` cookie through an internal cookie-proxy (`colab.clients6.google.com`), which a headless bearer-token CLI cannot use. Verified live 2026-06-15 with a third-party account (the RPC 403'd; the tunnel ping succeeded and kept the VM alive).
|
|
13
13
|
- **Runtime**: `ColabRuntime` wraps `jupyter-kernel-client` for execution.
|
|
14
14
|
- **State**:
|
|
15
15
|
- `StateStore` persists session metadata in `~/.config/colab-cli/sessions.json`.
|
|
@@ -42,6 +42,21 @@
|
|
|
42
42
|
- **Files**: `ls`, `rm`, `upload`, `download`, `edit`.
|
|
43
43
|
- **Automation**: `auth`, `drivemount`, `install`, `log`, `pay`, `version`, `update`.
|
|
44
44
|
|
|
45
|
+
## Release Tagging Workflow
|
|
46
|
+
The package version is derived from the git tag via `hatch-vcs` (see `pyproject.toml`), so a release is just (1) a `CHANGELOG.md` entry and (2) a `vX.Y.Z` tag on the merged commit. Follow this workflow ONLY when the user explicitly requests a release (e.g. "cut a release", "tag v0.7.0", "release the keep-alive fix"). NEVER propose or perform a release proactively.
|
|
47
|
+
|
|
48
|
+
1. **Verify a clean, current `main`**: `git fetch origin && git checkout main && git pull --ff-only origin main`. Confirm `git status` is clean. If `main` has diverged or there are unmerged feature branches the user expects in the release, stop and ask.
|
|
49
|
+
2. **Identify unreleased commits**: Find the last release tag with `git describe --tags --abbrev=0`, then list commits since then with `git log <last-tag>..HEAD --oneline`. These are what the new changelog section must cover. Cross-reference each commit's PR number (the `(#NN)` suffix in the merge commit subject) — every entry in the changelog should cite at least one PR.
|
|
50
|
+
3. **Infer the next version (semver)**: Categorize each commit using the Keep-a-Changelog buckets already present in `CHANGELOG.md` (`Added`, `Changed`, `Fixed`, `Removed`, `Deprecated`, `Security`). Pick the bump:
|
|
51
|
+
- **Major** (`X.0.0`): any breaking change to the CLI surface, flag semantics, on-disk state schema (`sessions.json` / `settings.json`), or persisted token format.
|
|
52
|
+
- **Minor** (`0.X.0`): at least one `Added` entry (new subcommand, new flag, new capability) with no breaking changes.
|
|
53
|
+
- **Patch** (`0.0.X`): only `Fixed`, `Changed`, `Removed` (non-breaking cleanup), `Deprecated`, or `Security` entries.
|
|
54
|
+
Confirm the inferred version with the user before proceeding — never tag without that confirmation, even when the bump seems obvious.
|
|
55
|
+
4. **Draft and commit the CHANGELOG entry on a branch**: Create a release branch (e.g. `release-v0.7.0`), then prepend a new `## [X.Y.Z] - YYYY-MM-DD` section above the previous release. Group entries by category in the order already established in `CHANGELOG.md` (`Changed`, `Added`, `Fixed`, `Removed`). Each bullet should be one short paragraph naming the user-visible behavior change (not the implementation detail) and ending with the PR reference `(#NN)`. Append a new link reference at the bottom: `[X.Y.Z]: https://github.com/googlecolab/google-colab-cli/compare/v<PREV>...vX.Y.Z`. Commit with message `docs: add CHANGELOG.md for vX.Y.Z release`, push the branch, and open a PR with `gh pr create`.
|
|
56
|
+
5. **Wait for the changelog PR to merge**: Do NOT tag the pre-merge commit on your branch. The tag must land on the squash-merge commit that appears on `main` (this is what `hatch-vcs` will see and what users will `git checkout`). After the user reports the PR is merged (or you observe it via `gh pr view <num> --json state,mergeCommit`), `git fetch origin && git checkout main && git pull --ff-only origin main`.
|
|
57
|
+
6. **Tag the merged changelog commit and push the tag**: Verify `git log -1 --oneline` is the merged changelog commit (subject matches `docs: add CHANGELOG.md for vX.Y.Z release (#NN)`). Create an annotated tag whose message is the changelog section body: `git tag -a vX.Y.Z -m "vX.Y.Z" -m "<changelog section body>"`. Push with `git push origin vX.Y.Z`. Do NOT create a GitHub Release entry via `gh release create` — the tag alone is sufficient because `hatch-vcs` reads it directly, and the canonical release notes already live in `CHANGELOG.md`.
|
|
58
|
+
7. **Verify**: Run `git describe --tags --exact-match HEAD` (should print `vX.Y.Z`) and `uv run colab version` (the version string should match). Confirm with `gh api repos/googlecolab/google-colab-cli/tags --jq '.[0].name'` that the tag is visible on the remote.
|
|
59
|
+
|
|
45
60
|
## Implementation Principles
|
|
46
61
|
1. **Direct Execution**: Code for `auth`, `drivemount`, etc., should be injected and executed on the VM kernel.
|
|
47
62
|
2. **Contents API**: Use the Jupyter Contents API for file management as seen in the browser traces.
|
|
@@ -60,7 +75,7 @@
|
|
|
60
75
|
15. **Two distinct auths — never confuse them**: This codebase has two unrelated authentication concerns: (a) **CLI-to-Colab-control-plane**: how `Client` authenticates HTTP requests to `colab.research.google.com` and `colab.pa.googleapis.com`. Driven by the global `--auth={oauth2,adc}` flag and `auth.py:get_credentials`. The OAuth2 path is bootstrapped automatically by `google_auth_oauthlib`'s `InstalledAppFlow` on first invocation when `~/.config/colab-cli/token.json` doesn't exist; **no separate command is needed** — any `--auth=oauth2` invocation (e.g. `colab --auth=oauth2 sessions`) triggers the browser consent flow. (b) **VM-side credentials**: how the `colab auth` subcommand injects user GCP credentials *into* the running Colab kernel so notebook code (e.g. `gcloud`, BigQuery client) can make authenticated calls from inside the VM. This uses the `USE_AUTH_EPHEM='0'` gcloud-fallback path executed on the kernel via `ColabRuntime`. **NEVER tell a user to "run `colab auth`" as a prerequisite for fixing CLI-side auth issues** — they're orthogonal layers and the suggestion misleads.
|
|
61
76
|
16. **Detached daemons inherit nothing useful**: When spawning a detached child process via `subprocess.Popen` (e.g. `spawn_keep_alive`), the child does NOT inherit the parent's parsed Typer flags. It re-parses argv from scratch, so any global flag the parent saw via `--auth=adc` or `--config /tmp/foo.json` MUST be re-emitted as part of the child's command line. Forgetting this causes silent fallback to Typer defaults: in 2026-04-30 this manifested as the keep-alive daemon (a) using OAUTH2 instead of the parent's ADC, and (b) reading from `~/.config/colab-cli/sessions.json` instead of the parent's `--config` path. Always propagate every relevant global flag in `cmd = [sys.executable, "-m", ...]` BEFORE the subcommand name (Typer requires global flags before the subcommand).
|
|
62
77
|
17. **Persist-before-spawn for daemons that read shared state**: When a detached child reads from a state file the parent owns (e.g. `state.store.get(session_name)`), the parent MUST persist BEFORE spawning. Otherwise the child can race ahead of the parent's `add()` call and observe an empty store. Symptom in 2026-04-30: keep-alive daemon exits immediately with `keep_alive_stopped reason=session_not_found iters=1 duration=0.0s`. Fix: call `state.store.add(s)` once before `spawn_keep_alive`, and again after (to capture the PID).
|
|
63
|
-
18.
|
|
78
|
+
18. **[SUPERSEDED 2026-06-15 — keep-alive no longer calls `colab.pa.googleapis.com`; see issue #14 / the Keep-alive note above] `colab.pa.googleapis.com` rejects ADC user creds without `X-Goog-User-Project`**: When calling `colab.pa.googleapis.com` from ADC user credentials minted by `gcloud auth application-default login`, the bearer token carries the user's gcloud quota project. The colab API key sent alongside it belongs to a different project (Colab, `1014160490159`). The backend enforces project-match between the two and returns HTTP 400 `CONSUMER_INVALID` ("The API Key and the authentication credential are from different projects."). The old fix was to send `X-Goog-User-Project: 1014160490159` to pin the consumer project — but that in turn required `serviceusage.serviceUsageConsumer` on project `1014160490159`, which ordinary users lack, yielding HTTP 403 `USER_PROJECT_DENIED` (the issue #14 root cause). Both failure modes are now moot because keep-alive uses the TFE tunnel ping on `colab.research.google.com` instead. Retained here as institutional knowledge: if any future code path must call `colab.pa.googleapis.com` with a bearer token, it will face this same project-entitlement wall for non-internal accounts.
|
|
64
79
|
19. **Pydantic validation requires a schema**: `_issue_request` accepts an optional `schema=` and historically called `TypeAdapter(schema).validate_python(...)` unconditionally. When `schema=None` (a caller that doesn't care about the response body — e.g. fire-and-forget RPCs like `KeepAliveAssignment` that return `[]`), this raises `pydantic.ValidationError: Input should be None`. Always guard with `if schema is None: return` after the empty-body short-circuit.
|
|
65
80
|
20. **Suggest the branch-diff review command after committing**: The user reviews changes with `git diff main..<branch-name>` (full cumulative diff against `main`, not just the latest commit). After landing one or more commits on a feature branch, ALWAYS suggest the exact command — e.g. "Review with `git diff main..sort-help-commands`" — instead of `git show <sha>` (which only shows a single commit and misses context when a branch has multiple commits). Encoded 2026-05-05 after suggesting `git show 9d9c7da` for a branch the user wanted to review holistically.
|
|
66
81
|
21. **Verify research-tool claims with primary sources**: Research tools and AI assistants can be confidently wrong, especially about edge cases or features outside their training corpus. When such a tool says "X is not used / not parsed / doesn't exist", treat it as a hypothesis to verify, not a fact. Always cross-check against the primary source (the actual code or config) — and when a tool names files, check whether the indirection chain it describes actually exists. The cost of believing the tool when it's wrong is shipping a non-functional feature; the cost of double-checking is small. Encoded 2026-05-05 after a `colab url` first-cut shipped the wrong URL format because of unverified output.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
The package version is derived from the git tag via `hatch-vcs`; each release
|
|
9
|
+
below corresponds to a tag of the same name.
|
|
10
|
+
|
|
11
|
+
## [0.7.1] - 2026-09-14
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- **build:** Pin core metadata to version 2.4 for both the wheel and the sdist.
|
|
16
|
+
hatchling 1.32.0 bumped its default to 2.5, which our publishing pipeline
|
|
17
|
+
rejects, so 0.7.0 was built but never reached PyPI. `colab ssh` (added in
|
|
18
|
+
0.7.0) was therefore unavailable to anyone installing from PyPI.
|
|
19
|
+
|
|
20
|
+
## [0.7.0] - 2026-09-03
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- **deps:** Bump cryptography from 49.0.0 to 50.0.0 (#98), and pyasn1 from 0.6.3 to 0.6.4 (#87).
|
|
25
|
+
- **lockfile:** Upgrade lockfile dependencies via `uv lock --upgrade`. (#67)
|
|
26
|
+
- **skill:** Move the CLI help skill details into a dedicated `SKILL.md`. (#55)
|
|
27
|
+
- **docs:** Update `AGENTS.md` with instructions for the release tagging workflow. (#66)
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
- **ssh:** Add `colab ssh` command to provide secure SSH-over-WebSocket direct access to the Colab runtime VM. (#88)
|
|
32
|
+
- **execution:** Add `--env KEY=VALUE` flag to `colab run` and `colab exec` commands to allow injecting custom environment variables into the running kernel. (#65)
|
|
33
|
+
- **session:** Add `--high-mem` flag to machine shape selection when creating a new session to support high-RAM resources. (#105)
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
|
|
37
|
+
- **session:** Surface a friendly error message on 412 GPU/TPU allocation failure instead of printing a raw traceback. (#112)
|
|
38
|
+
- **runtime:** Support both `ColabKernelClient` and standard `KernelClient` in the runtime layer to improve compatibility across environments. (#95)
|
|
39
|
+
|
|
40
|
+
## [0.6.0] - 2026-06-16
|
|
41
|
+
|
|
42
|
+
### Changed
|
|
43
|
+
|
|
44
|
+
- **auth:** OAuth2 login now uses a remote copy-paste flow instead of a
|
|
45
|
+
localhost callback server. The CLI prints an authorization URL with
|
|
46
|
+
`redirect_uri=https://sdk.cloud.google.com/applicationdefaultauthcode.html`
|
|
47
|
+
and `token_usage=remote`, then reads the pasted code from stdin. This works
|
|
48
|
+
in headless/remote environments where a browser cannot reach a local
|
|
49
|
+
callback port. (#54)
|
|
50
|
+
|
|
51
|
+
### Added
|
|
52
|
+
|
|
53
|
+
- **display output:** Rich rendering for `display_data` output via a shared
|
|
54
|
+
`render_display_data()` helper. HTML is converted with `html2text` and
|
|
55
|
+
rendered as Markdown, following a `text/markdown > text/html > text/plain`
|
|
56
|
+
priority; `text/plain` is wrapped with `Text.from_ansi` to preserve embedded
|
|
57
|
+
ANSI escapes. Applied consistently across `exec`, `console`/`repl`, and
|
|
58
|
+
automation call sites. (#58)
|
|
59
|
+
|
|
60
|
+
### Fixed
|
|
61
|
+
|
|
62
|
+
- **keep-alive:** Replace the `RuntimeService/KeepAliveAssignment` RPC on
|
|
63
|
+
`colab.pa.googleapis.com` with a Tunnel Frontend (TFE) HTTP ping
|
|
64
|
+
(`GET /tun/m/<endpoint>/keep-alive/` with `X-Colab-Tunnel: Google`) on
|
|
65
|
+
`colab.research.google.com`, authenticated by the user's own bearer token.
|
|
66
|
+
The old RPC required `serviceusage` consumer access to Colab's internal
|
|
67
|
+
project and returned HTTP 403 `USER_PROJECT_DENIED` for every external user,
|
|
68
|
+
causing their sessions to be idle-pruned within minutes. The TFE ping needs
|
|
69
|
+
no project entitlement; because the VM often does not answer on this path, a
|
|
70
|
+
`ReadTimeout` is treated as success while genuine HTTP errors propagate.
|
|
71
|
+
(#14, #61)
|
|
72
|
+
|
|
73
|
+
### Removed
|
|
74
|
+
|
|
75
|
+
- Dead grpc-web client-registry / API-key code path and the now-irrelevant
|
|
76
|
+
`colaboratory`-scope / `pa.googleapis.com` pre-flight remediation messaging,
|
|
77
|
+
superseded by the TFE keep-alive ping. (#61)
|
|
78
|
+
|
|
79
|
+
[0.7.0]: https://github.com/googlecolab/google-colab-cli/compare/v0.6.0...v0.7.0
|
|
80
|
+
[0.6.0]: https://github.com/googlecolab/google-colab-cli/compare/v0.5.11...v0.6.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: google-colab-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.2
|
|
4
4
|
Summary: CLI for interacting with Colab.
|
|
5
5
|
Project-URL: Homepage, https://github.com/googlecolab/google-colab-cli
|
|
6
6
|
Project-URL: Repository, https://github.com/googlecolab/google-colab-cli
|
|
@@ -20,7 +20,8 @@ Requires-Dist: click>=8.0
|
|
|
20
20
|
Requires-Dist: filelock>=3.29.2
|
|
21
21
|
Requires-Dist: google-auth-oauthlib>=1.3.0
|
|
22
22
|
Requires-Dist: google-auth>=2.49.1
|
|
23
|
-
Requires-Dist:
|
|
23
|
+
Requires-Dist: html2text>=2024.2.26
|
|
24
|
+
Requires-Dist: jupyter-kernel-client==0.8
|
|
24
25
|
Requires-Dist: nbformat>=5.10.4
|
|
25
26
|
Requires-Dist: packaging>=24.0
|
|
26
27
|
Requires-Dist: prompt-toolkit>=3.0.52
|
|
@@ -103,9 +104,9 @@ Run `colab <command> --help` to view specific options, defaults, and detailed he
|
|
|
103
104
|
### Session Management
|
|
104
105
|
| Command | Description |
|
|
105
106
|
| --- | --- |
|
|
106
|
-
| `colab new [-s NAME] [--gpu GPU] [--tpu TPU]` | Allocate a new CPU, GPU, or TPU VM runtime |
|
|
107
|
+
| `colab new [-s NAME] [--gpu GPU] [--tpu TPU] [--high-mem]` | Allocate a new CPU, GPU, or TPU VM runtime (optionally high-RAM) |
|
|
107
108
|
| `colab sessions` | List all active sessions currently active on the backend |
|
|
108
|
-
| `colab status [-s NAME]` | Display hardware, status, and local metadata for active sessions |
|
|
109
|
+
| `colab status [-s NAME]` | Display hardware, machine shape, status, and local metadata for active sessions |
|
|
109
110
|
| `colab restart-kernel [-s NAME]` | Restart the active session's Jupyter kernel |
|
|
110
111
|
| `colab stop [-s NAME]` | Terminate a session VM and tear down its keep-alive daemon |
|
|
111
112
|
| `colab url [-s NAME] [--open]` | Print or open a browser URL connecting to the active session |
|
|
@@ -113,10 +114,11 @@ Run `colab <command> --help` to view specific options, defaults, and detailed he
|
|
|
113
114
|
### Execution
|
|
114
115
|
| Command | Description |
|
|
115
116
|
| --- | --- |
|
|
116
|
-
| `colab run [--gpu GPU] [--tpu TPU] [--keep] SCRIPT [ARGS...]` | Run a local script on a fresh VM, forwarding arguments, then release it |
|
|
117
|
+
| `colab run [--gpu GPU] [--tpu TPU] [--high-mem] [--keep] SCRIPT [ARGS...]` | Run a local script on a fresh VM, forwarding arguments, then release it |
|
|
117
118
|
| `colab exec [-s NAME] [-f FILE] [--output-image PATH]` | Execute Python code from stdin, a local `.py` file, or a `.ipynb` notebook |
|
|
118
119
|
| `colab repl [-s NAME] [--output-image PATH]` | Start an interactive Python REPL on the VM (exits cleanly on piped EOF) |
|
|
119
120
|
| `colab console [-s NAME]` | Connect to a raw interactive TTY shell (tmux) on the remote VM |
|
|
121
|
+
| `colab ssh [-s NAME] [--proxy-mode] [-i KEY] [--gpu GPU] [--tpu TPU] [--high-mem]` | Open an SSH shell to the runtime over WebSocket, or act as an OpenSSH `ProxyCommand` bridge for IDE remote-dev |
|
|
120
122
|
|
|
121
123
|
### File Operations
|
|
122
124
|
| Command | Description |
|
|
@@ -134,6 +136,7 @@ Run `colab <command> --help` to view specific options, defaults, and detailed he
|
|
|
134
136
|
| `colab drivemount [-s NAME] [PATH]` | Mount Google Drive on the VM (default: `/content/drive`) |
|
|
135
137
|
| `colab install [-s NAME] [-r FILE \| PKG...]` | Install packages on the VM using `uv` (falls back to `pip`) |
|
|
136
138
|
| `colab log [-s NAME] [-n N] [-o FILE]` | View or export session history (`.ipynb`, `.md`, `.txt`, `.jsonl`) |
|
|
139
|
+
| `colab usage` | Show account compute-unit usage rate and balance |
|
|
137
140
|
| `colab pay` | Open the Colab subscription page to manage compute units |
|
|
138
141
|
| `colab version` | Print the installed version of the CLI |
|
|
139
142
|
| `colab update [--install]` | Check for a newer release (and optionally upgrade the CLI in place) |
|
|
@@ -176,6 +179,7 @@ colab stop -s analysis
|
|
|
176
179
|
|
|
177
180
|
## Usage Notes
|
|
178
181
|
|
|
182
|
+
* **Machine shape:** Use `--high-mem` with `colab new`, `colab run`, or `colab ssh` (when auto-creating a runtime) to request a high-RAM machine shape. Requires Colab Pro or Pro+ entitlement for supported accelerators (CPU, T4, A100, etc.). L4 and TPU runtimes ignore this flag because they only offer one shape. Machine shape is shown in `colab sessions` and `colab status`.
|
|
179
183
|
* **TTY Requirements:** The interactive commands `repl` and `console` require a local TTY. When running inside automated scripts or pipelines, make sure to pipe stdin (e.g., `echo "print(1)" | colab repl`) to trigger non-interactive execution modes.
|
|
180
184
|
* **Transparent Code Execution:** When calling `colab exec -f file.py`, the CLI reads the file locally and transmits its content to the remote kernel. You do not need to manually upload files before execution.
|
|
181
185
|
* **Storage & State Paths:** Session tokens and metadata are stored at `~/.config/colab-cli/sessions.json`. Global CLI settings are located at `~/.config/colab-cli/settings.json`. These can be customized or isolated via the global `--config` flag.
|
|
@@ -68,9 +68,9 @@ Run `colab <command> --help` to view specific options, defaults, and detailed he
|
|
|
68
68
|
### Session Management
|
|
69
69
|
| Command | Description |
|
|
70
70
|
| --- | --- |
|
|
71
|
-
| `colab new [-s NAME] [--gpu GPU] [--tpu TPU]` | Allocate a new CPU, GPU, or TPU VM runtime |
|
|
71
|
+
| `colab new [-s NAME] [--gpu GPU] [--tpu TPU] [--high-mem]` | Allocate a new CPU, GPU, or TPU VM runtime (optionally high-RAM) |
|
|
72
72
|
| `colab sessions` | List all active sessions currently active on the backend |
|
|
73
|
-
| `colab status [-s NAME]` | Display hardware, status, and local metadata for active sessions |
|
|
73
|
+
| `colab status [-s NAME]` | Display hardware, machine shape, status, and local metadata for active sessions |
|
|
74
74
|
| `colab restart-kernel [-s NAME]` | Restart the active session's Jupyter kernel |
|
|
75
75
|
| `colab stop [-s NAME]` | Terminate a session VM and tear down its keep-alive daemon |
|
|
76
76
|
| `colab url [-s NAME] [--open]` | Print or open a browser URL connecting to the active session |
|
|
@@ -78,10 +78,11 @@ Run `colab <command> --help` to view specific options, defaults, and detailed he
|
|
|
78
78
|
### Execution
|
|
79
79
|
| Command | Description |
|
|
80
80
|
| --- | --- |
|
|
81
|
-
| `colab run [--gpu GPU] [--tpu TPU] [--keep] SCRIPT [ARGS...]` | Run a local script on a fresh VM, forwarding arguments, then release it |
|
|
81
|
+
| `colab run [--gpu GPU] [--tpu TPU] [--high-mem] [--keep] SCRIPT [ARGS...]` | Run a local script on a fresh VM, forwarding arguments, then release it |
|
|
82
82
|
| `colab exec [-s NAME] [-f FILE] [--output-image PATH]` | Execute Python code from stdin, a local `.py` file, or a `.ipynb` notebook |
|
|
83
83
|
| `colab repl [-s NAME] [--output-image PATH]` | Start an interactive Python REPL on the VM (exits cleanly on piped EOF) |
|
|
84
84
|
| `colab console [-s NAME]` | Connect to a raw interactive TTY shell (tmux) on the remote VM |
|
|
85
|
+
| `colab ssh [-s NAME] [--proxy-mode] [-i KEY] [--gpu GPU] [--tpu TPU] [--high-mem]` | Open an SSH shell to the runtime over WebSocket, or act as an OpenSSH `ProxyCommand` bridge for IDE remote-dev |
|
|
85
86
|
|
|
86
87
|
### File Operations
|
|
87
88
|
| Command | Description |
|
|
@@ -99,6 +100,7 @@ Run `colab <command> --help` to view specific options, defaults, and detailed he
|
|
|
99
100
|
| `colab drivemount [-s NAME] [PATH]` | Mount Google Drive on the VM (default: `/content/drive`) |
|
|
100
101
|
| `colab install [-s NAME] [-r FILE \| PKG...]` | Install packages on the VM using `uv` (falls back to `pip`) |
|
|
101
102
|
| `colab log [-s NAME] [-n N] [-o FILE]` | View or export session history (`.ipynb`, `.md`, `.txt`, `.jsonl`) |
|
|
103
|
+
| `colab usage` | Show account compute-unit usage rate and balance |
|
|
102
104
|
| `colab pay` | Open the Colab subscription page to manage compute units |
|
|
103
105
|
| `colab version` | Print the installed version of the CLI |
|
|
104
106
|
| `colab update [--install]` | Check for a newer release (and optionally upgrade the CLI in place) |
|
|
@@ -141,6 +143,7 @@ colab stop -s analysis
|
|
|
141
143
|
|
|
142
144
|
## Usage Notes
|
|
143
145
|
|
|
146
|
+
* **Machine shape:** Use `--high-mem` with `colab new`, `colab run`, or `colab ssh` (when auto-creating a runtime) to request a high-RAM machine shape. Requires Colab Pro or Pro+ entitlement for supported accelerators (CPU, T4, A100, etc.). L4 and TPU runtimes ignore this flag because they only offer one shape. Machine shape is shown in `colab sessions` and `colab status`.
|
|
144
147
|
* **TTY Requirements:** The interactive commands `repl` and `console` require a local TTY. When running inside automated scripts or pipelines, make sure to pipe stdin (e.g., `echo "print(1)" | colab repl`) to trigger non-interactive execution modes.
|
|
145
148
|
* **Transparent Code Execution:** When calling `colab exec -f file.py`, the CLI reads the file locally and transmits its content to the remote kernel. You do not need to manually upload files before execution.
|
|
146
149
|
* **Storage & State Paths:** Session tokens and metadata are stored at `~/.config/colab-cli/sessions.json`. Global CLI settings are located at `~/.config/colab-cli/settings.json`. These can be customized or isolated via the global `--config` flag.
|
|
@@ -38,6 +38,27 @@ steps:
|
|
|
38
38
|
echo "TAG_NAME=${TAG_NAME}"
|
|
39
39
|
echo "git describe: $(git describe --tags --always)"
|
|
40
40
|
|
|
41
|
+
# 1b. Delete any artifacts a previous run left staged.
|
|
42
|
+
# Staged artifacts are only cleaned up after a successful release; a
|
|
43
|
+
# failed one leaves them in place so the release can be retried. Since
|
|
44
|
+
# step 4 publishes with `publish_all: true`, a later release would pick
|
|
45
|
+
# those up too and republish them alongside the new ones.
|
|
46
|
+
# This has to run as part of the build, which holds the delete
|
|
47
|
+
# permission that individual accounts do not.
|
|
48
|
+
# `|| true` so a first-ever release (nothing to delete) isn't a failure.
|
|
49
|
+
- id: purge-stale-artifacts
|
|
50
|
+
name: gcr.io/google.com/cloudsdktool/cloud-sdk:slim
|
|
51
|
+
entrypoint: bash
|
|
52
|
+
args:
|
|
53
|
+
- -c
|
|
54
|
+
- |
|
|
55
|
+
set -e
|
|
56
|
+
gcloud artifacts packages delete "${_EG_PROJECT_NAME}" \
|
|
57
|
+
--project="${_AR_PROJECT}" \
|
|
58
|
+
--repository="${_AR_REPOSITORY}" \
|
|
59
|
+
--location="${_AR_LOCATION}" \
|
|
60
|
+
--quiet || true
|
|
61
|
+
|
|
41
62
|
# 2. Build sdist + wheel into dist/ using uv.
|
|
42
63
|
# Use the non-slim bookworm variant: hatch-vcs derives the version
|
|
43
64
|
# by shelling out to `git describe`, which requires a git binary
|
|
@@ -57,6 +78,8 @@ steps:
|
|
|
57
78
|
# google-artifactregistry-auth keyring plugin (uses ADC from the
|
|
58
79
|
# Cloud Build service account, which is registered as a builder in
|
|
59
80
|
# the project's project.txtpb).
|
|
81
|
+
# Delete any existing artifact for this tag which can happen if the
|
|
82
|
+
# build failed to publish in step 4.
|
|
60
83
|
- id: publish-to-ar
|
|
61
84
|
name: python:3.13-slim
|
|
62
85
|
entrypoint: bash
|
|
@@ -66,6 +89,12 @@ steps:
|
|
|
66
89
|
set -e
|
|
67
90
|
pip install --quiet --root-user-action=ignore \
|
|
68
91
|
twine keyrings.google-artifactregistry-auth
|
|
92
|
+
gcloud artifacts versions delete ${TAG_NAME} \
|
|
93
|
+
--package={_EG_PROJECT_NAME} \
|
|
94
|
+
--project={_AR_PROJECT} \
|
|
95
|
+
--repository=${_AR_REPOSITORY} \
|
|
96
|
+
--location=us \
|
|
97
|
+
--quiet
|
|
69
98
|
twine upload \
|
|
70
99
|
--repository-url "https://${_AR_LOCATION}-python.pkg.dev/${_AR_PROJECT}/${_AR_REPOSITORY}/" \
|
|
71
100
|
--verbose \
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
log:
|
|
3
|
+
2026-08-10: Added `colab usage` for account-level compute-unit rate/balance via `GET /tun/m/ccu-info` on the session backend (same bearer token as `colab new`).
|
|
4
|
+
2026-08-09: Added `--high-mem` to `colab new`, `colab run`, and `colab ssh` (auto-create). Assign requests now send `shape=hm` when high-RAM is requested; `colab sessions` and `colab status` display machine shape.
|
|
5
|
+
2026-06-15: Switched the keep-alive daemon from the `colab.pa.googleapis.com` `RuntimeService/KeepAliveAssignment` RPC to a Tunnel Frontend HTTP ping (`GET /tun/m/<endpoint>/keep-alive/` with `X-Colab-Tunnel: Google`) on `colab.research.google.com`. The RPC required `serviceusage` consumer access to Colab's internal project `1014160490159`, which ordinary user accounts lack, so every external user hit HTTP 403 `USER_PROJECT_DENIED` and their CLI sessions were idle-pruned within minutes (issue #14). Reproduced live with a third-party account; verified the tunnel ping is accepted by the same bearer-token credential that already works for `assign`. A `ReadTimeout` on the ping is treated as success (TFE records activity before forwarding to the often-non-responding VM). Generalized the pre-flight remediation messaging away from the now-irrelevant `colaboratory`/`pa.googleapis.com` framing, and removed the dead grpc-web client-registry/API-key code.
|
|
3
6
|
2026-06-10: Replaced the POSIX-only `fcntl.flock` file locking in `_LockedFileStore` with the cross-platform `filelock` library (reported broken on Windows). Reads use `ReadWriteLock.read_lock()` (shared) and writes use `write_lock()` (exclusive), preserving the original `LOCK_SH`/`LOCK_EX` semantics. The lock is constructed with `is_singleton=False` so two `StateStore` instances for the same path in one process don't collapse into a single reentrant lock (which would raise `RuntimeError` on multi-threaded write contention). Added shared-read, cross-process exclusion, and multi-thread/multi-process regression tests.
|
|
4
7
|
---
|
|
5
8
|
|
|
@@ -31,11 +34,20 @@ Defines the specific hardware model.
|
|
|
31
34
|
- `V5E1`: TPU v5e (1 core, optimized for inference/efficient training).
|
|
32
35
|
- `V6E1`: TPU v6e (1 core, high performance).
|
|
33
36
|
|
|
34
|
-
### 3.
|
|
37
|
+
### 3. Machine shape (`shape`)
|
|
38
|
+
Defines the RAM profile for runtimes that support a choice (CPU, T4, A100, etc.).
|
|
39
|
+
- `STANDARD` (default): omit the `shape` query param on assign.
|
|
40
|
+
- `HIGH_RAM`: send `shape=hm` on assign (requires Colab Pro/Pro+ entitlement).
|
|
41
|
+
|
|
42
|
+
Accelerators with only one shape (L4, v5e1, v6e1) ignore `--high-mem`.
|
|
43
|
+
|
|
44
|
+
### 4. CLI Mapping
|
|
35
45
|
The CLI maps user flags to these backend parameters:
|
|
36
46
|
- `colab new my-session` -> `variant=DEFAULT`, `accelerator=NONE`
|
|
37
|
-
- `colab new my-session
|
|
38
|
-
- `colab new my-session
|
|
47
|
+
- `colab new my-session --gpu=L4` -> `variant=GPU`, `accelerator=L4`
|
|
48
|
+
- `colab new my-session --tpu=v5e1` -> `variant=TPU`, `accelerator=V5E1`
|
|
49
|
+
- `colab new my-session --high-mem` -> adds `shape=hm` (when supported)
|
|
50
|
+
- `colab new my-session --gpu A100 --high-mem` -> `variant=GPU`, `accelerator=A100`, `shape=hm`
|
|
39
51
|
|
|
40
52
|
## Approach
|
|
41
53
|
|
|
@@ -50,8 +62,8 @@ The CLI maps user flags to these backend parameters:
|
|
|
50
62
|
- Format: `{ "session_name": { "token": "...", "backend_url": "...", "hardware": "..." } }`
|
|
51
63
|
|
|
52
64
|
### 2. Session Status (`colab status`)
|
|
53
|
-
- **
|
|
54
|
-
- **
|
|
65
|
+
- **Session lines**: Local metadata per tracked session — hardware, shape, variant, IDLE/BUSY (from CLI bookkeeping), and optional last-execution detail. Syncs with `GET /tun/m/assignments` to prune stale entries.
|
|
66
|
+
- **Future**: Real-time VM resource usage (CPU/RAM/GPU) via a kernel diagnostic snippet is still TODO. For account-level compute-unit balance and usage rate, use `colab usage`.
|
|
55
67
|
|
|
56
68
|
### 3. Stop Session (`colab stop`)
|
|
57
69
|
- **API**: `POST https://colab.sandbox.google.com/tun/m/unassign/<endpoint>` (based on `tpu-v5e1-unassign.har`).
|
|
@@ -70,19 +82,20 @@ The CLI maps user flags to these backend parameters:
|
|
|
70
82
|
### 5. Keep-Alive Protocol
|
|
71
83
|
To prevent Colab VMs from being deleted due to idle timeouts (standard is ~90 minutes), the CLI implements a background keep-alive mechanism.
|
|
72
84
|
- **Daemon Process**: Since the CLI is a fire-and-forget tool, `colab new` spawns a detached background process running a hidden `keep-alive` command.
|
|
73
|
-
- **
|
|
74
|
-
- **
|
|
85
|
+
- **Tunnel ping**: Every 60 seconds, the daemon issues `GET https://colab.research.google.com/tun/m/<endpoint>/keep-alive/` with the header `X-Colab-Tunnel: Google`, authenticated with the user's own Gaia bearer token (the same credential and host used for `/tun/m/assign`). The Tunnel Frontend (TFE) records `LastActiveTime` before forwarding the request, which refreshes the idle timer. This matches the official `colab-vscode` extension's `sendKeepAlive`. TFE notes the activity on arrival and then forwards to the VM, which often does not answer on this path — so the request commonly read-times-out even though the keep-alive succeeded; a `ReadTimeout` is therefore treated as success, while genuine HTTP errors (e.g. 404 for a deleted assignment) propagate.
|
|
86
|
+
- **Why not the RuntimeService RPC**: The previous implementation called `google.internal.colab.v1.RuntimeService/KeepAliveAssignment` at `colab.pa.googleapis.com` with `X-Goog-User-Project: 1014160490159`. That path requires the caller to be a `serviceusage` consumer of Colab's internal project `1014160490159`, which no ordinary user account is — so it returned HTTP 403 `USER_PROJECT_DENIED` for every external user, causing CLI sessions to be idle-pruned within minutes (issue #14). Dropping the header instead produced HTTP 400 `CONSUMER_INVALID` (public API-key project ≠ bearer-token quota project). The browser only succeeds because it rides the user's `google.com` cookie through an internal cookie-proxy (`colab.clients6.google.com`), which a headless bearer-token client cannot use. The TFE tunnel ping needs no project entitlement and works for any account that can assign a VM.
|
|
87
|
+
- **Pre-flight (`colab new`, OAuth2/ADC only)**: Immediately after a successful `assign`, the CLI invokes `keep_alive_assignment` once synchronously. If the response is 403 with a `SCOPE_NOT_PERMITTED` body, it unassigns the new VM (to avoid leaking a billable assignment) and prints a per-provider remediation message before exiting non-zero. Other errors are tolerated — the daemon will retry and surface them via the structured event log. (Because keep-alive now uses the same backend/credential as `assign`, a scope failure at this stage is rare — assignment would normally have failed first.)
|
|
75
88
|
- **Structured logging**: The daemon emits `keep_alive_started` (with `pid`, `endpoint`), one `keep_alive_error` per failed iteration (with `status_code`, `error_type`, truncated `error`, `response_body`, `iteration`, `consecutive_4xx`), and `keep_alive_stopped` (with `reason`, `iterations`, `duration_seconds`, optional `last_error`, optional `expected_endpoint`/`actual_endpoint`). All three are rendered specially by `colab log` so users get diagnostic context without parsing JSONL by hand.
|
|
76
89
|
- **Termination**:
|
|
77
90
|
- **Explicit**: `colab stop` terminates the daemon using its stored PID.
|
|
78
91
|
- **Implicit**: If a session is pruned (e.g., during `sync_sessions`), its daemon is also terminated.
|
|
79
92
|
- **Safety Fallback**: The daemon automatically terminates after 24 hours to prevent permanent zombie processes.
|
|
80
93
|
- **State Check**: The daemon periodically verifies that its session still exists in the local state store; if missing, it exits.
|
|
81
|
-
- **Repeated 4xx**: After two consecutive 4xx responses, the daemon exits with `reason=consecutive_4xx_errors`.
|
|
94
|
+
- **Repeated 4xx**: After two consecutive 4xx responses, the daemon exits with `reason=consecutive_4xx_errors`. With the TFE tunnel ping, a normal read-timeout is not counted as a 4xx (it is treated as success), so this branch is now reached only by genuine HTTP errors such as a 404 for a deleted/expired assignment.
|
|
82
95
|
|
|
83
96
|
## TODO / Future Work
|
|
84
97
|
- **Backend Sync**: Implement a way to reconcile the local `sessions.json` with the output of `colab sessions`.
|
|
85
|
-
- **Resource Usage**: Add real-time resource usage (CPU/RAM/GPU) to the `status` output by executing a diagnostic snippet on the VM.
|
|
98
|
+
- **VM Resource Usage**: Add real-time resource usage (CPU/RAM/GPU) to the `status` output by executing a diagnostic snippet on the VM (distinct from account-level CU info, which is available via `colab usage`).
|
|
86
99
|
|
|
87
100
|
## Implementation Details
|
|
88
101
|
- **Authentication**: Uses `google-auth-oauthlib` to perform a local server OAuth flow.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
log:
|
|
3
|
+
2026-08-10: Added `colab usage` for account-level compute-unit rate/balance via `GET /tun/m/ccu-info` on the session backend (same bearer token as `colab new`).
|
|
4
|
+
2026-06-11: Replaced the `oauth2` provider's `run_local_server()` (localhost redirect) with a remote copy-paste flow (`_run_remote_flow` in `auth.py`). The CLI now prints an authorization URL built with `redirect_uri=https://sdk.cloud.google.com/applicationdefaultauthcode.html` and `token_usage=remote`, then reads the pasted authorization code via `input()` and exchanges it with `flow.fetch_token(code=...)`. This is the same flow `gcloud auth application-default login` uses and works identically in local and remote/headless/container environments, removing the heuristic of whether to auto-open a browser. Confirmed server-side acceptance with a live GET-only check against the bundled cloud-SDK client (`764086051850-...`); the OOB redirect and a non-bundled client id were both verified to be rejected (`OOB flow has been blocked` / `redirect_uri_mismatch`). Unit tests in `tests/test_auth.py` assert no localhost server is started, the redirect URI + `token_usage=remote` are set, and the pasted code is exchanged.
|
|
3
5
|
2026-06-01: Enabled `colab update --install` self-update on macOS in addition to Linux. Refactored platform check logic to keep the implementation DRY and updated both tests and documentation. Also, on these platforms, an additional message is shown recommending `colab update --install` to upgrade in place, positioned above the standard `pip`/`uv` installation command.
|
|
4
6
|
2026-05-29: Added default OAuth2 client config (`oauth_config.json`) as a bundled package resource and restored fallback loading logic in `get_credentials()`. The CLI now falls back to using these default credentials when no explicit local config is found. Added `integration/repro_bundled_oauth` integration test.
|
|
5
7
|
2026-05-27: Refactored `colab README` and `colab AGENT` to bundle `README.md` and `AGENTS.md` via Hatchling's `force-include` and read them using `importlib.resources` instead of `importlib.metadata`. `colab AGENT` now correctly prints `AGENTS.md`.
|
|
@@ -11,7 +13,7 @@ log:
|
|
|
11
13
|
2026-05-12: Added an optional `timeout=` parameter to `ColabRuntime.execute_code` that flows through to both the `execute()` and `execute_interactive()` branches. `colab auth` and `colab drivemount` now pass `timeout=600` (10 min) via a shared `INTERACTIVE_AUTOMATION_TIMEOUT_SEC` constant in `commands/automation.py`. Background: `jupyter_kernel_client` defaults to a 10s wall-clock timeout that is consumed even when the kernel is idle waiting on `input_request`. With the drivefs hook intercepting that request and prompting the user to OAuth in their browser, any user that takes >10s to click through (essentially everyone) hit `TimeoutError` and saw "drivemount failed" even though the mount had actually succeeded server-side. The fix is scoped narrowly to the two human-in-the-loop subcommands; non-interactive paths (`colab exec`, `colab run`, `colab install`, `colab repl --pipe`, `colab console --pipe`) keep the upstream default since they receive continuous iopub traffic that resets the practical inactivity ceiling.
|
|
12
14
|
---
|
|
13
15
|
|
|
14
|
-
# Design: Automation and Utility (`auth`, `install`, `log`, `pay`, `version`, `update`, `whoami`)
|
|
16
|
+
# Design: Automation and Utility (`auth`, `install`, `log`, `pay`, `usage`, `version`, `update`, `whoami`)
|
|
15
17
|
|
|
16
18
|
## Overview
|
|
17
19
|
|
|
@@ -23,11 +25,25 @@ managing local state, or inspecting the environment.
|
|
|
23
25
|
The CLI supports two authentication strategies for talking to the Colab
|
|
24
26
|
backend, selected via the global `--auth=<provider>` flag:
|
|
25
27
|
|
|
26
|
-
1. **`oauth2`** (default):
|
|
27
|
-
`google-auth-oauthlib
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
1. **`oauth2`** (default): Public `InstalledAppFlow` via
|
|
29
|
+
`google-auth-oauthlib`, but run with a **remote copy-paste flow** rather
|
|
30
|
+
than a localhost server. The CLI prints an authorization URL (with
|
|
31
|
+
`token_usage=remote`) using the registered HTTPS landing page
|
|
32
|
+
`https://sdk.cloud.google.com/applicationdefaultauthcode.html`; the user
|
|
33
|
+
signs in, copies the code Google displays, and pastes it back at the
|
|
34
|
+
prompt. The refresh token is cached at `~/.config/colab-cli/token.json`.
|
|
35
|
+
This is the same mechanism `gcloud auth application-default login` uses,
|
|
36
|
+
and it behaves identically on local, remote, headless, and container
|
|
37
|
+
hosts (no auto-opened browser, no bound port). We deliberately do **not**
|
|
38
|
+
use `run_local_server()` (environment-dependent) or the out-of-band (OOB)
|
|
39
|
+
redirect `urn:ietf:wg:oauth:2.0:oob` (blocked by Google in 2022 — see
|
|
40
|
+
`_run_remote_flow` / `REMOTE_REDIRECT_URI` in `auth.py`). The
|
|
41
|
+
`sdk.cloud.google.com` redirect is registered to the cloud-SDK OAuth
|
|
42
|
+
client (`764086051850-...`), which is also the client shipped in the
|
|
43
|
+
bundled `oauth_config.json`; reusing it with any other client id yields
|
|
44
|
+
`redirect_uri_mismatch`. If no local config is provided via
|
|
45
|
+
`-c/--client-oauth-config` or found at `~/.colab-cli-oauth-config.json`,
|
|
46
|
+
it falls back to that bundled `oauth_config.json`.
|
|
31
47
|
2. **`adc`**: Application Default Credentials via `google.auth.default()`.
|
|
32
48
|
Honors the standard ADC discovery chain
|
|
33
49
|
(`GOOGLE_APPLICATION_CREDENTIALS`, `gcloud auth application-default
|
|
@@ -41,18 +57,18 @@ allowing the core `Client` to remain authentication-agnostic — it only sees a
|
|
|
41
57
|
|
|
42
58
|
### Required Scopes
|
|
43
59
|
|
|
44
|
-
The CLI talks to
|
|
60
|
+
The CLI talks to the Colab session backend at `colab.research.google.com`
|
|
61
|
+
for assignment, unassignment, the contents API, **and keep-alive** (the TFE
|
|
62
|
+
tunnel ping — see `01_session_management.md`). The `userinfo.email` scope is
|
|
63
|
+
sufficient for this host.
|
|
45
64
|
|
|
46
|
-
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
`SCOPE_NOT_PERMITTED`. (The frontend additionally requires
|
|
54
|
-
`X-Goog-Api-Client` to contain `grpc-web` — see
|
|
55
|
-
`01_session_management.md` §5.)
|
|
65
|
+
> Historical note: keep-alive previously used the `RuntimeService`
|
|
66
|
+
> (`KeepAliveAssignment`) at `colab.pa.googleapis.com`, which required the
|
|
67
|
+
> `https://www.googleapis.com/auth/colaboratory` scope **and** the caller to
|
|
68
|
+
> be a `serviceusage` consumer of Colab's internal project `1014160490159`.
|
|
69
|
+
> The latter is impossible for ordinary user accounts, which made keep-alive
|
|
70
|
+
> fail with HTTP 403 `USER_PROJECT_DENIED` for all external users (issue #14).
|
|
71
|
+
> Keep-alive no longer touches `colab.pa.googleapis.com`.
|
|
56
72
|
|
|
57
73
|
How each provider supplies the scope:
|
|
58
74
|
|
|
@@ -76,12 +92,11 @@ How each provider supplies the scope:
|
|
|
76
92
|
```
|
|
77
93
|
|
|
78
94
|
`userinfo.email` is required for the session backend at
|
|
79
|
-
`colab.research.google.com` (otherwise assign/unassign/sessions
|
|
80
|
-
HTTP 401); `colaboratory` is
|
|
81
|
-
`
|
|
82
|
-
`
|
|
83
|
-
|
|
84
|
-
omit `cloud-platform` with `Invalid value for [--scopes]`).
|
|
95
|
+
`colab.research.google.com` (otherwise assign/unassign/sessions/keep-alive
|
|
96
|
+
return HTTP 401); `colaboratory` is retained for forward compatibility and
|
|
97
|
+
other Colab features; `openid` and `cloud-platform` are mandated by
|
|
98
|
+
`gcloud` itself (`gcloud auth application-default login` rejects scope
|
|
99
|
+
lists that omit `cloud-platform` with `Invalid value for [--scopes]`).
|
|
85
100
|
|
|
86
101
|
`colab new` performs a one-shot keep-alive pre-flight after `assign`
|
|
87
102
|
succeeds so missing-scope failures surface immediately (with per-provider
|
|
@@ -137,13 +152,22 @@ remediation guidance) rather than silently after ~1 minute via the daemon.
|
|
|
137
152
|
- **Conversion (Planned)**: Future expansion to convert history logs to
|
|
138
153
|
`.ipynb` or `.html`.
|
|
139
154
|
|
|
140
|
-
### 5.
|
|
155
|
+
### 5. Compute-Unit Usage (`colab usage`)
|
|
156
|
+
|
|
157
|
+
- **Action**: Print account-level compute-unit (CU) usage rate and balance.
|
|
158
|
+
- **Data source**: `GET https://colab.research.google.com/tun/m/ccu-info`
|
|
159
|
+
(balance, hourly rate, assignment count). Same bearer token and session
|
|
160
|
+
backend as `colab new`.
|
|
161
|
+
- **Output**: `Current balance: … compute units`, `Usage rate: {rate}/hr`
|
|
162
|
+
(aggregate CU/hour across assigned VMs), `Active assignments: N`.
|
|
163
|
+
|
|
164
|
+
### 6. Subscription Management (`colab pay`)
|
|
141
165
|
|
|
142
166
|
- **Action**: Open the Colab signup page in the user's browser.
|
|
143
167
|
- **Implementation**: Uses
|
|
144
168
|
`webbrowser.open("https://colab.research.google.com/signup")`.
|
|
145
169
|
|
|
146
|
-
###
|
|
170
|
+
### 7. Version Information (`colab version`)
|
|
147
171
|
|
|
148
172
|
- **Action**: Show the current version of the Colab CLI.
|
|
149
173
|
- **Implementation**:
|
|
@@ -153,7 +177,7 @@ remediation guidance) rather than silently after ~1 minute via the daemon.
|
|
|
153
177
|
Git commit hash using `git rev-parse --short HEAD`.
|
|
154
178
|
- Dynamic versioning is supported in the build system via `hatch-vcs`.
|
|
155
179
|
|
|
156
|
-
###
|
|
180
|
+
### 8. Auto-Update (`colab update`)
|
|
157
181
|
|
|
158
182
|
- **Action**: Check if a new version of the Colab CLI is available.
|
|
159
183
|
- **Auto-check**: The CLI automatically checks for updates once every 24 hours
|
|
@@ -204,7 +228,7 @@ remediation guidance) rather than silently after ~1 minute via the daemon.
|
|
|
204
228
|
automation. If the upgrade command exits non-zero, `colab update --install`
|
|
205
229
|
propagates the same exit code.
|
|
206
230
|
|
|
207
|
-
###
|
|
231
|
+
### 9. Identity Inspection (`colab whoami`) [developer-only]
|
|
208
232
|
|
|
209
233
|
- **Action**: Resolve the active credentials, mint an access token, and
|
|
210
234
|
print the email, audience, scopes, and expiry of that token.
|
|
@@ -246,7 +270,7 @@ remediation guidance) rather than silently after ~1 minute via the daemon.
|
|
|
246
270
|
- openid
|
|
247
271
|
```
|
|
248
272
|
|
|
249
|
-
###
|
|
273
|
+
### 10. README and AGENT (`colab README`, `colab AGENT`)
|
|
250
274
|
|
|
251
275
|
- **Action**: Print the bundled `README.md` or `AGENTS.md` file.
|
|
252
276
|
- **Implementation**:
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
log:
|
|
3
|
+
2026-08-09: Added `--high-mem` flag (passthrough to session creation; sends `shape=hm` on assign when supported).
|
|
3
4
|
2026-05-12: Initial design and implementation of `colab run <script.py> [args...]`. Combines `colab new` + `colab exec` + `colab stop` into a single fire-and-forget invocation so a Python file can use `#!/usr/bin/env -S colab run` as a shebang line and execute on a freshly-allocated Colab VM. Adds `--keep` (skip auto-stop), `--gpu` / `--tpu` (passthrough to session creation), `-s/--session` (name the ephemeral session), and propagates the script's exit status (non-zero on any uncaught exception in the kernel). The script's `sys.argv` is re-set inside the kernel to mirror native `python script.py arg1 arg2` semantics, and `__name__` is set to `"__main__"`.
|
|
4
5
|
2026-05-12: Native CPython exit-code semantics for `sys.exit()` / `raise SystemExit(...)` from the script body. The Colab kernel reports a `SystemExit` as `output_type=='error'`, which under the previous logic would have (a) printed the IPython traceback (`An exception has occurred, use %tb...`) and (b) flagged the run as a failure regardless of the integer exit code. Now: `sys.exit()` / `sys.exit(0)` exit 0 silently; `sys.exit(N)` exits N; `sys.exit('msg')` exits 1 (matching CPython). The IPython "To exit: use 'exit', 'quit', or Ctrl-D." UserWarning is filtered via the prelude. Encoded after running `examples/gpu_hello.py` end-to-end and seeing the noisy `SystemExit: 0` traceback at the end of an otherwise-successful GPU run.
|
|
5
6
|
2026-06-04: Bumped the default value of the `--timeout` flag from 10.0s to 30.0s so short-but-silent tasks aren't prematurely killed out of the box. Mirrors the same change for `colab exec`.
|
|
@@ -29,6 +30,7 @@ colab run [OPTIONS] SCRIPT [SCRIPT_ARGS]...
|
|
|
29
30
|
| `-s`, `--session` | str | auto | Name the ephemeral session (helpful with `--keep`). Auto-generated as `run-<6 hex>` if omitted. |
|
|
30
31
|
| `--gpu` | str | None | Same set as `colab new --gpu` (T4, L4, G4, H100, A100). |
|
|
31
32
|
| `--tpu` | str | None | Same set as `colab new --tpu` (v5e1, v6e1). |
|
|
33
|
+
| `--high-mem` | bool | False | Same as `colab new --high-mem` — request high-RAM when supported. |
|
|
32
34
|
| `--keep` | bool | False | Do **not** stop the session after the script finishes. |
|
|
33
35
|
| `--timeout` | float | 30.0 | Timeout in seconds for code execution to prevent hanging on silent tasks. |
|
|
34
36
|
|